-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGlobal.py
More file actions
97 lines (61 loc) · 1.79 KB
/
Copy pathGlobal.py
File metadata and controls
97 lines (61 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import math
import urllib.parse
nan = math.nan
isNaN = math.isnan
infinity = math.inf
isFinite = math.isfinite
def readInt(radix):
def ap(n):
try:
return float(int(n, radix))
except ValueError:
try:
return float(int(str(int(float(n))), radix))
except ValueError:
return math.nan
return math.nan
return ap
readFloat = float
def unsafeToFixed(digits):
def n_(n):
f = r"{:0." + str(digits) + r"f}"
return f.format(n)
return n_
def unsafeToExponential(digits):
def n_(n):
f = r"{:." + str(digits) + r"e}"
return f.format(n).replace("e-0", "e-").replace("e+0", "e+")
return n_
def unsafeToPrecision(digits):
def n_(n):
raise NotImplementedError()
return n_
def formatNumber(fmt):
def ap(fail, succ, digits, n):
try:
return succ(fmt(digits)(n))
except Exception as e:
return fail(str(e))
return ap
_toFixed = formatNumber(unsafeToFixed)
_toExponential = formatNumber(unsafeToExponential)
_toPrecision = formatNumber(unsafeToPrecision)
def encdecURI(encdec):
def ap(fail, succ, s):
try:
return succ(encdec(s))
except Exception as e:
return fail(str(e))
return ap
def decodeURI(s):
return urllib.parse.unquote(s, errors="strict")
def encodeURI(s):
return urllib.parse.quote(s, safe="~@#$&()*!+=:;,.?/'")
def decodeURIComponent(s):
return urllib.parse.unquote(s, errors="strict")
def encodeURIComponent(s):
return urllib.parse.quote(s, safe="~()*!.'")
_decodeURI = encdecURI(decodeURI)
_encodeURI = encdecURI(encodeURI)
_decodeURIComponent = encdecURI(decodeURIComponent)
_encodeURIComponent = encdecURI(encodeURIComponent)