(
        string,
        use_aliases=False,
        delimiters=(_DEFAULT_DELIMITER, _DEFAULT_DELIMITER),
        language='en',
        version=None,
        handle_version=None
)
return "".join(result)
Replace unicode emoji in a string with emoji shortcodes. Useful for storage.
        >>> import emoji
        >>> print(emoji.emojize("Python is fun :thumbs_up:"))
        Python is fun 👍
        >>> print(emoji.demojize(u"Python is fun 👍"))
        Python is fun :thumbs_up:
        >>> print(emoji.demojize(u"Unicode is tricky 😯", delimiters=("__", "__")))
        Unicode is tricky __hushed_face__

    :param string: String contains unicode characters. MUST BE UNICODE.
    :param use_aliases: (optional) Return emoji aliases.  See ``emoji.UNICODE_EMOJI_ALIAS``.
    :param delimiters: (optional) User delimiters other than ``_DEFAULT_DELIMITER``
    :param language: Choose language of emoji name: language code 'es', 'de', etc. or 'alias'
        to use English aliases
    :param version: (optional) Max version. If set to an Emoji Version,
        all emoji above this version will be removed.
    :param handle_version: (optional) Replace the emoji above ``version``
        instead of removing it. handle_version can be either a string or a
        callable ``handle_version(emj: str, data: dict) -> str``; If it is
        a callable, it's passed the unicode emoji and the data dict from
        emoji.EMOJI_DATA and must return a replacement string  to be used.
        The passed data is in the form of::

            handle_version(u'\\U0001F6EB', {
                'en' : ':airplane_departure:',
                'status' : fully_qualified,
                'E' : 1,
                'alias' : [u':flight_departure:'],
                'de': u':abflug:',
                'es': u':avión_despegando:',
                ...
            })
Replace unicode emoji in a string with emoji shortcodes. Useful for storage.
        >>> import emoji
        >>> print(emoji.emojize("Python is fun :thumbs_up:"))
        Python is fun 👍
        >>> print(emoji.demojize(u"Python is fun 👍"))
        Python is fun :thumbs_up:
        >>> print(emoji.demojize(u"Unicode is tricky 😯", delimiters=("__", "__")))
        Unicode is tricky __hushed_face__
