File: python.pyx

package info (click to toggle)
pythontracer 8.10.16-1.2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 352 kB
  • ctags: 461
  • sloc: python: 441; ansic: 325; makefile: 9
file content (27 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (2)
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
from posix cimport FILE

cdef extern from "Python.h":
    object PyString_FromStringAndSize(char *, Py_ssize_t)
    int PyString_AsStringAndSize(object, char **s, Py_ssize_t *len) except -1
    enum PyTraceEvent:
        PyTrace_CALL
        PyTrace_EXCEPTION
        PyTrace_LINE
        PyTrace_RETURN
        PyTrace_C_CALL
        PyTrace_C_EXCEPTION
        PyTrace_C_RETURN

    FILE *PyFile_AsFile(fileobj)
    ctypedef void *Py_tracefunc
    void PyEval_SetProfile(Py_tracefunc func, object arg)
    # PyEval_SetTrace is the same as PyEval_SetProfile, except it also
    # gets line number events
    void PyEval_SetTrace(Py_tracefunc func, object arg)

cdef FILE *file_from_obj(fileobj) except NULL:
    cdef FILE *file
    file = PyFile_AsFile(fileobj)
    if NULL == file:
        raise Error("Invalid fileobj")
    return file