def make_pattern(pat):
 if (pat is None):
  return None
 if isinstance(pat, six.binary_type):
  pat = pat.decode('utf8')
 if isinstance(pat, six.text_type):
  pat = re.compile(pat)
 if hasattr(pat, 'search'):
  return pat.search
 if hasattr(pat, '__call__'):
  return pat
 raise ValueError(('Cannot make callable pattern object out of %r' % pat))

def make_pattern ( pat ) : if ( pat is None ) : return None if isinstance ( pat , six . binary_type ) : pat = pat . decode ( 'utf8' ) if isinstance ( pat , six . text_type ) : pat = re . compile ( pat ) if hasattr ( pat , 'search' ) : return pat . search if hasattr ( pat , '__call__' ) : return pat raise ValueError ( ( 'Cannot make callable pattern object out of %r' % pat ) )
find element pattern can be a regex or a callable .