Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9a34523e
Kaydet (Commit)
9a34523e
authored
Nis 20, 1998
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
As Tim Peters points out, ``from string import *'' should not set re to None.
Also rename safe_env to _safe_env.
üst
476412a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
string.py
Lib/string.py
+11
-9
stringold.py
Lib/stringold.py
+11
-9
No files found.
Lib/string.py
Dosyayı görüntüle @
9a34523e
...
@@ -326,23 +326,25 @@ def rfind(s, sub, i = 0, last=None):
...
@@ -326,23 +326,25 @@ def rfind(s, sub, i = 0, last=None):
return
r
return
r
# "Safe" environment for eval()
# "Safe" environment for eval()
safe_env
=
{
"__builtins__"
:
{}}
_
safe_env
=
{
"__builtins__"
:
{}}
# Convert string to float
# Convert string to float
re
=
None
_
re
=
None
def
atof
(
str
):
def
atof
(
str
):
"""atof(s) -> float
"""atof(s) -> float
Return the floating point number represented by the string s.
Return the floating point number represented by the string s.
"""
"""
global
re
global
_
re
if
re
is
None
:
if
_
re
is
None
:
# Don't fail if re doesn't exist -- just skip the syntax check
# Don't fail if re doesn't exist -- just skip the syntax check
try
:
try
:
import
re
import
re
except
ImportError
:
except
ImportError
:
re
=
0
_re
=
0
else
:
_re
=
re
sign
=
''
sign
=
''
s
=
strip
(
str
)
s
=
strip
(
str
)
if
s
and
s
[
0
]
in
'+-'
:
if
s
and
s
[
0
]
in
'+-'
:
...
@@ -351,10 +353,10 @@ def atof(str):
...
@@ -351,10 +353,10 @@ def atof(str):
if
not
s
:
if
not
s
:
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
while
s
[
0
]
==
'0'
and
len
(
s
)
>
1
and
s
[
1
]
in
digits
:
s
=
s
[
1
:]
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
):
if
_re
and
not
_
re
.
match
(
'[0-9]*(
\
.[0-9]*)?([eE][-+]?[0-9]+)?$'
,
s
):
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
try
:
try
:
return
float
(
eval
(
sign
+
s
,
safe_env
))
return
float
(
eval
(
sign
+
s
,
_
safe_env
))
except
SyntaxError
:
except
SyntaxError
:
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
...
@@ -384,7 +386,7 @@ def atoi(str, base=10):
...
@@ -384,7 +386,7 @@ def atoi(str, base=10):
for
c
in
s
:
for
c
in
s
:
if
c
not
in
digits
:
if
c
not
in
digits
:
raise
ValueError
,
'non-integer argument to string.atoi'
raise
ValueError
,
'non-integer argument to string.atoi'
return
eval
(
sign
+
s
,
safe_env
)
return
eval
(
sign
+
s
,
_
safe_env
)
# Convert string to long integer
# Convert string to long integer
def
atol
(
str
,
base
=
10
):
def
atol
(
str
,
base
=
10
):
...
@@ -413,7 +415,7 @@ def atol(str, base=10):
...
@@ -413,7 +415,7 @@ def atol(str, base=10):
for
c
in
s
:
for
c
in
s
:
if
c
not
in
digits
:
if
c
not
in
digits
:
raise
ValueError
,
'non-integer argument to string.atol'
raise
ValueError
,
'non-integer argument to string.atol'
return
eval
(
sign
+
s
+
'L'
,
safe_env
)
return
eval
(
sign
+
s
+
'L'
,
_
safe_env
)
# Left-justify a string
# Left-justify a string
def
ljust
(
s
,
width
):
def
ljust
(
s
,
width
):
...
...
Lib/stringold.py
Dosyayı görüntüle @
9a34523e
...
@@ -326,23 +326,25 @@ def rfind(s, sub, i = 0, last=None):
...
@@ -326,23 +326,25 @@ def rfind(s, sub, i = 0, last=None):
return
r
return
r
# "Safe" environment for eval()
# "Safe" environment for eval()
safe_env
=
{
"__builtins__"
:
{}}
_
safe_env
=
{
"__builtins__"
:
{}}
# Convert string to float
# Convert string to float
re
=
None
_
re
=
None
def
atof
(
str
):
def
atof
(
str
):
"""atof(s) -> float
"""atof(s) -> float
Return the floating point number represented by the string s.
Return the floating point number represented by the string s.
"""
"""
global
re
global
_
re
if
re
is
None
:
if
_
re
is
None
:
# Don't fail if re doesn't exist -- just skip the syntax check
# Don't fail if re doesn't exist -- just skip the syntax check
try
:
try
:
import
re
import
re
except
ImportError
:
except
ImportError
:
re
=
0
_re
=
0
else
:
_re
=
re
sign
=
''
sign
=
''
s
=
strip
(
str
)
s
=
strip
(
str
)
if
s
and
s
[
0
]
in
'+-'
:
if
s
and
s
[
0
]
in
'+-'
:
...
@@ -351,10 +353,10 @@ def atof(str):
...
@@ -351,10 +353,10 @@ def atof(str):
if
not
s
:
if
not
s
:
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
while
s
[
0
]
==
'0'
and
len
(
s
)
>
1
and
s
[
1
]
in
digits
:
s
=
s
[
1
:]
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
):
if
_re
and
not
_
re
.
match
(
'[0-9]*(
\
.[0-9]*)?([eE][-+]?[0-9]+)?$'
,
s
):
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
try
:
try
:
return
float
(
eval
(
sign
+
s
,
safe_env
))
return
float
(
eval
(
sign
+
s
,
_
safe_env
))
except
SyntaxError
:
except
SyntaxError
:
raise
ValueError
,
'non-float argument to string.atof'
raise
ValueError
,
'non-float argument to string.atof'
...
@@ -384,7 +386,7 @@ def atoi(str, base=10):
...
@@ -384,7 +386,7 @@ def atoi(str, base=10):
for
c
in
s
:
for
c
in
s
:
if
c
not
in
digits
:
if
c
not
in
digits
:
raise
ValueError
,
'non-integer argument to string.atoi'
raise
ValueError
,
'non-integer argument to string.atoi'
return
eval
(
sign
+
s
,
safe_env
)
return
eval
(
sign
+
s
,
_
safe_env
)
# Convert string to long integer
# Convert string to long integer
def
atol
(
str
,
base
=
10
):
def
atol
(
str
,
base
=
10
):
...
@@ -413,7 +415,7 @@ def atol(str, base=10):
...
@@ -413,7 +415,7 @@ def atol(str, base=10):
for
c
in
s
:
for
c
in
s
:
if
c
not
in
digits
:
if
c
not
in
digits
:
raise
ValueError
,
'non-integer argument to string.atol'
raise
ValueError
,
'non-integer argument to string.atol'
return
eval
(
sign
+
s
+
'L'
,
safe_env
)
return
eval
(
sign
+
s
+
'L'
,
_
safe_env
)
# Left-justify a string
# Left-justify a string
def
ljust
(
s
,
width
):
def
ljust
(
s
,
width
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment