def __new__(mcs, name, bases, new_attrs): """Create a new class. Args: mcs: The metaclass. name: The name of the class. bases: List of base classes from which mcs inherits. new_attrs: The class attribute dictionary. """ if '_singular' not in new_attrs or not new_attrs['_singular']: # Convert CamelCase to lower_underscore singular = re.sub(r'\B((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))', r'_\1', name).lower() new_attrs['_singular'] = singular if '_plural' not in new_attrs or not new_attrs['_plural']: new_attrs['_plural'] = util.pluralize(new_attrs['_singular']) klass = type.__new__(mcs, name, bases, new_attrs) # if _site is defined, use the site property to ensure that user # and password are properly initialized. if '_site' in new_attrs: klass.site = new_attrs['_site'] return klass
def __new__(mcs, name, bases, new_attrs): """Create a new class. Args: mcs: The metaclass. name: The name of the class. bases: List of base classes from which mcs inherits. new_attrs: The class attribute dictionary. """ if "_singular" not in new_attrs or not new_attrs["_singular"]: new_attrs["_singular"] = util.underscore(name) if "_plural" not in new_attrs or not new_attrs["_plural"]: new_attrs["_plural"] = util.pluralize(new_attrs["_singular"]) klass = type.__new__(mcs, name, bases, new_attrs) # if _site is defined, use the site property to ensure that user # and password are properly initialized. if "_site" in new_attrs: klass.site = new_attrs["_site"] return klass
def __new__(mcs, name, bases, new_attrs): """Create a new class. Args: mcs: The metaclass. name: The name of the class. bases: List of base classes from which mcs inherits. new_attrs: The class attribute dictionary. """ if '_singular' not in new_attrs or not new_attrs['_singular']: new_attrs['_singular'] = util.underscore(name) if '_plural' not in new_attrs or not new_attrs['_plural']: new_attrs['_plural'] = util.pluralize(new_attrs['_singular']) klass = type.__new__(mcs, name, bases, new_attrs) # if _site is defined, use the site property to ensure that user # and password are properly initialized. if '_site' in new_attrs: klass.site = new_attrs['_site'] return klass