Creates a default instance of a basic non-relational field.
325926
def get_field_kwargs(self, field_name, model_field):
        
        kwargs = {}
        validator_kwarg = list(model_field.validators)

        # The following will only be used by ModelField classes.
        # Gets removed for everything else.
        kwargs['model_field'] = model_field

        if model_field.verbose_name and needs_label(model_field, field_name):
            kwargs['label'] = capfirst(model_field.verbose_name)

        if model_field.help_text:
            kwargs['help_text'] = model_field.help_text

        max_digits = getattr(model_field, 'max_digits', None)
        if max_digits is not None:
            kwargs['max_digits'] = max_digits

        decimal_places = getattr(model_field, 'decimal_places', None)
        if decimal_places is not None:
            kwargs['decimal_places'] = decimal_places

        if isinstance(model_field, models.TextField):
            kwargs['style'] = {'base_template': 'textarea.html'}

        if isinstance(model_field, models.AutoField) \
                or not model_field.editable:
            # If this field is read-only, then return early.
            # Further keyword arguments are not valid.
            kwargs['read_only'] = True
            return kwargs

        if model_field.has_default or model_field.blank or model_field.null:
            kwargs['required'] = False

        if model_field.null and not isinstance(model_field,
                                               models.NullBooleanField):
            kwargs['allow_null'] = True

        if model_field.blank and (
            isinstance(model_field, models.CharField) or
            isinstance(model_field, models.TextField) or
            isinstance(model_field, columns.Text)
        ):
            kwargs['allow_blank'] = True

        if isinstance(model_field, models.FilePathField):
            kwargs['path'] = model_field.path

            if model_field.match is not None:
                kwargs['match'] = model_field.match

            if model_field.recursive is not False:
                kwargs['recursive'] = model_field.recursive

            if model_field.allow_files is not True:
                kwargs['allow_files'] = model_field.allow_files

            if model_field.allow_folders is not False:
                kwargs['allow_folders'] = model_field.allow_folders

        if model_field.choices:
            # If this model field contains choices, then return early.
            # Further keyword arguments are not valid.
            kwargs['choices'] = model_field.choices
            return kwargs

        # Our decimal validation is handled in the field code,
        # not validator code.
        # (In Django 1.9+ this differs from previous style)
        if isinstance(model_field, models.DecimalField) and DecimalValidator:
            validator_kwarg = [
                validator for validator in validator_kwarg
                if not isinstance(validator, DecimalValidator)
            ]

        # Ensure that max_length is passed explicitly as a keyword arg,
        # rather than as a validator.
        max_length = getattr(model_field, 'max_length', None)
        if max_length is not None and (
                    isinstance(model_field, models.CharField) or
                    isinstance(model_field, models.TextField)):
            kwargs['max_length'] = max_length
            validator_kwarg = [
                validator for validator in validator_kwarg
                if not isinstance(validator, validators.MaxLengthValidator)
            ]

        # Ensure that min_length is passed explicitly as a keyword arg,
        # rather than as a validator.
        min_length = next((
            validator.limit_value for validator in validator_kwarg
            if isinstance(validator, validators.MinLengthValidator)
        ), None)
        if min_length is not None and isinstance(model_field,
                                                 models.CharField):
            kwargs['min_length'] = min_length
            validator_kwarg = [
                validator for validator in validator_kwarg
                if not isinstance(validator, validators.MinLengthValidator)
            ]

        # Ensure that max_value is passed explicitly as a keyword arg,
        # rather than as a validator.
        max_value = next((
            validator.limit_value for validator in validator_kwarg
            if isinstance(validator, validators.MaxValueValidator)
        ), None)
        if max_value is not None and isinstance(model_field,
                                                NUMERIC_FIELD_TYPES):
            kwargs['max_value'] = max_value
            validator_kwarg = [
                validator for validator in validator_kwarg
                if not isinstance(validator, validators.MaxValueValidator)
            ]

        # Ensure that max_value is passed explicitly as a keyword arg,
        # rather than as a validator.
        min_value = next((
            validator.limit_value for validator in validator_kwarg
            if isinstance(validator, validators.MinValueValidator)
        ), None)
        if min_value is not None and isinstance(model_field,
                                                NUMERIC_FIELD_TYPES):
            kwargs['min_value'] = min_value
            validator_kwarg = [
                validator for validator in validator_kwarg
                if not isinstance(validator, validators.MinValueValidator)
            ]

        # URLField does not need to include the URLValidator argument,
        # as it is explicitly added in.
        if isinstance(model_field, models.URLField):
            validator_kwarg = [
                validator for validator in validator_kwarg
                if not isinstance(validator, validators.URLValidator)
            ]

        # EmailField does not need to include the validate_email argument,
        # as it is explicitly added in.
        if isinstance(model_field, models.EmailField):
            validator_kwarg = [
                validator for validator in validator_kwarg
                if validator is not validators.validate_email
            ]

        # SlugField do not need to include the 'validate_slug' argument,
        if isinstance(model_field, models.SlugField):
            validator_kwarg = [
                validator for validator in validator_kwarg
                if validator is not validators.validate_slug
            ]

        # IPAddressField do not need to include the 'validate_ipv46_address'
        # argument,
        if isinstance(model_field, models.GenericIPAddressField):
            validator_kwarg = [
                validator for validator in validator_kwarg
                if validator is not validators.validate_ipv46_address
            ]

        if getattr(model_field, 'unique', False):
            warnings.warn(
                'UniqueValidator is currently not supported '
                'in DjangoCassandraSerializer'
            )

        if validator_kwarg:
            kwargs['validators'] = validator_kwarg

        return kwargs
