<s> import logging <EOL> import re <EOL> from pylons import request , response , session , tmpl_context as c <EOL> from pylons . controllers . util import abort , redirect_to <EOL> from anygit . lib import helpers <EOL> from anygit . lib . base import BaseController , render <EOL> from anygit import models <EOL> log = logging . getLogger ( __name__ ) <EOL> sha1_re = re . compile ( '<STR_LIT>' ) <EOL> class QueryController ( BaseController ) : <EOL> def index ( self ) : <EOL> return render ( '<STR_LIT>' , controller = '<STR_LIT>' ) <EOL> def query ( self , id , limit = '<STR_LIT>' ) : <EOL> id = id . strip ( ) <EOL> if not sha1_re . search ( id ) : <EOL> error_now = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % id ) <EOL> else : <EOL> error_now = None <EOL> id = id . lower ( ) <EOL> try : <EOL> page = max ( int ( request . params . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> page = <NUM_LIT:1> <EOL> try : <EOL> limit = min ( int ( limit or request . params . get ( '<STR_LIT>' , '<STR_LIT>' ) ) , <NUM_LIT:100> ) <EOL> except ValueError : <EOL> limit = <NUM_LIT:10> <EOL> offset = ( page - <NUM_LIT:1> ) * limit <EOL> matching , count = models . GitObject . lookup_by_sha1 ( sha1 = id , <EOL> partial = True , <EOL> limit = limit ) <EOL> if count > <NUM_LIT:1> : <EOL> matching . skip ( offset ) <EOL> c . page = page <EOL> c . start = offset + <NUM_LIT:1> <EOL> c . end = min ( page * limit , count ) <EOL> c . limit = limit <EOL> c . objects = matching <EOL> c . count = count <EOL> c . queried_id = id <EOL> c . out_of_range = c . start > count <EOL> return render ( '<STR_LIT>' , controller = '<STR_LIT>' , error_now = error_now ) <EOL> def query_with_string ( self ) : <EOL> kwargs = { '<STR_LIT:action>' : '<STR_LIT>' } <EOL> if '<STR_LIT>' in request . params : <EOL> kwargs [ '<STR_LIT:id>' ] = request . params [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in request . params : <EOL> kwargs [ '<STR_LIT>' ] = request . params [ '<STR_LIT>' ] <EOL> redirect_to ( ** kwargs ) <EOL> q = query </s>
