本文整理汇总了Python中web.cookies函数的典型用法代码示例。如果您正苦于以下问题:Python cookies函数的具体用法?Python cookies怎么用?Python cookies使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cookies函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
def POST(self):
web.header("Content-Type","text/html; charset=utf-8")
content = ""
if check_sid(web.cookies().get('sid')):
connrtn = conn()
if (connrtn == None):
try:
num = int(web.input().get('val', None))
except:
content += "Invalid input, assuming 0\n"
num = 0
buf = send_recv(47 * '0')
if (buf[43] == '1'): #input request
res = "Input request #" + str(str_to_num(buf[38:42])) + " : " + str(num)
buf = num_to_str(num) + 10 * '0' + '010'; #set in_ack
send_recv(buf)
buf = num_to_str(num) + 10 * '0' + '000'; #clr in_ack
send_recv(buf)
io_history = open('interaction.txt', 'a')
io_history.write(res + "\n")
io_history.close()
sock.close()
raise web.seeother('/interaction')
else:
content += connrtn
else:
content += "Serving other user.\nACCESS DENIED.\n"
return render.interaction(get_status(), check_sid(web.cookies().get('sid')), content, False, False, '')
示例2: __init__
def __init__(self):
try:
username=web.cookies().user
password=web.cookies().pwd
self.uid=get_isLoginOk(username,password)
except:
raise web.seeother("/login")
示例3: GET
def GET(self, slug):
query = web.input(curpage=1)
curpage = query.curpage
if slug:
article = session.query(Article).filter(Article.slug == slug).first()
comments = article.comments
offset = (curpage - 1) * config.COMMENT_PAGE_LEN
p = divmod(len(comments), config.COMMENT_PAGE_LEN)
if p[1] > 0:
pagecount = p[0] + 1
else:
pagecount = 1
comments = comments[offset : offset + config.COMMENT_PAGE_LEN - 1]
pages = util.pages(
pagecount,
curpage,
10,
"&".join("%s=%s" % (a, b) for a, b in query.items() if a != "curpage") + "#comment",
)
cookie = {
"author": web.cookies(author="").author,
"email": web.cookies(email="").email,
"weburl": web.cookies(weburl="").weburl,
}
return render_blog.article_detail(locals(), self)
else:
return web.notfound("not found the page")
示例4: GET
def GET(self,domain):
domainId = processData.domainInfo(
web.cookies().email,
web.cookies().password,
domain=domain
)#获取域名ID
recordList = processData.recordList(
web.cookies().email,
web.cookies().password,
id=domainId
)#获取记录列表
fileHead = '主机|类型|线路|记录值|MX优先级|TTL'#导出文件的头部
s = ''
s += fileHead + '\n'
for i in recordList:
s += i['name'].encode() + '\t'
s += str(i['type']) + '\t'
s += i['line'].encode('utf-8') + '\t'
s += str(i['value']) + '\t'
s += str(i['mx']) + '\t'
s += str(i['ttl']) + '\n'
web.header('Content-Type','static/txt')
web.header('Content-Disposition',"attachment;filename="+domain+".txt")
return s
示例5: POST
def POST(self):
data = web.input()
username = data.get('username','')
password = data.get('password','')
remember = data.get('remember', '')
if not username or not password:
error_msg = u"用户名或密码不能为空!"
return render.render('auth/login', username=username, error_msg=error_msg)
else:
password = hash_password(password)
if not self.checkUser(username, password):
error_msg = u'用户名或密码错误!'
return render.render('auth/login', username=username, error_msg=error_msg)
else:
web.ctx.session.login = 1
web.ctx.session.username = username
# 记住密码一周
if remember == 'on':
expires = 7 * 24 * 60 * 60
web.setcookie("username", username, expires)
web.setcookie("password", password, expires)
else:
# 如果没有选择记住密码,清除cookie
if web.cookies().get('username'):
web.setcookie("username", username, -1)
if web.cookies().get('password'):
web.setcookie("password", password, -1)
return web.seeother("/")
示例6: POST
def POST(self):
i = web.input()
board_list = [u'校外教育', u'远程办公', u'智慧之门', u'美容美体', u'情感天地',
u'健康管理', u'娱乐人生', u'家政辅导', u'购物天堂', u'职业生涯',
u'社区服务',u'公共信息']
board_id = board_list.index(i.board_id) + 1
x = web.input(upload_pic={})
f = None
if 'upload_pic' in x:
f = x['upload_pic'].value
# upload a file
headers2 = {
'X-Token': web.cookies().get('token')
}
upload_res = requests.post(conf.locate('/attachments/upload'),
data=f,
headers=headers2)
uuid = simplejson.loads(upload_res.text)
uuid = uuid['id']
payload = {
'introduction': i.introduction
}
headers = {
'X-Token': web.cookies().get('token'),
'Content-Type': 'application/json'
}
res = requests.post(conf.locate('/pin/create/%s/%s' % (board_id, uuid)),
data=simplejson.dumps(payload),
headers=headers)
return web.seeother('/controlskip/%s' % board_id)
示例7: POST
def POST(self,balabala):
domainId = processData.domainInfo(
web.cookies().email,
web.cookies().password,
domain=domain_g
)#获取域名ID
x = web.input(myfile={})
count = 0
k = 0
for line in x['myfile'].file:
line = line.split('\t')
count += 1
if count == 1 or line[3] == 'f1g1ns1.dnspod.net.' or line[3] == 'f1g1ns2.dnspod.net.':
k += 1
continue
message = processData.addRecord(
web.cookies().email,#邮箱
web.cookies().password,#密码
domain_id=domainId,#域名ID
sub_domain = line[0],#主机记录
record_type = line[1],#记录类型
route_line = line[2],#线路类型
value = line[3],#记录值
mx = line[4],#MX值
ttl = line[5][:-1]#TTL
)
count -= k
return render.upload(domain_g,msg='成功导入'+str(count)+'条记录,请点击左上角的域名进行查看!')
示例8: checkToken
def checkToken():
un = web.cookies().get('userName')
tk = web.cookies().get('token')
if(un and tk and ses):
if(un == ses.userName and tk == ses.token):
return True
raise web.seeother('/login')
示例9: GET
def GET(self):
cookies = web.cookies()
if cookies.get("session") == None:
web.seeother("http://www.tjhsst.edu/hackathon/login")
templates = web.template.render('webvirt/templates/')
myform = web.form.Form(
web.form.Textbox("name",web.form.notnull,description="Name of Virtual Machine: ",align='left'),
web.form.Textbox("mem",web.form.notnull,web.form.regexp('\d+', 'Must be a digit'),description="Amount of Memory (in KiB): ",align='left'),
web.form.Textbox("cpu",web.form.notnull,web.form.regexp('\d+', 'Must be a digit'),description="Number of Virtual Processors: ",align='left'),
web.form.Textbox("hd",web.form.notnull,description='Full Path to hard drive file: ',align='left'),
web.form.Textbox("iso",web.form.notnull,description="Full Path to cdrom iso file (e.x /var/hackfiles/gentoo.iso): ",align='left'),
web.form.Textbox("vnc",web.form.notnull,description="VNC Port Number: ",align='left'),
web.form.Textbox("pts",web.form.notnull,web.form.regexp('\d+', 'Must be a digit'),description="PTS number for serial console: ",align='left')
)
form = myform()
data = ""
content = "<h2>Create a New VM</h2>"
for dom in conn.listAllDomains(0):
dom = virt.Domain(dom)
if(dom.rawstate == libvirt.VIR_DOMAIN_RUNNING):
data += "<li><a href='/hackathon/vm?vm=" + dom.name + "'>" + dom.name + "<div class='pull-right'><span class='label label-success'>" + dom.state + "</span></div></a></li>"
elif(dom.rawstate == libvirt.VIR_DOMAIN_SHUTOFF):
data += "<li><a href='/hackathon/vm?vm=" + dom.name + "'>" + dom.name + "<div class='pull-right'><span class='label label-important'>" + dom.state + "</span></div></a></li>"
else:
data += "<li><a href='/hackathon/vm?vm=" + dom.name + "'>" + dom.name + "<div class='pull-right'><span class='label label-warning'>" + dom.state + "</span></div></a></li>"
return templates.create(content, data,form,web.cookies().get("session"))
示例10: auth_processor
def auth_processor(handler):
path = web.ctx.path
method = web.ctx.method
if path == '/auth' and (method == 'POST' or method == 'GET'):
return handler()
else:
name = web.cookies().get('user_name')
passwd = web.cookies().get('user_passwd')
if not name or not passwd:
raise RestfulError('570 cookies auth error')
# Note:
# 1. switch system model for develop or release, must auth 'admin' user,
# 'user' user has no permission.
# 2. shutdown or reboot the mechine, must auth the user, only 'admin' can do.
if path in ['/system/shutdown', '/system/reboot'] \
or (path == '/system/startup-mode' and method == 'PUT'):
# check user is 'admin'
if name != 'admin':
raise RestfulError("580 Auth Error: No permission, only admin can do this!")
# filter chinese and other characters
# rule = re.compile("^[\w-]+$")
# if not rule.match(name) or not rule.match(passwd):
# raise RestfulError('570 name or passwd just support [0-9a-zA-Z_-] characters')
ret = auth_user(name, passwd)
if ret:
return handler()
else:
raise RestfulError('570 auth failed')
示例11: POST
def POST(self):
i = web.input()
print "1111111."
print i.board_id
boardlist = ['education', 'remotworking', 'intelligence', 'beauty', 'emotion', 'health_management',
'entertainment', 'Domestic_counseling', 'shopping', 'career', 'community_services',
'public_information']
board_id = boardlist.index(i.board_id) + 1
# buffer
x = web.input(upload_pic={})
f = None
if 'upload_pic' in x:
f = x['upload_pic'].value
# upload a file
headers2 = {
'X-Token': web.cookies().get('token')
}
upload_res = requests.post(conf.locate('/attachments/upload'),
data=f,
headers=headers2)
uuid = simplejson.loads(upload_res.text)
uuid = uuid['id']
payload = {
'introduction': i.introduction
}
headers = {
'X-Token': web.cookies().get('token'),
'Content-Type': 'application/json'
}
res = requests.post(conf.locate('/pin/create/%s/%s' % (board_id, uuid)),
data=simplejson.dumps(payload),
headers=headers)
return web.seeother('/controlskip/%s' % board_id)
示例12: clear_session
def clear_session():
key = web.cookies().get('olin-auth-key')
username = web.cookies().get('olin-auth-username')
if key != None and username != None and verify_username(key, username):
clear_keys(username)
set_auth_cookie('olin-auth-key', "", 60*60*24*30)
set_auth_cookie('olin-auth-username', "", 60*60*24*30)
示例13: GET
def GET(self):
res = requests.get(conf.locate('/user/%s/profile' % web.cookies().get('key')))
present_user = simplejson.loads(res.text)
res = requests.get(conf.locate('/pin/user/%s' % web.cookies().get('key')))
present_user_pin = simplejson.loads(res.text)
pins = [[], [], [], []]
for i, p in enumerate(present_user_pin['pins']):
print "111111111222222"
print p
if p['type'] == 'movie':
res = requests.get(conf.locate('/user/%s/profile' % p['author_id']))
profile = simplejson.loads(res.text)
i %= 4
pin_obj = Pin(p, profile, present_user)
pins[i].append(pin_obj.render_video())
elif p['type'] == 'picture':
res = requests.get(conf.locate('/user/%s/profile' % p['author_id']))
profile = simplejson.loads(res.text)
print profile
i %= 4
pin_obj = Pin(p, profile, present_user)
pins[i].append(pin_obj.render())
headers = {
'X-Token': web.cookies().get('token')
}
res = requests.get(conf.locate('/following/%s' % web.cookies().get('key')), headers=headers)
result = simplejson.loads(res.text)
attentions = []
for attention in result:
attentions.append(str(pure_render.attention_list(attention)))
attentions_len=len(attentions)
return render.usermessage(pins, present_user, attentions,attentions_len)
示例14: GET
def GET(self):
rdio, currentUser = get_rdio_and_current_user()
if rdio and currentUser:
user_id = int(currentUser['key'][1:])
myPlaylists = rdio.call('getPlaylists')['result']['owned']
db = get_db()
result = list(db.select('discoversong_user', what='address, playlist', where="rdio_user_id=%i" % user_id))
if len(result) == 0:
access_token = web.cookies().get('at')
access_token_secret = web.cookies().get('ats')
db.insert('discoversong_user', rdio_user_id=user_id, address=make_unique_email(currentUser), token=access_token, secret=access_token_secret, playlist='new')
result = list(db.select('discoversong_user', what='address, playlist', where="rdio_user_id=%i" % user_id))[0]
else:
result = result[0]
message = ''
if 'saved' in get_input():
message = ' Saved your selections.'
return render.loggedin(name=currentUser['firstName'],
message=message,
to_address=result['address'],
editform=editform(myPlaylists, result['playlist'])
)
else:
return render.loggedout()
示例15: GET
def GET(self):
try:
posts=db.posts
query=posts.find({"user":web.cookies().user})
usuario1 = query[0]["user"]
password1 = query[0]["password"]
nombre1 = query[0]["nombre"]
apellidos1 = query[0]["apellidos"]
correo1 = query[0]["correo"]
dia1 = query[0]["dia"]
mes1 = query[0]["mes"]
anio1 = query[0]["anio"]
direccion1 = query[0]["direccion"]
pago1 = query[0]["pago"]
visa1 = query[0]["visa"]
res="Bienvenido usuario: %s " % (usuario1)
web.setcookie('pagina3', web.cookies().pagina2)
web.setcookie('pagina2', web.cookies().pagina1)
web.setcookie('pagina1', "ver_perfil")
web.header('Content-Type', 'text/html; charset=utf-8')
return plantillas.datos_perfil(formulario=res, mensaje="", usuario = usuario1, password = password1, nombre= nombre1, apellidos=apellidos1, correo=correo1, dia=dia1, mes=mes1, anio=anio1, direccion=direccion1, pago=pago1, visa=visa1)
except:
l=form_log()
web.header('Content-Type', 'text/html; charset=utf-8')
return plantillas.pagina_desconectado(formulario=l.render(), mensaje="Se ha producido algun error. Inicie sesion de nuevo.")