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


Python urlparse.ParseResult方法代码示例

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


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

示例1: urlparams

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def urlparams(url_, hash=None, **query):
    """Add a fragment and/or query paramaters to a URL.

    New query params will be appended to exising parameters, except duplicate
    names, which will be replaced.
    """
    url = urlparse.urlparse(url_)
    fragment = hash if hash is not None else url.fragment

    # Use dict(parse_qsl) so we don't get lists of values.
    query_dict = dict(urlparse.parse_qsl(url.query))
    query_dict.update(query)

    query_string = urlencode(
        [(k, v) for k, v in query_dict.items() if v is not None])
    new = urlparse.ParseResult(url.scheme, url.netloc, url.path, url.params,
                               query_string, fragment)
    return new.geturl() 
开发者ID:mozilla,项目名称:sugardough,代码行数:20,代码来源:helpers.py

示例2: update_receive_qr

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def update_receive_qr(self):
        import urlparse, urllib
        addr = str(self.receive_address_e.text())
        amount = None
        message = None
        url = None
        amount = self.receive_amount_e.get_amount()
        message = unicode(self.receive_message_e.text()).encode('utf8')
        self.save_request_button.setEnabled((amount is not None) or (message != ""))
        uri_scheme = chainkey.chainparams.get_active_chain().coin_name.lower()
        if addr:
            query = []
            if amount:
                query.append('amount=%s'%format_satoshis(amount))
            if message:
                query.append('message=%s'%urllib.quote(message))
            p = urlparse.ParseResult(scheme=uri_scheme, netloc='', path=addr, params='', query='&'.join(query), fragment='')
            url = urlparse.urlunparse(p)
        else:
            url = ""
        self.receive_qr.setData(url)
        if self.qr_window:
            self.qr_window.set_content(addr, amount, message, url) 
开发者ID:mazaclub,项目名称:encompass,代码行数:25,代码来源:main_window.py

示例3: geturl

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def geturl(self, include_params=True):
        params = self.params
        query = self.query
        fragment = self.fragment

        if not include_params:
            params = ""
            query = ""
            fragment = ""

        r = ParseResult(scheme=self.scheme,
                        netloc=self.netloc,
                        path=self.path,
                        params=params,
                        query=query,
                        fragment=fragment)
        return r.geturl() 
开发者ID:roglew,项目名称:pappy-proxy,代码行数:19,代码来源:repeater.py

示例4: strip_subfolder

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def strip_subfolder(url):
    """
    Strip off the subfolder if it exists so we always use the exact same
    share url for saving counts.
    """

    subfolder = app.config.get('SUBFOLDER', None)
    if not subfolder:
        return url

    p = urlparse.urlparse(url)

    if not p.path.startswith(subfolder):
        return url

    new_path = p.path.replace('%s' % (subfolder), '', 1)
    new_url = urlparse.ParseResult(p.scheme, p.netloc, new_path, p.params,
                                   p.query, p.fragment)
    return new_url.geturl() 
开发者ID:pluralsight,项目名称:guides-cms,代码行数:21,代码来源:views.py

示例5: validate_url

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def validate_url(self, url):
        url_path = urllib.quote(url.path, safe=b"/%")
        url_query = urllib.quote(url.query, safe=b"?=&")

        url = ParseResult(url.scheme, url.netloc, url_path,
                          url.params, url_query, url.fragment)

        has_hostname = url.hostname is not None and len(url.hostname) > 0
        has_http_scheme = url.scheme in ("http", "https")
        has_path = not len(url.path) or url.path.startswith("/")

        if not (has_hostname and has_http_scheme and has_path):
            raise NotSupported("invalid url: %s" % repr(url))

        return url 
开发者ID:dongweiming,项目名称:daenerys,代码行数:17,代码来源:app.py

