From patchwork Wed Jun 1 05:53:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6,of,6] pycompat: use unicode literals to appease Python 3 From: Gregory Szorc X-Patchwork-Id: 15323 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Tue, 31 May 2016 22:53:03 -0700 # HG changeset patch # User Gregory Szorc # Date 1464759504 25200 # Tue May 31 22:38:24 2016 -0700 # Node ID dc6956f6ec9efe421e7d023db24687b127291318 # Parent 856a1794f165a93ec8eb6fe1963b0ca1a68c647b pycompat: use unicode literals to appease Python 3 More of the same. diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -29,17 +29,17 @@ class _pycompatstub(object): pass def _alias(alias, origin, items): """ populate a _pycompatstub copies items from origin to alias """ def hgcase(item): - return item.replace('_', '').lower() + return item.replace(u'_', u'').lower() for item in items: try: setattr(alias, hgcase(item), getattr(origin, item)) except AttributeError: pass urlreq = _pycompatstub() urlerr = _pycompatstub() @@ -80,44 +80,44 @@ try: _alias(urlerr, urllib2, ( "HTTPError", "URLError", )) except ImportError: import urllib.request _alias(urlreq, urllib.request, ( - "AbstractHTTPHandler", - "addclosehook", - "addinfourl", - "BaseHandler", - "build_opener", - "FileHandler", - "FTPHandler", - "ftpwrapper", - "HTTPHandler", - "HTTPSHandler", - "install_opener", - "pathname2url", - "HTTPBasicAuthHandler", - "HTTPDigestAuthHandler", - "ProxyHandler", - "quote", - "Request", - "splitattr", - "splitpasswd", - "splitport", - "splituser", - "unquote", - "url2pathname", - "urlopen", + u"AbstractHTTPHandler", + u"addclosehook", + u"addinfourl", + u"BaseHandler", + u"build_opener", + u"FileHandler", + u"FTPHandler", + u"ftpwrapper", + u"HTTPHandler", + u"HTTPSHandler", + u"install_opener", + u"pathname2url", + u"HTTPBasicAuthHandler", + u"HTTPDigestAuthHandler", + u"ProxyHandler", + u"quote", + u"Request", + u"splitattr", + u"splitpasswd", + u"splitport", + u"splituser", + u"unquote", + u"url2pathname", + u"urlopen", )) import urllib.error _alias(urlerr, urllib.error, ( - "HTTPError", - "URLError", + u"HTTPError", + u"URLError", )) try: xrange except NameError: import builtins builtins.xrange = range diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t --- a/tests/test-check-py3-compat.t +++ b/tests/test-check-py3-compat.t @@ -30,134 +30,134 @@ tests/md5sum.py not using absolute_import tests/readlink.py not using absolute_import tests/run-tests.py not using absolute_import tests/test-demandimport.py not using absolute_import #if py3exe $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py doc/hgmanpage.py: invalid syntax: invalid syntax (, line *) (glob) - hgext/acl.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/acl.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/automv.py: error importing module: invalid syntax (commands.py, line 3382) (line 30) - hgext/blackbox.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/blackbox.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/bugzilla.py: error importing module: No module named 'urlparse' (line 284) - hgext/censor.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/censor.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/chgserver.py: error importing module: No module named 'SocketServer' (line 43) - hgext/children.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/churn.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/clonebundles.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/children.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/churn.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/clonebundles.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/color.py: invalid syntax: invalid syntax (, line *) (glob) hgext/convert/bzr.py: error importing module: Parent module 'hgext.convert' not loaded, cannot perform relative import (line 19) hgext/convert/common.py: error importing module: No module named 'cPickle' (line 10) - hgext/convert/convcmd.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/convert/cvs.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/convert/convcmd.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/convert/cvs.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/convert/cvsps.py: error importing module: No module named 'cPickle' (line 9) - hgext/convert/darcs.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/convert/darcs.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/convert/filemap.py: error importing module: Parent module 'hgext.convert' not loaded, cannot perform relative import (line 15) - hgext/convert/git.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/convert/gnuarch.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/convert/hg.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/convert/monotone.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/convert/p4.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/convert/git.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/convert/gnuarch.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/convert/hg.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/convert/monotone.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/convert/p4.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/convert/subversion.py: error importing module: No module named 'cPickle' (line 6) hgext/convert/transport.py: error importing module: No module named 'svn.client' (line 21) - hgext/eol.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/eol.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/extdiff.py: error importing module: invalid syntax (archival.py, line 234) (line 75) hgext/factotum.py: error importing: No module named 'rfc822' (error at __init__.py:*) (glob) - hgext/fetch.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/fsmonitor/state.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/fsmonitor/watchmanclient.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/gpg.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/graphlog.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/hgk.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/highlight/highlight.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/fetch.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/fsmonitor/state.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/fsmonitor/watchmanclient.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/gpg.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/graphlog.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/hgk.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/highlight/highlight.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/histedit.py: error importing module: invalid syntax (bundle2.py, line 992) (line 180) - hgext/keyword.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/largefiles/basestore.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/largefiles/lfcommands.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/largefiles/lfutil.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/keyword.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/largefiles/basestore.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/largefiles/lfcommands.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/largefiles/lfutil.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/largefiles/localstore.py: error importing module: No module named 'lfutil' (line 13) - hgext/largefiles/overrides.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/largefiles/overrides.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/largefiles/proto.py: error importing: No module named 'httplib' (error at httppeer.py:*) (glob) - hgext/largefiles/remotestore.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/largefiles/reposetup.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/largefiles/remotestore.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/largefiles/reposetup.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/largefiles/uisetup.py: error importing module: invalid syntax (archival.py, line *) (line *) (glob) hgext/largefiles/wirestore.py: error importing module: No module named 'lfutil' (line 8) - hgext/mq.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/notify.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/pager.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/patchbomb.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/purge.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/rebase.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/record.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/relink.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/schemes.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - hgext/share.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/mq.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/notify.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/pager.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/patchbomb.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/purge.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/rebase.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/record.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/relink.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/schemes.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + hgext/share.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/shelve.py: error importing module: invalid syntax (bundle2.py, line 992) (line 30) - hgext/strip.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/strip.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) hgext/transplant.py: error importing: invalid syntax (bundle2.py, line 992) (error at bundlerepo.py:*) (glob) - hgext/win32text.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + hgext/win32text.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/archival.py: invalid syntax: invalid syntax (, line *) (glob) - mercurial/bookmarks.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/branchmap.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/bookmarks.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/branchmap.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/bundle*.py: invalid syntax: invalid syntax (, line *) (glob) mercurial/bundlerepo.py: error importing module: invalid syntax (bundle2.py, line 992) (line 23) - mercurial/byterange.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/changegroup.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/changelog.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/cmdutil.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/byterange.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/changegroup.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/changelog.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/cmdutil.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/commands.py: invalid syntax: invalid syntax (, line *) (glob) mercurial/commandserver.py: error importing module: No module named 'SocketServer' (line 10) - mercurial/config.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/context.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/copies.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/crecord.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/destutil.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/dirstate.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/discovery.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/dispatch.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/exchange.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/extensions.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/filelog.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/config.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/context.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/copies.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/crecord.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/destutil.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/dirstate.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/discovery.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/dispatch.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/exchange.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/extensions.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/filelog.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/filemerge.py: error importing: No module named 'cPickle' (error at formatter.py:*) (glob) - mercurial/fileset.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/fileset.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/formatter.py: error importing module: No module named 'cPickle' (line 10) - mercurial/graphmod.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/help.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/hg.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/graphmod.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/help.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/hg.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/hgweb/common.py: error importing module: No module named 'BaseHTTPServer' (line 11) mercurial/hgweb/hgweb_mod.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 14) mercurial/hgweb/hgwebdir_mod.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 15) mercurial/hgweb/protocol.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 13) mercurial/hgweb/request.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 15) mercurial/hgweb/server.py: error importing module: No module named 'BaseHTTPServer' (line 11) mercurial/hgweb/webcommands.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 16) mercurial/hgweb/webutil.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 16) mercurial/hgweb/wsgicgi.py: error importing module: Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line 16) - mercurial/hook.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/hook.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/httpconnection.py: error importing: No module named 'rfc822' (error at __init__.py:*) (glob) mercurial/httppeer.py: error importing module: No module named 'httplib' (line 12) mercurial/keepalive.py: error importing module: No module named 'httplib' (line 113) - mercurial/localrepo.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/lock.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/mail.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/manifest.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/match.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/mdiff.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/merge.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/minirst.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/namespaces.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/obsolete.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/patch.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/pathutil.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/peer.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/localrepo.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/lock.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/mail.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/manifest.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/match.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/mdiff.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/merge.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/minirst.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/namespaces.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/obsolete.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/patch.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/pathutil.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/peer.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/pure/mpatch.py: error importing module: cannot import name 'pycompat' (line 12) mercurial/pure/parsers.py: error importing module: No module named 'mercurial.pure.node' (line 13) - mercurial/pushkey.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) - mercurial/pvec.py: error importing: getattr(): attribute name must be string (error at pycompat.py:*) (glob) + mercurial/pushkey.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) + mercurial/pvec.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/registrar.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/repair.py: error importing module: invalid syntax (bundle*.py, line *) (line *) (glob) mercurial/repoview.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/revlog.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/revset.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/scmutil.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob) mercurial/scmwindows.py: error importing module: No module named '_winreg' (line 3) mercurial/similar.py: error importing: getattr(): attribute name must be string (error at util.py:*) (glob)