<s> from __future__ import absolute_import , unicode_literals , division <EOL> import collections <EOL> import logging <EOL> from psd_tools . utils import read_fmt , trimmed_repr , read_pascal_string , pad <EOL> from psd_tools . exceptions import Error <EOL> from psd_tools . constants import ImageResourceID <EOL> logger = logging . getLogger ( __name__ ) <EOL> _ImageResource = collections . namedtuple ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class ImageResource ( _ImageResource ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . resource_id , ImageResourceID . name_of ( self . resource_id ) , <EOL> self . name , trimmed_repr ( self . data ) <EOL> ) <EOL> def read ( fp , encoding ) : <EOL> """<STR_LIT>""" <EOL> logger . debug ( "<STR_LIT>" ) <EOL> resource_section_length = read_fmt ( "<STR_LIT:I>" , fp ) [ <NUM_LIT:0> ] <EOL> position = fp . tell ( ) <EOL> end_position = position + resource_section_length <EOL> blocks = [ ] <EOL> while fp . tell ( ) < end_position : <EOL> block = _read_block ( fp , encoding ) <EOL> logger . debug ( "<STR_LIT>" , block ) <EOL> blocks . append ( block ) <EOL> return blocks <EOL> def _read_block ( fp , encoding ) : <EOL> """<STR_LIT>""" <EOL> sig = fp . read ( <NUM_LIT:4> ) <EOL> if not sig in [ b'<STR_LIT>' , b'<STR_LIT>' ] : <EOL> raise Error ( "<STR_LIT>" % sig ) <EOL> resource_id = read_fmt ( "<STR_LIT:H>" , fp ) [ <NUM_LIT:0> ] <EOL> name = read_pascal_string ( fp , encoding , <NUM_LIT:2> ) <EOL> data_size = pad ( read_fmt ( "<STR_LIT:I>" , fp ) [ <NUM_LIT:0> ] , <NUM_LIT:2> ) <EOL> data = fp . read ( data_size ) <EOL> return ImageResource ( resource_id , name , data ) </s>
