class_docstr: ImageResource handling utility.
  
  Represents a request for reading or saving an image resource. This
  object wraps information to that request and acts as an interface
  for the plugins to several resources; it allows the user to read
  from filenames, files, http, zipfiles, raw bytes, etc., but offer
  a simple interface to the plugins via ``get_file()`` and
  ``get_local_filename()``.
  
  For each read/write operation a single Request instance is used and passed
  to the can_read/can_write method of a format, and subsequently to
  the Reader/Writer class. This allows rudimentary passing of
  information between different formats and between a format and
  associated reader/writer.
  
  Parameters
  ----------
  uri : {str, bytes, file}
      The resource to load the image from.
  mode : str
      The first character is "r" or "w", indicating a read or write
      request. The second character is used to indicate the kind of data:
      "i" for an image, "I" for multiple images, "v" for a volume,
      "V" for multiple volumes, "?" for don't care.
class_docstr_tok: ["ImageResource","handling","utility",".","Represents","a","request","for","reading","or","saving","an","image","resource",".","This","object","wraps","information","to","that","request","and","acts","as","an","interface","for","the","plugins","to","several","resources",";","it","allows","the","user","to","read","from","filenames",",","files",",","http",",","zipfiles",",","raw","bytes",",","etc.",",","but","offer","a","simple","interface","to","the","plugins","via","``","get_file","(",")","``","and","``","get_local_filename","(",")","``",".","For","each","read\/write","operation","a","single","Request","instance","is","used","and","passed","to","the","can_read\/can_write","method","of","a","format",",","and","subsequently","to","the","Reader\/Writer","class",".","This","allows","rudimentary","passing","of","information","between","different","formats","and","between","a","format","and","associated","reader\/writer",".","Parameters","--","--","--","--","--","uri",":","{","str",",","bytes",",","file","}","The","resource","to","load","the","image","from",".","mode",":","str","The","first","character","is","``","r","''","or","``","w","''",",","indicating","a","read","or","write","request",".","The","second","character","is","used","to","indicate","the","kind","of","data",":","``","i","''","for","an","image",",","``","I","''","for","multiple","images",",","``","v","''","for","a","volume",",","``","V","''","for","multiple","volumes",",","``","?","''","for","do","n't","care","."]
code: def __init__(
      self,
      uri,
      mode,
      *,
      extension=None,
      format_hint: str = None,
      **kwargs,
  ):
      # General
      self.raw_uri = uri
      self._uri_type = None
      self._filename = None
      self._extension = None
      self._format_hint = None
      self._kwargs = kwargs
      self._result = None  # Some write actions may have a result
  
      # To handle the user-side
      self._filename_zip = None  # not None if a zipfile is used
      self._bytes = None  # Incoming bytes
      self._zipfile = None  # To store a zipfile instance (if used)
  
      # To handle the plugin side
      self._file = None  # To store the file instance
      self._file_is_local = (
          False  # whether the data needs to be copied at end
      )
      self._filename_local = (
          None  # not None if using tempfile on this FS
      )
      self._firstbytes = None  # For easy header parsing
  
      # To store formats that may be able to fulfil this request
      # self._potential_formats = []
  
      # Check mode
      try:
          self._mode = Mode(mode)
      except ValueError:
          raise ValueError(f"Invalid Request.Mode: {mode}")
  
      # Parse what was given
      self._parse_uri(uri)
  
      # Set extension
      if extension is not None:
          if extension[0] != ".":
              raise ValueError(
                  "`extension` should be a file extension starting with a `.`,"
                  f" but is `{extension}`."
              )
          self._extension = extension
      elif self._filename is not None:
          if self._uri_type in (URI_FILENAME, URI_ZIPPED):
              path = self._filename
          else:
              path = urlparse(self._filename).path
          ext = Path(path).suffix.lower()
          self._extension = ext if ext != "" else None
  
      if format_hint is not None:
          warnings.warn(
              "The usage of `format_hint` is deprecated and will be removed "
              "in ImageIO v3. Use `extension` instead.",
              DeprecationWarning,
          )
  
      if format_hint is not None and format_hint[0] != ".":
          raise ValueError(
              "`format_hint` should be a file extension starting with a `.`,"
              f" but is `{format_hint}`."
          )
  
      self.format_hint = format_hint
  
imports: import os
  from io import BytesIO
  import zipfile
  import tempfile
  import shutil
  import enum
  import warnings
  from ..core import urlopen, get_remote_file
  from pathlib import Path
  from urllib.parse import urlparse
  from typing import Optional
label_desc: Use image node_id 1 to create a new Request object from inherited base classes: object with example: obj = Request(uri, mode)