Revision d6688264 ncclient/rpc/rpc.py
b/ncclient/rpc/rpc.py | ||
---|---|---|
27 | 27 |
import logging |
28 | 28 |
logger = logging.getLogger('ncclient.rpc') |
29 | 29 |
|
30 |
|
|
31 | 30 |
class RPC(object): |
32 | 31 |
|
32 |
DEPENDS = [] |
|
33 |
REPLY_CLS = RPCReply |
|
34 |
|
|
33 | 35 |
def __init__(self, session, async=False, timeout=None): |
34 | 36 |
if not session.can_pipeline: |
35 | 37 |
raise UserWarning('Asynchronous mode not supported for this device/session') |
36 | 38 |
self._session = session |
39 |
try: |
|
40 |
for cap in self.DEPENDS: |
|
41 |
self.assert_capability(cap) |
|
42 |
except AttributeError: |
|
43 |
pass |
|
37 | 44 |
self._async = async |
38 | 45 |
self._timeout = timeout |
39 | 46 |
self._id = uuid1().urn |
... | ... | |
51 | 58 |
} |
52 | 59 |
return TreeBuilder(spec).to_string(encoding) |
53 | 60 |
|
54 |
def _request(self, op, timeout=None):
|
|
61 |
def _request(self, op): |
|
55 | 62 |
req = self._build(op) |
56 | 63 |
self._session.send(req) |
57 | 64 |
if self._async: |
58 | 65 |
return self._reply_event |
59 | 66 |
else: |
60 |
self._reply_event.wait(timeout) |
|
67 |
self._reply_event.wait(self._timeout)
|
|
61 | 68 |
if self._reply_event.isSet(): |
62 | 69 |
self._reply.parse() |
63 | 70 |
return self._reply |
... | ... | |
68 | 75 |
'For subclasses' |
69 | 76 |
pass |
70 | 77 |
|
78 |
def _assert(self, capability): |
|
79 |
if capability not in self._session.server_capabilities: |
|
80 |
raise MissingCapabilityError('Server does not support [%s]' % cap) |
|
81 |
|
|
71 | 82 |
def deliver(self, raw): |
72 |
self._reply = RPCReply(raw)
|
|
83 |
self._reply = self.REPLY_CLS(raw)
|
|
73 | 84 |
self._delivery_hook() |
74 | 85 |
self._reply_event.set() |
75 | 86 |
|
Also available in: Unified diff