o
    
i                     @   s  d dl mZmZmZ d dlmZ d dlZddlmZ ddl	m
Z
 ddlmZmZmZmZ G dd	 d	eZ	
		
	ddedededededefddZdeeef defddZdedefddZ	
		
	ddededededededdfddZdedefddZdS )     )UnionIOAny)StringION   )YAML)RepresenterError)
force_pathFilePath	YAMLInput
YAMLOutputc                   @   s    e Zd ZdddZd	ddZdS )

CustomYamlsafeTc                 C   s&   t j| ||d d| _d| _d| _d S )N)typpureFTzutf-8)r   __init__default_flow_styleallow_unicodeencoding)selfr   r    r   C/home/ubuntu/.local/lib/python3.10/site-packages/srsly/_yaml_api.pyr      s   
zCustomYaml.__init__Nc                 K   s<   d}|d u rd}t  }tj| ||fi | |r| S d S )NFT)r   r   dumpgetvalue)r   datastreamkwinefficientr   r   r   r      s   zCustomYaml.dump)r   T)N)__name__
__module____qualname__r   r   r   r   r   r   r   
   s    
r         Fr   indent_mappingindent_sequenceindent_offset	sort_keysreturnc                 C   s&   t  }||_|j|||d || S )a  Serialize an object to a YAML string. See the ruamel.yaml docs on
    indentation for more details on the expected format.
    https://yaml.readthedocs.io/en/latest/detail.html?highlight=indentation#indentation-of-block-sequences

    data: The YAML-serializable data.
    indent_mapping (int): Mapping indentation.
    indent_sequence (int): Sequence indentation.
    indent_offset (int): Indentation offset.
    sort_keys (bool): Sort dictionary keys.
    RETURNS (str): The serialized string.
    )mappingsequenceoffset)r    sort_base_mapping_type_on_outputindentr   )r   r#   r$   r%   r&   yamlr   r   r   
yaml_dumps   s   
r.   c              
   C   s:   t  }z|| W S  ty } ztd| d}~ww )zDeserialize unicode or a file object a Python object.

    data (str / file): The data to deserialize.
    RETURNS: The deserialized Python object.
    zInvalid YAML: N)r   load	Exception
ValueError)r   r-   er   r   r   
yaml_loads4   s   r3   pathc                 C   s\   | dkrt j }t|S t| }|jddd}t|W  d   S 1 s'w   Y  dS )zLoad YAML from file or standard input.

    location (FilePath): The file path. "-" for reading from stdin.
    RETURNS (YAMLOutput): The loaded content.
    -rutf8r   N)sysstdinreadr3   r	   open)r4   r   	file_pathfr   r   r   	read_yamlA   s   
$r?   c           	      C   sp   t |||||d}| dkrt| dS t| dd}|jddd}|| W d   dS 1 s1w   Y  dS )	a  Create a .json file and dump contents or write to standard
    output.

    location (FilePath): The file path. "-" for writing to stdout.
    data (YAMLInput): The JSON-serializable data to output.
    indent_mapping (int): Mapping indentation.
    indent_sequence (int): Sequence indentation.
    indent_offset (int): Indentation offset.
    sort_keys (bool): Sort dictionary keys.
    )r#   r$   r%   r&   r5   F)require_existswr7   r8   N)r.   printr	   r<   write)	r4   r   r#   r$   r%   r&   	yaml_datar=   r>   r   r   r   
write_yamlO   s   "rE   objc                 C   s$   zt |  W dS  ty   Y dS w )zCheck if a Python object is YAML-serializable (strict).

    obj: The object to check.
    RETURNS (bool): Whether the object is YAML-serializable.
    TF)r.   r   )rF   r   r   r   is_yaml_serializablep   s   rG   )r!   r"   r!   F)typingr   r   r   ior   r9   ruamel_yamlr   ruamel_yaml.representerr   utilr	   r
   r   r   r   intboolstrr.   r3   r?   rE   rG   r   r   r   r   <module>   s\    

!