<s> """<STR_LIT>""" <EOL> from gcloud . _helpers import _LocalStack <EOL> from gcloud . client import JSONClient <EOL> from gcloud . exceptions import NotFound <EOL> from gcloud . iterator import Iterator <EOL> from gcloud . storage . batch import Batch <EOL> from gcloud . storage . bucket import Bucket <EOL> from gcloud . storage . connection import Connection <EOL> class Client ( JSONClient ) : <EOL> """<STR_LIT>""" <EOL> _connection_class = Connection <EOL> def __init__ ( self , project = None , credentials = None , http = None ) : <EOL> self . _connection = None <EOL> super ( Client , self ) . __init__ ( project = project , credentials = credentials , <EOL> http = http ) <EOL> self . _batch_stack = _LocalStack ( ) <EOL> @ property <EOL> def connection ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . current_batch is not None : <EOL> return self . current_batch <EOL> else : <EOL> return self . _connection <EOL> @ connection . setter <EOL> def connection ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if self . _connection is not None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . _connection = value <EOL> def _push_batch ( self , batch ) : <EOL> """<STR_LIT>""" <EOL> self . _batch_stack . push ( batch ) <EOL> def _pop_batch ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _batch_stack . pop ( ) <EOL> @ property <EOL> def current_batch ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _batch_stack . top <EOL> def bucket ( self , bucket_name ) : <EOL> """<STR_LIT>""" <EOL> return Bucket ( client = self , name = bucket_name ) <EOL> def batch ( self ) : <EOL> """<STR_LIT>""" <EOL> return Batch ( client = self ) <EOL> def get_bucket ( self , bucket_name ) : <EOL> """<STR_LIT>""" <EOL> bucket = Bucket ( self , name = bucket_name ) <EOL> bucket . reload ( client = self ) <EOL> return bucket <EOL> def lookup_bucket ( self , bucket_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . get_bucket ( bucket_name ) <EOL> except NotFound : <EOL> return None <EOL> def create_bucket ( self , bucket_name ) : <EOL> """<STR_LIT>""" <EOL> bucket = Bucket ( self , name = bucket_name ) <EOL> bucket . create ( client = self ) <EOL> return bucket <EOL> def list_buckets ( self , max_results = None , page_token = None , prefix = None , <EOL> projection = '<STR_LIT>' , fields = None ) : <EOL> """<STR_LIT>""" <EOL> extra_params = { '<STR_LIT>' : self . project } <EOL> if max_results is not None : <EOL> extra_params [ '<STR_LIT>' ] = max_results <EOL> if prefix is not None : <EOL> extra_params [ '<STR_LIT>' ] = prefix <EOL> extra_params [ '<STR_LIT>' ] = projection <EOL> if fields is not None : <EOL> extra_params [ '<STR_LIT>' ] = fields <EOL> result = _BucketIterator ( client = self , <EOL> extra_params = extra_params ) <EOL> if page_token is not None : <EOL> result . next_page_token = page_token <EOL> return result <EOL> class _BucketIterator ( Iterator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client , extra_params = None ) : <EOL> super ( _BucketIterator , self ) . __init__ ( client = client , path = '<STR_LIT>' , <EOL> extra_params = extra_params ) <EOL> def get_items_from_response ( self , response ) : <EOL> """<STR_LIT>""" <EOL> for item in response . get ( '<STR_LIT>' , [ ] ) : <EOL> name = item . get ( '<STR_LIT:name>' ) <EOL> bucket = Bucket ( self . client , name ) <EOL> bucket . _set_properties ( item ) <EOL> yield bucket </s>
