##// END OF EJS Templates
py3compat: use absolute_import
Gregory Szorc -
r27486:5bfd01a3 default
parent child Browse files
Show More
@@ -1,65 +1,68 b''
1 # py3kcompat.py - compatibility definitions for running hg in py3k
1 # py3kcompat.py - compatibility definitions for running hg in py3k
2 #
2 #
3 # Copyright 2010 Renato Cunha <renatoc@gmail.com>
3 # Copyright 2010 Renato Cunha <renatoc@gmail.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import builtins
8 from __future__ import absolute_import
9
9
10 from numbers import Number
10 import builtins
11 import numbers
12
13 Number = numbers.Number
11
14
12 def bytesformatter(format, args):
15 def bytesformatter(format, args):
13 '''Custom implementation of a formatter for bytestrings.
16 '''Custom implementation of a formatter for bytestrings.
14
17
15 This function currently relies on the string formatter to do the
18 This function currently relies on the string formatter to do the
16 formatting and always returns bytes objects.
19 formatting and always returns bytes objects.
17
20
18 >>> bytesformatter(20, 10)
21 >>> bytesformatter(20, 10)
19 0
22 0
20 >>> bytesformatter('unicode %s, %s!', ('string', 'foo'))
23 >>> bytesformatter('unicode %s, %s!', ('string', 'foo'))
21 b'unicode string, foo!'
24 b'unicode string, foo!'
22 >>> bytesformatter(b'test %s', 'me')
25 >>> bytesformatter(b'test %s', 'me')
23 b'test me'
26 b'test me'
24 >>> bytesformatter('test %s', 'me')
27 >>> bytesformatter('test %s', 'me')
25 b'test me'
28 b'test me'
26 >>> bytesformatter(b'test %s', b'me')
29 >>> bytesformatter(b'test %s', b'me')
27 b'test me'
30 b'test me'
28 >>> bytesformatter('test %s', b'me')
31 >>> bytesformatter('test %s', b'me')
29 b'test me'
32 b'test me'
30 >>> bytesformatter('test %d: %s', (1, b'result'))
33 >>> bytesformatter('test %d: %s', (1, b'result'))
31 b'test 1: result'
34 b'test 1: result'
32 '''
35 '''
33 # The current implementation just converts from bytes to unicode, do
36 # The current implementation just converts from bytes to unicode, do
34 # what's needed and then convert the results back to bytes.
37 # what's needed and then convert the results back to bytes.
35 # Another alternative is to use the Python C API implementation.
38 # Another alternative is to use the Python C API implementation.
36 if isinstance(format, Number):
39 if isinstance(format, Number):
37 # If the fixer erroneously passes a number remainder operation to
40 # If the fixer erroneously passes a number remainder operation to
38 # bytesformatter, we just return the correct operation
41 # bytesformatter, we just return the correct operation
39 return format % args
42 return format % args
40 if isinstance(format, bytes):
43 if isinstance(format, bytes):
41 format = format.decode('utf-8', 'surrogateescape')
44 format = format.decode('utf-8', 'surrogateescape')
42 if isinstance(args, bytes):
45 if isinstance(args, bytes):
43 args = args.decode('utf-8', 'surrogateescape')
46 args = args.decode('utf-8', 'surrogateescape')
44 if isinstance(args, tuple):
47 if isinstance(args, tuple):
45 newargs = []
48 newargs = []
46 for arg in args:
49 for arg in args:
47 if isinstance(arg, bytes):
50 if isinstance(arg, bytes):
48 arg = arg.decode('utf-8', 'surrogateescape')
51 arg = arg.decode('utf-8', 'surrogateescape')
49 newargs.append(arg)
52 newargs.append(arg)
50 args = tuple(newargs)
53 args = tuple(newargs)
51 ret = format % args
54 ret = format % args
52 return ret.encode('utf-8', 'surrogateescape')
55 return ret.encode('utf-8', 'surrogateescape')
53 builtins.bytesformatter = bytesformatter
56 builtins.bytesformatter = bytesformatter
54
57
55 origord = builtins.ord
58 origord = builtins.ord
56 def fakeord(char):
59 def fakeord(char):
57 if isinstance(char, int):
60 if isinstance(char, int):
58 return char
61 return char
59 return origord(char)
62 return origord(char)
60 builtins.ord = fakeord
63 builtins.ord = fakeord
61
64
62 if __name__ == '__main__':
65 if __name__ == '__main__':
63 import doctest
66 import doctest
64 doctest.testmod()
67 doctest.testmod()
65
68
@@ -1,200 +1,199 b''
1 #require test-repo
1 #require test-repo
2
2
3 $ cd "$TESTDIR"/..
3 $ cd "$TESTDIR"/..
4
4
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 contrib/casesmash.py not using absolute_import
6 contrib/casesmash.py not using absolute_import
7 contrib/check-code.py not using absolute_import
7 contrib/check-code.py not using absolute_import
8 contrib/check-code.py requires print_function
8 contrib/check-code.py requires print_function
9 contrib/check-config.py not using absolute_import
9 contrib/check-config.py not using absolute_import
10 contrib/check-config.py requires print_function
10 contrib/check-config.py requires print_function
11 contrib/debugcmdserver.py not using absolute_import
11 contrib/debugcmdserver.py not using absolute_import
12 contrib/debugcmdserver.py requires print_function
12 contrib/debugcmdserver.py requires print_function
13 contrib/debugshell.py not using absolute_import
13 contrib/debugshell.py not using absolute_import
14 contrib/fixpax.py not using absolute_import
14 contrib/fixpax.py not using absolute_import
15 contrib/fixpax.py requires print_function
15 contrib/fixpax.py requires print_function
16 contrib/hgclient.py not using absolute_import
16 contrib/hgclient.py not using absolute_import
17 contrib/hgclient.py requires print_function
17 contrib/hgclient.py requires print_function
18 contrib/hgfixes/fix_bytes.py not using absolute_import
18 contrib/hgfixes/fix_bytes.py not using absolute_import
19 contrib/hgfixes/fix_bytesmod.py not using absolute_import
19 contrib/hgfixes/fix_bytesmod.py not using absolute_import
20 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
20 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
21 contrib/import-checker.py not using absolute_import
21 contrib/import-checker.py not using absolute_import
22 contrib/import-checker.py requires print_function
22 contrib/import-checker.py requires print_function
23 contrib/memory.py not using absolute_import
23 contrib/memory.py not using absolute_import
24 contrib/perf.py not using absolute_import
24 contrib/perf.py not using absolute_import
25 contrib/python-hook-examples.py not using absolute_import
25 contrib/python-hook-examples.py not using absolute_import
26 contrib/revsetbenchmarks.py not using absolute_import
26 contrib/revsetbenchmarks.py not using absolute_import
27 contrib/revsetbenchmarks.py requires print_function
27 contrib/revsetbenchmarks.py requires print_function
28 contrib/showstack.py not using absolute_import
28 contrib/showstack.py not using absolute_import
29 contrib/synthrepo.py not using absolute_import
29 contrib/synthrepo.py not using absolute_import
30 contrib/win32/hgwebdir_wsgi.py not using absolute_import
30 contrib/win32/hgwebdir_wsgi.py not using absolute_import
31 doc/check-seclevel.py not using absolute_import
31 doc/check-seclevel.py not using absolute_import
32 doc/gendoc.py not using absolute_import
32 doc/gendoc.py not using absolute_import
33 doc/hgmanpage.py not using absolute_import
33 doc/hgmanpage.py not using absolute_import
34 hgext/__init__.py not using absolute_import
34 hgext/__init__.py not using absolute_import
35 hgext/acl.py not using absolute_import
35 hgext/acl.py not using absolute_import
36 hgext/blackbox.py not using absolute_import
36 hgext/blackbox.py not using absolute_import
37 hgext/bugzilla.py not using absolute_import
37 hgext/bugzilla.py not using absolute_import
38 hgext/censor.py not using absolute_import
38 hgext/censor.py not using absolute_import
39 hgext/children.py not using absolute_import
39 hgext/children.py not using absolute_import
40 hgext/churn.py not using absolute_import
40 hgext/churn.py not using absolute_import
41 hgext/clonebundles.py not using absolute_import
41 hgext/clonebundles.py not using absolute_import
42 hgext/color.py not using absolute_import
42 hgext/color.py not using absolute_import
43 hgext/convert/__init__.py not using absolute_import
43 hgext/convert/__init__.py not using absolute_import
44 hgext/convert/bzr.py not using absolute_import
44 hgext/convert/bzr.py not using absolute_import
45 hgext/convert/common.py not using absolute_import
45 hgext/convert/common.py not using absolute_import
46 hgext/convert/convcmd.py not using absolute_import
46 hgext/convert/convcmd.py not using absolute_import
47 hgext/convert/cvs.py not using absolute_import
47 hgext/convert/cvs.py not using absolute_import
48 hgext/convert/cvsps.py not using absolute_import
48 hgext/convert/cvsps.py not using absolute_import
49 hgext/convert/darcs.py not using absolute_import
49 hgext/convert/darcs.py not using absolute_import
50 hgext/convert/filemap.py not using absolute_import
50 hgext/convert/filemap.py not using absolute_import
51 hgext/convert/git.py not using absolute_import
51 hgext/convert/git.py not using absolute_import
52 hgext/convert/gnuarch.py not using absolute_import
52 hgext/convert/gnuarch.py not using absolute_import
53 hgext/convert/hg.py not using absolute_import
53 hgext/convert/hg.py not using absolute_import
54 hgext/convert/monotone.py not using absolute_import
54 hgext/convert/monotone.py not using absolute_import
55 hgext/convert/p4.py not using absolute_import
55 hgext/convert/p4.py not using absolute_import
56 hgext/convert/subversion.py not using absolute_import
56 hgext/convert/subversion.py not using absolute_import
57 hgext/convert/transport.py not using absolute_import
57 hgext/convert/transport.py not using absolute_import
58 hgext/eol.py not using absolute_import
58 hgext/eol.py not using absolute_import
59 hgext/extdiff.py not using absolute_import
59 hgext/extdiff.py not using absolute_import
60 hgext/factotum.py not using absolute_import
60 hgext/factotum.py not using absolute_import
61 hgext/fetch.py not using absolute_import
61 hgext/fetch.py not using absolute_import
62 hgext/gpg.py not using absolute_import
62 hgext/gpg.py not using absolute_import
63 hgext/graphlog.py not using absolute_import
63 hgext/graphlog.py not using absolute_import
64 hgext/hgcia.py not using absolute_import
64 hgext/hgcia.py not using absolute_import
65 hgext/hgk.py not using absolute_import
65 hgext/hgk.py not using absolute_import
66 hgext/highlight/__init__.py not using absolute_import
66 hgext/highlight/__init__.py not using absolute_import
67 hgext/highlight/highlight.py not using absolute_import
67 hgext/highlight/highlight.py not using absolute_import
68 hgext/histedit.py not using absolute_import
68 hgext/histedit.py not using absolute_import
69 hgext/keyword.py not using absolute_import
69 hgext/keyword.py not using absolute_import
70 hgext/largefiles/__init__.py not using absolute_import
70 hgext/largefiles/__init__.py not using absolute_import
71 hgext/largefiles/basestore.py not using absolute_import
71 hgext/largefiles/basestore.py not using absolute_import
72 hgext/largefiles/lfcommands.py not using absolute_import
72 hgext/largefiles/lfcommands.py not using absolute_import
73 hgext/largefiles/lfutil.py not using absolute_import
73 hgext/largefiles/lfutil.py not using absolute_import
74 hgext/largefiles/localstore.py not using absolute_import
74 hgext/largefiles/localstore.py not using absolute_import
75 hgext/largefiles/overrides.py not using absolute_import
75 hgext/largefiles/overrides.py not using absolute_import
76 hgext/largefiles/proto.py not using absolute_import
76 hgext/largefiles/proto.py not using absolute_import
77 hgext/largefiles/remotestore.py not using absolute_import
77 hgext/largefiles/remotestore.py not using absolute_import
78 hgext/largefiles/reposetup.py not using absolute_import
78 hgext/largefiles/reposetup.py not using absolute_import
79 hgext/largefiles/uisetup.py not using absolute_import
79 hgext/largefiles/uisetup.py not using absolute_import
80 hgext/largefiles/wirestore.py not using absolute_import
80 hgext/largefiles/wirestore.py not using absolute_import
81 hgext/mq.py not using absolute_import
81 hgext/mq.py not using absolute_import
82 hgext/notify.py not using absolute_import
82 hgext/notify.py not using absolute_import
83 hgext/pager.py not using absolute_import
83 hgext/pager.py not using absolute_import
84 hgext/patchbomb.py not using absolute_import
84 hgext/patchbomb.py not using absolute_import
85 hgext/purge.py not using absolute_import
85 hgext/purge.py not using absolute_import
86 hgext/rebase.py not using absolute_import
86 hgext/rebase.py not using absolute_import
87 hgext/record.py not using absolute_import
87 hgext/record.py not using absolute_import
88 hgext/relink.py not using absolute_import
88 hgext/relink.py not using absolute_import
89 hgext/schemes.py not using absolute_import
89 hgext/schemes.py not using absolute_import
90 hgext/share.py not using absolute_import
90 hgext/share.py not using absolute_import
91 hgext/shelve.py not using absolute_import
91 hgext/shelve.py not using absolute_import
92 hgext/strip.py not using absolute_import
92 hgext/strip.py not using absolute_import
93 hgext/transplant.py not using absolute_import
93 hgext/transplant.py not using absolute_import
94 hgext/win32mbcs.py not using absolute_import
94 hgext/win32mbcs.py not using absolute_import
95 hgext/win32text.py not using absolute_import
95 hgext/win32text.py not using absolute_import
96 hgext/zeroconf/Zeroconf.py not using absolute_import
96 hgext/zeroconf/Zeroconf.py not using absolute_import
97 hgext/zeroconf/Zeroconf.py requires print_function
97 hgext/zeroconf/Zeroconf.py requires print_function
98 hgext/zeroconf/__init__.py not using absolute_import
98 hgext/zeroconf/__init__.py not using absolute_import
99 i18n/check-translation.py not using absolute_import
99 i18n/check-translation.py not using absolute_import
100 i18n/polib.py not using absolute_import
100 i18n/polib.py not using absolute_import
101 mercurial/byterange.py not using absolute_import
101 mercurial/byterange.py not using absolute_import
102 mercurial/cmdutil.py not using absolute_import
102 mercurial/cmdutil.py not using absolute_import
103 mercurial/commands.py not using absolute_import
103 mercurial/commands.py not using absolute_import
104 mercurial/context.py not using absolute_import
104 mercurial/context.py not using absolute_import
105 mercurial/dirstate.py not using absolute_import
105 mercurial/dirstate.py not using absolute_import
106 mercurial/dispatch.py requires print_function
106 mercurial/dispatch.py requires print_function
107 mercurial/exchange.py not using absolute_import
107 mercurial/exchange.py not using absolute_import
108 mercurial/httpclient/__init__.py not using absolute_import
108 mercurial/httpclient/__init__.py not using absolute_import
109 mercurial/httpclient/_readers.py not using absolute_import
109 mercurial/httpclient/_readers.py not using absolute_import
110 mercurial/httpclient/socketutil.py not using absolute_import
110 mercurial/httpclient/socketutil.py not using absolute_import
111 mercurial/httpconnection.py not using absolute_import
111 mercurial/httpconnection.py not using absolute_import
112 mercurial/keepalive.py not using absolute_import
112 mercurial/keepalive.py not using absolute_import
113 mercurial/keepalive.py requires print_function
113 mercurial/keepalive.py requires print_function
114 mercurial/localrepo.py not using absolute_import
114 mercurial/localrepo.py not using absolute_import
115 mercurial/lsprof.py requires print_function
115 mercurial/lsprof.py requires print_function
116 mercurial/lsprofcalltree.py not using absolute_import
116 mercurial/lsprofcalltree.py not using absolute_import
117 mercurial/lsprofcalltree.py requires print_function
117 mercurial/lsprofcalltree.py requires print_function
118 mercurial/mail.py requires print_function
118 mercurial/mail.py requires print_function
119 mercurial/manifest.py not using absolute_import
119 mercurial/manifest.py not using absolute_import
120 mercurial/pvec.py not using absolute_import
120 mercurial/pvec.py not using absolute_import
121 mercurial/py3kcompat.py not using absolute_import
122 setup.py not using absolute_import
121 setup.py not using absolute_import
123 tests/filterpyflakes.py requires print_function
122 tests/filterpyflakes.py requires print_function
124 tests/generate-working-copy-states.py requires print_function
123 tests/generate-working-copy-states.py requires print_function
125 tests/get-with-headers.py requires print_function
124 tests/get-with-headers.py requires print_function
126 tests/heredoctest.py requires print_function
125 tests/heredoctest.py requires print_function
127 tests/hypothesishelpers.py not using absolute_import
126 tests/hypothesishelpers.py not using absolute_import
128 tests/hypothesishelpers.py requires print_function
127 tests/hypothesishelpers.py requires print_function
129 tests/killdaemons.py not using absolute_import
128 tests/killdaemons.py not using absolute_import
130 tests/md5sum.py not using absolute_import
129 tests/md5sum.py not using absolute_import
131 tests/mockblackbox.py not using absolute_import
130 tests/mockblackbox.py not using absolute_import
132 tests/printenv.py not using absolute_import
131 tests/printenv.py not using absolute_import
133 tests/readlink.py not using absolute_import
132 tests/readlink.py not using absolute_import
134 tests/readlink.py requires print_function
133 tests/readlink.py requires print_function
135 tests/revlog-formatv0.py not using absolute_import
134 tests/revlog-formatv0.py not using absolute_import
136 tests/run-tests.py not using absolute_import
135 tests/run-tests.py not using absolute_import
137 tests/seq.py not using absolute_import
136 tests/seq.py not using absolute_import
138 tests/seq.py requires print_function
137 tests/seq.py requires print_function
139 tests/silenttestrunner.py not using absolute_import
138 tests/silenttestrunner.py not using absolute_import
140 tests/silenttestrunner.py requires print_function
139 tests/silenttestrunner.py requires print_function
141 tests/sitecustomize.py not using absolute_import
140 tests/sitecustomize.py not using absolute_import
142 tests/svn-safe-append.py not using absolute_import
141 tests/svn-safe-append.py not using absolute_import
143 tests/svnxml.py not using absolute_import
142 tests/svnxml.py not using absolute_import
144 tests/test-ancestor.py requires print_function
143 tests/test-ancestor.py requires print_function
145 tests/test-atomictempfile.py not using absolute_import
144 tests/test-atomictempfile.py not using absolute_import
146 tests/test-batching.py not using absolute_import
145 tests/test-batching.py not using absolute_import
147 tests/test-batching.py requires print_function
146 tests/test-batching.py requires print_function
148 tests/test-bdiff.py not using absolute_import
147 tests/test-bdiff.py not using absolute_import
149 tests/test-bdiff.py requires print_function
148 tests/test-bdiff.py requires print_function
150 tests/test-context.py not using absolute_import
149 tests/test-context.py not using absolute_import
151 tests/test-context.py requires print_function
150 tests/test-context.py requires print_function
152 tests/test-demandimport.py not using absolute_import
151 tests/test-demandimport.py not using absolute_import
153 tests/test-demandimport.py requires print_function
152 tests/test-demandimport.py requires print_function
154 tests/test-dispatch.py not using absolute_import
153 tests/test-dispatch.py not using absolute_import
155 tests/test-dispatch.py requires print_function
154 tests/test-dispatch.py requires print_function
156 tests/test-doctest.py not using absolute_import
155 tests/test-doctest.py not using absolute_import
157 tests/test-duplicateoptions.py not using absolute_import
156 tests/test-duplicateoptions.py not using absolute_import
158 tests/test-duplicateoptions.py requires print_function
157 tests/test-duplicateoptions.py requires print_function
159 tests/test-filecache.py not using absolute_import
158 tests/test-filecache.py not using absolute_import
160 tests/test-filecache.py requires print_function
159 tests/test-filecache.py requires print_function
161 tests/test-filelog.py not using absolute_import
160 tests/test-filelog.py not using absolute_import
162 tests/test-filelog.py requires print_function
161 tests/test-filelog.py requires print_function
163 tests/test-hg-parseurl.py not using absolute_import
162 tests/test-hg-parseurl.py not using absolute_import
164 tests/test-hg-parseurl.py requires print_function
163 tests/test-hg-parseurl.py requires print_function
165 tests/test-hgweb-auth.py not using absolute_import
164 tests/test-hgweb-auth.py not using absolute_import
166 tests/test-hgweb-auth.py requires print_function
165 tests/test-hgweb-auth.py requires print_function
167 tests/test-hgwebdir-paths.py not using absolute_import
166 tests/test-hgwebdir-paths.py not using absolute_import
168 tests/test-hybridencode.py not using absolute_import
167 tests/test-hybridencode.py not using absolute_import
169 tests/test-hybridencode.py requires print_function
168 tests/test-hybridencode.py requires print_function
170 tests/test-lrucachedict.py not using absolute_import
169 tests/test-lrucachedict.py not using absolute_import
171 tests/test-lrucachedict.py requires print_function
170 tests/test-lrucachedict.py requires print_function
172 tests/test-manifest.py not using absolute_import
171 tests/test-manifest.py not using absolute_import
173 tests/test-minirst.py not using absolute_import
172 tests/test-minirst.py not using absolute_import
174 tests/test-minirst.py requires print_function
173 tests/test-minirst.py requires print_function
175 tests/test-parseindex2.py not using absolute_import
174 tests/test-parseindex2.py not using absolute_import
176 tests/test-parseindex2.py requires print_function
175 tests/test-parseindex2.py requires print_function
177 tests/test-pathencode.py not using absolute_import
176 tests/test-pathencode.py not using absolute_import
178 tests/test-pathencode.py requires print_function
177 tests/test-pathencode.py requires print_function
179 tests/test-propertycache.py not using absolute_import
178 tests/test-propertycache.py not using absolute_import
180 tests/test-propertycache.py requires print_function
179 tests/test-propertycache.py requires print_function
181 tests/test-revlog-ancestry.py not using absolute_import
180 tests/test-revlog-ancestry.py not using absolute_import
182 tests/test-revlog-ancestry.py requires print_function
181 tests/test-revlog-ancestry.py requires print_function
183 tests/test-run-tests.py not using absolute_import
182 tests/test-run-tests.py not using absolute_import
184 tests/test-simplemerge.py not using absolute_import
183 tests/test-simplemerge.py not using absolute_import
185 tests/test-status-inprocess.py not using absolute_import
184 tests/test-status-inprocess.py not using absolute_import
186 tests/test-status-inprocess.py requires print_function
185 tests/test-status-inprocess.py requires print_function
187 tests/test-symlink-os-yes-fs-no.py not using absolute_import
186 tests/test-symlink-os-yes-fs-no.py not using absolute_import
188 tests/test-trusted.py not using absolute_import
187 tests/test-trusted.py not using absolute_import
189 tests/test-trusted.py requires print_function
188 tests/test-trusted.py requires print_function
190 tests/test-ui-color.py not using absolute_import
189 tests/test-ui-color.py not using absolute_import
191 tests/test-ui-color.py requires print_function
190 tests/test-ui-color.py requires print_function
192 tests/test-ui-config.py not using absolute_import
191 tests/test-ui-config.py not using absolute_import
193 tests/test-ui-config.py requires print_function
192 tests/test-ui-config.py requires print_function
194 tests/test-ui-verbosity.py not using absolute_import
193 tests/test-ui-verbosity.py not using absolute_import
195 tests/test-ui-verbosity.py requires print_function
194 tests/test-ui-verbosity.py requires print_function
196 tests/test-url.py not using absolute_import
195 tests/test-url.py not using absolute_import
197 tests/test-url.py requires print_function
196 tests/test-url.py requires print_function
198 tests/test-walkrepo.py requires print_function
197 tests/test-walkrepo.py requires print_function
199 tests/test-wireproto.py requires print_function
198 tests/test-wireproto.py requires print_function
200 tests/tinyproxy.py requires print_function
199 tests/tinyproxy.py requires print_function
General Comments 0
You need to be logged in to leave comments. Login now