diff options
| author | Chris McDonough <chrism@plope.com> | 2010-10-25 10:29:31 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2010-10-25 10:29:31 -0400 |
| commit | 64372401084889a440c9d990a0febc221e3e4b5c (patch) | |
| tree | c8939a341505d19f19fa6918d264b4e1d95326f8 /repoze/bfg/location.py | |
| parent | c8e78c2037806f3e5dab57de635bf80865b7061d (diff) | |
| download | pyramid-64372401084889a440c9d990a0febc221e3e4b5c.tar.gz pyramid-64372401084889a440c9d990a0febc221e3e4b5c.tar.bz2 pyramid-64372401084889a440c9d990a0febc221e3e4b5c.zip | |
first pass at converting bfg to pyramid namespace
Diffstat (limited to 'repoze/bfg/location.py')
| -rw-r--r-- | repoze/bfg/location.py | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/repoze/bfg/location.py b/repoze/bfg/location.py deleted file mode 100644 index 7472129d2..000000000 --- a/repoze/bfg/location.py +++ /dev/null @@ -1,66 +0,0 @@ -############################################################################## -# -# Copyright (c) 2003 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## - -def inside(model1, model2): - """Is ``model1`` 'inside' ``model2``? Return ``True`` if so, else - ``False``. - - ``model1`` is 'inside' ``model2`` if ``model2`` is a - :term:`lineage` ancestor of ``model1``. It is a lineage ancestor - if its parent (or one of its parent's parents, etc.) is an - ancestor. - """ - while model1 is not None: - if model1 is model2: - return True - model1 = model1.__parent__ - - return False - -def lineage(model): - """ - Return a generator representing the :term:`lineage` of the - :term:`model` object implied by the ``model`` argument. The - generator first returns ``model`` unconditionally. Then, if - ``model`` supplies a ``__parent__`` attribute, return the object - represented by ``model.__parent__``. If *that* object has a - ``__parent__`` attribute, return that object's parent, and so on, - until the object being inspected either has no ``__parent__`` - attribute or which has a ``__parent__`` attribute of ``None``. - For example, if the object tree is:: - - thing1 = Thing() - thing2 = Thing() - thing2.__parent__ = thing1 - - Calling ``lineage(thing2)`` will return a generator. When we turn - it into a list, we will get:: - - list(lineage(thing2)) - [ <Thing object at thing2>, <Thing object at thing1> ] - """ - while model is not None: - yield model - # The common case is that the AttributeError exception below - # is exceptional as long as the developer is a "good citizen" - # who has a root object with a __parent__ of None. Using an - # exception here instead of a getattr with a default is an - # important micro-optimization, because this function is - # called in any non-trivial application over and over again to - # generate URLs and paths. - try: - model = model.__parent__ - except AttributeError: - model = None - |
