
    l                     d   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddl	Z	ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlZdZedz
  ZdZd Zee_        d Zd Zd Z G d de      Z  G d de      Z! G d de      Z"d Z# G d de      Z$ G d dejJ                        Z&y)z(The gcloud interactive shell completion.    )absolute_import)division)unicode_literalsN)parser_completer)parser)generate_cli_trees)module_util)console_attr)
completion   z://c                 &   | j                   }|j                  s| j                  j                  dd       yt	        |j                  j
                        dk(  r)|j                  |j                  j
                  d          y|j                          y)zFcompletion.generate_completions override that auto selects singletons.TF)insert_common_partselect_firstr   r   N)current_buffercomplete_stateclistart_completionlencurrent_completionsapply_completioncomplete_next)eventbs     7lib/googlecloudsdk/command_lib/interactive/completer.py_GenerateCompletionsr   ,   ss     !	
			II$UK
1//0A5q'';;A>? OO    c                 "   t        j                         }|j                  d       | D ]E  }|j                  dj                  |j                  xs d|j
                  j                               G |j                  d       |j                         S )z0Pretty prints args into a string and returns it.[z({},{})z""])ioStringIOwriteformatvalue
token_typenamegetvalue)argsbufargs      r   _PrettyArgsr,   >   se    
#))C.cIIisyy0D#..2E2EFG ))C.	r   c                     t         }| j                  |      }|dk\  r0|t        t               z   }| d|dz
   g| |d j                  d      z   S | j                  d      S )zFReturns the list of component names in path, treating foo:// as a dir.r   Nr   /)_URI_SEPfindr   split)pathurisep	uri_indexns       r   _Splitr6   H   s^    &ii)!^CM!A!A#J<$qr(..---	Cr   c                 <    dj                  t        |       dd       S )z,Returns the dirname of path, '' if it's '.'.r.   Nr   )joinr6   )r2   s    r   _Dirnamer9   R   s    	&,s#	$$r   c                   "    e Zd ZdZd Zd Zd Zy)CacheArgzA completion cache arg.c                 .    || _         || _        i | _        y N)prefixcompletionsdirs)selfr>   r?   s      r   __init__zCacheArg.__init__Z   s    DK"DDIr   c                     | j                   d uS r=   )r?   rA   s    r   IsValidzCacheArg.IsValid_   s    4''r   c                 6    t         | _        d | _        i | _        y r=   )_INVALID_ARG_COMMAND_COUNTcommand_countr?   r@   rD   s    r   
InvalidatezCacheArg.Invalidateb   s    3DDDIr   N)__name__
__module____qualname____doc__rB   rE   rI    r   r   r;   r;   W   s    
(r   r;   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)CompletionCachea-  A per-arg cache of completions for the command line under construction.

  Since we have no details on the compeleted values this cache is only for the
  current command line. This means that async activities by other commands
  (creating files, instances, resources) may not be seen until the current
  command under construction is executed.

  Attributes:
    args: The list of CacheArg args holding the completion state for each arg.
    completer: The completer object.
    command_count: The completer.cli.command_count value for the current cache.
  c                 6    g | _         || _        t        | _        y r=   )r)   	completer_INVALID_COMMAND_COUNTrH   )rA   rR   s     r   rB   zCompletionCache.__init__v   s    DIDN/Dr   c                 \    | j                   | j                  j                  j                   k(  S r=   )rH   rR   r   rD   s    r   rE   zCompletionCache.IsValid{   s#    !3!3!A!AAAr   c                     | j                   |   j                         sy||   j                  j                  | j                   |   j                        S )z?Returns True if args[index] matches the cache prefix for index.T)r)   rE   r%   
startswithr>   )rA   r)   indexs      r   ArgMatchzCompletionCache.ArgMatch~   sD    99U##%;''		%(8(?(?@@r   c                 j   |r| j                         syt        |      t        | j                        kD  ryt        |      dz
  }t        |      D ]  }| j	                  ||      r y | j                  |   j                         sy||   j
                  }|j                  d      r|dd }| j                  j                  j                  j                  |       | j                  |   j                  j                  |d      \  }}|sy|| j                  |   _        || j                  |   _        n|| j                  |   j                  v r| j                  j                  j                  j                  t        |             | j                  |   j                  j                  t        |      d      \  }}|r(|| j                  |   _        || j                  |   _        | j	                  ||      sy| j                  |   j                  D cg c]  }|j!                  |      s| c}S c c}w )z@Returns the cached completions for the last arg in args or None.Nr   r.   r   NN)rE   r   r)   rangerX   r%   endswithrR   debugdirtextr@   getr>   r?   r9   rV   )	rA   r)   last_arg_indexiaparentr>   r?   cs	            r   LookupzCompletionCache.Lookup   s   
 t||~
