Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-09 Thread Rand Dvorak
Yep, that’s it. Just for posterity here’s the successful proof of concept. import objc from Foundation import NSLog, NSRunLoop CRApplication = objc.lookUpClass("CRApplication") objc.registerMetaDataForSelector( b'CRRouter', b'get:block:', { 'arguments': {

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-09 Thread Ronald Oussoren via Pythonmac-SIG
> On 9 Jan 2020, at 00:23, Rand Dvorak wrote: > > I got it working. Basically I have a main.py file in Resources that get > loaded and run by PyRun_SimpleFile in applicationDidFinishLaunching. Control > is then passed to the python interpreter. Notice the infinite loop at the > bottom whic

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-08 Thread Rand Dvorak
I got it working. Basically I have a main.py file in Resources that get loaded and run by PyRun_SimpleFile in applicationDidFinishLaunching. Control is then passed to the python interpreter. Notice the infinite loop at the bottom which is needed because the interpreter finishes executing the

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-08 Thread Rand Dvorak
Here’s what I’ve got so far. I don’t know much about the metadata, but I did try gen_bridge_metadata to try and decipher it, but I think it doesn’t generate it correctly either. import objc CRApplication = objc.lookUpClass("CRApplication") objc.registerMetaDataForSelector( b'CRHTTPSer

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-08 Thread Ronald Oussoren via Pythonmac-SIG
What is the type of ‘server’? And I just noticed the metadata block is a bit of, the callable is argument 3 instead of 2. Ronald -- On the road, hence brief. > On 8 Jan 2020, at 17:18, Rand Dvorak wrote: > > Same result: > > File "main.py", line 40, in > server.get_block_("/", hel

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-08 Thread Rand Dvorak
Same result: File "main.py", line 40, in server.get_block_("/", helloHandler) TypeError: Argument 3 is a block, but no signature available > On Jan 8, 2020, at 03:20, Ronald Oussoren wrote: > > Please change “get_block_” to “get:block:” in the call to > objc.registerMetadataForSelector

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server : SOLVED

2020-01-08 Thread Rand Dvorak
Turns out the instance of server is indeed a CRHTTPServer, but the class that need the metadata registered is CRRouter. > On Jan 8, 2020, at 15:41, Ronald Oussoren wrote: > > What is the type of ‘server’? > > And I just noticed the metadata block is a bit of, the callable is argument 3 > in

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-08 Thread Rand Dvorak
Same results with this code: import objc CRApplication = objc.lookUpClass("CRApplication") objc.registerMetaDataForSelector( b'CRServer', b'get_block_', { 'arguments': { 2: { 'callable': { 'arguments':

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-08 Thread Ronald Oussoren via Pythonmac-SIG
Please change “get_block_” to “get:block:” in the call to objc.registerMetadataForSelector. Ronald — Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ > On 8 Jan 2020, at 02:04, Rand Dvorak wrote: > > Same results with this code: > > import objc > CRApplication = objc.lookUpCl

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-07 Thread Ronald Oussoren via Pythonmac-SIG
And given de example on https://criollo.io: - The class name is CRServer, not CRApplication - The selector is “get:block:” instead of “get_block:”, which also means the block is argument 3 instead of 2. >> objc.registerMetaDataForSelector( >> b'CRServer', >> b’get:block:', >> { >>

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-07 Thread Ronald Oussoren via Pythonmac-SIG
Hi, You also need to remove the call to objc.selector. With correct metadata “blocks” are callables in Python code. Ronald — Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ > On 6 Jan 2020, at 23:59, Rand Dvorak wrote: > > Same result: > > Updated code: > > import objc > C

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-06 Thread Rand Dvorak
I found the place in the code to try to understand what is happening, but am a little out of my depth In libffi_support.m case _C_ID: if (argtype[1] == '?') { /* Argument is a block */ if (argument == Py_None) {

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-06 Thread Rand Dvorak
Same result: Updated code: import objc CRApplication = objc.lookUpClass("CRApplication") objc.registerMetaDataForSelector( b'CRApplication', b'get_block_', { 'arguments': { 2: { 'callable': { 'argumen

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-06 Thread Ronald Oussoren via Pythonmac-SIG
So much for typing code in Mail.app…. “Retail” should be “retval”. Ronald — Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ > On 6 Jan 2020, at 15:27, Ronald Oussoren via Pythonmac-SIG > wrote: > > > >> On 6 Jan 2020, at 00:51, Rand Dvorak wrote: >> >> >> I am trying to

Re: [Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-06 Thread Ronald Oussoren via Pythonmac-SIG
> On 6 Jan 2020, at 00:51, Rand Dvorak wrote: > > > I am trying to implement a simple server in PyObjC for the Criollo HTTP > server. The server has a method to set route handlers by passing a block to > setup the route and then when it receives and HTTP request for the route it > calls th

[Pythonmac-SIG] PyObjC and Criollo HTTP server

2020-01-05 Thread Rand Dvorak
I am trying to implement a simple server in PyObjC for the Criollo HTTP server. The server has a method to set route handlers by passing a block to setup the route and then when it receives and HTTP request for the route it calls the block. The block has the signature: typedef void(^CRRouteB