예제 #1
0
파일: utils.py 프로젝트: ltvolks/flimp
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)
예제 #2
0
파일: utils.py 프로젝트: fluidinfo/flimp
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)
예제 #3
0
 class fomtest(Object):
     ft = tag_value(u'test', cached=False)
예제 #4
0
 class fomtest(Object):
     ft = tag_value('test1', lazy_save=False)
     ft2 = tag_value('test2', 'text/html', lazy_save=False)
예제 #5
0
 class fomtest(Object):
     ft = tag_value('test1')
     ft2 = tag_value('test2', 'text/html')
예제 #6
0
 class UserClass(Object):
     username = tag_value('fluiddb/users/username')
     name = tag_value('fluiddb/users/name')
예제 #7
0
        class TestClass(Object):

            t = tag_value(u'test/test')
예제 #8
0
        class TestClass2(Object):

            t = tag_value(u'test/test', lazy_save=False)
예제 #9
0
 class Foo(Object):
     baz = tag_value('foo/baz', content_type='text/html')
예제 #10
0
        class b(a):

            t2 = tag_value('baz/qux')
예제 #11
0
        class a(Object):

            t1 = tag_value('foo/bar')
예제 #12
0
class Article(Object):

    title = tag_value(u'test/maptest/title', lazy_save=False)
    newspaper = tag_relation('test/maptest/newspaper',
                             Newspaper,
                             lazy_save=False)
예제 #13
0
class Newspaper(Object):

    name = tag_value(u'test/maptest/name', lazy_save=False)
예제 #14
0
class Auditable(Object):
    """Mixin to provide auditable behaviour
    """
    timestamp = tag_value(u'test/maptest/timestamp')
    username = tag_value(u'test/maptest/username')
예제 #15
0
class Describable(Object):
    """Mixin to provide describable behaviour
    """
    description = tag_value(u'test/maptest/description')
예제 #16
0
 class fomtest(Object):
     ft = tag_value('test/fomtest')
예제 #17
0
 class A(Object):
     fomtest = tag_value(u'test/fomtest', lazy_save=False)
예제 #18
0
 class mockClass(Object):
     foo = tag_value('foo/bar')