当前位置: 首页>>代码示例>>Python>>正文


Python Schema.get_element_list方法代码示例

本文整理汇总了Python中schema.Schema.get_element_list方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.get_element_list方法的具体用法?Python Schema.get_element_list怎么用?Python Schema.get_element_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schema.Schema的用法示例。


在下文中一共展示了Schema.get_element_list方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_schema_props

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_element_list [as 别名]
	def set_schema_props(self, schema_file):
		
		schema = Schema(schema_file)
		
		self.schema_version = schema.version
		self.simple_elements = schema.get_element_list("complexType", "simpleAddressType")
		self.detail_elements = schema.get_element_list("complexType", "detailAddressType")
		self.element_list = schema.get_element_list("element","vip_object")
		self.elem_fields = self.get_fields(schema, self.element_list)
开发者ID:ballotinfo,项目名称:VAVE,代码行数:11,代码来源:formatcheck.py

示例2: __init__

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_element_list [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:
#.........这里部分代码省略.........
开发者ID:simbha,项目名称:VAVE,代码行数:103,代码来源:schemaprops.py

示例3: urlopen

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_element_list [as 别名]
if db_type == "sqlite":
	connection = sqlite3.connect(host)
	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":
开发者ID:simbha,项目名称:VAVE,代码行数:33,代码来源:create_db.py

示例4:

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import get_element_list [as 别名]
					e_list[t_name][sub_elem_name] = sub_elem_name
					for sc_attr in sub_elem["simpleContent"]["attributes"]:
						e_list[t_name][sub_elem_name + "_" + sc_attr["name"]] = sc_attr["name"]
				else:
					e_list[root_elem][sub_elem_name] = sub_elem_name
		if "attributes" in subschema:
			for a in subschema["attributes"]:
				if a["name"] == "id":
					e_list[root_elem]["feed_id"] = a["name"]
				else:
					e_list[root_elem][a["name"]] = a["name"]
		field_list[root_elem] = e_list

	return field_list

simple_elements = schema.get_element_list("complexType", "simpleAddressType")
detail_elements = schema.get_element_list("complexType", "detailAddressType")
element_list = schema.get_element_list("element","vip_object")
elem_fields = get_fields(schema, element_list)
vip_id = 23
election_id = 1000
connection = psycopg2.connect(host="localhost", database="vip", user="username", password="password")
cursor = connection.cursor()

for f in os.listdir(FEED_DIR):
	ename = f.split(".")[0].lower()

	if ename in element_list:

		data = csv.DictReader(open(FEED_DIR + f))
		header = data.fieldnames
开发者ID:simbha,项目名称:VAVE,代码行数:33,代码来源:files_to_db.py


注:本文中的schema.Schema.get_element_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。