Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sid220/pyhp
https://github.com/sid220/pyhp
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sid220/pyhp
- Owner: Sid220
- Created: 2023-05-26T20:37:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-29T23:06:33.000Z (over 1 year ago)
- Last Synced: 2024-10-11T16:50:59.969Z (about 1 month ago)
- Language: C
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PyHP - Python Hypertext Processor
PyHP is a hypertext processor for the Python language written in C. **CURRENTLY IN DEVELEOPMENT**.## Demo
Consider the following document:
```phpPyHP Version Information
Information
for i in __pyhp_info__.keys():
print("" + i + "" + __escape_html__(__pyhp_info__[i]) + "")
?>Environmental Variables
for env in __ENVIRONMENTAL_VARIABLES__:
print("" + env.partition("=")[0] + "" + env.partition("=")[2] + "")
?>GET Params
req_meth = __get_env__("REQUEST_METHOD")
?>if req_meth == "GET":
if len(__get__) > 0:
for get_param in __get__:
print("" + get_param + "" + __get__[get_param][0] + "")
else:
print("None")
else:
print("None, request method not GET")
?>POST Params
if req_meth == "POST":
if len(__post__) > 0:
for post_param in __post__:
print("" + post_param + "" + __post__[post_param][0] + "")
else:
print("None")
else:
print("None, request method not POST")
?>```
Run this through PyHP, whether the CLI or socket, and you'll get something that looks like this:
```htmlPyHP Version 1.0.0 Information
Information
Version_PyHP1.0.0Version_CC11Compilation_DateMay 26 2023 13:49:10IS_FCGI1
Environmental Variables
FCGI_ROLERESPONDERQUERY_STRINGREQUEST_METHODGETCONTENT_TYPEapplication/x-www-form-urlencodedCONTENT_LENGTH0SCRIPT_NAME/info.pyhpREQUEST_URI/info.pyhpDOCUMENT_URI/info.pyhpDOCUMENT_ROOT/var/www/htmlSERVER_PROTOCOLHTTP/1.1REQUEST_SCHEMEhttpGATEWAY_INTERFACECGI/1.1SERVER_SOFTWAREnginx/1.18.0REMOTE_ADDR127.0.0.1REMOTE_PORT40592REMOTE_USERSERVER_ADDR127.0.0.1SERVER_PORT8010SERVER_NAME_REDIRECT_STATUS200REQUEST_URI/info.pyhpSCRIPT_FILENAME/var/www/html/info.pyhpREQUEST_BODYHTTP_HOSTlocalhost:8010HTTP_USER_AGENTcurl/7.81.0HTTP_ACCEPT*/*HTTP_CONTENT_LENGTH0HTTP_CONTENT_TYPEapplication/x-www-form-urlencoded
GET Params
None
POST Params
None, request method not POST
```
Cool, huh?## Installation
Currently, no binaries are available to download, so you must build from source.#### Install required libraries
```shell
sudo apt install libpython3.10 libpython3.10-dev
```
#### Download
```shell
git clone https://github.com/Sid220/PyHP.git
```
#### Build
```shell
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/path/to/ninja -G Ninja -S /path/to/git_clone -B /path/to/where/you/want/build
```
#### Run (optional)
```shell
/path/to/where/you/want/build/PyHP
```
#### Configure with NGINX
First start the socket:
```shell
chmod +x /path/to/git_clone/start.sh
/path/to/git_clone/start.sh
```
Then configure with NGINX. Here is some example configuration to get you started:
```nginx
server
{
root /var/www/html;
listen 8010 default_server;
listen [::]:8010 default_server;
server_name _;
location /
{
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}location ~ \.pyhp$
{
fastcgi_pass unix:/tmp/phyp-fcgi.sock;
include fastcgi_params;
fastcgi_param REQUEST_URI $uri;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param REQUEST_BODY $request_body;
}
}
```
Now open up [http://localhost:8010/yourfile.pyhp](http://localhost:8010/yourfile.pyhp) to see some magic!
## ToDo
PyHP is by no means finished, here's what we hope to do:- [ ] Speed up add_content and add_header methods, or find a better way to output
- [ ] Take other files through CLI
- [ ] Improve/create indentation fixer to remove extra indentation in files
- [ ] Add support for HTTP files
- [ ] Write Python documentation
- [ ] Write documentation for FastCGI and CLI
- [ ] Write NGINX guide
- [ ] More customization options
- [ ] Add support for custom headers from Python (`__header_add__` funtion)
- [ ] Add more tags such as `` or ``