def rewrite_file_imports(item, vendored_libs):
 text = item.read_text()
 text = re.sub('pkg_resources.extern', 'pip._vendor', text)
 for lib in vendored_libs:
  text = re.sub(('(\\n\\s*)import %s' % lib), ('\\1from pip._vendor import %s' % lib), text)
  text = re.sub(('(\\n\\s*)from %s' % lib), ('\\1from pip._vendor.%s' % lib), text)
 item.write_text(text)

def rewrite_file_imports ( item , vendored_libs ) : text = item . read_text ( ) text = re . sub ( 'pkg_resources.extern' , 'pip._vendor' , text ) for lib in vendored_libs : text = re . sub ( ( '(\\n\\s*)import %s' % lib ) , ( '\\1from pip._vendor import %s' % lib ) , text ) text = re . sub ( ( '(\\n\\s*)from %s' % lib ) , ( '\\1from pip._vendor.%s' % lib ) , text ) item . write_text ( text )
rewrite import xxx and from xxx import for vendored_libs .