Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@falcon.before(testing.set_resp_defaults)
def on_head(self, req, resp, **kwargs):
pass
# Test passing a single extra arg
super(TestFieldResourceChild, self).on_get(req, resp, id)
class TestFieldResourceChildToo(TestFieldResource):
def on_get(self, req, resp, id):
# Test passing a single kwarg, but no extra args
super(TestFieldResourceChildToo, self).on_get(req, resp, id=id)
@falcon.before(bunnies)
@falcon.before(frogs)
@falcon.before(Fish())
@falcon.before(bunnies_in_the_head)
@falcon.before(frogs_in_the_head)
class ZooResource:
def on_get(self, req, resp, bunnies, frogs, fish):
self.bunnies = bunnies
self.frogs = frogs
self.fish = fish
class ZooResourceChild(ZooResource):
def on_get(self, req, resp):
super(ZooResourceChild, self).on_get(
req,
resp,
# Test passing a mixture of args and kwargs
@falcon.before(validate_uuid)
@falcon.before(validate_token)
def on_delete(self, req, resp, book_id):
if [book for book in self.books if book['id'] == book_id]:
self.books[:] = [book for book in self.books if book["id"] != book_id]
resp.status = falcon.HTTP_200
else:
resp.status = falcon.HTTP_NOT_FOUND
@falcon.before(_another_fish.hook)
def on_delete(self, req, resp, fish, itemid):
del self._items[itemid]
resp.set_header('X-Fish-Trait', fish)
resp.status = falcon.HTTP_NO_CONTENT
@falcon.before(header_hook)
@falcon.before(_another_fish.hook)
@falcon.before(header_hook)
def on_delete_collection(self, req, resp, fish):
if fish != 'wet':
raise falcon.HTTPUnavailableForLegalReasons('fish must be wet')
self._items = {}
resp.status = falcon.HTTP_NO_CONTENT
@falcon.before(hooks.client_is_official)
@falcon.before(hooks.origin_client_auth)
def on_get(self, req, resp, origin_client_id):
"""
On a request from an official client, return data about the client.
:param req:
:param resp:
:param origin_client_id:
"""
# Match the client in the database
session = db()
client = session.query(Client).filter_by(client_id=origin_client_id).one_or_none()
# Get the number of users that use it
user_num = len(client.users)
req.context["result"] = {"data":
{"user_num": user_num,
"id": "CLIENT_DATA_FETCHED",
@falcon.before(get_validator('pairing_configuration'))
def on_post(self, req, resp, validated_body):
body = validated_body['pairing_configuration']
api_secret = body['api_secret']
coordinator_uri = body['coordinator_uri']
personality = body['personality']
#start pairing on a separate process
pairing_process = PairingProcess(
api_secret, coordinator_uri, personality)
pairing_process.run()
resp.status = falcon.HTTP_200
@falcon.before(Actions.validate_account_server_access)
def on_get(self, req, resp, account_id):
"""Handles GET requests"""
watched = Actions.get_watched(account_id)
if watched is None:
resp.status = falcon.HTTP_404
return
servers = Actions.get_servers(account_id)
resp.status = falcon.HTTP_200 # This is the default status
json_resp = {'account_id': account_id, 'watched': watched, 'servers': servers}
resp.body = json.dumps(json_resp)
@falcon.before(BaseValidate(postSchema).validate)
def process_login(self, req, resp):
req_data = req.context["data"]
username = req_data["username"]
password = req_data["password"]
try:
user = User.objects.filter(username=username).first()
except redis.exceptions.ConnectionError:
raise errors.DatabaseError(errors.ERR_DATABASE_CONNECTION)
except Exception as e:
_api_logger.info("UsersSelfOperation login ERROR: %s" % e)
self.on_error(resp, errors.ERR_UNKNOWN)
if not user:
raise errors.UnauthorizedError()
_api_logger.debug("password: %s, %s" % (password, user.password))
if not PasswordHash.py_value(user.password).check_password(password):
raise errors.UnauthorizedError()
@falcon.before(read_triples_from_body)
def on_post(self, req, resp, dataset_id, dataset_dto, triples_list):
"""Receives HTTP Request to add triples into the dataset
This will expect an input on the body similar to this
.. sourcecode:: json
[
{ "subject": "Q1492",
"predicate": "P17",
"object": "Q29" },
{ "subject": "Q90",
"predicate": "P17",
"object": "Q142"},
{ "subject": "Q2807",
"predicate": "P17",