Skip to content

Commit b849941

Browse files
committed
Merge branch 'dev'
2 parents 0a0ff7c + 172a039 commit b849941

File tree

9 files changed

+56
-29
lines changed

9 files changed

+56
-29
lines changed

pyArango/collection.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from . import consts as CONST
55

66
from .document import Document, Edge
7-
from .theExceptions import ValidationError, SchemaViolation, CreationError, UpdateError, DeletionError, InvalidDocument
7+
from .theExceptions import ValidationError, SchemaViolation, CreationError, UpdateError, DeletionError, InvalidDocument, ExportError
88
from .query import SimpleQuery
99
from .index import Index
1010

@@ -306,7 +306,7 @@ def createDocument_(self, initDict = None) :
306306

307307
def importBulk(self, data, **addParams):
308308
url = "%s/import" % (self.database.URL)
309-
payload = json.dumps(data)
309+
payload = json.dumps(data, default=str)
310310
params = {"collection": self.name, "type": "auto"}
311311
params.update(addParams)
312312
r = self.connection.session.post(url , params = params, data = payload)
@@ -315,6 +315,17 @@ def importBulk(self, data, **addParams):
315315
raise CreationError(data["errorMessage"], data)
316316
return data
317317

318+
def exportDocs( self, **data):
319+
url = "%s/export" % (self.database.URL)
320+
params = {"collection": self.name}
321+
payload = json.dumps(data)
322+
r = self.connection.session.post(url, params = params, data = payload)
323+
data = r.json()
324+
if not r.status_code == 201 or data["error"] :
325+
raise ExportError( data["errorMessage"], data )
326+
docs = data['result']
327+
return docs
328+
318329
def ensureHashIndex(self, fields, unique = False, sparse = True, deduplicate = False) :
319330
"""Creates a hash index if it does not already exist, and returns it"""
320331
data = {
@@ -485,12 +496,12 @@ def bulkSave(self, docs, onDuplicate="error", **params) :
485496
payload = []
486497
for d in docs :
487498
if type(d) is dict :
488-
payload.append(json.dumps(d))
499+
payload.append(json.dumps(d, default=str))
489500
else :
490501
try:
491502
payload.append(d.toJson())
492503
except Exception as e:
493-
payload.append(json.dumps(d.getStore()))
504+
payload.append(json.dumps(d.getStore(), default=str))
494505

495506
payload = '\n'.join(payload)
496507

pyArango/connection.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ class AikidoSession(object) :
2727
"""
2828

2929
class Holder(object) :
30-
def __init__(self, fct, auth) :
30+
def __init__(self, fct, auth, verify=True) :
3131
self.fct = fct
3232
self.auth = auth
33+
if verify != None:
34+
self.verify = verify
3335

3436
def __call__(self, *args, **kwargs) :
3537
if self.auth :
3638
kwargs["auth"] = self.auth
39+
if self.verify != True:
40+
kwargs["verify"] = self.verify
3741

3842
try :
3943
ret = self.fct(*args, **kwargs)
@@ -49,12 +53,13 @@ def __call__(self, *args, **kwargs) :
4953
ret.json = JsonHook(ret)
5054
return ret
5155

52-
def __init__(self, username, password) :
56+
def __init__(self, username, password, verify=True) :
5357
if username :
5458
self.auth = (username, password)
5559
else :
5660
self.auth = None
5761

62+
self.verify = verify
5863
self.session = requests.Session()
5964
self.log = {}
6065
self.log["nb_request"] = 0
@@ -68,14 +73,15 @@ def __getattr__(self, k) :
6873

6974
holdClass = object.__getattribute__(self, "Holder")
7075
auth = object.__getattribute__(self, "auth")
76+
verify = object.__getattribute__(self, "verify")
7177
log = object.__getattribute__(self, "log")
7278
log["nb_request"] += 1
7379
try :
7480
log["requests"][reqFct.__name__] += 1
7581
except :
7682
log["requests"][reqFct.__name__] = 1
7783

78-
return holdClass(reqFct, auth)
84+
return holdClass(reqFct, auth, verify)
7985

8086
def disconnect(self) :
8187
try:
@@ -85,7 +91,7 @@ def disconnect(self) :
8591

8692
class Connection(object) :
8793
"""This is the entry point in pyArango and directly handles databases."""
88-
def __init__(self, arangoURL = 'http://127.0.0.1:8529', username = None, password = None, verbose = False, statsdClient = None, reportFileName = None) :
94+
def __init__(self, arangoURL = 'http://127.0.0.1:8529', username = None, password = None, verify = True, verbose = False, statsdClient = None, reportFileName = None) :
8995
self.databases = {}
9096
self.verbose = verbose
9197
if arangoURL[-1] == "/" :
@@ -98,7 +104,7 @@ def __init__(self, arangoURL = 'http://127.0.0.1:8529', username = None, passwor
98104
self.identifier = None
99105
self.startTime = None
100106
self.session = None
101-
self.resetSession(username, password)
107+
self.resetSession(username, password, verify)
102108

103109
self.URL = '%s/_api' % self.arangoURL
104110
if not self.session.auth :
@@ -120,10 +126,10 @@ def disconnectSession(self) :
120126
if self.session:
121127
self.session.disconnect()
122128

123-
def resetSession(self, username=None, password=None) :
129+
def resetSession(self, username=None, password=None, verify=True) :
124130
"""resets the session"""
125131
self.disconnectSession()
126-
self.session = AikidoSession(username, password)
132+
self.session = AikidoSession(username, password, verify)
127133

128134
def reload(self) :
129135
"""Reloads the database list.
@@ -145,7 +151,7 @@ def reload(self) :
145151
def createDatabase(self, name, **dbArgs) :
146152
"use dbArgs for arguments other than name. for a full list of arguments please have a look at arangoDB's doc"
147153
dbArgs['name'] = name
148-
payload = json.dumps(dbArgs)
154+
payload = json.dumps(dbArgs, default=str)
149155
url = self.URL + "/database"
150156
r = self.session.post(url, data = payload)
151157
data = r.json()

pyArango/database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def createCollection(self, className = 'Collection', **colProperties) :
110110
else :
111111
colProperties["type"] = CONST.COLLECTION_DOCUMENT_TYPE
112112

113-
payload = json.dumps(colProperties)
113+
payload = json.dumps(colProperties, default=str)
114114
r = self.connection.session.post(self.collectionsURL, data = payload)
115115
data = r.json()
116116

@@ -155,7 +155,7 @@ def _checkCollectionList(lst) :
155155
"orphanCollections": graphClass._orphanedCollections
156156
}
157157

