Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b70e9e

Browse files
Helpers.GetDefaultEncoding is added
This function is equal to os_ops.get_default_encoding and is used in: - Helpers.PrepareProcessInput - RaiseError._TranslateDataIntoString__FromBinary
1 parent3cc19d2 commit7b70e9e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

‎testgres/operations/helpers.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
1+
importlocale
2+
3+
14
classHelpers:
5+
def_make_get_default_encoding_func():
6+
# locale.getencoding is added in Python 3.11
7+
ifhasattr(locale,'getencoding'):
8+
returnlocale.getencoding
9+
10+
# It must exist
11+
returnlocale.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+
defGetDefaultEncoding():
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_funcisnotNone
27+
28+
r=__class__._get_default_encoding_func()
29+
30+
ifr:
31+
assertrisnotNone
32+
asserttype(r)==str# noqa: E721
33+
assertr!=""
34+
returnr
35+
36+
# Is it an unexpected situation?
37+
return'UTF-8'
38+
239
defPrepareProcessInput(input,encoding):
340
ifnotinput:
441
returnNone
542

643
iftype(input)==str:# noqa: E721
744
ifencodingisNone:
8-
returninput.encode()
45+
returninput.encode(__class__.GetDefaultEncoding())
946

1047
asserttype(encoding)==str# noqa: E721
1148
returninput.encode(encoding)

‎testgres/operations/raise_error.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ..exceptionsimportExecUtilException
2+
from .helpersimportHelpers
23

34

45
classRaiseError:
@@ -29,7 +30,7 @@ def _TranslateDataIntoString__FromBinary(data):
2930
asserttype(data)==bytes# noqa: E721
3031

3132
try:
32-
returndata.decode('utf-8')
33+
returndata.decode(Helpers.GetDefaultEncoding())
3334
exceptUnicodeDecodeError:
3435
pass
3536

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp