Back to index

python-weblib  1.3.9
Public Member Functions | Public Attributes
pyweblib.helper.AcceptHeaderDict Class Reference
Inheritance diagram for pyweblib.helper.AcceptHeaderDict:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def __getitem__
def items
def keys

Public Attributes

 defaultValue
 preferred_value
 data

Detailed Description

This dictionary class is used to parse
Accept-header lines with quality weights.

It's a base class for all Accept-* headers described
in sections 14.1 to 14.5 of RFC2616.

Definition at line 83 of file helper.py.


Constructor & Destructor Documentation

def pyweblib.helper.AcceptHeaderDict.__init__ (   self,
  envKey,
  env = None,
  defaultValue = None 
)
Parse the Accept-* header line.

httpHeader
string with value of Accept-* header line

Reimplemented in pyweblib.helper.AcceptCharsetDict.

Definition at line 92 of file helper.py.

00092 
00093   def __init__(self,envKey,env=None,defaultValue=None):
00094     """
00095     Parse the Accept-* header line.
00096 
00097     httpHeader
00098         string with value of Accept-* header line
00099     """
00100     env = env or os.environ
00101     UserDict.UserDict.__init__(self)
00102     self.defaultValue = defaultValue
00103     self.preferred_value = []
00104     try:
00105       http_accept_value = [
00106         s
00107         for s in env[envKey].strip().split(',')
00108         if len(s)
00109       ]
00110     except KeyError:
00111       self.data = {'*':1.0}
00112     else:
00113       if not http_accept_value:
00114         self.data = {'*':1.0}
00115       else:
00116         self.data = {}
00117         for i in http_accept_value:
00118           try:
00119             c,w=i.split(';')
00120           except ValueError:
00121             c,w = i,''
00122           # Normalize charset name
00123           c=c.strip().lower()
00124           try:
00125             q,qvalue_str=w.split('=',1)
00126             qvalue = float(qvalue_str)
00127           except ValueError:
00128             qvalue = 1.0
00129           # Add to capability dictionary
00130           if c:
00131             self.data[c] = qvalue
00132     return # AcceptHeaderDict.__init__()


Member Function Documentation

def pyweblib.helper.AcceptHeaderDict.__getitem__ (   self,
  value 
)
value
String representing the value for which to return
the floating point capability weight.

Definition at line 133 of file helper.py.

00133 
00134   def __getitem__(self,value):
00135     """
00136     value
00137         String representing the value for which to return
00138         the floating point capability weight.
00139     """
00140     return self.data.get(
00141       value.lower(),
00142       self.data.get('*',0)
00143     )

Return the accepted values as tuples (value,weigth)
in descending order of capability weight

Definition at line 144 of file helper.py.

00144 
00145   def items(self):
00146     """
00147     Return the accepted values as tuples (value,weigth)
00148     in descending order of capability weight
00149     """
00150     l = self.data.items()
00151     l.sort(lambda x,y:cmp(y[1],x[1]))
00152     return l

Here is the caller graph for this function:

Return the accepted values in descending order of capability weight

Definition at line 153 of file helper.py.

00153 
00154   def keys(self):
00155     """
00156     Return the accepted values in descending order of capability weight
00157     """
00158     l = self.items()
00159     return [ k for k,v in l ]
00160 

Here is the call graph for this function:


Member Data Documentation

Definition at line 110 of file helper.py.

Definition at line 101 of file helper.py.

Definition at line 102 of file helper.py.


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