git://git.onelab.eu
/
plcapi.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1b1b5a9
)
replace old-school formatting in Filter.py with f-strings
author
Thierry Parmentelat
<thierry.parmentelat@inria.fr>
Wed, 7 Feb 2024 12:48:41 +0000
(13:48 +0100)
committer
Thierry Parmentelat
<thierry.parmentelat@inria.fr>
Wed, 7 Feb 2024 12:48:41 +0000
(13:48 +0100)
PLC/Filter.py
patch
|
blob
|
history
diff --git
a/PLC/Filter.py
b/PLC/Filter.py
index
41f89a6
..
29accf1
100644
(file)
--- a/
PLC/Filter.py
+++ b/
PLC/Filter.py
@@
-155,7
+155,7
@@
class Filter(Parameter, dict):
# filter on fields
if not modifiers['-']:
if field not in self.fields:
# filter on fields
if not modifiers['-']:
if field not in self.fields:
- raise PLCInvalidArgument(
"Invalid filter field '%s'" % field
)
+ raise PLCInvalidArgument(
f"Invalid filter field '{field}'"
)
# handling array fileds always as compound values
if modifiers['&'] or modifiers['|']:
# handling array fileds always as compound values
if modifiers['&'] or modifiers['|']:
@@
-198,10
+198,10
@@
class Filter(Parameter, dict):
operator = "="
value = "'{}'"
else:
operator = "="
value = "'{}'"
else:
- field
=
""
- operator
=
""
+ field
=
""
+ operator
=
""
value = "FALSE"
value = "FALSE"
- clause =
"%s %s %s" % (field, operator, value)
+ clause =
f"{field} {operator} {value}"
else:
vals = {}
for val in value:
else:
vals = {}
for val in value:
@@
-213,25
+213,26
@@
class Filter(Parameter, dict):
subclauses = []
for operator in list(vals.keys()):
if operator == '=':
subclauses = []
for operator in list(vals.keys()):
if operator == '=':
+ expanded = ",".join(vals[operator])
if modifiers['&']:
if modifiers['&']:
- subclauses.append(
"(%s @> ARRAY[%s])" % (field, ",".join(vals[operator]))
)
+ subclauses.append(
f"({field} @> ARRAY[{expanded}])"
)
elif modifiers['|']:
elif modifiers['|']:
- subclauses.append(
"(%s && ARRAY[%s])" % (field, ",".join(vals[operator]))
)
+ subclauses.append(
f"({field} && ARRAY[{expanded}])"
)
else:
else:
- subclauses.append(
"(%s IN (%s))" % (field, ",".join(vals[operator]))
)
+ subclauses.append(
f"({field} IN ({expanded}))"
)
elif operator == 'IS':
elif operator == 'IS':
- subclauses.append(
"(%s IS NULL)" % field
)
+ subclauses.append(
f"({field} IS NULL)"
)
else:
for value in vals[operator]:
else:
for value in vals[operator]:
- subclauses.append(
"(%s %s %s)" % (field, operator, value)
)
+ subclauses.append(
f"({field} {operator} {value})"
)
clause = "(" + " OR ".join(subclauses) + ")"
else:
operator, value = get_op_and_val(value)
clause = "(" + " OR ".join(subclauses) + ")"
else:
operator, value = get_op_and_val(value)
- clause =
"%s %s %s" % (field, operator, value)
+ clause =
f"{field} {operator} {value}"
if modifiers['~']:
if modifiers['~']:
- clause =
" ( NOT %s ) " % (clause)
+ clause =
f" ( NOT {clause} ) "
conditionals.append(clause)
# sorting and clipping
conditionals.append(clause)
# sorting and clipping
@@
-251,7
+252,7
@@
class Filter(Parameter, dict):
order = 'DESC'
if field not in self.fields:
raise PLCInvalidArgument("Invalid field %r in SORT filter"%field)
order = 'DESC'
if field not in self.fields:
raise PLCInvalidArgument("Invalid field %r in SORT filter"%field)
- sorts.append(
"%s %s"%(field,order)
)
+ sorts.append(
f"{field} {order}"
)
# clipping
elif field == 'OFFSET':
clips.append("OFFSET %d"%value)
# clipping
elif field == 'OFFSET':
clips.append("OFFSET %d"%value)
@@
-259,13
+260,12
@@
class Filter(Parameter, dict):
elif field == 'LIMIT' :
clips.append("LIMIT %d"%value)
elif field == 'LIMIT' :
clips.append("LIMIT %d"%value)
- where_part =
(" %s " % join_with)
.join(conditionals)
+ where_part =
f" {join_with} "
.join(conditionals)
clip_part = ""
if sorts:
clip_part += " ORDER BY " + ",".join(sorts)
if clips:
clip_part += " " + " ".join(clips)
if Filter.debug:
clip_part = ""
if sorts:
clip_part += " ORDER BY " + ",".join(sorts)
if clips:
clip_part += " " + " ".join(clips)
if Filter.debug:
- logger.debug('Filter.sql: where_part={} - clip_part={}'
- .format(where_part, clip_part))
+ logger.debug(f"Filter.sql: {where_part=} - {clip_part=}")
return where_part, clip_part
return where_part, clip_part