Welcome to Xierpa. This is the stable 1.2 version which was developed by Petr van Blokland + Claudia Mens (buro@petr.com) and is maintained by Michiel Kauw-A-Tjoe. It is subclassed by the Museum Meermanno and American Express applications.

Cookie

Xierpa automatically saves the session id (_sid url parameter) in a cookie (if the client browser allows access). This is done by setting the self.e.savecookiesession = True.
When e.session exists, the httprequest will try to set the cookie value with the current session id (from e.sidversion()).

Reading the session id from the cookie

When creating the local pagen environment e the server first will check if there is a _sid available in e.form. If there is no parameter available, then the server will look for a cookie. When the browser offers the cookie content, then take that id. If there is a current session with that id, then instal it a e.session. Otherwise the e.session is set to None.

Writing the session id to the cookie

Writing of the session id to a cookie only is relevant if there actually is a e.session available.
The writing of a cookie depends then on the value of the e.savecookiesession flag. If it is set to True, then a cookie header is added to the generated page, containing the session id. If the flag is False then an id value of none is written, thus clearing any reference to a session.
Default value for e.savecookiesession is False. If an application wants to use the automatic saving of the session id in a cookie, then the flag should be set to True.
def self.initializeapplication(self):
	...
	self.e.savecookiesession = True
	...
In Firefox the existence of the cookie shows as follows.



When the session does not exist, or when the e.savecookiesession tag is set to False.

Read and set other cookies

Set cookie to the http header.
import
  • default lifetime is 30 days, measured in seconds (2592000).
  • default path is e['domainroot'].
  • default domain is e['server']
Cookie(self,'the_cookie_name') represents the string of the cookie content.
If cookie name does not exists, a new cookie instance is made, but not set.
Use _set() to set the cookie.

Python example
from xpyth.xierpa.tools.cookie import Cookie
c = Cookie(self,'the_cookie_name', lifetime=12000)
c._delete()
c._set(14, lifetime=7000)


MethodAttributesDocstring or default value
_delete
Delete cookie by setting cookie expires to -14400 sec.
_lifetime lifetime
Change cookie lifetime to new expires.
lifetime is set in seconds.
_set content
domain
lifetime
path
Set cookie to the http header.
Default lifetime is 30 days, measured in seconds (2592000).
Default path is e['domainroot'].
Default domain is e['server']
_string
Return a string as the key=value pair.