Skip to content

Commit c0f5312

Browse files
committed
Administriva
bump testing versions blacken tcpfns.py and update copyright
1 parent b079210 commit c0f5312

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

admin-tools/pyenv-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
77
exit 1
88
fi
99

10-
export PYVERSIONS='3.5.10 3.6.13 3.3.7 3.4.10 3.2.6 3.7.10 3.8.9'
10+
export PYVERSIONS='3.5.10 3.6.13 3.3.7 3.4.10 3.2.6 3.7.10 3.8.10'

trepan/inout/tcpfns.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009-2017 Rocky Bernstein <rocky@gnu.org>
2+
# Copyright (C) 2009-2017, 2021 Rocky Bernstein <rocky@gnu.org>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -16,26 +16,28 @@
1616
"""Subsidiary routines used to "pack" and "unpack" TCP messages. """
1717

1818
TCP_MAX_PACKET = 8192 # Largest size for a recv
19-
LOG_MAX_MSG = 4 # int(log(TCP_MAX_PACKET)
19+
LOG_MAX_MSG = 4 # int(log(TCP_MAX_PACKET)
2020

2121

2222
def pack_msg(msg):
23-
fmt = '%%0%dd' % LOG_MAX_MSG # A funny way of writing: '%04d'
24-
byte_msg = bytes(msg, 'UTF-8')
25-
byte_fmt = bytes(fmt % len(byte_msg), 'UTF-8')
23+
fmt = "%%0%dd" % LOG_MAX_MSG # A funny way of writing: '%04d'
24+
byte_msg = bytes(msg, "UTF-8")
25+
byte_fmt = bytes(fmt % len(byte_msg), "UTF-8")
2626
return byte_fmt + byte_msg
2727

28+
2829
def unpack_msg(buf):
2930
if len(buf) == 0:
3031
# Fake a quit
31-
return '', bytes('q'.encode('utf-8'))
32-
length = int(buf[0:LOG_MAX_MSG])
33-
data = buf[LOG_MAX_MSG:LOG_MAX_MSG+length]
34-
buf = buf[LOG_MAX_MSG+length:]
32+
return "", bytes("q".encode("utf-8"))
33+
length = int(buf[0:LOG_MAX_MSG])
34+
data = buf[LOG_MAX_MSG : LOG_MAX_MSG + length]
35+
buf = buf[LOG_MAX_MSG + length :]
3536
return buf, data
3637

38+
3739
# Demo
38-
if __name__=='__main__':
39-
print(unpack_msg(pack_msg('Hello, there!'))[1])
40+
if __name__ == "__main__":
41+
print(unpack_msg(pack_msg("Hello, there!"))[1])
4042
# assert unpack_msg(pack_msg(msg))[1] == msg
4143
pass

0 commit comments

Comments
 (0)