o
    5tiy-                     @   s   d dl mZmZ d dlmZ d dlmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddl mZ G dd deZdS )    )AnyOptional)MultiByteStrDecoder)IntegerStrictLevelTypecodeTypeConversionError   )Align)align_getter)DataPeropertyBase)DefaultValue)ListContainerMinMaxContainer)DataProperty)calc_ascii_char_width)	FloatTypec                       s   e Zd ZdZedefddZedee fddZ	edefddZ
edee fd	d
ZedefddZedefddZedefddZedefddZdddejdejfdedee dedee dededededdf fdd Zdefd!d"Zd#edefd$d%Zd&eddfd'd(Zd&eddfd)d*Zd&eddfd+d,Zd-eddfd.d/Zd#eddfd0d1Z dNd3d4Z!dOd5d6Z"dOd7d8Z#d9edefd:d;Z$defd<d=Z%defd>d?Z&dee fd@dAZ'd#edefdBdCZ(de)fdDdEZ*dOdFdGZ+dOdHdIZ,dOdJdKZ-d#ede.fdLdMZ/  Z0S )PColumnDataProperty)__header_ascii_char_width__body_ascii_char_width__column_index	__dp_list__float_type__format_map__is_calculate__max_precision__minmax_integer_digits__minmax_decimal_places__minmax_additional_format_len__typecode_bitmapreturnc                 C   s   t | jS N)r   get_align_from_typecodetypecodeself r&   H/home/ubuntu/.local/lib/python3.10/site-packages/dataproperty/_column.pyalign    s   zColumnDataProperty.alignc              	   C   sL   | j tjkrd S d}| jD ]}zt|t|j}W q ty#   Y qw |S )Nr   )	r#   r   INTEGER_ColumnDataProperty__dp_listmaxint
bit_lengthdata	TypeError)r%   r-   value_dpr&   r&   r'   r-   $   s   
zColumnDataProperty.bit_lengthc                 C      | j S r!   )!_ColumnDataProperty__column_indexr$   r&   r&   r'   column_index2      zColumnDataProperty.column_indexc                 C   r1   r!   )_decimal_placesr$   r&   r&   r'   decimal_places6   r4   z!ColumnDataProperty.decimal_placesc                 C   s   t | j| jS r!   )r+   ,_ColumnDataProperty__header_ascii_char_width*_ColumnDataProperty__body_ascii_char_widthr$   r&   r&   r'   ascii_char_width:   s   z#ColumnDataProperty.ascii_char_widthc                 C   r1   r!   )*_ColumnDataProperty__minmax_integer_digitsr$   r&   r&   r'   minmax_integer_digits>   r4   z(ColumnDataProperty.minmax_integer_digitsc                 C   r1   r!   )*_ColumnDataProperty__minmax_decimal_placesr$   r&   r&   r'   minmax_decimal_placesB   r4   z(ColumnDataProperty.minmax_decimal_placesc                 C   r1   r!   )1_ColumnDataProperty__minmax_additional_format_lenr$   r&   r&   r'   minmax_additional_format_lenF   r4   z/ColumnDataProperty.minmax_additional_format_lenr   NTr	   r3   
float_type	min_widthformat_flagsis_formatting_floatdatetime_format_streast_asian_ambiguous_widthmax_precisionc	           	         s~   t  j||||d d| _|| _|| _|| _d| _g | _t | _	t
 | _t | _|| _tjj| _|   | jj| jd| _d S )N)rB   rC   rD   rE   r   Tr6   )super__init__r7   r8   r2   _ColumnDataProperty__float_type!_ColumnDataProperty__is_calculater*   r   r:   r   r<   r>   "_ColumnDataProperty__max_precisionr   NONEvalue$_ColumnDataProperty__typecode_bitmap._ColumnDataProperty__calc_typecode_from_bitmap
_formattermake_format_mapr5   _ColumnDataProperty__format_map)	r%   r3   r@   rA   rB   rC   rD   rE   rF   	__class__r&   r'   rI   J   s*   
zColumnDataProperty.__init__c                 C   s(  g }| j d ur|d| j   |d| j d| jj d| j g t| j	 r5|d| j  | j
 rS| j
 rGd| j
j }nd| j
 d}|| | j rq| j red	| jj }nd
| j d}|| | j s| j rd| jj }nd| j d}|| d|S )Nzcolumn=ztype=zalign=zascii_width=zbit_len=zint_digits=zint_digits=()zdecimal_places=zdecimal_places=(z
extra_len=zextra_len=(z, )r3   appendextendtypenamer(   align_stringr9   r   r-   is_typer;   	has_valueis_same_value	min_valuer=   r?   is_zerojoin)r%   element_listrN   r&   r&   r'   __repr__p   s6   












zColumnDataProperty.__repr__r0   c              	   C   s   |j tjkrt|jS z| |}W n ty'   | j|j d	|j Y S w | 
|}z|	|W S  ttfy>   Y nw zt|jW S  tyQ   Y t|S w Nz{:s})r#   r   STRINGstrr.   5_ColumnDataProperty__preprocess_value_before_tostringr   rS   getformat(_ColumnDataProperty__get_tostring_format
ValueErrorr/   r   unicode_str)r%   r0   rN   to_string_format_strr&   r&   r'   	dp_to_str   s&   

