summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-22 20:45:58 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-22 20:45:58 +0000
commit9cb00f863f0c23f00f232b495c6829a9adda8432 (patch)
tree5e15dbea5802ef76b1761e3fd933f7effd252eb6
parent1d975eaf1e534ff8fba6edf45f79f852c9d5cd4e (diff)
downloadpyramid-9cb00f863f0c23f00f232b495c6829a9adda8432.tar.gz
pyramid-9cb00f863f0c23f00f232b495c6829a9adda8432.tar.bz2
pyramid-9cb00f863f0c23f00f232b495c6829a9adda8432.zip
Maintain weight so it influences view lookup ordering.
-rw-r--r--repoze/bfg/zcml.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index 7dc9cd2a0..11331ab9e 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -237,6 +237,16 @@ def view(
weight = weight - 20
predicates.append(request_method_predicate)
+ if path_info is not None:
+ try:
+ path_info_val = re.compile(path_info)
+ except re.error, why:
+ raise ConfigurationError(why[0])
+ def path_info_predicate(context, request):
+ return path_info_val.match(request.path_info)
+ weight = weight - 30
+ predicates.append(path_info_predicate)
+
if request_param is not None:
request_param_val = None
if '=' in request_param:
@@ -245,7 +255,7 @@ def view(
if request_param_val is None:
return request_param in request.params
return request.params.get(request_param) == request_param_val
- weight = weight - 30
+ weight = weight - 40
predicates.append(request_param_predicate)
if header is not None:
@@ -262,29 +272,21 @@ def view(
return header_name in request.headers
val = request.headers.get(header_name)
return header_val.match(val) is not None
+ weight = weight - 50
predicates.append(header_predicate)
if accept is not None:
def accept_predicate(context, request):
return accept in request.accept
- weight = weight - 40
+ weight = weight - 60
predicates.append(accept_predicate)
if containment is not None:
def containment_predicate(context, request):
return find_interface(context, containment) is not None
- weight = weight - 50
+ weight = weight - 70
predicates.append(containment_predicate)
- if path_info is not None:
- try:
- path_info_val = re.compile(path_info)
- except re.error, why:
- raise ConfigurationError(why[0])
- def path_info_predicate(context, request):
- return path_info_val.match(request.path_info)
- predicates.append(path_info_predicate)
-
# this will be == sys.maxint if no predicates
score = weight / (len(predicates) + 1)