MCPcopy Index your code
hub / github.com/RustPython/RustPython / IOSBrowser

Class IOSBrowser

Lib/webbrowser.py:627–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

625 from ctypes import c_void_p, c_char_p, c_ulong
626
627 class IOSBrowser(BaseBrowser):
628 def open(self, url, new=0, autoraise=True):
629 sys.audit("webbrowser.open", url)
630 # If ctypes isn't available, we can't open a browser
631 if objc is None:
632 return False
633
634 # All the messages in this call return object references.
635 objc.objc_msgSend.restype = c_void_p
636
637 # This is the equivalent of:
638 # NSString url_string =
639 # [NSString stringWithCString:url.encode("utf-8")
640 # encoding:NSUTF8StringEncoding];
641 NSString = objc.objc_getClass(b"NSString")
642 constructor = objc.sel_registerName(b"stringWithCString:encoding:")
643 objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_char_p, c_ulong]
644 url_string = objc.objc_msgSend(
645 NSString,
646 constructor,
647 url.encode("utf-8"),
648 4, # NSUTF8StringEncoding = 4
649 )
650
651 # Create an NSURL object representing the URL
652 # This is the equivalent of:
653 # NSURL *nsurl = [NSURL URLWithString:url];
654 NSURL = objc.objc_getClass(b"NSURL")
655 urlWithString_ = objc.sel_registerName(b"URLWithString:")
656 objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_void_p]
657 ns_url = objc.objc_msgSend(NSURL, urlWithString_, url_string)
658
659 # Get the shared UIApplication instance
660 # This code is the equivalent of:
661 # UIApplication shared_app = [UIApplication sharedApplication]
662 UIApplication = objc.objc_getClass(b"UIApplication")
663 sharedApplication = objc.sel_registerName(b"sharedApplication")
664 objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
665 shared_app = objc.objc_msgSend(UIApplication, sharedApplication)
666
667 # Open the URL on the shared application
668 # This code is the equivalent of:
669 # [shared_app openURL:ns_url
670 # options:NIL
671 # completionHandler:NIL];
672 openURL_ = objc.sel_registerName(b"openURL:options:completionHandler:")
673 objc.objc_msgSend.argtypes = [
674 c_void_p, c_void_p, c_void_p, c_void_p, c_void_p
675 ]
676 # Method returns void
677 objc.objc_msgSend.restype = None
678 objc.objc_msgSend(shared_app, openURL_, ns_url, None, None)
679
680 return True
681
682
683def parse_args(arg_list: list[str] | None):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected