+def request_arg(key, type, default=None):
+ """Returns the key from the request if available, otherwise the default value.
+ In case type is provided and the key is present, the value is converted by calling type.
+ In other words: Reimplement request.args.get but don't return default value if
+ type raises a ValueError."""
+ if key in request.args:
+ try:
+ return type(request.args[key])
+ except ValueError as e:
+ abort(Response(str(e), 400))
+ else:
+ return default
+
+