blob: 655387532bd171594e518759f825a3cac97237e9 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#Author: Shu Shi
#emaiL: shushi@research.att.com
from toscalib.templates.constant import *
from toscalib.types.constraints import PropertyConstraints
import logging
class EntrySchema(object):
def __init__(self, content):
self.type = None
self.type_obj = None
self.constraints = None
self.raw_content = content
self.parsed = False
def _parse_content(self, db):
if self.parsed is True:
return
if self.raw_content is None:
logging.warning( 'Construct None entry_schema section')
self.parsed = True
return
if type(self.raw_content) is str:
self.type = self.raw_content
from toscalib.types.data import DataType
if self.type in DataType._built_in_types():
self.type_obj = DataType(self.type)
# elif db is None or db.DATA_TYPES.has_key(self.type) is False:
elif db is None or self.type not in db.DATA_TYPES:
logging.warning( 'Data type: '+ self.type+ ' not defined or imported!')
self.type_obj = None
else:
self.type_obj = db.DATA_TYPES[self.type]
self.type_obj._parse_content(db)
self.parsed = True
return
# if self.raw_content.has_key(PROP_TYPE):
if PROP_TYPE in self.raw_content:
self.type = self.raw_content[PROP_TYPE]
from toscalib.types.data import DataType
if self.type in DataType._built_in_types():
self.type_obj = DataType(self.type)
# elif db is None or db.DATA_TYPES.has_key(self.type) is False:
elif db is None or self.type not in db.DATA_TYPES:
logging.warning( 'Data type: '+ self.type+ ' not defined or imported!')
self.type_obj = None
else:
self.type_obj = db.DATA_TYPES[self.type]
self.type_obj._parse_content(db)
# if self.raw_content.has_key(PROP_CONSTRAINT):
if PROP_CONSTRAINT in self.raw_content:
self.constraints = PropertyConstraints(self.raw_content[PROP_CONSTRAINT])
self.constraints._parse_content()
self.parsed = True
return
def _format_value (self, value):
if self.type_obj is not None:
return self.type_obj._format_value(value)
else:
logging.warning( 'Invalid entry_schema type')
return value
|