本文整理汇总了Python中flask.ext.restful.reqparse.RequestParser方法的典型用法代码示例。如果您正苦于以下问题:Python reqparse.RequestParser方法的具体用法?Python reqparse.RequestParser怎么用?Python reqparse.RequestParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.restful.reqparse
的用法示例。
在下文中一共展示了reqparse.RequestParser方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def post(self):
req_parser = reqparse.RequestParser()
req_parser.add_argument('code', type=str, required=True)
req_parser.add_argument('password', type=str, required=True)
args = req_parser.parse_args()
password_reset = db.session.query(PasswordReset
).filter(PasswordReset.code==args['code']
).filter(PasswordReset.date>datetime.now()).first()
if not password_reset:
return CODE_NOT_VALID
password_reset.user.set_password(args['password'])
db.session.delete(password_reset)
db.session.commit()
return {}, 200
示例2: post
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def post(self):
"""
Handle setting the architechture settings.
"""
parser = reqparse.RequestParser()
parser.add_argument('filter_bytes', type=str, required=True,
location='json')
args = parser.parse_args()
ASSEMBLY_STORE.filter_bytes = binascii.unhexlify(args.filter_bytes)
ASSEMBLY_STORE.ClearErrors()
for row in ASSEMBLY_STORE.GetRowsIterator():
ASSEMBLER.CheckOpcodeBytes(row, ASSEMBLY_STORE)
return jsonify(success="1")
示例3: get
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('topic')
parser.add_argument('id')
args = parser.parse_args()
topic = args['topic']
index = 'default'
if "id" in args:
index = args['id']
times, poems, rhyme_words, table_html = get_rhyme_interactive(
topic, index)
d = {}
d['rhyme_words'] = rhyme_words
json_str = json.dumps(d, ensure_ascii=False)
r = make_response(json_str)
sm.clear_status(index)
return r
示例4: get
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('positive', type=str, required=False, help="Positive words.", action='append')
parser.add_argument('negative', type=str, required=False, help="Negative words.", action='append')
parser.add_argument('topn', type=int, required=False, help="Number of results.")
args = parser.parse_args()
pos = filter_words(args.get('positive', []))
neg = filter_words(args.get('negative', []))
t = args.get('topn', 10)
pos = [] if pos == None else pos
neg = [] if neg == None else neg
t = 10 if t == None else t
print "positive: " + str(pos) + " negative: " + str(neg) + " topn: " + str(t)
try:
res = model.most_similar_cosmul(positive=pos,negative=neg,topn=t)
return res
except Exception, e:
print e
print res
示例5: ns_all
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def ns_all():
""" Return all namespaces """
# We do this outside the blueprint to support the case of an empty
# public_id. However, this means the before_request isn't run, so we need
# to make our own session
with global_session_scope() as db_session:
parser = reqparse.RequestParser(argument_class=ValidatableArgument)
parser.add_argument('limit', default=DEFAULT_LIMIT, type=limit,
location='args')
parser.add_argument('offset', default=0, type=int, location='args')
parser.add_argument('email_address', type=bounded_str, location='args')
args = strict_parse_args(parser, request.args)
query = db_session.query(Namespace)
if args['email_address']:
query = query.join(Account)
query = query.filter_by(email_address=args['email_address'])
query = query.limit(args['limit'])
if args['offset']:
query = query.offset(args['offset'])
namespaces = query.all()
encoder = APIEncoder()
return encoder.jsonify(namespaces)
示例6: __init__
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def __init__(self):
super(BasicResource, self).__init__()
self.parser = reqparse.RequestParser()
示例7: post_put_parser
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def post_put_parser():
"""Request parser for HTTP POST or PUT.
:returns: flask.ext.restful.reqparse.RequestParser object
"""
parse = reqparse.RequestParser()
parse.add_argument(
'username', type=str, location='json', required=True)
parse.add_argument(
'password', type=str, location='json', required=True)
return parse
示例8: _post_put_parser
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def _post_put_parser(self):
"""Request parser for HTTP POST or PUT.
:returns: flask.ext.restful.reqparse.RequestParser object
"""
parse = reqparse.RequestParser()
parse.add_argument(
'username', type=str, location='json', required=True)
parse.add_argument(
'password', type=str, location='json', required=True)
return parse
示例9: __init__
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def __init__(self, *args, **kwargs):
RestResource.__init__(self, *args, **kwargs)
self._parser = reqparse.RequestParser()
self._parser.add_argument("name", type=str)
self._parser.add_argument("url", type=str)
示例10: start
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def start():
g.api_version = request.headers.get('Api-Version', API_VERSIONS[0])
if g.api_version not in API_VERSIONS:
g.api_version = API_VERSIONS[0]
if g.api_version == API_VERSIONS[0]:
g.api_features = APIFeatures(optimistic_updates=True)
else:
g.api_features = APIFeatures(optimistic_updates=False)
request.environ['log_context'] = {
'endpoint': request.endpoint,
'api_version': g.api_version,
'namespace_id': g.namespace_id,
}
engine = engine_manager.get_for_id(g.namespace_id)
g.db_session = new_session(engine)
g.namespace = Namespace.get(g.namespace_id, g.db_session)
if not g.namespace:
# The only way this can occur is if there used to be an account that
# was deleted, but the API access cache entry has not been expired yet.
raise AccountDoesNotExistError()
request.environ['log_context']['account_id'] = g.namespace.account_id
if hasattr(g, 'application_id'):
request.environ['log_context']['application_id'] = g.application_id
is_n1 = request.environ.get('IS_N1', False)
g.encoder = APIEncoder(g.namespace.public_id, is_n1=is_n1)
g.parser = reqparse.RequestParser(argument_class=ValidatableArgument)
g.parser.add_argument('limit', default=DEFAULT_LIMIT, type=limit,
location='args')
g.parser.add_argument('offset', default=0, type=offset, location='args')
示例11: put
# 需要导入模块: from flask.ext.restful import reqparse [as 别名]
# 或者: from flask.ext.restful.reqparse import RequestParser [as 别名]
def put(self, row_index):
"""
Edit the values of a row via an HTTP PUT request.
Args:
row_index: an integer index into the assembly store
Returns:
A tuple of http return code and a dictionary to be serialized to JSON
"""
try:
row = ASSEMBLY_STORE.GetRow(row_index)
except AssemblyStoreError:
abort(404)
parser = reqparse.RequestParser()
parser.add_argument('offset', type=int, default=row.offset,
location='json')
parser.add_argument('label', default=row.label, location='json')
parser.add_argument('address', type=str, default=row.address,
location='json')
parser.add_argument('opcode', default=row.opcode, location='json')
parser.add_argument('mnemonic', default=row.mnemonic, location='json')
parser.add_argument('comment', default=row.comment, location='json')
#this defaults to true as adding any data makes a row in use
parser.add_argument('in_use', default=True, location='json')
args = parser.parse_args()
row.offset = args.offset
row.SetLabel(args.label)
row.SetAddress(args.address)
row.SetComment(args.comment)
row.in_use = args.in_use
ASSEMBLY_STORE.UpdateRow(row.index, row)
if str(args.opcode).strip() != row.opcode:
row.SetOpcode(args.opcode)
ASSEMBLY_STORE.UpdateRow(row.index, row)
if row.error:
return row.ToDict()
ASSEMBLER.Disassemble(row.index, ASSEMBLY_STORE)
else:
if args.mnemonic != row.mnemonic or args.mnemonic == '':
if args.mnemonic == '':
# delete the row.
ASSEMBLY_STORE.DeleteRow(row_index)
return row.ToDict()
else:
new_mnemonics = args.mnemonic.split(';')
self.InsertMultipleRowsByMnemonic(row, new_mnemonics)
else:
ASSEMBLY_STORE.UpdateRow(row.index, row)
ASSEMBLER.Assemble(ASSEMBLY_STORE)
row = ASSEMBLY_STORE.GetRow(row.index)
return row.ToDict()