File: utils.py

package info (click to toggle)
python-vega-datasets 0.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,128 kB
  • sloc: python: 623; makefile: 22
file content (19 lines) | stat: -rw-r--r-- 594 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from vega_datasets.core import Dataset
from urllib.request import urlopen
from urllib.error import HTTPError, URLError


def connection_ok() -> bool:
    """Check web connection.
    Returns True if web connection is OK, False otherwise.
    """
    try:
        urlopen(Dataset.base_url, timeout=1)
        # if an index page is ever added, this will pass through
        return True
    except HTTPError:
        # There's no index for BASE_URL so Error 404 is expected
        return True
    except URLError:
        # This is raised if there is no internet connection
        return False