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
7626ef93
Commit
7626ef93
authored
Jan 27, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an entry for tarfile.
parent
a199368b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
Doc/whatsnew/3.2.rst
Doc/whatsnew/3.2.rst
+32
-0
No files found.
Doc/whatsnew/3.2.rst
View file @
7626ef93
...
...
@@ -1318,6 +1318,38 @@ wrong results.
(Patch submitted by Nir Aides in :issue:`7610`.)
tarfile
-------
The :class:`~tarfile.TarFile` class can now be used as a content manager. In
addition, its :meth:`~tarfile.TarFile.add` method has a new option, *filter*,
that controls which files are added to the archive and allows the file metadata
to be edited.
The new *filter* option replaces the older, less flexible *exclude* parameter
which is now deprecated. If specified, the optional *filter* parameter needs to
be a :term:`keyword argument`. The user-supplied filter function accepts a
:class:`~tarfile.TarInfo` object and returns an updated
:class:`~tarfile.TarInfo` object, or if it wants the file to be excluded, the
function can return *None*::
>>> import tarfile, glob
>>> def myfilter(tarinfo):
if tarinfo.isfile(): # only save real files
tarinfo.uname = 'monty' # redact the user name
return tarinfo
>>> with tarfile.TarFile(name='myarchive.tar', mode='w') as tf:
for filename in glob.glob('*.txt'):
tf.add(filename, filter=myfilter)
tf.list()
-rw-r--r-- monty/501 902 2011-01-26 17:59:11 annotations.txt
-rw-r--r-- monty/501 123 2011-01-26 17:59:11 general_questions.txt
-rw-r--r-- monty/501 3514 2011-01-26 17:59:11 prion.txt
-rw-r--r-- monty/501 124 2011-01-26 17:59:11 py_todo.txt
-rw-r--r-- monty/501 1399 2011-01-26 17:59:11 semaphore_notes.txt
hashlib
-------
...
...
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