Fixed indentation in StanzaBase.

This commit is contained in:
Lance Stout 2010-08-26 14:19:36 -04:00
parent 5c59f5baca
commit 56766508b3

View file

@ -875,85 +875,90 @@ class ElementBase(object):
class StanzaBase(ElementBase): class StanzaBase(ElementBase):
name = 'stanza' name = 'stanza'
namespace = 'jabber:client' namespace = 'jabber:client'
interfaces = set(('type', 'to', 'from', 'id', 'payload')) interfaces = set(('type', 'to', 'from', 'id', 'payload'))
types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat')) types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat'))
sub_interfaces = tuple() sub_interfaces = tuple()
def __init__(self, stream=None, xml=None, stype=None, sto=None, sfrom=None, sid=None): def __init__(self, stream=None, xml=None, stype=None,
self.stream = stream sto=None, sfrom=None, sid=None):
if stream is not None: self.stream = stream
self.namespace = stream.default_ns if stream is not None:
ElementBase.__init__(self, xml) self.namespace = stream.default_ns
if stype is not None: ElementBase.__init__(self, xml)
self['type'] = stype if stype is not None:
if sto is not None: self['type'] = stype
self['to'] = sto if sto is not None:
if sfrom is not None: self['to'] = sto
self['from'] = sfrom if sfrom is not None:
self.tag = "{%s}%s" % (self.namespace, self.name) self['from'] = sfrom
self.tag = "{%s}%s" % (self.namespace, self.name)
def setType(self, value): def setType(self, value):
if value in self.types: if value in self.types:
self.xml.attrib['type'] = value self.xml.attrib['type'] = value
return self return self
def getPayload(self): def getPayload(self):
return self.xml.getchildren() return self.xml.getchildren()
def setPayload(self, value): def setPayload(self, value):
self.xml.append(value) self.xml.append(value)
return self return self
def delPayload(self): def delPayload(self):
self.clear() self.clear()
return self return self
def clear(self): def clear(self):
for child in self.xml.getchildren(): for child in self.xml.getchildren():
self.xml.remove(child) self.xml.remove(child)
for plugin in list(self.plugins.keys()): for plugin in list(self.plugins.keys()):
del self.plugins[plugin] del self.plugins[plugin]
return self return self
def reply(self): def reply(self):
# if it's a component, use from # if it's a component, use from
if self.stream and hasattr(self.stream, "is_component") and self.stream.is_component: if self.stream and hasattr(self.stream, "is_component") and \
self['from'], self['to'] = self['to'], self['from'] self.stream.is_component:
else: self['from'], self['to'] = self['to'], self['from']
self['to'] = self['from'] else:
del self['from'] self['to'] = self['from']
self.clear() del self['from']
return self self.clear()
return self
def error(self): def error(self):
self['type'] = 'error' self['type'] = 'error'
return self return self
def getTo(self): def getTo(self):
return JID(self._getAttr('to')) return JID(self._getAttr('to'))
def setTo(self, value): def setTo(self, value):
return self._setAttr('to', str(value)) return self._setAttr('to', str(value))
def getFrom(self): def getFrom(self):
return JID(self._getAttr('from')) return JID(self._getAttr('from'))
def setFrom(self, value): def setFrom(self, value):
return self._setAttr('from', str(value)) return self._setAttr('from', str(value))
def unhandled(self): def unhandled(self):
pass pass
def exception(self, e): def exception(self, e):
logging.exception('Error handling {%s}%s stanza' % (self.namespace, self.name)) logging.exception('Error handling {%s}%s stanza' % (self.namespace,
self.name))
def send(self): def send(self):
self.stream.sendRaw(self.__str__()) self.stream.sendRaw(self.__str__())
def __copy__(self): def __copy__(self):
return self.__class__(xml=copy.deepcopy(self.xml), stream=self.stream) return self.__class__(xml=copy.deepcopy(self.xml), stream=self.stream)
def __str__(self): def __str__(self):
return tostring(self.xml, xmlns='', stanza_ns=self.namespace, stream=self.stream) return tostring(self.xml, xmlns='',
stanza_ns=self.namespace,
stream=self.stream)