Python urlparse.urlsplit() Examples

The following are 30 code examples of urlparse.urlsplit(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module urlparse , or try the search function .
Example #1
Source File: option.py    From vulscan with MIT License 6 votes vote down vote up
def _setHTTPProxy():
    """
    Check and set the HTTP/SOCKS proxy for all HTTP requests.
    """

    if not conf.proxy:
        return

    infoMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
    logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)

    try:
        _ = urlparse.urlsplit(conf.proxy)
    except Exception, ex:
        errMsg = "invalid proxy address '%s' ('%s')" % (conf.proxy, ex)
        raise PocsuiteSyntaxException(errMsg) 
Example #2
Source File: test_urlparse.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_attributes_without_netloc(self):
        # This example is straight from RFC 3261.  It looks like it
        # should allow the username, hostname, and port to be filled
        # in, but doesn't.  Since it's a URI and doesn't use the
        # scheme://netloc syntax, the netloc and related attributes
        # should be left empty.
        uri = "sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15"
        p = urlparse.urlsplit(uri)
        self.assertEqual(p.netloc, "")
        self.assertEqual(p.username, None)
        self.assertEqual(p.password, None)
        self.assertEqual(p.hostname, None)
        self.assertEqual(p.port, None)
        self.assertEqual(p.geturl(), uri)

        p = urlparse.urlparse(uri)
        self.assertEqual(p.netloc, "")
        self.assertEqual(p.username, None)
        self.assertEqual(p.password, None)
        self.assertEqual(p.hostname, None)
        self.assertEqual(p.port, None)
        self.assertEqual(p.geturl(), uri) 
Example #3
Source File: bulkloader.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def _GetRemoteAppId(url, throttle, email, passin,
                    raw_input_fn=raw_input, password_input_fn=getpass.getpass,
                    throttle_class=None):
  """Get the App ID from the remote server."""
  scheme, host_port, url_path, _, _ = urlparse.urlsplit(url)

  secure = (scheme == 'https')

  throttled_rpc_server_factory = (
      remote_api_throttle.ThrottledHttpRpcServerFactory(
            throttle, throttle_class=throttle_class))

  def AuthFunction():
    return _AuthFunction(host_port, email, passin, raw_input_fn,
                         password_input_fn)

  app_id, server = remote_api_stub.GetRemoteAppId(
      host_port, url_path, AuthFunction,
      rpc_server_factory=throttled_rpc_server_factory, secure=secure)

  return app_id, server 
Example #4
Source File: fixture.py    From mishkal with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #5
Source File: test_urlparse.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_issue14072(self):
        p1 = urlparse.urlsplit('tel:+31-641044153')
        self.assertEqual(p1.scheme, 'tel')
        self.assertEqual(p1.path, '+31-641044153')

        p2 = urlparse.urlsplit('tel:+31641044153')
        self.assertEqual(p2.scheme, 'tel')
        self.assertEqual(p2.path, '+31641044153')

        # Assert for urlparse
        p1 = urlparse.urlparse('tel:+31-641044153')
        self.assertEqual(p1.scheme, 'tel')
        self.assertEqual(p1.path, '+31-641044153')

        p2 = urlparse.urlparse('tel:+31641044153')
        self.assertEqual(p2.scheme, 'tel')
        self.assertEqual(p2.path, '+31641044153') 
Example #6
Source File: urllib2.py    From GDCTSCP with GNU Affero General Public License v3.0 6 votes vote down vote up
def reduce_uri(self, uri, default_port=True):
        """Accept authority or URI and extract only the authority and path."""
        # note HTTP URLs do not have a userinfo component
        parts = urlparse.urlsplit(uri)
        if parts[1]:
            # URI
            scheme = parts[0]
            authority = parts[1]
            path = parts[2] or '/'
        else:
            # host or host:port
            scheme = None
            authority = uri
            path = '/'
        host, port = splitport(authority)
        if default_port and port is None and scheme is not None:
            dport = {"http": 80,
                     "https": 443,
                     }.get(scheme)
            if dport is not None:
                authority = "%s:%d" % (host, dport)
        return authority, path 
Example #7
Source File: yum.py    From atomic-reactor with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def filename(self):
        '''Returns the filename to be used for saving the repo file.

        The filename is derived from the repo url by injecting a suffix
        after the name and before the file extension. This suffix is a
        partial md5 checksum of the full repourl. This avoids multiple
        repos from being written to the same file.
        '''
        urlpath = unquote(urlsplit(self.repourl, allow_fragments=False).path)
        basename = os.path.basename(urlpath)
        if not basename.endswith(REPO_SUFFIX):
            basename += REPO_SUFFIX
        if self.add_hash:
            suffix = '-' + md5(self.repourl.encode('utf-8')).hexdigest()[:5]  # nosec
        else:
            suffix = ''
        final_name = suffix.join(os.path.splitext(basename))
        return final_name 
Example #8
Source File: base.py    From bugatsinho.github.io with GNU General Public License v3.0 6 votes vote down vote up
def unshorten(self, uri, type=None):

        domain = urlsplit(uri).netloc

        if not domain:
            return uri, "No domain found in URI!"

        had_google_outbound, uri = self._clear_google_outbound_proxy(uri)

        if re.search(self._adfly_regex, domain, re.IGNORECASE) or type == 'adfly':
            return self._unshorten_adfly(uri)
        if re.search(self._adfocus_regex, domain, re.IGNORECASE) or type == 'adfocus':
            return self._unshorten_adfocus(uri)
        if re.search(self._linkbucks_regex, domain, re.IGNORECASE) or type == 'linkbucks':
            return self._unshorten_linkbucks(uri)
        if re.search(self._lnxlu_regex, domain, re.IGNORECASE) or type == 'lnxlu':
            return self._unshorten_lnxlu(uri)
        if re.search(self._shst_regex, domain, re.IGNORECASE):
            return self._unshorten_shst(uri)
        if re.search(self._hrefli_regex, domain, re.IGNORECASE):
            return self._unshorten_hrefli(uri)
        if re.search(self._anonymz_regex, domain, re.IGNORECASE):
            return self._unshorten_anonymz(uri)

        return uri, 200 
Example #9
Source File: urllib2.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def reduce_uri(self, uri, default_port=True):
        """Accept authority or URI and extract only the authority and path."""
        # note HTTP URLs do not have a userinfo component
        parts = urlparse.urlsplit(uri)
        if parts[1]:
            # URI
            scheme = parts[0]
            authority = parts[1]
            path = parts[2] or '/'
        else:
            # host or host:port
            scheme = None
            authority = uri
            path = '/'
        host, port = splitport(authority)
        if default_port and port is None and scheme is not None:
            dport = {"http": 80,
                     "https": 443,
                     }.get(scheme)
            if dport is not None:
                authority = "%s:%d" % (host, dport)
        return authority, path 
Example #10
Source File: meta_image.py    From python-hacker with Apache License 2.0 6 votes vote down vote up
def downloadImage(imgTag):
    try:
        print '[+] Downloading image...'
        imgSrc = imgTag['src']
        #将图片的二进制内容读取到变量imgContent中
        imgContent = urllib2.urlopen(imgSrc).read()
        imgFileName = basename(urlsplit(imgSrc)[2])
        imgFile = open(imgFileName, 'wb')
        imgFile.write(imgContent)
        imgFile.close()
        return imgFileName
    except:
        return ''


#检查是否存在GPS,存在则打印出来 
Example #11
Source File: pastee.py    From instavpn with Apache License 2.0 6 votes vote down vote up
def _clean_url(url):
        p = urlparse.urlsplit(url)
        scheme = p[0]
        netloc_split = p[1].split(":")
        hostname = netloc_split[0]
        if len(netloc_split) > 1:
            port = int(netloc_split[1])
        else:
            port = scheme == "https" and 443 or 80
        path = p[2]
        port_str = ""
        if port != 80 and scheme == "http":
            port_str = ":%d" % port
        elif port != 443 and scheme == "https":
            port_str = ":%d" % port
        return "%s://%s%s%s" % (scheme, hostname, port_str, path) 