711245
def field(self, type, field, default=None):
        ''''''
        if not type in self.messages:
            return default
        return getattr(self.messages[type], field, default)
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
33841
public static TypeInterestFactoryTrie newDefaultInstance()
    {
        TrieStructureTypeRelation<RewritePatternToRegex, String> relation = new TrieStructureTypeRelation<RewritePatternToRegex, String>()
        {

            @Override
            public String getStringToSearchFromSearchType(String search)
            {
                return search;
            }

            @Override
            public String getStringPrefixToSaveSaveType(RewritePatternToRegex save)
            {
                /**
                 * Take the prefix of the windup regex and save it in the node up to the first "{..}"
                 */
                return save.getRewritePattern().split("\\{")[0];
            }

            @Override
            public boolean checkIfMatchFound(RewritePatternToRegex saved, String searched)
            {
                return saved.getCompiledRegex().matcher(searched).matches();
            }
        };
        return new TypeInterestFactoryTrie(relation);
    }
204423
def build_standard_field(self, field_name, model_field):
        
        field_mapping = ClassLookupDict(self.serializer_field_mapping)

        field_class = field_mapping[model_field]
        field_kwargs = get_field_kwargs(field_name, model_field)

        if 'choices' in field_kwargs:
            # Fields with choices get coerced into `ChoiceField`
            # instead of using their regular typed field.
            field_class = self.serializer_choice_field
            # Some model fields may introduce kwargs that would not be valid
            # for the choice field. We need to strip these out.
            # Eg. models.DecimalField(max_digits=3, decimal_places=1, choices=DECIMAL_CHOICES)
            valid_kwargs = set((
                'read_only', 'write_only',
                'required', 'default', 'initial', 'source',
                'label', 'help_text', 'style',
                'error_messages', 'validators', 'allow_null', 'allow_blank',
                'choices'
            ))
            for key in list(field_kwargs.keys()):
                if key not in valid_kwargs:
                    field_kwargs.pop(key)

        if not issubclass(field_class, ModelField):
            # `model_field` is only valid for the fallback case of
            # `ModelField`, which is used when no other typed field
            # matched to the model field.
            field_kwargs.pop('model_field', None)

        if not issubclass(field_class, CharField) and not issubclass(field_class, ChoiceField):
            # `allow_blank` is only valid for textual fields.
            field_kwargs.pop('allow_blank', None)

        if postgres_fields and isinstance(model_field, postgres_fields.ArrayField):
            # Populate the `child` argument on `ListField` instances generated
            # for the PostgrSQL specfic `ArrayField`.
            child_model_field = model_field.base_field
            child_field_class, child_field_kwargs = self.build_standard_field(
                'child', child_model_field
            )
            field_kwargs['child'] = child_field_class(**child_field_kwargs)

        return field_class, field_kwargs
