MCPcopy Create free account
hub / github.com/dtmilano/AndroidViewClient / __parseTree

Method __parseTree

src/com/dtmilano/android/viewclient.py:3285–3344  ·  view source on GitHub ↗

Parses the View tree contained in L{receivedLines}. The tree is created and the root node assigned to L{self.root}. This method also assigns L{self.viewsById} values using L{View.getUniqueId} as the key. @type receivedLines: str @param receivedLines: the string rece

(self, receivedLines, windowId=None)

Source from the content-addressed store, hash-verified

3283 return attrs
3284
3285 def __parseTree(self, receivedLines, windowId=None):
3286 """
3287 Parses the View tree contained in L{receivedLines}. The tree is created and the root node assigned to L{self.root}.
3288 This method also assigns L{self.viewsById} values using L{View.getUniqueId} as the key.
3289
3290 @type receivedLines: str
3291 @param receivedLines: the string received from B{View Server}
3292 """
3293
3294 self.root = None
3295 self.viewsById = {}
3296 self.views = []
3297 parent = None
3298 parents = []
3299 treeLevel = -1
3300 newLevel = -1
3301 lastView = None
3302 for v in receivedLines:
3303 if v == '' or v == 'DONE' or v == 'DONE.':
3304 break
3305 attrs = self.__splitAttrs(v)
3306 if not self.root:
3307 if v[0] == ' ':
3308 raise Exception("Unexpected root element starting with ' '.")
3309 self.root = View.factory(attrs, self.device, self.build[VERSION_SDK_PROPERTY], self.forceViewServerUse,
3310 windowId, self.uiAutomatorHelper)
3311 if DEBUG: self.root.raw = v
3312 treeLevel = 0
3313 newLevel = 0
3314 lastView = self.root
3315 parent = self.root
3316 parents.append(parent)
3317 else:
3318 newLevel = (len(v) - len(v.lstrip()))
3319 if newLevel == 0:
3320 raise Exception("newLevel==0 treeLevel=%d but tree can have only one root, v=%s" % (treeLevel, v))
3321 child = View.factory(attrs, self.device, self.build[VERSION_SDK_PROPERTY], self.forceViewServerUse,
3322 windowId, self.uiAutomatorHelper)
3323 if DEBUG: child.raw = v
3324 if newLevel == treeLevel:
3325 parent.add(child)
3326 lastView = child
3327 elif newLevel > treeLevel:
3328 if (newLevel - treeLevel) != 1:
3329 raise Exception("newLevel jumps %d levels, v=%s" % ((newLevel - treeLevel), v))
3330 parent = lastView
3331 parents.append(parent)
3332 parent.add(child)
3333 lastView = child
3334 treeLevel = newLevel
3335 else: # newLevel < treeLevel
3336 for _ in range(treeLevel - newLevel):
3337 parents.pop()
3338 parent = parents.pop()
3339 parents.append(parent)
3340 parent.add(child)
3341 treeLevel = newLevel
3342 lastView = child

Callers 1

setViewsMethod · 0.95

Calls 6

__splitAttrsMethod · 0.95
rangeFunction · 0.85
appendMethod · 0.80
addMethod · 0.80
getUniqueIdMethod · 0.80
factoryMethod · 0.45

Tested by

no test coverage detected