File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,30 +74,33 @@ def multiple_chunks(self, chunk_size=None):
7474
7575 def __iter__ (self ):
7676 # Iterate over this file-like object by newlines
77- buffer_ = None
77+ buffer_ = []
7878 for chunk in self .chunks ():
7979 for line in chunk .splitlines (True ):
8080 if buffer_ :
81- if endswith_cr (buffer_ ) and not equals_lf (line ):
81+ if endswith_cr (buffer_ [ - 1 ] ) and not equals_lf (line ):
8282 # Line split after a \r newline; yield buffer_.
83- yield buffer_
83+ yield type ( buffer_ [ 0 ])(). join ( buffer_ )
8484 # Continue with line.
85+ buffer_ = []
8586 else :
8687 # Line either split without a newline (line
8788 # continues after buffer_) or with \r\n
8889 # newline (line == b'\n').
89- line = buffer_ + line
90- # buffer_ handled, clear it.
91- buffer_ = None
92-
93- # If this is the end of a \n or \r\n line, yield.
94- if endswith_lf (line ):
95- yield line
96- else :
97- buffer_ = line
98-
99- if buffer_ is not None :
100- yield buffer_
90+ buffer_ .append (line )
91+
92+ if not buffer_ :
93+ # If this is the end of a \n or \r\n line, yield.
94+ if endswith_lf (line ):
95+ yield line
96+ else :
97+ buffer_ .append (line )
98+ elif endswith_lf (line ):
99+ yield type (buffer_ [0 ])().join (buffer_ )
100+ buffer_ = []
101+
102+ if buffer_ :
103+ yield type (buffer_ [0 ])().join (buffer_ )
101104
102105 def __enter__ (self ):
103106 return self
You can’t perform that action at this time.
0 commit comments