<s> import os <EOL> from key import Key <EOL> from boto . file . simpleresultset import SimpleResultSet <EOL> from boto . s3 . bucketlistresultset import BucketListResultSet <EOL> class Bucket ( object ) : <EOL> def __init__ ( self , name , contained_key ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . contained_key = contained_key <EOL> def __iter__ ( self ) : <EOL> return iter ( BucketListResultSet ( self ) ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' + self . contained_key <EOL> def delete_key ( self , key_name , headers = None , <EOL> version_id = None , mfa_token = None ) : <EOL> """<STR_LIT>""" <EOL> os . remove ( key_name ) <EOL> def get_all_keys ( self , headers = None , ** params ) : <EOL> """<STR_LIT>""" <EOL> key = Key ( self . name , self . contained_key ) <EOL> return SimpleResultSet ( [ key ] ) <EOL> def get_key ( self , key_name , headers = None , version_id = None , <EOL> key_type = Key . KEY_REGULAR_FILE ) : <EOL> """<STR_LIT>""" <EOL> if key_name == '<STR_LIT:->' : <EOL> return Key ( self . name , '<STR_LIT:->' , key_type = Key . KEY_STREAM_READABLE ) <EOL> else : <EOL> fp = open ( key_name , '<STR_LIT:rb>' ) <EOL> return Key ( self . name , key_name , fp ) <EOL> def new_key ( self , key_name = None , key_type = Key . KEY_REGULAR_FILE ) : <EOL> """<STR_LIT>""" <EOL> if key_name == '<STR_LIT:->' : <EOL> return Key ( self . name , '<STR_LIT:->' , key_type = Key . KEY_STREAM_WRITABLE ) <EOL> else : <EOL> dir_name = os . path . dirname ( key_name ) <EOL> if dir_name and not os . path . exists ( dir_name ) : <EOL> os . makedirs ( dir_name ) <EOL> fp = open ( key_name , '<STR_LIT:wb>' ) <EOL> return Key ( self . name , key_name , fp ) </s>
