summaryrefslogtreecommitdiff
path: root/common/src/leap
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 /common/src/leap
parentba3fcb08eafd389bdbf0ab9c59577a25c8d8126d (diff)
[refactor] Improve python3 compatibility
With this commit all tests on py34 tox environment are collected.
Diffstat (limited to 'common/src/leap')
-rw-r--r--common/src/leap/soledad/common/command.py2
-rw-r--r--common/src/leap/soledad/common/couch/__init__.py5
-rw-r--r--common/src/leap/soledad/common/couch/state.py3
-rw-r--r--common/src/leap/soledad/common/l2db/backends/sqlite_backend.py13
-rw-r--r--common/src/leap/soledad/common/l2db/query_parser.py2
-rw-r--r--common/src/leap/soledad/common/l2db/remote/http_app.py6
-rw-r--r--common/src/leap/soledad/common/l2db/remote/http_client.py7
-rw-r--r--common/src/leap/soledad/common/l2db/remote/http_database.py2
-rw-r--r--common/src/leap/soledad/common/l2db/sync.py2
9 files changed, 22 insertions, 20 deletions
diff --git a/common/src/leap/soledad/common/command.py b/common/src/leap/soledad/common/command.py
index 811bf135..66aa6b7a 100644
--- a/common/src/leap/soledad/common/command.py
+++ b/common/src/leap/soledad/common/command.py
@@ -45,7 +45,7 @@ def exec_validated_cmd(cmd, argument, validator=None):
try:
process = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- except OSError, e:
+ except OSError as e:
return 1, e
(out, err) = process.communicate()
code = process.wait()
diff --git a/common/src/leap/soledad/common/couch/__init__.py b/common/src/leap/soledad/common/couch/__init__.py
index 2e6f734e..2343e849 100644
--- a/common/src/leap/soledad/common/couch/__init__.py
+++ b/common/src/leap/soledad/common/couch/__init__.py
@@ -25,9 +25,8 @@ import re
import uuid
import binascii
-
-from StringIO import StringIO
-from urlparse import urljoin
+from six import StringIO
+from six.moves.urllib.parse import urljoin
from contextlib import contextmanager
diff --git a/common/src/leap/soledad/common/couch/state.py b/common/src/leap/soledad/common/couch/state.py
index a4841d0d..8cbe0934 100644
--- a/common/src/leap/soledad/common/couch/state.py
+++ b/common/src/leap/soledad/common/couch/state.py
@@ -19,7 +19,8 @@ Server state using CouchDatabase as backend.
"""
import couchdb
import re
-from urlparse import urljoin
+
+from six.moves.urllib.parse import urljoin
from leap.soledad.common.log import getLogger
from leap.soledad.common.couch import CouchDatabase
diff --git a/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py b/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py
index 27db65af..4f7b1259 100644
--- a/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py
+++ b/common/src/leap/soledad/common/l2db/backends/sqlite_backend.py
@@ -58,7 +58,7 @@ class SQLiteDatabase(CommonBackend):
try:
c.execute("SELECT value FROM u1db_config"
" WHERE name = 'index_storage'")
- except dbapi2.OperationalError, e:
+ except dbapi2.OperationalError as e:
# The table does not exist yet
return None, e
else:
@@ -668,7 +668,7 @@ class SQLiteDatabase(CommonBackend):
c = self._db_handle.cursor()
try:
c.execute(statement, tuple(args))
- except dbapi2.OperationalError, e:
+ except dbapi2.OperationalError as e:
raise dbapi2.OperationalError(
str(e) +
'\nstatement: %s\nargs: %s\n' % (statement, args))
@@ -768,7 +768,7 @@ class SQLiteDatabase(CommonBackend):
c = self._db_handle.cursor()
try:
c.execute(statement, tuple(args))
- except dbapi2.OperationalError, e:
+ except dbapi2.OperationalError as e:
raise dbapi2.OperationalError(
str(e) +
'\nstatement: %s\nargs: %s\n' % (statement, args))
@@ -798,7 +798,7 @@ class SQLiteDatabase(CommonBackend):
value_fields))
try:
c.execute(statement, tuple(definition))
- except dbapi2.OperationalError, e:
+ except dbapi2.OperationalError as e:
raise dbapi2.OperationalError(
str(e) +
'\nstatement: %s\nargs: %s\n' % (statement, tuple(definition)))
@@ -893,7 +893,10 @@ class SQLitePartialExpandDatabase(SQLiteDatabase):
stored_def = self._get_index_definition(index_name)
if stored_def == [x[-1] for x in definition]:
return
- raise errors.IndexNameTakenError, e, sys.exc_info()[2]
+ raise errors.IndexNameTakenError(
+ str(e) +
+ str(sys.exc_info()[2])
+ )
new_fields = set(
[f for f in index_expressions if f not in cur_fields])
if new_fields:
diff --git a/common/src/leap/soledad/common/l2db/query_parser.py b/common/src/leap/soledad/common/l2db/query_parser.py
index dd35b12a..15a9ac80 100644
--- a/common/src/leap/soledad/common/l2db/query_parser.py
+++ b/common/src/leap/soledad/common/l2db/query_parser.py
@@ -323,7 +323,7 @@ class Parser(object):
else:
try:
inner = arg_type(arg)
- except ValueError, e:
+ except ValueError as e:
raise errors.IndexDefinitionParseError(
"Invalid value %r for argument type %r "
"(%r)." % (arg, arg_type, e))
diff --git a/common/src/leap/soledad/common/l2db/remote/http_app.py b/common/src/leap/soledad/common/l2db/remote/http_app.py
index 496274b2..a4eddb36 100644
--- a/common/src/leap/soledad/common/l2db/remote/http_app.py
+++ b/common/src/leap/soledad/common/l2db/remote/http_app.py
@@ -21,11 +21,11 @@ HTTP Application exposing U1DB.
# TODO -- deprecate, use twisted/txaio.
import functools
-import httplib
+import six.moves.http_client as httplib
import inspect
import json
import sys
-import urlparse
+import six.moves.urllib.parse as urlparse
import routes.mapper
@@ -610,7 +610,7 @@ class HTTPApp(object):
try:
resource = self._lookup_resource(environ, responder)
HTTPInvocationByMethodWithBody(resource, environ, self)()
- except errors.U1DBError, e:
+ except errors.U1DBError as e:
self.request_u1db_error(environ, e)
status = http_errors.wire_description_to_status.get(
e.wire_description, 500)
diff --git a/common/src/leap/soledad/common/l2db/remote/http_client.py b/common/src/leap/soledad/common/l2db/remote/http_client.py
index 53363c0a..1124b038 100644
--- a/common/src/leap/soledad/common/l2db/remote/http_client.py
+++ b/common/src/leap/soledad/common/l2db/remote/http_client.py
@@ -16,14 +16,13 @@
"""Base class to make requests to a remote HTTP server."""
-import httplib
import json
import socket
import ssl
import sys
-import urlparse
import urllib
-
+import six.moves.urllib.parse as urlparse
+import six.moves.http_client as httplib
from time import sleep
from leap.soledad.common.l2db import errors
from leap.soledad.common.l2db.remote import http_errors
@@ -168,7 +167,7 @@ class HTTPClientBase(object):
try:
self._conn.request(method, url_query, body, headers)
return self._response()
- except errors.Unavailable, e:
+ except errors.Unavailable as e:
sleep(delay)
raise e
diff --git a/common/src/leap/soledad/common/l2db/remote/http_database.py b/common/src/leap/soledad/common/l2db/remote/http_database.py
index 7512379f..7e61e5a4 100644
--- a/common/src/leap/soledad/common/l2db/remote/http_database.py
+++ b/common/src/leap/soledad/common/l2db/remote/http_database.py
@@ -87,7 +87,7 @@ class HTTPDatabase(http_client.HTTPClientBase, Database):
'GET', ['doc', doc_id], {"include_deleted": include_deleted})
except errors.DocumentDoesNotExist:
return None
- except errors.HTTPError, e:
+ except errors.HTTPError as e:
if (e.status == DOCUMENT_DELETED_STATUS and
'x-u1db-rev' in e.headers):
res = None
diff --git a/common/src/leap/soledad/common/l2db/sync.py b/common/src/leap/soledad/common/l2db/sync.py
index 5e9b22f4..32281f30 100644
--- a/common/src/leap/soledad/common/l2db/sync.py
+++ b/common/src/leap/soledad/common/l2db/sync.py
@@ -15,7 +15,7 @@
# along with u1db. If not, see <http://www.gnu.org/licenses/>.
"""The synchronization utilities for U1DB."""
-from itertools import izip
+from six.moves import zip as izip
from leap.soledad.common import l2db
from leap.soledad.common.l2db import errors