summaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorefkin <efkin@riseup.net>2017-03-13 21:17:18 +0100
committerKali Kaneko <kali@leap.se>2017-03-17 17:52:57 +0100
commit7562655cf4bf28a1ebd6c458334da0c166f34e61 (patch)
tree54bc2de9b71e35d56fdcc3dd1ee9642ce8fd491d /client/src
parentba3fcb08eafd389bdbf0ab9c59577a25c8d8126d (diff)
[refactor] Improve python3 compatibility
With this commit all tests on py34 tox environment are collected.
Diffstat (limited to 'client/src')
-rw-r--r--client/src/leap/soledad/client/_crypto.py8
-rw-r--r--client/src/leap/soledad/client/_secrets/storage.py2
-rw-r--r--client/src/leap/soledad/client/adbapi.py9
-rw-r--r--client/src/leap/soledad/client/api.py15
-rw-r--r--client/src/leap/soledad/client/http_target/api.py2
-rw-r--r--client/src/leap/soledad/client/http_target/fetch_protocol.py4
-rw-r--r--client/src/leap/soledad/client/http_target/send_protocol.py5
-rw-r--r--client/src/leap/soledad/client/sqlcipher.py9
8 files changed, 29 insertions, 25 deletions
diff --git a/client/src/leap/soledad/client/_crypto.py b/client/src/leap/soledad/client/_crypto.py
index f91084a4..f9a20285 100644
--- a/client/src/leap/soledad/client/_crypto.py
+++ b/client/src/leap/soledad/client/_crypto.py
@@ -30,7 +30,7 @@ import struct
import time
from io import BytesIO
-from itertools import imap
+from six.moves import map as imap
from collections import namedtuple
from twisted.internet import defer
@@ -43,7 +43,7 @@ from cryptography.hazmat.backends.multibackend import MultiBackend
from cryptography.hazmat.backends.openssl.backend \
import Backend as OpenSSLBackend
-from zope.interface import implements
+from zope.interface import implementer
SECRET_LENGTH = 64
@@ -290,7 +290,7 @@ class BlobDecryptor(object):
magic, sch, meth, ts, iv, doc_id, rev, doc_size = unpacked_data
else:
raise InvalidBlob("Unexpected preamble size %d", len(preamble))
- except struct.error, e:
+ except struct.error as e:
raise InvalidBlob(e)
if magic != BLOB_SIGNATURE_MAGIC:
@@ -325,12 +325,12 @@ class BlobDecryptor(object):
return d
+@implementer(interfaces.IConsumer)
class AESWriter(object):
"""
A Twisted's Consumer implementation that takes an input file descriptor and
applies AES-256 cipher in GCM mode.
"""
- implements(interfaces.IConsumer)
def __init__(self, key, iv=None, _buffer=None, tag=None, mode=modes.GCM):
if len(key) != 32:
diff --git a/client/src/leap/soledad/client/_secrets/storage.py b/client/src/leap/soledad/client/_secrets/storage.py
index 056c4322..6ea89900 100644
--- a/client/src/leap/soledad/client/_secrets/storage.py
+++ b/client/src/leap/soledad/client/_secrets/storage.py
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
-import urlparse
+import six.moves.urllib.parse as urlparse
from hashlib import sha256
diff --git a/client/src/leap/soledad/client/adbapi.py b/client/src/leap/soledad/client/adbapi.py
index a5328d2b..2bc146bd 100644
--- a/client/src/leap/soledad/client/adbapi.py
+++ b/client/src/leap/soledad/client/adbapi.py
@@ -26,14 +26,17 @@ from functools import partial
from twisted.enterprise import adbapi
from twisted.internet.defer import DeferredSemaphore
from zope.proxy import ProxyBase, setProxiedObject
-from pysqlcipher import dbapi2
from leap.soledad.common.log import getLogger
from leap.soledad.common.errors import DatabaseAccessError
-
from leap.soledad.client import sqlcipher as soledad_sqlcipher
from leap.soledad.client.pragmas import set_init_pragmas
+if sys.version_info[0] < 3:
+ from pysqlcipher import dbapi2
+else:
+ from pysqlcipher3 import dbapi2
+
logger = getLogger(__name__)
@@ -276,7 +279,7 @@ class U1DBConnectionPool(adbapi.ConnectionPool):
conn.rollback()
except:
logger.error(None, "Rollback failed")
- raise excType, excValue, excTraceback
+ raise excType(excValue, excTraceback)
def finalClose(self):
"""
diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py
index c8c3ce30..3b17f188 100644
--- a/client/src/leap/soledad/client/api.py
+++ b/client/src/leap/soledad/client/api.py
@@ -27,20 +27,19 @@ remote storage in the server side.
"""
import binascii
import errno
-import httplib
import os
import socket
import ssl
import uuid
-import urlparse
from itertools import chain
-
-from StringIO import StringIO
+import six.moves.http_client as httplib
+import six.moves.urllib.parse as urlparse
+from six import StringIO
from collections import defaultdict
from twisted.internet import defer
-from zope.interface import implements
+from zope.interface import implementer
from leap.common.config import get_path_prefix
from leap.common.plugins import collect_plugins
@@ -79,6 +78,9 @@ Soledad client and server.
SOLEDAD_CERT = None
+@implementer(soledad_interfaces.ILocalStorage,
+ soledad_interfaces.ISyncableStorage,
+ soledad_interfaces.ISecretsStorage)
class Soledad(object):
"""
Soledad provides encrypted data storage and sync.
@@ -111,9 +113,6 @@ class Soledad(object):
there's indeed new data to be synchronized between local database
replica and server's replica. --- not used right now.
"""
- implements(soledad_interfaces.ILocalStorage,
- soledad_interfaces.ISyncableStorage,
- soledad_interfaces.ISecretsStorage)
local_db_file_name = 'soledad.u1db'
secrets_file_name = "soledad.json"
diff --git a/client/src/leap/soledad/client/http_target/api.py b/client/src/leap/soledad/client/http_target/api.py
index fc65c9bd..c68185c6 100644
--- a/client/src/leap/soledad/client/http_target/api.py
+++ b/client/src/leap/soledad/client/http_target/api.py
@@ -18,7 +18,7 @@ import os
import json
import base64
-from StringIO import StringIO
+from six import StringIO
from uuid import uuid4
from twisted.internet import defer
diff --git a/client/src/leap/soledad/client/http_target/fetch_protocol.py b/client/src/leap/soledad/client/http_target/fetch_protocol.py
index c7eabe2b..851eb3a1 100644
--- a/client/src/leap/soledad/client/http_target/fetch_protocol.py
+++ b/client/src/leap/soledad/client/http_target/fetch_protocol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
from functools import partial
-from cStringIO import StringIO
+from six import StringIO
from twisted.web._newclient import ResponseDone
from leap.soledad.common.l2db import errors
from leap.soledad.common.l2db.remote import utils
@@ -70,7 +70,7 @@ class DocStreamReceiver(ReadBodyProtocol):
self.dataBuffer = self.metadata
else:
self.dataBuffer = self.finish()
- except errors.BrokenSyncStream, e:
+ except errors.BrokenSyncStream as e:
return self.deferred.errback(e)
return ReadBodyProtocol.connectionLost(self, reason)
diff --git a/client/src/leap/soledad/client/http_target/send_protocol.py b/client/src/leap/soledad/client/http_target/send_protocol.py
index 0cb6d039..4941aa34 100644
--- a/client/src/leap/soledad/client/http_target/send_protocol.py
+++ b/client/src/leap/soledad/client/http_target/send_protocol.py
@@ -14,20 +14,19 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from zope.interface import implements
+from zope.interface import implementer
from twisted.internet import defer
from twisted.internet import reactor
from twisted.web.iweb import IBodyProducer
from twisted.web.iweb import UNKNOWN_LENGTH
+@implementer(IBodyProducer)
class DocStreamProducer(object):
"""
A producer that writes the body of a request to a consumer.
"""
- implements(IBodyProducer)
-
def __init__(self, producer):
"""
Initialize the string produer.
diff --git a/client/src/leap/soledad/client/sqlcipher.py b/client/src/leap/soledad/client/sqlcipher.py
index a3e45228..2c995d5a 100644
--- a/client/src/leap/soledad/client/sqlcipher.py
+++ b/client/src/leap/soledad/client/sqlcipher.py
@@ -42,11 +42,10 @@ SQLCipher 1.1 databases, we do not implement them as all SQLCipher databases
handled by Soledad should be created by SQLCipher >= 2.0.
"""
import os
+import sys
from functools import partial
-from pysqlcipher import dbapi2 as sqlcipher_dbapi2
-
from twisted.internet import reactor
from twisted.internet import defer
from twisted.enterprise import adbapi
@@ -62,6 +61,10 @@ from leap.soledad.client.http_target import SoledadHTTPSyncTarget
from leap.soledad.client.sync import SoledadSynchronizer
from leap.soledad.client import pragmas
+if sys.version_info[0] < 3:
+ from pysqlcipher import dbapi2 as sqlcipher_dbapi2
+else:
+ from pysqlcipher3 import dbapi2 as sqlcipher_dbapi2
logger = getLogger(__name__)
@@ -306,7 +309,7 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase):
))
try:
c.execute(statement, tuple(args))
- except sqlcipher_dbapi2.OperationalError, e:
+ except sqlcipher_dbapi2.OperationalError as e:
raise sqlcipher_dbapi2.OperationalError(
str(e) + '\nstatement: %s\nargs: %s\n' % (statement, args))
res = c.fetchall()