mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 12:25:45 +01:00
Decode Emoji byte strings into unicode strings if using Python 3
This commit is contained in:
parent
688d6af541
commit
fea0c5cc2b
1 changed files with 32 additions and 0 deletions
|
@ -20,10 +20,42 @@
|
|||
|
||||
"""This module contains a object that represents an Emoji"""
|
||||
|
||||
import sys
|
||||
|
||||
def call_decode_byte_strings(cls):
|
||||
"""
|
||||
Calls the _decode_byte_strings function of the created class
|
||||
|
||||
Args:
|
||||
cls (Class):
|
||||
|
||||
Returns:
|
||||
Class:
|
||||
"""
|
||||
|
||||
cls._decode_byte_strings()
|
||||
return cls
|
||||
|
||||
class Emoji(object):
|
||||
"""This object represents an Emoji."""
|
||||
|
||||
@classmethod
|
||||
def _decode_byte_strings(cls):
|
||||
"""
|
||||
Decodes the Emojis into unicode strings if using Python 3
|
||||
|
||||
Args:
|
||||
cls (Class):
|
||||
|
||||
Returns:
|
||||
"""
|
||||
|
||||
if sys.version_info.major is 3:
|
||||
emojis = filter(lambda attr : type(getattr(cls, attr)) is bytes,
|
||||
dir(cls))
|
||||
for var in emojis:
|
||||
setattr(cls, var, getattr(cls, var).decode('utf-8'))
|
||||
|
||||
GRINNING_FACE_WITH_SMILING_EYES = b'\xF0\x9F\x98\x81'
|
||||
FACE_WITH_TEARS_OF_JOY = b'\xF0\x9F\x98\x82'
|
||||
SMILING_FACE_WITH_OPEN_MOUTH = b'\xF0\x9F\x98\x83'
|
||||
|
|
Loading…
Add table
Reference in a new issue