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
ea64038daf12
Commit
ea64038daf12
authored
4 years ago
by
Jean-Francois Pieronne
Browse files
Options
Downloads
Patches
Plain Diff
src/python/scripts/wsgi_test4.py initial version
parent
5fa999f9b97c
No related branches found
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/scripts/wsgi_test4.py
+68
-0
68 additions, 0 deletions
src/python/scripts/wsgi_test4.py
with
68 additions
and
0 deletions
src/python/scripts/wsgi_test4.py
0 → 100755
+
68
−
0
View file @
ea64038d
def
application
(
environ
,
start_response
):
"""
This demonstrates a minimal http upload CGI.
It can operate as a standard CGI or as a CGIplus script.
It accepts a GIF, JPEG or PNG file and displays it in the browser.
"""
if
os
.
environ
[
"
REQUEST_METHOD
"
]
==
"
POST
"
:
display_uploaded_file
(
start_response
,
"
image_file
"
)
else
:
print_html_form
(
start_response
)
return
(
''
)
def
print_html_form
(
start_response
):
"""
This prints out the html form. Note that the action is set to
the name of the script which makes this is a self-posting form.
In other words, this cgi both displays a form and processes it.
"""
HTML_TEMPLATE
=
"""
<!DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.01 Transitional//EN
"
>
<html><head><title>WSGI_test4.py</title>
<meta http-equiv=
"
Content-Type
"
content=
"
text/html; charset=iso-8859-1
"
>
</head><body><h1>WSGI_test4.py</h1>
<form action=
"
%(SCRIPT_NAME)s
"
method=
"
POST
"
enctype=
"
multipart/form-data
"
>
Image file name: <input name=
"
image_file
"
type=
"
file
"
><br>
<input name=
"
submit
"
type=
"
submit
"
>
</form>
</body>
</html>
"""
wsgi_write
=
start_response
(
'
200 OK
'
,[(
'
Content-type
'
,
'
text/html
'
)])
wsgi_write
(
HTML_TEMPLATE
%
{
'
SCRIPT_NAME
'
:
os
.
environ
[
'
SCRIPT_NAME
'
]})
def
display_uploaded_file
(
start_response
,
form_field
):
"""
This display an image file uploaded by an HTML form.
"""
form
=
cgi
.
FieldStorage
()
if
not
form
.
has_key
(
form_field
):
return
fileitem
=
form
[
form_field
]
if
not
fileitem
.
file
:
return
if
not
fileitem
.
filename
:
return
filename
=
fileitem
.
filename
.
lower
()
status
=
'
200 OK
'
;
if
filename
.
rfind
(
"
.gif
"
)
!=
-
1
:
response_headers
=
[(
'
Content-type
'
,
'
image/gif
'
)]
elif
filename
.
rfind
(
"
.jpg
"
)
!=
-
1
:
response_headers
=
[(
'
Content-type
'
,
'
image/jpeg
'
)]
elif
filename
.
rfind
(
"
.png
"
)
!=
-
1
:
response_headers
=
[(
'
Content-type
'
,
'
image/png
'
)]
else
:
wsgi_write
=
start_response
(
'
200 OK
'
,[(
'
Content-type
'
,
'
text/html
'
)])
wsgi_write
(
"
Only GIFs, JPEGs and PNGs handled by this test.
"
)
return
response_headers
+=
[(
'
expires
'
,
'
01 Jan 2005 00:00:00 GMT
'
)]
wsgi_write
=
start_response
(
status
,
response_headers
)
while
1
:
chunk
=
fileitem
.
file
.
read
(
100000
)
if
not
chunk
:
break
wsgi_write
(
chunk
)
del
fileitem
import
wasd
;
import
cgi
import
cgitb
;
cgitb
.
enable
()
import
os
,
sys
wasd
.
wsgi_run
(
application
)
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