예제 #1
0
파일: auth.py 프로젝트: kovidgoyal/vise
def get_http_auth_credentials(qurl, authenticator, parent=None):
    qurl = QUrl(qurl)
    qurl.setFragment(None)
    realm = authenticator.realm()
    trealm = (' (%s)' % realm) if realm else ''
    ac = parent and parent.get_login_credentials(qurl.toString())
    d = Credentials(
        _('Please specify a password for {0}{1}').format(
            qurl.toString(), trealm), parent)
    if ac is not None:
        if ac['autologin']:
            authenticator.setUser(ac['username'])
            authenticator.setPassword(ac['password'])
            return
        d.credentials = ac['username'], ac['password']

    if d.exec() == QDialog.DialogCode.Accepted:
        username, password = d.credentials
        authenticator.setUser(username)
        authenticator.setPassword(password)
        if parent is not None:
            parent.on_login_form_submit(qurl.toString(), username, password)
    else:
        if parent is not None:
            parent.setHtml(
                '<p style="font-family:sans-serif">{} {}</p>'.format(
                    _('Authentication required to access: '),
                    '<a href="{0}">{0}</a>'.format(qurl.toDisplayString())))
예제 #2
0
파일: auth.py 프로젝트: kovidgoyal/vise
def get_proxy_auth_credentials(qurl, authenticator, proxy_host, parent=None):
    qurl = QUrl(qurl)
    qurl.setFragment(None)
    d = Credentials(
        _('Please specify a password for {0} at the proxy: {1}').format(
            qurl.toString(), proxy_host), parent)
    if d.exec() == d.Accepted:
        username, password = d.credentials
        authenticator.setUser(username)
        authenticator.setPassword(password)
예제 #3
0
    def _create_empty_request(self, path: str) -> QNetworkRequest:
        """"Creates an empty HTTP request (GET or POST).

    Args:
      path: HTTP relative path.
    """
        url = QUrl(f'http://{self._ip_address}{path}')
        Logger.log('d', url.toString())
        request = QNetworkRequest(url)
        if USE_QT5:
            request.setAttribute(QNetworkRequest.FollowRedirectsAttribute,
                                 True)
        else:
            # FollowRedirectsAttribute was deprecated in PyQt6.
            # https://doc.qt.io/qt-6/network-changes-qt6.html#redirect-policies.
            request.setAttribute(
                QNetworkRequest.Attribute.RedirectPolicyAttribute,
                QNetworkRequest.RedirectPolicy.ManualRedirectPolicy)
        return request