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


Python ObjectDict.update方法代码示例

本文整理汇总了Python中tornado.util.ObjectDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python ObjectDict.update方法的具体用法?Python ObjectDict.update怎么用?Python ObjectDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.util.ObjectDict的用法示例。


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

示例1: TrackRequest

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import update [as 别名]
class TrackRequest(RequestHandler):
    """Subclass this class to track requests.
    A track member is available to store additional state to the mongo tracker
    collection if required. This class can be initialized with a different Stats
    interface to send metrics somewhere else. The default StatsdStats sends
    to statsd/graphite.
    """   
    max_response_size = 120   
    
    def skip_dotted_names(self, d):
        # and multiple values
        return dict(
            (key, value[0] if len(value) == 1 else value) for key, value in \
                    d.iteritems() if '.' not in key) 

    def prepare(self):
        function = self.request.path
        if function.startswith('/stubo/api/'):
            function = function.partition('/stubo/api/')[-1]
        elif function == '/stubo/default/execCmds':
            # LEGACY
            function = 'exec/cmds'    

        args = self.skip_dotted_names(self.request.arguments) 
        headers = self.skip_dotted_names(self.request.headers)
        self.track = ObjectDict(request_params=args, 
                                request_headers=headers,
                                request_method=self.request.method)
        host_parts = self.request.host.partition(':')       
        host = host_parts[0].lower()
        port = host_parts[-1] 
        cache = Cache(host)
        track_setting = cache.get_stubo_setting('tracking_level')
        if not track_setting:
            track_setting = cache.get_stubo_setting('tracking_level', 
                                                    all_hosts=True)
        if not track_setting:
            track_setting = 'normal'   
        self.track.tracking_level = args.get('tracking_level', track_setting)
                    
        request_size = len(self.request.body)
        # always track put/stub recordings
        if self.track.tracking_level == 'full' or function == 'put/stub':
            self.track.request_text = self.request.body
            if function == 'get/response' and request_size <= 0:
                self.track.error = 'NoTextInBody' 
        
        self.track.update(dict(function=function,                    
                               start_time=tsecs_to_date(self.request._start_time),
                               host=host,
                               port=port,
                               remote_ip=self.request.remote_ip,
                               server=socket.getfqdn(),
                               request_size=request_size))
        log.debug('tracking: {0}:{1}'.format(self.request.host, function))


    def send_stats(self):
        stats = self.settings.get('stats')
        if stats:
            stats.send(self.settings, self.track)
           
    def on_finish(self):
        elapsed_ms = int(1000.0 * self.request.request_time())
        tracker = Tracker() 
        # handle fail early cases that don't have a response
        if not hasattr(self.track, 'stubo_response'):
            self.track.stubo_response = ''  
        return_code = self.get_status()      
        record = dict(duration_ms=elapsed_ms,
                      return_code=return_code)
        if self._headers_written:
            record['response_headers'] = self._headers
        record['response_size'] = int(self._headers.get('Content-Length',
                                len(self.track.stubo_response)))    
        self.track.update(record)

        if self.track.function == 'get/response' \
          and return_code > 399:
            self.track.request_text = self.request.body
        
        if self.track.tracking_level != 'full' and \
            self.track.response_size > self.max_response_size:
            try:
                # response will typically be json dict so convert to str to chop
                self.track.stubo_response = str(self.track.stubo_response
                                                )[:self.max_response_size]
            except Exception, e:
                log.error("unable to trim tracked stubo response: {0}".format(e))                                    
                
        if self.track.function == 'get/stublist':
            # don't want to store stub listing in the track
            self.track.stubo_response = 'stubs listed ...'
        elif self.track.function == 'exec/cmds':
            self.track.stubo_response = 'commands executed ...' 
        try:
            write_concern =  1 if self.track.function == 'put/stub' else 0
            tracker.insert(self.track, write_concern)
        except Exception, e:
            log.warn(u"error inserting track: {0}".format(e))
开发者ID:erowan,项目名称:stubo-app,代码行数:102,代码来源:track.py

示例2:

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import update [as 别名]
    # mongodb settings
    dbname = 'mapthisnow',
    dbhost = None,
    dbport = None,

    # httpd server settings
    httpd_address = '127.0.0.1',
    httpd_port = 9988,
    cookie_secret = None, # ya you're gonna have to set this locally

    # file paths
    static_path = path.join(path.dirname(__file__), "static"),
    template_path = path.join(path.dirname(__file__), "app/templates"),
    login_url = '/auth/netflix/connect',

    # debuggery
    debug = False,
    debug_pdb = False,

    netflix_client_secret = None,
    netflix_client_id = None,
    netflix_callback_uri = 'http://127.0.0.1:9988/auth/netflix/connect',
    )

# pull in our local overrides, if any
try:
    from settings_local import settings as settings_local
    settings.update(settings_local)
except ImportError: pass
开发者ID:nod,项目名称:greeneggs,代码行数:31,代码来源:settings.py


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