Example #1
0
def configure(app_module="app", config_module="config"):
    global config

    if not config:
        config = tools.module(config_module)
        config.app_module = app_module
        config.app_path = os.path.realpath(app_module)
        config.errors_dir = config.app_path + '/errors/'
        config.env = Environment(loader=PackageLoader(config.app_module, '.'))
        config.allowed_referer = re.compile(config.allowed_referer)
        config.static_dir = os.path.realpath(config.app_path +
                                           (config.static_dir or '/static/'))
Example #2
0
 def __init__(self, app, default_mtype=None, static_dir=None,
              allowed_referer="*"):
     self.app_path = os.path.realpath(app)
     self.app = app
     self.static_dir = os.path.realpath(self.app_path +
                                        (static_dir or '/static/'))
     self.errors_dir = self.app_path + '/errors/'
     self.default_mtype = default_mtype or 'text/html'
     self.env = Environment(loader=PackageLoader(self.app, '.'))
     self.allowed_referer = re.compile(allowed_referer)
     self.config = tools.module('config')
     self.db = self.config.db
Example #3
0
    def find_longest_module(self, name, variables):
        base = name[1:]

        # need to limit the max we'll try to 20 for safety
        for i in xrange(0, 20):
            # go until we hit the /
            if base == '/': return None

            modname = base.replace('/', '.')

            try:
                return base, tools.module(modname, self.app)
            except ImportError:
                # split off the next chunk to try to load
                base, tail = os.path.split(base)

        # exhausted the path limit
        return None
Example #4
0
    def render_module(self, name, variables):
        base, ext = os.path.splitext(name[1:])
        context = RequestDict(variables['web'])
        base = base.replace('/', '.')
        try:
            target = tools.module(base)
        except ImportError:
            return self.render_error(404, "Not Found", variables=variables)

        try:
            actions = target.__dict__
            func = actions.get(context.method, None) or actions['run']
        except KeyError:
            return self.render_error(500, 'No run method or %s method.' %
                                     context.method)
        result = func(context)

        if isinstance(result, tuple):
            return result
        else:
            return result, 200, {'Content-Type': self.default_mtype}