Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
augustin_s
pier
Commits
a3ae4c16
Commit
a3ae4c16
authored
May 10, 2022
by
augustin_s
🐍
Browse files
first try
parent
134662d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
0 deletions
+61
-0
example1.py
example1.py
+5
-0
example2.py
example2.py
+5
-0
pier.py
pier.py
+51
-0
No files found.
example1.py
0 → 100755
View file @
a3ae4c16
#!/usr/bin/env python
print
(
"running example 1"
)
example2.py
0 → 100755
View file @
a3ae4c16
#!/usr/bin/env python
print
(
"running example 2"
)
pier.py
0 → 100755
View file @
a3ae4c16
#!/usr/bin/env python3
from
glob
import
glob
import
http.server
import
socketserver
HOST
=
"localhost"
PORT
=
9090
class
ScriptServer
(
http
.
server
.
SimpleHTTPRequestHandler
):
def
do_GET
(
self
):
scr
=
self
.
path
.
strip
(
"/"
)
if
not
scr
.
endswith
(
".py"
):
scr
+=
".py"
scripts
=
sorted
(
glob
(
"*.py"
))
if
scr
not
in
scripts
:
printable_scripts
=
"
\n
"
.
join
(
scripts
)
self
.
send_result
(
f
"
{
scr
}
does not exist. choose from:
\n
"
,
printable_scripts
)
return
with
open
(
scr
)
as
f
:
exec
(
f
.
read
())
self
.
send_result
(
scr
)
def
send_result
(
self
,
*
msg
):
self
.
send_response
(
200
)
self
.
send_header
(
"Content-type"
,
"text/html"
)
self
.
end_headers
()
msg
=
" "
.
join
(
msg
)
msg
=
msg
.
split
(
"
\n
"
)
msg
=
"<br>"
.
join
(
msg
)
msg
=
msg
.
encode
()
self
.
wfile
.
write
(
msg
)
print
(
msg
)
if
__name__
==
"__main__"
:
socketserver
.
TCPServer
.
allow_reuse_address
=
True
with
socketserver
.
ThreadingTCPServer
((
HOST
,
PORT
),
ScriptServer
)
as
httpd
:
print
(
f
"serving at
{
HOST
}
:
{
PORT
}
"
)
httpd
.
serve_forever
()
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