
    	D,j$                         d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZ	d dl
Z	d dlmZ ddlmZmZ ddddZdd
Zd Zd Zd Zd Z	 	 	 	 	 ddeedf         deedf         dededeedf         ddfdZdS )    N)Union   )_check_log_handlerloggerz~\AppData\Local\Pandocz~/binz~/Applications/pandoc)win32linuxdarwinlatestc                   
 d| dk    rdndz   | z   }	 t           j                            |          }|j                            d          }|d         } n+# t           j        j        $ r t          d|  d          w xY wt           j                            d	|            }|                                }t          j
                    d
         }|                    d          s|                    d          rdnd}t          j        d| d          }|                    |                    d                    }|d                             d          d         } dddd

fd|D             }	|	| fS )aX  Get the urls of pandoc's binaries
    Uses sys.platform keys, but removes the 2 from linux2
    Adding a new platform means implementing unpacking in "DownloadPandocCommand"
    and adding the URL here

    :param str version: pandoc version.
        Valid values are either a valid pandoc version e.g. "1.19.1", or "latest"
        Default: "latest".

    :return: str pandoc_urls: a dictionary with keys as system platform
        and values as the url pointing to respective binaries

    :return: str version: actual pandoc version.
        (e.g. "latest" will be resolved to the actual one)
    z'https://github.com/jgm/pandoc/releases/r
   ztag/ /zInvalid pandoc version .z7https://github.com/jgm/pandoc/releases/expanded_assets/   armaarchamdz#/jgm/pandoc/releases/download/.*(?:z|x86|mac).*\.(?:msi|deb|pkg)zutf-8r      r   r   r	   )msidebpkgc                 8    i | ]}|d d                  d| S )Nzhttps://github.com ).0url_fragext2platforms     g/home/rurouni/.local/share/uv/tools/aider-chat/lib/python3.11/site-packages/pypandoc/pandoc_download.py
<dictcomp>z$_get_pandoc_urls.<locals>.<dictcomp>H   sA        	Xbcc]#%D(%D%D      )urllibrequesturlopenurlspliterror	HTTPErrorRuntimeErrorreadplatformuname
startswithrecompilefindalldecode)versionr$   responseversion_url_fragscontentr+   processor_architectureregexpandoc_urls_listpandoc_urlsr   s             @r   _get_pandoc_urlsr9      s   $ 	2((66b	2
	 A>))#..$L..s33#B'<! A A A?W???@@@A ~%%K'KK H mmooGNQE!!%((PE,<,<W,E,EP5  J	D%	D 	D 	D E
 }}W^^G%<%<==q!'',,Q/G"78DDL   (  K s   AA (A=c                     t          j        |           j        }||dz  dz	  z  }t          j        d|  d           t          j        | |           d S )Ni$     zMaking z executable...)osstatst_moder   infochmod)pathmodes     r   _make_executablerC   O   sY    74== DTE\aD
K.$...///HT4r    c                 ~   t          j        d|  d           t          j                    }t	          j                    }t          j                            |           } 	 t	          j        |           dd| g}t          j
        |           t	          j        d          }t          d |D                       }dd|g}t          j
        |           d	}t          j                            |d
d|          }t          j                            ||          }	t          j        d| d| d           t          j        ||	           t!          |	           d}t          j                            |d
d|          }t          j                            ||          }	t          j                            |          r?t          j        d| d| d           t          j        ||	           t!          |	           t          j                            |d
ddd	d          }t          j                            |d          }	t          j        d| d           t          j        ||	           t	          j        |           t          j        |           d S # t	          j        |           t          j        |           w xY w)N
Unpacking  to tempfolder...arxr   c              3   D   K   | ]}|                     d           |V  dS )zdata.tarN)r,   )r   rH   s     r   	<genexpr>z _handle_linux.<locals>.<genexpr>b   s3      II!Z0H0HIAIIIIIIr    tarxfpandocusrbinCopying  to  ...pandoc-citeprocsharedoc	copyrightzcopyright.pandoczCopying copyright to )r   r?   tempfilemkdtempr<   getcwdrA   abspathchdir
subprocess
check_calllistdirnextjoinshutilcopyfilerC   existsrmtree)
filenametargetfolder
tempfoldercur_wdcmdfilesarchive_nameexesrcdsts
             r   _handle_linuxro   V   sv   
