@@ -303,9 +303,7 @@ def __init__(
303
303
verify = verify if verify is not None else config .get ("verify" , True )
304
304
retries = retries if retries is not None else config .get ("retries" , 0 )
305
305
timeout = timeout if timeout is not None else config .get ("timeout" , 300 )
306
- retry_delay = (
307
- retry_delay if retry_delay is not None else config .get ("retry_delay" , 5 )
308
- )
306
+ retry_delay = retry_delay if retry_delay is not None else config .get ("retry_delay" , 5 )
309
307
self .config = self ._from_dict (config )
310
308
311
309
self .auth = auth
@@ -351,9 +349,7 @@ def __get_address_parts(self, address):
351
349
Split the two parts of the api address
352
350
:param address: address of the api
353
351
"""
354
- return self .__verify_address_complement (
355
- address .split ("//" )[- 1 ].split ("/" , maxsplit = 1 )
356
- )
352
+ return self .__verify_address_complement (address .split ("//" )[- 1 ].split ("/" , maxsplit = 1 ))
357
353
358
354
@staticmethod
359
355
def __verify_address_complement (address_list ):
@@ -362,9 +358,7 @@ def __verify_address_complement(address_list):
362
358
:param address_list: One or two part of the address
363
359
"""
364
360
return (
365
- address_list
366
- if len (address_list ) == 2
367
- else [address_list [0 ], ADDRESS_QUERY_COMPLEMENT ]
361
+ address_list if len (address_list ) == 2 else [address_list [0 ], ADDRESS_QUERY_COMPLEMENT ]
368
362
)
369
363
370
364
@staticmethod
@@ -464,9 +458,7 @@ def query(
464
458
if not dates ["to" ]:
465
459
dates ["to" ] = "now()"
466
460
if self .config .stream :
467
- logging .warning (
468
- ERROR_MSGS ["stream_mode_not_supported" ] % self .config .response
469
- )
461
+ logging .warning (ERROR_MSGS ["stream_mode_not_supported" ] % self .config .response )
470
462
# If is a future query and response type is 'xls' or 'msgpack'
471
463
# return warning because is not available.
472
464
if self ._future_queries_available (self .config .response ):
@@ -476,9 +468,7 @@ def query(
476
468
toDate = self ._toDate_parser (fromDate , default_to (dates ["to" ]))
477
469
478
470
if toDate > default_to ("now()" ):
479
- raise DevoClientException (
480
- ERROR_MSGS ["future_queries_not_supported" ]
481
- )
471
+ raise DevoClientException (ERROR_MSGS ["future_queries_not_supported" ])
482
472
483
473
self .config .stream = False
484
474
@@ -509,9 +499,7 @@ def _call(self, payload):
509
499
# Analyse the response data to check if there are any error
510
500
# messages within the response.
511
501
self ._error_handler (wholeResponse .text )
512
- return self .config .processor (
513
- self ._keepalive_content_sanitize (wholeResponse .text )
514
- )
502
+ return self .config .processor (self ._keepalive_content_sanitize (wholeResponse .text ))
515
503
516
504
def _return_string_stream (self , payload ):
517
505
"""If it's a stream call, return yield lines
@@ -557,10 +545,7 @@ def _empty_lines_sanitize(line):
557
545
return line .strip ()
558
546
559
547
def _keepalive_content_sanitize (self , response ):
560
- if (
561
- self .config .keepAliveToken == NO_KEEPALIVE_TOKEN
562
- or self .config .keepAliveToken is None
563
- ):
548
+ if self .config .keepAliveToken == NO_KEEPALIVE_TOKEN or self .config .keepAliveToken is None :
564
549
return response
565
550
elif self .config .keepAliveToken == DEFAULT_KEEPALIVE_TOKEN :
566
551
if self .config .response .startswith ("json" ):
@@ -584,10 +569,7 @@ def _keepalive_content_sanitize(self, response):
584
569
return response .replace (f"{ self .config .keepAliveToken } " , "" )
585
570
586
571
def _keepalive_stream_sanitize (self , line ):
587
- if (
588
- self .config .keepAliveToken == NO_KEEPALIVE_TOKEN
589
- or self .config .keepAliveToken is None
590
- ):
572
+ if self .config .keepAliveToken == NO_KEEPALIVE_TOKEN or self .config .keepAliveToken is None :
591
573
return line
592
574
elif self .config .keepAliveToken == DEFAULT_KEEPALIVE_TOKEN :
593
575
if self .config .response .startswith ("json" ):
@@ -641,9 +623,7 @@ def __request(self, payload):
641
623
POST request method extracted for mocking purposes
642
624
"""
643
625
return requests .post (
644
- "{}://{}" .format (
645
- "http" if self .unsecure_http else "https" , "/" .join (self .address )
646
- ),
626
+ "{}://{}" .format ("http" if self .unsecure_http else "https" , "/" .join (self .address )),
647
627
data = payload ,
648
628
headers = self ._get_headers (payload ),
649
629
verify = self .verify ,
@@ -668,9 +648,7 @@ def _get_payload(query, query_id, dates, opts):
668
648
date_to = default_to (dates ["to" ]) if dates ["to" ] is not None else None
669
649
670
650
payload = {
671
- "from" : int (date_from / 1000 )
672
- if isinstance (date_from , (int , float ))
673
- else date_from ,
651
+ "from" : int (date_from / 1000 ) if isinstance (date_from , (int , float )) else date_from ,
674
652
"to" : int (date_to / 1000 ) if isinstance (date_to , (int , float )) else date_to ,
675
653
"mode" : {"type" : opts ["response" ]},
676
654
}
@@ -693,10 +671,7 @@ def _get_payload(query, query_id, dates, opts):
693
671
if opts ["destination" ]:
694
672
payload ["destination" ] = opts ["destination" ]
695
673
696
- if (
697
- opts ["keepAliveToken" ] is not None
698
- and opts ["keepAliveToken" ] != NO_KEEPALIVE_TOKEN
699
- ):
674
+ if opts ["keepAliveToken" ] is not None and opts ["keepAliveToken" ] != NO_KEEPALIVE_TOKEN :
700
675
if opts ["keepAliveToken" ] == EMPTY_EVENT_KEEPALIVE_TOKEN :
701
676
payload ["keepAlive" ] = {"type" : "empty" }
702
677
elif opts ["keepAliveToken" ] == DEFAULT_KEEPALIVE_TOKEN :
@@ -797,25 +772,19 @@ def stop_job(self, job_id):
797
772
"""Stop one job by ID
798
773
:param job_id: id of job
799
774
:return: bool"""
800
- return self ._call_jobs (
801
- "{}{}{}{}" .format (self .address [0 ], ADDRESS_JOB , "stop/" , job_id )
802
- )
775
+ return self ._call_jobs ("{}{}{}{}" .format (self .address [0 ], ADDRESS_JOB , "stop/" , job_id ))
803
776
804
777
def start_job (self , job_id ):
805
778
"""Start one job by ID
806
779
:param job_id: id of job
807
780
:return: bool"""
808
- return self ._call_jobs (
809
- "{}{}{}{}" .format (self .address [0 ], ADDRESS_JOB , "start/" , job_id )
810
- )
781
+ return self ._call_jobs ("{}{}{}{}" .format (self .address [0 ], ADDRESS_JOB , "start/" , job_id ))
811
782
812
783
def remove_job (self , job_id ):
813
784
"""Remove one job by ID
814
785
:param job_id: id of job
815
786
:return: bool"""
816
- return self ._call_jobs (
817
- "{}{}{}{}" .format (self .address [0 ], ADDRESS_JOB , "remove/" , job_id )
818
- )
787
+ return self ._call_jobs ("{}{}{}{}" .format (self .address [0 ], ADDRESS_JOB , "remove/" , job_id ))
819
788
820
789
def _call_jobs (self , address ):
821
790
"""
@@ -837,10 +806,7 @@ def _call_jobs(self, address):
837
806
raise DevoClientException (ERROR_MSGS ["connection_error" ]) from error
838
807
839
808
if response :
840
- if (
841
- response .status_code != 200
842
- or "error" in response .text [0 :15 ].lower ()
843
- ):
809
+ if response .status_code != 200 or "error" in response .text [0 :15 ].lower ():
844
810
raise DevoClientRequestException (response )
845
811
try :
846
812
return json .loads (response .text )
@@ -893,9 +859,7 @@ def _fromDate_parser(fromDate, now=datetime.now()):
893
859
elif fromDate == "today" :
894
860
return adate .timestamp () * 1000
895
861
elif fromDate == "endday" :
896
- return (
897
- adate + timedelta (hours = 23 , minutes = 59 , seconds = 59 )
898
- ).timestamp () * 1000
862
+ return (adate + timedelta (hours = 23 , minutes = 59 , seconds = 59 )).timestamp () * 1000
899
863
elif fromDate == "endmonth" :
900
864
return (
901
865
adate .replace (day = calendar .monthrange (adate .year , adate .month )[1 ])
@@ -910,15 +874,9 @@ def _toDate_parser(fromDateMillisec, toDate, now=datetime.now()):
910
874
return toDate
911
875
912
876
now = now .astimezone (pytz .UTC )
913
- fromDate = datetime .fromtimestamp (fromDateMillisec / 1000 ).replace (
914
- tzinfo = pytz .utc
915
- )
916
- aFromdate = datetime .strptime (str (fromDate .date ()), "%Y-%m-%d" ).replace (
917
- tzinfo = pytz .utc
918
- )
919
- aNowdate = datetime .strptime (str (now .date ()), "%Y-%m-%d" ).replace (
920
- tzinfo = pytz .utc
921
- )
877
+ fromDate = datetime .fromtimestamp (fromDateMillisec / 1000 ).replace (tzinfo = pytz .utc )
878
+ aFromdate = datetime .strptime (str (fromDate .date ()), "%Y-%m-%d" ).replace (tzinfo = pytz .utc )
879
+ aNowdate = datetime .strptime (str (now .date ()), "%Y-%m-%d" ).replace (tzinfo = pytz .utc )
922
880
923
881
if re .match ("^[1-9]+(d|ad|h|ah|m|am|s|as)" , toDate ):
924
882
date = re .split ("(d|ad|h|ah|m|am|s|as)" , toDate )
@@ -945,14 +903,10 @@ def _toDate_parser(fromDateMillisec, toDate, now=datetime.now()):
945
903
elif toDate == "today" :
946
904
return aNowdate .timestamp () * 1000
947
905
elif toDate == "endday" :
948
- return (
949
- aFromdate + timedelta (hours = 23 , minutes = 59 , seconds = 59 )
950
- ).timestamp () * 1000
906
+ return (aFromdate + timedelta (hours = 23 , minutes = 59 , seconds = 59 )).timestamp () * 1000
951
907
elif toDate == "endmonth" :
952
908
return (
953
- aFromdate .replace (
954
- day = calendar .monthrange (aFromdate .year , aFromdate .month )[1 ]
955
- )
909
+ aFromdate .replace (day = calendar .monthrange (aFromdate .year , aFromdate .month )[1 ])
956
910
+ timedelta (hours = 23 , minutes = 59 , seconds = 59 )
957
911
).timestamp () * 1000
958
912
elif toDate == "now" :
0 commit comments