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
04dc25c5
Kaydet (Commit)
04dc25c5
authored
Eki 03, 2008
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #3187: Add sys.setfilesystemencoding.
üst
efb14a88
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
4 deletions
+58
-4
sys.rst
Doc/library/sys.rst
+8
-0
fileobject.h
Include/fileobject.h
+2
-1
test_sys.py
Lib/test/test_sys.py
+5
-0
NEWS
Misc/NEWS
+2
-0
bltinmodule.c
Python/bltinmodule.c
+22
-3
sysmodule.c
Python/sysmodule.c
+19
-0
No files found.
Doc/library/sys.rst
Dosyayı görüntüle @
04dc25c5
...
...
@@ -578,6 +578,14 @@ always available.
:file:`/usr/include/dlfcn.h` using the :program:`h2py` script. Availability:
Unix.
.. function:: setfilesystemencoding(enc)
Set the encoding used when converting Python strings to file names to *enc*.
By default, Python tries to determine the encoding it should use automatically
on Unix; on Windows, it avoids such conversion completely. This function can
be used when Python's determination of the encoding needs to be overwritten,
e.g. when not all file names on disk can be decoded using the encoding that
Python had chosen.
.. function:: setprofile(profilefunc)
...
...
Include/fileobject.h
Dosyayı görüntüle @
04dc25c5
...
...
@@ -20,7 +20,8 @@ PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
If non-NULL, this is different than the default encoding for strings
*/
PyAPI_DATA
(
const
char
*
)
Py_FileSystemDefaultEncoding
;
PyAPI_DATA
(
const
int
)
Py_HasFileSystemDefaultEncoding
;
PyAPI_DATA
(
int
)
Py_HasFileSystemDefaultEncoding
;
PyAPI_FUNC
(
int
)
_Py_SetFileSystemEncoding
(
PyObject
*
);
/* Internal API
...
...
Lib/test/test_sys.py
Dosyayı görüntüle @
04dc25c5
...
...
@@ -658,6 +658,11 @@ class SizeofTest(unittest.TestCase):
# sys.flags
check
(
sys
.
flags
,
size
(
vh
)
+
self
.
P
*
len
(
sys
.
flags
))
def
test_setfilesystemencoding
(
self
):
old
=
sys
.
getfilesystemencoding
()
sys
.
setfilesystemencoding
(
"iso-8859-1"
)
self
.
assertEqual
(
sys
.
getfilesystemencoding
(),
"iso-8859-1"
)
sys
.
setfilesystemencoding
(
old
)
def
test_main
():
test
.
support
.
run_unittest
(
SysModuleTest
,
SizeofTest
)
...
...
Misc/NEWS
Dosyayı görüntüle @
04dc25c5
...
...
@@ -25,6 +25,8 @@ Core and Builtins
Library
-------
- Issue #3187: Add sys.setfilesystemencoding.
- Issue #3187: Better support for "undecodable" filenames. Code by Victor
Stinner, with small tweaks by GvR.
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
04dc25c5
...
...
@@ -17,15 +17,34 @@
*/
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
const
char
*
Py_FileSystemDefaultEncoding
=
"mbcs"
;
const
int
Py_HasFileSystemDefaultEncoding
=
1
;
int
Py_HasFileSystemDefaultEncoding
=
1
;
#elif defined(__APPLE__)
const
char
*
Py_FileSystemDefaultEncoding
=
"utf-8"
;
const
int
Py_HasFileSystemDefaultEncoding
=
1
;
int
Py_HasFileSystemDefaultEncoding
=
1
;
#else
const
char
*
Py_FileSystemDefaultEncoding
=
NULL
;
/* use default */
const
int
Py_HasFileSystemDefaultEncoding
=
0
;
int
Py_HasFileSystemDefaultEncoding
=
0
;
#endif
int
_Py_SetFileSystemEncoding
(
PyObject
*
s
)
{
PyObject
*
defenc
;
if
(
!
PyUnicode_Check
(
s
))
{
PyErr_BadInternalCall
();
return
-
1
;
}
defenc
=
_PyUnicode_AsDefaultEncodedString
(
s
,
NULL
);
if
(
!
defenc
)
return
-
1
;
if
(
!
Py_HasFileSystemDefaultEncoding
&&
Py_FileSystemDefaultEncoding
)
/* A file system encoding was set at run-time */
free
((
char
*
)
Py_FileSystemDefaultEncoding
);
Py_FileSystemDefaultEncoding
=
strdup
(
PyBytes_AsString
(
defenc
));
Py_HasFileSystemDefaultEncoding
=
0
;
return
0
;
}
static
PyObject
*
builtin___build_class__
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
...
...
Python/sysmodule.c
Dosyayı görüntüle @
04dc25c5
...
...
@@ -216,7 +216,24 @@ Return the encoding used to convert Unicode filenames in\n\
operating system filenames."
);
static
PyObject
*
sys_setfilesystemencoding
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
new_encoding
;
if
(
!
PyArg_ParseTuple
(
args
,
"U:setfilesystemencoding"
,
&
new_encoding
))
return
NULL
;
if
(
_Py_SetFileSystemEncoding
(
new_encoding
))
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyDoc_STRVAR
(
setfilesystemencoding_doc
,
"setfilesystemencoding(string) -> None
\n
\
\n
\
Set the encoding used to convert Unicode filenames in
\n
\
operating system filenames."
);
static
PyObject
*
sys_intern
(
PyObject
*
self
,
PyObject
*
args
)
...
...
@@ -872,6 +889,8 @@ static PyMethodDef sys_methods[] = {
#endif
{
"setdefaultencoding"
,
sys_setdefaultencoding
,
METH_VARARGS
,
setdefaultencoding_doc
},
{
"setfilesystemencoding"
,
sys_setfilesystemencoding
,
METH_VARARGS
,
setfilesystemencoding_doc
},
{
"setcheckinterval"
,
sys_setcheckinterval
,
METH_VARARGS
,
setcheckinterval_doc
},
{
"getcheckinterval"
,
sys_getcheckinterval
,
METH_NOARGS
,
...
...
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