[Pythonmac-SIG] [patch] GetURL argv emulation for py2app 0.5.2

Ronald Oussoren ronaldoussoren at mac.com
Sat Mar 12 15:30:52 CET 2011


On 12 Mar, 2011, at 6:36, Brendan Simon (eTRIX) wrote:

> On 12/03/11 10:00 PM, pythonmac-sig-request at python.org wrote:
>> 
>> On 10 Mar, 2011, at 18:04, Brendan Simon (eTRIX) wrote:
>>> > Below is my patch to get URLs/URIs to be added to sys.argv when an app
>>> > is opened via the Launcher.
>>> > 
>>> > It should be applied to:
>>> > 
>>> > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app/bootstrap/argv_emulation.py
>>> > 
>>> > Can this patch *please* be integrated (please modify if necessary) in to
>>> > 0.5.3 release !!
>> Which OS release are you on? I've tried to test with python 2.5 and 2.7 on OSX 10.6 and those seem to work fine without your patch (even with the lowercase values you mention furtheron).
>> 
>> My test has a simple main.py script that saves sys.argv in a text file. When I add that file to an application bundle with py2app and then start the bundle with 'open -a dist/myapp.app file:/usr/bin/ssh' the saved argv contains the file to open. As code says more than my description I've attached the unittest testcase I've tried.
>> 
>> Is this test testing the failure your reporting or did I misread your message?
> 
> I am running on OS 10.6, but my app needs to run on 10.4, 10.5 and 10.6 (PPC and Intel).
> I am using Python 2.5.4.
> 
> I don't think your test would work if you were to use a custom url, rather than 'file:' and a filename/path.
> 
> If I ran the command "open myurl:mycommand" from the terminal, and my plist has configured 'myurl' as a recognised url, then the app bundle should fire up.  It may need to be in the Application folder for it to work ??
> 
> I expect 'myurl:mycommand' to be appended to sys.argv.
> 
> Here is a snippet of my py2app setup.py.
> 
> # A custom plist for letting it associate with a URL protocol.
> URLTYPES = [
>              {
>                'CFBundleURLName' : "MyUrl",
>                'CFBundleURLSchemes' : [ "myurl" ]
>              }
>            ]
> 
> Plist = dict(
>                 NSAppleScriptEnabled = 'YES',
>                 CFBundleIdentifier = 'com.myurl',
>                 LSMinimumSystemVersion = "10.4",
>                 CFBundleURLTypes = URLTYPES
>             )
> 
> OPTIONS = {
>             'argv_emulation' : True,
>             'iconfile' : 'images/myurl.icns',
>             'plist' : Plist,
>            }
> 
> Hope that helps,

It sure does, this helped me to reproduce the issue.  I've added another 

>From your original e-mail:

> +        def __geturl(self, requestevent, replyevent):
> +            try:
> +                listdesc = requestevent.AEGetParamDesc(keyDirectObject,
> typeAEList)
> +                for i in range(listdesc.AECountItems()):
> +                    desc = listdesc.AEGetNthDesc(i+1, typeChar)[1]
> +                    url = desc.data.decode('utf8')

Is the decode really necessary? With this one of the times in sys.argv will be a Unicode string rather than a byte string. I'd therefore prefer to not have the decode call.

I've added your patch without the decode call to my repository, including some tests that ensure that future versions won't accidently break the code.

Thank you for the patch,

Ronald

> +                    sys.argv.append(url)
> +            except Exception, e:
> +                print "argvemulator.py warning: can't unpack a GetURL
> event"
> +                import traceback
> +                traceback.print_exc()
> +



> Brendan.
> 
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20110312/2c3555d8/attachment.html>


More information about the Pythonmac-SIG mailing list