FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Platforms/emscripten/web_example/server.py at 3.15 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.5k
(2.5k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Platforms
/
emscripten
/
web_example
/
server.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
46 lines (37 loc) · 1.03 KB
Breadcrumbs
cpython
/
Platforms
/
emscripten
/
web_example
/
server.py
Copy path
File metadata and controls
executable file
·
46 lines (37 loc) · 1.03 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
#!/usr/bin/env python
import
argparse
from
http
import
server
parser
=
argparse
.
ArgumentParser
(
description
=
"Start a local webserver with a Python terminal."
)
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
8000
,
help
=
"port for the http server to listen on"
,
)
parser
.
add_argument
(
"--bind"
,
type
=
str
,
default
=
"127.0.0.1"
,
help
=
"Bind address (empty for all)"
,
)
class
MyHTTPRequestHandler
(
server
.
SimpleHTTPRequestHandler
):
def
end_headers
(
self
)
->
None
:
self
.
send_my_headers
()
super
().
end_headers
()
def
send_my_headers
(
self
)
->
None
:
self
.
send_header
(
"Cross-Origin-Opener-Policy"
,
"same-origin"
)
self
.
send_header
(
"Cross-Origin-Embedder-Policy"
,
"require-corp"
)
def
main
()
->
None
:
args
=
parser
.
parse_args
()
if
not
args
.
bind
:
args
.
bind
=
None
server
.
test
(
# type: ignore[attr-defined]
HandlerClass
=
MyHTTPRequestHandler
,
protocol
=
"HTTP/1.1"
,
port
=
args
.
port
,
bind
=
args
.
bind
,
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL