ae.oaio_model

Our Asynchronously Interchangeable Objects Data Structures

Module Attributes

CREATE_ACCESS_RIGHT

create, delete and update rights, see access_right field in Pubz and Userz

DELETE_ACCESS_RIGHT

delete and update rights

UPDATE_ACCESS_RIGHT

only update rights

READ_ACCESS_RIGHT

read-only access

NO_ACCESS_RIGHT

no or not yet granted access right (not valid for Pubz.access_right)

ACCESS_RIGHTS

access rights (stored in the access_right db column of the Pubz table).

DELETE_ACTION

object got deleted, not used in Logz.action field (records get deleted instead)

DOWNLOAD_ACTION

object got downloaded/synced

REGISTER_ACTION

oaio got registered

UPLOAD_ACTION

object got uploaded/updated

LOG_DB_ACTIONS

see Logz.action field

NAME_VALUES_KEY

oaio values key of optional object name

ROOT_VALUES_KEY

oaio values key of optional files root path

FILES_VALUES_KEY

oaio values key of paths list of optional files attached to an oaio

OBJECTS_DIR

name of folder to store infos of oai objects not yet synced with server

FILES_DIR

name of folder to store file names attached to an oaio

HTTP_HEADER_USR_ID

user name

HTTP_HEADER_APP_ID

app id

HTTP_HEADER_DVC_ID

device id

MAX_STAMP_DIFF

maximum accepted UTC time difference in seconds between client and server

OLDEST_SYNC_STAMP

oldest complete stamp ("" is even older)

STAMP_FORMAT

stamp format string

now_stamp([sep])

return the current UTC timestamp as string (to use as suffix for file and variable/attribute names).

ActionType

register/upload/download.

OaioAccessRightType

oaio access rights (oaio_server.oapi.models.Pubz.access_right)

OaioAppIdType

app id

OaioCshIdType

cloud storage host id

OaioCtxType

dict-like mapping keeping the oaio-specific http header field names and values

OaioDeviceIdType

device id

OaioDictType

type of oai object converted into a dictionary

OaioFilesType

item type of the FILES_VALUES_KEY within OaiObject.client_values

OaioIdType

oai object id

OaioRootPathType

default root path (containing PATH_PLACEHOLDERS)

OaioStampType

oaio stamp

OaioUserIdType

Userz.Uid/auth.User.username

OaioValuesType

oaio client_values and server_values

Functions

context_decode(header)

decode and return the request/session http header context fields containing user/device/app ids.

context_encode(user_name, device_id[, app_id])

encode the extra http header context fields with user/device/app ids as ASCII/latin1 byte literals.

object_dict(oai_obj)

convert OaiObject dataclass instance into the corresponding mapping/dict object.

object_id(user_name, device_id, app_id, ...)

generate object id (of type OaioIdType) from the specified arguments.

stamp_diff(stamp1, stamp2)

determine the difference in seconds between the two specified stamps in the format %Y%m%d%H%M%S%f.

Classes

OaiObject(oaio_id[, client_stamp, ...])

oaio data types and structures

CREATE_ACCESS_RIGHT = 'C'

create, delete and update rights, see access_right field in Pubz and Userz

DELETE_ACCESS_RIGHT = 'D'

delete and update rights

UPDATE_ACCESS_RIGHT = 'U'

only update rights

READ_ACCESS_RIGHT = 'r'

read-only access

NO_ACCESS_RIGHT = 'x'

no or not yet granted access right (not valid for Pubz.access_right)

ACCESS_RIGHTS = ('C', 'D', 'r', 'U')

access rights (stored in the access_right db column of the Pubz table). access right names and their translations are provided, using the text prefix ‘access_right’ followed by an underscore and the access right character, in the optional loc//Msg.txt files provided by the ae.i18n portion

DELETE_ACTION = 'delete'

object got deleted, not used in Logz.action field (records get deleted instead)

DOWNLOAD_ACTION = 'download'

object got downloaded/synced

REGISTER_ACTION = 'register'

oaio got registered

UPLOAD_ACTION = 'upload'

object got uploaded/updated

LOG_DB_ACTIONS = ('register', 'upload', 'download')

see Logz.action field

NAME_VALUES_KEY = '_name'

oaio values key of optional object name

ROOT_VALUES_KEY = '_root_path'

oaio values key of optional files root path

FILES_VALUES_KEY = '_file_paths'

oaio values key of paths list of optional files attached to an oaio

OBJECTS_DIR = 'objz'

name of folder to store infos of oai objects not yet synced with server

FILES_DIR = 'filez'

name of folder to store file names attached to an oaio

HTTP_HEADER_USR_ID = 'X-OAIO-user'

user name

HTTP_HEADER_APP_ID = 'X-OAIO-app'

app id

HTTP_HEADER_DVC_ID = 'X-OAIO-dvc'

device id

MAX_STAMP_DIFF = 69.0

maximum accepted UTC time difference in seconds between client and server

OLDEST_SYNC_STAMP = '20221231111111012345'

