Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
a011e2b2
Kaydet (Commit)
a011e2b2
authored
Kas 07, 2011
tarafından
Florent Xicluna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
fileinput: replace this last occurence of codecs.open with builtins.open.
üst
5252f9fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
21 deletions
+10
-21
fileinput.py
Lib/fileinput.py
+1
-2
test_fileinput.py
Lib/test/test_fileinput.py
+9
-19
No files found.
Lib/fileinput.py
Dosyayı görüntüle @
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
Dosyayı görüntüle @
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