<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:ts=4:sw=4:noexpandtab
"""
pmxbotweb.py
"""

import sys
import os
import yaml
import cherrypy
from viewer import PmxbotPages

def run(configFile=None, configDict=None, start=True):
	global config
	class O(object): 
		def __init__(self, d):
			for k, v in d.iteritems():
				setattr(self, k, v)

	if configDict:
		config = O(configDict)
	else:
		if configFile:
			config_file = configFile
		else:
			if len(sys.argv) < 2:
				sys.stderr.write("error: need config file as first argument")
				raise SystemExit(1)
			config_file = sys.argv[1]
		config = O(yaml.load(open(config_file)))
	try:
		if config.web_base and config.web_base[0] != '/':
			config.web_base = '/%s' % config.web_base
	except AttributeError:
		config.web_base = '/'
	if config.web_base[-1] == '/':
		config.web_base = config.web_base[:-1]
	try:
		config.web_host
	except AttributeError:
		config.web_host = '0.0.0.0'
	try:
		config.web_port
	except AttributeError:
		config.web_port = 8080
	try:
		config.logo
	except AttributeError:
		config.logo = '%s/pmxbot.png' % config.web_base

	# Cherrypy configuration here
	app_conf = {
		'global': {
			'server.socket_port': config.web_port,
			'server.socket_host': config.web_host,
		},
		'/pmxbot.png' : {
			'tools.staticfile.on' : True,
			'tools.staticfile.filename' : os.path.join(os.path.dirname(__file__), 'templates/pmxbot.png'),
		},
		'botconf' : {'config' : config},
	}

	cherrypy.quickstart(PmxbotPages(), config.web_base, config=app_conf)
<commit_msg>Set default encoding to UTF-8; doing so seems to force the client to encode the query strings as utf-8, fixing issues with performing searches with international characters.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:ts=4:sw=4:noexpandtab
"""
pmxbotweb.py
"""

import sys
import os
import yaml
import cherrypy
from viewer import PmxbotPages

def run(configFile=None, configDict=None, start=True):
	global config
	class O(object): 
		def __init__(self, d):
			for k, v in d.iteritems():
				setattr(self, k, v)

	if configDict:
		config = O(configDict)
	else:
		if configFile:
			config_file = configFile
		else:
			if len(sys.argv) < 2:
				sys.stderr.write("error: need config file as first argument")
				raise SystemExit(1)
			config_file = sys.argv[1]
		config = O(yaml.load(open(config_file)))
	try:
		if config.web_base and config.web_base[0] != '/':
			config.web_base = '/%s' % config.web_base
	except AttributeError:
		config.web_base = '/'
	if config.web_base[-1] == '/':
		config.web_base = config.web_base[:-1]
	try:
		config.web_host
	except AttributeError:
		config.web_host = '0.0.0.0'
	try:
		config.web_port
	except AttributeError:
		config.web_port = 8080
	try:
		config.logo
	except AttributeError:
		config.logo = '%s/pmxbot.png' % config.web_base

	# Cherrypy configuration here
	app_conf = {
		'global': {
			'server.socket_port': config.web_port,
			'server.socket_host': config.web_host,
			#'tools.encode.on': True,
			'tools.encode.encoding': 'utf-8',
		},
		'/pmxbot.png' : {
			'tools.staticfile.on' : True,
			'tools.staticfile.filename' : os.path.join(os.path.dirname(__file__), 'templates/pmxbot.png'),
		},
		'botconf' : {'config' : config},
	}

	cherrypy.quickstart(PmxbotPages(), config.web_base, config=app_conf)

{'fraction_non_alphanumeric': 0.1451418225709113, 'fraction_numerical': 0.011164755582377792, 'mean_word_length': 3.925705794947994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '476688', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1223, 'n_words': 266}