
    >Tf                     $    d dl Z dZdZddZd ZdS )    N)
naturalizenaturalize_interfacez(^(?P<type>[^\d\.:]+)?)((?P<slot>\d+)/)?((?P<subslot>\d+)/)?((?P<position>\d+)/)?((?P<subposition>\d+)/)?((?P<id>\d+))?(:(?P<channel>\d+))?(\.(?P<vc>\d+))?(?P<remainder>.*)$   c                 &   | s| S g }t          j        d|           D ]W}|                                r*|                    |                    |d                     @|r|                    |           Xd                    |          }|d|         S )aY  
    Take an alphanumeric string and prepend all integers to `integer_places` places to ensure the strings
    are ordered naturally. For example:

        site9router21
        site10router4
        site10router19

    becomes:

        site00000009router00000021
        site00000010router00000004
        site00000010router00000019

    :param value: The value to be naturalized
    :param max_length: The maximum length of the returned string. Characters beyond this length will be stripped.
    :param integer_places: The number of places to which each integer will be expanded. (Default: 8)
    z(\d+)0 N)resplitisdigitappendrjustjoin)value
max_lengthinteger_placesoutputsegmentrets         7/var/www/html/netbox-4.1.3/netbox/utilities/ordering.pyr   r      s    &  F8He,, # #?? 	#MM'--<<==== 	#MM'"""
''&//C{
{    c                 \   d}t          j        t          |           }|| S dD ]8}|                    |          }|||                    dd          z  }3|dz  }9|                    d          ||                    d          z  }dD ]8}|                    |          }|||                    d	d          z  }3|d
z  }9|                    d          Kt          |          |k     r8t          |                    d          |t          |          z
            }||z  }|d|         S )a*  
    Similar in nature to naturalize(), but takes into account a particular naming format adapted from the old
    InterfaceManager.

    :param value: The value to be naturalized
    :param max_length: The maximum length of the returned string. Characters beyond this length will be stripped.
    r   N)slotsubslotpositionsubposition   r   9999type)idchannelvc   z......	remainder)r	   searchINTERFACE_NAME_REGEXgroupr   lenr   )r   r   r   match	part_namepartr#   s          r   r   r   3   sO    FI*E22E} D  	{{9%%djjC(((FFfFF {{6&%++f%%% -  	{{9%%djjC(((FFhFF {{;+Fj0H0Hu{{;77c&kk9QRR	)+:+r   )r   )r	   __all__r%   r   r    r   r   <module>r-      sK    				
-    @' ' ' ' 'r   