[PATCH 3 of 3] py3: call codecs.escape_encode() directly

Augie Fackler raf at durin42.com
Thu Mar 16 13:21:32 EDT 2017


On Thu, Mar 16, 2017 at 12:09:50AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1489588119 -32400
> #      Wed Mar 15 23:28:39 2017 +0900
> # Node ID fb6b172146566c203a18113536002a6f4b296879
> # Parent  8b8d561c82ee5c11827674dfff2866067d034eea
> py3: call codecs.escape_encode() directly

Queued, thanks.

>
> string_escape doesn't exist on Python 3, but fortunately the undocumented
> codecs.escape_encode() function exists on CPython 2.6, 2.7, 3.5 and PyPy 5.6.
> So let's use it for now.
>
> http://stackoverflow.com/a/23151714
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -17,6 +17,7 @@ from __future__ import absolute_import
>
>  import bz2
>  import calendar
> +import codecs
>  import collections
>  import datetime
>  import errno
> @@ -2131,7 +2132,9 @@ bytecount = unitcountfn(
>      )
>
>  def escapestr(s):
> -    return s.encode('string_escape')
> +    # call underlying function of s.encode('string_escape') directly for
> +    # Python 3 compatibility
> +    return codecs.escape_encode(s)[0]
>
>  def uirepr(s):
>      # Avoid double backslash in Windows path repr()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list