示例#1
0
 def test_conversion(self):
     p = NetasciiReceiverProxy(self.sink)
     chunk = self.source.read(2)
     while chunk:
         yield p.write(chunk)
         chunk = self.source.read(2)
     self.sink.seek(0) # !!!
     self.assertEqual(self.sink.read(), self.test_data)
示例#2
0
 def test_conversion(self):
     p = NetasciiReceiverProxy(self.sink)
     chunk = self.source.read(2)
     while chunk:
         yield p.write(chunk)
         chunk = self.source.read(2)
     self.sink.seek(0)  # !!!
     self.assertEqual(self.sink.read(), self.test_data)
示例#3
0
 def _startSession(self, datagram, addr, mode):
     # Set up a call context so that we can pass extra arbitrary
     # information to interested backends without adding extra call
     # arguments, or switching to using a request object, for example.
     context = {}
     if self.transport is not None:
         # Add the local and remote addresses to the call context.
         local = self.transport.getHost()
         context["local"] = local.host, local.port
         context["remote"] = addr
     try:
         if datagram.opcode == OP_WRQ:
             fs_interface = yield call(context, self.backend.get_writer,
                                       datagram.filename)
         elif datagram.opcode == OP_RRQ:
             fs_interface = yield call(context, self.backend.get_reader,
                                       datagram.filename)
     except Unsupported as e:
         self.transport.write(
             ERRORDatagram.from_code(
                 ERR_ILLEGAL_OP,
                 u"{}".format(e).encode("ascii", "replace")).to_wire(),
             addr)
     except AccessViolation:
         self.transport.write(
             ERRORDatagram.from_code(ERR_ACCESS_VIOLATION).to_wire(), addr)
     except FileExists:
         self.transport.write(
             ERRORDatagram.from_code(ERR_FILE_EXISTS).to_wire(), addr)
     except FileNotFound:
         self.transport.write(
             ERRORDatagram.from_code(ERR_FILE_NOT_FOUND).to_wire(), addr)
     except BackendError as e:
         self.transport.write(
             ERRORDatagram.from_code(
                 ERR_NOT_DEFINED,
                 u"{}".format(e).encode("ascii", "replace")).to_wire(),
             addr)
     else:
         if datagram.opcode == OP_WRQ:
             if mode == b'netascii':
                 fs_interface = NetasciiReceiverProxy(fs_interface)
             session = RemoteOriginWriteSession(addr,
                                                fs_interface,
                                                datagram.options,
                                                _clock=self._clock)
             reactor.listenUDP(0, session)
             returnValue(session)
         elif datagram.opcode == OP_RRQ:
             if mode == b'netascii':
                 fs_interface = NetasciiSenderProxy(fs_interface)
             session = RemoteOriginReadSession(addr,
                                               fs_interface,
                                               datagram.options,
                                               _clock=self._clock)
             reactor.listenUDP(0, session)
             returnValue(session)
示例#4
0
     self.transport.write(
         ERRORDatagram.from_code(ERR_ACCESS_VIOLATION).to_wire(), addr)
 except FileExists:
     self.transport.write(
         ERRORDatagram.from_code(ERR_FILE_EXISTS).to_wire(), addr)
 except FileNotFound:
     self.transport.write(
         ERRORDatagram.from_code(ERR_FILE_NOT_FOUND).to_wire(), addr)
 except BackendError, e:
     self.transport.write(
         ERRORDatagram.from_code(ERR_NOT_DEFINED, str(e)).to_wire(),
         addr)
 else:
     if datagram.opcode == OP_WRQ:
         if mode == 'netascii':
             fs_interface = NetasciiReceiverProxy(fs_interface)
         session = RemoteOriginWriteSession(addr,
                                            fs_interface,
                                            datagram.options,
                                            _clock=self._clock)
         reactor.listenUDP(0, session)
         returnValue(session)
     elif datagram.opcode == OP_RRQ:
         if mode == 'netascii':
             fs_interface = NetasciiSenderProxy(fs_interface)
         session = RemoteOriginReadSession(addr,
                                           fs_interface,
                                           datagram.options,
                                           _clock=self._clock)
         reactor.listenUDP(0, session)
         returnValue(session)