%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/xkit/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/xkit/__pycache__/xorgparser.cpython-312.pyc

�

p��O�W���ddlmZddlmZddlZddlmZmZddlZGd�de�ZGd�de�Z	Gd	�d
e�Z
Gd�de�ZGd
�de�Z
y)�)�print_function)�unicode_literalsN)�stdout�stderrc��eZdZdZy)�IdentifierExceptionz#Raise if no identifier can be foundN��__name__�
__module__�__qualname__�__doc__���1/usr/lib/python3/dist-packages/xkit/xorgparser.pyrrs��-�rrc��eZdZdZy)�OptionExceptionz&Raise when an option is not available.Nr	rrrrr���0�rrc��eZdZdZy)�SectionExceptionz&Raise when a section is not available.Nr	rrrrr"rrrc��eZdZdZy)�ParseExceptionz&Raise when a postion is not available.Nr	rrrrr&rrrc�n�eZdZdZd/d�Zd�Zd�Zeee�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd/d�Zd
�Z		d0d�Z		d1d�Z		d1d�Zd/d�Zd2d�Zd/d�Zd/d�Zd/d�Zd/d�Zd/d�Z	d2d�Z	d/d�Zd/d�Zd�Zd2d�Z		d1d�Z d2d�Z!d�Z"d �Z#d!�Z$d"�Z%d/d#�Z&d$�Z'd%�Z(d&�Z)d'�Z*d(�Z+d)�Z,d2d*�Z-d+�Z.		d1d,�Z/d/d-�Z0d.�Z1y)3�Parserz^Only low-level methods here.
    
    See the xutils.XUtils subclass for higher-level methods.Nc��d|_d|_||_ddddddd	d
ddd
ddd|j|jf|_|jdd|_gd�|_gd�|_ij|j
�|_g|_	ij|jd�|_
|jD]}i|j|<�|j�y)a�source = can be an object or a file. If set to None (default)
                 Parser will start from scratch with an empty
                 configuration.
        
        Public:
        
        comments = name of the section which stores the commented lines
                   located outside of the sections in the xorg.conf.

        globaldict = a global dictionary containing all the sections and
                     options. For further information on globaldict, have a
                     look at __check_sanity() and at get_value().

        globaldict['Comments'] = stores the commented lines located inside of
                                 the sections in the xorg.conf.

        require_id = a list of the sections which require to have an
                    "Identifier" set in the xorg.conf (e.g. Device sections).

        identifiers = a dictionary of the sections which require identifiers.

        sections = a tuple containing the names of all the sections in
                   globaldict. Their names are not guaranteed to be all legal
                   in xorg.conf (see "valid_sections").

        valid_sections = a tuple containing the names of all the sections
                         which __check_sanity() will look for in the
                         xorg.conf. Sections with other names will be ignored
                         by self._check_sanity().

        references = a list containing the names of all the possible
                     references.�
SubSection�Comments�InputDevice�Device�Module�Monitor�Screen�ServerLayout�ServerFlags�
Extensions�Files�
InputClass�DRI�VideoAdaptor�Vendor�ModesN���)r&rrr r!r")rrr r!r)�
subsection�commentsection�source�sections�valid_sections�
require_id�
references�fromkeys�identifiers�comments�_gdict�
_check_sanity)�selfr.�elems   r�__init__zParser.__init__.s���D'���(������&�!�!�"�!�'�&�%� �%��'�!� �����,�,�.��
�"#�m�m�C�R�0����������;�;�t���7�����
��k�k�$�-�-��3����K�K�	#�D� "�D�K�K���	#�	
���rc��|jS�N�r6)r8s r�_get_globalzParser._get_global~s���{�{�rc��||_yr<r=)r8�global_dicts  r�_set_globalzParser._set_global�s	��!��rc��|j}|dk(rg}nIt|d�s-t|d�}|j�}|j	�n|j�}ij|jd�}d}d}d}d}d}	d}
d}|D�]U}|j�jd��r�|dk(r|jj|��n||}
|dk(r�|j|jj|i�|j|j|}|j|
i�||
jd	d�||
jd
|
�||
jdd�||
jdg�||
dj|j��n�||j}|j|jj|ji�|j|j|j}|j|i�||jd	�||jd
|
�||jd|�||jdg�||dj|j��~�n:|j�j�jd�r�d}|j D]>}|j�j#d
|j�zd
z�dk7s�:d}|}n|sd|z}t%|��|dk(r
|	dz
}	}d}d}�n�d}t%|��|j�j�jd�dk(r/|	dz
}	|dk(r|dk(r||xxdz
cc<d}d}�n;d}t%|��|j�j�jd�dk(r�|
dz
}
|dk(r�|dk(r�d}||j#d
�dz|j'd
�j�}|jj|ji�||j}i|j|j|<|j|j|}||d<	|||d
<||d	<g|d<~�n1d}t%|��|j�j�jd�dk(r1|
dz
}
|dk(rd}||jxxdz
cc<n�d}t%|��|dk7r�|j�dk7r�|dk(rC|j|jdjd|j�zdz�nc|jj|i�||}|j|j|g�jd|j�zdz�|dz
}��X|s>|	dzdk7s|
dzdk7r
d}t%|��|j+�|j-�y|j+�y#t($r~d}t%|��wxYw)a�Perform a sanity check of the file and fill self.globaldict with
        all the sections and subsections in the xorg.conf
        
        
        empty = is the file empty? If yes, then don't check if:
            * the last section is not complete
            * there are duplicates
        
        has_section:
            * == True: a section is already open
            * == False: a section is closed and/or a new section can be opened
            
        has_subsection:
            * == True: a subsection is already open
            * == False: a section is closed and/or a new section can be opened
            
        section_flag:
            * == '':a section is closed and/or a new section can be opened
            * == the name the current section
        
        section_tags = counter of the number of Section and EndSection strings
        
        subsection_tags = counter of the number of SubSection and EndSubSection
                         strings
        
        lines_list = the list of the lines in the source object.
        
        global_iters = counts how many times each kind of section
                             (section_flag) is found in the xorg.confN�write�rrTF��#�
