Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pyrte
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
WASD
pyrte
Commits
1a665681e650
Commit
1a665681e650
authored
4 years ago
by
Jean-Francois Pieronne
Browse files
Options
Downloads
Patches
Plain Diff
src/python/scripts/wsgiref_test3.py initial version
parent
1adcf07832d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/scripts/wsgiref_test3.py
+125
-0
125 additions, 0 deletions
src/python/scripts/wsgiref_test3.py
with
125 additions
and
0 deletions
src/python/scripts/wsgiref_test3.py
0 → 100755
+
125
−
0
View file @
1a665681
"""
Simple WSGI applications
Adapted from ajp_test.py for WASD PyRTE
"""
def
what
(
environ
,
start_response
):
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
return
[
'
Applications are: app, test_app,
\
hash_app, hash_app2, hash_app3, hash_app4
\n
'
]
def
app
(
environ
,
start_response
):
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
return
[
'
Hello World!
\n
'
]
def
test_app
(
environ
,
start_response
):
import
cgi
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/html
'
)])
yield
'
<html><head><title>Hello World!</title></head>
\n
'
\
'
<body>
\n
'
\
'
<p>Hello World!</p>
\n
'
\
'
<table border=
"
1
"
>
'
names
=
environ
.
keys
()
names
.
sort
()
for
name
in
names
:
yield
'
<tr><td>%s</td><td>%s</td></tr>
\n
'
%
(
name
,
cgi
.
escape
(
`environ[name]`
))
form
=
cgi
.
FieldStorage
(
fp
=
environ
[
'
wsgi.input
'
],
environ
=
environ
,
keep_blank_values
=
1
)
if
form
.
list
:
yield
'
<tr><th colspan=
"
2
"
>Form data</th></tr>
'
for
field
in
form
.
list
:
yield
'
<tr><td>%s</td><td>%s</td></tr>
\n
'
%
(
field
.
name
,
field
.
value
)
yield
'
</table>
\n
'
\
'
</body></html>
\n
'
# For testing the InputStream implementation (use curl --data-binary)
def
hash_app
(
environ
,
start_response
):
import
sha
h
=
sha
.
sha
()
h
.
update
(
environ
[
'
wsgi.input
'
].
read
())
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
return
[
h
.
hexdigest
()
+
'
\n
'
]
def
hash_app2
(
environ
,
start_response
):
import
sha
h
=
sha
.
sha
()
inf
=
environ
[
'
wsgi.input
'
]
s
=
inf
.
read
(
4096
)
while
s
:
h
.
update
(
s
)
s
=
inf
.
read
(
4096
)
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
return
[
h
.
hexdigest
()
+
'
\n
'
]
def
hash_app3
(
environ
,
start_response
):
import
sha
h
=
sha
.
sha
()
lines
=
0
for
line
in
environ
[
'
wsgi.input
'
]:
h
.
update
(
line
)
lines
+=
1
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
return
[
'
%s
\n
%s
\n
'
%
(
h
.
hexdigest
(),
lines
)]
def
hash_app4
(
environ
,
start_response
):
import
sha
h
=
sha
.
sha
()
lines
=
0
inf
=
environ
[
'
wsgi.input
'
]
line
=
inf
.
readline
(
100
)
while
line
:
h
.
update
(
line
)
lines
+=
1
line
=
inf
.
readline
(
100
)
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
return
[
'
%s
\n
%s
\n
'
%
(
h
.
hexdigest
(),
lines
)]
def
wrap_app
(
environ
,
start_response
):
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
f
=
open
(
'
wsgi.c
'
)
if
'
wsgi.file_wrapper
'
in
environ
:
return
environ
[
'
wsgi.file_wrapper
'
](
f
)
else
:
return
iter
(
f
.
read
(
4096
),
''
)
# Wrap a file-like object that doesn't support fileno()
def
wrap_app2
(
environ
,
start_response
):
import
StringIO
start_response
(
'
200 OK
'
,
[(
'
Content-Type
'
,
'
text/plain
'
)])
f
=
open
(
'
wsgi.c
'
)
s
=
f
.
read
()
f
.
close
()
f
=
StringIO
.
StringIO
()
f
.
write
(
s
)
f
.
seek
(
0
,
0
)
if
'
wsgi.file_wrapper
'
in
environ
:
return
environ
[
'
wsgi.file_wrapper
'
](
f
)
else
:
return
iter
(
f
.
read
(
4096
),
''
)
import
wasd
from
wsgiref.handlers
import
CGIHandler
# not elegant (but hey)
qap
=
wasd
.
getvar
(
'
query_string
'
)
if
qap
==
'
app
'
:
CGIHandler
().
run
(
app
)
elif
qap
==
'
test_app
'
:
CGIHandler
().
run
(
test_app
)
elif
qap
==
'
hash_app
'
:
CGIHandler
().
run
(
hash_app
)
elif
qap
==
'
hash_app2
'
:
CGIHandler
().
run
(
hash_app2
)
elif
qap
==
'
hash_app3
'
:
CGIHandler
().
run
(
hash_app3
)
elif
qap
==
'
hash_app4
'
:
CGIHandler
().
run
(
hash_app4
)
else
:
CGIHandler
().
run
(
what
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment