Fix invalid escape syntax warnings

Additionally use rawstrings with all regex calls
This commit is contained in:
wereii
2024-09-10 15:15:24 +02:00
committed by Tomas
parent 1ea6136cb2
commit 954a164922
17 changed files with 43 additions and 43 deletions

View File

@@ -141,14 +141,14 @@ def update_db():
(row['typeName_en-us'].startswith('Civilian') and "Shuttle" not in row['typeName_en-us'])
or row['typeName_en-us'] == 'Capsule'
or row['groupID'] == 4033 # destructible effect beacons
or re.match('AIR .+Booster.*', row['typeName_en-us'])
or re.match(r'AIR .+Booster.*', row['typeName_en-us'])
):
row['published'] = True
# Nearly useless and clutter search results too much
elif (
row['typeName_en-us'].startswith('Limited Synth ')
or row['typeName_en-us'].startswith('Expired ')
or re.match('Mining Blitz .+ Booster Dose .+', row['typeName_en-us'])
or re.match(r'Mining Blitz .+ Booster Dose .+', row['typeName_en-us'])
or row['typeName_en-us'].endswith(' Filament') and (
"'Needlejack'" not in row['typeName_en-us'] and
"'Devana'" not in row['typeName_en-us'] and
@@ -544,7 +544,7 @@ def update_db():
continue
typeName = row.get('typeName_en-us', '')
# Regular sets matching
m = re.match('(?P<grade>(High|Mid|Low)-grade) (?P<set>\w+) (?P<implant>(Alpha|Beta|Gamma|Delta|Epsilon|Omega))', typeName, re.IGNORECASE)
m = re.match(r'(?P<grade>(High|Mid|Low)-grade) (?P<set>\w+) (?P<implant>(Alpha|Beta|Gamma|Delta|Epsilon|Omega))', typeName, re.IGNORECASE)
if m:
implantSets.setdefault((m.group('grade'), m.group('set')), set()).add(row['typeID'])
# Special set matching

View File

@@ -14,7 +14,7 @@ with open("version.yml", 'r') as file:
os.environ["PYFA_DIST_DIR"] = os.path.join(os.getcwd(), 'dist')
os.environ["PYFA_VERSION"] = version
iscc = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
iscc = r"C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
source = os.path.join(os.environ["PYFA_DIST_DIR"], "pyfa")

View File

@@ -21,7 +21,7 @@ for modName in iterNamespace(__name__, __path__):
# loop through python files, extracting update number and function, and
# adding it to a list
modname_tail = modName.rsplit('.', 1)[-1]
m = re.match("^upgrade(?P<index>\d+)$", modname_tail)
m = re.match(r"^upgrade(?P<index>\d+)$", modname_tail)
if not m:
continue
index = int(m.group("index"))

View File

@@ -573,7 +573,7 @@ class DynamicItem(EqBase):
for kw in keywords:
if name.startswith(f'{kw} '):
name = kw
m = re.match('(?P<mutagrade>\S+) (?P<dronetype>\S+) Drone (?P<mutatype>\S+) Mutaplasmid', name)
m = re.match(r'(?P<mutagrade>\S+) (?P<dronetype>\S+) Drone (?P<mutatype>\S+) Mutaplasmid', name)
if m:
name = '{} {}'.format(m.group('mutagrade'), m.group('mutatype'))
return name

View File

@@ -273,7 +273,7 @@ class GraphCanvasPanel(wx.Panel):
legendLines = []
for i, iData in enumerate(legendData):
color, lineStyle, label = iData
legendLines.append(Line2D([0], [0], color=color, linestyle=lineStyle, label=label.replace('$', '\$')))
legendLines.append(Line2D([0], [0], color=color, linestyle=lineStyle, label=label.replace('$', r'\$')))
if len(legendLines) > 0 and self.graphFrame.ctrlPanel.showLegend:
legend = self.subplot.legend(handles=legendLines)

View File

@@ -22,9 +22,9 @@ class ItemDescription(wx.Panel):
desc = item.description.replace("\n", "<br>")
# Strip font tags
desc = re.sub("<( *)font( *)color( *)=(.*?)>(?P<inside>.*?)<( *)/( *)font( *)>", "\g<inside>", desc)
desc = re.sub("<( *)font( *)color( *)=(.*?)>(?P<inside>.*?)<( *)/( *)font( *)>", r"\g<inside>", desc)
# Strip URLs
desc = re.sub("<( *)a(.*?)>(?P<inside>.*?)<( *)/( *)a( *)>", "\g<inside>", desc)
desc = re.sub("<( *)a(.*?)>(?P<inside>.*?)<( *)/( *)a( *)>", r"\g<inside>", desc)
desc = "<body bgcolor='{}' text='{}'>{}</body>".format(
bgcolor.GetAsString(wx.C2S_HTML_SYNTAX),
fgcolor.GetAsString(wx.C2S_HTML_SYNTAX),

View File

@@ -13,8 +13,8 @@ from service.market import Market
def stripHtml(text):
text = re.sub('<\s*br\s*/?\s*>', '\n', text)
text = re.sub('</?[^/]+?(/\s*)?>', '', text)
text = re.sub(r'<\s*br\s*/?\s*>', '\n', text)
text = re.sub(r'</?[^/]+?(/\s*)?>', '', text)
return text

View File

@@ -115,7 +115,7 @@ class CharacterEntityEditor(EntityEditor):
sChar = Character.getInstance()
if entity.alphaCloneID:
trimmed_name = re.sub('[ \(\u03B1\)]+$', '', name)
trimmed_name = re.sub('[ \\(\u03B1\\)]+$', '', name)
sChar.rename(entity, trimmed_name)
else:
sChar.rename(entity, name)

View File

@@ -66,8 +66,8 @@ class UpdateDialog(wx.Dialog):
self.browser.Bind(wx.html2.EVT_WEBVIEW_NEWWINDOW, self.OnNewWindow)
link_patterns = [
(re.compile("#(\d+)", re.I), r"https://github.com/pyfa-org/Pyfa/issues/\1"),
(re.compile("@(\w+)", re.I), r"https://github.com/\1")
(re.compile(r"#(\d+)", re.I), r"https://github.com/pyfa-org/Pyfa/issues/\1"),
(re.compile(r"@(\w+)", re.I), r"https://github.com/\1")
]
markdowner = markdown2.Markdown(

View File

@@ -96,7 +96,7 @@ class FloatBox(wx.TextCtrl):
if currentValue == self._storedValue:
event.Skip()
return
if currentValue == '' or re.match('^\d*\.?\d*$', currentValue):
if currentValue == '' or re.match(r'^\d*\.?\d*$', currentValue):
self._storedValue = currentValue
self.updateColor()
event.Skip()
@@ -131,7 +131,7 @@ class FloatRangeBox(wx.TextCtrl):
if currentValue == self._storedValue:
event.Skip()
return
if currentValue == '' or re.match('^\d*\.?\d*-?\d*\.?\d*$', currentValue):
if currentValue == '' or re.match(r'^\d*\.?\d*-?\d*\.?\d*$', currentValue):
self._storedValue = currentValue
event.Skip()
else:

View File

@@ -117,7 +117,7 @@ class PyfaJsonWriter(BaseWriter):
# Prefer safe way - replace any characters besides
# alphanumeric and few special characters with
# underscore
writer_safe_name = re.sub('[^\w\-.,() ]', '_', name, flags=re.UNICODE)
writer_safe_name = re.sub(r'[^\w\-.,() ]', '_', name, flags=re.UNICODE)
return writer_safe_name

View File

@@ -395,7 +395,7 @@ effectids_eos = set()
with open(effects_path) as f:
for line in f:
m = re.match("class Effect(\d+)\(", line)
m = re.match(r"class Effect(\d+)\(", line)
if m:
effectid = int(m.group(1))
effectids_eos.add(effectid)

View File

@@ -57,7 +57,7 @@ def main(old, new, groups=True, effects=True, attributes=True, renames=True):
with open(effectspath) as f:
for line in f:
for m in re.finditer('class Effect(?P<eid>\d+)\(BaseEffect\):', line):
for m in re.finditer(r'class Effect(?P<eid>\d+)\(BaseEffect\):', line):
effectid = int(m.group('eid'))
implemented.add(effectid)

View File

@@ -184,7 +184,7 @@ class SearchWorkerThread(threading.Thread):
def _prepareRequestNormal(self, request):
# Escape regexp-specific symbols, and un-escape whitespaces
request = re.escape(request)
request = re.sub(r'\\(?P<ws>\s+)', '\g<ws>', request)
request = re.sub(r'\\(?P<ws>\s+)', r'\g<ws>', request)
# Imitate wildcard search
request = re.sub(r'\\\*', r'\\w*', request)
request = re.sub(r'\\\?', r'\\w?', request)

View File

@@ -46,7 +46,7 @@ pyfalog = Logger(__name__)
MODULE_CATS = ('Module', 'Subsystem', 'Structure Module')
SLOT_ORDER = (FittingSlot.LOW, FittingSlot.MED, FittingSlot.HIGH, FittingSlot.RIG, FittingSlot.SUBSYSTEM, FittingSlot.SERVICE)
OFFLINE_SUFFIX = '/OFFLINE'
NAME_CHARS = '[^,/\[\]]' # Characters which are allowed to be used in name
NAME_CHARS = r'[^,/\[\]]' # Characters which are allowed to be used in name
class MutationExportData:
@@ -243,9 +243,9 @@ def importEft(lines):
aFit = AbstractFit()
aFit.mutations = importGetMutationData(lines)
stubPattern = '^\[.+?\]$'
modulePattern = '^(?P<typeName>{0}+?)(,\s*(?P<chargeName>{0}+?))?(?P<offline>\s*{1})?(\s*\[(?P<mutation>\d+?)\])?$'.format(NAME_CHARS, OFFLINE_SUFFIX)
droneCargoPattern = '^(?P<typeName>{}+?) x(?P<amount>\d+?)(\s*\[(?P<mutation>\d+?)\])?$'.format(NAME_CHARS)
stubPattern = r'^\[.+?\]$'
modulePattern = r'^(?P<typeName>{0}+?)(,\s*(?P<chargeName>{0}+?))?(?P<offline>\s*{1})?(\s*\[(?P<mutation>\d+?)\])?$'.format(NAME_CHARS, OFFLINE_SUFFIX)
droneCargoPattern = r'^(?P<typeName>{}+?) x(?P<amount>\d+?)(\s*\[(?P<mutation>\d+?)\])?$'.format(NAME_CHARS)
sections = []
for section in _importSectionIter(lines):
@@ -415,17 +415,17 @@ def importEftCfg(shipname, lines, progress):
continue
# Parse line into some data we will need
misc = re.match("(Drones|Implant|Booster)_(Active|Inactive)=(.+)", line)
cargo = re.match("Cargohold=(.+)", line)
misc = re.match(r"(Drones|Implant|Booster)_(Active|Inactive)=(.+)", line)
cargo = re.match(r"Cargohold=(.+)", line)
# 2017/03/27 NOTE: store description from EFT
description = re.match("Description=(.+)", line)
description = re.match(r"Description=(.+)", line)
if misc:
entityType = misc.group(1)
entityState = misc.group(2)
entityData = misc.group(3)
if entityType == "Drones":
droneData = re.match("(.+),([0-9]+)", entityData)
droneData = re.match(r"(.+),([0-9]+)", entityData)
# Get drone name and attempt to detect drone number
droneName = droneData.group(1) if droneData else entityData
droneAmount = int(droneData.group(2)) if droneData else 1
@@ -491,7 +491,7 @@ def importEftCfg(shipname, lines, progress):
fitobj.boosters.append(b)
# If we don't have any prefixes, then it's a module
elif cargo:
cargoData = re.match("(.+),([0-9]+)", cargo.group(1))
cargoData = re.match(r"(.+),([0-9]+)", cargo.group(1))
cargoName = cargoData.group(1) if cargoData else cargo.group(1)
cargoAmount = int(cargoData.group(2)) if cargoData else 1
# Bail if we can't get item
@@ -510,7 +510,7 @@ def importEftCfg(shipname, lines, progress):
elif description:
fitobj.notes = description.group(1).replace("|", "\n")
else:
withCharge = re.match("(.+),(.+)", line)
withCharge = re.match(r"(.+),(.+)", line)
modName = withCharge.group(1) if withCharge else line
chargeName = withCharge.group(2) if withCharge else None
# If we can't get module item, skip it
@@ -584,7 +584,7 @@ def _importPrepare(lines):
return lines
mutantHeaderPattern = re.compile('^\[(?P<ref>\d+)\](?P<tail>.*)')
mutantHeaderPattern = re.compile(r'^\[(?P<ref>\d+)\](?P<tail>.*)')
def importGetMutationData(lines):
@@ -645,7 +645,7 @@ def _importCreateFit(lines):
"""Create fit and set top-level entity (ship or citadel)."""
fit = Fit()
header = lines.pop(0)
m = re.match('\[(?P<shipType>[^,]+),\s*(?P<fitName>.+)\]', header)
m = re.match(r'\[(?P<shipType>[^,]+),\s*(?P<fitName>.+)\]', header)
if not m:
pyfalog.warning('service.port.eft.importEft: corrupted fit header')
raise EftImportError
@@ -968,7 +968,7 @@ def lineIter(text):
def parseAdditions(text, mutaData=None):
items = []
sMkt = Market.getInstance()
pattern = '^(?P<typeName>{}+?)( x(?P<amount>\d+?))?(\s*\[(?P<mutaref>\d+?)\])?$'.format(NAME_CHARS)
pattern = r'^(?P<typeName>{}+?)( x(?P<amount>\d+?))?(\s*\[(?P<mutaref>\d+?)\])?$'.format(NAME_CHARS)
for line in lineIter(text):
m = re.match(pattern, line)
if not m:
@@ -991,7 +991,7 @@ def isValidDroneImport(text):
lines = list(lineIter(text))
mutaData = importGetMutationData(lines)
text = '\n'.join(lines)
pattern = 'x\d+(\s*\[\d+\])?$'
pattern = r'x\d+(\s*\[\d+\])?$'
for line in lineIter(text):
if not re.search(pattern, line):
return False, ()
@@ -1005,7 +1005,7 @@ def isValidDroneImport(text):
def isValidFighterImport(text):
pattern = 'x\d+$'
pattern = r'x\d+$'
for line in lineIter(text):
if not re.search(pattern, line):
return False, ()
@@ -1019,7 +1019,7 @@ def isValidFighterImport(text):
def isValidCargoImport(text):
pattern = 'x\d+$'
pattern = r'x\d+$'
for line in lineIter(text):
if not re.search(pattern, line):
return False, ()
@@ -1033,7 +1033,7 @@ def isValidCargoImport(text):
def isValidImplantImport(text):
pattern = 'x\d+$'
pattern = r'x\d+$'
for line in lineIter(text):
if re.search(pattern, line):
return False, ()
@@ -1047,7 +1047,7 @@ def isValidImplantImport(text):
def isValidBoosterImport(text):
pattern = 'x\d+$'
pattern = r'x\d+$'
for line in lineIter(text):
if re.search(pattern, line):
return False, ()

View File

@@ -231,21 +231,21 @@ class Port:
# If we've got source file name which is used to describe ship name
# and first line contains something like [setup name], detect as eft config file
if re.match("^\s*\[.*\]", firstLine) and path is not None:
if re.match(r"^\s*\[.*\]", firstLine) and path is not None:
filename = os.path.split(path)[1]
shipName = filename.rsplit('.')[0]
return "EFT Config", True, cls.importEftCfg(shipName, lines, progress)
# If no file is specified and there's comma between brackets,
# consider that we have [ship, setup name] and detect like eft export format
if re.match("^\s*\[.*,.*\]", firstLine):
if re.match(r"^\s*\[.*,.*\]", firstLine):
return "EFT", True, (cls.importEft(lines),)
# Check if string is in DNA format
dnaPattern = "\d+(:\d+(;\d+))*::"
dnaPattern = r"\d+(:\d+(;\d+))*::"
if re.match(dnaPattern, firstLine):
return "DNA", True, (cls.importDna(string),)
dnaChatPattern = "<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format(dnaPattern)
dnaChatPattern = r"<url=fitting:(?P<dna>{})>(?P<fitName>[^<>]+)</url>".format(dnaPattern)
m = re.search(dnaChatPattern, firstLine)
if m:
return "DNA", True, (cls.importDna(m.group("dna"), fitName=m.group("fitName")),)

View File

@@ -55,7 +55,7 @@ def version_precheck():
try:
import sqlalchemy
saMatch = re.match("([0-9]+).([0-9]+).([0-9]+)(([b\.])([0-9]+))?", sqlalchemy.__version__)
saMatch = re.match(r"([0-9]+).([0-9]+).([0-9]+)(([b\.])([0-9]+))?", sqlalchemy.__version__)
version_block += "\nSQLAlchemy version: {}".format(sqlalchemy.__version__)
if (int(saMatch.group(1)), int(saMatch.group(2)), int(saMatch.group(3))) < (1, 0, 5):