home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- from struct import unpack
- from jabber.filetransfer.S5BFileXferHandler import SocketEventMixin
- import util
- import util.primitives.structures as structures
- from struct import pack
- from jabber.filetransfer.socketserver import ProxyFailure
- import common
- from functools import partial
- from logging import getLogger
- log = getLogger('S5B_proxyConnect')
-
- class S5B_proxyConnect(common.socket, SocketEventMixin):
-
- def __init__(self, addr, hash, streamhost):
- SocketEventMixin.__init__(self)
- self.handle_expt = self.post_connect_expt
- self.handle_error = self.post_connect_error
- self.handle_close = self.post_connect_close
- self.do_disconnect = self.post_connect_disconnect
- self.addr = addr
- self.hash = hash
- self.streamhost = streamhost
- self.data = None
- common.socket.__init__(self)
-
-
- def get_connect(self):
- self.connect(self.addr)
-
-
- def handle_connect(self):
- log.info('connect to %s', self.addr)
- self.proc(self.s5b_ok())
-
-
- def collect_incoming_data(self, data):
- pass
-
-
- def s5b_ok(self):
- yield (2, pack('BBB', 5, 1, 0))
- ok = None
- (_head, authmethod) = unpack('BB', ok)
- if authmethod != 0:
- raise ProxyFailure()
- authmethod != 0
- out = pack('!BBBBB40sH', 5, 1, 0, 3, 40, self.hash, 0)
- in_fmt = ('!BBBB', 's5head', 'status', 'reserved', 'addrtype')
- yield (4, out)
- in_ = None
- head = structures.unpack_named(*in_fmt + (in_,))
- if head.addrtype == 3:
- yield (1, '')
- head.addrlen = None
- head.addrlen = ord(head.addrlen)
- if head.addrlen > 0:
- yield (head.addrlen, '')
- address = None
- else:
- address = ''
-
- yield (2, '')
- _port = None
- if head.status != 0:
- raise ProxyFailure()
- head.status != 0
- log.info('proxy ok, calling on_success')
- self.event('connected')
-
-
- def proc(self, gen):
-
- try:
- (to_read, out_bytes) = gen.send(self.data)
- except ProxyFailure:
- self.close()
- self.event('connection_failed')
- return None
- except StopIteration:
- return None
-
-
- bytes = str(out_bytes)
- if out_bytes:
- self.push(bytes)
-
- self.data = ''
- self.found_terminator = partial(self.proc, gen)
- if isinstance(to_read, int):
- self.set_terminator(to_read)
- else:
- self.set_terminator(to_read._size())
-
-
-