Ignore:
Timestamp:
Aug 4, 2013, 1:42:38 PM (6 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Improved comments.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/file.py

    r1335 r1336  
    128128        instead this file object is modified in-place.
    129129        """
    130         # Python 3.x's `socket.makefile` supports the same interface
    131         # as the new `open` builtin, but Python 2.x supports a mode,
    132         # but neither buffering nor encoding/decoding. Therefore, to
    133         # make the code work on Python 2.x _and_ 3.x, create an
    134         # unbuffered binary file and possibly wrap it.
     130        # Python 3's `socket.makefile` supports the same interface as
     131        # the new `open` builtin, but Python 2 supports only a mode,
     132        # but doesn't return an object with the proper interface to
     133        # wrap it in `io.TextIOWrapper`.
     134        #
     135        # Therefore, to make the code work on Python 2 _and_ 3, use
     136        # `socket.makefile` to always create a binary file and under
     137        # Python 2 wrap it in an adapter class.
    135138        #
    136139        # Check mode.
     
    161164        with ftputil.error.ftplib_error_to_ftp_io_error:
    162165            self._conn = self._session.transfercmd(command)
    163         # The actual file object. Under Python 3, this will already
    164         # be wrapped by a `BufferedReader` or `BufferedWriter`.
     166        # The file object. Under Python 3, this will already be a
     167        # `BufferedReader` or `BufferedWriter` object.
    165168        fobj = self._conn.makefile(makefile_mode)
    166169        if ftputil.compat.python_version == 2:
     
    174177        self._fobj = fobj
    175178        # This comes last so that `close` won't try to close `_FTPFile`
    176         # objects without `_conn` and `_fo` attributes in case of an error.
     179        # objects without `_conn` and `_fobj` attributes in case of an
     180        # error.
    177181        self.closed = False
    178182
Note: See TracChangeset for help on using the changeset viewer.