@contextmanager<EOL>def open(s3_url, mode='<STR_LIT:r>', s3_connection=None, **kwargs):
connection = s3_connection or boto.connect_s3(**kwargs)<EOL>bucket_name, key_name = url_split(s3_url)<EOL>try:<EOL><INDENT>bucket = connection.get_bucket(bucket_name)<EOL><DEDENT>except boto.exception.S3ResponseError:<EOL><INDENT>raise BucketNotFoundError('<STR_LIT>' % bucket_name)<EOL><DEDENT>f = NamedTemporaryFile()<EOL>try:<EOL><INDENT>if '<STR_LIT:w>' in mode.lower():<EOL><INDENT>s3_key = bucket.new_key(key_name)<EOL>yield f<EOL>f.seek(<NUM_LIT:0>)<EOL>s3_key.set_contents_from_file(f)<EOL><DEDENT>else:<EOL><INDENT>s3_key = bucket.get_key(key_name)<EOL>if not s3_key:<EOL><INDENT>raise KeyNotFoundError('<STR_LIT>' % s3_url)<EOL><DEDENT>s3_key.get_file(f)<EOL>f.seek(<NUM_LIT:0>)<EOL>yield f<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>f.close()<EOL><DEDENT>
Open S3 url, returning a File Object.

    S3 connection:
        1. Can be specified directly by `s3_connection`.
        2. `boto.connect_s3` will be used supplying all `kwargs`.
           - `aws_access_key_id` and `aws_secret_access_key`.
           - `profile_name` - recommended.
              See:
              http://boto.readthedocs.org/en/latest/boto_config_tut.html