home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / digsby / accounts / account.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  4.5 KB  |  128 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from pyxmpp.utils import from_utf8
  5. from pyxmpp.iq import Iq
  6. from pyxmpp.objects import StanzaPayloadObject
  7. from pyxmpp.utils import to_utf8
  8. from pyxmpp.xmlextra import common_doc
  9. from pyxmpp.xmlextra import get_node_ns_uri
  10. import base64
  11. import cPickle
  12. import pickletools
  13. import binascii
  14. import digsby.accounts as digsby
  15. import digsbyprofile
  16. import common
  17. from digsby.accounts import DIGSBY_ACCOUNTS_NS
  18. import libxml2
  19.  
  20. def fix_truncated(short):
  21.     fix_shortname = fix_shortname
  22.     import common.protocolmeta
  23.     return fix_shortname.get(short, short)
  24.  
  25.  
  26. class Account(StanzaPayloadObject, common.HashedAccount):
  27.     xml_element_name = 'account'
  28.     xml_element_namespace = DIGSBY_ACCOUNTS_NS
  29.     
  30.     def __init__(self, xmlnode_or_acct_or_id = None, protocol = None, username = None, password = None, data = None, action = None):
  31.         if isinstance(xmlnode_or_acct_or_id, libxml2.xmlNode):
  32.             self._Account__from_xml(xmlnode_or_acct_or_id)
  33.         elif isinstance(xmlnode_or_acct_or_id, common.AccountBase):
  34.             acct = xmlnode_or_acct_or_id
  35.             self.id = acct.id
  36.             self.protocol = acct.protocol_info().get('name_truncated', acct.protocol)
  37.             self.username = acct.name
  38.             self.password = acct.password
  39.             
  40.             try:
  41.                 self.data = cPickle.dumps(acct.get_options())
  42.             except:
  43.                 print 'acct.get_options()', repr(acct.get_options())
  44.                 raise 
  45.  
  46.             if hasattr(pickletools, 'optimize'):
  47.                 self.data = pickletools.optimize(self.data)
  48.             
  49.             self.action = action
  50.         else:
  51.             self.id = xmlnode_or_acct_or_id
  52.             self.protocol = protocol
  53.             self.username = username
  54.             self.password = password
  55.             self.data = data
  56.             self.action = action
  57.         if not isinstance(self.id, int) or not (self.id >= 0):
  58.             raise ValueError('positive int id is required! (got %r)' % self.id)
  59.         not (self.id >= 0)
  60.  
  61.     
  62.     def __repr__(self):
  63.         return '<Digsby.Account %s (%s)>' % (self.protocol, self.username)
  64.  
  65.     
  66.     def __from_xml(self, node):
  67.         if node.type != 'element':
  68.             raise ValueError, 'XML node is not an account element (not en element)'
  69.         node.type != 'element'
  70.         ns = get_node_ns_uri(node)
  71.         if ns or ns != DIGSBY_ACCOUNTS_NS or node.name != 'account':
  72.             raise ValueError, 'XML node is not an account element'
  73.         node.name != 'account'
  74.         id = node.prop('id')
  75.         self.id = None if id else None
  76.         username = node.prop('username')
  77.         self.username = None if username else None
  78.         protocol = node.prop('protocol')
  79.         self.protocol = None if protocol else None
  80.         self.protocol = fix_truncated(self.protocol)
  81.         password = node.prop('password')
  82.         self.password = None if password else None
  83.         action = node.prop('action')
  84.         self.action = None if action else None
  85.         self.data = None
  86.         n = node.children
  87.         while n:
  88.             if n.type != 'element':
  89.                 n = n.next
  90.                 continue
  91.             
  92.             ns = get_node_ns_uri(n)
  93.             if ns and ns != DIGSBY_ACCOUNTS_NS:
  94.                 n = n.next
  95.                 continue
  96.             
  97.             if n.name == 'data':
  98.                 self.data = base64.decodestring(n.getContent())
  99.             
  100.             n = n.next
  101.  
  102.     
  103.     def complete_xml_element(self, xmlnode, _unused):
  104.         if isinstance(self.id, int) and self.id >= 0:
  105.             xmlnode.setProp('id', to_utf8(str(self.id)))
  106.         else:
  107.             raise ValueError, 'self.id must be int'
  108.         None if (self.id >= 0).protocol else None
  109.         None if self.username else None
  110.         None if self.password else None
  111.         None if self.action else None
  112.         None if self.data is not None else None
  113.  
  114.     
  115.     def make_push(self, digsby_protocol):
  116.         return digsby.accounts.Accounts([
  117.             self]).make_push(digsby_protocol)
  118.  
  119.     
  120.     def __str__(self):
  121.         n = self.as_xml(doc = common_doc)
  122.         r = n.serialize()
  123.         n.unlinkNode()
  124.         n.freeNode()
  125.         return r
  126.  
  127.  
  128.