示例#1
0
 def get_spec_for_field(self, field):
     return (
         field.field_id,
         get_backend_type("thrift", field.field_type.type_id),
         field.field_name,
         self.get_spec_type_parameter(field.field_type),
         field.default,)
示例#2
0
 def test_simple_field(self):
     FIELD_TYPE = types.Int()
     FIELD_NAME = "apple"
     FIELD_ID = 1
     DEFAULT = "1"
     field = Field(
         field_type=FIELD_TYPE,
         field_name=FIELD_NAME,
         field_id=FIELD_ID,
         default=DEFAULT)
     self.assertEquals(
         self.get_field_spec(field),
         (FIELD_ID,
          get_backend_type("thrift", field.field_type.type_id),
          FIELD_NAME,
          None,
          DEFAULT))
示例#3
0
 def get_spec_type_parameter(self, field_type):
     """ Returns value 3 of the element
         in thrift_spec which defines this field. """
     # tuples are encoded as structs
     if isinstance(field_type, types.Tuple):
         return self.get_tuple_type_parameter(field_type)
     # structs are a special case
     if isinstance(field_type, types.Struct):
         interface_class = field_type.get_python_type()
         implementation_class = self.model_registry.lookup(interface_class)
         return (implementation_class, self.get_spec(implementation_class))
     # If there are no type parameters, return None
     if not field_type.type_parameters:
         return None
     # lists, sets, maps
     spec_list = []
     for t in field_type.type_parameters:
         # for each type_parameter, first add the type's id
         spec_list.append(get_backend_type("thrift", t.type_id))
         # then the type's parameters
         spec_list.append(self.get_spec_type_parameter(t))
     return spec_list
示例#4
0
文件: types.py 项目: neumark/unimodel
 def get_python_type(self):
     from unimodel.util import get_backend_type
     return get_backend_type("python", self.type_id)
示例#5
0
 def define_basic_field(self, type_definition):
     return copy.deepcopy(get_backend_type("json", type_definition.type_id))