Skip to content

Commit aa684be

Browse files
committed
Merge pull request #737 from dhermes/bucket-make-name-first
Making name= the first argument in Bucket() constructor.
2 parents 99616fa + 453c0bf commit aa684be

File tree

5 files changed

+77
-74
lines changed

5 files changed

+77
-74
lines changed

gcloud/storage/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def set_default_bucket(bucket=None):
8282
connection = get_default_connection()
8383

8484
if bucket_name is not None and connection is not None:
85-
bucket = Bucket(connection=connection, name=bucket_name)
85+
bucket = Bucket(bucket_name, connection=connection)
8686

8787
if bucket is not None:
8888
_implicit_environ._DEFAULTS.bucket = bucket

gcloud/storage/bucket.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ def get_items_from_response(self, response):
7575
class Bucket(_PropertyMixin):
7676
"""A class representing a Bucket on Cloud Storage.
7777
78+
:type name: string
79+
:param name: The name of the bucket.
80+
7881
:type connection: :class:`gcloud.storage.connection.Connection`
7982
:param connection: The connection to use when sending requests.
8083
81-
:type name: string
82-
:param name: The name of the bucket.
84+
:type properties: dictionary or ``NoneType``
85+
:param properties: The properties associated with the bucket.
8386
"""
8487
_iterator_class = _BlobIterator
8588

@@ -89,7 +92,7 @@ class Bucket(_PropertyMixin):
8992
# ACL rules are lazily retrieved.
9093
_acl = _default_object_acl = None
9194

92-
def __init__(self, connection=None, name=None, properties=None):
95+
def __init__(self, name=None, connection=None, properties=None):
9396
if name is None and properties is not None:
9497
name = properties.get('name')
9598
super(Bucket, self).__init__(name=name, properties=properties)

