Fix CollectionReader treating any collection with additional +hints as
authorTom Clegg <tom@curoverse.com>
Fri, 7 Mar 2014 21:49:47 +0000 (16:49 -0500)
committerTom Clegg <tom@curoverse.com>
Fri, 7 Mar 2014 21:49:47 +0000 (16:49 -0500)
an empty manifest.

Now, accept hash+size+anyhints as a UUID, and if the argument looks
like neither a UUID nor a manifest, raise an exception instead of
proceeding with undefined results.

sdk/python/arvados/collection.py
sdk/python/arvados/errors.py
sdk/python/test_collections.py

index b48b6df009dbe26ca970c381b0202472eb26e6fe..ff29919f1bf3c6a0e7e60245333ad454164f2df5 100644 (file)
@@ -84,12 +84,15 @@ def normalize(collection):
 
 class CollectionReader(object):
     def __init__(self, manifest_locator_or_text):
-        if re.search(r'^[a-f0-9]{32}\+\d+(\+\S)*$', manifest_locator_or_text):
+        if re.search(r'^[a-f0-9]{32}(\+\d+)?(\+\S+)*$', manifest_locator_or_text):
             self._manifest_locator = manifest_locator_or_text
             self._manifest_text = None
-        else:
+        elif re.search(r'^\S+( [a-f0-9]{32,}(\+\S+)*)*( \d+:\d+:\S+)+\n', manifest_locator_or_text):
             self._manifest_text = manifest_locator_or_text
             self._manifest_locator = None
+        else:
+            raise errors.ArgumentError(
+                "Argument to CollectionReader must be a manifest or a collection UUID")
         self._streams = None
 
     def __enter__(self):
index 5ea54befdebcc735dabb3b13688f50743474f31e..e4c69a3c83dff24ebc70f1ce0212931b4b77ba06 100644 (file)
@@ -1,5 +1,7 @@
 # errors.py - Arvados-specific exceptions.
 
+class ArgumentError(Exception):
+    pass
 class SyntaxError(Exception):
     pass
 class AssertionError(Exception):
index 3dfc72f65b66bcc25482e966edda8d85795daa12..7df620d977d54954fbd9b0b7d943549934b467cd 100644 (file)
@@ -42,7 +42,7 @@ class LocalCollectionReaderTest(unittest.TestCase):
         os.environ['KEEP_LOCAL_STORE'] = '/tmp'
         LocalCollectionWriterTest().runTest()
     def runTest(self):
-        cr = arvados.CollectionReader('d6c3b8e571f1b81ebb150a45ed06c884+114')
+        cr = arvados.CollectionReader('d6c3b8e571f1b81ebb150a45ed06c884+114+Xzizzle')
         got = []
         for s in cr.all_streams():
             for f in s.all_files():