Skip to content

Commit

Permalink
Merge pull request #306 from cvzi/json_unicodeerror
Browse files Browse the repository at this point in the history
Fix UnicodeDecodeError v2.13.1
  • Loading branch information
TahirJalilov authored Sep 21, 2024
2 parents d34e4bf + 9f6cc98 commit f154602
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
emoji
=====

v2.13.1 (2024-09-21)
-----
* Read JSON files in binary mode to avoid UnicodeDecodeError #305

v2.13.0 (2024-09-19)
-----
* Use JSON files to store the database of emoji
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ include README.rst
include CHANGES.md
include utils/testutils.py
recursive-include tests *.py
include emoji/unicode_codes/emoji.json
recursive-include emoji/unicode_codes emoji_*.json
2 changes: 1 addition & 1 deletion emoji/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'LANGUAGES',
]

__version__ = '2.13.0'
__version__ = '2.13.1'
__author__ = 'Taehoon Kim, Kevin Wurster'
__email__ = 'carpedm20@gmail.com'
# and wursterk@gmail.com, tahir.jalilov@gmail.com
Expand Down
6 changes: 4 additions & 2 deletions emoji/unicode_codes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def __missing__(self, key: str) -> str:
def _load_default_from_json():
global EMOJI_DATA
global _loaded_keys
with open(Path(__file__).with_name('emoji.json')) as f:

file = Path(__file__).with_name('emoji.json')
with open(file, 'rb') as f:
EMOJI_DATA = dict(json.load(f, object_pairs_hook=EmojiDataDict)) # type: ignore
_loaded_keys = list(_DEFAULT_KEYS)

Expand All @@ -93,7 +95,7 @@ def load_from_json(key: str):
raise NotImplementedError('Language not supported', key)

file = Path(__file__).with_name(f'emoji_{key}.json')
with open(file) as f:
with open(file, 'rb') as f:
for emj, value in json.load(f).items():
EMOJI_DATA[emj][key] = value # type: ignore

Expand Down

0 comments on commit f154602

Please sign in to comment.