FileWrapper Module

This module provides wrappers for file-like objects for encoding and decoding.

class knittingpattern.Dumper.FileWrapper.TextWrapper(binary_file, encoding)[source]

Bases: object

Use this class if you have a binary-file but you want to write strings to it.

__init__(binary_file, encoding)[source]

Create a wrapper around binary_file that encodes strings to bytes using encoding and writes them to binary_file.

Parameters:
  • encoding (str) – The encoding to use to transfer the written string to bytes so they can be written to binary_file
  • binary_file – a file-like object open in binary mode
__weakref__

list of weak references to the object (if defined)

write(string)[source]

Write a string to the file.

class knittingpattern.Dumper.FileWrapper.BytesWrapper(text_file, encoding)[source]

Bases: object

Use this class if you have a text-file but you want to write bytes to it.

__init__(text_file, encoding)[source]

Create a wrapper around text_file that decodes bytes to string using encoding and writes them to text_file.

Parameters:
  • encoding (str) – The encoding to use to transfer the written bytes to string so they can be written to text_file
  • text_file – a file-like object open in text mode
__weakref__

list of weak references to the object (if defined)

write(bytes_)[source]

Write bytes to the file.