3 O4Â\ã@sfdd„Zdd„Zdd„Zddd„Zd d „Zd d „Zd d„Zdd„Zdd„Zdd„Z dd„Z dd„Z dS)cCs d||giS)Nz Fn::GetAtt©)Ú logical_nameZattribute_namerrú†/Users/sshvans/Documents/Work/Quickstart/python-virtual-environments/env/lib/python3.6/site-packages/samtranslator/model/intrinsics.pyÚfnGetAttsrcCsd|iS)NÚRefr)rrrrÚrefsrcCs d||giS)NzFn::Joinr)Ú delimiterÚvaluesrrrÚfnJoin sr NcCs|rd||giSd|iS)NzFn::Subr)ÚstringÚ variablesrrrÚfnSub s r cCsd|iS)NzFn::Orr)Z argument_listrrrÚfnOrsr cCsd||ddigiS)NzFn::Ifrz AWS::NoValuer)Ú conditionÚdatarrrÚmake_conditionalsrcCs(g}x|D]}d|i}|j|ƒq W|S)NÚ Condition)Úappend)Úconditions_listZcondition_or_listrÚcrrrÚmake_condition_or_list!s  rcCst|ƒ}t|ƒ}|S)N)rr )rZor_listrrrrÚmake_or_condition)srcCsd|d|d}|S)aþ Every condition can hold up to max_conditions, which (as of writing this) is 10. Every time a condition is created, (max_conditions) are used and 1 new one is added to the conditions list. This means that there is a net decrease of up to (max_conditions-1) with each iteration. This formula calculates the number of conditions needed. x items in groups of y, where every group adds another number to x Math: either math.ceil((x-1)/(y-1)) or math.floor((x+(y-1)-2)/(y-1)) == 1 + (x-2)//(y-1) :param int conditions_length: total # of conditions to handle :param int max_conditions: maximum number of conditions that can be put in an Fn::Or statement :return: the number (int) of necessary additional conditions. éér)Úconditions_lengthÚmax_conditionsZnum_conditionsrrrÚcalculate_number_of_conditions/srcCs’t|ƒdkrdSd}i}t|ƒ}t||ƒd}x^t|ƒdkrŒ|}|dkr\dj||ƒ}|d8}t|d|…ƒ}||d…}|j|ƒ|||<q0W|S)a´ Makes a combined condition using Fn::Or. Since Fn::Or only accepts up to 10 conditions, this method optionally creates multiple conditions. These conditions are named based on the condition_name parameter that is passed into the method. :param list conditions_list: list of conditions :param string condition_name: base name desired for new condition :return: dictionary of condition_name: condition_value rNé réz{}{})ÚlenrÚformatrr)rZcondition_namerZ conditionsrZzero_based_num_conditionsZnew_condition_nameZnew_condition_contentrrrÚmake_combined_conditionBs     r cCs:d|krd|dSd|kr.ddj|dƒStdƒ‚dS)ad Converts a given intrinsics dictionary into a short-hand notation that Fn::Sub can use. Only Ref and Fn::GetAtt support shorthands. Ex: {"Ref": "foo"} => ${foo} {"Fn::GetAtt": ["bar", "Arn"]} => ${bar.Arn} This method assumes that the input is a valid intrinsic function dictionary. It does no validity on the input. :param dict intrinsic_dict: Input dictionary which is assumed to be a valid intrinsic function dictionary :returns string: String representing the shorthand notation :raises NotImplementedError: For intrinsic functions that don't support shorthands. rz${%s}z Fn::GetAttÚ.z5Shorthanding is only supported for Ref and Fn::GetAttN)ÚjoinÚNotImplementedError)Zintrinsic_dictrrrÚmake_shorthandfs  r$cCsL|dk rHt|tƒrHt|ƒdkrHt|jƒƒd}|dkpF|dkpF|jdƒSdS)zû Checks if the given input is an intrinsic function dictionary. Intrinsic function is a dictionary with single key that is the name of the intrinsics. :param input: Input value to check if it is an intrinsic :return: True, if yes NrrrrzFn::F)Ú isinstanceÚdictrÚlistÚkeysÚ startswith)ÚinputÚkeyrrrÚ is_instrinsic|s   r,)N) rrr r r rrrrr r$r,rrrrÚs  $