From 56766508b3550f6dbf9ea89516c6423842011494 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 26 Aug 2010 14:19:36 -0400 Subject: Fixed indentation in StanzaBase. --- sleekxmpp/xmlstream/stanzabase.py | 149 ++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 72 deletions(-) (limited to 'sleekxmpp/xmlstream/stanzabase.py') diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index abe288db..854aceba 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -875,85 +875,90 @@ class ElementBase(object): class StanzaBase(ElementBase): - name = 'stanza' - namespace = 'jabber:client' - interfaces = set(('type', 'to', 'from', 'id', 'payload')) - types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat')) - sub_interfaces = tuple() - - def __init__(self, stream=None, xml=None, stype=None, sto=None, sfrom=None, sid=None): - self.stream = stream - if stream is not None: - self.namespace = stream.default_ns - ElementBase.__init__(self, xml) - if stype is not None: - self['type'] = stype - if sto is not None: - self['to'] = sto - if sfrom is not None: - self['from'] = sfrom - self.tag = "{%s}%s" % (self.namespace, self.name) - - def setType(self, value): - if value in self.types: - self.xml.attrib['type'] = value - return self - - def getPayload(self): - return self.xml.getchildren() - - def setPayload(self, value): - self.xml.append(value) - return self - - def delPayload(self): - self.clear() - return self - - def clear(self): - for child in self.xml.getchildren(): - self.xml.remove(child) - for plugin in list(self.plugins.keys()): - del self.plugins[plugin] - return self - - def reply(self): - # if it's a component, use from - if self.stream and hasattr(self.stream, "is_component") and self.stream.is_component: - self['from'], self['to'] = self['to'], self['from'] - else: - self['to'] = self['from'] - del self['from'] - self.clear() - return self + name = 'stanza' + namespace = 'jabber:client' + interfaces = set(('type', 'to', 'from', 'id', 'payload')) + types = set(('get', 'set', 'error', None, 'unavailable', 'normal', 'chat')) + sub_interfaces = tuple() + + def __init__(self, stream=None, xml=None, stype=None, + sto=None, sfrom=None, sid=None): + self.stream = stream + if stream is not None: + self.namespace = stream.default_ns + ElementBase.__init__(self, xml) + if stype is not None: + self['type'] = stype + if sto is not None: + self['to'] = sto + if sfrom is not None: + self['from'] = sfrom + self.tag = "{%s}%s" % (self.namespace, self.name) + + def setType(self, value): + if value in self.types: + self.xml.attrib['type'] = value + return self + + def getPayload(self): + return self.xml.getchildren() + + def setPayload(self, value): + self.xml.append(value) + return self - def error(self): - self['type'] = 'error' - return self + def delPayload(self): + self.clear() + return self - def getTo(self): - return JID(self._getAttr('to')) + def clear(self): + for child in self.xml.getchildren(): + self.xml.remove(child) + for plugin in list(self.plugins.keys()): + del self.plugins[plugin] + return self - def setTo(self, value): - return self._setAttr('to', str(value)) + def reply(self): + # if it's a component, use from + if self.stream and hasattr(self.stream, "is_component") and \ + self.stream.is_component: + self['from'], self['to'] = self['to'], self['from'] + else: + self['to'] = self['from'] + del self['from'] + self.clear() + return self - def getFrom(self): - return JID(self._getAttr('from')) + def error(self): + self['type'] = 'error' + return self - def setFrom(self, value): - return self._setAttr('from', str(value)) + def getTo(self): + return JID(self._getAttr('to')) - def unhandled(self): - pass + def setTo(self, value): + return self._setAttr('to', str(value)) - def exception(self, e): - logging.exception('Error handling {%s}%s stanza' % (self.namespace, self.name)) + def getFrom(self): + return JID(self._getAttr('from')) - def send(self): - self.stream.sendRaw(self.__str__()) + def setFrom(self, value): + return self._setAttr('from', str(value)) - def __copy__(self): - return self.__class__(xml=copy.deepcopy(self.xml), stream=self.stream) + def unhandled(self): + pass - def __str__(self): - return tostring(self.xml, xmlns='', stanza_ns=self.namespace, stream=self.stream) + def exception(self, e): + logging.exception('Error handling {%s}%s stanza' % (self.namespace, + self.name)) + + def send(self): + self.stream.sendRaw(self.__str__()) + + def __copy__(self): + return self.__class__(xml=copy.deepcopy(self.xml), stream=self.stream) + + def __str__(self): + return tostring(self.xml, xmlns='', + stanza_ns=self.namespace, + stream=self.stream) -- cgit v1.2.3