4y3tyy>! Y]N>"]]4# # 99^$,,. 	^""Azz#"vf
nn##F+ IIn5::>>v?KMfk)/dii&.9dii+	
dii',,	,
nn##HQK0 IIn5::>>x{?KMfk	+1		.!(0;		.!- ==~. yy0<<P<!QA<PPPs   H0)H0c                    | j                   j                  j                  | _        t        |      dz
  }t	        |      D ]}  }|t        | j
                        k\  r3| j
                  j                  t        ||   j                  d             N| j                  ||      ra| j
                  |   j                           ||   j                  }|t        | j
                        k(  r%| j
                  j                  t        ||             | j
                  |   j                         r9|j                  | j
                  |   j                        r|j                  d      r|j                  d      r| j
                  |   j                  sL| j
                  |   j                  | j
                  |   j                   f| j
                  |   j                  d<   ||f| j
                  |   j                  |dd <   |r!d|d   dd v rd|vri }|D ]  }|j                  d      r|dd }d}nd}t#        |      }	|r|	dxx   |z  cc<   t	        t        |	            D ]h  }dj%                  |	d|       }
|
|vrg ||
<   dj%                  |	d|dz          }|j                  d      r|dz  }|||
   vsU||
   j                  |       j  t'        j(                  |      D ];  \  }
}|
}|j                  d      r|dz  }||f| j
                  |   j                  |
<   = n(|| j
                  |   _        || j
                  |   _        t	        |dz   t        | j
                              D ]  }| j
                  |   j                          ! y)z-Updates completions for the last arg in args.r   Nr.    r   r   z:/)rR   r   rH   r   r[   r)   appendr;   r%   rX   rI   rE   rV   r>   r\   r@   r?   r6   r8   six	iteritems)rA   r)   r?   ra   rb   rc   r@   compmarkpartsdre   markeds                r   UpdatezCompletionCache.Update   s   ++99DY]N>"	
c$))n			$q'--67}}T1%		!! # 	^""A TYY'
iix;/0 IIn%--/LL>299:	

3	
Cyy(-- ii'..ii'3305$))N
#
(
(
, 34[1A		.!&&q"v. sk!nSb11cld$==cr$$$t
)t
)s5z"AhhuRay!!d]DG%Q-($]]4 CKDa GNN4  # $ --%$!Q??4 
C-&,2AI		.!&&q)	 & *+dii&.9dii+ >A%s499~6
iil 7r   N)	rJ   rK   rL   rM   rB   rE   rX   rf   rq   rN   r   r   rP   rP   h   s%    0
BA3QjA r   rP   c                   @    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d	 Zd
 Zy)Spinnera  A Spinner to show when completer takes too long to respond.

  Some completer calls take too long, specially those that fetch remote
  resources. An instance of this class can be used as a context manager wrapping
  slow completers to get spinmarks while the completer fetches.

  Attributes:
    _done_loading: Boolean flag indicating whether ticker thread is working.
    _set_spinner: Function reference to InteractiveCliCompleter's spinner
      setter.
    _spin_marks: List of unicode spinmarks to be cycled while loading.
    _ticker: Thread instance that handles displaying the spinner.
    _ticker_index: Integer specifying the last iteration index in _spin_marks.
    _TICKER_INTERVAL: Float specifying time between ticker rotation in
      milliseconds.
    _ticker_length: Integer spcifying length of _spin_marks.
    _TICKER_WAIT: Float specifying the wait time before ticking in milliseconds.
    _TICKER_WAIT_CHECK_INTERVAL: Float specifying interval time to break wait
      in milliseconds.
  d      
   c                     d| _         t        j                         j                         j                  | _        d | _        d| _        t        | j
                        | _	        || _
        y )NFr   )_done_loadingr
   GetConsoleAttrGetProgressTrackerSymbols
