Skip to content

Commit d951ba8

Browse files
committed
bugfix: string literals
1 parent c558d9d commit d951ba8

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

flask_blueprint/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"""
1515

1616
__all__ = ['Core', '__version__']
17-
__version__ = '1.2.7'
17+
__version__ = '1.2.8'
1818

1919

2020
"""

flask_blueprint/module_router.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@ class ErrorMessage(Enum):
99
MEMBER_NOT_A_FUNCTION = 'Member is not a function.'
1010

1111

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-
3012
class PreDefinedHttpMethod(Enum):
3113
INDEX = 'index'
3214
CREATE = 'create'
@@ -47,16 +29,16 @@ def __init__(self, mod, **kwargs): # module
4729
self.model_add_router()
4830

4931
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__):
5133
route_type, route_data = self._routing_type(route=self._module.__routes__.pop(0))
52-
if route_type == RoutingType.CLS:
34+
if route_type == 'cls':
5335
""" If it's a class it needs to extract the methods by function names
5436
magic functions are excluded
5537
"""
5638
route_name, slug, cls = route_data
5739
self.class_member_route(route=route_data, members=self.get_cls_fn_members(cls))
5840

59-
elif route_type == RoutingType.FN:
41+
elif route_type == 'fn':
6042
route_name, slug, fn, methods = route_data
6143
self.__routers.append(route_data)
6244
self._module.__method__.add_url_rule(
@@ -67,17 +49,17 @@ def model_add_router(self):
6749
self.model_add_router()
6850

6951
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__")
7153

7254
@staticmethod
7355
def _routing_type(route):
7456
__type = None
7557
if isinstance(route, tuple):
7658
if len(route) == 3 and inspect.isclass(route[2]):
77-
__type = RoutingType.CLS
59+
__type = 'cls'
7860
elif len(route) == 4 and inspect.isfunction(route[2]):
7961
if isinstance(route[3], (list, tuple, set)):
80-
__type = RoutingType.FN
62+
__type = 'fn'
8163
else:
8264
raise TypeError(ErrorMessage.METHOD_NOT_A_LIST)
8365
else:
@@ -92,15 +74,15 @@ def get_http_methods(names):
9274
for name in names:
9375
if "__" not in name:
9476
if name == PreDefinedHttpMethod.INDEX:
95-
methods.append(MethodType.GET)
77+
methods.append('GET')
9678
elif name == PreDefinedHttpMethod.CREATE:
97-
methods.append(MethodType.POST)
79+
methods.append('POST')
9880
elif name == PreDefinedHttpMethod.UPDATE:
99-
methods.append(MethodType.PUT)
81+
methods.append('PUT')
10082
elif name == PreDefinedHttpMethod.DESTROY:
101-
methods.append(MethodType.DELETE)
83+
methods.append('DELETE')
10284
else:
103-
methods.append(MethodType.GET)
85+
methods.append('GET')
10486

10587
return methods
10688
else:
@@ -153,6 +135,8 @@ def blueprint_name_to_url(name):
153135
"""
154136
if name[-1:] == ".":
155137
name = name[:-1]
138+
if name[-1:] is not "/":
139+
name = "/" + name
156140
name = str(name).replace(".", "/")
157141
return name
158142

flask_blueprint/package_extractor.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import inspect
22
import pkgutil
3-
from os import listdir
43

54
from .module_router import ModuleRouter
65

76
"""
87
PACKAGE EXTRACTOR
9-
108
It's purpose is to extract all the modules based on the paths of the parameter given
119
it extracts valid packages within the root module path
1210
and register the valid modules to the flask blueprint
13-
1411
:param application
1512
flask application object
1613
example: flask_app = Flask(import_name, instance_relative_config=True)
@@ -33,19 +30,14 @@ def __init__(self, application, paths):
3330
self.__iter_paths()
3431

3532
def __iter_paths(self):
36-
for path in self.paths:
37-
self.__iter_path_sub_path(sub_paths=listdir(path))
38-
39-
def __iter_path_sub_path(self, sub_paths):
40-
for path_directories in sub_paths:
41-
self.__extract_packages(packages=pkgutil.walk_packages(path_directories, prefix='', onerror=None))
33+
self.__extract_packages(packages=pkgutil.walk_packages(self.paths, prefix='', onerror=None))
4234

4335
def __extract_packages(self, packages):
4436
if inspect.isgenerator(packages):
4537
try:
4638
loader, name, is_pkg = next(packages)
47-
self.__extract_packages(packages)
4839
self.__extract_modules(loader, name, is_pkg)
40+
self.__extract_packages(packages)
4941
except StopIteration:
5042
pass
5143
else:

0 commit comments

Comments
 (0)