Skip to content
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

Support non-ASCII characters in function arguments #2584

Merged
merged 37 commits into from
Aug 21, 2023
Merged
Changes from 4 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
75778bf
Support non-ASCII characters
seisman Jun 24, 2023
e840c99
Support all ISOlatin1 characters
seisman Jun 24, 2023
1b6d940
Support more ISOLatin1+ characters
seisman Jun 25, 2023
1b88cd6
fix
seisman Jun 25, 2023
311b976
Update pygmt/helpers/utils.py
seisman Jun 26, 2023
672413b
Refactor to make it more readable
seisman Jun 26, 2023
2dcc288
Need to remove single quote
seisman Jun 26, 2023
c9b8254
[ci skip] Use a better reference for ASCII table
seisman Jun 26, 2023
e2947fa
Support Symbols charset
seisman Jun 26, 2023
1a84634
Support ZapfDingbats charset
seisman Jun 26, 2023
636ace0
Refactor and add more doctests
seisman Jun 26, 2023
ffabaee
Fix a symbol which is incorrectly copied from PDF
seisman Jun 27, 2023
e1b43b2
Replace octal codes with non-ASCII character in two examples
seisman Jun 27, 2023
7ea78da
Fix a typo in doctest
seisman Jun 27, 2023
487f2d8
Merge branch 'main' into non-ascii-support
seisman Jun 30, 2023
288486c
Fix some characters
seisman Jun 30, 2023
97a223d
Fix symbol characters
seisman Jun 30, 2023
4ff2e56
Add one more reference
seisman Jun 30, 2023
388109f
Add two more references
seisman Jun 30, 2023
2270d9d
Update ZapfDingbats charset
seisman Jul 1, 2023
117b6e5
Make it clear that Symbol/ZapfDingbats are from Adobe
seisman Jul 2, 2023
1798ccc
Update for ISOLatin1+ charset
seisman Jul 2, 2023
e4bedb9
Fix registered sign, copyright sign and trade mark sign
seisman Jul 2, 2023
5ef84f9
Add more notes
seisman Jul 2, 2023
490535c
Add a test for non-ascii support
seisman Jul 2, 2023
418adc5
Update the dvc file
seisman Jul 2, 2023
4b66b8a
Fix styling issue
seisman Jul 2, 2023
37b0c6a
Add docstrings
seisman Jul 2, 2023
3362b31
Update examples/gallery/embellishments/colorbar.py
seisman Jul 22, 2023
695c59b
Merge branch 'main' into non-ascii-support
seisman Aug 2, 2023
bbc223b
Remove an unused pylint directive
seisman Aug 2, 2023
35306bf
Fix a typo in doctest
seisman Aug 2, 2023
e56359e
Merge branch 'main' into non-ascii-support
seisman Aug 5, 2023
633b2f9
Merge branch 'main' into non-ascii-support
seisman Aug 16, 2023
cdb4ab1
Merge branch 'main' into non-ascii-support
seisman Aug 17, 2023
646465c
Update pygmt/helpers/utils.py
seisman Aug 21, 2023
9ce0217
Merge branch 'main' into non-ascii-support
seisman Aug 21, 2023
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
37 changes: 36 additions & 1 deletion pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ def data_kind(data, x=None, y=None, z=None, required_z=False):
return kind


def non_ascii_to_octal(argstr):
r"""
Translate non-ASCII characters to their corresponding octal codes.

Currently, only ISOLatin1+ character set is supported.
seisman marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
argstr : str
The string to be translated.

Returns
-------
str
The translated string.
seisman marked this conversation as resolved.
Show resolved Hide resolved

Examples
--------
>>> non_ascii_to_octal("ABC ±120° DEF")
'ABC \\261120\\260 DEF'
"""
# Mapping for non-ASCII characters in ISOLatin1 charset
# Reference: https://www.ascii.ca/adobeiso.htm
mapping_isolatin1 = {chr(i): "\\" + format(i, "o") for i in range(160, 256)}
# Mapping for extended non-ASCII characters in ISOLatin1+ charset
mapping_isolatin1plus = {
c: "\\" + format(i, "o")
for c, i in zip(
"•…™—–fižšŒ†‡Ł⁄‹Š›œŸŽł‰„“”ı`´ˆ˜¯˘˙¨‚˚¸'˝˛ˇ",
list(range(25, 32)) + list(range(127, 160)),
)
}
return argstr.translate(str.maketrans(mapping_isolatin1 | mapping_isolatin1plus))


def build_arg_string(kwdict, confdict=None, infile=None, outfile=None):
r"""
Convert keyword dictionaries and input/output files into a GMT argument
Expand Down Expand Up @@ -213,7 +248,7 @@ def build_arg_string(kwdict, confdict=None, infile=None, outfile=None):
gmt_args = [str(infile)] + gmt_args
if outfile:
gmt_args.append("->" + str(outfile))
return " ".join(gmt_args)
return non_ascii_to_octal(" ".join(gmt_args))


def is_nonstr_iter(value):
Expand Down