def _get_closest_begin(begin_before, end_before):
 end_iter = reversed(end_before)
 begin_iter = reversed(begin_before)
 while True:
  try:
   b = next(begin_iter)
  except:
   raise NoEnvError('No open environment detected')
  try:
   e = next(end_iter)
  except:
   break
  if (not (b.begin() < e.begin())):
   break
 return b

def _get_closest_begin ( begin_before , end_before ) : end_iter = reversed ( end_before ) begin_iter = reversed ( begin_before ) while True : try : b = next ( begin_iter ) except : raise NoEnvError ( 'No open environment detected' ) try : e = next ( end_iter ) except : break if ( not ( b . begin ( ) < e . begin ( ) ) ) : break return b
returns the closest begin .