root / src / session.py @ 7238f39d
History | View | Annotate | Download (1.5 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 |
import threading |
16 |
|
17 |
class Session(threading.Thread): |
18 |
|
19 |
def __init__(self, capabilities, reply_cb): |
20 |
Thread.__init__(self)
|
21 |
self.capabilities = {
|
22 |
'client': capabilities,
|
23 |
'server': None #yet |
24 |
} |
25 |
self._q = Queue.Queue()
|
26 |
self._cb = reply_cb
|
27 |
self.id = None # session-id |
28 |
self.connected = False |
29 |
|
30 |
def connect(self): |
31 |
self.start()
|
32 |
|
33 |
def run(self): |
34 |
raise NotImplementedError |
35 |
|
36 |
def send(self, msg): |
37 |
if not self.connected: |
38 |
self._q.add(msg)
|
39 |
|
40 |
def expectClose(self, val=True): |
41 |
'''operations.CloseSession must call this before a call to send(),
|
42 |
so that the remote endpoint closing the connection does not result
|
43 |
in an exception'''
|
44 |
self._expectClose = val
|
45 |
|
46 |
@property
|
47 |
def id(self): |
48 |
'Session ID'
|
49 |
return self._id |
50 |
|
51 |
# Preferred way is to access the attributes directly,
|
52 |
# but here goes:
|
53 |
|
54 |
# TODO
|