def cat(<EOL>self,<EOL>source,<EOL>buffersize=None,<EOL>memsize=<NUM_LIT:2> ** <NUM_LIT>,<EOL>compressed=False,<EOL>encoding='<STR_LIT>',<EOL>raw=False,<EOL>):
assert self._is_s3(source) or isinstance(source, Key), '<STR_LIT>'<EOL>key = self._get_key(source) if not isinstance(source, Key) else source<EOL>compressed = (compressed or key.name.endswith('<STR_LIT>')) and not raw<EOL>if compressed:<EOL><INDENT>decompress = zlib.decompressobj(<NUM_LIT:16> + zlib.MAX_WBITS)<EOL><DEDENT>size = <NUM_LIT:0><EOL>bytes_read = <NUM_LIT:0><EOL>err = None<EOL>undecoded = '<STR_LIT>'<EOL>if key:<EOL><INDENT>for i in range(<NUM_LIT:100>):<EOL><INDENT>obj = self.s3.Object(key.bucket.name, key.name)<EOL>buffersize = buffersize if buffersize is not None else <NUM_LIT:2> ** <NUM_LIT:20><EOL>if not size:<EOL><INDENT>size = obj.content_length<EOL><DEDENT>elif size != obj.content_length:<EOL><INDENT>raise AwsError('<STR_LIT>')<EOL><DEDENT>r = obj.get(Range="<STR_LIT>".format(bytes_read))<EOL>try:<EOL><INDENT>while bytes_read < size:<EOL><INDENT>if size - bytes_read > buffersize:<EOL><INDENT>bytes = r['<STR_LIT>'].read(amt=buffersize)<EOL><DEDENT>else:<EOL><INDENT>bytes = r['<STR_LIT>'].read()<EOL><DEDENT>if compressed:<EOL><INDENT>s = decompress.decompress(bytes)<EOL><DEDENT>else:<EOL><INDENT>s = bytes<EOL><DEDENT>if encoding and not raw:<EOL><INDENT>try:<EOL><INDENT>decoded = undecoded + s.decode(encoding)<EOL>undecoded = '<STR_LIT>'<EOL>yield decoded<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>undecoded += s<EOL>if len(undecoded) > memsize:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>yield s<EOL><DEDENT>bytes_read += len(bytes)<EOL><DEDENT><DEDENT>except zlib.error:<EOL><INDENT>logger.error("<STR_LIT>", key.name)<EOL>raise<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>raise<EOL><DEDENT>except Exception:<EOL><INDENT>err = True<EOL>pass<EOL><DEDENT>if size <= bytes_read:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if size != bytes_read:<EOL><INDENT>if err:<EOL><INDENT>raise Exception<EOL><DEDENT>else:<EOL><INDENT>raise AwsError('<STR_LIT>' % source.name)<EOL><DEDENT><DEDENT>if undecoded:<EOL><INDENT>assert encoding is not None  <EOL>decoded = undecoded.decode(encoding)<EOL>yield decoded<EOL><DEDENT><DEDENT>
Returns an iterator for the data in the key or nothing if the key
doesn't exist. Decompresses data on the fly (if compressed is True
or key ends with .gz) unless raw is True. Pass None for encoding to
skip encoding.