def fetch_document(url=None, host=None, path="<STR_LIT:/>", timeout=<NUM_LIT:10>, raise_ssl_errors=True, extra_headers=None):
if not url and not host:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>logger.debug("<STR_LIT>",<EOL>url, host, path, timeout, raise_ssl_errors)<EOL>headers = {'<STR_LIT>': USER_AGENT}<EOL>if extra_headers:<EOL><INDENT>headers.update(extra_headers)<EOL><DEDENT>if url:<EOL><INDENT>logger.debug("<STR_LIT>", url)<EOL>try:<EOL><INDENT>response = requests.get(url, timeout=timeout, headers=headers)<EOL>logger.debug("<STR_LIT>", response.status_code)<EOL>return response.text, response.status_code, None<EOL><DEDENT>except RequestException as ex:<EOL><INDENT>logger.debug("<STR_LIT>", ex)<EOL>return None, None, ex<EOL><DEDENT><DEDENT>host_string = host.replace("<STR_LIT>", "<STR_LIT>").replace("<STR_LIT>", "<STR_LIT>").strip("<STR_LIT:/>")<EOL>path_string = path if path.startswith("<STR_LIT:/>") else "<STR_LIT>" % path<EOL>url = "<STR_LIT>" % (host_string, path_string)<EOL>logger.debug("<STR_LIT>", url)<EOL>try:<EOL><INDENT>response = requests.get(url, timeout=timeout, headers=headers)<EOL>logger.debug("<STR_LIT>", response.status_code)<EOL>response.raise_for_status()<EOL>return response.text, response.status_code, None<EOL><DEDENT>except (HTTPError, SSLError, ConnectionError) as ex:<EOL><INDENT>if isinstance(ex, SSLError) and raise_ssl_errors:<EOL><INDENT>logger.debug("<STR_LIT>", ex)<EOL>return None, None, ex<EOL><DEDENT>url = url.replace("<STR_LIT>", "<STR_LIT>")<EOL>logger.debug("<STR_LIT>", url)<EOL>try:<EOL><INDENT>response = requests.get(url, timeout=timeout, headers=headers)<EOL>logger.debug("<STR_LIT>", response.status_code)<EOL>response.raise_for_status()<EOL>return response.text, response.status_code, None<EOL><DEDENT>except RequestException as ex:<EOL><INDENT>logger.debug("<STR_LIT>", ex)<EOL>return None, None, ex<EOL><DEDENT><DEDENT>except RequestException as ex:<EOL><INDENT>logger.debug("<STR_LIT>", ex)<EOL>return None, None, ex<EOL><DEDENT>
Helper method to fetch remote document.

    Must be given either the ``url`` or ``host``.
    If ``url`` is given, only that will be tried without falling back to http from https.
    If ``host`` given, `path` will be added to it. Will fall back to http on non-success status code.

    :arg url: Full url to fetch, including protocol
    :arg host: Domain part only without path or protocol
    :arg path: Path without domain (defaults to "/")
    :arg timeout: Seconds to wait for response (defaults to 10)
    :arg raise_ssl_errors: Pass False if you want to try HTTP even for sites with SSL errors (default True)
    :returns: Tuple of document (str or None), status code (int or None) and error (an exception class instance or None)
    :raises ValueError: If neither url nor host are given as parameters