Exemple #1
0
  def __importPlugin(self,file):

    target = self.__searchPlugin(file)

    if target:
      directory = os.path.dirname(target)
      name = os.path.splitext(os.path.basename(target))[0]
      return vampire.importModule(name,directory,self.req)
def handler_html(req):

    directory, name = os.path.split(os.path.splitext(req.filename)[0])

    module = vampire.importModule(name, directory)

    if not hasattr(module, "Servlet"):
        return apache.HTTP_NOT_FOUND

    _servlet = module.Servlet()

    _servlet.req = req

    try:
        _servlet.auth()
        _servlet.prep()
        if not _servlet.respond():
            return apache.HTTP_NO_CONTENT
        _servlet.wrapup()

    finally:
        _servlet._finally()

    return apache.OK
Exemple #3
0
import vampire
import sys

config = vampire.loadConfig(__req__, ".vampire")
layouts = config.get("Handlers", "layouts_root")
layout = vampire.importModule("basic", layouts, __req__)


class Template(layout.Template):

    no_cache = True

    def renderTemplate(self):
        def renderModule(node, label):
            node.label.content = label
            if hasattr(sys.modules[label], "__file__"):
                node.path.content = sys.modules[label].__file__

        keys = sys.modules.keys()
        keys.sort()

        self.template.module.repeat(renderModule, keys)


handler_html = vampire.Instance(Template)
Exemple #4
0
import netsvc
import netsvc.client
import vampire
import os

# Import startup code for dispatcher to ensure it is
# initialised and connection to exchange is created.

_gateway = vampire.importModule("_gateway", None, __req__)

# Handler which will attempt to log all requests with
# the remote request database service.


def loghandler(req):

    # Lookup the request logging service. Abort the
    # search immediately if the service isn't already
    # registered by specifying a zero length timeout.

    registry = netsvc.client.Registry(timeout=0)
    bindings = registry.locateService("apache-logger")

    # Because we are logging requests, not serious that
    # service couldn't be found. Just means details about
    # requests for period service is not available will
    # be lost.

    if bindings != []:

        # We don't want to hang around for the response
Exemple #5
0
import vampire
import os

# Following determines if this is being run within the
# context of the parent web site, and if it is use the
# links from the parent web site as well as any which
# have been added here.

current = os.path.dirname(__file__)
parent = os.path.join(current, "../..")

_links = []

try:
    module = vampire.importModule("_links", parent)
except OSError:
    pass
else:
    _links = list(module._links)

_package = []

if _links == []:
    _package.append(("Home", "%(ose_home)s/index.html"))

#_package.append(("Articles","%(ose_home)s/articles.html"))
_package.append(("License", "%(ose_home)s/license.html"))
#_package.append(("Examples","%(ose_home)s/examples/index.html"))
_package.append(("Installation", "%(ose_home)s/install.html"))
#_package.append(("Changes","%(ose_home)s/changes.html"))
#_package.append(("TODO","%(ose_home)s/todo.html"))
Exemple #6
0
def handler(req, **fields):

    # We only want to treat request as being a possible
    # request for a Cheetah generated template file if
    # there exists both a ".tmpl" and ".py" file.

    target = os.path.splitext(req.filename)[0]

    target_tmpl = target + ".tmpl"
    target_py = target + ".py"

    if not os.path.exists(target_tmpl) and not os.path.exists(target_py):
        return apache.DECLINED

    # Grab the module name to look for from the last part
    # of the path. This means that pages can be spread
    # across subdirectories as well.

    directory, module_name = os.path.split(target)

    # Import the module. Any coding error in the module
    # being imported is thrown back to the user. Error
    # also results if by chance the target just vanished.

    module = vampire.importModule(module_name, directory, req)

    # Ensure that there is a class defined in the module
    # of the appropriate name.

    if not hasattr(module, module_name):
        return apache.DECLINED

    # Create instance of the class.

    tmpl = getattr(module, module_name)()

    # Cache any decoded form parameters in an obvious
    # place so they are available. Note that the actual
    # mod_python form object is also cached as "req.form"
    # but the decoded form parameters would preferably be
    # used. By default decoded form parameters follow
    # structured naming convention supported by Vampire.
    # If this naming convention isn't wanted, it would
    # need to be disabled in the Apache configuration.

    req.fields = fields

    # Cache the Vampire configuration object in an obvious
    # place as well. Use the same one as defined the
    # default handlers which would have triggered use of
    # this handler in the first place.

    options = req.get_options()

    file = ".vampire"
    if options.has_key("VampireHandlersConfig"):
        file = options["VampireHandlersConfig"]
    config = vampire.loadConfig(req, file)

    req.config = config

    # Make request object available within the template.

    tmpl.req = req

    # Set type of content being returned if not set.

    if not req._content_type_set:
        req.content_type = "text/html"

    # Now generate the actual content and return it.

    req.send_http_header()

    req.write(tmpl.respond())

    return apache.OK
