| 345 | self._line_buffered = line_buffered |
| 346 | |
| 347 | def write(self, data): |
| 348 | # bytes-like but not text -> decode |
| 349 | if isinstance(data, _bytes_types) and not isinstance(data, _text_type): |
| 350 | data = bytes(data).decode(self._encoding, self._errors) |
| 351 | elif not isinstance(data, _text_type): |
| 352 | data = _text_type(data) |
| 353 | |
| 354 | n = self._fh.write(data) |
| 355 | |
| 356 | # Approximate "line buffering" behavior if requested |
| 357 | if self._line_buffered and u"\n" in data: |
| 358 | try: |
| 359 | self._fh.flush() |
| 360 | except Exception: |
| 361 | pass |
| 362 | |
| 363 | return n |
| 364 | |
| 365 | def writelines(self, lines): |
| 366 | for x in lines: |