本文整理汇总了Python中schema.Schema.get_sub_schema方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.get_sub_schema方法的具体用法?Python Schema.get_sub_schema怎么用?Python Schema.get_sub_schema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schema.Schema
的用法示例。
在下文中一共展示了Schema.get_sub_schema方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: urlopen
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_sub_schema [as 别名]
connection.row_factory = sqlite3.Row
elif db_type == "mysql":
connection = mdb.connect(host, username, password, db_name)
elif db_type == "postgres":
connection = psycopg2.connect(host=host, database=db_name, user=username, password=password)
cursor = connection.cursor()
fschema = urlopen(SCHEMA_URL)
schema = Schema(fschema)
complex_types = schema.get_complexTypes()
simple_types = schema.get_simpleTypes()
elements = schema.get_element_list("element", "vip_object")
if db_type == "postgres":
for simple in simple_types:
create_enum(simple, schema.get_element_list("simpleType", simple))
for element in elements:
create_table(element, schema.get_sub_schema(element)["elements"])
for q in META_QUERIES:
create_statement = q.format(**TYPE_CONVERSIONS[db_type])
cursor.execute(create_statement)
connection.commit()
if db_type == "postgres" or db_type == "sqlite":
create_triggers()
if db_type == "postgres":
create_partition_triggers()
示例2: __init__
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_sub_schema [as 别名]
class SchemaProps:
def __init__(self, schema_data=None):
if not schema_data:
self.schema = Schema(urlopen(SCHEMA_URL + DEFAULT_VERSION + ".xsd"))
elif schema_data in VALID_VERSIONS:
self.schema = Schema(urlopen(SCHEMA_URL + schema_data + ".xsd"))
elif path.exists(schema_data):
self.schema = Schema(open(schema_data))
else:
self.schema = Schema(urlopen(SCHEMA_URL + DEFAULT_VERSION + ".xsd"))
self.version = self.schema.version
self.simple_elements = self.schema.get_element_list("complexType", "simpleAddressType")
self.detail_elements = self.schema.get_element_list("complexType", "detailAddressType")
self.element_list = self.schema.get_element_list("element","vip_object")
self.create_headers()
def address_fields(self, e_name, e_type, required):
e_list = {}
for e in self.schema.get_sub_schema(e_type)["elements"]:
if required and ("minOccurs" not in e or int(e["minOccurs"]) > 0):
e_list[e_name + "_" + e["name"]] = {"type":e["type"],"is_required":"true"}
else:
e_list[e_name + "_" + e["name"]] = {"type":e["type"],"is_required":"false"}
return e_list
def create_headers(self):
self.element_header = {}
self.db_header = {}
self.conversion_data = {}
self.db_types = {}
self.element_types = {}
for elem_name in self.element_list:
subschema = self.schema.get_sub_schema(elem_name)
elem_list = []
db_list = []
db_type = {}
element_type = {}
conversion_list = {elem_name:{}}
if "elements" in subschema:
for e in subschema["elements"]:
e_name = e["name"]
if e["type"].endswith("AddressType"):
if "minOccurs" not in e or int(e["minOccurs"]) > 0:
address_required = True
else:
address_required = False
temp_list = self.address_fields(e_name, e["type"], address_required)
elem_list.extend(temp_list.keys())
element_type.update(temp_list)
db_list.extend(temp_list.keys())
db_type.update(temp_list)
for t in temp_list.keys():
conversion_list[elem_name][t] = t
elif "simpleContent" in e:
elem_list.append(e_name)
element_type[e_name] = {"type":e["type"],"is_required":"false"}
sc_name = elem_name + "_" + e_name[:e_name.find("_id")]
conversion_list[sc_name] = {"id":elem_name + "_id", e_name:e_name}
temp_list = [elem_name + "_id", e_name]
temp_dict = {elem_name + "_id":{"type":"xs:integer","is_required":"true"}, e_name:{"type":e["type"],"is_required":"true"}}
for sc_attr in e["simpleContent"]["attributes"]:
elem_list.append(e_name + "_" + sc_attr["name"])
element_type[e_name + "_" + sc_attr["name"]] = {"type":sc_attr["type"],"is_required":"false"}
temp_list.append(sc_attr["name"])
temp_dict[sc_attr["name"]] = {"type":sc_attr["type"],"is_required":"false"}
conversion_list[sc_name][e_name + "_" + sc_attr["name"]] = sc_attr["name"]
self.db_header[sc_name] = temp_list
self.db_types[sc_name] = temp_dict
elif "maxOccurs" in e and e["maxOccurs"] == "unbounded":
elem_list.append(e_name)
element_type[e_name] = {"type":e["type"],"is_required":"false"}
unbounded_name = elem_name + "_" + e_name[:e_name.find("_id")]
self.db_header[unbounded_name] = [elem_name + "_id", e_name]
self.db_types[unbounded_name] = {elem_name + "_id":{"type":"xs:integer","is_required":"true"}, e_name:{"type":e["type"],"is_required":"true"}}
conversion_list[unbounded_name] = {"id":elem_name + "_id", e_name:e_name}
else:
elem_list.append(e_name)
db_list.append(e_name)
if "minOccurs" not in e or int(e["minOccurs"]) > 0:
element_type[e_name] = {"type":e["type"],"is_required":"true"}
db_type[e_name] = {"type":e["type"],"is_required":"true"}
else:
element_type[e_name] = {"type":e["type"],"is_required":"false"}
db_type[e_name] = {"type":e["type"],"is_required":"false"}
conversion_list[elem_name][e_name] = e_name
if "attributes" in subschema:
for a in subschema["attributes"]:
elem_list.append(a["name"])
db_list.append(a["name"])
if "use" in a and a["use"] == "required":
element_type[a["name"]] = {"type":a["type"],"is_required":"true"}
db_type[a["name"]] = {"type":a["type"],"is_required":"true"}
else:
#.........这里部分代码省略.........
示例3: urlopen
# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_sub_schema [as 别名]
connection.row_factory = sqlite3.Row
elif db_type == "mysql":
connection = mdb.connect(host, username, password, db_name)
elif db_type == "postgres":
connection = psycopg2.connect(host=host, database=db_name, user=username, password=password)
cursor = connection.cursor()
fschema = urlopen(SCHEMA_URL)
schema = Schema(fschema)
complex_types = schema.get_complexTypes()
simple_types = schema.get_simpleTypes()
elements = schema.get_element_list("element", "vip_object")
if db_type == "postgres":
for simple in simple_types:
create_enum(simple, schema.get_element_list("simpleType", simple))
for complex_t in complex_types:
sub_schema = schema.get_sub_schema(complex_t)
if "elements" in sub_schema:
create_table(complex_t, sub_schema["elements"])
for element in elements:
create_table(element, schema.get_sub_schema(element)["elements"])
if db_type == "postgres" or db_type == "sqlite":
create_triggers()