Back to index

python3.2  3.2.2
Classes | Functions | Variables
wsgiref.handlers Namespace Reference

Classes

class  BaseHandler
class  SimpleHandler
class  BaseCGIHandler
class  CGIHandler
class  IISCGIHandler

Functions

def format_date_time
def _needs_transcode
def read_environ

Variables

list __all__
list _weekdayname = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
list _monthname
dictionary _is_request

Detailed Description

Base classes for server/gateway implementations

Function Documentation

def wsgiref.handlers._needs_transcode (   k) [private]

Definition at line 30 of file handlers.py.

00030 
00031 def _needs_transcode(k):
00032     return _is_request(k) or k.startswith('HTTP_') or k.startswith('SSL_') \
00033         or (k.startswith('REDIRECT_') and _needs_transcode(k[9:]))

Here is the caller graph for this function:

def wsgiref.handlers.format_date_time (   timestamp)

Definition at line 19 of file handlers.py.

00019 
00020 def format_date_time(timestamp):
00021     year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
00022     return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
00023         _weekdayname[wd], day, _monthname[month], year, hh, mm, ss
00024     )

Here is the caller graph for this function:

Read environment, fixing HTTP variables

Definition at line 34 of file handlers.py.

00034 
00035 def read_environ():
00036     """Read environment, fixing HTTP variables"""
00037     enc = sys.getfilesystemencoding()
00038     esc = 'surrogateescape'
00039     try:
00040         ''.encode('utf-8', esc)
00041     except LookupError:
00042         esc = 'replace'
00043     environ = {}
00044 
00045     # Take the basic environment from native-unicode os.environ. Attempt to
00046     # fix up the variables that come from the HTTP request to compensate for
00047     # the bytes->unicode decoding step that will already have taken place.
00048     for k, v in os.environ.items():
00049         if _needs_transcode(k):
00050 
00051             # On win32, the os.environ is natively Unicode. Different servers
00052             # decode the request bytes using different encodings.
00053             if sys.platform == 'win32':
00054                 software = os.environ.get('SERVER_SOFTWARE', '').lower()
00055 
00056                 # On IIS, the HTTP request will be decoded as UTF-8 as long
00057                 # as the input is a valid UTF-8 sequence. Otherwise it is
00058                 # decoded using the system code page (mbcs), with no way to
00059                 # detect this has happened. Because UTF-8 is the more likely
00060                 # encoding, and mbcs is inherently unreliable (an mbcs string
00061                 # that happens to be valid UTF-8 will not be decoded as mbcs)
00062                 # always recreate the original bytes as UTF-8.
00063                 if software.startswith('microsoft-iis/'):
00064                     v = v.encode('utf-8').decode('iso-8859-1')
00065 
00066                 # Apache mod_cgi writes bytes-as-unicode (as if ISO-8859-1) direct
00067                 # to the Unicode environ. No modification needed.
00068                 elif software.startswith('apache/'):
00069                     pass
00070 
00071                 # Python 3's http.server.CGIHTTPRequestHandler decodes
00072                 # using the urllib.unquote default of UTF-8, amongst other
00073                 # issues.
00074                 elif (
00075                     software.startswith('simplehttp/')
00076                     and 'python/3' in software
00077                 ):
00078                     v = v.encode('utf-8').decode('iso-8859-1')
00079 
00080                 # For other servers, guess that they have written bytes to
00081                 # the environ using stdio byte-oriented interfaces, ending up
00082                 # with the system code page.
00083                 else:
00084                     v = v.encode(enc, 'replace').decode('iso-8859-1')
00085 
00086             # Recover bytes from unicode environ, using surrogate escapes
00087             # where available (Python 3.1+).
00088             else:
00089                 v = v.encode(enc, esc).decode('iso-8859-1')
00090 
00091         environ[k] = v
00092     return environ
00093 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [
00002     'BaseHandler', 'SimpleHandler', 'BaseCGIHandler', 'CGIHandler',
00003     'IISCGIHandler', 'read_environ'
00004 ]

Definition at line 8 of file handlers.py.

Initial value:
00001 {
00002     'SCRIPT_NAME', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_METHOD', 'AUTH_TYPE',
00003     'CONTENT_TYPE', 'CONTENT_LENGTH', 'HTTPS', 'REMOTE_USER', 'REMOTE_IDENT',
00004 }

Definition at line 25 of file handlers.py.

Initial value:
00001 [None, # Dummy so we can use 1-based month numbers
00002               "Jan", "Feb", "Mar", "Apr", "May", "Jun",
00003               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

Definition at line 15 of file handlers.py.

list wsgiref.handlers._weekdayname = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

Definition at line 14 of file handlers.py.