Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
typon-concurrency
Commits
6cd4878c
Commit
6cd4878c
authored
Dec 01, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add webserver_eval example
parent
5ae60b33
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
typon/trans/tests/webserver_eval.py
typon/trans/tests/webserver_eval.py
+56
-0
No files found.
typon/trans/tests/webserver_eval.py
0 → 100644
View file @
6cd4878c
# coding: utf-8
# norun
import
sys
from
socket
import
socket
,
SOCK_STREAM
,
AF_INET6
,
SOL_SOCKET
,
SO_REUSEADDR
from
typon
import
fork
from
builtins
import
eval
#fork = lambda x: x()
BACKLOG
=
1024
PORT
=
8000
response_fmt
=
\
"HTTP/1.0 200 OK
\
r
\
n
"
\
"Content-type: text/plain
\
r
\
n
"
\
"Content-length: {}
\
r
\
n
"
\
"
\
r
\
n
"
\
"{}"
def
create_listening_socket
(
port
):
sockfd
=
socket
(
AF_INET6
,
SOCK_STREAM
)
sockfd
.
setsockopt
(
SOL_SOCKET
,
SO_REUSEADDR
,
1
)
sockfd
.
bind
((
""
,
port
))
sockfd
.
listen
(
BACKLOG
)
return
sockfd
def
handle_connection
(
connfd
):
buf
=
connfd
.
recv
(
1024
).
decode
(
"utf-8"
)
resp
:
str
if
not
buf
.
startswith
(
"GET /eval?e="
):
resp
=
"Expression missing"
else
:
http_pos
=
buf
.
find
(
"HTTP/1.1
\
r
\
n
"
)
s
=
"str("
+
buf
[
12
:
http_pos
-
1
]
+
")"
resp
=
eval
(
s
,
{
"req"
:
buf
})
response
=
response_fmt
.
format
(
len
(
resp
),
resp
)
connfd
.
send
(
response
.
encode
(
"utf-8"
))
connfd
.
close
()
def
server_loop
(
sockfd
):
while
True
:
connfd
,
_
=
sockfd
.
accept
()
fork
(
lambda
:
handle_connection
(
connfd
))
def
server_loops
(
sockfd
):
for
i
in
range
(
20
):
fork
(
lambda
:
server_loop
(
sockfd
))
if
__name__
==
"__main__"
:
print
(
"Serving on port"
,
PORT
)
print
()
sockfd
=
create_listening_socket
(
PORT
)
server_loops
(
sockfd
)
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