Skip to content

Commit

Permalink
python: More fixes for Python 3.12 `SyntaxWarning: invalid escape seq…
Browse files Browse the repository at this point in the history
…uence` (OSGeo#3331)
  • Loading branch information
echoix authored and jadenabrams100 committed Feb 21, 2024
1 parent fc043c5 commit 26e4531
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def Run(self, log, onDone, parent=None):
# split condition
# TODO: this part needs some better solution
condVar, condText = map(
lambda x: x.strip(), re.split("\s* in \s*", cond)
lambda x: x.strip(), re.split(r"\s* in \s*", cond)
)
pattern = re.compile("%" + condVar)
# for vars()[condVar] in eval(condText): ?
Expand Down Expand Up @@ -2578,7 +2578,7 @@ def _writeItem(self, item, ignoreBlock=True, variables={}):
cond = pattern.sub(value, cond)
if isinstance(item, ModelLoop):
condVar, condText = map(
lambda x: x.strip(), re.split("\s* in \s*", cond)
lambda x: x.strip(), re.split(r"\s* in \s*", cond)
)
cond = "%sfor %s in " % (" " * self.indent, condVar)
if condText[0] == "`" and condText[-1] == "`":
Expand Down Expand Up @@ -3362,7 +3362,7 @@ def _substituteVariable(self, string, variable, data):
:return: modified string
"""
result = ""
ss = re.split("\w*(%" + variable + ")w*", string)
ss = re.split(r"\w*(%" + variable + ")w*", string)

if not ss[0] and not ss[-1]:
if data:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/modules/mcalc_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def _getCommand(self):
if self.overwrite.IsChecked():
overwrite = " --overwrite"
seed_flag = seed = ""
if re.search(pattern="rand *\(.+\)", string=expr):
if re.search(pattern=r"rand *\(.+\)", string=expr):
if self.randomSeed.IsChecked():
seed_flag = " -s"
else:
Expand Down Expand Up @@ -624,7 +624,7 @@ def _addSomething(self, what):

self.text_mcalc.SetValue(newmcalcstr)
if len(what) > 0:
match = re.search(pattern="\(.*\)", string=what)
match = re.search(pattern=r"\(.*\)", string=what)
if match:
position_offset += match.start() + 1
else:
Expand Down Expand Up @@ -665,7 +665,7 @@ def OnMCalcRun(self, event):
return

seed_flag = seed = None
if re.search(pattern="rand *\(.+\)", string=expr):
if re.search(pattern=r"rand *\(.+\)", string=expr):
if self.randomSeed.IsChecked():
seed_flag = "-s"
else:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/web_services/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def addlayer(layer, item):
# self.ExpandAll(self.GetRootItem())

def GetSelectedLayers(self):
"""Get selected layers/styles in LayersList
r"""Get selected layers/styles in LayersList
:return: dict with these items:
* 'name' : layer name used for request
Expand Down
2 changes: 1 addition & 1 deletion python/grass/gunittest/gmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class SimpleModule(Module):
"""Simple wrapper around pygrass.modules.Module to make sure that
r"""Simple wrapper around pygrass.modules.Module to make sure that
run\_, finish\_, stdout and stderr are set correctly.
>>> mapcalc = SimpleModule('r.mapcalc', expression='test_a = 1',
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/modules/interface/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self, nprocs=1):
self._finished_modules = [] # Store all processed modules in a list

def put(self, module):
"""Put the next Module or MultiModule object in the queue
r"""Put the next Module or MultiModule object in the queue
To run the Module objects in parallel the run\_ and finish\_ options
of the Module must be set to False.
Expand Down
3 changes: 2 additions & 1 deletion python/grass/pygrass/modules/interface/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def __init__(self, xparameter=None, diz=None):
try:
# Check for integer ranges: "3-30" or float ranges: "0.0-1.0"
isrange = re.match(
"(?P<min>-*\d+.*\d*)*-(?P<max>\d+.*\d*)*", diz["values"][0]
r"(?P<min>-?(?:\d*\.)?\d+)?-(?P<max>-?(?:\d*\.)?\d+)?",
diz["values"][0],
)
if isrange:
mn, mx = isrange.groups()
Expand Down
14 changes: 7 additions & 7 deletions python/grass/pygrass/vector/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
LineDist = namedtuple("LineDist", "point dist spdist sldist")

WKT = {
"POINT\((.*)\)": "point", # 'POINT\(\s*([+-]*\d+\.*\d*)+\s*\)'
"LINESTRING\((.*)\)": "line",
r"POINT\((.*)\)": "point", # 'POINT\(\s*([+-]*\d+\.*\d*)+\s*\)'
r"LINESTRING\((.*)\)": "line",
}


Expand Down Expand Up @@ -1135,7 +1135,7 @@ def from_wkt(self, wkt):
..
"""
match = re.match("LINESTRING\((.*)\)", wkt)
match = re.match(r"LINESTRING\((.*)\)", wkt)
if match:
self.reset()
for coord in match.groups()[0].strip().split(","):
Expand Down Expand Up @@ -1682,7 +1682,7 @@ def isles(self, isles=None):

@mapinfo_must_be_set
def area(self):
"""Returns area of area without areas of isles.
r"""Returns area of area without areas of isles.
double Vect_get_area_area (const struct Map_info \*Map, int area)
"""
return libvect.Vect_get_area_area(self.c_mapinfo, self.id)
Expand Down Expand Up @@ -1763,7 +1763,7 @@ def buffer(

@mapinfo_must_be_set
def boundaries(self, ilist=False):
"""Creates list of boundaries for given area.
r"""Creates list of boundaries for given area.
int Vect_get_area_boundaries(const struct Map_info \*Map,
int area, struct ilist \*List)
Expand Down Expand Up @@ -1802,7 +1802,7 @@ def cats(self, cats=None):
return cats

def get_first_cat(self):
"""Find FIRST category of given field and area.
r"""Find FIRST category of given field and area.
int Vect_get_area_cat(const struct Map_info \*Map, int area, int field)
Expand All @@ -1828,7 +1828,7 @@ def contains_point(self, point, bbox=None):

@mapinfo_must_be_set
def perimeter(self):
"""Calculate area perimeter.
r"""Calculate area perimeter.
:return: double Vect_area_perimeter (const struct line_pnts \*Points)
Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def convert_xml_to_utf8(xml_text):

# modify: fetch encoding from the interface description text(xml)
# e.g. <?xml version="1.0" encoding="GBK"?>
pattern = re.compile(b'<\?xml[^>]*\Wencoding="([^"]*)"[^>]*\?>')
pattern = re.compile(rb'<\?xml[^>]*\Wencoding="([^"]*)"[^>]*\?>')
m = re.match(pattern, xml_text)
if m is None:
return xml_text.encode("utf-8") if xml_text else None
Expand Down
4 changes: 2 additions & 2 deletions python/grass/temporal/abstract_space_time_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,8 +1630,8 @@ def leading_zero(value):
shortcut_identifier = leading_zero(self.semantic_label)
if shortcut_identifier:
where += (
"{br} LIKE '{si}\_%' {esc} OR {br} LIKE '%\_{si}' {esc} OR "
"{br} LIKE '{orig}\_%' {esc} OR {br} LIKE '%\_{orig}' {esc}".format(
"{br} LIKE '{si}\\_%' {esc} OR {br} LIKE '%\\_{si}' {esc} OR "
"{br} LIKE '{orig}\\_%' {esc} OR {br} LIKE '%\\_{orig}' {esc}".format(
br="semantic_label",
si=shortcut_identifier,
orig=self.semantic_label.upper(),
Expand Down

0 comments on commit 26e4531

Please sign in to comment.