o
    bi                     @   sx  d dl Z d dlZd dlmZmZ d dlZd dlm  mZ e	dZ
de
j de
j dZdhZdd	d
 eD Ze	de de
j de
j de
j d	Zdedeeef fddZdedeeef fddZdedeeef fddZdeeef fddZdedee fddZd efd!d"Zd#eeeef  dee fd$d%Zd&edee fd'd(Zdeeef fd)d*ZdS )+    N)DictOptionalz/([a-zA-Z0-9]([a-zA-Z0-9_.-]{0,61}[a-zA-Z0-9])?)z^(z?(\.z?)*)$in|c                 C   s   g | ]}t |qS  )reescape).0operatorr   r   L/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/label_utils.py
<listcomp>   s    r   z^!?(?:z)?\(z(?:, ?z	)*\)$|^!?$labels_jsonreturnc                 C   sf   t | }t|tstd| D ]\}}t|tstdt|ts,td| dqt| |S )Nz<The format after deserialization is not a key-value pair mapThe key is not string type.zThe value of the "z" is not string type)jsonloads
isinstancedict
ValueErroritemsstrvalidate_node_labels)r   labelskeyvaluer   r   r   parse_node_labels_json)   s   



r   
labels_strc                 C   s   i }t | dkr| dr| dr| dd } | dkr|S | d}|D ]!}|d}t |dkr6td|d	  }|d  }|||< q%t| |S )
N   " ,=   z%Label string is not a key-value pair.r   )len
startswithendswithsplitr   stripvalidate_node_label_syntax)r   r   label_pairspair	key_valuer   r   r   r   r   parse_node_labels_string9   s    


r.   pathc                 C   s   | dkri S t | d5}t|}t|tstd| D ]\}}t|ts+tdt|ts8td| dqW d    n1 sCw   Y  t| |S )Nr!   rz=The format after deserialization is not a key-value pair map.r   zThe value of "z" is not string type.)	openyaml	safe_loadr   r   r   r   r   r*   )r/   filer   r   r   r   r   r    parse_node_labels_from_yaml_fileU   s$   



r5   r   c                 C   sB   | d u rd S |   D ]}|tjrtd| dtj dq
d S )NzCustom label keys `z ` cannot start with the prefix `z+`. This is reserved for Ray defined labels.)keysr&   ray_constantsRAY_DEFAULT_LABEL_KEYS_PREFIXr   )r   r   r   r   r   r   m   s   r   r   c                 C   sr   d| v r!|  dd\}}t|dkstt|s td| dS n| }t|dks/tt|s7td| dS d S )	N/r      zInvalid label key prefix `zh`. Prefix must be a series of DNS labels separated by dots (.), not longer than 253 characters in total.?   zInvalid label key name `z`. Name must be 63 chars or less beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_),dots (.), and alphanumerics between.)rsplitr%   r   	fullmatchLABEL_PREFIX_REGEXr   LABEL_REGEX)r   prefixnamer   r   r   validate_label_keyy   s   

rB   r   c                 C   s8   | dkrd S t | dkstt| std|  dd S )Nr!   r;   zInvalid label key value `z`. Value must be 63 chars or less beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_),dots (.), and alphanumerics between.)r%   r   r=   r?   r   )r   r   r   r   validate_label_value   s   
rC   label_selectorc                 C   sR   | d u rd S |   D ]\}}t|}|r|  S |d ur&t|}|r&|  S q
d S N)r   rB   validate_label_selector_value)rD   r   r   possible_error_messager   r   r   validate_label_selector   s   rH   selectorc                 C   s2   | dkrd S t t| std|  dt dS d S )Nr!   zInvalid label selector value `zp`. The label selector value should contain optional operators and a label value. Supported operators are: ! and z. Value must be 63 chars or less beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_),dots (.), and alphanumerics between.)r   r=   LABEL_SELECTOR_REGEXr   LABEL_OPERATORS)rI   r   r   r   rF      s   rF   c                 C   sF   | d u rd S |   D ]\}}t|}|rt||d ur t| q
d S rE   )r   rB   r   rC   )r   r   r   rG   r   r   r   r*      s   r*   )r   r   typingr   r   r2   ray._private.ray_constants_privater7   compiler?   patternr>   rK   joinOPERATOR_PATTERNrJ   r   r   r.   r5   r   rB   rC   rH   rF   r*   r   r   r   r   <module>   s*    
	""