Creates a StreamRecoder instance which implements a two-way conversion: encode and decode work on the frontend (the data visible to .read() and .write()) while Reader and Writer work on the backend (the data in stream). You can use these objects
(self, stream, encode, decode, Reader, Writer,
errors='strict')
| 782 | file_encoding = 'unknown' |
| 783 | |
| 784 | def __init__(self, stream, encode, decode, Reader, Writer, |
| 785 | errors='strict'): |
| 786 | |
| 787 | """ Creates a StreamRecoder instance which implements a two-way |
| 788 | conversion: encode and decode work on the frontend (the |
| 789 | data visible to .read() and .write()) while Reader and Writer |
| 790 | work on the backend (the data in stream). |
| 791 | |
| 792 | You can use these objects to do transparent |
| 793 | transcodings from e.g. latin-1 to utf-8 and back. |
| 794 | |
| 795 | stream must be a file-like object. |
| 796 | |
| 797 | encode and decode must adhere to the Codec interface; Reader and |
| 798 | Writer must be factory functions or classes providing the |
| 799 | StreamReader and StreamWriter interfaces resp. |
| 800 | |
| 801 | Error handling is done in the same way as defined for the |
| 802 | StreamWriter/Readers. |
| 803 | |
| 804 | """ |
| 805 | self.stream = stream |
| 806 | self.encode = encode |
| 807 | self.decode = decode |
| 808 | self.reader = Reader(stream, errors) |
| 809 | self.writer = Writer(stream, errors) |
| 810 | self.errors = errors |
| 811 | |
| 812 | def read(self, size=-1): |
| 813 |