当前位置: 首页>>代码示例>>Python>>正文


Python utils.safestr函数代码示例

本文整理汇总了Python中toughlib.utils.safestr函数的典型用法代码示例。如果您正苦于以下问题:Python safestr函数的具体用法?Python safestr怎么用?Python safestr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了safestr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: event_toughcloud_mail_account_open

    def event_toughcloud_mail_account_open(self, userinfo):
        """ toughCloud mail api open notify without password event """
        if not userinfo:
            return

        if not userinfo.get('email'):
            logger.error('user email is None exit')
            return

        try:
            api_secret = self.get_param_value("toughcloud_license")
            service_mail = self.get_param_value("toughcloud_service_mail")
            if not service_mail:
                return
            api_token = yield tools.get_sys_token()
            params = dict(
                token=api_token.strip(),
                action='email',
                mailto=userinfo.get('email'),
                tplname=self.MAIL_TPLNAME,
                customer=utils.safestr(userinfo.get('realname')),
                username=userinfo.get('account_number'),
                product=utils.safestr(userinfo.get('product_name')),
                expire=userinfo.get('expire_date'),
                service_call=self.get_param_value("toughcloud_service_call", ''),
                service_mail=service_mail,
                nonce=str(int(time.time()))
            )
            params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
            resp = yield httpclient.fetch(self.MAIL_APIURL, postdata=urlencode(params))
            logger.info(resp.body)
            logger.info('open account send email without password success')
        except Exception as err:
            logger.exception(err)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:34,代码来源:account_open_notify.py

示例2: event_toughcloud_sms_account_open

    def event_toughcloud_sms_account_open(self, userinfo):
        """ toughCloud sms api open notify event """
        if not userinfo:
            return

        if not userinfo.get('phone'):
            logger.error('user phone is None exit')
            return

        api_secret = self.get_param_value("toughcloud_license")
        api_token = yield tools.get_sys_token()
        params = dict(
            token=api_token.strip(),
            action='sms',
            tplname=self.SMS_TPLNAME,
            phone=userinfo.get('phone'),
            customer=utils.safestr(userinfo.get('realname')),
            username=userinfo.get('account_number'),
            product=utils.safestr(userinfo.get('product_name')),
            password=userinfo.get('password'),
            expire=userinfo.get('expire_date'),
            nonce=str(int(time.time()))
        )
        params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
        try:
            resp = yield httpclient.fetch(self.SMS_APIURL, postdata=urlencode(params))
            logger.info(resp.body)
            logger.info('open account send short message success')
        except Exception as err:
            logger.exception(err)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:30,代码来源:account_open_notify.py

示例3: post

    def post(self):

        # if FeedbackHandler.last_send == 0:
        #     FeedbackHandler.last_send = time.time()
        # elif (time.time() - FeedbackHandler.last_send) < 10:
        #     rsec = int(10 - (time.time() - FeedbackHandler.last_send))
        #     return self.render_json(code=0,msg=u"发送间隔为10秒,请再等待 %s 秒"% rsec)

        topic = self.get_argument("topic","")
        email = self.get_argument("email","")
        
        if not topic or len(topic.strip()) == 0:
            self.render_json(code=0,msg=u"描述不能为空")
            return
        if len(topic.strip()) > 90:
            self.render_json(code=0,msg=u"描述不能大于90个字符")
            return

        service_url = '%s/service/feedback'%self.settings.config.system.service_url
        param_data = dict(
            topic=utils.safestr(topic),
            email=email,
            uuid=get_uuid(),
            license=self.settings.config.system.license,
            content=utils.safestr(self.warp_content())
        )

        resp = yield httpclient.post(service_url.encode('utf-8'), data=param_data)
        content = yield resp.content()
        self.write(content)
开发者ID:Kge38131,项目名称:ToughRADIUS,代码行数:30,代码来源:logger.py

示例4: event_toughcloud_mail_account_expire

    def event_toughcloud_mail_account_expire(self, userinfo):
        """ toughcloud mail api notify event """
        if not userinfo:
            return

        api_secret = self.get_param_value("toughcloud_license")
        service_mail=self.get_param_value("toughcloud_service_mail")
        if not service_mail:
            return
        api_token = yield tools.get_sys_token()
        params = dict(
            token=api_token.strip(),
            mailto=userinfo.email,
            tplname=self.MAIL_TPLNAME,
            customer=utils.safestr(userinfo.realname),
            username=userinfo.account_number,
            product=utils.safestr(userinfo.product_name),
            expire=userinfo.expire_date,
            service_call=self.get_param_value("toughcloud_service_call",''),
            service_mail=service_mail,
            nonce = str(int(time.time()))
        )
        params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
        try:
            resp = yield httpclient.fetch(self.MAIL_APIURL, postdata=urlencode(params))
            logger.info(resp.body)
        except Exception as err:
            logger.exception(err)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:28,代码来源:account_expire_notify.py

