reykit 1.1.107__py3-none-any.whl → 1.1.109__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.
reykit/rbase.py CHANGED
@@ -50,7 +50,6 @@ __all__ = (
50
50
  'check_most_one',
51
51
  'check_file_found',
52
52
  'check_file_exist',
53
- 'check_response_code',
54
53
  'is_class',
55
54
  'is_instance',
56
55
  'is_iterable',
@@ -153,36 +152,55 @@ class ConfigMeta(StaticMeta):
153
152
 
154
153
  def __getitem__(cls, name: str) -> Any:
155
154
  """
156
- Get item.
155
+ Get config value.
157
156
 
158
157
  Parameters
159
158
  ----------
160
- name : Item name.
159
+ name : Config name.
161
160
 
162
161
  Returns
163
162
  -------
164
- Item value.
163
+ Config value.
165
164
  """
166
165
 
167
166
  # Get.
168
- item = getattr(cls, name)
167
+ value = getattr(cls, name)
169
168
 
170
- return item
169
+ return value
171
170
 
172
171
 
173
172
  def __setitem__(cls, name: str, value: Any) -> None:
174
173
  """
175
- Set item.
174
+ Set config value.
176
175
 
177
176
  Parameters
178
177
  ----------
179
- name : Item name.
178
+ name : Config name.
180
179
  """
181
180
 
182
181
  # Set.
183
182
  setattr(cls, name, value)
184
183
 
185
184
 
185
+ def __contains__(cls, name: str) -> bool:
186
+ """
187
+ Whether the exist this config value.
188
+
189
+ Parameters
190
+ ----------
191
+ name : Config name.
192
+
193
+ Returns
194
+ -------
195
+ Result.
196
+ """
197
+
198
+ # Judge.
199
+ result = hasattr(cls, name)
200
+
201
+ return result
202
+
203
+
186
204
  type NullType = Type['Null']
187
205
 
188
206
 
@@ -470,44 +488,6 @@ def check_file_exist(path: str) -> None:
470
488
  throw(FileExistsError, path)
471
489
 
472
490
 
473
- def check_response_code(
474
- code: int,
475
- range_: int | Iterable[int] | None = None
476
- ) -> bool:
477
- """
478
- Check if the response code is in range.
479
-
480
- Parameters
481
- ----------
482
- code : Response code.
483
- range\\_ : Pass the code range.
484
- - `None`: Check if is between 200 and 299.
485
- - `int`: Check if is this value.
486
- - `Iterable`: Check if is in sequence.
487
-
488
- Returns
489
- -------
490
- Check result.
491
- """
492
-
493
- # Check.
494
- match range_:
495
- case None:
496
- result = code // 100 == 2
497
- case int():
498
- result = code == range_
499
- case _ if hasattr(range_, '__contains__'):
500
- result = code in range_
501
- case _:
502
- throw(TypeError, range_)
503
-
504
- # Throw exception.
505
- if not result:
506
- throw(AssertionError, code)
507
-
508
- return result
509
-
510
-
511
491
  def is_class(obj: Any) -> bool:
512
492
  """
513
493
  Judge whether it is class.
reykit/rnet.py CHANGED
@@ -14,7 +14,11 @@ from collections.abc import Callable, Iterable
14
14
  from warnings import filterwarnings
15
15
  from os.path import abspath as os_abspath, isfile as os_isfile
16
16
  from socket import socket as Socket
17
- from urllib.parse import urlsplit as urllib_urlsplit, quote as urllib_quote, unquote as urllib_unquote
17
+ from urllib.parse import (
18
+ urlsplit as urllib_urlsplit,
19
+ quote as urllib_quote,
20
+ unquote as urllib_unquote
21
+ )
18
22
  from requests.api import request as requests_request
19
23
  from requests.models import Response
20
24
  from requests_cache import (
@@ -32,7 +36,7 @@ from datetime import datetime
32
36
 
33
37
  from .rbase import Base, throw, check_response_code
34
38
  from .ros import File, get_md5
35
- from .rre import search, split
39
+ from .rre import search, split, sub
36
40
 
37
41
 
38
42
  __all__ = (
@@ -63,34 +67,45 @@ RequestCacheParameters = TypedDict(
63
67
  )
64
68
 
65
69
 
66
- def join_url(url: str, params: dict) -> str:
70
+ def join_url(*urls: str, **params: dict) -> str:
67
71
  """
68
72
  Join URL and parameters.
69
73
 
70
74
  Parameters
71
75
  ----------
72
- url : URL.
73
- params : Parameters of URL.
76
+ urls : URL.
77
+ params : URL parameters.
74
78
 
75
79
  Returns
76
80
  -------
77
81
  Joined URL.
78
82
  """
79
83
 
80
- # Join parameter.
81
- params_str = '&'.join(
82
- [
83
- f'{key}={urllib_quote(value)}'
84
- for key, value in params.items()
85
- ]
86
- )
84
+ # Check.
85
+ if len(urls) == 0:
86
+ throw(ValueError, urls)
87
87
 
88
88
  # Join URL.
89
- if '?' not in url:
90
- url += '?'
91
- elif url[-1] != '?':
92
- url += '&'
93
- url += params_str
89
+ url: str = '/'.join(urls)
90
+ url = url.replace('\\', '/')
91
+ pattern = '(?<!:)//+'
92
+ url = sub(pattern, url, '/')
93
+ if url[-1] == '/':
94
+ url = url[:-1]
95
+
96
+ # Join parameter.
97
+ if params != {}:
98
+ params_str = '&'.join(
99
+ [
100
+ f'{key}={urllib_quote(str(value))}'
101
+ for key, value in params.items()
102
+ ]
103
+ )
104
+ if '?' not in url:
105
+ url += '?'
106
+ elif url[-1] != '?':
107
+ url += '&'
108
+ url += params_str
94
109
 
95
110
  return url
96
111
 
@@ -369,7 +384,24 @@ def request(
369
384
  range_ = None
370
385
  else:
371
386
  range_ = check
372
- check_response_code(response.status_code, range_)
387
+ match range_:
388
+ case None:
389
+ result = response.status_code // 100 == 2
390
+ case int():
391
+ result = response.status_code == range_
392
+ case _ if hasattr(range_, '__contains__'):
393
+ result = response.status_code in range_
394
+ case _:
395
+ throw(TypeError, range_)
396
+
397
+ ## Throw exception.
398
+ if not result:
399
+ response_text = response.text[:100]
400
+ if len(response.text) > 100:
401
+ response_text += '...'
402
+ response_text = repr(response_text)
403
+ text = f"response code is '{response.status_code}', response content is {response_text}"
404
+ throw(AssertionError, text=text)
373
405
 
374
406
  return response
375
407
 
reykit/rtask.py CHANGED
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  """
5
- @Time : 2022-12-19
5
+ @Time : 2022-12-19 20:06:20
6
6
  @Author : Rey
7
7
  @Contact : reyxbo@163.com
8
8
  @Explain : Multi task methods.
@@ -715,7 +715,25 @@ async def async_request(
715
715
  range_ = None
716
716
  else:
717
717
  range_ = check
718
- check_response_code(response.status, range_)
718
+ match range_:
719
+ case None:
720
+ result = response.status // 100 == 2
721
+ case int():
722
+ result = response.status == range_
723
+ case _ if hasattr(range_, '__contains__'):
724
+ result = response.status in range_
725
+ case _:
726
+ throw(TypeError, range_)
727
+
728
+ ## Throw exception.
729
+ if not result:
730
+ response_text = await response.text()
731
+ response_text = response_text[:100]
732
+ if len(response_text) > 100:
733
+ response_text += '...'
734
+ response_text = repr(response_text)
735
+ text = f"response code is '{response.status_code}', response content is {response_text}"
736
+ throw(AssertionError, text=text)
719
737
 
720
738
  # Receive.
721
739
  match handler:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reykit
3
- Version: 1.1.107
3
+ Version: 1.1.109
4
4
  Summary: Kit method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reykit/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -1,12 +1,12 @@
1
1
  reykit/__init__.py,sha256=5oKzVHvTmotJB08LhrMFQO3tFVFy7JuqXMn9PqnJEH8,779
2
2
  reykit/rall.py,sha256=-gxGRcEcK7zTcA66DgGLw46QuDsJcdda6NQA_Xuyq8w,619
3
- reykit/rbase.py,sha256=HceNnyn_pDikZxd5jdWM9AP8Z2y6zYFhZ3pVG9rRoUo,22243
3
+ reykit/rbase.py,sha256=w1hnRw0pOSj2Ws_DA206-QGrc5BzNryeZ9wx0BY6AxA,21713
4
4
  reykit/rdata.py,sha256=j3BBeWKMIwowjC-W_5wkJxIWvVlZsqt1mYMKuQbaPG0,11323
5
5
  reykit/remail.py,sha256=DE4sxfJEXNu6MiBJKUsWXqvBrIOJNmnm_1lnGL0tZec,6693
6
6
  reykit/rimage.py,sha256=z-cjI_MgEbUhuKgIbvDS_e2fy2CrnBhr_FS6D8XuAg0,6124
7
7
  reykit/rlog.py,sha256=yBArs48wl509v4q7e1vHbE3E_Bqi3VHEV-Iuw2Y58f8,25649
8
8
  reykit/rmonkey.py,sha256=PBA19EqlJHI9FxT8C4-t59RlyAfwfhX7xV9ZJ3PegWo,7894
9
- reykit/rnet.py,sha256=gL7doDgzEE-AwBPgz3LUFvgG8MmPpX-JU0sA9dm9C1Q,16837
9
+ reykit/rnet.py,sha256=FmmI1wB0chBnMdCmeVVVOsD4K0iHio8vNgF_q8bX6E8,17870
10
10
  reykit/rnum.py,sha256=WNtvKSS-MkgmudIqDR8Xv4WIdNLyEPIO0jz5ukL3cXg,3603
11
11
  reykit/ros.py,sha256=quDCZfqpYtZRgyK2wtscm92oPm3PaKoBqDBAaM29HV8,47714
12
12
  reykit/rrand.py,sha256=nH0e4wRiLba7Tg6pRyn7qnPrzIXdlJxm7e4S1EqsBLQ,8549
@@ -15,14 +15,14 @@ reykit/rschedule.py,sha256=H7JQbX3kVFetmGS2EZ_216NnZj-ilGl6h1MusIx8ZWk,12288
15
15
  reykit/rstdout.py,sha256=YEKP8-OcCSk8TTtChgqTkO7NSnJ5LOb77d2qiE_3vLI,8081
16
16
  reykit/rsys.py,sha256=zxHeahRwCNonyprHfw6yFT9qMkITBwInOlWuvaXgnhQ,24894
17
17
  reykit/rtable.py,sha256=fTeuiZNGelSfAT-BIjT2u-wgkh9WpphgdD7gj_TcFw0,10587
18
- reykit/rtask.py,sha256=mnCl-LV23ccK6EvD4ZXInjPpMjRuq6lq2DYwTjYtYnw,27519
18
+ reykit/rtask.py,sha256=78b1zlDAqqKb0XHbbYi8NhUjIJnslPMjTwksKY-RB1c,28393
19
19
  reykit/rtext.py,sha256=cf3a0uGmdr2ucKjGzYkQFkUPdixKJW1c82FPDdmRzwM,13227
20
20
  reykit/rtime.py,sha256=3UPpUK027TY1Wgf5bzwCQo1N4ZceZ2YtcZzM9I8Q9Qg,17766
21
21
  reykit/rwrap.py,sha256=lOKBhSqx8V_PcsdipPP4SaiGXXcpfaEhO_qEGSySEkw,15065
22
22
  reykit/rzip.py,sha256=vYw17toqg-DbMjvycluohU9zVX73uYYqQGAp_b21pA8,3433
23
23
  reykit/rdll/__init__.py,sha256=mewj06HHIzzW6oreQAz-6in2zYwNJ4-d1eWWL7CPQgc,685
24
24
  reykit/rdll/rdll_core.py,sha256=zBmOyxD6LkbNIadXmFHLJinj-6UFko8D6w5d7hYA7vU,5077
25
- reykit-1.1.107.dist-info/METADATA,sha256=3aiGxp4u63VpBj6V6ebkZANs-XSdz8TA3Xo2GDFesok,1882
26
- reykit-1.1.107.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- reykit-1.1.107.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
- reykit-1.1.107.dist-info/RECORD,,
25
+ reykit-1.1.109.dist-info/METADATA,sha256=uMdDhtS8qzYWPsPVAcXyljysE-PrkNEkSpPdq9p90SU,1882
26
+ reykit-1.1.109.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ reykit-1.1.109.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
+ reykit-1.1.109.dist-info/RECORD,,