Exemplo n.º 1
0
    def _setitem_uid(self, key, value, uid):
        validKey(key)

        key_str = key.toString()
        value_str = value.toxml()

        tried = []

        wasCached = [(key_str, uid) in self._cached]
        self._cached[(key_str, uid)] = value_str
        @inlineCallbacks
        def trySetItem(txn):
            if tried:
                yield self._refresh(txn)
                wasCached[:] = [(key_str, uid) in self._cached]
            tried.append(True)
            if wasCached[0]:
                yield self._updateQuery.on(
                    txn, resourceID=self._resourceID, value=value_str,
                    name=key_str, uid=uid)
            else:
                yield self._insertQuery.on(
                    txn, resourceID=self._resourceID, value=value_str,
                    name=key_str, uid=uid)
            self._cacher.delete(str(self._resourceID))

        # Call the registered notification callback
        if hasattr(self, "_notifyCallback") and self._notifyCallback is not None:
            self._notifyCallback()

        def justLogIt(f):
            f.trap(AllRetriesFailed)
            self.log_error("setting a property failed; probably nothing.")
        self._txn.subtransaction(trySetItem).addErrback(justLogIt)
Exemplo n.º 2
0
    def _delitem_uid(self, key, uid):
        validKey(key)

        key_str = key.toString()
        del self._cached[(key_str, uid)]
        @inlineCallbacks
        def doIt(txn):
            yield self._deleteQuery.on(
                txn, lambda: KeyError(key),
                resourceID=self._resourceID,
                name=key_str, uid=uid
            )
            if self._cacher is not None:
                self._cacher.delete(self._cacheToken(uid))

        # Call the registered notification callback - we need to do this as a preCommit since it involves
        # a bunch of deferred operations, but this propstore api is not deferred. preCommit will execute
        # the deferreds properly, and it is fine to wait until everything else is done before sending the
        # notifications.
        if hasattr(self, "_notifyCallback") and self._notifyCallback is not None:
            self._txn.preCommit(self._notifyCallback)

        def justLogIt(f):
            f.trap(AllRetriesFailed)
            self.log.error("setting a property failed; probably nothing.")
        self._txn.subtransaction(doIt).addErrback(justLogIt)
Exemplo n.º 3
0
    def _setitem_uid(self, key, value, uid):
        validKey(key)
        effectiveKey = (key, uid)

        if effectiveKey in self.removed:
            self.removed.remove(effectiveKey)
        self.modified[effectiveKey] = value
Exemplo n.º 4
0
    def _setitem_uid(self, key, value, uid):
        validKey(key)
        effectiveKey = (key, uid)

        if effectiveKey in self.removed:
            self.removed.remove(effectiveKey)
        self.modified[effectiveKey] = value
Exemplo n.º 5
0
    def _delitem_uid(self, key, uid):
        validKey(key)

        key_str = key.toString()
        del self._cached[(key_str, uid)]

        @inlineCallbacks
        def doIt(txn):
            yield self._deleteQuery.on(txn,
                                       lambda: KeyError(key),
                                       resourceID=self._resourceID,
                                       name=key_str,
                                       uid=uid)
            if self._cacher is not None:
                self._cacher.delete(self._cacheToken(uid))

        # Call the registered notification callback - we need to do this as a preCommit since it involves
        # a bunch of deferred operations, but this propstore api is not deferred. preCommit will execute
        # the deferreds properly, and it is fine to wait until everything else is done before sending the
        # notifications.
        if hasattr(self,
                   "_notifyCallback") and self._notifyCallback is not None:
            self._txn.preCommit(self._notifyCallback)

        def justLogIt(f):
            f.trap(AllRetriesFailed)
            self.log.error("setting a property failed; probably nothing.")

        self._txn.subtransaction(doIt).addErrback(justLogIt)
Exemplo n.º 6
0
 def _delitem_uid(self, key, uid):
     validKey(key)
     self._txn.execSQL(
         "delete from RESOURCE_PROPERTY where VIEWER_UID = %s"
         "and RESOURCE_ID = %s AND NAME = %s",
         [uid, self._resourceID, key.toString()],
         raiseOnZeroRowCount=lambda:KeyError(key)
     )
