
    g                     &    d gZ  G d d e      Zd Zy)Originc                   R    e Zd ZdZd Zed        Zd Zd Zd Z	d Z
ddZd	 Zd
 Zy)r   aG  This represents the origin of some object in some string.

    For example, if we have an object ``x1_obj`` that was produced by parsing
    the ``x1`` in the formula ``"y ~ x1:x2"``, then we conventionally keep
    track of that relationship by doing::

      x1_obj.origin = Origin("y ~ x1:x2", 4, 6)

    Then later if we run into a problem, we can do::

      raise PatsyError("invalid factor", x1_obj)

    and we'll produce a nice error message like::

      PatsyError: invalid factor
          y ~ x1:x2
              ^^

    Origins are compared by value, and hashable.
    c                 .    || _         || _        || _        y Ncodestartend)selfr   r   r	   s       I/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/patsy/origin.py__init__zOrigin.__init__$   s    	
    c                    g }|D ]4  }|t        |t              s|j                  }|$|j                  |       6 |syt	        |D cg c]  }|j
                   c}      }t        |      dk(  sJ t        |D cg c]  }|j                   c}      }t        |D cg c]  }|j                   c}      } | |j                         ||      S c c}w c c}w c c}w )a  Class method for combining a set of Origins into one large Origin
        that spans them.

        Example usage: if we wanted to represent the origin of the "x1:x2"
        term, we could do ``Origin.combine([x1_obj, x2_obj])``.

        Single argument is an iterable, and each element in the iterable
        should be either:

        * An Origin object
        * ``None``
        * An object that has a ``.origin`` attribute which fulfills the above
          criteria.

        Returns either an Origin object, or None.
        N   )
isinstancer   originappendsetr   lenminr   maxr	   pop)clsorigin_objsoriginsobjocodesr   r	   s           r   combinezOrigin.combine)   s    $  	 Cz#v'>jj{NN3	  W-QVV-.5zQg.QWW./'*Q155*+599;s++	 ..*s   C;CCc                 H    | j                   | j                  | j                   S )zgExtracts and returns the span of the original code represented by
        this Origin. Example: ``x1``.r   r
   s    r   relevant_codezOrigin.relevant_codeJ   s     yydhh//r   c                     t        |t              xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r   )r   r   r   r   r	   r
   others     r   __eq__zOrigin.__eq__O   sR    uf% &		UZZ'&

ekk)& EII%		
r   c                     | |k(   S r    r#   s     r   __ne__zOrigin.__ne__W   s    5=  r   c                 d    t        t        | j                  | j                  | j                  f      S r   )hashr   r   r   r	   r    s    r   __hash__zOrigin.__hash__Z   s"    VTYY

DHH=>>r   c                     d|z  | j                   dd|z  d| j                  z  d| j                  | j                  z
  z  S )a3  Produces a user-readable two line string indicating the origin of
        some code. Example::

          y ~ x1:x2
              ^^

        If optional argument 'indent' is given, then both lines will be
        indented by this much. The returned string does not have a trailing
        newline.
         
^r   )r
   indents     r   caretizezOrigin.caretize]   sD     &LII&L$**488djj()
 	
r   c                     d| j                   d | j                   d| j                   | j                  | j                   d| j                   | j                  d  d| j                  d| j                  dS )Nz<Origin z->z<-z (-z)>r   r    s    r   __repr__zOrigin.__repr__p   sT    IIl

#IIdjj488,IIdhhj!JJHH
 	
r   c                     t         r   )NotImplementedErrorr    s    r   __getstate__zOrigin.__getstate__z   s    !!r   N)    )__name__
__module____qualname____doc__r   classmethodr   r!   r%   r(   r+   r1   r4   r7   r'   r   r   r   r      sD    *
 , ,@0

!?
&
"r   c                     t        ddd      } t        ddd      }| j                         dk(  sJ |j                         dk(  sJ t         j                  | |g      }|j                  dk(  sJ |j                  dk(  sJ |j
                  dk(  sJ |j                  d      dk(  sJ |t        ddd      k(  sJ  G d	 d
t              }t         j                   ||        |       d g      }|| k(  sJ t         j                   ||       |g      }||k(  sJ t         j                   |        |       g      J ddlm}  |t        ddd             y )N012345         z012345
  ^^z012345
    ^)r0   z  012345
    ^^^c                       e Zd ZddZy)"test_Origin.<locals>.ObjWithOriginNc                     || _         y r   )r   )r
   r   s     r   r   z+test_Origin.<locals>.ObjWithOrigin.__init__   s	     DKr   r   )r9   r:   r;   r   r'   r   r   ObjWithOriginrD      s    	!r   rF   r8   )assert_no_pickling )	r   r1   r   r   r   r	   object
patsy.utilrG   )o1o2o3rF   o4o5rG   s          r   test_OriginrP   ~   sE   	!Q	B	!Q	B;;=N***;;=O+++	R	!B77h88q==66Q;;;;a; $7777!Q''''! ! 
r*MOTB	CB8O8	r*B/	0B8O8>>=?MO<=EEE-vb!Q'(r   N)__all__rI   r   rP   r'   r   r   <module>rR      s"    *m"V m"`)r   