How to use the pyactiveresource.util.underscore function in pyactiveresource

To help you get started, we’ve selected a few pyactiveresource examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JetBrains / youtrack-rest-python-library / python / pyactiveresource / activeresource.py View on Github external
"""Look in the parent modules for classes matching the element name.

        One or both of element/class name must be specified.

        Args:
            element_name: The name of the element type.
            class_name: The class name of the element type.
            create_missing: Whether classes should be auto-created if no
                existing match is found.
        Returns:
            A Resource class.
        """
        if not element_name and not class_name:
            raise Error('One of element_name,class_name must be specified.')
        elif not element_name:
            element_name = util.underscore(class_name)
        elif not class_name:
            class_name = util.camelize(element_name)

        module_path = cls.__module__.split('.')
        for depth in range(len(module_path), 0, -1):
            try:
                __import__('.'.join(module_path[:depth]))
                module = sys.modules['.'.join(module_path[:depth])]
            except ImportError:
                continue
            try:
                klass = getattr(module, class_name)
                return klass
            except AttributeError:
                try:
                    __import__('.'.join([module.__name__, element_name]))
github JetBrains / youtrack-rest-python-library / python / pyactiveresource / activeresource.py View on Github external
Args:
            xml_string: An xml errors object (e.g. '')
        Returns:
            None
        """
        attribute_keys = self.base.attributes.keys()
        try:
            messages = util.xml_to_dict(
                    xml_string)['errors']['error']
            if not isinstance(messages, list):
                messages = [messages]
        except util.Error:
            messages = []
        for message in messages:
            attr_name = message.split()[0]
            key = util.underscore(attr_name)
            if key in attribute_keys:
                self.add(key, message[len(attr_name)+1:])
            else:
                self.add_to_base(message)
github JetBrains / youtrack-rest-python-library / python / pyactiveresource / activeresource.py View on Github external
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