ujotypes.variants.base

This module provides the base object all ujotypes inherit from

class ujotypes.variants.base.UjoBase(variant_handle, owner=False)

Bases: object

Base class wrapping an ujotypes-c object into a Python object

Parameters:
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant
  • owner (bool) – Indicates if the class takes the ownership of the variant handle
handle

C API handle of the variant

Type:(int)
refcount

Current reference count of Ujo variant

Type:(int)
subtype

Subtype constant of the variant

Type:(int)
type

Type constant of the variant

Type:(int)
value

Abstract method to be implemented in concrete classes.

variant_subtype = 0
variant_type = 0

ujotypes.variants.none

Ujo Types None wrapper class

class ujotypes.variants.none.UjoNone(variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo None type

Parameters:
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If no handle is passed a new handle will be created.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(None)
variant_type = 15

ujotypes.variants.boolean

Ujo Types Boolean wrapper class

class ujotypes.variants.boolean.UjoBool(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo Boolean type

Parameters:
  • value (bool, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(bool)
variant_type = 13

ujotypes.variants.integer

Ujo Types Integer wrapper class

class ujotypes.variants.integer.UjoInt16(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo int16 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 7
class ujotypes.variants.integer.UjoInt32(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo int32 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 6
class ujotypes.variants.integer.UjoInt64(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo int64 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 5
class ujotypes.variants.integer.UjoInt8(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo int8 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 8
class ujotypes.variants.integer.UjoUInt16(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo uint16 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 11
class ujotypes.variants.integer.UjoUInt32(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo uint32 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 10
class ujotypes.variants.integer.UjoUInt64(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo uint64 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 9
class ujotypes.variants.integer.UjoUInt8(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo uint8 type

Parameters:
  • value (int, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(int)
variant_type = 12

ujotypes.variants.float

Ujo Types Floats wrapper class

class ujotypes.variants.float.UjoFloat16(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo float16 type

Parameters:
  • value (float, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(float)
variant_type = 3
class ujotypes.variants.float.UjoFloat32(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo float32 type

Parameters:
  • value (float, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(float)
variant_type = 2
class ujotypes.variants.float.UjoFloat64(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo float64 type

Parameters:
  • value (float, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(float)
variant_type = 1

ujotypes.variants.string

Ujo Types String wrapper class

class ujotypes.variants.string.UjoStringC(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo C string type

Parameters:
  • value (str, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(str)
variant_subtype = 0
variant_type = 4
class ujotypes.variants.string.UjoStringUTF8(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo UTF-8 string type

Parameters:
  • value (str, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(str)
variant_subtype = 1
variant_type = 4

ujotypes.variants.timestamp

Ujo Types Timestamp wrapper class

class ujotypes.variants.timestamp.UjoTimestamp(value=None, variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase

Wrap Ujo Timestamp type

Parameters:
  • value (datetime, None) – The value can be None if a valid variant handle is passed.
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If a handle is passed the value is ignored.
  • owner (bool) – Indicates if the class owns the variant
value

Current Value

Type:(datetime)
variant_type = 19

ujotypes.variants.container (List and Map)

Ujo Types container wrapper classes

class ujotypes.variants.container.UjoList(variant_handle=None, owner=False)

Bases: ujotypes.variants.base.UjoBase, collections.abc.MutableSequence

An Ujo list of Ujo objects

The Ujo list is comparable to a python list and provides the same operators and functions being available by Python Lists. The main difference being that the Ujo list itself contains only typed Ujo objects.

Parameters:
  • variant_handle (int) – A handle returned by the Ujo C-API representing a variant. If None is passed a new handle is created.
  • owner (bool) – Indicates if the class owns the variant
append(value)

Append an Ujo Types element to the end of the list

Parameters:value (UjoBase) – The Ujo variant to be added to the list
Raises:TypeError – If objects other than objects derived from UjoBase are appended
as_pyobject() → list

Converts the Ujo container to its corresponding python representation.

Returns:Python representation of Ujo object
Return type:list
copy(deepcopy=False)

Create a copy of the ujo list

Parameters:deepcopy (bool) – create a copy of contained items (recursively), default: False
Returns:a new instance of an UjoList holding the same (or a copy of) the content
Return type:UjoList
count(value)

Return number of occurrences of Ujo elements in list having same type and value

Parameters:value (UjoBase) – The Ujo variant to count occurrences for
Returns:Number of occurrences
Return type:(int)
get_value(index, default=None, constraint=None)

Read a value from an index position with default fallback and constraint check

Parameters:
  • index (int) – item index
  • default (any) – default fallback value
  • constraint (class) – class type as constraint for the list item
Returns:

item value from the list at index position or default

Return type:

(UjoBase)

get_variant(index, default=<class 'ujotypes.variants.none.UjoNone'>, constraint=None)

Read an item from an index position with default fallback and constraint check

Parameters:
  • index (int) – item index
  • default (UjoBase) – default fallback value
  • constraint (class) – class type as constraint for the list item
Returns:

item from the list at index position or default

Return type:

(UjoBase)

index(value, start=0, stop=None)

Return first index of Ujo element in list having same type and value

For searching the element just inside a slice of the list a start and stop index can be passed to the index function. Negative numbers to count from the end of the list are allowed.

Parameters:
  • value (UjoBase) – The Ujo variant to return index for
  • index (int) – Index of element to insert before
  • start (int) – Optional index to start searching at
  • stop (int) – Optional index to stop searching at
Returns:

Index of first element in list

Return type:

(int)

Raises:

ValueError – If element of same type and value is not present

insert(index, value)

Insert an Ujo variant element before index

Parameters:
  • index (int) – Index of element to insert before
  • value (UjoBase) – The Ujo variant to be added to the list
Raises:

TypeError – If objects other than objects derived from UjoBase are inserted

set_value(index, value, value_type)

Replace a value at an index position

The value has to fit the value_type. If the value is an instance of UjoBase, the value_type is ignored.

Parameters:
  • index (int) – item index
  • value (any) – the value to set
  • value_type (class) – class type for the list item
value

Python list

Type:(list)
variant_type = 48
class ujotypes.variants.container.UjoMap(variant_handle=None, owner=True)

Bases: ujotypes.variants.base.UjoBase, collections.abc.MutableMapping

An Ujo map of Ujo objects

The Ujo map is comparable to a Python dictionary and provides the same operators and functions being available by Python dictionaries. The main difference being that the Ujo map itself contains only typed Ujo objects.

Parameters:
  • variant_handle (int) – A handle returned by the Ujo C-API representing a map variant. If None is passed a new handle is created.
  • owner (bool) – Indicates if the class owns the variant
as_pyobject() → dict

Converts an Ujo container to its corresponding python representation.

Duplicate keys of different Ujo key types will only create one entry in the Python dictionary with the value of the Ujo key value pair evaluated last.

Returns:Python representation of Ujo object
Return type:dict
copy(deepcopy=False)

Create a copy of the ujo map

Parameters:deepcopy (bool) – create a copy of contained items (recursively), default: False
Returns:a new instance of an UjoMap holding the same (or a copy of) the content
Return type:UjoMap
get_value(key, default=None, constraint=None, key_type=<class 'ujotypes.variants.string.UjoStringC'>)

Get value from map by its key with default fallback and constraint check

The key has to fit the key_type. If the key is an instance of UjoBase, the key_type is ignored.

Parameters:
  • key (any) – the key to find value with
  • default (any) – default fallback value
  • constraint (class) – class type as constraint for the map item
  • key_type (class) – class type for the key in the map
Returns:

value of item from the map or default

Return type:

(any)

get_variant(key, default=<class 'ujotypes.variants.none.UjoNone'>, constraint=None, key_type=<class 'ujotypes.variants.string.UjoStringC'>)

Get item from map by its key with default fallback and constraint check

The key has to fit the key_type. If the key is an instance of UjoBase, the key_type is ignored.

Parameters:
  • key (any) – the key to find value with
  • default (UjoBase) – default fallback value
  • constraint (class) – class type as constraint for the map item
  • key_type (class) – class type for the key in the map
Returns:

item from the map or default

Return type:

(UjoBase)

set_value(key, value, value_type, key_type=<class 'ujotypes.variants.string.UjoStringC'>)

Set or add a key value pair to the map

The key has to fit the key_type. The value has to fit the value_type. If the key is an instance of UjoBase, the key_type is ignored. If the value is an instance of UjoBase, the value_type is ignored.

Parameters:
  • key (any) – the key to store the value with
  • value (any) – the value to store
  • value_type (class) – class type for the map item
  • key_type (class) – class type for the key in the map
value

Python dictionary

Type:(dict)
variant_type = 49
ujotypes.variants.container.read_buffer(buffer)

Read Ujo container from in memory buffer to in memory Ujo Types variant

Parameters:buffer (bytes) – Binary buffer containing an Ujo container
Returns:Ujo Types variant instance
Return type:(UjoTypesBase)
ujotypes.variants.container.read_file(filename)

Read Ujo file from disc to in memory Ujo Types variant

Parameters:filename (str) – Full path of file to read
Returns:Ujo Types variant instance
Return type:(UjoTypesBase)
ujotypes.variants.container.variant_factory(variant_handle, owner=False)

Put an Ujo variant handle inside a class

Parameters:
  • variant_handle (int) – C-API variant handle
  • owner (bool) – indicates if the class wrapper owns the handle
Returns:

A variant wrapper class containing the handle

Return type:

(UjoBase)

ujotypes.variants.container.write_buffer(variant)

Write in memory Ujo Types variant to in memory binary buffer

Parameters:variant (UjoTypesBase) – List or map Ujo Types variant
Returns:Binary buffer containing Ujo container
Return type:(bytes)
ujotypes.variants.container.write_file(variant, filename)

Write in memory Ujo Types variant to Ujo file on disk

Parameters:
  • variant (UjoTypesBase) – List or map Ujo Types variant
  • filename (str) – Full path of file to write