3 D\ @sdZddlZddlZddlZyddlmZWnek rDeZYnXddlm Z m Z ddl m Z ddl ZddlZejeZddZdd Zd d Zd d ZdS)a Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. N)JSONDecodeError) ParserError ScannerError) YAMLErrorc#Cs,d}g}ytjjj|}Wntk r}z|jdkrZtjd||jt |d|nV|jdkrtjd||jt |d|n*|jdkrtjd||jt |d||rd|fSWYdd}~Xn"t k r}z&tjd||jt |d|WYdd}~Xntjjj k rL}z||j _ |j g}WYdd}~Xntk r|}zt||g}WYdd}~Xnttk r}z&|jdkrytjjj|}Wntjjjk r}z||j _|j g}WYdd}~Xntk r}zt||g}WYdd}~Xntk r}zn|rRtjd ||jtjd |t|n>tjd ||jtjd |t|dt |d |t|fgfSWYdd}~XnXn t||g}WYdd}~Xn0tk r}zt ||g}WYdd}~XnXt|t r$| r$tjd d d d |tjddg}||fS)z, Decode filename into an object NzTemplate file not found: %sz/Template references a directory, not a file: %s z2Permission denied when accessing template file: %szCannot read file contents: %s0found character '\t' that cannot start any tokenfound unknown escape characterzTemplate %s is malformed: %sz+Tried to parse %s as JSON but got error: %szTemplate needs to be an object.)message)r r )cfnlintdecodeZcfn_yamlloadIOErrorerrnoLOGGERerrorappendcreate_match_file_errorUnicodeDecodeErrorZ CfnParseErrormatchZFilenamercreate_match_yaml_parser_errorrproblemZcfn_jsonrfilenamecreate_match_json_parser_error Exceptioninfostrr isinstancedictMatch ParseError)rZignore_bad_templatetemplatematcheseerrZjson_errr'q/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/decode/__init__.pyr!s`       &0rc Cs>|jjd}|jjd}|j}tj||||d|tj|dS)z!Create a Match for a parser errorr )r )Z problem_marklinecolumnrr r!r") parser_errorrlinenocolnomsgr'r'r(r\s   rc Cstjdddd|tj|dS)z!Create a Match for a parser errorr r)Z linenumberZ columnnumberZ linenumberendZcolumnnumberendrZruler )r r!r")rr.r'r'r(rfsrc Cs^tjddkr"|j}|j}|j}ntjddkr>d}d}|j}tj||||d|tj|dS)z!Create a Match for a parser errorrrr )r ) sys version_infor,r-r.r r r!r")r+rr,r-r.r'r'r(rmsr)__doc__r0loggingsixZ json.decoderr ImportError ValueErrorZ yaml.parserrrZyamlrZcfnlint.decode.cfn_yamlr Zcfnlint.decode.cfn_json getLogger__name__rrrrrr'r'r'r(s    ;