Пример #1
0
    def __getitem__(self, index: Union[SchemaKey, int]) -> dict:
        """
        Get schema by key or sequence number, or raise CacheIndex for no such schema.

        Raise CacheIndex for no such index in schema store.

        :param index: schema key or sequence number
        :return: corresponding schema or None
        """

        logger = logging.getLogger(__name__)
        logger.debug('SchemaCache.__getitem__: >>> index: {}'.format(index))

        rv = None
        if isinstance(index, SchemaKey):
            rv = self._schema_key2schema[index]
        elif isinstance(index, int):
            try:
                rv = self._schema_key2schema[self._seq_no2schema_key[index]]
            except KeyError:
                logger.debug(
                    'SchemaCache.__getitem__: <!< index {} not present'.format(
                        index))
                raise CacheIndex('{}'.format(index))
        else:
            logger.debug(
                'SchemaCache.__getitem__: <!< index {} must be int or SchemaKey'
                .format(index))
            raise CacheIndex('{} must be int or SchemaKey'.format(index))

        logger.debug('SchemaCache.__getitem__: <<< {}'.format(rv))
        return rv
Пример #2
0
    def __getitem__(self, index: Union[SchemaKey, int, str]) -> dict:
        """
        Get schema by schema key, sequence number, or schema identifier. Raise CacheIndex for no such schema.

        Raise CacheIndex for no such index in schema store.

        :param index: schema key, sequence number, or schema identifier
        :return: corresponding schema or None
        """

        LOGGER.debug('SchemaCache.__getitem__ >>> index: %s', index)

        rv = None
        if isinstance(index, SchemaKey):
            rv = self._schema_key2schema[index]
        elif isinstance(index, int) or (isinstance(index, str) and ':2:' not in index):
            try:
                rv = self._schema_key2schema[self._seq_no2schema_key[int(index)]]
            except KeyError:
                LOGGER.debug('SchemaCache.__getitem__: <!< index %s not present', index)
                raise CacheIndex('{}'.format(index))
        elif isinstance(index, str):
            rv = self._schema_key2schema[schema_key(index)]
        else:
            LOGGER.debug('SchemaCache.__getitem__: <!< index %s must be int SchemaKey, or schema id', index)
            raise CacheIndex('{} must be int, SchemaKey, or schema id'.format(index))

        LOGGER.debug('SchemaCache.__getitem__ <<< %s', rv)
        return rv
Пример #3
0
    def __setitem__(self, index: Union[SchemaKey, int], schema: dict) -> dict:
        """
        Put schema into cache and return it.

        :param index: schema key or sequence number
        :param schema: schema to put into cache
        :return: input schema
        """

        logger = logging.getLogger(__name__)
        logger.debug(
            'SchemaCache.__setitem__: >>> index: {}, schema: {}'.format(
                index, schema))

        if isinstance(index, SchemaKey):
            self._schema_key2schema[index] = schema
            self._seq_no2schema_key[schema['seqNo']] = index
        elif isinstance(index, int):
            s_key = schema_key(schema['id'])
            self._schema_key2schema[s_key] = schema
            self._seq_no2schema_key[index] = s_key
        else:
            logger.debug(
                'SchemaCache.__setitem__: <!< Bad index {} must be a schema key or a sequence number'
                .format(index))
            raise CacheIndex(
                'Bad index {} must be a schema key or a sequence number'.
                format(index))

        logger.debug('SchemaCache.__setitem__: <<< {}'.format(schema))
        return schema
Пример #4
0
    def dflt_interval(self, cd_id: str) -> (int, int):
        """
        Return default non-revocation interval from latest 'to' times on delta frames
        of revocation cache entries on indices stemming from input cred def id.

        Compute the 'from'/'to' values as the earliest/latest 'to' values of all
        cached delta frames on all rev reg ids stemming from the input cred def id.

        E.g., on frames for
            rev-reg-0: -[xx]---[xxxx]-[x]---[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]--> time
            rev-reg-1: ----------------------[xxxx]----[xxx]---[xxxxxxxxxxxxxxxxxxxx]---------> time
            rev-reg-2: -------------------------------------------[xx]-----[xxxx]-----[xxxxx]-> time
            rev-reg-3: -----------------------------------------------------------[xxxxxxxx]--> time

        return the most recent interval covering all matching revocation registries in the cache; i.e.,:
            interval:  -------------------------------------------------------------[*******]-> time

        Raise CacheIndex if there are no matching entries.

        :param cd_id: cred def identifier to match
        :return: default non-revocation interval as 2-tuple (fro, to)
        """

        LOGGER.debug('RevocationCache.dflt_interval >>>')

        fro = None
        to = None

        for rr_id in self:
            if cd_id != rev_reg_id2cred_def_id(rr_id):
                continue
            entry = self[rr_id]
            if entry.rr_delta_frames:
                to = max(entry.rr_delta_frames, key=lambda f: f.to).to
                fro = min(fro or to, to)

        if not (fro and to):
            LOGGER.debug(
                'RevocationCache.dflt_interval <!< No data for default non-revoc interval on cred def id %s',
                cd_id)
            raise CacheIndex('No data for default non-revoc interval on cred def id {}'.format(cd_id))

        rv = (fro, to)
        LOGGER.debug('RevocationCache.dflt_interval <<< %s', rv)
        return rv
Пример #5
0
    def __setitem__(self, index: Union[SchemaKey, int], schema: dict) -> dict:
        """
        Put schema into cache and return it.

        :param index: schema key or sequence number
        :param schema: schema to put into cache
        :return: input schema
        """

        LOGGER.debug('SchemaCache.__setitem__ >>> index: %s, schema: %s', index, schema)

        if isinstance(index, SchemaKey):
            self._schema_key2schema[index] = schema
            self._seq_no2schema_key[schema['seqNo']] = index
        elif isinstance(index, int):
            s_key = schema_key(schema['id'])
            self._schema_key2schema[s_key] = schema
            self._seq_no2schema_key[index] = s_key
        else:
            LOGGER.debug('SchemaCache.__setitem__: <!< Bad index %s must be a schema key or a sequence number', index)
            raise CacheIndex('Bad index {} must be a schema key or a sequence number'.format(index))

        LOGGER.debug('SchemaCache.__setitem__ <<< %s', schema)
        return schema