File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/dockermod/translate/__pycache__/helpers.cpython-310.pyc
Back
o ;j�% � @ s� d Z ddlZddlZddlZddlmZ e� Zd)dd�Z d*d d �Z dd� Zd d� Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd+d"d#�Zd,d%d&�Zd'd(� ZdS )-z\ Functions to translate input in the docker CLI format to the format desired by by the API. � N)�SaltInvocationError�,���c C s dd� | � ||�D �S )Nc S � g | ]}|� � �qS � ��strip��.0�xr r �Z/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/dockermod/translate/helpers.py� <listcomp> � zsplit.<locals>.<listcomp>)�split)�item�sep�maxsplitr r r r � r �tcpc C sn z | � d�\} }}W n ty Y nw |r|}z|�� dkr&t| �dfW S W t| �S ty6 Y t| �S w )a` Given a port number and protocol, returns the port definition expected by docker-py. For TCP ports this is simply an integer, for UDP ports this is (port_num, 'udp'). port_num can also be a string in the format 'port_num/udp'. If so, the "proto" argument will be ignored. The reason we need to be able to pass in the protocol separately is because this function is sometimes invoked on data derived from a port range (e.g. '2222-2223/udp'). In these cases the protocol has already been stripped off and the port range resolved into the start and end of the range, and get_port_def() is invoked once for each port number in that range. So, rather than munge udp ports back into strings before passing them to this function, the function will see if it has a string and use the protocol from it if present. This function does not catch the TypeError or ValueError which would be raised if the port number is non-numeric. This function either needs to be run on known good input, or should be run within a try/except that catches these two exceptions. �/Zudp)� partition�AttributeError�lower�int)Zport_num�proto�_Zport_num_protor r r �get_port_def s ����r c C s� t | t�r | | fS z(dd� t| d�D �}t|�dkr!|d }}n|\}}||kr-td��W ||fS ttfyY } zt|�dkrKd�||�}t|��d| � d �}t|��d }~ww )z� Given a port number or range, return a start and end to that range. Port ranges are defined as a string containing two numbers separated by a dash (e.g. '4505-4506'). A ValueError will be raised if bad input is provided. c S s g | ]}t |��qS r )r r r r r r C r z"get_port_range.<locals>.<listcomp>�-� r zstart > endzFStart of port range ({}) cannot be greater than end of port range ({})�'z)' is non-numeric or an invalid port rangeN)� isinstancer r �len� ValueError� TypeError�str�format)Zport_def�compsZrange_startZ range_end�exc�msgr r r �get_port_range7 s* ������r) c O s� |� dt�}t|�}t| �} t| �D ]T\}}t|t�sfdd� |�d�D �}t|�}||k rE|tu r:td� |||���|� |g|| � n||kr]td� |||tu rV|���d|� ����tt||��| |<