@@ -95,12 +95,11 @@ def readline(self):
9595 return line
9696
9797 def _check_eofstack (self , data , start = 0 , end = sys .maxsize ):
98- for ateof in reversed (self ._eofstack ):
99- if ateof (data , start , end ):
100- # We're at the false EOF.
101- return True
102-
103- return False
98+ # check if we can find a dummy EOF
99+ return any (
100+ ateof (data , start , end )
101+ for ateof in reversed (self ._eofstack )
102+ )
104103
105104 def unreadline (self , line ):
106105 # Let the consumer push a line back into the buffer.
@@ -112,7 +111,7 @@ def _flush_partial(self):
112111 if not line :
113112 pass
114113 elif self ._dump_destination is None :
115- # We're not dumping data. Just flush the partial to lines
114+ # We're not dumping data. Just flush the partial to lines.
116115 self ._lines .append (line )
117116 elif self ._check_eofstack (line ):
118117 # We were dumping, but we've now reached the end of the dump.
@@ -128,19 +127,17 @@ def _flush_partial(self):
128127 def push (self , data ):
129128 """Push some new data into this object."""
130129 if not data :
131- return
132-
133- if self ._can_dump_data (data ):
130+ pass
131+ elif self ._can_dump_data (data ):
134132 self ._dump_destination .append (data )
135- return
136-
137- self ._push_data (data )
133+ else :
134+ self ._push_data (data )
138135
139136 def _can_dump_data (self , data ):
140137 if self ._dump_destination is None :
141138 return False
142139
143- # We're dumping; check for easy optimizations
140+ # We're dumping; check for easy optimizations.
144141 if not self ._eofstack :
145142 # There's nothing that will ever tell us to stop dumping.
146143 # This does absolute wonders for large non-multipart emails.
@@ -178,7 +175,6 @@ def _can_dump_partial(self, line, start=0, end=sys.maxsize):
178175 # There's nothing that will ever tell us to stop dumping. Dump away
179176 return True
180177
181- all_boundary_matches = True
182178 for pred in self ._eofstack :
183179 if not hasattr (pred , 'is_boundary_match' ):
184180 return False
@@ -190,7 +186,6 @@ def _can_dump_partial(self, line, start=0, end=sys.maxsize):
190186 def _is_dump_midline (self ):
191187 if not self ._dump_destination :
192188 return False
193-
194189 return self ._dump_destination [- 1 ][- 1 ] not in ('\n ' , '\r ' )
195190
196191 def _push_data (self , data ):
@@ -214,8 +209,7 @@ def _push_data(self, data):
214209 return
215210
216211 data_start_index = 0
217-
218- # Complete our previous/partial line
212+ # Complete our previous/partial line.
219213 if self ._partial :
220214 if self ._dangling_partial :
221215 if data [0 ] != NL :
@@ -227,7 +221,6 @@ def _push_data(self, data):
227221 self ._flush_partial ()
228222 data_start_index = 1
229223
230- # Find the next newline
231224 unl_start_index = BufferedSubFile ._find_unl (
232225 data , data_start_index )
233226 else :
@@ -285,7 +278,6 @@ def _push_data_no_partial(self, data, data_start_index, unl_start_index):
285278 self ._partial .append (lines .pop ())
286279 if data [- 1 ] == '\r ' :
287280 self ._dangling_partial = True
288-
289281 self .pushlines (lines )
290282 else :
291283 dump_data_start = None if self ._dump_destination is None \
@@ -353,7 +345,7 @@ def __next__(self):
353345 raise StopIteration
354346 return line
355347
356- def _get_dump (self , start_value : str | None = None ):
348+ def _get_dump (self , start_value = None ):
357349 _dump_destination = deque ()
358350 self ._dump_destination = _dump_destination
359351
@@ -398,7 +390,6 @@ def _find_unl(data, start=0):
398390 cr_index = data .find ('\r ' , start )
399391 if cr_index < 0 :
400392 return data .find (NL , start )
401-
402393 nl_index = data .find (NL , start , cr_index )
403394 return nl_index if nl_index >= 0 else cr_index
404395
@@ -410,15 +401,12 @@ def _find_unl_end(data, start):
410401 # \n is always end of line
411402 if data .startswith (NL , start ):
412403 return start + 1
413-
414404 # \r\n is always end of line
415405 if data .startswith (NL , start + 1 ):
416406 return start + 2
417-
418407 # End of data; we can't know if a \n follows, so no universal line end
419408 if start + 1 >= len (data ):
420409 return - 1
421-
422410 # This is a \r followed by some other non-newline character
423411 return start + 1
424412
0 commit comments