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


Python parse.urlunsplit方法代码示例

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


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

示例1: validate_

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def validate_(self, value, context=None):
        url = self.valid_url(value)
        if not url:
            raise StopValidationError(self.messages['invalid_url'])
        if self.verify_exists:
            url_string = urlquote(urlunsplit((
                url['scheme'],
                (url['host6'] or url['host4'] or url['hostn_enc']) + ':' + (url['port'] or ''),
                url['path'],
                url['query'],
                url['frag'])
                ).encode('utf-8'), safe=VALID_CHAR_STRING)
            try:
                urlopen(url_string)
            except URLError:
                raise StopValidationError(self.messages['not_found']) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:net.py

示例2: transform_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def transform_url(url, qparams=None, **kwargs):
    """ Modify url

    :param url: url to transform (can be relative)
    :param qparams: additional query params to add to end of url
    :param kwargs: pieces of URL to modify - e.g. netloc=localhost:8000
    :return: Modified URL

    .. versionadded:: 3.2.0
    """
    if not url:
        return url
    link_parse = urlsplit(url)
    if qparams:
        current_query = dict(parse_qsl(link_parse.query))
        current_query.update(qparams)
        link_parse = link_parse._replace(query=urlencode(current_query))
    return urlunsplit(link_parse._replace(**kwargs)) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:20,代码来源:utils.py

示例3: _fetch_tle

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def _fetch_tle(self, path, sate_id, date=None):
        url = urlparse.urljoin(self.url, path)
        url = urlparse.urlparse(url)
        qargs = {'satellite_number': sate_id}
        if date is not None:
            date_str = date.strftime("%Y-%m-%d")
            qargs['date'] = date_str

        query_string = urlencode(qargs)
        url = urlparse.urlunsplit((url.scheme, url.netloc, url.path, query_string, url.fragment))
        headers = {'user-agent': 'orbit-predictor', 'Accept': 'application/json'}
        try:
            response = requests.get(url, headers=headers)
        except requests.exceptions.RequestException as error:
            logger.error("Exception requesting TLE: %s", error)
            raise
        if response.ok and 'lines' in response.json():
            lines = tuple(response.json()['lines'])
            return lines
        else:
            raise ValueError("Error requesting TLE: %s", response.text) 
开发者ID:satellogic,项目名称:orbit-predictor,代码行数:23,代码来源:sources.py

示例4: translate_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def translate_url(url, lang_code):
    """
    Given a URL (absolute or relative), try to get its translated version in
    the `lang_code` language (either by i18n_patterns or by translated regex).
    Return the original URL if no translated version is found.
    """
    parsed = urlsplit(url)
    try:
        match = resolve(parsed.path)
    except Resolver404:
        pass
    else:
        to_be_reversed = "%s:%s" % (match.namespace, match.url_name) if match.namespace else match.url_name
        with override(lang_code):
            try:
                url = reverse(to_be_reversed, args=match.args, kwargs=match.kwargs)
            except NoReverseMatch:
                pass
            else:
                url = urlunsplit((parsed.scheme, parsed.netloc, url, parsed.query, parsed.fragment))
    return url 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:base.py

示例5: stored_name

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def stored_name(self, name):
        parsed_name = urlsplit(unquote(name))
        clean_name = parsed_name.path.strip()
        hash_key = self.hash_key(clean_name)
        cache_name = self.hashed_files.get(hash_key)
        if cache_name is None:
            if self.manifest_strict:
                raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
            cache_name = self.clean_name(self.hashed_name(name))
        unparsed_name = list(parsed_name)
        unparsed_name[2] = cache_name
        # Special casing for a @font-face hack, like url(myfont.eot?#iefix")
        # http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
        if '?#' in name and not unparsed_name[3]:
            unparsed_name[2] += '?'
        return urlunsplit(unparsed_name) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:18,代码来源:storage.py

