app/soc/logic/out_of_band.py
author Todd Larsen <tlarsen@google.com>
Tue, 23 Sep 2008 23:30:15 +0000
changeset 190 b1351bf81064
parent 111 f506a22f50db
child 293 1edd01373e71
permissions -rw-r--r--
Move isReferrerSelf() and replaceSuffix() into new request_helpers.py module, since they are (mainly) used to manipulate parts of an HTTP request.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
111
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Out-of-band responses to render instead of the usual HTTP response.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  ]
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
class OutOfBandResponse(Exception):
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
  """Base exception for out-of-band responses raised by controller logic.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
  """
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
  pass
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
class ErrorResponse(OutOfBandResponse):
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
  """Out-of-band response when controller logic needs a special error page.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
  """
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
  def __init__(self, message, **response_args):
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
    """Constructor used to set error message and HTTP response arguments.
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
  
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
    Args:
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
      message: error message to display on the error page
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
      **response_args: keyword arguments that are supplied directly to
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
        django.http.HttpResponse; the most commonly used is 'status' to
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
        set the HTTP status code for the response
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
    """
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
    self.message = message
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
    self.response_args = response_args
f506a22f50db Exception classes used by controller logic to request an "out-of-band" response
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46