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
beaa3ada
Commit
beaa3ada
authored
Feb 09, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10355: SpooledTemporaryFile properties and xreadline method now work for unrolled files.
parent
62e709c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
11 deletions
+48
-11
Lib/tempfile.py
Lib/tempfile.py
+12
-11
Lib/test/test_tempfile.py
Lib/test/test_tempfile.py
+31
-0
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/tempfile.py
View file @
beaa3ada
...
@@ -546,10 +546,6 @@ class SpooledTemporaryFile:
...
@@ -546,10 +546,6 @@ class SpooledTemporaryFile:
def
closed
(
self
):
def
closed
(
self
):
return
self
.
_file
.
closed
return
self
.
_file
.
closed
@
property
def
encoding
(
self
):
return
self
.
_file
.
encoding
def
fileno
(
self
):
def
fileno
(
self
):
self
.
rollover
()
self
.
rollover
()
return
self
.
_file
.
fileno
()
return
self
.
_file
.
fileno
()
...
@@ -562,15 +558,17 @@ class SpooledTemporaryFile:
...
@@ -562,15 +558,17 @@ class SpooledTemporaryFile:
@
property
@
property
def
mode
(
self
):
def
mode
(
self
):
return
self
.
_file
.
mode
try
:
return
self
.
_file
.
mode
except
AttributeError
:
return
self
.
_TemporaryFileArgs
[
0
]
@
property
@
property
def
name
(
self
):
def
name
(
self
):
return
self
.
_file
.
name
try
:
return
self
.
_file
.
name
@
property
except
AttributeError
:
def
newlines
(
self
):
return
None
return
self
.
_file
.
newlines
def
next
(
self
):
def
next
(
self
):
return
self
.
_file
.
next
return
self
.
_file
.
next
...
@@ -610,4 +608,7 @@ class SpooledTemporaryFile:
...
@@ -610,4 +608,7 @@ class SpooledTemporaryFile:
return
rv
return
rv
def
xreadlines
(
self
,
*
args
):
def
xreadlines
(
self
,
*
args
):
return
self
.
_file
.
xreadlines
(
*
args
)
try
:
return
self
.
_file
.
xreadlines
(
*
args
)
except
AttributeError
:
return
iter
(
self
.
_file
.
readlines
(
*
args
))
Lib/test/test_tempfile.py
View file @
beaa3ada
...
@@ -738,6 +738,17 @@ class test_SpooledTemporaryFile(TC):
...
@@ -738,6 +738,17 @@ class test_SpooledTemporaryFile(TC):
f
.
write
(
b'x'
)
f
.
write
(
b'x'
)
self
.
assertTrue
(
f
.
_rolled
)
self
.
assertTrue
(
f
.
_rolled
)
def
test_xreadlines
(
self
):
f
=
self
.
do_create
(
max_size
=
20
)
f
.
write
(
b'abc
\
n
'
*
5
)
f
.
seek
(
0
)
self
.
assertFalse
(
f
.
_rolled
)
self
.
assertEqual
(
list
(
f
.
xreadlines
()),
[
b'abc
\
n
'
]
*
5
)
f
.
write
(
b'x
\
n
y'
)
self
.
assertTrue
(
f
.
_rolled
)
f
.
seek
(
0
)
self
.
assertEqual
(
list
(
f
.
xreadlines
()),
[
b'abc
\
n
'
]
*
5
+
[
b'x
\
n
'
,
b'y'
])
def
test_sparse
(
self
):
def
test_sparse
(
self
):
# A SpooledTemporaryFile that is written late in the file will extend
# A SpooledTemporaryFile that is written late in the file will extend
# when that occurs
# when that occurs
...
@@ -793,6 +804,26 @@ class test_SpooledTemporaryFile(TC):
...
@@ -793,6 +804,26 @@ class test_SpooledTemporaryFile(TC):
seek
(
0
,
0
)
seek
(
0
,
0
)
self
.
assertTrue
(
read
(
70
)
==
'a'
*
35
+
'b'
*
35
)
self
.
assertTrue
(
read
(
70
)
==
'a'
*
35
+
'b'
*
35
)
def
test_properties
(
self
):
f
=
tempfile
.
SpooledTemporaryFile
(
max_size
=
10
)
f
.
write
(
b'x'
*
10
)
self
.
assertFalse
(
f
.
_rolled
)
self
.
assertEqual
(
f
.
mode
,
'w+b'
)
self
.
assertIsNone
(
f
.
name
)
with
self
.
assertRaises
(
AttributeError
):
f
.
newlines
with
self
.
assertRaises
(
AttributeError
):
f
.
encoding
f
.
write
(
b'x'
)
self
.
assertTrue
(
f
.
_rolled
)
self
.
assertEqual
(
f
.
mode
,
'w+b'
)
self
.
assertIsNotNone
(
f
.
name
)
with
self
.
assertRaises
(
AttributeError
):
f
.
newlines
with
self
.
assertRaises
(
AttributeError
):
f
.
encoding
def
test_context_manager_before_rollover
(
self
):
def
test_context_manager_before_rollover
(
self
):
# A SpooledTemporaryFile can be used as a context manager
# A SpooledTemporaryFile can be used as a context manager
with
tempfile
.
SpooledTemporaryFile
(
max_size
=
1
)
as
f
:
with
tempfile
.
SpooledTemporaryFile
(
max_size
=
1
)
as
f
:
...
...
Misc/NEWS
View file @
beaa3ada
...
@@ -202,6 +202,11 @@ Core and Builtins
...
@@ -202,6 +202,11 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10355: In SpooledTemporaryFile class mode and name properties and
xreadlines method now work for unrolled files. encoding and newlines
properties now removed as they have no sense and always produced
AttributeError.
- Issue #16686: Fixed a lot of bugs in audioop module. Fixed crashes in
- Issue #16686: Fixed a lot of bugs in audioop module. Fixed crashes in
avgpp(), maxpp() and ratecv(). Fixed an integer overflow in add(), bias(),
avgpp(), maxpp() and ratecv(). Fixed an integer overflow in add(), bias(),
and ratecv(). reverse(), lin2lin() and ratecv() no more lose precision for
and ratecv(). reverse(), lin2lin() and ratecv() no more lose precision for
...
...
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