Example #12
Source File: urllib2.py    From meddle with MIT License 6 votes vote down vote up
def reduce_uri(self, uri, default_port=True):
        """Accept authority or URI and extract only the authority and path."""
        # note HTTP URLs do not have a userinfo component
        parts = urlparse.urlsplit(uri)
        if parts[1]:
            # URI
            scheme = parts[0]
            authority = parts[1]
            path = parts[2] or '/'
        else:
            # host or host:port
            scheme = None
            authority = uri
            path = '/'
        host, port = splitport(authority)
        if default_port and port is None and scheme is not None:
            dport = {"http": 80,
                     "https": 443,
                     }.get(scheme)
            if dport is not None:
                authority = "%s:%d" % (host, dport)
        return authority, path 
Example #13
Source File: model_dictize.py    From daf-recipes with GNU General Public License v3.0 6 votes vote down vote up
def resource_dictize(res, context):
    model = context['model']
    resource = d.table_dictize(res, context)
    extras = resource.pop("extras", None)
    if extras:
        resource.update(extras)
    # some urls do not have the protocol this adds http:// to these
    url = resource['url']
    ## for_edit is only called at the times when the dataset is to be edited
    ## in the frontend. Without for_edit the whole qualified url is returned.
    if resource.get('url_type') == 'upload' and not context.get('for_edit'):
        cleaned_name = munge.munge_filename(url)
        resource['url'] = h.url_for(controller='package',
                                    action='resource_download',
                                    id=resource['package_id'],
                                    resource_id=res.id,
                                    filename=cleaned_name,
                                    qualified=True)
    elif resource['url'] and not urlparse.urlsplit(url).scheme and not context.get('for_edit'):
        resource['url'] = u'http://' + url.lstrip('/')
    return resource 
Example #14
Source File: utils.py    From Yuki-Chan-The-Auto-Pentest with MIT License 5 votes vote down vote up
def ParserUrl(self,url):
		scheme = urlparse.urlsplit(url).scheme
		netloc = urlparse.urlsplit(url).netloc
		path = urlparse.urlsplit(url).path
		query = urlparse.urlsplit(url).query
		if scheme not in ['http','https','']:
			pass
		if netloc == "":
			return("http"+"://"+path)
		else:
			return(scheme+"://"+netloc+path) 
Example #15
Source File: wpseku.py    From ITWSV with MIT License 5 votes vote down vote up
def CheckTarget(self,url):
		scheme = urlparse.urlsplit(url).scheme
		netloc = urlparse.urlsplit(url).netloc
		path = urlparse.urlsplit(url).path
		if scheme not in ['http','https','']:
			sys.exit(self.printf.erro('Schme %s not supported'%(scheme)))
		if netloc == "":
			return "http://"+path
		else:
			return scheme+"://"+netloc+path 
Example #16
Source File: routing.py    From kodi-plugin-routing with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, base_url=None):
        self._rules = {}  # function to list of rules
        if sys.argv:
            self.path = urlsplit(sys.argv[0]).path or '/'
        else:
            self.path = '/'
        if len(sys.argv) > 1 and sys.argv[1].isdigit():
            self.handle = int(sys.argv[1])
        else:
            self.handle = -1
        self.args = {}
        self.base_url = base_url
        if self.base_url is None:
            self.base_url = "plugin://" + xbmcaddon.Addon().getAddonInfo('id') 
Example #17
Source File: utils.py    From ITWSV with MIT License 5 votes vote down vote up
def ParserUrl(self,url):
		scheme = urlparse.urlsplit(url).scheme
		netloc = urlparse.urlsplit(url).netloc
		path = urlparse.urlsplit(url).path
		query = urlparse.urlsplit(url).query
		if scheme not in ['http','https','']:
			pass
		if netloc == "":
			return("http"+"://"+path)
		else:
			return(scheme+"://"+netloc+path) 
Example #18
Source File: humblebundle.py    From humblebundle with GNU General Public License v3.0 5 votes vote down vote up
def _download_basename(self, d):
        basename = osp.basename(urlsplit(d.get('url', {}).get('web', "")).path)
        return basename 
Example #19
Source File: routing.py    From kodi-plugin-routing with GNU General Public License v3.0 5 votes vote down vote up
def match(self, path):
        """
        Check if path matches this rule. Returns a dictionary of the extracted
        arguments if match, otherwise None.
        """
        # match = self._regex.search(urlsplit(path).path)
        match = self._regex.search(path)
        return match.groupdict() if match else None 
