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
44ae4a2a
Kaydet (Commit)
44ae4a2a
authored
Kas 30, 2011
tarafından
Nadeem Vawda
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make error handling in BZ2File.{readable,seekable,writable,fileno} consistent with TextIOWrapper.
Also, add tests for these methods.
üst
3ff069eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
bz2.py
Lib/bz2.py
+3
-3
test_bz2.py
Lib/test/test_bz2.py
+56
-1
No files found.
Lib/bz2.py
Dosyayı görüntüle @
44ae4a2a
...
...
@@ -125,6 +125,7 @@ class BZ2File(io.BufferedIOBase):
def
fileno
(
self
):
"""Return the file descriptor for the underlying file."""
self
.
_check_not_closed
()
return
self
.
_fp
.
fileno
()
def
seekable
(
self
):
...
...
@@ -133,10 +134,12 @@ class BZ2File(io.BufferedIOBase):
def
readable
(
self
):
"""Return whether the file was opened for reading."""
self
.
_check_not_closed
()
return
self
.
_mode
in
(
_MODE_READ
,
_MODE_READ_EOF
)
def
writable
(
self
):
"""Return whether the file was opened for writing."""
self
.
_check_not_closed
()
return
self
.
_mode
==
_MODE_WRITE
# Mode-checking helper functions.
...
...
@@ -147,17 +150,14 @@ class BZ2File(io.BufferedIOBase):
def
_check_can_read
(
self
):
if
not
self
.
readable
():
self
.
_check_not_closed
()
raise
io
.
UnsupportedOperation
(
"File not open for reading"
)
def
_check_can_write
(
self
):
if
not
self
.
writable
():
self
.
_check_not_closed
()
raise
io
.
UnsupportedOperation
(
"File not open for writing"
)
def
_check_can_seek
(
self
):
if
not
self
.
seekable
():
self
.
_check_not_closed
()
raise
io
.
UnsupportedOperation
(
"Seeking is only supported "
"on files open for reading"
)
...
...
Lib/test/test_bz2.py
Dosyayı görüntüle @
44ae4a2a
...
...
@@ -348,8 +348,63 @@ class BZ2FileTest(BaseTest):
def
testFileno
(
self
):
self
.
createTempFile
()
with
open
(
self
.
filename
,
'rb'
)
as
rawf
:
with
BZ2File
(
fileobj
=
rawf
)
as
bz2f
:
bz2f
=
BZ2File
(
fileobj
=
rawf
)
try
:
self
.
assertEqual
(
bz2f
.
fileno
(),
rawf
.
fileno
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
fileno
)
def
testSeekable
(
self
):
bz2f
=
BZ2File
(
fileobj
=
BytesIO
(
self
.
DATA
))
try
:
self
.
assertTrue
(
bz2f
.
seekable
())
bz2f
.
read
()
self
.
assertTrue
(
bz2f
.
seekable
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
seekable
)
bz2f
=
BZ2File
(
fileobj
=
BytesIO
(),
mode
=
"w"
)
try
:
self
.
assertFalse
(
bz2f
.
seekable
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
seekable
)
def
testReadable
(
self
):
bz2f
=
BZ2File
(
fileobj
=
BytesIO
(
self
.
DATA
))
try
:
self
.
assertTrue
(
bz2f
.
readable
())
bz2f
.
read
()
self
.
assertTrue
(
bz2f
.
readable
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
readable
)
bz2f
=
BZ2File
(
fileobj
=
BytesIO
(),
mode
=
"w"
)
try
:
self
.
assertFalse
(
bz2f
.
readable
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
readable
)
def
testWritable
(
self
):
bz2f
=
BZ2File
(
fileobj
=
BytesIO
(
self
.
DATA
))
try
:
self
.
assertFalse
(
bz2f
.
writable
())
bz2f
.
read
()
self
.
assertFalse
(
bz2f
.
writable
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
writable
)
bz2f
=
BZ2File
(
fileobj
=
BytesIO
(),
mode
=
"w"
)
try
:
self
.
assertTrue
(
bz2f
.
writable
())
finally
:
bz2f
.
close
()
self
.
assertRaises
(
ValueError
,
bz2f
.
writable
)
def
testOpenDel
(
self
):
self
.
createTempFile
()
...
...
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