FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-39121: write gzip header OS information by wungad · Pull Request #17682 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) No extension  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 15 additions & 1 deletion Lib/gzip.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

READ, WRITE = 1, 2

# OS field values as specified in RFC 1952
_OS_CODES = {
'unix': b'\x03',
'ntfs': b'\x0b',
'unknown': b'\xff'
}
_OS_UNIX = ('linux', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'aix')
_OS_NTFS = ('win32')

_COMPRESS_LEVEL_FAST = 1
_COMPRESS_LEVEL_TRADEOFF = 6
_COMPRESS_LEVEL_BEST = 9
Expand Down Expand Up @@ -264,7 +273,12 @@ def _write_gzip_header(self, compresslevel):
else:
xfl = b'\000'
self.fileobj.write(xfl)
self.fileobj.write(b'\377')
if sys.platform.startswith(_OS_UNIX):
self.fileobj.write(_OS_CODES['unix'])
elif sys.platform.startswith(_OS_NTFS):
self.fileobj.write(_OS_CODES['ntfs'])
else:
self.fileobj.write(_OS_CODES['unknown'])
if fname:
self.fileobj.write(fname + b'\000')

Expand Down
9 changes: 7 additions & 2 deletions Lib/test/test_gzip.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,12 @@ def test_mtime(self):

def test_metadata(self):
mtime = 123456789

if sys.platform.startswith(gzip._OS_UNIX):
os_code = gzip._OS_CODES['unix']
elif sys.platform.startswith(gzip._OS_NTFS):
os_code = gzip._OS_CODES['ntfs']
else:
os_code = gzip._OS_CODES['unknown']
with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite:
fWrite.write(data1)

Expand All @@ -338,7 +343,7 @@ def test_metadata(self):
self.assertEqual(xflByte, b'\x02') # maximum compression

osByte = fRead.read(1)
self.assertEqual(osByte, b'\xff') # OS "unknown" (OS-independent)
self.assertEqual(osByte, os_code) # gzip OS code

# Since the FNAME flag is set, the zero-terminated filename follows.
# RFC 1952 specifies that this is the name of the input file, if any.
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ Grzegorz Makarewicz
David Malcolm
Greg Malcolm
William Mallard
Robert Mandic
Ken Manheimer
Vladimir Marangozov
Colin Marc
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Writing gzip files sets 10th byte of the gzip header (the OS information)
based on :attr:`sys.platform` Patch by Robert Mandic.

Back | FazBrowse Home | New Git URL