app/soc/views/out_of_band.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 19 Oct 2008 00:34:33 +0000
changeset 387 c55195361cb6
parent 303 4f1bb54ddae5
child 543 280a1ac6bcc1
permissions -rw-r--r--
Addressed comments by Todd on r822 Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
303
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Out-of-band responses to render instead of the usual HTTP response.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
class OutOfBandResponse(Exception):
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
  """Base exception for out-of-band responses raised by views.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
  """
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
  pass
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
class AccessViolationResponse(OutOfBandResponse):
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
  """"Out of band response when an access requirement was not met.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  """
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
  def __init__(self, response):
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
    """Constructor used to set response message.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
    Args:
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
      response: The response that should be returned to the user.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
    """
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
    self._response = response
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  def response(self):
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    """Returns the response that was set in the constructor.
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
    """
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
4f1bb54ddae5 Moved soc/logic/helper/access to soc/views/helper/access
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
    return self._response