
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#  SSK"J$r$  \RJ                  (       a  \&r'\
RP                  " S5      r)Sr* " S S\+5      r, " S S\,5      r-S r. " S S\,5      r/ " S  S!\'5      r0     S#S" jr1g)$z1Wildcard iterator class and supporting functions.    )absolute_import)print_function)division)unicode_literalsN)BucketListingBucket)BucketListingObject)BucketListingPrefix)AccessDeniedException)CloudApi)NotFoundException)CommandException)ContainsWildcard)GenerationFromUrlAndString)StorageUrlFromString)StripOneSlash)WILDCARD_REGEX)storage_v1_messages)UTF8)FixWindowsEncodingIfNeeded)PrintableStrz (?P<before>.*?)\*\*(?P<after>.*)a\  Invalid Unicode path encountered (%s). gsutil cannot proceed with such files present. Please remove or rename this file and try again. NOTE: the path printed above replaces the problematic characters with a hex-encoded printable representation. For more details (including how to convert to a gsutil-compatible encoding) see `gsutil help encoding`.c                       \ rS rSrSrS rSrg)WildcardIterator?   zClass for iterating over Google Cloud Storage strings containing wildcards.

The base class is abstract; you should instantiate using the
wildcard_iterator() static factory method, which chooses the right
implementation depending on the base string.
c                 4    SU R                   R                  -  $ )z2Returns string representation of WildcardIterator.zWildcardIterator(%s))wildcard_url
url_stringselfs    *platform/gsutil/gslib/wildcard_iterator.py__repr__WildcardIterator.__repr__I   s    !D$5$5$@$@@@     N)__name__
__module____qualname____firstlineno____doc__r    __static_attributes__r#   r"   r   r   r   ?   s    Ar"   r   c                       \ rS rSrSr   SS jr  SS jrS rS rS r	SS	 jr
SS
 jrSS jrS rSS jrSS jrSS jrSrg)CloudWildcardIteratorN   aL  WildcardIterator subclass for buckets, bucket subdirs and objects.

Iterates over BucketListingRef matching the Url string wildcard. It's
much more efficient to first get metadata that's available in the Bucket
(for example to get the name and size of each object), because that
information is available in the object list results.
Nc                 z    Xl         X0l        X l        X@l        U=(       d    [        R
                  " 5       U l        g)aU  Instantiates an iterator that matches the wildcard URL.

Args:
  wildcard_url: CloudUrl that contains the wildcard to iterate.
  gsutil_api: Cloud storage interface.  Passed in for thread safety, also
              settable for testing/mocking.
  all_versions: If true, the iterator yields all versions of objects
                matching the wildcard.  If false, yields just the live
                object version.
  project_id: Project ID to use for bucket listings.
  logger: logging.Logger used for outputting debug messages during
          iteration. If None, the root logger will be used.
N)r   all_versions
gsutil_api
project_idlogging	getLoggerlogger)r   r   r/   r.   r0   r3   s         r   __init__CloudWildcardIterator.__init__W   s/    & %$ O O/G--/DKr"   c           
   #     #    U R                   R                  5       nSnU(       a  [        5       nU H  nUR                  U5        M     U R	                  US9nUR                  SS/5        UR                  S/5        U(       d  U R                  (       a&  UR                  SS/5        UR                  SS	/5        U R                  S
