From randdvorak at gmail.com Sun Jan 5 18:51:32 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Sun, 5 Jan 2020 18:51:32 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server Message-ID: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> 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 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? From ronaldoussoren at mac.com Mon Jan 6 09:27:19 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Mon, 6 Jan 2020 15:27:19 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> Message-ID: <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> > 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 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 > 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? The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. import objc objc.registerMetaDataForSelector( b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? b?get_block:?, { ?arguments?: { 2: { ?callable?: { ?arguments?: { 0: { ?type?: b?^v? }, 1: { ?type?: b?@? }, 2: { ?type?: b?@? }, 3: { ?type?: b?@? } }, ?retail?: { ?type?: b?v? } } } } ) This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). Ronald ? Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ > _______________________________________________ > Pythonmac-SIG maillist - Pythonmac-SIG at python.org > https://mail.python.org/mailman/listinfo/pythonmac-sig > unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG From ronaldoussoren at mac.com Mon Jan 6 10:30:41 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Mon, 6 Jan 2020 16:30:41 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> Message-ID: <88131E17-3621-47F6-97F9-1816F3E2633E@mac.com> 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 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 >> 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? > > The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. > > import objc > objc.registerMetaDataForSelector( > b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? > b?get_block:?, > { > ?arguments?: { > 2: { > ?callable?: { > ?arguments?: { > 0: { ?type?: b?^v? }, > 1: { ?type?: b?@? }, > 2: { ?type?: b?@? }, > 3: { ?type?: b?@? } > }, > ?retail?: { ?type?: b?v? } > } > } > } > ) > > This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). > > Ronald > ? > > Twitter: @ronaldoussoren > Blog: https://blog.ronaldoussoren.net/ >> _______________________________________________ >> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >> https://mail.python.org/mailman/listinfo/pythonmac-sig >> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG > > _______________________________________________ > Pythonmac-SIG maillist - Pythonmac-SIG at python.org > https://mail.python.org/mailman/listinfo/pythonmac-sig > unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Mon Jan 6 17:59:21 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Mon, 6 Jan 2020 17:59:21 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> Message-ID: <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> Same result: Updated code: import objc CRApplication = objc.lookUpClass("CRApplication") objc.registerMetaDataForSelector( b'CRApplication', b'get_block_', { 'arguments': { 2: { 'callable': { 'arguments': { 0:{'type': b'^v'}, 1:{'type': b'@'}, 2:{'type': b'@'}, 3:{'type': b'@'} }, ' retval': { 'type': b'v' } } } } } ) 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@:@@@')) server.startListening() results: Traceback (most recent call last): File "main.py", line 37, in server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) TypeError: Argument 3 is a block, but no signature available > On Jan 6, 2020, at 09:27, Ronald Oussoren wrote: > > > >> 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 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 >> 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? > > The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. > > import objc > objc.registerMetaDataForSelector( > b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? > b?get_block:?, > { > ?arguments?: { > 2: { > ?callable?: { > ?arguments?: { > 0: { ?type?: b?^v? }, > 1: { ?type?: b?@? }, > 2: { ?type?: b?@? }, > 3: { ?type?: b?@? } > }, > ?retail?: { ?type?: b?v? } > } > } > } > ) > > This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). > > Ronald > ? > > Twitter: @ronaldoussoren > Blog: https://blog.ronaldoussoren.net/ >> _______________________________________________ >> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >> https://mail.python.org/mailman/listinfo/pythonmac-sig >> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG > -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Mon Jan 6 18:35:16 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Mon, 6 Jan 2020 18:35:16 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> Message-ID: <486849A2-6C6A-40F8-9CE3-F6F1755A4F2C@gmail.com> 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) { argbuf_cur = align(argbuf_cur, PyObjCRT_AlignOfType(argtype)); arg = argbuf + argbuf_cur; argbuf_cur += PyObjCRT_SizeOfType(argtype); PyObjC_Assert(argbuf_cur <= argbuf_len, -1); *(void**)arg = NULL; } else { if (methinfo->argtype[i]->callable == NULL) { PyErr_Format(PyExc_TypeError, "Argument %" PY_FORMAT_SIZE_T "d is a block, but no signature available", i); return -1; } argbuf_cur = align(argbuf_cur, PyObjCRT_AlignOfType(argtype)); arg = argbuf + argbuf_cur; argbuf_cur += PyObjCRT_SizeOfType(argtype); PyObjC_Assert(argbuf_cur <= argbuf_len, -1); *(void**)arg = PyObjCBlock_Create(methinfo->argtype[i]->callable, argument); if (*(void**)arg == NULL) { return -1; } byref_attr[i].buffer = PyCapsule_New( *(void**)arg, "objc.__block__", block_capsule_cleanup); } arglist[i] = signature_to_ffi_type(argtype); values[i] = arg; break; } Is this telling me that I am not passing a python callable? > On Jan 6, 2020, at 09:27, Ronald Oussoren wrote: > > > >> 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 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 >> 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? > > The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. > > import objc > objc.registerMetaDataForSelector( > b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? > b?get_block:?, > { > ?arguments?: { > 2: { > ?callable?: { > ?arguments?: { > 0: { ?type?: b?^v? }, > 1: { ?type?: b?@? }, > 2: { ?type?: b?@? }, > 3: { ?type?: b?@? } > }, > ?retail?: { ?type?: b?v? } > } > } > } > ) > > This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). > > Ronald > ? > > Twitter: @ronaldoussoren > Blog: https://blog.ronaldoussoren.net/ >> _______________________________________________ >> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >> https://mail.python.org/mailman/listinfo/pythonmac-sig >> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronaldoussoren at mac.com Tue Jan 7 04:00:04 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Tue, 7 Jan 2020 10:00:04 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> Message-ID: <567B5D3A-F032-48D6-932D-B3A96C7700F1@mac.com> 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 > CRApplication = objc.lookUpClass("CRApplication") > objc.registerMetaDataForSelector( > b'CRApplication', > b'get_block_', > { > 'arguments': { > 2: { > 'callable': { > 'arguments': { > 0:{'type': b'^v'}, > 1:{'type': b'@'}, > 2:{'type': b'@'}, > 3:{'type': b'@'} > }, > ' retval': { 'type': b'v' } > } > } > } > } > ) > 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@:@@@')) > server.startListening() > > > results: > > Traceback (most recent call last): > File "main.py", line 37, in > server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) > TypeError: Argument 3 is a block, but no signature available > > >> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >> >> >> >>> 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 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 >>> 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? >> >> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >> >> import objc >> objc.registerMetaDataForSelector( >> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >> b?get_block:?, >> { >> ?arguments?: { >> 2: { >> ?callable?: { >> ?arguments?: { >> 0: { ?type?: b?^v? }, >> 1: { ?type?: b?@? }, >> 2: { ?type?: b?@? }, >> 3: { ?type?: b?@? } >> }, >> ?retail?: { ?type?: b?v? } >> } >> } >> } >> ) >> >> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >> >> Ronald >> ? >> >> Twitter: @ronaldoussoren >> Blog: https://blog.ronaldoussoren.net/ >>> _______________________________________________ >>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronaldoussoren at mac.com Tue Jan 7 04:47:53 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Tue, 7 Jan 2020 10:47:53 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <567B5D3A-F032-48D6-932D-B3A96C7700F1@mac.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> <567B5D3A-F032-48D6-932D-B3A96C7700F1@mac.com> Message-ID: 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:', >> { >> 'arguments': { >> 3: { >> 'callable': { >> 'arguments': { >> 0:{'type': b'^v'}, >> 1:{'type': b'@'}, >> 2:{'type': b'@'}, >> 3:{'type': b'@'} >> }, >> 'retval': { 'type': b'v' } >> } >> } >> } >> } >> ) and later: >> server.get_block_("/", helloHandler) > ? Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ > On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG wrote: > > 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 >> CRApplication = objc.lookUpClass("CRApplication") >> objc.registerMetaDataForSelector( >> b'CRApplication', >> b'get_block_', >> { >> 'arguments': { >> 2: { >> 'callable': { >> 'arguments': { >> 0:{'type': b'^v'}, >> 1:{'type': b'@'}, >> 2:{'type': b'@'}, >> 3:{'type': b'@'} >> }, >> ' retval': { 'type': b'v' } >> } >> } >> } >> } >> ) >> 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@:@@@')) >> server.startListening() >> >> >> results: >> >> Traceback (most recent call last): >> File "main.py", line 37, in >> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >> TypeError: Argument 3 is a block, but no signature available >> >> >>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>> >>> >>> >>>> 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 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 >>>> 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? >>> >>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>> >>> import objc >>> objc.registerMetaDataForSelector( >>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>> b?get_block:?, >>> { >>> ?arguments?: { >>> 2: { >>> ?callable?: { >>> ?arguments?: { >>> 0: { ?type?: b?^v? }, >>> 1: { ?type?: b?@? }, >>> 2: { ?type?: b?@? }, >>> 3: { ?type?: b?@? } >>> }, >>> ?retail?: { ?type?: b?v? } >>> } >>> } >>> } >>> ) >>> >>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>> >>> Ronald >>> ? >>> >>> Twitter: @ronaldoussoren >>> Blog: https://blog.ronaldoussoren.net/ >>>> _______________________________________________ >>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>> >> > > _______________________________________________ > Pythonmac-SIG maillist - Pythonmac-SIG at python.org > https://mail.python.org/mailman/listinfo/pythonmac-sig > unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Tue Jan 7 20:04:21 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Tue, 7 Jan 2020 20:04:21 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> <567B5D3A-F032-48D6-932D-B3A96C7700F1@mac.com> Message-ID: <9420D9BF-1166-4919-BB49-6547499DBC2B@gmail.com> Same results with this code: import objc CRApplication = objc.lookUpClass("CRApplication") objc.registerMetaDataForSelector( b'CRServer', b'get_block_', { 'arguments': { 2: { '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): response.send_("Hello World!") handler() if __name__ == "__main__": server = CRApplication.sharedApplication().delegate().server() server.get_block_("/", helloHandler) server.startListening() > On Jan 7, 2020, at 04:47, Ronald Oussoren wrote: > > 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:', >>> { >>> 'arguments': { >>> 3: { >>> 'callable': { >>> 'arguments': { >>> 0:{'type': b'^v'}, >>> 1:{'type': b'@'}, >>> 2:{'type': b'@'}, >>> 3:{'type': b'@'} >>> }, >>> 'retval': { 'type': b'v' } >>> } >>> } >>> } >>> } >>> ) > > and later: > >>> server.get_block_("/", helloHandler) > >> > > > ? > > Twitter: @ronaldoussoren > Blog: https://blog.ronaldoussoren.net/ > >> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG > wrote: >> >> 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 >>> CRApplication = objc.lookUpClass("CRApplication") >>> objc.registerMetaDataForSelector( >>> b'CRApplication', >>> b'get_block_', >>> { >>> 'arguments': { >>> 2: { >>> 'callable': { >>> 'arguments': { >>> 0:{'type': b'^v'}, >>> 1:{'type': b'@'}, >>> 2:{'type': b'@'}, >>> 3:{'type': b'@'} >>> }, >>> ' retval': { 'type': b'v' } >>> } >>> } >>> } >>> } >>> ) >>> 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@:@@@')) >>> server.startListening() >>> >>> >>> results: >>> >>> Traceback (most recent call last): >>> File "main.py", line 37, in >>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>> TypeError: Argument 3 is a block, but no signature available >>> >>> >>>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>>> >>>> >>>> >>>>> 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 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 >>>>> 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? >>>> >>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>> >>>> import objc >>>> objc.registerMetaDataForSelector( >>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>> b?get_block:?, >>>> { >>>> ?arguments?: { >>>> 2: { >>>> ?callable?: { >>>> ?arguments?: { >>>> 0: { ?type?: b?^v? }, >>>> 1: { ?type?: b?@? }, >>>> 2: { ?type?: b?@? }, >>>> 3: { ?type?: b?@? } >>>> }, >>>> ?retail?: { ?type?: b?v? } >>>> } >>>> } >>>> } >>>> ) >>>> >>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>> >>>> Ronald >>>> ? >>>> >>>> Twitter: @ronaldoussoren >>>> Blog: https://blog.ronaldoussoren.net/ >>>>> _______________________________________________ >>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>> >>> >> >> _______________________________________________ >> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >> https://mail.python.org/mailman/listinfo/pythonmac-sig >> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronaldoussoren at mac.com Wed Jan 8 03:20:08 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Wed, 8 Jan 2020 09:20:08 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <9420D9BF-1166-4919-BB49-6547499DBC2B@gmail.com> References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> <567B5D3A-F032-48D6-932D-B3A96C7700F1@mac.com> <9420D9BF-1166-4919-BB49-6547499DBC2B@gmail.com> Message-ID: 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.lookUpClass("CRApplication") > objc.registerMetaDataForSelector( > b'CRServer', > b'get_block_', > { > 'arguments': { > 2: { > '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): > response.send_("Hello World!") > handler() > > if __name__ == "__main__": > server = CRApplication.sharedApplication().delegate().server() > server.get_block_("/", helloHandler) > server.startListening() > > >> On Jan 7, 2020, at 04:47, Ronald Oussoren > wrote: >> >> 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:', >>>> { >>>> 'arguments': { >>>> 3: { >>>> 'callable': { >>>> 'arguments': { >>>> 0:{'type': b'^v'}, >>>> 1:{'type': b'@'}, >>>> 2:{'type': b'@'}, >>>> 3:{'type': b'@'} >>>> }, >>>> 'retval': { 'type': b'v' } >>>> } >>>> } >>>> } >>>> } >>>> ) >> >> and later: >> >>>> server.get_block_("/", helloHandler) >> >>> >> >> >> ? >> >> Twitter: @ronaldoussoren >> Blog: https://blog.ronaldoussoren.net/ >> >>> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG > wrote: >>> >>> 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 >>>> CRApplication = objc.lookUpClass("CRApplication") >>>> objc.registerMetaDataForSelector( >>>> b'CRApplication', >>>> b'get_block_', >>>> { >>>> 'arguments': { >>>> 2: { >>>> 'callable': { >>>> 'arguments': { >>>> 0:{'type': b'^v'}, >>>> 1:{'type': b'@'}, >>>> 2:{'type': b'@'}, >>>> 3:{'type': b'@'} >>>> }, >>>> ' retval': { 'type': b'v' } >>>> } >>>> } >>>> } >>>> } >>>> ) >>>> 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@:@@@')) >>>> server.startListening() >>>> >>>> >>>> results: >>>> >>>> Traceback (most recent call last): >>>> File "main.py", line 37, in >>>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>>> TypeError: Argument 3 is a block, but no signature available >>>> >>>> >>>>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>>>> >>>>> >>>>> >>>>>> 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 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 >>>>>> 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? >>>>> >>>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>>> >>>>> import objc >>>>> objc.registerMetaDataForSelector( >>>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>>> b?get_block:?, >>>>> { >>>>> ?arguments?: { >>>>> 2: { >>>>> ?callable?: { >>>>> ?arguments?: { >>>>> 0: { ?type?: b?^v? }, >>>>> 1: { ?type?: b?@? }, >>>>> 2: { ?type?: b?@? }, >>>>> 3: { ?type?: b?@? } >>>>> }, >>>>> ?retail?: { ?type?: b?v? } >>>>> } >>>>> } >>>>> } >>>>> ) >>>>> >>>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>>> >>>>> Ronald >>>>> ? >>>>> >>>>> Twitter: @ronaldoussoren >>>>> Blog: https://blog.ronaldoussoren.net/ >>>>>> _______________________________________________ >>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>> >>>> >>> >>> _______________________________________________ >>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Wed Jan 8 11:18:11 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Wed, 8 Jan 2020 11:18:11 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: References: <34B2AC0B-951D-4973-8320-1D04AA391A12@gmail.com> <503C7568-3EBA-429B-AC01-4C1978F10DC9@mac.com> <020DC3ED-D6BD-4340-8495-761FD29721DD@gmail.com> <567B5D3A-F032-48D6-932D-B3A96C7700F1@mac.com> <9420D9BF-1166-4919-BB49-6547499DBC2B@gmail.com> Message-ID: 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. > > 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.lookUpClass("CRApplication") >> objc.registerMetaDataForSelector( >> b'CRServer', >> b'get_block_', >> { >> 'arguments': { >> 2: { >> '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): >> response.send_("Hello World!") >> handler() >> >> if __name__ == "__main__": >> server = CRApplication.sharedApplication().delegate().server() >> server.get_block_("/", helloHandler) >> server.startListening() >> >> >>> On Jan 7, 2020, at 04:47, Ronald Oussoren > wrote: >>> >>> 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:', >>>>> { >>>>> 'arguments': { >>>>> 3: { >>>>> 'callable': { >>>>> 'arguments': { >>>>> 0:{'type': b'^v'}, >>>>> 1:{'type': b'@'}, >>>>> 2:{'type': b'@'}, >>>>> 3:{'type': b'@'} >>>>> }, >>>>> 'retval': { 'type': b'v' } >>>>> } >>>>> } >>>>> } >>>>> } >>>>> ) >>> >>> and later: >>> >>>>> server.get_block_("/", helloHandler) >>> >>>> >>> >>> >>> ? >>> >>> Twitter: @ronaldoussoren >>> Blog: https://blog.ronaldoussoren.net/ >>> >>>> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG > wrote: >>>> >>>> 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 >>>>> CRApplication = objc.lookUpClass("CRApplication") >>>>> objc.registerMetaDataForSelector( >>>>> b'CRApplication', >>>>> b'get_block_', >>>>> { >>>>> 'arguments': { >>>>> 2: { >>>>> 'callable': { >>>>> 'arguments': { >>>>> 0:{'type': b'^v'}, >>>>> 1:{'type': b'@'}, >>>>> 2:{'type': b'@'}, >>>>> 3:{'type': b'@'} >>>>> }, >>>>> ' retval': { 'type': b'v' } >>>>> } >>>>> } >>>>> } >>>>> } >>>>> ) >>>>> 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@:@@@')) >>>>> server.startListening() >>>>> >>>>> >>>>> results: >>>>> >>>>> Traceback (most recent call last): >>>>> File "main.py", line 37, in >>>>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>>>> TypeError: Argument 3 is a block, but no signature available >>>>> >>>>> >>>>>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>>>>> >>>>>> >>>>>> >>>>>>> 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 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 >>>>>>> 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? >>>>>> >>>>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>>>> >>>>>> import objc >>>>>> objc.registerMetaDataForSelector( >>>>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>>>> b?get_block:?, >>>>>> { >>>>>> ?arguments?: { >>>>>> 2: { >>>>>> ?callable?: { >>>>>> ?arguments?: { >>>>>> 0: { ?type?: b?^v? }, >>>>>> 1: { ?type?: b?@? }, >>>>>> 2: { ?type?: b?@? }, >>>>>> 3: { ?type?: b?@? } >>>>>> }, >>>>>> ?retail?: { ?type?: b?v? } >>>>>> } >>>>>> } >>>>>> } >>>>>> ) >>>>>> >>>>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>>>> >>>>>> Ronald >>>>>> ? >>>>>> >>>>>> Twitter: @ronaldoussoren >>>>>> Blog: https://blog.ronaldoussoren.net/ >>>>>>> _______________________________________________ >>>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>>> >>>>> >>>> >>>> _______________________________________________ >>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronaldoussoren at mac.com Wed Jan 8 15:41:20 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Wed, 8 Jan 2020 21:41:20 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: References: Message-ID: 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_("/", 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. >> >> 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.lookUpClass("CRApplication") >>> objc.registerMetaDataForSelector( >>> b'CRServer', >>> b'get_block_', >>> { >>> 'arguments': { >>> 2: { >>> '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): >>> response.send_("Hello World!") >>> handler() >>> >>> if __name__ == "__main__": >>> server = CRApplication.sharedApplication().delegate().server() >>> server.get_block_("/", helloHandler) >>> server.startListening() >>> >>> >>>> On Jan 7, 2020, at 04:47, Ronald Oussoren wrote: >>>> >>>> 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:', >>>>>> { >>>>>> 'arguments': { >>>>>> 3: { >>>>>> 'callable': { >>>>>> 'arguments': { >>>>>> 0:{'type': b'^v'}, >>>>>> 1:{'type': b'@'}, >>>>>> 2:{'type': b'@'}, >>>>>> 3:{'type': b'@'} >>>>>> }, >>>>>> 'retval': { 'type': b'v' } >>>>>> } >>>>>> } >>>>>> } >>>>>> } >>>>>> ) >>>> >>>> and later: >>>> >>>>>> server.get_block_("/", helloHandler) >>>> >>>>> >>>> >>>> >>>> ? >>>> >>>> Twitter: @ronaldoussoren >>>> Blog: https://blog.ronaldoussoren.net/ >>>> >>>>> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG wrote: >>>>> >>>>> 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 >>>>>> CRApplication = objc.lookUpClass("CRApplication") >>>>>> objc.registerMetaDataForSelector( >>>>>> b'CRApplication', >>>>>> b'get_block_', >>>>>> { >>>>>> 'arguments': { >>>>>> 2: { >>>>>> 'callable': { >>>>>> 'arguments': { >>>>>> 0:{'type': b'^v'}, >>>>>> 1:{'type': b'@'}, >>>>>> 2:{'type': b'@'}, >>>>>> 3:{'type': b'@'} >>>>>> }, >>>>>> ' retval': { 'type': b'v' } >>>>>> } >>>>>> } >>>>>> } >>>>>> } >>>>>> ) >>>>>> 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@:@@@')) >>>>>> server.startListening() >>>>>> >>>>>> >>>>>> results: >>>>>> >>>>>> Traceback (most recent call last): >>>>>> File "main.py", line 37, in >>>>>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>>>>> TypeError: Argument 3 is a block, but no signature available >>>>>> >>>>>> >>>>>>> On Jan 6, 2020, at 09:27, Ronald Oussoren wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> 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 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 >>>>>>>> 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? >>>>>>> >>>>>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>>>>> >>>>>>> import objc >>>>>>> objc.registerMetaDataForSelector( >>>>>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>>>>> b?get_block:?, >>>>>>> { >>>>>>> ?arguments?: { >>>>>>> 2: { >>>>>>> ?callable?: { >>>>>>> ?arguments?: { >>>>>>> 0: { ?type?: b?^v? }, >>>>>>> 1: { ?type?: b?@? }, >>>>>>> 2: { ?type?: b?@? }, >>>>>>> 3: { ?type?: b?@? } >>>>>>> }, >>>>>>> ?retail?: { ?type?: b?v? } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>>>> >>>>>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>>>>> >>>>>>> Ronald >>>>>>> ? >>>>>>> >>>>>>> Twitter: @ronaldoussoren >>>>>>> Blog: https://blog.ronaldoussoren.net/ >>>>>>>> _______________________________________________ >>>>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Wed Jan 8 15:55:34 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Wed, 8 Jan 2020 15:55:34 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: References: Message-ID: <235E8BC9-D4ED-4313-8E56-FA0C98FD1AB4@gmail.com> 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'CRHTTPServer', b'get: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): response.send_("Hello World!") handler() if __name__ == "__main__": server = CRApplication.sharedApplication().delegate().server() server.get_block_("/", helloHandler) server.startListening() > 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 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_("/", 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. >>> >>> 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.lookUpClass("CRApplication") >>>> objc.registerMetaDataForSelector( >>>> b'CRServer', >>>> b'get_block_', >>>> { >>>> 'arguments': { >>>> 2: { >>>> '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): >>>> response.send_("Hello World!") >>>> handler() >>>> >>>> if __name__ == "__main__": >>>> server = CRApplication.sharedApplication().delegate().server() >>>> server.get_block_("/", helloHandler) >>>> server.startListening() >>>> >>>> >>>>> On Jan 7, 2020, at 04:47, Ronald Oussoren > wrote: >>>>> >>>>> 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:', >>>>>>> { >>>>>>> 'arguments': { >>>>>>> 3: { >>>>>>> 'callable': { >>>>>>> 'arguments': { >>>>>>> 0:{'type': b'^v'}, >>>>>>> 1:{'type': b'@'}, >>>>>>> 2:{'type': b'@'}, >>>>>>> 3:{'type': b'@'} >>>>>>> }, >>>>>>> 'retval': { 'type': b'v' } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>> >>>>> and later: >>>>> >>>>>>> server.get_block_("/", helloHandler) >>>>> >>>>>> >>>>> >>>>> >>>>> ? >>>>> >>>>> Twitter: @ronaldoussoren >>>>> Blog: https://blog.ronaldoussoren.net/ >>>>> >>>>>> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG > wrote: >>>>>> >>>>>> 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 >>>>>>> CRApplication = objc.lookUpClass("CRApplication") >>>>>>> objc.registerMetaDataForSelector( >>>>>>> b'CRApplication', >>>>>>> b'get_block_', >>>>>>> { >>>>>>> 'arguments': { >>>>>>> 2: { >>>>>>> 'callable': { >>>>>>> 'arguments': { >>>>>>> 0:{'type': b'^v'}, >>>>>>> 1:{'type': b'@'}, >>>>>>> 2:{'type': b'@'}, >>>>>>> 3:{'type': b'@'} >>>>>>> }, >>>>>>> ' retval': { 'type': b'v' } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>>>> 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@:@@@')) >>>>>>> server.startListening() >>>>>>> >>>>>>> >>>>>>> results: >>>>>>> >>>>>>> Traceback (most recent call last): >>>>>>> File "main.py", line 37, in >>>>>>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>>>>>> TypeError: Argument 3 is a block, but no signature available >>>>>>> >>>>>>> >>>>>>>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> 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 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 >>>>>>>>> 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? >>>>>>>> >>>>>>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>>>>>> >>>>>>>> import objc >>>>>>>> objc.registerMetaDataForSelector( >>>>>>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>>>>>> b?get_block:?, >>>>>>>> { >>>>>>>> ?arguments?: { >>>>>>>> 2: { >>>>>>>> ?callable?: { >>>>>>>> ?arguments?: { >>>>>>>> 0: { ?type?: b?^v? }, >>>>>>>> 1: { ?type?: b?@? }, >>>>>>>> 2: { ?type?: b?@? }, >>>>>>>> 3: { ?type?: b?@? } >>>>>>>> }, >>>>>>>> ?retail?: { ?type?: b?v? } >>>>>>>> } >>>>>>>> } >>>>>>>> } >>>>>>>> ) >>>>>>>> >>>>>>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>>>>>> >>>>>>>> Ronald >>>>>>>> ? >>>>>>>> >>>>>>>> Twitter: @ronaldoussoren >>>>>>>> Blog: https://blog.ronaldoussoren.net/ >>>>>>>>> _______________________________________________ >>>>>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>> >>>> >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Wed Jan 8 16:06:49 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Wed, 8 Jan 2020 16:06:49 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server : SOLVED In-Reply-To: References: Message-ID: 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 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_("/", 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. >>> >>> 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.lookUpClass("CRApplication") >>>> objc.registerMetaDataForSelector( >>>> b'CRServer', >>>> b'get_block_', >>>> { >>>> 'arguments': { >>>> 2: { >>>> '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): >>>> response.send_("Hello World!") >>>> handler() >>>> >>>> if __name__ == "__main__": >>>> server = CRApplication.sharedApplication().delegate().server() >>>> server.get_block_("/", helloHandler) >>>> server.startListening() >>>> >>>> >>>>> On Jan 7, 2020, at 04:47, Ronald Oussoren > wrote: >>>>> >>>>> 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:', >>>>>>> { >>>>>>> 'arguments': { >>>>>>> 3: { >>>>>>> 'callable': { >>>>>>> 'arguments': { >>>>>>> 0:{'type': b'^v'}, >>>>>>> 1:{'type': b'@'}, >>>>>>> 2:{'type': b'@'}, >>>>>>> 3:{'type': b'@'} >>>>>>> }, >>>>>>> 'retval': { 'type': b'v' } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>> >>>>> and later: >>>>> >>>>>>> server.get_block_("/", helloHandler) >>>>> >>>>>> >>>>> >>>>> >>>>> ? >>>>> >>>>> Twitter: @ronaldoussoren >>>>> Blog: https://blog.ronaldoussoren.net/ >>>>> >>>>>> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG > wrote: >>>>>> >>>>>> 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 >>>>>>> CRApplication = objc.lookUpClass("CRApplication") >>>>>>> objc.registerMetaDataForSelector( >>>>>>> b'CRApplication', >>>>>>> b'get_block_', >>>>>>> { >>>>>>> 'arguments': { >>>>>>> 2: { >>>>>>> 'callable': { >>>>>>> 'arguments': { >>>>>>> 0:{'type': b'^v'}, >>>>>>> 1:{'type': b'@'}, >>>>>>> 2:{'type': b'@'}, >>>>>>> 3:{'type': b'@'} >>>>>>> }, >>>>>>> ' retval': { 'type': b'v' } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>>>> 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@:@@@')) >>>>>>> server.startListening() >>>>>>> >>>>>>> >>>>>>> results: >>>>>>> >>>>>>> Traceback (most recent call last): >>>>>>> File "main.py", line 37, in >>>>>>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>>>>>> TypeError: Argument 3 is a block, but no signature available >>>>>>> >>>>>>> >>>>>>>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> 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 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 >>>>>>>>> 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? >>>>>>>> >>>>>>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>>>>>> >>>>>>>> import objc >>>>>>>> objc.registerMetaDataForSelector( >>>>>>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>>>>>> b?get_block:?, >>>>>>>> { >>>>>>>> ?arguments?: { >>>>>>>> 2: { >>>>>>>> ?callable?: { >>>>>>>> ?arguments?: { >>>>>>>> 0: { ?type?: b?^v? }, >>>>>>>> 1: { ?type?: b?@? }, >>>>>>>> 2: { ?type?: b?@? }, >>>>>>>> 3: { ?type?: b?@? } >>>>>>>> }, >>>>>>>> ?retail?: { ?type?: b?v? } >>>>>>>> } >>>>>>>> } >>>>>>>> } >>>>>>>> ) >>>>>>>> >>>>>>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>>>>>> >>>>>>>> Ronald >>>>>>>> ? >>>>>>>> >>>>>>>> Twitter: @ronaldoussoren >>>>>>>> Blog: https://blog.ronaldoussoren.net/ >>>>>>>>> _______________________________________________ >>>>>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>> >>>> >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Wed Jan 8 18:23:58 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Wed, 8 Jan 2020 18:23:58 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: References: Message-ID: <8EA6ED3E-1B82-4C10-81AE-BC89C9D5BDC8@gmail.com> 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. import objc from Foundation import NSLog 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' } } } } } ) global server def helloHandler(request, response, handler): NSLog("%@ %@ %@", request, response, handler) response.send_("Hello World!") handler() if __name__ == "__main__": server = CRApplication.sharedApplication().delegate().server() NSLog("Server: %@", server) server.get_block_("/", objc.selector(helloHandler, signature=b'^v:@@@')) NSLog("Started...") socket = server.startListening() while(socket): pass > 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 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_("/", 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. >>> >>> 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.lookUpClass("CRApplication") >>>> objc.registerMetaDataForSelector( >>>> b'CRServer', >>>> b'get_block_', >>>> { >>>> 'arguments': { >>>> 2: { >>>> '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): >>>> response.send_("Hello World!") >>>> handler() >>>> >>>> if __name__ == "__main__": >>>> server = CRApplication.sharedApplication().delegate().server() >>>> server.get_block_("/", helloHandler) >>>> server.startListening() >>>> >>>> >>>>> On Jan 7, 2020, at 04:47, Ronald Oussoren > wrote: >>>>> >>>>> 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:', >>>>>>> { >>>>>>> 'arguments': { >>>>>>> 3: { >>>>>>> 'callable': { >>>>>>> 'arguments': { >>>>>>> 0:{'type': b'^v'}, >>>>>>> 1:{'type': b'@'}, >>>>>>> 2:{'type': b'@'}, >>>>>>> 3:{'type': b'@'} >>>>>>> }, >>>>>>> 'retval': { 'type': b'v' } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>> >>>>> and later: >>>>> >>>>>>> server.get_block_("/", helloHandler) >>>>> >>>>>> >>>>> >>>>> >>>>> ? >>>>> >>>>> Twitter: @ronaldoussoren >>>>> Blog: https://blog.ronaldoussoren.net/ >>>>> >>>>>> On 7 Jan 2020, at 10:00, Ronald Oussoren via Pythonmac-SIG > wrote: >>>>>> >>>>>> 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 >>>>>>> CRApplication = objc.lookUpClass("CRApplication") >>>>>>> objc.registerMetaDataForSelector( >>>>>>> b'CRApplication', >>>>>>> b'get_block_', >>>>>>> { >>>>>>> 'arguments': { >>>>>>> 2: { >>>>>>> 'callable': { >>>>>>> 'arguments': { >>>>>>> 0:{'type': b'^v'}, >>>>>>> 1:{'type': b'@'}, >>>>>>> 2:{'type': b'@'}, >>>>>>> 3:{'type': b'@'} >>>>>>> }, >>>>>>> ' retval': { 'type': b'v' } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> } >>>>>>> ) >>>>>>> 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@:@@@')) >>>>>>> server.startListening() >>>>>>> >>>>>>> >>>>>>> results: >>>>>>> >>>>>>> Traceback (most recent call last): >>>>>>> File "main.py", line 37, in >>>>>>> server.get_block_("/", objc.selector(helloHandler, signature=b'v@:@@@')) >>>>>>> TypeError: Argument 3 is a block, but no signature available >>>>>>> >>>>>>> >>>>>>>> On Jan 6, 2020, at 09:27, Ronald Oussoren > wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> 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 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 >>>>>>>>> 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? >>>>>>>> >>>>>>>> The code below should do the trick, but eas typed directly into this mail and might therefore contain syntax errors. >>>>>>>> >>>>>>>> import objc >>>>>>>> objc.registerMetaDataForSelector( >>>>>>>> b?CRApplication?, # name of the class implementing ?get_block:?, or ?NSObject? >>>>>>>> b?get_block:?, >>>>>>>> { >>>>>>>> ?arguments?: { >>>>>>>> 2: { >>>>>>>> ?callable?: { >>>>>>>> ?arguments?: { >>>>>>>> 0: { ?type?: b?^v? }, >>>>>>>> 1: { ?type?: b?@? }, >>>>>>>> 2: { ?type?: b?@? }, >>>>>>>> 3: { ?type?: b?@? } >>>>>>>> }, >>>>>>>> ?retail?: { ?type?: b?v? } >>>>>>>> } >>>>>>>> } >>>>>>>> } >>>>>>>> ) >>>>>>>> >>>>>>>> This tells the bridge the signature for the block argument of the ?get_block:? selector, which is information that cannot be retrieved from the Objective-C runtime. Argument 2 is the first real argument of ObjC selectors, after the implicit arguments ?self? and ?_imp? (which is not available in python code). >>>>>>>> >>>>>>>> Ronald >>>>>>>> ? >>>>>>>> >>>>>>>> Twitter: @ronaldoussoren >>>>>>>> Blog: https://blog.ronaldoussoren.net/ >>>>>>>>> _______________________________________________ >>>>>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Pythonmac-SIG maillist - Pythonmac-SIG at python.org >>>>>> https://mail.python.org/mailman/listinfo/pythonmac-sig >>>>>> unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG >>>>> >>>> >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jack.jansen at cwi.nl Wed Jan 8 18:16:00 2020 From: jack.jansen at cwi.nl (Jack Jansen) Date: Thu, 9 Jan 2020 00:16:00 +0100 Subject: [Pythonmac-SIG] Problems with the pythonmac-sig mailing list Message-ID: <93AAD05B-B561-4671-A08A-0A7188C09998@cwi.nl> Folks, as of yesterday every posting to the list is held for approval. I?ve asked the mailman maintainers what could be going on. I the mean time I?ll approve all posts as quickly as possible, but I trust you understand that I?m not sitting here waiting to approve things 24 hours a day, so things may be a bit slow:-) -- Jack Jansen, , http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman From jack.jansen at cwi.nl Wed Jan 8 19:02:16 2020 From: jack.jansen at cwi.nl (Jack Jansen) Date: Thu, 9 Jan 2020 01:02:16 +0100 Subject: [Pythonmac-SIG] Problems with the pythonmac-sig mailing list In-Reply-To: <93AAD05B-B561-4671-A08A-0A7188C09998@cwi.nl> References: <93AAD05B-B561-4671-A08A-0A7188C09998@cwi.nl> Message-ID: <55A0A2CB-4A0E-434A-BEF8-95244D545FBA@cwi.nl> Well, turns out the problem isn?t with the whole list, it?s just with that Criollo thread. Apparently the messages in that thread have gotten so big (>40K) because of all the code fragments and topquoting. So nothing to worry about. Jack > On 09-Jan-2020, at 00:16 , Jack Jansen wrote: > > Folks, > as of yesterday every posting to the list is held for approval. I?ve asked the mailman maintainers what could be going on. > > I the mean time I?ll approve all posts as quickly as possible, but I trust you understand that I?m not sitting here waiting to approve things 24 hours a day, so things may be a bit slow:-) > -- > Jack Jansen, , http://www.cwi.nl/~jack > If I can't dance I don't want to be part of your revolution -- Emma Goldman > > > > _______________________________________________ > Pythonmac-SIG maillist - Pythonmac-SIG at python.org > https://mail.python.org/mailman/listinfo/pythonmac-sig > unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG -- Jack Jansen, , http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronaldoussoren at mac.com Thu Jan 9 04:18:01 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Thu, 9 Jan 2020 10:18:01 +0100 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <8EA6ED3E-1B82-4C10-81AE-BC89C9D5BDC8@gmail.com> References: <8EA6ED3E-1B82-4C10-81AE-BC89C9D5BDC8@gmail.com> Message-ID: <5C5B261F-F2A4-4898-BEBF-B56F2DDC288B@mac.com> > 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 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 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/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From randdvorak at gmail.com Thu Jan 9 11:55:49 2020 From: randdvorak at gmail.com (Rand Dvorak) Date: Thu, 9 Jan 2020 11:55:49 -0500 Subject: [Pythonmac-SIG] PyObjC and Criollo HTTP server In-Reply-To: <5C5B261F-F2A4-4898-BEBF-B56F2DDC288B@mac.com> References: <8EA6ED3E-1B82-4C10-81AE-BC89C9D5BDC8@gmail.com> <5C5B261F-F2A4-4898-BEBF-B56F2DDC288B@mac.com> Message-ID: <1289C98F-DE86-4107-9DF4-4C87345B5E43@gmail.com> 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 wrote: > > >> 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 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 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/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ronaldoussoren at mac.com Tue Jan 14 17:34:09 2020 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Tue, 14 Jan 2020 23:34:09 +0100 Subject: [Pythonmac-SIG] ANN: py2app and related projects updated Message-ID: <1137C264-867F-45B2-A65D-B630D7C479C7@mac.com> Hi, I?ve pushed updates for py2app, modulegraph, macholib, altgraph, modulegraph2, objectgraph and asl to PyPI. - py2app now supports Python 3.8 and has some minor bug fixes. - macholib has some minor bugfixes - all projects have stricter pyflakes configuration, and were reformatted using black. The major change is that all projects were moved to GitHub, the repositories at BitBucket will no longer be updated. Note that PyObjC and closely related projects are still on BitBucket, they will move later due to some issues I ran into while migrating the PyObjC repository from Mercurial to Git. Ronald ? Twitter: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: