Browse code

Merge remote-tracking branch 'orenhe/simplify_wildcard_handling' into merge

Matt Domsch authored on 2013/11/26 10:08:06
Showing 1 changed files
... ...
@@ -17,6 +17,7 @@ import os
17 17
 import sys
18 18
 import glob
19 19
 import copy
20
+import re
20 21
 
21 22
 __all__ = ["fetch_local_list", "fetch_remote_list", "compare_filelists", "filter_exclude_include"]
22 23
 
... ...
@@ -402,16 +403,12 @@ def fetch_remote_list(args, require_attribs = False, recursive = None):
402 402
             uri_str = str(uri)
403 403
             ## Wildcards used in remote URI?
404 404
             ## If yes we'll need a bucket listing...
405
-            if uri_str.find('*') > -1 or uri_str.find('?') > -1:
406
-                first_wildcard = uri_str.find('*')
407
-                first_questionmark = uri_str.find('?')
408
-                if first_questionmark > -1 and first_questionmark < first_wildcard:
409
-                    first_wildcard = first_questionmark
410
-                prefix = uri_str[:first_wildcard]
411
-                rest = uri_str[first_wildcard+1:]
405
+            wildcard_split_result = re.split("\*|\?", uri_str, maxsplit=1)
406
+            if len(wildcard_split_result) == 2: # wildcards found
407
+                prefix, rest = wildcard_split_result
412 408
                 ## Only request recursive listing if the 'rest' of the URI,
413 409
                 ## i.e. the part after first wildcard, contains '/'
414
-                need_recursion = rest.find('/') > -1
410
+                need_recursion = '/' in rest
415 411
                 objectlist = _get_filelist_remote(S3Uri(prefix), recursive = need_recursion)
416 412
                 for key in objectlist:
417 413
                     ## Check whether the 'key' matches the requested wildcards