
    
                     t    S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	r	S r
S rS	 rS
 rS rS rg)zFunctions to convert attribute formats between Task Queue and Cloud Tasks.

Functions defined here are used to migrate away from soon to be deprecated
admin-console-hr superapp. Instead we will be using Cloud Tasks APIs.
    )absolute_import)division)unicode_literalsN)	constantsc                 Z   [        [        S5      (       d  0 [        l        U [        R                  ;   a  [        R                  U    $ U R                  S5      n[	        U5       H  u  p#US:X  a  M  UR                  5       X'   M!     SR                  U5      nU[        R                  U '   U$ )zTakes a 'snake_case' string and converts it to 'camelCase'.

Args:
  string: The string we want to convert.

Returns:
  The converted string. Some examples are below:
    min_backoff => minBackoff
    max_retry_duration => maxRetryDuration
processed_strings_r    )hasattrConvertStringToCamelCaser   split	enumerate
capitalizejoin)string
attributesindex	attributecamel_case_strings        :lib/googlecloudsdk/api_lib/tasks/task_queues_convertors.pyr   r   "   s     
)+>	?	?13.'999#55f==||C *#J/ez!,,.J 0 ggj)7H,,V4	    c                 f    [        U SS 5      U S   p![        U[        R                  U   -  S5      $ )a7  Converts the time based rate into its integer value in seconds.

This function converts the input float values into its seconds equivalent.
For example,
  '100/s' => 100.0
  '60/m' => 1.0

Args:
  value: The string value we want to convert.

Returns:
  A float value representing the rate on a per second basis
N	   )floatroundr   TIME_IN_SECONDS)valuefloat_valueunits      r   ConvertRater"   ;   s7     E#2J'rt	{Y66t<<a	@@r   c                    [        U [        R                  5      (       d  U $ [        R                  " SU 5      (       a%  [        U SS 5      [        R                  U S      -  $  [        U 5      nU$ ! [         a    U n U$ f = f)a  Converts the input into a float if possible.

This function converts the input float values into its seconds equivalent if
the string has any relevant time units. For example,
  '2m' => 120.0
  '1h' => 3600.0
  '8s' => 8.0
  'apples' => 'apples'

Args:
  string: The string we want to convert.

Returns:
  The input itself if it is not possible to convert it to a float value,
  the converted float value otherwise.
z^(\d+(\.\d+)?|\.\d+)[smhd]$Nr   )	
isinstancesixstring_typesrematchr   r   r   
ValueError)r   return_values     r   (CheckAndConvertStringToFloatIfApplicabler+   M   s    " 
FC,,	-	-MXX,f55	 9 9&* EEE=L 
 
 L	s   $A1 1B Bc                 @    U c  gSR                  [        U S5      5      $ )zConverts min/max backoff values to the format CT expects.

Args:
  value: A float value representing time in seconds.

Returns:
  The string representing the time with 's' appended at the end.
N{}s   )formatr   )r   s    r   ConvertBackoffSecondsr0   i   s!     ]	eE1o	&&r   c                    U R                  S5      n[        U5      S:X  a  [        R                  " SUS   05      $ [        U5      S:X  a  [        R                  " US   US   S.5      $ [	        SR                  U 5      5      e)a2  Converts target to that format that Cloud Tasks APIs expect.

Args:
  value: A string representing the service or version_dot_service.

Returns:
  An ordered dict with parsed values for service and target if it exists.

Raises:
  ValueError: If the input provided for target is not in the format expected.
.   servicer      )r4   versionz(Unsupported value received for target {})r   lencollectionsOrderedDictr)   r/   )r   targetss     r   ConvertTargetr;   w   s~     KK'\Q""Iwqz#:;;
7|q""AJ71:68 8=DDUKLLr   c                     [        U SS 5      [        R                  U S      -  nSR                  [	        U5      5      $ )a  Converts task age limit values to the format CT expects.

Args:
  value: A string value representing the task age limit. For example, '2.5m',
    '1h', '8s', etc.

Returns:
  The string representing the time to the nearest second with 's' appended
  at the end.
Nr   r-   )r   r   r   r/   int)r   time_in_secondss     r   ConvertTaskAgeLimitr?      s<     %*%	(A(A%)(LL/	c/*	++r   )__doc__
__future__r   r   r   r8   r'    googlecloudsdk.command_lib.tasksr   r%   r   r"   r+   r0   r;   r?    r   r   <module>rD      sA     '  '  	 6 
2A$8'M*,r   