-
Notifications
You must be signed in to change notification settings - Fork 235
Support non-ASCII characters in ISO-8859-x charsets #3310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
3bcf57f
4738815
9f0e0f1
21e91f1
01ef6b3
3c8b979
d946636
7aa07a0
6f3aae4
e2fa2c8
dca5079
32a6646
db590a3
7c9bed4
91818e1
9af4efb
4734520
df3679b
36b2a2f
78cc52b
2d01f6b
43ef0a2
586127d
e8ac6bb
6bd5008
5260749
556fee9
c414b4c
7607c7e
6728856
7a26bfc
1636453
d90dcc8
23a2806
3474bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| args_in_kwargs, | ||
| build_arg_list, | ||
| build_arg_string, | ||
| check_encoding, | ||
|
||
| data_kind, | ||
| is_nonstr_iter, | ||
| launch_external_viewer, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -205,7 +205,55 @@ def data_kind(data=None, x=None, y=None, z=None, required_z=False, required_data | |||||||||||||||||||||||||||||||||||||||||||
| return kind | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def non_ascii_to_octal(argstr: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||
| def check_encoding(argstr: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| def check_encoding(argstr: str) -> str: | |
| def check_encoding(argstr: str) -> Literal[ | |
| "ascii", | |
| "ISOLatin1+", | |
| "ISO-8859-1", | |
| "ISO-8859-2", | |
| "ISO-8859-3", | |
| "ISO-8859-4", | |
| "ISO-8859-5", | |
| "ISO-8859-6", | |
| "ISO-8859-7", | |
| "ISO-8859-8", | |
| "ISO-8859-9", | |
| "ISO-8859-10", | |
| "ISO-8859-11", | |
| "ISO-8859-13", | |
| "ISO-8859-14", | |
| "ISO-8859-15", | |
| "ISO-8859-16", | |
| "ISO-8859-17", | |
| ]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about that too. Actually the same types can be used in typing hints the encoding parameter of the non_ascii_to_octal function. So my initial plan is to define a generic type
type Encodings = Literal[
"ascii",
"ISOLatin1+",
"ISO-8859-1",
"ISO-8859-2",
"ISO-8859-3",
"ISO-8859-4",
"ISO-8859-5",
"ISO-8859-6",
"ISO-8859-7",
"ISO-8859-8",
"ISO-8859-9",
"ISO-8859-10",
"ISO-8859-11",
"ISO-8859-13",
"ISO-8859-14",
"ISO-8859-15",
"ISO-8859-16",
]
and then use it like:
def check_encoding(argstr: str) -> Encodings:
def non_ascii_to_octal(argstr: str, encoding: Encodings = "ISOLatin1+") -> str:
but mypy v1.10.0 complains
pygmt/helpers/utils.py:21: error: PEP 695 type aliases are not yet supported [valid-type]
mypy v1.11.0 started to support PEP 695 but it was released just a few days ago (https://mypy-lang.blogspot.com/2024/07/mypy-111-released.html) and the PEP 695 support is still experimental.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 7607c7e.
seisman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the GMT-supported encodings, I'm thinking if we should return ascii (the name ascii comes from https://docs.python.org/3/library/codecs.html#standard-encodings) if the input string only contains ASCII characters, e.g.,
if all(32 <= ord(c) <= 126 for c in argstr):
return "ascii"
Since in most cases, the arguments and the text string contain ASCII characters only. When ascii encoding is detected, we no longer need to apply non_ascii_to_octal to the strings, which may improve the performance for most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2d01f6b.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function returns ISOLatin1+/ISO-8859-1/.../ISO-8859-16, but Python's standard encodings are latin_1/iso8859_1/...iso8859_16 (https://docs.python.org/3/library/codecs.html#standard-encodings). They're inconsistent, but using names like ISOLatin1+ can greatly simplify the codes.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| outs: | ||
| - md5: a0f35a1d58c95e6589c7397e7660e946 | ||
| size: 17089 | ||
| hash: md5 | ||
| path: test_text_nonascii_iso8859.png |
Uh oh!
There was an error while loading. Please reload this page.