Beispiel #1
0
 def __init__(self, manager, name, url, parser, fullname=None):
     if isinstance(manager, DataSourceManager):
         self.parent = None
         self._generations = 1
         self._sign = 1 << manager.sign_bit
         self._cconfig = cconfig(name.lower(), conf=manager.ext_conf)
     elif isinstance(manager, self.__class__):
         parent = manager
         manager = parent.manager
         generations = parent._generations + 1
         if generations > manager.max_generations:
             raise ValueError(
                 'DataSource.__init__ "generations=%d" 超过最大值:%d' %
                 (generations, manager.max_generations))
         self._generations = generations
         self._sign = 0
         self._cconfig = cconfig(name.lower(), parent)
         parent._children[name.lower()] = self
         parser = parser or parent.parser
     else:
         raise TypeError('DataSource.__init__ "manager" 类型错误:%s' %
                         manager.__class__)
     self.manager = manager
     self.url = url
     self.parser = parser
     self.fullname = fullname or name
     self.req = None
     self.update = None
     self.itemlist = []
Beispiel #2
0
 def __init__(self):
     self._sign_all = 0
     self._sign_bit = 0
     self._valid = {}
     self._conf = cconfig('ds', conf=self.ext_conf)
Beispiel #3
0
def init():
    global allown_gevent_patch

    patch_stdout()

    argv = set(sys.argv[1:])
    allown_gevent_patch = 'nogevent' not in argv
    if allown_gevent_patch:
        #设置优先使用的事件循环类型,优先应用命令行参数
        #用法: python start.py looptype
        # http://www.gevent.org/loop_impls.html
        if 'libuv' in argv or 'libuv-cffi' in argv:
            looptype = 'libuv-cffi'
        elif 'libev-cffi' in argv:
            looptype = 'libev-cffi'
        elif 'libev' in argv or 'libev-cext' in argv:
            looptype = 'libev-cext'
        else:
            gloop_conf = os.path.join(config_dir, 'gloop.conf')
            gloop = cconfig('gloop', conf=gloop_conf)
            gloop.add(['libuv-cffi', 'libev-cext', 'libev-cffi', 'nogevent'])
            gloop.load()
            allown_gevent_patch = not gloop.check('nogevent')
            if allown_gevent_patch:
                if gloop.check('libuv-cffi'):
                    looptype = 'libuv-cffi'
                elif gloop.check('libev-cffi'):
                    looptype = 'libev-cffi'
                elif gloop.check('libev-cext'):
                    looptype = 'libev-cext'
                else:
                    looptype = None
            gloop.close()

    if allown_gevent_patch:
        try:
            import gevent
        except ImportError:
            wait_exit(
                '无法找到 gevent 或者与 Python 版本不匹配,'
                '请安装 gevent-1.3.0 以上版本,'
                '或将相应 .egg 放到 %r 文件夹!\n'
                '或者使用 nogevent 参数重新启动。',
                packages,
                exc_info=True)
        if looptype:
            try:
                gevent._config.Loop.default.insert(0, looptype)
            except:
                pass
        try:
            import gevent.monkey
            gevent.monkey.patch_all(os=False,
                                    ssl=False,
                                    subprocess=False,
                                    signal=False)
        except TypeError:
            gevent.monkey.patch_all(os=False)
        if get_looptype().startswith('libuv') and sys.platform.startswith(
                'win'):
            patch_gevent_socket()

    replace_logging()
    patch_time()
    patch_builtins()
    patch_configparser()

    import logging

    if allown_gevent_patch and gevent.__version__ < '1.3.0':
        logging.warning('警告:请更新 gevent 至 1.3.0 以上版本!')

    try:
        import OpenSSL
    except ImportError:
        wait_exit(
            '无法找到 pyOpenSSL,请安装 pyOpenSSL-16.0.0 以上版本,'
            '或将相应 .egg 放到 %r 文件夹!',
            packages,
            exc_info=True)

    try:
        import dnslib
    except ImportError:
        wait_exit('无法找到 dnslib,请安装 dnslib-0.8.3 以上版本,'
                  '或将相应 .egg 放到 %r 文件夹!',
                  packages,
                  exc_info=True)