mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-23 23:54:44 +00:00
Remove unused url.get_content()
This commit is contained in:
parent
e4ba9c84ce
commit
e372657fb8
2 changed files with 1 additions and 53 deletions
|
|
@ -21,10 +21,6 @@ import os
|
|||
import re
|
||||
import urllib.parse
|
||||
|
||||
import requests
|
||||
|
||||
from . import log, LOG_CHECK
|
||||
|
||||
for scheme in ('ldap', 'irc'):
|
||||
if scheme not in urllib.parse.uses_netloc:
|
||||
urllib.parse.uses_netloc.append(scheme)
|
||||
|
|
@ -479,50 +475,6 @@ def splitport(host, port=0):
|
|||
return host, port
|
||||
|
||||
|
||||
def get_content(url, user=None, password=None, proxy=None, data=None, addheaders=None):
|
||||
"""Get URL content and info.
|
||||
|
||||
@return: (decoded text content of URL, headers) or
|
||||
(None, errmsg) on error.
|
||||
@rtype: tuple (String, dict) or (None, String)
|
||||
"""
|
||||
from . import configuration
|
||||
|
||||
headers = {
|
||||
'User-Agent': configuration.UserAgent,
|
||||
}
|
||||
if addheaders:
|
||||
headers.update(addheaders)
|
||||
method = 'GET'
|
||||
kwargs = dict(headers=headers)
|
||||
if user and password:
|
||||
kwargs['auth'] = (user, password)
|
||||
if data:
|
||||
kwargs['data'] = data
|
||||
method = 'POST'
|
||||
if proxy:
|
||||
kwargs['proxy'] = dict(http=proxy)
|
||||
from .configuration import get_share_file
|
||||
|
||||
try:
|
||||
kwargs["verify"] = get_share_file('cacert.pem')
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
response = requests.request(method, url, **kwargs)
|
||||
return response.text, response.headers
|
||||
except (
|
||||
requests.exceptions.RequestException,
|
||||
requests.exceptions.BaseHTTPError,
|
||||
) as msg:
|
||||
log.warn(
|
||||
LOG_CHECK,
|
||||
("Could not get content of URL %(url)s: %(msg)s.")
|
||||
% {"url": url, "msg": str(msg)},
|
||||
)
|
||||
return None, str(msg)
|
||||
|
||||
|
||||
def shorten_duplicate_content_url(url):
|
||||
"""Remove anchor part and trailing index.html from URL."""
|
||||
if '#' in url:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
"""
|
||||
Test url routines.
|
||||
"""
|
||||
from . import need_network, need_posix, need_windows
|
||||
from . import need_posix, need_windows
|
||||
import unittest
|
||||
import os
|
||||
import re
|
||||
|
|
@ -547,10 +547,6 @@ class TestUrl(unittest.TestCase):
|
|||
self.assertTrue(is_safe_domain("a-b.example.com"))
|
||||
self.assertTrue(is_safe_domain("x1.example.com"))
|
||||
|
||||
@need_network
|
||||
def test_get_content(self):
|
||||
linkcheck.url.get_content("http://www.debian.org/")
|
||||
|
||||
def test_duplicate_urls(self):
|
||||
is_dup = linkcheck.url.is_duplicate_content_url
|
||||
self.assertTrue(is_dup("http://example.org", "http://example.org"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue