mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
StringIO patch #462596: let's [c]StringIO accept read buffers on
input to .write() too.
This commit is contained in:
parent
c72d4cddc9
commit
e47df7a211
3 changed files with 32 additions and 18 deletions
|
|
@ -38,7 +38,8 @@ __all__ = ["StringIO"]
|
|||
|
||||
class StringIO:
|
||||
def __init__(self, buf = ''):
|
||||
self.buf = buf
|
||||
# Force self.buf to be a string
|
||||
self.buf = str(buf)
|
||||
self.len = len(buf)
|
||||
self.buflist = []
|
||||
self.pos = 0
|
||||
|
|
@ -134,6 +135,8 @@ class StringIO:
|
|||
if self.closed:
|
||||
raise ValueError, "I/O operation on closed file"
|
||||
if not s: return
|
||||
# Force s to be a string
|
||||
s = str(s)
|
||||
if self.pos > self.len:
|
||||
self.buflist.append('\0'*(self.pos - self.len))
|
||||
self.len = self.pos
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue