3

U'ícà,ã@szUddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
Gdd„dƒZeedœdd„Zedœdd	„Zedœd
d„Zeedœd
d„Zejdd„ƒZe	eefGdd„deƒZeedœdd„Zeedœdd„Zeedœdd„Zee
eefdœdd„Zejƒe
eefdœdd„ƒZeeeedœdd „Zd+d#d,d%d-d'iZ eee
ed(œd)d*„Z!dS).éN)ÚIOÚDictÚIteratorÚ
NamedTupleÚOptionalÚTuplec@s`eZdZGdd„deƒZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZdZeed
dœdd„Zd
S)Ú_ELFFileHeaderc@seZdZdZdS)z$_ELFFileHeader._InvalidELFFileHeaderz7
        An invalid ELF file header was found.
        N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__©r
r
ú9/tmp/pip-build-gk9425m9/packaging/packaging/_manylinux.pyÚ_InvalidELFFileHeadersriFLEééééé(é>l~iiN)ÚfileÚreturncszttdœ‡fdd„}|dƒ|_|j|jkr2tjƒ‚|dƒ|_|j|j|jhkrVtjƒ‚|dƒ|_	|j	|j
|jhkrztjƒ‚|dƒ|_|dƒ|_
|dƒ|_ˆjdƒ|_|j	|j
kr´dnd}|j	|j
krÈd	nd}|j	|j
krÜd
nd}|j|jkrð|n|}||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_||ƒ|_dS)N)ÚfmtrcsHy ˆjtj|ƒƒ}tj||ƒ}Wntjk
r>tjƒ‚YnX|dS)Nr)ÚreadÚstructÚcalcsizeÚunpackÚerrorrr)rÚdataÚresult)rr
rr$sz'_ELFFileHeader.__init__.<locals>.unpackz>IÚBéz<Hz>Hz<Iz<Qz>Q)ÚstrÚintZ
e_ident_magicÚELF_MAGIC_NUMBERrrÚ
e_ident_classÚ
ELFCLASS32Ú
ELFCLASS64Úe_ident_dataÚELFDATA2LSBÚELFDATA2MSBZe_ident_versionZ
e_ident_osabiZe_ident_abiversionrZe_ident_padZe_typeÚ	e_machineZ	e_versionZe_entryZe_phoffZe_shoffÚe_flagsZe_ehsizeZe_phentsizeZe_phnumZe_shentsizeZe_shnumZ
e_shstrndx)ÚselfrrZformat_hZformat_iZformat_qZformat_pr
)rrÚ__init__#s>

















z_ELFFileHeader.__init__)r	r
rÚ
ValueErrorrr$r&r'r)r*ÚEM_386ZEM_S390ÚEM_ARMZ	EM_X86_64ÚEF_ARM_ABIMASKÚEF_ARM_ABI_VER5ÚEF_ARM_ABI_FLOAT_HARDrÚbytesr.r
r
r
rrsr)rcCsFy$ttjdƒ}t|ƒ}WdQRXWntttjfk
r@dSX|S)NÚrb)ÚopenÚsysÚ
executablerÚOSErrorÚ	TypeErrorr)ÚfÚ
elf_headerr
r
rÚ_get_elf_headerLsr>cCsntƒ}|dkrdS|j|jk}||j|jkM}||j|jkM}||j|j@|j	kM}||j|j
@|j
kM}|S)NF)r>r%r&r(r)r+r1r,r2r3r4)r=rr
r
rÚ_is_linux_armhfUs



r?cCsBtƒ}|dkrdS|j|jk}||j|jkM}||j|jkM}|S)NF)r>r%r&r(r)r+r0)r=rr
r
rÚ_is_linux_i686hsr@)ÚarchrcCs$|dkrtƒS|dkrtƒS|dkS)	NZarmv7lÚi686Úx86_64Úaarch64Úppc64Úppc64leÚs390x>rCrGrFrErD)r?r@)rAr
r
rÚ_have_compatible_abirs
rHcCsdS)Né2r
r
r
r
rÚ<lambda>srJc@seZdZUeedS)Ú
_GLibCVersionN)r	r
rr#ÚmajorÚminorr
r
r
rrK‚s
rKcCsHy&tjdƒ}|dk	st‚|jƒ\}}Wnttttfk
rBdSX|S)zJ
    Primary implementation of glibc_version_string using os.confstr.
    ÚCS_GNU_LIBC_VERSIONN)ÚosÚconfstrÚAssertionErrorÚsplitÚAttributeErrorr:r/)Úversion_stringÚ_Úversionr
r
rÚ_glibc_version_string_confstr‡s
rWcCsŒyddl}Wntk
r dSXy|jdƒ}Wntk
rDdSXy
|j}Wntk
rddSX|j|_|ƒ}t|t	ƒsˆ|j
dƒ}|S)zG
    Fallback implementation of glibc_version_string using ctypes.
    rNÚascii)ÚctypesÚImportErrorÚCDLLr:Úgnu_get_libc_versionrSÚc_char_pÚrestypeÚ
isinstancer"Údecode)rYÚprocess_namespacer\Úversion_strr
r
rÚ_glibc_version_string_ctypesšs"


rccCstƒp
tƒS)z9Returns glibc version string, or None if not using glibc.)rWrcr
r
r
rÚ_glibc_version_stringÆsrd)rbrcCs@tjd|ƒ}|s$tjd|tƒdSt|jdƒƒt|jdƒƒfS)	a3Parse glibc version.

    We use a regexp instead of str.split because we want to discard any
    random junk that might come after the minor version -- this might happen
    in patched/forked versions of glibc (e.g. Linaro's version of glibc
    uses version strings like "2.20-2014.11"). See gh-3588.
    z$(?P<major>[0-9]+)\.(?P<minor>[0-9]+)z=Expected glibc version with 2 components major.minor, got: %srrLrMéÿÿÿÿre)rere)ÚreÚmatchÚwarningsÚwarnÚRuntimeWarningr#Úgroup)rbÚmr
r
rÚ_parse_glibc_versionËsrmcCstƒ}|dkrdSt|ƒS)Nrrere)rere)rdrm)rbr
r
rÚ_get_glibc_versionÞsrn)ÚnamerArVrcCsÒtƒ}||krdSyddl}Wntk
r2dSXt|dƒrh|j|d|d|ƒ}|dk	rdt|ƒSdS|tddƒkrŠt|dƒrŠt|jƒS|tdd	ƒkr¬t|d
ƒr¬t|jƒS|tddƒkrÎt|dƒrÎt|j	ƒSdS)
NFrTÚmanylinux_compatiblerréÚmanylinux1_compatibleéÚmanylinux2010_compatibleéÚmanylinux2014_compatible)
rnÚ
_manylinuxrZÚhasattrrpÚboolrKrrrtrv)rorArVZ	sys_glibcrwrr
r
rÚ_is_compatibleçs,






rzrruZ
manylinux2014rsZ
manylinux2010rqÚ
manylinux1)ÚlinuxrArccst|ƒsdStddƒ}|d	kr(tddƒ}ttƒŽ}|g}x2t|jddd
ƒD]}t|}|jt||ƒƒqLWx–|D]Ž}|j|jkrŠ|j}nd}xpt|j|dƒD]^}t|j|ƒ}	dj|	Ž}
t	|
||	ƒrÒ|j
d|
ƒV|	tkržt|	}t	|||	ƒrž|j
d|ƒVqžWqrWdS)
NrérCrBérzmanylinux_{}_{}r|>rCrBrerere)rHrKrnÚrangerLÚ_LAST_GLIBC_MINORÚappendrMÚformatrzÚreplaceÚ_LEGACY_MANYLINUX_MAP)r|rAZtoo_old_glibc2Z
current_glibcZglibc_max_listZglibc_majorZglibc_minorZ	glibc_maxZ	min_minorÚ
glibc_versionÚtagZ
legacy_tagr
r
rÚ
platform_tagss.




r‡)rru)rrs)rrq)"ÚcollectionsÚ	functoolsrOrfrr8rhÚtypingrrrrrrrr>ryr?r@r"rHÚdefaultdictr€r#rKrWrcrdrmÚ	lru_cachernrzr„r‡r
r
r
rÚ<module>s4 =	

,