code: def format_from_extension(self, extension):
          
          formats = [name
                     for name, format in self._formats.items()
                     if format.get('file_extension', None) == extension]
          if len(formats) == 0:
              return None
          elif len(formats) == 2:
              raise RuntimeError("Several extensions are registered with "
                                 "that extension; please specify the format "
                                 "explicitly.")
          else:
              return formats[0]
docs: Find a format from its extension.