identifier�position�section�options�"r+z;The name in the following line is invalid for a section:
%s�z,Sections cannot be nested in other sections.�
endsectionz$An EndSection is in the wrong place.r,z7SubSections can be nested only in well formed sections.�
endsubsectionz=SubSections can be closed only after being previously opened.�	�
�zThe last section is incomplete.)r.�hasattr�open�	readlines�closer3r/�strip�
startswithr5�appendr6r-�
setdefaultr,�lowerr0�findr�rfind�KeyError�_fill_identifiers�
_check_syntax)r8�file�
lines_list�myfile�global_iters�empty�has_section�has_subsection�section_flag�section_tags�subsection_tags�it�line�section_pos�	temp_dict�	curlength�
subsection_id�test_line_found�sectrI�errors                     rr7zParser._check_sanity�s2��B�{�{���4�<��J��4��)��d�C���#�-�-�/�
�����!�^�^�-�
��{�{�4�=�=�!�4��������������
���F	�D��z�z�|�&�&�s�+��%�'��M�M�(�(��.�".�|�"<�K�%��.����D�$7�$7�8�C�C�L�RT�U�$(�K�K��0C�0C�$D�\�$R�	�!�,�,�[�"�=�!�+�.�9�9�,��M�!�+�.�9�9�*�k�R�!�+�.�9�9�)�T�J�!�+�.�9�9�)�R�H�!�+�.�y�9�@�@�����N�$0����$A�	����D�$7�$7�8�C�C�D�O�O�UW�X�$(�K�K��0C�0C�$D�T�_�_�$U�	�!�,�,�Y��;�!�)�,�7�7��m�T�!�)�,�7�7�
�K�P�!�)�,�7�7�	�<�P�!�)�,�7�7�	�2�F�!�)�,�Y�7�>�>�t�z�z�|�L�!�
����#�#�%�0�0��;�"'�� �/�/��D��z�z�|�(�(��t�z�z�|�);�c�)A�B�b�H�*.��"&���	�
'�,�/3�5�E�(��/�/�"�e�+�$��)��'.�� %��&*�� N��,�U�3�3�����#�#�%�0�0��>�$�F���!���$�&�>�U�+B� ��.�!�3�.�#%�L�"'�K�B�E�(��/�/�����#�#�%�0�0��>�$�F��1�$���$�&�>�U�+B�%)�N�$(����3��!�);�)-���C��%:�:?�%�'�"��K�K�*�*�4�?�?�B�?� ,�T�_�_� =�I�>@�D�K�K����0��;�!%���D�O�O� <�Y� G�I�+7�I�i�(�4�0<�\�0J�	�*�-�/<�I�l�+�+-�I�i�(�!�)�E�(��/�/�����#�#�%�0�0��A�T�I��1�$��!�T�)�%*�N� ����1�Q�6�1�2�E�(��/�/��2�%��z�z�|�r�)�)�T�1�!�K�K����8��C�!*�,�,2�F�4�$�*�*�,�3F��3M�,N� �K�K�2�2�<��D�(4�\�(B�I� �K�K��5�@�@��(*�,�,2�F�4�$�*�*�,�3F��3M�,N��!�G�B�MF	�P��a��1�$��!�(;�q�(@�9��$�U�+�+�
�"�"�$�
��� �
�"�"�$��}$�4�%�"4��,�U�3�3�	4�s�X4�4Yc�V�t|j��dkDr'dt|j��z}t|��|j	�|j�}d}|D]}|t||�z
}�|dkDrdt|�z}t|��|jD]@}t|j|�t|j|�k7s�5d}t|��t|jd�dkDrG|jdD]5}|jd|dg��}t|d�dk(s�*d}t|��|j�}t|�dkDr?t|�d	kDr
d
}t|��|jd|d��s
d}t|��y
y
)zuThis method contains the several checks which can guarantee
        compliance with the syntax rules of the xorg.confrz&There cannot be Duplicate Sections:
%sz%There cannot be Broken References:
%szDNot all the sections which require an identifier have an identifier.r"r!)�reflistzNThe ServerLayout section must have at least 1 reference to a "Screen" section.rLzRNo more than one default ServerLayout can be specified in the ServerFlags section.�rH�(The default ServerLayout does not exist.N)�len�get_duplicate_sections�strr�_validate_options�get_broken_referencesr1r6r4�get_references�get_default_serverlayout�
is_section)r8rr�brokenrjrI�screen_references�default_layouts       rr_zParser._check_syntax]s���>�t�*�*�,�-��1�>��D�7�7�9�:�<�E� ��'�'�
	
��� �&�+�+�-��
���	'�G��#�f�W�o�&�&�B�	'�
��6�<��F��L�E� ��'�'����	,�G��4�;�;�w�'�(�C��0@�0@��0I�,J�J�/��$�U�+�+�		,��t�{�{�>�*�+�a�/��;�;�~�6�
0��$(�$7�$7��8?�AI�
�%8�%L�!��(��2�3�q�8�H�E�(��/�/�
0��6�6�8���~���"��>�"�Q�&�A��$�U�+�+��?�?�>�N�1�<M�?�N�B��$�U�+�+�O�
#rc�x�|jD]w}g|j|<d}|j|D]R}	|j|d|�}	|jd�|d}|j|j||f�|dz
}�T�yy#tt
f$rd||fz}t
|��wxYw#t$rY�ZwxYw)a�Fill self.identifiers
        
        self.identifiers has the section types as keys and a list of tuples
        as values. The tuples contain the identifier and the position of
        each section.
        
        Here's a basic scheme:
        
        self.identifiers = {section_type1: [
                                        (identifier1, position1),
                                        (identifier2, position2)
                                      ], etc.
                           }
        
        Concrete example:
        
        self.identifiers = {'Device': [
                                        ('Configured Video Device', 0),
                                        ('Another Video Device', 1)
                                      ],
                            'Screen': [
                                        ('Configured Screen Device', 0),
                                        ('Another Screen Device', 1)
                                      ],
                           } r�
Identifierz8No Identifier for section %s, position %d, can be found.rErLN)	r1r4r6�	get_valuerrrrX�AttributeError)r8rqrjr9rGrrs      rr^zParser._fill_identifiers�s���6�O�O�	�D�%'�D���T�"��B����D�)�
��0�!%����l�B�!G�J���%�%�b�)�!+�A��J�� � ��&�-�-�z�2�.>�?��a���
�	��(�)9�:�0�-�04�d�|�<�E�(��/�/�	0��&����s�B�B-�"B*�-	B9�8B9c�\�ddg}dg}|jD�]}||vs�	|j|D]�}||jk(r|j||d}n|j||}|D]�}|j�}|j	d�dk7r|d|j	d�}d|j�z}|j|d	�
�}t
|�dk(r.|dj�j�|vrt|��|ddj�r��t|������y)
z�One word entries are not acceptable as either options or references

        If a one word entry is found, ParseException will be raised.r%r�endmoderJrFr+rz#The following option is invalid: %sT)�include_nullrLN)
r/r6r,rVr[�_clean_duplicatesrwrZr�isalpha)	r8�sections_whitelist�options_whitelistrIrHrJ�optionrr�optbitss	         rrzzParser._validate_options�sM��&�z�2��&�K���}�}�	8�G��0�0� $���G� 4�8�H��$�/�/�1�"&�+�+�g�"6�x�"@��"K��"&�+�+�g�"6�x�"@��#*�8��!'�����!�;�;�s�+�r�1�%+�A�v�{�{�3�/?�%@�F�!F�$*�L�L�N�"4��#'�"8�"8��FJ�#9�#L�� ��L�A�-�#�A�J�,�,�.�4�4�6�,�-�"0��"7�7�&�q�z�!�}�4�4�6�"0��"7�7�#8�8�	8rc�|�gd�}g}g}|dk(r|j||d}n|j||}|D]�}|j�}|jd�dk7r|d|jd�}|j|�}	|dj	�|vr|j|d�nA|dj	�dk(r+t
|�dkDr|dd	k7r	|j|d���i}	|D]-}|	j|�d	k7r|j|��)||	|<�/|S#ttf$rY��wxYw)
z�See if there are duplicate options in a section

        It is ok to have duplicated references e.g. several Load options, or
        Screen, etc. though)�driver�busidrGrrJrFr+rr�rLN)
r6rVr[r�rZrXrwr��
IndexError�get)
r8rIrH�	blacklist�total�
duplicatesrJr�r��finals
          r�get_duplicate_optionszParser.get_duplicate_optionssc��6�	����
��l�"��k�k�'�*�8�4�Y�?�G��k�k�'�*�8�4�G��	�F��\�\�^�F��{�{�3��2�%���6�;�;�s�#3�4���,�,�V�4�G�
��1�:�#�#�%��2��L�L����,��Q�Z�%�%�'�8�3��7�|�a�'�G�A�J�$�,>�����W�Q�Z�0��+	�0���	'�F��y�y�� �D�(��!�!�&�)� &��f�
�		'�
���#�J�/�
��
�s�A+D(�(D;�:D;c���i}|jD]Y}|j|D]E}|j||�}t|�dkDs�$|j|i�j||��G�[|S)z5Look for and return duplicate options in all sectionsr)r6r�rwrY)r8r�rIr9�duplopts     r�check_duplicate_optionszParser.check_duplicate_optionsMs���
��{�{�	K�G����G�,�
K���4�4�W�d�C���w�<�!�#��)�)�'�2�6�A�A�$�BI�K�
K�	K��rc��g}d}d}d}|jd�}|dkDr�|D]~}|j�s|dk(r|dz
}n5||z
}n/|dzdk7r||z
}n!t|�dkDr|j|�d}|t|�dz
k(r|dk7r|j|�|dz
}��n�|D]{}|j�s||z
}n!t|�dkDr|j|�d}|t|�dz
k(r,|dk7r|j|�n|rd}|j|�|dz
}�}|r't|�|dzdzk7rd}|j|�|S)z�Clean the option and return all its components in a list
        
        include_null - is used only by _validate_options() and makes
        sure that options with a null value assigned in quotation
        marks are not considered as one-word optionsrErrKrLrQ)�count�isspacerwrX)	r8r�r�r��optbitrj�	quotation�optcount�is	         rr�zParser._clean_duplicatesZsp������
