This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/299/ |
src/python/openlmi/common/__init__.py (Diff revision 1) | |||
---|---|---|---|
25 | def parse_instance_id(instance_id, classname=None): |
||
26 | """ |
||
27 | Parse InstanceID, check it has LMI:<classname>:<ID> format and return |
||
28 | the ID. Return None if the format is bad. |
||
29 | :param instance_id: (``string``) String to parse. |
||
30 | :param classname: (``string``) Name of class, whose InstanceID we parse. |
||
31 | If the classname is None, it won't be checked. |
||
32 | :returns: ``string`` with the ID. |
||
33 | """ |
||
34 | parts = instance_id.split(":", 2) |
||
35 | if len(parts) != 3: |
||
36 | return None |
||
37 | if parts[0] != "LMI": |
||
38 | return None |
||
39 | real_classname = parts[1] |
||
40 | if classname and real_classname != classname: |
||
41 | return None |
||
42 | return parts[2] |
I agree with Roman, I'm just not sure if the CIM error is the correct one to use here: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, 'Failed to parse id "%s"' % instance_id) Looking at your code, it seems that you don't parse the user's input but something generated by your code. In that case I would go for a new subclass of ValueError.
- Michal
On May 2nd, 2013, 9:01 a.m. UTC, Jan Safranek wrote:
Review request for OpenLMI Developers.
By Jan Safranek.
Updated May 2, 2013, 9:01 a.m.
Repository:
openlmi-providers
Description
Diffs
|