Esempio n. 1
0
    def _getNode(self, cursor, nodeIdentifier):
        configuration = {}
        cursor.execute(
            """SELECT node_type,
                                 persist_items,
                                 deliver_payloads,
                                 send_last_published_item
                          FROM nodes
                          WHERE node=%s""", (nodeIdentifier, ))
        row = cursor.fetchone()

        if not row:
            raise error.NodeNotFound()

        if row.node_type == 'leaf':
            configuration = {
                'pubsub#persist_items': row.persist_items,
                'pubsub#deliver_payloads': row.deliver_payloads,
                'pubsub#send_last_published_item': row.send_last_published_item
            }
            node = LeafNode(nodeIdentifier, configuration)
            node.dbpool = self.dbpool
            return node
        elif row.node_type == 'collection':
            configuration = {
                'pubsub#deliver_payloads': row.deliver_payloads,
                'pubsub#send_last_published_item': row.send_last_published_item
            }
            node = CollectionNode(nodeIdentifier, configuration)
            node.dbpool = self.dbpool
            return node
Esempio n. 2
0
    def trapNotFound(self, failure):
        failure.trap(StanzaError)

        if failure.value.condition == 'item-not-found':
            raise error.NodeNotFound()
        else:
            return failure
Esempio n. 3
0
    def deleteNode(self, nodeIdentifier):
        try:
            del self._nodes[nodeIdentifier]
        except KeyError:
            return defer.fail(error.NodeNotFound())

        return defer.succeed(None)
Esempio n. 4
0
    def getNode(self, nodeIdentifier):
        try:
            node = self._nodes[nodeIdentifier]
        except KeyError:
            return defer.fail(error.NodeNotFound())

        return defer.succeed(node)
Esempio n. 5
0
 def deleteNode(self, nodeIdentifier):
     if nodeIdentifier in ['to-be-deleted']:
         self.deleteCalled.append(nodeIdentifier)
         return defer.succeed(None)
     else:
         return defer.fail(error.NodeNotFound())
Esempio n. 6
0
 def _checkNodeExists(self, cursor):
     cursor.execute("""SELECT node_id FROM nodes WHERE node=%s""",
                    (self.nodeIdentifier, ))
     if not cursor.fetchone():
         raise error.NodeNotFound()
Esempio n. 7
0
    def _deleteNode(self, cursor, nodeIdentifier):
        cursor.execute("""DELETE FROM nodes WHERE node=%s""",
                       (nodeIdentifier, ))

        if cursor.rowcount != 1:
            raise error.NodeNotFound()