K8X888999!##JY[[Fwx((H"
S(#c"""
3IIuIIIIIdL)c"""gll:ueS99gll<--:s:::::;;;S!!!gll:ueS99gll<--7>># 	"K>3>>L>>>???OC%%%S!!!gll:uguhTTgll<);<<>L>>>???S!!!
j!!!!! 	j!!!!s   H	J *J<c                    t          j        d|  d           t          j                    }t          j                            |d          }dd| |g}t          j        |           ddt          j                            |dd	          d
|g}t          j        |           d}t          j                            |ddd|          }t          j                            ||          }t          j        d| d| d           t          j
        ||           t          |           d}t          j                            |ddd|          }t          j                            ||          }t          j                            |          r?t          j        d| d| d           t          j
        ||           t          |           t          j        |           t          j        d           d S )NrE   rF   tmppkgutilz--expandrK   xvfz
pandoc.pkgPayloadz-CrM   rN   localrO   rP   rQ   rR   rS   Done.)r   r?   rW   rX   r<   rA   r`   r\   r]   ra   rb   rC   rc   rd   )re   rf   rg   pkgutilfolderri   rl   rm   rn   s           r   _handle_darwinrx   |   s   
K8X888999!##JGLLU33Mj(M
:C# 	
]L)<<C # C
',,}eWeS
A
AC
',,|S
)
)C
K6366L666777
OCS
C
',,}eWeS
A
AC
',,|S
)
)C	w~~c :s:::::;;;S!!! M*
Kr    c                    t          j        d|  d           t          j                    }dd| dd|z  g}t	          j        |           d}t          j                            |d|          }t          j                            ||          }t          j        d	| d
| d           t          j
        ||           d}t          j                            |d|          }t          j                            ||          }t          j                            |          r0t          j        d	| d
| d           t          j
        ||           d}t          j                            |d|          }t          j                            ||          }t          j        d	| d
| d           t          j
        ||           t          j        |           t          j        d           d S )NrE   rF   msiexecz/az/qbzTARGETDIR=%sz
pandoc.exePandocrP   rQ   rR   zpandoc-citeproc.exezCOPYRIGHT.txtrv   )r   r?   rW   rX   r\   r]   r<   rA   r`   ra   rb   rc   rd   )re   rf   rg   ri   rl   rm   rn   s          r   _handle_win32r|      s   
K8X888999!##JdHe^z-J
KC# C
',,z8S
1
1C
',,|S
)
)C
K6366L666777
OC
C
',,z8S
1
1C
',,|S
)
)C	w~~c ":s:::::;;;S!!!
C
',,z8S
1
1C
',,|S
)
)C
K6366L666777
OC M*
Kr    Fr$   rf   r1   delete_installerdownload_folderreturnc                    t                       t          j        }| v|                    d          r4d}t          j                    d         }|dk    rt          d| d          t          |          \  }}||vrt          d          ||         } |                     d          d	         }	|\|                    d          r
|dd	         }t          j
                            t          j
                            |          |	          }	t          j
                            |	          rt          j        d
|	            ntt          j        d|  d           t           j                            |           }
t'          |	d          5 }t)          j        |
|           ddd           n# 1 swxY w Y   |t,          |         }t          j
                            |          }	 t          j        |           n# t0          $ r Y nw xY wt3                                          d|z             }|
J d             ||	|           |rt          j        |	           dS dS )aZ  Download and unpack pandoc

    Downloads prebuild binaries for pandoc from `url` and unpacks it into
    `targetfolder`.

    :param str url: URL for the to be downloaded pandoc binary distribution for
        the platform under which this python runs. If no `url` is give, uses
        the latest available release at the time pypandoc was released.

    :param str targetfolder: directory, where the binaries should be installed
        to. If no `targetfolder` is given, uses a platform specific user
        location: `~/bin` on Linux, `~/Applications/pandoc` on Mac OS X, and
        `~\AppData\Local\Pandoc` on Windows.

    :param str download_folder: Directory where the installer should download files
        before unpacking to the target folder. If no `download_folder` is given,
        uses the current directory. example: `/tmp/`, `/tmp`
    Nr   r   64bitz2Linux pandoc is only compiled for 64bit. Got arch=r   z;Can't handle your platform (only Linux, Mac OS X, Windows).r   r   zUsing already downloaded file zDownloading pandoc from rR   wb_handle_zBCan't handle download, only Linux, Windows and OS X are supported.)r   sysr*   r,   architecturer(   r9   r%   endswithr<   rA   r`   
expanduserisfiler   r?   r!   r"   r#   openra   copyfileobjDEFAULT_TARGET_FOLDERmakedirsOSErrorglobalsgetremove)r$   rf   r1   r}   r~   pfarchr8   _re   r2   out_fileunpacks                r   download_pandocr      s   4 	B
{==!! 	B(**1-Dw"PPPP  
 *'22Q[  M   "oyy~~b!H"##C(( 	3-crc2O7<< 2 2? C CXNN	w~~h 3?X??@@@@8s888999>))#..(D!! 	3Xx222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 ,R07%%l33L
L!!!!    YY]]:?++FK 	 F8\""" 
	( s$   
F,,F03F0&G; ;
HH)r
   )NNr
   FN)r<   os.pathr*   r-   ra   r\   r   rW   urllib.errorr!   urllib.requesttypingr   handlerr   r   r   r9   rC   ro   rx   r|   strboolr   r   r    r   <module>r      s   				   				      



                / / / / / / / / )%  6  6  6  6 r  #" #" #"L' ' 'T     H !%)"(,S S	sDy	ST	"S S 	S
 39%S 
S S S S S Sr    