diff options
author | Nagappan Alagappan <nagappan@gmail.com> | 2013-04-30 17:08:55 -0700 |
---|---|---|
committer | Nagappan Alagappan <nagappan@gmail.com> | 2013-04-30 17:08:55 -0700 |
commit | 3c19667fb5c1da3e49c4c6f353dc9e3db6985a01 (patch) | |
tree | 94101b5a1b6e7c41445fa3ff09ee435e5d41e7ac | |
parent | ec519dac093212a178b8d9e826408ea66f99db3f (diff) |
Support Python 3.0LDTP_3.5.0
-rw-r--r-- | ldtp/__init__.py | 11 | ||||
-rw-r--r-- | ldtp/client.py | 10 | ||||
-rw-r--r-- | ldtpd/__init__.py | 4 | ||||
-rw-r--r-- | ldtpd/combo_box.py | 8 | ||||
-rw-r--r-- | ldtpd/core.py | 22 | ||||
-rw-r--r-- | ldtpd/sequence_step.py | 2 | ||||
-rw-r--r-- | ldtpd/table.py | 2 | ||||
-rw-r--r-- | ldtpd/utils.py | 62 | ||||
-rw-r--r-- | ldtpd/waiters.py | 14 | ||||
-rw-r--r-- | ldtpd/xmlrpc_daemon.py | 8 | ||||
-rw-r--r-- | ldtputils/__init__.py | 4 | ||||
-rw-r--r-- | ooldtp/_context.py | 2 | ||||
-rwxr-xr-x | scripts/ldtp | 2 |
13 files changed, 74 insertions, 77 deletions
diff --git a/ldtp/__init__.py b/ldtp/__init__.py index 3d6ce4d..121fdbb 100644 --- a/ldtp/__init__.py +++ b/ldtp/__init__.py @@ -97,7 +97,7 @@ def log(message, level = logging.DEBUG): """ if _ldtp_debug: - print message + print(message) logger.log(level, str(message)) return 1 @@ -128,7 +128,7 @@ def startlog(filename, overwrite = True): # Create logging file handler _file_logger = logging.FileHandler(os.path.expanduser(filename), _mode) # Log 'Levelname: Messages', eg: 'ERROR: Logged message' - _formatter = logging.Formatter(u'%(levelname)-8s: %(message)s') + _formatter = logging.Formatter('%(levelname)-8s: %(message)s') _file_logger.setFormatter(_formatter) logger.addHandler(_file_logger) if _ldtp_debug: @@ -462,7 +462,7 @@ def registerevent(event_name, fn_name, *args): @rtype: integer """ if not isinstance(event_name, str): - raise ValueError, "event_name should be string" + raise ValueError("event_name should be string") _pollEvents._callback[event_name] = [event_name, fn_name, args] return _remote_registerevent(event_name) @@ -497,7 +497,7 @@ def registerkbevent(keys, modifiers, fn_name, *args): @return: 1 if registration was successful, 0 if not. @rtype: integer """ - event_name = u"kbevent%s%s" % (keys, modifiers) + event_name = "kbevent%s%s" % (keys, modifiers) _pollEvents._callback[event_name] = [event_name, fn_name, args] return _remote_registerkbevent(keys, modifiers) @@ -513,8 +513,7 @@ def deregisterkbevent(keys, modifiers): @return: 1 if registration was successful, 0 if not. @rtype: integer """ - - event_name = u"kbevent%s%s" % (keys, modifiers) + event_name = "kbevent%s%s" % (keys, modifiers) if event_name in _pollEvents._callback: del _pollEvents._callback[event_name] return _remote_deregisterkbevent(keys, modifiers) diff --git a/ldtp/client.py b/ldtp/client.py index 829da65..98f49f2 100644 --- a/ldtp/client.py +++ b/ldtp/client.py @@ -72,11 +72,11 @@ class Transport(xmlrpclib.Transport): def _handle_signal(self, signum, frame): if _ldtp_debug: if signum == signal.SIGCHLD: - print "ldtpd exited!" + print("ldtpd exited!") elif signum == signal.SIGUSR1: - print "SIGUSR1 received. ldtpd ready for requests." + print("SIGUSR1 received. ldtpd ready for requests.") elif signum == signal.SIGALRM: - print "SIGALRM received. Timeout waiting for SIGUSR1." + print("SIGALRM received. Timeout waiting for SIGUSR1.") def _spawn_daemon(self): pid = os.getpid() @@ -150,7 +150,7 @@ class Transport(xmlrpclib.Transport): parser.close() return unmarshaller.close() - except SocketError, e: + except SocketError as e: if ((_ldtp_windows_env and e[0] == 10061) or \ (not _ldtp_windows_env and (e.errno == 111 or \ e.errno == 101 or \ @@ -182,7 +182,7 @@ class Transport(xmlrpclib.Transport): raise # else raise exception raise - except xmlrpclib.Fault, e: + except xmlrpclib.Fault as e: if hasattr(self, 'close'): self.close() if e.faultCode == ERROR_CODE: diff --git a/ldtpd/__init__.py b/ldtpd/__init__.py index eda1261..399396f 100644 --- a/ldtpd/__init__.py +++ b/ldtpd/__init__.py @@ -79,7 +79,7 @@ def main(port=4118, parentpid=None): reactor.run() except twisted.internet.error.CannotListenError: if _ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) except socket.error: if _ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) diff --git a/ldtpd/combo_box.py b/ldtpd/combo_box.py index 5bcba60..ca4dc68 100644 --- a/ldtpd/combo_box.py +++ b/ldtpd/combo_box.py @@ -354,8 +354,8 @@ class ComboBox(Utils, LayeredPane): # Concat object type and object name # ex: 'frmUnsavedDocument1-gedit' for Gedit application # frm - Frame, Window title - 'Unsaved Document 1 - gedit' - _object_name = u'%s%s' % (_ldtpize_accessible_name[0], - _ldtpize_accessible_name[1]) + _object_name = '%s%s' % (_ldtpize_accessible_name[0], + _ldtpize_accessible_name[1]) if self._glob_match(item_name, _object_name): self._click_object(child) return 1 @@ -635,8 +635,8 @@ class ComboBox(Utils, LayeredPane): # Concat object type and object name # ex: 'frmUnsavedDocument1-gedit' for Gedit application # frm - Frame, Window title - 'Unsaved Document 1 - gedit' - _object_name = u'%s%s' % (_ldtpize_accessible_name[0], - _ldtpize_accessible_name[1]) + _object_name = '%s%s' % (_ldtpize_accessible_name[0], + _ldtpize_accessible_name[1]) if self._glob_match(item_name, _object_name): return 1 except: diff --git a/ldtpd/core.py b/ldtpd/core.py index d2917c1..19c34a3 100644 --- a/ldtpd/core.py +++ b/ldtpd/core.py @@ -102,11 +102,11 @@ class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList, if event and event.source and event.type: abbrev_role, abbrev_name, label_by=self._ldtpize_accessible( \ event.source) - window_name=u'%s%s' % (abbrev_role, abbrev_name) - self._callback_event.append(u"%s-%s" % (event.type, window_name)) + window_name='%s%s' % (abbrev_role, abbrev_name) + self._callback_event.append("%s-%s" % (event.type, window_name)) except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) def _registered_kb_event_cb(self, event): if not event: @@ -121,7 +121,7 @@ class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList, self._kb_timestamp=event.timestamp if event.modifiers in self._kb_modifiers and \ event.hw_code in self._kb_entries: - self._callback_event.append(u"kbevent-%s-%d" % (event.event_string, + self._callback_event.append("kbevent-%s-%d" % (event.event_string, event.modifiers)) def _event_cb(self, event): @@ -129,22 +129,22 @@ class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList, if event and event.type == "window:create" and event.source: for window in self._callback: if window and self._match_name_to_acc(window, event.source): - self._callback_event.append(u"onwindowcreate-%s" % window) + self._callback_event.append("onwindowcreate-%s" % window) abbrev_role, abbrev_name, label_by=self._ldtpize_accessible( \ event.source) - win_name=u'%s%s' % (abbrev_role, abbrev_name) + win_name='%s%s' % (abbrev_role, abbrev_name) self._window_uptime[win_name]=[event.source_name, time.strftime("%Y %m %d %H %M %S")] elif event and event.type == "window:destroy" and event.source: abbrev_role, abbrev_name, label_by=self._ldtpize_accessible( \ event.source) - win_name=u'%s%s' % (abbrev_role, abbrev_name) + win_name='%s%s' % (abbrev_role, abbrev_name) if win_name in self._window_uptime: self._window_uptime[win_name].append( \ time.strftime("%Y %m %d %H %M %S")) except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) def appundertest(self, app_name): """ @@ -268,7 +268,7 @@ class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList, time.sleep(int(delay)) except ValueError: time.sleep(5) - except Exception, e: + except Exception as e: raise LdtpServerException(str(e)) os.environ['NO_GAIL']='1' os.environ['NO_AT_BRIDGE']='1' @@ -820,7 +820,7 @@ class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList, return int(waiter.run()) except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) return 0 def grabfocus(self, window_name, object_name): @@ -1368,7 +1368,7 @@ class Ldtpd(Utils, ComboBox, Table, Menu, PageTabList, size=self._get_size(gui) return [size.x, size.y, size.width, size.height] - raise LdtpServerException(u'Window "%s" does not exist' % window_name) + raise LdtpServerException('Window "%s" does not exist' % window_name) def _getComponentAtCoords(self, parent, x, y): """ diff --git a/ldtpd/sequence_step.py b/ldtpd/sequence_step.py index 57cd00c..9ceabf4 100644 --- a/ldtpd/sequence_step.py +++ b/ldtpd/sequence_step.py @@ -118,7 +118,7 @@ class DebugAction(AtomicAction): ''' Print the debug message. ''' - print self._debug_msg + print(self._debug_msg) def __str__(self): ''' diff --git a/ldtpd/table.py b/ldtpd/table.py index f01ea9d..4b658aa 100644 --- a/ldtpd/table.py +++ b/ldtpd/table.py @@ -227,9 +227,7 @@ class Table(Utils): @rtype: integer """ obj = self._get_object(window_name, object_name) - cell = self._get_accessible_at_row_column(obj, row_index, column) - print cell name = None if cell.childCount > 0: flag = False diff --git a/ldtpd/utils.py b/ldtpd/utils.py index d33917c..00423dd 100644 --- a/ldtpd/utils.py +++ b/ldtpd/utils.py @@ -55,7 +55,7 @@ class LdtpCustomLog(logging.Handler): def emit(self, record): # Get the message and add to the list # Later the list element can be poped out - self.log_events.append(u'%s-%s' % (record.levelname, record.getMessage())) + self.log_events.append('%s-%s' % (record.levelname, record.getMessage())) # Add LdtpCustomLog handler logging.handlers.LdtpCustomLog = LdtpCustomLog @@ -229,7 +229,7 @@ class Utils: """ if self._ldtp_debug: try: - print event, event.type, event.source, event.source.parent + print(event, event.type, event.source, event.source.parent) except: # With at-spi2, sometimes noticed exception # ignore exception, as we just use them for debugging @@ -257,7 +257,7 @@ class Utils: def _on_window_event(self, event): if self._ldtp_debug: try: - print event, event.type, event.source, event.source.parent + print(event, event.type, event.source, event.source.parent) except: # With at-spi2, sometimes noticed exception # ignore exception, as we just use them for debugging @@ -271,9 +271,9 @@ class Utils: event.source) # LDTPized name try: - win_name = u'%s%s' % (abbrev_role, abbrev_name) + win_name = '%s%s' % (abbrev_role, abbrev_name) except UnicodeDecodeError: - win_name = u'%s%s' % (abbrev_role, abbrev_name.decode('utf-8')) + win_name = '%s%s' % (abbrev_role, abbrev_name.decode('utf-8')) # Window title is empty if abbrev_name == '': for win_name in self._appmap.keys(): @@ -314,7 +314,7 @@ class Utils: self.cached_apps.append([event.host_application, True]) except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) def _atspi2_workaround(self): if not hasattr(pyatspi, 'Accessible'): @@ -398,7 +398,7 @@ class Utils: # exceptions.AttributeError: 'NoneType' object has no attribute '_narrow' # Let us not throw exception, instead continue if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) continue try: role = acc.getRole() @@ -474,7 +474,7 @@ class Utils: return 0 if acc.name: try: - _acc_name=u"%s" % acc.name + _acc_name="%s" % acc.name except UnicodeDecodeError: _acc_name=acc.name.decode('utf-8') if acc.name and re.match(fnmatch.translate(name), _acc_name, re.M | re.U): @@ -490,10 +490,10 @@ class Utils: # ex: 'frmUnsavedDocument1-gedit' for Gedit application # frm - Frame, Window title - 'Unsaved Document 1 - gedit' try: - _object_name = u'%s%s' % (_ldtpize_accessible_name[0], + _object_name = '%s%s' % (_ldtpize_accessible_name[0], _ldtpize_accessible_name[1]) except UnicodeDecodeError: - _object_name = u'%s%s' % (_ldtpize_accessible_name[0], + _object_name = '%s%s' % (_ldtpize_accessible_name[0], _ldtpize_accessible_name[1].decode('utf-8')) if self._glob_match(name, acc.name): # If given name match object name with regexp @@ -554,7 +554,7 @@ class Utils: if self._glob_match(name, acc['label']): return 1 # Strip space and look for object - obj_name = u'%s' % re.sub(' ', '', name) + obj_name = '%s' % re.sub(' ', '', name) role = acc['class'] if role == 'frame' or role == 'dialog' or \ role == 'window' or \ @@ -638,22 +638,22 @@ class Utils: self.ldtpized_obj_index[abbrev_role] = 0 if abbrev_name == '': ldtpized_name_base = abbrev_role - ldtpized_name = u'%s%d' % (ldtpized_name_base, + ldtpized_name = '%s%d' % (ldtpized_name_base, self.ldtpized_obj_index[abbrev_role]) else: try: - ldtpized_name_base = u'%s%s' % (abbrev_role, abbrev_name) + ldtpized_name_base = '%s%s' % (abbrev_role, abbrev_name) except UnicodeDecodeError: - ldtpized_name_base = u'%s%s' % (abbrev_role, abbrev_name.decode('utf-8')) + ldtpized_name_base = '%s%s' % (abbrev_role, abbrev_name.decode('utf-8')) ldtpized_name = ldtpized_name_base i = 0 while ldtpized_name in self.ldtpized_list: i += 1 - ldtpized_name = u'%s%d' % (ldtpized_name_base, i) + ldtpized_name = '%s%d' % (ldtpized_name_base, i) if parent in self.ldtpized_list: _current_children = self.ldtpized_list[parent]['children'] if _current_children: - _current_children = u'%s %s' % (_current_children, ldtpized_name) + _current_children = '%s %s' % (_current_children, ldtpized_name) else: _current_children = ldtpized_name self.ldtpized_list[parent]['children'] = _current_children @@ -761,7 +761,7 @@ class Utils: raise LdtpServerException("Invalid menu hierarchy input") if not re.search('^mnu', _menu_hierarchy[0], re.M | re.U): # Add mnu to the first object, if it doesn't exist - _menu_hierarchy[0] = u'mnu%s' % _menu_hierarchy[0] + _menu_hierarchy[0] = 'mnu%s' % _menu_hierarchy[0] obj = self._get_object(window_name, _menu_hierarchy[0], wait) for _menu in _menu_hierarchy[1:]: _flag = False @@ -788,7 +788,7 @@ class Utils: else: for i in xrange(iaction.nActions): if self._ldtp_debug: - print iaction.getName(i) + print(iaction.getName(i)) if re.match(action, iaction.getName(i), re.I): iaction.doAction(i) return @@ -869,16 +869,16 @@ class Utils: tmp_name = obj_name[1] # Append window type and window title try: - w_name = name = u'%s%s' % (obj_name[0], tmp_name) + w_name = name = '%s%s' % (obj_name[0], tmp_name) except UnicodeDecodeError: - w_name = name = u'%s%s' % (obj_name[0], tmp_name.decode('utf-8')) + w_name = name = '%s%s' % (obj_name[0], tmp_name.decode('utf-8')) # If multiple window with same title, increment the index index = 1 while name in window_list: # If window name already exist in list, increase # the index, so that we will have the window name # always unique - name = u'%s%d' % (w_name, index) + name = '%s%d' % (w_name, index) index += 1 window_list.append(name) @@ -887,26 +887,26 @@ class Utils: # Search with LDTP appmap format if window_name.find('#') != -1: - obj_index = u'%s#%d' % (gui.getApplication().name, + obj_index = '%s#%d' % (gui.getApplication().name, gui.getIndexInParent()) if self._ldtp_debug: - print 'Window name has #', window_name, obj_index + print('Window name has #', window_name, obj_index) if window_name == obj_index: if self._ldtp_debug: - print 'Window found', gui, name + print('Window found', gui, name) return gui, name if window_name == name: if self._ldtp_debug: - print 'Window found', gui, name + print('Window found', gui, name) return gui, name if self._glob_match(window_name, name): if self._ldtp_debug: - print 'Window found', gui, name + print('Window found', gui, name) return gui, name if self._glob_match(re.sub(' ', '', window_name), re.sub(' ', '', name)): if self._ldtp_debug: - print 'Window found', gui, name + print('Window found', gui, name) return gui, name return None, None @@ -989,16 +989,16 @@ class Utils: if obj.getRoleName() != _appmap_role: # Traversing object role and appmap role doesn't match if self._ldtp_debug: - print "Traversing object role and appmap role " \ - "doesn't match", obj.getRoleName(), _appmap_role + print("Traversing object role and appmap role " \ + "doesn't match", obj.getRoleName(), _appmap_role) return None break obj = tmp_obj if obj.getRoleName() != _appmap_role: # Traversing object role and appmap role doesn't match if self._ldtp_debug: - print "Traversing object role and appmap role " \ - "doesn't match", obj.getRoleName(), _appmap_role + print("Traversing object role and appmap role " \ + "doesn't match", obj.getRoleName(), _appmap_role) return None return obj _current_obj = _self_get_object(window_name, obj_name, obj) diff --git a/ldtpd/waiters.py b/ldtpd/waiters.py index 168457f..5d43170 100644 --- a/ldtpd/waiters.py +++ b/ldtpd/waiters.py @@ -89,7 +89,7 @@ class Waiter(Utils): self._event_cb, *self.events) except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) return self.success def _timeout_thread_cb(self, params): @@ -105,7 +105,7 @@ class Waiter(Utils): self.poll() except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) if self._timeout_count * self.timeout_seconds > self.timeout or \ self.success: try: @@ -130,7 +130,7 @@ class Waiter(Utils): self.event_cb(event) except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) if self.success: try: # Required for wnck functions @@ -372,7 +372,7 @@ class GuiExistsWaiter(Waiter): self.success = True except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) class GuiNotExistsWaiter(Waiter): events = ["window:destroy"] @@ -391,7 +391,7 @@ class GuiNotExistsWaiter(Waiter): self.success = True except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) class ObjectExistsWaiter(GuiExistsWaiter): def __init__(self, frame_name, obj_name, timeout, state = ''): @@ -419,7 +419,7 @@ class ObjectExistsWaiter(GuiExistsWaiter): self.success = True except: if self._ldtp_debug: - print traceback.format_exc() + print(traceback.format_exc()) def event_cb(self, event): GuiExistsWaiter.event_cb(self, event) @@ -443,4 +443,4 @@ class ObjectNotExistsWaiter(GuiNotExistsWaiter): if __name__ == "__main__": waiter = ObjectExistsWaiter('frmCalculator', 'mnuEitanIsaacsonFoo', 0) - print waiter.run() + print(waiter.run()) diff --git a/ldtpd/xmlrpc_daemon.py b/ldtpd/xmlrpc_daemon.py index ba4139c..67def63 100644 --- a/ldtpd/xmlrpc_daemon.py +++ b/ldtpd/xmlrpc_daemon.py @@ -99,7 +99,7 @@ class XMLRPCLdtpd(Ldtpd, xmlrpc.XMLRPC, object): time.sleep(0.5) else: kwargs = {} - except Exception, e: + except Exception as e: f = xmlrpc.Fault( self.FAILURE, "Can't deserialize input: %s" % (e,)) self._cbRender(f, request) @@ -110,16 +110,16 @@ class XMLRPCLdtpd(Ldtpd, xmlrpc.XMLRPC, object): function = self.lookupProcedure(functionPath) else: function = self._getFunction(functionPath) - except xmlrpc.Fault, f: + except xmlrpc.Fault as f: self._cbRender(f, request) else: if _ldtp_debug: - debug_st = u'%s(%s)' % \ + debug_st = '%s(%s)' % \ (functionPath, ', '.join(map(repr, args) + \ ['%s=%s' % (k, repr(v)) \ for k, v in kwargs.items()])) - print debug_st + print(debug_st) logger.debug(debug_st) xmlrpc.defer.maybeDeferred(function, *args, **kwargs).\ diff --git a/ldtputils/__init__.py b/ldtputils/__init__.py index 746eb64..419dba0 100644 --- a/ldtputils/__init__.py +++ b/ldtputils/__init__.py @@ -26,7 +26,7 @@ def imagecompare(imgfile1, imgfile2): try: import ImageChops, Image except ImportError: - raise Exception, 'Python-Imaging package not installed' + raise Exception('Python-Imaging package not installed') try: diffcount = 0.0 im1 = Image.open(imgfile1) @@ -50,4 +50,4 @@ def imagecompare(imgfile1, imgfile2): diffpercent = (diffcount * 100) / diffImgLen return diffpercent except IOError: - raise Exception, 'Input file does not exist' + raise Exception('Input file does not exist') diff --git a/ooldtp/_context.py b/ooldtp/_context.py index 1f97406..a5ec1e0 100644 --- a/ooldtp/_context.py +++ b/ooldtp/_context.py @@ -152,5 +152,5 @@ class _ComponentFuncWrapper: if __name__ == "__main__": c = Component('Calculator', 'btnNumeric1') - print dir(c) + print(dir(c)) c.click() diff --git a/scripts/ldtp b/scripts/ldtp index ab41c56..218d0aa 100755 --- a/scripts/ldtp +++ b/scripts/ldtp @@ -36,7 +36,7 @@ def parse_cmd_line_option(): (options, args) = parser.parse_args() if options.version: # Print version info and exit - print 'ldtp-3.5.0' + print('ldtp-3.5.0') sys.exit(0) if options.verbose: # Set verbose flag |