This context manager sets the line-end translation mode for stdout. It is deliberately set to binary mode so that `\r` does not get added to the line ending. This can be useful when printing commands where a windows style line ending would cause errors.
| 89 | |
| 90 | |
| 91 | class NonTranslatedStdout: |
| 92 | """This context manager sets the line-end translation mode for stdout. |
| 93 | |
| 94 | It is deliberately set to binary mode so that `\r` does not get added to |
| 95 | the line ending. This can be useful when printing commands where a |
| 96 | windows style line ending would cause errors. |
| 97 | """ |
| 98 | |
| 99 | def __enter__(self): |
| 100 | if sys.platform == "win32": |
| 101 | import msvcrt |
| 102 | |
| 103 | self.previous_mode = msvcrt.setmode( |
| 104 | sys.stdout.fileno(), os.O_BINARY |
| 105 | ) |
| 106 | return sys.stdout |
| 107 | |
| 108 | def __exit__(self, type, value, traceback): |
| 109 | if sys.platform == "win32": |
| 110 | import msvcrt |
| 111 | |
| 112 | msvcrt.setmode(sys.stdout.fileno(), self.previous_mode) |
| 113 | |
| 114 | |
| 115 | def ensure_text_type(s): |
no outgoing calls
no test coverage detected