diff options
author | Michael P. Soulier <msoulier@digitaltorque.ca> | 2018-09-13 12:48:16 -0400 |
---|---|---|
committer | Michael P. Soulier <msoulier@digitaltorque.ca> | 2018-09-13 12:48:16 -0400 |
commit | 336d4e0b0e4dc38ca4b905a9d14aed56d9046a5e (patch) | |
tree | fcca9fcc6804ff2f5eebf3d511cfa4048497d02b /tftpy | |
parent | d86b9df73d3d00c0abde7acc264e89824685831e (diff) | |
download | tftpy-336d4e0b0e4dc38ca4b905a9d14aed56d9046a5e.tar.gz |
Fixing more encoding issues for python3.
Diffstat (limited to 'tftpy')
-rw-r--r-- | tftpy/TftpPacketTypes.py | 13 | ||||
-rw-r--r-- | tftpy/TftpStates.py | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/tftpy/TftpPacketTypes.py b/tftpy/TftpPacketTypes.py index deb5b52..3d3bdf8 100644 --- a/tftpy/TftpPacketTypes.py +++ b/tftpy/TftpPacketTypes.py @@ -294,11 +294,14 @@ class TftpPacketDAT(TftpPacket): returns self for easy method chaining.""" if len(self.data) == 0: log.debug("Encoding an empty DAT packet") - fmt = b"!HH%ds" % len(self.data) + data = self.data + if not isinstance(self.data, bytes): + data = self.data.encode('ascii') + fmt = b"!HH%ds" % len(data) self.buffer = struct.pack(fmt, self.opcode, self.blocknumber, - self.data) + data) return self def decode(self): @@ -449,8 +452,10 @@ class TftpPacketOACK(TftpPacket, TftpPacketWithOptions): value = self.options[key] if isinstance(value, int): value = str(value) - key = key.encode('ascii') - value = value.encode('ascii') + if not isinstance(key, bytes): + key = key.encode('ascii') + if not isinstance(value, bytes): + value = value.encode('ascii') log.debug("looping on option key %s", key) log.debug("value is %s", value) fmt += b"%dsx" % len(key) diff --git a/tftpy/TftpStates.py b/tftpy/TftpStates.py index b3e108b..42bac1d 100644 --- a/tftpy/TftpStates.py +++ b/tftpy/TftpStates.py @@ -269,10 +269,10 @@ class TftpServerState(TftpState): # begin with a '/' strip it off as otherwise os.path.join will # treat it as absolute (regardless of whether it is ntpath or # posixpath module - if pkt.filename.startswith(self.context.root.encode()): + if pkt.filename.startswith(self.context.root): full_path = pkt.filename else: - full_path = os.path.join(self.context.root, pkt.filename.decode().lstrip('/')) + full_path = os.path.join(self.context.root, pkt.filename.lstrip('/')) # Use abspath to eliminate any remaining relative elements # (e.g. '..') and ensure that is still within the server's |