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
def trapNotFound(self, failure): failure.trap(StanzaError) if failure.value.condition == 'item-not-found': raise error.NodeNotFound() else: return failure
def deleteNode(self, nodeIdentifier): try: del self._nodes[nodeIdentifier] except KeyError: return defer.fail(error.NodeNotFound()) return defer.succeed(None)
def getNode(self, nodeIdentifier): try: node = self._nodes[nodeIdentifier] except KeyError: return defer.fail(error.NodeNotFound()) return defer.succeed(node)
def deleteNode(self, nodeIdentifier): if nodeIdentifier in ['to-be-deleted']: self.deleteCalled.append(nodeIdentifier) return defer.succeed(None) else: return defer.fail(error.NodeNotFound())
def _checkNodeExists(self, cursor): cursor.execute("""SELECT node_id FROM nodes WHERE node=%s""", (self.nodeIdentifier, )) if not cursor.fetchone(): raise error.NodeNotFound()
def _deleteNode(self, cursor, nodeIdentifier): cursor.execute("""DELETE FROM nodes WHERE node=%s""", (nodeIdentifier, )) if cursor.rowcount != 1: raise error.NodeNotFound()