���	��<�<��$���a�<��
���y�y�{��C�x�!�Q��	��!���!�1�}��)��!����v�;��?�#�N�N�6�2�%'�F���V��q��(���|����v�.��a���-
�0�
���y�y�{��a�K�F��6�{�Q�����v�.�!#����V��q��(���|����v�.�(�%'�F�#�N�N�6�2��a���%
�(�C��L�H�Q�J��M�9��F��N�N�6�"��rc��i}|jD]y}g}|j|D]}|j|d��|D]H}|j|�dkDs�|j|i�j||j|���J�{|S)zpReturn a dictionary with the duplicate sections i.e. sections
        of the same kind, with the same identifierrrL)r4rXr�rY)r8r�rI�temprqr9s      rrxzParser.get_duplicate_sections�s����
��'�'�	I�G��D��(�(��1�
%�����D��G�$�
%��
I���:�:�d�#�a�'��)�)�'�2�6�A�A�$�7;�z�z�$�7G�I�
I�		I��rc���dg}|dk7rT|j|j|�dk(rt�|r|j||||��n'|j|||��n|j||�|dk(ry|dk(rd|zdz|zt	|�z|zdz}	n|j�j
�|vrd|zdz|zt	|�z|zdz}	nAd|zdzt	|�zdz}	n)d|zdzdz|zdzdz|zt	|�z|zdz}	t|j|�dk(rXi|j|<g|j|d<||jvr)d	|zd
z}
|j|dj|
�|dk(r6|j|D]#}|j||j|	��%y|j||j|	�y)aAdd an option to a section
        
        section= the section which will have the option added
        option= the option to add
        value= the value which will be assigned to the option
        position= e.g. 0 (i.e. the first element in the list of Screen
                      sections)
        option_type= if set to "Option" it will cause the option to look like
                    the following:
                    Option "NameOfTheOption" "Value"
                    
                    Otherwise it will look like the following:
                    NameOfTheOption "Value"
        position= e.g. 0 (i.e. the first element in the list of Screen
                      sections)
        reference= used only in a particular case of reference (see
                   add_reference)
        
        prefix= usually quotation marks are used for the values (e.g. "True")
                however sometimes they don't have to be used
                (e.g. DefaultDepth 24) and prefix should be set to '' instead
                of '"'  �deviceN��valuerHrurOrPrKrz	Identifier	"Default z"
)
r6r�r�
remove_optionryrVrZrwr1rX)r8rIr�r��option_typerH�	reference�prefix�refSections�toaddrGr9s            r�
add_optionzParser.add_option�s,��0 �j���t���{�{�7�#�'�'��1�T�9�&�&���"�"�7�F�%�+3�#�5��"�"�7�F�X�"�F�
���w��/��$���D� �����-��6��U��C�f�L�� ���=�=�?�(�(�*�+�=�!�F�]�T�1�F�:�S��Z�G�%�&�(,�-�E�
!�6�M�D�0�3�u�:�=��D�E��K�'�$�.��4�v�=��C�d�J��� #�E�
�+�-3�4�6:�;�E��t�{�{�7�#�$��)�#%�D�K�K�� �&(�D�K�K�� ��#��$�/�/�)�6��@�5�H�
����G�$�Q�'�.�.�z�:��t�����G�,�
9�����G�$�T�*�1�1�%�8�
9�
�K�K�� ��*�1�1�%�8rc��i}t|j|�dk7�r*|dk(�r|j|D]�}d}|j||D]�}	|dk7r�|	j�j|j��dk7r�|	j�j|j��dk7rs|j	|g�j|�nQ|	j�j|j��dk7r!|j	|g�j|�|dz
}����|S|j|j
|�dk(ryd}|j||D]�}	|dk7r�|	j�j|j��dk7r�|	j�j|j��dk7rs|j	|g�j|�nQ|	j�j|j��dk7r!|j	|g�j|�|dz
}��|S)z=Private method shared by remove_option and comment_out_optionrNr+rL)rwr6rZr[rYrXr�)
r8rIr�r�rHr��	to_remover9rjrks
          r�_get_options_to_blacklistz Parser._get_options_to_blacklist�s���	��t�{�{�7�#�$��)��4�� �K�K��0� �D��B� $���G� 4�T� :�
 �� �D�=�!%�
�
�� 1� 1�&�,�,�.� A�R� G� $�
�
�� 1� 1�%�+�+�-� @�B� F� )� 4� 4�T�2� >� E� E�b� I�#�z�z�|�0�0�����@�B�F� )� 4� 4�T�2� >� E� E�b� I��a���
 � �H��-�;�;�w�'�+�+�H�5��=���B� $���G� 4�X� >� �� �D�=�!%�
�
�� 1� 1�&�,�,�.� A�R� G� $�
�
�� 1� 1�%�+�+�-� @�B� F� )� 4� 4�X�r� B� I� I�"� M� $�z�z�|�0�0�����@�B�F� )� 4� 4�X�r� B� I� I�"� M��a��� � �rc��|j|||||�}|D]+}d}||D]}	|	|z
}
|j|||
=|dz
}�!�-y)aCRemove an option from a section.
        
        section= the section which will have the option removed
        option= the option to remove
        value= if you want to remove an option only if it has a certain value
        position= e.g. 0 (i.e. the first element in the list of Screen
                      sections)rrLN)r�r6)r8rIr�r�rHr�r��part�moddedrk�realposs           rr�zParser.remove_option&so���2�2�7�F�E�2:�I�G�	��	�D��F�!�$��
����-���K�K��(��.�w�7��!���
�	rc��t|j|�}||jvr�|dk7r�d}d}|j|D]i}|j|||�s�	|j|||�j	�j�|j	�j�k(rd}n�k|rWg|j||<|j||||��|j|j||f�|Std|z��|Sg|j||<|S#t$r]|j|||�D]C}|j	�j�|j	�j�k(s�Ad}nY��@wxYw)aCreate a new section and return the position of the section

        The position is relative to the list of sections of the same type
        (e.g. "Screen") so as to make it available in case the user wants
        to add some options to it.
        
        The identifier and the position of the new section is added to 
        self.identifiers[section]
        
        section= the section to create
        identifier= the identifier of a section (if the section requires
                    an identifier)Nr�TFr�z!%s Section requires an identifier)rwr6r1r�rVrZr�r�r4rXr)r8rIrGrHr��create�subr9s        r�make_sectionzParser.make_section9s�������G�,�-���d�o�o�%��T�!�%�����;�;�w�/�*�C��~�~�g�v�s�;�
