Exemplo n.º 1
0
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)
Exemplo n.º 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")
Exemplo n.º 3
0
 def getName(self):
     """See ILocationInfo
     """
     return u('')
Exemplo n.º 4
0
 def getPath(self):
     """See ILocationInfo
     """
     return u('/')