File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 1+ import locale
2+
3+
14class Helpers :
5+ def _make_get_default_encoding_func ():
6+ # locale.getencoding is added in Python 3.11
7+ if hasattr (locale , 'getencoding' ):
8+ return locale .getencoding
9+
10+ # It must exist
11+ return locale .getpreferredencoding
12+
13+ # Prepared pointer on function to get a name of system codepage
14+ _get_default_encoding_func = _make_get_default_encoding_func ()
15+
16+ def GetDefaultEncoding ():
17+ #
18+ # Original idea/source was:
19+ #
20+ # def os_ops.get_default_encoding():
21+ # if not hasattr(locale, 'getencoding'):
22+ # locale.getencoding = locale.getpreferredencoding
23+ # return locale.getencoding() or 'UTF-8'
24+ #
25+
26+ assert __class__ ._get_default_encoding_func is not None
27+
28+ r = __class__ ._get_default_encoding_func ()
29+
30+ if r :
31+ assert r is not None
32+ assert type (r ) == str # noqa: E721
33+ assert r != ""
34+ return r
35+
36+ # Is it an unexpected situation?
37+ return 'UTF-8'
38+
239 def PrepareProcessInput (input , encoding ):
340 if not input :
441 return None
542
643 if type (input ) == str : # noqa: E721
744 if encoding is None :
8- return input .encode ()
45+ return input .encode (__class__ . GetDefaultEncoding () )
946
1047 assert type (encoding ) == str # noqa: E721
1148 return input .encode (encoding )
Original file line number Diff line number Diff line change 11from ..exceptions import ExecUtilException
2+ from .helpers import Helpers
23
34
45class RaiseError :
@@ -29,7 +30,7 @@ def _TranslateDataIntoString__FromBinary(data):
2930 assert type (data ) == bytes # noqa: E721
3031
3132 try :
32- return data .decode ('utf-8' )
33+ return data .decode (Helpers . GetDefaultEncoding () )
3334 except UnicodeDecodeError :
3435 pass
3536
You can’t perform that action at this time.
0 commit comments