示例5: disconnect

    def disconnect(self):
        try:
            is_chap=self.settings.config.portal.chap in (1, "1", "chap")
            userIp = self.current_user.ipaddr

            nas = self.get_nas(self.current_user.nasaddr)
            ac_addr = nas['ip_addr']
            ac_port = int(nas['ac_port'])
            secret = utils.safestr(nas['bas_secret'])
            _vendor= utils.safestr(nas['portal_vendor'])
            if _vendor not in ('cmccv1','cmccv2','huaweiv1','huaweiv2'):
                defer.returnValue("not support vendor %s"%_vendor)

            send_portal = functools.partial(
                client.send,
                secret,
                log=self.syslog,
                debug=self.settings.debug,
                vendor=_vendor
            )
            vendor = client.PortalClient.vendors.get(_vendor)
            logout_req = vendor.proto.newReqLogout(userIp, secret,chap=is_chap)
            logout_resp = yield send_portal(data=logout_req, host=ac_addr, port=ac_port)

            if logout_resp.errCode > 0:
                _err_msg=u"{0},{1}".format(
                    vendor.mod.AckLogoutErrs[logout_resp.errCode], 
                    utils.safeunicode(logout_resp.get_text_info()[0] or "")
                )
                logger.error( _err_msg)

            defer.returnValue("disconnect done!")
        except Exception as err:
            defer.returnValue(err)
开发者ID:gvsurenderreddy,项目名称:toughwlan,代码行数:34,代码来源:logout.py

示例6: add_mail_alert

 def add_mail_alert(self,mailto,content):
     db = self.mdb['nagios_alerts']
     coll = db['alerts']
     data = dict(
         alert_type = 'mail',
         target = utils.safestr(mailto),
         content = utils.safestr(content),
         sendtime = time.time()   
     ) 
     coll.insert(data)
开发者ID:lxyjyy,项目名称:ToughNMS,代码行数:10,代码来源:mongodb.py

示例7: process

    def process(self, msgid, message):
        self.syslog.info("accept auth message @ %s : %r" % (self.listen, utils.safeunicode(message)))
        @self.cache.cache(expire=600)   
        def get_account_by_username(username):
            return self.db.query(models.TrAccount).filter_by(account_number=username).first()

        @self.cache.cache(expire=600)   
        def get_product_by_id(product_id):
            return self.db.query(models.TrProduct).filter_by(id=product_id).first()

        try:
            req_msg = apiutils.parse_request(self.secret, message)
            if req_msg.get("action") == 'ping':
                return self.agent.reply(msgid, apiutils.make_message(self.secret,code=0))
            if 'username' not in req_msg:
                raise ValueError('username is empty')
        except Exception as err:
            resp = apiutils.make_message(self.secret, code=1, msg=utils.safestr(err.message))
            self.agent.reply(msgid, resp)
            return
            
        try:
            username = req_msg['username']
            account = get_account_by_username(username)
            if not account:
                apiutils.make_message(self.secret, code=1, msg=u'user  {0} not exists'.format(utils.safeunicode(username)))
                self.agent.reply(msgid, resp)
                return
                
            passwd = self.app.aes.decrypt(account.password)
            product = get_product_by_id(account.product_id)

            result = dict(
                code=0,
                msg='success',
                username=username,
                passwd=passwd,
                input_rate=product.input_max_limit,
                output_rate=product.output_max_limit,
                attrs={
                    "Session-Timeout"      : 86400,
                    "Acct-Interim-Interval": 300
                }
            )

            resp = apiutils.make_message(self.secret, **result)
            self.agent.reply(msgid, resp)
            self.syslog.info("send auth response %r" % (utils.safeunicode(resp)))
        except Exception as err:
            self.syslog.error(u"api authorize error %s" % utils.safeunicode(err.message))
            resp = apiutils.make_message(self.secret, code=1, msg=utils.safestr(err.message))
            return self.agent.reply(msgid, resp)
开发者ID:davislidaqing,项目名称:ToughRADIUS,代码行数:52,代码来源:authorize.py

示例8: make_sign

 def make_sign(self, secret, params=[]):
     """ make sign
     :param params: params list
     :return: :rtype:
     """
     _params = [utils.safestr(p) for p in params if p is not None]
     _params.sort()
     _params.insert(0, secret)
     strs = ''.join(_params)
     # if self.settings.debug:
     #     log.msg("sign_src = %s" % strs, level=logging.DEBUG)
     mds = md5(utils.safestr(strs)).hexdigest()
     return mds.upper()
开发者ID:lxyjyy,项目名称:ToughNMS,代码行数:13,代码来源:base.py

示例9: event_webhook_account_expire

 def event_webhook_account_expire(self, userinfo):
     """webhook notify event """
     notify_url = self.get_param_value("expire_notify_url")
     if not notify_url:
         return
     url = notify_url.replace('{account}',userinfo.account_number)
     url = url.replace('{customer}',utils.safestr(userinfo.realname))
     url = url.replace('{expire}',userinfo.expire_date)
     url = url.replace('{email}',userinfo.email)
     url = url.replace('{mobile}',userinfo.mobile)
     url = url.replace('{product}',utils.safestr(userinfo.product_name))
     url = url.encode('utf-8')
     url = quote(url,":?=/&")
     return httpclient.fetch(url).addCallbacks(lambda r: logger.info(r.body),logger.exception)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:14,代码来源:account_expire_notify.py

