Ticket #5411: 5411-6.diff

File 5411-6.diff, 2.9 KB (added by adiroiban, 3 years ago)
  • twisted/protocols/ftp.py

    diff --git a/twisted/protocols/ftp.py b/twisted/protocols/ftp.py
    index cbb1621..dd20357 100644
    a b class FTP(object, basic.LineReceiver, policies.TimeoutMixin): 
    928928        return self.dtpFactory.deferred.addCallbacks(connected, connFailed)
    929929
    930930
    931     def _checkListResult(self, name):
     931    def _checkWireFormat(self, value):
    932932        """
    933         Inspect an element from the list returned by an L{IFTPShell.list}
    934         implementation to make sure the content is formated to be
     933        Check C{value} to make sure the content is formatted to be
    935934        send on the wire.
    936935
    937         @param name: The name of a file, as returned by L{IFTPShell.list}.
    938         @type name: L{bytes} or L{unicode}
     936        @param value: Value to be checked.
     937        @type value: L{bytes} or L{unicode}
    939938
    940         @return: Either C{name} or the UTF-8 encoded form of it, if it is
    941             L{unicode}.
     939        @return: Wire format of C{value}.
    942940        @rtype: L{bytes}
    943941        """
    944         if isinstance(name, unicode):
    945             return name.encode('utf-8')
    946         return name
     942        if isinstance(value, unicode):
     943            return value.encode('utf-8')
     944        return value
    947945
    948946
    949947    def ftp_LIST(self, path=''):
    class FTP(object, basic.LineReceiver, policies.TimeoutMixin): 
    975973        def gotListing(results):
    976974            self.reply(DATA_CNX_ALREADY_OPEN_START_XFR)
    977975            for (name, attrs) in results:
    978                 name = self._checkListResult(name)
     976                name = self._checkWireFormat(name)
    979977                self.dtpInstance.sendListResponse(name, attrs)
    980978            self.dtpInstance.transport.loseConnection()
    981979            return (TXFR_COMPLETE_OK,)
    class FTP(object, basic.LineReceiver, policies.TimeoutMixin): 
    10391037            self.reply(DATA_CNX_ALREADY_OPEN_START_XFR)
    10401038            for (name, ignored) in results:
    10411039                if not glob or (glob and fnmatch.fnmatch(name, glob)):
    1042                     name = self._checkListResult(name)
     1040                    name = self._checkWireFormat(name)
    10431041                    self.dtpInstance.sendLine(name)
    10441042            self.dtpInstance.transport.loseConnection()
    10451043            return (TXFR_COMPLETE_OK,)
  • twisted/test/test_ftp.py

    diff --git a/twisted/test/test_ftp.py b/twisted/test/test_ftp.py
    index 1bea121..d3d55b3 100644
    a b class FTPServerPasvDataConnectionTestCase(FTPServerTestCase): 
    736736
    737737    def test_LISTNonASCIIBytes(self):
    738738        """
    739         Support for returning byte strings from L{IFTPShell.list} is deprecated
    740         and doing so results in a warning, but in the filename being sent as-is.
     739        When LIST receive a filename as byte string from L{IFTPShell.list}
     740        it will just pass the data to lower level without any change.
    741741        """
    742742        return self._listTestHelper(
    743743            "LIST",