web/views/urlrewrite.py
changeset 10688 fa29f3628a1b
parent 10612 84468b90e9c1
equal deleted inserted replaced
10687:d394bfcd8c25 10688:fa29f3628a1b
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Rules based url rewriter component, to get configurable RESTful urls"""
    18 """Rules based url rewriter component, to get configurable RESTful urls"""
    19 
    19 
    20 import re
    20 import re
    21 
    21 
    22 from six import string_types
    22 from six import string_types, add_metaclass
    23 
    23 
    24 from cubicweb.uilib import domid
    24 from cubicweb.uilib import domid
    25 from cubicweb.appobject import AppObject
    25 from cubicweb.appobject import AppObject
    26 
    26 
    27 
    27 
    51                 inputs.add(input)
    51                 inputs.add(input)
    52         classdict['rules'] = rules
    52         classdict['rules'] = rules
    53         return super(metarewriter, mcs).__new__(mcs, name, bases, classdict)
    53         return super(metarewriter, mcs).__new__(mcs, name, bases, classdict)
    54 
    54 
    55 
    55 
       
    56 @add_metaclass(metarewriter)
    56 class URLRewriter(AppObject):
    57 class URLRewriter(AppObject):
    57     """Base class for URL rewriters.
    58     """Base class for URL rewriters.
    58 
    59 
    59     Url rewriters should have a `rules` dict that maps an input URI
    60     Url rewriters should have a `rules` dict that maps an input URI
    60     to something that should be used for rewriting.
    61     to something that should be used for rewriting.
    64 
    65 
    65     A `priority` attribute might be used to indicate which rewriter
    66     A `priority` attribute might be used to indicate which rewriter
    66     should be tried first. The higher the priority is, the earlier the
    67     should be tried first. The higher the priority is, the earlier the
    67     rewriter will be tried.
    68     rewriter will be tried.
    68     """
    69     """
    69     __metaclass__ = metarewriter
       
    70     __registry__ = 'urlrewriting'
    70     __registry__ = 'urlrewriting'
    71     __abstract__ = True
    71     __abstract__ = True
    72     priority = 1
    72     priority = 1
    73 
    73 
    74     def rewrite(self, req, uri):
    74     def rewrite(self, req, uri):