comparison genshi_view/template/+package+/handlers.py @ 14:d54f85043f77

better and more configurable matching logic
author k0s <k0scist@gmail.com>
date Wed, 18 Nov 2009 15:39:11 -0500
parents 8a7731b2126a
children 807c8eef8098
comparison
equal deleted inserted replaced
13:6075ca965357 14:d54f85043f77
14 methods = set(['GET']) # methods to listen to 14 methods = set(['GET']) # methods to listen to
15 handler_path = [] # path elements to match 15 handler_path = [] # path elements to match
16 16
17 @classmethod 17 @classmethod
18 def match(cls, app, request): 18 def match(cls, app, request):
19
20 # check the method
21 if request.method not in cls.methods:
22 return None
23
24 # check the path
25 if request.environ['path'][:len(cls.handler_path)] != cls.handler_path:
26 return None
27
19 try: 28 try:
20 return cls(app, request) 29 return cls(app, request)
21 except HandlerMatchException: 30 except HandlerMatchException:
22 return None 31 return None
23 32
24 def __init__(self, app, request): 33 def __init__(self, app, request):
25
26 # check the method
27 if request.method not in self.methods:
28 raise HandlerMatchException
29
30 # check the path
31 if request.environ['path'][:len(self.handler_path)] != self.handler_path:
32 raise HandlerMatchException
33
34 self.app = app 34 self.app = app
35 self.request = request 35 self.request = request
36 self.application_path = urlparse(request.application_url)[2] 36 self.application_path = urlparse(request.application_url)[2]
37 37
38 def link(self, path=(), permanant=False): 38 def link(self, path=(), permanant=False):