Skip to content

Commit b6b92d5

Browse files
author
Sergey Vilgelm
committed
Using black formatting
Run `black .` to format the current code with black
1 parent 0d0b8f6 commit b6b92d5

Some content is hidden

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

55 files changed

+7819
-7698
lines changed

doc/conf.py

+134-124
Large diffs are not rendered by default.

examples/todo.py

+39-33
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,87 @@
44

55
app = Flask(__name__)
66
app.wsgi_app = ProxyFix(app.wsgi_app)
7-
api = Api(app, version='1.0', title='Todo API',
8-
description='A simple TODO API',
9-
)
7+
api = Api(app, version="1.0", title="Todo API", description="A simple TODO API",)
108

11-
ns = api.namespace('todos', description='TODO operations')
9+
ns = api.namespace("todos", description="TODO operations")
1210

1311
TODOS = {
14-
'todo1': {'task': 'build an API'},
15-
'todo2': {'task': '?????'},
16-
'todo3': {'task': 'profit!'},
12+
"todo1": {"task": "build an API"},
13+
"todo2": {"task": "?????"},
14+
"todo3": {"task": "profit!"},
1715
}
1816

19-
todo = api.model('Todo', {
20-
'task': fields.String(required=True, description='The task details')
21-
})
17+
todo = api.model(
18+
"Todo", {"task": fields.String(required=True, description="The task details")}
19+
)
2220

23-
listed_todo = api.model('ListedTodo', {
24-
'id': fields.String(required=True, description='The todo ID'),
25-
'todo': fields.Nested(todo, description='The Todo')
26-
})
21+
listed_todo = api.model(
22+
"ListedTodo",
23+
{
24+
"id": fields.String(required=True, description="The todo ID"),
25+
"todo": fields.Nested(todo, description="The Todo"),
26+
},
27+
)
2728

2829

2930
def abort_if_todo_doesnt_exist(todo_id):
3031
if todo_id not in TODOS:
3132
api.abort(404, "Todo {} doesn't exist".format(todo_id))
3233

34+
3335
parser = api.parser()
34-
parser.add_argument('task', type=str, required=True, help='The task details', location='form')
36+
parser.add_argument(
37+
"task", type=str, required=True, help="The task details", location="form"
38+
)
3539

3640

37-
@ns.route('/<string:todo_id>')
38-
@api.doc(responses={404: 'Todo not found'}, params={'todo_id': 'The Todo ID'})
41+
@ns.route("/<string:todo_id>")
42+
@api.doc(responses={404: "Todo not found"}, params={"todo_id": "The Todo ID"})
3943
class Todo(Resource):
40-
'''Show a single todo item and lets you delete them'''
41-
@api.doc(description='todo_id should be in {0}'.format(', '.join(TODOS.keys())))
44+
"""Show a single todo item and lets you delete them"""
45+
46+
@api.doc(description="todo_id should be in {0}".format(", ".join(TODOS.keys())))
4247
@api.marshal_with(todo)
4348
def get(self, todo_id):
44-
'''Fetch a given resource'''
49+
"""Fetch a given resource"""
4550
abort_if_todo_doesnt_exist(todo_id)
4651
return TODOS[todo_id]
4752

48-
@api.doc(responses={204: 'Todo deleted'})
53+
@api.doc(responses={204: "Todo deleted"})
4954
def delete(self, todo_id):
50-
'''Delete a given resource'''
55+
"""Delete a given resource"""
5156
abort_if_todo_doesnt_exist(todo_id)
5257
del TODOS[todo_id]
53-
return '', 204
58+
return "", 204
5459

5560
@api.doc(parser=parser)
5661
@api.marshal_with(todo)
5762
def put(self, todo_id):
58-
'''Update a given resource'''
63+
"""Update a given resource"""
5964
args = parser.parse_args()
60-
task = {'task': args['task']}
65+
task = {"task": args["task"]}
6166
TODOS[todo_id] = task
6267
return task
6368

6469

65-
@ns.route('/')
70+
@ns.route("/")
6671
class TodoList(Resource):
67-
'''Shows a list of all todos, and lets you POST to add new tasks'''
72+
"""Shows a list of all todos, and lets you POST to add new tasks"""
73+
6874
@api.marshal_list_with(listed_todo)
6975
def get(self):
70-
'''List all todos'''
71-
return [{'id': id, 'todo': todo} for id, todo in TODOS.items()]
76+
"""List all todos"""
77+
return [{"id": id, "todo": todo} for id, todo in TODOS.items()]
7278

7379
@api.doc(parser=parser)
7480
@api.marshal_with(todo, code=201)
7581
def post(self):
76-
'''Create a todo'''
82+
"""Create a todo"""
7783
args = parser.parse_args()
78-
todo_id = 'todo%d' % (len(TODOS) + 1)
79-
TODOS[todo_id] = {'task': args['task']}
84+
todo_id = "todo%d" % (len(TODOS) + 1)
85+
TODOS[todo_id] = {"task": args["task"]}
8086
return TODOS[todo_id], 201
8187

8288

