<commit_before>#!/usr/bin/python3.4
from flask import Flask, render_template, url_for, Markup, abort
from flask.ext.libsass import *
import pkg_resources, socket

import markdown
from markdown.extensions.headerid import HeaderIdExtension

from slimit import minify

from PIL import Image

app=Flask(__name__)

Sass(
	{'app': 'scss/app.scss'},
	app,
	url_path='/static/css',
	include_paths=[pkg_resources.resource_filename('views', 'scss')],
	output_style='compressed'
)

@app.route('/static/js/<js>')
def render_js(js):
	try:
		fd=open(pkg_resources.resource_filename('views', 'js/' + js), encoding='UTF-8')
		out=minify(fd.read(), mangle=True, mangle_toplevel=True)
		fd.close()
		return out
	except OSError:
		abort(404)

@app.route('/static/img/<width>px-<imgfile>')
def render_thumb(width, imgfile):
	try:
		img=Image.open(pkg_resources.resource_filename('views', 'img/', imgfile))
		img.thumbnail((width, width/(img.size[0]/img.size[1])))
		return img
	except IOError:
		abort(404)

@app.route('/<page>')
def get_page(page):
	try:
		md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
		html=Markup(markdown.markdown(md.read(), output_format='html5', extensions=['markdown.extensions.attr_list', 'markdown.extensions.def_list', 'markdown.extensions.fenced_code', 'markdown.extensions.tables', 'markdown.extensions.toc', HeaderIdExtension(level=2)]))
		md.close()
		if page=='index':
			return render_template('page.html', hostname=socket.gethostname(), content=html)
		return render_template('page.html', hostname=socket.gethostname(), content=html, title=page)
	except OSError:
		abort(404)

@app.route('/')
def index():
	return get_page('index')

if __name__=='__main__':
	app.run()<commit_msg>Save image to buffer, then return the buffer<commit_after>#!/usr/bin/python3.4
from flask import Flask, render_template, url_for, Markup, abort, send_file
from flask.ext.libsass import *
import pkg_resources, socket

import markdown
from markdown.extensions.headerid import HeaderIdExtension

from slimit import minify

from PIL import Image
import io

app=Flask(__name__)

Sass(
	{'app': 'scss/app.scss'},
	app,
	url_path='/static/css',
	include_paths=[pkg_resources.resource_filename('views', 'scss')],
	output_style='compressed'
)

@app.route('/static/js/<js>')
def render_js(js):
	try:
		fd=open(pkg_resources.resource_filename('views', 'js/' + js), encoding='UTF-8')
		out=minify(fd.read(), mangle=True, mangle_toplevel=True)
		fd.close()
		return out
	except OSError:
		abort(404)

@app.route('/static/img/<width>px-<imgfile>')
def render_thumb(width, imgfile):
	try:
		img=Image.open(pkg_resources.resource_filename('views', 'img/' + imgfile))
		imgIO=io.BytesIO()
		img.thumbnail((int(width), int(width)/(img.size[0]/img.size[1])))
		img.save(imgIO, img.format)
		img.close()
		imgIO.seek(0)
		return send_file(imgIO, mimetype='image/jpeg')
	except IOError:
		abort(404)

@app.route('/<page>')
def get_page(page):
	try:
		md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
		html=Markup(markdown.markdown(md.read(), output_format='html5', extensions=['markdown.extensions.attr_list', 'markdown.extensions.def_list', 'markdown.extensions.fenced_code', 'markdown.extensions.tables', 'markdown.extensions.toc', HeaderIdExtension(level=2)]))
		md.close()
		if page=='index':
			return render_template('page.html', hostname=socket.gethostname(), content=html)
		return render_template('page.html', hostname=socket.gethostname(), content=html, title=page)
	except OSError:
		abort(404)

@app.route('/')
def index():
	return get_page('index')

if __name__=='__main__':
	app.run()
{'fraction_non_alphanumeric': 0.16921397379912664, 'fraction_numerical': 0.00955240174672489, 'mean_word_length': 6.419028340080971, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5536466', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1302, 'n_words': 235}