Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/tcf/channel/Command.py')
-rw-r--r--python/src/tcf/channel/Command.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/python/src/tcf/channel/Command.py b/python/src/tcf/channel/Command.py
index 53256f0aa..72b6e9544 100644
--- a/python/src/tcf/channel/Command.py
+++ b/python/src/tcf/channel/Command.py
@@ -1,5 +1,5 @@
-# *******************************************************************************
-# * Copyright (c) 2011 Wind River Systems, Inc. and others.
+# *****************************************************************************
+# * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others.
# * All rights reserved. This program and the accompanying materials
# * are made available under the terms of the Eclipse Public License v1.0
# * which accompanies this distribution, and is available at
@@ -7,24 +7,26 @@
# *
# * Contributors:
# * Wind River Systems - initial API and implementation
-# *******************************************************************************
+# *****************************************************************************
import cStringIO
-from tcf import protocol, errors, services
-from tcf.channel import Token, toJSONSequence, fromJSONSequence, dumpJSONObject
+from .. import protocol, errors, services
+from ..channel import Token, toJSONSequence, fromJSONSequence, dumpJSONObject
+
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.
+ """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.
+ 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
+ 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:
@@ -52,8 +54,9 @@ class Command(object):
t = None
try:
# TODO zero_copy
- #zero_copy = channel.isZeroCopySupported()
- t = channel.sendCommand(service, command, toJSONSequence(args), self)
+ # zero_copy = channel.isZeroCopySupported()
+ t = channel.sendCommand(service, command, toJSONSequence(args),
+ self)
except Exception as y:
t = Token()
protocol.invokeLater(self._error, y)
@@ -90,7 +93,7 @@ class Command(object):
def getCommandString(self):
buf = cStringIO.StringIO()
- buf.write(self.service)
+ buf.write(str(self.service))
buf.write(" ")
buf.write(self.command)
if self.args is not None:
@@ -110,14 +113,16 @@ class Command(object):
return buf.getvalue()
def toError(self, data, include_command_text=True):
- if not isinstance(data, dict): return None
- map = data
+ if not isinstance(data, dict):
+ return None
+ errMap = data
bf = cStringIO.StringIO()
bf.write("TCF error report:\n")
if include_command_text:
cmd = self.getCommandString()
- if len(cmd) > 120: cmd = cmd[:120] + "..."
+ if len(cmd) > 120:
+ cmd = cmd[:120] + "..."
bf.write("Command: ")
bf.write(cmd)
- errors.appendErrorProps(bf, map)
- return errors.ErrorReport(bf.getvalue(), map)
+ errors.appendErrorProps(bf, errMap)
+ return errors.ErrorReport(bf.getvalue(), errMap)

Back to the top