[Python-checkins] cpython (merge 3.3 -> default): merge with 3.3
georg.brandl
python-checkins at python.org
Sun May 12 12:47:29 CEST 2013
http://hg.python.org/cpython/rev/ca133fab2f8e
changeset: 83743:ca133fab2f8e
parent: 83731:e98cf2cec516
parent: 83741:19a5fbb924b1
user: Georg Brandl <georg at python.org>
date: Sun May 12 12:08:05 2013 +0200
summary:
merge with 3.3
files:
Lib/test/test_sax.py | 31 +++++++++++++++++++++++++++++
Lib/xml/sax/saxutils.py | 5 ++++
Misc/NEWS | 9 ++++++++
3 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -15,6 +15,7 @@
from xml.sax.handler import feature_namespaces
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
from io import BytesIO, StringIO
+import codecs
import os.path
import shutil
from test import support
@@ -538,6 +539,34 @@
def getvalue(self):
return b''.join(self)
+class StreamWriterXmlgenTest(XmlgenTest, unittest.TestCase):
+ def ioclass(self):
+ raw = BytesIO()
+ writer = codecs.getwriter('ascii')(raw, 'xmlcharrefreplace')
+ writer.getvalue = raw.getvalue
+ return writer
+
+ def xml(self, doc, encoding='iso-8859-1'):
+ return ('<?xml version="1.0" encoding="%s"?>\n%s' %
+ (encoding, doc)).encode('ascii', 'xmlcharrefreplace')
+
+class StreamReaderWriterXmlgenTest(XmlgenTest, unittest.TestCase):
+ fname = support.TESTFN + '-codecs'
+
+ def ioclass(self):
+ writer = codecs.open(self.fname, 'w', encoding='ascii',
+ errors='xmlcharrefreplace', buffering=0)
+ self.addCleanup(support.unlink, self.fname)
+ writer.getvalue = self.getvalue
+ return writer
+
+ def getvalue(self):
+ with open(self.fname, 'rb') as f:
+ return f.read()
+
+ def xml(self, doc, encoding='iso-8859-1'):
+ return ('<?xml version="1.0" encoding="%s"?>\n%s' %
+ (encoding, doc)).encode('ascii', 'xmlcharrefreplace')
start = b'<?xml version="1.0" encoding="iso-8859-1"?>\n'
@@ -946,6 +975,8 @@
StringXmlgenTest,
BytesXmlgenTest,
WriterXmlgenTest,
+ StreamWriterXmlgenTest,
+ StreamReaderWriterXmlgenTest,
ExpatReaderTest,
ErrorReportingTest,
XmlReaderTest)
diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py
--- a/Lib/xml/sax/saxutils.py
+++ b/Lib/xml/sax/saxutils.py
@@ -5,6 +5,7 @@
import os, urllib.parse, urllib.request
import io
+import codecs
from . import handler
from . import xmlreader
@@ -77,6 +78,10 @@
# use a text writer as is
return out
+ if isinstance(out, (codecs.StreamWriter, codecs.StreamReaderWriter)):
+ # use a codecs stream writer as is
+ return out
+
# wrap a binary writer with TextIOWrapper
if isinstance(out, io.RawIOBase):
# Keep the original file open when the TextIOWrapper is
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -91,6 +91,9 @@
Library
-------
+- Issue #17915: Fix interoperability of xml.sax with file objects returned by
+ codecs.open().
+
- Issue #16601: Restarting iteration over tarfile no more continues from where
it left off. Patch by Michael Birtwell.
@@ -280,6 +283,12 @@
- Issue #17692: test_sqlite now works with unittest test discovery.
Patch by Zachary Ware.
+
+Documentation
+-------------
+
+- Issue #15940: Specify effect of locale on time functions.
+
- Issue #6696: add documentation for the Profile objects, and improve
profile/cProfile docs. Patch by Tom Pinckney.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list