Decode Emoji byte strings into unicode strings if using Python 3

This commit is contained in:
Jannes Höke 2015-10-23 00:29:26 +02:00
parent 688d6af541
commit fea0c5cc2b

View file

@ -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'