當前位置: 首頁>>代碼示例>>Python>>正文


Python urlparse.urlunsplit方法代碼示例

本文整理匯總了Python中urlparse.urlunsplit方法的典型用法代碼示例。如果您正苦於以下問題:Python urlparse.urlunsplit方法的具體用法?Python urlparse.urlunsplit怎麽用?Python urlparse.urlunsplit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urlparse的用法示例。


在下文中一共展示了urlparse.urlunsplit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validate_

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse 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: goto

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def goto(self, href, method='get', **args):
        """
        Go to the (potentially relative) link ``href``, using the
        given method (``'get'`` or ``'post'``) and any extra arguments
        you want to pass to the ``app.get()`` or ``app.post()``
        methods.

        All hostnames and schemes will be ignored.
        """
        scheme, host, path, query, fragment = urlparse.urlsplit(href)
        # We
        scheme = host = fragment = ''
        href = urlparse.urlunsplit((scheme, host, path, query, fragment))
        href = urlparse.urljoin(self.request.full_url, href)
        method = method.lower()
        assert method in ('get', 'post'), (
            'Only "get" or "post" are allowed for method (you gave %r)'
            % method)
        if method == 'get':
            method = self.test_app.get
        else:
            method = self.test_app.post
        return method(href, **args) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:25,代碼來源:fixture.py

示例3: _convert_to_idn

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def _convert_to_idn(url):
    """Convert a URL to IDN notation"""
    # this function should only be called with a unicode string
    # strategy: if the host cannot be encoded in ascii, then
    # it'll be necessary to encode it in idn form
    parts = list(urlparse.urlsplit(url))
    try:
        parts[1].encode('ascii')
    except UnicodeEncodeError:
        # the url needs to be converted to idn notation
        host = parts[1].rsplit(':', 1)
        newhost = []
        port = u''
        if len(host) == 2:
            port = host.pop()
        for h in host[0].split('.'):
            newhost.append(h.encode('idna').decode('utf-8'))
        parts[1] = '.'.join(newhost)
        if port:
            parts[1] += ':' + port
        return urlparse.urlunsplit(parts)
    else:
        return url 
開發者ID:liantian-cn,項目名稱:RSSNewsGAE,代碼行數:25,代碼來源:feedparser.py

示例4: url_fix

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def url_fix(s, charset='utf-8'):
    '''
    Sometimes you get an URL by a user that just isn't a real
    URL because it contains unsafe characters like ' ' and so on.  This
    function can fix some of the problems in a similar way browsers
    handle data entered by the user:

    >>> url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)')
    'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29'

    :param s: Url address.
    :type s: string
    :param charset: The target charset for the URL if the url was
                    given as unicode string. Default is 'utf-8'.
    :type charset: string
    :rtype: string
                    
    (taken from `werkzeug.utils <http://werkzeug.pocoo.org/docs/utils/>`_)
    '''
    if sys.version_info < (3, 0) and isinstance(s, unicode):
        s = s.encode(charset, 'ignore')
    scheme, netloc, path, qs, anchor = urlparse.urlsplit(s)
    path = urllib.quote(path, '/%')
    qs = urllib.quote_plus(qs, ':&=')
    return urlparse.urlunsplit((scheme, netloc, path, qs, anchor)) 
開發者ID:KanoComputing,項目名稱:kano-burners,代碼行數:27,代碼來源:utils.py

示例5: generate_docservice_url

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def generate_docservice_url(request, doc_id, temporary=True, prefix=None):
    docservice_key = getattr(request.registry, 'docservice_key', None)
    parsed_url = urlparse(request.registry.docservice_url)
    query = {}
    if temporary:
        expires = int(ttime()) + 300  # EXPIRES
        mess = "{}\0{}".format(doc_id, expires)
        query['Expires'] = expires
    else:
        mess = doc_id
    if prefix:
        mess = '{}/{}'.format(prefix, mess)
        query['Prefix'] = prefix
    query['Signature'] = quote(b64encode(docservice_key.signature(mess.encode("utf-8"))))
    query['KeyID'] = docservice_key.hex_vk()[:8]
    return urlunsplit((parsed_url.scheme, parsed_url.netloc, '/get/{}'.format(doc_id), urlencode(query), '')) 
開發者ID:openprocurement,項目名稱:openprocurement.api,代碼行數:18,代碼來源:utils.py

