Stores the credential of currently logged in UCS in current session to a file. Password will be stored in encrypted format using key.

    - filePath specifies the path of the credential file.
    - key specifies any string used for secure encryption.
    - merge should be set as False unless user wants to append the existing credential file with new credential.

def ExportUcsSession(filePath, key, merge=YesOrNo.FALSE):
	"""
    Stores the credential of currently logged in UCS in current session to a file. Password will be stored in encrypted format using key.

    - filePath specifies the path of the credential file.
    - key specifies any string used for secure encryption.
    - merge should be set as False unless user wants to append the existing credential file with new credential.
    """
	from UcsBase import UcsUtils, WriteUcsWarning, UcsValidationException
	# from p3 import p3_encrypt, p3_decrypt

	if filePath is None:
		raise UcsValidationException("filePath parameter is not provided.")
	# raise Exception('[Error]: Please provide filePath')

	if key is None:
		raise UcsValidationException("key parameter is not provided.")
	# raise Exception('[Error]: Please provide key')

	doc = xml.dom.minidom.Document()
	nodeList = None

	if merge in _AffirmativeList and os.path.isfile(
			filePath):  # isfile() checks for file. exists() return true for directory as well
		doc = xml.dom.minidom.parse(filePath)
		# nodeList = doc.documentElement._get_childNodes()
		nodeList = doc.documentElement.childNodes
	else:
		doc.appendChild(doc.createElement(UcsLoginXml.UCS_HANDLES))

	hUcsArray = defaultUcs.values()

	if hUcsArray != None:
		for hUcs in hUcsArray:
			updated = False
			if nodeList != None:
				for childNode in nodeList:
					if (childNode.nodeType != Node.ELEMENT_NODE):
						continue

					elem = childNode
					if ((not elem.hasAttribute(UcsLoginXml.NAME)) or (not elem.hasAttribute(UcsLoginXml.USER_NAME))):
						continue
					if ((elem.getAttribute(UcsLoginXml.NAME) != hUcs._name) or (
								elem.getAttribute(UcsLoginXml.USER_NAME) != hUcs._username)):
						continue

					if hUcs._noSsl:
						elem.setAttribute(UcsLoginXml.NO_SSL, hUcs._noSsl)
					elif elem.hasAttribute(UcsLoginXml.NO_SSL):
						elem.removeAttribute(UcsLoginXml.NO_SSL)

					if ((hUcs._noSsl and (hUcs._port != 80)) or ((not hUcs._noSsl) and (hUcs._port != 443))):
						elem.setAttribute(UcsLoginXml.PORT, hUcs._port)
					elif elem.hasAttribute(UcsLoginXml.PORT):
						elem.removeAttribute(UcsLoginXml.PORT)

					# elem.setAttribute(UcsLoginXml.PASSWORD, p3_encrypt(hUcs._password,key))
					elem.setAttribute(UcsLoginXml.PASSWORD, UcsUtils.EncryptPassword(hUcs._password, key))

					updated = True
					break

			if updated:
				continue

			node = doc.createElement(UcsLoginXml.UCS)
			attr = doc.createAttribute(UcsLoginXml.NAME)
			attr.value = hUcs._name
			node.setAttributeNode(attr)
			attr = doc.createAttribute(UcsLoginXml.USER_NAME)
			attr.value = hUcs._username
			node.setAttributeNode(attr)

			if hUcs._noSsl:
				attr = doc.createAttribute(UcsLoginXml.NO_SSL)
				attr.value = hUcs._noSsl
				node.setAttributeNode(attr)

			if ((hUcs._noSsl and (hUcs._port != 80)) or ((not hUcs._noSsl) and (hUcs._port != 443))):
				attr = doc.createAttribute(UcsLoginXml.PORT)
				attr.value = hUcs._port
				node.setAttributeNode(attr)

			attr = doc.createAttribute(UcsLoginXml.PASSWORD)
			# attr.value = p3_encrypt(hUcs._password,key)
			attr.value = UcsUtils.EncryptPassword(hUcs._password, key)
			node.setAttributeNode(attr)

			doc.documentElement.insertBefore(node, doc.documentElement.lastChild)

	xmlNew = doc.toprettyxml(indent=" ")
	xmlNew = re.sub(r"^.*?xml version.*\n", "", xmlNew)
	xmlNew = re.sub(r"\n[\s]*\n", "\n", xmlNew)
	xmlNew = re.sub(r"^(.*)", r"\1", xmlNew, re.MULTILINE)

	f = open(filePath, 'w')
	f.write(xmlNew)
	f.close()