Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

edgify / rook   python

Repository URL to install this package:

/ processor / namespaces / container_namespace.py

from .namespace import Namespace

from .python_object_namespace import PythonObjectNamespace

from rook.exceptions import RookAttributeNotFound


class ContainerNamespace(dict, Namespace):
    def __init__(self, dictionary=None):
        Namespace.__init__(self, self.METHODS)
        dict.__init__(self, dictionary or {})

    def read_attribute(self, name):
        try:
            return self[name]
        except KeyError:
            raise RookAttributeNotFound(name)

    def write_attribute(self, name, value):
        self[name] = value

    def size(self, args):
        return PythonObjectNamespace(len(self))

    def __getattr__(self, item):
        if item == u'dictionary':
            return self
        elif item in self:
            return self[item]
        else:
            return dict.__getattribute__(self, item)

    METHODS = (size,)