changeset 49288:ef5f5f1cbd90

py3: constant-fold some `pycompat.ispy3`
author Manuel Jacob <me@manueljacob.de>
date Tue, 31 May 2022 00:50:29 +0200
parents 7fe82a5101c9
children 6c4c341d8fa5
files hgext/convert/common.py hgext/git/gitlog.py hgext/hooklib/changeset_obsoleted.py hgext/hooklib/changeset_published.py hgext/notify.py
diffstat 5 files changed, 12 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Sun May 29 15:38:01 2022 +0200
+++ b/hgext/convert/common.py	Tue May 31 00:50:29 2022 +0200
@@ -55,45 +55,25 @@
 
 def shlexer(data=None, filepath=None, wordchars=None, whitespace=None):
     if data is None:
-        if pycompat.ispy3:
-            data = open(filepath, b'r', encoding='latin1')
-        else:
-            data = open(filepath, b'r')
+        data = open(filepath, b'r', encoding='latin1')
     else:
         if filepath is not None:
             raise error.ProgrammingError(
                 b'shlexer only accepts data or filepath, not both'
             )
-        if pycompat.ispy3:
-            data = data.decode('latin1')
+        data = data.decode('latin1')
     l = shlex.shlex(data, infile=filepath, posix=True)
     if whitespace is not None:
         l.whitespace_split = True
-        if pycompat.ispy3:
-            l.whitespace += whitespace.decode('latin1')
-        else:
-            l.whitespace += whitespace
+        l.whitespace += whitespace.decode('latin1')
     if wordchars is not None:
-        if pycompat.ispy3:
-            l.wordchars += wordchars.decode('latin1')
-        else:
-            l.wordchars += wordchars
-    if pycompat.ispy3:
-        return _shlexpy3proxy(l)
-    return l
-
-
-if pycompat.ispy3:
-    base64_encodebytes = base64.encodebytes
-    base64_decodebytes = base64.decodebytes
-else:
-    base64_encodebytes = base64.encodestring
-    base64_decodebytes = base64.decodestring
+        l.wordchars += wordchars.decode('latin1')
+    return _shlexpy3proxy(l)
 
 
 def encodeargs(args):
     def encodearg(s):
-        lines = base64_encodebytes(s)
+        lines = base64.encodebytes(s)
         lines = [l.splitlines()[0] for l in pycompat.iterbytestr(lines)]
         return b''.join(lines)
 
@@ -102,7 +82,7 @@
 
 
 def decodeargs(s):
-    s = base64_decodebytes(s)
+    s = base64.decodebytes(s)
     return pickle.loads(s)
 
 
--- a/hgext/git/gitlog.py	Sun May 29 15:38:01 2022 +0200
+++ b/hgext/git/gitlog.py	Tue May 31 00:50:29 2022 +0200
@@ -534,8 +534,7 @@
                 ).fetchone()[0]
                 # This filelog is missing some data. Build the
                 # filelog, then recurse (which will always find data).
-                if pycompat.ispy3:
-                    commit = commit.decode('ascii')
+                commit = commit.decode('ascii')
                 index.fill_in_filelog(self.gitrepo, self._db, commit, gp, gn)
                 return self.parents(node)
             else:
--- a/hgext/hooklib/changeset_obsoleted.py	Sun May 29 15:38:01 2022 +0200
+++ b/hgext/hooklib/changeset_obsoleted.py	Tue May 31 00:50:29 2022 +0200
@@ -114,7 +114,7 @@
         msg['From'] = mail.addressencode(ui, sender, n.charsets, n.test)
     msg['To'] = ', '.join(sorted(subs))
 
-    msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
+    msgtext = msg.as_bytes()
     if ui.configbool(b'notify', b'test'):
         ui.write(msgtext)
         if not msgtext.endswith(b'\n'):
--- a/hgext/hooklib/changeset_published.py	Sun May 29 15:38:01 2022 +0200
+++ b/hgext/hooklib/changeset_published.py	Tue May 31 00:50:29 2022 +0200
@@ -113,7 +113,7 @@
         msg['From'] = mail.addressencode(ui, sender, n.charsets, n.test)
     msg['To'] = ', '.join(sorted(subs))
 
-    msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
+    msgtext = msg.as_bytes()
     if ui.configbool(b'notify', b'test'):
         ui.write(msgtext)
         if not msgtext.endswith(b'\n'):
--- a/hgext/notify.py	Sun May 29 15:38:01 2022 +0200
+++ b/hgext/notify.py	Tue May 31 00:50:29 2022 +0200
@@ -465,7 +465,7 @@
             # create fresh mime message from scratch
             # (multipart templates must take care of this themselves)
             headers = msg.items()
-            payload = msg.get_payload(decode=pycompat.ispy3)
+            payload = msg.get_payload(decode=True)
             # for notification prefer readability over data precision
             msg = mail.mimeencode(self.ui, payload, self.charsets, self.test)
             # reinstate custom headers
@@ -524,7 +524,7 @@
                 )
         msg['To'] = ', '.join(sorted(subs))
 
-        msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
+        msgtext = msg.as_bytes()
         if self.test:
             self.ui.write(msgtext)
             if not msgtext.endswith(b'\n'):