@@ -9,24 +9,6 @@ class ErrorMessage(Enum):
9
9
MEMBER_NOT_A_FUNCTION = 'Member is not a function.'
10
10
11
11
12
- class RoutingType (Enum ):
13
- CLS = 'cls'
14
- FN = 'fn'
15
-
16
-
17
- class MethodType (Enum ):
18
- GET = 'GET'
19
- POST = 'POST'
20
- PUT = 'PUT'
21
- DELETE = 'DELETE'
22
- PATCH = 'PATCH'
23
-
24
-
25
- class ModuleType (Enum ):
26
- ROUTES = '__routes__'
27
- METHOD = '__method__'
28
-
29
-
30
12
class PreDefinedHttpMethod (Enum ):
31
13
INDEX = 'index'
32
14
CREATE = 'create'
@@ -47,16 +29,16 @@ def __init__(self, mod, **kwargs): # module
47
29
self .model_add_router ()
48
30
49
31
def model_add_router (self ):
50
- if hasattr (self ._module , ' __routes__' ) and len (self ._module .__routes__ ):
32
+ if hasattr (self ._module , " __routes__" ) and len (self ._module .__routes__ ):
51
33
route_type , route_data = self ._routing_type (route = self ._module .__routes__ .pop (0 ))
52
- if route_type == RoutingType . CLS :
34
+ if route_type == 'cls' :
53
35
""" If it's a class it needs to extract the methods by function names
54
36
magic functions are excluded
55
37
"""
56
38
route_name , slug , cls = route_data
57
39
self .class_member_route (route = route_data , members = self .get_cls_fn_members (cls ))
58
40
59
- elif route_type == RoutingType . FN :
41
+ elif route_type == 'fn' :
60
42
route_name , slug , fn , methods = route_data
61
43
self .__routers .append (route_data )
62
44
self ._module .__method__ .add_url_rule (
@@ -67,17 +49,17 @@ def model_add_router(self):
67
49
self .model_add_router ()
68
50
69
51
def _is_valid_module (self ):
70
- return hasattr (self ._module , str ( ModuleType . ROUTES )) or hasattr (self ._module , str ( ModuleType . METHOD ) )
52
+ return hasattr (self ._module , "__routes__" ) or hasattr (self ._module , "__method__" )
71
53
72
54
@staticmethod
73
55
def _routing_type (route ):
74
56
__type = None
75
57
if isinstance (route , tuple ):
76
58
if len (route ) == 3 and inspect .isclass (route [2 ]):
77
- __type = RoutingType . CLS
59
+ __type = 'cls'
78
60
elif len (route ) == 4 and inspect .isfunction (route [2 ]):
79
61
if isinstance (route [3 ], (list , tuple , set )):
80
- __type = RoutingType . FN
62
+ __type = 'fn'
81
63
else :
82
64
raise TypeError (ErrorMessage .METHOD_NOT_A_LIST )
83
65
else :
@@ -92,15 +74,15 @@ def get_http_methods(names):
92
74
for name in names :
93
75
if "__" not in name :
94
76
if name == PreDefinedHttpMethod .INDEX :
95
- methods .append (MethodType . GET )
77
+ methods .append (' GET' )
96
78
elif name == PreDefinedHttpMethod .CREATE :
97
- methods .append (MethodType . POST )
79
+ methods .append (' POST' )
98
80
elif name == PreDefinedHttpMethod .UPDATE :
99
- methods .append (MethodType . PUT )
81
+ methods .append (' PUT' )
100
82
elif name == PreDefinedHttpMethod .DESTROY :
101
- methods .append (MethodType . DELETE )
83
+ methods .append (' DELETE' )
102
84
else :
103
- methods .append (MethodType . GET )
85
+ methods .append (' GET' )
104
86
105
87
return methods
106
88
else :
@@ -153,6 +135,8 @@ def blueprint_name_to_url(name):
153
135
"""
154
136
if name [- 1 :] == "." :
155
137
name = name [:- 1 ]
138
+ if name [- 1 :] is not "/" :
139
+ name = "/" + name
156
140
name = str (name ).replace ("." , "/" )
157
141
return name
158
142
0 commit comments