brain_responses.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  2. # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
  4. """
  5. Astroid hooks for responses.
  6. It might need to be manually updated from the public methods of
  7. :class:`responses.RequestsMock`.
  8. See: https://github.com/getsentry/responses/blob/master/responses.py
  9. """
  10. from astroid import nodes
  11. from astroid.brain.helpers import register_module_extender
  12. from astroid.builder import parse
  13. from astroid.manager import AstroidManager
  14. def responses_funcs() -> nodes.Module:
  15. return parse(
  16. """
  17. DELETE = "DELETE"
  18. GET = "GET"
  19. HEAD = "HEAD"
  20. OPTIONS = "OPTIONS"
  21. PATCH = "PATCH"
  22. POST = "POST"
  23. PUT = "PUT"
  24. response_callback = None
  25. def reset():
  26. return
  27. def add(
  28. method=None, # method or ``Response``
  29. url=None,
  30. body="",
  31. adding_headers=None,
  32. *args,
  33. **kwargs
  34. ):
  35. return
  36. def add_passthru(prefix):
  37. return
  38. def remove(method_or_response=None, url=None):
  39. return
  40. def replace(method_or_response=None, url=None, body="", *args, **kwargs):
  41. return
  42. def add_callback(
  43. method, url, callback, match_querystring=False, content_type="text/plain"
  44. ):
  45. return
  46. calls = []
  47. def __enter__():
  48. return
  49. def __exit__(type, value, traceback):
  50. success = type is None
  51. return success
  52. def activate(func):
  53. return func
  54. def start():
  55. return
  56. def stop(allow_assert=True):
  57. return
  58. """
  59. )
  60. def register(manager: AstroidManager) -> None:
  61. register_module_extender(manager, "responses", responses_funcs)