Skip to content

Commit

Permalink
make FSImage.__str__ available in Python 3
Browse files Browse the repository at this point in the history
In both Python 2 and 3, the tag() method returns the respective str type, so
the result can always be used for __str__. Without having this method
available in Python 3, the image tag cannot be included, for example, in
Chamaeleon page templates by simply accessing the image object, as that uses
i18n which in turn casts the object to the respective text (unicode) type. Not
implementing __str__ in Python 3 results in the object representation instead
of the tag in that case.
  • Loading branch information
tlotze committed May 17, 2018
1 parent 76314d0 commit 059b739
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/OFS/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,8 @@ def update_data(self, data, content_type=None, size=None):
def __bytes__(self):
return self.tag().encode('utf-8')

if PY2:
def __str__(self):
return self.tag()
def __str__(self):
return self.tag()

security.declareProtected(View, 'tag')
def tag(self, height=None, width=None, alt=None,
Expand Down

0 comments on commit 059b739

Please sign in to comment.