ticket id
000066
status
resolved
priority
???
assigned to
Waylan
Reported by:
Component:

in inlinepatterns.py we find:

if sys.version >= "3.0":
    from html import entities as htmlentitydefs
else:
    import html.entities

Why? html.entities works fine with Python 3.1.x and is used once in inlinepatterns.py, within AutomailPattern:

class AutomailPattern (Pattern):
    """
    Return a mailto link Element given an automail link (`<foo@example.com>`).
    """
    def handleMatch(self, m):
        el = markdown.etree.Element('a')
        email = m.group(2)
        if email.startswith("mailto:"):
            email = email[len("mailto:"):]

        def codepoint2name(code):
            """Return entity definition by code, or the code if not defined."""
            entity = html.entities.codepoint2name.get(code)

htmlentitydefs is never used and should not exist.

Comments

By Waylan on 7/11/2010

Yes, that is not needed for 3.1.x. However, it is required for 3.0. Of course, as Python itself dropped support for 3.0 on release of 3.1, we probably should too. Thanks for the reminder to do this. Of course, patches are welcome.

By Waylan on 7/12/2010

Ok, I looked a little closer at this and first of all we support python versions 2.4 through 3.1. I just checked and versions 2.4, 2.5 & 2.6 do not have an html module, so we still need to import htmlentitydefs.

By the way, the original report by some mystery person misrepresents the code. It actually looks like this:

if sys.version >= "3.0":
     from html import entities as htmlentitydefs
else:
     import htmlentitydefs

I wonder if the the mystery reporter looked at the source after running 2to3.

I haven't actually confirmed this yet, but I believe the 2to3 tool that ships with 3.1 will convert the import line for us. It was a bug in 3.0 that that didn't happen - which required the version check. If this is true, then we can lose the version check and drop support for the now dead 3.0.

By Waylan on 07/14/2010

I've confirmed that the 2to3 tool for Python 3.1 has in fact been fixed so that when run it makes the following change:

- import htmlentitydefs
+ from html import entities

And it changes any calls to htmlentitydefs to call entities instead. Additionally, given Python's drop of support for 3.0 upon the release of 3.1, we will drop support for Python 3.0 and only support 3.1+ in the Python 3 series. So no more special casing for 3.0 in our code.

Resolution

fixed

Powered by Sputnik | XHTML 1.1