summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schwarz <david.schwarz@calxeda.com>2012-02-15 15:23:59 -0600
committerDavid Schwarz <david.schwarz@calxeda.com>2012-02-15 15:23:59 -0600
commita4cbc3c1de64fbadc87b4ca98831e0ca2e84dac9 (patch)
tree77046e1c5f13a3bf009bc126e76441d37d0b04ae
parentf8f4bfe30f223cb8a5b76a597ab919465825a892 (diff)
downloadpyipmi-a4cbc3c1de64fbadc87b4ca98831e0ca2e84dac9.tar.gz
Fix result parsing errors:
- Generically handle parse simple methods that don't take keyword arguments - parse_colon_record loop was quitting one line too soon - parse_colon_record_list sometimes left a blank line at the beginning of a record, causing parse_colon_record to bail
-rw-r--r--pyipmi/commands/sel.py12
-rw-r--r--pyipmi/tools/responseparser.py17
2 files changed, 16 insertions, 13 deletions
diff --git a/pyipmi/commands/sel.py b/pyipmi/commands/sel.py
index bc06e43..9bc7106 100644
--- a/pyipmi/commands/sel.py
+++ b/pyipmi/commands/sel.py
@@ -61,7 +61,7 @@ class SELInfoCommand(Command, ResponseParserMixIn):
response_fields = {
'Version' : {'parser': version_parser},
- 'Entries' : {'parser': int},
+ 'Entries' : {'parser': lambda s: int(s)},
'Free Space' : {'parser': lambda s: int(s[:-6])}, #removes ' bytes'
'Last Add Time' : {'parser': lambda ts: SELTimestamp(ts)},
'Last Del Time' : {'parser': lambda ts: SELTimestamp(ts)},
@@ -78,11 +78,11 @@ class SELAllocInfoCommand(Command, ResponseParserMixIn):
result_type = SELAllocInfo
response_fields = {
- '# of Alloc Units' : {'attr': 'num_alloc_units', 'parser': int},
- 'Alloc Unit Size' : {'parser': int},
- '# Free Units' : {'attr': 'num_free_units', 'parser': int},
- 'Largest Free Blk' : {'parser': int},
- 'Max Record Size' : {'parser': int}
+ '# of Alloc Units' : {'attr': 'num_alloc_units', 'parser': lambda s: int(s)},
+ 'Alloc Unit Size' : {'parser': lambda s: int(s)},
+ '# Free Units' : {'attr': 'num_free_units', 'parser': lambda s: int(s)},
+ 'Largest Free Blk' : {'parser': lambda s: int(s)},
+ 'Max Record Size' : {'parser': lambda s: int(s)}
}
diff --git a/pyipmi/tools/responseparser.py b/pyipmi/tools/responseparser.py
index 002affc..41e70ed 100644
--- a/pyipmi/tools/responseparser.py
+++ b/pyipmi/tools/responseparser.py
@@ -3,6 +3,7 @@
from pyipmi import IpmiError
import string
+import inspect
def str_to_list(val, **params):
@@ -15,7 +16,7 @@ def str_to_list(val, **params):
return map(string.strip, val.split(delimiter))
-def str2bool(val, **params):
+def str2bool(val):
"""True if val is 'true', 'yes' or 'enabled, otherwise false"""
return val.lower() in ['true', 'yes', 'enabled']
@@ -37,7 +38,7 @@ def str_to_dict(val, **params):
return result
-def paren_pair(val, **params):
+def paren_pair(val):
"""Convert 'foo (bar)' to ['foo', 'bar']"""
return [p.strip(' )') for p in val.split('(')]
@@ -96,7 +97,7 @@ class ResponseParserMixIn(object):
obj = result_type()
line, sep, rest = response.partition('\n')
left_over = []
- while sep != '':
+ while line != '':
colon_index = 10000000
if line.find(':') != -1:
colon_index = line.index(':')
@@ -143,7 +144,7 @@ class ResponseParserMixIn(object):
results = []
records = response.split('\n\n')
for record in records:
- obj = self.parse_colon_record(record, err)
+ obj = self.parse_colon_record(record.strip(), err)
if obj == None:
continue
@@ -184,11 +185,13 @@ class ResponseParserMixIn(object):
it, and the result will be assigned to the attribute. The default
parser is str().
"""
- str_params = lambda x, **y: str(x)
-
+ str_func = lambda x: str(x)
attr_name = field_info.get('attr', field_to_attr(field_name))
- attr_parser = field_info.get('parser', str_params)
+ attr_parser = supplied_parser = field_info.get('parser', str_func)
+ args, varargs, keywords, defaults = inspect.getargspec(attr_parser)
+ if keywords == None:
+ attr_parser = lambda x, **y: supplied_parser(x)
setattr(obj, attr_name, attr_parser(value, **field_info))
def get_response_types(self, response):