本文整理汇总了Python中Cookie.SimpleCookie.has_key方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCookie.has_key方法的具体用法?Python SimpleCookie.has_key怎么用?Python SimpleCookie.has_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie.SimpleCookie
的用法示例。
在下文中一共展示了SimpleCookie.has_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def login(self,username,password):
# 发起HTTP请求
conn = httplib.HTTPConnection("www.douban.com")
conn.request("GET","/")
resp = conn.getresponse()
print resp.read()
cookie = resp.getheader('Set-Cookie')
print cookie
cookie = SimpleCookie(cookie)
conn.close()
if not cookie.has_key('bid'):
print "cookie_error"
raise DoubanLoginException
else:
self.bid = cookie['bid']
print self.bid
# return self.bid
# login douban
data = urllib.urlencode({'source:':'simple',
'form_email':username,
'form_password':password,
'remember':'on'})
contentType = "application/x-www-form-urlencoded"
print data
cookie = 'bid="%s"' % self.bid
print cookie
headers = {"Content-Type":contentType,"Cookie":cookie}
with contextlib.closing(httplib.HTTPSConnection("www.douban.com")) as conn:
conn.request("POST","/accounts/login",data,headers)
r1 = conn.getresponse()
print r1.read()
resultCookie = SimpleCookie(r1.getheader('Set-Cookie'))
print resultCookie
# # 通过不了有验证码的情况
if not resultCookie.has_key('dbcl2'):
raise DoubanLoginException()
dbcl2 = resultCookie['dbcl2'].value
if dbcl2 is not None and len(dbcl2) > 0:
self.dbcl2 = dbcl2
uid = self.dbcl2.split(':')[0]
self.uid = uid
示例2: __login
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def __login(self, username, password):
"""
login douban, get the session token
"""
data = urllib.urlencode({'source':'simple',
'form_email':username, 'form_password':password})
contentType = "application/x-www-form-urlencoded"
self.__get_bid()
cookie = "bid=%s" % self.bid
headers = {"Content-Type":contentType, "Cookie": cookie }
with contextlib.closing(httplib.HTTPSConnection("www.douban.com")) as conn:
conn.request("POST", "/accounts/login", data, headers)
r1 = conn.getresponse()
resultCookie = SimpleCookie(r1.getheader('Set-Cookie'))
if not resultCookie.has_key('dbcl2'):
raise DoubanLoginException()
dbcl2 = resultCookie['dbcl2'].value
if dbcl2 is not None and len(dbcl2) > 0:
self.dbcl2 = dbcl2
uid = self.dbcl2.split(':')[0]
self.uid = uid
示例3: __init__
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
class cookie:
def __init__( self ):
self.cookieObj = SimpleCookie()
self.load()
def load( self ):
if not os.environ.has_key("HTTP_COOKIE"):
# Kein Cookie vorhanden
return
self.cookieObj.load( os.environ["HTTP_COOKIE"] )
def readCookie( self, CookieName ):
if self.cookieObj == False:
# Gibt kein Cookie
return False
if self.cookieObj.has_key(CookieName):
return self.cookieObj[CookieName].value
else:
return False
def debug( self ):
print "Cookie-Debug:"
print "<hr><pre>"
if not os.environ.has_key("HTTP_COOKIE"):
print "There is no HTTP_COOKIE in os.environ:\n"
for k,v in os.environ.iteritems(): print k,v
else:
print self.cookieObj
print "</pre><hr>"
示例4: check_cookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def check_cookie(self):
"""check, if the cookie with the session variable is set"""
HTML = HtmlContent()
if os.environ.has_key('HTTP_COOKIE') and os.environ.has_key('HTTP_REFERER'):
C = SimpleCookie(os.environ['HTTP_COOKIE'])
if C.has_key('session') and C['session'].value != "":
if C.has_key('company') and C['company'].value != "":
company = C['company'].value
else:
company = -1
else:
HTML.simple_redirect_header(self._url_)
return
return company
else:
HTML.simple_redirect_header(self._url_)
return
示例5: checklogin
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def checklogin(request):
c=SimpleCookie(request.headers.getheader('Cookie', ''))
m=md5.md5(fixeduser+':'+fixedpass)
digest=m.hexdigest()
if c.has_key('authhash') and c['authhash'].value==digest:
return True
else:
return False
示例6: test_anonymous_session
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def test_anonymous_session(self):
"""
Verify that session variables are stored in the database.
"""
incookie = Cookie()
incookie["trac_session"] = "123456"
outcookie = Cookie()
req = Mock(authname="anonymous", base_path="/", incookie=incookie, outcookie=outcookie)
session = Session(self.env, req)
self.assertEquals("123456", session.sid)
self.failIf(outcookie.has_key("trac_session"))
示例7: authPloneUser
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def authPloneUser(self, username, password, loginurl):
http = httplib2.Http()
headers = {}
headers['Content-type'] = 'application/x-www-form-urlencoded'
headers['User-Agent'] = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers[LEOCORNUS_HTTP_HEADER_KEY] = LEOCORNUS_HTTP_HEADER_VALUE
login_form = {}
login_form['__ac_name'] = username
login_form['__ac_password'] = password
login_form['cookies_enabled'] = '1'
login_form['js_enabled'] = '0'
login_form['form.submitted'] = '1'
body = urllib.urlencode(login_form)
try:
res, cont = http.request(loginurl, 'POST',
headers=headers, body=body)
except Exception:
# not valid login url!
return None
if res.has_key('set-cookie'):
cookie = SimpleCookie()
cookie.load(res['set-cookie'])
cookieName = settings.PLONEPROXY_COOKIE_NAME
defaultCookieName = '__ac'
if cookie.has_key(cookieName):
cookieValue = cookie.get(cookieName).value
return (cookieName, cookieValue)
elif cookie.has_key(defaultCookieName):
# try the default Plone cookie name in case.
cookieValue = cookie.get(defaultCookieName).value
return (defaultCookieName, cookieValue)
# no valid cookie found!
return None
示例8: test_anonymous_session
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def test_anonymous_session(self):
"""
Verify that session variables are stored in the database.
"""
incookie = Cookie()
incookie['trac_session'] = '123456'
outcookie = Cookie()
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=outcookie)
session = Session(self.env, req)
self.assertEquals('123456', session.sid)
self.failIf(outcookie.has_key('trac_session'))
示例9: __get_bid
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def __get_bid(self):
conn = httplib.HTTPConnection("www.douban.com")
conn.request("GET", "/accounts/login")
resp = conn.getresponse()
cookie = resp.getheader('Set-Cookie')
cookie = SimpleCookie(cookie)
conn.close()
if not cookie.has_key('bid'):
raise DoubanLoginException()
else:
self.bid = cookie['bid']
return self.bid
示例10: checkCookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def checkCookie(request):
if os.environ.has_key('HTTP_COOKIE'):
cookieStr = os.environ.get('HTTP_COOKIE')
if not cookieStr:
return False
cookie = SimpleCookie()
cookie.load(cookieStr)
if not cookie.has_key('hopper_oid_sid'):
return False
sid = cookie['hopper_oid_sid'].value
return isValidSession(request, sid)
else:
return False
示例11: getCookie
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def getCookie( initialvalues = {} ):
# TODO This is duplicated in leave-comic-comment.py getCookie(); delete that one.
"""
Return a SimpleCookie. If some of the cookie values haven't
been set, we'll plunk them into the cookie with the initialValues
dict.
"""
if os.environ.has_key('HTTP_COOKIE'):
C = SimpleCookie(os.environ['HTTP_COOKIE'])
else:
C = SimpleCookie()
for key in initialvalues.keys():
if not C.has_key(key): C[key] = initialvalues[key]
return C
示例12: login
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def login(self, username, password):
data = urllib.urlencode({'form_email':username, 'form_password':password})
with closing(httplib.HTTPConnection("www.douban.com")) as conn:
conn.request("POST", "/accounts/login", data, {"Content-Type":"application/x-www-form-urlencoded"})
cookie = SimpleCookie(conn.getresponse().getheader('Set-Cookie'))
if not cookie.has_key('dbcl2'):
print 'login failed'
thread.exit()
return
dbcl2 = cookie['dbcl2'].value
if dbcl2 and len(dbcl2) > 0:
self.dbcl2 = dbcl2
self.uid = self.dbcl2.split(':')[0]
self.bid = cookie['bid'].value
示例13: test_login
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def test_login(self):
outcookie = Cookie()
# remote_user must be upper case to test that by default, case is
# preserved.
req = Mock(cgi_location='/trac', href=Href('/trac.cgi'),
incookie=Cookie(), outcookie=outcookie,
remote_addr='127.0.0.1', remote_user='john',
authname='john', base_path='/trac.cgi')
self.module._do_login(req)
assert outcookie.has_key('trac_auth'), '"trac_auth" Cookie not set'
auth_cookie = outcookie['trac_auth'].value
self.assertEquals([('john', '127.0.0.1')], self.env.db_query(
"SELECT name, ipnr FROM auth_cookie WHERE cookie=%s",
(auth_cookie,)))
示例14: test_login
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def test_login(self):
outcookie = Cookie()
# remote_user must be upper case to test that by default, case is
# preserved.
req = Mock(cgi_location='/trac', href=Href('/trac.cgi'),
incookie=Cookie(), outcookie=outcookie,
remote_addr='127.0.0.1', remote_user='john', authname='john')
self.module._do_login(req)
assert outcookie.has_key('trac_auth'), '"trac_auth" Cookie not set'
auth_cookie = outcookie['trac_auth'].value
cursor = self.db.cursor()
cursor.execute("SELECT name,ipnr FROM auth_cookie WHERE cookie=%s",
(auth_cookie,))
row = cursor.fetchone()
self.assertEquals('john', row[0])
self.assertEquals('127.0.0.1', row[1])
示例15: is_authenticated
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import has_key [as 别名]
def is_authenticated(self):
if self.username and self.password:
post_data = {
'user': self.username,
'passwd': self.password
}
response = requests.post(LOGIN_URL, data=post_data)
cookie = SimpleCookie()
cookie.load(response.headers.get('set-cookie'))
# The API docs state that is the cookie returned
# contains a reddit_session key only if the auth
# was succesful. Unsuccesful responses will still
# return a cookie, but with a 'reddit_first' key.
if cookie.has_key('reddit_session'):
self.session_key = cookie['reddit_session']
return True
return None