158-
payload = json.dumps(payload)
158+
payload = json.dumps(payload, default=str)
159159
r = self.connection.session.post(self.graphsURL, data = payload)
160160
data = r.json()
161161

@@ -193,13 +193,13 @@ def AQLQuery(self, query, batchSize = 100, rawResults = False, bindVars = {}, op
193193
def explainAQLQuery(self, query, bindVars={}, allPlans = False) :
194194
"""Returns an explanation of the query. Setting allPlans to True will result in ArangoDB returning all possible plans. False returns only the optimal plan"""
195195
payload = {'query' : query, 'bindVars' : bindVars, 'allPlans' : allPlans}
196-
request = self.connection.session.post(self.explainURL, data = json.dumps(payload))
196+
request = self.connection.session.post(self.explainURL, data = json.dumps(payload, default=str))
197197
return request.json()
198198

199199
def validateAQLQuery(self, query, bindVars = {}, options = {}) :
200200
"returns the server answer is the query is valid. Raises an AQLQueryError if not"
201201
payload = {'query' : query, 'bindVars' : bindVars, 'options' : options}
202-
r = self.connection.session.post(self.cursorsURL, data = json.dumps(payload))
202+
r = self.connection.session.post(self.cursorsURL, data = json.dumps(payload, default=str))
203203
data = r.json()
204204
if r.status_code == 201 and not data["error"] :
205205
return data
@@ -219,7 +219,7 @@ def transaction(self, collections, action, waitForSync = False, lockTimeout = No
219219

220220
self.connection.reportStart(action)
221221

222-
r = self.connection.session.post(self.transactionURL, data = json.dumps(payload))
222+
r = self.connection.session.post(self.transactionURL, data = json.dumps(payload, default=str))
223223

224224
self.connection.reportItem()
225225

pyArango/document.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ def _save(self, payload, waitForSync = False, **docArgs) :
243243
if self.URL is None :
244244
if self._key is not None :
245245
payload["_key"] = self._key
246-
payload = json.dumps(payload)
246+
payload = json.dumps(payload, default=str)
247247
r = self.connection.session.post(self.documentsURL, params = params, data = payload)
248248
update = False
249249
data = r.json()
250250
self.setPrivates(data)
251251
else :
252-
payload = json.dumps(payload)
252+
payload = json.dumps(payload, default=str)
253253
r = self.connection.session.put(self.URL, params = params, data = payload)
254254
update = True
255255
data = r.json()
@@ -298,7 +298,7 @@ def patch(self, keepNull = True, **docArgs) :
298298
if len(payload) > 0 :
299299
params = dict(docArgs)
300300
params.update({'collection': self.collection.name, 'keepNull' : keepNull})
301-
payload = json.dumps(payload)
301+
payload = json.dumps(payload, default=str)
302302

303303
r = self.connection.session.patch(self.URL, params = params, data = payload)
304304
data = r.json()
@@ -342,7 +342,12 @@ def getEdges(self, edges, inEdges = True, outEdges = True, rawResults = False) :
342342

343343
def getStore(self) :
344344
"""return the store in a dict format"""
345-
return self._store.getStore()
345+
store = self._store.getStore()
346+
for priv in self.privates :
347+
v = getattr(self, priv)
348+
if v :
349+
store[priv] = v
350+
return store
346351

347352
def getPatches(self) :
348353
"""return the patches in a dict format"""

pyArango/graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def createVertex(self, collectionName, docAttributes, waitForSync = False) :
120120
# self.database[collectionName].validateDct(docAttributes)
121121
store.validate()
122122

123-
r = self.connection.session.post(url, data = json.dumps(docAttributes), params = {'waitForSync' : waitForSync})
123+
r = self.connection.session.post(url, data = json.dumps(docAttributes, default=str), params = {'waitForSync' : waitForSync})
124124

125125
data = r.json()
126126
if r.status_code == 201 or r.status_code == 202 :
@@ -162,7 +162,7 @@ def createEdge(self, collectionName, _fromId, _toId, edgeAttributes, waitForSync
162162
payload = ed.getStore()
163163
payload.update({'_from' : _fromId, '_to' : _toId})
164164

165-
r = self.connection.session.post(url, data = json.dumps(payload), params = {'waitForSync' : waitForSync})
165+
r = self.connection.session.post(url, data = json.dumps(payload, default=str), params = {'waitForSync' : waitForSync})
166166
data = r.json()
167167
if r.status_code == 201 or r.status_code == 202 :
168168
return self.database[collectionName][data["edge"]["_key"]]
@@ -229,7 +229,7 @@ def traverse(self, startVertex, **kwargs) :
229229

230230
payload.update(kwargs)
231231

232-
r = self.connection.session.post(url, data = json.dumps(payload))
232+
r = self.connection.session.post(url, data = json.dumps(payload, default=str))
233233
data = r.json()
234234
if r.status_code < 200 or r.status_code > 202 or data["error"] :
235235
raise TraversalError(data["errorMessage"], data)

pyArango/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, collection, infos = None, creationData = None) :
2222
def _create(self, postData) :
2323
"""Creates an index of any type according to postData"""
2424
if self.infos is None :
25-
r = self.connection.session.post(self.indexesURL, params = {"collection" : self.collection.name}, data = json.dumps(postData))
25+
r = self.connection.session.post(self.indexesURL, params = {"collection" : self.collection.name}, data = json.dumps(postData, default=str))
2626
data = r.json()
2727
if (r.status_code >= 400) or data['error'] :
2828
raise CreationError(data['errorMessage'], data)

pyArango/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(self, database, query, batchSize, bindVars, options, count, fullCou
142142
self.database = database
143143
self.connection = self.database.connection
144144
self.connection.reportStart(query)
145-
request = self.connection.session.post(database.cursorsURL, data = json.dumps(payload, cls=json_encoder))
145+
request = self.connection.session.post(database.cursorsURL, data = json.dumps(payload, cls=json_encoder, default=str))
146146
self.connection.reportItem()
147147

148148
try :
@@ -182,7 +182,7 @@ def __init__(self, collection, queryType, rawResults, json_encoder = None,
182182

183183
payload = {'collection' : collection.name}
184184
payload.update(queryArgs)
185-
payload = json.dumps(payload, cls=json_encoder)
185+
payload = json.dumps(payload, cls=json_encoder, default=str)
186186
URL = "%s/simple/%s" % (collection.database.URL, queryType)
187187
request = self.connection.session.put(URL, data = payload)
188188

pyArango/theExceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ def __init__(self, cls) :
105105

106106
def __str__(self) :
107107
return self.message
108+
109+
class ExportError(pyArangoException) :
110+
""" Something went wrong using the export cursor """
111+
def __init__(self, message, errors = {} ):
112+
pyArangoException.__init__(self, message, errors)

pyArango/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def save(self):
5050
del(payload["username"])
5151
del(payload["password"])
5252

53-
payload = json.dumps(payload)
53+
payload = json.dumps(payload, default=str)
5454
if not self.URL :
5555
if "username" not in self._store or "password" not in self._store :
5656
raise KeyError("You must define self['name'] and self['password'] to be able to create a new user")
@@ -86,7 +86,7 @@ def setPermissions(self, dbName, access) :
8686
raise KeyError("Unknown database: %s" % dbName)
8787

8888
url = "%s/database/%s" % (self.URL, dbName)
89-
r = self.connection.session.put(url, data = json.dumps({"grant": rights}))
89+
r = self.connection.session.put(url, data = json.dumps({"grant": rights}, default=str))
9090
if r.status_code < 200 or r.status_code > 202 :
9191
raise CreationError("Unable to grant rights", r.content)
9292

0 commit comments

Comments
 (0)