Python 3.2 and html.escape function

Discussion in 'Python' started by Gerald Britton, Feb 20, 2011.

  1. I see that Python 3.2 includes a new module -- html -- with a single
    function -- escape. I would like to know how this function differs
    from xml.sax.saxutils.escape and, if there is no difference (or only a
    minor one), what the need is for this new module and its lone function

    --
    Gerald Britton
     
    Gerald Britton, Feb 20, 2011
    #1
    1. Advertising

  2. On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote:

    > I see that Python 3.2 includes a new module -- html -- with a single
    > function -- escape. I would like to know how this function differs from
    > xml.sax.saxutils.escape and, if there is no difference (or only a minor
    > one), what the need is for this new module and its lone function


    Unless the html API has changed radically since Python 3.2a, I believe
    you are mistaken.

    [steve@sylar ~]$ python3.2
    Python 3.2a1 (r32a1:83318, Aug 12 2010, 02:17:22)
    [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import html
    >>> help(html)


    which gives me the following information:



    Help on package html:

    NAME
    html - # This directory is a Python package.

    FILE
    /usr/local/lib/python3.2/html/__init__.py

    MODULE DOCS
    http://docs.python.org/library/html

    PACKAGE CONTENTS
    entities
    parser



    So html is not a module, but a package that includes two sub-modules,
    entities and parser. I see no sign of anything called "escape" in either
    the top level html package, or either of the sub-modules, and the word
    "escape" only appears twice in the whole package, both times as
    "unescape":


    [steve@sylar ~]$ cd /usr/local/lib/python3.2/html/
    [steve@sylar html]$ ls
    entities.py __init__.py parser.py __pycache__
    [steve@sylar html]$ grep -i escape *.py
    parser.py: attrvalue = self.unescape(attrvalue)
    parser.py: def unescape(self, s):


    So I don't know what you are looking at, but I don't believe it is the
    standard html package in the Python standard library. Perhaps you have
    accidentally shadowed it with your own html module? Try this:

    >>> import html
    >>> html.__file__

    '/usr/local/lib/python3.2/html/__init__.py'



    --
    Steven
     
    Steven D'Aprano, Feb 20, 2011
    #2
    1. Advertising

  3. Gerald Britton

    Peter Otten Guest

    Steven D'Aprano wrote:

    > On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote:
    >
    >> I see that Python 3.2 includes a new module -- html -- with a single
    >> function -- escape. I would like to know how this function differs from
    >> xml.sax.saxutils.escape and, if there is no difference (or only a minor
    >> one), what the need is for this new module and its lone function

    >
    > Unless the html API has changed radically since Python 3.2a, I believe
    > you are mistaken.


    Adding a function is not /that/ radical, and it has happened, see

    http://docs.python.org/dev/py3k/library/html.html

    The check-in message that is linked there claims that html.escape() is
    supposed to replace cgi.escape()

    Side note: there has been a discussion whether it's a good idea to put a
    function into a package, see

    http://mail.python.org/pipermail/python-dev/2011-January/107635.html
     
    Peter Otten, Feb 20, 2011
    #3
  4. On Sun, 20 Feb 2011 15:33:39 +0100, Peter Otten wrote:

    > Steven D'Aprano wrote:
    >
    >> On Sun, 20 Feb 2011 08:15:35 -0500, Gerald Britton wrote:
    >>
    >>> I see that Python 3.2 includes a new module -- html -- with a single
    >>> function -- escape. I would like to know how this function differs
    >>> from xml.sax.saxutils.escape and, if there is no difference (or only a
    >>> minor one), what the need is for this new module and its lone function

    >>
    >> Unless the html API has changed radically since Python 3.2a, I believe
    >> you are mistaken.

    >
    > Adding a function is not /that/ radical, and it has happened, see
    >
    > http://docs.python.org/dev/py3k/library/html.html


    Well, I just learned something, thank you. I was under the mistaken
    impression that adding new functionality after the first alpha release
    was not permitted by the Python devs.



    --
    Steven
     
    Steven D'Aprano, Feb 21, 2011
    #4
  5. Gerald Britton

    Rafe Kettler Guest

    On Feb 20, 8:15 am, Gerald Britton <> wrote:
    > I see that Python 3.2 includes a new module -- html -- with a single
    > function -- escape.  I would like to know how this function differs
    > from xml.sax.saxutils.escape and, if there is no difference (or only a
    > minor one), what the need is for this new module and its lone function
    >
    > --
    > Gerald Britton


    I believe that they're trying to organize a new top-level package
    called html that will, at some point, contain all HTML functionality.
    It's sort of similar to what they're doing with the concurrent package.
     
    Rafe Kettler, Feb 21, 2011
    #5
  6. > Well, I just learned something, thank you. I was under the mistaken
    > impression that adding new functionality after the first alpha release
    > was not permitted by the Python devs.


    It's the first beta release after which no new functionality could be added.

    Regards,
    Martin
     
    Martin v. Loewis, Feb 21, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Dupont

    Html escape text

    Lloyd Dupont, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    4,404
    Lloyd Dupont
    Jan 10, 2006
  2. harrelson
    Replies:
    3
    Views:
    3,925
    Craig Ringer
    Dec 10, 2004
  3. slomo
    Replies:
    5
    Views:
    1,582
    Duncan Booth
    Dec 2, 2007
  4. Gerald Britton

    Python 3.2 and html.escape function

    Gerald Britton, Feb 20, 2011, in forum: Python
    Replies:
    0
    Views:
    309
    Gerald Britton
    Feb 20, 2011
  5. khinester

    how to escape and pass html as variable

    khinester, Jul 19, 2010, in forum: Javascript
    Replies:
    1
    Views:
    102
    Martin Honnen
    Jul 19, 2010
Loading...

Share This Page