示例6: replicate_per_farm_dbs

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def replicate_per_farm_dbs(cloud_url=None, local_url=None, farm_name=None):
    """
    Sete up replication of the per-farm databases from the local server to the
    cloud server.

    :param str cloud_url: Used to override the cloud url from the global
    configuration in case the calling function is in the process of
    initializing the cloud server
    :param str local_url: Used to override the local url from the global
    configuration in case the calling function is in the process of
    initializing the local server
    :param str farm_name: Used to override the farm name from the global
    configuratino in case the calling function is in the process of
    initializing the farm
    """
    cloud_url = cloud_url or config["cloud_server"]["url"]
    local_url = local_url or config["local_server"]["url"]
    farm_name = farm_name or config["cloud_server"]["farm_name"]
    username = config["cloud_server"]["username"]
    password = config["cloud_server"]["password"]

    # Add credentials to the cloud url
    parsed_cloud_url = urlparse(cloud_url)
    if not parsed_cloud_url.username:
        new_netloc = "{}:{}@{}".format(
            username, password, parsed_cloud_url.netloc
        )
    cloud_url = ParseResult(
        parsed_cloud_url.scheme, new_netloc, parsed_cloud_url.path,
        parsed_cloud_url.params, parsed_cloud_url.query,
        parsed_cloud_url.fragment
    ).geturl()

    server = Server(local_url)
    for db_name in per_farm_dbs:
        remote_db_name = "{}/{}/{}".format(username, farm_name, db_name)
        server.replicate(
            db_name, db_name, urljoin(cloud_url, remote_db_name),
            continuous=True
        ) 
开发者ID:OpenAgricultureFoundation,项目名称:openag_python,代码行数:42,代码来源:utils.py

示例7: should_follow

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def should_follow(self, response, spider):
        parsed = urlparse(response.url)
        url = ParseResult(
            parsed.scheme,
            parsed.netloc,
            parsed.path,
            parsed.params,
            None,
            None
        )
        url = url.geturl()
        return url not in spider.disallow_urls 
开发者ID:tryolabs,项目名称:daywatch,代码行数:14,代码来源:middleware.py

示例8: open_url

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def open_url(url):
    ru = urlparse.urlparse(url)
    pu = urlparse.ParseResult("", "", ru.path, ru.params, ru.query, ru.fragment)
    if ru.scheme == "https":
        c = httplib.HTTPSConnection(ru.netloc)
    else:
        c = httplib.HTTPConnection(ru.netloc)
    c.putrequest("GET", pu.geturl())
    c.putheader("User-Agent", FLAGS.user_agent)
    c.endheaders()
    return c.getresponse() 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:13,代码来源:import_google_fonts.py

示例9: parse_url

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def parse_url(url):
    url = urlparse.urlparse(url)
    if not url.scheme and not url.netloc and url.path:
        netloc = url.path
        if ':' not in netloc:
            netloc = '{}:8765'.format(netloc)
        return urlparse.ParseResult('http', netloc, '/', '', '', '')
    return url


# Defined in phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java 
开发者ID:lalinsky,项目名称:python-phoenixdb,代码行数:13,代码来源:client.py

示例10: _parse_url

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import ParseResult [as 别名]
def _parse_url(self,dst,src):
        """
        Check wether target url 'dst' is in the same domain(include port) with url 'src', and 
        convert url into complete url without params.

        Returns:
            String of complete url with query params if it has. if target url is not in the 
            same domain, return '';
        """
        LOG.debug('detecting url: '+dst)
        s_parsed=urlparse.urlparse(src)
        s_scheme=s_parsed.scheme
        s_netloc=s_parsed.netloc
        s_cur_dir=s_parsed.path
        if s_cur_dir[-1]!='/':
            s_cur_dir='/'.join(s_cur_dir.split('/')[:-1])
        else:
            s_cur_dir=s_cur_dir[:-1]

        d_parsed=urlparse.urlparse(dst)
        d_scheme=d_parsed.scheme
        if d_parsed.netloc.find(':')==-1 and d_parsed.netloc!='':
            if d_scheme=='http':
                d_netloc=d_parsed.netloc+':80'
            elif d_scheme=='https':
                d_netloc=d_parsed.netloc+':443'
            elif d_scheme=='':
                d_netloc=d_parsed.netloc+':80' if s_scheme=='http' else d_parsed.netloc+':443'
            else:
                d_netloc=d_parsed.netloc
        else:
            d_netloc=d_parsed.netloc
        # add '/' as prefix if the path does not starts with '/'
        if d_parsed.path!='':
            d_path='/'+d_parsed.path if d_parsed.path[0]!='/' else d_parsed.path
        else:
            d_path='/'
        d_query=d_parsed.query
        
        # if it is a relative url
        if d_netloc=='':
            return urlparse.ParseResult(s_scheme,s_netloc,s_cur_dir+d_path,'',d_query,'').geturl()
        elif d_netloc==s_netloc and (d_scheme==s_scheme or d_scheme==''):
            return urlparse.ParseResult(s_scheme,s_netloc,d_path,'',d_query,'').geturl()
        else:
            return '' 
开发者ID:a7vinx,项目名称:swarm,代码行数:48,代码来源:sitemap.py


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