Skip to content
Permalink
Browse files

[processing] replace str() with unicode() to avoid possible issues with

non-ASCII characters (work in progress)
  • Loading branch information
alexbruy committed Jul 30, 2014
1 parent 3480ef2 commit 2d835fbae06d0de31e3d9544544b3a2bc47e809f
@@ -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
@@ -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
@@ -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:
@@ -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
@@ -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
@@ -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:
@@ -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):
@@ -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]
@@ -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
@@ -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) + '"'
@@ -168,7 +168,7 @@ def setValue(self, text):
return False

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

class ParameterFile(Parameter):

@@ -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):
@@ -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)
@@ -415,7 +415,7 @@ def setValue(self, text):
return False

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


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

This comment has been minimized.

Copy link
Contributor

@PedroVenancio PedroVenancio replied Aug 7, 2014

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

This comment has been minimized.

Copy link
Contributor Author

@alexbruy alexbruy replied Aug 7, 2014

Thanks for feedback, will look at this

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