Skip to content

Commit 2d835fb

Browse files
committedAug 1, 2014
[processing] replace str() with unicode() to avoid possible issues with
non-ASCII characters (work in progress)
1 parent 3480ef2 commit 2d835fb

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed
 

‎python/plugins/processing/algs/gdal/OgrAlgorithm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ def ogrConnectionString(self, uri):
5454
if provider == 'spatialite':
5555
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=
5656
regex = re.compile("dbname='(.+)'")
57-
r = regex.search(str(layer.source()))
57+
r = regex.search(unicode(layer.source()))
5858
ogrstr = r.groups()[0]
5959
elif provider == 'postgres':
6060
# dbname='ktryjh_iuuqef' host=spacialdb.com port=9999
6161
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
6262
# key='gid' estimatedmetadata=true srid=4326 type=MULTIPOLYGON
6363
# table="t4" (geom) sql=
64-
s = re.sub(''' sslmode=.+''', '', str(layer.source()))
64+
s = re.sub(''' sslmode=.+''', '', unicode(layer.source()))
6565
ogrstr = 'PG:%s' % s
6666
else:
67-
ogrstr = str(layer.source())
67+
ogrstr = unicode(layer.source())
6868
return ogrstr

‎python/plugins/processing/core/outputs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, name='', description='', hidden=False):
5353
# in a vector layer). In the case of layers, hidden outputs are
5454
# not loaded into QGIS after the algorithm is executed. Other
5555
# outputs not representing layers or tables should always be hidden.
56-
self.hidden = str(hidden).lower() == str(True).lower()
56+
self.hidden = unicode(hidden).lower() == unicode(True).lower()
5757

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

6565
def getValueAsCommandLineParameter(self):
6666
if self.value is None:
67-
return str(None)
67+
return unicode(None)
6868
else:
6969
if not isWindows():
70-
return '"' + str(self.value) + '"'
70+
return '"' + unicode(self.value) + '"'
7171
else:
72-
return '"' + str(self.value).replace('\\', '\\\\') + '"'
72+
return '"' + unicode(self.value).replace('\\', '\\\\') + '"'
7373

7474
def setValue(self, value):
7575
try:
@@ -99,7 +99,7 @@ def setValue(self, value):
9999
if value is not None and isinstance(value, basestring):
100100
value = value.strip()
101101
else:
102-
self.value = ','.join([str(v) for v in value])
102+
self.value = ','.join([unicode(v) for v in value])
103103
return True
104104
except:
105105
return False
@@ -292,4 +292,4 @@ def getVectorWriter(self, fields, geomType, crs, options=None):
292292
w = VectorWriter(self.value, self.encoding, fields, geomType,
293293
crs, options)
294294
self.memoryLayer = w.memLayer
295-
return w
295+
return w

‎python/plugins/processing/core/parameters.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def getParameterFromString(s):
3939
return clazz(*params)
4040

4141
def parseBool(s):
42-
if s == str(None):
42+
if s == unicode(None):
4343
return None
44-
return str(s).lower() == str(True).lower()
44+
return unicode(s).lower() == unicode(True).lower()
4545

4646

4747
class Parameter:
@@ -69,7 +69,7 @@ def setValue(self, obj):
6969
Returns true if the value passed is correct for the type
7070
of parameter.
7171
"""
72-
self.value = str(obj)
72+
self.value = unicode(obj)
7373
return True
7474

7575
def __str__(self):
@@ -81,7 +81,7 @@ def getValueAsCommandLineParameter(self):
8181
entered in the console if calling an algorithm using the
8282
Processing.runalg() method.
8383
"""
84-
return str(self.value)
84+
return unicode(self.value)
8585

8686
def parameterName(self):
8787
return self.__module__.split('.')[-1]
@@ -102,7 +102,7 @@ def setValue(self, value):
102102
self.value = self.default
103103
return True
104104
if isinstance(value, basestring):
105-
self.value = str(value).lower() == str(True).lower()
105+
self.value = unicode(value).lower() == unicode(True).lower()
106106
else:
107107
self.value = bool(value)
108108
return True
@@ -122,18 +122,18 @@ def setValue(self, value):
122122
return True
123123

124124
# TODO: check it is a valid authid
125-
self.value = str(value)
125+
self.value = unicode(value)
126126
return True
127127

128128
def getValueAsCommandLineParameter(self):
129-
return '"' + str(self.value) + '"'
129+
return '"' + unicode(self.value) + '"'
130130

131131

132132
class ParameterDataObject(Parameter):
133133

134134
def getValueAsCommandLineParameter(self):
135135
if self.value is None:
136-
return str(None)
136+
return unicode(None)
137137
else:
138138
if not isWindows():
139139
return '"' + unicode(self.value) + '"'
@@ -168,7 +168,7 @@ def setValue(self, text):
168168
return False
169169

170170
def getValueAsCommandLineParameter(self):
171-
return '"' + str(self.value) + '"'
171+
return '"' + unicode(self.value) + '"'
172172

173173
class ParameterFile(Parameter):
174174

@@ -214,7 +214,7 @@ def setValue(self, obj):
214214
return True
215215

216216
def getValueAsCommandLineParameter(self):
217-
return '"' + str(self.value) + '"'
217+
return '"' + unicode(self.value) + '"'
218218

219219
@staticmethod
220220
def tableToString(table):
@@ -362,7 +362,7 @@ def __init__(self, name='', description='', minValue=None, maxValue=None,
362362
default=0.0):
363363
Parameter.__init__(self, name, description)
364364
try:
365-
self.default = int(str(default))
365+
self.default = int(unicode(default))
366366
self.isInteger = True
367367
except:
368368
self.default = float(default)
@@ -415,7 +415,7 @@ def setValue(self, text):
415415
return False
416416

417417
def getValueAsCommandLineParameter(self):
418-
return '"' + str(self.value) + '"'
418+
return '"' + unicode(self.value) + '"'
419419

420420

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

2 commit comments

Comments
 (2)

PedroVenancio commented on Aug 7, 2014

@PedroVenancio
Contributor

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 commented on Aug 7, 2014

@alexbruy
ContributorAuthor

Thanks for feedback, will look at this

Please sign in to comment.