Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,7 @@ def GetDefaultEncoding(forceUTF8: bool = False) -> str:

:return: system encoding (can be None)
"""
try:
# Python >= 3.11
enc = locale.getencoding()
except AttributeError:
enc = locale.getdefaultlocale()[1]
enc = locale.getencoding()
if forceUTF8 and (enc is None or enc == "UTF8"):
return "UTF-8"

Expand Down
6 changes: 1 addition & 5 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,7 @@ def Redirect(self):
sys.stdout = self.cmdStdOut
sys.stderr = self.cmdStdErr
else:
try:
# Python >= 3.11
enc = locale.getencoding()
except AttributeError:
enc = locale.getdefaultlocale()[1]
enc = locale.getencoding()
if enc:
# https://stackoverflow.com/questions/4374455/how-to-set-sys-stdout-encoding-in-python-3
sys.stdout = codecs.getwriter(enc)(sys.__stdout__.detach())
Expand Down
18 changes: 3 additions & 15 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,11 +2430,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
)
if p.get("value", "") and Path(p["value"]).is_file():
ifbb.Clear()
try:
# Python >= 3.11
enc = locale.getencoding()
except AttributeError:
enc = locale.getdefaultlocale()[1]
enc = locale.getencoding()
with codecs.open(
p["value"], encoding=enc, errors="ignore"
) as f:
Expand Down Expand Up @@ -2991,11 +2987,7 @@ def OnFileSave(self, event):

if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
try:
# Python >= 3.11
enc = locale.getencoding()
except AttributeError:
enc = locale.getdefaultlocale()[1]
enc = locale.getencoding()

with codecs.open(path, encoding=enc, mode="w", errors="replace") as f:
f.write(text + os.linesep)
Expand All @@ -3017,11 +3009,7 @@ def OnFileText(self, event):
filename = grass.tempfile()
win.SetValue(filename)

try:
# Python >= 3.11
enc = locale.getencoding()
except AttributeError:
enc = locale.getdefaultlocale()[1]
enc = locale.getencoding()

with codecs.open(filename, encoding=enc, mode="w", errors="replace") as f:
f.write(text)
Expand Down
6 changes: 1 addition & 5 deletions gui/wxpython/gui_core/ghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,7 @@ def _pageInfo(self):
if not self.langUsed:
import locale

try:
# Python >= 3.11
loc = locale.getlocale()
except AttributeError:
loc = locale.getdefaultlocale()
loc = locale.getlocale()
if loc == (None, None):
self.langUsed = _("unknown")
else:
Expand Down
6 changes: 1 addition & 5 deletions gui/wxpython/rlisetup/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def __init__(
self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
self.btn_ok.Bind(wx.EVT_BUTTON, self.OnOk)
self._layout()
try:
# Python >= 3.11
self.enc = locale.getencoding()
except AttributeError:
self.enc = locale.getdefaultlocale()[1]
self.enc = locale.getencoding()

def _layout(self):
"""Set the layout"""
Expand Down
12 changes: 2 additions & 10 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@

GISBASE = None

try:
# Python >= 3.11
ENCODING = locale.getencoding()
except AttributeError:
ENCODING = locale.getdefaultlocale()[1]
ENCODING = locale.getencoding()
if ENCODING is None:
ENCODING = "UTF-8"
print("Default locale not found, using UTF-8") # intentionally not translatable
Expand Down Expand Up @@ -1097,11 +1093,7 @@ def set_language(grass_config_dir: StrPath) -> None:
"Default locale settings are missing. GRASS running with C locale.\n"
)

try:
# Python >= 3.11
language, encoding = locale.getlocale()
except AttributeError:
language, encoding = locale.getdefaultlocale()
language, encoding = locale.getlocale()
if not language:
sys.stderr.write(
"Default locale settings are missing. GRASS running with C locale.\n"
Expand Down
6 changes: 1 addition & 5 deletions python/grass/gunittest/multirunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@


def _get_encoding():
try:
# Python >= 3.11
encoding = locale.getencoding()
except AttributeError:
encoding = locale.getdefaultlocale()[1]
encoding = locale.getencoding()
if not encoding:
encoding = "UTF-8"
return encoding
Expand Down
6 changes: 1 addition & 5 deletions python/grass/script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ def __setattr__(self, key: str, value: VT) -> None:


def _get_encoding() -> str:
try:
# Python >= 3.11
encoding = locale.getencoding()
except AttributeError:
encoding = locale.getdefaultlocale()[1]
encoding = locale.getencoding()
if not encoding:
encoding = "UTF-8"
return encoding
Expand Down
6 changes: 1 addition & 5 deletions utils/mkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@


def _get_encoding():
try:
# Python >= 3.11
encoding = locale.getencoding()
except AttributeError:
encoding = locale.getdefaultlocale()[1]
encoding = locale.getencoding()
if not encoding:
encoding = "UTF-8"
return encoding
Expand Down
Loading