/usr/lib/python2.7/dist-packages/twext/web2/iweb.py is in calendarserver 5.2+dfsg-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 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 | # -*- test-case-name: twext.web2.test -*-
##
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
# Copyright (c) 2010-2014 Apple Computer, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
##
"""
I contain the interfaces for several web related objects including IRequest
and IResource. I am based heavily on ideas from C{nevow.inevow}.
"""
from zope.interface import Attribute, Interface, interface
# server.py interfaces
class IResource(Interface):
"""
An HTTP resource.
I serve 2 main purposes: one is to provide a standard representation for
what HTTP specification calls an 'entity', and the other is to provide an
mechanism for mapping URLs to content.
"""
def locateChild(req, segments):
"""
Locate another object which can be adapted to IResource.
@return: A 2-tuple of (resource, remaining-path-segments),
or a deferred which will fire the above.
Causes the object publishing machinery to continue on
with specified resource and segments, calling the
appropriate method on the specified resource.
If you return (self, L{server.StopTraversal}), this
instructs web2 to immediately stop the lookup stage,
and switch to the rendering stage, leaving the
remaining path alone for your render function to
handle.
"""
def renderHTTP(req):
"""
Return an IResponse or a deferred which will fire an
IResponse. This response will be written to the web browser
which initiated the request.
"""
# Is there a better way to do this than this funky extra class?
_default = object()
class SpecialAdaptInterfaceClass(interface.InterfaceClass):
# A special adapter for IResource to handle the extra step of adapting
# from IOldNevowResource-providing resources.
def __call__(self, other, alternate=_default):
result = super(SpecialAdaptInterfaceClass, self).__call__(other, alternate)
if result is not alternate:
return result
result = IOldNevowResource(other, alternate)
if result is not alternate:
result = IResource(result)
return result
if alternate is not _default:
return alternate
raise TypeError('Could not adapt', other, self)
IResource.__class__ = SpecialAdaptInterfaceClass
class IOldNevowResource(Interface):
# Shared interface with inevow.IResource
"""
I am a web resource.
"""
def locateChild(ctx, segments):
"""
Locate another object which can be adapted to IResource
Return a tuple of resource, path segments
"""
def renderHTTP(ctx):
"""
Return a string or a deferred which will fire a string. This string
will be written to the web browser which initiated this request.
Unlike iweb.IResource, this expects the incoming data to have already been read
and parsed into request.args and request.content, and expects to return a
string instead of a response object.
"""
class ICanHandleException(Interface):
# Shared interface with inevow.ICanHandleException
def renderHTTP_exception(request, failure):
"""
Render an exception to the given request object.
"""
def renderInlineException(request, reason):
"""
Return stan representing the exception, to be printed in the page,
not replacing the page."""
# http.py interfaces
class IResponse(Interface):
"""
I'm a response.
"""
code = Attribute("The HTTP response code")
headers = Attribute("A http_headers.Headers instance of headers to send")
stream = Attribute("A stream.IByteStream of outgoing data, or else None.")
class IRequest(Interface):
"""
I'm a request for a web resource.
"""
method = Attribute("The HTTP method from the request line, e.g. GET")
uri = Attribute("The raw URI from the request line. May or may not include host.")
clientproto = Attribute("Protocol from the request line, e.g. HTTP/1.1")
headers = Attribute("A http_headers.Headers instance of incoming headers.")
stream = Attribute("A stream.IByteStream of incoming data.")
def writeResponse(response):
"""
Write an IResponse object to the client.
"""
chanRequest = Attribute("The ChannelRequest. I wonder if this is public really?")
from twisted.web.iweb import IRequest as IOldRequest
class IChanRequestCallbacks(Interface):
"""
The bits that are required of a Request for interfacing with a
IChanRequest object
"""
def __init__(chanRequest, command, path, version, contentLength, inHeaders):
"""
Create a new Request object.
@param chanRequest: the IChanRequest object creating this request
@param command: the HTTP command e.g. GET
@param path: the HTTP path e.g. /foo/bar.html
@param version: the parsed HTTP version e.g. (1,1)
@param contentLength: how much data to expect, or None if unknown
@param inHeaders: the request headers"""
def process():
"""
Process the request. Called as soon as it's possibly reasonable
to return a response. L{handleContentComplete} may or may not
have been called already.
"""
def handleContentChunk(data):
"""
Called when a piece of incoming data has been received.
"""
def handleContentComplete():
"""
Called when the incoming data stream is finished.
"""
def connectionLost(reason):
"""
Called if the connection was lost.
"""
class IChanRequest(Interface):
def writeIntermediateResponse(code, headers=None):
"""
Write a non-terminating response.
Intermediate responses cannot contain data.
If the channel does not support intermediate responses, do nothing.
@param code: The response code. Should be in the 1xx range.
@type code: int
@param headers: the headers to send in the response
@type headers: C{twisted.web.http_headers.Headers}
"""
def writeHeaders(code, headers):
"""
Write a final response.
@param code: The response code. Should not be in the 1xx range.
@type code: int
@param headers: the headers to send in the response. They will
be augmented with any connection-oriented headers as
necessary for the protocol.
@type headers: C{twisted.web.http_headers.Headers}
"""
def write(data):
"""
Write some data.
@param data: the data bytes
@type data: str
"""
def finish():
"""
Finish the request, and clean up the connection if necessary.
"""
def abortConnection():
"""
Forcibly abort the connection without cleanly closing.
Use if, for example, you can't write all the data you promised.
"""
def registerProducer(producer, streaming):
"""
Register a producer with the standard API.
"""
def unregisterProducer():
"""
Unregister a producer.
"""
def getHostInfo():
"""
Returns a tuple of (address, socket user connected to,
boolean, was it secure). Note that this should not necessarily
always return the actual local socket information from
twisted. E.g. in a CGI, it should use the variables coming
from the invoking script.
"""
def getRemoteHost():
"""
Returns an address of the remote host.
Like L{getHostInfo}, this information may come from the real
socket, or may come from additional information, depending on
the transport.
"""
persistent = Attribute("""Whether this request supports HTTP connection persistence. May be set to False. Should not be set to other values.""")
class ISite(Interface):
pass
__all__ = ['ICanHandleException', 'IChanRequest', 'IChanRequestCallbacks', 'IOldNevowResource', 'IOldRequest', 'IRequest', 'IResource', 'IResponse', 'ISite']
|