Exemplo n.º 1
0
 def __new__(cls, name, bases, namespace, **kwds):
     props = {}
     if name == 'VertexProperty':
         element_type = name.lower()
     elif bases:
         element_type = bases[0].__type__
         if element_type not in ['vertex', 'edge']:
             element_type = bases[0].__name__.lower()
         for base in bases:
             base_props = getattr(base, '__properties__', {})
             props.update(base_props)
     else:
         element_type = name.lower()
     namespace['__type__'] = element_type
     if not namespace.get('__label__', None):
         namespace['__label__'] = inflection.underscore(name)
     new_namespace = {}
     props.pop('id', None)
     for k, v in namespace.items():
         if isinstance(v, abc.BaseProperty):
             if element_type == 'edge' and hasattr(v, 'cardinality'):
                 raise exception.MappingError(
                     'Edge property cannot have set/list cardinality')
             props[k] = v
             if k != 'id':
                 if not v.db_name:
                     v.db_name = v.db_name_factory(k,
                                                   namespace['__label__'])
             v = v.__descriptor__(k, v)
         new_namespace[k] = v
     new_namespace['__mapping__'] = mapper.create_mapping(namespace, props)
     new_namespace['__properties__'] = props
     result = type.__new__(cls, name, bases, new_namespace)
     return result
Exemplo n.º 2
0
 def __new__(cls, name, bases, namespace, **kwds):
     props = {}
     if name == 'VertexProperty':
         element_type = name.lower()
     elif bases:
         element_type = bases[0].__type__
         if element_type not in ['vertex', 'edge']:
             element_type = bases[0].__name__.lower()
         for base in bases:
             base_props = getattr(base, '__properties__', {})
             props.update(base_props)
     else:
         element_type = name.lower()
     namespace['__type__'] = element_type
     if not namespace.get('__label__', None):
         namespace['__label__'] = inflection.underscore(name)
     new_namespace = {}
     props.pop('id', None)
     for k, v in namespace.items():
         if isinstance(v, abc.BaseProperty):
             if element_type == 'edge' and hasattr(v, 'cardinality'):
                 raise exception.MappingError(
                     'Edge property cannot have set/list cardinality')
             props[k] = v
             v = v.__descriptor__(k, v)
         new_namespace[k] = v
     new_namespace['__mapping__'] = mapper.create_mapping(namespace,
                                                          props)
     new_namespace['__properties__'] = props
     result = type.__new__(cls, name, bases, new_namespace)
     return result