def _psed(text, before, after, limit, flags):
 atext = text
 if limit:
  limit = re.compile(limit)
  comps = text.split(limit)
  atext = ''.join(comps[1:])
 count = 1
 if ('g' in flags):
  count = 0
  flags = flags.replace('g', '')
 aflags = 0
 for flag in flags:
  aflags |= RE_FLAG_TABLE[flag]
 before = re.compile(before, flags=aflags)
 text = re.sub(before, after, atext, count=count)
 return text

def _psed ( text , before , after , limit , flags ) : atext = text if limit : limit = re . compile ( limit ) comps = text . split ( limit ) atext = '' . join ( comps [ 1 : ] ) count = 1 if ( 'g' in flags ) : count = 0 flags = flags . replace ( 'g' , '' ) aflags = 0 for flag in flags : aflags |= RE_FLAG_TABLE [ flag ] before = re . compile ( before , flags = aflags ) text = re . sub ( before , after , atext , count = count ) return text
does the actual work for file .