Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
2a5cb8db
Commit
2a5cb8db
authored
Sep 03, 2013
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wsgi example fixed
parent
3a3f4991
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
17 deletions
+27
-17
fs/expose/wsgi/dirtemplate.py
+8
-5
fs/expose/wsgi/serve_home.py
+6
-0
fs/expose/wsgi/wsgi.py
+13
-12
No files found.
fs/expose/wsgi/dirtemplate.py
View file @
2a5cb8db
...
...
@@ -15,6 +15,7 @@ table.dirlist {
margin:0 auto;
font-size:13px;
color:#666;
min-width:960px;
}
table.dirlist tr.r1 {
...
...
@@ -58,19 +59,21 @@ table.dirlist tr:hover {
<table class="dirlist">
<thead>
<tr>
<th>File/Directory</th>
<th>Size</th>
<th>Created Date</th>
</tr>
</thead>
<tbody>
%
for i, entry in enumerate(dirlist):
<tr class="${entry['type']} r${i
%2
}">
<td><a class="link-${entry['type']}" href="${ entry['path'] }">${entry['name']}</a></td>
<td>${entry['size']}</td>
<td>${entry['created_time']}</td>
</tr>
%
endfor
</tbody>
</table>
...
...
fs/expose/wsgi/serve_home.py
View file @
2a5cb8db
from
wsgiref.simple_server
import
make_server
from
fs.osfs
import
OSFS
from
wsgi
import
serve_fs
osfs
=
OSFS
(
'~/'
)
application
=
serve_fs
(
osfs
)
httpd
=
make_server
(
''
,
8000
,
application
)
print
"Serving on http://127.0.0.1:8000"
httpd
.
serve_forever
()
fs/expose/wsgi/wsgi.py
View file @
2a5cb8db
...
...
@@ -62,22 +62,24 @@ class WSGIServer(object):
serving_file
.
close
()
return
self
.
serve_500
(
request
,
str
(
e
))
mime_type
=
mimetypes
.
guess_type
(
basename
(
path
))
mime_type
=
mimetypes
.
guess_type
(
basename
(
path
))
[
0
]
or
b
'text/plain'
file_size
=
self
.
serve_fs
.
getsize
(
path
)
headers
=
[(
'Content-Type'
,
mime_type
),
(
'Content-Length'
,
str
(
file_size
))]
headers
=
[(
b
'Content-Type'
,
bytes
(
mime_type
)
),
(
b
'Content-Length'
,
bytes
(
file_size
))]
def
gen_file
():
chunk_size
=
self
.
chunk_size
read
=
serving_file
.
read
try
:
while
True
:
data
=
serving_file
.
read
(
self
.
chunk_size
)
while
1
:
data
=
read
(
chunk_size
)
if
not
data
:
break
yield
data
finally
:
serving_file
.
close
()
request
.
start_response
(
'200 OK'
,
request
.
start_response
(
b
'200 OK'
,
headers
)
return
gen_file
()
...
...
@@ -121,22 +123,21 @@ class WSGIServer(object):
# Render the mako template
html
=
self
.
dir_template
.
render
(
**
dict
(
fs
=
self
.
serve_fs
,
path
=
path
,
dirlist
=
entries
))
request
.
start_response
(
'200 OK'
,
[(
'Content-Type'
,
'text/html'
),
(
'Content-Length'
,
'
%
i'
%
len
(
html
))])
dirlist
=
entries
))
.
encode
(
'utf-8'
)
request
.
start_response
(
b
'200 OK'
,
[(
b
'Content-Type'
,
b
'text/html'
),
(
b
'Content-Length'
,
b
'
%
i'
%
len
(
html
))])
return
[
html
]
def
serve_404
(
self
,
request
,
msg
=
'Not found'
):
"""Serves a Not found page"""
request
.
start_response
(
'404 NOT FOUND'
,
[(
'Content-Type'
,
'text/html'
)])
request
.
start_response
(
b
'404 NOT FOUND'
,
[(
b
'Content-Type'
,
b
'text/html'
)])
return
[
msg
]
def
serve_500
(
self
,
request
,
msg
=
'Unable to complete request'
):
"""Serves an internal server error page"""
request
.
start_response
(
'500 INTERNAL SERVER ERROR'
,
[(
'Content-Type'
,
'text/html'
)])
request
.
start_response
(
b
'500 INTERNAL SERVER ERROR'
,
[(
b
'Content-Type'
,
b
'text/html'
)])
return
[
msg
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment