2
2
"""
3
3
import html
4
4
import re
5
+ from typing import Any
5
6
6
7
from .entities import entities
7
8
8
9
# from .normalize_url import unescape_string
9
10
10
11
11
- def charCodeAt (src : str , pos : int ):
12
+ def charCodeAt (src : str , pos : int ) -> Any :
12
13
"""
13
14
Returns the Unicode value of the character at the specified location.
14
15
@@ -26,12 +27,11 @@ def charCodeAt(src: str, pos: int):
26
27
# function _class(obj) { return Object.prototype.toString.call(obj); }
27
28
28
29
29
- def isString (obj ) :
30
+ def isString (obj : object ) -> bool :
30
31
return isinstance (obj , str )
31
32
32
33
33
- def has (object , key ):
34
- return hasattr (object , key )
34
+ has = hasattr
35
35
36
36
37
37
# Merge objects
@@ -56,18 +56,18 @@ def assign(obj):
56
56
# return obj
57
57
58
58
59
- def arrayReplaceAt (src : list , pos : int , newElements : list ):
59
+ def arrayReplaceAt (src : list , pos : int , newElements : list ) -> list :
60
60
"""
61
61
Remove element from array and put another array at those position.
62
62
Useful for some operations with tokens
63
63
"""
64
- return src [0 :pos ] + newElements + src [pos + 1 :]
64
+ return src [:pos ] + newElements + src [pos + 1 :]
65
65
66
66
67
67
######################################################################
68
68
69
69
70
- def isValidEntityCode (c ) :
70
+ def isValidEntityCode (c : int ) -> bool :
71
71
72
72
# broken sequence
73
73
if c >= 0xD800 and c <= 0xDFFF :
@@ -111,7 +111,7 @@ def fromCodePoint(c: int) -> str:
111
111
DIGITAL_ENTITY_TEST_RE = re .compile (r"^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))" , re .IGNORECASE )
112
112
113
113
114
- def replaceEntityPattern (match , name ) :
114
+ def replaceEntityPattern (match : str , name : str ) -> str :
115
115
"""Convert HTML entity patterns
116
116
117
117
::
@@ -138,22 +138,22 @@ def replaceEntityPattern(match, name):
138
138
# return string.replace(ENTITY_RE, replaceEntityPattern)
139
139
140
140
141
- def unescapeMd (string : str ):
141
+ def unescapeMd (string : str ) -> str :
142
142
raise NotImplementedError
143
143
# if "\\" in string:
144
144
# return string
145
145
# return string.replace(UNESCAPE_MD_RE, "$1")
146
146
147
147
148
- def unescapeAll (string : str ):
148
+ def unescapeAll (string : str ) -> str :
149
149
return html .unescape (string )
150
150
151
151
152
152
ESCAPABLE = r"""\\!"#$%&'()*+,./:;<=>?@\[\]^`{}|_~-"""
153
153
ESCAPE_CHAR = re .compile (r"\\([" + ESCAPABLE + r"])" )
154
154
155
155
156
- def stripEscape (string ) :
156
+ def stripEscape (string : str ) -> str :
157
157
"""Strip escape \\ characters"""
158
158
return ESCAPE_CHAR .sub (r"\1" , string )
159
159
@@ -179,7 +179,7 @@ def stripEscape(string):
179
179
# return string
180
180
181
181
182
- def escapeHtml (raw : str ):
182
+ def escapeHtml (raw : str ) -> str :
183
183
# return html.escape(html.unescape(raw)).replace("'", "'")
184
184
return html .escape (raw ).replace ("'" , "'" )
185
185
@@ -197,7 +197,7 @@ def escapeRE(string: str) -> str:
197
197
# //////////////////////////////////////////////////////////////////////////////
198
198
199
199
200
- def isSpace (code ) -> bool :
200
+ def isSpace (code : object ) -> bool :
201
201
return code in {0x09 , 0x20 }
202
202
203
203
@@ -271,7 +271,7 @@ def isPunctChar(ch: str) -> bool:
271
271
}
272
272
273
273
274
- def isMdAsciiPunct (ch : int ):
274
+ def isMdAsciiPunct (ch : int ) -> bool :
275
275
"""Markdown ASCII punctuation characters.
276
276
277
277
::
0 commit comments