changeset 27348:83a8219fb790

setup.py: use bytes literals The b() helper was needed because Python < 2.6 didn't support bytes literals (b''). Now that we don't support Python < 2.6, we no longer need this helper.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 13 Dec 2015 09:40:53 -0800
parents 7807fe2795fb
children 5b68f72c2ba9
files setup.py
diffstat 1 files changed, 7 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Tue Dec 15 07:17:15 2015 +0100
+++ b/setup.py	Sun Dec 13 09:40:53 2015 -0800
@@ -9,22 +9,14 @@
     raise SystemExit("Mercurial requires Python 2.6 or later.")
 
 if sys.version_info[0] >= 3:
-    def b(s):
-        '''A helper function to emulate 2.6+ bytes literals using string
-        literals.'''
-        return s.encode('latin1')
     printf = eval('print')
     libdir_escape = 'unicode_escape'
 else:
     libdir_escape = 'string_escape'
-    def b(s):
-        '''A helper function to emulate 2.6+ bytes literals using string
-        literals.'''
-        return s
     def printf(*args, **kwargs):
         f = kwargs.get('file', sys.stdout)
         end = kwargs.get('end', '\n')
-        f.write(b(' ').join(args) + end)
+        f.write(b' '.join(args) + end)
 
 # Solaris Python packaging brain damage
 try:
@@ -172,12 +164,12 @@
     # fine, we don't want to load it anyway.  Python may warn about
     # a missing __init__.py in mercurial/locale, we also ignore that.
     err = [e for e in err.splitlines()
-           if not e.startswith(b('not trusting file')) \
-              and not e.startswith(b('warning: Not importing')) \
-              and not e.startswith(b('obsolete feature not enabled'))]
+           if not e.startswith(b'not trusting file') \
+              and not e.startswith(b'warning: Not importing') \
+              and not e.startswith(b'obsolete feature not enabled')]
     if err:
         printf("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr)
-        printf(b('\n').join([b('  ') + e for e in err]), file=sys.stderr)
+        printf(b'\n'.join([b'  ' + e for e in err]), file=sys.stderr)
         return ''
     return out
 
@@ -516,7 +508,7 @@
             fp.close()
 
             # skip binary files
-            if b('\0') in data:
+            if b'\0' in data:
                 continue
 
             # During local installs, the shebang will be rewritten to the final
@@ -527,7 +519,7 @@
                          'not known' % outfile)
                 continue
 
-            data = data.replace(b('@LIBDIR@'), libdir.encode(libdir_escape))
+            data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
             fp = open(outfile, 'wb')
             fp.write(data)
             fp.close()