예제 #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
예제 #2
0
파일: http.py 프로젝트: kusoof/wprof
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
예제 #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]
예제 #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]
예제 #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
예제 #6
0
파일: qfurl.py 프로젝트: chmouel/kupfer
	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
예제 #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
예제 #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
예제 #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()))
예제 #10
0
def urlparse(url):
    parsed = _urlparse(url)
    if not hasattr(parsed, 'scheme'):
        parsed = ParsedUrl(parsed)
    return parsed
예제 #11
0
 def urlparse( uri):
     return _urlparse( uri)[2:]    #ignore scheme,netloc