Spaces:
Sleeping
Sleeping
Download venv/lib/python3.14/site-packages/rich/_emoji_replace.py from HSR-DeepThink/Perhance: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/HSR-DeepThink/Perhance/resolve/main/venv/lib/python3.14/site-packages/rich/_emoji_replace.py
- Command line
-
hf download hf://spaces/HSR-DeepThink/Perhance/venv/lib/python3.14/site-packages/rich/_emoji_replace.py
-
curl -L -o _emoji_replace.py https://huggingface.co/spaces/HSR-DeepThink/Perhance/resolve/main/venv/lib/python3.14/site-packages/rich/_emoji_replace.py
1.07 kB
| import re | |
| from typing import Callable, Match, Optional | |
| _ReStringMatch = Match[str] # regex match object | |
| _ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub | |
| _EmojiSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re | |
| def _emoji_replace( | |
| text: str, | |
| default_variant: Optional[str] = None, | |
| _emoji_sub: _EmojiSubMethod = re.compile(r"(:(\S*?)(?:(?:\-)(emoji|text))?:)").sub, | |
| ) -> str: | |
| """Replace emoji code in text.""" | |
| from ._emoji_codes import EMOJI | |
| get_emoji = EMOJI.__getitem__ | |
| variants = {"text": "\ufe0e", "emoji": "\ufe0f"} | |
| get_variant = variants.get | |
| default_variant_code = variants.get(default_variant, "") if default_variant else "" | |
| def do_replace(match: Match[str]) -> str: | |
| emoji_code, emoji_name, variant = match.groups() | |
| try: | |
| return get_emoji(emoji_name.lower()) + get_variant( | |
| variant, default_variant_code | |
| ) | |
| except KeyError: | |
| return emoji_code | |
| return _emoji_sub(do_replace, text) | |