[ python-Bugs-953177 ] cgi module documentation could mention
getlist
SourceForge.net
noreply at sourceforge.net
Sun Jun 6 19:29:29 EDT 2004
Bugs item #953177, was opened at 2004-05-13 07:15
Message generated for change (Settings changed) made by akuchling
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=953177&group_id=5470
Category: Documentation
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Richard Jones (richard)
Assigned to: A.M. Kuchling (akuchling)
Summary: cgi module documentation could mention getlist
Initial Comment:
Section "11.2.2 Using the cgi module" at
http://www.python.org/dev/doc/devel/lib/node411.html has a
discussion about how the module handles multiple values with the
same name. It even presents a section of code describing how to
handle the situation. It could alternatively just make mention of its
own getlist() method.
----------------------------------------------------------------------
>Comment By: A.M. Kuchling (akuchling)
Date: 2004-06-06 19:29
Message:
Logged In: YES
user_id=11375
Committed to CVS HEAD and to 2.3 branch.
----------------------------------------------------------------------
Comment By: A.M. Kuchling (akuchling)
Date: 2004-06-05 16:22
Message:
Logged In: YES
user_id=11375
Ready to check in the fix, but SF CVS is down.
----------------------------------------------------------------------
Comment By: Paul Moore (pmoore)
Date: 2004-06-05 12:00
Message:
Logged In: YES
user_id=113328
The following patch seems to be what is required (inline
because I can't upload files :-()
Index: lib/libcgi.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libcgi.tex,v
retrieving revision 1.43
diff -u -r1.43 libcgi.tex
--- lib/libcgi.tex 23 Jan 2004 04:05:27 -0000 1.43
+++ lib/libcgi.tex 5 Jun 2004 15:59:45 -0000
@@ -135,19 +135,14 @@
\samp{form.getvalue(\var{key})} would return a list of strings.
If you expect this possibility
(when your HTML form contains multiple fields with the same
name), use
-the \function{isinstance()} built-in function to determine
whether you
-have a single instance or a list of instances. For
example, this
+the \function{getlist()}, which always returns a list of
values (so that you
+do not need to special-case the single item case). For
example, this
code concatenates any number of username fields, separated by
commas:
\begin{verbatim}
-value = form.getvalue("username", "")
-if isinstance(value, list):
- # Multiple username fields specified
- usernames = ",".join(value)
-else:
- # Single or no username field specified
- usernames = value
+values = form.getlist("username")
+usernames = ",".join(values)
\end{verbatim}
If a field represents an uploaded file, accessing the value
via the
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=953177&group_id=5470
More information about the Python-bugs-list
mailing list