Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pyutils.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _PYUTILS__H__
  20. #define _PYUTILS__H__
  21. #include "config.h"
  22. #include <fcgiapp.h>
  23. #include <fcgi_stdio.h> /* fcgi library; put it first*/
  24. #define PY_SSIZE_T_CLEAN
  25. #include <Python.h>
  26. #include "logger.h"
  27. #include "python_pyfcgi.h"
  28. /* Imports from libpyfcgi python module header */
  29. extern PyObject* response_status;
  30. extern PyObject* response_headers;
  31. extern PyObject* libpyfcgi_self;
  32. /**@brief Call Py_Initialize & update_python_path
  33. */
  34. void pyinit();
  35. /**@brief Add . to the embed pythonpath
  36. * @deprecated Py_SetPath breaks Py_GetPrefix()... now
  37. */
  38. void update_python_path();
  39. /**@brief Fetch stdout & stderr python flush() function
  40. * @param pystdout_flush will point on &sys.stdout.flush() python function
  41. * @param pystderr_flush will point on &sys.stderr.flush() python function
  42. */
  43. void fetch_pyflush(PyObject** pystdout_flush, PyObject** pystderr_flush);
  44. /**@brief Create two pipes for stdout & stderr
  45. * @ingroup worker_process
  46. * @param pipe_out pipe for stdout
  47. * @param pipe_err pipe for stderr
  48. * @warning Deprecated behavior. We will us ioin like classes for std & err
  49. * output
  50. */
  51. void update_python_fd(int pipe_out[2], int pipe_err[2]);
  52. /**@brief Clear then update python sys.environ using current FCGI environ
  53. * @ingroup worker_process
  54. * @note The environ has to be set without a call to os.putenv, the problem
  55. * is that the os.environ is a special mapping calling putenv on setitem...
  56. * For these reason the os.environ will be replaced by a new dict instance for
  57. * each request...
  58. * @param py_osmod Python os module
  59. * @param environ The environ string provided by libfcgi
  60. * @return Python env dict
  61. */
  62. PyObject* update_pyenv(PyObject* py_osmod, char** environ);
  63. /**@brief Import & return the python entrypoint callable
  64. * from PyFCGI_conf.py_entrymod & PyFCGI_conf.py_entryfun */
  65. PyObject* import_entrypoint();
  66. /**@brief Init and return libpyfcgi */
  67. PyObject* pyinit_libpyfcgi();
  68. /**@brief Return the start_response() python function for pep333 worker */
  69. PyObject* get_start_response();
  70. /**@brief Logs an exception */
  71. void log_expt(int priority);
  72. /**@brief Set python version
  73. * @param version version buffer */
  74. void pyfcgi_python_version(char version[16]);
  75. /**@brief Import os module and exit on error
  76. * @return Imported module */
  77. PyObject* python_osmod();
  78. #endif