@@ -1217,7 +1217,13 @@ def __str__(self):
12171217 if isinstance (self .map [a ], str ):
12181218 __str += self .map [a ]
12191219 else :
1220- __str += str (self .map [a ]).encode ('utf-8' , errors = 'replace' ).decode ('utf-8' )
1220+ if sys .version_info [0 ] < 3 :
1221+ if type (self .map [a ]) == unicode :
1222+ __str += self .map [a ].encode ('utf-8' , errors = 'replace' ).decode ('utf-8' )
1223+ else :
1224+ __str += str (self .map [a ])
1225+ else :
1226+ __str += str (self .map [a ]).encode ('utf-8' , errors = 'replace' ).decode ('utf-8' )
12211227 __str += " "
12221228 __str += "] parent="
12231229 if self .parent :
@@ -1228,7 +1234,7 @@ def __str__(self):
12281234 else :
12291235 __str += "None"
12301236 except AttributeError as ex :
1231- print (f '⛔️ self={ self .__class__ .__name__ } : { ex } ' , file = sys .stderr )
1237+ print ('⛔️ self=%s: %s' % ( self .__class__ .__name__ , ex ) , file = sys .stderr )
12321238
12331239 return __str
12341240
@@ -3260,7 +3266,9 @@ def __treeFromWindowHierarchy(self, windowHierarchy):
32603266 self .__processWindowHierarchyChild (self .root , idCount , version )
32613267
32623268 @staticmethod
3263- def __attributesFromWindowHierarchyChild (unique_id , child : WindowHierarchyChild ):
3269+ # python 3
3270+ # def __attributesFromWindowHierarchyChild(unique_id, child: WindowHierarchyChild):
3271+ def __attributesFromWindowHierarchyChild (unique_id , child ):
32643272 bounds = ((int (child .bounds [0 ]), int (child .bounds [1 ])), (int (child .bounds [2 ]), int (child .bounds [3 ])))
32653273 return {'index' : child .index , 'text' : child .text , 'resource-id' : child .resource_id , 'class' : child .clazz ,
32663274 'package' : child .package , 'content-desc' : child .content_description , 'checkable' : child .checkable ,
@@ -3271,8 +3279,9 @@ def __attributesFromWindowHierarchyChild(unique_id, child: WindowHierarchyChild)
32713279
32723280 def __processWindowHierarchyChild (self , node , idCount , version ):
32733281 if node .id != 'hierarchy' :
3274- node .unique_id = f'id/no_id/{ idCount } '
3275- attributes = ViewClient .__attributesFromWindowHierarchyChild (f'id/no_id/{ idCount } ' , node )
3282+ node .unique_id = 'id/no_id/%d' % idCount
3283+ # FIXME: unique_id is not needed as a param
3284+ attributes = ViewClient .__attributesFromWindowHierarchyChild (node .unique_id , node )
32763285 view = View .factory (attributes , self .device , version = version , uiAutomatorHelper = self .uiAutomatorHelper )
32773286 self .views .append (view )
32783287 idCount += 1
@@ -3359,7 +3368,10 @@ def __traverse(root, indent="", transform=View.__str__, stream=sys.stdout):
33593368 print (s , file = stream )
33603369 return
33613370 else :
3362- ius = "%s%s" % (indent , s if isinstance (s , str ) else str (s , 'utf-8' , 'replace' ))
3371+ if sys .version_info [0 ] < 3 :
3372+ ius = "%s%s" % (indent , s if isinstance (s , unicode ) else unicode (s , 'utf-8' , 'replace' ))
3373+ else :
3374+ ius = "%s%s" % (indent , s if isinstance (s , str ) else str (s , 'utf-8' , 'replace' ))
33633375 print (ius .encode ('utf-8' , 'replace' ).decode ('utf-8' ), file = stream )
33643376
33653377 for ch in root .children :
0 commit comments