python类urlsplit()的实例源码

hosts.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def collect_hosts(hosts, randomize=True):
    """Collect a set of hosts and an optional chroot from a string."""
    host_ports, chroot = hosts.partition("/")[::2]
    chroot = "/" + chroot if chroot else None

    result = []
    for host_port in host_ports.split(","):
        # put all complexity of dealing with
        # IPv4 & IPv6 address:port on the urlsplit
        res = urllib_parse.urlsplit("xxx://" + host_port)
        host = res.hostname
        if host is None:
            raise ValueError("bad hostname")
        port = int(res.port) if res.port else 2181
        result.append((host.strip(), port))

    if randomize:
        random.shuffle(result)

    return result, chroot
clients.py 文件源码 项目:script.module.python.twitch 作者: MrSprigster 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def parse_implicit_response(url):
        pairs = urlsplit(url).fragment.split('&')
        fragment = dict()
        for pair in pairs:
            key, value = pair.split('=')
            fragment[key] = value
        return {'access_token': fragment.get('access_token'), 'scope': fragment.get('scope', '').split('+'), 'state': fragment.get('state')}
base.py 文件源码 项目:everypolitician-popolo-python 作者: everypolitician 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def extract_twitter_username(username_or_url):
    split_url = urlsplit(username_or_url)
    if split_url.netloc == 'twitter.com':
        return re.sub(r'^/([^/]+).*', r'\1', split_url.path)
    return username_or_url.strip().lstrip('@')
hosts.py 文件源码 项目:deb-kazoo 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def collect_hosts(hosts):
    """
       Collect a set of hosts and an optional chroot from
       a string or a list of strings.
    """
    if isinstance(hosts, list):
        if hosts[-1].strip().startswith('/'):
            host_ports, chroot = hosts[:-1], hosts[-1]
        else:
            host_ports, chroot = hosts, None
    else:
        host_ports, chroot = hosts.partition("/")[::2]
        host_ports = host_ports.split(",")
        chroot = "/" + chroot if chroot else None

    result = []
    for host_port in host_ports:
        # put all complexity of dealing with
        # IPv4 & IPv6 address:port on the urlsplit
        res = urllib_parse.urlsplit("xxx://" + host_port)
        host = res.hostname
        if host is None:
            raise ValueError("bad hostname")
        port = int(res.port) if res.port else 2181
        result.append((host.strip(), port))

    return result, chroot


问题


面经


文章

微信
公众号

扫码关注公众号