spin_marks_spin_marks_ticker_ticker_indexr   _ticker_length_set_spinner)rA   set_spinners     r   rB   zSpinner.__init__  sU    D#224	"	"	$ZZ 	DLDd../D#Dr   c                     t         j                  j                  |dz          t         j                  j                          y)z0Marks spin_mark on stdout and moves cursor back.N)sysstdoutr#   flush)rA   	spin_marks     r   _MarkzSpinner._Mark!  s)    JJY%&JJr   c                     | j                  d       d| _        | j                  r| j                  j                          yy)z2Erases last spin_mark and joins the ticker thread. TN)r   rx   r}   r8   rD   s    r   StopzSpinner.Stop&  s1    JJsOD||
ll r   c                    t        t        j                  t        j                  z        D ]6  }t	        j
                  t        j                  dz         | j                  s6 n | j                  s| j                  | j                     }| j                  |       | j                  dz   | j                  z  | _        t	        j
                  t        j                  dz         | j                  s~yy)z<Waits for _TICKER_WAIT and then starts printing the spinner.g     @@r   N)r[   rs   _TICKER_WAIT_TICKER_WAIT_CHECK_INTERVALtimesleeprx   r|   r~   r   r   _TICKER_INTERVAL)rA   _r   s      r   _TickerzSpinner._Ticker-  s    7''7+N+NNO
jj44V;<			 P   ""4#5#56i
jj ..2d6I6IId
jj))&01	   r   c                     | j                  |        t        j                  | j                        | _        | j                  j                          | S )N)target)r   	threadingThreadr   r}   startrD   s    r   	__enter__zSpinner.__enter__9  s;    d##4<<8DLLLKr   c                 F    | j                          | j                  d        y r=   )r   r   rA   r)   s     r   __exit__zSpinner.__exit__?  s    IIKdr   N)rJ   rK   rL   rM   r   r   r   rB   r   r   r   r   r   rN   r   r   rs   rs      s8    * , "$

