Tests: pathlib used where appropriate
Also fixed various pylint errors and style issues.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
def application(env, start_response):
|
||||
length = env.get('HTTP_X_LENGTH', '10')
|
||||
bytes = b'X' * int(length)
|
||||
body = b'X' * int(length)
|
||||
|
||||
start_response('200', [('Content-Length', length)])
|
||||
return [bytes]
|
||||
return [body]
|
||||
|
||||
@@ -33,7 +33,9 @@ async def application(scope, receive, send):
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', str(len(body)).encode()),],
|
||||
'headers': [
|
||||
(b'content-length', str(len(body)).encode()),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ import os
|
||||
|
||||
|
||||
def application(env, start_response):
|
||||
vars = env.get('HTTP_X_VARIABLES').split(',')
|
||||
variables = env.get('HTTP_X_VARIABLES').split(',')
|
||||
|
||||
body = ','.join([str(os.environ[var]) for var in vars if var in os.environ])
|
||||
body = ','.join(
|
||||
[str(os.environ[var]) for var in variables if var in os.environ]
|
||||
)
|
||||
body = body.encode()
|
||||
|
||||
start_response('200', [('Content-Length', str(len(body)))])
|
||||
|
||||
@@ -8,9 +8,7 @@ class application:
|
||||
def __iter__(self):
|
||||
self.__i = 0
|
||||
self._skip_level = int(self.environ.get('HTTP_X_SKIP', 0))
|
||||
self._not_skip_close = int(
|
||||
self.environ.get('HTTP_X_NOT_SKIP_CLOSE', 0)
|
||||
)
|
||||
self._not_skip_close = int(self.environ.get('HTTP_X_NOT_SKIP_CLOSE', 0))
|
||||
self._is_chunked = self.environ.get('HTTP_X_CHUNKED')
|
||||
|
||||
headers = [(('Content-Length', '10'))]
|
||||
|
||||
@@ -9,6 +9,8 @@ async def app_http(receive, send):
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', b'0'),],
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
def application(scope, receive=None, send=None):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
if receive == None and send == None:
|
||||
if receive is None and send is None:
|
||||
return app_http
|
||||
|
||||
else:
|
||||
return app_http(receive, send)
|
||||
return app_http(receive, send)
|
||||
|
||||
|
||||
async def app_http(receive, send):
|
||||
@@ -13,6 +12,8 @@ async def app_http(receive, send):
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', b'0'),],
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
|
||||
async def handler(prefix, scope, receive, send):
|
||||
if scope['type'] == 'lifespan':
|
||||
with open(f'{prefix}version', 'w+') as f:
|
||||
with open(f'{prefix}version', 'w+', encoding='utf-8') as f:
|
||||
f.write(
|
||||
f"{scope['asgi']['version']} {scope['asgi']['spec_version']}"
|
||||
)
|
||||
|
||||
@@ -6,6 +6,6 @@ async def application(scope, receive, send):
|
||||
await send({"type": "lifespan.startup.failed"})
|
||||
raise Exception('Exception blah')
|
||||
|
||||
elif message['type'] == 'lifespan.shutdown':
|
||||
if message['type'] == 'lifespan.shutdown':
|
||||
await send({'type': 'lifespan.shutdown.complete'})
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ import time
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def application(environ, start_response):
|
||||
body = str(os.getpid()).encode()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
def application(environ, start_response):
|
||||
temp_dir = environ.get('HTTP_TEMP_DIR')
|
||||
|
||||
with open(f'{temp_dir}/tempfile', 'w') as f:
|
||||
with open(f'{temp_dir}/tempfile', 'w', encoding='utf-8') as f:
|
||||
f.write('\u26a0\ufe0f')
|
||||
|
||||
start_response('200', [('Content-Length', '0')])
|
||||
|
||||
@@ -6,7 +6,12 @@ def application(environ, start_response):
|
||||
uid = os.geteuid()
|
||||
gid = os.getegid()
|
||||
|
||||
out = json.dumps({'UID': uid, 'GID': gid,}).encode('utf-8')
|
||||
out = json.dumps(
|
||||
{
|
||||
'UID': uid,
|
||||
'GID': gid,
|
||||
}
|
||||
).encode('utf-8')
|
||||
|
||||
start_response(
|
||||
'200 OK',
|
||||
|
||||
Reference in New Issue
Block a user