Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _update_viewarg(self, name, choices):
''' Updates the global View arguments validator '''
viewargs[name] = fields.String(required=True, location='view_args', validate=validate.OneOf(choices))
# viewargs[name].validate = validate.OneOf(choices)
def _set_params_required(self, subset):
''' Set the param validation required parameter '''
# make list or not
self._required = [self._required] if not isinstance(self._required, (list, tuple)) else self._required
# update the required attribute
for req_param in self._required:
if req_param in subset.keys():
subset[req_param].required = True
subset[req_param].allow_none = False
if req_param == 'bintemp':
bintemps = self._get_bin_temps()
subset[req_param].validate = validate.OneOf(bintemps)
subset[req_param].validators.append(validate.OneOf(bintemps))
return subset
add_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}
@use_kwargs(add_args)
def post(self, x, y):
"""An addition endpoint."""
return {"result": x + y}
class DateAddResource(Resource):
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
return {"result": result.isoformat()}
# This error handler is necessary for usage with Flask-RESTful
validate.Regexp('^[0-9-]*$')]),
'galid': fields.String(required=True, location='view_args', validate=[validate.Length(min=4),
validate.Regexp('^[0-9-]*$')]),
'bintype': fields.String(required=True, location='view_args'),
'template': fields.String(required=True, location='view_args'),
'property_name': fields.String(required=True, location='view_args'),
'channel': fields.String(required=True, location='view_args'),
'binid': fields.Integer(required=True, location='view_args', validate=validate.Range(min=-1, max=5800)),
'plateid': fields.String(required=True, location='view_args', validate=[validate.Length(min=4, max=5),
plate_in_range]),
'x': fields.Integer(required=True, location='view_args', validate=validate.Range(min=0, max=100)),
'y': fields.Integer(required=True, location='view_args', validate=validate.Range(min=0, max=100)),
'mangaid': fields.String(required=True, location='view_args', validate=validate.Length(min=4, max=20)),
'paramdisplay': fields.String(required=True, location='view_args', validate=validate.OneOf(['all', 'best'])),
'cube_extension': fields.String(required=True, location='view_args',
validate=validate.OneOf(['flux', 'ivar', 'mask',
'disp', 'predisp',
'specres', 'specresd',
'prespecres',
'prespecresd'])),
'modelcube_extension': fields.String(required=True, location='view_args',
validate=validate.OneOf(['flux', 'ivar', 'mask',
'model', 'emline',
'emline_base',
'emline_mask'])),
'colname': fields.String(required=True, location='view_args', allow_none=True),
'fiberid': fields.Integer(required=True, location='view_args',
validate=validate.Range(min=-1, max=5800)),
}
# List of all form parameters that are needed in all the API routes
# allow_none = True allows for the parameter to be non-existent when required=False and missing is not set
def _set_params_required(self, subset):
''' Set the param validation required parameter '''
# make list or not
self._required = [self._required] if not isinstance(self._required, (list, tuple)) else self._required
# update the required attribute
for req_param in self._required:
if req_param in subset.keys():
subset[req_param].required = True
subset[req_param].allow_none = False
if req_param == 'bintemp':
bintemps = self._get_bin_temps()
subset[req_param].validate = validate.OneOf(bintemps)
subset[req_param].validators.append(validate.OneOf(bintemps))
return subset