a
    �Ï?eˆ  ã                   @   s„   d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
 dee
edœd	d
„Zeeejeje eje f dœdd„ZdS )z¼anyconfig.query module to support query data with JMESPath expressions.

Changelog:

.. versionadded:: 0.8.3

   - Added to query config data with JMESPath expression, http://jmespath.org
é    Né   )Ú	InDataExTÚInDataT)Úis_dict_likeé   )Ú	MaybeJexp)ÚdataÚjexpÚreturnc                 K   sb   |du s|s| S t | ƒs0t dt| ƒ› �¡ | S tt t| ¡t t|¡fi |¤Ž\}}|r^|‚|S )z2Try to query data with JMESPath expression `jexp`.NzBCould not query because given data is not a mapping object (type? )	r   ÚwarningsÚwarnÚtypeÚqueryÚtypingÚcastr   Ústr)r   r	   ÚoptionsÚodataÚexc© r   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/anyconfig/query/query.pyÚ	try_query   s    ÿÿÿ
r   c              
   K   sh   d}zt  |¡}| | ¡|fW S  tyJ } z| |fW  Y d}~S d}~0  tyb   d|f Y S 0 dS )ai  Filter data with given JMESPath expression.

    See also: https://github.com/jmespath/jmespath.py and http://jmespath.org.

    :param data: Target object (a dict or a dict-like object) to query
    :param jexp: a string represents JMESPath expression
    :param options: Keyword options

    :return: A tuple of query result and maybe exception if failed
    N)ÚjmespathÚcompileÚsearchÚ
ValueErrorÚBaseException)r   r	   Ú_optionsr   Zpexpr   r   r   r   -   s    
r   )N)Ú__doc__r   r   r   Úcommonr   r   Úutilsr   Z	datatypesr   r   r   ÚTupleÚOptionalÚ	Exceptionr   r   r   r   r   Ú<module>   s   ÿÿ