##// END OF EJS Templates
setup.py: use bytes literals...
Gregory Szorc -
r27348:83a8219f default
parent child Browse files
Show More
@@ -9,22 +9,14 b" if getattr(sys, 'version_info', (0, 0, 0"
9 raise SystemExit("Mercurial requires Python 2.6 or later.")
9 raise SystemExit("Mercurial requires Python 2.6 or later.")
10
10
11 if sys.version_info[0] >= 3:
11 if sys.version_info[0] >= 3:
12 def b(s):
13 '''A helper function to emulate 2.6+ bytes literals using string
14 literals.'''
15 return s.encode('latin1')
16 printf = eval('print')
12 printf = eval('print')
17 libdir_escape = 'unicode_escape'
13 libdir_escape = 'unicode_escape'
18 else:
14 else:
19 libdir_escape = 'string_escape'
15 libdir_escape = 'string_escape'
20 def b(s):
21 '''A helper function to emulate 2.6+ bytes literals using string
22 literals.'''
23 return s
24 def printf(*args, **kwargs):
16 def printf(*args, **kwargs):
25 f = kwargs.get('file', sys.stdout)
17 f = kwargs.get('file', sys.stdout)
26 end = kwargs.get('end', '\n')
18 end = kwargs.get('end', '\n')
27 f.write(b(' ').join(args) + end)
19 f.write(b' '.join(args) + end)
28
20
29 # Solaris Python packaging brain damage
21 # Solaris Python packaging brain damage
30 try:
22 try:
@@ -172,12 +164,12 b' def runhg(cmd, env):'
172 # fine, we don't want to load it anyway. Python may warn about
164 # fine, we don't want to load it anyway. Python may warn about
173 # a missing __init__.py in mercurial/locale, we also ignore that.
165 # a missing __init__.py in mercurial/locale, we also ignore that.
174 err = [e for e in err.splitlines()
166 err = [e for e in err.splitlines()
175 if not e.startswith(b('not trusting file')) \
167 if not e.startswith(b'not trusting file') \
176 and not e.startswith(b('warning: Not importing')) \
168 and not e.startswith(b'warning: Not importing') \
177 and not e.startswith(b('obsolete feature not enabled'))]
169 and not e.startswith(b'obsolete feature not enabled')]
178 if err:
170 if err:
179 printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
171 printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
180 printf(b('\n').join([b(' ') + e for e in err]), file=sys.stderr)
172 printf(b'\n'.join([b' ' + e for e in err]), file=sys.stderr)
181 return ''
173 return ''
182 return out
174 return out
183
175
@@ -516,7 +508,7 b' class hginstallscripts(install_scripts):'
516 fp.close()
508 fp.close()
517
509
518 # skip binary files
510 # skip binary files
519 if b('\0') in data:
511 if b'\0' in data:
520 continue
512 continue
521
513
522 # During local installs, the shebang will be rewritten to the final
514 # During local installs, the shebang will be rewritten to the final
@@ -527,7 +519,7 b' class hginstallscripts(install_scripts):'
527 'not known' % outfile)
519 'not known' % outfile)
528 continue
520 continue
529
521
530 data = data.replace(b('@LIBDIR@'), libdir.encode(libdir_escape))
522 data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
531 fp = open(outfile, 'wb')
523 fp = open(outfile, 'wb')
532 fp.write(data)
524 fp.write(data)
533 fp.close()
525 fp.close()
General Comments 0
You need to be logged in to leave comments. Login now