Given an instance of a serializer field, return a dictionary
        of metadata about it.
767192
def get_field_info(self, field):
        
        field_info = OrderedDict()
        field_info['type'] = self.label_lookup[field]
        field_info['required'] = getattr(field, 'required', False)

        attrs = [
            'read_only', 'label', 'help_text',
            'min_length', 'max_length',
            'min_value', 'max_value'
        ]

        for attr in attrs:
            value = getattr(field, attr, None)
            if value is not None and value != '':
                field_info[attr] = force_text(value, strings_only=True)

        if getattr(field, 'child', None):
            field_info['child'] = self.get_field_info(field.child)
        elif getattr(field, 'fields', None):
            field_info['children'] = self.get_serializer_info(field)

        if not field_info.get('read_only') and hasattr(field, 'choices'):
            field_info['choices'] = [
                {
                    'value': choice_value,
                    'display_name': force_text(choice_name, strings_only=True)
                }
                for choice_value, choice_name in field.choices.items()
            ]

        return field_info
128178
def struct2dict(struct):
    """"""
    return {x: getattr(struct, x) for x in dict(struct._fields_).keys()}
1329162
def metainfo_to_dict(self) -> dict:
        ''''''

        r = {
            "version": self.version,
            "amount": self.amount,
            "number_of_decimals": self.number_of_decimals
        }

        if self.asset_specific_data:
            r.update({'asset_specific_data': self.asset_specific_data})

        return r
798050
def get_metadata(headers):
  """"""
  return dict((k, v) for k, v in headers.iteritems()
              if any(k.lower().startswith(valid) for valid in _GCS_METADATA))
196359
def to_serializable_value(self):
        
        return {
            name: field.to_serializable_value()
            for name, field in self.value.__dict__.items()
            if isinstance(field, Field) and self.value
        }
121359
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'model') and self.model is not None:
            _dict['model'] = self.model
        return _dict
628744
def get_serializer_info(self, serializer):
        
        if hasattr(serializer, 'child'):
            # If this is a `ListSerializer` then we want to examine the
            # underlying child serializer instance instead.
            serializer = serializer.child
        return self.get_fields(serializer.fields)
1149812
def obj_to_dict(cls, obj):
        
        data = {}
        for field_name in cls.get_fields():
            try:
                value = getattr(obj, field_name)
            except AttributeError:
                # If the field doesn't exist on the object, fail gracefully
                # and don't include the field in the data dict at all. Fail
                # loudly if the field exists but produces a different error
                # (edge case: accessing an *existing* field could technically
                # produce an unrelated AttributeError).
                continue

            if callable(value):
                value = value()
            data[field_name] = value

        return data
767920
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'models') and self.models is not None:
            _dict['models'] = [x._to_dict() for x in self.models]
        return _dict
1007743
def to_dict(self, field):
        """"""
        assert field in self._fields, "This field doesn't exist"
        return {cluster: self.get(field, cluster)
                for cluster in self._data.keys()}
382912
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'id') and self.id is not None:
            _dict['id'] = self.id
        if hasattr(self, 'metadata') and self.metadata is not None:
            _dict['metadata'] = self.metadata
        if hasattr(self, 'collection_id') and self.collection_id is not None:
            _dict['collection_id'] = self.collection_id
        if hasattr(self,
                   'result_metadata') and self.result_metadata is not None:
            _dict['result_metadata'] = self.result_metadata._to_dict()
        if hasattr(self, 'title') and self.title is not None:
            _dict['title'] = self.title
        if hasattr(self, '_additionalProperties'):
            for _key in self._additionalProperties:
                _value = getattr(self, _key, None)
                if _value is not None:
                    _dict[_key] = _value
        return _dict
1274005
def metadata(self):
        """"""
        if not self._operation.HasField("metadata"):
            return None

        return protobuf_helpers.from_any_pb(
            self._metadata_type, self._operation.metadata
        )
372375
def fields_from_dict(d):
        """"""
        class_container = FieldsContainer.class_container
        fields = [field_cls.from_dict(field_dict) 
                  for field_cls, container in class_container.iteritems()
                  for field_dict in d.get(container, [])]
        return fields
1225834
def to_dict(self, include_readonly=True, field_names=None):
        '''
        
        '''
        fields = self.fields(writable=not include_readonly)

        if field_names is not None:
            fields = [f for f in fields if f in field_names]

        data = self.__dict__
        return {name: data[name] for name in fields}
845548
def get_field_names(self, declared_fields, info):
        
        meta_fields = getattr(self.Meta, 'meta_fields', [])

        declared = OrderedDict()
        for field_name in set(declared_fields.keys()):
            field = declared_fields[field_name]
            if field_name not in meta_fields:
                declared[field_name] = field
        fields = super(ModelSerializer, self).get_field_names(declared, info)
        return list(fields) + list(getattr(self.Meta, 'meta_fields', list()))
1139826
def metadata(self):
        
        # Check exceptional case: return none if no metadata
        if not self._operation.HasField('metadata'):
            return None

        # Return expected metadata
        return _from_any(self._metadata_type, self._operation.metadata)
623931
def metadata(self):
        """"""
        auto = {u'records': self.size}
        auto.update(self.meta)
        return auto