示例6: _send_websocket_redirect

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def _send_websocket_redirect(self, scope: dict, send: Callable) -> None:
        # If the HTTP version is 2 we should redirect with a https
        # scheme not wss.

        scheme = "wss"
        if scope.get("http_version", "1.1") == "2":
            scheme = "https"

        new_url = urlunsplit(
            (scheme, self.host, scope["raw_path"].decode(), scope["query_string"].decode(), "")
        )
        await send(
            {
                "type": "websocket.http.response.start",
                "status": 307,
                "headers": [(b"location", new_url.encode())],
            }
        )
        await send({"type": "websocket.http.response.body"}) 
开发者ID:pgjones,项目名称:hypercorn,代码行数:21,代码来源:http_to_https.py

示例7: parse_image_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def parse_image_url(url: str) -> str:
    """
    Convert the image URL into a sized Discord avatar.

    Parameters
    ----------
    url : str
        The URL to convert.

    Returns
    -------
    str
        The converted URL, or '' if the URL isn't in the proper format.
    """
    types = [".png", ".jpg", ".gif", ".jpeg", ".webp"]
    url = parse.urlsplit(url)

    if any(url.path.lower().endswith(i) for i in types):
        return parse.urlunsplit((*url[:3], "size=128", url[-1]))
    return "" 
开发者ID:kyb3r,项目名称:modmail,代码行数:22,代码来源:utils.py

示例8: docker_init_app

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def docker_init_app(app):
    if "POSTGRES_PORT_5432_TCP_ADDR" in os.environ:
        scheme = "postgresql"
        host = os.environ["POSTGRES_PORT_5432_TCP_ADDR"]
        user = os.environ.get("POSTGRES_ENV_POSTGRES_USER") or "postgres"
        password = os.environ.get("POSTGRES_ENV_POSTGRES_PASSWORD")
        db = os.environ.get("POSTGRES_ENV_POSTGRES_DB") or user
        if user and password:
            netloc = f"{user}:{password}@{host}"
        elif user:
            netloc = f"{user}@{host}"
        else:
            netloc = host
        if not app.config.get("SQLALCHEMY_DATABASE_URI"):
            app.config["SQLALCHEMY_DATABASE_URI"] = urlunsplit(
                (scheme, netloc, db, None, None)
            )

    if "REDIS_PORT_6379_TCP_ADDR" in os.environ:
        scheme = "redis"
        host = os.environ["REDIS_PORT_6379_TCP_ADDR"]
        port = 6379
        netloc = f"{host}:{port}"
        app.config.setdefault("REDIS_URL", urlunsplit((scheme, netloc, "", None, None))) 
开发者ID:getsentry,项目名称:freight,代码行数:26,代码来源:config.py

示例9: _guess_links

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def _guess_links(self):
        path_segments = self.path.split("/")
        maybe_contains_feed = []
        maybe_feed = []
        root = urlunsplit((self.scheme, self.netloc, "", "", ""))
        maybe_contains_feed.append(ScoredLink(root, 0.5))
        for i in range(len(path_segments)):
            path = "/".join(path_segments[:i])
            url = urlunsplit((self.scheme, self.netloc, path, "", ""))
            maybe_contains_feed.append(ScoredLink(url, 1.0 / (i + 3)))
            for k in MAYBE_FEEDS:
                path = "/".join(path_segments[:i] + [k])
                url = urlunsplit((self.scheme, self.netloc, path, "", ""))
                maybe_feed.append(ScoredLink(url, 1.0 / (i + 4)))
        links = maybe_contains_feed + maybe_feed
        self._merge_links(links) 
开发者ID:anyant,项目名称:rssant,代码行数:18,代码来源:finder.py

示例10: append_query_params

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def append_query_params(original_url, **kwargs):
    """
    Add additional query string arguments to the given url.

    Example call:
        new_url = append_query_params(
            original_url, error='this is an error',
            another_arg='this is another argument')
    """
    scheme, netloc, path, query_string, fragment = urlsplit(original_url)
    query_params = parse_qs(query_string)
    if kwargs is not None:
        for key, value in kwargs.items():
            query_params[key] = [value]

    new_query_string = urlencode(query_params, doseq=True)
    new_url = urlunsplit((scheme, netloc, path, new_query_string, fragment))
    return new_url 
