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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
:mod:`zope.location` API
========================
:mod:`zope.location.interfaces`
-------------------------------
.. automodule:: zope.location.interfaces
.. autointerface:: ILocation
:members:
:member-order: bysource
.. autointerface:: IContained
:members:
:member-order: bysource
.. autointerface:: ILocationInfo
:members:
:member-order: bysource
.. autointerface:: ISublocations
:members:
:member-order: bysource
.. autointerface:: IRoot
:members:
:member-order: bysource
.. autoexception:: LocationError
:members:
:member-order: bysource
:mod:`zope.location.location`
-----------------------------
.. automodule:: zope.location.location
.. autoclass:: Location
:members:
:member-order: bysource
.. autofunction:: locate
.. autofunction:: located
.. autofunction:: LocationIterator
.. autofunction:: inside
.. autoclass:: LocationProxy
:members:
:member-order: bysource
:mod:`zope.location.traversing`
-------------------------------
.. automodule:: zope.location.traversing
.. autoclass:: LocationPhysicallyLocatable
.. doctest::
>>> from zope.interface.verify import verifyObject
>>> from zope.location.interfaces import ILocationInfo
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> info = LocationPhysicallyLocatable(Location())
>>> verifyObject(ILocationInfo, info)
True
.. automethod:: getRoot
.. doctest::
>>> from zope.interface import directlyProvides
>>> from zope.location.interfaces import IRoot
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> root = Location()
>>> directlyProvides(root, IRoot)
>>> LocationPhysicallyLocatable(root).getRoot() is root
True
>>> o1 = Location(); o1.__parent__ = root
>>> LocationPhysicallyLocatable(o1).getRoot() is root
True
>>> o2 = Location(); o2.__parent__ = o1
>>> LocationPhysicallyLocatable(o2).getRoot() is root
True
We'll get a TypeError if we try to get the location fo a
rootless object:
.. doctest::
>>> o1.__parent__ = None
>>> LocationPhysicallyLocatable(o1).getRoot()
Traceback (most recent call last):
...
TypeError: Not enough context to determine location root
>>> LocationPhysicallyLocatable(o2).getRoot()
Traceback (most recent call last):
...
TypeError: Not enough context to determine location root
If we screw up and create a location cycle, it will be caught:
.. doctest::
>>> o1.__parent__ = o2
>>> LocationPhysicallyLocatable(o1).getRoot()
Traceback (most recent call last):
...
TypeError: Maximum location depth exceeded, probably due to a a location cycle.
.. automethod:: getPath
.. doctest::
>>> from zope.interface import directlyProvides
>>> from zope.location.interfaces import IRoot
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> root = Location()
>>> directlyProvides(root, IRoot)
>>> print(LocationPhysicallyLocatable(root).getPath())
/
>>> o1 = Location(); o1.__parent__ = root; o1.__name__ = 'o1'
>>> print(LocationPhysicallyLocatable(o1).getPath())
/o1
>>> o2 = Location(); o2.__parent__ = o1; o2.__name__ = u'o2'
>>> print(LocationPhysicallyLocatable(o2).getPath())
/o1/o2
It is an error to get the path of a rootless location:
.. doctest::
>>> o1.__parent__ = None
>>> LocationPhysicallyLocatable(o1).getPath()
Traceback (most recent call last):
...
TypeError: Not enough context to determine location root
>>> LocationPhysicallyLocatable(o2).getPath()
Traceback (most recent call last):
...
TypeError: Not enough context to determine location root
If we screw up and create a location cycle, it will be caught:
.. doctest::
>>> o1.__parent__ = o2
>>> LocationPhysicallyLocatable(o1).getPath()
Traceback (most recent call last):
...
TypeError: Maximum location depth exceeded, """ \
"""probably due to a a location cycle.
.. automethod:: getParent
.. doctest::
>>> from zope.interface import directlyProvides
>>> from zope.location.interfaces import IRoot
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> root = Location()
>>> directlyProvides(root, IRoot)
>>> o1 = Location()
>>> o2 = Location()
>>> LocationPhysicallyLocatable(o2).getParent() # doctest: +ELLIPSIS
Traceback (most recent call last):
TypeError: ('Not enough context information to get parent', <zope.location.location.Location object at 0x...>)
>>> o1.__parent__ = root
>>> LocationPhysicallyLocatable(o1).getParent() == root
True
>>> o2.__parent__ = o1
>>> LocationPhysicallyLocatable(o2).getParent() == o1
True
.. automethod:: getParents
.. doctest::
>>> from zope.interface import directlyProvides
>>> from zope.interface import noLongerProvides
>>> from zope.location.interfaces import IRoot
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> root = Location()
>>> directlyProvides(root, IRoot)
>>> o1 = Location()
>>> o2 = Location()
>>> o1.__parent__ = root
>>> o2.__parent__ = o1
>>> LocationPhysicallyLocatable(o2).getParents() == [o1, root]
True
If the last parent is not an IRoot object, TypeError will be
raised as statet before.
>>> noLongerProvides(root, IRoot)
>>> LocationPhysicallyLocatable(o2).getParents()
Traceback (most recent call last):
...
TypeError: Not enough context information to get all parents
.. automethod:: getName
.. doctest::
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> o1 = Location(); o1.__name__ = u'o1'
>>> print(LocationPhysicallyLocatable(o1).getName())
o1
.. automethod:: getNearestSite
.. doctest::
>>> from zope.interface import directlyProvides
>>> from zope.component.interfaces import ISite
>>> from zope.location.interfaces import IRoot
>>> from zope.location.location import Location
>>> from zope.location.traversing import LocationPhysicallyLocatable
>>> o1 = Location()
>>> o1.__name__ = 'o1'
>>> LocationPhysicallyLocatable(o1).getNearestSite()
Traceback (most recent call last):
...
TypeError: Not enough context information to get all parents
>>> root = Location()
>>> directlyProvides(root, IRoot)
>>> o1 = Location()
>>> o1.__name__ = 'o1'
>>> o1.__parent__ = root
>>> LocationPhysicallyLocatable(o1).getNearestSite() is root
True
>>> directlyProvides(o1, ISite)
>>> LocationPhysicallyLocatable(o1).getNearestSite() is o1
True
>>> o2 = Location()
>>> o2.__parent__ = o1
>>> LocationPhysicallyLocatable(o2).getNearestSite() is o1
True
.. autoclass:: RootPhysicallyLocatable
.. doctest::
>>> from zope.interface.verify import verifyObject
>>> from zope.location.interfaces import ILocationInfo
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> info = RootPhysicallyLocatable(None)
>>> verifyObject(ILocationInfo, info)
True
.. automethod:: getRoot
No need to search for root when our context is already root :)
.. doctest::
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> o1 = object()
>>> RootPhysicallyLocatable(o1).getRoot() is o1
True
.. automethod:: getPath
Root object is at the top of the tree, so always return ``/``.
.. doctest::
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> o1 = object()
>>> print(RootPhysicallyLocatable(o1).getPath())
/
.. automethod:: getParent
Returns None if the object is a containment root.
Raises TypeError if the object doesn't have enough context to get the
parent.
.. doctest::
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> o1 = object()
>>> RootPhysicallyLocatable(o1).getParent() is None
True
.. automethod:: getParents
There's no parents for the root object, return empty list.
.. doctest::
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> o1 = object()
>>> RootPhysicallyLocatable(o1).getParents()
[]
.. automethod:: getName
Always return empty unicode string for the root object
.. doctest::
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> o1 = object()
>>> RootPhysicallyLocatable(o1).getName() == u''
True
.. automethod:: getNearestSite
Return object itself as the nearest site, because there's no
other place to look for. It's also usual that the root is the
site as well.
.. doctest::
>>> from zope.location.traversing import RootPhysicallyLocatable
>>> o1 = object()
>>> RootPhysicallyLocatable(o1).getNearestSite() is o1
True
|