Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_wechat_reply():
message = parse_user_msg(
"""
1348831860
1234567890123456
"""
)
s = to_binary("喵fdsjaklfsk")
reply = WeChatReply(message=message, s=s)
assert reply._args['source'] == 'toUser'
assert reply._args['target'] == 'fromUser'
assert reply._args['s'] == to_text(s)
assert isinstance(reply._args['time'], int)
TEMPLATE = to_text(
"""
{time}
"""
)
class VideoReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
<video>
<title><![CDATA[{title}]]></title>
</video>
"""
)
TEMPLATE = to_text(
"""
{time}
<img>
"""
)
class VoiceReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
"""
)
class VideoReply(WeChatReply):
"""
)
else:
return to_text(
"""
{time}
"""
)
class SuccessReply(WeChatReply):
def render(self):
return "success"
def process_function_reply(reply, message=None):
if is_string(reply):
return TextReply(message=message, content=reply)
elif isinstance(reply, list) and all([len(x) == 4 for x in reply]):
if len(reply) > 10:
raise AttributeError(
"Can't add more than 10 articles"
" in an ArticlesReply"
)
r = ArticlesReply(message=message)
for article in reply:
article = Article(*article)
)
else:
self._articles.append(article)
def render(self):
items = []
for article in self._articles:
items.append(article.render())
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)
class MusicReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
<title><![CDATA[{title}]]></title>
"""
)
class TextReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
<content></content>
"""
)
class ImageReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
<img>
"""
)
class VoiceReply(WeChatReply):
<title><![CDATA[{title}]]></title>
"""
)
def process_args(self, args):
if 'hq_url' not in args:
args['hq_url'] = args['url']
class TransferCustomerServiceReply(WeChatReply):
@property
def TEMPLATE(self):
if 'account' in self._args:
return to_text(
"""
{time}
"""
)
typename="Article",
field_names=("title", "description", "img", "url"),
tempalte=to_text(
"""
<title><![CDATA[{title}]]></title>
"""
)
)
class ArticlesReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
<content></content>
{count}
{items}
"""
)
def __init__(self, message=None, **kwargs):
super(ArticlesReply, self).__init__(message, **kwargs)
for k, v in kwargs.items():
if is_string(v):
v = to_text(v)
args[k] = v
self.process_args(args)
self._args = args
def render(self):
return to_text(self.TEMPLATE.format(**self._args))
def __getattr__(self, item):
if item in self._args:
return self._args[item]
class TextReply(WeChatReply):
TEMPLATE = to_text(
"""
{time}
<content></content>
"""
)
class ImageReply(WeChatReply):
TEMPLATE = to_text(
"""