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
34d20137
Kaydet (Commit)
34d20137
authored
Eyl 05, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18878: sunau.open now supports the context manager protocol. Based on
patches by Claudiu Popa and R. David Murray.
üst
555e57de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
15 deletions
+72
-15
3.4.rst
Doc/whatsnew/3.4.rst
+2
-0
sunau.py
Lib/sunau.py
+23
-8
test_sunau.py
Lib/test/test_sunau.py
+44
-7
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/whatsnew/3.4.rst
Dosyayı görüntüle @
34d20137
...
...
@@ -374,6 +374,8 @@ sunau
The :meth:`~sunau.getparams` method now returns a namedtuple rather than a
plain tuple. (Contributed by Claudiu Popa in :issue:`18901`.)
:meth:`sunau.open` now supports the context manager protocol (:issue:`18878`).
urllib
------
...
...
Lib/sunau.py
Dosyayı görüntüle @
34d20137
...
...
@@ -168,6 +168,12 @@ class Au_read:
if
self
.
_file
:
self
.
close
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
def
initfp
(
self
,
file
):
self
.
_file
=
file
self
.
_soundpos
=
0
...
...
@@ -303,6 +309,12 @@ class Au_write:
self
.
close
()
self
.
_file
=
None
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
def
initfp
(
self
,
file
):
self
.
_file
=
file
self
.
_framerate
=
0
...
...
@@ -410,14 +422,17 @@ class Au_write:
self
.
_patchheader
()
def
close
(
self
):
self
.
_ensure_header_written
()
if
self
.
_nframeswritten
!=
self
.
_nframes
or
\
self
.
_datalength
!=
self
.
_datawritten
:
self
.
_patchheader
()
self
.
_file
.
flush
()
if
self
.
_opened
and
self
.
_file
:
self
.
_file
.
close
()
self
.
_file
=
None
if
self
.
_file
:
try
:
self
.
_ensure_header_written
()
if
self
.
_nframeswritten
!=
self
.
_nframes
or
\
self
.
_datalength
!=
self
.
_datawritten
:
self
.
_patchheader
()
self
.
_file
.
flush
()
finally
:
if
self
.
_opened
and
self
.
_file
:
self
.
_file
.
close
()
self
.
_file
=
None
#
# private methods
...
...
Lib/test/test_sunau.py
Dosyayı görüntüle @
34d20137
from
test.support
import
run_unittest
,
TESTFN
from
test.support
import
TESTFN
,
unlink
import
unittest
import
pickle
import
os
...
...
@@ -18,10 +18,7 @@ class SunAUTest(unittest.TestCase):
def
tearDown
(
self
):
if
self
.
f
is
not
None
:
self
.
f
.
close
()
try
:
os
.
remove
(
TESTFN
)
except
OSError
:
pass
unlink
(
TESTFN
)
def
test_lin
(
self
):
self
.
f
=
sunau
.
open
(
TESTFN
,
'w'
)
...
...
@@ -84,9 +81,49 @@ class SunAUTest(unittest.TestCase):
dump
=
pickle
.
dumps
(
params
)
self
.
assertEqual
(
pickle
.
loads
(
dump
),
params
)
def
test_write_context_manager_calls_close
(
self
):
# Close checks for a minimum header and will raise an error
# if it is not set, so this proves that close is called.
with
self
.
assertRaises
(
sunau
.
Error
):
with
sunau
.
open
(
TESTFN
,
'wb'
)
as
f
:
pass
with
self
.
assertRaises
(
sunau
.
Error
):
with
open
(
TESTFN
,
'wb'
)
as
testfile
:
with
sunau
.
open
(
testfile
):
pass
def
test_context_manager_with_open_file
(
self
):
with
open
(
TESTFN
,
'wb'
)
as
testfile
:
with
sunau
.
open
(
testfile
)
as
f
:
f
.
setnchannels
(
nchannels
)
f
.
setsampwidth
(
sampwidth
)
f
.
setframerate
(
framerate
)
self
.
assertFalse
(
testfile
.
closed
)
with
open
(
TESTFN
,
'rb'
)
as
testfile
:
with
sunau
.
open
(
testfile
)
as
f
:
self
.
assertFalse
(
f
.
getfp
()
.
closed
)
params
=
f
.
getparams
()
self
.
assertEqual
(
params
[
0
],
nchannels
)
self
.
assertEqual
(
params
[
1
],
sampwidth
)
self
.
assertEqual
(
params
[
2
],
framerate
)
self
.
assertIsNone
(
f
.
getfp
())
self
.
assertFalse
(
testfile
.
closed
)
def
test_context_manager_with_filename
(
self
):
# If the file doesn't get closed, this test won't fail, but it will
# produce a resource leak warning.
with
sunau
.
open
(
TESTFN
,
'wb'
)
as
f
:
f
.
setnchannels
(
nchannels
)
f
.
setsampwidth
(
sampwidth
)
f
.
setframerate
(
framerate
)
with
sunau
.
open
(
TESTFN
)
as
f
:
self
.
assertFalse
(
f
.
getfp
()
.
closed
)
params
=
f
.
getparams
()
self
.
assertEqual
(
params
[
0
],
nchannels
)
self
.
assertEqual
(
params
[
1
],
sampwidth
)
self
.
assertEqual
(
params
[
2
],
framerate
)
self
.
assertIsNone
(
f
.
getfp
())
def
test_main
():
run_unittest
(
SunAUTest
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
34d20137
...
...
@@ -54,6 +54,9 @@ Core and Builtins
Library
-------
- Issue #18878: sunau.open now supports the context manager protocol. Based on
patches by Claudiu Popa and R. David Murray.
- Issue #18909: Fix _tkinter.tkapp.interpaddr() on Windows 64-bit, don'
t
cast
64
-
bit
pointer
to
long
(
32
bits
).
...
...
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