
    %                     b   S r SSKrSSKJr  SSKJr  SSKJr  SSKr " S S\R                  5      r	 " S S	\	5      r
 " S
 S\	5      r " S S\	5      r " S S\R                  " \R                  \5      5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z/This module contains all survey question types.    N)util)
exceptions)logc                       \ rS rSrSrSrg)Error   z!Base error class for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r	       1lib/googlecloudsdk/command_lib/survey/question.pyr   r      s    )r   r   c                       \ rS rSrSrSrg)AnswerRejectedError    zRaises when answer is rejected.r	   Nr
   r	   r   r   r   r       s    'r   r   c                       \ rS rSrSrSrg)"RetrieveAnswerOfUnansweredQuestion%   z:Raises when retrieving answer from an unanswered question.r	   Nr
   r	   r   r   r   r   %   s    Br   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )QuestionCreationError*   z>Raises when question cannot be created with the provided data.c                 l   > SR                  U5      n[        [        U ]  SR	                  U5      5        g )Nz, zQuestion cannot be created because either some required field is missing or there are redundant fields. Required fields are {}.)joinsuperr   __init__format)selfrequired_fieldsrequired_fields_in_string	__class__s      r   r   QuestionCreationError.__init__-   s2     $		/ :	
/	 9:<r   r	   )r   r   r   r   r   r   r   __classcell__r$   s   @r   r   r   *   s    F< <r   r   c                      \ rS rSrSr  SS jr\R                  S 5       r\	S 5       r
\	S 5       r\	S 5       rS	 r\R                  S
 5       rS rS r\R                  S 5       rS rS r\	S 5       rS rS rS rSrg)Question5   a  Base class for survey questions.

Attributes:
  _question: str, the question to ask.
  _instruction: str, instruction on how to answer the question.
  _instruction_on_rejection: str, instruction after the answer is rejected.
  _answer: str, the answer to the question.
Nc                 4    Xl         X l        X0l        X@l        g N)	_question_instruction_instruction_on_rejection_answer)r!   questioninstructioninstruction_on_rejectionanswers        r   r   Question.__init__?   s    
 N#%="Lr   c                     g r,   r	   )r!   contents     r   FromDictionaryQuestion.FromDictionaryI       r   c                     U R                   $ r,   )r-   r!   s    r   r1   Question.questionM   s    >>r   c                     U R                   $ r,   )r.   r<   s    r   r2   Question.instructionQ   s    r   c                     U R                   $ r,   )r/   r<   s    r   r3   !Question.instruction_on_rejectionU   s    )))r   c                 `    U R                  5         [        R                  R                  5         g r,   )_PrintQuestionr   outflushr<   s    r   PrintQuestionQuestion.PrintQuestionY   s    GGMMOr   c                     g r,   r	   r<   s    r   rC   Question._PrintQuestion]   r:   r   c                 z    U R                   (       a*  [        R                  R                  U R                   5        g g r,   )r.   r   errwriter<   s    r   PrintInstructionQuestion.PrintInstructiona   s&    	ggmmD%%& r   c                 z    U R                   (       a*  [        R                  R                  U R                   5        g g r,   )r/   r   rK   rL   r<   s    r   PrintInstructionOnRejection$Question.PrintInstructionOnRejectione   s&    %%	ggmmD223 &r   c                     g)<Returns True if answer is accepted, otherwise returns False.Nr	   r!   r4   s     r   AcceptAnswerQuestion.AcceptAnsweri   s     	r   c                     U R                   S L$ r,   )r0   r<   s    r   