2r   rs   c                 L   i }d}| D ]  }|j                   t        j                  j                  k(  r6|j                  j                  t        j                        }|j                  }n|j                   t        j                  j                  k(  rT|j                  j                  t        j                        }|r(|j                  d      r|dd }|j                  dd      }|s|j                   t        j                  j                  k(  r|j                  }n|||<    |S )z4Returns a namespace dict given parsed CLI tree args.Nz--   -r   )r&   r   ArgTokenType
POSITIONALtreer`   LOOKUP_NAMEr%   FLAGrV   replaceFLAG_ARG)r)   	namespacer'   r+   r%   s        r   _NameSpaceDictr   D  s    )	$c
~~,,777XX\\&,,-diie	6..33	3XX\\&,,-d	??4 ab$||C%	6..77	7iieIdO# $ 
r   c                       e Zd ZdZdZd Zy)ModuleCachea  A local completer module cache item to minimize intra-command latency.

  Some CLI tree positionals and flag values have completers that are specified
  by module paths. These path strings point to a completer method or class that
  can be imported at run-time. The ModuleCache keeps track of modules that have
  already been imported, the most recent completeion result, and a timeout for
  the data. This saves on import lookup, and more importantly, repeated
  completion requests within a short window. Users really love that TAB key.

  Attributes:
    _TIMEOUT: Newly updated choices stale after this many seconds.
    completer_class: The completer class.
    coshell: The coshell object.
    choices: The cached choices.
    stale: choices stale after this time.
  <   c                 X    || _         d | _        d| _        t        j                  | _        y Nr   )completer_classchoicesstaler   _TIMEOUTtimeout)rA   r   s     r   rB   zModuleCache.__init__q  s%    *DDLDJ''DLr   N)rJ   rK   rL   rM   r   rB   rN   r   r   r   r   ]  s    " ((r   r   c                   ~    e Zd ZdZ	 	 	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zedd       Zy)InteractiveCliCompletera  A prompt_toolkit interactive CLI completer.

  This is the wrapper class for the get_completions() callback that is
  called when characters are added to the default input buffer. It's a bit
  hairy because it maintains state between calls to avoid duplicate work,
  especially for completer calls of unknown cost.

  cli.command_count is a serial number that marks the current command line in
  progress. Some of the cached state is reset when get_completions() detects
  that it has changed.

  Attributes:
    cli: The interactive CLI object.
    coshell: The interactive coshell object.
    debug: The debug object.
    empty: Completion request is on an empty arg if True.
    hidden: Complete hidden commands and flags if True.
    last: The last character before the cursor in the completion request.
    manpage_generator: The unknown command man page generator object.
    module_cache: The completer module path cache object.
    parsed_args: The parsed args namespace passed to completer modules.
    parser: The interactive parser object.
    prefix_completer_command_count: If this is equal to cli.command_count then
      command PREFIX TAB completion is enabled. This completion searches PATH
      for executables matching the current PREFIX token. It's fairly expensive
      and volumninous, so we don't want to do it for every completion event.
    _spinner: Private instance of Spinner used for loading during
      ArgCompleter.
  Nc                    t        |       | _        || _        || _        || _        || _        || _        i | _        || _        || _	        d| _
        d | _        d| _        t        j                  j                  d       | j!                          y )NFrh   T)rP   	arg_cacher   coshellr]   hiddenmanpage_generatormodule_cacher   parsed_argsempty_spinnerlastr   CliTreeGeneratorMemoizeFailuresreset)rA   r   r   r]   interactive_parserr)   r   r   s           r   rB   z InteractiveCliCompleter.__init__  s}     %T*DNDHDLDJDK.DD$DKDDJDMDI''77=JJLr   c                     | j                          | j                  r"| j                  j                          d| _        yy)z?Resets any cached state for the current command being composed.N)DisableExecutableCompletionsr   r   rD   s    r   r   zInteractiveCliCompleter.reset  s1    %%'}}
mmdm r   c                     || _         y)z'Sets and Unsets current spinner object.N)r   )rA   spinners     r   
SetSpinnerz"InteractiveCliCompleter.SetSpinner  s	    DMr   c                 H    | j                   | j                  j                  k(  S )zEReturns True if command prefix args should use executable completion.)prefix_completer_command_countr   rH   rD   s    r   DoExecutableCompletionsz/InteractiveCliCompleter.DoExecutableCompletions  s    ..$((2H2HHHr   c                     t         | _        y)z2Disables command prefix arg executable completion.N)rS   r   rD   s    r   r   z4InteractiveCliCompleter.DisableExecutableCompletions  s
    *@D'r   c                 :    | j                   j                  | _        y)z1Enables command prefix arg executable completion.N)r   rH   r   rD   s    r   EnableExecutableCompletionsz3InteractiveCliCompleter.EnableExecutableCompletions  s    *.((*@*@D'r   c                 t    | j                    xr* |d   j                  t        j                  j                  k(  S )zCReturns True if the input buffer cursor is in a command prefix arg.r   )r   r&   r   r   PREFIXr   s     r   IsPrefixArgz#InteractiveCliCompleter.IsPrefixArg  s.    zz>Od2h11V5H5H5O5OOOr   c                     | j                   r/|j                  t        j                  d      j	                  d      S |j                  t        j
                        S )z@Returns True if the info for a command, group or flag is hidden.rh   z--no-)r   r`   r   r   rV   LOOKUP_IS_HIDDEN)rA   infos     r   IsSuppressedz$InteractiveCliCompleter.IsSuppressed  s@    {{XXf(("-88AA88F++,,r   c              #     K   | j                   j                  j                         j                  dj	                  | j
                  j                  |j                  rdnd             |j                  s>|j                  r2| j                         r| j                          y| j                          y| j                  j                  |j                        }|sy| j                  | j                  | j                   | j"                  f}| j%                  |      r)| j                         s|j                  r| j"                  f}|j                  r|j                  d   nd| _        | j&                  j)                         | _        || _        | j                   j&                  j                  | j&                         | j                   j.                  j                  t1        |             |D ]  } ||      \  }}|| j                   j3                  |j4                        j                         j                  t7        t9        |                   ||D ]  }|   yt;        |      D ]  }t=        j>                  ||         y yw)zYields the completions for doc.

    Args:
      doc: A Document instance containing the interactive command line to
           complete.
      event: The CompleteEvent that triggered this completion.

    Yields:
      Completion instances for doc.
    z@{}:{}explicitimplicitNr   rh   )start_position) r]   tabscountr_   r$   r   rH   completion_requestedtext_before_cursorr   r   r   r   ParseCommandCommandCompleterFlagCompleterPositionalCompleterInteractiveCompleterr   r   isspacer   r   tokensr,   tagrJ   r   listsortedr   
