@@ -243,10 +243,11 @@ def read(self, b=-1):
243
243
output .write (self .output_buffer [:b ])
244
244
self .output_buffer = self .output_buffer [b :]
245
245
else :
246
- while not self .source_stream .closed :
247
- self ._read_bytes (LINE_LENGTH )
248
- output .write (self .output_buffer )
249
- self .output_buffer = b""
246
+ while True :
247
+ line = self .readline ()
248
+ if not line :
249
+ break
250
+ output .write (line )
250
251
251
252
self .bytes_read += output .tell ()
252
253
_LOGGER .debug ("Returning %d bytes of %d bytes requested" , output .tell (), b )
@@ -294,10 +295,13 @@ def next(self):
294
295
if self .closed :
295
296
_LOGGER .debug ("stream is closed" )
296
297
raise StopIteration ()
297
- if self .source_stream .closed and not self .output_buffer :
298
+
299
+ line = self .readline ()
300
+ if not line :
298
301
_LOGGER .debug ("nothing more to read" )
299
302
raise StopIteration ()
300
- return self .readline ()
303
+
304
+ return line
301
305
302
306
#: Provides hook for Python3 iterator functionality.
303
307
__next__ = next
@@ -400,6 +404,7 @@ def __init__(self, **kwargs): # pylint: disable=unused-argument,super-init-not-
400
404
raise SerializationError ("Source too large for non-framed message" )
401
405
402
406
self .__unframed_plaintext_cache = io .BytesIO ()
407
+ self .__message_complete = False
403
408
404
409
def ciphertext_length (self ):
405
410
"""Returns the length of the resulting ciphertext message in bytes.
@@ -552,6 +557,7 @@ def _read_bytes_to_non_framed_body(self, b):
552
557
553
558
if self .signer is not None :
554
559
closing += serialize_footer (self .signer )
560
+ self .__message_complete = True
555
561
return ciphertext + closing
556
562
557
563
return ciphertext
@@ -618,6 +624,7 @@ def _read_bytes_to_framed_body(self, b):
618
624
_LOGGER .debug ("Writing footer" )
619
625
if self .signer is not None :
620
626
output += serialize_footer (self .signer )
627
+ self .__message_complete = True
621
628
self .source_stream .close ()
622
629
return output
623
630
@@ -628,7 +635,7 @@ def _read_bytes(self, b):
628
635
:raises NotSupportedError: if content type is not supported
629
636
"""
630
637
_LOGGER .debug ("%d bytes requested from stream with content type: %s" , b , self .content_type )
631
- if 0 <= b <= len (self .output_buffer ) or self .source_stream . closed :
638
+ if 0 <= b <= len (self .output_buffer ) or self .__message_complete :
632
639
_LOGGER .debug ("No need to read from source stream or source stream closed" )
633
640
return
634
641
@@ -900,8 +907,8 @@ def _read_bytes(self, b):
900
907
:param int b: Number of bytes to read
901
908
:raises NotSupportedError: if content type is not supported
902
909
"""
903
- if self . source_stream . closed :
904
- _LOGGER .debug ("Source stream closed " )
910
+ if hasattr ( self , "footer" ) :
911
+ _LOGGER .debug ("Source stream processing complete " )
905
912
return
906
913
907
914
buffer_length = len (self .output_buffer )
0 commit comments