o
    ;Di                     @   sh   d dl mZmZmZ d dlZd dlmZ d dlmZm	Z	m
Z
 G dd deZdd Zd	d
 Zdd ZdS )    )absolute_importprint_functiondivisionN)partial)	text_typebinary_typenumeric_typesc                   @   sx   e Zd ZdZddgZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )
Comparableao  Wrapper class to allow for flexible comparison of objects of different
    types, preserving the relaxed sorting behaviour of Python 2 with
    additional flexibility to allow for comparison of arbitrary objects with
    the `None` value (for example, the date and time objects from the standard
    library cannot be directly compared with `None` in Python 2).

    objinnerc                 C   s0   || _ t|ttfrtdd |D }|| _d S )Nc                 s   s    | ]}t |V  qd S Nr	   ).0o r   H/var/www/Datamplify/venv/lib/python3.10/site-packages/petl/comparison.py	<genexpr>   s    z&Comparable.__init__.<locals>.<genexpr>)r   
isinstancelisttupler
   )selfr
   r   r   r   __init__   s   
zComparable.__init__c                 C   s   | j }t|tr|j }|d u rdS |d u rdS t|tr#t|ts#dS t|ts/t|tr/dS t|tr;t|tr;dS t|trGt|trGdS z||k W S  ty]   t|t|k  Y S w )NFT)r
   r   r	   r   r   r   	TypeError_typestr)r   otherr
   r   r   r   __lt__   s0   



zComparable.__lt__c                 C   s    t |tr| j|jkS | j|kS r   )r   r	   r
   r   r   r   r   r   __eq__@   s   

zComparable.__eq__c                 C   s   | |k p| |kS r   r   r   r   r   r   __le__E   s   zComparable.__le__c                 C   s   | |k p| |k S r   r   r   r   r   r   __gt__H      zComparable.__gt__c                 C   s
   | |k  S r   r   r   r   r   r   __ge__K      
zComparable.__ge__c                 C   
   t | jS r   )strr
   r   r   r   r   __str__N   r"   zComparable.__str__c                 C   r#   r   )r   r
   r%   r   r   r   __unicode__Q   r"   zComparable.__unicode__c                 C   s   dt | j d S )NzComparable())reprr
   r%   r   r   r   __repr__T   r    zComparable.__repr__c                 O   s   t | jg|R i |S r   )iterr
   )r   argskwargsr   r   r   __iter__W   s   zComparable.__iter__c                 C   r#   r   )lenr
   r%   r   r   r   __len__Z   r"   zComparable.__len__c                 C   s   | j |S r   )r
   __getitem__)r   itemr   r   r   r1   ]   s   zComparable.__getitem__N)__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r!   r&   r'   r*   r.   r0   r1   r   r   r   r   r	   
   s    #r	   c                 C   s&   t | trdS t | trdS t| jS )Nr$   unicode)r   r   r   typer3   xr   r   r   r   a   s
   


r   c                     s0   t j|  t|  fdd  fdd}|S )Nc              	      s*   z | W S  t tfy   |  Y S w r   
IndexErrorKeyErrorr
   )gettergetter_with_defaultr   r   _getter_with_fallbackn   s
   
z4comparable_itemgetter.<locals>._getter_with_fallbackc                    s   t  | S r   r   r:   )rB   r   r   <lambda>s   s    z'comparable_itemgetter.<locals>.<lambda>)operator
itemgetter_itemgetter_with_default)r,   gr   )rB   r@   rA   r   comparable_itemgetterj   s
   
rH   c                     s4   dd  t dkrt d ddS  fddS )	z itemgetter compatible with `operator.itemgetter` behavior, filling missing
    values with default instead of raising IndexError or KeyError c              	   S   s&   z| | W S  t tfy   | Y S w r   r<   )r
   r2   defaultr   r   r   _get_defaultz   s
   
z._itemgetter_with_default.<locals>._get_default   r   Nr2   rI   c                    s   t  fddD S )Nc                 3   s    | ]
} |d dV  qd S )NrL   r   )r   r2   )rJ   r
   r   r   r      s    z=_itemgetter_with_default.<locals>.<lambda>.<locals>.<genexpr>)r   r?   rJ   r,   r?   r   rC      s    z*_itemgetter_with_default.<locals>.<lambda>)r/   r   )r,   r   rM   r   rF   w   s   rF   )
__future__r   r   r   rD   	functoolsr   petl.compatr   r   r   objectr	   r   rH   rF   r   r   r   r   <module>   s    W	