*� $���w�.4�.1�!3�38�5�7�5�5�7�1;�1A�1A�1C�1I�1I�1K�!L�*/�� %�!L�*�"�57�D�K�K��(��2��O�O�G�V�:�-5�$�7��$�$�W�-�4�4�j�(�5K�L���	*�+N�-4�,6�8�8���.0�D�K�K�� ��*����1 .�*�(,���w���(L�*��$(�J�J�L�$6�$6�$8�'1�'7�'7�'9�'?�'?�'A�%B�-2�F�$)�*��*�s�AD�AF�7F�?Fc��i}|r&	|j||�}|j|d�nb|dk7r&|j||��rJ|j|d�n7t	|j
|j
��}ij|�}||jvrfd}|j|D]R}	t	|j
��j|d�}	||t	|j
��|	<|dz
}�Tt	|j
��}
|
j�d}|
D]}}|j||�}
|
D]}	|j
|j|=�|j!||�|j
||=||}|dk7s�d||z
}|j||=|dz
}�y#t$rY��.wxYw#t$rY��wxYw#t$rY��wxYw)z/Remove Sections by identifier, position or typeNrurrL)�get_positionrYrr~�listr6�keysr3r1r4�index�
ValueError�sort�get_subsectionsr,r]�_remove_comment_entries)r8rIrGrHr��pos�allkeysrjr��ref�
sorted_remover�rq�subsectionsr��identrefr�s                 r�remove_sectionzParser.remove_sectionrs	��
�	��
��'�'���<���$�$�S�$�/�
��
����w���:��$�$�X�t�4��4�;�;�w�/�4�4�6�7�G����G�,�I��d�o�o�%��B�!�-�-�g�6�
�	���y�~�~�/�0�6�6�y��|�D�C�=?�I�d�9�>�>�#3�4�S�9�:��a���

��Y�^�^�-�.�
�������!�	�D��.�.�w��=�K�#�
������D�O�O�4�S�9�
�
�(�(��$�7����G�$�T�*�!���H��4��"�V�+���$�$�W�-�g�6��!���1	��='�
��
��,"����� ����s6�$F/�0A
F?�	G�/	F<�;F<�?	G�
G�	G�Gc�0�|j||||d��y)a�Add a reference to a section from another section.

        For example:
        to put a reference to the Screen section named "Default Screen"
        in the ServerLayout section you should do:

        section='ServerLayout'
        reference='Screen'
        identifier='Default Screen'
        position=0 #the first ServerLayout section

        NOTE: if position is set to None it will add such reference to any
        instance of the section (e.g. to any ServerLayout section)T�r�rHr�N)r��r8rIr�rGrHs     r�
add_referencezParser.add_reference�s ��	
�����*�!)�T�	�	;rc�0�|j||||d��y)a�Remove a reference to a section from another section.

        For example:
        to remove a reference to Screen "Default Screen" from the
        ServerLayout section you should do:

        section='ServerLayout'
        reference='Screen'
        identifier='Default Screen'
        position=0 #the first ServerLayout section

        NOTE: if position is set to None it will remove such reference from
        any instance of the section (e.g. from any ServerLayout section)Tr�N)r�r�s     r�remove_referencezParser.remove_reference�s"��	
���7�I�Z�$,��	�	>rc�n�|dk(r
|j}n|jd�|d=|}ij|�}|D]�}g||<i}	|j|||d��}|s�#	|jd�|d=|D]2}		|	jd�|	d=|	D]}
|	s�|j|
���4	t|j��D]}||j|����|S#t$rg}Y��wxYw#t$r|	r|j|	�Y��wxYw#t$r|r|j|�Y��wxYw)aWGet references to other sections which are located in a section.

        section= the section (e.g. "Screen")
        position= e.g. 0 stands for the 1st Screen section
        reflist= a list of references which this function should look for.
                 The default list of references is self.require_id but this
                 list can be overridden by the reflist argument so that, for
                 example, if reflist is set to ['Device'], this function will
                 look for references to other devices only (references to,
                 say, screens, will be ignored).NrEr+T�r�)	r1rXr3r�rrYr�r�r�)r8rIrHrtrJr2r��reference_dictr�r9�extrefr�s            rr|zParser.get_references�sr���d�?��o�o�G�

�N�N�2������G��[�[��)�
��	9�F�!#�J�v���N�
��n�n�W�f�h�$�n�O���7��J�J�r�N��B�� #�	@��@� �K�K��O� $�R��*.�F��#'�$2�$=�$=�f�$E�F�		@�"&�n�&9�&9�&;�!<�9�I��v�&�-�-�i�8�9�3	9�6���-#�
���
�� .�@�#� .� 9� 9�$� ?��@��&�7��&�1�1�#�6��7�sN�C"� D�:C3�C3�)D�"C0�/C0�3D�D�D�D�D4�3D4c��t|j|j�}|dk(r�|j|D]�}d}|j|jD]�}|j|j|jd�|k(s�2|j|j|jd�|k(s�a|j|j|jd�|k(s��d}��|s��ix}|j|j|<||d<||d<g|d<||d<~|dz
}��yd}|j|jD]�}|j|j|jd�|k(s�2|j|j|jd�|k(s�a|j|j|jd�|k(s��d}��|r4ix}|j|j|<||d<||d<g|d<||d<~yy)	a�Create a new subsection inside of a section.

        section= the section to which the subsection will belong
        identifier= the name of the subsection
        position= the position of the section in the dictionary with the
                  sections (e.g. the 1st "Screen" section would be 0).
                  If set to None, it will create a new subsection in all
                  the instances of the said section (e.g. in all the
                  "Screen" sections)NTrIrGrHFrJrL)rwr6r,r�)	r8rIrGrHrnr9r�r�rms	         r�make_subsectionzParser.make_subsections!������D�O�O�4�5�	��t�����G�,�
#�����;�;�t���7�'�C����D�O�O�4�S�9�=�=�i�H�� ����D�O�O�4�S�9�=�=�l�K�"�#����D�O�O�4�S�9�=�=�j�I���!&��'��JL�L�I����D�O�O� <�Y� G�+2�I�i�(�.8�I�l�+�+-�I�i�(�,0�I�j�)�!���N�I�)
#�0�F��{�{�4�?�?�3�
#���K�K����0��5�9�9�)�D����K�K����0��5�9�9�,�G����K�K����0��5�9�9�*�E���"�F�
#��FH�H�	�D�K�K����8��C�'.�	�)�$�*4�	�,�'�')�	�)�$�(0�	�*�%��
rc�,�t|j|j�}g}|dk(r�|j|jD]q}|j|j|jd�|k(s�2|j|j|jd�|k(s�a|j	|��sn�|j|jD]�}|j|j|jd�|k(s�2|j|j|jd�|k(s�a|j|j|jd�|k(s��|j	|���|D]}|j|j|=�y)a�Remove a subsection from one or more sections.
        
        section= the section to which the subsection belongs
        identifier= the name of the subsection
        position= the position of the section in the dictionary with the
                  sections (e.g. the 1st "Screen" section would be 0).
                  If set to None it will remove a subsection from all the
                  instances of the said section (e.g. in all the "Screen"
                  sections)NrIrGrH)rwr6r,r�rX)r8rIrGrHrnr�r9�items        r�remove_subsectionzParser.remove_subsectionDsl������D�O�O�4�5�	��	��t�����D�O�O�4�
