def coll_to_tuples(cls, coll): """Generate 'conformant' tuples from an input collection, similar to itertuples""" raise exc.CollectionDefinitionError( property='coll_to_tuples', coll='Collection', )
def json_to_initkwargs(cls, json_struct, kwargs): member_type = cls.itemtype if not member_type: raise exc.CollectionDefinitionError( coll="JsonRecordDict", property='itemtype', ) if kwargs.get('values', None) is None: kwargs['values'] = values = {} if json_struct is None: json_struct = {} if not isinstance(json_struct, collections.Mapping): raise exc.JsonCollectionCoerceError( passed=json_struct, colltype=cls, ) if hasattr(member_type, "from_json"): for k, x in cls.coll_to_tuples(json_struct): try: values[k] = (x if isinstance(x, member_type) else member_type.from_json(x)) except Exception as e: raise _box_ingress_error(k, e) elif issubclass(member_type, Record): for k, x in cls.coll_to_tuples(json_struct): try: values[k] = (x if isinstance(x, member_type) else from_json(member_type, x)) except Exception as e: raise _box_ingress_error(k, e) else: kwargs['values'] = json_struct return kwargs
def itertuples(self): """Iterate over the items in the collection; return (k, v) where k is the key, index etc into the collection (or potentially the value itself, for sets). This form is the *tuple protocol*""" raise exc.CollectionDefinitionError( property='itertuples', coll='Collection', )
def tuples_to_coll(cls, generator, coerce=False): """*required virtual method* This class method, part of the sub-class API, converts a generator of ``(K, V)`` tuples (the *tuple protocol*) to one of the underlying collection type. """ if cls != Collection: raise exc.CollectionDefinitionError( property='tuples_to_coll', coll='Collection', )
def json_to_initkwargs(cls, json_struct, kwargs): member_type = cls.itemtype if kwargs.get('values', None) is None: kwargs['values'] = values = [] if not json_struct: json_struct = tuple() if hasattr(member_type, "from_json"): for x in json_struct: values.append(member_type.from_json(x)) elif issubclass(member_type, Record): for x in json_struct: values.append(from_json(member_type, x)) else: raise exc.CollectionDefinitionError( coll="JsonRecordList", property='itemtype', ) return kwargs
def colltype(cls): raise exc.CollectionDefinitionError( property='colltype', coll='Collection', )