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
bf5e9604
Kaydet (Commit)
bf5e9604
authored
Şub 06, 2015
tarafından
Berker Peksag
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20289: cgi.FieldStorage() now supports the context management protocol.
üst
088ca8b9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
6 deletions
+35
-6
cgi.rst
Doc/library/cgi.rst
+7
-0
3.5.rst
Doc/whatsnew/3.5.rst
+6
-0
cgi.py
Lib/cgi.py
+6
-0
test_cgi.py
Lib/test/test_cgi.py
+13
-6
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/cgi.rst
Dosyayı görüntüle @
bf5e9604
...
...
@@ -157,6 +157,9 @@ return bytes)::
if not line: break
linecount = linecount + 1
:class:`FieldStorage` objects also support being used in a :keyword:`with`
statement, which will automatically close them when done.
If an error is encountered when obtaining the contents of an uploaded file
(for example, when the user interrupts the form submission by clicking on
a Back or Cancel button) the :attr:`~FieldStorage.done` attribute of the
...
...
@@ -182,6 +185,10 @@ A form submitted via POST that also has a query string will contain both
The :attr:`~FieldStorage.file` attribute is automatically closed upon the
garbage collection of the creating :class:`FieldStorage` instance.
.. versionchanged:: 3.5
Added support for the context management protocol to the
:class:`FieldStorage` class.
Higher Level Interface
----------------------
...
...
Doc/whatsnew/3.5.rst
Dosyayı görüntüle @
bf5e9604
...
...
@@ -136,6 +136,12 @@ New Modules
Improved Modules
================
cgi
---
* :class:`FieldStorage` now supports the context management protocol.
(Contributed by Berker Peksag in :issue:`20289`.)
code
----
...
...
Lib/cgi.py
Dosyayı görüntüle @
bf5e9604
...
...
@@ -566,6 +566,12 @@ class FieldStorage:
except
AttributeError
:
pass
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
file
.
close
()
def
__repr__
(
self
):
"""Return a printable representation."""
return
"FieldStorage(
%
r,
%
r,
%
r)"
%
(
...
...
Lib/test/test_cgi.py
Dosyayı görüntüle @
bf5e9604
from
test.support
import
run_unittest
,
check_warnings
from
test.support
import
check_warnings
import
cgi
import
os
import
sys
...
...
@@ -307,6 +307,17 @@ Content-Type: text/plain
got
=
getattr
(
files
[
x
],
k
)
self
.
assertEqual
(
got
,
exp
)
def
test_fieldstorage_as_context_manager
(
self
):
fp
=
BytesIO
(
b
'x'
*
10
)
env
=
{
'REQUEST_METHOD'
:
'PUT'
}
with
cgi
.
FieldStorage
(
fp
=
fp
,
environ
=
env
)
as
fs
:
content
=
fs
.
file
.
read
()
self
.
assertFalse
(
fs
.
file
.
closed
)
self
.
assertTrue
(
fs
.
file
.
closed
)
self
.
assertEqual
(
content
,
'x'
*
10
)
with
self
.
assertRaisesRegex
(
ValueError
,
'I/O operation on closed file'
):
fs
.
file
.
read
()
_qs_result
=
{
'key1'
:
'value1'
,
'key2'
:
[
'value2x'
,
'value2y'
],
...
...
@@ -481,9 +492,5 @@ Content-Transfer-Encoding: binary
--AaB03x--
"""
def
test_main
():
run_unittest
(
CgiTests
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
bf5e9604
...
...
@@ -235,6 +235,9 @@ Core and Builtins
Library
-------
- Issue #20289: cgi.FieldStorage() now supports the context management
protocol.
- Issue #13128: Print response headers for CONNECT requests when debuglevel
> 0. Patch by Demian Brecht.
...
...
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