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
9a63470f
Commit
9a63470f
authored
Jul 09, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make test_tempfile.py work. Make SpooledTempFile work in text and binary mode.
parent
b4e87e37
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
Lib/tempfile.py
Lib/tempfile.py
+5
-3
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+17
-2
No files found.
Lib/tempfile.py
View file @
9a63470f
...
...
@@ -29,6 +29,7 @@ __all__ = [
# Imports.
import
io
as
_io
import
os
as
_os
import
errno
as
_errno
from
random
import
Random
as
_Random
...
...
@@ -37,8 +38,6 @@ if _os.name == 'mac':
import
Carbon.Folder
as
_Folder
import
Carbon.Folders
as
_Folders
from
io
import
StringIO
as
_StringIO
try
:
import
fcntl
as
_fcntl
except
ImportError
:
...
...
@@ -486,7 +485,10 @@ class SpooledTemporaryFile:
def
__init__
(
self
,
max_size
=
0
,
mode
=
'w+b'
,
bufsize
=-
1
,
suffix
=
""
,
prefix
=
template
,
dir
=
None
):
self
.
_file
=
_StringIO
()
if
'b'
in
mode
:
self
.
_file
=
_io
.
BytesIO
()
else
:
self
.
_file
=
_io
.
StringIO
()
self
.
_max_size
=
max_size
self
.
_rolled
=
False
self
.
_TemporaryFileArgs
=
(
mode
,
bufsize
,
suffix
,
prefix
,
dir
)
...
...
Lib/test/test_tempfile.py
View file @
9a63470f
...
...
@@ -664,7 +664,7 @@ class test_SpooledTemporaryFile(TC):
self
.
failUnless
(
f
.
_rolled
)
filename
=
f
.
name
f
.
close
()
self
.
failIf
(
os
.
path
.
exists
(
filename
),
self
.
failIf
(
isinstance
(
filename
,
str
)
and
os
.
path
.
exists
(
filename
),
"SpooledTemporaryFile %s exists after close"
%
filename
)
finally
:
os
.
rmdir
(
dir
)
...
...
@@ -730,7 +730,22 @@ class test_SpooledTemporaryFile(TC):
write
(
"a"
*
35
)
write
(
"b"
*
35
)
seek
(
0
,
0
)
self
.
assertEqual
(
read
(
70
),
'a'
*
35
+
'b'
*
35
)
self
.
assertEqual
(
read
(
70
),
b'a'
*
35
+
b'b'
*
35
)
def
test_text_mode
(
self
):
# Creating a SpooledTemporaryFile with a text mode should produce
# a file object reading and writing (Unicode) text strings.
f
=
tempfile
.
SpooledTemporaryFile
(
mode
=
'w+'
,
max_size
=
10
)
f
.
write
(
"abc
\
n
"
)
f
.
seek
(
0
)
self
.
assertEqual
(
f
.
read
(),
"abc
\
n
"
)
f
.
write
(
"def
\
n
"
)
f
.
seek
(
0
)
self
.
assertEqual
(
f
.
read
(),
"abc
\
n
def
\
n
"
)
f
.
write
(
"xyzzy
\
n
"
)
f
.
seek
(
0
)
self
.
assertEqual
(
f
.
read
(),
"abc
\
n
def
\
n
xyzzy
\
n
"
)
test_classes
.
append
(
test_SpooledTemporaryFile
)
...
...
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