Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
f16a062d
Commit
f16a062d
authored
Mar 05, 2019
by
eckhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- stub for a compilation-server-module extended
parent
9bf2aea1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
29 deletions
+11
-29
DHParser/server.py
DHParser/server.py
+11
-29
No files found.
DHParser/server.py
View file @
f16a062d
...
...
@@ -53,44 +53,26 @@ class CompilerServer:
self
.
compiler
=
compiler
self
.
max_source_size
=
get_config_value
(
'max_source_size'
)
def
handle_compilation_request
(
self
,
reader
,
writer
):
async
def
handle_compilation_request
(
self
,
reader
:
asyncio
.
StreamReader
,
writer
:
asyncio
.
StreamWriter
):
data
=
await
reader
.
read
(
self
.
max_source_size
+
1
)
if
len
(
data
)
>
self
.
max_source_size
:
writer
.
write
(
BEGIN_TOKEN
+
SERVER_ERROR
+
TOKEN_DELIMITER
+
"Source code to large! Only %iMB allowed."
%
(
self
.
max_source_size
//
(
1024
**
2
))
+
END_TOKEN
)
else
:
pass
# TODO: to be continued
writer
.
write
(
data
)
# for now, only echo
await
writer
.
drain
()
writer
.
close
()
async
def
handle_echo
(
reader
,
writer
):
# TODO: Add deliver/answer-challenge-mechanism here to verify the source
# see file:///usr/share/doc/python/html/library/multiprocessing.html?highlight=connection#module-multiprocessing.connection
data
=
await
reader
.
read
(
100
)
message
=
data
.
decode
()
addr
=
writer
.
get_extra_info
(
'peername'
)
async
def
_compiler_server
(
self
,
address
:
str
,
port
:
int
):
server
=
await
syncio
.
start_server
(
self
.
handle_compilation_request
,
address
,
port
)
async
with
server
:
await
server
.
serve_forever
print
(
f
"Received
{
message
!
r
}
from
{
addr
!
r
}
"
)
def
serve
(
self
,
address
:
str
=
'127.0.0.1'
,
port
:
int
=
8888
):
# TODO: Replace this by a python 3.5. compatible construct...
asyncio
.
run
(
self
.
_compiler_server
())
await
asyncio
.
sleep
(
5
)
print
(
f
"Send:
{
message
!
r
}
"
)
writer
.
write
(
data
)
await
writer
.
drain
()
print
(
"Close the connection"
)
writer
.
close
()
async
def
main
():
server
=
await
asyncio
.
start_server
(
handle_echo
,
'127.0.0.1'
,
8888
)
addr
=
server
.
sockets
[
0
].
getsockname
()
print
(
f
'Serving on
{
addr
}
'
)
async
with
server
:
await
server
.
serve_forever
()
asyncio
.
run
(
main
())
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