/usr/lib/python3/dist-packages/zope/location/traversing.py is in python3-zope.location 4.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | ##############################################################################
#
# Copyright (c) 2003-2009 Zope Foundation 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.
#
##############################################################################
"""Classes to support implenting IContained
"""
__docformat__ = 'restructuredtext'
from zope.interface import implementer
from zope.location.interfaces import ILocationInfo
from zope.location.interfaces import IRoot
from zope.location.interfaces import ISite # zope.component, if present
from zope.location._compat import u
@implementer(ILocationInfo)
class LocationPhysicallyLocatable(object):
"""Provide location information for location objects
"""
def __init__(self, context):
self.context = context
def getRoot(self):
"""See ILocationInfo.
"""
context = self.context
max = 9999
while context is not None:
if IRoot.providedBy(context):
return context
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")
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")
def getParent(self):
"""See ILocationInfo.
"""
parent = getattr(self.context, '__parent__', None)
if parent is not None:
return parent
raise TypeError('Not enough context information to get parent',
self.context)
def getParents(self):
"""See ILocationInfo.
"""
# XXX Merge this implementation with getPath. This was refactored
# from zope.traversing.
parents = []
w = self.context
while 1:
w = getattr(w, '__parent__', None)
if w is None:
break
parents.append(w)
if parents and IRoot.providedBy(parents[-1]):
return parents
raise TypeError("Not enough context information to get all parents")
def getName(self):
"""See ILocationInfo
"""
return self.context.__name__
def getNearestSite(self):
"""See ILocationInfo
"""
if ISite.providedBy(self.context):
return self.context
for parent in self.getParents():
if ISite.providedBy(parent):
return parent
return self.getRoot()
@implementer(ILocationInfo)
class RootPhysicallyLocatable(object):
"""Provide location information for the root object
This adapter is very simple, because there's no places to search
for parents and nearest sites, so we are only working with context
object, knowing that its the root object already.
"""
def __init__(self, context):
self.context = context
def getRoot(self):
"""See ILocationInfo
"""
return self.context
def getPath(self):
"""See ILocationInfo
"""
return u('/')
def getParent(self):
"""See ILocationInfo.
"""
return None
def getParents(self):
"""See ILocationInfo
"""
return []
def getName(self):
"""See ILocationInfo
"""
return u('')
def getNearestSite(self):
"""See ILocationInfo
"""
return self.context
|