
    kh/%                        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 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y# e$ r	 d dlmZ Y Qw xY w)    N)Union)urlopen   )logger_check_log_handlerz~\AppData\Local\Pandocz~/binz~/Applications/pandoc)win32linuxdarwinc                    d| dk7  rdndz   | z   }	 t        |      }|j                  j                  d      }|d   } t        d	|        }|j                         }t        j                         d
   }|j                  d      s|j                  d      rdnd}t        j                  d| d      }|j                  |j                  d            }	|	d   j                  d      d   } dddd}
|	D ci c]  }|
|dd    d|  }}|| fS # t        j                  j
                  $ r}t        dj                  |             d}~ww xY wc c}w )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/latestz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pkgzhttps://github.com)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ext2platformurl_fragpandoc_urlss                T/var/www/teggl/fontify/venv/lib/python3.12/site-packages/pypandoc/pandoc_download.py_get_pandoc_urlsr4      sw     4(6b24;<C3<$LL..s3#B'
 PQXPYZ[HmmoGNNQE&+&6&6u&=AQAQRYAZU`eJJ=>T=UUqrsE}}W^^G%<=q!'',Q/G L cssV^<.3EhZ1PPsKs/ <<!! 7>>wGHH, ts   +D
 1E	
E'EEc                     t        j                  |       j                  }||dz  dz	  z  }t        j                  d|  d       t        j
                  | |       y )Ni$     zMaking z executable...)osstatst_moder   infochmod)pathmodes     r3   _make_executabler>   N   sK    774=  DTE\aD
KK'$~./HHT4    c                    t        j                  d|  d       t        j                         }t	        j
                         }t        j                  j                  |       } 	 t	        j                  |       dd| g}t        j                  |       t	        j                  d      }t        d |D              }dd|g}t        j                  |       d	}t        j                  j                  |d
d|      }t        j                  j                  ||      }	t        j                  d| d| d       t        j                  ||	       t!        |	       d}t        j                  j                  |d
d|      }t        j                  j                  ||      }	t        j                  j#                  |      r=t        j                  d| d| d       t        j                  ||	       t!        |	       t        j                  j                  |d
ddd	d      }t        j                  j                  |d      }	t        j                  d| d       t        j                  ||	       t	        j                  |       t        j$                  |       y # t	        j                  |       t        j$                  |       w xY w)N
Unpacking  to tempfolder...arx.c              3   D   K   | ]  }|j                  d       s|  yw)zdata.tarN)r#   ).0rD   s     r3   	<genexpr>z _handle_linux.<locals>.<genexpr>a   s     I!Z0HAIs     tarxfpandocusrbinCopying  to  ...pandoc-citeprocsharedoc	copyrightzcopyright.pandoczCopying copyright to )r   r:   tempfilemkdtempr7   getcwdr<   abspathchdir
subprocess
check_calllistdirnextjoinshutilcopyfiler>   existsrmtree)
filenametargetfolder
tempfoldercur_wdcmdfilesarchive_nameexesrcdsts
             r3   _handle_linuxrm   U   s   
KK*XJ&789!!#JYY[Fwwx(H"
S(#c"

3IuIIdL)c"ggll:ueS9ggll<-hse4~T:;S!ggll:ueS9ggll<-77>>#KK(3%tL>>?OOC%S!ggll:uguhTggll<);<+L>>?S!
j! 	j!s   "HJ ,J=c                    t        j                  d|  d       t        j                         }t        j
                  j                  |d      }dd| |g}t        j                  |       ddt        j
                  j                  |dd	      d
|g}t        j                  |       d}t        j
                  j                  |ddd|      }t        j
                  j                  ||      }t        j                  d| d| d       t        j                  ||       t        |       d}t        j
                  j                  |ddd|      }t        j
                  j                  ||      }t        j
                  j                  |      r=t        j                  d| d| d       t        j                  ||       t        |       t        j                  |       t        j                  d       y )NrA   rB   tmppkgutilz--expandrI   xvfz
pandoc.pkgPayloadz-CrK   rL   localrM   rN   rO   rP   rQ   Done.)r   r:   rU   rV   r7   r<   r^   rZ   r[   r_   r`   r>   ra   rb   )rc   rd   re   pkgutilfolderrg   rj   rk   rl   s           r3   _handle_darwinrv   {   s~   
KK*XJ&789!!#JGGLLU3Mj(M
:C# %m\9M C# C
'',,}eWeS
AC
'',,|S
)C
KK(3%tL>67
OOCS
C
'',,}eWeS
AC
'',,|S
)C	ww~~chse4~T:;S! MM*
KKr?   c                    t        j                  d|  d       t        j                         }dd| dd|z  g}t	        j
                  |       d}t        j                  j                  |d|      }t        j                  j                  ||      }t        j                  d	| d
