comparison idavoll/pubsub.py @ 164:40d931ed15b9

Make imports work with Twisted 0.5.0. Author: ralphm Fixes #3
author Ralph Meijer <ralphm@ik.nu>
date Thu, 18 Jan 2007 13:52:39 +0000
parents 6fe78048baf9
children
comparison
equal deleted inserted replaced
163:1701c0e2c707 164:40d931ed15b9
1 # Copyright (c) 2003-2006 Ralph Meijer 1 # Copyright (c) 2003-2006 Ralph Meijer
2 # See LICENSE for details. 2 # See LICENSE for details.
3 3
4 from zope.interface import implements
5
4 from twisted.words.protocols.jabber import component, jid, error 6 from twisted.words.protocols.jabber import component, jid, error
5 from twisted.words.xish import utility, domish 7 from twisted.words.xish import domish
6 from twisted.python import components 8 from twisted.python import components
7 from twisted.internet import defer 9 from twisted.internet import defer
8 from zope.interface import implements
9 10
10 import backend 11 import backend
11 import storage 12 import storage
12 import disco 13 import disco
13 import data_form 14 import data_form
15
16 try:
17 from twisted.words.protocols.jabber.ijabber import IService
18 except ImportError:
19 from twisted.words.protocols.jabber.component import IService
14 20
15 if issubclass(domish.SerializedXML, str): 21 if issubclass(domish.SerializedXML, str):
16 # Work around bug # in twisted Xish 22 # Work around bug # in twisted Xish
17 class SerializedXML(unicode): 23 class SerializedXML(unicode):
18 """ Marker class for pre-serialized XML in the DOM. """ 24 """ Marker class for pre-serialized XML in the DOM. """
84 backend.NoRootNode: ('bad-request', None, None), 90 backend.NoRootNode: ('bad-request', None, None),
85 } 91 }
86 92
87 class Service(component.Service): 93 class Service(component.Service):
88 94
89 implements(component.IService) 95 implements(IService)
90 96
91 def __init__(self, backend): 97 def __init__(self, backend):
92 self.backend = backend 98 self.backend = backend
93 99
94 def error(self, failure, iq): 100 def error(self, failure, iq):
201 for node in nodes]) 207 for node in nodes])
202 return d 208 return d
203 209
204 components.registerAdapter(ComponentServiceFromService, 210 components.registerAdapter(ComponentServiceFromService,
205 backend.IBackendService, 211 backend.IBackendService,
206 component.IService) 212 IService)
207 213
208 class ComponentServiceFromNotificationService(Service): 214 class ComponentServiceFromNotificationService(Service):
209 215
210 def componentConnected(self, xmlstream): 216 def componentConnected(self, xmlstream):
211 self.backend.register_notifier(self.notify) 217 self.backend.register_notifier(self.notify)
230 items.children.extend(itemlist) 236 items.children.extend(itemlist)
231 self.send(message) 237 self.send(message)
232 238
233 components.registerAdapter(ComponentServiceFromNotificationService, 239 components.registerAdapter(ComponentServiceFromNotificationService,
234 backend.INotificationService, 240 backend.INotificationService,
235 component.IService) 241 IService)
236 242
237 class ComponentServiceFromPublishService(Service): 243 class ComponentServiceFromPublishService(Service):
238 244
239 def componentConnected(self, xmlstream): 245 def componentConnected(self, xmlstream):
240 xmlstream.addObserver(PUBSUB_PUBLISH, self.onPublish) 246 xmlstream.addObserver(PUBSUB_PUBLISH, self.onPublish)
264 return self.backend.publish(node, items, 270 return self.backend.publish(node, items,
265 jid.internJID(iq["from"]).userhostJID()) 271 jid.internJID(iq["from"]).userhostJID())
266 272
267 components.registerAdapter(ComponentServiceFromPublishService, 273 components.registerAdapter(ComponentServiceFromPublishService,
268 backend.IPublishService, 274 backend.IPublishService,
269 component.IService) 275 IService)
270 276
271 class ComponentServiceFromSubscriptionService(Service): 277 class ComponentServiceFromSubscriptionService(Service):
272 278
273 def componentConnected(self, xmlstream): 279 def componentConnected(self, xmlstream):
274 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe) 280 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe)
355 item['subscription'] = state 361 item['subscription'] = state
356 return [reply] 362 return [reply]
357 363
358 components.registerAdapter(ComponentServiceFromSubscriptionService, 364 components.registerAdapter(ComponentServiceFromSubscriptionService,
359 backend.ISubscriptionService, 365 backend.ISubscriptionService,
360 component.IService) 366 IService)
361 367
362 class ComponentServiceFromNodeCreationService(Service): 368 class ComponentServiceFromNodeCreationService(Service):
363 369
364 def componentConnected(self, xmlstream): 370 def componentConnected(self, xmlstream):
365 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate) 371 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate)
484 490
485 return options 491 return options
486 492
487 components.registerAdapter(ComponentServiceFromNodeCreationService, 493 components.registerAdapter(ComponentServiceFromNodeCreationService,
488 backend.INodeCreationService, 494 backend.INodeCreationService,
489 component.IService) 495 IService)
490 496
491 class ComponentServiceFromAffiliationsService(Service): 497 class ComponentServiceFromAffiliationsService(Service):
492 498
493 def componentConnected(self, xmlstream): 499 def componentConnected(self, xmlstream):
494 xmlstream.addObserver(PUBSUB_AFFILIATIONS, self.onAffiliations) 500 xmlstream.addObserver(PUBSUB_AFFILIATIONS, self.onAffiliations)
519 item['affiliation'] = affiliation 525 item['affiliation'] = affiliation
520 return [reply] 526 return [reply]
521 527
522 components.registerAdapter(ComponentServiceFromAffiliationsService, 528 components.registerAdapter(ComponentServiceFromAffiliationsService,
523 backend.IAffiliationsService, 529 backend.IAffiliationsService,
524 component.IService) 530 IService)
525 531
526 class ComponentServiceFromItemRetrievalService(Service): 532 class ComponentServiceFromItemRetrievalService(Service):
527 533
528 def componentConnected(self, xmlstream): 534 def componentConnected(self, xmlstream):
529 xmlstream.addObserver(PUBSUB_ITEMS, self.onItems) 535 xmlstream.addObserver(PUBSUB_ITEMS, self.onItems)
577 583
578 return [reply] 584 return [reply]
579 585
580 components.registerAdapter(ComponentServiceFromItemRetrievalService, 586 components.registerAdapter(ComponentServiceFromItemRetrievalService,
581 backend.IItemRetrievalService, 587 backend.IItemRetrievalService,
582 component.IService) 588 IService)
583 589
584 class ComponentServiceFromRetractionService(Service): 590 class ComponentServiceFromRetractionService(Service):
585 591
586 def componentConnected(self, xmlstream): 592 def componentConnected(self, xmlstream):
587 xmlstream.addObserver(PUBSUB_RETRACT, self.onRetract) 593 xmlstream.addObserver(PUBSUB_RETRACT, self.onRetract)
629 return self.backend.purge_node(node, 635 return self.backend.purge_node(node,
630 jid.internJID(iq["from"]).userhostJID()) 636 jid.internJID(iq["from"]).userhostJID())
631 637
632 components.registerAdapter(ComponentServiceFromRetractionService, 638 components.registerAdapter(ComponentServiceFromRetractionService,
633 backend.IRetractionService, 639 backend.IRetractionService,
634 component.IService) 640 IService)
635 641
636 class ComponentServiceFromNodeDeletionService(Service): 642 class ComponentServiceFromNodeDeletionService(Service):
637 643
638 def __init__(self, backend): 644 def __init__(self, backend):
639 Service.__init__(self, backend) 645 Service.__init__(self, backend)
683 return self.backend.delete_node(node, 689 return self.backend.delete_node(node,
684 jid.internJID(iq["from"]).userhostJID()) 690 jid.internJID(iq["from"]).userhostJID())
685 691
686 components.registerAdapter(ComponentServiceFromNodeDeletionService, 692 components.registerAdapter(ComponentServiceFromNodeDeletionService,
687 backend.INodeDeletionService, 693 backend.INodeDeletionService,
688 component.IService) 694 IService)