
    |xj                    F    d dl mZ d dlZd dlZd dlmZ ddZdd
ZddZdS )    )annotationsN)Anykeyr   returnstrc                H    t          | pd                                          S N r   strip)r   s    &src/jarvis_finance/imports/row_hash.py_normalize_keyr      s    syb>>!!!    valuec                L    | dS t          |                                           S r	   r   )r   s    r   _normalize_valuer      s$    }ru::r   rowdict[str, Any]c                    d |                                  D             }t          j        |ddd          }t          j        |                    d                                                    S )ai  Return a stable deterministic hash for a logical CSV row.

    Whitespace, key order, and None-vs-empty differences are normalized so the
    same logical source row cannot be imported twice merely because formatting
    changed. Values remain case-sensitive; ticker/ISIN canonicalization belongs
    in import-specific validation, not in the generic hash.
    c                N    i | ]"\  }}t          |          t          |          #S  )r   r   ).0kvs      r   
<dictcomp>z$compute_row_hash.<locals>.<dictcomp>   s/    QQQTQ.##%5a%8%8QQQr   FT),:)ensure_ascii	sort_keys
separatorszutf-8)itemsjsondumpshashlibsha256encode	hexdigest)r   
normalizedpayloads      r   compute_row_hashr*      sa     RQSYY[[QQQJj%4T^___G>'..1122<<>>>r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )	
__future__r   r$   r"   typingr   r   r   r*   r   r   r   <module>r-      s    " " " " " "        " " " "   
? 
? 
? 
? 
? 
?r   