-
Notifications
You must be signed in to change notification settings - Fork 2
/
hooks.py
111 lines (81 loc) · 2.56 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'''
HTTP 请求钩子
'''
from .config import HTTP_ENGINE
# 类泛属性
class inherit(type):
'''类泛属性'''
def __getattr__(cls, name):
if not '__general__' in dir(cls):
raise NameError("name '__general__' is not defined")
if hasattr(cls.__general__, name):
return getattr(cls.__general__, name)
raise AttributeError(f"method '{name}' is not defined in {cls.__general__}")
# 类方法描述
class repr(type):
'''类方法描述'''
def __repr__(cls) -> str:
return f"<lupros.{cls.__name__} object>"
# requests参数引擎
class requests(metaclass = repr):
'''`requests参数引擎` 辅助字典生成器'''
@classmethod
def request(cls, *args, **kw):
return (args, kw)
@classmethod
def get(cls, *args, **kw):
return ('get', args, kw)
@classmethod
def post(cls, *args, **kw):
return ('post', args, kw)
@classmethod
def options(cls, *args, **kw):
return ('options', args, kw)
@classmethod
def head(cls, *args, **kw):
return ('head', args, kw)
@classmethod
def put(cls, *args, **kw):
return ('put', args, kw)
@classmethod
def patch(cls, *args, **kw):
return ('patch', args, kw)
@classmethod
def delete(cls, *args, **kw):
return ('delete', args, kw)
def __repr__(self) -> str:
return "<lupros.requests object >"
# httpx参数引擎
class httpx(metaclass = repr):
'''`httpx参数引擎` 辅助字典生成器'''
@classmethod
def request(cls, *args, **kw):
return (args, kw)
@classmethod
def get(cls, *args, **kw):
return ('GET', args, kw)
@classmethod
def post(cls, *args, **kw):
return ('POST', args, kw)
@classmethod
def options(cls, *args, **kw):
return ('OPTIONS', args, kw)
@classmethod
def head(cls, *args, **kw):
return ('HEAD', args, kw)
@classmethod
def put(cls, *args, **kw):
return ('PUT', args, kw)
@classmethod
def patch(cls, *args, **kw):
return ('PATCH', args, kw)
@classmethod
def delete(cls, *args, **kw):
return ('DELETE', args, kw)
def __repr__(self) -> str:
return "<lupros.httpx object >"
# `HTTP参数引擎`
class lupros(metaclass = inherit):
'''`HTTP参数引擎` 辅助字典生成器'''
kernel = {'requests': requests, 'httpx' : httpx}
__general__ = kernel[HTTP_ENGINE.__name__]