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
a011e2b2
Commit
a011e2b2
authored
Nov 07, 2011
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fileinput: replace this last occurence of codecs.open with builtins.open.
parent
5252f9fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
21 deletions
+10
-21
Lib/fileinput.py
Lib/fileinput.py
+1
-2
Lib/test/test_fileinput.py
Lib/test/test_fileinput.py
+9
-19
No files found.
Lib/fileinput.py
View file @
a011e2b2
...
...
@@ -398,9 +398,8 @@ def hook_compressed(filename, mode):
def
hook_encoded
(
encoding
):
import
codecs
def
openhook
(
filename
,
mode
):
return
codecs
.
open
(
filename
,
mode
,
encoding
)
return
open
(
filename
,
mode
,
encoding
=
encoding
)
return
openhook
...
...
Lib/test/test_fileinput.py
View file @
a011e2b2
...
...
@@ -7,8 +7,7 @@ import sys
import
re
import
fileinput
import
collections
import
types
import
codecs
import
builtins
import
unittest
try
:
...
...
@@ -807,18 +806,8 @@ class Test_hook_compressed(unittest.TestCase):
@
staticmethod
def
replace_builtin_open
(
new_open_func
):
builtins_type
=
type
(
__builtins__
)
if
builtins_type
is
dict
:
original_open
=
__builtins__
[
"open"
]
__builtins__
[
"open"
]
=
new_open_func
elif
builtins_type
is
types
.
ModuleType
:
original_open
=
__builtins__
.
open
__builtins__
.
open
=
new_open_func
else
:
raise
RuntimeError
(
"unknown __builtins__ type: %r (unable to replace open)"
%
builtins_type
)
original_open
=
builtins
.
open
builtins
.
open
=
new_open_func
return
original_open
class
Test_hook_encoded
(
unittest
.
TestCase
):
...
...
@@ -829,21 +818,22 @@ class Test_hook_encoded(unittest.TestCase):
result
=
fileinput
.
hook_encoded
(
encoding
)
fake_open
=
InvocationRecorder
()
original_open
=
codec
s
.
open
codec
s
.
open
=
fake_open
original_open
=
builtin
s
.
open
builtin
s
.
open
=
fake_open
try
:
filename
=
object
()
mode
=
object
()
open_result
=
result
(
filename
,
mode
)
finally
:
codec
s
.
open
=
original_open
builtin
s
.
open
=
original_open
self
.
assertEqual
(
fake_open
.
invocation_count
,
1
)
args
=
fake_open
.
last_invocation
[
0
]
args
,
kwargs
=
fake_open
.
last_invocation
self
.
assertIs
(
args
[
0
],
filename
)
self
.
assertIs
(
args
[
1
],
mode
)
self
.
assertIs
(
args
[
2
],
encoding
)
self
.
assertIs
(
kwargs
.
pop
(
'encoding'
),
encoding
)
self
.
assertFalse
(
kwargs
)
def
test_main
():
run_unittest
(
...
...
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