Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Private Attributes
http.cookies.Morsel Class Reference

List of all members.

Public Member Functions

def __init__
def __setitem__
def isReservedKey
def set
def output
def __repr__
def js_output
def OutputString

Public Attributes

 key
 value
 coded_value

Static Private Attributes

dictionary _reserved
 __str__ = output

Detailed Description

A class to hold ONE (key, value) pair.

In a cookie, each such pair may have several attributes, so this class is
used to keep the attributes associated with the appropriate key,value pair.
This class also includes a coded_value attribute, which is used to hold
the network representation of the value.  This is most useful when Python
objects are pickled for network transit.

Definition at line 308 of file cookies.py.


Constructor & Destructor Documentation

Definition at line 341 of file cookies.py.

00341 
00342     def __init__(self):
00343         # Set defaults
00344         self.key = self.value = self.coded_value = None
00345 
00346         # Set default attributes
00347         for key in self._reserved:
00348             dict.__setitem__(self, key, "")

Here is the caller graph for this function:


Member Function Documentation

Definition at line 376 of file cookies.py.

00376 
00377     def __repr__(self):
00378         return '<%s: %s=%s>' % (self.__class__.__name__,
00379                                 self.key, repr(self.value))

def http.cookies.Morsel.__setitem__ (   self,
  K,
  V 
)

Definition at line 349 of file cookies.py.

00349 
00350     def __setitem__(self, K, V):
00351         K = K.lower()
00352         if not K in self._reserved:
00353             raise CookieError("Invalid Attribute %s" % K)
00354         dict.__setitem__(self, K, V)

def http.cookies.Morsel.isReservedKey (   self,
  K 
)

Definition at line 355 of file cookies.py.

00355 
00356     def isReservedKey(self, K):
00357         return K.lower() in self._reserved

def http.cookies.Morsel.js_output (   self,
  attrs = None 
)

Definition at line 380 of file cookies.py.

00380 
00381     def js_output(self, attrs=None):
00382         # Print javascript
00383         return """
00384         <script type="text/javascript">
00385         <!-- begin hiding
00386         document.cookie = \"%s\";
00387         // end hiding -->
00388         </script>
00389         """ % (self.OutputString(attrs).replace('"', r'\"'))

Here is the call graph for this function:

def http.cookies.Morsel.output (   self,
  attrs = None,
  header = "Set-Cookie:" 
)

Definition at line 371 of file cookies.py.

00371 
00372     def output(self, attrs=None, header="Set-Cookie:"):
00373         return "%s %s" % (header, self.OutputString(attrs))

Here is the call graph for this function:

def http.cookies.Morsel.OutputString (   self,
  attrs = None 
)

Definition at line 390 of file cookies.py.

00390 
00391     def OutputString(self, attrs=None):
00392         # Build up our result
00393         #
00394         result = []
00395         append = result.append
00396 
00397         # First, the key=value pair
00398         append("%s=%s" % (self.key, self.coded_value))
00399 
00400         # Now add any defined attributes
00401         if attrs is None:
00402             attrs = self._reserved
00403         items = sorted(self.items())
00404         for key, value in items:
00405             if value == "":
00406                 continue
00407             if key not in attrs:
00408                 continue
00409             if key == "expires" and isinstance(value, int):
00410                 append("%s=%s" % (self._reserved[key], _getdate(value)))
00411             elif key == "max-age" and isinstance(value, int):
00412                 append("%s=%d" % (self._reserved[key], value))
00413             elif key == "secure":
00414                 append(str(self._reserved[key]))
00415             elif key == "httponly":
00416                 append(str(self._reserved[key]))
00417             else:
00418                 append("%s=%s" % (self._reserved[key], value))
00419 
00420         # Return the result
00421         return _semispacejoin(result)
00422 
00423 
00424 #
00425 # Pattern for finding cookie
00426 #
00427 # This used to be strict parsing based on the RFC2109 and RFC2068
00428 # specifications.  I have since discovered that MSIE 3.0x doesn't
00429 # follow the character rules outlined in those specs.  As a
00430 # result, the parsing rules here are less strict.
00431 #

Here is the call graph for this function:

Here is the caller graph for this function:

def http.cookies.Morsel.set (   self,
  key,
  val,
  coded_val,
  LegalChars = _LegalChars 
)

Definition at line 358 of file cookies.py.

00358 
00359     def set(self, key, val, coded_val, LegalChars=_LegalChars):
00360         # First we verify that the key isn't a reserved word
00361         # Second we make sure it only contains legal characters
00362         if key.lower() in self._reserved:
00363             raise CookieError("Attempt to set a reserved key: %s" % key)
00364         if any(c not in LegalChars for c in key):
00365             raise CookieError("Illegal key value: %s" % key)
00366 
00367         # It's a good key, so save it.
00368         self.key = key
00369         self.value = val
00370         self.coded_value = coded_val

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

http.cookies.Morsel.__str__ = output [static, private]

Definition at line 374 of file cookies.py.

Initial value:
{
        "expires"  : "expires",
        "path"     : "Path",
        "comment"  : "Comment",
        "domain"   : "Domain",
        "max-age"  : "Max-Age",
        "secure"   : "secure",
        "httponly" : "httponly",
        "version"  : "Version",
    }

Definition at line 330 of file cookies.py.

Definition at line 343 of file cookies.py.

Definition at line 343 of file cookies.py.

Definition at line 343 of file cookies.py.


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