mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-16 22:10:26 +00:00
Replace deprecated http.server.CGIHTTPRequestHandler for TestLoginUrl
Scheduled for removal in Python 3.15.
This commit is contained in:
parent
1ffb62a1f0
commit
c3d0787654
3 changed files with 15 additions and 31 deletions
|
|
@ -1,11 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from http import cookies
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
C = cookies.SimpleCookie()
|
||||
for field, value in urllib.parse.parse_qsl(sys.stdin.read()):
|
||||
C[field] = value
|
||||
|
||||
print(C)
|
||||
|
|
@ -18,9 +18,8 @@ Define http test support classes for LinkChecker tests.
|
|||
"""
|
||||
|
||||
import html
|
||||
from http.server import CGIHTTPRequestHandler, SimpleHTTPRequestHandler, HTTPServer
|
||||
from http.server import SimpleHTTPRequestHandler, HTTPServer
|
||||
from http.client import HTTPConnection, HTTPSConnection
|
||||
import os.path
|
||||
import ssl
|
||||
import time
|
||||
import threading
|
||||
|
|
@ -304,18 +303,3 @@ class CookieRedirectHttpRequestHandler(NoQueryHttpRequestHandler):
|
|||
self.redirect()
|
||||
else:
|
||||
super().do_HEAD()
|
||||
|
||||
|
||||
class CGIHandler(CGIHTTPRequestHandler, StoppableHttpRequestHandler):
|
||||
cgi_path = "/tests/checker/cgi-bin/"
|
||||
|
||||
def is_cgi(self):
|
||||
# CGIHTTPRequestHandler.is_cgi() can only handle a single-level path
|
||||
# override so that we can store scripts under /tests/checker
|
||||
if CGIHandler.cgi_path in self.path:
|
||||
self.cgi_info = (
|
||||
CGIHandler.cgi_path,
|
||||
os.path.relpath(self.path, CGIHandler.cgi_path),
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright (C) 2020 Chris Mayo
|
||||
# Copyright (C) 2020-2023 Chris Mayo
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -18,17 +18,28 @@ Test director.aggregator.Aggregate.visit_loginurl().
|
|||
This includes the retrieval and search of a login form and posting credentials.
|
||||
"""
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
from .httpserver import HttpServerTest, CGIHandler
|
||||
from .httpserver import HttpServerTest, StoppableHttpRequestHandler
|
||||
from . import get_test_aggregate
|
||||
|
||||
|
||||
class LoginPostHandler(StoppableHttpRequestHandler):
|
||||
def do_POST(self):
|
||||
length = int(self.headers.get("content-length"))
|
||||
form_data = self.rfile.read(length).decode()
|
||||
self.send_response(200)
|
||||
for name, value in urllib.parse.parse_qsl(form_data):
|
||||
self.send_header("Set-Cookie", f"{name}={value}")
|
||||
self.end_headers()
|
||||
|
||||
|
||||
class TestLoginUrl(HttpServerTest):
|
||||
"""Test loginurl retrieval, search and posting credentials."""
|
||||
|
||||
def __init__(self, methodName="runTest"):
|
||||
super().__init__(methodName=methodName)
|
||||
self.handler = CGIHandler
|
||||
self.handler = LoginPostHandler
|
||||
|
||||
def visit_loginurl(self, page, user=None, password=None, extrafields=False):
|
||||
confargs = {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue