Revision 41e2ed46 ncclient/operations/reply.py
b/ncclient/operations/reply.py | ||
---|---|---|
17 | 17 |
from ncclient.content import multiqualify as _ |
18 | 18 |
from ncclient.content import unqualify as __ |
19 | 19 |
|
20 |
import logging |
|
21 |
logger = logging.getLogger('ncclient.operations.reply') |
|
22 |
|
|
20 | 23 |
class RPCReply: |
21 | 24 |
|
22 | 25 |
def __init__(self, raw): |
23 |
self._raw = None
|
|
26 |
self._raw = raw
|
|
24 | 27 |
self._parsed = False |
25 | 28 |
self._errors = [] |
26 | 29 |
|
... | ... | |
28 | 31 |
return self._raw |
29 | 32 |
|
30 | 33 |
def parse(self): |
31 |
root = ET.fromstring(raw) # <rpc-reply> element |
|
34 |
root = ET.fromstring(self._raw) # <rpc-reply> element
|
|
32 | 35 |
|
33 | 36 |
# per rfc 4741 an <ok/> tag is sent when there are no errors or warnings |
34 | 37 |
oktags = _('ok') |
35 | 38 |
for oktag in oktags: |
36 | 39 |
if root.find(oktag) is not None: |
40 |
logger.debug('found %s' % oktag) |
|
41 |
self._parsed = True |
|
37 | 42 |
return |
38 | 43 |
|
39 | 44 |
# create RPCError objects from <rpc-error> elements |
... | ... | |
46 | 51 |
self._errors.append(RPCError(d)) |
47 | 52 |
if self._errors: |
48 | 53 |
break |
54 |
self._parsed = True |
|
49 | 55 |
|
50 | 56 |
@property |
51 | 57 |
def raw(self): |
... | ... | |
53 | 59 |
|
54 | 60 |
@property |
55 | 61 |
def ok(self): |
56 |
if not self._parsed: |
|
57 |
self.parse() |
|
58 |
return bool(self._errors) # empty list = false |
|
62 |
if not self._parsed: self.parse() |
|
63 |
return not bool(self._errors) # empty list = false |
|
59 | 64 |
|
60 | 65 |
@property |
61 | 66 |
def errors(self): |
62 | 67 |
'List of RPCError objects. Will be empty if no <rpc-error> elements in reply.' |
63 |
if not self._parsed: |
|
64 |
self.parse() |
|
68 |
if not self._parsed: self.parse() |
|
65 | 69 |
return self._errors |
66 | 70 |
|
67 | 71 |
|
Also available in: Unified diff