+���K�K����0��6�:�:�9�E����K�K����0��6�:�:�<�H����$�$�T�*�
+����D�O�O�4�
+���K�K����0��6�:�:�9�E����K�K����0��6�:�:�<�H����K�K����0��6�:�:�:�F����$�$�T�*�
+��	3�D����D�O�O�,�T�2�	3rc�\�d}g}g}	|dk(r|j|||�n|j||||��|dk(rd|zdzt|�zdz}
n)d|zdz|z|z|zdz|zt|�z|zdz}
t|j|j�}|dk(r ||gd�|j|jd<|dk(�r�t|j|�}d}
|
|kr�|j|jD]�}|j|j|jd�|
k(s�2|j|j|jd	�|k(s�a|j|j|jd
�|k(s��|j
|
���|
dz
}
|
|kr��t|dz�D]}||vs�|j|||���|j|jD]q}|j|j|jd
�|k(s�2|j|j|jd	�|k(s�a|	j
|��s�n|j|jD]q}|j|j|jd�|k(s�2|j|j|jd
�|k(s�a|	j
|��st|	�dk(rtt|j|j�}||g|d�|j|jt|j|j�<|	j
|�|	D]0}|j|j|d
j
|
��2y)a�Add an option to one or more subsections.
        
        section= the section which contains the subsection
        identifier= the identifier of the SubSection (e.g. Display)
        option= the option to add
        value= the value which will be assigned to the option
        option_type= if set to "Option" it will cause the option to look like
                     the following:
                     Option "NameOfTheOption" "Value"
                    
                     Otherwise it will look like the following:
                     NameOfTheOption "Value"
        position= e.g. 0 (i.e. the option will be added to a subsection which
                  is located in the first element in the list of Screen
                  sections)rKNrurOrPr)rIrGrJrHrIrGrL)rIrGrJrHrJ)	�remove_suboptionryrwr6r,r�rX�ranger�)r8rIrGr�r�r�rHr��
not_to_create�	to_modifyr�rn�cursect_lengthrjr9r�s                r�
add_suboptionzParser.add_suboptionds���$���
��	��t���!�!�'�:�v�>��!�!�'�:�v�*2�
"�
4��$���6�M�D�(�3�u�:�5��<�E��K�'�$�.��7�&�@�6�I���"�#�%(��Z�0�28�9�;?�@�E�����D�O�O�4�5�	���>�:A�$��/5�D�K�K����(��+��t��!����W�!5�6�N��B��~�%� �K�K����8�1�D����D�O�O�4�T�:�>�>�z�J������D�O�O�4�T�:�>�>�y�I�� ����D�O�O�4�T�:�>�>�|�L�"�#�%�,�,�R�0�1��a����~�%��>�A�-�.�
J���M�)��(�(��*�q�(�I�
J����D�O�O�4�
+���K�K����0��6�:�:�<�H����K�K����0��6�:�:�9�E����$�$�T�*�
+����D�O�O�4�
+���K�K����0��6�:�:�:�F����K�K����0��6�:�:�<�H����$�$�T�*�
+��9�~��"�����D�O�O� <�=�	�$�:��H�6����D�O�O�,��D�K�K����0�1�3�� � ��+��	H�D��K�K����(��.�y�9�@�@��G�	Hrc���i}t|j|�dk7�r�t|j|j�dk7�r�|j|jD�]�}|j|j|}|dk(r�|jd�|k(�rN|jd�|k(�r9d}|dD]t}	|	j	�j�j
|j	�j��dk7r!|j|g�j|�|dz
}�vn�|jd�|k(r�|jd�|k(r�|jd�|k(r~d}|dD]t}	|	j	�j�j
|j	�j��dk7r!|j|g�j|�|dz
}�v~���|S)	z�Get a dictionay of the suboptions to blacklist.

        See add_suboption() for an explanation on the arguments.

        Used in both remove_option() and remove_suboption()rNrIrGrJr+rLrH)	rwr6r,r�rVrZr[rYrX)
r8rIrGr�rHr�r9�	temp_elemrj�opts
          r�_get_suboptions_to_blacklistz#Parser._get_suboptions_to_blacklist�s����	��t�{�{�7�#�$��)��4�;�;�t���/�0�A�5� �K�K����8�"�D� $���D�O�O� <�T� B�I��4�'�%�M�M�)�4��?�%�M�M�,�7�:�E�!"�B�'0��';�(��$'�I�I�K�$5�$5�$7�%)�T�&�,�,�.�*>�*>�*@�%A�R�%H�$-�$8�$8��r�$B�$I�$I�"�$M� "�a���	(�&�M�M�)�4��?�%�M�M�,�7�:�E�%�M�M�*�5��A�!"�B�'0��';�(��$'�I�I�K�$5�$5�$7�%)�T�&�,�,�.�*>�*>�*@�%A�R�%H�$-�$8�$8��r�$B�$I�$I�"�$M� "�a���	(�
"�+"�,�rc��|j||||�}|D]8}d}||D],}||z
}	|j|j|d|	=|dz
}�.�:y)z#Remove an option from a subsection.rrJrLN)r�r6r,)
r8rIrGr�rHr�r9r�r��real_poss
          rr�zParser.remove_suboption�sv���5�5�g�z�6<�h�H�	��	�D��F�!�$��
