Show More
@@ -26,11 +26,12 from . import ( | |||||
26 | pycompat, |
|
26 | pycompat, | |
27 | ) |
|
27 | ) | |
28 |
|
28 | |||
|
29 | from .interfaces import modules as intmod | |||
29 | from .pure import charencode as charencodepure |
|
30 | from .pure import charencode as charencodepure | |
30 |
|
31 | |||
31 | _Tlocalstr = TypeVar('_Tlocalstr', bound='localstr') |
|
32 | _Tlocalstr = TypeVar('_Tlocalstr', bound='localstr') | |
32 |
|
33 | |||
33 | charencode = policy.importmod('charencode') |
|
34 | charencode: intmod.CharEncoding = policy.importmod('charencode') | |
34 |
|
35 | |||
35 | isasciistr = charencode.isasciistr |
|
36 | isasciistr = charencode.isasciistr | |
36 | asciilower = charencode.asciilower |
|
37 | asciilower = charencode.asciilower | |
@@ -41,15 +42,6 asciiupper = charencode.asciiupper | |||||
41 |
|
42 | |||
42 | unichr = chr |
|
43 | unichr = chr | |
43 |
|
44 | |||
44 | if typing.TYPE_CHECKING: |
|
|||
45 | # TODO: make a stub file for .cext.charencode, and import here |
|
|||
46 | from .pure.charencode import ( |
|
|||
47 | asciilower, |
|
|||
48 | asciiupper, |
|
|||
49 | isasciistr, |
|
|||
50 | jsonescapeu8fast as _jsonescapeu8fast, |
|
|||
51 | ) |
|
|||
52 |
|
||||
53 |
|
45 | |||
54 | # These unicode characters are ignored by HFS+ (Apple Technote 1150, |
|
46 | # These unicode characters are ignored by HFS+ (Apple Technote 1150, | |
55 | # "Unicode Subtleties"), so we need to ignore them in some places for |
|
47 | # "Unicode Subtleties"), so we need to ignore them in some places for |
@@ -50,3 +50,26 class BDiff(Protocol): | |||||
50 |
|
50 | |||
51 | xdiffblocks: Optional[BDiffBlocksFnc] |
|
51 | xdiffblocks: Optional[BDiffBlocksFnc] | |
52 | """This method is currently only available in the ``cext`` module.""" |
|
52 | """This method is currently only available in the ``cext`` module.""" | |
|
53 | ||||
|
54 | ||||
|
55 | class CharEncoding(Protocol): | |||
|
56 | """A Protocol class for the various charencoding module implementations.""" | |||
|
57 | ||||
|
58 | def isasciistr(self, s: bytes) -> bool: | |||
|
59 | """Can the byte string be decoded with the ``ascii`` codec?""" | |||
|
60 | ||||
|
61 | def asciilower(self, s: bytes) -> bytes: | |||
|
62 | """convert a string to lowercase if ASCII | |||
|
63 | ||||
|
64 | Raises UnicodeDecodeError if non-ASCII characters are found.""" | |||
|
65 | ||||
|
66 | def asciiupper(self, s: bytes) -> bytes: | |||
|
67 | """convert a string to uppercase if ASCII | |||
|
68 | ||||
|
69 | Raises UnicodeDecodeError if non-ASCII characters are found.""" | |||
|
70 | ||||
|
71 | def jsonescapeu8fast(self, u8chars: bytes, paranoid: bool) -> bytes: | |||
|
72 | """Convert a UTF-8 byte string to JSON-escaped form (fast path) | |||
|
73 | ||||
|
74 | Raises ValueError if non-ASCII characters have to be escaped. | |||
|
75 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now