Tests: style.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import atexit
|
||||
|
||||
|
||||
def application(environ, start_response):
|
||||
def at_exit():
|
||||
environ['wsgi.errors'].write('At exit called.\n')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import io
|
||||
|
||||
|
||||
def application(env, start_response):
|
||||
start_response('200', [('Content-Length', '10')])
|
||||
f = io.BytesIO(b'0123456789')
|
||||
|
||||
@@ -2,6 +2,7 @@ def application(env, start_response):
|
||||
start_response('204', [('Content-Length', '0')])
|
||||
return []
|
||||
|
||||
|
||||
def app(env, start_response):
|
||||
start_response('200', [('Content-Length', '0')])
|
||||
return []
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import atexit
|
||||
|
||||
|
||||
class application:
|
||||
def __init__(self, environ, start_response):
|
||||
self.environ = environ
|
||||
@@ -11,13 +12,14 @@ class application:
|
||||
content_length = int(self.environ.get('CONTENT_LENGTH', 0))
|
||||
body = bytes(self.environ['wsgi.input'].read(content_length))
|
||||
|
||||
self.start('200', [
|
||||
('Content-Type', self.environ.get('CONTENT_TYPE')),
|
||||
('Content-Length', str(len(body)))
|
||||
])
|
||||
self.start(
|
||||
'200',
|
||||
[
|
||||
('Content-Type', self.environ.get('CONTENT_TYPE')),
|
||||
('Content-Length', str(len(body))),
|
||||
],
|
||||
)
|
||||
yield body
|
||||
|
||||
def _atexit(self):
|
||||
self.start('200', [
|
||||
('Content-Length', '0')
|
||||
])
|
||||
self.start('200', [('Content-Length', '0')])
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
def application(environ, start_response):
|
||||
|
||||
start_response('200', [
|
||||
('Content-Length', '0'),
|
||||
('Custom-Header', environ.get('HTTP_CUSTOM_HEADER'))
|
||||
])
|
||||
start_response(
|
||||
'200',
|
||||
[
|
||||
('Content-Length', '0'),
|
||||
('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')),
|
||||
],
|
||||
)
|
||||
return []
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
|
||||
|
||||
async def application(scope, receive, send):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
@@ -28,13 +29,13 @@ async def application(scope, receive, send):
|
||||
loop.call_later(n, future.set_result, None)
|
||||
await future
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', str(len(body)).encode()),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', str(len(body)).encode()),],
|
||||
}
|
||||
)
|
||||
|
||||
if not body:
|
||||
await sleep(delay)
|
||||
@@ -42,10 +43,12 @@ async def application(scope, receive, send):
|
||||
|
||||
step = int(len(body) / parts)
|
||||
for i in range(0, len(body), step):
|
||||
await send({
|
||||
'type': 'http.response.body',
|
||||
'body': body[i : i + step],
|
||||
'more_body': True,
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.body',
|
||||
'body': body[i : i + step],
|
||||
'more_body': True,
|
||||
}
|
||||
)
|
||||
|
||||
await sleep(delay)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
async def application(scope, receive, send):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', b'0')],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
|
||||
|
||||
def application(env, start_response):
|
||||
body = ''
|
||||
vars = env.get('HTTP_X_VARIABLES').split(',')
|
||||
|
||||
@@ -2,8 +2,7 @@ def application(environ, start_response):
|
||||
|
||||
h = (k for k, v in environ.items() if k.startswith('HTTP_'))
|
||||
|
||||
start_response('200', [
|
||||
('Content-Length', '0'),
|
||||
('All-Headers', ','.join(h))
|
||||
])
|
||||
start_response(
|
||||
'200', [('Content-Length', '0'), ('All-Headers', ','.join(h))]
|
||||
)
|
||||
return []
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
def application(env, start_response):
|
||||
start_response('200', [
|
||||
('Content-Length', '0'),
|
||||
('X-Server-Name', env.get('SERVER_NAME')),
|
||||
('X-Http-Host', str(env.get('HTTP_HOST')))
|
||||
])
|
||||
start_response(
|
||||
'200',
|
||||
[
|
||||
('Content-Length', '0'),
|
||||
('X-Server-Name', env.get('SERVER_NAME')),
|
||||
('X-Http-Host', str(env.get('HTTP_HOST'))),
|
||||
],
|
||||
)
|
||||
return []
|
||||
|
||||
@@ -8,7 +8,9 @@ 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'))]
|
||||
|
||||
@@ -3,11 +3,12 @@ def application(scope):
|
||||
|
||||
return app_http
|
||||
|
||||
|
||||
async def app_http(receive, send):
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', b'0'),],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -7,11 +7,12 @@ def application(scope, receive=None, send=None):
|
||||
else:
|
||||
return app_http(receive, send)
|
||||
|
||||
|
||||
async def app_http(receive, send):
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', b'0'),],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -8,15 +8,12 @@ async def application(scope, receive, send):
|
||||
if not m.get('more_body', False):
|
||||
break
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', str(len(body)).encode()),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', str(len(body)).encode())],
|
||||
}
|
||||
)
|
||||
|
||||
await send({
|
||||
'type': 'http.response.body',
|
||||
'body': body,
|
||||
})
|
||||
await send({'type': 'http.response.body', 'body': body})
|
||||
|
||||
@@ -3,7 +3,5 @@ def application(environ, start_response):
|
||||
content_length = int(environ.get('CONTENT_LENGTH', 0))
|
||||
body = bytes(environ['wsgi.input'].read(content_length))
|
||||
|
||||
start_response('200', [
|
||||
('Content-Length', str(len(body)))
|
||||
])
|
||||
start_response('200', [('Content-Length', str(len(body)))])
|
||||
return [body]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def application(environ, start_response):
|
||||
body = os.pathsep.join(sys.path).encode()
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
async def application(scope, receive, send):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
(b'query-string', scope['query_string']),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
(b'query-string', scope['query_string']),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
def application(environ, start_response):
|
||||
|
||||
start_response('200', [
|
||||
('Content-Length', '0'),
|
||||
('Query-String', environ.get('QUERY_STRING'))
|
||||
])
|
||||
start_response(
|
||||
'200',
|
||||
[
|
||||
('Content-Length', '0'),
|
||||
('Query-String', environ.get('QUERY_STRING')),
|
||||
],
|
||||
)
|
||||
return []
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
async def application(scope, receive, send):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
(b'server-port', str(scope['server'][1]).encode()),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
(b'server-port', str(scope['server'][1]).encode()),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
def application(environ, start_response):
|
||||
|
||||
start_response('200', [
|
||||
('Content-Length', '0'),
|
||||
('Server-Port', environ.get('SERVER_PORT'))
|
||||
])
|
||||
start_response(
|
||||
'200',
|
||||
[('Content-Length', '0'), ('Server-Port', environ.get('SERVER_PORT'))],
|
||||
)
|
||||
return []
|
||||
|
||||
@@ -33,10 +33,10 @@ async def application(scope, receive, send):
|
||||
Foo(Foo.num).start()
|
||||
Foo.num += 10
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [(b'content-length', b'0')],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import asyncio
|
||||
import time
|
||||
import threading
|
||||
|
||||
|
||||
async def application(scope, receive, send):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
@@ -17,11 +18,13 @@ async def application(scope, receive, send):
|
||||
|
||||
time.sleep(delay)
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
(b'x-thread', str(threading.currentThread().ident).encode()),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
(b'x-thread', str(threading.currentThread().ident).encode()),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import time
|
||||
import threading
|
||||
|
||||
|
||||
def application(environ, start_response):
|
||||
delay = float(environ.get('HTTP_X_DELAY', 0))
|
||||
|
||||
time.sleep(delay)
|
||||
|
||||
start_response('200', [
|
||||
('Content-Length', '0'),
|
||||
('Wsgi-Multithread', str(environ['wsgi.multithread'])),
|
||||
('X-Thread', str(threading.currentThread().ident))
|
||||
])
|
||||
start_response(
|
||||
'200',
|
||||
[
|
||||
('Content-Length', '0'),
|
||||
('Wsgi-Multithread', str(environ['wsgi.multithread'])),
|
||||
('X-Thread', str(threading.currentThread().ident)),
|
||||
],
|
||||
)
|
||||
|
||||
return []
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from tempfile import TemporaryFile
|
||||
import os, cgi
|
||||
|
||||
|
||||
def read(environ):
|
||||
length = int(environ.get('CONTENT_LENGTH', 0))
|
||||
|
||||
@@ -11,6 +12,7 @@ def read(environ):
|
||||
environ['wsgi.input'] = body
|
||||
return body
|
||||
|
||||
|
||||
def application(environ, start_response):
|
||||
file = read(environ)
|
||||
|
||||
@@ -19,9 +21,9 @@ def application(environ, start_response):
|
||||
filename = form['file'].filename
|
||||
data = filename.encode() + form['file'].file.read()
|
||||
|
||||
start_response('200 OK', [
|
||||
('Content-Type', 'text/plain'),
|
||||
('Content-Length', str(len(data))),
|
||||
])
|
||||
start_response(
|
||||
'200 OK',
|
||||
[('Content-Type', 'text/plain'), ('Content-Length', str(len(data)))],
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
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', [
|
||||
('Content-Length', str(len(out))),
|
||||
('Content-Type', 'application/json')
|
||||
])
|
||||
start_response(
|
||||
'200 OK',
|
||||
[
|
||||
('Content-Length', str(len(out))),
|
||||
('Content-Type', 'application/json'),
|
||||
],
|
||||
)
|
||||
|
||||
return [out]
|
||||
|
||||
@@ -17,24 +17,23 @@ async def application(scope, receive, send):
|
||||
res.append(h[1])
|
||||
return b', '.join(res)
|
||||
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-type', get_header(b'content-type')),
|
||||
(b'content-length', str(len(body)).encode()),
|
||||
(b'request-method', scope['method'].encode()),
|
||||
(b'request-uri', scope['path'].encode()),
|
||||
(b'http-host', get_header(b'host')),
|
||||
(b'http-version', scope['http_version'].encode()),
|
||||
(b'asgi-version', scope['asgi']['version'].encode()),
|
||||
(b'asgi-spec-version', scope['asgi']['spec_version'].encode()),
|
||||
(b'scheme', scope['scheme'].encode()),
|
||||
(b'custom-header', get_header(b'custom-header')),
|
||||
]
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-type', get_header(b'content-type')),
|
||||
(b'content-length', str(len(body)).encode()),
|
||||
(b'request-method', scope['method'].encode()),
|
||||
(b'request-uri', scope['path'].encode()),
|
||||
(b'http-host', get_header(b'host')),
|
||||
(b'http-version', scope['http_version'].encode()),
|
||||
(b'asgi-version', scope['asgi']['version'].encode()),
|
||||
(b'asgi-spec-version', scope['asgi']['spec_version'].encode()),
|
||||
(b'scheme', scope['scheme'].encode()),
|
||||
(b'custom-header', get_header(b'custom-header')),
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
await send({
|
||||
'type': 'http.response.body',
|
||||
'body': body,
|
||||
})
|
||||
await send({'type': 'http.response.body', 'body': body})
|
||||
|
||||
@@ -3,19 +3,22 @@ def application(environ, start_response):
|
||||
content_length = int(environ.get('CONTENT_LENGTH', 0))
|
||||
body = bytes(environ['wsgi.input'].read(content_length))
|
||||
|
||||
start_response('200', [
|
||||
('Content-Type', environ.get('CONTENT_TYPE')),
|
||||
('Content-Length', str(len(body))),
|
||||
('Request-Method', environ.get('REQUEST_METHOD')),
|
||||
('Request-Uri', environ.get('REQUEST_URI')),
|
||||
('Http-Host', environ.get('HTTP_HOST')),
|
||||
('Server-Protocol', environ.get('SERVER_PROTOCOL')),
|
||||
('Server-Software', environ.get('SERVER_SOFTWARE')),
|
||||
('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')),
|
||||
('Wsgi-Version', str(environ['wsgi.version'])),
|
||||
('Wsgi-Url-Scheme', environ['wsgi.url_scheme']),
|
||||
('Wsgi-Multithread', str(environ['wsgi.multithread'])),
|
||||
('Wsgi-Multiprocess', str(environ['wsgi.multiprocess'])),
|
||||
('Wsgi-Run-Once', str(environ['wsgi.run_once']))
|
||||
])
|
||||
start_response(
|
||||
'200',
|
||||
[
|
||||
('Content-Type', environ.get('CONTENT_TYPE')),
|
||||
('Content-Length', str(len(body))),
|
||||
('Request-Method', environ.get('REQUEST_METHOD')),
|
||||
('Request-Uri', environ.get('REQUEST_URI')),
|
||||
('Http-Host', environ.get('HTTP_HOST')),
|
||||
('Server-Protocol', environ.get('SERVER_PROTOCOL')),
|
||||
('Server-Software', environ.get('SERVER_SOFTWARE')),
|
||||
('Custom-Header', environ.get('HTTP_CUSTOM_HEADER')),
|
||||
('Wsgi-Version', str(environ['wsgi.version'])),
|
||||
('Wsgi-Url-Scheme', environ['wsgi.url_scheme']),
|
||||
('Wsgi-Multithread', str(environ['wsgi.multithread'])),
|
||||
('Wsgi-Multiprocess', str(environ['wsgi.multiprocess'])),
|
||||
('Wsgi-Run-Once', str(environ['wsgi.run_once'])),
|
||||
],
|
||||
)
|
||||
return [body]
|
||||
|
||||
@@ -3,16 +3,16 @@ async def application(scope, receive, send):
|
||||
while True:
|
||||
m = await receive()
|
||||
if m['type'] == 'websocket.connect':
|
||||
await send({
|
||||
'type': 'websocket.accept',
|
||||
})
|
||||
await send({'type': 'websocket.accept'})
|
||||
|
||||
if m['type'] == 'websocket.receive':
|
||||
await send({
|
||||
'type': 'websocket.send',
|
||||
'bytes': m.get('bytes', None),
|
||||
'text': m.get('text', None),
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'websocket.send',
|
||||
'bytes': m.get('bytes', None),
|
||||
'text': m.get('text', None),
|
||||
}
|
||||
)
|
||||
|
||||
if m['type'] == 'websocket.disconnect':
|
||||
break;
|
||||
break
|
||||
|
||||
@@ -6,20 +6,24 @@ async def application(scope, receive, send):
|
||||
if m['type'] == 'websocket.connect':
|
||||
subprotocols = scope['subprotocols']
|
||||
|
||||
await send({
|
||||
'type': 'websocket.accept',
|
||||
'headers': [
|
||||
(b'x-subprotocols', str(subprotocols).encode()),
|
||||
],
|
||||
'subprotocol': subprotocols[0],
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'websocket.accept',
|
||||
'headers': [
|
||||
(b'x-subprotocols', str(subprotocols).encode()),
|
||||
],
|
||||
'subprotocol': subprotocols[0],
|
||||
}
|
||||
)
|
||||
|
||||
if m['type'] == 'websocket.receive':
|
||||
await send({
|
||||
'type': 'websocket.send',
|
||||
'bytes': m.get('bytes', None),
|
||||
'text': m.get('text', None),
|
||||
})
|
||||
await send(
|
||||
{
|
||||
'type': 'websocket.send',
|
||||
'bytes': m.get('bytes', None),
|
||||
'text': m.get('text', None),
|
||||
}
|
||||
)
|
||||
|
||||
if m['type'] == 'websocket.disconnect':
|
||||
break;
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user