Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
helloweb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
helloweb
Commits
a072af78
Commit
a072af78
authored
Jul 26, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python: Port it to Python3
The code is now unified - it can work on both python2 and python3.
parent
39fd89a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
python/helloweb.py
python/helloweb.py
+14
-5
No files found.
python/helloweb.py
View file @
a072af78
...
@@ -4,10 +4,17 @@
...
@@ -4,10 +4,17 @@
helloweb.py [--logfile <logfile>] <bind-ip> <bind-port> ...
helloweb.py [--logfile <logfile>] <bind-ip> <bind-port> ...
"""
"""
from
__future__
import
print_function
import
sys
import
sys
PY3
=
sys
.
version_info
.
major
>=
3
import
time
import
time
import
argparse
import
argparse
from
BaseHTTPServer
import
BaseHTTPRequestHandler
,
HTTPServer
if
PY3
:
from
http.server
import
BaseHTTPRequestHandler
,
HTTPServer
else
:
from
BaseHTTPServer
import
BaseHTTPRequestHandler
,
HTTPServer
from
socket
import
AF_INET6
from
socket
import
AF_INET6
...
@@ -18,10 +25,12 @@ class WebHello(BaseHTTPRequestHandler):
...
@@ -18,10 +25,12 @@ class WebHello(BaseHTTPRequestHandler):
self
.
send_header
(
"Content-type"
,
"text/plain"
)
self
.
send_header
(
"Content-type"
,
"text/plain"
)
self
.
end_headers
()
self
.
end_headers
()
print
>>
self
.
wfile
,
\
msg
=
"Hello %s at `%s` ; %s (python %s)"
%
(
"Hello %s at `%s` ; %s (python %s)"
%
(
' '
.
join
(
self
.
server
.
webhello_argv
)
or
'world'
,
' '
.
join
(
self
.
server
.
webhello_argv
)
or
'world'
,
self
.
path
,
time
.
asctime
(),
sys
.
version
.
replace
(
'
\
n
'
,
' '
))
self
.
path
,
time
.
asctime
(),
sys
.
version
.
replace
(
'
\
n
'
,
' '
))
if
PY3
:
msg
=
msg
.
encode
()
self
.
wfile
.
write
(
msg
)
class
HTTPServerV6
(
HTTPServer
):
class
HTTPServerV6
(
HTTPServer
):
...
@@ -41,8 +50,8 @@ def main():
...
@@ -41,8 +50,8 @@ def main():
f
=
open
(
args
.
logfile
,
'a'
,
buffering
=
1
)
f
=
open
(
args
.
logfile
,
'a'
,
buffering
=
1
)
sys
.
stderr
=
f
sys
.
stderr
=
f
print
>>
sys
.
stderr
,
'* %s helloweb.py starting at %s'
%
(
print
(
'* %s helloweb.py starting at %s'
%
(
time
.
asctime
(),
(
args
.
bind_ip
,
args
.
bind_port
))
time
.
asctime
(),
(
args
.
bind_ip
,
args
.
bind_port
))
,
file
=
sys
.
stderr
)
# TODO autodetect ipv6/ipv4
# TODO autodetect ipv6/ipv4
httpd
=
HTTPServerV6
(
(
args
.
bind_ip
,
args
.
bind_port
),
WebHello
)
httpd
=
HTTPServerV6
(
(
args
.
bind_ip
,
args
.
bind_port
),
WebHello
)
...
...
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