<s> import itertools <EOL> import string <EOL> class XCursor ( object ) : <EOL> def __init__ ( self , sheet , headingrow = None ) : <EOL> self . headingrow = headingrow <EOL> self . sheet = sheet <EOL> def num_rows ( self ) : <EOL> return self . sheet . nrows <EOL> def num_cols ( self ) : <EOL> if self . headingrow is None : <EOL> return len ( self . sheet_row ( <NUM_LIT:0> ) ) <EOL> else : <EOL> return len ( self . sheet_row ( self . headingrow ) ) <EOL> def sheet_row ( self , n ) : <EOL> return [ c . value for c in self . sheet . row ( n ) ] <EOL> def keys ( self ) : <EOL> if self . headingrow is not None : <EOL> return self . sheet_row ( self . headingrow ) <EOL> else : <EOL> u = string . ascii_uppercase <EOL> return [ '<STR_LIT>' . join ( r ) for idx , r in <EOL> enumerate ( itertools . chain ( u , itertools . product ( u , u ) ) ) <EOL> if idx < self . num_cols ( ) ] <EOL> def __iter__ ( self ) : <EOL> start = self . headingrow + <NUM_LIT:1> if self . headingrow is not None else <NUM_LIT:0> <EOL> return ( self . sheet_row ( n ) for n in range ( start , self . num_rows ( ) ) ) <EOL> class CSVCursor ( XCursor ) : <EOL> def sheet_row ( self , n ) : <EOL> return self . sheet [ n ] <EOL> def num_rows ( self ) : <EOL> return len ( self . sheet ) </s>
