Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'source.': 0.05; 'transform': 0.05; 'except:': 0.07; 'try:': 0.07; 'api': 0.09; 'python': 0.09; 'okay': 0.09; 'python:': 0.09; 'def': 0.10; 'commit': 0.15; 'slightly': 0.15; '`path`': 0.16; 'anymore': 0.16; 'belongs': 0.16; 'folks,': 0.16; 'nevertheless': 0.16; 'skip:g 50': 0.16; 'url:gnome': 0.16; 'url:urllib': 0.16; 'thanks,': 0.18; 'module': 0.19; 'written': 0.20; 'assuming': 0.22; 'ctypes': 0.22; 'exceptions': 0.22; 'latter': 0.22; 'defined': 0.22; 'cheers,': 0.23; 'work.': 0.23; '(you': 0.23; 'seems': 0.23; 'header': 0.24; 'specifically': 0.24; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; 'checking': 0.27; 'realize': 0.27; 'topic': 0.27; 'is?': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chase': 0.29; 'idea,': 0.29; 'implied': 0.29; 'source': 0.29; 'probably': 0.29; 'maybe': 0.29; 'related': 0.30; 'that.': 0.30; 'daniel': 0.30; 'function': 0.30; 'stuff': 0.30; 'url:python': 0.32; 'could': 0.32; 'docs': 0.33; 'function.': 0.33; 'turns': 0.33; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'likely': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'done': 0.34; 'list': 0.35; 'exist': 0.35; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'skip:g 30': 0.36; 'totally': 0.36; 'url:library': 0.36; 'anything': 0.36; 'should': 0.36; 'enough': 0.36; 'does': 0.37; 'uses': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'things': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'url:mail': 0.40; 'skip:u 10': 0.60; 'more': 0.63; 'great': 0.64; 'hoping': 0.72; 'down!': 0.84; 'presumably': 0.84; 'to:name:python': 0.84; 'lift': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=rSZBKVZIjigVGwSMUrwqx82aRDZXG6kDtcwS4sdRNOs=; b=d1Yom1VSaveq3iVzPcpdQwa0ymTwm9RZ0b7Up5w/GNqZm4Va9GosM0UvUysjczCIfF V0vY2JDLM8sqshl60TskLbE2sw1xiFKLF2SeRgJviwcLgingHo2F0oR2JLdrf1AvAPH4 atPMCrAV15KS/yTEe0o6WbyLIQgeb2caQZ22piJ6Jddcs8X1UgFgobDI2CDS8pab5iqb bxTMJBxzFSv1a7JNXTLKGbaxiWCjA6lVGggH/YYB8L8RklZJOANSic21JvLuuGxppuk8 QnYDc6mnpfdsF5HfdIIfZ2vViEBTPpqElODygQmLXWlBsxSkFUkMhKmBApiRR4v/t9Cv gY6Q== MIME-Version: 1.0 In-Reply-To: References: Date: Sat, 22 Dec 2012 16:01:33 +0100 Subject: Re: pygnomevfs get_local_path_from_uri replacement From: Daniel Fetchinson To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356188502 news.xs4all.nl 6840 [2001:888:2000:d::a6]:54091 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35366 >> Hi folks, I realize this is slightly off topic and maybe belongs to a >> gnome email list but it's nevertheless python: >> >> I use an old python program that was written for gnome 2 and gtk 2 and >> uses the function get_local_path_from_uri. More specifically it uses >> gnomevfs.get_local_path_from_uri. >> >> Now with gnome 3 the module pygnomevfs does not exist anymore and >> after checking the source for pygnomevfs it turns out it's written in >> C using all the header files and stuff from gnome 2. So I can't just >> lift it from the source. I was hoping it's pure python in which case I >> could have simply lifted it. >> >> Does anyone know what a good replacement for get_local_path_from_uri >> is? Is there a gtk/gnome/etc related python package that contains it >> which would work with gnome 3? Or a totally gnome-independent python >> implementation? > > The commit > https://mail.gnome.org/archives/commits-list/2009-May/msg05733.html > suggests that get_local_path_from_uri() might have been defined as > (taking slight liberties): > gnome_vfs_unescape_string(remove_host_from_uri(uri)) > Assuming these functions do the "obvious" things implied by their > names (you can probably chase down the Gnome VFS source or docs to > check; I don't care enough to bother), given a general URI > "protocol://host/path", it presumably returns either > "protocol:///path" (`protocol:` likely being "file:" in this case) or > "/path", in either case with `path` having been un-percent-escaped. > The latter transform can be done using > http://docs.python.org/2/library/urllib.html#urllib.unquote > > Alternately, you might call the Gnome VFS C API directly via > http://docs.python.org/2/library/ctypes.html Thanks, ctypes is actually a great idea, I should have thought about that. In the meantime I use the simple function def get_local_path_from_uri( uri ): return uri.split( '//' )[1] and it seems to work. In the program the function is always called in a try: except: block so if anything is not okay it will get caught, I don't have to catch exceptions inside the function. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown