File: _compat.pyx

package info (click to toggle)
python-pyproj 3.7.2-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,728 kB
  • sloc: python: 13,453; sh: 273; makefile: 90
file content (31 lines) | stat: -rw-r--r-- 727 bytes parent folder | download | duplicates (6)
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
import array


cpdef bytes cstrencode(str pystr):
    """
    Encode a string into bytes.
    """
    try:
        return pystr.encode("utf-8")
    except UnicodeDecodeError:
        return pystr.decode("utf-8").encode("utf-8")


cdef str cstrdecode(const char *instring):
    if instring != NULL:
        return instring
    return None


IF CTE_PYTHON_IMPLEMENTATION == "CPython":
    from cpython cimport array

    cdef array.array _ARRAY_TEMPLATE = array.array("d", [])

    cdef array.array empty_array(int npts):
        return array.clone(_ARRAY_TEMPLATE, npts, zero=False)

ELSE:
    # https://github.com/pyproj4/pyproj/issues/854
    cdef empty_array(int npts):
        return array.array("d", [float("NaN")] * npts)