elephant_vending_machine.views module

Define all routes for the behavioral experiment server.

Here, all API routes for the experiment server are defined. Consider splitting into its own package if end up being a lot of routes.

elephant_vending_machine.views.allowed_file(filename)[source]

Determines whether an uploaded image file has an allowed extension.

Returns

True if filename includes extension and extension is an allowed extension False otherwise

elephant_vending_machine.views.log()[source]

Returns the specified log file

All requests sent to this route should have a log_name in the query string, otherwise a 400 error will be returned

Returns

HTTP response 200 if log file exists, or HTTP response 500 if it does not.

elephant_vending_machine.views.run_trial()[source]

Responds with ‘Running {trial_name}’ string

All requests sent to this route should have a trial_name in the query string, otherwise a 400 error will be returned

Returns

HTTP response 200 with payload ‘Running {trial_name}’ or HTTP response 400 with payload ‘No trial_name specified’

elephant_vending_machine.views.upload_image()[source]

Return string indicating result of request

Example request:

POST /image HTTP/1.1
Host: 127.0.0.1:5000
Content-Type: multipart/form-data; boundary=--------------------------827430006917349763475527
Accept-Encoding: gzip, deflate, br
Content-Length: 737067
Connection: keep-alive
----------------------------827430006917349763475527
Content-Disposition: form-data; name="file"; filename="elephant.jpeg"

<elephant.jpeg>
----------------------------827430006917349763475527--

Example response:

HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 21
Server: Werkzeug/0.16.1 Python/3.8.1
Date: Thu, 13 Feb 2020 15:35:32 GMT

Success: Image saved.

All requests sent to this route should have an image file included in the body of the request, otherwise a 400 error will be returned

Status 201

file saved

Status 400

malformed request