-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__testing__.py
126 lines (97 loc) · 3.97 KB
/
__testing__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from java.lang import System
import os
import sys
def escape_html(s): return s.replace('&', '&').replace('<', '<').replace('>', '>')
def cutoff(s, n=100):
if len(s) > n: return s[:n]+ '.. cut ..'
return s
def handler(environ, start_response):
writer = start_response("200 OK", [ ('content-type', 'text/html') ])
response_parts = []
response_parts.append("<p>Modjy servlet running correctly: jython %s on %s:</p>" % (sys.version, sys.platform))
response_parts.append("<h3>Hello WSGI World!</h3>")
response_parts.append("<h4>Here are the contents of the WSGI environment</h4>")
environ_str = "<table border='1'>"
keys = environ.keys()
keys.sort()
ix = 0
for name in keys:
if ix % 2:
background='#ffffff'
else:
background='#eeeeee'
style = " style='background-color:%s;'" % background
value = escape_html(cutoff(str(environ[name]))) or ' '
environ_str = "%s<tr><td%s>%s</td><td%s>%s</td></tr>" % \
(environ_str, style, name, style, value)
ix += 1
environ_str = "%s</table>" % environ_str
response_parts.append(environ_str)
response_text = "".join(response_parts)
return [response_text]
def start_with_one_arg(environ, start_response):
writer = start_response("200 OK")
return []
def start_with_three_args(environ, start_response):
writer = start_response("200 OK", [], None)
return []
def start_with_int_first_arg(environ, start_response):
writer = start_response(200, [])
return []
def start_with_float_first_arg(environ, start_response):
writer = start_response(200.0, [])
return []
def start_with_string_second_arg(environ, start_response):
writer = start_response("200 OK", 'content-type: text/plain')
return []
def start_with_tuple_second_arg(environ, start_response):
writer = start_response("200 OK", () )
return []
def start_with_single_header_string(environ, start_response):
writer = start_response("200 OK", ['content-type: text/plain'] )
return []
def start_with_non_tuple_pair(environ, start_response):
writer = start_response("200 OK", ['content-type', 'text/plain'] )
return []
def writer_with_no_args(environ, start_response):
writer = start_response("200 OK", [('content-type', 'text/plain')] )
writer()
return []
def writer_with_int_arg(environ, start_response):
writer = start_response("200 OK", [('content-type', 'text/plain')] )
writer(42)
return []
def return_none(environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
return None
def return_no_start(environ, start_response):
pass
return ['hello', 'world']
def return_list(environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
return ['return', ':', 'list']
def return_tuple(environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
return ('return', ':', 'tuple')
def return_listcomp(environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
return [s for s in ['return', ':', 'listcomp']]
def return_string(environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
return "A single string should be acceptable"
def return_int(environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
return 42
class return_iter_wrong_length:
def __init__(self, environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )
def __len__(self):
return 2
def __getitem__(self, ix):
if ix == 0:
return "a string"
else:
raise IndexError()
class return_not_iter:
def __init__(self, environ, start_response):
start_response("200 OK", [('content-type', 'text/plain')] )