Completion)	rA   docr   r)   
completersrR   r   offsetchoices	            r   get_completionsz'InteractiveCliCompleter.get_completions  s     	JJOO  00
j"B C !!e&@&@		%	%	'))+  	((* ;;##C$:$:;D
 	  !!	J $$&%*D*D--/j.1.D.D&&r*"DI""$DJDJJJOO#JJ;t,-
  	!$ogv	
jjnnY''(..055c$w-6HI	F, 
  WoF%%fVD
D &  s   JJ
c                 B   |d   }|j                   j                  d      ry| j                  |      r$| j                  j                  }|j                   }n|j
                  t        j                  j                  t        j                  j                  fv rM| j                  sAt        |      dkD  r|d   j                  n| j                  j                  }|j                   }nL|j
                  t        j                  j                  k(  r | j                  sg dfS |j                  }d}n|j
                  t        j                  j                  k(  r|j                   }| j                  r||szt        |      dk(  rl|d   j                   r]t        j                  |d   j                         }|sy|| j                  j                  t        j                      |d   j                   <   nJt        |      dkD  r:|d   j
                  t        j                  j                  k(  r|d   j                  }nyyt#        j$                  |t        j                            D cg c])  \  }}|j                  |      r| j'                  |      s|+ }}}|r|t        |       fS yc c}}w )	a  Returns the command/group completion choices for args or None.

    Args:
      args: The CLI tree parsed command args.

    Returns:
      (choices, offset):
        choices - The list of completion strings or None.
        offset - The completion prefix offset.
    r   r   r   r   r   rh   r   )r%   rV   r   r   rootr&   r   COMMANDGROUPr   r   r   UNKNOWNr   r   LoadOrGenerateLOOKUP_COMMANDSrj   rk   r   )rA   r)   r+   noder>   kvr   s           r   r   z(InteractiveCliCompleter.CommandCompleter  s    r(C
yyC 			$	 [[dyyf	F//77"//557 
7?Czz "$i!mT"X]]1A1Adyyf	6..44	4ZZ1uXXdf	6..66	6yyf

 
 
d)q.T!W]]!00a?BF//0a?t9q=T"X00F4G4G4M4MMBx}}  ]]40F0F+GH EHTQ,,v&t/@/@/C HG Es6{l""Es   .Jc                 (   |j                  t        j                        }|rr|j                  t        j                  i       j                  t        j                  g       }|D cg c]  }|j                  |      s||vs| }}|t        |       fS |s| j                  j                  sg dfS |j                  t        j                        }|sg dfS | j                  j                  |      }	|	s-t        t        j                  |            }	|	| j                  |<   |}
t        |	j                  t               s|	j                  |
      |	_        n*|	j$                  t'        j&                         k  r| j(                  j*                  }i | j(                  _        | j(                  j*                  j-                  |       | j(                  j*                  j-                  t/        |             t1        j2                  |	j                  | j(                        }t5        | j6                        5   |d      |	_        ddd       || j(                  _        t'        j&                         |	j8                  z   |	_        |j                  t        j:                        dk(  r|j=                  d      }|d   }
