comparison sat_pubsub/backend.py @ 240:70c8bb90d75f

added access_model to config, default to 'open'
author Goffi <goffi@goffi.org>
date Tue, 22 May 2012 21:21:57 +0200
parents 6596730685e8
children 42048e37699e
comparison
equal deleted inserted replaced
239:2b50e4664d74 240:70c8bb90d75f
68 68
69 from twisted.application import service 69 from twisted.application import service
70 from twisted.python import components, log 70 from twisted.python import components, log
71 from twisted.internet import defer, reactor 71 from twisted.internet import defer, reactor
72 from twisted.words.protocols.jabber.error import StanzaError 72 from twisted.words.protocols.jabber.error import StanzaError
73 from twisted.words.protocols.jabber.jid import JID 73 from twisted.words.protocols.jabber.jid import JID, InvalidFormat
74 from twisted.words.xish import utility 74 from twisted.words.xish import utility
75 75
76 from wokkel import disco 76 from wokkel import disco
77 from wokkel.iwokkel import IPubSubResource 77 from wokkel.iwokkel import IPubSubResource
78 from wokkel.pubsub import PubSubResource, PubSubError 78 from wokkel.pubsub import PubSubResource, PubSubError
601 self.backend = backend 601 self.backend = backend
602 self.hideNodes = False 602 self.hideNodes = False
603 603
604 self.backend.registerNotifier(self._notify) 604 self.backend.registerNotifier(self._notify)
605 self.backend.registerPreDelete(self._preDelete) 605 self.backend.registerPreDelete(self._preDelete)
606
606 if self.backend.supportsCreatorCheck(): 607 if self.backend.supportsCreatorCheck():
607 self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to 608 self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to
608 # a jid in this server) is created by the right jid 609 # a jid in this server) is created by the right jid
609 610
610 if self.backend.supportsAutoCreate(): 611 if self.backend.supportsAutoCreate():
661 else: 662 else:
662 exc = StanzaError(condition, text=msg) 663 exc = StanzaError(condition, text=msg)
663 664
664 raise exc 665 raise exc
665 666
666
667 def getInfo(self, requestor, service, nodeIdentifier): 667 def getInfo(self, requestor, service, nodeIdentifier):
668 info = {} 668 info = {}
669 669
670 def saveType(result): 670 def saveType(result):
671 info['type'] = result 671 info['type'] = result
699 def getConfigurationOptions(self): 699 def getConfigurationOptions(self):
700 return self.backend.nodeOptions 700 return self.backend.nodeOptions
701 701
702 def _publish_errb(self, failure, request): 702 def _publish_errb(self, failure, request):
703 if failure.type == error.NodeNotFound and self.backend.supportsAutoCreate(): 703 if failure.type == error.NodeNotFound and self.backend.supportsAutoCreate():
704 print "Auto-creating node %s" % (request.nodeIdentifier,)
704 d = self.backend.createNode(request.nodeIdentifier, 705 d = self.backend.createNode(request.nodeIdentifier,
705 request.sender) 706 request.sender)
706 d.addCallback(lambda ignore, 707 d.addCallback(lambda ignore,
707 request: self.backend.publish(request.nodeIdentifier, 708 request: self.backend.publish(request.nodeIdentifier,
708 request.items, 709 request.items,
709 request.sender), 710 request.sender),
710 request) 711 request)
711 return d 712 return d
712 713
713 raise failure 714 return failure
714
715 715
716 def publish(self, request): 716 def publish(self, request):
717 d = self.backend.publish(request.nodeIdentifier, 717 d = self.backend.publish(request.nodeIdentifier,
718 request.items, 718 request.items,
719 request.sender) 719 request.sender)