
    3&                        S r SSKJr  SSKJr  SSKJ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.    )absolute_import)division)unicode_literalsN)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__0   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)Question8   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__B   s    
 N#%="Lr   c                     g r/   r   )r$   contents     r   FromDictionaryQuestion.FromDictionaryL       r   c                     U R                   $ r/   )r0   r$   s    r   r4   Question.questionP   s    >>r   c                     U R                   $ r/   )r1   r?   s    r   r5   Question.instructionT   s    r   c                     U R                   $ r/   )r2   r?   s    r   r6   !Question.instruction_on_rejectionX   s    )))r   c                 `    U R                  5         [        R                  R                  5         g r/   )_PrintQuestionr   outflushr?   s    r   PrintQuestionQuestion.PrintQuestion\   s    GGMMOr   c                     g r/   r   r?   s    r   rF   Question._PrintQuestion`   r=   r   c                 z    U R                   (       a*  [        R                  R                  U R                   5        g g r/   )r1   r   errwriter?   s    r   PrintInstructionQuestion.PrintInstructiond   s&    	ggmmD%%& r   c                 z    U R                   (       a*  [        R                  R                  U R                   5        g g r/   )r2   r   rN   rO   r?   s    r   PrintInstructionOnRejection$Question.PrintInstructionOnRejectionh   s&    %%	ggmmD223 &r   c                     g)<Returns True if answer is accepted, otherwise returns False.Nr   r$   r7   s     r   AcceptAnswerQuestion.AcceptAnswerl   s     	r   c                     U R                   S L$ r/   )r3   r?   s    r   
IsAnsweredQuestion.IsAnsweredq   s    <<t##r   c                 R    U R                  U5      (       a  Xl        g [        S5      e)NzAnswer is invalid.)rX   r3   r   rW   s     r   AnswerQuestionQuestion.AnswerQuestiont   s$      l 455r   c                 Z    U R                  5       (       a  U R                  $ [        S5      e)NzNo answer for this question.)r[   r3   r   r?   s    r   r7   Question.answerz   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'   r0   r1   r2   r$   others     r   __eq__Question.__eq__   s`    %((nn/ P5#5#55P,,0O0OOQ r   c                     X:X  + $ r/   r   re   s     r   __ne__Question.__ne__       r   c                 Z    [        U R                  U R                  U R                  45      $ r/   )hashr0   r1   r2   r?   s    r   __hash__Question.__hash__   s+    !2!2//1 2 2r   )r3   r1   r2   r0   )NN)r   r   r   r   r   r"   abcabstractmethodr;   propertyr4   r5   r6   rI   rF   rP   rS   rX   r[   r^   r7   rg   rj   ro   r   r   r   r   r,   r,   8   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)r7   )r!   ru   r"   _choices)r$   r4   r5   r6   choicesr7   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)r4   r5   r6   ry   r%   r   	TypeErrorr   clsr:   s     r   r;   "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lenrx   r   Print)r$   question_reprs     r   rF   "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   )ziprx   r#   survey_utilIndentr    r0   )r$   r   indexmsgchoices_reprr:   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)rV   r   F)intr   rx   
ValueErrorr$   r7   
answer_ints      r   rX    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   rx   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rc   )rd   r'   r0   r1   r2   rx   re   s     r   rg   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/   )rn   r0   r1   r2   tuplerx   r?   s    r   ro   MultiChoiceQuestion.__hash__   s9    !2!2//t}}1EG H Hr   c                 ,    [        U R                  5      $ r/   )r   rx   r?   s    r   __len__MultiChoiceQuestion.__len__   s    t}}r   r   r/   )r   r   r   r   r   r"   classmethodr;   rF   r   rX   r   rg   ro   r   r   r)   r*   s   @r   ru   ru      sO      	 		43$
H r   ru   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)r[   r   r7   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   rx   r   r   r   )r$   choice_indexesr   s      r   rF   #SatisfactionQuestion._PrintQuestion   s:     3t}}-q"5N(((@MIImr   c                 L    U R                   [        U R                   5      U-
     $ )r   )rx   r   r   s     r   r   SatisfactionQuestion.Choice   s!     ==T]]+e344r   r   N)	r   r   r   r   r   r   rF   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)r4   r5   r6   
min_answer
max_answerr|   r   r}   r   s     r   r;   RatingQuestion.FromDictionary   s4    	^7^ 	! 3 	 		r   c                 F   > [         [        U ]  UUUUS9  X@l        XPl        g )N)r4   r5   r6   r7   )r!   r   r"   _min_max)r$   r4   r5   r6   r   r   r7   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   r0   r   r   r$   r4   s     r   rF   RatingQuestion._PrintQuestion  $    !!$..!4HIIhr   c                      [        U5      nU R                  Us=:*  =(       a    U R                  :*  $ s  $ ! [         a     gf = frc   )r   r   r   r   r   s      r   rX   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rc   )rd   r'   r0   r1   r2   r   r   re   s     r   rg   RatingQuestion.__eq__"  s    %((nn/ F5#5#55F,,0O0OOF ))uzz)F /3ii5::.EG
 r   c                     X:X  + $ r/   r   re   s     r   rj   RatingQuestion.__ne__,  rl   r   c                     [        U R                  U R                  U R                  U R                  U R
                  45      $ r/   )rn   r0   r1   r2   r   r   r?   s    r   ro   RatingQuestion.__hash__/  s:    !2!2//DIIG H Hr   )r   r   r/   )r   r   r   r   r   r   r;   r"   rF   rX   rg   rj   ro   r   r)   r*   s   @r   r   r      sF     	 	 H Hr   r   c                       \ rS rSrSrSrg)NPSQuestioni4  zNet promoter score question.r   Nr   r   r   r   r   r   4  s    $r   r   c                   4    \ rS rSrSrS rS r\S 5       rSr	g)FreeTextQuestioni8  zFree text question.c                 r    [         R                  " U R                  S5      n[        R                  " U5        g r   r   r   s     r   rF   FreeTextQuestion._PrintQuestion;  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   rW   s     r   rX   FreeTextQuestion.AcceptAnswer?  s     r   c                 F     U " S0 UD6$ ! [          a    [        SS/S9ef = f)Nr4   r5   r|   r   r}   r   s     r   r;   FreeTextQuestion.FromDictionaryL  s5    O^7^ O!:}2MNNOr   r   N)
r   r   r   r   r   rF   rX   r   r;   r   r   r   r   r   r   8  s%     O Or   r   )r   
__future__r   r   r   rq   !googlecloudsdk.command_lib.surveyr   r   googlecloudsdk.corer   r   sixr
   r   r   r   with_metaclassABCMetaobjectr,   ru   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   