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
6ce29fa7
Kaydet (Commit)
6ce29fa7
authored
Eki 30, 2010
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix test_mailbox by supporting context manager protocol for get_file() returns.
üst
849e12bf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
mailbox.rst
Doc/library/mailbox.rst
+7
-3
mailbox.py
Lib/mailbox.py
+14
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/mailbox.rst
Dosyayı görüntüle @
6ce29fa7
...
...
@@ -180,15 +180,19 @@ Maildir, mbox, MH, Babyl, and MMDF.
.. method:: get_file(key)
Return a file-like representation of the message corresponding to *key*,
or raise a :exc:`KeyError` exception if no such message exists. The
file-like object behaves as if open in binary mode. This file should be
or raise a :exc:`KeyError` exception if no such message exists.
The
file-like object behaves as if open in binary mode.
This file should be
closed once it is no longer needed.
.. versionadded:: 3.2
The file-like object supports the context manager protocol, so that
you can use a :keyword:`with` statement to automatically close it.
.. note::
Unlike other representations of messages, file-like representations are
not necessarily independent of the :class:`Mailbox` instance that
created them or of the underlying mailbox. More specific documentation
created them or of the underlying mailbox.
More specific documentation
is provided by each subclass.
...
...
Lib/mailbox.py
Dosyayı görüntüle @
6ce29fa7
...
...
@@ -1827,6 +1827,8 @@ class _ProxyFile:
def
close
(
self
):
"""Close the file."""
if
hasattr
(
self
.
_file
,
'close'
):
self
.
_file
.
close
()
del
self
.
_file
def
_read
(
self
,
size
,
read_method
):
...
...
@@ -1838,6 +1840,13 @@ class _ProxyFile:
self
.
_pos
=
self
.
_file
.
tell
()
return
result
def
__enter__
(
self
):
"""Context manager protocol support."""
return
self
def
__exit__
(
self
,
*
exc
):
self
.
close
()
class
_PartialFile
(
_ProxyFile
):
"""A read-only wrapper of part of a file."""
...
...
@@ -1871,6 +1880,11 @@ class _PartialFile(_ProxyFile):
size
=
remaining
return
_ProxyFile
.
_read
(
self
,
size
,
read_method
)
def
close
(
self
):
# do *not* close the underlying file object for partial files,
# since it's global to the mailbox object
del
self
.
_file
def
_lock_file
(
f
,
dotlock
=
True
):
"""Lock file f using lockf and dot locking."""
...
...
Misc/NEWS
Dosyayı görüntüle @
6ce29fa7
...
...
@@ -57,6 +57,9 @@ Core and Builtins
Library
-------
- Support context manager protocol for file-like objects returned by
mailbox ``get_file()`` methods.
- Issue #10246: uu.encode didn't close file objects explicitly when filenames
were given to it. Patch by Brian Brazil.
...
...
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