mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-05-01 06:34:53 +02:00
Update flake8 and pyflakes
This commit is contained in:
parent
58d72a93d2
commit
f8086dfa59
@ -1,5 +1,5 @@
|
|||||||
-r requirements.txt
|
-r requirements.txt
|
||||||
pytest==7.1.2
|
pytest==7.1.2
|
||||||
pytest-cov==3.0.0
|
pytest-cov==3.0.0
|
||||||
flake8==4.0.1
|
flake8==5.0.4
|
||||||
pyflakes==2.4.0
|
pyflakes==2.5.0
|
||||||
|
@ -123,14 +123,14 @@ class MultiListener:
|
|||||||
self.bind_called = False
|
self.bind_called = False
|
||||||
|
|
||||||
def setsockopt(self, level, optname, value):
|
def setsockopt(self, level, optname, value):
|
||||||
assert(self.bind_called)
|
assert self.bind_called
|
||||||
if self.v6:
|
if self.v6:
|
||||||
self.v6.setsockopt(level, optname, value)
|
self.v6.setsockopt(level, optname, value)
|
||||||
if self.v4:
|
if self.v4:
|
||||||
self.v4.setsockopt(level, optname, value)
|
self.v4.setsockopt(level, optname, value)
|
||||||
|
|
||||||
def add_handler(self, handlers, callback, method, mux):
|
def add_handler(self, handlers, callback, method, mux):
|
||||||
assert(self.bind_called)
|
assert self.bind_called
|
||||||
socks = []
|
socks = []
|
||||||
if self.v6:
|
if self.v6:
|
||||||
socks.append(self.v6)
|
socks.append(self.v6)
|
||||||
@ -145,7 +145,7 @@ class MultiListener:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def listen(self, backlog):
|
def listen(self, backlog):
|
||||||
assert(self.bind_called)
|
assert self.bind_called
|
||||||
if self.v6:
|
if self.v6:
|
||||||
self.v6.listen(backlog)
|
self.v6.listen(backlog)
|
||||||
if self.v4:
|
if self.v4:
|
||||||
@ -160,7 +160,7 @@ class MultiListener:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
def bind(self, address_v6, address_v4):
|
def bind(self, address_v6, address_v4):
|
||||||
assert(not self.bind_called)
|
assert not self.bind_called
|
||||||
self.bind_called = True
|
self.bind_called = True
|
||||||
if address_v6 is not None:
|
if address_v6 is not None:
|
||||||
self.v6 = socket.socket(socket.AF_INET6, self.type, self.proto)
|
self.v6 = socket.socket(socket.AF_INET6, self.type, self.proto)
|
||||||
@ -189,7 +189,7 @@ class MultiListener:
|
|||||||
self.v4 = None
|
self.v4 = None
|
||||||
|
|
||||||
def print_listening(self, what):
|
def print_listening(self, what):
|
||||||
assert(self.bind_called)
|
assert self.bind_called
|
||||||
if self.v6:
|
if self.v6:
|
||||||
listenip = self.v6.getsockname()
|
listenip = self.v6.getsockname()
|
||||||
debug1('%s listening on %r.' % (what, listenip))
|
debug1('%s listening on %r.' % (what, listenip))
|
||||||
@ -374,8 +374,8 @@ class FirewallClient:
|
|||||||
raise Fatal('%r expected STARTED, got %r' % (self.argv, line))
|
raise Fatal('%r expected STARTED, got %r' % (self.argv, line))
|
||||||
|
|
||||||
def sethostip(self, hostname, ip):
|
def sethostip(self, hostname, ip):
|
||||||
assert(not re.search(br'[^-\w\.]', hostname))
|
assert not re.search(br'[^-\w\.]', hostname)
|
||||||
assert(not re.search(br'[^0-9.]', ip))
|
assert not re.search(br'[^0-9.]', ip)
|
||||||
self.pfile.write(b'HOST %s,%s\n' % (hostname, ip))
|
self.pfile.write(b'HOST %s,%s\n' % (hostname, ip))
|
||||||
self.pfile.flush()
|
self.pfile.flush()
|
||||||
|
|
||||||
@ -973,7 +973,7 @@ def main(listenip_v6, listenip_v4,
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
if not bound:
|
if not bound:
|
||||||
assert(last_e)
|
assert last_e
|
||||||
raise last_e
|
raise last_e
|
||||||
tcp_listener.listen(10)
|
tcp_listener.listen(10)
|
||||||
tcp_listener.print_listening("TCP redirector")
|
tcp_listener.print_listening("TCP redirector")
|
||||||
@ -1019,7 +1019,7 @@ def main(listenip_v6, listenip_v4,
|
|||||||
|
|
||||||
dns_listener.print_listening("DNS")
|
dns_listener.print_listening("DNS")
|
||||||
if not bound:
|
if not bound:
|
||||||
assert(last_e)
|
assert last_e
|
||||||
raise last_e
|
raise last_e
|
||||||
else:
|
else:
|
||||||
dnsport_v6 = 0
|
dnsport_v6 = 0
|
||||||
|
@ -250,14 +250,14 @@ def main(method_name, syslog):
|
|||||||
dnsport_v6 = int(ports[2])
|
dnsport_v6 = int(ports[2])
|
||||||
dnsport_v4 = int(ports[3])
|
dnsport_v4 = int(ports[3])
|
||||||
|
|
||||||
assert(port_v6 >= 0)
|
assert port_v6 >= 0
|
||||||
assert(port_v6 <= 65535)
|
assert port_v6 <= 65535
|
||||||
assert(port_v4 >= 0)
|
assert port_v4 >= 0
|
||||||
assert(port_v4 <= 65535)
|
assert port_v4 <= 65535
|
||||||
assert(dnsport_v6 >= 0)
|
assert dnsport_v6 >= 0
|
||||||
assert(dnsport_v6 <= 65535)
|
assert dnsport_v6 <= 65535
|
||||||
assert(dnsport_v4 >= 0)
|
assert dnsport_v4 >= 0
|
||||||
assert(dnsport_v4 <= 65535)
|
assert dnsport_v4 <= 65535
|
||||||
|
|
||||||
debug2('Got ports: %d,%d,%d,%d'
|
debug2('Got ports: %d,%d,%d,%d'
|
||||||
% (port_v6, port_v4, dnsport_v6, dnsport_v4))
|
% (port_v6, port_v4, dnsport_v6, dnsport_v4))
|
||||||
|
@ -52,7 +52,7 @@ def _fill_oldctls(prefix):
|
|||||||
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=get_env())
|
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=get_env())
|
||||||
for line in p.stdout:
|
for line in p.stdout:
|
||||||
line = line.decode()
|
line = line.decode()
|
||||||
assert(line[-1] == '\n')
|
assert line[-1] == '\n'
|
||||||
(k, v) = line[:-1].split(': ', 1)
|
(k, v) = line[:-1].split(': ', 1)
|
||||||
_oldctls[k] = v.strip()
|
_oldctls[k] = v.strip()
|
||||||
rv = p.wait()
|
rv = p.wait()
|
||||||
@ -74,7 +74,7 @@ _changedctls = []
|
|||||||
|
|
||||||
def sysctl_set(name, val, permanent=False):
|
def sysctl_set(name, val, permanent=False):
|
||||||
PREFIX = 'net.inet.ip'
|
PREFIX = 'net.inet.ip'
|
||||||
assert(name.startswith(PREFIX + '.'))
|
assert name.startswith(PREFIX + '.')
|
||||||
val = str(val)
|
val = str(val)
|
||||||
if not _oldctls:
|
if not _oldctls:
|
||||||
_fill_oldctls(PREFIX)
|
_fill_oldctls(PREFIX)
|
||||||
|
@ -127,7 +127,7 @@ class Method(BaseMethod):
|
|||||||
|
|
||||||
def _ipt_proto_ports(proto, fport, lport):
|
def _ipt_proto_ports(proto, fport, lport):
|
||||||
return proto + ('--dport', '%d:%d' % (fport, lport)) \
|
return proto + ('--dport', '%d:%d' % (fport, lport)) \
|
||||||
if fport else proto
|
if fport else proto
|
||||||
|
|
||||||
mark_chain = 'sshuttle-m-%s' % port
|
mark_chain = 'sshuttle-m-%s' % port
|
||||||
tproxy_chain = 'sshuttle-t-%s' % port
|
tproxy_chain = 'sshuttle-t-%s' % port
|
||||||
|
@ -302,7 +302,7 @@ def main(latency_control, latency_buffer_size, auto_hosts, to_nameserver,
|
|||||||
hw.leftover = b('')
|
hw.leftover = b('')
|
||||||
|
|
||||||
def hostwatch_ready(sock):
|
def hostwatch_ready(sock):
|
||||||
assert(hw.pid)
|
assert hw.pid
|
||||||
content = hw.sock.recv(4096)
|
content = hw.sock.recv(4096)
|
||||||
if content:
|
if content:
|
||||||
lines = (hw.leftover + content).split(b('\n'))
|
lines = (hw.leftover + content).split(b('\n'))
|
||||||
@ -380,7 +380,7 @@ def main(latency_control, latency_buffer_size, auto_hosts, to_nameserver,
|
|||||||
|
|
||||||
while mux.ok:
|
while mux.ok:
|
||||||
if hw.pid:
|
if hw.pid:
|
||||||
assert(hw.pid > 0)
|
assert hw.pid > 0
|
||||||
(rpid, rv) = os.waitpid(hw.pid, os.WNOHANG)
|
(rpid, rv) = os.waitpid(hw.pid, os.WNOHANG)
|
||||||
if rpid:
|
if rpid:
|
||||||
raise Fatal(
|
raise Fatal(
|
||||||
|
@ -227,7 +227,7 @@ class SockWrapper:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def write(self, buf):
|
def write(self, buf):
|
||||||
assert(buf)
|
assert buf
|
||||||
return self.uwrite(buf)
|
return self.uwrite(buf)
|
||||||
|
|
||||||
def uread(self):
|
def uread(self):
|
||||||
@ -402,15 +402,15 @@ class Mux(Handler):
|
|||||||
elif cmd == CMD_EXIT:
|
elif cmd == CMD_EXIT:
|
||||||
self.ok = False
|
self.ok = False
|
||||||
elif cmd == CMD_TCP_CONNECT:
|
elif cmd == CMD_TCP_CONNECT:
|
||||||
assert(not self.channels.get(channel))
|
assert not self.channels.get(channel)
|
||||||
if self.new_channel:
|
if self.new_channel:
|
||||||
self.new_channel(channel, data)
|
self.new_channel(channel, data)
|
||||||
elif cmd == CMD_DNS_REQ:
|
elif cmd == CMD_DNS_REQ:
|
||||||
assert(not self.channels.get(channel))
|
assert not self.channels.get(channel)
|
||||||
if self.got_dns_req:
|
if self.got_dns_req:
|
||||||
self.got_dns_req(channel, data)
|
self.got_dns_req(channel, data)
|
||||||
elif cmd == CMD_UDP_OPEN:
|
elif cmd == CMD_UDP_OPEN:
|
||||||
assert(not self.channels.get(channel))
|
assert not self.channels.get(channel)
|
||||||
if self.got_udp_open:
|
if self.got_udp_open:
|
||||||
self.got_udp_open(channel, data)
|
self.got_udp_open(channel, data)
|
||||||
elif cmd == CMD_ROUTES:
|
elif cmd == CMD_ROUTES:
|
||||||
@ -482,8 +482,8 @@ class Mux(Handler):
|
|||||||
if len(self.inbuf) >= (self.want or HDR_LEN):
|
if len(self.inbuf) >= (self.want or HDR_LEN):
|
||||||
(s1, s2, channel, cmd, datalen) = \
|
(s1, s2, channel, cmd, datalen) = \
|
||||||
struct.unpack('!ccHHH', self.inbuf[:HDR_LEN])
|
struct.unpack('!ccHHH', self.inbuf[:HDR_LEN])
|
||||||
assert(s1 == b('S'))
|
assert s1 == b('S')
|
||||||
assert(s2 == b('S'))
|
assert s2 == b('S')
|
||||||
self.want = datalen + HDR_LEN
|
self.want = datalen + HDR_LEN
|
||||||
if self.want and len(self.inbuf) >= self.want:
|
if self.want and len(self.inbuf) >= self.want:
|
||||||
data = self.inbuf[HDR_LEN:self.want]
|
data = self.inbuf[HDR_LEN:self.want]
|
||||||
|
Loading…
Reference in New Issue
Block a user