Dynamic object creation in Python
Classes are first-class objects in Python.

amap = {
  'zip': zipfile.ZipFile,
  'rar': rarfile.RarFile
}

 ...

with amap[archive_type](encode(f)) as archive:
   ...


or

with amap.get(archive_type, rarfile.RarFile)(encode(f)) as archive:
   ...