/S9 GH  nUR                  nU R                   R                  5       (       a  U(       a  [        U5      nU R                  R                  UR                  SU R                  U R                   R                  US9 Hq  n	U	R                  [         R"                  R$                  :X  a)  U R'                  UU	R(                  U R                  S9v   MT  U R+                  XyR(                  5      v   Ms     M  Uv   GM  [-        U R                   R                  5      (       d  U R                   R/                  5       (       a  U R                  (       d   U R                  R1                  U R                   R                  U R                   R2                  U R                   R4                  U R                   R                  US9n
U R'                  U R                   R6                  U
U R                  =(       d    US9v     gU(       a5  U< U R                   R2                  < SU R                   R4                  < 3nO.U< [=        U R                   R2                  5      =(       d    S< 3nU/nU(       d  GMy  [        UR?                  S5      5      nU RA                  UR2                  5      u  pnnU RC                  U5      nU(       a  [        S/5      OUnU R                  R                  UR                  UUU R                  =(       d    UU R                   R                  US9 GHi  n	U GH^  nU	R                  [         R"                  R$                  :X  a  U	R(                  nURE                  URF                  5      (       ap  U(       a  [=        URF                  5      U:X  aM  U(       a   U RI                  UR4                  5      (       a&  U R'                  UUU R                  =(       d    US9v     M  M  U	R(                  n[-        U5      (       a  [K        SU< U< S35      e[=        U5      nURE                  U5      (       d  GM  U(       a&  UU:w  a   U< US-   U-   < 3nURM                  U5        OU R+                  X}5      v     GMg     GMl     U(       a  GM&  GM     g! [8        [:        4 a     GNf = f7f)a  Iterator that gets called when iterating over the cloud wildcard.

In the case where no wildcard is present, returns a single matching object,
single matching prefix, or one of each if both exist.

Args:
  bucket_listing_fields: Iterable fields to include in bucket listings.
                         Ex. ['name', 'acl'].  Iterator is
                         responsible for converting these to list-style
                         format ['items/name', 'items/acl'] as well as
                         adding any fields necessary for listing such as
                         prefixes.  API implementation is responsible for
                         adding pagination fields.  If this is None,
                         all fields are returned.
  expand_top_level_buckets: If true, yield no BUCKET references.  Instead,
                            expand buckets into top-level objects and
                            prefixes.

Yields:
  BucketListingRef of type BUCKET, OBJECT or PREFIX.
N)
get_fieldsz
items/nameprefixesnamezitems/generationzitems/metageneration
generationmetagenerationidbucket_fields/)	delimiterr.   providerfields)with_version)r:   rA   rB   #r   )prefixr@   r.   rA   rB   zCloud folder z] contains a wildcard; gsutil does not currently support objects with wildcards in their name.)'r   HasGenerationsetadd_GetToListFieldsupdater.   _ExpandBucketWildcardsr   IsBucketr   r/   ListObjectsbucket_nameschemedatatyper   CsObjectOrPrefixTypeOBJECT_GetObjectRefdata_GetPrefixRefr   IsObjectGetObjectMetadataobject_namer:   bucket_url_stringr   r
   r   pop_BuildBucketFilterStrings_GetRegexPatternsmatchr9   _SingleVersionMatchesr   append)r   bucket_listing_fieldsexpand_top_level_bucketssingle_version_requestr7   fieldbucket_listing_refrY   urlobj_or_prefix
get_objectr   urls_needing_expansionrE   r@   prefix_wildcardsuffix_wildcardregex_patternslisting_fieldspattern
gcs_objectrstripped_prefixurl_append_strings                          r   __iter__CloudWildcardIterator.__iter__p   s    0 "..<<> J5j(%u )"33* 4 ,""L*#=>! 
 4#4#4$$!78	:<)9:;
 #999O,77				#	#	%	% $$%67##::oo,,((//*  ;  ,m %%)F)F)M)MM&&'8'4'9'9484E4E ' G G &&'8:L:LMM , #
"
 !!2!2!=!=>>&&((1B1B::!!--!!--,,77**11! ; #J $$T%6%6%H%H%/373D3D 4J3I % L L  "$5$($5$5$A$A$($5$5$@$@B*  t/@/@/L/L!M ""* #-$$$%;%?%?%BC##==cooN6o11/B.  /  -4I   $::oo!,,F0F((//#  ;  %m *''8+H+H+O+OO*//
==11(]:??-K0?.@122:3H3HII ..+$(,(9(9 )?(>	 / A A
  2 '++#F++
 ) "3F<= = $1#8 ==!122$)9_)L2C2BS2H2A3B)C% +112CD ,,->GGS * % %$u PN $%:; s@   H"V%B'U1A4VGVAV+V1VVVVc                 L   U/nSU;   a$  UR                  SS5      nUR                  U5        OUnX4 H/  nUR                  S5      (       d  M  UR                  USS 5        M1     U Vs/ s H-  n[        R                  " [
        R                  " U5      5      PM/     sn$ s  snf )a  Returns list of regex patterns derived from the wildcard patterns.

Args:
  wildcard_pattern (str): A wilcard_pattern to filter the resources.

Returns:
  List of compiled regex patterns.

This translates the wildcard_pattern and also creates some additional
patterns so that we can treat ** in a/b/c/**/d.txt as zero or more folders.
This means, a/b/c/d.txt will also be returned along with a/b/c/e/f/d.txt.
z/**/r?   **/   N)replacer_   
startswithrecompilefnmatch	translate)r   wildcard_patternwildcard_patternsupdated_patternrm   ps         r   r\   'CloudWildcardIterator._GetRegexPatterns  s     **!! )00=o/(o$6			E	"	" 	  - 7 7HH6GBJJw((+,6GHHHs   *4B!c           
         [         R                  " U5      nU(       d	  UnSnUnSnOUR                  5       S:  a&  USUR                  5        nXR                  5       S nOSnUnUR                  S5      nUS:w  a  USUS-    nU=(       d    SU-   nUR	                  S5      (       d  [        U5      nXR                  5       S nUR                  S5      nUS:X  a  SnOXhS-   S nUR                  S5      S:w  a	  SnXV-  nSnOSnU R                  R                  S	[        U5      [        U5      [        U5      [        U5      [        U5      5        X4XV4$ )
aO  Builds strings needed for querying a bucket and filtering results.

This implements wildcard object name matching.

Args:
  wildcard: The wildcard string to match to objects.

Returns:
  (prefix, delimiter, prefix_wildcard, suffix_wildcard)
  where:
    prefix is the prefix to be sent in bucket GET request.
    delimiter is the delimiter to be sent in bucket GET request.
    prefix_wildcard is the wildcard to be used to filter bucket GET results.
    suffix_wildcard is wildcard to be appended to filtered bucket GET
      results for next wildcard expansion iteration.
  For example, given the wildcard gs://bucket/abc/d*e/f*.txt we
  would build prefix= abc/d, delimiter=/, prefix_wildcard=d*e, and
  suffix_wildcard=f*.txt. Using this prefix and delimiter for a bucket
  listing request will then produce a listing result set that can be
  filtered using this prefix_wildcard; and we'd use this suffix_wildcard
  to feed into the next call(s) to _BuildBucketFilterStrings(), for the
  next iteration of listing/filtering.

Raises:
  AssertionError if wildcard doesn't contain any wildcard chars.
r?    r   N   rt   z**zMwildcard=%s, prefix=%s, delimiter=%s, prefix_wildcard=%s, suffix_wildcard=%s
)
r   searchstartfindendswithr   endr3   debugr   )	r   wildcardr]   rE   r@   ri   rj   wildcard_partr   s	            r   r[   /CloudWildcardIterator._BuildBucketFilterStrings9  sn   : !!(+E fi oo		 .5;;=) 0 s#c	%hsQw/26o%%e,, (8 .o  %c	)'(3 
		d	#r	)	*	 	KK	34@4JVl95_%|O'D	F
 @@r"   c                     [        U R                  U5      n[        U R                  R                  5      [        U5      :H  $ N)r   r   strr:   )r   listed_generationdecoded_generations      r   r^   +CloudWildcardIterator._SingleVersionMatches  s;    3D4E4E4EGt  ++,4F0GGGr"   c           	   #     #    [        U R                  R                  5      nU(       aK  [        U5      [        S/5      :X  a2  [	        U R                  R
                  5      (       d  [        U5      v   gU R                  R                  5       (       ar  [	        U R                  R
                  5      (       dN  [        UU R                  R                  U R                  R
                  U R                  R                  US9S9v   g[        R                  " U R                  R
                  5      n[        R                  " U5      nU R                  U5      nU(       a  UR!                  S5        U R                  R#                  UU R$                  U R                  R                  S9 Ha  nUR'                  UR(                  5      (       d  M%  [        U R                  R                  < SUR(                  < S35      n[        XvS9v   Mc     g7f)	a+  Expands bucket and provider wildcards.

Builds a list of bucket url strings that can be iterated on.

Args:
  bucket_fields: If present, populate only these metadata fields for
                 buckets.  Example value: ['acl', 'defaultObjectAcl']

Yields:
  BucketListingRefereneces of type BUCKET.
r<   )rA   rB   root_objectzitems/id)rB   r0   rA   z://r?   N)r   r   rY   rG   r   rN   r   rL   r/   	GetBucketrO   rz   r{   rx   ry   rI   rH   ListBucketsr0   r]   r<   )r   r>   
bucket_urlregexprogrB   bucketre   s           r   rK   ,CloudWildcardIterator._ExpandBucketWildcards  s     &d&7&7&I&IJJ#m,TF;T..::;;  
++



$
$
&
&t00<<==
,0OO,E,E$($5$5$A$A-1->->-E-E+8 -F -:; ;  1 1 = =>eZZd$$]3f	

:OO//__$$++ 0 -& ::fii  $&*&7&7&>&>		&K L##C<
<-s   GHAHc                 d    U(       a)  [        5       nU H  nUR                  SU-   5        M     U$ g)a  Prepends 'items/' to the input fields and converts it to a set.

This way field sets requested for GetBucket can be used in ListBucket calls.
Note that the input set must contain only bucket or object fields; listing
fields such as prefixes or nextPageToken should be added after calling
this function.

Args:
  get_fields: Iterable fields usable in GetBucket/GetObject calls.

Returns:
  Set of fields usable in ListBuckets/ListObjects calls.
zitems/N)rG   rH   )r   r7   list_fieldsrc   s       r   rI   &CloudWildcardIterator._GetToListFields  s4     Ek%5() 	 r"   c                     U(       aD  UR                   b7  [        U R                  UR                   5      nU< UR                  < SU< 3nOU< UR                  < 3n[	        U5      n[        XbS9$ )aL  Creates a BucketListingRef of type OBJECT from the arguments.

Args:
  bucket_url_string: Wildcardless string describing the containing bucket.
  gcs_object: gsutil_api root Object for populating the BucketListingRef.
  with_version: If true, return a reference with a versioned string.

Returns:
  BucketListingRef of type OBJECT.
rD   r   )r:   r   r   r9   r   r   )r   rY   rn   rC   generation_strobject_string
object_urls          r   rS   #CloudWildcardIterator._GetObjectRef  sf     
--91$2C2C2<2G2GIn#4joo#13m !2:??Cm%m4JzBBr"   c                 6    [        U< U< 35      n[        X2S9$ )zCreates a BucketListingRef of type PREFIX from the arguments.

Args:
  bucket_url_string: Wildcardless string describing the containing bucket.
  prefix: gsutil_api Prefix for populating the BucketListingRef

Returns:
  BucketListingRef of type PREFIX.
r   )r   r	   )r   rY   rE   
prefix_urls       r   rU   #CloudWildcardIterator._GetPrefixRef  s     &0A6&JKJz>>r"   c              #   @   #    U R                  US9 H  nUv   M	     g7f)a0  Iterates over the wildcard, returning refs for each expanded bucket.

This ignores the object part of the URL entirely and expands only the
the bucket portion.  It will yield BucketListingRefs of type BUCKET only.

Args:
  bucket_fields: Iterable fields to include in bucket listings.
                 Ex. ['defaultObjectAcl', 'logging'].  This function is
                 responsible for converting these to listing-style
                 format ['items/defaultObjectAcl', 'items/logging'], as
                 well as adding any fields necessary for listing such as
                 'items/id'.  API implemenation is responsible for
                 adding pagination fields.  If this is None, all fields are
                 returned.

Yields:
  BucketListingRef of type BUCKET, or empty iterator if no matches.
r=   N)rK   )r   r>   blrs      r   IterBuckets!CloudWildcardIterator.IterBuckets  s%     & ***Gi H   c              #   B   #    U R                  UUS9 H  nUv   M	     g7f)aQ  Iterates over the wildcard, yielding bucket, prefix or object refs.

Args:
  bucket_listing_fields: If present, populate only these metadata
                         fields for listed objects.
  expand_top_level_buckets: If true and the wildcard expands only to
                            Bucket(s), yields the expansion of each bucket
                            into a top-level listing of prefixes and objects
                            in that bucket instead of a BucketListingRef
                            to that bucket.

Yields:
  BucketListingRef, or empty iterator if no matches.
r`   ra   Nrq   )r   r`   ra   r   s       r   IterAllCloudWildcardIterator.IterAll  s,      }}3H6N  PiPs   c              #   p   #    U R                  USS9 H  nUR                  5       (       d  M  Uv   M      g7f)a  Iterates over the wildcard, yielding only object BucketListingRefs.

Args:
  bucket_listing_fields: If present, populate only these metadata
                         fields for listed objects.

Yields:
  BucketListingRefs of type OBJECT or empty iterator if no matches.
Tr   N)rq   rV   )r   r`   r   s      r   IterObjects!CloudWildcardIterator.IterObjects  s5      }}3H6:  <		<s   '6	6)r.   r/   r3   r0   r   )FNNNFr   )F)r$   r%   r&   r'   r(   r4   rq   r\   r[   r^   rK   rI   rS   rU   r   r   r   r)   r#   r"   r   r+   r+   N   s`     "04 &*(-fPIBSAjH
(=T(C.?,&r"   r+   c                 d    [         R                  " [        R                  R	                  U 5      S9$ )a"  Returns an apitools Object class with supported file attributes.

To provide size estimates for local to cloud file copies, we need to retrieve
expose the local file's size.

Args:
  filepath: Path to the file.

Returns:
  apitools Object that with file name and size attributes filled-in.
)size)apitools_messagesObjectospathgetsize)filepaths    r   _GetFileObjectr   .  s"     
	!	!rwwx'@	AAr"   c                   \    \ rS rSrSr   SS jrSS jrS rS rSS jr	SS	 jr
SS
 jrSrg)FileWildcardIteratori?  a  WildcardIterator subclass for files and directories.

If you use recursive wildcards ('**') only a single such wildcard is
supported. For example you could use the wildcard '**/*.txt' to list all .txt
files in any subdirectory of the current directory, but you couldn't use a
wildcard like '**/abc/**/*.txt' (which would, if supported, let you find .txt
files in any subdirectory named 'abc').
Nc                 n    Xl         X l        X0l        U=(       d    [        R                  " 5       U l        g)a  Instantiates an iterator over BucketListingRefs matching wildcard URL.

Args:
  wildcard_url: FileUrl that contains the wildcard to iterate.
  exclude_tuple: (base_url, exclude_pattern), where base_url is
                 top-level URL to list; exclude_pattern is a regex
                 of paths to ignore during iteration.
  ignore_symlinks: If True, ignore symlinks during iteration.
  logger: logging.Logger used for outputting debug messages during
          iteration. If None, the root logger will be used.
N)r   exclude_tupleignore_symlinksr1   r2   r3   )r   r   r   r   r3   s        r   r4   FileWildcardIterator.__init__I  s+      %&*/G--/DKr"   c              #     #    U=(       a    S[        U5      ;   nU R                  R                  n[        R	                  U5      nU(       a  UR                  S5      SS nUR                  S5      nUR                  S5      (       a  [        SU-  5      eU(       d  SnUR                  [        R                  5      nU R                  XV5      nO[        R                  " U5      nU H  n[        U5      n	 U R                  (       aS  [        R                   R#                  U5      (       a/  U R$                  (       a  U R$                  R'                  SU5        Ms  [        R                   R)                  U5      (       a  [+        U	5      v   M  U(       a  [-        U5      OSn
[/        XS	9v   M     g! [0         a?    [3        S
R5                  [6        R8                  " [:        [=        U5      -  5      5      5      ef = f7f)a  Iterator that gets called when iterating over the file wildcard.

In the case where no wildcard is present, returns a single matching file
or directory.

Args:
  bucket_listing_fields: Iterable fields to include in listings.
      Ex. ['size']. Currently only 'size' is supported.
      If present, will populate yielded BucketListingObject.root_object
      with the file name and size.

Raises:
  WildcardException: if invalid wildcard found.

Yields:
  BucketListingRef of type OBJECT (for files) or PREFIX (for directories)
r   beforeNr   after*z5Invalid wildcard with more than 2 consecutive *s (%s)zSkipping symbolic link %s...r   
)rG   r   rX   FLAT_LIST_REGEXr]   grouprw   WildcardExceptionlstripr   sep_IterDirglobiglobr   r   r   islinkr3   infoisdirr	   r   r   UnicodeEncodeErrorr   jointextwrapwrap_UNICODE_EXCEPTION_TEXTrepr)r   r`   include_sizer   r]   base_dirremaining_wildcard	filepathsr   expanded_url
blr_objects              r   rq   FileWildcardIterator.__iter__^  s    $ * 9c"788    ,,H!!(+E X&s+h ;;w/ 
	&	&s	+	+ !*,4!5 6 	6
   -44RVV<--=i **X&i)(3lFBGGNN8$<$<[[KK;XF
77==""#L1
13?~h/T*#LI
I    FtyyMM1DNBC E F 	FFs8   C3G=6A"F1G=1F1G=F1,G=1A	G::G=c              #     #    [         R                  R                  U5      S   U:X  a  US-  n[         R                  " [        R
                  " U5      SS9 H  u  p4n/ nU H  n[         R                  R                  X75      nU R                  U5      (       d  UR                  U5        OML  U R                  (       d  M_  [         R                  R                  U5      (       d  M  U R                  R                  SU5        M     XdSS& [        R                  " XR5       H/  n	 [         R                  R                  U[        U	5      5      v   M1     M     g! [         a\    [!        SR                  ["        R$                  " [&        [)        [         R                  R                  X95      5      -  5      5      5      ef = f7f)a  An iterator over the specified dir and wildcard.

Args:
  directory (unicode): The path of the directory to iterate over.
  wildcard (str): The wildcard characters used for filename pattern
      matching.

Yields:
  (str) A string containing the path to a file somewhere under the directory
  hierarchy of `directory`.

Raises:
  ComandException: If this method encounters a file path that it cannot
  decode as UTF-8.
r   \T)topdownzSkipping symlink directory "%s"Nr   )r   r   
splitdrivewalksixensure_textr   _ExcludeDirr_   r3   r   r   rz   filterr   UnicodeDecodeErrorr   r   r   r   r   )
r   	directoryr   dirpathdirnames	filenamesfiltered_dirnamesdirnamefull_dir_pathfs
             r   r   FileWildcardIterator._IterDir  s`      
ww)$Q'94 4i )+	0J8<)>$9'W6 ..

"
"7
+  ;;;277>>-88
++

<m
L  &qk~~i2!	>W&@&CD
D 3))>. " 	>6 !mm3 g!9:; <"= > >7	>s+   B:G "G&=G$+E	GA&F>>Gc                    U R                   c  gU R                   u  p#nU(       d  g[        U5      R                  [        UR                  5      S nUR	                  U R
                  R                  5      (       a  USS nUR                  U5      (       a.  U R                  (       a  U R                  R                  SU5        gg)zCheck a directory to see if it should be excluded from os.walk.

Args:
  dir: String representing the directory to check.

Returns:
  True if the directory should be excluded.
NFr   z!Skipping excluded directory %s...T)
r   r   r   lenrw   r   delimr]   r3   r   )r   dirbase_urlexclude_dirsexclude_patternstr_to_checks         r   r    FileWildcardIterator._ExcludeDir  s     !040B0B-X_'ZH//013Lt006677!!"%l\**	<cB +r"   c              #   n   #    U R                  US9 H  nUR                  5       (       d  M  Uv   M      g7f)av  Iterates over the wildcard, yielding only object (file) refs.

Args:
  bucket_listing_fields: Iterable fields to include in listings.
      Ex. ['size']. Currently only 'size' is supported.
      If present, will populate yielded BucketListingObject.root_object
      with the file name and size.

Yields:
  BucketListingRefs of type OBJECT or empty iterator if no matches.
r`   N)r   rV   )r   r`   rd   s      r   r    FileWildcardIterator.IterObjects  s8      #ll3 + 5		$	$	&	&  5s   &5	5c              #   @   #    U R                  US9 H  nUv   M	     g7f)a  Iterates over the wildcard, yielding BucketListingRefs.

Args:
  bucket_listing_fields: Iterable fields to include in listings.
      Ex. ['size']. Currently only 'size' is supported.
      If present, will populate yielded BucketListingObject.root_object
      with the file name and size.
  expand_top_level_buckets: Ignored; filesystems don't have buckets.

Yields:
  BucketListingRefs of type OBJECT (file) or PREFIX (directory),
  or empty iterator if no matches.
r   Nr   )r   r`   ra   rd   s       r   r   FileWildcardIterator.IterAll  s)      #mm3 , 55r   c                     [        S5      e)zPlaceholder to allow polymorphic use of WildcardIterator.

Args:
  unused_bucket_fields: Ignored; filesystems don't have buckets.

Raises:
  WildcardException: in all cases.
z6Iterating over Buckets not possible for file wildcards)r   )r   unused_bucket_fieldss     r   r    FileWildcardIterator.IterBuckets*  s     @B Br"   )r   r   r3   r   )NFNr   r   )r$   r%   r&   r'   r(   r4   rq   r   r   r   r   r   r)   r#   r"   r   r   r   ?  s:     "$	0*:FxR>h0!$$
Br"   r   c                   *    \ rS rSrSrS rS rS rSrg)r   i7  z+Exception raised for invalid wildcard URLs.c                 :    [         R                  U 5        Xl        g r   )StandardErrorr4   reason)r   r
  s     r   r4   WildcardException.__init__:  s    4 Kr"   c                      SU R                   -  $ NzWildcardException: %sr
  r   s    r   r    WildcardException.__repr__>      "T[[00r"   c                      SU R                   -  $ r  r  r   s    r   __str__WildcardException.__str__A  r  r"   r  N)	r$   r%   r&   r'   r(   r4   r    r  r)   r#   r"   r   r   r   7  s    311r"   r   c                     [        U 5      nU=(       d    [        R                  " 5       nUR                  5       (       a  [	        UUUUS9$ [        UUUUS9$ )a  Instantiate a WildcardIterator for the given URL string.

Args:
  url_str: URL string naming wildcard object(s) to iterate.
  gsutil_api: Cloud storage interface.  Passed in for thread safety, also
              settable for testing/mocking.
  all_versions: If true, the iterator yields all versions of objects
                matching the wildcard.  If false, yields just the live
                object version.
  project_id: Project id to use for bucket listings.
  exclude_tuple: (base_url, exclude_pattern), where base_url is
                 top-level URL to list; exclude_pattern is a regex
                 of paths to ignore during iteration.
  ignore_symlinks: For FileUrls, ignore symlinks during iteration if true.
  logger: logging.Logger used for outputting debug messages during iteration.
          If None, the root logger will be used.

Returns:
  A WildcardIterator that handles the requested iteration.
)r   r   r3   )r.   r0   )r   r1   r2   	IsFileUrlr   r+   )url_strr/   r.   r0   r   r   r3   re   s           r   CreateWildcardIteratorr  E  s^    8 	W%#(W&&(&]]__.;0?'-/ /
 !!+.:,68 8r"   )FNNFN)2r(   
__future__r   r   r   r   rz   r   r1   r   rx   r   r   gslib.bucket_listing_refr   r   r	   gslib.cloud_apir
   r   r   gslib.exceptionr   gslib.storage_urlr   r   r   r   r   "gslib.third_party.storage_apitoolsr   r   gslib.utils.constantsr   gslib.utils.text_utilr   r   PY3	Exceptionr	  ry   r   r   objectr   r+   r   r   r   r  r#   r"   r   <module>r#     s    8 & %  '    	 	  
 8 8 8 1 $ - , . 8 2 + , W & < .77-**@A> Av A], ]@B"uB+ uBp1 1  ).&*)-+0"&'8r"   