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
729c31f5
Commit
729c31f5
authored
Mar 14, 2005
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset internal buffers when seek() is called. This fixes SF bug #1156259.
parent
3390d33d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
Lib/codecs.py
Lib/codecs.py
+11
-1
Lib/encodings/utf_16.py
Lib/encodings/utf_16.py
+7
-0
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+15
-0
No files found.
Lib/codecs.py
View file @
729c31f5
...
...
@@ -356,7 +356,17 @@ class StreamReader(Codec):
from decoding errors.
"""
pass
self
.
bytebuffer
=
""
self
.
charbuffer
=
u""
self
.
atcr
=
False
def
seek
(
self
,
offset
,
whence
):
""" Set the input stream's current position.
Resets the codec buffers used for keeping state.
"""
self
.
reset
()
self
.
stream
.
seek
(
offset
,
whence
)
def
next
(
self
):
...
...
Lib/encodings/utf_16.py
View file @
729c31f5
...
...
@@ -31,6 +31,13 @@ class StreamWriter(codecs.StreamWriter):
class
StreamReader
(
codecs
.
StreamReader
):
def
reset
(
self
):
codecs
.
StreamReader
.
reset
(
self
)
try
:
del
self
.
decode
except
AttributeError
:
pass
def
decode
(
self
,
input
,
errors
=
'strict'
):
(
object
,
consumed
,
byteorder
)
=
\
codecs
.
utf_16_ex_decode
(
input
,
errors
,
0
,
False
)
...
...
Lib/test/test_codecs.py
View file @
729c31f5
...
...
@@ -755,6 +755,21 @@ class BasicUnicodeTest(unittest.TestCase):
decodedresult
+=
reader
.
read
()
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
def
test_seek
(
self
):
# all codecs should be able to encode these
s
=
u"%s
\
n
%s
\
n
"
%
(
100
*
u"abc123"
,
100
*
u"def456"
)
for
encoding
in
all_unicode_encodings
:
if
encoding
==
"idna"
:
# FIXME: See SF bug #1163178
continue
if
encoding
in
broken_unicode_with_streams
:
continue
reader
=
codecs
.
getreader
(
encoding
)(
StringIO
.
StringIO
(
s
.
encode
(
encoding
)))
for
t
in
xrange
(
5
):
# Test that calling seek resets the internal codec state and buffers
reader
.
seek
(
0
,
0
)
line
=
reader
.
readline
()
self
.
assertEqual
(
s
[:
len
(
line
)],
line
)
class
BasicStrTest
(
unittest
.
TestCase
):
def
test_basics
(
self
):
s
=
"abc123"
...
...
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