21
21
AQLCacheConfigureError ,
22
22
AQLCachePropertiesError
23
23
)
24
+ from arango .formatter import (
25
+ format_aql_cache ,
26
+ format_aql_query ,
27
+ format_aql_tracking
28
+ )
24
29
from arango .request import Request
25
30
26
31
@@ -39,45 +44,6 @@ def __init__(self, connection, executor):
39
44
def __repr__ (self ):
40
45
return '<AQL in {}>' .format (self ._conn .db_name )
41
46
42
- # noinspection PyMethodMayBeStatic
43
- def _format_tracking_properties (self , body ):
44
- """Format the tracking properties.
45
-
46
- :param body: Response body.
47
- :type body: dict
48
- :return: Formatted body.
49
- :rtype: dict
50
- """
51
- body .pop ('code' , None )
52
- body .pop ('error' , None )
53
- if 'maxQueryStringLength' in body :
54
- body ['max_query_string_length' ] = body .pop ('maxQueryStringLength' )
55
- if 'maxSlowQueries' in body :
56
- body ['max_slow_queries' ] = body .pop ('maxSlowQueries' )
57
- if 'slowQueryThreshold' in body :
58
- body ['slow_query_threshold' ] = body .pop ('slowQueryThreshold' )
59
- if 'trackBindVars' in body :
60
- body ['track_bind_vars' ] = body .pop ('trackBindVars' )
61
- if 'trackSlowQueries' in body :
62
- body ['track_slow_queries' ] = body .pop ('trackSlowQueries' )
63
- return body
64
-
65
- # noinspection PyMethodMayBeStatic
66
- def _format_queries (self , body ):
67
- """Format the list of queries.
68
-
69
- :param body: Response body.
70
- :type body: dict
71
- :return: Formatted body.
72
- :rtype: dict
73
- """
74
- for query in body :
75
- if 'bindVars' in query :
76
- query ['bind_vars' ] = query .pop ('bindVars' )
77
- if 'runTime' in query :
78
- query ['runtime' ] = query .pop ('runTime' )
79
- return body
80
-
81
47
@property
82
48
def cache (self ):
83
49
"""Return the query cache API wrapper.
@@ -359,7 +325,7 @@ def queries(self):
359
325
def response_handler (resp ):
360
326
if not resp .is_success :
361
327
raise AQLQueryListError (resp , request )
362
- return self . _format_queries ( resp .body )
328
+ return [ format_aql_query ( q ) for q in resp .body ]
363
329
364
330
return self ._execute (request , response_handler )
365
331
@@ -378,7 +344,7 @@ def slow_queries(self):
378
344
def response_handler (resp ):
379
345
if not resp .is_success :
380
346
raise AQLQueryListError (resp , request )
381
- return self . _format_queries ( resp .body )
347
+ return [ format_aql_query ( q ) for q in resp .body ]
382
348
383
349
return self ._execute (request , response_handler )
384
350
@@ -416,7 +382,7 @@ def tracking(self):
416
382
def response_handler (resp ):
417
383
if not resp .is_success :
418
384
raise AQLQueryTrackingGetError (resp , request )
419
- return self . _format_tracking_properties (resp .body )
385
+ return format_aql_tracking (resp .body )
420
386
421
387
return self ._execute (request , response_handler )
422
388
@@ -456,7 +422,7 @@ def set_tracking(self,
456
422
def response_handler (resp ):
457
423
if not resp .is_success :
458
424
raise AQLQueryTrackingSetError (resp , request )
459
- return self . _format_tracking_properties (resp .body )
425
+ return format_aql_tracking (resp .body )
460
426
461
427
return self ._execute (request , response_handler )
462
428
@@ -554,28 +520,6 @@ class AQLQueryCache(APIWrapper):
554
520
def __repr__ (self ):
555
521
return '<AQLQueryCache in {}>' .format (self ._conn .db_name )
556
522
557
- # noinspection PyMethodMayBeStatic
558
- def _format_cache_properties (self , body ):
559
- """Format the query cache properties.
560
-
561
- :param body: Response body.
562
- :type body: dict
563
- :return: Formatted body.
564
- :rtype: dict
565
- """
566
- body .pop ('code' , None )
567
- body .pop ('error' , None )
568
-
569
- if 'maxResults' in body :
570
- body ['max_results' ] = body .pop ('maxResults' )
571
- if 'maxResultsSize' in body :
572
- body ['max_results_size' ] = body .pop ('maxResultsSize' )
573
- if 'maxEntrySize' in body :
574
- body ['max_entry_size' ] = body .pop ('maxEntrySize' )
575
- if 'includeSystem' in body :
576
- body ['include_system' ] = body .pop ('includeSystem' )
577
- return body
578
-
579
523
def properties (self ):
580
524
"""Return the query cache properties.
581
525
@@ -591,7 +535,7 @@ def properties(self):
591
535
def response_handler (resp ):
592
536
if not resp .is_success :
593
537
raise AQLCachePropertiesError (resp , request )
594
- return self . _format_cache_properties (resp .body )
538
+ return format_aql_cache (resp .body )
595
539
596
540
return self ._execute (request , response_handler )
597
541
@@ -642,7 +586,7 @@ def configure(self,
642
586
def response_handler (resp ):
643
587
if not resp .is_success :
644
588
raise AQLCacheConfigureError (resp , request )
645
- return self . _format_cache_properties (resp .body )
589
+ return format_aql_cache (resp .body )
646
590
647
591
return self ._execute (request , response_handler )
648
592
0 commit comments