aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-08-05 10:30:46 -0400
committerJason R. Coombs <jaraco@jaraco.com>2016-08-05 10:30:46 -0400
commit9d60e5d491298f36a5de33c60c462d1a900844e8 (patch)
treec1dcda384d68110819fc6a9b17f5dfb372fdeb76 /pkg_resources
parent21efdb5615f98a60cfa0b6130a1c2d93e5faa28e (diff)
downloadexternal_python_setuptools-9d60e5d491298f36a5de33c60c462d1a900844e8.tar.gz
external_python_setuptools-9d60e5d491298f36a5de33c60c462d1a900844e8.tar.bz2
external_python_setuptools-9d60e5d491298f36a5de33c60c462d1a900844e8.zip
Forget the environment variable, and just log a warning when a metadata can't be decoded. Ref #719.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index b402ddd6..7dbd13a6 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -1,3 +1,5 @@
+# coding: utf-8
+
"""
Package resource API
--------------------
@@ -1859,19 +1861,19 @@ class FileMetadata(EmptyProvider):
def get_metadata(self, name):
if name=='PKG-INFO':
- env_key = 'PKG_RESOURCES_METADATA_ERRORS'
- errors = os.environ.get(env_key, 'strict')
- with io.open(self.path, encoding='utf-8', errors=errors) as f:
- try:
- metadata = f.read()
- except UnicodeDecodeError as exc:
- # add path context to error message
- tmpl = " in {self.path}"
- exc.reason += tmpl.format(self=self)
- raise
+ with io.open(self.path, encoding='utf-8', errors="replace") as f:
+ metadata = f.read()
+ self._warn_on_replacement(metadata)
return metadata
raise KeyError("No metadata except PKG-INFO is available")
+ def _warn_on_replacement(self, metadata):
+ replacement_char = '�'
+ if replacement_char in metadata:
+ tmpl = "{self.path} could not be properly decoded in UTF-8"
+ msg = tmpl.format(**locals())
+ warnings.warn(msg)
+
def get_metadata_lines(self, name):
return yield_lines(self.get_metadata(name))