���&�=���K�K����0��6�y�A�(�K��!���
�	rc��d||fz}	|j|D]}|d|k(s�|dcS	t|��#t$rt�wxYw)z;Get the identifier of a specific section from its position.z1No identifier can be found for section "%s" No %drLr)r4r]rr)r8rIrH�	error_msgrqs     r�get_identifierzParser.get_identifier�so��I���)�*�	�	#��(�(��1�
#����7�h�&���7�N�
#�
"�)�,�,���	#�"�"�	#�s�8�8�8�Ac��|rkd|j�j�vry|j�j�j|j�j��syg}d}d}d}|jd�}	|	dkDr�|D]�}
|	dvrj|dk(re|
j	�sG|
dk(r4|dk7r)|dzdk7r!t|�dkDr|j
|�d}|d	z
}nl|dzdk7rd||
z
}n^|dzdk7rV||
z
}nP|
j	�s|
dk(r|d	z
}n5||
z
}n/|dzdk7r||
z
}n!t|�dkDr|j
|�d}|t|�d	z
k(r|dk7r|j
|�|d	z
}��nj|D]e}
|
j	�s||
z
}n!t|�dkDr|j
|�d}|t|�d	z
k(r|dk7r|j
|�|d	z
}�gt|�}|d	kD�r2|jD�cgc] }|j�j���"}
}|dk7r�|dk(r�|dk(r�|dj�j�|
vr�	d}t|d	j��}|jD]F}|dj�j�|j�j�k(s�D|}n	|j||�}|gS|	d
k7r8|dk7r3d}|D]&}|j�|j�k(s�%d}�(|dk(ry|dk(r%|dj�j�dk(ry|jD�cgc] }|j�j���"}}|	d
k(rj|dk(re|j�j�d
k(rt|�dk(r|d	=i}|D]}|j|��t|j!��S|	dkDr
|	d
kr||d	z
S|	d
kDr|d=|S|	dk(r|d=dj#|�Sy|	dvr|dk(r|Sycc}w#t$rYywxYw#t$rY��mwxYwcc}w)z�Clean the option and return the value

        This returns the last item of the list which this method generates.

        If no value can be found, return False.r�FrErrK)rQ�r"rQrLr�T�True�inputdevice� N)rVrZrWr�r�rwrXr2�intr1r�rr�r/rYr�r��join)r8r��optnamer�rIr�r�rjr�r�r��optlen�x�references_listrqr�r�rG�statusr9r/�server_dicts                      r�
_clean_optionzParser._clean_option�s�����6�<�<�>�/�/�1�1���<�<�>�'�'�)�4�4�W�]�]�_�5J�5J�5L�M������
���	��<�<��$���a�<��&
���v�%�'�^�*C��9�9�;���8�(�A�~�)�a�-�1�2D�#&�v�;��?�$+�N�N�6�$:�-/�F�%��N�I�(�1�}��1� &�!���%�q�=�A�-�"�a�K�F��9�9�;���8�%��N�I�"�a�K�F�%�q�=�A�-�"�a�K�F� #�6�{�Q�� '���v� 6�)+����V��q��(���|����v�.��a���M&
�P�
���y�y�{��a�K�F��6�{�Q�����v�.�!#����V��q��(���|����v�.��a���
� �W����A�:�
;?�/�/�J�Q�q�w�w�y���0�J�O�J��>�)��Q��6�Q�;���
� � �"�(�(�*�o�=�
��D����
� 0� 0� 2�3�E� $���"��"�1�:�+�+�-�3�3�5�����9K�9K�9M�M�#'�D�!�"�%�%)�%8�%8��u�%E�
� *�|�+��1�}��N�!:���#�&�D��z�z�|�w�}�}��6�!%��&��U�?� ���{�w�q�z�/�/�1�7�7�9�X�E��9=���G���
�
��*�*�,�G�H�G��1�}��N�!:��M�M�O�)�)�+�}�<���L�A�%���
� ��#�1�D��*�*�4�0�1��K�,�,�.�/�/��A��(�a�-��v�q�y�)�)��A���A�J����Q���A�J��x�x��(�(���6�!�g��&?�����IK��(0�%�$�%��!�����"HsC�%P7�!A-Q�Q�P<�%Q�<	Q�Q�Q�Q�	Q�Qc
�v�g}|j|j|�dk(rt�	|j||jd�y#t$�r�|dk(rtd��|j|D�]O}|j||jd�|k(s�)|j||jd�|k(s�N|j||jd�|k(s�s|j||dD]�}	|j
�j�|	j
�j�vs�@|	j
�jd�d	k7r1|	j
�d
|	j
�jd�}
n|	j
�}
|j|j|
||�������Rt|�d
k(rt�t|�dkDr|cYS	|d
cYS#t$rYYywxYwt$�r|j||D]�}|j
�j�|j
�j�vs�@|j
�jd�d	k7r1|j
�d
|j
�jd�}
n|j
�}
|j|j|
|||�
����t|�d
k(rt�t|�dkDr|cYS	|d
cYS#t$rYYywxYwt$rt�wxYw)a�Get the value which is assigned to an option.

        Return types:
          * string (if only one value is available)
            - usually in options
          * list (if more than one option is found)
            - having multiple references of the same type is allowed.
              for example it is not unusual to have 2 references to
              Screen sections in the ServerLayout section (in case of
              Xinerama)
            - if the options are actually options and not references
              then there are duplicate options, which should be detected
              in advance with get_duplicate_options()   
          * None (if no value can be found) - Not always true -> See below.

        Use-case for returning None
          * When dealing with incomplete references. For example:
                Screen "Configured Screen"
              is different from:
                Screen
                (which is an incomplete reference)
          * When dealing with incomplete options. For example:
                Depth 24
              is different from:
                Depth
                (which is an incomplete option)
          * Exception:
              Some options (with the "Option" prefix) (not references)
              can be used with no value (explicitly) assigned and are
              considered as True by the Xserver. In such case get_value()
              will return "True". For example:
                Option "AddARGBGLXVisuals" 
              is the same as:
                Option "AddARGBGLXVisuals" "True"

        Meaning of keys in Sections and SubSections:
          * When dealing with a Section:
              section= e.g. 'Screen', 'Device', etc.
              option= the option
              position= e.g. 0 (i.e. the first element in the list of Screen
                        sections)
              reference= used only by get_references()

          * When dealing with a SubSection:
              section= 'SubSection' (this is mandatory)
              option= the option
              position= e.g. 0 would mean that the subsection belongs to 
                        the 1st item of the list of, say, "Screen" sections.
                        (i.e. the first element in the list of Screen 
                        sections)
                        ["position" is a key of an item of the list of 
                        subsections see below]
              identifier= the name of the subsection e.g. 'Display'
              sect = the 'section' key of an item of the list of 
                     subsections e.g. the "Display" subsection can be 
                     found in the "Screen" section ('sect' is the latter)

        Anatomy of Sections and SubSections:
          * Anatomy of subsections:
              self.globaldict['SubSection'] =
                  {0: {'section': 'Screen', 'identifier': 'Display', 
                   'position': 0, 'options': [option1, option2, etc.], 
                   etc.}
                  In this case we refer to the 'Display' subsection 
                  which is located in the first 'Screen' section.

          * Anatomy of a section:
              self.globaldict['Screen'] =
                  {0: [option1, option2, etc.], 1: [...], ...}
              0, 1, etc. is the position N�fooz)An identifier is required for subsectionsrGrHrIrJrFr+rr�rL)r�rI)r6r�rr�r��	ExceptionrVrZr[rXr�rwrr�r�r])r8rIr�rHrGrqr��valuesr9r��stropts           rr�zParser.get_value�s��R���;�;�w��#�#�H�-��5�"�"�=
&����G�$�X�.�4�4�U�;��!� 
(���%�#�%2�3�3�!%���G� 4�P�� �K�K��0��6�:�:�<�H�&�'� �K�K��0��6�:�:�:�F�$�%� �K�K��0��6�:�:�9�E��M�'+�{�{�7�';�D�'A�)�'L�
P��$*�L�L�N�$8�$8�$:�$'�I�I�K�$5�$5�$7�%8�'*�y�y�{�'7�'7��'<��'B�14����Q��=B�U�W�T�T�#�Y�2P��25�����$*�M�M�$�2D�2D�V�28�I�3E�3O�%P�
P�
P�$�6�{�a�'�-�-��6�{�Q��%�
�(�#)�!�9�,��)�(�#'�(���
$� �K�K��0��:�M�D��|�|�~�+�+�-�����1C�1C�1E�E��:�:�<�,�,�S�1�R�7�%)�Z�Z�\�!�T�Z�Z�\�5F�5F�s�5K�%L�F�%)�Z�Z�\�F��
�
�d�&8�&8���09�7�'9�'L�M�M��v�;�!�#�)�)��v�;��?�!�M�$�%�a�y�(��%�$�#�$���
&�%�%�
&�sv�!A
�
AL8�$L8�$L8�)AL8�>B/L8�0G7�4L8�7	H�L8�H�AL8�"B-L8�L�L8�	L&�"L8�%L&�&L8c��|dk7r	|j||�y|dk7r!|j|j|�dk7Sd}t	|��#t$rYywxYw)zqSee if a section with a certain identifier exists.

        NOTE: either identifier or position must be provided.NTFz.Either identifier or position must be provided)r�rr6r�r�)r8rIrGrHr�s     rr~zParser.is_section#sq��
���
��!�!�'�:�6����
��;�;�w�'�+�+�H�5��=�=�H�I��I�&�&��
'�
��
�s�A
�
	A�Ac��d|�d|�d�}|j|D]J}	|dj�j�|j�j�k(r|dcS�Lt	|��#t$rY�cwxYw)z;Get the position of a specific section from its identifier.zNo z section named "z" can be foundrrL)r4rVrZr�r)r8rIrGr�rqs     rr�zParser.get_position4s����z�+�	��$�$�W�-�	�D�
���7�=�=�?�(�(�*�j�.>�.>�.@�.F�.F�.H�H���7�N�I�	�"�)�,�,��"�
��
�s�AA1�1	A=�<A=c�.�ij|j�}i}|jD]8}i||<i||<|j|D]}|j||�|||<��:|D]�}||D]�}|||D]�}t	||||�dkDs�||||D]l}|j
D]4}|j
�|j�j
�k(s�3|}�6|j||�r�Y||j|��n������|S)a�Look for references to sections which don't exist

        This returns a dictionary having the items of self.require_id as keys
        and a dictionary with the identifiers of the sections which are
        being referred to by the broken references.

        For example:

        broken_references = {
                            'InputDevice': {'InputDevice 1': None,
                                            'Another input device': None},
                            'Device': {...},
                            'Monitor' {...},
                            'Screen' {...},
                            'ServerLayout' {...}
                            }r)