1270297
def init_default_cb():
    """"""
    global default_cb
    nlcb = os.environ.get('NLCB', '').lower()
    if not nlcb:
        return

    if nlcb == 'default':
        default_cb = NL_CB_DEFAULT
    elif nlcb == 'verbose':
        default_cb = NL_CB_VERBOSE
    elif nlcb == 'debug':
        default_cb = NL_CB_DEBUG
    else:
        _LOGGER.warning('Unknown value for NLCB, valid values: {default | verbose | debug}')
57883
private Indexer getDefaultIndexer(Field field) {
    Type type = field.getGenericType();
    if (type instanceof Class && type.equals(String.class)) {
      return getIndexer(LowerCaseStringIndexer.class);
    } else if (type instanceof ParameterizedType) {
      ParameterizedType parameterizedType = (ParameterizedType) type;
      Class<?> rawType = (Class<?>) parameterizedType.getRawType();
      if (List.class.isAssignableFrom(rawType) || Set.class.isAssignableFrom(rawType)) {
        Class<?>[] collectionType = IntrospectionUtils.resolveCollectionType(type);
        if (String.class.equals(collectionType[1])) {
          return getIndexer(LowerCaseStringListIndexer.class);
        }
      }
    }
    String message = String.format("No default indexer found for field %s in class %s",
        field.getName(), field.getDeclaringClass().getName());
    throw new NoSuitableIndexerException(message);
  }
851591
public static NonceAttribute createNonceAttribute(byte nonce[]) {
		NonceAttribute attribute = new NonceAttribute();

		attribute.setNonce(nonce);
		return attribute;
	}
111031
def create_model(cls, name, field=None):
        
        if field:
            attrs = {'name': name, 'field': field}
        else:
            attrs = {'name': name, 'field': {'_id': ObjectId()}}

        return type(str(name), (cls, ), attrs)()
1285415
def property2field(self, prop, instance=True, field_class=None, **kwargs):
        
        field = super().property2field(prop, instance, field_class, **kwargs)
        # when a column is not nullable, mark the field as required
        if hasattr(prop, 'columns'):
            col = prop.columns[0]
            if not col.primary_key and not col.nullable:
                field.required = True
        return field
1038190
def add_field(self, field):
        """"""
        self.remove_field(field.name)
        self._fields[field.name] = field

        if field.default is not None:
            if six.callable(field.default):
                self._default_callables[field.key] = field.default
            else:
                self._defaults[field.key] = field.default
29478
def _setdefault(self, relation):
        
        self.add_schema(relation.database, relation.schema)
        key = relation.key()
        return self.relations.setdefault(key, relation)
1205164
def instance_default(self, obj):
        ''' 

        '''
        return self.property.themed_default(obj.__class__, self.name, obj.themed_values())
