Change only `.write()` of the wrapped object by encoding the passed value and passing the result to the wrapped object's `.write()` method.
| 161 | |
| 162 | |
| 163 | class SimpleTextIOWrapper(ObjectWrapper): |
| 164 | """ |
| 165 | Change only `.write()` of the wrapped object by encoding the passed |
| 166 | value and passing the result to the wrapped object's `.write()` method. |
| 167 | """ |
| 168 | # pylint: disable=too-few-public-methods |
| 169 | def __init__(self, wrapped, encoding): |
| 170 | super().__init__(wrapped) |
| 171 | self.wrapper_setattr('encoding', encoding) |
| 172 | |
| 173 | def write(self, s): |
| 174 | """ |
| 175 | Encode `s` and pass to the wrapped object's `.write()` method. |
| 176 | """ |
| 177 | return self._wrapped.write(s.encode(self.wrapper_getattr('encoding'))) |
| 178 | |
| 179 | def __eq__(self, other): |
| 180 | return self._wrapped == getattr(other, '_wrapped', other) |
| 181 | |
| 182 | |
| 183 | class DisableOnWriteError(ObjectWrapper): |