MCPcopy Index your code
hub / github.com/python/cpython / open

Method open

Lib/webbrowser.py:677–730  ·  view source on GitHub ↗
(self, url, new=0, autoraise=True)

Source from the content-addressed store, hash-verified

675
676 class IOSBrowser(BaseBrowser):
677 def open(self, url, new=0, autoraise=True):
678 sys.audit("webbrowser.open", url)
679 self._check_url(url)
680 # If ctypes isn't available, we can't open a browser
681 if objc is None:
682 return False
683
684 # All the messages in this call return object references.
685 objc.objc_msgSend.restype = c_void_p
686
687 # This is the equivalent of:
688 # NSString url_string =
689 # [NSString stringWithCString:url.encode("utf-8")
690 # encoding:NSUTF8StringEncoding];
691 NSString = objc.objc_getClass(b"NSString")
692 constructor = objc.sel_registerName(b"stringWithCString:encoding:")
693 objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_char_p, c_ulong]
694 url_string = objc.objc_msgSend(
695 NSString,
696 constructor,
697 url.encode("utf-8"),
698 4, # NSUTF8StringEncoding = 4
699 )
700
701 # Create an NSURL object representing the URL
702 # This is the equivalent of:
703 # NSURL *nsurl = [NSURL URLWithString:url];
704 NSURL = objc.objc_getClass(b"NSURL")
705 urlWithString_ = objc.sel_registerName(b"URLWithString:")
706 objc.objc_msgSend.argtypes = [c_void_p, c_void_p, c_void_p]
707 ns_url = objc.objc_msgSend(NSURL, urlWithString_, url_string)
708
709 # Get the shared UIApplication instance
710 # This code is the equivalent of:
711 # UIApplication shared_app = [UIApplication sharedApplication]
712 UIApplication = objc.objc_getClass(b"UIApplication")
713 sharedApplication = objc.sel_registerName(b"sharedApplication")
714 objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
715 shared_app = objc.objc_msgSend(UIApplication, sharedApplication)
716
717 # Open the URL on the shared application
718 # This code is the equivalent of:
719 # [shared_app openURL:ns_url
720 # options:NIL
721 # completionHandler:NIL];
722 openURL_ = objc.sel_registerName(b"openURL:options:completionHandler:")
723 objc.objc_msgSend.argtypes = [
724 c_void_p, c_void_p, c_void_p, c_void_p, c_void_p
725 ]
726 # Method returns void
727 objc.objc_msgSend.restype = None
728 objc.objc_msgSend(shared_app, openURL_, ns_url, None, None)
729
730 return True
731
732
733def parse_args(arg_list: list[str] | None):

Callers

nothing calls this directly

Calls 2

_check_urlMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected