1
- import re
2
1
import binascii
3
2
import email
4
- from email import quoprimime , base64mime
3
+ import re
4
+ from email import base64mime , quoprimime
5
5
from email import charset as _charset
6
6
7
- if str == bytes :
7
+ if str is bytes :
8
8
message_from_bytes = email .message_from_string
9
9
message_from_binary_file = email .message_from_file
10
10
else :
@@ -74,8 +74,8 @@ def decode_header(header):
74
74
# between two encoded strings.
75
75
droplist = []
76
76
for n , w in enumerate (words ):
77
- if n > 1 and w [1 ] and words [n - 2 ][1 ] and words [n - 1 ][0 ].isspace ():
78
- droplist .append (n - 1 )
77
+ if n > 1 and w [1 ] and words [n - 2 ][1 ] and words [n - 1 ][0 ].isspace ():
78
+ droplist .append (n - 1 )
79
79
for d in reversed (droplist ):
80
80
del words [d ]
81
81
@@ -94,7 +94,7 @@ def decode_header(header):
94
94
# Postel's law: add missing padding
95
95
paderr = len (encoded_string ) % 4
96
96
if paderr :
97
- encoded_string += '===' [:4 - paderr ]
97
+ encoded_string += '===' [:4 - paderr ] # noqa: PLW2901
98
98
try :
99
99
word = base64mime .decode (encoded_string )
100
100
except binascii .Error :
@@ -108,8 +108,9 @@ def decode_header(header):
108
108
collapsed = []
109
109
last_word = last_charset = None
110
110
for word , charset in decoded_words :
111
- if isinstance (word , str ) and bytes != str :
112
- word = bytes (word , 'raw-unicode-escape' )
111
+ # ruff: noqa: PLW2901 - loop var word is overwritten
112
+ if isinstance (word , str ) and bytes is not str :
113
+ word = bytes (word , 'raw-unicode-escape' ) # PLW2901
113
114
if last_word is None :
114
115
last_word = word
115
116
last_charset = charset
0 commit comments