#NEWLINE# def storage_uri( uri_str , default_scheme = 'file' , debug = 0 , validate = True , bucket_storage_uri_class = BucketStorageUri , suppress_consec_slashes = True , is_latest = False ) : #NEWLINE# #INDENT# "\n    Instantiate a StorageUri from a URI string.\n\n    :type uri_str: string\n    :param uri_str: URI naming bucket + optional object.\n    :type default_scheme: string\n    :param default_scheme: default scheme for scheme-less URIs.\n    :type debug: int\n    :param debug: debug level to pass in to boto connection (range 0..2).\n    :type validate: bool\n    :param validate: whether to check for bucket name validity.\n    :type bucket_storage_uri_class: BucketStorageUri interface.\n    :param bucket_storage_uri_class: Allows mocking for unit tests.\n    :param suppress_consec_slashes: If provided, controls whether\n        consecutive slashes will be suppressed in key paths.\n    :type is_latest: bool\n    :param is_latest: whether this versioned object represents the\n        current version.\n\n    We allow validate to be disabled to allow caller\n    to implement bucket-level wildcarding (outside the boto library;\n    see gsutil).\n\n    :rtype: :class:`boto.StorageUri` subclass\n    :return: StorageUri subclass for given URI.\n\n    ``uri_str`` must be one of the following formats:\n\n    * gs://bucket/name\n    * gs://bucket/name#ver\n    * s3://bucket/name\n    * gs://bucket\n    * s3://bucket\n    * filename (which could be a Unix path like /a/b/c or a Windows path like\n      C:\x07\x08\\c)\n\n    The last example uses the default scheme ('file', unless overridden).\n    " #NEWLINE# version_id = None #NEWLINE# generation = None #NEWLINE# end_scheme_idx = uri_str . find ( '://' ) #NEWLINE# if ( end_scheme_idx == ( - 1 ) ) : #NEWLINE# #INDENT# scheme = default_scheme . lower ( ) #NEWLINE# path = uri_str #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# scheme = uri_str [ 0 : end_scheme_idx ] . lower ( ) #NEWLINE# path = uri_str [ ( end_scheme_idx + 3 ) : ] #NEWLINE# #UNINDENT# if ( scheme not in [ 'file' , 's3' , 'gs' ] ) : #NEWLINE# #INDENT# raise InvalidUriError ( ( 'Unrecognized scheme "%s"' % scheme ) ) #NEWLINE# #UNINDENT# if ( scheme == 'file' ) : #NEWLINE# #INDENT# is_stream = False #NEWLINE# if ( path == '-' ) : #NEWLINE# #INDENT# is_stream = True #NEWLINE# #UNINDENT# return FileStorageUri ( path , debug , is_stream ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# path_parts = path . split ( '/' , 1 ) #NEWLINE# bucket_name = path_parts [ 0 ] #NEWLINE# object_name = '' #NEWLINE# if ( validate and bucket_name and ( ( not BUCKET_NAME_RE . match ( bucket_name ) ) or TOO_LONG_DNS_NAME_COMP . search ( bucket_name ) ) ) : #NEWLINE# #INDENT# raise InvalidUriError ( ( 'Invalid bucket name in URI "%s"' % uri_str ) ) #NEWLINE# #UNINDENT# if ( scheme == 'gs' ) : #NEWLINE# #INDENT# match = GENERATION_RE . search ( path ) #NEWLINE# if match : #NEWLINE# #INDENT# md = match . groupdict ( ) #NEWLINE# versionless_uri_str = md [ 'versionless_uri_str' ] #NEWLINE# path_parts = versionless_uri_str . split ( '/' , 1 ) #NEWLINE# generation = int ( md [ 'generation' ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( scheme == 's3' ) : #NEWLINE# #INDENT# match = VERSION_RE . search ( path ) #NEWLINE# if match : #NEWLINE# #INDENT# md = match . groupdict ( ) #NEWLINE# versionless_uri_str = md [ 'versionless_uri_str' ] #NEWLINE# path_parts = versionless_uri_str . split ( '/' , 1 ) #NEWLINE# version_id = md [ 'version_id' ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise InvalidUriError ( ( 'Unrecognized scheme "%s"' % scheme ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( path_parts ) > 1 ) : #NEWLINE# #INDENT# object_name = path_parts [ 1 ] #NEWLINE# #UNINDENT# return bucket_storage_uri_class ( scheme , bucket_name , object_name , debug , suppress_consec_slashes = suppress_consec_slashes , version_id = version_id , generation = generation , is_latest = is_latest )