Example #1
0
 def test_connection(self):
     self.message.setText(
         '<span style="font-size: 10px; color: #000000;">' +
         'Verbindung wird getestet.' + '</span>')
     self.nam.finished.connect(self.test_reply)
     self.nam.sslErrors.connect(self.ssl_errors)
     ssl_config = QSslConfiguration().defaultConfiguration()
     ssl_config.setCiphers(QSslSocket().supportedCiphers())
     if self.certificate:
         certificate = QSslCertificate(encoded=self.certificate,
                                       format=QSsl.Pem)
         ssl_config.setCaCertificates([certificate])
     else:
         ssl_config.setCaCertificates([])
     url = QUrl(self.url_edit.text())
     url.setPath("/".join(
         filter(bool, (url.path() + "/ajax/read.php").split("/"))))
     request = QNetworkRequest(url)
     request.setSslConfiguration(ssl_config)
     request.setRawHeader(
         "Authorization", "Basic ".encode('utf-8') + b64encode(
             (self.username_edit.text() + ":" +
              self.password_edit.text()).encode('utf-8')))
     request.setHeader(QNetworkRequest.ContentTypeHeader,
                       "application/x-www-form-urlencoded")
     self.replies.add(self.nam.post(request, QByteArray()))
Example #2
0
    def open(self, address, method='get', headers={}, auth=None, body=None,
             default_popup_response=None):
        """Opens a web page.

        :param address: The resource URL.
        :param method: The Http method.
        :param headers: An optional dict of extra request hearders.
        :param auth: An optional tuple of HTTP auth (username, password).
        :param body: An optional string containing a payload.
        :param default_popup_response: the default response for any confirm/
        alert/prompt popup from the Javascript (replaces the need for the with
        blocks)
        :return: Page resource, All loaded resources.
        """
        body = body or QByteArray()
        try:
            method = getattr(QNetworkAccessManager,
                             "%sOperation" % method.capitalize())
        except AttributeError:
            raise Error("Invalid http method %s" % method)
        request = QNetworkRequest(QUrl(address))
        request.CacheLoadControl(0)
        for header in headers:
            request.setRawHeader(header, headers[header])
        self._auth = auth
        self._auth_attempt = 0  # Avoids reccursion

        self.main_frame.load(request, method, body)
        self.loaded = False

        if default_popup_response is not None:
            Ghost._prompt_expected = (default_popup_response, None)
            Ghost._confirm_expected = (default_popup_response, None)

        return self.wait_for_page_loaded()
Example #3
0
    def open(self, address, method='get', headers={}, auth=None, body=None,
             default_popup_response=None):
        """Opens a web page.

        :param address: The resource URL.
        :param method: The Http method.
        :param headers: An optional dict of extra request hearders.
        :param auth: An optional tuple of HTTP auth (username, password).
        :param body: An optional string containing a payload.
        :param default_popup_response: the default response for any confirm/
        alert/prompt popup from the Javascript (replaces the need for the with
        blocks)
        :return: Page resource, All loaded resources.
        """
        body = body or QByteArray()
        try:
            method = getattr(QNetworkAccessManager,
                             "%sOperation" % method.capitalize())
        except AttributeError:
            raise Error("Invalid http method %s" % method)
        request = QNetworkRequest(QUrl(address))
        request.CacheLoadControl(0)
        for header in headers:
            request.setRawHeader(header, headers[header])
        self._auth = auth
        self._auth_attempt = 0  # Avoids reccursion

        self.main_frame.load(request, method, body)
        self.loaded = False

        if default_popup_response is not None:
            Ghost._prompt_expected = (default_popup_response, None)
            Ghost._confirm_expected = (default_popup_response, None)

        return self.wait_for_page_loaded()
Example #4
0
 def createRequest(self, operation, request, device=None):
     if self.headers:
         request = QNetworkRequest(request)
         if operation != QNetworkAccessManager.PostOperation and operation != QNetworkAccessManager.PutOperation :
             request.setHeader(QNetworkRequest.ContentTypeHeader, None)
         for item in self.headers.iteritems():
             request.setRawHeader(*item)
     return QNetworkAccessManager.createRequest(self,operation, request, device)
