class_docstr: Some little helper to deal with cookies
  
  Lazy loading from the shelved dictionary
  
  TODO: this is not multiprocess or multi-thread safe implementation due to shelve auto saving etc
class_docstr_tok: ["Some","little","helper","to","deal","with","cookies","Lazy","loading","from","the","shelved","dictionary","TODO",":","this","is","not","multiprocess","or","multi-thread","safe","implementation","due","to","shelve","auto","saving","etc"]
code: def _load(self):
      if self._cookies_db is not None:
          return
      if self._filename:
          filename = self._filename
          cookies_dir = os.path.dirname(filename)
      else:
          cookies_dir = os.path.join(
              platformdirs.user_config_dir(), "datalad"
          )  # FIXME prolly shouldn't hardcode 'datalad'
          filename = os.path.join(cookies_dir, "cookies")
  
      # TODO: guarantee restricted permissions
  
      if not os.path.exists(cookies_dir):
          os.makedirs(cookies_dir)
  
      lgr.debug("Opening cookies DB %s", filename)
      try:
          self._cookies_db = shelve.open(
              filename, writeback=True, protocol=2
          )
      except Exception as exc:
          lgr.warning(
              "Failed to open cookies DB %s: %s",
              filename,
              CapturedException(exc),
          )
  
file_path: datalad/datalad/support/cookies.py
imports: from __future__ import annotations
  import atexit
  import logging
  import os.path
  import shelve
  from pathlib import Path
  from typing import Any, Optional
  import platformdirs
  from datalad.support.exceptions import CapturedException
  from .network import get_tld
label_desc: Use image node_id 3 for calling the CookiesDB obj's underlying member method code with example usage: obj._load() without return types