aboutsummaryrefslogtreecommitdiffstats
path: root/Testcases/cfgm_common/ifmap/metadata.py
blob: 17f4515a261920f89f5a3d0fef1452fb8947e961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright 2011, Infoblox, All Rights Reserved
#
# Open Source, see LICENSE
#
from util import attr, link_ids

class MetadataBase:
    """ foundation class for metadata factory """
    pass

class Metadata(MetadataBase):
    """
    Metadata factory
    """
    __ns_uri = ''
    
    def __init__(self, name, value=None, attributes=None, ns_prefix=None, ns_uri=None, elements=''):
        self.__value = value
        self.__attributes = attributes
        self.__elements = elements
        
        if ns_prefix:
            self.__name = ns_prefix + ':' + name
        elif not ns_uri:
            self.__name = 'meta:' + name
            
        if ns_uri:
            if ns_prefix:
                self.__ns_uri = ' xmlns:' + ns_prefix + '="' + ns_uri + '"'
            else:
                self.__ns_uri = ' xmlns="' + ns_uri + '"'
    
    def __str__(self):
        __attr = ' '+ attr(self.__attributes)
        return '<metadata><' + self.__name + self.__ns_uri + __attr + '>' + self.__value + self.__elements + '</' + self.__name + '></metadata>'