certbot_nginx.nginxparser

Very low-level nginx config parser based on pyparsing.

class certbot_nginx.nginxparser.RawNginxParser(source)[source]

Bases: object

A class that parses nginx configuration with pyparsing.

parse()[source]

Returns the parsed tree.

as_list()[source]

Returns the parsed tree as a list.

class certbot_nginx.nginxparser.RawNginxDumper(blocks)[source]

Bases: object

A class that dumps nginx configuration from the provided tree.

certbot_nginx.nginxparser.loads(source)[source]

Parses from a string.

Parameters:source (str) – The string to parse
Returns:The parsed tree
Return type:list
certbot_nginx.nginxparser.load(_file)[source]

Parses from a file.

Parameters:_file (file) – The file to parse
Returns:The parsed tree
Return type:list
certbot_nginx.nginxparser.dumps(blocks)[source]

Dump to a string.

Parameters:
  • block (UnspacedList) – The parsed tree
  • indentation (int) – The number of spaces to indent
Return type:

str

certbot_nginx.nginxparser.dump(blocks, _file)[source]

Dump to a file.

Parameters:
  • block (UnspacedList) – The parsed tree
  • _file (file) – The file to dump to
  • indentation (int) – The number of spaces to indent
Return type:

NoneType

class certbot_nginx.nginxparser.UnspacedList(list_source)[source]

Bases: list

Wrap a list [of lists], making any whitespace entries magically invisible

_coerce(inbound)[source]

Coerce some inbound object to be appropriately usable in this object

Parameters:inbound – string or None or list or UnspacedList
Returns:(coerced UnspacedList or string or None, spaced equivalent)
Return type:tuple
insert(i, x)[source]

Insert object before index.

append(x)[source]

Append object to the end of the list.

extend(x)[source]

Extend list by appending elements from the iterable.

pop(_i=None)[source]

Remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(_)[source]

Remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()[source]

Reverse IN PLACE.

sort(_cmp=None, _key=None, _Rev=None)[source]

Sort the list in ascending order and return None.

The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).

If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.

The reverse flag can be set to sort in descending order.

is_dirty()[source]

Recurse through the parse tree to figure out if any sublists are dirty

_spaced_position(idx)[source]

Convert from indexes in the unspaced list to positions in the spaced one