Splits the C{View} attributes in C{strArgs} and optionally adds the view id to the C{viewsById} list. Unique Ids ========== It is very common to find C{View}s having B{NO_ID} as the Id. This turns very difficult to use L{self.findViewById()}. To help in this
(self, strArgs)
| 3193 | print("there are %d views in this dump" % len(self.views), file=sys.stderr) |
| 3194 | |
| 3195 | def __splitAttrs(self, strArgs): |
| 3196 | """ |
| 3197 | Splits the C{View} attributes in C{strArgs} and optionally adds the view id to the C{viewsById} list. |
| 3198 | |
| 3199 | Unique Ids |
| 3200 | ========== |
| 3201 | It is very common to find C{View}s having B{NO_ID} as the Id. This turns very difficult to |
| 3202 | use L{self.findViewById()}. To help in this situation this method assigns B{unique Ids}. |
| 3203 | |
| 3204 | The B{unique Ids} are generated using the pattern C{id/no_id/<number>} with C{<number>} starting |
| 3205 | at 1. |
| 3206 | |
| 3207 | @type strArgs: str |
| 3208 | @param strArgs: the string containing the raw list of attributes and values |
| 3209 | |
| 3210 | @return: Returns the attributes map. |
| 3211 | """ |
| 3212 | |
| 3213 | if self.useUiAutomator: |
| 3214 | raise RuntimeError("This method is not compatible with UIAutomator") |
| 3215 | # replace the spaces in text:mText to preserve them in later split |
| 3216 | # they are translated back after the attribute matches |
| 3217 | textRE = re.compile('%s=%s,' % (self.textProperty, _nd('len'))) |
| 3218 | m = textRE.search(strArgs) |
| 3219 | if m: |
| 3220 | __textStart = m.end() |
| 3221 | __textLen = int(m.group('len')) |
| 3222 | __textEnd = m.end() + __textLen |
| 3223 | s1 = strArgs[__textStart:__textEnd] |
| 3224 | s2 = s1.replace(' ', WS) |
| 3225 | strArgs = strArgs.replace(s1, s2, 1) |
| 3226 | |
| 3227 | idRE = re.compile(r"(?P<viewId>id/\S+)") |
| 3228 | attrRE = re.compile(r'%s(?P<parens>\(\))?=%s,(?P<val>[^ ]*)' % (_ns('attr'), _nd('len')), flags=re.DOTALL) |
| 3229 | hashRE = re.compile('%s@%s' % (_ns('class'), _nh('oid'))) |
| 3230 | |
| 3231 | attrs = {} |
| 3232 | viewId = None |
| 3233 | m = idRE.search(strArgs) |
| 3234 | if m: |
| 3235 | viewId = m.group('viewId') |
| 3236 | if DEBUG: |
| 3237 | print("found view with id=%s" % viewId, file=sys.stderr) |
| 3238 | |
| 3239 | for attr in strArgs.split(): |
| 3240 | m = attrRE.match(attr) |
| 3241 | if m: |
| 3242 | __attr = m.group('attr') |
| 3243 | __parens = '()' if m.group('parens') else '' |
| 3244 | __len = int(m.group('len')) |
| 3245 | __val = m.group('val') |
| 3246 | if WARNINGS and __len != len(__val): |
| 3247 | warnings.warn("Invalid len: expected: %d found: %d s=%s e=%s" % ( |
| 3248 | __len, len(__val), __val[:50], __val[-50:])) |
| 3249 | if __attr == self.textProperty: |
| 3250 | # restore spaces that have been replaced |
| 3251 | __val = __val.replace(WS, ' ') |
| 3252 | attrs[__attr + __parens] = __val |
no test coverage detected