本文整理汇总了Python中mod_python.Cookie类的典型用法代码示例。如果您正苦于以下问题:Python Cookie类的具体用法?Python Cookie怎么用?Python Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_browser_info
def set_browser_info(self, info):
""" sets the "state" info for the browser
"""
#info = base64.encodestring(repr(info))
info = repr(info)
Cookie.add_cookie(self.req, Cookie.Cookie('browseinfo', info))
示例2: __init__
def __init__(self, req):
"""get, extract info, and do upkeep on the session cookie. This determines what the sessid and user are
for this request."""
#pass the request in making in so we can edit it later if requested (ACL for example)
self.ip = req.connection.remote_ip
c = Cookie.get_cookies(req)
if not c.has_key('mps'):
self.sessid = Uid().new_sid(req)
else:
c = c['mps']
self.sessid = c.value
#make new cookie so the cycle continues
c = Cookie.Cookie('mps', self.sessid)
c.path = '/'
Cookie.add_cookie(req, c)
self.session_path = "%s%s"%(path_to_sessions, self.sessid)
self.full_session_path = "%s%s"%(self.session_path, db_extension)
#use previous authenication until cookie is reevaluated, if they are officially logged in (in Instance)
if os.path.exists(self.full_session_path):
session = shelve.open(self.session_path, 'rw')
self.user = session['USER_']
session.close()
else:
self.user = self.unauthorized
示例3: general_authenhandler
def general_authenhandler(req, req_type, anon_ok=False):
pw = req.get_basic_auth_pw()
cookies = Cookie.get_cookies(req)
if not cookies.has_key('csrftoken'):
cookie = Cookie.Cookie('csrftoken', hashlib.md5(str(random.randrange(0, 2<<63))).hexdigest())
cookie.path = '/'
if config.get('session', 'cookie_host') != '':
cookie.domain = config.get('session', 'cookie_host')
Cookie.add_cookie(req, cookie)
if cookies.has_key('myemsl_session'):
sql = "select user_name from myemsl.eus_auth where session_id = %(sid)s"
cnx = myemsldb_connect(myemsl_schema_versions=['1.0'])
cursor = cnx.cursor()
cursor.execute(sql, {'sid':cookies['myemsl_session'].value})
rows = cursor.fetchall()
found = False
for row in rows:
req.user = row[0]
found = True
if found:
logger.debug("Session: %s", str(cookies['myemsl_session'].value))
#FIXME outage_check seems to be in the wrong place for a myemsl database outage.
return outage_check(req, req_type)
elif anon_ok:
req.user = ''
return outage_check(req, req_type)
url = urllib.quote(req.unparsed_uri)
redirect(req, "/myemsl/auth?url=%s" %(url))
return apache.HTTP_UNAUTHORIZED
示例4: _set_cookie
def _set_cookie(self, value, **attrs):
"""(session_id : string)
Ensure that a session cookie with value 'session_id' will be
returned to the client via the response object.
Since Mod_Python has its own Cookie management system, we use it.
"""
config = get_publisher().config
name = config.session_cookie_name
domain = config.session_cookie_domain
if config.session_cookie_path:
path = config.session_cookie_path
else:
path = get_request().get_environ('SCRIPT_NAME')
if not path.endswith("/"):
path += "/"
expires = -1
options = {'expires': expires,
'path': path }
if domain is not None:
options.update({'domain':domain})
if value:
Cookie.add_cookie(self.modpython_request, name, value, **options)
return name
示例5: logout
def logout(req):
cookies = Cookie.get_cookies(req)
Cookie.add_cookie(req, 'ogtvogh', '', expires=time.time(), path='/')
req.status=apache.HTTP_MOVED_TEMPORARILY
req.headers_out["Location"] = SITEURL
req.send_http_header()
return "You have successfully logged out"
示例6: index
def index(req):
# check if cookie is set for respondent who already participated
client_cookie = Cookie.get_cookie(req, 'rm-group-a')
if client_cookie is None:
Cookie.add_cookie(req, 'rm-group-a', 'true', expires=time.time()+31*24*3600) # expires after 1 month
else:
return 'You already participated.'
# load current respondent conditions
with open(PATH, 'r') as f:
respondents = yaml.load(f)
if respondents is None:
respondents = []
no_avatar_count = count_str_in_seq(NO_AVATAR, respondents)
avatar_count = count_str_in_seq(AVATAR, respondents)
if no_avatar_count <= MIN_RESPONDENTS and avatar_count >= MIN_RESPONDENTS:
condition = NO_AVATAR
elif no_avatar_count >= MIN_RESPONDENTS and avatar_count <= MIN_RESPONDENTS:
condition = AVATAR
else:
condition = random.choice([NO_AVATAR, AVATAR])
# write new condition entry
with open(PATH, 'w') as f:
respondents.append(condition)
yaml.dump(respondents, f)
util.redirect(req, 'welcome' + '-' + condition + '.html')
示例7: _add_csrf_cookie_if_needed
def _add_csrf_cookie_if_needed(req):
signed_cookies = Cookie.get_cookies(req, Cookie.SignedCookie, secret=_get_secret())
cookie = signed_cookies.get(settings.csrf_cookie_name, None)
if cookie:
# make sure we aren't altered
if type(cookie) is Cookie.SignedCookie and cookie.value == _message_contents():
return
Cookie.add_cookie(req, _generate_csrf_cookie())
示例8: set
def set(self,username):
value = {
"username": username
}
cookie = Cookie.MarshalCookie(self.cookie_key, value, secret=str(self.captureSettings["secretKey"]))
cookie.path = "/"
cookie.expires = time.time() + int(self.captureSettings["sessionCookiesTimeout"])
Cookie.add_cookie(self.req, cookie)
示例9: send_cookies
def send_cookies(self):
""" sends the http headers for any cookies that need to be set
"""
if self.req != None:
for c in self._cookies:
Cookie.add_cookie(self.req,c)
else:
for c in self._cookies:
print c
示例10: set
def set(self, var, val):
ck = scs.encode(self.s, val, len(val))
if ck is None:
raise Exception, 'failed scs.encode()'
c = Cookie.Cookie(var, ck)
Cookie.add_cookie(self.req, c)
return ck
示例11: index
def index(req):
secret = 'my_secret'
marshal_cookies = Cookie.get_cookies(req, Cookie.MarshalCookie, secret=secret)
returned_marshal = marshal_cookies.get('marshal', None)
if(returned_marshal):
returned_marshal.expires= time.time()
Cookie.add_cookie(req, returned_marshal)
return '<html><body>return to main place <a href="./">here</a></body></html>'
else:
return '<html><title></title><body>there is nothing <a href="./">back</a></body></html>'
示例12: Cookie_Cookie
def Cookie_Cookie(req):
from mod_python import Cookie
cookies = Cookie.get_cookies(req)
for k in cookies:
Cookie.add_cookie(req, cookies[k])
req.write("test ok")
return apache.OK
示例13: Cookie_MarshalCookie
def Cookie_MarshalCookie(req):
from mod_python import Cookie
cookies = Cookie.get_cookies(req, Cookie.MarshalCookie,
secret="secret")
for k in cookies:
Cookie.add_cookie(req, cookies[k])
req.write("test ok")
return apache.OK
示例14: logout
def logout(self, REQUEST):
""" logs out and redirects to main page
"""
Cookie.add_cookie(self.req, Cookie.Cookie("sessionkey", "", expires=0))
Cookie.add_cookie(self.req, Cookie.Cookie("browseinfo", "", expires=0))
self.info = {}
links = {"banner": "menu", "leftcontent": "advertising"}
page = self.tmpl("logout")
page.staticlink(links)
return page
示例15: setCookie
def setCookie(self,key,value,secret=None,expires=None,path=None):
cookieType = Cookie.Cookie
options = {}
if expires != None: options['expires'] = expires
if path != None: options['path'] = path
if secret != None:
cookieType = Cookie.MarshalCookie
options['secret'] = secret
Cookie.add_cookie(self.req, cookieType(key, value, **options))
if expires==0 and not secret:
self.cookieCache[key] = None
elif not secret:
self.cookieCache[key] = value