changeset 4745:854637e3d2d0

py3: use array.array.{to,from}bytes() on py3 array.array.{to,from}string() still exists on py3, but they're deprecated and generate warnings. I've put the compat function in compat.pt for now. We can move into a dedicated pycompat.py if we end up with a lot of py3 compat stuff.
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 09 Jul 2019 10:56:42 -0700
parents 45afcbfea417
children 724c67878d98
files hgext3rd/evolve/compat.py hgext3rd/evolve/depthcache.py hgext3rd/evolve/firstmergecache.py hgext3rd/evolve/stablesort.py
diffstat 4 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/compat.py	Thu Jul 11 14:31:32 2019 -0700
+++ b/hgext3rd/evolve/compat.py	Tue Jul 09 10:56:42 2019 -0700
@@ -7,6 +7,7 @@
 """
 
 import inspect
+import array
 
 from mercurial import (
     context,
@@ -15,6 +16,7 @@
     mdiff,
     obsolete,
     obsutil,
+    pycompat,
     repair,
     scmutil,
     util,
@@ -22,6 +24,13 @@
 )
 from mercurial.hgweb import hgweb_mod
 
+if pycompat.ispy3:
+    arraytobytes = array.array.tobytes
+    arrayfrombytes = array.array.frombytes
+else:
+    arraytobytes = array.array.tostring
+    arrayfrombytes = array.array.fromstring
+
 # hg < 4.6 compat (c8e2d6ed1f9e)
 try:
     from mercurial import logcmdutil
--- a/hgext3rd/evolve/depthcache.py	Thu Jul 11 14:31:32 2019 -0700
+++ b/hgext3rd/evolve/depthcache.py	Tue Jul 09 10:56:42 2019 -0700
@@ -185,7 +185,7 @@
         else:
             headerdata = data[:self._cachekeysize]
             self._cachekey = self._deserializecachekey(headerdata)
-            self._data.fromstring(data[self._cachekeysize:])
+            compat.arrayfrombytes(self._data, data[self._cachekeysize:])
         self._ondiskkey = self._cachekey
 
     def save(self, repo):
@@ -201,7 +201,7 @@
             cachefile = repo.cachevfs(self._filepath, 'w', atomictemp=True)
             headerdata = self._serializecachekey()
             cachefile.write(headerdata)
-            cachefile.write(self._data.tostring())
+            cachefile.write(compat.arraytobytes(self._data))
             cachefile.close()
             self._ondiskkey = self._cachekey
         except (IOError, OSError) as exc:
--- a/hgext3rd/evolve/firstmergecache.py	Thu Jul 11 14:31:32 2019 -0700
+++ b/hgext3rd/evolve/firstmergecache.py	Tue Jul 09 10:56:42 2019 -0700
@@ -122,7 +122,7 @@
         else:
             headerdata = data[:self._cachekeysize]
             self._cachekey = self._deserializecachekey(headerdata)
-            self._data.fromstring(data[self._cachekeysize:])
+            compat.arrayfrombytes(self._data, data[self._cachekeysize:])
         self._ondiskkey = self._cachekey
 
     def save(self, repo):
@@ -138,7 +138,7 @@
             cachefile = repo.cachevfs(self._filepath, 'w', atomictemp=True)
             headerdata = self._serializecachekey()
             cachefile.write(headerdata)
-            cachefile.write(self._data.tostring())
+            cachefile.write(compat.arraytobytes(self._data))
             cachefile.close()
             self._ondiskkey = self._cachekey
         except (IOError, OSError) as exc:
--- a/hgext3rd/evolve/stablesort.py	Thu Jul 11 14:31:32 2019 -0700
+++ b/hgext3rd/evolve/stablesort.py	Tue Jul 09 10:56:42 2019 -0700
@@ -620,9 +620,9 @@
             indexsizedata = data[offset:offset + S_INDEXSIZE.size]
             indexsize = S_INDEXSIZE.unpack(indexsizedata)[0]
             offset += S_INDEXSIZE.size
-            self._index.fromstring(data[offset:offset + indexsize])
+            compat.arrayfrombytes(self._index, data[offset:offset + indexsize])
             offset += indexsize
-            self._data.fromstring(data[offset:])
+            compat.arrayfrombytes(self._data, data[offset:])
         self._ondiskkey = self._cachekey
         pass
 
@@ -638,8 +638,8 @@
 
             # data to write
             headerdata = self._serializecachekey()
-            indexdata = self._index.tostring()
-            data = self._data.tostring()
+            indexdata = compat.arraytobytes(self._index)
+            data = compat.arraytobytes(self._data)
             indexsize = S_INDEXSIZE.pack(len(indexdata))
 
             # writing