HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/self/root/usr/lib/python3/dist-packages/debian/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3/dist-packages/debian/__pycache__/substvars.cpython-311.pyc
�

)uyc#:����dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZmZmZmZ	ddlmZeeeefZn#e$rYnwxYwejd	��Zejd
��Z Gd�d��Z!ej"d
kser$Gd�dej#eeeefe��Z$nGd�dej%eee��Z$Gd�de$d��Z&dS)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�j�eZdZddgZ		dd�Zed���Zejd���Zd�Zd	�Z	d
�Z
dS)
�Substvar�_assignment_operator�_value��=c�"�||_||_dS�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�@�|dvrtd|z���||_dS)N>�?=rz-Operator must be one of: "=", or "?=" - got: )�
ValueErrorr)r�new_operators  rrzSubstvar.assignment_operatorWs1���{�*�*��L�|�[�\�\�\�$0��!�!�!rc���|jdkr
|h|_dSt|jt��r)d�|j�d��D��|_|j�|��dS)Nrc�6�h|]}|�����S�)�strip)�.0�vs  r�	<setcomp>z*Substvar.add_dependency.<locals>.<setcomp>es ��E�E�E��1�7�7�9�9�E�E�Er�,)r�
isinstance�str�split�add)r�dependency_clauses  r�add_dependencyzSubstvar.add_dependency^ss���;�"���,�-�D�K��F��d�k�3�'�'�	F�E�E�d�k�.?�.?��.D�.D�E�E�E�D�K�����)�*�*�*�*�*rc��t|jt��r'd�t	|j����S|jS)Nz, )r.r�set�join�sortedr!s r�resolvezSubstvar.resolvehs:���d�k�3�'�'�	2��9�9�V�D�K�0�0�1�1�1��{�rc��|�t|t��sdS|j|jkrdS|���|���kS�NF)r.rrr8�r�others  r�__eq__zSubstvar.__eq__nsK���=�
�5�(� ;� ;�=��5��#�u�'@�@�@��5��|�|�~�~������0�0rN)rr)�__name__�
__module__�__qualname__�	__slots__r�propertyr�setterr3r8r=r(rrrr=s�������'��2�I�%'�%(�7�7�7�7�"�)�)��X�)���1�1� ��1�+�+�+����1�1�1�1�1rr)��	c��eZdZdS)�_Substvars_BaseN)r>r?r@r(rrrGrGxs�������rrGc��eZdZd�Zd�ZdS)rGc��|Srr(r!s r�	__enter__z_Substvars_Base.__enter__�s���Krc��dSrr()r�exc_type�exc_val�exc_tbs    r�__exit__z_Substvars_Base.__exit__�s���4rN)r>r?r@rJrOr(rrrGrGs2������	�	�	�	�	�	�	�	rc���eZdZdZddgZd�Zedd���Zed���Z	e	j
d���Z	ed	���Zej
d
���Zd�Z�fd�Z
d
�Zdefd�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�:�t��|_d|_dSr)rrRrSr!s rrzSubstvars.__init__�s��%�-�-���#����rFc��|��}	t|dd���5}|�|��ddd��n#1swxYwYn/#t$r"}|jtjks|s�Yd}~nd}~wwxYw||_|S)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�s���6�C�E�E�	�	��n�c�G�<�<�<�
-���(�(��,�,�,�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-����	�	�	��w�%�,�&�&�j�&��'�&�&�&�&�����	����$2�	� ��s9�A�A�A�A�A�A�A�
A8�A3�3A8c��|jSr�rRr!s r�_varszSubstvars._vars�s����rc��||_dSrrg)r�	vars_dicts  rrhzSubstvars._vars�s��$����rc��|jSr�rSr!s rr_zSubstvars.substvars_path�s
���#�#rc��||_dSrrl)r�new_paths  rr_zSubstvars.substvars_path�s�� (����rc��	|j|}n(#t$rt��}||j|<YnwxYw|�|��dS)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)rh�KeyErrorrr3)r�substvarr2�variables    rr3zSubstvars.add_dependency�sh��,	,��z�(�+�H�H���	,�	,�	,��z�z�H�#+�D�J�x� � � �	,����	��� 1�2�2�2�2�2s�
�"5�5c�v��|�|���t���|||��Sr)�save�superrO)rrLrMrN�	__class__s    �rrOzSubstvars.__exit__s4������I�I�K�K�K��w�w����'�6�:�:�:rc�*�t|j��Sr)�iterrhr!s r�__iter__zSubstvars.__iter__s���D�J���r�returnc�*�t|j��Sr)�lenrRr!s r�__len__zSubstvars.__len__s���4�?�#�#�#rc��||jvSr�rh)r�items  r�__contains__zSubstvars.__contains__s���t�z�!�!rc�@�|j|���Sr)rhr8�r�keys  r�__getitem__zSubstvars.__getitem__s���z�#��&�&�(�(�(rc��|j|=dSrrr�s  r�__delitem__zSubstvars.__delitem__ s���J�s�O�O�Orc�4�t|��|j|<dSr)rrh)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
        rr!s r�as_substvarzSubstvars.as_substvar(s��6�z�rc�T�|�t|t��sdS|j|jkSr:)r.rQrhr;s  rr=zSubstvars.__eq__Es)���=�
�5�)� <� <�=��5��z�U�[�(�(rc�n�d�d�|j���D����S)z�Debug aid that generates a string representation of the content

        For persisting the contents, please consider `save()` or `write_substvars`.
        rc3�xK�|]5\}}d�||j|�����V��6dS�z{}{}{}
