Changeset 1610:618b30604061


Ignore:
Timestamp:
Nov 22, 2015, 6:04:14 PM (5 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Remove function `adapted_session`; apply `SessionAdapter` directly

Don't keep the helper function `adapted_session` for applying it just
once. Instead, when adapting an FTP session for Python 2 in
`ftputil.host._make_session`, wrap it in a `SessionAdapter` object
directly.

This is like the wrapping in `ftputil.file.FTPFile._open` where we
have the Python version check directly in the method.
Location:
ftputil
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1603 r1610  
    113113    #
    114114    # Dealing with child sessions and file-like objects
    115     #  (rather low-level)
     115    # (rather low-level)
    116116    #
    117117    def _make_session(self):
     
    133133        # code points <= 255). See the docstring in module
    134134        # `session_adapter` for details.
    135         return ftputil.session_adapter.adapted_session(session)
     135        if ftputil.compat.python_version == 2:
     136            session = ftputil.session_adapter.SessionAdapter(session)
     137        return session
    136138
    137139    def _copy(self):
  • ftputil/session_adapter.py

    r1604 r1610  
    111111    def __getattr__(self, name):
    112112        return getattr(self._session, name)
    113 
    114 
    115 def adapted_session(session):
    116     """
    117     Return an adapted session that will work with Python 2's
    118     `ftplib.FTP` and compatible sessions.
    119 
    120     Under Python 3 return the passed session itself.
    121     """
    122     if ftputil.compat.python_version == 2:
    123         return SessionAdapter(session)
    124     else:
    125         return session
Note: See TracChangeset for help on using the changeset viewer.