Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python-stdlib/gzip/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ def GzipFile(fileobj):
return deflate.DeflateIO(fileobj, deflate.GZIP, _WBITS)


def open(filename, mode="rb"):
def open(filename, mode="rb", /):
return deflate.DeflateIO(builtins.open(filename, mode), deflate.GZIP, _WBITS, True)


if hasattr(deflate.DeflateIO, "write"):

def compress(data):
def compress(data, /):
f = io.BytesIO()
with GzipFile(fileobj=f) as g:
g.write(data)
return f.getvalue()


def decompress(data):
def decompress(data, /):
f = io.BytesIO(data)
with GzipFile(fileobj=f) as g:
return g.read()
2 changes: 1 addition & 1 deletion python-stdlib/gzip/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="1.0.1")
metadata(version="1.0.2")

module("gzip.py")
26 changes: 26 additions & 0 deletions python-stdlib/gzip/test_gzip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import gzip
import unittest


class TestPositionalOnly(unittest.TestCase):
def test_open(self):
with self.assertRaises(TypeError):
gzip.open(filename="/__gzip_signature_check__.gz")
with self.assertRaises(TypeError):
gzip.open("/__gzip_signature_check__.gz", mode="rb")

def test_decompress(self):
data = bytes.fromhex("1f8b08000000000002ffcb48cdc9c9070086a6103605000000")
self.assertEqual(gzip.decompress(data), b"hello")
with self.assertRaises(TypeError):
gzip.decompress(data=data)

@unittest.skipUnless(hasattr(gzip, "compress"), "compression unavailable")
def test_compress(self):
self.assertEqual(gzip.decompress(gzip.compress(b"hello")), b"hello")
with self.assertRaises(TypeError):
gzip.compress(data=b"hello")


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion python-stdlib/zlib/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="1.0.0", description="Compression and decompression using the deflate algorithm")
metadata(version="1.0.1", description="Compression and decompression using the deflate algorithm")

module("zlib.py")
27 changes: 27 additions & 0 deletions python-stdlib/zlib/test_zlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
import zlib


class TestPositionalOnly(unittest.TestCase):
def test_decompress(self):
data = bytes.fromhex("789ccb48cdc9c90700062c0215")
# positional only
with self.assertRaises(TypeError):
zlib.decompress(data=data)
# positional or keyword
self.assertEqual(zlib.decompress(data), b"hello")
self.assertEqual(zlib.decompress(data, 15), b"hello")
self.assertEqual(zlib.decompress(data, wbits=0), b"hello")

@unittest.skipUnless(hasattr(zlib, "compress"), "compression unavailable")
def test_compress(self):
# positional only
with self.assertRaises(TypeError):
zlib.compress(data=b"hello")
# positional or keyword
self.assertEqual(zlib.decompress(zlib.compress(b"hello")), b"hello")
self.assertEqual(zlib.decompress(zlib.compress(b"hello", 15), 15), b"hello")
self.assertEqual(zlib.decompress(zlib.compress(b"hello", 15), wbits=15), b"hello")

if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions python-stdlib/zlib/zlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def _decode_wbits(wbits, decompress):

if hasattr(deflate.DeflateIO, "write"):

def compress(data, wbits=_MAX_WBITS):
def compress(data, /, wbits=_MAX_WBITS):
f = io.BytesIO()
with deflate.DeflateIO(f, *_decode_wbits(wbits, False)) as g:
g.write(data)
return f.getvalue()


def decompress(data, wbits=_MAX_WBITS):
def decompress(data, /, wbits=_MAX_WBITS):
f = io.BytesIO(data)
with deflate.DeflateIO(f, *_decode_wbits(wbits, True)) as g:
return g.read()
2 changes: 2 additions & 0 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function ci_package_tests_run {
python-stdlib/functools/test_partial.py \
python-stdlib/functools/test_reduce.py \
python-stdlib/functools/test_cache.py \
python-stdlib/gzip/test_gzip.py \
python-stdlib/heapq/test_heapq.py \
python-stdlib/hmac/test_hmac.py \
python-stdlib/itertools/test_itertools.py \
Expand All @@ -78,6 +79,7 @@ function ci_package_tests_run {
python-stdlib/pickle/test_pickle.py \
python-stdlib/pprint/test_pprint.py \
python-stdlib/string/test_translate.py \
python-stdlib/zlib/test_zlib.py \
python-stdlib/unittest/tests/exception.py \
unix-ffi/gettext/test_gettext.py \
unix-ffi/pwd/test_getpwnam.py \
Expand Down
Loading