Ë
    9ài¶  ã                   óX   — d dl Z d dlZd dlmZ ddlmZmZmZmZ ddl	m
Z
  G d„ d«      Zy)é    N)Úerrorsé   )ÚMETAFILEÚget_current_context_nameÚget_meta_dirÚ#write_context_name_to_docker_config)ÚContextc                   óž   — e Zd ZdZ edd«      Ze	 	 dd„«       Zedd„«       Zed„ «       Z	ed„ «       Z
edd	„«       Zed
„ «       Zedd„«       Zy)Ú
ContextAPIzfContext API.
    Contains methods for context management:
    create, list, remove, get, inspect.
    ÚdefaultÚswarmNc                 ó:  — |st        j                  d«      ‚|dk(  rt        j                  d«      ‚t        j                  |«      }|rt        j
                  |«      ‚d}|r|dk7  r|}t        ||«      }|j                  |||||¬«       |j                  «        |S )aR  Creates a new context.
        Returns:
            (Context): a Context object.
        Raises:
            :py:class:`docker.errors.MissingContextParameter`
                If a context name is not provided.
            :py:class:`docker.errors.ContextAlreadyExists`
                If a context with the name already exists.
            :py:class:`docker.errors.ContextException`
                If name is default.

        Example:

        >>> from docker.context import ContextAPI
        >>> ctx = ContextAPI.create_context(name='test')
        >>> print(ctx.Metadata)
        {
            "Name": "test",
            "Metadata": {},
            "Endpoints": {
                "docker": {
                    "Host": "unix:///var/run/docker.sock",
                    "SkipTLSVerify": false
                }
            }
        }
        Únamer   z$"default" is a reserved context nameÚdockerr   )Úskip_tls_verifyÚdef_namespace)r   ÚMissingContextParameterÚContextExceptionr	   Úload_contextÚContextAlreadyExistsÚset_endpointÚsave)	Úclsr   ÚorchestratorÚhostÚtls_cfgÚdefault_namespacer   ÚctxÚendpoints	            úS/home/factor_ks/STREAMA2026/venv/lib/python3.12/site-packages/docker/context/api.pyÚcreate_contextzContextAPI.create_context   sª   € ñ> Ü×0Ñ0°Ó8Ð8Ø�9ÒÜ×)Ñ)Ø6ó8ð 8ä×"Ñ" 4Ó(ˆÙÜ×-Ñ-¨dÓ3Ð3ØˆÙ˜L¨GÒ3Ø#ˆHÜ�d˜LÓ)ˆØ×ÑØ�d˜GØ+Ø+ð 	ô 	-ð 	�‰Œ
Øˆ
ó    c                 óf   — |s
t        «       }|dk(  r| j                  S t        j                  |«      S )aþ  Retrieves a context object.
        Args:
            name (str): The name of the context

        Example:

        >>> from docker.context import ContextAPI
        >>> ctx = ContextAPI.get_context(name='test')
        >>> print(ctx.Metadata)
        {
            "Name": "test",
            "Metadata": {},
            "Endpoints": {
                "docker": {
                "Host": "unix:///var/run/docker.sock",
                "SkipTLSVerify": false
                }
            }
        }
        r   )r   ÚDEFAULT_CONTEXTr	   r   )r   r   s     r    Úget_contextzContextAPI.get_contextH   s4   € ñ, Ü+Ó-ˆDØ�9ÒØ×&Ñ&Ð&Ü×#Ñ# DÓ)Ð)r"   c           
      óê  — g }t        j                  t        «       «      D ]k  \  }}}||z   D ]]  }|t        k(  sŒ	 t	        j
                  t        t         j                  j                  ||«      «      «      }|j                  |d   «       Œ_ Œm | j                  g}|D ]&  }	|j                  t        j                  |	«      «       Œ( |S # t        $ r!}t        j                  d|› d|› �«      |‚d}~ww xY w)zÆContext list.
        Returns:
            (Context): List of context objects.
        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        ÚNamezFailed to load metafile z: N)ÚosÚwalkr   r   ÚjsonÚloadÚopenÚpathÚjoinÚappendÚ	Exceptionr   r   r$   r	   r   )
r   ÚnamesÚdirnameÚdirnamesÚfnamesÚfilenameÚdataÚeÚcontextsr   s
             r    r8   zContextAPI.contextsd   sô   € ð ˆÜ)+¯©´³Ó)@ò 
	!Ñ%ˆG�X˜vØ" XÑ-ò 	!�ØœxÓ'ð!Ü#Ÿy™yÜ ¤§¡§¡¨g°xÓ!@ÓAó C˜àŸ™ T¨&¡\Õ2ñ	!ð
	!ð ×'Ñ'Ð(ˆØò 	8ˆDØ�O‰OœG×0Ñ0°Ó6Õ7ð	8àˆøô %ò !Ü$×5Ñ5Ø6°x°jÀÀ1À#ÐFóà ð!ûð!ús   ºACÃ	C2ÃC-Ã-C2c                 ó"   — | j                  «       S )z]Get current context.
        Returns:
            (Context): current context object.
        )r%   )r   s    r    Úget_current_contextzContextAPI.get_current_context   s   € ð �‰Ó Ð r"   c                 óž   — | j                  |«      }|st        j                  |«      ‚t        |«      }|rt        j                  d|› �«      ‚y )NzFailed to set current context: )r%   r   ÚContextNotFoundr   r   )r   r   r   Úerrs       r    Úset_current_contextzContextAPI.set_current_context‡   sS   € à�o‰o˜dÓ#ˆÙÜ×(Ñ(¨Ó.Ð.ä1°$Ó7ˆÙÜ×)Ñ)Ø1°#°Ð7ó9ð 9ð r"   c                 ó  — |st        j                  d«      ‚|dk(  rt        j                  d«      ‚t        j                  |«      }|st        j
                  |«      ‚|t        «       k(  rt        d«       |j                  «        y)aY  Remove a context. Similar to the ``docker context rm`` command.

        Args:
            name (str): The name of the context

        Raises:
            :py:class:`docker.errors.MissingContextParameter`
                If a context name is not provided.
            :py:class:`docker.errors.ContextNotFound`
                If a context with the name does not exist.
            :py:class:`docker.errors.ContextException`
                If name is default.

        Example:

        >>> from docker.context import ContextAPI
        >>> ContextAPI.remove_context(name='test')
        >>>
        r   r   z#context "default" cannot be removedN)	r   r   r   r	   r   r<   r   r   Úremove©r   r   r   s      r    Úremove_contextzContextAPI.remove_context’   sw   € ñ* Ü×0Ñ0°Ó8Ð8Ø�9ÒÜ×)Ñ)Ø5ó7ð 7ä×"Ñ" 4Ó(ˆÙÜ×(Ñ(¨Ó.Ð.ØÔ+Ó-Ò-Ü/°Ô5Ø�
‰
�r"   c                 óÀ   — |st        j                  d«      ‚|dk(  r| j                  «       S t        j                  |«      }|st        j
                  |«      ‚ |«       S )a  Remove a context. Similar to the ``docker context inspect`` command.

        Args:
            name (str): The name of the context

        Raises:
            :py:class:`docker.errors.MissingContextParameter`
                If a context name is not provided.
            :py:class:`docker.errors.ContextNotFound`
                If a context with the name does not exist.

        Example:

        >>> from docker.context import ContextAPI
        >>> ContextAPI.remove_context(name='test')
        >>>
        r   r   )r   r   r$   r	   r   r<   rA   s      r    Úinspect_contextzContextAPI.inspect_context³   sZ   € ñ& Ü×0Ñ0°Ó8Ð8Ø�9ÒØ×&Ñ&Ó(Ð(Ü×"Ñ" 4Ó(ˆÙÜ×(Ñ(¨Ó.Ð.á‹uˆr"   )NNNNF)N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r$   Úclassmethodr!   r%   r8   r:   r>   rB   rD   © r"   r    r   r      s§   „ ññ ˜i¨Ó1€Oàà=AØ49ò/ó ð/ðb ò*ó ð*ð6 ñó ðð4 ñ!ó ð!ð ò9ó ð9ð ñó ðð@ òó ñr"   r   )r*   r(   r   r   Úconfigr   r   r   r   Úcontextr	   r   rJ   r"   r    ú<module>rM      s)   ðÛ Û 	å ÷ó õ ÷ò r"   