Ejemplo n.º 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()))
Ejemplo n.º 2
0
    def downloadFile(self, path, setting):
        self.progress_text = 'Downloading {}'.format(path.replace(self.base_url.format(self.selected_version()),''))

        location = self.getSetting('download_dir').value

        url = QUrl(path)
        fileInfo = QFileInfo(url.path())
        fileName = setting.save_file_path(self.selected_version(), location)

        archive_exists = QFile.exists(fileName)

        dest_files_exist = False

        #for dest_file in setting.dest_files:
        #    dest_file_path = os.path.join('files', setting.name, dest_file)
        #    dest_files_exist &= QFile.exists(dest_file_path)

        forced = self.getSetting('force_download').value

        if (archive_exists or dest_files_exist) and not forced:
            self.continueDownloadingOrExtract()
            return #QFile.remove(fileName)

        self.outFile = QFile(fileName)
        if not self.outFile.open(QIODevice.WriteOnly):
            self.show_error('Unable to save the file {}: {}.'.format(fileName, self.outFile.errorString()))
            self.outFile = None
            self.enableUI()
            return

        mode = QHttp.ConnectionModeHttp
        port = url.port()
        if port == -1:
            port = 0
        self.http.setHost(url.host(), mode, port)
        self.httpRequestAborted = False

        path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
        if path:
            path = str(path)
        else:
            path = '/'

        # Download the file.
        self.httpGetId = self.http.get(path, self.outFile)
Ejemplo n.º 3
0
    def download_file(self, path, setting):
        version_file = self.settings['base_url'].format(
            self.selected_version())

        location = self.get_setting('download_dir').value

        versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0]

        minor = int(versions[1])
        if minor >= 12:
            path = path.replace('node-webkit', 'nwjs')

        self.progress_text = 'Downloading {}'.format(
            path.replace(version_file, ''))

        url = QUrl(path)
        file_name = setting.save_file_path(self.selected_version(), location)

        archive_exists = QFile.exists(file_name)

        #dest_files_exist = False

        # for dest_file in setting.dest_files:
        #    dest_file_path = os.path.join('files', setting.name, dest_file)
        #    dest_files_exist &= QFile.exists(dest_file_path)

        forced = self.get_setting('force_download').value

        if archive_exists and not forced:
            self.continue_downloading_or_extract()
            return

        self.out_file = QFile(file_name)
        if not self.out_file.open(QIODevice.WriteOnly):
            error = self.out_file.error().name
            self.show_error('Unable to save the file {}: {}.'.format(
                file_name, error))
            self.out_file = None
            self.enable_ui()
            return

        mode = QHttp.ConnectionModeHttp
        port = url.port()
        if port == -1:
            port = 0
        self.http.setHost(url.host(), mode, port)
        self.http_request_aborted = False

        path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
        if path:
            path = str(path)
        else:
            path = '/'

        # Download the file.
        self.http_get_id = self.http.get(path, self.out_file)
Ejemplo n.º 4
0
    def downloadFile(self, path, setting):
        self.progress_text = 'Downloading {}'.format(path.replace(self.base_url.format(self.selected_version()),''))

        url = QUrl(path)
        fileInfo = QFileInfo(url.path())
        fileName = setting.save_file_path(self.selected_version())

        archive_exists = QFile.exists(fileName)

        dest_files_exist = True

        for dest_file in setting.dest_files:
            dest_file_path = os.path.join('files', setting.name, dest_file)
            dest_files_exist &= QFile.exists(dest_file_path)

        forced = self.getSetting('force_download').value

        if (archive_exists or dest_files_exist) and not forced:
            self.continueDownloadingOrExtract()
            return #QFile.remove(fileName)

        self.outFile = QFile(fileName)
        if not self.outFile.open(QIODevice.WriteOnly):
            self.show_error('Unable to save the file {}: {}.'.format(fileName, self.outFile.errorString()))
            self.outFile = None
            self.enableUI()
            return

        mode = QHttp.ConnectionModeHttp
        port = url.port()
        if port == -1:
            port = 0
        self.http.setHost(url.host(), mode, port)
        self.httpRequestAborted = False

        path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
        if path:
            path = str(path)
        else:
            path = '/'

        # Download the file.
        self.httpGetId = self.http.get(path, self.outFile)
Ejemplo n.º 5
0
    def download_file(self, path, setting):
        version_file = self.settings['base_url'].format(self.selected_version())

        location = self.get_setting('download_dir').value

        versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0]

        minor = int(versions[1])
        if minor >= 12:
            path = path.replace('node-webkit', 'nwjs')

        self.progress_text = 'Downloading {}'.format(path.replace(version_file, ''))

        url = QUrl(path)
        file_name = setting.save_file_path(self.selected_version(), location)

        archive_exists = QFile.exists(file_name)

        #dest_files_exist = False

        # for dest_file in setting.dest_files:
        #    dest_file_path = os.path.join('files', setting.name, dest_file)
        #    dest_files_exist &= QFile.exists(dest_file_path)

        forced = self.get_setting('force_download').value

        if archive_exists and not forced:
            self.continue_downloading_or_extract()
            return

        self.out_file = QFile(file_name)
        if not self.out_file.open(QIODevice.WriteOnly):
            error = self.out_file.error().name
            self.show_error('Unable to save the file {}: {}.'.format(file_name,
                                                                     error))
            self.out_file = None
            self.enable_ui()
            return

        mode = QHttp.ConnectionModeHttp
        port = url.port()
        if port == -1:
            port = 0
        self.http.setHost(url.host(), mode, port)
        self.http_request_aborted = False

        path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
        if path:
            path = str(path)
        else:
            path = '/'

        # Download the file.
        self.http_get_id = self.http.get(path, self.out_file)
