本文整理汇总了Python中mod_python.Cookie类的典型用法代码示例。如果您正苦于以下问题:Python Cookie类的具体用法?Python Cookie怎么用?Python Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cookie类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:pombredanne,项目名称:pyjamas-desktop,代码行数:7,代码来源:zct.py
示例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
开发者ID:circlecycle,项目名称:mps,代码行数:27,代码来源:Identity.py
示例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
开发者ID:EMSL-MSC,项目名称:pacifica-2.0,代码行数:29,代码来源:__init__.py
示例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
开发者ID:philn,项目名称:alinea,代码行数:31,代码来源:ModPySessionManager.py
示例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"
开发者ID:doublewera,项目名称:smdc,代码行数:7,代码来源:structure.py
示例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')
开发者ID:mchlbrnd,项目名称:rm-group-a,代码行数:29,代码来源:randomize.py
示例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())
开发者ID:JonnyFunFun,项目名称:pycoin-gateway,代码行数:8,代码来源:csrf.py
示例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)
开发者ID:untangle,项目名称:ngfw_src,代码行数:8,代码来源:handler.py
示例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
开发者ID:thecapn2k5,项目名称:cloneme,代码行数:9,代码来源:cgi_app.py
示例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
开发者ID:babongo,项目名称:libscs,代码行数:10,代码来源:modpyscs.py
示例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>'
开发者ID:COMU,项目名称:pyldapadmin,代码行数:10,代码来源:server_info.py
示例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
开发者ID:tianyanhui,项目名称:mod_python,代码行数:12,代码来源:tests.py
示例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
开发者ID:tianyanhui,项目名称:mod_python,代码行数:13,代码来源:tests.py
示例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
开发者ID:pombredanne,项目名称:pyjamas-desktop,代码行数:14,代码来源:zctlogin.py
示例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
开发者ID:palli,项目名称:statmon,代码行数:15,代码来源:standardControllers.py
示例16: save
def save(req):
# Get a list with all the values of the selected_shows[]
selected_shows = req.form.getlist('selected_shows[]')
# Escape the user input to avoid script injection attacks
selected_shows = map(lambda show: cgi.escape(show), selected_shows)
# Value of the cookie is the list of selected shows seperated by ','
cookie_str = ','.join(selected_shows)
c = Cookie.Cookie('selected_shows', cookie_str, path='/')
c.expires = time.time() + 30 * 24 * 60 * 60
# Add the cookie to the HTTP header
Cookie.add_cookie(req, c)
util.redirect(req, 'http://localhost/wwia')
开发者ID:akshaykumar90,项目名称:wwia,代码行数:15,代码来源:add.py
示例17: __init__
def __init__(self,req=None, form=None):
self.req = req
if self.req != None:
# mod_python
self.form = util.FieldStorage(self.req)
self._cookies_in = Cookie.get_cookies(self.req)
else:
# if we have a form, don't get a new one
if form:
self.form=form
# if we don't have a form, then get one
else:
self.form = cgi.FieldStorage()
self._cookies_in = SimpleCookie()
try:
self._cookies_in.load(os.environ["HTTP_COOKIE"])
except KeyError:
pass
self._dispatch = {}
self._header_sent = 0
self._header_props = {"Content-Type" : "text/html;charset=UTF-8"}
self._header_props = {}
self._header_type = "header"
self._cookies = []
self._url = ""
self._environ = os.environ
self.template_dir = 'templates'
self.run_mode_param = 'rm'
self.start_mode = ''
self.__globals__ = {}
self.setup()
开发者ID:thecapn2k5,项目名称:cloneme,代码行数:31,代码来源:cgi_app.py
示例18: get_cookie
def get_cookie(cls, req, name):
"""Retreive cookie by name from request object."""
#cookies = mod_python.Cookie.get_cookies(req)
cookies = Cookie.get_cookies(req)
this_cookie = cookies.get(name)
value = cut(str(this_cookie), "{0}=".format(name))
return value
开发者ID:OaklandPeters,项目名称:local_packages,代码行数:7,代码来源:web_utility.py
示例19: __init__
def __init__(self,req,appid=None):
self.req = req
if appid == None:
args = split_args(self.req.args);
appid = args['APPID']
self.captureSettings = load_capture_settings(self.req,appid)
self.cookie = Cookie.get_cookies(self.req, Cookie.MarshalCookie, secret=str(self.captureSettings["secretKey"]))
开发者ID:untangle,项目名称:ngfw_src,代码行数:7,代码来源:handler.py
示例20: accesshandler
def accesshandler(request):
cookies = Cookie.get_cookies(request)
# if login ticket cookie does not exist, then deny
if not cookies.has_key('login_ticket'):
# just refuse access
return apache.HTTP_FORBIDDEN
ticket = cookies['login_ticket'].value
if not ticket:
return apache.HTTP_FORBIDDEN
server = TacticServerStub.get(protocol='local')
expr = "@SOBJECT(sthpw/ticket['ticket','%s'])" % ticket
sobject = server.eval(expr, single=True)
now = SPTDate.now()
expiry = sobject.get("expiry")
if expiry and expiry < str(now):
return apache.HTTP_FORBIDDEN
request.add_common_vars()
path = str(request.subprocess_env['REQUEST_URI'])
if path == None:
return apache.HTTP_FORBIDDEN
# FIXME: find some mechanism which is more acceptable ... like /icons
#if path.find("_icon_") != -1:
# return apache.OK
return apache.OK
开发者ID:0-T-0,项目名称:TACTIC,代码行数:32,代码来源:asset_security.py
注:本文中的mod_python.Cookie类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论