Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: remove non-generic parser code #10676

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
stsewd committed Aug 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1c759700d554e133b5d47aca6c8c64fdd0fa4d6e
5 changes: 0 additions & 5 deletions readthedocs/search/tests/data/sphinx/out/requests.json
Original file line number Diff line number Diff line change
@@ -742,11 +742,6 @@
"title": "requests.codes",
"content": "alias of <lookup \u2018status_codes\u2019>"
},
{
"id": "",
"title": "",
"content": "Developer Interface This part of the documentation covers all the interfaces of Requests. For parts where Requests depends on external libraries, we document the most important right here and provide links to the canonical documentation. Main Interface All of Requests\u2019 functionality can be accessed by these 7 methods. They all return an instance of the Response object. Exceptions Request Sessions Lower-Level Classes Lower-Lower-Level Classes Authentication Encodings Cookies Status Code Lookup The codes object defines a mapping from common names for HTTP statuses to their numerical codes, accessible either as attributes or as dictionary items. Example: >>> import requests >>> requests.codes['temporary_redirect'] 307 >>> requests.codes.teapot 418 >>> requests.codes['\\o/'] 200 Some codes have multiple names, and both upper- and lower-case versions of the names are allowed. For example, codes.ok, codes.OK, and codes.okay all correspond to the HTTP status code 200. 100: continue 101: switching_protocols 102: processing 103: checkpoint 122: uri_too_long, request_uri_too_long 200: ok, okay, all_ok, all_okay, all_good, \\o/, \u2713 201: created 202: accepted 203: non_authoritative_info, non_authoritative_information 204: no_content 205: reset_content, reset 206: partial_content, partial 207: multi_status, multiple_status, multi_stati, multiple_stati 208: already_reported 226: im_used 300: multiple_choices 301: moved_permanently, moved, \\o- 302: found 303: see_other, other 304: not_modified 305: use_proxy 306: switch_proxy 307: temporary_redirect, temporary_moved, temporary 308: permanent_redirect, resume_incomplete, resume 400: bad_request, bad 401: unauthorized 402: payment_required, payment 403: forbidden 404: not_found, -o- 405: method_not_allowed, not_allowed 406: not_acceptable 407: proxy_authentication_required, proxy_auth, proxy_authentication 408: request_timeout, timeout 409: conflict 410: gone 411: length_required 412: precondition_failed, precondition 413: request_entity_too_large 414: request_uri_too_large 415: unsupported_media_type, unsupported_media, media_type 416: requested_range_not_satisfiable, requested_range, range_not_satisfiable 417: expectation_failed 418: im_a_teapot, teapot, i_am_a_teapot 421: misdirected_request 422: unprocessable_entity, unprocessable 423: locked 424: failed_dependency, dependency 425: unordered_collection, unordered 426: upgrade_required, upgrade 428: precondition_required, precondition 429: too_many_requests, too_many 431: header_fields_too_large, fields_too_large 444: no_response, none 449: retry_with, retry 450: blocked_by_windows_parental_controls, parental_controls 451: unavailable_for_legal_reasons, legal_reasons 499: client_closed_request 500: internal_server_error, server_error, /o\\, \u2717 501: not_implemented 502: bad_gateway 503: service_unavailable, unavailable 504: gateway_timeout 505: http_version_not_supported, http_version 506: variant_also_negotiates 507: insufficient_storage 509: bandwidth_limit_exceeded, bandwidth 510: not_extended 511: network_authentication_required, network_auth, network_authentication Migrating to 1.x This section details the main differences between 0.x and 1.x and is meant to ease the pain of upgrading. API Changes Response.json is now a callable and not a property of a response. import requests r = requests.get('https://api.github.com/events') r.json() # This *call* raises an exception if JSON decoding fails The Session API has changed. Sessions objects no longer take parameters. Session is also now capitalized, but it can still be instantiated with a lowercase session for backwards compatibility. s = requests.Session() # formerly, session took parameters s.auth = auth s.headers.update(headers) r = s.get('https://httpbin.org/headers') All request hooks have been removed except \u2018response\u2019. Authentication helpers have been broken out into separate modules. See requests-oauthlib and requests-kerberos. The parameter for streaming requests was changed from prefetch to stream and the logic was inverted. In addition, stream is now required for raw response reading. # in 0.x, passing prefetch=False would accomplish the same thing r = requests.get('https://api.github.com/events', stream=True) for chunk in r.iter_content(8192): ... The config parameter to the requests method has been removed. Some of these options are now configured on a Session such as keep-alive and maximum number of redirects. The verbosity option should be handled by configuring logging. import requests import logging # Enabling debugging at http.client level (requests->urllib3->http.client) # you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA. # the only thing missing will be the response.body which is not logged. try: # for Python 3 from http.client import HTTPConnection except ImportError: from httplib import HTTPConnection HTTPConnection.debuglevel = 1 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests logging.getLogger().setLevel(logging.DEBUG) requests_log = logging.getLogger(\"urllib3\") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True requests.get('https://httpbin.org/headers') Licensing One key difference that has nothing to do with the API is a change in the license from the ISC license to the Apache 2.0 license. The Apache 2.0 license ensures that contributions to Requests are also covered by the Apache 2.0 license. Migrating to 2.x Compared with the 1.0 release, there were relatively few backwards incompatible changes, but there are still a few issues to be aware of with this major release. For more details on the changes in this release including new APIs, links to the relevant GitHub issues and some of the bug fixes, read Cory\u2019s blog on the subject. API Changes There were a couple changes to how Requests handles exceptions. RequestException is now a subclass of IOError rather than RuntimeError as that more accurately categorizes the type of error. In addition, an invalid URL escape sequence now raises a subclass of RequestException rather than a ValueError. requests.get('http://%zz/') # raises requests.exceptions.InvalidURL Lastly, httplib.IncompleteRead exceptions caused by incorrect chunked encoding will now raise a Requests ChunkedEncodingError instead. The proxy API has changed slightly. The scheme for a proxy URL is now required. proxies = { \"http\": \"10.10.1.10:3128\", # use http://10.10.1.10:3128 instead } # In requests 1.x, this was legal, in requests 2.x, # this raises requests.exceptions.MissingSchema requests.get(\"http://example.org\", proxies=proxies) Behavioural Changes Keys in the headers dictionary are now native strings on all Python versions, i.e. bytestrings on Python 2 and unicode on Python 3. If the keys are not native strings (unicode on Python 2 or bytestrings on Python 3) they will be converted to the native string type assuming UTF-8 encoding. Values in the headers dictionary should always be strings. This has been the project\u2019s position since before 1.0 but a recent change (since version 2.11.0) enforces this more strictly. It\u2019s advised to avoid passing header values as unicode when possible. \u00a9MMXVIX. A Kenneth Reitz Project."
},
{
"id": "module-requests",
"title": "Developer Interface",
3 changes: 1 addition & 2 deletions readthedocs/search/tests/test_parsers.py
Original file line number Diff line number Diff line change
@@ -268,8 +268,7 @@ def test_sphinx_toctree(self, storage_open, storage_exists):
# Source:
# https://docs.readthedocs.io/en/stable/api/index.html
html_content = data_path / "sphinx/in/toctree.html"
json_content = {"body": html_content.open().read()}
storage_open.side_effect = self._mock_open(json.dumps(json_content))
storage_open.side_effect = self._mock_open(html_content.open().read())
storage_exists.return_value = True

self.version.documentation_type = SPHINX