Name
- class naming.Name(name='', sep=' ')[source]
Base class for name objects.
Each subclass may have its own config attribute that should be a dictionary in the form of {field: pattern} where pattern is a valid regular expression.
Classes may as well have a drop iterable attribute representing the fileds they want to ignore from their bases and a join dictionary attribute for nesting existing fields into new ones (or to override other fields).
All field names should be unique. No duplicates are allowed.
- Example:
>>> from naming import Name >>> class MyName(Name): ... config = dict(base=r'\w+') ... >>> n = MyName() >>> n.get() # no name has been set on the object, convention is solved with {missing} fields '{base}' >>> n.values {} >>> n.name = 'hello_world' >>> n Name("hello_world") >>> str(n) # cast to string 'hello_world' >>> n.values {'base': 'hello_world'} >>> # modify name and get values from field names >>> n.base = 'through_field_name' >>> n.values {'base': 'through_field_name'} >>> n.base 'through_field_name'
- static cast(value, name='')
Cast value to a grouped regular expression when name is provided.
- classmethod cast_config(config)
Cast config to grouped regular expressions.
- get(**values)
Get a new name string from this object’s name values.
- Parameters:
values – Variable keyword arguments where the key should refer to a field on this object that will use the provided value to build the new name.
- Return type:
- get_pattern_list()
Fields / properties names (sorted) to be used when building names. Defaults to the keys of self.config
- config = mappingproxy({})
- join = mappingproxy({})
- property name: str
This object’s solved name.
- Raises:
ValueError – If an invalid string is provided when setting the attribute.