<commit_before># -*- coding: utf-8 -*-
"""
	claslite.handlers
	~~~~~~~~~~~~~~~~~~~~

	CLASlite handler

	:Copyright 2010 Carnegie Institution for Science and <NAME>
	:Use under any Open Source license:
	:http://www.opensource.org/licenses/
"""

from tipfy import RequestHandler, Response
from tipfy.auth import login_required, user_required
from tipfy.sessions import SessionMiddleware
from tipfyext.jinja2 import Jinja2Mixin

from google.appengine.api.users import(
	create_login_url, create_logout_url,
	get_current_user, is_current_user_admin
)

class BaseHandler( RequestHandler, Jinja2Mixin ):
	middleware = [ SessionMiddleware() ]
	
	def redirect( self, url=None ):
		if url == None: url = '/'
		return super(BaseHandler,self).redirect( url )
	
	def redirect_path( self, default='/' ):
		url = self.request.args.get( 'continue', '/' )
		if url.startswith('/'): return default
		return url


class ClasliteHandler( BaseHandler ):
	@user_required
	def get( self ):
		'''	Return Response object for main CLASlite page.
		'''
		if 'count' not in self.session: self.session['count'] = '0';
		count = int(self.session['count']) + 1
		self.session['count'] = str(count)
		
		context = {
			'count': count,
			'email': self.auth.session.email(),
			'logout_url': self.auth.logout_url(),
			'user_id': 'gae|' + self.auth.session.user_id(),
		}
		return self.render_response( 'claslite.html', **context )


class LoginHandler( BaseHandler ):
	def get( self, **kwargs ):
		return self.redirect( create_login_url( self.redirect_path() ) )


class LogoutHandler( BaseHandler ):
	def get( self, **kwargs ):
		return self.redirect( create_logout_url( self.redirect_path() ) )


class SignupHandler( BaseHandler ):
	@login_required
	def get( self, **kwargs ):
		if not self.auth.user:
			user_id = 'gae|' + self.auth.session.user_id()
			email = self.auth.session.email()
			user = self.auth.create_user( user_id, user_id, email=email )
		return self.redirect()
	
	@login_required
	def get( self, **kwargs ):
		if self.auth.user:
			return self.redirect()
		context = {
			'redirect_url': self.redirect_path(),
		}
		return self.render_response( 'signup.html', **context )
	
	@login_required
	def post( self, **kwargs ):
		if self.auth.user:
			return self.redirect()
		auth_id = 'gae|%s' % self.auth.session.user_id()
		email = self.auth.session.email()
		user = self.auth.create_user( auth_id, auth_id, email=email )
		if user:
			return self.redirect()
		return self.get( **kwargs )
<commit_msg>Remove dead code<commit_after># -*- coding: utf-8 -*-
"""
	claslite.handlers
	~~~~~~~~~~~~~~~~~~~~

	CLASlite handler

	:Copyright 2010 Carnegie Institution for Science and <NAME>
	:Use under any Open Source license:
	:http://www.opensource.org/licenses/
"""

from tipfy import RequestHandler, Response
from tipfy.auth import login_required, user_required
from tipfy.sessions import SessionMiddleware
from tipfyext.jinja2 import Jinja2Mixin

from google.appengine.api.users import(
	create_login_url, create_logout_url,
	get_current_user, is_current_user_admin
)

class BaseHandler( RequestHandler, Jinja2Mixin ):
	middleware = [ SessionMiddleware() ]
	
	def redirect( self, url=None ):
		if url == None: url = '/'
		return super(BaseHandler,self).redirect( url )
	
	def redirect_path( self, default='/' ):
		url = self.request.args.get( 'continue', '/' )
		if url.startswith('/'): return default
		return url


class ClasliteHandler( BaseHandler ):
	@user_required
	def get( self ):
		'''	Return Response object for main CLASlite page.
		'''
		if 'count' not in self.session: self.session['count'] = '0';
		count = int(self.session['count']) + 1
		self.session['count'] = str(count)
		
		context = {
			'count': count,
			'email': self.auth.session.email(),
			'logout_url': self.auth.logout_url(),
			'user_id': 'gae|' + self.auth.session.user_id(),
		}
		return self.render_response( 'claslite.html', **context )


class LoginHandler( BaseHandler ):
	def get( self, **kwargs ):
		return self.redirect( create_login_url( self.redirect_path() ) )


class LogoutHandler( BaseHandler ):
	def get( self, **kwargs ):
		return self.redirect( create_logout_url( self.redirect_path() ) )


class SignupHandler( BaseHandler ):
	@login_required
	def get( self, **kwargs ):
		if self.auth.user:
			return self.redirect()
		context = {
			'redirect_url': self.redirect_path(),
		}
		return self.render_response( 'signup.html', **context )
	
	@login_required
	def post( self, **kwargs ):
		if self.auth.user:
			return self.redirect()
		auth_id = 'gae|%s' % self.auth.session.user_id()
		email = self.auth.session.email()
		user = self.auth.create_user( auth_id, auth_id, email=email )
		if user:
			return self.redirect()
		return self.get( **kwargs )

{'fraction_non_alphanumeric': 0.1452431289640592, 'fraction_numerical': 0.004228329809725159, 'mean_word_length': 4.321709786276715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7031728', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1556, 'n_words': 388}