
    	                         S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SrS	 r " S
 S\R                  5      r " S S\5      rS rS rS rS rg)z Declarative hooks for ml speech.    N)apis)base)
exceptions)
properties)files	translatec                 r    U R                   R                  5       [        R                  R                  :X  a  gg)Nv3v3beta1)calliope_commandReleaseTrackcalliope_baseBETA)argss    4lib/googlecloudsdk/command_lib/ml/translate/hooks.py_GetApiVersionr       s+    	'')]-G-G-L-LL    c                       \ rS rSrSrSrg)Error'   zExceptions for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   '   s    #r   r   c                       \ rS rSrSrSrg)ContentFileError+   z8Error if content file can't be read and isn't a GCS URL.r   Nr   r   r   r   r    r    +   s    @r   r    c                 R   UR                   nUR                  n[        R                  " [        [        U5      5      nUR                  5       n[        R                  R                  R                  R                  5       nSR                  XqR                  5      Ul        UR                  S5      (       a^  [        R                  R                  R                  R                  5       nSR                  XqR                  UR                   5      nXl        U(       aZ  ["        R$                  R'                  U5      (       a  [(        R*                  " U5      Ul         O [-        SR                  U5      5      eX6l         UR                  S5      (       a  UR.                  Ul        Xbl        U$ )z?The hook to inject content into the language detection request.projects/{}/locations/{}modelz5projects/{}/locations/{}/models/language-detection/{}PCould not find --content-file [{}]. Content file must be a path to a local file)	mime_type)contentcontent_filer   GetMessagesModule
SPEECH_APIr   DetectLanguageRequestr   VALUEScoreproject	GetOrFailformatzoneparentIsSpecifiedr$   ospathisfiler   ReadFileContentsr    r&   mimeTypedetectLanguageRequest)	unused_instance_refr   requestr'   r(   messagesdetect_language_requestr.   r$   s	            r   UpdateRequestLangDetectionr>   /   s=   LL'"",##Jt0DE($::<""**446'-44WiiH'.	g$$,,668GCJJDJJ(E$)!	ww~~l##(-(>(>|(L%#VL13 3 '.#	k""'+~~$"9	.r   c                 0   UR                   nUR                  n[        R                  " [        [        U5      5      nUR                  5       n[        R                  R                  R                  R                  5       nSR                  XqR                  5      Ul        UR                  S5      (       a^  [        R                  R                  R                  R                  5       nSR                  XqR                  UR                   5      nXl        U(       a[  ["        R$                  R'                  U5      (       a  [(        R*                  " U5      /Ul        O"[/        SR                  U5      5      eU/Ul        UR                  S5      (       a  UR0                  Ul        UR                  S5      (       a  UR5                  UR6                  S9Ul        UR                  S5      (       a  UR8                  Ul        UR<                  Ul        Xbl         U$ )	z6The hook to inject content into the translate request.r#   r$   "projects/{}/locations/{}/models/{}r%   r&   glossary_configglossarysource_language)!r'   r(   r   r)   r*   r   TranslateTextRequestr   r,   r-   r.   r/   r0   r1   r2   r3   r$   r4   r5   r6   r   r7   contentsr    r&   r8   TranslateTextGlossaryConfigglossaryConfigrD   sourceLanguageCodetarget_languagetargetLanguageCodetranslateTextRequest)	r:   r   r;   r'   r(   r<   translate_text_requestr.   r$   s	            r   UpdateRequestTranslateTextrN   M   s   LL'"",##Jt0DE(#88:""**446'-44WiiH'.	g$$,,668G077DJJ(E#( 	ww~~l##).)?)?)M(N%#VL13 3 (/i#	k""&*nn#	'((**D4G4G*H )	'((040D0D-.2.B.B+!7	.r   c                 .   [         R                  R                  R                  R	                  5       nSR                  X1R                  5      Ul        UR                  S5      (       a,  SR                  X1R                  UR                  5      nXBl	        U$ )zBThe hook to inject content into the getSupportedLanguages request.r#   r$   r@   )
r   r,   r-   r.   r/   r0   r1   r2   r3   r$   )r:   r   r;   r.   r$   s        r   "UpdateRequestGetSupportedLanguagesrP   r   sp    ""**446'-44WiiH'.	g077DJJ(EM	.r   c                 R   [         R                  " [        [        U5      5      nUR	                  5       n[
        R                  R                  R                  R                  5       nSR                  XQR                  5      Ul        UR                  Ul        UR                  Ul        UR#                  UR%                  UR&                  S9S9Ul        [+        UR,                  R/                  5       5       VVs/ s H+  u  pgUR1                  UR3                  US9U(       a  UOSS9PM-     snnUl        UR7                  S5      (       a  UR                  R9                  [+        UR:                  R/                  5       5       VVs/ s HC  u  pgUR                  R8                  R=                  USR                  XQR                  U5      S	9PME     snnS
9Ul        UR7                  S5      (       a  [+        UR>                  R/                  5       5       VVs/ s HO  u  pgUR                  R@                  R=                  XcRC                  SR                  XQR                  U5      S9S	9PMQ     snnnUR                  RA                  US
9Ul        XBl"        U$ s  snnf s  snnf s  snnf )z<The hook to inject content into the batch translate request.r#   )outputUriPrefix)gcsDestination)inputUriN)	gcsSourcer8   modelsr@   )keyvalue)additionalProperties
glossariesz&projects/{}/locations/{}/glossaries/{}rB   )#r   r)   r*   r   BatchTranslateTextRequestr   r,   r-   r.   r/   r0   r1   r2   rD   rI   target_language_codestargetLanguageCodesOutputConfigGcsDestinationdestinationoutputConfigsortedsourceitemsInputConfig	GcsSourceinputConfigsr3   ModelsValuerV   AdditionalPropertyrZ   GlossariesValuerG   batchTranslateTextRequest)	r:   r   r;   r<   batch_translate_text_requestr.   kvadditional_propertiess	            r   UpdateRequestBatchTranslateTextrp   }   s   ##Jt0DE(!)!C!C!E""**446'-44WiiH'.484H4H1595O5O2.6.C.C,,T=M=M,N /D /P+
 ))+,., H$6$6$6$B()1t  5,. + 
h&&22 9?t{{?P?P?R8S
 9T ..::MMAHHYY+ N ,8S
 3  !' 
l## mssw  tC  tC  tI  tI  tK  mLM mLdhde ))99LL;;?FFwPYPY[\] < _ M ` mLM 
 ((884 9 6 !+ 'C#	.-.
Ms   :2JA
J
AJ#)r   r4   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r*   r   r   r    r>   rN   rP   rp   r   r   r   <module>ru      s_     ' 
 , 9 * * * 
$J $Au A<"J!r   