# $SnapHashLicense:
#
# SnapLogic - Open source data services
#
# Copyright (C) 2008-2009, SnapLogic, Inc. All rights reserved.
#
# See http://www.snaplogic.org for more information about
# the SnapLogic project.
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LEGAL file
# at the top of the source tree.
#
# "SnapLogic" is a trademark of SnapLogic, Inc.
#
#
# $
# $Id: __init__.py 7729 2009-05-21 00:20:51Z dhiraj $
""" snaplogic.server package """
log = None
elog = None
config = None
logger = None
public_uri = None
"""URI derived from the config file, which respresents the official address of the server."""
auth_realm = "SnapLogic"
"""The realm used for HTTP authentication. Is here rather than in auth package to avoid circular-import issues."""
cc_token_list = []
""" The list of CC tokens. The information is redundantly stored in a list for easy lookup."""
server_token = None
"""This server's token."""
local_host_ip_addresses = None
"""All the IP addresses configured on the local host."""
server_port = None
"""The server port that the server listens on."""
class RhResponse(object):
"""
Response object for any RH handler functions.
The Request Handler calls various handler functions (which may be
located in different modules) to handle the actual requests. This
object here is the response that is returned by those handler
functions.
An important aspect of the response is the error indicator, which
is returned as a tuple. The error indicator consists of one of our
own response codes (which are returned inside of an X-header), and
an error message.
Exposes:
http_code
data
status
options
headers
The 'headers' element may be used to specify additional response
header lines. This is commonly used when a 401 error is returnd
which requires the WWW-authenticate header.
"""
def __init__(self, http_code, data=None, status=None, options=None):
"""
Initialize the response object.
@param http_code: The HTTP response code.
@type http_code: integer
@param data: The object that should be returned in the
response message body.
@type data: string
@param status: A number indicating the Snapi status code.
If this is defined, a X-Snapi-status header
will be added to the response. If this is
an error, then it is advised to send a detailed
error message as the reponse body.
@type status: integer
@param options: Options for the rendering (the RP modules).
has to be a dictionary specifying name value
pairs, which are interpreted (or ignored)
by the RPs any way they wish. An example of
the use of these options is an indication to
an HTML RP to render in fixed-width font.
@type options: dict
"""
self.http_code = http_code
self.data = data
self.status = status
self.options = options
self.headers = []
if http_code == 401:
self.headers.append( ( "WWW-Authenticate", "Basic realm=\"%s\"" % auth_realm ) )
def __repr__(self):
"""
The string representation of the RhResponse object.
This is mosty useful for debugging.
"""
s = "HTTP_CODE: %s\nDATA: %s\nSTATUS: %s\nOPTIONS: %s" % (self.http_code, self.data, self.status, self.options)
return s
|