
    L                     $   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlZ G d	 d
e	j                        Z G d de	j                        Z G d de	j                        Z G d dej&                        Zd Zd Zy)z8Helpers for parsing Binary Authorization resource files.    )absolute_import)division)unicode_literalsN)
exceptions)yaml)filesc                       e Zd ZdZy)ResourceFileReadErrorz,Indicates a resource file could not be read.N__name__
__module____qualname____doc__     <lib/googlecloudsdk/command_lib/container/binauthz/parsing.pyr
   r
       s    4r   r
   c                       e Zd ZdZy)ResourceFileTypeErrorz5Indicates a resource file was of an unsupported type.Nr   r   r   r   r   r   $   s    =r   r   c                       e Zd ZdZy)ResourceFileParseErrorz.Indicates a resource file could not be parsed.Nr   r   r   r   r   r   (   s    6r   r   c                       e Zd ZdZdZdZy)ResourceFileTyper         N)r   r   r   UNKNOWNJSONYAMLr   r   r   r   r   ,   s    '	
$	
$r   r   c                     t         j                  j                  |       \  }}|dk(  rt        j                  S |dv rt        j
                  S t        j                  S )Nz.json)z.yamlz.yml)ospathsplitextr   r   r   r   )	file_name_exts      r   GetResourceFileTyper%   2   sN    77I&&!SG^   
   ###r   c                 j   	 t        j                  |       }t        |       }|t        j                  k(  r	 t        j                  |      S |t        j                  k(  r	 t        j                  |      S t#        dj%                  |             # t         j                  $ r#}t        t	        j
                  |            d}~ww xY w# t        $ r&}t        dt	        j
                  |      z         d}~ww xY w# t        j                   $ r&}t        dt	        j
                  |      z         d}~ww xY w)a  Load an input resource file in either JSON or YAML format.

  Args:
    input_fname: The name of the file to convert to parse.

  Returns:
    The Python object resulting from the decode.

  Raises:
    ResourceFileReadError: An error occurred attempting to read the input file.
    ResourceFileTypeError: The input file was an unsupported type.
    ResourceFileParseError: A parse error occurred.
  NzError in resource file JSON: zError in resource file YAML: z(Input file [{}] not of type YAML or JSON)r   ReadFileContentsErrorr
   six	text_typer%   r   r   jsonloads
ValueErrorr   r   r   loadYAMLParseErrorr   format)input_fname
input_texte	file_types       r   LoadResourceFiler5   <   s   2''4J "+.)"'''5ZZ
## $)))5YYz""
  299+FH H# 
 2
a 0
112  5"#B#&==#3$4 5 55  5"#B#&==#3$4 5 55sF   B C C9 C!B??C	C6!C11C69D2!D--D2)r   
__future__r   r   r   r+   r   enum-googlecloudsdk.command_lib.container.binauthzr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r)   r(   r
   r   r   Enumr   r%   r5   r   r   r   <module>r<      sy     ? &  '  	  D $ * 
5J,, 5>J,, >7Z-- 7tyy $"Hr   