<s> '''<STR_LIT>''' <EOL> import re , hashlib , time , json <EOL> try : <EOL> from sqlite3 import dbapi2 as database <EOL> except : <EOL> from pysqlite2 import dbapi2 as database <EOL> from resources . lib . libraries import control <EOL> def get ( function , timeout , * args , ** table ) : <EOL> try : <EOL> response = None <EOL> f = repr ( function ) <EOL> f = re . sub ( '<STR_LIT>' , '<STR_LIT>' , f ) <EOL> a = hashlib . md5 ( ) <EOL> for i in args : a . update ( str ( i ) ) <EOL> a = str ( a . hexdigest ( ) ) <EOL> except : <EOL> pass <EOL> try : <EOL> table = table [ '<STR_LIT>' ] <EOL> except : <EOL> table = '<STR_LIT>' <EOL> try : <EOL> control . makeFile ( control . dataPath ) <EOL> dbcon = database . connect ( control . cacheFile ) <EOL> dbcur = dbcon . cursor ( ) <EOL> dbcur . execute ( "<STR_LIT>" % ( table , f , a ) ) <EOL> match = dbcur . fetchone ( ) <EOL> response = eval ( match [ <NUM_LIT:2> ] . encode ( '<STR_LIT:utf-8>' ) ) <EOL> t1 = int ( match [ <NUM_LIT:3> ] ) <EOL> t2 = int ( time . time ( ) ) <EOL> update = ( abs ( t2 - t1 ) / <NUM_LIT> ) >= int ( timeout ) <EOL> if update == False : <EOL> return response <EOL> except : <EOL> pass <EOL> try : <EOL> r = function ( * args ) <EOL> if ( r == None or r == [ ] ) and not response == None : <EOL> return response <EOL> elif ( r == None or r == [ ] ) : <EOL> return r <EOL> except : <EOL> return <EOL> try : <EOL> r = repr ( r ) <EOL> t = int ( time . time ( ) ) <EOL> dbcur . execute ( "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % table ) <EOL> dbcur . execute ( "<STR_LIT>" % ( table , f , a ) ) <EOL> dbcur . execute ( "<STR_LIT>" % table , ( f , a , r , t ) ) <EOL> dbcon . commit ( ) <EOL> except : <EOL> pass <EOL> try : <EOL> return eval ( r . encode ( '<STR_LIT:utf-8>' ) ) <EOL> except : <EOL> pass <EOL> def clear ( table = None ) : <EOL> try : <EOL> control . idle ( ) <EOL> if table == None : table = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> elif not type ( table ) == list : table = [ table ] <EOL> yes = control . yesnoDialog ( control . lang ( <NUM_LIT> ) . encode ( '<STR_LIT:utf-8>' ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not yes : return <EOL> dbcon = database . connect ( control . cacheFile ) <EOL> dbcur = dbcon . cursor ( ) <EOL> for t in table : <EOL> try : <EOL> dbcur . execute ( "<STR_LIT>" % t ) <EOL> dbcur . execute ( "<STR_LIT>" ) <EOL> dbcon . commit ( ) <EOL> except : <EOL> pass <EOL> control . infoDialog ( control . lang ( <NUM_LIT> ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> except : <EOL> pass <EOL> def get_cached_url ( self , url , data = '<STR_LIT>' , cache_limit = <NUM_LIT:8> ) : <EOL> try : <EOL> dbcon = database . connect ( control . sourcescachedUrl ) <EOL> dbcur = dbcon . cursor ( ) <EOL> dbcur . execute ( <EOL> "<STR_LIT>" ) <EOL> except : <EOL> pass <EOL> try : <EOL> if data is None : data = '<STR_LIT>' <EOL> html = '<STR_LIT>' <EOL> res_header = [ ] <EOL> created = <NUM_LIT:0> <EOL> now = time . time ( ) <EOL> age = now - created <EOL> limit = <NUM_LIT> * <NUM_LIT> * cache_limit <EOL> dbcur . execute ( '<STR_LIT>' % ( url , data ) ) <EOL> rows = dbcur . fetchall ( ) <EOL> control . log ( '<STR_LIT>' % ( rows ) ) <EOL> if rows : <EOL> created = float ( rows [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> res_header = json . loads ( rows [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ) <EOL> age = now - created <EOL> if age < limit : <EOL> html = rows [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> control . log ( '<STR_LIT>' % ( <EOL> url , data , bool ( html ) , created , age , age / ( <NUM_LIT> * <NUM_LIT> ) , limit ) ) <EOL> return created , res_header , html <EOL> except : <EOL> return <EOL> def cache_url ( self , url , body , data = None , res_header = None ) : <EOL> try : <EOL> dbcon = database . connect ( control . sourcescachedUrl ) <EOL> dbcur = dbcon . cursor ( ) <EOL> dbcur . execute ( <EOL> "<STR_LIT>" ) <EOL> except : <EOL> pass <EOL> try : <EOL> now = time . time ( ) <EOL> if data is None : data = '<STR_LIT>' <EOL> if res_header is None : res_header = [ ] <EOL> res_header = json . dumps ( res_header ) <EOL> sql = "<STR_LIT>" % ( url , data , body , res_header , now ) <EOL> dbcur . execute ( sql ) <EOL> dbcon . commit ( ) <EOL> except : <EOL> pass <EOL> def timeout ( function , * args , ** table ) : <EOL> try : <EOL> response = None <EOL> f = repr ( function ) <EOL> f = re . sub ( '<STR_LIT>' , '<STR_LIT>' , f ) <EOL> a = hashlib . md5 ( ) <EOL> for i in args : a . update ( str ( i ) ) <EOL> a = str ( a . hexdigest ( ) ) <EOL> except : <EOL> pass <EOL> try : <EOL> table = table [ '<STR_LIT>' ] <EOL> except : <EOL> table = '<STR_LIT>' <EOL> try : <EOL> control . makeFile ( control . dataPath ) <EOL> dbcon = database . connect ( control . cacheFile ) <EOL> dbcur = dbcon . cursor ( ) <EOL> dbcur . execute ( "<STR_LIT>" % ( table , f , a ) ) <EOL> match = dbcur . fetchone ( ) <EOL> return int ( match [ <NUM_LIT:3> ] ) <EOL> except : <EOL> return </s>
