
    9i                         S SK JrJr  S SKJr  SSKJr  SSKJrJ	r	  \" 5       \	" 5       \	" 5       S.r
SS jrSS	 jrS
 rg)    )BytesIOStringIO)Path   )File)JsonHandlerYamlHandler)jsonyamlymlNc                    [        U [        5      (       a  [        U 5      n Uc)  [        U [        5      (       a  U R                  S5      S   nU[        ;  a  [        SU 35      e[        U   n[        U [        5      (       a  UR                  (       a=  [        [        R                  " U 5      5       nUR                  " U40 UD6nSSS5        U$ [        [        R                  " U 5      5       nUR                  " U40 UD6nSSS5        U$ [        U S5      (       a  UR                  " U 40 UD6nU$ [        S5      e! , (       d  f       W$ = f! , (       d  f       W$ = f)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         T/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/fileio/io.pyr   r      s5   ( $4yz$44jjob)/).{m<==k*G$$.../1ll1// 0 J 4)Qll1// * J	 
v		ll4*6* J HII 0/ J *) Js   3D?0E?
E
E c                 F   [        U[        5      (       a  [        U5      nUc8  [        U[        5      (       a  UR                  S5      S   nOUc  [	        S5      eU[
        ;  a  [        SU 35      e[
        U   nUc  UR                  " U 40 UD6$ [        U[        5      (       a  UR                  (       aL  [        5        nUR                  " X40 UD6  [        R                  " UR                  5       U5        SSS5        g[        5        nUR                  " X40 UD6  [        R                  " UR                  5       U5        SSS5        g[!        US5      (       a  UR                  " X40 UD6  g[        S5      e! , (       d  f       g= f! , (       d  f       g= f)ac  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&   ;   sP   & $4ydC  **S/"-K\BD D/).{m<==k*G|""31&11	D#		qS.v.

d3  aS.v.

1::<.  
w		S)&)HII  s   9F9F
F
F c                 j    U[         ;  a  [        SU 35      e[         U   nUR                  " U 40 UD6$ )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   s=      _$.vh788f%G=='''    )N)NN)ior   r   pathlibr   r   r   r+   r   r	   r   r   r&   r*    r,   r!   <module>r0      s=    !   , MM='T-J`(r,   