Revision ee4bb099 ncclient/rpc.py

b/ncclient/rpc.py
13 13
# limitations under the License.
14 14

  
15 15
from threading import Event, Lock
16

  
17
from listener import SessionListener
18

  
19 16
from uuid import uuid1
20 17

  
18
import content
19
from listeners import session_listener_factory
20

  
21 21
class RPC:
22 22
    
23
    def __init__(self, session, async=False):
23
    def __init__(self, session, async=False, parse=True):
24 24
        self._session = session
25 25
        self._async = async
26
        self._id = uuid1().urn
27
        self._listener = session_listener_factory(self._session)
28
        listener.register(self._id, self)
29
        session.add_listener(self._listener)
26 30
        self._reply = None
27 31
        self._reply_event = Event()
28
        self._id = uuid1().urn
29 32

  
30
    def _listener(self):
31
        if not RPC.listeners.has_key(self._session.id):
32
            RPC.listeners[self._session.id] = SessionListener()
33
        return RPC.listeners[self._session.id]
34

  
35
    def request(self, async=False):
36
        self._async = async
37
        listener = SessionListener(self._session.id)
38
        session.add_listener(listener)
39
        listener.register(self._id, self)
40
        self._session.send(self.to_xml())
41
    
42
    def response_cb(self, reply):
43
        self._reply = reply # does callback parse??
33
    def _response_cb(self, reply):
34
        self._reply = reply
44 35
        self._event.set()
45 36
    
37
    def _do_request(self, op):
38
        self._session.send(content.make_rpc(self._id, op))
39
        if not self._async:
40
            self._reply_event.wait()
41
        return self._reply
42
    
43
    def request(self):
44
        raise NotImplementedError
45
    
46
    def wait_for_reply(self, timeout=None):
47
        self._reply_event.wait(timeout)
48
    
46 49
    @property
47 50
    def has_reply(self):
48 51
        return self._reply_event.isSet()
49 52
    
50
    def wait_on_reply(self, timeout=None):
51
        self._reply_event.wait(timeout)
52
    
53 53
    @property
54 54
    def is_async(self):
55 55
        return self._async
56 56
    
57 57
    @property
58
    def reply(self):
59
        return self._reply
60
    
61
    @property
58 62
    def id(self):
59
        return self._id
63
        return self._id
64
    
65
    @property
66
    def session(self):
67
        return self._session
68

  
69

  
70
class RPCReply:
71
    pass
72

  
73
class RPCError:
74
    pass

Also available in: Unified diff