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


Python dotdict.DotDict类代码示例

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


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

示例1: post

    def post(self):
        """Turn on buletooth."""
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            tid = data.get('tid', None)
            tids = data.get('tids', None)
            self.check_tid(tid)
            logging.info("[BLUETOOTH] kqly request: %s, uid: %s, tids: %s",
                         data, self.current_user.uid, tids)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            logging.exception("[UWEB] Invalid data format. body:%s, Exception: %s",
                              self.request.body, e.args)
            self.write_ret(status)
            return

        try:
            tids = str_to_list(tids)
            tids = tids if tids else [self.current_user.tid, ]
            tids = [str(t) for t in tids]          
            kqly(self.db, self.redis, tids)
            self.write_ret(status)
        except Exception as e:
            logging.exception("[BLUETOOTH] Kqly failed. uid: %s, tid: %s, Exception: %s. ",
                              self.current_user.uid, self.current_user.tid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:bluetooth.py

示例2: get_tinyurl

    def get_tinyurl(url):
        """Get a tiny url for wap url.
        """ 
        try:
            # Baidu dwz
            #h = httplib2.Http()
            #msg={'url':url}
            #url_create = 'http://dwz.cn/create.php'
            #response, content = h.request(url_create, "POST", urlencode(msg),  headers={'Content-Type': 'application/x-www-form-urlencoded'})
            #res = DotDict(json_decode(content))
            #logging.info("[TINY_URL] response: %s", res) 
            #if res.status == 0:
            #    return res.tinyurl
            #else:
            #    return None

            # google
            h = httplib2.Http()
            url_create = 'https://www.googleapis.com/urlshortener/v1/url'
            msg = json_encode({'longUrl': url})
            response, content = h.request(url_create,
                                          "POST",
                                          msg,
                                          headers = {'Content-Type': 'application/json'})
            res = DotDict(json_decode(content))
            logging.info("[TINY_URL] response: %s", res) 
            return res.get('id', None)

        except Exception as e:
            logging.exception("Get tiny url failed. Exception: %s", e.args)
            return None
开发者ID:jcsy521,项目名称:ydws,代码行数:31,代码来源:urlhelper.py

示例3: post

    def post(self):
        """Clear the cookie and set defend."""
        try:
            data = DotDict(json_decode(self.request.body))
            devid = data.get("devid", "")
            logging.info("[UWEB] logout request: %s, uid: %s",
                         data, self.current_user.uid)
        except:
            self.write_ret(ErrorCode.ILLEGAL_DATA_FORMAT)
            logging.error("[UWEB] illegal format, body:%s", self.request.body)
        else:
            # 1: if there are tids, set defend
            for tid in data.tids:
                update_mannual_status(self.db, self.redis, tid, UWEB.DEFEND_STATUS.YES)

            # 2: remove devid from android_push_list
            android_push_list_key = get_android_push_list_key(
                self.current_user.uid)
            android_push_list = self.redis.getvalue(android_push_list_key)
            android_push_list = android_push_list if android_push_list else []
            if devid in android_push_list:
                android_push_list.remove(devid)
                self.redis.set(android_push_list_key, android_push_list)
            logging.info("[UWEB] uid:%s, android_push_lst: %s",
                         self.current_user.uid, android_push_list)
        finally:
            # 3: clear cookie
            self.clear_cookie(self.app_name)
            self.write_ret(ErrorCode.SUCCESS)
开发者ID:jcsy521,项目名称:ydws,代码行数:29,代码来源:login.py

示例4: retrieve

    def retrieve(self, citylist=None):
        """core for Retrieving and Storing operation."""
        #store the complete data of curent month into MongoDB
        if not citylist:
            cities = self.mysql_db.query("SELECT DISTINCT region_code AS id"
                                         "  FROM T_HLR_CITY")
            citylist = [c.id for c in cities]

        results = self.retrieve_mixin(citylist)

        # get the group_id list from mongodb(may include the group_id has been removed)
        res = self.collection.find({'city_id': { '$in' : citylist }}, {'group_id':1})
        ids_mongod = [int(v['group_id']) for v in res]
        # get the group_id lsit from mysql (the latest)
        ids_mysql = [int(result['group_id']) for result in results]        
        # get the group_id to be removed and remove them from mongodb
        ids_move = list(set(ids_mongod) - set(ids_mysql))
        self.collection.remove({'group_id': {'$in':ids_move}})

        try:
            for result in results:
                result = DotDict(result)
                oldresult = self.collection.find_one({'id': result.id})
                if oldresult:
                    result['_id'] = oldresult['_id']
                else:
                    result.pop('_id')
                self.collection.save(result)
        except:
            logging.exception('mongodb connected failed')
        return results
开发者ID:jcsy521,项目名称:ydws,代码行数:31,代码来源:mgroup.py

示例5: post

    def post(self):
        status = WXErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            tid = data.get('tid', None)
            mannual_status = data.get('mannual_status', None)
            
            terminal = self.db.get("SELECT mannual_status, defend_status, service_status FROM T_TERMINAL_INFO "
                                   "WHERE tid = %s ", tid)

            if terminal:
                service_status = terminal['service_status']
                if int(service_status) == 0:
                    status = WXErrorCode.OUTSERVICE
                    self.write_ret(status=status,
                                   message=WXErrorCode.ERROR_MESSAGE[status])
                    return
             
            try:
                self.db.execute("UPDATE T_TERMINAL_INFO SET mannual_status = %s"
                                "WHERE tid = %s", mannual_status, tid)
            except MySQLdb.Error as e:
                logging.exception("[WEIXIN] execute update sql terminal:%s mannual_stauts failed ",
                                  tid, e.args)
                status = WXErrorCode.SERVER_BUSY

            self.write_ret(status=status,
                           message=WXErrorCode.ERROR_MESSAGE[status])

        except Exception as e:
            logging.exception("[WEIXIN] update terminal:%s mannual_stauts failed", tid)
            status = WXErrorCode.FAILED
            self.write_ret(status=status,
                           message=WXErrorCode.ERROR_MESSAGE[status])
开发者ID:jcsy521,项目名称:ydws,代码行数:34,代码来源:defend.py

示例6: handle_request

 def handle_request(self, data):
     try:
         packet = T_CLWCheck(data)
         command = packet.head.command
         if command == GATEWAY.T_MESSAGE_TYPE.AGPS:
             head = packet.head
             body = packet.body 
             args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                            agps_data=None)
             ap = AgpsParser(body, head)
             agps_sign = self.get_agps_sign(ap.ret, int(head.timestamp))
             if agps_sign != int(head.agps_sign, 16):
                 args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID
                 logging.error("[AGPS] agps_sign invalid.")
             else:
                 agps = ap.ret
                 args.agps_data = self.get_agps_from_redis(agps)
                 if args.agps_data:
                     ac = AgpsComposer(args)
                     return ac.buf
                 else:
                     logging.error("[AGPS] there's no invalid agps data.")
                     return None 
     except:
         logging.exception("[AGPS] Handle agps request exception.")
         return None 
