Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'booking_reason': fields.String(load_from='reason', validate=validate.Length(min=3)),
'is_prebooking': fields.Bool(missing=False)
})
def _process(self, args):
room = Room.get_one(args.pop('room_id'))
user_id = args.pop('user_id', None)
booked_for = User.get_one(user_id) if user_id else session.user
is_prebooking = args.pop('is_prebooking')
# Check that the booking is not longer than allowed
booking_limit_days = room.booking_limit_days or rb_settings.get('booking_limit')
if not self._validate_room_booking_limit(args['start_dt'], args['end_dt'], booking_limit_days):
msg = (_('Bookings for the room "{}" may not be longer than {} days')
.format(room.name, booking_limit_days))
return jsonify(success=False, msg=msg)
try:
from gevent import monkey
from IdentityCard import IdentityCard
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding)
monkey.patch_all()
app = Flask(__name__)
cls = IdentityCard()
cls.initialize_areas()
req_args = {
'num': fields.Int(missing=1, validate=validate.Range(min=1, max=50)),
'min': fields.Int(missing=0, validate=validate.Range(min=0, max=100)),
'max': fields.Int(missing=100, validate=validate.Range(min=0, max=100)),
'sex': fields.Int(missing=0, validate=validate.Range(min=0, max=2)),
'year': fields.Int(validate=validate.Range(min=1900, max=dt.datetime.now().year)),
'month': fields.Int(validate=validate.Range(min=1, max=12)),
'day': fields.Int(validate=validate.Range(min=1, max=31))
}
@app.route('/api', methods=['GET'])
@use_kwargs(req_args)
def api_identidycard(num, min, max, sex, year, month, day):
ret = cls.generator(num, min, max, sex, year, month, day)
tmp = []
for r in ret:
tmp.append({'name': r[0], 'id': r[1], 'birthday': r[2], 'age': r[3], 'sex': r[4], 'address': r[5]})
'comment': fields.String(validate=validate.Length(min=1)),
'visibility': EnumField(PaperCommentVisibility, required=True)
})
def _process(self, comment, visibility):
create_comment(self.paper, comment, visibility, session.user)
return '', 204
adder_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}
@use_kwargs(adder_args)
def on_post(self, req, resp, x, y):
req.context["result"] = {"result": x + y}
class DateAddResource(object):
"""A datetime 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"])
),
}
@falcon.before(add_args(dateadd_args))
def on_post(self, req, resp):
"""A datetime adder endpoint."""
args = req.context["args"]
value = args["value"] or dt.datetime.utcnow()
if args["unit"] == "minutes":
delta = dt.timedelta(minutes=args["addend"])
else:
delta = dt.timedelta(days=args["addend"])
result = value + delta
req.context["result"] = {"result": result.isoformat()}
decoding_class = PartnersPerToken
class PartnersPerTokenListSchema(BaseListSchema):
data = fields.Nested(PartnersPerTokenSchema, many=True)
class Meta:
strict = True
decoding_class = PartnersPerTokenList
class MintTokenSchema(BaseSchema):
to = AddressField(required=True)
value = IntegerToStringField(required=True, validate=validate.Range(min=1, max=UINT256_MAX))
contract_method = fields.String(
validate=validate.OneOf(choices=("increaseSupply", "mint", "mintFor"))
)
class Meta:
strict = True
decoding_class = dict
class ChannelStateSchema(BaseSchema):
channel_identifier = IntegerToStringField(attribute="identifier")
token_network_address = AddressField()
token_address = AddressField()
partner_address = fields.Method("get_partner_address")
settle_timeout = IntegerToStringField()
reveal_timeout = IntegerToStringField()
balance = fields.Method("get_balance")
state = fields.Method("get_state")
class Meta:
strict = True
decoding_class = PartnersPerToken
class PartnersPerTokenListSchema(BaseListSchema):
data = fields.Nested(PartnersPerTokenSchema, many=True)
class Meta:
strict = True
decoding_class = PartnersPerTokenList
class MintTokenSchema(BaseSchema):
to = AddressField(required=True)
value = IntegerToStringField(required=True, validate=validate.Range(min=1, max=UINT256_MAX))
contract_method = fields.String(
validate=validate.OneOf(choices=("increaseSupply", "mint", "mintFor"))
)
class Meta:
strict = True
decoding_class = dict
class ChannelStateSchema(BaseSchema):
channel_identifier = IntegerToStringField(attribute="identifier")
token_network_address = AddressField()
token_address = AddressField()
partner_address = fields.Method("get_partner_address")
settle_timeout = IntegerToStringField()
reveal_timeout = IntegerToStringField()
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."""
value = value or dt.datetime.utcnow()
if unit == 'minutes':
delta = dt.timedelta(minutes=addend)
else:
delta = dt.timedelta(days=addend)
result = value + delta
return json_response({'result': result.isoformat()})
def create_app():
app = web.Application()
'limit': fields.Integer(required=False, missing=10, validate=validate.Range(1, 10)),
})
def get_user_tips(args, **kwargs):
user = User.query.get(args['user_id'])
if not user:
raise RequestError(code=404, message='No user with that ID')
tips = Tip.query \
.filter_by(receiver_id=user.id) \
.filter(Tip.amount != None ) \
.filter(Tip.amount != 0) \
.order_by(Tip.date_created.desc()) \
.paginate(
page=args['page'],
per_page=args['limit'],
error_out=False)
return jsonify({
validate=webargs_validate.OneOf(('D1', 'D2', 'E', 'F'), error="Must be either D1, D2, E or F"))
})
def check_generation_status(submission, file_type):
""" Return status of file generation job
Attributes:
submission: submission for which we're generating the file
file_type: type of file to check the status of
"""
return generation_handler.check_generation(submission, file_type)
"""
return {"message": "Welcome, {}!".format(args["name"])}
add_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}
@route("/add", method="POST", apply=use_kwargs(add_args))
def add(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"])),
}
@route("/dateadd", method="POST", apply=use_kwargs(dateadd_args))
def dateadd(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()}