gcloud/storage/test_acl.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def test_reload_eager_missing(self):
541541
NAME = 'name'
542542
ROLE = 'role'
543543
connection = _Connection({})
544-
bucket = _Bucket(connection, NAME)
544+
bucket = _Bucket(NAME, connection)
545545
acl = self._makeOne(bucket)
546546
acl.loaded = True
547547
acl.entity('allUsers', ROLE)
@@ -556,7 +556,7 @@ def test_reload_eager_empty(self):
556556
NAME = 'name'
557557
ROLE = 'role'
558558
connection = _Connection({'items': []})
559-
bucket = _Bucket(connection, NAME)
559+
bucket = _Bucket(NAME, connection)
560560
acl = self._makeOne(bucket)
561561
acl.loaded = True
562562
acl.entity('allUsers', ROLE)
@@ -572,7 +572,7 @@ def test_reload_eager_nonempty(self):
572572
ROLE = 'role'
573573
connection = _Connection(
574574
{'items': [{'entity': 'allUsers', 'role': ROLE}]})
575-
bucket = _Bucket(connection, NAME)
575+
bucket = _Bucket(NAME, connection)
576576
acl = self._makeOne(bucket)
577577
acl.loaded = True
578578
self.assertTrue(acl.reload() is acl)
@@ -587,7 +587,7 @@ def test_reload_lazy(self):
587587
ROLE = 'role'
588588
connection = _Connection(
589589
{'items': [{'entity': 'allUsers', 'role': ROLE}]})
590-
bucket = _Bucket(connection, NAME)
590+
bucket = _Bucket(NAME, connection)
591591
acl = self._makeOne(bucket)
592592
self.assertTrue(acl.reload() is acl)
593593
self.assertEqual(list(acl), [{'entity': 'allUsers', 'role': ROLE}])
@@ -599,7 +599,7 @@ def test_reload_lazy(self):
599599
def test_save_none_set_none_passed(self):
600600
NAME = 'name'
601601
connection = _Connection()
602-
bucket = _Bucket(connection, NAME)
602+
bucket = _Bucket(NAME, connection)
603603
acl = self._makeOne(bucket)
604604
self.assertTrue(acl.save() is acl)
605605
kw = connection._requested
@@ -608,7 +608,7 @@ def test_save_none_set_none_passed(self):
608608
def test_save_existing_missing_none_passed(self):
609609
NAME = 'name'
610610
connection = _Connection({})
611-
bucket = _Bucket(connection, NAME)
611+
bucket = _Bucket(NAME, connection)
612612
acl = self._makeOne(bucket)
613613
acl.loaded = True
614614
self.assertTrue(acl.save() is acl)
@@ -625,7 +625,7 @@ def test_save_no_arg(self):
625625
ROLE = 'role'
626626
AFTER = [{'entity': 'allUsers', 'role': ROLE}]
627627
connection = _Connection({'acl': AFTER})
628-
bucket = _Bucket(connection, NAME)
628+
bucket = _Bucket(NAME, connection)
629629
acl = self._makeOne(bucket)
630630
acl.loaded = True
631631
acl.entity('allUsers').grant(ROLE)
@@ -645,7 +645,7 @@ def test_save_w_arg(self):
645645
STICKY = {'entity': 'allUsers', 'role': ROLE2}
646646
new_acl = [{'entity': 'allUsers', 'role': ROLE1}]
647647
connection = _Connection({'acl': [STICKY] + new_acl})
648-
bucket = _Bucket(connection, NAME)
648+
bucket = _Bucket(NAME, connection)
649649
acl = self._makeOne(bucket)
650650
acl.loaded = True
651651
self.assertTrue(acl.save(new_acl) is acl)
@@ -666,7 +666,7 @@ def test_clear(self):
666666
ROLE2 = 'role2'
667667
STICKY = {'entity': 'allUsers', 'role': ROLE2}
668668
connection = _Connection({'acl': [STICKY]})
669-
bucket = _Bucket(connection, NAME)
669+
bucket = _Bucket(NAME, connection)
670670
acl = self._makeOne(bucket)
671671
acl.loaded = True
672672
acl.entity('allUsers', ROLE1)
@@ -703,7 +703,7 @@ def test_reload_eager_missing(self):
703703
ROLE = 'role'
704704
after = {}
705705
connection = _Connection(after)
706-
bucket = _Bucket(connection, NAME)
706+
bucket = _Bucket(NAME, connection)
707707
blob = _Blob(bucket, BLOB_NAME)
708708
acl = self._makeOne(blob)
709709
acl.loaded = True
@@ -717,7 +717,7 @@ def test_reload_eager_empty(self):
717717
ROLE = 'role'
718718
after = {'items': []}
719719
connection = _Connection(after)
720-
bucket = _Bucket(connection, NAME)
720+
bucket = _Bucket(NAME, connection)
721721
blob = _Blob(bucket, BLOB_NAME)
722722
acl = self._makeOne(blob)
723723
acl.loaded = True
@@ -731,7 +731,7 @@ def test_reload_eager_nonempty(self):
731731
ROLE = 'role'
732732
after = {'items': [{'entity': 'allUsers', 'role': ROLE}]}
733733
connection = _Connection(after)
734-
bucket = _Bucket(connection, NAME)
734+
bucket = _Bucket(NAME, connection)
735735
blob = _Blob(bucket, BLOB_NAME)
736736
acl = self._makeOne(blob)
737737
acl.loaded = True
@@ -748,7 +748,7 @@ def test_reload_lazy(self):
748748
ROLE = 'role'
749749
after = {'items': [{'entity': 'allUsers', 'role': ROLE}]}
750750
connection = _Connection(after)
751-
bucket = _Bucket(connection, NAME)
751+
bucket = _Bucket(NAME, connection)
752752
blob = _Blob(bucket, BLOB_NAME)
753753
acl = self._makeOne(blob)
754754
self.assertTrue(acl.reload() is acl)
@@ -763,7 +763,7 @@ def test_save_none_set_none_passed(self):
763763
NAME = 'name'
764764
BLOB_NAME = 'blob-name'
765765
connection = _Connection()
766-
bucket = _Bucket(connection, NAME)
766+
bucket = _Bucket(NAME, connection)
767767
blob = _Blob(bucket, BLOB_NAME)
768768
acl = self._makeOne(blob)
769769
self.assertTrue(acl.save() is acl)
@@ -775,7 +775,7 @@ def test_save_existing_missing_none_passed(self):
775775
NAME = 'name'
776776
BLOB_NAME = 'blob-name'
777777
connection = _Connection({'foo': 'Foo'})
778-
bucket = _Bucket(connection, NAME)
778+
bucket = _Bucket(NAME, connection)
779779
blob = _Blob(bucket, BLOB_NAME)
780780
acl = self._makeOne(blob)
781781
acl.loaded = True
@@ -791,7 +791,7 @@ def test_save_existing_set_none_passed(self):
791791
NAME = 'name'
792792
BLOB_NAME = 'blob-name'
793793
connection = _Connection({'foo': 'Foo', 'acl': []})
794-
bucket = _Bucket(connection, NAME)
794+
bucket = _Bucket(NAME, connection)
795795
blob = _Blob(bucket, BLOB_NAME)
796796
acl = self._makeOne(blob)
797797
acl.loaded = True
@@ -809,7 +809,7 @@ def test_save_existing_set_new_passed(self):
809809
ROLE = 'role'
810810
new_acl = [{'entity': 'allUsers', 'role': ROLE}]
811811
connection = _Connection({'foo': 'Foo', 'acl': new_acl})
812-
bucket = _Bucket(connection, NAME)
812+
bucket = _Bucket(NAME, connection)
813813
blob = _Blob(bucket, BLOB_NAME)
814814
acl = self._makeOne(blob)
815815
acl.loaded = True
@@ -828,7 +828,7 @@ def test_clear(self):
828828
BLOB_NAME = 'blob-name'
829829
ROLE = 'role'
830830
connection = _Connection({'foo': 'Foo', 'acl': []})
831-
bucket = _Bucket(connection, NAME)
831+
bucket = _Bucket(NAME, connection)
832832
blob = _Blob(bucket, BLOB_NAME)
833833
acl = self._makeOne(blob)
834834
acl.loaded = True
@@ -860,9 +860,9 @@ def path(self):
860860

861861
class _Bucket(object):
862862

863-
def __init__(self, connection, name):
864-
self.connection = connection
863+
def __init__(self, name, connection):
865864
self.name = name
865+
self.connection = connection
866866

867867
@property
868868
def path(self):

0 commit comments

Comments
 (0)