1
0
Fork 0

Add a copy of the nginx builder module

This commit is contained in:
Luca Beltrame 2021-10-20 23:42:40 +02:00
parent ee9e06b1ee
commit 261e9d9fbb
Signed by: einar
GPG key ID: 4707F46E9EC72DEC
14 changed files with 1237 additions and 0 deletions

View file

@ -0,0 +1,65 @@
"""
The Block API provides objects to programatically generate nginx configurations.
Example::
>>> from nginx.config.api import Config, Section, Location
>>> events = Section('events', worker_connections='1024')
>>> http = Section('http', include='../conf/mime.types')
>>> http.sections.add(
... Section(
... 'server',
... Location(
... '/foo',
... proxy_pass='upstream',
... ),
... server_name='_',
... )
... )
>>> nginx = Config(
... events,
... http,
... worker_processes='auto',
... daemon='on',
... error_log='var/error.log',
... )
>>> print(nginx)
error_log var/error.log;
worker_processes auto;
daemon on;
http {
include ../conf/mime.types;
server {
server_name _;
location /foo {
proxy_pass upstream;
}
}
}
events {
worker_connections 1024;
}
.. The objects in this submodule are largely inspired by code found in https://github.com/FeroxTL/pynginxconfig-new.
"""
from .blocks import EmptyBlock, Block, Location
from .options import Comment, KeyOption, KeyValueOption, KeyMultiValueOption
__all__ = [
'EmptyBlock',
'Block',
'Location',
'KeyOption',
'KeyValueOption',
'KeyValueMultilines',
'KeyMultiValueOption',
'Comment',
'Config',
'Section'
]
# aliases
Config = EmptyBlock
Section = Block