zColumnDataProperty.dp_to_strr9   c                 C   s   |  | | | d S r!   )extend_header_widthextend_body_widthr%   r9   r&   r&   r'   extend_width   s   
zColumnDataProperty.extend_widthc                 C      |  j |7  _ d S r!   )r7   rp   r&   r&   r'   rn         z&ColumnDataProperty.extend_header_widthc                 C   rr   r!   )r8   rp   r&   r&   r'   ro      rs   z$ColumnDataProperty.extend_body_width	header_dbc                 C   s   |j | _d S r!   )r9   r7   )r%   rt   r&   r&   r'   update_header   s   z ColumnDataProperty.update_headerc                 C   s   |j r|jsJ |j}|  j|jjO  _|   |jtjtjfv r3| j	
|j | j
|j |   | j
|j | j| |   d S r!   )is_include_ansi_escapeno_ansi_escape_dprO   r#   rN   rP   r   REAL_NUMBERr)   r:   updateinteger_digitsr<   r6   *_ColumnDataProperty__update_decimal_placesr>   additional_format_lenr*   rW   ,_ColumnDataProperty__update_ascii_char_widthr%   r0   r&   r&   r'   update_body   s   
zColumnDataProperty.update_body	column_dpc                 C   sh   |  j |jjO  _ |   | j|j | j|j | 	  | j
|j t| j|j| _|   d S r!   )rO   r#   rN   rP   r:   merger;   r<   r=   r{   r>   r?   r+   r8   r9   r}   )r%   r   r&   r&   r'   r      s   zColumnDataProperty.mergec                 C   s
   d| _ d S )NF)rK   r$   r&   r&   r'   begin_update   s   
zColumnDataProperty.begin_updatec                 C   s"   d| _ |   |   |   d S )NT)rK   rP   r{   r}   r$   r&   r&   r'   
end_update   s   zColumnDataProperty.end_updatetypecode_bitmapc                 C   s   t | j|@ o| j| @ S r!   )boolrO   )r%   r   r&   r&   r'   __is_not_single_typecode   s   z+ColumnDataProperty.__is_not_single_typecodec                 C   s~   t jjt jjB t jjB }|t jjB }| |t jjB rdS t| j	|t jjB @ 
ddkr/dS t| j	|@ 
ddkr=dS dS )NF1   T)r   rx   rN   INFINITYNANr)   +_ColumnDataProperty__is_not_single_typecodeNULL_STRINGbinrO   count)r%   FLOAT_TYPECODE_BMPNUMBER_TYPECODE_BMPr&   r&   r'   __is_float_typecode   s   z&ColumnDataProperty.__is_float_typecodec                 C   sJ   | j g}| jD ]}|jr|jsJ |j}|t| || j qt|S r!   )	r8   r*   rv   rw   rW   r   rm   _east_asian_ambiguous_widthr+   )r%   
width_listr0   r&   r&   r'   __calc_body_ascii_char_width  s   

z/ColumnDataProperty.__calc_body_ascii_char_widthc                 C   s$   | j jd u rd S t| jt| j jS r!   )r=   	max_valueminrL   r,   r$   r&   r&   r'   __calc_decimal_places  s   z(ColumnDataProperty.__calc_decimal_placesc                 C   s,   | j tjkr| j|j dS | j| j dS rc   )r#   r   rd   rS   rg   r~   r&   r&   r'   __get_tostring_format  s   z(ColumnDataProperty.__get_tostring_formatc                 C   s   |   rtjS t| tjj| tjjgrtjS tjtjtj	tjtj
tjtjtjtjtjtjg}|D ]}| j|j@ r@|  S q4| jtjjkrKtjS tjS r!   )&_ColumnDataProperty__is_float_typecoder   rx   anyr   BOOLrN   DATETIMErd   r)   
DICTIONARY
IP_ADDRESSLISTr   r   r   rO   rM   )r%   typecode_listr#   r&   r&   r'   __get_typecode_from_bitmap  s6   z-ColumnDataProperty.__get_typecode_from_bitmapc                 C      | j sd S |  | _d S r!   )rK   /_ColumnDataProperty__calc_body_ascii_char_widthr8   r$   r&   r&   r'   __update_ascii_char_width@     z,ColumnDataProperty.__update_ascii_char_widthc                 C   s*   | j sd S |  | _| jj| jd| _d S )NrG   )rK   (_ColumnDataProperty__calc_decimal_placesr5   rQ   rR   rS   r$   r&   r&   r'   __update_decimal_placesF  s   
z*ColumnDataProperty.__update_decimal_placesc                 C   r   r!   )rK   -_ColumnDataProperty__get_typecode_from_bitmap	_typecoder$   r&   r&   r'   __calc_typecode_from_bitmapM  r   z.ColumnDataProperty.__calc_typecode_from_bitmapc                 C   sD   | j |j ks| j tjtjtjfv r|jS | j|jtj| j	dd
 S )NF)strict_levelr@   strip_ansi_escape)r#   r   rd   r   r   r.   
type_classr   MINrJ   convertr~   r&   r&   r'   "__preprocess_value_before_tostringS  s   z5ColumnDataProperty.__preprocess_value_before_tostring)r   r   r    N)r    N)1__name__
__module____qualname__	__slots__propertyr
   r(   r   r,   r-   r3   r6   r9   r   r;   r   r=   r?   r   DATETIME_FORMATMAX_PRECISIONr   r   re   rI   rb   r   rm   rq   rn   ro   ru   r   r   r   r   r   r   r   r   ri   r   r   r}   r{   rP   r   rf   __classcell__r&   r&   rT   r'   r      s~    	
&+



#

r   N)typingr   r   mbstrdecoderr   typepyr   r   r   r   _alignr
   _align_getterr   _baser   _commonr   
_containerr   r   _datapropertyr   	_functionr   r   r   r&   r&   r&   r'   <module>   s    