<commit_before># -*- coding: utf-8 -*-
import webapp2
import os
import jinja2
import hashlib, uuid

def joinfunc(array, wrapper):
	wrap_array = [wrapper % x for x in array]
	a = []
	if ', '.join(wrap_array[0:-1]):
		a.append(', '.join(wrap_array[0:-1]))
	if wrap_array[-1]:
		a.append(wrap_array[-1])
	return ' and '.join(a)

class Handler(webapp2.RequestHandler):
	template_dir = os.path.join(os.path.dirname(__file__), 'templates')
	
	jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), 
	autoescape = True)
	jinja_env.filters['joinfunc'] = joinfunc
	
	SECRET = "The AskNow secret"
	
	def urlencode(self, params): ## FIXME: This is FUUUUUCKIN' UGLY!
		paramlist = []
		for k, v in params.items():
			if type(v) == str:
				val = v.encode('utf-8')
			else:
				val = str(v)
			paramlist.append(k + '=' + val)
		return '&'.join(paramlist)
	
	def write(self, *a, **kw):
		self.response.out.write(*a, **kw)
		
	def render_str(self, template, **params):
		t = self.jinja_env.get_template(template)
		return t.render(params)
		
	def render(self, template, **kw):
		self.write(self.render_str(template, **kw))
		
	def hash_str(self, s):
		return hashlib.sha256(self.SECRET + str(s)).hexdigest()
		
	def reset_cookie(self, cookie):
		self.response.headers.add_header('Set-Cookie', '%s=; Path=/' % cookie)
		
	def generate_salt(self):
		return uuid.uuid4().hex
		
	def generate_pwhash(self, password, salt):
		return hashlib.sha512(password + salt).hexdigest()<commit_msg>Remove ugly hack that is supported by Python's native library urllib<commit_after># -*- coding: utf-8 -*-
import webapp2
import os
import jinja2
import hashlib, uuid

def joinfunc(array, wrapper):
	wrap_array = [wrapper % x for x in array]
	a = []
	if ', '.join(wrap_array[0:-1]):
		a.append(', '.join(wrap_array[0:-1]))
	if wrap_array[-1]:
		a.append(wrap_array[-1])
	return ' and '.join(a)

class Handler(webapp2.RequestHandler):
	template_dir = os.path.join(os.path.dirname(__file__), 'templates')
	
	jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), 
	autoescape = True)
	jinja_env.filters['joinfunc'] = joinfunc
	
	SECRET = "The AskNow secret"
	
	def write(self, *a, **kw):
		self.response.out.write(*a, **kw)
		
	def render_str(self, template, **params):
		t = self.jinja_env.get_template(template)
		return t.render(params)
		
	def render(self, template, **kw):
		self.write(self.render_str(template, **kw))
		
	def hash_str(self, s):
		return hashlib.sha256(self.SECRET + str(s)).hexdigest()
		
	def reset_cookie(self, cookie):
		self.response.headers.add_header('Set-Cookie', '%s=; Path=/' % cookie)
		
	def generate_salt(self):
		return uuid.uuid4().hex
		
	def generate_pwhash(self, password, salt):
		return hashlib.sha512(password + salt).hexdigest()
{'fraction_non_alphanumeric': 0.16091954022988506, 'fraction_numerical': 0.014008620689655173, 'mean_word_length': 4.471512770137524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7355228', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1025, 'n_words': 221}