Example #20
Source File: cookielib.py    From BinderFilter with MIT License 5 votes vote down vote up
def request_path(request):
    """Path component of request-URI, as defined by RFC 2965."""
    url = request.get_full_url()
    parts = urlparse.urlsplit(url)
    path = escape_path(parts.path)
    if not path.startswith("/"):
        # fix bad RFC 2396 absoluteURI
        path = "/" + path
    return path 
Example #21
Source File: test_requestor.py    From pledgeservice with Apache License 2.0 5 votes vote down vote up
def __eq__(self, other):
        other_parts = urlparse.urlsplit(other)

        for part in ('scheme', 'netloc', 'path', 'fragment'):
            expected = getattr(self.exp_parts, part)
            actual = getattr(other_parts, part)
            if expected != actual:
                print 'Expected %s "%s" but got "%s"' % (
                    part, expected, actual)
                return False

        q_matcher = QueryMatcher(stripe.util.parse_qsl(self.exp_parts.query))
        return q_matcher == other 
Example #22
Source File: test_urlparse.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_attributes_bad_port(self):
        """Check handling of non-integer ports."""
        p = urlparse.urlsplit("http://www.example.net:foo")
        self.assertEqual(p.netloc, "www.example.net:foo")
        self.assertRaises(ValueError, lambda: p.port)

        p = urlparse.urlparse("http://www.example.net:foo")
        self.assertEqual(p.netloc, "www.example.net:foo")
        self.assertRaises(ValueError, lambda: p.port) 
Example #23
Source File: test_urlparse.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_http_roundtrips(self):
        # urlparse.urlsplit treats 'http:' as an optimized special case,
        # so we test both 'http:' and 'https:' in all the following.
        # Three cheers for white box knowledge!
        testcases = [
            ('://www.python.org',
             ('www.python.org', '', '', '', ''),
             ('www.python.org', '', '', '')),
            ('://www.python.org#abc',
             ('www.python.org', '', '', '', 'abc'),
             ('www.python.org', '', '', 'abc')),
            ('://www.python.org?q=abc',
             ('www.python.org', '', '', 'q=abc', ''),
             ('www.python.org', '', 'q=abc', '')),
            ('://www.python.org/#abc',
             ('www.python.org', '/', '', '', 'abc'),
             ('www.python.org', '/', '', 'abc')),
            ('://a/b/c/d;p?q#f',
             ('a', '/b/c/d', 'p', 'q', 'f'),
             ('a', '/b/c/d;p', 'q', 'f')),
            ]
        for scheme in ('http', 'https'):
            for url, parsed, split in testcases:
                url = scheme + url
                parsed = (scheme,) + parsed
                split = (scheme,) + split
                self.checkRoundtrips(url, parsed, split) 
Example #24
Source File: cookielib.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def request_path(request):
    """Path component of request-URI, as defined by RFC 2965."""
    url = request.get_full_url()
    parts = urlparse.urlsplit(url)
    path = escape_path(parts.path)
    if not path.startswith("/"):
        # fix bad RFC 2396 absoluteURI
        path = "/" + path
    return path 
Example #25
Source File: link.py    From poetry with MIT License 5 votes vote down vote up
def url_without_fragment(self):
        scheme, netloc, path, query, fragment = urlparse.urlsplit(self.url)
        return urlparse.urlunsplit((scheme, netloc, path, query, None)) 
Example #26
Source File: link.py    From poetry with MIT License 5 votes vote down vote up
def path(self):
        return urlparse.unquote(urlparse.urlsplit(self.url)[2]) 
Example #27
Source File: link.py    From poetry with MIT License 5 votes vote down vote up
def netloc(self):
        return urlparse.urlsplit(self.url)[1] 
Example #28
Source File: link.py    From poetry with MIT License 5 votes vote down vote up
def scheme(self):
        return urlparse.urlsplit(self.url)[0] 
Example #29
Source File: __init__.py    From misp42splunk with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 
Example #30
Source File: link.py    From poetry with MIT License 5 votes vote down vote up
def filename(self):
        _, netloc, path, _, _ = urlparse.urlsplit(self.url)
        name = posixpath.basename(path.rstrip("/")) or netloc
        name = urlparse.unquote(name)
        assert name, "URL %r produced no filename" % self.url
        return name