Revision efc6b445

b/ncclient/listener.py
18 18

  
19 19
    def __init__(self):
20 20
        self._id2rpc = {}
21
        self._subscription_id = None # notifications are delivered to the rpc
22
                                    # that created the subscription
21
        self._sub_id = None # message-id of <create-subscription> request
23 22
    
24 23
    def set_subscription(self, id):
25 24
        self._subscription = id
26 25
    
26
    def register(self, id, op):
27
        self._id2rpc[id] = op
28
    
29
    def unregister(self, id):
30
        del self._id2prc[id]
31
    
32
    ### Events
33
    
27 34
    def reply(self, raw):
28
        id, is_notification = rpc.parse(raw)
29
        if is_notification:
30
            self._id2rpc[self._subscription_id].event(raw)
31
        else:
35
        id = rpc.parse(raw)
36
        if id:
32 37
            self._id2rpc[id]._deliver(raw)
33
            del self._id2rpc[id]
38
        else:
39
            self._id2rpc[self._sub_id]._notify(raw)
34 40
    
35
    def error(self, buf):
36
        pass
41
    def close(self, buf):
42
        pass # TODO
b/ncclient/rpc.py
12 12
# See the License for the specific language governing permissions and
13 13
# limitations under the License.
14 14

  
15
import content
16

  
17 15
from threading import Event
18 16

  
19
from listener import RPCReplyListener
17
from listener import SessionListener
20 18

  
21 19
class RPC:
22 20
    
......
52 50
    @property
53 51
    def listener(self):
54 52
        if RPC.listeners[self._sid] is None:
55
            RPC.listeners[self.sid] = listener.RPCReplyListener()
53
            RPC.listeners[self.sid] = SessionListener()
56 54
        return RPC.listeners[self._sid]
57
    
58
    @property
59
    def ok(self):
60
        pass
61
    
55

  
62 56
    def _next_id(self):
63 57
        RPC.current_id[self._session.id] = RPC.current_id.get(self._session.id, 0) + 1
64 58
        return RPC.current_id[self._sid]
65
    
66
class RPCReply:
67
    
68
    def __init__(self, id, raw):
69
        self._id = id
70
        self._raw = raw
71
    
72
    @property
73
    def id(self):
74
        return self._id
75
    
76
class RPCError(NETCONFError):
77
    pass
b/ncclient/session.py
13 13
# limitations under the License.
14 14

  
15 15
import logging
16

  
17
import content
18

  
16 19
from threading import Thread, Event
17 20
from Queue import Queue
18 21

  
19 22
from capability import CAPABILITIES
20
from content import hello
21 23
from error import ClientError
22 24
from subject import Subject
23 25

  
......
80 82
            self._session.remove_listener(self)
81 83
            self._session._init_event.set()
82 84
        
83
        ### Events
84
        
85 85
        def reply(self, data):
86 86
            err = None
87 87
            try:
88
                id, capabilities = hello.parse(data)
88
                id, capabilities = content.parse_hello(data)
89 89
                logger.debug('session_id: %s | capabilities: \n%s', id, capabilities)
90 90
                self._session._id, self._session.capabilities = id, capabilities
91 91
            except Exception as e:
......
103 103
        # start the subclass' main loop
104 104
        self.start()
105 105
        # queue client's hello message for sending
106
        self.send(hello.make(self._client_capabilities))
106
        self.send(content.make_hello(self._client_capabilities))
107 107
        # we expect server's hello message, wait for _init_event to be set by HelloListener
108 108
        self._init_event.wait()
109 109
        # there may have been an error
b/ncclient/subject.py
16 16

  
17 17
import logging
18 18

  
19
logger = logging.getLogger('ncclient.listener')
19
logger = logging.getLogger('ncclient.subject')
20 20

  
21 21
class Subject:
22 22
        

Also available in: Unified diff