def _regex_from_encoded_pattern(s):
 if (s.startswith('/') and (s.rfind('/') != 0)):
  idx = s.rfind('/')
  (pattern, flags_str) = (s[1:idx], s[(idx + 1):])
  flag_from_char = {'i': re.IGNORECASE, 'l': re.LOCALE, 's': re.DOTALL, 'm': re.MULTILINE, 'u': re.UNICODE}
  flags = 0
  for char in flags_str:
   try:
    flags |= flag_from_char[char]
   except KeyError:
    raise ValueError(("unsupported regex flag: '%s' in '%s' (must be one of '%s')" % (char, s, ''.join(flag_from_char.keys()))))
  return re.compile(s[1:idx], flags)
 else:
  return re.compile(re.escape(s))

def _regex_from_encoded_pattern ( s ) : if ( s . startswith ( '/' ) and ( s . rfind ( '/' ) != 0 ) ) : idx = s . rfind ( '/' ) ( pattern , flags_str ) = ( s [ 1 : idx ] , s [ ( idx + 1 ) : ] ) flag_from_char = { 'i' : re . IGNORECASE , 'l' : re . LOCALE , 's' : re . DOTALL , 'm' : re . MULTILINE , 'u' : re . UNICODE } flags = 0 for char in flags_str : try : flags |= flag_from_char [ char ] except KeyError : raise ValueError ( ( "unsupported regex flag: '%s' in '%s' (must be one of '%s')" % ( char , s , '' . join ( flag_from_char . keys ( ) ) ) ) ) return re . compile ( s [ 1 : idx ] , flags ) else : return re . compile ( re . escape ( s ) )
foo -> re .