locust 2.29.1.dev4__py3-none-any.whl → 2.29.1.dev31__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
locust/__init__.py CHANGED
@@ -12,7 +12,8 @@ if os.getenv("LOCUST_PLAYWRIGHT", None):
12
12
 
13
13
  from gevent import monkey
14
14
 
15
- monkey.patch_all()
15
+ if not os.getenv("LOCUST_SKIP_MONKEY_PATCH", None):
16
+ monkey.patch_all()
16
17
 
17
18
  from ._version import version as __version__
18
19
  from .contrib.fasthttp import FastHttpUser
locust/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '2.29.1.dev4'
16
- __version_tuple__ = version_tuple = (2, 29, 1, 'dev4')
15
+ __version__ = version = '2.29.1.dev31'
16
+ __version_tuple__ = version_tuple = (2, 29, 1, 'dev31')
locust/clients.py CHANGED
@@ -2,8 +2,8 @@ from __future__ import annotations
2
2
 
3
3
  import re
4
4
  import time
5
- from collections.abc import Generator
6
5
  from contextlib import contextmanager
6
+ from typing import TYPE_CHECKING
7
7
  from urllib.parse import urlparse, urlunparse
8
8
 
9
9
  import requests
@@ -15,6 +15,41 @@ from urllib3 import PoolManager
15
15
 
16
16
  from .exception import CatchResponseError, LocustError, ResponseError
17
17
 
18
+ if TYPE_CHECKING:
19
+ import sys
20
+ from collections.abc import Callable, Generator, Iterable, Mapping, MutableMapping
21
+ from typing import Any, TypedDict
22
+
23
+ from requests.cookies import RequestsCookieJar
24
+
25
+ if sys.version_info >= (3, 11):
26
+ from typing import Unpack
27
+ else:
28
+ from typing_extensions import Unpack
29
+
30
+ # Annotations below were generated using output from mypy.
31
+ # Mypy underneath uses information from the https://github.com/python/typeshed repo.
32
+
33
+ class RequestKwargs(TypedDict, total=False):
34
+ params: Any | None # simplified signature
35
+ headers: Mapping[str, str | bytes | None] | None
36
+ cookies: RequestsCookieJar | MutableMapping[str, str] | None
37
+ files: Any | None # simplified signature
38
+ auth: Any | None # simplified signature
39
+ timeout: float | tuple[float, float] | tuple[float, None] | None
40
+ allow_redirects: bool
41
+ proxies: MutableMapping[str, str] | None
42
+ hooks: Mapping[str, Iterable[Callable[[Response], Any]] | Callable[[Response], Any]] | None
43
+ stream: bool | None
44
+ verify: bool | str | None
45
+ cert: str | tuple[str, str] | None
46
+
47
+ class RESTKwargs(RequestKwargs, total=False):
48
+ name: str | None
49
+ catch_response: bool
50
+ context: dict
51
+
52
+
18
53
  absolute_http_url_regexp = re.compile(r"^https?://", re.I)
19
54
 
20
55
 
@@ -94,7 +129,18 @@ class HttpSession(requests.Session):
94
129
  finally:
95
130
  self.request_name = None
96
131
 
