Skip to content
Permalink
Browse files

Fix escaping issues

  • Loading branch information
m-kuhn committed May 5, 2020
1 parent d1a4923 commit a5f557f08578dae3f025edadd7f6abc4c8aa0dbd
@@ -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)
@@ -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)
@@ -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.
@@ -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
@@ -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:
@@ -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)
@@ -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

@@ -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:
@@ -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)
@@ -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,
@@ -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())
@@ -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',
@@ -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)
@@ -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!"
@@ -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
@@ -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).)+))'


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

0 comments on commit a5f557f

Please sign in to comment.
You can’t perform that action at this time.