diff --git a/conman/routes/handlers/base/__init__.py b/conman/routes/handlers.py similarity index 57% rename from conman/routes/handlers/base/__init__.py rename to conman/routes/handlers.py index bc5c736..b16f05f 100644 --- a/conman/routes/handlers/base/__init__.py +++ b/conman/routes/handlers.py @@ -30,3 +30,27 @@ def handle(self, request, path): """ view, args, kwargs = resolve(path, urlconf=self.urlconf) return view(request, *args, route=self.route, **kwargs) + + +class UnboundViewMeta(type): + """ + Metaclass that wraps the `view` attribute with `staticmethod`. + + This ensures that the method does not bind to the class unintentionally. + """ + def __new__(cls, name, bases, attrs): + """Create the new class with a staticmethod view attribute.""" + view = attrs.get('view') + if view: + attrs['view'] = staticmethod(view) + return super().__new__(cls, name, bases, attrs) + + +class SimpleHandler(BaseHandler, metaclass=UnboundViewMeta): + """ + Abstract handler for Routes that have one url: `/` relative to the Route. + + Subclasses should define a view on the class as `view`. This will be + called if the `path` passed to `handle` is `/`. + """ + urlconf = 'conman.routes.simple.urls' diff --git a/conman/routes/handlers/__init__.py b/conman/routes/handlers/__init__.py deleted file mode 100644 index b431cd6..0000000 --- a/conman/routes/handlers/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .base import BaseHandler -from .simple import SimpleHandler - - -__all__ = (BaseHandler, SimpleHandler) diff --git a/conman/routes/handlers/simple/__init__.py b/conman/routes/handlers/simple/__init__.py deleted file mode 100644 index 1454749..0000000 --- a/conman/routes/handlers/simple/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -from ..base import BaseHandler - - -class UnboundViewMeta(type): - """ - Metaclass that wraps the `view` attribute with `staticmethod`. - - This ensures that the method does not bind to the class unintentionally. - """ - def __new__(cls, name, bases, attrs): - """Create the new class with a staticmethod view attribute.""" - view = attrs.get('view') - if view: - attrs['view'] = staticmethod(view) - return super().__new__(cls, name, bases, attrs) - - -class SimpleHandler(BaseHandler, metaclass=UnboundViewMeta): - """ - Abstract handler for Routes that have one url: `/` relative to the Route. - - Subclasses should define a view on the class as `view`. This will be - called if the `path` passed to `handle` is `/`. - """ - urlconf = 'conman.routes.handlers.simple.urls' diff --git a/conman/routes/simple/__init__.py b/conman/routes/simple/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/conman/routes/handlers/simple/urls.py b/conman/routes/simple/urls.py similarity index 100% rename from conman/routes/handlers/simple/urls.py rename to conman/routes/simple/urls.py diff --git a/conman/routes/handlers/simple/views.py b/conman/routes/simple/views.py similarity index 100% rename from conman/routes/handlers/simple/views.py rename to conman/routes/simple/views.py diff --git a/conman/routes/tests/test_handlers.py b/conman/routes/tests/test_handlers.py index 50727c4..547fece 100644 --- a/conman/routes/tests/test_handlers.py +++ b/conman/routes/tests/test_handlers.py @@ -11,7 +11,7 @@ class BaseHandlerPathTest(TestCase): """Test BaseHandler.path().""" def test_path(self): """Test directly on base class.""" - base_handler_path = 'conman.routes.handlers.base.BaseHandler' + base_handler_path = 'conman.routes.handlers.BaseHandler' self.assertEqual(BaseHandler.path(), base_handler_path) def test_path_on_subclass(self):