Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _fields_and_defaults(typename, field_names, default, rename):
# field_names must be a string or an iterable, consisting of fieldname
# strings or 2-tuples. Each 2-tuple is of the form (fieldname,
# default).
# Keeps track of the fields we're adding, with their defaults.
fields = _Fields(default)
# Validates field and type names.
name_checker = _NameChecker(typename)
if isinstance(field_names, _basestring):
# No per-field defaults. So it's like a collections.namedtuple,
# but with a possible default value.
field_names = field_names.replace(',', ' ').split()
# If field_names is a Mapping, change it to return the
# (field_name, default) pairs, as if it were a list.
if isinstance(field_names, _collections.Mapping):
field_names = field_names.items()
# Parse and validate the field names.