summaryrefslogtreecommitdiff
path: root/repoze/bfg/policy.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-07-04 17:50:59 +0000
committerChris McDonough <chrism@agendaless.com>2008-07-04 17:50:59 +0000
commit8b2c67309a9a3f9cf709bf3003dc3275f17c709e (patch)
tree1b20d5b000e4333cf50b2c2305dbb03e8b312144 /repoze/bfg/policy.py
parentd6cb3c1b68e752922a149d37a8d208b7d01dbe14 (diff)
downloadpyramid-8b2c67309a9a3f9cf709bf3003dc3275f17c709e.tar.gz
pyramid-8b2c67309a9a3f9cf709bf3003dc3275f17c709e.tar.bz2
pyramid-8b2c67309a9a3f9cf709bf3003dc3275f17c709e.zip
Don't depend on ZODB; shuffle policy responsibilities around a little.
Diffstat (limited to 'repoze/bfg/policy.py')
-rw-r--r--repoze/bfg/policy.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/repoze/bfg/policy.py b/repoze/bfg/policy.py
new file mode 100644
index 000000000..a25da9efd
--- /dev/null
+++ b/repoze/bfg/policy.py
@@ -0,0 +1,45 @@
+import urllib
+
+from zope.interface import implements
+
+from repoze.bfg.interfaces import IPolicy
+
+def split_path(path):
+ if path.startswith('/'):
+ path = path[1:]
+ if path.endswith('/'):
+ path = path[:-1]
+ clean=[]
+ for item in path.split('/'):
+ item = urllib.unquote(item) # deal with spaces in path segment
+ if not item or item=='.':
+ continue
+ elif item == '..':
+ del clean[-1]
+ else:
+ clean.append(item)
+ return clean
+
+class NaivePolicy:
+
+ implements(IPolicy)
+
+ def __call__(self, environ, root):
+ path = split_path(environ['PATH_INFO'])
+
+ ob = root
+ name = ''
+ while path:
+ element = pop(path)
+ try:
+ ob = ob[element]
+ except KeyError:
+ if path:
+ name = pop(path)
+ break
+
+ return ob, name, path
+
+def pop(path):
+ return path.pop(0)
+