Ejemplo n.º 1
0
	def testFunctions(self):
		smb_urls = (
			('smb://MyHost.local/share/My%20Documents', r'\\MyHost.local\share\My Documents'),
		)
		for url, share in smb_urls:
			if os.name == 'nt':
				self.assertEqual(normalize_win32_share(share), share)
				self.assertEqual(normalize_win32_share(url), share)
			else:
				self.assertEqual(normalize_win32_share(share), url)
				self.assertEqual(normalize_win32_share(url), url)
Ejemplo n.º 2
0
def open_url(widget, url):
    '''Open an URL (or URI) in the web browser or other relevant
	program. The application is determined based on the URL / URI
	scheme. Unkown schemes and "file://" URIs are opened with the
	webbrowser.
	@param widget: parent for new dialogs, C{Gtk.Widget} or C{None}
	@param url: an URL or URI as string
	'''
    logger.debug('open_url(%s)', url)
    assert isinstance(url, str)

    if is_win32_share_re.match(url):
        url = normalize_win32_share(url)
        if os.name == 'nt':
            return _open_with_filebrowser(widget, url)
        # else consider as a x-scheme-handler/smb type URI below
    elif is_www_link_re.match(url):
        url = 'http://' + url
    elif not is_uri_re.match(url):
        raise ValueError('Not an URL: %s' % url)
    else:
        pass

    if url.startswith('file:/'):
        # Special case, force to browser (and not use open_file())
        # even though the result may be the same if the browser is
        # dispatched through xdg-open, gnome-open, ...)
        _open_with_webbrowser(widget, url)
    elif url.startswith('outlook:') and hasattr(os, 'startfile'):
        # Special case for outlook folder paths on windows
        os.startfile(url)
    else:
        from zim.gui.applications import get_mimetype
        manager = ApplicationManager()
        type = get_mimetype(
            url)  # Supports "x-scheme-handler/... for URL schemes"
        logger.debug('Got type "%s" for "%s"', type, url)
        entry = manager.get_default_application(type)
        if entry:
            _open_with(widget, entry, url)
        elif url.startswith('mailto:'):
            _open_with_emailclient(widget, url)
        else:
            _open_with_webbrowser(widget, url)