PyHP
PyHP 3.1
PyHP is a package that allows you to embed Python code like PHP code into HTML and other text files. A script is called either by the configuration of the web server or a shebang and communicates with the web server via WSGI.
<?pyhp and ?> tagsexit and sys.exit terminate the script, not the whole serveratexit registered functions dont get called until server shutdown in WSGI moderegister_shutdown_function
pyhp-cli commandpyhp-cgi commandpyhp.wsgi.apps submodulepyhp.wsgi.util submodule$_SERVER as SERVER
$_REQUEST as REQUEST
$_GET as GET
$_POST as POST
$_COOKIE as COOKIE
$_FILES as FILES
http_response_codeheaderheaders_listheader_removeheaders_sentheader_register_callback with an additional replace keyword argument to register multiple callbackssetcookie with an additional samesite keyword argumentsetrawcookie also with an additional samesite keyword argumentregister_shutdown_function with reversed callback execution order (LIFO)opcache_compile_file which raises Exceptions instead of returning False when compilation failsopcache_invalidateopcache_is_script_cachedopcache_reset-c or --config cli argumentPYHPCONFIG environment variable~/.config/pyhp.toml/etc/pyhp.tomlRuntimeError if not foundpyhp.backends
pyhp-backend or python3 -m pyhp.backends cli commandsThis section shows you how to install PyHP on your computer. If you want to use pyhp scripts on your website by CGI you have to additionally enable CGI in your webserver.
python3 setup.py bdist_wheel
PYHPCONFIG environ variable or copy pyhp.toml to one of the config file locations to use the CLI commandsdebian/build_deb.sh in the root directory of the project.sudo dpkg -i python3-pyhp-core_{version}-1_all.deb
python3-toml and python3-werkzeug are installed to use the CLI commandspyhp-backend clear will be executed on uninstall or upgrade if the backend is a cache, remember this when using paths containing ~ for the file cachePYHPCONFIG environ variable or copy pyhp.toml to one of the config file locationspyhp-* commands import sys
import re
import tempfile
from wsgiref.simple_server import make_server
from pyhp.compiler import parsers, util, generic
from pyhp.backends.files import Directory
from pyhp.wsgi.apps import ConcurrentWSGIApp
from pyhp.wsgi.proxys import LocalStackProxy
from pyhp.wsgi.interfaces.php import PHPWSGIInterfaceFactory
from pyhp.wsgi.interfaces.phputils import UploadStreamFactory
compiler = util.Compiler(
parsers.RegexParser(
re.compile(r"<?pyhps"),
re.compile(r"s?>")
),
util.Dedenter(
generic.GenericCodeBuilder(-1)
)
)
interface_factory = PHPWSGIInterfaceFactory(
200,
[("Content-type", "text/html; charset="UTF-8"")],
None,
("GET", "POST", "COOKIE"),
8000000,
UploadStreamFactory(
tempfile.gettempdir(),
20
)
)
sys.stdout = proxy = LocalStackProxy(sys.stdout)
with Directory(".", compiler) as backend:
with ConcurrentWSGIApp("tests/embedding/syntax.pyhp", backend, proxy, interface_factory) as app:
with make_server("", 8000, app) as httpd:
httpd.serve_forever() from wsgiref.simple_server import make_server
import toml
from pyhp.wsgi.util import ConcurrentWSGIAppFactory
config = toml.load("pyhp.toml")
with ConcurrentWSGIAppFactory.from_config(config) as factory:
with factory.app("tests/embedding/syntax.pyhp") as app:
with make_server("", 8000, app) as httpd:
httpd.serve_forever()