diff options
author | Marius Gedminas <marius@gedmin.as> | 2013-02-07 20:35:53 +0000 |
---|---|---|
committer | Marius Gedminas <marius@gedmin.as> | 2013-02-07 20:35:53 +0000 |
commit | 98626ef004b6215b9e325a884d6e2c7e1683dfae (patch) | |
tree | e62cdcd530b215e8c0a75507e27aa4c394293c7c /src | |
parent | b1277c05599b137127611f584ffc95e07a49d60d (diff) | |
download | zope-tal-98626ef004b6215b9e325a884d6e2c7e1683dfae.tar.gz |
Towards Py3K: stdlib reorganization
StringIO is omitted from this checkin: we can't use io.StringIO nor
io.BytesIO, because zope.tal likes to write both byte strings and
Unicode objects into the same stream. This will require careful
untangling.
Diffstat (limited to 'src')
-rw-r--r-- | src/zope/tal/htmltalparser.py | 8 | ||||
-rw-r--r-- | src/zope/tal/xmlparser.py | 10 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/zope/tal/htmltalparser.py b/src/zope/tal/htmltalparser.py index b7376c1..cfa2952 100644 --- a/src/zope/tal/htmltalparser.py +++ b/src/zope/tal/htmltalparser.py @@ -14,7 +14,13 @@ """Parse HTML and compile to TALInterpreter intermediate code. """ -from HTMLParser import HTMLParser, HTMLParseError +# When Python 3 becomes mainstream please swap the try and except parts. +try: + # Python 2.x + from HTMLParser import HTMLParser, HTMLParseError +except ImportError: + # Python 3.x + from html.parser import HTMLParser, HTMLParseError from zope.tal.taldefs import (ZOPE_METAL_NS, ZOPE_TAL_NS, ZOPE_I18N_NS, METALError, TALError, I18NError) diff --git a/src/zope/tal/xmlparser.py b/src/zope/tal/xmlparser.py index 2bf87ba..fb777cb 100644 --- a/src/zope/tal/xmlparser.py +++ b/src/zope/tal/xmlparser.py @@ -17,6 +17,13 @@ This creates a parser with namespace processing enabled. """ import logging +try: + # Python 2.x + from urllib import urlopen +except ImportError: + # Python 3.x + from urllib.request import urlopen + class XMLParser(object): @@ -80,8 +87,7 @@ class XMLParser(object): self.parser.Parse(s, 1) def parseURL(self, url): - import urllib - self.parseStream(urllib.urlopen(url)) + self.parseStream(urlopen(url)) def parseStream(self, stream): self.parser.ParseFile(stream) |