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


Python Config.discover方法代码示例

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


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

示例1: check_if_following

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def check_if_following(follower):
    config = Config.discover()

    if config.get_source_by_nick(follower):
        return True

    return False
开发者ID:myles,项目名称:twtxt.mylesb.ca,代码行数:9,代码来源:followers.py

示例2: test_add_get_remove_source

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def test_add_get_remove_source():
    conf = Config.discover()
    conf.cfg.remove_section("following")

    assert conf.remove_source_by_nick("foo") is False
    assert conf.get_source_by_nick("baz") is None

    conf.add_source(Source("foo", "bar"))
    source = conf.get_source_by_nick("foo")
    assert source.nick == "foo"
    assert source.url == "bar"

    assert conf.remove_source_by_nick("baz") is False
    assert conf.remove_source_by_nick("foo") is True
    assert conf.following == []
开发者ID:timofurrer,项目名称:twtxt,代码行数:17,代码来源:test_config.py

示例3: cli

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def cli(ctx, config, verbose):
    """Decentralised, minimalist microblogging service for hackers."""
    init_logging(debug=verbose)

    try:
        if config:
            conf = Config.from_file(config)
        else:
            conf = Config.discover()
    except ValueError:
        click.echo("Error loading config file.")
        if not config:
            if click.confirm("Do you want to run the twtxt quickstart wizard?", abort=True):
                pass

    ctx.default_map = conf.build_default_map()
    ctx.obj = {'conf': conf}
开发者ID:gitter-badger,项目名称:twtxt,代码行数:19,代码来源:cli.py

示例4: test_create_config

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def test_create_config(config_dir):
    config_dir_old = Config.config_dir
    Config.config_dir = str(config_dir.join("new"))
    conf_w = Config.create_config("bar", "batz.txt", False, True)
    conf_r = Config.discover()
    assert conf_r.nick == "bar"
    assert conf_r.twtfile == "batz.txt"
    assert conf_r.character_limit == 140
    assert conf_r.following[0].nick == "twtxt"
    assert conf_r.following[0].url == "https://buckket.org/twtxt_news.txt"
    assert set(conf_r.options.keys()) == {"nick", "twtfile", "disclose_identity", "character_limit"}

    conf_r.cfg.remove_section("twtxt")
    assert conf_r.options == {}

    conf_r.cfg.remove_section("following")
    assert conf_r.following == []
    Config.config_dir = config_dir_old
开发者ID:timofurrer,项目名称:twtxt,代码行数:20,代码来源:test_config.py

示例5: cli

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def cli(ctx, config, verbose):
    """Decentralised, minimalist microblogging service for hackers."""
    init_logging(debug=verbose)

    if ctx.invoked_subcommand == "quickstart":
        return

    try:
        if config:
            conf = Config.from_file(config)
        else:
            conf = Config.discover()
    except ValueError:
        click.echo("✗ Config file not found or not readable. You may want to run twtxt quickstart.")
        sys.exit()

    ctx.default_map = conf.build_default_map()
    ctx.obj = {'conf': conf}
开发者ID:timofurrer,项目名称:twtxt,代码行数:20,代码来源:cli.py

示例6: cli

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def cli(ctx, config, verbose):
    """Decentralised, minimalist microblogging service for hackers."""
    init_logging(debug=verbose)

    if ctx.invoked_subcommand == "quickstart":
        return  # Skip initializing config file

    try:
        if config:
            conf = Config.from_file(config)
        else:
            conf = Config.discover()
    except ValueError as e:
        if "Error in config file." in str(e):
            click.echo("✗ Please correct the errors mentioned above an run twtxt again.")
        else:
            click.echo("✗ Config file not found or not readable. You may want to run twtxt quickstart.")
        sys.exit()

    ctx.default_map = conf.build_default_map()
    ctx.obj = {'conf': conf}
开发者ID:DracoBlue,项目名称:twtxt,代码行数:23,代码来源:cli.py

示例7: test_discover

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def test_discover():
    conf = Config.discover()
    check_cfg(conf)
开发者ID:timofurrer,项目名称:twtxt,代码行数:5,代码来源:test_config.py

示例8: retrieve_file

# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import discover [as 别名]
def retrieve_file(client, source, limit, cache):
    is_cached = cache.is_cached(source.url) if cache else None
    headers = {"If-Modified-Since": cache.last_modified(source.url)} if is_cached else {}

    try:
        response = yield from client.request("get",source.url, headers=headers,allow_redirects=False)
        content = yield from response.text()
    except Exception as e:
        if is_cached:
            logger.debug("{}: {} - using cached content".format(source.url, e))
            return cache.get_tweets(source.url, limit)
    #comp490
        elif e==ssl.CertificateError:

            click.echo("Warning the source: "+source.nick+" is unsafe: Hostname does not match name on SSL certificate")
            return []
        elif e==aiohttp.errors.ClientOSError:

            if "[[SSL: CERTIFICATE_VERIFY_FAILED" in str(e):
                click.echo("Warning the source: "+source.nick+" is unsafe: The ssl certificate has expired")
                return []
            elif "[SSL: EXCESSIVE_MESSAGE_SIZE]" in str(e):
                click.echo("Warning the source: "+source.nick+" is unsafe: source has sent an invalid response")
    #COMP490
        else:
            logger.debug(e)
            return []

    if response.status == 200:
        tweets = parse_tweets(content.splitlines(), source)

        if cache:
            last_modified_header = response.headers.get("Last-Modified")
            if last_modified_header:
                logger.debug("{} returned 200 and Last-Modified header - adding content to cache".format(source.url))
                cache.add_tweets(source.url, last_modified_header, tweets)
            else:
                logger.debug("{} returned 200 but no Last-Modified header - can’t cache content".format(source.url))
        else:
            logger.debug("{} returned 200".format(source.url))

        return sorted(tweets, reverse=True)[:limit]
#comp490
    elif response.status==301:
        cache = Cache.discover()
        conf=Config.discover()
        tweets=cache.get_tweets(source.url)

        conf.remove_source_by_nick(source.nick)
        url=response.headers["Location"]
        conf.add_source(Source(source.nick,url))
        for tweet in tweets:
            cache.add_tweet(url,0,tweet)
#comp490
    elif response.status == 410 and is_cached:
        # 410 Gone:
        # The resource requested is no longer available,
        # and will not be available again.
        logger.debug("{} returned 410 - deleting cached content".format(source.url))
        cache.remove_tweets(source.url)
        return []

    elif is_cached:
        logger.debug("{} returned {} - using cached content".format(source.url, response.status))
        return cache.get_tweets(source.url, limit)

    else:
        logger.debug("{} returned {}".format(source.url, response.status))
        return []
开发者ID:Puddinglord,项目名称:twtxt,代码行数:71,代码来源:twhttp.py


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