r3r1r6r|rwr/rZrVr~rY)r8�broken_references�references_treerIrqr9�refsectr�s        rr{zParser.get_broken_referencesAsb��$�K�K����8�������	K�G�')�O�G�$�)+��g�&����G�,�
K��15�1D�1D�W�EI�2K���(��.�
K�	K�'�	K�G�'��0�
K��.�w�7��=�
K�G��?�7�3�D�9�'�B�C�a�G�#2�7�#;�D�#A�'�#J�K�C�(,�
�
�3��#'�:�:�<�7�=�=�?�3H�3H�3J�#J�.2�G�3�$(�?�?�7�C�#@�!2�'� :� E� E�c� J�K�
K�
K�	K� !� rc��g}|jd}d}|D]�}	|jdd|�}|r�d}|jdD]\}|dj�j	�|j�j	�k(s�D|j|d�|dz
}�^|dk(r
d}t
|��|dz
}��|S#t$rY�wxYw)z�Return a list with the position of default ServerLayout sections

        NOTE: If the section set as the default ServerLayout doesn't exist
              it will raise a ParseException.r#r�DefaultServerLayoutr"rLrv)r6r�r4rZrVrXrr)	r8�default�serverflagsrj�flagr��def_itrGrrs	         rr}zParser.get_default_serverlayoutos������k�k�-�0��
���	�D�
�!%���
�/D�b�"J��!��F�&*�&6�&6�~�&F�(�
�&�q�M�/�/�1�7�7�9�*�0�0�2�8�8�:�;�#�N�N�:�a�=�9�"�a�K�F�	(�
��{�!K��,�U�3�3�
�!�G�B�%	�&���#�
��
�s�A)B:�-B:�:	C�Cc���|dD]�}|d|d}|d|d}|d|jd�}|d|d}||j|g�jd|zdzdz�t|�d	kDr-|||jd
d
j	|�zdz���|||jd
j	|�dz���	|d=|S#t
$rY|SwxYw)z<Put SubSections back into the sections to which they belong.rrIrGrHrJz
	SubSection "rKrPrrOz	EndSubSection
)r�rYrXrwr�r])r8rmrqrIrGrHrJs       r�_merge_subsectionszParser._merge_subsections�sT���l�+�	I�D���-�d�3�I�>�G�"�<�0��6�|�D�J� ��.�t�4�8�8��D�H���-�d�3�I�>�G��g��)�)�(�B�7�>�>�=@�BL�=M�<?�=@�BF�=G�
H��7�|�a���'�"�8�,�3�3�D�48�I�I�g�4F�5G�4G�5H�I��'�"�8�,�3�3�D�I�I�g�4F�4G�5H�I�	I� 	��,�'�����	����	�s�C�	C'�&C'c	�L�tj|j�}|j|�}|j	|�}g}dj|j�dz}|j|�|D]q}||jk7s�t||�dkDs�%||D]E}|jd|zdzdz�|jdj|||�dz��G�s~t|d�sL|r
t|d�}nt|d	�}|jdj|��|j�y	|jttdj|�d
���y#t $r#|jdj|��YywxYw)
a�Write the changes to the destination

        The destination can be either a file (e.g. /etc/X11/xorg.conf)
        or a file object (e.g. sys.stdout).

        destination = the destination file or file object (mandatory)
        test = if set to True write will append the result to the
               destination file instead of overwriting it. It has no
               effect on file objects. Useful for testing.rErPrz	Section "rKzEndSection

rC�a�wzUTF-8rN)�copy�deepcopyr6�_merge_commented_optionsr
r�r5rXr-rwrRrSrCrUry�bytes�	TypeError)r8�destination�testrm�linesr5rIr9s        rrCzParser.write�s����M�M�$�+�+�.�	��1�1�)�<�	��+�+�I�6�	����7�7�4�=�=�)�D�0��
���X�� �	7�G��$�-�-�-��y��)�*�Q�.� )�'� 2�7�����%5��%?�#�%E��%L�M����R�W�W�Y�w�-?��-E�%F�%5�&6�7�7�	7�
��{�G�,��"�;��4��"�;��4�����b�g�g�e�n�-�����
3��!�!�#�e�B�G�G�E�N�G�&D�"E�F���
3��!�!�#�(�(�5�/�2�
3�s�3E7�7)F#�"F#c���g}|j|jD]Y}|j|j|d|k(s�&|j|j|d|k(s�I|j|��[|S)z.Get all the subsections contained in a sectionrIrH)r6r,rX)r8rIrHr�r�s     rr�zParser.get_subsections�sy�����;�;�t���/�	(�C����D�O�O�,�S�1�)�<��G��K�K����0��5�j�A�X�M��"�"�3�'�	(�
�rc�d�|D�]}|j|j|d}|j|j|d}|j|j|jd�}|j|j|d}|jj	d|zdzdz�|D]K}d|j�z}|jj	|�|jj	d	��M	|j|j|=��y
#t$rY��+wxYw)a)Put SubSections back into their sections and comment them out

        This alters globaldict and should be used only in
        comment_out_section() i.e. when the whole section is being
        commented out.

        subsections = the list of the indices subsections to merge and
        removerIrGrHrJz#	SubSection "rKrP�#		%s
�#	EndSubSection
N)r6r,r�r5rXrVr])	r8r�rqrIrGrHrJr�r�s	         r�_permanent_merge_subsectionsz#Parser._permanent_merge_subsections�s$�� �	�D��k�k�$�/�/�2�4�8��C�G����T�_�_�5�d�;�L�I�J��{�{�4�?�?�3�D�9�=�=�j�I�H��k�k�$�/�/�2�4�8��C�G��M�M� � �!7�*�!D�s�!J�!%�"&�
'�"�
;��!�V�\�\�^�4���
�
�$�$�S�)��
�
�$�$�%9�:�
;�

��K�K����0��6�	���
��
�s�D"�"	D/�.D/c�"�g}|j|jj|�rd|j|j|D]E}|j|j||jd�|k(s�5|j|��G|S)zBReturn the index of the entry in the Comments section of a sectionrH)r6r-r�rX)r8rIrHr5rqs     r�
_get_commentszParser._get_comments�s������;�;�t�*�*�+�/�/��8����D�$7�$7�8��A�
*���K�K�� 3� 3�4�W�=�d�C��S��_��1��O�O�D�)�
*�
�rc�L�d}|D�]�}|j|j|d}|j|j|d}|j|j|jd�}|j|j|d}d|z}|j||�}	|	soi|j|j|<i|j|j||<|j|j||}
d|
d<||
d<d|
d<g|
d<~
|j|j||d}|j|�|D]&}d|j
�z}
|j|
��(|j|�|j|j|=���y)	a[Put SubSections back into their sections and comment them out

        This alters globaldict and should be used only to comment out
        subsections (i.e. in comment_out_subsection()) when the whole section
        is not being commented out.

        subsections = the list of the indices subsections to merge and
                      removerrIrGrHrJz#	SubSection "%s"
Nr)r6r,r�rr-rXrV)r8r��end_subsectionrqrIrGrHrJ�start_subsectionr5rm�comments_optionsr�r�s              r� _merge_subsections_with_commentsz'Parser._merge_subsections_with_comments
s���.���	3�D��k�k�$�/�/�2�4�8��C�G����T�_�_�5�d�;�L�I�J��{�{�4�?�?�3�D�9�=�=�j�I�H��k�k�$�/�/�2�4�8��C�G�5��D���)�)�'�8�<�H��<>����D�/�/�0��9�FH����D�/�/�0��9�(�C� �K�K��(;�(;�<�W�E�h�O�	�*.�	�,�'�(0�	�*�%�'+�	�)�$�')�	�)�$��#�{�{�4�+>�+>�?�� -�-5� 7�7@� B��
�#�#�$4�5�!�
-��!�V�\�\�^�4�� �'�'��,�
-�
�#�#�N�3����D�O�O�,�T�2�=	3rc�J�|j||�}|j|�y)z-Comment out all the subsections of a section.N)r�r)r8rIrHr�s    r�_comment_out_subsectionszParser._comment_out_subsections6s$���*�*�7�H�=���)�)�+�6rc�p�|j||�}|D]}|j|j||=�!y)zBRemove comment sections of a "section" from the "Comments" sectionN)rr6r-)r8rIrHr5�comment_sections     rr�zParser._remove_comment_entries<sC���%�%�g�x�8��'�	K�O����D�/�/�0��9�/�J�	Krc�^�d|z}d}i}|r&	|j||�}|j|d�nb|dk7r&|j||��rJ|j|d�n7t	|j
|j
��}ij|�}||jvrfd}	|j|D]R}
	t	|j
