o
    pf                     @   s   d dl mZmZmZ d dlZd dlZd dlZd dlmZ zd dlmZ W n e	y3   ddl
mZ Y nw ddlmZ ddlmZ ed ejZedejZed	ejZd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )    )absolute_importprint_functionunicode_literalsN)datetime)timezone   )ResourceType)Permissionsa  
    ^
    ([-dlpscbD])
    ([r-][w-][xsS-][r-][w-][xsS-][r-][w-][xtT-][\.\+]?)
    \s+?
    (\d+)
    \s+?
    ([A-Za-z0-9][A-Za-z0-9\-\.\_\@]*\$?)
    \s+?
    ([A-Za-z0-9][A-Za-z0-9\-\.\_\@]*\$?)
    \s+?
    (\d+)
    \s+?
    (\w{3}\s+\d{1,2}\s+[\w:]+)
    \s+
    (.*?)
    $
    z
    ^
    (?P<modified_date>\S+)
    \s+
    (?P<modified_time>\S+(AM|PM)?)
    \s+
    (?P<size>(<DIR>|\d+))
    \s+
    (?P<name>.*)
    $
    c                  C   s   t tfttfg} | S )zHReturn all available FTP LIST line decoders with their matching regexes.)RE_LINUXdecode_linuxRE_WINDOWSNTdecode_windowsnt)decoders r   F/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/_ftp_parse.pyget_decoders:   s   r   c                 C   s6   g }| D ]}|  sqt|}|d ur|| q|S N)strip
parse_lineappend)linesinfolineraw_infor   r   r   parseC   s   
r   c                 C   s4   t  D ]\}}|| }|d ur|| |  S qd S r   )r   match)r   line_redecode_callabler   r   r   r   r   N   s   
r   c              	   C   s   |D ]}z	t | |}W  n ty   Y qw d S |jdkr!|jnt  j}|j}|j}|j}|j}t	|||||t
jd}	|	t  }
|
S )Nil  )tzinfo)timestrptime
ValueErrortm_year	localtimetm_montm_mdaytm_hourtm_minr   r   utcEPOCH_DTtotal_seconds)tformatsfrmt_tyearmonthdayhourminutesdt
epoch_timer   r   r   _parse_timeV   s    r6   c                 C      t | ddgdS )Nz%b %d %Yz%b %d %H:%Mr,   r6   mtimer   r   r   _decode_linux_timek      r<   c                 C   s   |  \}}}}}}}}	|dk}
|dkp|
}|
r(|	d\}	}}|	 }	| }t|}t|}td|	}	|	|dt|t|rDt	j
nt	jdd| id| id	}|d
 }|d }|d urd||d< ||d< ||d< |S )Nldz->NFCnameis_dir)sizetypepermissionsls)basicdetailsaccessftprJ   rI   modifiedusergroup)groups	partitionr   r	   r   r<   unicodedata	normalizeintr   	directoryfiledump)r   r   typermslinksuidgidrD   r;   rB   is_linkrC   _
_link_namerF   mtime_epochr   rJ   rI   r   r   r   r   o   s0   

	r   c                 C   r7   )Nz%d-%m-%y %I:%M%pz%d-%m-%y %H:%Mr8   r9   r:   r   r   r   _decode_windowsnt_time   r=   r`   c                 C   s   | ddk}| d|ddt|rtjntjid| id}|s,t| d|d d< t| d	d
 | d }|durD||d d< |S )a  Decode a Windows NT FTP LIST line.

    Examples:
        Decode a directory line::

            >>> line = "11-02-18  02:12PM       <DIR>          images"
            >>> match = RE_WINDOWSNT.match(line)
            >>> pprint(decode_windowsnt(line, match))
            {'basic': {'is_dir': True, 'name': 'images'},
             'details': {'modified': 1518358320.0, 'type': 1},
             'ftp': {'ls': '11-02-18  02:12PM       <DIR>          images'}}

        Decode a file line::

            >>> line = "11-02-18  03:33PM                 9276 logo.gif"
            >>> match = RE_WINDOWSNT.match(line)
            >>> pprint(decode_windowsnt(line, match))
            {'basic': {'is_dir': False, 'name': 'logo.gif'},
             'details': {'modified': 1518363180.0, 'size': 9276, 'type': 2},
             'ftp': {'ls': '11-02-18  03:33PM                 9276 logo.gif'}}

        Alternatively, the time might also be present in 24-hour format::

            >>> line = "11-02-18  15:33                   9276 logo.gif"
            >>> match = RE_WINDOWSNT.match(line)
            >>> decode_windowsnt(line, match)["details"]["modified"]
            1518363180.0

    rD   z<DIR>rB   rA   rE   rG   )rH   rI   rK   rI   modified_date modified_timeNrL   )rN   rS   r   rT   rU   r`   )r   r   rC   r   rL   r   r   r   r      s    r   )
__future__r   r   r   rer   rQ   r   r   ImportError	_tzcompatenumsr   rF   r	   fromtimestampr(   r)   compileVERBOSEr
   r   r   r   r   r6   r<   r   r`   r   r   r   r   r   <module>   s:    	"