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

@@ -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):