Skip to content

Commit 6ab735c

Browse files
committed
Reformat everything with black
1 parent 4d54100 commit 6ab735c

File tree

10 files changed

+399
-457
lines changed

10 files changed

+399
-457
lines changed

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ confidence=
6767
# --disable=W"
6868
disable=
6969
fixme,
70+
bad-continuation,
7071
missing-docstring,
7172
too-few-public-methods,
7273

aiohttp_graphql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .graphqlview import GraphQLView
22

3-
__all__ = ['GraphQLView']
3+
__all__ = ["GraphQLView"]

aiohttp_graphql/graphqlview.py

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@
1919

2020
class GraphQLView: # pylint: disable = too-many-instance-attributes
2121
def __init__(
22-
self,
23-
schema=None,
24-
executor=None,
25-
root_value=None,
26-
context=None,
27-
pretty=False,
28-
graphiql=False,
29-
graphiql_version=None,
30-
graphiql_template=None,
31-
middleware=None,
32-
batch=False,
33-
jinja_env=None,
34-
max_age=86400,
35-
encoder=None,
36-
error_formatter=None,
37-
enable_async=True):
22+
self,
23+
schema=None,
24+
executor=None,
25+
root_value=None,
26+
context=None,
27+
pretty=False,
28+
graphiql=False,
29+
graphiql_version=None,
30+
graphiql_template=None,
31+
middleware=None,
32+
batch=False,
33+
jinja_env=None,
34+
max_age=86400,
35+
encoder=None,
36+
error_formatter=None,
37+
enable_async=True,
38+
):
3839
# pylint: disable=too-many-arguments
3940
# pylint: disable=too-many-locals
4041

@@ -52,33 +53,34 @@ def __init__(
5253
self.max_age = max_age
5354
self.encoder = encoder or json_encode
5455
self.error_formatter = error_formatter or default_format_error
55-
self.enable_async = enable_async and isinstance(
56-
self.executor, AsyncioExecutor)
57-
assert isinstance(self.schema, GraphQLSchema), \
58-
'A Schema is required to be provided to GraphQLView.'
56+
self.enable_async = enable_async and isinstance(self.executor, AsyncioExecutor)
57+
assert isinstance(
58+
self.schema, GraphQLSchema
59+
), "A Schema is required to be provided to GraphQLView."
5960

6061
def get_context(self, request):
6162
if self.context and isinstance(self.context, Mapping):
6263
context = self.context.copy()
6364
else:
6465
context = {}
6566

66-
if isinstance(context, Mapping) and 'request' not in context:
67-
context.update({'request': request})
67+
if isinstance(context, Mapping) and "request" not in context:
68+
context.update({"request": request})
6869
return context
6970

7071
async def parse_body(self, request):
71-
if request.content_type == 'application/graphql':
72+
if request.content_type == "application/graphql":
7273
r_text = await request.text()
73-
return {'query': r_text}
74+
return {"query": r_text}
7475

75-
if request.content_type == 'application/json':
76+
if request.content_type == "application/json":
7677
text = await request.text()
7778
return load_json_body(text)
7879

7980
if request.content_type in (
80-
'application/x-www-form-urlencoded',
81-
'multipart/form-data'):
81+
"application/x-www-form-urlencoded",
82+
"multipart/form-data",
83+
):
8284
# TODO: seems like a multidict would be more appropriate
8385
# than casting it and de-duping variables. Alas, it's what
8486
# graphql-python wants.
@@ -96,22 +98,24 @@ def render_graphiql(self, params, result):
9698
)
9799

98100
def is_graphiql(self, request):
99-
return all([
100-
self.graphiql,
101-
request.method.lower() == 'get',
102-
'raw' not in request.query,
103-
any([
104-
'text/html' in request.headers.get('accept', {}),
105-
'*/*' in request.headers.get('accept', {}),
106-
]),
107-
])
101+
return all(
102+
[
103+
self.graphiql,
104+
request.method.lower() == "get",
105+
"raw" not in request.query,
106+
any(
107+
[
108+
"text/html" in request.headers.get("accept", {}),
109+
"*/*" in request.headers.get("accept", {}),
110+
]
111+
),
112+
]
113+
)
108114

109115
def is_pretty(self, request):
110-
return any([
111-
self.pretty,
112-
self.is_graphiql(request),
113-
request.query.get('pretty'),
114-
])
116+
return any(
117+
[self.pretty, self.is_graphiql(request), request.query.get("pretty")]
118+
)
115119

116120
async def __call__(self, request):
117121
try:
@@ -120,7 +124,7 @@ async def __call__(self, request):
120124
is_graphiql = self.is_graphiql(request)
121125
is_pretty = self.is_pretty(request)
122126

123-
if request_method == 'options':
127+
if request_method == "options":
124128
return self.process_preflight(request)
125129

