本文整理匯總了Python中bottle.request.forms方法的典型用法代碼示例。如果您正苦於以下問題:Python request.forms方法的具體用法?Python request.forms怎麽用?Python request.forms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bottle.request
的用法示例。
在下文中一共展示了request.forms方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: key_auth
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def key_auth(name=""):
"""Authenticates a API key."""
if 'secret' in request.forms:
secret = request.forms["secret"]
elif 'X-Lokun-Secret' in request.headers:
secret = request.headers["X-Lokun-Secret"]
else:
abort(401, "Must include a secret")
try:
return model.APIKey.auth(secret, name=name)
except ValueError:
log("Not accepted: " + repr(request.forms['secret']))
abort(403, "Secret not accepted")
# ------------
# /users/
# ------------
示例2: vpn_report
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def vpn_report(name):
keyinfo= key_auth()
user = model.User.get(name)
if not 'dl' in request.forms:
abort(400, "Must include dl")
dl = int(request.forms['dl'])
if dl < 0:
abort(400, "dl must be >= 0")
user.dl_left = user.dl_left - dl
if user.dl_left < 0:
logger.email("dl_finished: " + ",".join(user.username, user.sub_end))
user.save()
log("Report for a user recieved (user disconnected from {0})".format(keyinfo.name))
return {}
#----------
# /nodes/
#----------
示例3: dalpay
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def dalpay():
# Since deciding to create lokun-billing, this got a
# bit.. hacky.
try:
passwd = request.forms["SilentPostPassword"]
if not sec.compare(passwd, config.dalpay_passwd):
log("DalPay: Invalid SilentPostPassword")
abort(401, "Unauthorized")
message = request.forms["user1"]
dalpay = DalPay.read(message, key=config.dalpay_key)
cardtype = request.forms["pay_type"]
fees = calculate_fees(cardtype, dalpay.amount)
model.Deposit.new(dalpay.username, dalpay.amount, cardtype,
vsk=25.5, fees=fees, deposit=True)
logger.email("DalPay: {0},{1}".format(dalpay.username, dalpay.amount))
return config.dalpay_return
except ValueError as ve:
logger.email("DalPay: " + str(ve))
# Do i need to log something more? BK 22.03.2014
return "<!-- error: {0} -->".format(str(ve))
示例4: search_functions
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def search_functions(self):
try:
requested_sources = request.forms.getall('sources[]')
if not len(requested_sources):
requested_sources = None
items, full_report = self.interactive.search_for_functions(request.forms.get('terms'), requested_sources)
items_unique = set([])
for search_term in items:
items_unique = items_unique.union(set(items[search_term]))
return json.dumps({'status': 0, 'results': full_report, 'item_count': len(items_unique)})
except Exception as e:
message = str(e.clear_text()) if hasattr(e, 'clear_text') else str(e)
return json.dumps({'status': 1, 'message': message})
示例5: reroot_tree
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def reroot_tree(self):
newick = request.forms.get('newick')
tree = Tree(newick, format=1)
left_most = tree.search_nodes(name=request.forms.get('left_most'))[0]
right_most = tree.search_nodes(name=request.forms.get('right_most'))[0]
new_root = tree.get_common_ancestor(left_most, right_most)
tree.set_outgroup(new_root)
# Ete3 tree.write function replaces some charachters that we support in the interface.
# As a workaround we are going to encode node names with base32, after serialization
# we are going to decode them back.
for node in tree.traverse('preorder'):
node.name = 'base32' + base64.b32encode(node.name.encode('utf-8')).decode('utf-8')
new_newick = tree.write(format=1)
# ete also converts base32 padding charachter "=" to "_" so we need to replace it.
new_newick = re.sub(r"base32(\w*)", lambda m: base64.b32decode(m.group(1).replace('_','=')).decode('utf-8'), new_newick)
return json.dumps({'newick': new_newick})
示例6: get_taxonomy
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def get_taxonomy(self):
collection = json.loads(request.forms.get('collection'))
if not self.scg_taxonomy:
message = "You first need to run `anvi-run-scg-taxonomy` on your contigs database for this to work :("
run.warning(message)
return json.dumps({'status': 1, 'message': message})
output = {}
try:
for bin_name in collection:
output[bin_name] = self.scg_taxonomy.estimate_for_list_of_splits(collection[bin_name], bin_name=bin_name)
run.info_single('Taxonomy estimation has been requested for bin(s) "%s".' % (", ".join(collection.keys())))
except Exception as e:
message = str(e.clear_text()) if hasattr(e, 'clear_text') else str(e)
return json.dumps({'status': 1, 'message': message})
return json.dumps(output)
示例7: routes
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def routes(self):
@self.www.route('/')
def index():
return static_file('index.html', root=join(self.here,"www/"))
@self.www.post('/show-text/')
def show_text():
color = (0,255,0)
if 'message' in request.forms:
if 'color' in request.forms:
color = tuple([int(i) for i in request.forms.color.split(",")])
background = tuple([int(i) for i in request.forms.background.split(",")])
self.send_text(request.forms.message,color,background)
print 'Your message %s! In color %s</b>' % (request.forms.message, color)
@self.www.post('/show-image/')
def show_image():
self.send_image(request.forms.url)
print 'image URL: %s' % (request.forms.url)
@self.www.get('/static/<filename:path>')
def send_static(filename):
return static_file(filename, root=join(self.here,"www/"))
示例8: _add_logger_by_name
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def _add_logger_by_name(self, name):
''' Handles POST requests for adding a new logger.
Expects logger configuration to be passed in the request's query string.
The logger name is included in the URL and the address components and
connection type should be included as well. The loc attribute is
defaulted to "localhost" when making the socket connection if not
defined.
loc = IP / interface
port = port / protocol
conn_type = udp or ethernet
Raises:
ValueError:
if the port or connection type are not supplied.
'''
data = dict(request.forms)
loc = data.pop('loc', '')
port = data.pop('port', None)
conn_type = data.pop('conn_type', None)
if not port or not conn_type:
e = 'Port and/or conn_type not set'
raise ValueError(e)
address = [loc, int(port)]
if 'rotate_log' in data:
data['rotate_log'] = True if data == 'true' else False
if 'rotate_log_delta' in data:
data['rotate_log_delta'] = int(data['rotate_log_delta'])
self._logger_manager.add_logger(name, address, conn_type, **data)
示例9: auth
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def auth(name):
if not 'password' in request.forms:
abort(400, "Must include a password")
try:
return model.User.auth(name, request.forms['password'])
except ValueError as e:
abort(errstatus(e), e.message)
示例10: putuser
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def putuser(name):
if not 'password' in request.forms:
abort(400, "Must include a password")
if model.User.exists(name):
try:
user = auth(name)
if request.forms.newpassword:
user.set_passwd(request.forms['newpassword'])
if request.forms.email:
user.email = request.forms.email
except ValueError as e:
errstatus(e)
log(str(e))
return {'error': e.message}
else:
try:
user = model.User.new(name, request.forms['password'],
request.forms.invite_key,
email=request.forms.email)
log("Created a new user")
# temporarily added for fun and profit
if request.forms.invite_key:
logger.email("Invite key used: " + request.forms.invite_key)
except ValueError as e:
errstatus(e)
log(str(e))
return {'error': e.message}
return dict(user)
示例11: putisk
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def putisk(name):
key_auth("billing")
if 'isk' not in request.forms:
abort(400, "Must include 'isk'")
try:
user = model.User.get(name)
isk = int(request.forms.isk)
user.credit_isk += isk
user.save()
return str(user.credit_isk)
except ValueError as ve:
abort(errstatus(ve), ve.message)
示例12: postusers
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def postusers():
if not 'username' in request.forms:
abort(400, "Must include a username")
name = request.forms.username
return putuser(name)
# -------------
# /vpn/
# -------------
示例13: node_auth
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def node_auth(name):
"""Authorizes and _Authenticates_ a VPN node.
Used when a node reports its health Used for correctness,
a VPN node can only report its own health."""
if not 'secret' in request.forms:
abort(400, "Must include a secret")
try:
return model.Node.auth(name, request.forms['secret'])
except ValueError as e:
abort(errstatus(e), e.message)
示例14: postnode
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def postnode(name):
node = node_auth(name)
old_usercount = int(node.usercount)
old_total = int(node.total_throughput) # deep copy
try:
# coercing the types since sqlite doesn't give a shit
# about types
node.update(usercount = int(request.forms['usercount']),
selfcheck = bool(request.forms['selfcheck'].lower() == "true"),
throughput = int(request.forms['throughput']),
total_throughput = int(request.forms.total_throughput),
uptime = request.forms.uptime,
cpu = float(request.forms['cpu']))
log("Updated {0}".format(node.name))
if node.within_limit and old_total < node.throughput_limit:
message = "throughput_limit: {0}, {1} GB\n\n{2}"
pretty = pformat(dict(node))
logger.email(message.format(node.name, node.total_throughput, pretty))
return {'status': 'ok',
'userdiff': node.usercount - old_usercount,
'score': node.score,
'heartbeat': node.heartbeat}
except (ValueError, KeyError) as error:
abort(400, str(error))
示例15: putnode
# 需要導入模塊: from bottle import request [as 別名]
# 或者: from bottle.request import forms [as 別名]
def putnode(name):
if 'ip' not in request.forms:
abort(400, "Must include IP address")
if model.Node.exists(name):
try:
node = node_auth(name)
node.ip = request.forms["ip"]
node.save()
log("Changed IP for a node")
return dict(node)
except ValueError as e:
errstatus(e)
return {'error': e.message}
else:
try:
is_exit = request.forms.is_exit.lower() == "true"
max_t = int(request.forms.max_throughput or 0)
node = model.Node.new(name, request.forms["ip"], is_exit, max_t)
apikey = model.APIKey.new(name, status="new")
log("Created a new node: {0}. API key status set to 'new'".format(name))
return dict({'secret': apikey.key}, **dict(node))
except ValueError as e:
errstatus(e)
return {'error': e.message}
return {}
# ---------------
# /exits/
# ---------------