class_docstr: Mock class used to patch requests.sessions.Session.send.
  
  In nilearn's tests this replaces the function used by requests to send
  requests over the network.
  
  Test functions can configure this object to specify what response is
  expected when sending requests to specific URLs. This is done by adding
  items to the ordered dictionary self.url_mapping
  
  When a Sender receives a request, it tries to match it against the keys in
  url_mapping, and then against urls found in
  nilearn/datasets/tests/data/archive_contents/ (details below). If a key
  matches, the corresponding value is used to compute the response. If no key
  matches, an response with empty content is returned.
  
  If several keys match, the one that was inserted most recently in
  url_mapping is used.
  
  Specifying keys
  ---------------
  Keys of url_mapping can be:
  
  - a `str`: it is used as a glob pattern, matched against the url with
    fnmatch (If special characters need to be matched literally they can be
    escaped with []). For example:
       '*' matches everything
       '*example.com/*' matches 'https://www.example.com/data'
                        but not 'https://example.org'
  
  - a `re.Pattern` (ie a compiled regex): it is matched against the url, and
    groups can be used to capture parts needed to construct the response. For
    example:
      re.compile(r'.*example.org/subject_(\d+)\.tar\.gz')
        matches 'https://example.org/subject_12.tar.gz' and captures '12'
        but does not match 'https://example.org/subject_12.csv'
  
  If none of the keys in url_mapping matches, the Sender turns to the
  contents of nilearn/datasets/tests/data/archive_contents. Files in this
  directory or any subdirectory are used to build responses that contain zip
  or tar archives containing a certain list of files. (.py and .pyc files are
  ignored)
  The first line of a file in archive_contents is a glob pattern stating to
  which urls it applies. If it matches, the subsequent lines are paths that
  will exist inside the archive. The files created in the archive are
  empty. For example, if a file looks like:
    https://example.org/subj_*.tar.gz
    README.txt
    data/img.nii.gz
    data/labels.csv
  the response will be a tar gzipped archive with this structure:
      .
      ├── data
      │   ├── img.nii.gz
      │   └── labels.csv
      └── README.txt
  
  Moreover, if the first line starts with 'format:' it is used to determine
  the archive format. For example: 'format: zip', 'format: gztar' (see
  `shutil` documentation for available formats). In this case the second line
  contains the url pattern and the rest of the file lists the contents.
  The paths for the archive contents must use '/' as path separator, it gets
  converted to the OS's separator when the file is read.
  A helper script is provided in
  nilearn/datasets/tests/data/list_archive_contents.sh to generate such files
  from a url.
  
  Finally, if no key and no file matches the request url, a response with an
  empty content is returned.
  
  Specifying values
  -----------------
  
  Once a key matches, the corresponding value is used to build a response.
  The value can be:
  - a callable: it is called as value(match, request), where request is the
    input `Request` object, and match is the url if the key was a string and
    the `re.Match` resulting from matching the key if it was a `re.Pattern`.
    The result of this call is then processed as described below.
  - an instance of the Response class: it used without modification.
  - a `bytes`: result is a Response with status 200 and these bytes as
    content.
  - a str: if the key was a `re.Pattern`, the value can contain
    backreferences that are replaced with groups matched in the url, e.g.
    \1, \g<groupname>. The resulting string is then encoded with UTF-8 to
    build the response content. For example:
      re.compile(r'.*example\.org/(.*)'): r'hello, \1'
      results in b'hello, nilearn' if the url is https://example.org/nilearn
  - an int: results in an response with this status code. The content is
    b"ERROR" if the status code is in [400, 600[ and b"OK" otherwise
  - an `Exception`: it is raised
  - a `pathlib.Path`: the contents of the response are the contents of that
    file. (can also be anything that has a `read_bytes` attribute,
    e.g a `pathlib2.Path`)
  - an object with a `to_filename` method, eg a Nifti1Image: it is serialized
    to .nii.gz to produce the response content.
  
  To help construct values that mock downloaded archives, this module
  provides `dict_to_archive` and `list_to_archive` helper functions; more
  details in their docstrings.
  
  Inspecting history
  ------------------
  Senders record all sent requests in `sent_requests`, the visited urls in
  `visited_urls`, and the number of sent requests in `url_count`
code: def __init__(self):
      self.url_mapping = OrderedDict()
      self.sent_requests = []
      self._archive_contents_index = _index_archive_contents()
  
imports: import fnmatch
  import json
  import os
  import pickle
  import re
  import shutil
  import tempfile
  from collections import OrderedDict
  from pathlib import Path
  from unittest.mock import MagicMock
  import pytest
  from requests.exceptions import HTTPError
  from nilearn._utils.testing import serialize_niimg
label_desc: Use image node_id 1 to create a new Sender object  with example: obj = Sender()