Ë
    ðì�iA  ã                   ó   — d Z  G d„ de«      Zy)zP
PassportEye::Util: Pipeline utility

Author: Konstantin Tretyakov
License: MIT
c                   óD   — e Zd ZdZd„ Zdd„Zd„ Zdd„Zd„ Zd„ Z	d	„ Z
d
„ Zy)ÚPipelinea  
    The computation performed in order to extract the information from an image
    is essentially a list of steps of various complexity, where each step uses
    results of the previous steps and introduces its own results.

    Although this is nothing more than a standard sequential program, it seems to be somewhat
    more convenient sometimes to regard it as a "pipeline" consisting of pluggable "components",
    where each component explicitly specifies what inputs it needs and what outputs it produces,
    and the workflow engine wires up the inputs to the outputs.

    This class offers provides a simple implementation of such a pipeline.
    It keeps track of a dictionary of values that were already computed, a dictionary of
    "components" which know how to compute other values, and routes item accesses to computations automatically.

    >>> a = Pipeline()
    >>> a.add_component('1', lambda: 1, ['a'], [])
    >>> a.add_component('2', lambda: 2, ['b'], [])
    >>> a.add_component('s,d', lambda x,y: (x+y, x-y), ['c', 'd'], ['a', 'b'])
    >>> a.add_component('sd', lambda x,y: (x+y, x-y), ['e'], ['a', 'b'])
    >>> a['c']
    3
    >>> a['d']
    -1
    >>> a['e']
    (3, -1)
    >>> a.replace_component('1', lambda: 2, ['a'], [])
    >>> a['e']
    (4, 0)
    >>> a['d']
    0
    c                 óê   — t        «       | _        t        «       | _        t        «       | _        t        «       | _        t        «       | _        | j                  | j                  d<   | | j                  d<   y )NÚ__data__Ú__pipeline__)ÚdictÚdataÚ
componentsÚprovidesÚdependsÚwhoprovides)Úselfs    ú~/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/passporteye/util/pipeline.pyÚ__init__zPipeline.__init__*   sP   € Ü“FˆŒ	Ü›&ˆŒÜ›ˆŒÜ“vˆŒÜ›6ˆÔØ $§	¡	ˆ�	‰	�*ÑØ$(ˆ�	‰	�.Ò!ó    Nc                 ó  — |xs t        |dg «      }|xs t        |dg «      }|D ]  }|| j                  v sŒt        d|z  «      ‚ || j                  |<   || j                  |<   || j
                  |<   |D ]  }|| j                  |<   Œ y)a'  
        Add a given callable to a list of components. The provides and depends are lists of strings, specifying what
        keys the component computes and what keys it requires to be present. If those are not given, the callable must
        have fields __provides__ and __depends__.
        Ú__provides__Ú__depends__z-There is already a component that provides %sN)Úgetattrr   Ú	Exceptionr
   r   r	   )r   ÚnameÚcallabler
   r   Úps         r   Úadd_componentzPipeline.add_component3   s¦   € ð ÒDœw x°ÀÓDˆØÒAœW X¨}¸bÓAˆØò 	UˆAØ�D×$Ñ$Ò$ÜÐ OÐRSÑ SÓTÐTð	Uð 'ˆ�‰�dÑØ$ˆ�‰�TÑØ (ˆ�‰˜ÑØò 	'ˆAØ"&ˆD×Ñ˜QÒñ	'r   c                 óî   — || j                   vrt        d|z  «      ‚| j                   |= | j                  |= | j                  |   D ]   }| j                  |= | j                  |«       Œ" | j                  |= y)zxRemoves an existing component with a given name, invalidating all the values computed by
        the previous component.zNo component named %sN)r	   r   r   r
   r   Ú
invalidate)r   r   r   s      r   Úremove_componentzPipeline.remove_componentD   sy   € ð �t—‘Ñ&ÜÐ3°dÑ:Ó;Ð;Ø�O‰O˜DÐ!Ø�L‰L˜ÐØ—‘˜tÑ$ò 	ˆAØ× Ñ  Ð#Ø�O‰O˜AÕð	ð �M‰M˜$Ñr   c                 óN   — | j                  |«       | j                  ||||«       y)z‹Changes an existing component with a given name, invalidating all the values computed by
        the previous component and its successors.N)r   r   )r   r   r   r
   r   s        r   Úreplace_componentzPipeline.replace_componentP   s&   € ð 	×Ñ˜dÔ#Ø×Ñ˜4 ¨8°WÕ=r   c                 óÌ   — || j                   vry| j                   |= | j                  D ]9  }|| j                  |   v sŒ| j                  |   D ]  }| j	                  |«       Œ Œ; y)zORemove the given data item along with all items that depend on it in the graph.N)r   r	   r   r
   r   )r   ÚkeyÚcnameÚdownstream_keys       r   r   zPipeline.invalidateV   sf   € à�d—i‘iÑØØ�I‰I�cˆNð —_‘_ò 	4ˆEØ�d—l‘l 5Ñ)Ò)Ø&*§m¡m°EÑ&:ò 4�NØ—O‘O NÕ3ñ4ñ	4r   c                 ó"   — || j                   |<   y ©N)r   )r   r    Úvalues      r   Ú__setitem__zPipeline.__setitem__b   s   € Øˆ�	‰	�#Šr   c                 óB   — | j                  |«       | j                  |   S r$   )Ú_computer   )r   r    s     r   Ú__getitem__zPipeline.__getitem__e   s   € Ø�‰�cÔØ�y‰y˜‰~Ðr   c                 óà  — || j                   vrÛ| j                  |   }| j                  |   D ]  }| j                  |«       Œ | j                  |   D �cg c]  }| j                   |   ‘Œ }} | j                  |   |Ž }t        | j                  |   «      dk(  r || j                   | j                  |   d   <   y t        | j                  |   |«      D ]  \  }}|| j                   |<   Œ y y c c}w )Né   é    )r   r   r   r(   r	   Úlenr
   Úzip)r   r    r!   ÚdÚinputsÚresultsÚkÚvs           r   r(   zPipeline._computei   sè   € Ø�d—i‘iÑØ×$Ñ$ SÑ)ˆEØ—\‘\ %Ñ(ò !�Ø—‘˜aÕ ð!à,0¯L©L¸Ñ,?Ö@ q�d—i‘i “lÐ@ˆFÐ@Ø,�d—o‘o eÑ,¨fÐ5ˆGÜ�4—=‘= Ñ'Ó(¨AÒ-Ø5<�—	‘	˜$Ÿ-™-¨Ñ.¨qÑ1Ò2ä §¡¨eÑ 4°gÓ>ò %‘D�A�qØ#$�D—I‘I˜a’Lñ%ð  ùò As   ÁC+)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r&   r)   r(   © r   r   r   r   	   s0   „ ñò@)ó'ò"
 ó>ò
4òòó%r   r   N)r7   Úobjectr   r8   r   r   ú<module>r:      s   ðñôk%ˆvõ k%r   