oldest complete stamp (”” is even older)

STAMP_FORMAT = '%Y%m%d%H%M%S%f'

stamp format string

now_stamp(sep='')

function alias used to create a new oaio stamp

Return type:

str

ActionType

register/upload/download… action type

OaioAccessRightType

oaio access rights (oaio_server.oapi.models.Pubz.access_right)

OaioAppIdType

app id

OaioCshIdType

cloud storage host id

OaioCtxType

dict-like mapping keeping the oaio-specific http header field names and values

alias of Mapping[str, str]

OaioDeviceIdType

device id

OaioDictType

type of oai object converted into a dictionary

alias of dict[str, Any]

OaioFilesType

item type of the FILES_VALUES_KEY within OaiObject.client_values

alias of Sequence[str]

OaioIdType

oai object id

OaioRootPathType

default root path (containing PATH_PLACEHOLDERS)

OaioStampType

oaio stamp

OaioUserIdType

Userz.Uid/auth.User.username

OaioValuesType

oaio client_values and server_values

alias of dict[str, Any]

class OaiObject(oaio_id, client_stamp='', server_stamp='', client_values=<factory>, server_values=<factory>, csh_id=None, username='', device_id='', app_id='', csh_access_right='')[source]

Bases: object

oaio data types and structures

oaio_id: str

object id string (created by object_id())

client_stamp: str = ''

timestamp of register or newest upload

server_stamp: str = ''

timestamp of previous version

client_values: dict[str, Any]

actual object values

server_values: dict[str, Any]

previous object values (for debugging/monitoring)

csh_id: str | None = None

cloud storage host id (for attached file/folders)

username: str = ''

name of the actual user

device_id: str = ''

id of the actual device

app_id: str = ''

id of the actual application

csh_access_right: str = ''

csh+values access right of the actual user

__dataclass_fields__ = {'app_id': Field(name='app_id',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'client_stamp': Field(name='client_stamp',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'client_values': Field(name='client_values',type=dict[str, typing.Any],default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'csh_access_right': Field(name='csh_access_right',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'csh_id': Field(name='csh_id',type=typing.Optional[str],default=None,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'device_id': Field(name='device_id',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'oaio_id': Field(name='oaio_id',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'server_stamp': Field(name='server_stamp',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'server_values': Field(name='server_values',type=dict[str, typing.Any],default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'dict'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'username': Field(name='username',type=<class 'str'>,default='',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False,match_args=True,kw_only=False,slots=False,weakref_slot=False)
__eq__(other)

Return self==value.

__hash__ = None
__init__(oaio_id, client_stamp='', server_stamp='', client_values=<factory>, server_values=<factory>, csh_id=None, username='', device_id='', app_id='', csh_access_right='')
__match_args__ = ('oaio_id', 'client_stamp', 'server_stamp', 'client_values', 'server_values', 'csh_id', 'username', 'device_id', 'app_id', 'csh_access_right')
__repr__()

Return repr(self).

context_decode(header)[source]

decode and return the request/session http header context fields containing user/device/app ids.

Parameters:

header (Mapping[str, str]) – mapping with http header fields and values, having at least the extra context fields with the user/device/app ids.

Return type:

tuple[str, str, str]

Returns:

tuple with the decoded user/device/app ids.

context_encode(user_name, device_id, app_id='')[source]

encode the extra http header context fields with user/device/app ids as ASCII/latin1 byte literals.

Parameters:
  • user_name (str) – id of the user.

  • device_id (str) – id of the client device.

  • app_id (str) – id of the app.

Return type:

Mapping[str, str]

Returns:

mapping with http header context field names/values (each of them with Unicode chars will be encoded as UTF8-byte-value-literal using only ASCII/latin-1 characters).

object_dict(oai_obj)[source]

convert OaiObject dataclass instance into the corresponding mapping/dict object.

Parameters:

oai_obj (OaiObject) – oai object to convert.

Return type:

dict[str, Any]

Returns:

converted dict object.

object_id(user_name, device_id, app_id, stamp, values)[source]

generate object id (of type OaioIdType) from the specified arguments.

Parameters:
  • user_name (str) – username of the object creator/registrar.

  • device_id (str) – id of the device from where the object get registered.

  • app_id (str) – id of the registering application.

  • stamp (str) – timestamp when the object got registered.

  • values (dict[str, Any]) – values of the object.

Return type:

str

Returns:

oai object id converted by defuse() to be usable as filename on most OS.

Raises:

AssertionError if one of the following arguments is empty: object_id.user_name, object_id.device_id, object_id.app_id or object_id.stamp.

stamp_diff(stamp1, stamp2)[source]

determine the difference in seconds between the two specified stamps in the format %Y%m%d%H%M%S%f.

Parameters:
  • stamp1 (str) – time stamp string 1 (return positive seconds value if older than stamp2).

  • stamp2 (str) – time stamp string 2.

Return type:

float

Returns:

float with the difference in seconds between both specified stamps (stamp2 - stamp1).