コード例 #1
0
ファイル: interfaces.py プロジェクト: nielsbom/zope.location
class ILocation(Interface):
    """Objects that can be located in a hierachy.

    Given a parent and a name an object can be located within that parent. The
    locatable object's `__name__` and `__parent__` attributes store this
    information.

    Located objects form a hierarchy that can be used to build file-system-like
    structures. For example in Zope `ILocation` is used to build URLs and to
    support security machinery.

    To retrieve an object from its parent using its name, the `ISublocation`
    interface provides the `sublocations` method to iterate over all objects
    located within the parent. The object searched for can be found by reading
    each sublocation's __name__ attribute.

    """

    __parent__ = Attribute("The parent in the location hierarchy.")

    __name__ = TextLine(
        title=u("The name within the parent"),
        description=u("The object can be looked up from the parent's "
            "sublocations using this name."),
        required=False,
        default=None)
コード例 #2
0
    def getPath(self):
        """See ILocationInfo.
        """
        path = []
        context = self.context
        max = 9999
        while context is not None:
            if IRoot.providedBy(context):
                if path:
                    path.append('')
                    path.reverse()
                    return u('/').join(path)
                else:
                    return u('/')
            path.append(context.__name__)
            context = context.__parent__
            max -= 1
            if max < 1:
                raise TypeError("Maximum location depth exceeded, "
                                "probably due to a a location cycle.")

        raise TypeError("Not enough context to determine location root")
コード例 #3
0
 def getName(self):
     """See ILocationInfo
     """
     return u('')
コード例 #4
0
 def getPath(self):
     """See ILocationInfo
     """
     return u('/')