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
794652dd
Commit
794652dd
authored
Jun 11, 2008
by
Alexandre Vassalotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 2918: Merge StringIO and cStringIO.
parent
502d89ed
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
702 additions
and
22 deletions
+702
-22
Lib/io.py
Lib/io.py
+278
-10
Lib/test/test_memoryio.py
Lib/test/test_memoryio.py
+7
-3
Lib/test/test_minidom.py
Lib/test/test_minidom.py
+1
-2
Lib/test/test_uu.py
Lib/test/test_uu.py
+30
-4
Lib/xml/dom/minidom.py
Lib/xml/dom/minidom.py
+4
-3
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_stringio.c
Modules/_stringio.c
+379
-0
setup.py
setup.py
+1
-0
No files found.
Lib/io.py
View file @
794652dd
This diff is collapsed.
Click to expand it.
Lib/test/test_memoryio.py
View file @
794652dd
...
...
@@ -10,7 +10,7 @@ import io
import
sys
try
:
import
_bytesio
import
_bytesio
,
_stringio
has_c_implementation
=
True
except
ImportError
:
has_c_implementation
=
False
...
...
@@ -373,7 +373,7 @@ class PyBytesIOTest(MemoryTestMixin, unittest.TestCase):
class
PyStringIOTest
(
MemoryTestMixin
,
unittest
.
TestCase
):
buftype
=
str
ioclass
=
io
.
StringIO
ioclass
=
io
.
_
StringIO
EOF
=
""
def
test_relative_seek
(
self
):
...
...
@@ -404,10 +404,14 @@ if has_c_implementation:
class
CBytesIOTest
(
PyBytesIOTest
):
ioclass
=
io
.
BytesIO
class
CStringIOTest
(
PyStringIOTest
):
ioclass
=
io
.
StringIO
def
test_main
():
tests
=
[
PyBytesIOTest
,
PyStringIOTest
]
if
has_c_implementation
:
tests
.
extend
([
CBytesIOTest
])
tests
.
extend
([
CBytesIOTest
,
CStringIOTest
])
support
.
run_unittest
(
*
tests
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_minidom.py
View file @
794652dd
...
...
@@ -3,7 +3,6 @@
import
os
import
sys
import
pickle
from
io
import
StringIO
from
test.support
import
verbose
,
run_unittest
,
TestSkipped
import
unittest
...
...
@@ -80,7 +79,7 @@ class MinidomTest(unittest.TestCase):
self
.
confirm
(
t
==
s
,
"looking for %s, found %s"
%
(
repr
(
s
),
repr
(
t
)))
def
testParseFromFile
(
self
):
dom
=
parse
(
StringIO
(
open
(
tstfile
).
read
()
))
dom
=
parse
(
open
(
tstfile
))
dom
.
unlink
()
self
.
confirm
(
isinstance
(
dom
,
Document
))
...
...
Lib/test/test_uu.py
View file @
794652dd
...
...
@@ -17,6 +17,32 @@ encodedtext = b"""\
M5&AE('-M;V]T:
\
"
US8V%L960@<'ET:&]N(&-R97!T(&]V97(@=&AE('-L965P
(:6YG(&1O9PH """
# Stolen from io.py
class
FakeIO
(
io
.
TextIOWrapper
):
"""Text I/O implementation using an in-memory buffer.
Can be a used as a drop-in replacement for sys.stdin and sys.stdout.
"""
# XXX This is really slow, but fully functional
def
__init__
(
self
,
initial_value
=
""
,
encoding
=
"utf-8"
,
errors
=
"strict"
,
newline
=
"
\
n
"
):
super
(
FakeIO
,
self
).
__init__
(
io
.
BytesIO
(),
encoding
=
encoding
,
errors
=
errors
,
newline
=
newline
)
if
initial_value
:
if
not
isinstance
(
initial_value
,
str
):
initial_value
=
str
(
initial_value
)
self
.
write
(
initial_value
)
self
.
seek
(
0
)
def
getvalue
(
self
):
self
.
flush
()
return
self
.
buffer
.
getvalue
().
decode
(
self
.
_encoding
,
self
.
_errors
)
def
encodedtextwrapped
(
mode
,
filename
):
return
(
bytes
(
"begin %03o %s
\
n
"
%
(
mode
,
filename
),
"ascii"
)
+
encodedtext
+
b"
\
n
\
n
end
\
n
"
)
...
...
@@ -76,15 +102,15 @@ class UUStdIOTest(unittest.TestCase):
sys
.
stdout
=
self
.
stdout
def
test_encode
(
self
):
sys
.
stdin
=
io
.
String
IO
(
plaintext
.
decode
(
"ascii"
))
sys
.
stdout
=
io
.
String
IO
()
sys
.
stdin
=
Fake
IO
(
plaintext
.
decode
(
"ascii"
))
sys
.
stdout
=
Fake
IO
()
uu
.
encode
(
"-"
,
"-"
,
"t1"
,
0o666
)
self
.
assertEqual
(
sys
.
stdout
.
getvalue
(),
encodedtextwrapped
(
0o666
,
"t1"
).
decode
(
"ascii"
))
def
test_decode
(
self
):
sys
.
stdin
=
io
.
String
IO
(
encodedtextwrapped
(
0o666
,
"t1"
).
decode
(
"ascii"
))
sys
.
stdout
=
io
.
String
IO
()
sys
.
stdin
=
Fake
IO
(
encodedtextwrapped
(
0o666
,
"t1"
).
decode
(
"ascii"
))
sys
.
stdout
=
Fake
IO
()
uu
.
decode
(
"-"
,
"-"
)
stdout
=
sys
.
stdout
sys
.
stdout
=
self
.
stdout
...
...
Lib/xml/dom/minidom.py
View file @
794652dd
...
...
@@ -14,6 +14,7 @@ Todo:
* SAX 2 namespaces
"""
import
codecs
import
io
import
xml.dom
...
...
@@ -49,16 +50,16 @@ class Node(xml.dom.Node):
# indent = the indentation string to prepend, per level
# newl = the newline string to append
use_encoding
=
"utf-8"
if
encoding
is
None
else
encoding
writer
=
io
.
StringIO
(
encoding
=
use_encoding
)
writer
=
codecs
.
getwriter
(
use_encoding
)(
io
.
BytesIO
()
)
if
self
.
nodeType
==
Node
.
DOCUMENT_NODE
:
# Can pass encoding only to document, to put it into XML header
self
.
writexml
(
writer
,
""
,
indent
,
newl
,
encoding
)
else
:
self
.
writexml
(
writer
,
""
,
indent
,
newl
)
if
encoding
is
None
:
return
writer
.
getvalue
(
)
return
writer
.
stream
.
getvalue
().
decode
(
use_encoding
)
else
:
return
writer
.
buffer
.
getvalue
()
return
writer
.
stream
.
getvalue
()
def
hasChildNodes
(
self
):
if
self
.
childNodes
:
...
...
Misc/NEWS
View file @
794652dd
...
...
@@ -78,6 +78,8 @@ Extension Modules
Library
-------
- Added C optimized implementation of io.StringIO.
- The ``pickle`` module is now automatically use an optimized C
implementation of Pickler and Unpickler when available. The
``cPickle`` module is no longer needed.
...
...
Modules/_stringio.c
0 → 100644
View file @
794652dd
This diff is collapsed.
Click to expand it.
setup.py
View file @
794652dd
...
...
@@ -422,6 +422,7 @@ class PyBuildExt(build_ext):
exts
.
append
(
Extension
(
"_functools"
,
[
"_functoolsmodule.c"
])
)
# Memory-based IO accelerator modules
exts
.
append
(
Extension
(
"_bytesio"
,
[
"_bytesio.c"
])
)
exts
.
append
(
Extension
(
"_stringio"
,
[
"_stringio.c"
])
)
# C-optimized pickle replacement
exts
.
append
(
Extension
(
"_pickle"
,
[
"_pickle.c"
])
)
# atexit
...
...
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