Skip to content

Commit

Permalink
fix double string encoding with EncodeString()
Browse files Browse the repository at this point in the history
  • Loading branch information
pesekon2 authored and petrasovaa committed Dec 6, 2019
1 parent 86b2e80 commit cf6c2e6
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 67 deletions.
3 changes: 0 additions & 3 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ class Popen(subprocess.Popen):

def __init__(self, args, **kwargs):
if is_mswindows:
# encoding not needed for Python3
# args = list(map(EncodeString, args))

# The Windows shell (cmd.exe) requires some special characters to
# be escaped by preceding them with 3 carets (^^^). cmd.exe /?
# mentions <space> and &()[]{}^=;!'+,`~. A quick test revealed that
Expand Down
11 changes: 4 additions & 7 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from core import utils
from core.ws import RenderWMSMgr
from core.gcmd import GException, GError, RunCommand, EncodeString
from core.gcmd import GException, GError, RunCommand
from core.debug import Debug
from core.settings import UserSettings
from core.gthread import gThread
Expand Down Expand Up @@ -1297,8 +1297,7 @@ def AddLayer(self, ltype, command, name=None,
renderMgr = layer.GetRenderMgr()
Debug.msg(
1, "Map.AddLayer(): ltype={0}, command={1}".format(
ltype, EncodeString(layer.GetCmd(
string=True))))
ltype, layer.GetCmd(string=True)))
if renderMgr:
if layer.type == 'wms':
renderMgr.dataFetched.connect(self.renderMgr.ReportProgress)
Expand Down Expand Up @@ -1360,7 +1359,7 @@ def DeleteLayer(self, layer, overlay=False):

def SetLayers(self, layers):
self.layers = layers
Debug.msg(5, "Map.SetLayers(): layers={0}".format([EncodeString(layer.GetCmd(string=True)) for layer in layers]))
Debug.msg(5, "Map.SetLayers(): layers={0}".format([layer.GetCmd(string=True) for layer in layers]))

def ChangeLayer(self, layer, render=False, **kargs):
"""Change map layer properties
Expand Down Expand Up @@ -1510,9 +1509,7 @@ def AddOverlay(self, id, ltype, command,

renderMgr = overlay.GetRenderMgr()
Debug.msg(
1, "Map.AddOverlay(): cmd={0}".format(EncodeString(
overlay.GetCmd(
string=True))))
1, "Map.AddOverlay(): cmd={0}".format(overlay.GetCmd(string=True)))
if renderMgr:
renderMgr.updateProgress.connect(self.renderMgr.ReportProgress)
renderMgr.renderingFailed.connect(self.renderMgr.RenderingFailed)
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from core.render import Map
from gui_core.gselect import Select, LocationSelect, MapsetSelect
from gui_core.dialogs import GroupDialog
from core.gcmd import RunCommand, GMessage, GError, GWarning, EncodeString
from core.gcmd import RunCommand, GMessage, GError, GWarning
from core.settings import UserSettings
from gcp.mapdisplay import MapFrame
from core.giface import Notification
Expand Down Expand Up @@ -296,7 +296,7 @@ def SetSrcEnv(self, location, mapset):
self.gisrc_dict['LOCATION_NAME'] = location
self.gisrc_dict['MAPSET'] = mapset

self.source_gisrc = EncodeString(utils.GetTempfile())
self.source_gisrc = utils.GetTempfile()

try:
f = open(self.source_gisrc, mode='w')
Expand Down
7 changes: 2 additions & 5 deletions gui/wxpython/gmodeler/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from core import globalvar
from core import utils
from gui_core.widgets import SearchModuleWidget, SimpleValidator
from core.gcmd import GError, EncodeString
from core.gcmd import GError
from gui_core.dialogs import SimpleDialog, MapLayersDialogForModeler
from gui_core.prompt import GPromptSTC
from gui_core.gselect import Select, ElementSelect
Expand Down Expand Up @@ -274,10 +274,7 @@ def _getCmd(self):
if len(line) == 0:
cmd = list()
else:
try:
cmd = utils.split(str(line))
except UnicodeError:
cmd = utils.split(EncodeString((line)))
cmd = utils.split(str(line))
return cmd

def GetCmd(self):
Expand Down
46 changes: 19 additions & 27 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

from core import globalvar
from core import utils
from core.gcmd import GMessage, GException, GError, RunCommand, EncodeString, GWarning, GetDefaultEncoding
from core.gcmd import GMessage, GException, GError, RunCommand, GWarning, GetDefaultEncoding
from core.settings import UserSettings
from gui_core.forms import GUI, CmdPanel
from gui_core.widgets import GNotebook
Expand Down Expand Up @@ -2249,22 +2249,19 @@ def _properties(self):
'%s<name>%s</name>\n' %
(' ' *
self.indent,
EncodeString(
self.properties['name'])))
self.properties['name']))
if self.properties['description']:
self.fd.write(
'%s<description>%s</description>\n' %
(' ' *
self.indent,
EncodeString(
self.properties['description'])))
self.properties['description']))
if self.properties['author']:
self.fd.write(
'%s<author>%s</author>\n' %
(' ' *
self.indent,
EncodeString(
self.properties['author'])))
self.properties['author']))

if 'overwrite' in self.properties and \
self.properties['overwrite']:
Expand All @@ -2283,15 +2280,15 @@ def _variables(self):
for name, values in six.iteritems(self.variables):
self.fd.write(
'%s<variable name="%s" type="%s">\n' %
(' ' * self.indent, EncodeString(name), values['type']))
(' ' * self.indent, name, values['type']))
self.indent += 4
if 'value' in values:
self.fd.write('%s<value>%s</value>\n' %
(' ' * self.indent, EncodeString(values['value'])))
(' ' * self.indent, values['value']))
if 'description' in values:
self.fd.write(
'%s<description>%s</description>\n' %
(' ' * self.indent, EncodeString(values['description'])))
(' ' * self.indent, values['description']))
self.indent -= 4
self.fd.write('%s</variable>\n' % (' ' * self.indent))
self.indent -= 4
Expand All @@ -2313,21 +2310,19 @@ def _action(self, action):
"""Write actions"""
self.fd.write(
'%s<action id="%d" name="%s" pos="%d,%d" size="%d,%d">\n' %
(' ' *
self.indent,
(' ' * self.indent,
action.GetId(),
EncodeString(
action.GetLabel()),
action.GetX(),
action.GetY(),
action.GetWidth(),
action.GetHeight()))
action.GetLabel(),
action.GetX(),
action.GetY(),
action.GetWidth(),
action.GetHeight()))
self.indent += 4
comment = action.GetComment()
if comment:
self.fd.write(
'%s<comment>%s</comment>\n' %
(' ' * self.indent, EncodeString(comment)))
(' ' * self.indent, comment))
self.fd.write('%s<task name="%s">\n' %
(' ' * self.indent, action.GetLog(string=False)[0]))
self.indent += 4
Expand Down Expand Up @@ -2503,8 +2498,7 @@ def _comment(self, comment):
comment.GetY(),
comment.GetWidth(),
comment.GetHeight(),
EncodeString(
comment.GetLabel())))
comment.GetLabel()))


class WritePythonFile:
Expand Down Expand Up @@ -2556,10 +2550,9 @@ def _writePython(self):
#
#{header_end}
""".format(header_begin='#' * 77,
module_name=EncodeString(properties['name']),
author=EncodeString(properties['author']),
purpose=EncodeString(
'\n# '.join(properties['description'].splitlines())),
module_name=properties['name'],
author=properties['author'],
purpose='\n# '.join(properties['description'].splitlines()),
date=time.asctime(),
header_end='#' * 77))

Expand All @@ -2569,8 +2562,7 @@ def _writePython(self):
#%module
#% description: {description}
#%end
""".format(description=EncodeString(
' '.join(properties['description'].splitlines()))))
""".format(description=' '.join(properties['description'].splitlines())))

modelItems = self.model.GetItems()
for item in modelItems:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/goutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def OnOutputSave(self, event):

