[PATCH 6 of 7] get-with-headers: handle python3 bytes in stdout

Yuya Nishihara yuya at tcha.org
Mon May 16 10:33:38 EDT 2016


On Wed, 11 May 2016 05:20:28 +0000, timeless wrote:
> # HG changeset patch
> # User timeless <timeless at mozdev.org>
> # Date 1462561643 0
> #      Fri May 06 19:07:23 2016 +0000
> # Node ID 6849a6b26ea35775c142b78802b6b943dd2adf68
> # Parent  67542cf802e8669a1c954c3066f468fe3ae6ba0e
> # EXP-Topic runtests
> # Available At bb://timeless/mercurial-crew
> #              hg pull bb://timeless/mercurial-crew -r 6849a6b26ea3
> get-with-headers: handle python3 bytes in stdout
> 
> diff -r 67542cf802e8 -r 6849a6b26ea3 tests/get-with-headers.py
> --- a/tests/get-with-headers.py	Fri May 06 19:06:05 2016 +0000
> +++ b/tests/get-with-headers.py	Fri May 06 19:07:23 2016 +0000
> @@ -17,6 +17,17 @@
>  except ImportError:
>      pass
>  
> +try:
> +    stdout = sys.stdout.buffer
> +except AttributeError:
> +    stdout = sys.stdout
> +
> +if sys.version_info[0] < 3:
> +    sprint = print
> +else:
> +    def sprint(*s):
> +        print(*s, file=sys.stdout, flush=True)

Why do flush() only on Python 3 ?

The commit message explains why we need "stdout = sys.stdout.buffer", but
it says nothing about sprint().


More information about the Mercurial-devel mailing list