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
7fd59e09
Kaydet (Commit)
7fd59e09
authored
Agu 28, 2014
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
properly handle file closing in error cases (closes #22266)
üst
ce2ec49d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
29 deletions
+48
-29
tarfile.py
Lib/tarfile.py
+48
-29
No files found.
Lib/tarfile.py
Dosyayı görüntüle @
7fd59e09
...
...
@@ -417,28 +417,34 @@ class _Stream:
self
.
pos
=
0L
self
.
closed
=
False
if
comptype
==
"gz"
:
try
:
import
zlib
except
ImportError
:
raise
CompressionError
(
"zlib module is not available"
)
self
.
zlib
=
zlib
self
.
crc
=
zlib
.
crc32
(
""
)
&
0xffffffff
L
if
mode
==
"r"
:
self
.
_init_read_gz
()
else
:
self
.
_init_write_gz
()
try
:
if
comptype
==
"gz"
:
try
:
import
zlib
except
ImportError
:
raise
CompressionError
(
"zlib module is not available"
)
self
.
zlib
=
zlib
self
.
crc
=
zlib
.
crc32
(
""
)
&
0xffffffff
L
if
mode
==
"r"
:
self
.
_init_read_gz
()
else
:
self
.
_init_write_gz
()
if
comptype
==
"bz2"
:
try
:
import
bz2
except
ImportError
:
raise
CompressionError
(
"bz2 module is not available"
)
if
mode
==
"r"
:
self
.
dbuf
=
""
self
.
cmp
=
bz2
.
BZ2Decompressor
()
else
:
self
.
cmp
=
bz2
.
BZ2Compressor
()
elif
comptype
==
"bz2"
:
try
:
import
bz2
except
ImportError
:
raise
CompressionError
(
"bz2 module is not available"
)
if
mode
==
"r"
:
self
.
dbuf
=
""
self
.
cmp
=
bz2
.
BZ2Decompressor
()
else
:
self
.
cmp
=
bz2
.
BZ2Compressor
()
except
:
if
not
self
.
_extfileobj
:
self
.
fileobj
.
close
()
self
.
closed
=
True
raise
def
__del__
(
self
):
if
hasattr
(
self
,
"closed"
)
and
not
self
.
closed
:
...
...
@@ -1685,9 +1691,12 @@ class TarFile(object):
if
filemode
not
in
(
"r"
,
"w"
):
raise
ValueError
(
"mode must be 'r' or 'w'"
)
t
=
cls
(
name
,
filemode
,
_Stream
(
name
,
filemode
,
comptype
,
fileobj
,
bufsize
),
**
kwargs
)
stream
=
_Stream
(
name
,
filemode
,
comptype
,
fileobj
,
bufsize
)
try
:
t
=
cls
(
name
,
filemode
,
stream
,
**
kwargs
)
except
:
stream
.
close
()
raise
t
.
_extfileobj
=
False
return
t
...
...
@@ -1718,17 +1727,23 @@ class TarFile(object):
except
(
ImportError
,
AttributeError
):
raise
CompressionError
(
"gzip module is not available"
)
if
fileobj
is
None
:
fileobj
=
bltn_open
(
name
,
mode
+
"b"
)
try
:
fileobj
=
gzip
.
GzipFile
(
name
,
mode
,
compresslevel
,
fileobj
)
except
OSError
:
if
fileobj
is
not
None
and
mode
==
'r'
:
raise
ReadError
(
"not a gzip file"
)
raise
try
:
t
=
cls
.
taropen
(
name
,
mode
,
gzip
.
GzipFile
(
name
,
mode
,
compresslevel
,
fileobj
),
**
kwargs
)
t
=
cls
.
taropen
(
name
,
mode
,
fileobj
,
**
kwargs
)
except
IOError
:
fileobj
.
close
()
if
mode
==
'r'
:
raise
ReadError
(
"not a gzip file"
)
raise
except
:
fileobj
.
close
()
raise
t
.
_extfileobj
=
False
return
t
...
...
@@ -1753,9 +1768,13 @@ class TarFile(object):
try
:
t
=
cls
.
taropen
(
name
,
mode
,
fileobj
,
**
kwargs
)
except
(
IOError
,
EOFError
):
fileobj
.
close
()
if
mode
==
'r'
:
raise
ReadError
(
"not a bzip2 file"
)
raise
except
:
fileobj
.
close
()
raise
t
.
_extfileobj
=
False
return
t
...
...
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