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
fd1c3d30
Kaydet (Commit)
fd1c3d30
authored
Eki 13, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #19198: Improved cross-references in the cgi module documentation.
üst
83620061
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
cgi.rst
Doc/library/cgi.rst
+19
-17
No files found.
Doc/library/cgi.rst
Dosyayı görüntüle @
fd1c3d30
...
@@ -97,7 +97,7 @@ standard input, it should be instantiated only once.
...
@@ -97,7 +97,7 @@ standard input, it should be instantiated only once.
The :class:`FieldStorage` instance can be indexed like a Python dictionary.
The :class:`FieldStorage` instance can be indexed like a Python dictionary.
It allows membership testing with the :keyword:`in` operator, and also supports
It allows membership testing with the :keyword:`in` operator, and also supports
the standard dictionary method :meth:`keys` and the built-in function
the standard dictionary method :meth:`
~dict.
keys` and the built-in function
:func:`len`. Form fields containing empty strings are ignored and do not appear
:func:`len`. Form fields containing empty strings are ignored and do not appear
in the dictionary; to keep such values, provide a true value for the optional
in the dictionary; to keep such values, provide a true value for the optional
*keep_blank_values* keyword parameter when creating the :class:`FieldStorage`
*keep_blank_values* keyword parameter when creating the :class:`FieldStorage`
...
@@ -119,30 +119,32 @@ string::
...
@@ -119,30 +119,32 @@ string::
Here the fields, accessed through ``form[key]``, are themselves instances of
Here the fields, accessed through ``form[key]``, are themselves instances of
:class:`FieldStorage` (or :class:`MiniFieldStorage`, depending on the form
:class:`FieldStorage` (or :class:`MiniFieldStorage`, depending on the form
encoding). The :attr:`
value` attribute of the instance yields the string value
encoding). The :attr:`
~FieldStorage.value` attribute of the instance yields
of the field. The :meth:`getvalue` method returns this string value directly;
the string value of the field. The :meth:`~FieldStorage.getvalue` method
it also accepts an optional second argument as a default to return if the
returns this string value directly; it also accepts an optional second argument
requested key is not present.
as a default to return if the
requested key is not present.
If the submitted form data contains more than one field with the same name, the
If the submitted form data contains more than one field with the same name, the
object retrieved by ``form[key]`` is not a :class:`FieldStorage` or
object retrieved by ``form[key]`` is not a :class:`FieldStorage` or
:class:`MiniFieldStorage` instance but a list of such instances. Similarly, in
:class:`MiniFieldStorage` instance but a list of such instances. Similarly, in
this situation, ``form.getvalue(key)`` would return a list of strings. If you
this situation, ``form.getvalue(key)`` would return a list of strings. If you
expect this possibility (when your HTML form contains multiple fields with the
expect this possibility (when your HTML form contains multiple fields with the
same name), use the :
func:`getlist` function, which always returns a list of
same name), use the :
meth:`~FieldStorage.getlist` method, which always returns
values (so that you do not need to special-case the single item case). For
a list of values (so that you do not need to special-case the single item
example, this code concatenates any number of username fields, separated by
case). For example, this code concatenates any number of username fields,
commas::
separated by
commas::
value = form.getlist("username")
value = form.getlist("username")
usernames = ",".join(value)
usernames = ",".join(value)
If a field represents an uploaded file, accessing the value via the
If a field represents an uploaded file, accessing the value via the
:attr:`value` attribute or the :func:`getvalue` method reads the entire file in
:attr:`~FieldStorage.value` attribute or the :meth:`~FieldStorage.getvalue`
memory as bytes. This may not be what you want. You can test for an uploaded
method reads the entire file in memory as bytes. This may not be what you
file by testing either the :attr:`filename` attribute or the :attr:`!file`
want. You can test for an uploaded file by testing either the
:attr:`~FieldStorage.filename` attribute or the :attr:`~FieldStorage.file`
attribute. You can then read the data at leisure from the :attr:`!file`
attribute. You can then read the data at leisure from the :attr:`!file`
attribute (the :func:`read` and :func:`readline` methods will return bytes)::
attribute (the :func:`~io.RawIOBase.read` and :func:`~io.IOBase.readline`
methods will return bytes)::
fileitem = form["userfile"]
fileitem = form["userfile"]
if fileitem.file:
if fileitem.file:
...
@@ -155,8 +157,8 @@ attribute (the :func:`read` and :func:`readline` methods will return bytes)::
...
@@ -155,8 +157,8 @@ attribute (the :func:`read` and :func:`readline` methods will return bytes)::
If an error is encountered when obtaining the contents of an uploaded file
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
(for example, when the user interrupts the form submission by clicking on
a Back or Cancel button) the :attr:`
done` attribute of the object for
the
a Back or Cancel button) the :attr:`
~FieldStorage.done` attribute of
the
field will be set to the value -1.
object for the
field will be set to the value -1.
The file upload draft standard entertains the possibility of uploading multiple
The file upload draft standard entertains the possibility of uploading multiple
files from one field (using a recursive :mimetype:`multipart/\*` encoding).
files from one field (using a recursive :mimetype:`multipart/\*` encoding).
...
@@ -223,8 +225,8 @@ Therefore, the appropriate way to read form data values was to always use the
...
@@ -223,8 +225,8 @@ Therefore, the appropriate way to read form data values was to always use the
code which checks whether the obtained value is a single value or a list of
code which checks whether the obtained value is a single value or a list of
values. That's annoying and leads to less readable scripts.
values. That's annoying and leads to less readable scripts.
A more convenient approach is to use the methods :meth:`
getfirst` and
A more convenient approach is to use the methods :meth:`
~FieldStorage.getfirst`
:meth:`
getlist` provided by this higher level interface.
and :meth:`~FieldStorage.
getlist` provided by this higher level interface.
.. method:: FieldStorage.getfirst(name, default=None)
.. method:: FieldStorage.getfirst(name, default=None)
...
...
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