| d       t        j                  ||       d}t        j                  j                  |d|      }t        j                  j                  ||      }t        j                  j                  |      r2t        j                  d	| d
| d       t        j                  ||       d}t        j                  j                  |d|      }t        j                  j                  ||      }t        j                  d	| d
| d       t        j                  ||       t        j                  |       t        j                  d       y )NrA   rB   msiexecz/az/qbzTARGETDIR=%sz
pandoc.exePandocrN   rO   rP   zpandoc-citeproc.exezCOPYRIGHT.txtrt   )r   r:   rU   rV   rZ   r[   r7   r<   r^   r_   r`   ra   rb   )rc   rd   re   rg   rj   rk   rl   s          r3   _handle_win32rz      s}   
KK*XJ&789!!#JdHe^z-J
KC# C
'',,z8S
1C
'',,|S
)C
KK(3%tL>67
OOC
C
'',,z8S
1C
'',,|S
)C	ww~~chse4~T:;S!
C
'',,z8S
1C
'',,|S
)C
KK(3%tL>67
OOC MM*
KKr?   r   rd   r(   delete_installerdownload_folderreturnc                    t                t        j                  }| `|j                  d      r-d}t        j                         d   }|dk7  rt        d| d      t        |      \  }}||vrt        d      ||   } | j                  d      d	   }	|S|j                  d      r|dd	 }t        j                  j                  t        j                  j                  |      |	      }	t        j                  j                  |	      rt        j                  d
|	        nOt        j                  d|  d       t!        |       }
t#        |	d      5 }t%        j&                  |
|       ddd       |	t(        |   }t        j                  j                  |      }	 t        j*                  |       t/               j1                  d|z         }|J d        ||	|       |rt        j2                  |	       yy# 1 sw Y   xY w# t,        $ r Y ^w xY w)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=rE   z;Can't handle your platform (only Linux, Mac OS X, Windows).r   r   zUsing already downloaded file zDownloading pandoc from rP   wb_handle_zBCan't handle download, only Linux, Windows and OS X are supported.)r   sysr!   r#   architecturer   r4   r   endswithr7   r<   r^   
expanduserisfiler   r:   r   openr_   copyfileobjDEFAULT_TARGET_FOLDERmakedirsOSErrorglobalsgetremove)r   rd   r(   r{   r|   pfarchr2   _rc   r)   out_fileunpacks                r3   download_pandocr      s   . 	B
{==!B((*1-Dw"%WX\W]]^#_`` *'2Q[ \]]"oyy~b!H"##C(-cr2O77<< 2 2? CXN	ww~~h4XJ?@.se4893<(D! 	3Xx2	3 ,R077%%l3L
L! Y]]:?+Fccc
8\"
		( #	3 	3  s   G4H  4G= 	HH)r   )NNr   FN)loggingr7   os.pathr!   r$   r_   rZ   r   rU   typingr   r   urllib.requestr   ImportErrorhandlerr   r   r   r4   r>   rm   rv   rz   strboolr    r?   r3   <module>r      s     	   	   
   & 0 )% . b#"L"J F *.26 (*/59	Jc4i( J!&sDy!1JJ &*J %*#t)$4	J ?C	Je  s   A: :BB