本文整理汇总了Python中Cookie.SimpleCookie.get方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCookie.get方法的具体用法?Python SimpleCookie.get怎么用?Python SimpleCookie.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie.SimpleCookie
的用法示例。
在下文中一共展示了SimpleCookie.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: status
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def status(self, environ, start_response):
name1 = ''
name1_key = '*empty*'
if 'HTTP_COOKIE' in environ:
c = SimpleCookie(environ.get('HTTP_COOKIE', ''))
if 'name1' in c:
key = c.get('name1').value
name1 = usernames.get(key, '')
name1_key = key
data = """
<html>
<body>
Your username is """
data += name1
data += " and your key is "
data += name1_key
data += "<p><a href='/'>Home</a></body></html>"
else:
data = """
<html>
<body>
You're not Logged in.....<p>
<a href='/'>Home</a>
</body>
</html>
"""
start_response('200 OK', list(html_headers))
return [data]
示例2: __init__
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def __init__(self, environ, backend, ttl, cookie_name, fp_use_ip, log):
self.handler = backend
self.ttl = ttl
self.cookie_name = cookie_name
self.sid = None
self.data = {}
self.log = log
self.clear_cookie = False
self.session_start = False
fingerprint = '%s%s%s' % (environ.get('HTTP_USER_AGENT'),
environ.get('HTTP_ACCEPT_ENCODING'),
environ.get('HTTP_ACCEPT_LANGUAGE'))
if fp_use_ip:
fingerprint += environ.get('REMOTE_ADDR')
self.fingerprint = hashlib.sha1(fingerprint).hexdigest()
if 'HTTP_COOKIE' in environ:
cookie = SimpleCookie(environ['HTTP_COOKIE'])
if cookie.get(self.cookie_name):
cookie_sid = cookie[self.cookie_name].value
if cookie_sid:
self.sid = cookie_sid
示例3: getSession
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def getSession(self):
"""Return the existing session or a new session"""
if self.session is not None:
return self.session
# Get value of cookie header that was sent
cookie_str = self.headers.get('Cookie')
if cookie_str:
cookie_obj = SimpleCookie(cookie_str)
sid_morsel = cookie_obj.get(self.SESSION_COOKIE_NAME, None)
if sid_morsel is not None:
sid = sid_morsel.value
else:
sid = None
else:
sid = None
# If a session id was not set, create a new one
if sid is None:
sid = randomString(16, '0123456789abcdef')
session = None
else:
session = self.server.sessions.get(sid)
# If no session exists for this session ID, create one
if session is None:
session = self.server.sessions[sid] = {}
session['id'] = sid
self.session = session
return session
示例4: parse_cookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def parse_cookie(name, seed, kaka):
"""Parses and verifies a cookie value """
if not kaka:
return None
cookie_obj = SimpleCookie(kaka)
morsel = cookie_obj.get(name)
if morsel:
parts = morsel.value.split("|")
if len(parts) != 3: return None
# verify the cookie signature
#print >> sys.stderr, "COOKIE verify '%s' '%s' '%s'" % (seed,
# parts[0],
# parts[1])
sig = cookie_signature(seed, parts[0], parts[1])
#print >> sys.stderr, ">>", sig
if sig != parts[2]:
raise Exception("Invalid cookie signature")
try:
return parts[0].strip(), parts[1]
except KeyError:
return None
else:
return None
示例5: application
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def application(environ, start_response):
GET = parse_qs(environ['QUERY_STRING'])
path = environ['PATH_INFO']
cookies = SimpleCookie(environ.get('HTTP_COOKIE', ''))
headers = {'Content-Type': 'text/html'}
if path == '/':
response = base%{'contenido': form}
elif path == '/set':
cookies['sessionId'] = store.add(GET.get('name', ['NULL McNULL',])[0])
response = base%{'contenido': '<div style="background-color:green;color:white">Cookie establecida</div>'}
headers.update({'Set-Cookie': cookies['sessionId'].OutputString()})
else:
cookie = cookies.get('sessionId',None)
name = cookie and store.get(cookie.value, None) or None
response = base%{'contenido': "<p>El valor de la sesión es: %s</p>"%name if name else 'Ninguno'}
headers.update({'Content-Length': str(len(response))})
start_response(
"200 OK",
headers.items()
)
return [response]
示例6: getSession
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def getSession(self):
"""Return the existing session or a new session"""
if self.session is not None:
return self.session
# Get value of cookie header that was sent
cookie_str = self.headers.get('Cookie')
if cookie_str:
cookie_obj = SimpleCookie(cookie_str)
sid_morsel = cookie_obj.get(self.SESSION_COOKIE_NAME, None)
if sid_morsel is not None:
sid = sid_morsel.value
else:
sid = None
else:
sid = None
# If a session id was not set, create a new one
if sid is None:
# Pure pragmatism: Use function for nonce salt to generate session ID.
sid = make_nonce_salt(16)
session = None
else:
session = self.server.sessions.get(sid)
# If no session exists for this session ID, create one
if session is None:
session = self.server.sessions[sid] = {}
session['id'] = sid
self.session = session
return session
示例7: start
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def start(self, cookies, cookieopts=None):
c = SimpleCookie(cookies)
sid = c.get(self.cookiename)
create = True
if sid is not None:
for m in self.get(sid.value):
yield m
if self.apiroutine.retvalue is not None:
self.apiroutine.retvalue = (self.SessionHandle(self.apiroutine.retvalue, self.apiroutine), [])
create = False
if create:
for m in self.create():
yield m
sh = self.apiroutine.retvalue
m = Morsel()
m.key = self.cookiename
m.value = sh.id
m.coded_value = sh.id
opts = {"path": "/", "httponly": True}
if cookieopts:
opts.update(cookieopts)
if not cookieopts["httponly"]:
del cookieopts["httponly"]
m.update(opts)
self.apiroutine.retvalue = (sh, [m])
示例8: parse_cookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def parse_cookie(name, seed, kaka):
"""Parses and verifies a cookie value
:param seed: A seed used for the HMAC signature
:param kaka: The cookie
:return: A tuple consisting of (payload, timestamp)
"""
if not kaka:
return None
cookie_obj = SimpleCookie(kaka)
morsel = cookie_obj.get(name)
if morsel:
parts = morsel.value.split("|")
if len(parts) != 3:
return None
# verify the cookie signature
sig = cookie_signature(seed, parts[0], parts[1])
if sig != parts[2]:
raise Exception("Invalid cookie signature")
try:
return parts[0].strip(), parts[1]
except KeyError:
return None
else:
return None
示例9: cookie_parts
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def cookie_parts(name, kaka):
cookie_obj = SimpleCookie(kaka)
morsel = cookie_obj.get(name)
if morsel:
return morsel.value.split("|")
else:
return None
示例10: party_make
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def party_make(self, environ, start_response):
content_type = 'text/html'
username = ''
if 'HTTP_COOKIE' in environ:
c = SimpleCookie(environ.get('HTTP_COOKIE', ''))
if 'name1' in c:
key = c.get('name1').value
name1_key = key
if key in usernames:
username = str(usernames[key])
if username == '':
username = "Anonymous"
data = """\
<html><head><title>Create a Party - Drinkz - Alex Lockwood</title>
<style type="text/css">
h1 {color:red;}
p {color:black;}
</style></head><body>
<h1>Create a Party!</h1>
<a href='/'>Return to Index</a><p>
"""
data += "<form action='party_make_submit'>Please input the following information:<br>"
data += "Party title: <input type='text' name='title'><br>Date: <input type='text' name='date'><br>Time: <input type='text' name='time'><br>Address: <input type='text' name='address'><br>"
data += "Enter up to three liquors you're bringing:<br>"
data += "Brand: <input type='text' name='m1'>Liquor: <input type='text' name='l1'>Amount (ml): <input type=number name='a1' min='0' max='5000'>"
data += "Brand: <input type='text' name='m2'>Liquor: <input type='text' name='l2'>Amount (ml): <input type=number name='a2' min='0' max='5000'>"
data += "Brand: <input type='text' name='m3'>Liquor: <input type='text' name='l3'>Amount (ml): <input type=number name='a3' min='0' max='5000'>"
data += "<input type='submit' value='CREATE PARTY!'><input name='user' type='hidden' value='%s'></form></p></body></html>"% username
start_response('200 OK', list(html_headers))
return [data]
示例11: getCookie2
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def getCookie2(cookie_name):
cookiestr = doc().cookie
c = SimpleCookie(str(cookiestr))
cs = c.get(cookie_name, None)
print "getCookie2", cookiestr, "name", cookie_name, "val", cs
if cs:
return cs.value
return None
示例12: get_cookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def get_cookie(self, key):
in_cookies = SimpleCookie()
request_cookies = self.headers.get('Cookie')
if request_cookies:
in_cookies.load(request_cookies)
val = in_cookies.get(key)
return val.value if val else None
return None
示例13: recv_make_party
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def recv_make_party(self, environ, start_response):
formdata = environ['QUERY_STRING']
results = urlparse.parse_qs(formdata)
new_music = ""
new_crash_spots = 0
new_DDs = 0
try:
new_music = results['music'][0]
new_crash_spots = results['crash_spots'][0]
new_DDs = results['DD'][0]
except KeyError:
pass
name1 = ''
if 'HTTP_COOKIE' in environ:
c = SimpleCookie(environ.get('HTTP_COOKIE', ''))
if 'name1' in c:
key = c.get('name1').value
name1 = usernames.get(key, '')
p = party.Party(name1, new_music, int(new_crash_spots), int(new_DDs))
db.add_party(p)
content_type = 'text/html'
data = """\
<html>
<head>
<title>Party</title>
<style type='text/css'>
h1 {color:red;}
body {
font-size: 14px;
}
</style>
</head>
<body>
"""
data += "Liquors:"
data += "<p>"
for item in results['liquors']:
p.add_liquor(item[0:])
data += item[0:]
data += "<p>"
data += "Type of music: "+new_music
data += '<p>'
data += "Crash Spots: "+str(new_crash_spots)
data += '<p>'
data += "Desginated Drivers: "+str(new_DDs)
data += """\
<p>
<a href='./'>return to index</a>
</body>
</html>
"""
start_response('200 OK', list(html_headers))
return [data]
示例14: __get__
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def __get__(self, item, cls):
if len(self) == 0:
c = SimpleCookie(app.request.get('HTTP_COOKIE', ''))
# TODO Fix for GAE
for key in c.keys():
self[key] = c.get(key).value
return self
示例15: readCookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import get [as 别名]
def readCookie(self, name):
cookie_str = self.headers.get('Cookie')
print 'cookie:', cookie_str
if cookie_str:
c = SimpleCookie(cookie_str)
cookie_morsel = c.get(name, None)
if cookie_morsel is not None:
return cookie_morsel.value
return None