Changeset 6:283b6997cf7d
- Timestamp:
- Oct 4, 2007, 9:47:22 AM (15 years ago)
- Branch:
- default
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@13
- Location:
- wokkel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/component.py
r1 r6 28 28 if domish.IElement.providedBy(obj) and \ 29 29 not obj.getAttribute('from'): 30 obj['from'] = self.xmlstream.this Host30 obj['from'] = self.xmlstream.thisEntity.full() 31 31 old_send(obj) 32 32 -
wokkel/disco.py
r5 r6 85 85 86 86 def _onDiscoInfo(self, iq): 87 requestor = jid.internJID(iq["from"]) 87 88 target = jid.internJID(iq["to"]) 88 requestor = jid.internJID(iq["from"])89 89 nodeIdentifier = iq.query.getAttribute("node") 90 90 … … 107 107 for handler in self.parent: 108 108 if IDisco.providedBy(handler): 109 dl.append(handler.getDiscoInfo( target, requestor,109 dl.append(handler.getDiscoInfo(requestor, target, 110 110 nodeIdentifier)) 111 111 … … 115 115 116 116 def _onDiscoItems(self, iq): 117 requestor = jid.internJID(iq["from"]) 117 118 target = jid.internJID(iq["to"]) 118 requestor = jid.internJID(iq["from"])119 119 nodeIdentifier = iq.query.getAttribute("node") 120 120 … … 134 134 for handler in self.parent: 135 135 if IDisco.providedBy(handler): 136 dl.append(handler.getDiscoItems( target, requestor,136 dl.append(handler.getDiscoItems(requestor, target, 137 137 nodeIdentifier)) 138 138 -
wokkel/generic.py
r2 r6 68 68 iq.handled = True 69 69 70 def getDiscoInfo(self, target, requestor, node):70 def getDiscoInfo(self, requestor, target, node): 71 71 if not node: 72 72 return defer.succeed(set([disco.DiscoFeature(NS_VERSION)])) 73 73 74 def getDiscoItems(self, target, requestor, node):74 def getDiscoItems(self, requestor, target, node): 75 75 return defer.succeed([]) -
wokkel/iwokkel.py
r4 r6 105 105 """ 106 106 107 def getDiscoInfo( target, requestor, nodeIdentifier=None):107 def getDiscoInfo(requestor, target, nodeIdentifier=None): 108 108 """ 109 109 Get identity and features from this entity, node. … … 111 111 @param requestor: The entity the request originated from. 112 112 @type requestor: L{jid.JID} 113 @param target: The target entity to which the request is made. 114 @type target: L{jid.JID} 113 115 @param nodeIdentifier: The optional identifier of the node at this 114 116 entity to retrieve the identify and features of. … … 117 119 """ 118 120 119 def getDiscoItems( target, requestor, nodeIdentifier=None):121 def getDiscoItems(requestor, target, nodeIdentifier=None): 120 122 """ 121 123 Get contained items for this entity, node. … … 123 125 @param requestor: The entity the request originated from. 124 126 @type requestor: L{jid.JID} 127 @param target: The target entity to which the request is made. 128 @type target: L{jid.JID} 125 129 @param nodeIdentifier: The optional identifier of the node at this 126 130 entity to retrieve the identify and features of. … … 132 136 class IPubSubClient(Interface): 133 137 134 def itemsReceived( notifier, node, items):138 def itemsReceived(recipient, service, nodeIdentifier, items): 135 139 """ 136 140 Called when items have been received from a node. 137 141 138 @param notifier: the entity from which the notification was received. 139 @type notifier: L{jid.JID} 140 @param node: identifier of the node the items belong to. 141 @type node: C{unicode} 142 @param items: list of received items as domish elements. 142 @param recipient: The entity to which the notification was sent. 143 @type recipient: L{jid.JID} 144 @param service: The entity from which the notification was received. 145 @type service: L{jid.JID} 146 @param nodeIdentifier: Identifier of the node the items belong to. 147 @type nodeIdentifier: C{unicode} 148 @param items: List of received items as domish elements. 143 149 @type items: C{list} of L{domish.Element} 144 150 """ 145 151 146 def createNode( node=None):152 def createNode(service, nodeIdentifier=None): 147 153 """ 148 154 Create a new publish subscribe node. 149 155 150 @param node: optional suggestion for the new node's identifier. If 151 omitted, the creation of an instant node will be 152 attempted. 153 @type node: L{unicode} 156 @param service: The publish-subscribe service entity. 157 @type service: L{jid.JID} 158 @param nodeIdentifier: Optional suggestion for the new node's 159 identifier. If omitted, the creation of an 160 instant node will be attempted. 161 @type nodeIdentifier: L{unicode} 154 162 @return: a deferred that fires with the identifier of the newly created 155 163 node. Note that this can differ from the suggested identifier … … 159 167 """ 160 168 161 def deleteNode( node):169 def deleteNode(service, nodeIdentifier): 162 170 """ 163 171 Delete a node. 164 172 165 @param node: identifier of the node to be deleted. 166 @type node: L{unicode} 167 @rtype: L{defer.Deferred} 168 """ 169 170 def subscribe(node, subscriber): 173 @param service: The publish-subscribe service entity. 174 @type service: L{jid.JID} 175 @param nodeIdentifier: Identifier of the node to be deleted. 176 @type nodeIdentifier: L{unicode} 177 @rtype: L{defer.Deferred} 178 """ 179 180 def subscribe(service, nodeIdentifier, subscriber): 171 181 """ 172 182 Subscribe to a node with a given JID. 173 183 174 @param node: identifier of the node to subscribe to. 175 @type node: L{unicode} 184 @param service: The publish-subscribe service entity. 185 @type service: L{jid.JID} 186 @param nodeIdentifier: Identifier of the node to subscribe to. 187 @type nodeIdentifier: L{unicode} 176 188 @param subscriber: JID to subscribe to the node. 177 189 @type subscriber: L{jid.JID} … … 179 191 """ 180 192 181 def publish( requestor, node, items=[]):193 def publish(service, nodeIdentifier, items=[]): 182 194 """ 183 195 Publish to a node. … … 187 199 actions only signify a change in some resource. 188 200 189 @param node: identifier of the node to publish to. 190 @type node: L{unicode} 191 @param items: list of item elements. 201 @param service: The publish-subscribe service entity. 202 @type service: L{jid.JID} 203 @param nodeIdentifier: Identifier of the node to publish to. 204 @type nodeIdentifier: L{unicode} 205 @param items: List of item elements. 192 206 @type items: L{list} of L{Item} 193 207 @rtype: L{defer.Deferred} … … 205 219 """ 206 220 207 def notifyPublish( entity, nodeIdentifier, notifications):221 def notifyPublish(service, nodeIdentifier, notifications): 208 222 """ 209 223 Send out notifications for a publish event. 210 224 211 @param entity: The entity the notifications will originate from.212 @type entity: L{jid.JID}225 @param service: The entity the notifications will originate from. 226 @type service: L{jid.JID} 213 227 @param nodeIdentifier: The identifier of the node that was published 214 228 to. … … 220 234 """ 221 235 222 def publish(requestor, nodeIdentifier, items):236 def publish(requestor, service, nodeIdentifier, items): 223 237 """ 224 238 Called when a publish request has been received. … … 226 240 @param requestor: The entity the request originated from. 227 241 @type requestor: L{jid.JID} 242 @param service: The entity the request was addressed to. 243 @type service: L{jid.JID} 228 244 @param nodeIdentifier: The identifier of the node to publish to. 229 245 @type nodeIdentifier: C{unicode} … … 234 250 """ 235 251 236 def subscribe(requestor, nodeIdentifier, subscriber):252 def subscribe(requestor, service, nodeIdentifier, subscriber): 237 253 """ 238 254 Called when a subscribe request has been received. … … 240 256 @param requestor: The entity the request originated from. 241 257 @type requestor: L{jid.JID} 258 @param service: The entity the request was addressed to. 259 @type service: L{jid.JID} 242 260 @param nodeIdentifier: The identifier of the node to subscribe to. 243 261 @type nodeIdentifier: C{unicode} … … 249 267 """ 250 268 251 def unsubscribe(requestor, nodeIdentifier, subscriber):269 def unsubscribe(requestor, service, nodeIdentifier, subscriber): 252 270 """ 253 271 Called when a subscribe request has been received. … … 255 273 @param requestor: The entity the request originated from. 256 274 @type requestor: L{jid.JID} 275 @param service: The entity the request was addressed to. 276 @type service: L{jid.JID} 257 277 @param nodeIdentifier: The identifier of the node to unsubscribe from. 258 278 @type nodeIdentifier: C{unicode} … … 264 284 """ 265 285 266 def subscriptions(requestor ):286 def subscriptions(requestor, service): 267 287 """ 268 288 Called when a subscriptions retrieval request has been received. … … 270 290 @param requestor: The entity the request originated from. 271 291 @type requestor: L{jid.JID} 292 @param service: The entity the request was addressed to. 293 @type service: L{jid.JID} 272 294 @return: A deferred that fires with a C{list} of suscriptions as 273 295 C{tuple}s of (node identifier as C{unicode}, subscriber as … … 277 299 """ 278 300 279 def affiliations(requestor ):301 def affiliations(requestor, service): 280 302 """ 281 303 Called when a affiliations retrieval request has been received. … … 283 305 @param requestor: The entity the request originated from. 284 306 @type requestor: L{jid.JID} 307 @param service: The entity the request was addressed to. 308 @type service: L{jid.JID} 285 309 @return: A deferred that fires with a C{list} of affiliations as 286 310 C{tuple}s of (node identifier as C{unicode}, affiliation state … … 290 314 """ 291 315 292 def create(requestor, nodeIdentifier):316 def create(requestor, service, nodeIdentifier): 293 317 """ 294 318 Called when a node creation request has been received. … … 296 320 @param requestor: The entity the request originated from. 297 321 @type requestor: L{jid.JID} 322 @param service: The entity the request was addressed to. 323 @type service: L{jid.JID} 298 324 @param nodeIdentifier: The suggestion for the identifier of the node to 299 325 be created. If the request did not include a … … 306 332 """ 307 333 308 def getDefaultConfiguration(requestor ):334 def getDefaultConfiguration(requestor, service): 309 335 """ 310 336 Called when a default node configuration request has been received. … … 312 338 @param requestor: The entity the request originated from. 313 339 @type requestor: L{jid.JID} 340 @param service: The entity the request was addressed to. 341 @type service: L{jid.JID} 314 342 @return: A deferred that fires with a C{dict} representing the default 315 343 node configuration. Keys are C{str}s that represent the … … 319 347 """ 320 348 321 def getConfiguration(requestor, nodeIdentifier):349 def getConfiguration(requestor, service, nodeIdentifier): 322 350 """ 323 351 Called when a node configuration retrieval request has been received. … … 325 353 @param requestor: The entity the request originated from. 326 354 @type requestor: L{jid.JID} 355 @param service: The entity the request was addressed to. 356 @type service: L{jid.JID} 327 357 @param nodeIdentifier: The identifier of the node to retrieve the 328 358 configuration from. … … 334 364 """ 335 365 336 def setConfiguration(requestor, nodeIdentifier, options):366 def setConfiguration(requestor, service, nodeIdentifier, options): 337 367 """ 338 368 Called when a node configuration change request has been received. … … 340 370 @param requestor: The entity the request originated from. 341 371 @type requestor: L{jid.JID} 372 @param service: The entity the request was addressed to. 373 @type service: L{jid.JID} 342 374 @param nodeIdentifier: The identifier of the node to change the 343 375 configuration of. … … 348 380 """ 349 381 350 def items(requestor, nodeIdentifier, maxItems, itemIdentifiers):382 def items(requestor, service, nodeIdentifier, maxItems, itemIdentifiers): 351 383 """ 352 384 Called when a items retrieval request has been received. … … 354 386 @param requestor: The entity the request originated from. 355 387 @type requestor: L{jid.JID} 388 @param service: The entity the request was addressed to. 389 @type service: L{jid.JID} 356 390 @param nodeIdentifier: The identifier of the node to retrieve items 357 391 from. … … 359 393 """ 360 394 361 def retract(requestor, nodeIdentifier, itemIdentifiers):395 def retract(requestor, service, nodeIdentifier, itemIdentifiers): 362 396 """ 363 397 Called when a item retraction request has been received. … … 365 399 @param requestor: The entity the request originated from. 366 400 @type requestor: L{jid.JID} 401 @param service: The entity the request was addressed to. 402 @type service: L{jid.JID} 367 403 @param nodeIdentifier: The identifier of the node to retract items 368 404 from. … … 370 406 """ 371 407 372 def purge(requestor, nodeIdentifier):408 def purge(requestor, service, nodeIdentifier): 373 409 """ 374 410 Called when a node purge request has been received. … … 376 412 @param requestor: The entity the request originated from. 377 413 @type requestor: L{jid.JID} 414 @param service: The entity the request was addressed to. 415 @type service: L{jid.JID} 378 416 @param nodeIdentifier: The identifier of the node to be purged. 379 417 @type nodeIdentifier: C{unicode} 380 418 """ 381 419 382 def delete(requestor, nodeIdentifier):420 def delete(requestor, service, nodeIdentifier): 383 421 """ 384 422 Called when a node deletion request has been received. … … 386 424 @param requestor: The entity the request originated from. 387 425 @type requestor: L{jid.JID} 426 @param service: The entity the request was addressed to. 427 @type service: L{jid.JID} 388 428 @param nodeIdentifier: The identifier of the node to be delete. 389 429 @type nodeIdentifier: C{unicode} 390 430 """ 391 392 -
wokkel/pubsub.py
r2 r6 222 222 def _onItems(self, message): 223 223 try: 224 notifier = jid.JID(message["from"]) 225 node = message.event.items["node"] 224 service = jid.JID(message["from"]) 225 recipient = jid.JID(message["to"]) 226 nodeIdentifier = message.event.items["node"] 226 227 except KeyError: 227 228 return … … 230 231 if element.name == 'item'] 231 232 232 self.itemsReceived( notifier, node, items)233 234 def itemsReceived(self, notifier, node, items):233 self.itemsReceived(recipient, service, nodeIdentifier, items) 234 235 def itemsReceived(self, recipient, service, nodeIdentifier, items): 235 236 pass 236 237 237 def createNode(self, service, node =None):238 request = CreateNode(self.xmlstream, node )238 def createNode(self, service, nodeIdentifier=None): 239 request = CreateNode(self.xmlstream, nodeIdentifier) 239 240 240 241 def cb(iq): … … 243 244 except AttributeError: 244 245 # the suggested node identifier was accepted 245 new_node = node 246 new_node = nodeIdentifier 246 247 return new_node 247 248 248 249 return request.send(service).addCallback(cb) 249 250 250 def deleteNode(self, service, node ):251 return DeleteNode(self.xmlstream, node ).send(service)252 253 def subscribe(self, service, node , subscriber):254 request = Subscribe(self.xmlstream, node , subscriber)251 def deleteNode(self, service, nodeIdentifier): 252 return DeleteNode(self.xmlstream, nodeIdentifier).send(service) 253 254 def subscribe(self, service, nodeIdentifier, subscriber): 255 request = Subscribe(self.xmlstream, nodeIdentifier, subscriber) 255 256 256 257 def cb(iq): … … 269 270 return request.send(service).addCallback(cb) 270 271 271 def publish(self, service, node , items=[]):272 request = Publish(self.xmlstream, node )272 def publish(self, service, nodeIdentifier, items=[]): 273 request = Publish(self.xmlstream, nodeIdentifier) 273 274 for item in items: 274 275 request.command.addChild(item) … … 343 344 self.xmlstream.addObserver(PUBSUB_OWNER_SET, self.handleRequest) 344 345 345 def getDiscoInfo(self, target, requestor, nodeIdentifier):346 def getDiscoInfo(self, requestor, target, nodeIdentifier): 346 347 info = [] 347 348 … … 379 380 return d 380 381 381 def getDiscoItems(self, target, requestor, nodeIdentifier):382 def getDiscoItems(self, requestor, target, nodeIdentifier): 382 383 if nodeIdentifier or self.hideNodes: 383 384 return defer.succeed([]) … … 390 391 def _onPublish(self, iq): 391 392 requestor = jid.internJID(iq["from"]).userhostJID() 393 service = jid.internJID(iq["to"]) 392 394 393 395 try: … … 401 403 items.append(element) 402 404 403 return self.publish(requestor, nodeIdentifier, items)405 return self.publish(requestor, service, nodeIdentifier, items) 404 406 405 407 def _onSubscribe(self, iq): 406 408 requestor = jid.internJID(iq["from"]).userhostJID() 409 service = jid.internJID(iq["to"]) 407 410 408 411 try: … … 421 424 return response 422 425 423 d = self.subscribe(requestor, nodeIdentifier, subscriber)426 d = self.subscribe(requestor, service, nodeIdentifier, subscriber) 424 427 d.addCallback(toResponse) 425 428 return d … … 427 430 def _onUnsubscribe(self, iq): 428 431 requestor = jid.internJID(iq["from"]).userhostJID() 432 service = jid.internJID(iq["to"]) 429 433 430 434 try: … … 434 438 raise BadRequest 435 439 436 return self.unsubscribe(requestor, nodeIdentifier, subscriber)440 return self.unsubscribe(requestor, service, nodeIdentifier, subscriber) 437 441 438 442 def _onOptionsGet(self, iq): … … 444 448 def _onSubscriptions(self, iq): 445 449 requestor = jid.internJID(iq["from"]).userhostJID() 450 service = jid.internJID(iq["to"]) 446 451 447 452 def toResponse(result): … … 455 460 return response 456 461 457 d = self.subscriptions(requestor )462 d = self.subscriptions(requestor, service) 458 463 d.addCallback(toResponse) 459 464 return d … … 461 466 def _onAffiliations(self, iq): 462 467 requestor = jid.internJID(iq["from"]).userhostJID() 468 service = jid.internJID(iq["to"]) 463 469 464 470 def toResponse(result): … … 473 479 return response 474 480 475 d = self.affiliations(requestor )481 d = self.affiliations(requestor, service) 476 482 d.addCallback(toResponse) 477 483 return d … … 479 485 def _onCreate(self, iq): 480 486 requestor = jid.internJID(iq["from"]).userhostJID() 487 service = jid.internJID(iq["to"]) 481 488 nodeIdentifier = iq.pubsub.create.getAttribute("node") 482 489 … … 490 497 return None 491 498 492 d = self.create(requestor, nodeIdentifier)499 d = self.create(requestor, service, nodeIdentifier) 493 500 d.addCallback(toResponse) 494 501 return d … … 504 511 def _onDefault(self, iq): 505 512 requestor = jid.internJID(iq["from"]).userhostJID() 513 service = jid.internJID(iq["to"]) 506 514 507 515 def toResponse(options): … … 511 519 return response 512 520 513 d = self.getDefaultConfiguration(requestor )521 d = self.getDefaultConfiguration(requestor, service) 514 522 d.addCallback(toResponse) 515 523 return d … … 517 525 def _onConfigureGet(self, iq): 518 526 requestor = jid.internJID(iq["from"]).userhostJID() 527 service = jid.internJID(iq["to"]) 519 528 nodeIdentifier = iq.pubsub.configure.getAttribute("node") 520 529 … … 529 538 return response 530 539 531 d = self.getConfiguration(requestor, nodeIdentifier)540 d = self.getConfiguration(requestor, service, nodeIdentifier) 532 541 d.addCallback(toResponse) 533 542 return d … … 535 544 def _onConfigureSet(self, iq): 536 545 requestor = jid.internJID(iq["from"]).userhostJID() 546 service = jid.internJID(iq["to"]) 537 547 nodeIdentifier = iq.pubsub.configure["node"] 538 548 … … 566 576 if options["FORM_TYPE"] == NS_PUBSUB + "#node_config": 567 577 del options["FORM_TYPE"] 568 return self.setConfiguration(requestor, nodeIdentifier,569 options)578 return self.setConfiguration(requestor, service, 579 nodeIdentifier, options) 570 580 571 581 raise BadRequest … … 573 583 def _onItems(self, iq): 574 584 requestor = jid.internJID(iq["from"]).userhostJID() 585 service = jid.internJID(iq["to"]) 575 586 576 587 try: … … 605 616 return response 606 617 607 d = self.items(requestor, nodeIdentifier, maxItems, itemIdentifiers) 618 d = self.items(requestor, service, nodeIdentifier, maxItems, 619 itemIdentifiers) 608 620 d.addCallback(toResponse) 609 621 return d … … 611 623 def _onRetract(self, iq): 612 624 requestor = jid.internJID(iq["from"]).userhostJID() 625 service = jid.internJID(iq["to"]) 613 626 614 627 try: … … 625 638 raise BadRequest 626 639 627 return self.retract(requestor, nodeIdentifier, itemIdentifiers) 640 return self.retract(requestor, service, nodeIdentifier, 641 itemIdentifiers) 628 642 629 643 def _onPurge(self, iq): 630 644 requestor = jid.internJID(iq["from"]).userhostJID() 645 service = jid.internJID(iq["to"]) 631 646 632 647 try: … … 635 650 raise BadRequest 636 651 637 return self.purge(requestor, nodeIdentifier)652 return self.purge(requestor, service, nodeIdentifier) 638 653 639 654 def _onDelete(self, iq): 640 655 requestor = jid.internJID(iq["from"]).userhostJID() 656 service = jid.internJID(iq["to"]) 641 657 642 658 try: … … 645 661 raise BadRequest 646 662 647 return self.delete(requestor, nodeIdentifier)663 return self.delete(requestor, service, nodeIdentifier) 648 664 649 665 def _onAffiliationsGet(self, iq): … … 661 677 # public methods 662 678 663 def notifyPublish(self, entity, nodeIdentifier, notifications):679 def notifyPublish(self, service, nodeIdentifier, notifications): 664 680 665 681 print notifications 666 682 for recipient, items in notifications: 667 683 message = domish.Element((None, "message")) 668 message["from"] = entity.full()684 message["from"] = service.full() 669 685 message["to"] = recipient.full() 670 686 event = message.addElement((NS_PUBSUB_EVENT, "event")) … … 674 690 self.send(message) 675 691 676 def getNodeInfo(self, requestor, nodeIdentifier):692 def getNodeInfo(self, requestor, service, nodeIdentifier): 677 693 return None 678 694 679 def getNodes(self, requestor ):695 def getNodes(self, requestor, service): 680 696 return [] 681 697 682 def publish(self, requestor, nodeIdentifier, items):698 def publish(self, requestor, service, nodeIdentifier, items): 683 699 raise Unsupported('publish') 684 700 685 def subscribe(self, requestor, nodeIdentifier, subscriber):701 def subscribe(self, requestor, service, nodeIdentifier, subscriber): 686 702 raise Unsupported('subscribe') 687 703 688 def unsubscribe(self, requestor, nodeIdentifier, subscriber):704 def unsubscribe(self, requestor, service, nodeIdentifier, subscriber): 689 705 raise Unsupported('subscribe') 690 706 691 def subscriptions(self, requestor ):707 def subscriptions(self, requestor, service): 692 708 raise Unsupported('retrieve-subscriptions') 693 709 694 def affiliations(self, requestor ):710 def affiliations(self, requestor, service): 695 711 raise Unsupported('retrieve-affiliations') 696 712 697 def create(self, requestor, nodeIdentifier):713 def create(self, requestor, service, nodeIdentifier): 698 714 raise Unsupported('create-nodes') 699 715 700 def getDefaultConfiguration(self, requestor ):716 def getDefaultConfiguration(self, requestor, service): 701 717 raise Unsupported('retrieve-default') 702 718 703 def getConfiguration(self, requestor, nodeIdentifier):719 def getConfiguration(self, requestor, service, nodeIdentifier): 704 720 raise Unsupported('config-node') 705 721 706 def setConfiguration(self, requestor, nodeIdentifier, options):722 def setConfiguration(self, requestor, service, nodeIdentifier, options): 707 723 raise Unsupported('config-node') 708 724 709 def items(self, requestor, nodeIdentifier, maxItems, itemIdentifiers): 725 def items(self, requestor, service, nodeIdentifier, maxItems, 726 itemIdentifiers): 710 727 raise Unsupported('retrieve-items') 711 728 712 def retract(self, requestor, nodeIdentifier, itemIdentifiers):729 def retract(self, requestor, service, nodeIdentifier, itemIdentifiers): 713 730 raise Unsupported('retract-items') 714 731 715 def purge(self, requestor, nodeIdentifier):732 def purge(self, requestor, service, nodeIdentifier): 716 733 raise Unsupported('purge-nodes') 717 734 718 def delete(self, requestor, nodeIdentifier):735 def delete(self, requestor, service, nodeIdentifier): 719 736 raise Unsupported('delete-nodes') 720 -
wokkel/test/test_disco.py
r1 r6 7 7 8 8 from twisted.internet import defer 9 from twisted.test import proto_helpers10 9 from twisted.trial import unittest 11 10 from twisted.words.xish.xmlstream import XmlStreamFactory … … 22 21 implements(disco.IDisco) 23 22 24 def getDiscoInfo(self, nodeIdentifier):23 def getDiscoInfo(self, requestor, target, nodeIdentifier): 25 24 if nodeIdentifier is None: 26 25 return defer.succeed([ 27 disco. Identity('dummy', 'generic', 'Generic Dummy Entity'),28 disco. Feature('jabber:iq:version')26 disco.DiscoIdentity('dummy', 'generic', 'Generic Dummy Entity'), 27 disco.DiscoFeature('jabber:iq:version') 29 28 ]) 30 29 else: … … 35 34 factory = XmlStreamFactory() 36 35 sm = StreamManager(factory) 37 sm.addHandler(disco.DiscoHandler())38 sm.addHandler(DiscoResponder())36 disco.DiscoHandler().setHandlerParent(sm) 37 DiscoResponder().setHandlerParent(sm) 39 38 xs = factory.buildProtocol(None) 40 xs.transport = proto_helpers.StringTransport() 39 output = [] 40 xs.send = output.append 41 41 xs.connectionMade() 42 xs.dispatch(xs, "//event/stream/authd") 42 43 xs.dataReceived("<stream>") 43 xs.dataReceived("""<iq from='test@example.com' type='get'> 44 xs.dataReceived("""<iq from='test@example.com' to='example.com' 45 type='get'> 44 46 <query xmlns='%s'/> 45 47 </iq>""" % NS_DISCO_INFO) 48 reply = output[0] 49 self.assertEqual(NS_DISCO_INFO, reply.query.uri) 50 self.assertEqual(NS_DISCO_INFO, reply.query.identity.uri) 51 self.assertEqual('dummy', reply.query.identity['category']) 52 self.assertEqual('generic', reply.query.identity['type']) 53 self.assertEqual('Generic Dummy Entity', reply.query.identity['name']) 54 self.assertEqual(NS_DISCO_INFO, reply.query.feature.uri) 55 self.assertEqual('jabber:iq:version', reply.query.feature['var']) 56 -
wokkel/test/test_pubsub.py
r4 r6 26 26 iq = domish.Element((None, 'iq')) 27 27 iq['from'] = 'user@example.org' 28 iq['to'] = 'pubsub.example.org' 28 29 iq['type'] = 'set' 29 30 iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub')) … … 45 46 iq['type'] = 'set' 46 47 iq['from'] = 'user@example.org' 48 iq['to'] = 'pubsub.example.org' 47 49 iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub')) 48 50 iq.pubsub.addElement('publish') … … 50 52 handler.handleRequest(iq) 51 53 52 self.assertEqual((JID('user@example.org'), 'test', []), handler.args) 54 self.assertEqual((JID('user@example.org'), 55 JID('pubsub.example.org'), 'test', []), handler.args) 53 56 54 57 def test_onOptionsGet(self): … … 57 60 iq = domish.Element((None, 'iq')) 58 61 iq['from'] = 'user@example.org' 62 iq['to'] = 'pubsub.example.org' 59 63 iq['type'] = 'get' 60 64 iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
Note: See TracChangeset
for help on using the changeset viewer.