code: def intervals_from_codec(
      codec_name: str,
  ) -> IntervalSet:  # pragma: no cover
      """Return an IntervalSet of characters which are part of this codec."""
      assert codec_name == codecs.lookup(codec_name).name
      fname = charmap_file(f"codec-{codec_name}")
      try:
          with gzip.GzipFile(fname) as gzf:
              encodable_intervals = json.load(gzf)
  
      except Exception:
          # This loop is kinda slow, but hopefully we don't need to do it very often!
          encodable_intervals = []
          for i in range(sys.maxunicode + 1):
              try:
                  chr(i).encode(codec_name)
              except (
                  Exception
              ):  # usually _but not always_ UnicodeEncodeError
                  pass
              else:
                  encodable_intervals.append((i, i))
  
      res = IntervalSet(encodable_intervals)
      res = res.union(res)
      try:
          # Write the Unicode table atomically
          tmpdir = storage_directory("tmp")
          tmpdir.mkdir(exist_ok=True, parents=True)
          fd, tmpfile = tempfile.mkstemp(dir=tmpdir)
          os.close(fd)
          # Explicitly set the mtime to get reproducible output
          with gzip.GzipFile(tmpfile, "wb", mtime=1) as o:
              o.write(json.dumps(res.intervals).encode())
          os.renames(tmpfile, fname)
      except Exception:
          pass
      return res
  
file_path: catboost/contrib/python/hypothesis/py3/hypothesis/internal/charmap.py
imports: import codecs
  import gzip
  import json
  import os
  import sys
  import tempfile
  import unicodedata
  from functools import lru_cache
  from typing import Dict, Tuple
  from hypothesis.configuration import storage_directory
  from hypothesis.errors import InvalidArgument
  from hypothesis.internal.intervalsets import IntervalSet
label_desc: Use image node_id 3 for calling a global function with example usage: intervals_from_codec(codec_name) and returns: res