[Checkins] SVN: zope.tal/trunk/src/zope/tal/ Towards Py3K: stdlib reorganization
Marius Gedminas
cvs-admin at zope.org
Thu Feb 7 20:35:54 UTC 2013
Log message for revision 129181:
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.
Changed:
U zope.tal/trunk/src/zope/tal/htmltalparser.py
U zope.tal/trunk/src/zope/tal/xmlparser.py
-=-
Modified: zope.tal/trunk/src/zope/tal/htmltalparser.py
===================================================================
--- zope.tal/trunk/src/zope/tal/htmltalparser.py 2013-02-07 20:35:50 UTC (rev 129180)
+++ zope.tal/trunk/src/zope/tal/htmltalparser.py 2013-02-07 20:35:53 UTC (rev 129181)
@@ -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)
Modified: zope.tal/trunk/src/zope/tal/xmlparser.py
===================================================================
--- zope.tal/trunk/src/zope/tal/xmlparser.py 2013-02-07 20:35:50 UTC (rev 129180)
+++ zope.tal/trunk/src/zope/tal/xmlparser.py 2013-02-07 20:35:53 UTC (rev 129181)
@@ -17,7 +17,14 @@
"""
import logging
+try:
+ # Python 2.x
+ from urllib import urlopen
+except ImportError:
+ # Python 3.x
+ from urllib.request import urlopen
+
class XMLParser(object):
ordered_attributes = 0
@@ -80,8 +87,7 @@
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)
More information about the checkins
mailing list