def accept(self, _openfileobj): self.state = self.states.CONNECTING for stream_type in self.si_handler.supported_streams: if stream_type in self.si_ft.feature.possible_streams: selected = stream_type break else: assert False self._fileobj = _openfileobj self.filepath = path(_openfileobj.name) si_ft = SI_FileTransfer(self.si_ft.sid) si_ft.feature = Feature(selected_stream=selected) si_ft.file = File() self.bytestream = b = self.si_handler.supported_streams[selected]( self.stanza) #bind events here b.bind("stream_connected", self.transferring) b.bind("stream_closed", self.stream_closed) b.bind("stream_connect_failed", self.stream_connect_failed) b.bind("stream_data_recieved", self.incoming_data) b.bind("stream_error", self.stream_error) #wrap result in feature ns elem self.si_handler.send_accept(self.stanza, si_ft)
def accept(self, _openfileobj): self.state = self.states.CONNECTING for stream_type in self.si_handler.supported_streams: if stream_type in self.si_ft.feature.possible_streams: selected = stream_type break else: assert False self._fileobj = _openfileobj self.filepath = path(_openfileobj.name) si_ft = SI_FileTransfer(self.si_ft.sid) si_ft.feature = Feature(selected_stream = selected) si_ft.file = File() self.bytestream = b = self.si_handler.supported_streams[selected](self.stanza) #bind events here b.bind("stream_connected", self.transferring) b.bind("stream_closed", self.stream_closed) b.bind("stream_connect_failed", self.stream_connect_failed) b.bind("stream_data_recieved", self.incoming_data) b.bind("stream_error", self.stream_error) #wrap result in feature ns elem self.si_handler.send_accept(self.stanza, si_ft)
def send_offer(self): self.state = self.states.WAITING_FOR_BUDDY i = Iq(to_jid=self.jid, stanza_type='set') #CAS: id generator for streams si = SI_FileTransfer(self.sid) si.file = File(self.filestor.name, self.filestor.size) si.feature = Feature(possible_streams=supported_streams) si.as_xml(i.get_node()) self.j.send_cb(i, success = self.handle_response, error = self.handle_error, timeout = self.timed_out)
def waitfor(self, stanza): ''' add a new stream to those we're looking for. ''' si_ft = SI_FileTransfer(stanza.xpath_eval('si:si',{'si':SI_NS})[0]) print 'waiting for stream for ', si_ft s5b = SOCKS5Bytestream(si_ft, self.j) self.d.set_item(si_ft.sid,s5b,timeout_callback=s5b.timed_out) return s5b
def handle_response(self, stanza): self.state = self.states.CONNECTING si = SI_FileTransfer.from_iq(stanza) self.stream = b = stream_connectors[si.feature.selected_stream](self) b.bind_event("stream_connected", self.transferring) b.bind_event("stream_connect_failed", self.stream_connect_failed) b.bind_event("stream_error", self.stream_error) b.bind_event("stream_closed", self.stream_closed) b.connect_stream()
def __init__(self, si_handler, iq): self.si_handler = si_handler self.stanza = iq self.si_ft = SI_FileTransfer.from_iq(iq) self.bytestream = None self._lock = threading.RLock() if self.check_streams(): #CAS: fix this with fail cases, i.e. check to see if this is a valid offer ft = self.si_ft self.numfiles = 1 self.name = ft.file.name self.size = ft.file.size self.buddy = self.si_handler.j.buddies[iq.get_from()] file_desc = unicode(ft.file.desc) IncomingFileTransfer.__init__(self) si_handler.j.hub.on_file_request(si_handler.j, self) self.on_get_buddy(self.buddy)
def send_offer(self): self.state = self.states.WAITING_FOR_BUDDY i = Iq(to_jid=self.jid, stanza_type='set') #CAS: id generator for streams si = SI_FileTransfer(self.sid) si.file = File(self.filestor.name, self.filestor.size) si.feature = Feature(possible_streams=supported_streams) si.as_xml(i.get_node()) self.j.send_cb(i, success=self.handle_response, error=self.handle_error, timeout=self.timed_out)