Skip to content

Commit

Permalink
[processing] replace str() with unicode() to avoid possible issues with
Browse files Browse the repository at this point in the history
non-ASCII characters (work in progress)
  • Loading branch information
alexbruy committed Aug 1, 2014
1 parent 3480ef2 commit 2d835fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/gdal/OgrAlgorithm.py
Expand Up @@ -54,15 +54,15 @@ def ogrConnectionString(self, uri):
if provider == 'spatialite':
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=
regex = re.compile("dbname='(.+)'")
r = regex.search(str(layer.source()))
r = regex.search(unicode(layer.source()))
ogrstr = r.groups()[0]
elif provider == 'postgres':
# dbname='ktryjh_iuuqef' host=spacialdb.com port=9999
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
# key='gid' estimatedmetadata=true srid=4326 type=MULTIPOLYGON
# table="t4" (geom) sql=
s = re.sub(''' sslmode=.+''', '', str(layer.source()))
s = re.sub(''' sslmode=.+''', '', unicode(layer.source()))
ogrstr = 'PG:%s' % s
else:
ogrstr = str(layer.source())
ogrstr = unicode(layer.source())
return ogrstr
12 changes: 6 additions & 6 deletions python/plugins/processing/core/outputs.py
Expand Up @@ -53,7 +53,7 @@ def __init__(self, name='', description='', hidden=False):
# in a vector layer). In the case of layers, hidden outputs are
# not loaded into QGIS after the algorithm is executed. Other
# outputs not representing layers or tables should always be hidden.
self.hidden = str(hidden).lower() == str(True).lower()
self.hidden = unicode(hidden).lower() == unicode(True).lower()

# This value indicates whether the output has to be opened
# after being produced by the algorithm or not
Expand All @@ -64,12 +64,12 @@ def __str__(self):

def getValueAsCommandLineParameter(self):
if self.value is None:
return str(None)
return unicode(None)
else:
if not isWindows():
return '"' + str(self.value) + '"'
return '"' + unicode(self.value) + '"'
else:
return '"' + str(self.value).replace('\\', '\\\\') + '"'
return '"' + unicode(self.value).replace('\\', '\\\\') + '"'

def setValue(self, value):
try:
Expand Down Expand Up @@ -99,7 +99,7 @@ def setValue(self, value):
if value is not None and isinstance(value, basestring):
value = value.strip()
else:
self.value = ','.join([str(v) for v in value])
self.value = ','.join([unicode(v) for v in value])
return True
except:
return False
Expand Down Expand Up @@ -292,4 +292,4 @@ def getVectorWriter(self, fields, geomType, crs, options=None):
w = VectorWriter(self.value, self.encoding, fields, geomType,
crs, options)
self.memoryLayer = w.memLayer
return w
return w
26 changes: 13 additions & 13 deletions python/plugins/processing/core/parameters.py
Expand Up @@ -39,9 +39,9 @@ def getParameterFromString(s):
return clazz(*params)

def parseBool(s):
if s == str(None):
if s == unicode(None):
return None
return str(s).lower() == str(True).lower()
return unicode(s).lower() == unicode(True).lower()


class Parameter:
Expand Down Expand Up @@ -69,7 +69,7 @@ def setValue(self, obj):
Returns true if the value passed is correct for the type
of parameter.
"""
self.value = str(obj)
self.value = unicode(obj)
return True

def __str__(self):
Expand All @@ -81,7 +81,7 @@ def getValueAsCommandLineParameter(self):
entered in the console if calling an algorithm using the
Processing.runalg() method.
"""
return str(self.value)
return unicode(self.value)

def parameterName(self):
return self.__module__.split('.')[-1]
Expand All @@ -102,7 +102,7 @@ def setValue(self, value):
self.value = self.default
return True
if isinstance(value, basestring):
self.value = str(value).lower() == str(True).lower()
self.value = unicode(value).lower() == unicode(True).lower()
else:
self.value = bool(value)
return True
Expand All @@ -122,18 +122,18 @@ def setValue(self, value):
return True

# TODO: check it is a valid authid
self.value = str(value)
self.value = unicode(value)
return True

def getValueAsCommandLineParameter(self):
return '"' + str(self.value) + '"'
return '"' + unicode(self.value) + '"'


class ParameterDataObject(Parameter):

def getValueAsCommandLineParameter(self):
if self.value is None:
return str(None)
return unicode(None)
else:
if not isWindows():
return '"' + unicode(self.value) + '"'
Expand Down Expand Up @@ -168,7 +168,7 @@ def setValue(self, text):
return False

def getValueAsCommandLineParameter(self):
return '"' + str(self.value) + '"'
return '"' + unicode(self.value) + '"'

class ParameterFile(Parameter):

Expand Down Expand Up @@ -214,7 +214,7 @@ def setValue(self, obj):
return True

def getValueAsCommandLineParameter(self):
return '"' + str(self.value) + '"'
return '"' + unicode(self.value) + '"'

@staticmethod
def tableToString(table):
Expand Down Expand Up @@ -362,7 +362,7 @@ def __init__(self, name='', description='', minValue=None, maxValue=None,
default=0.0):
Parameter.__init__(self, name, description)
try:
self.default = int(str(default))
self.default = int(unicode(default))
self.isInteger = True
except:
self.default = float(default)
Expand Down Expand Up @@ -415,7 +415,7 @@ def setValue(self, text):
return False

def getValueAsCommandLineParameter(self):
return '"' + str(self.value) + '"'
return '"' + unicode(self.value) + '"'


class ParameterRaster(ParameterDataObject):
Expand Down Expand Up @@ -709,4 +709,4 @@ def getFileFilter(self):
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
for i in range(len(exts)):
exts[i] = exts[i].upper() + ' files(*.' + exts[i].lower() + ')'
return ';;'.join(exts)
return ';;'.join(exts)

2 comments on commit 2d835fb

@PedroVenancio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Alexander,

These changes do not fix the problem completely.

On Linux, everything ok.

On windows, the problem persists:

Uncaught error while executing algorithm
Traceback (most recent call last):
Traceback (most recent call last):
File "C:/OSGEO41/apps/qgis-dev/./python/plugins\processing\core\GeoAlgorithm.py", line 212, in execute
self.processAlgorithm(progress)
File "C:/Users/win7/.qgis2/python/plugins\processing_pttransform\UTM29NED50ToETR89PTTM06_Raster.py", line 77, in processAlgorithm
progress)
File "C:/OSGEO4
1/apps/qgis-dev/./python/plugins\processing\algs\gdal\GdalUtils.py", line 78, in runGdal
universal_newlines=False,
File "C:\OSGEO41\apps\Python27\lib\subprocess.py", line 711, in init
errread, errwrite)
File "C:\OSGEO4
1\apps\Python27\lib\subprocess.py", line 922, in _execute_child
args = '{} /c "{}"'.format (comspec, args)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 237: ordinal not in range(128)

@alexbruy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for feedback, will look at this

Please sign in to comment.