97
- def request(self, method, url, name=None, catch_response=False, context={}, **kwargs):
132
+ def request( # type: ignore[override]
133
+ self,
134
+ method: str | bytes,
135
+ url: str | bytes,
136
+ name: str | None = None,
137
+ catch_response: bool = False,
138
+ context: dict = {},
139
+ *,
140
+ data: Any | None = None,
141
+ json: Any | None = None,
142
+ **kwargs: Unpack[RequestKwargs],
143
+ ):
98
144
  """
99
145
  Constructs and sends a :py:class:`requests.Request`.
100
146
  Returns :py:class:`requests.Response` object.
@@ -108,7 +154,8 @@ class HttpSession(requests.Session):
108
154
  response, even if the response code is ok (2xx). The opposite also works, one can use catch_response to catch a request
109
155
  and then mark it as successful even if the response code was not (i.e 500 or 404).
110
156
  :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
111
- :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
157
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`.
158
+ :param json: (optional) json to send in the body of the :class:`Request`.
112
159
  :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
113
160
  :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
114
161
  :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload.
@@ -117,9 +164,17 @@ class HttpSession(requests.Session):
117
164
  :type timeout: float or tuple
118
165
  :param allow_redirects: (optional) Set to True by default.
119
166
  :type allow_redirects: bool
120
- :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
167
+ :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
168
+ :param hooks: (optional) Dictionary mapping hook name to one event or list of events, event must be callable.
121
169
  :param stream: (optional) whether to immediately download the response content. Defaults to ``False``.
122
- :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
170
+ :param verify: (optional) Either a boolean, in which case it controls whether we verify
171
+ the server's TLS certificate, or a string, in which case it must be a path
172
+ to a CA bundle to use. Defaults to ``True``. When set to
173
+ ``False``, requests will accept any TLS certificate presented by
174
+ the server, and will ignore hostname mismatches and/or expired
175
+ certificates, which will make your application vulnerable to
176
+ man-in-the-middle (MitM) attacks. Setting verify to ``False``
177
+ may be useful during local development or testing.
123
178
  :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
124
179
  """
125
180
 
@@ -132,7 +187,7 @@ class HttpSession(requests.Session):
132
187
 
133
188
  start_time = time.time()
134
189
  start_perf_counter = time.perf_counter()
135
- response = self._send_request_safe_mode(method, url, **kwargs)
190
+ response = self._send_request_safe_mode(method, url, data=data, json=json, **kwargs)
136
191
  response_time = (time.perf_counter() - start_perf_counter) * 1000
137
192
 
138
193
  request_before_redirect = (response.history and response.history[0] or response).request
@@ -187,6 +242,80 @@ class HttpSession(requests.Session):
187
242
  r.request = Request(method, url).prepare()
188
243
  return r
189
244
 
245
+ def get(
246
+ self, url: str | bytes, *, data: Any | None = None, json: Any | None = None, **kwargs: Unpack[RESTKwargs]
247
+ ) -> ResponseContextManager | Response | LocustResponse:
248
+ """Sends a GET request"""
249
+ kwargs.setdefault("allow_redirects", True)
250
+ return self.request("GET", url, data=data, json=json, **kwargs)
251
+
252
+ def options(
253
+ self,
254
+ url: str | bytes,
255
+ *,
256
+ data: Any | None = None,
257
+ json: Any | None = None,
258
+ **kwargs: Unpack[RESTKwargs],
259
+ ) -> ResponseContextManager | Response | LocustResponse:
260
+ """Sends a OPTIONS request"""
261
+ kwargs.setdefault("allow_redirects", True)
262
+ return self.request("OPTIONS", url, data=data, json=json, **kwargs)
263
+
264
+ def head(
265
+ self,
266
+ url: str | bytes,
267
+ *,
268
+ data: Any | None = None,
269
+ json: Any | None = None,
270
+ **kwargs: Unpack[RESTKwargs],
271
+ ) -> ResponseContextManager | Response | LocustResponse:
272
+ """Sends a HEAD request"""
273
+ kwargs.setdefault("allow_redirects", False)
274
+ return self.request("HEAD", url, data=data, json=json, **kwargs)
275
+
276
+ def post(
277
+ self,
278
+ url: str | bytes,
279
+ data: Any | None = None,
280
+ json: Any | None = None,
281
+ **kwargs: Unpack[RESTKwargs],
282
+ ) -> ResponseContextManager | Response | LocustResponse:
283
+ """Sends a POST request"""
284
+ return self.request("POST", url, data=data, json=json, **kwargs)
285
+
286
+ def put(
287
+ self,
288
+ url: str | bytes,
289
+ data: Any | None = None,
290
+ *,
291
+ json: Any | None = None,
292
+ **kwargs: Unpack[RESTKwargs],
293
+ ) -> ResponseContextManager | Response | LocustResponse:
294
+ """Sends a PUT request"""
295
+ return self.request("PUT", url, data=data, json=json, **kwargs)
296
+
297
+ def patch(
298
+ self,
299
+ url: str | bytes,
300
+ data: Any | None = None,
301
+ *,
302
+ json: Any | None = None,
303
+ **kwargs: Unpack[RESTKwargs],
304
+ ) -> ResponseContextManager | Response | LocustResponse:
305
+ """Sends a PATCH request"""
306
+ return self.request("PATCH", url, data=data, json=json, **kwargs)
307
+
308
+ def delete(
309
+ self,
310
+ url: str | bytes,
311
+ *,
312
+ data: Any | None = None,
313
+ json: Any | None = None,
314
+ **kwargs: Unpack[RESTKwargs],
315
+ ) -> ResponseContextManager | Response | LocustResponse:
316
+ """Sends a DELETE request"""
317
+ return self.request("DELETE", url, data=data, json=json, **kwargs)
318
+
190
319
 
