How to use the werobot.utils.to_text function in WeRoBot

To help you get started, we’ve selected a few WeRoBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github offu / WeRoBot / tests / test_utils.py View on Github external
def test_to_text():
    assert to_text(6) == six.text_type(6)
    assert to_text(b"aa") == "aa"
    assert to_text("cc") == "cc"
    if six.PY2:
        assert to_text(u"喵") == u"喵"
        assert to_text("喵") == u"喵"
github offu / WeRoBot / tests / test_utils.py View on Github external
def test_to_text():
    assert to_text(6) == six.text_type(6)
    assert to_text(b"aa") == "aa"
    assert to_text("cc") == "cc"
    if six.PY2:
        assert to_text(u"喵") == u"喵"
        assert to_text("喵") == u"喵"
github offu / WeRoBot / werobot / replies.py View on Github external
class TextReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <content></content>
    
    """
    )


class ImageReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <img>
    
    
    
    """
    )


class VoiceReply(WeChatReply):
    TEMPLATE = to_text(
github offu / WeRoBot / werobot / replies.py View on Github external
if 'account' in self._args:
            return to_text(
                """
            
            
            
            {time}
            
            
                 
             
            
            """
            )
        else:
            return to_text(
                """
github JoneXiong / oejia_wx / ext_libs / werobot / reply.py View on Github external
class ArticlesReply(WeChatReply):
    TEMPLATE = to_text("""
    
    
    
    {time}
    
    <content></content>
    {count}
    {items}
    {flag}
    
    """)

    ITEM_TEMPLATE = to_text("""
    
    <title>&lt;![CDATA[{title}]]&gt;</title>
    
    
    
    
    """)

    def __init__(self, message=None, star=False, **kwargs):
        super(ArticlesReply, self).__init__(message, star, **kwargs)
        self._articles = []

    def add_article(self, article):
        if len(self._articles) &gt;= 10:
            raise AttributeError("Can't add more than 10 articles"
                                 " in an ArticlesReply")
github JoneXiong / oejia_wx / ext_libs / werobot / reply.py View on Github external
kwargs["flag"] = 0

        args = dict()
        for k, v in kwargs.items():
            if is_string(v):
                v = to_text(v)
            args[k] = v

        self._args = args

    def render(self):
        raise NotImplementedError()


class TextReply(WeChatReply):
    TEMPLATE = to_text("""
    
    
    
    {time}
    
    <content></content>
    {flag}
    
    """)

    def render(self):
        return TextReply.TEMPLATE.format(**self._args)


class ArticlesReply(WeChatReply):
    TEMPLATE = to_text("""
github offu / WeRoBot / werobot / crypto / __init__.py View on Github external
:param app_id: 微信公众平台的 AppID
        :return: 解密后的字符串
        """
        text = to_binary(text)
        decryptor = self.cipher.decryptor()
        plain_text = decryptor.update(base64.b64decode(text)
                                      ) + decryptor.finalize()

        padding = byte2int(plain_text, -1)
        content = plain_text[16:-padding]

        xml_len = socket.ntohl(struct.unpack("I", content[:4])[0])
        xml_content = content[4:xml_len + 4]
        from_appid = content[xml_len + 4:]

        if to_text(from_appid) != app_id:
            raise AppIdValidationError(text, app_id)

        return xml_content
github offu / WeRoBot / werobot / replies.py View on Github external
def process_args(self, kwargs):
            args = defaultdict(str)
            for k, v in kwargs.items():
                if is_string(v):
                    v = to_text(v)
                args[k] = v
            return args
github JoneXiong / oejia_wx / ext_libs / werobot / reply.py View on Github external
def render(self):
        items = []
        for article in self._articles:
            items.append(ArticlesReply.ITEM_TEMPLATE.format(
                title=to_text(article.title),
                description=to_text(article.description),
                img=to_text(article.img),
                url=to_text(article.url)
            ))
        self._args["items"] = ''.join(items)
        self._args["count"] = len(items)
        if "content" not in self._args:
            self._args["content"] = ''
        return ArticlesReply.TEMPLATE.format(**self._args)