def _py_byUUID(cls, val, candidates=EMPTY_TUPLE, py=False): if candidates: chk = cls.checktype objs = [chk(x) for x in candidates] objs = [x for x in candidates if x] else: objs = cls.ls() if isinstance(val, BASESTR): val = _UUID(val) elif isinstance(val, Iterable): uuids = set([(x if isinstance(x, _UUID) else _UUID(x)) for x in val]) return [x for x in objs if x.hasAttr(UUID_ATTR_NAME) and _UUID(x.plug_(UUID_ATTR_NAME).get()) in uuids] return [x for x in objs if x.hasAttr(UUID_ATTR_NAME) and val == _UUID(x.plug_(UUID_ATTR_NAME).get())]
def delete_data_collections(self, collection_id=None, exclude=None): try: # delete all stores if collection_id is None: collection_count = len(self.dtl.datastore_collection.list()) for collection in self.dtl.datastore_collection.list(): if exclude is None: self.dtl.datastore_collection.delete( datastore_collection_id=collection.id) else: if collection.id not in exclude: self.dtl.datastore_collection.delete( datastore_collection_id=collection.id) if len(self.dtl.datastore_collection.list()) == 0: print('{0} data collections deleted ...'.format( collection_count)) else: # delete a single store self.dtl.datastore_collection.delete( datastore_collection_id=_UUID(collection_id)) print('data collection deleted ...') except Exception as ex: print('error deleting data collections ({0}) :: {1}'.format( 'multiple' if collection_id is None else 'single', ex))
def test_version(self): hex = "a8098c1a-f86e-11da-bd1a-00112444be1e" for version in range(1, 5): with self.subTest(version=version): uuid = _UUID(hex=hex, version=version) cyuuid = UUID(hex=hex, version=version) self.assertEqual(uuid, cyuuid)
def delete_streams(self, stream_id=None, exclude=None): try: # delete all stream if stream_id is None: stream_count = len(self.dtl.stream_collection.list()) for stream in self.dtl.stream_collection.list(): if exclude is None: self.dtl.stream_collection.delete( stream_collection_id=stream.id) else: if stream.id not in exclude: self.dtl.stream_collection.delete( stream_collection_id=stream.id) if len(self.dtl.stream_collection.list()) == 0: print('ALL {0} pipelines deleted'.format(stream_count)) else: print('PARTIAL {0} pipelines deleted'.format(stream_count)) else: # delete a single store self.dtl.stream_collection.delete( stream_collection_id=_UUID(stream_id)) print('pipeline deleted') except Exception as ex: print('error deleting pipeline ({0}) :: {1}'.format( 'multiple' if stream_id is None else 'single', ex))
def serialize(uuid): if isinstance(uuid, str): uuid = _UUID(uuid) assert isinstance( uuid, _UUID), "Expected UUID instance, received {}".format(uuid) return str(uuid)
def serialize(uuid): if isinstance(uuid, str): uuid = _UUID(uuid) if not isinstance(uuid, _UUID): raise AssertionError( "Expected UUID instance, received {}".format(uuid)) return str(uuid)
def _uuid(self): u""" UUID を得る。 :rtype: `.UUID` """ return _UUID(str(self.mfn().uuid()))
def serialize(uuid): if isinstance(uuid, str): uuid = _UUID(uuid) assert isinstance(uuid, _UUID), f"Expected UUID instance, received {uuid}" return str(uuid)
def validate(self, value): val = super(UUID, self).validate(value) if val is None: return from uuid import UUID as _UUID if isinstance(val, _UUID): return val if isinstance(val, six.string_types) and self.re_uuid.match(val): return _UUID(val) raise ValidationError("{0} {1} is not a valid uuid".format(self.column_name, value))
def validate(self, value): val = super(UUID, self).validate(value) if val is None: return from uuid import UUID as _UUID if isinstance(val, _UUID): return val if isinstance(val, six.string_types) and self.re_uuid.match(val): return _UUID(val) raise ValidationError("{} is not a valid uuid".format(value))
def validate(self, value): val = super(UUID, self).validate(value) if val is None: return from uuid import UUID as _UUID if isinstance(val, _UUID): return val if isinstance(val, basestring) and self.re_uuid.match(val): return _UUID(val) raise ValidationError("{} is not a valid uuid".format(value))
def random(cls, as_hex=True): """ Return a random UUID backed by a cryptographically strong PRNG. """ # we set the attr lazily to circumvent a prefork issue # in the Crypto libraru. if not hasattr(cls, '_random'): setattr(cls, '_random', _Random.new()) uuid = _UUID(bytes=cls._random.read(16)) return uuid.hex if as_hex else uuid
def delete_ontology(self, ontology_id): try: # check ontology exists ontology = self.dtl.ontology.get(ontology_id=_UUID(ontology_id)) try: name = ontology.name except: raise Exception('ontology does not exist') # delete ontology self.dtl.ontology.delete(ontology_id=_UUID(ontology_id)) print('ontology \'{0}\' deleted ...'.format(name)) return (True) except Exception as ex: print('error deleting ontology (id=\'{0}\') :: {1}'.format( ontology_id, ex)) return (False)
def _py_uuid(self, new=False, py=False): if not self.hasAttr(UUID_ATTR_NAME): self.addAttr(UUID_ATTR_NAME, 'string') new = True plug = self.plug_(UUID_ATTR_NAME) if new: val = _uuid4() plug.set(str(val)) return val else: return _UUID(plug.get())
def validate(self, value): val = super(UUID, self).validate(value) if val is None: return from uuid import UUID as _UUID if isinstance(val, _UUID): return val if isinstance(val, six.string_types): try: return _UUID(val) except ValueError: raise ValidationError("{} {} is not a valid uuid".format( self.column_name, value))
def __init__( self, uuid: _Union[_UUID, str] = None, username: str = None, ) -> None: if uuid is not None and not isinstance(uuid, _UUID): uuid = _UUID(uuid) super().__init__() self.uuid = uuid self.username = username
def validate(self, value): val = super(UUID, self).validate(value) if val is None: return if isinstance(val, _UUID): return val if isinstance(val, six.string_types): try: return _UUID(val) except ValueError: # fall-through to error pass raise ValidationError("{0} {1} is not a valid uuid".format( self.column_name, value))
def get_streams(self, as_df=True, stream_id=None): streams = [] try: # check if id entered if stream_id is None: # get a list for stream in self.dtl.stream_collection.list(): if as_df: streams.append({ 'stream_id': stream.id, 'stream_name': stream.name }) else: streams.append(stream) else: # get an individual try: if as_df: stream = self.dtl.stream_collection.get( stream_collection_id=_UUID(stream_id)) streams.append({ 'stream_id': stream.id, 'stream_name': stream.name }) else: streams.append(stream) except: raise Exception('invalid pipeline id') # return dataframe if len(streams) > 0: if as_df: return (_pd.DataFrame(streams)[[ 'stream_id', 'stream_name' ]]) else: return (streams) else: print('no pipelines available') return (None) except Exception as ex: print('error getting pipelines ({0}) :: {1}'.format( 'multiple' if stream_id is None else 'single', ex))
def delete_data_stores(self, store_id=None, exclude=None): try: # delete all stores if store_id is None: store_count = len(self.dtl.datastore.list()) for store in self.dtl.datastore.list(): if exclude is None: self.dtl.datastore.delete(datastore_id=store.id) else: if store.id not in exclude: self.dtl.datastore.delete(datastore_id=store.id) if len(self.dtl.datastore.list()) == 0: print('{0} data stores deleted ...'.format(store_count)) else: # delete a single store self.dtl.datastore.delete(datastore_id=_UUID(store_id)) print('data store deleted ...') except Exception as ex: print('error deleting data stores ({0}) :: {1}'.format( 'multiple' if store_id is None else 'single', ex))
def consume_payload(self, it: _Union[_ByteString, _Iterator[int]]) -> None: it = iter(it) self.uuid = _UUID(_iterutils.consume_string(it)) self.username = _iterutils.consume_string(it) () = it
def parse_value(value): return _UUID(value)
def test_hex(self): hex = "a8098c1a-f86e-11da-bd1a-00112444be1e" uuid = _UUID(hex=hex) cyuuid = UUID(hex=hex) self.assertEqual(uuid, cyuuid)
def test_bytes(self): _bytes = b'\xa8\t\x8c\x1a\xf8n\x11\xda\xbd\x1a\x00\x11$D\xbe\x1e' uuid = _UUID(bytes=_bytes) cyuuid = UUID(bytes=_bytes) self.assertEqual(uuid, cyuuid)
def test_bytes_le(self): bytes_le = b'\x1a\x8c\t\xa8n\xf8\xda\x11\xbd\x1a\x00\x11$D\xbe\x1e' uuid = _UUID(bytes_le=bytes_le) cyuuid = UUID(bytes_le=bytes_le) self.assertEqual(uuid, cyuuid)
def test_fields(self): fields = (0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678) uuid = _UUID(fields=fields) cyuuid = UUID(fields=fields) self.assertEqual(uuid, cyuuid)
def test_int(self): _int = 223359875637754765292326297443183672862 uuid = _UUID(int=_int) cyuuid = UUID(int=_int) self.assertEqual(uuid, cyuuid)
def get_data_collections(self, datastore=False, as_df=True, collection_id=None): collections = [] flag = False try: # check if id entered if collection_id is None: # get a list for collection in self.dtl.datastore_collection.list(): if as_df: if not datastore or len(collection.storeIds) == 0: collections.append({ 'collection_id': collection.id, 'collection_name': collection.name }) else: for store in collection.storeIds: collections.append({ 'collection_id': collection.id, 'collection_name': collection.name, 'store_id': store['id'], 'store_name': store['name'] }) flag = True else: collections.append(collection) else: # get an individual collection try: collection = self.dtl.datastore_collection.get( datastore_collection_id=_UUID(collection_id)) if as_df: if not datastore or len(collection.storeIds) == 0: collections.append({ 'collection_id': collection.id, 'collection_name': collection.name }) else: for store in collection.storeIds: collections.append({ 'collection_id': collection.id, 'collection_name': collection.name, 'store_id': store['id'], 'store_name': store['name'] }) flag = True else: collections.append(collection) except: raise Exception('invalid collection id') # return dataframe if len(collections) > 0: if as_df: if flag: return (_pd.DataFrame(collections)[[ 'collection_id', 'collection_name', 'store_id', 'store_name' ]]) else: return (_pd.DataFrame(collections)[[ 'collection_id', 'collection_name' ]]) else: return (collections) else: print('no data collections available') return (None) except Exception as ex: print('error getting data collections ({0}) :: {1}'.format( 'multiple' if collection_id is None else 'single', ex))
def _decode(self, obj, context): return str(_UUID(bytes_le=obj))
def setUp(self): self._uuid = _UUID("a8098c1a-f86e-11da-bd1a-00112444be1e") self._cyuuid = UUID("a8098c1a-f86e-11da-bd1a-00112444be1e")
def parse_literal(node): if isinstance(node, StringValueNode): return _UUID(node.value)
def parse_literal(node): if isinstance(node, ast.StringValue): return _UUID(node.value)
def serialize(uuid): if isinstance(uuid, str): uuid = _UUID(uuid) assert isinstance(uuid, _UUID), "Expected UUID instance, received {}".format(uuid) return str(uuid)