Пример #1
0
    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)

        if attr in self.__dict__:
            # Check ourselves first to avoid infinite loops
            return getattr(self, attr)

        try:
            return self._attrs[attr]
        except KeyError:
            if self._obj is not None:
                try:
                    return self._obj[attr]
                except (AttributeError, KeyError):
                    pass

        raise AttributeError("Model has no attribute '%s' (tried %r)" %
                             (camel_to_snake(attr), dir(self)))
Пример #2
0
    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)

        if attr in self.__dict__:
            # Check ourselves first to avoid infinite loops
            return getattr(self, attr)

        try:
            return self._attrs[attr]
        except KeyError:
            if self._obj is not None:
                try:
                    return self._obj[attr]
                except (AttributeError, KeyError):
                    pass

        raise AttributeError("Model has no attribute '%s' (tried %r)"
                             % (camel_to_snake(attr), dir(self)))
Пример #3
0
def _additional_data(data):
    if data is None:
        return None

    element = E.additionalData()
    for key, value in data.items():
        if key == 'birth_date':
            try:
                value = value.strftime('%Y-%m-%d')
            except AttributeError:
                pass
        element.append(E(snake_to_camel(key), value))
    return element
Пример #4
0
def _additional_data(data):
    if data is None:
        return None

    element = E.additionalData()
    for key, value in data.items():
        if key == 'birth_date':
            try:
                value = value.strftime('%Y-%m-%d')
            except AttributeError:
                pass
        element.append(E(snake_to_camel(key), value))
    return element
Пример #5
0
def _extension_additional_data(data):
    if data is None:
        return None

    return E.extensionAdditionalData(
        E(snake_to_camel(key), value) for key, value in data.items())
Пример #6
0
def test_camel_snake_camel():
    assert snake_to_camel(camel_to_snake("countryCode")), "countryCode"
Пример #7
0
def test_snake_to_camel(value, expected):
    assert snake_to_camel(value) == expected
Пример #8
0
def test_snake_camel_snake():
    assert camel_to_snake(snake_to_camel("country_code")) == "country_code"
Пример #9
0
def _extension_additional_data(data):
    if data is None:
        return None

    return E.extensionAdditionalData(E(snake_to_camel(key), value) for key, value in data.items())
Пример #10
0
 def __init__(self, obj=None, **kwargs):
     self._obj = obj
     self._attrs = dict((snake_to_camel(key), value) for (key, value) in kwargs.items())
Пример #11
0
 def __init__(self, obj=None, **kwargs):
     self._obj = obj
     self._attrs = dict(
         (snake_to_camel(key), value) for (key, value) in kwargs.items())
Пример #12
0
def test_camel_snake_camel():
    assert snake_to_camel(camel_to_snake("countryCode")), "countryCode"
Пример #13
0
def test_snake_to_camel(value, expected):
    assert snake_to_camel(value) == expected
Пример #14
0
def test_snake_camel_snake():
    assert camel_to_snake(snake_to_camel("country_code")) == "country_code"