示例6: audit

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def audit(arg):

    ooO0oooOoO0 = arg
    II11i = urlparse.urlparse(ooO0oooOoO0)
    i1oOOoo00O0O = urlparse.urlunsplit((II11i.scheme, II11i.netloc, II11i.path, "", ""))
    Oo0Ooo = urlparse.parse_qsl(II11i.query)

    i1111 = ['__VIEWSTATE', 'IbtnEnter.x', 'IbtnEnter.y']
    i11 = ["GET", "POST"]

    for I11 in i11:

        for O0O0OO0O0O0, iiiii in Oo0Ooo:
            if O0O0OO0O0O0 in i1111:
                continue

            debug('[XSS] <%s> %s %s', I11, O0O0OO0O0O0, i1oOOoo00O0O)
            Oo0o0000o0o0 = iI1(I11, i1oOOoo00O0O, Oo0Ooo, O0O0OO0O0O0, iiiii)

            if Oo0o0000o0o0:
                security_info('<%s> %s' % (I11, Oo0o0000o0o0[1]))
                return 
開發者ID:w-digital-scanner,項目名稱:w9scan,代碼行數:24,代碼來源:w9_xss.py

示例7: giphy_translate

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def giphy_translate(text):
    """
    Giphy translate method, uses the Giphy API to find an appropriate gif url
    """

    params = {}
    params['s'] = text
    params['rating'] = RATING
    params['api_key'] = GIPHY_API_KEY

    resp = requests.get('https://api.giphy.com/v1/gifs/translate', params=params, verify=True)

    if resp.status_code is not requests.codes.ok:
        print('Encountered error using Giphy API, text=%s, status=%d, response_body=%s' % (text, resp.status_code, resp.json()))
        return ''

    resp_data = resp.json()

    url = list(urlsplit(resp_data['data']['images']['original']['url']))
    url[0] = SCHEME.lower()
    return urlunsplit(url) 
開發者ID:mattermost,項目名稱:mattermost-integration-giphy,代碼行數:23,代碼來源:server.py

示例8: smart_urlquote

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse 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

示例9: __call__

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse 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

示例10: url_fix

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def url_fix(self, charset = 'utf-8'):
        """
        From http://stackoverflow.com/a/121017/854988
        """

        if self.bypass_url_encoding:

            return

        if type(self.url) is bytes:

            self.url = self._bytes_to_unicode(self.url, encoding = charset)

        scheme, netloc, path, qs, anchor = urlparse.urlsplit(self.url)

        if self.force_quote or not self.is_quoted(path):

            path = urllib.quote(path, '/%')

        if self.force_quote or not self.is_quoted_plus(qs):

            qs = urllib.quote_plus(qs, '& = ')

        self.url = urlparse.urlunsplit((scheme, netloc, path, qs, anchor)) 
開發者ID:saezlab,項目名稱:pypath,代碼行數:26,代碼來源:curl.py

示例11: urldefrag

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def urldefrag(url):
    if "#" in url:
        s, n, p, q, frag = urlsplit(url)
        defrag = urlunsplit((s, n, p, q, ''))
    else:
        defrag = url
        frag = ''
    return defrag, frag 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:10,代碼來源:__init__.py

示例12: iri2uri

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def iri2uri(uri):
    """Convert an IRI to a URI. Note that IRIs must be
    passed in a unicode strings. That is, do not utf-8 encode
    the IRI before passing it into the function."""
    if isinstance(uri, unicode):
        (scheme, authority, path, query, fragment) = urlparse.urlsplit(uri)
        authority = authority.encode("idna")
        # For each character in 'ucschar' or 'iprivate'
        #  1. encode as utf-8
        #  2. then %-encode each octet of that utf-8
        uri = urlparse.urlunsplit((scheme, authority, path, query, fragment))
        uri = "".join([encode(c) for c in uri])
    return uri 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:15,代碼來源:iri2uri.py

示例13: iri2uri

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def iri2uri(uri):
    """Convert an IRI to a URI. Note that IRIs must be
    passed in a unicode strings. That is, do not utf-8 encode
    the IRI before passing it into the function."""
    if isinstance(uri ,unicode):
        (scheme, authority, path, query, fragment) = urlparse.urlsplit(uri)
        authority = authority.encode('idna')
        # For each character in 'ucschar' or 'iprivate'
        #  1. encode as utf-8
        #  2. then %-encode each octet of that utf-8
        uri = urlparse.urlunsplit((scheme, authority, path, query, fragment))
        uri = "".join([encode(c) for c in uri])
    return uri 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:15,代碼來源:iri2uri.py

示例14: _build_api_url

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def _build_api_url(url, query):
    scheme, netloc, path, base_query, fragment = urlparse.urlsplit(url)

    if base_query:
        query = '%s&%s' % (base_query, query)

    return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:9,代碼來源:api_requestor.py

示例15: url_without_fragment

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunsplit [as 別名]
def url_without_fragment(self):
        scheme, netloc, path, query, fragment = urlparse.urlsplit(self.url)
        return urlparse.urlunsplit((scheme, netloc, path, query, None)) 
開發者ID:python-poetry,項目名稱:poetry,代碼行數:5,代碼來源:link.py


注:本文中的urlparse.urlunsplit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。