Skip to content

Commit

Permalink
Apply compatibility shim for text_encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 24, 2022
1 parent b190479 commit 6ed5f3e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions zipp.py
@@ -1,4 +1,5 @@
import io
import sys
import posixpath
import zipfile
import itertools
Expand All @@ -9,6 +10,18 @@
__all__ = ['Path']


def _text_encoding(encoding, stacklevel=2, /):
"""
Backport stub of io.text_encoding.
"""
return encoding


text_encoding = (
io.text_encoding if sys.version_info > (3, 10) else _text_encoding # type: ignore
)


def _parents(path):
"""
Given a path with elements separated by
Expand Down Expand Up @@ -258,7 +271,7 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
raise ValueError("encoding args invalid for binary operation")
return stream
else:
kwargs["encoding"] = io.text_encoding(kwargs.get("encoding"))
kwargs["encoding"] = text_encoding(kwargs.get("encoding"))
return io.TextIOWrapper(stream, *args, **kwargs)

@property
Expand All @@ -282,7 +295,7 @@ def filename(self):
return pathlib.Path(self.root.filename).joinpath(self.at)

def read_text(self, *args, **kwargs):
kwargs["encoding"] = io.text_encoding(kwargs.get("encoding"))
kwargs["encoding"] = text_encoding(kwargs.get("encoding"))
with self.open('r', *args, **kwargs) as strm:
return strm.read()

Expand Down

0 comments on commit 6ed5f3e

Please sign in to comment.