
    r}f0%                     ,   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Z	 d dlmZ n# e$ r	 d dlmZ Y nw xY w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)urlopen   )logger_check_log_handlerz~\AppData\Local\Pandocz~/binz~/Applications/pandoc)win32linuxdarwinlatestc                    d| dk    rdndz   | z   }	 t          |          }|j                            d          }|d         } n># t          j        j        $ r'}t          d                    |                     d}~ww xY wt          d	|            }|                                }t          j
                    d
         }|                    d          s|                    d          rdnd}t          j        d|z   dz             }|                    |                    d                    }	|	d                             d          d         } ddddfd|	D             }
|
| fS )aP  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 {}.Nz7https://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     Q/var/www/rtfcompare/venv/lib/python3.11/site-packages/pypandoc/pandoc_download.py
<dictcomp>z$_get_pandoc_urls.<locals>.<dictcomp>J   s2    sssV^<.1Ph1P1Psss    )r   urlspliturlliberror	HTTPErrorRuntimeErrorformatreadplatformuname
startswithrecompilefindalldecode)versionr!   responseversion_url_fragsecontentr*   processor_architectureregexpandoc_urls_listpandoc_urlsr   s              @r   _get_pandoc_urlsr9      s     4((66b24;<C3<<$L..s33#B'<!   7>>wGGHHH ZQXZZ[[HmmooGNQE&+&6&6u&=&=eAQAQRYAZAZeUU`eJ=>TTUssttE}}W^^G%<%<==q!'',,Q/G  L tsssbrsssKs   1A B "A;;B 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   N   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x.c              3   D   K   | ]}|                     d           |V  dS )zdata.tarN)r+   )r   rH   s     r   	<genexpr>z _handle_linux.<locals>.<genexpr>a   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_linuxrp   U   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--expandrL   xvfz
pandoc.pkgPayloadz-CrN   rO   localrP   rQ   rR   rS   rT   Done.)r   r?   rX   rY   r<   rA   ra   r]   r^   rb   rc   rC   rd   re   )rf   rg   rh   pkgutilfolderrj   rm   rn   ro   s           r   _handle_darwinry   {   s   
K8X888999!##JGLLU33Mj(M
:C# %m\9MM 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PandocrQ   rR   rS   zpandoc-citeproc.exezCOPYRIGHT.txtrw   )r   r?   rX   rY   r]   r^   r<   rA   ra   rb   rc   rd   re   )rf   rg   rh   rj   rm   rn   ro   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!   rg   r0   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
|	            ndt          j        d|  d           t!          |           }
t#          |	d          5 }t%          j        |
|           ddd           n# 1 swxY w Y   |t(          |         }t          j
                            |          }	 t          j        |           n# t,          $ r Y nw xY wt/                                          d|z             }|
J d             ||	|           |rt          j        |	           dS dS )aS  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=rI   z;Can't handle your platform (only Linux, Mac OS X, Windows).r   r   zUsing already downloaded file zDownloading pandoc from rS   wb_handle_zBCan't handle download, only Linux, Windows and OS X are supported.)r   sysr)   r+   architecturer&   r9   r"   endswithr<   rA   ra   
expanduserisfiler   r?   r   openrb   copyfileobjDEFAULT_TARGET_FOLDERmakedirsOSErrorglobalsgetremove)r!   rg   r0   r~   r   pfarchr8   _rf   r1   out_fileunpacks                r   download_pandocr      s   . 	B
{==!! 	aB(**1-Dw"#_X\#_#_#_``` *'22Q[  \]]]"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3<<(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c
F8\""" 
	( s$   :FF #F G+ +
G87G8)r   )NNr   FN)loggingr<   os.pathr)   r,   rb   r]   r   rX   typingr   r#   urllib.requestr   ImportErrorhandlerr   r   r   r9   rC   rp   ry   r}   strboolr   r   r    r   <module>r      s    				   				      



        &&&&&&&    0 / / / / / / / )%  .  .  .  . b  #" #" #"L" " "J     F *.26 (*/59	J Jc4i( J!&sDy!1JJ &*J %*#t)$4	J ?C	J J J J J Js   7 AA