Пример #1
0
 def test_uuid_creation(self):
     uid = self.generator.new_uuid()
     assert len(uid) == 36
     item = self._mock_item()
     assert IUUID(item, None) is not None  # has a UUID
     normalized = normalize_uuid(IUUID(item, None))
     assert self.generator.new_uuid(item) == normalized
Пример #2
0
 def test_uuid_creation(self):
     uid = self.generator.new_uuid()
     assert len(uid) == 36
     item = self._mock_item()
     assert IUUID(item, None) is not None  # has a UUID
     normalized = normalize_uuid(IUUID(item, None))
     assert self.generator.new_uuid(item) == normalized
Пример #3
0
 def __contains__(self, spec):
     uid = spec
     if not isinstance(spec, str):
         uid = IUUID(spec, None)
         if uid is None:
             uid = normalize_uuid(spec)
             if uid is None:
                 return False
     return uid in self.uidmap
Пример #4
0
 def __contains__(self, spec):
     uid = spec
     if not isinstance(spec, str):
         uid = IUUID(spec, None)
         if uid is None:
             uid = normalize_uuid(spec)
             if uid is None:
                 return False
     return uid in self.uidmap
Пример #5
0
    def new_uuid(self, obj=None, createfn=None):
        """Returns string represntation"""

        if obj and createfn is None:
            try:
                uid = normalize_uuid(IUUID(obj))
            except TypeError:
                uid = None
            if uid is not None:
                return str(uid)
        if obj and createfn:
            return str(createfn(obj))
        if createfn and obj is None:
            return str(createfn())
        return str(uuid.uuid4())  # random UUID
Пример #6
0
    def new_uuid(self, obj=None, createfn=None):
        """Returns string represntation"""

        if obj and createfn is None:
            try:
                uid = normalize_uuid(IUUID(obj))
            except TypeError:
                uid = None
            if uid is not None:
                return str(uid)
        if obj and createfn:
            return str(createfn(obj))
        if createfn and obj is None:
            return str(createfn())
        return str(uuid.uuid4())  # random UUID
Пример #7
0
 def add(self, uid, docid=None):
     if not (isinstance(uid, str) or isinstance(uid, uuid.UUID)):
         # maybe uid is object *with* a UUID, not a UUID itself
         try:
             uid = IUUID(uid)
         except TypeError:
             uid = None
         if uid is None:
             raise ValueError('unable to obtain uuid for object')
     uid = normalize_uuid(uid)
     if docid is None:
         docid = self.new_docid()
     if uid in self.uuid_to_docid:
         raise KeyError('Cannot add, UUID already in use: %s' % uid)
     if docid in self.docid_to_uuid:
         raise KeyError('docid %s already in use' % docid)
     self.uuid_to_docid[uid] = docid
     self.docid_to_uuid[docid] = uid
     self._length.change(1)  # increment length counter
     return uid, docid
Пример #8
0
 def add(self, uid, docid=None):
     if not (isinstance(uid, str) or isinstance(uid, uuid.UUID)):
         # maybe uid is object *with* a UUID, not a UUID itself
         try:
             uid = IUUID(uid)
         except TypeError:
             uid = None
         if uid is None:
             raise ValueError('unable to obtain uuid for object')
     uid = normalize_uuid(uid)
     if docid is None:
         docid = self.new_docid()
     if uid in self.uuid_to_docid:
         raise KeyError('Cannot add, UUID already in use: %s' % uid)
     if docid in self.docid_to_uuid:
         raise KeyError('docid %s already in use' % docid)
     self.uuid_to_docid[uid] = docid
     self.docid_to_uuid[docid] = uid
     self._length.change(1)  # increment length counter
     return uid, docid
Пример #9
0
 def _is_uid(self, spec):
     if isinstance(spec, int) or isinstance(spec, long):
         return False
     normalized = normalize_uuid(spec)
     return (len(normalized) == 36 and '-' in normalized)
Пример #10
0
 def _is_uid(self, spec):
     if isinstance(spec, int) or isinstance(spec, long):
         return False
     normalized = normalize_uuid(spec)
     return (len(normalized) == 36 and '-' in normalized)