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
f0a4668e
Kaydet (Commit)
f0a4668e
authored
Kas 03, 2002
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add getpreferredencoding. Support @euro modifiers. Fixes #554676.
The @euro part is backported to 2.2.3.
üst
cf57e509
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
1 deletion
+59
-1
liblocale.tex
Doc/lib/liblocale.tex
+14
-0
locale.py
Lib/locale.py
+41
-0
test_locale.py
Lib/test/test_locale.py
+2
-0
NEWS
Misc/NEWS
+2
-1
No files found.
Doc/lib/liblocale.tex
Dosyayı görüntüle @
f0a4668e
...
...
@@ -155,6 +155,20 @@ for which symbolic constants are available in the locale module.
\versionadded
{
2.0
}
\end{funcdesc}
\begin{funcdesc}
{
getpreferredencoding
}{
\optional
{
do
_
setlocale
}}
Return the encoding used for text data, according to user
preferences. User preferences are expressed differently on
different systems, and might not be available programmatically on
some systems, so this function only returns a guess.
On some systems, it is necessary to invoke
\function
{
setlocale
}
to obtain the user preferences, so this function is not thread-safe.
If invoking setlocale is not necessary or desired,
\var
{
do
_
setlocale
}
should be set to
\code
{
False
}
.
\versionadded
{
2.3
}
\end{funcdesc}
\begin{funcdesc}
{
normalize
}{
localename
}
Returns a normalized locale code for the given locale name. The
returned locale code is formatted for use with
...
...
Lib/locale.py
Dosyayı görüntüle @
f0a4668e
...
...
@@ -264,6 +264,15 @@ def _parse_localename(localename):
"""
code
=
normalize
(
localename
)
if
'@'
in
localename
:
# Deal with locale modifiers
code
,
modifier
=
code
.
split
(
'@'
)
if
modifier
==
'euro'
and
'.'
not
in
code
:
# Assume Latin-9 for @euro locales. This is bogus,
# since some systems may use other encodings for these
# locales. Also, we ignore other modifiers.
return
code
,
'iso-8859-15'
if
'.'
in
code
:
return
code
.
split
(
'.'
)[:
2
]
elif
code
==
'C'
:
...
...
@@ -381,6 +390,38 @@ def resetlocale(category=LC_ALL):
"""
_setlocale
(
category
,
_build_localename
(
getdefaultlocale
()))
if
sys
.
platform
in
(
'win32'
,
'darwin'
,
'mac'
):
# On Win32, this will return the ANSI code page
# On the Mac, it should return the system encoding;
# it might return "ascii" instead
def
getpreferredencoding
(
do_setlocale
=
True
):
"""Return the charset that the user is likely using."""
import
_locale
return
_locale
.
getdefaultlocale
()[
1
]
else
:
# On Unix, if CODESET is available, use that.
try
:
CODESET
except
NameError
:
# Fall back to parsing environment variables :-(
def
getpreferredencoding
(
do_setlocale
=
True
):
"""Return the charset that the user is likely using,
by looking at environment variables."""
return
getdefaultlocale
()[
1
]
else
:
def
getpreferredencoding
(
do_setlocale
=
True
):
"""Return the charset that the user is likely using,
according to the system configuration."""
if
do_setlocale
:
oldloc
=
setlocale
(
LC_CTYPE
)
setlocale
(
LC_CTYPE
,
""
)
result
=
nl_langinfo
(
CODESET
)
setlocale
(
LC_CTYPE
,
oldloc
)
return
result
else
:
return
nl_langinfo
(
CODESET
)
### Database
#
# The following data was extracted from the locale.alias file which
...
...
Lib/test/test_locale.py
Dosyayı görüntüle @
f0a4668e
...
...
@@ -38,5 +38,7 @@ try:
testformat
(
"
%20
.f"
,
-
42
,
grouping
=
1
,
output
=
' -42'
)
testformat
(
"
%+10
.f"
,
-
4200
,
grouping
=
1
,
output
=
' -4,200'
)
testformat
(
"
%-10
.f"
,
4200
,
grouping
=
1
,
output
=
'4,200 '
)
# Invoke getpreferredencoding to make sure it does not cause exceptions,
locale
.
getpreferredencoding
()
finally
:
locale
.
setlocale
(
locale
.
LC_NUMERIC
,
oldlocale
)
Misc/NEWS
Dosyayı görüntüle @
f0a4668e
...
...
@@ -325,7 +325,8 @@ Extension modules
- posix.lchown, posix.killpg, posix.mknod, and posix.getpgid have been
added where available.
- The locale module now exposes the C library'
s
gettext
interface
.
- The locale module now exposes the C library'
s
gettext
interface
.
It
also
has
a
new
function
getpreferredencoding
.
-
A
security
hole
(
"double free"
)
was
found
in
zlib
-
1.1.3
,
a
popular
third
party
compression
library
used
by
some
Python
modules
.
The
...
...
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