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
0f599891
Kaydet (Commit)
0f599891
authored
Haz 02, 2008
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Forward-port PYTHONIOENCODING.
üst
e95593e9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
6 deletions
+45
-6
cmdline.rst
Doc/using/cmdline.rst
+7
-0
test_sys.py
Lib/test/test_sys.py
+20
-0
main.c
Modules/main.c
+1
-0
pythonrun.c
Python/pythonrun.c
+17
-6
No files found.
Doc/using/cmdline.rst
Dosyayı görüntüle @
0f599891
...
@@ -467,6 +467,13 @@ if Python was configured with the :option:`--with-pydebug` build option.
...
@@ -467,6 +467,13 @@ if Python was configured with the :option:`--with-pydebug` build option.
If set, Python will dump objects and reference counts still alive after
If set, Python will dump objects and reference counts still alive after
shutting down the interpreter.
shutting down the interpreter.
.. envvar:: PYTHONIOENCODING
Overrides the encoding used for stdin/stdout/stderr, in the syntax
encodingname:errorhandler, with the :errors part being optional.
.. versionadded:: 2.6
.. envvar:: PYTHONMALLOCSTATS
.. envvar:: PYTHONMALLOCSTATS
...
...
Lib/test/test_sys.py
Dosyayı görüntüle @
0f599891
...
@@ -349,6 +349,26 @@ class SysModuleTest(unittest.TestCase):
...
@@ -349,6 +349,26 @@ class SysModuleTest(unittest.TestCase):
#self.assert_(r[0][1] > 100, r[0][1])
#self.assert_(r[0][1] > 100, r[0][1])
#self.assert_(r[0][2] > 100, r[0][2])
#self.assert_(r[0][2] > 100, r[0][2])
def
test_ioencoding
(
self
):
import
subprocess
,
os
env
=
dict
(
os
.
environ
)
# Test character: cent sign, encoded as 0x4A (ASCII J) in CP424,
# not representable in ASCII.
env
[
"PYTHONIOENCODING"
]
=
"cp424"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'print(chr(0xa2))'
],
stdout
=
subprocess
.
PIPE
,
env
=
env
)
out
=
p
.
stdout
.
read
()
self
.
assertEqual
(
out
,
"
\xa2\n
"
.
encode
(
"cp424"
))
env
[
"PYTHONIOENCODING"
]
=
"ascii:replace"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'print(chr(0xa2))'
],
stdout
=
subprocess
.
PIPE
,
env
=
env
)
out
=
p
.
stdout
.
read
()
.
strip
()
self
.
assertEqual
(
out
,
b
'?'
)
def
test_main
():
def
test_main
():
test
.
support
.
run_unittest
(
SysModuleTest
)
test
.
support
.
run_unittest
(
SysModuleTest
)
...
...
Modules/main.c
Dosyayı görüntüle @
0f599891
...
@@ -96,6 +96,7 @@ static char *usage_5 = "\
...
@@ -96,6 +96,7 @@ static char *usage_5 = "\
PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).
\n
\
PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).
\n
\
The default module search path uses %s.
\n
\
The default module search path uses %s.
\n
\
PYTHONCASEOK : ignore case in 'import' statements (Windows).
\n
\
PYTHONCASEOK : ignore case in 'import' statements (Windows).
\n
\
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
\n
\
"
;
"
;
#ifndef MS_WINDOWS
#ifndef MS_WINDOWS
...
...
Python/pythonrun.c
Dosyayı görüntüle @
0f599891
...
@@ -701,6 +701,7 @@ initstdio(void)
...
@@ -701,6 +701,7 @@ initstdio(void)
PyObject
*
std
=
NULL
;
PyObject
*
std
=
NULL
;
int
status
=
0
,
fd
;
int
status
=
0
,
fd
;
PyObject
*
encoding_attr
;
PyObject
*
encoding_attr
;
char
*
encoding
,
*
errors
;
/* Hack to avoid a nasty recursion issue when Python is invoked
/* Hack to avoid a nasty recursion issue when Python is invoked
in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
...
@@ -730,6 +731,16 @@ initstdio(void)
...
@@ -730,6 +731,16 @@ initstdio(void)
goto
error
;
goto
error
;
}
}
encoding
=
Py_GETENV
(
"PYTHONIOENCODING"
);
if
(
encoding
)
{
encoding
=
strdup
(
encoding
);
errors
=
strchr
(
encoding
,
':'
);
if
(
errors
)
{
*
errors
=
'\0'
;
errors
++
;
}
}
/* Set sys.stdin */
/* Set sys.stdin */
fd
=
fileno
(
stdin
);
fd
=
fileno
(
stdin
);
/* Under some conditions stdin, stdout and stderr may not be connected
/* Under some conditions stdin, stdout and stderr may not be connected
...
@@ -745,8 +756,8 @@ initstdio(void)
...
@@ -745,8 +756,8 @@ initstdio(void)
#endif
#endif
}
}
else
{
else
{
if
(
!
(
std
=
PyFile_FromFd
(
fd
,
"<stdin>"
,
"r"
,
-
1
,
NULL
,
NULL
,
if
(
!
(
std
=
PyFile_FromFd
(
fd
,
"<stdin>"
,
"r"
,
-
1
,
encoding
,
"
\n
"
,
0
)))
{
errors
,
"
\n
"
,
0
)))
{
goto
error
;
goto
error
;
}
}
}
/* if (fd < 0) */
}
/* if (fd < 0) */
...
@@ -765,8 +776,8 @@ initstdio(void)
...
@@ -765,8 +776,8 @@ initstdio(void)
#endif
#endif
}
}
else
{
else
{
if
(
!
(
std
=
PyFile_FromFd
(
fd
,
"<stdout>"
,
"w"
,
-
1
,
NULL
,
NULL
,
if
(
!
(
std
=
PyFile_FromFd
(
fd
,
"<stdout>"
,
"w"
,
-
1
,
encoding
,
"
\n
"
,
0
)))
{
errors
,
"
\n
"
,
0
)))
{
goto
error
;
goto
error
;
}
}
}
/* if (fd < 0) */
}
/* if (fd < 0) */
...
@@ -786,8 +797,8 @@ initstdio(void)
...
@@ -786,8 +797,8 @@ initstdio(void)
#endif
#endif
}
}
else
{
else
{
if
(
!
(
std
=
PyFile_FromFd
(
fd
,
"<stderr>"
,
"w"
,
-
1
,
NULL
,
NULL
,
if
(
!
(
std
=
PyFile_FromFd
(
fd
,
"<stderr>"
,
"w"
,
-
1
,
encoding
,
"
\n
"
,
0
)))
{
errors
,
"
\n
"
,
0
)))
{
goto
error
;
goto
error
;
}
}
}
/* if (fd < 0) */
}
/* if (fd < 0) */
...
...
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