Back to index

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

List of all members.

Public Member Functions

def file_open
def get_names
def open_local_file
def add_parent
def close
def __lt__

Public Attributes

 parent

Static Public Attributes

 names = None
int handler_order = 500

Detailed Description

Definition at line 1252 of file request.py.


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

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.FileHandler.file_open (   self,
  req 
)

Definition at line 1254 of file request.py.

01254 
01255     def file_open(self, req):
01256         url = req.selector
01257         if url[:2] == '//' and url[2:3] != '/' and (req.host and
01258                 req.host != 'localhost'):
01259             if not req.host is self.get_names():
01260                 raise URLError("file:// scheme is supported only on localhost")
01261         else:
01262             return self.open_local_file(req)

Here is the call graph for this function:

Definition at line 1265 of file request.py.

01265 
01266     def get_names(self):
01267         if FileHandler.names is None:
01268             try:
01269                 FileHandler.names = tuple(
01270                     socket.gethostbyname_ex('localhost')[2] +
01271                     socket.gethostbyname_ex(socket.gethostname())[2])
01272             except socket.gaierror:
01273                 FileHandler.names = (socket.gethostbyname('localhost'),)
01274         return FileHandler.names

Here is the caller graph for this function:

def urllib.request.FileHandler.open_local_file (   self,
  req 
)

Definition at line 1276 of file request.py.

01276 
01277     def open_local_file(self, req):
01278         import email.utils
01279         import mimetypes
01280         host = req.host
01281         filename = req.selector
01282         localfile = url2pathname(filename)
01283         try:
01284             stats = os.stat(localfile)
01285             size = stats.st_size
01286             modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
01287             mtype = mimetypes.guess_type(filename)[0]
01288             headers = email.message_from_string(
01289                 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
01290                 (mtype or 'text/plain', size, modified))
01291             if host:
01292                 host, port = splitport(host)
01293             if not host or \
01294                 (not port and _safe_gethostbyname(host) in self.get_names()):
01295                 if host:
01296                     origurl = 'file://' + host + filename
01297                 else:
01298                     origurl = 'file://' + filename
01299                 return addinfourl(open(localfile, 'rb'), headers, origurl)
01300         except OSError as msg:
01301             # users shouldn't expect OSErrors coming from urlopen()
01302             raise URLError(msg)
01303         raise URLError('file not on local host')

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

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

Definition at line 1264 of file request.py.

Definition at line 461 of file request.py.


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