本文整理汇总了Python中bottle.request.query方法的典型用法代码示例。如果您正苦于以下问题:Python request.query方法的具体用法?Python request.query怎么用?Python request.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.request
的用法示例。
在下文中一共展示了request.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_params
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def get_params():
url = request.query.get('url')
archive = request.query.get('archive')
browser_type = request.query.get('browser', 'chrome')
if not url:
raise HTTPError(status=400, body='No url= specified')
if archive not in theconfig['archives']:
raise HTTPError(status=400, body='No archive {0}'.format(archive))
if not url.startswith(('http://', 'https://')):
url = 'http://' + url
return browser_type, archive, url
示例2: get_token
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def get_token():
# Get JSON Payload
try:
payload = json.load(request.body)
username = payload["username"]
password = payload["password"]
pwhash = _get_password_hash(password)
except:
response.status = 400
return dict({"message":"No valid JSON found in post body or mandatory fields missing."})
user_list = rc.scan_iter("USER:*")
for user in user_list:
user_record = json.loads(rc.get(user))
if user_record["username"] == username and user_record["hash"] == pwhash:
user_token = _issue_token(user=username, id=user[5:], expiry=token_expiry_seconds)
if 'raw' in request.query:
return(user_token)
else:
return(dict(token_type="bearer", access_token=user_token))
response.status = 401
return(dict(info="could not authorize user"))
# Test Auth Token
示例3: index
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def index():
_,images_list = get_samples()
page = 1
if 'p' in request.query:
page = int(request.query['p'])
subm_data = get_all_submissions()
vars = {
'url':url,
'acronym':acronym,
'title':title,
'images':images_list,
'method_params':method_params,
'page':page,
'subm_data':subm_data,
'submit_params':submit_params,
'instructions':instructions,
'extension':gt_ext
}
return template('index',vars)
示例4: gt_image
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def gt_image():
imagesFilePath = os.path.dirname(os.path.abspath(__file__)) + "/gt/gt.zip"
archive = zipfile.ZipFile(imagesFilePath,'r')
fileName = request.query['sample']
ext = fileName.split('.')[-1]
if ext=="jpg":
header = "image/jpeg"
elif ext == "gif":
header = "image/gif"
elif ext == "png":
header = "image/png"
data = archive.read(fileName)
body = data
headers = dict()
headers['Content-Type'] = header
if 'c' in request.query:
headers['Cache-Control'] = "public, max-age=3600"
return HTTPResponse(body, **headers)
示例5: subm_image
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def subm_image():
submFilePath = os.path.dirname(os.path.abspath(__file__)) + "/output/subm_" + str(request.query['m']) + ".zip"
archive = zipfile.ZipFile(submFilePath,'r')
fileName = request.query['sample']
ext = fileName.split('.')[-1]
if ext=="jpg":
header = "image/jpeg"
elif ext == "gif":
header = "image/gif"
elif ext == "png":
header = "image/png"
data = archive.read(fileName)
body = data
headers = dict()
headers['Content-Type'] = header
if 'c' in request.query:
headers['Cache-Control'] = "public, max-age=3600"
return HTTPResponse(body, **headers)
示例6: db_search
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def db_search(query,type=None):
if type=="ARTIST":
results = []
for a in ARTISTS:
#if query.lower() in a.lower():
if simplestr(query) in simplestr(a):
results.append(a)
if type=="TRACK":
results = []
for t in TRACKS:
#if query.lower() in t[1].lower():
if simplestr(query) in simplestr(t[1]):
results.append(get_track_dict(t))
return results
####
## Useful functions
####
# makes a string usable for searching (special characters are blanks, accents and stuff replaced with their real part)
示例7: file
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def file():
print('[bottle] url: /upload')
print('[bottle] query:', request.query.keys())
print('[bottle] forms:', request.forms.keys())
print('[bottle] files:', request.files.keys())
files = request.files.getall('file')
print('[bottle] files:', files)
save_path = "./save_file"
if not os.path.exists(save_path):
os.mkdir(save_path)
File(files).start()
print('[bottle] redirect: /')
redirect('/')
# print('after redirect') # never executed
示例8: _authenticate
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def _authenticate():
# Token can be in query string or AUTH header
if 'token' in request.query:
access_token = request.query["token"]
else:
bearer = request.environ.get('HTTP_AUTHORIZATION','')
access_token=bearer[7:]
# Extract the data from the token
data = _get_token_data(token=access_token)
# If there was an error, end here
if data["error"] != "0":
return(dict(data))
# Was the token issued by this cluster?
if data["cluster_id"] != cluster_id:
return(dict(data))
# Is the access token still valid?
token_timestamp = data["timestamp"]
current_time = int(time.time())
delta = current_time - token_timestamp
if delta > token_expiry_seconds:
# expired
data["authenticated"] = "False"
data["info"] = "Token expired"
else:
# valid
data["authenticated"] = "True"
data["info"] = "Session expires in " + str(token_expiry_seconds - delta) + " seconds."
# Set response header: username
response.headers["B9Y-AUTHENTICATED-USER"] = data["user"]
return(dict(data))
示例9: _get_elements
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def _get_elements(self):
query = request.query
include_data = query.get('include_data', '').lower() == 'true'
include_props = query.get('include_props', '').lower() == 'true'
return {
'elements': {
eid: self._get_element(eid, include_data=include_data, include_props=include_props)
for eid in self._registry.elements
}
}
示例10: method
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def method():
_,images_list = get_samples()
results = None
page = 1
subm_data = {}
if 'm' in request.query:
id = request.query['m']
submFilePath = os.path.dirname(os.path.abspath(__file__)) + "/output/results_" + id + ".zip"
if os.path.isfile(submFilePath):
results = zipfile.ZipFile(submFilePath,'r')
if 'p' in request.query:
page = int(request.query['p'])
subm_data = get_submission(id)
if results is None or subm_data is None:
redirect('/')
else:
redirect('/')
vars = {
'url':url,
'acronym':acronym,
'title':title,
'images':images_list,
'method_params':method_params,
'sample_params':sample_params,
'results':results,
'page':page,
'subm_data':subm_data
}
return template('method',vars)
示例11: get_sample_info
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def get_sample_info():
methodId = request.query['m']
submFilePath = os.path.dirname(os.path.abspath(__file__)) + "/output/results_" + methodId + ".zip"
archive = zipfile.ZipFile(submFilePath,'r')
id = get_sample_id_from_num(int(request.query['sample']))
results = json.loads(archive.read(id + ".json"))
return json.dumps(results)
示例12: image_thumb
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def image_thumb():
sample = int(request.query['sample'])
fileName,data = get_sample_from_num(sample)
ext = fileName.split('.')[-1]
f = BytesIO(data)
image = Image.open(f)
maxsize = (205, 130)
image.thumbnail(maxsize)
output = BytesIO()
if ext=="jpg":
im_format = "JPEG"
header = "image/jpeg"
image.save(output,im_format, quality=80, optimize=True, progressive=True)
elif ext == "gif":
im_format = "GIF"
header = "image/gif"
image.save(output,im_format)
elif ext == "png":
im_format = "PNG"
header = "image/png"
image.save(output,im_format, optimize=True)
contents = output.getvalue()
output.close()
body = contents
headers = dict()
headers['Content-Type'] = header
if 'c' in request.query:
headers['Cache-Control'] = "public, max-age=3600"
return HTTPResponse(body, **headers)
示例13: gt_file
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def gt_file():
imagesFilePath = os.path.dirname(os.path.abspath(__file__)) + "/gt/gt.zip"
archive = zipfile.ZipFile(imagesFilePath,'r')
fileName = request.query['sample']
ext = fileName.split('.')[-1]
if ext=="xml":
header = "text/xml"
data = archive.read(fileName)
body = data
headers = dict()
headers['Content-Type'] = header
if 'c' in request.query:
headers['Cache-Control'] = "public, max-age=3600"
return HTTPResponse(body, **headers)
示例14: gt_video
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def gt_video():
imagesFilePath = os.path.dirname(os.path.abspath(__file__)) + "/gt/images.zip"
archive = zipfile.ZipFile(imagesFilePath,'r')
fileName = request.query['sample']
ext = fileName.split('.')[-1]
header = "video/mp4"
data = archive.read(fileName)
body = data
headers = dict()
headers['Content-Type'] = header
if 'c' in request.query:
headers['Cache-Control'] = "public, max-age=3600"
return HTTPResponse(body, **headers)
示例15: subm_xml
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import query [as 别名]
def subm_xml():
submFilePath = os.path.dirname(os.path.abspath(__file__)) + "/output/subm_" + str(request.query['m']) + ".zip"
archive = zipfile.ZipFile(submFilePath,'r')
fileName = request.query['sample']
header = "text/xml"
data = archive.read(fileName)
body = data
headers = dict()
headers['Content-Type'] = header
if 'c' in request.query:
headers['Cache-Control'] = "public, max-age=3600"
return HTTPResponse(body, **headers)