o
    d`                     @   sh   d Z dZddlZddlmZ dd ZG dd deZG d	d
 d
eZ	G dd de	Z
G dd de	ZdS )zResource format handlers.zMark Roach (mrroach@google.com)    N)utilc                 C   s*   t | trt| dkrtt|  S | S )N   )
isinstancedictlennextitervalues)data r   o/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/pyactiveresource/formats.pyremove_root
   s   r   c                   @      e Zd ZdZdS )Errorz$Base exception type for this module.N__name__
__module____qualname____doc__r   r   r   r   r          r   c                   @   r   )Basez%A base format object for inheritance.Nr   r   r   r   r   r      r   r   c                   @   s$   e Zd ZdZdZdZedd ZdS )	XMLFormatz*Read XML formatted ActiveResource objects.xmlzapplication/xmlc              
   C   sR   t d}|d|  ztj| dd}W t|S  tjy( } zt|d}~ww )*Convert a resource string to a dictionary.pyactiveresource.formatdecoding resource: %sF)saverootN)logging	getLoggerdebugr   xml_to_dictr   r   resource_stringlogr
   errr   r   r   decode   s   
zXMLFormat.decodeN)r   r   r   r   	extension	mime_typestaticmethodr%   r   r   r   r   r      s    r   c                   @   s0   e Zd ZdZdZdZedd Zedd ZdS )	
JSONFormatz8Encode and Decode JSON formatted ActiveResource objects.jsonzapplication/jsonc              
   C   sR   t d}|d|  zt| d}W t|S  ty( } zt|d}~ww )r   r   r   utf-8N)	r   r   r   r   json_to_dictr%   
ValueErrorr   r   r!   r   r   r   r%   .   s   
zJSONFormat.decodec                 C   s&   t d}|d|  t| dS )z*Convert a dictionary to a resource string.r   zencoding resource: %rr+   )r   r   r   r   to_jsonencode)r
   r#   r   r   r   r/   9   s   
zJSONFormat.encodeN)	r   r   r   r   r&   r'   r(   r%   r/   r   r   r   r   r)   (   s    

r)   )r   
__author__r   pyactiveresourcer   r   	Exceptionr   objectr   r   r)   r   r   r   r   <module>   s   