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 toproxyurl(url):  # QUrl -> QUrl or None
    proxy = _SCHEME_PROXY.get(url.scheme())
    if proxy:
        url = QUrl(url)  # Avoid modifying the original URL
        host = _normalize_host(url.host())
        ip = _PROXY_DOMAINS.get(host) if _MAINLAND else None
        if ip:
            url.setHost(ip)
        else:
            key = _PROXY_SITES.get(host)
            if not key and _MAINLAND:
                key = _DLSITE_PROXY_SITES.get(
                    host) or _TORANOANA_PROXY_SITES.get(host)
            if key:
                url.setHost(config.PROXY_HOST)
                path = proxy + key + url.path()
                url.setPath(path)
        #print url
        return url
Example #3
0
def fromproxyurl(url):  # QUrl -> QUrl or None
    if not isinstance(url, QUrl):
        url = QUrl(url)
    if url.scheme() in ('http', 'https'):
        host = url.host()
        if host == config.PROXY_HOST:
            path = url.path()
            for rx in _re_proxy_key, _re_proxy_key2:
                m = rx.match(path)
                if m:
                    key = m.group(1)
                    if key:
                        host = config.PROXY_SITES.get(key)
                        if host:
                            url = QUrl(url)
                            url.setHost(host)
                            path = m.group(2) or '/'
                            if path[0] != '/':
                                path = '/' + path
                            url.setPath(path)
                            return url
                    #elif _MAINLAND and key == 'dlsite':
                    #  host = None
                    #  path = m.group(2) or '/'
                    #  if path.startswith('/www'):
                    #    host = _DLSITE_PROXY_SITES['/dlsite/www']
                    #    path = path[4:] or '/'
                    #  elif path.startswith('/img'):
                    #    host = _DLSITE_PROXY_SITES['/dlsite/img']
                    #    path = path[4:] or '/'
                    #  if host:
                    #    url = QUrl(url)
                    #    url.setHost(host)
                    #    url.setPath(path)
                    #    return url
        elif _MAINLAND:
            host = _PROXY_IPS.get(host)
            if host:
                url = QUrl(url)
                url.setHost(host)
                return url
Example #4
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 #5
0
    def testSetAttributes(self):
        #Construct QUrl by set* methods
        url = QUrl()

        url.setScheme('ftp')
        self.assertEqual(url.toString(), 'ftp:')

        url.setHost('www.google.com')
        self.assertEqual(url.toString(), 'ftp://www.google.com')

        url.setPort(8080)
        self.assertEqual(url.toString(), 'ftp://www.google.com:8080')

        url.setPath('mail/view')
        self.assertEqual(url.toString(), 'ftp://www.google.com:8080/mail/view')

        url.setUserName('john')
        self.assertEqual(url.toString(),
                         'ftp://[email protected]:8080/mail/view')

        url.setPassword('abc123')
        self.assertEqual(url.toString(),
                         'ftp://*****:*****@www.google.com:8080/mail/view')
Example #6
0
    def testSetAttributes(self):
        #Construct QUrl by set* methods
        url = QUrl()

        url.setScheme('ftp')
        self.assertEqual(url.toString(), 'ftp:')

        url.setHost('www.google.com')
        self.assertEqual(url.toString(), 'ftp://www.google.com')

        url.setPort(8080)
        self.assertEqual(url.toString(), 'ftp://www.google.com:8080')

        url.setPath('mail/view')
        self.assertEqual(url.toString(),
                        'ftp://www.google.com:8080/mail/view')

        url.setUserName('john')
        self.assertEqual(url.toString(),
                        'ftp://[email protected]:8080/mail/view')

        url.setPassword('abc123')
        self.assertEqual(url.toString(),
                        'ftp://*****:*****@www.google.com:8080/mail/view')