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
2233d27a
Commit
2233d27a
authored
Jun 22, 2007
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change readbuffer_encode() and charbuffer_encode() to
return bytes objects.
parent
63a28be0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
13 deletions
+9
-13
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+5
-5
Modules/_codecsmodule.c
Modules/_codecsmodule.c
+4
-8
No files found.
Lib/test/test_codecs.py
View file @
2233d27a
...
...
@@ -422,12 +422,12 @@ class ReadBufferTest(unittest.TestCase):
def
test_array
(
self
):
import
array
self
.
assertEqual
(
codecs
.
readbuffer_encode
(
array
.
array
(
"
c"
,
"spam"
)),
(
"spam"
,
4
)
codecs
.
readbuffer_encode
(
array
.
array
(
"
b"
,
bytes
(
"spam"
)
)),
(
b
"spam"
,
4
)
)
def
test_empty
(
self
):
self
.
assertEqual
(
codecs
.
readbuffer_encode
(
""
),
(
""
,
0
))
self
.
assertEqual
(
codecs
.
readbuffer_encode
(
""
),
(
b
""
,
0
))
def
test_bad_args
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
readbuffer_encode
)
...
...
@@ -436,10 +436,10 @@ class ReadBufferTest(unittest.TestCase):
class
CharBufferTest
(
unittest
.
TestCase
):
def
test_string
(
self
):
self
.
assertEqual
(
codecs
.
charbuffer_encode
(
"spam"
),
(
"spam"
,
4
))
self
.
assertEqual
(
codecs
.
charbuffer_encode
(
"spam"
),
(
b
"spam"
,
4
))
def
test_empty
(
self
):
self
.
assertEqual
(
codecs
.
charbuffer_encode
(
""
),
(
""
,
0
))
self
.
assertEqual
(
codecs
.
charbuffer_encode
(
""
),
(
b
""
,
0
))
def
test_bad_args
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
charbuffer_encode
)
...
...
Modules/_codecsmodule.c
View file @
2233d27a
...
...
@@ -533,8 +533,7 @@ readbuffer_encode(PyObject *self,
&
data
,
&
size
,
&
errors
))
return
NULL
;
return
codec_tuple
(
PyString_FromStringAndSize
(
data
,
size
),
size
);
return
codec_tuple
(
PyBytes_FromStringAndSize
(
data
,
size
),
size
);
}
static
PyObject
*
...
...
@@ -549,8 +548,7 @@ charbuffer_encode(PyObject *self,
&
data
,
&
size
,
&
errors
))
return
NULL
;
return
codec_tuple
(
PyString_FromStringAndSize
(
data
,
size
),
size
);
return
codec_tuple
(
PyBytes_FromStringAndSize
(
data
,
size
),
size
);
}
static
PyObject
*
...
...
@@ -569,14 +567,12 @@ unicode_internal_encode(PyObject *self,
if
(
PyUnicode_Check
(
obj
))
{
data
=
PyUnicode_AS_DATA
(
obj
);
size
=
PyUnicode_GET_DATA_SIZE
(
obj
);
return
codec_tuple
(
PyString_FromStringAndSize
(
data
,
size
),
size
);
return
codec_tuple
(
PyBytes_FromStringAndSize
(
data
,
size
),
size
);
}
else
{
if
(
PyObject_AsReadBuffer
(
obj
,
(
const
void
**
)
&
data
,
&
size
))
return
NULL
;
return
codec_tuple
(
PyString_FromStringAndSize
(
data
,
size
),
size
);
return
codec_tuple
(
PyBytes_FromStringAndSize
(
data
,
size
),
size
);
}
}
...
...
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