HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //lib/google-cloud-sdk/lib/googlecloudsdk/calliope/__pycache__/walker.cpython-312.pyc
�

�����n�dZddlmZddlmZddlmZddlmZddlmZddlm	Z	ddl
Z
Gd	�d
e�Zy)z,A module for walking the Cloud SDK CLI tree.�)�absolute_import)�division)�unicode_literals)�Any)�
console_io)�progress_trackerNc�:�eZdZdZ	d	d�Zd�Zd
d�Zd�Zd�Zd�Z	y)�Walkera=Base class for walking the Cloud SDK CLI tree.

  Attributes:
    _roots: The root elements of the CLI tree that will be walked.
    _num_nodes: The total number of nodes in the tree.
    _num_visited: The count of visited nodes so far.
    _progress_callback: The progress bar function to call to update progress.
  Nc	�N�|j�}|r8|D�cgc]}|j||���}}|D�cgc]}|s�|��	c}|_n|g|_d|_|rZt	j
d�5|jD]+}|xjd|j
d|��zz
c_�-	ddd�n:|jD]+}|xjd|j
d|��zz
c_�-d|_|xstj|_
ycc}wcc}w#1swY�4xYw)a�Constructor.

    Args:
      cli: The Cloud SDK CLI object.
      progress_callback: f(float), The function to call to update the progress
        bar or None for no progress bar.
      ignore_load_errors: bool, True to ignore command load failures. This
        should only be used when it is not critical that all data is returned,
        like for optimizations like static tab completion.
      restrict: Restricts the walk to the command/group dotted paths in this
        list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
        restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
        commands/groups. When provided here, any groups above the restrictions
        in the tree will not be loaded or visited.
    rzLoading CLI Treeg�?T)�	recursive�ignore_load_errorsN)�_TopElement�_GetSubElement�_roots�
_num_nodesr�ProgressTracker�LoadAllSubElements�_num_visitedr�DefaultProgressBarCallback�_progress_callback)	�self�cli�progress_callbackr
�restrict�top�r�roots�roots	         �%lib/googlecloudsdk/calliope/walker.py�__init__zWalker.__init__'s!��$�/�/�
�C��4<�=�H�q�t�"�"�3��*�H�e�=� %�+��1��Q��+�d�k��E�d�k��D�O���+�+�,>�?��K�K�D�
�/�/�S�4�#:�#:��1C�$;�$���/� �@�?��+�+�$����3��!8�!8��/A�"9�"
�
�	
���
�D���B�Z�B�B�	���'>��+�@�?�s�D�D�D�1;D�D$c�j�|jd�dd}|}|D]}|j|�}|r�y|S)N�.�)�split�LoadSubElement)r�top_element�path�parts�current�parts      rrzWalker._GetSubElementRsB���J�J�s�O�A�B��E��G����&�&�t�,�g�
����N�c���������dtdtfd��d����fd�	����fd��d�_d}�jD]}�|d�}�
�j	�|S)	aCalls self.Visit() on each node in the CLI tree.

    The walk is DFS, ordered by command name for reproducability.

    Args:
      hidden: Include hidden groups and commands if True.
      universe_compatible: Exclusively include commands which are marked
        universe compatible.
      restrict: Restricts the walk to the command/group dotted paths in this
        list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
        restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
        commands/groups. When provided here, parent groups will still be visited
        as the walk progresses down to these leaves, but only parent groups
        between the restrictions and the root.

    Returns:
      The return value of the top level Visit() call.
    �command�returnc�H�t|t�xr|j�S)z�Determines if a command is universe compatible.

      Args:
        command: CommandCommon command node.

      Returns:
        True if command is universe compatible.
      )�
isinstance�dict�IsUniverseCompatible)r-s r�_IsUniverseCompatiblez*Walker.Walk.<locals>._IsUniverseCompatibleos"���G�T�*�
*�
O��0L�0L�0N�Or+c�����s|j�ry�r	�|�sy�sydj|j��}�D]+}|j|�ry|s�|j|�s�+yy)aDetermines if command should be included in the walk.

      Args:
        command: CommandCommon command node.
        traverse: If True then check traversal through group to subcommands.

      Returns:
        True if command should be included in the walk.
      FTr")�IsHidden�join�GetPath�
startswith)r-�traverser'�itemr3�hiddenr�universe_compatibles    ����r�_IncludezWalker.Walk.<locals>._Includezsn�����(�(�*��	�%:�7�%C��
��
�X�X�g�o�o�'�
(�d��$��?�?�4� �������-��	�
r+c�$��|js�	j||d��|S�	j||d��}g}|jrDtj|j�D]"\}}�|�s�|j||df��$|jrFtj|j�D]$\}}�|d��s�|j||df��&t|�D]&\}}}|r
�||���	j||d���(|S)a
Walk() helper that calls self.Visit() on each node in the CLI tree.

      Args:
        node: CommandCommon tree node.
        parent: The parent Visit() return value, None at the top level.

      Returns:
        The return value of the outer Visit() call.
      F)�is_groupT)r9)r?�_Visit�commands�six�	iteritems�append�groups�sorted)
�node�parent�commands_and_groups�namer-�_r?r=�_Walkrs
       ���rrLzWalker.Walk.<locals>._Walk�s�����]�]����D�&�5��1��
��{�{�4��$�{�7�f���	
��� �]�]�4�=�=�9�M�D�'�
�g�
��&�&��g�u�'=�>�:�
��� �]�]�4�;�;�7�M�D�'�
�g��
-��&�&��g�t�'<�=�8�#)�)<�"=�
�!�W�h��
���
 �
�+�+�g�v��+�
6�	#>�
�mr+rN)F)r�boolrr�Done)	rr;r<rrHrr=r3rLs	````  @@@r�WalkzWalker.Walk[s`���(	P�s�	P�t�	P���0�@�D��
�F������T�4� �f���I�I�K��Mr+c��|xjdz
c_|j|j|jz�|j|||�S)Nr#)rrr�Visit�rrGrHr?s    rr@z
Walker._Visit�sC�����������D�-�-����@�A��:�:�d�F�H�-�-r+c��y)a�Visits each node in the CLI command tree.

    Called preorder by WalkCLI() using DFS.

    Args:
      node: group/command CommandCommon info.
      parent: The parent Visit() return value, None at the top level.
      is_group: True if node is a group, otherwise its is a command.

    Returns:
      A new parent value for the node subtree. This value is the parent arg
      for the Visit() calls for the children of this node.
    N�rRs    rrQzWalker.Visit�s��	r+c��y)z<Cleans up after all nodes in the CLI tree have been visited.NrT)rs rrNzWalker.Done�s��r+)NFN)FFN)
�__name__�
__module__�__qualname__�__doc__r rrOr@rQrNrTr+rr
r
s/���MQ�)�V�\�|.�
	� 	r+r
)
rY�
__future__rrr�typingr�googlecloudsdk.core.consolerrrB�objectr
rTr+r�<module>r^s-�� 3�&��'��2�8�
�s	�V�s	r+