<s> """<STR_LIT>""" <EOL> from . import model <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> class _BaseMetadata ( model . Model ) : <EOL> """<STR_LIT>""" <EOL> _use_cache = False <EOL> _use_memcache = False <EOL> KIND_NAME = '<STR_LIT>' <EOL> @ classmethod <EOL> def _get_kind ( cls ) : <EOL> """<STR_LIT>""" <EOL> return cls . KIND_NAME <EOL> class Namespace ( _BaseMetadata ) : <EOL> """<STR_LIT>""" <EOL> KIND_NAME = '<STR_LIT>' <EOL> EMPTY_NAMESPACE_ID = <NUM_LIT:1> <EOL> @ property <EOL> def namespace_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . key_to_namespace ( self . key ) <EOL> @ classmethod <EOL> def key_for_namespace ( cls , namespace ) : <EOL> """<STR_LIT>""" <EOL> if namespace : <EOL> return model . Key ( cls . KIND_NAME , namespace ) <EOL> else : <EOL> return model . Key ( cls . KIND_NAME , cls . EMPTY_NAMESPACE_ID ) <EOL> @ classmethod <EOL> def key_to_namespace ( cls , key ) : <EOL> """<STR_LIT>""" <EOL> return key . string_id ( ) or '<STR_LIT>' <EOL> class Kind ( _BaseMetadata ) : <EOL> """<STR_LIT>""" <EOL> KIND_NAME = '<STR_LIT>' <EOL> @ property <EOL> def kind_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . key_to_kind ( self . key ) <EOL> @ classmethod <EOL> def key_for_kind ( cls , kind ) : <EOL> """<STR_LIT>""" <EOL> return model . Key ( cls . KIND_NAME , kind ) <EOL> @ classmethod <EOL> def key_to_kind ( cls , key ) : <EOL> """<STR_LIT>""" <EOL> return key . id ( ) <EOL> class Property ( _BaseMetadata ) : <EOL> """<STR_LIT>""" <EOL> KIND_NAME = '<STR_LIT>' <EOL> @ property <EOL> def property_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . key_to_property ( self . key ) <EOL> @ property <EOL> def kind_name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . key_to_kind ( self . key ) <EOL> property_representation = model . StringProperty ( repeated = True ) <EOL> @ classmethod <EOL> def key_for_kind ( cls , kind ) : <EOL> """<STR_LIT>""" <EOL> return model . Key ( Kind . KIND_NAME , kind ) <EOL> @ classmethod <EOL> def key_for_property ( cls , kind , property ) : <EOL> """<STR_LIT>""" <EOL> return model . Key ( Kind . KIND_NAME , kind , Property . KIND_NAME , property ) <EOL> @ classmethod <EOL> def key_to_kind ( cls , key ) : <EOL> """<STR_LIT>""" <EOL> if key . kind ( ) == Kind . KIND_NAME : <EOL> return key . id ( ) <EOL> else : <EOL> return key . parent ( ) . id ( ) <EOL> @ classmethod <EOL> def key_to_property ( cls , key ) : <EOL> """<STR_LIT>""" <EOL> if key . kind ( ) == Kind . KIND_NAME : <EOL> return None <EOL> else : <EOL> return key . id ( ) <EOL> class EntityGroup ( _BaseMetadata ) : <EOL> """<STR_LIT>""" <EOL> KIND_NAME = '<STR_LIT>' <EOL> ID = <NUM_LIT:1> <EOL> version = model . IntegerProperty ( name = '<STR_LIT>' ) <EOL> @ classmethod <EOL> def key_for_entity_group ( cls , key ) : <EOL> """<STR_LIT>""" <EOL> return model . Key ( cls . KIND_NAME , cls . ID , parent = key . root ( ) ) <EOL> def get_namespaces ( start = None , end = None ) : <EOL> """<STR_LIT>""" <EOL> q = Namespace . query ( ) <EOL> if start is not None : <EOL> q = q . filter ( Namespace . key >= Namespace . key_for_namespace ( start ) ) <EOL> if end is not None : <EOL> q = q . filter ( Namespace . key < Namespace . key_for_namespace ( end ) ) <EOL> return [ x . namespace_name for x in q ] <EOL> def get_kinds ( start = None , end = None ) : <EOL> """<STR_LIT>""" <EOL> q = Kind . query ( ) <EOL> if start is not None and start != '<STR_LIT>' : <EOL> q = q . filter ( Kind . key >= Kind . key_for_kind ( start ) ) <EOL> if end is not None : <EOL> if end == '<STR_LIT>' : <EOL> return [ ] <EOL> q = q . filter ( Kind . key < Kind . key_for_kind ( end ) ) <EOL> return [ x . kind_name for x in q ] <EOL> def get_properties_of_kind ( kind , start = None , end = None ) : <EOL> """<STR_LIT>""" <EOL> q = Property . query ( ancestor = Property . key_for_kind ( kind ) ) <EOL> if start is not None and start != '<STR_LIT>' : <EOL> q = q . filter ( Property . key >= Property . key_for_property ( kind , start ) ) <EOL> if end is not None : <EOL> if end == '<STR_LIT>' : <EOL> return [ ] <EOL> q = q . filter ( Property . key < Property . key_for_property ( kind , end ) ) <EOL> return [ Property . key_to_property ( k ) for k in q . iter ( keys_only = True ) ] <EOL> def get_representations_of_kind ( kind , start = None , end = None ) : <EOL> """<STR_LIT>""" <EOL> q = Property . query ( ancestor = Property . key_for_kind ( kind ) ) <EOL> if start is not None and start != '<STR_LIT>' : <EOL> q = q . filter ( Property . key >= Property . key_for_property ( kind , start ) ) <EOL> if end is not None : <EOL> if end == '<STR_LIT>' : <EOL> return { } <EOL> q = q . filter ( Property . key < Property . key_for_property ( kind , end ) ) <EOL> result = { } <EOL> for property in q : <EOL> result [ property . property_name ] = property . property_representation <EOL> return result <EOL> def get_entity_group_version ( key ) : <EOL> """<STR_LIT>""" <EOL> eg = EntityGroup . key_for_entity_group ( key ) . get ( ) <EOL> if eg : <EOL> return eg . version <EOL> else : <EOL> return None </s>
