X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FLeaseFilter.py;h=de340ea4333161ea822441834894fe305cee59dd;hb=1b1b5a911bb005644baabb87ecba60602228a070;hp=c7e31bc7d95963ebd09557c6071f1aaf7dfa9170;hpb=6c98ac7b4385db298d2a545c4ef11f3f7ebad61d;p=plcapi.git diff --git a/PLC/LeaseFilter.py b/PLC/LeaseFilter.py index c7e31bc..de340ea 100644 --- a/PLC/LeaseFilter.py +++ b/PLC/LeaseFilter.py @@ -21,7 +21,7 @@ class LeaseFilter(Filter): # general notes on input parameters # int_timestamp: number of seconds since the epoch # str_timestamp: see Timestamp.sql_validate - # timeslot: a tuple (from, until), each being either int_timestamp or + # timeslot: a list [from, until], each being either int_timestamp or # str_timestamp local_fields = { @@ -64,12 +64,11 @@ class LeaseFilter(Filter): # basic SQL utilities @staticmethod def sql_time_intersect(f1, u1, f2, u2): - # either f2 is in [f1,u1], or u2 is in [f1,u1], or f2<=f1<=u1<=u2 + # either f2 is in [f1,u1[, or u2 is in ]f1,u1], or f2<=f1= mark - return "({u1} >= {mark})".format(u1=u1, mark=mark) + return f"({u1} >= {mark})" # hooks for the local fields def sql_alive(self, alive): @@ -100,8 +97,7 @@ class LeaseFilter(Filter): u = LeaseFilter.quote(u) return LeaseFilter.sql_time_intersect(f, u, 't_from', 't_until') else: - raise PLCInvalidArgument("LeaseFilter: alive field {}" - .format(alive)) + raise PLCInvalidArgument(f"LeaseFilter: alive field {alive}") def sql_clip(self, clip): if isinstance(clip, int) or isinstance(clip, str): @@ -113,8 +109,7 @@ class LeaseFilter(Filter): u = LeaseFilter.quote(u) return LeaseFilter.sql_time_intersect(f, u, 't_from', 't_until') else: - raise PLCInvalidArgument("LeaseFilter: clip field {}" - .format(clip)) + raise PLCInvalidArgument(f"LeaseFilter: clip field {clip}") # the whole key to implementing day is to compute today's beginning def today_start(self): @@ -157,14 +152,14 @@ class LeaseFilter(Filter): try: # locate hook function associated with key method = LeaseFilter.__dict__['sql_' + k] - where_part += " {} {}({})"\ - .format(self.join_with, - self.negation[k], - method(self, self.local[k])) + where_part += ( + f" {self.join_with} {self.negation[k]}" + f"({method(self, self.local[k])})" + ) except Exception as e: raise PLCInvalidArgument( - "LeaseFilter: something wrong with filter" - "key {}, val was {} -- {}".format(k, v, e)) + f"LeaseFilter: something wrong with filter " + f"key {k}, value was {v} -- {e}") return (where_part, clip_part) # xxx not sure where this belongs yet