|	j"                  sg dfS |	j"                  D cg c]  }|j                  |
      s| c}t        |
       fS c c}w # 1 sw Y   xY wc c}w )	a`  Returns the flag or positional completion choices for arg or [].

    Args:
      args: The CLI tree parsed command args.
      arg: The flag or positional argument.
      value: The (partial) arg value.

    Returns:
      (choices, offset):
        choices - The list of completion strings or None.
        offset - The completion prefix offset.
    r   r>   )r   rh   Nr   ,r   )r`   r   LOOKUP_CHOICESLOOKUP_ATTRLOOKUP_HIDDEN_CHOICESrV   r   r   r   LOOKUP_COMPLETERr   r   r	   ImportModule
isinstancer   typer   r   r   r   __dict__updater   r   ArgumentCompleterrs   r   r   LOOKUP_TYPEr1   )rA   r)   r+   r%   r   hidden_choicesr   static_choicesmodule_pathcacher>   old_dictrR   rn   s                 r   ArgCompleterz$InteractiveCliCompleter.ArgCompleterN  s|    ggf++,Gwwv1126::

&
&,n QU 38O!W  Qc%j[((88Ul''&112KUl !!+.E+22;?@e',d$Fe++T2++6+:em	tyy{	"!!**h"$d
&&x0
&&~d';<"44


&&(i 4??#!, $"*dIIK%--/ek
wwv!!"f,kk#eRyf==Ul}}=}!V(<A}=F|KKIQ6 $# >s*   $K>;K> K>0LL+LLc                    |d   }|j                   t        j                  j                  k(  r|d   j                   t        j                  j                  k(  r^|j
                  s| j                  dv s|j
                  r8| j                  s,|d   j                  }| j                  |||j
                        S |j                   t        j                  j                  k(  rs| j                  si }t        |      D ]J  }|j                  st        j                  |j                  v s-|j                  t        j                     } n t        j                  |      D cg c]B  \  }}||j
                  k7  r.|j                  |j
                        r| j                  |      s|D }}}|r3|j!                  |j
                         |t#        |j
                         fS |j                  }|j%                  t        j&                        dk7  rG| j                  ||d      \  }}	| j                  s!| j                  dk7  r|D 
cg c]  }
d|
z   	 }}
||	fS y	|j
                  j                  d      rt        j                  |j                  t        j                           D cg c]3  \  }}|j                  |j
                        r| j                  |      s|5 c}}t#        |j
                         fS y	c c}}w c c}
w c c}}w )
a  Returns the flag completion choices for args or None.

    Args:
      args: The CLI tree parsed command args.

    Returns:
      (choices, offset):
        choices - The list of completion strings or None.
        offset - The completion prefix offset.
    r   r   )r   =boolrh   r  r   r   r   )r&   r   r   r   r   r%   r   r   r   r  reversedLOOKUP_FLAGSrj   rk   rV   r   ri   r   r`   r  )rA   r)   r+   flagflagsrc   r   r   r?   r   re   s              r   r   z%InteractiveCliCompleter.FlagCompleter  su    r(C&--666Rv22777YY499
2	4::"X]]dtT39955	6..33	3ZZ $AVV++qvv5FF6../E   &)]]5%9 1%9TQsyy.||CII.,,Q/ %9 1 


SYY
's399~o-
- XXd	&$$	%	/"//dB?Vzzdii3.*56+Qq++6F""  
		c	"MM#((63F3F*GH (HDAqcii(##A& H (*-cii.9 9 /1 7
(s   AK1=K78K<c                     |d   }|j                   t        j                  j                  k(  r'| j	                  ||j
                  |j                        S y)a	  Returns the positional completion choices for args or None.

    Args:
      args: The CLI tree parsed command args.

    Returns:
      (choices, offset):
        choices - The list of completion strings or None.
        offset - The completion prefix offset.
    r   r   )r&   r   r   r   r  r   r%   )rA   r)   r+   s      r   r   z+InteractiveCliCompleter.PositionalCompleter  sE     r(C
~~,,777tSXXsyy99r   c                 x   | j                   rR|d   j                  rC|dd }|j                  t        j                  dt        j
                  j                  d             | j                  j                  |      }|s| j                         xr | j                  |      }| j                  j                  s|sy|D cg c]  }|j                   }}t        | j                        5  | j                  j!                  ||      }ddd       | j"                  j$                  j'                          |sy| j                  j)                  ||       n$| j"                  j*                  j'                          |d   j                  }t-        |       }	 t-        t0        j2                  j5                  |            }t6        }	|d   j9                  |	      }
