示例#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"