N��formatrr8�r*�kr+s   r�	<genexpr>z!Substvars.dump.<locals>.<genexpr>QsW�������1�a�"�(�(��A�,A�1�9�9�;�;�O�O������r)r6rh�itemsr!s r�dumpzSubstvars.dumpKsD���w�w���#'�:�#3�#3�#5�#5������	rc��|j�td���t|jdd���5}|�|��cddd��S#1swxYwYdS)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�wrWrX)rS�	TypeErrorrZ�write_substvars)rrcs  rrtzSubstvars.saveUs�����'��O�P�P�
P��$�&��g�
>�
>�
>�	,�"��'�'��+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	,�	,s�A�A�Ac�r�|�d�|j���D����dS)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�|]5\}}d�||j|�����V��6dSr�r�r�s   rr�z,Substvars.write_substvars.<locals>.<genexpr>jsW������#�q�!�&�,�,�Q��0E�q�y�y�{�{�S�S������rN)�
writelinesrhr�)r�fileobjs  rr�zSubstvars.write_substvarsdsP��	�����'+�z�'7�'7�'9�'9����	�	�	�	�	rc�<�t��}|D]�}|���dks|ddkr�'t�|�d����}|s�W|���\}}}t
||���||<��||_dS)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.
        rr�#z
)rN)rr)�_SUBSTVAR_PATTERN�match�rstrip�groupsrrh)rr�rj�line�m�varnamerr�s        rr[zSubstvars.read_substvarsns���0 �M�M�	��	Z�	Z�D��z�z�|�|�r�!�!�T�!�W��^�^��!�'�'����F�(;�(;�<�<�A��
��23�(�(�*�*�/�G�(�%�!)�%�EX�!Y�!Y�!Y�I�g�����
�
�
r)F)r>r?r@�__doc__rAr�classmethodrerBrhrCr_r3rOry�intr}r�r�r�r�r�r=r�rtr�r[�
__classcell__)rvs@rrQrQ�s����������>�0�1�I�$�$�$�
�"�"�"��[�"�H����X��
�\�$�$��\�$�
�$�$��X�$���(�(���(�3�3�3�:;�;�;�;�;� � � �$��$�$�$�$�"�"�"�)�)�)����*�*�*�����X��8)�)�)����
,�
,�
,����!�!�!�!�!�!�!rrQ)'r��
contextlibr]�re�sys�typing�abcr�collectionsr�collections.abcr�typesrrrr	r
rrr
rr�osrr/�bytes�AnyPath�ImportError�TypeVarr�compiler�r�version_info�AbstractContextManagerrG�GenericrQr(rr�<module>r�s<��!�!�H��������	�	�	�	�
�
�
�
�
�
�
�
�������#�#�#�#�#�#�*�*�*�*�*�*�������Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�Z�	��������H�c�5�(�)�G�G���	�	�	��D�	�����F�N�3�����B�J�I����
71�71�71�71�71�71�71�71�t��v�����
�
�
�
�
�*�;�A�>��s�TW�x�@X�Z]�
�
�
�
������&�.��+�^�S����G�G�G�G�G���,�G�G�G�G�Gs�A�A �A