body Module

Request and response payload.

class wpull.body.Body(file=None, directory=None, hint='lone_body')[source]

Bases: object

Represents the document/payload of a request or response.

This class is a wrapper around a file object. Methods are forwarded to the underlying file object.

file

file

The file object.

Parameters:
  • file (file, optional) – Use the given file as the file object.
  • directory (str) – If file is not given, use directory for a new temporary file.
  • hint (str) – If file is not given, use hint as a filename infix.
content()[source]

Return the content of the file.

If this function is invoked, the contents of the entire file is read and cached.

Returns:The entire content of the file.
Return type:bytes
size()[source]

Return the size of the file.

to_dict()[source]

Convert the body to a dict.

Returns:The items are:
  • filename (string, None): The path of the file.
  • length (int, None): The size of the file.
Return type:dict
wpull.body.is_seekable(file)[source]
wpull.body.new_temp_file(directory=None, hint='')[source]

Return a new temporary file.