Skip to content

Commit d873afc

Browse files
author
Joohwan Oh
committed
Add python3 compatibility
1 parent 0de70b0 commit d873afc

File tree

12 files changed

+185
-168
lines changed

12 files changed

+185
-168
lines changed

arango/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ def remove_database(self, name):
167167

168168
if __name__ == "__main__":
169169
a = Arango()
170-
print a.version
170+
print(a.version)

arango/api.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44

55
from arango.clients.default import DefaultArangoClient
6+
from arango.utils import is_string
67

78

89
class ArangoAPI(object):
@@ -44,13 +45,13 @@ def url_prefix(self):
4445
:rtype: str
4546
"""
4647
return "{protocol}://{host}:{port}/_db/{db}".format(
47-
protocol = self.protocol,
48-
host = self.host,
49-
port = self.port,
50-
db = self.db_name,
48+
protocol=self.protocol,
49+
host=self.host,
50+
port=self.port,
51+
db=self.db_name,
5152
)
5253

53-
def head(self, path, params=None, headers=None, batch=False):
54+
def head(self, path, params=None, headers=None):
5455
"""Execute an HTTP HEAD method."""
5556
return self.client.head(
5657
url=self.url_prefix + path,
@@ -59,7 +60,7 @@ def head(self, path, params=None, headers=None, batch=False):
5960
auth=(self.username, self.password)
6061
)
6162

62-
def get(self, path, params=None, headers=None, batch=False):
63+
def get(self, path, params=None, headers=None):
6364
"""Execute an HTTP GET method."""
6465
return self.client.get(
6566
url=self.url_prefix + path,
@@ -68,37 +69,37 @@ def get(self, path, params=None, headers=None, batch=False):
6869
auth=(self.username, self.password),
6970
)
7071

71-
def put(self, path, data=None, params=None, headers=None, batch=False):
72+
def put(self, path, data=None, params=None, headers=None):
7273
"""Execute an HTTP PUT method."""
7374
return self.client.put(
7475
url=self.url_prefix + path,
75-
data=data if isinstance(data, basestring) else json.dumps(data),
76+
data=data if is_string(data) else json.dumps(data),
7677
params=params,
7778
headers=headers,
7879
auth=(self.username, self.password)
7980
)
8081

81-
def post(self, path, data=None, params=None, headers=None, batch=False):
82+
def post(self, path, data=None, params=None, headers=None):
8283
"""Execute an HTTP POST method."""
8384
return self.client.post(
8485
url=self.url_prefix + path,
85-
data=data if isinstance(data, basestring) else json.dumps(data),
86+
data=data if is_string(data) else json.dumps(data),
8687
params=params,
8788
headers=headers,
8889
auth=(self.username, self.password)
8990
)
9091

91-
def patch(self, path, data=None, params=None, headers=None, batch=False):
92+
def patch(self, path, data=None, params=None, headers=None):
9293
"""Execute an HTTP PATCH method."""
9394
return self.client.patch(
9495
url=self.url_prefix + path,
95-
data=data if isinstance(data, basestring) else json.dumps(data),
96+
data=data if is_string(data) else json.dumps(data),
9697
params=params,
9798
headers=headers,
9899
auth=(self.username, self.password)
99100
)
100101

101-
def delete(self, path, params=None, headers=None, batch=False):
102+
def delete(self, path, params=None, headers=None):
102103
"""Execute an HTTP DELETE method."""
103104
return self.client.delete(
104105
url=self.url_prefix + path,

arango/batch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
22
import inspect
3-
from urllib import urlencode
4-
3+
try:
4+
from urllib import urlencode
5+
except ImportError:
6+
from urllib.parse import urlencode
57
from arango.exceptions import (
68
BatchInvalidError,
79
BatchExecuteError
@@ -53,7 +55,7 @@ def stringify_request(method, path, params=None, headers=None, data=None):
5355
path = path + "?" + urlencode(params) if params else path
5456
request_string = "{} {} HTTP/1.1".format(method, path)
5557
if headers:
56-
for key, value in headers.iteritems():
58+
for key, value in headers.items():
5759
request_string += "\r\n{key}: {value}".format(
5860
key=key, value=value
5961
)

arango/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class DatabaseRemoveError(ArangoRequestError):
6666
# Collections #
6767
###############
6868

69+
6970
class CollectionCorruptedError(Exception):
7071
"""The collection is corrupted (unknown status)."""
7172

@@ -125,6 +126,7 @@ class CollectionBulkImportError(ArangoRequestError):
125126
# Documents #
126127
#############
127128

129+
128130
class DocumentInvalidError(Exception):
129131
"""The document is invalid."""
130132

@@ -229,6 +231,7 @@ class IndexRemoveError(ArangoRequestError):
229231
# Queries #
230232
###########
231233

234+
232235
class QueryExplainError(ArangoRequestError):
233236
"""Failed to explain the query."""
234237

@@ -260,6 +263,7 @@ class AQLFunctionRemoveError(ArangoRequestError):
260263
# Simple Queries #
261264
##################
262265

266+
263267
class SimpleQueryGetByExampleError(ArangoRequestError):
264268
"""Failed to execute the ``by-example`` simple query."""
265269

@@ -319,13 +323,15 @@ class SimpleQueryError(ArangoRequestError):
319323
# Transactions #
320324
################
321325

326+
322327
class TransactionExecuteError(ArangoRequestError):
323328
"""Failed to execute a transaction."""
324329

325330
###########
326331
# Batches #
327332
###########
328333

334+
329335
class BatchInvalidError(Exception):
330336
"""The Batch request is malformed."""
331337

@@ -337,6 +343,7 @@ class BatchExecuteError(ArangoRequestError):
337343
# Graphs #
338344
##########
339345

346+
340347
class GraphNotFoundError(ArangoNotFoundError):
341348
"""Failed to find the graph."""
342349

@@ -368,6 +375,7 @@ class GraphTraversalError(ArangoRequestError):
368375
# Vertex Collections #
369376
######################
370377

378+
371379
class VertexCollectionListError(ArangoRequestError):
372380
"""Failed to list the vertex collections."""
373381

@@ -383,6 +391,7 @@ class VertexCollectionRemoveError(ArangoRequestError):
383391
# Edge Collections/Definitions #
384392
################################
385393

394+
386395
class EdgeDefinitionListError(ArangoRequestError):
387396
"""Failed to list the edge collections."""
388397

arango/graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def remove_vertex(self, vertex_id, rev=None, wait_for_sync=False,
372372
:raises: RevisionMismatchError, VertexRemoveError
373373
"""
374374
path = "/_api/gharial/{}/vertex/{}".format(self.name, vertex_id)
375-
params={"waitForSync": wait_for_sync}
375+
params = {"waitForSync": wait_for_sync}
376376
if rev is not None:
377377
params["rev"] = rev
378378
if _batch:
@@ -584,8 +584,8 @@ def remove_edge(self, edge_id, rev=None, wait_for_sync=False,
584584

585585
def execute_traversal(self, start_vertex, direction=None,
586586
strategy=None, order=None, item_order=None, uniqueness=None,
587-
max_iterations=None, min_depth=None, max_depth=None,
588-
init=None, filters=None, visitor=None, expander=None, sort=None):
587+
max_iterations=None, min_depth=None, max_depth=None, init=None,
588+
filters=None, visitor=None, expander=None, sort=None):
589589
"""Execute a graph traversal and return the visited vertices.
590590
591591
For more details on ``init``, ``filter``, ``visitor``, ``expander``

arango/tests/test_aql_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ def test_remove_aql_functions_by_group(self):
6565

6666

6767
if __name__ == "__main__":
68-
unittest.main()
68+
unittest.main()

arango/tests/test_collection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from arango import Arango
66
from arango.exceptions import *
7+
from arango.utils import is_string
78
from arango.tests.utils import (
89
get_next_col_name,
910
get_next_db_name
1011
)
1112

13+
1214
class CollectionManagementTest(unittest.TestCase):
1315

1416
def setUp(self):
@@ -84,7 +86,7 @@ def test_collection_add_with_config(self):
8486
self.assertFalse(col.do_compact)
8587
self.assertTrue(col.wait_for_sync)
8688
self.assertTrue(col.is_edge)
87-
self.assertTrue(isinstance(col.id, basestring))
89+
self.assertTrue(is_string(col.id))
8890
self.assertTrue(isinstance(col.figures, dict))
8991

9092
def test_collection_setters(self):
@@ -117,4 +119,3 @@ def test_collection_rotate_journal(self):
117119

118120
if __name__ == "__main__":
119121
unittest.main()
120-

arango/tests/test_database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"""Tests for ArangoDB Databases."""
22

33
import unittest
4+
45
from arango import Arango
6+
from arango.utils import is_string
57
from arango.tests.utils import (
68
get_next_db_name
79
)
810

11+
912
class DatabaseManagementTest(unittest.TestCase):
1013

1114
def setUp(self):
1215
self.arango = Arango()
1316

14-
def tearDown(self):
15-
self.arango = None
16-
1717
def test_database_add_and_remove(self):
1818
db_name = get_next_db_name(self.arango)
1919
self.arango.add_database(db_name)
@@ -31,8 +31,8 @@ def test_database_properties(self):
3131
db = self.arango.database("_system")
3232
self.assertEqual(db.name, "_system")
3333
self.assertTrue(isinstance(db.properties, dict))
34-
self.assertTrue(isinstance(db.id, basestring))
35-
self.assertTrue(isinstance(db.path, basestring))
34+
self.assertTrue(is_string(db.id))
35+
self.assertTrue(is_string(db.path))
3636
self.assertEqual(db.is_system, True)
3737

3838

arango/tests/test_document.py

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,9 @@ def test_last(self):
149149
strip_system_keys(self.col.last(1)),
150150
[{"name": "test_doc_03"}]
151151
)
152-
self.assertEqual(
153-
sorted(strip_system_keys(self.col.last(2))),
154-
sorted([{"name": "test_doc_03"}, {"name": "test_doc_02"}])
155-
)
152+
docs = strip_system_keys(self.col.last(2))
153+
self.assertIn({"name": "test_doc_03"}, docs)
154+
self.assertIn({"name": "test_doc_02"}, docs)
156155

157156
def test_all(self):
158157
self.assertEqual(list(self.col.all()), [])
@@ -162,14 +161,11 @@ def test_all(self):
162161
{"name": "test_doc_03"}
163162
])
164163
self.assertEqual(len(self.col), 3)
165-
self.assertEqual(
166-
sorted(strip_system_keys(self.col.all())),
167-
sorted([
168-
{"name": "test_doc_01"},
169-
{"name": "test_doc_02"},
170-
{"name": "test_doc_03"}
171-
])
172-
)
164+
165+
docs = strip_system_keys(self.col.all())
166+
self.assertIn({"name": "test_doc_01"}, docs)
167+
self.assertIn({"name": "test_doc_02"}, docs)
168+
self.assertIn({"name": "test_doc_03"}, docs)
173169

174170
def test_any(self):
175171
self.assertEqual(strip_system_keys(self.col.all()), [])
@@ -210,13 +206,9 @@ def test_get_by_example(self):
210206
{"name": "test_doc_02", "value": 1},
211207
{"name": "test_doc_03", "value": 3}
212208
])
213-
self.assertEqual(
214-
sorted(strip_system_keys(self.col.get_by_example({"value": 1}))),
215-
sorted([
216-
{"name": "test_doc_01", "value": 1},
217-
{"name": "test_doc_02", "value": 1},
218-
])
219-
)
209+
docs = strip_system_keys(self.col.get_by_example({"value": 1}))
210+
self.assertIn({"name": "test_doc_01", "value": 1}, docs)
211+
self.assertIn({"name": "test_doc_02", "value": 1}, docs)
220212
self.assertEqual(
221213
strip_system_keys(self.col.get_by_example({"value": 2})), []
222214
)
@@ -231,14 +223,10 @@ def test_update_by_example(self):
231223
{"name": "test_doc_03", "value": 3}
232224
])
233225
self.col.update_by_example({"value": 1}, {"value": 2})
234-
self.assertEqual(
235-
sorted(strip_system_keys(self.col.all())),
236-
sorted([
237-
{"name": "test_doc_01", "value": 2},
238-
{"name": "test_doc_02", "value": 2},
239-
{"name": "test_doc_03", "value": 3}
240-
])
241-
)
226+
docs = strip_system_keys(self.col.all())
227+
self.assertIn({"name": "test_doc_01", "value": 2}, docs)
228+
self.assertIn({"name": "test_doc_02", "value": 2}, docs)
229+
self.assertIn({"name": "test_doc_03", "value": 3}, docs)
242230

243231
def test_replace_by_example(self):
244232
self.col.bulk_import([
@@ -247,14 +235,10 @@ def test_replace_by_example(self):
247235
{"name": "test_doc_03", "value": 3}
248236
])
249237
self.col.replace_by_example({"value": 1}, {"foo": "bar"})
250-
self.assertEqual(
251-
sorted(strip_system_keys(self.col.all())),
252-
sorted([
253-
{"foo": "bar"},
254-
{"foo": "bar"},
255-
{"name": "test_doc_03", "value": 3}
256-
])
257-
)
238+
239+
docs = strip_system_keys(self.col.all())
240+
self.assertIn({"foo": "bar"}, docs)
241+
self.assertIn({"name": "test_doc_03", "value": 3}, docs)
258242

259243
def test_remove_by_example(self):
260244
self.col.bulk_import([

0 commit comments

Comments
 (0)