%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Cf�c#:����dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZmZmZmZ	ddlmZeeeefZej:d	�Zej>d
�Z Gd�d�Z!ejDd
k\ser Gd�dejFeeeefe�Z$nGd�dejJeee�Z$Gd�de$d�Z&y#e$rY��wxYw)a Facilities for reading and writing Debian substvars files

The aim of this module is to provide programmatic access to Debian substvars
files to query and manipulate them. The format for the changelog is defined in
`deb-substvars(5)
<https://manpages.debian.org/stretch/dpkg-dev/deb-substvars.5.html>`_

Overview
========

The most common use-case for substvars is for package helpers to add or update
a substvars (e.g., to add a dependency).  This would look something like:

    >>> from debian.substvars import Substvars
    >>> from tempfile import TemporaryDirectory
    >>> import os
    >>> # Using a tmp dir for the sake of doctests
    >>> with TemporaryDirectory() as debian_dir:
    ...    filename = os.path.join(debian_dir, "foo.substvars")
    ...    with Substvars.load_from_path(filename, missing_ok=True) as svars:
    ...        svars.add_dependency("misc:Depends", "bar (>= 1.0)")

By default, the module creates new substvars as "mandatory" substvars (that
triggers a warning by dpkg-gecontrol if not used.  However, it does also
support the "optional" substvars introduced in dpkg 1.21.8.  See
`Substvars.as_substvars` for an example of how to use the "optional"
substvars.


The :class:`Substvars` class is the key class within this module.

Substvars Classes
-----------------
�N)�ABC)�OrderedDict)�MutableMapping)�
TracebackType)	�Dict�Set�Optional�Union�Iterator�IO�Iterable�
TYPE_CHECKING�Type)�PathLike�TzB^(?P<name>\w[-:\dA-Za-z]*)(?P<assignment_type>[?]?=)(?P<value>.*)$c�f�eZdZddgZ		d
d�Zed��Zejd��Zd�Zd�Z	d�Z
y	)�Substvar�_assignment_operator�_valuec� �||_||_y�N)r�assignment_operator)�self�
initial_valuers   �2/usr/lib/python3/dist-packages/debian/substvars.py�__init__zSubstvar.__init__As��$���#6�� �c��|jSr)r�rs rrzSubstvar.assignment_operatorRs���(�(�(rc�6�|dvrtd|z��||_y)N>�?=�=z-Operator must be one of: "=", or "?=" - got: )�
ValueErrorr)r�new_operators  rrzSubstvar.assignment_operatorWs%���{�*��L�|�[�\�\�$0��!rc� �|jdk(r	|h|_yt|jt�r<|jjd�D�chc]}|j	���c}|_|jj|�ycc}w)N��,)r�
isinstance�str�split�strip�add)r�dependency_clause�vs   r�add_dependencyzSubstvar.add_dependency^sg���;�;�"��,�-�D�K���d�k�k�3�'�.2�k�k�.?�.?��.D�E��1�7�7�9�E�D�K������)�*��Fs�Bc��t|jt�r$djt	|j��S|jS)Nz, )r(r�set�join�sortedrs r�resolvezSubstvar.resolvehs2���d�k�k�3�'��9�9�V�D�K�K�0�1�1��{�{�rc��|�t|t�sy|j|jk7ry|j�|j�k(S�NF)r(rrr4�r�others  r�__eq__zSubstvar.__eq__nsA���=�
�5�(� ;���#�#�u�'@�'@�@���|�|�~�����0�0rN)r&r")�__name__�
__module__�__qualname__�	__slots__r�propertyr�setterr/r4r9�rrrr=sT��'��2�I�%'�%(�7�"�)��)����1� �1�+��1rr)��	c��eZdZy)�_Substvars_BaseN)r:r;r<r@rrrDrDxs��rrDc��eZdZd�Zd�Zy)rDc��|Srr@rs r�	__enter__z_Substvars_Base.__enter__�s���Krc��yrr@)r�exc_type�exc_val�exc_tbs    r�__exit__z_Substvars_Base.__exit__�s��rN)r:r;r<rGrLr@rrrDrDs��	�	rc���eZdZdZddgZd�Zedd��Zed��Z	e	jd��Z	ed��Zejd	��Zd
�Z�fd�Z
d�Zd
efd�Zd�Zd�Zd�Zd�Zed��Zd�Zd�Zd�Zd�Zd�Z�xZS)�	Substvarsa�Substvars is a dict-like object containing known substvars for a given package.

    >>> substvars = Substvars()
    >>> substvars['foo'] = 'bar, golf'
    >>> substvars['foo']
    'bar, golf'
    >>> substvars.add_dependency('foo', 'dpkg (>= 1.20.0)')
    >>> substvars['foo']
    'bar, dpkg (>= 1.20.0), golf'
    >>> 'foo' in substvars
    True
    >>> sorted(substvars)
    ['foo']
    >>> del substvars['foo']
    >>> substvars['foo']
    Traceback (most recent call last):
        ...
    KeyError: 'foo'
    >>> substvars.get('foo')
    >>> # None
    >>> substvars['foo'] = ""
    >>> substvars['foo']
    ''

    The Substvars object also provide methods for serializing and deserializing
    the substvars into and from the format used by dpkg-gencontrol.

    The Substvars object can be used as a context manager, which causes the substvars
    to be saved when the context manager exits successfully (i.e., no exceptions are raised).
    �
_vars_dict�_substvars_pathc�0�t�|_d|_yr)rrOrPrs rrzSubstvars.__init__�s��%�-���#��rc��|�}	t|dd��5}|j|�ddd�||_|S#1swY�xYw#t$r*}|jtjk7s|s�Yd}~�Cd}~wwxYw)aShorthand for initializing a Substvars from a file

        The return substvars will have `substvars_path` set to the provided path enabling
        `save()` to work out of the box. This also makes it easy to combine this with the
        context manager interface to automatically save the file again.

        >>> import os
        >>> from tempfile import TemporaryDirectory
        >>> with TemporaryDirectory() as tmpdir:
        ...    filename = os.path.join(tmpdir, "foo.substvars")
        ...    # Obviously, this does not exist
        ...    print("Exists before: " + str(os.path.exists(filename)))
        ...    with Substvars.load_from_path(filename, missing_ok=True) as svars:
        ...        svars.add_dependency("misc:Depends", "bar (>= 1.0)")
        ...    print("Exists after: " + str(os.path.exists(filename)))
        Exists before: False
        Exists after: True

        :param substvars_path: The path to load from
        :param missing_ok: If True, then the path does not have to exist (i.e.
          FileNotFoundError causes an empty Substvars object to be returned).  Combined
          with the context manager, this is useful for packaging helpers that want to
          append / update to the existing if it exists or create it if it does not exist.
        �r�utf-8��encodingN)�open�read_substvars�OSError�errno�ENOENT�substvars_path)�clsr\�
