Changeset 18:adb98b60e012


Ignore:
Timestamp:
Jan 20, 2002, 7:06:01 PM (17 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Convert:
svn:778c30c8-61e0-0310-89d4-fe2f97a467b2/trunk@19
Message:
FTPHost: Fixed some docstrings and comments.
FTPOSError: setting more variables (OSError-like) in the constructor;
            overwrote __str__ so that str(self) doesn't raise an
            AttributeError
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil.py

    r17 r18  
    3232import ftplib
    3333import os
     34import sys
    3435import posixpath
    3536
     
    5455class FTPOSError(OSError):
    5556    def __init__(self, ftp_exception):
    56         self.ftp_exception = ftp_exception
    57         OSError( self, str(ftp_exception) )
     57        self.args = (ftp_exception,)
     58        self.strerror = str(ftp_exception)
     59        self.errno = int(self.strerror[:3])
     60        self.filename = None
     61       
     62    def __str__(self):
     63        return str(self.ftp_exception)
    5864
    5965
     
    207213    def __init__(self, *args, **kwargs):
    208214        '''Abstract initialization of FTPHost object.'''
    209         print 'New FTPHost'
    210215        self._session = ftplib.FTP(*args, **kwargs)
    211216        # simulate os.path
     
    222227        # The copy includes a new ftplib.FTP instance
    223228        #  (aka session) but doesn't copy the state of
    224         #  self.getcwd()
     229        #  self.getcwd().
    225230        return FTPHost(*self._args, **self._kwargs)
    226231       
    227232    def _available_child(self):
    228         '''Return a closed file object from the pool or
    229         None if there aren't any.'''
     233        '''Return an available (i. e. one whose _file object
     234        is closed) child (FTPHost object) from the pool of
     235        children or None if there aren't any.'''
    230236        for host in self._children:
    231237            if host._file.closed:
     
    235241    def file(self, path, mode='r'):
    236242        '''Return an open file(-like) object which is
    237         associated with this FTPHost object.'''
     243        associated with this FTPHost object.
     244        This method tries to reuse a child but will generate
     245        a new if none is available.'''
    238246        host = self._available_child()
    239247        if host is None:
     
    249257        '''Close host connection.'''
    250258        if not self.closed:
    251             # close associated clones
     259            # close associated children
    252260            for host in self._children:
    253261                # only children have _file attributes
     
    270278            return callee(*args)
    271279        except ftplib.all_errors:
    272             raise FTPOSError( sys.exc_info()[1] )
     280            ftp_error = sys.exc_info()[1]
     281            raise FTPOSError(ftp_error)
    273282       
    274283    def getcwd(self):
Note: See TracChangeset for help on using the changeset viewer.