Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    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))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)