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': {
                3: { 'callable': {
                        'arguments': {
                        0:{'type': b'^v'},
                        1:{'type': b'@'},
                        2:{'type': b'@'},
                        3:{'type': b'@'}
                        },
                '       retval': { 'type': b'v' }
                        }
                   }
                }
        }
)
objc.registerMetaDataForSelector(
        b'CRRouter',
        b'add:block:',
        {
        'arguments': {
                3: { 'callable': {
                        'arguments': {
                        0:{'type': b'^v'},
                        1:{'type': b'@'},
                        2:{'type': b'@'},
                        3:{'type': b'@'}
                        },
                '       retval': { 'type': b'v' }
                        }
                   }
                }
        }
)

global server

def helloHandler(request, response, handler):
        NSLog("%@ %@ %@", request, response, handler)
        response.send_("Hello World!")
        handler()

def completionHandler(request, response, handler):
        NSLog("Completion handler called")

if __name__ == "__main__":
        server = CRApplication.sharedApplication().delegate().server()
        NSLog("Server: %@", server)
        server.get_block_("/", helloHandler)
        server.add_block_("/", completionHandler)
        NSLog("Started...")
        listening = server.startListening()
        NSRunLoop.currentRunLoop().run()


> On Jan 9, 2020, at 04:18, Ronald Oussoren <ronaldousso...@mac.com> wrote:
> 
> 
>> On 9 Jan 2020, at 00:23, Rand Dvorak <randdvo...@gmail.com 
>> <mailto:randdvo...@gmail.com>> 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 which is needed because the interpreter finishes executing the 
>> file and exits.  It is needed to keep the python interpreter alive.  I need 
>> a better solution to keep the interpreter alive because this eats up too 
>> much cpu. It was just a hack to prove that is what was happening.
> 
> I’ve quickly scanned 
> https://github.com/thecatalinstan/Criollo/wiki/Getting-Started 
> <https://github.com/thecatalinstan/Criollo/wiki/Getting-Started> and that 
> seems to indicate that the webserver integrates with the regular Cocoa event 
> loop. That means you’ll probably need to run the NSRunloop or CFRunloop.
> 
> Ronald
> —
> 
> Twitter: @ronaldoussoren
> Blog: https://blog.ronaldoussoren.net/ <https://blog.ronaldoussoren.net/>
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
https://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to