Skip to content

Commit c0d19ad

Browse files
committed
python 2.7 is totally fine
1 parent 4e87392 commit c0d19ad

File tree

10 files changed

+50
-34
lines changed

10 files changed

+50
-34
lines changed

bin/partftpy_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def main():
107107
parser.print_help()
108108
sys.exit(1)
109109

110-
class Progress:
110+
class Progress(object):
111111
def __init__(self, out):
112112
self.progress = 0
113113
self.out = out

partftpy/TftpClient.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module implements the TFTP Client functionality. Instantiate an
36
instance of the client, and then use its upload or download method. Logging is
47
performed via a standard logging object set in TftpShared."""
@@ -55,12 +58,8 @@ def download(
5558
5659
Note: If output is a hyphen, stdout is used."""
5760
# We're downloading.
58-
log.debug("Creating download context with the following params:")
59-
log.debug(f"host = {self.host}, port = {self.iport}, filename = {filename}")
60-
log.debug(
61-
"options = %s, packethook = %s, timeout = %s"
62-
% (self.options, packethook, timeout)
63-
)
61+
t = "DL-ctx: host = %s, port = %s, filename = %s, options = %s, packethook = %s, timeout = %s"
62+
log.debug(t, self.host, self.iport, filename, self.options, packethook, timeout)
6463
self.context = TftpContextClientDownload(
6564
self.host,
6665
self.iport,

partftpy/TftpContexts.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module implements all contexts for state handling during uploads and
36
downloads, the main interface to which being the TftpContext base class.
47
@@ -28,7 +31,7 @@
2831
###############################################################################
2932

3033

31-
class TftpMetrics:
34+
class TftpMetrics(object):
3235
"""A class representing metrics of the transfer."""
3336

3437
def __init__(self):
@@ -78,7 +81,7 @@ def add_dup(self, pkt):
7881
###############################################################################
7982

8083

81-
class TftpContext:
84+
class TftpContext(object):
8285
"""The base class of the contexts."""
8386

8487
def __init__(self, host, port, timeout, retries=DEF_TIMEOUT_RETRIES, localip=""):
@@ -247,7 +250,7 @@ def __init__(
247250
self.upload_open = upload_open
248251

249252
def __str__(self):
250-
return f"{self.host}:{self.port} {self.state}"
253+
return "%s:%s %s" % (self.host, self.port, self.state)
251254

252255
def start(self, buffer):
253256
"""
@@ -314,7 +317,7 @@ def __init__(
314317
)
315318

316319
def __str__(self):
317-
return f"{self.host}:{self.port} {self.state}"
320+
return "%s:%s %s" % (self.host, self.port, self.state)
318321

319322
def start(self):
320323
log.info("Sending tftp upload request to %s" % self.host)
@@ -400,7 +403,7 @@ def __init__(
400403
)
401404

402405
def __str__(self):
403-
return f"{self.host}:{self.port} {self.state}"
406+
return "%s:%s %s" % (self.host, self.port, self.state)
404407

405408
def start(self):
406409
"""Initiate the download."""

partftpy/TftpPacketFactory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module implements the TftpPacketFactory class, which can take a binary
36
buffer, and return the appropriate TftpPacket object to represent it, via the
47
parse() method."""
@@ -12,7 +15,7 @@
1215
log = logging.getLogger("partftpy.TftpPacketFactory")
1316

1417

15-
class TftpPacketFactory:
18+
class TftpPacketFactory(object):
1619
"""This class generates TftpPacket objects. It is responsible for parsing
1720
raw buffers off of the wire and returning objects representing them, via
1821
the parse() method."""

partftpy/TftpPacketTypes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module implements the packet types of TFTP itself, and the
36
corresponding encode and decode methods for them."""
47

@@ -12,15 +15,15 @@
1215
log = logging.getLogger("partftpy.TftpPacketTypes")
1316

1417

15-
class TftpSession:
18+
class TftpSession(object):
1619
"""This class is the base class for the tftp client and server. Any shared
1720
code should be in this class."""
1821

1922
# FIXME: do we need this anymore?
2023
pass
2124

2225

23-
class TftpPacketWithOptions:
26+
class TftpPacketWithOptions(object):
2427
"""This class exists to permit some TftpPacket subclasses to share code
2528
regarding options handling. It does not inherit from TftpPacket, as the
2629
goal is just to share code here, and not cause diamond inheritance."""
@@ -99,7 +102,7 @@ def decode_options(self, buffer):
99102
return options
100103

101104

102-
class TftpPacket:
105+
class TftpPacket(object):
103106
"""This class is the parent class of all tftp packet classes. It is an
104107
abstract class, providing an interface, and should not be instantiated
105108
directly."""

partftpy/TftpServer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module implements the TFTP Server functionality. Instantiate an
36
instance of the server, and then run the listen() method to listen for client
47
requests. Logging is performed via a standard logging object set in
@@ -58,7 +61,7 @@ def __init__(self, tftproot="/tftpboot", dyn_file_func=None, upload_open=None):
5861
for name in "dyn_file_func", "upload_open":
5962
attr = getattr(self, name)
6063
if attr and not callable(attr):
61-
raise TftpException(f"{name} supplied, but it is not callable.")
64+
raise TftpException("%s supplied, but it is not callable." % (name,))
6265
if os.path.exists(self.root):
6366
log.debug("tftproot %s does exist", self.root)
6467
if not os.path.isdir(self.root):
@@ -92,7 +95,7 @@ def listen(
9295
# listenip = listenip if listenip else '0.0.0.0'
9396
if not listenip:
9497
listenip = "0.0.0.0"
95-
log.info(f"Server requested on ip {listenip}, port {listenport}")
98+
log.info("Server requested on ip %s, port %s" % (listenip, listenport))
9699
try:
97100
# FIXME - sockets should be non-blocking
98101
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -163,7 +166,7 @@ def listen(
163166

164167
# Forge a session key based on the client's IP and port,
165168
# which should safely work through NAT.
166-
key = f"{raddress}:{rport}"
169+
key = "%s:%s" % (raddress, rport)
167170

168171
if key not in self.sessions:
169172
log.debug(

partftpy/TftpShared.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module holds all objects shared by all other modules in partftpy."""
36

47

@@ -28,7 +31,7 @@ def tftpassert(condition, msg):
2831
raise TftpException(msg)
2932

3033

31-
class TftpErrors:
34+
class TftpErrors(object):
3235
"""This class is a convenience for defining the common tftp error codes,
3336
and making them more readable in the code."""
3437

partftpy/TftpStates.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""This module implements all state handling during uploads and downloads, the
36
main interface to which being the TftpState base class.
47
@@ -25,7 +28,7 @@
2528
###############################################################################
2629

2730

28-
class TftpState:
31+
class TftpState(object):
2932
"""The base class for the states."""
3033

3134
def __init__(self, context):
@@ -48,7 +51,7 @@ def handleOACK(self, pkt):
4851
# Set options to OACK options
4952
self.context.options = pkt.options
5053
for key in self.context.options:
51-
log.info(f" {key} = {self.context.options[key]}")
54+
log.info(" %s = %s", key, self.context.options[key])
5255
else:
5356
log.error("Failed to negotiate options")
5457
raise TftpException("Failed to negotiate options")
@@ -168,7 +171,7 @@ def sendOACK(self):
168171
def resendLast(self):
169172
"""Resend the last sent packet due to a timeout."""
170173
assert( self.context.last_pkt is not None )
171-
log.warning(f"Resending packet {self.context.last_pkt} on sessions {self}")
174+
log.warning("Resending packet %s on sessions %s", self.context.last_pkt, self)
172175
self.context.metrics.resent_bytes += len(self.context.last_pkt.buffer)
173176
self.context.metrics.add_dup(self.context.last_pkt)
174177
sendto_port = self.context.tidport
@@ -335,7 +338,7 @@ def handle(self, pkt, raddress, rport):
335338
else:
336339
log.warning("File not found: %s", path)
337340
self.sendError(TftpErrors.FileNotFound)
338-
raise TftpException(f"File not found: {path}")
341+
raise TftpException("File not found: %s" % (path,))
339342

340343
# Options negotiation.
341344
if sendoack and "tsize" in self.context.options:
@@ -630,7 +633,7 @@ def handle(self, pkt, raddress, rport):
630633
if pkt.errorcode == TftpErrors.FileNotFound:
631634
raise TftpFileNotFoundError("File not found")
632635
else:
633-
raise TftpException(f"Received ERR from server: {pkt}")
636+
raise TftpException("Received ERR from server: %s" % (pkt,))
634637

635638
else:
636639
self.sendError(TftpErrors.IllegalTftpOp)

partftpy/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1+
# coding: utf-8
12
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
"""
36
This library implements the tftp protocol, based on rfc 1350.
47
http://www.faqs.org/rfcs/rfc1350.html
58
"""
69

7-
import sys
8-
910
import pkg_resources
1011

11-
# Make sure that this is at least Python 3
12-
required_version = (3, 0)
13-
if sys.version_info < required_version:
14-
raise ImportError("Requires at least Python 3.0")
15-
1612
from . import __name__ as pkg_name
1713

1814

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#!/usr/bin/env python
1+
# coding: utf-8
2+
# vim: ts=4 sw=4 et ai:
3+
from __future__ import print_function, unicode_literals
4+
25
# vim: ts=4 sw=4 et ai:
36
import os
47

@@ -27,7 +30,7 @@ def read_file(fname):
2730
"setuptools_scm[toml]",
2831
"setuptools_scm_git_archive >= 1.0",
2932
],
30-
python_requires=">=3.6",
33+
python_requires=">=2.7",
3134
classifiers=[
3235
"Programming Language :: Python :: 3",
3336
"Development Status :: 4 - Beta",

0 commit comments

Comments
 (0)