File: _network.pyx

package info (click to toggle)
python-pyproj 3.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,720 kB
  • sloc: python: 13,468; sh: 273; makefile: 90
file content (48 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
include "proj.pxi"

import os

from pyproj.utils import strtobool

from pyproj._compat cimport cstrencode
from pyproj._context cimport pyproj_context_create
from pyproj._context import _set_context_network_enabled


def set_network_enabled(active=None):
    """
    .. versionadded:: 3.0.0

    Set whether PROJ network is enabled by default. This has the same
    behavior as the `PROJ_NETWORK` environment variable.

    See: :c:func:`proj_context_set_enable_network`

    Parameters
    ----------
    active: bool, optional
        Default is None, which uses the system defaults for networking.
        If True, it will force the use of network for grids regardless of
        any other network setting. If False, it will force disable use of
        network for grids regardless of any other network setting.
    """
    if active is None:
        # in the case of the global context, need to reset network
        # setting based on the environment variable every time if None
        # because it could have been changed by the user previously
        active = strtobool(os.environ.get("PROJ_NETWORK", "OFF"))
    _set_context_network_enabled(bool(active))


def is_network_enabled():
    """
    .. versionadded:: 3.0.0

    See: :c:func:`proj_context_is_network_enabled`

    Returns
    -------
    bool:
        If PROJ network is enabled by default.
    """
    return proj_context_is_network_enabled(pyproj_context_create()) == 1