
    uj                         d dl mZmZ d dlmZ ddlmZ ddlmZm	Z	  e             e	             e	            dZ
ddZdd	Zd
 ZdS )    )BytesIOStringIO)Path   )File)JsonHandlerYamlHandler)jsonyamlymlNc                    t          | t                    rt          |           } |0t          | t                    r|                     d          d         }|t          vrt          d|           t          |         }t          | t                    r|j        rHt          t          j	        |                     5 } |j
        |fi |}ddd           n# 1 swxY w Y   nvt          t          j        |                     5 } |j
        |fi |}ddd           n# 1 swxY w Y   n.t          | d          r |j
        | fi |}nt          d          |S )a  Load data from json/yaml/pickle files.

    This method provides a unified api for loading data from serialized files.

    Args:
        file (str or :obj:`Path` or file-like object): Filename or a file-like
            object.
        file_format (str, optional): If not specified, the file format will be
            inferred from the file extension, otherwise use the specified one.
            Currently supported formats include "json", "yaml/yml".

    Examples:
        >>> load('/path/of/your/file')  # file is stored in disk
        >>> load('https://path/of/your/file')  # file is stored on internet
        >>> load('oss://path/of/your/file')  # file is stored in petrel

    Returns:
        The content from the file.
    N.Unsupported format: readz."file" must be a filepath str or a file-object)
isinstancer   strsplitformat_handlers	TypeError	text_moder   r   	read_textloadr   r   hasattr)filefile_formatkwargshandlerfobjs         d/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/fileio/io.pyr   r      s   ( $ 4yyz$44jjoob)/))<{<<===k*G$ 
J 	0$...// 01"gl1////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4)) 0Q"gl1////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	v		 Jgl4**6**HIIIJs$   <CCCDD#&D#c                 V   t          |t                    rt          |          }|Bt          |t                    r|                    d          d         }n|t	          d          |t
          vrt          d|           t
          |         }| |j        | fi |S t          |t                    r|j        r_t                      5 } |j
        | |fi | t          j        |                                |           ddd           dS # 1 swxY w Y   dS t                      5 } |j
        | |fi | t          j        |                                |           ddd           dS # 1 swxY w Y   dS t!          |d          r |j
        | |fi | dS t          d          )a  Dump data to json/yaml strings or files.

    This method provides a unified api for dumping data as strings or to files.

    Args:
        obj (any): The python object to be dumped.
        file (str or :obj:`Path` or file-like object, optional): If not
            specified, then the object is dumped to a str, otherwise to a file
            specified by the filename or file-like object.
        file_format (str, optional): Same as :func:`load`.

    Examples:
        >>> dump('hello world', '/path/of/your/file')  # disk
        >>> dump('hello world', 'oss://path/of/your/file')  # oss

    Returns:
        bool: True for success, False otherwise.
    Nr   r   z0file_format must be specified since file is Noner   writez."file" must be a filename str or a file-object)r   r   r   r   
ValueErrorr   r   dump_to_strr   r   dumpr   
write_textgetvaluer   r#   r   )r    r   r   r   r   r   s         r!   r&   r&   ;   sa   & $ 4yydC   	D**S//"-KK\BD D D/))<{<<===k*G|"w"311&111	D#		 J 	/ 4qS!..v...

d3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4  /aS!..v...
1::<<.../ / / / / / / / / / / / / / / / / / 
w		 JS$))&)))))HIIIs$   7DDD*7E..E25E2c                 n    |t           vrt          d|           t           |         } |j        | fi |S )a  Dump data to json/yaml strings or files.

    This method provides a unified api for dumping data as strings or to files.

    Args:
        obj (any): The python object to be dumped.
        format (str, optional): Same as file_format :func:`load`.

    Examples:
        >>> dumps('hello world', 'json')  # json
        >>> dumps('hello world', 'yaml')  # yaml

    Returns:
        bool: True for success, False otherwise.
    r   )r   r   dumps)r    formatr   r   s       r!   r*   r*   k   sJ      _$$7v77888f%G7='''''    )N)NN)ior   r   pathlibr   r   r   r+   r   r	   r   r   r&   r*    r,   r!   <module>r0      s    !                           , , , , , , , , KMMKMM;== ' ' ' 'T-J -J -J -J`( ( ( ( (r,   