Revision 1d540e60 ncclient/transport/session.py

b/ncclient/transport/session.py
12 12
# See the License for the specific language governing permissions and
13 13
# limitations under the License.
14 14

  
15
from threading import Thread, Event
15
from threading import Event
16 16

  
17 17
from ncclient.capabilities import Capabilities, CAPABILITIES
18 18
from ncclient.glue import Subject
......
20 20
from . import logger
21 21
from hello import HelloHandler
22 22

  
23
class Session(Thread, Subject):
23
class Session(Subject):
24 24
    
25 25
    "TODO: docstring"
26 26
    
27 27
    def __init__(self):
28 28
        "TODO: docstring"
29 29
        Subject.__init__(self)
30
        Thread.__init__(self, name='session')
31
        self.setDaemon(True)
30
        self.setName('session')
31
        self.setDaemon(True) #hmm
32 32
        self._client_capabilities = CAPABILITIES
33 33
        self._server_capabilities = None # yet
34 34
        self._id = None # session-id
35 35
        self._connected = False # to be set/cleared by subclass implementation
36
        logger.debug('[session object created] client_capabilities=%r' %
37
                     self._client_capabilities)
36 38
    
37 39
    def _post_connect(self):
38 40
        "TODO: docstring"
39
        self.send(HelloHandler.build(self._client_capabilities))
40
        error = None
41 41
        init_event = Event()
42
        error = [None] # so that err_cb can bind error[0]. just how it is.
42 43
        # callbacks
43 44
        def ok_cb(id, capabilities):
44
            self._id, self._server_capabilities = id, Capabilities(capabilities)
45
            self._id = id
46
            self._server_capabilities = Capabilities(capabilities)
45 47
            init_event.set()
46 48
        def err_cb(err):
47
            error = err
49
            error[0] = err
48 50
            init_event.set()
49 51
        listener = HelloHandler(ok_cb, err_cb)
50 52
        self.add_listener(listener)
51
        # start the subclass' main loop
53
        self.send(HelloHandler.build(self._client_capabilities))
54
        logger.debug('[starting main loop]')
52 55
        self.start()
53 56
        # we expect server's hello message
54 57
        init_event.wait()
55 58
        # received hello message or an error happened
56 59
        self.remove_listener(listener)
57
        if error:
58
            raise error
60
        if error[0]:
61
            raise error[0]
59 62
        logger.info('initialized: session-id=%s | server_capabilities=%s' %
60
                     (self.id, self.server_capabilities))
63
                     (self._id, self._server_capabilities))
61 64
    
62 65
    def connect(self, *args, **kwds):
63 66
        "TODO: docstring"

Also available in: Unified diff