Pass in a list of fields (as strings) to get a dict with the
    field name as a key and a randomly generated value as another
321070
def get_random_values(fields):
    
    values = {}

    for field in fields:
        try:
            value = get_random_value(field)
        except AttributeError:
            # this can only really occur if the field is not implemented yet.
            # Silencing the exception during the prototype phase
            value = None

        values.update({field: value})

    return values
107186
def get_fields_by_prop(cls, prop_key, prop_val):
        

        ret = []

        for key, val in cls.get_fields_with_prop(prop_key):
            if val == prop_val:
                ret.append(key)
        return ret
476504
def shuffle(self):
        
        order = range(len(self))
        random.shuffle(order)
        for name, data in self.fields.items():
            reindexed = []
            for _, i in enumerate(order):
                reindexed.append(data[i])
            self.fields[name] = reindexed
        return self
298361
def export_to_dicts(table, *args, **kwargs):
    """"""
    field_names = table.field_names
    return [{key: getattr(row, key) for key in field_names} for row in table]
715058
def sql_to_dict(self, query, param):
        
        cursor = connection.cursor()
        cursor.execute(query, param)
        fieldnames = [name[0] for name in cursor.description]
        result = []
        for row in cursor.fetchall():
            rowset = []
            for field in zip(fieldnames, row):
                rowset.append(field)
            result.append(dict(rowset))
        return result
335085
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'fields' in _dict:
            args['fields'] = [
                Field._from_dict(x) for x in (_dict.get('fields'))
            ]
        return cls(**args)
1138166
def pkeys(self,parent,field):
    ""
    template=[(parent[k] if k is not None else None) for k in self.pkey]
    inull=template.index(None)
    def mk(x):
      "helper for constructing pkey tuples in a list comp"
      template[inull]=x
      return tuple(template)
    val=parent[field]
    if self.getter is not None: return map(mk,self.getter(val))
    elif isinstance(val,VDList): return map(mk,val.generate())
    else: raise NotImplementedError(type(val))
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
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
        }
174321
def make_field_objects(field_data, names):
        # type: (List[Dict[Text, Text]], Names) -> List[Field]
        """"""
        field_objects = []
        field_names = []  # type: List[Text]
        for field in field_data:
            if hasattr(field, 'get') and callable(field.get):
                atype = cast(Text, field.get('type'))
                name = cast(Text, field.get('name'))

                # null values can have a default value of None
                has_default = False
                default = None
                if 'default' in field:
                    has_default = True
                    default = field.get('default')

                order = field.get('order')
                doc = field.get('doc')
                other_props = get_other_props(field, FIELD_RESERVED_PROPS)
                new_field = Field(atype, name, has_default, default, order, names, doc,
                                 other_props)
                # make sure field name has not been used yet
                if new_field.name in field_names:
                    fail_msg = 'Field name %s already in use.' % new_field.name
                    raise SchemaParseException(fail_msg)
                field_names.append(new_field.name)
            else:
                raise SchemaParseException('Not a valid field: %s' % field)
            field_objects.append(new_field)
        return field_objects
713169
def _param_fields(kwargs, fields):
  
  if fields is None:
    return
  if type(fields) in [list, set, frozenset, tuple]:
    fields = {x: True for x in fields}
  if type(fields) == dict:
    fields.setdefault("_id", False)
  kwargs["projection"] = fields
1172846
def ListField(field):
    
    # alter the original field's get_from_instance so it iterates over the
    # values that the field's get_from_instance() method returns
    original_get_from_instance = field.get_from_instance

    def get_from_instance(self, instance):
        for value in original_get_from_instance(instance):
            yield value

    field.get_from_instance = MethodType(get_from_instance, field)

    return field
290989
def get_aggregations_fields(cls, params):
        
        fields = []
        for key, val in params.items():
            if isinstance(val, dict):
                fields += cls.get_aggregations_fields(val)
            if key == 'field':
                fields.append(val)
        return fields
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()}
1092132
def set_fields(self, fields=None, *fields_args, **fields_kwargs):
        
        if fields_args:
            fields = [fields]
            fields.extend(fields_args)
            for field_name in fields:
                self.set_field(field_name)

        elif fields_kwargs:
            fields = make_dict(fields, fields_kwargs)
            for field_name, field_val in fields.items():
                self.set_field(field_name, field_val)

        else:
            if isinstance(fields, Mapping):
                for field_name, field_val in fields.items():
                    self.set_field(field_name, field_val)

            else:
                for field_name in fields:
                    self.set_field(field_name)

        return self
727633
def setup_fields(attrs):
    
    fields = {}
    iterator = list(attrs.items())
    for key, value in iterator:
        if not isinstance(value, Field):
            continue
        fields[key] = value
        del attrs[key]
    return fields
80432
def _with_fields(*fields):
    
    dd = {}
    for x in fields:
        dd[x] = _COMMON_FIELDS[x]

    def wrap(cls):
        dd.update(cls.__dict__)
        return type(cls.__name__, cls.__bases__, dd)

    return wrap