예제 #1
0
    def __setitem__(self, key, object):
        """ See `IOrderedContainer`.

        >>> oc = OrderedContainer()
        >>> oc.keys()
        []
        >>> oc['foo'] = 'bar'
        >>> oc._order
        ['foo']
        >>> oc['baz'] = 'quux'
        >>> oc._order
        ['foo', 'baz']
        >>> int(len(oc._order) == len(oc._data))
        1

        >>> oc['foo'] = 'baz'
        Traceback (most recent call last):
        ...
        KeyError: u'foo'
        >>> oc._order
        ['foo', 'baz']
        """
        # This function creates a lot of events that other code
        # listens to. None of them are fired (notified) though, before
        # _setitemf is called. At that point we need to be sure that
        # we have the key in _order too.
        setitem(self, self._setitemf, key, object)
        return key
예제 #2
0
    def __setitem__(self, key, object):
        existed = key in self._data

        bad = False
        if not isinstance(key, six.string_types):
            bad = True
        if bad:
            raise TypeError("'%s' is invalid, the key must be an "
                            "ascii or unicode string" % key)
        if len(key) == 0:
            raise ValueError("The key cannot be an empty string")

        # We have to first update the order, so that the item is available,
        # otherwise most API functions will lie about their available values
        # when an event subscriber tries to do something with the container.
        if not existed:
            self._order.append(key)

        # This function creates a lot of events that other code listens to.
        try:
            setitem(self, self._data.__setitem__, key, object)
        except Exception:
            if not existed:
                self._order.remove(key)
            raise

        return key
예제 #3
0
    def __setitem__(self, key, object):
        """ See `IOrderedContainer`.

        >>> oc = OrderedContainer()
        >>> oc.keys()
        []
        >>> oc['foo'] = 'bar'
        >>> oc._order
        ['foo']
        >>> oc['baz'] = 'quux'
        >>> oc._order
        ['foo', 'baz']
        >>> int(len(oc._order) == len(oc._data))
        1

        >>> oc['foo'] = 'baz'
        Traceback (most recent call last):
        ...
        KeyError: u'foo'
        >>> oc._order
        ['foo', 'baz']
        """
        # This function creates a lot of events that other code
        # listens to. None of them are fired (notified) though, before
        # _setitemf is called. At that point we need to be sure that
        # we have the key in _order too.
        setitem(self, self._setitemf, key, object)
        return key
예제 #4
0
    def __setitem__(self, key, object):
        existed = key in self._data

        bad = False
        if not isinstance(key, six.string_types):
            bad = True
        if bad:
            raise TypeError("'%s' is invalid, the key must be an "
                            "ascii or unicode string" % key)
        if len(key) == 0:
            raise ValueError("The key cannot be an empty string")

        # We have to first update the order, so that the item is available,
        # otherwise most API functions will lie about their available values
        # when an event subscriber tries to do something with the container.
        if not existed:
            self._order.append(key)

        # This function creates a lot of events that other code listens to.
        try:
            setitem(self, self._data.__setitem__, key, object)
        except Exception:
            if not existed:
                self._order.remove(key)
            raise

        return key
예제 #5
0
    def __setitem__(self, key, object):
        """ See `IOrderedContainer`.

        >>> oc = OrderedContainer()
        >>> oc.keys()
        []
        >>> oc['foo'] = 'bar'
        >>> oc._order
        ['foo']
        >>> oc['baz'] = 'quux'
        >>> oc._order
        ['foo', 'baz']
        >>> int(len(oc._order) == len(oc._data))
        1

        >>> oc['foo'] = 'baz'
        Traceback (most recent call last):
        ...
        KeyError: u'foo'
        >>> oc._order
        ['foo', 'baz']
        """

        existed = key in self._data

        bad = False
        if isinstance(key, six.string_types):
            try:
                key.decode()
            except AttributeError:
                # Py3 str cannot decode.
                pass
            except UnicodeError:
                bad = True
        else:
            bad = True
        if bad:
            raise TypeError("'%s' is invalid, the key must be an "
                            "ascii or unicode string" % key)
        if len(key) == 0:
            raise ValueError("The key cannot be an empty string")

        # We have to first update the order, so that the item is available,
        # otherwise most API functions will lie about their available values
        # when an event subscriber tries to do something with the container.
        if not existed:
            self._order.append(key)

        # This function creates a lot of events that other code listens to.
        try:
            setitem(self, self._data.__setitem__, key, object)
        except Exception:
            if not existed:
                self._order.remove(key)
            raise

        return key