Exemplo n.º 7
0
    def _getitem_uid(self, key, uid):
        validKey(key)

        try:
            value = self._cached[(key.toString(), uid)]
        except KeyError:
            raise KeyError(key)

        return WebDAVDocument.fromString(value).root_element
Exemplo n.º 8
0
    def _getitem_uid(self, key, uid):
        validKey(key)

        try:
            value = self._cached[(key.toString(), uid)]
        except KeyError:
            raise KeyError(key)

        return WebDAVDocument.fromString(value).root_element
Exemplo n.º 9
0
    def _delitem_uid(self, key, uid):
        validKey(key)
        effectiveKey = (key, uid)

        if effectiveKey in self.modified:
            del self.modified[effectiveKey]
        elif self._encodeKey(effectiveKey) not in self.attrs:
            raise KeyError(key)

        self.removed.add(effectiveKey)
Exemplo n.º 10
0
    def _delitem_uid(self, key, uid):
        validKey(key)
        effectiveKey = (key, uid)

        if effectiveKey in self.modified:
            del self.modified[effectiveKey]
        elif self._encodeKey(effectiveKey) not in self.attrs:
            raise KeyError(key)

        self.removed.add(effectiveKey)
Exemplo n.º 11
0
    def _delitem_uid(self, key, uid):
        validKey(key)

        key_str = key.toString()
        del self._cached[(key_str, uid)]
        self._deleteQuery.on(self._txn, lambda:KeyError(key),
                             resourceID=self._resourceID,
                             name=key_str, uid=uid
                            )
        self._cacher.delete(str(self._resourceID))
Exemplo n.º 12
0
 def _getitem_uid(self, key, uid):
     validKey(key)
     rows = self._txn.execSQL(
         "select VALUE from RESOURCE_PROPERTY where "
         "RESOURCE_ID = %s and NAME = %s and VIEWER_UID = %s",
         [self._resourceID, key.toString(), uid]
     )
     if not rows:
         raise KeyError(key)
     return WebDAVDocument.fromString(rows[0][0]).root_element
Exemplo n.º 13
0
 def _setitem_uid(self, key, value, uid):
     validKey(key)
     try:
         self._delitem_uid(key, uid)
     except KeyError:
         pass
     self._txn.execSQL(
         "insert into RESOURCE_PROPERTY "
         "(RESOURCE_ID, NAME, VALUE, VIEWER_UID) values (%s, %s, %s, %s)",
         [self._resourceID, key.toString(), value.toxml(), uid]
     )
Exemplo n.º 14
0
    def _setitem_uid(self, key, value, uid):
        validKey(key)

        key_str = key.toString()
        value_str = value.toxml()

        tried = []

        wasCached = [(key_str, uid) in self._cached]
        self._cached[(key_str, uid)] = value_str

        @inlineCallbacks
        def trySetItem(txn):
            if tried:
                yield self._refresh(txn)
                wasCached[:] = [(key_str, uid) in self._cached]
            tried.append(True)
            if wasCached[0]:
                yield self._updateQuery.on(txn,
                                           resourceID=self._resourceID,
                                           value=value_str,
                                           name=key_str,
                                           uid=uid)
            else:
                yield self._insertQuery.on(txn,
                                           resourceID=self._resourceID,
                                           value=value_str,
                                           name=key_str,
                                           uid=uid)
            if self._cacher is not None:
                self._cacher.delete(self._cacheToken(uid))

        # Call the registered notification callback - we need to do this as a preCommit since it involves
        # a bunch of deferred operations, but this propstore api is not deferred. preCommit will execute
        # the deferreds properly, and it is fine to wait until everything else is done before sending the
        # notifications.
        if hasattr(self,
                   "_notifyCallback") and self._notifyCallback is not None:
            self._txn.preCommit(self._notifyCallback)

        def justLogIt(f):
            f.trap(AllRetriesFailed)
            self.log.error("setting a property failed; probably nothing.")

        self._txn.subtransaction(trySetItem).addErrback(justLogIt)
