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"""
6Astroid hooks for responses.
7
8It might need to be manually updated from the public methods of
9:class:`responses.RequestsMock`.
10
11See: https://github.com/getsentry/responses/blob/master/responses.py
12"""
13from astroid import nodes
14from astroid.brain.helpers import register_module_extender
15from astroid.builder import parse
16from astroid.manager import AstroidManager
17
18
19def responses_funcs() -> nodes.Module:
20 return parse(
21 """
22 DELETE = "DELETE"
23 GET = "GET"
24 HEAD = "HEAD"
25 OPTIONS = "OPTIONS"
26 PATCH = "PATCH"
27 POST = "POST"
28 PUT = "PUT"
29 response_callback = None
30
31 def reset():
32 return
33
34 def add(
35 method=None, # method or ``Response``
36 url=None,
37 body="",
38 adding_headers=None,
39 *args,
40 **kwargs
41 ):
42 return
43
44 def add_passthru(prefix):
45 return
46
47 def remove(method_or_response=None, url=None):
48 return
49
50 def replace(method_or_response=None, url=None, body="", *args, **kwargs):
51 return
52
53 def add_callback(
54 method, url, callback, match_querystring=False, content_type="text/plain"
55 ):
56 return
57
58 calls = []
59
60 def __enter__():
61 return
62
63 def __exit__(type, value, traceback):
64 success = type is None
65 return success
66
67 def activate(func):
68 return func
69
70 def start():
71 return
72
73 def stop(allow_assert=True):
74 return
75 """
76 )
77
78
79def register(manager: AstroidManager) -> None:
80 register_module_extender(manager, "responses", responses_funcs)