开发者ID:uc-cdis,项目名称:fence,代码行数:20,代码来源:utils.py

示例11: _build_sitelink_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def _build_sitelink_url(site, title):
    netloc_builder = []
    split_index = site.find('wiki')
    language = site[:split_index]
    netloc_builder.append(language.replace('_', '-'))
    project = site[split_index:]
    if project == 'wiki':
        project = 'wikipedia'
    if language == 'commons':
        project = 'wikimedia'
    netloc_builder.append(project)
    netloc_builder.append('org')
    url = urlunsplit(
        (
            'https',
            '.'.join(netloc_builder),
            '/wiki/%s' % title.replace(' ', '_'),
            '',
            '',
        )
    )
    LOGGER.debug('Site: %s - Title: %s - Full URL: %s', site, title, url)
    return url 
开发者ID:Wikidata,项目名称:soweego,代码行数:25,代码来源:api_requests.py

示例12: _send_response

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def _send_response(response_url, response_body):
    try:
        json_response_body = json.dumps(response_body)
    except Exception as e:
        msg = "Failed to convert response to json: {}".format(str(e))
        logger.error(msg, exc_info=True)
        response_body = {'Status': 'FAILED', 'Data': {}, 'Reason': msg}
        json_response_body = json.dumps(response_body)
    logger.debug("CFN response URL: {}".format(response_url))
    logger.debug(json_response_body)
    headers = {'content-type': '', 'content-length': str(len(json_response_body))}
    split_url = urlsplit(response_url)
    host = split_url.netloc
    url = urlunsplit(("", "", *split_url[2:]))
    while True:
        try:
            connection = HTTPSConnection(host)
            connection.request(method="PUT", url=url, body=json_response_body, headers=headers)
            response = connection.getresponse()
            logger.info("CloudFormation returned status code: {}".format(response.reason))
            break
        except Exception as e:
            logger.error("Unexpected failure sending response to CloudFormation {}".format(e), exc_info=True)
            time.sleep(5) 
开发者ID:aws-cloudformation,项目名称:custom-resource-helper,代码行数:26,代码来源:utils.py

示例13: smart_urlquote

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def smart_urlquote(url):
    "Quotes a URL if it isn't already quoted."
    # Handle IDN before quoting.
    scheme, netloc, path, query, fragment = urlsplit(url)
    try:
        netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
    except UnicodeError: # invalid domain part
        pass
    else:
        url = urlunsplit((scheme, netloc, path, query, fragment))

    url = unquote(force_str(url))
    # See http://bugs.python.org/issue2637
    url = quote(url, safe=b'!*\'();:@&=+$,/?#[]~')

    return force_text(url) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:18,代码来源:html.py

示例14: __call__

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def __call__(self, value):
        try:
            super(URLValidator, self).__call__(value)
        except ValidationError as e:
            # Trivial case failed. Try for possible IDN domain
            if value:
                value = force_text(value)
                scheme, netloc, path, query, fragment = urlsplit(value)
                try:
                    netloc = netloc.encode('idna').decode('ascii')  # IDN -> ACE
                except UnicodeError:  # invalid domain part
                    raise e
                url = urlunsplit((scheme, netloc, path, query, fragment))
                super(URLValidator, self).__call__(url)
            else:
                raise
        else:
            url = value 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:validators.py

示例15: compress

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlunsplit [as 别名]
def compress(self, data_list):
        user = quote_plus(data_list[1])
        passwd = quote_plus(data_list[2])
        auth = user
        if passwd:
            auth += ':'
            auth += passwd
        parsed = urlsplit(data_list[0])
        if auth:
            host = auth + '@' + parsed.netloc
            return urlunsplit((
                parsed.scheme,
                host,
                parsed.path,
                parsed.query,
                parsed.fragment
            ))
        return parsed.url 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:20,代码来源:forms.py


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