Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class HelloHandler(BaseRequestHandler):
"""A welcome page."""
hello_args = {"name": fields.Str(missing="Friend")}
@use_args(hello_args)
def get(self, args):
response = {"message": "Welcome, {}!".format(args["name"])}
self.write(response)
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"])
),
}
{"x": fields.Float(required=True), "y": fields.Float(required=True)},
location="json",
)
async def add(request, x, y):
"""An addition endpoint."""
return JSONResponse({"result": x + y})
from webargs import fields, validate
from webargs.aiohttpparser import use_args, use_kwargs
hello_args = {
'name': fields.Str(missing='Friend')
}
@asyncio.coroutine
@use_args(hello_args)
def index(request, args):
"""A welcome page.
"""
return json_response({'message': 'Welcome, {}!'.format(args['name'])})
add_args = {
'x': fields.Float(required=True),
'y': fields.Float(required=True),
}
@asyncio.coroutine
@use_kwargs(add_args)
def add(request, x, y):
"""An addition endpoint."""
return json_response({'result': x + y})
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']))
}
@asyncio.coroutine
@use_kwargs(dateadd_args)
def dateadd(request, value, addend, unit):
"""A datetime adder endpoint."""
@use_kwargs({'location_id': fields.Int(required=True)})
@use_args(RoomUpdateArgsSchema)
def _process_POST(self, args, location_id):
room = Room()
args['location_id'] = location_id
update_room(room, args)
db.session.add(room)
db.session.flush()
RHRoomsPermissions._jsonify_user_permissions.clear_cached(session.user)
return jsonify(id=room.id)
_base_args = {
'default': fields.Bool(),
'bounds': fields.Nested({
'north_east': fields.Nested({'lat': fields.Float(), 'lng': fields.Float()}, required=True),
'south_west': fields.Nested({'lat': fields.Float(), 'lng': fields.Float()}, required=True)
}, required=True)
}
_create_args = dict(_base_args, **{
'name': fields.String(required=True)
})
_update_args = {
'areas': fields.List(
fields.Nested(dict(_base_args, **{
'id': fields.Int(required=True),
'name': fields.String()
}), required=True)
)
}
from webargs.flaskparser import use_args, use_kwargs
app = Flask(__name__)
hello_args = {"name": fields.Str(missing="Friend")}
@app.route("/", methods=["GET"])
@use_args(hello_args)
def index(args):
"""A welcome page.
"""
return jsonify({"message": "Welcome, {}!".format(args["name"])})
add_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}
@app.route("/add", methods=["POST"])
@use_kwargs(add_args)
def add(x, y):
"""An addition endpoint."""
return jsonify({"result": x + y})
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"])),
}
search_room_args = {
'capacity': fields.Int(),
'equipment': fields.List(fields.Str()),
'favorite': fields.Bool(),
'mine': fields.Bool(),
'text': fields.Str(),
'start_dt': fields.DateTime(),
'end_dt': fields.DateTime(),
'repeat_frequency': EnumField(RepeatFrequency),
'repeat_interval': fields.Int(missing=0),
'building': fields.Str(),
'floor': fields.Str(),
'sw_lat': fields.Float(validate=lambda x: -90 <= x <= 90),
'sw_lng': fields.Float(validate=lambda x: -180 <= x <= 180),
'ne_lat': fields.Float(validate=lambda x: -90 <= x <= 90),
'ne_lng': fields.Float(validate=lambda x: -180 <= x <= 180)
}
_cache = GenericCache('Rooms')
def _serialize_availability(availability):
for data in availability.viewvalues():
data['room'] = rooms_schema.dump(data['room'], many=False).data
data['blockings'] = serialize_blockings(data['blockings'])
data['nonbookable_periods'] = serialize_nonbookable_periods(data['nonbookable_periods'])
data['unbookable_hours'] = serialize_unbookable_hours(data['unbookable_hours'])
data.update({k: serialize_occurrences(data[k]) if k in data else []
for k in ['candidates', 'pre_bookings', 'bookings', 'conflicts', 'pre_conflicts']})
return availability
from webargs import fields, validate
from webargs.pyramidparser import use_args, use_kwargs
hello_args = {"name": fields.Str(missing="Friend")}
@view_config(route_name="hello", request_method="GET", renderer="json")
@use_args(hello_args)
def index(request, args):
"""A welcome page.
"""
return {"message": "Welcome, {}!".format(args["name"])}
add_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}
@view_config(route_name="add", request_method="POST", renderer="json")
@use_kwargs(add_args)
def add(request, x, y):
"""An addition endpoint."""
return {"result": x + y}
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"])),
}
# TODO: Allow storage/retrieval of multiple markets
""" Allows storage/retrieval for custom market data instead of automatic gathering """
from api import api, db
from api.helpers import HTTP_CODES, query_to_dict, validate_db
from api.models.market import Data as DataModel
from flask import abort
from flask_restful import Resource
from webargs import fields
from webargs.flaskparser import use_kwargs
data_kwargs = {
'id': fields.Integer(required=True),
'low': fields.Float(missing=None),
'high': fields.Float(missing=None),
'close': fields.Float(missing=None),
'volume': fields.Float(missing=None)
}
@api.resource('/api/private/market/')
class Data(Resource):
""" Market data at an instance in time """
@use_kwargs({'id': fields.Integer(missing=None)})
@validate_db(db)
def get(self, id):
if id is None:
return [query_to_dict(q) for q in DataModel.query.all()]
else:
return query_to_dict(DataModel.query.get_or_404(id))
@use_kwargs(data_kwargs)
@validate_db(db)
def post(self, id, low, high, close, volume):