예제 #6
0
    def __setitem__(self, key, value):
        # When the key is None, we need to determine it.
        if key is None:
            key = self._get_key(value)

        # We want to be as close as possible to using the Zope semantics.
        contained.setitem(self, self._real_setitem, key, value)
        # Also add the item to the container cache.
        self._cache[key] = value
예제 #7
0
    def __setitem__(self, key, value):
        # When the key is None, we need to determine it.
        if key is None:
            key = self._get_key(value)

        # We want to be as close as possible to using the Zope semantics.
        contained.setitem(self, self._real_setitem, key, value)
        # Also add the item to the container cache.
        self._cache[key] = value
예제 #8
0
 def __setitem__(self, key, value):
     # When the key is None, we need to determine it.
     if key is None:
         if self._pj_mapping_key is None:
             key = self._pj_jar.createId()
         else:
             # we have _pj_mapping_key, use that attribute
             key = getattr(value, self._pj_mapping_key)
     # We want to be as close as possible to using the Zope semantics.
     contained.setitem(self, self._real_setitem, key, value)
     # Also add the item to the container cache.
     self._cache[key] = value
예제 #9
0
파일: ordered.py 프로젝트: c0ns0le/zenoss-4
    def __setitem__(self, key, object):
        """ See `IOrderedContainer`.

        >>> oc = OrderedContainer()
        >>> oc.keys()
        []
        >>> oc['foo'] = 'bar'
        >>> oc._order
        ['foo']
        >>> oc['baz'] = 'quux'
        >>> oc._order
        ['foo', 'baz']
        >>> int(len(oc._order) == len(oc._data))
        1

        >>> oc['foo'] = 'baz'
        Traceback (most recent call last):
        ...
        KeyError: u'foo'
        >>> oc._order
        ['foo', 'baz']
        """

        existed = self._data.has_key(key)

        bad = False
        if isinstance(key, StringTypes):
            try:
                unicode(key)
            except UnicodeError:
                bad = True
        else:
            bad = True
        if bad:
            raise TypeError("'%s' is invalid, the key must be an "
                            "ascii or unicode string" % key)
        if len(key) == 0:
            raise ValueError("The key cannot be an empty string")

        # We have to first update the order, so that the item is available,
        # otherwise most API functions will lie about their available values
        # when an event subscriber tries to do something with the container.
        if not existed:
            self._order.append(key)

        # This function creates a lot of events that other code listens to.
        try:
            setitem(self, self._data.__setitem__, key, object)
        except Exception, e:
            if not existed:
                self._order.remove(key)
            raise e
예제 #10
0
 def __setitem__(self, key, value):
     # When the key is None, we need to determine it.
     if key is None:
         if self._m_mapping_key is None:
             # Make sure the value is in the database, since we might want
             # to use its oid.
             if value._p_oid is None:
                 self._m_jar.insert(value)
             key = unicode(value._p_oid.id)
         else:
             # we have _m_mapping_key, use that attribute
             key = getattr(value, self._m_mapping_key)
     # We want to be as close as possible to using the Zope semantics.
     contained.setitem(self, self._real_setitem, key, value)
예제 #11
0
 def __setitem__(self, key, value):
     # When the key is None, we need to determine it.
     if key is None:
         if self._m_mapping_key is None:
             # Make sure the value is in the database, since we might want
             # to use its oid.
             if value._p_oid is None:
                 self._m_jar.insert(value)
             key = unicode(value._p_oid.id)
         else:
             # we have _m_mapping_key, use that attribute
             key = getattr(value, self._m_mapping_key)
     # We want to be as close as possible to using the Zope semantics.
     contained.setitem(self, self._real_setitem, key, value)
예제 #12
0
파일: folder.py 프로젝트: c0ns0le/zenoss-4
    def __setitem__(self, name, object):
        """Add the given object to the folder under the given name."""

        if not (isinstance(name, str) or isinstance(name, unicode)):
            raise TypeError("Name must be a string rather than a %s" %
                            name.__class__.__name__)
        try:
            unicode(name)
        except UnicodeError:
            raise TypeError("Non-unicode names must be 7-bit-ascii only")
        if not name:
            raise TypeError("Name must not be empty")

        if name in self.data:
            raise KeyError("name, %s, is already in use" % name)

        setitem(self, self.data.__setitem__, name, object)
