Exemple #1
0
def urlparse(url):
    """
    Parse an URL into six components.

    This is similar to L{urlparse.urlparse}, but rejects C{unicode} input
    and always produces C{str} output.

    @type url: C{str}

    @raise TypeError: The given url was a C{unicode} string instead of a
    C{str}.

    @rtype: six-tuple of str
    @return: The scheme, net location, path, params, query string, and fragment
    of the URL.
    """
    if isinstance(url, unicode):
        raise TypeError("url must be str, not unicode")
    scheme, netloc, path, params, query, fragment = _urlparse(url)
    if isinstance(scheme, unicode):
        scheme = scheme.encode('ascii')
        netloc = netloc.encode('ascii')
        path = path.encode('ascii')
        query = query.encode('ascii')
        fragment = fragment.encode('ascii')
    return scheme, netloc, path, params, query, fragment
Exemple #2
0
def urlparse(url):
    """
    Parse an URL into six components.

    This is similar to L{urlparse.urlparse}, but rejects C{unicode} input
    and always produces C{str} output.

    @type url: C{str}

    @raise TypeError: The given url was a C{unicode} string instead of a
    C{str}.

    @rtype: six-tuple of str
    @return: The scheme, net location, path, params, query string, and fragment
    of the URL.
    """
    if isinstance(url, unicode):
        raise TypeError("url must be str, not unicode")
    scheme, netloc, path, params, query, fragment = _urlparse(url)
    if isinstance(scheme, unicode):
        scheme = scheme.encode('ascii')
        netloc = netloc.encode('ascii')
        path = path.encode('ascii')
        query = query.encode('ascii')
        fragment = fragment.encode('ascii')
    return scheme, netloc, path, params, query, fragment
Exemple #3
0
def test_urlparse():
	urldata = {'url1': 'http://env1.test', 'url2': 'ftp://env2.test'}

	parseddata = env.urlparse(urldata)

	yield compare_values, len(parseddata), len(urldata)

	for item in urldata:
		yield compare_values, _urlparse(urldata[item]), parseddata[item]
Exemple #4
0
def test_urlparse():
    urldata = {'url1': 'http://env1.test', 'url2': 'ftp://env2.test'}

    parseddata = env.urlparse(urldata)

    assert len(parseddata) == len(urldata)

    for item in urldata:
        assert _urlparse(urldata[item]) == parseddata[item]
Exemple #5
0
    def _parts_mother_id_typename(cls, url):
        """
		>>> murl = "qpfer://mother/qfid#module_and_type_hint"
		>>> qfurl._parts_mother_id_typename(murl)
		('mother', 'qfid', 'module_and_type_hint')
		"""
        scheme, mother, qfid, _ign, _ore, typname = _urlparse(url)
        if scheme != QFURL_SCHEME:
            raise QfurlError("Wrong scheme: %s" % scheme)
        qfid = qfid.lstrip("/")
        return mother, qfid, typname
Exemple #6
0
	def _parts_mother_id_typename(cls, url):
		"""
		>>> murl = "qpfer://mother/qfid#module_and_type_hint"
		>>> qfurl._parts_mother_id_typename(murl)
		('mother', 'qfid', 'module_and_type_hint')
		"""
		scheme, mother, qfid, _ign, _ore, typname = _urlparse(url)
		if scheme != QFURL_SCHEME:
			raise QfurlError("Wrong scheme: %s" % scheme)
		qfid = qfid.lstrip("/")
		return mother, qfid, typname
Exemple #7
0
def urlparse(d, keys=None):
    """Returns a copy of the given dictionary with url values parsed."""

    d = d.copy()

    if keys is None:
        keys = d.keys()

    for key in keys:
        d[key] = _urlparse(d[key])

    return d
Exemple #8
0
def urlparse(d, keys=None):
    """Returns a copy of the given dictionary with url values parsed."""

    d = d.copy()

    if keys is None:
        keys = d.keys()

    for key in keys:
        d[key] = _urlparse(d[key])

    return d
Exemple #9
0
    def open(self, url, tab=False):
        '''Open a new window or tab in the browser.

           @param url: The URL to open (C{str}).
           @keyword tab: New tab (C{bool}), new window otherwise.

           @return: Parsed I{url} as C{ParseResult}.

           @raise ValueError: Scheme of I{url} not 'http', 'https' or 'file'.
        '''
        ns = url2NS(url)
        sc = nsString2str(ns.scheme())
        if sc.lower() not in ('http', 'https', 'file'):
            raise ValueError('%s scheme %r invalid: %r' % ('url', sc, url))
        if self._browser:
            self._browser.open(url, new=2 if tab else 1)
        elif self.NS:
            d = dict2NS(dict(URL=ns, reveal=True, newTab=bool(tab)), frozen=True)
            u = NSStr('WebBrowserOpenURLNotification')
            self.NS.postNotificationName_object_userInfo_(u, None, d)
            u.release()  # PYCHOK expected
        return _urlparse(nsString2str(ns.absoluteString()))
Exemple #10
0
def urlparse(url):
    parsed = _urlparse(url)
    if not hasattr(parsed, 'scheme'):
        parsed = ParsedUrl(parsed)
    return parsed
Exemple #11
0
 def urlparse( uri):
     return _urlparse( uri)[2:]    #ignore scheme,netloc