��j|
d�}|	|t	|j
��|<|	dz
}	�Tt	|j
��}|j�d}
|D]�}|jj|�|j
||D]0}d|j�z}|jj|��2|j!||�|jj|�|j#||�|j
||=||}|dk7s��||
z
}|j||=|
dz
}
��y#t$rY���wxYw#t$rY��*wxYw)z.Comment out a section and all its subsections.z
#Section "%s"
z#EndSection
NrurrLz#	%s
)r�rYrr~r�r6r�r3r1r4r�r�r�r5rXrVr#r�)r8rIrGrH�
start_section�end_sectionr�r��all_keysrjr�r�r�r�rqr��commented_option�	ident_refr�s                   r�comment_out_sectionzParser.comment_out_sectionCsA��,�w�7�
�%��
�	��
��'�'���<���$�$�S�$�/�
��
����w���:��$�$�X�t�4��D�K�K��0�5�5�7�8�H����H�-�I��d�o�o�%��B�!�-�-�g�6�
�	���y�~�~�/�0�6�6�y��|�D�C�=?�I�d�9�>�>�#3�4�S�9�:��a���

��Y�^�^�-�.�
�������!�	�D��M�M� � ��/��+�+�g�.�t�4�
7��#,�����#?� ��
�
�$�$�%5�6�
7�
�)�)�'�4�8��M�M� � ��-�
�(�(��$�7����G�$�T�*�"�$��I��D� �#�f�,���$�$�W�-�g�6��!���3	��='�
��
��,"����s$�$H�7A
H�	H�H�	H,�+H,c��g}|j|jD]J}|j|j|}|d|k(r#|d|k(r|d|k(r|j|�n~�L|j|�y)z�Comment out a subsection.

        section= the type of the section which contains the subsection
        identifier= the identifier of the subsection
        position= the position of the sectionrIrGrHN)r6r,rXr!)r8rIrGrHr�r,rms       r�comment_out_subsectionzParser.comment_out_subsection�s������+�+�d�o�o�6�	�J����D�O�O�4�Z�@�I��)�$��/��,�'�:�5��*�%��1��"�"�:�.���	�	
�-�-�k�:rc��|j|||||�}|D�]b}d}||D�]T}	|	|z
}
d|j|||
j�z|j|||
<|j|jj	|i�t|j|j|�}|j|j|}|j	|i�||j	dd�||j	d|�||j	dd�||j	dg�||dj
|j|||
�~|j|||
=|dz
}��W��ey)	a]Comment out an option in a section.

        section= the section which will have the option commented out
        option= the option to comment out
        value= if you want to comment out an option only if it has a
               certain value
        position= e.g. 0 (i.e. the first element in the list of Screen
                      sections)r�#%srGNrHrIrJrL)r�r6rVr-rYrwrX)
r8rIr�r�rHr�r�r�r�rkr�rnrms
             r�comment_out_optionzParser.comment_out_option�s����2�2�7�F�E�3;�Y�H�	��	�D��F�!�$��
����-��7<����G�,�T�2�7�;�A�A�C�8E����G�$�T�*�7�3����D�/�/�0�;�;�G�R�H�����D�,?�,?� @�� I�J�	� �K�K��(;�(;�<�W�E�	��$�$�T�2�.��$��*�*�<��>��$��*�*�:�t�<��$��*�*�9�d�;��$��*�*�9�b�9��$��	�*�1�1�*.�+�+�g�*>�t�*D�W�*M�O���K�K��(��.�w�7��!���+
�	rc�J�|j||||�}|D�]�}d}||D�]{}||z
}	d|j|j|d|	j�z|j|j|d|	<|j|jj|ji�|j|j|j}
|
j|i�|
|jd|�|
|jd|�|
|jd|�|
|jdg�|
|d}|j|j|d|	}|j
|�~
|j|j|d|	=|dz
}��~���y)	apComment out an option in a subsection.

        section= the section which contains the subsection
        identifier= the identifier of the subsection
        option= the option to comment out
        position= the position of the section which contains the subsection
                  e.g. 0 (i.e. the first element in the list of Screen
                  sections)rr0rJrGrHrIrLN)r�r6r,rVr-rYrX)
r8rIrGr�rHr�r9r�r�r�rmr r*s
             r�comment_out_suboptionzParser.comment_out_suboption�s����5�5�g�z�6<�h�H�	��	�D��F�!�$��
����-��JO��{�{�4�?�?�3�D�9�)�D�W�M��U�W�K����D�O�O�,�T�2�9�=�g�F����D�/�/�0�;�;�D�O�O�<>�@� �K�K��(;�(;�<�T�_�_�M�	��$�$�T�2�.��$��*�*�<��D��$��*�*�:�t�<��$��*�*�9�g�>��$��*�*�9�b�9�#,�T�?�9�#=� �#'�;�;�t���#?��#E�.7�$9�9@�$B� � �'�'�(8�9���K�K����0��6�y�A�'�J��!���5
�	rc���||jD�]]}d}||j|D]�}||j||jd�}||j||jd�}||j||jd�}||j||d}||jk(r:||D]1}	|||	}
|
d|k(s�|
d|k(s�|
d|k(s�&|||	d}����||j|�}��|s��D]W}d|j�z}||jk(r"|j	dg�j|��G|j|��Y��`|S)zAPut commented out options back into their sections or subsectionsNrIrGrHrJz	%s
)r-r�r,rVrYrX)r8rmrq�section_options�section_instancerIrGrHrJr�r,r�s            rrzParser._merge_commented_options�s����d�1�1�2�	7�D�"�O�$-�d�.A�.A�$B�4�$H�
D� �#�D�$7�$7�8��>�$4�6�69�c�)�n��&�t�':�':�;�D�A�'7�9�9<��\�9J��$�T�%8�%8�9�$�?�%5�7�7:�s�:���#�D�$7�$7�8��>�$4�6�6?�A���d�o�o�-�(���"��%.�t�_�S�%9�
�&�|�4�
�B�&�z�2�h�>�&�y�1�W�<�.7��o�c�.B�9�.M�O�!�
"�'0��o�&9�&9�(�&C�O�%
D�(�%�7�F�%�����8�F��t���.�'�2�2�9�35�7�7=�v�f�~�'�.�.�v�6�
7�/	7�>�rr<)NNNrK)NNN)NN)2r
rrr
r:r>rA�property�
globaldictr7r_r^rzr�r�r�rxr�r�r�r�r�r�r�r|r�r�r�r�r�r�r�r�r~r�r{r}r
rCr�rrr!r#r�r,r.r1r3rrrrrr*sP��@�N�`�"��+�{�3�J�T%�ll,�\-�^"8�H-�^�C�J�">B�9<�F9�P@D�;?�,�\CG�#��&7�r@�F;�$>�$1�f6�p3�B26�NH�d/3� �F
�-�\�|?C�'+�Q&�f'�"-�+!�\�>�8*3�X
��8
�*3�X7�K�E�P;�(HL�%)�$�N(�V"rr)�
__future__rr�sysrrrr�rrrr�objectrrrr�<module>r<sT��(&�'�
���	�)�	�	�i�	�	�y�	�	�Y�	�i�V�ir

Zerion Mini Shell 1.0