René's URL Explorer Experiment


Title: bpo-21417: Compression level for zipfile by bbayles · Pull Request #5385 · python/cpython · GitHub

Open Graph Title: bpo-21417: Compression level for zipfile by bbayles · Pull Request #5385 · python/cpython

X Title: bpo-21417: Compression level for zipfile by bbayles · Pull Request #5385 · python/cpython

Description: This PR adds a compresslevel parameter to zipfile.ZipFile(), similar to the one that exists for tarfile.open(). A few things to point out: The default compression type and level remain unchanged. In the issue someone thought compresslevel=None might make it look like no compression is being done - this is in fact the case with the default ZIP_STORED. The ZIP_DEFLATED and ZIP_BZIP2 compression types support different levels - 0 through 9 for the former; 1 through 9 for the latter. Specifying mode='w:bz2' in tarfile.open() leads to a ValueError; the same thing happens here. You can set compresslevel on mode='r', but it doesn't do anything. This matches tarfile.open()'s behavior - there you can do stuff like compresslevel=9000 and compresslevel='kittens' with no error. The ZIP_LZMA compression type doesn't support "levels." It has a similar concept called a preset, however we can't set that here because we're using custom filters. These are mutually exclusive. Because of this, if you try to set mode='w:xz' and compresslevel=9 (or whatever) in tarfile.open, you get an obscure TypeError. I will file a new bug for that. Because of this, I've made compresslevel for ZIP_LZMA and ZIP_STORED have no effect for zipfile.ZipFile. I could raise an exception instead, but given that tarfile.open() ignores parameters that don't make sense (e.g. mode='r:gz' and compresslevel=9000) I thought this was appropriate. I've added tests to exercise this new functionality to the test_zipfile module. In my own testing I used this script, which shows things in action. I did not touch PyZipFile() for simplicity's sake; I can be persuaded to try it out. I will add a few more notes inline. https://bugs.python.org/issue21417

Open Graph Description: This PR adds a compresslevel parameter to zipfile.ZipFile(), similar to the one that exists for tarfile.open(). A few things to point out: The default compression type and level remain unchanged. ...

X Description: This PR adds a compresslevel parameter to zipfile.ZipFile(), similar to the one that exists for tarfile.open(). A few things to point out: The default compression type and level remain unchanged. ...

