Revision 35ad9d81 ncclient/session.py
b/ncclient/session.py | ||
---|---|---|
13 | 13 |
# limitations under the License. |
14 | 14 |
|
15 | 15 |
import logging |
16 |
|
|
17 | 16 |
from threading import Thread, Event |
18 | 17 |
from Queue import Queue |
19 | 18 |
|
20 |
from error import ClientError |
|
21 |
from content import hello |
|
22 |
from listener import Subject |
|
23 | 19 |
from capability import CAPABILITIES |
20 |
from content import hello |
|
21 |
from error import ClientError |
|
22 |
from subject import Subject |
|
24 | 23 |
|
25 | 24 |
logger = logging.getLogger('ncclient.session') |
26 | 25 |
|
27 |
class SessionError(ClientError): pass |
|
26 |
class SessionError(ClientError): |
|
27 |
|
|
28 |
pass |
|
28 | 29 |
|
29 | 30 |
class Session(Thread, Subject): |
30 | 31 |
|
... | ... | |
39 | 40 |
self._init_event = Event() |
40 | 41 |
self._q = Queue() |
41 | 42 |
|
42 |
def _close(self): |
|
43 |
self._connected = False |
|
44 |
|
|
45 |
def _init(self): |
|
46 |
self._connected = True |
|
47 |
# start the subclass' main loop |
|
48 |
self.start() |
|
49 |
# queue client's hello message for sending |
|
50 |
self.send(hello.make(self._client_capabilities)) |
|
51 |
# we expect server's hello message, wait for _init_event to be set by HelloListener |
|
52 |
self._init_event.wait() |
|
53 |
# there may have been an error |
|
54 |
if self._error: |
|
55 |
self._close() |
|
56 |
raise self._error |
|
57 |
|
|
58 | 43 |
def connect(self): |
59 | 44 |
raise NotImplementedError |
60 | 45 |
|
... | ... | |
69 | 54 |
### Properties |
70 | 55 |
|
71 | 56 |
@property |
72 |
def client_capabilities(self): return self._client_capabilities |
|
57 |
def client_capabilities(self): |
|
58 |
return self._client_capabilities |
|
73 | 59 |
|
74 | 60 |
@property |
75 |
def serve_capabilities(self): return self._server_capabilities |
|
61 |
def serve_capabilities(self): |
|
62 |
return self._server_capabilities |
|
76 | 63 |
|
77 | 64 |
@property |
78 |
def connected(self): return self._connected |
|
65 |
def connected(self): |
|
66 |
return self._connected |
|
79 | 67 |
|
80 | 68 |
@property |
81 |
def id(self): return self._id |
|
69 |
def id(self): |
|
70 |
return self._id |
|
82 | 71 |
|
83 | 72 |
class HelloListener: |
84 | 73 |
|
... | ... | |
106 | 95 |
|
107 | 96 |
def close(self, err): |
108 | 97 |
self._done(err) |
98 |
|
|
99 |
### Methods for which subclasses should call super after they are done |
|
100 |
|
|
101 |
def _connect(self): |
|
102 |
self._connected = True |
|
103 |
# start the subclass' main loop |
|
104 |
self.start() |
|
105 |
# queue client's hello message for sending |
|
106 |
self.send(hello.make(self._client_capabilities)) |
|
107 |
# we expect server's hello message, wait for _init_event to be set by HelloListener |
|
108 |
self._init_event.wait() |
|
109 |
# there may have been an error |
|
110 |
if self._error: |
|
111 |
self._close() |
|
112 |
raise self._error |
|
113 |
|
|
114 |
def _close(self): |
|
115 |
self._connected = False |
Also available in: Unified diff