Revision 6c70b245 ncclient/operations/rpc.py

b/ncclient/operations/rpc.py
249 249
    # subclass of :class:`RPCReply`.
250 250
    REPLY_CLS = RPCReply
251 251

  
252
    def __init__(self, session, async=False, timeout=None):
252
    def __init__(self, session, async=False, timeout=None, raise_mode='none'):
253 253
        self._session = session
254 254
        try:
255 255
            for cap in self.DEPENDS:
......
258 258
            pass
259 259
        self._async = async
260 260
        self._timeout = timeout
261
        self._raise_mode = raise_mode
261 262
        # keeps things simple instead of having a class attr that has to be locked
262 263
        self._id = uuid1().urn
263
        # RPCReplyListener itself makes sure there isn't more than one instance -- i.e. multiton
264 264
        self._listener = RPCReplyListener(session)
265 265
        self._listener.register(self._id, self)
266 266
        self._reply = None
......
305 305
            self._event.wait(self._timeout)
306 306
            if self._event.isSet():
307 307
                if self._error:
308
                    # Error that prevented reply delivery
308 309
                    raise self._error
309 310
                self._reply.parse()
311
                if self._reply.error is not None:
312
                    # <rpc-error>'s [ RPCError ]
313
                    if self._raise_mode == "all":
314
                        raise self._reply._error
315
                    elif (self._raise_mode == "errors" and
316
                          self._reply.error.type == "error"):
317
                        raise self._reply.error
310 318
                return self._reply
311 319
            else:
312 320
                raise TimeoutExpiredError
......
315 323
        """Subclasses implement this method. Here, the operation is constructed
316 324
        in :ref:`dtree`, and the result of :meth:`_request` returned."""
317 325
        return self._request(self.SPEC)
318

  
319
    #def _delivery_hook(self):
320
    #    """Subclasses can implement this method. Will be called after
321
    #    initialising the :attr:`reply` or :attr:`error` attribute and before
322
    #    setting the :attr:`event`"""
323
    #    pass
324

  
326
    
325 327
    def _assert(self, capability):
326 328
        """Subclasses can use this method to verify that a capability is available
327 329
        with the NETCONF server, before making a request that requires it. A
......
386 388
        if async and not session.can_pipeline:
387 389
            raise UserWarning('Asynchronous mode not supported for this device/session')
388 390

  
389
    def set_raise_mode(self, choice):
391
    def set_raise_mode(self, mode):
390 392
        assert(choice in ('all', 'errors', 'none'))
391
        self._raise = choice
393
        self._raise_mode = mode
392 394

  
393 395
    def set_timeout(self, timeout):
394 396
        """Set the timeout for synchronous waiting defining how long the RPC

Also available in: Unified diff