Package wtf :: Package impl :: Package http :: Module _util :: Class ChunkedReader
[hide private]
[frames] | no frames]

Class ChunkedReader

source code

object --+
         |
        ChunkedReader

Chunked transfer encoding decoder
Instance Methods [hide private]
 
__init__(self, stream)
Initialization
source code
str
read(self, size)
Read (at max) size bytes from the stream
source code
str
_done(self, size)
Final state: Hit EOF (or EOS, rather)
source code
str
_read_header(self, size)
Initial State: Read chunk header and follow up the stream
source code
str
_read_trailer(self, size)
After last chunk state: Read trailer and finish
source code
str
_read_data(self, size)
Read actual chunk data
source code
str
_read_suffix(self, size)
Read trailing CRLF after chunk data
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
int _left
Bytes left of the current chunk
callable _state
Current read function
file _stream
The stream to decode
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, stream)
(Constructor)

source code 
Initialization
Parameters:
  • stream (file) - The stream to decode
Overrides: object.__init__

read(self, size)

source code 

Read (at max) size bytes from the stream

This just calls the current state reader and returns its result.

Parameters:
  • size (int) - The maximum number of bytes to read (>0)
Returns: str
Bytes read (empty on EOF)
Raises:

_done(self, size)

source code 

Final state: Hit EOF (or EOS, rather)

This function always returns an empty string, so size is ignored.

Parameters:
  • size (int) - The maximum number of bytes to read (>0)
Returns: str
Bytes read (empty on EOF)

_read_header(self, size)

source code 
Initial State: Read chunk header and follow up the stream
Parameters:
  • size (int) - The maximum number of bytes to read (>0)
Returns: str
Bytes read (empty on EOF)
Raises:

_read_trailer(self, size)

source code 
After last chunk state: Read trailer and finish
Parameters:
  • size (int) - The maximum number of bytes to read (>0)
Returns: str
Bytes read (empty on EOF)
Raises:

_read_data(self, size)

source code 
Read actual chunk data
Parameters:
  • size (int) - The maximum number of bytes to read (>0)
Returns: str
Bytes read (empty on EOF)
Raises:
  • IncompleteChunk - The stream ended unexpectedly in the middle of the chunk

_read_suffix(self, size)

source code 

Read trailing CRLF after chunk data

After that it switches back to _read_header and follows up on the stream.

Parameters:
  • size (int) - The maximum number of bytes to read (>0)
Returns: str
Bytes read (empty on EOF)
Raises: