<commit_before># dathomir
# Copyright (C) 2007 <NAME>
#
# $Id$
#
# See LICENSE for details

import MySQLdb
from dathomir.util import url
from dathomir.web import session, wsgi
from dathomir import persist

base_url = '/'
db_url = 'mysql://dathomir:dathomir@localhost/dathomir'
session_class = session.UserSession
debug_session = False
initialize_store = True
webroot = 'webroot'

_site_tree = url.URLNode()
_db = None
_response_headers = []

def activate(rsrc):
	"""
	Add a resource to this site's URLNode tree
	"""
	global _site_tree
	for path in rsrc.get_paths():
		_site_tree.register(path, rsrc)

def get_tree():
	"""
	Return this site's URLNode tree
	"""
	global _site_tree
	return _site_tree

def add_header(header, data):
	"""
	Store headers for later retrieval.
	"""
	global _response_headers
	_response_headers.append((header, data))

def has_header(header):
	"""
	Check if a header has ever been set.
	"""
	global _response_headers
	for h, d in _response_headers:
		if(h == header):
			return True
	return False

def get_headers():
	"""
	Get accumulated headers
	"""
	global _response_headers
	return _response_headers

def load_config(req):
	"""
	Load this app's configuration variables into the
	provided request object.
	"""
	global db_url, session_class, initialize_store
	global base_url, webroot
	
	req['dathomir.config.db_url'] = db_url
	req['dathomir.config.session_class'] = session_class
	req['dathomir.config.debug_session'] = debug_session
	req['dathomir.config.initialize_store'] = initialize_store
	req['dathomir.config.base_url'] = base_url
	req['dathomir.config.webroot'] = webroot

def bootstrap(req):
	"""
	Initialize the common services, store them in the
	provided request variable.
	"""
	# Databases are a slightly special case. Since we want to re-use
	# db connections as much as possible, we keep the current connection
	# as a global variable. Ordinarily this is a naughty-no-no in mod_python,
	# but we're going to be very very careful.
	global _db
	db_url = req['dathomir.config.db_url']
	if(not _db and db_url):
		dsn = url.urlparse(req['dathomir.config.db_url'])
		if(dsn['scheme'] == 'mysql'):
			_db = MySQLdb.connect(dsn['host'], dsn['user'], dsn['password'], dsn['path'][1:])
		else:
			raise NotImplementedError("Unsupported database driver: '%s'" % dsn['scheme'])
	req['dathomir.db'] = _db
	
	# FIXME: We assume that any session class requires database access, and pass
	# the db connection as the second paramter to the session class constructor
	session_class = req['dathomir.config.session_class']
	if(db_url and session_class):
		req['dathomir.session'] = session_class(req, req['dathomir.db'])
		if(req['dathomir.config.debug_session']):
			req.log_error('session contains: ' + str(req['dathomir.session']))
	
	initialize_store = req['dathomir.config.initialize_store']
	if(_db):
		# FIXME: I really can't think of any scenario where a store will
		# already be initialized, but we'll check anyway, for now
		store = persist.get_store()
		if not(store):
			store = persist.Store(_db)
		req['dathomir.store'] = store
<commit_msg>added debug_store configuration option<commit_after># dathomir
# Copyright (C) 2007 <NAME>
#
# $Id$
#
# See LICENSE for details

import MySQLdb
from dathomir.util import url
from dathomir.web import session, wsgi
from dathomir import persist

base_url = '/'
db_url = 'mysql://dathomir:dathomir@localhost/dathomir'
session_class = session.UserSession
initialize_store = True
webroot = 'webroot'
debug_session = False
debug_store = False

_site_tree = url.URLNode()
_db = None
_response_headers = []

def activate(rsrc):
	"""
	Add a resource to this site's URLNode tree
	"""
	global _site_tree
	for path in rsrc.get_paths():
		_site_tree.register(path, rsrc)

def get_tree():
	"""
	Return this site's URLNode tree
	"""
	global _site_tree
	return _site_tree

def add_header(header, data):
	"""
	Store headers for later retrieval.
	"""
	global _response_headers
	_response_headers.append((header, data))

def has_header(header):
	"""
	Check if a header has ever been set.
	"""
	global _response_headers
	for h, d in _response_headers:
		if(h == header):
			return True
	return False

def get_headers():
	"""
	Get accumulated headers
	"""
	global _response_headers
	return _response_headers

def load_config(req):
	"""
	Load this app's configuration variables into the
	provided request object.
	"""
	global db_url, session_class, initialize_store
	global base_url, webroot, debug_store, debug_session
	
	req['dathomir.config.db_url'] = db_url
	req['dathomir.config.session_class'] = session_class
	req['dathomir.config.initialize_store'] = initialize_store
	req['dathomir.config.base_url'] = base_url
	req['dathomir.config.webroot'] = webroot
	
	req['dathomir.config.debug_session'] = debug_session
	req['dathomir.config.debug_store'] = debug_store

def bootstrap(req):
	"""
	Initialize the common services, store them in the
	provided request variable.
	"""
	# Databases are a slightly special case. Since we want to re-use
	# db connections as much as possible, we keep the current connection
	# as a global variable. Ordinarily this is a naughty-no-no in mod_python,
	# but we're going to be very very careful.
	global _db
	db_url = req['dathomir.config.db_url']
	if(not _db and db_url):
		dsn = url.urlparse(req['dathomir.config.db_url'])
		if(dsn['scheme'] == 'mysql'):
			_db = MySQLdb.connect(dsn['host'], dsn['user'], dsn['password'], dsn['path'][1:])
		else:
			raise NotImplementedError("Unsupported database driver: '%s'" % dsn['scheme'])
	req['dathomir.db'] = _db
	
	# FIXME: We assume that any session class requires database access, and pass
	# the db connection as the second paramter to the session class constructor
	session_class = req['dathomir.config.session_class']
	if(db_url and session_class):
		req['dathomir.session'] = session_class(req, req['dathomir.db'])
		if(req['dathomir.config.debug_session']):
			req.log_error('session contains: ' + str(req['dathomir.session']))
	
	initialize_store = req['dathomir.config.initialize_store']
	if(_db):
		# FIXME: I really can't think of any scenario where a store will
		# already be initialized, but we'll check anyway, for now
		store = persist.get_store()
		if not(store):
			if(req['dathomir.config.debug_store']):
				debug_file = req['wsgi.errors']
			else:
				debug_file = None
			store = persist.Store(_db, debug_file=debug_file)
		req['dathomir.store'] = store

{'fraction_non_alphanumeric': 0.11646398503274089, 'fraction_numerical': 0.0015590894917368258, 'mean_word_length': 4.95636025998143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6771647', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2120, 'n_words': 604}