Revision ee4bb099 ncclient/session.py
b/ncclient/session.py | ||
---|---|---|
13 | 13 |
# limitations under the License. |
14 | 14 |
|
15 | 15 |
import logging |
16 |
|
|
17 |
import content |
|
18 |
|
|
19 | 16 |
from threading import Thread, Event |
20 | 17 |
from Queue import Queue |
21 | 18 |
|
22 |
from capability import CAPABILITIES |
|
19 |
import content |
|
20 |
from capabilities import CAPABILITIES |
|
23 | 21 |
from error import ClientError |
24 | 22 |
from subject import Subject |
25 | 23 |
|
26 | 24 |
logger = logging.getLogger('ncclient.session') |
27 | 25 |
|
28 |
class SessionError(ClientError): |
|
29 |
|
|
30 |
pass |
|
26 |
class SessionError(ClientError): pass |
|
31 | 27 |
|
32 | 28 |
class Session(Thread, Subject): |
33 | 29 |
|
... | ... | |
37 | 33 |
self._client_capabilities = CAPABILITIES |
38 | 34 |
self._server_capabilities = None # yet |
39 | 35 |
self._id = None # session-id |
40 |
self._connected = False # subclasses should set this |
|
41 | 36 |
self._error = None |
42 | 37 |
self._init_event = Event() |
43 | 38 |
self._q = Queue() |
39 |
self._connected = False # to be set/cleared by subclass |
|
40 |
|
|
41 |
def _post_connect(self): |
|
42 |
# start the subclass' main loop |
|
43 |
self.start() |
|
44 |
# queue client's hello message for sending |
|
45 |
self.send(content.make_hello(self._client_capabilities)) |
|
46 |
# we expect server's hello message, wait for _init_event to be set by HelloListener |
|
47 |
self._init_event.wait() |
|
48 |
# there may have been an error |
|
49 |
if self._error: |
|
50 |
self._close() |
|
51 |
raise self._error |
|
44 | 52 |
|
45 | 53 |
def send(self, message): |
46 |
message = (u'<?xml version="1.0" encoding="UTF-8"?>%s' % message).encode('utf-8') |
|
54 |
message = (u'<?xml version="1.0" encoding="UTF-8"?>%s' % |
|
55 |
message).encode('utf-8') |
|
47 | 56 |
logger.debug('queueing message: \n%s' % message) |
48 | 57 |
self._q.put(message) |
49 | 58 |
|
... | ... | |
60 | 69 |
return self._client_capabilities |
61 | 70 |
|
62 | 71 |
@property |
63 |
def serve_capabilities(self): |
|
72 |
def server_capabilities(self):
|
|
64 | 73 |
return self._server_capabilities |
65 | 74 |
|
66 | 75 |
@property |
... | ... | |
71 | 80 |
def id(self): |
72 | 81 |
return self._id |
73 | 82 |
|
74 |
def _post_connect(self): |
|
75 |
# start the subclass' main loop |
|
76 |
self.start() |
|
77 |
# queue client's hello message for sending |
|
78 |
self.send(content.make_hello(self._client_capabilities)) |
|
79 |
# we expect server's hello message, wait for _init_event to be set by HelloListener |
|
80 |
self._init_event.wait() |
|
81 |
# there may have been an error |
|
82 |
if self._error: |
|
83 |
self._close() |
|
84 |
raise self._error |
|
85 |
|
|
86 | 83 |
class HelloListener: |
87 | 84 |
|
88 | 85 |
def __str__(self): |
Also available in: Unified diff