3030import signal
3131import warnings
3232import xml .parsers .expat
33+ import org .python .modules .sre .PatternObject
3334from com .android .monkeyrunner import MonkeyDevice , MonkeyRunner
3435
3536DEBUG = False
@@ -168,7 +169,7 @@ def __str__(self):
168169
169170class ViewNotFoundException (Exception ):
170171 def __init__ (self , attr , value , root ):
171- if type (value ). __name__ == ' PatternObject' :
172+ if isinstance (value , org . python . modules . sre . PatternObject ) :
172173 msg = "Couldn't find View with %s that matches '%s' in tree with root=%s" % (attr , value .pattern , root )
173174 else :
174175 msg = "Couldn't find View with %s='%s' in tree with root=%s" % (attr , value , root )
@@ -1569,8 +1570,10 @@ def dump(self, window=-1, sleep=1):
15691570
15701571 @type window: int or str
15711572 @param window: the window id or name of the window to dump.
1572- The name is the package name or the window name (i.e. StatusBar) for
1573+ The B{ name} is the package name or the window name (i.e. StatusBar) for
15731574 system windows.
1575+ The window id can be provided as C{int} or C{str}. The C{str} should represent
1576+ and C{int} in either base 10 or 16.
15741577 Use -1 to dump all windows.
15751578 This parameter only is used when the backend is B{ViewServer} and it's
15761579 ignored for B{UiAutomator}.
@@ -1590,7 +1593,7 @@ def dump(self, window=-1, sleep=1):
15901593 if not output :
15911594 raise RuntimeError ('ERROR: Getting UIAutomator dump' )
15921595 if not re .search ('dumped' , output ):
1593- raise RuntimeError ("ERROR: UIAutomator dump output doesn't containt 'dumped' (%s)" % output )
1596+ raise RuntimeError ("ERROR: UIAutomator dump output doesn't contain 'dumped' (%s)" % output )
15941597 received = self .device .shell ('cat %s 2>/dev/null' % windowDump )
15951598 if received :
15961599 received = received .encode ('ascii' , 'ignore' )
@@ -1610,19 +1613,34 @@ def dump(self, window=-1, sleep=1):
16101613 print >> sys .stderr
16111614 self .setViewsFromUiAutomatorDump (received )
16121615 else :
1613- if type (window ). __name__ == ' str' :
1616+ if isinstance (window , str ) :
16141617 self .list (sleep = 0 )
16151618 found = False
16161619 for wId in self .windows :
16171620 try :
1618- if window == self .windows [wId ] or int ( window ) == wId :
1621+ if window == self .windows [wId ]:
16191622 window = wId
16201623 found = True
16211624 break
1622- except ValueError :
1625+ except :
1626+ pass
1627+ try :
1628+ if int (window ) == wId :
1629+ window = wId
1630+ found = True
1631+ break
1632+ except :
16231633 pass
1634+ try :
1635+ if int (window , 16 ) == wId :
1636+ window = wId
1637+ found = True
1638+ break
1639+ except :
1640+ pass
1641+
16241642 if not found :
1625- raise RuntimeError ("ERROR: Cannot find window '%s'" % window )
1643+ raise RuntimeError ("ERROR: Cannot find window '%s' in %s " % ( window , self . windows ) )
16261644
16271645 s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
16281646 try :
@@ -1807,7 +1825,7 @@ def __findViewWithAttributeInTree(self, attr, val, root):
18071825
18081826 if DEBUG : print >> sys .stderr , "__findViewWithAttributeInTree: checking if root=%s has attr=%s == %s" % (root .__smallStr__ (), attr , val )
18091827
1810- if type (val ). __name__ == ' PatternObject' :
1828+ if isinstance (val , org . python . modules . sre . PatternObject ) :
18111829 return self .__findViewWithAttributeInTreeThatMatches (attr , val , root )
18121830 else :
18131831 if root and attr in root .map and root .map [attr ] == val :
@@ -1884,7 +1902,7 @@ def findViewWithAttributeThatMatches(self, attr, regex, root="ROOT"):
18841902 return self .__findViewWithAttributeInTreeThatMatches (attr , regex , root )
18851903
18861904 def findViewWithText (self , text , root = "ROOT" ):
1887- if type (text ). __name__ == ' PatternObject' :
1905+ if isinstance (text , org . python . modules . sre . PatternObject ) :
18881906 return self .findViewWithAttributeThatMatches (self .textProperty , text , root )
18891907 #l = self.findViewWithAttributeThatMatches(TEXT_PROPERTY, text)
18901908 #ll = len(l)
0 commit comments