126130
execution_results, all_params = run_http_query(
@@ -141,8 +145,8 @@ async def __call__(self, request):
141145
if is_graphiql and self.enable_async:
142146
# catch errors like run_http_query does when async
143147
execution_results = [
144-
result.catch(lambda value: None)
145-
for result in execution_results]
148+
result.catch(lambda value: None) for result in execution_results
149+
]
146150
awaited_execution_results = await Promise.all(execution_results)
147151
result, status_code = encode_execution_results(
148152
awaited_execution_results,
@@ -152,54 +156,46 @@ async def __call__(self, request):
152156
)
153157

154158
if is_graphiql:
155-
return await self.render_graphiql(
156-
params=all_params[0],
157-
result=result,
158-
)
159+
return await self.render_graphiql(params=all_params[0], result=result,)
159160

160161
return web.Response(
161-
text=result,
162-
status=status_code,
163-
content_type='application/json',
162+
text=result, status=status_code, content_type="application/json",
164163
)
165164

166165
except HttpQueryError as err:
167-
if err.headers and 'Allow' in err.headers:
166+
if err.headers and "Allow" in err.headers:
168167
# bug in graphql_server.execute_graphql_request
169168
# https://github.com/graphql-python/graphql-server-core/pull/4
170-
if isinstance(err.headers['Allow'], list):
171-
err.headers['Allow'] = ', '.join(err.headers['Allow'])
169+
if isinstance(err.headers["Allow"], list):
170+
err.headers["Allow"] = ", ".join(err.headers["Allow"])
172171

173172
return web.Response(
174-
text=self.encoder({
175-
'errors': [self.error_formatter(err)]
176-
}),
173+
text=self.encoder({"errors": [self.error_formatter(err)]}),
177174
status=err.status_code,
178175
headers=err.headers,
179-
content_type='application/json',
176+
content_type="application/json",
180177
)
181178

182179
def process_preflight(self, request):
183180
""" Preflight request support for apollo-client
184181
https://www.w3.org/TR/cors/#resource-preflight-requests """
185182
headers = request.headers
186-
origin = headers.get('Origin', '')
187-
method = headers.get('Access-Control-Request-Method', '').upper()
183+
origin = headers.get("Origin", "")
184+
method = headers.get("Access-Control-Request-Method", "").upper()
188185

189-
accepted_methods = ['GET', 'POST', 'PUT', 'DELETE']
186+
accepted_methods = ["GET", "POST", "PUT", "DELETE"]
190187
if method and method in accepted_methods:
191188
return web.Response(
192189
status=200,
193190
headers={
194-
'Access-Control-Allow-Origin': origin,
195-
'Access-Control-Allow-Methods': ', '.join(accepted_methods),
196-
'Access-Control-Max-Age': str(self.max_age),
197-
}
191+
"Access-Control-Allow-Origin": origin,
192+
"Access-Control-Allow-Methods": ", ".join(accepted_methods),
193+
"Access-Control-Max-Age": str(self.max_age),
194+
},
198195
)
199196
return web.Response(status=400)
200197

201198
@classmethod
202-
def attach(cls, app, *, route_path='/graphql', route_name='graphql',
203-
**kwargs):
199+
def attach(cls, app, *, route_path="/graphql", route_name="graphql", **kwargs):
204200
view = cls(**kwargs)
205-
app.router.add_route('*', route_path, view, name=route_name)
201+
app.router.add_route("*", route_path, view, name=route_name)

aiohttp_graphql/render_graphiql.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from aiohttp import web
55

66

7-
GRAPHIQL_VERSION = '0.11.10'
7+
GRAPHIQL_VERSION = "0.11.10"
88

