Skip to content

Commit 688fa5d

Browse files
committed
autopep8: next/
1 parent 48d2277 commit 688fa5d

45 files changed

Lines changed: 1642 additions & 1327 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

next/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

next/api/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

next/api/api.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,30 @@
1717
app.register_blueprint(dashboard, url_prefix=dashboard_prefix)
1818
app.register_blueprint(query_page, url_prefix='/query')
1919

20+
2021
@app.context_processor
2122
def inject_global_templatevars():
2223
return dict(next_git_hash=constants.GIT_HASH,
2324
next_version=constants.VERSION)
2425

26+
2527
import logging
2628
import sys
2729
# Log to standard out. Remember to turn off in production
2830
app.logger.addHandler(logging.StreamHandler(sys.stdout))
2931
app.logger.setLevel(logging.DEBUG)
3032

31-
#Handle internal errors using a custom error message
33+
# Handle internal errors using a custom error message
3234
import json
35+
36+
3337
@app.errorhandler(404)
3438
def internal_system_error(error):
35-
response = {
36-
'meta':{
37-
'status':'FAIL',
38-
'code':404,
39-
'message':'Resource not found'
39+
response = {
40+
'meta': {
41+
'status': 'FAIL',
42+
'code': 404,
43+
'message': 'Resource not found'
4044
}
4145
}
4246
return json.dumps(response), 404
43-

next/api/api_blueprint.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@
3535
from next.api.resources.participants import Participants
3636
api_interface.add_resource(Participants,
3737
'/experiment/<string:exp_uid>/participants')
38-

next/api/api_util.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
import time
99

10+
1011
def timeit(f):
1112
"""
1213
Utility used to time the duration of code execution. This script can be composed with any other script.
13-
14+
1415
Usage::\n
1516
def f(n):
1617
return n**n
@@ -25,78 +26,84 @@ def timed(*args, **kw):
2526
ts = time.time()
2627
result = f(*args, **kw)
2728
te = time.time()
28-
if type(result)==tuple:
29-
return result + ((te-ts),)
29+
if type(result) == tuple:
30+
return result + ((te - ts),)
3031
else:
31-
return result,(te-ts)
32+
return result, (te - ts)
3233
return timed
3334

3435

3536
def attach_meta(response, meta, **kwargs):
3637
"""
3738
Attach a meta dictionary to a response dictionary.
38-
39+
3940
Inputs: :\n
40-
(dict) response, (dict) meta, (key-value pairs) kwargs - optional messages to add to mets
41+
(dict) response, (dict) meta, (key-value pairs) kwargs - optional messages to add to mets
4142
4243
Usage: :\n
4344
"""
4445
for k, v in kwargs.iteritems():
4546
meta[k] = v
46-
47+
4748
response["meta"] = meta
4849
return response
4950

51+
5052
verification_error = {
51-
'message':'Failed to Authenticate',
52-
'status':'FAIL',
53-
'code':401
54-
}
53+
'message': 'Failed to Authenticate',
54+
'status': 'FAIL',
55+
'code': 401
56+
}
5557

5658

5759
from flask_restful import Api
58-
import sys, traceback
60+
import sys
61+
import traceback
62+
63+
5964
class NextBackendApi(Api):
6065
"""
6166
Subclass of the default Api class of Flask-Restful with custom error handling for 500 requests
62-
67+
6368
All other errors are passed onto the default handle_error.
6469
"""
70+
6571
def handle_error(self, e, **kwargs):
6672
exc_type, exc_value, tb = sys.exc_info()
67-
backend_error = traceback.format_exc(tb)
68-
print "backend_error", backend_error,exc_type, exc_value, tb, traceback.format_exc(tb)
73+
backend_error = traceback.format_exc(tb)
74+
print "backend_error", backend_error, exc_type, exc_value, tb, traceback.format_exc(tb)
6975

7076
# Catch internal system errors
7177
code = getattr(e, 'code', 500)
72-
if code == 500:
78+
if code == 500:
7379
response = {
74-
'meta':{
80+
'meta': {
7581
'status': 'FAIL',
7682
'code': 500,
7783
'message': 'Internal Server Error',
7884
'backend_error': backend_error
7985
}
8086
}
81-
return self.make_response(response, 500)
82-
return super(NextBackendApi, self).handle_error(e)
83-
87+
return self.make_response(response, 500)
88+
return super(NextBackendApi, self).handle_error(e)
8489

8590

8691
from flask_restful.reqparse import Argument
8792
from flask_restful import abort
8893

94+
8995
class APIArgument(Argument):
9096
"""
9197
Subclass of the standard flask restful Argument class to provide a custom meta message.
9298
Passes up a 400 message if arguments are not correctly parsed.
9399
"""
100+
94101
def __init__(self, *args, **kwargs):
95102
"""
96103
Pass up the default arguments.
97104
"""
98105
super(APIArgument, self).__init__(*args, **kwargs)
99-
106+
100107
def handle_validation_error(self, error, bundle_errors):
101108
"""
102109
Called when an error is raised while parsing. Aborts the request
@@ -110,12 +117,13 @@ def handle_validation_error(self, error, bundle_errors):
110117
msg = '[%s]: %s%s' % (self.name, help_str, str(error))
111118
if bundle_errors:
112119
return error, msg
113-
return abort(400, meta={'message':msg, 'code':400, 'status':'FAIL'})
120+
return abort(400, meta={'message': msg, 'code': 400, 'status': 'FAIL'})
114121

115122

116123
# Custom Exception types for the api. These should just pass.
117124
class DatabaseException(Exception):
118125
pass
119126

127+
120128
class BackendConnectionException(Exception):
121129
pass

next/api/app_handler.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'Error': {
2222
'message': "There was an error calling this API endpoint ",
2323
'code': 400,
24-
'status':'FAIL'
24+
'status': 'FAIL'
2525
}
2626
}
2727

@@ -31,13 +31,13 @@
3131
}
3232

3333

34-
3534
class AppHandler(Resource):
3635
def post(self, exp_uid, function_name):
3736
try:
38-
post_parser.add_argument('exp_uid', type=str, required=True, help="Experiment ID Required.")
39-
post_parser.add_argument('args', type=dict, required=False, help="Experiment args Required.")
40-
37+
post_parser.add_argument(
38+
'exp_uid', type=str, required=True, help="Experiment ID Required.")
39+
post_parser.add_argument(
40+
'args', type=dict, required=False, help="Experiment args Required.")
4141

4242
# Validate args with post_parser
4343
args_data = post_parser.parse_args()
@@ -54,7 +54,8 @@ def post(self, exp_uid, function_name):
5454
# and hit the API with those functions.
5555
# TODO: test this feature
5656
# implemented by Scott Sievert, 2016-1-26
57-
response_json, didSucceed, message = broker.applyAsync(app_id, exp_uid, function_name, args_json)
57+
response_json, didSucceed, message = broker.applyAsync(
58+
app_id, exp_uid, function_name, args_json)
5859

5960
if not didSucceed:
6061
raise Exception(message)

0 commit comments

Comments
 (0)