def match(self, view_dict): """ return True if this view_selector matches a view_dict @param view_dict: a view in dict, element of DeviceState.views @return: """ if 'text' in view_dict and 'resource_id' in view_dict \ and 'class' in view_dict and 'bounds' in view_dict: pass else: return False if self.text_re and not safe_re_match(self.text_re, view_dict['text']): return False if self.resource_id_re and not safe_re_match(self.resource_id_re, view_dict['resource_id']): return False if self.class_re and not safe_re_match(self.class_re, view_dict['class']): return False bounds = view_dict['bounds'] bound_x_min = bounds[0][0] bound_x_max = bounds[1][0] bound_y_min = bounds[0][1] bound_y_max = bounds[1][1] for (x, y) in self.in_coordinates: if x < bound_x_min or x > bound_x_max or y < bound_y_min or y > bound_y_max: return False for (x, y) in self.out_coordinates: if bound_x_min < x < bound_x_max and bound_y_min < y < bound_y_max: return False return True
def match(self, device_state): """ check if the selector matches the DeviceState @param device_state: DeviceState @return: """ if self.activity_re and not safe_re_match(self.activity_re, device_state.foreground_activity): return False for service_re in self.service_re_set: service_re_matched = False if device_state.background_services is None: return False if not isinstance(device_state.background_services, list): return False for background_service in device_state.background_services: if safe_re_match(service_re, background_service): service_re_matched = True break if not service_re_matched: return False for view_selector in self.views: view_selector_matched = False view_dicts = device_state.views if view_dicts is None: return False if not isinstance(view_dicts, list): return False for view_dict in view_dicts: if view_selector.match(view_dict): view_selector_matched = True break if not view_selector_matched: return False return True
def check_grammar_identifier_is_valid(value): m = safe_re_match(IDENTIFIER_RE, value) if not m: msg = "invalid identifier: %s" % value raise ScriptSyntaxError(msg)