comparison idavoll/idavoll.py @ 159:6fe78048baf9

Rework error handling, depend on Twisted Words 0.4.0. Twisted Words 0.4.0 introduced support for stanza error handling, much better than the custom error handling in Idavoll. Also, all protocol-level errors were examined and brought up to date with version 1.8 of JEP-0060. As a result of the error examination, the retrieval of default configuration options using <default/> is now supported properly.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 06 Sep 2006 12:38:47 +0000
parents 5191ba7c4df8
children 1701c0e2c707
comparison
equal deleted inserted replaced
158:b2149e448465 159:6fe78048baf9
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 twisted.words.protocols.jabber import component 4 from twisted.words.protocols.jabber import component, error
5 from twisted.application import service 5 from twisted.application import service
6 from twisted.internet import defer 6 from twisted.internet import defer
7 import backend 7 import backend
8 import pubsub 8 import pubsub
9 import xmpp_error
10 import disco 9 import disco
11 10
12 import sys 11 import sys
13 12
14 __version__ = '0.5.0' 13 __version__ = '0.5.0'
67 info = [] 66 info = []
68 for i in results: 67 for i in results:
69 info.extend(i[1]) 68 info.extend(i[1])
70 69
71 if node and not info: 70 if node and not info:
72 return xmpp_error.error_from_iq(iq, 'item-not-found') 71 return error.StanzaError('item-not-found').toResponse(iq)
73 else: 72 else:
74 iq.swapAttributeValues("to", "from") 73 iq.swapAttributeValues("to", "from")
75 iq["type"] = "result" 74 iq["type"] = "result"
76 for item in info: 75 for item in info:
77 #domish.Element.addChild should probably do this for all 76 #domish.Element.addChild should probably do this for all
83 return iq 82 return iq
84 83
85 def _error(self, result, iq): 84 def _error(self, result, iq):
86 print "Got error on index %d:" % result.value[1] 85 print "Got error on index %d:" % result.value[1]
87 result.value[0].printBriefTraceback() 86 result.value[0].printBriefTraceback()
88 return xmpp_error.error_from_iq(iq, 'internal-server-error') 87 return error.StanzaError('internal-server-error').toResponse(iq)
89 88
90 def onDiscoItems(self, iq): 89 def onDiscoItems(self, iq):
91 dl = [] 90 dl = []
92 node = iq.query.getAttribute("node") 91 node = iq.query.getAttribute("node")
93 92
116 115
117 def iqFallback(self, iq): 116 def iqFallback(self, iq):
118 if iq.handled == True: 117 if iq.handled == True:
119 return 118 return
120 119
121 self.send(xmpp_error.error_from_iq(iq, 'service-unavailable')) 120 self.send(error.StanzaError('service-unavailable').toResponse(iq))
122 121
123 class LogService(component.Service): 122 class LogService(component.Service):
124 123
125 def transportConnected(self, xmlstream): 124 def transportConnected(self, xmlstream):
126 xmlstream.rawDataInFn = self.rawDataIn 125 xmlstream.rawDataInFn = self.rawDataIn