summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorAdrian Tschira <nota@notafile.com>2018-05-29 17:10:06 +0200
committerAdrian Tschira <nota@notafile.com>2018-05-29 17:14:34 +0200
commit1afafb34978726b63c2a02520ff20d85382ce2bc (patch)
treec3ff3cccba905fe43117fe413d247b23e67d4c49 /synapse/storage
parentMerge pull request #3299 from matrix-org/matthew/macos-fixes (diff)
downloadsynapse-1afafb34978726b63c2a02520ff20d85382ce2bc.tar.xz
use memoryview in py3
Signed-off-by: Adrian Tschira <nota@notafile.com>
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/keys.py8
-rw-r--r--synapse/storage/signatures.py12
2 files changed, 18 insertions, 2 deletions
diff --git a/synapse/storage/keys.py b/synapse/storage/keys.py
index 0540c2b0b1..e56c464852 100644
--- a/synapse/storage/keys.py
+++ b/synapse/storage/keys.py
@@ -17,6 +17,7 @@ from ._base import SQLBaseStore
 from synapse.util.caches.descriptors import cachedInlineCallbacks
 
 from twisted.internet import defer
+import six
 
 import OpenSSL
 from signedjson.key import decode_verify_key_bytes
@@ -26,6 +27,13 @@ import logging
 
 logger = logging.getLogger(__name__)
 
+# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
+# despite being deprecated and removed in favor of memoryview
+if six.PY2:
+    db_binary_type = buffer
+else:
+    db_binary_type = memoryview
+
 
 class KeyStore(SQLBaseStore):
     """Persistence for signature verification keys and tls X.509 certificates
diff --git a/synapse/storage/signatures.py b/synapse/storage/signatures.py
index 9e6eaaa532..25922e5a9c 100644
--- a/synapse/storage/signatures.py
+++ b/synapse/storage/signatures.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 from twisted.internet import defer
+import six
 
 from ._base import SQLBaseStore
 
@@ -21,6 +22,13 @@ from unpaddedbase64 import encode_base64
 from synapse.crypto.event_signing import compute_event_reference_hash
 from synapse.util.caches.descriptors import cached, cachedList
 
+# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
+# despite being deprecated and removed in favor of memoryview
+if six.PY2:
+    db_binary_type = buffer
+else:
+    db_binary_type = memoryview
+
 
 class SignatureWorkerStore(SQLBaseStore):
     @cached()
@@ -56,7 +64,7 @@ class SignatureWorkerStore(SQLBaseStore):
             for e_id, h in hashes.items()
         }
 
-        defer.returnValue(hashes.items())
+        defer.returnValue(list(hashes.items()))
 
     def _get_event_reference_hashes_txn(self, txn, event_id):
         """Get all the hashes for a given PDU.
@@ -91,7 +99,7 @@ class SignatureStore(SignatureWorkerStore):
             vals.append({
                 "event_id": event.event_id,
                 "algorithm": ref_alg,
-                "hash": buffer(ref_hash_bytes),
+                "hash": db_binary_type(ref_hash_bytes),
             })
 
         self._simple_insert_many_txn(