<s> from __future__ import absolute_import <EOL> from itertools import chain <EOL> from openpyxl . descriptors . serialisable import Serialisable <EOL> from openpyxl . descriptors import ( <EOL> MinMax , <EOL> Typed , <EOL> String , <EOL> Strict , <EOL> ) <EOL> from openpyxl . worksheet import Worksheet <EOL> from openpyxl . utils import ( <EOL> get_column_letter , <EOL> range_to_tuple , <EOL> quote_sheetname <EOL> ) <EOL> class DummyWorksheet : <EOL> def __init__ ( self , title ) : <EOL> self . title = title <EOL> class Reference ( Strict ) : <EOL> """<STR_LIT>""" <EOL> min_row = MinMax ( min = <NUM_LIT:1> , max = <NUM_LIT> , expected_type = int ) <EOL> max_row = MinMax ( min = <NUM_LIT:1> , max = <NUM_LIT> , expected_type = int ) <EOL> min_col = MinMax ( min = <NUM_LIT:1> , max = <NUM_LIT> , expected_type = int ) <EOL> max_col = MinMax ( min = <NUM_LIT:1> , max = <NUM_LIT> , expected_type = int ) <EOL> range_string = String ( allow_none = True ) <EOL> def __init__ ( self , <EOL> worksheet = None , <EOL> min_col = None , <EOL> min_row = None , <EOL> max_col = None , <EOL> max_row = None , <EOL> range_string = None <EOL> ) : <EOL> if range_string is not None : <EOL> sheetname , boundaries = range_to_tuple ( range_string ) <EOL> min_col , min_row , max_col , max_row = boundaries <EOL> worksheet = DummyWorksheet ( sheetname ) <EOL> self . worksheet = worksheet <EOL> self . min_col = min_col <EOL> self . min_row = min_row <EOL> if max_col is None : <EOL> max_col = min_col <EOL> self . max_col = max_col <EOL> if max_row is None : <EOL> max_row = min_row <EOL> self . max_row = max_row <EOL> def __repr__ ( self ) : <EOL> fmt = "<STR_LIT>" <EOL> if ( self . min_col == self . max_col <EOL> and self . min_row == self . max_row ) : <EOL> fmt = "<STR_LIT>" <EOL> return fmt . format ( self . sheetname , <EOL> get_column_letter ( self . min_col ) , self . min_row , <EOL> get_column_letter ( self . max_col ) , self . max_row <EOL> ) <EOL> def __str__ ( self ) : <EOL> return repr ( self ) <EOL> def __len__ ( self ) : <EOL> if self . min_row == self . max_row : <EOL> return <NUM_LIT:1> + self . max_col - self . min_col <EOL> return <NUM_LIT:1> + self . max_row - self . min_row <EOL> @ property <EOL> def rows ( self ) : <EOL> """<STR_LIT>""" <EOL> for row in range ( self . min_row , self . max_row + <NUM_LIT:1> ) : <EOL> yield tuple ( '<STR_LIT>' % ( get_column_letter ( col ) , row ) <EOL> for col in range ( self . min_col , self . max_col + <NUM_LIT:1> ) ) <EOL> @ property <EOL> def cols ( self ) : <EOL> """<STR_LIT>""" <EOL> for col in range ( self . min_col , self . max_col + <NUM_LIT:1> ) : <EOL> yield tuple ( '<STR_LIT>' % ( get_column_letter ( col ) , row ) <EOL> for row in range ( self . min_row , self . max_row + <NUM_LIT:1> ) ) <EOL> @ property <EOL> def cells ( self ) : <EOL> """<STR_LIT>""" <EOL> return chain . from_iterable ( self . cols ) <EOL> def pop ( self ) : <EOL> """<STR_LIT>""" <EOL> cell = next ( self . cells ) <EOL> if self . min_row == self . max_row : <EOL> self . min_col += <NUM_LIT:1> <EOL> else : <EOL> self . min_row += <NUM_LIT:1> <EOL> return cell <EOL> @ property <EOL> def sheetname ( self ) : <EOL> return quote_sheetname ( self . worksheet . title ) </s>