Opengraph URL: https://github.com/python/cpython/pull/5385

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:9254c1a9-b0ee-5493-a6cf-5d85df7ba49f
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id87EE:1D90CC:17967FB:2021278:6A4F0B57
html-safe-nonce405d1b03cede1a648e6f4098ff2279dccb8f9dfde49d9f06f8c97886d5e5f375
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0VFOjFEOTBDQzoxNzk2N0ZCOjIwMjEyNzg6NkE0RjBCNTciLCJ2aXNpdG9yX2lkIjoiNDMzNDE3ODEwMjkyODE0OTMzNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd15c0c40e88ac6ab5b07f78276b8cbac7edd329073837e19de0e4914d49d4614
hovercard-subject-tagpull_request:165570238
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/5385/files
twitter:imagehttps://avatars.githubusercontent.com/u/1922815?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1922815?s=400&v=4
og:image:altThis PR adds a compresslevel parameter to zipfile.ZipFile(), similar to the one that exists for tarfile.open(). A few things to point out: The default compression type and level remain unchanged. ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2b8f23afb982271f1b22258a94aede67a6b77760
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/5385/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F5385%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F5385%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/5385/files
Reloadhttps://github.com/python/cpython/pull/5385/files
Reloadhttps://github.com/python/cpython/pull/5385/files
Please reload this pagehttps://github.com/python/cpython/pull/5385/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/5385/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.6k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
gpsheadhttps://github.com/gpshead
python:masterhttps://github.com/python/cpython/tree/master
bbayles:zipfile-compresslevelhttps://github.com/bbayles/cpython/tree/zipfile-compresslevel
Conversation 12 https://github.com/python/cpython/pull/5385
Commits 13 https://github.com/python/cpython/pull/5385/commits
Checks 0 https://github.com/python/cpython/pull/5385/checks
Files changed https://github.com/python/cpython/pull/5385/files
Please reload this pagehttps://github.com/python/cpython/pull/5385/files
bpo-21417: Compression level for zipfile https://github.com/python/cpython/pull/5385/files#top
Show all changes 13 commits https://github.com/python/cpython/pull/5385/files
23f3310 First stab at adding compresslevel to zipfile bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/23f3310331474440a8c16d98f808427fad9d0a3c
b029977 Smooth out errors for bz2 and lzma bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/b02997775bcb5fa200e3951a52bfe7d748079769
9c57700 Remove now-spurious comments bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/9c5770042ed9e67bea3bc2b162d5cce7aa9f2a4d
1508073 No it was not needed bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/15080736f30df418d3b9c4cbecd6c039fb1fb361
9b5d74e Don't open the PyZipFile box yet bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/9b5d74ed9a0d2b8fc3c1f4a380f3be618c6e8877
6504581 Add basic notes about compresslevel to docs bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/65045819e0459b1e40cf79ce39745bd5b531436f
46eb503 Add basic tests for compresslevel bbayles Jan 27, 2018 https://github.com/python/cpython/pull/5385/commits/46eb50360a98d8459bf0fda4d164454c20c39d1e
7ff8272 Make ZipInfo compression level private bbayles Jan 28, 2018 https://github.com/python/cpython/pull/5385/commits/7ff82720ffb914277300e2dfa0e4b93264b453c1
8310c79 Test implicit and overridden compression levels bbayles Jan 28, 2018 https://github.com/python/cpython/pull/5385/commits/8310c7951b8f0f37d6a7b59b4ab570080195d4a2
8ab542c Add Misc/NEWS entry bbayles Jan 28, 2018 https://github.com/python/cpython/pull/5385/commits/8ab542c3e6198578ebd71a4bd41d135378680607
0e3f9ce Correct typo in test comment. bbayles Jan 29, 2018 https://github.com/python/cpython/pull/5385/commits/0e3f9ced44bd5121e7f4e8f3c141d44ffab72358
3925fc2 compress_level to compresslevel throughout bbayles Jan 29, 2018 https://github.com/python/cpython/pull/5385/commits/3925fc2f310b4eb4a46f16fa7bb562b11242a8b0
c390f64 Update compresslevel documentation targets bbayles Jan 29, 2018 https://github.com/python/cpython/pull/5385/commits/c390f645d5bccade0d7744164483a87729aa5346
Clear filters https://github.com/python/cpython/pull/5385/files
Please reload this pagehttps://github.com/python/cpython/pull/5385/files
Please reload this pagehttps://github.com/python/cpython/pull/5385/files
zipfile.rst https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
test_zipfile.py https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
zipfile.py https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
2018-01-28-07-55-10.bpo-21417.JFnV99.rst https://github.com/python/cpython/pull/5385/files#diff-56baa489db95aefb1ca9878f396997c2658bfce7f3c0d5b442eed58e5c04f677
Doc/library/zipfile.rsthttps://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
View file https://github.com/bbayles/cpython/blob/c390f645d5bccade0d7744164483a87729aa5346/Doc/library/zipfile.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5385/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
bbayleshttps://github.com/bbayles
Jan 28, 2018https://github.com/python/cpython/pull/5385/files#r164301469
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
style guidehttps://devguide.python.org/documenting/#use-of-whitespace
Please reload this pagehttps://github.com/python/cpython/pull/5385/files
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
https://github.com/python/cpython/pull/5385/files#diff-8a20c37fb313d7b188ae15bb57b351cc2ab73cbdcb6b2aee44cf2f8451768086
Lib/test/test_zipfile.pyhttps://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
View file https://github.com/bbayles/cpython/blob/c390f645d5bccade0d7744164483a87729aa5346/Lib/test/test_zipfile.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5385/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
https://github.com/python/cpython/pull/5385/files#diff-88215aededc3f81c55ba2432fe67617be9fc3faff9cb10e0c01f710adfcba426
Lib/zipfile.pyhttps://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
View file https://github.com/bbayles/cpython/blob/c390f645d5bccade0d7744164483a87729aa5346/Lib/zipfile.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5385/{{ revealButtonHref }}
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
https://github.com/python/cpython/pull/5385/files#diff-b5cf7374d79aae191c1e38d0959527e0bbb7a95e0df5b125a8b1056cc2c54851
Misc/NEWS.d/next/Library/2018-01-28-07-55-10.bpo-21417.JFnV99.rsthttps://github.com/python/cpython/pull/5385/files#diff-56baa489db95aefb1ca9878f396997c2658bfce7f3c0d5b442eed58e5c04f677
View file https://github.com/bbayles/cpython/blob/c390f645d5bccade0d7744164483a87729aa5346/Misc/NEWS.d/next/Library/2018-01-28-07-55-10.bpo-21417.JFnV99.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/5385/{{ revealButtonHref }}
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.