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


Python ObjectDict.get方法代码示例

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


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

示例1: __init__

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import get [as 别名]
 def __init__(self, config_path):
     cfg = ObjectDict(read_config(config_path))
     cfg.db_name = cfg['mongo.db']
     cfg['num_processes'] = int(cfg.get('num_processes', 0))
     cfg['stubo_version'] = version
     cfg['debug'] = asbool(cfg.get('debug', False))
     max_workers = int(cfg.get('max_workers', 100))
     log.info('started with {0} worker threads'.format(max_workers))
     cfg['executor'] = ThreadPoolExecutor(max_workers)
    
     try:
         cfg['statsd_client'] = StatsClient(host=cfg.get('statsd.host', 
             'localhost'), prefix=cfg.get('statsd.prefix', 'stubo')) 
         cfg['stats'] = StatsdStats()
         log.info('statsd host addr={0}, prefix={1}'.format(
                 cfg['statsd_client']._addr, cfg['statsd_client']._prefix))
     except socket.gaierror, e:
         log.warn("unable to connect to statsd: {0}".format(e))
开发者ID:mithun-kumar,项目名称:stubo-app,代码行数:20,代码来源:run_stubo.py

示例2: __init__

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import get [as 别名]
    def __init__(self, config_path):
        cfg = ObjectDict(read_config(config_path))
        cfg.db_name = cfg["mongo.db"]
        cfg["num_processes"] = int(cfg.get("num_processes", 0))
        cfg["stubo_version"] = version
        cfg["debug"] = asbool(cfg.get("debug", False))
        max_workers = int(cfg.get("max_workers", 100))
        log.info("started with {0} worker threads".format(max_workers))
        cfg["executor"] = ThreadPoolExecutor(max_workers)

        try:
            cfg["statsd_client"] = StatsClient(
                host=cfg.get("statsd.host", "localhost"), prefix=cfg.get("statsd.prefix", "stubo")
            )
            cfg["stats"] = StatsdStats()
            log.info(
                "statsd host addr={0}, prefix={1}".format(cfg["statsd_client"]._addr, cfg["statsd_client"]._prefix)
            )
        except socket.gaierror, e:
            log.warn("unable to connect to statsd: {0}".format(e))
开发者ID:rusenask,项目名称:mirage,代码行数:22,代码来源:run_stubo.py

示例3: A

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import get [as 别名]
class A(object):

    __slots__ = ['_data', '_dirty']

    def __init__(self):
        self._dirty = False
        self._data = ObjectDict({'a':10})

    def __getitem__(self, name):
        return self._data.get(name, None)

    def __setitem__(self, name, value):
        self._data[name] = value
        self._dirty = True

    def __delitem__(self, name):
        del self._data[name]
        self._dirty = True

    def __contains__(self, name):
        return name in self._data

    def __len__(self):
        return len(self._data)

    def __getattr__(self, name):
        print('getattr %s' % name)
        return getattr(self._data, name)

    def __setattr__(self, name, value):
        print('__setattr__ %s '%name)
        if name in self.__slots__:
            print('setattr slots %s'%name)
            super(A, self).__setattr__(name, value)
        else:
            print('setattr data %'%name)
            self._dirty = True
            setattr(self._data, name, value)

    def __delattr__(self, name):
        print('__delattr__')
        delattr(self._data, name)
        self._dirty = True

    def __iter__(self):
        for key in self._data:
            yield key

    def __repr__(self):
        return str(self._data)
开发者ID:zhyq0826,项目名称:test-lab,代码行数:52,代码来源:test_dict.py

示例4: Session

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import get [as 别名]
class Session(object):

    __slots__ = ['store', 'handler', 'app', '_data', '_dirty', '_config',
        '_initializer', 'session_id', '_session_object', '_session_name']

    def __init__(self, app, handler, store, initializer, session_config=None, session_object=None):
        self.handler = handler
        self.app = app
        self.store = store or DiskStore(app_config.store_config.diskpath)

        self._config = deepcopy(app_config.session_config)
        if session_config:
            self._config.update(session_config)

        self._session_name = self._config.name

        self._session_object = (session_object or CookieObject)(app, handler, self.store, self._config)
        
        self._data = ObjectDict()
        self._initializer = initializer

        self.session_id = None

        self._dirty = False
        self._processor()

    def __getitem__(self, name):
        if name not in self._data:
            session_log.error('%s key not exist in %s session' % (name, self.session_id))

        return self._data.get(name, None)

    def __setitem__(self, name, value):
        self._data[name] = value
        self._dirty = True

    def __delitem__(self, name):
        del self._data[name]
        self._dirty = True

    def __contains__(self, name):
        return name in self._data

    def __len__(self):
        return len(self._data)

    def __getattr__(self, name):
        return getattr(self._data, name)
    
    def __setattr__(self, name, value):
        if name in self.__slots__:
            super(Session, self).__setattr__(name, value)
        else:
            self._dirty = True
            setattr(self._data, name, value)
        
    def __delattr__(self, name):
        delattr(self._data, name)
        self._dirty = True

    def __iter__(self):
        for key in self._data:
            yield key

    def __repr__(self):
        return str(self._data)

    def _processor(self):
        """Application processor to setup session for every request"""
        self.store.cleanup(self._config.timeout)
        self._load()

    def _load(self):
        """Load the session from the store, by the id from cookie"""

        self.session_id = self._session_object.get_session_id()

        # protection against session_id tampering
        if self.session_id and not self._valid_session_id(self.session_id):
            self.session_id = None

        if self.session_id:
            d = self.store[self.session_id]
            if isinstance(d, dict) and d:
                self.update(d)

        if not self.session_id:
            self.session_id = self._session_object.generate_session_id()

        if not self._data:
            if self._initializer and isinstance(self._initializer, dict):
                self.update(deepcopy(self._initializer))

        self._session_object.set_session_id(self.session_id)

    def save(self):
        if self._dirty:
            self.store[self.session_id] = self._data

    def _valid_session_id(self, session_id):
#.........这里部分代码省略.........
开发者ID:intfrr,项目名称:app-turbo,代码行数:103,代码来源:session.py


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