File: //lib/python3.9/site-packages/ansible/plugins/shell/__pycache__/powershell.cpython-39.pyc
a
�)gp, � @ s� d dl mZmZmZ eZdZd dlZd dlZd dl Z d dl
Z
d dlZd dlm
mZ d dlZd dlmZmZ d dlmZ g d�Zddd �ZG d
d� de�ZdS )
� )�absolute_import�division�print_functionaL
name: powershell
version_added: historical
short_description: Windows PowerShell
description:
- The only option when using 'winrm' or 'psrp' as a connection plugin.
- Can also be used when using 'ssh' as a connection plugin and the C(DefaultShell) has been configured to PowerShell.
extends_documentation_fragment:
- shell_windows
N)�to_bytes�to_text)� ShellBase)Z
PowerShellz
-NoProfilez-NonInteractivez-ExecutionPolicyZUnrestricted�Errorc s� g }| r�| � d�d }| | � d�|� }| |d� } t�|�}t�d|j�}|r^d|�d� nd}|�d | �}|�� fd
d�|D �� qt d�
|��S )
z�
Takes a byte string like '#< CLIXML
<Objs...' and extracts the stream
message encoded in the XML data. CLIXML is used by PowerShell to encode
multiple objects in stderr.
s </Objs>� s <Objs Nz{(.*)}z{%s}� � z./%sSc s* g | ]"}|j �d �� kr|j�dd��qS )�SZ_x000D__x000A_r )Zattrib�get�text�replace)�.0�e��stream� �D/usr/lib/python3.9/site-packages/ansible/plugins/shell/powershell.py�
<listcomp>7 � z!_parse_clixml.<locals>.<listcomp>z
)�find�ETZ
fromstring�re�match�tag�group�findall�extendr �join) �datar �linesZend_idxZcurrent_elementZclixmlZnamespace_match� namespace�stringsr r r �
_parse_clixml! s
r% c @ s� e Zd Ze� ZdZdZdZdZdd� Z dd� Z
d d
� Zdd� Zd
d� Z
dd� Zdd� Zd*dd�Zd+dd�Zd,dd�Zdd� Zdd� Zd-d d!�Zd"d#� Zd$d%� Zd&d'� Zd.d(d)�ZdS )/�ShellModuleZ
powershellz> $null�;Tc K s dS )Nr r )�self�kwargsr r r �
env_prefixM s zShellModule.env_prefixc s: � fdd�|D �}t j|d gdd� |dd � D ��R � S )Nc s g | ]}t �� �|���qS r )�ntpath�normpath�_unquote)r �arg�r( r r r S r z)ShellModule.join_path.<locals>.<listcomp>r c S s g | ]}|� d ��qS )�\��strip)r �partr r r r X r r
)r+ r )r( �args�partsr r/ r � join_pathQ s zShellModule.join_pathc C s@ t j�|�� �}t j�|�� �\}}|�� dvr8|d S |�� S )N)�.ps1z.exer7 )�os�path�basenamer2 �splitext�lower)r( �pathname� base_name�name�extr r r �get_remote_filenameZ s
zShellModule.get_remote_filenamec C s | � |�}|�d�p|�d�S )N�/r0 )r- �endswith)r( r9 r r r �path_has_trailing_slashc s
z#ShellModule.path_has_trailing_slashc C s t d��d S )Nz'chmod is not implemented for Powershell��NotImplementedError)r( �paths�moder r r �chmodh s zShellModule.chmodc C s t d��d S )Nz'chown is not implemented for PowershellrE )r( rG �userr r r �chownk s zShellModule.chownc C s t d��d S )Nz/set_user_facl is not implemented for PowershellrE )r( rG rJ rH r r r �
set_user_facln s zShellModule.set_user_faclFc C s4 | � | �|��}|r"| �d| �S | �d| �S d S )Nz!Remove-Item '%s' -Force -Recurse;zRemove-Item '%s' -Force;��_escaper- �_encode_script)r( r9 Zrecurser r r �removeq s zShellModule.removeNc C sJ |s| j �� }| �| �|��}|r&|n| �d�}d||f }| �|�� �S )NZ
remote_tmpz�
$tmp_path = [System.Environment]::ExpandEnvironmentVariables('%s')
$tmp = New-Item -Type Directory -Path $tmp_path -Name '%s'
Write-Output -InputObject $tmp.FullName
)� __class__Z_generate_temp_dir_namerN r- Z
get_optionrO r2 )r( Zbasefile�systemrH ZtmpdirZ
basetmpdir�scriptr r r �mkdtempx s
�zShellModule.mkdtempr c C sR | � |�}|dkrd}n0|�d�r:d| �|dd � � }nd| �|� }| �|�S )N�~z Write-Output (Get-Location).Pathz~\z)Write-Output ((Get-Location).Path + '%s')r
zWrite-Output '%s')r- �
startswithrN rO )r( Zuser_home_path�usernamerS r r r �expand_user� s
zShellModule.expand_userc C s"