191
320
  class ResponseContextManager(LocustResponse):
192
321
  """
@@ -211,7 +340,7 @@ class ResponseContextManager(LocustResponse):
211
340
  self._entered = True
212
341
  return self
213
342
 
214
- def __exit__(self, exc, value, traceback):
343
+ def __exit__(self, exc, value, traceback): # type: ignore[override]
215
344
  # if the user has already manually marked this response as failure or success
216
345
  # we can ignore the default behaviour of letting the response code determine the outcome
217
346
  if self._manual_result is not None:
locust/event.py CHANGED
@@ -61,7 +61,9 @@ class EventHook:
61
61
 
62
62
  Example usage (in a task):
63
63
 
64
- with self.environment.events.request.measure("myrequestType", "myRequestName") as request_meta:
64
+ .. code-block:: python
65
+
66
+ with self.environment.events.request.measure("requestType", "requestName") as request_meta:
65
67
  # do the stuff you want to measure
66
68
 
67
69
  You can optionally add/overwrite entries in the request_meta dict and they will be passed to the request event.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: locust
3
- Version: 2.29.1.dev4
3
+ Version: 2.29.1.dev31
4
4
  Summary: Developer-friendly load testing framework
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/locustio/locust
@@ -39,6 +39,7 @@ Requires-Dist: Flask-Login >=0.6.3
39
39
  Requires-Dist: Flask-Cors >=3.0.10
40
40
  Requires-Dist: pywin32 ; platform_system == "Windows"
41
41
  Requires-Dist: tomli >=1.1.0 ; python_version < "3.11"
42
+ Requires-Dist: typing-extensions >=4.6.0 ; python_version < "3.11"
42
43
  Requires-Dist: requests >=2.32.2 ; python_version > "3.11"
43
44
 
44
45
  # Locust
@@ -1,12 +1,12 @@
1
- locust/__init__.py,sha256=g6oA-Ba_hs3gLWVf5MKJ1mvfltI8MFnDWG8qslqm8yg,1402
1
+ locust/__init__.py,sha256=Hmw2vNf75eLQ1mQIPXAwlQrJ_XFY65MOb92fGsNCukQ,1458
2
2
  locust/__main__.py,sha256=vBQ82334kX06ImDbFlPFgiBRiLIinwNk3z8Khs6hd74,31
3
- locust/_version.py,sha256=MizKAMwPqZtmBXP0ZwKFTJ_-4wik36hnXaD3a16Jbhg,426
3
+ locust/_version.py,sha256=4_aPghH9jy3XETUhOBI9pUPtDewJ26sTX2m1Doiuzys,428
4
4
  locust/argument_parser.py,sha256=sjQoJ1NTac9LdNYT7zn8RajlWqBQs8YFNv6uRExb2gg,28941
5
- locust/clients.py,sha256=YKuAyMAbxs8_-w7XJw0hc67KFBNNLxibsw6FwiS01Q8,14781
5
+ locust/clients.py,sha256=M9hOrS1ORRGAV1_419_bvD_bRZxA5A1SJkI-ouSmAkQ,19600
6
6
  locust/debug.py,sha256=We6Z9W0btkKSc7PxWmrZx-xMynvOOsKhG6jmDgQin0g,5134
7
7
  locust/dispatch.py,sha256=vYh0QEDFgJ3hY0HgSk-EiNO7IP9ffzXF_Et8wB9JvsI,16995
8
8
  locust/env.py,sha256=sP-fCnZs0e2xodRemLHgTgyyUt5eezwtdA9WsCoqJkQ,12767
9
- locust/event.py,sha256=m-egSPfOEd1Q6HEXx5lB0LlXOuEdzeS7B1XSFIDgRy0,7836
9
+ locust/event.py,sha256=H2SuxyadPMsRY-LQ6MuK1okHls9lYsS9GgXIDSxpi50,7864
10
10
  locust/exception.py,sha256=jGgJ32ubuf4pWdlaVOkbh2Y0LlG0_DHi-lv3ib8ppOE,1791
11
11
  locust/html.py,sha256=_n3aB3fxiYzSeE_7RqHF3iiEPjPnbQ3e2Pw9P8AVtPU,3920
12
12
  locust/input_events.py,sha256=ZIyePyAMuA_YFYWg18g_pE4kwuQV3RbEB250MzXRwjY,3314
@@ -71,9 +71,9 @@ locust/webui/dist/report.html,sha256=sOdZZVgZbqgu86BBCSQf3uQUYXgmgSnXF32JpnyAII8
71
71
  locust/webui/dist/assets/favicon.ico,sha256=IUl-rYqfpHdV38e-s0bkmFIeLS-n3Ug0DQxk-h202hI,8348
72
72
  locust/webui/dist/assets/index-84c63e70.js,sha256=cwyH4ju0OCRvFhg3O-0SYVBTFlN_XQeQ6YkymAO4Hco,1647185
73
73
  locust/webui/dist/assets/logo.png,sha256=EIVPqr6wE_yqguHaqFHIsH0ZACLSrvNWyYO7PbyIj4w,19299
74
- locust-2.29.1.dev4.dist-info/LICENSE,sha256=78XGpIn3fHVBfaxlPNUfjVufSN7QsdhpJMRJHv2AFpo,1095
75
- locust-2.29.1.dev4.dist-info/METADATA,sha256=-hz8DceAzx0ygHlBenlXRxNI7QocbpfOd-31tVh7vIU,7322
76
- locust-2.29.1.dev4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
77
- locust-2.29.1.dev4.dist-info/entry_points.txt,sha256=RAdt8Ku-56m7bFjmdj-MBhbF6h4NX7tVODR9QNnOg0E,44
78
- locust-2.29.1.dev4.dist-info/top_level.txt,sha256=XSsjgPA8Ggf9TqKVbkwSqZFuPlZ085X13M9orDycE20,7
79
- locust-2.29.1.dev4.dist-info/RECORD,,
74
+ locust-2.29.1.dev31.dist-info/LICENSE,sha256=78XGpIn3fHVBfaxlPNUfjVufSN7QsdhpJMRJHv2AFpo,1095
75
+ locust-2.29.1.dev31.dist-info/METADATA,sha256=U5UCAUiJPE_mT_7Bh65rXvHeOQhkaIGtHm2sIG2AFcY,7390
76
+ locust-2.29.1.dev31.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
77
+ locust-2.29.1.dev31.dist-info/entry_points.txt,sha256=RAdt8Ku-56m7bFjmdj-MBhbF6h4NX7tVODR9QNnOg0E,44
78
+ locust-2.29.1.dev31.dist-info/top_level.txt,sha256=XSsjgPA8Ggf9TqKVbkwSqZFuPlZ085X13M9orDycE20,7
79
+ locust-2.29.1.dev31.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5