Skip to content

Commit

Permalink
Merge branch 'master' into add_types
Browse files Browse the repository at this point in the history
  • Loading branch information
adbar authored Oct 18, 2024
2 parents e735b9b + 6dedfbf commit 6fb4ec3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 0 additions & 2 deletions tests/downloads_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def test_fetch():
'''Test URL fetching.'''
# sanity check
assert _send_urllib_request('', True, False, DEFAULT_CONFIG) is None
with pytest.raises(ValueError):
fetch_url("https://example.org", decode=False)

# fetch_url
assert fetch_url('#@1234') is None
Expand Down
13 changes: 3 additions & 10 deletions trafilatura/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ def _handle_response(

def fetch_url(
url: str,
decode: bool = True,
no_ssl: bool = False,
config: ConfigParser = DEFAULT_CONFIG,
options: Optional[Extractor] = None,
Expand All @@ -233,25 +232,19 @@ def fetch_url(
Args:
url: URL of the page to fetch.
no_ssl: Don't try to establish a secure connection (to prevent SSLError).
no_ssl: Do not try to establish a secure connection (to prevent SSLError).
config: Pass configuration values for output control.
options: Extraction options (supersedes config).
Returns:
Unicode string or None in case of failed downloads and invalid results.
"""
if not decode:
raise ValueError(
"Raw response objects are deprecated for fetch_url(), use fetch_response() instead."
)
response = fetch_response(url, decode=decode, no_ssl=no_ssl, config=config)
response = fetch_response(url, decode=True, no_ssl=no_ssl, config=config)
if response and response.data:
if not options:
options = Extractor(config=config)
return _handle_response(url, response, decode, options)
# return '' (useful do discard further processing?)
# return response
return _handle_response(url, response, True, options)
return None


Expand Down

0 comments on commit 6fb4ec3

Please sign in to comment.