def media_comments(self, media_id): comments = memcache.get("media_comments_%s" % (media_id)) if not comments: converter = emoji.factory("softbank", "utf-8") converter.prefix = '<span class="emoji emoji_' converter.suffix = '"></span>' comments = self.api.media_comments(media_id) for comment in comments: comment["text"] = escape(comment["text"].encode("utf-8")) comment["text"] = self._convert_emoji(comment["text"]) comment["text"] = self._convert_tag_to_link(comment["text"]) memcache.add("media_comments_%s" % (media_id), comments, 300) return comments
def test_factory(self): dcm = emoji.factory('docomo', 'sjis') assert dcm ez = emoji.factory('ezweb', 'sjis') assert ez soft = emoji.factory('softbank', 'sjis') assert soft pc = emoji.factory('pc', 'sjis') assert pc assert dcm != ez assert dcm != soft assert ez != soft assert dcm == emoji.factory('docomo', 'sjis') assert ez == emoji.factory('ezweb', 'sjis') assert soft == emoji.factory('softbank', 'sjis')
def test_restore_ezweb_utf8(self): obj = emoji.factory('ezweb', 'utf-8') ret = obj.restore('hello [e1] world') assert 'hello \xEE\xBD\x99 world' == ret, ret
def test_restore_docomo_utf8(self): obj = emoji.factory('docomo', 'utf-8') ret = obj.restore('hello [d1] world') assert 'hello \xEE\x98\xBE world' == ret, ret
def test_restore_softbank_sjis(self): obj = emoji.factory('softbank', 'sjis') ret = obj.restore('hello [s1] world') assert 'hello \xF9\x41 world' == ret, ret
def test_restore_ezweb_sjis(self): obj = emoji.factory('ezweb', 'sjis') ret = obj.restore('hello [e1] world') assert 'hello \xF6\x59 world' == ret, ret
def test_restore_docomo_sjis(self): obj = emoji.factory('docomo', 'sjis') ret = obj.restore('hello [d1] world') assert 'hello \xF8\x9F world' == ret, ret
def test_convert_ezweb_jis(self): obj = emoji.factory('ezweb', 'jis-email') ret = obj.convert('hello \x1B\x24\x42\x75\x3A\x1B\x28\x42 world') ret = ret.decode('iso2022-jp') assert 'hello [e1] world' == ret, ret
def _convert_emoji(self, text): converter = emoji.factory("softbank", "utf-8") converter.prefix = '<span class="emoji emoji_' converter.suffix = '"></span>' text = converter.convert(text) return text
def test_restore_ezweb_jis(self): obj = emoji.factory('ezweb', 'jis-email') ret = obj.restore('hello [e1] world') assert 'hello \x1B\x24\x42\x75\x3A\x1B\x28\x42 world' == ret, ret
def test_restore_softbank_utf8(self): obj = emoji.factory('softbank', 'utf-8') ret = obj.restore('hello [s1] world') assert 'hello \xEE\x80\x81 world' == ret, ret