1717from pyld .jsonld import (JsonLdError , parse_link_header , prepend_base , LINK_HEADER_REL )
1818
1919
20- def requests_document_loader (secure = False , max_link_follows = 2 , ** kwargs ):
20+ def requests_document_loader (secure = False , ** kwargs ):
2121 """
2222 Create a Requests document loader.
2323 Can be used to setup extra Requests args such as verify, cert, timeout,
2424 or others.
2525 :param secure: require all requests to use HTTPS (default: False).
26- :param max_link_follows: Maximum number of alternate link follows allowed.
2726 :param **kwargs: extra keyword args for Requests get() call.
2827 :return: the RemoteDocument loader function.
2928 """
3029 import requests
3130
32- def loader (url , options = {}, link_follow_count = 0 ):
31+ def loader (url , options = {}):
3332 """
3433 Retrieves JSON-LD at the given URL.
3534 :param url: the URL to retrieve.
@@ -69,8 +68,6 @@ def loader(url, options={}, link_follow_count=0):
6968 'documentUrl' : response .url ,
7069 'document' : None
7170 }
72- # Try loading the JSON if the content_type matches
73- # A failure here means the response body is not valid json
7471 if re .match (r'^application\/(\w*\+)?json$' , content_type ):
7572 doc ['document' ] = response .json ()
7673 # if content_type in headers['Accept']:
@@ -97,9 +94,7 @@ def loader(url, options={}, link_follow_count=0):
9794 not re .match (r'^application\/(\w*\+)?json$' , content_type )):
9895 doc ['contentType' ] = 'application/ld+json'
9996 doc ['documentUrl' ] = prepend_base (url , linked_alternate ['target' ])
100- if link_follow_count >= max_link_follows :
101- raise requests .TooManyRedirects (f"Exceeded maximum link header redirects ({ max_link_follows } )" )
102- return loader (doc ['documentUrl' ], options = options , link_follow_count = link_follow_count + 1 )
97+ return loader (doc ['documentUrl' ], options = options )
10398 return doc
10499 except JsonLdError as e :
105100 raise e
0 commit comments