diff options
author | Frederic Leger | 2016-07-07 09:18:03 +0000 |
---|---|---|
committer | Frederic Leger | 2016-07-07 09:18:03 +0000 |
commit | 72c9f8995912207a44d31c82f74056248e882dba (patch) | |
tree | 58e4f7c74b1b3138b6abeffa80d505df8d56bab0 /python/src/tcf/util | |
parent | 69846a1fda38662c05543d5b584086cf0fbc8406 (diff) | |
download | org.eclipse.tcf-72c9f8995912207a44d31c82f74056248e882dba.tar.gz org.eclipse.tcf-72c9f8995912207a44d31c82f74056248e882dba.tar.xz org.eclipse.tcf-72c9f8995912207a44d31c82f74056248e882dba.zip |
TCF Python: Python 3 compliance.
The whole TCF python code should now be python 2 AND python 3
compatible.
As there are few tests, I made sure this works by running the
BasicTests.py and ProcessStart.py using both a python2 or python3
interpreter.
Diffstat (limited to 'python/src/tcf/util')
-rw-r--r-- | python/src/tcf/util/cache.py | 24 | ||||
-rw-r--r-- | python/src/tcf/util/event.py | 6 | ||||
-rw-r--r-- | python/src/tcf/util/logging.py | 23 | ||||
-rw-r--r-- | python/src/tcf/util/sync.py | 25 | ||||
-rw-r--r-- | python/src/tcf/util/task.py | 6 |
5 files changed, 41 insertions, 43 deletions
diff --git a/python/src/tcf/util/cache.py b/python/src/tcf/util/cache.py index 23df4cd22..f8b9bbf5e 100644 --- a/python/src/tcf/util/cache.py +++ b/python/src/tcf/util/cache.py @@ -1,5 +1,5 @@ # ***************************************************************************** -# * Copyright (c) 2011, 2013-2014 Wind River Systems, Inc. and others. +# * Copyright (c) 2011, 2013-2014, 2016 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 @@ -9,7 +9,6 @@ # * Wind River Systems - initial API and implementation # ***************************************************************************** -import cStringIO from .. import protocol, channel from .task import Task @@ -263,7 +262,7 @@ class DataCache(object): if not self.__disposed: self.__data = data self.__error = None - self.__valid = True + self.__valid = data is not None self.post() def cancel(self): @@ -286,20 +285,19 @@ class DataCache(object): self.__disposed = True def __str__(self): - bf = cStringIO.StringIO() - bf.write('[') + res = '[' if self.__valid: - bf.append("valid,") + res += 'valid,' if self.__disposed: - bf.write("disposed,") + res += 'disposed,' if self.__posted: - bf.write("posted,") + res += 'posted,' if self.__error is not None: - bf.write("error,") - bf.write("data=") - bf.write(str(self.__data)) - bf.write(']') - return bf.getvalue() + res += 'error,' + res += 'data=' + res += str(self.__data) + res += ']' + return res def startDataRetrieval(self): """ diff --git a/python/src/tcf/util/event.py b/python/src/tcf/util/event.py index 4c552db29..4f77fb10a 100644 --- a/python/src/tcf/util/event.py +++ b/python/src/tcf/util/event.py @@ -1,5 +1,5 @@ # ***************************************************************************** -# * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others. +# * Copyright (c) 2011, 2013, 2016 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 @@ -27,7 +27,7 @@ class DelegatingEventListener(channel.EventListener): def _print_event(service, name, *args): - print "Event: %s.%s%s" % (service, name, tuple(args)) + print("Event: %s.%s%s" % (service, name, tuple(args))) def get_event_printer(): @@ -70,7 +70,7 @@ class EventRecorder(object): if service: self.record(service, False) else: - for service in self._listeners.keys(): + for service in list(self._listeners.keys()): self.record(service, False) def get(self): diff --git a/python/src/tcf/util/logging.py b/python/src/tcf/util/logging.py index 889ff3dd7..132daa931 100644 --- a/python/src/tcf/util/logging.py +++ b/python/src/tcf/util/logging.py @@ -1,5 +1,5 @@ # ***************************************************************************** -# * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others. +# * Copyright (c) 2011, 2013, 2016 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 @@ -11,7 +11,6 @@ "Internal utility methods used for logging/tracing." -import cStringIO import locale import time @@ -30,24 +29,24 @@ def getDebugTime(): the relative time between two events, since the counter will flip to zero roughly every 16 minutes. """ - traceBuilder = cStringIO.StringIO() + traceBuilder = '' # Record the time tm = int(time.time() * 1000) - seconds = (tm / 1000) % 1000 + seconds = int((tm / 1000)) % 1000 if seconds < 100: - traceBuilder.write('0') + traceBuilder += '0' if seconds < 10: - traceBuilder.write('0') - traceBuilder.write(str(seconds)) - traceBuilder.write(DECIMAL_DELIMITER) + traceBuilder += '0' + traceBuilder += str(seconds) + traceBuilder += str(DECIMAL_DELIMITER) millis = tm % 1000 if millis < 100: - traceBuilder.write('0') + traceBuilder += '0' if millis < 10: - traceBuilder.write('0') - traceBuilder.write(str(millis)) - return traceBuilder.getvalue() + traceBuilder += '0' + traceBuilder += str(millis) + return traceBuilder def trace(msg): diff --git a/python/src/tcf/util/sync.py b/python/src/tcf/util/sync.py index 2114febe0..e604cd2e0 100644 --- a/python/src/tcf/util/sync.py +++ b/python/src/tcf/util/sync.py @@ -1,5 +1,5 @@ # ***************************************************************************** -# * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others. +# * Copyright (c) 2011, 2013, 2016 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 @@ -67,8 +67,8 @@ class CommandControl(object): return services if attr in services: return ServiceWrapper(self, attr) - raise AttributeError("Unknown service: %s. Use one of %s" % ( - attr, services)) + raise AttributeError("Unknown service: %s. Use one of %s" % + (attr, services)) def invoke(self, service, command, *args, **kwargs): cmd = None @@ -91,8 +91,10 @@ class CommandControl(object): class GenericCommand(Command): _result = None + def done(self, error, args): # @IgnorePep8 resultArgs = None + rcmds = ('read', 'readdir', 'roots') if not error and args: # error result is usually in args[0], # but there are exceptions @@ -102,16 +104,15 @@ class CommandControl(object): elif service == "Expressions" and command == "evaluate": error = self.toError(args[1]) resultArgs = (args[0], args[2]) - elif service == "FileSystem" and command in ( - 'read', 'readdir', 'roots'): + elif service == "FileSystem" and command in rcmds: error = self.toError(args[1]) resultArgs = (args[0],) + tuple(args[2:]) elif service == "Streams" and command == 'read': error = self.toError(args[1]) resultArgs = (args[0],) + tuple(args[2:]) - elif service == "Diagnostics" and \ - command.startswith("echo"): - resultArgs = (args[0],) + elif service == "Diagnostics": + if command.startswith("echo"): + resultArgs = (args[0],) else: error = self.toError(args[0]) resultArgs = args[1:] @@ -218,7 +219,7 @@ class CommandControl(object): protocol.invokeLater(self.cancel) return with self._lock: - for cmd in self._pending.values(): + for cmd in list(self._pending.values()): cmd.token.cancel() del self._queue[:] @@ -226,7 +227,7 @@ class CommandControl(object): if wait: self.wait() with self._lock: - result = map(lambda c: c.getResult(), self._complete) + result = [c.getResult() for c in self._complete] del self._complete[:] return result @@ -267,5 +268,5 @@ class CommandWrapper(object): self._command = command def __call__(self, *args, **kwargs): - return self._control.invoke( - self._service, self._command, *args, **kwargs) + return self._control.invoke(self._service, self._command, *args, + **kwargs) diff --git a/python/src/tcf/util/task.py b/python/src/tcf/util/task.py index cdca94eb7..3864cef16 100644 --- a/python/src/tcf/util/task.py +++ b/python/src/tcf/util/task.py @@ -1,5 +1,5 @@ -#****************************************************************************** -# Copyright (c) 2011, 2013 Wind River Systems, Inc. and others. +# ***************************************************************************** +# Copyright (c) 2011, 2013, 2016 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,7 +7,7 @@ # # Contributors: # Wind River Systems - initial API and implementation -#****************************************************************************** +# ***************************************************************************** import threading from .. import protocol, channel |