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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from digsby.accounts.account import Account
  5. from pyxmpp.iq import Iq
  6. from pyxmpp.objects import StanzaPayloadObject
  7. from pyxmpp.xmlextra import common_doc, get_node_ns_uri
  8. from common.hashacct import HashedAccounts
  9. import base64
  10. import binascii
  11. from digsby.accounts import DIGSBY_ACCOUNTS_NS
  12. import libxml2
  13. from jabber.jabber_util import xpath_eval
  14.  
  15. class Accounts(StanzaPayloadObject, list, HashedAccounts):
  16.     xml_element_name = 'query'
  17.     xml_element_namespace = DIGSBY_ACCOUNTS_NS
  18.     
  19.     def __init__(self, xmlelem_or_accounts = [], order = sentinel):
  20.         if isinstance(xmlelem_or_accounts, libxml2.xmlNode):
  21.             self._Accounts__from_xml(xmlelem_or_accounts)
  22.         else:
  23.             self.order = order
  24.             self.extend(xmlelem_or_accounts)
  25.  
  26.     
  27.     def __from_xml(self, node):
  28.         if node.type != 'element':
  29.             raise ValueError, 'XML node is not an Accounts element (not en element)'
  30.         node.type != 'element'
  31.         ns = get_node_ns_uri(node)
  32.         if ns or ns != DIGSBY_ACCOUNTS_NS or node.name != 'query':
  33.             raise ValueError, 'XML node is not an Accounts element'
  34.         node.name != 'query'
  35.         accts = xpath_eval(node, 'a:account', {
  36.             'a': DIGSBY_ACCOUNTS_NS })
  37.         orders = xpath_eval(node, 'a:order', {
  38.             'a': DIGSBY_ACCOUNTS_NS })
  39.         self.order = [] if orders else []
  40.         self.extend((lambda .0: for acct in .0:
  41. Account(acct))(accts))
  42.  
  43.     
  44.     def complete_xml_element(self, xmlnode, doc):
  45.         if self.order is not sentinel:
  46.             xmlnode.newTextChild(None, 'order', binascii.b2a_base64(''.join((lambda .0: for c in .0:
  47. chr(c))(self.order))))
  48.         
  49.         [ item.as_xml(xmlnode, doc) for item in self ]
  50.  
  51.     
  52.     def make_push(self, digsby_protocol):
  53.         iq = Iq(stanza_type = 'set')
  54.         iq.set_to(digsby_protocol.jid.domain)
  55.         self.as_xml(parent = iq.get_node())
  56.         return iq
  57.  
  58.     
  59.     def make_get(self, digsby_protocol):
  60.         iq = Iq(stanza_type = 'get')
  61.         iq.set_to(digsby_protocol.jid.domain)
  62.         self.as_xml(parent = iq.get_node())
  63.         return iq
  64.  
  65.     
  66.     def __str__(self):
  67.         n = self.as_xml(doc = common_doc)
  68.         r = n.serialize()
  69.         n.unlinkNode()
  70.         n.freeNode()
  71.         return r
  72.  
  73.     
  74.     def from_local_store(local_info):
  75.         accts = Accounts(order = local_info['order'])
  76.         for a in local_info['accts']:
  77.             import cPickle
  78.             data = cPickle.dumps(a['data'])
  79.             accts.append(Account(a['id'], a['protocol'], a['username'], a['password'], data))
  80.         
  81.         return accts
  82.  
  83.     from_local_store = staticmethod(from_local_store)
  84.  
  85.