FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PythonSystemAdminTools/serverFilesHTTP.py at master · dgleebits/PythonSystemAdminTools · GitHub
dgleebits
/
PythonSystemAdminTools
Public
Notifications
You must be signed in to change notification settings
Fork
14
Star
21
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
PythonSystemAdminTools
/
serverFilesHTTP.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (39 loc) · 1.43 KB
Breadcrumbs
PythonSystemAdminTools
/
serverFilesHTTP.py
Copy path
File metadata and controls
48 lines (39 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
os
import
posixpath
import
urllib
import
BaseHTTPServer
from
SimpleHTTPServer
import
SimpleHTTPRequestHandler
# modify this to add additional routes
ROUTES
=
(
# [url_prefix , directory_path]
[
'/media'
,
'/var/www/media'
],
[
''
,
'/var/www/site'
]
# empty string for the 'default' match
)
class
RequestHandler
(
SimpleHTTPRequestHandler
):
def
translate_path
(
self
,
path
):
"""translate path given routes"""
# set default root to cwd
root
=
os
.
getcwd
()
# look up routes and set root directory accordingly
for
pattern
,
rootdir
in
ROUTES
:
if
path
.
startswith
(
pattern
):
# found match!
path
=
path
[
len
(
pattern
):]
# consume path up to pattern len
root
=
rootdir
break
# normalize path and prepend root directory
path
=
path
.
split
(
'?'
,
1
)[
0
]
path
=
path
.
split
(
'#'
,
1
)[
0
]
path
=
posixpath
.
normpath
(
urllib
.
unquote
(
path
))
words
=
path
.
split
(
'/'
)
words
=
filter
(
None
,
words
)
path
=
root
for
word
in
words
:
drive
,
word
=
os
.
path
.
splitdrive
(
word
)
head
,
word
=
os
.
path
.
split
(
word
)
if
word
in
(
os
.
curdir
,
os
.
pardir
):
continue
path
=
os
.
path
.
join
(
path
,
word
)
return
path
if
__name__
==
'__main__'
:
BaseHTTPServer
.
test
(
RequestHandler
,
BaseHTTPServer
.
HTTPServer
)
Back
|
FazBrowse Home
|
New Git URL