<commit_before># Built in library imports
import mimetypes
import re
import os
import sys
# Server imports
import urlparse
import cgi

class Juno(object):
    def __init__(self, configuration=None):
        """Takes an optional configuration dictionary. """
        global _hub
        if _hub is not None:
            print >>sys.stderr, 'Warning: there is already a Juno object created;'
            print >>sys.stderr, '         you might get some weird behavior.'
        else: _hub = self
        self.routes = []
        # Join the path to the app's current location
        # In progress
        def join_app_path(path):
            #return os.path.join(os.path.abspath(sys.path[0]), path)
            return './' + path
        # Set options and merge in user-set options
        self.config = {
                # General settings
                'log':    True,
                'routes': self.routes,
                # Types and encodings
                'charset':      'utf-8',
                'content_type': 'text/html',
                # Server options
                'mode':     'dev',
                'scgi_port': 8000,
                'fcgi_port': 8000,
                'dev_port':  8000,
                # Static file handling
                'use_static':     True,
                'static_url':     '/static/*:file/',
                'static_root':    join_app_path('static/'),
                'static_handler': static_serve,
                # Template options
                'use_templates':           True,
                'template_lib':            'jinja2',
                'get_template_handler':    _get_template_handler,
                'render_template_handler': _render_template_handler,
                'auto_reload_templates':   True,
                'translations':            [], 
                'template_kwargs':         {},
                'template_root':           join_app_path('templates/'),
                '404_template':            '404.html',
                '500_template':            '500.html',
                # Database options
                'use_db':      True,
                'db_type':     'sqlite',
                'db_location': ':memory:',
                'db_models':   {},
                # Session options
                'use_sessions': False,
                'session_lib':  'beaker',
                # Debugger
                'use_debugger': False,
                'raise_view_exceptions': False,
                # Custom middleware
                'middleware': []
        }
        if configuration is not None: self.config.update(configuration)
        # Set up the static file handler
        if self.config['use_static']: 
            self.setup_static()
        # Set up templating
        if self.config['use_templates']: 
            self.setup_templates()
        # Set up the database 
        if self.config['use_db']:
            self.setup_database()

    def setup_static(self):
        self.route(self.config['static_url'], self.config['static_handler'], '*')
<commit_msg>* static/template_root no longer need full paths under mod_wsgi. * Default relative paths are as noted in docs.<commit_after># Built in library imports
import mimetypes
import re
import os
import sys
# Server imports
import urlparse
import cgi

class Juno(object):
    def __init__(self, configuration=None):
        """Takes an optional configuration dictionary. """
        global _hub
        if _hub is not None:
            print >>sys.stderr, 'Warning: there is already a Juno object created;'
            print >>sys.stderr, '         you might get some weird behavior.'
        else: _hub = self
        self.routes = []
        # Find the directory of the user's app, so we can setup static/template_roots
        self.find_user_path()
        # Set options and merge in user-set options
        self.config = {
                # General settings / meta information
                'log':    True,
                'routes': self.routes,
                'self':   self,
                # Types and encodings
                'charset':      'utf-8',
                'content_type': 'text/html',
                # Server options
                'mode':     'dev',
                'scgi_port': 8000,
                'fcgi_port': 8000,
                'dev_port':  8000,
                # Static file handling
                'use_static':     True,
                'static_url':     '/static/*:file/',
                'static_root':    os.path.join(self.app_path, 'static/'),
                'static_handler': static_serve,
                # Template options
                'use_templates':           True,
                'template_lib':            'jinja2',
                'get_template_handler':    _get_template_handler,
                'render_template_handler': _render_template_handler,
                'auto_reload_templates':   True,
                'translations':            [], 
                'template_kwargs':         {},
                'template_root':           os.path.join(self.app_path, 'templates/'),
                '404_template':            '404.html',
                '500_template':            '500.html',
                # Database options
                'use_db':      True,
                'db_type':     'sqlite',
                'db_location': ':memory:',
                'db_models':   {},
                # Session options
                'use_sessions': False,
                'session_lib':  'beaker',
                # Debugger
                'use_debugger': False,
                'raise_view_exceptions': False,
                # Custom middleware
                'middleware': []
        }
        if configuration is not None: self.config.update(configuration)
        # Set up the static file handler
        if self.config['use_static']: 
            self.setup_static()
        # Set up templating
        if self.config['use_templates']: 
            self.setup_templates()
        # Set up the database 
        if self.config['use_db']:
            self.setup_database()

    def find_user_path(self):
        # This section may look strange, but it seems like the only solution.
        # Basically, we need the directory of the user's app in order to setup
        # the static/template_roots.  When we run under mod_wsgi, we can't use
        # either os.getcwd() or sys.path[0].  This code generates an exception,
        # then goes up to the top stack frame (the user's code), and finds
        # the location of that.
        try:
            raise NameError
        except:
            traceback = sys.exc_info()[2]
            if traceback is None:
                print >>sys.stderr, 'Warning: Failed to find current working directory.'
                print >>sys.stderr, '         Default static_root and template_root'
                print >>sys.stderr, '         values may not work correctly.'
                filename = './'
            else:
                frame = traceback.tb_frame
                while traceback is not None:
                    if frame.f_back is None:
                        break
                    frame = frame.f_back
                filename = frame.f_code.co_filename
        self.app_path = os.path.abspath(os.path.dirname(filename))

    def setup_static(self):
        self.route(self.config['static_url'], self.config['static_handler'], '*')

{'fraction_non_alphanumeric': 0.09546313799621928, 'fraction_numerical': 0.007426411018093438, 'mean_word_length': 1.451837140019861, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '384296', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1853, 'n_words': 517}