root / ncclient / listener.py @ efc6b445
History | View | Annotate | Download (1.2 kB)
1 |
# Copyright 2009 Shikhar Bhushan
|
---|---|
2 |
#
|
3 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
# you may not use this file except in compliance with the License.
|
5 |
# You may obtain a copy of the License at
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
#
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
|
15 |
from content import rpc |
16 |
|
17 |
class SessionListener: |
18 |
|
19 |
def __init__(self): |
20 |
self._id2rpc = {}
|
21 |
self._sub_id = None # message-id of <create-subscription> request |
22 |
|
23 |
def set_subscription(self, id): |
24 |
self._subscription = id |
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 |
|
34 |
def reply(self, raw): |
35 |
id = rpc.parse(raw) |
36 |
if id: |
37 |
self._id2rpc[id]._deliver(raw) |
38 |
else:
|
39 |
self._id2rpc[self._sub_id]._notify(raw) |
40 |
|
41 |
def close(self, buf): |
42 |
pass # TODO |