Mercurial > p > roundup > code
comparison PageTemplates/PathIterator.py @ 984:a3a8ac7b8c40
Adding PageTemplates to the dist
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 30 Aug 2002 08:27:34 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 983:7fe79c67aaa9 | 984:a3a8ac7b8c40 |
|---|---|
| 1 ############################################################################## | |
| 2 # | |
| 3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved. | |
| 4 # | |
| 5 # This software is subject to the provisions of the Zope Public License, | |
| 6 # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | |
| 7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | |
| 8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | |
| 10 # FOR A PARTICULAR PURPOSE | |
| 11 # | |
| 12 ############################################################################## | |
| 13 | |
| 14 """Path Iterator | |
| 15 | |
| 16 A TALES Iterator with the ability to use first() and last() on | |
| 17 subpaths of elements. | |
| 18 """ | |
| 19 | |
| 20 __version__='$Revision: 1.1 $'[11:-2] | |
| 21 | |
| 22 import TALES | |
| 23 from Expressions import restrictedTraverse, Undefs, getSecurityManager | |
| 24 from string import split | |
| 25 | |
| 26 class Iterator(TALES.Iterator): | |
| 27 def __bobo_traverse__(self, REQUEST, name): | |
| 28 if name in ('first', 'last'): | |
| 29 path = REQUEST['TraversalRequestNameStack'] | |
| 30 names = list(path) | |
| 31 names.reverse() | |
| 32 path[:] = [tuple(names)] | |
| 33 return getattr(self, name) | |
| 34 | |
| 35 def same_part(self, name, ob1, ob2): | |
| 36 if name is None: | |
| 37 return ob1 == ob2 | |
| 38 if isinstance(name, type('')): | |
| 39 name = split(name, '/') | |
| 40 name = filter(None, name) | |
| 41 securityManager = getSecurityManager() | |
| 42 try: | |
| 43 ob1 = restrictedTraverse(ob1, name, securityManager) | |
| 44 ob2 = restrictedTraverse(ob2, name, securityManager) | |
| 45 except Undefs: | |
| 46 return 0 | |
| 47 return ob1 == ob2 | |
| 48 |
