Skip to content

Commit 0c54f5c

Browse files
committed
#533 - AbcTK now uses requests library for all http request
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 07a974a commit 0c54f5c

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

src/attributecode/api.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ def request_license_data(api_url, api_key, license_key):
5454
license_data = {}
5555
errors = []
5656
try:
57-
# request = Request(quoted_url, headers=headers)
58-
# response = urlopen(request)
59-
# response_content = response.read().decode('utf-8')
6057
response = get(quoted_url, headers=headers)
6158
response_content = response.text
6259
# FIXME: this should be an ordered dict

src/attributecode/model.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131
import traceback
3232
from itertools import zip_longest
3333

34-
import urllib
3534
from urllib.parse import urljoin
3635
from urllib.parse import urlparse
37-
from urllib.request import urlopen
38-
from urllib.request import Request
39-
from urllib.error import HTTPError
4036

4137
from license_expression import Licensing
4238
from packageurl import PackageURL
@@ -1828,15 +1824,14 @@ def pre_process_and_fetch_license_dict(abouts, from_check=False, api_url=None, a
18281824
license_url = url + lic_key + '.json'
18291825
license_text_url = url + lic_key + '.LICENSE'
18301826
try:
1831-
json_url = urlopen(license_url)
1832-
# We don't want to actually get the license information from the
1833-
# check utility
1827+
json_url_content = get(license_url).text
1828+
# We don't want to actually get the license
1829+
# information from the check utility
18341830
if from_check:
18351831
continue
1836-
data = json.loads(json_url.read())
1832+
data = json.loads(json_url_content)
18371833
license_name = data['short_name']
1838-
license_text = urllib.request.urlopen(
1839-
license_text_url).read().decode('utf-8')
1834+
license_text = get(license_text_url).text
18401835
license_filename = data['key'] + '.LICENSE'
18411836
lic_url = url + license_filename
18421837
spdx_license_key = data['spdx_license_key']

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_api_request_license_data_without_result(self, mock_data):
7575
expected = ({}, [Error(ERROR, "Invalid 'license': apache-2.0")])
7676
assert expected == license_data
7777

78-
@mock.patch.object(api, 'urlopen')
78+
@mock.patch.object(api, 'get')
7979
def test_api_request_license_data_with_incorrect_url(self, mock_data):
8080
# Some URL that is accessible but not a correct API URL
8181
response_content = b'<html></html>'

0 commit comments

Comments
 (0)