@@ -58,7 +58,6 @@ def _content_type_is_json(kwargs):
58
58
:param kwargs: A ``dict``. The keyword args supplied to :func:`request` or
59
59
one of the convenience functions like it.
60
60
:returns: ``True`` or ``False``
61
-
62
61
"""
63
62
if 'headers' in kwargs and 'content-type' in kwargs ['headers' ]:
64
63
return kwargs ['headers' ]['content-type' ].lower () == 'application/json'
@@ -75,7 +74,6 @@ def _set_content_type(kwargs):
75
74
:param kwargs: A ``dict``. The keyword args supplied to :func:`request` or
76
75
one of the convenience functions like it.
77
76
:return: Nothing. ``kwargs`` is modified in-place.
78
-
79
77
"""
80
78
if 'files' in kwargs :
81
79
return # requests will automatically set the content-type
@@ -85,7 +83,7 @@ def _set_content_type(kwargs):
85
83
86
84
87
85
def _truncate_data (data , max_len = 500 ):
88
- """Truncate data to a max length"""
86
+ """Truncate data to a max length. """
89
87
if isinstance (data , str | bytes ):
90
88
if len (data ) > max_len :
91
89
return f"{ data [:max_len - 3 ]} ..."
@@ -103,7 +101,6 @@ def _log_request(method, url, kwargs, data=None, params=None):
103
101
one can pass to ``requests.request``.
104
102
105
103
:return: Nothing is returned.
106
-
107
104
"""
108
105
logger .debug (
109
106
'Making HTTP %s request to %s with %s, %s and %s.' ,
@@ -123,7 +120,6 @@ def _log_response(response):
123
120
the object returned is logged.
124
121
125
122
:return: Nothing is returned.
126
-
127
123
"""
128
124
message = f'Received HTTP { response .status_code } response: { response .text } '
129
125
if not response .ok :
@@ -133,7 +129,7 @@ def _log_response(response):
133
129
134
130
135
131
def request (method , url , ** kwargs ):
136
- """A wrapper for ``requests.request``."""
132
+ """Wrap ``requests.request``."""
137
133
_set_content_type (kwargs )
138
134
if _content_type_is_json (kwargs ) and kwargs .get ('data' ) is not None :
139
135
kwargs ['data' ] = dumps (kwargs ['data' ])
@@ -144,7 +140,7 @@ def request(method, url, **kwargs):
144
140
145
141
146
142
def head (url , ** kwargs ):
147
- """A wrapper for ``requests.head``."""
143
+ """Wrap ``requests.head``."""
148
144
_set_content_type (kwargs )
149
145
if _content_type_is_json (kwargs ) and kwargs .get ('data' ) is not None :
150
146
kwargs ['data' ] = dumps (kwargs ['data' ])
@@ -155,7 +151,7 @@ def head(url, **kwargs):
155
151
156
152
157
153
def get (url , params = None , ** kwargs ):
158
- """A wrapper for ``requests.get``."""
154
+ """Wrap ``requests.get``."""
159
155
_set_content_type (kwargs )
160
156
if _content_type_is_json (kwargs ) and kwargs .get ('data' ) is not None :
161
157
kwargs ['data' ] = dumps (kwargs ['data' ])
@@ -166,7 +162,7 @@ def get(url, params=None, **kwargs):
166
162
167
163
168
164
def post (url , data = None , json = None , ** kwargs ):
169
- """A wrapper for ``requests.post``."""
165
+ """Wrap ``requests.post``."""
170
166
_set_content_type (kwargs )
171
167
if _content_type_is_json (kwargs ) and data is not None :
172
168
data = dumps (data )
@@ -177,7 +173,7 @@ def post(url, data=None, json=None, **kwargs):
177
173
178
174
179
175
def put (url , data = None , ** kwargs ):
180
- """A wrapper for ``requests.put``. Sends a PUT request."""
176
+ """Wrap ``requests.put``. Sends a PUT request."""
181
177
_set_content_type (kwargs )
182
178
if _content_type_is_json (kwargs ) and data is not None :
183
179
data = dumps (data )
@@ -188,7 +184,7 @@ def put(url, data=None, **kwargs):
188
184
189
185
190
186
def patch (url , data = None , ** kwargs ):
191
- """A wrapper for ``requests.patch``. Sends a PATCH request."""
187
+ """Wrap ``requests.patch``. Sends a PATCH request."""
192
188
_set_content_type (kwargs )
193
189
if _content_type_is_json (kwargs ) and data is not None :
194
190
data = dumps (data )
@@ -199,7 +195,7 @@ def patch(url, data=None, **kwargs):
199
195
200
196
201
197
def delete (url , ** kwargs ):
202
- """A wrapper for ``requests.delete``. Sends a DELETE request."""
198
+ """Wrap ``requests.delete``. Sends a DELETE request."""
203
199
_set_content_type (kwargs )
204
200
if _content_type_is_json (kwargs ) and kwargs .get ('data' ) is not None :
205
201
kwargs ['data' ] = dumps (kwargs ['data' ])
0 commit comments