def rex_search(self, regexp, flags=0, byte=False, default=NULL): """ Search the regular expression in response body. :param byte: if False then search is performed in `response.unicode_body()` else the rex is searched in `response.body`. Note: if you use default non-byte mode than do not forget to build your regular expression with re.U flag. Return found match object or None """ regexp = normalize_regexp(regexp, flags) match = None if byte: if not isinstance(regexp.pattern, unicode) or not PY3K: #if PY3K: #body = self.body_as_bytes() #else: #body = self.body match = regexp.search(self.body) else: if isinstance(regexp.pattern, unicode) or not PY3K: ubody = self.unicode_body() match = regexp.search(ubody) if match: return match else: if default is NULL: rstr = regexp#regexp.source if regexp.hasattr('source') else regexp raise DataNotFound('Could not find regexp: %s' % regexp) else: return default
def rex_search(self, regexp, flags=0, byte=False, default=NULL): """ Search the regular expression in response body. :param byte: if False then search is performed in `response.unicode_body()` else the rex is searched in `response.body`. Note: if you use default non-byte mode than do not forget to build your regular expression with re.U flag. Return found match object or None """ regexp = normalize_regexp(regexp, flags) match = None if byte: if not isinstance(regexp.pattern, unicode) or not PY3K: #if PY3K: #body = self.body_as_bytes() #else: #body = self.body match = regexp.search(self.body) else: if isinstance(regexp.pattern, unicode) or not PY3K: ubody = self.unicode_body() match = regexp.search(ubody) if match: return match else: if default is NULL: rstr = regexp #regexp.source if regexp.hasattr('source') else regexp raise DataNotFound('Could not find regexp: %s' % regexp) else: return default
def rex(self, regexp, flags=0, byte=False): norm_regexp = rex_tools.normalize_regexp(regexp, flags) matches = list(norm_regexp.finditer(self.html())) return RexResultList(matches, source_rex=norm_regexp)