Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
09075403
Commit
09075403
authored
Feb 09, 2001
by
Eric S. Raymond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
String method conversion.
parent
6627da09
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
42 deletions
+42
-42
Lib/locale.py
Lib/locale.py
+12
-12
Lib/xmllib.py
Lib/xmllib.py
+30
-30
No files found.
Lib/locale.py
View file @
09075403
...
...
@@ -11,7 +11,7 @@
"""
import
s
tring
,
s
ys
import
sys
# Try importing the _locale module.
#
...
...
@@ -140,24 +140,24 @@ def str(val):
"""Convert float to integer, taking the locale into account."""
return
format
(
"%.12g"
,
val
)
def
atof
(
str
,
func
=
string
.
atof
):
def
atof
(
str
,
func
=
float
):
"Parses a string as a float according to the locale settings."
#First, get rid of the grouping
ts
=
localeconv
()[
'thousands_sep'
]
if
ts
:
s
=
str
ing
.
split
(
str
,
ts
)
str
=
string
.
join
(
s
,
""
)
s
=
str
.
split
(
ts
)
str
=
""
.
join
(
s
)
#next, replace the decimal point with a dot
dd
=
localeconv
()[
'decimal_point'
]
if
dd
:
s
=
str
ing
.
split
(
str
,
dd
)
str
=
string
.
join
(
s
,
'.'
)
s
=
str
.
split
(
dd
)
str
=
'.'
.
join
(
s
)
#finally, parse the string
return
func
(
str
)
def
atoi
(
str
):
"Converts a string to an integer according to the locale settings."
return
atof
(
str
,
string
.
atoi
)
return
atof
(
str
,
int
)
def
_test
():
setlocale
(
LC_ALL
,
""
)
...
...
@@ -194,12 +194,12 @@ def normalize(localename):
"""
# Normalize the locale name and extract the encoding
fullname
=
string
.
lower
(
localename
)
fullname
=
localename
.
lower
(
)
if
':'
in
fullname
:
# ':' is sometimes used as encoding delimiter.
fullname
=
string
.
replace
(
fullname
,
':'
,
'.'
)
fullname
=
fullname
.
replace
(
':'
,
'.'
)
if
'.'
in
fullname
:
langname
,
encoding
=
string
.
split
(
fullname
,
'.'
)[:
2
]
langname
,
encoding
=
fullname
.
split
(
'.'
)[:
2
]
fullname
=
langname
+
'.'
+
encoding
else
:
langname
=
fullname
...
...
@@ -214,7 +214,7 @@ def normalize(localename):
code
=
locale_alias
.
get
(
langname
,
None
)
if
code
is
not
None
:
if
'.'
in
code
:
langname
,
defenc
=
string
.
split
(
code
,
'.'
)
langname
,
defenc
=
code
.
split
(
'.'
)
else
:
langname
=
code
defenc
=
''
...
...
@@ -246,7 +246,7 @@ def _parse_localename(localename):
"""
code
=
normalize
(
localename
)
if
'.'
in
code
:
return
string
.
split
(
code
,
'.'
)[:
2
]
return
code
.
split
(
'.'
)[:
2
]
elif
code
==
'C'
:
return
None
,
None
else
:
...
...
Lib/xmllib.py
View file @
09075403
This diff is collapsed.
Click to expand it.
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