Nginx Configuration Parser
An nginx configuration parser that uses Pyparsing.
You can parse a nginx configuration file with load or loads method:
>>> from nginxparser_eb import load
>>> load(open("/etc/nginx/sites-enabled/foo.conf"))
[['server'], [
['listen', '80'],
['server_name', 'foo.com'],
['root', '/home/ubuntu/sites/foo/']]]]
Same as other serialization modules also you can export configuration with
>>> from nginxparser_eb import load
>>> load(open("/etc/nginx/sites-enabled/foo.conf"))
[['server'], [
['listen', '80'],
['server_name', 'foo.com'],
['root', '/home/ubuntu/sites/foo/']]]]
Same as other serialization modules also you can export configuration with dump and dumps methods.
>>> from nginxparser_eb import dumps
>>> dumps([['server'], [
['listen', '80'],
['server_name', 'foo.com'],
['root', '/home/ubuntu/sites/foo/']]])
'server {
listen 80;
server_name foo.com;
root /home/ubuntu/sites/foo/;
}'
Installation
The Nginx parser is now available via pip:
pip install nginxparser_eb
Troubleshooting
Exception like this may occur:
ParseException: Expected {Group:({W:(ABCD...) [{Suppress:(<SPC><TAB><CR><LF>) !W:({};)}] Suppress:(";")}) | Forward: ...} (at char 0), (line:1, col:1)
It may be caused by importing Cmd2 package which modifies pyparsing globals. In particular, the following code causes the trouble:
pyparsing.ParserElement.setDefaultWhitespaceChars(' \t')
In this setting the pyparser parser stops parsing after a new line.
From this reason, importing pyparsing modifies set white space chars back to
pyparsing.ParserElement.setDefaultWhitespaceChars(" \n\t\r")
Credits
Based on the https://github.com/fatiherikli/nginxparser and CertBot Nginx parser.
Metadata
Release files for nginxparser_eb 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nginxparser_eb-0.0.9.tar.gz | 12.4 kB | Details |
Release files / nginxparser_eb-0.0.9.tar.gz
| Download URL | nginxparser_eb-0.0.9.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3fb2a237dd0d3738887a764ade567770d37d2af70409b1c0fda57ff3a6f11b1
|
|
BLAKE2b-256 checksum How to use checksums |
1f97a176ab33d8c6bdcae00d6e20204281f9361941dccfc6cdf2aafc37509334
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |