Show More
@@ -149,93 +149,76 b' def run():' | |||||
149 | sys.exit(status & 255) |
|
149 | sys.exit(status & 255) | |
150 |
|
150 | |||
151 |
|
151 | |||
152 | if pycompat.ispy3: |
|
152 | def initstdio(): | |
153 |
|
153 | # stdio streams on Python 3 are io.TextIOWrapper instances proxying another | ||
154 | def initstdio(): |
|
154 | # buffer. These streams will normalize \n to \r\n by default. Mercurial's | |
155 | # stdio streams on Python 3 are io.TextIOWrapper instances proxying another |
|
155 | # preferred mechanism for writing output (ui.write()) uses io.BufferedWriter | |
156 | # buffer. These streams will normalize \n to \r\n by default. Mercurial's |
|
156 | # instances, which write to the underlying stdio file descriptor in binary | |
157 | # preferred mechanism for writing output (ui.write()) uses io.BufferedWriter |
|
157 | # mode. ui.write() uses \n for line endings and no line ending normalization | |
158 | # instances, which write to the underlying stdio file descriptor in binary |
|
158 | # is attempted through this interface. This "just works," even if the system | |
159 | # mode. ui.write() uses \n for line endings and no line ending normalization |
|
159 | # preferred line ending is not \n. | |
160 | # is attempted through this interface. This "just works," even if the system |
|
160 | # | |
161 | # preferred line ending is not \n. |
|
161 | # But some parts of Mercurial (e.g. hooks) can still send data to sys.stdout | |
162 | # |
|
162 | # and sys.stderr. They will inherit the line ending normalization settings, | |
163 | # But some parts of Mercurial (e.g. hooks) can still send data to sys.stdout |
|
163 | # potentially causing e.g. \r\n to be emitted. Since emitting \n should | |
164 | # and sys.stderr. They will inherit the line ending normalization settings, |
|
164 | # "just work," here we change the sys.* streams to disable line ending | |
165 | # potentially causing e.g. \r\n to be emitted. Since emitting \n should |
|
165 | # normalization, ensuring compatibility with our ui type. | |
166 | # "just work," here we change the sys.* streams to disable line ending |
|
|||
167 | # normalization, ensuring compatibility with our ui type. |
|
|||
168 |
|
||||
169 | if sys.stdout is not None: |
|
|||
170 | # write_through is new in Python 3.7. |
|
|||
171 | kwargs = { |
|
|||
172 | "newline": "\n", |
|
|||
173 | "line_buffering": sys.stdout.line_buffering, |
|
|||
174 | } |
|
|||
175 | if util.safehasattr(sys.stdout, "write_through"): |
|
|||
176 | # pytype: disable=attribute-error |
|
|||
177 | kwargs["write_through"] = sys.stdout.write_through |
|
|||
178 | # pytype: enable=attribute-error |
|
|||
179 | sys.stdout = io.TextIOWrapper( |
|
|||
180 | sys.stdout.buffer, |
|
|||
181 | sys.stdout.encoding, |
|
|||
182 | sys.stdout.errors, |
|
|||
183 | **kwargs |
|
|||
184 | ) |
|
|||
185 |
|
166 | |||
186 |
|
|
167 | if sys.stdout is not None: | |
187 | kwargs = { |
|
168 | # write_through is new in Python 3.7. | |
188 | "newline": "\n", |
|
169 | kwargs = { | |
189 | "line_buffering": sys.stderr.line_buffering, |
|
170 | "newline": "\n", | |
190 | } |
|
171 | "line_buffering": sys.stdout.line_buffering, | |
191 | if util.safehasattr(sys.stderr, "write_through"): |
|
172 | } | |
192 | # pytype: disable=attribute-error |
|
173 | if util.safehasattr(sys.stdout, "write_through"): | |
193 | kwargs["write_through"] = sys.stderr.write_through |
|
174 | # pytype: disable=attribute-error | |
194 | # pytype: enable=attribute-error |
|
175 | kwargs["write_through"] = sys.stdout.write_through | |
195 | sys.stderr = io.TextIOWrapper( |
|
176 | # pytype: enable=attribute-error | |
196 | sys.stderr.buffer, |
|
177 | sys.stdout = io.TextIOWrapper( | |
197 | sys.stderr.encoding, |
|
178 | sys.stdout.buffer, sys.stdout.encoding, sys.stdout.errors, **kwargs | |
198 | sys.stderr.errors, |
|
179 | ) | |
199 | **kwargs |
|
|||
200 | ) |
|
|||
201 |
|
180 | |||
202 |
|
|
181 | if sys.stderr is not None: | |
203 | # No write_through on read-only stream. |
|
182 | kwargs = { | |
204 | sys.stdin = io.TextIOWrapper( |
|
183 | "newline": "\n", | |
205 |
|
|
184 | "line_buffering": sys.stderr.line_buffering, | |
206 | sys.stdin.encoding, |
|
185 | } | |
207 | sys.stdin.errors, |
|
186 | if util.safehasattr(sys.stderr, "write_through"): | |
208 | # None is universal newlines mode. |
|
187 | # pytype: disable=attribute-error | |
209 | newline=None, |
|
188 | kwargs["write_through"] = sys.stderr.write_through | |
210 | line_buffering=sys.stdin.line_buffering, |
|
189 | # pytype: enable=attribute-error | |
211 | ) |
|
190 | sys.stderr = io.TextIOWrapper( | |
|
191 | sys.stderr.buffer, sys.stderr.encoding, sys.stderr.errors, **kwargs | |||
|
192 | ) | |||
212 |
|
193 | |||
213 | def _silencestdio(): |
|
194 | if sys.stdin is not None: | |
214 | for fp in (sys.stdout, sys.stderr): |
|
195 | # No write_through on read-only stream. | |
215 | if fp is None: |
|
196 | sys.stdin = io.TextIOWrapper( | |
216 |
|
|
197 | sys.stdin.buffer, | |
217 | # Check if the file is okay |
|
198 | sys.stdin.encoding, | |
218 |
|
|
199 | sys.stdin.errors, | |
219 | fp.flush() |
|
200 | # None is universal newlines mode. | |
220 |
|
|
201 | newline=None, | |
221 | except IOError: |
|
202 | line_buffering=sys.stdin.line_buffering, | |
222 | pass |
|
203 | ) | |
223 | # Otherwise mark it as closed to silence "Exception ignored in" |
|
|||
224 | # message emitted by the interpreter finalizer. |
|
|||
225 | try: |
|
|||
226 | fp.close() |
|
|||
227 | except IOError: |
|
|||
228 | pass |
|
|||
229 |
|
204 | |||
230 |
|
205 | |||
231 | else: |
|
206 | def _silencestdio(): | |
232 |
|
207 | for fp in (sys.stdout, sys.stderr): | ||
233 | def initstdio(): |
|
208 | if fp is None: | |
234 | for fp in (sys.stdin, sys.stdout, sys.stderr): |
|
209 | continue | |
235 | procutil.setbinary(fp) |
|
210 | # Check if the file is okay | |
236 |
|
211 | try: | ||
237 | def _silencestdio(): |
|
212 | fp.flush() | |
238 | pass |
|
213 | continue | |
|
214 | except IOError: | |||
|
215 | pass | |||
|
216 | # Otherwise mark it as closed to silence "Exception ignored in" | |||
|
217 | # message emitted by the interpreter finalizer. | |||
|
218 | try: | |||
|
219 | fp.close() | |||
|
220 | except IOError: | |||
|
221 | pass | |||
239 |
|
222 | |||
240 |
|
223 | |||
241 | def _formatargs(args): |
|
224 | def _formatargs(args): |
General Comments 0
You need to be logged in to leave comments.
Login now