[Pythonmac-SIG] PyObjC and Criollo HTTP server

Rand Dvorak randdvorak at gmail.com
Sun Jan 5 18:51:32 EST 2020


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(^CRRouteBlock)(CRRequest* _Nonnull request, CRResponse* _Nonnull response, CRRouteCompletionBlock _Nonnull completionHandler);


So, here is my simple proof of concept:

import objc 
CRApplication = objc.lookUpClass("CRApplication")
global server

def helloHandler(self, request, response, handler):
	response.send_("Hello World!")
	handler()
	
if __name__ == "__main__":
	server = CRApplication.sharedApplication().delegate().server()
	server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@‘))  *** error occurs here
	server.startListening()


But, when I try to setup the route I get the following error:

Traceback (most recent call last):
  File "main.py", line 21, in <module>
    server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@'))
TypeError: Argument 3 is a block, but no signature available


Any ideas how to workaround this issue and implement the route handlers in PyObjC?


More information about the Pythonmac-SIG mailing list