Mercurial > p > roundup > code
annotate roundup/cgi/PageTemplates/PathIterator.py @ 4546:d39c37fd2940 git
Repository conversion from Subversion to git.
| author | Eric S. Raymond <esr@thyrsus.com> |
|---|---|
| date | Tue, 18 Oct 2011 10:20:29 -0400 |
| parents | b43efe461b3e |
| children | 6e3e4f24c753 |
| rev | line source |
|---|---|
| 1049 | 1 ############################################################################## |
| 2 # | |
| 3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved. | |
|
2349
b43efe461b3e
update PageTemplates to latest Zope codebase
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
4 # |
| 1049 | 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 | |
|
2349
b43efe461b3e
update PageTemplates to latest Zope codebase
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
11 # |
| 1049 | 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 | |
|
2349
b43efe461b3e
update PageTemplates to latest Zope codebase
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
20 __version__='$Revision: 1.3 $'[11:-2] |
| 1049 | 21 |
| 22 import TALES | |
| 23 from Expressions import restrictedTraverse, Undefs, getSecurityManager | |
| 24 | |
| 25 class Iterator(TALES.Iterator): | |
| 26 def __bobo_traverse__(self, REQUEST, name): | |
| 27 if name in ('first', 'last'): | |
| 28 path = REQUEST['TraversalRequestNameStack'] | |
| 29 names = list(path) | |
| 30 names.reverse() | |
| 31 path[:] = [tuple(names)] | |
| 32 return getattr(self, name) | |
| 33 | |
| 34 def same_part(self, name, ob1, ob2): | |
| 35 if name is None: | |
| 36 return ob1 == ob2 | |
| 37 if isinstance(name, type('')): | |
|
2349
b43efe461b3e
update PageTemplates to latest Zope codebase
Richard Jones <richard@users.sourceforge.net>
parents:
2005
diff
changeset
|
38 name = name.split('/') |
| 1049 | 39 name = filter(None, name) |
| 40 securityManager = getSecurityManager() | |
| 41 try: | |
| 42 ob1 = restrictedTraverse(ob1, name, securityManager) | |
| 43 ob2 = restrictedTraverse(ob2, name, securityManager) | |
| 44 except Undefs: | |
| 45 return 0 | |
| 46 return ob1 == ob2 |
