[Libvirt-cim] [PATCH] [TEST] add a try..except to get_value_xpath()

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Wed Apr 9 09:45:12 UTC 2008



zli at linux.vnet.ibm.com wrote:
> # HG changeset patch
> # User Zhengang Li <lizg at cn.ibm.com>
> # Date 1207733009 -28800
> # Node ID 87913147308d5075130dcae5b5648cc3f0158681
> # Parent  262153788503c8b10c76c77719bba081df9a7b88
> [TEST] add a try..except to get_value_xpath()
>
> A 'None' return is more elegant than a pure exception error.
>
> Signed-off-by: Zhengang Li <lizg at cn.ibm.com>
>
> diff -r 262153788503 -r 87913147308d suites/libvirt-cim/lib/XenKvmLib/vxml.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Tue Apr 08 17:58:44 2008 +0530
> +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Wed Apr 09 17:23:29 2008 +0800
> @@ -115,7 +115,12 @@ class XMLClass:
>          return self.xdoc.toprettyxml()
>
>      def get_value_xpath(self, xpathStr):
> -        node = self.get_node(xpathStr)
> +        try:
> +            node = self.get_node(xpathStr)
> +        except LoopUpError:
>   
I think this should be *LookUpError.*
> +            raise Exception('Zero or multiple node found')
>   
And can we use logger.error instead, I guess using raise statement does 
not proceed with the execution of the next stmt after it, right ??
In that case the return None wont be of much use.
**
> +            return None
> +
>          if node.nodeType == Node.ATTRIBUTE_NODE:
>              return node.value
>          if node.nodeType == Node.TEXT_NODE:
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>   




More information about the Libvirt-cim mailing list