<s> """<STR_LIT>""" <EOL> from airy . core . files import File <EOL> class ImageFile ( File ) : <EOL> """<STR_LIT>""" <EOL> def _get_width ( self ) : <EOL> return self . _get_image_dimensions ( ) [ <NUM_LIT:0> ] <EOL> width = property ( _get_width ) <EOL> def _get_height ( self ) : <EOL> return self . _get_image_dimensions ( ) [ <NUM_LIT:1> ] <EOL> height = property ( _get_height ) <EOL> def _get_image_dimensions ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> close = self . closed <EOL> self . open ( ) <EOL> self . _dimensions_cache = get_image_dimensions ( self , close = close ) <EOL> return self . _dimensions_cache <EOL> def get_image_dimensions ( file_or_path , close = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from PIL import ImageFile as PILImageFile <EOL> except ImportError : <EOL> import ImageFile as PILImageFile <EOL> p = PILImageFile . Parser ( ) <EOL> if hasattr ( file_or_path , '<STR_LIT>' ) : <EOL> file = file_or_path <EOL> file_pos = file . tell ( ) <EOL> file . seek ( <NUM_LIT:0> ) <EOL> else : <EOL> file = open ( file_or_path , '<STR_LIT:rb>' ) <EOL> close = True <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> data = file . read ( <NUM_LIT> ) <EOL> if not data : <EOL> break <EOL> p . feed ( data ) <EOL> if p . image : <EOL> return p . image . size <EOL> return None <EOL> finally : <EOL> if close : <EOL> file . close ( ) <EOL> else : <EOL> file . seek ( file_pos ) </s>