try:
output = open(path, "w")
output.write(EncodeString(text))
output.write(text)
except IOError as e:
GError(
_("Unable to write file '%(path)s'.\n\nDetails: %(error)s") % {
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/gui_core/pyedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from grass.script.setup import set_gui_path
set_gui_path()

from core.gcmd import EncodeString, GError
from core.gcmd import GError
from gui_core.pystc import PyStc
from core import globalvar
from core.menutree import MenuTreeModelBuilder
Expand Down Expand Up @@ -89,9 +89,9 @@ def module_template():
#
#%s
""" % ('#' * 72,
EncodeString(properties['name']),
EncodeString(properties['author']),
EncodeString('\n# '.join(properties['description'].splitlines())),
properties['name'],
properties['author'],
'\n# '.join(properties['description'].splitlines()),
time.asctime(),
'#' * 72))

Expand All @@ -101,7 +101,7 @@ def module_template():
#%%module
#%% description: %s
#%%end
""" % (EncodeString(' '.join(properties['description'].splitlines()))))
""" % (' '.join(properties['description'].splitlines())))

# import modules
output.write(
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from core.render import Map
from gui_core.gselect import Select, LocationSelect, MapsetSelect
from gui_core.dialogs import GroupDialog
from core.gcmd import RunCommand, GMessage, GError, GWarning, EncodeString
from core.gcmd import RunCommand, GMessage, GError, GWarning
from core.settings import UserSettings
from gcp.mapdisplay import MapFrame
from core.giface import Notification
Expand Down Expand Up @@ -323,7 +323,7 @@ def SetSrcEnv(self, location, mapset):
self.gisrc_dict['LOCATION_NAME'] = location
self.gisrc_dict['MAPSET'] = mapset

self.source_gisrc = EncodeString(utils.GetTempfile())
self.source_gisrc = utils.GetTempfile()

try:
f = open(self.source_gisrc, mode='w')
Expand Down
13 changes: 2 additions & 11 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from grass.script import core as grass
from grass.script.utils import decode

from core.gcmd import RunCommand, GError, GMessage, EncodeString
from core.gcmd import RunCommand, GError, GMessage
from core.settings import UserSettings, GetDisplayVectSettings
from core.utils import SetAddOnPath, GetLayerNameFromCmd, command2ltype
from gui_core.preferences import MapsetAccess, PreferencesDialog
Expand Down Expand Up @@ -976,15 +976,6 @@ def OnRunScript(self, event):

if not filename:
return False
try:
filename_encoded = EncodeString(filename)
except UnicodeEncodeError:
GError(
parent=self, message=_(
"Due to the limitations of your operating system, "
"the script path cannot contain certain non-ascii characters. "
"Please rename the script or move it to a different location."))
return

if not os.path.exists(filename):
GError(parent=self,
Expand Down Expand Up @@ -1020,7 +1011,7 @@ def OnRunScript(self, event):
addonPath = os.getenv('GRASS_ADDON_PATH', [])
if addonPath:
addonPath = addonPath.split(os.pathsep)
dirName = os.path.dirname(filename_encoded)
dirName = os.path.dirname(filename)
if dirName not in addonPath:
addonPath.append(dirName)
dlg = wx.MessageDialog(
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/nviz/wxnviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

from core.debug import Debug
from core.utils import autoCropImageFromFile
from core.gcmd import EncodeString, DecodeString
from core.gcmd import DecodeString
from core.globalvar import wxPythonPhoenix
from gui_core.wrap import Rect
import grass.script as grass
Expand Down Expand Up @@ -1847,7 +1847,6 @@ def SaveToFile(self, filename, width=20, height=20, itype='ppm'):
"""
widthOrig = self.width
heightOrig = self.height
filename = EncodeString(filename)

self.ResizeWindow(width, height)
GS_clear(Nviz_get_bgcolor(self.data))
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from core.render import Map
from gui_core.gselect import Select, LocationSelect, MapsetSelect
from gui_core.dialogs import GroupDialog
from core.gcmd import RunCommand, GMessage, GError, GWarning, EncodeString
from core.gcmd import RunCommand, GMessage, GError, GWarning
from core.settings import UserSettings
from photo2image.ip2i_mapdisplay import MapFrame
from core.giface import Notification
Expand Down Expand Up @@ -235,7 +235,7 @@ def SetSrcEnv(self, location, mapset):
self.gisrc_dict['LOCATION_NAME'] = location
self.gisrc_dict['MAPSET'] = mapset

self.source_gisrc = EncodeString(utils.GetTempfile())
self.source_gisrc = utils.GetTempfile()

try:
f = open(self.source_gisrc, mode='w')
Expand Down

0 comments on commit cf6c2e6

Please sign in to comment.