我有一个名为zms_add_bridge
的函数调用一个名为xmlbuilder
的函数。 xmlbuilder
创建一个名为xml
的全局变量,并用东西填充它。
当调用zms_add_bridge
时,它会打印“here”,表示它至少在脚本中已经到了那么远。然后,它调用xmlbuilder
,它打印“xml1”以及xml输出,说它至少在脚本中得到了那么远。
问题是,一旦xmlbuilder退出并返回zms_add_bridge,脚本似乎就会死掉。 xml
是一个全局变量,因此它应该打印“是”,但它甚至不打印“否”。
我甚至在return xml
结束时尝试xmlbuilder
来查看这是否有效,但事实并非如此(甚至仍然是多余的,因为xml
是def xmlbuilder(requestType,xbra):
global xmlbuild
global xmlbuild__request
global xmlbuild__requestElement
global xmlbuild__requestElementAttribute
global xml
xmlbuild = etree.Element("OSS", attrib={"{"+xsi+"}schemaLocation":schema}, nsmap={'xsi':xsi, None:xmlns})
xmlbuild__request = etree.SubElement(xmlbuild, "Request")
etree.SubElement(xmlbuild__request, "RequestType").text = requestType
etree.SubElement(xmlbuild__request, "RequestMode").text = "online"
etree.SubElement(xmlbuild__request, "SessionID").text = session_id
etree.SubElement(xmlbuild__request, "operName").text = apiUser
etree.SubElement(xmlbuild__request, "Version").text = version
etree.SubElement(xmlbuild__request, "Overwrite").text = "false"
xmlbuild__requestElement = etree.SubElement(xmlbuild, "RequestElement")
for index, data in xbra.items():
for key in data:
xmlbuild__requestElementAttribute = etree.SubElement(xmlbuild__requestElement, "Attribute")
etree.SubElement(xmlbuild__requestElementAttribute, "Name").text = "%s" % key
etree.SubElement(xmlbuild__requestElementAttribute, "Value").text = "%s" % data[key]
xml = etree.tostring(xmlbuild, encoding="UTF-8", pretty_print=True, xml_declaration=True)
if debug >= 1:
print "\nDEBUG: Generated XML for transmission\n"
print xml
print "xml1: " + xml
def zms_add_bridge(fsan,vlanId,maxUnicast,secure):
if debug >= 3:
print "\nDEBUG: Function: zms_add_bridge\n"
print "\nDEBUG: Get GPON parameters of ONT\n"
xbra = defaultdict(list)
xbra[1] = {'Filter_Type': 'GponOnuPhysical'}
xbra[2] = {'Filter_Condition': 'Device_Id=' + device_Handle_Id}
xbra[3] = {'Filter_Condition': 'serialNoVendorId=ZNTS'}
xbra[4] = {'Filter_Condition': 'serialNoVendorSpecificHex=' + fsan}
if debug >= 4:
print "\nDEBUG: Dictionary\n"
for index, data in xbra.items():
for key in data:
print "Index: %s: Key: %s, Value: %s" % (index, key,data[key])
print "here"
xmlbuilder("list",xbra)
if xml:
print "yes"
else:
print "no"
全球宣布,不是吗?)
任何线索?我输了。
here
xml1: <?xml version='1.0' encoding='UTF-8'?>
<OSS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zhone.com/OSSXML" xsi:schemaLocation="http://www.zhone.com/OSSXML ossxml.xsd">
<Request>
<RequestType>list</RequestType>
<RequestMode>online</RequestMode>
<SessionID>0.379081153249641</SessionID>
<operName>boss</operName>
<Version>2.5.1</Version>
<Overwrite>false</Overwrite>
</Request>
<RequestElement>
<Attribute>
<Name>Filter_Type</Name>
<Value>GponOnuPhysical</Value>
</Attribute>
<Attribute>
<Name>Filter_Condition</Name>
<Value>Device_Id=2</Value>
</Attribute>
<Attribute>
<Name>Filter_Condition</Name>
<Value>serialNoVendorId=ZNTS</Value>
</Attribute>
<Attribute>
<Name>Filter_Condition</Name>
<Value>serialNoVendorSpecificHex=03739175</Value>
</Attribute>
</RequestElement>
</OSS>
输出:
ListenPropertyChange = true