Commit 9d60e5d4 authored by Jason R. Coombs's avatar Jason R. Coombs

Forget the environment variable, and just log a warning when a metadata can't be decoded. Ref #719.

parent 21efdb56
# 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))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment