diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-07-04 17:50:59 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-07-04 17:50:59 +0000 |
| commit | 8b2c67309a9a3f9cf709bf3003dc3275f17c709e (patch) | |
| tree | 1b20d5b000e4333cf50b2c2305dbb03e8b312144 /repoze/bfg/policy.py | |
| parent | d6cb3c1b68e752922a149d37a8d208b7d01dbe14 (diff) | |
| download | pyramid-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.py | 45 |
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) + |
