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
3f8aca11
Kaydet (Commit)
3f8aca11
authored
Şub 06, 2007
tarafından
Lars Gustäbel
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1652681: create nonexistent files in append mode and
allow appending to empty files.
üst
5f9c6ae5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
3 deletions
+68
-3
libtarfile.tex
Doc/lib/libtarfile.tex
+2
-1
tarfile.py
Lib/tarfile.py
+7
-2
test_tarfile.py
Lib/test/test_tarfile.py
+56
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libtarfile.tex
Dosyayı görüntüle @
3f8aca11
...
@@ -36,7 +36,8 @@ Some facts and figures:
...
@@ -36,7 +36,8 @@ Some facts and figures:
\lineii
{
'r:'
}{
Open for reading exclusively without compression.
}
\lineii
{
'r:'
}{
Open for reading exclusively without compression.
}
\lineii
{
'r:gz'
}{
Open for reading with gzip compression.
}
\lineii
{
'r:gz'
}{
Open for reading with gzip compression.
}
\lineii
{
'r:bz2'
}{
Open for reading with bzip2 compression.
}
\lineii
{
'r:bz2'
}{
Open for reading with bzip2 compression.
}
\lineii
{
'a' or 'a:'
}{
Open for appending with no compression.
}
\lineii
{
'a' or 'a:'
}{
Open for appending with no compression. The file
is created if it does not exist.
}
\lineii
{
'w' or 'w:'
}{
Open for uncompressed writing.
}
\lineii
{
'w' or 'w:'
}{
Open for uncompressed writing.
}
\lineii
{
'w:gz'
}{
Open for gzip compressed writing.
}
\lineii
{
'w:gz'
}{
Open for gzip compressed writing.
}
\lineii
{
'w:bz2'
}{
Open for bzip2 compressed writing.
}
\lineii
{
'w:bz2'
}{
Open for bzip2 compressed writing.
}
...
...
Lib/tarfile.py
Dosyayı görüntüle @
3f8aca11
...
@@ -1060,6 +1060,10 @@ class TarFile(object):
...
@@ -1060,6 +1060,10 @@ class TarFile(object):
self
.
mode
=
{
"r"
:
"rb"
,
"a"
:
"r+b"
,
"w"
:
"wb"
}[
mode
]
self
.
mode
=
{
"r"
:
"rb"
,
"a"
:
"r+b"
,
"w"
:
"wb"
}[
mode
]
if
not
fileobj
:
if
not
fileobj
:
if
self
.
_mode
==
"a"
and
not
os
.
path
.
exists
(
self
.
name
):
# Create nonexistent files in append mode.
self
.
_mode
=
"w"
self
.
mode
=
"wb"
fileobj
=
file
(
self
.
name
,
self
.
mode
)
fileobj
=
file
(
self
.
name
,
self
.
mode
)
self
.
_extfileobj
=
False
self
.
_extfileobj
=
False
else
:
else
:
...
@@ -1093,7 +1097,8 @@ class TarFile(object):
...
@@ -1093,7 +1097,8 @@ class TarFile(object):
self
.
fileobj
.
seek
(
0
)
self
.
fileobj
.
seek
(
0
)
break
break
if
tarinfo
is
None
:
if
tarinfo
is
None
:
self
.
fileobj
.
seek
(
-
BLOCKSIZE
,
1
)
if
self
.
offset
>
0
:
self
.
fileobj
.
seek
(
-
BLOCKSIZE
,
1
)
break
break
if
self
.
_mode
in
"aw"
:
if
self
.
_mode
in
"aw"
:
...
@@ -1120,7 +1125,7 @@ class TarFile(object):
...
@@ -1120,7 +1125,7 @@ class TarFile(object):
'r:' open for reading exclusively uncompressed
'r:' open for reading exclusively uncompressed
'r:gz' open for reading with gzip compression
'r:gz' open for reading with gzip compression
'r:bz2' open for reading with bzip2 compression
'r:bz2' open for reading with bzip2 compression
'a' or 'a:' open for appending
'a' or 'a:' open for appending
, creating the file if necessary
'w' or 'w:' open for writing without compression
'w' or 'w:' open for writing without compression
'w:gz' open for writing with gzip compression
'w:gz' open for writing with gzip compression
'w:bz2' open for writing with bzip2 compression
'w:bz2' open for writing with bzip2 compression
...
...
Lib/test/test_tarfile.py
Dosyayı görüntüle @
3f8aca11
...
@@ -305,6 +305,61 @@ class WriteTest(BaseTest):
...
@@ -305,6 +305,61 @@ class WriteTest(BaseTest):
self
.
assertEqual
(
self
.
dst
.
getnames
(),
[],
"added the archive to itself"
)
self
.
assertEqual
(
self
.
dst
.
getnames
(),
[],
"added the archive to itself"
)
class
AppendTest
(
unittest
.
TestCase
):
# Test append mode (cp. patch #1652681).
def
setUp
(
self
):
self
.
tarname
=
tmpname
()
if
os
.
path
.
exists
(
self
.
tarname
):
os
.
remove
(
self
.
tarname
)
def
_add_testfile
(
self
,
fileobj
=
None
):
tar
=
tarfile
.
open
(
self
.
tarname
,
"a"
,
fileobj
=
fileobj
)
tar
.
addfile
(
tarfile
.
TarInfo
(
"bar"
))
tar
.
close
()
def
_create_testtar
(
self
):
src
=
tarfile
.
open
(
tarname
())
t
=
src
.
getmember
(
"0-REGTYPE"
)
t
.
name
=
"foo"
f
=
src
.
extractfile
(
t
)
tar
=
tarfile
.
open
(
self
.
tarname
,
"w"
)
tar
.
addfile
(
t
,
f
)
tar
.
close
()
def
_test
(
self
,
names
=
[
"bar"
],
fileobj
=
None
):
tar
=
tarfile
.
open
(
self
.
tarname
,
fileobj
=
fileobj
)
self
.
assert_
(
tar
.
getnames
()
==
names
)
def
test_non_existing
(
self
):
self
.
_add_testfile
()
self
.
_test
()
def
test_empty
(
self
):
open
(
self
.
tarname
,
"w"
)
.
close
()
self
.
_add_testfile
()
self
.
_test
()
def
test_empty_fileobj
(
self
):
fobj
=
StringIO
.
StringIO
()
self
.
_add_testfile
(
fobj
)
fobj
.
seek
(
0
)
self
.
_test
(
fileobj
=
fobj
)
def
test_fileobj
(
self
):
self
.
_create_testtar
()
data
=
open
(
self
.
tarname
)
.
read
()
fobj
=
StringIO
.
StringIO
(
data
)
self
.
_add_testfile
(
fobj
)
fobj
.
seek
(
0
)
self
.
_test
(
names
=
[
"foo"
,
"bar"
],
fileobj
=
fobj
)
def
test_existing
(
self
):
self
.
_create_testtar
()
self
.
_add_testfile
()
self
.
_test
(
names
=
[
"foo"
,
"bar"
])
class
Write100Test
(
BaseTest
):
class
Write100Test
(
BaseTest
):
# The name field in a tar header stores strings of at most 100 chars.
# The name field in a tar header stores strings of at most 100 chars.
# If a string is shorter than 100 chars it has to be padded with '\0',
# If a string is shorter than 100 chars it has to be padded with '\0',
...
@@ -711,6 +766,7 @@ def test_main():
...
@@ -711,6 +766,7 @@ def test_main():
ReadAsteriskTest
,
ReadAsteriskTest
,
ReadStreamAsteriskTest
,
ReadStreamAsteriskTest
,
WriteTest
,
WriteTest
,
AppendTest
,
Write100Test
,
Write100Test
,
WriteSize0Test
,
WriteSize0Test
,
WriteStreamTest
,
WriteStreamTest
,
...
...
Misc/NEWS
Dosyayı görüntüle @
3f8aca11
...
@@ -126,6 +126,9 @@ Core and builtins
...
@@ -126,6 +126,9 @@ Core and builtins
Library
Library
-------
-------
- Patch #1652681: tarfile.py: create nonexistent files in append mode and
allow appending to empty files.
- Bug #1124861: Automatically create pipes if GetStdHandle fails in
- Bug #1124861: Automatically create pipes if GetStdHandle fails in
subprocess.
subprocess.
...
...
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