Exemplo n.º 15
0
    def _getitem_uid(self, key, uid):
        validKey(key)
        effectiveKey = (key, uid)

        if effectiveKey in self.modified:
            return self.modified[effectiveKey]

        if effectiveKey in self.removed:
            raise KeyError(key)

        try:
            try:
                data = self.attrs[self._encodeKey(effectiveKey)]
            except IOError, e:
                if e.errno in [_ERRNO_NO_ATTR, errno.ENOENT]:
                    raise KeyError(key)
                raise PropertyStoreError(e)
        except KeyError:
            # Check for uncompressed namespace
            if  effectiveKey[0].namespace in self._namespaceCompress:
                try:
                    data = self.attrs[self._encodeKey(effectiveKey,
                                                      compressNamespace=False)]
                except IOError, e:
                    raise KeyError(key)

                try:
                    # Write it back using the compressed format
                    self.attrs[self._encodeKey(effectiveKey)] = data
                    del self.attrs[self._encodeKey(effectiveKey,
                                                   compressNamespace=False)]
                except IOError, e:
                    msg = (
                        "Unable to upgrade property "
                        "to compressed namespace: %s" % (key.toString())
                    )
                    self.log.error(msg)
                    raise PropertyStoreError(msg)
Exemplo n.º 16
0
    def _getitem_uid(self, key, uid):
        validKey(key)
        effectiveKey = (key, uid)

        if effectiveKey in self.modified:
            return self.modified[effectiveKey]

        if effectiveKey in self.removed:
            raise KeyError(key)

        try:
            try:
                data = self.attrs[self._encodeKey(effectiveKey)]
            except IOError, e:
                if e.errno in [_ERRNO_NO_ATTR, errno.ENOENT]:
                    raise KeyError(key)
                raise PropertyStoreError(e)
        except KeyError:
            # Check for uncompressed namespace
            if effectiveKey[0].namespace in self._namespaceCompress:
                try:
                    data = self.attrs[self._encodeKey(effectiveKey,
                                                      compressNamespace=False)]
                except IOError, e:
                    raise KeyError(key)

                try:
                    # Write it back using the compressed format
                    self.attrs[self._encodeKey(effectiveKey)] = data
                    del self.attrs[self._encodeKey(effectiveKey,
                                                   compressNamespace=False)]
                except IOError, e:
                    msg = (
                        "Unable to upgrade property "
                        "to compressed namespace: %s" % (key.toString())
                    )
                    self.log.error(msg)
                    raise PropertyStoreError(msg)
Exemplo n.º 17
0
    def _setitem_uid(self, key, value, uid):
        validKey(key)

        key_str = key.toString()
        value_str = value.toxml()

        tried = []

        wasCached = [(key_str, uid) in self._cached]
        self._cached[(key_str, uid)] = value_str
        @inlineCallbacks
        def trySetItem(txn):
            if tried:
                yield self._refresh(txn)
                wasCached[:] = [(key_str, uid) in self._cached]
            tried.append(True)
            if wasCached[0]:
                yield self._updateQuery.on(
                    txn, resourceID=self._resourceID, value=value_str,
                    name=key_str, uid=uid)
            else:
                yield self._insertQuery.on(
                    txn, resourceID=self._resourceID, value=value_str,
                    name=key_str, uid=uid)
            if self._cacher is not None:
                self._cacher.delete(self._cacheToken(uid))

        # Call the registered notification callback - we need to do this as a preCommit since it involves
        # a bunch of deferred operations, but this propstore api is not deferred. preCommit will execute
        # the deferreds properly, and it is fine to wait until everything else is done before sending the
        # notifications.
        if hasattr(self, "_notifyCallback") and self._notifyCallback is not None:
            self._txn.preCommit(self._notifyCallback)

        def justLogIt(f):
            f.trap(AllRetriesFailed)
            self.log.error("setting a property failed; probably nothing.")
        self._txn.subtransaction(trySetItem).addErrback(justLogIt)
Exemplo n.º 18
0
 def __setitem__(self, key, value):
     validKey(key)
     raise PropertyChangeNotAllowedError("Property store is read-only.", (key,))
Exemplo n.º 19
0
 def __delitem__(self, key):
     validKey(key)
     raise KeyError(key)
Exemplo n.º 20
0
 def __setitem__(self, key, value):
     validKey(key)
     raise PropertyChangeNotAllowedError("Property store is read-only.", (key,))
Exemplo n.º 21
0
 def __delitem__(self, key):
     validKey(key)
     raise KeyError(key)