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
214db63d
Commit
214db63d
authored
May 02, 2006
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use open() instead of file()
parent
b2045837
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
23 deletions
+23
-23
Lib/mailbox.py
Lib/mailbox.py
+20
-20
Lib/test/test_mailbox.py
Lib/test/test_mailbox.py
+3
-3
No files found.
Lib/mailbox.py
View file @
214db63d
...
...
@@ -294,7 +294,7 @@ class Maildir(Mailbox):
def
get_message
(
self
,
key
):
"""Return a Message representation or raise a KeyError."""
subpath
=
self
.
_lookup
(
key
)
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
subpath
),
'r'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
subpath
),
'r'
)
try
:
msg
=
MaildirMessage
(
f
)
finally
:
...
...
@@ -308,7 +308,7 @@ class Maildir(Mailbox):
def
get_string
(
self
,
key
):
"""Return a string representation or raise a KeyError."""
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
self
.
_lookup
(
key
)),
'r'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
self
.
_lookup
(
key
)),
'r'
)
try
:
return
f
.
read
()
finally
:
...
...
@@ -316,7 +316,7 @@ class Maildir(Mailbox):
def
get_file
(
self
,
key
):
"""Return a file-like representation or raise a KeyError."""
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
self
.
_lookup
(
key
)),
'rb'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
self
.
_lookup
(
key
)),
'rb'
)
return
_ProxyFile
(
f
)
def
iterkeys
(
self
):
...
...
@@ -422,7 +422,7 @@ class Maildir(Mailbox):
except
OSError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
Maildir
.
_count
+=
1
return
file
(
path
,
'wb+'
)
return
open
(
path
,
'wb+'
)
else
:
raise
else
:
...
...
@@ -471,15 +471,15 @@ class _singlefileMailbox(Mailbox):
"""Initialize a single-file mailbox."""
Mailbox
.
__init__
(
self
,
path
,
factory
,
create
)
try
:
f
=
file
(
self
.
_path
,
'rb+'
)
f
=
open
(
self
.
_path
,
'rb+'
)
except
IOError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
if
create
:
f
=
file
(
self
.
_path
,
'wb+'
)
f
=
open
(
self
.
_path
,
'wb+'
)
else
:
raise
NoSuchMailboxError
(
self
.
_path
)
elif
e
.
errno
==
errno
.
EACCES
:
f
=
file
(
self
.
_path
,
'rb'
)
f
=
open
(
self
.
_path
,
'rb'
)
else
:
raise
self
.
_file
=
f
...
...
@@ -572,7 +572,7 @@ class _singlefileMailbox(Mailbox):
os
.
rename
(
new_file
.
name
,
self
.
_path
)
else
:
raise
self
.
_file
=
file
(
self
.
_path
,
'rb+'
)
self
.
_file
=
open
(
self
.
_path
,
'rb+'
)
self
.
_toc
=
new_toc
self
.
_pending
=
False
if
self
.
_locked
:
...
...
@@ -792,7 +792,7 @@ class MH(Mailbox):
"""Remove the keyed message; raise KeyError if it doesn't exist."""
path
=
os
.
path
.
join
(
self
.
_path
,
str
(
key
))
try
:
f
=
file
(
path
,
'rb+'
)
f
=
open
(
path
,
'rb+'
)
except
IOError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
KeyError
(
'No message with key: %s'
%
key
)
...
...
@@ -814,7 +814,7 @@ class MH(Mailbox):
"""Replace the keyed message; raise KeyError if it doesn't exist."""
path
=
os
.
path
.
join
(
self
.
_path
,
str
(
key
))
try
:
f
=
file
(
path
,
'rb+'
)
f
=
open
(
path
,
'rb+'
)
except
IOError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
KeyError
(
'No message with key: %s'
%
key
)
...
...
@@ -838,9 +838,9 @@ class MH(Mailbox):
"""Return a Message representation or raise a KeyError."""
try
:
if
self
.
_locked
:
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r+'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r+'
)
else
:
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r'
)
except
IOError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
KeyError
(
'No message with key: %s'
%
key
)
...
...
@@ -865,9 +865,9 @@ class MH(Mailbox):
"""Return a string representation or raise a KeyError."""
try
:
if
self
.
_locked
:
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r+'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r+'
)
else
:
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r'
)
except
IOError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
KeyError
(
'No message with key: %s'
%
key
)
...
...
@@ -887,7 +887,7 @@ class MH(Mailbox):
def
get_file
(
self
,
key
):
"""Return a file-like representation or raise a KeyError."""
try
:
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'rb'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'rb'
)
except
IOError
,
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
KeyError
(
'No message with key: %s'
%
key
)
...
...
@@ -911,7 +911,7 @@ class MH(Mailbox):
def
lock
(
self
):
"""Lock the mailbox."""
if
not
self
.
_locked
:
self
.
_file
=
file
(
os
.
path
.
join
(
self
.
_path
,
'.mh_sequences'
),
'rb+'
)
self
.
_file
=
open
(
os
.
path
.
join
(
self
.
_path
,
'.mh_sequences'
),
'rb+'
)
_lock_file
(
self
.
_file
)
self
.
_locked
=
True
...
...
@@ -963,7 +963,7 @@ class MH(Mailbox):
def
get_sequences
(
self
):
"""Return a name-to-key-list dictionary to define each sequence."""
results
=
{}
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
'.mh_sequences'
),
'r'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
'.mh_sequences'
),
'r'
)
try
:
all_keys
=
set
(
self
.
keys
())
for
line
in
f
:
...
...
@@ -989,7 +989,7 @@ class MH(Mailbox):
def
set_sequences
(
self
,
sequences
):
"""Set sequences using the given name-to-key-list dictionary."""
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
'.mh_sequences'
),
'r+'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
'.mh_sequences'
),
'r+'
)
try
:
os
.
close
(
os
.
open
(
f
.
name
,
os
.
O_WRONLY
|
os
.
O_TRUNC
))
for
name
,
keys
in
sequences
.
iteritems
():
...
...
@@ -1024,7 +1024,7 @@ class MH(Mailbox):
for
key
in
self
.
iterkeys
():
if
key
-
1
!=
prev
:
changes
.
append
((
key
,
prev
+
1
))
f
=
file
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r+'
)
f
=
open
(
os
.
path
.
join
(
self
.
_path
,
str
(
key
)),
'r+'
)
try
:
if
self
.
_locked
:
_lock_file
(
f
)
...
...
@@ -1864,7 +1864,7 @@ def _create_carefully(path):
"""Create a file if it doesn't exist and open for reading and writing."""
fd
=
os
.
open
(
path
,
os
.
O_CREAT
|
os
.
O_EXCL
|
os
.
O_RDWR
)
try
:
return
file
(
path
,
'rb+'
)
return
open
(
path
,
'rb+'
)
finally
:
os
.
close
(
fd
)
...
...
Lib/test/test_mailbox.py
View file @
214db63d
...
...
@@ -717,7 +717,7 @@ class _TestMboxMMDF(TestMailbox):
self._box._file.seek(0)
contents = self._box._file.read()
self._box.close()
self.assert_(contents ==
file
(self._path, 'rb').read())
self.assert_(contents ==
open
(self._path, 'rb').read())
self._box = self._factory(self._path)
...
...
@@ -1473,7 +1473,7 @@ class TestProxyFile(TestProxyFileBase):
def setUp(self):
self._path = test_support.TESTFN
self._file =
file
(self._path, 'wb+')
self._file =
open
(self._path, 'wb+')
def tearDown(self):
self._file.close()
...
...
@@ -1522,7 +1522,7 @@ class TestPartialFile(TestProxyFileBase):
def setUp(self):
self._path = test_support.TESTFN
self._file =
file
(self._path, 'wb+')
self._file =
open
(self._path, 'wb+')
def tearDown(self):
self._file.close()
...
...
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