[Python-checkins] r72188 - in python/branches/pep-0383: Doc/library/codecs.rst Lib/test/test_codecs.py Objects/unicodeobject.c Python/codecs.c

martin.v.loewis python-checkins at python.org
Sat May 2 11:41:21 CEST 2009


Author: martin.v.loewis
Date: Sat May 2 11:41:19 2009
New Revision: 72188
Log:
Fix issues from Benjamin's review (rietveld issue 52081).
Modified:
 python/branches/pep-0383/Doc/library/codecs.rst
 python/branches/pep-0383/Lib/test/test_codecs.py
 python/branches/pep-0383/Objects/unicodeobject.c
 python/branches/pep-0383/Python/codecs.c
Modified: python/branches/pep-0383/Doc/library/codecs.rst
==============================================================================
--- python/branches/pep-0383/Doc/library/codecs.rst	(original)
+++ python/branches/pep-0383/Doc/library/codecs.rst	Sat May 2 11:41:19 2009
@@ -323,8 +323,7 @@
 | | (only for encoding). |
 +-------------------------+-----------------------------------------------+
 
-In addition, the following error handlers are specific to only selected
-codecs:
+In addition, the following error handlers are specific to a single codec:
 
 +------------------+---------+--------------------------------------------+
 | Value | Codec | Meaning |
@@ -333,6 +332,9 @@
 | | | codes in UTF-8. |
 +------------------+---------+--------------------------------------------+
 
+.. versionadded:: 3.1
+ The ``'surrogates'`` error handler.
+
 The set of allowed values can be extended via :meth:`register_error`.
 
 
Modified: python/branches/pep-0383/Lib/test/test_codecs.py
==============================================================================
--- python/branches/pep-0383/Lib/test/test_codecs.py	(original)
+++ python/branches/pep-0383/Lib/test/test_codecs.py	Sat May 2 11:41:19 2009
@@ -541,9 +541,11 @@
 self.check_state_handling_decode(self.encoding,
 u, u.encode(self.encoding))
 
- def test_surrogates(self):
+ def test_lone_surrogates(self):
 self.assertRaises(UnicodeEncodeError, "\ud800".encode, "utf-8")
 self.assertRaises(UnicodeDecodeError, b"\xed\xa0\x80".decode, "utf-8")
+
+ def test_surrogates_handler(self):
 self.assertEquals("abc\ud800def".encode("utf-8", "surrogates"),
 b"abc\xed\xa0\x80def")
 self.assertEquals(b"abc\xed\xa0\x80def".decode("utf-8", "surrogates"),
Modified: python/branches/pep-0383/Objects/unicodeobject.c
==============================================================================
--- python/branches/pep-0383/Objects/unicodeobject.c	(original)
+++ python/branches/pep-0383/Objects/unicodeobject.c	Sat May 2 11:41:19 2009
@@ -155,11 +155,9 @@
 };
 
 static PyObject *unicode_encode_call_errorhandler(const char *errors,
- PyObject **errorHandler,
- const char *encoding, const char *reason,
- const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
- Py_ssize_t startpos, Py_ssize_t endpos,
- Py_ssize_t *newpos);
+ PyObject **errorHandler,const char *encoding, const char *reason,
+ const Py_UNICODE *unicode, Py_ssize_t size, PyObject **exceptionObject,
+ Py_ssize_t startpos, Py_ssize_t endpos, Py_ssize_t *newpos);
 
 /* Same for linebreaks */
 static unsigned char ascii_linebreak[] = {
@@ -2376,6 +2374,7 @@
 Py_ssize_t nneeded; /* number of result bytes needed */
 char stackbuf[MAX_SHORT_UNICHARS * 4];
 PyObject *errorHandler = NULL;
+ PyObject *exc = NULL;
 
 assert(s != NULL);
 assert(size >= 0);
@@ -2430,7 +2429,6 @@
 }
 #endif
 if (ch >= 0xd800 && ch <= 0xdfff) {
- PyObject *exc = NULL;
 Py_ssize_t newpos;
 PyObject *rep;
 char *prep;
@@ -2486,9 +2484,11 @@
 _PyBytes_Resize(&result, nneeded);
 }
 Py_XDECREF(errorHandler);
+ Py_XDECREF(exc);
 return result;
 error:
 Py_XDECREF(errorHandler);
+ Py_XDECREF(exc);
 Py_XDECREF(result);
 return NULL;
 
Modified: python/branches/pep-0383/Python/codecs.c
==============================================================================
--- python/branches/pep-0383/Python/codecs.c	(original)
+++ python/branches/pep-0383/Python/codecs.c	Sat May 2 11:41:19 2009
@@ -767,8 +767,10 @@
 	 return NULL;
 	startp = PyUnicode_AS_UNICODE(object);
 	res = PyBytes_FromStringAndSize(NULL, 3*(end-start));
-	if (!res)
+	if (!res) {
+	 Py_DECREF(object);
 	 return NULL;
+	}
 	outp = PyBytes_AsString(res);
 	for (p = startp+start; p < startp+end; p++) {
 	 Py_UNICODE ch = *p;


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /