<s> import inspect <EOL> from types import * <EOL> import re <EOL> import functools <EOL> import random <EOL> import time <EOL> from threading import Timer <EOL> class _IdCounter ( object ) : <EOL> """<STR_LIT>""" <EOL> count = <NUM_LIT:0> <EOL> pass <EOL> class __ ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , repr , func ) : <EOL> self . _repr = repr <EOL> self . _func = func <EOL> functools . update_wrapper ( self , func ) <EOL> def __call__ ( self , * args , ** kw ) : <EOL> return self . _func ( * args , ** kw ) <EOL> def __repr__ ( self ) : <EOL> return self . _repr ( self . _func ) <EOL> def u_withrepr ( reprfun ) : <EOL> """<STR_LIT>""" <EOL> def _wrap ( func ) : <EOL> return __ ( reprfun , func ) <EOL> return _wrap <EOL> @ u_withrepr ( lambda x : "<STR_LIT>" ) <EOL> def _ ( obj ) : <EOL> """<STR_LIT>""" <EOL> return underscore ( obj ) <EOL> class underscore ( object ) : <EOL> """<STR_LIT>""" <EOL> object = None <EOL> """<STR_LIT>""" <EOL> VERSION = "<STR_LIT>" <EOL> chained = False <EOL> """<STR_LIT>""" <EOL> Null = "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> _wrapped = Null <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> self . chained = False <EOL> self . object = obj <EOL> class Namespace ( object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> self . Namespace = Namespace <EOL> def __str__ ( self ) : <EOL> if self . chained is True : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def __repr__ ( self ) : <EOL> if self . chained is True : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ property <EOL> def obj ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _wrapped is not self . Null : <EOL> return self . _wrapped <EOL> else : <EOL> return self . object <EOL> @ obj . setter <EOL> def obj ( self , value ) : <EOL> """<STR_LIT>""" <EOL> self . object = value <EOL> return self . object <EOL> def _wrap ( self , ret ) : <EOL> """<STR_LIT>""" <EOL> if self . chained : <EOL> self . _wrapped = ret <EOL> return self <EOL> else : <EOL> return ret <EOL> @ property <EOL> def _clean ( self ) : <EOL> """<STR_LIT>""" <EOL> return _ ( self . obj ) <EOL> def _toOriginal ( self , val ) : <EOL> """<STR_LIT>""" <EOL> if self . _clean . isTuple ( ) : <EOL> return tuple ( val ) <EOL> elif self . _clean . isList ( ) : <EOL> return list ( val ) <EOL> elif self . _clean . isDict ( ) : <EOL> return dict ( val ) <EOL> else : <EOL> return val <EOL> """<STR_LIT>""" <EOL> def each ( self , func ) : <EOL> """<STR_LIT>""" <EOL> if self . _clean . isTuple ( ) or self . _clean . isList ( ) : <EOL> for index , value in enumerate ( self . obj ) : <EOL> r = func ( value , index , self . obj ) <EOL> if r is "<STR_LIT>" : <EOL> break <EOL> else : <EOL> for index , key in enumerate ( self . obj ) : <EOL> r = func ( self . obj [ key ] , key , self . obj , index ) <EOL> if r is "<STR_LIT>" : <EOL> break <EOL> return self . _wrap ( self ) <EOL> forEach = each <EOL> def map ( self , func ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . results = [ ] <EOL> def by ( value , index , list , * args ) : <EOL> ns . results . append ( func ( value , index , list ) ) <EOL> _ ( self . obj ) . each ( by ) <EOL> return self . _wrap ( ns . results ) <EOL> collect = map <EOL> def reduce ( self , func , memo = None ) : <EOL> """<STR_LIT>""" <EOL> if memo is None : <EOL> memo = [ ] <EOL> ns = self . Namespace ( ) <EOL> ns . initial = True <EOL> ns . memo = memo <EOL> obj = self . obj <EOL> def by ( value , index , * args ) : <EOL> if not ns . initial : <EOL> ns . memo = value <EOL> ns . initial = True <EOL> else : <EOL> ns . memo = func ( ns . memo , value , index ) <EOL> _ ( obj ) . each ( by ) <EOL> return self . _wrap ( ns . memo ) <EOL> foldl = inject = reduce <EOL> def reduceRight ( self , func ) : <EOL> """<STR_LIT>""" <EOL> x = self . obj [ : ] <EOL> x . reverse ( ) <EOL> return self . _wrap ( functools . reduce ( func , x ) ) <EOL> foldr = reduceRight <EOL> def find ( self , func ) : <EOL> """<STR_LIT>""" <EOL> self . ftmp = None <EOL> def test ( value , index , list ) : <EOL> if func ( value , index , list ) is True : <EOL> self . ftmp = value <EOL> return True <EOL> self . _clean . any ( test ) <EOL> return self . _wrap ( self . ftmp ) <EOL> detect = find <EOL> def filter ( self , func ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( list ( filter ( func , self . obj ) ) ) <EOL> select = filter <EOL> def reject ( self , func ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( list ( filter ( lambda val : not func ( val ) , self . obj ) ) ) <EOL> def all ( self , func = None ) : <EOL> """<STR_LIT>""" <EOL> if func is None : <EOL> func = lambda x , * args : x <EOL> self . altmp = True <EOL> def testEach ( value , index , * args ) : <EOL> if func ( value , index , * args ) is False : <EOL> self . altmp = False <EOL> self . _clean . each ( testEach ) <EOL> return self . _wrap ( self . altmp ) <EOL> every = all <EOL> def any ( self , func = None ) : <EOL> """<STR_LIT>""" <EOL> if func is None : <EOL> func = lambda x , * args : x <EOL> self . antmp = False <EOL> def testEach ( value , index , * args ) : <EOL> if func ( value , index , * args ) is True : <EOL> self . antmp = True <EOL> return "<STR_LIT>" <EOL> self . _clean . each ( testEach ) <EOL> return self . _wrap ( self . antmp ) <EOL> some = any <EOL> def include ( self , target ) : <EOL> """<STR_LIT>""" <EOL> if self . _clean . isDict ( ) : <EOL> return self . _wrap ( target in self . obj . values ( ) ) <EOL> else : <EOL> return self . _wrap ( target in self . obj ) <EOL> contains = include <EOL> def invoke ( self , method , * args ) : <EOL> """<STR_LIT>""" <EOL> def inv ( value , * ar ) : <EOL> if ( <EOL> _ ( method ) . isFunction ( ) or <EOL> _ ( method ) . isLambda ( ) or <EOL> _ ( method ) . isMethod ( ) <EOL> ) : <EOL> return method ( value , * args ) <EOL> else : <EOL> return getattr ( value , method ) ( * args ) <EOL> return self . _wrap ( self . _clean . map ( inv ) ) <EOL> def pluck ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( [ x . get ( key ) for x in self . obj ] ) <EOL> def where ( self , attrs = None , first = False ) : <EOL> """<STR_LIT>""" <EOL> if attrs is None : <EOL> return None if first is True else [ ] <EOL> method = _ . find if first else _ . filter <EOL> def by ( val , * args ) : <EOL> for key , value in attrs . items ( ) : <EOL> try : <EOL> if attrs [ key ] != val [ key ] : <EOL> return False <EOL> except KeyError : <EOL> return False <EOL> return True <EOL> return self . _wrap ( method ( self . obj , by ) ) <EOL> def findWhere ( self , attrs = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . _clean . where ( attrs , True ) ) <EOL> def max ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . _clean . isDict ( ) ) : <EOL> return self . _wrap ( list ( ) ) <EOL> return self . _wrap ( max ( self . obj ) ) <EOL> def min ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . _clean . isDict ( ) ) : <EOL> return self . _wrap ( list ( ) ) <EOL> return self . _wrap ( min ( self . obj ) ) <EOL> def shuffle ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . _clean . isDict ( ) ) : <EOL> return self . _wrap ( list ( ) ) <EOL> cloned = self . obj [ : ] <EOL> random . shuffle ( cloned ) <EOL> return self . _wrap ( cloned ) <EOL> def sortBy ( self , val = None ) : <EOL> """<STR_LIT>""" <EOL> if val is not None : <EOL> if _ ( val ) . isString ( ) : <EOL> return self . _wrap ( sorted ( self . obj , key = lambda x , <EOL> * args : x . get ( val ) ) ) <EOL> else : <EOL> return self . _wrap ( sorted ( self . obj , key = val ) ) <EOL> else : <EOL> return self . _wrap ( sorted ( self . obj ) ) <EOL> def _lookupIterator ( self , val ) : <EOL> """<STR_LIT>""" <EOL> if val is None : <EOL> return lambda el , * args : el <EOL> return val if _ . isCallable ( val ) else lambda obj , * args : obj [ val ] <EOL> def _group ( self , obj , val , behavior ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . result = { } <EOL> iterator = self . _lookupIterator ( val ) <EOL> def e ( value , index , * args ) : <EOL> key = iterator ( value , index ) <EOL> behavior ( ns . result , key , value ) <EOL> _ . each ( obj , e ) <EOL> if len ( ns . result ) == <NUM_LIT:1> : <EOL> try : <EOL> return ns . result [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> return list ( ns . result . values ( ) ) [ <NUM_LIT:0> ] <EOL> return ns . result <EOL> def groupBy ( self , val ) : <EOL> """<STR_LIT>""" <EOL> def by ( result , key , value ) : <EOL> if key not in result : <EOL> result [ key ] = [ ] <EOL> result [ key ] . append ( value ) <EOL> res = self . _group ( self . obj , val , by ) <EOL> return self . _wrap ( res ) <EOL> def indexBy ( self , val = None ) : <EOL> """<STR_LIT>""" <EOL> if val is None : <EOL> val = lambda * args : args [ <NUM_LIT:0> ] <EOL> def by ( result , key , value ) : <EOL> result [ key ] = value <EOL> res = self . _group ( self . obj , val , by ) <EOL> return self . _wrap ( res ) <EOL> def countBy ( self , val ) : <EOL> """<STR_LIT>""" <EOL> def by ( result , key , value ) : <EOL> if key not in result : <EOL> result [ key ] = <NUM_LIT:0> <EOL> result [ key ] += <NUM_LIT:1> <EOL> res = self . _group ( self . obj , val , by ) <EOL> return self . _wrap ( res ) <EOL> def sortedIndex ( self , obj , iterator = lambda x : x ) : <EOL> """<STR_LIT>""" <EOL> array = self . obj <EOL> value = iterator ( obj ) <EOL> low = <NUM_LIT:0> <EOL> high = len ( array ) <EOL> while low < high : <EOL> mid = ( low + high ) >> <NUM_LIT:1> <EOL> if iterator ( array [ mid ] ) < value : <EOL> low = mid + <NUM_LIT:1> <EOL> else : <EOL> high = mid <EOL> return self . _wrap ( low ) <EOL> def toArray ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( list ( self . obj ) ) <EOL> def size ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( len ( self . obj ) ) <EOL> def first ( self , n = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> res = self . obj [ <NUM_LIT:0> : n ] <EOL> if len ( res ) is <NUM_LIT:1> : <EOL> res = res [ <NUM_LIT:0> ] <EOL> return self . _wrap ( res ) <EOL> head = take = first <EOL> def initial ( self , n = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj [ <NUM_LIT:0> : - n ] ) <EOL> def last ( self , n = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> res = self . obj [ - n : ] <EOL> if len ( res ) is <NUM_LIT:1> : <EOL> res = res [ <NUM_LIT:0> ] <EOL> return self . _wrap ( res ) <EOL> def rest ( self , n = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj [ n : ] ) <EOL> tail = rest <EOL> def compact ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . _clean . filter ( lambda x : x ) ) <EOL> def _flatten ( self , input , shallow = False , output = None ) : <EOL> ns = self . Namespace ( ) <EOL> ns . output = output <EOL> if ns . output is None : <EOL> ns . output = [ ] <EOL> def by ( value , * args ) : <EOL> if _ . isList ( value ) or _ . isTuple ( value ) : <EOL> if shallow : <EOL> ns . output = ns . output + value <EOL> else : <EOL> self . _flatten ( value , shallow , ns . output ) <EOL> else : <EOL> ns . output . append ( value ) <EOL> _ . each ( input , by ) <EOL> return ns . output <EOL> def flatten ( self , shallow = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . _flatten ( self . obj , shallow ) ) <EOL> def without ( self , * values ) : <EOL> """<STR_LIT>""" <EOL> if self . _clean . isDict ( ) : <EOL> newlist = { } <EOL> for i , k in enumerate ( self . obj ) : <EOL> if _ ( values ) . indexOf ( k ) is - <NUM_LIT:1> : <EOL> newlist . set ( k , self . obj [ k ] ) <EOL> else : <EOL> newlist = [ ] <EOL> for i , v in enumerate ( self . obj ) : <EOL> if _ ( values ) . indexOf ( v ) is - <NUM_LIT:1> : <EOL> newlist . append ( v ) <EOL> return self . _wrap ( newlist ) <EOL> def partition ( self , predicate = None ) : <EOL> """<STR_LIT>""" <EOL> predicate = self . _lookupIterator ( predicate ) <EOL> pass_list = [ ] <EOL> fail_list = [ ] <EOL> def by ( elem , index , * args ) : <EOL> ( pass_list if predicate ( elem ) else fail_list ) . append ( elem ) <EOL> _ . each ( self . obj , by ) <EOL> return self . _wrap ( [ pass_list , fail_list ] ) <EOL> def uniq ( self , isSorted = False , iterator = None ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . results = [ ] <EOL> ns . array = self . obj <EOL> initial = self . obj <EOL> if iterator is not None : <EOL> initial = _ ( ns . array ) . map ( iterator ) <EOL> def by ( memo , value , index ) : <EOL> if ( ( _ . last ( memo ) != value or <EOL> not len ( memo ) ) if isSorted else not _ . include ( memo , value ) ) : <EOL> memo . append ( value ) <EOL> ns . results . append ( ns . array [ index ] ) <EOL> return memo <EOL> ret = _ . reduce ( initial , by ) <EOL> return self . _wrap ( ret ) <EOL> unique = uniq <EOL> def union ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> args = list ( args ) <EOL> args . insert ( <NUM_LIT:0> , self . obj ) <EOL> return self . _wrap ( _ . uniq ( self . _flatten ( args , True , [ ] ) ) ) <EOL> def intersection ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if type ( self . obj [ <NUM_LIT:0> ] ) is int : <EOL> a = self . obj <EOL> else : <EOL> a = tuple ( self . obj [ <NUM_LIT:0> ] ) <EOL> setobj = set ( a ) <EOL> for i , v in enumerate ( args ) : <EOL> setobj = setobj & set ( args [ i ] ) <EOL> return self . _wrap ( list ( setobj ) ) <EOL> def difference ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> setobj = set ( self . obj ) <EOL> for i , v in enumerate ( args ) : <EOL> setobj = setobj - set ( args [ i ] ) <EOL> return self . _wrap ( self . _clean . _toOriginal ( setobj ) ) <EOL> def zip ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> args = list ( args ) <EOL> args . insert ( <NUM_LIT:0> , self . obj ) <EOL> maxLen = _ ( args ) . chain ( ) . collect ( lambda x , * args : len ( x ) ) . max ( ) . value ( ) <EOL> for i , v in enumerate ( args ) : <EOL> l = len ( args [ i ] ) <EOL> if l < maxLen : <EOL> args [ i ] <EOL> for x in range ( maxLen - l ) : <EOL> args [ i ] . append ( None ) <EOL> return self . _wrap ( zip ( * args ) ) <EOL> def zipObject ( self , values ) : <EOL> """<STR_LIT>""" <EOL> result = { } <EOL> keys = self . obj <EOL> i = <NUM_LIT:0> <EOL> l = len ( keys ) <EOL> while i < l : <EOL> result [ keys [ i ] ] = values [ i ] <EOL> l = len ( keys ) <EOL> i += <NUM_LIT:1> <EOL> return self . _wrap ( result ) <EOL> def indexOf ( self , item , isSorted = False ) : <EOL> """<STR_LIT>""" <EOL> array = self . obj <EOL> ret = - <NUM_LIT:1> <EOL> if not ( self . _clean . isList ( ) or self . _clean . isTuple ( ) ) : <EOL> return self . _wrap ( - <NUM_LIT:1> ) <EOL> if isSorted : <EOL> i = _ . sortedIndex ( array , item ) <EOL> ret = i if array [ i ] is item else - <NUM_LIT:1> <EOL> else : <EOL> i = <NUM_LIT:0> <EOL> l = len ( array ) <EOL> while i < l : <EOL> if array [ i ] is item : <EOL> return self . _wrap ( i ) <EOL> i += <NUM_LIT:1> <EOL> return self . _wrap ( ret ) <EOL> def lastIndexOf ( self , item ) : <EOL> """<STR_LIT>""" <EOL> array = self . obj <EOL> i = len ( array ) - <NUM_LIT:1> <EOL> if not ( self . _clean . isList ( ) or self . _clean . isTuple ( ) ) : <EOL> return self . _wrap ( - <NUM_LIT:1> ) <EOL> while i > - <NUM_LIT:1> : <EOL> if array [ i ] is item : <EOL> return self . _wrap ( i ) <EOL> i -= <NUM_LIT:1> <EOL> return self . _wrap ( - <NUM_LIT:1> ) <EOL> def range ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> args = list ( args ) <EOL> args . insert ( <NUM_LIT:0> , self . obj ) <EOL> return self . _wrap ( range ( * args ) ) <EOL> """<STR_LIT>""" <EOL> def bind ( self , context ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj ) <EOL> curry = bind <EOL> def partial ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> def part ( * args2 ) : <EOL> args3 = args + args2 <EOL> return self . obj ( * args3 ) <EOL> return self . _wrap ( part ) <EOL> def bindAll ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj ) <EOL> def memoize ( self , hasher = None ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . memo = { } <EOL> if hasher is None : <EOL> hasher = lambda x : x <EOL> def memoized ( * args , ** kwargs ) : <EOL> key = hasher ( * args ) <EOL> if key not in ns . memo : <EOL> ns . memo [ key ] = self . obj ( * args , ** kwargs ) <EOL> return ns . memo [ key ] <EOL> return self . _wrap ( memoized ) <EOL> def delay ( self , wait , * args ) : <EOL> """<STR_LIT>""" <EOL> def call_it ( ) : <EOL> self . obj ( * args ) <EOL> t = Timer ( ( float ( wait ) / float ( <NUM_LIT:1000> ) ) , call_it ) <EOL> t . start ( ) <EOL> return self . _wrap ( self . obj ) <EOL> def defer ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> return self . delay ( <NUM_LIT:1> , * args ) <EOL> def throttle ( self , wait ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . timeout = None <EOL> ns . throttling = None <EOL> ns . more = None <EOL> ns . result = None <EOL> def done ( ) : <EOL> ns . more = ns . throttling = False <EOL> whenDone = _ . debounce ( done , wait ) <EOL> wait = ( float ( wait ) / float ( <NUM_LIT:1000> ) ) <EOL> def throttled ( * args , ** kwargs ) : <EOL> def later ( ) : <EOL> ns . timeout = None <EOL> if ns . more : <EOL> self . obj ( * args , ** kwargs ) <EOL> whenDone ( ) <EOL> if not ns . timeout : <EOL> ns . timeout = Timer ( wait , later ) <EOL> ns . timeout . start ( ) <EOL> if ns . throttling : <EOL> ns . more = True <EOL> else : <EOL> ns . throttling = True <EOL> ns . result = self . obj ( * args , ** kwargs ) <EOL> whenDone ( ) <EOL> return ns . result <EOL> return self . _wrap ( throttled ) <EOL> def debounce ( self , wait , immediate = None ) : <EOL> """<STR_LIT>""" <EOL> wait = ( float ( wait ) / float ( <NUM_LIT:1000> ) ) <EOL> def debounced ( * args , ** kwargs ) : <EOL> def call_it ( ) : <EOL> self . obj ( * args , ** kwargs ) <EOL> try : <EOL> debounced . t . cancel ( ) <EOL> except ( AttributeError ) : <EOL> pass <EOL> debounced . t = Timer ( wait , call_it ) <EOL> debounced . t . start ( ) <EOL> return self . _wrap ( debounced ) <EOL> def once ( self ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . memo = None <EOL> ns . run = False <EOL> def work_once ( * args , ** kwargs ) : <EOL> if ns . run is False : <EOL> ns . memo = self . obj ( * args , ** kwargs ) <EOL> ns . run = True <EOL> return ns . memo <EOL> return self . _wrap ( work_once ) <EOL> def wrap ( self , wrapper ) : <EOL> """<STR_LIT>""" <EOL> def wrapped ( * args , ** kwargs ) : <EOL> if kwargs : <EOL> kwargs [ "<STR_LIT:object>" ] = self . obj <EOL> else : <EOL> args = list ( args ) <EOL> args . insert ( <NUM_LIT:0> , self . obj ) <EOL> return wrapper ( * args , ** kwargs ) <EOL> return self . _wrap ( wrapped ) <EOL> def compose ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> args = list ( args ) <EOL> def composed ( * ar , ** kwargs ) : <EOL> lastRet = self . obj ( * ar , ** kwargs ) <EOL> for i in args : <EOL> lastRet = i ( lastRet ) <EOL> return lastRet <EOL> return self . _wrap ( composed ) <EOL> def after ( self , func ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . times = self . obj <EOL> if ns . times <= <NUM_LIT:0> : <EOL> return func ( ) <EOL> def work_after ( * args ) : <EOL> if ns . times <= <NUM_LIT:1> : <EOL> return func ( * args ) <EOL> ns . times -= <NUM_LIT:1> <EOL> return self . _wrap ( work_after ) <EOL> """<STR_LIT>""" <EOL> def keys ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj . keys ( ) ) <EOL> def values ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj . values ( ) ) <EOL> def pairs ( self ) : <EOL> """<STR_LIT>""" <EOL> keys = self . _clean . keys ( ) <EOL> pairs = [ ] <EOL> for key in keys : <EOL> pairs . append ( [ key , self . obj [ key ] ] ) <EOL> return self . _wrap ( pairs ) <EOL> def invert ( self ) : <EOL> """<STR_LIT>""" <EOL> keys = self . _clean . keys ( ) <EOL> inverted = { } <EOL> for key in keys : <EOL> inverted [ self . obj [ key ] ] = key <EOL> return self . _wrap ( inverted ) <EOL> def functions ( self ) : <EOL> """<STR_LIT>""" <EOL> names = [ ] <EOL> for i , k in enumerate ( self . obj ) : <EOL> if _ ( self . obj [ k ] ) . isCallable ( ) : <EOL> names . append ( k ) <EOL> return self . _wrap ( sorted ( names ) ) <EOL> methods = functions <EOL> def extend ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> args = list ( args ) <EOL> for i in args : <EOL> self . obj . update ( i ) <EOL> return self . _wrap ( self . obj ) <EOL> def pick ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace ( ) <EOL> ns . result = { } <EOL> def by ( key , * args ) : <EOL> if key in self . obj : <EOL> ns . result [ key ] = self . obj [ key ] <EOL> _ . each ( self . _flatten ( args , True , [ ] ) , by ) <EOL> return self . _wrap ( ns . result ) <EOL> def omit ( self , * args ) : <EOL> copy = { } <EOL> keys = _ ( args ) . flatten ( ) <EOL> for i , key in enumerate ( self . obj ) : <EOL> if not _ . include ( keys , key ) : <EOL> copy [ key ] = self . obj [ key ] <EOL> return self . _wrap ( copy ) <EOL> def defaults ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> ns = self . Namespace <EOL> ns . obj = self . obj <EOL> def by ( source , * ar ) : <EOL> for i , prop in enumerate ( source ) : <EOL> if prop not in ns . obj : <EOL> ns . obj [ prop ] = source [ prop ] <EOL> _ . each ( args , by ) <EOL> return self . _wrap ( ns . obj ) <EOL> def clone ( self ) : <EOL> """<STR_LIT>""" <EOL> import copy <EOL> return self . _wrap ( copy . copy ( self . obj ) ) <EOL> def tap ( self , interceptor ) : <EOL> """<STR_LIT>""" <EOL> interceptor ( self . obj ) <EOL> return self . _wrap ( self . obj ) <EOL> def isEqual ( self , match ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj == match ) <EOL> def isEmpty ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . obj is None : <EOL> return True <EOL> if self . _clean . isString ( ) : <EOL> ret = self . obj . strip ( ) is "<STR_LIT>" <EOL> elif self . _clean . isDict ( ) : <EOL> ret = len ( self . obj . keys ( ) ) == <NUM_LIT:0> <EOL> else : <EOL> ret = len ( self . obj ) == <NUM_LIT:0> <EOL> return self . _wrap ( ret ) <EOL> def isElement ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( False ) <EOL> def isDict ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is dict ) <EOL> def isTuple ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is tuple ) <EOL> def isList ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is list ) <EOL> def isNone ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj is None ) <EOL> def isType ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is type ) <EOL> def isBoolean ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is bool ) <EOL> isBool = isBoolean <EOL> def isInt ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is int ) <EOL> def isLong ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is long ) <EOL> def isFloat ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is float ) <EOL> def isComplex ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is complex ) <EOL> def isString ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is str ) <EOL> def isUnicode ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is unicode ) <EOL> def isCallable ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( callable ( self . obj ) ) <EOL> def isFunction ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is FunctionType ) <EOL> def isLambda ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is LambdaType ) <EOL> def isGenerator ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is GeneratorType ) <EOL> def isCode ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is CodeType ) <EOL> def isClass ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( inspect . isclass ( self . obj ) ) <EOL> def isInstance ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is InstanceType ) <EOL> def isMethod ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( inspect . ismethod ( self . obj ) ) <EOL> def isUnboundMethod ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is UnboundMethodType ) <EOL> def isBuiltinFunction ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is BuiltinFunctionType ) <EOL> def isBuiltinMethod ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is BuiltinMethodType ) <EOL> def isModule ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is ModuleType ) <EOL> def isFile ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> filetype = file <EOL> except NameError : <EOL> filetype = io . IOBase <EOL> return self . _wrap ( type ( self . obj ) is filetype ) <EOL> def isXRange ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is XRangeType ) <EOL> def isSlice ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is type ( slice ) ) <EOL> def isEllipsis ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is type ( Ellipsis ) ) <EOL> def isTraceback ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is TracebackType ) <EOL> def isFrame ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is FrameType ) <EOL> def isBuffer ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is BufferType ) <EOL> def isDictProxy ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is DictProxyType ) <EOL> def isNotImplemented ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is type ( NotImplemented ) ) <EOL> def isGetSetDescriptor ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is GetSetDescriptorType ) <EOL> def isMemberDescriptor ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( type ( self . obj ) is MemberDescriptorType ) <EOL> def has ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( hasattr ( self . obj , key ) ) <EOL> def join ( self , glue = "<STR_LIT:U+0020>" ) : <EOL> """<STR_LIT>""" <EOL> j = glue . join ( [ str ( x ) for x in self . obj ] ) <EOL> return self . _wrap ( j ) <EOL> def constant ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( lambda * args : self . obj ) <EOL> def identity ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( self . obj ) <EOL> def property ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap ( lambda obj , * args : obj [ self . obj ] ) <EOL> def matches ( self ) : <EOL> """<STR_LIT>""" <EOL> def ret ( obj , * args ) : <EOL> if self . obj is obj : <EOL> return True <EOL> for key in self . obj : <EOL> if self . obj [ key ] != obj [ key ] : <EOL> return False <EOL> return True <EOL> return self . _wrap ( ret ) <EOL> def times ( self , func , * args ) : <EOL> """<STR_LIT>""" <EOL> n = self . obj <EOL> i = <NUM_LIT:0> <EOL> while n is not <NUM_LIT:0> : <EOL> n -= <NUM_LIT:1> <EOL> func ( i ) <EOL> i += <NUM_LIT:1> <EOL> return self . _wrap ( func ) <EOL> def now ( self ) : <EOL> return self . _wrap ( time . time ( ) ) <EOL> def random ( self , max_number = None ) : <EOL> """<STR_LIT>""" <EOL> min_number = self . obj <EOL> if max_number is None : <EOL> min_number = <NUM_LIT:0> <EOL> max_number = self . obj <EOL> return random . randrange ( min_number , max_number ) <EOL> def result ( self , property , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . obj is None : <EOL> return self . _wrap ( self . obj ) <EOL> if ( hasattr ( self . obj , property ) ) : <EOL> value = getattr ( self . obj , property ) <EOL> else : <EOL> value = self . obj . get ( property ) <EOL> if _ . isCallable ( value ) : <EOL> return self . _wrap ( value ( * args ) ) <EOL> return self . _wrap ( value ) <EOL> def mixin ( self ) : <EOL> """<STR_LIT>""" <EOL> methods = self . obj <EOL> for i , k in enumerate ( methods ) : <EOL> setattr ( underscore , k , methods [ k ] ) <EOL> self . makeStatic ( ) <EOL> return self . _wrap ( self . obj ) <EOL> def uniqueId ( self , prefix = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> _IdCounter . count += <NUM_LIT:1> <EOL> id = _IdCounter . count <EOL> if prefix : <EOL> return self . _wrap ( prefix + str ( id ) ) <EOL> else : <EOL> return self . _wrap ( id ) <EOL> _html_escape_table = { <EOL> "<STR_LIT:&>" : "<STR_LIT>" , <EOL> '<STR_LIT:">' : "<STR_LIT>" , <EOL> "<STR_LIT:'>" : "<STR_LIT>" , <EOL> "<STR_LIT:>>" : "<STR_LIT>" , <EOL> "<STR_LIT:<>" : "<STR_LIT>" , <EOL> } <EOL> def escape ( self ) : <EOL> """<STR_LIT>""" <EOL> self . obj = self . obj . replace ( "<STR_LIT:&>" , self . _html_escape_table [ "<STR_LIT:&>" ] ) <EOL> for i , k in enumerate ( self . _html_escape_table ) : <EOL> v = self . _html_escape_table [ k ] <EOL> if k is not "<STR_LIT:&>" : <EOL> self . obj = self . obj . replace ( k , v ) <EOL> return self . _wrap ( self . obj ) <EOL> def unescape ( self ) : <EOL> """<STR_LIT>""" <EOL> for i , k in enumerate ( self . _html_escape_table ) : <EOL> v = self . _html_escape_table [ k ] <EOL> self . obj = self . obj . replace ( v , k ) <EOL> return self . _wrap ( self . obj ) <EOL> """<STR_LIT>""" <EOL> templateSettings = { <EOL> "<STR_LIT>" : r"<STR_LIT>" , <EOL> "<STR_LIT>" : r"<STR_LIT>" , <EOL> "<STR_LIT>" : r"<STR_LIT>" <EOL> } <EOL> escapes = { <EOL> '<STR_LIT:\\>' : '<STR_LIT:\\>' , <EOL> "<STR_LIT:'>" : r"<STR_LIT:'>" , <EOL> "<STR_LIT:r>" : r'<STR_LIT:\r>' , <EOL> "<STR_LIT:n>" : r'<STR_LIT:\n>' , <EOL> "<STR_LIT:t>" : r'<STR_LIT:\t>' , <EOL> "<STR_LIT>" : r'<STR_LIT>' , <EOL> "<STR_LIT>" : r'<STR_LIT>' , <EOL> r'<STR_LIT:\\>' : '<STR_LIT:\\>' , <EOL> r"<STR_LIT:'>" : "<STR_LIT:'>" , <EOL> '<STR_LIT>' : "<STR_LIT:r>" , <EOL> '<STR_LIT>' : "<STR_LIT:n>" , <EOL> '<STR_LIT>' : "<STR_LIT:t>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> } <EOL> def template ( self , data = None , settings = None ) : <EOL> """<STR_LIT>""" <EOL> if settings is None : <EOL> settings = { } <EOL> ts = _ . templateSettings <EOL> _ . defaults ( ts , self . templateSettings ) <EOL> _ . extend ( settings , ts ) <EOL> _ . extend ( settings , { <EOL> "<STR_LIT>" : r"<STR_LIT>" , <EOL> "<STR_LIT>" : r"<STR_LIT>" <EOL> } ) <EOL> src = self . obj <EOL> ns = self . Namespace ( ) <EOL> ns . indent_level = <NUM_LIT:1> <EOL> def unescape ( code ) : <EOL> def unescapes ( matchobj ) : <EOL> a = re . sub ( "<STR_LIT>" , "<STR_LIT>" , ( "<STR_LIT>" % matchobj . group ( <NUM_LIT:1> ) ) ) <EOL> if a == '<STR_LIT:\n>' : <EOL> a = "<STR_LIT>" <EOL> if a == '<STR_LIT:\r>' : <EOL> a = "<STR_LIT>" <EOL> if a == '<STR_LIT:\t>' : <EOL> a = "<STR_LIT>" <EOL> if a == '<STR_LIT>' : <EOL> a = '<STR_LIT>' <EOL> if a == '<STR_LIT>' : <EOL> a = '<STR_LIT>' <EOL> return self . escapes [ a ] <EOL> return re . sub ( settings . get ( '<STR_LIT>' ) , unescapes , code ) <EOL> def escapes ( matchobj ) : <EOL> a = matchobj . group ( <NUM_LIT:0> ) <EOL> if a == '<STR_LIT:\n>' : <EOL> a = "<STR_LIT>" <EOL> if a == '<STR_LIT:\r>' : <EOL> a = "<STR_LIT>" <EOL> if a == '<STR_LIT:\t>' : <EOL> a = "<STR_LIT>" <EOL> if a == '<STR_LIT>' : <EOL> a = '<STR_LIT>' <EOL> if a == '<STR_LIT>' : <EOL> a = '<STR_LIT>' <EOL> return '<STR_LIT:\\>' + self . escapes [ a ] <EOL> def indent ( n = None ) : <EOL> if n is not None : <EOL> ns . indent_level += n <EOL> return "<STR_LIT:U+0020>" * ns . indent_level <EOL> def interpolate ( matchobj ) : <EOL> if getattr ( str , '<STR_LIT>' , False ) : <EOL> key = ( matchobj . group ( <NUM_LIT:1> ) . decode ( '<STR_LIT>' ) ) . strip ( ) <EOL> else : <EOL> key = ( bytes ( matchobj . group ( <NUM_LIT:1> ) , "<STR_LIT:utf-8>" ) . decode ( ) ) . strip ( ) <EOL> return "<STR_LIT>" + unescape ( key ) + "<STR_LIT>" <EOL> def evaluate ( matchobj ) : <EOL> if getattr ( str , '<STR_LIT>' , False ) : <EOL> code = ( matchobj . group ( <NUM_LIT:1> ) . decode ( '<STR_LIT>' ) ) . strip ( ) <EOL> else : <EOL> code = ( bytes ( matchobj . group ( <NUM_LIT:1> ) , "<STR_LIT:utf-8>" ) . decode ( ) ) . strip ( ) <EOL> if code . startswith ( "<STR_LIT:end>" ) : <EOL> return "<STR_LIT>" + indent ( - <NUM_LIT:1> ) + "<STR_LIT>" <EOL> elif code . endswith ( '<STR_LIT::>' ) : <EOL> return "<STR_LIT>" + indent ( ) + unescape ( code ) + "<STR_LIT:\n>" + indent ( + <NUM_LIT:1> ) + "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" + indent ( ) + unescape ( code ) + "<STR_LIT:\n>" + indent ( ) + "<STR_LIT>" <EOL> def escape ( matchobj ) : <EOL> if getattr ( str , '<STR_LIT>' , False ) : <EOL> key = ( matchobj . group ( <NUM_LIT:1> ) . decode ( '<STR_LIT>' ) ) . strip ( ) <EOL> else : <EOL> key = ( bytes ( matchobj . group ( <NUM_LIT:1> ) , "<STR_LIT:utf-8>" ) . decode ( ) ) . strip ( ) <EOL> return "<STR_LIT>" + unescape ( key ) + "<STR_LIT>" <EOL> source = indent ( ) + '<STR_LIT>' + '<STR_LIT>' <EOL> source += indent ( ) + '<STR_LIT>' <EOL> source += indent ( ) + "<STR_LIT>" <EOL> src = re . sub ( settings . get ( "<STR_LIT>" ) , escapes , src ) <EOL> source += indent ( ) + "<STR_LIT>" + re . sub ( settings . get ( '<STR_LIT>' ) , escape , src ) + "<STR_LIT>" <EOL> source = re . sub ( settings . get ( '<STR_LIT>' ) , interpolate , source ) <EOL> source = re . sub ( settings . get ( '<STR_LIT>' ) , evaluate , source ) <EOL> if getattr ( str , '<STR_LIT>' , False ) : <EOL> source += indent ( ) + '<STR_LIT>' <EOL> else : <EOL> source += indent ( ) + '<STR_LIT>' <EOL> f = self . create_function ( settings . get ( "<STR_LIT>" ) <EOL> or "<STR_LIT>" , source ) <EOL> if data is not None : <EOL> return f ( data ) <EOL> return f <EOL> def create_function ( self , args , source ) : <EOL> source = "<STR_LIT>" + args + "<STR_LIT>" + source + "<STR_LIT:\n>" <EOL> ns = self . Namespace ( ) <EOL> try : <EOL> code = compile ( source , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exec ( code ) in globals ( ) , locals ( ) <EOL> except : <EOL> print ( source ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ns . func = func <EOL> def _wrap ( obj = { "<STR_LIT>" : "<STR_LIT>" } ) : <EOL> for i , k in enumerate ( obj ) : <EOL> if getattr ( ns . func , '<STR_LIT>' , False ) : <EOL> ns . func . func_globals [ k ] = obj [ k ] <EOL> else : <EOL> ns . func . __globals__ [ k ] = obj [ k ] <EOL> return ns . func ( obj ) <EOL> _wrap . source = source <EOL> return _wrap <EOL> def chain ( self ) : <EOL> """<STR_LIT>""" <EOL> self . chained = True <EOL> return self <EOL> def value ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _wrapped is not self . Null : <EOL> return self . _wrapped <EOL> else : <EOL> return self . obj <EOL> @ staticmethod <EOL> def makeStatic ( ) : <EOL> """<STR_LIT>""" <EOL> p = lambda value : inspect . ismethod ( value ) or inspect . isfunction ( value ) <EOL> for eachMethod in inspect . getmembers ( underscore , <EOL> predicate = p ) : <EOL> m = eachMethod [ <NUM_LIT:0> ] <EOL> if not hasattr ( _ , m ) : <EOL> def caller ( a ) : <EOL> def execute ( * args ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> r = getattr ( underscore ( args [ <NUM_LIT:0> ] ) , a ) ( ) <EOL> elif len ( args ) > <NUM_LIT:1> : <EOL> rargs = args [ <NUM_LIT:1> : ] <EOL> r = getattr ( underscore ( args [ <NUM_LIT:0> ] ) , a ) ( * rargs ) <EOL> else : <EOL> r = getattr ( underscore ( [ ] ) , a ) ( ) <EOL> return r <EOL> return execute <EOL> _ . __setattr__ ( m , caller ( m ) ) <EOL> _ . __setattr__ ( "<STR_LIT>" , underscore ) <EOL> _ . templateSettings = { } <EOL> underscore . makeStatic ( ) </s>
