docs: def escape_path(pth):
      """ Hex/unicode escapes a path.
  
      Escapes a path so that it can be represented faithfully in an HDF5
      file without changing directories. This means that leading ``'.'``
      must be escaped. ``'/'`` and null must be escaped to. Backslashes
      are escaped as double backslashes. Other escaped characters are
      replaced with ``'\\xYY'``, ``'\\uYYYY', or ``'\\UYYYYYYYY'`` where Y
      are hex digits depending on the unicode numerical value of the
      character. for ``'.'``, both slashes, and null; this will be the
      former (``'\\xYY'``).
  
      .. versionadded:: 0.2
  
      Parameters
      ----------
      pth : str or bytes
          The path to escape.
  
      Returns
      -------
      epth : str
          The escaped path.
  
      Raises
      ------
      TypeError
          If `pth` is not the right type.
  
      See Also
      --------
      unescape_path
  
      """
      if isinstance(pth, bytes):
          pth = pth.decode('utf-8')
      if sys.hexversion >= 0x03000000:
          if not isinstance(pth, str):
              raise TypeError('pth must be str or bytes.')
          match = _find_dots_re.match(pth)
          if match is None:
              prefix = ''
              s = pth
          else:
              prefix = '\\x2e' * match.end()
              s = pth[match.end():]
      else:
          if not isinstance(pth, unicode):
              raise TypeError('pth must be unicode or str.')
          match = _find_dots_re.match(pth)
          if match is None:
              prefix = unicode('')
              s = pth
          else:
              prefix = unicode('\\x2e') * match.end()
              s = pth[match.end():]
      return prefix + _find_fslashnull_re.sub(_replace_fun_escape, s)