def initialize(self, stream, session): super(OutgoingFileTransferHandler, self).initialize(stream, session) if stream.file_selector.fd is None: NotificationCenter().post_notification( 'FileTransferHandlerDidNotInitialize', sender=self, data=NotificationData(reason='file descriptor not specified')) return if stream.file_selector.size == 0: NotificationCenter().post_notification( 'FileTransferHandlerDidNotInitialize', sender=self, data=NotificationData(reason='file is empty')) return self.headers[ContentTypeHeader.name] = ContentTypeHeader( stream.file_selector.type) self.headers[SuccessReportHeader.name] = SuccessReportHeader('yes') self.headers[FailureReportHeader.name] = FailureReportHeader('yes') if stream.file_selector.hash is None: self._calculate_file_hash() else: NotificationCenter().post_notification( 'FileTransferHandlerDidInitialize', sender=self)
def make_hello(self, msrptransport, success_report=None, failure_report=None): chunk = msrptransport.make_send_request(data='hello') chunk.add_header(ContentTypeHeader('text/plain')) # because MSRPTransport does not send the responses, the relay must not either if success_report is not None: chunk.add_header(SuccessReportHeader(success_report)) if failure_report is not None: chunk.add_header(FailureReportHeader(failure_report)) return chunk
def __init__(self, filename, msrp_session, msrp): self.notification_center = NotificationCenter() self.msrp = msrp self.msrp_session = msrp_session self.offset = 0 self.fileSize = 0 self.filename = filename self.headers = {} self.headers[ContentTypeHeader.name] = ContentTypeHeader('application/x-webodf-genesisdocument') self.headers[SuccessReportHeader.name] = SuccessReportHeader('yes') self.headers[FailureReportHeader.name] = FailureReportHeader('yes') self.finished_event = Event() self.stop_event = Event()
def _msrp_writer(self): while True: try: data = self.outgoing_queue.wait() chunk = self.msrp.make_send_request(data=data) chunk.add_header(SuccessReportHeader('no')) chunk.add_header(FailureReportHeader('partial')) chunk.add_header(ContentTypeHeader('application/x-rfb')) self.msrp.write_chunk(chunk) except Exception as e: self.msrp_writer_thread = None # avoid issues caused by the notification handler killing this greenlet during post_notification if self.shutting_down and isinstance(e, ConnectionDone): break self._failure_reason = str(e) NotificationCenter().post_notification('MediaStreamDidFail', sender=self, data=NotificationData(context='sending', reason=self._failure_reason)) break
def _send_chunk(self, data): if self.stop_event.is_set(): return data_len = len(data) chunk = self.stream.msrp.make_send_request(message_id=self.message_id, data=data, start=self.offset+1, end=self.offset+data_len, length=self.stream.file_selector.size) chunk.add_header(ContentTypeHeader(self.stream.file_selector.type)) chunk.add_header(SuccessReportHeader('yes')) chunk.add_header(FailureReportHeader('yes')) try: self.stream.msrp_session.send_chunk(chunk, response_cb=self._on_transaction_response) except Exception as e: NotificationCenter().post_notification('FileTransferHandlerError', sender=self, data=NotificationData(error=str(e))) else: self.offset += data_len