ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #62: ARIA-66-Convert-custom-parser-fields-i...
Date Mon, 30 Jan 2017 17:06:36 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/62#discussion_r98484829
  
    --- Diff: aria/storage/type.py ---
    @@ -74,16 +125,115 @@ def coerce(cls, key, value):
                 raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
     
     
    +class _StrictListMixin(object):
    +    ANY_TYPE = 'any_type'
    +
    +    _item_cls = ANY_TYPE
    +
    +    @classmethod
    +    def coerce(cls, key, value):
    +        "Convert plain dictionaries to MutableDict."
    +        try:
    +            if not isinstance(value, cls):
    +                if isinstance(value, list):
    +                    for item in value:
    +                        cls._assert_item(item)
    +                    return cls(value)
    +                return mutable.MutableList.coerce(key, value)
    +            else:
    +                return value
    +        except ValueError as e:
    +            raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
    +
    +    def __setitem__(self, index, value):
    +        """Detect list set events and emit change events."""
    +        self._assert_item(value)
    +        super(_StrictListMixin, self).__setitem__(index, value)
    +
    +    def append(self, item):
    +        self._assert_item(item)
    +        super(_StrictListMixin, self).append(item)
    +
    +    def extend(self, item):
    +        self._assert_item(item)
    +        super(_StrictListMixin, self).extend(item)
    +
    +    def insert(self, index, item):
    +        self._assert_item(item)
    +        super(_StrictListMixin, self).insert(index, item)
    +
    +    @classmethod
    +    def _assert_item(cls, item):
    +        if cls._item_cls is not None and not isinstance(item, cls._item_cls):
    +            raise exceptions.StorageError("Key type was set strictly to {0}, but was
{1}".format(
    +                cls._item_cls, type(item)
    +            ))
    +
    +
     class _MutableList(mutable.MutableList):
     
         @classmethod
         def coerce(cls, key, value):
             "Convert plain dictionaries to MutableDict."
    +
             try:
    -            return mutable.MutableList.coerce(key, value)
    +            if not isinstance(value, cls):
    --- End diff --
    
    try to remove


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message