Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/tcf/channel')
-rw-r--r--python/src/tcf/channel/AbstractChannel.py7
-rw-r--r--python/src/tcf/channel/ChannelProxy.py9
-rw-r--r--python/src/tcf/channel/ChannelTCP.py6
-rw-r--r--python/src/tcf/channel/Command.py22
-rw-r--r--python/src/tcf/channel/StreamChannel.py6
-rw-r--r--python/src/tcf/channel/__init__.py8
6 files changed, 29 insertions, 29 deletions
diff --git a/python/src/tcf/channel/AbstractChannel.py b/python/src/tcf/channel/AbstractChannel.py
index f343d58ef..d8991e383 100644
--- a/python/src/tcf/channel/AbstractChannel.py
+++ b/python/src/tcf/channel/AbstractChannel.py
@@ -10,7 +10,6 @@
# *******************************************************************************
import sys, threading, time, types
-from exceptions import Exception, IOError
from tcf import protocol, transport, services, peer, errors
from tcf.services import locator
from tcf.channel import STATE_CLOSED, STATE_OPEN, STATE_OPENING
@@ -43,7 +42,7 @@ class ReaderThread(threading.Thread):
self.buf = bytearray()
self.eos_err_report = None
self.daemon = True
-
+
def error(self):
raise IOError("Protocol syntax error")
@@ -128,7 +127,7 @@ class AbstractChannel(object):
"""
AbstractChannel implements communication link connecting two end points (peers).
The channel asynchronously transmits messages: commands, results and events.
-
+
Clients can subclass AbstractChannel to support particular transport (wire) protocol.
Also, see StreamChannel for stream oriented transport protocols.
"""
@@ -163,7 +162,7 @@ class AbstractChannel(object):
self.local_congestion_time = 0
self.local_service_by_class = {}
self.trace_listeners = []
-
+
def __write_output(self):
try:
while True:
diff --git a/python/src/tcf/channel/ChannelProxy.py b/python/src/tcf/channel/ChannelProxy.py
index b95eaeb11..eca426e3c 100644
--- a/python/src/tcf/channel/ChannelProxy.py
+++ b/python/src/tcf/channel/ChannelProxy.py
@@ -14,7 +14,6 @@ ChannelProxy implements forwarding of TCF messages between two channels.
The class is used to implement Locator service "redirect" command.
"""
-import exceptions
from tcf import channel
class ProxyCommandListener(channel.CommandListener):
@@ -27,7 +26,7 @@ class ProxyCommandListener(channel.CommandListener):
self.ch.sendResult(self.tokens.pop(token, None), data)
def terminated(self, token, error):
self.ch.rejectCommand(self.tokens.pop(token, None))
-
+
class ChannelProxy(object):
def __init__(self, x, y):
#assert not isinstance(x, ChannelLoop)
@@ -41,7 +40,7 @@ class ChannelProxy(object):
cmd_listener_x = ProxyCommandListener(self.ch_x, self.tokens_x)
cmd_listener_y = ProxyCommandListener(self.ch_y, self.tokens_y)
proxy = self
-
+
class ProxyX(channel.Proxy):
def onChannelClosed(self, error):
proxy.closed_x = True
@@ -58,7 +57,7 @@ class ChannelProxy(object):
s = proxy.ch_x.getRemoteService(service)
if not s: proxy.ch_x.terminate(IOError("Invalid service name"))
elif not proxy.closed_y: proxy.ch_y.sendEvent(s, name, data)
-
+
class ProxyY(channel.Proxy):
def onChannelClosed(self, error):
proxy.closed_y = True
@@ -84,7 +83,7 @@ class ChannelProxy(object):
class ChannelListener(channel.ChannelListener):
def onChannelClosed(self, error):
proxy.ch_y.removeChannelListener(self)
- if error is None: error = exceptions.Exception("Channel closed")
+ if error is None: error = Exception("Channel closed")
def onChannelOpened(self):
proxy.ch_y.removeChannelListener(self)
try:
diff --git a/python/src/tcf/channel/ChannelTCP.py b/python/src/tcf/channel/ChannelTCP.py
index 1538ca067..ae020237b 100644
--- a/python/src/tcf/channel/ChannelTCP.py
+++ b/python/src/tcf/channel/ChannelTCP.py
@@ -30,9 +30,9 @@ class ChannelTCP(StreamChannel):
channel.socket = sock
channel._onSocketConnected(None)
protocol.invokeLater(CreateSocket())
-
+
def _onSocketConnected(self, x):
- if x:
+ if x:
self.terminate(x)
self.closed = True
if self.closed:
@@ -44,7 +44,7 @@ class ChannelTCP(StreamChannel):
else:
self.started = True
self.start()
-
+
def get(self):
if self.closed: return -1
try:
diff --git a/python/src/tcf/channel/Command.py b/python/src/tcf/channel/Command.py
index c22484db4..53256f0aa 100644
--- a/python/src/tcf/channel/Command.py
+++ b/python/src/tcf/channel/Command.py
@@ -9,7 +9,7 @@
# * Wind River Systems - initial API and implementation
# *******************************************************************************
-import exceptions, cStringIO
+import cStringIO
from tcf import protocol, errors, services
from tcf.channel import Token, toJSONSequence, fromJSONSequence, dumpJSONObject
@@ -18,17 +18,17 @@ class Command(object):
This is utility class that helps to implement sending a command and receiving
command result over TCF communication channel. The class uses JSON to encode
command arguments and to decode result data.
-
+
The class also provides support for TCF standard error report encoding.
-
+
Clients are expected to subclass <code>Command</code> and override <code>done</code> method.
-
+
Note: most clients don't need to handle protocol commands directly and
can use service APIs instead. Service API does all command encoding/decoding
for a client.
-
+
Typical usage example:
-
+
def getContext(self, id, done):
class GetContextCommand(Command):
def done(self, error, args):
@@ -54,7 +54,7 @@ class Command(object):
# TODO zero_copy
#zero_copy = channel.isZeroCopySupported()
t = channel.sendCommand(service, command, toJSONSequence(args), self)
- except exceptions.Exception as y:
+ except Exception as y:
t = Token()
protocol.invokeLater(self._error, y)
self.token = t
@@ -63,7 +63,7 @@ class Command(object):
assert not self.__done
self.__done = True
self.done(error, None)
-
+
def progress(self, token, data):
assert self.token is token
@@ -73,7 +73,7 @@ class Command(object):
args = None
try:
args = fromJSONSequence(data)
- except exceptions.Exception as e:
+ except Exception as e:
error = e
assert not self.__done
self.__done = True
@@ -86,7 +86,7 @@ class Command(object):
self.done(error, None)
def done(self, error, args):
- raise exceptions.NotImplementedError("Abstract method")
+ raise NotImplementedError("Abstract method")
def getCommandString(self):
buf = cStringIO.StringIO()
@@ -103,7 +103,7 @@ class Command(object):
i += 1
try:
dumpJSONObject(arg, buf)
- except exceptions.Exception as x:
+ except Exception as x:
buf.write("***")
buf.write(x.message)
buf.write("***")
diff --git a/python/src/tcf/channel/StreamChannel.py b/python/src/tcf/channel/StreamChannel.py
index 1b409c7a3..a572f83ac 100644
--- a/python/src/tcf/channel/StreamChannel.py
+++ b/python/src/tcf/channel/StreamChannel.py
@@ -17,12 +17,12 @@ ESC = 3
class StreamChannel(AbstractChannel):
"""
Abstract channel implementation for stream oriented transport protocols.
-
+
StreamChannel implements communication link connecting two end points (peers).
The channel asynchronously transmits messages: commands, results and events.
-
+
StreamChannel uses escape sequences to represent End-Of-Message and End-Of-Stream markers.
-
+
Clients can subclass StreamChannel to support particular stream oriented transport (wire) protocol.
Also, see ChannelTCP for a concrete IChannel implementation that works on top of TCP sockets as a transport.
"""
diff --git a/python/src/tcf/channel/__init__.py b/python/src/tcf/channel/__init__.py
index dc040aa98..b66708adb 100644
--- a/python/src/tcf/channel/__init__.py
+++ b/python/src/tcf/channel/__init__.py
@@ -9,7 +9,7 @@
# * Wind River Systems - initial API and implementation
# *******************************************************************************
-import cStringIO, json, binascii, types, exceptions
+import cStringIO, json, binascii, types
# channel states
STATE_OPENING = 0
@@ -166,7 +166,7 @@ def fromJSONSequence(bytes):
def dumpJSONObject(object, buf):
json.dump(object, buf, separators=(',', ':'), cls=TCFJSONEncoder)
-
+
def toByteArray(data):
if data is None: return None
t = type(data)
@@ -175,12 +175,14 @@ def toByteArray(data):
return binascii.a2b_base64(data)
elif t is unicode:
return binascii.a2b_base64(str(data))
- raise exceptions.TypeError(str(t))
+ raise TypeError(str(t))
class TCFJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, bytearray):
return binascii.b2a_base64(o)[:-1]
+ elif hasattr(o, '__json__'):
+ return o.__json__()
elif hasattr(o, '__iter__'):
return tuple(o)
else:

Back to the top