def execute(my):
# create an xml document
xml_impl = getDOMImplementation()
doc = xml_impl.createDocument(None, "session", None)
root = doc.documentElement
# go through the tactic
tactic_nodes = my.util.get_all_tactic_nodes()
tactic_nodes.sort()
for tactic_node in tactic_nodes:
node_data = NodeData(tactic_node)
ref_node = node_data.get_ref_node()
root.appendChild(ref_node)
my.xml = doc.toxml()
return my.xml
python类getDOMImplementation()的实例源码
def introspect(my):
'''introspect the session and create a session xml from it'''
# create an xml document
xml_impl = getDOMImplementation()
my.doc = xml_impl.createDocument(None, "session", None)
my.root = my.doc.documentElement
# go through the tactic
tactic_nodes = my.util.get_all_tactic_nodes()
tactic_nodes.sort()
for tactic_node in tactic_nodes:
node_data = NodeData(tactic_node)
ref_node = node_data.get_ref_node()
# set some more info on the ref node
ref_node.setAttribute("tactic_node", tactic_node)
my.root.appendChild(ref_node)
my.xml = my.doc.toprettyxml()
return my.xml
def _WriteConfigFile(config_path, issues_dict):
new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
top_element = new_dom.documentElement
top_element.appendChild(new_dom.createComment(_DOC))
for issue_id, issue in sorted(issues_dict.iteritems(), key=lambda i: i[0]):
issue_element = new_dom.createElement('issue')
issue_element.attributes['id'] = issue_id
if issue.severity:
issue_element.attributes['severity'] = issue.severity
if issue.severity == 'ignore':
print 'Warning: [%s] is suppressed globally.' % issue_id
else:
for path in sorted(issue.paths):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['path'] = path
issue_element.appendChild(ignore_element)
for regexp in sorted(issue.regexps):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['regexp'] = regexp
issue_element.appendChild(ignore_element)
top_element.appendChild(issue_element)
with open(config_path, 'w') as f:
f.write(new_dom.toprettyxml(indent=' ', encoding='utf-8'))
print 'Updated %s' % config_path
def _WriteConfigFile(config_path, issues_dict):
new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
top_element = new_dom.documentElement
top_element.appendChild(new_dom.createComment(_DOC))
for issue_id, issue in sorted(issues_dict.iteritems(), key=lambda i: i[0]):
issue_element = new_dom.createElement('issue')
issue_element.attributes['id'] = issue_id
if issue.severity:
issue_element.attributes['severity'] = issue.severity
if issue.severity == 'ignore':
print 'Warning: [%s] is suppressed globally.' % issue_id
else:
for path in sorted(issue.paths):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['path'] = path
issue_element.appendChild(ignore_element)
for regexp in sorted(issue.regexps):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['regexp'] = regexp
issue_element.appendChild(ignore_element)
top_element.appendChild(issue_element)
with open(config_path, 'w') as f:
f.write(new_dom.toprettyxml(indent=' ', encoding='utf-8'))
print 'Updated %s' % config_path
def __init__(self, cls, db_name, db_user, db_passwd,
db_host, db_port, db_table, ddl_dir, enable_ssl):
self.cls = cls
if not db_name:
db_name = cls.__name__.lower()
self.db_name = db_name
self.db_user = db_user
self.db_passwd = db_passwd
self.db_host = db_host
self.db_port = db_port
self.db_table = db_table
self.ddl_dir = ddl_dir
self.s3 = None
self.converter = XMLConverter(self)
self.impl = getDOMImplementation()
self.doc = self.impl.createDocument(None, 'objects', None)
self.connection = None
self.enable_ssl = enable_ssl
self.auth_header = None
if self.db_user:
base64string = encodebytes('%s:%s' % (self.db_user, self.db_passwd))[:-1]
authheader = "Basic %s" % base64string
self.auth_header = authheader
def _WriteConfigFile(config_path, issues_dict):
new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
top_element = new_dom.documentElement
top_element.appendChild(new_dom.createComment(_DOC))
for issue_id, issue in sorted(issues_dict.iteritems(), key=lambda i: i[0]):
issue_element = new_dom.createElement('issue')
issue_element.attributes['id'] = issue_id
if issue.severity:
issue_element.attributes['severity'] = issue.severity
if issue.severity == 'ignore':
print 'Warning: [%s] is suppressed globally.' % issue_id
else:
for path in sorted(issue.paths):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['path'] = path
issue_element.appendChild(ignore_element)
for regexp in sorted(issue.regexps):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['regexp'] = regexp
issue_element.appendChild(ignore_element)
top_element.appendChild(issue_element)
with open(config_path, 'w') as f:
f.write(new_dom.toprettyxml(indent=' ', encoding='utf-8'))
print 'Updated %s' % config_path
def __init__(self, cls, db_name, db_user, db_passwd,
db_host, db_port, db_table, ddl_dir, enable_ssl):
self.cls = cls
if not db_name:
db_name = cls.__name__.lower()
self.db_name = db_name
self.db_user = db_user
self.db_passwd = db_passwd
self.db_host = db_host
self.db_port = db_port
self.db_table = db_table
self.ddl_dir = ddl_dir
self.s3 = None
self.converter = XMLConverter(self)
self.impl = getDOMImplementation()
self.doc = self.impl.createDocument(None, 'objects', None)
self.connection = None
self.enable_ssl = enable_ssl
self.auth_header = None
if self.db_user:
base64string = encodebytes('%s:%s' % (self.db_user, self.db_passwd))[:-1]
authheader = "Basic %s" % base64string
self.auth_header = authheader
def set_settings(JsonRespuesta):
for Ajuste in JsonRespuesta:
settings_dic[Ajuste]=JsonRespuesta[Ajuste].encode("utf8")
from xml.dom import minidom
#Crea un Nuevo XML vacio
new_settings = minidom.getDOMImplementation().createDocument(None, "settings", None)
new_settings_root = new_settings.documentElement
for key in settings_dic:
nodo = new_settings.createElement("setting")
nodo.setAttribute("value",settings_dic[key])
nodo.setAttribute("id",key)
new_settings_root.appendChild(nodo)
fichero = open(configfilepath, "w")
fichero.write(new_settings.toprettyxml(encoding='utf-8'))
fichero.close()
# Fichero de configuración
def __init__(self, cls, db_name, db_user, db_passwd,
db_host, db_port, db_table, ddl_dir, enable_ssl):
self.cls = cls
if not db_name:
db_name = cls.__name__.lower()
self.db_name = db_name
self.db_user = db_user
self.db_passwd = db_passwd
self.db_host = db_host
self.db_port = db_port
self.db_table = db_table
self.ddl_dir = ddl_dir
self.s3 = None
self.converter = XMLConverter(self)
self.impl = getDOMImplementation()
self.doc = self.impl.createDocument(None, 'objects', None)
self.connection = None
self.enable_ssl = enable_ssl
self.auth_header = None
if self.db_user:
base64string = encodebytes('%s:%s' % (self.db_user, self.db_passwd))[:-1]
authheader = "Basic %s" % base64string
self.auth_header = authheader
def _WriteConfigFile(config_path, issues_dict):
new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
top_element = new_dom.documentElement
top_element.appendChild(new_dom.createComment(_DOC))
for issue_id in sorted(issues_dict.keys()):
severity = issues_dict[issue_id].severity
paths = issues_dict[issue_id].paths
issue = new_dom.createElement('issue')
issue.attributes['id'] = issue_id
if severity:
issue.attributes['severity'] = severity
if severity == 'ignore':
print 'Warning: [%s] is suppressed globally.' % issue_id
else:
for path in sorted(paths):
ignore = new_dom.createElement('ignore')
ignore.attributes['path'] = path
issue.appendChild(ignore)
top_element.appendChild(issue)
with open(config_path, 'w') as f:
f.write(new_dom.toprettyxml(indent=' ', encoding='utf-8'))
print 'Updated %s' % config_path
def make_xmlresponse(result):
""" construct a response from a dict of uri:error_code elements """
doc = minidom.getDOMImplementation().createDocument(None, "multistatus", None)
doc.documentElement.setAttribute("xmlns:D","DAV:")
doc.documentElement.tagName = "D:multistatus"
for el,ec in result.items():
re=doc.createElementNS("DAV:","response")
hr=doc.createElementNS("DAV:","href")
st=doc.createElementNS("DAV:","status")
huri=doc.createTextNode(quote_uri(el))
t=doc.createTextNode(gen_estring(ec))
st.appendChild(t)
hr.appendChild(huri)
re.appendChild(hr)
re.appendChild(st)
doc.documentElement.appendChild(re)
return doc.toxml(encoding="utf-8")
# taken from App.Common
def save(self, cache_file):
xml = getDOMImplementation().createDocument(
None, "xenserver-network-configuration", None)
for (ref,rec) in self.__pifs.items():
self.__to_xml(xml, xml.documentElement, _PIF_XML_TAG, ref, rec, _PIF_ATTRS)
for (ref,rec) in self.__bonds.items():
self.__to_xml(xml, xml.documentElement, _BOND_XML_TAG, ref, rec, _BOND_ATTRS)
for (ref,rec) in self.__vlans.items():
self.__to_xml(xml, xml.documentElement, _VLAN_XML_TAG, ref, rec, _VLAN_ATTRS)
for (ref,rec) in self.__tunnels.items():
self.__to_xml(xml, xml.documentElement, _TUNNEL_XML_TAG, ref, rec, _TUNNEL_ATTRS)
for (ref,rec) in self.__networks.items():
self.__to_xml(xml, xml.documentElement, _NETWORK_XML_TAG, ref, rec,
_NETWORK_ATTRS)
for (ref,rec) in self.__pools.items():
self.__to_xml(xml, xml.documentElement, _POOL_XML_TAG, ref, rec, _POOL_ATTRS)
temp_file = cache_file + ".%d" % os.getpid()
f = open(temp_file, 'w')
f.write(xml.toprettyxml())
f.close()
os.rename(temp_file, cache_file)
def set_settings(JsonRespuesta):
for Ajuste in JsonRespuesta:
settings_dic[Ajuste] = JsonRespuesta[Ajuste].encode("utf8")
from xml.dom import minidom
# Crea un Nuevo XML vacio
new_settings = minidom.getDOMImplementation().createDocument(None, "settings", None)
new_settings_root = new_settings.documentElement
for key in settings_dic:
nodo = new_settings.createElement("setting")
nodo.setAttribute("value", settings_dic[key])
nodo.setAttribute("id", key)
new_settings_root.appendChild(nodo)
fichero = open(configfilepath, "w")
fichero.write(new_settings.toprettyxml(encoding='utf-8'))
fichero.close()
# Fichero de configuración
def dict_to_xml(raw_item, sign=None):
dom = minidom.getDOMImplementation().createDocument(None, 'xml', None)
root = dom.documentElement
keys = raw_item.keys()
keys.sort()
for k in keys:
node = dom.createElement(k)
text = dom.createTextNode(raw_item[k].decode('utf-8'))
node.appendChild(text)
root.appendChild(node)
if sign is not None:
node = dom.createElement('sign')
node.appendChild(dom.createTextNode(sign))
root.appendChild(node)
return root.toprettyxml()
# xml???
def _WriteConfigFile(config_path, issues_dict):
new_dom = minidom.getDOMImplementation().createDocument(None, 'lint', None)
top_element = new_dom.documentElement
top_element.appendChild(new_dom.createComment(_DOC))
for issue_id, issue in sorted(issues_dict.iteritems(), key=lambda i: i[0]):
issue_element = new_dom.createElement('issue')
issue_element.attributes['id'] = issue_id
if issue.severity:
issue_element.attributes['severity'] = issue.severity
if issue.severity == 'ignore':
print 'Warning: [%s] is suppressed globally.' % issue_id
else:
for path in sorted(issue.paths):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['path'] = path
issue_element.appendChild(ignore_element)
for regexp in sorted(issue.regexps):
ignore_element = new_dom.createElement('ignore')
ignore_element.attributes['regexp'] = regexp
issue_element.appendChild(ignore_element)
top_element.appendChild(issue_element)
with open(config_path, 'w') as f:
f.write(new_dom.toprettyxml(indent=' ', encoding='utf-8'))
print 'Updated %s' % config_path
def create_doc_without_doctype(doctype=None):
return getDOMImplementation().createDocument(None, "doc", doctype)
def create_nonempty_doctype():
doctype = getDOMImplementation().createDocumentType("doc", None, None)
doctype.entities._seq = []
doctype.notations._seq = []
notation = xml.dom.minidom.Notation("my-notation", None,
"http://xml.python.org/notations/my")
doctype.notations._seq.append(notation)
entity = xml.dom.minidom.Entity("my-entity", None,
"http://xml.python.org/entities/my",
"my-notation")
entity.version = "1.0"
entity.encoding = "utf-8"
entity.actualEncoding = "us-ascii"
doctype.entities._seq.append(entity)
return doctype
def testRenameOther(self):
# We have to create a comment node explicitly since not all DOM
# builders used with minidom add comments to the DOM.
doc = xml.dom.minidom.getDOMImplementation().createDocument(
xml.dom.EMPTY_NAMESPACE, "e", None)
node = doc.createComment("comment")
self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
xml.dom.EMPTY_NAMESPACE, "foo")
doc.unlink()
def create_doc_without_doctype(doctype=None):
return getDOMImplementation().createDocument(None, "doc", doctype)
def create_nonempty_doctype():
doctype = getDOMImplementation().createDocumentType("doc", None, None)
doctype.entities._seq = []
doctype.notations._seq = []
notation = xml.dom.minidom.Notation("my-notation", None,
"http://xml.python.org/notations/my")
doctype.notations._seq.append(notation)
entity = xml.dom.minidom.Entity("my-entity", None,
"http://xml.python.org/entities/my",
"my-notation")
entity.version = "1.0"
entity.encoding = "utf-8"
entity.actualEncoding = "us-ascii"
doctype.entities._seq.append(entity)
return doctype
def testRenameOther(self):
# We have to create a comment node explicitly since not all DOM
# builders used with minidom add comments to the DOM.
doc = xml.dom.minidom.getDOMImplementation().createDocument(
xml.dom.EMPTY_NAMESPACE, "e", None)
node = doc.createComment("comment")
self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
xml.dom.EMPTY_NAMESPACE, "foo")
doc.unlink()
def create_doc_without_doctype(doctype=None):
return getDOMImplementation().createDocument(None, "doc", doctype)
def create_nonempty_doctype():
doctype = getDOMImplementation().createDocumentType("doc", None, None)
doctype.entities._seq = []
doctype.notations._seq = []
notation = xml.dom.minidom.Notation("my-notation", None,
"http://xml.python.org/notations/my")
doctype.notations._seq.append(notation)
entity = xml.dom.minidom.Entity("my-entity", None,
"http://xml.python.org/entities/my",
"my-notation")
entity.version = "1.0"
entity.encoding = "utf-8"
entity.actualEncoding = "us-ascii"
doctype.entities._seq.append(entity)
return doctype
def testRenameOther(self):
# We have to create a comment node explicitly since not all DOM
# builders used with minidom add comments to the DOM.
doc = xml.dom.minidom.getDOMImplementation().createDocument(
xml.dom.EMPTY_NAMESPACE, "e", None)
node = doc.createComment("comment")
self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
xml.dom.EMPTY_NAMESPACE, "foo")
doc.unlink()
def __init__(self, email_address):
impl = getDOMImplementation()
newdoc = impl.createDocument(None, "Autodiscover", None)
top_element = newdoc.documentElement
top_element.setAttribute("xmlns", "http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006")
req_elem = newdoc.createElement('Request')
top_element.appendChild(req_elem)
email_elem = newdoc.createElement('EMailAddress')
req_elem.appendChild(email_elem)
email_elem.appendChild(newdoc.createTextNode(email_address))
resp_schema = newdoc.createElement('AcceptableResponseSchema')
req_elem.appendChild(resp_schema)
resp_schema.appendChild(newdoc.createTextNode("http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006"))
self.body = newdoc.toxml("utf-8")
self.length = len(self.body)
def create_doc_without_doctype(doctype=None):
return getDOMImplementation().createDocument(None, "doc", doctype)
def create_nonempty_doctype():
doctype = getDOMImplementation().createDocumentType("doc", None, None)
doctype.entities._seq = []
doctype.notations._seq = []
notation = xml.dom.minidom.Notation("my-notation", None,
"http://xml.python.org/notations/my")
doctype.notations._seq.append(notation)
entity = xml.dom.minidom.Entity("my-entity", None,
"http://xml.python.org/entities/my",
"my-notation")
entity.version = "1.0"
entity.encoding = "utf-8"
entity.actualEncoding = "us-ascii"
doctype.entities._seq.append(entity)
return doctype
def testRenameOther(self):
# We have to create a comment node explicitly since not all DOM
# builders used with minidom add comments to the DOM.
doc = xml.dom.minidom.getDOMImplementation().createDocument(
xml.dom.EMPTY_NAMESPACE, "e", None)
node = doc.createComment("comment")
self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
xml.dom.EMPTY_NAMESPACE, "foo")
doc.unlink()
def serializeXML( data ):
def recursiveSerializer( data, element ):
if isinstance(data, dict):
element.setAttribute('ViurDataType', 'dict')
for key in data.keys():
childElement = recursiveSerializer(data[key], doc.createElement(key) )
element.appendChild( childElement )
elif isinstance(data, (tuple, list)):
element.setAttribute('ViurDataType', 'list')
for value in data:
childElement = recursiveSerializer(value, doc.createElement('entry') )
element.appendChild( childElement )
else:
if isinstance(data , bool):
element.setAttribute('ViurDataType', 'boolean')
elif isinstance( data, float ) or isinstance( data, int ):
element.setAttribute('ViurDataType', 'numeric')
elif isinstance( data, str ) or isinstance( data, unicode ):
element.setAttribute('ViurDataType', 'string')
elif isinstance( data, datetime ) or isinstance( data, date ) or isinstance( data, time ):
if isinstance( data, datetime ):
element.setAttribute('ViurDataType', 'datetime')
elif isinstance( data, date ):
element.setAttribute('ViurDataType', 'date')
else:
element.setAttribute('ViurDataType', 'time')
data = data.isoformat()
elif data is None:
element.setAttribute('ViurDataType', 'none')
data = ""
else:
raise NotImplementedError("Type %s is not supported!" % type(data))
element.appendChild( doc.createTextNode( unicode(data) ) )
return element
dom = minidom.getDOMImplementation()
doc = dom.createDocument(None, u"ViurResult", None)
elem = doc.childNodes[0]
return( recursiveSerializer( data, elem ).toprettyxml(encoding="UTF-8") )
def create_doc_without_doctype(doctype=None):
return getDOMImplementation().createDocument(None, "doc", doctype)