예제 #13
0
파일: folder.py 프로젝트: kislovm/findburo
    def __setitem__(self, name, object):
        """Add the given object to the folder under the given name."""

        if not (isinstance(name, str) or isinstance(name, unicode)):
            raise TypeError("Name must be a string rather than a %s" %
                            name.__class__.__name__)
        try:
            unicode(name)
        except UnicodeError:
            raise TypeError("Non-unicode names must be 7-bit-ascii only")
        if not name:
            raise TypeError("Name must not be empty")

        if name in self.data:
            raise KeyError("name, %s, is already in use" % name)

        setitem(self, self.data.__setitem__, name, object)
예제 #14
0
    def __setitem__(self, key, obj):
        existed = self._data.has_key(key)

        bad = False
        if isinstance(key, StringTypes):
            try:
                unicode(key)
            except UnicodeError:
                bad = True
        else:
            bad = True
        if bad:
            raise TypeError("'%s' is invalid, the key must be an "
                            "ascii or unicode string" % key)
        if len(key) == 0:
            raise ValueError("The key cannot be an empty string")

        # We have to first update the order, so that the item is available,
        # otherwise most API functions will lie about their available values
        # when an event subscriber tries to do something with the container.
        if not existed:
            if len(self._order) < self.order_limit:
                self._order.append(key)
            if len(self._container_order) < self.container_order_limit:
                if 'Container' in getattr(obj, 'object_types', []):
                    self._container_order.append(key)

        # This function creates a lot of events that other code listens to.
        try:
            setitem(self, self._data.__setitem__, key, obj)
        except Exception:
            if not existed:
                if key in self._order: self._order.remove(key)
                if key in self._container_order:
                    self._container_order.remove(key)
            raise

        return key
예제 #15
0
    def __setitem__(self, key, obj):
        existed = self._data.has_key(key)

        bad = False
        if isinstance(key, StringTypes):
            try:
                unicode(key)
            except UnicodeError:
                bad = True
        else:
            bad = True
        if bad:
            raise TypeError("'%s' is invalid, the key must be an "
                            "ascii or unicode string" % key)
        if len(key) == 0:
            raise ValueError("The key cannot be an empty string")

        # We have to first update the order, so that the item is available,
        # otherwise most API functions will lie about their available values
        # when an event subscriber tries to do something with the container.
        if not existed:
            if len(self._order) < self.order_limit:
                self._order.append(key)
            if len(self._container_order) < self.container_order_limit:
                if 'Container' in getattr(obj, 'object_types', []):
                    self._container_order.append(key)

        # This function creates a lot of events that other code listens to.
        try:
            setitem(self, self._data.__setitem__, key, obj)
        except Exception:
            if not existed:
                if key in self._order: self._order.remove(key)
                if key in self._container_order: self._container_order.remove(key)
            raise

        return key
예제 #16
0
 def __setitem__(self, key, value):
     setitem(self, self._setitemf, key, value)
예제 #17
0
파일: sample.py 프로젝트: pigaov10/plone4.3
 def __setitem__(self, key, object):
     """See interface `IWriteContainer`"""
     setitem(self, self.__data.__setitem__, key, object)
예제 #18
0
 def __setitem__(self, key, object):
     '''See interface `IWriteContainer`'''
     setitem(self, self.__data.__setitem__, key, object)
예제 #19
0
    def makeObjects(self):
        checker = NamesChecker(['__getitem__'])
        defineChecker(SiteManagerStub, checker)
        self.futurama = futurama = SampleSite()
        directlyProvides(futurama, IContainmentRoot)
        planetexpress = SampleContainer()
        robotfactory = SampleContainer()
        nimbus = SampleContainer()
        omicronpersei = SampleSite()

        bender = SampleContent()
        fry = SampleContent()
        leela = SampleContent()
        mom = SampleContent()
        zapp = SampleContent()
        kif = SampleContent()

        setitem(futurama, futurama.__setitem__, 'planetexpress', planetexpress)
        setitem(futurama, futurama.__setitem__, 'robotfactory', robotfactory)
        setitem(futurama, futurama.__setitem__, 'nimbus', nimbus)
        setitem(futurama, futurama.__setitem__, 'omicronpersei', omicronpersei)

        setitem(planetexpress, planetexpress.__setitem__, 'bender', bender)
        setitem(planetexpress, planetexpress.__setitem__, 'fry', fry)
        setitem(planetexpress, planetexpress.__setitem__, 'leela', leela)
        setitem(robotfactory, robotfactory.__setitem__, 'mom', mom)
        setitem(nimbus, nimbus.__setitem__, 'zapp', zapp)
        setitem(nimbus, nimbus.__setitem__, 'kif', kif)
예제 #20
0
 def __setitem__(self, key, value):
     setitem(self, self._setitemf, key, value)