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
44c66c72
Kaydet (Commit)
44c66c72
authored
Ara 29, 2012
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16486: Make aifc files work with 'with' as context managers.
üst
ff2840a7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
0 deletions
+30
-0
aifc.rst
Doc/library/aifc.rst
+4
-0
aifc.py
Lib/aifc.py
+12
-0
test_aifc.py
Lib/test/test_aifc.py
+12
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/aifc.rst
Dosyayı görüntüle @
44c66c72
...
...
@@ -51,6 +51,10 @@ Module :mod:`aifc` defines the following function:
used for writing, the file object should be seekable, unless you know ahead of
time how many samples you are going to write in total and use
:meth:`writeframesraw` and :meth:`setnframes`.
Objects returned by :func:`.open` also supports the :keyword:`with` statement.
.. versionchanged:: 3.4
Support for the :keyword:`with` statement was added.
Objects returned by :func:`.open` when a file is opened for reading have the
following methods:
...
...
Lib/aifc.py
Dosyayı görüntüle @
44c66c72
...
...
@@ -334,6 +334,12 @@ class Aifc_read:
# else, assume it is an open file object already
self
.
initfp
(
f
)
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
#
# User visible methods.
#
...
...
@@ -553,6 +559,12 @@ class Aifc_write:
def
__del__
(
self
):
self
.
close
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
#
# User visible methods.
#
...
...
Lib/test/test_aifc.py
Dosyayı görüntüle @
44c66c72
...
...
@@ -43,6 +43,18 @@ class AIFCTest(unittest.TestCase):
(
2
,
2
,
48000
,
14400
,
b
'NONE'
,
b
'not compressed'
),
)
def
test_context_manager
(
self
):
with
open
(
self
.
sndfilepath
,
'rb'
)
as
testfile
:
with
aifc
.
open
(
testfile
)
as
f
:
pass
self
.
assertEqual
(
testfile
.
closed
,
True
)
with
open
(
TESTFN
,
'wb'
)
as
testfile
:
with
self
.
assertRaises
(
aifc
.
Error
):
with
aifc
.
open
(
testfile
,
'wb'
)
as
fout
:
pass
self
.
assertEqual
(
testfile
.
closed
,
True
)
fout
.
close
()
# do nothing
def
test_read
(
self
):
f
=
self
.
f
=
aifc
.
open
(
self
.
sndfilepath
)
self
.
assertEqual
(
f
.
readframes
(
0
),
b
''
)
...
...
Misc/NEWS
Dosyayı görüntüle @
44c66c72
...
...
@@ -200,6 +200,8 @@ Core and Builtins
Library
-------
-
Issue
#
16486
:
Make
aifc
files
work
with
'with'
as
context
managers
.
-
Issue
#
16485
:
Fix
file
descriptor
not
being
closed
if
file
header
patching
fails
on
closing
of
aifc
file
.
...
...
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