Example #1
0
    def setCookiesFromUrl(self, cookieList, url):
        # logger.debug('?set cookies for %s' % url)
        _url = url.toString()
        # discard cookies unless url matches one of:
        # /displayauth, /conductor, /slides.json, 
        # /display_ctrl.json, /screen.manifest
        if not re.search(
            r'/displayauth|/conductor|/slides\.json|/display_ctrl\.json|/screen\.manifest',
            _url):
            # logger.debug("nay")
            return False

        # cookies accepted
        # logger.debug("ay")
        try:
            cookies_to_store = []
            for cookie in cookieList:
                # do not store session cookies
                if not cookie.isSessionCookie():
                    cookies_to_store.append(cookie.toRawForm().__str__())
            # logger.debug(_url +" : "+ ", ".join(cookies_to_store))
            # save to file
            f = open(self.cookiejar_file,'w')
            f.write("\n".join(cookies_to_store))
            f.close()
            logger.debug('stored %d cookie(s) from "%s"' % (
                len(cookies_to_store), _url))
            # publish cookies to Qt
            self.setAllCookies(cookieList)

        except Exception, e:
            logger.error(e)
            return False
Example #2
0
    def setCookiesFromUrl(self, cookieList, url):
        # logger.debug('?set cookies for %s' % url)
        _url = url.toString()
        # discard cookies unless url matches one of:
        # /displayauth, /conductor, /slides.json,
        # /display_ctrl.json, /screen.manifest
        if not re.search(
            r'/displayauth|/conductor|/slides\.json|/display_ctrl\.json|/screen\.manifest',
            _url):
            # logger.debug("nay")
            return False

        # cookies accepted
        # logger.debug("ay")
        try:
            cookies_to_store = []
            for cookie in cookieList:
                # do not store session cookies
                if not cookie.isSessionCookie():
                    cookies_to_store.append(cookie.toRawForm().__str__())
            # logger.debug(_url +" : "+ ", ".join(cookies_to_store))
            # save to file
            f = open(self.cookiejar_file,'w')
            f.write("\n".join(cookies_to_store))
            f.close()
            logger.debug('stored %d cookie(s) from "%s"' % (
                len(cookies_to_store), _url))
            # publish cookies to Qt
            self.setAllCookies(cookieList)

        except Exception, e:
            logger.error(e)
            return False
Example #3
0
    def _finished(self, reply):
        """Logs possible network errors.
        
        After the request has finished, it is the responsibility of the user 
        to delete the PySide.QtNetwork.QNetworkReply object at an appropriate 
        time. Do not directly delete it inside the slot connected to 
        QNetworkAccessManager.finished().
        You can use the QObject.deleteLater() function.
        @see http://doc.qt.nokia.com/latest/qnetworkaccessmanager.html#details
        """
        try:
            code = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
            if code >= 400:
                reason = reply.attribute(QtNetwork.QNetworkRequest.HttpReasonPhraseAttribute)
                logger.warn('Failed to GET "%s": %s' % (
                    reply.request().url().toString(), reason))
            # NOTE: calling deleteLater() on the reply object
            # causes segmentation fault on Linux with Qt4.6 (and PySide 1.0.6).
            # Leaving the object to remain in memory may
            # cause a huge memory leak over time?
            # Qt4.7 does seem to behave better in this regard.
            if float(QtCore.__version__[0:3]) >= 4.7:
                reply.deleteLater()

        except Exception, e:
            logger.error(e)
Example #4
0
    def _finished(self, reply):
        """Logs possible network errors.
        
        After the request has finished, it is the responsibility of the user 
        to delete the PySide.QtNetwork.QNetworkReply object at an appropriate 
        time. Do not directly delete it inside the slot connected to 
        QNetworkAccessManager.finished().
        You can use the QObject.deleteLater() function.
        @see http://doc.qt.nokia.com/latest/qnetworkaccessmanager.html#details
        """
        try:
            code = reply.attribute(
                QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
            if code >= 400:
                reason = reply.attribute(
                    QtNetwork.QNetworkRequest.HttpReasonPhraseAttribute)
                logger.warn('Failed to GET "%s": %s' %
                            (reply.request().url().toString(), reason))
            # NOTE: calling deleteLater() on the reply object
            # causes segmentation fault on Linux with Qt4.6 (and PySide 1.0.6).
            # Leaving the object to remain in memory may
            # cause a huge memory leak over time?
            # Qt4.7 does seem to behave better in this regard.
            if float(QtCore.__version__[0:3]) >= 4.7:
                reply.deleteLater()

        except Exception, e:
            logger.error(e)
Example #5
0
    def _runscript(self, scriptname):
        """Execute a shell script
        """
        logger.debug("executing script %s" % scriptname)
        try:
            p = Popen(scriptname,
		      shell=False,
		      stdin=PIPE,
		      stdout=PIPE,
		      stderr=PIPE)
            stdout, stderr = p.communicate()
            if len(stdout) > 0:
                logger.debug(stdout)
            if len(stderr) > 0:
                # it is quite annoying to get the xset usage
                # constantly flooding the debug log
                #logger.error(stderr)
                logger.warn(stderr[0:36])
        except Exception, e:
            logger.error(e)
Example #6
0
    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)
Example #7
0
    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)