nodes: 0, module; 1, function_definition; 2, function_name:make_dynamic_class; 3, parameters; 4, block; 5, identifier:typename; 6, identifier:field_names; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, return_statement; 20, comment:"""a factory function to create type dynamically
  
      The factory function is used by :func:`objson.load` and :func:`objson.loads`.
      Creating the object deserialize from json string. The inspiration come from
      :func:`collections.namedtuple`. the difference is that I don't your the class
      template to define a dynamic class, instead of, I use the :func:`type` factory
      function.
  
      Class prototype definition ::
  
          class JsonObject(object):
              __identifier__ = "dolphin"
  
              def __init__(self, kv=None):
                  if kv is None:
                      kv = dict()
                  self.__dict__.update(kv)
  
              def __getitem__(self, key):
                  return self.__dict__.get(key)
  
              def __setitem__(self, key, value):
                  self.__dict__[key] = value
  
              def __iter__(self):
                  return iter(self.__dict__)
  
              def __repr__(self):
                  keys = sorted(self.__dict__.keys())
                  text = ', '.join(["%s=%r" % (key, self[key]) for key in keys])
                  return '{%s}' % text
  
              name=_property('name')
  
      Basic Usage ::
  
          from objson import make_dynamic_class, dumps
          Entity = make_dynamic_class('Entity', 'name, sex, age')
          entity = Entity()
          entity.name, entity.sex, entity.age = 'benjamin', 'male', 21
          dumps(entity)
  
      :param typename: dynamic class's name
      :param field_names: a string :class:`list` and a field name string which separated by comma,
          ``['name', 'sex']`` or ``"name,sex"``
  
      :return: a class type
      """; 21, call; 22, block; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, call; 34, identifier:isinstance; 35, argument_list; 36, expression_statement; 37, identifier:field_names; 38, call; 39, identifier:safe_fields_names; 40, call; 41, identifier:attr; 42, call; 43, subscript; 44, identifier:typename; 45, subscript; 46, string:"dolphin"; 47, subscript; 48, identifier:_dynamic__init; 49, subscript; 50, lambda; 51, subscript; 52, identifier:_dynamic__setitem; 53, subscript; 54, lambda; 55, subscript; 56, lambda; 57, identifier:type; 58, argument_list; 59, identifier:field_names; 60, identifier:basestring; 61, assignment; 62, identifier:map; 63, argument_list; 64, identifier:map; 65, argument_list; 66, identifier:dict; 67, generator_expression; 68, identifier:attr; 69, string; 70, identifier:attr; 71, string; 72, identifier:attr; 73, string; 74, identifier:attr; 75, string; 76, lambda_parameters; 77, call; 78, identifier:attr; 79, string; 80, identifier:attr; 81, string; 82, lambda_parameters; 83, call; 84, identifier:attr; 85, string; 86, lambda_parameters; 87, binary_operator:"{%s}" % (', '.join([
                                                              "%s=%r" % (key, self[key]) for key in
                                                              sorted(self.__dict__.keys())
                                                              ])); 88, identifier:typename; 89, tuple; 90, identifier:attr; 91, identifier:field_names; 92, call; 93, identifier:str; 94, identifier:field_names; 95, identifier:_encode_property_name; 96, identifier:field_names; 97, tuple; 98, for_in_clause; 99, string_content:__doc__; 100, string_content:__identifier__; 101, string_content:__init__; 102, string_content:__getitem__; 103, identifier:self; 104, identifier:key; 105, attribute; 106, argument_list; 107, string_content:__setitem__; 108, string_content:__iter__; 109, identifier:self; 110, identifier:iter; 111, argument_list; 112, string_content:__repr__; 113, identifier:self; 114, string:"{%s}"; 115, parenthesized_expression; 116, identifier:object; 117, attribute; 118, argument_list; 119, identifier:safe_name; 120, call; 121, pattern_list; 122, call; 123, attribute; 124, identifier:get; 125, identifier:key; 126, attribute; 127, call; 128, call; 129, identifier:split; 130, identifier:_property; 131, argument_list; 132, identifier:name; 133, identifier:safe_name; 134, identifier:zip; 135, argument_list; 136, identifier:self; 137, identifier:__dict__; 138, identifier:self; 139, identifier:__dict__; 140, attribute; 141, argument_list; 142, attribute; 143, argument_list; 144, identifier:name; 145, identifier:field_names; 146, identifier:safe_fields_names; 147, string; 148, identifier:join; 149, list_comprehension; 150, identifier:field_names; 151, identifier:replace; 152, string:","; 153, string:" "; 154, string_content:,; 155, binary_operator:"%s=%r" % (key, self[key]); 156, for_in_clause; 157, string:"%s=%r"; 158, tuple; 159, identifier:key; 160, call; 161, identifier:key; 162, subscript; 163, identifier:sorted; 164, argument_list; 165, identifier:self; 166, identifier:key; 167, call; 168, attribute; 169, argument_list; 170, attribute; 171, identifier:keys; 172, identifier:self; 173, identifier:__dict__
code: def make_dynamic_class(typename, field_names):
      """a factory function to create type dynamically
  
      The factory function is used by :func:`objson.load` and :func:`objson.loads`.
      Creating the object deserialize from json string. The inspiration come from
      :func:`collections.namedtuple`. the difference is that I don't your the class
      template to define a dynamic class, instead of, I use the :func:`type` factory
      function.
  
      Class prototype definition ::
  
          class JsonObject(object):
              __identifier__ = "dolphin"
  
              def __init__(self, kv=None):
                  if kv is None:
                      kv = dict()
                  self.__dict__.update(kv)
  
              def __getitem__(self, key):
                  return self.__dict__.get(key)
  
              def __setitem__(self, key, value):
                  self.__dict__[key] = value
  
              def __iter__(self):
                  return iter(self.__dict__)
  
              def __repr__(self):
                  keys = sorted(self.__dict__.keys())
                  text = ', '.join(["%s=%r" % (key, self[key]) for key in keys])
                  return '{%s}' % text
  
              name=_property('name')
  
      Basic Usage ::
  
          from objson import make_dynamic_class, dumps
          Entity = make_dynamic_class('Entity', 'name, sex, age')
          entity = Entity()
          entity.name, entity.sex, entity.age = 'benjamin', 'male', 21
          dumps(entity)
  
      :param typename: dynamic class's name
      :param field_names: a string :class:`list` and a field name string which separated by comma,
          ``['name', 'sex']`` or ``"name,sex"``
  
      :return: a class type
      """
      if isinstance(field_names, basestring):
          field_names = field_names.replace(",", " ").split()
      field_names = map(str, field_names)
  
      safe_fields_names = map(_encode_property_name, field_names)
  
      attr = dict((safe_name, _property(name)) for name, safe_name in zip(field_names, safe_fields_names))
      attr['__doc__'] = typename
      attr['__identifier__'] = "dolphin"
      attr['__init__'] = _dynamic__init
      attr['__getitem__'] = lambda self, key: self.__dict__.get(key)
      attr['__setitem__'] = _dynamic__setitem
      attr['__iter__'] = lambda self: iter(self.__dict__)
      attr['__repr__'] = lambda self: "{%s}" % (', '.join([
                                                              "%s=%r" % (key, self[key]) for key in
                                                              sorted(self.__dict__.keys())
                                                              ]))
  
      return type(typename, (object,), attr)