missing_ok�	substvars�fd�es      r�load_from_pathzSubstvars.load_from_path�sz��6�E�	�	��n�c�G�<�
-���(�(��,�
-�
$2�	� ���

-�
-���	��w�w�%�,�,�&�j��/9��	�s*�A�:�A�A�A�	A9� A4�4A9c��|jSr�rOrs r�_varszSubstvars._vars�s�����rc��||_yrrd)r�	vars_dicts  rrezSubstvars._vars�s��$��rc��|jSr�rPrs rr\zSubstvars.substvars_path�s���#�#�#rc��||_yrri)r�new_paths  rr\zSubstvars.substvars_path�s�� (��rc��	|j|}|j|�y#t$rt�}||j|<Y�6wxYw)a�Add a dependency clause to a given substvar

        >>> substvars = Substvars()
        >>> # add_dependency automatically creates variables
        >>> 'misc:Recommends' not in substvars
        True
        >>> substvars.add_dependency('misc:Recommends', "foo (>= 1.0)")
        >>> substvars['misc:Recommends']
        'foo (>= 1.0)'
        >>> # It can be appended to other variables
        >>> substvars['foo'] = 'bar, golf'
        >>> substvars.add_dependency('foo', 'dpkg (>= 1.20.0)')
        >>> substvars['foo']
        'bar, dpkg (>= 1.20.0), golf'
        >>> # Exact duplicates are ignored
        >>> substvars.add_dependency('foo', 'dpkg (>= 1.20.0)')
        >>> substvars['foo']
        'bar, dpkg (>= 1.20.0), golf'

        N)re�KeyErrorrr/)r�substvarr-�variables    rr/zSubstvars.add_dependency�sL��,	,��z�z�(�+�H�	��� 1�2���	,��z�H�#+�D�J�J�x� �	,�s�#�"A�Ac�J��|�|j�t�|�	|||�Sr)�save�superrL)rrIrJrK�	__class__s    �rrLzSubstvars.__exit__s(������I�I�K��w���'�6�:�:rc�,�t|j�Sr)�iterrers r�__iter__zSubstvars.__iter__s���D�J�J��r�returnc�,�t|j�Sr)�lenrOrs r�__len__zSubstvars.__len__s���4�?�?�#�#rc��||jvSr�re)r�items  r�__contains__zSubstvars.__contains__s���t�z�z�!�!rc�<�|j|j�Sr)rer4�r�keys  r�__getitem__zSubstvars.__getitem__s���z�z�#��&�&�(�(rc��|j|=yrr|r�s  r�__delitem__zSubstvars.__delitem__ s
���J�J�s�Orc�4�t|�|j|<yr)rre)rr��values   r�__setitem__zSubstvars.__setitem__$s��"�5�/��
�
�3�rc��|jS)a�Provides a mapping to the Substvars object for more advanced operations

        Treating a substvars file mostly as a "str -> str" mapping is sufficient for many cases.
        But when full control over the substvars (like fiddling with the assignment operator) is
        needed this attribute is useful.

        >>> content = '''
        ... # Some comment (which is allowed but no one uses them - also, they are not preserved)
        ... shlib:Depends=foo (>= 1.0), libbar2 (>= 2.1-3~)
        ... random:substvar?=With the new assignment operator from dpkg 1.21.8
        ... '''
        >>> substvars = Substvars()
        >>> substvars.read_substvars(content.splitlines())
        >>> substvars.as_substvar["shlib:Depends"].assignment_operator
        '='
        >>> substvars.as_substvar["random:substvar"].assignment_operator
        '?='
        >>> # Mutation is also possible
        >>> substvars.as_substvar["shlib:Depends"].assignment_operator = '?='
        >>> print(substvars.dump(), end="")
        shlib:Depends?=foo (>= 1.0), libbar2 (>= 2.1-3~)
        random:substvar?=With the new assignment operator from dpkg 1.21.8
        r|rs r�as_substvarzSubstvars.as_substvar(s��6�z�z�rc�Z�|�t|t�sy|j|jk(Sr6)r(rNrer7s  rr9zSubstvars.__eq__Es&���=�
�5�)� <���z�z�U�[�[�(�(rc�b�djd�|jj�D��S)z�Debug aid that generates a string representation of the content

        For persisting the contents, please consider `save()` or `write_substvars`.
        r&c3�xK�|]2\}}dj||j|j�����4y�w�z{}{}{}
N��formatrr4��.0�kr.s   r�	<genexpr>z!Substvars.dump.<locals>.<genexpr>Qs7������1�a�"�(�(��A�,A�,A�1�9�9�;�O����8:)r2re�itemsrs r�dumpzSubstvars.dumpKs/���w�w��#'�:�:�#3�#3�#5���	rc��|j�td��t|jdd��5}|j|�cddd�S#1swYyxYw)z�Save the substvars file

        Replace the path denoted by the `substvars_path` attribute with the
        in-memory version of the substvars.  Note that the `substvars_path`
        property must be not None for this method to work.
        NzcThe substvar does not have a substvars_path: Please set substvars_path first or use write_substvars�wrTrU)rP�	TypeErrorrW�write_substvars)rr`s  rrqzSubstvars.saveUs^�����'��O�P�
P��$�&�&��g�
>�	,�"��'�'��+�	,�	,�	,�s�A�Ac�d�|jd�|jj�D��y)z�Write a copy of the substvars to an open text file

        :param fileobj: The open file (should open in text mode using the UTF-8 encoding)
        c3�xK�|]2\}}dj||j|j�����4y�wr�r�r�s   rr�z,Substvars.write_substvars.<locals>.<genexpr>js7�����#�q�!�&�,�,�Q��0E�0E�q�y�y�{�S��r�N)�
writelinesrer�)r�fileobjs  rr�zSubstvars.write_substvarsds,��	����'+�z�z�'7�'7�'9��	rc��t�}|D]i}|j�dk(s|ddk(r�tj|j	d��}|s�F|j�\}}}t
||��||<�k||_y)a Read substvars from an open text file in the format supported by dpkg-gencontrol

        On success, all existing variables will be discarded and only variables
        from the file will be present after this method completes.  In case of
        any IO related errors, the object retains its state prior to the call
        of this method.

        >>> content = '''
        ... # Some comment (which is allowed but no one uses them - also, they are not preserved)
        ... shlib:Depends=foo (>= 1.0), libbar2 (>= 2.1-3~)
        ... random:substvar?=With the new assignment operator from dpkg 1.21.8
        ... '''
        >>> substvars = Substvars()
        >>> substvars.read_substvars(content.splitlines())
        >>> substvars["shlib:Depends"]
        'foo (>= 1.0), libbar2 (>= 2.1-3~)'
        >>> substvars["random:substvar"]
        'With the new assignment operator from dpkg 1.21.8'

        :param fileobj: An open file (in text mode using the UTF-8 encoding) or an
          iterable of str that provides line by line content.
        r&r�#z
)rN)rr+�_SUBSTVAR_PATTERN�match�rstrip�groupsrre)rr�rg�line�m�varnamerr�s        rrXzSubstvars.read_substvarsns���0 �M�	��	Z�D��z�z�|�r�!�T�!�W��^��!�'�'����F�(;�<�A���23�(�(�*�/�G�(�%�!)�%�EX�!Y�I�g��	Z���
r)F)r:r;r<�__doc__r=r�classmethodrbr>rer?r\r/rLrv�intrzr~r�r�r�r�r9r�rqr�rX�
__classcell__)rss@rrNrN�s�����>�0�1�I�$�
�"��"�H����
�\�\�$��$�
�$��$����(��(�3�:;� �$��$�"�)��*�����8)��
,��!rrN)'r��
contextlibrZ�re�sys�typing�abcr�collectionsr�collections.abcr�typesrrrr	r
rrr
rr�osrr)�bytes�AnyPath�ImportError�TypeVarr�compiler�r�version_info�AbstractContextManagerrD�GenericrNr@rr�<module>r�s���!�H��	�
�
��#�*��Z�Z�Z�	���H�c�5�(�)�G��F�N�N�3����B�J�J�I���
71�71�t���v���
�*�;�;�A�>��s�TW�x�@X�Z]�
��&�.�.��+�^�S��G���,�G��k�	��	�s�C�C$�#C$

Zerion Mini Shell 1.0