home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / oscar / rendezvous / proxy.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  2.8 KB  |  66 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from util import Storage, to_hex
  5. from util.packable import Packable
  6. import struct
  7. import oscar.capabilities as capabilities
  8. from oscar.OscarUtil import tlv
  9. from logging import getLogger
  10. log = getLogger('rdv.proxy')
  11. info = log.info
  12.  
  13. class ProxyHeader(Packable):
  14.     version = 1098
  15.     fmt = ('length', 'H', 'version', 'H', 'command', 'H', 'null', 'I', 'flags', 'H')
  16.     invars = [
  17.         (lambda o: o.version == ProxyHeader.version)]
  18.     commands = Storage(error = 1, initsend = 2, ack = 3, initreceive = 4, ready = 5)
  19.     
  20.     def initsend(cls, screenname, cookie):
  21.         return make_proxy_init(screenname, cookie)
  22.  
  23.     initsend = classmethod(initsend)
  24.     
  25.     def initreceive(cls, screenname, cookie, port):
  26.         return make_proxy_init(screenname, cookie, port)
  27.  
  28.     initreceive = classmethod(initreceive)
  29.  
  30. SENDFILE = capabilities.by_name['file_xfer']
  31. _send_file_tlv = tlv(1, SENDFILE)
  32.  
  33. def make_proxy_init(sn, cookie, port = None):
  34.     if not isinstance(sn, str):
  35.         raise TypeError('screenname must be a str object')
  36.     
  37.     if isinstance(cookie, long):
  38.         cookie = struct.pack('!Q', cookie)
  39.     
  40.     command = None if port else 'initsend'
  41.     length = len(sn) + 41
  42.     if port is None:
  43.         length -= 2
  44.     
  45.     info(command + ' length: %d', length)
  46.     data = ProxyHeader(length, ProxyHeader.version, ProxyHeader.commands[command], null = 0, flags = 0).pack()
  47.     data += struct.pack('B', len(sn)) + sn
  48.     if port:
  49.         data += struct.pack('!H', port)
  50.     
  51.     fullpacket = data + cookie + _send_file_tlv
  52.     log.info_s('proxy packet assembled (%d bytes): %s', len(fullpacket), to_hex(fullpacket))
  53.     return fullpacket
  54.  
  55.  
  56. def unpack_proxy_ack(data):
  57.     (ack, data) = ProxyHeader.unpack(data)
  58.     (ack.port, ack.ip) = struct.unpack('!HI', data)
  59.     return ack
  60.  
  61.  
  62. def unpack_proxy_ready(data):
  63.     (ready, data) = ProxyHeader.unpack(data)
  64.     return ready
  65.  
  66.