示例10: render_json

 def render_json(self, **template_vars):
     if not template_vars.has_key("code"):
         template_vars["code"] = 0
     resp = json.dumps(template_vars, ensure_ascii=False)
     if self.settings.debug:
         logger.debug("[api debug] :: %s response body: %s" % (self.request.path, utils.safestr(resp)))
     self.write(resp)
开发者ID:talkincode,项目名称:toughtester,代码行数:7,代码来源:base.py

示例11: get

    def get(self, *args, **kwargs):
        logger.info(utils.safeunicode(self.request.query))
        wlan_params = {
            "wlanuserip": self.get_argument("userip", self.request.remote_ip),
            "ispcode": self.get_argument("ispcode", "default"),
            "wlanusername": self.get_argument("username","test"),
            "wlanacip": self.settings.config.acagent.nasaddr,
            "ssid": self.get_argument("ssid","default"),
            "wlanusermac": self.get_argument("wlanusermac","00-00-00-00-00"),
            "wlanapmac": self.get_argument("wlanapmac","00-00-00-00-00"),
            "wlanuserfirsturl": self.get_argument("wlanuserfirsturl","/portal/index"),
            "callback": self.get_argument("callback",""),
            "vendortype" : self.get_argument("vendortype",""),
        }
        logger.info(utils.safeunicode(wlan_params))
        if wlan_params['vendortype'] == 'routeros':
            logger.info("Forward to RouterOS Portal Login")
            self.forward_ros(wlan_params)
            return

        elif wlan_params['vendortype'] == 'ikuai':
            logger.info("Forward to RouterOS ikuai Login")
            self.forward_ikuai(wlan_params)
            return

        logger.info("callback_cache_%s" % utils.safeunicode(wlan_params['wlanuserip']))
        self.application.mcache.set(
            "callback_cache_%s" % utils.safestr(wlan_params['wlanuserip']),wlan_params['callback'],300)

        url = self.settings.config.acagent.portal_login.format(**wlan_params)
        logger.info("portal forward to : %s" % url)
        self.redirect(url, permanent=False)
开发者ID:sdgdsffdsfff,项目名称:toughwlan,代码行数:32,代码来源:forward.py

示例12: post

    def post(self):
        try:
            req_msg = self.parse_request()
        except Exception as err:
            self.render_json(code=1, msg=safestr(err.message))
            return

        session_id = req_msg.get("session_id")
        if not session_id:
            self.render_json(code=1, msg="session_id is empty")

        session = self.db.query(models.TrwOnline).filter_by(session_id=session_id)

        result = dict(
            username=session.username,
            nas_addr=session.nas_addr,
            session_id=session_id,
            start_time=session.start_time,
            ipaddr=session.ipaddr,
            macaddr=session.macaddr,
            input_total=session.input_total,
            output_total=session.output_total,
        )

        self.render_json(code=0, msg="success", data=result)
开发者ID:talkincode,项目名称:toughwlan,代码行数:25,代码来源:api_online.py

示例13: get_error_html

 def get_error_html(self, status_code=500, **kwargs):
     self.syslog.error("http error : [status_code:{0}], {1}".format(status_code, utils.safestr(kwargs)))
     if status_code == 404:
         return self.render_string("error.html", msg=u"404:页面不存在")
     elif status_code == 403:
         return self.render_string("error.html", msg=u"403:非法的请求")
     elif status_code == 500:
         return self.render_string("error.html", msg=u"500:服务器处理失败,请联系管理员")
     else:
         return self.render_string("error.html", msg=u"%s:服务器处理失败,请联系管理员" % status_code)
开发者ID:lanyeit,项目名称:toughwlan,代码行数:10,代码来源:base.py

示例14: explode_list

def explode_list(msg, blist):
    for n1 in msg:
        if isinstance(msg[n1], dict):
            explode_list(msg[n1], blist)
        elif isinstance(msg[n1], list):
            for n2 in msg[n1]:
                explode_list(n2, blist)
        else:
            if n1 != 'sign':
                blist.append(utils.safestr(msg[n1]))
开发者ID:fozzmarc,项目名称:toughlib,代码行数:10,代码来源:apiutils.py

示例15: process

 def process(self, msgid, message):
     self.syslog.info("accept acct message @ %s : %r" % (self.listen, utils.safeunicode(message)))
     try:
         req_msg = apiutils.parse_request(self.secret, message)
         if req_msg.get("action") == 'ping':
             return self.agent.reply(msgid, apiutils.make_message(self.secret,code=0))
     except Exception as err:
         resp = apiutils.make_message(self.secret, code=1, msg=utils.safestr(err.message))
         self.agent.reply(msgid, resp)
         return
开发者ID:davislidaqing,项目名称:ToughRADIUS,代码行数:10,代码来源:acctounting.py


注:本文中的toughlib.utils.safestr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。