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
a5071c2b
Kaydet (Commit)
a5071c2b
authored
Haz 04, 2016
tarafından
Kushal Das
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
NULL merge
üst
c79b06c3
c1cbeedf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
os.py
Lib/os.py
+14
-8
test_os.py
Lib/test/test_os.py
+15
-0
No files found.
Lib/os.py
Dosyayı görüntüle @
a5071c2b
...
...
@@ -877,29 +877,35 @@ def _fscodec():
def
fsencode
(
filename
):
"""
Encode filename to the filesystem encoding with 'surrogateescape' error
handler, return bytes unchanged. On Windows, use 'strict' error handler if
the file system encoding is 'mbcs' (which is the default encoding).
Encode filename (an os.PathLike, bytes, or str) to the filesystem
encoding with 'surrogateescape' error handler, return bytes unchanged.
On Windows, use 'strict' error handler if the file system encoding is
'mbcs' (which is the default encoding).
"""
filename
=
fspath
(
filename
)
if
isinstance
(
filename
,
bytes
):
return
filename
elif
isinstance
(
filename
,
str
):
return
filename
.
encode
(
encoding
,
errors
)
else
:
raise
TypeError
(
"expect bytes or str, not
%
s"
%
type
(
filename
)
.
__name__
)
raise
TypeError
(
"expected str, bytes or os.PathLike object, not "
+
path_type
.
__name__
)
def
fsdecode
(
filename
):
"""
Decode filename from the filesystem encoding with 'surrogateescape' error
handler, return str unchanged. On Windows, use 'strict' error handler if
the file system encoding is 'mbcs' (which is the default encoding).
Decode filename (an os.PathLike, bytes, or str) from the filesystem
encoding with 'surrogateescape' error handler, return str unchanged. On
Windows, use 'strict' error handler if the file system encoding is
'mbcs' (which is the default encoding).
"""
filename
=
fspath
(
filename
)
if
isinstance
(
filename
,
str
):
return
filename
elif
isinstance
(
filename
,
bytes
):
return
filename
.
decode
(
encoding
,
errors
)
else
:
raise
TypeError
(
"expect bytes or str, not
%
s"
%
type
(
filename
)
.
__name__
)
raise
TypeError
(
"expected str, bytes or os.PathLike object, not "
+
path_type
.
__name__
)
return
fsencode
,
fsdecode
...
...
Lib/test/test_os.py
Dosyayı görüntüle @
a5071c2b
...
...
@@ -3106,6 +3106,21 @@ class TestPEP519(unittest.TestCase):
for
s
in
'hello'
,
'goodbye'
,
'some/path/and/file'
:
self
.
assertEqual
(
s
,
os
.
fspath
(
s
))
def
test_fsencode_fsdecode_return_pathlike
(
self
):
class
Pathlike
:
def
__init__
(
self
,
path
):
self
.
path
=
path
def
__fspath__
(
self
):
return
self
.
path
for
p
in
"path/like/object"
,
b
"path/like/object"
:
pathlike
=
Pathlike
(
p
)
self
.
assertEqual
(
p
,
os
.
fspath
(
pathlike
))
self
.
assertEqual
(
b
"path/like/object"
,
os
.
fsencode
(
pathlike
))
self
.
assertEqual
(
"path/like/object"
,
os
.
fsdecode
(
pathlike
))
def
test_garbage_in_exception_out
(
self
):
vapor
=
type
(
'blah'
,
(),
{})
for
o
in
int
,
type
,
os
,
vapor
():
...
...
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