Example #5
0
    def _prepare_request(self, url, headers):
        # create an empty request
        request = QNetworkRequest()
        # assign a url to it
        request.setUrl(QUrl(url))

        # add some custom headers to the request
        for (header_name, header_value) in headers.items():
            request.setRawHeader(header_name, QByteArray(header_value))

        return request
Example #6
0
    def open(self, address, method='get', headers={}):
        body = QByteArray()

        try:
            method = getattr(QNetworkAccessManager,
                "%sOperation" % method.capitalize())
        except AttributeError:
            raise Exception("Invalid http method %s" % method)

        request = QNetworkRequest(QUrl(address))
        request.CacheLoadControl(0)

        for header in headers:
            request.setRawHeader(header, headers[header])

        self._view.page().currentFrame().load(request, method, body)
        self._wait_for_page()
Example #7
0
    def open(self, address, method='get', headers={}, auth=None, body=None,
             default_popup_response=None, wait=True):
        """Opens a web page.

        :param address: The resource URL.
        :param method: The Http method.
        :param headers: An optional dict of extra request hearders.
        :param auth: An optional tuple of HTTP auth (username, password).
        :param body: An optional string containing a payload.
        :param default_popup_response: the default response for any confirm/
        alert/prompt popup from the Javascript (replaces the need for the with
        blocks)
        :param wait: If set to True (which is the default), this
        method call waits for the page load to complete before
        returning.  Otherwise, it just starts the page load task and
        it is the caller's responsibilty to wait for the load to
        finish by other means (e.g. by calling wait_for_page_loaded()).
        :return: Page resource, and all loaded resources, unless wait
        is False, in which case it returns None.
        """
        body = body or QByteArray()
        try:
            method = getattr(QNetworkAccessManager,
                             "%sOperation" % method.capitalize())
        except AttributeError:
            raise Error("Invalid http method %s" % method)
        request = QNetworkRequest(QUrl(address))
        request.CacheLoadControl(0)
        for header in headers:
            request.setRawHeader(header, headers[header])
        self._auth = auth
        self._auth_attempt = 0  # Avoids reccursion

        self.main_frame.load(request, method, body)
        self.loaded = False

        if default_popup_response is not None:
            Ghost._prompt_expected = (default_popup_response, None)
            Ghost._confirm_expected = (default_popup_response, None)

        if wait:
            return self.wait_for_page_loaded()
Example #8
0
 def test_connection(self):
     self.message.setText('<span style="font-size: 10px; color: #000000;">' +
                          'Verbindung wird getestet.' +
                          '</span>')
     self.nam.finished.connect(self.test_reply)
     self.nam.sslErrors.connect(self.ssl_errors)
     ssl_config = QSslConfiguration().defaultConfiguration()
     ssl_config.setCiphers(QSslSocket().supportedCiphers())
     if self.certificate:
         certificate = QSslCertificate(encoded=self.certificate, format=QSsl.Pem)
         ssl_config.setCaCertificates([certificate])
     else:
         ssl_config.setCaCertificates([])
     url = QUrl(self.url_edit.text())
     url.setPath("/".join(filter(bool, (url.path() + "/ajax/read.php").split("/"))))
     request = QNetworkRequest(url)
     request.setSslConfiguration(ssl_config)
     request.setRawHeader("Authorization",
                          "Basic ".encode('utf-8') +
                          b64encode((self.username_edit.text() + ":" + self.password_edit.text()).encode('utf-8')))
     request.setHeader(QNetworkRequest.ContentTypeHeader, "application/x-www-form-urlencoded")
     self.replies.add(self.nam.post(request, QByteArray()))
Example #9
0
    def open(self, address, method="GET", **kwargs):
        """
        Open a URL in the current frame.

        :param address: the url to open
        :param method: the HTTP method to use.  Defaults to 'GET'.
        """
        body = QByteArray()
        try:
            method = getattr(QNetworkAccessManager,
                             "%sOperation" % method.capitalize())
        except AttributeError:
            raise SpecterError("Invalid http method %s" % method)

        request = QNetworkRequest(QUrl(address))
        request.CacheLoadControl(0)

        # If we have headers...
        if 'headers' in kwargs:
            for header, val in kwargs['headers'].items():
                request.setRawHeader(header, val)

        self._frame.load(request, method, body)