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
262be5e7
Commit
262be5e7
authored
May 22, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6268: Fix seek() method of codecs.open(), don't read the BOM twice
after seek(0)
parent
d6703b5e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
0 deletions
+28
-0
Lib/codecs.py
Lib/codecs.py
+4
-0
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+21
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/codecs.py
View file @
262be5e7
...
...
@@ -694,6 +694,10 @@ class StreamReaderWriter:
self
.
reader
.
reset
()
self
.
writer
.
reset
()
def
seek
(
self
,
offset
,
whence
=
0
):
self
.
reader
.
seek
(
offset
,
whence
)
self
.
writer
.
seek
(
offset
,
whence
)
def
__getattr__
(
self
,
name
,
getattr
=
getattr
):
...
...
Lib/test/test_codecs.py
View file @
262be5e7
...
...
@@ -1496,6 +1496,26 @@ class WithStmtTest(unittest.TestCase):
self
.
assertEquals
(
srw
.
read
(),
u"
\
xfc
"
)
class
BomTest
(
unittest
.
TestCase
):
def
test_seek0
(
self
):
data
=
"1234567890"
tests
=
(
"utf-16"
,
"utf-16-le"
,
"utf-16-be"
,
"utf-32"
,
"utf-32-le"
,
"utf-32-be"
)
for
encoding
in
tests
:
with
codecs
.
open
(
'foo'
,
'wt+'
,
encoding
=
encoding
)
as
f
:
# Check if the BOM is written only once
f
.
write
(
data
)
f
.
write
(
data
)
f
.
seek
(
0
)
self
.
assertEquals
(
f
.
read
(),
data
*
2
)
f
.
seek
(
0
)
self
.
assertEquals
(
f
.
read
(),
data
*
2
)
def
test_main
():
test_support
.
run_unittest
(
UTF32Test
,
...
...
@@ -1524,6 +1544,7 @@ def test_main():
BasicStrTest
,
CharmapTest
,
WithStmtTest
,
BomTest
,
)
...
...
Misc/NEWS
View file @
262be5e7
...
...
@@ -29,6 +29,9 @@ C-API
Library
-------
- Issue #6268: Fix seek() method of codecs.open(), don't read the BOM twice
after seek(0)
- Issue #5640: Fix Shift-JIS incremental encoder for error handlers different
than strict
...
...
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