← Back
Editing: parser_obj.cpython-38.pyc
U �]�: � @ s� d Z ddlZddlZddlZddlmZ ddlmZ e�e �Z dZdegZG dd� de �ZG d d � d e�Zdd� ZG d d� de�ZG dd� de�Zdd� Zdd� Zddd�Zdd� Zddd�ZdS )zx This file contains parsing routines and object classes to help derive meaning from raw lists of tokens from pyparsing. � N)�errors)�Listz managed by Certbot�#c @ s� e Zd ZdZejZddd�Zedd� �Z e ejdd� ��Zejdd d��Z ejddd ��Zejdd� �Zejddd��Zddd�ZdS )�Parsablez� Abstract base class for "Parsable" objects whose underlying representation is a tree of lists. :param .Parsable parent: This object's parsed parent in the tree Nc C s g | _ d | _|| _d S �N)�_dataZ_tabs�parent��selfr � r �:/usr/lib/python3/dist-packages/certbot_nginx/parser_obj.py�__init__ s zParsable.__init__c C s t ttfS )a Returns object types that this class should be able to `parse` recusrively. The order of the objects indicates the order in which the parser should try to parse each subitem. :returns: A list of Parsable classes. :rtype list: )�Block�Sentence� Statements)�clsr r r � parsing_hooks s zParsable.parsing_hooksc C s t � �dS )z� Returns whether the contents of `lists` can be parsed into this object. :returns: Whether `lists` can be parsed as this object. :rtype bool: N��NotImplementedError�Zlistsr r r �should_parse) s zParsable.should_parseFc C s t � �dS )aZ Loads information into this object from underlying raw_list structure. Each Parsable object might make different assumptions about the structure of raw_list. :param list raw_list: A list or sublist of tokens from pyparsing, containing whitespace as separate tokens. :param bool add_spaces: If set, the method can and should manipulate and insert spacing between non-whitespace tokens and lists to delimit them. :raises .errors.MisconfigurationError: when the assumptions about the structure of raw_list are not met. Nr �r Zraw_list� add_spacesr r r �parse3 s zParsable.parsec C s t � �dS )a Iterates across this object. If this object is a leaf object, only yields itself. If it contains references other parsing objects, and `expanded` is set, this function should first yield itself, then recursively iterate across all of them. :param bool expanded: Whether to recursively iterate on possible children. :param callable match: If provided, an object is only iterated if this callable returns True when called on that object. :returns: Iterator over desired objects. Nr �r �expanded�matchr r r �iterateB s zParsable.iteratec C s t � �dS )a� Guess at the tabbing style of this parsed object, based on whitespace. If this object is a leaf, it deducts the tabbing based on its own contents. Other objects may guess by calling `get_tabs` recursively on child objects. :returns: Guess at tabbing for this object. Should only return whitespace strings that does not contain newlines. :rtype str: Nr �r r r r �get_tabsO s zParsable.get_tabs� c C s t � �dS )a! This tries to set and alter the tabbing of the current object to a desired whitespace string. Primarily meant for objects that were constructed, so they can conform to surrounding whitespace. :param str tabs: A whitespace string (not containing newlines). Nr �r �tabsr r r �set_tabs\ s zParsable.set_tabsc s � fdd�| j D �S )a� Dumps back to pyparsing-like list tree. The opposite of `parse`. Note: if this object has not been modified, `dump` with `include_spaces=True` should always return the original input of `parse`. :param bool include_spaces: If set to False, magically hides whitespace tokens from dumped output. :returns: Pyparsing-like list tree. :rtype list: c s g | ]}|� � ��qS r )�dump��.0�elem��include_spacesr r � <listcomp>r s z!Parsable.dump.<locals>.<listcomp>�r �r r) r r( r r$ f s z Parsable.dump)N)F)FN)r )F)�__name__� __module__�__qualname__�__doc__�abc�ABCMetaZ __metaclass__r �classmethodr �staticmethod�abstractmethodr r r r r# r$ r r r r r s"