<s> class CIndexedRowset ( dict ) : <EOL> __guid__ = "<STR_LIT>" <EOL> def __init__ ( self , header , columnName ) : <EOL> self . header = header <EOL> self . columnName = columnName <EOL> class CFilterRowset ( dict ) : <EOL> __guid__ = "<STR_LIT>" <EOL> def __setstate__ ( self , data ) : <EOL> self . __dict__ . update ( data ) <EOL> def __getstate__ ( self ) : <EOL> return { "<STR_LIT>" : self . header , "<STR_LIT>" : self . columnName } <EOL> class CRowset ( list ) : <EOL> __guid__ = "<STR_LIT>" <EOL> __passbyvalue__ = <NUM_LIT:1> <EOL> def __init__ ( self , header , rows ) : <EOL> list . __init__ ( self , rows ) <EOL> self . header = header <EOL> def Sort ( self , columnName , caseInsensitive = False ) : <EOL> ix = self . header . Keys ( ) . index ( columnName ) <EOL> if caseInsensitive : <EOL> self . sort ( key = lambda x : x [ ix ] . upper ( ) ) <EOL> else : <EOL> self . sort ( key = lambda x : x [ ix ] ) <EOL> def Index ( self , columnName ) : <EOL> d = CIndexedRowset ( self . header , columnName ) <EOL> if "<STR_LIT:.>" in columnName : <EOL> keys = columnName . split ( "<STR_LIT:.>" ) <EOL> c = <NUM_LIT:0> <EOL> for row in self : <EOL> combinedKey = [ ] <EOL> for key in keys : <EOL> combinedKey . append ( row [ key ] ) <EOL> d [ tuple ( combinedKey ) ] = row <EOL> return d <EOL> else : <EOL> pass <EOL> def Filter ( self , columnName , indexName = None ) : <EOL> fr = CFilterRowset ( self . header , columnName ) <EOL> c = <NUM_LIT:0> <EOL> keyIdx = fr . header . Keys ( ) . index ( columnName ) <EOL> _get = dict . get <EOL> if indexName is None : <EOL> for row in self : <EOL> key = row [ keyIdx ] <EOL> grp = _get ( fr , key ) <EOL> if grp is None : <EOL> fr [ key ] = [ row ] <EOL> else : <EOL> grp . append ( row ) <EOL> else : <EOL> key2Idx = fr . header . Keys ( ) . index ( indexName ) <EOL> for row in self : <EOL> key = row [ keyIdx ] <EOL> key2 = row [ key2Idx ] <EOL> if key not in fr : <EOL> fr [ key ] = { } <EOL> fr [ key ] [ key2 ] = row <EOL> return fr </s>
