-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace most string forwarding with f-strings
This commit replaces most of the older modulo-based string formatting with f-strings. The one exception is in calls to the logger, which still uses printf-like substitutions. This is left alone, as the logger does additional type-specific formatting of the arguments passed into it.
- Loading branch information
Showing
47 changed files
with
305 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) 2013-2021 by Ron Frederick <[email protected]> and others. | ||
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others. | ||
# | ||
# This program and the accompanying materials are made available under | ||
# the terms of the Eclipse Public License v2.0 which accompanies this | ||
|
@@ -169,8 +169,8 @@ def __init__(self, tag: int, content: bytes, asn1_class: int): | |
self.content = content | ||
|
||
def __repr__(self) -> str: | ||
return ('RawDERObject(%s, %s, %r)' % | ||
(_asn1_class[self.asn1_class], self.tag, self.content)) | ||
return f'RawDERObject({_asn1_class[self.asn1_class]}, ' \ | ||
f'{self.tag}, {self.content!r})' | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, RawDERObject): # pragma: no cover | ||
|
@@ -213,10 +213,10 @@ def __init__(self, tag: int, value: object, | |
|
||
def __repr__(self) -> str: | ||
if self.asn1_class == CONTEXT_SPECIFIC: | ||
return 'TaggedDERObject(%s, %r)' % (self.tag, self.value) | ||
return f'TaggedDERObject({self.tag}, {self.value!r})' | ||
else: | ||
return ('TaggedDERObject(%s, %s, %r)' % | ||
(_asn1_class[self.asn1_class], self.tag, self.value)) | ||
return f'TaggedDERObject({_asn1_class[self.asn1_class]}, ' \ | ||
f'{self.tag}, {self.value!r})' | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, TaggedDERObject): # pragma: no cover | ||
|
@@ -469,7 +469,7 @@ def __str__(self) -> str: | |
return result | ||
|
||
def __repr__(self) -> str: | ||
return "BitString('%s')" % self | ||
return f"BitString('{self}')" | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, BitString): # pragma: no cover | ||
|
@@ -508,10 +508,10 @@ def __init__(self, value: Union[bytes, bytearray]): | |
self.value = value | ||
|
||
def __str__(self) -> str: | ||
return '%s' % self.value.decode('ascii') | ||
return self.value.decode('ascii') | ||
|
||
def __repr__(self) -> str: | ||
return 'IA5String(%r)' % self.value | ||
return f'IA5String({self.value!r})' | ||
|
||
def __eq__(self, other: object) -> bool: # pragma: no cover | ||
if not isinstance(other, IA5String): | ||
|
@@ -569,7 +569,7 @@ def __str__(self) -> str: | |
return self.value | ||
|
||
def __repr__(self) -> str: | ||
return "ObjectIdentifier('%s')" % self.value | ||
return f"ObjectIdentifier('{self.value}')" | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, ObjectIdentifier): # pragma: no cover | ||
|
@@ -685,7 +685,7 @@ def der_encode(value: object) -> bytes: | |
identifier = cls.identifier | ||
content = cls.encode(value) | ||
else: | ||
raise ASN1EncodeError('Cannot DER encode type %s' % t.__name__) | ||
raise ASN1EncodeError(f'Cannot DER encode type {t.__name__}') | ||
|
||
length = len(content) | ||
if length < 0x80: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) 2015-2021 by Ron Frederick <[email protected]> and others. | ||
# Copyright (c) 2015-2024 by Ron Frederick <[email protected]> and others. | ||
# | ||
# This program and the accompanying materials are made available under | ||
# the terms of the Eclipse Public License v2.0 which accompanies this | ||
|
@@ -121,7 +121,7 @@ def _add_permitopen(self, option: str, value: str) -> None: | |
|
||
port = None if port_str == '*' else int(port_str) | ||
except ValueError: | ||
raise ValueError('Illegal permitopen value: %s' % value) from None | ||
raise ValueError(f'Illegal permitopen value: {value}') from None | ||
|
||
permitted_opens = cast(Set[Tuple[str, Optional[int]]], | ||
self.options.setdefault(option, set())) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.