Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
urllib.request.ftpwrapper Class Reference

List of all members.

Public Member Functions

def __init__
def init
def retrfile
def endtransfer
def close
def file_close
def real_close

Public Attributes

 user
 passwd
 host
 port
 dirs
 timeout
 refcount
 keepalive
 busy
 ftp

Detailed Description

Class used by open_ftp() for cache of open FTP connections.

Definition at line 2142 of file request.py.


Constructor & Destructor Documentation

def urllib.request.ftpwrapper.__init__ (   self,
  user,
  passwd,
  host,
  port,
  dirs,
  timeout = None,
  persistent = True 
)

Definition at line 2146 of file request.py.

02146 
02147                  persistent=True):
02148         self.user = user
02149         self.passwd = passwd
02150         self.host = host
02151         self.port = port
02152         self.dirs = dirs
02153         self.timeout = timeout
02154         self.refcount = 0
02155         self.keepalive = persistent
02156         self.init()

Here is the caller graph for this function:


Member Function Documentation

Definition at line 2220 of file request.py.

02220 
02221     def close(self):
02222         self.keepalive = False
02223         if self.refcount <= 0:
02224             self.real_close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2211 of file request.py.

02211 
02212     def endtransfer(self):
02213         if not self.busy:
02214             return
02215         self.busy = 0
02216         try:
02217             self.ftp.voidresp()
02218         except ftperrors():
02219             pass

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2225 of file request.py.

02225 
02226     def file_close(self):
02227         self.endtransfer()
02228         self.refcount -= 1
02229         if self.refcount <= 0 and not self.keepalive:
02230             self.real_close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2157 of file request.py.

02157 
02158     def init(self):
02159         import ftplib
02160         self.busy = 0
02161         self.ftp = ftplib.FTP()
02162         self.ftp.connect(self.host, self.port, self.timeout)
02163         self.ftp.login(self.user, self.passwd)
02164         for dir in self.dirs:
02165             self.ftp.cwd(dir)

Here is the caller graph for this function:

Definition at line 2231 of file request.py.

02231 
02232     def real_close(self):
02233         self.endtransfer()
02234         try:
02235             self.ftp.close()
02236         except ftperrors():
02237             pass
02238 
# Proxy handling

Here is the call graph for this function:

Here is the caller graph for this function:

def urllib.request.ftpwrapper.retrfile (   self,
  file,
  type 
)

Definition at line 2166 of file request.py.

02166 
02167     def retrfile(self, file, type):
02168         import ftplib
02169         self.endtransfer()
02170         if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1
02171         else: cmd = 'TYPE ' + type; isdir = 0
02172         try:
02173             self.ftp.voidcmd(cmd)
02174         except ftplib.all_errors:
02175             self.init()
02176             self.ftp.voidcmd(cmd)
02177         conn = None
02178         if file and not isdir:
02179             # Try to retrieve as a file
02180             try:
02181                 cmd = 'RETR ' + file
02182                 conn, retrlen = self.ftp.ntransfercmd(cmd)
02183             except ftplib.error_perm as reason:
02184                 if str(reason)[:3] != '550':
02185                     raise URLError('ftp error', reason).with_traceback(
02186                         sys.exc_info()[2])
02187         if not conn:
02188             # Set transfer mode to ASCII!
02189             self.ftp.voidcmd('TYPE A')
02190             # Try a directory listing. Verify that directory exists.
02191             if file:
02192                 pwd = self.ftp.pwd()
02193                 try:
02194                     try:
02195                         self.ftp.cwd(file)
02196                     except ftplib.error_perm as reason:
02197                         raise URLError('ftp error', reason) from reason
02198                 finally:
02199                     self.ftp.cwd(pwd)
02200                 cmd = 'LIST ' + file
02201             else:
02202                 cmd = 'LIST'
02203             conn, retrlen = self.ftp.ntransfercmd(cmd)
02204         self.busy = 1
02205 
02206         ftpobj = addclosehook(conn.makefile('rb'), self.file_close)
02207         self.refcount += 1
02208         conn.close()
02209         # Pass back both a suitably decorated object and a retrieval length
02210         return (ftpobj, retrlen)

Here is the call graph for this function:


Member Data Documentation

Definition at line 2159 of file request.py.

Definition at line 2151 of file request.py.

Definition at line 2160 of file request.py.

Definition at line 2149 of file request.py.

Definition at line 2154 of file request.py.

Definition at line 2148 of file request.py.

Definition at line 2150 of file request.py.

Definition at line 2153 of file request.py.

Definition at line 2152 of file request.py.

Definition at line 2147 of file request.py.


The documentation for this class was generated from the following file: