/usr/share/pyshared/zope/publisher/interfaces/__init__.py is in python-zope.publisher 3.12.6-2ubuntu1.
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 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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | ##############################################################################
#
# Copyright (c) 2001-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.
#
##############################################################################
"""Interfaces for the publisher.
"""
__docformat__ = "reStructuredText"
from zope.browser.interfaces import IView # BBB import
from zope.interface import Interface
from zope.interface import Attribute
from zope.interface import implements
from zope.interface.interfaces import IInterface
from zope.interface.common.mapping import IEnumerableMapping
from zope.interface.common.interfaces import IException
from zope.interface.common.interfaces import ILookupError
from zope.security.interfaces import IParticipation
from zope.security.interfaces import Unauthorized
class IPublishingException(IException):
pass
class PublishingException(Exception):
implements(IPublishingException)
class ITraversalException(IPublishingException):
pass
class TraversalException(PublishingException):
implements(ITraversalException)
class INotFound(ILookupError, ITraversalException):
def getObject():
'Returns the object that was being traversed.'
def getName():
'Returns the name that was being traversed.'
class NotFound(LookupError, TraversalException):
implements(INotFound)
def __init__(self, ob, name, request=None):
self.ob = ob
self.name = name
def getObject(self):
return self.ob
def getName(self):
return self.name
def __str__(self):
try:
ob = `self.ob`
except:
ob = 'unprintable object'
return 'Object: %s, name: %s' % (ob, `self.name`)
class IDebugError(ITraversalException):
def getObject():
'Returns the object being traversed.'
def getMessage():
'Returns the debug message.'
class DebugError(TraversalException):
implements(IDebugError)
message = None # override this not to cause warnings in python 2.6
def __init__(self, ob, message):
self.ob = ob
self.message = message
def getObject(self):
return self.ob
def getMessage(self):
return self.message
def __str__(self):
return self.message
class IBadRequest(IPublishingException):
def __str__():
'Returns the error message.'
class BadRequest(PublishingException):
implements(IBadRequest)
message = None # override this not to cause warnings in python 2.6
def __init__(self, message):
self.message = message
def __str__(self):
return self.message
class IRedirect(IPublishingException):
def getLocation():
'Returns the location.'
class Redirect(PublishingException):
implements(IRedirect)
def __init__(self, location):
self.location = location
def getLocation(self):
return self.location
def __str__(self):
return 'Location: %s' % self.location
class IRetry(IPublishingException):
def getOriginalException():
'Returns the original exception object.'
class Retry(PublishingException):
"""Raise this to retry a request."""
implements(IRetry)
def __init__(self, orig_exc=None):
"""orig_exc must be a 3-tuple as returned from sys.exc_info() or None"""
self.orig_exc = orig_exc
def getOriginalException(self):
return self.orig_exc
def __str__(self):
if self.orig_exc is None:
return 'None'
return str(self.orig_exc[1])
class IExceptionSideEffects(Interface):
"""An exception caught by the publisher is adapted to this so that
it can have persistent side-effects."""
def __call__(obj, request, exc_info):
"""Effect persistent side-effects.
Arguments are:
obj context-wrapped object that was published
request the request
exc_info the exception info being handled
"""
class IPublishTraverse(Interface):
def publishTraverse(request, name):
"""Lookup a name
The 'request' argument is the publisher request object. The
'name' argument is the name that is to be looked up; it must
be an ASCII string or Unicode object.
If a lookup is not possible, raise a NotFound error.
This method should return an object having the specified name and
`self` as parent. The method can use the request to determine the
correct object.
"""
class IPublisher(Interface):
def publish(request):
"""Publish a request
The request must be an IPublisherRequest.
"""
class IResponse(Interface):
"""Interface used by the publsher"""
def setResult(result):
"""Sets the response result value.
"""
def handleException(exc_info):
"""Handles an exception.
This method is intended only as a convenience for the publication
object. The publication object can choose to handle exceptions by
calling this method. The publication object can also choose not
to call this method at all.
Implementations set the reponse body.
"""
def internalError():
"""Called when the exception handler bombs.
Should report back to the client that an internal error occurred.
"""
def reset():
"""Reset the output result.
Reset the response by nullifying already set variables.
"""
def retry():
"""Returns a retry response
Returns a response suitable for repeating the publication attempt.
"""
class IPublication(Interface):
"""Object publication framework.
The responsibility of publication objects is to provide
application hooks for the publishing process. This allows
application-specific tasks, such as connecting to databases,
managing transactions, and setting security contexts to be invoked
during the publishing process.
"""
# The order of the hooks mostly corresponds with the order in which
# they are invoked.
def beforeTraversal(request):
"""Pre-traversal hook.
This is called *once* before any traversal has been done.
"""
def getApplication(request):
"""Returns the object where traversal should commence.
"""
def callTraversalHooks(request, ob):
"""Invokes any traversal hooks associated with the object.
This is called before traversing each object. The ob argument
is the object that is about to be traversed.
"""
def traverseName(request, ob, name):
"""Traverses to the next object.
Name must be an ASCII string or Unicode object."""
def afterTraversal(request, ob):
"""Post-traversal hook.
This is called after all traversal.
"""
def callObject(request, ob):
"""Call the object, returning the result.
For GET/POST this means calling it, but for other methods
(including those of WebDAV and FTP) this might mean invoking
a method of an adapter.
"""
def afterCall(request, ob):
"""Post-callObject hook (if it was successful).
"""
def handleException(object, request, exc_info, retry_allowed=1):
"""Handle an exception
Either:
- sets the body of the response, request.response, or
- raises a Retry exception, or
- throws another exception, which is a Bad Thing.
"""
def endRequest(request, ob):
"""Do any end-of-request cleanup
"""
class IPublicationRequest(IParticipation):
"""Interface provided by requests to IPublication objects
"""
response = Attribute("""The request's response object
Return an IPublisherResponse for the request.
""")
def close():
"""Release resources held by the request.
"""
def hold(held):
"""Hold a reference to an object until the request is closed.
The object should be an IHeld. If it is an IHeld, its
release method will be called when it is released.
"""
def getTraversalStack():
"""Return the request traversal stack
This is a sequence of steps to traverse in reverse order. They
will be traversed from last to first.
"""
def setTraversalStack(stack):
"""Change the traversal stack.
See getTraversalStack.
"""
def getPositionalArguments():
"""Return the positional arguments given to the request.
"""
def setPrincipal(principal):
"""Set the principal attribute.
It should be IPrincipal wrapped in its AuthenticationService's context.
"""
class IHeld(Interface):
"""Object to be held and explicitly released by a request
"""
def release():
"""Release the held object
This is called by a request that holds the IHeld when the
request is closed
"""
class IPublisherRequest(IPublicationRequest):
"""Request interface use by the publisher
The responsibility of requests is to encapsulate protocol
specific details, especially wrt request inputs.
Request objects also serve as "context" objects, providing
construction of and access to responses and storage of publication
objects.
"""
def supportsRetry():
"""Check whether the request supports retry
Return a boolean value indicating whether the request can be retried.
"""
def retry():
"""Return a retry request
Return a request suitable for repeating the publication attempt.
"""
publication = Attribute("""The request's publication object
The publication object, an IRequestPublication provides
application-specific functionality hooks.
""")
def setPublication(publication):
"""Set the request's publication object
"""
def traverse(obj):
"""Traverse from the given object to the published object
The published object is returned.
The following hook methods on the publication will be called:
- callTraversalHooks is called before each step and after
the last step.
- traverseName to actually do a single traversal
"""
def processInputs():
"""Do any input processing that needs to be done before traversing
This is done after construction to allow the publisher to
handle errors that arise.
"""
class IDebugFlags(Interface):
"""Features that support debugging."""
sourceAnnotations = Attribute("""Enable ZPT source annotations""")
showTAL = Attribute("""Leave TAL markup in rendered page templates""")
class IApplicationRequest(IEnumerableMapping):
"""Features that support application logic
"""
principal = Attribute("""Principal object associated with the request
This is a read-only attribute.
""")
bodyStream = Attribute(
"""The stream that provides the data of the request.
The data returned by the stream will not include any possible header
information, which should have been stripped by the server (or
previous layer) before.
Also, the body stream might already be read and not return any
data. This is commonly done when retrieving the data for the ``body``
attribute.
If you access this stream directly to retrieve data, it will not be
possible by other parts of the framework to access the data of the
request via the ``body`` attribute.""")
debug = Attribute("""Debug flags (see IDebugFlags).""")
def __getitem__(key):
"""Return request data
The only request data are environment variables.
"""
environment = Attribute(
"""Request environment data
This is a read-only mapping from variable name to value.
""")
annotations = Attribute(
"""Stores arbitrary application data under package-unique keys.
By "package-unique keys", we mean keys that are are unique by
virtue of including the dotted name of a package as a prefex. A
package name is used to limit the authority for picking names for
a package to the people using that package.
For example, when implementing annotations for hypothetical
request-persistent adapters in a hypothetical zope.persistentadapter
package, the key would be (or at least begin with) the following::
"zope.persistentadapter"
""")
class IRequest(IPublisherRequest, IPublicationRequest, IApplicationRequest):
"""The basic request contract
"""
class IRequestEvent(Interface):
"""An event which is about or for a request."""
request = Attribute("The request this event is about.")
class IEndRequestEvent(IRequestEvent):
"""An event which gets sent when the publication is ended."""
class IStartRequestEvent(IRequestEvent):
"""An event which gets sent before publication of a request."""
class RequestEvent(object):
"""Events for requests.
:ivar request: The request the event is for.
"""
def __init__(self, request):
self.request = request
class EndRequestEvent(RequestEvent):
"""An event which gets sent when the publication is ended"""
implements(IEndRequestEvent)
def __init__(self, ob, request):
super(EndRequestEvent, self).__init__(request)
self.object = ob
class StartRequestEvent(RequestEvent):
"""An event send when before publication of a request."""
implements(IStartRequestEvent)
class ISkinType(IInterface):
"""Base interface for skin types."""
class ISkinnable(Interface):
"""A skinnable (request) can provide a skin.
The implementation in BrowserRequest will apply a default skin/layer called
``IDefaultBrowserLayer`` if not default skin get registered.
"""
class IDefaultSkin(Interface):
"""Any component providing this interface must be a skin.
This is a marker interface, so that we can register the default skin as an
adapter from the presentation type to `IDefaultSkin`.
"""
class ISkinChangedEvent(IRequestEvent):
"""Event that gets triggered when the skin of a request is changed."""
class IDefaultViewName(Interface):
"""A string that contains the default view name
A default view name is used to select a view when a user hasn't
specified one.
"""
class IReRaiseException(Interface):
"""An exception that should be reraised, when handled in publisher.
Under some circumstances (for instance if acting in a WSGI
pipeline with debugger middleware) certain exceptions occuring
while publishing should be handled by the Zope machinery and never
reach the 'outside world'.
Adapters providing this interface for a certain exception type
which also return ``False`` when being called, indicate by this
that the exception should not be reraised during publishing.
This makes it possible, for instance, to authenticate with
basic-auth when a debugger middleware is used and `IUnauthorized`
is raised.
"""
def __call__():
"""Return True if an exception should be re-raised"""
|