nodes: 0, module; 1, function_definition; 2, function_name:MakeSimpleProtoClass; 3, parameters; 4, block; 5, identifier:fields; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, comment:# Get a list of (name, field_type) tuples from the fields dict. If fields was; 12, comment:# an OrderedDict we keep the order, but otherwise we sort the field to ensure; 13, comment:# consistent ordering.; 14, expression_statement; 15, if_statement; 16, comment:# Use a consistent file name that is unlikely to conflict with any imported; 17, comment:# proto files.; 18, expression_statement; 19, for_statement; 20, expression_statement; 21, comment:# If the proto is anonymous, use the same hash to name it.; 22, if_statement; 23, comment:# This is the first time we see this proto: add a new descriptor to the pool.; 24, expression_statement; 25, return_statement; 26, identifier:full_name; 27, None; 28, identifier:pool; 29, None; 30, comment:"""Create a Protobuf class whose fields are basic types.
  
    Note: this doesn't validate field names!
  
    Args:
      fields: dict of {name: field_type} mappings for each field in the proto. If
          this is an OrderedDict the order will be maintained, otherwise the
          fields will be sorted by name.
      full_name: optional str, the fully-qualified name of the proto type.
      pool: optional DescriptorPool instance.
    Returns:
      a class, the new protobuf class with a FileDescriptor.
    """; 31, assignment; 32, comparison_operator:full_name is not None; 33, block; 34, assignment; 35, not_operator; 36, block; 37, assignment; 38, pattern_list; 39, identifier:field_items; 40, block; 41, assignment; 42, comparison_operator:full_name is None; 43, block; 44, call; 45, call; 46, identifier:factory; 47, call; 48, identifier:full_name; 49, None; 50, try_statement; 51, identifier:field_items; 52, call; 53, call; 54, expression_statement; 55, identifier:fields_hash; 56, call; 57, identifier:f_name; 58, identifier:f_type; 59, expression_statement; 60, expression_statement; 61, identifier:proto_file_name; 62, binary_operator:fields_hash.hexdigest() + '.proto'; 63, identifier:full_name; 64, None; 65, expression_statement; 66, try_statement; 67, attribute; 68, argument_list; 69, identifier:_GetMessageFromFactory; 70, argument_list; 71, attribute; 72, argument_list; 73, block; 74, except_clause; 75, attribute; 76, argument_list; 77, identifier:isinstance; 78, argument_list; 79, assignment; 80, attribute; 81, argument_list; 82, call; 83, call; 84, call; 85, string; 86, assignment; 87, block; 88, except_clause; 89, attribute; 90, identifier:Add; 91, call; 92, identifier:factory; 93, identifier:full_name; 94, identifier:message_factory; 95, identifier:MessageFactory; 96, keyword_argument; 97, expression_statement; 98, return_statement; 99, identifier:KeyError; 100, comment:# The factory's DescriptorPool doesn't know about this class yet.; 101, block; 102, identifier:fields; 103, identifier:items; 104, identifier:fields; 105, identifier:OrderedDict; 106, identifier:field_items; 107, call; 108, identifier:hashlib; 109, identifier:sha1; 110, attribute; 111, argument_list; 112, attribute; 113, argument_list; 114, attribute; 115, argument_list; 116, string_content:.proto; 117, identifier:full_name; 118, parenthesized_expression; 119, expression_statement; 120, return_statement; 121, identifier:KeyError; 122, comment:# The factory's DescriptorPool doesn't know about this class yet.; 123, block; 124, identifier:factory; 125, identifier:pool; 126, identifier:_MakeFileDescriptorProto; 127, argument_list; 128, identifier:pool; 129, identifier:pool; 130, assignment; 131, identifier:proto_cls; 132, pass_statement; 133, identifier:sorted; 134, argument_list; 135, identifier:fields_hash; 136, identifier:update; 137, call; 138, identifier:fields_hash; 139, identifier:update; 140, call; 141, identifier:fields_hash; 142, identifier:hexdigest; 143, binary_operator:'net.proto2.python.public.proto_builder.AnonymousProto_' +
                   fields_hash.hexdigest(); 144, assignment; 145, identifier:proto_cls; 146, pass_statement; 147, identifier:proto_file_name; 148, identifier:full_name; 149, identifier:field_items; 150, identifier:proto_cls; 151, call; 152, identifier:field_items; 153, attribute; 154, argument_list; 155, attribute; 156, argument_list; 157, string; 158, call; 159, identifier:proto_cls; 160, call; 161, identifier:_GetMessageFromFactory; 162, argument_list; 163, identifier:f_name; 164, identifier:encode; 165, string; 166, call; 167, identifier:encode; 168, string; 169, string_content:net.proto2.python.public.proto_builder.AnonymousProto_; 170, attribute; 171, argument_list; 172, identifier:_GetMessageFromFactory; 173, argument_list; 174, identifier:factory; 175, identifier:full_name; 176, string_content:utf-8; 177, identifier:str; 178, argument_list; 179, string_content:utf-8; 180, identifier:fields_hash; 181, identifier:hexdigest; 182, identifier:factory; 183, identifier:full_name; 184, identifier:f_type
code: def MakeSimpleProtoClass(fields, full_name=None, pool=None):
    """Create a Protobuf class whose fields are basic types.
  
    Note: this doesn't validate field names!
  
    Args:
      fields: dict of {name: field_type} mappings for each field in the proto. If
          this is an OrderedDict the order will be maintained, otherwise the
          fields will be sorted by name.
      full_name: optional str, the fully-qualified name of the proto type.
      pool: optional DescriptorPool instance.
    Returns:
      a class, the new protobuf class with a FileDescriptor.
    """
    factory = message_factory.MessageFactory(pool=pool)
  
    if full_name is not None:
      try:
        proto_cls = _GetMessageFromFactory(factory, full_name)
        return proto_cls
      except KeyError:
        # The factory's DescriptorPool doesn't know about this class yet.
        pass
  
    # Get a list of (name, field_type) tuples from the fields dict. If fields was
    # an OrderedDict we keep the order, but otherwise we sort the field to ensure
    # consistent ordering.
    field_items = fields.items()
    if not isinstance(fields, OrderedDict):
      field_items = sorted(field_items)
  
    # Use a consistent file name that is unlikely to conflict with any imported
    # proto files.
    fields_hash = hashlib.sha1()
    for f_name, f_type in field_items:
      fields_hash.update(f_name.encode('utf-8'))
      fields_hash.update(str(f_type).encode('utf-8'))
    proto_file_name = fields_hash.hexdigest() + '.proto'
  
    # If the proto is anonymous, use the same hash to name it.
    if full_name is None:
      full_name = ('net.proto2.python.public.proto_builder.AnonymousProto_' +
                   fields_hash.hexdigest())
      try:
        proto_cls = _GetMessageFromFactory(factory, full_name)
        return proto_cls
      except KeyError:
        # The factory's DescriptorPool doesn't know about this class yet.
        pass
  
    # This is the first time we see this proto: add a new descriptor to the pool.
    factory.pool.Add(
        _MakeFileDescriptorProto(proto_file_name, full_name, field_items))
    return _GetMessageFromFactory(factory, full_name)