83-
if __name__ == '__main__':
89+
if __name__ == "__main__":
8490
app.run(debug=True)

examples/todo_blueprint.py

+40-34
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,91 @@
11
from flask import Flask, Blueprint
22
from flask_restx import Api, Resource, fields
33

4-
api_v1 = Blueprint('api', __name__, url_prefix='/api/1')
4+
api_v1 = Blueprint("api", __name__, url_prefix="/api/1")
55

6-
api = Api(api_v1, version='1.0', title='Todo API',
7-
description='A simple TODO API',
8-
)
6+
api = Api(api_v1, version="1.0", title="Todo API", description="A simple TODO API",)
97

10-
ns = api.namespace('todos', description='TODO operations')
8+
ns = api.namespace("todos", description="TODO operations")
119

1210
TODOS = {
13-
'todo1': {'task': 'build an API'},
14-
'todo2': {'task': '?????'},
15-
'todo3': {'task': 'profit!'},
11+
"todo1": {"task": "build an API"},
12+
"todo2": {"task": "?????"},
13+
"todo3": {"task": "profit!"},
1614
}
1715

18-
todo = api.model('Todo', {
19-
'task': fields.String(required=True, description='The task details')
20-
})
16+
todo = api.model(
17+
"Todo", {"task": fields.String(required=True, description="The task details")}
18+
)
2119

22-
listed_todo = api.model('ListedTodo', {
23-
'id': fields.String(required=True, description='The todo ID'),
24-
'todo': fields.Nested(todo, description='The Todo')
25-
})
20+
listed_todo = api.model(
21+
"ListedTodo",
22+
{
23+
"id": fields.String(required=True, description="The todo ID"),
24+
"todo": fields.Nested(todo, description="The Todo"),
25+
},
26+
)
2627

2728

2829
def abort_if_todo_doesnt_exist(todo_id):
2930
if todo_id not in TODOS:
3031
api.abort(404, "Todo {} doesn't exist".format(todo_id))
3132

33+
3234
parser = api.parser()
33-
parser.add_argument('task', type=str, required=True, help='The task details', location='form')
35+
parser.add_argument(
36+
"task", type=str, required=True, help="The task details", location="form"
37+
)
3438

3539

36-
@ns.route('/<string:todo_id>')
37-
@api.doc(responses={404: 'Todo not found'}, params={'todo_id': 'The Todo ID'})
40+
@ns.route("/<string:todo_id>")
41+
@api.doc(responses={404: "Todo not found"}, params={"todo_id": "The Todo ID"})
3842
class Todo(Resource):
39-
'''Show a single todo item and lets you delete them'''
40-
@api.doc(description='todo_id should be in {0}'.format(', '.join(TODOS.keys())))
43+
"""Show a single todo item and lets you delete them"""
44+
45+
@api.doc(description="todo_id should be in {0}".format(", ".join(TODOS.keys())))
4146
@api.marshal_with(todo)
4247
def get(self, todo_id):
43-
'''Fetch a given resource'''
48+
"""Fetch a given resource"""
4449
abort_if_todo_doesnt_exist(todo_id)
4550
return TODOS[todo_id]
4651

47-
@api.doc(responses={204: 'Todo deleted'})
52+
@api.doc(responses={204: "Todo deleted"})
4853
def delete(self, todo_id):
49-
'''Delete a given resource'''
54+
"""Delete a given resource"""
5055
abort_if_todo_doesnt_exist(todo_id)
5156
del TODOS[todo_id]
52-
return '', 204
57+
return "", 204
5358

5459
@api.doc(parser=parser)
5560
@api.marshal_with(todo)
5661
def put(self, todo_id):
57-
'''Update a given resource'''
62+
"""Update a given resource"""
5863
args = parser.parse_args()
59-
task = {'task': args['task']}
64+
task = {"task": args["task"]}
6065
TODOS[todo_id] = task
6166
return task
6267

6368

64-
@ns.route('/')
69+
@ns.route("/")
6570
class TodoList(Resource):
66-
'''Shows a list of all todos, and lets you POST to add new tasks'''
71+
"""Shows a list of all todos, and lets you POST to add new tasks"""
72+
6773
@api.marshal_list_with(listed_todo)
6874
def get(self):
69-
'''List all todos'''
70-
return [{'id': id, 'todo': todo} for id, todo in TODOS.items()]
75+
"""List all todos"""
76+
return [{"id": id, "todo": todo} for id, todo in TODOS.items()]
7177

7278
@api.doc(parser=parser)
7379
@api.marshal_with(todo, code=201)
7480
def post(self):
75-
'''Create a todo'''
81+
"""Create a todo"""
7682
args = parser.parse_args()
77-
todo_id = 'todo%d' % (len(TODOS) + 1)
78-
TODOS[todo_id] = {'task': args['task']}
83+
todo_id = "todo%d" % (len(TODOS) + 1)
84+
TODOS[todo_id] = {"task": args["task"]}
7985
return TODOS[todo_id], 201
8086

8187

82-
if __name__ == '__main__':
88+
if __name__ == "__main__":
8389
app = Flask(__name__)
8490
app.register_blueprint(api_v1)
8591
app.run(debug=True)

