a
    kÄ#d¿  ã                   @   sˆ   d Z ddlZddlZddlZej e¡Zdd„ Zdd„ Z	dd„ Z
e
ƒ  ZZe d	e¡Zedurfe ¡ neZed
kr„ddlmZ eƒ  dS )zš
Scapy: create, send, sniff, dissect and manipulate network packets.

Usable either from an interactive console or as a Python library.
https://scapy.net
é    Nc                 C   s:   t  d| ¡}|r(d| d¡| d¡f S t  dd| ¡S dS )z~
    Parse a tag from ``git describe`` into a version.

    Example::

        v2.3.2-346-g164a52c075c8 -> '2.3.2.dev346'
    z^v?(.+?)-(\d+)-g[a-f0-9]+$z%s.dev%sé   é   z^vÚ N)ÚreÚmatchÚgroupÚsub)Útagr   © r
   úE/var/www/html/gsl.tools/lib/python3.9/site-packages/scapy/__init__.pyÚ
_parse_tag   s    	r   c                  C   s\   t j t j t j t¡d¡¡s&tdƒ‚dd„ } | dƒ}| d¡sT| dƒ}| d| ƒ}t|ƒS )	aŽ  
    Read the version from ``git describe``. It returns the latest tag with an
    optional suffix if the current directory is not exactly on the tag.

    Example::

        $ git describe --always
        v2.3.2-346-g164a52c075c8

    The tag prefix (``v``) and the git commit sha1 (``-g164a52c075c8``) are
    removed if present.

    If the current directory is not exactly on the tag, a ``.devN`` suffix is
    appended where N is the number of commits made after the last tag.

    Example::

        >>> _version_from_git_describe()
        '2.3.2.dev346'

    :raises CalledProcessError: if git is unavailable
    :return: Scapy's latest tag
    z.gitznot in scapy git repoc                 S   sN   t j|  ¡ tt jt jd�}| ¡ \}}|jdkr<| ¡  ¡ S t  	|j|¡‚d S )N)ÚcwdÚstdoutÚstderrr   )
Ú
subprocessÚPopenÚsplitÚ_SCAPY_PKG_DIRÚPIPEÚcommunicateÚ
returncodeÚdecodeÚstripÚCalledProcessError)ÚcmdÚprocessÚoutÚerrr
   r
   r   Ú_gitB   s    ü
z(_version_from_git_describe.<locals>._gitzgit describe --alwaysÚvz!git rev-list --tags --max-count=1z&git describe --tags --always --long %s)	ÚosÚpathÚisdirÚjoinÚdirnamer   Ú
ValueErrorÚ
startswithr   )r   r	   Úcommitr
   r
   r   Ú_version_from_git_describe&   s    
r(   c                  C   s
  d  ¡  ¡ } | d }| d }d|vrLd|v r0d}|r<t|ƒS |rHd| S dS tj td	¡}z@tƒ }t|d
ƒ�}| 	|¡ W d  ƒ n1 sŒ0    Y  |W S  t
�y   z<t|dƒ�}| ¡ }W d  ƒ n1 sÔ0    Y  |W  Y S  t
� yþ   Y Y dS 0 Y n0 dS )zTReturns the Scapy version from multiple methods

    :return: the Scapy version
    z$Format:%h %(describe)$r   r   ZFormatZdescriber   zgit-archive.zunknown.versionÚVERSIONÚwNÚr)r   r   r   r    r!   r#   r   r(   ÚopenÚwriteÚ	ExceptionÚread)Zgit_archive_idÚsha1r	   Zversion_fileZfdescZfdsecr
   r
   r   Ú_versionX   s0    
(&
r1   z[0-9.]+Ú__main__)Úinteract)Ú__doc__r    r   r   r!   r$   Ú__file__r   r   r(   r1   r)   Ú__version__ÚsearchZ_tmpr   ZVERSION_MAINÚ__name__Z
scapy.mainr3   r
   r
   r
   r   Ú<module>   s   2*
