home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.3)
-
- import sys
- import traceback
- import time
- import os
- import pdb
- import stat
- import imp
- import types
- import _apache
- _path = None
-
- class CallBack:
- '''
- A generic callback object.
- '''
-
- class HStack:
- '''
- The actual stack string lives in the request object so
- it can be manipulated by both apache.py and mod_python.c
- '''
-
- def __init__(self, req):
- self.req = req
-
-
- def pop(self):
- handlers = self.req.hstack.split()
- if not handlers:
- return None
- else:
- self.req.hstack = ' '.join(handlers[1:])
- return handlers[0]
-
-
-
- def ConnectionDispatch(self, conn):
- global _path
- config = conn.base_server.get_config()
- debug = int(config.get('PythonDebug', 0))
-
- try:
- handler = conn.hlist.handler
- l = handler.split('::', 1)
- module_name = l[0]
- if len(l) == 1:
- object_str = 'connectionhandler'
- else:
- object_str = l[1]
- if config.has_key('PythonPath'):
- pathstring = config['PythonPath']
- if pathstring != _path:
- _path = pathstring
- newpath = eval(pathstring)
- if sys.path != newpath:
- sys.path[:] = newpath
-
-
-
- module = import_module(module_name, autoreload = int(config.get('PythonAutoReload', 1)), log = debug)
- object = resolve_object(module, object_str, arg = conn, silent = 0)
- if object:
- if config.has_key('PythonEnablePdb'):
- result = pdb.runcall(object, conn)
- else:
- result = object(conn)
- if not type(result) == type(int()):
- raise AssertionError, "ConnectionHandler '%s' returned invalid return code." % handler
- except PROG_TRACEBACK:
- traceblock = None
-
- try:
- (etype, value, traceback) = traceblock
- result = self.ReportError(etype, value, traceback, srv = conn.base_server, phase = 'ConnectionHandler', hname = handler, debug = debug)
- finally:
- traceback = None
-
- except:
-
- try:
- (exc_type, exc_value, exc_traceback) = sys.exc_info()
- result = self.ReportError(exc_type, exc_value, exc_traceback, srv = conn.base_server, phase = 'ConnectionHandler', hname = handler, debug = debug)
- finally:
- exc_traceback = None
-
-
- return result
-
-
- def FilterDispatch(self, filter):
- global _path
- req = filter.req
- config = req.get_config()
- debug = int(config.get('PythonDebug', 0))
-
- try:
- l = filter.handler.split('::', 1)
- module_name = l[0]
- if len(l) == 1:
- if filter.is_input:
- object_str = 'inputfilter'
- else:
- object_str = 'outputfilter'
- else:
- object_str = l[1]
- if config.has_key('PythonPath'):
- pathstring = config['PythonPath']
- if pathstring != _path:
- _path = pathstring
- newpath = eval(pathstring)
- if sys.path != newpath:
- sys.path[:] = newpath
-
-
- elif filter.dir and filter.dir not in sys.path:
- sys.path[:0] = [
- filter.dir]
-
- module = import_module(module_name, autoreload = int(config.get('PythonAutoReload', 1)), log = debug)
- object = resolve_object(module, object_str, arg = filter, silent = 0)
- if object:
- if config.has_key('PythonEnablePdb'):
- pdb.runcall(object, filter)
- else:
- object(filter)
- filter.flush()
- except SERVER_RETURN:
- value = None
-
- try:
- if len(value.args) == 2:
- (result, status) = value.args
- if status:
- req.status = status
-
- else:
- result = value.args[0]
- if type(result) != type(7):
- s = 'Value raised with SERVER_RETURN is invalid. It is a '
- s = s + '%s, but it must be a tuple or an int.' % type(result)
- _apache.log_error(s, APLOG_NOERRNO | APLOG_ERR, req.server)
- return None
-
- except PROG_TRACEBACK:
- traceblock = None
-
- try:
- (etype, value, traceback) = traceblock
- filter.disable()
- result = self.ReportError(etype, value, traceback, req = req, filter = filter, phase = 'Filter: ' + filter.name, hname = filter.handler, debug = debug)
- finally:
- traceback = None
-
- except:
-
- try:
- (exc_type, exc_value, exc_traceback) = sys.exc_info()
- filter.disable()
- result = self.ReportError(exc_type, exc_value, exc_traceback, req = req, filter = filter, phase = filter.name, hname = filter.handler, debug = debug)
- finally:
- exc_traceback = None
-
-
- return OK
-
-
- def HandlerDispatch(self, req):
- '''
- This is the handler dispatcher.
- '''
- global _path
- result = HTTP_INTERNAL_SERVER_ERROR
- config = req.get_config()
- debug = int(config.get('PythonDebug', 0))
-
- try:
- hlist = req.hlist
- while hlist.handler:
- l = hlist.handler.split('::', 1)
- module_name = l[0]
- if len(l) == 1:
- object_str = req.phase[len('python'):].lower()
- else:
- object_str = l[1]
- if config.has_key('PythonPath'):
- pathstring = config['PythonPath']
- if pathstring != _path:
- _path = pathstring
- newpath = eval(pathstring)
- if sys.path != newpath:
- sys.path[:] = newpath
-
-
- else:
- dir = hlist.directory
- if dir and dir not in sys.path:
- sys.path[:0] = [
- dir]
-
- module = import_module(module_name, autoreload = int(config.get('PythonAutoReload', 1)), log = debug)
- object = resolve_object(module, object_str, arg = req, silent = hlist.silent)
- if object:
- if config.has_key('PythonEnablePdb'):
- result = pdb.runcall(object, req)
- else:
- result = object(req)
- if not type(result) == type(int()):
- raise AssertionError, "Handler '%s' returned invalid return code." % hlist.handler
- if result != OK:
- break
-
- elif hlist.silent:
- result = DECLINED
-
- hlist.next()
- except SERVER_RETURN:
- value = None
-
- try:
- if len(value.args) == 2:
- (result, status) = value.args
- if status:
- req.status = status
-
- else:
- result = value.args[0]
- if type(result) != type(7):
- s = 'Value raised with SERVER_RETURN is invalid. It is a '
- s = s + '%s, but it must be a tuple or an int.' % type(result)
- _apache.log_error(s, APLOG_NOERRNO | APLOG_ERR, req.server)
- return HTTP_INTERNAL_SERVER_ERROR
-
- except PROG_TRACEBACK:
- traceblock = None
-
- try:
- (etype, value, traceback) = traceblock
- result = self.ReportError(etype, value, traceback, req = req, phase = req.phase, hname = hlist.handler, debug = debug)
- finally:
- traceback = None
-
- except:
-
- try:
- (exc_type, exc_value, exc_traceback) = sys.exc_info()
- result = self.ReportError(exc_type, exc_value, exc_traceback, req = req, phase = req.phase, hname = hlist.handler, debug = debug)
- finally:
- exc_traceback = None
-
-
- return result
-
-
- def ReportError(self, etype, evalue, etb, req = None, filter = None, srv = None, phase = 'N/A', hname = 'N/A', debug = 0):
- """
- \tThis function is only used when debugging is on.
- \tIt sends the output similar to what you'd see
- \twhen using Python interactively to the browser
- \t"""
-
- try:
- if str(etype) == 'exceptions.IOError' and str(evalue)[:5] == 'Write':
- debug = 0
-
- for e in traceback.format_exception(etype, evalue, etb):
- s = '%s %s: %s' % (phase, hname, e[:-1])
- if req:
- req.log_error(s, APLOG_NOERRNO | APLOG_ERR)
- continue
- _apache.log_error(s, APLOG_NOERRNO | APLOG_ERR, srv)
-
- if not debug or not req:
- return HTTP_INTERNAL_SERVER_ERROR
- else:
- req.content_type = 'text/html'
- s = '\n<pre>\nMod_python error: "%s %s"\n\n' % (phase, hname)
- for e in traceback.format_exception(etype, evalue, etb):
- s = s + e + '\n'
-
- s = s + '</pre>\n'
- if filter:
- filter.write(s)
- filter.flush()
- else:
- req.write(s)
- return DONE
- except:
- traceback.print_exc()
- finally:
- etb = None
-
-
-
-
- def import_module(module_name, autoreload = 1, log = 0, path = None):
- '''
- Get the module to handle the request. If
- autoreload is on, then the module will be reloaded
- if it has changed since the last import.
- '''
- if sys.modules.has_key(module_name):
- module = sys.modules[module_name]
- file = module.__dict__.get('__file__')
- if not file and path and not filter(file.startswith, path):
- (mtime, oldmtime) = (0, -1)
- elif autoreload:
- oldmtime = module.__dict__.get('__mtime__', 0)
- mtime = module_mtime(module)
- else:
- (mtime, oldmtime) = (0, 0)
- else:
- (mtime, oldmtime) = (0, -1)
- if mtime > oldmtime:
- if log:
- if path:
- s = "mod_python: (Re)importing module '%s' with path set to '%s'" % (module_name, path)
- else:
- s = "mod_python: (Re)importing module '%s'" % module_name
- _apache.log_error(s, APLOG_NOERRNO | APLOG_NOTICE)
-
- parts = module_name.split('.')
- for i in range(len(parts)):
- (f, p, d) = imp.find_module(parts[i], path)
-
- try:
- mname = '.'.join(parts[:i + 1])
- module = imp.load_module(mname, f, p, d)
- finally:
- if f:
- f.close()
-
-
- if hasattr(module, '__path__'):
- path = module.__path__
- continue
-
- if mtime == 0:
- mtime = module_mtime(module)
-
- module.__mtime__ = mtime
-
- return module
-
-
- def module_mtime(module):
- '''Get modification time of module'''
- mtime = 0
- if module.__dict__.has_key('__file__'):
- filepath = module.__file__
-
- try:
- if os.path.exists(filepath):
- mtime = os.path.getmtime(filepath)
-
- if os.path.exists(filepath[:-1]):
- mtime = max(mtime, os.path.getmtime(filepath[:-1]))
- except OSError:
- pass
- except:
- None<EXCEPTION MATCH>OSError
-
-
- None<EXCEPTION MATCH>OSError
- return mtime
-
-
- def resolve_object(module, object_str, arg = None, silent = 0):
- """
- This function traverses the objects separated by .
- (period) to find the last one we're looking for:
-
- From left to right, find objects, if it is
- an unbound method of a class, instantiate the
- class passing the request as single argument
-
- 'arg' is sometimes req, sometimes filter,
- sometimes connection
- """
- obj = module
- for obj_str in object_str.split('.'):
- parent = obj
- if silent and not hasattr(obj, obj_str):
- return None
-
- if obj == module and not hasattr(module, obj_str):
- if hasattr(module, '__file__'):
- s = "module '%s' contains no '%s'" % (module.__file__, obj_str)
- raise AttributeError, s
-
-
- obj = getattr(obj, obj_str)
- if hasattr(obj, 'im_self') and not (obj.im_self):
- instance = parent(arg)
- obj = getattr(instance, obj_str)
- continue
-
- return obj
-
-
- def build_cgi_env(req):
- '''
- Utility function that returns a dictionary of
- CGI environment variables as described in
- http://hoohoo.ncsa.uiuc.edu/cgi/env.html
- '''
- req.add_common_vars()
- env = req.subprocess_env.copy()
- if len(req.path_info) > 0:
- env['SCRIPT_NAME'] = req.uri[:-len(req.path_info)]
- else:
- env['SCRIPT_NAME'] = req.uri
- env['GATEWAY_INTERFACE'] = 'Python-CGI/1.1'
- if req.headers_in.has_key('authorization'):
- env['HTTP_AUTHORIZATION'] = req.headers_in['authorization']
-
- return env
-
-
- class NullIO:
- ''' Abstract IO
- '''
-
- def tell(self):
- return 0
-
-
- def read(self, n = -1):
- return ''
-
-
- def readline(self, length = None):
- return ''
-
-
- def readlines(self):
- return []
-
-
- def write(self, s):
- pass
-
-
- def writelines(self, list):
- self.write(''.join(list))
-
-
- def isatty(self):
- return 0
-
-
- def flush(self):
- pass
-
-
- def close(self):
- pass
-
-
- def seek(self, pos, mode = 0):
- pass
-
-
-
- class CGIStdin(NullIO):
-
- def __init__(self, req):
- self.pos = 0
- self.req = req
- self.BLOCK = 65536
- self.buf = ''
-
-
- def read(self, n = -1):
- if n == 0:
- return ''
-
- if n == -1:
- s = self.req.read(self.BLOCK)
- while s:
- self.buf = self.buf + s
- self.pos = self.pos + len(s)
- s = self.req.read(self.BLOCK)
- result = self.buf
- self.buf = ''
- return result
- elif self.buf:
- s = self.buf[:n]
- n = n - len(s)
- else:
- s = ''
- s = s + self.req.read(n)
- self.pos = self.pos + len(s)
- return s
-
-
- def readlines(self):
- s = (self.buf + self.read()).split('\n')
- return map((lambda s: s + '\n'), s)
-
-
- def readline(self, n = -1):
- if n == 0:
- return ''
-
- self.buf = self.buf + self.req.read(self.BLOCK)
- i = self.buf.find('\n')
- while i == -1:
- if n != -1 and len(self.buf) >= n:
- i = n - 1
- break
-
- x = len(self.buf)
- self.buf = self.buf + self.req.read(self.BLOCK)
- if len(self.buf) == x:
- i = x - 1
- break
-
- i = self.buf.find('\n', x)
- result = self.buf[:i + 1]
- self.buf = self.buf[i + 1:]
- self.pos = self.pos + len(result)
- return result
-
-
-
- class CGIStdout(NullIO):
- '''
- Class that allows writing to the socket directly for CGI.
- '''
-
- def __init__(self, req):
- self.pos = 0
- self.req = req
- self.headers_sent = 0
- self.headers = ''
-
-
- def write(self, s):
- if not s:
- return None
-
- if not (self.headers_sent):
- self.headers = self.headers + s
- headers_over = 0
- ss = self.headers.split('\r\n\r\n', 1)
- if len(ss) < 2:
- ss = self.headers.split('\n\n', 1)
- if len(ss) >= 2:
- headers_over = 1
-
- else:
- headers_over = 1
- if headers_over:
- ss[0] = ss[0].replace('\r\n', '\n')
- lines = ss[0].split('\n')
- for line in lines:
- (h, v) = line.split(':', 1)
- v = v.strip()
- if h.lower() == 'status':
- status = int(v.split()[0])
- self.req.status = status
- continue
- if h.lower() == 'content-type':
- self.req.content_type = v
- self.req.headers_out[h] = v
- continue
- self.req.headers_out.add(h, v)
-
- self.headers_sent = 1
- self.req.write(ss[1])
-
- else:
- self.req.write(str(s))
- self.pos = self.pos + len(s)
-
-
- def tell(self):
- return self.pos
-
-
-
- def setup_cgi(req):
- '''
- Replace sys.stdin and stdout with an objects that read/write to
- the socket, as well as substitute the os.environ.
- Returns (environ, stdin, stdout) which you must save and then use
- with restore_nocgi().
- '''
- save_env = os.environ.copy()
- si = sys.stdin
- so = sys.stdout
- os.environ.update(build_cgi_env(req))
- sys.stdout = CGIStdout(req)
- sys.stdin = CGIStdin(req)
- sys.argv = []
- return (save_env, si, so)
-
-
- def restore_nocgi(sav_env, si, so):
- ''' see setup_cgi() '''
- osenv = os.environ
- for k in osenv.keys():
- del osenv[k]
-
- for k in sav_env:
- osenv[k] = sav_env[k]
-
- sys.stdout = si
- sys.stdin = so
-
-
- def init():
- '''
- This function is called by the server at startup time
- '''
- return CallBack()
-
- make_table = _apache.table
- log_error = _apache.log_error
- table = _apache.table
- config_tree = _apache.config_tree
- server_root = _apache.server_root
- mpm_query = _apache.mpm_query
- HTTP_CONTINUE = 100
- HTTP_SWITCHING_PROTOCOLS = 101
- HTTP_PROCESSING = 102
- HTTP_OK = 200
- HTTP_CREATED = 201
- HTTP_ACCEPTED = 202
- HTTP_NON_AUTHORITATIVE = 203
- HTTP_NO_CONTENT = 204
- HTTP_RESET_CONTENT = 205
- HTTP_PARTIAL_CONTENT = 206
- HTTP_MULTI_STATUS = 207
- HTTP_MULTIPLE_CHOICES = 300
- HTTP_MOVED_PERMANENTLY = 301
- HTTP_MOVED_TEMPORARILY = 302
- HTTP_SEE_OTHER = 303
- HTTP_NOT_MODIFIED = 304
- HTTP_USE_PROXY = 305
- HTTP_TEMPORARY_REDIRECT = 307
- HTTP_BAD_REQUEST = 400
- HTTP_UNAUTHORIZED = 401
- HTTP_PAYMENT_REQUIRED = 402
- HTTP_FORBIDDEN = 403
- HTTP_NOT_FOUND = 404
- HTTP_METHOD_NOT_ALLOWED = 405
- HTTP_NOT_ACCEPTABLE = 406
- HTTP_PROXY_AUTHENTICATION_REQUIRED = 407
- HTTP_REQUEST_TIME_OUT = 408
- HTTP_CONFLICT = 409
- HTTP_GONE = 410
- HTTP_LENGTH_REQUIRED = 411
- HTTP_PRECONDITION_FAILED = 412
- HTTP_REQUEST_ENTITY_TOO_LARGE = 413
- HTTP_REQUEST_URI_TOO_LARGE = 414
- HTTP_UNSUPPORTED_MEDIA_TYPE = 415
- HTTP_RANGE_NOT_SATISFIABLE = 416
- HTTP_EXPECTATION_FAILED = 417
- HTTP_UNPROCESSABLE_ENTITY = 422
- HTTP_LOCKED = 423
- HTTP_FAILED_DEPENDENCY = 424
- HTTP_INTERNAL_SERVER_ERROR = 500
- HTTP_NOT_IMPLEMENTED = 501
- HTTP_BAD_GATEWAY = 502
- HTTP_SERVICE_UNAVAILABLE = 503
- HTTP_GATEWAY_TIME_OUT = 504
- HTTP_VERSION_NOT_SUPPORTED = 505
- HTTP_VARIANT_ALSO_VARIES = 506
- HTTP_INSUFFICIENT_STORAGE = 507
- HTTP_NOT_EXTENDED = 510
-
- try:
- import syslog
- APLOG_EMERG = syslog.LOG_EMERG
- APLOG_ALERT = syslog.LOG_ALERT
- APLOG_CRIT = syslog.LOG_CRIT
- APLOG_ERR = syslog.LOG_ERR
- APLOG_WARNING = syslog.LOG_WARNING
- APLOG_NOTICE = syslog.LOG_NOTICE
- APLOG_INFO = syslog.LOG_INFO
- APLOG_DEBUG = syslog.LOG_DEBUG
- except ImportError:
- APLOG_EMERG = 0
- APLOG_ALERT = 1
- APLOG_CRIT = 2
- APLOG_ERR = 3
- APLOG_WARNING = 4
- APLOG_NOTICE = 5
- APLOG_INFO = 6
- APLOG_DEBUG = 7
-
- APLOG_NOERRNO = 8
- OK = REQ_PROCEED = 0
- DONE = -2
- DECLINED = REQ_NOACTION = -1
- REMOTE_HOST = 0
- REMOTE_NAME = 1
- REMOTE_NOLOOKUP = 2
- REMOTE_DOUBLE_REV = 3
- REQ_ABORTED = HTTP_INTERNAL_SERVER_ERROR
- REQ_EXIT = 'REQ_EXIT'
- SERVER_RETURN = _apache.SERVER_RETURN
- PROG_TRACEBACK = 'PROG_TRACEBACK'
- FINFO_MODE = 0
- FINFO_INO = 1
- FINFO_DEV = 2
- FINFO_NLINK = 3
- FINFO_UID = 4
- FINFO_GID = 5
- FINFO_SIZE = 6
- FINFO_ATIME = 7
- FINFO_MTIME = 8
- FINFO_CTIME = 9
- FINFO_FNAME = 10
- FINFO_NAME = 11
- URI_SCHEME = 0
- URI_HOSTINFO = 1
- URI_USER = 2
- URI_PASSWORD = 3
- URI_HOSTNAME = 4
- URI_PORT = 5
- URI_PATH = 6
- URI_QUERY = 7
- URI_FRAGMENT = 8
- PROXYREQ_NONE = 0
- PROXYREQ_PROXY = 1
- PROXYREQ_REVERSE = 2
- M_GET = 0
- M_PUT = 1
- M_POST = 2
- M_DELETE = 3
- M_CONNECT = 4
- M_OPTIONS = 5
- M_TRACE = 6
- M_PATCH = 7
- M_PROPFIND = 8
- M_PROPPATCH = 9
- M_MKCOL = 10
- M_COPY = 11
- M_MOVE = 12
- M_LOCK = 13
- M_UNLOCK = 14
- M_VERSION_CONTROL = 15
- M_CHECKOUT = 16
- M_UNCHECKOUT = 17
- M_CHECKIN = 18
- M_UPDATE = 19
- M_LABEL = 20
- M_REPORT = 21
- M_MKWORKSPACE = 22
- M_MKACTIVITY = 23
- M_BASELINE_CONTROL = 24
- M_MERGE = 25
- M_INVALID = 26
- AP_REQ_ACCEPT_PATH_INFO = 0
- AP_REQ_REJECT_PATH_INFO = 1
- AP_REQ_DEFAULT_PATH_INFO = 2
- AP_MPMQ_NOT_SUPPORTED = 0
- AP_MPMQ_STATIC = 1
- AP_MPMQ_DYNAMIC = 2
- AP_MPMQ_MAX_DAEMON_USED = 1
- AP_MPMQ_IS_THREADED = 2
- AP_MPMQ_IS_FORKED = 3
- AP_MPMQ_HARD_LIMIT_DAEMONS = 4
- AP_MPMQ_HARD_LIMIT_THREADS = 5
- AP_MPMQ_MAX_THREADS = 6
- AP_MPMQ_MIN_SPARE_DAEMONS = 7
- AP_MPMQ_MIN_SPARE_THREADS = 8
- AP_MPMQ_MAX_SPARE_DAEMONS = 9
- AP_MPMQ_MAX_SPARE_THREADS = 10
- AP_MPMQ_MAX_REQUESTS_DAEMON = 11
- AP_MPMQ_MAX_DAEMONS = 12
-