home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / pyxmpp / message.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  3.0 KB  |  80 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: message.py 714 2010-04-05 10:20:10Z jajcus $'
  5. __docformat__ = 'restructuredtext en'
  6. import libxml2
  7. from pyxmpp.stanza import Stanza
  8. from pyxmpp.utils import to_utf8, from_utf8
  9. from pyxmpp.xmlextra import common_ns
  10. message_types = ('normal', 'chat', 'headline', 'error', 'groupchat')
  11.  
  12. class Message(Stanza):
  13.     stanza_type = 'message'
  14.     
  15.     def __init__(self, xmlnode = None, from_jid = None, to_jid = None, stanza_type = None, stanza_id = None, subject = None, body = None, thread = None, error = None, error_cond = None, stream = None):
  16.         self.xmlnode = None
  17.         if isinstance(xmlnode, Message):
  18.             pass
  19.         elif isinstance(xmlnode, Stanza):
  20.             raise TypeError, "Couldn't make Message from other Stanza"
  21.         elif isinstance(xmlnode, libxml2.xmlNode):
  22.             pass
  23.         elif xmlnode is not None:
  24.             raise TypeError, "Couldn't make Message from %r" % (type(xmlnode),)
  25.         
  26.         if xmlnode is None:
  27.             xmlnode = 'message'
  28.         
  29.         Stanza.__init__(self, xmlnode, from_jid = from_jid, to_jid = to_jid, stanza_type = stanza_type, stanza_id = stanza_id, error = error, error_cond = error_cond, stream = stream)
  30.         if subject is not None:
  31.             self.xmlnode.newTextChild(common_ns, 'subject', to_utf8(subject))
  32.         
  33.         if body is not None:
  34.             self.xmlnode.newTextChild(common_ns, 'body', to_utf8(body))
  35.         
  36.         if thread is not None:
  37.             self.xmlnode.newTextChild(common_ns, 'thread', to_utf8(thread))
  38.         
  39.  
  40.     
  41.     def get_subject(self):
  42.         n = self.xpath_eval('ns:subject')
  43.         if n:
  44.             return from_utf8(n[0].getContent())
  45.         return None
  46.  
  47.     
  48.     def get_thread(self):
  49.         n = self.xpath_eval('ns:thread')
  50.         if n:
  51.             return from_utf8(n[0].getContent())
  52.         return None
  53.  
  54.     
  55.     def copy(self):
  56.         return Message(self)
  57.  
  58.     
  59.     def get_body(self):
  60.         n = self.xpath_eval('ns:body')
  61.         if n:
  62.             return from_utf8(n[0].getContent())
  63.         return None
  64.  
  65.     
  66.     def make_error_response(self, cond):
  67.         if self.get_type() == 'error':
  68.             raise ValueError, 'Errors may not be generated in response to errors'
  69.         self.get_type() == 'error'
  70.         m = Message(stanza_type = 'error', from_jid = self.get_to(), to_jid = self.get_from(), stanza_id = self.get_id(), error_cond = cond)
  71.         if self.xmlnode.children:
  72.             n = self.xmlnode.children
  73.             while n:
  74.                 m.xmlnode.children.addPrevSibling(n.copyNode(1))
  75.                 n = n.next
  76.         
  77.         return m
  78.  
  79.  
  80.