msg158008 - (view) |
Author: Chris Jerdonek (chris.jerdonek) *  |
Date: 2012-04-11 05:26 |
The Python documentation says that the html module (defining html.escape()) is new in Python 3.2: http://docs.python.org/dev/library/html.html However, it's importable in Python 3.1, but without the escape() function. See below for evidence. This prevents the usual EAFP code from not working: try: # Python 3.2 deprecates cgi.escape() and adds the html module as a replacement. import html except ImportError: import cgi as html > python Python 3.1.4 (default, Apr 10 2012, 21:58:25) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import html >>> html.escape Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'escape' >>> dir(html) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] >>> html.__file__ '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/html/__init__.py' |
|
|
msg158009 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
Date: 2012-04-11 06:01 |
The doc for the html module was added in 5633af590057 (see #2830) and it was previously undocumented even if it was importable. Moving the versionadded under html.escape sounds good to me. As a side note, it would be better to do try: # Python 3.2 deprecates cgi.escape() and adds html.escape() as a replacement. from html import escape except ImportError: from cgi import escape rather than importing the whole cgi module as "html" just to use the escape function. |
|
|
msg158011 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2012-04-11 06:50 |
"html" is a package. The "html.parser" module, which was already in 3.0, cannot be importable without a "html" package, so in all 3.x versions there was at least an empty html/__init__.py. That said, I have no objection to Ezio's suggestion. |
|
|
msg158014 - (view) |
Author: Chris Jerdonek (chris.jerdonek) *  |
Date: 2012-04-11 09:23 |
Ezio, I appreciate the suggestion/tip. Thanks. Regarding Georg's clarification that '"html" is a package,' I don't know if that was intended to correct my comment, Ezio's comment, the docs, or all of the above. In any case, that point should also be corrected in the docs as the docs currently say about html, "This *module* defines utilities to manipulate HTML." |
|
|
msg158016 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2012-04-11 09:38 |
The comment that "html" was a package was not meant as a correction, but as an explanation why it already exists previous to its status as an official "module" in 3.2. No correction to "package"is needed. |
|
|
msg158050 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2012-04-11 16:36 |
New changeset 2776ccf003cc by Georg Brandl in branch '3.2': Closes #14545: make clearer what was added. http://hg.python.org/cpython/rev/2776ccf003cc New changeset f5f8a7fd881c by Georg Brandl in branch 'default': #14545: merge 3.2 http://hg.python.org/cpython/rev/f5f8a7fd881c |
|
|