Exemple #7
0
def browse(req, name="", object="", **kw):

    if req.vampire["handler"] != "vampire::publisher":
        return apache.HTTP_NOT_IMPLEMENTED

    directory = '/'.join((len(req.path_info.split('/')) - 1) * [".."])
    module = os.path.splitext(os.path.split(req.filename)[1])[0]

    if not directory:
        directory = '.'

    action = "%s/%s/browse" % (directory, module)

    rules = _publisher_rules

    directory = os.path.dirname(req.filename)

    try:
        target = vampire.importModule(os.path.split(name)[1], directory)
    except OSError:
        value = os.path.split(req.uri)[0]
        req.headers_out["location"] = "%s" % value
        req.status = apache.HTTP_MOVED_TEMPORARILY
        return apache.HTTP_NOT_FOUND

    root = target

    req.content_type = "text/html"
    req.send_http_header()
    req.write("<html><body>\n")

    if object != "":
        for element in object.split('/'):
            target = getattr(target, element)

    subobjects = dir(target)
    subobjects.sort()

    req.write("<table>\n")

    for key in subobjects:
        if object != "":
            subobject = object + "/" + key
        else:
            subobject = key

        req.write("<tr>\n")

        req.write("<td>\n")
        req.write("<p>\n")
        req.write(cgi.escape(subobject))
        req.write("</p>\n")
        req.write("</td>\n")

        subinstance = None
        typestring = ""
        if hasattr(target, key):
            subinstance = getattr(target, key)
            typestring = cgi.escape(str(type(subinstance)))

        req.write("<td>\n")
        req.write("<p>%s</p>\n" % typestring)
        req.write("</td>\n")

        parts = subobject.split('/')
        status, traverse, execute, access, subinstance = _resolve(
            req, root, parts, rules)

        if not traverse and not execute and not access:
            req.write("<td>\n")
            req.write("DENY")
            req.write("</td>\n")

            req.write("<td>\n")
            req.write("</td>\n")

        else:
            req.write("<td>\n")
            if execute:
                req.write("CALL")
            else:
                req.write("TYPE")
            req.write("</td>\n")

            req.write("<td>\n")

            if traverse:
                req.write("&nbsp;")
                req.write("<a href='%s" % action)
                req.write("?name=%s&object=%s'>" % (name, subobject))
                req.write("BROWSE")
                req.write("</a>")

            if execute:
                req.write("&nbsp;")
                url = action + '/../' + subobject
                req.write("<a href='%s'>" % url)
                req.write("EXEC")
                req.write("</a>")

            if access:
                req.write("&nbsp;")
                url = action + '/../' + subobject
                req.write("<a href='%s'>" % url)
                req.write("VIEW")
                req.write("</a>")

            req.write("</td>\n")

            req.write("</tr>\n")

    req.write("</table>\n")
    req.write("</body></html>\n")
Exemple #8
0
from mod_python import apache

import vampire
import cgi
import os

basic = vampire.importModule("basic",None,__req__)

PREFIX = """
<div id="pageWrapper">
<div id="masthead" class="inside">
<!-- masthead content begin -->
<h1>%(masthead)s</h1>
<!-- masthead content end -->
</div>
<!-- horizontal nav begin -->
<div class="hnav">%(navbar)s</div>
<!-- horizontal nav end -->
<div id="outerColumnContainer">
<div id="innerColumnContainer">
<div id="SOWrap">
<div id="middleColumn">
<div class="inside">
"""

SUFFIX = """
</div>
</div>
<div id="leftColumn">
<div class="inside">
<!--- left column begin -->
import vampire
import os

# Following determines if this is being run within the
# context of the parent web site, and if it is use the
# navigation bar from the parent web site.

current = os.path.dirname(__file__)
parent = os.path.join(current, "../..")

_links = []

try:
    module = vampire.importModule("_navbar", parent)
except OSError:
    pass
else:
    _links = list(module._links)


def navbar(req):
    return _links
Exemple #10
0
from mod_python import apache

import os
import vampire

__psp_root__ = os.path.join(os.path.dirname(__file__), "..", "psp")
psp = vampire.importModule("_handler", __psp_root__, __req__)


class Handler(psp.Servlet):
    def __call__(self, message=""):
        if not message:
            message = "Give Blood!"

        self.vars["message"] = message

        self.render()


handler_html = vampire.Instance(Handler)
from mod_python import apache

import vampire
import os

config = vampire.loadConfig(__req__, ".vampire")

cheetah = vampire.importModule("_handler",
                               config.get("DEFAULT", "__cheetah_root__"),
                               __req__)

psp = vampire.importModule("_handler", config.get("DEFAULT", "__psp_root__"),
                           __req__)


def handler_html(req):

    # This default handler for ".html" requests provides
    # support for both Cheetah templates and PSP.

    target = os.path.splitext(req.filename)[0]

    # First look to see if request can be handle by a
    # Cheetah template. Note that the ".tmpl" file must
    # have been compiled into an appropriate ".py" file.

    if os.path.exists(target + ".tmpl"):
        return cheetah.handler_html(req)

    # Now look to see if it could instead be handled as
    # PSP request.