Re: A sophisticated g_file resolve
- From: Alexander Larsson <alexl redhat com>
- To: David Versmisse <david versmisse itaapy com>
- Cc: gvfs-list gnome org
- Subject: Re: A sophisticated g_file resolve
- Date: Fri, 24 Apr 2009 09:40:25 +0200
On Wed, 2009-04-22 at 15:25 +0200, David Versmisse wrote:
> Hello,
>
> I use gio via its Python's wrapper.
>
> To manage simply all our URIs, i wrote this function:
>
> class Folder
> ....
>
> def _get_g_file(self, uri):
> if type(uri) is not str:
> raise TypeError, 'unexpected "%s"' % repr(uri)
> if self._folder is None:
> return File(uri)
>
> return self._folder.resolve_relative_path(uri)
>
> self._folder can be None => a new File with the given "uri"
> or can be a File => we must resolve the uri to it.
>
> The problem that "uri" can be an absolute path, a relative path or an
> URI.
> resolve_relative_path(uri) doesn't work with by example:
> "file:///toto/tutu/".
>
> How can i resolve my problem?
> Do you plan to implement a resolve_path_or_uri function ?
> Does this function already exists ?
In general it is not possible to do this. The basic problem is that
given a string of unknown type like "file:///foo/Bar" is both a valid
uri and a valid relative path.
So, any function like this would be a heuristic that you couldn't rely
on 100%. However, if you want to implement something like this the best
approach is probably to use the g_uri_parse_scheme() function on the
string, and if that returns non-null assume its a uri, otherwise use
resolve_relative_path.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]