Beispiel #1
0
 def make_key_value(self, data):
     _id = data['_id']
     try:
         _id = data['_id'].encode()
     except:
         raise IndexPreconditionsException(
             "_id must be valid string/bytes object")
     if len(_id) != 32:
         raise IndexPreconditionsException("Invalid _id lenght")
     del data['_id']
     del data['_rev']
     return _id, data
Beispiel #2
0
 def make_key_value(self, data):
     _id = data['_id']
     try:
         _id = data['_id']
         if isinstance(_id, six.text_type):
             _id = _id.encode()
     except:
         raise IndexPreconditionsException(
             "_id must be valid string/bytes object")
     if not isinstance(_id, bytes) or len(_id) != 32:
         raise IndexPreconditionsException("Invalid _id type or lenght")
     del data['_id']
     del data['_rev']
     return _id, data
Beispiel #3
0
 def __init__(self, db_path, name, *args, **kwargs):
     if kwargs.get('sh_nums', 0) > 255:
         raise IndexPreconditionsException("Too many shards")
     kwargs['ind_class'] = UniqueHashIndex
     super(IU_ShardedUniqueHashIndex,
           self).__init__(db_path, name, *args, **kwargs)
     self.patchers.append(self.wrap_insert_id_index)
Beispiel #4
0
    def __init__(self, db_path, name, entry_line_format="<32s8sIIcI", *args, **kwargs):
        # Fix types
        if isinstance(db_path, six.text_type):
            db_path = db_path.encode()
        if isinstance(name, six.text_type):
            name = name.encode()

        if 'key' in kwargs:
            raise IndexPreconditionsException(
                "UniqueHashIndex doesn't accept key parameter'")
        super(IU_UniqueHashIndex, self).__init__(db_path, name,
                                                 entry_line_format, *args, **kwargs)
        self.create_key = random_hex_32  # : set the function to create random key when no _id given
Beispiel #5
0
 def wrap_insert_id_index(db_obj, clean=False):
     def _insert_id_index(_rev, data):
         """
         Performs insert on **id** index.
         """
         _id, value = db_obj.id_ind.make_key_value(data)  # may be improved
         trg_shard = _id[:2]
         storage = db_obj.id_ind.shards_r[trg_shard].storage
         start, size = storage.insert(value)
         db_obj.id_ind.insert(_id, _rev, start, size)
         return _id
     if not clean:
         if hasattr(db_obj, '_insert_id_index_orig'):
             raise IndexPreconditionsException(
                 "Already patched, something went wrong")
         setattr(db_obj, "_insert_id_index_orig", db_obj._insert_id_index)
         setattr(db_obj, "_insert_id_index", _insert_id_index)
     else:
         setattr(db_obj, "_insert_id_index", db_obj._insert_id_index_orig)
         delattr(db_obj, "_insert_id_index_orig")