开发者ID:jcsy521,项目名称:ydws,代码行数:26,代码来源:server.py

示例7: put

    def put(self):
        """Update the parameters of terminal.
        """
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            tid = data.get('tid', None)
            # check tid whether exist in request and update current_user
            self.check_tid(tid)
            logging.info("[UWEB] Terminal request: %s, uid: %s, tid: %s",
                         data, self.current_user.uid, self.current_user.tid)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write_ret(status)
            return

        try:
            terminal = QueryHelper.get_available_terminal(
                self.current_user.tid, self.db)
            if not terminal:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The terminal with tid: %s does not exist,"
                              "  redirect to login.html",
                              self.current_user.tid)
                self.write_ret(status)
                return

            user = QueryHelper.get_user_by_uid(self.current_user.uid, self.db)
            if not user:
                status = ErrorCode.LOGIN_AGAIN
                logging.error("[UWEB] The user with uid: %s does not exist,"
                              "  redirect to login.html",
                              self.current_user.uid)
                self.write_ret(status)
                return

            # sql injection
            if data.has_key('corp_cnum') and not check_cnum(data.corp_cnum):
                status = ErrorCode.ILLEGAL_CNUM
                self.write_ret(status)
                return

            # NOTE: deprecated
            if data.has_key('white_list'):
                white_list = ":".join(data.white_list)
                if not check_sql_injection(white_list):
                    status = ErrorCode.ILLEGAL_WHITELIST
                    self.write_ret(status)
                    return

            self.update_terminal_db(data)
            # NOTE: wspush to client
            if status == ErrorCode.SUCCESS:
                WSPushHelper.pushS7(tid, self.db, self.redis)
            self.write_ret(status)
        except Exception as e:
            logging.exception("[UWEB] uid:%s, tid:%s update terminal info failed. Exception: %s",
                              self.current_user.uid, self.current_user.tid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:60,代码来源:terminal.py

示例8: get

 def get(self):
     """Display profile of current operator.
     """
     status = ErrorCode.SUCCESS
     try: 
         profile = DotDict()
         # 1: user     
         oper = QueryHelper.get_operator_by_oid(self.current_user.oid, self.db)
         if not oper:
             status = ErrorCode.LOGIN_AGAIN
             logging.error("[UWEB] Operator does not exist, redirect to login.html. oid: %s.", 
                           self.current_user.oid)
             self.write_ret(status)
             return
         
         profile.update(oper)
         for key in profile.keys():
             profile[key] = profile[key] if profile[key] else ''
         self.write_ret(status,
                        dict_=dict(profile=profile))
     except Exception as e:
         logging.exception("[UWEB] Get corp profile failed. oid:%s, tid:%s, Exception: %s", 
                           self.current_user.oid, self.current_user.tid, e.args) 
         status = ErrorCode.SERVER_BUSY
         self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:25,代码来源:profile.py

示例9: post

    def post(self):
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            tid = data.get("tid", None)
            self.check_tid(tid)
            logging.info("[UWEB] terminal request: %s, uid: %s, tid: %s", 
                         data, self.current_user.uid, self.current_user.tid)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write(status)
            return

        try:
            tid = data["tid"]
            items = self.db.query("SELECT * FROM T_ALERT_SETTING WHERE tid=%s", tid)
            if len(items) >= 7:
                status = ErrorCode.FAILED
                self.write_ret(status)
                logging.error("[UWEB] terminal %s set too many event periods", tid)
            else:
                start_time = data["start_time"]
                end_time = data["end_time"]
                week = data["week"]
                self.db.execute("INSERT INTO T_ALERT_SETTING"
                                "  VALUES(NULL, %s, %s, %s, %s)",
                                tid, start_time, end_time, week)
                logging.info("[UWEB] terminal add event period success: %s", data)
                self.write_ret(status)
        except Exception as e:
            logging.exception("[UWEB] tid:%s insert event period. Exception:%s", 
                              tid, e.args)
            status = ErrorCode.FAILED
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:34,代码来源:eventperiod.py

示例10: put

    def put(self):
        """Modify profile of current operator. 
        """
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            logging.info("[UWEB] Operator profile request: %s, oid: %s, tid: %s", 
                         data, self.current_user.oid, self.current_user.tid)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write_ret(status)
            return 

        try:
            #if data.has_key('email')  and not check_sql_injection(data.email):
            if data.has_key('email') and len(data.email)>50:
                status = ErrorCode.ILLEGAL_EMAIL 
                self.write_ret(status, 
                               message=u'联系人邮箱的最大长度是50个字符!')
                return

            update_operator(data, self.current_user.oid, self.db, self.redis)
            self.write_ret(status)
        except Exception as e:
            logging.exception("[UWEB] Update operator profile failed. oid:%s, Exception: %s", 
                              self.current_user.oid, e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:profile.py

示例11: handle_fob_info

def handle_fob_info(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S19 
    NOTE: deprecated 

    fob info packet: add or remove fob
    0: success, then record new terminal's address
    1: invalid SessionID
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id
        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS)
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            fp = FobInfoParser(body, head)
            fobinfo = fp.ret
            update_terminal_status(redis, head.dev_id, address)
            update_fob_info(db, redis, fobinfo)

        fc = FobInfoRespComposer(args)
        request = DotDict(packet=fc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle fob info report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:31,代码来源:fob.py

示例12: retrieve

    def retrieve(self, city_list=None, end_time=None):
        """core for Retrieving and Storing operation."""

        """This method returns the last day"""
        if not end_time:
            d = datetime.datetime.fromtimestamp(time.time())
            t = datetime.datetime.combine(datetime.date(d.year, d.month, d.day), datetime.time(0, 0))
            # get today 0:00:00
            end_time = int(time.mktime(t.timetuple())*1000)

        if not city_list:
            cities = self.mysql_db.query("SELECT DISTINCT region_code AS id FROM T_HLR_CITY")
            city_list = [city.id for city in cities]

        results = self.retrieve_mixin(city_list, end_time)
        try:
            for result in results:
                result = DotDict(result)
                query_term = {'city_id': result.city_id, 'timestamp': result.timestamp}
                oldresult = self.collection.find_one(query_term)
                if oldresult:
                    result['_id'] = oldresult['_id']
                else:
                    result.pop('_id')
                self.collection.save(result)
        except Exception as e:
            logging.exception('mongodb saved failed. Error: %s', e.args)
        return results
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:mdaily.py

示例13: update_operator

def update_operator(operator, oid, db, redis):
    """Update operator status.

    :arg operator: dict, e.g.

        {
          'address':'',
          'email':'',          
        }

    :arg oid: string
    :arg db: database instance
    :arg redis: redis instance

    """
    set_clause_dct = DotDict()
    fields = DotDict(address="address = '%s'",
                     email="email = '%s'")
    for key, value in operator.iteritems():
        set_clause_dct.setdefault(key, fields[key] % value)

    set_clause = ','.join(
        [v for v in set_clause_dct.itervalues() if v is not None])
    if set_clause:
        db.execute("UPDATE T_OPERATOR SET " + set_clause +
                   "  WHERE oid = %s",
                   oid)
开发者ID:jcsy521,项目名称:ydws,代码行数:27,代码来源:public.py

示例14: post

    def post(self, ecmobile):
        """Modify a business.
        """
        fields = DotDict(ecname=" name = '%s'",
                         ecmobile=" mobile = '%s'",
                         linkman="linkman = '%s'",
                         address="address = '%s'",
                         email="email = '%s'",
                         bizcode="bizcode = '%s'",
                         type="type = '%s'")

        for key in fields:
            v = self.get_argument(key, None)
            if v is not None:
                # if not check_sql_injection(v):
                # call get method
                #   self.get(tmobile)
                #   return
                fields[key] = fields[key] % v
            else:
                fields[key] = None
        set_cmd = ', '.join([v for v in fields.itervalues()
                             if v is not None])

        sql = "UPDATE T_CORP SET " + set_cmd + " WHERE mobile = %s" % ecmobile
        self.db.execute(sql)

        self.redirect("/ecbusiness/list/%s" % ecmobile)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:ecbusiness.py

示例15: post

    def post(self):
        """Insert new items."""
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            content = data.get('content', '')
            mobiles = data.get('mobiles', None)
            logging.info("[UWEB] Announcement request: %s", data)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write_ret(status)
            return

        try:
            mobiles_ = u''
            if mobiles is not None:
                mobiles_ = ','.join(mobiles)
                for mobile in mobiles:
                    SMSHelper.send(mobile, content)

            announcement = dict(cid=self.current_user.cid,
                                content=content,
                                mobiles=mobiles_)
            record_announcement(self.db, announcement)

            self.write_ret(status)
        except Exception as e:
            status = ErrorCode.SERVER_BUSY
            logging.exception(
                "[UWEB] record share failed, Exception: %s", e.args)
            self.write_ret(status)
开发者ID:jcsy521,项目名称:ydws,代码行数:31,代码来源:announcement.py


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