def _lazy_re_compile(regex, flags=0):
 def _compile():
  if isinstance(regex, str):
   return re.compile(regex, flags)
  else:
   assert (not flags), 'flags must be empty if regex is passed pre-compiled'
   return regex
 return SimpleLazyObject(_compile)

def _lazy_re_compile ( regex , flags = 0 ) : def _compile ( ) : if isinstance ( regex , str ) : return re . compile ( regex , flags ) else : assert ( not flags ) , 'flags must be empty if regex is passed pre-compiled' return regex return SimpleLazyObject ( _compile )
lazily compile a regex with flags .