318210
def build_standard_field(self, field_name, model_field):
        
        kwargs = {}

        if model_field.null or model_field.blank:
            kwargs['required'] = False

            if model_field.null:
                kwargs['allow_null'] = True
            if model_field.blank and (issubclass(model_field.__class__, models.CharField) or
                                      (issubclass(model_field.__class__, models.TextField))):
                kwargs['allow_blank'] = True

        if isinstance(model_field, models.AutoField) or not model_field.editable:
            kwargs['read_only'] = True

        if model_field.has_default():
            kwargs['default'] = model_field.get_default()

        if issubclass(model_field.__class__, models.TextField):
            kwargs['style'] = {'base_template': 'textarea.html'}

        if model_field.verbose_name is not None:
            kwargs['label'] = model_field.verbose_name

        if model_field.help_text is not None:
            kwargs['help_text'] = model_field.help_text

        # TODO: TypedChoiceField?
        if model_field.flatchoices:  # This ModelField contains choices
            kwargs['choices'] = model_field.flatchoices
            if model_field.null:
                kwargs['empty'] = None
            return (ChoiceField, kwargs)

        # put this below the ChoiceField because min_value isn't a valid initializer
        if issubclass(model_field.__class__, models.PositiveIntegerField) or\
                issubclass(model_field.__class__, models.PositiveSmallIntegerField):
            kwargs['min_value'] = 0

        attribute_dict = {
            models.CharField: ['max_length'],
            models.CommaSeparatedIntegerField: ['max_length'],
            models.DecimalField: ['max_digits', 'decimal_places'],
            models.EmailField: ['max_length'],
            models.FileField: ['max_length'],
            models.ImageField: ['max_length'],
            models.SlugField: ['max_length'],
            models.URLField: ['max_length'],
        }

        # === django-rest-framework-hstore specific ====
        # if available, use __basefield__ attribute instead of __class__
        # this will cause DRF to pick the correct DRF-field
        key = getattr(model_field, '__basefield__', model_field.__class__)

        if key in attribute_dict:
            attributes = attribute_dict[key]
            for attribute in attributes:
                kwargs.update({attribute: getattr(model_field, attribute)})

        if model_field.__class__ == DictionaryField and model_field.schema:
            kwargs['schema'] = True

        try:
            return (self.serializer_field_mapping[key], kwargs)
        except KeyError:
            pass

        try:
            return (self.serializer_field_mapping[model_field.__class__.__name__], kwargs)
        except KeyError:
            # return ModelField(model_field=model_field, **kwargs)
            return super(HStoreSerializer, self).build_standard_field(field_name, model_field)
351158
function createField(kind) {
  if (!fields.has(kind)) {
    let type;
    switch (kind) {
      case DynamicFieldKind.STRING_VAL.toString():
        type = StringType.create();
        break;

      case DynamicFieldKind.TEXT_VAL.toString():
        type = TextType.create();
        break;

      case DynamicFieldKind.INT_VAL.toString():
        type = IntType.create();
        break;

      case DynamicFieldKind.BOOL_VAL.toString():
        type = BooleanType.create();
        break;

      case DynamicFieldKind.FLOAT_VAL.toString():
        type = FloatType.create();
        break;

      case DynamicFieldKind.DATE_VAL.toString():
        type = DateType.create();
        break;

      default:
        throw new AssertionFailed(`DynamicField "${kind}" is not a valid type.`);
    }

    fields.set(
      kind, new Field({ name: kind, type, rule: FieldRule.A_SINGLE_VALUE, required: true }),
    );
  }

  return fields.get(kind);
}
727568
def custom_fields_basic_attributes=(attributes)
      self.non_relationship_custom_fields.each do |rule|
        name, type = rule['name'], rule['type'].to_sym

        # method of the custom getter
        method_name = "#{type}_attribute_set"

        self.class.send(method_name, self, name, attributes)
      end
    end
49803
private Record setDefault(Record record) {
        int size = record.size();
        for (int i = 0; i < size; i++)
            if (record.get(i) == null) {
                @SuppressWarnings("unchecked")
                Field<Object> field = (Field<Object>) record.field(i);
                if (!field.getDataType().nullable() && !field.getDataType().identity())
                    record.set(field, DSL.defaultValue());
            }
        return record;
    }