Exemple #1
0
    def log_request(self, code='-', size='-'):
        requestline = self.requestline
        method, url, httpv = requestline.split(" ")
        url = smart_str(unquote(url))

        if code == 200:
            statusColor = self.GREEN
        elif str(code)[0] in ['4', '5']:
            statusColor = self.RED
        else:
            statusColor = self.LITTLEGRAY

        if method == 'GET':
            methodColor = self.BLUE
        elif method in ['POST', 'PUT']:
            methodColor = self.LIGHTGREEN
        else:
            methodColor = self.RED

        if re.search(hidePattern, url):
            return

        duration = int((self.Processed - self.Started) * 1000)

        message = '{methodColor}{method}{colorEnd} {urlColor}{url}{colorEnd} {httpv} {statusColor}{status}{colorEnd} {size} {durationColor}[{duration}ms]{colorEnd}'.format(
            url=url,
            size=size,
            status=code,
            httpv=httpv,
            method=method,
            duration=duration,
            urlColor=self.HEADER,
            statusColor=statusColor,
            methodColor=methodColor,
            durationColor=self.CYAN,
            colorEnd=self.ENDC)
        message = smart_str(unquote(message))
        self.log('info', message)
Exemple #2
0
 def url_encode(self, s):
     if not s:
         return ''
     return urllib.quote(smart_str(s), safe="/")
Exemple #3
0
 def _encryp_xml(self, crypt, to_xml, nonce):
     to_xml = smart_str(to_xml)
     ret, encrypt_xml = crypt.EncryptMsg(to_xml, nonce)
     return encrypt_xml
Exemple #4
0
 def _get_xml(self, data):
     post_str = smart_str(data)
     # 验证xml 格式是否正确
     validate_xml(StringIO(post_str))
     return post_str
Exemple #5
0
from weixin import WeixinMpAPI
from weixin.reply import TextReply, ImageReply
from weixin.response import WXResponse as _WXResponse
from weixin.lib.WXBizMsgCrypt import WXBizMsgCrypt

from momo.settings import Config
from momo.media import media_fetch_to_qiniu, upload_file_to_qcos
from momo.helper import (validate_xml, smart_str, get_momo_answer,
                         set_momo_answer, get_weixinmp_token,
                         get_weixinmp_media_id)
from momo.models.wx_response import KWResponse as KWR

blueprint = Blueprint('weixin', url_prefix='/weixin')

appid = smart_str(Config.WEIXINMP_APPID)
secret = smart_str(Config.WEIXINMP_APP_SECRET)
token = smart_str(Config.WEIXINMP_TOKEN)
encoding_aeskey = smart_str(Config.WEIXINMP_ENCODINGAESKEY)

PM25_BASE_URL = 'http://api.waqi.info'
PM25_TOKEN = Config.PM25_TOKEN

AUTO_REPLY_CONTENT = """
Hi,朋友!

这是我妈四月的公号,我是魔魔,我可以陪你聊天呦!

你可以输入"pm25 城市名" 查询实时 pm 指数!

也可以试试"菜单"、"note"、"并发"、"协程"、"设计模式" 等关键字吼!