mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Merged revisions 59056-59076 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59064 | christian.heimes | 2007-11-20 02:48:48 +0100 (Tue, 20 Nov 2007) | 1 line Fixed bug #1470 ........ r59066 | martin.v.loewis | 2007-11-20 03:46:02 +0100 (Tue, 20 Nov 2007) | 2 lines Patch #1468: Package Lib/test/*.pem. ........ r59068 | christian.heimes | 2007-11-20 04:21:02 +0100 (Tue, 20 Nov 2007) | 1 line Another fix for test_shutil. Martin pointed out that it breaks some build bots ........ r59073 | nick.coghlan | 2007-11-20 15:55:57 +0100 (Tue, 20 Nov 2007) | 1 line Backport some main.c cleanup from the py3k branch ........ r59076 | amaury.forgeotdarc | 2007-11-21 00:31:27 +0100 (Wed, 21 Nov 2007) | 6 lines The incremental decoder for utf-7 must preserve its state between calls. Solves issue1460. Might not be a backport candidate: a new API function was added, and some code may rely on details in utf-7.py. ........
This commit is contained in:
parent
81e8ab5ba0
commit
5d14c2b8f8
6 changed files with 61 additions and 22 deletions
|
@ -751,6 +751,13 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(
|
||||||
const char *errors /* error handling */
|
const char *errors /* error handling */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7Stateful(
|
||||||
|
const char *string, /* UTF-7 encoded string */
|
||||||
|
Py_ssize_t length, /* size of string */
|
||||||
|
const char *errors, /* error handling */
|
||||||
|
Py_ssize_t *consumed /* bytes consumed */
|
||||||
|
);
|
||||||
|
|
||||||
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
|
PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
|
||||||
const Py_UNICODE *data, /* Unicode char buffer */
|
const Py_UNICODE *data, /* Unicode char buffer */
|
||||||
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
|
Py_ssize_t length, /* number of Py_UNICODE chars to encode */
|
||||||
|
|
|
@ -6,34 +6,31 @@ import codecs
|
||||||
|
|
||||||
### Codec APIs
|
### Codec APIs
|
||||||
|
|
||||||
class Codec(codecs.Codec):
|
encode = codecs.utf_7_encode
|
||||||
|
|
||||||
# Note: Binding these as C functions will result in the class not
|
def decode(input, errors='strict'):
|
||||||
# converting them to methods. This is intended.
|
return codecs.utf_7_decode(input, errors, True)
|
||||||
encode = codecs.utf_7_encode
|
|
||||||
decode = codecs.utf_7_decode
|
|
||||||
|
|
||||||
class IncrementalEncoder(codecs.IncrementalEncoder):
|
class IncrementalEncoder(codecs.IncrementalEncoder):
|
||||||
def encode(self, input, final=False):
|
def encode(self, input, final=False):
|
||||||
return codecs.utf_7_encode(input, self.errors)[0]
|
return codecs.utf_7_encode(input, self.errors)[0]
|
||||||
|
|
||||||
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
|
||||||
def _buffer_decode(self, input, errors, final):
|
_buffer_decode = codecs.utf_7_decode
|
||||||
return codecs.utf_7_decode(input, self.errors)
|
|
||||||
|
|
||||||
class StreamWriter(Codec,codecs.StreamWriter):
|
class StreamWriter(codecs.StreamWriter):
|
||||||
pass
|
encode = codecs.utf_7_encode
|
||||||
|
|
||||||
class StreamReader(Codec,codecs.StreamReader):
|
class StreamReader(codecs.StreamReader):
|
||||||
pass
|
decode = codecs.utf_7_decode
|
||||||
|
|
||||||
### encodings module API
|
### encodings module API
|
||||||
|
|
||||||
def getregentry():
|
def getregentry():
|
||||||
return codecs.CodecInfo(
|
return codecs.CodecInfo(
|
||||||
name='utf-7',
|
name='utf-7',
|
||||||
encode=Codec.encode,
|
encode=encode,
|
||||||
decode=Codec.decode,
|
decode=decode,
|
||||||
incrementalencoder=IncrementalEncoder,
|
incrementalencoder=IncrementalEncoder,
|
||||||
incrementaldecoder=IncrementalDecoder,
|
incrementaldecoder=IncrementalDecoder,
|
||||||
streamreader=StreamReader,
|
streamreader=StreamReader,
|
||||||
|
|
|
@ -544,7 +544,17 @@ class UTF8Test(ReadTest):
|
||||||
class UTF7Test(ReadTest):
|
class UTF7Test(ReadTest):
|
||||||
encoding = "utf-7"
|
encoding = "utf-7"
|
||||||
|
|
||||||
# No test_partial() yet, because UTF-7 doesn't support it.
|
def test_partial(self):
|
||||||
|
self.check_partial(
|
||||||
|
"a+-b",
|
||||||
|
[
|
||||||
|
"a",
|
||||||
|
"a",
|
||||||
|
"a+",
|
||||||
|
"a+-",
|
||||||
|
"a+-b",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
class UTF16ExTest(unittest.TestCase):
|
class UTF16ExTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -250,18 +250,25 @@ unicode_internal_decode(PyObject *self,
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
utf_7_decode(PyObject *self,
|
utf_7_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
const char *data;
|
const char *data;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
|
int final = 0;
|
||||||
|
Py_ssize_t consumed;
|
||||||
|
PyObject *decoded = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
|
if (!PyArg_ParseTuple(args, "t#|zi:utf_7_decode",
|
||||||
&data, &size, &errors))
|
&data, &size, &errors, &final))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
consumed = size;
|
||||||
|
|
||||||
return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
|
decoded = PyUnicode_DecodeUTF7Stateful(data, size, errors,
|
||||||
size);
|
final ? NULL : &consumed);
|
||||||
|
if (decoded == NULL)
|
||||||
|
return NULL;
|
||||||
|
return codec_tuple(decoded, consumed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -1518,6 +1518,14 @@ char utf7_special[128] = {
|
||||||
PyObject *PyUnicode_DecodeUTF7(const char *s,
|
PyObject *PyUnicode_DecodeUTF7(const char *s,
|
||||||
Py_ssize_t size,
|
Py_ssize_t size,
|
||||||
const char *errors)
|
const char *errors)
|
||||||
|
{
|
||||||
|
return PyUnicode_DecodeUTF7Stateful(s, size, errors, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
|
||||||
|
Py_ssize_t size,
|
||||||
|
const char *errors,
|
||||||
|
Py_ssize_t *consumed)
|
||||||
{
|
{
|
||||||
const char *starts = s;
|
const char *starts = s;
|
||||||
Py_ssize_t startinpos;
|
Py_ssize_t startinpos;
|
||||||
|
@ -1537,8 +1545,11 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
|
||||||
unicode = _PyUnicode_New(size);
|
unicode = _PyUnicode_New(size);
|
||||||
if (!unicode)
|
if (!unicode)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (size == 0)
|
if (size == 0) {
|
||||||
|
if (consumed)
|
||||||
|
*consumed = 0;
|
||||||
return (PyObject *)unicode;
|
return (PyObject *)unicode;
|
||||||
|
}
|
||||||
|
|
||||||
p = unicode->str;
|
p = unicode->str;
|
||||||
e = s + size;
|
e = s + size;
|
||||||
|
@ -1624,7 +1635,7 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inShift) {
|
if (inShift && !consumed) {
|
||||||
outpos = p-PyUnicode_AS_UNICODE(unicode);
|
outpos = p-PyUnicode_AS_UNICODE(unicode);
|
||||||
endinpos = size;
|
endinpos = size;
|
||||||
if (unicode_decode_call_errorhandler(
|
if (unicode_decode_call_errorhandler(
|
||||||
|
@ -1636,6 +1647,12 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
|
||||||
if (s < e)
|
if (s < e)
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
if (consumed) {
|
||||||
|
if(inShift)
|
||||||
|
*consumed = startinpos;
|
||||||
|
else
|
||||||
|
*consumed = s-starts;
|
||||||
|
}
|
||||||
|
|
||||||
if (_PyUnicode_Resize(&unicode, p - PyUnicode_AS_UNICODE(unicode)) < 0)
|
if (_PyUnicode_Resize(&unicode, p - PyUnicode_AS_UNICODE(unicode)) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
|
@ -974,6 +974,7 @@ def add_files(db):
|
||||||
lib.add_file("check_soundcard.vbs")
|
lib.add_file("check_soundcard.vbs")
|
||||||
lib.add_file("empty.vbs")
|
lib.add_file("empty.vbs")
|
||||||
lib.glob("*.uue")
|
lib.glob("*.uue")
|
||||||
|
lib.glob("*.pem")
|
||||||
lib.add_file("readme.txt", src="README")
|
lib.add_file("readme.txt", src="README")
|
||||||
if dir=='decimaltestdata':
|
if dir=='decimaltestdata':
|
||||||
lib.glob("*.decTest")
|
lib.glob("*.decTest")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue