revset: build _syminitletters from a saner source: the string module
For now, these sets will be unicode characters in Python 3, which is
probably wrong, but it un-blocks importing the module so we can get
further along. In the future we'll have to come up with a reasonable
encoding strategy for revsets in Python 3.
This patch was originally pair-programmed with Martijn.
--- a/mercurial/revset.py Thu Aug 11 15:05:17 2016 +0200
+++ b/mercurial/revset.py Fri Oct 07 08:32:40 2016 -0400
@@ -9,6 +9,7 @@
import heapq
import re
+import string
from .i18n import _
from . import (
@@ -22,6 +23,7 @@
parser,
pathutil,
phases,
+ pycompat,
registrar,
repoview,
util,
@@ -173,11 +175,12 @@
keywords = set(['and', 'or', 'not'])
# default set of valid characters for the initial letter of symbols
-_syminitletters = set(c for c in [chr(i) for i in xrange(256)]
- if c.isalnum() or c in '._@' or ord(c) > 127)
+_syminitletters = set(
+ string.ascii_letters +
+ string.digits + pycompat.sysstr('._@')) | set(map(chr, xrange(128, 256)))
# default set of valid characters for non-initial letters of symbols
-_symletters = _syminitletters | set('-/')
+_symletters = _syminitletters | set(pycompat.sysstr('-/'))
def tokenize(program, lookup=None, syminitletters=None, symletters=None):
'''
@@ -2619,8 +2622,7 @@
# the set of valid characters for the initial letter of symbols in
# alias declarations and definitions
-_aliassyminitletters = set(c for c in [chr(i) for i in xrange(256)]
- if c.isalnum() or c in '._@$' or ord(c) > 127)
+_aliassyminitletters = _syminitletters | set(pycompat.sysstr('$'))
def _parsewith(spec, lookup=None, syminitletters=None):
"""Generate a parse tree of given spec with given tokenizing options
--- a/tests/test-check-py3-compat.t Thu Aug 11 15:05:17 2016 +0200
+++ b/tests/test-check-py3-compat.t Fri Oct 07 08:32:40 2016 -0400
@@ -120,35 +120,33 @@
mercurial/httppeer.py: error importing: <TypeError> Can't mix strings and bytes in path components (error at i18n.py:*)
mercurial/i18n.py: error importing module: <TypeError> bytes expected, not str (line *)
mercurial/keepalive.py: error importing module: <AttributeError> module 'mercurial.util' has no attribute 'httplib' (line *)
- mercurial/localrepo.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/localrepo.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *)
- mercurial/manifest.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/merge.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/namespaces.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/patch.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/manifest.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/merge.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/namespaces.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/patch.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
mercurial/pvec.py: error importing module: <NameError> name 'xrange' is not defined (line *)
- mercurial/repair.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/revlog.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/revset.py: error importing module: <NameError> name 'xrange' is not defined (line *)
- mercurial/scmutil.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/repair.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
+ mercurial/revlog.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/revset.py: error importing module: <AttributeError> 'dict' object has no attribute 'iteritems' (line *)
mercurial/scmwindows.py: error importing module: <ImportError> No module named 'winreg' (line *)
- mercurial/simplemerge.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/sshpeer.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/sshserver.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/sshpeer.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
+ mercurial/sshserver.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
mercurial/statichttprepo.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at byterange.py:*)
- mercurial/store.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/streamclone.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/subrepo.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/templatefilters.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/templatekw.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/templater.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/ui.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
- mercurial/unionrepo.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/store.py: error importing module: <NameError> name 'xrange' is not defined (line *)
+ mercurial/streamclone.py: error importing: <TypeError> can't concat bytes to str (error at store.py:*)
+ mercurial/subrepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/templatefilters.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/templatekw.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/templater.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/ui.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
+ mercurial/unionrepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
mercurial/url.py: error importing: <AttributeError> module 'mercurial.util' has no attribute 'urlerr' (error at httpconnection.py:*)
- mercurial/verify.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/verify.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*)
mercurial/win32.py: error importing module: <ImportError> No module named 'msvcrt' (line *)
mercurial/windows.py: error importing module: <ImportError> No module named 'msvcrt' (line *)
- mercurial/wireproto.py: error importing: <TypeError> a bytes-like object is required, not 'str' (error at revset.py:*)
+ mercurial/wireproto.py: error importing: <TypeError> %b requires bytes, or an object that implements __bytes__, not 'str' (error at bundle2.py:*)
#endif