← Back
Editing: parser.cpython-38.pyc
U �]�s � @ sz d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z ddl mZ ddlm Z ddlmZ ddlmZmZmZmZmZmZ e�e�ZG dd � d e�Zd d� Zd<dd �Zdd� Zdd� Zdd� Zdd� Z dd� Z!dd� Z"dd� Z#dd� Z$dZ%e&dd e%d!d"g�Z'd#Z(d$d%e(gZ)d&d'� Z*d(d)� Z+d=d*d+�Z,d,d-� Z-d.d/� Z.d0d1� Z/d2d3� Z0d4d5� Z1d6d7� Z2d8d9� Z3d:d;� Z4dS )>z>NginxParser is a member object of the NginxConfigurator class.� N)�errors)�os)�obj)�nginxparser)�Union�Dict�Set�Any�List�Tuplec @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zdd � Z dd� Z dd� Zdd� Zd.dd�Z dd� Zd/dd�Zdd� Zdd � Zd0d!d"�Zd1d#d$�Zd2d&d'�Zd(d)� Zd*d+� Zd3d,d-�Zd%S )4�NginxParserz�Class handles the fine details of parsing the Nginx Configuration. :ivar str root: Normalized absolute path to the server root directory. Without trailing slash. :ivar dict parsed: Mapping of file paths to parsed trees c C s* i | _ tj�|�| _| �� | _| �� d S �N)�parsedr �path�abspath�root�_find_config_root�config_root�load)�selfr � r �6/usr/lib/python3/dist-packages/certbot_nginx/parser.py�__init__ s zNginxParser.__init__c C s i | _ | �| j� dS )z/Loads Nginx files into a parsed tree. N)r �_parse_recursivelyr )r r r r r ( s zNginxParser.loadc C s� | � |�}| �|�}|D ]�}|D ]�}t|�r<| �|d � q |d dgksX|d dgkr |d D ]\}t|�r|| �|d � q`|d dgkr`|d dgkr`|d D ]}t|�r�| �|d � q�q`q qdS )a Parses nginx config files recursively by looking at 'include' directives inside 'http' and 'server' blocks. Note that this only reads Nginx files that potentially declare a virtual host. :param str filepath: The path to the files to parse, as a glob � r Zhttp�serverN)�abs_path�_parse_files�_is_include_directiver )r �filepath�trees�tree�entryZsubentryZserver_entryr r r r / s zNginxParser._parse_recursivelyc C s0 t j�|�s$t j�t j�| j|��S t j�|�S )z�Converts a relative path to an absolute path relative to the root. Does nothing for paths that are already absolute. :param str path: The path :returns: The absolute path :rtype: str )r r �isabs�normpath�joinr )r r r r r r K s zNginxParser.abs_pathc C sn | � � }i }|D ]X}|| D ]J\}}t|�}|d D ]0}|�� }||krR|j||<