Skip to content

Commit

Permalink
Fix escaping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 5, 2020
1 parent d1a4923 commit a5f557f
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 28 deletions.
4 changes: 2 additions & 2 deletions ms-windows/mxe/deploy.py
Expand Up @@ -67,7 +67,7 @@ def library_install_exe(out=''):
out = run_check().splitlines()
for line in out:
# err = re.search('(err:module:import_dll (Library |Loading library)) (.*?\.dll) ', line)
err = re.search('([^ ]+\.dll) \(which', line)
err = re.search(r'([^ ]+\.dll) \(which', line)
if err is not None:

dll = err.group(1)
Expand Down Expand Up @@ -98,7 +98,7 @@ def library_install_objdump(path, level):

done.append(path)

command = objdump_path + " -p " + lib + " | grep -o ': .*\.dll$'"
command = objdump_path + " -p " + lib + " | grep -o ': .*\\.dll$'"
res = subprocess.getstatusoutput(command)
if (res[0] > 0):
print("Error: objdump failed with " + lib)
Expand Down
2 changes: 1 addition & 1 deletion python/core/additions/qgsfunction.py
Expand Up @@ -134,7 +134,7 @@ def handlesNull(self):


def qgsfunction(args='auto', group='custom', **kwargs):
"""
r"""
Decorator function used to define a user expression function.
:param args: Number of parameters, set to 'auto' to accept a variable length of parameters.
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/grass7/Grass7Utils.py
Expand Up @@ -189,7 +189,7 @@ def searchFolder(folder):

if command:
Grass7Utils.command = command
if path is '':
if path == '':
Grass7Utils.path = os.path.dirname(command)

return command
Expand Down
Expand Up @@ -103,7 +103,7 @@ def processAlgorithm(self, parameters, context, feedback):

databaseuri = database.dataProvider().dataSourceUri()
uri = QgsDataSourceUri(databaseuri)
if uri.database() is '':
if uri.database() == '':
if '|layername' in databaseuri:
databaseuri = databaseuri[:databaseuri.find('|layername')]
elif '|layerid' in databaseuri:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/RasterCalculator.py
Expand Up @@ -197,7 +197,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
for i in list(model.inputs.values()):
param = i.param
if isinstance(param, QgsProcessingParameterRasterLayer) and "{}@".format(param.name) in expression:
values.append(ValueFromInput(param.name()))
values.append(ValueFromInput(param.name())) # noqa TODO: how is that supposed to work??

if algorithm.name:
dependent = model.getDependentAlgorithms(algorithm.name)
Expand All @@ -208,7 +208,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
for out in alg.algorithm.outputs:
if (isinstance(out, QgsProcessingOutputRasterLayer) and
"{}:{}@".format(alg.modeler_name, out.name) in expression):
values.append(ValueFromOutput(alg.modeler_name, out.name))
values.append(ValueFromOutput(alg.modeler_name, out.name)) # noqa TODO: how is that supposed to work??

algorithm.params[self.LAYERS] = values

Expand Down
Expand Up @@ -67,7 +67,7 @@ def processAlgorithm(self, parameters, context, feedback):
database = self.parameterAsVectorLayer(parameters, self.DATABASE, context)
databaseuri = database.dataProvider().dataSourceUri()
uri = QgsDataSourceUri(databaseuri)
if uri.database() is '':
if uri.database() == '':
if '|layername' in databaseuri:
databaseuri = databaseuri[:databaseuri.find('|layername')]
elif '|layerid' in databaseuri:
Expand Down
Expand Up @@ -71,7 +71,7 @@ def accept(self):
QgsApplication.processingRegistry().providerById('preconfigured').refreshAlgorithms()
except AlgorithmDialogBase.InvalidParameterValue as e:
try:
self.buttonBox().accepted.connect(lambda: e.widget.setPalette(QPalette()))
self.buttonBox().accepted.connect(lambda: e.widget.setPalette(QPalette())) # noqa do not ask me why
palette = e.widget.palette()
palette.setColor(QPalette.Base, QColor(255, 255, 0))
e.widget.setPalette(palette)
Expand Down
46 changes: 45 additions & 1 deletion python/plugins/processing/tests/GuiTest.py
Expand Up @@ -21,6 +21,7 @@
__date__ = 'August 2017'
__copyright__ = '(C) 2017, Nyall Dawson'

import os
from qgis.testing import start_app, unittest
from qgis.core import (QgsApplication,
QgsCoordinateReferenceSystem,
Expand All @@ -41,7 +42,50 @@
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
from processing.gui.wrappers import * # noqa
from processing.gui.wrappers import (
BandWidgetWrapper,
BooleanWidgetWrapper,
CrsWidgetWrapper,
DistanceWidgetWrapper,
EnumWidgetWrapper,
ExpressionWidgetWrapper,
ExtentWidgetWrapper,
FeatureSourceWidgetWrapper,
FileWidgetWrapper,
FixedTableWidgetWrapper,
MapLayerWidgetWrapper,
MeshWidgetWrapper,
MultipleLayerWidgetWrapper,
NumberWidgetWrapper,
PointWidgetWrapper,
ProcessingConfig,
QgsProcessingFeatureSourceDefinition,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
QgsProcessingParameterCrs,
QgsProcessingParameterDistance,
QgsProcessingParameterEnum,
QgsProcessingParameterExpression,
QgsProcessingParameterExtent,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFile,
QgsProcessingParameterMapLayer,
QgsProcessingParameterMeshLayer,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterNumber,
QgsProcessingParameterPoint,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterString,
QgsProcessingParameterVectorLayer,
QgsVectorLayer,
RangeWidgetWrapper,
RasterWidgetWrapper,
StringWidgetWrapper,
TableFieldWidgetWrapper,
VectorLayerWidgetWrapper,
WidgetWrapperFactory,
)

start_app()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_authmanager_ogr.py
Expand Up @@ -41,7 +41,7 @@
'IDB:"server=demo_on user=informix dbname=frames authcfg=\'%s\'"': 'IDB:"server=demo_on user=informix dbname=frames user=username pass=password"',
'@driver=ingres,dbname=test,tables=usa/canada authcfg=\'%s\'': '@driver=ingres,dbname=test,tables=usa/canada,userid=username,password=password',
'MySQL:westholland,port=3306,tables=bedrijven authcfg=\'%s\'': 'MySQL:westholland,port=3306,tables=bedrijven,user=username,password=password',
'MSSQL:server=.\MSSQLSERVER2008;database=dbname;trusted_connection=yes authcfg=\'%s\'': 'MSSQL:server=.\MSSQLSERVER2008;database=dbname;uid=username;pwd=password',
'MSSQL:server=.\\MSSQLSERVER2008;database=dbname;trusted_connection=yes authcfg=\'%s\'': 'MSSQL:server=.\\MSSQLSERVER2008;database=dbname;uid=username;pwd=password',
'OCI:/@database_instance:table,table authcfg=\'%s\'': 'OCI:username/password@database_instance:table,table',
'ODBC:database_instance authcfg=\'%s\'': 'ODBC:username/password@database_instance',
'couchdb://myconnection authcfg=\'%s\'': 'couchdb://username:password@myconnection',
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_authmanager_pki_ows.py
Expand Up @@ -129,7 +129,7 @@ def setUpClass(cls):
cls.server = subprocess.Popen([sys.executable, server_path],
env=os.environ, stdout=subprocess.PIPE)
line = cls.server.stdout.readline()
cls.port = int(re.findall(b':(\d+)', line)[0])
cls.port = int(re.findall(br':(\d+)', line)[0])
assert cls.port != 0
# Wait for the server process to start
assert waitServer('%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)), "Server is not responding! %s://%s:%s" % (cls.protocol, cls.hostname, cls.port)
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_offline_editing_wfs.py
Expand Up @@ -97,7 +97,7 @@ def setUp(self):
self.server = subprocess.Popen([sys.executable, self.server_path],
env=os.environ, stdout=subprocess.PIPE)
line = self.server.stdout.readline()
self.port = int(re.findall(b':(\d+)', line)[0])
self.port = int(re.findall(br':(\d+)', line)[0])
assert self.port != 0
# Wait for the server process to start
assert waitServer('http://127.0.0.1:%s' % self.port), "Server is not responding!"
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsappstartup.py
Expand Up @@ -132,7 +132,7 @@ def testPyQgisStartupEnvVar(self):
# internal binary will match, minus the '.app'
found = False
for app_path in glob.glob(d + '/QGIS*.app'):
m = re.search('/(QGIS(_\d\.\d-dev)?)\.app', app_path)
m = re.search(r'/(QGIS(_\d\.\d-dev)?)\.app', app_path)
if m:
QGIS_BIN = app_path + '/Contents/MacOS/' + m.group(1)
found = True
Expand Down
10 changes: 5 additions & 5 deletions tests/src/python/test_qgsserver.py
Expand Up @@ -51,9 +51,9 @@


# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
RE_ELEMENT = b'</*([^>\[\s]+)[ >]'
RE_ELEMENT_CONTENT = b'<[^>\[]+>(.+)</[^>\[\s]+>'
RE_STRIP_UNCHECKABLE = rb'MAP=[^"]+|Content-Length: \d+'
RE_ELEMENT = br'</*([^>\[\s]+)[ >]'
RE_ELEMENT_CONTENT = br'<[^>\[]+>(.+)</[^>\[\s]+>'
RE_ATTRIBUTES = rb'((?:(?!\s|=).)*)\s*?=\s*?["\']?((?:(?<=")(?:(?<=\\)"|[^"])*|(?<=\')(?:(?<=\\)\'|[^\'])*)|(?:(?!"|\')(?:(?!\/>|>|\s).)+))'


Expand All @@ -78,7 +78,7 @@ def assertXMLEqual(self, response, expected, msg=''):
for expected_line in expected_lines:
expected_line = expected_line.strip()
response_line = response_lines[line_no - 1].strip()
response_line = response_line.replace(b'e+6', b'e+06')
response_line = response_line.replace(b'e+6', br'e+06')
# Compare tag
if re.match(RE_ELEMENT, expected_line):
expected_elements = re.findall(RE_ELEMENT, expected_line)
Expand Down Expand Up @@ -139,7 +139,7 @@ def setUp(self):

def strip_version_xmlns(self, text):
"""Order of attributes is random, strip version and xmlns"""
return text.replace(b'version="1.3.0"', b'').replace(b'xmlns="http://www.opengis.net/ogc"', b'')
return text.replace(br'version="1.3.0"', r'').replace(br'xmlns="http://www.opengis.net/ogc"', b'')

def assert_headers(self, header, body):
stream = StringIO()
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsserver_plugins.py
Expand Up @@ -27,8 +27,8 @@


# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
RE_STRIP_UNCHECKABLE = br'MAP=[^"]+|Content-Length: \d+'
RE_ATTRIBUTES = br'[^>\s]+=[^>\s]+'


class TestQgsServerPlugins(QgsServerTestBase):
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsserver_wms_getmap.py
Expand Up @@ -34,8 +34,8 @@
from qgis.core import QgsProject

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
RE_STRIP_UNCHECKABLE = br'MAP=[^"]+|Content-Length: \d+'
RE_ATTRIBUTES = br'[^>\s]+=[^>\s]+'


class TestQgsServerWMSGetMap(QgsServerTestBase):
Expand Down
Expand Up @@ -36,8 +36,8 @@
from qgis.core import QgsProject, QgsApplication

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
RE_STRIP_UNCHECKABLE = br'MAP=[^"]+|Content-Length: \d+'
RE_ATTRIBUTES = br'[^>\s]+=[^>\s]+'


class TestQgsServerWMSGetMapIgnoreBadLayers(QgsServerTestBase):
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgsserver_wmts.py
Expand Up @@ -35,8 +35,8 @@
from qgis.core import QgsProject

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+|timeStamp="[^"]+"'
RE_ATTRIBUTES = b'[^>\s]+=[^>\s]+'
RE_STRIP_UNCHECKABLE = br'MAP=[^"]+|Content-Length: \d+|timeStamp="[^"]+"'
RE_ATTRIBUTES = br'[^>\s]+=[^>\s]+'


class TestQgsServerWMTS(QgsServerTestBase):
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/utilities.py
Expand Up @@ -318,7 +318,7 @@ def printImportant(info):


def waitServer(url, timeout=10):
""" Wait for a server to be online and to respond
r""" Wait for a server to be online and to respond
HTTP errors are ignored
\param timeout: in seconds
\return: True of False
Expand Down

0 comments on commit a5f557f

Please sign in to comment.