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 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. */
  37. void update_python_path();
  38. /**@brief Fetch stdout & stderr python flush() function
  39. * @param PyObject* pystdout_flush
  40. * @param PyObject* pystderr_flush
  41. */
  42. void fetch_pyflush(PyObject**, PyObject**);
  43. /**@brief Create two pipes for stdout & stderr
  44. * @ingroup worker_process
  45. * @params int[2] pystdout
  46. * @params int[2] pystderr
  47. */
  48. void update_python_fd(int[2], int[2]);
  49. /**@brief Clear then update python sys.environ using current FCI environ
  50. * @ingroup worker_process
  51. * @note The environ has to be set without a call to os.putenv, the problem
  52. * is that the os.environ is a special mapping calling putenv on setitem...
  53. * For these reason the os.environ will be replaced by a new dict instance for
  54. * each request...
  55. * @param PyObject* os module
  56. * @return Python env dict
  57. */
  58. PyObject* update_pyenv(PyObject*, char**);
  59. /**@brief Import & return the python entrypoint callable
  60. * from PyFCGI_conf.py_entrymod & PyFCGI_conf.py_entryfun */
  61. PyObject* import_entrypoint();
  62. /**@brief Return the start_response() python function for pep333 worker */
  63. PyObject* get_start_response();
  64. /**@brief Logs an exception */
  65. void log_expt(int priority);
  66. /**@brief Set python version
  67. * @param char[16] version buffer */
  68. void pyfcgi_python_version(char[16]);
  69. /**@brief Import os module and exit on error
  70. * @return Imported module */
  71. PyObject* python_osmod();
  72. #endif