def collect_iteration(self, schema, prop, options): """Run thru an iteration for a given configuration.""" filename = pkg_resources.resource_filename(__name__, "samples/test1.xmp") with open(filename, 'r') as fptr: strbuffer = fptr.read() xmp = exempi.new_empty() exempi.parse(xmp, strbuffer) iterator = exempi.iterator_new(xmp, schema, prop, options) schemas = [] paths = [] props = [] if iterator: while True: try: schema, path, prop, _ = exempi.iterator_next(iterator) schemas.append(schema) paths.append(path) props.append(prop) except StopIteration: break exempi.iterator_free(iterator) exempi.free(xmp) return schemas, paths, props
def test_3(self): """Corresponds to test3.cpp""" filename = pkg_resources.resource_filename(__name__, "samples/test1.xmp") with open(filename, 'r') as fptr: strbuffer = fptr.read() xmp = exempi.new_empty() exempi.parse(xmp, strbuffer) options = XMP_ITERATOR_OPTIONS['iter_justleafnodes'] iterator = exempi.iterator_new(xmp, None, None, options) schemas = [] paths = [] props = [] while True: try: schema, path, prop, _ = exempi.iterator_next(iterator) schemas.append(schema) paths.append(path) props.append(prop) except StopIteration: break exempi.iterator_free(iterator) exempi.free(xmp)
def collect_iteration(self, schema, prop, options): """Run thru an iteration for a given configuration.""" filename = pkg_resources.resource_filename(__name__, "samples/test1.xmp") with open(filename, 'r') as fptr: strbuffer = fptr.read() xmp = exempi.new_empty() exempi.parse(xmp, strbuffer) iterator = exempi.iterator_new(xmp, schema, prop, options) schemas = [] paths = [] props = [] while True: try: schema, path, prop, _ = exempi.iterator_next(iterator) schemas.append(schema) paths.append(path) props.append(prop) except StopIteration: break exempi.iterator_free(iterator) exempi.free(xmp) return schemas, paths, props
def test_iter_skip_subtree(self): """Alter the iteration midstream.""" options = XMP_ITERATOR_OPTIONS['iter_properties'] filename = pkg_resources.resource_filename(__name__, "samples/test1.xmp") with open(filename, 'r') as fptr: strbuffer = fptr.read() xmp = exempi.new_empty() exempi.parse(xmp, strbuffer) iterator = exempi.iterator_new(xmp, None, None, options) schemas = [] paths = [] props = [] while True: try: schema, path, prop, _ = exempi.iterator_next(iterator) if schema == NS_TIFF: exempi.iterator_skip(iterator, XMP_SKIP_OPTIONS['iter_skipsubtree']) continue schemas.append(schema) paths.append(path) props.append(prop) except StopIteration: break exempi.iterator_free(iterator) exempi.free(xmp) # If the iteration modification worked, there should be no TIFF # properties in the list of schemas. self.assertTrue(NS_TIFF not in schemas)