def _load_defaults(self): if not hasattr(build_number, 'frozen'): debugging = objc.YES self.exceptiondelegate = PyObjCExceptionDelegate.alloc().init() NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(NSLogAndHandleEveryExceptionMask) NSExceptionHandler.defaultExceptionHandler().setDelegate_(self.exceptiondelegate) else: debugging = objc.NO if self.using_xui: NSUserDefaults.standardUserDefaults().registerDefaults_({'WebKitDeveloperExtras': debugging})
def installExceptionHandler(verbosity=DEFAULTVERBOSITY, mask=DEFAULTMASK): """ Install the exception handling delegate that will log every exception matching the given mask with the given verbosity. """ # we need to retain this, cause the handler doesn't global _exceptionHandlerDelegate delegate = PyObjCDebuggingDelegate.alloc().initWithVerbosity_(verbosity) NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(mask) NSExceptionHandler.defaultExceptionHandler().setDelegate_(delegate) _exceptionHandlerDelegate = delegate
def install_exception_handler(verbosity=LOGSTACKTRACE, mask=DEFAULTMASK): """ Install the exception handling delegate that will log every exception matching the given mask with the given verbosity. """ if _installed: return delegate = DebuggingDelegate.alloc().initWithVerbosity_(verbosity) NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(mask) NSExceptionHandler.defaultExceptionHandler().setDelegate_(delegate) # we need to retain this, because the handler doesn't _installed.append(delegate)
def install_exception_handler(verbosity=DEFAULTVERBOSITY, mask=DEFAULTMASK): """ Install the exception handling delegate that will log every exception matching the given mask with the given verbosity. """ if _installed: return delegate = DebuggingDelegate.alloc().initWithVerbosity_(verbosity) NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_( mask) NSExceptionHandler.defaultExceptionHandler().setDelegate_(delegate) # we need to retain this, because the handler doesn't _installed.append(delegate)
def handlerInstalled(): """ Is an exception handler delegate currently installed? """ return NSExceptionHandler.defaultExceptionHandler().delegate() is not None
def removeExceptionHandler(): """ Remove the current exception handler delegate """ NSExceptionHandler.defaultExceptionHandler().setDelegate_(None) NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(0)
def main(): cmdparser = optparse.OptionParser(__doc__.strip(), version="wk-bench %s" % __version__) cmdparser.add_option("--debug", action="store_true", help="Display more progress information") cmdparser.add_option( "-u", "--url_list", help="Specify a list of URLs in a file rather than on the command-line" ) cmdparser.add_option("--requests", dest="max_requests", type="int", default=0, help="How many requests to make") cmdparser.add_option("--random", action="store_true", default=False, help="Pick URL randomly rather than in-order") (options, url_list) = cmdparser.parse_args() if options.url_list: url_list = map(str.strip, open(options.url_list).readlines()) if not url_list: cmdparser.print_usage() sys.exit(1) logging.basicConfig(format="%(asctime)s [%(levelname)s]: %(message)s", level=logging.DEBUG if options.debug else logging.INFO) if not options.max_requests: options.max_requests = len(url_list) if options.max_requests < len(url_list): logging.warn( "Making only %d requests even though you provided %d URLs" % (options.max_requests, len(url_list))) # Insert a URL which will be used to get all of the actual WebKit # initialization out of the way before we load the test sites url_list.insert(0, TEST_URL) app = AppKit.NSApplication.sharedApplication() # create an app delegate delegate = AppDelegate.alloc().init() AppKit.NSApp().setDelegate_(delegate) # create a window rect = NSMakeRect(0, 0, 1024, 768) win = AppKit.NSWindow.alloc() win.initWithContentRect_styleMask_backing_defer_( rect, AppKit.NSBorderlessWindowMask, 2, 0) if options.debug: win.orderFrontRegardless() # create a webview object webview = WebKit.WebView.alloc() webview.initWithFrame_(rect) webview.setPreferencesIdentifier_('wk-bench') win.setContentView_(webview) load_delegate = WebkitLoad.alloc().init() load_delegate.options = options load_delegate.urls = url_list webview.setFrameLoadDelegate_(load_delegate) ui_delegate = UIDelegate.alloc().init() webview.setUIDelegate_(ui_delegate) # Not supported by PyObjC yet: # NSSetUncaughtExceptionHandler(exc_handler) # # Instead we'll install a custom delegate for the ExceptionHandling framework # to use. In theory this should include logic to filter events but it appears # not to be an issue for an app this primitive in testing exc_delegate = exc_handler.alloc().init() NSExceptionHandler.defaultExceptionHandler().setDelegate_(exc_delegate) NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_( NSLogAndHandleEveryExceptionMask) AppHelper.runEventLoop(installInterrupt=True)
def main(): cmdparser = optparse.OptionParser(__doc__.strip(), version="wk_bench %s" % __version__) cmdparser.add_option("--debug", action="store_true", help="Display more progress information") cmdparser.add_option("-u", "--url_list", help="Specify a list of URLs in a file rather than on the command-line") cmdparser.add_option("--max-requests", type="int", default=0, help="How many requests to make") cmdparser.add_option("--random", action="store_true", default=False, help="Pick URL randomly rather than in-order") (options, url_list) = cmdparser.parse_args() if options.url_list: url_list = map(str.strip, open(options.url_list).readlines()) if not url_list: cmdparser.print_usage() sys.exit(1) logging.basicConfig(format="%(asctime)s [%(levelname)s]: %(message)s", level=logging.DEBUG if options.debug else logging.INFO) if not options.max_requests: options.max_requests = len(url_list) if options.max_requests < len(url_list): logging.warn("request limit %d is smaller than the provided %d URLs", options.max_requests, len(url_list)) # Insert a URL which will be used to get all of the actual WebKit # initialization out of the way before we load the test sites url_list.insert(0, TEST_URL) AppKit.NSApplication.sharedApplication() # create an app delegate delegate = AppDelegate.alloc().init() AppKit.NSApp().setDelegate_(delegate) # create a window rect = NSMakeRect(0, 0, 1024, 768) win = AppKit.NSWindow.alloc() win.initWithContentRect_styleMask_backing_defer_(rect, AppKit.NSBorderlessWindowMask, 2, 0) if options.debug: win.orderFrontRegardless() # create a webview object webview = WebKit.WebView.alloc() webview.initWithFrame_(rect) webview.setPreferencesIdentifier_('wk_bench') webview.preferences().setJavaEnabled_(False) win.setContentView_(webview) load_delegate = WebkitLoad.alloc().init() load_delegate.options = options load_delegate.urls = url_list webview.setFrameLoadDelegate_(load_delegate) ui_delegate = UIDelegate.alloc().init() webview.setUIDelegate_(ui_delegate) # Not supported by PyObjC yet: # NSSetUncaughtExceptionHandler(exc_handler) # # Instead we'll install a custom delegate for the ExceptionHandling framework # to use. In theory this should include logic to filter events but it appears # not to be an issue for an app this primitive in testing exc_delegate = exc_handler.alloc().init() NSExceptionHandler.defaultExceptionHandler().setDelegate_(exc_delegate) NSExceptionHandler.defaultExceptionHandler().setExceptionHandlingMask_(NSLogAndHandleEveryExceptionMask) AppHelper.runEventLoop(installInterrupt=True)