Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
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
nexedi
nemu3
Commits
743b0191
Commit
743b0191
authored
Jul 21, 2024
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more type hints
parent
d277d777
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
42 deletions
+27
-42
src/nemu/environ.py
src/nemu/environ.py
+8
-7
src/nemu/interface.py
src/nemu/interface.py
+11
-11
src/nemu/iproute.py
src/nemu/iproute.py
+6
-5
src/nemu/protocol.py
src/nemu/protocol.py
+2
-19
No files found.
src/nemu/environ.py
View file @
743b0191
...
@@ -25,6 +25,7 @@ import socket
...
@@ -25,6 +25,7 @@ import socket
import
subprocess
import
subprocess
import
sys
import
sys
import
syslog
import
syslog
import
typing
from
syslog
import
LOG_ERR
,
LOG_WARNING
,
LOG_NOTICE
,
LOG_INFO
,
LOG_DEBUG
from
syslog
import
LOG_ERR
,
LOG_WARNING
,
LOG_NOTICE
,
LOG_INFO
,
LOG_DEBUG
from
typing
import
TypeVar
,
Callable
,
Optional
from
typing
import
TypeVar
,
Callable
,
Optional
...
@@ -164,14 +165,14 @@ def set_log_level(level: int):
...
@@ -164,14 +165,14 @@ def set_log_level(level: int):
_log_level
=
level
_log_level
=
level
def
set_log_output
(
stream
):
def
set_log_output
(
stream
:
typing
.
TextIO
):
"Redirect console messages to the provided stream."
"Redirect console messages to the provided stream."
global
_log_stream
global
_log_stream
assert
hasattr
(
stream
,
"write"
)
and
hasattr
(
stream
,
"flush"
)
assert
hasattr
(
stream
,
"write"
)
and
hasattr
(
stream
,
"flush"
)
_log_stream
=
stream
_log_stream
=
stream
def
log_use_syslog
(
use
=
True
,
ident
=
None
,
logopt
=
0
,
def
log_use_syslog
(
use
=
True
,
ident
:
str
=
None
,
logopt
=
0
,
facility
=
syslog
.
LOG_USER
):
facility
=
syslog
.
LOG_USER
):
"Enable or disable the use of syslog for logging messages."
"Enable or disable the use of syslog for logging messages."
global
_log_use_syslog
,
_log_syslog_opts
global
_log_use_syslog
,
_log_syslog_opts
...
@@ -207,23 +208,23 @@ def logger(priority: int, message: str):
...
@@ -207,23 +208,23 @@ def logger(priority: int, message: str):
_log_stream
.
flush
()
_log_stream
.
flush
()
def
error
(
message
):
def
error
(
message
:
str
):
logger
(
LOG_ERR
,
message
)
logger
(
LOG_ERR
,
message
)
def
warning
(
message
):
def
warning
(
message
:
str
):
logger
(
LOG_WARNING
,
message
)
logger
(
LOG_WARNING
,
message
)
def
notice
(
message
):
def
notice
(
message
:
str
):
logger
(
LOG_NOTICE
,
message
)
logger
(
LOG_NOTICE
,
message
)
def
info
(
message
):
def
info
(
message
:
str
):
logger
(
LOG_INFO
,
message
)
logger
(
LOG_INFO
,
message
)
def
debug
(
message
):
def
debug
(
message
:
str
):
logger
(
LOG_DEBUG
,
message
)
logger
(
LOG_DEBUG
,
message
)
...
...
src/nemu/interface.py
View file @
743b0191
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
import
os
import
os
import
weakref
import
weakref
from
typing
import
TypedDict
from
typing
import
TypedDict
,
Optional
import
nemu.iproute
import
nemu.iproute
from
nemu.environ
import
*
from
nemu.environ
import
*
...
@@ -64,7 +64,7 @@ class Interface:
...
@@ -64,7 +64,7 @@ class Interface:
return
self
.
_idx
return
self
.
_idx
@
property
@
property
def
control
(
self
):
def
control
(
self
)
->
Optional
[
"Interface"
]
:
"""Associated interface in the main name space (if it exists). Only
"""Associated interface in the main name space (if it exists). Only
control interfaces can be put into a Switch, for example."""
control interfaces can be put into a Switch, for example."""
return
None
return
None
...
@@ -175,7 +175,7 @@ class NodeInterface(NSInterface):
...
@@ -175,7 +175,7 @@ class NodeInterface(NSInterface):
super
(
NodeInterface
,
self
).
__init__
(
node
,
ns
.
index
)
super
(
NodeInterface
,
self
).
__init__
(
node
,
ns
.
index
)
@
property
@
property
def
control
(
self
):
def
control
(
self
)
->
"Interface"
:
return
self
.
_control
return
self
.
_control
def
destroy
(
self
):
def
destroy
(
self
):
...
@@ -334,7 +334,7 @@ class ExternalInterface(Interface):
...
@@ -334,7 +334,7 @@ class ExternalInterface(Interface):
namespace."""
namespace."""
@
property
@
property
def
control
(
self
):
def
control
(
self
)
->
"Interface"
:
# This is *the* control interface
# This is *the* control interface
return
self
return
self
...
@@ -508,12 +508,12 @@ class Switch(ExternalInterface):
...
@@ -508,12 +508,12 @@ class Switch(ExternalInterface):
self
.
_apply_parameters
({},
iface
.
control
)
self
.
_apply_parameters
({},
iface
.
control
)
del
self
.
_ports
[
iface
.
control
.
index
]
del
self
.
_ports
[
iface
.
control
.
index
]
def
set_parameters
(
self
,
bandwidth
=
None
,
def
set_parameters
(
self
,
bandwidth
:
int
=
None
,
delay
=
None
,
delay_jitter
=
None
,
delay
:
float
=
None
,
delay_jitter
:
float
=
None
,
delay_correlation
=
None
,
delay_distribution
=
None
,
delay_correlation
:
float
=
None
,
delay_distribution
:
str
=
None
,
loss
=
None
,
loss_correlation
=
None
,
loss
:
float
=
None
,
loss_correlation
:
float
=
None
,
dup
=
None
,
dup_correlation
=
None
,
dup
:
float
=
None
,
dup_correlation
:
float
=
None
,
corrupt
=
None
,
corrupt_correlation
=
None
):
corrupt
:
float
=
None
,
corrupt_correlation
:
float
=
None
):
"""Set the parameters that control the link characteristics. For the
"""Set the parameters that control the link characteristics. For the
description of each, refer to netem documentation:
description of each, refer to netem documentation:
http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
...
@@ -542,6 +542,6 @@ class Switch(ExternalInterface):
...
@@ -542,6 +542,6 @@ class Switch(ExternalInterface):
raise
raise
self
.
_parameters
=
parameters
self
.
_parameters
=
parameters
def
_apply_parameters
(
self
,
parameters
,
port
=
None
):
def
_apply_parameters
(
self
,
parameters
,
port
:
Interface
=
None
):
for
i
in
[
port
]
if
port
else
list
(
self
.
_ports
.
values
()):
for
i
in
[
port
]
if
port
else
list
(
self
.
_ports
.
values
()):
nemu
.
iproute
.
set_tc
(
i
.
index
,
**
parameters
)
nemu
.
iproute
.
set_tc
(
i
.
index
,
**
parameters
)
src/nemu/iproute.py
View file @
743b0191
...
@@ -878,11 +878,12 @@ def clear_tc(iface):
...
@@ -878,11 +878,12 @@ def clear_tc(iface):
execute([TC_PATH, "qdisc", "del", "dev", iface.name, "root"])
execute([TC_PATH, "qdisc", "del", "dev", iface.name, "root"])
def set_tc(iface, bandwidth=None, delay=None, delay_jitter=None,
def set_tc(iface, bandwidth: int = None,
delay_correlation=None, delay_distribution=None,
delay: float = None, delay_jitter: float = None,
loss=None, loss_correlation=None,
delay_correlation: float = None, delay_distribution: str = None,
dup=None, dup_correlation=None,
loss: float = None, loss_correlation: float = None,
corrupt=None, corrupt_correlation=None):
dup: float = None, dup_correlation: float = None,
corrupt: float = None, corrupt_correlation: float = None):
use_netem = bool(delay or delay_jitter or delay_correlation or
use_netem = bool(delay or delay_jitter or delay_correlation or
delay_distribution or loss or loss_correlation or dup or
delay_distribution or loss or loss_correlation or dup or
dup_correlation or corrupt or corrupt_correlation)
dup_correlation or corrupt or corrupt_correlation)
...
...
src/nemu/protocol.py
View file @
743b0191
...
@@ -179,7 +179,7 @@ class Server:
...
@@ -179,7 +179,7 @@ class Server:
debug
(
"<Reply> %s"
%
s
)
debug
(
"<Reply> %s"
%
s
)
return
return
def
readline
(
self
):
def
readline
(
self
)
->
Optional
[
str
]
:
"Read a line from the socket and detect connection break-up."
"Read a line from the socket and detect connection break-up."
# FIXME: should use the eintr_wrapper from environ; why was I using
# FIXME: should use the eintr_wrapper from environ; why was I using
# readline instead of read?
# readline instead of read?
...
@@ -312,7 +312,7 @@ class Server:
...
@@ -312,7 +312,7 @@ class Server:
self
.
reply
(
200
,
reply
)
self
.
reply
(
200
,
reply
)
def
do_QUIT
(
self
,
cmdname
):
def
do_QUIT
(
self
,
cmdname
):
self
.
reply
(
221
,
"Sayounara."
)
;
self
.
reply
(
221
,
"Sayounara."
)
self
.
_closed
=
True
self
.
_closed
=
True
def
do_PROC_CRTE
(
self
,
cmdname
,
executable
,
*
argv
):
def
do_PROC_CRTE
(
self
,
cmdname
,
executable
,
*
argv
):
...
@@ -824,23 +824,6 @@ class Client:
...
@@ -824,23 +824,6 @@ class Client:
self
.
_forwarder
=
_spawn_x11_forwarder
(
server
,
sock
,
addr
)
self
.
_forwarder
=
_spawn_x11_forwarder
(
server
,
sock
,
addr
)
def
_b64_OLD
(
text
:
str
|
bytes
)
->
str
:
if
text
is
None
:
# easier this way
text
=
''
if
type
(
text
)
is
str
:
btext
=
text
.
encode
(
"utf-8"
)
elif
type
(
text
)
is
bytes
:
btext
=
text
else
:
btext
=
text
if
len
(
btext
)
==
0
or
any
(
x
for
x
in
btext
if
x
<=
ord
(
" "
)
or
x
>
ord
(
"z"
)
or
x
==
ord
(
"="
)):
return
"="
+
base64
.
b64encode
(
btext
).
decode
(
"ascii"
)
else
:
return
text
def
_b64
(
text
)
->
str
:
def
_b64
(
text
)
->
str
:
if
text
is
None
:
if
text
is
None
:
# easier this way
# easier this way
...
...
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