Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note explicit support for Python 3.5 #5

Merged
merged 2 commits into from Nov 13, 2015

Conversation

felixonmars
Copy link
Contributor

No description provided.

@felixonmars
Copy link
Contributor Author

Looks like I was opening this too fast. The error is harder to fix than I expected, as the parser will never raise an error in Python 3.5 if I understand it correctly...

@mgedmin
Copy link
Member

mgedmin commented Nov 13, 2015

@mgedmin
Copy link
Member

mgedmin commented Nov 13, 2015

HTMLParseError is only used as a base class for new exceptions defined in zope.tal.htmltalparser.

Suggestion:

try:
    # Python 2.x
    from HTMLParser import HTMLParser, HTMLParseError
except ImportError:
    # Python 3.x
    from html.parser import HTMLParser
    try:
        from html.parser import HTMLParseError
    except ImportError:
        # Python 3.5 removed it, but we need it as a base class
        # so here's a copy taken from Python 3.4:
        class HTMLParseError(Exception):
            def __init__(self, msg, position=(None, None)):
                assert msg
                self.msg = msg
                self.lineno = position[0]
                self.offset = position[1]

            def __str__(self):
                result = self.msg
                if self.lineno is not None:
                    result = result + ", at line %d" % self.lineno
                if self.offset is not None:
                    result = result + ", column %d" % (self.offset + 1)
                return result

@felixonmars
Copy link
Contributor Author

Updated accordingly, thanks! I originally thought it rely on the standard library to raise the exception :P

mgedmin added a commit that referenced this pull request Nov 13, 2015
Note explicit support for Python 3.5
@mgedmin mgedmin merged commit 65009b2 into zopefoundation:master Nov 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants