Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use f-strings #87

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tnefparse/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def tnefparse() -> None:
except ValueError as exc:
sys.exit(str(exc))
if args.overview:
print("\nOverview of %s: \n" % tfp.name)
print(f"\nOverview of {tfp.name}: \n")

# list TNEF attachments
print(" Attachments:\n")
Expand Down Expand Up @@ -111,7 +111,7 @@ def tnefparse() -> None:
def print_body(attr: str, description: str) -> None:
body = getattr(t, attr)
if body is None:
sys.exit("No %s found" % description)
sys.exit(f"No {description} found")
elif isinstance(body, bytes):
sys.stdout.write(body.decode('latin-1'))
else:
Expand Down
4 changes: 2 additions & 2 deletions tnefparse/codepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def best_guess(self) -> Optional[str]:
if CODEPAGE_MAP.get(self.cp):
return CODEPAGE_MAP.get(self.cp)
elif self.cp <= 1258: # max cpXXXX page in python
return 'cp%d' % self.cp
return f"cp{self.cp}"
else:
return None

Expand All @@ -27,7 +27,7 @@ def codepage(self) -> str:
if bg:
return bg
else:
return 'cp%d' % self.cp
return f"cp{self.cp}"

def decode(self, byte_str: Union[str, bytes]) -> str:
if isinstance(byte_str, bytes):
Expand Down
2 changes: 1 addition & 1 deletion tnefparse/mapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def parse_property(data, offset, attr_name, attr_type, codepage, is_multi):
offset += length

else:
raise ValueError("Unknown MAPI type 0x%4.4x" % attr_type)
raise ValueError(f"Unknown MAPI type {attr_type:#06x}")

return attr_data, offset

Expand Down
6 changes: 3 additions & 3 deletions tnefparse/tnef.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def add_attr(self, attribute):
logger.debug("Unknown attribute name: %s", attribute)

def __str__(self):
return "<ATTCH:'%s'>" % self.long_filename()
return f"<ATTCH:{self.long_filename()}>"


class TNEF:
Expand Down Expand Up @@ -228,7 +228,7 @@ class TNEF:
def __init__(self, data, do_checksum=True):
self.signature = uint32(data)
if self.signature != TNEF.TNEF_SIGNATURE:
raise ValueError("Wrong TNEF signature: 0x%2.8x" % self.signature)
raise ValueError(f"Wrong TNEF signature: {self.signature:#010x}")
self.key = uint16(data, 4)
self.codepage = None
self.objects = []
Expand Down Expand Up @@ -340,7 +340,7 @@ def rtfbody(self):
return None

def __str__(self):
atts = (", %i attachments" % len(self.attachments)) if self.attachments else ''
atts = f", {len(self.attachments)} attachments" if self.attachments else ''
return f"<{self.__class__.__name__}:0x{self.key:02x}{atts}>"

def dump(self, force_strings=False):
Expand Down