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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
Index: Lib/string.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/string.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -c -r1.41 -r1.42
*** string.py 1998/03/30 17:22:30 1.41
--- string.py 1998/04/20 14:01:00 1.42
***************
*** 326,348 ****
return r
# "Safe" environment for eval()
! safe_env = {"__builtins__": {}}
# Convert string to float
! re = None
def atof(str):
"""atof(s) -> float
Return the floating point number represented by the string s.
"""
! global re
! if re is None:
# Don't fail if re doesn't exist -- just skip the syntax check
try:
import re
except ImportError:
! re = 0
sign = ''
s = strip(str)
if s and s[0] in '+-':
--- 326,350 ----
return r
# "Safe" environment for eval()
! _safe_env = {"__builtins__": {}}
# Convert string to float
! _re = None
def atof(str):
"""atof(s) -> float
Return the floating point number represented by the string s.
"""
! global _re
! if _re is None:
# Don't fail if re doesn't exist -- just skip the syntax check
try:
import re
except ImportError:
! _re = 0
! else:
! _re = re
sign = ''
s = strip(str)
if s and s[0] in '+-':
***************
*** 351,360 ****
if not s:
raise ValueError, 'non-float argument to string.atof'
while s[0] == '0' and len(s) > 1 and s[1] in digits: s = s[1:]
! if re and not re.match('[0-9]*(\.[0-9]*)?([eE][-+]?[0-9]+)?$', s):
raise ValueError, 'non-float argument to string.atof'
try:
! return float(eval(sign + s, safe_env))
except SyntaxError:
raise ValueError, 'non-float argument to string.atof'
--- 353,362 ----
if not s:
raise ValueError, 'non-float argument to string.atof'
while s[0] == '0' and len(s) > 1 and s[1] in digits: s = s[1:]
! if _re and not _re.match('[0-9]*(\.[0-9]*)?([eE][-+]?[0-9]+)?$', s):
raise ValueError, 'non-float argument to string.atof'
try:
! return float(eval(sign + s, _safe_env))
except SyntaxError:
raise ValueError, 'non-float argument to string.atof'
***************
*** 384,390 ****
for c in s:
if c not in digits:
raise ValueError, 'non-integer argument to string.atoi'
! return eval(sign + s, safe_env)
# Convert string to long integer
def atol(str, base=10):
--- 386,392 ----
for c in s:
if c not in digits:
raise ValueError, 'non-integer argument to string.atoi'
! return eval(sign + s, _safe_env)
# Convert string to long integer
def atol(str, base=10):
***************
*** 413,419 ****
for c in s:
if c not in digits:
raise ValueError, 'non-integer argument to string.atol'
! return eval(sign + s + 'L', safe_env)
# Left-justify a string
def ljust(s, width):
--- 415,421 ----
for c in s:
if c not in digits:
raise ValueError, 'non-integer argument to string.atol'
! return eval(sign + s + 'L', _safe_env)
# Left-justify a string
def ljust(s, width):
|