Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 5648:a4514df51ded
Python3: fix crash bug when importing binary file (like jpeg). The
hyperdb content property inteprets the file as text and raises an
error if the UTF-8 decode fails. To fix, read file as binary/byte and
do conversion (ignoring errors) at the import level not the hyperdb
level.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 15 Mar 2019 17:27:31 -0400 |
| parents | fea11d05110e |
| children | 5a9159ad773f |
comparison
equal
deleted
inserted
replaced
| 5647:095db27e8064 | 5648:a4514df51ded |
|---|---|
| 1680 if 'type' in props: | 1680 if 'type' in props: |
| 1681 mime_type = self.get(nodeid, 'type') | 1681 mime_type = self.get(nodeid, 'type') |
| 1682 if not mime_type: | 1682 if not mime_type: |
| 1683 mime_type = self.default_mime_type | 1683 mime_type = self.default_mime_type |
| 1684 if props['content'].indexme: | 1684 if props['content'].indexme: |
| 1685 index_content = self.get(nodeid, 'binary_content') | |
| 1686 if bytes != str and isinstance(index_content, bytes): | |
| 1687 index_content = index_content.decode('utf-8', errors='ignore') | |
| 1688 # indexer will only index text mime type. It will skip | |
| 1689 # other types. So if mime type of file is correct, we | |
| 1690 # call add_text on content. | |
| 1685 self.db.indexer.add_text((self.classname, nodeid, 'content'), | 1691 self.db.indexer.add_text((self.classname, nodeid, 'content'), |
| 1686 self.get(nodeid, 'content'), mime_type) | 1692 index_content, mime_type) |
| 1687 | 1693 |
| 1688 class Node: | 1694 class Node: |
| 1689 """ A convenience wrapper for the given node | 1695 """ A convenience wrapper for the given node |
| 1690 """ | 1696 """ |
| 1691 def __init__(self, cl, nodeid, cache=1): | 1697 def __init__(self, cl, nodeid, cache=1): |