Replace unicode emoji in a string with emoji shortcodes . Useful for storage . >>> import emoji >>> print ( emoji . emojize ( Python is fun : thumbs_up : )) Python is fun 👍 >>> print ( emoji . demojize ( u Python is fun 👍 )) Python is fun : thumbs_up : >>> print ( emoji . demojize ( u Unicode is tricky 😯 delimiters = ( __ __ ))) Unicode is tricky __hushed_face__
def demojize(
        string,
        use_aliases=False,
        delimiters=(_DEFAULT_DELIMITER, _DEFAULT_DELIMITER),
        language='en',
        version=None,
        handle_version=None
):
    """Replace unicode emoji in a string with emoji shortcodes. Useful for storage.
        >>> import emoji
        >>> print(emoji.emojize("Python is fun :thumbs_up:"))
        Python is fun 👍
        >>> print(emoji.demojize(u"Python is fun 👍"))
        Python is fun :thumbs_up:
        >>> print(emoji.demojize(u"Unicode is tricky 😯", delimiters=("__", "__")))
        Unicode is tricky __hushed_face__

    :param string: String contains unicode characters. MUST BE UNICODE.
    :param use_aliases: (optional) Return emoji aliases.  See ``emoji.UNICODE_EMOJI_ALIAS``.
    :param delimiters: (optional) User delimiters other than ``_DEFAULT_DELIMITER``
    :param language: Choose language of emoji name: language code 'es', 'de', etc. or 'alias'
        to use English aliases
    :param version: (optional) Max version. If set to an Emoji Version,
        all emoji above this version will be removed.
    :param handle_version: (optional) Replace the emoji above ``version``
        instead of removing it. handle_version can be either a string or a
        callable ``handle_version(emj: str, data: dict) -> str``; If it is
        a callable, it's passed the unicode emoji and the data dict from
        emoji.EMOJI_DATA and must return a replacement string  to be used.
        The passed data is in the form of::

            handle_version(u'\\U0001F6EB', {
                'en' : ':airplane_departure:',
                'status' : fully_qualified,
                'E' : 1,
                'alias' : [u':flight_departure:'],
                'de': u':abflug:',
                'es': u':avión_despegando:',
                ...
            })

    """

    if language == 'alias':
        language = 'en'
        use_aliases = True
    elif use_aliases and language != 'en':
            warnings.warn("use_aliases=True is only supported for language='en'. "
                          "It is recommended to use demojize(string, language='alias') instead", stacklevel=2)
            language = 'en'

    tree = _get_search_tree()
    result = []
    i = 0
    length = len(string)
    while i < length:
        consumed = False
        char = string[i]
        if char in tree:
            j = i + 1
            sub_tree = tree[char]
            while j < length and string[j] in sub_tree:
                sub_tree = sub_tree[string[j]]
                j += 1
            if 'data' in sub_tree:
                emj_data = sub_tree['data']
                code_points = string[i:j]
                replace_str = None
                if version is not None and emj_data['E'] > version:
                    if callable(handle_version):
                        emj_data = emj_data.copy()
                        emj_data['match_start'] = i
                        emj_data['match_end'] = j
                        replace_str = handle_version(code_points, emj_data)
                    elif handle_version is not None:
                        replace_str = str(handle_version)
                    else:
                        replace_str = None
                elif language in emj_data:
                    if use_aliases and 'alias' in emj_data:
                        replace_str = delimiters[0] + emj_data['alias'][0][1:-1] + delimiters[1]
                    else:
                        replace_str = delimiters[0] + emj_data[language][1:-1] + delimiters[1]
                else:
                    # The emoji exists, but it is not translated, so we keep the emoji
                    replace_str = code_points

                i = j - 1
                consumed = True
                if replace_str:
                    result.append(replace_str)

        if not consumed and char != u'\ufe0e' and char != u'\ufe0f':
            result.append(char)
        i += 1

    return "".join(result)
def demojize ( string , use_aliases = False , delimiters = ( _DEFAULT_DELIMITER , _DEFAULT_DELIMITER ) , language = 'en' , version = None , handle_version = None ) : if language == 'alias' : language = 'en' use_aliases = True elif use_aliases and language != 'en' : warnings . warn ( "use_aliases=True is only supported for language='en'. " "It is recommended to use demojize(string, language='alias') instead" , stacklevel = 2 ) language = 'en' tree = _get_search_tree ( ) result = [ ] i = 0 length = len ( string ) while i < length : consumed = False char = string [ i ] if char in tree : j = i + 1 sub_tree = tree [ char ] while j < length and string [ j ] in sub_tree : sub_tree = sub_tree [ string [ j ] ] j += 1 if 'data' in sub_tree : emj_data = sub_tree [ 'data' ] code_points = string [ i : j ] replace_str = None if version is not None and emj_data [ 'E' ] > version : if callable ( handle_version ) : emj_data = emj_data . copy ( ) emj_data [ 'match_start' ] = i emj_data [ 'match_end' ] = j replace_str = handle_version ( code_points , emj_data ) elif handle_version is not None : replace_str = str ( handle_version ) else : replace_str = None elif language in emj_data : if use_aliases and 'alias' in emj_data : replace_str = delimiters [ 0 ] + emj_data [ 'alias' ] [ 0 ] [ 1 : - 1 ] + delimiters [ 1 ] else : replace_str = delimiters [ 0 ] + emj_data [ language ] [ 1 : - 1 ] + delimiters [ 1 ] else : # The emoji exists, but it is not translated, so we keep the emoji replace_str = code_points i = j - 1 consumed = True if replace_str : result . append ( replace_str ) if not consumed and char != u'\ufe0e' and char != u'\ufe0f' : result . append ( char ) i += 1 return "" . join ( result )