IsAnsweredQuestion.IsAnsweredn   s    <<t##r   c                 R    U R                  U5      (       a  Xl        g [        S5      e)NzAnswer is invalid.)rU   r0   r   rT   s     r   AnswerQuestionQuestion.AnswerQuestionq   s$      l 455r   c                 Z    U R                  5       (       a  U R                  $ [        S5      e)NzNo answer for this question.)rX   r0   r   r<   s    r   r4   Question.answerw   s%    \\./MNNr   c                     [        XR                  5      (       aY  U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ gNF)
isinstancer$   r-   r.   r/   r!   others     r   __eq__Question.__eq__~   s`    %((nn/ P5#5#55P,,0O0OOQ r   c                     X:X  + $ r,   r	   rb   s     r   __ne__Question.__ne__       r   c                 Z    [        U R                  U R                  U R                  45      $ r,   )hashr-   r.   r/   r<   s    r   __hash__Question.__hash__   s+    !2!2//1 2 2r   )r0   r.   r/   r-   )NN)r   r   r   r   r   r   abcabstractmethodr8   propertyr1   r2   r3   rF   rC   rM   rP   rU   rX   r[   r4   rd   rg   rl   r   r	   r   r   r)   r)   5   s     )-	 	 	     * * 	 	'4 	 	$6 O O2r   r)   c                   l   ^  \ rS rSrSr SU 4S jjr\S 5       rS rS r	S r
S rS	 rS
 rS rSrU =r$ )MultiChoiceQuestion   zHMulti-choice question.

Attributes:
  _choices: [str], list of choices.
c                 6   > [         [        U ]  XX5S9  X@l        g )N)r4   )r   rr   r   _choices)r!   r1   r2   r3   choicesr4   r$   s         r   r   MultiChoiceQuestion.__init__   s&     

t-7 . HMr   c                 F     U " S0 UD6$ ! [          a    [        / SQS9ef = f)N)r1   r2   r3   rv   r"   r	   	TypeErrorr   clsr7   s     r   r8   "MultiChoiceQuestion.FromDictionary   s4    	^7^ 	! 3 	 		   
  c                     U R                  [        S[        U R                  5      S-   5      S9n[        R
                  " U5        g)z&Prints question and lists all choices.   indexesN)_FormatQuestionrangelenru   r   Print)r!   question_reprs     r   rC   "MultiChoiceQuestion._PrintQuestion   sB     ((a$--(1,. ) /M IImr   c                 ^   [        XR                  5       VVs/ s H  u  p#SR                  X#5      PM     nnnU Vs/ s H  n[        R                  " US5      PM     nnSR                  U5      n[        R                  " U R                  S5      nSR                  Xd/5      $ s  snnf s  snf )z%Formats question to present to users.z[{}] {}   
r   )zipru   r    survey_utilIndentr   r-   )r!   r   indexmsgchoices_reprr7   r   s          r   r   #MultiChoiceQuestion._FormatQuestion   s     g}}55JE 	$5   COO,wK&&w2,LO99\*L&&t~~q9M99m233 Ps
   B$!B*c                      [        U5      nSUs=:*  =(       a    [        U R                  5      :*  $ s  $ ! [         a     gf = f)rS   r   F)intr   ru   
ValueErrorr!   r4   
answer_ints      r   rU    MultiChoiceQuestion.AcceptAnswer   sH    3v;j *22DMM 22222  s   5 
AAc                 &    U R                   US-
     $ )#Gets the choice at the given index.r   ru   r!   r   s     r   ChoiceMultiChoiceQuestion.Choice   s     ==##r   c                 *   [        XR                  5      (       ay  U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ gr`   )ra   r$   r-   r.   r/   ru   rb   s     r   rd   MultiChoiceQuestion.__eq__   st    %((nn/ 25#5#552,,0O0OO2 --5>>13
 r   c                     [        U R                  U R                  U R                  [	        U R
                  5      45      $ r,   )rk   r-   r.   r/   tupleru   r<   s    r   rl   MultiChoiceQuestion.__hash__   s9    !2!2//t}}1EG H Hr   c                 ,    [        U R                  5      $ r,   )r   ru   r<   s    r   __len__MultiChoiceQuestion.__len__   s    t}}r   r   r,   )r   r   r   r   r   r   classmethodr8   rC   r   rU   r   rd   rl   r   r   r&   r'   s   @r   rr   rr      sO      	 		43$
H r   rr   c                   *    \ rS rSrSrS rS rS rSrg)SatisfactionQuestion   zCustomer satisfaction question.c                 ^    U R                  5       (       a  [        U R                  5      S:  $ g)zFReturns true is user answers "Very satisfied" or "Somewhat satisfied".   N)rX   r   r4   r<   s    r   IsSatisfied SatisfactionQuestion.IsSatisfied   s&    !!r   c                     [        [        U R                  5      SS5      nU R                  US9n[        R
                  " U5        g )Nr   r   )r   r   ru   r   r   r   )r!   choice_indexesr   s      r   rC   #SatisfactionQuestion._PrintQuestion   s:     3t}}-q"5N(((@MIImr   c                 L    U R                   [        U R                   5      U-
     $ )r   )ru   r   r   s     r   r   SatisfactionQuestion.Choice   s!     ==T]]+e344r   r	   N)	r   r   r   r   r   r   rC   r   r   r	   r   r   r   r      s    '5r   r   c                   `   ^  \ rS rSrSr\S 5       r SU 4S jjrS rS r	S r
S rS	 rS
rU =r$ )RatingQuestion   z"Rating question.

Attributes:
   min_answer: int, minimum acceptable value for answer.
   max_answer: int, maximum acceptable value for answer.
c                 F     U " S0 UD6$ ! [          a    [        / SQS9ef = f)N)r1   r2   r3   
min_answer
max_answerry   r	   rz   r|   s     r   r8   RatingQuestion.FromDictionary   s4    	^7^ 	! 3 	 		r   c                 F   > [         [        U ]  UUUUS9  X@l        XPl        g )N)r1   r2   r3   r4   )r   r   r   _min_max)r!   r1   r2   r3   r   r   r4   r$   s          r   r   RatingQuestion.__init__  s1     
.$(!9	 ) 
 IIr   c                 r    [         R                  " U R                  S5      n[        R                  " U5        g Nr   r   r   r-   r   r   r!   r1   s     r   rC   RatingQuestion._PrintQuestion  $    !!$..!4HIIhr   c                      [        U5      nU R                  Us=:*  =(       a    U R                  :*  $ s  $ ! [         a     gf = fr`   )r   r   r   r   r   s      r   rU   RatingQuestion.AcceptAnswer  sC    v;jYY*11		1111 s   06 6 
AAc                 j   [        XR                  5      (       a  U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R
                  UR
                  :H  =(       a    U R                  UR                  :H  $ gr`   )ra   r$   r-   r.   r/   r   r   rb   s     r   rd   RatingQuestion.__eq__  s    %((nn/ F5#5#55F,,0O0OOF ))uzz)F /3ii5::.EG
 r   c                     X:X  + $ r,   r	   rb   s     r   rg   RatingQuestion.__ne__)  ri   r   c                     [        U R                  U R                  U R                  U R                  U R
                  45      $ r,   )rk   r-   r.   r/   r   r   r<   s    r   rl   RatingQuestion.__hash__,  s:    !2!2//DIIG H Hr   )r   r   r,   )r   r   r   r   r   r   r8   r   rC   rU   rd   rg   rl   r   r&   r'   s   @r   r   r      sF     	 	 H Hr   r   c                       \ rS rSrSrSrg)NPSQuestioni1  zNet promoter score question.r	   Nr
   r	   r   r   r   r   1  s    $r   r   c                   4    \ rS rSrSrS rS r\S 5       rSr	g)FreeTextQuestioni5  zFree text question.c                 r    [         R                  " U R                  S5      n[        R                  " U5        g r   r   r   s     r   rC   FreeTextQuestion._PrintQuestion8  r   r   c                     g)zReturns True if answer is accepted, otherwise returns False.

Accepts any answer for free text question.

Args:
  answer: str, the answer to check.

Returns:
   True
Tr	   rT   s     r   rU   FreeTextQuestion.AcceptAnswer<  s     r   c                 F     U " S0 UD6$ ! [          a    [        SS/S9ef = f)Nr1   r2   ry   r	   rz   r|   s     r   r8   FreeTextQuestion.FromDictionaryI  s5    O^7^ O!:}2MNNOr   r	   N)
r   r   r   r   r   rC   rU   r   r8   r   r	   r   r   r   r   5  s%     O Or   r   )r   rn   !googlecloudsdk.command_lib.surveyr   r   googlecloudsdk.corer   r   sixr   r   r   r   with_metaclassABCMetaobjectr)   rr   r   r   r   r   r	   r   r   <module>r      s    6  A * # 
J 
% 
 
<E <W2s!!#++v6 W2tJ( JZ5. 5.;HX ;H|%. %Ox Or   