Back to index

python-weblib  1.3.9
Classes | Functions | Variables
pyweblib.helper Namespace Reference

Classes

class  AcceptHeaderDict
class  AcceptCharsetDict

Functions

def BrowserType
def guessClientAddr

Variables

string __version__ = '0.3.1'
dictionary known_browsers
dictionary known_browsers_rev = {}
tuple compatible_browsers = known_browsers.keys()
tuple compatible_browsers_re = re.compile('(%s)[/ ]+([0-9.]*)' % '|'.join(compatible_browsers))
tuple mozilla_re = re.compile('(Mozilla)[/ ]+([0-9.]*)')

Detailed Description

pyweblib.helper - Misc. stuff useful in CGI-BINs
(c) by Michael Stroeder <michael@stroeder.com>

This module is distributed under the terms of the
GPL (GNU GENERAL PUBLIC LICENSE) Version 2
(see http://www.gnu.org/copyleft/gpl.html)

$Id: helper.py,v 1.15 2011/01/16 09:04:10 michael Exp $

Function Documentation

def pyweblib.helper.BrowserType (   http_user_agent)
Parse the HTTP_USER_AGENT environment variable and return the
tuple (Browser,Version).

Not sure if this succeeds in every situation since most
browsers have very obscure HTTP_USER_AGENT entries for compability reasons.
The following browsers are known by name:
Netscape  Netscape Navigator, Netscape Communicator)
MSIE    MS Internet Explorer
Opera   Opera browser from http://www.operasoftware.com/
StarOffice  built-in browser of Star Office
Lynx    the text-based browser Lynx
NetPositive Net Positive (BeOS)

Definition at line 38 of file helper.py.

00038 
00039 def BrowserType(http_user_agent):
00040   """
00041   Parse the HTTP_USER_AGENT environment variable and return the
00042   tuple (Browser,Version).
00043 
00044   Not sure if this succeeds in every situation since most
00045   browsers have very obscure HTTP_USER_AGENT entries for compability reasons.
00046   The following browsers are known by name:
00047   Netscape  Netscape Navigator, Netscape Communicator)
00048   MSIE    MS Internet Explorer
00049   Opera   Opera browser from http://www.operasoftware.com/
00050   StarOffice  built-in browser of Star Office
00051   Lynx    the text-based browser Lynx
00052   NetPositive Net Positive (BeOS)
00053   """
00054 
00055   if not http_user_agent:
00056     return ('','')
00057   else:
00058     browserrm = compatible_browsers_re.search(http_user_agent)
00059     if browserrm:
00060       return browserrm.groups()
00061     else:
00062       browserrm = mozilla_re.search(http_user_agent)
00063       if browserrm:
00064         return browserrm.groups()
00065       else:
00066         return ('','')
00067 

def pyweblib.helper.guessClientAddr (   env = None)
Guesses the host name or IP address of the HTTP client by looking
at various HTTP headers mapped to CGI-BIN environment.

env
      dictionary containing environment vars (default os.env)

Definition at line 68 of file helper.py.

00068 
00069 def guessClientAddr(env=None):
00070   """
00071   Guesses the host name or IP address of the HTTP client by looking
00072   at various HTTP headers mapped to CGI-BIN environment.
00073 
00074   env
00075         dictionary containing environment vars (default os.env)
00076   """
00077   env = env or os.environ
00078   return env.get('FORWARDED_FOR',
00079          env.get('HTTP_X_FORWARDED_FOR',
00080          env.get('REMOTE_HOST',
00081          env.get('REMOTE_ADDR',None))))
00082 


Variable Documentation

string pyweblib.helper.__version__ = '0.3.1'

Definition at line 12 of file helper.py.

tuple pyweblib.helper.compatible_browsers = known_browsers.keys()

Definition at line 31 of file helper.py.

tuple pyweblib.helper.compatible_browsers_re = re.compile('(%s)[/ ]+([0-9.]*)' % '|'.join(compatible_browsers))

Definition at line 34 of file helper.py.

Initial value:
00001 {
00002   'MSIE':'Microsoft Internet Explorer',
00003   'Mozilla':'Netscape Navigator',
00004   'Lynx':'Lynx',
00005   'Opera':'Opera',
00006   'StarOffice':'StarOffice',
00007   'NCSA_Mosaic':'NCSA Mosaic',
00008   'NetPositive':'Net Positive',
00009   'Mozilla':'Firefox',
00010   'Mozilla':'Seamonkey',
00011 }

Definition at line 16 of file helper.py.

Definition at line 27 of file helper.py.

tuple pyweblib.helper.mozilla_re = re.compile('(Mozilla)[/ ]+([0-9.]*)')

Definition at line 35 of file helper.py.