|
dkD  r|s|
t-        |	      z   }g }t-        |      dk7  }|D ]*  }| j;                  ||||      }|s|j                  |       , |dfS c c}w # 1 sw Y   -xY w)a
  Returns the interactive completion choices for args or None.

    Args:
      args: The CLI tree parsed command args.

    Returns:
      (choices, offset):
        choices - The list of completion strings or None.
        offset - The completion prefix offset.
    r   Nrh   rZ   r   r   r   )r   r%   ri   r   ArgTokenr   r   r   rf   r   r   r   r   rs   r   r   GetCompletionsr]   r`   r   rq   hitr   rV   osr2   dirnamer/   r0   MakePathCompletion)rA   r)   r?   r>   r+   commandr   r   chopuri_sepuri_sep_indexresultstrip_trailing_slashre   path_completions                  r   r   z,InteractiveCliCompleter.InteractiveCompleter  s    zzd2hnn!Wd
kk&//"f&9&9&A&A4HI ..''-K ++-H$2B2B42HfZZ,,V '++dsdg+4??#ll11'&1I $
jjnn
nnD+.
jjnn8>>D$iZF  rwwt$%DGN''0Mqs7|+ F{+q0//
VT/1o	o&	 
 4<S ,##s   <H*&H//H9c                     |}|r||d j                  d      }|sy|r&|j                  t              s|j                  d      }|syt	        j
                  |||      S )a  Returns the Completion object for a file/uri path completion value.

    Args:
      value: The file/path completion value string.
      offset: The Completion object offset used for dropdown display.
      chop: The minimum number of chars to chop from the dropdown items.
      strip_trailing_slash: Strip trailing '/' if True.

    Returns:
      The Completion object for a file path completion value or None if the
      chopped/stripped value is empty.
    Nr.   )displayr   )lstripr\   r/   rstripr   r   )clsr%   r   r  r   r#  s         r   r  z*InteractiveCliCompleter.MakePathCompletion  s_     G%%c*gENN8$<ll3e  OOr   )NNNNNFT)T)rJ   rK   rL   rM   rB   r   r   r   r   r   r   r   r   r   r  r   r   r   classmethodr  rN   r   r   r   r   x  sz    < 48:?!%$IAAP-DL<|6Lp6p$IV P Pr   r   )'rM   
__future__r   r   r   r!   r  r   r   r   googlecloudsdk.callioper   &googlecloudsdk.command_lib.interactiver   googlecloudsdk.command_lib.metar   googlecloudsdk.corer	   googlecloudsdk.core.consoler
   prompt_toolkitr   rj   rS   rG   r/   r   generate_completionsr,   r6   r9   objectr;   rP   rs   r   r   	Completerr   rN   r   r   <module>r2     s     / &  ' 	 	 
   4 9 > + 4 % 
  3a7  #7
 %
v "S f S lCf CL2(& (6{Pj22 {Pr   