## The Python Imaging Library# $Id$## GRIB stub adapter## Copyright (c) 1996-2003 by Fredrik Lundh## See the README file for information on usage and redistribution.#from__future__importannotationsfromtypingimportIOfrom.importImage,ImageFile_handler=None
[docs]classGribStubImageFile(ImageFile.StubImageFile):format="GRIB"format_description="GRIB"def_open(self)->None:offset=self.fp.tell()ifnot_accept(self.fp.read(8)):msg="Not a GRIB file"raiseSyntaxError(msg)self.fp.seek(offset)# make something upself._mode="F"self._size=1,1loader=self._load()ifloader:loader.open(self)def_load(self)->ImageFile.StubHandler|None:return_handler
def_save(im:Image.Image,fp:IO[bytes],filename:str|bytes)->None:if_handlerisNoneornothasattr(_handler,"save"):msg="GRIB save handler not installed"raiseOSError(msg)_handler.save(im,fp,filename)# --------------------------------------------------------------------# RegistryImage.register_open(GribStubImageFile.format,GribStubImageFile,_accept)Image.register_save(GribStubImageFile.format,_save)Image.register_extension(GribStubImageFile.format,".grib")