Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
urllib.request.CacheFTPHandler Class Reference
Inheritance diagram for urllib.request.CacheFTPHandler:
Inheritance graph
[legend]
Collaboration diagram for urllib.request.CacheFTPHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def setTimeout
def setMaxConns
def connect_ftp
def check_cache
def clear_cache
def ftp_open
def add_parent
def close
def __lt__

Public Attributes

 cache
 timeout
 soonest
 delay
 max_conns
 parent

Static Public Attributes

int handler_order = 500

Detailed Description

Definition at line 1368 of file request.py.


Constructor & Destructor Documentation

Definition at line 1371 of file request.py.

01371 
01372     def __init__(self):
01373         self.cache = {}
01374         self.timeout = {}
01375         self.soonest = 0
01376         self.delay = 60
01377         self.max_conns = 16

Here is the caller graph for this function:


Member Function Documentation

def urllib.request.BaseHandler.__lt__ (   self,
  other 
) [inherited]

Definition at line 467 of file request.py.

00467 
00468     def __lt__(self, other):
00469         if not hasattr(other, "handler_order"):
00470             # Try to preserve the old behavior of having custom classes
00471             # inserted after default ones (works only for custom user
00472             # classes which are not aware of handler_order).
00473             return True
00474         return self.handler_order < other.handler_order
00475 

def urllib.request.BaseHandler.add_parent (   self,
  parent 
) [inherited]

Definition at line 460 of file request.py.

00460 
00461     def add_parent(self, parent):
00462         self.parent = parent

Definition at line 1395 of file request.py.

01395 
01396     def check_cache(self):
01397         # first check for old ones
01398         t = time.time()
01399         if self.soonest <= t:
01400             for k, v in list(self.timeout.items()):
01401                 if v < t:
01402                     self.cache[k].close()
01403                     del self.cache[k]
01404                     del self.timeout[k]
01405         self.soonest = min(list(self.timeout.values()))
01406 
01407         # then check the size
01408         if len(self.cache) == self.max_conns:
01409             for k, v in list(self.timeout.items()):
01410                 if v == self.soonest:
01411                     del self.cache[k]
01412                     del self.timeout[k]
01413                     break
01414             self.soonest = min(list(self.timeout.values()))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1415 of file request.py.

01415 
01416     def clear_cache(self):
01417         for conn in self.cache.values():
01418             conn.close()
01419         self.cache.clear()
01420         self.timeout.clear()
01421 
01422 
01423 # Code move from the old urllib module

def urllib.request.BaseHandler.close (   self) [inherited]

Definition at line 463 of file request.py.

00463 
00464     def close(self):
00465         # Only exists for backwards compatibility
00466         pass

Here is the caller graph for this function:

def urllib.request.CacheFTPHandler.connect_ftp (   self,
  user,
  passwd,
  host,
  port,
  dirs,
  timeout 
)

Reimplemented from urllib.request.FTPHandler.

Definition at line 1384 of file request.py.

01384 
01385     def connect_ftp(self, user, passwd, host, port, dirs, timeout):
01386         key = user, host, port, '/'.join(dirs), timeout
01387         if key in self.cache:
01388             self.timeout[key] = time.time() + self.delay
01389         else:
01390             self.cache[key] = ftpwrapper(user, passwd, host, port,
01391                                          dirs, timeout)
01392             self.timeout[key] = time.time() + self.delay
01393         self.check_cache()
01394         return self.cache[key]

Here is the call graph for this function:

def urllib.request.FTPHandler.ftp_open (   self,
  req 
) [inherited]

Definition at line 1311 of file request.py.

01311 
01312     def ftp_open(self, req):
01313         import ftplib
01314         import mimetypes
01315         host = req.host
01316         if not host:
01317             raise URLError('ftp error: no host given')
01318         host, port = splitport(host)
01319         if port is None:
01320             port = ftplib.FTP_PORT
01321         else:
01322             port = int(port)
01323 
01324         # username/password handling
01325         user, host = splituser(host)
01326         if user:
01327             user, passwd = splitpasswd(user)
01328         else:
01329             passwd = None
01330         host = unquote(host)
01331         user = user or ''
01332         passwd = passwd or ''
01333 
01334         try:
01335             host = socket.gethostbyname(host)
01336         except socket.error as msg:
01337             raise URLError(msg)
01338         path, attrs = splitattr(req.selector)
01339         dirs = path.split('/')
01340         dirs = list(map(unquote, dirs))
01341         dirs, file = dirs[:-1], dirs[-1]
01342         if dirs and not dirs[0]:
01343             dirs = dirs[1:]
01344         try:
01345             fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout)
01346             type = file and 'I' or 'D'
01347             for attr in attrs:
01348                 attr, value = splitvalue(attr)
01349                 if attr.lower() == 'type' and \
01350                    value in ('a', 'A', 'i', 'I', 'd', 'D'):
01351                     type = value.upper()
01352             fp, retrlen = fw.retrfile(file, type)
01353             headers = ""
01354             mtype = mimetypes.guess_type(req.full_url)[0]
01355             if mtype:
01356                 headers += "Content-type: %s\n" % mtype
01357             if retrlen is not None and retrlen >= 0:
01358                 headers += "Content-length: %d\n" % retrlen
01359             headers = email.message_from_string(headers)
01360             return addinfourl(fp, headers, req.full_url)
01361         except ftplib.all_errors as msg:
01362             exc = URLError('ftp error: %s' % msg)
01363             raise exc.with_traceback(sys.exc_info()[2])

Here is the call graph for this function:

Definition at line 1381 of file request.py.

01381 
01382     def setMaxConns(self, m):
01383         self.max_conns = m

Definition at line 1378 of file request.py.

01378 
01379     def setTimeout(self, t):
01380         self.delay = t


Member Data Documentation

Definition at line 1372 of file request.py.

Definition at line 1375 of file request.py.

int urllib.request.BaseHandler.handler_order = 500 [static, inherited]

Definition at line 1376 of file request.py.

Definition at line 461 of file request.py.

Definition at line 1374 of file request.py.

Definition at line 1373 of file request.py.


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