|
18 | 18 | from pygmt.encodings import charset |
19 | 19 | from pygmt.exceptions import GMTInvalidInput |
20 | 20 |
|
| 21 | +# Type hints for the list of encodings supported by PyGMT. |
| 22 | +Encoding = Literal[ |
| 23 | + "ascii", |
| 24 | + "ISOLatin1+", |
| 25 | + "ISO-8859-1", |
| 26 | + "ISO-8859-2", |
| 27 | + "ISO-8859-3", |
| 28 | + "ISO-8859-4", |
| 29 | + "ISO-8859-5", |
| 30 | + "ISO-8859-6", |
| 31 | + "ISO-8859-7", |
| 32 | + "ISO-8859-8", |
| 33 | + "ISO-8859-9", |
| 34 | + "ISO-8859-10", |
| 35 | + "ISO-8859-11", |
| 36 | + "ISO-8859-13", |
| 37 | + "ISO-8859-14", |
| 38 | + "ISO-8859-15", |
| 39 | + "ISO-8859-16", |
| 40 | +] |
| 41 | + |
21 | 42 |
|
22 | 43 | def _validate_data_input( |
23 | 44 | data=None, x=None, y=None, z=None, required_z=False, required_data=True, kind=None |
@@ -123,27 +144,7 @@ def _validate_data_input( |
123 | 144 | raise GMTInvalidInput(msg) |
124 | 145 |
|
125 | 146 |
|
126 | | -def _check_encoding( |
127 | | - argstr: str, |
128 | | -) -> Literal[ |
129 | | - "ascii", |
130 | | - "ISOLatin1+", |
131 | | - "ISO-8859-1", |
132 | | - "ISO-8859-2", |
133 | | - "ISO-8859-3", |
134 | | - "ISO-8859-4", |
135 | | - "ISO-8859-5", |
136 | | - "ISO-8859-6", |
137 | | - "ISO-8859-7", |
138 | | - "ISO-8859-8", |
139 | | - "ISO-8859-9", |
140 | | - "ISO-8859-10", |
141 | | - "ISO-8859-11", |
142 | | - "ISO-8859-13", |
143 | | - "ISO-8859-14", |
144 | | - "ISO-8859-15", |
145 | | - "ISO-8859-16", |
146 | | -]: |
| 147 | +def _check_encoding(argstr: str) -> Encoding: |
147 | 148 | """ |
148 | 149 | Check the charset encoding of a string. |
149 | 150 |
|
@@ -185,9 +186,7 @@ def _check_encoding( |
185 | 186 | adobe_chars = set(charset["Symbol"].values()) | set( |
186 | 187 | charset["ZapfDingbats"].values() |
187 | 188 | ) |
188 | | - for encoding in ["ISOLatin1+"] + [f"ISO-8859-{i}" for i in range(1, 17)]: |
189 | | - if encoding == "ISO-8859-12": # ISO-8859-12 was abandoned. Skip it. |
190 | | - continue |
| 189 | + for encoding in ["ISOLatin1+"] + [f"ISO-8859-{i}" for i in range(1, 17) if i != 12]: |
191 | 190 | if all(c in (set(charset[encoding].values()) | adobe_chars) for c in argstr): |
192 | 191 | return encoding # type: ignore[return-value] |
193 | 192 | # Return the "ISOLatin1+" encoding if the string contains characters from multiple |
@@ -340,34 +339,13 @@ def data_kind( |
340 | 339 | return kind # type: ignore[return-value] |
341 | 340 |
|
342 | 341 |
|
343 | | -def non_ascii_to_octal( |
344 | | - argstr: str, |
345 | | - encoding: Literal[ |
346 | | - "ascii", |
347 | | - "ISOLatin1+", |
348 | | - "ISO-8859-1", |
349 | | - "ISO-8859-2", |
350 | | - "ISO-8859-3", |
351 | | - "ISO-8859-4", |
352 | | - "ISO-8859-5", |
353 | | - "ISO-8859-6", |
354 | | - "ISO-8859-7", |
355 | | - "ISO-8859-8", |
356 | | - "ISO-8859-9", |
357 | | - "ISO-8859-10", |
358 | | - "ISO-8859-11", |
359 | | - "ISO-8859-13", |
360 | | - "ISO-8859-14", |
361 | | - "ISO-8859-15", |
362 | | - "ISO-8859-16", |
363 | | - ] = "ISOLatin1+", |
364 | | -) -> str: |
| 342 | +def non_ascii_to_octal(argstr: str, encoding: Encoding = "ISOLatin1+") -> str: |
365 | 343 | r""" |
366 | 344 | Translate non-ASCII characters to their corresponding octal codes. |
367 | 345 |
|
368 | 346 | Currently, only non-ASCII characters in the Adobe ISOLatin1+, Adobe Symbol, Adobe |
369 | 347 | ZapfDingbats, and ISO-8850-x (x can be in 1-11, 13-17) encodings are supported. |
370 | | - The Adobe Standard encoding is not supported yet. |
| 348 | + The Adobe Standard+ encoding is not supported. |
371 | 349 |
|
372 | 350 | Parameters |
373 | 351 | ---------- |
|
0 commit comments