Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b930f3e8
Commit
b930f3e8
authored
May 17, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make test_codecs work. The CJK codecs now use bytes instead of str8 for
their encoded input/output.
parent
164872d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
29 deletions
+32
-29
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+5
-5
Modules/cjkcodecs/multibytecodec.c
Modules/cjkcodecs/multibytecodec.c
+27
-24
No files found.
Lib/test/test_codecs.py
View file @
b930f3e8
...
@@ -492,7 +492,7 @@ class EscapeDecodeTest(unittest.TestCase):
...
@@ -492,7 +492,7 @@ class EscapeDecodeTest(unittest.TestCase):
class
RecodingTest
(
unittest
.
TestCase
):
class
RecodingTest
(
unittest
.
TestCase
):
def
test_recoding
(
self
):
def
test_recoding
(
self
):
f
=
io
.
String
IO
()
f
=
io
.
Bytes
IO
()
f2
=
codecs
.
EncodedFile
(
f
,
"unicode_internal"
,
"utf-8"
)
f2
=
codecs
.
EncodedFile
(
f
,
"unicode_internal"
,
"utf-8"
)
f2
.
write
(
"a"
)
f2
.
write
(
"a"
)
f2
.
close
()
f2
.
close
()
...
@@ -1205,7 +1205,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
...
@@ -1205,7 +1205,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
decodedresult
=
""
decodedresult
=
""
for
c
in
encodedresult
:
for
c
in
encodedresult
:
decodedresult
+=
decoder
.
decode
(
bytes
([
c
]))
decodedresult
+=
decoder
.
decode
(
bytes
([
c
]))
decodedresult
+=
decoder
.
decode
(
""
,
True
)
decodedresult
+=
decoder
.
decode
(
b
""
,
True
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
# check C API
# check C API
...
@@ -1217,7 +1217,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
...
@@ -1217,7 +1217,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
decodedresult
=
""
decodedresult
=
""
for
c
in
encodedresult
:
for
c
in
encodedresult
:
decodedresult
+=
cdecoder
.
decode
(
bytes
([
c
]))
decodedresult
+=
cdecoder
.
decode
(
bytes
([
c
]))
decodedresult
+=
cdecoder
.
decode
(
""
,
True
)
decodedresult
+=
cdecoder
.
decode
(
b
""
,
True
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
# check iterencode()/iterdecode()
# check iterencode()/iterdecode()
...
@@ -1258,8 +1258,8 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
...
@@ -1258,8 +1258,8 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
for
t
in
range
(
5
):
for
t
in
range
(
5
):
# Test that calling seek resets the internal codec state and buffers
# Test that calling seek resets the internal codec state and buffers
reader
.
seek
(
0
,
0
)
reader
.
seek
(
0
,
0
)
line
=
reader
.
readline
()
data
=
reader
.
read
()
self
.
assertEqual
(
s
[:
len
(
line
)],
line
)
self
.
assertEqual
(
s
,
data
)
def
test_bad_decode_args
(
self
):
def
test_bad_decode_args
(
self
):
for
encoding
in
all_unicode_encodings
:
for
encoding
in
all_unicode_encodings
:
...
...
Modules/cjkcodecs/multibytecodec.c
View file @
b930f3e8
...
@@ -166,15 +166,15 @@ expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
...
@@ -166,15 +166,15 @@ expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
Py_ssize_t
orgpos
,
orgsize
;
Py_ssize_t
orgpos
,
orgsize
;
orgpos
=
(
Py_ssize_t
)((
char
*
)
buf
->
outbuf
-
orgpos
=
(
Py_ssize_t
)((
char
*
)
buf
->
outbuf
-
Py
String
_AS_STRING
(
buf
->
outobj
));
Py
Bytes
_AS_STRING
(
buf
->
outobj
));
orgsize
=
Py
String
_GET_SIZE
(
buf
->
outobj
);
orgsize
=
Py
Bytes
_GET_SIZE
(
buf
->
outobj
);
if
(
_PyString_Resize
(
&
buf
->
outobj
,
orgsize
+
(
if
(
PyBytes_Resize
(
buf
->
outobj
,
orgsize
+
(
esize
<
(
orgsize
>>
1
)
?
(
orgsize
>>
1
)
|
1
:
esize
))
==
-
1
)
esize
<
(
orgsize
>>
1
)
?
(
orgsize
>>
1
)
|
1
:
esize
))
==
-
1
)
return
-
1
;
return
-
1
;
buf
->
outbuf
=
(
unsigned
char
*
)
Py
String
_AS_STRING
(
buf
->
outobj
)
+
orgpos
;
buf
->
outbuf
=
(
unsigned
char
*
)
Py
Bytes
_AS_STRING
(
buf
->
outobj
)
+
orgpos
;
buf
->
outbuf_end
=
(
unsigned
char
*
)
Py
String
_AS_STRING
(
buf
->
outobj
)
buf
->
outbuf_end
=
(
unsigned
char
*
)
Py
Bytes
_AS_STRING
(
buf
->
outobj
)
+
Py
String
_GET_SIZE
(
buf
->
outobj
);
+
Py
Bytes
_GET_SIZE
(
buf
->
outobj
);
return
0
;
return
0
;
}
}
...
@@ -322,6 +322,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
...
@@ -322,6 +322,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto
errorexit
;
goto
errorexit
;
}
}
assert
(
PyString_Check
(
retstr
));
retstrsize
=
PyString_GET_SIZE
(
retstr
);
retstrsize
=
PyString_GET_SIZE
(
retstr
);
REQUIRE_ENCODEBUFFER
(
buf
,
retstrsize
);
REQUIRE_ENCODEBUFFER
(
buf
,
retstrsize
);
...
@@ -468,16 +469,16 @@ multibytecodec_encode(MultibyteCodec *codec,
...
@@ -468,16 +469,16 @@ multibytecodec_encode(MultibyteCodec *codec,
Py_ssize_t
finalsize
,
r
=
0
;
Py_ssize_t
finalsize
,
r
=
0
;
if
(
datalen
==
0
)
if
(
datalen
==
0
)
return
Py
String_FromString
(
""
);
return
Py
Bytes_FromStringAndSize
(
NULL
,
0
);
buf
.
excobj
=
NULL
;
buf
.
excobj
=
NULL
;
buf
.
inbuf
=
buf
.
inbuf_top
=
*
data
;
buf
.
inbuf
=
buf
.
inbuf_top
=
*
data
;
buf
.
inbuf_end
=
buf
.
inbuf_top
+
datalen
;
buf
.
inbuf_end
=
buf
.
inbuf_top
+
datalen
;
buf
.
outobj
=
Py
String
_FromStringAndSize
(
NULL
,
datalen
*
2
+
16
);
buf
.
outobj
=
Py
Bytes
_FromStringAndSize
(
NULL
,
datalen
*
2
+
16
);
if
(
buf
.
outobj
==
NULL
)
if
(
buf
.
outobj
==
NULL
)
goto
errorexit
;
goto
errorexit
;
buf
.
outbuf
=
(
unsigned
char
*
)
Py
String
_AS_STRING
(
buf
.
outobj
);
buf
.
outbuf
=
(
unsigned
char
*
)
Py
Bytes
_AS_STRING
(
buf
.
outobj
);
buf
.
outbuf_end
=
buf
.
outbuf
+
Py
String
_GET_SIZE
(
buf
.
outobj
);
buf
.
outbuf_end
=
buf
.
outbuf
+
Py
Bytes
_GET_SIZE
(
buf
.
outobj
);
while
(
buf
.
inbuf
<
buf
.
inbuf_end
)
{
while
(
buf
.
inbuf
<
buf
.
inbuf_end
)
{
Py_ssize_t
inleft
,
outleft
;
Py_ssize_t
inleft
,
outleft
;
...
@@ -512,10 +513,10 @@ multibytecodec_encode(MultibyteCodec *codec,
...
@@ -512,10 +513,10 @@ multibytecodec_encode(MultibyteCodec *codec,
}
}
finalsize
=
(
Py_ssize_t
)((
char
*
)
buf
.
outbuf
-
finalsize
=
(
Py_ssize_t
)((
char
*
)
buf
.
outbuf
-
Py
String
_AS_STRING
(
buf
.
outobj
));
Py
Bytes
_AS_STRING
(
buf
.
outobj
));
if
(
finalsize
!=
Py
String
_GET_SIZE
(
buf
.
outobj
))
if
(
finalsize
!=
Py
Bytes
_GET_SIZE
(
buf
.
outobj
))
if
(
_PyString_Resize
(
&
buf
.
outobj
,
finalsize
)
==
-
1
)
if
(
PyBytes_Resize
(
buf
.
outobj
,
finalsize
)
==
-
1
)
goto
errorexit
;
goto
errorexit
;
Py_XDECREF
(
buf
.
excobj
);
Py_XDECREF
(
buf
.
excobj
);
...
@@ -1223,10 +1224,11 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
...
@@ -1223,10 +1224,11 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
if
(
cres
==
NULL
)
if
(
cres
==
NULL
)
goto
errorexit
;
goto
errorexit
;
if
(
!
Py
String
_Check
(
cres
))
{
if
(
!
Py
Bytes
_Check
(
cres
))
{
PyErr_
SetString
(
PyExc_TypeError
,
PyErr_
Format
(
PyExc_TypeError
,
"stream function returned a "
"stream function returned a "
"non-string object"
);
"non-string object (%.100s)"
,
cres
->
ob_type
->
tp_name
);
goto
errorexit
;
goto
errorexit
;
}
}
...
@@ -1234,22 +1236,22 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
...
@@ -1234,22 +1236,22 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
PyObject
*
ctr
;
PyObject
*
ctr
;
char
*
ctrdata
;
char
*
ctrdata
;
rsize
=
Py
String
_GET_SIZE
(
cres
)
+
self
->
pendingsize
;
rsize
=
Py
Bytes
_GET_SIZE
(
cres
)
+
self
->
pendingsize
;
ctr
=
Py
String
_FromStringAndSize
(
NULL
,
rsize
);
ctr
=
Py
Bytes
_FromStringAndSize
(
NULL
,
rsize
);
if
(
ctr
==
NULL
)
if
(
ctr
==
NULL
)
goto
errorexit
;
goto
errorexit
;
ctrdata
=
Py
String
_AS_STRING
(
ctr
);
ctrdata
=
Py
Bytes
_AS_STRING
(
ctr
);
memcpy
(
ctrdata
,
self
->
pending
,
self
->
pendingsize
);
memcpy
(
ctrdata
,
self
->
pending
,
self
->
pendingsize
);
memcpy
(
ctrdata
+
self
->
pendingsize
,
memcpy
(
ctrdata
+
self
->
pendingsize
,
Py
String
_AS_STRING
(
cres
),
Py
Bytes
_AS_STRING
(
cres
),
Py
String
_GET_SIZE
(
cres
));
Py
Bytes
_GET_SIZE
(
cres
));
Py_DECREF
(
cres
);
Py_DECREF
(
cres
);
cres
=
ctr
;
cres
=
ctr
;
self
->
pendingsize
=
0
;
self
->
pendingsize
=
0
;
}
}
rsize
=
Py
String
_GET_SIZE
(
cres
);
rsize
=
Py
Bytes
_GET_SIZE
(
cres
);
if
(
decoder_prepare_buffer
(
&
buf
,
Py
String
_AS_STRING
(
cres
),
if
(
decoder_prepare_buffer
(
&
buf
,
Py
Bytes
_AS_STRING
(
cres
),
rsize
)
!=
0
)
rsize
)
!=
0
)
goto
errorexit
;
goto
errorexit
;
...
@@ -1594,6 +1596,7 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
...
@@ -1594,6 +1596,7 @@ mbstreamwriter_reset(MultibyteStreamWriterObject *self)
if
(
pwrt
==
NULL
)
if
(
pwrt
==
NULL
)
return
NULL
;
return
NULL
;
assert
(
PyString_Check
(
pwrt
));
if
(
PyString_Size
(
pwrt
)
>
0
)
{
if
(
PyString_Size
(
pwrt
)
>
0
)
{
PyObject
*
wr
;
PyObject
*
wr
;
wr
=
PyObject_CallMethod
(
self
->
stream
,
"write"
,
"O"
,
pwrt
);
wr
=
PyObject_CallMethod
(
self
->
stream
,
"write"
,
"O"
,
pwrt
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment