terminator = line.rstrip()
line = line.decode(transfer_encoding)
raise ValueError('could not base 64 decode chunk')
+ # we have something in the buffer from the last iteration.
+ # write that value to the output stream now and clear the buffer.
+ # If the line ends with windows CRLF we write everything except
+ # the last two bytes. In all other cases however we write everything
+ # except the last byte. If it was a newline, that's fine, otherwise
+ # it does not matter because we write it the last iteration. If the
+ # loop aborts early because the end of a part was reached, the last
+ # newline is not written which is exactly what we want.
newline_length = line[-2:] == '\r\n' and 2 or 1
+ buf = line[-newline_length:]
if not is_file and max_form_memory_size is not None:
if in_memory > max_form_memory_size:
raise ValueError('unexpected end of part')
- # chop off the trailing line terminator and rewind
- stream.seek(-newline_length, 1)