# Path: openprovider/util.py
# def camel_to_snake(string):
#     """
#     Converts a camelCaseString to a snake_case_string.
# 
#     >>> camel_to_snake("fooBarBaz")
#     'foo_bar_baz'
#     """
#     return re.sub('([A-Z]+)', r'_\1', string).lower()
# 
# def snake_to_camel(value):
#     """
#     Converts a snake_case_string to a camelCaseString.
# 
#     >>> snake_to_camel("foo_bar_baz")
#     'fooBarBaz'
#     """
#     camel = "".join(word.title() for word in value.split("_"))
#     return value[:1].lower() + camel[1:]


import datetime
import lxml.etree
from openprovider.util import camel_to_snake, snake_to_camel



class Model(object):
    """
    Superclass for all models. Delegates attribute access to a wrapped class.
    """

    def __init__(self, obj=None, **kwargs):
        self._obj = obj
        self._attrs = dict((snake_to_camel(key), value) for (key, value) in kwargs.items())

    def __dir__(self):
        attrs = set(list(self.__dict__.keys()) + [camel_to_snake(key) for key in self._attrs.keys()])
        if self._obj is not None:
            attrs.update(camel_to_snake(t.tag) for t in self._obj.iterchildren())
        return [attr for attr in attrs if not attr.startswith('_')]

    def __getattr__(self, attr):
        """
        Magic for returning an attribute. Will try the attributes of the
        wrapper class first, then attributes in self._attrs, then the attributes
        of the wrapped objectified element.

        Will try a camelCased version of the snake_cased input if the attribute
        contains an underscore. This means foo.company_name will return the same
        as foo.companyName.
        """

        if "_" in attr:

# Path: openprovider/util.py
# def camel_to_snake(string):
#     """
#     Converts a camelCaseString to a snake_case_string.
# 
#     >>> camel_to_snake("fooBarBaz")
#     'foo_bar_baz'
#     """
#     return re.sub('([A-Z]+)', r'_\1', string).lower()
# 
# def snake_to_camel(value):
#     """
#     Converts a snake_case_string to a camelCaseString.
# 
#     >>> snake_to_camel("foo_bar_baz")
#     'fooBarBaz'
#     """
#     camel = "".join(word.title() for word in value.split("_"))
#     return value[:1].lower() + camel[1:]


# Path: openprovider/models.py
import datetime
import lxml.etree
from openprovider.util import camel_to_snake, snake_to_camel




class Model(object):
    """
    Superclass for all models. Delegates attribute access to a wrapped class.
    """

    def __init__(self, obj=None, **kwargs):
        self._obj = obj
        self._attrs = dict((snake_to_camel(key), value) for (key, value) in kwargs.items())

    def __dir__(self):
        attrs = set(list(self.__dict__.keys()) + [camel_to_snake(key) for key in self._attrs.keys()])
        if self._obj is not None:
            attrs.update(camel_to_snake(t.tag) for t in self._obj.iterchildren())
        return [attr for attr in attrs if not attr.startswith('_')]

    def __getattr__(self, attr):
        """
        Magic for returning an attribute. Will try the attributes of the
        wrapper class first, then attributes in self._attrs, then the attributes
        of the wrapped objectified element.

        Will try a camelCased version of the snake_cased input if the attribute
        contains an underscore. This means foo.company_name will return the same
        as foo.companyName.
        """

        if "_" in attr:

            attr = snake_to_camel(attr)