o nnh @sdZddlmZddlZddlZddlZddlZddlm Z m Z m Z d+d d Z d,d d Z d-ddZd.ddZ   d/d0ddZd1d2ddZd3d4d#d$Zd5d6d'd(ZGd)d*d*ejZdS)7zFunctions for disk IO.) annotationsN)ENCODINGto_bytesto_textpathstrreturnt.AnycCstt|S)z:Parse and return the json content from the specified path.)jsonloadsread_text_filerrD/usr/local/lib/python3.10/dist-packages/ansible_test/_internal/io.pyread_json_filesrcCs tt|S)z2Return the contents of the specified path as text.)rread_binary_filerrrrr s r bytescCs4t| }|WdS1swYdS)z3Return the contents of the specified path as bytes.N)open_binary_fileread)rfile_objrrrrs $rNonecCstjt|dddS)zGCreate a directory at path, including any necessary parent directories.T)exist_okN)osmakedirsrrrrr make_dirs srFTcontentcreate_directoriesbool formattedencoder$t.Optional[t.Type[json.JSONEncoder]]cCs:tj|||rdnd|r dnd|dd}t|||d|S)z\Write the given json content to the specified path, optionally creating missing directories.N)z, z: ),:) sort_keysindent separatorscls )r)r dumpswrite_text_file)rrrrr text_contentrrrwrite_json_file%s  r-cCsR|r ttj|t|d}|t|WddS1s"wYdS)z\Write the given text content to the specified path, optionally creating missing directories.wbN)rrrdirnamerwriter)rrrrrrrr+9s  "r+rmode t.IO[str]cCs(d|vr td|tjt||tdS)z$Open the given path for text access.bz*mode cannot include "b" for text files: %s)encoding) Exceptionioopenrrrr2rrropen_text_fileBs r:rb t.IO[bytes]cCs$d|vr td|tt||S)z&Open the given path for binary access.r4z*mode must include "b" for binary files: %s)r6r7r8rr9rrrrJs rc@seZdZdZdddZdS) SortedSetEncoderzEncode sets as sorted lists.or r cCs t|tr t|Stj||S)z.Return a serialized version of the `o` object.) isinstancesetsortedr JSONEncoderdefault)selfr>rrrrCUs zSortedSetEncoder.defaultN)r>r r r )__name__ __module__ __qualname____doc__rCrrrrr=Rsr=)rrr r )rrr r)rrr r)rrr r)FTN) rrrr rrrrr r!r r)F)rrrrrrr r)r1)rrr2rr r3)r;)rrr2rr r<)rH __future__rr7r rtypingtr5rrrrr rrr-r+r:rrBr=rrrrs&