9-
TEMPLATE = '''<!--
9+
TEMPLATE = """<!--
1010
The request to this GraphQL server provided the header "Accept: text/html"
1111
and as a result has been presented GraphiQL - an in-browser IDE for
1212
exploring GraphQL.
@@ -124,7 +124,7 @@
124124
);
125125
</script>
126126
</body>
127-
</html>'''
127+
</html>"""
128128

129129

130130
def escape_js_value(value):
@@ -133,49 +133,50 @@ def escape_js_value(value):
133133
quotation = True
134134
value = value[1:-1]
135135

136-
value = value.replace('\\\\n', '\\\\\\n').replace('\\n', '\\\\n')
136+
value = value.replace("\\\\n", "\\\\\\n").replace("\\n", "\\\\n")
137137
if quotation:
138-
value = '"' + value.replace('\\\\"', '"').replace('\"', '\\\"') + '"'
138+
value = '"' + value.replace('\\\\"', '"').replace('"', '\\"') + '"'
139139

140140
return value
141141

142142

143143
def process_var(template, name, value, jsonify=False):
144-
pattern = r'{{\s*' + name + r'(\s*|[^}]+)*\s*}}'
145-
if jsonify and value not in ['null', 'undefined']:
144+
pattern = r"{{\s*" + name + r"(\s*|[^}]+)*\s*}}"
145+
if jsonify and value not in ["null", "undefined"]:
146146
value = json.dumps(value)
147147
value = escape_js_value(value)
148148

149149
return re.sub(pattern, value, template)
150150

151151

152152
def simple_renderer(template, **values):
153-
replace = ['graphiql_version']
154-
replace_jsonify = ['query', 'result', 'variables', 'operation_name']
153+
replace = ["graphiql_version"]
154+
replace_jsonify = ["query", "result", "variables", "operation_name"]
155155

156156
for rep in replace:
157-
template = process_var(template, rep, values.get(rep, ''))
157+
template = process_var(template, rep, values.get(rep, ""))
158158

159159
for rep in replace_jsonify:
160-
template = process_var(template, rep, values.get(rep, ''), True)
160+
template = process_var(template, rep, values.get(rep, ""), True)
161161

162162
return template
163163

164164

165165
async def render_graphiql(
166-
jinja_env=None,
167-
graphiql_version=None,
168-
graphiql_template=None,
169-
params=None,
170-
result=None):
166+
jinja_env=None,
167+
graphiql_version=None,
168+
graphiql_template=None,
169+
params=None,
170+
result=None,
171+
):
171172
graphiql_version = graphiql_version or GRAPHIQL_VERSION
172173
template = graphiql_template or TEMPLATE
173174
template_vars = {
174-
'graphiql_version': graphiql_version,
175-
'query': params and params.query,
176-
'variables': params and params.variables,
177-
'operation_name': params and params.operation_name,
178-
'result': result,
175+
"graphiql_version": graphiql_version,
176+
"query": params and params.query,
177+
"variables": params and params.variables,
178+
"operation_name": params and params.operation_name,
179+
"result": result,
179180
}
180181

181182
if jinja_env:
@@ -187,4 +188,4 @@ async def render_graphiql(
187188
else:
188189
source = simple_renderer(template, **template_vars)
189190

190-
return web.Response(text=source, content_type='text/html')
191+
return web.Response(text=source, content_type="text/html")

setup.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
from setuptools import setup, find_packages
22

33
setup(
4-
name='aiohttp-graphql',
5-
version='1.1.0',
6-
description='Adds GraphQL support to your aiohttp application',
7-
long_description=open('README.md').read(),
8-
long_description_content_type='text/markdown',
9-
url='https://github.com/graphql-python/aiohttp-graphql',
10-
download_url='https://github.com/graphql-python/aiohttp-graphql/releases',
11-
author='Devin Fee',
12-
author_email='[email protected]',
13-
license='MIT',
4+
name="aiohttp-graphql",
5+
version="1.1.0",
6+
description="Adds GraphQL support to your aiohttp application",
7+
long_description=open("README.md").read(),
8+
long_description_content_type="text/markdown",
9+
url="https://github.com/graphql-python/aiohttp-graphql",
10+
download_url="https://github.com/graphql-python/aiohttp-graphql/releases",
11+
author="Devin Fee",
12+
author_email="[email protected]",
13+
license="MIT",
1414
classifiers=[
15-
'Development Status :: 5 - Production/Stable',
16-
'Intended Audience :: Developers',
17-
'Topic :: Software Development :: Libraries',
18-
'Programming Language :: Python :: 3.6',
19-
'Programming Language :: Python :: 3.7',
20-
'Programming Language :: Python :: 3.8',
21-
'License :: OSI Approved :: MIT License',
15+
"Development Status :: 5 - Production/Stable",
16+
"Intended Audience :: Developers",
17+
"Topic :: Software Development :: Libraries",
18+
"Programming Language :: Python :: 3.6",
19+
"Programming Language :: Python :: 3.7",
20+
"Programming Language :: Python :: 3.8",
21+
"License :: OSI Approved :: MIT License",
2222
],
23-
keywords='api graphql protocol aiohttp',
24-
packages=find_packages(exclude=['tests']),
23+
keywords="api graphql protocol aiohttp",
24+
packages=find_packages(exclude=["tests"]),
2525
install_requires=[
26-
'graphql-core>=2.3,<3',
27-
'graphql-server-core>=1.2,<2',
28-
'aiohttp>=3,<4',
26+
"graphql-core>=2.3,<3",
27+
"graphql-server-core>=1.2,<2",
28+
"aiohttp>=3,<4",
2929
],
3030
extras_require={
31-
'test': [
32-
'pytest>=5.3,<5.4',
33-
'pytest-asyncio>=0.10,<0.11',
34-
'pytest-cov>=2.8,<3',
35-
'jinja2>=2.10,<3',
36-
'yarl>1.4,<1.5',
31+
"test": [
32+
"pytest>=5.3,<5.4",
33+
"pytest-asyncio>=0.10,<0.11",
34+
"pytest-cov>=2.8,<3",
35+
"jinja2>=2.10,<3",
36+
"yarl>1.4,<1.5",
3737
],
3838
},
3939
include_package_data=True,
40-
platforms='any',
40+
platforms="any",
4141
)

0 commit comments

Comments
 (0)