examples/todo_simple.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
todos = {}
88

99

10-
@api.route('/<string:todo_id>')
10+
@api.route("/<string:todo_id>")
1111
class TodoSimple(Resource):
1212
"""
1313
You can try this example as follow:
@@ -30,15 +30,14 @@ class TodoSimple(Resource):
3030
{u'todo2': u'Change my breakpads'}
3131
3232
"""
33+
3334
def get(self, todo_id):
3435
return {todo_id: todos[todo_id]}
3536

3637
def put(self, todo_id):
37-
todos[todo_id] = request.form['data']
38+
todos[todo_id] = request.form["data"]
3839
return {todo_id: todos[todo_id]}
3940

4041

41-
if __name__ == '__main__':
42+
if __name__ == "__main__":
4243
app.run(debug=False)
43-
44-

examples/todomvc.py

+34-31
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
app = Flask(__name__)
66
app.wsgi_app = ProxyFix(app.wsgi_app)
7-
api = Api(app, version='1.0', title='TodoMVC API',
8-
description='A simple TodoMVC API',
9-
)
7+
api = Api(app, version="1.0", title="TodoMVC API", description="A simple TodoMVC API",)
108

11-
ns = api.namespace('todos', description='TODO operations')
9+
ns = api.namespace("todos", description="TODO operations")
1210

13-
todo = api.model('Todo', {
14-
'id': fields.Integer(readonly=True, description='The task unique identifier'),
15-
'task': fields.String(required=True, description='The task details')
16-
})
11+
todo = api.model(
12+
"Todo",
13+
{
14+
"id": fields.Integer(readonly=True, description="The task unique identifier"),
15+
"task": fields.String(required=True, description="The task details"),
16+
},
17+
)
1718

1819

1920
class TodoDAO(object):
@@ -23,13 +24,13 @@ def __init__(self):
2324

2425
def get(self, id):
2526
for todo in self.todos:
26-
if todo['id'] == id:
27+
if todo["id"] == id:
2728
return todo
2829
api.abort(404, "Todo {} doesn't exist".format(id))
2930

3031
def create(self, data):
3132
todo = data
32-
todo['id'] = self.counter = self.counter + 1
33+
todo["id"] = self.counter = self.counter + 1
3334
self.todos.append(todo)
3435
return todo
3536

@@ -44,52 +45,54 @@ def delete(self, id):
4445

4546

4647
DAO = TodoDAO()
47-
DAO.create({'task': 'Build an API'})
48-
DAO.create({'task': '?????'})
49-
DAO.create({'task': 'profit!'})
48+
DAO.create({"task": "Build an API"})
49+
DAO.create({"task": "?????"})
50+
DAO.create({"task": "profit!"})
5051

5152

52-
@ns.route('/')
53+
@ns.route("/")
5354
class TodoList(Resource):
54-
'''Shows a list of all todos, and lets you POST to add new tasks'''
55-
@ns.doc('list_todos')
55+
"""Shows a list of all todos, and lets you POST to add new tasks"""
56+
57+
@ns.doc("list_todos")
5658
@ns.marshal_list_with(todo)
5759
def get(self):
58-
'''List all tasks'''
60+
"""List all tasks"""
5961
return DAO.todos
6062

61-
@ns.doc('create_todo')
63+
@ns.doc("create_todo")
6264
@ns.expect(todo)
6365
@ns.marshal_with(todo, code=201)
6466
def post(self):
65-
'''Create a new task'''
67+
"""Create a new task"""
6668
return DAO.create(api.payload), 201
6769

6870

69-
@ns.route('/<int:id>')
70-
@ns.response(404, 'Todo not found')
71-
@ns.param('id', 'The task identifier')
71+
@ns.route("/<int:id>")
72+
@ns.response(404, "Todo not found")
73+
@ns.param("id", "The task identifier")
7274
class Todo(Resource):
73-
'''Show a single todo item and lets you delete them'''
74-
@ns.doc('get_todo')
75+
"""Show a single todo item and lets you delete them"""
76+
77+
@ns.doc("get_todo")
7578
@ns.marshal_with(todo)
7679
def get(self, id):
77-
'''Fetch a given resource'''
80+
"""Fetch a given resource"""
7881
return DAO.get(id)
7982

80-
@ns.doc('delete_todo')
81-
@ns.response(204, 'Todo deleted')
83+
@ns.doc("delete_todo")
84+
@ns.response(204, "Todo deleted")
8285
def delete(self, id):
83-
'''Delete a task given its identifier'''
86+
"""Delete a task given its identifier"""
8487
DAO.delete(id)
85-
return '', 204
88+
return "", 204
8689

8790
@ns.expect(todo)
8891
@ns.marshal_with(todo)
8992
def put(self, id):
90-
'''Update a task given its identifier'''
93+
"""Update a task given its identifier"""
9194
return DAO.update(id, api.payload)
9295

9396

94-
if __name__ == '__main__':
97+
if __name__ == "__main__":
9598
app.run(debug=True)

0 commit comments

Comments
 (0)