File tree Expand file tree Collapse file tree 1 file changed +20
-7
lines changed
storage/google/cloud/storage Expand file tree Collapse file tree 1 file changed +20
-7
lines changed Original file line number Diff line number Diff line change 1818"""
1919
2020import base64
21- import re
2221from hashlib import md5
2322
2423
24+ def _validate_name (name ):
25+ """Pre-flight ``Bucket`` name validation.
26+
27+ :type name: str or :data:`NoneType`
28+ :param name: Proposed bucket name.
29+
30+ :rtype: str or :data:`NoneType`
31+ :returns: ``name`` if valid.
32+ """
33+ if name is None :
34+ return
35+
36+ # The first and las characters must be alphanumeric.
37+ if not all ([name [0 ].isalnum (), name [- 1 ].isalnum ()]):
38+ raise ValueError (
39+ 'Bucket names must start and end with a number or letter.' )
40+ return name
41+
42+
2543class _PropertyMixin (object ):
2644 """Abstract mixin for cloud storage classes with associated propertties.
2745
@@ -35,12 +53,7 @@ class _PropertyMixin(object):
3553 """
3654
3755 def __init__ (self , name = None ):
38- if name is None or (re .match (r'\w' , name [0 ]) and
39- re .match (r'\w' , name [- 1 ])):
40- self .name = name
41- else :
42- raise ValueError (
43- 'Bucket names must start and end with a number or letter.' )
56+ self .name = _validate_name (name )
4457 self ._properties = {}
4558 self ._changes = set ()
4659
You can’t perform that action at this time.
0 commit comments