@@ -102,11 +102,13 @@ def _status(self, code):
102
102
103
103
:param code: the collection status code
104
104
:type code: int
105
- :returns: the collection status text
106
- :rtype: str | unicode
105
+ :returns: the collection status text or ``None``
106
+ :rtype: str | unicode | None
107
107
:raises arango.exceptions.CollectionBadStatusError: if the collection
108
108
status code is unknown
109
109
"""
110
+ if code is None : # pragma: no cover
111
+ return None
110
112
try :
111
113
return self .STATUSES [code ]
112
114
except KeyError :
@@ -217,10 +219,10 @@ def handler(res):
217
219
def properties (self ):
218
220
"""Return the collection properties.
219
221
220
- :returns: the collection properties
222
+ :returns: The collection properties.
221
223
:rtype: dict
222
- :raises arango.exceptions.CollectionPropertiesError: if the
223
- collection properties cannot be retrieved
224
+ :raises arango.exceptions.CollectionPropertiesError: If the
225
+ collection properties cannot be retrieved.
224
226
"""
225
227
request = Request (
226
228
method = 'get' ,
@@ -230,24 +232,24 @@ def properties(self):
230
232
def handler (res ):
231
233
if res .status_code not in HTTP_OK :
232
234
raise CollectionPropertiesError (res )
233
- result = {
234
- 'id' : res .body ['id' ],
235
- 'name' : res .body ['name' ],
236
- 'edge' : res .body ['type' ] == 3 ,
237
- 'sync' : res .body ['waitForSync' ],
238
- 'status' : self ._status (res .body ['status' ]),
239
- 'compact' : res .body ['doCompact' ],
240
- 'system' : res .body ['isSystem' ],
241
- 'volatile' : res .body ['isVolatile' ],
242
- 'journal_size' : res .body ['journalSize' ],
243
- 'keygen' : res .body ['keyOptions' ]['type' ],
244
- 'user_keys' : res .body ['keyOptions' ]['allowUserKeys' ],
235
+
236
+ key_options = res .body .get ('keyOptions' , {})
237
+
238
+ return {
239
+ 'id' : res .body .get ('id' ),
240
+ 'name' : res .body .get ('name' ),
241
+ 'edge' : res .body .get ('type' ) == 3 ,
242
+ 'sync' : res .body .get ('waitForSync' ),
243
+ 'status' : self ._status (res .body .get ('status' )),
244
+ 'compact' : res .body .get ('doCompact' ),
245
+ 'system' : res .body .get ('isSystem' ),
246
+ 'volatile' : res .body .get ('isVolatile' ),
247
+ 'journal_size' : res .body .get ('journalSize' ),
248
+ 'keygen' : key_options .get ('type' ),
249
+ 'user_keys' : key_options .get ('allowUserKeys' ),
250
+ 'key_increment' : key_options .get ('increment' ),
251
+ 'key_offset' : key_options .get ('offset' )
245
252
}
246
- if 'increment' in res .body ['keyOptions' ]:
247
- result ['key_increment' ] = res .body ['keyOptions' ]['increment' ]
248
- if 'offset' in res .body ['keyOptions' ]:
249
- result ['key_offset' ] = res .body ['keyOptions' ]['offset' ]
250
- return result
251
253
252
254
return request , handler
253
255
@@ -257,9 +259,9 @@ def configure(self, sync=None, journal_size=None):
257
259
258
260
Only *sync* and *journal_size* properties are configurable.
259
261
260
- :param sync: wait for the operation to sync to disk
262
+ :param sync: Wait for the operation to sync to disk.
261
263
:type sync: bool
262
- :param journal_size: the journal size
264
+ :param journal_size: The journal size.
263
265
:type journal_size: int
264
266
:returns: the new collection properties
265
267
:rtype: dict
@@ -281,22 +283,24 @@ def configure(self, sync=None, journal_size=None):
281
283
def handler (res ):
282
284
if res .status_code not in HTTP_OK :
283
285
raise CollectionConfigureError (res )
284
- result = {
285
- 'id' : res .body ['id' ],
286
- 'name' : res .body ['name' ],
287
- 'edge' : res .body ['type' ] == 3 ,
288
- 'sync' : res .body ['waitForSync' ],
289
- 'status' : self ._status (res .body ['status' ]),
290
- 'compact' : res .body ['doCompact' ],
291
- 'system' : res .body ['isSystem' ],
292
- 'volatile' : res .body ['isVolatile' ],
293
- 'journal_size' : res .body ['journalSize' ],
294
- 'keygen' : res .body ['keyOptions' ]['type' ],
295
- 'user_keys' : res .body ['keyOptions' ]['allowUserKeys' ],
296
- 'key_increment' : res .body ['keyOptions' ].get ('increment' ),
297
- 'key_offset' : res .body ['keyOptions' ].get ('offset' )
286
+
287
+ key_options = res .body .get ('keyOptions' , {})
288
+
289
+ return {
290
+ 'id' : res .body .get ('id' ),
291
+ 'name' : res .body .get ('name' ),
292
+ 'edge' : res .body .get ('type' ) == 3 ,
293
+ 'sync' : res .body .get ('waitForSync' ),
294
+ 'status' : self ._status (res .body .get ('status' )),
295
+ 'compact' : res .body .get ('doCompact' ),
296
+ 'system' : res .body .get ('isSystem' ),
297
+ 'volatile' : res .body .get ('isVolatile' ),
298
+ 'journal_size' : res .body .get ('journalSize' ),
299
+ 'keygen' : key_options .get ('type' ),
300
+ 'user_keys' : key_options .get ('allowUserKeys' ),
301
+ 'key_increment' : key_options .get ('increment' ),
302
+ 'key_offset' : key_options .get ('offset' )
298
303
}
299
- return result
300
304
301
305
return request , handler
302
306
0 commit comments