Skip to content
This repository was archived by the owner on Apr 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'
5 changes: 0 additions & 5 deletions conman/routes/handlers/__init__.py

This file was deleted.

25 changes: 0 additions & 25 deletions conman/routes/handlers/simple/__init__.py

This file was deleted.

Empty file.
2 changes: 1 addition & 1 deletion conman/routes/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down