
    DUf                     ^    d dl mZ d dlZd dlZd dlZ G d dej                  ZddZd Z	dS )	    Nc                   ,     e Zd Z	 d fd	Z fdZ xZS )TabularFilePathFc                 ^    || _         t                                          |||           dS )a  
        Parameters
        ----------
        default_column : str or int
            Name of desired column or 0-based column index.
        exists : bool
        resolve_path : bool

        Returns
        -------
        path to file, column name or index

        )existsresolve_path
allow_dashN)default_column_indexsuper__init__)selfr	   r   r   r   	__class__s        O/var/www/html/software/conda/lib/python3.11/site-packages/cooltools/cli/util.pyr   zTabularFilePath.__init__   s?      %9! 	 	
 	
 	
 	
 	
    c                 ,   |d S |                     d          \  }}}t                                          |||          }|s| j        }nF|                                r0t          |          dz
  }|dk     r|                     d||           n|}||fS )N::   r   z/Expected one-based column number, received "0".)	partitionr
   convertr	   isdigitintfail)	r   valueparamctx	file_path_fieldcolr   s	           r   r   zTabularFilePath.convert   s    =F#ood33	1eGGOOIuc::	 	+CC]]__ 	e**q.CQww		KUTWXXXC#~r   )FFF)__name__
__module____qualname__r   r   __classcell__)r   s   @r   r   r      sY        QV
 
 
 
 
 
*        r   r   	#c                 ~   t          | d          5 }t          j        |                                          }ddd           n# 1 swxY w Y   g }|D ].}|                    |          s|                    |            n/t          d          D ])}|                    |                                           *|                    d           t          j
                                        d                    |                    }|r.|d                                                             |          }	nd}	||	fS )zA
    Warning: reads the entire file into a StringIO buffer!

    rN
   r   
)openioStringIOread
startswithappendrangereadlineseekcsvSniffer
has_headerjoinstripsplit)
r   sepcommentfbufsample_linesliner   r4   namess
             r   sniff_for_headerr?   -   sk   
 
i		 $k!&&((##$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ L  w'' 	%%%E	 2YY , ,CLLNN++++HHQKKK))$))L*A*ABBJ Q%%''--c22:s   'AAAc                    |d S |                     d          \  }}}t          j        |          s*t          j        d                    |          | |          |s|}n#|                                rt          |          }||fS )Nr   zPath not found: "{}")r   r   )r   opr   clickBadParameterformatr   r   )r   r   r   default_columnr   r   
field_names          r   validate_csvrG   G   s    }$t44Iq*9Y 
 ")))44#U
 
 
 	
  %#

					 %__
j  r   )r#   r$   )
os.pathpathrA   r2   r*   rB   Pathr   r?   rG    r   r   <module>rL      s          



 				 # # # # #ej # # #L   4! ! ! ! !r   