Skip to content

Commit

Permalink
Use binary mode when opening JSON files
Browse files Browse the repository at this point in the history
to avoid UnicodeDecodeError: 'ascii' codec can't decode byte...
  • Loading branch information
cvzi committed Sep 20, 2024
1 parent d34e4bf commit 0ff7724
Showing 1 changed file with 4 additions and 2 deletions.
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 0ff7724

Please sign in to comment.