def generate(parent, child_name, template, description, name, tags): """ A recursive function that traverses the "tree" in a dict to create new namespaces and/or tags as required. Populates the "tags" dict with tag_value instances so it's possible to generate FOM Object based classes based on the newly created tags. """ # Create the child namespace if child_name: ns = make_namespace('/'.join([parent.path, child_name]), name, description) else: ns = parent for key, value in template.iteritems(): # drop all the white space key = key.strip() # lets see what's in here if isinstance(value, dict): # ok... we have another dict, so we're doing depth first traversal # and jump right in generate(ns, key, value, description, name, tags) else: # it must be a tag so create the tag within the current namespace tag = make_tag(ns, key, description, False) # Create the tag_value instance... # Lets make sure we specify the right sort of mime defaultType = None if isinstance(value, list) and not all( isinstance(x, basestring) for x in value): defaultType = 'application/json' logger.info( "Found list that's not all strings, setting JSON tag value " "with MIME type %r" % defaultType) attribute_name = tag.path logger.info('Mapping tag: %r to attribute: %r' % (tag.path, attribute_name)) tags[attribute_name] = tag_value(tag.path, defaultType)
def generate(parent, child_name, template, description, name, tags): """ A recursive function that traverses the "tree" in a dict to create new namespaces and/or tags as required. Populates the "tags" dict with tag_value instances so it's possible to generate FOM Object based classes based on the newly created tags. """ # Create the child namespace if child_name: ns = make_namespace('/'.join([parent.path, child_name]), name, description) else: ns = parent for key, value in template.iteritems(): # drop all the white space key = key.strip() # lets see what's in here if isinstance(value, dict): # ok... we have another dict, so we're doing depth first traversal # and jump right in generate(ns, key, value, description, name, tags) else: # it must be a tag so create the tag within the current namespace tag = make_tag(ns, key, description, False) # Create the tag_value instance... # Lets make sure we specify the right sort of mime defaultType = None if isinstance(value, list) and not all(isinstance(x, basestring) for x in value): defaultType = 'application/json' logger.info("Found list that's not all strings, setting JSON tag value " "with MIME type %r" % defaultType) attribute_name = tag.path logger.info('Mapping tag: %r to attribute: %r' % (tag.path, attribute_name)) tags[attribute_name] = tag_value(tag.path, defaultType)
class fomtest(Object): ft = tag_value(u'test', cached=False)
class fomtest(Object): ft = tag_value('test1', lazy_save=False) ft2 = tag_value('test2', 'text/html', lazy_save=False)
class fomtest(Object): ft = tag_value('test1') ft2 = tag_value('test2', 'text/html')
class UserClass(Object): username = tag_value('fluiddb/users/username') name = tag_value('fluiddb/users/name')
class TestClass(Object): t = tag_value(u'test/test')
class TestClass2(Object): t = tag_value(u'test/test', lazy_save=False)
class Foo(Object): baz = tag_value('foo/baz', content_type='text/html')
class b(a): t2 = tag_value('baz/qux')
class a(Object): t1 = tag_value('foo/bar')
class Article(Object): title = tag_value(u'test/maptest/title', lazy_save=False) newspaper = tag_relation('test/maptest/newspaper', Newspaper, lazy_save=False)
class Newspaper(Object): name = tag_value(u'test/maptest/name', lazy_save=False)
class Auditable(Object): """Mixin to provide auditable behaviour """ timestamp = tag_value(u'test/maptest/timestamp') username = tag_value(u'test/maptest/username')
class Describable(Object): """Mixin to provide describable behaviour """ description = tag_value(u'test/maptest/description')
class fomtest(Object): ft = tag_value('test/fomtest')
class A(Object): fomtest = tag_value(u'test/fomtest', lazy_save=False)
class mockClass(Object): foo = tag_value('foo/bar')