Skip to content

Commit

Permalink
- guard against cases where default_encoding is not yet set at import…
Browse files Browse the repository at this point in the history
… tim'e
  • Loading branch information
dataflake committed Apr 26, 2019
1 parent 671c687 commit d5fb1ac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/OFS/DTMLMethod.py
Expand Up @@ -69,7 +69,6 @@ class DTMLMethod(
"""
meta_type = 'DTML Method'
zmi_icon = 'far fa-file-alt'
encoding = default_encoding
_proxy_roles = ()
index_html = None # Prevent accidental acquisition
_cache_namespace_keys = ()
Expand Down Expand Up @@ -118,6 +117,7 @@ def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
o If supplied, use the REQUEST mapping, Response, and key word
arguments.
"""
self.encoding = default_encoding
if not self._cache_namespace_keys:
data = self.ZCacheable_get(default=_marker)
if data is not _marker:
Expand Down Expand Up @@ -181,8 +181,9 @@ def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
else:
if PY2 and not isinstance(r, text_type):
# Prevent double-encoding edge cases under Python 2
r = r.decode('utf-8')
c, e = guess_content_type(self.getId(), r.encode('utf-8'))
r = r.decode(self.encoding)
c, e = guess_content_type(self.getId(),
r.encode(self.encoding))
RESPONSE.setHeader('Content-Type', c)
result = decapitate(r, RESPONSE)
if not self._cache_namespace_keys:
Expand Down

0 comments on commit d5fb1ac

Please sign in to comment.