Ejemplo n.º 6
0
    def linkClicked(self, url):
        fragment = None
        if url.hasFragment():
            fragment = url.fragment()
            _url = QUrl(url.toString()[:url.toString().find('#%s'%fragment)])
            if _url.toString() != 'about:blank' and _url.path() != self.current_position:
                url = _url
                fragment = None

        if fragment:
            page = self.view.page()
            page.mainFrame().scrollToAnchor(fragment)
        elif url.path() in self.contents.keys():
            self.current_position = url.path()
            self.loadPage(self.contents[url.path()])
        elif url.path().startswith('http://') or url.path().startswith('www.'):
            print 'pass the address to the system browser'
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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()))
Ejemplo n.º 10
0
   def _qss_url(self, path, url, allow_inheritance=True, _suppress=False,
                for_import=False):
       """
       Process a url() and return an absolute URL, or None if the URL isn't
       valid.
       """
       if (url.startswith('"') and url.endswith('"')) or \
               (url.startswith("'") and url.endswith("'")):
           url = url[1:-1]
 
       # Make a QUrl.
       url = QUrl(url.decode('unicode_escape'))
 
       # Is it a data uri?
       if url.scheme() == 'data':
           # Extract the useful information from the path.
           format, sep, data = url.path().partition(',')
           if not sep and not data:
               data = format
               format = ''
 
           mimetype, _, format = format.partition(';')
           if not mimetype:
               ext = 'txt'
           else:
               _, _, ext = mimetype.rpartition('/')
           if not format:
               format = 'charset=US-ASCII'
 
           # Build the filename.
           fn = os.path.join(profile.cache_path, u'data-uris',
                   '%s.%s' % (hashlib.md5(data).hexdigest(), ext))
 
           # Ensure the path exists and write the file.
           try:
               if not os.path.exists(os.path.dirname(fn)):
                   os.makedirs(os.path.dirname(fn))
               with open(fn, 'wb') as f:
                   if format == 'base64':
                       f.write(base64.b64decode(data))
                   elif format.startswith('charset='):
                       data = urllib.unquote(data).encode('latin1')
                       cs = format[8:]
                       if cs and cs.lower() not in ('utf-8','utf8'):
                           data = data.decode(cs).encode('utf-8')
                       f.write(data)
                   else:
                       return
           except (ValueError, OSError, IOError, TypeError):
               log.debug('Error parsing data URI.', exc_info=1)
               return
 
           # Substitute the right / on Windows, and return the path.
           if os.name == 'nt':
               fn = fn.replace('\\', '/')
           return fn
 
       # If it's relative, build an absolute URL. If not, return.
       if not url.isRelative():
           return
 
       url = url.toLocalFile()
       if url.startswith('/'):
           url = url[1:]
       else:
           url = profile.join(path, url)
 
       # If we're dealing with import, return a relative path.
       if for_import:
           return url
 
       return self.get_path(url, allow_inheritance, False, _suppress)
Ejemplo n.º 11
0
    def _qss_url(self,
                 path,
                 url,
                 allow_inheritance=True,
                 _suppress=False,
                 for_import=False):
        """
        Process a url() and return an absolute URL, or None if the URL isn't
        valid.
        """
        if (url.startswith('"') and url.endswith('"')) or \
                (url.startswith("'") and url.endswith("'")):
            url = url[1:-1]

        # Make a QUrl.
        url = QUrl(url.decode('unicode_escape'))

        # Is it a data uri?
        if url.scheme() == 'data':
            # Extract the useful information from the path.
            format, sep, data = url.path().partition(',')
            if not sep and not data:
                data = format
                format = ''

            mimetype, _, format = format.partition(';')
            if not mimetype:
                ext = 'txt'
            else:
                _, _, ext = mimetype.rpartition('/')
            if not format:
                format = 'charset=US-ASCII'

            # Build the filename.
            fn = os.path.join(profile.cache_path, u'data-uris',
                              '%s.%s' % (hashlib.md5(data).hexdigest(), ext))

            # Ensure the path exists and write the file.
            try:
                if not os.path.exists(os.path.dirname(fn)):
                    os.makedirs(os.path.dirname(fn))
                with open(fn, 'wb') as f:
                    if format == 'base64':
                        f.write(base64.b64decode(data))
                    elif format.startswith('charset='):
                        data = urllib.unquote(data).encode('latin1')
                        cs = format[8:]
                        if cs and cs.lower() not in ('utf-8', 'utf8'):
                            data = data.decode(cs).encode('utf-8')
                        f.write(data)
                    else:
                        return
            except (ValueError, OSError, IOError, TypeError):
                log.debug('Error parsing data URI.', exc_info=1)
                return

            # Substitute the right / on Windows, and return the path.
            if os.name == 'nt':
                fn = fn.replace('\\', '/')
            return fn

        # If it's relative, build an absolute URL. If not, return.
        if not url.isRelative():
            return

        url = url.toLocalFile()
        if url.startswith('/'):
            url = url[1:]
        else:
            url = profile.join(path, url)

        # If we're dealing with import, return a relative path.
        if for_import:
            return url

        return self.get_path(url, allow_inheritance, False, _suppress)