Skip to content

Commit

Permalink
Don't use Python 3.6 f"strings", RTD only has Python 3.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Jan 23, 2018
1 parent 4f1bbd1 commit 378f08e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Contents:
prerequisites
getting_started
commands
hostlibrary
host_library
faq
2 changes: 1 addition & 1 deletion docs/prerequisites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Prerequisites
*libfx2* has the following dependencies:

* make and sdcc_ for building the firmware code,
* `Python 3.6+ <python_>`_ and `Python libusb1 wrapper <python-libusb1_>`_ for interacting with the device.
* `Python 3 <python_>`_ and `Python libusb1 wrapper <python-libusb1_>`_ for interacting with the device.

On a Debian system, these can be installed with:

Expand Down
5 changes: 3 additions & 2 deletions software/fx2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, vid=VID_CYPRESS, pid=PID_FX2):
self._context = usb1.USBContext()
self._device = self._context.openByVendorIDAndProductID(vid, pid)
if self._device is None:
raise FX2DeviceError(f"Device {vid:04x}:{pid:04x} not found")
raise FX2DeviceError("Device {04x}:{04x} not found".format(vid, pid))
self._device.setAutoDetachKernelDriver(True)

self._eeprom_size = None
Expand Down Expand Up @@ -61,7 +61,8 @@ def _eeprom_cmd(addr_width):
elif addr_width == 2:
return _CMD_RW_EEPROM_DB
else:
raise ValueError(f"Address width {addr_width} is not supported")
raise ValueError("Address width {addr_width} is not supported"
.format(addr_width=addr_width))

def read_eeprom(self, addr, length, addr_width):
"""Read ``length`` bytes at ``addr`` from boot EEPROM."""
Expand Down
20 changes: 10 additions & 10 deletions software/fx2/fx2tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class VID_PID(collections.namedtuple("VID_PID", "vid pid")):
def parse(cls, s):
match = re.match(r"^([0-9a-f]{1,4}):([0-9a-f]{1,4})$", s, re.I)
if not match:
raise ValueError(f"{s} is not a VID:PID pair")
raise ValueError("{} is not a VID:PID pair".format(s))
vid = int(match.group(1), 16)
pid = int(match.group(2), 16)
return cls(vid, pid)

def __str__(self):
return f"{self.vid:04x}:{self.pid:04x}"
return "{04x}:{04x}".format(self.vid, self.pid)


class TextHelpFormatter(argparse.HelpFormatter):
Expand Down Expand Up @@ -49,13 +49,13 @@ def vid_pid(arg):
try:
return VID_PID.parse(arg)
except ValueError:
raise argparse.ArgumentTypeError(f"{arg} is not a VID:PID pair")
raise argparse.ArgumentTypeError("{} is not a VID:PID pair".format(arg))

def int_with_base(arg):
try:
return int(arg, 0)
except ValueError:
raise argparse.ArgumentTypeError(f"{arg} is not an integer")
raise argparse.ArgumentTypeError("{} is not an integer".format(arg))

parser = argparse.ArgumentParser(
formatter_class=TextHelpFormatter,
Expand Down Expand Up @@ -187,7 +187,7 @@ def output_data(fmt, file, data, offset):
elif fmt == "hex":
n = 0
for n, byte in enumerate(data):
file.write(f"{byte:02x}".encode())
file.write("{02x}".format(byte).encode())
if n > 0 and n % 16 == 15:
file.write(b"\n")
elif n > 0 and n % 8 == 7:
Expand Down Expand Up @@ -253,21 +253,21 @@ def input_data(fmt, file, data, offset):
while pos < len(data):
match = RE_HDR.match(data, pos)
if match is None:
raise SystemExit(f"Invalid record header at offset {pos}")
raise SystemExit("Invalid record header at offset {}".format(pos))
*rechdr, = bytes.fromhex(match.group(1).decode())
reclen, recoffh, recoffl, rectype = rechdr

recdatahex = data[match.end(0):match.end(0)+(reclen+1)*2]
if len(recdatahex) < (reclen + 1) * 2:
raise SystemExit(f"Truncated record at offset {pos}")
raise SystemExit("Truncated record at offset {}".format(pos))
try:
*recdata, recsum = bytes.fromhex(recdatahex.decode())
except ValueError:
raise SystemExit(f"Invalid record data at offset {pos}")
raise SystemExit("Invalid record data at offset {}".format(pos))
if sum(rechdr + recdata + [recsum]) & 0xff != 0:
raise SystemExit(f"Invalid record checksum at offset {pos}")
raise SystemExit("Invalid record checksum at offset {}".format(pos))
if rectype not in [0x00, 0x01]:
raise SystemExit(f"Unknown record type at offset {pos}")
raise SystemExit("Unknown record type at offset {}".format(pos))
if rectype == 0x01:
break

Expand Down

0 comments on commit 378f08e

Please sign in to comment.