util Module

Miscellaneous functions.

class wpull.util.ASCIIStreamWriter(stream, errors='backslashreplace')[source]

Bases: codecs.StreamWriter

A Stream Writer that encodes everything to ASCII.

By default, the replacement character is a Python backslash sequence.

DEFAULT_ERROR = 'backslashreplace'
decode(instance, errors='backslashreplace')[source]
encode(instance, errors='backslashreplace')[source]
write(instance)[source]
writelines(list_instance)[source]
class wpull.util.GzipPickleStream(filename=None, file=None, mode='rb', **kwargs)[source]

Bases: wpull.util.PickleStream

gzip compressed pickle stream.

close()[source]
class wpull.util.PickleStream(filename=None, file=None, mode='rb', protocol=3)[source]

Bases: object

Pickle stream helper.

close()[source]

Close stream.

dump(obj)[source]

Pickle an object.

iter_load()[source]

Unpickle objects.

load()[source]

Unpickle an object.

wpull.util.close_on_error(close_func)[source]

Context manager to close object on error.

wpull.util.datetime_str()[source]

Return the current time in simple ISO8601 notation.

wpull.util.filter_pem(data)[source]

Processes the bytes for PEM certificates.

Returns:set containing each certificate
wpull.util.get_exception_message(instance)[source]

Try to get the exception message or the class name.

wpull.util.get_package_data(filename, mode='rb')[source]

Return the contents of a real file or a zip file.

wpull.util.get_package_filename(filename, package_dir=None)[source]

Return the filename of the data file.

wpull.util.grouper(iterable, n, fillvalue=None)[source]

Collect data into fixed-length chunks or blocks

wpull.util.is_ascii(text)[source]

Returns whether the given string is ASCII.

wpull.util.parse_iso8601_str(string)[source]

Parse a fixed ISO8601 datetime string.

Note

This function only parses dates in the format %Y-%m-%dT%H:%M:%SZ. You must use a library like dateutils to properly parse dates and times.

Returns:A UNIX timestamp.
Return type:float
wpull.util.peek_file(file, length=4096)[source]

Peek the file by calling read on it.

wpull.util.python_version()[source]

Return the Python version as a string.

wpull.util.reset_file_offset(file)[source]

Reset the file offset back to original position.

wpull.util.rewrap_bytes(data)[source]

Rewrap characters to 70 character width.

Intended to rewrap base64 content.

wpull.util.seek_file_end(file)[source]

Seek to the end of the file.

wpull.util.truncate_file(path)[source]

Truncate the file.