def __init__(self, page): QtCore.QThread.__init__(self) self.page = page logger.info("Starting up JavaScript REPL") # configure console for logging # FIXME: at Repl restart (window.display.refresh()), # the loggers are initialized several times! self.console = StreamHandler() from logger.crc_logger import ConcurrentRotatingColoredLogger self.console.setFormatter(ConcurrentRotatingColoredLogger.debug_formatter()) self.attach()
def __init__(self, page): QtCore.QThread.__init__(self) self.page = page logger.info("Starting up JavaScript REPL") # configure console for logging # FIXME: at Repl restart (window.display.refresh()), # the loggers are initialized several times! self.console = StreamHandler() from logger.crc_logger import ConcurrentRotatingColoredLogger self.console.setFormatter( ConcurrentRotatingColoredLogger.debug_formatter()) self.attach()
def __init__(self, cookiejar_file): QtNetwork.QNetworkCookieJar.__init__(self) self.cookiejar_file = cookiejar_file # create cookiejar file unless it exists if not os.path.exists(self.cookiejar_file): open(self.cookiejar_file, "w").close() else: try: # read cookies from file f = open(self.cookiejar_file, "r") cookies = QtNetwork.QNetworkCookie.parseCookies(f.read()) f.close() self.setAllCookies(cookies) if len(cookies) > 0: logger.info('read %d cookies from "%s"' % (len(cookies), self.cookiejar_file)) except (IOError, TypeError), e: logger.warn('Error while restoring cookies from "%s": %s' % (self.cookiejar_file, e))
def __init__(self, cookiejar_file): QtNetwork.QNetworkCookieJar.__init__(self) self.cookiejar_file = cookiejar_file # create cookiejar file unless it exists if not os.path.exists(self.cookiejar_file): open(self.cookiejar_file, 'w').close() else: try: # read cookies from file f = open(self.cookiejar_file,'r') cookies = QtNetwork.QNetworkCookie.parseCookies( f.read()) f.close() self.setAllCookies(cookies) if len(cookies) > 0: logger.info('read %d cookies from "%s"' % ( len(cookies), self.cookiejar_file)) except (IOError, TypeError), e: logger.warn('Error while restoring cookies from "%s": %s' % (self.cookiejar_file, e))
def javaScriptConsoleMessage(self, message, lineNumber, sourceID): """Catches JavaScript console messages and errors from a QWebPage. Differentiates between normal messages and errors by matching 'Error' in the string. """ msg_tmpl = '(%s:%i)\n%s' % (sourceID, lineNumber, '%s') # strip Warning, Info match = re.search('Info: (.*)',message) if match: logger.info(msg_tmpl % match.group(1)) return match = re.search('Warning: (.*)',message) if match: logger.warn(msg_tmpl % match.group(1)) return match = re.search('Error|Exception',message) if match: logger.error(msg_tmpl % message) return logger.debug(msg_tmpl % message)
def javaScriptConsoleMessage(self, message, lineNumber, sourceID): """Catches JavaScript console messages and errors from a QWebPage. Differentiates between normal messages and errors by matching 'Error' in the string. """ msg_tmpl = '(%s:%i)\n%s' % (sourceID, lineNumber, '%s') # strip Warning, Info match = re.search('Info: (.*)', message) if match: logger.info(msg_tmpl % match.group(1)) return match = re.search('Warning: (.*)', message) if match: logger.warn(msg_tmpl % match.group(1)) return match = re.search('Error|Exception', message) if match: logger.error(msg_tmpl % message) return logger.debug(msg_tmpl % message)
def __init__(self, centralwidget, **kwargs): """MainWebView loads the page, and attaches interfaces to it. Keyword arguments: - url - hostname - use_repl NOTE: all QWebSettings must be set before setUrl() is called! """ QtWebKit.QWebView.__init__(self, centralwidget) self.setObjectName("webView0") # store keyword arguments to options self.options = kwargs use_repl = self.options.get('use_repl') # if IIVARI_CACHE_PATH is None, caching is disabled cache_path = __builtin__.IIVARI_CACHE_PATH # set custom WebPage to log JavaScript messages self.setPage(MainWebPage()) # initialize REPL here to attach to console log early if use_repl is True: self.repl = Repl(page=self.page()) # get token for network request authentication hostname = self.options.get('hostname') token = self.get_token(hostname) # set custom NetworkAccessManager for cookie management and network error logging self.page().setNetworkAccessManager(MainNetworkAccessManager(token=token)) # attach a Display object to JavaScript window.display after page has loaded self.page().loadFinished[bool].connect(self.create_display) # use QWebSettings for this webView qsettings = self.settings() #qsettings = QWebSettings.globalSettings() # enable Javascript qsettings.setAttribute(QWebSettings.JavascriptEnabled, True) """ Enable application to work in offline mode. Use HTML5 cache manifest for static content, and jquery.offline for dynamic JSON content. @see http://diveintohtml5.info/offline.html """ if cache_path is not None: qsettings.enablePersistentStorage(cache_path) # uncertain whether LocalContentCanAccessRemoteUrls is needed even when using offline cache # FIXME: check, and disable this if unneeded. qsettings.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True) #qsettings.setAttribute( # QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) # write qsettings to log logger.debug("\n * ".join([ ' --- QWebSettings ---', 'OfflineWebApplicationCache: %s' % ( qsettings.testAttribute( QWebSettings.OfflineWebApplicationCacheEnabled)), 'LocalStorage: %s' % ( qsettings.testAttribute( QWebSettings.LocalStorageEnabled)), 'offlineWebApplicationCachePath: %s' % ( qsettings.offlineWebApplicationCachePath()), 'offlineWebApplicationCacheQuota: %i' % ( qsettings.offlineWebApplicationCacheQuota()), 'LocalContentCanAccessRemoteUrls: %s' % ( qsettings.testAttribute( QWebSettings.LocalContentCanAccessRemoteUrls)), ])) # set URL and launch the request url = self.options.get('url') logger.info("url: %s" % url) self.setUrl(QtCore.QUrl(url))
def __init__(self, centralwidget, **kwargs): """MainWebView loads the page, and attaches interfaces to it. Keyword arguments: - url - hostname - use_repl NOTE: all QWebSettings must be set before setUrl() is called! """ QtWebKit.QWebView.__init__(self, centralwidget) self.setObjectName("webView0") # store keyword arguments to options self.options = kwargs use_repl = self.options.get('use_repl') # if IIVARI_CACHE_PATH is None, caching is disabled cache_path = __builtin__.IIVARI_CACHE_PATH # set custom WebPage to log JavaScript messages self.setPage(MainWebPage()) # initialize REPL here to attach to console log early if use_repl is True: self.repl = Repl(page=self.page()) # get token for network request authentication hostname = self.options.get('hostname') token = self.get_token(hostname) # set custom NetworkAccessManager for cookie management and network error logging self.page().setNetworkAccessManager( MainNetworkAccessManager(token=token)) # attach a Display object to JavaScript window.display after page has loaded self.page().loadFinished[bool].connect(self.create_display) # use QWebSettings for this webView qsettings = self.settings() #qsettings = QWebSettings.globalSettings() # enable Javascript qsettings.setAttribute(QWebSettings.JavascriptEnabled, True) """ Enable application to work in offline mode. Use HTML5 cache manifest for static content, and jquery.offline for dynamic JSON content. @see http://diveintohtml5.info/offline.html """ if cache_path is not None: qsettings.enablePersistentStorage(cache_path) # uncertain whether LocalContentCanAccessRemoteUrls is needed even when using offline cache # FIXME: check, and disable this if unneeded. qsettings.setAttribute( QWebSettings.LocalContentCanAccessRemoteUrls, True) #qsettings.setAttribute( # QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) # write qsettings to log logger.debug("\n * ".join([ ' --- QWebSettings ---', 'OfflineWebApplicationCache: %s' % (qsettings.testAttribute( QWebSettings.OfflineWebApplicationCacheEnabled)), 'LocalStorage: %s' % (qsettings.testAttribute(QWebSettings.LocalStorageEnabled)), 'offlineWebApplicationCachePath: %s' % (qsettings.offlineWebApplicationCachePath()), 'offlineWebApplicationCacheQuota: %i' % (qsettings.offlineWebApplicationCacheQuota()), 'LocalContentCanAccessRemoteUrls: %s' % (qsettings.testAttribute( QWebSettings.LocalContentCanAccessRemoteUrls)), ])) # set URL and launch the request url = self.options.get('url') logger.info("url: %s" % url) self.setUrl(QtCore.QUrl(url))