Skip to content

Commit b9f3035

Browse files
committed
Bump vendored packaging==23.2
1 parent 5ac3ec8 commit b9f3035

18 files changed

+2640
-8193
lines changed

pip_api/_vendor/packaging/__about__.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

pip_api/_vendor/packaging/__init__.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@
22
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
33
# for complete details.
44

5-
from .__about__ import (
6-
__author__,
7-
__copyright__,
8-
__email__,
9-
__license__,
10-
__summary__,
11-
__title__,
12-
__uri__,
13-
__version__,
14-
)
5+
__title__ = "packaging"
6+
__summary__ = "Core utilities for Python packages"
7+
__uri__ = "https://github.com/pypa/packaging"
158

16-
__all__ = [
17-
"__title__",
18-
"__summary__",
19-
"__uri__",
20-
"__version__",
21-
"__author__",
22-
"__email__",
23-
"__license__",
24-
"__copyright__",
25-
]
9+
__version__ = "23.2"
10+
11+
__author__ = "Donald Stufft and individual contributors"
12+
__email__ = "[email protected]"
13+
14+
__license__ = "BSD-2-Clause or Apache-2.0"
15+
__copyright__ = "2014 %s" % __author__

pip_api/_vendor/packaging/_elffile.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
"""
2+
ELF file parser.
3+
4+
This provides a class ``ELFFile`` that parses an ELF executable in a similar
5+
interface to ``ZipFile``. Only the read interface is implemented.
6+
7+
Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
8+
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
9+
"""
10+
11+
import enum
12+
import os
13+
import struct
14+
from typing import IO, Optional, Tuple
15+
16+
17+
class ELFInvalid(ValueError):
18+
pass
19+
20+
21+
class EIClass(enum.IntEnum):
22+
C32 = 1
23+
C64 = 2
24+
25+
26+
class EIData(enum.IntEnum):
27+
Lsb = 1
28+
Msb = 2
29+
30+
31+
class EMachine(enum.IntEnum):
32+
I386 = 3
33+
S390 = 22
34+
Arm = 40
35+
X8664 = 62
36+
AArc64 = 183
37+
38+
39+
class ELFFile:
40+
"""
41+
Representation of an ELF executable.
42+
"""
43+
44+
def __init__(self, f: IO[bytes]) -> None:
45+
self._f = f
46+
47+
try:
48+
ident = self._read("16B")
49+
except struct.error:
50+
raise ELFInvalid("unable to parse identification")
51+
magic = bytes(ident[:4])
52+
if magic != b"\x7fELF":
53+
raise ELFInvalid(f"invalid magic: {magic!r}")
54+
55+
self.capacity = ident[4] # Format for program header (bitness).
56+
self.encoding = ident[5] # Data structure encoding (endianness).
57+
58+
try:
59+
# e_fmt: Format for program header.
60+
# p_fmt: Format for section header.
61+
# p_idx: Indexes to find p_type, p_offset, and p_filesz.
62+
e_fmt, self._p_fmt, self._p_idx = {
63+
(1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
64+
(1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
65+
(2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
66+
(2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
67+
}[(self.capacity, self.encoding)]
68+
except KeyError:
69+
raise ELFInvalid(
70+
f"unrecognized capacity ({self.capacity}) or "
71+
f"encoding ({self.encoding})"
72+
)
73+
74+
try:
75+
(
76+
_,
77+
self.machine, # Architecture type.
78+
_,
79+
_,
80+
self._e_phoff, # Offset of program header.
81+
_,
82+
self.flags, # Processor-specific flags.
83+
_,
84+
self._e_phentsize, # Size of section.
85+
self._e_phnum, # Number of sections.
86+
) = self._read(e_fmt)
87+
except struct.error as e:
88+
raise ELFInvalid("unable to parse machine and section information") from e
89+
90+
def _read(self, fmt: str) -> Tuple[int, ...]:
91+
return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))
92+
93+
@property
94+
def interpreter(self) -> Optional[str]:
95+
"""
96+
The path recorded in the ``PT_INTERP`` section header.
97+
"""
98+
for index in range(self._e_phnum):
99+
self._f.seek(self._e_phoff + self._e_phentsize * index)
100+
try:
101+
data = self._read(self._p_fmt)
102+
except struct.error:
103+
continue
104+
if data[self._p_idx[0]] != 3: # Not PT_INTERP.
105+
continue
106+
self._f.seek(data[self._p_idx[1]])
107+
return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip("\0")
108+
return None

0 commit comments

Comments
 (0)