# HG changeset patch # User Yuya Nishihara # Date 1475060734 -32400 # Node ID e4a6b439acc55f821322b3012592eec77f2e17a7 # Parent 02dbfaa6df0b9dd4c15cbf3edfe867fe6a90abd2 py3: provide encoding.environ which is a dict of bytes This can't be moved to pycompat.py since we need encoding.tolocal() to build bytes dict from unicode os.environ. diff -r 02dbfaa6df0b -r e4a6b439acc5 mercurial/encoding.py --- a/mercurial/encoding.py Wed Sep 28 20:39:06 2016 +0900 +++ b/mercurial/encoding.py Wed Sep 28 20:05:34 2016 +0900 @@ -47,6 +47,19 @@ s = s.replace(c, '') return s +# encoding.environ is provided read-only, which may not be used to modify +# the process environment +_nativeenviron = (not pycompat.ispy3 or os.supports_bytes_environ) +if not pycompat.ispy3: + environ = os.environ +elif _nativeenviron: + environ = os.environb +else: + # preferred encoding isn't known yet; use utf-8 to avoid unicode error + # and recreate it once encoding is settled + environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8')) + for k, v in os.environ.items()) + def _getpreferredencoding(): ''' On darwin, getpreferredencoding ignores the locale environment and @@ -78,13 +91,13 @@ } try: - encoding = os.environ.get("HGENCODING") + encoding = environ.get("HGENCODING") if not encoding: encoding = locale.getpreferredencoding() or 'ascii' encoding = _encodingfixers.get(encoding, lambda: encoding)() except locale.Error: encoding = 'ascii' -encodingmode = os.environ.get("HGENCODINGMODE", "strict") +encodingmode = environ.get("HGENCODINGMODE", "strict") fallbackencoding = 'ISO-8859-1' class localstr(str): @@ -183,8 +196,14 @@ except LookupError as k: raise error.Abort(k, hint="please check your locale settings") +if not _nativeenviron: + # now encoding and helper functions are available, recreate the environ + # dict to be exported to other modules + environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8'))) + for k, v in os.environ.items()) + # How to treat ambiguous-width characters. Set to 'wide' to treat as wide. -wide = (os.environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide" +wide = (environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide" and "WFA" or "WF") def colwidth(s): diff -r 02dbfaa6df0b -r e4a6b439acc5 tests/test-check-py3-compat.t --- a/tests/test-check-py3-compat.t Wed Sep 28 20:39:06 2016 +0900 +++ b/tests/test-check-py3-compat.t Wed Sep 28 20:05:34 2016 +0900 @@ -17,89 +17,90 @@ > | xargs $PYTHON3 contrib/check-py3-compat.py \ > | sed 's/[0-9][0-9]*)$/*)/' doc/hgmanpage.py: invalid syntax: invalid syntax (, line *) - hgext/acl.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/automv.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/blackbox.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/bugzilla.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/censor.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/chgserver.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/children.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/churn.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/clonebundles.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/color.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/bzr.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/common.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/convcmd.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/cvs.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/cvsps.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/darcs.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/filemap.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/git.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/gnuarch.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/hg.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/monotone.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/p4.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/convert/subversion.py: error importing: str expected, not bytes (error at encoding.py:*) + hgext/acl.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/automv.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/blackbox.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/bugzilla.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/censor.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/chgserver.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/children.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/churn.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/clonebundles.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/color.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/bzr.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/common.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/convcmd.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/cvs.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/cvsps.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/darcs.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/filemap.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/git.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/gnuarch.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/hg.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/monotone.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/p4.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/convert/subversion.py: error importing: str expected, not bytes (error at i18n.py:*) hgext/convert/transport.py: error importing module: No module named 'svn.client' (line *) - hgext/eol.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/extdiff.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/factotum.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/fetch.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/fsmonitor/state.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/fsmonitor/watchmanclient.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/gpg.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/graphlog.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/hgk.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/histedit.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/journal.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/keyword.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/basestore.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/lfcommands.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/lfutil.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/localstore.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/overrides.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/proto.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/remotestore.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/reposetup.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/storefactory.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/largefiles/uisetup.py: error importing: str expected, not bytes (error at encoding.py:*) + hgext/eol.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/extdiff.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/factotum.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/fetch.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/fsmonitor/state.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/fsmonitor/watchmanclient.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/gpg.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/graphlog.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/hgk.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/histedit.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/journal.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/keyword.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/basestore.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/lfcommands.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/lfutil.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/localstore.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/overrides.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/proto.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/remotestore.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/reposetup.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/storefactory.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/largefiles/uisetup.py: error importing: str expected, not bytes (error at i18n.py:*) hgext/largefiles/wirestore.py: error importing module: Parent module 'hgext.largefiles' not loaded, cannot perform relative import (line *) - hgext/mq.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/notify.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/pager.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/patchbomb.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/purge.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/rebase.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/record.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/relink.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/schemes.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/share.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/shelve.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/strip.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/transplant.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/win32mbcs.py: error importing: str expected, not bytes (error at encoding.py:*) - hgext/win32text.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/archival.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/bookmarks.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/branchmap.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/bundle2.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/bundlerepo.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/byterange.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/changegroup.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/changelog.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/cmdutil.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/commands.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/commandserver.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/config.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/context.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/copies.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/crecord.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/dagparser.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/dagutil.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/destutil.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/dirstate.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/discovery.py: error importing: str expected, not bytes (error at encoding.py:*) - mercurial/dispatch.py: error importing: str expected, not bytes (error at encoding.py:*) + hgext/mq.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/notify.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/pager.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/patchbomb.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/purge.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/rebase.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/record.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/relink.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/schemes.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/share.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/shelve.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/strip.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/transplant.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/win32mbcs.py: error importing: str expected, not bytes (error at i18n.py:*) + hgext/win32text.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/archival.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/bookmarks.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/branchmap.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/bundle2.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/bundlerepo.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/byterange.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/changegroup.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/changelog.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/cmdutil.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/commands.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/commandserver.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/config.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/context.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/copies.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/crecord.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/dagparser.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/dagutil.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/destutil.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/dirstate.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/discovery.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/dispatch.py: error importing: str expected, not bytes (error at i18n.py:*) + mercurial/encoding.py: error importing module: bytes expected, not str (line *) mercurial/exchange.py: error importing: str expected, not bytes (error at i18n.py:*) mercurial/extensions.py: error importing: str expected, not bytes (error at i18n.py:*) mercurial/fancyopts.py: error importing: str expected, not bytes (error at i18n.py:*) @@ -165,10 +166,11 @@ mercurial/ui.py: error importing: __slots__ items must be strings, not 'bytes' (error at util.py:*) mercurial/unionrepo.py: error importing: __slots__ items must be strings, not 'bytes' (error at util.py:*) mercurial/url.py: error importing: __slots__ items must be strings, not 'bytes' (error at util.py:*) - mercurial/verify.py: error importing module: unorderable types: str() >= tuple() (line *) + mercurial/util.py: error importing module: encode() argument 1 must be str, not bytes (line *) + mercurial/verify.py: error importing: __slots__ items must be strings, not 'bytes' (error at util.py:*) mercurial/win32.py: error importing module: No module named 'msvcrt' (line *) mercurial/windows.py: error importing module: No module named 'msvcrt' (line *) - mercurial/wireproto.py: error importing module: unorderable types: str() >= tuple() (line *) + mercurial/wireproto.py: error importing: __slots__ items must be strings, not 'bytes' (error at util.py:*) #endif @@ -176,5 +178,5 @@ $ hg files 'set:(**.py) and grep(pygments)' | sed 's|\\|/|g' \ > | xargs $PYTHON3 contrib/check-py3-compat.py \ > | sed 's/[0-9][0-9]*)$/*)/' - hgext/highlight/highlight.py: error importing: str expected, not bytes (error at encoding.py:*) + hgext/highlight/highlight.py: error importing: str expected, not bytes (error at i18n.py:*) #endif