Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_it_should_parse_multiple_arg_required(self):
args = {"foo": fields.List(fields.Int(), required=True)}
request = make_json_request({})
msg = "Missing data for required field."
with pytest.raises(tornado.web.HTTPError, match=msg):
parser.parse(args, request)
from datashader.colors import Hot, viridis
from datashader.bokeh_ext import HoverLayer, create_categorical_legend, create_ramp_legend
from datashader.utils import hold
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler
from webargs import fields
from webargs.tornadoparser import use_args
# http request arguments for datashing HTTP request
ds_args = {
'width': fields.Int(missing=800),
'height': fields.Int(missing=600),
'select': fields.Str(missing=""),
}
class GetDataset(RequestHandler):
"""Handles http requests for datashading."""
@use_args(ds_args)
def get(self, args):
# parse args
selection = args['select'].strip(',').split(',')
xmin, ymin, xmax, ymax = map(float, selection)
self.model.map_extent = [xmin, ymin, xmax, ymax]
glyph = self.model.glyph.get(str(self.model.field), 'points')
'area_ids': fields.List(fields.Int(), required=True)
})
def _process_DELETE(self, area_ids):
delete_areas(area_ids)
return '', 204
'limit': webargs_fields.Int(missing=5),
'certified': webargs_fields.String(
required=True,
validate=webargs_validate.OneOf(('mixed', 'true', 'false'))),
'sort': webargs_fields.String(missing='modified'),
'order': webargs_fields.String(missing='desc')
})
def list_submissions(page, limit, certified, sort, order):
""" List submission IDs associated with the current user """
return list_submissions_handler(page, limit, certified, sort, order)
@use_args(dict(institution_id = List(Int(), missing=None)))
def home(args):
"""
Home page + ranking interface.
"""
facets = utils.bootstrap_facets()
# Bootstrap URL institution(s).
facets['institution'] = utils.institution_facets(
include=args['institution_id']
)
return render_template('home.html', facets=facets)
class AdderHandler(BaseRequestHandler):
"""An addition endpoint."""
add_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}
@use_kwargs(add_args)
def post(self, x, y):
self.write({"result": x + y})
class DateAddHandler(BaseRequestHandler):
"""A date adder endpoint."""
dateadd_args = {
"value": fields.Date(required=False),
"addend": fields.Int(required=True, validate=validate.Range(min=1)),
"unit": fields.Str(
missing="days", validate=validate.OneOf(["minutes", "days"])
),
}
@use_kwargs(dateadd_args)
def post(self, value, addend, unit):
"""A date adder endpoint."""
value = value or dt.datetime.utcnow()
if unit == "minutes":
delta = dt.timedelta(minutes=addend)
else:
delta = dt.timedelta(days=addend)
result = value + delta
self.write({"result": result.isoformat()})
'n_clusters': wfields.Int(missing=-1),
'branching_factor': wfields.Int(missing=20),
'max_tree_depth': wfields.Int(),
# this corresponds approximately to threashold = 0.5
'min_similarity': wfields.Number(missing=0.5),
'metric': wfields.Str(missing='cosine')
}
)
@marshal_with(IDSchema())
def post(self, **args):
from math import sqrt
metric = args.pop('metric')
S_cos = _scale_cosine_similarity(args.pop('min_similarity'),
metric=metric,
inverse=True)
# cosine sim to euclidean distance
pwg = PasswordGenerator()
password_generator_args = {
'minlen': fields.Int(missing=6, validate=lambda val: val > 0),
'maxlen': fields.Int(missing=16, validate=lambda val: val > 0),
'minuchars': fields.Int(missing=1, validate=lambda val: val > 0),
'minuchars': fields.Int(missing=1, validate=lambda val: val > 0),
'minlchars': fields.Int(missing=1, validate=lambda val: val > 0),
'excludeuchars': fields.Str(missing=''),
'excludelchars': fields.Str(missing=''),
'excludenumbers': fields.Str(missing=''),
'excludeschars': fields.Str(missing='')
}
shuffle_password_args = {
'maxlen': fields.Int(required={'message': 'maximum length required', 'code': 400}),
'password': fields.Str(required={'message': 'Password required', 'code': 400})
}
non_duplicate_args = {
'maxlen': fields.Int(required={'message': 'maximum length required', 'code': 400})
}
class PasswordGenerator(Resource):
@use_args(password_generator_args)
def get(self, args):
try:
pwg.__dict__.update(args)
res = pwg.generate()
except Exception as e:
abort(404, str(e))
'room_ids': fields.List(fields.Int(), missing=[]),
'start_date': fields.Date(),
'end_date': fields.Date(),
'reason': fields.Str(),
'allowed_principals': fields.List(fields.Dict())
})
def _process(self, args):
blocking = create_blocking(created_by=session.user, **args)
approve_or_request_blocking(blocking)
return jsonify_data(flash=False)