Ticket #5411: 5411-4.diff

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

    diff --git a/twisted/protocols/ftp.py b/twisted/protocols/ftp.py
    index 7411cdd..9f034c0 100644
    a b class DTP(object, protocol.Protocol): 
    424424        @param line: The line to be sent.
    425425        @type line: L{bytes}
    426426        """
    427         if isinstance(line, unicode):
    428             warnings.warn(
    429                 "Passing unicode to DTP.sendLine is deprecated since "
    430                 "Twisted 13.0.  Pass only byte strings.",
    431                 category=DeprecationWarning, stacklevel=2)
    432             line = line.encode('utf-8')
    433 
    434427        self.transport.write(line + '\r\n')
    435428
    436429
    class FTP(object, basic.LineReceiver, policies.TimeoutMixin): 
    939932    def _checkListResult(self, name):
    940933        """
    941934        Inspect an element from the list returned by an L{IFTPShell.list}
    942         implementation to make sure it is of the correct type and issue a
    943         warning if not.
     935        implementation to make sure the content is formated to be
     936        send on the wire.
    944937
    945938        @param name: The name of a file, as returned by L{IFTPShell.list}.
    946939        @type name: L{bytes} or L{unicode}
    class FTP(object, basic.LineReceiver, policies.TimeoutMixin): 
    951944        """
    952945        if isinstance(name, unicode):
    953946            return name.encode('utf-8')
    954         warnAboutFunction(
    955             self.shell.list,
    956             "Support for returning byte strings from "
    957             "IFTPShell.list is deprecated since Twisted "
    958             "13.0.  Return unicode strings only.")
    959947        return name
    960948
    961949
  • twisted/test/test_ftp.py

    diff --git a/twisted/test/test_ftp.py b/twisted/test/test_ftp.py
    index ea4e5c7..6fb7064 100644
    a b class FTPServerPasvDataConnectionTestCase(FTPServerTestCase): 
    734734            '0 Jan 01  1970 my resum\xc3\xa9\r\n')
    735735
    736736
    737     def _deprecatedListTestHelper(self, command, expectedOutput):
    738         """
    739         Like L{_listTestHelper}, but with an additional assertion that a warning
    740         is emitted telling application developers to return C{unicode} from
    741         L{IFTPShell.list} implementations, not L{bytes}.
    742         """
    743         d = self._listTestHelper(
    744             command,
    745             ('my resum\xc3\xa9', (0, 1, 0777, 0, 0, 'user', 'group')),
    746             expectedOutput)
    747 
    748         def checkDeprecation(offendingFunction):
    749             warnings = self.flushWarnings([offendingFunction])
    750             self.assertEqual(warnings[0]['category'], DeprecationWarning)
    751             self.assertEqual(
    752                 warnings[0]['message'],
    753                 "Support for returning byte strings from IFTPShell.list "
    754                 "is deprecated since Twisted 13.0.  Return unicode strings "
    755                 "only.")
    756             self.assertEqual(1, len(warnings))
    757         return d.addCallback(checkDeprecation)
    758 
    759 
    760     def test_LISTNonASCIIBytes(self):
    761         """
    762         Support for returning byte strings from L{IFTPShell.list} is deprecated
    763         and doing so results in a warning, but in the filename being sent as-is.
    764         """
    765         return self._deprecatedListTestHelper(
    766             "LIST",
    767             'drwxrwxrwx   0 user      group                   '
    768             '0 Jan 01  1970 my resum\xc3\xa9\r\n')
    769 
    770 
    771737    def testManyLargeDownloads(self):
    772738        # Login
    773739        d = self._anonymousLogin()
    class FTPServerPasvDataConnectionTestCase(FTPServerTestCase): 
    863829            'my resum\xc3\xa9\r\n')
    864830
    865831
    866     def test_NLSTNonASCIIBytes(self):
    867         """
    868         Support for returning byte strings from L{IFTPShell.list} is deprecated
    869         and doing so results in a warning, but in the filename being sent as-is.
    870         """
    871         return self._deprecatedListTestHelper(
    872             "NLST",
    873             'my resum\xc3\xa9\r\n')
    874 
    875 
    876832    def test_NLSTOnPathToFile(self):
    877833        """
    878834        NLST on an existent file returns only the path to that file.
    class DTPTests(unittest.TestCase): 
    11391095        self.assertEqual(lineContent + '\r\n', dataSent)
    11401096
    11411097
    1142     def test_sendLineUnicode(self):
    1143         """
    1144         L{ftp.DTP.sendLine} notices unicode lines, encodes them to strings using
    1145         UTF-8, and emits a warning to not send unicode strings.
    1146         """
    1147         dtpInstance = self.factory.buildProtocol(None)
    1148         dtpInstance.makeConnection(self.transport)
    1149         lineContent = u'my resum\xe9'
    1150 
    1151         self.assertWarns(
    1152             DeprecationWarning,
    1153             "Passing unicode to DTP.sendLine is deprecated since "
    1154             "Twisted 13.0.  Pass only byte strings.",
    1155             __file__,
    1156             lambda: dtpInstance.sendLine(lineContent))
    1157 
    1158         dataSent = self.transport.value()
    1159         self.assertIsInstance(dataSent, bytes)
    1160         self.assertEqual(lineContent.encode('utf-8') + b'\r\n', dataSent)
    1161 
    1162 
    11631098
    11641099# -- Client Tests -----------------------------------------------------------
    11651100