from django.core.urlresolvers import RegexURLPattern
from django.conf.urls.defaults import patterns

class DecoratedURLPattern(RegexURLPattern):
    def resolve(self, *args, **kwargs):
        result = RegexURLPattern.resolve(self, *args, **kwargs)
        if result:
            result = list(result)
            result[0] = self._decorate_with(result[0])
        return result

def decorated_patterns(prefix, func, *args):
    result = patterns(prefix, *args)
    if func:
        for p in result:
            if isinstance(p, RegexURLPattern):
                p.__class__ = DecoratedURLPattern
                p._decorate_with = func
    return result

def control_access(view_func):
    def _checklogin(request, *args, **kwargs):
        raise Http404()
    return _checklogin

urlpatterns = patterns('views',
    # unprotected views
    (r'^public/contact/$',      'contact'),
    (r'^public/imprint/$',        'imprint'),
) + decorated_patterns('views', control_access,
    (r'^admin/add/$',      'add'),
    (r'^admin/edit/$',      'edit'),
)