auto-sync 2026-07-02T13:37:00Z workspace (part 5)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +7 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/iup.py +490 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/merger.py +1717 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/models.py +663 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/multiVarStore.py +253 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/mutator.py +529 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/mvar.py +40 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/plot.py +238 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/stat.py +149 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/varStore.py +739 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/__init__.py +5 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/__main__.py +206 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/ast.py +452 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/error.py +12 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/lexer.py +99 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/parser.py +664 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/voltToFea.py +911 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/INSTALLER +1 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/METADATA +74 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/RECORD +701 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/WHEEL +5 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/entry_points.txt +5 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/licenses/LICENSE +21 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/licenses/LICENSE.external +388 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/top_level.txt +1 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/INSTALLER +1 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/METADATA +257 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/RECORD +119 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/WHEEL +5 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/licenses/LICENSE +29 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/__init__.py +71 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/_version.py +24 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/archive.py +75 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/asyn.py +1158 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/caching.py +1004 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/callbacks.py +324 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/compression.py +185 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/config.py +131 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/conftest.py +125 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/core.py +760 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/dircache.py +98 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/exceptions.py +18 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/fuse.py +324 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/generic.py +396 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/gui.py +417 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/__init__.py +0 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/arrow.py +312 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/asyn_wrapper.py +124 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/cache_mapper.py +75 -0
- workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/cache_metadata.py +217 -0
.gitattributes
CHANGED
|
@@ -144,3 +144,10 @@ workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/misc/bezierT
|
|
| 144 |
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/pens/momentsPen.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 145 |
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/qu2cu/qu2cu.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 146 |
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/iup.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/pens/momentsPen.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 145 |
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/qu2cu/qu2cu.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 146 |
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/iup.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 147 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/jiter/jiter.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 148 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/kiwisolver/_cext.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 149 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/matplotlib/_c_internal_utils.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 150 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/matplotlib/_image.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 151 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/matplotlib/_path.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 152 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/matplotlib/_qhull.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 153 |
+
workspace/outputs/audit_venv/lib/python3.11/site-packages/matplotlib/_tri.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/iup.py
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import cython
|
| 3 |
+
except (AttributeError, ImportError):
|
| 4 |
+
# if cython not installed, use mock module with no-op decorators and types
|
| 5 |
+
from fontTools.misc import cython
|
| 6 |
+
COMPILED = cython.compiled
|
| 7 |
+
|
| 8 |
+
from typing import (
|
| 9 |
+
Sequence,
|
| 10 |
+
Tuple,
|
| 11 |
+
Union,
|
| 12 |
+
)
|
| 13 |
+
from numbers import Integral, Real
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
_Point = Tuple[Real, Real]
|
| 17 |
+
_Delta = Tuple[Real, Real]
|
| 18 |
+
_PointSegment = Sequence[_Point]
|
| 19 |
+
_DeltaSegment = Sequence[_Delta]
|
| 20 |
+
_DeltaOrNone = Union[_Delta, None]
|
| 21 |
+
_DeltaOrNoneSegment = Sequence[_DeltaOrNone]
|
| 22 |
+
_Endpoints = Sequence[Integral]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
MAX_LOOKBACK = 8
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@cython.cfunc
|
| 29 |
+
@cython.locals(
|
| 30 |
+
j=cython.int,
|
| 31 |
+
n=cython.int,
|
| 32 |
+
x1=cython.double,
|
| 33 |
+
x2=cython.double,
|
| 34 |
+
d1=cython.double,
|
| 35 |
+
d2=cython.double,
|
| 36 |
+
scale=cython.double,
|
| 37 |
+
x=cython.double,
|
| 38 |
+
d=cython.double,
|
| 39 |
+
)
|
| 40 |
+
def iup_segment(
|
| 41 |
+
coords: _PointSegment, rc1: _Point, rd1: _Delta, rc2: _Point, rd2: _Delta
|
| 42 |
+
): # -> _DeltaSegment:
|
| 43 |
+
"""Given two reference coordinates `rc1` & `rc2` and their respective
|
| 44 |
+
delta vectors `rd1` & `rd2`, returns interpolated deltas for the set of
|
| 45 |
+
coordinates `coords`."""
|
| 46 |
+
|
| 47 |
+
# rc1 = reference coord 1
|
| 48 |
+
# rd1 = reference delta 1
|
| 49 |
+
out_arrays = [None, None]
|
| 50 |
+
for j in 0, 1:
|
| 51 |
+
out_arrays[j] = out = []
|
| 52 |
+
x1, x2, d1, d2 = rc1[j], rc2[j], rd1[j], rd2[j]
|
| 53 |
+
|
| 54 |
+
if x1 == x2:
|
| 55 |
+
n = len(coords)
|
| 56 |
+
if d1 == d2:
|
| 57 |
+
out.extend([d1] * n)
|
| 58 |
+
else:
|
| 59 |
+
out.extend([0] * n)
|
| 60 |
+
continue
|
| 61 |
+
|
| 62 |
+
if x1 > x2:
|
| 63 |
+
x1, x2 = x2, x1
|
| 64 |
+
d1, d2 = d2, d1
|
| 65 |
+
|
| 66 |
+
# x1 < x2
|
| 67 |
+
scale = (d2 - d1) / (x2 - x1)
|
| 68 |
+
for pair in coords:
|
| 69 |
+
x = pair[j]
|
| 70 |
+
|
| 71 |
+
if x <= x1:
|
| 72 |
+
d = d1
|
| 73 |
+
elif x >= x2:
|
| 74 |
+
d = d2
|
| 75 |
+
else:
|
| 76 |
+
# Interpolate
|
| 77 |
+
#
|
| 78 |
+
# NOTE: we assign an explicit intermediate variable here in
|
| 79 |
+
# order to disable a fused mul-add optimization. See:
|
| 80 |
+
#
|
| 81 |
+
# - https://godbolt.org/z/YsP4T3TqK,
|
| 82 |
+
# - https://github.com/fonttools/fonttools/issues/3703
|
| 83 |
+
nudge = (x - x1) * scale
|
| 84 |
+
d = d1 + nudge
|
| 85 |
+
|
| 86 |
+
out.append(d)
|
| 87 |
+
|
| 88 |
+
return zip(*out_arrays)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def iup_contour(deltas: _DeltaOrNoneSegment, coords: _PointSegment) -> _DeltaSegment:
|
| 92 |
+
"""For the contour given in `coords`, interpolate any missing
|
| 93 |
+
delta values in delta vector `deltas`.
|
| 94 |
+
|
| 95 |
+
Returns fully filled-out delta vector."""
|
| 96 |
+
|
| 97 |
+
assert len(deltas) == len(coords)
|
| 98 |
+
if None not in deltas:
|
| 99 |
+
return deltas
|
| 100 |
+
|
| 101 |
+
n = len(deltas)
|
| 102 |
+
# indices of points with explicit deltas
|
| 103 |
+
indices = [i for i, v in enumerate(deltas) if v is not None]
|
| 104 |
+
if not indices:
|
| 105 |
+
# All deltas are None. Return 0,0 for all.
|
| 106 |
+
return [(0, 0)] * n
|
| 107 |
+
|
| 108 |
+
out = []
|
| 109 |
+
it = iter(indices)
|
| 110 |
+
start = next(it)
|
| 111 |
+
if start != 0:
|
| 112 |
+
# Initial segment that wraps around
|
| 113 |
+
i1, i2, ri1, ri2 = 0, start, start, indices[-1]
|
| 114 |
+
out.extend(
|
| 115 |
+
iup_segment(
|
| 116 |
+
coords[i1:i2], coords[ri1], deltas[ri1], coords[ri2], deltas[ri2]
|
| 117 |
+
)
|
| 118 |
+
)
|
| 119 |
+
out.append(deltas[start])
|
| 120 |
+
for end in it:
|
| 121 |
+
if end - start > 1:
|
| 122 |
+
i1, i2, ri1, ri2 = start + 1, end, start, end
|
| 123 |
+
out.extend(
|
| 124 |
+
iup_segment(
|
| 125 |
+
coords[i1:i2], coords[ri1], deltas[ri1], coords[ri2], deltas[ri2]
|
| 126 |
+
)
|
| 127 |
+
)
|
| 128 |
+
out.append(deltas[end])
|
| 129 |
+
start = end
|
| 130 |
+
if start != n - 1:
|
| 131 |
+
# Final segment that wraps around
|
| 132 |
+
i1, i2, ri1, ri2 = start + 1, n, start, indices[0]
|
| 133 |
+
out.extend(
|
| 134 |
+
iup_segment(
|
| 135 |
+
coords[i1:i2], coords[ri1], deltas[ri1], coords[ri2], deltas[ri2]
|
| 136 |
+
)
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
assert len(deltas) == len(out), (len(deltas), len(out))
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def iup_delta(
|
| 144 |
+
deltas: _DeltaOrNoneSegment, coords: _PointSegment, ends: _Endpoints
|
| 145 |
+
) -> _DeltaSegment:
|
| 146 |
+
"""For the outline given in `coords`, with contour endpoints given
|
| 147 |
+
in sorted increasing order in `ends`, interpolate any missing
|
| 148 |
+
delta values in delta vector `deltas`.
|
| 149 |
+
|
| 150 |
+
Returns fully filled-out delta vector."""
|
| 151 |
+
|
| 152 |
+
assert sorted(ends) == ends and len(coords) == (ends[-1] + 1 if ends else 0) + 4
|
| 153 |
+
n = len(coords)
|
| 154 |
+
ends = ends + [n - 4, n - 3, n - 2, n - 1]
|
| 155 |
+
out = []
|
| 156 |
+
start = 0
|
| 157 |
+
for end in ends:
|
| 158 |
+
end += 1
|
| 159 |
+
contour = iup_contour(deltas[start:end], coords[start:end])
|
| 160 |
+
out.extend(contour)
|
| 161 |
+
start = end
|
| 162 |
+
|
| 163 |
+
return out
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# Optimizer
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
@cython.cfunc
|
| 170 |
+
@cython.inline
|
| 171 |
+
@cython.locals(
|
| 172 |
+
i=cython.int,
|
| 173 |
+
j=cython.int,
|
| 174 |
+
# tolerance=cython.double, # https://github.com/fonttools/fonttools/issues/3282
|
| 175 |
+
x=cython.double,
|
| 176 |
+
y=cython.double,
|
| 177 |
+
p=cython.double,
|
| 178 |
+
q=cython.double,
|
| 179 |
+
)
|
| 180 |
+
@cython.returns(int)
|
| 181 |
+
def can_iup_in_between(
|
| 182 |
+
deltas: _DeltaSegment,
|
| 183 |
+
coords: _PointSegment,
|
| 184 |
+
i: Integral,
|
| 185 |
+
j: Integral,
|
| 186 |
+
tolerance: Real,
|
| 187 |
+
): # -> bool:
|
| 188 |
+
"""Return true if the deltas for points at `i` and `j` (`i < j`) can be
|
| 189 |
+
successfully used to interpolate deltas for points in between them within
|
| 190 |
+
provided error tolerance."""
|
| 191 |
+
|
| 192 |
+
assert j - i >= 2
|
| 193 |
+
interp = iup_segment(coords[i + 1 : j], coords[i], deltas[i], coords[j], deltas[j])
|
| 194 |
+
deltas = deltas[i + 1 : j]
|
| 195 |
+
|
| 196 |
+
return all(
|
| 197 |
+
abs(complex(x - p, y - q)) <= tolerance
|
| 198 |
+
for (x, y), (p, q) in zip(deltas, interp)
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
@cython.locals(
|
| 203 |
+
cj=cython.double,
|
| 204 |
+
dj=cython.double,
|
| 205 |
+
lcj=cython.double,
|
| 206 |
+
ldj=cython.double,
|
| 207 |
+
ncj=cython.double,
|
| 208 |
+
ndj=cython.double,
|
| 209 |
+
force=cython.int,
|
| 210 |
+
forced=set,
|
| 211 |
+
)
|
| 212 |
+
def _iup_contour_bound_forced_set(
|
| 213 |
+
deltas: _DeltaSegment, coords: _PointSegment, tolerance: Real = 0
|
| 214 |
+
) -> set:
|
| 215 |
+
"""The forced set is a conservative set of points on the contour that must be encoded
|
| 216 |
+
explicitly (ie. cannot be interpolated). Calculating this set allows for significantly
|
| 217 |
+
speeding up the dynamic-programming, as well as resolve circularity in DP.
|
| 218 |
+
|
| 219 |
+
The set is precise; that is, if an index is in the returned set, then there is no way
|
| 220 |
+
that IUP can generate delta for that point, given `coords` and `deltas`.
|
| 221 |
+
"""
|
| 222 |
+
assert len(deltas) == len(coords)
|
| 223 |
+
|
| 224 |
+
n = len(deltas)
|
| 225 |
+
forced = set()
|
| 226 |
+
# Track "last" and "next" points on the contour as we sweep.
|
| 227 |
+
for i in range(len(deltas) - 1, -1, -1):
|
| 228 |
+
ld, lc = deltas[i - 1], coords[i - 1]
|
| 229 |
+
d, c = deltas[i], coords[i]
|
| 230 |
+
nd, nc = deltas[i - n + 1], coords[i - n + 1]
|
| 231 |
+
|
| 232 |
+
for j in (0, 1): # For X and for Y
|
| 233 |
+
cj = c[j]
|
| 234 |
+
dj = d[j]
|
| 235 |
+
lcj = lc[j]
|
| 236 |
+
ldj = ld[j]
|
| 237 |
+
ncj = nc[j]
|
| 238 |
+
ndj = nd[j]
|
| 239 |
+
|
| 240 |
+
if lcj <= ncj:
|
| 241 |
+
c1, c2 = lcj, ncj
|
| 242 |
+
d1, d2 = ldj, ndj
|
| 243 |
+
else:
|
| 244 |
+
c1, c2 = ncj, lcj
|
| 245 |
+
d1, d2 = ndj, ldj
|
| 246 |
+
|
| 247 |
+
force = False
|
| 248 |
+
|
| 249 |
+
# If the two coordinates are the same, then the interpolation
|
| 250 |
+
# algorithm produces the same delta if both deltas are equal,
|
| 251 |
+
# and zero if they differ.
|
| 252 |
+
#
|
| 253 |
+
# This test has to be before the next one.
|
| 254 |
+
if c1 == c2:
|
| 255 |
+
if abs(d1 - d2) > tolerance and abs(dj) > tolerance:
|
| 256 |
+
force = True
|
| 257 |
+
|
| 258 |
+
# If coordinate for current point is between coordinate of adjacent
|
| 259 |
+
# points on the two sides, but the delta for current point is NOT
|
| 260 |
+
# between delta for those adjacent points (considering tolerance
|
| 261 |
+
# allowance), then there is no way that current point can be IUP-ed.
|
| 262 |
+
# Mark it forced.
|
| 263 |
+
elif c1 <= cj <= c2: # and c1 != c2
|
| 264 |
+
if not (min(d1, d2) - tolerance <= dj <= max(d1, d2) + tolerance):
|
| 265 |
+
force = True
|
| 266 |
+
|
| 267 |
+
# Otherwise, the delta should either match the closest, or have the
|
| 268 |
+
# same sign as the interpolation of the two deltas.
|
| 269 |
+
else: # cj < c1 or c2 < cj
|
| 270 |
+
if d1 != d2:
|
| 271 |
+
if cj < c1:
|
| 272 |
+
if (
|
| 273 |
+
abs(dj) > tolerance
|
| 274 |
+
and abs(dj - d1) > tolerance
|
| 275 |
+
and ((dj - tolerance < d1) != (d1 < d2))
|
| 276 |
+
):
|
| 277 |
+
force = True
|
| 278 |
+
else: # c2 < cj
|
| 279 |
+
if (
|
| 280 |
+
abs(dj) > tolerance
|
| 281 |
+
and abs(dj - d2) > tolerance
|
| 282 |
+
and ((d2 < dj + tolerance) != (d1 < d2))
|
| 283 |
+
):
|
| 284 |
+
force = True
|
| 285 |
+
|
| 286 |
+
if force:
|
| 287 |
+
forced.add(i)
|
| 288 |
+
break
|
| 289 |
+
|
| 290 |
+
return forced
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
@cython.locals(
|
| 294 |
+
i=cython.int,
|
| 295 |
+
j=cython.int,
|
| 296 |
+
best_cost=cython.double,
|
| 297 |
+
best_j=cython.int,
|
| 298 |
+
cost=cython.double,
|
| 299 |
+
forced=set,
|
| 300 |
+
tolerance=cython.double,
|
| 301 |
+
)
|
| 302 |
+
def _iup_contour_optimize_dp(
|
| 303 |
+
deltas: _DeltaSegment,
|
| 304 |
+
coords: _PointSegment,
|
| 305 |
+
forced=set(),
|
| 306 |
+
tolerance: Real = 0,
|
| 307 |
+
lookback: Integral = None,
|
| 308 |
+
):
|
| 309 |
+
"""Straightforward Dynamic-Programming. For each index i, find least-costly encoding of
|
| 310 |
+
points 0 to i where i is explicitly encoded. We find this by considering all previous
|
| 311 |
+
explicit points j and check whether interpolation can fill points between j and i.
|
| 312 |
+
|
| 313 |
+
Note that solution always encodes last point explicitly. Higher-level is responsible
|
| 314 |
+
for removing that restriction.
|
| 315 |
+
|
| 316 |
+
As major speedup, we stop looking further whenever we see a "forced" point."""
|
| 317 |
+
|
| 318 |
+
n = len(deltas)
|
| 319 |
+
if lookback is None:
|
| 320 |
+
lookback = n
|
| 321 |
+
lookback = min(lookback, MAX_LOOKBACK)
|
| 322 |
+
costs = {-1: 0}
|
| 323 |
+
chain = {-1: None}
|
| 324 |
+
for i in range(0, n):
|
| 325 |
+
best_cost = costs[i - 1] + 1
|
| 326 |
+
|
| 327 |
+
costs[i] = best_cost
|
| 328 |
+
chain[i] = i - 1
|
| 329 |
+
|
| 330 |
+
if i - 1 in forced:
|
| 331 |
+
continue
|
| 332 |
+
|
| 333 |
+
for j in range(i - 2, max(i - lookback, -2), -1):
|
| 334 |
+
cost = costs[j] + 1
|
| 335 |
+
|
| 336 |
+
if cost < best_cost and can_iup_in_between(deltas, coords, j, i, tolerance):
|
| 337 |
+
costs[i] = best_cost = cost
|
| 338 |
+
chain[i] = j
|
| 339 |
+
|
| 340 |
+
if j in forced:
|
| 341 |
+
break
|
| 342 |
+
|
| 343 |
+
return chain, costs
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def _rot_list(l: list, k: int):
|
| 347 |
+
"""Rotate list by k items forward. Ie. item at position 0 will be
|
| 348 |
+
at position k in returned list. Negative k is allowed."""
|
| 349 |
+
n = len(l)
|
| 350 |
+
k %= n
|
| 351 |
+
if not k:
|
| 352 |
+
return l
|
| 353 |
+
return l[n - k :] + l[: n - k]
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
def _rot_set(s: set, k: int, n: int):
|
| 357 |
+
k %= n
|
| 358 |
+
if not k:
|
| 359 |
+
return s
|
| 360 |
+
return {(v + k) % n for v in s}
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def iup_contour_optimize(
|
| 364 |
+
deltas: _DeltaSegment, coords: _PointSegment, tolerance: Real = 0.0
|
| 365 |
+
) -> _DeltaOrNoneSegment:
|
| 366 |
+
"""For contour with coordinates `coords`, optimize a set of delta
|
| 367 |
+
values `deltas` within error `tolerance`.
|
| 368 |
+
|
| 369 |
+
Returns delta vector that has most number of None items instead of
|
| 370 |
+
the input delta.
|
| 371 |
+
"""
|
| 372 |
+
|
| 373 |
+
n = len(deltas)
|
| 374 |
+
|
| 375 |
+
# Get the easy cases out of the way:
|
| 376 |
+
|
| 377 |
+
# If all are within tolerance distance of 0, encode nothing:
|
| 378 |
+
if all(abs(complex(*p)) <= tolerance for p in deltas):
|
| 379 |
+
return [None] * n
|
| 380 |
+
|
| 381 |
+
# If there's exactly one point, return it:
|
| 382 |
+
if n == 1:
|
| 383 |
+
return deltas
|
| 384 |
+
|
| 385 |
+
# If all deltas are exactly the same, return just one (the first one):
|
| 386 |
+
d0 = deltas[0]
|
| 387 |
+
if all(d0 == d for d in deltas):
|
| 388 |
+
return [d0] + [None] * (n - 1)
|
| 389 |
+
|
| 390 |
+
# Else, solve the general problem using Dynamic Programming.
|
| 391 |
+
|
| 392 |
+
forced = _iup_contour_bound_forced_set(deltas, coords, tolerance)
|
| 393 |
+
# The _iup_contour_optimize_dp() routine returns the optimal encoding
|
| 394 |
+
# solution given the constraint that the last point is always encoded.
|
| 395 |
+
# To remove this constraint, we use two different methods, depending on
|
| 396 |
+
# whether forced set is non-empty or not:
|
| 397 |
+
|
| 398 |
+
# Debugging: Make the next if always take the second branch and observe
|
| 399 |
+
# if the font size changes (reduced); that would mean the forced-set
|
| 400 |
+
# has members it should not have.
|
| 401 |
+
if forced:
|
| 402 |
+
# Forced set is non-empty: rotate the contour start point
|
| 403 |
+
# such that the last point in the list is a forced point.
|
| 404 |
+
k = (n - 1) - max(forced)
|
| 405 |
+
assert k >= 0
|
| 406 |
+
|
| 407 |
+
deltas = _rot_list(deltas, k)
|
| 408 |
+
coords = _rot_list(coords, k)
|
| 409 |
+
forced = _rot_set(forced, k, n)
|
| 410 |
+
|
| 411 |
+
# Debugging: Pass a set() instead of forced variable to the next call
|
| 412 |
+
# to exercise forced-set computation for under-counting.
|
| 413 |
+
chain, costs = _iup_contour_optimize_dp(deltas, coords, forced, tolerance)
|
| 414 |
+
|
| 415 |
+
# Assemble solution.
|
| 416 |
+
solution = set()
|
| 417 |
+
i = n - 1
|
| 418 |
+
while i is not None:
|
| 419 |
+
solution.add(i)
|
| 420 |
+
i = chain[i]
|
| 421 |
+
solution.remove(-1)
|
| 422 |
+
|
| 423 |
+
# if not forced <= solution:
|
| 424 |
+
# print("coord", coords)
|
| 425 |
+
# print("deltas", deltas)
|
| 426 |
+
# print("len", len(deltas))
|
| 427 |
+
assert forced <= solution, (forced, solution)
|
| 428 |
+
|
| 429 |
+
deltas = [deltas[i] if i in solution else None for i in range(n)]
|
| 430 |
+
|
| 431 |
+
deltas = _rot_list(deltas, -k)
|
| 432 |
+
else:
|
| 433 |
+
# Repeat the contour an extra time, solve the new case, then look for solutions of the
|
| 434 |
+
# circular n-length problem in the solution for new linear case. I cannot prove that
|
| 435 |
+
# this always produces the optimal solution...
|
| 436 |
+
chain, costs = _iup_contour_optimize_dp(
|
| 437 |
+
deltas + deltas, coords + coords, forced, tolerance, n
|
| 438 |
+
)
|
| 439 |
+
best_sol, best_cost = None, n + 1
|
| 440 |
+
|
| 441 |
+
for start in range(n - 1, len(costs) - 1):
|
| 442 |
+
# Assemble solution.
|
| 443 |
+
solution = set()
|
| 444 |
+
i = start
|
| 445 |
+
while i > start - n:
|
| 446 |
+
solution.add(i % n)
|
| 447 |
+
i = chain[i]
|
| 448 |
+
if i == start - n:
|
| 449 |
+
cost = costs[start] - costs[start - n]
|
| 450 |
+
if cost <= best_cost:
|
| 451 |
+
best_sol, best_cost = solution, cost
|
| 452 |
+
|
| 453 |
+
# if not forced <= best_sol:
|
| 454 |
+
# print("coord", coords)
|
| 455 |
+
# print("deltas", deltas)
|
| 456 |
+
# print("len", len(deltas))
|
| 457 |
+
assert forced <= best_sol, (forced, best_sol)
|
| 458 |
+
|
| 459 |
+
deltas = [deltas[i] if i in best_sol else None for i in range(n)]
|
| 460 |
+
|
| 461 |
+
return deltas
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def iup_delta_optimize(
|
| 465 |
+
deltas: _DeltaSegment,
|
| 466 |
+
coords: _PointSegment,
|
| 467 |
+
ends: _Endpoints,
|
| 468 |
+
tolerance: Real = 0.0,
|
| 469 |
+
) -> _DeltaOrNoneSegment:
|
| 470 |
+
"""For the outline given in `coords`, with contour endpoints given
|
| 471 |
+
in sorted increasing order in `ends`, optimize a set of delta
|
| 472 |
+
values `deltas` within error `tolerance`.
|
| 473 |
+
|
| 474 |
+
Returns delta vector that has most number of None items instead of
|
| 475 |
+
the input delta.
|
| 476 |
+
"""
|
| 477 |
+
assert sorted(ends) == ends and len(coords) == (ends[-1] + 1 if ends else 0) + 4
|
| 478 |
+
n = len(coords)
|
| 479 |
+
ends = ends + [n - 4, n - 3, n - 2, n - 1]
|
| 480 |
+
out = []
|
| 481 |
+
start = 0
|
| 482 |
+
for end in ends:
|
| 483 |
+
contour = iup_contour_optimize(
|
| 484 |
+
deltas[start : end + 1], coords[start : end + 1], tolerance
|
| 485 |
+
)
|
| 486 |
+
assert len(contour) == end - start + 1
|
| 487 |
+
out.extend(contour)
|
| 488 |
+
start = end + 1
|
| 489 |
+
|
| 490 |
+
return out
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/merger.py
ADDED
|
@@ -0,0 +1,1717 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ging
|
| 10 |
+
from fontTools.colorLib.builder import MAX_PAINT_COLR_LAYER_COUNT, LayerReuseCache
|
| 11 |
+
from fontTools.misc import classifyTools
|
| 12 |
+
from fontTools.misc.roundTools import otRound
|
| 13 |
+
from fontTools.misc.treeTools import build_n_ary_tree
|
| 14 |
+
from fontTools.ttLib.tables import otTables as ot
|
| 15 |
+
from fontTools.ttLib.tables import otBase as otBase
|
| 16 |
+
from fontTools.ttLib.tables.otConverters import BaseFixedValue
|
| 17 |
+
from fontTools.ttLib.tables.otTraverse import dfs_base_table
|
| 18 |
+
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
| 19 |
+
from fontTools.varLib import builder, models, varStore
|
| 20 |
+
from fontTools.varLib.models import nonNone, allNone, allEqual, allEqualTo, subList
|
| 21 |
+
from fontTools.varLib.varStore import VarStoreInstancer
|
| 22 |
+
from functools import reduce
|
| 23 |
+
from fontTools.otlLib.builder import buildSinglePos
|
| 24 |
+
from fontTools.otlLib.optimize.gpos import (
|
| 25 |
+
_compression_level_from_env,
|
| 26 |
+
compact_pair_pos,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
log = logging.getLogger("fontTools.varLib.merger")
|
| 30 |
+
|
| 31 |
+
from .errors import (
|
| 32 |
+
ShouldBeConstant,
|
| 33 |
+
FoundANone,
|
| 34 |
+
MismatchedTypes,
|
| 35 |
+
NotANone,
|
| 36 |
+
LengthsDiffer,
|
| 37 |
+
KeysDiffer,
|
| 38 |
+
InconsistentGlyphOrder,
|
| 39 |
+
InconsistentExtensions,
|
| 40 |
+
InconsistentFormats,
|
| 41 |
+
UnsupportedFormat,
|
| 42 |
+
VarLibMergeError,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Merger(object):
|
| 47 |
+
def __init__(self, font=None):
|
| 48 |
+
self.font = font
|
| 49 |
+
# mergeTables populates this from the parent's master ttfs
|
| 50 |
+
self.ttfs = None
|
| 51 |
+
|
| 52 |
+
@classmethod
|
| 53 |
+
def merger(celf, clazzes, attrs=(None,)):
|
| 54 |
+
assert celf != Merger, "Subclass Merger instead."
|
| 55 |
+
if "mergers" not in celf.__dict__:
|
| 56 |
+
celf.mergers = {}
|
| 57 |
+
if type(clazzes) in (type, enum.EnumMeta):
|
| 58 |
+
clazzes = (clazzes,)
|
| 59 |
+
if type(attrs) == str:
|
| 60 |
+
attrs = (attrs,)
|
| 61 |
+
|
| 62 |
+
def wrapper(method):
|
| 63 |
+
assert method.__name__ == "merge"
|
| 64 |
+
done = []
|
| 65 |
+
for clazz in clazzes:
|
| 66 |
+
if clazz in done:
|
| 67 |
+
continue # Support multiple names of a clazz
|
| 68 |
+
done.append(clazz)
|
| 69 |
+
mergers = celf.mergers.setdefault(clazz, {})
|
| 70 |
+
for attr in attrs:
|
| 71 |
+
assert attr not in mergers, (
|
| 72 |
+
"Oops, class '%s' has merge function for '%s' defined already."
|
| 73 |
+
% (clazz.__name__, attr)
|
| 74 |
+
)
|
| 75 |
+
mergers[attr] = method
|
| 76 |
+
return None
|
| 77 |
+
|
| 78 |
+
return wrapper
|
| 79 |
+
|
| 80 |
+
@classmethod
|
| 81 |
+
def mergersFor(celf, thing, _default={}):
|
| 82 |
+
typ = type(thing)
|
| 83 |
+
|
| 84 |
+
for celf in celf.mro():
|
| 85 |
+
mergers = getattr(celf, "mergers", None)
|
| 86 |
+
if mergers is None:
|
| 87 |
+
break
|
| 88 |
+
|
| 89 |
+
m = celf.mergers.get(typ, None)
|
| 90 |
+
if m is not None:
|
| 91 |
+
return m
|
| 92 |
+
|
| 93 |
+
return _default
|
| 94 |
+
|
| 95 |
+
def mergeObjects(self, out, lst, exclude=()):
|
| 96 |
+
if hasattr(out, "ensureDecompiled"):
|
| 97 |
+
out.ensureDecompiled(recurse=False)
|
| 98 |
+
for item in lst:
|
| 99 |
+
if hasattr(item, "ensureDecompiled"):
|
| 100 |
+
item.ensureDecompiled(recurse=False)
|
| 101 |
+
keys = sorted(vars(out).keys())
|
| 102 |
+
if not all(keys == sorted(vars(v).keys()) for v in lst):
|
| 103 |
+
raise KeysDiffer(
|
| 104 |
+
self, expected=keys, got=[sorted(vars(v).keys()) for v in lst]
|
| 105 |
+
)
|
| 106 |
+
mergers = self.mergersFor(out)
|
| 107 |
+
defaultMerger = mergers.get("*", self.__class__.mergeThings)
|
| 108 |
+
try:
|
| 109 |
+
for key in keys:
|
| 110 |
+
if key in exclude:
|
| 111 |
+
continue
|
| 112 |
+
value = getattr(out, key)
|
| 113 |
+
values = [getattr(table, key) for table in lst]
|
| 114 |
+
mergerFunc = mergers.get(key, defaultMerger)
|
| 115 |
+
mergerFunc(self, value, values)
|
| 116 |
+
except VarLibMergeError as e:
|
| 117 |
+
e.stack.append("." + key)
|
| 118 |
+
raise
|
| 119 |
+
|
| 120 |
+
def mergeLists(self, out, lst):
|
| 121 |
+
if not allEqualTo(out, lst, len):
|
| 122 |
+
raise LengthsDiffer(self, expected=len(out), got=[len(x) for x in lst])
|
| 123 |
+
for i, (value, values) in enumerate(zip(out, zip(*lst))):
|
| 124 |
+
try:
|
| 125 |
+
self.mergeThings(value, values)
|
| 126 |
+
except VarLibMergeError as e:
|
| 127 |
+
e.stack.append("[%d]" % i)
|
| 128 |
+
raise
|
| 129 |
+
|
| 130 |
+
def mergeThings(self, out, lst):
|
| 131 |
+
if not allEqualTo(out, lst, type):
|
| 132 |
+
raise MismatchedTypes(
|
| 133 |
+
self, expected=type(out).__name__, got=[type(x).__name__ for x in lst]
|
| 134 |
+
)
|
| 135 |
+
mergerFunc = self.mergersFor(out).get(None, None)
|
| 136 |
+
if mergerFunc is not None:
|
| 137 |
+
mergerFunc(self, out, lst)
|
| 138 |
+
elif isinstance(out, enum.Enum):
|
| 139 |
+
# need to special-case Enums as have __dict__ but are not regular 'objects',
|
| 140 |
+
# otherwise mergeObjects/mergeThings get trapped in a RecursionError
|
| 141 |
+
if not allEqualTo(out, lst):
|
| 142 |
+
raise ShouldBeConstant(self, expected=out, got=lst)
|
| 143 |
+
elif hasattr(out, "__dict__"):
|
| 144 |
+
self.mergeObjects(out, lst)
|
| 145 |
+
elif isinstance(out, list):
|
| 146 |
+
self.mergeLists(out, lst)
|
| 147 |
+
else:
|
| 148 |
+
if not allEqualTo(out, lst):
|
| 149 |
+
raise ShouldBeConstant(self, expected=out, got=lst)
|
| 150 |
+
|
| 151 |
+
def mergeTables(self, font, master_ttfs, tableTags):
|
| 152 |
+
for tag in tableTags:
|
| 153 |
+
if tag not in font:
|
| 154 |
+
continue
|
| 155 |
+
try:
|
| 156 |
+
self.ttfs = master_ttfs
|
| 157 |
+
self.mergeThings(font[tag], [m.get(tag) for m in master_ttfs])
|
| 158 |
+
except VarLibMergeError as e:
|
| 159 |
+
e.stack.append(tag)
|
| 160 |
+
raise
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
#
|
| 164 |
+
# Aligning merger
|
| 165 |
+
#
|
| 166 |
+
class AligningMerger(Merger):
|
| 167 |
+
pass
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@AligningMerger.merger(ot.GDEF, "GlyphClassDef")
|
| 171 |
+
def merge(merger, self, lst):
|
| 172 |
+
if self is None:
|
| 173 |
+
if not allNone(lst):
|
| 174 |
+
raise NotANone(merger, expected=None, got=lst)
|
| 175 |
+
return
|
| 176 |
+
|
| 177 |
+
lst = [l.classDefs for l in lst]
|
| 178 |
+
self.classDefs = {}
|
| 179 |
+
# We only care about the .classDefs
|
| 180 |
+
self = self.classDefs
|
| 181 |
+
|
| 182 |
+
allKeys = set()
|
| 183 |
+
allKeys.update(*[l.keys() for l in lst])
|
| 184 |
+
for k in allKeys:
|
| 185 |
+
allValues = nonNone(l.get(k) for l in lst)
|
| 186 |
+
if not allEqual(allValues):
|
| 187 |
+
raise ShouldBeConstant(
|
| 188 |
+
merger, expected=allValues[0], got=lst, stack=["." + k]
|
| 189 |
+
)
|
| 190 |
+
if not allValues:
|
| 191 |
+
self[k] = None
|
| 192 |
+
else:
|
| 193 |
+
self[k] = allValues[0]
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _SinglePosUpgradeToFormat2(self):
|
| 197 |
+
if self.Format == 2:
|
| 198 |
+
return self
|
| 199 |
+
|
| 200 |
+
ret = ot.SinglePos()
|
| 201 |
+
ret.Format = 2
|
| 202 |
+
ret.Coverage = self.Coverage
|
| 203 |
+
ret.ValueFormat = self.ValueFormat
|
| 204 |
+
ret.Value = [self.Value for _ in ret.Coverage.glyphs]
|
| 205 |
+
ret.ValueCount = len(ret.Value)
|
| 206 |
+
|
| 207 |
+
return ret
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def _merge_GlyphOrders(font, lst, values_lst=None, default=None):
|
| 211 |
+
"""Takes font and list of glyph lists (must be sorted by glyph id), and returns
|
| 212 |
+
two things:
|
| 213 |
+
- Combined glyph list,
|
| 214 |
+
- If values_lst is None, return input glyph lists, but padded with None when a glyph
|
| 215 |
+
was missing in a list. Otherwise, return values_lst list-of-list, padded with None
|
| 216 |
+
to match combined glyph lists.
|
| 217 |
+
"""
|
| 218 |
+
if values_lst is None:
|
| 219 |
+
dict_sets = [set(l) for l in lst]
|
| 220 |
+
else:
|
| 221 |
+
dict_sets = [{g: v for g, v in zip(l, vs)} for l, vs in zip(lst, values_lst)]
|
| 222 |
+
combined = set()
|
| 223 |
+
combined.update(*dict_sets)
|
| 224 |
+
|
| 225 |
+
sortKey = font.getReverseGlyphMap().__getitem__
|
| 226 |
+
order = sorted(combined, key=sortKey)
|
| 227 |
+
# Make sure all input glyphsets were in proper order
|
| 228 |
+
if not all(sorted(vs, key=sortKey) == vs for vs in lst):
|
| 229 |
+
raise InconsistentGlyphOrder()
|
| 230 |
+
del combined
|
| 231 |
+
|
| 232 |
+
paddedValues = None
|
| 233 |
+
if values_lst is None:
|
| 234 |
+
padded = [
|
| 235 |
+
[glyph if glyph in dict_set else default for glyph in order]
|
| 236 |
+
for dict_set in dict_sets
|
| 237 |
+
]
|
| 238 |
+
else:
|
| 239 |
+
assert len(lst) == len(values_lst)
|
| 240 |
+
padded = [
|
| 241 |
+
[dict_set[glyph] if glyph in dict_set else default for glyph in order]
|
| 242 |
+
for dict_set in dict_sets
|
| 243 |
+
]
|
| 244 |
+
return order, padded
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@AligningMerger.merger(otBase.ValueRecord)
|
| 248 |
+
def merge(merger, self, lst):
|
| 249 |
+
# Code below sometimes calls us with self being
|
| 250 |
+
# a new object. Copy it from lst and recurse.
|
| 251 |
+
self.__dict__ = lst[0].__dict__.copy()
|
| 252 |
+
merger.mergeObjects(self, lst)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
@AligningMerger.merger(ot.Anchor)
|
| 256 |
+
def merge(merger, self, lst):
|
| 257 |
+
# Code below sometimes calls us with self being
|
| 258 |
+
# a new object. Copy it from lst and recurse.
|
| 259 |
+
self.__dict__ = lst[0].__dict__.copy()
|
| 260 |
+
merger.mergeObjects(self, lst)
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def _Lookup_SinglePos_get_effective_value(merger, subtables, glyph):
|
| 264 |
+
for self in subtables:
|
| 265 |
+
if (
|
| 266 |
+
self is None
|
| 267 |
+
or type(self) != ot.SinglePos
|
| 268 |
+
or self.Coverage is None
|
| 269 |
+
or glyph not in self.Coverage.glyphs
|
| 270 |
+
):
|
| 271 |
+
continue
|
| 272 |
+
if self.Format == 1:
|
| 273 |
+
return self.Value
|
| 274 |
+
elif self.Format == 2:
|
| 275 |
+
return self.Value[self.Coverage.glyphs.index(glyph)]
|
| 276 |
+
else:
|
| 277 |
+
raise UnsupportedFormat(merger, subtable="single positioning lookup")
|
| 278 |
+
return None
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def _Lookup_PairPos_get_effective_value_pair(
|
| 282 |
+
merger, subtables, firstGlyph, secondGlyph
|
| 283 |
+
):
|
| 284 |
+
for self in subtables:
|
| 285 |
+
if (
|
| 286 |
+
self is None
|
| 287 |
+
or type(self) != ot.PairPos
|
| 288 |
+
or self.Coverage is None
|
| 289 |
+
or firstGlyph not in self.Coverage.glyphs
|
| 290 |
+
):
|
| 291 |
+
continue
|
| 292 |
+
if self.Format == 1:
|
| 293 |
+
ps = self.PairSet[self.Coverage.glyphs.index(firstGlyph)]
|
| 294 |
+
pvr = ps.PairValueRecord
|
| 295 |
+
for rec in pvr: # TODO Speed up
|
| 296 |
+
if rec.SecondGlyph == secondGlyph:
|
| 297 |
+
return rec
|
| 298 |
+
continue
|
| 299 |
+
elif self.Format == 2:
|
| 300 |
+
klass1 = self.ClassDef1.classDefs.get(firstGlyph, 0)
|
| 301 |
+
klass2 = self.ClassDef2.classDefs.get(secondGlyph, 0)
|
| 302 |
+
return self.Class1Record[klass1].Class2Record[klass2]
|
| 303 |
+
else:
|
| 304 |
+
raise UnsupportedFormat(merger, subtable="pair positioning lookup")
|
| 305 |
+
return None
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
@AligningMerger.merger(ot.SinglePos)
|
| 309 |
+
def merge(merger, self, lst):
|
| 310 |
+
self.ValueFormat = valueFormat = reduce(int.__or__, [l.ValueFormat for l in lst], 0)
|
| 311 |
+
if not (len(lst) == 1 or (valueFormat & ~0xF == 0)):
|
| 312 |
+
raise UnsupportedFormat(merger, subtable="single positioning lookup")
|
| 313 |
+
|
| 314 |
+
# If all have same coverage table and all are format 1,
|
| 315 |
+
coverageGlyphs = self.Coverage.glyphs
|
| 316 |
+
if all(v.Format == 1 for v in lst) and all(
|
| 317 |
+
coverageGlyphs == v.Coverage.glyphs for v in lst
|
| 318 |
+
):
|
| 319 |
+
self.Value = otBase.ValueRecord(valueFormat, self.Value)
|
| 320 |
+
if valueFormat != 0:
|
| 321 |
+
# If v.Value is None, it means a kerning of 0; we want
|
| 322 |
+
# it to participate in the model still.
|
| 323 |
+
# https://github.com/fonttools/fonttools/issues/3111
|
| 324 |
+
merger.mergeThings(
|
| 325 |
+
self.Value,
|
| 326 |
+
[v.Value if v.Value is not None else otBase.ValueRecord() for v in lst],
|
| 327 |
+
)
|
| 328 |
+
self.ValueFormat = self.Value.getFormat()
|
| 329 |
+
return
|
| 330 |
+
|
| 331 |
+
# Upgrade everything to Format=2
|
| 332 |
+
self.Format = 2
|
| 333 |
+
lst = [_SinglePosUpgradeToFormat2(v) for v in lst]
|
| 334 |
+
|
| 335 |
+
# Align them
|
| 336 |
+
glyphs, padded = _merge_GlyphOrders(
|
| 337 |
+
merger.font, [v.Coverage.glyphs for v in lst], [v.Value for v in lst]
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
self.Coverage.glyphs = glyphs
|
| 341 |
+
self.Value = [otBase.ValueRecord(valueFormat) for _ in glyphs]
|
| 342 |
+
self.ValueCount = len(self.Value)
|
| 343 |
+
|
| 344 |
+
for i, values in enumerate(padded):
|
| 345 |
+
for j, glyph in enumerate(glyphs):
|
| 346 |
+
if values[j] is not None:
|
| 347 |
+
continue
|
| 348 |
+
# Fill in value from other subtables
|
| 349 |
+
# Note!!! This *might* result in behavior change if ValueFormat2-zeroedness
|
| 350 |
+
# is different between used subtable and current subtable!
|
| 351 |
+
# TODO(behdad) Check and warn if that happens?
|
| 352 |
+
v = _Lookup_SinglePos_get_effective_value(
|
| 353 |
+
merger, merger.lookup_subtables[i], glyph
|
| 354 |
+
)
|
| 355 |
+
if v is None:
|
| 356 |
+
v = otBase.ValueRecord(valueFormat)
|
| 357 |
+
values[j] = v
|
| 358 |
+
|
| 359 |
+
merger.mergeLists(self.Value, padded)
|
| 360 |
+
|
| 361 |
+
# Merge everything else; though, there shouldn't be anything else. :)
|
| 362 |
+
merger.mergeObjects(
|
| 363 |
+
self, lst, exclude=("Format", "Coverage", "Value", "ValueCount", "ValueFormat")
|
| 364 |
+
)
|
| 365 |
+
self.ValueFormat = reduce(
|
| 366 |
+
int.__or__, [v.getEffectiveFormat() for v in self.Value], 0
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
@AligningMerger.merger(ot.PairSet)
|
| 371 |
+
def merge(merger, self, lst):
|
| 372 |
+
# Align them
|
| 373 |
+
glyphs, padded = _merge_GlyphOrders(
|
| 374 |
+
merger.font,
|
| 375 |
+
[[v.SecondGlyph for v in vs.PairValueRecord] for vs in lst],
|
| 376 |
+
[vs.PairValueRecord for vs in lst],
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
self.PairValueRecord = pvrs = []
|
| 380 |
+
for glyph in glyphs:
|
| 381 |
+
pvr = ot.PairValueRecord()
|
| 382 |
+
pvr.SecondGlyph = glyph
|
| 383 |
+
pvr.Value1 = (
|
| 384 |
+
otBase.ValueRecord(merger.valueFormat1) if merger.valueFormat1 else None
|
| 385 |
+
)
|
| 386 |
+
pvr.Value2 = (
|
| 387 |
+
otBase.ValueRecord(merger.valueFormat2) if merger.valueFormat2 else None
|
| 388 |
+
)
|
| 389 |
+
pvrs.append(pvr)
|
| 390 |
+
self.PairValueCount = len(self.PairValueRecord)
|
| 391 |
+
|
| 392 |
+
for i, values in enumerate(padded):
|
| 393 |
+
for j, glyph in enumerate(glyphs):
|
| 394 |
+
# Fill in value from other subtables
|
| 395 |
+
v = ot.PairValueRecord()
|
| 396 |
+
v.SecondGlyph = glyph
|
| 397 |
+
if values[j] is not None:
|
| 398 |
+
vpair = values[j]
|
| 399 |
+
else:
|
| 400 |
+
vpair = _Lookup_PairPos_get_effective_value_pair(
|
| 401 |
+
merger, merger.lookup_subtables[i], self._firstGlyph, glyph
|
| 402 |
+
)
|
| 403 |
+
if vpair is None:
|
| 404 |
+
v1, v2 = None, None
|
| 405 |
+
else:
|
| 406 |
+
v1 = getattr(vpair, "Value1", None)
|
| 407 |
+
v2 = getattr(vpair, "Value2", None)
|
| 408 |
+
v.Value1 = (
|
| 409 |
+
otBase.ValueRecord(merger.valueFormat1, src=v1)
|
| 410 |
+
if merger.valueFormat1
|
| 411 |
+
else None
|
| 412 |
+
)
|
| 413 |
+
v.Value2 = (
|
| 414 |
+
otBase.ValueRecord(merger.valueFormat2, src=v2)
|
| 415 |
+
if merger.valueFormat2
|
| 416 |
+
else None
|
| 417 |
+
)
|
| 418 |
+
values[j] = v
|
| 419 |
+
del self._firstGlyph
|
| 420 |
+
|
| 421 |
+
merger.mergeLists(self.PairValueRecord, padded)
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def _PairPosFormat1_merge(self, lst, merger):
|
| 425 |
+
assert allEqual(
|
| 426 |
+
[l.ValueFormat2 == 0 for l in lst if l.PairSet]
|
| 427 |
+
), "Report bug against fonttools."
|
| 428 |
+
|
| 429 |
+
# Merge everything else; makes sure Format is the same.
|
| 430 |
+
merger.mergeObjects(
|
| 431 |
+
self,
|
| 432 |
+
lst,
|
| 433 |
+
exclude=("Coverage", "PairSet", "PairSetCount", "ValueFormat1", "ValueFormat2"),
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
empty = ot.PairSet()
|
| 437 |
+
empty.PairValueRecord = []
|
| 438 |
+
empty.PairValueCount = 0
|
| 439 |
+
|
| 440 |
+
# Align them
|
| 441 |
+
glyphs, padded = _merge_GlyphOrders(
|
| 442 |
+
merger.font,
|
| 443 |
+
[v.Coverage.glyphs for v in lst],
|
| 444 |
+
[v.PairSet for v in lst],
|
| 445 |
+
default=empty,
|
| 446 |
+
)
|
| 447 |
+
|
| 448 |
+
self.Coverage.glyphs = glyphs
|
| 449 |
+
self.PairSet = [ot.PairSet() for _ in glyphs]
|
| 450 |
+
self.PairSetCount = len(self.PairSet)
|
| 451 |
+
for glyph, ps in zip(glyphs, self.PairSet):
|
| 452 |
+
ps._firstGlyph = glyph
|
| 453 |
+
|
| 454 |
+
merger.mergeLists(self.PairSet, padded)
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
def _ClassDef_invert(self, allGlyphs=None):
|
| 458 |
+
if isinstance(self, dict):
|
| 459 |
+
classDefs = self
|
| 460 |
+
else:
|
| 461 |
+
classDefs = self.classDefs if self and self.classDefs else {}
|
| 462 |
+
m = max(classDefs.values()) if classDefs else 0
|
| 463 |
+
|
| 464 |
+
ret = []
|
| 465 |
+
for _ in range(m + 1):
|
| 466 |
+
ret.append(set())
|
| 467 |
+
|
| 468 |
+
for k, v in classDefs.items():
|
| 469 |
+
ret[v].add(k)
|
| 470 |
+
|
| 471 |
+
# Class-0 is special. It's "everything else".
|
| 472 |
+
if allGlyphs is None:
|
| 473 |
+
ret[0] = None
|
| 474 |
+
else:
|
| 475 |
+
# Limit all classes to glyphs in allGlyphs.
|
| 476 |
+
# Collect anything without a non-zero class into class=zero.
|
| 477 |
+
ret[0] = class0 = set(allGlyphs)
|
| 478 |
+
for s in ret[1:]:
|
| 479 |
+
s.intersection_update(class0)
|
| 480 |
+
class0.difference_update(s)
|
| 481 |
+
|
| 482 |
+
return ret
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def _ClassDef_merge_classify(lst, allGlyphses=None):
|
| 486 |
+
self = ot.ClassDef()
|
| 487 |
+
self.classDefs = classDefs = {}
|
| 488 |
+
allGlyphsesWasNone = allGlyphses is None
|
| 489 |
+
if allGlyphsesWasNone:
|
| 490 |
+
allGlyphses = [None] * len(lst)
|
| 491 |
+
|
| 492 |
+
classifier = classifyTools.Classifier()
|
| 493 |
+
for classDef, allGlyphs in zip(lst, allGlyphses):
|
| 494 |
+
sets = _ClassDef_invert(classDef, allGlyphs)
|
| 495 |
+
if allGlyphs is None:
|
| 496 |
+
sets = sets[1:]
|
| 497 |
+
classifier.update(sets)
|
| 498 |
+
classes = classifier.getClasses()
|
| 499 |
+
|
| 500 |
+
if allGlyphsesWasNone:
|
| 501 |
+
classes.insert(0, set())
|
| 502 |
+
|
| 503 |
+
for i, classSet in enumerate(classes):
|
| 504 |
+
if i == 0:
|
| 505 |
+
continue
|
| 506 |
+
for g in classSet:
|
| 507 |
+
classDefs[g] = i
|
| 508 |
+
|
| 509 |
+
return self, classes
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
def _PairPosFormat2_align_matrices(self, lst, font, transparent=False):
|
| 513 |
+
matrices = [l.Class1Record for l in lst]
|
| 514 |
+
|
| 515 |
+
# Align first classes
|
| 516 |
+
self.ClassDef1, classes = _ClassDef_merge_classify(
|
| 517 |
+
[l.ClassDef1 for l in lst], [l.Coverage.glyphs for l in lst]
|
| 518 |
+
)
|
| 519 |
+
self.Class1Count = len(classes)
|
| 520 |
+
new_matrices = []
|
| 521 |
+
for l, matrix in zip(lst, matrices):
|
| 522 |
+
nullRow = None
|
| 523 |
+
coverage = set(l.Coverage.glyphs)
|
| 524 |
+
classDef1 = l.ClassDef1.classDefs
|
| 525 |
+
class1Records = []
|
| 526 |
+
for classSet in classes:
|
| 527 |
+
exemplarGlyph = next(iter(classSet))
|
| 528 |
+
if exemplarGlyph not in coverage:
|
| 529 |
+
# Follow-up to e6125b353e1f54a0280ded5434b8e40d042de69f,
|
| 530 |
+
# Fixes https://github.com/googlei18n/fontmake/issues/470
|
| 531 |
+
# Again, revert 8d441779e5afc664960d848f62c7acdbfc71d7b9
|
| 532 |
+
# when merger becomes selfless.
|
| 533 |
+
nullRow = None
|
| 534 |
+
if nullRow is None:
|
| 535 |
+
nullRow = ot.Class1Record()
|
| 536 |
+
class2records = nullRow.Class2Record = []
|
| 537 |
+
# TODO: When merger becomes selfless, revert e6125b353e1f54a0280ded5434b8e40d042de69f
|
| 538 |
+
for _ in range(l.Class2Count):
|
| 539 |
+
if transparent:
|
| 540 |
+
rec2 = None
|
| 541 |
+
else:
|
| 542 |
+
rec2 = ot.Class2Record()
|
| 543 |
+
rec2.Value1 = (
|
| 544 |
+
otBase.ValueRecord(self.ValueFormat1)
|
| 545 |
+
if self.ValueFormat1
|
| 546 |
+
else None
|
| 547 |
+
)
|
| 548 |
+
rec2.Value2 = (
|
| 549 |
+
otBase.ValueRecord(self.ValueFormat2)
|
| 550 |
+
if self.ValueFormat2
|
| 551 |
+
else None
|
| 552 |
+
)
|
| 553 |
+
class2records.append(rec2)
|
| 554 |
+
rec1 = nullRow
|
| 555 |
+
else:
|
| 556 |
+
klass = classDef1.get(exemplarGlyph, 0)
|
| 557 |
+
rec1 = matrix[klass] # TODO handle out-of-range?
|
| 558 |
+
class1Records.append(rec1)
|
| 559 |
+
new_matrices.append(class1Records)
|
| 560 |
+
matrices = new_matrices
|
| 561 |
+
del new_matrices
|
| 562 |
+
|
| 563 |
+
# Align second classes
|
| 564 |
+
self.ClassDef2, classes = _ClassDef_merge_classify([l.ClassDef2 for l in lst])
|
| 565 |
+
self.Class2Count = len(classes)
|
| 566 |
+
new_matrices = []
|
| 567 |
+
for l, matrix in zip(lst, matrices):
|
| 568 |
+
classDef2 = l.ClassDef2.classDefs
|
| 569 |
+
class1Records = []
|
| 570 |
+
for rec1old in matrix:
|
| 571 |
+
oldClass2Records = rec1old.Class2Record
|
| 572 |
+
rec1new = ot.Class1Record()
|
| 573 |
+
class2Records = rec1new.Class2Record = []
|
| 574 |
+
for classSet in classes:
|
| 575 |
+
if not classSet: # class=0
|
| 576 |
+
rec2 = oldClass2Records[0]
|
| 577 |
+
else:
|
| 578 |
+
exemplarGlyph = next(iter(classSet))
|
| 579 |
+
klass = classDef2.get(exemplarGlyph, 0)
|
| 580 |
+
rec2 = oldClass2Records[klass]
|
| 581 |
+
class2Records.append(copy.deepcopy(rec2))
|
| 582 |
+
class1Records.append(rec1new)
|
| 583 |
+
new_matrices.append(class1Records)
|
| 584 |
+
matrices = new_matrices
|
| 585 |
+
del new_matrices
|
| 586 |
+
|
| 587 |
+
return matrices
|
| 588 |
+
|
| 589 |
+
|
| 590 |
+
def _PairPosFormat2_merge(self, lst, merger):
|
| 591 |
+
assert allEqual(
|
| 592 |
+
[l.ValueFormat2 == 0 for l in lst if l.Class1Record]
|
| 593 |
+
), "Report bug against fonttools."
|
| 594 |
+
|
| 595 |
+
merger.mergeObjects(
|
| 596 |
+
self,
|
| 597 |
+
lst,
|
| 598 |
+
exclude=(
|
| 599 |
+
"Coverage",
|
| 600 |
+
"ClassDef1",
|
| 601 |
+
"Class1Count",
|
| 602 |
+
"ClassDef2",
|
| 603 |
+
"Class2Count",
|
| 604 |
+
"Class1Record",
|
| 605 |
+
"ValueFormat1",
|
| 606 |
+
"ValueFormat2",
|
| 607 |
+
),
|
| 608 |
+
)
|
| 609 |
+
|
| 610 |
+
# Align coverages
|
| 611 |
+
glyphs, _ = _merge_GlyphOrders(merger.font, [v.Coverage.glyphs for v in lst])
|
| 612 |
+
self.Coverage.glyphs = glyphs
|
| 613 |
+
|
| 614 |
+
# Currently, if the coverage of PairPosFormat2 subtables are different,
|
| 615 |
+
# we do NOT bother walking down the subtable list when filling in new
|
| 616 |
+
# rows for alignment. As such, this is only correct if current subtable
|
| 617 |
+
# is the last subtable in the lookup. Ensure that.
|
| 618 |
+
#
|
| 619 |
+
# Note that our canonicalization process merges trailing PairPosFormat2's,
|
| 620 |
+
# so in reality this is rare.
|
| 621 |
+
for l, subtables in zip(lst, merger.lookup_subtables):
|
| 622 |
+
if l.Coverage.glyphs != glyphs:
|
| 623 |
+
assert l == subtables[-1]
|
| 624 |
+
|
| 625 |
+
matrices = _PairPosFormat2_align_matrices(self, lst, merger.font)
|
| 626 |
+
|
| 627 |
+
self.Class1Record = list(matrices[0]) # TODO move merger to be selfless
|
| 628 |
+
merger.mergeLists(self.Class1Record, matrices)
|
| 629 |
+
|
| 630 |
+
|
| 631 |
+
@AligningMerger.merger(ot.PairPos)
|
| 632 |
+
def merge(merger, self, lst):
|
| 633 |
+
merger.valueFormat1 = self.ValueFormat1 = reduce(
|
| 634 |
+
int.__or__, [l.ValueFormat1 for l in lst], 0
|
| 635 |
+
)
|
| 636 |
+
merger.valueFormat2 = self.ValueFormat2 = reduce(
|
| 637 |
+
int.__or__, [l.ValueFormat2 for l in lst], 0
|
| 638 |
+
)
|
| 639 |
+
|
| 640 |
+
if self.Format == 1:
|
| 641 |
+
_PairPosFormat1_merge(self, lst, merger)
|
| 642 |
+
elif self.Format == 2:
|
| 643 |
+
_PairPosFormat2_merge(self, lst, merger)
|
| 644 |
+
else:
|
| 645 |
+
raise UnsupportedFormat(merger, subtable="pair positioning lookup")
|
| 646 |
+
|
| 647 |
+
del merger.valueFormat1, merger.valueFormat2
|
| 648 |
+
|
| 649 |
+
# Now examine the list of value records, and update to the union of format values,
|
| 650 |
+
# as merge might have created new values.
|
| 651 |
+
vf1 = 0
|
| 652 |
+
vf2 = 0
|
| 653 |
+
if self.Format == 1:
|
| 654 |
+
for pairSet in self.PairSet:
|
| 655 |
+
for pairValueRecord in pairSet.PairValueRecord:
|
| 656 |
+
pv1 = getattr(pairValueRecord, "Value1", None)
|
| 657 |
+
if pv1 is not None:
|
| 658 |
+
vf1 |= pv1.getFormat()
|
| 659 |
+
pv2 = getattr(pairValueRecord, "Value2", None)
|
| 660 |
+
if pv2 is not None:
|
| 661 |
+
vf2 |= pv2.getFormat()
|
| 662 |
+
elif self.Format == 2:
|
| 663 |
+
for class1Record in self.Class1Record:
|
| 664 |
+
for class2Record in class1Record.Class2Record:
|
| 665 |
+
pv1 = getattr(class2Record, "Value1", None)
|
| 666 |
+
if pv1 is not None:
|
| 667 |
+
vf1 |= pv1.getFormat()
|
| 668 |
+
pv2 = getattr(class2Record, "Value2", None)
|
| 669 |
+
if pv2 is not None:
|
| 670 |
+
vf2 |= pv2.getFormat()
|
| 671 |
+
self.ValueFormat1 = vf1
|
| 672 |
+
self.ValueFormat2 = vf2
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
def _MarkBasePosFormat1_merge(self, lst, merger, Mark="Mark", Base="Base"):
|
| 676 |
+
self.ClassCount = max(l.ClassCount for l in lst)
|
| 677 |
+
|
| 678 |
+
MarkCoverageGlyphs, MarkRecords = _merge_GlyphOrders(
|
| 679 |
+
merger.font,
|
| 680 |
+
[getattr(l, Mark + "Coverage").glyphs for l in lst],
|
| 681 |
+
[getattr(l, Mark + "Array").MarkRecord for l in lst],
|
| 682 |
+
)
|
| 683 |
+
getattr(self, Mark + "Coverage").glyphs = MarkCoverageGlyphs
|
| 684 |
+
|
| 685 |
+
BaseCoverageGlyphs, BaseRecords = _merge_GlyphOrders(
|
| 686 |
+
merger.font,
|
| 687 |
+
[getattr(l, Base + "Coverage").glyphs for l in lst],
|
| 688 |
+
[getattr(getattr(l, Base + "Array"), Base + "Record") for l in lst],
|
| 689 |
+
)
|
| 690 |
+
getattr(self, Base + "Coverage").glyphs = BaseCoverageGlyphs
|
| 691 |
+
|
| 692 |
+
# MarkArray
|
| 693 |
+
records = []
|
| 694 |
+
for g, glyphRecords in zip(MarkCoverageGlyphs, zip(*MarkRecords)):
|
| 695 |
+
allClasses = [r.Class for r in glyphRecords if r is not None]
|
| 696 |
+
|
| 697 |
+
# TODO Right now we require that all marks have same class in
|
| 698 |
+
# all masters that cover them. This is not required.
|
| 699 |
+
#
|
| 700 |
+
# We can relax that by just requiring that all marks that have
|
| 701 |
+
# the same class in a master, have the same class in every other
|
| 702 |
+
# master. Indeed, if, say, a sparse master only covers one mark,
|
| 703 |
+
# that mark probably will get class 0, which would possibly be
|
| 704 |
+
# different from its class in other masters.
|
| 705 |
+
#
|
| 706 |
+
# We can even go further and reclassify marks to support any
|
| 707 |
+
# input. But, since, it's unlikely that two marks being both,
|
| 708 |
+
# say, "top" in one master, and one being "top" and other being
|
| 709 |
+
# "top-right" in another master, we shouldn't do that, as any
|
| 710 |
+
# failures in that case will probably signify mistakes in the
|
| 711 |
+
# input masters.
|
| 712 |
+
|
| 713 |
+
if not allEqual(allClasses):
|
| 714 |
+
raise ShouldBeConstant(merger, expected=allClasses[0], got=allClasses)
|
| 715 |
+
else:
|
| 716 |
+
rec = ot.MarkRecord()
|
| 717 |
+
rec.Class = allClasses[0]
|
| 718 |
+
allAnchors = [None if r is None else r.MarkAnchor for r in glyphRecords]
|
| 719 |
+
if allNone(allAnchors):
|
| 720 |
+
anchor = None
|
| 721 |
+
else:
|
| 722 |
+
anchor = ot.Anchor()
|
| 723 |
+
anchor.Format = 1
|
| 724 |
+
merger.mergeThings(anchor, allAnchors)
|
| 725 |
+
rec.MarkAnchor = anchor
|
| 726 |
+
records.append(rec)
|
| 727 |
+
array = ot.MarkArray()
|
| 728 |
+
array.MarkRecord = records
|
| 729 |
+
array.MarkCount = len(records)
|
| 730 |
+
setattr(self, Mark + "Array", array)
|
| 731 |
+
|
| 732 |
+
# BaseArray
|
| 733 |
+
records = []
|
| 734 |
+
for g, glyphRecords in zip(BaseCoverageGlyphs, zip(*BaseRecords)):
|
| 735 |
+
if allNone(glyphRecords):
|
| 736 |
+
rec = None
|
| 737 |
+
else:
|
| 738 |
+
rec = getattr(ot, Base + "Record")()
|
| 739 |
+
anchors = []
|
| 740 |
+
setattr(rec, Base + "Anchor", anchors)
|
| 741 |
+
glyphAnchors = [
|
| 742 |
+
[] if r is None else getattr(r, Base + "Anchor") for r in glyphRecords
|
| 743 |
+
]
|
| 744 |
+
for l in glyphAnchors:
|
| 745 |
+
l.extend([None] * (self.ClassCount - len(l)))
|
| 746 |
+
for allAnchors in zip(*glyphAnchors):
|
| 747 |
+
if allNone(allAnchors):
|
| 748 |
+
anchor = None
|
| 749 |
+
else:
|
| 750 |
+
anchor = ot.Anchor()
|
| 751 |
+
anchor.Format = 1
|
| 752 |
+
merger.mergeThings(anchor, allAnchors)
|
| 753 |
+
anchors.append(anchor)
|
| 754 |
+
records.append(rec)
|
| 755 |
+
array = getattr(ot, Base + "Array")()
|
| 756 |
+
setattr(array, Base + "Record", records)
|
| 757 |
+
setattr(array, Base + "Count", len(records))
|
| 758 |
+
setattr(self, Base + "Array", array)
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
@AligningMerger.merger(ot.MarkBasePos)
|
| 762 |
+
def merge(merger, self, lst):
|
| 763 |
+
if not allEqualTo(self.Format, (l.Format for l in lst)):
|
| 764 |
+
raise InconsistentFormats(
|
| 765 |
+
merger,
|
| 766 |
+
subtable="mark-to-base positioning lookup",
|
| 767 |
+
expected=self.Format,
|
| 768 |
+
got=[l.Format for l in lst],
|
| 769 |
+
)
|
| 770 |
+
if self.Format == 1:
|
| 771 |
+
_MarkBasePosFormat1_merge(self, lst, merger)
|
| 772 |
+
else:
|
| 773 |
+
raise UnsupportedFormat(merger, subtable="mark-to-base positioning lookup")
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
@AligningMerger.merger(ot.MarkMarkPos)
|
| 777 |
+
def merge(merger, self, lst):
|
| 778 |
+
if not allEqualTo(self.Format, (l.Format for l in lst)):
|
| 779 |
+
raise InconsistentFormats(
|
| 780 |
+
merger,
|
| 781 |
+
subtable="mark-to-mark positioning lookup",
|
| 782 |
+
expected=self.Format,
|
| 783 |
+
got=[l.Format for l in lst],
|
| 784 |
+
)
|
| 785 |
+
if self.Format == 1:
|
| 786 |
+
_MarkBasePosFormat1_merge(self, lst, merger, "Mark1", "Mark2")
|
| 787 |
+
else:
|
| 788 |
+
raise UnsupportedFormat(merger, subtable="mark-to-mark positioning lookup")
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
def _PairSet_flatten(lst, font):
|
| 792 |
+
self = ot.PairSet()
|
| 793 |
+
self.Coverage = ot.Coverage()
|
| 794 |
+
|
| 795 |
+
# Align them
|
| 796 |
+
glyphs, padded = _merge_GlyphOrders(
|
| 797 |
+
font,
|
| 798 |
+
[[v.SecondGlyph for v in vs.PairValueRecord] for vs in lst],
|
| 799 |
+
[vs.PairValueRecord for vs in lst],
|
| 800 |
+
)
|
| 801 |
+
|
| 802 |
+
self.Coverage.glyphs = glyphs
|
| 803 |
+
self.PairValueRecord = pvrs = []
|
| 804 |
+
for values in zip(*padded):
|
| 805 |
+
for v in values:
|
| 806 |
+
if v is not None:
|
| 807 |
+
pvrs.append(v)
|
| 808 |
+
break
|
| 809 |
+
else:
|
| 810 |
+
assert False
|
| 811 |
+
self.PairValueCount = len(self.PairValueRecord)
|
| 812 |
+
|
| 813 |
+
return self
|
| 814 |
+
|
| 815 |
+
|
| 816 |
+
def _Lookup_PairPosFormat1_subtables_flatten(lst, font):
|
| 817 |
+
assert allEqual(
|
| 818 |
+
[l.ValueFormat2 == 0 for l in lst if l.PairSet]
|
| 819 |
+
), "Report bug against fonttools."
|
| 820 |
+
|
| 821 |
+
self = ot.PairPos()
|
| 822 |
+
self.Format = 1
|
| 823 |
+
self.Coverage = ot.Coverage()
|
| 824 |
+
self.ValueFormat1 = reduce(int.__or__, [l.ValueFormat1 for l in lst], 0)
|
| 825 |
+
self.ValueFormat2 = reduce(int.__or__, [l.ValueFormat2 for l in lst], 0)
|
| 826 |
+
|
| 827 |
+
# Align them
|
| 828 |
+
glyphs, padded = _merge_GlyphOrders(
|
| 829 |
+
font, [v.Coverage.glyphs for v in lst], [v.PairSet for v in lst]
|
| 830 |
+
)
|
| 831 |
+
|
| 832 |
+
self.Coverage.glyphs = glyphs
|
| 833 |
+
self.PairSet = [
|
| 834 |
+
_PairSet_flatten([v for v in values if v is not None], font)
|
| 835 |
+
for values in zip(*padded)
|
| 836 |
+
]
|
| 837 |
+
self.PairSetCount = len(self.PairSet)
|
| 838 |
+
return self
|
| 839 |
+
|
| 840 |
+
|
| 841 |
+
def _Lookup_PairPosFormat2_subtables_flatten(lst, font):
|
| 842 |
+
assert allEqual(
|
| 843 |
+
[l.ValueFormat2 == 0 for l in lst if l.Class1Record]
|
| 844 |
+
), "Report bug against fonttools."
|
| 845 |
+
|
| 846 |
+
self = ot.PairPos()
|
| 847 |
+
self.Format = 2
|
| 848 |
+
self.Coverage = ot.Coverage()
|
| 849 |
+
self.ValueFormat1 = reduce(int.__or__, [l.ValueFormat1 for l in lst], 0)
|
| 850 |
+
self.ValueFormat2 = reduce(int.__or__, [l.ValueFormat2 for l in lst], 0)
|
| 851 |
+
|
| 852 |
+
# Align them
|
| 853 |
+
glyphs, _ = _merge_GlyphOrders(font, [v.Coverage.glyphs for v in lst])
|
| 854 |
+
self.Coverage.glyphs = glyphs
|
| 855 |
+
|
| 856 |
+
matrices = _PairPosFormat2_align_matrices(self, lst, font, transparent=True)
|
| 857 |
+
|
| 858 |
+
matrix = self.Class1Record = []
|
| 859 |
+
for rows in zip(*matrices):
|
| 860 |
+
row = ot.Class1Record()
|
| 861 |
+
matrix.append(row)
|
| 862 |
+
row.Class2Record = []
|
| 863 |
+
row = row.Class2Record
|
| 864 |
+
for cols in zip(*list(r.Class2Record for r in rows)):
|
| 865 |
+
col = next(iter(c for c in cols if c is not None))
|
| 866 |
+
row.append(col)
|
| 867 |
+
|
| 868 |
+
return self
|
| 869 |
+
|
| 870 |
+
|
| 871 |
+
def _Lookup_PairPos_subtables_canonicalize(lst, font):
|
| 872 |
+
"""Merge multiple Format1 subtables at the beginning of lst,
|
| 873 |
+
and merge multiple consecutive Format2 subtables that have the same
|
| 874 |
+
Class2 (ie. were split because of offset overflows). Returns new list."""
|
| 875 |
+
lst = list(lst)
|
| 876 |
+
|
| 877 |
+
l = len(lst)
|
| 878 |
+
i = 0
|
| 879 |
+
while i < l and lst[i].Format == 1:
|
| 880 |
+
i += 1
|
| 881 |
+
lst[:i] = [_Lookup_PairPosFormat1_subtables_flatten(lst[:i], font)]
|
| 882 |
+
|
| 883 |
+
l = len(lst)
|
| 884 |
+
i = l
|
| 885 |
+
while i > 0 and lst[i - 1].Format == 2:
|
| 886 |
+
i -= 1
|
| 887 |
+
lst[i:] = [_Lookup_PairPosFormat2_subtables_flatten(lst[i:], font)]
|
| 888 |
+
|
| 889 |
+
return lst
|
| 890 |
+
|
| 891 |
+
|
| 892 |
+
def _Lookup_SinglePos_subtables_flatten(lst, font, min_inclusive_rec_format):
|
| 893 |
+
glyphs, _ = _merge_GlyphOrders(font, [v.Coverage.glyphs for v in lst], None)
|
| 894 |
+
num_glyphs = len(glyphs)
|
| 895 |
+
new = ot.SinglePos()
|
| 896 |
+
new.Format = 2
|
| 897 |
+
new.ValueFormat = min_inclusive_rec_format
|
| 898 |
+
new.Coverage = ot.Coverage()
|
| 899 |
+
new.Coverage.glyphs = glyphs
|
| 900 |
+
new.ValueCount = num_glyphs
|
| 901 |
+
new.Value = [None] * num_glyphs
|
| 902 |
+
for singlePos in lst:
|
| 903 |
+
if singlePos.Format == 1:
|
| 904 |
+
val_rec = singlePos.Value
|
| 905 |
+
for gname in singlePos.Coverage.glyphs:
|
| 906 |
+
i = glyphs.index(gname)
|
| 907 |
+
new.Value[i] = copy.deepcopy(val_rec)
|
| 908 |
+
elif singlePos.Format == 2:
|
| 909 |
+
for j, gname in enumerate(singlePos.Coverage.glyphs):
|
| 910 |
+
val_rec = singlePos.Value[j]
|
| 911 |
+
i = glyphs.index(gname)
|
| 912 |
+
new.Value[i] = copy.deepcopy(val_rec)
|
| 913 |
+
return [new]
|
| 914 |
+
|
| 915 |
+
|
| 916 |
+
@AligningMerger.merger(ot.CursivePos)
|
| 917 |
+
def merge(merger, self, lst):
|
| 918 |
+
# Align them
|
| 919 |
+
glyphs, padded = _merge_GlyphOrders(
|
| 920 |
+
merger.font,
|
| 921 |
+
[l.Coverage.glyphs for l in lst],
|
| 922 |
+
[l.EntryExitRecord for l in lst],
|
| 923 |
+
)
|
| 924 |
+
|
| 925 |
+
self.Format = 1
|
| 926 |
+
self.Coverage = ot.Coverage()
|
| 927 |
+
self.Coverage.glyphs = glyphs
|
| 928 |
+
self.EntryExitRecord = []
|
| 929 |
+
for _ in glyphs:
|
| 930 |
+
rec = ot.EntryExitRecord()
|
| 931 |
+
rec.EntryAnchor = ot.Anchor()
|
| 932 |
+
rec.EntryAnchor.Format = 1
|
| 933 |
+
rec.ExitAnchor = ot.Anchor()
|
| 934 |
+
rec.ExitAnchor.Format = 1
|
| 935 |
+
self.EntryExitRecord.append(rec)
|
| 936 |
+
merger.mergeLists(self.EntryExitRecord, padded)
|
| 937 |
+
self.EntryExitCount = len(self.EntryExitRecord)
|
| 938 |
+
|
| 939 |
+
|
| 940 |
+
@AligningMerger.merger(ot.EntryExitRecord)
|
| 941 |
+
def merge(merger, self, lst):
|
| 942 |
+
if all(master.EntryAnchor is None for master in lst):
|
| 943 |
+
self.EntryAnchor = None
|
| 944 |
+
if all(master.ExitAnchor is None for master in lst):
|
| 945 |
+
self.ExitAnchor = None
|
| 946 |
+
merger.mergeObjects(self, lst)
|
| 947 |
+
|
| 948 |
+
|
| 949 |
+
@AligningMerger.merger(ot.Lookup)
|
| 950 |
+
def merge(merger, self, lst):
|
| 951 |
+
subtables = merger.lookup_subtables = [l.SubTable for l in lst]
|
| 952 |
+
|
| 953 |
+
# Remove Extension subtables
|
| 954 |
+
for l, sts in list(zip(lst, subtables)) + [(self, self.SubTable)]:
|
| 955 |
+
if not sts:
|
| 956 |
+
continue
|
| 957 |
+
if sts[0].__class__.__name__.startswith("Extension"):
|
| 958 |
+
if not allEqual([st.__class__ for st in sts]):
|
| 959 |
+
raise InconsistentExtensions(
|
| 960 |
+
merger,
|
| 961 |
+
expected="Extension",
|
| 962 |
+
got=[st.__class__.__name__ for st in sts],
|
| 963 |
+
)
|
| 964 |
+
if not allEqual([st.ExtensionLookupType for st in sts]):
|
| 965 |
+
raise InconsistentExtensions(merger)
|
| 966 |
+
l.LookupType = sts[0].ExtensionLookupType
|
| 967 |
+
new_sts = [st.ExtSubTable for st in sts]
|
| 968 |
+
del sts[:]
|
| 969 |
+
sts.extend(new_sts)
|
| 970 |
+
|
| 971 |
+
isPairPos = self.SubTable and isinstance(self.SubTable[0], ot.PairPos)
|
| 972 |
+
|
| 973 |
+
if isPairPos:
|
| 974 |
+
# AFDKO and feaLib sometimes generate two Format1 subtables instead of one.
|
| 975 |
+
# Merge those before continuing.
|
| 976 |
+
# https://github.com/fonttools/fonttools/issues/719
|
| 977 |
+
self.SubTable = _Lookup_PairPos_subtables_canonicalize(
|
| 978 |
+
self.SubTable, merger.font
|
| 979 |
+
)
|
| 980 |
+
subtables = merger.lookup_subtables = [
|
| 981 |
+
_Lookup_PairPos_subtables_canonicalize(st, merger.font) for st in subtables
|
| 982 |
+
]
|
| 983 |
+
else:
|
| 984 |
+
isSinglePos = self.SubTable and isinstance(self.SubTable[0], ot.SinglePos)
|
| 985 |
+
if isSinglePos:
|
| 986 |
+
numSubtables = [len(st) for st in subtables]
|
| 987 |
+
if not all([nums == numSubtables[0] for nums in numSubtables]):
|
| 988 |
+
# Flatten list of SinglePos subtables to single Format 2 subtable,
|
| 989 |
+
# with all value records set to the rec format type.
|
| 990 |
+
# We use buildSinglePos() to optimize the lookup after merging.
|
| 991 |
+
valueFormatList = [t.ValueFormat for st in subtables for t in st]
|
| 992 |
+
# Find the minimum value record that can accomodate all the singlePos subtables.
|
| 993 |
+
mirf = reduce(ior, valueFormatList)
|
| 994 |
+
self.SubTable = _Lookup_SinglePos_subtables_flatten(
|
| 995 |
+
self.SubTable, merger.font, mirf
|
| 996 |
+
)
|
| 997 |
+
subtables = merger.lookup_subtables = [
|
| 998 |
+
_Lookup_SinglePos_subtables_flatten(st, merger.font, mirf)
|
| 999 |
+
for st in subtables
|
| 1000 |
+
]
|
| 1001 |
+
flattened = True
|
| 1002 |
+
else:
|
| 1003 |
+
flattened = False
|
| 1004 |
+
|
| 1005 |
+
merger.mergeLists(self.SubTable, subtables)
|
| 1006 |
+
self.SubTableCount = len(self.SubTable)
|
| 1007 |
+
|
| 1008 |
+
if isPairPos:
|
| 1009 |
+
# If format-1 subtable created during canonicalization is empty, remove it.
|
| 1010 |
+
assert len(self.SubTable) >= 1 and self.SubTable[0].Format == 1
|
| 1011 |
+
if not self.SubTable[0].Coverage.glyphs:
|
| 1012 |
+
self.SubTable.pop(0)
|
| 1013 |
+
self.SubTableCount -= 1
|
| 1014 |
+
|
| 1015 |
+
# If format-2 subtable created during canonicalization is empty, remove it.
|
| 1016 |
+
assert len(self.SubTable) >= 1 and self.SubTable[-1].Format == 2
|
| 1017 |
+
if not self.SubTable[-1].Coverage.glyphs:
|
| 1018 |
+
self.SubTable.pop(-1)
|
| 1019 |
+
self.SubTableCount -= 1
|
| 1020 |
+
|
| 1021 |
+
# Compact the merged subtables
|
| 1022 |
+
# This is a good moment to do it because the compaction should create
|
| 1023 |
+
# smaller subtables, which may prevent overflows from happening.
|
| 1024 |
+
# Keep reading the value from the ENV until ufo2ft switches to the config system
|
| 1025 |
+
level = merger.font.cfg.get(
|
| 1026 |
+
"fontTools.otlLib.optimize.gpos:COMPRESSION_LEVEL",
|
| 1027 |
+
default=_compression_level_from_env(),
|
| 1028 |
+
)
|
| 1029 |
+
if level != 0:
|
| 1030 |
+
log.info("Compacting GPOS...")
|
| 1031 |
+
self.SubTable = compact_pair_pos(merger.font, level, self.SubTable)
|
| 1032 |
+
self.SubTableCount = len(self.SubTable)
|
| 1033 |
+
|
| 1034 |
+
elif isSinglePos and flattened:
|
| 1035 |
+
singlePosTable = self.SubTable[0]
|
| 1036 |
+
glyphs = singlePosTable.Coverage.glyphs
|
| 1037 |
+
# We know that singlePosTable is Format 2, as this is set
|
| 1038 |
+
# in _Lookup_SinglePos_subtables_flatten.
|
| 1039 |
+
singlePosMapping = {
|
| 1040 |
+
gname: valRecord for gname, valRecord in zip(glyphs, singlePosTable.Value)
|
| 1041 |
+
}
|
| 1042 |
+
self.SubTable = buildSinglePos(
|
| 1043 |
+
singlePosMapping, merger.font.getReverseGlyphMap()
|
| 1044 |
+
)
|
| 1045 |
+
merger.mergeObjects(self, lst, exclude=["SubTable", "SubTableCount"])
|
| 1046 |
+
|
| 1047 |
+
del merger.lookup_subtables
|
| 1048 |
+
|
| 1049 |
+
|
| 1050 |
+
#
|
| 1051 |
+
# InstancerMerger
|
| 1052 |
+
#
|
| 1053 |
+
|
| 1054 |
+
|
| 1055 |
+
class InstancerMerger(AligningMerger):
|
| 1056 |
+
"""A merger that takes multiple master fonts, and instantiates
|
| 1057 |
+
an instance."""
|
| 1058 |
+
|
| 1059 |
+
def __init__(self, font, model, location):
|
| 1060 |
+
Merger.__init__(self, font)
|
| 1061 |
+
self.model = model
|
| 1062 |
+
self.location = location
|
| 1063 |
+
self.masterScalars = model.getMasterScalars(location)
|
| 1064 |
+
|
| 1065 |
+
|
| 1066 |
+
@InstancerMerger.merger(ot.CaretValue)
|
| 1067 |
+
def merge(merger, self, lst):
|
| 1068 |
+
assert self.Format == 1
|
| 1069 |
+
Coords = [a.Coordinate for a in lst]
|
| 1070 |
+
model = merger.model
|
| 1071 |
+
masterScalars = merger.masterScalars
|
| 1072 |
+
self.Coordinate = otRound(
|
| 1073 |
+
model.interpolateFromValuesAndScalars(Coords, masterScalars)
|
| 1074 |
+
)
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
+
@InstancerMerger.merger(ot.Anchor)
|
| 1078 |
+
def merge(merger, self, lst):
|
| 1079 |
+
assert self.Format == 1
|
| 1080 |
+
XCoords = [a.XCoordinate for a in lst]
|
| 1081 |
+
YCoords = [a.YCoordinate for a in lst]
|
| 1082 |
+
model = merger.model
|
| 1083 |
+
masterScalars = merger.masterScalars
|
| 1084 |
+
self.XCoordinate = otRound(
|
| 1085 |
+
model.interpolateFromValuesAndScalars(XCoords, masterScalars)
|
| 1086 |
+
)
|
| 1087 |
+
self.YCoordinate = otRound(
|
| 1088 |
+
model.interpolateFromValuesAndScalars(YCoords, masterScalars)
|
| 1089 |
+
)
|
| 1090 |
+
|
| 1091 |
+
|
| 1092 |
+
@InstancerMerger.merger(otBase.ValueRecord)
|
| 1093 |
+
def merge(merger, self, lst):
|
| 1094 |
+
model = merger.model
|
| 1095 |
+
masterScalars = merger.masterScalars
|
| 1096 |
+
# TODO Handle differing valueformats
|
| 1097 |
+
for name, tableName in [
|
| 1098 |
+
("XAdvance", "XAdvDevice"),
|
| 1099 |
+
("YAdvance", "YAdvDevice"),
|
| 1100 |
+
("XPlacement", "XPlaDevice"),
|
| 1101 |
+
("YPlacement", "YPlaDevice"),
|
| 1102 |
+
]:
|
| 1103 |
+
assert not hasattr(self, tableName)
|
| 1104 |
+
|
| 1105 |
+
if hasattr(self, name):
|
| 1106 |
+
values = [getattr(a, name, 0) for a in lst]
|
| 1107 |
+
value = otRound(
|
| 1108 |
+
model.interpolateFromValuesAndScalars(values, masterScalars)
|
| 1109 |
+
)
|
| 1110 |
+
setattr(self, name, value)
|
| 1111 |
+
|
| 1112 |
+
|
| 1113 |
+
#
|
| 1114 |
+
# MutatorMerger
|
| 1115 |
+
#
|
| 1116 |
+
|
| 1117 |
+
|
| 1118 |
+
class MutatorMerger(AligningMerger):
|
| 1119 |
+
"""A merger that takes a variable font, and instantiates
|
| 1120 |
+
an instance. While there's no "merging" to be done per se,
|
| 1121 |
+
the operation can benefit from many operations that the
|
| 1122 |
+
aligning merger does."""
|
| 1123 |
+
|
| 1124 |
+
def __init__(self, font, instancer, deleteVariations=True):
|
| 1125 |
+
Merger.__init__(self, font)
|
| 1126 |
+
self.instancer = instancer
|
| 1127 |
+
self.deleteVariations = deleteVariations
|
| 1128 |
+
|
| 1129 |
+
|
| 1130 |
+
@MutatorMerger.merger(ot.CaretValue)
|
| 1131 |
+
def merge(merger, self, lst):
|
| 1132 |
+
# Hack till we become selfless.
|
| 1133 |
+
self.__dict__ = lst[0].__dict__.copy()
|
| 1134 |
+
|
| 1135 |
+
if self.Format != 3:
|
| 1136 |
+
return
|
| 1137 |
+
|
| 1138 |
+
instancer = merger.instancer
|
| 1139 |
+
dev = self.DeviceTable
|
| 1140 |
+
if merger.deleteVariations:
|
| 1141 |
+
del self.DeviceTable
|
| 1142 |
+
if dev:
|
| 1143 |
+
assert dev.DeltaFormat == 0x8000
|
| 1144 |
+
varidx = (dev.StartSize << 16) + dev.EndSize
|
| 1145 |
+
delta = otRound(instancer[varidx])
|
| 1146 |
+
self.Coordinate += delta
|
| 1147 |
+
|
| 1148 |
+
if merger.deleteVariations:
|
| 1149 |
+
self.Format = 1
|
| 1150 |
+
|
| 1151 |
+
|
| 1152 |
+
@MutatorMerger.merger(ot.Anchor)
|
| 1153 |
+
def merge(merger, self, lst):
|
| 1154 |
+
# Hack till we become selfless.
|
| 1155 |
+
self.__dict__ = lst[0].__dict__.copy()
|
| 1156 |
+
|
| 1157 |
+
if self.Format != 3:
|
| 1158 |
+
return
|
| 1159 |
+
|
| 1160 |
+
instancer = merger.instancer
|
| 1161 |
+
for v in "XY":
|
| 1162 |
+
tableName = v + "DeviceTable"
|
| 1163 |
+
if not hasattr(self, tableName):
|
| 1164 |
+
continue
|
| 1165 |
+
dev = getattr(self, tableName)
|
| 1166 |
+
if merger.deleteVariations:
|
| 1167 |
+
delattr(self, tableName)
|
| 1168 |
+
if dev is None:
|
| 1169 |
+
continue
|
| 1170 |
+
|
| 1171 |
+
assert dev.DeltaFormat == 0x8000
|
| 1172 |
+
varidx = (dev.StartSize << 16) + dev.EndSize
|
| 1173 |
+
delta = otRound(instancer[varidx])
|
| 1174 |
+
|
| 1175 |
+
attr = v + "Coordinate"
|
| 1176 |
+
setattr(self, attr, getattr(self, attr) + delta)
|
| 1177 |
+
|
| 1178 |
+
if merger.deleteVariations:
|
| 1179 |
+
self.Format = 1
|
| 1180 |
+
|
| 1181 |
+
|
| 1182 |
+
@MutatorMerger.merger(otBase.ValueRecord)
|
| 1183 |
+
def merge(merger, self, lst):
|
| 1184 |
+
# Hack till we become selfless.
|
| 1185 |
+
self.__dict__ = lst[0].__dict__.copy()
|
| 1186 |
+
|
| 1187 |
+
instancer = merger.instancer
|
| 1188 |
+
for name, tableName in [
|
| 1189 |
+
("XAdvance", "XAdvDevice"),
|
| 1190 |
+
("YAdvance", "YAdvDevice"),
|
| 1191 |
+
("XPlacement", "XPlaDevice"),
|
| 1192 |
+
("YPlacement", "YPlaDevice"),
|
| 1193 |
+
]:
|
| 1194 |
+
if not hasattr(self, tableName):
|
| 1195 |
+
continue
|
| 1196 |
+
dev = getattr(self, tableName)
|
| 1197 |
+
if merger.deleteVariations:
|
| 1198 |
+
delattr(self, tableName)
|
| 1199 |
+
if dev is None:
|
| 1200 |
+
continue
|
| 1201 |
+
|
| 1202 |
+
assert dev.DeltaFormat == 0x8000
|
| 1203 |
+
varidx = (dev.StartSize << 16) + dev.EndSize
|
| 1204 |
+
delta = otRound(instancer[varidx])
|
| 1205 |
+
|
| 1206 |
+
setattr(self, name, getattr(self, name, 0) + delta)
|
| 1207 |
+
|
| 1208 |
+
|
| 1209 |
+
#
|
| 1210 |
+
# VariationMerger
|
| 1211 |
+
#
|
| 1212 |
+
|
| 1213 |
+
|
| 1214 |
+
class VariationMerger(AligningMerger):
|
| 1215 |
+
"""A merger that takes multiple master fonts, and builds a
|
| 1216 |
+
variable font."""
|
| 1217 |
+
|
| 1218 |
+
def __init__(self, model, axisTags, font):
|
| 1219 |
+
Merger.__init__(self, font)
|
| 1220 |
+
self.store_builder = varStore.OnlineVarStoreBuilder(axisTags)
|
| 1221 |
+
self.setModel(model)
|
| 1222 |
+
|
| 1223 |
+
def setModel(self, model):
|
| 1224 |
+
self.model = model
|
| 1225 |
+
self.store_builder.setModel(model)
|
| 1226 |
+
|
| 1227 |
+
def mergeThings(self, out, lst):
|
| 1228 |
+
masterModel = None
|
| 1229 |
+
origTTFs = None
|
| 1230 |
+
if None in lst:
|
| 1231 |
+
if allNone(lst):
|
| 1232 |
+
if out is not None:
|
| 1233 |
+
raise FoundANone(self, got=lst)
|
| 1234 |
+
return
|
| 1235 |
+
|
| 1236 |
+
# temporarily subset the list of master ttfs to the ones for which
|
| 1237 |
+
# master values are not None
|
| 1238 |
+
origTTFs = self.ttfs
|
| 1239 |
+
if self.ttfs:
|
| 1240 |
+
self.ttfs = subList([v is not None for v in lst], self.ttfs)
|
| 1241 |
+
|
| 1242 |
+
masterModel = self.model
|
| 1243 |
+
model, lst = masterModel.getSubModel(lst)
|
| 1244 |
+
self.setModel(model)
|
| 1245 |
+
|
| 1246 |
+
super(VariationMerger, self).mergeThings(out, lst)
|
| 1247 |
+
|
| 1248 |
+
if masterModel:
|
| 1249 |
+
self.setModel(masterModel)
|
| 1250 |
+
if origTTFs:
|
| 1251 |
+
self.ttfs = origTTFs
|
| 1252 |
+
|
| 1253 |
+
|
| 1254 |
+
def buildVarDevTable(store_builder, master_values):
|
| 1255 |
+
if allEqual(master_values):
|
| 1256 |
+
return master_values[0], None
|
| 1257 |
+
base, varIdx = store_builder.storeMasters(master_values)
|
| 1258 |
+
return base, builder.buildVarDevTable(varIdx)
|
| 1259 |
+
|
| 1260 |
+
|
| 1261 |
+
@VariationMerger.merger(ot.BaseCoord)
|
| 1262 |
+
def merge(merger, self, lst):
|
| 1263 |
+
if self.Format != 1:
|
| 1264 |
+
raise UnsupportedFormat(merger, subtable="a baseline coordinate")
|
| 1265 |
+
self.Coordinate, DeviceTable = buildVarDevTable(
|
| 1266 |
+
merger.store_builder, [a.Coordinate for a in lst]
|
| 1267 |
+
)
|
| 1268 |
+
if DeviceTable:
|
| 1269 |
+
self.Format = 3
|
| 1270 |
+
self.DeviceTable = DeviceTable
|
| 1271 |
+
|
| 1272 |
+
|
| 1273 |
+
@VariationMerger.merger(ot.CaretValue)
|
| 1274 |
+
def merge(merger, self, lst):
|
| 1275 |
+
if self.Format != 1:
|
| 1276 |
+
raise UnsupportedFormat(merger, subtable="a caret")
|
| 1277 |
+
self.Coordinate, DeviceTable = buildVarDevTable(
|
| 1278 |
+
merger.store_builder, [a.Coordinate for a in lst]
|
| 1279 |
+
)
|
| 1280 |
+
if DeviceTable:
|
| 1281 |
+
self.Format = 3
|
| 1282 |
+
self.DeviceTable = DeviceTable
|
| 1283 |
+
|
| 1284 |
+
|
| 1285 |
+
@VariationMerger.merger(ot.Anchor)
|
| 1286 |
+
def merge(merger, self, lst):
|
| 1287 |
+
if self.Format != 1:
|
| 1288 |
+
raise UnsupportedFormat(merger, subtable="an anchor")
|
| 1289 |
+
self.XCoordinate, XDeviceTable = buildVarDevTable(
|
| 1290 |
+
merger.store_builder, [a.XCoordinate for a in lst]
|
| 1291 |
+
)
|
| 1292 |
+
self.YCoordinate, YDeviceTable = buildVarDevTable(
|
| 1293 |
+
merger.store_builder, [a.YCoordinate for a in lst]
|
| 1294 |
+
)
|
| 1295 |
+
if XDeviceTable or YDeviceTable:
|
| 1296 |
+
self.Format = 3
|
| 1297 |
+
self.XDeviceTable = XDeviceTable
|
| 1298 |
+
self.YDeviceTable = YDeviceTable
|
| 1299 |
+
|
| 1300 |
+
|
| 1301 |
+
@VariationMerger.merger(otBase.ValueRecord)
|
| 1302 |
+
def merge(merger, self, lst):
|
| 1303 |
+
for name, tableName in [
|
| 1304 |
+
("XAdvance", "XAdvDevice"),
|
| 1305 |
+
("YAdvance", "YAdvDevice"),
|
| 1306 |
+
("XPlacement", "XPlaDevice"),
|
| 1307 |
+
("YPlacement", "YPlaDevice"),
|
| 1308 |
+
]:
|
| 1309 |
+
if hasattr(self, name):
|
| 1310 |
+
value, deviceTable = buildVarDevTable(
|
| 1311 |
+
merger.store_builder, [getattr(a, name, 0) for a in lst]
|
| 1312 |
+
)
|
| 1313 |
+
setattr(self, name, value)
|
| 1314 |
+
if deviceTable:
|
| 1315 |
+
setattr(self, tableName, deviceTable)
|
| 1316 |
+
|
| 1317 |
+
|
| 1318 |
+
class COLRVariationMerger(VariationMerger):
|
| 1319 |
+
"""A specialized VariationMerger that takes multiple master fonts containing
|
| 1320 |
+
COLRv1 tables, and builds a variable COLR font.
|
| 1321 |
+
|
| 1322 |
+
COLR tables are special in that variable subtables can be associated with
|
| 1323 |
+
multiple delta-set indices (via VarIndexBase).
|
| 1324 |
+
They also contain tables that must change their type (not simply the Format)
|
| 1325 |
+
as they become variable (e.g. Affine2x3 -> VarAffine2x3) so this merger takes
|
| 1326 |
+
care of that too.
|
| 1327 |
+
"""
|
| 1328 |
+
|
| 1329 |
+
def __init__(self, model, axisTags, font, allowLayerReuse=True):
|
| 1330 |
+
VariationMerger.__init__(self, model, axisTags, font)
|
| 1331 |
+
# maps {tuple(varIdxes): VarIndexBase} to facilitate reuse of VarIndexBase
|
| 1332 |
+
# between variable tables with same varIdxes.
|
| 1333 |
+
self.varIndexCache = {}
|
| 1334 |
+
# flat list of all the varIdxes generated while merging
|
| 1335 |
+
self.varIdxes = []
|
| 1336 |
+
# set of id()s of the subtables that contain variations after merging
|
| 1337 |
+
# and need to be upgraded to the associated VarType.
|
| 1338 |
+
self.varTableIds = set()
|
| 1339 |
+
# we keep these around for rebuilding a LayerList while merging PaintColrLayers
|
| 1340 |
+
self.layers = []
|
| 1341 |
+
self.layerReuseCache = None
|
| 1342 |
+
if allowLayerReuse:
|
| 1343 |
+
self.layerReuseCache = LayerReuseCache()
|
| 1344 |
+
# flag to ensure BaseGlyphList is fully merged before LayerList gets processed
|
| 1345 |
+
self._doneBaseGlyphs = False
|
| 1346 |
+
|
| 1347 |
+
def mergeTables(self, font, master_ttfs, tableTags=("COLR",)):
|
| 1348 |
+
if "COLR" in tableTags and "COLR" in font:
|
| 1349 |
+
# The merger modifies the destination COLR table in-place. If this contains
|
| 1350 |
+
# multiple PaintColrLayers referencing the same layers from LayerList, it's
|
| 1351 |
+
# a problem because we may risk modifying the same paint more than once, or
|
| 1352 |
+
# worse, fail while attempting to do that.
|
| 1353 |
+
# We don't know whether the master COLR table was built with layer reuse
|
| 1354 |
+
# disabled, thus to be safe we rebuild its LayerList so that it contains only
|
| 1355 |
+
# unique layers referenced from non-overlapping PaintColrLayers throughout
|
| 1356 |
+
# the base paint graphs.
|
| 1357 |
+
self.expandPaintColrLayers(font["COLR"].table)
|
| 1358 |
+
VariationMerger.mergeTables(self, font, master_ttfs, tableTags)
|
| 1359 |
+
|
| 1360 |
+
def checkFormatEnum(self, out, lst, validate=lambda _: True):
|
| 1361 |
+
fmt = out.Format
|
| 1362 |
+
formatEnum = out.formatEnum
|
| 1363 |
+
ok = False
|
| 1364 |
+
try:
|
| 1365 |
+
fmt = formatEnum(fmt)
|
| 1366 |
+
except ValueError:
|
| 1367 |
+
pass
|
| 1368 |
+
else:
|
| 1369 |
+
ok = validate(fmt)
|
| 1370 |
+
if not ok:
|
| 1371 |
+
raise UnsupportedFormat(self, subtable=type(out).__name__, value=fmt)
|
| 1372 |
+
expected = fmt
|
| 1373 |
+
got = []
|
| 1374 |
+
for v in lst:
|
| 1375 |
+
fmt = getattr(v, "Format", None)
|
| 1376 |
+
try:
|
| 1377 |
+
fmt = formatEnum(fmt)
|
| 1378 |
+
except ValueError:
|
| 1379 |
+
pass
|
| 1380 |
+
got.append(fmt)
|
| 1381 |
+
if not allEqualTo(expected, got):
|
| 1382 |
+
raise InconsistentFormats(
|
| 1383 |
+
self,
|
| 1384 |
+
subtable=type(out).__name__,
|
| 1385 |
+
expected=expected,
|
| 1386 |
+
got=got,
|
| 1387 |
+
)
|
| 1388 |
+
return expected
|
| 1389 |
+
|
| 1390 |
+
def mergeSparseDict(self, out, lst):
|
| 1391 |
+
for k in out.keys():
|
| 1392 |
+
try:
|
| 1393 |
+
self.mergeThings(out[k], [v.get(k) for v in lst])
|
| 1394 |
+
except VarLibMergeError as e:
|
| 1395 |
+
e.stack.append(f"[{k!r}]")
|
| 1396 |
+
raise
|
| 1397 |
+
|
| 1398 |
+
def mergeAttrs(self, out, lst, attrs):
|
| 1399 |
+
for attr in attrs:
|
| 1400 |
+
value = getattr(out, attr)
|
| 1401 |
+
values = [getattr(item, attr) for item in lst]
|
| 1402 |
+
try:
|
| 1403 |
+
self.mergeThings(value, values)
|
| 1404 |
+
except VarLibMergeError as e:
|
| 1405 |
+
e.stack.append(f".{attr}")
|
| 1406 |
+
raise
|
| 1407 |
+
|
| 1408 |
+
def storeMastersForAttr(self, out, lst, attr):
|
| 1409 |
+
master_values = [getattr(item, attr) for item in lst]
|
| 1410 |
+
|
| 1411 |
+
# VarStore treats deltas for fixed-size floats as integers, so we
|
| 1412 |
+
# must convert master values to int before storing them in the builder
|
| 1413 |
+
# then back to float.
|
| 1414 |
+
is_fixed_size_float = False
|
| 1415 |
+
conv = out.getConverterByName(attr)
|
| 1416 |
+
if isinstance(conv, BaseFixedValue):
|
| 1417 |
+
is_fixed_size_float = True
|
| 1418 |
+
master_values = [conv.toInt(v) for v in master_values]
|
| 1419 |
+
|
| 1420 |
+
baseValue = master_values[0]
|
| 1421 |
+
varIdx = ot.NO_VARIATION_INDEX
|
| 1422 |
+
if not allEqual(master_values):
|
| 1423 |
+
baseValue, varIdx = self.store_builder.storeMasters(master_values)
|
| 1424 |
+
|
| 1425 |
+
if is_fixed_size_float:
|
| 1426 |
+
baseValue = conv.fromInt(baseValue)
|
| 1427 |
+
|
| 1428 |
+
return baseValue, varIdx
|
| 1429 |
+
|
| 1430 |
+
def storeVariationIndices(self, varIdxes) -> int:
|
| 1431 |
+
# try to reuse an existing VarIndexBase for the same varIdxes, or else
|
| 1432 |
+
# create a new one
|
| 1433 |
+
key = tuple(varIdxes)
|
| 1434 |
+
varIndexBase = self.varIndexCache.get(key)
|
| 1435 |
+
|
| 1436 |
+
if varIndexBase is None:
|
| 1437 |
+
# scan for a full match anywhere in the self.varIdxes
|
| 1438 |
+
for i in range(len(self.varIdxes) - len(varIdxes) + 1):
|
| 1439 |
+
if self.varIdxes[i : i + len(varIdxes)] == varIdxes:
|
| 1440 |
+
self.varIndexCache[key] = varIndexBase = i
|
| 1441 |
+
break
|
| 1442 |
+
|
| 1443 |
+
if varIndexBase is None:
|
| 1444 |
+
# try find a partial match at the end of the self.varIdxes
|
| 1445 |
+
for n in range(len(varIdxes) - 1, 0, -1):
|
| 1446 |
+
if self.varIdxes[-n:] == varIdxes[:n]:
|
| 1447 |
+
varIndexBase = len(self.varIdxes) - n
|
| 1448 |
+
self.varIndexCache[key] = varIndexBase
|
| 1449 |
+
self.varIdxes.extend(varIdxes[n:])
|
| 1450 |
+
break
|
| 1451 |
+
|
| 1452 |
+
if varIndexBase is None:
|
| 1453 |
+
# no match found, append at the end
|
| 1454 |
+
self.varIndexCache[key] = varIndexBase = len(self.varIdxes)
|
| 1455 |
+
self.varIdxes.extend(varIdxes)
|
| 1456 |
+
|
| 1457 |
+
return varIndexBase
|
| 1458 |
+
|
| 1459 |
+
def mergeVariableAttrs(self, out, lst, attrs) -> int:
|
| 1460 |
+
varIndexBase = ot.NO_VARIATION_INDEX
|
| 1461 |
+
varIdxes = []
|
| 1462 |
+
for attr in attrs:
|
| 1463 |
+
baseValue, varIdx = self.storeMastersForAttr(out, lst, attr)
|
| 1464 |
+
setattr(out, attr, baseValue)
|
| 1465 |
+
varIdxes.append(varIdx)
|
| 1466 |
+
|
| 1467 |
+
if any(v != ot.NO_VARIATION_INDEX for v in varIdxes):
|
| 1468 |
+
varIndexBase = self.storeVariationIndices(varIdxes)
|
| 1469 |
+
|
| 1470 |
+
return varIndexBase
|
| 1471 |
+
|
| 1472 |
+
@classmethod
|
| 1473 |
+
def convertSubTablesToVarType(cls, table):
|
| 1474 |
+
for path in dfs_base_table(
|
| 1475 |
+
table,
|
| 1476 |
+
skip_root=True,
|
| 1477 |
+
predicate=lambda path: (
|
| 1478 |
+
getattr(type(path[-1].value), "VarType", None) is not None
|
| 1479 |
+
),
|
| 1480 |
+
):
|
| 1481 |
+
st = path[-1]
|
| 1482 |
+
subTable = st.value
|
| 1483 |
+
varType = type(subTable).VarType
|
| 1484 |
+
newSubTable = varType()
|
| 1485 |
+
newSubTable.__dict__.update(subTable.__dict__)
|
| 1486 |
+
newSubTable.populateDefaults()
|
| 1487 |
+
parent = path[-2].value
|
| 1488 |
+
if st.index is not None:
|
| 1489 |
+
getattr(parent, st.name)[st.index] = newSubTable
|
| 1490 |
+
else:
|
| 1491 |
+
setattr(parent, st.name, newSubTable)
|
| 1492 |
+
|
| 1493 |
+
@staticmethod
|
| 1494 |
+
def expandPaintColrLayers(colr):
|
| 1495 |
+
"""Rebuild LayerList without PaintColrLayers reuse.
|
| 1496 |
+
|
| 1497 |
+
Each base paint graph is fully DFS-traversed (with exception of PaintColrGlyph
|
| 1498 |
+
which are irrelevant for this); any layers referenced via PaintColrLayers are
|
| 1499 |
+
collected into a new LayerList and duplicated when reuse is detected, to ensure
|
| 1500 |
+
that all paints are distinct objects at the end of the process.
|
| 1501 |
+
PaintColrLayers's FirstLayerIndex/NumLayers are updated so that no overlap
|
| 1502 |
+
is left. Also, any consecutively nested PaintColrLayers are flattened.
|
| 1503 |
+
The COLR table's LayerList is replaced with the new unique layers.
|
| 1504 |
+
A side effect is also that any layer from the old LayerList which is not
|
| 1505 |
+
referenced by any PaintColrLayers is dropped.
|
| 1506 |
+
"""
|
| 1507 |
+
if not colr.LayerList:
|
| 1508 |
+
# if no LayerList, there's nothing to expand
|
| 1509 |
+
return
|
| 1510 |
+
uniqueLayerIDs = set()
|
| 1511 |
+
newLayerList = []
|
| 1512 |
+
for rec in colr.BaseGlyphList.BaseGlyphPaintRecord:
|
| 1513 |
+
frontier = [rec.Paint]
|
| 1514 |
+
while frontier:
|
| 1515 |
+
paint = frontier.pop()
|
| 1516 |
+
if paint.Format == ot.PaintFormat.PaintColrGlyph:
|
| 1517 |
+
# don't traverse these, we treat them as constant for merging
|
| 1518 |
+
continue
|
| 1519 |
+
elif paint.Format == ot.PaintFormat.PaintColrLayers:
|
| 1520 |
+
# de-treeify any nested PaintColrLayers, append unique copies to
|
| 1521 |
+
# the new layer list and update PaintColrLayers index/count
|
| 1522 |
+
children = list(_flatten_layers(paint, colr))
|
| 1523 |
+
first_layer_index = len(newLayerList)
|
| 1524 |
+
for layer in children:
|
| 1525 |
+
if id(layer) in uniqueLayerIDs:
|
| 1526 |
+
layer = copy.deepcopy(layer)
|
| 1527 |
+
assert id(layer) not in uniqueLayerIDs
|
| 1528 |
+
newLayerList.append(layer)
|
| 1529 |
+
uniqueLayerIDs.add(id(layer))
|
| 1530 |
+
paint.FirstLayerIndex = first_layer_index
|
| 1531 |
+
paint.NumLayers = len(children)
|
| 1532 |
+
else:
|
| 1533 |
+
children = paint.getChildren(colr)
|
| 1534 |
+
frontier.extend(reversed(children))
|
| 1535 |
+
# sanity check all the new layers are distinct objects
|
| 1536 |
+
assert len(newLayerList) == len(uniqueLayerIDs)
|
| 1537 |
+
colr.LayerList.Paint = newLayerList
|
| 1538 |
+
colr.LayerList.LayerCount = len(newLayerList)
|
| 1539 |
+
|
| 1540 |
+
|
| 1541 |
+
@COLRVariationMerger.merger(ot.BaseGlyphList)
|
| 1542 |
+
def merge(merger, self, lst):
|
| 1543 |
+
# ignore BaseGlyphCount, allow sparse glyph sets across masters
|
| 1544 |
+
out = {rec.BaseGlyph: rec for rec in self.BaseGlyphPaintRecord}
|
| 1545 |
+
masters = [{rec.BaseGlyph: rec for rec in m.BaseGlyphPaintRecord} for m in lst]
|
| 1546 |
+
|
| 1547 |
+
for i, g in enumerate(out.keys()):
|
| 1548 |
+
try:
|
| 1549 |
+
# missing base glyphs don't participate in the merge
|
| 1550 |
+
merger.mergeThings(out[g], [v.get(g) for v in masters])
|
| 1551 |
+
except VarLibMergeError as e:
|
| 1552 |
+
e.stack.append(f".BaseGlyphPaintRecord[{i}]")
|
| 1553 |
+
e.cause["location"] = f"base glyph {g!r}"
|
| 1554 |
+
raise
|
| 1555 |
+
|
| 1556 |
+
merger._doneBaseGlyphs = True
|
| 1557 |
+
|
| 1558 |
+
|
| 1559 |
+
@COLRVariationMerger.merger(ot.LayerList)
|
| 1560 |
+
def merge(merger, self, lst):
|
| 1561 |
+
# nothing to merge for LayerList, assuming we have already merged all PaintColrLayers
|
| 1562 |
+
# found while traversing the paint graphs rooted at BaseGlyphPaintRecords.
|
| 1563 |
+
assert merger._doneBaseGlyphs, "BaseGlyphList must be merged before LayerList"
|
| 1564 |
+
# Simply flush the final list of layers and go home.
|
| 1565 |
+
self.LayerCount = len(merger.layers)
|
| 1566 |
+
self.Paint = merger.layers
|
| 1567 |
+
|
| 1568 |
+
|
| 1569 |
+
def _flatten_layers(root, colr):
|
| 1570 |
+
assert root.Format == ot.PaintFormat.PaintColrLayers
|
| 1571 |
+
for paint in root.getChildren(colr):
|
| 1572 |
+
if paint.Format == ot.PaintFormat.PaintColrLayers:
|
| 1573 |
+
yield from _flatten_layers(paint, colr)
|
| 1574 |
+
else:
|
| 1575 |
+
yield paint
|
| 1576 |
+
|
| 1577 |
+
|
| 1578 |
+
def _merge_PaintColrLayers(self, out, lst):
|
| 1579 |
+
# we only enforce that the (flat) number of layers is the same across all masters
|
| 1580 |
+
# but we allow FirstLayerIndex to differ to acommodate for sparse glyph sets.
|
| 1581 |
+
|
| 1582 |
+
out_layers = list(_flatten_layers(out, self.font["COLR"].table))
|
| 1583 |
+
|
| 1584 |
+
# sanity check ttfs are subset to current values (see VariationMerger.mergeThings)
|
| 1585 |
+
# before matching each master PaintColrLayers to its respective COLR by position
|
| 1586 |
+
assert len(self.ttfs) == len(lst)
|
| 1587 |
+
master_layerses = [
|
| 1588 |
+
list(_flatten_layers(lst[i], self.ttfs[i]["COLR"].table))
|
| 1589 |
+
for i in range(len(lst))
|
| 1590 |
+
]
|
| 1591 |
+
|
| 1592 |
+
try:
|
| 1593 |
+
self.mergeLists(out_layers, master_layerses)
|
| 1594 |
+
except VarLibMergeError as e:
|
| 1595 |
+
# NOTE: This attribute doesn't actually exist in PaintColrLayers but it's
|
| 1596 |
+
# handy to have it in the stack trace for debugging.
|
| 1597 |
+
e.stack.append(".Layers")
|
| 1598 |
+
raise
|
| 1599 |
+
|
| 1600 |
+
# following block is very similar to LayerListBuilder._beforeBuildPaintColrLayers
|
| 1601 |
+
# but I couldn't find a nice way to share the code between the two...
|
| 1602 |
+
|
| 1603 |
+
if self.layerReuseCache is not None:
|
| 1604 |
+
# successful reuse can make the list smaller
|
| 1605 |
+
out_layers = self.layerReuseCache.try_reuse(out_layers)
|
| 1606 |
+
|
| 1607 |
+
# if the list is still too big we need to tree-fy it
|
| 1608 |
+
is_tree = len(out_layers) > MAX_PAINT_COLR_LAYER_COUNT
|
| 1609 |
+
out_layers = build_n_ary_tree(out_layers, n=MAX_PAINT_COLR_LAYER_COUNT)
|
| 1610 |
+
|
| 1611 |
+
# We now have a tree of sequences with Paint leaves.
|
| 1612 |
+
# Convert the sequences into PaintColrLayers.
|
| 1613 |
+
def listToColrLayers(paint):
|
| 1614 |
+
if isinstance(paint, list):
|
| 1615 |
+
layers = [listToColrLayers(l) for l in paint]
|
| 1616 |
+
paint = ot.Paint()
|
| 1617 |
+
paint.Format = int(ot.PaintFormat.PaintColrLayers)
|
| 1618 |
+
paint.NumLayers = len(layers)
|
| 1619 |
+
paint.FirstLayerIndex = len(self.layers)
|
| 1620 |
+
self.layers.extend(layers)
|
| 1621 |
+
if self.layerReuseCache is not None:
|
| 1622 |
+
self.layerReuseCache.add(layers, paint.FirstLayerIndex)
|
| 1623 |
+
return paint
|
| 1624 |
+
|
| 1625 |
+
out_layers = [listToColrLayers(l) for l in out_layers]
|
| 1626 |
+
|
| 1627 |
+
if len(out_layers) == 1 and out_layers[0].Format == ot.PaintFormat.PaintColrLayers:
|
| 1628 |
+
# special case when the reuse cache finds a single perfect PaintColrLayers match
|
| 1629 |
+
# (it can only come from a successful reuse, _flatten_layers has gotten rid of
|
| 1630 |
+
# all nested PaintColrLayers already); we assign it directly and avoid creating
|
| 1631 |
+
# an extra table
|
| 1632 |
+
out.NumLayers = out_layers[0].NumLayers
|
| 1633 |
+
out.FirstLayerIndex = out_layers[0].FirstLayerIndex
|
| 1634 |
+
else:
|
| 1635 |
+
out.NumLayers = len(out_layers)
|
| 1636 |
+
out.FirstLayerIndex = len(self.layers)
|
| 1637 |
+
|
| 1638 |
+
self.layers.extend(out_layers)
|
| 1639 |
+
|
| 1640 |
+
# Register our parts for reuse provided we aren't a tree
|
| 1641 |
+
# If we are a tree the leaves registered for reuse and that will suffice
|
| 1642 |
+
if self.layerReuseCache is not None and not is_tree:
|
| 1643 |
+
self.layerReuseCache.add(out_layers, out.FirstLayerIndex)
|
| 1644 |
+
|
| 1645 |
+
|
| 1646 |
+
@COLRVariationMerger.merger((ot.Paint, ot.ClipBox))
|
| 1647 |
+
def merge(merger, self, lst):
|
| 1648 |
+
fmt = merger.checkFormatEnum(self, lst, lambda fmt: not fmt.is_variable())
|
| 1649 |
+
|
| 1650 |
+
if fmt is ot.PaintFormat.PaintColrLayers:
|
| 1651 |
+
_merge_PaintColrLayers(merger, self, lst)
|
| 1652 |
+
return
|
| 1653 |
+
|
| 1654 |
+
varFormat = fmt.as_variable()
|
| 1655 |
+
|
| 1656 |
+
varAttrs = ()
|
| 1657 |
+
if varFormat is not None:
|
| 1658 |
+
varAttrs = otBase.getVariableAttrs(type(self), varFormat)
|
| 1659 |
+
staticAttrs = (c.name for c in self.getConverters() if c.name not in varAttrs)
|
| 1660 |
+
|
| 1661 |
+
merger.mergeAttrs(self, lst, staticAttrs)
|
| 1662 |
+
|
| 1663 |
+
varIndexBase = merger.mergeVariableAttrs(self, lst, varAttrs)
|
| 1664 |
+
|
| 1665 |
+
subTables = [st.value for st in self.iterSubTables()]
|
| 1666 |
+
|
| 1667 |
+
# Convert table to variable if itself has variations or any subtables have
|
| 1668 |
+
isVariable = varIndexBase != ot.NO_VARIATION_INDEX or any(
|
| 1669 |
+
id(table) in merger.varTableIds for table in subTables
|
| 1670 |
+
)
|
| 1671 |
+
|
| 1672 |
+
if isVariable:
|
| 1673 |
+
if varAttrs:
|
| 1674 |
+
# Some PaintVar* don't have any scalar attributes that can vary,
|
| 1675 |
+
# only indirect offsets to other variable subtables, thus have
|
| 1676 |
+
# no VarIndexBase of their own (e.g. PaintVarTransform)
|
| 1677 |
+
self.VarIndexBase = varIndexBase
|
| 1678 |
+
|
| 1679 |
+
if subTables:
|
| 1680 |
+
# Convert Affine2x3 -> VarAffine2x3, ColorLine -> VarColorLine, etc.
|
| 1681 |
+
merger.convertSubTablesToVarType(self)
|
| 1682 |
+
|
| 1683 |
+
assert varFormat is not None
|
| 1684 |
+
self.Format = int(varFormat)
|
| 1685 |
+
|
| 1686 |
+
|
| 1687 |
+
@COLRVariationMerger.merger((ot.Affine2x3, ot.ColorStop))
|
| 1688 |
+
def merge(merger, self, lst):
|
| 1689 |
+
varType = type(self).VarType
|
| 1690 |
+
|
| 1691 |
+
varAttrs = otBase.getVariableAttrs(varType)
|
| 1692 |
+
staticAttrs = (c.name for c in self.getConverters() if c.name not in varAttrs)
|
| 1693 |
+
|
| 1694 |
+
merger.mergeAttrs(self, lst, staticAttrs)
|
| 1695 |
+
|
| 1696 |
+
varIndexBase = merger.mergeVariableAttrs(self, lst, varAttrs)
|
| 1697 |
+
|
| 1698 |
+
if varIndexBase != ot.NO_VARIATION_INDEX:
|
| 1699 |
+
self.VarIndexBase = varIndexBase
|
| 1700 |
+
# mark as having variations so the parent table will convert to Var{Type}
|
| 1701 |
+
merger.varTableIds.add(id(self))
|
| 1702 |
+
|
| 1703 |
+
|
| 1704 |
+
@COLRVariationMerger.merger(ot.ColorLine)
|
| 1705 |
+
def merge(merger, self, lst):
|
| 1706 |
+
merger.mergeAttrs(self, lst, (c.name for c in self.getConverters()))
|
| 1707 |
+
|
| 1708 |
+
if any(id(stop) in merger.varTableIds for stop in self.ColorStop):
|
| 1709 |
+
merger.convertSubTablesToVarType(self)
|
| 1710 |
+
merger.varTableIds.add(id(self))
|
| 1711 |
+
|
| 1712 |
+
|
| 1713 |
+
@COLRVariationMerger.merger(ot.ClipList, "clips")
|
| 1714 |
+
def merge(merger, self, lst):
|
| 1715 |
+
# 'sparse' in that we allow non-default masters to omit ClipBox entries
|
| 1716 |
+
# for some/all glyphs (i.e. they don't participate)
|
| 1717 |
+
merger.mergeSparseDict(self, lst)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/models.py
ADDED
|
@@ -0,0 +1,663 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Variation fonts interpolation models."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
__all__ = [
|
| 6 |
+
"normalizeValue",
|
| 7 |
+
"normalizeLocation",
|
| 8 |
+
"supportScalar",
|
| 9 |
+
"piecewiseLinearMap",
|
| 10 |
+
"VariationModel",
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
from collections.abc import Mapping
|
| 14 |
+
from typing import TYPE_CHECKING
|
| 15 |
+
from fontTools.misc.roundTools import noRound
|
| 16 |
+
from .errors import VariationModelError
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if TYPE_CHECKING:
|
| 20 |
+
from typing import Mapping, Sequence
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def nonNone(lst):
|
| 24 |
+
return [l for l in lst if l is not None]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def allNone(lst):
|
| 28 |
+
return all(l is None for l in lst)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def allEqualTo(ref, lst, mapper=None):
|
| 32 |
+
if mapper is None:
|
| 33 |
+
return all(ref == item for item in lst)
|
| 34 |
+
|
| 35 |
+
mapped = mapper(ref)
|
| 36 |
+
return all(mapped == mapper(item) for item in lst)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def allEqual(lst, mapper=None):
|
| 40 |
+
if not lst:
|
| 41 |
+
return True
|
| 42 |
+
it = iter(lst)
|
| 43 |
+
try:
|
| 44 |
+
first = next(it)
|
| 45 |
+
except StopIteration:
|
| 46 |
+
return True
|
| 47 |
+
return allEqualTo(first, it, mapper=mapper)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def subList(truth, lst):
|
| 51 |
+
assert len(truth) == len(lst)
|
| 52 |
+
return [l for l, t in zip(lst, truth) if t]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def normalizeValue(
|
| 56 |
+
v: float, triple: Sequence[float], extrapolate: bool = False
|
| 57 |
+
) -> float:
|
| 58 |
+
"""Normalizes value based on a min/default/max triple.
|
| 59 |
+
|
| 60 |
+
>>> normalizeValue(400, (100, 400, 900))
|
| 61 |
+
0.0
|
| 62 |
+
>>> normalizeValue(100, (100, 400, 900))
|
| 63 |
+
-1.0
|
| 64 |
+
>>> normalizeValue(650, (100, 400, 900))
|
| 65 |
+
0.5
|
| 66 |
+
"""
|
| 67 |
+
lower, default, upper = triple
|
| 68 |
+
if not (lower <= default <= upper):
|
| 69 |
+
raise ValueError(
|
| 70 |
+
f"Invalid axis values, must be minimum, default, maximum: "
|
| 71 |
+
f"{lower:3.3f}, {default:3.3f}, {upper:3.3f}"
|
| 72 |
+
)
|
| 73 |
+
if not extrapolate:
|
| 74 |
+
v = max(min(v, upper), lower)
|
| 75 |
+
|
| 76 |
+
if v == default or lower == upper:
|
| 77 |
+
return 0.0
|
| 78 |
+
|
| 79 |
+
if (v < default and lower != default) or (v > default and upper == default):
|
| 80 |
+
return (v - default) / (default - lower)
|
| 81 |
+
else:
|
| 82 |
+
assert (v > default and upper != default) or (
|
| 83 |
+
v < default and lower == default
|
| 84 |
+
), f"Ooops... v={v}, triple=({lower}, {default}, {upper})"
|
| 85 |
+
return (v - default) / (upper - default)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def normalizeLocation(
|
| 89 |
+
location: Mapping[str, float],
|
| 90 |
+
axes: Mapping[str, tuple[float, float, float]],
|
| 91 |
+
extrapolate: bool = False,
|
| 92 |
+
*,
|
| 93 |
+
validate: bool = False,
|
| 94 |
+
) -> dict[str, float]:
|
| 95 |
+
"""Normalizes location based on axis min/default/max values from axes.
|
| 96 |
+
|
| 97 |
+
>>> axes = {"wght": (100, 400, 900)}
|
| 98 |
+
>>> normalizeLocation({"wght": 400}, axes)
|
| 99 |
+
{'wght': 0.0}
|
| 100 |
+
>>> normalizeLocation({"wght": 100}, axes)
|
| 101 |
+
{'wght': -1.0}
|
| 102 |
+
>>> normalizeLocation({"wght": 900}, axes)
|
| 103 |
+
{'wght': 1.0}
|
| 104 |
+
>>> normalizeLocation({"wght": 650}, axes)
|
| 105 |
+
{'wght': 0.5}
|
| 106 |
+
>>> normalizeLocation({"wght": 1000}, axes)
|
| 107 |
+
{'wght': 1.0}
|
| 108 |
+
>>> normalizeLocation({"wght": 0}, axes)
|
| 109 |
+
{'wght': -1.0}
|
| 110 |
+
>>> axes = {"wght": (0, 0, 1000)}
|
| 111 |
+
>>> normalizeLocation({"wght": 0}, axes)
|
| 112 |
+
{'wght': 0.0}
|
| 113 |
+
>>> normalizeLocation({"wght": -1}, axes)
|
| 114 |
+
{'wght': 0.0}
|
| 115 |
+
>>> normalizeLocation({"wght": 1000}, axes)
|
| 116 |
+
{'wght': 1.0}
|
| 117 |
+
>>> normalizeLocation({"wght": 500}, axes)
|
| 118 |
+
{'wght': 0.5}
|
| 119 |
+
>>> normalizeLocation({"wght": 1001}, axes)
|
| 120 |
+
{'wght': 1.0}
|
| 121 |
+
>>> axes = {"wght": (0, 1000, 1000)}
|
| 122 |
+
>>> normalizeLocation({"wght": 0}, axes)
|
| 123 |
+
{'wght': -1.0}
|
| 124 |
+
>>> normalizeLocation({"wght": -1}, axes)
|
| 125 |
+
{'wght': -1.0}
|
| 126 |
+
>>> normalizeLocation({"wght": 500}, axes)
|
| 127 |
+
{'wght': -0.5}
|
| 128 |
+
>>> normalizeLocation({"wght": 1000}, axes)
|
| 129 |
+
{'wght': 0.0}
|
| 130 |
+
>>> normalizeLocation({"wght": 1001}, axes)
|
| 131 |
+
{'wght': 0.0}
|
| 132 |
+
"""
|
| 133 |
+
if validate:
|
| 134 |
+
assert set(location.keys()) <= set(axes.keys()), set(location.keys()) - set(
|
| 135 |
+
axes.keys()
|
| 136 |
+
)
|
| 137 |
+
out = {}
|
| 138 |
+
for tag, triple in axes.items():
|
| 139 |
+
v = location.get(tag, triple[1])
|
| 140 |
+
out[tag] = normalizeValue(v, triple, extrapolate=extrapolate)
|
| 141 |
+
return out
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def supportScalar(location, support, ot=True, extrapolate=False, axisRanges=None):
|
| 145 |
+
"""Returns the scalar multiplier at location, for a master
|
| 146 |
+
with support. If ot is True, then a peak value of zero
|
| 147 |
+
for support of an axis means "axis does not participate". That
|
| 148 |
+
is how OpenType Variation Font technology works.
|
| 149 |
+
|
| 150 |
+
If extrapolate is True, axisRanges must be a dict that maps axis
|
| 151 |
+
names to (axisMin, axisMax) tuples.
|
| 152 |
+
|
| 153 |
+
>>> supportScalar({}, {})
|
| 154 |
+
1.0
|
| 155 |
+
>>> supportScalar({'wght':.2}, {})
|
| 156 |
+
1.0
|
| 157 |
+
>>> supportScalar({'wght':.2}, {'wght':(0,2,3)})
|
| 158 |
+
0.1
|
| 159 |
+
>>> supportScalar({'wght':2.5}, {'wght':(0,2,4)})
|
| 160 |
+
0.75
|
| 161 |
+
>>> supportScalar({'wght':2.5, 'wdth':0}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
|
| 162 |
+
0.75
|
| 163 |
+
>>> supportScalar({'wght':2.5, 'wdth':.5}, {'wght':(0,2,4), 'wdth':(-1,0,+1)}, ot=False)
|
| 164 |
+
0.375
|
| 165 |
+
>>> supportScalar({'wght':2.5, 'wdth':0}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
|
| 166 |
+
0.75
|
| 167 |
+
>>> supportScalar({'wght':2.5, 'wdth':.5}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
|
| 168 |
+
0.75
|
| 169 |
+
>>> supportScalar({'wght':3}, {'wght':(0,1,2)}, extrapolate=True, axisRanges={'wght':(0, 2)})
|
| 170 |
+
-1.0
|
| 171 |
+
>>> supportScalar({'wght':-1}, {'wght':(0,1,2)}, extrapolate=True, axisRanges={'wght':(0, 2)})
|
| 172 |
+
-1.0
|
| 173 |
+
>>> supportScalar({'wght':3}, {'wght':(0,2,2)}, extrapolate=True, axisRanges={'wght':(0, 2)})
|
| 174 |
+
1.5
|
| 175 |
+
>>> supportScalar({'wght':-1}, {'wght':(0,2,2)}, extrapolate=True, axisRanges={'wght':(0, 2)})
|
| 176 |
+
-0.5
|
| 177 |
+
"""
|
| 178 |
+
if extrapolate and axisRanges is None:
|
| 179 |
+
raise TypeError("axisRanges must be passed when extrapolate is True")
|
| 180 |
+
scalar = 1.0
|
| 181 |
+
for axis, (lower, peak, upper) in support.items():
|
| 182 |
+
if ot:
|
| 183 |
+
# OpenType-specific case handling
|
| 184 |
+
if peak == 0.0:
|
| 185 |
+
continue
|
| 186 |
+
if lower > peak or peak > upper:
|
| 187 |
+
continue
|
| 188 |
+
if lower < 0.0 and upper > 0.0:
|
| 189 |
+
continue
|
| 190 |
+
v = location.get(axis, 0.0)
|
| 191 |
+
else:
|
| 192 |
+
assert axis in location
|
| 193 |
+
v = location[axis]
|
| 194 |
+
if v == peak:
|
| 195 |
+
continue
|
| 196 |
+
|
| 197 |
+
if extrapolate:
|
| 198 |
+
axisMin, axisMax = axisRanges[axis]
|
| 199 |
+
if v < axisMin and lower <= axisMin:
|
| 200 |
+
if peak <= axisMin and peak < upper:
|
| 201 |
+
scalar *= (v - upper) / (peak - upper)
|
| 202 |
+
continue
|
| 203 |
+
elif axisMin < peak:
|
| 204 |
+
scalar *= (v - lower) / (peak - lower)
|
| 205 |
+
continue
|
| 206 |
+
elif axisMax < v and axisMax <= upper:
|
| 207 |
+
if axisMax <= peak and lower < peak:
|
| 208 |
+
scalar *= (v - lower) / (peak - lower)
|
| 209 |
+
continue
|
| 210 |
+
elif peak < axisMax:
|
| 211 |
+
scalar *= (v - upper) / (peak - upper)
|
| 212 |
+
continue
|
| 213 |
+
|
| 214 |
+
if v <= lower or upper <= v:
|
| 215 |
+
scalar = 0.0
|
| 216 |
+
break
|
| 217 |
+
|
| 218 |
+
if v < peak:
|
| 219 |
+
scalar *= (v - lower) / (peak - lower)
|
| 220 |
+
else: # v > peak
|
| 221 |
+
scalar *= (v - upper) / (peak - upper)
|
| 222 |
+
return scalar
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
class VariationModel(object):
|
| 226 |
+
"""Locations must have the base master at the origin (ie. 0).
|
| 227 |
+
|
| 228 |
+
If axis-ranges are not provided, values are assumed to be normalized to
|
| 229 |
+
the range [-1, 1].
|
| 230 |
+
|
| 231 |
+
If the extrapolate argument is set to True, then values are extrapolated
|
| 232 |
+
outside the axis range.
|
| 233 |
+
|
| 234 |
+
>>> from pprint import pprint
|
| 235 |
+
>>> axisRanges = {'wght': (-180, +180), 'wdth': (-1, +1)}
|
| 236 |
+
>>> locations = [ \
|
| 237 |
+
{'wght':100}, \
|
| 238 |
+
{'wght':-100}, \
|
| 239 |
+
{'wght':-180}, \
|
| 240 |
+
{'wdth':+.3}, \
|
| 241 |
+
{'wght':+120,'wdth':.3}, \
|
| 242 |
+
{'wght':+120,'wdth':.2}, \
|
| 243 |
+
{}, \
|
| 244 |
+
{'wght':+180,'wdth':.3}, \
|
| 245 |
+
{'wght':+180}, \
|
| 246 |
+
]
|
| 247 |
+
>>> model = VariationModel(locations, axisOrder=['wght'], axisRanges=axisRanges)
|
| 248 |
+
>>> pprint(model.locations)
|
| 249 |
+
[{},
|
| 250 |
+
{'wght': -100},
|
| 251 |
+
{'wght': -180},
|
| 252 |
+
{'wght': 100},
|
| 253 |
+
{'wght': 180},
|
| 254 |
+
{'wdth': 0.3},
|
| 255 |
+
{'wdth': 0.3, 'wght': 180},
|
| 256 |
+
{'wdth': 0.3, 'wght': 120},
|
| 257 |
+
{'wdth': 0.2, 'wght': 120}]
|
| 258 |
+
>>> pprint(model.deltaWeights)
|
| 259 |
+
[{},
|
| 260 |
+
{0: 1.0},
|
| 261 |
+
{0: 1.0},
|
| 262 |
+
{0: 1.0},
|
| 263 |
+
{0: 1.0},
|
| 264 |
+
{0: 1.0},
|
| 265 |
+
{0: 1.0, 4: 1.0, 5: 1.0},
|
| 266 |
+
{0: 1.0, 3: 0.75, 4: 0.25, 5: 1.0, 6: 0.6666666666666666},
|
| 267 |
+
{0: 1.0,
|
| 268 |
+
3: 0.75,
|
| 269 |
+
4: 0.25,
|
| 270 |
+
5: 0.6666666666666667,
|
| 271 |
+
6: 0.4444444444444445,
|
| 272 |
+
7: 0.6666666666666667}]
|
| 273 |
+
"""
|
| 274 |
+
|
| 275 |
+
def __init__(
|
| 276 |
+
self, locations, axisOrder=None, extrapolate=False, *, axisRanges=None
|
| 277 |
+
):
|
| 278 |
+
locations = [{k: v for k, v in loc.items() if v != 0.0} for loc in locations]
|
| 279 |
+
|
| 280 |
+
if len(set(tuple(sorted(l.items())) for l in locations)) != len(locations):
|
| 281 |
+
raise VariationModelError("Locations must be unique.")
|
| 282 |
+
|
| 283 |
+
self.origLocations = locations
|
| 284 |
+
self.axisOrder = axisOrder if axisOrder is not None else []
|
| 285 |
+
self.extrapolate = extrapolate
|
| 286 |
+
if axisRanges is None:
|
| 287 |
+
if extrapolate:
|
| 288 |
+
axisRanges = self.computeAxisRanges(locations)
|
| 289 |
+
else:
|
| 290 |
+
allAxes = {axis for loc in locations for axis in loc.keys()}
|
| 291 |
+
axisRanges = {axis: (-1, 1) for axis in allAxes}
|
| 292 |
+
self.axisRanges = axisRanges
|
| 293 |
+
keyFunc = self.getMasterLocationsSortKeyFunc(
|
| 294 |
+
locations, axisOrder=self.axisOrder
|
| 295 |
+
)
|
| 296 |
+
self.locations = sorted(locations, key=keyFunc)
|
| 297 |
+
|
| 298 |
+
# Mapping from user's master order to our master order
|
| 299 |
+
self.mapping = [self.locations.index(l) for l in locations]
|
| 300 |
+
self.reverseMapping = [locations.index(l) for l in self.locations]
|
| 301 |
+
|
| 302 |
+
self._computeMasterSupports()
|
| 303 |
+
self._subModels = {}
|
| 304 |
+
|
| 305 |
+
def getSubModel(self, items):
|
| 306 |
+
"""Return a sub-model and the items that are not None.
|
| 307 |
+
|
| 308 |
+
The sub-model is necessary for working with the subset
|
| 309 |
+
of items when some are None.
|
| 310 |
+
|
| 311 |
+
The sub-model is cached."""
|
| 312 |
+
if None not in items:
|
| 313 |
+
return self, items
|
| 314 |
+
key = tuple(v is not None for v in items)
|
| 315 |
+
subModel = self._subModels.get(key)
|
| 316 |
+
if subModel is None:
|
| 317 |
+
subModel = VariationModel(
|
| 318 |
+
subList(key, self.origLocations),
|
| 319 |
+
self.axisOrder,
|
| 320 |
+
extrapolate=self.extrapolate,
|
| 321 |
+
axisRanges=self.axisRanges,
|
| 322 |
+
)
|
| 323 |
+
self._subModels[key] = subModel
|
| 324 |
+
return subModel, subList(key, items)
|
| 325 |
+
|
| 326 |
+
@staticmethod
|
| 327 |
+
def computeAxisRanges(locations):
|
| 328 |
+
axisRanges = {}
|
| 329 |
+
allAxes = {axis for loc in locations for axis in loc.keys()}
|
| 330 |
+
for loc in locations:
|
| 331 |
+
for axis in allAxes:
|
| 332 |
+
value = loc.get(axis, 0)
|
| 333 |
+
axisMin, axisMax = axisRanges.get(axis, (value, value))
|
| 334 |
+
axisRanges[axis] = min(value, axisMin), max(value, axisMax)
|
| 335 |
+
return axisRanges
|
| 336 |
+
|
| 337 |
+
@staticmethod
|
| 338 |
+
def getMasterLocationsSortKeyFunc(locations, axisOrder=[]):
|
| 339 |
+
if {} not in locations:
|
| 340 |
+
raise VariationModelError("Base master not found.")
|
| 341 |
+
axisPoints = {}
|
| 342 |
+
for loc in locations:
|
| 343 |
+
if len(loc) != 1:
|
| 344 |
+
continue
|
| 345 |
+
axis = next(iter(loc))
|
| 346 |
+
value = loc[axis]
|
| 347 |
+
if axis not in axisPoints:
|
| 348 |
+
axisPoints[axis] = {0.0}
|
| 349 |
+
assert (
|
| 350 |
+
value not in axisPoints[axis]
|
| 351 |
+
), 'Value "%s" in axisPoints["%s"] --> %s' % (value, axis, axisPoints)
|
| 352 |
+
axisPoints[axis].add(value)
|
| 353 |
+
|
| 354 |
+
def getKey(axisPoints, axisOrder):
|
| 355 |
+
def sign(v):
|
| 356 |
+
return -1 if v < 0 else +1 if v > 0 else 0
|
| 357 |
+
|
| 358 |
+
def key(loc):
|
| 359 |
+
rank = len(loc)
|
| 360 |
+
onPointAxes = [
|
| 361 |
+
axis
|
| 362 |
+
for axis, value in loc.items()
|
| 363 |
+
if axis in axisPoints and value in axisPoints[axis]
|
| 364 |
+
]
|
| 365 |
+
orderedAxes = [axis for axis in axisOrder if axis in loc]
|
| 366 |
+
orderedAxes.extend(
|
| 367 |
+
[axis for axis in sorted(loc.keys()) if axis not in axisOrder]
|
| 368 |
+
)
|
| 369 |
+
return (
|
| 370 |
+
rank, # First, order by increasing rank
|
| 371 |
+
-len(onPointAxes), # Next, by decreasing number of onPoint axes
|
| 372 |
+
tuple(
|
| 373 |
+
axisOrder.index(axis) if axis in axisOrder else 0x10000
|
| 374 |
+
for axis in orderedAxes
|
| 375 |
+
), # Next, by known axes
|
| 376 |
+
tuple(orderedAxes), # Next, by all axes
|
| 377 |
+
tuple(
|
| 378 |
+
sign(loc[axis]) for axis in orderedAxes
|
| 379 |
+
), # Next, by signs of axis values
|
| 380 |
+
tuple(
|
| 381 |
+
abs(loc[axis]) for axis in orderedAxes
|
| 382 |
+
), # Next, by absolute value of axis values
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
return key
|
| 386 |
+
|
| 387 |
+
ret = getKey(axisPoints, axisOrder)
|
| 388 |
+
return ret
|
| 389 |
+
|
| 390 |
+
def reorderMasters(self, master_list, mapping):
|
| 391 |
+
# For changing the master data order without
|
| 392 |
+
# recomputing supports and deltaWeights.
|
| 393 |
+
new_list = [master_list[idx] for idx in mapping]
|
| 394 |
+
self.origLocations = [self.origLocations[idx] for idx in mapping]
|
| 395 |
+
locations = [
|
| 396 |
+
{k: v for k, v in loc.items() if v != 0.0} for loc in self.origLocations
|
| 397 |
+
]
|
| 398 |
+
self.mapping = [self.locations.index(l) for l in locations]
|
| 399 |
+
self.reverseMapping = [locations.index(l) for l in self.locations]
|
| 400 |
+
self._subModels = {}
|
| 401 |
+
return new_list
|
| 402 |
+
|
| 403 |
+
def _computeMasterSupports(self):
|
| 404 |
+
self.supports = []
|
| 405 |
+
regions = self._locationsToRegions()
|
| 406 |
+
for i, region in enumerate(regions):
|
| 407 |
+
locAxes = set(region.keys())
|
| 408 |
+
# Walk over previous masters now
|
| 409 |
+
for prev_region in regions[:i]:
|
| 410 |
+
# Master with different axes do not participate
|
| 411 |
+
if set(prev_region.keys()) != locAxes:
|
| 412 |
+
continue
|
| 413 |
+
# If it's NOT in the current box, it does not participate
|
| 414 |
+
relevant = True
|
| 415 |
+
for axis, (lower, peak, upper) in region.items():
|
| 416 |
+
if not (
|
| 417 |
+
prev_region[axis][1] == peak
|
| 418 |
+
or lower < prev_region[axis][1] < upper
|
| 419 |
+
):
|
| 420 |
+
relevant = False
|
| 421 |
+
break
|
| 422 |
+
if not relevant:
|
| 423 |
+
continue
|
| 424 |
+
|
| 425 |
+
# Split the box for new master; split in whatever direction
|
| 426 |
+
# that has largest range ratio.
|
| 427 |
+
#
|
| 428 |
+
# For symmetry, we actually cut across multiple axes
|
| 429 |
+
# if they have the largest, equal, ratio.
|
| 430 |
+
# https://github.com/fonttools/fonttools/commit/7ee81c8821671157968b097f3e55309a1faa511e#commitcomment-31054804
|
| 431 |
+
|
| 432 |
+
bestAxes = {}
|
| 433 |
+
bestRatio = -1
|
| 434 |
+
for axis in prev_region.keys():
|
| 435 |
+
val = prev_region[axis][1]
|
| 436 |
+
assert axis in region
|
| 437 |
+
lower, locV, upper = region[axis]
|
| 438 |
+
newLower, newUpper = lower, upper
|
| 439 |
+
if val < locV:
|
| 440 |
+
newLower = val
|
| 441 |
+
ratio = (val - locV) / (lower - locV)
|
| 442 |
+
elif locV < val:
|
| 443 |
+
newUpper = val
|
| 444 |
+
ratio = (val - locV) / (upper - locV)
|
| 445 |
+
else: # val == locV
|
| 446 |
+
# Can't split box in this direction.
|
| 447 |
+
continue
|
| 448 |
+
if ratio > bestRatio:
|
| 449 |
+
bestAxes = {}
|
| 450 |
+
bestRatio = ratio
|
| 451 |
+
if ratio == bestRatio:
|
| 452 |
+
bestAxes[axis] = (newLower, locV, newUpper)
|
| 453 |
+
|
| 454 |
+
for axis, triple in bestAxes.items():
|
| 455 |
+
region[axis] = triple
|
| 456 |
+
self.supports.append(region)
|
| 457 |
+
self._computeDeltaWeights()
|
| 458 |
+
|
| 459 |
+
def _locationsToRegions(self):
|
| 460 |
+
locations = self.locations
|
| 461 |
+
axisRanges = self.axisRanges
|
| 462 |
+
|
| 463 |
+
regions = []
|
| 464 |
+
for loc in locations:
|
| 465 |
+
region = {}
|
| 466 |
+
for axis, locV in loc.items():
|
| 467 |
+
if locV > 0:
|
| 468 |
+
region[axis] = (0, locV, axisRanges[axis][1])
|
| 469 |
+
else:
|
| 470 |
+
region[axis] = (axisRanges[axis][0], locV, 0)
|
| 471 |
+
regions.append(region)
|
| 472 |
+
return regions
|
| 473 |
+
|
| 474 |
+
def _computeDeltaWeights(self):
|
| 475 |
+
self.deltaWeights = []
|
| 476 |
+
for i, loc in enumerate(self.locations):
|
| 477 |
+
deltaWeight = {}
|
| 478 |
+
# Walk over previous masters now, populate deltaWeight
|
| 479 |
+
for j, support in enumerate(self.supports[:i]):
|
| 480 |
+
scalar = supportScalar(loc, support)
|
| 481 |
+
if scalar:
|
| 482 |
+
deltaWeight[j] = scalar
|
| 483 |
+
self.deltaWeights.append(deltaWeight)
|
| 484 |
+
|
| 485 |
+
def getDeltas(self, masterValues, *, round=noRound):
|
| 486 |
+
assert len(masterValues) == len(self.deltaWeights), (
|
| 487 |
+
len(masterValues),
|
| 488 |
+
len(self.deltaWeights),
|
| 489 |
+
)
|
| 490 |
+
mapping = self.reverseMapping
|
| 491 |
+
out = []
|
| 492 |
+
for i, weights in enumerate(self.deltaWeights):
|
| 493 |
+
delta = masterValues[mapping[i]]
|
| 494 |
+
for j, weight in weights.items():
|
| 495 |
+
if weight == 1:
|
| 496 |
+
delta -= out[j]
|
| 497 |
+
else:
|
| 498 |
+
delta -= out[j] * weight
|
| 499 |
+
out.append(round(delta))
|
| 500 |
+
return out
|
| 501 |
+
|
| 502 |
+
def getDeltasAndSupports(self, items, *, round=noRound):
|
| 503 |
+
model, items = self.getSubModel(items)
|
| 504 |
+
return model.getDeltas(items, round=round), model.supports
|
| 505 |
+
|
| 506 |
+
def getScalars(self, loc):
|
| 507 |
+
"""Return scalars for each delta, for the given location.
|
| 508 |
+
If interpolating many master-values at the same location,
|
| 509 |
+
this function allows speed up by fetching the scalars once
|
| 510 |
+
and using them with interpolateFromMastersAndScalars()."""
|
| 511 |
+
return [
|
| 512 |
+
supportScalar(
|
| 513 |
+
loc, support, extrapolate=self.extrapolate, axisRanges=self.axisRanges
|
| 514 |
+
)
|
| 515 |
+
for support in self.supports
|
| 516 |
+
]
|
| 517 |
+
|
| 518 |
+
def getMasterScalars(self, targetLocation):
|
| 519 |
+
"""Return multipliers for each master, for the given location.
|
| 520 |
+
If interpolating many master-values at the same location,
|
| 521 |
+
this function allows speed up by fetching the scalars once
|
| 522 |
+
and using them with interpolateFromValuesAndScalars().
|
| 523 |
+
|
| 524 |
+
Note that the scalars used in interpolateFromMastersAndScalars(),
|
| 525 |
+
are *not* the same as the ones returned here. They are the result
|
| 526 |
+
of getScalars()."""
|
| 527 |
+
out = self.getScalars(targetLocation)
|
| 528 |
+
for i, weights in reversed(list(enumerate(self.deltaWeights))):
|
| 529 |
+
for j, weight in weights.items():
|
| 530 |
+
out[j] -= out[i] * weight
|
| 531 |
+
|
| 532 |
+
out = [out[self.mapping[i]] for i in range(len(out))]
|
| 533 |
+
return out
|
| 534 |
+
|
| 535 |
+
@staticmethod
|
| 536 |
+
def interpolateFromValuesAndScalars(values, scalars):
|
| 537 |
+
"""Interpolate from values and scalars coefficients.
|
| 538 |
+
|
| 539 |
+
If the values are master-values, then the scalars should be
|
| 540 |
+
fetched from getMasterScalars().
|
| 541 |
+
|
| 542 |
+
If the values are deltas, then the scalars should be fetched
|
| 543 |
+
from getScalars(); in which case this is the same as
|
| 544 |
+
interpolateFromDeltasAndScalars().
|
| 545 |
+
"""
|
| 546 |
+
v = None
|
| 547 |
+
assert len(values) == len(scalars)
|
| 548 |
+
for value, scalar in zip(values, scalars):
|
| 549 |
+
if not scalar:
|
| 550 |
+
continue
|
| 551 |
+
contribution = value * scalar
|
| 552 |
+
if v is None:
|
| 553 |
+
v = contribution
|
| 554 |
+
else:
|
| 555 |
+
v += contribution
|
| 556 |
+
return v
|
| 557 |
+
|
| 558 |
+
@staticmethod
|
| 559 |
+
def interpolateFromDeltasAndScalars(deltas, scalars):
|
| 560 |
+
"""Interpolate from deltas and scalars fetched from getScalars()."""
|
| 561 |
+
return VariationModel.interpolateFromValuesAndScalars(deltas, scalars)
|
| 562 |
+
|
| 563 |
+
def interpolateFromDeltas(self, loc, deltas):
|
| 564 |
+
"""Interpolate from deltas, at location loc."""
|
| 565 |
+
scalars = self.getScalars(loc)
|
| 566 |
+
return self.interpolateFromDeltasAndScalars(deltas, scalars)
|
| 567 |
+
|
| 568 |
+
def interpolateFromMasters(self, loc, masterValues, *, round=noRound):
|
| 569 |
+
"""Interpolate from master-values, at location loc."""
|
| 570 |
+
scalars = self.getMasterScalars(loc)
|
| 571 |
+
return self.interpolateFromValuesAndScalars(masterValues, scalars)
|
| 572 |
+
|
| 573 |
+
def interpolateFromMastersAndScalars(self, masterValues, scalars, *, round=noRound):
|
| 574 |
+
"""Interpolate from master-values, and scalars fetched from
|
| 575 |
+
getScalars(), which is useful when you want to interpolate
|
| 576 |
+
multiple master-values with the same location."""
|
| 577 |
+
deltas = self.getDeltas(masterValues, round=round)
|
| 578 |
+
return self.interpolateFromDeltasAndScalars(deltas, scalars)
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
def piecewiseLinearMap(v: float, mapping: Mapping[float, float]) -> float:
|
| 582 |
+
keys = mapping.keys()
|
| 583 |
+
if not keys:
|
| 584 |
+
return v
|
| 585 |
+
if v in keys:
|
| 586 |
+
return mapping[v]
|
| 587 |
+
k = min(keys)
|
| 588 |
+
if v < k:
|
| 589 |
+
return v + mapping[k] - k
|
| 590 |
+
k = max(keys)
|
| 591 |
+
if v > k:
|
| 592 |
+
return v + mapping[k] - k
|
| 593 |
+
# Interpolate
|
| 594 |
+
a = max(k for k in keys if k < v)
|
| 595 |
+
b = min(k for k in keys if k > v)
|
| 596 |
+
va = mapping[a]
|
| 597 |
+
vb = mapping[b]
|
| 598 |
+
return va + (vb - va) * (v - a) / (b - a)
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def main(args=None):
|
| 602 |
+
"""Normalize locations on a given designspace"""
|
| 603 |
+
from fontTools import configLogger
|
| 604 |
+
import argparse
|
| 605 |
+
|
| 606 |
+
parser = argparse.ArgumentParser(
|
| 607 |
+
"fonttools varLib.models",
|
| 608 |
+
description=main.__doc__,
|
| 609 |
+
)
|
| 610 |
+
parser.add_argument(
|
| 611 |
+
"--loglevel",
|
| 612 |
+
metavar="LEVEL",
|
| 613 |
+
default="INFO",
|
| 614 |
+
help="Logging level (defaults to INFO)",
|
| 615 |
+
)
|
| 616 |
+
|
| 617 |
+
group = parser.add_mutually_exclusive_group(required=True)
|
| 618 |
+
group.add_argument("-d", "--designspace", metavar="DESIGNSPACE", type=str)
|
| 619 |
+
group.add_argument(
|
| 620 |
+
"-l",
|
| 621 |
+
"--locations",
|
| 622 |
+
metavar="LOCATION",
|
| 623 |
+
nargs="+",
|
| 624 |
+
help="Master locations as comma-separate coordinates. One must be all zeros.",
|
| 625 |
+
)
|
| 626 |
+
|
| 627 |
+
args = parser.parse_args(args)
|
| 628 |
+
|
| 629 |
+
configLogger(level=args.loglevel)
|
| 630 |
+
from pprint import pprint
|
| 631 |
+
|
| 632 |
+
if args.designspace:
|
| 633 |
+
from fontTools.designspaceLib import DesignSpaceDocument
|
| 634 |
+
|
| 635 |
+
doc = DesignSpaceDocument()
|
| 636 |
+
doc.read(args.designspace)
|
| 637 |
+
locs = [s.location for s in doc.sources]
|
| 638 |
+
print("Original locations:")
|
| 639 |
+
pprint(locs)
|
| 640 |
+
doc.normalize()
|
| 641 |
+
print("Normalized locations:")
|
| 642 |
+
locs = [s.location for s in doc.sources]
|
| 643 |
+
pprint(locs)
|
| 644 |
+
else:
|
| 645 |
+
axes = [chr(c) for c in range(ord("A"), ord("Z") + 1)]
|
| 646 |
+
locs = [
|
| 647 |
+
dict(zip(axes, (float(v) for v in s.split(",")))) for s in args.locations
|
| 648 |
+
]
|
| 649 |
+
|
| 650 |
+
model = VariationModel(locs)
|
| 651 |
+
print("Sorted locations:")
|
| 652 |
+
pprint(model.locations)
|
| 653 |
+
print("Supports:")
|
| 654 |
+
pprint(model.supports)
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
if __name__ == "__main__":
|
| 658 |
+
import doctest, sys
|
| 659 |
+
|
| 660 |
+
if len(sys.argv) > 1:
|
| 661 |
+
sys.exit(main())
|
| 662 |
+
|
| 663 |
+
sys.exit(doctest.testmod().failed)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/multiVarStore.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc.roundTools import noRound, otRound
|
| 2 |
+
from fontTools.misc.intTools import bit_count
|
| 3 |
+
from fontTools.misc.vector import Vector
|
| 4 |
+
from fontTools.ttLib.tables import otTables as ot
|
| 5 |
+
from fontTools.varLib.models import supportScalar
|
| 6 |
+
import fontTools.varLib.varStore # For monkey-patching
|
| 7 |
+
from fontTools.varLib.builder import (
|
| 8 |
+
buildVarRegionList,
|
| 9 |
+
buildSparseVarRegionList,
|
| 10 |
+
buildSparseVarRegion,
|
| 11 |
+
buildMultiVarStore,
|
| 12 |
+
buildMultiVarData,
|
| 13 |
+
)
|
| 14 |
+
from fontTools.misc.iterTools import batched
|
| 15 |
+
from functools import partial
|
| 16 |
+
from collections import defaultdict
|
| 17 |
+
from heapq import heappush, heappop
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
NO_VARIATION_INDEX = ot.NO_VARIATION_INDEX
|
| 21 |
+
ot.MultiVarStore.NO_VARIATION_INDEX = NO_VARIATION_INDEX
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _getLocationKey(loc):
|
| 25 |
+
return tuple(sorted(loc.items(), key=lambda kv: kv[0]))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class OnlineMultiVarStoreBuilder(object):
|
| 29 |
+
def __init__(self, axisTags):
|
| 30 |
+
self._axisTags = axisTags
|
| 31 |
+
self._regionMap = {}
|
| 32 |
+
self._regionList = buildSparseVarRegionList([], axisTags)
|
| 33 |
+
self._store = buildMultiVarStore(self._regionList, [])
|
| 34 |
+
self._data = None
|
| 35 |
+
self._model = None
|
| 36 |
+
self._supports = None
|
| 37 |
+
self._varDataIndices = {}
|
| 38 |
+
self._varDataCaches = {}
|
| 39 |
+
self._cache = None
|
| 40 |
+
|
| 41 |
+
def setModel(self, model):
|
| 42 |
+
self.setSupports(model.supports)
|
| 43 |
+
self._model = model
|
| 44 |
+
|
| 45 |
+
def setSupports(self, supports):
|
| 46 |
+
self._model = None
|
| 47 |
+
self._supports = list(supports)
|
| 48 |
+
if not self._supports[0]:
|
| 49 |
+
del self._supports[0] # Drop base master support
|
| 50 |
+
self._cache = None
|
| 51 |
+
self._data = None
|
| 52 |
+
|
| 53 |
+
def finish(self):
|
| 54 |
+
self._regionList.RegionCount = len(self._regionList.Region)
|
| 55 |
+
self._store.MultiVarDataCount = len(self._store.MultiVarData)
|
| 56 |
+
return self._store
|
| 57 |
+
|
| 58 |
+
def _add_MultiVarData(self):
|
| 59 |
+
regionMap = self._regionMap
|
| 60 |
+
regionList = self._regionList
|
| 61 |
+
|
| 62 |
+
regions = self._supports
|
| 63 |
+
regionIndices = []
|
| 64 |
+
for region in regions:
|
| 65 |
+
key = _getLocationKey(region)
|
| 66 |
+
idx = regionMap.get(key)
|
| 67 |
+
if idx is None:
|
| 68 |
+
varRegion = buildSparseVarRegion(region, self._axisTags)
|
| 69 |
+
idx = regionMap[key] = len(regionList.Region)
|
| 70 |
+
regionList.Region.append(varRegion)
|
| 71 |
+
regionIndices.append(idx)
|
| 72 |
+
|
| 73 |
+
# Check if we have one already...
|
| 74 |
+
key = tuple(regionIndices)
|
| 75 |
+
varDataIdx = self._varDataIndices.get(key)
|
| 76 |
+
if varDataIdx is not None:
|
| 77 |
+
self._outer = varDataIdx
|
| 78 |
+
self._data = self._store.MultiVarData[varDataIdx]
|
| 79 |
+
self._cache = self._varDataCaches[key]
|
| 80 |
+
if len(self._data.Item) == 0xFFFF:
|
| 81 |
+
# This is full. Need new one.
|
| 82 |
+
varDataIdx = None
|
| 83 |
+
|
| 84 |
+
if varDataIdx is None:
|
| 85 |
+
self._data = buildMultiVarData(regionIndices, [])
|
| 86 |
+
self._outer = len(self._store.MultiVarData)
|
| 87 |
+
self._store.MultiVarData.append(self._data)
|
| 88 |
+
self._varDataIndices[key] = self._outer
|
| 89 |
+
if key not in self._varDataCaches:
|
| 90 |
+
self._varDataCaches[key] = {}
|
| 91 |
+
self._cache = self._varDataCaches[key]
|
| 92 |
+
|
| 93 |
+
def storeMasters(self, master_values, *, round=round):
|
| 94 |
+
deltas = self._model.getDeltas(master_values, round=round)
|
| 95 |
+
base = deltas.pop(0)
|
| 96 |
+
return base, self.storeDeltas(deltas, round=noRound)
|
| 97 |
+
|
| 98 |
+
def storeDeltas(self, deltas, *, round=round):
|
| 99 |
+
deltas = tuple(round(d) for d in deltas)
|
| 100 |
+
|
| 101 |
+
if not any(deltas):
|
| 102 |
+
return NO_VARIATION_INDEX
|
| 103 |
+
|
| 104 |
+
deltas_tuple = tuple(tuple(d) for d in deltas)
|
| 105 |
+
|
| 106 |
+
if not self._data:
|
| 107 |
+
self._add_MultiVarData()
|
| 108 |
+
|
| 109 |
+
varIdx = self._cache.get(deltas_tuple)
|
| 110 |
+
if varIdx is not None:
|
| 111 |
+
return varIdx
|
| 112 |
+
|
| 113 |
+
inner = len(self._data.Item)
|
| 114 |
+
if inner == 0xFFFF:
|
| 115 |
+
# Full array. Start new one.
|
| 116 |
+
self._add_MultiVarData()
|
| 117 |
+
return self.storeDeltas(deltas, round=noRound)
|
| 118 |
+
self._data.addItem(deltas, round=noRound)
|
| 119 |
+
|
| 120 |
+
varIdx = (self._outer << 16) + inner
|
| 121 |
+
self._cache[deltas_tuple] = varIdx
|
| 122 |
+
return varIdx
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def MultiVarData_addItem(self, deltas, *, round=round):
|
| 126 |
+
deltas = tuple(round(d) for d in deltas)
|
| 127 |
+
|
| 128 |
+
assert len(deltas) == self.VarRegionCount
|
| 129 |
+
|
| 130 |
+
values = []
|
| 131 |
+
for d in deltas:
|
| 132 |
+
values.extend(d)
|
| 133 |
+
|
| 134 |
+
self.Item.append(values)
|
| 135 |
+
self.ItemCount = len(self.Item)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
ot.MultiVarData.addItem = MultiVarData_addItem
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def SparseVarRegion_get_support(self, fvar_axes):
|
| 142 |
+
return {
|
| 143 |
+
fvar_axes[reg.AxisIndex].axisTag: (reg.StartCoord, reg.PeakCoord, reg.EndCoord)
|
| 144 |
+
for reg in self.SparseVarRegionAxis
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
ot.SparseVarRegion.get_support = SparseVarRegion_get_support
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def MultiVarStore___bool__(self):
|
| 152 |
+
return bool(self.MultiVarData)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
ot.MultiVarStore.__bool__ = MultiVarStore___bool__
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class MultiVarStoreInstancer(object):
|
| 159 |
+
def __init__(self, multivarstore, fvar_axes, location={}):
|
| 160 |
+
self.fvar_axes = fvar_axes
|
| 161 |
+
assert multivarstore is None or multivarstore.Format == 1
|
| 162 |
+
self._varData = multivarstore.MultiVarData if multivarstore else []
|
| 163 |
+
self._regions = (
|
| 164 |
+
multivarstore.SparseVarRegionList.Region if multivarstore else []
|
| 165 |
+
)
|
| 166 |
+
self.setLocation(location)
|
| 167 |
+
|
| 168 |
+
def setLocation(self, location):
|
| 169 |
+
self.location = dict(location)
|
| 170 |
+
self._clearCaches()
|
| 171 |
+
|
| 172 |
+
def _clearCaches(self):
|
| 173 |
+
self._scalars = {}
|
| 174 |
+
|
| 175 |
+
def _getScalar(self, regionIdx):
|
| 176 |
+
scalar = self._scalars.get(regionIdx)
|
| 177 |
+
if scalar is None:
|
| 178 |
+
support = self._regions[regionIdx].get_support(self.fvar_axes)
|
| 179 |
+
scalar = supportScalar(self.location, support)
|
| 180 |
+
self._scalars[regionIdx] = scalar
|
| 181 |
+
return scalar
|
| 182 |
+
|
| 183 |
+
@staticmethod
|
| 184 |
+
def interpolateFromDeltasAndScalars(deltas, scalars):
|
| 185 |
+
if not deltas:
|
| 186 |
+
return Vector([])
|
| 187 |
+
assert len(deltas) % len(scalars) == 0, (len(deltas), len(scalars))
|
| 188 |
+
m = len(deltas) // len(scalars)
|
| 189 |
+
delta = Vector([0] * m)
|
| 190 |
+
for d, s in zip(batched(deltas, m), scalars):
|
| 191 |
+
if not s:
|
| 192 |
+
continue
|
| 193 |
+
delta += Vector(d) * s
|
| 194 |
+
return delta
|
| 195 |
+
|
| 196 |
+
def __getitem__(self, varidx):
|
| 197 |
+
major, minor = varidx >> 16, varidx & 0xFFFF
|
| 198 |
+
if varidx == NO_VARIATION_INDEX:
|
| 199 |
+
return Vector([])
|
| 200 |
+
varData = self._varData
|
| 201 |
+
scalars = [self._getScalar(ri) for ri in varData[major].VarRegionIndex]
|
| 202 |
+
deltas = varData[major].Item[minor]
|
| 203 |
+
return self.interpolateFromDeltasAndScalars(deltas, scalars)
|
| 204 |
+
|
| 205 |
+
def interpolateFromDeltas(self, varDataIndex, deltas):
|
| 206 |
+
varData = self._varData
|
| 207 |
+
scalars = [self._getScalar(ri) for ri in varData[varDataIndex].VarRegionIndex]
|
| 208 |
+
return self.interpolateFromDeltasAndScalars(deltas, scalars)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def MultiVarStore_subset_varidxes(self, varIdxes):
|
| 212 |
+
return ot.VarStore.subset_varidxes(self, varIdxes, VarData="MultiVarData")
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def MultiVarStore_prune_regions(self):
|
| 216 |
+
return ot.VarStore.prune_regions(
|
| 217 |
+
self, VarData="MultiVarData", VarRegionList="SparseVarRegionList"
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
ot.MultiVarStore.prune_regions = MultiVarStore_prune_regions
|
| 222 |
+
ot.MultiVarStore.subset_varidxes = MultiVarStore_subset_varidxes
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def MultiVarStore_get_supports(self, major, fvarAxes):
|
| 226 |
+
supports = []
|
| 227 |
+
varData = self.MultiVarData[major]
|
| 228 |
+
for regionIdx in varData.VarRegionIndex:
|
| 229 |
+
region = self.SparseVarRegionList.Region[regionIdx]
|
| 230 |
+
support = region.get_support(fvarAxes)
|
| 231 |
+
supports.append(support)
|
| 232 |
+
return supports
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
ot.MultiVarStore.get_supports = MultiVarStore_get_supports
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def VARC_collect_varidxes(self, varidxes):
|
| 239 |
+
for glyph in self.VarCompositeGlyphs.VarCompositeGlyph:
|
| 240 |
+
for component in glyph.components:
|
| 241 |
+
varidxes.add(component.axisValuesVarIndex)
|
| 242 |
+
varidxes.add(component.transformVarIndex)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def VARC_remap_varidxes(self, varidxes_map):
|
| 246 |
+
for glyph in self.VarCompositeGlyphs.VarCompositeGlyph:
|
| 247 |
+
for component in glyph.components:
|
| 248 |
+
component.axisValuesVarIndex = varidxes_map[component.axisValuesVarIndex]
|
| 249 |
+
component.transformVarIndex = varidxes_map[component.transformVarIndex]
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
ot.VARC.collect_varidxes = VARC_collect_varidxes
|
| 253 |
+
ot.VARC.remap_varidxes = VARC_remap_varidxes
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/mutator.py
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ate a variation font. Run, eg:
|
| 3 |
+
|
| 4 |
+
.. code-block:: sh
|
| 5 |
+
|
| 6 |
+
$ fonttools varLib.mutator ./NotoSansArabic-VF.ttf wght=140 wdth=85
|
| 7 |
+
|
| 8 |
+
.. warning::
|
| 9 |
+
``fontTools.varLib.mutator`` is deprecated in favor of :mod:`fontTools.varLib.instancer`
|
| 10 |
+
which provides equivalent full instancing and also supports partial instancing.
|
| 11 |
+
Please migrate CLI usage to ``fonttools varLib.instancer`` and API usage to
|
| 12 |
+
:func:`fontTools.varLib.instancer.instantiateVariableFont`.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
from fontTools.misc.fixedTools import floatToFixedToFloat, floatToFixed
|
| 16 |
+
from fontTools.misc.loggingTools import deprecateFunction
|
| 17 |
+
from fontTools.misc.roundTools import otRound
|
| 18 |
+
from fontTools.pens.boundsPen import BoundsPen
|
| 19 |
+
from fontTools.ttLib import TTFont, newTable
|
| 20 |
+
from fontTools.ttLib.tables import ttProgram
|
| 21 |
+
from fontTools.ttLib.tables._g_l_y_f import (
|
| 22 |
+
GlyphCoordinates,
|
| 23 |
+
flagOverlapSimple,
|
| 24 |
+
OVERLAP_COMPOUND,
|
| 25 |
+
)
|
| 26 |
+
from fontTools.varLib.models import (
|
| 27 |
+
supportScalar,
|
| 28 |
+
normalizeLocation,
|
| 29 |
+
piecewiseLinearMap,
|
| 30 |
+
)
|
| 31 |
+
from fontTools.varLib.merger import MutatorMerger
|
| 32 |
+
from fontTools.varLib.varStore import VarStoreInstancer
|
| 33 |
+
from fontTools.varLib.mvar import MVAR_ENTRIES
|
| 34 |
+
from fontTools.varLib.iup import iup_delta
|
| 35 |
+
import fontTools.subset.cff
|
| 36 |
+
import os.path
|
| 37 |
+
import logging
|
| 38 |
+
from io import BytesIO
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
log = logging.getLogger("fontTools.varlib.mutator")
|
| 42 |
+
|
| 43 |
+
# map 'wdth' axis (1..200) to OS/2.usWidthClass (1..9), rounding to closest
|
| 44 |
+
OS2_WIDTH_CLASS_VALUES = {}
|
| 45 |
+
percents = [50.0, 62.5, 75.0, 87.5, 100.0, 112.5, 125.0, 150.0, 200.0]
|
| 46 |
+
for i, (prev, curr) in enumerate(zip(percents[:-1], percents[1:]), start=1):
|
| 47 |
+
half = (prev + curr) / 2
|
| 48 |
+
OS2_WIDTH_CLASS_VALUES[half] = i
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def interpolate_cff2_PrivateDict(topDict, interpolateFromDeltas):
|
| 52 |
+
pd_blend_lists = (
|
| 53 |
+
"BlueValues",
|
| 54 |
+
"OtherBlues",
|
| 55 |
+
"FamilyBlues",
|
| 56 |
+
"FamilyOtherBlues",
|
| 57 |
+
"StemSnapH",
|
| 58 |
+
"StemSnapV",
|
| 59 |
+
)
|
| 60 |
+
pd_blend_values = ("BlueScale", "BlueShift", "BlueFuzz", "StdHW", "StdVW")
|
| 61 |
+
for fontDict in topDict.FDArray:
|
| 62 |
+
pd = fontDict.Private
|
| 63 |
+
vsindex = pd.vsindex if (hasattr(pd, "vsindex")) else 0
|
| 64 |
+
for key, value in pd.rawDict.items():
|
| 65 |
+
if (key in pd_blend_values) and isinstance(value, list):
|
| 66 |
+
delta = interpolateFromDeltas(vsindex, value[1:])
|
| 67 |
+
pd.rawDict[key] = otRound(value[0] + delta)
|
| 68 |
+
elif (key in pd_blend_lists) and isinstance(value[0], list):
|
| 69 |
+
"""If any argument in a BlueValues list is a blend list,
|
| 70 |
+
then they all are. The first value of each list is an
|
| 71 |
+
absolute value. The delta tuples are calculated from
|
| 72 |
+
relative master values, hence we need to append all the
|
| 73 |
+
deltas to date to each successive absolute value."""
|
| 74 |
+
delta = 0
|
| 75 |
+
for i, val_list in enumerate(value):
|
| 76 |
+
delta += otRound(interpolateFromDeltas(vsindex, val_list[1:]))
|
| 77 |
+
value[i] = val_list[0] + delta
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def interpolate_cff2_charstrings(topDict, interpolateFromDeltas, glyphOrder):
|
| 81 |
+
charstrings = topDict.CharStrings
|
| 82 |
+
for gname in glyphOrder:
|
| 83 |
+
# Interpolate charstring
|
| 84 |
+
# e.g replace blend op args with regular args,
|
| 85 |
+
# and use and discard vsindex op.
|
| 86 |
+
charstring = charstrings[gname]
|
| 87 |
+
new_program = []
|
| 88 |
+
vsindex = 0
|
| 89 |
+
last_i = 0
|
| 90 |
+
for i, token in enumerate(charstring.program):
|
| 91 |
+
if token == "vsindex":
|
| 92 |
+
vsindex = charstring.program[i - 1]
|
| 93 |
+
if last_i != 0:
|
| 94 |
+
new_program.extend(charstring.program[last_i : i - 1])
|
| 95 |
+
last_i = i + 1
|
| 96 |
+
elif token == "blend":
|
| 97 |
+
num_regions = charstring.getNumRegions(vsindex)
|
| 98 |
+
numMasters = 1 + num_regions
|
| 99 |
+
num_args = charstring.program[i - 1]
|
| 100 |
+
# The program list starting at program[i] is now:
|
| 101 |
+
# ..args for following operations
|
| 102 |
+
# num_args values from the default font
|
| 103 |
+
# num_args tuples, each with numMasters-1 delta values
|
| 104 |
+
# num_blend_args
|
| 105 |
+
# 'blend'
|
| 106 |
+
argi = i - (num_args * numMasters + 1)
|
| 107 |
+
end_args = tuplei = argi + num_args
|
| 108 |
+
while argi < end_args:
|
| 109 |
+
next_ti = tuplei + num_regions
|
| 110 |
+
deltas = charstring.program[tuplei:next_ti]
|
| 111 |
+
delta = interpolateFromDeltas(vsindex, deltas)
|
| 112 |
+
charstring.program[argi] += otRound(delta)
|
| 113 |
+
tuplei = next_ti
|
| 114 |
+
argi += 1
|
| 115 |
+
new_program.extend(charstring.program[last_i:end_args])
|
| 116 |
+
last_i = i + 1
|
| 117 |
+
if last_i != 0:
|
| 118 |
+
new_program.extend(charstring.program[last_i:])
|
| 119 |
+
charstring.program = new_program
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def interpolate_cff2_metrics(varfont, topDict, glyphOrder, loc):
|
| 123 |
+
"""Unlike TrueType glyphs, neither advance width nor bounding box
|
| 124 |
+
info is stored in a CFF2 charstring. The width data exists only in
|
| 125 |
+
the hmtx and HVAR tables. Since LSB data cannot be interpolated
|
| 126 |
+
reliably from the master LSB values in the hmtx table, we traverse
|
| 127 |
+
the charstring to determine the actual bound box."""
|
| 128 |
+
|
| 129 |
+
charstrings = topDict.CharStrings
|
| 130 |
+
boundsPen = BoundsPen(glyphOrder)
|
| 131 |
+
hmtx = varfont["hmtx"]
|
| 132 |
+
hvar_table = None
|
| 133 |
+
if "HVAR" in varfont:
|
| 134 |
+
hvar_table = varfont["HVAR"].table
|
| 135 |
+
fvar = varfont["fvar"]
|
| 136 |
+
varStoreInstancer = VarStoreInstancer(hvar_table.VarStore, fvar.axes, loc)
|
| 137 |
+
|
| 138 |
+
for gid, gname in enumerate(glyphOrder):
|
| 139 |
+
entry = list(hmtx[gname])
|
| 140 |
+
# get width delta.
|
| 141 |
+
if hvar_table:
|
| 142 |
+
if hvar_table.AdvWidthMap:
|
| 143 |
+
width_idx = hvar_table.AdvWidthMap.mapping[gname]
|
| 144 |
+
else:
|
| 145 |
+
width_idx = gid
|
| 146 |
+
width_delta = otRound(varStoreInstancer[width_idx])
|
| 147 |
+
else:
|
| 148 |
+
width_delta = 0
|
| 149 |
+
|
| 150 |
+
# get LSB.
|
| 151 |
+
boundsPen.init()
|
| 152 |
+
charstring = charstrings[gname]
|
| 153 |
+
charstring.draw(boundsPen)
|
| 154 |
+
if boundsPen.bounds is None:
|
| 155 |
+
# Happens with non-marking glyphs
|
| 156 |
+
lsb_delta = 0
|
| 157 |
+
else:
|
| 158 |
+
lsb = otRound(boundsPen.bounds[0])
|
| 159 |
+
lsb_delta = entry[1] - lsb
|
| 160 |
+
|
| 161 |
+
if lsb_delta or width_delta:
|
| 162 |
+
if width_delta:
|
| 163 |
+
entry[0] = max(0, entry[0] + width_delta)
|
| 164 |
+
if lsb_delta:
|
| 165 |
+
entry[1] = lsb
|
| 166 |
+
hmtx[gname] = tuple(entry)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
@deprecateFunction(
|
| 170 |
+
"use fontTools.varLib.instancer.instantiateVariableFont instead "
|
| 171 |
+
"for either full or partial instancing",
|
| 172 |
+
)
|
| 173 |
+
def instantiateVariableFont(varfont, location, inplace=False, overlap=True):
|
| 174 |
+
"""Generate a static instance from a variable TTFont and a dictionary
|
| 175 |
+
defining the desired location along the variable font's axes.
|
| 176 |
+
The location values must be specified as user-space coordinates, e.g.:
|
| 177 |
+
|
| 178 |
+
.. code-block::
|
| 179 |
+
|
| 180 |
+
{'wght': 400, 'wdth': 100}
|
| 181 |
+
|
| 182 |
+
By default, a new TTFont object is returned. If ``inplace`` is True, the
|
| 183 |
+
input varfont is modified and reduced to a static font.
|
| 184 |
+
|
| 185 |
+
When the overlap parameter is defined as True,
|
| 186 |
+
OVERLAP_SIMPLE and OVERLAP_COMPOUND bits are set to 1. See
|
| 187 |
+
https://docs.microsoft.com/en-us/typography/opentype/spec/glyf
|
| 188 |
+
"""
|
| 189 |
+
if not inplace:
|
| 190 |
+
# make a copy to leave input varfont unmodified
|
| 191 |
+
stream = BytesIO()
|
| 192 |
+
varfont.save(stream)
|
| 193 |
+
stream.seek(0)
|
| 194 |
+
varfont = TTFont(stream)
|
| 195 |
+
|
| 196 |
+
fvar = varfont["fvar"]
|
| 197 |
+
axes = {a.axisTag: (a.minValue, a.defaultValue, a.maxValue) for a in fvar.axes}
|
| 198 |
+
loc = normalizeLocation(location, axes)
|
| 199 |
+
if "avar" in varfont:
|
| 200 |
+
maps = varfont["avar"].segments
|
| 201 |
+
loc = {k: piecewiseLinearMap(v, maps[k]) for k, v in loc.items()}
|
| 202 |
+
# Quantize to F2Dot14, to avoid surprise interpolations.
|
| 203 |
+
loc = {k: floatToFixedToFloat(v, 14) for k, v in loc.items()}
|
| 204 |
+
# Location is normalized now
|
| 205 |
+
log.info("Normalized location: %s", loc)
|
| 206 |
+
|
| 207 |
+
if "gvar" in varfont:
|
| 208 |
+
log.info("Mutating glyf/gvar tables")
|
| 209 |
+
gvar = varfont["gvar"]
|
| 210 |
+
glyf = varfont["glyf"]
|
| 211 |
+
hMetrics = varfont["hmtx"].metrics
|
| 212 |
+
vMetrics = getattr(varfont.get("vmtx"), "metrics", None)
|
| 213 |
+
# get list of glyph names in gvar sorted by component depth
|
| 214 |
+
glyphnames = sorted(
|
| 215 |
+
gvar.variations.keys(),
|
| 216 |
+
key=lambda name: (
|
| 217 |
+
(
|
| 218 |
+
glyf[name].getCompositeMaxpValues(glyf).maxComponentDepth
|
| 219 |
+
if glyf[name].isComposite()
|
| 220 |
+
else 0
|
| 221 |
+
),
|
| 222 |
+
name,
|
| 223 |
+
),
|
| 224 |
+
)
|
| 225 |
+
for glyphname in glyphnames:
|
| 226 |
+
variations = gvar.variations[glyphname]
|
| 227 |
+
coordinates, _ = glyf._getCoordinatesAndControls(
|
| 228 |
+
glyphname, hMetrics, vMetrics
|
| 229 |
+
)
|
| 230 |
+
origCoords, endPts = None, None
|
| 231 |
+
for var in variations:
|
| 232 |
+
scalar = supportScalar(loc, var.axes)
|
| 233 |
+
if not scalar:
|
| 234 |
+
continue
|
| 235 |
+
delta = var.coordinates
|
| 236 |
+
if None in delta:
|
| 237 |
+
if origCoords is None:
|
| 238 |
+
origCoords, g = glyf._getCoordinatesAndControls(
|
| 239 |
+
glyphname, hMetrics, vMetrics
|
| 240 |
+
)
|
| 241 |
+
delta = iup_delta(delta, origCoords, g.endPts)
|
| 242 |
+
coordinates += GlyphCoordinates(delta) * scalar
|
| 243 |
+
glyf._setCoordinates(glyphname, coordinates, hMetrics, vMetrics)
|
| 244 |
+
else:
|
| 245 |
+
glyf = None
|
| 246 |
+
|
| 247 |
+
if "DSIG" in varfont:
|
| 248 |
+
del varfont["DSIG"]
|
| 249 |
+
|
| 250 |
+
if "cvar" in varfont:
|
| 251 |
+
log.info("Mutating cvt/cvar tables")
|
| 252 |
+
cvar = varfont["cvar"]
|
| 253 |
+
cvt = varfont["cvt "]
|
| 254 |
+
deltas = {}
|
| 255 |
+
for var in cvar.variations:
|
| 256 |
+
scalar = supportScalar(loc, var.axes)
|
| 257 |
+
if not scalar:
|
| 258 |
+
continue
|
| 259 |
+
for i, c in enumerate(var.coordinates):
|
| 260 |
+
if c is not None:
|
| 261 |
+
deltas[i] = deltas.get(i, 0) + scalar * c
|
| 262 |
+
for i, delta in deltas.items():
|
| 263 |
+
cvt[i] += otRound(delta)
|
| 264 |
+
|
| 265 |
+
if "CFF2" in varfont:
|
| 266 |
+
log.info("Mutating CFF2 table")
|
| 267 |
+
glyphOrder = varfont.getGlyphOrder()
|
| 268 |
+
CFF2 = varfont["CFF2"]
|
| 269 |
+
topDict = CFF2.cff.topDictIndex[0]
|
| 270 |
+
vsInstancer = VarStoreInstancer(topDict.VarStore.otVarStore, fvar.axes, loc)
|
| 271 |
+
interpolateFromDeltas = vsInstancer.interpolateFromDeltas
|
| 272 |
+
interpolate_cff2_PrivateDict(topDict, interpolateFromDeltas)
|
| 273 |
+
CFF2.desubroutinize()
|
| 274 |
+
interpolate_cff2_charstrings(topDict, interpolateFromDeltas, glyphOrder)
|
| 275 |
+
interpolate_cff2_metrics(varfont, topDict, glyphOrder, loc)
|
| 276 |
+
del topDict.rawDict["VarStore"]
|
| 277 |
+
del topDict.VarStore
|
| 278 |
+
|
| 279 |
+
if "MVAR" in varfont:
|
| 280 |
+
log.info("Mutating MVAR table")
|
| 281 |
+
mvar = varfont["MVAR"].table
|
| 282 |
+
varStoreInstancer = VarStoreInstancer(mvar.VarStore, fvar.axes, loc)
|
| 283 |
+
records = mvar.ValueRecord
|
| 284 |
+
for rec in records:
|
| 285 |
+
mvarTag = rec.ValueTag
|
| 286 |
+
if mvarTag not in MVAR_ENTRIES:
|
| 287 |
+
continue
|
| 288 |
+
tableTag, itemName = MVAR_ENTRIES[mvarTag]
|
| 289 |
+
delta = otRound(varStoreInstancer[rec.VarIdx])
|
| 290 |
+
if not delta:
|
| 291 |
+
continue
|
| 292 |
+
setattr(
|
| 293 |
+
varfont[tableTag],
|
| 294 |
+
itemName,
|
| 295 |
+
getattr(varfont[tableTag], itemName) + delta,
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
log.info("Mutating FeatureVariations")
|
| 299 |
+
for tableTag in "GSUB", "GPOS":
|
| 300 |
+
if not tableTag in varfont:
|
| 301 |
+
continue
|
| 302 |
+
table = varfont[tableTag].table
|
| 303 |
+
if not getattr(table, "FeatureVariations", None):
|
| 304 |
+
continue
|
| 305 |
+
variations = table.FeatureVariations
|
| 306 |
+
for record in variations.FeatureVariationRecord:
|
| 307 |
+
applies = True
|
| 308 |
+
for condition in record.ConditionSet.ConditionTable:
|
| 309 |
+
if condition.Format == 1:
|
| 310 |
+
axisIdx = condition.AxisIndex
|
| 311 |
+
axisTag = fvar.axes[axisIdx].axisTag
|
| 312 |
+
Min = condition.FilterRangeMinValue
|
| 313 |
+
Max = condition.FilterRangeMaxValue
|
| 314 |
+
v = loc[axisTag]
|
| 315 |
+
if not (Min <= v <= Max):
|
| 316 |
+
applies = False
|
| 317 |
+
else:
|
| 318 |
+
applies = False
|
| 319 |
+
if not applies:
|
| 320 |
+
break
|
| 321 |
+
|
| 322 |
+
if applies:
|
| 323 |
+
assert record.FeatureTableSubstitution.Version == 0x00010000
|
| 324 |
+
for rec in record.FeatureTableSubstitution.SubstitutionRecord:
|
| 325 |
+
table.FeatureList.FeatureRecord[rec.FeatureIndex].Feature = (
|
| 326 |
+
rec.Feature
|
| 327 |
+
)
|
| 328 |
+
break
|
| 329 |
+
del table.FeatureVariations
|
| 330 |
+
|
| 331 |
+
if "GDEF" in varfont and varfont["GDEF"].table.Version >= 0x00010003:
|
| 332 |
+
log.info("Mutating GDEF/GPOS/GSUB tables")
|
| 333 |
+
gdef = varfont["GDEF"].table
|
| 334 |
+
instancer = VarStoreInstancer(gdef.VarStore, fvar.axes, loc)
|
| 335 |
+
|
| 336 |
+
merger = MutatorMerger(varfont, instancer)
|
| 337 |
+
merger.mergeTables(varfont, [varfont], ["GDEF", "GPOS"])
|
| 338 |
+
|
| 339 |
+
# Downgrade GDEF.
|
| 340 |
+
del gdef.VarStore
|
| 341 |
+
gdef.Version = 0x00010002
|
| 342 |
+
if gdef.MarkGlyphSetsDef is None:
|
| 343 |
+
del gdef.MarkGlyphSetsDef
|
| 344 |
+
gdef.Version = 0x00010000
|
| 345 |
+
|
| 346 |
+
if not (
|
| 347 |
+
gdef.LigCaretList
|
| 348 |
+
or gdef.MarkAttachClassDef
|
| 349 |
+
or gdef.GlyphClassDef
|
| 350 |
+
or gdef.AttachList
|
| 351 |
+
or (gdef.Version >= 0x00010002 and gdef.MarkGlyphSetsDef)
|
| 352 |
+
):
|
| 353 |
+
del varfont["GDEF"]
|
| 354 |
+
|
| 355 |
+
addidef = False
|
| 356 |
+
if glyf:
|
| 357 |
+
for glyph in glyf.glyphs.values():
|
| 358 |
+
if hasattr(glyph, "program"):
|
| 359 |
+
instructions = glyph.program.getAssembly()
|
| 360 |
+
# If GETVARIATION opcode is used in bytecode of any glyph add IDEF
|
| 361 |
+
addidef = any(op.startswith("GETVARIATION") for op in instructions)
|
| 362 |
+
if addidef:
|
| 363 |
+
break
|
| 364 |
+
if overlap:
|
| 365 |
+
for glyph_name in glyf.keys():
|
| 366 |
+
glyph = glyf[glyph_name]
|
| 367 |
+
# Set OVERLAP_COMPOUND bit for compound glyphs
|
| 368 |
+
if glyph.isComposite():
|
| 369 |
+
glyph.components[0].flags |= OVERLAP_COMPOUND
|
| 370 |
+
# Set OVERLAP_SIMPLE bit for simple glyphs
|
| 371 |
+
elif glyph.numberOfContours > 0:
|
| 372 |
+
glyph.flags[0] |= flagOverlapSimple
|
| 373 |
+
if addidef:
|
| 374 |
+
log.info("Adding IDEF to fpgm table for GETVARIATION opcode")
|
| 375 |
+
asm = []
|
| 376 |
+
if "fpgm" in varfont:
|
| 377 |
+
fpgm = varfont["fpgm"]
|
| 378 |
+
asm = fpgm.program.getAssembly()
|
| 379 |
+
else:
|
| 380 |
+
fpgm = newTable("fpgm")
|
| 381 |
+
fpgm.program = ttProgram.Program()
|
| 382 |
+
varfont["fpgm"] = fpgm
|
| 383 |
+
asm.append("PUSHB[000] 145")
|
| 384 |
+
asm.append("IDEF[ ]")
|
| 385 |
+
args = [str(len(loc))]
|
| 386 |
+
for a in fvar.axes:
|
| 387 |
+
args.append(str(floatToFixed(loc[a.axisTag], 14)))
|
| 388 |
+
asm.append("NPUSHW[ ] " + " ".join(args))
|
| 389 |
+
asm.append("ENDF[ ]")
|
| 390 |
+
fpgm.program.fromAssembly(asm)
|
| 391 |
+
|
| 392 |
+
# Change maxp attributes as IDEF is added
|
| 393 |
+
if "maxp" in varfont:
|
| 394 |
+
maxp = varfont["maxp"]
|
| 395 |
+
setattr(
|
| 396 |
+
maxp, "maxInstructionDefs", 1 + getattr(maxp, "maxInstructionDefs", 0)
|
| 397 |
+
)
|
| 398 |
+
setattr(
|
| 399 |
+
maxp,
|
| 400 |
+
"maxStackElements",
|
| 401 |
+
max(len(loc), getattr(maxp, "maxStackElements", 0)),
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
if "name" in varfont:
|
| 405 |
+
log.info("Pruning name table")
|
| 406 |
+
exclude = {a.axisNameID for a in fvar.axes}
|
| 407 |
+
for i in fvar.instances:
|
| 408 |
+
exclude.add(i.subfamilyNameID)
|
| 409 |
+
exclude.add(i.postscriptNameID)
|
| 410 |
+
if "ltag" in varfont:
|
| 411 |
+
# Drop the whole 'ltag' table if all its language tags are referenced by
|
| 412 |
+
# name records to be pruned.
|
| 413 |
+
# TODO: prune unused ltag tags and re-enumerate langIDs accordingly
|
| 414 |
+
excludedUnicodeLangIDs = [
|
| 415 |
+
n.langID
|
| 416 |
+
for n in varfont["name"].names
|
| 417 |
+
if n.nameID in exclude and n.platformID == 0 and n.langID != 0xFFFF
|
| 418 |
+
]
|
| 419 |
+
if set(excludedUnicodeLangIDs) == set(range(len((varfont["ltag"].tags)))):
|
| 420 |
+
del varfont["ltag"]
|
| 421 |
+
varfont["name"].names[:] = [
|
| 422 |
+
n
|
| 423 |
+
for n in varfont["name"].names
|
| 424 |
+
if n.nameID < 256 or n.nameID not in exclude
|
| 425 |
+
]
|
| 426 |
+
|
| 427 |
+
if "wght" in location and "OS/2" in varfont:
|
| 428 |
+
varfont["OS/2"].usWeightClass = otRound(max(1, min(location["wght"], 1000)))
|
| 429 |
+
if "wdth" in location:
|
| 430 |
+
wdth = location["wdth"]
|
| 431 |
+
for percent, widthClass in sorted(OS2_WIDTH_CLASS_VALUES.items()):
|
| 432 |
+
if wdth < percent:
|
| 433 |
+
varfont["OS/2"].usWidthClass = widthClass
|
| 434 |
+
break
|
| 435 |
+
else:
|
| 436 |
+
varfont["OS/2"].usWidthClass = 9
|
| 437 |
+
if "slnt" in location and "post" in varfont:
|
| 438 |
+
varfont["post"].italicAngle = max(-90, min(location["slnt"], 90))
|
| 439 |
+
|
| 440 |
+
log.info("Removing variable tables")
|
| 441 |
+
for tag in ("avar", "cvar", "fvar", "gvar", "HVAR", "MVAR", "VVAR", "STAT"):
|
| 442 |
+
if tag in varfont:
|
| 443 |
+
del varfont[tag]
|
| 444 |
+
|
| 445 |
+
return varfont
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
def main(args=None):
|
| 449 |
+
"""Instantiate a variation font"""
|
| 450 |
+
from fontTools import configLogger
|
| 451 |
+
import argparse
|
| 452 |
+
|
| 453 |
+
parser = argparse.ArgumentParser(
|
| 454 |
+
"fonttools varLib.mutator", description="Instantiate a variable font"
|
| 455 |
+
)
|
| 456 |
+
parser.add_argument("input", metavar="INPUT.ttf", help="Input variable TTF file.")
|
| 457 |
+
parser.add_argument(
|
| 458 |
+
"locargs",
|
| 459 |
+
metavar="AXIS=LOC",
|
| 460 |
+
nargs="*",
|
| 461 |
+
help="List of space separated locations. A location consist in "
|
| 462 |
+
"the name of a variation axis, followed by '=' and a number. E.g.: "
|
| 463 |
+
" wght=700 wdth=80. The default is the location of the base master.",
|
| 464 |
+
)
|
| 465 |
+
parser.add_argument(
|
| 466 |
+
"-o",
|
| 467 |
+
"--output",
|
| 468 |
+
metavar="OUTPUT.ttf",
|
| 469 |
+
default=None,
|
| 470 |
+
help="Output instance TTF file (default: INPUT-instance.ttf).",
|
| 471 |
+
)
|
| 472 |
+
parser.add_argument(
|
| 473 |
+
"--no-recalc-timestamp",
|
| 474 |
+
dest="recalc_timestamp",
|
| 475 |
+
action="store_false",
|
| 476 |
+
help="Don't set the output font's timestamp to the current time.",
|
| 477 |
+
)
|
| 478 |
+
logging_group = parser.add_mutually_exclusive_group(required=False)
|
| 479 |
+
logging_group.add_argument(
|
| 480 |
+
"-v", "--verbose", action="store_true", help="Run more verbosely."
|
| 481 |
+
)
|
| 482 |
+
logging_group.add_argument(
|
| 483 |
+
"-q", "--quiet", action="store_true", help="Turn verbosity off."
|
| 484 |
+
)
|
| 485 |
+
parser.add_argument(
|
| 486 |
+
"--no-overlap",
|
| 487 |
+
dest="overlap",
|
| 488 |
+
action="store_false",
|
| 489 |
+
help="Don't set OVERLAP_SIMPLE/OVERLAP_COMPOUND glyf flags.",
|
| 490 |
+
)
|
| 491 |
+
options = parser.parse_args(args)
|
| 492 |
+
|
| 493 |
+
varfilename = options.input
|
| 494 |
+
outfile = (
|
| 495 |
+
os.path.splitext(varfilename)[0] + "-instance.ttf"
|
| 496 |
+
if not options.output
|
| 497 |
+
else options.output
|
| 498 |
+
)
|
| 499 |
+
configLogger(
|
| 500 |
+
level=("DEBUG" if options.verbose else "ERROR" if options.quiet else "INFO")
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
loc = {}
|
| 504 |
+
for arg in options.locargs:
|
| 505 |
+
try:
|
| 506 |
+
tag, val = arg.split("=")
|
| 507 |
+
assert len(tag) <= 4
|
| 508 |
+
loc[tag.ljust(4)] = float(val)
|
| 509 |
+
except (ValueError, AssertionError):
|
| 510 |
+
parser.error("invalid location argument format: %r" % arg)
|
| 511 |
+
log.info("Location: %s", loc)
|
| 512 |
+
|
| 513 |
+
log.info("Loading variable font")
|
| 514 |
+
varfont = TTFont(varfilename, recalcTimestamp=options.recalc_timestamp)
|
| 515 |
+
|
| 516 |
+
instantiateVariableFont(varfont, loc, inplace=True, overlap=options.overlap)
|
| 517 |
+
|
| 518 |
+
log.info("Saving instance font %s", outfile)
|
| 519 |
+
varfont.save(outfile)
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
if __name__ == "__main__":
|
| 523 |
+
import sys
|
| 524 |
+
|
| 525 |
+
if len(sys.argv) > 1:
|
| 526 |
+
sys.exit(main())
|
| 527 |
+
import doctest
|
| 528 |
+
|
| 529 |
+
sys.exit(doctest.testmod().failed)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/mvar.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MVAR_ENTRIES = {
|
| 2 |
+
"hasc": ("OS/2", "sTypoAscender"), # horizontal ascender
|
| 3 |
+
"hdsc": ("OS/2", "sTypoDescender"), # horizontal descender
|
| 4 |
+
"hlgp": ("OS/2", "sTypoLineGap"), # horizontal line gap
|
| 5 |
+
"hcla": ("OS/2", "usWinAscent"), # horizontal clipping ascent
|
| 6 |
+
"hcld": ("OS/2", "usWinDescent"), # horizontal clipping descent
|
| 7 |
+
"vasc": ("vhea", "ascent"), # vertical ascender
|
| 8 |
+
"vdsc": ("vhea", "descent"), # vertical descender
|
| 9 |
+
"vlgp": ("vhea", "lineGap"), # vertical line gap
|
| 10 |
+
"hcrs": ("hhea", "caretSlopeRise"), # horizontal caret rise
|
| 11 |
+
"hcrn": ("hhea", "caretSlopeRun"), # horizontal caret run
|
| 12 |
+
"hcof": ("hhea", "caretOffset"), # horizontal caret offset
|
| 13 |
+
"vcrs": ("vhea", "caretSlopeRise"), # vertical caret rise
|
| 14 |
+
"vcrn": ("vhea", "caretSlopeRun"), # vertical caret run
|
| 15 |
+
"vcof": ("vhea", "caretOffset"), # vertical caret offset
|
| 16 |
+
"xhgt": ("OS/2", "sxHeight"), # x height
|
| 17 |
+
"cpht": ("OS/2", "sCapHeight"), # cap height
|
| 18 |
+
"sbxs": ("OS/2", "ySubscriptXSize"), # subscript em x size
|
| 19 |
+
"sbys": ("OS/2", "ySubscriptYSize"), # subscript em y size
|
| 20 |
+
"sbxo": ("OS/2", "ySubscriptXOffset"), # subscript em x offset
|
| 21 |
+
"sbyo": ("OS/2", "ySubscriptYOffset"), # subscript em y offset
|
| 22 |
+
"spxs": ("OS/2", "ySuperscriptXSize"), # superscript em x size
|
| 23 |
+
"spys": ("OS/2", "ySuperscriptYSize"), # superscript em y size
|
| 24 |
+
"spxo": ("OS/2", "ySuperscriptXOffset"), # superscript em x offset
|
| 25 |
+
"spyo": ("OS/2", "ySuperscriptYOffset"), # superscript em y offset
|
| 26 |
+
"strs": ("OS/2", "yStrikeoutSize"), # strikeout size
|
| 27 |
+
"stro": ("OS/2", "yStrikeoutPosition"), # strikeout offset
|
| 28 |
+
"unds": ("post", "underlineThickness"), # underline size
|
| 29 |
+
"undo": ("post", "underlinePosition"), # underline offset
|
| 30 |
+
#'gsp0': ('gasp', 'gaspRange[0].rangeMaxPPEM'), # gaspRange[0]
|
| 31 |
+
#'gsp1': ('gasp', 'gaspRange[1].rangeMaxPPEM'), # gaspRange[1]
|
| 32 |
+
#'gsp2': ('gasp', 'gaspRange[2].rangeMaxPPEM'), # gaspRange[2]
|
| 33 |
+
#'gsp3': ('gasp', 'gaspRange[3].rangeMaxPPEM'), # gaspRange[3]
|
| 34 |
+
#'gsp4': ('gasp', 'gaspRange[4].rangeMaxPPEM'), # gaspRange[4]
|
| 35 |
+
#'gsp5': ('gasp', 'gaspRange[5].rangeMaxPPEM'), # gaspRange[5]
|
| 36 |
+
#'gsp6': ('gasp', 'gaspRange[6].rangeMaxPPEM'), # gaspRange[6]
|
| 37 |
+
#'gsp7': ('gasp', 'gaspRange[7].rangeMaxPPEM'), # gaspRange[7]
|
| 38 |
+
#'gsp8': ('gasp', 'gaspRange[8].rangeMaxPPEM'), # gaspRange[8]
|
| 39 |
+
#'gsp9': ('gasp', 'gaspRange[9].rangeMaxPPEM'), # gaspRange[9]
|
| 40 |
+
}
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/plot.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Visualize DesignSpaceDocument and resulting VariationModel."""
|
| 2 |
+
|
| 3 |
+
from fontTools.varLib.models import VariationModel, supportScalar
|
| 4 |
+
from fontTools.designspaceLib import DesignSpaceDocument
|
| 5 |
+
from matplotlib import pyplot
|
| 6 |
+
from mpl_toolkits.mplot3d import axes3d
|
| 7 |
+
from itertools import cycle
|
| 8 |
+
import math
|
| 9 |
+
import logging
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
log = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def stops(support, count=10):
|
| 16 |
+
a, b, c = support
|
| 17 |
+
|
| 18 |
+
return (
|
| 19 |
+
[a + (b - a) * i / count for i in range(count)]
|
| 20 |
+
+ [b + (c - b) * i / count for i in range(count)]
|
| 21 |
+
+ [c]
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _plotLocationsDots(locations, axes, subplot, **kwargs):
|
| 26 |
+
for loc, color in zip(locations, cycle(pyplot.cm.Set1.colors)):
|
| 27 |
+
if len(axes) == 1:
|
| 28 |
+
subplot.plot([loc.get(axes[0], 0)], [1.0], "o", color=color, **kwargs)
|
| 29 |
+
elif len(axes) == 2:
|
| 30 |
+
subplot.plot(
|
| 31 |
+
[loc.get(axes[0], 0)],
|
| 32 |
+
[loc.get(axes[1], 0)],
|
| 33 |
+
[1.0],
|
| 34 |
+
"o",
|
| 35 |
+
color=color,
|
| 36 |
+
**kwargs,
|
| 37 |
+
)
|
| 38 |
+
else:
|
| 39 |
+
raise AssertionError(len(axes))
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def plotLocations(locations, fig, names=None, **kwargs):
|
| 43 |
+
n = len(locations)
|
| 44 |
+
cols = math.ceil(n**0.5)
|
| 45 |
+
rows = math.ceil(n / cols)
|
| 46 |
+
|
| 47 |
+
if names is None:
|
| 48 |
+
names = [None] * len(locations)
|
| 49 |
+
|
| 50 |
+
model = VariationModel(locations)
|
| 51 |
+
names = [names[model.reverseMapping[i]] for i in range(len(names))]
|
| 52 |
+
|
| 53 |
+
axes = sorted(locations[0].keys())
|
| 54 |
+
if len(axes) == 1:
|
| 55 |
+
_plotLocations2D(model, axes[0], fig, cols, rows, names=names, **kwargs)
|
| 56 |
+
elif len(axes) == 2:
|
| 57 |
+
_plotLocations3D(model, axes, fig, cols, rows, names=names, **kwargs)
|
| 58 |
+
else:
|
| 59 |
+
raise ValueError("Only 1 or 2 axes are supported")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _plotLocations2D(model, axis, fig, cols, rows, names, **kwargs):
|
| 63 |
+
subplot = fig.add_subplot(111)
|
| 64 |
+
for i, (support, color, name) in enumerate(
|
| 65 |
+
zip(model.supports, cycle(pyplot.cm.Set1.colors), cycle(names))
|
| 66 |
+
):
|
| 67 |
+
if name is not None:
|
| 68 |
+
subplot.set_title(name)
|
| 69 |
+
subplot.set_xlabel(axis)
|
| 70 |
+
pyplot.xlim(-1.0, +1.0)
|
| 71 |
+
|
| 72 |
+
Xs = support.get(axis, (-1.0, 0.0, +1.0))
|
| 73 |
+
X, Y = [], []
|
| 74 |
+
for x in stops(Xs):
|
| 75 |
+
y = supportScalar({axis: x}, support)
|
| 76 |
+
X.append(x)
|
| 77 |
+
Y.append(y)
|
| 78 |
+
subplot.plot(X, Y, color=color, **kwargs)
|
| 79 |
+
|
| 80 |
+
_plotLocationsDots(model.locations, [axis], subplot)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _plotLocations3D(model, axes, fig, rows, cols, names, **kwargs):
|
| 84 |
+
ax1, ax2 = axes
|
| 85 |
+
|
| 86 |
+
axis3D = fig.add_subplot(111, projection="3d")
|
| 87 |
+
for i, (support, color, name) in enumerate(
|
| 88 |
+
zip(model.supports, cycle(pyplot.cm.Set1.colors), cycle(names))
|
| 89 |
+
):
|
| 90 |
+
if name is not None:
|
| 91 |
+
axis3D.set_title(name)
|
| 92 |
+
axis3D.set_xlabel(ax1)
|
| 93 |
+
axis3D.set_ylabel(ax2)
|
| 94 |
+
pyplot.xlim(-1.0, +1.0)
|
| 95 |
+
pyplot.ylim(-1.0, +1.0)
|
| 96 |
+
|
| 97 |
+
Xs = support.get(ax1, (-1.0, 0.0, +1.0))
|
| 98 |
+
Ys = support.get(ax2, (-1.0, 0.0, +1.0))
|
| 99 |
+
for x in stops(Xs):
|
| 100 |
+
X, Y, Z = [], [], []
|
| 101 |
+
for y in Ys:
|
| 102 |
+
z = supportScalar({ax1: x, ax2: y}, support)
|
| 103 |
+
X.append(x)
|
| 104 |
+
Y.append(y)
|
| 105 |
+
Z.append(z)
|
| 106 |
+
axis3D.plot(X, Y, Z, color=color, **kwargs)
|
| 107 |
+
for y in stops(Ys):
|
| 108 |
+
X, Y, Z = [], [], []
|
| 109 |
+
for x in Xs:
|
| 110 |
+
z = supportScalar({ax1: x, ax2: y}, support)
|
| 111 |
+
X.append(x)
|
| 112 |
+
Y.append(y)
|
| 113 |
+
Z.append(z)
|
| 114 |
+
axis3D.plot(X, Y, Z, color=color, **kwargs)
|
| 115 |
+
|
| 116 |
+
_plotLocationsDots(model.locations, [ax1, ax2], axis3D)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def plotDocument(doc, fig, **kwargs):
|
| 120 |
+
doc.normalize()
|
| 121 |
+
locations = [s.location for s in doc.sources]
|
| 122 |
+
names = [s.name for s in doc.sources]
|
| 123 |
+
plotLocations(locations, fig, names, **kwargs)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def _plotModelFromMasters2D(model, masterValues, fig, **kwargs):
|
| 127 |
+
assert len(model.axisOrder) == 1
|
| 128 |
+
axis = model.axisOrder[0]
|
| 129 |
+
|
| 130 |
+
axis_min = min(loc.get(axis, 0) for loc in model.locations)
|
| 131 |
+
axis_max = max(loc.get(axis, 0) for loc in model.locations)
|
| 132 |
+
|
| 133 |
+
import numpy as np
|
| 134 |
+
|
| 135 |
+
X = np.arange(axis_min, axis_max, (axis_max - axis_min) / 100)
|
| 136 |
+
Y = []
|
| 137 |
+
|
| 138 |
+
for x in X:
|
| 139 |
+
loc = {axis: x}
|
| 140 |
+
v = model.interpolateFromMasters(loc, masterValues)
|
| 141 |
+
Y.append(v)
|
| 142 |
+
|
| 143 |
+
subplot = fig.add_subplot(111)
|
| 144 |
+
subplot.plot(X, Y, "-", **kwargs)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def _plotModelFromMasters3D(model, masterValues, fig, **kwargs):
|
| 148 |
+
assert len(model.axisOrder) == 2
|
| 149 |
+
axis1, axis2 = model.axisOrder[0], model.axisOrder[1]
|
| 150 |
+
|
| 151 |
+
axis1_min = min(loc.get(axis1, 0) for loc in model.locations)
|
| 152 |
+
axis1_max = max(loc.get(axis1, 0) for loc in model.locations)
|
| 153 |
+
axis2_min = min(loc.get(axis2, 0) for loc in model.locations)
|
| 154 |
+
axis2_max = max(loc.get(axis2, 0) for loc in model.locations)
|
| 155 |
+
|
| 156 |
+
import numpy as np
|
| 157 |
+
|
| 158 |
+
X = np.arange(axis1_min, axis1_max, (axis1_max - axis1_min) / 100)
|
| 159 |
+
Y = np.arange(axis2_min, axis2_max, (axis2_max - axis2_min) / 100)
|
| 160 |
+
X, Y = np.meshgrid(X, Y)
|
| 161 |
+
Z = []
|
| 162 |
+
|
| 163 |
+
for row_x, row_y in zip(X, Y):
|
| 164 |
+
z_row = []
|
| 165 |
+
Z.append(z_row)
|
| 166 |
+
for x, y in zip(row_x, row_y):
|
| 167 |
+
loc = {axis1: x, axis2: y}
|
| 168 |
+
v = model.interpolateFromMasters(loc, masterValues)
|
| 169 |
+
z_row.append(v)
|
| 170 |
+
Z = np.array(Z)
|
| 171 |
+
|
| 172 |
+
axis3D = fig.add_subplot(111, projection="3d")
|
| 173 |
+
axis3D.plot_surface(X, Y, Z, **kwargs)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def plotModelFromMasters(model, masterValues, fig, **kwargs):
|
| 177 |
+
"""Plot a variation model and set of master values corresponding
|
| 178 |
+
to the locations to the model into a pyplot figure. Variation
|
| 179 |
+
model must have axisOrder of size 1 or 2."""
|
| 180 |
+
if len(model.axisOrder) == 1:
|
| 181 |
+
_plotModelFromMasters2D(model, masterValues, fig, **kwargs)
|
| 182 |
+
elif len(model.axisOrder) == 2:
|
| 183 |
+
_plotModelFromMasters3D(model, masterValues, fig, **kwargs)
|
| 184 |
+
else:
|
| 185 |
+
raise ValueError("Only 1 or 2 axes are supported")
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def main(args=None):
|
| 189 |
+
from fontTools import configLogger
|
| 190 |
+
|
| 191 |
+
if args is None:
|
| 192 |
+
args = sys.argv[1:]
|
| 193 |
+
|
| 194 |
+
# configure the library logger (for >= WARNING)
|
| 195 |
+
configLogger()
|
| 196 |
+
# comment this out to enable debug messages from logger
|
| 197 |
+
# log.setLevel(logging.DEBUG)
|
| 198 |
+
|
| 199 |
+
if len(args) < 1:
|
| 200 |
+
print("usage: fonttools varLib.plot source.designspace", file=sys.stderr)
|
| 201 |
+
print(" or")
|
| 202 |
+
print("usage: fonttools varLib.plot location1 location2 ...", file=sys.stderr)
|
| 203 |
+
print(" or")
|
| 204 |
+
print(
|
| 205 |
+
"usage: fonttools varLib.plot location1=value1 location2=value2 ...",
|
| 206 |
+
file=sys.stderr,
|
| 207 |
+
)
|
| 208 |
+
sys.exit(1)
|
| 209 |
+
|
| 210 |
+
fig = pyplot.figure()
|
| 211 |
+
fig.set_tight_layout(True)
|
| 212 |
+
|
| 213 |
+
if len(args) == 1 and args[0].endswith(".designspace"):
|
| 214 |
+
doc = DesignSpaceDocument()
|
| 215 |
+
doc.read(args[0])
|
| 216 |
+
plotDocument(doc, fig)
|
| 217 |
+
else:
|
| 218 |
+
axes = [chr(c) for c in range(ord("A"), ord("Z") + 1)]
|
| 219 |
+
if "=" not in args[0]:
|
| 220 |
+
locs = [dict(zip(axes, (float(v) for v in s.split(",")))) for s in args]
|
| 221 |
+
plotLocations(locs, fig)
|
| 222 |
+
else:
|
| 223 |
+
locations = []
|
| 224 |
+
masterValues = []
|
| 225 |
+
for arg in args:
|
| 226 |
+
loc, v = arg.split("=")
|
| 227 |
+
locations.append(dict(zip(axes, (float(v) for v in loc.split(",")))))
|
| 228 |
+
masterValues.append(float(v))
|
| 229 |
+
model = VariationModel(locations, axes[: len(locations[0])])
|
| 230 |
+
plotModelFromMasters(model, masterValues, fig)
|
| 231 |
+
|
| 232 |
+
pyplot.show()
|
| 233 |
+
|
| 234 |
+
|
|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|
|
|
| 1 |
+
"""Extra methods for DesignSpaceDocument to generate its STAT table data."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Dict, List, Union
|
| 6 |
+
|
| 7 |
+
import fontTools.otlLib.builder
|
| 8 |
+
from fontTools.designspaceLib import (
|
| 9 |
+
AxisLabelDescriptor,
|
| 10 |
+
DesignSpaceDocument,
|
| 11 |
+
DesignSpaceDocumentError,
|
| 12 |
+
LocationLabelDescriptor,
|
| 13 |
+
)
|
| 14 |
+
from fontTools.designspaceLib.types import Region, getVFUserRegion, locationInRegion
|
| 15 |
+
from fontTools.ttLib import TTFont
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def buildVFStatTable(ttFont: TTFont, doc: DesignSpaceDocument, vfName: str) -> None:
|
| 19 |
+
"""Build the STAT table for the variable font identified by its name in
|
| 20 |
+
the given document.
|
| 21 |
+
|
| 22 |
+
Knowing which variable we're building STAT data for is needed to subset
|
| 23 |
+
the STAT locations to only include what the variable font actually ships.
|
| 24 |
+
|
| 25 |
+
.. versionadded:: 5.0
|
| 26 |
+
|
| 27 |
+
.. seealso::
|
| 28 |
+
- :func:`getStatAxes()`
|
| 29 |
+
- :func:`getStatLocations()`
|
| 30 |
+
- :func:`fontTools.otlLib.builder.buildStatTable()`
|
| 31 |
+
"""
|
| 32 |
+
for vf in doc.getVariableFonts():
|
| 33 |
+
if vf.name == vfName:
|
| 34 |
+
break
|
| 35 |
+
else:
|
| 36 |
+
raise DesignSpaceDocumentError(
|
| 37 |
+
f"Cannot find the variable font by name {vfName}"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
region = getVFUserRegion(doc, vf)
|
| 41 |
+
|
| 42 |
+
# if there are not currently any mac names don't add them here, that's inconsistent
|
| 43 |
+
# https://github.com/fonttools/fonttools/issues/683
|
| 44 |
+
macNames = any(
|
| 45 |
+
nr.platformID == 1 for nr in getattr(ttFont.get("name"), "names", ())
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
return fontTools.otlLib.builder.buildStatTable(
|
| 49 |
+
ttFont,
|
| 50 |
+
getStatAxes(doc, region),
|
| 51 |
+
getStatLocations(doc, region),
|
| 52 |
+
doc.elidedFallbackName if doc.elidedFallbackName is not None else 2,
|
| 53 |
+
macNames=macNames,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def getStatAxes(doc: DesignSpaceDocument, userRegion: Region) -> List[Dict]:
|
| 58 |
+
"""Return a list of axis dicts suitable for use as the ``axes``
|
| 59 |
+
argument to :func:`fontTools.otlLib.builder.buildStatTable()`.
|
| 60 |
+
|
| 61 |
+
.. versionadded:: 5.0
|
| 62 |
+
"""
|
| 63 |
+
# First, get the axis labels with explicit ordering
|
| 64 |
+
# then append the others in the order they appear.
|
| 65 |
+
maxOrdering = max(
|
| 66 |
+
(axis.axisOrdering for axis in doc.axes if axis.axisOrdering is not None),
|
| 67 |
+
default=-1,
|
| 68 |
+
)
|
| 69 |
+
axisOrderings = []
|
| 70 |
+
for axis in doc.axes:
|
| 71 |
+
if axis.axisOrdering is not None:
|
| 72 |
+
axisOrderings.append(axis.axisOrdering)
|
| 73 |
+
else:
|
| 74 |
+
maxOrdering += 1
|
| 75 |
+
axisOrderings.append(maxOrdering)
|
| 76 |
+
return [
|
| 77 |
+
dict(
|
| 78 |
+
tag=axis.tag,
|
| 79 |
+
name={"en": axis.name, **axis.labelNames},
|
| 80 |
+
ordering=ordering,
|
| 81 |
+
values=[
|
| 82 |
+
_axisLabelToStatLocation(label)
|
| 83 |
+
for label in axis.axisLabels
|
| 84 |
+
if locationInRegion({axis.name: label.userValue}, userRegion)
|
| 85 |
+
],
|
| 86 |
+
)
|
| 87 |
+
for axis, ordering in zip(doc.axes, axisOrderings)
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def getStatLocations(doc: DesignSpaceDocument, userRegion: Region) -> List[Dict]:
|
| 92 |
+
"""Return a list of location dicts suitable for use as the ``locations``
|
| 93 |
+
argument to :func:`fontTools.otlLib.builder.buildStatTable()`.
|
| 94 |
+
|
| 95 |
+
.. versionadded:: 5.0
|
| 96 |
+
"""
|
| 97 |
+
axesByName = {axis.name: axis for axis in doc.axes}
|
| 98 |
+
return [
|
| 99 |
+
dict(
|
| 100 |
+
name={"en": label.name, **label.labelNames},
|
| 101 |
+
# Location in the designspace is keyed by axis name
|
| 102 |
+
# Location in buildStatTable by axis tag
|
| 103 |
+
location={
|
| 104 |
+
axesByName[name].tag: value
|
| 105 |
+
for name, value in label.getFullUserLocation(doc).items()
|
| 106 |
+
},
|
| 107 |
+
flags=_labelToFlags(label),
|
| 108 |
+
)
|
| 109 |
+
for label in doc.locationLabels
|
| 110 |
+
if locationInRegion(label.getFullUserLocation(doc), userRegion)
|
| 111 |
+
]
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _labelToFlags(label: Union[AxisLabelDescriptor, LocationLabelDescriptor]) -> int:
|
| 115 |
+
flags = 0
|
| 116 |
+
if label.olderSibling:
|
| 117 |
+
flags |= 1
|
| 118 |
+
if label.elidable:
|
| 119 |
+
flags |= 2
|
| 120 |
+
return flags
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _axisLabelToStatLocation(
|
| 124 |
+
label: AxisLabelDescriptor,
|
| 125 |
+
) -> Dict:
|
| 126 |
+
label_format = label.getFormat()
|
| 127 |
+
name = {"en": label.name, **label.labelNames}
|
| 128 |
+
flags = _labelToFlags(label)
|
| 129 |
+
if label_format == 1:
|
| 130 |
+
return dict(name=name, value=label.userValue, flags=flags)
|
| 131 |
+
if label_format == 3:
|
| 132 |
+
return dict(
|
| 133 |
+
name=name,
|
| 134 |
+
value=label.userValue,
|
| 135 |
+
linkedValue=label.linkedUserValue,
|
| 136 |
+
flags=flags,
|
| 137 |
+
)
|
| 138 |
+
if label_format == 2:
|
| 139 |
+
res = dict(
|
| 140 |
+
name=name,
|
| 141 |
+
nominalValue=label.userValue,
|
| 142 |
+
flags=flags,
|
| 143 |
+
)
|
| 144 |
+
if label.userMinimum is not None:
|
| 145 |
+
res["rangeMinValue"] = label.userMinimum
|
| 146 |
+
if label.userMaximum is not None:
|
| 147 |
+
res["rangeMaxValue"] = label.userMaximum
|
| 148 |
+
return res
|
| 149 |
+
raise NotImplementedError("Unknown STAT label format")
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/varLib/varStore.py
ADDED
|
@@ -0,0 +1,739 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc.roundTools import noRound, otRound
|
| 2 |
+
from fontTools.misc.intTools import bit_count
|
| 3 |
+
from fontTools.ttLib.tables import otTables as ot
|
| 4 |
+
from fontTools.varLib.models import supportScalar
|
| 5 |
+
from fontTools.varLib.builder import (
|
| 6 |
+
buildVarRegionList,
|
| 7 |
+
buildVarStore,
|
| 8 |
+
buildVarRegion,
|
| 9 |
+
buildVarData,
|
| 10 |
+
)
|
| 11 |
+
from functools import partial
|
| 12 |
+
from collections import defaultdict
|
| 13 |
+
from heapq import heappush, heappop
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
NO_VARIATION_INDEX = ot.NO_VARIATION_INDEX
|
| 17 |
+
ot.VarStore.NO_VARIATION_INDEX = NO_VARIATION_INDEX
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _getLocationKey(loc):
|
| 21 |
+
return tuple(sorted(loc.items(), key=lambda kv: kv[0]))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class OnlineVarStoreBuilder(object):
|
| 25 |
+
def __init__(self, axisTags):
|
| 26 |
+
self._axisTags = axisTags
|
| 27 |
+
self._regionMap = {}
|
| 28 |
+
self._regionList = buildVarRegionList([], axisTags)
|
| 29 |
+
self._store = buildVarStore(self._regionList, [])
|
| 30 |
+
self._data = None
|
| 31 |
+
self._model = None
|
| 32 |
+
self._supports = None
|
| 33 |
+
self._varDataIndices = {}
|
| 34 |
+
self._varDataCaches = {}
|
| 35 |
+
self._cache = None
|
| 36 |
+
|
| 37 |
+
def setModel(self, model):
|
| 38 |
+
self.setSupports(model.supports)
|
| 39 |
+
self._model = model
|
| 40 |
+
|
| 41 |
+
def setSupports(self, supports):
|
| 42 |
+
self._model = None
|
| 43 |
+
self._supports = list(supports)
|
| 44 |
+
if self._supports and not self._supports[0]:
|
| 45 |
+
del self._supports[0] # Drop base master support
|
| 46 |
+
self._cache = None
|
| 47 |
+
self._data = None
|
| 48 |
+
|
| 49 |
+
def finish(self, optimize=True):
|
| 50 |
+
self._regionList.RegionCount = len(self._regionList.Region)
|
| 51 |
+
self._store.VarDataCount = len(self._store.VarData)
|
| 52 |
+
for data in self._store.VarData:
|
| 53 |
+
data.ItemCount = len(data.Item)
|
| 54 |
+
data.calculateNumShorts(optimize=optimize)
|
| 55 |
+
return self._store
|
| 56 |
+
|
| 57 |
+
def _add_VarData(self, num_items=1):
|
| 58 |
+
regionMap = self._regionMap
|
| 59 |
+
regionList = self._regionList
|
| 60 |
+
|
| 61 |
+
regions = self._supports
|
| 62 |
+
regionIndices = []
|
| 63 |
+
for region in regions:
|
| 64 |
+
key = _getLocationKey(region)
|
| 65 |
+
idx = regionMap.get(key)
|
| 66 |
+
if idx is None:
|
| 67 |
+
varRegion = buildVarRegion(region, self._axisTags)
|
| 68 |
+
idx = regionMap[key] = len(regionList.Region)
|
| 69 |
+
regionList.Region.append(varRegion)
|
| 70 |
+
regionIndices.append(idx)
|
| 71 |
+
|
| 72 |
+
# Check if we have one already...
|
| 73 |
+
key = tuple(regionIndices)
|
| 74 |
+
varDataIdx = self._varDataIndices.get(key)
|
| 75 |
+
if varDataIdx is not None:
|
| 76 |
+
self._outer = varDataIdx
|
| 77 |
+
self._data = self._store.VarData[varDataIdx]
|
| 78 |
+
self._cache = self._varDataCaches[key]
|
| 79 |
+
if len(self._data.Item) + num_items > 0xFFFF:
|
| 80 |
+
# This is full. Need new one.
|
| 81 |
+
varDataIdx = None
|
| 82 |
+
|
| 83 |
+
if varDataIdx is None:
|
| 84 |
+
self._data = buildVarData(regionIndices, [], optimize=False)
|
| 85 |
+
self._outer = len(self._store.VarData)
|
| 86 |
+
self._store.VarData.append(self._data)
|
| 87 |
+
self._varDataIndices[key] = self._outer
|
| 88 |
+
if key not in self._varDataCaches:
|
| 89 |
+
self._varDataCaches[key] = {}
|
| 90 |
+
self._cache = self._varDataCaches[key]
|
| 91 |
+
|
| 92 |
+
def storeMasters(self, master_values, *, round=round):
|
| 93 |
+
deltas = self._model.getDeltas(master_values, round=round)
|
| 94 |
+
base = deltas.pop(0)
|
| 95 |
+
return base, self.storeDeltas(deltas, round=noRound)
|
| 96 |
+
|
| 97 |
+
def storeMastersMany(self, master_values_list, *, round=round):
|
| 98 |
+
deltas_list = [
|
| 99 |
+
self._model.getDeltas(master_values, round=round)
|
| 100 |
+
for master_values in master_values_list
|
| 101 |
+
]
|
| 102 |
+
base_list = [deltas.pop(0) for deltas in deltas_list]
|
| 103 |
+
return base_list, self.storeDeltasMany(deltas_list, round=noRound)
|
| 104 |
+
|
| 105 |
+
def storeDeltas(self, deltas, *, round=round):
|
| 106 |
+
deltas = [round(d) for d in deltas]
|
| 107 |
+
if len(deltas) == len(self._supports) + 1:
|
| 108 |
+
deltas = tuple(deltas[1:])
|
| 109 |
+
else:
|
| 110 |
+
assert len(deltas) == len(self._supports)
|
| 111 |
+
deltas = tuple(deltas)
|
| 112 |
+
|
| 113 |
+
if not self._data:
|
| 114 |
+
self._add_VarData()
|
| 115 |
+
|
| 116 |
+
varIdx = self._cache.get(deltas)
|
| 117 |
+
if varIdx is not None:
|
| 118 |
+
return varIdx
|
| 119 |
+
|
| 120 |
+
inner = len(self._data.Item)
|
| 121 |
+
if inner == 0xFFFF:
|
| 122 |
+
# Full array. Start new one.
|
| 123 |
+
self._add_VarData()
|
| 124 |
+
return self.storeDeltas(deltas, round=noRound)
|
| 125 |
+
self._data.addItem(deltas, round=noRound)
|
| 126 |
+
|
| 127 |
+
varIdx = (self._outer << 16) + inner
|
| 128 |
+
self._cache[deltas] = varIdx
|
| 129 |
+
return varIdx
|
| 130 |
+
|
| 131 |
+
def storeDeltasMany(self, deltas_list, *, round=round):
|
| 132 |
+
deltas_list = [[round(d) for d in deltas] for deltas in deltas_list]
|
| 133 |
+
deltas_list = tuple(tuple(deltas) for deltas in deltas_list)
|
| 134 |
+
|
| 135 |
+
if not self._data:
|
| 136 |
+
self._add_VarData(len(deltas_list))
|
| 137 |
+
|
| 138 |
+
varIdx = self._cache.get(deltas_list)
|
| 139 |
+
if varIdx is not None:
|
| 140 |
+
return varIdx
|
| 141 |
+
|
| 142 |
+
inner = len(self._data.Item)
|
| 143 |
+
if inner + len(deltas_list) > 0xFFFF:
|
| 144 |
+
# Full array. Start new one.
|
| 145 |
+
self._add_VarData(len(deltas_list))
|
| 146 |
+
return self.storeDeltasMany(deltas_list, round=noRound)
|
| 147 |
+
for i, deltas in enumerate(deltas_list):
|
| 148 |
+
self._data.addItem(deltas, round=noRound)
|
| 149 |
+
|
| 150 |
+
varIdx = (self._outer << 16) + inner + i
|
| 151 |
+
self._cache[deltas] = varIdx
|
| 152 |
+
|
| 153 |
+
varIdx = (self._outer << 16) + inner
|
| 154 |
+
self._cache[deltas_list] = varIdx
|
| 155 |
+
|
| 156 |
+
return varIdx
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def VarData_addItem(self, deltas, *, round=round):
|
| 160 |
+
deltas = [round(d) for d in deltas]
|
| 161 |
+
|
| 162 |
+
countUs = self.VarRegionCount
|
| 163 |
+
countThem = len(deltas)
|
| 164 |
+
if countUs + 1 == countThem:
|
| 165 |
+
deltas = list(deltas[1:])
|
| 166 |
+
else:
|
| 167 |
+
assert countUs == countThem, (countUs, countThem)
|
| 168 |
+
deltas = list(deltas)
|
| 169 |
+
self.Item.append(deltas)
|
| 170 |
+
self.ItemCount = len(self.Item)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
ot.VarData.addItem = VarData_addItem
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def VarRegion_get_support(self, fvar_axes):
|
| 177 |
+
return {
|
| 178 |
+
fvar_axes[i].axisTag: (reg.StartCoord, reg.PeakCoord, reg.EndCoord)
|
| 179 |
+
for i, reg in enumerate(self.VarRegionAxis)
|
| 180 |
+
if reg.PeakCoord != 0
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
ot.VarRegion.get_support = VarRegion_get_support
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def VarStore___bool__(self):
|
| 188 |
+
return bool(self.VarData)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
ot.VarStore.__bool__ = VarStore___bool__
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
class VarStoreInstancer(object):
|
| 195 |
+
def __init__(self, varstore, fvar_axes, location={}):
|
| 196 |
+
self.fvar_axes = fvar_axes
|
| 197 |
+
assert varstore is None or varstore.Format == 1
|
| 198 |
+
self._varData = varstore.VarData if varstore else []
|
| 199 |
+
self._regions = varstore.VarRegionList.Region if varstore else []
|
| 200 |
+
self.setLocation(location)
|
| 201 |
+
|
| 202 |
+
def setLocation(self, location):
|
| 203 |
+
self.location = dict(location)
|
| 204 |
+
self._clearCaches()
|
| 205 |
+
|
| 206 |
+
def _clearCaches(self):
|
| 207 |
+
self._scalars = {}
|
| 208 |
+
|
| 209 |
+
def _getScalar(self, regionIdx):
|
| 210 |
+
scalar = self._scalars.get(regionIdx)
|
| 211 |
+
if scalar is None:
|
| 212 |
+
support = self._regions[regionIdx].get_support(self.fvar_axes)
|
| 213 |
+
scalar = supportScalar(self.location, support)
|
| 214 |
+
self._scalars[regionIdx] = scalar
|
| 215 |
+
return scalar
|
| 216 |
+
|
| 217 |
+
@staticmethod
|
| 218 |
+
def interpolateFromDeltasAndScalars(deltas, scalars):
|
| 219 |
+
delta = 0.0
|
| 220 |
+
for d, s in zip(deltas, scalars):
|
| 221 |
+
if not s:
|
| 222 |
+
continue
|
| 223 |
+
delta += d * s
|
| 224 |
+
return delta
|
| 225 |
+
|
| 226 |
+
def __getitem__(self, varidx):
|
| 227 |
+
major, minor = varidx >> 16, varidx & 0xFFFF
|
| 228 |
+
if varidx == NO_VARIATION_INDEX:
|
| 229 |
+
return 0.0
|
| 230 |
+
varData = self._varData
|
| 231 |
+
scalars = [self._getScalar(ri) for ri in varData[major].VarRegionIndex]
|
| 232 |
+
deltas = varData[major].Item[minor]
|
| 233 |
+
return self.interpolateFromDeltasAndScalars(deltas, scalars)
|
| 234 |
+
|
| 235 |
+
def interpolateFromDeltas(self, varDataIndex, deltas):
|
| 236 |
+
varData = self._varData
|
| 237 |
+
scalars = [self._getScalar(ri) for ri in varData[varDataIndex].VarRegionIndex]
|
| 238 |
+
return self.interpolateFromDeltasAndScalars(deltas, scalars)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
#
|
| 242 |
+
# Optimizations
|
| 243 |
+
#
|
| 244 |
+
# retainFirstMap - If true, major 0 mappings are retained. Deltas for unused indices are zeroed
|
| 245 |
+
# advIdxes - Set of major 0 indices for advance deltas to be listed first. Other major 0 indices follow.
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def VarStore_subset_varidxes(
|
| 249 |
+
self,
|
| 250 |
+
varIdxes,
|
| 251 |
+
optimize=True,
|
| 252 |
+
retainFirstMap=False,
|
| 253 |
+
advIdxes=set(),
|
| 254 |
+
*,
|
| 255 |
+
VarData="VarData",
|
| 256 |
+
):
|
| 257 |
+
# Sort out used varIdxes by major/minor.
|
| 258 |
+
used = defaultdict(set)
|
| 259 |
+
for varIdx in varIdxes:
|
| 260 |
+
if varIdx == NO_VARIATION_INDEX:
|
| 261 |
+
continue
|
| 262 |
+
major = varIdx >> 16
|
| 263 |
+
minor = varIdx & 0xFFFF
|
| 264 |
+
used[major].add(minor)
|
| 265 |
+
del varIdxes
|
| 266 |
+
|
| 267 |
+
#
|
| 268 |
+
# Subset VarData
|
| 269 |
+
#
|
| 270 |
+
|
| 271 |
+
varData = getattr(self, VarData)
|
| 272 |
+
newVarData = []
|
| 273 |
+
varDataMap = {NO_VARIATION_INDEX: NO_VARIATION_INDEX}
|
| 274 |
+
for major, data in enumerate(varData):
|
| 275 |
+
usedMinors = used.get(major)
|
| 276 |
+
if usedMinors is None:
|
| 277 |
+
continue
|
| 278 |
+
newMajor = len(newVarData)
|
| 279 |
+
newVarData.append(data)
|
| 280 |
+
|
| 281 |
+
items = data.Item
|
| 282 |
+
newItems = []
|
| 283 |
+
if major == 0 and retainFirstMap:
|
| 284 |
+
for minor in range(len(items)):
|
| 285 |
+
newItems.append(
|
| 286 |
+
items[minor] if minor in usedMinors else [0] * len(items[minor])
|
| 287 |
+
)
|
| 288 |
+
varDataMap[minor] = minor
|
| 289 |
+
else:
|
| 290 |
+
if major == 0:
|
| 291 |
+
minors = sorted(advIdxes) + sorted(usedMinors - advIdxes)
|
| 292 |
+
else:
|
| 293 |
+
minors = sorted(usedMinors)
|
| 294 |
+
for minor in minors:
|
| 295 |
+
newMinor = len(newItems)
|
| 296 |
+
newItems.append(items[minor])
|
| 297 |
+
varDataMap[(major << 16) + minor] = (newMajor << 16) + newMinor
|
| 298 |
+
|
| 299 |
+
data.Item = newItems
|
| 300 |
+
data.ItemCount = len(data.Item)
|
| 301 |
+
|
| 302 |
+
if VarData == "VarData":
|
| 303 |
+
data.calculateNumShorts(optimize=optimize)
|
| 304 |
+
|
| 305 |
+
setattr(self, VarData, newVarData)
|
| 306 |
+
setattr(self, VarData + "Count", len(newVarData))
|
| 307 |
+
|
| 308 |
+
self.prune_regions()
|
| 309 |
+
|
| 310 |
+
return varDataMap
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
ot.VarStore.subset_varidxes = VarStore_subset_varidxes
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def VarStore_prune_regions(self, *, VarData="VarData", VarRegionList="VarRegionList"):
|
| 317 |
+
"""Remove unused VarRegions."""
|
| 318 |
+
#
|
| 319 |
+
# Subset VarRegionList
|
| 320 |
+
#
|
| 321 |
+
|
| 322 |
+
# Collect.
|
| 323 |
+
usedRegions = set()
|
| 324 |
+
for data in getattr(self, VarData):
|
| 325 |
+
usedRegions.update(data.VarRegionIndex)
|
| 326 |
+
# Subset.
|
| 327 |
+
regionList = getattr(self, VarRegionList)
|
| 328 |
+
regions = regionList.Region
|
| 329 |
+
newRegions = []
|
| 330 |
+
regionMap = {}
|
| 331 |
+
for i in sorted(usedRegions):
|
| 332 |
+
regionMap[i] = len(newRegions)
|
| 333 |
+
newRegions.append(regions[i])
|
| 334 |
+
regionList.Region = newRegions
|
| 335 |
+
regionList.RegionCount = len(regionList.Region)
|
| 336 |
+
# Map.
|
| 337 |
+
for data in getattr(self, VarData):
|
| 338 |
+
data.VarRegionIndex = [regionMap[i] for i in data.VarRegionIndex]
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
ot.VarStore.prune_regions = VarStore_prune_regions
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def _visit(self, func):
|
| 345 |
+
"""Recurse down from self, if type of an object is ot.Device,
|
| 346 |
+
call func() on it. Works on otData-style classes."""
|
| 347 |
+
|
| 348 |
+
if type(self) == ot.Device:
|
| 349 |
+
func(self)
|
| 350 |
+
|
| 351 |
+
elif isinstance(self, list):
|
| 352 |
+
for that in self:
|
| 353 |
+
_visit(that, func)
|
| 354 |
+
|
| 355 |
+
elif hasattr(self, "getConverters") and not hasattr(self, "postRead"):
|
| 356 |
+
for conv in self.getConverters():
|
| 357 |
+
that = getattr(self, conv.name, None)
|
| 358 |
+
if that is not None:
|
| 359 |
+
_visit(that, func)
|
| 360 |
+
|
| 361 |
+
elif isinstance(self, ot.ValueRecord):
|
| 362 |
+
for that in self.__dict__.values():
|
| 363 |
+
_visit(that, func)
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def _Device_recordVarIdx(self, s):
|
| 367 |
+
"""Add VarIdx in this Device table (if any) to the set s."""
|
| 368 |
+
if self.DeltaFormat == 0x8000:
|
| 369 |
+
s.add((self.StartSize << 16) + self.EndSize)
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def Object_collect_device_varidxes(self, varidxes):
|
| 373 |
+
adder = partial(_Device_recordVarIdx, s=varidxes)
|
| 374 |
+
_visit(self, adder)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
ot.GDEF.collect_device_varidxes = Object_collect_device_varidxes
|
| 378 |
+
ot.GPOS.collect_device_varidxes = Object_collect_device_varidxes
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def _Device_mapVarIdx(self, mapping, done):
|
| 382 |
+
"""Map VarIdx in this Device table (if any) through mapping."""
|
| 383 |
+
if id(self) in done:
|
| 384 |
+
return
|
| 385 |
+
done.add(id(self))
|
| 386 |
+
if self.DeltaFormat == 0x8000:
|
| 387 |
+
varIdx = mapping[(self.StartSize << 16) + self.EndSize]
|
| 388 |
+
self.StartSize = varIdx >> 16
|
| 389 |
+
self.EndSize = varIdx & 0xFFFF
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def Object_remap_device_varidxes(self, varidxes_map):
|
| 393 |
+
mapper = partial(_Device_mapVarIdx, mapping=varidxes_map, done=set())
|
| 394 |
+
_visit(self, mapper)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
ot.GDEF.remap_device_varidxes = Object_remap_device_varidxes
|
| 398 |
+
ot.GPOS.remap_device_varidxes = Object_remap_device_varidxes
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
class _Encoding(object):
|
| 402 |
+
def __init__(self, chars):
|
| 403 |
+
self.chars = chars
|
| 404 |
+
self.width = bit_count(chars)
|
| 405 |
+
self.columns = self._columns(chars)
|
| 406 |
+
self.overhead = self._characteristic_overhead(self.columns)
|
| 407 |
+
self.items = set()
|
| 408 |
+
|
| 409 |
+
def append(self, row):
|
| 410 |
+
self.items.add(row)
|
| 411 |
+
|
| 412 |
+
def extend(self, lst):
|
| 413 |
+
self.items.update(lst)
|
| 414 |
+
|
| 415 |
+
def width_sort_key(self):
|
| 416 |
+
return self.width, self.chars
|
| 417 |
+
|
| 418 |
+
@staticmethod
|
| 419 |
+
def _characteristic_overhead(columns):
|
| 420 |
+
"""Returns overhead in bytes of encoding this characteristic
|
| 421 |
+
as a VarData."""
|
| 422 |
+
c = 4 + 6 # 4 bytes for LOffset, 6 bytes for VarData header
|
| 423 |
+
c += bit_count(columns) * 2
|
| 424 |
+
return c
|
| 425 |
+
|
| 426 |
+
@staticmethod
|
| 427 |
+
def _columns(chars):
|
| 428 |
+
cols = 0
|
| 429 |
+
i = 1
|
| 430 |
+
while chars:
|
| 431 |
+
if chars & 0b1111:
|
| 432 |
+
cols |= i
|
| 433 |
+
chars >>= 4
|
| 434 |
+
i <<= 1
|
| 435 |
+
return cols
|
| 436 |
+
|
| 437 |
+
def gain_from_merging(self, other_encoding):
|
| 438 |
+
combined_chars = other_encoding.chars | self.chars
|
| 439 |
+
combined_width = bit_count(combined_chars)
|
| 440 |
+
combined_columns = self.columns | other_encoding.columns
|
| 441 |
+
combined_overhead = _Encoding._characteristic_overhead(combined_columns)
|
| 442 |
+
combined_gain = (
|
| 443 |
+
+self.overhead
|
| 444 |
+
+ other_encoding.overhead
|
| 445 |
+
- combined_overhead
|
| 446 |
+
- (combined_width - self.width) * len(self.items)
|
| 447 |
+
- (combined_width - other_encoding.width) * len(other_encoding.items)
|
| 448 |
+
)
|
| 449 |
+
return combined_gain
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
class _EncodingDict(dict):
|
| 453 |
+
def __missing__(self, chars):
|
| 454 |
+
r = self[chars] = _Encoding(chars)
|
| 455 |
+
return r
|
| 456 |
+
|
| 457 |
+
def add_row(self, row):
|
| 458 |
+
chars = self._row_characteristics(row)
|
| 459 |
+
self[chars].append(row)
|
| 460 |
+
|
| 461 |
+
@staticmethod
|
| 462 |
+
def _row_characteristics(row):
|
| 463 |
+
"""Returns encoding characteristics for a row."""
|
| 464 |
+
longWords = False
|
| 465 |
+
|
| 466 |
+
chars = 0
|
| 467 |
+
i = 1
|
| 468 |
+
for v in row:
|
| 469 |
+
if v:
|
| 470 |
+
chars += i
|
| 471 |
+
if not (-128 <= v <= 127):
|
| 472 |
+
chars += i * 0b0010
|
| 473 |
+
if not (-32768 <= v <= 32767):
|
| 474 |
+
longWords = True
|
| 475 |
+
break
|
| 476 |
+
i <<= 4
|
| 477 |
+
|
| 478 |
+
if longWords:
|
| 479 |
+
# Redo; only allow 2byte/4byte encoding
|
| 480 |
+
chars = 0
|
| 481 |
+
i = 1
|
| 482 |
+
for v in row:
|
| 483 |
+
if v:
|
| 484 |
+
chars += i * 0b0011
|
| 485 |
+
if not (-32768 <= v <= 32767):
|
| 486 |
+
chars += i * 0b1100
|
| 487 |
+
i <<= 4
|
| 488 |
+
|
| 489 |
+
return chars
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
def VarStore_optimize(self, use_NO_VARIATION_INDEX=True, quantization=1):
|
| 493 |
+
"""Optimize storage. Returns mapping from old VarIdxes to new ones."""
|
| 494 |
+
|
| 495 |
+
# Overview:
|
| 496 |
+
#
|
| 497 |
+
# For each VarData row, we first extend it with zeroes to have
|
| 498 |
+
# one column per region in VarRegionList. We then group the
|
| 499 |
+
# rows into _Encoding objects, by their "characteristic" bitmap.
|
| 500 |
+
# The characteristic bitmap is a binary number representing how
|
| 501 |
+
# many bytes each column of the data takes up to encode. Each
|
| 502 |
+
# column is encoded in four bits. For example, if a column has
|
| 503 |
+
# only values in the range -128..127, it would only have a single
|
| 504 |
+
# bit set in the characteristic bitmap for that column. If it has
|
| 505 |
+
# values in the range -32768..32767, it would have two bits set.
|
| 506 |
+
# The number of ones in the characteristic bitmap is the "width"
|
| 507 |
+
# of the encoding.
|
| 508 |
+
#
|
| 509 |
+
# Each encoding as such has a number of "active" (ie. non-zero)
|
| 510 |
+
# columns. The overhead of encoding the characteristic bitmap
|
| 511 |
+
# is 10 bytes, plus 2 bytes per active column.
|
| 512 |
+
#
|
| 513 |
+
# When an encoding is merged into another one, if the characteristic
|
| 514 |
+
# of the old encoding is a subset of the new one, then the overhead
|
| 515 |
+
# of the old encoding is completely eliminated. However, each row
|
| 516 |
+
# now would require more bytes to encode, to the tune of one byte
|
| 517 |
+
# per characteristic bit that is active in the new encoding but not
|
| 518 |
+
# in the old one.
|
| 519 |
+
#
|
| 520 |
+
# The "gain" of merging two encodings is how many bytes we save by doing so.
|
| 521 |
+
#
|
| 522 |
+
# High-level algorithm:
|
| 523 |
+
#
|
| 524 |
+
# - Each encoding has a minimal way to encode it. However, because
|
| 525 |
+
# of the overhead of encoding the characteristic bitmap, it may
|
| 526 |
+
# be beneficial to merge two encodings together, if there is
|
| 527 |
+
# gain in doing so. As such, we need to search for the best
|
| 528 |
+
# such successive merges.
|
| 529 |
+
#
|
| 530 |
+
# Algorithm:
|
| 531 |
+
#
|
| 532 |
+
# - Put all encodings into a "todo" list.
|
| 533 |
+
#
|
| 534 |
+
# - Sort todo list (for stability) by width_sort_key(), which is a tuple
|
| 535 |
+
# of the following items:
|
| 536 |
+
# * The "width" of the encoding.
|
| 537 |
+
# * The characteristic bitmap of the encoding, with higher-numbered
|
| 538 |
+
# columns compared first.
|
| 539 |
+
#
|
| 540 |
+
# - Make a priority-queue of the gain from combining each two
|
| 541 |
+
# encodings in the todo list. The priority queue is sorted by
|
| 542 |
+
# decreasing gain. Only positive gains are included.
|
| 543 |
+
#
|
| 544 |
+
# - While priority queue is not empty:
|
| 545 |
+
# - Pop the first item from the priority queue,
|
| 546 |
+
# - Merge the two encodings it represents,
|
| 547 |
+
# - Remove the two encodings from the todo list,
|
| 548 |
+
# - Insert positive gains from combining the new encoding with
|
| 549 |
+
# all existing todo list items into the priority queue,
|
| 550 |
+
# - If a todo list item with the same characteristic bitmap as
|
| 551 |
+
# the new encoding exists, remove it from the todo list and
|
| 552 |
+
# merge it into the new encoding.
|
| 553 |
+
# - Insert the new encoding into the todo list,
|
| 554 |
+
#
|
| 555 |
+
# - Encode all remaining items in the todo list.
|
| 556 |
+
#
|
| 557 |
+
# The output is then sorted for stability, in the following way:
|
| 558 |
+
# - The VarRegionList of the input is kept intact.
|
| 559 |
+
# - The VarData is sorted by the same width_sort_key() used at the beginning.
|
| 560 |
+
# - Within each VarData, the items are sorted as vectors of numbers.
|
| 561 |
+
#
|
| 562 |
+
# Finally, each VarData is optimized to remove the empty columns and
|
| 563 |
+
# reorder columns as needed.
|
| 564 |
+
|
| 565 |
+
# TODO
|
| 566 |
+
# Check that no two VarRegions are the same; if they are, fold them.
|
| 567 |
+
|
| 568 |
+
n = len(self.VarRegionList.Region) # Number of columns
|
| 569 |
+
zeroes = [0] * n
|
| 570 |
+
|
| 571 |
+
front_mapping = {} # Map from old VarIdxes to full row tuples
|
| 572 |
+
|
| 573 |
+
encodings = _EncodingDict()
|
| 574 |
+
|
| 575 |
+
# Collect all items into a set of full rows (with lots of zeroes.)
|
| 576 |
+
for major, data in enumerate(self.VarData):
|
| 577 |
+
regionIndices = data.VarRegionIndex
|
| 578 |
+
|
| 579 |
+
for minor, item in enumerate(data.Item):
|
| 580 |
+
row = list(zeroes)
|
| 581 |
+
|
| 582 |
+
if quantization == 1:
|
| 583 |
+
for regionIdx, v in zip(regionIndices, item):
|
| 584 |
+
row[regionIdx] += v
|
| 585 |
+
else:
|
| 586 |
+
for regionIdx, v in zip(regionIndices, item):
|
| 587 |
+
row[regionIdx] += (
|
| 588 |
+
round(v / quantization) * quantization
|
| 589 |
+
) # TODO https://github.com/fonttools/fonttools/pull/3126#discussion_r1205439785
|
| 590 |
+
|
| 591 |
+
row = tuple(row)
|
| 592 |
+
|
| 593 |
+
if use_NO_VARIATION_INDEX and not any(row):
|
| 594 |
+
front_mapping[(major << 16) + minor] = None
|
| 595 |
+
continue
|
| 596 |
+
|
| 597 |
+
encodings.add_row(row)
|
| 598 |
+
front_mapping[(major << 16) + minor] = row
|
| 599 |
+
|
| 600 |
+
# Prepare for the main algorithm.
|
| 601 |
+
todo = sorted(encodings.values(), key=_Encoding.width_sort_key)
|
| 602 |
+
del encodings
|
| 603 |
+
|
| 604 |
+
# Repeatedly pick two best encodings to combine, and combine them.
|
| 605 |
+
|
| 606 |
+
heap = []
|
| 607 |
+
for i, encoding in enumerate(todo):
|
| 608 |
+
for j in range(i + 1, len(todo)):
|
| 609 |
+
other_encoding = todo[j]
|
| 610 |
+
combining_gain = encoding.gain_from_merging(other_encoding)
|
| 611 |
+
if combining_gain > 0:
|
| 612 |
+
heappush(heap, (-combining_gain, i, j))
|
| 613 |
+
|
| 614 |
+
while heap:
|
| 615 |
+
_, i, j = heappop(heap)
|
| 616 |
+
if todo[i] is None or todo[j] is None:
|
| 617 |
+
continue
|
| 618 |
+
|
| 619 |
+
encoding, other_encoding = todo[i], todo[j]
|
| 620 |
+
todo[i], todo[j] = None, None
|
| 621 |
+
|
| 622 |
+
# Combine the two encodings
|
| 623 |
+
combined_chars = other_encoding.chars | encoding.chars
|
| 624 |
+
combined_encoding = _Encoding(combined_chars)
|
| 625 |
+
combined_encoding.extend(encoding.items)
|
| 626 |
+
combined_encoding.extend(other_encoding.items)
|
| 627 |
+
|
| 628 |
+
for k, enc in enumerate(todo):
|
| 629 |
+
if enc is None:
|
| 630 |
+
continue
|
| 631 |
+
|
| 632 |
+
# In the unlikely event that the same encoding exists already,
|
| 633 |
+
# combine it.
|
| 634 |
+
if enc.chars == combined_chars:
|
| 635 |
+
combined_encoding.extend(enc.items)
|
| 636 |
+
todo[k] = None
|
| 637 |
+
continue
|
| 638 |
+
|
| 639 |
+
combining_gain = combined_encoding.gain_from_merging(enc)
|
| 640 |
+
if combining_gain > 0:
|
| 641 |
+
heappush(heap, (-combining_gain, k, len(todo)))
|
| 642 |
+
|
| 643 |
+
todo.append(combined_encoding)
|
| 644 |
+
|
| 645 |
+
encodings = [encoding for encoding in todo if encoding is not None]
|
| 646 |
+
|
| 647 |
+
# Assemble final store.
|
| 648 |
+
back_mapping = {} # Mapping from full rows to new VarIdxes
|
| 649 |
+
encodings.sort(key=_Encoding.width_sort_key)
|
| 650 |
+
self.VarData = []
|
| 651 |
+
for encoding in encodings:
|
| 652 |
+
items = sorted(encoding.items)
|
| 653 |
+
|
| 654 |
+
while items:
|
| 655 |
+
major = len(self.VarData)
|
| 656 |
+
data = ot.VarData()
|
| 657 |
+
self.VarData.append(data)
|
| 658 |
+
data.VarRegionIndex = range(n)
|
| 659 |
+
data.VarRegionCount = len(data.VarRegionIndex)
|
| 660 |
+
|
| 661 |
+
# Each major can only encode up to 0xFFFF entries.
|
| 662 |
+
data.Item, items = items[:0xFFFF], items[0xFFFF:]
|
| 663 |
+
|
| 664 |
+
for minor, item in enumerate(data.Item):
|
| 665 |
+
back_mapping[item] = (major << 16) + minor
|
| 666 |
+
|
| 667 |
+
# Compile final mapping.
|
| 668 |
+
varidx_map = {NO_VARIATION_INDEX: NO_VARIATION_INDEX}
|
| 669 |
+
for k, v in front_mapping.items():
|
| 670 |
+
varidx_map[k] = back_mapping[v] if v is not None else NO_VARIATION_INDEX
|
| 671 |
+
|
| 672 |
+
# Recalculate things and go home.
|
| 673 |
+
self.VarRegionList.RegionCount = len(self.VarRegionList.Region)
|
| 674 |
+
self.VarDataCount = len(self.VarData)
|
| 675 |
+
for data in self.VarData:
|
| 676 |
+
data.ItemCount = len(data.Item)
|
| 677 |
+
data.optimize()
|
| 678 |
+
|
| 679 |
+
# Remove unused regions.
|
| 680 |
+
self.prune_regions()
|
| 681 |
+
|
| 682 |
+
return varidx_map
|
| 683 |
+
|
| 684 |
+
|
| 685 |
+
ot.VarStore.optimize = VarStore_optimize
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
def main(args=None):
|
| 689 |
+
"""Optimize a font's GDEF variation store"""
|
| 690 |
+
from argparse import ArgumentParser
|
| 691 |
+
from fontTools import configLogger
|
| 692 |
+
from fontTools.ttLib import TTFont
|
| 693 |
+
from fontTools.ttLib.tables.otBase import OTTableWriter
|
| 694 |
+
|
| 695 |
+
parser = ArgumentParser(prog="varLib.varStore", description=main.__doc__)
|
| 696 |
+
parser.add_argument("--quantization", type=int, default=1)
|
| 697 |
+
parser.add_argument("fontfile")
|
| 698 |
+
parser.add_argument("outfile", nargs="?")
|
| 699 |
+
options = parser.parse_args(args)
|
| 700 |
+
|
| 701 |
+
# TODO: allow user to configure logging via command-line options
|
| 702 |
+
configLogger(level="INFO")
|
| 703 |
+
|
| 704 |
+
quantization = options.quantization
|
| 705 |
+
fontfile = options.fontfile
|
| 706 |
+
outfile = options.outfile
|
| 707 |
+
|
| 708 |
+
font = TTFont(fontfile)
|
| 709 |
+
gdef = font["GDEF"]
|
| 710 |
+
store = gdef.table.VarStore
|
| 711 |
+
|
| 712 |
+
writer = OTTableWriter()
|
| 713 |
+
store.compile(writer, font)
|
| 714 |
+
size = len(writer.getAllData())
|
| 715 |
+
print("Before: %7d bytes" % size)
|
| 716 |
+
|
| 717 |
+
varidx_map = store.optimize(quantization=quantization)
|
| 718 |
+
|
| 719 |
+
writer = OTTableWriter()
|
| 720 |
+
store.compile(writer, font)
|
| 721 |
+
size = len(writer.getAllData())
|
| 722 |
+
print("After: %7d bytes" % size)
|
| 723 |
+
|
| 724 |
+
if outfile is not None:
|
| 725 |
+
gdef.table.remap_device_varidxes(varidx_map)
|
| 726 |
+
if "GPOS" in font:
|
| 727 |
+
font["GPOS"].table.remap_device_varidxes(varidx_map)
|
| 728 |
+
|
| 729 |
+
font.save(outfile)
|
| 730 |
+
|
| 731 |
+
|
| 732 |
+
if __name__ == "__main__":
|
| 733 |
+
import sys
|
| 734 |
+
|
| 735 |
+
if len(sys.argv) > 1:
|
| 736 |
+
sys.exit(main())
|
| 737 |
+
import doctest
|
| 738 |
+
|
| 739 |
+
sys.exit(doctest.testmod().failed)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""fontTools.voltLib -- a package for dealing with Visual OpenType Layout Tool
|
| 2 |
+
(VOLT) files."""
|
| 3 |
+
|
| 4 |
+
# See
|
| 5 |
+
# http://www.microsoft.com/typography/VOLT.mspx
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/__main__.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import logging
|
| 3 |
+
import sys
|
| 4 |
+
from io import StringIO
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from fontTools import configLogger
|
| 8 |
+
from fontTools.feaLib.builder import addOpenTypeFeaturesFromString
|
| 9 |
+
from fontTools.feaLib.error import FeatureLibError
|
| 10 |
+
from fontTools.feaLib.lexer import Lexer
|
| 11 |
+
from fontTools.misc.cliTools import makeOutputFileName
|
| 12 |
+
from fontTools.ttLib import TTFont, TTLibError
|
| 13 |
+
from fontTools.voltLib.parser import Parser
|
| 14 |
+
from fontTools.voltLib.voltToFea import TABLES, VoltToFea
|
| 15 |
+
|
| 16 |
+
log = logging.getLogger("fontTools.feaLib")
|
| 17 |
+
|
| 18 |
+
SUPPORTED_TABLES = TABLES + ["cmap"]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def invalid_fea_glyph_name(name):
|
| 22 |
+
"""Check if the glyph name is valid according to FEA syntax."""
|
| 23 |
+
if name[0] not in Lexer.CHAR_NAME_START_:
|
| 24 |
+
return True
|
| 25 |
+
if any(c not in Lexer.CHAR_NAME_CONTINUATION_ for c in name[1:]):
|
| 26 |
+
return True
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def sanitize_glyph_name(name):
|
| 31 |
+
"""Sanitize the glyph name to ensure it is valid according to FEA syntax."""
|
| 32 |
+
sanitized = ""
|
| 33 |
+
for i, c in enumerate(name):
|
| 34 |
+
if i == 0 and c not in Lexer.CHAR_NAME_START_:
|
| 35 |
+
sanitized += "a" + c
|
| 36 |
+
elif c not in Lexer.CHAR_NAME_CONTINUATION_:
|
| 37 |
+
sanitized += "_"
|
| 38 |
+
else:
|
| 39 |
+
sanitized += c
|
| 40 |
+
|
| 41 |
+
return sanitized
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main(args=None):
|
| 45 |
+
"""Build tables from a MS VOLT project into an OTF font"""
|
| 46 |
+
parser = argparse.ArgumentParser(
|
| 47 |
+
description="Use fontTools to compile MS VOLT projects."
|
| 48 |
+
)
|
| 49 |
+
parser.add_argument(
|
| 50 |
+
"input",
|
| 51 |
+
metavar="INPUT",
|
| 52 |
+
help="Path to the input font/VTP file to process",
|
| 53 |
+
type=Path,
|
| 54 |
+
)
|
| 55 |
+
parser.add_argument(
|
| 56 |
+
"-f",
|
| 57 |
+
"--font",
|
| 58 |
+
metavar="INPUT_FONT",
|
| 59 |
+
help="Path to the input font (if INPUT is a VTP file)",
|
| 60 |
+
type=Path,
|
| 61 |
+
)
|
| 62 |
+
parser.add_argument(
|
| 63 |
+
"-o",
|
| 64 |
+
"--output",
|
| 65 |
+
dest="output",
|
| 66 |
+
metavar="OUTPUT",
|
| 67 |
+
help="Path to the output font.",
|
| 68 |
+
type=Path,
|
| 69 |
+
)
|
| 70 |
+
parser.add_argument(
|
| 71 |
+
"-t",
|
| 72 |
+
"--tables",
|
| 73 |
+
metavar="TABLE_TAG",
|
| 74 |
+
choices=SUPPORTED_TABLES,
|
| 75 |
+
nargs="+",
|
| 76 |
+
help="Specify the table(s) to be built.",
|
| 77 |
+
)
|
| 78 |
+
parser.add_argument(
|
| 79 |
+
"-F",
|
| 80 |
+
"--debug-feature-file",
|
| 81 |
+
help="Write the generated feature file to disk.",
|
| 82 |
+
action="store_true",
|
| 83 |
+
)
|
| 84 |
+
parser.add_argument(
|
| 85 |
+
"--ship",
|
| 86 |
+
help="Remove source VOLT tables from output font.",
|
| 87 |
+
action="store_true",
|
| 88 |
+
)
|
| 89 |
+
parser.add_argument(
|
| 90 |
+
"-v",
|
| 91 |
+
"--verbose",
|
| 92 |
+
help="Increase the logger verbosity. Multiple -v options are allowed.",
|
| 93 |
+
action="count",
|
| 94 |
+
default=0,
|
| 95 |
+
)
|
| 96 |
+
parser.add_argument(
|
| 97 |
+
"-T",
|
| 98 |
+
"--traceback",
|
| 99 |
+
help="show traceback for exceptions.",
|
| 100 |
+
action="store_true",
|
| 101 |
+
)
|
| 102 |
+
options = parser.parse_args(args)
|
| 103 |
+
|
| 104 |
+
levels = ["WARNING", "INFO", "DEBUG"]
|
| 105 |
+
configLogger(level=levels[min(len(levels) - 1, options.verbose)])
|
| 106 |
+
|
| 107 |
+
output_font = options.output or Path(
|
| 108 |
+
makeOutputFileName(options.font or options.input)
|
| 109 |
+
)
|
| 110 |
+
log.info(f"Compiling MS VOLT to '{output_font}'")
|
| 111 |
+
|
| 112 |
+
file_or_path = options.input
|
| 113 |
+
font = None
|
| 114 |
+
|
| 115 |
+
# If the input is a font file, extract the VOLT data from the "TSIV" table
|
| 116 |
+
try:
|
| 117 |
+
font = TTFont(file_or_path)
|
| 118 |
+
if "TSIV" in font:
|
| 119 |
+
file_or_path = StringIO(font["TSIV"].data.decode("utf-8"))
|
| 120 |
+
else:
|
| 121 |
+
log.error('"TSIV" table is missing')
|
| 122 |
+
return 1
|
| 123 |
+
except TTLibError:
|
| 124 |
+
pass
|
| 125 |
+
|
| 126 |
+
# If input is not a font file, the font must be provided
|
| 127 |
+
if font is None:
|
| 128 |
+
if not options.font:
|
| 129 |
+
log.error("Please provide an input font")
|
| 130 |
+
return 1
|
| 131 |
+
font = TTFont(options.font)
|
| 132 |
+
|
| 133 |
+
# FEA syntax does not allow some glyph names that VOLT accepts, so if we
|
| 134 |
+
# found such glyph name we will temporarily rename such glyphs.
|
| 135 |
+
glyphOrder = font.getGlyphOrder()
|
| 136 |
+
tempGlyphOrder = None
|
| 137 |
+
if any(invalid_fea_glyph_name(n) for n in glyphOrder):
|
| 138 |
+
tempGlyphOrder = []
|
| 139 |
+
for n in glyphOrder:
|
| 140 |
+
if invalid_fea_glyph_name(n):
|
| 141 |
+
n = sanitize_glyph_name(n)
|
| 142 |
+
existing = set(tempGlyphOrder) | set(glyphOrder)
|
| 143 |
+
while n in existing:
|
| 144 |
+
n = "a" + n
|
| 145 |
+
tempGlyphOrder.append(n)
|
| 146 |
+
font.setGlyphOrder(tempGlyphOrder)
|
| 147 |
+
|
| 148 |
+
doc = Parser(file_or_path).parse()
|
| 149 |
+
|
| 150 |
+
log.info("Converting VTP data to FEA")
|
| 151 |
+
converter = VoltToFea(doc, font)
|
| 152 |
+
try:
|
| 153 |
+
fea = converter.convert(options.tables, ignore_unsupported_settings=True)
|
| 154 |
+
except NotImplementedError as e:
|
| 155 |
+
if options.traceback:
|
| 156 |
+
raise
|
| 157 |
+
location = getattr(e.args[0], "location", None)
|
| 158 |
+
message = f'"{e}" is not supported'
|
| 159 |
+
if location:
|
| 160 |
+
path, line, column = location
|
| 161 |
+
log.error(f"{path}:{line}:{column}: {message}")
|
| 162 |
+
else:
|
| 163 |
+
log.error(message)
|
| 164 |
+
return 1
|
| 165 |
+
|
| 166 |
+
fea_filename = options.input
|
| 167 |
+
if options.debug_feature_file:
|
| 168 |
+
fea_filename = output_font.with_suffix(".fea")
|
| 169 |
+
log.info(f"Writing FEA to '{fea_filename}'")
|
| 170 |
+
with open(fea_filename, "w") as fp:
|
| 171 |
+
fp.write(fea)
|
| 172 |
+
|
| 173 |
+
log.info("Compiling FEA to OpenType tables")
|
| 174 |
+
try:
|
| 175 |
+
addOpenTypeFeaturesFromString(
|
| 176 |
+
font,
|
| 177 |
+
fea,
|
| 178 |
+
filename=fea_filename,
|
| 179 |
+
tables=options.tables,
|
| 180 |
+
)
|
| 181 |
+
except FeatureLibError as e:
|
| 182 |
+
if options.traceback:
|
| 183 |
+
raise
|
| 184 |
+
log.error(e)
|
| 185 |
+
return 1
|
| 186 |
+
|
| 187 |
+
if options.ship:
|
| 188 |
+
for tag in ["TSIV", "TSIS", "TSIP", "TSID"]:
|
| 189 |
+
if tag in font:
|
| 190 |
+
del font[tag]
|
| 191 |
+
|
| 192 |
+
# Restore original glyph names.
|
| 193 |
+
if tempGlyphOrder:
|
| 194 |
+
import io
|
| 195 |
+
|
| 196 |
+
f = io.BytesIO()
|
| 197 |
+
font.save(f)
|
| 198 |
+
font = TTFont(f)
|
| 199 |
+
font.setGlyphOrder(glyphOrder)
|
| 200 |
+
font["post"].extraNames = []
|
| 201 |
+
|
| 202 |
+
font.save(output_font)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
if __name__ == "__main__":
|
| 206 |
+
sys.exit(main())
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/ast.py
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.voltLib.error import VoltLibError
|
| 2 |
+
from typing import NamedTuple
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class Pos(NamedTuple):
|
| 6 |
+
adv: int
|
| 7 |
+
dx: int
|
| 8 |
+
dy: int
|
| 9 |
+
adv_adjust_by: dict
|
| 10 |
+
dx_adjust_by: dict
|
| 11 |
+
dy_adjust_by: dict
|
| 12 |
+
|
| 13 |
+
def __str__(self):
|
| 14 |
+
res = " POS"
|
| 15 |
+
for attr in ("adv", "dx", "dy"):
|
| 16 |
+
value = getattr(self, attr)
|
| 17 |
+
if value is not None:
|
| 18 |
+
res += f" {attr.upper()} {value}"
|
| 19 |
+
adjust_by = getattr(self, f"{attr}_adjust_by", {})
|
| 20 |
+
for size, adjustment in adjust_by.items():
|
| 21 |
+
res += f" ADJUST_BY {adjustment} AT {size}"
|
| 22 |
+
res += " END_POS"
|
| 23 |
+
return res
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class Element(object):
|
| 27 |
+
def __init__(self, location=None):
|
| 28 |
+
self.location = location
|
| 29 |
+
|
| 30 |
+
def build(self, builder):
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
def __str__(self):
|
| 34 |
+
raise NotImplementedError
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class Statement(Element):
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class Expression(Element):
|
| 42 |
+
pass
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class VoltFile(Statement):
|
| 46 |
+
def __init__(self):
|
| 47 |
+
Statement.__init__(self, location=None)
|
| 48 |
+
self.statements = []
|
| 49 |
+
|
| 50 |
+
def build(self, builder):
|
| 51 |
+
for s in self.statements:
|
| 52 |
+
s.build(builder)
|
| 53 |
+
|
| 54 |
+
def __str__(self):
|
| 55 |
+
return "\n" + "\n".join(str(s) for s in self.statements) + " END\n"
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class GlyphDefinition(Statement):
|
| 59 |
+
def __init__(self, name, gid, gunicode, gtype, components, location=None):
|
| 60 |
+
Statement.__init__(self, location)
|
| 61 |
+
self.name = name
|
| 62 |
+
self.id = gid
|
| 63 |
+
self.unicode = gunicode
|
| 64 |
+
self.type = gtype
|
| 65 |
+
self.components = components
|
| 66 |
+
|
| 67 |
+
def __str__(self):
|
| 68 |
+
res = f'DEF_GLYPH "{self.name}" ID {self.id}'
|
| 69 |
+
if self.unicode is not None:
|
| 70 |
+
if len(self.unicode) > 1:
|
| 71 |
+
unicodes = ",".join(f"U+{u:04X}" for u in self.unicode)
|
| 72 |
+
res += f' UNICODEVALUES "{unicodes}"'
|
| 73 |
+
else:
|
| 74 |
+
res += f" UNICODE {self.unicode[0]}"
|
| 75 |
+
if self.type is not None:
|
| 76 |
+
res += f" TYPE {self.type}"
|
| 77 |
+
if self.components is not None:
|
| 78 |
+
res += f" COMPONENTS {self.components}"
|
| 79 |
+
res += " END_GLYPH"
|
| 80 |
+
return res
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class GroupDefinition(Statement):
|
| 84 |
+
def __init__(self, name, enum, location=None):
|
| 85 |
+
Statement.__init__(self, location)
|
| 86 |
+
self.name = name
|
| 87 |
+
self.enum = enum
|
| 88 |
+
self.glyphs_ = None
|
| 89 |
+
|
| 90 |
+
def glyphSet(self, groups=None):
|
| 91 |
+
if groups is not None and self.name in groups:
|
| 92 |
+
raise VoltLibError(
|
| 93 |
+
'Group "%s" contains itself.' % (self.name), self.location
|
| 94 |
+
)
|
| 95 |
+
if self.glyphs_ is None:
|
| 96 |
+
if groups is None:
|
| 97 |
+
groups = set({self.name})
|
| 98 |
+
else:
|
| 99 |
+
groups.add(self.name)
|
| 100 |
+
self.glyphs_ = self.enum.glyphSet(groups)
|
| 101 |
+
return self.glyphs_
|
| 102 |
+
|
| 103 |
+
def __str__(self):
|
| 104 |
+
enum = self.enum and str(self.enum) or ""
|
| 105 |
+
return f'DEF_GROUP "{self.name}"\n{enum}\nEND_GROUP'
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class GlyphName(Expression):
|
| 109 |
+
"""A single glyph name, such as cedilla."""
|
| 110 |
+
|
| 111 |
+
def __init__(self, glyph, location=None):
|
| 112 |
+
Expression.__init__(self, location)
|
| 113 |
+
self.glyph = glyph
|
| 114 |
+
|
| 115 |
+
def glyphSet(self):
|
| 116 |
+
return (self.glyph,)
|
| 117 |
+
|
| 118 |
+
def __str__(self):
|
| 119 |
+
return f' GLYPH "{self.glyph}"'
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class Enum(Expression):
|
| 123 |
+
"""An enum"""
|
| 124 |
+
|
| 125 |
+
def __init__(self, enum, location=None):
|
| 126 |
+
Expression.__init__(self, location)
|
| 127 |
+
self.enum = enum
|
| 128 |
+
|
| 129 |
+
def __iter__(self):
|
| 130 |
+
for e in self.glyphSet():
|
| 131 |
+
yield e
|
| 132 |
+
|
| 133 |
+
def glyphSet(self, groups=None):
|
| 134 |
+
glyphs = []
|
| 135 |
+
for element in self.enum:
|
| 136 |
+
if isinstance(element, (GroupName, Enum)):
|
| 137 |
+
glyphs.extend(element.glyphSet(groups))
|
| 138 |
+
else:
|
| 139 |
+
glyphs.extend(element.glyphSet())
|
| 140 |
+
return tuple(glyphs)
|
| 141 |
+
|
| 142 |
+
def __str__(self):
|
| 143 |
+
enum = "".join(str(e) for e in self.enum)
|
| 144 |
+
return f" ENUM{enum} END_ENUM"
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class GroupName(Expression):
|
| 148 |
+
"""A glyph group"""
|
| 149 |
+
|
| 150 |
+
def __init__(self, group, parser, location=None):
|
| 151 |
+
Expression.__init__(self, location)
|
| 152 |
+
self.group = group
|
| 153 |
+
self.parser_ = parser
|
| 154 |
+
|
| 155 |
+
def glyphSet(self, groups=None):
|
| 156 |
+
group = self.parser_.resolve_group(self.group)
|
| 157 |
+
if group is not None:
|
| 158 |
+
self.glyphs_ = group.glyphSet(groups)
|
| 159 |
+
return self.glyphs_
|
| 160 |
+
else:
|
| 161 |
+
raise VoltLibError(
|
| 162 |
+
'Group "%s" is used but undefined.' % (self.group), self.location
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
def __str__(self):
|
| 166 |
+
return f' GROUP "{self.group}"'
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class Range(Expression):
|
| 170 |
+
"""A glyph range"""
|
| 171 |
+
|
| 172 |
+
def __init__(self, start, end, parser, location=None):
|
| 173 |
+
Expression.__init__(self, location)
|
| 174 |
+
self.start = start
|
| 175 |
+
self.end = end
|
| 176 |
+
self.parser = parser
|
| 177 |
+
|
| 178 |
+
def glyphSet(self):
|
| 179 |
+
return tuple(self.parser.glyph_range(self.start, self.end))
|
| 180 |
+
|
| 181 |
+
def __str__(self):
|
| 182 |
+
return f' RANGE "{self.start}" TO "{self.end}"'
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class ScriptDefinition(Statement):
|
| 186 |
+
def __init__(self, name, tag, langs, location=None):
|
| 187 |
+
Statement.__init__(self, location)
|
| 188 |
+
self.name = name
|
| 189 |
+
self.tag = tag
|
| 190 |
+
self.langs = langs
|
| 191 |
+
|
| 192 |
+
def __str__(self):
|
| 193 |
+
res = "DEF_SCRIPT"
|
| 194 |
+
if self.name is not None:
|
| 195 |
+
res += f' NAME "{self.name}"'
|
| 196 |
+
res += f' TAG "{self.tag}"\n\n'
|
| 197 |
+
for lang in self.langs:
|
| 198 |
+
res += f"{lang}"
|
| 199 |
+
res += "END_SCRIPT"
|
| 200 |
+
return res
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
class LangSysDefinition(Statement):
|
| 204 |
+
def __init__(self, name, tag, features, location=None):
|
| 205 |
+
Statement.__init__(self, location)
|
| 206 |
+
self.name = name
|
| 207 |
+
self.tag = tag
|
| 208 |
+
self.features = features
|
| 209 |
+
|
| 210 |
+
def __str__(self):
|
| 211 |
+
res = "DEF_LANGSYS"
|
| 212 |
+
if self.name is not None:
|
| 213 |
+
res += f' NAME "{self.name}"'
|
| 214 |
+
res += f' TAG "{self.tag}"\n\n'
|
| 215 |
+
for feature in self.features:
|
| 216 |
+
res += f"{feature}"
|
| 217 |
+
res += "END_LANGSYS\n"
|
| 218 |
+
return res
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
class FeatureDefinition(Statement):
|
| 222 |
+
def __init__(self, name, tag, lookups, location=None):
|
| 223 |
+
Statement.__init__(self, location)
|
| 224 |
+
self.name = name
|
| 225 |
+
self.tag = tag
|
| 226 |
+
self.lookups = lookups
|
| 227 |
+
|
| 228 |
+
def __str__(self):
|
| 229 |
+
res = f'DEF_FEATURE NAME "{self.name}" TAG "{self.tag}"\n'
|
| 230 |
+
res += " " + " ".join(f'LOOKUP "{l}"' for l in self.lookups) + "\n"
|
| 231 |
+
res += "END_FEATURE\n"
|
| 232 |
+
return res
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class LookupDefinition(Statement):
|
| 236 |
+
def __init__(
|
| 237 |
+
self,
|
| 238 |
+
name,
|
| 239 |
+
process_base,
|
| 240 |
+
process_marks,
|
| 241 |
+
mark_glyph_set,
|
| 242 |
+
direction,
|
| 243 |
+
reversal,
|
| 244 |
+
comments,
|
| 245 |
+
context,
|
| 246 |
+
sub,
|
| 247 |
+
pos,
|
| 248 |
+
location=None,
|
| 249 |
+
):
|
| 250 |
+
Statement.__init__(self, location)
|
| 251 |
+
self.name = name
|
| 252 |
+
self.process_base = process_base
|
| 253 |
+
self.process_marks = process_marks
|
| 254 |
+
self.mark_glyph_set = mark_glyph_set
|
| 255 |
+
self.direction = direction
|
| 256 |
+
self.reversal = reversal
|
| 257 |
+
self.comments = comments
|
| 258 |
+
self.context = context
|
| 259 |
+
self.sub = sub
|
| 260 |
+
self.pos = pos
|
| 261 |
+
|
| 262 |
+
def __str__(self):
|
| 263 |
+
res = f'DEF_LOOKUP "{self.name}"'
|
| 264 |
+
res += f' {self.process_base and "PROCESS_BASE" or "SKIP_BASE"}'
|
| 265 |
+
if self.process_marks:
|
| 266 |
+
res += " PROCESS_MARKS "
|
| 267 |
+
if self.mark_glyph_set:
|
| 268 |
+
res += f'MARK_GLYPH_SET "{self.mark_glyph_set}"'
|
| 269 |
+
elif isinstance(self.process_marks, str):
|
| 270 |
+
res += f'"{self.process_marks}"'
|
| 271 |
+
else:
|
| 272 |
+
res += "ALL"
|
| 273 |
+
else:
|
| 274 |
+
res += " SKIP_MARKS"
|
| 275 |
+
if self.direction is not None:
|
| 276 |
+
res += f" DIRECTION {self.direction}"
|
| 277 |
+
if self.reversal:
|
| 278 |
+
res += " REVERSAL"
|
| 279 |
+
if self.comments is not None:
|
| 280 |
+
comments = self.comments.replace("\n", r"\n")
|
| 281 |
+
res += f'\nCOMMENTS "{comments}"'
|
| 282 |
+
if self.context:
|
| 283 |
+
res += "\n" + "\n".join(str(c) for c in self.context)
|
| 284 |
+
else:
|
| 285 |
+
res += "\nIN_CONTEXT\nEND_CONTEXT"
|
| 286 |
+
if self.sub:
|
| 287 |
+
res += f"\n{self.sub}"
|
| 288 |
+
if self.pos:
|
| 289 |
+
res += f"\n{self.pos}"
|
| 290 |
+
return res
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
class SubstitutionDefinition(Statement):
|
| 294 |
+
def __init__(self, mapping, location=None):
|
| 295 |
+
Statement.__init__(self, location)
|
| 296 |
+
self.mapping = mapping
|
| 297 |
+
|
| 298 |
+
def __str__(self):
|
| 299 |
+
res = "AS_SUBSTITUTION\n"
|
| 300 |
+
for src, dst in self.mapping.items():
|
| 301 |
+
src = "".join(str(s) for s in src)
|
| 302 |
+
dst = "".join(str(d) for d in dst)
|
| 303 |
+
res += f"SUB{src}\nWITH{dst}\nEND_SUB\n"
|
| 304 |
+
res += "END_SUBSTITUTION"
|
| 305 |
+
return res
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
class SubstitutionSingleDefinition(SubstitutionDefinition):
|
| 309 |
+
pass
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class SubstitutionMultipleDefinition(SubstitutionDefinition):
|
| 313 |
+
pass
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
class SubstitutionLigatureDefinition(SubstitutionDefinition):
|
| 317 |
+
pass
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
class SubstitutionAlternateDefinition(SubstitutionDefinition):
|
| 321 |
+
pass
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
class SubstitutionReverseChainingSingleDefinition(SubstitutionDefinition):
|
| 325 |
+
pass
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
class PositionAttachDefinition(Statement):
|
| 329 |
+
def __init__(self, coverage, coverage_to, location=None):
|
| 330 |
+
Statement.__init__(self, location)
|
| 331 |
+
self.coverage = coverage
|
| 332 |
+
self.coverage_to = coverage_to
|
| 333 |
+
|
| 334 |
+
def __str__(self):
|
| 335 |
+
coverage = "".join(str(c) for c in self.coverage)
|
| 336 |
+
res = f"AS_POSITION\nATTACH{coverage}\nTO"
|
| 337 |
+
for coverage, anchor in self.coverage_to:
|
| 338 |
+
coverage = "".join(str(c) for c in coverage)
|
| 339 |
+
res += f'{coverage} AT ANCHOR "{anchor}"'
|
| 340 |
+
res += "\nEND_ATTACH\nEND_POSITION"
|
| 341 |
+
return res
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
class PositionAttachCursiveDefinition(Statement):
|
| 345 |
+
def __init__(self, coverages_exit, coverages_enter, location=None):
|
| 346 |
+
Statement.__init__(self, location)
|
| 347 |
+
self.coverages_exit = coverages_exit
|
| 348 |
+
self.coverages_enter = coverages_enter
|
| 349 |
+
|
| 350 |
+
def __str__(self):
|
| 351 |
+
res = "AS_POSITION\nATTACH_CURSIVE"
|
| 352 |
+
for coverage in self.coverages_exit:
|
| 353 |
+
coverage = "".join(str(c) for c in coverage)
|
| 354 |
+
res += f"\nEXIT {coverage}"
|
| 355 |
+
for coverage in self.coverages_enter:
|
| 356 |
+
coverage = "".join(str(c) for c in coverage)
|
| 357 |
+
res += f"\nENTER {coverage}"
|
| 358 |
+
res += "\nEND_ATTACH\nEND_POSITION"
|
| 359 |
+
return res
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class PositionAdjustPairDefinition(Statement):
|
| 363 |
+
def __init__(self, coverages_1, coverages_2, adjust_pair, location=None):
|
| 364 |
+
Statement.__init__(self, location)
|
| 365 |
+
self.coverages_1 = coverages_1
|
| 366 |
+
self.coverages_2 = coverages_2
|
| 367 |
+
self.adjust_pair = adjust_pair
|
| 368 |
+
|
| 369 |
+
def __str__(self):
|
| 370 |
+
res = "AS_POSITION\nADJUST_PAIR\n"
|
| 371 |
+
for coverage in self.coverages_1:
|
| 372 |
+
coverage = " ".join(str(c) for c in coverage)
|
| 373 |
+
res += f" FIRST {coverage}"
|
| 374 |
+
res += "\n"
|
| 375 |
+
for coverage in self.coverages_2:
|
| 376 |
+
coverage = " ".join(str(c) for c in coverage)
|
| 377 |
+
res += f" SECOND {coverage}"
|
| 378 |
+
res += "\n"
|
| 379 |
+
for (id_1, id_2), (pos_1, pos_2) in self.adjust_pair.items():
|
| 380 |
+
res += f" {id_1} {id_2} BY{pos_1}{pos_2}\n"
|
| 381 |
+
res += "\nEND_ADJUST\nEND_POSITION"
|
| 382 |
+
return res
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
class PositionAdjustSingleDefinition(Statement):
|
| 386 |
+
def __init__(self, adjust_single, location=None):
|
| 387 |
+
Statement.__init__(self, location)
|
| 388 |
+
self.adjust_single = adjust_single
|
| 389 |
+
|
| 390 |
+
def __str__(self):
|
| 391 |
+
res = "AS_POSITION\nADJUST_SINGLE"
|
| 392 |
+
for coverage, pos in self.adjust_single:
|
| 393 |
+
coverage = "".join(str(c) for c in coverage)
|
| 394 |
+
res += f"{coverage} BY{pos}"
|
| 395 |
+
res += "\nEND_ADJUST\nEND_POSITION"
|
| 396 |
+
return res
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
class ContextDefinition(Statement):
|
| 400 |
+
def __init__(self, ex_or_in, left=None, right=None, location=None):
|
| 401 |
+
Statement.__init__(self, location)
|
| 402 |
+
self.ex_or_in = ex_or_in
|
| 403 |
+
self.left = left if left is not None else []
|
| 404 |
+
self.right = right if right is not None else []
|
| 405 |
+
|
| 406 |
+
def __str__(self):
|
| 407 |
+
res = self.ex_or_in + "\n"
|
| 408 |
+
for coverage in self.left:
|
| 409 |
+
coverage = "".join(str(c) for c in coverage)
|
| 410 |
+
res += f" LEFT{coverage}\n"
|
| 411 |
+
for coverage in self.right:
|
| 412 |
+
coverage = "".join(str(c) for c in coverage)
|
| 413 |
+
res += f" RIGHT{coverage}\n"
|
| 414 |
+
res += "END_CONTEXT"
|
| 415 |
+
return res
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
class AnchorDefinition(Statement):
|
| 419 |
+
def __init__(self, name, gid, glyph_name, component, locked, pos, location=None):
|
| 420 |
+
Statement.__init__(self, location)
|
| 421 |
+
self.name = name
|
| 422 |
+
self.gid = gid
|
| 423 |
+
self.glyph_name = glyph_name
|
| 424 |
+
self.component = component
|
| 425 |
+
self.locked = locked
|
| 426 |
+
self.pos = pos
|
| 427 |
+
|
| 428 |
+
def __str__(self):
|
| 429 |
+
locked = self.locked and " LOCKED" or ""
|
| 430 |
+
return (
|
| 431 |
+
f'DEF_ANCHOR "{self.name}"'
|
| 432 |
+
f" ON {self.gid}"
|
| 433 |
+
f" GLYPH {self.glyph_name}"
|
| 434 |
+
f" COMPONENT {self.component}"
|
| 435 |
+
f"{locked}"
|
| 436 |
+
f" AT {self.pos} END_ANCHOR"
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
class SettingDefinition(Statement):
|
| 441 |
+
def __init__(self, name, value, location=None):
|
| 442 |
+
Statement.__init__(self, location)
|
| 443 |
+
self.name = name
|
| 444 |
+
self.value = value
|
| 445 |
+
|
| 446 |
+
def __str__(self):
|
| 447 |
+
if self.value is True:
|
| 448 |
+
return f"{self.name}"
|
| 449 |
+
if isinstance(self.value, (tuple, list)):
|
| 450 |
+
value = " ".join(str(v) for v in self.value)
|
| 451 |
+
return f"{self.name} {value}"
|
| 452 |
+
return f"{self.name} {self.value}"
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/error.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class VoltLibError(Exception):
|
| 2 |
+
def __init__(self, message, location):
|
| 3 |
+
Exception.__init__(self, message)
|
| 4 |
+
self.location = location
|
| 5 |
+
|
| 6 |
+
def __str__(self):
|
| 7 |
+
message = Exception.__str__(self)
|
| 8 |
+
if self.location:
|
| 9 |
+
path, line, column = self.location
|
| 10 |
+
return "%s:%d:%d: %s" % (path, line, column, message)
|
| 11 |
+
else:
|
| 12 |
+
return message
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/lexer.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.voltLib.error import VoltLibError
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Lexer(object):
|
| 5 |
+
NUMBER = "NUMBER"
|
| 6 |
+
STRING = "STRING"
|
| 7 |
+
NAME = "NAME"
|
| 8 |
+
NEWLINE = "NEWLINE"
|
| 9 |
+
|
| 10 |
+
CHAR_WHITESPACE_ = " \t"
|
| 11 |
+
CHAR_NEWLINE_ = "\r\n"
|
| 12 |
+
CHAR_DIGIT_ = "0123456789"
|
| 13 |
+
CHAR_UC_LETTER_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| 14 |
+
CHAR_LC_LETTER_ = "abcdefghijklmnopqrstuvwxyz"
|
| 15 |
+
CHAR_UNDERSCORE_ = "_"
|
| 16 |
+
CHAR_PERIOD_ = "."
|
| 17 |
+
CHAR_NAME_START_ = (
|
| 18 |
+
CHAR_UC_LETTER_ + CHAR_LC_LETTER_ + CHAR_PERIOD_ + CHAR_UNDERSCORE_
|
| 19 |
+
)
|
| 20 |
+
CHAR_NAME_CONTINUATION_ = CHAR_NAME_START_ + CHAR_DIGIT_
|
| 21 |
+
|
| 22 |
+
def __init__(self, text, filename):
|
| 23 |
+
self.filename_ = filename
|
| 24 |
+
self.line_ = 1
|
| 25 |
+
self.pos_ = 0
|
| 26 |
+
self.line_start_ = 0
|
| 27 |
+
self.text_ = text
|
| 28 |
+
self.text_length_ = len(text)
|
| 29 |
+
|
| 30 |
+
def __iter__(self):
|
| 31 |
+
return self
|
| 32 |
+
|
| 33 |
+
def next(self): # Python 2
|
| 34 |
+
return self.__next__()
|
| 35 |
+
|
| 36 |
+
def __next__(self): # Python 3
|
| 37 |
+
while True:
|
| 38 |
+
token_type, token, location = self.next_()
|
| 39 |
+
if token_type not in {Lexer.NEWLINE}:
|
| 40 |
+
return (token_type, token, location)
|
| 41 |
+
|
| 42 |
+
def location_(self):
|
| 43 |
+
column = self.pos_ - self.line_start_ + 1
|
| 44 |
+
return (self.filename_ or "<volt>", self.line_, column)
|
| 45 |
+
|
| 46 |
+
def next_(self):
|
| 47 |
+
self.scan_over_(Lexer.CHAR_WHITESPACE_)
|
| 48 |
+
location = self.location_()
|
| 49 |
+
start = self.pos_
|
| 50 |
+
text = self.text_
|
| 51 |
+
limit = len(text)
|
| 52 |
+
if start >= limit:
|
| 53 |
+
raise StopIteration()
|
| 54 |
+
cur_char = text[start]
|
| 55 |
+
next_char = text[start + 1] if start + 1 < limit else None
|
| 56 |
+
|
| 57 |
+
if cur_char == "\n":
|
| 58 |
+
self.pos_ += 1
|
| 59 |
+
self.line_ += 1
|
| 60 |
+
self.line_start_ = self.pos_
|
| 61 |
+
return (Lexer.NEWLINE, None, location)
|
| 62 |
+
if cur_char == "\r":
|
| 63 |
+
self.pos_ += 2 if next_char == "\n" else 1
|
| 64 |
+
self.line_ += 1
|
| 65 |
+
self.line_start_ = self.pos_
|
| 66 |
+
return (Lexer.NEWLINE, None, location)
|
| 67 |
+
if cur_char == '"':
|
| 68 |
+
self.pos_ += 1
|
| 69 |
+
self.scan_until_('"\r\n')
|
| 70 |
+
if self.pos_ < self.text_length_ and self.text_[self.pos_] == '"':
|
| 71 |
+
self.pos_ += 1
|
| 72 |
+
return (Lexer.STRING, text[start + 1 : self.pos_ - 1], location)
|
| 73 |
+
else:
|
| 74 |
+
raise VoltLibError("Expected '\"' to terminate string", location)
|
| 75 |
+
if cur_char in Lexer.CHAR_NAME_START_:
|
| 76 |
+
self.pos_ += 1
|
| 77 |
+
self.scan_over_(Lexer.CHAR_NAME_CONTINUATION_)
|
| 78 |
+
token = text[start : self.pos_]
|
| 79 |
+
return (Lexer.NAME, token, location)
|
| 80 |
+
if cur_char in Lexer.CHAR_DIGIT_:
|
| 81 |
+
self.scan_over_(Lexer.CHAR_DIGIT_)
|
| 82 |
+
return (Lexer.NUMBER, int(text[start : self.pos_], 10), location)
|
| 83 |
+
if cur_char == "-" and next_char in Lexer.CHAR_DIGIT_:
|
| 84 |
+
self.pos_ += 1
|
| 85 |
+
self.scan_over_(Lexer.CHAR_DIGIT_)
|
| 86 |
+
return (Lexer.NUMBER, int(text[start : self.pos_], 10), location)
|
| 87 |
+
raise VoltLibError("Unexpected character: '%s'" % cur_char, location)
|
| 88 |
+
|
| 89 |
+
def scan_over_(self, valid):
|
| 90 |
+
p = self.pos_
|
| 91 |
+
while p < self.text_length_ and self.text_[p] in valid:
|
| 92 |
+
p += 1
|
| 93 |
+
self.pos_ = p
|
| 94 |
+
|
| 95 |
+
def scan_until_(self, stop_at):
|
| 96 |
+
p = self.pos_
|
| 97 |
+
while p < self.text_length_ and self.text_[p] not in stop_at:
|
| 98 |
+
p += 1
|
| 99 |
+
self.pos_ = p
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fontTools/voltLib/parser.py
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fontTools.voltLib.ast as ast
|
| 2 |
+
from fontTools.voltLib.lexer import Lexer
|
| 3 |
+
from fontTools.voltLib.error import VoltLibError
|
| 4 |
+
from io import open
|
| 5 |
+
|
| 6 |
+
PARSE_FUNCS = {
|
| 7 |
+
"DEF_GLYPH": "parse_def_glyph_",
|
| 8 |
+
"DEF_GROUP": "parse_def_group_",
|
| 9 |
+
"DEF_SCRIPT": "parse_def_script_",
|
| 10 |
+
"DEF_LOOKUP": "parse_def_lookup_",
|
| 11 |
+
"DEF_ANCHOR": "parse_def_anchor_",
|
| 12 |
+
"GRID_PPEM": "parse_ppem_",
|
| 13 |
+
"PRESENTATION_PPEM": "parse_ppem_",
|
| 14 |
+
"PPOSITIONING_PPEM": "parse_ppem_",
|
| 15 |
+
"COMPILER_USEEXTENSIONLOOKUPS": "parse_noarg_option_",
|
| 16 |
+
"COMPILER_USEPAIRPOSFORMAT2": "parse_noarg_option_",
|
| 17 |
+
"CMAP_FORMAT": "parse_cmap_format",
|
| 18 |
+
"DO_NOT_TOUCH_CMAP": "parse_noarg_option_",
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class Parser(object):
|
| 23 |
+
def __init__(self, path):
|
| 24 |
+
self.doc_ = ast.VoltFile()
|
| 25 |
+
self.glyphs_ = OrderedSymbolTable()
|
| 26 |
+
self.groups_ = SymbolTable()
|
| 27 |
+
self.anchors_ = {} # dictionary of SymbolTable() keyed by glyph
|
| 28 |
+
self.scripts_ = SymbolTable()
|
| 29 |
+
self.langs_ = SymbolTable()
|
| 30 |
+
self.lookups_ = SymbolTable()
|
| 31 |
+
self.next_token_type_, self.next_token_ = (None, None)
|
| 32 |
+
self.next_token_location_ = None
|
| 33 |
+
self.make_lexer_(path)
|
| 34 |
+
self.advance_lexer_()
|
| 35 |
+
|
| 36 |
+
def make_lexer_(self, file_or_path):
|
| 37 |
+
if hasattr(file_or_path, "read"):
|
| 38 |
+
filename = getattr(file_or_path, "name", None)
|
| 39 |
+
data = file_or_path.read()
|
| 40 |
+
else:
|
| 41 |
+
filename = file_or_path
|
| 42 |
+
with open(file_or_path, "r") as f:
|
| 43 |
+
data = f.read()
|
| 44 |
+
self.lexer_ = Lexer(data, filename)
|
| 45 |
+
|
| 46 |
+
def parse(self):
|
| 47 |
+
statements = self.doc_.statements
|
| 48 |
+
while self.next_token_type_ is not None:
|
| 49 |
+
self.advance_lexer_()
|
| 50 |
+
if self.cur_token_ in PARSE_FUNCS.keys():
|
| 51 |
+
func = getattr(self, PARSE_FUNCS[self.cur_token_])
|
| 52 |
+
statements.append(func())
|
| 53 |
+
elif self.is_cur_keyword_("END"):
|
| 54 |
+
break
|
| 55 |
+
else:
|
| 56 |
+
raise VoltLibError(
|
| 57 |
+
"Expected " + ", ".join(sorted(PARSE_FUNCS.keys())),
|
| 58 |
+
self.cur_token_location_,
|
| 59 |
+
)
|
| 60 |
+
return self.doc_
|
| 61 |
+
|
| 62 |
+
def parse_def_glyph_(self):
|
| 63 |
+
assert self.is_cur_keyword_("DEF_GLYPH")
|
| 64 |
+
location = self.cur_token_location_
|
| 65 |
+
name = self.expect_string_()
|
| 66 |
+
self.expect_keyword_("ID")
|
| 67 |
+
gid = self.expect_number_()
|
| 68 |
+
if gid < 0:
|
| 69 |
+
raise VoltLibError("Invalid glyph ID", self.cur_token_location_)
|
| 70 |
+
gunicode = None
|
| 71 |
+
if self.next_token_ == "UNICODE":
|
| 72 |
+
self.expect_keyword_("UNICODE")
|
| 73 |
+
gunicode = [self.expect_number_()]
|
| 74 |
+
if gunicode[0] < 0:
|
| 75 |
+
raise VoltLibError("Invalid glyph UNICODE", self.cur_token_location_)
|
| 76 |
+
elif self.next_token_ == "UNICODEVALUES":
|
| 77 |
+
self.expect_keyword_("UNICODEVALUES")
|
| 78 |
+
gunicode = self.parse_unicode_values_()
|
| 79 |
+
gtype = None
|
| 80 |
+
if self.next_token_ == "TYPE":
|
| 81 |
+
self.expect_keyword_("TYPE")
|
| 82 |
+
gtype = self.expect_name_()
|
| 83 |
+
assert gtype in ("BASE", "LIGATURE", "MARK", "COMPONENT")
|
| 84 |
+
components = None
|
| 85 |
+
if self.next_token_ == "COMPONENTS":
|
| 86 |
+
self.expect_keyword_("COMPONENTS")
|
| 87 |
+
components = self.expect_number_()
|
| 88 |
+
self.expect_keyword_("END_GLYPH")
|
| 89 |
+
if self.glyphs_.resolve(name) is not None:
|
| 90 |
+
raise VoltLibError(
|
| 91 |
+
'Glyph "%s" (gid %i) already defined' % (name, gid), location
|
| 92 |
+
)
|
| 93 |
+
def_glyph = ast.GlyphDefinition(
|
| 94 |
+
name, gid, gunicode, gtype, components, location=location
|
| 95 |
+
)
|
| 96 |
+
self.glyphs_.define(name, def_glyph)
|
| 97 |
+
return def_glyph
|
| 98 |
+
|
| 99 |
+
def parse_def_group_(self):
|
| 100 |
+
assert self.is_cur_keyword_("DEF_GROUP")
|
| 101 |
+
location = self.cur_token_location_
|
| 102 |
+
name = self.expect_string_()
|
| 103 |
+
enum = None
|
| 104 |
+
if self.next_token_ == "ENUM":
|
| 105 |
+
enum = self.parse_enum_()
|
| 106 |
+
self.expect_keyword_("END_GROUP")
|
| 107 |
+
if self.groups_.resolve(name) is not None:
|
| 108 |
+
raise VoltLibError(
|
| 109 |
+
'Glyph group "%s" already defined, '
|
| 110 |
+
"group names are case insensitive" % name,
|
| 111 |
+
location,
|
| 112 |
+
)
|
| 113 |
+
def_group = ast.GroupDefinition(name, enum, location=location)
|
| 114 |
+
self.groups_.define(name, def_group)
|
| 115 |
+
return def_group
|
| 116 |
+
|
| 117 |
+
def parse_def_script_(self):
|
| 118 |
+
assert self.is_cur_keyword_("DEF_SCRIPT")
|
| 119 |
+
location = self.cur_token_location_
|
| 120 |
+
name = None
|
| 121 |
+
if self.next_token_ == "NAME":
|
| 122 |
+
self.expect_keyword_("NAME")
|
| 123 |
+
name = self.expect_string_()
|
| 124 |
+
self.expect_keyword_("TAG")
|
| 125 |
+
tag = self.expect_string_()
|
| 126 |
+
if self.scripts_.resolve(tag) is not None:
|
| 127 |
+
raise VoltLibError(
|
| 128 |
+
'Script "%s" already defined, '
|
| 129 |
+
"script tags are case insensitive" % tag,
|
| 130 |
+
location,
|
| 131 |
+
)
|
| 132 |
+
self.langs_.enter_scope()
|
| 133 |
+
langs = []
|
| 134 |
+
while self.next_token_ != "END_SCRIPT":
|
| 135 |
+
self.advance_lexer_()
|
| 136 |
+
lang = self.parse_langsys_()
|
| 137 |
+
self.expect_keyword_("END_LANGSYS")
|
| 138 |
+
if self.langs_.resolve(lang.tag) is not None:
|
| 139 |
+
raise VoltLibError(
|
| 140 |
+
'Language "%s" already defined in script "%s", '
|
| 141 |
+
"language tags are case insensitive" % (lang.tag, tag),
|
| 142 |
+
location,
|
| 143 |
+
)
|
| 144 |
+
self.langs_.define(lang.tag, lang)
|
| 145 |
+
langs.append(lang)
|
| 146 |
+
self.expect_keyword_("END_SCRIPT")
|
| 147 |
+
self.langs_.exit_scope()
|
| 148 |
+
def_script = ast.ScriptDefinition(name, tag, langs, location=location)
|
| 149 |
+
self.scripts_.define(tag, def_script)
|
| 150 |
+
return def_script
|
| 151 |
+
|
| 152 |
+
def parse_langsys_(self):
|
| 153 |
+
assert self.is_cur_keyword_("DEF_LANGSYS")
|
| 154 |
+
location = self.cur_token_location_
|
| 155 |
+
name = None
|
| 156 |
+
if self.next_token_ == "NAME":
|
| 157 |
+
self.expect_keyword_("NAME")
|
| 158 |
+
name = self.expect_string_()
|
| 159 |
+
self.expect_keyword_("TAG")
|
| 160 |
+
tag = self.expect_string_()
|
| 161 |
+
features = []
|
| 162 |
+
while self.next_token_ != "END_LANGSYS":
|
| 163 |
+
self.advance_lexer_()
|
| 164 |
+
feature = self.parse_feature_()
|
| 165 |
+
self.expect_keyword_("END_FEATURE")
|
| 166 |
+
features.append(feature)
|
| 167 |
+
def_langsys = ast.LangSysDefinition(name, tag, features, location=location)
|
| 168 |
+
return def_langsys
|
| 169 |
+
|
| 170 |
+
def parse_feature_(self):
|
| 171 |
+
assert self.is_cur_keyword_("DEF_FEATURE")
|
| 172 |
+
location = self.cur_token_location_
|
| 173 |
+
self.expect_keyword_("NAME")
|
| 174 |
+
name = self.expect_string_()
|
| 175 |
+
self.expect_keyword_("TAG")
|
| 176 |
+
tag = self.expect_string_()
|
| 177 |
+
lookups = []
|
| 178 |
+
while self.next_token_ != "END_FEATURE":
|
| 179 |
+
# self.advance_lexer_()
|
| 180 |
+
self.expect_keyword_("LOOKUP")
|
| 181 |
+
lookup = self.expect_string_()
|
| 182 |
+
lookups.append(lookup)
|
| 183 |
+
feature = ast.FeatureDefinition(name, tag, lookups, location=location)
|
| 184 |
+
return feature
|
| 185 |
+
|
| 186 |
+
def parse_def_lookup_(self):
|
| 187 |
+
assert self.is_cur_keyword_("DEF_LOOKUP")
|
| 188 |
+
location = self.cur_token_location_
|
| 189 |
+
name = self.expect_string_()
|
| 190 |
+
if not name[0].isalpha():
|
| 191 |
+
raise VoltLibError(
|
| 192 |
+
'Lookup name "%s" must start with a letter' % name, location
|
| 193 |
+
)
|
| 194 |
+
if self.lookups_.resolve(name) is not None:
|
| 195 |
+
raise VoltLibError(
|
| 196 |
+
'Lookup "%s" already defined, '
|
| 197 |
+
"lookup names are case insensitive" % name,
|
| 198 |
+
location,
|
| 199 |
+
)
|
| 200 |
+
process_base = True
|
| 201 |
+
if self.next_token_ == "PROCESS_BASE":
|
| 202 |
+
self.advance_lexer_()
|
| 203 |
+
elif self.next_token_ == "SKIP_BASE":
|
| 204 |
+
self.advance_lexer_()
|
| 205 |
+
process_base = False
|
| 206 |
+
process_marks = True
|
| 207 |
+
mark_glyph_set = None
|
| 208 |
+
if self.next_token_ == "PROCESS_MARKS":
|
| 209 |
+
self.advance_lexer_()
|
| 210 |
+
if self.next_token_ == "MARK_GLYPH_SET":
|
| 211 |
+
self.advance_lexer_()
|
| 212 |
+
mark_glyph_set = self.expect_string_()
|
| 213 |
+
elif self.next_token_ == "ALL":
|
| 214 |
+
self.advance_lexer_()
|
| 215 |
+
elif self.next_token_ == "NONE":
|
| 216 |
+
self.advance_lexer_()
|
| 217 |
+
process_marks = False
|
| 218 |
+
elif self.next_token_type_ == Lexer.STRING:
|
| 219 |
+
process_marks = self.expect_string_()
|
| 220 |
+
else:
|
| 221 |
+
raise VoltLibError(
|
| 222 |
+
"Expected ALL, NONE, MARK_GLYPH_SET or an ID. "
|
| 223 |
+
"Got %s" % (self.next_token_type_),
|
| 224 |
+
location,
|
| 225 |
+
)
|
| 226 |
+
elif self.next_token_ == "SKIP_MARKS":
|
| 227 |
+
self.advance_lexer_()
|
| 228 |
+
process_marks = False
|
| 229 |
+
direction = None
|
| 230 |
+
if self.next_token_ == "DIRECTION":
|
| 231 |
+
self.expect_keyword_("DIRECTION")
|
| 232 |
+
direction = self.expect_name_()
|
| 233 |
+
assert direction in ("LTR", "RTL")
|
| 234 |
+
reversal = None
|
| 235 |
+
if self.next_token_ == "REVERSAL":
|
| 236 |
+
self.expect_keyword_("REVERSAL")
|
| 237 |
+
reversal = True
|
| 238 |
+
comments = None
|
| 239 |
+
if self.next_token_ == "COMMENTS":
|
| 240 |
+
self.expect_keyword_("COMMENTS")
|
| 241 |
+
comments = self.expect_string_().replace(r"\n", "\n")
|
| 242 |
+
context = []
|
| 243 |
+
while self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"):
|
| 244 |
+
context = self.parse_context_()
|
| 245 |
+
as_pos_or_sub = self.expect_name_()
|
| 246 |
+
sub = None
|
| 247 |
+
pos = None
|
| 248 |
+
if as_pos_or_sub == "AS_SUBSTITUTION":
|
| 249 |
+
sub = self.parse_substitution_(reversal)
|
| 250 |
+
elif as_pos_or_sub == "AS_POSITION":
|
| 251 |
+
pos = self.parse_position_()
|
| 252 |
+
else:
|
| 253 |
+
raise VoltLibError(
|
| 254 |
+
"Expected AS_SUBSTITUTION or AS_POSITION. " "Got %s" % (as_pos_or_sub),
|
| 255 |
+
location,
|
| 256 |
+
)
|
| 257 |
+
def_lookup = ast.LookupDefinition(
|
| 258 |
+
name,
|
| 259 |
+
process_base,
|
| 260 |
+
process_marks,
|
| 261 |
+
mark_glyph_set,
|
| 262 |
+
direction,
|
| 263 |
+
reversal,
|
| 264 |
+
comments,
|
| 265 |
+
context,
|
| 266 |
+
sub,
|
| 267 |
+
pos,
|
| 268 |
+
location=location,
|
| 269 |
+
)
|
| 270 |
+
self.lookups_.define(name, def_lookup)
|
| 271 |
+
return def_lookup
|
| 272 |
+
|
| 273 |
+
def parse_context_(self):
|
| 274 |
+
location = self.cur_token_location_
|
| 275 |
+
contexts = []
|
| 276 |
+
while self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"):
|
| 277 |
+
side = None
|
| 278 |
+
coverage = None
|
| 279 |
+
ex_or_in = self.expect_name_()
|
| 280 |
+
# side_contexts = [] # XXX
|
| 281 |
+
if self.next_token_ != "END_CONTEXT":
|
| 282 |
+
left = []
|
| 283 |
+
right = []
|
| 284 |
+
while self.next_token_ in ("LEFT", "RIGHT"):
|
| 285 |
+
side = self.expect_name_()
|
| 286 |
+
coverage = self.parse_coverage_()
|
| 287 |
+
if side == "LEFT":
|
| 288 |
+
left.append(coverage)
|
| 289 |
+
else:
|
| 290 |
+
right.append(coverage)
|
| 291 |
+
self.expect_keyword_("END_CONTEXT")
|
| 292 |
+
context = ast.ContextDefinition(
|
| 293 |
+
ex_or_in, left, right, location=location
|
| 294 |
+
)
|
| 295 |
+
contexts.append(context)
|
| 296 |
+
else:
|
| 297 |
+
self.expect_keyword_("END_CONTEXT")
|
| 298 |
+
return contexts
|
| 299 |
+
|
| 300 |
+
def parse_substitution_(self, reversal):
|
| 301 |
+
assert self.is_cur_keyword_("AS_SUBSTITUTION")
|
| 302 |
+
location = self.cur_token_location_
|
| 303 |
+
src = []
|
| 304 |
+
dest = []
|
| 305 |
+
if self.next_token_ != "SUB":
|
| 306 |
+
raise VoltLibError("Expected SUB", location)
|
| 307 |
+
while self.next_token_ == "SUB":
|
| 308 |
+
self.expect_keyword_("SUB")
|
| 309 |
+
src.append(self.parse_coverage_())
|
| 310 |
+
self.expect_keyword_("WITH")
|
| 311 |
+
dest.append(self.parse_coverage_())
|
| 312 |
+
self.expect_keyword_("END_SUB")
|
| 313 |
+
self.expect_keyword_("END_SUBSTITUTION")
|
| 314 |
+
max_src = max([len(cov) for cov in src])
|
| 315 |
+
max_dest = max([len(cov) for cov in dest])
|
| 316 |
+
|
| 317 |
+
# many to many or mixed is invalid
|
| 318 |
+
if max_src > 1 and max_dest > 1:
|
| 319 |
+
raise VoltLibError("Invalid substitution type", location)
|
| 320 |
+
|
| 321 |
+
mapping = dict(zip(tuple(src), tuple(dest)))
|
| 322 |
+
if max_src == 1 and max_dest == 1:
|
| 323 |
+
# Alternate substitutions are represented by adding multiple
|
| 324 |
+
# substitutions for the same glyph, so we detect that here
|
| 325 |
+
glyphs = [x.glyphSet() for cov in src for x in cov] # flatten src
|
| 326 |
+
if len(set(glyphs)) != len(glyphs): # src has duplicates
|
| 327 |
+
sub = ast.SubstitutionAlternateDefinition(mapping, location=location)
|
| 328 |
+
else:
|
| 329 |
+
if reversal:
|
| 330 |
+
# Reversal is valid only for single glyph substitutions
|
| 331 |
+
# and VOLT ignores it otherwise.
|
| 332 |
+
sub = ast.SubstitutionReverseChainingSingleDefinition(
|
| 333 |
+
mapping, location=location
|
| 334 |
+
)
|
| 335 |
+
else:
|
| 336 |
+
sub = ast.SubstitutionSingleDefinition(mapping, location=location)
|
| 337 |
+
elif max_src == 1 and max_dest > 1:
|
| 338 |
+
sub = ast.SubstitutionMultipleDefinition(mapping, location=location)
|
| 339 |
+
elif max_src > 1 and max_dest == 1:
|
| 340 |
+
sub = ast.SubstitutionLigatureDefinition(mapping, location=location)
|
| 341 |
+
return sub
|
| 342 |
+
|
| 343 |
+
def parse_position_(self):
|
| 344 |
+
assert self.is_cur_keyword_("AS_POSITION")
|
| 345 |
+
location = self.cur_token_location_
|
| 346 |
+
pos_type = self.expect_name_()
|
| 347 |
+
if pos_type not in ("ATTACH", "ATTACH_CURSIVE", "ADJUST_PAIR", "ADJUST_SINGLE"):
|
| 348 |
+
raise VoltLibError(
|
| 349 |
+
"Expected ATTACH, ATTACH_CURSIVE, ADJUST_PAIR, ADJUST_SINGLE", location
|
| 350 |
+
)
|
| 351 |
+
if pos_type == "ATTACH":
|
| 352 |
+
position = self.parse_attach_()
|
| 353 |
+
elif pos_type == "ATTACH_CURSIVE":
|
| 354 |
+
position = self.parse_attach_cursive_()
|
| 355 |
+
elif pos_type == "ADJUST_PAIR":
|
| 356 |
+
position = self.parse_adjust_pair_()
|
| 357 |
+
elif pos_type == "ADJUST_SINGLE":
|
| 358 |
+
position = self.parse_adjust_single_()
|
| 359 |
+
self.expect_keyword_("END_POSITION")
|
| 360 |
+
return position
|
| 361 |
+
|
| 362 |
+
def parse_attach_(self):
|
| 363 |
+
assert self.is_cur_keyword_("ATTACH")
|
| 364 |
+
location = self.cur_token_location_
|
| 365 |
+
coverage = self.parse_coverage_()
|
| 366 |
+
coverage_to = []
|
| 367 |
+
self.expect_keyword_("TO")
|
| 368 |
+
while self.next_token_ != "END_ATTACH":
|
| 369 |
+
cov = self.parse_coverage_()
|
| 370 |
+
self.expect_keyword_("AT")
|
| 371 |
+
self.expect_keyword_("ANCHOR")
|
| 372 |
+
anchor_name = self.expect_string_()
|
| 373 |
+
coverage_to.append((cov, anchor_name))
|
| 374 |
+
self.expect_keyword_("END_ATTACH")
|
| 375 |
+
position = ast.PositionAttachDefinition(
|
| 376 |
+
coverage, coverage_to, location=location
|
| 377 |
+
)
|
| 378 |
+
return position
|
| 379 |
+
|
| 380 |
+
def parse_attach_cursive_(self):
|
| 381 |
+
assert self.is_cur_keyword_("ATTACH_CURSIVE")
|
| 382 |
+
location = self.cur_token_location_
|
| 383 |
+
coverages_exit = []
|
| 384 |
+
coverages_enter = []
|
| 385 |
+
while self.next_token_ != "ENTER":
|
| 386 |
+
self.expect_keyword_("EXIT")
|
| 387 |
+
coverages_exit.append(self.parse_coverage_())
|
| 388 |
+
while self.next_token_ != "END_ATTACH":
|
| 389 |
+
self.expect_keyword_("ENTER")
|
| 390 |
+
coverages_enter.append(self.parse_coverage_())
|
| 391 |
+
self.expect_keyword_("END_ATTACH")
|
| 392 |
+
position = ast.PositionAttachCursiveDefinition(
|
| 393 |
+
coverages_exit, coverages_enter, location=location
|
| 394 |
+
)
|
| 395 |
+
return position
|
| 396 |
+
|
| 397 |
+
def parse_adjust_pair_(self):
|
| 398 |
+
assert self.is_cur_keyword_("ADJUST_PAIR")
|
| 399 |
+
location = self.cur_token_location_
|
| 400 |
+
coverages_1 = []
|
| 401 |
+
coverages_2 = []
|
| 402 |
+
adjust_pair = {}
|
| 403 |
+
while self.next_token_ == "FIRST":
|
| 404 |
+
self.advance_lexer_()
|
| 405 |
+
coverage_1 = self.parse_coverage_()
|
| 406 |
+
coverages_1.append(coverage_1)
|
| 407 |
+
while self.next_token_ == "SECOND":
|
| 408 |
+
self.advance_lexer_()
|
| 409 |
+
coverage_2 = self.parse_coverage_()
|
| 410 |
+
coverages_2.append(coverage_2)
|
| 411 |
+
while self.next_token_ != "END_ADJUST":
|
| 412 |
+
id_1 = self.expect_number_()
|
| 413 |
+
id_2 = self.expect_number_()
|
| 414 |
+
self.expect_keyword_("BY")
|
| 415 |
+
pos_1 = self.parse_pos_()
|
| 416 |
+
pos_2 = self.parse_pos_()
|
| 417 |
+
adjust_pair[(id_1, id_2)] = (pos_1, pos_2)
|
| 418 |
+
self.expect_keyword_("END_ADJUST")
|
| 419 |
+
position = ast.PositionAdjustPairDefinition(
|
| 420 |
+
coverages_1, coverages_2, adjust_pair, location=location
|
| 421 |
+
)
|
| 422 |
+
return position
|
| 423 |
+
|
| 424 |
+
def parse_adjust_single_(self):
|
| 425 |
+
assert self.is_cur_keyword_("ADJUST_SINGLE")
|
| 426 |
+
location = self.cur_token_location_
|
| 427 |
+
adjust_single = []
|
| 428 |
+
while self.next_token_ != "END_ADJUST":
|
| 429 |
+
coverages = self.parse_coverage_()
|
| 430 |
+
self.expect_keyword_("BY")
|
| 431 |
+
pos = self.parse_pos_()
|
| 432 |
+
adjust_single.append((coverages, pos))
|
| 433 |
+
self.expect_keyword_("END_ADJUST")
|
| 434 |
+
position = ast.PositionAdjustSingleDefinition(adjust_single, location=location)
|
| 435 |
+
return position
|
| 436 |
+
|
| 437 |
+
def parse_def_anchor_(self):
|
| 438 |
+
assert self.is_cur_keyword_("DEF_ANCHOR")
|
| 439 |
+
location = self.cur_token_location_
|
| 440 |
+
name = self.expect_string_()
|
| 441 |
+
self.expect_keyword_("ON")
|
| 442 |
+
gid = self.expect_number_()
|
| 443 |
+
self.expect_keyword_("GLYPH")
|
| 444 |
+
glyph_name = self.expect_name_()
|
| 445 |
+
self.expect_keyword_("COMPONENT")
|
| 446 |
+
component = self.expect_number_()
|
| 447 |
+
# check for duplicate anchor names on this glyph
|
| 448 |
+
if glyph_name in self.anchors_:
|
| 449 |
+
anchor = self.anchors_[glyph_name].resolve(name)
|
| 450 |
+
if anchor is not None and anchor.component == component:
|
| 451 |
+
raise VoltLibError(
|
| 452 |
+
'Anchor "%s" already defined, '
|
| 453 |
+
"anchor names are case insensitive" % name,
|
| 454 |
+
location,
|
| 455 |
+
)
|
| 456 |
+
if self.next_token_ == "LOCKED":
|
| 457 |
+
locked = True
|
| 458 |
+
self.advance_lexer_()
|
| 459 |
+
else:
|
| 460 |
+
locked = False
|
| 461 |
+
self.expect_keyword_("AT")
|
| 462 |
+
pos = self.parse_pos_()
|
| 463 |
+
self.expect_keyword_("END_ANCHOR")
|
| 464 |
+
anchor = ast.AnchorDefinition(
|
| 465 |
+
name, gid, glyph_name, component, locked, pos, location=location
|
| 466 |
+
)
|
| 467 |
+
if glyph_name not in self.anchors_:
|
| 468 |
+
self.anchors_[glyph_name] = SymbolTable()
|
| 469 |
+
self.anchors_[glyph_name].define(name, anchor)
|
| 470 |
+
return anchor
|
| 471 |
+
|
| 472 |
+
def parse_adjust_by_(self):
|
| 473 |
+
self.advance_lexer_()
|
| 474 |
+
assert self.is_cur_keyword_("ADJUST_BY")
|
| 475 |
+
adjustment = self.expect_number_()
|
| 476 |
+
self.expect_keyword_("AT")
|
| 477 |
+
size = self.expect_number_()
|
| 478 |
+
return adjustment, size
|
| 479 |
+
|
| 480 |
+
def parse_pos_(self):
|
| 481 |
+
# VOLT syntax doesn't seem to take device Y advance
|
| 482 |
+
self.advance_lexer_()
|
| 483 |
+
location = self.cur_token_location_
|
| 484 |
+
assert self.is_cur_keyword_("POS"), location
|
| 485 |
+
adv = None
|
| 486 |
+
dx = None
|
| 487 |
+
dy = None
|
| 488 |
+
adv_adjust_by = {}
|
| 489 |
+
dx_adjust_by = {}
|
| 490 |
+
dy_adjust_by = {}
|
| 491 |
+
if self.next_token_ == "ADV":
|
| 492 |
+
self.advance_lexer_()
|
| 493 |
+
adv = self.expect_number_()
|
| 494 |
+
while self.next_token_ == "ADJUST_BY":
|
| 495 |
+
adjustment, size = self.parse_adjust_by_()
|
| 496 |
+
adv_adjust_by[size] = adjustment
|
| 497 |
+
if self.next_token_ == "DX":
|
| 498 |
+
self.advance_lexer_()
|
| 499 |
+
dx = self.expect_number_()
|
| 500 |
+
while self.next_token_ == "ADJUST_BY":
|
| 501 |
+
adjustment, size = self.parse_adjust_by_()
|
| 502 |
+
dx_adjust_by[size] = adjustment
|
| 503 |
+
if self.next_token_ == "DY":
|
| 504 |
+
self.advance_lexer_()
|
| 505 |
+
dy = self.expect_number_()
|
| 506 |
+
while self.next_token_ == "ADJUST_BY":
|
| 507 |
+
adjustment, size = self.parse_adjust_by_()
|
| 508 |
+
dy_adjust_by[size] = adjustment
|
| 509 |
+
self.expect_keyword_("END_POS")
|
| 510 |
+
return ast.Pos(adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by)
|
| 511 |
+
|
| 512 |
+
def parse_unicode_values_(self):
|
| 513 |
+
location = self.cur_token_location_
|
| 514 |
+
try:
|
| 515 |
+
unicode_values = self.expect_string_().split(",")
|
| 516 |
+
unicode_values = [int(uni[2:], 16) for uni in unicode_values if uni != ""]
|
| 517 |
+
except ValueError as err:
|
| 518 |
+
raise VoltLibError(str(err), location)
|
| 519 |
+
return unicode_values if unicode_values != [] else None
|
| 520 |
+
|
| 521 |
+
def parse_enum_(self):
|
| 522 |
+
self.expect_keyword_("ENUM")
|
| 523 |
+
location = self.cur_token_location_
|
| 524 |
+
enum = ast.Enum(self.parse_coverage_(), location=location)
|
| 525 |
+
self.expect_keyword_("END_ENUM")
|
| 526 |
+
return enum
|
| 527 |
+
|
| 528 |
+
def parse_coverage_(self):
|
| 529 |
+
coverage = []
|
| 530 |
+
location = self.cur_token_location_
|
| 531 |
+
while self.next_token_ in ("GLYPH", "GROUP", "RANGE", "ENUM"):
|
| 532 |
+
if self.next_token_ == "ENUM":
|
| 533 |
+
enum = self.parse_enum_()
|
| 534 |
+
coverage.append(enum)
|
| 535 |
+
elif self.next_token_ == "GLYPH":
|
| 536 |
+
self.expect_keyword_("GLYPH")
|
| 537 |
+
name = self.expect_string_()
|
| 538 |
+
coverage.append(ast.GlyphName(name, location=location))
|
| 539 |
+
elif self.next_token_ == "GROUP":
|
| 540 |
+
self.expect_keyword_("GROUP")
|
| 541 |
+
name = self.expect_string_()
|
| 542 |
+
coverage.append(ast.GroupName(name, self, location=location))
|
| 543 |
+
elif self.next_token_ == "RANGE":
|
| 544 |
+
self.expect_keyword_("RANGE")
|
| 545 |
+
start = self.expect_string_()
|
| 546 |
+
self.expect_keyword_("TO")
|
| 547 |
+
end = self.expect_string_()
|
| 548 |
+
coverage.append(ast.Range(start, end, self, location=location))
|
| 549 |
+
return tuple(coverage)
|
| 550 |
+
|
| 551 |
+
def resolve_group(self, group_name):
|
| 552 |
+
return self.groups_.resolve(group_name)
|
| 553 |
+
|
| 554 |
+
def glyph_range(self, start, end):
|
| 555 |
+
return self.glyphs_.range(start, end)
|
| 556 |
+
|
| 557 |
+
def parse_ppem_(self):
|
| 558 |
+
location = self.cur_token_location_
|
| 559 |
+
ppem_name = self.cur_token_
|
| 560 |
+
value = self.expect_number_()
|
| 561 |
+
setting = ast.SettingDefinition(ppem_name, value, location=location)
|
| 562 |
+
return setting
|
| 563 |
+
|
| 564 |
+
def parse_noarg_option_(self):
|
| 565 |
+
location = self.cur_token_location_
|
| 566 |
+
name = self.cur_token_
|
| 567 |
+
value = True
|
| 568 |
+
setting = ast.SettingDefinition(name, value, location=location)
|
| 569 |
+
return setting
|
| 570 |
+
|
| 571 |
+
def parse_cmap_format(self):
|
| 572 |
+
location = self.cur_token_location_
|
| 573 |
+
name = self.cur_token_
|
| 574 |
+
value = (self.expect_number_(), self.expect_number_(), self.expect_number_())
|
| 575 |
+
setting = ast.SettingDefinition(name, value, location=location)
|
| 576 |
+
return setting
|
| 577 |
+
|
| 578 |
+
def is_cur_keyword_(self, k):
|
| 579 |
+
return (self.cur_token_type_ is Lexer.NAME) and (self.cur_token_ == k)
|
| 580 |
+
|
| 581 |
+
def expect_string_(self):
|
| 582 |
+
self.advance_lexer_()
|
| 583 |
+
if self.cur_token_type_ is not Lexer.STRING:
|
| 584 |
+
raise VoltLibError("Expected a string", self.cur_token_location_)
|
| 585 |
+
return self.cur_token_
|
| 586 |
+
|
| 587 |
+
def expect_keyword_(self, keyword):
|
| 588 |
+
self.advance_lexer_()
|
| 589 |
+
if self.cur_token_type_ is Lexer.NAME and self.cur_token_ == keyword:
|
| 590 |
+
return self.cur_token_
|
| 591 |
+
raise VoltLibError('Expected "%s"' % keyword, self.cur_token_location_)
|
| 592 |
+
|
| 593 |
+
def expect_name_(self):
|
| 594 |
+
self.advance_lexer_()
|
| 595 |
+
if self.cur_token_type_ is Lexer.NAME:
|
| 596 |
+
return self.cur_token_
|
| 597 |
+
raise VoltLibError("Expected a name", self.cur_token_location_)
|
| 598 |
+
|
| 599 |
+
def expect_number_(self):
|
| 600 |
+
self.advance_lexer_()
|
| 601 |
+
if self.cur_token_type_ is not Lexer.NUMBER:
|
| 602 |
+
raise VoltLibError("Expected a number", self.cur_token_location_)
|
| 603 |
+
return self.cur_token_
|
| 604 |
+
|
| 605 |
+
def advance_lexer_(self):
|
| 606 |
+
self.cur_token_type_, self.cur_token_, self.cur_token_location_ = (
|
| 607 |
+
self.next_token_type_,
|
| 608 |
+
self.next_token_,
|
| 609 |
+
self.next_token_location_,
|
| 610 |
+
)
|
| 611 |
+
try:
|
| 612 |
+
if self.is_cur_keyword_("END"):
|
| 613 |
+
raise StopIteration
|
| 614 |
+
(
|
| 615 |
+
self.next_token_type_,
|
| 616 |
+
self.next_token_,
|
| 617 |
+
self.next_token_location_,
|
| 618 |
+
) = self.lexer_.next()
|
| 619 |
+
except StopIteration:
|
| 620 |
+
self.next_token_type_, self.next_token_ = (None, None)
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
class SymbolTable(object):
|
| 624 |
+
def __init__(self):
|
| 625 |
+
self.scopes_ = [{}]
|
| 626 |
+
|
| 627 |
+
def enter_scope(self):
|
| 628 |
+
self.scopes_.append({})
|
| 629 |
+
|
| 630 |
+
def exit_scope(self):
|
| 631 |
+
self.scopes_.pop()
|
| 632 |
+
|
| 633 |
+
def define(self, name, item):
|
| 634 |
+
self.scopes_[-1][name] = item
|
| 635 |
+
|
| 636 |
+
def resolve(self, name, case_insensitive=True):
|
| 637 |
+
for scope in reversed(self.scopes_):
|
| 638 |
+
item = scope.get(name)
|
| 639 |
+
if item:
|
| 640 |
+
return item
|
| 641 |
+
if case_insensitive:
|
| 642 |
+
for key in scope:
|
| 643 |
+
if key.lower() == name.lower():
|
| 644 |
+
return scope[key]
|
| 645 |
+
return None
|
| 646 |
+
|
| 647 |
+
|
| 648 |
+
class OrderedSymbolTable(SymbolTable):
|
| 649 |
+
def __init__(self):
|
| 650 |
+
self.scopes_ = [{}]
|
| 651 |
+
|
| 652 |
+
def enter_scope(self):
|
| 653 |
+
self.scopes_.append({})
|
| 654 |
+
|
| 655 |
+
def resolve(self, name, case_insensitive=False):
|
| 656 |
+
SymbolTable.resolve(self, name, case_insensitive=case_insensitive)
|
| 657 |
+
|
| 658 |
+
def range(self, start, end):
|
| 659 |
+
for scope in reversed(self.scopes_):
|
| 660 |
+
if start in scope and end in scope:
|
| 661 |
+
start_idx = list(scope.keys()).index(start)
|
| 662 |
+
end_idx = list(scope.keys()).index(end)
|
| 663 |
+
return list(scope.keys())[start_idx : end_idx + 1]
|
| 664 |
+
return None
|
workspace/output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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""\
|
| 2 |
+
MS VOLT ``.vtp`` to AFDKO ``.fea`` OpenType Layout converter.
|
| 3 |
+
|
| 4 |
+
Usage
|
| 5 |
+
-----
|
| 6 |
+
|
| 7 |
+
To convert a VTP project file:
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
.. code-block:: sh
|
| 11 |
+
|
| 12 |
+
$ fonttools voltLib.voltToFea input.vtp output.fea
|
| 13 |
+
|
| 14 |
+
It is also possible convert font files with `TSIV` table (as saved from Volt),
|
| 15 |
+
in this case the glyph names used in the Volt project will be mapped to the
|
| 16 |
+
actual glyph names in the font files when written to the feature file:
|
| 17 |
+
|
| 18 |
+
.. code-block:: sh
|
| 19 |
+
|
| 20 |
+
$ fonttools voltLib.voltToFea input.ttf output.fea
|
| 21 |
+
|
| 22 |
+
The ``--quiet`` option can be used to suppress warnings.
|
| 23 |
+
|
| 24 |
+
The ``--traceback`` can be used to get Python traceback in case of exceptions,
|
| 25 |
+
instead of suppressing the traceback.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Limitations
|
| 29 |
+
-----------
|
| 30 |
+
|
| 31 |
+
* Not all VOLT features are supported, the script will error if it it
|
| 32 |
+
encounters something it does not understand. Please report an issue if this
|
| 33 |
+
happens.
|
| 34 |
+
* AFDKO feature file syntax for mark positioning is awkward and does not allow
|
| 35 |
+
setting the mark coverage. It also defines mark anchors globally, as a result
|
| 36 |
+
some mark positioning lookups might cover many marks than what was in the VOLT
|
| 37 |
+
file. This should not be an issue in practice, but if it is then the only way
|
| 38 |
+
is to modify the VOLT file or the generated feature file manually to use unique
|
| 39 |
+
mark anchors for each lookup.
|
| 40 |
+
* VOLT allows subtable breaks in any lookup type, but AFDKO feature file
|
| 41 |
+
implementations vary in their support; currently AFDKO’s makeOTF supports
|
| 42 |
+
subtable breaks in pair positioning lookups only, while FontTools’ feaLib
|
| 43 |
+
support it for most substitution lookups and only some positioning lookups.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
import logging
|
| 47 |
+
import re
|
| 48 |
+
from io import StringIO
|
| 49 |
+
from graphlib import TopologicalSorter
|
| 50 |
+
|
| 51 |
+
from fontTools.feaLib import ast
|
| 52 |
+
from fontTools.ttLib import TTFont, TTLibError
|
| 53 |
+
from fontTools.voltLib import ast as VAst
|
| 54 |
+
from fontTools.voltLib.parser import Parser as VoltParser
|
| 55 |
+
|
| 56 |
+
log = logging.getLogger("fontTools.voltLib.voltToFea")
|
| 57 |
+
|
| 58 |
+
TABLES = ["GDEF", "GSUB", "GPOS"]
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _flatten_group(group):
|
| 62 |
+
ret = []
|
| 63 |
+
if isinstance(group, (tuple, list)):
|
| 64 |
+
for item in group:
|
| 65 |
+
ret.extend(_flatten_group(item))
|
| 66 |
+
elif hasattr(group, "enum"):
|
| 67 |
+
ret.extend(_flatten_group(group.enum))
|
| 68 |
+
else:
|
| 69 |
+
ret.append(group)
|
| 70 |
+
return ret
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# Topologically sort of group definitions to ensure that all groups are defined
|
| 74 |
+
# before they are referenced. This is necessary because FEA requires it but
|
| 75 |
+
# VOLT does not, see below.
|
| 76 |
+
def sort_groups(groups):
|
| 77 |
+
group_map = {group.name.lower(): group for group in groups}
|
| 78 |
+
graph = {
|
| 79 |
+
group.name.lower(): [
|
| 80 |
+
x.group.lower()
|
| 81 |
+
for x in _flatten_group(group)
|
| 82 |
+
if isinstance(x, VAst.GroupName)
|
| 83 |
+
]
|
| 84 |
+
for group in groups
|
| 85 |
+
}
|
| 86 |
+
sorter = TopologicalSorter(graph)
|
| 87 |
+
return [group_map[name] for name in sorter.static_order()]
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class Lookup(ast.LookupBlock):
|
| 91 |
+
def __init__(self, name, use_extension=False, location=None):
|
| 92 |
+
super().__init__(name, use_extension, location)
|
| 93 |
+
self.chained = []
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class VoltToFea:
|
| 97 |
+
_NOT_LOOKUP_NAME_RE = re.compile(r"[^A-Za-z_0-9.]")
|
| 98 |
+
_NOT_CLASS_NAME_RE = re.compile(r"[^A-Za-z_0-9.\-]")
|
| 99 |
+
|
| 100 |
+
def __init__(self, file_or_path, font=None):
|
| 101 |
+
if isinstance(file_or_path, VAst.VoltFile):
|
| 102 |
+
self._doc, self._file_or_path = file_or_path, None
|
| 103 |
+
else:
|
| 104 |
+
self._doc, self._file_or_path = None, file_or_path
|
| 105 |
+
self._font = font
|
| 106 |
+
|
| 107 |
+
self._glyph_map = {}
|
| 108 |
+
self._glyph_order = None
|
| 109 |
+
|
| 110 |
+
self._gdef = {}
|
| 111 |
+
self._glyphclasses = {}
|
| 112 |
+
self._features = {}
|
| 113 |
+
self._lookups = {}
|
| 114 |
+
|
| 115 |
+
self._marks = set()
|
| 116 |
+
self._ligatures = {}
|
| 117 |
+
|
| 118 |
+
self._markclasses = {}
|
| 119 |
+
self._anchors = {}
|
| 120 |
+
|
| 121 |
+
self._settings = {}
|
| 122 |
+
|
| 123 |
+
self._lookup_names = {}
|
| 124 |
+
self._class_names = {}
|
| 125 |
+
|
| 126 |
+
def _lookupName(self, name):
|
| 127 |
+
if name not in self._lookup_names:
|
| 128 |
+
res = self._NOT_LOOKUP_NAME_RE.sub("_", name)
|
| 129 |
+
while res in self._lookup_names.values():
|
| 130 |
+
res += "_"
|
| 131 |
+
self._lookup_names[name] = res
|
| 132 |
+
return self._lookup_names[name]
|
| 133 |
+
|
| 134 |
+
def _className(self, name):
|
| 135 |
+
if name not in self._class_names:
|
| 136 |
+
res = self._NOT_CLASS_NAME_RE.sub("_", name)
|
| 137 |
+
while res in self._class_names.values():
|
| 138 |
+
res += "_"
|
| 139 |
+
self._class_names[name] = res
|
| 140 |
+
return self._class_names[name]
|
| 141 |
+
|
| 142 |
+
def _collectStatements(self, doc, tables, ignore_unsupported_settings=False):
|
| 143 |
+
# Collect glyph difinitions first, as we need them to map VOLT glyph names to font glyph name.
|
| 144 |
+
for statement in doc.statements:
|
| 145 |
+
if isinstance(statement, VAst.GlyphDefinition):
|
| 146 |
+
self._glyphDefinition(statement)
|
| 147 |
+
|
| 148 |
+
# Collect and sort group definitions first, to make sure a group
|
| 149 |
+
# definition that references other groups comes after them since VOLT
|
| 150 |
+
# does not enforce such ordering, and feature file require it.
|
| 151 |
+
groups = [s for s in doc.statements if isinstance(s, VAst.GroupDefinition)]
|
| 152 |
+
for group in sort_groups(groups):
|
| 153 |
+
self._groupDefinition(group)
|
| 154 |
+
|
| 155 |
+
for statement in doc.statements:
|
| 156 |
+
if isinstance(statement, VAst.AnchorDefinition):
|
| 157 |
+
if "GPOS" in tables:
|
| 158 |
+
self._anchorDefinition(statement)
|
| 159 |
+
elif isinstance(statement, VAst.SettingDefinition):
|
| 160 |
+
self._settingDefinition(statement, ignore_unsupported_settings)
|
| 161 |
+
elif isinstance(statement, (VAst.GlyphDefinition, VAst.GroupDefinition)):
|
| 162 |
+
pass # Handled above
|
| 163 |
+
elif isinstance(statement, VAst.ScriptDefinition):
|
| 164 |
+
self._scriptDefinition(statement)
|
| 165 |
+
elif not isinstance(statement, VAst.LookupDefinition):
|
| 166 |
+
raise NotImplementedError(statement)
|
| 167 |
+
|
| 168 |
+
# Lookup definitions need to be handled last as they reference glyph
|
| 169 |
+
# and mark classes that might be defined after them.
|
| 170 |
+
for statement in doc.statements:
|
| 171 |
+
if isinstance(statement, VAst.LookupDefinition):
|
| 172 |
+
if statement.pos and "GPOS" not in tables:
|
| 173 |
+
continue
|
| 174 |
+
if statement.sub and "GSUB" not in tables:
|
| 175 |
+
continue
|
| 176 |
+
self._lookupDefinition(statement)
|
| 177 |
+
|
| 178 |
+
def _buildFeatureFile(self, tables):
|
| 179 |
+
doc = ast.FeatureFile()
|
| 180 |
+
statements = doc.statements
|
| 181 |
+
|
| 182 |
+
if self._glyphclasses:
|
| 183 |
+
statements.append(ast.Comment("# Glyph classes"))
|
| 184 |
+
statements.extend(self._glyphclasses.values())
|
| 185 |
+
|
| 186 |
+
if self._markclasses:
|
| 187 |
+
statements.append(ast.Comment("\n# Mark classes"))
|
| 188 |
+
statements.extend(c[1] for c in sorted(self._markclasses.items()))
|
| 189 |
+
|
| 190 |
+
if self._lookups:
|
| 191 |
+
statements.append(ast.Comment("\n# Lookups"))
|
| 192 |
+
for lookup in self._lookups.values():
|
| 193 |
+
statements.extend(lookup.chained)
|
| 194 |
+
statements.append(lookup)
|
| 195 |
+
|
| 196 |
+
# Prune features
|
| 197 |
+
features = self._features.copy()
|
| 198 |
+
for feature_tag in features:
|
| 199 |
+
scripts = features[feature_tag]
|
| 200 |
+
for script_tag in scripts:
|
| 201 |
+
langs = scripts[script_tag]
|
| 202 |
+
for language_tag in langs:
|
| 203 |
+
langs[language_tag] = [
|
| 204 |
+
l for l in langs[language_tag] if l.lower() in self._lookups
|
| 205 |
+
]
|
| 206 |
+
scripts[script_tag] = {t: l for t, l in langs.items() if l}
|
| 207 |
+
features[feature_tag] = {t: s for t, s in scripts.items() if s}
|
| 208 |
+
features = {t: f for t, f in features.items() if f}
|
| 209 |
+
|
| 210 |
+
if features:
|
| 211 |
+
statements.append(ast.Comment("# Features"))
|
| 212 |
+
for feature_tag, scripts in features.items():
|
| 213 |
+
feature = ast.FeatureBlock(feature_tag)
|
| 214 |
+
script_tags = sorted(scripts, key=lambda k: 0 if k == "DFLT" else 1)
|
| 215 |
+
if feature_tag == "aalt" and len(script_tags) > 1:
|
| 216 |
+
log.warning(
|
| 217 |
+
"FEA syntax does not allow script statements in 'aalt' feature, "
|
| 218 |
+
"so only lookups from the first script will be included."
|
| 219 |
+
)
|
| 220 |
+
script_tags = script_tags[:1]
|
| 221 |
+
for script_tag in script_tags:
|
| 222 |
+
if feature_tag != "aalt":
|
| 223 |
+
feature.statements.append(ast.ScriptStatement(script_tag))
|
| 224 |
+
language_tags = sorted(
|
| 225 |
+
scripts[script_tag],
|
| 226 |
+
key=lambda k: 0 if k == "dflt" else 1,
|
| 227 |
+
)
|
| 228 |
+
if feature_tag == "aalt" and len(language_tags) > 1:
|
| 229 |
+
log.warning(
|
| 230 |
+
"FEA syntax does not allow language statements in 'aalt' feature, "
|
| 231 |
+
"so only lookups from the first language will be included."
|
| 232 |
+
)
|
| 233 |
+
language_tags = language_tags[:1]
|
| 234 |
+
for language_tag in language_tags:
|
| 235 |
+
if feature_tag != "aalt":
|
| 236 |
+
include_default = True if language_tag == "dflt" else False
|
| 237 |
+
feature.statements.append(
|
| 238 |
+
ast.LanguageStatement(
|
| 239 |
+
language_tag.ljust(4),
|
| 240 |
+
include_default=include_default,
|
| 241 |
+
)
|
| 242 |
+
)
|
| 243 |
+
for name in scripts[script_tag][language_tag]:
|
| 244 |
+
lookup = self._lookups[name.lower()]
|
| 245 |
+
lookupref = ast.LookupReferenceStatement(lookup)
|
| 246 |
+
feature.statements.append(lookupref)
|
| 247 |
+
statements.append(feature)
|
| 248 |
+
|
| 249 |
+
if self._gdef and "GDEF" in tables:
|
| 250 |
+
classes = []
|
| 251 |
+
for name in ("BASE", "MARK", "LIGATURE", "COMPONENT"):
|
| 252 |
+
if name in self._gdef:
|
| 253 |
+
classname = "GDEF_" + name.lower()
|
| 254 |
+
glyphclass = ast.GlyphClassDefinition(classname, self._gdef[name])
|
| 255 |
+
statements.append(glyphclass)
|
| 256 |
+
classes.append(ast.GlyphClassName(glyphclass))
|
| 257 |
+
else:
|
| 258 |
+
classes.append(None)
|
| 259 |
+
|
| 260 |
+
gdef = ast.TableBlock("GDEF")
|
| 261 |
+
gdef.statements.append(ast.GlyphClassDefStatement(*classes))
|
| 262 |
+
statements.append(gdef)
|
| 263 |
+
|
| 264 |
+
return doc
|
| 265 |
+
|
| 266 |
+
def convert(self, tables=None, ignore_unsupported_settings=False):
|
| 267 |
+
if self._doc is None:
|
| 268 |
+
self._doc = VoltParser(self._file_or_path).parse()
|
| 269 |
+
doc = self._doc
|
| 270 |
+
|
| 271 |
+
if tables is None:
|
| 272 |
+
tables = TABLES
|
| 273 |
+
if self._font is not None:
|
| 274 |
+
self._glyph_order = self._font.getGlyphOrder()
|
| 275 |
+
|
| 276 |
+
self._collectStatements(doc, tables, ignore_unsupported_settings)
|
| 277 |
+
fea = self._buildFeatureFile(tables)
|
| 278 |
+
return fea.asFea()
|
| 279 |
+
|
| 280 |
+
def _glyphName(self, glyph):
|
| 281 |
+
try:
|
| 282 |
+
name = glyph.glyph
|
| 283 |
+
except AttributeError:
|
| 284 |
+
name = glyph
|
| 285 |
+
return ast.GlyphName(self._glyph_map.get(name, name))
|
| 286 |
+
|
| 287 |
+
def _groupName(self, group):
|
| 288 |
+
try:
|
| 289 |
+
name = group.group
|
| 290 |
+
except AttributeError:
|
| 291 |
+
name = group
|
| 292 |
+
return ast.GlyphClassName(self._glyphclasses[name.lower()])
|
| 293 |
+
|
| 294 |
+
def _glyphSet(self, item):
|
| 295 |
+
return [
|
| 296 |
+
(self._glyphName(x) if isinstance(x, (str, VAst.GlyphName)) else x)
|
| 297 |
+
for x in item.glyphSet()
|
| 298 |
+
]
|
| 299 |
+
|
| 300 |
+
def _coverage(self, coverage, flatten=False):
|
| 301 |
+
items = []
|
| 302 |
+
for item in coverage:
|
| 303 |
+
if isinstance(item, VAst.GlyphName):
|
| 304 |
+
items.append(self._glyphName(item))
|
| 305 |
+
elif isinstance(item, VAst.GroupName):
|
| 306 |
+
items.append(self._groupName(item))
|
| 307 |
+
elif isinstance(item, VAst.Enum):
|
| 308 |
+
item = self._coverage(item.enum, flatten=True)
|
| 309 |
+
if flatten:
|
| 310 |
+
items.extend(item)
|
| 311 |
+
else:
|
| 312 |
+
items.append(ast.GlyphClass(item))
|
| 313 |
+
elif isinstance(item, VAst.Range):
|
| 314 |
+
item = self._glyphSet(item)
|
| 315 |
+
if flatten:
|
| 316 |
+
items.extend(item)
|
| 317 |
+
else:
|
| 318 |
+
items.append(ast.GlyphClass(item))
|
| 319 |
+
else:
|
| 320 |
+
raise NotImplementedError(item)
|
| 321 |
+
return items
|
| 322 |
+
|
| 323 |
+
def _context(self, context):
|
| 324 |
+
out = []
|
| 325 |
+
for item in context:
|
| 326 |
+
coverage = self._coverage(item, flatten=True)
|
| 327 |
+
if len(coverage) > 1:
|
| 328 |
+
coverage = ast.GlyphClass(coverage)
|
| 329 |
+
else:
|
| 330 |
+
coverage = coverage[0]
|
| 331 |
+
out.append(coverage)
|
| 332 |
+
return out
|
| 333 |
+
|
| 334 |
+
def _groupDefinition(self, group):
|
| 335 |
+
name = self._className(group.name)
|
| 336 |
+
glyphs = self._coverage(group.enum.enum, flatten=True)
|
| 337 |
+
glyphclass = ast.GlyphClass(glyphs)
|
| 338 |
+
classdef = ast.GlyphClassDefinition(name, glyphclass)
|
| 339 |
+
self._glyphclasses[group.name.lower()] = classdef
|
| 340 |
+
|
| 341 |
+
def _glyphDefinition(self, glyph):
|
| 342 |
+
try:
|
| 343 |
+
self._glyph_map[glyph.name] = self._glyph_order[glyph.id]
|
| 344 |
+
except TypeError:
|
| 345 |
+
pass
|
| 346 |
+
|
| 347 |
+
if glyph.type in ("BASE", "MARK", "LIGATURE", "COMPONENT"):
|
| 348 |
+
if glyph.type not in self._gdef:
|
| 349 |
+
self._gdef[glyph.type] = ast.GlyphClass()
|
| 350 |
+
self._gdef[glyph.type].glyphs.append(self._glyphName(glyph.name))
|
| 351 |
+
|
| 352 |
+
if glyph.type == "MARK":
|
| 353 |
+
self._marks.add(glyph.name)
|
| 354 |
+
elif glyph.type == "LIGATURE":
|
| 355 |
+
self._ligatures[glyph.name] = glyph.components
|
| 356 |
+
|
| 357 |
+
def _scriptDefinition(self, script):
|
| 358 |
+
stag = script.tag
|
| 359 |
+
for lang in script.langs:
|
| 360 |
+
ltag = lang.tag
|
| 361 |
+
for feature in lang.features:
|
| 362 |
+
lookups = {l.split("\\")[0]: True for l in feature.lookups}
|
| 363 |
+
ftag = feature.tag
|
| 364 |
+
if ftag not in self._features:
|
| 365 |
+
self._features[ftag] = {}
|
| 366 |
+
if stag not in self._features[ftag]:
|
| 367 |
+
self._features[ftag][stag] = {}
|
| 368 |
+
assert ltag not in self._features[ftag][stag]
|
| 369 |
+
self._features[ftag][stag][ltag] = lookups.keys()
|
| 370 |
+
|
| 371 |
+
def _settingDefinition(self, setting, ignore_unsupported=False):
|
| 372 |
+
if setting.name.startswith("COMPILER_"):
|
| 373 |
+
self._settings[setting.name] = setting.value
|
| 374 |
+
elif not ignore_unsupported:
|
| 375 |
+
log.warning(f"Unsupported setting ignored: {setting.name}")
|
| 376 |
+
|
| 377 |
+
def _adjustment(self, adjustment):
|
| 378 |
+
adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = adjustment
|
| 379 |
+
|
| 380 |
+
adv_device = adv_adjust_by and adv_adjust_by.items() or None
|
| 381 |
+
dx_device = dx_adjust_by and dx_adjust_by.items() or None
|
| 382 |
+
dy_device = dy_adjust_by and dy_adjust_by.items() or None
|
| 383 |
+
|
| 384 |
+
return ast.ValueRecord(
|
| 385 |
+
xPlacement=dx,
|
| 386 |
+
yPlacement=dy,
|
| 387 |
+
xAdvance=adv,
|
| 388 |
+
xPlaDevice=dx_device,
|
| 389 |
+
yPlaDevice=dy_device,
|
| 390 |
+
xAdvDevice=adv_device,
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
def _anchor(self, adjustment):
|
| 394 |
+
adv, dx, dy, adv_adjust_by, dx_adjust_by, dy_adjust_by = adjustment
|
| 395 |
+
|
| 396 |
+
assert not adv_adjust_by
|
| 397 |
+
dx_device = dx_adjust_by and dx_adjust_by.items() or None
|
| 398 |
+
dy_device = dy_adjust_by and dy_adjust_by.items() or None
|
| 399 |
+
|
| 400 |
+
return ast.Anchor(
|
| 401 |
+
dx or 0,
|
| 402 |
+
dy or 0,
|
| 403 |
+
xDeviceTable=dx_device or None,
|
| 404 |
+
yDeviceTable=dy_device or None,
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
def _anchorDefinition(self, anchordef):
|
| 408 |
+
anchorname = anchordef.name
|
| 409 |
+
glyphname = anchordef.glyph_name
|
| 410 |
+
anchor = self._anchor(anchordef.pos)
|
| 411 |
+
|
| 412 |
+
if glyphname not in self._anchors:
|
| 413 |
+
self._anchors[glyphname] = {}
|
| 414 |
+
if anchorname.startswith("MARK_"):
|
| 415 |
+
anchorname = anchorname[:5] + anchorname[5:].lower()
|
| 416 |
+
else:
|
| 417 |
+
anchorname = anchorname.lower()
|
| 418 |
+
if anchorname not in self._anchors[glyphname]:
|
| 419 |
+
self._anchors[glyphname][anchorname] = {}
|
| 420 |
+
self._anchors[glyphname][anchorname][anchordef.component] = anchor
|
| 421 |
+
|
| 422 |
+
def _gposLookup(self, lookup, fealookup):
|
| 423 |
+
statements = fealookup.statements
|
| 424 |
+
|
| 425 |
+
pos = lookup.pos
|
| 426 |
+
if isinstance(pos, VAst.PositionAdjustPairDefinition):
|
| 427 |
+
for (idx1, idx2), (pos1, pos2) in pos.adjust_pair.items():
|
| 428 |
+
coverage_1 = pos.coverages_1[idx1 - 1]
|
| 429 |
+
coverage_2 = pos.coverages_2[idx2 - 1]
|
| 430 |
+
|
| 431 |
+
# If not both are groups, use “enum pos” otherwise makeotf will
|
| 432 |
+
# fail.
|
| 433 |
+
enumerated = False
|
| 434 |
+
for item in coverage_1 + coverage_2:
|
| 435 |
+
if not isinstance(item, VAst.GroupName):
|
| 436 |
+
enumerated = True
|
| 437 |
+
|
| 438 |
+
glyphs1 = self._coverage(coverage_1)
|
| 439 |
+
glyphs2 = self._coverage(coverage_2)
|
| 440 |
+
record1 = self._adjustment(pos1)
|
| 441 |
+
record2 = self._adjustment(pos2)
|
| 442 |
+
assert len(glyphs1) == 1
|
| 443 |
+
assert len(glyphs2) == 1
|
| 444 |
+
statements.append(
|
| 445 |
+
ast.PairPosStatement(
|
| 446 |
+
glyphs1[0], record1, glyphs2[0], record2, enumerated=enumerated
|
| 447 |
+
)
|
| 448 |
+
)
|
| 449 |
+
elif isinstance(pos, VAst.PositionAdjustSingleDefinition):
|
| 450 |
+
for a, b in pos.adjust_single:
|
| 451 |
+
glyphs = self._coverage(a)
|
| 452 |
+
record = self._adjustment(b)
|
| 453 |
+
assert len(glyphs) == 1
|
| 454 |
+
statements.append(
|
| 455 |
+
ast.SinglePosStatement([(glyphs[0], record)], [], [], False)
|
| 456 |
+
)
|
| 457 |
+
elif isinstance(pos, VAst.PositionAttachDefinition):
|
| 458 |
+
anchors = {}
|
| 459 |
+
allmarks = set()
|
| 460 |
+
for coverage, anchorname in pos.coverage_to:
|
| 461 |
+
# In feature files mark classes are global, but in VOLT they
|
| 462 |
+
# are defined per-lookup. If we output mark class definitions
|
| 463 |
+
# for all marks that use a given anchor, we might end up with a
|
| 464 |
+
# mark used in two different classes in the same lookup, which
|
| 465 |
+
# is causes feature file compilation error.
|
| 466 |
+
# At the expense of uglier feature code, we make the mark class
|
| 467 |
+
# name by appending the current lookup name not the anchor
|
| 468 |
+
# name, and output mark class definitions only for marks used
|
| 469 |
+
# in this lookup.
|
| 470 |
+
classname = self._className(f"{anchorname}.{lookup.name}")
|
| 471 |
+
markclass = ast.MarkClass(classname)
|
| 472 |
+
|
| 473 |
+
# Anchor names are case-insensitive in VOLT
|
| 474 |
+
anchorname = anchorname.lower()
|
| 475 |
+
|
| 476 |
+
# We might still end in marks used in two different anchor
|
| 477 |
+
# classes, so we filter out already used marks.
|
| 478 |
+
marks = set()
|
| 479 |
+
for mark in coverage:
|
| 480 |
+
marks.update(mark.glyphSet())
|
| 481 |
+
if not marks.isdisjoint(allmarks):
|
| 482 |
+
marks.difference_update(allmarks)
|
| 483 |
+
if not marks:
|
| 484 |
+
continue
|
| 485 |
+
allmarks.update(marks)
|
| 486 |
+
|
| 487 |
+
for glyphname in marks:
|
| 488 |
+
glyph = self._glyphName(glyphname)
|
| 489 |
+
anchor = self._anchors[glyphname][f"MARK_{anchorname}"][1]
|
| 490 |
+
markdef = ast.MarkClassDefinition(markclass, anchor, glyph)
|
| 491 |
+
self._markclasses[(glyphname, classname)] = markdef
|
| 492 |
+
|
| 493 |
+
for base in pos.coverage:
|
| 494 |
+
for name in base.glyphSet():
|
| 495 |
+
if name not in anchors:
|
| 496 |
+
anchors[name] = []
|
| 497 |
+
if (anchorname, classname) not in anchors[name]:
|
| 498 |
+
anchors[name].append((anchorname, classname))
|
| 499 |
+
|
| 500 |
+
is_ligature = all(n in self._ligatures for n in anchors)
|
| 501 |
+
is_mark = all(n in self._marks for n in anchors)
|
| 502 |
+
for name in anchors:
|
| 503 |
+
components = 1
|
| 504 |
+
if is_ligature:
|
| 505 |
+
components = self._ligatures[name]
|
| 506 |
+
|
| 507 |
+
marks = [[] for _ in range(components)]
|
| 508 |
+
for mark, classname in anchors[name]:
|
| 509 |
+
markclass = ast.MarkClass(classname)
|
| 510 |
+
for component in range(1, components + 1):
|
| 511 |
+
if component in self._anchors[name][mark]:
|
| 512 |
+
anchor = self._anchors[name][mark][component]
|
| 513 |
+
marks[component - 1].append((anchor, markclass))
|
| 514 |
+
|
| 515 |
+
base = self._glyphName(name)
|
| 516 |
+
if is_mark:
|
| 517 |
+
mark = ast.MarkMarkPosStatement(base, marks[0])
|
| 518 |
+
elif is_ligature:
|
| 519 |
+
mark = ast.MarkLigPosStatement(base, marks)
|
| 520 |
+
else:
|
| 521 |
+
mark = ast.MarkBasePosStatement(base, marks[0])
|
| 522 |
+
statements.append(mark)
|
| 523 |
+
elif isinstance(pos, VAst.PositionAttachCursiveDefinition):
|
| 524 |
+
# Collect enter and exit glyphs
|
| 525 |
+
enter_coverage = []
|
| 526 |
+
for coverage in pos.coverages_enter:
|
| 527 |
+
for base in coverage:
|
| 528 |
+
for name in base.glyphSet():
|
| 529 |
+
enter_coverage.append(name)
|
| 530 |
+
exit_coverage = []
|
| 531 |
+
for coverage in pos.coverages_exit:
|
| 532 |
+
for base in coverage:
|
| 533 |
+
for name in base.glyphSet():
|
| 534 |
+
exit_coverage.append(name)
|
| 535 |
+
|
| 536 |
+
# Write enter anchors, also check if the glyph has exit anchor and
|
| 537 |
+
# write it, too.
|
| 538 |
+
for name in enter_coverage:
|
| 539 |
+
glyph = self._glyphName(name)
|
| 540 |
+
entry = self._anchors[name]["entry"][1]
|
| 541 |
+
exit = None
|
| 542 |
+
if name in exit_coverage:
|
| 543 |
+
exit = self._anchors[name]["exit"][1]
|
| 544 |
+
exit_coverage.pop(exit_coverage.index(name))
|
| 545 |
+
statements.append(ast.CursivePosStatement(glyph, entry, exit))
|
| 546 |
+
|
| 547 |
+
# Write any remaining exit anchors.
|
| 548 |
+
for name in exit_coverage:
|
| 549 |
+
glyph = self._glyphName(name)
|
| 550 |
+
exit = self._anchors[name]["exit"][1]
|
| 551 |
+
statements.append(ast.CursivePosStatement(glyph, None, exit))
|
| 552 |
+
else:
|
| 553 |
+
raise NotImplementedError(pos)
|
| 554 |
+
|
| 555 |
+
def _gposContextLookup(self, lookup, prefix, suffix, ignore, fealookup, chained):
|
| 556 |
+
statements = fealookup.statements
|
| 557 |
+
|
| 558 |
+
pos = lookup.pos
|
| 559 |
+
if isinstance(pos, VAst.PositionAdjustPairDefinition):
|
| 560 |
+
for (idx1, idx2), (pos1, pos2) in pos.adjust_pair.items():
|
| 561 |
+
glyphs1 = self._coverage(pos.coverages_1[idx1 - 1])
|
| 562 |
+
glyphs2 = self._coverage(pos.coverages_2[idx2 - 1])
|
| 563 |
+
assert len(glyphs1) == 1
|
| 564 |
+
assert len(glyphs2) == 1
|
| 565 |
+
glyphs = (glyphs1[0], glyphs2[0])
|
| 566 |
+
|
| 567 |
+
if ignore:
|
| 568 |
+
statement = ast.IgnorePosStatement([(prefix, glyphs, suffix)])
|
| 569 |
+
else:
|
| 570 |
+
statement = ast.ChainContextPosStatement(
|
| 571 |
+
prefix, glyphs, suffix, [chained, chained]
|
| 572 |
+
)
|
| 573 |
+
statements.append(statement)
|
| 574 |
+
elif isinstance(pos, VAst.PositionAdjustSingleDefinition):
|
| 575 |
+
glyphs = [ast.GlyphClass()]
|
| 576 |
+
for a, _ in pos.adjust_single:
|
| 577 |
+
glyphs[0].extend(self._coverage(a, flatten=True))
|
| 578 |
+
|
| 579 |
+
if ignore:
|
| 580 |
+
statement = ast.IgnorePosStatement([(prefix, glyphs, suffix)])
|
| 581 |
+
else:
|
| 582 |
+
statement = ast.ChainContextPosStatement(
|
| 583 |
+
prefix, glyphs, suffix, [chained]
|
| 584 |
+
)
|
| 585 |
+
statements.append(statement)
|
| 586 |
+
elif isinstance(pos, VAst.PositionAttachDefinition):
|
| 587 |
+
glyphs = [ast.GlyphClass()]
|
| 588 |
+
for coverage, _ in pos.coverage_to:
|
| 589 |
+
glyphs[0].extend(self._coverage(coverage, flatten=True))
|
| 590 |
+
|
| 591 |
+
if ignore:
|
| 592 |
+
statement = ast.IgnorePosStatement([(prefix, glyphs, suffix)])
|
| 593 |
+
else:
|
| 594 |
+
statement = ast.ChainContextPosStatement(
|
| 595 |
+
prefix, glyphs, suffix, [chained]
|
| 596 |
+
)
|
| 597 |
+
statements.append(statement)
|
| 598 |
+
else:
|
| 599 |
+
raise NotImplementedError(pos)
|
| 600 |
+
|
| 601 |
+
def _gsubLookup(self, lookup, fealookup):
|
| 602 |
+
statements = fealookup.statements
|
| 603 |
+
|
| 604 |
+
sub = lookup.sub
|
| 605 |
+
|
| 606 |
+
# Alternate substitutions are represented by adding multiple
|
| 607 |
+
# substitutions for the same glyph, so we need to collect them into one
|
| 608 |
+
# to many mapping.
|
| 609 |
+
if isinstance(sub, VAst.SubstitutionAlternateDefinition):
|
| 610 |
+
alternates = {}
|
| 611 |
+
for key, val in sub.mapping.items():
|
| 612 |
+
if not key or not val:
|
| 613 |
+
path, line, column = sub.location
|
| 614 |
+
log.warning(f"{path}:{line}:{column}: Ignoring empty substitution")
|
| 615 |
+
continue
|
| 616 |
+
glyphs = self._coverage(key)
|
| 617 |
+
replacements = self._coverage(val)
|
| 618 |
+
assert len(glyphs) == 1
|
| 619 |
+
for src_glyph, repl_glyph in zip(
|
| 620 |
+
glyphs[0].glyphSet(), replacements[0].glyphSet()
|
| 621 |
+
):
|
| 622 |
+
alternates.setdefault(str(self._glyphName(src_glyph)), []).append(
|
| 623 |
+
str(self._glyphName(repl_glyph))
|
| 624 |
+
)
|
| 625 |
+
|
| 626 |
+
for glyph, replacements in alternates.items():
|
| 627 |
+
statement = ast.AlternateSubstStatement(
|
| 628 |
+
[], glyph, [], ast.GlyphClass(replacements)
|
| 629 |
+
)
|
| 630 |
+
statements.append(statement)
|
| 631 |
+
return
|
| 632 |
+
|
| 633 |
+
for key, val in sub.mapping.items():
|
| 634 |
+
if not key or not val:
|
| 635 |
+
path, line, column = sub.location
|
| 636 |
+
log.warning(f"{path}:{line}:{column}: Ignoring empty substitution")
|
| 637 |
+
continue
|
| 638 |
+
glyphs = self._coverage(key)
|
| 639 |
+
replacements = self._coverage(val)
|
| 640 |
+
if isinstance(sub, VAst.SubstitutionSingleDefinition):
|
| 641 |
+
assert len(glyphs) == 1
|
| 642 |
+
assert len(replacements) == 1
|
| 643 |
+
statements.append(
|
| 644 |
+
ast.SingleSubstStatement(glyphs, replacements, [], [], False)
|
| 645 |
+
)
|
| 646 |
+
elif isinstance(sub, VAst.SubstitutionReverseChainingSingleDefinition):
|
| 647 |
+
# This is handled in gsubContextLookup()
|
| 648 |
+
pass
|
| 649 |
+
elif isinstance(sub, VAst.SubstitutionMultipleDefinition):
|
| 650 |
+
assert len(glyphs) == 1
|
| 651 |
+
statements.append(
|
| 652 |
+
ast.MultipleSubstStatement([], glyphs[0], [], replacements)
|
| 653 |
+
)
|
| 654 |
+
elif isinstance(sub, VAst.SubstitutionLigatureDefinition):
|
| 655 |
+
assert len(replacements) == 1
|
| 656 |
+
statement = ast.LigatureSubstStatement(
|
| 657 |
+
[], glyphs, [], replacements[0], False
|
| 658 |
+
)
|
| 659 |
+
|
| 660 |
+
# If any of the input glyphs is a group, we need to
|
| 661 |
+
# explode the substitution into multiple ligature substitutions
|
| 662 |
+
# since feature file syntax does not support classes in
|
| 663 |
+
# ligature substitutions.
|
| 664 |
+
n = max(len(x.glyphSet()) for x in glyphs)
|
| 665 |
+
if n > 1:
|
| 666 |
+
# All input should either be groups of the same length or single glyphs
|
| 667 |
+
assert all(len(x.glyphSet()) in (n, 1) for x in glyphs)
|
| 668 |
+
glyphs = [x.glyphSet() for x in glyphs]
|
| 669 |
+
glyphs = [([x[0]] * n if len(x) == 1 else x) for x in glyphs]
|
| 670 |
+
|
| 671 |
+
# In this case ligature replacements must be a group of the same length
|
| 672 |
+
# as the input groups, or a single glyph. VOLT
|
| 673 |
+
# allows the replacement glyphs to be longer and truncates them.
|
| 674 |
+
# So well allow that and zip() below will do the truncation
|
| 675 |
+
# for us.
|
| 676 |
+
replacement = replacements[0].glyphSet()
|
| 677 |
+
if len(replacement) == 1:
|
| 678 |
+
replacement = [replacement[0]] * n
|
| 679 |
+
assert len(replacement) >= n
|
| 680 |
+
|
| 681 |
+
# Add the unexploded statement commented out for reference.
|
| 682 |
+
statements.append(ast.Comment(f"# {statement}"))
|
| 683 |
+
|
| 684 |
+
for zipped in zip(*glyphs, replacement):
|
| 685 |
+
zipped = [self._glyphName(x) for x in zipped]
|
| 686 |
+
statements.append(
|
| 687 |
+
ast.LigatureSubstStatement(
|
| 688 |
+
[], zipped[:-1], [], zipped[-1], False
|
| 689 |
+
)
|
| 690 |
+
)
|
| 691 |
+
else:
|
| 692 |
+
statements.append(statement)
|
| 693 |
+
else:
|
| 694 |
+
raise NotImplementedError(sub)
|
| 695 |
+
|
| 696 |
+
def _gsubContextLookup(self, lookup, prefix, suffix, ignore, fealookup, chained):
|
| 697 |
+
statements = fealookup.statements
|
| 698 |
+
|
| 699 |
+
sub = lookup.sub
|
| 700 |
+
|
| 701 |
+
if isinstance(sub, VAst.SubstitutionReverseChainingSingleDefinition):
|
| 702 |
+
# Reverse substitutions is a special case, it can’t use chained lookups.
|
| 703 |
+
for key, val in sub.mapping.items():
|
| 704 |
+
if not key or not val:
|
| 705 |
+
path, line, column = sub.location
|
| 706 |
+
log.warning(f"{path}:{line}:{column}: Ignoring empty substitution")
|
| 707 |
+
continue
|
| 708 |
+
glyphs = self._coverage(key)
|
| 709 |
+
replacements = self._coverage(val)
|
| 710 |
+
statements.append(
|
| 711 |
+
ast.ReverseChainSingleSubstStatement(
|
| 712 |
+
prefix, suffix, glyphs, replacements
|
| 713 |
+
)
|
| 714 |
+
)
|
| 715 |
+
fealookup.chained = []
|
| 716 |
+
return
|
| 717 |
+
|
| 718 |
+
if not isinstance(
|
| 719 |
+
sub,
|
| 720 |
+
(
|
| 721 |
+
VAst.SubstitutionSingleDefinition,
|
| 722 |
+
VAst.SubstitutionMultipleDefinition,
|
| 723 |
+
VAst.SubstitutionLigatureDefinition,
|
| 724 |
+
VAst.SubstitutionAlternateDefinition,
|
| 725 |
+
),
|
| 726 |
+
):
|
| 727 |
+
raise NotImplementedError(type(sub))
|
| 728 |
+
|
| 729 |
+
glyphs = []
|
| 730 |
+
for key, val in sub.mapping.items():
|
| 731 |
+
if not key or not val:
|
| 732 |
+
path, line, column = sub.location
|
| 733 |
+
log.warning(f"{path}:{line}:{column}: Ignoring empty substitution")
|
| 734 |
+
continue
|
| 735 |
+
glyphs.extend(self._coverage(key, flatten=True))
|
| 736 |
+
|
| 737 |
+
if len(glyphs) > 1:
|
| 738 |
+
glyphs = [ast.GlyphClass(glyphs)]
|
| 739 |
+
if ignore:
|
| 740 |
+
statements.append(ast.IgnoreSubstStatement([(prefix, glyphs, suffix)]))
|
| 741 |
+
else:
|
| 742 |
+
statements.append(
|
| 743 |
+
ast.ChainContextSubstStatement(prefix, glyphs, suffix, [chained])
|
| 744 |
+
)
|
| 745 |
+
|
| 746 |
+
def _lookupDefinition(self, lookup):
|
| 747 |
+
mark_attachement = None
|
| 748 |
+
mark_filtering = None
|
| 749 |
+
|
| 750 |
+
flags = 0
|
| 751 |
+
if lookup.direction == "RTL":
|
| 752 |
+
flags |= 1
|
| 753 |
+
if not lookup.process_base:
|
| 754 |
+
flags |= 2
|
| 755 |
+
# FIXME: Does VOLT support this?
|
| 756 |
+
# if not lookup.process_ligatures:
|
| 757 |
+
# flags |= 4
|
| 758 |
+
if not lookup.process_marks:
|
| 759 |
+
flags |= 8
|
| 760 |
+
elif isinstance(lookup.process_marks, str):
|
| 761 |
+
mark_attachement = self._groupName(lookup.process_marks)
|
| 762 |
+
elif lookup.mark_glyph_set is not None:
|
| 763 |
+
mark_filtering = self._groupName(lookup.mark_glyph_set)
|
| 764 |
+
|
| 765 |
+
lookupflags = None
|
| 766 |
+
if flags or mark_attachement is not None or mark_filtering is not None:
|
| 767 |
+
lookupflags = ast.LookupFlagStatement(
|
| 768 |
+
flags, mark_attachement, mark_filtering
|
| 769 |
+
)
|
| 770 |
+
|
| 771 |
+
use_extension = False
|
| 772 |
+
if self._settings.get("COMPILER_USEEXTENSIONLOOKUPS"):
|
| 773 |
+
use_extension = True
|
| 774 |
+
|
| 775 |
+
if "\\" in lookup.name:
|
| 776 |
+
# Merge sub lookups as subtables (lookups named “base\sub”),
|
| 777 |
+
# makeotf/feaLib will issue a warning and ignore the subtable
|
| 778 |
+
# statement if it is not a pairpos lookup, though.
|
| 779 |
+
name = lookup.name.split("\\")[0]
|
| 780 |
+
if name.lower() not in self._lookups:
|
| 781 |
+
fealookup = Lookup(
|
| 782 |
+
self._lookupName(name),
|
| 783 |
+
use_extension=use_extension,
|
| 784 |
+
)
|
| 785 |
+
if lookupflags is not None:
|
| 786 |
+
fealookup.statements.append(lookupflags)
|
| 787 |
+
fealookup.statements.append(ast.Comment("# " + lookup.name))
|
| 788 |
+
else:
|
| 789 |
+
fealookup = self._lookups[name.lower()]
|
| 790 |
+
fealookup.statements.append(ast.SubtableStatement())
|
| 791 |
+
fealookup.statements.append(ast.Comment("# " + lookup.name))
|
| 792 |
+
self._lookups[name.lower()] = fealookup
|
| 793 |
+
else:
|
| 794 |
+
fealookup = Lookup(
|
| 795 |
+
self._lookupName(lookup.name),
|
| 796 |
+
use_extension=use_extension,
|
| 797 |
+
)
|
| 798 |
+
if lookupflags is not None:
|
| 799 |
+
fealookup.statements.append(lookupflags)
|
| 800 |
+
self._lookups[lookup.name.lower()] = fealookup
|
| 801 |
+
|
| 802 |
+
if lookup.comments is not None:
|
| 803 |
+
fealookup.statements.append(ast.Comment("# " + lookup.comments))
|
| 804 |
+
|
| 805 |
+
contexts = []
|
| 806 |
+
for context in lookup.context:
|
| 807 |
+
prefix = self._context(context.left)
|
| 808 |
+
suffix = self._context(context.right)
|
| 809 |
+
ignore = context.ex_or_in == "EXCEPT_CONTEXT"
|
| 810 |
+
contexts.append([prefix, suffix, ignore])
|
| 811 |
+
# It seems that VOLT will create contextual substitution using
|
| 812 |
+
# only the input if there is no other contexts in this lookup.
|
| 813 |
+
if ignore and len(lookup.context) == 1:
|
| 814 |
+
contexts.append([[], [], False])
|
| 815 |
+
|
| 816 |
+
if contexts:
|
| 817 |
+
chained = ast.LookupBlock(
|
| 818 |
+
self._lookupName(lookup.name + " chained"),
|
| 819 |
+
use_extension=use_extension,
|
| 820 |
+
)
|
| 821 |
+
fealookup.chained.append(chained)
|
| 822 |
+
if lookup.sub is not None:
|
| 823 |
+
self._gsubLookup(lookup, chained)
|
| 824 |
+
elif lookup.pos is not None:
|
| 825 |
+
self._gposLookup(lookup, chained)
|
| 826 |
+
for prefix, suffix, ignore in contexts:
|
| 827 |
+
if lookup.sub is not None:
|
| 828 |
+
self._gsubContextLookup(
|
| 829 |
+
lookup, prefix, suffix, ignore, fealookup, chained
|
| 830 |
+
)
|
| 831 |
+
elif lookup.pos is not None:
|
| 832 |
+
self._gposContextLookup(
|
| 833 |
+
lookup, prefix, suffix, ignore, fealookup, chained
|
| 834 |
+
)
|
| 835 |
+
else:
|
| 836 |
+
if lookup.sub is not None:
|
| 837 |
+
self._gsubLookup(lookup, fealookup)
|
| 838 |
+
elif lookup.pos is not None:
|
| 839 |
+
self._gposLookup(lookup, fealookup)
|
| 840 |
+
|
| 841 |
+
|
| 842 |
+
def main(args=None):
|
| 843 |
+
"""Convert MS VOLT to AFDKO feature files."""
|
| 844 |
+
|
| 845 |
+
import argparse
|
| 846 |
+
from pathlib import Path
|
| 847 |
+
|
| 848 |
+
from fontTools import configLogger
|
| 849 |
+
|
| 850 |
+
parser = argparse.ArgumentParser(
|
| 851 |
+
"fonttools voltLib.voltToFea", description=main.__doc__
|
| 852 |
+
)
|
| 853 |
+
parser.add_argument(
|
| 854 |
+
"input", metavar="INPUT", type=Path, help="input font/VTP file to process"
|
| 855 |
+
)
|
| 856 |
+
parser.add_argument(
|
| 857 |
+
"featurefile", metavar="OUTPUT", type=Path, help="output feature file"
|
| 858 |
+
)
|
| 859 |
+
parser.add_argument(
|
| 860 |
+
"-t",
|
| 861 |
+
"--table",
|
| 862 |
+
action="append",
|
| 863 |
+
choices=TABLES,
|
| 864 |
+
dest="tables",
|
| 865 |
+
help="List of tables to write, by default all tables are written",
|
| 866 |
+
)
|
| 867 |
+
parser.add_argument(
|
| 868 |
+
"-q", "--quiet", action="store_true", help="Suppress non-error messages"
|
| 869 |
+
)
|
| 870 |
+
parser.add_argument(
|
| 871 |
+
"--traceback", action="store_true", help="Don’t catch exceptions"
|
| 872 |
+
)
|
| 873 |
+
|
| 874 |
+
options = parser.parse_args(args)
|
| 875 |
+
|
| 876 |
+
configLogger(level=("ERROR" if options.quiet else "INFO"))
|
| 877 |
+
|
| 878 |
+
file_or_path = options.input
|
| 879 |
+
font = None
|
| 880 |
+
try:
|
| 881 |
+
font = TTFont(file_or_path)
|
| 882 |
+
if "TSIV" in font:
|
| 883 |
+
file_or_path = StringIO(font["TSIV"].data.decode("utf-8"))
|
| 884 |
+
else:
|
| 885 |
+
log.error('"TSIV" table is missing, font was not saved from VOLT?')
|
| 886 |
+
return 1
|
| 887 |
+
except TTLibError:
|
| 888 |
+
pass
|
| 889 |
+
|
| 890 |
+
converter = VoltToFea(file_or_path, font)
|
| 891 |
+
try:
|
| 892 |
+
fea = converter.convert(options.tables)
|
| 893 |
+
except NotImplementedError as e:
|
| 894 |
+
if options.traceback:
|
| 895 |
+
raise
|
| 896 |
+
location = getattr(e.args[0], "location", None)
|
| 897 |
+
message = f'"{e}" is not supported'
|
| 898 |
+
if location:
|
| 899 |
+
path, line, column = location
|
| 900 |
+
log.error(f"{path}:{line}:{column}: {message}")
|
| 901 |
+
else:
|
| 902 |
+
log.error(message)
|
| 903 |
+
return 1
|
| 904 |
+
with open(options.featurefile, "w") as feafile:
|
| 905 |
+
feafile.write(fea)
|
| 906 |
+
|
| 907 |
+
|
| 908 |
+
if __name__ == "__main__":
|
| 909 |
+
import sys
|
| 910 |
+
|
| 911 |
+
sys.exit(main())
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/METADATA
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.2
|
| 2 |
+
Name: fonttools
|
| 3 |
+
Version: 4.63.0+computecanada
|
| 4 |
+
Summary: Tools to manipulate font files
|
| 5 |
+
Description-Content-Type: text/x-rst
|
| 6 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 7 |
+
Classifier: Environment :: Console
|
| 8 |
+
Classifier: Environment :: Other Environment
|
| 9 |
+
Classifier: Intended Audience :: Developers
|
| 10 |
+
Classifier: Intended Audience :: End Users/Desktop
|
| 11 |
+
Classifier: Natural Language :: English
|
| 12 |
+
Classifier: Operating System :: OS Independent
|
| 13 |
+
Classifier: Programming Language :: Python
|
| 14 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 19 |
+
Classifier: Programming Language :: Python :: 3
|
| 20 |
+
Classifier: Topic :: Text Processing :: Fonts
|
| 21 |
+
Classifier: Topic :: Multimedia :: Graphics
|
| 22 |
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
| 23 |
+
Author: Just van Rossum
|
| 24 |
+
Author-email: just@letterror.com
|
| 25 |
+
Maintainer: Behdad Esfahbod
|
| 26 |
+
Maintainer-email: behdad@behdad.org
|
| 27 |
+
Home-page: http://github.com/fonttools/fonttools
|
| 28 |
+
Platform: Any
|
| 29 |
+
Requires-Python: >=3.10
|
| 30 |
+
Requires-Dist: lxml>=4.0; extra == "lxml"
|
| 31 |
+
Requires-Dist: brotli>=1.0.1; platform_python_implementation == "CPython" and extra == "woff"
|
| 32 |
+
Requires-Dist: brotlicffi>=0.8.0; platform_python_implementation != "CPython" and extra == "woff"
|
| 33 |
+
Requires-Dist: zopfli>=0.1.4; extra == "woff"
|
| 34 |
+
Requires-Dist: unicodedata2>=17.0.0; python_version <= "3.14" and extra == "unicode"
|
| 35 |
+
Requires-Dist: lz4>=1.7.4.2; extra == "graphite"
|
| 36 |
+
Requires-Dist: scipy; platform_python_implementation != "PyPy" and extra == "interpolatable"
|
| 37 |
+
Requires-Dist: munkres; platform_python_implementation == "PyPy" and extra == "interpolatable"
|
| 38 |
+
Requires-Dist: pycairo; extra == "interpolatable"
|
| 39 |
+
Requires-Dist: matplotlib; extra == "plot"
|
| 40 |
+
Requires-Dist: sympy; extra == "symfont"
|
| 41 |
+
Requires-Dist: xattr; sys_platform == "darwin" and extra == "type1"
|
| 42 |
+
Requires-Dist: skia-pathops>=0.5.0; extra == "pathops"
|
| 43 |
+
Requires-Dist: uharfbuzz>=0.45.0; extra == "repacker"
|
| 44 |
+
Requires-Dist: lxml>=4.0; extra == "all"
|
| 45 |
+
Requires-Dist: brotli>=1.0.1; platform_python_implementation == "CPython" and extra == "all"
|
| 46 |
+
Requires-Dist: brotlicffi>=0.8.0; platform_python_implementation != "CPython" and extra == "all"
|
| 47 |
+
Requires-Dist: zopfli>=0.1.4; extra == "all"
|
| 48 |
+
Requires-Dist: unicodedata2>=17.0.0; python_version <= "3.14" and extra == "all"
|
| 49 |
+
Requires-Dist: lz4>=1.7.4.2; extra == "all"
|
| 50 |
+
Requires-Dist: scipy; platform_python_implementation != "PyPy" and extra == "all"
|
| 51 |
+
Requires-Dist: munkres; platform_python_implementation == "PyPy" and extra == "all"
|
| 52 |
+
Requires-Dist: pycairo; extra == "all"
|
| 53 |
+
Requires-Dist: matplotlib; extra == "all"
|
| 54 |
+
Requires-Dist: sympy; extra == "all"
|
| 55 |
+
Requires-Dist: xattr; sys_platform == "darwin" and extra == "all"
|
| 56 |
+
Requires-Dist: skia-pathops>=0.5.0; extra == "all"
|
| 57 |
+
Requires-Dist: uharfbuzz>=0.45.0; extra == "all"
|
| 58 |
+
Provides-Extra: ufo
|
| 59 |
+
Provides-Extra: lxml
|
| 60 |
+
Provides-Extra: woff
|
| 61 |
+
Provides-Extra: unicode
|
| 62 |
+
Provides-Extra: graphite
|
| 63 |
+
Provides-Extra: interpolatable
|
| 64 |
+
Provides-Extra: plot
|
| 65 |
+
Provides-Extra: symfont
|
| 66 |
+
Provides-Extra: type1
|
| 67 |
+
Provides-Extra: pathops
|
| 68 |
+
Provides-Extra: repacker
|
| 69 |
+
Provides-Extra: all
|
| 70 |
+
License-File: LICENSE
|
| 71 |
+
License-File: LICENSE.external
|
| 72 |
+
Dynamic: author
|
| 73 |
+
|
| 74 |
+
MIT
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/RECORD
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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x.1,sha256=cLbm_pOOj1C76T2QXvDxzwDj9gk-GTd5RztvTMsouFw,5377
|
| 6 |
+
fontTools/__init__.py,sha256=yAGxcHJPzTgLB4szimvj-C4mSPOUESVqivNB_-W0gR4,183
|
| 7 |
+
fontTools/__main__.py,sha256=VjkGh1UD-i1zTDA1dXo1uecSs6PxHdGQ5vlCk_mCCYs,925
|
| 8 |
+
fontTools/__pycache__/__init__.cpython-311.pyc,,
|
| 9 |
+
fontTools/__pycache__/__main__.cpython-311.pyc,,
|
| 10 |
+
fontTools/__pycache__/afmLib.cpython-311.pyc,,
|
| 11 |
+
fontTools/__pycache__/agl.cpython-311.pyc,,
|
| 12 |
+
fontTools/__pycache__/annotations.cpython-311.pyc,,
|
| 13 |
+
fontTools/__pycache__/fontBuilder.cpython-311.pyc,,
|
| 14 |
+
fontTools/__pycache__/help.cpython-311.pyc,,
|
| 15 |
+
fontTools/__pycache__/tfmLib.cpython-311.pyc,,
|
| 16 |
+
fontTools/__pycache__/ttx.cpython-311.pyc,,
|
| 17 |
+
fontTools/__pycache__/unicode.cpython-311.pyc,,
|
| 18 |
+
fontTools/afmLib.py,sha256=1MagIItOzRV4vV5kKPxeDZbPJsfxLB3wdHLFkQvl0uk,13164
|
| 19 |
+
fontTools/agl.py,sha256=05bm8Uq45uVWW8nPbP6xbNgmFyxQr8sWhYAiP0VSjnI,112975
|
| 20 |
+
fontTools/annotations.py,sha256=BdIIriNYDzBfgniwWFg_u71qLZnV0sCcn4-VAkXkYNM,1225
|
| 21 |
+
fontTools/cffLib/CFF2ToCFF.py,sha256=7h0fK53ji4JlA4mAxlVb54eQTM4N2e3LAd4wwW3TLyE,8201
|
| 22 |
+
fontTools/cffLib/CFFToCFF2.py,sha256=Qnk7lYlsTRHnlZQ6NXNdr_f4MJwZQ21kcS08KFbsyY8,10119
|
| 23 |
+
fontTools/cffLib/__init__.py,sha256=RG1jUl82tehcsjI0SbsKJ_-MhVTvKxQ2ThgWOI3SA0k,107890
|
| 24 |
+
fontTools/cffLib/__pycache__/CFF2ToCFF.cpython-311.pyc,,
|
| 25 |
+
fontTools/cffLib/__pycache__/CFFToCFF2.cpython-311.pyc,,
|
| 26 |
+
fontTools/cffLib/__pycache__/__init__.cpython-311.pyc,,
|
| 27 |
+
fontTools/cffLib/__pycache__/specializer.cpython-311.pyc,,
|
| 28 |
+
fontTools/cffLib/__pycache__/transforms.cpython-311.pyc,,
|
| 29 |
+
fontTools/cffLib/__pycache__/width.cpython-311.pyc,,
|
| 30 |
+
fontTools/cffLib/specializer.py,sha256=vsOPkR_jHNe6tESQEjmm0i76y7sWI5MKo3bsTmI3sNM,32609
|
| 31 |
+
fontTools/cffLib/transforms.py,sha256=SEIZc1XxWYiVXVBsoNm6LTvM9SUN7Z76QOaSAlR1ZCo,17455
|
| 32 |
+
fontTools/cffLib/width.py,sha256=IqGL0CLyCZqi_hvsHySG08qpYxS3kaqW-tsAT-bjHV4,6074
|
| 33 |
+
fontTools/colorLib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 34 |
+
fontTools/colorLib/__pycache__/__init__.cpython-311.pyc,,
|
| 35 |
+
fontTools/colorLib/__pycache__/builder.cpython-311.pyc,,
|
| 36 |
+
fontTools/colorLib/__pycache__/errors.cpython-311.pyc,,
|
| 37 |
+
fontTools/colorLib/__pycache__/geometry.cpython-311.pyc,,
|
| 38 |
+
fontTools/colorLib/__pycache__/table_builder.cpython-311.pyc,,
|
| 39 |
+
fontTools/colorLib/__pycache__/unbuilder.cpython-311.pyc,,
|
| 40 |
+
fontTools/colorLib/builder.py,sha256=XChSOAAWbp-kQqQ3tspEwEkxl0uHE1I3HRAq5p9SOrk,23711
|
| 41 |
+
fontTools/colorLib/errors.py,sha256=CsaviiRxxrpgVX4blm7KCyK8553ljwL44xkJOeC5U7U,41
|
| 42 |
+
fontTools/colorLib/geometry.py,sha256=3ScySrR2YDJa7d5K5_xM5Yt1-3NCV-ry8ikYA5VwVbI,5518
|
| 43 |
+
fontTools/colorLib/table_builder.py,sha256=ZeltWY6n-YPiJv_hQ1iBXoEFAG70EKxZyScgsMKUFGU,7469
|
| 44 |
+
fontTools/colorLib/unbuilder.py,sha256=iW-E5I39WsV82K3NgCO4Cjzwm1WqzGrtypHt8epwbHM,2142
|
| 45 |
+
fontTools/config/__init__.py,sha256=JICOHIz06KuHCiBmrxj-ga19P6ZTuLXh0lHmPh-Ra1w,3154
|
| 46 |
+
fontTools/config/__pycache__/__init__.cpython-311.pyc,,
|
| 47 |
+
fontTools/cu2qu/__init__.py,sha256=Cuc7Uglb0nSgaraTxXY5J8bReznH5wApW0uakN7MycY,618
|
| 48 |
+
fontTools/cu2qu/__main__.py,sha256=kTUI-jczsHeelULLlory74QEeFjZWp9zigCc7PrdVQY,92
|
| 49 |
+
fontTools/cu2qu/__pycache__/__init__.cpython-311.pyc,,
|
| 50 |
+
fontTools/cu2qu/__pycache__/__main__.cpython-311.pyc,,
|
| 51 |
+
fontTools/cu2qu/__pycache__/benchmark.cpython-311.pyc,,
|
| 52 |
+
fontTools/cu2qu/__pycache__/cli.cpython-311.pyc,,
|
| 53 |
+
fontTools/cu2qu/__pycache__/cu2qu.cpython-311.pyc,,
|
| 54 |
+
fontTools/cu2qu/__pycache__/errors.cpython-311.pyc,,
|
| 55 |
+
fontTools/cu2qu/__pycache__/ufo.cpython-311.pyc,,
|
| 56 |
+
fontTools/cu2qu/benchmark.py,sha256=wasPJmf8q9k9UHjpHChC3WQAGbBAyHN9PvJzXvWC0Fw,1296
|
| 57 |
+
fontTools/cu2qu/cli.py,sha256=cT6419FTnrGVm4pJeH3bOenQq7LHGAj-GGrtvtTzg4Y,6075
|
| 58 |
+
fontTools/cu2qu/cu2qu.c,sha256=DLQ4jdgnufi0A9SXTNP-FKxOjU-v27o83MJnefK4gsE,650930
|
| 59 |
+
fontTools/cu2qu/cu2qu.cpython-311-x86_64-linux-gnu.so,sha256=Xwapg0XY8xTGHHmZLclA_6MWVb-ziEWDdUzzP36ARTU,742104
|
| 60 |
+
fontTools/cu2qu/cu2qu.py,sha256=yDuJRHUwbS6EzhDn6UFX95ziB0ebvEzysdZ72qHg8o0,18283
|
| 61 |
+
fontTools/cu2qu/errors.py,sha256=PyJNMy8lHDtKpfFkc0nkM8F4jNLZAC4lPQCN1Km4bpg,2441
|
| 62 |
+
fontTools/cu2qu/ufo.py,sha256=F54FtS-1Wnb6Wurrxp4xlw_m7Y_pRCtNZUqY62V_GRw,13124
|
| 63 |
+
fontTools/designspaceLib/__init__.py,sha256=K_MqE93yFETrORGcjfv7npUkvwNiXuSc4YsTl2eYFuI,130368
|
| 64 |
+
fontTools/designspaceLib/__main__.py,sha256=xhtYXo1T1tsykhQDD0tcconSNYgWL5hoTBORpVDUYrc,103
|
| 65 |
+
fontTools/designspaceLib/__pycache__/__init__.cpython-311.pyc,,
|
| 66 |
+
fontTools/designspaceLib/__pycache__/__main__.cpython-311.pyc,,
|
| 67 |
+
fontTools/designspaceLib/__pycache__/split.cpython-311.pyc,,
|
| 68 |
+
fontTools/designspaceLib/__pycache__/statNames.cpython-311.pyc,,
|
| 69 |
+
fontTools/designspaceLib/__pycache__/types.cpython-311.pyc,,
|
| 70 |
+
fontTools/designspaceLib/split.py,sha256=FB1NuvhUO453UXveQZi9oyrW_caoCPM3RADp1rYWkDs,19239
|
| 71 |
+
fontTools/designspaceLib/statNames.py,sha256=gXGKWVr1ju2_oL-R_DkyoZ3GlI7mfLORovpk1Ebgmvc,9237
|
| 72 |
+
fontTools/designspaceLib/types.py,sha256=ofK65qXNADqcpl7zI72Pa5s07-cm7G41iEmLVV44-Es,5320
|
| 73 |
+
fontTools/diff/__init__.py,sha256=DgYBwtNerim9gxmYvy3KT8TEx6zHw3zDFuAaAPAQp1c,13626
|
| 74 |
+
fontTools/diff/__main__.py,sha256=442JjNXoCFuVK3UktJ3S4v-3J0Z1hordmoxyEjzUtTE,93
|
| 75 |
+
fontTools/diff/__pycache__/__init__.cpython-311.pyc,,
|
| 76 |
+
fontTools/diff/__pycache__/__main__.cpython-311.pyc,,
|
| 77 |
+
fontTools/diff/__pycache__/color.cpython-311.pyc,,
|
| 78 |
+
fontTools/diff/__pycache__/diff.cpython-311.pyc,,
|
| 79 |
+
fontTools/diff/__pycache__/utils.cpython-311.pyc,,
|
| 80 |
+
fontTools/diff/color.py,sha256=irtBTlKWAc2FQvY8tI3_hkVCkfKGxTUqu3F7XFNb-Yc,1387
|
| 81 |
+
fontTools/diff/diff.py,sha256=Sw_QdyYkTJilzDaQMo5ijCIVXeI5bDcNzUZrB7e2U0o,8964
|
| 82 |
+
fontTools/diff/utils.py,sha256=OTdXNfK4JO8VvT4eueZ-XtYf01lOop0XGBIp84BtPz8,1020
|
| 83 |
+
fontTools/encodings/MacRoman.py,sha256=4vEooUDm2gLCG8KIIDhRxm5-A64w7XrhP9cjDRr2Eo0,3576
|
| 84 |
+
fontTools/encodings/StandardEncoding.py,sha256=Eo3AGE8FE_p-IVYYuV097KouSsF3UrXoRRN0XyvYbrs,3581
|
| 85 |
+
fontTools/encodings/__init__.py,sha256=DJBWmoX_Haau7qlgmvWyfbhSzrX2qL636Rns7CG01pk,75
|
| 86 |
+
fontTools/encodings/__pycache__/MacRoman.cpython-311.pyc,,
|
| 87 |
+
fontTools/encodings/__pycache__/StandardEncoding.cpython-311.pyc,,
|
| 88 |
+
fontTools/encodings/__pycache__/__init__.cpython-311.pyc,,
|
| 89 |
+
fontTools/encodings/__pycache__/codecs.cpython-311.pyc,,
|
| 90 |
+
fontTools/encodings/codecs.py,sha256=u50ruwz9fcRsrUrRGpR17Cr55Ovn1fvCHCKrElVumDE,4721
|
| 91 |
+
fontTools/feaLib/__init__.py,sha256=jlIru2ghxvb1HhC5Je2BCXjFJmFQlYKpruorPoz3BvQ,213
|
| 92 |
+
fontTools/feaLib/__main__.py,sha256=Df2PA6LXwna98lSXiL7R4as_ZEdWCIk3egSM5w7GpvM,2240
|
| 93 |
+
fontTools/feaLib/__pycache__/__init__.cpython-311.pyc,,
|
| 94 |
+
fontTools/feaLib/__pycache__/__main__.cpython-311.pyc,,
|
| 95 |
+
fontTools/feaLib/__pycache__/ast.cpython-311.pyc,,
|
| 96 |
+
fontTools/feaLib/__pycache__/builder.cpython-311.pyc,,
|
| 97 |
+
fontTools/feaLib/__pycache__/error.cpython-311.pyc,,
|
| 98 |
+
fontTools/feaLib/__pycache__/lexer.cpython-311.pyc,,
|
| 99 |
+
fontTools/feaLib/__pycache__/location.cpython-311.pyc,,
|
| 100 |
+
fontTools/feaLib/__pycache__/lookupDebugInfo.cpython-311.pyc,,
|
| 101 |
+
fontTools/feaLib/__pycache__/parser.cpython-311.pyc,,
|
| 102 |
+
fontTools/feaLib/__pycache__/variableScalar.cpython-311.pyc,,
|
| 103 |
+
fontTools/feaLib/ast.py,sha256=48Y6vpSD_wYfucWyh_bQtzf2AQFX-pOwBvsxdcpVDz0,74158
|
| 104 |
+
fontTools/feaLib/builder.py,sha256=PBEAwdjxnAIjTrlIIevCzXR6Sgvz_DODIGnGL_KMYJg,75405
|
| 105 |
+
fontTools/feaLib/error.py,sha256=Bz_5tNcNVcY7_nrAmFlQNhQldtqZWd8WUGQ2E3PWhZo,648
|
| 106 |
+
fontTools/feaLib/lexer.c,sha256=EC3ITEOrpFlChkY9DZ8L_IEKKMCfiXrPFynbcmRix2I,748779
|
| 107 |
+
fontTools/feaLib/lexer.cpython-311-x86_64-linux-gnu.so,sha256=T-HPVnHOd9e7aeidva_MpdXOqWQe8HYLKbkb_UuqDSU,828832
|
| 108 |
+
fontTools/feaLib/lexer.py,sha256=emyMPmRoqNZkzxnJyI6JRCCtXrbCOFofwa9O6ABGLiw,11121
|
| 109 |
+
fontTools/feaLib/location.py,sha256=JXzHqGV56EHdcq823AwA5oaK05hf_1ySWpScbo3zGC0,234
|
| 110 |
+
fontTools/feaLib/lookupDebugInfo.py,sha256=gVRr5-APWfT_a5-25hRuawSVX8fEvXVsOSLWkH91T2w,304
|
| 111 |
+
fontTools/feaLib/parser.py,sha256=2QxPRhc9c5OVyw7UnrgAuLwKVCI5xa_6Rp9NhwPOF9Y,99974
|
| 112 |
+
fontTools/feaLib/variableScalar.py,sha256=DQZDWHV3dDnnGRcF1w4jrmHILoCFhPWsO1VZAoUu-78,9671
|
| 113 |
+
fontTools/fontBuilder.py,sha256=d9bBaId9K6KPpR5nP0l5Ou_8Pp7hr4gRuLeQV0NmwUY,34280
|
| 114 |
+
fontTools/help.py,sha256=bAjatvIhV7TJyXI7WhsxdYO4YVlhScZXu_kRtHANEPo,1125
|
| 115 |
+
fontTools/merge/__init__.py,sha256=8i6ownyQTAOBKWnTEHvvCYFw64Mv7Z1HPBgJI-ZiuKo,8256
|
| 116 |
+
fontTools/merge/__main__.py,sha256=hDx3gfbUBO83AJKumSEhiV-xqNTJNNgK2uFjazOGTmw,94
|
| 117 |
+
fontTools/merge/__pycache__/__init__.cpython-311.pyc,,
|
| 118 |
+
fontTools/merge/__pycache__/__main__.cpython-311.pyc,,
|
| 119 |
+
fontTools/merge/__pycache__/base.cpython-311.pyc,,
|
| 120 |
+
fontTools/merge/__pycache__/cmap.cpython-311.pyc,,
|
| 121 |
+
fontTools/merge/__pycache__/layout.cpython-311.pyc,,
|
| 122 |
+
fontTools/merge/__pycache__/options.cpython-311.pyc,,
|
| 123 |
+
fontTools/merge/__pycache__/tables.cpython-311.pyc,,
|
| 124 |
+
fontTools/merge/__pycache__/unicode.cpython-311.pyc,,
|
| 125 |
+
fontTools/merge/__pycache__/util.cpython-311.pyc,,
|
| 126 |
+
fontTools/merge/base.py,sha256=l0G1Px98E9ZdVuFLMUBKWdtr7Jb8JX8vxcjeaDUUnzY,2389
|
| 127 |
+
fontTools/merge/cmap.py,sha256=HpthxVH5lA7VegJ8yHoBjd9vrFBV7UB5OknKGYpxWY8,6728
|
| 128 |
+
fontTools/merge/layout.py,sha256=fkMPGPLxEdxohS3scVM4W7LmNthSz-UPyocsffe2KqE,16075
|
| 129 |
+
fontTools/merge/options.py,sha256=xko_1-WErcNQkirECzIOOYxSJR_bRtdQYQYOtmgccYI,2501
|
| 130 |
+
fontTools/merge/tables.py,sha256=7SzXYL04awDEDhvU2-9T_8A2gAjvgGyYAHUICUJOpZg,10958
|
| 131 |
+
fontTools/merge/unicode.py,sha256=kb1Jrfuoq1KUcVhhSKnflAED_wMZxXDjVwB-CI9k05Y,4273
|
| 132 |
+
fontTools/merge/util.py,sha256=BH3bZWNFy-Tsj1cth7aSpGVJ18YXKXqDakPn6Wzku6U,3378
|
| 133 |
+
fontTools/misc/__init__.py,sha256=DJBWmoX_Haau7qlgmvWyfbhSzrX2qL636Rns7CG01pk,75
|
| 134 |
+
fontTools/misc/__pycache__/__init__.cpython-311.pyc,,
|
| 135 |
+
fontTools/misc/__pycache__/arrayTools.cpython-311.pyc,,
|
| 136 |
+
fontTools/misc/__pycache__/bezierTools.cpython-311.pyc,,
|
| 137 |
+
fontTools/misc/__pycache__/classifyTools.cpython-311.pyc,,
|
| 138 |
+
fontTools/misc/__pycache__/cliTools.cpython-311.pyc,,
|
| 139 |
+
fontTools/misc/__pycache__/configTools.cpython-311.pyc,,
|
| 140 |
+
fontTools/misc/__pycache__/cython.cpython-311.pyc,,
|
| 141 |
+
fontTools/misc/__pycache__/dictTools.cpython-311.pyc,,
|
| 142 |
+
fontTools/misc/__pycache__/eexec.cpython-311.pyc,,
|
| 143 |
+
fontTools/misc/__pycache__/encodingTools.cpython-311.pyc,,
|
| 144 |
+
fontTools/misc/__pycache__/enumTools.cpython-311.pyc,,
|
| 145 |
+
fontTools/misc/__pycache__/etree.cpython-311.pyc,,
|
| 146 |
+
fontTools/misc/__pycache__/filenames.cpython-311.pyc,,
|
| 147 |
+
fontTools/misc/__pycache__/fixedTools.cpython-311.pyc,,
|
| 148 |
+
fontTools/misc/__pycache__/iftSparseBitSet.cpython-311.pyc,,
|
| 149 |
+
fontTools/misc/__pycache__/intTools.cpython-311.pyc,,
|
| 150 |
+
fontTools/misc/__pycache__/iterTools.cpython-311.pyc,,
|
| 151 |
+
fontTools/misc/__pycache__/lazyTools.cpython-311.pyc,,
|
| 152 |
+
fontTools/misc/__pycache__/loggingTools.cpython-311.pyc,,
|
| 153 |
+
fontTools/misc/__pycache__/macCreatorType.cpython-311.pyc,,
|
| 154 |
+
fontTools/misc/__pycache__/macRes.cpython-311.pyc,,
|
| 155 |
+
fontTools/misc/__pycache__/psCharStrings.cpython-311.pyc,,
|
| 156 |
+
fontTools/misc/__pycache__/psLib.cpython-311.pyc,,
|
| 157 |
+
fontTools/misc/__pycache__/psOperators.cpython-311.pyc,,
|
| 158 |
+
fontTools/misc/__pycache__/py23.cpython-311.pyc,,
|
| 159 |
+
fontTools/misc/__pycache__/roundTools.cpython-311.pyc,,
|
| 160 |
+
fontTools/misc/__pycache__/sstruct.cpython-311.pyc,,
|
| 161 |
+
fontTools/misc/__pycache__/symfont.cpython-311.pyc,,
|
| 162 |
+
fontTools/misc/__pycache__/testTools.cpython-311.pyc,,
|
| 163 |
+
fontTools/misc/__pycache__/textTools.cpython-311.pyc,,
|
| 164 |
+
fontTools/misc/__pycache__/timeTools.cpython-311.pyc,,
|
| 165 |
+
fontTools/misc/__pycache__/transform.cpython-311.pyc,,
|
| 166 |
+
fontTools/misc/__pycache__/treeTools.cpython-311.pyc,,
|
| 167 |
+
fontTools/misc/__pycache__/vector.cpython-311.pyc,,
|
| 168 |
+
fontTools/misc/__pycache__/visitor.cpython-311.pyc,,
|
| 169 |
+
fontTools/misc/__pycache__/xmlReader.cpython-311.pyc,,
|
| 170 |
+
fontTools/misc/__pycache__/xmlWriter.cpython-311.pyc,,
|
| 171 |
+
fontTools/misc/arrayTools.py,sha256=jZk__GE-K9VViZE_H-LPPj0smWbKng-yfPE8BfGp8HI,11483
|
| 172 |
+
fontTools/misc/bezierTools.c,sha256=zz4veIZquc91rQR25WyU1BQRj7rHTh0Tefpky9RBLn8,1837643
|
| 173 |
+
fontTools/misc/bezierTools.cpython-311-x86_64-linux-gnu.so,sha256=pSnqzYCb8rnnFoa7JgPv0rYON72VgJ4HB-P9Yq2NnCI,2632208
|
| 174 |
+
fontTools/misc/bezierTools.py,sha256=2xvnsKboUZ-Ln1bbiJk2392foh3vRhulmpqaWl1a-lQ,45240
|
| 175 |
+
fontTools/misc/classifyTools.py,sha256=zcg3EM4GOerBW9c063ljaLllgeeZ772EpFZjp9CdgLI,5613
|
| 176 |
+
fontTools/misc/cliTools.py,sha256=qCznJMLCQu3ZHQD_4ctUnr3TkfAUdkGl-UuxZUrppy0,1862
|
| 177 |
+
fontTools/misc/configTools.py,sha256=tDede_q8h81w6mDh132_F5WzfWkwmDGAF8nwj3dHVus,11229
|
| 178 |
+
fontTools/misc/cython.py,sha256=eyLcL2Bw-SSToYro8f44dkkYRlQfiFbhcza0afS-qHE,682
|
| 179 |
+
fontTools/misc/dictTools.py,sha256=VxjarsGJuk_wa3z29FSCtKZNCFfXtMBiNEu0RPAlpDk,2417
|
| 180 |
+
fontTools/misc/eexec.py,sha256=GNn2OCRvO1HbbIeDPxk9i0glO7cux_AQaoVMXhBR8y8,3331
|
| 181 |
+
fontTools/misc/encodingTools.py,sha256=hCv5PFfnXQJVCZA8Wyn1vr3vzLBbUuEPtGk5CzWM9RY,2073
|
| 182 |
+
fontTools/misc/enumTools.py,sha256=YQZW-d2ES9KFFkAXOUMIBbRUk6v_3BT6Q7lXE1ufhxA,502
|
| 183 |
+
fontTools/misc/etree.py,sha256=ZzJc6TvAS579deAgZLVDvTY_HeTm-ZsKJ5s3LYhZSSY,16304
|
| 184 |
+
fontTools/misc/filenames.py,sha256=MMCO3xjk1pcDc-baobcKd8IdoFPt-bcGqu8t8HUGAkI,8223
|
| 185 |
+
fontTools/misc/filesystem/__init__.py,sha256=iwoOj6DpXKk8q-NRRHqOfRxFF6lcXIhsIA46j-cZswU,2011
|
| 186 |
+
fontTools/misc/filesystem/__pycache__/__init__.cpython-311.pyc,,
|
| 187 |
+
fontTools/misc/filesystem/__pycache__/_base.cpython-311.pyc,,
|
| 188 |
+
fontTools/misc/filesystem/__pycache__/_copy.cpython-311.pyc,,
|
| 189 |
+
fontTools/misc/filesystem/__pycache__/_errors.cpython-311.pyc,,
|
| 190 |
+
fontTools/misc/filesystem/__pycache__/_info.cpython-311.pyc,,
|
| 191 |
+
fontTools/misc/filesystem/__pycache__/_osfs.cpython-311.pyc,,
|
| 192 |
+
fontTools/misc/filesystem/__pycache__/_path.cpython-311.pyc,,
|
| 193 |
+
fontTools/misc/filesystem/__pycache__/_subfs.cpython-311.pyc,,
|
| 194 |
+
fontTools/misc/filesystem/__pycache__/_tempfs.cpython-311.pyc,,
|
| 195 |
+
fontTools/misc/filesystem/__pycache__/_tools.cpython-311.pyc,,
|
| 196 |
+
fontTools/misc/filesystem/__pycache__/_walk.cpython-311.pyc,,
|
| 197 |
+
fontTools/misc/filesystem/__pycache__/_zipfs.cpython-311.pyc,,
|
| 198 |
+
fontTools/misc/filesystem/_base.py,sha256=p74O7xREadfPQgzPJ9mP3ehu0ZHDgsmXlpsL9CnTRso,4010
|
| 199 |
+
fontTools/misc/filesystem/_copy.py,sha256=ifMSs-A_bz1Aa4tIQrlUd9HtdJQ5fp5M3B6mbYuDtXI,1361
|
| 200 |
+
fontTools/misc/filesystem/_errors.py,sha256=-YziRB1BT1I80ypmufvCR-M_4XoerCHyBVqX-cRnIzU,641
|
| 201 |
+
fontTools/misc/filesystem/_info.py,sha256=pbV7bDTJ5F8ms6alK34J0FZYWzmRO7FT0NM3yRA3czo,2013
|
| 202 |
+
fontTools/misc/filesystem/_osfs.py,sha256=RkKCE2IxcRaj7gyqFW10LhEm_-VJYtXxsS5s0DCXihM,5737
|
| 203 |
+
fontTools/misc/filesystem/_path.py,sha256=frP6ZLmMeP9E3NiwoCbbgBPWpQbLBRh7T-0vOE-EuPo,1745
|
| 204 |
+
fontTools/misc/filesystem/_subfs.py,sha256=vRotQwyLVfINbR88xIBQUbq9j4Kmg1_mJvEhnpvK_t4,3028
|
| 205 |
+
fontTools/misc/filesystem/_tempfs.py,sha256=9FUXdCBTwFtZMFx8ghYuZVYoQdDb0tDB-jXNu3D-Qy0,924
|
| 206 |
+
fontTools/misc/filesystem/_tools.py,sha256=r75dpadp7C9EdQ6r7pJQKZlCZDUJzVq2ikb_LXN-wCI,972
|
| 207 |
+
fontTools/misc/filesystem/_walk.py,sha256=KMQ-GavWYr4SsA5V8ohLPmz3boilvY2P0JKrLoxW6NU,1655
|
| 208 |
+
fontTools/misc/filesystem/_zipfs.py,sha256=i3qolbkDRntB_oL3v79KuEgfVlVojecPBnBA0X04PWc,6301
|
| 209 |
+
fontTools/misc/fixedTools.py,sha256=XycD5QpaejJE-GFaFMlLlku6RG0ipJowuamMXjFrMjQ,7668
|
| 210 |
+
fontTools/misc/iftSparseBitSet.py,sha256=nhqQIa3o-P5frMdk4XlySzEAmGc7igouYlhBSR8U7ss,10521
|
| 211 |
+
fontTools/misc/intTools.py,sha256=l6pjk4UYlXcyLtfC0DdOC5RL6UJ8ihRR0zRiYow5xA8,586
|
| 212 |
+
fontTools/misc/iterTools.py,sha256=17H6LPZszp32bTKoNorp6uZF1PKj47BAbe5QG8irUjo,390
|
| 213 |
+
fontTools/misc/lazyTools.py,sha256=BC6MmF-OzJ3GrBD8TYDZ-VCSN4UOx0pN0r3oF4GSoiw,1020
|
| 214 |
+
fontTools/misc/loggingTools.py,sha256=NOYROsLK5TzONK5967OGdVonNyXC6kP_CmPr7M2PW_c,19933
|
| 215 |
+
fontTools/misc/macCreatorType.py,sha256=Je9jtqUr7EPbpH3QxlVl3pizoQ-1AOPMBIctHIMTM3k,1593
|
| 216 |
+
fontTools/misc/macRes.py,sha256=GT_pnfPw2NCvvOF86nHLAnOtZ6SMHqEuLntaplXzvHM,8579
|
| 217 |
+
fontTools/misc/plistlib/__init__.py,sha256=1HfhHPt3As6u2eRSlFfl6XdnXv_ypQImeQdWIw6wK7Y,21113
|
| 218 |
+
fontTools/misc/plistlib/__pycache__/__init__.cpython-311.pyc,,
|
| 219 |
+
fontTools/misc/plistlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 220 |
+
fontTools/misc/psCharStrings.py,sha256=Zn8mr7NRTfEJbnaXbOnSarrFBPcvPM0AupAxF2C80LY,43468
|
| 221 |
+
fontTools/misc/psLib.py,sha256=ioIPm5x3MHkBXF2vzNkC4iVZYobrkWcyvFhmYsjOrPY,12099
|
| 222 |
+
fontTools/misc/psOperators.py,sha256=9SLl5PPBulLo0Xxg_dqlJMitNIBdiGKdkXhOWsNSYZE,15700
|
| 223 |
+
fontTools/misc/py23.py,sha256=aPVCEUz_deggwLBCeTSsccX6QgJavZqvdVtuhpzrPvA,2238
|
| 224 |
+
fontTools/misc/roundTools.py,sha256=1RSXZ0gyi1qW42tz6WSBMJD1FlPdtgqKfWixVN9bd78,3173
|
| 225 |
+
fontTools/misc/sstruct.py,sha256=vUODd2CKvHLtjr7yn1K94Hui_yxOPWKmlgAmBMm3KDQ,7009
|
| 226 |
+
fontTools/misc/symfont.py,sha256=x5ZwqK9Ik9orG6qSftgVGygBFE1wTSngrMK2We1Z5AM,6977
|
| 227 |
+
fontTools/misc/testTools.py,sha256=3vj_KllUQVEiVFbS0SzTmeuKv44-L-disI1dZ4XhOfw,7052
|
| 228 |
+
fontTools/misc/textTools.py,sha256=wNjH5zl1v9qNfmTl4BL52IO2IG1H5xY3o_pslqPPRjc,3483
|
| 229 |
+
fontTools/misc/timeTools.py,sha256=e9h5pgzL04tBDXmCv_8eRGB4boFV8GKXlS6dq3ggEpw,2234
|
| 230 |
+
fontTools/misc/transform.py,sha256=OR8dPsAw87z77gkZQMq00iUkDWLIxYv-12XiKH1-erk,15798
|
| 231 |
+
fontTools/misc/treeTools.py,sha256=tLWkwyDHeZUPVOGNnJeD4Pn7x2bQeZetwJKaEAW2J2M,1269
|
| 232 |
+
fontTools/misc/vector.py,sha256=6lqZcDjAgHJFQgjzD-ULQ_PrigAMfeZKaBZmAfcC0ig,4062
|
| 233 |
+
fontTools/misc/visitor.py,sha256=zwBAVfZ3MTsrbhNFj03pSSjNRyT6oGkare-kfWkN5ns,5754
|
| 234 |
+
fontTools/misc/xmlReader.py,sha256=igut4_d13RT4WarliqVvuuPybO1uSXVeoBOeW4j0_e4,6580
|
| 235 |
+
fontTools/misc/xmlWriter.py,sha256=EIdcS_0y9gvpc82QvZC9VcerAqEsP8eeC0gqMoPK4jc,7374
|
| 236 |
+
fontTools/mtiLib/__init__.py,sha256=EzYwNaENLf906h1THBeq6nSRHUKpOAYxuzO9x9PHzh8,46602
|
| 237 |
+
fontTools/mtiLib/__main__.py,sha256=gd8X89jnZOe-752k7uaR1lWoiju-2zIT5Yx35Kl0Xek,94
|
| 238 |
+
fontTools/mtiLib/__pycache__/__init__.cpython-311.pyc,,
|
| 239 |
+
fontTools/mtiLib/__pycache__/__main__.cpython-311.pyc,,
|
| 240 |
+
fontTools/otlLib/__init__.py,sha256=D2leUW-3gsUTOFcJYGC18edBYjIJ804ut4qitJYWsaQ,45
|
| 241 |
+
fontTools/otlLib/__pycache__/__init__.cpython-311.pyc,,
|
| 242 |
+
fontTools/otlLib/__pycache__/builder.cpython-311.pyc,,
|
| 243 |
+
fontTools/otlLib/__pycache__/error.cpython-311.pyc,,
|
| 244 |
+
fontTools/otlLib/__pycache__/maxContextCalc.cpython-311.pyc,,
|
| 245 |
+
fontTools/otlLib/builder.py,sha256=SFwSVBHxdvSr0hEkBzzdMrBXDrppN1TJIwR3ndYrdtQ,129529
|
| 246 |
+
fontTools/otlLib/error.py,sha256=cthuhBuOwZYpkTLi5gFPupUxkXkCHe-L_YgkE7N1wCI,335
|
| 247 |
+
fontTools/otlLib/maxContextCalc.py,sha256=3es4Kt84TaZ49sA2ev1zrlwPJikJCAECx5KavwhyB-I,3175
|
| 248 |
+
fontTools/otlLib/optimize/__init__.py,sha256=UUQRpNkHU2RczCRt-Gz7sEiYE9AQq9BHLXZEOyvsnX4,1530
|
| 249 |
+
fontTools/otlLib/optimize/__main__.py,sha256=BvP472kA9KxBb9RMyyehPNevAfpmgW9MfdazkUiAO3M,104
|
| 250 |
+
fontTools/otlLib/optimize/__pycache__/__init__.cpython-311.pyc,,
|
| 251 |
+
fontTools/otlLib/optimize/__pycache__/__main__.cpython-311.pyc,,
|
| 252 |
+
fontTools/otlLib/optimize/__pycache__/gpos.cpython-311.pyc,,
|
| 253 |
+
fontTools/otlLib/optimize/gpos.py,sha256=htOgSP743DZDUKF3eWAeJ-kdqNYOnpGXdlV-rbEXJ1A,17668
|
| 254 |
+
fontTools/pens/__init__.py,sha256=DJBWmoX_Haau7qlgmvWyfbhSzrX2qL636Rns7CG01pk,75
|
| 255 |
+
fontTools/pens/__pycache__/__init__.cpython-311.pyc,,
|
| 256 |
+
fontTools/pens/__pycache__/areaPen.cpython-311.pyc,,
|
| 257 |
+
fontTools/pens/__pycache__/basePen.cpython-311.pyc,,
|
| 258 |
+
fontTools/pens/__pycache__/boundsPen.cpython-311.pyc,,
|
| 259 |
+
fontTools/pens/__pycache__/cairoPen.cpython-311.pyc,,
|
| 260 |
+
fontTools/pens/__pycache__/cocoaPen.cpython-311.pyc,,
|
| 261 |
+
fontTools/pens/__pycache__/cu2quPen.cpython-311.pyc,,
|
| 262 |
+
fontTools/pens/__pycache__/explicitClosingLinePen.cpython-311.pyc,,
|
| 263 |
+
fontTools/pens/__pycache__/filterPen.cpython-311.pyc,,
|
| 264 |
+
fontTools/pens/__pycache__/freetypePen.cpython-311.pyc,,
|
| 265 |
+
fontTools/pens/__pycache__/hashPointPen.cpython-311.pyc,,
|
| 266 |
+
fontTools/pens/__pycache__/momentsPen.cpython-311.pyc,,
|
| 267 |
+
fontTools/pens/__pycache__/perimeterPen.cpython-311.pyc,,
|
| 268 |
+
fontTools/pens/__pycache__/pointInsidePen.cpython-311.pyc,,
|
| 269 |
+
fontTools/pens/__pycache__/pointPen.cpython-311.pyc,,
|
| 270 |
+
fontTools/pens/__pycache__/qtPen.cpython-311.pyc,,
|
| 271 |
+
fontTools/pens/__pycache__/qu2cuPen.cpython-311.pyc,,
|
| 272 |
+
fontTools/pens/__pycache__/quartzPen.cpython-311.pyc,,
|
| 273 |
+
fontTools/pens/__pycache__/recordingPen.cpython-311.pyc,,
|
| 274 |
+
fontTools/pens/__pycache__/reportLabPen.cpython-311.pyc,,
|
| 275 |
+
fontTools/pens/__pycache__/reverseContourPen.cpython-311.pyc,,
|
| 276 |
+
fontTools/pens/__pycache__/roundingPen.cpython-311.pyc,,
|
| 277 |
+
fontTools/pens/__pycache__/statisticsPen.cpython-311.pyc,,
|
| 278 |
+
fontTools/pens/__pycache__/svgPathPen.cpython-311.pyc,,
|
| 279 |
+
fontTools/pens/__pycache__/t2CharStringPen.cpython-311.pyc,,
|
| 280 |
+
fontTools/pens/__pycache__/teePen.cpython-311.pyc,,
|
| 281 |
+
fontTools/pens/__pycache__/transformPen.cpython-311.pyc,,
|
| 282 |
+
fontTools/pens/__pycache__/ttGlyphPen.cpython-311.pyc,,
|
| 283 |
+
fontTools/pens/__pycache__/wxPen.cpython-311.pyc,,
|
| 284 |
+
fontTools/pens/areaPen.py,sha256=Y1WkmqzcC4z_bpGAR0IZUKrtHFtxKUQBmr5-64_zCOk,1472
|
| 285 |
+
fontTools/pens/basePen.py,sha256=eIGSKrKm6w4LLHuG6XJoQZ3eObtoKV5P6aF4gT4sk7U,17073
|
| 286 |
+
fontTools/pens/boundsPen.py,sha256=wE3owOQA8DfhH-zBGC3lJvnVwp-oyIt0KZrEqXbmS9I,3129
|
| 287 |
+
fontTools/pens/cairoPen.py,sha256=wuuOJ1qQDSt_K3zscM2nukRyHZTZMwMzzCXCirfq_qQ,592
|
| 288 |
+
fontTools/pens/cocoaPen.py,sha256=IJRQcAxRuVOTQ90bB_Bgjnmz7px_ST5uLF9CW-Y0KPY,612
|
| 289 |
+
fontTools/pens/cu2quPen.py,sha256=gMUwFUsm_-WzBlDjTMQiNnEuI2heomGeOJBX81zYXPo,13007
|
| 290 |
+
fontTools/pens/explicitClosingLinePen.py,sha256=kKKtdZiwaf8Cj4_ytrIDdGB2GMpPPDXm5Nwbw5WDgwU,3219
|
| 291 |
+
fontTools/pens/filterPen.py,sha256=REgspXaaSvF3XUwqe40abe3X_E7-WbBP13IqLUUBLCw,14703
|
| 292 |
+
fontTools/pens/freetypePen.py,sha256=HD-gXJSbgImJdBc8sIBk0HWBdjv3WKFofs6PgCCsGOY,19908
|
| 293 |
+
fontTools/pens/hashPointPen.py,sha256=gElrFyQoOQp3ZbpKHRWPwC61A9OgT2Js8crVUD8BQAY,3573
|
| 294 |
+
fontTools/pens/momentsPen.c,sha256=Oa69GAyoaCsPcsCt58hToFUgpg_tiNCWhQq_xutJ_1U,568777
|
| 295 |
+
fontTools/pens/momentsPen.cpython-311-x86_64-linux-gnu.so,sha256=hHE3LS_BnKTm01olMCu7FdWsQpv65bXpzzpZorOzycc,527624
|
| 296 |
+
fontTools/pens/momentsPen.py,sha256=kjLVXhGe55Abl__Yr1gob0bl0dHe7fPSwyr7TRJnbug,25658
|
| 297 |
+
fontTools/pens/perimeterPen.py,sha256=lr6NzrIWxi4TXBJPbcJsKzqABWfQeil2Bgm9BgUD3N4,2153
|
| 298 |
+
fontTools/pens/pointInsidePen.py,sha256=noEUvBQIeAheDMJwzvvfnEiKhmwbS1i0RQE9jik6Gl4,6355
|
| 299 |
+
fontTools/pens/pointPen.py,sha256=mXO5Tv25kyAdZ9FX29IoTQSjeh00kmtv3SZIMru8ZvI,24604
|
| 300 |
+
fontTools/pens/qtPen.py,sha256=QRNLIry2rQl4E_7ct2tu10-qLHneQp0XV7FfaZ-tcL8,634
|
| 301 |
+
fontTools/pens/qu2cuPen.py,sha256=pRST43-rUpzlOP83Z_Rr0IvIQBCx6RWI6nnNaitQcLk,3985
|
| 302 |
+
fontTools/pens/quartzPen.py,sha256=EH482Kz_xsqYhVRovv6N_T1CXaSvOzUKPLxTaN956tU,1287
|
| 303 |
+
fontTools/pens/recordingPen.py,sha256=VgFZ4NMhnZt1qSTzFEU0cma-gw3kBe47bfSxPYH73rs,12489
|
| 304 |
+
fontTools/pens/reportLabPen.py,sha256=kpfMfOLXt2vOQ5smPsU82ft80FpCPWJzQLl7ENOH8Ew,2066
|
| 305 |
+
fontTools/pens/reverseContourPen.py,sha256=oz64ZRhLAvT7DYMAwGKoLzZXQK8l81jRiYnTZkW6a-Y,4022
|
| 306 |
+
fontTools/pens/roundingPen.py,sha256=vh_FjikRd82-S4I8glgGMGEuGrj5IkCjRT_wmZ8jfqY,4620
|
| 307 |
+
fontTools/pens/statisticsPen.py,sha256=piWK6NjjWqk9MLROjeE2-4EsxVYMyNU7UQFGD_trE9g,9808
|
| 308 |
+
fontTools/pens/svgPathPen.py,sha256=T3b6SZS9B9sVWMK9mSFDtjHeviQs_yOJOZKq5Sg5Zdg,8572
|
| 309 |
+
fontTools/pens/t2CharStringPen.py,sha256=GgGklb5XsCer0w37ujgRLRXx-EuzdFsyCYuzCx4n-Qs,2931
|
| 310 |
+
fontTools/pens/teePen.py,sha256=P1ARJOCMJ6MxK-PB1yZ-ips3CUfnadWYnQ_do6VIasQ,1290
|
| 311 |
+
fontTools/pens/transformPen.py,sha256=s0kUyQdnemUwHvYr2SFboFmh4WY1S9OHBL8L4PJKRwE,4056
|
| 312 |
+
fontTools/pens/ttGlyphPen.py,sha256=yLtB-E5pTQR59OKVYySttWBu1xC2vR8ezSaRhIMtVwg,11870
|
| 313 |
+
fontTools/pens/wxPen.py,sha256=W9RRHlBWHp-CVC4Exvk3ytBmRaB4-LgJPP5Bv7o9BA0,680
|
| 314 |
+
fontTools/qu2cu/__init__.py,sha256=Jfm1JljXbt91w4gyvZn6jzEmVnhRx50sh2fDongrOsE,618
|
| 315 |
+
fontTools/qu2cu/__main__.py,sha256=9FWf6SIZaRaC8SiL0LhjAWC2yIdY9N_9wlRko8m1l2Q,93
|
| 316 |
+
fontTools/qu2cu/__pycache__/__init__.cpython-311.pyc,,
|
| 317 |
+
fontTools/qu2cu/__pycache__/__main__.cpython-311.pyc,,
|
| 318 |
+
fontTools/qu2cu/__pycache__/benchmark.cpython-311.pyc,,
|
| 319 |
+
fontTools/qu2cu/__pycache__/cli.cpython-311.pyc,,
|
| 320 |
+
fontTools/qu2cu/__pycache__/qu2cu.cpython-311.pyc,,
|
| 321 |
+
fontTools/qu2cu/benchmark.py,sha256=GMcr_4r7L6K9SmJ13itt-_XKhnKqSVUDPlXUG6IZmmM,1400
|
| 322 |
+
fontTools/qu2cu/cli.py,sha256=rTuUuk0UX7ki3oIU6rG38U7v3FJapEt4flY3GHP8pPo,3840
|
| 323 |
+
fontTools/qu2cu/qu2cu.c,sha256=ujc5hBu52ZqNMJ2MA4qoGFZnGkOIrV2viE7l_8un7Wk,734539
|
| 324 |
+
fontTools/qu2cu/qu2cu.cpython-311-x86_64-linux-gnu.so,sha256=v4jX6BgGkdvWqG7cDsWRXoaIFCewb6VXkC6f7MBiT0s,792040
|
| 325 |
+
fontTools/qu2cu/qu2cu.py,sha256=DR6f4X0o3bEmhE0zHlwzAozndWtdN0yZ9j751H3rsnE,13117
|
| 326 |
+
fontTools/subset/__init__.py,sha256=R9VoZ2QWhqENHC5Ct1wyhLhEU-xo4mUXwCWl6EZGgwQ,143263
|
| 327 |
+
fontTools/subset/__main__.py,sha256=bhtfP2SqP4k799pxtksFgnC-XGNQDr3LcO4lc8T5e5g,95
|
| 328 |
+
fontTools/subset/__pycache__/__init__.cpython-311.pyc,,
|
| 329 |
+
fontTools/subset/__pycache__/__main__.cpython-311.pyc,,
|
| 330 |
+
fontTools/subset/__pycache__/cff.cpython-311.pyc,,
|
| 331 |
+
fontTools/subset/__pycache__/svg.cpython-311.pyc,,
|
| 332 |
+
fontTools/subset/__pycache__/util.cpython-311.pyc,,
|
| 333 |
+
fontTools/subset/cff.py,sha256=rqMRJOlX5FacV1LW8aDlVOglgEM87TkMA9bdsYenask,6145
|
| 334 |
+
fontTools/subset/svg.py,sha256=sbuR0UHVB_9vYIb6dWCbZ5yCqushkpp5lg-f9NeatBM,9297
|
| 335 |
+
fontTools/subset/util.py,sha256=9SXFYb5Ef9Z58uXmYPCQil8B2i3Q7aFB_1fFDFSppdU,754
|
| 336 |
+
fontTools/svgLib/__init__.py,sha256=IGCLwSbU8jLhq6HI2vSdPQgNs6zDUi5774TgX5MCXPY,75
|
| 337 |
+
fontTools/svgLib/__pycache__/__init__.cpython-311.pyc,,
|
| 338 |
+
fontTools/svgLib/path/__init__.py,sha256=C82fh7xH6ZHsSFVnV848-xeDezpokx1EwTmayJCouFU,1996
|
| 339 |
+
fontTools/svgLib/path/__pycache__/__init__.cpython-311.pyc,,
|
| 340 |
+
fontTools/svgLib/path/__pycache__/arc.cpython-311.pyc,,
|
| 341 |
+
fontTools/svgLib/path/__pycache__/parser.cpython-311.pyc,,
|
| 342 |
+
fontTools/svgLib/path/__pycache__/shapes.cpython-311.pyc,,
|
| 343 |
+
fontTools/svgLib/path/arc.py,sha256=-f5Ym6q4tDWQ76sMNSTUTWgL_7AfgXojvBhtBS7bWwQ,5812
|
| 344 |
+
fontTools/svgLib/path/parser.py,sha256=8T6okMstvgM9ufb2zBcwSzsuuoYbqfnUjNYgb6kjznU,10788
|
| 345 |
+
fontTools/svgLib/path/shapes.py,sha256=5NYE-JSSNsxUt2T20ZK3TIFWrNg3cH3ETvOTwak-6cA,5387
|
| 346 |
+
fontTools/t1Lib/__init__.py,sha256=p42y70wEIbuX0IIxZG7-b_I-gHto1VLy0gLsDvxCfkw,20865
|
| 347 |
+
fontTools/t1Lib/__pycache__/__init__.cpython-311.pyc,,
|
| 348 |
+
fontTools/tfmLib.py,sha256=UMbkM73JXRJVS9t2B-BJc13rSjImaWBuzCoehLwHFhs,14270
|
| 349 |
+
fontTools/ttLib/__init__.py,sha256=1k7qp9z04gA3m6GvxDaINjqrKbzOkdTA_4RnqW_-LrA,661
|
| 350 |
+
fontTools/ttLib/__main__.py,sha256=lHMPWsnzjKPuMFavf6i1gpk9KexiAk4qzgDd50Mbby0,4733
|
| 351 |
+
fontTools/ttLib/__pycache__/__init__.cpython-311.pyc,,
|
| 352 |
+
fontTools/ttLib/__pycache__/__main__.cpython-311.pyc,,
|
| 353 |
+
fontTools/ttLib/__pycache__/macUtils.cpython-311.pyc,,
|
| 354 |
+
fontTools/ttLib/__pycache__/removeOverlaps.cpython-311.pyc,,
|
| 355 |
+
fontTools/ttLib/__pycache__/reorderGlyphs.cpython-311.pyc,,
|
| 356 |
+
fontTools/ttLib/__pycache__/scaleUpem.cpython-311.pyc,,
|
| 357 |
+
fontTools/ttLib/__pycache__/sfnt.cpython-311.pyc,,
|
| 358 |
+
fontTools/ttLib/__pycache__/standardGlyphOrder.cpython-311.pyc,,
|
| 359 |
+
fontTools/ttLib/__pycache__/ttCollection.cpython-311.pyc,,
|
| 360 |
+
fontTools/ttLib/__pycache__/ttFont.cpython-311.pyc,,
|
| 361 |
+
fontTools/ttLib/__pycache__/ttGlyphSet.cpython-311.pyc,,
|
| 362 |
+
fontTools/ttLib/__pycache__/ttVisitor.cpython-311.pyc,,
|
| 363 |
+
fontTools/ttLib/__pycache__/woff2.cpython-311.pyc,,
|
| 364 |
+
fontTools/ttLib/macUtils.py,sha256=lj3oeFpyjV7ko_JqnluneITmAtlc119J-vwTTg2s73A,1737
|
| 365 |
+
fontTools/ttLib/removeOverlaps.py,sha256=ny3XhFw-RrriJ6n0sSh4SaVaKc3GhmCVZMw8g4oI0TY,12744
|
| 366 |
+
fontTools/ttLib/reorderGlyphs.py,sha256=TbxLxqPTUGiKRX3ulGFCwVm2lEisFYlX6caONJr_4oY,10371
|
| 367 |
+
fontTools/ttLib/scaleUpem.py,sha256=U_-NGkwfS9GRIackdEXjGYZ-wSomcUPXQahDneLeArI,14618
|
| 368 |
+
fontTools/ttLib/sfnt.py,sha256=D5f7kvZX7rXDcmDqVBXqPPki4k27QgiBFYi8ziH2OiU,22981
|
| 369 |
+
fontTools/ttLib/standardGlyphOrder.py,sha256=7AY_fVWdtwZ4iv5uWdyKAUcbEQiSDt1lN4sqx9xXwE0,5785
|
| 370 |
+
fontTools/ttLib/tables/B_A_S_E_.py,sha256=H71A9pJ850mvjbrWHqy8iFI2Dxg7102YRtAkfdCooig,369
|
| 371 |
+
fontTools/ttLib/tables/BitmapGlyphMetrics.py,sha256=9gcGPVzsxEYnVBO7YLWfeOuht9PaCl09GmbAqDYqKi0,1769
|
| 372 |
+
fontTools/ttLib/tables/C_B_D_T_.py,sha256=5LNdc8FMir1kC5fvp5iHwWfeuE-RuqdxAArFXaqPjQ0,3646
|
| 373 |
+
fontTools/ttLib/tables/C_B_L_C_.py,sha256=YXlwovoCHYx8THLQD9iBU_VGoaB9LFObEKtL6ddD320,520
|
| 374 |
+
fontTools/ttLib/tables/C_F_F_.py,sha256=yg3mUtYBudgmpG7Bz475j_DNnCelsgrTsM8DH1uR4ek,1978
|
| 375 |
+
fontTools/ttLib/tables/C_F_F__2.py,sha256=YoHfJQdF-ezx4OwRQ2Y2O7rRJEPjOkf3Hx5Y11Xq0AM,807
|
| 376 |
+
fontTools/ttLib/tables/C_O_L_R_.py,sha256=SHwFVNVmoUQR2e87KuTSe-J9LfeegS4f2hEpee29_2o,5993
|
| 377 |
+
fontTools/ttLib/tables/C_P_A_L_.py,sha256=odFjqM4GnjXyQYGEC-e0Gvqms1jQ5zHHG3SDg7y-BI0,11942
|
| 378 |
+
fontTools/ttLib/tables/D_S_I_G_.py,sha256=ahBwKMgJf9hPm3ETuF1IvG4d1_UlSW0UdzO85DibOck,5903
|
| 379 |
+
fontTools/ttLib/tables/D__e_b_g.py,sha256=KDnfkNOUnm3F13wD_j3YNBOvYadZ40Gf_0170hFkJp0,1134
|
| 380 |
+
fontTools/ttLib/tables/DefaultTable.py,sha256=moj0d0iIyZQt_7EVK024tP7JjJSP9HIwamQ-Big252A,1913
|
| 381 |
+
fontTools/ttLib/tables/E_B_D_T_.py,sha256=uOpmt25gOJQeO1u1IGAyPWgVmh-4vSZqrQEHvOYwbwg,32534
|
| 382 |
+
fontTools/ttLib/tables/E_B_L_C_.py,sha256=LfEVzBg_yWr9dhChzS0U2G-7wNOwzwB0LWoXIUYNKKM,30054
|
| 383 |
+
fontTools/ttLib/tables/F_F_T_M_.py,sha256=_450vdbEH7Y-0_rOwb3Q0hg-Qq2W8C_sHljy7rZtqqM,1683
|
| 384 |
+
fontTools/ttLib/tables/F__e_a_t.py,sha256=LAk4RCO66ErHFKpcm-z7YKD33_7w3yZ1NFmyF6GRGUM,5947
|
| 385 |
+
fontTools/ttLib/tables/G_D_E_F_.py,sha256=QXiILFCRnPNZcwpub6ojN5S9WP6y56LsXi25pUWLgp4,299
|
| 386 |
+
fontTools/ttLib/tables/G_P_O_S_.py,sha256=UkP3mlnyvQg-jj6ZBOh6j-OieVg_goJQ31nlLvoLGSI,397
|
| 387 |
+
fontTools/ttLib/tables/G_S_U_B_.py,sha256=cwFMKO-pgwsn1H8Q9Jb58Z6ZrBrCoN0sqJB0YunBfSk,294
|
| 388 |
+
fontTools/ttLib/tables/G_V_A_R_.py,sha256=13oO2dD-L4yfkrBuR-KN2rc40wh5lLIlx_khwMz5GH4,94
|
| 389 |
+
fontTools/ttLib/tables/G__l_a_t.py,sha256=Xh3IzFgYlvNjrAOn7Ja73DrWrQTJgJxmDFSUKS6yHdM,8645
|
| 390 |
+
fontTools/ttLib/tables/G__l_o_c.py,sha256=5DsxGzaG7HyJVvLlKQeff1lXt-XPWaHNNaf-EYwsKh4,2685
|
| 391 |
+
fontTools/ttLib/tables/H_V_A_R_.py,sha256=6kPLDUGT8EussA3y9gKr_mrgY5PNv7YaK1V0keMXD9w,313
|
| 392 |
+
fontTools/ttLib/tables/I_F_T_.py,sha256=d63nXOfLF7WqGrNj99PcLkvLIiCQ3JdZl5Sf9a7ITGk,272
|
| 393 |
+
fontTools/ttLib/tables/I_F_T_X_.py,sha256=5A7KfKBr_7FgtkQV6NT2YS1eGlrWrOnjYrLnG-BGFNY,274
|
| 394 |
+
fontTools/ttLib/tables/J_S_T_F_.py,sha256=Q9TEf3OuyDIxZlmoz9a3c-mDMlJK6YBQ9KcYmiwFRbU,315
|
| 395 |
+
fontTools/ttLib/tables/L_T_S_H_.py,sha256=Iu6syJFuhJj0_7Aan2NPlDuQDIq-AzLwsOQbXVTnlL0,2189
|
| 396 |
+
fontTools/ttLib/tables/M_A_T_H_.py,sha256=-TVu9Nlcs-1shkElbIk-CWtUwXUMdycHFkjvPE8C_fs,342
|
| 397 |
+
fontTools/ttLib/tables/M_V_A_R_.py,sha256=67cEuiTw5y5W1Zk98L_S_SmJINIfy_mzWCkyHcujz94,308
|
| 398 |
+
fontTools/ttLib/tables/O_S_2f_2.py,sha256=DwgOLNqcA0IIWLS8_G5Pgy41aH-HCEkOXlP1qGu2jlk,28030
|
| 399 |
+
fontTools/ttLib/tables/S_T_A_T_.py,sha256=y9NiWCtnlZtMjw4K9_SdA84Xa-dJk7G5eb2dSe6ciWc,498
|
| 400 |
+
fontTools/ttLib/tables/S_V_G_.py,sha256=vT6QTW5ArtskVUxnPEH_ZxKz4DF4v1pKbylN6DG0R3o,7676
|
| 401 |
+
fontTools/ttLib/tables/S__i_l_f.py,sha256=lPQV2RdhcJRgfDzHp_dkgSxVUUdkcAnY1Bz7V18Gt9U,34985
|
| 402 |
+
fontTools/ttLib/tables/S__i_l_l.py,sha256=Vjtn7SI83vaLGIuQf2e-jhZSFOXb9vXB4jwqznjqnMc,3224
|
| 403 |
+
fontTools/ttLib/tables/T_S_I_B_.py,sha256=3WhEtyNnjYumcowD0GpjubrgnS-RzouZxCxEe4yLDo8,341
|
| 404 |
+
fontTools/ttLib/tables/T_S_I_C_.py,sha256=hAV9Hq_ALsWaducDpw1tDRREvFL7hx7onnUF0sXTelU,381
|
| 405 |
+
fontTools/ttLib/tables/T_S_I_D_.py,sha256=TsdX-G2xxVQO9sSE1wE_xDRx-gor5YiXTHeUthMwCPY,341
|
| 406 |
+
fontTools/ttLib/tables/T_S_I_J_.py,sha256=x8Tlvi6aTxoQcI12UL7muoWF1Q61iBDseAS1mRdOYrg,341
|
| 407 |
+
fontTools/ttLib/tables/T_S_I_P_.py,sha256=-il2ucTBOghVBY7cmleHdLZc3W3CKh7-iPPT0A3KBzk,341
|
| 408 |
+
fontTools/ttLib/tables/T_S_I_S_.py,sha256=tVBnl63vyZUIq93oM6dEjHCXvPn9vt5vvL3jG59b0Lg,341
|
| 409 |
+
fontTools/ttLib/tables/T_S_I_V_.py,sha256=iUWxz2MSrtw7mzuQZj30QAJrCPnyJ4GincFfySFUNAg,855
|
| 410 |
+
fontTools/ttLib/tables/T_S_I__0.py,sha256=O-2oI0eBgt4mP15-UwH0_0r7YWi3EEEhG-4etqDueGI,2505
|
| 411 |
+
fontTools/ttLib/tables/T_S_I__1.py,sha256=nSUhni-fvYmeKXW4zLfP3FG_3LQU2QKPKS1_gKY5lYg,6971
|
| 412 |
+
fontTools/ttLib/tables/T_S_I__2.py,sha256=q2rub-d77iWWiBM6awO0-TCl-Xq7kalPobHYC2QEOfc,496
|
| 413 |
+
fontTools/ttLib/tables/T_S_I__3.py,sha256=0LcvvCzVZJzyz7i4zjIkUuYXEqXwOCs9WeCsgDFqKJ8,543
|
| 414 |
+
fontTools/ttLib/tables/T_S_I__5.py,sha256=hhvJn6jiXs8kuBtun8krNUTXTljH-eKxaxXM1T-7SXM,1905
|
| 415 |
+
fontTools/ttLib/tables/T_T_F_A_.py,sha256=LuT0w__AMtawnsBMobhEMW9gp2yk0mA5ZRzwF45c0UI,392
|
| 416 |
+
fontTools/ttLib/tables/TupleVariation.py,sha256=1Cot3Eoj-O_JfEPUKd2wJh1jJoqs8eiD0smaQxu9FlM,32196
|
| 417 |
+
fontTools/ttLib/tables/V_A_R_C_.py,sha256=3jFX50J6X-Cc4dwwiztKKsDTRXVHTXlVdQH328UN1-k,289
|
| 418 |
+
fontTools/ttLib/tables/V_D_M_X_.py,sha256=RbHl7vvO9pcjT_kKvcCmcByQj39n4PmVeq55wD5C14g,10437
|
| 419 |
+
fontTools/ttLib/tables/V_O_R_G_.py,sha256=Cn3OxjVtcO-Uvp61P5c2336V9iEbuGr6vWAXnSIaihk,5965
|
| 420 |
+
fontTools/ttLib/tables/V_V_A_R_.py,sha256=Cstw6tc_U4-EmTriRItBSpvTJODAjMFQjfyTaxLzsbI,319
|
| 421 |
+
fontTools/ttLib/tables/__init__.py,sha256=WRAkPL6KLlvwjJoJo3z3btfFJ71S9z4qLmbxMYmlJlA,2622
|
| 422 |
+
fontTools/ttLib/tables/__pycache__/B_A_S_E_.cpython-311.pyc,,
|
| 423 |
+
fontTools/ttLib/tables/__pycache__/BitmapGlyphMetrics.cpython-311.pyc,,
|
| 424 |
+
fontTools/ttLib/tables/__pycache__/C_B_D_T_.cpython-311.pyc,,
|
| 425 |
+
fontTools/ttLib/tables/__pycache__/C_B_L_C_.cpython-311.pyc,,
|
| 426 |
+
fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-311.pyc,,
|
| 427 |
+
fontTools/ttLib/tables/__pycache__/C_F_F__2.cpython-311.pyc,,
|
| 428 |
+
fontTools/ttLib/tables/__pycache__/C_O_L_R_.cpython-311.pyc,,
|
| 429 |
+
fontTools/ttLib/tables/__pycache__/C_P_A_L_.cpython-311.pyc,,
|
| 430 |
+
fontTools/ttLib/tables/__pycache__/D_S_I_G_.cpython-311.pyc,,
|
| 431 |
+
fontTools/ttLib/tables/__pycache__/D__e_b_g.cpython-311.pyc,,
|
| 432 |
+
fontTools/ttLib/tables/__pycache__/DefaultTable.cpython-311.pyc,,
|
| 433 |
+
fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-311.pyc,,
|
| 434 |
+
fontTools/ttLib/tables/__pycache__/E_B_L_C_.cpython-311.pyc,,
|
| 435 |
+
fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-311.pyc,,
|
| 436 |
+
fontTools/ttLib/tables/__pycache__/F__e_a_t.cpython-311.pyc,,
|
| 437 |
+
fontTools/ttLib/tables/__pycache__/G_D_E_F_.cpython-311.pyc,,
|
| 438 |
+
fontTools/ttLib/tables/__pycache__/G_P_O_S_.cpython-311.pyc,,
|
| 439 |
+
fontTools/ttLib/tables/__pycache__/G_S_U_B_.cpython-311.pyc,,
|
| 440 |
+
fontTools/ttLib/tables/__pycache__/G_V_A_R_.cpython-311.pyc,,
|
| 441 |
+
fontTools/ttLib/tables/__pycache__/G__l_a_t.cpython-311.pyc,,
|
| 442 |
+
fontTools/ttLib/tables/__pycache__/G__l_o_c.cpython-311.pyc,,
|
| 443 |
+
fontTools/ttLib/tables/__pycache__/H_V_A_R_.cpython-311.pyc,,
|
| 444 |
+
fontTools/ttLib/tables/__pycache__/I_F_T_.cpython-311.pyc,,
|
| 445 |
+
fontTools/ttLib/tables/__pycache__/I_F_T_X_.cpython-311.pyc,,
|
| 446 |
+
fontTools/ttLib/tables/__pycache__/J_S_T_F_.cpython-311.pyc,,
|
| 447 |
+
fontTools/ttLib/tables/__pycache__/L_T_S_H_.cpython-311.pyc,,
|
| 448 |
+
fontTools/ttLib/tables/__pycache__/M_A_T_H_.cpython-311.pyc,,
|
| 449 |
+
fontTools/ttLib/tables/__pycache__/M_V_A_R_.cpython-311.pyc,,
|
| 450 |
+
fontTools/ttLib/tables/__pycache__/O_S_2f_2.cpython-311.pyc,,
|
| 451 |
+
fontTools/ttLib/tables/__pycache__/S_T_A_T_.cpython-311.pyc,,
|
| 452 |
+
fontTools/ttLib/tables/__pycache__/S_V_G_.cpython-311.pyc,,
|
| 453 |
+
fontTools/ttLib/tables/__pycache__/S__i_l_f.cpython-311.pyc,,
|
| 454 |
+
fontTools/ttLib/tables/__pycache__/S__i_l_l.cpython-311.pyc,,
|
| 455 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_B_.cpython-311.pyc,,
|
| 456 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_C_.cpython-311.pyc,,
|
| 457 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_D_.cpython-311.pyc,,
|
| 458 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_J_.cpython-311.pyc,,
|
| 459 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_P_.cpython-311.pyc,,
|
| 460 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_S_.cpython-311.pyc,,
|
| 461 |
+
fontTools/ttLib/tables/__pycache__/T_S_I_V_.cpython-311.pyc,,
|
| 462 |
+
fontTools/ttLib/tables/__pycache__/T_S_I__0.cpython-311.pyc,,
|
| 463 |
+
fontTools/ttLib/tables/__pycache__/T_S_I__1.cpython-311.pyc,,
|
| 464 |
+
fontTools/ttLib/tables/__pycache__/T_S_I__2.cpython-311.pyc,,
|
| 465 |
+
fontTools/ttLib/tables/__pycache__/T_S_I__3.cpython-311.pyc,,
|
| 466 |
+
fontTools/ttLib/tables/__pycache__/T_S_I__5.cpython-311.pyc,,
|
| 467 |
+
fontTools/ttLib/tables/__pycache__/T_T_F_A_.cpython-311.pyc,,
|
| 468 |
+
fontTools/ttLib/tables/__pycache__/TupleVariation.cpython-311.pyc,,
|
| 469 |
+
fontTools/ttLib/tables/__pycache__/V_A_R_C_.cpython-311.pyc,,
|
| 470 |
+
fontTools/ttLib/tables/__pycache__/V_D_M_X_.cpython-311.pyc,,
|
| 471 |
+
fontTools/ttLib/tables/__pycache__/V_O_R_G_.cpython-311.pyc,,
|
| 472 |
+
fontTools/ttLib/tables/__pycache__/V_V_A_R_.cpython-311.pyc,,
|
| 473 |
+
fontTools/ttLib/tables/__pycache__/__init__.cpython-311.pyc,,
|
| 474 |
+
fontTools/ttLib/tables/__pycache__/_a_n_k_r.cpython-311.pyc,,
|
| 475 |
+
fontTools/ttLib/tables/__pycache__/_a_v_a_r.cpython-311.pyc,,
|
| 476 |
+
fontTools/ttLib/tables/__pycache__/_b_g_c_l.cpython-311.pyc,,
|
| 477 |
+
fontTools/ttLib/tables/__pycache__/_b_s_l_n.cpython-311.pyc,,
|
| 478 |
+
fontTools/ttLib/tables/__pycache__/_c_i_d_g.cpython-311.pyc,,
|
| 479 |
+
fontTools/ttLib/tables/__pycache__/_c_m_a_p.cpython-311.pyc,,
|
| 480 |
+
fontTools/ttLib/tables/__pycache__/_c_v_a_r.cpython-311.pyc,,
|
| 481 |
+
fontTools/ttLib/tables/__pycache__/_c_v_t.cpython-311.pyc,,
|
| 482 |
+
fontTools/ttLib/tables/__pycache__/_f_e_a_t.cpython-311.pyc,,
|
| 483 |
+
fontTools/ttLib/tables/__pycache__/_f_p_g_m.cpython-311.pyc,,
|
| 484 |
+
fontTools/ttLib/tables/__pycache__/_f_v_a_r.cpython-311.pyc,,
|
| 485 |
+
fontTools/ttLib/tables/__pycache__/_g_a_s_p.cpython-311.pyc,,
|
| 486 |
+
fontTools/ttLib/tables/__pycache__/_g_c_i_d.cpython-311.pyc,,
|
| 487 |
+
fontTools/ttLib/tables/__pycache__/_g_l_y_f.cpython-311.pyc,,
|
| 488 |
+
fontTools/ttLib/tables/__pycache__/_g_v_a_r.cpython-311.pyc,,
|
| 489 |
+
fontTools/ttLib/tables/__pycache__/_h_d_m_x.cpython-311.pyc,,
|
| 490 |
+
fontTools/ttLib/tables/__pycache__/_h_e_a_d.cpython-311.pyc,,
|
| 491 |
+
fontTools/ttLib/tables/__pycache__/_h_h_e_a.cpython-311.pyc,,
|
| 492 |
+
fontTools/ttLib/tables/__pycache__/_h_m_t_x.cpython-311.pyc,,
|
| 493 |
+
fontTools/ttLib/tables/__pycache__/_k_e_r_n.cpython-311.pyc,,
|
| 494 |
+
fontTools/ttLib/tables/__pycache__/_l_c_a_r.cpython-311.pyc,,
|
| 495 |
+
fontTools/ttLib/tables/__pycache__/_l_o_c_a.cpython-311.pyc,,
|
| 496 |
+
fontTools/ttLib/tables/__pycache__/_l_t_a_g.cpython-311.pyc,,
|
| 497 |
+
fontTools/ttLib/tables/__pycache__/_m_a_x_p.cpython-311.pyc,,
|
| 498 |
+
fontTools/ttLib/tables/__pycache__/_m_e_t_a.cpython-311.pyc,,
|
| 499 |
+
fontTools/ttLib/tables/__pycache__/_m_o_r_t.cpython-311.pyc,,
|
| 500 |
+
fontTools/ttLib/tables/__pycache__/_m_o_r_x.cpython-311.pyc,,
|
| 501 |
+
fontTools/ttLib/tables/__pycache__/_n_a_m_e.cpython-311.pyc,,
|
| 502 |
+
fontTools/ttLib/tables/__pycache__/_o_p_b_d.cpython-311.pyc,,
|
| 503 |
+
fontTools/ttLib/tables/__pycache__/_p_o_s_t.cpython-311.pyc,,
|
| 504 |
+
fontTools/ttLib/tables/__pycache__/_p_r_e_p.cpython-311.pyc,,
|
| 505 |
+
fontTools/ttLib/tables/__pycache__/_p_r_o_p.cpython-311.pyc,,
|
| 506 |
+
fontTools/ttLib/tables/__pycache__/_s_b_i_x.cpython-311.pyc,,
|
| 507 |
+
fontTools/ttLib/tables/__pycache__/_t_r_a_k.cpython-311.pyc,,
|
| 508 |
+
fontTools/ttLib/tables/__pycache__/_v_h_e_a.cpython-311.pyc,,
|
| 509 |
+
fontTools/ttLib/tables/__pycache__/_v_m_t_x.cpython-311.pyc,,
|
| 510 |
+
fontTools/ttLib/tables/__pycache__/asciiTable.cpython-311.pyc,,
|
| 511 |
+
fontTools/ttLib/tables/__pycache__/grUtils.cpython-311.pyc,,
|
| 512 |
+
fontTools/ttLib/tables/__pycache__/otBase.cpython-311.pyc,,
|
| 513 |
+
fontTools/ttLib/tables/__pycache__/otConverters.cpython-311.pyc,,
|
| 514 |
+
fontTools/ttLib/tables/__pycache__/otData.cpython-311.pyc,,
|
| 515 |
+
fontTools/ttLib/tables/__pycache__/otDataSchema.cpython-311.pyc,,
|
| 516 |
+
fontTools/ttLib/tables/__pycache__/otTables.cpython-311.pyc,,
|
| 517 |
+
fontTools/ttLib/tables/__pycache__/otTraverse.cpython-311.pyc,,
|
| 518 |
+
fontTools/ttLib/tables/__pycache__/sbixGlyph.cpython-311.pyc,,
|
| 519 |
+
fontTools/ttLib/tables/__pycache__/sbixStrike.cpython-311.pyc,,
|
| 520 |
+
fontTools/ttLib/tables/__pycache__/ttProgram.cpython-311.pyc,,
|
| 521 |
+
fontTools/ttLib/tables/_a_n_k_r.py,sha256=MpAzIifmIi_3gx2oP6PC3R2lu36Ewsr2-W1rXjsz2Ug,483
|
| 522 |
+
fontTools/ttLib/tables/_a_v_a_r.py,sha256=_qplWEwFos0VwRTdZa7LhfLIWw-CF1G76NbiRM_Rgvs,7374
|
| 523 |
+
fontTools/ttLib/tables/_b_g_c_l.py,sha256=e8-vrpQlyh2CBnIRIYAK9xcMtWXdXr0i1Gmz13eTOsk,5484
|
| 524 |
+
fontTools/ttLib/tables/_b_s_l_n.py,sha256=_848o7SQqztzBDfHYei-80u9ltxIHVBzXu1dYHLV57M,465
|
| 525 |
+
fontTools/ttLib/tables/_c_i_d_g.py,sha256=yt8rVIadpJSDUCoVH4dZetNiy0Azm5ESAxHjB2BX_eA,913
|
| 526 |
+
fontTools/ttLib/tables/_c_m_a_p.py,sha256=1bfeetlu0fMcipG1n5pS6XccmeDrtUoq_KSSNt8EVNM,62544
|
| 527 |
+
fontTools/ttLib/tables/_c_v_a_r.py,sha256=35ayk2kX1pcLGwyx0y4I1l-r7LHgdKv0ulVx8oBPteI,3527
|
| 528 |
+
fontTools/ttLib/tables/_c_v_t.py,sha256=1_RhEcTmhWQWQp7Hsj8UsByKmXCIppZyIbIArGywEEM,1618
|
| 529 |
+
fontTools/ttLib/tables/_f_e_a_t.py,sha256=Fi1XnjhkCG0tp43AcvpIaivD-YRFpufo6feGIrenQDo,469
|
| 530 |
+
fontTools/ttLib/tables/_f_p_g_m.py,sha256=uZHZzqL6OdLn_Hxskv-xf3XuE4fyaSv_jbALEjwXYug,1633
|
| 531 |
+
fontTools/ttLib/tables/_f_v_a_r.py,sha256=NTpSm77_UDcPtQMg8etrkRVmm6P23vESpe_WAbFP03o,8808
|
| 532 |
+
fontTools/ttLib/tables/_g_a_s_p.py,sha256=YvhAVDvdssN2fjPMTfSrO4WBCfTuh9T2cU5zquDVnSw,2203
|
| 533 |
+
fontTools/ttLib/tables/_g_c_i_d.py,sha256=AJ4uV7PTHbnsw4Tfw8c2Ezh0VMox3oAH0qhhq7y8hdM,362
|
| 534 |
+
fontTools/ttLib/tables/_g_l_y_f.py,sha256=O9TATqc30B_Z7h-HwBfAeRaOM0Al84VpcReAfFsYodU,85308
|
| 535 |
+
fontTools/ttLib/tables/_g_v_a_r.py,sha256=E9WCKjeITUfd5hcJLQ0rjQFBtZdxw1eswFlWp1U6bD4,12196
|
| 536 |
+
fontTools/ttLib/tables/_h_d_m_x.py,sha256=wMrO4D04QNT8u30p8AV-aG3bndXCq4wlPNvtbd8ip7c,4252
|
| 537 |
+
fontTools/ttLib/tables/_h_e_a_d.py,sha256=yY2GTFq6Mn6nN8EegbMVJRMUWIqDYFln3FhTk3ziw6s,4926
|
| 538 |
+
fontTools/ttLib/tables/_h_h_e_a.py,sha256=X4t1aF1MZMuz3phCVSFwKcNTeoZdx-042wFtHc-nK9w,4767
|
| 539 |
+
fontTools/ttLib/tables/_h_m_t_x.py,sha256=rbxr3cy9-9Jm0HCGIWQiX6fGH5iu6yojp9kfgWrW2Ks,6192
|
| 540 |
+
fontTools/ttLib/tables/_k_e_r_n.py,sha256=DQNLmD_HEdDKPfp4tamOd9W3T5a1lXFM5tDaWrKl164,10794
|
| 541 |
+
fontTools/ttLib/tables/_l_c_a_r.py,sha256=8W6xFOj-sm003MCXX4bIHxs9ntfVvT0FXYllPxa3z4I,390
|
| 542 |
+
fontTools/ttLib/tables/_l_o_c_a.py,sha256=yxiwLKXLZjNju5XYmLb6EhNLec1d7ezEDDe1dszceHo,2180
|
| 543 |
+
fontTools/ttLib/tables/_l_t_a_g.py,sha256=9YpApjI-rZ4e3HeT8Pj-osiHl3uALD9JXg5O7pqk9L0,2552
|
| 544 |
+
fontTools/ttLib/tables/_m_a_x_p.py,sha256=cIDIZWse9czwwsnlxIh3qwgwaXbt7PQAjXKAcmMDspY,5264
|
| 545 |
+
fontTools/ttLib/tables/_m_e_t_a.py,sha256=A0CZPEAVxYrpytjXUGQJCTddwG8KrvUVbtBe3A1MqgI,3913
|
| 546 |
+
fontTools/ttLib/tables/_m_o_r_t.py,sha256=u35tYqn3cjzKxeCF0FUFeLtaf36mjDDSN08uuk0Kme8,487
|
| 547 |
+
fontTools/ttLib/tables/_m_o_r_x.py,sha256=OwamVpIO7REDnFr95HuFPoY_0U6i9zQPb11K1sFTvDY,548
|
| 548 |
+
fontTools/ttLib/tables/_n_a_m_e.py,sha256=86_0fUeA5_c-GY5ZnkqUI0jyWwMh1mn6yVOf6KKqIlU,41266
|
| 549 |
+
fontTools/ttLib/tables/_o_p_b_d.py,sha256=TNZv_2YTrj4dGzd6wA9Jb-KGZ99un177s5p3LlfxQ74,448
|
| 550 |
+
fontTools/ttLib/tables/_p_o_s_t.py,sha256=9siVXSisWGdTfj_mC1E9dUDz9Jdm1i3QzI-l3i3VWME,11671
|
| 551 |
+
fontTools/ttLib/tables/_p_r_e_p.py,sha256=CcKr4HrswkupLmbJdrJLTM-z9XgLefQyv8467j9V0zs,427
|
| 552 |
+
fontTools/ttLib/tables/_p_r_o_p.py,sha256=Eg8x5qWyXDzPezMafFu0s0qyPDHj-sPsFxGtE6h29qo,427
|
| 553 |
+
fontTools/ttLib/tables/_s_b_i_x.py,sha256=tkkKbNKNYkUhZJuN0kl7q37x5KK5OovB06y28obPV6A,4865
|
| 554 |
+
fontTools/ttLib/tables/_t_r_a_k.py,sha256=YJHZy28-h7LlTGykF7SuU8lrgD9lQgznkUxz-TxdFUU,11350
|
| 555 |
+
fontTools/ttLib/tables/_v_h_e_a.py,sha256=FuULIBl4OQyUeLPOFEY8buB0pAnQhGa1-5a6kN9i5Sc,4459
|
| 556 |
+
fontTools/ttLib/tables/_v_m_t_x.py,sha256=AUuxtyQvMWrTBNbOIaL6uKcB_DNpNb0YX28JIuTHw_Y,500
|
| 557 |
+
fontTools/ttLib/tables/asciiTable.py,sha256=4c69jsAirUnDEpylf9CYBoCKTzwbmfbtUAOrtPnpHjY,637
|
| 558 |
+
fontTools/ttLib/tables/grUtils.py,sha256=hcOJ5oJPOd2uJWnWA7qwR7AfL37YZ5zUT7g8o5BBV80,2270
|
| 559 |
+
fontTools/ttLib/tables/otBase.py,sha256=Cje7tkdabZ8fowzz1dXrBcSOtRdpBgvpAq5tQBUKkXA,53237
|
| 560 |
+
fontTools/ttLib/tables/otConverters.py,sha256=fgVqc1I_99rbVC9dkF8RFidTZLAyrFKaxBqXdcnProY,85940
|
| 561 |
+
fontTools/ttLib/tables/otData.py,sha256=RyvA-k_3FgwL_hkrGd_IdZHGXeZVdKKr9Xq6ZK5uCek,203917
|
| 562 |
+
fontTools/ttLib/tables/otDataSchema.py,sha256=JWAnyuhMTfT2satixLYsL8ci0jvWArQqOM3D_9Y1gqA,1667
|
| 563 |
+
fontTools/ttLib/tables/otTables.py,sha256=QlTXte1aHGTQ4m7N1O5rCNq9gh7yo-4c7GDF7d_u76c,98116
|
| 564 |
+
fontTools/ttLib/tables/otTraverse.py,sha256=HznEVAlVf_8eyqjsO2edgELtMlXnjnUqccK3PytvVUE,5518
|
| 565 |
+
fontTools/ttLib/tables/sbixGlyph.py,sha256=tjEUPVRfx6gr5yme8UytGTtVrimKN5qmbzT1GZPjXiM,5796
|
| 566 |
+
fontTools/ttLib/tables/sbixStrike.py,sha256=dL8O9K8R4S6RVQDP-PVjIPBrvbqbE9zwra0uRL0nLq0,6651
|
| 567 |
+
fontTools/ttLib/tables/table_API_readme.txt,sha256=eZlRTLUkLzc_9Ot3pdfhyMb3ahU0_Iipx0vSbzOVGy8,2748
|
| 568 |
+
fontTools/ttLib/tables/ttProgram.py,sha256=LT9NCxufFPlA6dRkYdYsawmOXIJ5rhauQ4nfy4_z8tQ,36005
|
| 569 |
+
fontTools/ttLib/ttCollection.py,sha256=aRph2MkBK3kd9-JCLqhJ1EN9pffN_lVX6WWmOTTewc8,3963
|
| 570 |
+
fontTools/ttLib/ttFont.py,sha256=otE7aE6JjnE98OtfQYF-ve7AnNaLpBMq1R6z88_rnDw,63517
|
| 571 |
+
fontTools/ttLib/ttGlyphSet.py,sha256=cUBhMGa5hszeVqOm2KpOdeJh-LsiqE7RNdyIUPZ2vO8,17476
|
| 572 |
+
fontTools/ttLib/ttVisitor.py,sha256=_tah4C42Tv6Pm9QeLNQwwVCxqI4VNEAqYCbmThp6cvY,1025
|
| 573 |
+
fontTools/ttLib/woff2.py,sha256=6LPISeBQ1dubzKjWrUcYm_vgETC46BTLY4XkG52qvSA,60921
|
| 574 |
+
fontTools/ttx.py,sha256=FxuGubujWCGJWSTrJEjoNH--25fVIPy-ZRtYy9H6iTk,17277
|
| 575 |
+
fontTools/ufoLib/__init__.py,sha256=chTCZoHcVj85nXt66BIcr4BrxgeFTQHVSq_HOkRQKQs,98982
|
| 576 |
+
fontTools/ufoLib/__pycache__/__init__.cpython-311.pyc,,
|
| 577 |
+
fontTools/ufoLib/__pycache__/converters.cpython-311.pyc,,
|
| 578 |
+
fontTools/ufoLib/__pycache__/errors.cpython-311.pyc,,
|
| 579 |
+
fontTools/ufoLib/__pycache__/etree.cpython-311.pyc,,
|
| 580 |
+
fontTools/ufoLib/__pycache__/filenames.cpython-311.pyc,,
|
| 581 |
+
fontTools/ufoLib/__pycache__/glifLib.cpython-311.pyc,,
|
| 582 |
+
fontTools/ufoLib/__pycache__/kerning.cpython-311.pyc,,
|
| 583 |
+
fontTools/ufoLib/__pycache__/plistlib.cpython-311.pyc,,
|
| 584 |
+
fontTools/ufoLib/__pycache__/pointPen.cpython-311.pyc,,
|
| 585 |
+
fontTools/ufoLib/__pycache__/utils.cpython-311.pyc,,
|
| 586 |
+
fontTools/ufoLib/__pycache__/validators.cpython-311.pyc,,
|
| 587 |
+
fontTools/ufoLib/converters.py,sha256=YnBKr8kmyjwLcq8LdD46ubGOgyL9Pxt9avlvZn9anKI,13444
|
| 588 |
+
fontTools/ufoLib/errors.py,sha256=9f8l5NaFAj3BZPa6Bbqt06FL4afffLuMzy4nPf-eOlE,845
|
| 589 |
+
fontTools/ufoLib/etree.py,sha256=T3sjLTgjMAq6VyYRicWPaMIVBJ2YSuwZxV6Vc5yZtQI,231
|
| 590 |
+
fontTools/ufoLib/filenames.py,sha256=hoyUhzzQMDaeckT7UdreISANq4-gLR2jGyk5yAyYtOA,10654
|
| 591 |
+
fontTools/ufoLib/glifLib.py,sha256=VBbz67ece59g_re8GxtEWDP3zh6Fqsf3lmFXr7zxDoA,77495
|
| 592 |
+
fontTools/ufoLib/kerning.py,sha256=o1BeJDVZ_CZZPzmOPwRKTqglYmhA_JZPjwq2JLgdQIk,4836
|
| 593 |
+
fontTools/ufoLib/plistlib.py,sha256=jzMGOGvHO6XvS-IO8hS04ur7r8-v2dnVq-vKMoJZvqQ,1510
|
| 594 |
+
fontTools/ufoLib/pointPen.py,sha256=CuREcm3IYteZNBDAd_ZRAV4XqBsy0s07jdWc4en9r-8,244
|
| 595 |
+
fontTools/ufoLib/utils.py,sha256=nZoJJqHXQSL-LXYE58_WHA97XlbTkEbYkdH3GL32SmQ,3192
|
| 596 |
+
fontTools/ufoLib/validators.py,sha256=Il9qYYVj9Po51_IGVGmeVE2SXf77pFccgJpVLkgAFKk,31991
|
| 597 |
+
fontTools/unicode.py,sha256=ZZ7OMmWvIyV1IL1k6ioTzaRAh3tUvm6gvK7QgFbOIHY,1237
|
| 598 |
+
fontTools/unicodedata/Blocks.py,sha256=frShN07WqD1uLt-V0TNlUZPnn0-cKc0Nuhtd2uNDoSw,33139
|
| 599 |
+
fontTools/unicodedata/Mirrored.py,sha256=kdhwCWOWaArmfNkDah0Thv-67M9wWz45R5IMPhqyzFM,9242
|
| 600 |
+
fontTools/unicodedata/OTTags.py,sha256=wOPpbMsNcp_gdvPFeITtgVMnTN8TJSNAsVEdu_nuPXE,1196
|
| 601 |
+
fontTools/unicodedata/ScriptExtensions.py,sha256=udL53Wdd5n-ZFEVHeIC0LpKKBqPHD2WqRiBbzXs2U7U,28647
|
| 602 |
+
fontTools/unicodedata/Scripts.py,sha256=wBD6SElfM3w-u6JcgyNsyofXPvqW1e4YltgeHE4XaOc,131148
|
| 603 |
+
fontTools/unicodedata/__init__.py,sha256=4eR0Luk4QJHC9YDG0_wi6UrIDawED36e6Xbf3S5hDPg,9085
|
| 604 |
+
fontTools/unicodedata/__pycache__/Blocks.cpython-311.pyc,,
|
| 605 |
+
fontTools/unicodedata/__pycache__/Mirrored.cpython-311.pyc,,
|
| 606 |
+
fontTools/unicodedata/__pycache__/OTTags.cpython-311.pyc,,
|
| 607 |
+
fontTools/unicodedata/__pycache__/ScriptExtensions.cpython-311.pyc,,
|
| 608 |
+
fontTools/unicodedata/__pycache__/Scripts.cpython-311.pyc,,
|
| 609 |
+
fontTools/unicodedata/__pycache__/__init__.cpython-311.pyc,,
|
| 610 |
+
fontTools/varLib/__init__.py,sha256=C1tfl_FZ-ek_5cXqtKSXRLu8dqAg_DL2UdbvLusYBxQ,56777
|
| 611 |
+
fontTools/varLib/__main__.py,sha256=wbdYC5bPjWCxA0I4SKcLO88gl-UMtsYS8MxdW9ySTkY,95
|
| 612 |
+
fontTools/varLib/__pycache__/__init__.cpython-311.pyc,,
|
| 613 |
+
fontTools/varLib/__pycache__/__main__.cpython-311.pyc,,
|
| 614 |
+
fontTools/varLib/__pycache__/avarPlanner.cpython-311.pyc,,
|
| 615 |
+
fontTools/varLib/__pycache__/builder.cpython-311.pyc,,
|
| 616 |
+
fontTools/varLib/__pycache__/cff.cpython-311.pyc,,
|
| 617 |
+
fontTools/varLib/__pycache__/errors.cpython-311.pyc,,
|
| 618 |
+
fontTools/varLib/__pycache__/featureVars.cpython-311.pyc,,
|
| 619 |
+
fontTools/varLib/__pycache__/hvar.cpython-311.pyc,,
|
| 620 |
+
fontTools/varLib/__pycache__/interpolatable.cpython-311.pyc,,
|
| 621 |
+
fontTools/varLib/__pycache__/interpolatableHelpers.cpython-311.pyc,,
|
| 622 |
+
fontTools/varLib/__pycache__/interpolatablePlot.cpython-311.pyc,,
|
| 623 |
+
fontTools/varLib/__pycache__/interpolatableTestContourOrder.cpython-311.pyc,,
|
| 624 |
+
fontTools/varLib/__pycache__/interpolatableTestStartingPoint.cpython-311.pyc,,
|
| 625 |
+
fontTools/varLib/__pycache__/interpolate_layout.cpython-311.pyc,,
|
| 626 |
+
fontTools/varLib/__pycache__/iup.cpython-311.pyc,,
|
| 627 |
+
fontTools/varLib/__pycache__/merger.cpython-311.pyc,,
|
| 628 |
+
fontTools/varLib/__pycache__/models.cpython-311.pyc,,
|
| 629 |
+
fontTools/varLib/__pycache__/multiVarStore.cpython-311.pyc,,
|
| 630 |
+
fontTools/varLib/__pycache__/mutator.cpython-311.pyc,,
|
| 631 |
+
fontTools/varLib/__pycache__/mvar.cpython-311.pyc,,
|
| 632 |
+
fontTools/varLib/__pycache__/plot.cpython-311.pyc,,
|
| 633 |
+
fontTools/varLib/__pycache__/stat.cpython-311.pyc,,
|
| 634 |
+
fontTools/varLib/__pycache__/varStore.cpython-311.pyc,,
|
| 635 |
+
fontTools/varLib/avar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 636 |
+
fontTools/varLib/avar/__main__.py,sha256=ew1fJpg81GpYbdkrp4I7ntWdbhkDeg5fNn1SrpF254k,1770
|
| 637 |
+
fontTools/varLib/avar/__pycache__/__init__.cpython-311.pyc,,
|
| 638 |
+
fontTools/varLib/avar/__pycache__/__main__.cpython-311.pyc,,
|
| 639 |
+
fontTools/varLib/avar/__pycache__/build.cpython-311.pyc,,
|
| 640 |
+
fontTools/varLib/avar/__pycache__/map.cpython-311.pyc,,
|
| 641 |
+
fontTools/varLib/avar/__pycache__/plan.cpython-311.pyc,,
|
| 642 |
+
fontTools/varLib/avar/__pycache__/unbuild.cpython-311.pyc,,
|
| 643 |
+
fontTools/varLib/avar/build.py,sha256=g0rlRT1HqVFv7pIzY0MN8phqZhEuJ0YO2S-mauW4frA,2089
|
| 644 |
+
fontTools/varLib/avar/map.py,sha256=dtCkJ7dP6Cvav8pyO3GJIaXq9OIPuSdyaRgWCmKeFag,3482
|
| 645 |
+
fontTools/varLib/avar/plan.py,sha256=qDKZjQq6OfeXBr3T3DZnrmauyMm5ek0rm5YVosAO_UA,27354
|
| 646 |
+
fontTools/varLib/avar/unbuild.py,sha256=Es_D9yiqp-ib-5bxfxCsZF9Jq7f60eb2aVfx-Eepv10,10517
|
| 647 |
+
fontTools/varLib/avarPlanner.py,sha256=CabG5xB57FMdwmN1acpVMvyOucVPxCdRdJSK2gu7gb4,109
|
| 648 |
+
fontTools/varLib/builder.py,sha256=mSKOCcnnw-WzmZs15FayoqCDh77Ts7o9Tre9psh8CUc,6609
|
| 649 |
+
fontTools/varLib/cff.py,sha256=EVgaQcoROIrYQsRuftnxFuGGldEPYbrIh5yBckylJC4,22901
|
| 650 |
+
fontTools/varLib/errors.py,sha256=dMo8eGj76I7H4hrBEiNbYrGs2J1K1SwdsUyTHpkVOrQ,6934
|
| 651 |
+
fontTools/varLib/featureVars.py,sha256=kp4gPjKyyGRu7yBWxgd1N4OkKnU9V45QwiWSHs6OWd0,26180
|
| 652 |
+
fontTools/varLib/hvar.py,sha256=1IvL5BneTkg8jJYicH0TSQViB6D0vBEesLdlfqoLBX4,3695
|
| 653 |
+
fontTools/varLib/instancer/__init__.py,sha256=59DxY9wZuxRbUfj1KnY9FeYmDIr2AoHv7e244J8Fl3s,75423
|
| 654 |
+
fontTools/varLib/instancer/__main__.py,sha256=zfULwcP01FhplS1IlcMgNQnLxk5RVfmOuinWjqeid-g,104
|
| 655 |
+
fontTools/varLib/instancer/__pycache__/__init__.cpython-311.pyc,,
|
| 656 |
+
fontTools/varLib/instancer/__pycache__/__main__.cpython-311.pyc,,
|
| 657 |
+
fontTools/varLib/instancer/__pycache__/featureVars.cpython-311.pyc,,
|
| 658 |
+
fontTools/varLib/instancer/__pycache__/names.cpython-311.pyc,,
|
| 659 |
+
fontTools/varLib/instancer/__pycache__/solver.cpython-311.pyc,,
|
| 660 |
+
fontTools/varLib/instancer/featureVars.py,sha256=oPqSlnHLMDTtOsmQMi6gkzLox7ymCrqlRAkvC_EJ4bc,7110
|
| 661 |
+
fontTools/varLib/instancer/names.py,sha256=IPRqel_M8zVU0jl30WsfgufxUm9PBBQDQCY3VHapeHc,14950
|
| 662 |
+
fontTools/varLib/instancer/solver.py,sha256=uMePwX0BVT5F94kUvDglsI4_F0nEH67F7RFuJ6tQwQ0,11002
|
| 663 |
+
fontTools/varLib/interpolatable.py,sha256=WP553NVSShJp8oGktsYlYrv0fLDY2gRs6dNSZRSpNd8,45227
|
| 664 |
+
fontTools/varLib/interpolatableHelpers.py,sha256=9EZUwcgXLeKAn_mPA2E5mCqWkpXREB71a5efsmzyk9o,10286
|
| 665 |
+
fontTools/varLib/interpolatablePlot.py,sha256=14AMcuUIrgQItBfeWlAP6FFFtmvoh97Hwjicj1Fj5KA,44272
|
| 666 |
+
fontTools/varLib/interpolatableTestContourOrder.py,sha256=xIPmAKLDq_5wtI9hDtYRbprfNT9Bj-uaQmklBth8Xh0,2970
|
| 667 |
+
fontTools/varLib/interpolatableTestStartingPoint.py,sha256=WrV4VzmL6YmaLmThXrMd_U9A1dlzStV-AqkamIRNh24,4364
|
| 668 |
+
fontTools/varLib/interpolate_layout.py,sha256=22VjGZuV2YiAe2MpdTf0xPVz1x2G84bcOL0vOeBpGQM,3689
|
| 669 |
+
fontTools/varLib/iup.c,sha256=YaaxnrOIaGpf4PAvDLIYOrPO-AUi61Mx1zHsLTJ-xHA,835847
|
| 670 |
+
fontTools/varLib/iup.cpython-311-x86_64-linux-gnu.so,sha256=hDXbvTUVnY5BB1qCj6E0E2FW9vpeUmYr7D5Tp7B2dYA,974976
|
| 671 |
+
fontTools/varLib/iup.py,sha256=mKq_GRWuUg4yTmw2V32nu0v2r-SzzN7xS7rIbV0mYuc,14984
|
| 672 |
+
fontTools/varLib/merger.py,sha256=E59oli4AwqWZ-FgnuStMSBvsB-FHe-55esXTYUqGeJ8,60802
|
| 673 |
+
fontTools/varLib/models.py,sha256=2cr3hjwKd6E6uciOVZixh0Z-TATEtUa-LEGsDK3zvqk,22910
|
| 674 |
+
fontTools/varLib/multiVarStore.py,sha256=eQEuWNY01YF5zDpy1UwNtvOYyD6c0FLxpH-QFpX1i78,8305
|
| 675 |
+
fontTools/varLib/mutator.py,sha256=kzXiLFxRLgU2pcHzOzh9u0n0KkO3DuBk06xZ_RPhWz8,19804
|
| 676 |
+
fontTools/varLib/mvar.py,sha256=LTV77vH_3Ecg_qKBO5xQzjLOlJir_ppEr7mPVZRgad8,2449
|
| 677 |
+
fontTools/varLib/plot.py,sha256=NoSZkJ5ndxNcDvJIvd5pQ9_jX6X1oM1K2G_tR4sdPVs,7494
|
| 678 |
+
fontTools/varLib/stat.py,sha256=XuNKKZxGlBrl4OGFDAwVXhpBwJi23U3BdHmNTKoJnvE,4811
|
| 679 |
+
fontTools/varLib/varStore.py,sha256=2QA9SDI6jQyQ_zq82OOwa3FBkfl-ksaSo1KGmVFpa9Q,24069
|
| 680 |
+
fontTools/voltLib/__init__.py,sha256=ZZ1AsTx1VlDn40Kupce-fM3meOWugy3RZraBW9LG-9M,151
|
| 681 |
+
fontTools/voltLib/__main__.py,sha256=uVtABLzMeHtvKL8zetf4rpC4aB8BkYr5QLSegNjZZZI,5928
|
| 682 |
+
fontTools/voltLib/__pycache__/__init__.cpython-311.pyc,,
|
| 683 |
+
fontTools/voltLib/__pycache__/__main__.cpython-311.pyc,,
|
| 684 |
+
fontTools/voltLib/__pycache__/ast.cpython-311.pyc,,
|
| 685 |
+
fontTools/voltLib/__pycache__/error.cpython-311.pyc,,
|
| 686 |
+
fontTools/voltLib/__pycache__/lexer.cpython-311.pyc,,
|
| 687 |
+
fontTools/voltLib/__pycache__/parser.cpython-311.pyc,,
|
| 688 |
+
fontTools/voltLib/__pycache__/voltToFea.cpython-311.pyc,,
|
| 689 |
+
fontTools/voltLib/ast.py,sha256=arA9W3Gqo6OqljwNNKnMAojz-C5LStbC5SgjJh7buKk,13300
|
| 690 |
+
fontTools/voltLib/error.py,sha256=phcQOQj-xOspCXu9hBJQRhSOBDzxHRgZd3fWQOFNJzw,395
|
| 691 |
+
fontTools/voltLib/lexer.py,sha256=OvuETOSvlS6v7iCVeJ3IdH2Cg71n3OJoEyiB3-h6vhE,3368
|
| 692 |
+
fontTools/voltLib/parser.py,sha256=rkw2IHBZPsrhGVC7Kw7V501m0u52kh1JSM5HXp-xchM,25396
|
| 693 |
+
fontTools/voltLib/voltToFea.py,sha256=Z2yvnaZLQXzPLT86Uta0zRsXIYgj6NnvZtSWt5xmw2s,36549
|
| 694 |
+
fonttools-4.63.0+computecanada.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 695 |
+
fonttools-4.63.0+computecanada.dist-info/METADATA,sha256=GeP8bvnFLhoon2AaSvcxwc5l8RPdxKGpQnjTPwxEoJQ,3289
|
| 696 |
+
fonttools-4.63.0+computecanada.dist-info/RECORD,,
|
| 697 |
+
fonttools-4.63.0+computecanada.dist-info/WHEEL,sha256=dCAA691vV7BW_aZWazBJJ5ldVUtr6Pzmdb_zOoyLvl4,99
|
| 698 |
+
fonttools-4.63.0+computecanada.dist-info/entry_points.txt,sha256=8kVHddxfFWA44FSD4mBpmC-4uCynQnkoz_9aNJb227Y,147
|
| 699 |
+
fonttools-4.63.0+computecanada.dist-info/licenses/LICENSE,sha256=Z4cgj4P2Wcy8IiOy_elS_6b36KymLxqKK_W8UbsbI4M,1072
|
| 700 |
+
fonttools-4.63.0+computecanada.dist-info/licenses/LICENSE.external,sha256=lKg6ruBymg8wLTSsxKzsvZ1YNm8mJCkHX-VX5KVLLmk,20022
|
| 701 |
+
fonttools-4.63.0+computecanada.dist-info/top_level.txt,sha256=rRgRylrXzekqWOsrhygzib12pQ7WILf7UGjqEwkIFDM,10
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: wheelfile 0.0.8
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: cp311-cp311-linux_x86_64
|
| 5 |
+
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
fonttools = fontTools.__main__:main
|
| 3 |
+
pyftmerge = fontTools.merge:main
|
| 4 |
+
pyftsubset = fontTools.subset:main
|
| 5 |
+
ttx = fontTools.ttx:main
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2017 Just van Rossum
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/licenses/LICENSE.external
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FontTools includes the following font projects for testing purposes, which are
|
| 2 |
+
under SIL Open Font License, Version 1.1:
|
| 3 |
+
|
| 4 |
+
Lobster
|
| 5 |
+
Copyright (c) 2010, Pablo Impallari (www.impallari.com|impallari@gmail.com),
|
| 6 |
+
with Reserved Font Name Lobster.
|
| 7 |
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
| 8 |
+
|
| 9 |
+
Noto Fonts
|
| 10 |
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
| 11 |
+
|
| 12 |
+
XITS font project
|
| 13 |
+
Copyright (c) 2001-2010 by the STI Pub Companies, consisting of the American
|
| 14 |
+
Institute of Physics, the American Chemical Society, the American
|
| 15 |
+
Mathematical Society, the American Physical Society, Elsevier, Inc., and The
|
| 16 |
+
Institute of Electrical and Electronic Engineers, Inc. (www.stixfonts.org),
|
| 17 |
+
with Reserved Font Name STIX Fonts, STIX Fonts (TM) is a trademark of The
|
| 18 |
+
Institute of Electrical and Electronics Engineers, Inc.
|
| 19 |
+
|
| 20 |
+
Portions copyright (c) 1998-2003 by MicroPress, Inc.
|
| 21 |
+
(www.micropress-inc.com), with Reserved Font Name TM Math. To obtain
|
| 22 |
+
additional mathematical fonts, please contact MicroPress, Inc., 68-30 Harrow
|
| 23 |
+
Street, Forest Hills, NY 11375, USA, Phone: (718) 575-1816.
|
| 24 |
+
|
| 25 |
+
Portions copyright (c) 1990 by Elsevier, Inc.
|
| 26 |
+
|
| 27 |
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
| 28 |
+
|
| 29 |
+
Iosevka
|
| 30 |
+
Copyright (c) 2015-2020 Belleve Invis (belleve@typeof.net).
|
| 31 |
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
| 32 |
+
|
| 33 |
+
This license is copied below, and is also available with a FAQ at:
|
| 34 |
+
http://scripts.sil.org/OFL
|
| 35 |
+
|
| 36 |
+
-----------------------------------------------------------
|
| 37 |
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
| 38 |
+
-----------------------------------------------------------
|
| 39 |
+
|
| 40 |
+
PREAMBLE
|
| 41 |
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
| 42 |
+
development of collaborative font projects, to support the font
|
| 43 |
+
creation efforts of academic and linguistic communities, and to
|
| 44 |
+
provide a free and open framework in which fonts may be shared and
|
| 45 |
+
improved in partnership with others.
|
| 46 |
+
|
| 47 |
+
The OFL allows the licensed fonts to be used, studied, modified and
|
| 48 |
+
redistributed freely as long as they are not sold by themselves. The
|
| 49 |
+
fonts, including any derivative works, can be bundled, embedded,
|
| 50 |
+
redistributed and/or sold with any software provided that any reserved
|
| 51 |
+
names are not used by derivative works. The fonts and derivatives,
|
| 52 |
+
however, cannot be released under any other type of license. The
|
| 53 |
+
requirement for fonts to remain under this license does not apply to
|
| 54 |
+
any document created using the fonts or their derivatives.
|
| 55 |
+
|
| 56 |
+
DEFINITIONS
|
| 57 |
+
"Font Software" refers to the set of files released by the Copyright
|
| 58 |
+
Holder(s) under this license and clearly marked as such. This may
|
| 59 |
+
include source files, build scripts and documentation.
|
| 60 |
+
|
| 61 |
+
"Reserved Font Name" refers to any names specified as such after the
|
| 62 |
+
copyright statement(s).
|
| 63 |
+
|
| 64 |
+
"Original Version" refers to the collection of Font Software
|
| 65 |
+
components as distributed by the Copyright Holder(s).
|
| 66 |
+
|
| 67 |
+
"Modified Version" refers to any derivative made by adding to,
|
| 68 |
+
deleting, or substituting -- in part or in whole -- any of the
|
| 69 |
+
components of the Original Version, by changing formats or by porting
|
| 70 |
+
the Font Software to a new environment.
|
| 71 |
+
|
| 72 |
+
"Author" refers to any designer, engineer, programmer, technical
|
| 73 |
+
writer or other person who contributed to the Font Software.
|
| 74 |
+
|
| 75 |
+
PERMISSION & CONDITIONS
|
| 76 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 77 |
+
a copy of the Font Software, to use, study, copy, merge, embed,
|
| 78 |
+
modify, redistribute, and sell modified and unmodified copies of the
|
| 79 |
+
Font Software, subject to the following conditions:
|
| 80 |
+
|
| 81 |
+
1) Neither the Font Software nor any of its individual components, in
|
| 82 |
+
Original or Modified Versions, may be sold by itself.
|
| 83 |
+
|
| 84 |
+
2) Original or Modified Versions of the Font Software may be bundled,
|
| 85 |
+
redistributed and/or sold with any software, provided that each copy
|
| 86 |
+
contains the above copyright notice and this license. These can be
|
| 87 |
+
included either as stand-alone text files, human-readable headers or
|
| 88 |
+
in the appropriate machine-readable metadata fields within text or
|
| 89 |
+
binary files as long as those fields can be easily viewed by the user.
|
| 90 |
+
|
| 91 |
+
3) No Modified Version of the Font Software may use the Reserved Font
|
| 92 |
+
Name(s) unless explicit written permission is granted by the
|
| 93 |
+
corresponding Copyright Holder. This restriction only applies to the
|
| 94 |
+
primary font name as presented to the users.
|
| 95 |
+
|
| 96 |
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
| 97 |
+
Software shall not be used to promote, endorse or advertise any
|
| 98 |
+
Modified Version, except to acknowledge the contribution(s) of the
|
| 99 |
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
| 100 |
+
permission.
|
| 101 |
+
|
| 102 |
+
5) The Font Software, modified or unmodified, in part or in whole,
|
| 103 |
+
must be distributed entirely under this license, and must not be
|
| 104 |
+
distributed under any other license. The requirement for fonts to
|
| 105 |
+
remain under this license does not apply to any document created using
|
| 106 |
+
the Font Software.
|
| 107 |
+
|
| 108 |
+
TERMINATION
|
| 109 |
+
This license becomes null and void if any of the above conditions are
|
| 110 |
+
not met.
|
| 111 |
+
|
| 112 |
+
DISCLAIMER
|
| 113 |
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 114 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
| 115 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
| 116 |
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
| 117 |
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 118 |
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
| 119 |
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 120 |
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
| 121 |
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
| 122 |
+
|
| 123 |
+
=====
|
| 124 |
+
|
| 125 |
+
FontTools includes Adobe AGL & AGLFN, which is under 3-clauses BSD license:
|
| 126 |
+
|
| 127 |
+
Redistribution and use in source and binary forms, with or without
|
| 128 |
+
modification, are permitted provided that the following conditions are
|
| 129 |
+
met:
|
| 130 |
+
|
| 131 |
+
Redistributions of source code must retain the above copyright notice,
|
| 132 |
+
this list of conditions and the following disclaimer.
|
| 133 |
+
|
| 134 |
+
Redistributions in binary form must reproduce the above copyright
|
| 135 |
+
notice, this list of conditions and the following disclaimer in the
|
| 136 |
+
documentation and/or other materials provided with the distribution.
|
| 137 |
+
|
| 138 |
+
Neither the name of Adobe Systems Incorporated nor the names of its
|
| 139 |
+
contributors may be used to endorse or promote products derived from
|
| 140 |
+
this software without specific prior written permission.
|
| 141 |
+
|
| 142 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 143 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 144 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 145 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 146 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 147 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 148 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 149 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 150 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 151 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 152 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 153 |
+
|
| 154 |
+
=====
|
| 155 |
+
|
| 156 |
+
FontTools includes cu2qu, which is Copyright 2016 Google Inc. All Rights Reserved.
|
| 157 |
+
Licensed under the Apache License, Version 2.0, a copy of which is reproduced below:
|
| 158 |
+
|
| 159 |
+
Apache License
|
| 160 |
+
Version 2.0, January 2004
|
| 161 |
+
http://www.apache.org/licenses/
|
| 162 |
+
|
| 163 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 164 |
+
|
| 165 |
+
1. Definitions.
|
| 166 |
+
|
| 167 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 168 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 169 |
+
|
| 170 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 171 |
+
the copyright owner that is granting the License.
|
| 172 |
+
|
| 173 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 174 |
+
other entities that control, are controlled by, or are under common
|
| 175 |
+
control with that entity. For the purposes of this definition,
|
| 176 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 177 |
+
direction or management of such entity, whether by contract or
|
| 178 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 179 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 180 |
+
|
| 181 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 182 |
+
exercising permissions granted by this License.
|
| 183 |
+
|
| 184 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 185 |
+
including but not limited to software source code, documentation
|
| 186 |
+
source, and configuration files.
|
| 187 |
+
|
| 188 |
+
"Object" form shall mean any form resulting from mechanical
|
| 189 |
+
transformation or translation of a Source form, including but
|
| 190 |
+
not limited to compiled object code, generated documentation,
|
| 191 |
+
and conversions to other media types.
|
| 192 |
+
|
| 193 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 194 |
+
Object form, made available under the License, as indicated by a
|
| 195 |
+
copyright notice that is included in or attached to the work
|
| 196 |
+
(an example is provided in the Appendix below).
|
| 197 |
+
|
| 198 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 199 |
+
form, that is based on (or derived from) the Work and for which the
|
| 200 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 201 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 202 |
+
of this License, Derivative Works shall not include works that remain
|
| 203 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 204 |
+
the Work and Derivative Works thereof.
|
| 205 |
+
|
| 206 |
+
"Contribution" shall mean any work of authorship, including
|
| 207 |
+
the original version of the Work and any modifications or additions
|
| 208 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 209 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 210 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 211 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 212 |
+
means any form of electronic, verbal, or written communication sent
|
| 213 |
+
to the Licensor or its representatives, including but not limited to
|
| 214 |
+
communication on electronic mailing lists, source code control systems,
|
| 215 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 216 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 217 |
+
excluding communication that is conspicuously marked or otherwise
|
| 218 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 219 |
+
|
| 220 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 221 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 222 |
+
subsequently incorporated within the Work.
|
| 223 |
+
|
| 224 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 225 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 226 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 227 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 228 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 229 |
+
Work and such Derivative Works in Source or Object form.
|
| 230 |
+
|
| 231 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 232 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 233 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 234 |
+
(except as stated in this section) patent license to make, have made,
|
| 235 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 236 |
+
where such license applies only to those patent claims licensable
|
| 237 |
+
by such Contributor that are necessarily infringed by their
|
| 238 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 239 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 240 |
+
institute patent litigation against any entity (including a
|
| 241 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 242 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 243 |
+
or contributory patent infringement, then any patent licenses
|
| 244 |
+
granted to You under this License for that Work shall terminate
|
| 245 |
+
as of the date such litigation is filed.
|
| 246 |
+
|
| 247 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 248 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 249 |
+
modifications, and in Source or Object form, provided that You
|
| 250 |
+
meet the following conditions:
|
| 251 |
+
|
| 252 |
+
(a) You must give any other recipients of the Work or
|
| 253 |
+
Derivative Works a copy of this License; and
|
| 254 |
+
|
| 255 |
+
(b) You must cause any modified files to carry prominent notices
|
| 256 |
+
stating that You changed the files; and
|
| 257 |
+
|
| 258 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 259 |
+
that You distribute, all copyright, patent, trademark, and
|
| 260 |
+
attribution notices from the Source form of the Work,
|
| 261 |
+
excluding those notices that do not pertain to any part of
|
| 262 |
+
the Derivative Works; and
|
| 263 |
+
|
| 264 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 265 |
+
distribution, then any Derivative Works that You distribute must
|
| 266 |
+
include a readable copy of the attribution notices contained
|
| 267 |
+
within such NOTICE file, excluding those notices that do not
|
| 268 |
+
pertain to any part of the Derivative Works, in at least one
|
| 269 |
+
of the following places: within a NOTICE text file distributed
|
| 270 |
+
as part of the Derivative Works; within the Source form or
|
| 271 |
+
documentation, if provided along with the Derivative Works; or,
|
| 272 |
+
within a display generated by the Derivative Works, if and
|
| 273 |
+
wherever such third-party notices normally appear. The contents
|
| 274 |
+
of the NOTICE file are for informational purposes only and
|
| 275 |
+
do not modify the License. You may add Your own attribution
|
| 276 |
+
notices within Derivative Works that You distribute, alongside
|
| 277 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 278 |
+
that such additional attribution notices cannot be construed
|
| 279 |
+
as modifying the License.
|
| 280 |
+
|
| 281 |
+
You may add Your own copyright statement to Your modifications and
|
| 282 |
+
may provide additional or different license terms and conditions
|
| 283 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 284 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 285 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 286 |
+
the conditions stated in this License.
|
| 287 |
+
|
| 288 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 289 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 290 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 291 |
+
this License, without any additional terms or conditions.
|
| 292 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 293 |
+
the terms of any separate license agreement you may have executed
|
| 294 |
+
with Licensor regarding such Contributions.
|
| 295 |
+
|
| 296 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 297 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 298 |
+
except as required for reasonable and customary use in describing the
|
| 299 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 300 |
+
|
| 301 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 302 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 303 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 304 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 305 |
+
implied, including, without limitation, any warranties or conditions
|
| 306 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 307 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 308 |
+
appropriateness of using or redistributing the Work and assume any
|
| 309 |
+
risks associated with Your exercise of permissions under this License.
|
| 310 |
+
|
| 311 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 312 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 313 |
+
unless required by applicable law (such as deliberate and grossly
|
| 314 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 315 |
+
liable to You for damages, including any direct, indirect, special,
|
| 316 |
+
incidental, or consequential damages of any character arising as a
|
| 317 |
+
result of this License or out of the use or inability to use the
|
| 318 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 319 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 320 |
+
other commercial damages or losses), even if such Contributor
|
| 321 |
+
has been advised of the possibility of such damages.
|
| 322 |
+
|
| 323 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 324 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 325 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 326 |
+
or other liability obligations and/or rights consistent with this
|
| 327 |
+
License. However, in accepting such obligations, You may act only
|
| 328 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 329 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 330 |
+
defend, and hold each Contributor harmless for any liability
|
| 331 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 332 |
+
of your accepting any such warranty or additional liability.
|
| 333 |
+
|
| 334 |
+
END OF TERMS AND CONDITIONS
|
| 335 |
+
|
| 336 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 337 |
+
|
| 338 |
+
To apply the Apache License to your work, attach the following
|
| 339 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 340 |
+
replaced with your own identifying information. (Don't include
|
| 341 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 342 |
+
comment syntax for the file format. We also recommend that a
|
| 343 |
+
file or class name and description of purpose be included on the
|
| 344 |
+
same "printed page" as the copyright notice for easier
|
| 345 |
+
identification within third-party archives.
|
| 346 |
+
|
| 347 |
+
Copyright [yyyy] [name of copyright owner]
|
| 348 |
+
|
| 349 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 350 |
+
you may not use this file except in compliance with the License.
|
| 351 |
+
You may obtain a copy of the License at
|
| 352 |
+
|
| 353 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 354 |
+
|
| 355 |
+
Unless required by applicable law or agreed to in writing, software
|
| 356 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 357 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 358 |
+
See the License for the specific language governing permissions and
|
| 359 |
+
limitations under the License.
|
| 360 |
+
|
| 361 |
+
=====
|
| 362 |
+
|
| 363 |
+
FontTools includes code in `fontTools.misc.filesystem` which is derived from:
|
| 364 |
+
|
| 365 |
+
PyFilesystem2 (i.e. the `fs` package) by Will McGugan
|
| 366 |
+
Licensed under the MIT License
|
| 367 |
+
https://github.com/PyFilesystem/pyfilesystem2
|
| 368 |
+
|
| 369 |
+
Copyright (c) 2017-2021 The PyFilesystem2 contributors
|
| 370 |
+
Copyright (c) 2016-2019 Will McGugan
|
| 371 |
+
|
| 372 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 373 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 374 |
+
in the Software without restriction, including without limitation the rights
|
| 375 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 376 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 377 |
+
furnished to do so, subject to the following conditions:
|
| 378 |
+
|
| 379 |
+
The above copyright notice and this permission notice shall be included in all
|
| 380 |
+
copies or substantial portions of the Software.
|
| 381 |
+
|
| 382 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 383 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 384 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 385 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 386 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 387 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 388 |
+
SOFTWARE.
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fonttools-4.63.0+computecanada.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fontTools
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/METADATA
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 6 |
+
Keywords: file
|
| 7 |
+
Classifier: Development Status :: 4 - Beta
|
| 8 |
+
Classifier: Intended Audience :: Developers
|
| 9 |
+
Classifier: Operating System :: OS Independent
|
| 10 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 11 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 12 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 13 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 14 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 15 |
+
Maintainer-email: Martin Durant <mdurant@anaconda.com>
|
| 16 |
+
Project-URL: Changelog, https://filesystem-spec.readthedocs.io/en/latest/changelog.html
|
| 17 |
+
Project-URL: Documentation, https://filesystem-spec.readthedocs.io/en/latest/
|
| 18 |
+
Project-URL: Homepage, https://github.com/fsspec/filesystem_spec
|
| 19 |
+
Requires-Python: >=3.10
|
| 20 |
+
Requires-Dist: adlfs; extra == 'abfs'
|
| 21 |
+
Requires-Dist: adlfs; extra == 'adl'
|
| 22 |
+
Requires-Dist: pyarrow>=1; extra == 'arrow'
|
| 23 |
+
Requires-Dist: dask; extra == 'dask'
|
| 24 |
+
Requires-Dist: distributed; extra == 'dask'
|
| 25 |
+
Requires-Dist: pre-commit; extra == 'dev'
|
| 26 |
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
| 27 |
+
Requires-Dist: numpydoc; extra == 'doc'
|
| 28 |
+
Requires-Dist: sphinx; extra == 'doc'
|
| 29 |
+
Requires-Dist: sphinx-design; extra == 'doc'
|
| 30 |
+
Requires-Dist: sphinx-rtd-theme; extra == 'doc'
|
| 31 |
+
Requires-Dist: yarl; extra == 'doc'
|
| 32 |
+
Requires-Dist: dropbox; extra == 'dropbox'
|
| 33 |
+
Requires-Dist: dropboxdrivefs; extra == 'dropbox'
|
| 34 |
+
Requires-Dist: requests; extra == 'dropbox'
|
| 35 |
+
Requires-Dist: adlfs; extra == 'full'
|
| 36 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'full'
|
| 37 |
+
Requires-Dist: dask; extra == 'full'
|
| 38 |
+
Requires-Dist: distributed; extra == 'full'
|
| 39 |
+
Requires-Dist: dropbox; extra == 'full'
|
| 40 |
+
Requires-Dist: dropboxdrivefs; extra == 'full'
|
| 41 |
+
Requires-Dist: fusepy; extra == 'full'
|
| 42 |
+
Requires-Dist: gcsfs>2024.2.0; extra == 'full'
|
| 43 |
+
Requires-Dist: libarchive-c; extra == 'full'
|
| 44 |
+
Requires-Dist: ocifs; extra == 'full'
|
| 45 |
+
Requires-Dist: panel; extra == 'full'
|
| 46 |
+
Requires-Dist: paramiko; extra == 'full'
|
| 47 |
+
Requires-Dist: pyarrow>=1; extra == 'full'
|
| 48 |
+
Requires-Dist: pygit2; extra == 'full'
|
| 49 |
+
Requires-Dist: requests; extra == 'full'
|
| 50 |
+
Requires-Dist: s3fs>2024.2.0; extra == 'full'
|
| 51 |
+
Requires-Dist: smbprotocol; extra == 'full'
|
| 52 |
+
Requires-Dist: tqdm; extra == 'full'
|
| 53 |
+
Requires-Dist: fusepy; extra == 'fuse'
|
| 54 |
+
Requires-Dist: gcsfs>2024.2.0; extra == 'gcs'
|
| 55 |
+
Requires-Dist: pygit2; extra == 'git'
|
| 56 |
+
Requires-Dist: requests; extra == 'github'
|
| 57 |
+
Requires-Dist: gcsfs; extra == 'gs'
|
| 58 |
+
Requires-Dist: panel; extra == 'gui'
|
| 59 |
+
Requires-Dist: pyarrow>=1; extra == 'hdfs'
|
| 60 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'http'
|
| 61 |
+
Requires-Dist: libarchive-c; extra == 'libarchive'
|
| 62 |
+
Requires-Dist: ocifs; extra == 'oci'
|
| 63 |
+
Requires-Dist: s3fs>2024.2.0; extra == 's3'
|
| 64 |
+
Requires-Dist: paramiko; extra == 'sftp'
|
| 65 |
+
Requires-Dist: smbprotocol; extra == 'smb'
|
| 66 |
+
Requires-Dist: paramiko; extra == 'ssh'
|
| 67 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'test'
|
| 68 |
+
Requires-Dist: numpy; extra == 'test'
|
| 69 |
+
Requires-Dist: pytest; extra == 'test'
|
| 70 |
+
Requires-Dist: pytest-asyncio!=0.22.0; extra == 'test'
|
| 71 |
+
Requires-Dist: pytest-benchmark; extra == 'test'
|
| 72 |
+
Requires-Dist: pytest-cov; extra == 'test'
|
| 73 |
+
Requires-Dist: pytest-mock; extra == 'test'
|
| 74 |
+
Requires-Dist: pytest-recording; extra == 'test'
|
| 75 |
+
Requires-Dist: pytest-rerunfailures; extra == 'test'
|
| 76 |
+
Requires-Dist: requests; extra == 'test'
|
| 77 |
+
Requires-Dist: aiobotocore<3.0.0,>=2.5.4; extra == 'test-downstream'
|
| 78 |
+
Requires-Dist: dask[dataframe,test]; extra == 'test-downstream'
|
| 79 |
+
Requires-Dist: moto[server]<5,>4; extra == 'test-downstream'
|
| 80 |
+
Requires-Dist: pytest-timeout; extra == 'test-downstream'
|
| 81 |
+
Requires-Dist: xarray; extra == 'test-downstream'
|
| 82 |
+
Requires-Dist: adlfs; extra == 'test-full'
|
| 83 |
+
Requires-Dist: aiohttp!=4.0.0a0,!=4.0.0a1; extra == 'test-full'
|
| 84 |
+
Requires-Dist: backports-zstd; (python_version < '3.14') and extra == 'test-full'
|
| 85 |
+
Requires-Dist: cloudpickle; extra == 'test-full'
|
| 86 |
+
Requires-Dist: dask; extra == 'test-full'
|
| 87 |
+
Requires-Dist: distributed; extra == 'test-full'
|
| 88 |
+
Requires-Dist: dropbox; extra == 'test-full'
|
| 89 |
+
Requires-Dist: dropboxdrivefs; extra == 'test-full'
|
| 90 |
+
Requires-Dist: fastparquet; extra == 'test-full'
|
| 91 |
+
Requires-Dist: fusepy; extra == 'test-full'
|
| 92 |
+
Requires-Dist: gcsfs; extra == 'test-full'
|
| 93 |
+
Requires-Dist: jinja2; extra == 'test-full'
|
| 94 |
+
Requires-Dist: kerchunk; extra == 'test-full'
|
| 95 |
+
Requires-Dist: libarchive-c; extra == 'test-full'
|
| 96 |
+
Requires-Dist: lz4; extra == 'test-full'
|
| 97 |
+
Requires-Dist: notebook; extra == 'test-full'
|
| 98 |
+
Requires-Dist: numpy; extra == 'test-full'
|
| 99 |
+
Requires-Dist: ocifs; extra == 'test-full'
|
| 100 |
+
Requires-Dist: pandas<3.0.0; extra == 'test-full'
|
| 101 |
+
Requires-Dist: panel; extra == 'test-full'
|
| 102 |
+
Requires-Dist: paramiko; extra == 'test-full'
|
| 103 |
+
Requires-Dist: pyarrow; extra == 'test-full'
|
| 104 |
+
Requires-Dist: pyarrow>=1; extra == 'test-full'
|
| 105 |
+
Requires-Dist: pyftpdlib; extra == 'test-full'
|
| 106 |
+
Requires-Dist: pygit2; extra == 'test-full'
|
| 107 |
+
Requires-Dist: pytest; extra == 'test-full'
|
| 108 |
+
Requires-Dist: pytest-asyncio!=0.22.0; extra == 'test-full'
|
| 109 |
+
Requires-Dist: pytest-benchmark; extra == 'test-full'
|
| 110 |
+
Requires-Dist: pytest-cov; extra == 'test-full'
|
| 111 |
+
Requires-Dist: pytest-mock; extra == 'test-full'
|
| 112 |
+
Requires-Dist: pytest-recording; extra == 'test-full'
|
| 113 |
+
Requires-Dist: pytest-rerunfailures; extra == 'test-full'
|
| 114 |
+
Requires-Dist: python-snappy; extra == 'test-full'
|
| 115 |
+
Requires-Dist: requests; extra == 'test-full'
|
| 116 |
+
Requires-Dist: smbprotocol; extra == 'test-full'
|
| 117 |
+
Requires-Dist: tqdm; extra == 'test-full'
|
| 118 |
+
Requires-Dist: urllib3; extra == 'test-full'
|
| 119 |
+
Requires-Dist: zarr<3.2.0; extra == 'test-full'
|
| 120 |
+
Requires-Dist: zstandard; (python_version < '3.14') and extra == 'test-full'
|
| 121 |
+
Requires-Dist: tqdm; extra == 'tqdm'
|
| 122 |
+
Provides-Extra: abfs
|
| 123 |
+
Provides-Extra: adl
|
| 124 |
+
Provides-Extra: arrow
|
| 125 |
+
Provides-Extra: dask
|
| 126 |
+
Provides-Extra: dev
|
| 127 |
+
Provides-Extra: doc
|
| 128 |
+
Provides-Extra: dropbox
|
| 129 |
+
Provides-Extra: entrypoints
|
| 130 |
+
Provides-Extra: full
|
| 131 |
+
Provides-Extra: fuse
|
| 132 |
+
Provides-Extra: gcs
|
| 133 |
+
Provides-Extra: git
|
| 134 |
+
Provides-Extra: github
|
| 135 |
+
Provides-Extra: gs
|
| 136 |
+
Provides-Extra: gui
|
| 137 |
+
Provides-Extra: hdfs
|
| 138 |
+
Provides-Extra: http
|
| 139 |
+
Provides-Extra: libarchive
|
| 140 |
+
Provides-Extra: oci
|
| 141 |
+
Provides-Extra: s3
|
| 142 |
+
Provides-Extra: sftp
|
| 143 |
+
Provides-Extra: smb
|
| 144 |
+
Provides-Extra: ssh
|
| 145 |
+
Provides-Extra: test
|
| 146 |
+
Provides-Extra: test-downstream
|
| 147 |
+
Provides-Extra: test-full
|
| 148 |
+
Provides-Extra: tqdm
|
| 149 |
+
License-File: LICENSE
|
| 150 |
+
License-Expression: BSD-3-Clause
|
| 151 |
+
|
| 152 |
+
# filesystem_spec
|
| 153 |
+
|
| 154 |
+
[](https://pypi.python.org/pypi/fsspec/)
|
| 155 |
+
[](https://anaconda.org/conda-forge/fsspec)
|
| 156 |
+

|
| 157 |
+
[](https://filesystem-spec.readthedocs.io/en/latest/?badge=latest)
|
| 158 |
+
|
| 159 |
+
A specification for pythonic filesystems.
|
| 160 |
+
|
| 161 |
+
## Install
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
pip install fsspec
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
would install the base fsspec. Various optionally supported features might require specification of custom
|
| 168 |
+
extra require, e.g. `pip install fsspec[ssh]` will install dependencies for `ssh` backends support.
|
| 169 |
+
Use `pip install fsspec[full]` for installation of all known extra dependencies.
|
| 170 |
+
|
| 171 |
+
Up-to-date package also provided through conda-forge distribution:
|
| 172 |
+
|
| 173 |
+
```bash
|
| 174 |
+
conda install -c conda-forge fsspec
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
## Purpose
|
| 179 |
+
|
| 180 |
+
To produce a template or specification for a file-system interface, that specific implementations should follow,
|
| 181 |
+
so that applications making use of them can rely on a common behaviour and not have to worry about the specific
|
| 182 |
+
internal implementation decisions with any given backend. Many such implementations are included in this package,
|
| 183 |
+
or in sister projects such as `s3fs` and `gcsfs`.
|
| 184 |
+
|
| 185 |
+
In addition, if this is well-designed, then additional functionality, such as a key-value store or FUSE
|
| 186 |
+
mounting of the file-system implementation may be available for all implementations "for free".
|
| 187 |
+
|
| 188 |
+
## Documentation
|
| 189 |
+
|
| 190 |
+
Please refer to [RTD](https://filesystem-spec.readthedocs.io/en/latest/?badge=latest)
|
| 191 |
+
|
| 192 |
+
## Develop
|
| 193 |
+
|
| 194 |
+
fsspec uses GitHub Actions for CI. Environment files can be found
|
| 195 |
+
in the "ci/" directory. Note that the main environment is called "py38",
|
| 196 |
+
but it is expected that the version of python installed be adjustable at
|
| 197 |
+
CI runtime. For local use, pick a version suitable for you.
|
| 198 |
+
|
| 199 |
+
```bash
|
| 200 |
+
# For a new environment (mamba / conda).
|
| 201 |
+
mamba create -n fsspec -c conda-forge python=3.10 -y
|
| 202 |
+
conda activate fsspec
|
| 203 |
+
|
| 204 |
+
# Standard dev install with docs and tests.
|
| 205 |
+
pip install -e ".[dev,doc,test]"
|
| 206 |
+
|
| 207 |
+
# Full tests except for downstream
|
| 208 |
+
pip install s3fs
|
| 209 |
+
pip uninstall s3fs
|
| 210 |
+
pip install -e .[dev,doc,test_full]
|
| 211 |
+
pip install s3fs --no-deps
|
| 212 |
+
pytest -v
|
| 213 |
+
|
| 214 |
+
# Downstream tests.
|
| 215 |
+
sh install_s3fs.sh
|
| 216 |
+
# Windows powershell.
|
| 217 |
+
install_s3fs.sh
|
| 218 |
+
```
|
| 219 |
+
|
| 220 |
+
### Testing
|
| 221 |
+
|
| 222 |
+
Tests can be run in the dev environment, if activated, via ``pytest fsspec``.
|
| 223 |
+
|
| 224 |
+
The full fsspec suite requires a system-level docker, docker-compose, and fuse
|
| 225 |
+
installation. If only making changes to one backend implementation, it is
|
| 226 |
+
not generally necessary to run all tests locally.
|
| 227 |
+
|
| 228 |
+
It is expected that contributors ensure that any change to fsspec does not
|
| 229 |
+
cause issues or regressions for either other fsspec-related packages such
|
| 230 |
+
as gcsfs and s3fs, nor for downstream users of fsspec. The "downstream" CI
|
| 231 |
+
run and corresponding environment file run a set of tests from the dask
|
| 232 |
+
test suite, and very minimal tests against pandas and zarr from the
|
| 233 |
+
test_downstream.py module in this repo.
|
| 234 |
+
|
| 235 |
+
### Code Formatting
|
| 236 |
+
|
| 237 |
+
fsspec uses [Black](https://black.readthedocs.io/en/stable) to ensure
|
| 238 |
+
a consistent code format throughout the project.
|
| 239 |
+
Run ``black fsspec`` from the root of the filesystem_spec repository to
|
| 240 |
+
auto-format your code. Additionally, many editors have plugins that will apply
|
| 241 |
+
``black`` as you edit files. ``black`` is included in the ``tox`` environments.
|
| 242 |
+
|
| 243 |
+
Optionally, you may wish to setup [pre-commit hooks](https://pre-commit.com) to
|
| 244 |
+
automatically run ``black`` when you make a git commit.
|
| 245 |
+
Run ``pre-commit install --install-hooks`` from the root of the
|
| 246 |
+
filesystem_spec repository to setup pre-commit hooks. ``black`` will now be run
|
| 247 |
+
before you commit, reformatting any changed files. You can format without
|
| 248 |
+
committing via ``pre-commit run`` or skip these checks with ``git commit
|
| 249 |
+
--no-verify``.
|
| 250 |
+
|
| 251 |
+
## Support
|
| 252 |
+
|
| 253 |
+
Work on this repository is supported in part by:
|
| 254 |
+
|
| 255 |
+
"Anaconda, Inc. - Advancing AI through open source."
|
| 256 |
+
|
| 257 |
+
<a href="https://anaconda.com/"><img src="https://camo.githubusercontent.com/b8555ef2222598ed37ce38ac86955febbd25de7619931bb7dd3c58432181d3b6/68747470733a2f2f626565776172652e6f72672f636f6d6d756e6974792f6d656d626572732f616e61636f6e64612f616e61636f6e64612d6c617267652e706e67" alt="anaconda logo" width="40%"/></a>
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/RECORD
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fsspec-2026.6.0+computecanada.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
fsspec-2026.6.0+computecanada.dist-info/METADATA,sha256=FnkOWDW6ZJsI3jhFb2EX7JjI-VN4e7CC1CEmNTS-ziI,10544
|
| 3 |
+
fsspec-2026.6.0+computecanada.dist-info/RECORD,,
|
| 4 |
+
fsspec-2026.6.0+computecanada.dist-info/WHEEL,sha256=E4Ta9GSW8Vg2e11uZktRc054ObD9JXJ5hm6vpxg0WJE,87
|
| 5 |
+
fsspec-2026.6.0+computecanada.dist-info/licenses/LICENSE,sha256=LcNUls5TpzB5FcAIqESq1T53K0mzTN0ARFBnaRQH7JQ,1513
|
| 6 |
+
fsspec/__init__.py,sha256=L7qwNBU1iMNQd8Of87HYSNFT9gWlNMSESaJC8fY0AaQ,2053
|
| 7 |
+
fsspec/__pycache__/__init__.cpython-311.pyc,,
|
| 8 |
+
fsspec/__pycache__/_version.cpython-311.pyc,,
|
| 9 |
+
fsspec/__pycache__/archive.cpython-311.pyc,,
|
| 10 |
+
fsspec/__pycache__/asyn.cpython-311.pyc,,
|
| 11 |
+
fsspec/__pycache__/caching.cpython-311.pyc,,
|
| 12 |
+
fsspec/__pycache__/callbacks.cpython-311.pyc,,
|
| 13 |
+
fsspec/__pycache__/compression.cpython-311.pyc,,
|
| 14 |
+
fsspec/__pycache__/config.cpython-311.pyc,,
|
| 15 |
+
fsspec/__pycache__/conftest.cpython-311.pyc,,
|
| 16 |
+
fsspec/__pycache__/core.cpython-311.pyc,,
|
| 17 |
+
fsspec/__pycache__/dircache.cpython-311.pyc,,
|
| 18 |
+
fsspec/__pycache__/exceptions.cpython-311.pyc,,
|
| 19 |
+
fsspec/__pycache__/fuse.cpython-311.pyc,,
|
| 20 |
+
fsspec/__pycache__/generic.cpython-311.pyc,,
|
| 21 |
+
fsspec/__pycache__/gui.cpython-311.pyc,,
|
| 22 |
+
fsspec/__pycache__/json.cpython-311.pyc,,
|
| 23 |
+
fsspec/__pycache__/mapping.cpython-311.pyc,,
|
| 24 |
+
fsspec/__pycache__/parquet.cpython-311.pyc,,
|
| 25 |
+
fsspec/__pycache__/registry.cpython-311.pyc,,
|
| 26 |
+
fsspec/__pycache__/spec.cpython-311.pyc,,
|
| 27 |
+
fsspec/__pycache__/transaction.cpython-311.pyc,,
|
| 28 |
+
fsspec/__pycache__/utils.cpython-311.pyc,,
|
| 29 |
+
fsspec/_version.py,sha256=UvxfmLfdYeeNmxMYI29CuetrWuGdmBzeCcZ6C6RpX24,526
|
| 30 |
+
fsspec/archive.py,sha256=vM6t_lgV6lBWbBYwpm3S4ofBQFQxUPr5KkDQrrQcQro,2411
|
| 31 |
+
fsspec/asyn.py,sha256=i2pfNovARPVnV4pg93gMUZnnkMT_sCQGF0RKPCVZP5w,38733
|
| 32 |
+
fsspec/caching.py,sha256=YJm7SjQTxOgyavKvAE0CST_GR0mpnEjnIIWCdE1QbLk,34024
|
| 33 |
+
fsspec/callbacks.py,sha256=BDIwLzK6rr_0V5ch557fSzsivCElpdqhXr5dZ9Te-EE,9210
|
| 34 |
+
fsspec/compression.py,sha256=3v_Fe39gzRRWfaeXpzNjAGPqgTzmETYRCo3qHVqD3po,5132
|
| 35 |
+
fsspec/config.py,sha256=mHKzAgjXa_LwqtO_VoTJJ568VqwYkbK3gUp4J6JZJp4,4238
|
| 36 |
+
fsspec/conftest.py,sha256=uWfm_Qs5alPRxOhRpDfQ0-1jqSJ54pni4y96IxOREXM,3446
|
| 37 |
+
fsspec/core.py,sha256=lc7XSnZU6_C6xljp7Z_xEGN3V7704hbeQLkxvPP0wds,24173
|
| 38 |
+
fsspec/dircache.py,sha256=YzogWJrhEastHU7vWz-cJiJ7sdtLXFXhEpInGKd4EcM,2717
|
| 39 |
+
fsspec/exceptions.py,sha256=pauSLDMxzTJMOjvX1WEUK0cMyFkrFxpWJsyFywav7A8,331
|
| 40 |
+
fsspec/fuse.py,sha256=Q-3NOOyLqBfYa4Db5E19z_ZY36zzYHtIs1mOUasItBQ,10177
|
| 41 |
+
fsspec/generic.py,sha256=9QHQYMNb-8w8-eYuIqShcTjO_LeHXFoQTyt8J5oEq5Q,13482
|
| 42 |
+
fsspec/gui.py,sha256=CQ7QsrTpaDlWSLNOpwNoJc7khOcYXIZxmrAJN9bHWQU,14002
|
| 43 |
+
fsspec/implementations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 44 |
+
fsspec/implementations/__pycache__/__init__.cpython-311.pyc,,
|
| 45 |
+
fsspec/implementations/__pycache__/arrow.cpython-311.pyc,,
|
| 46 |
+
fsspec/implementations/__pycache__/asyn_wrapper.cpython-311.pyc,,
|
| 47 |
+
fsspec/implementations/__pycache__/cache_mapper.cpython-311.pyc,,
|
| 48 |
+
fsspec/implementations/__pycache__/cache_metadata.cpython-311.pyc,,
|
| 49 |
+
fsspec/implementations/__pycache__/cached.cpython-311.pyc,,
|
| 50 |
+
fsspec/implementations/__pycache__/chained.cpython-311.pyc,,
|
| 51 |
+
fsspec/implementations/__pycache__/dask.cpython-311.pyc,,
|
| 52 |
+
fsspec/implementations/__pycache__/data.cpython-311.pyc,,
|
| 53 |
+
fsspec/implementations/__pycache__/dbfs.cpython-311.pyc,,
|
| 54 |
+
fsspec/implementations/__pycache__/dirfs.cpython-311.pyc,,
|
| 55 |
+
fsspec/implementations/__pycache__/ftp.cpython-311.pyc,,
|
| 56 |
+
fsspec/implementations/__pycache__/gist.cpython-311.pyc,,
|
| 57 |
+
fsspec/implementations/__pycache__/git.cpython-311.pyc,,
|
| 58 |
+
fsspec/implementations/__pycache__/github.cpython-311.pyc,,
|
| 59 |
+
fsspec/implementations/__pycache__/http.cpython-311.pyc,,
|
| 60 |
+
fsspec/implementations/__pycache__/http_sync.cpython-311.pyc,,
|
| 61 |
+
fsspec/implementations/__pycache__/jupyter.cpython-311.pyc,,
|
| 62 |
+
fsspec/implementations/__pycache__/libarchive.cpython-311.pyc,,
|
| 63 |
+
fsspec/implementations/__pycache__/local.cpython-311.pyc,,
|
| 64 |
+
fsspec/implementations/__pycache__/memory.cpython-311.pyc,,
|
| 65 |
+
fsspec/implementations/__pycache__/reference.cpython-311.pyc,,
|
| 66 |
+
fsspec/implementations/__pycache__/sftp.cpython-311.pyc,,
|
| 67 |
+
fsspec/implementations/__pycache__/smb.cpython-311.pyc,,
|
| 68 |
+
fsspec/implementations/__pycache__/tar.cpython-311.pyc,,
|
| 69 |
+
fsspec/implementations/__pycache__/webhdfs.cpython-311.pyc,,
|
| 70 |
+
fsspec/implementations/__pycache__/zip.cpython-311.pyc,,
|
| 71 |
+
fsspec/implementations/arrow.py,sha256=8FhvcvOYLZNMMegCYFFCEHgEqig8AkOU7Ehb8XfcgnA,8890
|
| 72 |
+
fsspec/implementations/asyn_wrapper.py,sha256=3lfJkGs6D_AwRBdxTSYlL-RCVdaXBZ9Itys2P5o5Si0,3738
|
| 73 |
+
fsspec/implementations/cache_mapper.py,sha256=W4wlxyPxZbSp9ItJ0pYRVBMh6bw9eFypgP6kUYuuiI4,2421
|
| 74 |
+
fsspec/implementations/cache_metadata.py,sha256=EPhQV27lgPlYREYprDET1vcMed15pVNMit-Ta1ljoyE,7942
|
| 75 |
+
fsspec/implementations/cached.py,sha256=38B4qVDDXRh65Zb_JXy2-lJOxtdgUdBgNdy-oBe6jGw,36375
|
| 76 |
+
fsspec/implementations/chained.py,sha256=iGivpNaHUFjB_ea0-HAPhcmm6CL8qnDf270PSj7JwuE,680
|
| 77 |
+
fsspec/implementations/dask.py,sha256=CXZbJzIVOhKV8ILcxuy3bTvcacCueAbyQxmvAkbPkrk,4466
|
| 78 |
+
fsspec/implementations/data.py,sha256=9tMcy1fyX1auvzFX2aANPK9CfPoarnxTCDLhX12usvs,2131
|
| 79 |
+
fsspec/implementations/dbfs.py,sha256=yHuLUGNmQd5pUCt9vpXleQNpjOpIZZwVZA08YauQU4U,16249
|
| 80 |
+
fsspec/implementations/dirfs.py,sha256=5JAp_nn9v1OjKY3MwuRkLrqeZ8gGYlILSQRqkQQdz7k,12624
|
| 81 |
+
fsspec/implementations/ftp.py,sha256=XkD7MiHczFllZZQWndpz9sHBJkzFfRcfkKAfey6KnSI,13465
|
| 82 |
+
fsspec/implementations/gist.py,sha256=Y6jTDrE-wuTwvpPyAQDuuOMBGxlajafKWoB1_yX6jdY,8528
|
| 83 |
+
fsspec/implementations/git.py,sha256=qBDWMz5LNllPqVjr5jf_1FuNha4P5lyQI3IlhYg-wUE,3731
|
| 84 |
+
fsspec/implementations/github.py,sha256=aCsZL8UvXZgdkcB1RUs3DdLeNrjLKcFsFYeQFDWbBFo,11653
|
| 85 |
+
fsspec/implementations/http.py,sha256=1uWwxllOjPe8mQD54IrCYQJHU1YaAXh_cDmXBk-AoQ8,30894
|
| 86 |
+
fsspec/implementations/http_sync.py,sha256=UmBqd938ebwVjYgVtzg-ysG3ZoGhIJw0wFtQAfxV3Aw,30332
|
| 87 |
+
fsspec/implementations/jupyter.py,sha256=q1PlQ66AAswGFyr8MFKWyobaV2YekMWRtqENBDQtD28,4002
|
| 88 |
+
fsspec/implementations/libarchive.py,sha256=SpIA1F-zf7kb2-VYUVuhMrXTBOhBxUXKgEW1RaAdDoA,7098
|
| 89 |
+
fsspec/implementations/local.py,sha256=aVEUnAB2hkxmweXLCiB4XD_KPwDL-gMX4dN9Fz-pk7k,17161
|
| 90 |
+
fsspec/implementations/memory.py,sha256=TDdLtSPWXxZKrrVGwmc3uS3oK_2mlcVTk2BiqR8IeII,10507
|
| 91 |
+
fsspec/implementations/reference.py,sha256=YKLzPBF6bLpOnHY9iM0MR5JLGRi5CB6x1cWIgMb6Ahg,49974
|
| 92 |
+
fsspec/implementations/sftp.py,sha256=v7t-LpD4hEycHnw1kbepyoNgrhClshXQXitFuY4mBWE,5951
|
| 93 |
+
fsspec/implementations/smb.py,sha256=5fhu8h06nOLBPh2c48aT7WBRqh9cEcbIwtyu06wTjec,15236
|
| 94 |
+
fsspec/implementations/tar.py,sha256=0gqTHdwmwQI1Ia8rNQjuAVjNgrEFKPbdPkmndR9vpmk,4451
|
| 95 |
+
fsspec/implementations/webhdfs.py,sha256=osF2m0nhDil6sbMzYW_4DZzhxF4ygtb59XDiybd9Fyg,17589
|
| 96 |
+
fsspec/implementations/zip.py,sha256=GPDJh4UtUNJmaqijUQ0eiEZIGpwusQjkIcbhsrmLSi0,6263
|
| 97 |
+
fsspec/json.py,sha256=4EBZ-xOmRiyxmIqPIwxmDImosRQ7io7qBM2xjJPsEE4,3768
|
| 98 |
+
fsspec/mapping.py,sha256=m2ndB_gtRBXYmNJg0Ie1-BVR75TFleHmIQBzC-yWhjU,8343
|
| 99 |
+
fsspec/parquet.py,sha256=0SzfswUTc2k5nAj7xZNYPPyvUkFNXznFRXXtBRhr-iE,20506
|
| 100 |
+
fsspec/registry.py,sha256=KeDNL9HOyHX_D4D4qQGAI-Y3DQhiLeUC1VK2I81NZaE,12344
|
| 101 |
+
fsspec/spec.py,sha256=7G8EFQn3gMSMP6PxaFgM9Vf93DhFc_-1ABivc_069fo,78097
|
| 102 |
+
fsspec/tests/abstract/__init__.py,sha256=4xUJrv7gDgc85xAOz1p-V_K1hrsdMWTSa0rviALlJk8,10181
|
| 103 |
+
fsspec/tests/abstract/__pycache__/__init__.cpython-311.pyc,,
|
| 104 |
+
fsspec/tests/abstract/__pycache__/common.cpython-311.pyc,,
|
| 105 |
+
fsspec/tests/abstract/__pycache__/copy.cpython-311.pyc,,
|
| 106 |
+
fsspec/tests/abstract/__pycache__/get.cpython-311.pyc,,
|
| 107 |
+
fsspec/tests/abstract/__pycache__/mv.cpython-311.pyc,,
|
| 108 |
+
fsspec/tests/abstract/__pycache__/open.cpython-311.pyc,,
|
| 109 |
+
fsspec/tests/abstract/__pycache__/pipe.cpython-311.pyc,,
|
| 110 |
+
fsspec/tests/abstract/__pycache__/put.cpython-311.pyc,,
|
| 111 |
+
fsspec/tests/abstract/common.py,sha256=1GQwNo5AONzAnzZj0fWgn8NJPLXALehbsuGxS3FzWVU,4973
|
| 112 |
+
fsspec/tests/abstract/copy.py,sha256=gU5-d97U3RSde35Vp4RxPY4rWwL744HiSrJ8IBOp9-8,19967
|
| 113 |
+
fsspec/tests/abstract/get.py,sha256=vNR4HztvTR7Cj56AMo7_tx7TeYz1Jgr_2Wb8Lv-UiBY,20755
|
| 114 |
+
fsspec/tests/abstract/mv.py,sha256=k8eUEBIrRrGMsBY5OOaDXdGnQUKGwDIfQyduB6YD3Ns,1982
|
| 115 |
+
fsspec/tests/abstract/open.py,sha256=Fi2PBPYLbRqysF8cFm0rwnB41kMdQVYjq8cGyDXp3BU,329
|
| 116 |
+
fsspec/tests/abstract/pipe.py,sha256=LFzIrLCB5GLXf9rzFKJmE8AdG7LQ_h4bJo70r8FLPqM,402
|
| 117 |
+
fsspec/tests/abstract/put.py,sha256=7aih17OKB_IZZh1Mkq1eBDIjobhtMQmI8x-Pw-S_aZk,21201
|
| 118 |
+
fsspec/transaction.py,sha256=xliRG6U2Zf3khG4xcw9WiB-yAoqJSHEGK_VjHOdtgo0,2398
|
| 119 |
+
fsspec/utils.py,sha256=E24ji0XLWC6n3bw2sHA28OYxrGU9Wy_al2XydsRgrRk,23623
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: wheelfile 0.0.8
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec-2026.6.0+computecanada.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BSD 3-Clause License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2018, Martin Durant
|
| 4 |
+
All rights reserved.
|
| 5 |
+
|
| 6 |
+
Redistribution and use in source and binary forms, with or without
|
| 7 |
+
modification, are permitted provided that the following conditions are met:
|
| 8 |
+
|
| 9 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 10 |
+
list of conditions and the following disclaimer.
|
| 11 |
+
|
| 12 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 13 |
+
this list of conditions and the following disclaimer in the documentation
|
| 14 |
+
and/or other materials provided with the distribution.
|
| 15 |
+
|
| 16 |
+
* Neither the name of the copyright holder nor the names of its
|
| 17 |
+
contributors may be used to endorse or promote products derived from
|
| 18 |
+
this software without specific prior written permission.
|
| 19 |
+
|
| 20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 21 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 22 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 23 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 24 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 25 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 26 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 27 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 28 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 29 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import caching
|
| 2 |
+
from ._version import __version__ # noqa: F401
|
| 3 |
+
from .callbacks import Callback
|
| 4 |
+
from .compression import available_compressions
|
| 5 |
+
from .core import get_fs_token_paths, open, open_files, open_local, url_to_fs
|
| 6 |
+
from .exceptions import FSTimeoutError
|
| 7 |
+
from .mapping import FSMap, get_mapper
|
| 8 |
+
from .registry import (
|
| 9 |
+
available_protocols,
|
| 10 |
+
filesystem,
|
| 11 |
+
get_filesystem_class,
|
| 12 |
+
register_implementation,
|
| 13 |
+
registry,
|
| 14 |
+
)
|
| 15 |
+
from .spec import AbstractFileSystem
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"AbstractFileSystem",
|
| 19 |
+
"FSTimeoutError",
|
| 20 |
+
"FSMap",
|
| 21 |
+
"filesystem",
|
| 22 |
+
"register_implementation",
|
| 23 |
+
"get_filesystem_class",
|
| 24 |
+
"get_fs_token_paths",
|
| 25 |
+
"get_mapper",
|
| 26 |
+
"open",
|
| 27 |
+
"open_files",
|
| 28 |
+
"open_local",
|
| 29 |
+
"registry",
|
| 30 |
+
"caching",
|
| 31 |
+
"Callback",
|
| 32 |
+
"available_protocols",
|
| 33 |
+
"available_compressions",
|
| 34 |
+
"url_to_fs",
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def process_entries():
|
| 39 |
+
try:
|
| 40 |
+
from importlib.metadata import entry_points
|
| 41 |
+
except ImportError:
|
| 42 |
+
return
|
| 43 |
+
if entry_points is not None:
|
| 44 |
+
try:
|
| 45 |
+
eps = entry_points()
|
| 46 |
+
except TypeError:
|
| 47 |
+
pass # importlib-metadata < 0.8
|
| 48 |
+
else:
|
| 49 |
+
if hasattr(eps, "select"): # Python 3.10+ / importlib_metadata >= 3.9.0
|
| 50 |
+
specs = eps.select(group="fsspec.specs")
|
| 51 |
+
else:
|
| 52 |
+
specs = eps.get("fsspec.specs", [])
|
| 53 |
+
registered_names = {}
|
| 54 |
+
for spec in specs:
|
| 55 |
+
err_msg = f"Unable to load filesystem from {spec}"
|
| 56 |
+
name = spec.name
|
| 57 |
+
if name in registered_names:
|
| 58 |
+
continue
|
| 59 |
+
registered_names[name] = True
|
| 60 |
+
register_implementation(
|
| 61 |
+
name,
|
| 62 |
+
spec.value.replace(":", "."),
|
| 63 |
+
errtxt=err_msg,
|
| 64 |
+
# We take our implementations as the ones to overload with if
|
| 65 |
+
# for some reason we encounter some, may be the same, already
|
| 66 |
+
# registered
|
| 67 |
+
clobber=True,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
process_entries()
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# file generated by vcs-versioning
|
| 2 |
+
# don't change, don't track in version control
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
__all__ = [
|
| 6 |
+
"__version__",
|
| 7 |
+
"__version_tuple__",
|
| 8 |
+
"version",
|
| 9 |
+
"version_tuple",
|
| 10 |
+
"__commit_id__",
|
| 11 |
+
"commit_id",
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
version: str
|
| 15 |
+
__version__: str
|
| 16 |
+
__version_tuple__: tuple[int | str, ...]
|
| 17 |
+
version_tuple: tuple[int | str, ...]
|
| 18 |
+
commit_id: str | None
|
| 19 |
+
__commit_id__: str | None
|
| 20 |
+
|
| 21 |
+
__version__ = version = '2026.6.0'
|
| 22 |
+
__version_tuple__ = version_tuple = (2026, 6, 0)
|
| 23 |
+
|
| 24 |
+
__commit_id__ = commit_id = None
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/archive.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import operator
|
| 2 |
+
|
| 3 |
+
from fsspec import AbstractFileSystem
|
| 4 |
+
from fsspec.utils import tokenize
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class AbstractArchiveFileSystem(AbstractFileSystem):
|
| 8 |
+
"""
|
| 9 |
+
A generic superclass for implementing Archive-based filesystems.
|
| 10 |
+
|
| 11 |
+
Currently, it is shared amongst
|
| 12 |
+
:class:`~fsspec.implementations.zip.ZipFileSystem`,
|
| 13 |
+
:class:`~fsspec.implementations.libarchive.LibArchiveFileSystem` and
|
| 14 |
+
:class:`~fsspec.implementations.tar.TarFileSystem`.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
def __str__(self):
|
| 18 |
+
return f"<Archive-like object {type(self).__name__} at {id(self)}>"
|
| 19 |
+
|
| 20 |
+
__repr__ = __str__
|
| 21 |
+
|
| 22 |
+
def ukey(self, path):
|
| 23 |
+
return tokenize(path, self.fo, self.protocol)
|
| 24 |
+
|
| 25 |
+
def _all_dirnames(self, paths):
|
| 26 |
+
"""Returns *all* directory names for each path in paths, including intermediate
|
| 27 |
+
ones.
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
paths: Iterable of path strings
|
| 32 |
+
"""
|
| 33 |
+
if len(paths) == 0:
|
| 34 |
+
return set()
|
| 35 |
+
|
| 36 |
+
dirnames = {self._parent(path) for path in paths} - {self.root_marker}
|
| 37 |
+
return dirnames | self._all_dirnames(dirnames)
|
| 38 |
+
|
| 39 |
+
def info(self, path, **kwargs):
|
| 40 |
+
self._get_dirs()
|
| 41 |
+
path = self._strip_protocol(path)
|
| 42 |
+
if path in {"", "/"} and self.dir_cache:
|
| 43 |
+
return {"name": "", "type": "directory", "size": 0}
|
| 44 |
+
if path in self.dir_cache:
|
| 45 |
+
return self.dir_cache[path]
|
| 46 |
+
elif path + "/" in self.dir_cache:
|
| 47 |
+
return self.dir_cache[path + "/"]
|
| 48 |
+
else:
|
| 49 |
+
raise FileNotFoundError(path)
|
| 50 |
+
|
| 51 |
+
def ls(self, path, detail=True, **kwargs):
|
| 52 |
+
self._get_dirs()
|
| 53 |
+
paths = {}
|
| 54 |
+
for p, f in self.dir_cache.items():
|
| 55 |
+
p = p.rstrip("/")
|
| 56 |
+
if "/" in p:
|
| 57 |
+
root = p.rsplit("/", 1)[0]
|
| 58 |
+
else:
|
| 59 |
+
root = ""
|
| 60 |
+
if root == path.rstrip("/"):
|
| 61 |
+
paths[p] = f
|
| 62 |
+
elif all(
|
| 63 |
+
(a == b)
|
| 64 |
+
for a, b in zip(path.split("/"), [""] + p.strip("/").split("/"))
|
| 65 |
+
):
|
| 66 |
+
# root directory entry
|
| 67 |
+
ppath = p.rstrip("/").split("/", 1)[0]
|
| 68 |
+
if ppath not in paths:
|
| 69 |
+
out = {"name": ppath, "size": 0, "type": "directory"}
|
| 70 |
+
paths[ppath] = out
|
| 71 |
+
if detail:
|
| 72 |
+
out = sorted(paths.values(), key=operator.itemgetter("name"))
|
| 73 |
+
return out
|
| 74 |
+
else:
|
| 75 |
+
return sorted(paths)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/asyn.py
ADDED
|
@@ -0,0 +1,1158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import asyncio.events
|
| 3 |
+
import functools
|
| 4 |
+
import inspect
|
| 5 |
+
import io
|
| 6 |
+
import numbers
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
import threading
|
| 10 |
+
from collections.abc import Iterable
|
| 11 |
+
from glob import has_magic
|
| 12 |
+
from typing import TYPE_CHECKING
|
| 13 |
+
|
| 14 |
+
from .callbacks import DEFAULT_CALLBACK
|
| 15 |
+
from .exceptions import FSTimeoutError
|
| 16 |
+
from .implementations.local import LocalFileSystem, make_path_posix, trailing_sep
|
| 17 |
+
from .spec import AbstractBufferedFile, AbstractFileSystem
|
| 18 |
+
from .utils import glob_translate, is_exception, other_paths
|
| 19 |
+
|
| 20 |
+
private = re.compile("_[^_]")
|
| 21 |
+
iothread = [None] # dedicated fsspec IO thread
|
| 22 |
+
loop = [None] # global event loop for any non-async instance
|
| 23 |
+
_lock = None # global lock placeholder
|
| 24 |
+
get_running_loop = asyncio.get_running_loop
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_lock():
|
| 28 |
+
"""Allocate or return a threading lock.
|
| 29 |
+
|
| 30 |
+
The lock is allocated on first use to allow setting one lock per forked process.
|
| 31 |
+
"""
|
| 32 |
+
global _lock
|
| 33 |
+
if not _lock:
|
| 34 |
+
_lock = threading.Lock()
|
| 35 |
+
return _lock
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def reset_lock():
|
| 39 |
+
"""Reset the global lock.
|
| 40 |
+
|
| 41 |
+
This should be called only on the init of a forked process to reset the lock to
|
| 42 |
+
None, enabling the new forked process to get a new lock.
|
| 43 |
+
"""
|
| 44 |
+
global _lock
|
| 45 |
+
|
| 46 |
+
iothread[0] = None
|
| 47 |
+
loop[0] = None
|
| 48 |
+
_lock = None
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
async def _runner(event, coro, result, timeout=None):
|
| 52 |
+
timeout = timeout if timeout else None # convert 0 or 0.0 to None
|
| 53 |
+
if timeout is not None:
|
| 54 |
+
coro = asyncio.wait_for(coro, timeout=timeout)
|
| 55 |
+
try:
|
| 56 |
+
result[0] = await coro
|
| 57 |
+
except Exception as ex:
|
| 58 |
+
result[0] = ex
|
| 59 |
+
finally:
|
| 60 |
+
event.set()
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def sync(loop, func, *args, timeout=None, **kwargs):
|
| 64 |
+
"""
|
| 65 |
+
Make loop run coroutine until it returns. Runs in other thread
|
| 66 |
+
|
| 67 |
+
Examples
|
| 68 |
+
--------
|
| 69 |
+
>>> fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args,
|
| 70 |
+
timeout=timeout, **kwargs)
|
| 71 |
+
"""
|
| 72 |
+
timeout = timeout if timeout else None # convert 0 or 0.0 to None
|
| 73 |
+
# NB: if the loop is not running *yet*, it is OK to submit work
|
| 74 |
+
# and we will wait for it
|
| 75 |
+
if loop is None or loop.is_closed():
|
| 76 |
+
raise RuntimeError("Loop is not running")
|
| 77 |
+
try:
|
| 78 |
+
loop0 = asyncio.events.get_running_loop()
|
| 79 |
+
if loop0 is loop:
|
| 80 |
+
raise NotImplementedError("Calling sync() from within a running loop")
|
| 81 |
+
except NotImplementedError:
|
| 82 |
+
raise
|
| 83 |
+
except RuntimeError:
|
| 84 |
+
pass
|
| 85 |
+
coro = func(*args, **kwargs)
|
| 86 |
+
result = [None]
|
| 87 |
+
event = threading.Event()
|
| 88 |
+
asyncio.run_coroutine_threadsafe(_runner(event, coro, result, timeout), loop)
|
| 89 |
+
while True:
|
| 90 |
+
# this loops allows thread to get interrupted
|
| 91 |
+
if event.wait(1):
|
| 92 |
+
break
|
| 93 |
+
if timeout is not None:
|
| 94 |
+
timeout -= 1
|
| 95 |
+
if timeout < 0:
|
| 96 |
+
raise FSTimeoutError
|
| 97 |
+
|
| 98 |
+
return_result = result[0]
|
| 99 |
+
if isinstance(return_result, asyncio.TimeoutError):
|
| 100 |
+
# suppress asyncio.TimeoutError, raise FSTimeoutError
|
| 101 |
+
raise FSTimeoutError from return_result
|
| 102 |
+
elif isinstance(return_result, BaseException):
|
| 103 |
+
raise return_result
|
| 104 |
+
else:
|
| 105 |
+
return return_result
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def sync_wrapper(func, obj=None):
|
| 109 |
+
"""Given a function, make so can be called in blocking contexts
|
| 110 |
+
|
| 111 |
+
Leave obj=None if defining within a class. Pass the instance if attaching
|
| 112 |
+
as an attribute of the instance.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
@functools.wraps(func)
|
| 116 |
+
def wrapper(*args, **kwargs):
|
| 117 |
+
self = obj or args[0]
|
| 118 |
+
return sync(self.loop, func, *args, **kwargs)
|
| 119 |
+
|
| 120 |
+
return wrapper
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def async_gen_wrapper(func, obj=None):
|
| 124 |
+
"""Given a async generator, make so can be called in blocking contexts"""
|
| 125 |
+
|
| 126 |
+
@functools.wraps(func)
|
| 127 |
+
def wrapper(*args, **kwargs):
|
| 128 |
+
self = obj or args[0]
|
| 129 |
+
gen = func(*args, **kwargs)
|
| 130 |
+
while True:
|
| 131 |
+
try:
|
| 132 |
+
yield sync(self.loop, gen.__anext__)
|
| 133 |
+
except StopAsyncIteration:
|
| 134 |
+
break
|
| 135 |
+
|
| 136 |
+
return wrapper
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def get_loop():
|
| 140 |
+
"""Create or return the default fsspec IO loop
|
| 141 |
+
|
| 142 |
+
The loop will be running on a separate thread.
|
| 143 |
+
"""
|
| 144 |
+
if loop[0] is None:
|
| 145 |
+
with get_lock():
|
| 146 |
+
# repeat the check just in case the loop got filled between the
|
| 147 |
+
# previous two calls from another thread
|
| 148 |
+
if loop[0] is None:
|
| 149 |
+
loop[0] = asyncio.new_event_loop()
|
| 150 |
+
th = threading.Thread(target=loop[0].run_forever, name="fsspecIO")
|
| 151 |
+
th.daemon = True
|
| 152 |
+
th.start()
|
| 153 |
+
iothread[0] = th
|
| 154 |
+
return loop[0]
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def reset_after_fork():
|
| 158 |
+
global lock
|
| 159 |
+
loop[0] = None
|
| 160 |
+
iothread[0] = None
|
| 161 |
+
lock = None
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
if hasattr(os, "register_at_fork"):
|
| 165 |
+
# should be posix; this will do nothing for spawn or forkserver subprocesses
|
| 166 |
+
os.register_at_fork(after_in_child=reset_after_fork)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
if TYPE_CHECKING:
|
| 170 |
+
import resource
|
| 171 |
+
|
| 172 |
+
ResourceError = resource.error
|
| 173 |
+
else:
|
| 174 |
+
try:
|
| 175 |
+
import resource
|
| 176 |
+
except ImportError:
|
| 177 |
+
resource = None
|
| 178 |
+
ResourceError = OSError
|
| 179 |
+
else:
|
| 180 |
+
ResourceError = getattr(resource, "error", OSError)
|
| 181 |
+
|
| 182 |
+
_DEFAULT_BATCH_SIZE = 128
|
| 183 |
+
_NOFILES_DEFAULT_BATCH_SIZE = 1280
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def _get_batch_size(nofiles=False):
|
| 187 |
+
from fsspec.config import conf
|
| 188 |
+
|
| 189 |
+
if nofiles:
|
| 190 |
+
if "nofiles_gather_batch_size" in conf:
|
| 191 |
+
return conf["nofiles_gather_batch_size"]
|
| 192 |
+
else:
|
| 193 |
+
if "gather_batch_size" in conf:
|
| 194 |
+
return conf["gather_batch_size"]
|
| 195 |
+
if nofiles:
|
| 196 |
+
return _NOFILES_DEFAULT_BATCH_SIZE
|
| 197 |
+
if resource is None:
|
| 198 |
+
return _DEFAULT_BATCH_SIZE
|
| 199 |
+
|
| 200 |
+
try:
|
| 201 |
+
soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
|
| 202 |
+
except (ImportError, ValueError, ResourceError):
|
| 203 |
+
return _DEFAULT_BATCH_SIZE
|
| 204 |
+
|
| 205 |
+
if soft_limit == resource.RLIM_INFINITY:
|
| 206 |
+
return -1
|
| 207 |
+
else:
|
| 208 |
+
return soft_limit // 8
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def running_async() -> bool:
|
| 212 |
+
"""Being executed by an event loop?"""
|
| 213 |
+
try:
|
| 214 |
+
asyncio.get_running_loop()
|
| 215 |
+
return True
|
| 216 |
+
except RuntimeError:
|
| 217 |
+
return False
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
async def _run_coros_in_chunks(
|
| 221 |
+
coros,
|
| 222 |
+
batch_size=None,
|
| 223 |
+
callback=DEFAULT_CALLBACK,
|
| 224 |
+
timeout=None,
|
| 225 |
+
return_exceptions=False,
|
| 226 |
+
nofiles=False,
|
| 227 |
+
):
|
| 228 |
+
"""Run the given coroutines in chunks.
|
| 229 |
+
|
| 230 |
+
Parameters
|
| 231 |
+
----------
|
| 232 |
+
coros: list of coroutines to run
|
| 233 |
+
batch_size: int or None
|
| 234 |
+
Number of coroutines to submit/wait on simultaneously.
|
| 235 |
+
If -1, then it will not be any throttling. If
|
| 236 |
+
None, it will be inferred from _get_batch_size()
|
| 237 |
+
callback: fsspec.callbacks.Callback instance
|
| 238 |
+
Gets a relative_update when each coroutine completes
|
| 239 |
+
timeout: number or None
|
| 240 |
+
If given, each coroutine times out after this time. Note that, since
|
| 241 |
+
there are multiple batches, the total run time of this function will in
|
| 242 |
+
general be longer
|
| 243 |
+
return_exceptions: bool
|
| 244 |
+
Same meaning as in asyncio.gather
|
| 245 |
+
nofiles: bool
|
| 246 |
+
If inferring the batch_size, does this operation involve local files?
|
| 247 |
+
If yes, you normally expect smaller batches.
|
| 248 |
+
"""
|
| 249 |
+
|
| 250 |
+
if batch_size is None:
|
| 251 |
+
batch_size = _get_batch_size(nofiles=nofiles)
|
| 252 |
+
|
| 253 |
+
if batch_size == -1:
|
| 254 |
+
batch_size = len(coros)
|
| 255 |
+
elif batch_size <= 0:
|
| 256 |
+
raise ValueError
|
| 257 |
+
|
| 258 |
+
async def _run_coro(coro, i):
|
| 259 |
+
try:
|
| 260 |
+
return await asyncio.wait_for(coro, timeout=timeout), i
|
| 261 |
+
except Exception as e:
|
| 262 |
+
if not return_exceptions:
|
| 263 |
+
raise
|
| 264 |
+
return e, i
|
| 265 |
+
finally:
|
| 266 |
+
callback.relative_update(1)
|
| 267 |
+
|
| 268 |
+
i = 0
|
| 269 |
+
n = len(coros)
|
| 270 |
+
results = [None] * n
|
| 271 |
+
pending = set()
|
| 272 |
+
|
| 273 |
+
while pending or i < n:
|
| 274 |
+
while len(pending) < batch_size and i < n:
|
| 275 |
+
pending.add(asyncio.ensure_future(_run_coro(coros[i], i)))
|
| 276 |
+
i += 1
|
| 277 |
+
|
| 278 |
+
if not pending:
|
| 279 |
+
break
|
| 280 |
+
|
| 281 |
+
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
|
| 282 |
+
first_exc = None
|
| 283 |
+
while done:
|
| 284 |
+
task = done.pop()
|
| 285 |
+
try:
|
| 286 |
+
result, k = await task
|
| 287 |
+
results[k] = result
|
| 288 |
+
except Exception as exc:
|
| 289 |
+
if first_exc is None:
|
| 290 |
+
first_exc = exc
|
| 291 |
+
|
| 292 |
+
if first_exc is not None:
|
| 293 |
+
for task in pending:
|
| 294 |
+
task.cancel()
|
| 295 |
+
if pending:
|
| 296 |
+
await asyncio.gather(*pending, return_exceptions=True)
|
| 297 |
+
raise first_exc
|
| 298 |
+
|
| 299 |
+
return results
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
# these methods should be implemented as async by any async-able backend
|
| 303 |
+
async_methods = [
|
| 304 |
+
"_ls",
|
| 305 |
+
"_cat_file",
|
| 306 |
+
"_get_file",
|
| 307 |
+
"_put_file",
|
| 308 |
+
"_rm_file",
|
| 309 |
+
"_cp_file",
|
| 310 |
+
"_pipe_file",
|
| 311 |
+
"_expand_path",
|
| 312 |
+
"_info",
|
| 313 |
+
"_isfile",
|
| 314 |
+
"_isdir",
|
| 315 |
+
"_exists",
|
| 316 |
+
"_walk",
|
| 317 |
+
"_glob",
|
| 318 |
+
"_find",
|
| 319 |
+
"_du",
|
| 320 |
+
"_size",
|
| 321 |
+
"_mkdir",
|
| 322 |
+
"_makedirs",
|
| 323 |
+
]
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
class AsyncFileSystem(AbstractFileSystem):
|
| 327 |
+
"""Async file operations, default implementations
|
| 328 |
+
|
| 329 |
+
Passes bulk operations to asyncio.gather for concurrent operation.
|
| 330 |
+
|
| 331 |
+
Implementations that have concurrent batch operations and/or async methods
|
| 332 |
+
should inherit from this class instead of AbstractFileSystem. Docstrings are
|
| 333 |
+
copied from the un-underscored method in AbstractFileSystem, if not given.
|
| 334 |
+
"""
|
| 335 |
+
|
| 336 |
+
# note that methods do not have docstring here; they will be copied
|
| 337 |
+
# for _* methods and inferred for overridden methods.
|
| 338 |
+
|
| 339 |
+
async_impl = True
|
| 340 |
+
mirror_sync_methods = True
|
| 341 |
+
disable_throttling = False
|
| 342 |
+
|
| 343 |
+
def __init__(self, *args, asynchronous=False, loop=None, batch_size=None, **kwargs):
|
| 344 |
+
self.asynchronous = asynchronous
|
| 345 |
+
self._pid = os.getpid()
|
| 346 |
+
if not asynchronous:
|
| 347 |
+
self._loop = loop or get_loop()
|
| 348 |
+
else:
|
| 349 |
+
self._loop = None
|
| 350 |
+
self.batch_size = batch_size
|
| 351 |
+
super().__init__(*args, **kwargs)
|
| 352 |
+
|
| 353 |
+
@property
|
| 354 |
+
def loop(self):
|
| 355 |
+
if self._pid != os.getpid():
|
| 356 |
+
raise RuntimeError("This class is not fork-safe")
|
| 357 |
+
return self._loop
|
| 358 |
+
|
| 359 |
+
async def _rm_file(self, path, **kwargs):
|
| 360 |
+
if (
|
| 361 |
+
inspect.iscoroutinefunction(self._rm)
|
| 362 |
+
and type(self)._rm is not AsyncFileSystem._rm
|
| 363 |
+
):
|
| 364 |
+
return await self._rm(path, recursive=False, batch_size=1, **kwargs)
|
| 365 |
+
raise NotImplementedError
|
| 366 |
+
|
| 367 |
+
async def _rm(self, path, recursive=False, batch_size=None, **kwargs):
|
| 368 |
+
# TODO: implement on_error
|
| 369 |
+
batch_size = batch_size or self.batch_size
|
| 370 |
+
path = await self._expand_path(path, recursive=recursive)
|
| 371 |
+
return await _run_coros_in_chunks(
|
| 372 |
+
[self._rm_file(p, **kwargs) for p in reversed(path)],
|
| 373 |
+
batch_size=batch_size,
|
| 374 |
+
nofiles=True,
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
async def _cp_file(self, path1, path2, **kwargs):
|
| 378 |
+
raise NotImplementedError
|
| 379 |
+
|
| 380 |
+
async def _mv_file(self, path1, path2):
|
| 381 |
+
await self._cp_file(path1, path2)
|
| 382 |
+
await self._rm_file(path1)
|
| 383 |
+
|
| 384 |
+
async def _copy(
|
| 385 |
+
self,
|
| 386 |
+
path1,
|
| 387 |
+
path2,
|
| 388 |
+
recursive=False,
|
| 389 |
+
on_error=None,
|
| 390 |
+
maxdepth=None,
|
| 391 |
+
batch_size=None,
|
| 392 |
+
**kwargs,
|
| 393 |
+
):
|
| 394 |
+
if on_error is None and recursive:
|
| 395 |
+
on_error = "ignore"
|
| 396 |
+
elif on_error is None:
|
| 397 |
+
on_error = "raise"
|
| 398 |
+
|
| 399 |
+
if isinstance(path1, list) and isinstance(path2, list):
|
| 400 |
+
# No need to expand paths when both source and destination
|
| 401 |
+
# are provided as lists
|
| 402 |
+
paths1 = path1
|
| 403 |
+
paths2 = path2
|
| 404 |
+
else:
|
| 405 |
+
source_is_str = isinstance(path1, str)
|
| 406 |
+
paths1 = await self._expand_path(
|
| 407 |
+
path1, maxdepth=maxdepth, recursive=recursive
|
| 408 |
+
)
|
| 409 |
+
if source_is_str and (not recursive or maxdepth is not None):
|
| 410 |
+
# Non-recursive glob does not copy directories
|
| 411 |
+
paths1 = [
|
| 412 |
+
p for p in paths1 if not (trailing_sep(p) or await self._isdir(p))
|
| 413 |
+
]
|
| 414 |
+
if not paths1:
|
| 415 |
+
return
|
| 416 |
+
|
| 417 |
+
source_is_file = len(paths1) == 1
|
| 418 |
+
dest_is_dir = isinstance(path2, str) and (
|
| 419 |
+
trailing_sep(path2) or await self._isdir(path2)
|
| 420 |
+
)
|
| 421 |
+
|
| 422 |
+
exists = source_is_str and (
|
| 423 |
+
(has_magic(path1) and source_is_file)
|
| 424 |
+
or (not has_magic(path1) and dest_is_dir and not trailing_sep(path1))
|
| 425 |
+
)
|
| 426 |
+
paths2 = other_paths(
|
| 427 |
+
paths1,
|
| 428 |
+
path2,
|
| 429 |
+
exists=exists,
|
| 430 |
+
flatten=not source_is_str,
|
| 431 |
+
)
|
| 432 |
+
|
| 433 |
+
batch_size = batch_size or self.batch_size
|
| 434 |
+
coros = [self._cp_file(p1, p2, **kwargs) for p1, p2 in zip(paths1, paths2)]
|
| 435 |
+
result = await _run_coros_in_chunks(
|
| 436 |
+
coros, batch_size=batch_size, return_exceptions=True, nofiles=True
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
for ex in filter(is_exception, result):
|
| 440 |
+
if on_error == "ignore" and isinstance(ex, FileNotFoundError):
|
| 441 |
+
continue
|
| 442 |
+
raise ex
|
| 443 |
+
|
| 444 |
+
async def _pipe_file(self, path, value, mode="overwrite", **kwargs):
|
| 445 |
+
raise NotImplementedError
|
| 446 |
+
|
| 447 |
+
async def _pipe(self, path, value=None, batch_size=None, **kwargs):
|
| 448 |
+
if isinstance(path, str):
|
| 449 |
+
path = {path: value}
|
| 450 |
+
batch_size = batch_size or self.batch_size
|
| 451 |
+
return await _run_coros_in_chunks(
|
| 452 |
+
[self._pipe_file(k, v, **kwargs) for k, v in path.items()],
|
| 453 |
+
batch_size=batch_size,
|
| 454 |
+
nofiles=True,
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
async def _process_limits(self, url, start, end):
|
| 458 |
+
"""Helper for "Range"-based _cat_file"""
|
| 459 |
+
size = None
|
| 460 |
+
suff = False
|
| 461 |
+
if start is not None and start < 0:
|
| 462 |
+
# if start is negative and end None, end is the "suffix length"
|
| 463 |
+
if end is None:
|
| 464 |
+
end = -start
|
| 465 |
+
start = ""
|
| 466 |
+
suff = True
|
| 467 |
+
else:
|
| 468 |
+
size = size or (await self._info(url))["size"]
|
| 469 |
+
start = size + start
|
| 470 |
+
elif start is None:
|
| 471 |
+
start = 0
|
| 472 |
+
if not suff:
|
| 473 |
+
if end is not None and end < 0:
|
| 474 |
+
if start is not None:
|
| 475 |
+
size = size or (await self._info(url))["size"]
|
| 476 |
+
end = size + end
|
| 477 |
+
elif end is None:
|
| 478 |
+
end = ""
|
| 479 |
+
if isinstance(end, numbers.Integral):
|
| 480 |
+
end -= 1 # bytes range is inclusive
|
| 481 |
+
return f"bytes={start}-{end}"
|
| 482 |
+
|
| 483 |
+
async def _cat_file(self, path, start=None, end=None, **kwargs):
|
| 484 |
+
raise NotImplementedError
|
| 485 |
+
|
| 486 |
+
async def _cat(
|
| 487 |
+
self, path, recursive=False, on_error="raise", batch_size=None, **kwargs
|
| 488 |
+
):
|
| 489 |
+
paths = await self._expand_path(path, recursive=recursive)
|
| 490 |
+
coros = [self._cat_file(path, **kwargs) for path in paths]
|
| 491 |
+
batch_size = batch_size or self.batch_size
|
| 492 |
+
out = await _run_coros_in_chunks(
|
| 493 |
+
coros, batch_size=batch_size, nofiles=True, return_exceptions=True
|
| 494 |
+
)
|
| 495 |
+
if on_error == "raise":
|
| 496 |
+
ex = next(filter(is_exception, out), False)
|
| 497 |
+
if ex:
|
| 498 |
+
raise ex
|
| 499 |
+
if (
|
| 500 |
+
len(paths) > 1
|
| 501 |
+
or isinstance(path, list)
|
| 502 |
+
or paths[0] != self._strip_protocol(path)
|
| 503 |
+
):
|
| 504 |
+
return {
|
| 505 |
+
k: v
|
| 506 |
+
for k, v in zip(paths, out)
|
| 507 |
+
if on_error != "omit" or not is_exception(v)
|
| 508 |
+
}
|
| 509 |
+
else:
|
| 510 |
+
return out[0]
|
| 511 |
+
|
| 512 |
+
async def _cat_ranges(
|
| 513 |
+
self,
|
| 514 |
+
paths,
|
| 515 |
+
starts,
|
| 516 |
+
ends,
|
| 517 |
+
max_gap=None,
|
| 518 |
+
batch_size=None,
|
| 519 |
+
on_error="return",
|
| 520 |
+
**kwargs,
|
| 521 |
+
):
|
| 522 |
+
"""Get the contents of byte ranges from one or more files
|
| 523 |
+
|
| 524 |
+
Parameters
|
| 525 |
+
----------
|
| 526 |
+
paths: list
|
| 527 |
+
A list of of filepaths on this filesystems
|
| 528 |
+
starts, ends: int or list
|
| 529 |
+
Bytes limits of the read. If using a single int, the same value will be
|
| 530 |
+
used to read all the specified files.
|
| 531 |
+
on_error: "return" or "raise"
|
| 532 |
+
If "return" (default), any per-range exception is placed in the output
|
| 533 |
+
list at the corresponding position. Otherwise the first such exception
|
| 534 |
+
is raised. Matches ``AbstractFileSystem.cat_ranges``.
|
| 535 |
+
"""
|
| 536 |
+
if max_gap is not None:
|
| 537 |
+
# use utils.merge_offset_ranges
|
| 538 |
+
raise NotImplementedError
|
| 539 |
+
if not isinstance(paths, list):
|
| 540 |
+
raise TypeError
|
| 541 |
+
if not isinstance(starts, Iterable):
|
| 542 |
+
starts = [starts] * len(paths)
|
| 543 |
+
if not isinstance(ends, Iterable):
|
| 544 |
+
ends = [ends] * len(paths)
|
| 545 |
+
if len(starts) != len(paths) or len(ends) != len(paths):
|
| 546 |
+
raise ValueError
|
| 547 |
+
coros = [
|
| 548 |
+
self._cat_file(p, start=s, end=e, **kwargs)
|
| 549 |
+
for p, s, e in zip(paths, starts, ends)
|
| 550 |
+
]
|
| 551 |
+
batch_size = batch_size or self.batch_size
|
| 552 |
+
out = await _run_coros_in_chunks(
|
| 553 |
+
coros, batch_size=batch_size, nofiles=True, return_exceptions=True
|
| 554 |
+
)
|
| 555 |
+
if on_error != "return":
|
| 556 |
+
ex = next(filter(is_exception, out), None)
|
| 557 |
+
if ex is not None:
|
| 558 |
+
raise ex
|
| 559 |
+
return out
|
| 560 |
+
|
| 561 |
+
async def _put_file(self, lpath, rpath, mode="overwrite", **kwargs):
|
| 562 |
+
raise NotImplementedError
|
| 563 |
+
|
| 564 |
+
async def _put(
|
| 565 |
+
self,
|
| 566 |
+
lpath,
|
| 567 |
+
rpath,
|
| 568 |
+
recursive=False,
|
| 569 |
+
callback=DEFAULT_CALLBACK,
|
| 570 |
+
batch_size=None,
|
| 571 |
+
maxdepth=None,
|
| 572 |
+
**kwargs,
|
| 573 |
+
):
|
| 574 |
+
"""Copy file(s) from local.
|
| 575 |
+
|
| 576 |
+
Copies a specific file or tree of files (if recursive=True). If rpath
|
| 577 |
+
ends with a "/", it will be assumed to be a directory, and target files
|
| 578 |
+
will go within.
|
| 579 |
+
|
| 580 |
+
The put_file method will be called concurrently on a batch of files. The
|
| 581 |
+
batch_size option can configure the amount of futures that can be executed
|
| 582 |
+
at the same time. If it is -1, then all the files will be uploaded concurrently.
|
| 583 |
+
The default can be set for this instance by passing "batch_size" in the
|
| 584 |
+
constructor, or for all instances by setting the "gather_batch_size" key
|
| 585 |
+
in ``fsspec.config.conf``, falling back to 1/8th of the system limit .
|
| 586 |
+
"""
|
| 587 |
+
if isinstance(lpath, list) and isinstance(rpath, list):
|
| 588 |
+
# No need to expand paths when both source and destination
|
| 589 |
+
# are provided as lists
|
| 590 |
+
rpaths = rpath
|
| 591 |
+
lpaths = lpath
|
| 592 |
+
else:
|
| 593 |
+
source_is_str = isinstance(lpath, str)
|
| 594 |
+
if source_is_str:
|
| 595 |
+
lpath = make_path_posix(lpath)
|
| 596 |
+
fs = LocalFileSystem()
|
| 597 |
+
lpaths = fs.expand_path(lpath, recursive=recursive, maxdepth=maxdepth)
|
| 598 |
+
if source_is_str and (not recursive or maxdepth is not None):
|
| 599 |
+
# Non-recursive glob does not copy directories
|
| 600 |
+
lpaths = [p for p in lpaths if not (trailing_sep(p) or fs.isdir(p))]
|
| 601 |
+
if not lpaths:
|
| 602 |
+
return
|
| 603 |
+
|
| 604 |
+
source_is_file = len(lpaths) == 1
|
| 605 |
+
dest_is_dir = isinstance(rpath, str) and (
|
| 606 |
+
trailing_sep(rpath) or await self._isdir(rpath)
|
| 607 |
+
)
|
| 608 |
+
|
| 609 |
+
rpath = self._strip_protocol(rpath)
|
| 610 |
+
exists = source_is_str and (
|
| 611 |
+
(has_magic(lpath) and source_is_file)
|
| 612 |
+
or (not has_magic(lpath) and dest_is_dir and not trailing_sep(lpath))
|
| 613 |
+
)
|
| 614 |
+
rpaths = other_paths(
|
| 615 |
+
lpaths,
|
| 616 |
+
rpath,
|
| 617 |
+
exists=exists,
|
| 618 |
+
flatten=not source_is_str,
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
is_dir = {l: os.path.isdir(l) for l in lpaths}
|
| 622 |
+
rdirs = [r for l, r in zip(lpaths, rpaths) if is_dir[l]]
|
| 623 |
+
file_pairs = [(l, r) for l, r in zip(lpaths, rpaths) if not is_dir[l]]
|
| 624 |
+
|
| 625 |
+
await asyncio.gather(*[self._makedirs(d, exist_ok=True) for d in rdirs])
|
| 626 |
+
batch_size = batch_size or self.batch_size
|
| 627 |
+
|
| 628 |
+
coros = []
|
| 629 |
+
callback.set_size(len(file_pairs))
|
| 630 |
+
for lfile, rfile in file_pairs:
|
| 631 |
+
put_file = callback.branch_coro(self._put_file)
|
| 632 |
+
coros.append(put_file(lfile, rfile, **kwargs))
|
| 633 |
+
|
| 634 |
+
return await _run_coros_in_chunks(
|
| 635 |
+
coros, batch_size=batch_size, callback=callback
|
| 636 |
+
)
|
| 637 |
+
|
| 638 |
+
async def _get_file(self, rpath, lpath, **kwargs):
|
| 639 |
+
raise NotImplementedError
|
| 640 |
+
|
| 641 |
+
async def _get(
|
| 642 |
+
self,
|
| 643 |
+
rpath,
|
| 644 |
+
lpath,
|
| 645 |
+
recursive=False,
|
| 646 |
+
callback=DEFAULT_CALLBACK,
|
| 647 |
+
maxdepth=None,
|
| 648 |
+
**kwargs,
|
| 649 |
+
):
|
| 650 |
+
"""Copy file(s) to local.
|
| 651 |
+
|
| 652 |
+
Copies a specific file or tree of files (if recursive=True). If lpath
|
| 653 |
+
ends with a "/", it will be assumed to be a directory, and target files
|
| 654 |
+
will go within. Can submit a list of paths, which may be glob-patterns
|
| 655 |
+
and will be expanded.
|
| 656 |
+
|
| 657 |
+
The get_file method will be called concurrently on a batch of files. The
|
| 658 |
+
batch_size option can configure the amount of futures that can be executed
|
| 659 |
+
at the same time. If it is -1, then all the files will be uploaded concurrently.
|
| 660 |
+
The default can be set for this instance by passing "batch_size" in the
|
| 661 |
+
constructor, or for all instances by setting the "gather_batch_size" key
|
| 662 |
+
in ``fsspec.config.conf``, falling back to 1/8th of the system limit .
|
| 663 |
+
"""
|
| 664 |
+
if isinstance(lpath, list) and isinstance(rpath, list):
|
| 665 |
+
# No need to expand paths when both source and destination
|
| 666 |
+
# are provided as lists
|
| 667 |
+
rpaths = rpath
|
| 668 |
+
lpaths = lpath
|
| 669 |
+
else:
|
| 670 |
+
source_is_str = isinstance(rpath, str)
|
| 671 |
+
# First check for rpath trailing slash as _strip_protocol removes it.
|
| 672 |
+
source_not_trailing_sep = source_is_str and not trailing_sep(rpath)
|
| 673 |
+
rpath = self._strip_protocol(rpath)
|
| 674 |
+
rpaths = await self._expand_path(
|
| 675 |
+
rpath, recursive=recursive, maxdepth=maxdepth
|
| 676 |
+
)
|
| 677 |
+
if source_is_str and (not recursive or maxdepth is not None):
|
| 678 |
+
# Non-recursive glob does not copy directories
|
| 679 |
+
rpaths = [
|
| 680 |
+
p for p in rpaths if not (trailing_sep(p) or await self._isdir(p))
|
| 681 |
+
]
|
| 682 |
+
if not rpaths:
|
| 683 |
+
return
|
| 684 |
+
|
| 685 |
+
lpath = make_path_posix(lpath)
|
| 686 |
+
source_is_file = len(rpaths) == 1
|
| 687 |
+
dest_is_dir = isinstance(lpath, str) and (
|
| 688 |
+
trailing_sep(lpath) or LocalFileSystem().isdir(lpath)
|
| 689 |
+
)
|
| 690 |
+
|
| 691 |
+
exists = source_is_str and (
|
| 692 |
+
(has_magic(rpath) and source_is_file)
|
| 693 |
+
or (not has_magic(rpath) and dest_is_dir and source_not_trailing_sep)
|
| 694 |
+
)
|
| 695 |
+
lpaths = other_paths(
|
| 696 |
+
rpaths,
|
| 697 |
+
lpath,
|
| 698 |
+
exists=exists,
|
| 699 |
+
flatten=not source_is_str,
|
| 700 |
+
)
|
| 701 |
+
|
| 702 |
+
[os.makedirs(os.path.dirname(lp), exist_ok=True) for lp in lpaths]
|
| 703 |
+
batch_size = kwargs.pop("batch_size", self.batch_size)
|
| 704 |
+
|
| 705 |
+
coros = []
|
| 706 |
+
callback.set_size(len(lpaths))
|
| 707 |
+
for lpath, rpath in zip(lpaths, rpaths):
|
| 708 |
+
get_file = callback.branch_coro(self._get_file)
|
| 709 |
+
coros.append(get_file(rpath, lpath, **kwargs))
|
| 710 |
+
return await _run_coros_in_chunks(
|
| 711 |
+
coros, batch_size=batch_size, callback=callback
|
| 712 |
+
)
|
| 713 |
+
|
| 714 |
+
async def _isfile(self, path):
|
| 715 |
+
try:
|
| 716 |
+
return (await self._info(path))["type"] == "file"
|
| 717 |
+
except: # noqa: E722
|
| 718 |
+
return False
|
| 719 |
+
|
| 720 |
+
async def _isdir(self, path):
|
| 721 |
+
try:
|
| 722 |
+
return (await self._info(path))["type"] == "directory"
|
| 723 |
+
except OSError:
|
| 724 |
+
return False
|
| 725 |
+
|
| 726 |
+
async def _size(self, path):
|
| 727 |
+
return (await self._info(path)).get("size", None)
|
| 728 |
+
|
| 729 |
+
async def _sizes(self, paths, batch_size=None):
|
| 730 |
+
batch_size = batch_size or self.batch_size
|
| 731 |
+
return await _run_coros_in_chunks(
|
| 732 |
+
[self._size(p) for p in paths], batch_size=batch_size
|
| 733 |
+
)
|
| 734 |
+
|
| 735 |
+
async def _exists(self, path, **kwargs):
|
| 736 |
+
try:
|
| 737 |
+
await self._info(path, **kwargs)
|
| 738 |
+
return True
|
| 739 |
+
except FileNotFoundError:
|
| 740 |
+
return False
|
| 741 |
+
|
| 742 |
+
async def _info(self, path, **kwargs):
|
| 743 |
+
raise NotImplementedError
|
| 744 |
+
|
| 745 |
+
async def _ls(self, path, detail=True, **kwargs):
|
| 746 |
+
raise NotImplementedError
|
| 747 |
+
|
| 748 |
+
async def _walk(self, path, maxdepth=None, on_error="omit", **kwargs):
|
| 749 |
+
if maxdepth is not None and maxdepth < 1:
|
| 750 |
+
raise ValueError("maxdepth must be at least 1")
|
| 751 |
+
|
| 752 |
+
path = self._strip_protocol(path)
|
| 753 |
+
full_dirs = {}
|
| 754 |
+
dirs = {}
|
| 755 |
+
files = {}
|
| 756 |
+
|
| 757 |
+
detail = kwargs.pop("detail", False)
|
| 758 |
+
try:
|
| 759 |
+
listing = await self._ls(path, detail=True, **kwargs)
|
| 760 |
+
except (FileNotFoundError, OSError) as e:
|
| 761 |
+
if on_error == "raise":
|
| 762 |
+
raise
|
| 763 |
+
elif callable(on_error):
|
| 764 |
+
on_error(e)
|
| 765 |
+
if detail:
|
| 766 |
+
yield path, {}, {}
|
| 767 |
+
else:
|
| 768 |
+
yield path, [], []
|
| 769 |
+
return
|
| 770 |
+
|
| 771 |
+
for info in listing:
|
| 772 |
+
# each info name must be at least [path]/part , but here
|
| 773 |
+
# we check also for names like [path]/part/
|
| 774 |
+
pathname = info["name"].rstrip("/")
|
| 775 |
+
name = pathname.rsplit("/", 1)[-1]
|
| 776 |
+
if info["type"] == "directory" and pathname != path:
|
| 777 |
+
# do not include "self" path
|
| 778 |
+
full_dirs[name] = pathname
|
| 779 |
+
dirs[name] = info
|
| 780 |
+
elif pathname == path:
|
| 781 |
+
# file-like with same name as give path
|
| 782 |
+
files[""] = info
|
| 783 |
+
else:
|
| 784 |
+
files[name] = info
|
| 785 |
+
|
| 786 |
+
if detail:
|
| 787 |
+
yield path, dirs, files
|
| 788 |
+
else:
|
| 789 |
+
yield path, list(dirs), list(files)
|
| 790 |
+
|
| 791 |
+
if maxdepth is not None:
|
| 792 |
+
maxdepth -= 1
|
| 793 |
+
if maxdepth < 1:
|
| 794 |
+
return
|
| 795 |
+
|
| 796 |
+
for d in dirs:
|
| 797 |
+
async for _ in self._walk(
|
| 798 |
+
full_dirs[d], maxdepth=maxdepth, detail=detail, **kwargs
|
| 799 |
+
):
|
| 800 |
+
yield _
|
| 801 |
+
|
| 802 |
+
async def _glob(self, path, maxdepth=None, **kwargs):
|
| 803 |
+
if maxdepth is not None and maxdepth < 1:
|
| 804 |
+
raise ValueError("maxdepth must be at least 1")
|
| 805 |
+
|
| 806 |
+
import re
|
| 807 |
+
|
| 808 |
+
seps = (os.path.sep, os.path.altsep) if os.path.altsep else (os.path.sep,)
|
| 809 |
+
ends_with_sep = path.endswith(seps) # _strip_protocol strips trailing slash
|
| 810 |
+
path = self._strip_protocol(path)
|
| 811 |
+
append_slash_to_dirname = ends_with_sep or path.endswith(
|
| 812 |
+
tuple(sep + "**" for sep in seps)
|
| 813 |
+
)
|
| 814 |
+
idx_star = path.find("*") if path.find("*") >= 0 else len(path)
|
| 815 |
+
idx_qmark = path.find("?") if path.find("?") >= 0 else len(path)
|
| 816 |
+
idx_brace = path.find("[") if path.find("[") >= 0 else len(path)
|
| 817 |
+
|
| 818 |
+
min_idx = min(idx_star, idx_qmark, idx_brace)
|
| 819 |
+
|
| 820 |
+
detail = kwargs.pop("detail", False)
|
| 821 |
+
withdirs = kwargs.pop("withdirs", True)
|
| 822 |
+
|
| 823 |
+
if not has_magic(path):
|
| 824 |
+
if await self._exists(path, **kwargs):
|
| 825 |
+
if not detail:
|
| 826 |
+
return [path]
|
| 827 |
+
else:
|
| 828 |
+
return {path: await self._info(path, **kwargs)}
|
| 829 |
+
else:
|
| 830 |
+
if not detail:
|
| 831 |
+
return [] # glob of non-existent returns empty
|
| 832 |
+
else:
|
| 833 |
+
return {}
|
| 834 |
+
elif "/" in path[:min_idx]:
|
| 835 |
+
first_wildcard_idx = min_idx
|
| 836 |
+
min_idx = path[:min_idx].rindex("/")
|
| 837 |
+
root = path[
|
| 838 |
+
: min_idx + 1
|
| 839 |
+
] # everything up to the last / before the first wildcard
|
| 840 |
+
prefix = path[
|
| 841 |
+
min_idx + 1 : first_wildcard_idx
|
| 842 |
+
] # stem between last "/" and first wildcard
|
| 843 |
+
depth = path[min_idx + 1 :].count("/") + 1
|
| 844 |
+
else:
|
| 845 |
+
root = ""
|
| 846 |
+
prefix = path[:min_idx] # stem up to the first wildcard
|
| 847 |
+
depth = path[min_idx + 1 :].count("/") + 1
|
| 848 |
+
|
| 849 |
+
if "**" in path:
|
| 850 |
+
if maxdepth is not None:
|
| 851 |
+
idx_double_stars = path.find("**")
|
| 852 |
+
depth_double_stars = path[idx_double_stars:].count("/") + 1
|
| 853 |
+
depth = depth - depth_double_stars + maxdepth
|
| 854 |
+
else:
|
| 855 |
+
depth = None
|
| 856 |
+
|
| 857 |
+
# Pass the filename stem as prefix= so backends that support it such as
|
| 858 |
+
# gcsfs, s3fs and adlfs can filter server-side up to the first wildcard.
|
| 859 |
+
if prefix:
|
| 860 |
+
kwargs["prefix"] = prefix
|
| 861 |
+
allpaths = await self._find(
|
| 862 |
+
root, maxdepth=depth, withdirs=withdirs, detail=True, **kwargs
|
| 863 |
+
)
|
| 864 |
+
|
| 865 |
+
pattern = glob_translate(path + ("/" if ends_with_sep else ""))
|
| 866 |
+
pattern = re.compile(pattern)
|
| 867 |
+
|
| 868 |
+
out = {
|
| 869 |
+
p: info
|
| 870 |
+
for p, info in sorted(allpaths.items())
|
| 871 |
+
if pattern.match(
|
| 872 |
+
p + "/"
|
| 873 |
+
if append_slash_to_dirname and info["type"] == "directory"
|
| 874 |
+
else p
|
| 875 |
+
)
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
if detail:
|
| 879 |
+
return out
|
| 880 |
+
else:
|
| 881 |
+
return list(out)
|
| 882 |
+
|
| 883 |
+
async def _du(self, path, total=True, maxdepth=None, **kwargs):
|
| 884 |
+
sizes = {}
|
| 885 |
+
# async for?
|
| 886 |
+
for f in await self._find(path, maxdepth=maxdepth, **kwargs):
|
| 887 |
+
info = await self._info(f)
|
| 888 |
+
sizes[info["name"]] = info["size"]
|
| 889 |
+
if total:
|
| 890 |
+
return sum(sizes.values())
|
| 891 |
+
else:
|
| 892 |
+
return sizes
|
| 893 |
+
|
| 894 |
+
async def _find(self, path, maxdepth=None, withdirs=False, **kwargs):
|
| 895 |
+
path = self._strip_protocol(path)
|
| 896 |
+
out = {}
|
| 897 |
+
detail = kwargs.pop("detail", False)
|
| 898 |
+
|
| 899 |
+
# Add the root directory if withdirs is requested
|
| 900 |
+
# This is needed for posix glob compliance
|
| 901 |
+
if withdirs and path != "" and await self._isdir(path):
|
| 902 |
+
out[path] = await self._info(path)
|
| 903 |
+
|
| 904 |
+
# async for?
|
| 905 |
+
async for _, dirs, files in self._walk(path, maxdepth, detail=True, **kwargs):
|
| 906 |
+
if withdirs:
|
| 907 |
+
files.update(dirs)
|
| 908 |
+
out.update({info["name"]: info for name, info in files.items()})
|
| 909 |
+
if not out and (await self._isfile(path)):
|
| 910 |
+
# walk works on directories, but find should also return [path]
|
| 911 |
+
# when path happens to be a file
|
| 912 |
+
out[path] = {}
|
| 913 |
+
names = sorted(out)
|
| 914 |
+
if not detail:
|
| 915 |
+
return names
|
| 916 |
+
else:
|
| 917 |
+
return {name: out[name] for name in names}
|
| 918 |
+
|
| 919 |
+
async def _expand_path(
|
| 920 |
+
self, path, recursive=False, maxdepth=None, assume_literal=False
|
| 921 |
+
):
|
| 922 |
+
if maxdepth is not None and maxdepth < 1:
|
| 923 |
+
raise ValueError("maxdepth must be at least 1")
|
| 924 |
+
|
| 925 |
+
if isinstance(path, str):
|
| 926 |
+
out = await self._expand_path([path], recursive, maxdepth)
|
| 927 |
+
else:
|
| 928 |
+
out = set()
|
| 929 |
+
path = [self._strip_protocol(p) for p in path]
|
| 930 |
+
for p in path: # can gather here
|
| 931 |
+
if not assume_literal and has_magic(p):
|
| 932 |
+
bit = set(await self._glob(p, maxdepth=maxdepth))
|
| 933 |
+
out |= bit
|
| 934 |
+
if recursive:
|
| 935 |
+
# glob call above expanded one depth so if maxdepth is defined
|
| 936 |
+
# then decrement it in expand_path call below. If it is zero
|
| 937 |
+
# after decrementing then avoid expand_path call.
|
| 938 |
+
if maxdepth is not None and maxdepth <= 1:
|
| 939 |
+
continue
|
| 940 |
+
out |= set(
|
| 941 |
+
await self._expand_path(
|
| 942 |
+
list(bit),
|
| 943 |
+
recursive=recursive,
|
| 944 |
+
maxdepth=maxdepth - 1 if maxdepth is not None else None,
|
| 945 |
+
assume_literal=True,
|
| 946 |
+
)
|
| 947 |
+
)
|
| 948 |
+
continue
|
| 949 |
+
elif recursive:
|
| 950 |
+
rec = set(await self._find(p, maxdepth=maxdepth, withdirs=True))
|
| 951 |
+
out |= rec
|
| 952 |
+
if p not in out and (recursive is False or (await self._exists(p))):
|
| 953 |
+
# should only check once, for the root
|
| 954 |
+
out.add(p)
|
| 955 |
+
if not out:
|
| 956 |
+
raise FileNotFoundError(path)
|
| 957 |
+
return sorted(out)
|
| 958 |
+
|
| 959 |
+
async def _mkdir(self, path, create_parents=True, **kwargs):
|
| 960 |
+
pass # not necessary to implement, may not have directories
|
| 961 |
+
|
| 962 |
+
async def _makedirs(self, path, exist_ok=False):
|
| 963 |
+
pass # not necessary to implement, may not have directories
|
| 964 |
+
|
| 965 |
+
async def open_async(self, path, mode="rb", **kwargs):
|
| 966 |
+
if "b" not in mode or kwargs.get("compression"):
|
| 967 |
+
raise ValueError
|
| 968 |
+
raise NotImplementedError
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
def mirror_sync_methods(obj):
|
| 972 |
+
"""Populate sync and async methods for obj
|
| 973 |
+
|
| 974 |
+
For each method will create a sync version if the name refers to an async method
|
| 975 |
+
(coroutine) and there is no override in the child class; will create an async
|
| 976 |
+
method for the corresponding sync method if there is no implementation.
|
| 977 |
+
|
| 978 |
+
Uses the methods specified in
|
| 979 |
+
- async_methods: the set that an implementation is expected to provide
|
| 980 |
+
- default_async_methods: that can be derived from their sync version in
|
| 981 |
+
AbstractFileSystem
|
| 982 |
+
- AsyncFileSystem: async-specific default coroutines
|
| 983 |
+
"""
|
| 984 |
+
from fsspec import AbstractFileSystem
|
| 985 |
+
|
| 986 |
+
for method in set(async_methods + dir(AsyncFileSystem)):
|
| 987 |
+
if not method.startswith("_"):
|
| 988 |
+
continue
|
| 989 |
+
smethod = method[1:]
|
| 990 |
+
if private.match(method):
|
| 991 |
+
isco = inspect.iscoroutinefunction(getattr(obj, method, None))
|
| 992 |
+
unsync = getattr(getattr(obj, smethod, False), "__func__", None)
|
| 993 |
+
is_default = unsync is getattr(AbstractFileSystem, smethod, "")
|
| 994 |
+
if isco and is_default:
|
| 995 |
+
mth = sync_wrapper(getattr(obj, method), obj=obj)
|
| 996 |
+
elif inspect.isasyncgenfunction(getattr(obj, method, None)) and is_default:
|
| 997 |
+
mth = async_gen_wrapper(getattr(obj, method), obj=obj)
|
| 998 |
+
else:
|
| 999 |
+
continue
|
| 1000 |
+
setattr(obj, smethod, mth)
|
| 1001 |
+
if not mth.__doc__:
|
| 1002 |
+
mth.__doc__ = getattr(
|
| 1003 |
+
getattr(AbstractFileSystem, smethod, None), "__doc__", ""
|
| 1004 |
+
)
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
class FSSpecCoroutineCancel(Exception):
|
| 1008 |
+
pass
|
| 1009 |
+
|
| 1010 |
+
|
| 1011 |
+
def _dump_running_tasks(
|
| 1012 |
+
printout=True, cancel=True, exc=FSSpecCoroutineCancel, with_task=False
|
| 1013 |
+
):
|
| 1014 |
+
import traceback
|
| 1015 |
+
|
| 1016 |
+
tasks = [t for t in asyncio.tasks.all_tasks(loop[0]) if not t.done()]
|
| 1017 |
+
if printout:
|
| 1018 |
+
[task.print_stack() for task in tasks]
|
| 1019 |
+
out = [
|
| 1020 |
+
{
|
| 1021 |
+
"locals": task._coro.cr_frame.f_locals,
|
| 1022 |
+
"file": task._coro.cr_frame.f_code.co_filename,
|
| 1023 |
+
"firstline": task._coro.cr_frame.f_code.co_firstlineno,
|
| 1024 |
+
"linelo": task._coro.cr_frame.f_lineno,
|
| 1025 |
+
"stack": traceback.format_stack(task._coro.cr_frame),
|
| 1026 |
+
"task": task if with_task else None,
|
| 1027 |
+
}
|
| 1028 |
+
for task in tasks
|
| 1029 |
+
]
|
| 1030 |
+
if cancel:
|
| 1031 |
+
for t in tasks:
|
| 1032 |
+
cbs = t._callbacks
|
| 1033 |
+
t.cancel()
|
| 1034 |
+
asyncio.futures.Future.set_exception(t, exc)
|
| 1035 |
+
asyncio.futures.Future.cancel(t)
|
| 1036 |
+
[cb[0](t) for cb in cbs] # cancels any dependent concurrent.futures
|
| 1037 |
+
try:
|
| 1038 |
+
t._coro.throw(exc) # exits coro, unless explicitly handled
|
| 1039 |
+
except exc:
|
| 1040 |
+
pass
|
| 1041 |
+
return out
|
| 1042 |
+
|
| 1043 |
+
|
| 1044 |
+
class AbstractAsyncStreamedFile(AbstractBufferedFile):
|
| 1045 |
+
# no read buffering, and always auto-commit
|
| 1046 |
+
# TODO: readahead might still be useful here, but needs async version
|
| 1047 |
+
|
| 1048 |
+
async def read(self, length=-1):
|
| 1049 |
+
"""
|
| 1050 |
+
Return data from cache, or fetch pieces as necessary
|
| 1051 |
+
|
| 1052 |
+
Parameters
|
| 1053 |
+
----------
|
| 1054 |
+
length: int (-1)
|
| 1055 |
+
Number of bytes to read; if <0, all remaining bytes.
|
| 1056 |
+
"""
|
| 1057 |
+
length = -1 if length is None else int(length)
|
| 1058 |
+
if self.mode != "rb":
|
| 1059 |
+
raise ValueError("File not in read mode")
|
| 1060 |
+
if length < 0:
|
| 1061 |
+
length = self.size - self.loc
|
| 1062 |
+
if self.closed:
|
| 1063 |
+
raise ValueError("I/O operation on closed file.")
|
| 1064 |
+
if length == 0:
|
| 1065 |
+
# don't even bother calling fetch
|
| 1066 |
+
return b""
|
| 1067 |
+
out = await self._fetch_range(self.loc, self.loc + length)
|
| 1068 |
+
self.loc += len(out)
|
| 1069 |
+
return out
|
| 1070 |
+
|
| 1071 |
+
async def write(self, data):
|
| 1072 |
+
"""
|
| 1073 |
+
Write data to buffer.
|
| 1074 |
+
|
| 1075 |
+
Buffer only sent on flush() or if buffer is greater than
|
| 1076 |
+
or equal to blocksize.
|
| 1077 |
+
|
| 1078 |
+
Parameters
|
| 1079 |
+
----------
|
| 1080 |
+
data: bytes
|
| 1081 |
+
Set of bytes to be written.
|
| 1082 |
+
"""
|
| 1083 |
+
if self.mode not in {"wb", "ab"}:
|
| 1084 |
+
raise ValueError("File not in write mode")
|
| 1085 |
+
if self.closed:
|
| 1086 |
+
raise ValueError("I/O operation on closed file.")
|
| 1087 |
+
if self.forced:
|
| 1088 |
+
raise ValueError("This file has been force-flushed, can only close")
|
| 1089 |
+
out = self.buffer.write(data)
|
| 1090 |
+
self.loc += out
|
| 1091 |
+
if self.buffer.tell() >= self.blocksize:
|
| 1092 |
+
await self.flush()
|
| 1093 |
+
return out
|
| 1094 |
+
|
| 1095 |
+
async def close(self):
|
| 1096 |
+
"""Close file
|
| 1097 |
+
|
| 1098 |
+
Finalizes writes, discards cache
|
| 1099 |
+
"""
|
| 1100 |
+
if getattr(self, "_unclosable", False):
|
| 1101 |
+
return
|
| 1102 |
+
if self.closed:
|
| 1103 |
+
return
|
| 1104 |
+
if self.mode == "rb":
|
| 1105 |
+
self.cache = None
|
| 1106 |
+
else:
|
| 1107 |
+
if not self.forced:
|
| 1108 |
+
await self.flush(force=True)
|
| 1109 |
+
|
| 1110 |
+
if self.fs is not None:
|
| 1111 |
+
self.fs.invalidate_cache(self.path)
|
| 1112 |
+
self.fs.invalidate_cache(self.fs._parent(self.path))
|
| 1113 |
+
|
| 1114 |
+
self.closed = True
|
| 1115 |
+
|
| 1116 |
+
async def flush(self, force=False):
|
| 1117 |
+
if self.closed:
|
| 1118 |
+
raise ValueError("Flush on closed file")
|
| 1119 |
+
if force and self.forced:
|
| 1120 |
+
raise ValueError("Force flush cannot be called more than once")
|
| 1121 |
+
if force:
|
| 1122 |
+
self.forced = True
|
| 1123 |
+
|
| 1124 |
+
if self.mode not in {"wb", "ab"}:
|
| 1125 |
+
# no-op to flush on read-mode
|
| 1126 |
+
return
|
| 1127 |
+
|
| 1128 |
+
if not force and self.buffer.tell() < self.blocksize:
|
| 1129 |
+
# Defer write on small block
|
| 1130 |
+
return
|
| 1131 |
+
|
| 1132 |
+
if self.offset is None:
|
| 1133 |
+
# Initialize a multipart upload
|
| 1134 |
+
self.offset = 0
|
| 1135 |
+
try:
|
| 1136 |
+
await self._initiate_upload()
|
| 1137 |
+
except:
|
| 1138 |
+
self.closed = True
|
| 1139 |
+
raise
|
| 1140 |
+
|
| 1141 |
+
if await self._upload_chunk(final=force) is not False:
|
| 1142 |
+
self.offset += self.buffer.seek(0, 2)
|
| 1143 |
+
self.buffer = io.BytesIO()
|
| 1144 |
+
|
| 1145 |
+
async def __aenter__(self):
|
| 1146 |
+
return self
|
| 1147 |
+
|
| 1148 |
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
| 1149 |
+
await self.close()
|
| 1150 |
+
|
| 1151 |
+
async def _fetch_range(self, start, end):
|
| 1152 |
+
raise NotImplementedError
|
| 1153 |
+
|
| 1154 |
+
async def _initiate_upload(self):
|
| 1155 |
+
pass
|
| 1156 |
+
|
| 1157 |
+
async def _upload_chunk(self, final=False):
|
| 1158 |
+
raise NotImplementedError
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/caching.py
ADDED
|
@@ -0,0 +1,1004 @@
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import collections
|
| 4 |
+
import functools
|
| 5 |
+
import logging
|
| 6 |
+
import math
|
| 7 |
+
import os
|
| 8 |
+
import threading
|
| 9 |
+
from collections import OrderedDict
|
| 10 |
+
from collections.abc import Callable
|
| 11 |
+
from concurrent.futures import Future, ThreadPoolExecutor
|
| 12 |
+
from itertools import groupby
|
| 13 |
+
from operator import itemgetter
|
| 14 |
+
from typing import TYPE_CHECKING, Any, ClassVar, Generic, NamedTuple, TypeVar
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
import mmap
|
| 18 |
+
|
| 19 |
+
from typing_extensions import ParamSpec
|
| 20 |
+
|
| 21 |
+
P = ParamSpec("P")
|
| 22 |
+
else:
|
| 23 |
+
P = TypeVar("P")
|
| 24 |
+
|
| 25 |
+
T = TypeVar("T")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
logger = logging.getLogger("fsspec.caching")
|
| 29 |
+
|
| 30 |
+
Fetcher = Callable[[int, int], bytes] # Maps (start, end) to bytes
|
| 31 |
+
MultiFetcher = Callable[[list[int, int]], bytes] # Maps [(start, end)] to bytes
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class BaseCache:
|
| 35 |
+
"""Pass-though cache: doesn't keep anything, calls every time
|
| 36 |
+
|
| 37 |
+
Acts as base class for other cachers
|
| 38 |
+
|
| 39 |
+
Parameters
|
| 40 |
+
----------
|
| 41 |
+
blocksize: int
|
| 42 |
+
How far to read ahead in numbers of bytes
|
| 43 |
+
fetcher: func
|
| 44 |
+
Function of the form f(start, end) which gets bytes from remote as
|
| 45 |
+
specified
|
| 46 |
+
size: int
|
| 47 |
+
How big this file is
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
name: ClassVar[str] = "none"
|
| 51 |
+
|
| 52 |
+
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None:
|
| 53 |
+
self.blocksize = blocksize
|
| 54 |
+
self.nblocks = 0
|
| 55 |
+
self.fetcher = fetcher
|
| 56 |
+
self.size = size
|
| 57 |
+
self.hit_count = 0
|
| 58 |
+
self.miss_count = 0
|
| 59 |
+
# the bytes that we actually requested
|
| 60 |
+
self.total_requested_bytes = 0
|
| 61 |
+
|
| 62 |
+
def _fetch(self, start: int | None, stop: int | None) -> bytes:
|
| 63 |
+
if start is None:
|
| 64 |
+
start = 0
|
| 65 |
+
if stop is None:
|
| 66 |
+
stop = self.size
|
| 67 |
+
if start >= self.size or start >= stop:
|
| 68 |
+
return b""
|
| 69 |
+
return self.fetcher(start, stop)
|
| 70 |
+
|
| 71 |
+
def _reset_stats(self) -> None:
|
| 72 |
+
"""Reset hit and miss counts for a more ganular report e.g. by file."""
|
| 73 |
+
self.hit_count = 0
|
| 74 |
+
self.miss_count = 0
|
| 75 |
+
self.total_requested_bytes = 0
|
| 76 |
+
|
| 77 |
+
def _log_stats(self) -> str:
|
| 78 |
+
"""Return a formatted string of the cache statistics."""
|
| 79 |
+
if self.hit_count == 0 and self.miss_count == 0:
|
| 80 |
+
# a cache that does nothing, this is for logs only
|
| 81 |
+
return ""
|
| 82 |
+
return f" , {self.name}: {self.hit_count} hits, {self.miss_count} misses, {self.total_requested_bytes} total requested bytes"
|
| 83 |
+
|
| 84 |
+
def __repr__(self) -> str:
|
| 85 |
+
# TODO: use rich for better formatting
|
| 86 |
+
return f"""
|
| 87 |
+
<{self.__class__.__name__}:
|
| 88 |
+
block size : {self.blocksize}
|
| 89 |
+
block count : {self.nblocks}
|
| 90 |
+
file size : {self.size}
|
| 91 |
+
cache hits : {self.hit_count}
|
| 92 |
+
cache misses: {self.miss_count}
|
| 93 |
+
total requested bytes: {self.total_requested_bytes}>
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class MMapCache(BaseCache):
|
| 98 |
+
"""memory-mapped sparse file cache
|
| 99 |
+
|
| 100 |
+
Opens temporary file, which is filled blocks-wise when data is requested.
|
| 101 |
+
Ensure there is enough disc space in the temporary location.
|
| 102 |
+
|
| 103 |
+
This cache method might only work on posix
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
blocksize: int
|
| 108 |
+
How far to read ahead in numbers of bytes
|
| 109 |
+
fetcher: Fetcher
|
| 110 |
+
Function of the form f(start, end) which gets bytes from remote as
|
| 111 |
+
specified
|
| 112 |
+
size: int
|
| 113 |
+
How big this file is
|
| 114 |
+
location: str
|
| 115 |
+
Where to create the temporary file. If None, a temporary file is
|
| 116 |
+
created using tempfile.TemporaryFile().
|
| 117 |
+
blocks: set[int]
|
| 118 |
+
Set of block numbers that have already been fetched. If None, an empty
|
| 119 |
+
set is created.
|
| 120 |
+
multi_fetcher: MultiFetcher
|
| 121 |
+
Function of the form f([(start, end)]) which gets bytes from remote
|
| 122 |
+
as specified. This function is used to fetch multiple blocks at once.
|
| 123 |
+
If not specified, the fetcher function is used instead.
|
| 124 |
+
"""
|
| 125 |
+
|
| 126 |
+
name = "mmap"
|
| 127 |
+
|
| 128 |
+
def __init__(
|
| 129 |
+
self,
|
| 130 |
+
blocksize: int,
|
| 131 |
+
fetcher: Fetcher,
|
| 132 |
+
size: int,
|
| 133 |
+
location: str | None = None,
|
| 134 |
+
blocks: set[int] | None = None,
|
| 135 |
+
multi_fetcher: MultiFetcher | None = None,
|
| 136 |
+
) -> None:
|
| 137 |
+
super().__init__(blocksize, fetcher, size)
|
| 138 |
+
self.blocks = set() if blocks is None else blocks
|
| 139 |
+
self.location = location
|
| 140 |
+
self.multi_fetcher = multi_fetcher
|
| 141 |
+
self.cache = self._makefile()
|
| 142 |
+
|
| 143 |
+
def _makefile(self) -> mmap.mmap | bytearray:
|
| 144 |
+
import mmap
|
| 145 |
+
import tempfile
|
| 146 |
+
|
| 147 |
+
if self.size == 0:
|
| 148 |
+
return bytearray()
|
| 149 |
+
|
| 150 |
+
# posix version
|
| 151 |
+
if self.location is None or not os.path.exists(self.location):
|
| 152 |
+
if self.location is None:
|
| 153 |
+
fd = tempfile.TemporaryFile()
|
| 154 |
+
self.blocks = set()
|
| 155 |
+
else:
|
| 156 |
+
fd = open(self.location, "wb+")
|
| 157 |
+
fd.seek(self.size - 1)
|
| 158 |
+
fd.write(b"1")
|
| 159 |
+
fd.flush()
|
| 160 |
+
else:
|
| 161 |
+
fd = open(self.location, "r+b")
|
| 162 |
+
|
| 163 |
+
return mmap.mmap(fd.fileno(), self.size)
|
| 164 |
+
|
| 165 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 166 |
+
logger.debug(f"MMap cache fetching {start}-{end}")
|
| 167 |
+
if start is None:
|
| 168 |
+
start = 0
|
| 169 |
+
if end is None:
|
| 170 |
+
end = self.size
|
| 171 |
+
if start >= self.size or start >= end:
|
| 172 |
+
return b""
|
| 173 |
+
start_block = start // self.blocksize
|
| 174 |
+
end_block = end // self.blocksize
|
| 175 |
+
block_range = range(start_block, end_block + 1)
|
| 176 |
+
# Determine which blocks need to be fetched. This sequence is sorted by construction.
|
| 177 |
+
need = (i for i in block_range if i not in self.blocks)
|
| 178 |
+
# Count the number of blocks already cached
|
| 179 |
+
self.hit_count += sum(1 for i in block_range if i in self.blocks)
|
| 180 |
+
|
| 181 |
+
ranges = []
|
| 182 |
+
|
| 183 |
+
# Consolidate needed blocks.
|
| 184 |
+
# Algorithm adapted from Python 2.x itertools documentation.
|
| 185 |
+
# We are grouping an enumerated sequence of blocks. By comparing when the difference
|
| 186 |
+
# between an ascending range (provided by enumerate) and the needed block numbers
|
| 187 |
+
# we can detect when the block number skips values. The key computes this difference.
|
| 188 |
+
# Whenever the difference changes, we know that we have previously cached block(s),
|
| 189 |
+
# and a new group is started. In other words, this algorithm neatly groups
|
| 190 |
+
# runs of consecutive block numbers so they can be fetched together.
|
| 191 |
+
for _, _blocks in groupby(enumerate(need), key=lambda x: x[0] - x[1]):
|
| 192 |
+
# Extract the blocks from the enumerated sequence
|
| 193 |
+
_blocks = tuple(map(itemgetter(1), _blocks))
|
| 194 |
+
# Compute start of first block
|
| 195 |
+
sstart = _blocks[0] * self.blocksize
|
| 196 |
+
# Compute the end of the last block. Last block may not be full size.
|
| 197 |
+
send = min(_blocks[-1] * self.blocksize + self.blocksize, self.size)
|
| 198 |
+
|
| 199 |
+
# Fetch bytes (could be multiple consecutive blocks)
|
| 200 |
+
self.total_requested_bytes += send - sstart
|
| 201 |
+
logger.debug(
|
| 202 |
+
f"MMap get blocks {_blocks[0]}-{_blocks[-1]} ({sstart}-{send})"
|
| 203 |
+
)
|
| 204 |
+
ranges.append((sstart, send))
|
| 205 |
+
|
| 206 |
+
# Update set of cached blocks
|
| 207 |
+
self.blocks.update(_blocks)
|
| 208 |
+
# Update cache statistics with number of blocks we had to cache
|
| 209 |
+
self.miss_count += len(_blocks)
|
| 210 |
+
|
| 211 |
+
if not ranges:
|
| 212 |
+
return self.cache[start:end]
|
| 213 |
+
|
| 214 |
+
if self.multi_fetcher:
|
| 215 |
+
logger.debug(f"MMap get blocks {ranges}")
|
| 216 |
+
for idx, r in enumerate(self.multi_fetcher(ranges)):
|
| 217 |
+
sstart, send = ranges[idx]
|
| 218 |
+
logger.debug(f"MMap copy block ({sstart}-{send}")
|
| 219 |
+
self.cache[sstart:send] = r
|
| 220 |
+
else:
|
| 221 |
+
for sstart, send in ranges:
|
| 222 |
+
logger.debug(f"MMap get block ({sstart}-{send}")
|
| 223 |
+
self.cache[sstart:send] = self.fetcher(sstart, send)
|
| 224 |
+
|
| 225 |
+
return self.cache[start:end]
|
| 226 |
+
|
| 227 |
+
def __getstate__(self) -> dict[str, Any]:
|
| 228 |
+
state = self.__dict__.copy()
|
| 229 |
+
# Remove the unpicklable entries.
|
| 230 |
+
del state["cache"]
|
| 231 |
+
return state
|
| 232 |
+
|
| 233 |
+
def __setstate__(self, state: dict[str, Any]) -> None:
|
| 234 |
+
# Restore instance attributes
|
| 235 |
+
self.__dict__.update(state)
|
| 236 |
+
self.cache = self._makefile()
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class ReadAheadCache(BaseCache):
|
| 240 |
+
"""Cache which reads only when we get beyond a block of data
|
| 241 |
+
|
| 242 |
+
This is a much simpler version of BytesCache, and does not attempt to
|
| 243 |
+
fill holes in the cache or keep fragments alive. It is best suited to
|
| 244 |
+
many small reads in a sequential order (e.g., reading lines from a file).
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
name = "readahead"
|
| 248 |
+
|
| 249 |
+
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None:
|
| 250 |
+
super().__init__(blocksize, fetcher, size)
|
| 251 |
+
self.cache = b""
|
| 252 |
+
self.start = 0
|
| 253 |
+
self.end = 0
|
| 254 |
+
|
| 255 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 256 |
+
if start is None:
|
| 257 |
+
start = 0
|
| 258 |
+
if end is None or end > self.size:
|
| 259 |
+
end = self.size
|
| 260 |
+
if start >= self.size or start >= end:
|
| 261 |
+
return b""
|
| 262 |
+
l = end - start
|
| 263 |
+
if start >= self.start and end <= self.end:
|
| 264 |
+
# cache hit
|
| 265 |
+
self.hit_count += 1
|
| 266 |
+
return self.cache[start - self.start : end - self.start]
|
| 267 |
+
elif self.start <= start < self.end:
|
| 268 |
+
# partial hit
|
| 269 |
+
self.miss_count += 1
|
| 270 |
+
part = self.cache[start - self.start :]
|
| 271 |
+
l -= len(part)
|
| 272 |
+
start = self.end
|
| 273 |
+
else:
|
| 274 |
+
# miss
|
| 275 |
+
self.miss_count += 1
|
| 276 |
+
part = b""
|
| 277 |
+
end = min(self.size, end + self.blocksize)
|
| 278 |
+
self.total_requested_bytes += end - start
|
| 279 |
+
self.cache = self.fetcher(start, end) # new block replaces old
|
| 280 |
+
self.start = start
|
| 281 |
+
self.end = self.start + len(self.cache)
|
| 282 |
+
return part + self.cache[:l]
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
class FirstChunkCache(BaseCache):
|
| 286 |
+
"""Caches the first block of a file only
|
| 287 |
+
|
| 288 |
+
This may be useful for file types where the metadata is stored in the header,
|
| 289 |
+
but is randomly accessed.
|
| 290 |
+
"""
|
| 291 |
+
|
| 292 |
+
name = "first"
|
| 293 |
+
|
| 294 |
+
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None:
|
| 295 |
+
if blocksize > size:
|
| 296 |
+
# this will buffer the whole thing
|
| 297 |
+
blocksize = size
|
| 298 |
+
super().__init__(blocksize, fetcher, size)
|
| 299 |
+
self.cache: bytes | None = None
|
| 300 |
+
|
| 301 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 302 |
+
start = start or 0
|
| 303 |
+
if start > self.size:
|
| 304 |
+
logger.debug("FirstChunkCache: requested start > file size")
|
| 305 |
+
return b""
|
| 306 |
+
|
| 307 |
+
end = min(end, self.size)
|
| 308 |
+
|
| 309 |
+
if start < self.blocksize:
|
| 310 |
+
if self.cache is None:
|
| 311 |
+
self.miss_count += 1
|
| 312 |
+
if end > self.blocksize:
|
| 313 |
+
self.total_requested_bytes += end
|
| 314 |
+
data = self.fetcher(0, end)
|
| 315 |
+
self.cache = data[: self.blocksize]
|
| 316 |
+
return data[start:]
|
| 317 |
+
self.cache = self.fetcher(0, self.blocksize)
|
| 318 |
+
self.total_requested_bytes += self.blocksize
|
| 319 |
+
part = self.cache[start:end]
|
| 320 |
+
if end > self.blocksize:
|
| 321 |
+
self.total_requested_bytes += end - self.blocksize
|
| 322 |
+
part += self.fetcher(self.blocksize, end)
|
| 323 |
+
self.hit_count += 1
|
| 324 |
+
return part
|
| 325 |
+
else:
|
| 326 |
+
self.miss_count += 1
|
| 327 |
+
self.total_requested_bytes += end - start
|
| 328 |
+
return self.fetcher(start, end)
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class BlockCache(BaseCache):
|
| 332 |
+
"""
|
| 333 |
+
Cache holding memory as a set of blocks.
|
| 334 |
+
|
| 335 |
+
Requests are only ever made ``blocksize`` at a time, and are
|
| 336 |
+
stored in an LRU cache. The least recently accessed block is
|
| 337 |
+
discarded when more than ``maxblocks`` are stored.
|
| 338 |
+
|
| 339 |
+
Parameters
|
| 340 |
+
----------
|
| 341 |
+
blocksize : int
|
| 342 |
+
The number of bytes to store in each block.
|
| 343 |
+
Requests are only ever made for ``blocksize``, so this
|
| 344 |
+
should balance the overhead of making a request against
|
| 345 |
+
the granularity of the blocks.
|
| 346 |
+
fetcher : Callable
|
| 347 |
+
size : int
|
| 348 |
+
The total size of the file being cached.
|
| 349 |
+
maxblocks : int
|
| 350 |
+
The maximum number of blocks to cache for. The maximum memory
|
| 351 |
+
use for this cache is then ``blocksize * maxblocks``.
|
| 352 |
+
"""
|
| 353 |
+
|
| 354 |
+
name = "blockcache"
|
| 355 |
+
|
| 356 |
+
def __init__(
|
| 357 |
+
self, blocksize: int, fetcher: Fetcher, size: int, maxblocks: int = 32
|
| 358 |
+
) -> None:
|
| 359 |
+
super().__init__(blocksize, fetcher, size)
|
| 360 |
+
self.nblocks = math.ceil(size / blocksize)
|
| 361 |
+
self.maxblocks = maxblocks
|
| 362 |
+
self._fetch_block_cached = functools.lru_cache(maxblocks)(self._fetch_block)
|
| 363 |
+
|
| 364 |
+
def cache_info(self):
|
| 365 |
+
"""
|
| 366 |
+
The statistics on the block cache.
|
| 367 |
+
|
| 368 |
+
Returns
|
| 369 |
+
-------
|
| 370 |
+
NamedTuple
|
| 371 |
+
Returned directly from the LRU Cache used internally.
|
| 372 |
+
"""
|
| 373 |
+
return self._fetch_block_cached.cache_info()
|
| 374 |
+
|
| 375 |
+
def __getstate__(self) -> dict[str, Any]:
|
| 376 |
+
state = self.__dict__
|
| 377 |
+
del state["_fetch_block_cached"]
|
| 378 |
+
return state
|
| 379 |
+
|
| 380 |
+
def __setstate__(self, state: dict[str, Any]) -> None:
|
| 381 |
+
self.__dict__.update(state)
|
| 382 |
+
self._fetch_block_cached = functools.lru_cache(state["maxblocks"])(
|
| 383 |
+
self._fetch_block
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 387 |
+
if start is None:
|
| 388 |
+
start = 0
|
| 389 |
+
if end is None:
|
| 390 |
+
end = self.size
|
| 391 |
+
if start >= self.size or start >= end:
|
| 392 |
+
return b""
|
| 393 |
+
|
| 394 |
+
return self._read_cache(
|
| 395 |
+
start, end, start // self.blocksize, (end - 1) // self.blocksize
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
def _fetch_block(self, block_number: int) -> bytes:
|
| 399 |
+
"""
|
| 400 |
+
Fetch the block of data for `block_number`.
|
| 401 |
+
"""
|
| 402 |
+
if block_number > self.nblocks:
|
| 403 |
+
raise ValueError(
|
| 404 |
+
f"'block_number={block_number}' is greater than "
|
| 405 |
+
f"the number of blocks ({self.nblocks})"
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
+
start = block_number * self.blocksize
|
| 409 |
+
end = start + self.blocksize
|
| 410 |
+
self.total_requested_bytes += end - start
|
| 411 |
+
self.miss_count += 1
|
| 412 |
+
logger.info("BlockCache fetching block %d", block_number)
|
| 413 |
+
block_contents = super()._fetch(start, end)
|
| 414 |
+
return block_contents
|
| 415 |
+
|
| 416 |
+
def _read_cache(
|
| 417 |
+
self, start: int, end: int, start_block_number: int, end_block_number: int
|
| 418 |
+
) -> bytes:
|
| 419 |
+
"""
|
| 420 |
+
Read from our block cache.
|
| 421 |
+
|
| 422 |
+
Parameters
|
| 423 |
+
----------
|
| 424 |
+
start, end : int
|
| 425 |
+
The start and end byte positions.
|
| 426 |
+
start_block_number, end_block_number : int
|
| 427 |
+
The start and end block numbers.
|
| 428 |
+
"""
|
| 429 |
+
start_pos = start % self.blocksize
|
| 430 |
+
end_pos = end % self.blocksize
|
| 431 |
+
if end_pos == 0:
|
| 432 |
+
end_pos = self.blocksize
|
| 433 |
+
|
| 434 |
+
self.hit_count += 1
|
| 435 |
+
if start_block_number == end_block_number:
|
| 436 |
+
block: bytes = self._fetch_block_cached(start_block_number)
|
| 437 |
+
return block[start_pos:end_pos]
|
| 438 |
+
|
| 439 |
+
else:
|
| 440 |
+
# read from the initial
|
| 441 |
+
out = [self._fetch_block_cached(start_block_number)[start_pos:]]
|
| 442 |
+
|
| 443 |
+
# intermediate blocks
|
| 444 |
+
# Note: it'd be nice to combine these into one big request. However
|
| 445 |
+
# that doesn't play nicely with our LRU cache.
|
| 446 |
+
out.extend(
|
| 447 |
+
map(
|
| 448 |
+
self._fetch_block_cached,
|
| 449 |
+
range(start_block_number + 1, end_block_number),
|
| 450 |
+
)
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
# final block
|
| 454 |
+
out.append(self._fetch_block_cached(end_block_number)[:end_pos])
|
| 455 |
+
|
| 456 |
+
return b"".join(out)
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class BytesCache(BaseCache):
|
| 460 |
+
"""Cache which holds data in a in-memory bytes object
|
| 461 |
+
|
| 462 |
+
Implements read-ahead by the block size, for semi-random reads progressing
|
| 463 |
+
through the file.
|
| 464 |
+
|
| 465 |
+
Parameters
|
| 466 |
+
----------
|
| 467 |
+
trim: bool
|
| 468 |
+
As we read more data, whether to discard the start of the buffer when
|
| 469 |
+
we are more than a blocksize ahead of it.
|
| 470 |
+
"""
|
| 471 |
+
|
| 472 |
+
name: ClassVar[str] = "bytes"
|
| 473 |
+
|
| 474 |
+
def __init__(
|
| 475 |
+
self, blocksize: int, fetcher: Fetcher, size: int, trim: bool = True
|
| 476 |
+
) -> None:
|
| 477 |
+
super().__init__(blocksize, fetcher, size)
|
| 478 |
+
self.cache = b""
|
| 479 |
+
self.start: int | None = None
|
| 480 |
+
self.end: int | None = None
|
| 481 |
+
self.trim = trim
|
| 482 |
+
|
| 483 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 484 |
+
# TODO: only set start/end after fetch, in case it fails?
|
| 485 |
+
# is this where retry logic might go?
|
| 486 |
+
if start is None:
|
| 487 |
+
start = 0
|
| 488 |
+
if end is None:
|
| 489 |
+
end = self.size
|
| 490 |
+
if start >= self.size or start >= end:
|
| 491 |
+
return b""
|
| 492 |
+
if (
|
| 493 |
+
self.start is not None
|
| 494 |
+
and start >= self.start
|
| 495 |
+
and self.end is not None
|
| 496 |
+
and end < self.end
|
| 497 |
+
):
|
| 498 |
+
# cache hit: we have all the required data
|
| 499 |
+
offset = start - self.start
|
| 500 |
+
self.hit_count += 1
|
| 501 |
+
return self.cache[offset : offset + end - start]
|
| 502 |
+
|
| 503 |
+
if self.blocksize:
|
| 504 |
+
bend = min(self.size, end + self.blocksize)
|
| 505 |
+
else:
|
| 506 |
+
bend = end
|
| 507 |
+
|
| 508 |
+
if bend == start or start > self.size:
|
| 509 |
+
return b""
|
| 510 |
+
|
| 511 |
+
if (self.start is None or start < self.start) and (
|
| 512 |
+
self.end is None or end > self.end
|
| 513 |
+
):
|
| 514 |
+
# First read, or extending both before and after
|
| 515 |
+
self.total_requested_bytes += bend - start
|
| 516 |
+
self.miss_count += 1
|
| 517 |
+
self.cache = self.fetcher(start, bend)
|
| 518 |
+
self.start = start
|
| 519 |
+
else:
|
| 520 |
+
assert self.start is not None
|
| 521 |
+
assert self.end is not None
|
| 522 |
+
self.miss_count += 1
|
| 523 |
+
|
| 524 |
+
if start < self.start:
|
| 525 |
+
if self.end is None or self.end - end > self.blocksize:
|
| 526 |
+
self.total_requested_bytes += bend - start
|
| 527 |
+
self.cache = self.fetcher(start, bend)
|
| 528 |
+
self.start = start
|
| 529 |
+
else:
|
| 530 |
+
self.total_requested_bytes += self.start - start
|
| 531 |
+
new = self.fetcher(start, self.start)
|
| 532 |
+
self.start = start
|
| 533 |
+
self.cache = new + self.cache
|
| 534 |
+
elif self.end is not None and bend > self.end:
|
| 535 |
+
if self.end > self.size:
|
| 536 |
+
pass
|
| 537 |
+
elif end - self.end > self.blocksize:
|
| 538 |
+
self.total_requested_bytes += bend - start
|
| 539 |
+
self.cache = self.fetcher(start, bend)
|
| 540 |
+
self.start = start
|
| 541 |
+
else:
|
| 542 |
+
self.total_requested_bytes += bend - self.end
|
| 543 |
+
new = self.fetcher(self.end, bend)
|
| 544 |
+
self.cache = self.cache + new
|
| 545 |
+
|
| 546 |
+
self.end = self.start + len(self.cache)
|
| 547 |
+
offset = start - self.start
|
| 548 |
+
out = self.cache[offset : offset + end - start]
|
| 549 |
+
if self.trim:
|
| 550 |
+
num = (self.end - self.start) // (self.blocksize + 1)
|
| 551 |
+
if num > 1:
|
| 552 |
+
self.start += self.blocksize * num
|
| 553 |
+
self.cache = self.cache[self.blocksize * num :]
|
| 554 |
+
return out
|
| 555 |
+
|
| 556 |
+
def __len__(self) -> int:
|
| 557 |
+
return len(self.cache)
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
class AllBytes(BaseCache):
|
| 561 |
+
"""Cache entire contents of the file"""
|
| 562 |
+
|
| 563 |
+
name: ClassVar[str] = "all"
|
| 564 |
+
|
| 565 |
+
def __init__(
|
| 566 |
+
self,
|
| 567 |
+
blocksize: int | None = None,
|
| 568 |
+
fetcher: Fetcher | None = None,
|
| 569 |
+
size: int | None = None,
|
| 570 |
+
data: bytes | None = None,
|
| 571 |
+
) -> None:
|
| 572 |
+
super().__init__(blocksize, fetcher, size) # type: ignore[arg-type]
|
| 573 |
+
if data is None:
|
| 574 |
+
self.miss_count += 1
|
| 575 |
+
self.total_requested_bytes += self.size
|
| 576 |
+
data = self.fetcher(0, self.size)
|
| 577 |
+
self.data = data
|
| 578 |
+
|
| 579 |
+
def _fetch(self, start: int | None, stop: int | None) -> bytes:
|
| 580 |
+
self.hit_count += 1
|
| 581 |
+
return self.data[start:stop]
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
class KnownPartsOfAFile(BaseCache):
|
| 585 |
+
"""
|
| 586 |
+
Cache holding known file parts.
|
| 587 |
+
|
| 588 |
+
Parameters
|
| 589 |
+
----------
|
| 590 |
+
blocksize: int
|
| 591 |
+
How far to read ahead in numbers of bytes
|
| 592 |
+
fetcher: func
|
| 593 |
+
Function of the form f(start, end) which gets bytes from remote as
|
| 594 |
+
specified
|
| 595 |
+
size: int
|
| 596 |
+
How big this file is
|
| 597 |
+
data: dict
|
| 598 |
+
A dictionary mapping explicit `(start, stop)` file-offset tuples
|
| 599 |
+
with known bytes.
|
| 600 |
+
strict: bool, default True
|
| 601 |
+
Whether to fetch reads that go beyond a known byte-range boundary.
|
| 602 |
+
If `False`, any read that ends outside a known part will be zero
|
| 603 |
+
padded. Note that zero padding will not be used for reads that
|
| 604 |
+
begin outside a known byte-range.
|
| 605 |
+
"""
|
| 606 |
+
|
| 607 |
+
name: ClassVar[str] = "parts"
|
| 608 |
+
|
| 609 |
+
def __init__(
|
| 610 |
+
self,
|
| 611 |
+
blocksize: int,
|
| 612 |
+
fetcher: Fetcher,
|
| 613 |
+
size: int,
|
| 614 |
+
data: dict[tuple[int, int], bytes] | None = None,
|
| 615 |
+
strict: bool = False,
|
| 616 |
+
**_: Any,
|
| 617 |
+
):
|
| 618 |
+
super().__init__(blocksize, fetcher, size)
|
| 619 |
+
self.strict = strict
|
| 620 |
+
|
| 621 |
+
# simple consolidation of contiguous blocks
|
| 622 |
+
if data:
|
| 623 |
+
old_offsets = sorted(data.keys())
|
| 624 |
+
offsets = [old_offsets[0]]
|
| 625 |
+
blocks = [data.pop(old_offsets[0])]
|
| 626 |
+
for start, stop in old_offsets[1:]:
|
| 627 |
+
start0, stop0 = offsets[-1]
|
| 628 |
+
if start == stop0:
|
| 629 |
+
offsets[-1] = (start0, stop)
|
| 630 |
+
blocks[-1] += data.pop((start, stop))
|
| 631 |
+
else:
|
| 632 |
+
offsets.append((start, stop))
|
| 633 |
+
blocks.append(data.pop((start, stop)))
|
| 634 |
+
|
| 635 |
+
self.data = dict(zip(offsets, blocks))
|
| 636 |
+
else:
|
| 637 |
+
self.data = {}
|
| 638 |
+
|
| 639 |
+
@property
|
| 640 |
+
def size(self):
|
| 641 |
+
return sum(_[1] - _[0] for _ in self.data)
|
| 642 |
+
|
| 643 |
+
@size.setter
|
| 644 |
+
def size(self, value):
|
| 645 |
+
pass
|
| 646 |
+
|
| 647 |
+
@property
|
| 648 |
+
def nblocks(self):
|
| 649 |
+
return len(self.data)
|
| 650 |
+
|
| 651 |
+
@nblocks.setter
|
| 652 |
+
def nblocks(self, value):
|
| 653 |
+
pass
|
| 654 |
+
|
| 655 |
+
def _fetch(self, start: int | None, stop: int | None) -> bytes:
|
| 656 |
+
logger.debug("Known parts request %s %s", start, stop)
|
| 657 |
+
if start is None:
|
| 658 |
+
start = 0
|
| 659 |
+
if stop is None:
|
| 660 |
+
stop = self.size
|
| 661 |
+
self.total_requested_bytes += stop - start
|
| 662 |
+
out = b""
|
| 663 |
+
started = False
|
| 664 |
+
loc_old = 0
|
| 665 |
+
for loc0, loc1 in sorted(self.data):
|
| 666 |
+
if (loc0 <= start < loc1) and (loc0 <= stop <= loc1):
|
| 667 |
+
# entirely within the block
|
| 668 |
+
off = start - loc0
|
| 669 |
+
self.hit_count += 1
|
| 670 |
+
return self.data[(loc0, loc1)][off : off + stop - start]
|
| 671 |
+
if stop <= loc0:
|
| 672 |
+
break
|
| 673 |
+
if started and loc0 > loc_old:
|
| 674 |
+
# a gap where we need data
|
| 675 |
+
self.miss_count += 1
|
| 676 |
+
if self.strict:
|
| 677 |
+
raise ValueError
|
| 678 |
+
out += b"\x00" * (loc0 - loc_old)
|
| 679 |
+
if loc0 <= start < loc1:
|
| 680 |
+
# found the start
|
| 681 |
+
self.hit_count += 1
|
| 682 |
+
off = start - loc0
|
| 683 |
+
out = self.data[(loc0, loc1)][off : off + stop - start]
|
| 684 |
+
started = True
|
| 685 |
+
elif start < loc0 and stop > loc1:
|
| 686 |
+
# the whole block
|
| 687 |
+
self.hit_count += 1
|
| 688 |
+
out += self.data[(loc0, loc1)]
|
| 689 |
+
elif loc0 <= stop <= loc1:
|
| 690 |
+
# end block
|
| 691 |
+
self.hit_count += 1
|
| 692 |
+
out = out + self.data[(loc0, loc1)][: stop - loc0]
|
| 693 |
+
return out
|
| 694 |
+
loc_old = loc1
|
| 695 |
+
self.miss_count += 1
|
| 696 |
+
if started and not self.strict:
|
| 697 |
+
out = out + b"\x00" * (stop - loc_old)
|
| 698 |
+
return out
|
| 699 |
+
raise ValueError
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
class UpdatableLRU(Generic[P, T]):
|
| 703 |
+
"""
|
| 704 |
+
Custom implementation of LRU cache that allows updating keys
|
| 705 |
+
|
| 706 |
+
Used by BackgroundBlockCache
|
| 707 |
+
"""
|
| 708 |
+
|
| 709 |
+
class CacheInfo(NamedTuple):
|
| 710 |
+
hits: int
|
| 711 |
+
misses: int
|
| 712 |
+
maxsize: int
|
| 713 |
+
currsize: int
|
| 714 |
+
|
| 715 |
+
def __init__(self, func: Callable[P, T], max_size: int = 128) -> None:
|
| 716 |
+
self._cache: OrderedDict[Any, T] = collections.OrderedDict()
|
| 717 |
+
self._func = func
|
| 718 |
+
self._max_size = max_size
|
| 719 |
+
self._hits = 0
|
| 720 |
+
self._misses = 0
|
| 721 |
+
self._lock = threading.Lock()
|
| 722 |
+
|
| 723 |
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
| 724 |
+
if kwargs:
|
| 725 |
+
raise TypeError(f"Got unexpected keyword argument {kwargs.keys()}")
|
| 726 |
+
with self._lock:
|
| 727 |
+
if args in self._cache:
|
| 728 |
+
self._cache.move_to_end(args)
|
| 729 |
+
self._hits += 1
|
| 730 |
+
return self._cache[args]
|
| 731 |
+
|
| 732 |
+
result = self._func(*args, **kwargs)
|
| 733 |
+
|
| 734 |
+
with self._lock:
|
| 735 |
+
self._cache[args] = result
|
| 736 |
+
self._misses += 1
|
| 737 |
+
if len(self._cache) > self._max_size:
|
| 738 |
+
self._cache.popitem(last=False)
|
| 739 |
+
|
| 740 |
+
return result
|
| 741 |
+
|
| 742 |
+
def is_key_cached(self, *args: Any) -> bool:
|
| 743 |
+
with self._lock:
|
| 744 |
+
return args in self._cache
|
| 745 |
+
|
| 746 |
+
def add_key(self, result: T, *args: Any) -> None:
|
| 747 |
+
with self._lock:
|
| 748 |
+
self._cache[args] = result
|
| 749 |
+
if len(self._cache) > self._max_size:
|
| 750 |
+
self._cache.popitem(last=False)
|
| 751 |
+
|
| 752 |
+
def cache_info(self) -> UpdatableLRU.CacheInfo:
|
| 753 |
+
with self._lock:
|
| 754 |
+
return self.CacheInfo(
|
| 755 |
+
maxsize=self._max_size,
|
| 756 |
+
currsize=len(self._cache),
|
| 757 |
+
hits=self._hits,
|
| 758 |
+
misses=self._misses,
|
| 759 |
+
)
|
| 760 |
+
|
| 761 |
+
|
| 762 |
+
class BackgroundBlockCache(BaseCache):
|
| 763 |
+
"""
|
| 764 |
+
Cache holding memory as a set of blocks with pre-loading of
|
| 765 |
+
the next block in the background.
|
| 766 |
+
|
| 767 |
+
Requests are only ever made ``blocksize`` at a time, and are
|
| 768 |
+
stored in an LRU cache. The least recently accessed block is
|
| 769 |
+
discarded when more than ``maxblocks`` are stored. If the
|
| 770 |
+
next block is not in cache, it is loaded in a separate thread
|
| 771 |
+
in non-blocking way.
|
| 772 |
+
|
| 773 |
+
Parameters
|
| 774 |
+
----------
|
| 775 |
+
blocksize : int
|
| 776 |
+
The number of bytes to store in each block.
|
| 777 |
+
Requests are only ever made for ``blocksize``, so this
|
| 778 |
+
should balance the overhead of making a request against
|
| 779 |
+
the granularity of the blocks.
|
| 780 |
+
fetcher : Callable
|
| 781 |
+
size : int
|
| 782 |
+
The total size of the file being cached.
|
| 783 |
+
maxblocks : int
|
| 784 |
+
The maximum number of blocks to cache for. The maximum memory
|
| 785 |
+
use for this cache is then ``blocksize * maxblocks``.
|
| 786 |
+
"""
|
| 787 |
+
|
| 788 |
+
name: ClassVar[str] = "background"
|
| 789 |
+
|
| 790 |
+
def __init__(
|
| 791 |
+
self, blocksize: int, fetcher: Fetcher, size: int, maxblocks: int = 32
|
| 792 |
+
) -> None:
|
| 793 |
+
super().__init__(blocksize, fetcher, size)
|
| 794 |
+
self.nblocks = math.ceil(size / blocksize)
|
| 795 |
+
self.maxblocks = maxblocks
|
| 796 |
+
self._fetch_block_cached = UpdatableLRU(self._fetch_block, maxblocks)
|
| 797 |
+
|
| 798 |
+
self._thread_executor = ThreadPoolExecutor(max_workers=1)
|
| 799 |
+
self._fetch_future_block_number: int | None = None
|
| 800 |
+
self._fetch_future: Future[bytes] | None = None
|
| 801 |
+
self._fetch_future_lock = threading.Lock()
|
| 802 |
+
|
| 803 |
+
def cache_info(self) -> UpdatableLRU.CacheInfo:
|
| 804 |
+
"""
|
| 805 |
+
The statistics on the block cache.
|
| 806 |
+
|
| 807 |
+
Returns
|
| 808 |
+
-------
|
| 809 |
+
NamedTuple
|
| 810 |
+
Returned directly from the LRU Cache used internally.
|
| 811 |
+
"""
|
| 812 |
+
return self._fetch_block_cached.cache_info()
|
| 813 |
+
|
| 814 |
+
def __getstate__(self) -> dict[str, Any]:
|
| 815 |
+
state = self.__dict__
|
| 816 |
+
del state["_fetch_block_cached"]
|
| 817 |
+
del state["_thread_executor"]
|
| 818 |
+
del state["_fetch_future_block_number"]
|
| 819 |
+
del state["_fetch_future"]
|
| 820 |
+
del state["_fetch_future_lock"]
|
| 821 |
+
return state
|
| 822 |
+
|
| 823 |
+
def __setstate__(self, state) -> None:
|
| 824 |
+
self.__dict__.update(state)
|
| 825 |
+
self._fetch_block_cached = UpdatableLRU(self._fetch_block, state["maxblocks"])
|
| 826 |
+
self._thread_executor = ThreadPoolExecutor(max_workers=1)
|
| 827 |
+
self._fetch_future_block_number = None
|
| 828 |
+
self._fetch_future = None
|
| 829 |
+
self._fetch_future_lock = threading.Lock()
|
| 830 |
+
|
| 831 |
+
def _fetch(self, start: int | None, end: int | None) -> bytes:
|
| 832 |
+
if start is None:
|
| 833 |
+
start = 0
|
| 834 |
+
if end is None:
|
| 835 |
+
end = self.size
|
| 836 |
+
if start >= self.size or start >= end:
|
| 837 |
+
return b""
|
| 838 |
+
|
| 839 |
+
# byte position -> block numbers
|
| 840 |
+
start_block_number = start // self.blocksize
|
| 841 |
+
end_block_number = end // self.blocksize
|
| 842 |
+
|
| 843 |
+
fetch_future_block_number = None
|
| 844 |
+
fetch_future = None
|
| 845 |
+
with self._fetch_future_lock:
|
| 846 |
+
# Background thread is running. Check we we can or must join it.
|
| 847 |
+
if self._fetch_future is not None:
|
| 848 |
+
assert self._fetch_future_block_number is not None
|
| 849 |
+
if self._fetch_future.done():
|
| 850 |
+
logger.info("BlockCache joined background fetch without waiting.")
|
| 851 |
+
self._fetch_block_cached.add_key(
|
| 852 |
+
self._fetch_future.result(), self._fetch_future_block_number
|
| 853 |
+
)
|
| 854 |
+
# Cleanup the fetch variables. Done with fetching the block.
|
| 855 |
+
self._fetch_future_block_number = None
|
| 856 |
+
self._fetch_future = None
|
| 857 |
+
else:
|
| 858 |
+
# Must join if we need the block for the current fetch
|
| 859 |
+
must_join = bool(
|
| 860 |
+
start_block_number
|
| 861 |
+
<= self._fetch_future_block_number
|
| 862 |
+
<= end_block_number
|
| 863 |
+
)
|
| 864 |
+
if must_join:
|
| 865 |
+
# Copy to the local variables to release lock
|
| 866 |
+
# before waiting for result
|
| 867 |
+
fetch_future_block_number = self._fetch_future_block_number
|
| 868 |
+
fetch_future = self._fetch_future
|
| 869 |
+
|
| 870 |
+
# Cleanup the fetch variables. Have a local copy.
|
| 871 |
+
self._fetch_future_block_number = None
|
| 872 |
+
self._fetch_future = None
|
| 873 |
+
|
| 874 |
+
# Need to wait for the future for the current read
|
| 875 |
+
if fetch_future is not None:
|
| 876 |
+
logger.info("BlockCache waiting for background fetch.")
|
| 877 |
+
# Wait until result and put it in cache
|
| 878 |
+
self._fetch_block_cached.add_key(
|
| 879 |
+
fetch_future.result(), fetch_future_block_number
|
| 880 |
+
)
|
| 881 |
+
|
| 882 |
+
# these are cached, so safe to do multiple calls for the same start and end.
|
| 883 |
+
for block_number in range(start_block_number, end_block_number + 1):
|
| 884 |
+
self._fetch_block_cached(block_number)
|
| 885 |
+
|
| 886 |
+
# fetch next block in the background if nothing is running in the background,
|
| 887 |
+
# the block is within file and it is not already cached
|
| 888 |
+
end_block_plus_1 = end_block_number + 1
|
| 889 |
+
with self._fetch_future_lock:
|
| 890 |
+
if (
|
| 891 |
+
self._fetch_future is None
|
| 892 |
+
and end_block_plus_1 <= self.nblocks
|
| 893 |
+
and not self._fetch_block_cached.is_key_cached(end_block_plus_1)
|
| 894 |
+
):
|
| 895 |
+
self._fetch_future_block_number = end_block_plus_1
|
| 896 |
+
self._fetch_future = self._thread_executor.submit(
|
| 897 |
+
self._fetch_block, end_block_plus_1, "async"
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
return self._read_cache(
|
| 901 |
+
start,
|
| 902 |
+
end,
|
| 903 |
+
start_block_number=start_block_number,
|
| 904 |
+
end_block_number=end_block_number,
|
| 905 |
+
)
|
| 906 |
+
|
| 907 |
+
def _fetch_block(self, block_number: int, log_info: str = "sync") -> bytes:
|
| 908 |
+
"""
|
| 909 |
+
Fetch the block of data for `block_number`.
|
| 910 |
+
"""
|
| 911 |
+
if block_number > self.nblocks:
|
| 912 |
+
raise ValueError(
|
| 913 |
+
f"'block_number={block_number}' is greater than "
|
| 914 |
+
f"the number of blocks ({self.nblocks})"
|
| 915 |
+
)
|
| 916 |
+
|
| 917 |
+
start = block_number * self.blocksize
|
| 918 |
+
end = start + self.blocksize
|
| 919 |
+
logger.info("BlockCache fetching block (%s) %d", log_info, block_number)
|
| 920 |
+
self.total_requested_bytes += end - start
|
| 921 |
+
self.miss_count += 1
|
| 922 |
+
block_contents = super()._fetch(start, end)
|
| 923 |
+
return block_contents
|
| 924 |
+
|
| 925 |
+
def _read_cache(
|
| 926 |
+
self, start: int, end: int, start_block_number: int, end_block_number: int
|
| 927 |
+
) -> bytes:
|
| 928 |
+
"""
|
| 929 |
+
Read from our block cache.
|
| 930 |
+
|
| 931 |
+
Parameters
|
| 932 |
+
----------
|
| 933 |
+
start, end : int
|
| 934 |
+
The start and end byte positions.
|
| 935 |
+
start_block_number, end_block_number : int
|
| 936 |
+
The start and end block numbers.
|
| 937 |
+
"""
|
| 938 |
+
start_pos = start % self.blocksize
|
| 939 |
+
end_pos = end % self.blocksize
|
| 940 |
+
|
| 941 |
+
# kind of pointless to count this as a hit, but it is
|
| 942 |
+
self.hit_count += 1
|
| 943 |
+
|
| 944 |
+
if start_block_number == end_block_number:
|
| 945 |
+
block = self._fetch_block_cached(start_block_number)
|
| 946 |
+
return block[start_pos:end_pos]
|
| 947 |
+
|
| 948 |
+
else:
|
| 949 |
+
# read from the initial
|
| 950 |
+
out = [self._fetch_block_cached(start_block_number)[start_pos:]]
|
| 951 |
+
|
| 952 |
+
# intermediate blocks
|
| 953 |
+
# Note: it'd be nice to combine these into one big request. However
|
| 954 |
+
# that doesn't play nicely with our LRU cache.
|
| 955 |
+
out.extend(
|
| 956 |
+
map(
|
| 957 |
+
self._fetch_block_cached,
|
| 958 |
+
range(start_block_number + 1, end_block_number),
|
| 959 |
+
)
|
| 960 |
+
)
|
| 961 |
+
|
| 962 |
+
# final block
|
| 963 |
+
out.append(self._fetch_block_cached(end_block_number)[:end_pos])
|
| 964 |
+
|
| 965 |
+
return b"".join(out)
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
caches: dict[str | None, type[BaseCache]] = {
|
| 969 |
+
# one custom case
|
| 970 |
+
None: BaseCache,
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
|
| 974 |
+
def register_cache(cls: type[BaseCache], clobber: bool = False) -> None:
|
| 975 |
+
"""'Register' cache implementation.
|
| 976 |
+
|
| 977 |
+
Parameters
|
| 978 |
+
----------
|
| 979 |
+
clobber: bool, optional
|
| 980 |
+
If set to True (default is False) - allow to overwrite existing
|
| 981 |
+
entry.
|
| 982 |
+
|
| 983 |
+
Raises
|
| 984 |
+
------
|
| 985 |
+
ValueError
|
| 986 |
+
"""
|
| 987 |
+
name = cls.name
|
| 988 |
+
if not clobber and name in caches:
|
| 989 |
+
raise ValueError(f"Cache with name {name!r} is already known: {caches[name]}")
|
| 990 |
+
caches[name] = cls
|
| 991 |
+
|
| 992 |
+
|
| 993 |
+
for c in (
|
| 994 |
+
BaseCache,
|
| 995 |
+
MMapCache,
|
| 996 |
+
BytesCache,
|
| 997 |
+
ReadAheadCache,
|
| 998 |
+
BlockCache,
|
| 999 |
+
FirstChunkCache,
|
| 1000 |
+
All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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import wraps
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Callback:
|
| 5 |
+
"""
|
| 6 |
+
Base class and interface for callback mechanism
|
| 7 |
+
|
| 8 |
+
This class can be used directly for monitoring file transfers by
|
| 9 |
+
providing ``callback=Callback(hooks=...)`` (see the ``hooks`` argument,
|
| 10 |
+
below), or subclassed for more specialised behaviour.
|
| 11 |
+
|
| 12 |
+
Parameters
|
| 13 |
+
----------
|
| 14 |
+
size: int (optional)
|
| 15 |
+
Nominal quantity for the value that corresponds to a complete
|
| 16 |
+
transfer, e.g., total number of tiles or total number of
|
| 17 |
+
bytes
|
| 18 |
+
value: int (0)
|
| 19 |
+
Starting internal counter value
|
| 20 |
+
hooks: dict or None
|
| 21 |
+
A dict of named functions to be called on each update. The signature
|
| 22 |
+
of these must be ``f(size, value, **kwargs)``
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def __init__(self, size=None, value=0, hooks=None, **kwargs):
|
| 26 |
+
self.size = size
|
| 27 |
+
self.value = value
|
| 28 |
+
self.hooks = hooks or {}
|
| 29 |
+
self.kw = kwargs
|
| 30 |
+
|
| 31 |
+
def __enter__(self):
|
| 32 |
+
return self
|
| 33 |
+
|
| 34 |
+
def __exit__(self, *exc_args):
|
| 35 |
+
self.close()
|
| 36 |
+
|
| 37 |
+
def close(self):
|
| 38 |
+
"""Close callback."""
|
| 39 |
+
|
| 40 |
+
def branched(self, path_1, path_2, **kwargs):
|
| 41 |
+
"""
|
| 42 |
+
Return callback for child transfers
|
| 43 |
+
|
| 44 |
+
If this callback is operating at a higher level, e.g., put, which may
|
| 45 |
+
trigger transfers that can also be monitored. The function returns a callback
|
| 46 |
+
that has to be passed to the child method, e.g., put_file,
|
| 47 |
+
as `callback=` argument.
|
| 48 |
+
|
| 49 |
+
The implementation uses `callback.branch` for compatibility.
|
| 50 |
+
When implementing callbacks, it is recommended to override this function instead
|
| 51 |
+
of `branch` and avoid calling `super().branched(...)`.
|
| 52 |
+
|
| 53 |
+
Prefer using this function over `branch`.
|
| 54 |
+
|
| 55 |
+
Parameters
|
| 56 |
+
----------
|
| 57 |
+
path_1: str
|
| 58 |
+
Child's source path
|
| 59 |
+
path_2: str
|
| 60 |
+
Child's destination path
|
| 61 |
+
**kwargs:
|
| 62 |
+
Arbitrary keyword arguments
|
| 63 |
+
|
| 64 |
+
Returns
|
| 65 |
+
-------
|
| 66 |
+
callback: Callback
|
| 67 |
+
A callback instance to be passed to the child method
|
| 68 |
+
"""
|
| 69 |
+
self.branch(path_1, path_2, kwargs)
|
| 70 |
+
# mutate kwargs so that we can force the caller to pass "callback=" explicitly
|
| 71 |
+
return kwargs.pop("callback", DEFAULT_CALLBACK)
|
| 72 |
+
|
| 73 |
+
def branch_coro(self, fn):
|
| 74 |
+
"""
|
| 75 |
+
Wraps a coroutine, and pass a new child callback to it.
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
@wraps(fn)
|
| 79 |
+
async def func(path1, path2: str, **kwargs):
|
| 80 |
+
with self.branched(path1, path2, **kwargs) as child:
|
| 81 |
+
return await fn(path1, path2, callback=child, **kwargs)
|
| 82 |
+
|
| 83 |
+
return func
|
| 84 |
+
|
| 85 |
+
def set_size(self, size):
|
| 86 |
+
"""
|
| 87 |
+
Set the internal maximum size attribute
|
| 88 |
+
|
| 89 |
+
Usually called if not initially set at instantiation. Note that this
|
| 90 |
+
triggers a ``call()``.
|
| 91 |
+
|
| 92 |
+
Parameters
|
| 93 |
+
----------
|
| 94 |
+
size: int
|
| 95 |
+
"""
|
| 96 |
+
self.size = size
|
| 97 |
+
self.call()
|
| 98 |
+
|
| 99 |
+
def absolute_update(self, value):
|
| 100 |
+
"""
|
| 101 |
+
Set the internal value state
|
| 102 |
+
|
| 103 |
+
Triggers ``call()``
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
value: int
|
| 108 |
+
"""
|
| 109 |
+
self.value = value
|
| 110 |
+
self.call()
|
| 111 |
+
|
| 112 |
+
def relative_update(self, inc=1):
|
| 113 |
+
"""
|
| 114 |
+
Delta increment the internal counter
|
| 115 |
+
|
| 116 |
+
Triggers ``call()``
|
| 117 |
+
|
| 118 |
+
Parameters
|
| 119 |
+
----------
|
| 120 |
+
inc: int
|
| 121 |
+
"""
|
| 122 |
+
self.value += inc
|
| 123 |
+
self.call()
|
| 124 |
+
|
| 125 |
+
def call(self, hook_name=None, **kwargs):
|
| 126 |
+
"""
|
| 127 |
+
Execute hook(s) with current state
|
| 128 |
+
|
| 129 |
+
Each function is passed the internal size and current value
|
| 130 |
+
|
| 131 |
+
Parameters
|
| 132 |
+
----------
|
| 133 |
+
hook_name: str or None
|
| 134 |
+
If given, execute on this hook
|
| 135 |
+
kwargs: passed on to (all) hook(s)
|
| 136 |
+
"""
|
| 137 |
+
if not self.hooks:
|
| 138 |
+
return
|
| 139 |
+
kw = self.kw.copy()
|
| 140 |
+
kw.update(kwargs)
|
| 141 |
+
if hook_name:
|
| 142 |
+
if hook_name not in self.hooks:
|
| 143 |
+
return
|
| 144 |
+
return self.hooks[hook_name](self.size, self.value, **kw)
|
| 145 |
+
for hook in self.hooks.values() or []:
|
| 146 |
+
hook(self.size, self.value, **kw)
|
| 147 |
+
|
| 148 |
+
def wrap(self, iterable):
|
| 149 |
+
"""
|
| 150 |
+
Wrap an iterable to call ``relative_update`` on each iterations
|
| 151 |
+
|
| 152 |
+
Parameters
|
| 153 |
+
----------
|
| 154 |
+
iterable: Iterable
|
| 155 |
+
The iterable that is being wrapped
|
| 156 |
+
"""
|
| 157 |
+
for item in iterable:
|
| 158 |
+
self.relative_update()
|
| 159 |
+
yield item
|
| 160 |
+
|
| 161 |
+
def branch(self, path_1, path_2, kwargs):
|
| 162 |
+
"""
|
| 163 |
+
Set callbacks for child transfers
|
| 164 |
+
|
| 165 |
+
If this callback is operating at a higher level, e.g., put, which may
|
| 166 |
+
trigger transfers that can also be monitored. The passed kwargs are
|
| 167 |
+
to be *mutated* to add ``callback=``, if this class supports branching
|
| 168 |
+
to children.
|
| 169 |
+
|
| 170 |
+
Parameters
|
| 171 |
+
----------
|
| 172 |
+
path_1: str
|
| 173 |
+
Child's source path
|
| 174 |
+
path_2: str
|
| 175 |
+
Child's destination path
|
| 176 |
+
kwargs: dict
|
| 177 |
+
arguments passed to child method, e.g., put_file.
|
| 178 |
+
|
| 179 |
+
Returns
|
| 180 |
+
-------
|
| 181 |
+
|
| 182 |
+
"""
|
| 183 |
+
return None
|
| 184 |
+
|
| 185 |
+
def no_op(self, *_, **__):
|
| 186 |
+
pass
|
| 187 |
+
|
| 188 |
+
def __getattr__(self, item):
|
| 189 |
+
"""
|
| 190 |
+
If undefined methods are called on this class, nothing happens
|
| 191 |
+
"""
|
| 192 |
+
return self.no_op
|
| 193 |
+
|
| 194 |
+
@classmethod
|
| 195 |
+
def as_callback(cls, maybe_callback=None):
|
| 196 |
+
"""Transform callback=... into Callback instance
|
| 197 |
+
|
| 198 |
+
For the special value of ``None``, return the global instance of
|
| 199 |
+
``NoOpCallback``. This is an alternative to including
|
| 200 |
+
``callback=DEFAULT_CALLBACK`` directly in a method signature.
|
| 201 |
+
"""
|
| 202 |
+
if maybe_callback is None:
|
| 203 |
+
return DEFAULT_CALLBACK
|
| 204 |
+
return maybe_callback
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
class NoOpCallback(Callback):
|
| 208 |
+
"""
|
| 209 |
+
This implementation of Callback does exactly nothing
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
def call(self, *args, **kwargs):
|
| 213 |
+
return None
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class DotPrinterCallback(Callback):
|
| 217 |
+
"""
|
| 218 |
+
Simple example Callback implementation
|
| 219 |
+
|
| 220 |
+
Almost identical to Callback with a hook that prints a char; here we
|
| 221 |
+
demonstrate how the outer layer may print "#" and the inner layer "."
|
| 222 |
+
"""
|
| 223 |
+
|
| 224 |
+
def __init__(self, chr_to_print="#", **kwargs):
|
| 225 |
+
self.chr = chr_to_print
|
| 226 |
+
super().__init__(**kwargs)
|
| 227 |
+
|
| 228 |
+
def branch(self, path_1, path_2, kwargs):
|
| 229 |
+
"""Mutate kwargs to add new instance with different print char"""
|
| 230 |
+
kwargs["callback"] = DotPrinterCallback(".")
|
| 231 |
+
|
| 232 |
+
def call(self, **kwargs):
|
| 233 |
+
"""Just outputs a character"""
|
| 234 |
+
print(self.chr, end="")
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
class TqdmCallback(Callback):
|
| 238 |
+
"""
|
| 239 |
+
A callback to display a progress bar using tqdm
|
| 240 |
+
|
| 241 |
+
Parameters
|
| 242 |
+
----------
|
| 243 |
+
tqdm_kwargs : dict, (optional)
|
| 244 |
+
Any argument accepted by the tqdm constructor.
|
| 245 |
+
See the `tqdm doc <https://tqdm.github.io/docs/tqdm/#__init__>`_.
|
| 246 |
+
Will be forwarded to `tqdm_cls`.
|
| 247 |
+
tqdm_cls: (optional)
|
| 248 |
+
subclass of `tqdm.tqdm`. If not passed, it will default to `tqdm.tqdm`.
|
| 249 |
+
|
| 250 |
+
Examples
|
| 251 |
+
--------
|
| 252 |
+
>>> import fsspec
|
| 253 |
+
>>> from fsspec.callbacks import TqdmCallback
|
| 254 |
+
>>> fs = fsspec.filesystem("memory")
|
| 255 |
+
>>> path2distant_data = "/your-path"
|
| 256 |
+
>>> fs.upload(
|
| 257 |
+
".",
|
| 258 |
+
path2distant_data,
|
| 259 |
+
recursive=True,
|
| 260 |
+
callback=TqdmCallback(),
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
You can forward args to tqdm using the ``tqdm_kwargs`` parameter.
|
| 264 |
+
|
| 265 |
+
>>> fs.upload(
|
| 266 |
+
".",
|
| 267 |
+
path2distant_data,
|
| 268 |
+
recursive=True,
|
| 269 |
+
callback=TqdmCallback(tqdm_kwargs={"desc": "Your tqdm description"}),
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
You can also customize the progress bar by passing a subclass of `tqdm`.
|
| 273 |
+
|
| 274 |
+
.. code-block:: python
|
| 275 |
+
|
| 276 |
+
class TqdmFormat(tqdm):
|
| 277 |
+
'''Provides a `total_time` format parameter'''
|
| 278 |
+
@property
|
| 279 |
+
def format_dict(self):
|
| 280 |
+
d = super().format_dict
|
| 281 |
+
total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
|
| 282 |
+
d.update(total_time=self.format_interval(total_time) + " in total")
|
| 283 |
+
return d
|
| 284 |
+
|
| 285 |
+
>>> with TqdmCallback(
|
| 286 |
+
tqdm_kwargs={
|
| 287 |
+
"desc": "desc",
|
| 288 |
+
"bar_format": "{total_time}: {percentage:.0f}%|{bar}{r_bar}",
|
| 289 |
+
},
|
| 290 |
+
tqdm_cls=TqdmFormat,
|
| 291 |
+
) as callback:
|
| 292 |
+
fs.upload(".", path2distant_data, recursive=True, callback=callback)
|
| 293 |
+
"""
|
| 294 |
+
|
| 295 |
+
def __init__(self, tqdm_kwargs=None, *args, **kwargs):
|
| 296 |
+
try:
|
| 297 |
+
from tqdm import tqdm
|
| 298 |
+
|
| 299 |
+
except ImportError as exce:
|
| 300 |
+
raise ImportError(
|
| 301 |
+
"Using TqdmCallback requires tqdm to be installed"
|
| 302 |
+
) from exce
|
| 303 |
+
|
| 304 |
+
self._tqdm_cls = kwargs.pop("tqdm_cls", tqdm)
|
| 305 |
+
self._tqdm_kwargs = tqdm_kwargs or {}
|
| 306 |
+
self.tqdm = None
|
| 307 |
+
super().__init__(*args, **kwargs)
|
| 308 |
+
|
| 309 |
+
def call(self, *args, **kwargs):
|
| 310 |
+
if self.tqdm is None:
|
| 311 |
+
self.tqdm = self._tqdm_cls(total=self.size, **self._tqdm_kwargs)
|
| 312 |
+
self.tqdm.total = self.size
|
| 313 |
+
self.tqdm.update(self.value - self.tqdm.n)
|
| 314 |
+
|
| 315 |
+
def close(self):
|
| 316 |
+
if self.tqdm is not None:
|
| 317 |
+
self.tqdm.close()
|
| 318 |
+
self.tqdm = None
|
| 319 |
+
|
| 320 |
+
def __del__(self):
|
| 321 |
+
return self.close()
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
DEFAULT_CALLBACK = _DEFAULT_CALLBACK = NoOpCallback()
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/compression.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Helper functions for a standard streaming compression API"""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from zipfile import ZipFile
|
| 5 |
+
|
| 6 |
+
import fsspec.utils
|
| 7 |
+
from fsspec.spec import AbstractBufferedFile
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def noop_file(file, mode, **kwargs):
|
| 11 |
+
return file
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# TODO: files should also be available as contexts
|
| 15 |
+
# should be functions of the form func(infile, mode=, **kwargs) -> file-like
|
| 16 |
+
compr = {None: noop_file}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def register_compression(name, callback, extensions, force=False):
|
| 20 |
+
"""Register an "inferable" file compression type.
|
| 21 |
+
|
| 22 |
+
Registers transparent file compression type for use with fsspec.open.
|
| 23 |
+
Compression can be specified by name in open, or "infer"-ed for any files
|
| 24 |
+
ending with the given extensions.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
name: (str) The compression type name. Eg. "gzip".
|
| 28 |
+
callback: A callable of form (infile, mode, **kwargs) -> file-like.
|
| 29 |
+
Accepts an input file-like object, the target mode and kwargs.
|
| 30 |
+
Returns a wrapped file-like object.
|
| 31 |
+
extensions: (str, Iterable[str]) A file extension, or list of file
|
| 32 |
+
extensions for which to infer this compression scheme. Eg. "gz".
|
| 33 |
+
force: (bool) Force re-registration of compression type or extensions.
|
| 34 |
+
|
| 35 |
+
Raises:
|
| 36 |
+
ValueError: If name or extensions already registered, and not force.
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
if isinstance(extensions, str):
|
| 40 |
+
extensions = [extensions]
|
| 41 |
+
|
| 42 |
+
# Validate registration
|
| 43 |
+
if name in compr and not force:
|
| 44 |
+
raise ValueError(f"Duplicate compression registration: {name}")
|
| 45 |
+
|
| 46 |
+
for ext in extensions:
|
| 47 |
+
if ext in fsspec.utils.compressions and not force:
|
| 48 |
+
raise ValueError(f"Duplicate compression file extension: {ext} ({name})")
|
| 49 |
+
|
| 50 |
+
compr[name] = callback
|
| 51 |
+
|
| 52 |
+
for ext in extensions:
|
| 53 |
+
fsspec.utils.compressions[ext] = name
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def unzip(infile, mode="rb", filename=None, **kwargs):
|
| 57 |
+
if "r" not in mode:
|
| 58 |
+
filename = filename or "file"
|
| 59 |
+
z = ZipFile(infile, mode="w", **kwargs)
|
| 60 |
+
fo = z.open(filename, mode="w")
|
| 61 |
+
fo.close = lambda closer=fo.close: closer() or z.close()
|
| 62 |
+
return fo
|
| 63 |
+
z = ZipFile(infile)
|
| 64 |
+
if filename is None:
|
| 65 |
+
filename = z.namelist()[0]
|
| 66 |
+
return z.open(filename, mode="r", **kwargs)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
register_compression("zip", unzip, "zip")
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
from bz2 import BZ2File
|
| 73 |
+
except ImportError:
|
| 74 |
+
pass
|
| 75 |
+
else:
|
| 76 |
+
register_compression("bz2", BZ2File, "bz2")
|
| 77 |
+
|
| 78 |
+
try: # pragma: no cover
|
| 79 |
+
from isal import igzip
|
| 80 |
+
|
| 81 |
+
def isal(infile, mode="rb", **kwargs):
|
| 82 |
+
return igzip.IGzipFile(fileobj=infile, mode=mode, **kwargs)
|
| 83 |
+
|
| 84 |
+
register_compression("gzip", isal, "gz")
|
| 85 |
+
except ImportError:
|
| 86 |
+
from gzip import GzipFile
|
| 87 |
+
|
| 88 |
+
register_compression(
|
| 89 |
+
"gzip", lambda f, **kwargs: GzipFile(fileobj=f, **kwargs), "gz"
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
try:
|
| 93 |
+
from lzma import LZMAFile
|
| 94 |
+
|
| 95 |
+
register_compression("lzma", LZMAFile, "lzma")
|
| 96 |
+
register_compression("xz", LZMAFile, "xz")
|
| 97 |
+
except ImportError:
|
| 98 |
+
pass
|
| 99 |
+
|
| 100 |
+
try:
|
| 101 |
+
import lzmaffi
|
| 102 |
+
|
| 103 |
+
register_compression("lzma", lzmaffi.LZMAFile, "lzma", force=True)
|
| 104 |
+
register_compression("xz", lzmaffi.LZMAFile, "xz", force=True)
|
| 105 |
+
except ImportError:
|
| 106 |
+
pass
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class SnappyFile(AbstractBufferedFile):
|
| 110 |
+
def __init__(self, infile, mode, **kwargs):
|
| 111 |
+
import snappy
|
| 112 |
+
|
| 113 |
+
super().__init__(
|
| 114 |
+
fs=None, path="snappy", mode=mode.strip("b") + "b", size=999999999, **kwargs
|
| 115 |
+
)
|
| 116 |
+
self.infile = infile
|
| 117 |
+
if "r" in mode:
|
| 118 |
+
self.codec = snappy.StreamDecompressor()
|
| 119 |
+
else:
|
| 120 |
+
self.codec = snappy.StreamCompressor()
|
| 121 |
+
|
| 122 |
+
def _upload_chunk(self, final=False):
|
| 123 |
+
self.buffer.seek(0)
|
| 124 |
+
out = self.codec.add_chunk(self.buffer.read())
|
| 125 |
+
self.infile.write(out)
|
| 126 |
+
return True
|
| 127 |
+
|
| 128 |
+
def seek(self, loc, whence=0):
|
| 129 |
+
raise NotImplementedError("SnappyFile is not seekable")
|
| 130 |
+
|
| 131 |
+
def seekable(self):
|
| 132 |
+
return False
|
| 133 |
+
|
| 134 |
+
def _fetch_range(self, start, end):
|
| 135 |
+
"""Get the specified set of bytes from remote"""
|
| 136 |
+
data = self.infile.read(end - start)
|
| 137 |
+
return self.codec.decompress(data)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
try:
|
| 141 |
+
import snappy
|
| 142 |
+
|
| 143 |
+
snappy.compress(b"")
|
| 144 |
+
# Snappy may use the .sz file extension, but this is not part of the
|
| 145 |
+
# standard implementation.
|
| 146 |
+
register_compression("snappy", SnappyFile, [])
|
| 147 |
+
|
| 148 |
+
except (ImportError, NameError, AttributeError):
|
| 149 |
+
pass
|
| 150 |
+
|
| 151 |
+
try:
|
| 152 |
+
import lz4.frame
|
| 153 |
+
|
| 154 |
+
register_compression("lz4", lz4.frame.open, "lz4")
|
| 155 |
+
except ImportError:
|
| 156 |
+
pass
|
| 157 |
+
|
| 158 |
+
try:
|
| 159 |
+
if sys.version_info >= (3, 14):
|
| 160 |
+
from compression import zstd
|
| 161 |
+
else:
|
| 162 |
+
from backports import zstd
|
| 163 |
+
|
| 164 |
+
register_compression("zstd", zstd.ZstdFile, "zst")
|
| 165 |
+
except ImportError:
|
| 166 |
+
try:
|
| 167 |
+
import zstandard as zstd
|
| 168 |
+
|
| 169 |
+
def zstandard_file(infile, mode="rb"):
|
| 170 |
+
if "r" in mode:
|
| 171 |
+
cctx = zstd.ZstdDecompressor()
|
| 172 |
+
return cctx.stream_reader(infile)
|
| 173 |
+
else:
|
| 174 |
+
cctx = zstd.ZstdCompressor(level=10)
|
| 175 |
+
return cctx.stream_writer(infile)
|
| 176 |
+
|
| 177 |
+
register_compression("zstd", zstandard_file, "zst")
|
| 178 |
+
except ImportError:
|
| 179 |
+
pass
|
| 180 |
+
pass
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def available_compressions():
|
| 184 |
+
"""Return a list of the implemented compressions."""
|
| 185 |
+
return list(compr)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/config.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import configparser
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import warnings
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
conf: dict[str, dict[str, Any]] = {}
|
| 10 |
+
default_conf_dir = os.path.join(os.path.expanduser("~"), ".config/fsspec")
|
| 11 |
+
conf_dir = os.environ.get("FSSPEC_CONFIG_DIR", default_conf_dir)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def set_conf_env(conf_dict, envdict=os.environ):
|
| 15 |
+
"""Set config values from environment variables
|
| 16 |
+
|
| 17 |
+
Looks for variables of the form ``FSSPEC_<protocol>`` and
|
| 18 |
+
``FSSPEC_<protocol>_<kwarg>``. For ``FSSPEC_<protocol>`` the value is parsed
|
| 19 |
+
as a json dictionary and used to ``update`` the config of the
|
| 20 |
+
corresponding protocol. For ``FSSPEC_<protocol>_<kwarg>`` there is no
|
| 21 |
+
attempt to convert the string value, but the kwarg keys will be lower-cased.
|
| 22 |
+
|
| 23 |
+
The ``FSSPEC_<protocol>_<kwarg>`` variables are applied after the
|
| 24 |
+
``FSSPEC_<protocol>`` ones.
|
| 25 |
+
|
| 26 |
+
Parameters
|
| 27 |
+
----------
|
| 28 |
+
conf_dict : dict(str, dict)
|
| 29 |
+
This dict will be mutated
|
| 30 |
+
envdict : dict-like(str, str)
|
| 31 |
+
Source for the values - usually the real environment
|
| 32 |
+
"""
|
| 33 |
+
envdict = dict(envdict)
|
| 34 |
+
kwarg_keys = []
|
| 35 |
+
for key in envdict:
|
| 36 |
+
if key.startswith("FSSPEC_") and len(key) > 7 and key[7] != "_":
|
| 37 |
+
try:
|
| 38 |
+
value = json.loads(envdict[key])
|
| 39 |
+
envdict[key] = value
|
| 40 |
+
except json.decoder.JSONDecodeError:
|
| 41 |
+
value = envdict[key]
|
| 42 |
+
if key.count("_") > 1:
|
| 43 |
+
kwarg_keys.append(key)
|
| 44 |
+
continue
|
| 45 |
+
else:
|
| 46 |
+
if isinstance(value, dict):
|
| 47 |
+
_, proto = key.split("_", 1)
|
| 48 |
+
conf_dict.setdefault(proto.lower(), {}).update(value)
|
| 49 |
+
else:
|
| 50 |
+
warnings.warn(
|
| 51 |
+
f"Ignoring environment variable {key} due to not being a dict:"
|
| 52 |
+
f" {type(value)}"
|
| 53 |
+
)
|
| 54 |
+
elif key.startswith("FSSPEC"):
|
| 55 |
+
warnings.warn(
|
| 56 |
+
f"Ignoring environment variable {key} due to having an unexpected name"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
for key in kwarg_keys:
|
| 60 |
+
_, proto, kwarg = key.split("_", 2)
|
| 61 |
+
conf_dict.setdefault(proto.lower(), {})[kwarg.lower()] = envdict[key]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def set_conf_files(cdir, conf_dict):
|
| 65 |
+
"""Set config values from files
|
| 66 |
+
|
| 67 |
+
Scans for INI and JSON files in the given dictionary, and uses their
|
| 68 |
+
contents to set the config. In case of repeated values, later values
|
| 69 |
+
win.
|
| 70 |
+
|
| 71 |
+
In the case of INI files, all values are strings, and these will not
|
| 72 |
+
be converted.
|
| 73 |
+
|
| 74 |
+
Parameters
|
| 75 |
+
----------
|
| 76 |
+
cdir : str
|
| 77 |
+
Directory to search
|
| 78 |
+
conf_dict : dict(str, dict)
|
| 79 |
+
This dict will be mutated
|
| 80 |
+
"""
|
| 81 |
+
if not os.path.isdir(cdir):
|
| 82 |
+
return
|
| 83 |
+
allfiles = sorted(os.listdir(cdir))
|
| 84 |
+
for fn in allfiles:
|
| 85 |
+
if fn.endswith(".ini"):
|
| 86 |
+
ini = configparser.ConfigParser()
|
| 87 |
+
ini.read(os.path.join(cdir, fn))
|
| 88 |
+
for key in ini:
|
| 89 |
+
if key == "DEFAULT":
|
| 90 |
+
continue
|
| 91 |
+
conf_dict.setdefault(key, {}).update(dict(ini[key]))
|
| 92 |
+
if fn.endswith(".json"):
|
| 93 |
+
with open(os.path.join(cdir, fn)) as f:
|
| 94 |
+
js = json.load(f)
|
| 95 |
+
for key in js:
|
| 96 |
+
conf_dict.setdefault(key, {}).update(dict(js[key]))
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def apply_config(cls, kwargs, conf_dict=None):
|
| 100 |
+
"""Supply default values for kwargs when instantiating class
|
| 101 |
+
|
| 102 |
+
Augments the passed kwargs, by finding entries in the config dict
|
| 103 |
+
which match the classes ``.protocol`` attribute (one or more str)
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
cls : file system implementation
|
| 108 |
+
kwargs : dict
|
| 109 |
+
conf_dict : dict of dict
|
| 110 |
+
Typically this is the global configuration
|
| 111 |
+
|
| 112 |
+
Returns
|
| 113 |
+
-------
|
| 114 |
+
dict : the modified set of kwargs
|
| 115 |
+
"""
|
| 116 |
+
if conf_dict is None:
|
| 117 |
+
conf_dict = conf
|
| 118 |
+
protos = cls.protocol if isinstance(cls.protocol, (tuple, list)) else [cls.protocol]
|
| 119 |
+
kw = {}
|
| 120 |
+
for proto in protos:
|
| 121 |
+
# default kwargs from the current state of the config
|
| 122 |
+
if proto in conf_dict:
|
| 123 |
+
kw.update(conf_dict[proto])
|
| 124 |
+
# explicit kwargs always win
|
| 125 |
+
kw.update(**kwargs)
|
| 126 |
+
kwargs = kw
|
| 127 |
+
return kwargs
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
set_conf_files(conf_dir, conf)
|
| 131 |
+
set_conf_env(conf)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/conftest.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
import time
|
| 6 |
+
from collections import deque
|
| 7 |
+
from collections.abc import Generator, Sequence
|
| 8 |
+
|
| 9 |
+
import pytest
|
| 10 |
+
|
| 11 |
+
import fsspec
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.fixture()
|
| 15 |
+
def m():
|
| 16 |
+
"""
|
| 17 |
+
Fixture providing a memory filesystem.
|
| 18 |
+
"""
|
| 19 |
+
m = fsspec.filesystem("memory")
|
| 20 |
+
m.store.clear()
|
| 21 |
+
m.pseudo_dirs.clear()
|
| 22 |
+
m.pseudo_dirs.append("")
|
| 23 |
+
try:
|
| 24 |
+
yield m
|
| 25 |
+
finally:
|
| 26 |
+
m.store.clear()
|
| 27 |
+
m.pseudo_dirs.clear()
|
| 28 |
+
m.pseudo_dirs.append("")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class InstanceCacheInspector:
|
| 32 |
+
"""
|
| 33 |
+
Helper class to inspect instance caches of filesystem classes in tests.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
def clear(self) -> None:
|
| 37 |
+
"""
|
| 38 |
+
Clear instance caches of all currently imported filesystem classes.
|
| 39 |
+
"""
|
| 40 |
+
classes = deque([fsspec.spec.AbstractFileSystem])
|
| 41 |
+
while classes:
|
| 42 |
+
cls = classes.popleft()
|
| 43 |
+
cls.clear_instance_cache()
|
| 44 |
+
classes.extend(cls.__subclasses__())
|
| 45 |
+
|
| 46 |
+
def gather_counts(self, *, omit_zero: bool = True) -> dict[str, int]:
|
| 47 |
+
"""
|
| 48 |
+
Gather counts of filesystem instances in the instance caches
|
| 49 |
+
of all currently imported filesystem classes.
|
| 50 |
+
|
| 51 |
+
Parameters
|
| 52 |
+
----------
|
| 53 |
+
omit_zero:
|
| 54 |
+
Whether to omit instance types with no cached instances.
|
| 55 |
+
"""
|
| 56 |
+
out: dict[str, int] = {}
|
| 57 |
+
classes = deque([fsspec.spec.AbstractFileSystem])
|
| 58 |
+
while classes:
|
| 59 |
+
cls = classes.popleft()
|
| 60 |
+
count = len(cls._cache) # there is no public interface for the cache
|
| 61 |
+
# note: skip intermediate AbstractFileSystem subclasses
|
| 62 |
+
# if they proxy the protocol attribute via a property.
|
| 63 |
+
if isinstance(cls.protocol, (Sequence, str)):
|
| 64 |
+
key = cls.protocol if isinstance(cls.protocol, str) else cls.protocol[0]
|
| 65 |
+
if count or not omit_zero:
|
| 66 |
+
out[key] = count
|
| 67 |
+
classes.extend(cls.__subclasses__())
|
| 68 |
+
return out
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@pytest.fixture(scope="function", autouse=True)
|
| 72 |
+
def instance_caches() -> Generator[InstanceCacheInspector, None, None]:
|
| 73 |
+
"""
|
| 74 |
+
Fixture to ensure empty filesystem instance caches before and after a test.
|
| 75 |
+
|
| 76 |
+
Used by default for all tests.
|
| 77 |
+
Clears caches of all imported filesystem classes.
|
| 78 |
+
Can be used to write test assertions about instance caches.
|
| 79 |
+
|
| 80 |
+
Usage:
|
| 81 |
+
|
| 82 |
+
def test_something(instance_caches):
|
| 83 |
+
# Test code here
|
| 84 |
+
fsspec.open("file://abc")
|
| 85 |
+
fsspec.open("memory://foo/bar")
|
| 86 |
+
|
| 87 |
+
# Test assertion
|
| 88 |
+
assert instance_caches.gather_counts() == {"file": 1, "memory": 1}
|
| 89 |
+
|
| 90 |
+
Returns
|
| 91 |
+
-------
|
| 92 |
+
instance_caches: An instance cache inspector for clearing and inspecting caches.
|
| 93 |
+
"""
|
| 94 |
+
ic = InstanceCacheInspector()
|
| 95 |
+
|
| 96 |
+
ic.clear()
|
| 97 |
+
try:
|
| 98 |
+
yield ic
|
| 99 |
+
finally:
|
| 100 |
+
ic.clear()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
@pytest.fixture(scope="function")
|
| 104 |
+
def ftp_writable(tmpdir):
|
| 105 |
+
"""
|
| 106 |
+
Fixture providing a writable FTP filesystem.
|
| 107 |
+
"""
|
| 108 |
+
pytest.importorskip("pyftpdlib")
|
| 109 |
+
|
| 110 |
+
d = str(tmpdir)
|
| 111 |
+
with open(os.path.join(d, "out"), "wb") as f:
|
| 112 |
+
f.write(b"hello" * 10000)
|
| 113 |
+
P = subprocess.Popen(
|
| 114 |
+
[sys.executable, "-m", "pyftpdlib", "-d", d, "-u", "user", "-P", "pass", "-w"]
|
| 115 |
+
)
|
| 116 |
+
try:
|
| 117 |
+
time.sleep(1)
|
| 118 |
+
yield "localhost", 2121, "user", "pass"
|
| 119 |
+
finally:
|
| 120 |
+
P.terminate()
|
| 121 |
+
P.wait()
|
| 122 |
+
try:
|
| 123 |
+
shutil.rmtree(tmpdir)
|
| 124 |
+
except Exception:
|
| 125 |
+
pass
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/core.py
ADDED
|
@@ -0,0 +1,760 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import io
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
from glob import has_magic
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
# for backwards compat, we export cache things from here too
|
| 11 |
+
from fsspec.caching import ( # noqa: F401
|
| 12 |
+
BaseCache,
|
| 13 |
+
BlockCache,
|
| 14 |
+
BytesCache,
|
| 15 |
+
MMapCache,
|
| 16 |
+
ReadAheadCache,
|
| 17 |
+
caches,
|
| 18 |
+
)
|
| 19 |
+
from fsspec.compression import compr
|
| 20 |
+
from fsspec.config import conf
|
| 21 |
+
from fsspec.registry import available_protocols, filesystem, get_filesystem_class
|
| 22 |
+
from fsspec.utils import (
|
| 23 |
+
_unstrip_protocol,
|
| 24 |
+
build_name_function,
|
| 25 |
+
infer_compression,
|
| 26 |
+
stringify_path,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
logger = logging.getLogger("fsspec")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class OpenFile:
|
| 33 |
+
"""
|
| 34 |
+
File-like object to be used in a context
|
| 35 |
+
|
| 36 |
+
Can layer (buffered) text-mode and compression over any file-system, which
|
| 37 |
+
are typically binary-only.
|
| 38 |
+
|
| 39 |
+
These instances are safe to serialize, as the low-level file object
|
| 40 |
+
is not created until invoked using ``with``.
|
| 41 |
+
|
| 42 |
+
Parameters
|
| 43 |
+
----------
|
| 44 |
+
fs: FileSystem
|
| 45 |
+
The file system to use for opening the file. Should be a subclass or duck-type
|
| 46 |
+
with ``fsspec.spec.AbstractFileSystem``
|
| 47 |
+
path: str
|
| 48 |
+
Location to open
|
| 49 |
+
mode: str like 'rb', optional
|
| 50 |
+
Mode of the opened file
|
| 51 |
+
compression: str or None, optional
|
| 52 |
+
Compression to apply
|
| 53 |
+
encoding: str or None, optional
|
| 54 |
+
The encoding to use if opened in text mode.
|
| 55 |
+
errors: str or None, optional
|
| 56 |
+
How to handle encoding errors if opened in text mode.
|
| 57 |
+
newline: None or str
|
| 58 |
+
Passed to TextIOWrapper in text mode, how to handle line endings.
|
| 59 |
+
autoopen: bool
|
| 60 |
+
If True, calls open() immediately. Mostly used by pickle
|
| 61 |
+
pos: int
|
| 62 |
+
If given and autoopen is True, seek to this location immediately
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
def __init__(
|
| 66 |
+
self,
|
| 67 |
+
fs,
|
| 68 |
+
path,
|
| 69 |
+
mode="rb",
|
| 70 |
+
compression=None,
|
| 71 |
+
encoding=None,
|
| 72 |
+
errors=None,
|
| 73 |
+
newline=None,
|
| 74 |
+
):
|
| 75 |
+
self.fs = fs
|
| 76 |
+
self.path = path
|
| 77 |
+
self.mode = mode
|
| 78 |
+
self.compression = get_compression(path, compression)
|
| 79 |
+
self.encoding = encoding
|
| 80 |
+
self.errors = errors
|
| 81 |
+
self.newline = newline
|
| 82 |
+
self.fobjects = []
|
| 83 |
+
|
| 84 |
+
def __reduce__(self):
|
| 85 |
+
return (
|
| 86 |
+
OpenFile,
|
| 87 |
+
(
|
| 88 |
+
self.fs,
|
| 89 |
+
self.path,
|
| 90 |
+
self.mode,
|
| 91 |
+
self.compression,
|
| 92 |
+
self.encoding,
|
| 93 |
+
self.errors,
|
| 94 |
+
self.newline,
|
| 95 |
+
),
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
def __repr__(self):
|
| 99 |
+
return f"<OpenFile '{self.path}'>"
|
| 100 |
+
|
| 101 |
+
def __enter__(self):
|
| 102 |
+
mode = self.mode.replace("t", "").replace("b", "") + "b"
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
f = self.fs.open(self.path, mode=mode)
|
| 106 |
+
except FileNotFoundError as e:
|
| 107 |
+
if has_magic(self.path):
|
| 108 |
+
raise FileNotFoundError(
|
| 109 |
+
"%s not found. The URL contains glob characters: you maybe needed\n"
|
| 110 |
+
"to pass expand=True in fsspec.open() or the storage_options of \n"
|
| 111 |
+
"your library. You can also set the config value 'open_expand'\n"
|
| 112 |
+
"before import, or fsspec.core.DEFAULT_EXPAND at runtime, to True.",
|
| 113 |
+
self.path,
|
| 114 |
+
) from e
|
| 115 |
+
raise
|
| 116 |
+
|
| 117 |
+
self.fobjects = [f]
|
| 118 |
+
|
| 119 |
+
if self.compression is not None:
|
| 120 |
+
compress = compr[self.compression]
|
| 121 |
+
f = compress(f, mode=mode[0])
|
| 122 |
+
self.fobjects.append(f)
|
| 123 |
+
|
| 124 |
+
if "b" not in self.mode:
|
| 125 |
+
# assume, for example, that 'r' is equivalent to 'rt' as in builtin
|
| 126 |
+
f = PickleableTextIOWrapper(
|
| 127 |
+
f, encoding=self.encoding, errors=self.errors, newline=self.newline
|
| 128 |
+
)
|
| 129 |
+
self.fobjects.append(f)
|
| 130 |
+
|
| 131 |
+
return self.fobjects[-1]
|
| 132 |
+
|
| 133 |
+
def __exit__(self, *args):
|
| 134 |
+
self.close()
|
| 135 |
+
|
| 136 |
+
@property
|
| 137 |
+
def full_name(self):
|
| 138 |
+
return _unstrip_protocol(self.path, self.fs)
|
| 139 |
+
|
| 140 |
+
def open(self):
|
| 141 |
+
"""Materialise this as a real open file without context
|
| 142 |
+
|
| 143 |
+
The OpenFile object should be explicitly closed to avoid enclosed file
|
| 144 |
+
instances persisting. You must, therefore, keep a reference to the OpenFile
|
| 145 |
+
during the life of the file-like it generates.
|
| 146 |
+
"""
|
| 147 |
+
return self.__enter__()
|
| 148 |
+
|
| 149 |
+
def close(self):
|
| 150 |
+
"""Close all encapsulated file objects"""
|
| 151 |
+
for f in reversed(self.fobjects):
|
| 152 |
+
if "r" not in self.mode and not f.closed:
|
| 153 |
+
f.flush()
|
| 154 |
+
f.close()
|
| 155 |
+
self.fobjects.clear()
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class OpenFiles(list):
|
| 159 |
+
"""List of OpenFile instances
|
| 160 |
+
|
| 161 |
+
Can be used in a single context, which opens and closes all of the
|
| 162 |
+
contained files. Normal list access to get the elements works as
|
| 163 |
+
normal.
|
| 164 |
+
|
| 165 |
+
A special case is made for caching filesystems - the files will
|
| 166 |
+
be down/uploaded together at the start or end of the context, and
|
| 167 |
+
this may happen concurrently, if the target filesystem supports it.
|
| 168 |
+
"""
|
| 169 |
+
|
| 170 |
+
def __init__(self, *args, mode="rb", fs=None):
|
| 171 |
+
self.mode = mode
|
| 172 |
+
self.fs = fs
|
| 173 |
+
self.files = []
|
| 174 |
+
super().__init__(*args)
|
| 175 |
+
|
| 176 |
+
def __enter__(self):
|
| 177 |
+
if self.fs is None:
|
| 178 |
+
raise ValueError("Context has already been used")
|
| 179 |
+
|
| 180 |
+
fs = self.fs
|
| 181 |
+
while True:
|
| 182 |
+
if hasattr(fs, "open_many"):
|
| 183 |
+
# check for concurrent cache download; or set up for upload
|
| 184 |
+
self.files = fs.open_many(self)
|
| 185 |
+
return self.files
|
| 186 |
+
if hasattr(fs, "fs") and fs.fs is not None:
|
| 187 |
+
fs = fs.fs
|
| 188 |
+
else:
|
| 189 |
+
break
|
| 190 |
+
return [s.__enter__() for s in self]
|
| 191 |
+
|
| 192 |
+
def __exit__(self, *args):
|
| 193 |
+
fs = self.fs
|
| 194 |
+
[s.__exit__(*args) for s in self]
|
| 195 |
+
if "r" not in self.mode:
|
| 196 |
+
while True:
|
| 197 |
+
if hasattr(fs, "open_many"):
|
| 198 |
+
# check for concurrent cache upload
|
| 199 |
+
fs.commit_many(self.files)
|
| 200 |
+
return
|
| 201 |
+
if hasattr(fs, "fs") and fs.fs is not None:
|
| 202 |
+
fs = fs.fs
|
| 203 |
+
else:
|
| 204 |
+
break
|
| 205 |
+
|
| 206 |
+
def __getitem__(self, item):
|
| 207 |
+
out = super().__getitem__(item)
|
| 208 |
+
if isinstance(item, slice):
|
| 209 |
+
return OpenFiles(out, mode=self.mode, fs=self.fs)
|
| 210 |
+
return out
|
| 211 |
+
|
| 212 |
+
def __repr__(self):
|
| 213 |
+
return f"<List of {len(self)} OpenFile instances>"
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def open_files(
|
| 217 |
+
urlpath,
|
| 218 |
+
mode="rb",
|
| 219 |
+
compression=None,
|
| 220 |
+
encoding="utf8",
|
| 221 |
+
errors=None,
|
| 222 |
+
name_function=None,
|
| 223 |
+
num=1,
|
| 224 |
+
protocol=None,
|
| 225 |
+
newline=None,
|
| 226 |
+
auto_mkdir=True,
|
| 227 |
+
expand=True,
|
| 228 |
+
**kwargs,
|
| 229 |
+
):
|
| 230 |
+
"""Given a path or paths, return a list of ``OpenFile`` objects.
|
| 231 |
+
|
| 232 |
+
For writing, a str path must contain the "*" character, which will be filled
|
| 233 |
+
in by increasing numbers, e.g., "part*" -> "part1", "part2" if num=2.
|
| 234 |
+
|
| 235 |
+
For either reading or writing, can instead provide explicit list of paths.
|
| 236 |
+
|
| 237 |
+
Parameters
|
| 238 |
+
----------
|
| 239 |
+
urlpath: string or list
|
| 240 |
+
Absolute or relative filepath(s). Prefix with a protocol like ``s3://``
|
| 241 |
+
to read from alternative filesystems. To read from multiple files you
|
| 242 |
+
can pass a globstring or a list of paths, with the caveat that they
|
| 243 |
+
must all have the same protocol.
|
| 244 |
+
mode: 'rb', 'wt', etc.
|
| 245 |
+
compression: string or None
|
| 246 |
+
If given, open file using compression codec. Can either be a compression
|
| 247 |
+
name (a key in ``fsspec.compression.compr``) or "infer" to guess the
|
| 248 |
+
compression from the filename suffix.
|
| 249 |
+
encoding: str
|
| 250 |
+
For text mode only
|
| 251 |
+
errors: None or str
|
| 252 |
+
Passed to TextIOWrapper in text mode
|
| 253 |
+
name_function: function or None
|
| 254 |
+
if opening a set of files for writing, those files do not yet exist,
|
| 255 |
+
so we need to generate their names by formatting the urlpath for
|
| 256 |
+
each sequence number
|
| 257 |
+
num: int [1]
|
| 258 |
+
if writing mode, number of files we expect to create (passed to
|
| 259 |
+
name+function)
|
| 260 |
+
protocol: str or None
|
| 261 |
+
If given, overrides the protocol found in the URL.
|
| 262 |
+
newline: bytes or None
|
| 263 |
+
Used for line terminator in text mode. If None, uses system default;
|
| 264 |
+
if blank, uses no translation.
|
| 265 |
+
auto_mkdir: bool (True)
|
| 266 |
+
If in write mode, this will ensure the target directory exists before
|
| 267 |
+
writing, by calling ``fs.mkdirs(exist_ok=True)``.
|
| 268 |
+
expand: bool
|
| 269 |
+
**kwargs: dict
|
| 270 |
+
Extra options that make sense to a particular storage connection, e.g.
|
| 271 |
+
host, port, username, password, etc.
|
| 272 |
+
|
| 273 |
+
Examples
|
| 274 |
+
--------
|
| 275 |
+
>>> files = open_files('2015-*-*.csv') # doctest: +SKIP
|
| 276 |
+
>>> files = open_files(
|
| 277 |
+
... 's3://bucket/2015-*-*.csv.gz', compression='gzip'
|
| 278 |
+
... ) # doctest: +SKIP
|
| 279 |
+
|
| 280 |
+
Returns
|
| 281 |
+
-------
|
| 282 |
+
An ``OpenFiles`` instance, which is a list of ``OpenFile`` objects that can
|
| 283 |
+
be used as a single context
|
| 284 |
+
|
| 285 |
+
Notes
|
| 286 |
+
-----
|
| 287 |
+
For a full list of the available protocols and the implementations that
|
| 288 |
+
they map across to see the latest online documentation:
|
| 289 |
+
|
| 290 |
+
- For implementations built into ``fsspec`` see
|
| 291 |
+
https://filesystem-spec.readthedocs.io/en/latest/api.html#built-in-implementations
|
| 292 |
+
- For implementations in separate packages see
|
| 293 |
+
https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations
|
| 294 |
+
"""
|
| 295 |
+
fs, fs_token, paths = get_fs_token_paths(
|
| 296 |
+
urlpath,
|
| 297 |
+
mode,
|
| 298 |
+
num=num,
|
| 299 |
+
name_function=name_function,
|
| 300 |
+
storage_options=kwargs,
|
| 301 |
+
protocol=protocol,
|
| 302 |
+
expand=expand,
|
| 303 |
+
)
|
| 304 |
+
if fs.protocol == "file":
|
| 305 |
+
fs.auto_mkdir = auto_mkdir
|
| 306 |
+
elif "r" not in mode and auto_mkdir:
|
| 307 |
+
parents = {fs._parent(path) for path in paths}
|
| 308 |
+
for parent in parents:
|
| 309 |
+
try:
|
| 310 |
+
fs.makedirs(parent, exist_ok=True)
|
| 311 |
+
except PermissionError:
|
| 312 |
+
pass
|
| 313 |
+
return OpenFiles(
|
| 314 |
+
[
|
| 315 |
+
OpenFile(
|
| 316 |
+
fs,
|
| 317 |
+
path,
|
| 318 |
+
mode=mode,
|
| 319 |
+
compression=compression,
|
| 320 |
+
encoding=encoding,
|
| 321 |
+
errors=errors,
|
| 322 |
+
newline=newline,
|
| 323 |
+
)
|
| 324 |
+
for path in paths
|
| 325 |
+
],
|
| 326 |
+
mode=mode,
|
| 327 |
+
fs=fs,
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def _un_chain(path, kwargs):
|
| 332 |
+
# Avoid a circular import
|
| 333 |
+
from fsspec.implementations.chained import ChainedFileSystem
|
| 334 |
+
|
| 335 |
+
if "::" in path:
|
| 336 |
+
x = re.compile(".*[^a-z]+.*") # test for non protocol-like single word
|
| 337 |
+
known_protocols = set(available_protocols())
|
| 338 |
+
bits = []
|
| 339 |
+
|
| 340 |
+
# split on '::', then ensure each bit has a protocol
|
| 341 |
+
for p in path.split("::"):
|
| 342 |
+
if p in known_protocols:
|
| 343 |
+
bits.append(p + "://")
|
| 344 |
+
elif "://" in p or x.match(p):
|
| 345 |
+
bits.append(p)
|
| 346 |
+
else:
|
| 347 |
+
bits.append(p + "://")
|
| 348 |
+
else:
|
| 349 |
+
bits = [path]
|
| 350 |
+
|
| 351 |
+
# [[url, protocol, kwargs], ...]
|
| 352 |
+
out = []
|
| 353 |
+
previous_bit = None
|
| 354 |
+
kwargs = kwargs.copy()
|
| 355 |
+
|
| 356 |
+
for bit in reversed(bits):
|
| 357 |
+
protocol = kwargs.pop("protocol", None) or split_protocol(bit)[0] or "file"
|
| 358 |
+
cls = get_filesystem_class(protocol)
|
| 359 |
+
extra_kwargs = cls._get_kwargs_from_urls(bit)
|
| 360 |
+
kws = kwargs.pop(protocol, {})
|
| 361 |
+
|
| 362 |
+
if bit is bits[0]:
|
| 363 |
+
kws.update(kwargs)
|
| 364 |
+
|
| 365 |
+
kw = dict(
|
| 366 |
+
**{k: v for k, v in extra_kwargs.items() if k not in kws or v != kws[k]},
|
| 367 |
+
**kws,
|
| 368 |
+
)
|
| 369 |
+
bit = cls._strip_protocol(bit)
|
| 370 |
+
|
| 371 |
+
if (
|
| 372 |
+
"target_protocol" not in kw
|
| 373 |
+
and issubclass(cls, ChainedFileSystem)
|
| 374 |
+
and not bit
|
| 375 |
+
):
|
| 376 |
+
# replace bit if we are chaining and no path given
|
| 377 |
+
bit = previous_bit
|
| 378 |
+
|
| 379 |
+
out.append((bit, protocol, kw))
|
| 380 |
+
previous_bit = bit
|
| 381 |
+
|
| 382 |
+
out.reverse()
|
| 383 |
+
return out
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def url_to_fs(url, **kwargs):
|
| 387 |
+
"""
|
| 388 |
+
Turn fully-qualified and potentially chained URL into filesystem instance
|
| 389 |
+
|
| 390 |
+
Parameters
|
| 391 |
+
----------
|
| 392 |
+
url : str
|
| 393 |
+
The fsspec-compatible URL
|
| 394 |
+
**kwargs: dict
|
| 395 |
+
Extra options that make sense to a particular storage connection, e.g.
|
| 396 |
+
host, port, username, password, etc.
|
| 397 |
+
|
| 398 |
+
Returns
|
| 399 |
+
-------
|
| 400 |
+
filesystem : FileSystem
|
| 401 |
+
The new filesystem discovered from ``url`` and created with
|
| 402 |
+
``**kwargs``.
|
| 403 |
+
urlpath : str
|
| 404 |
+
The file-systems-specific URL for ``url``.
|
| 405 |
+
"""
|
| 406 |
+
url = stringify_path(url)
|
| 407 |
+
# non-FS arguments that appear in fsspec.open()
|
| 408 |
+
# inspect could keep this in sync with open()'s signature
|
| 409 |
+
known_kwargs = {
|
| 410 |
+
"compression",
|
| 411 |
+
"encoding",
|
| 412 |
+
"errors",
|
| 413 |
+
"expand",
|
| 414 |
+
"mode",
|
| 415 |
+
"name_function",
|
| 416 |
+
"newline",
|
| 417 |
+
"num",
|
| 418 |
+
}
|
| 419 |
+
kwargs = {k: v for k, v in kwargs.items() if k not in known_kwargs}
|
| 420 |
+
chain = _un_chain(url, kwargs)
|
| 421 |
+
inkwargs = {}
|
| 422 |
+
# Reverse iterate the chain, creating a nested target_* structure
|
| 423 |
+
for i, ch in enumerate(reversed(chain)):
|
| 424 |
+
urls, protocol, kw = ch
|
| 425 |
+
if i == len(chain) - 1:
|
| 426 |
+
inkwargs = dict(**kw, **inkwargs)
|
| 427 |
+
continue
|
| 428 |
+
inkwargs["target_options"] = dict(**kw, **inkwargs)
|
| 429 |
+
inkwargs["target_protocol"] = protocol
|
| 430 |
+
inkwargs["fo"] = urls
|
| 431 |
+
urlpath, protocol, _ = chain[0]
|
| 432 |
+
fs = filesystem(protocol, **inkwargs)
|
| 433 |
+
return fs, urlpath
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
DEFAULT_EXPAND = conf.get("open_expand", False)
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
def open(
|
| 440 |
+
urlpath,
|
| 441 |
+
mode="rb",
|
| 442 |
+
compression=None,
|
| 443 |
+
encoding="utf8",
|
| 444 |
+
errors=None,
|
| 445 |
+
protocol=None,
|
| 446 |
+
newline=None,
|
| 447 |
+
expand=None,
|
| 448 |
+
**kwargs,
|
| 449 |
+
):
|
| 450 |
+
"""Given a path or paths, return one ``OpenFile`` object.
|
| 451 |
+
|
| 452 |
+
Parameters
|
| 453 |
+
----------
|
| 454 |
+
urlpath: string or list
|
| 455 |
+
Absolute or relative filepath. Prefix with a protocol like ``s3://``
|
| 456 |
+
to read from alternative filesystems. Should not include glob
|
| 457 |
+
character(s).
|
| 458 |
+
mode: 'rb', 'wt', etc.
|
| 459 |
+
compression: string or None
|
| 460 |
+
If given, open file using compression codec. Can either be a compression
|
| 461 |
+
name (a key in ``fsspec.compression.compr``) or "infer" to guess the
|
| 462 |
+
compression from the filename suffix.
|
| 463 |
+
encoding: str
|
| 464 |
+
For text mode only
|
| 465 |
+
errors: None or str
|
| 466 |
+
Passed to TextIOWrapper in text mode
|
| 467 |
+
protocol: str or None
|
| 468 |
+
If given, overrides the protocol found in the URL.
|
| 469 |
+
newline: bytes or None
|
| 470 |
+
Used for line terminator in text mode. If None, uses system default;
|
| 471 |
+
if blank, uses no translation.
|
| 472 |
+
expand: bool or None
|
| 473 |
+
Whether to regard file paths containing special glob characters as needing
|
| 474 |
+
expansion (finding the first match) or absolute. Setting False allows using
|
| 475 |
+
paths which do embed such characters. If None (default), this argument
|
| 476 |
+
takes its value from the DEFAULT_EXPAND module variable, which takes
|
| 477 |
+
its initial value from the "open_expand" config value at startup, which will
|
| 478 |
+
be False if not set.
|
| 479 |
+
**kwargs: dict
|
| 480 |
+
Extra options that make sense to a particular storage connection, e.g.
|
| 481 |
+
host, port, username, password, etc.
|
| 482 |
+
|
| 483 |
+
Examples
|
| 484 |
+
--------
|
| 485 |
+
>>> openfile = open('2015-01-01.csv') # doctest: +SKIP
|
| 486 |
+
>>> openfile = open(
|
| 487 |
+
... 's3://bucket/2015-01-01.csv.gz', compression='gzip'
|
| 488 |
+
... ) # doctest: +SKIP
|
| 489 |
+
>>> with openfile as f:
|
| 490 |
+
... df = pd.read_csv(f) # doctest: +SKIP
|
| 491 |
+
...
|
| 492 |
+
|
| 493 |
+
Returns
|
| 494 |
+
-------
|
| 495 |
+
``OpenFile`` object.
|
| 496 |
+
|
| 497 |
+
Notes
|
| 498 |
+
-----
|
| 499 |
+
For a full list of the available protocols and the implementations that
|
| 500 |
+
they map across to see the latest online documentation:
|
| 501 |
+
|
| 502 |
+
- For implementations built into ``fsspec`` see
|
| 503 |
+
https://filesystem-spec.readthedocs.io/en/latest/api.html#built-in-implementations
|
| 504 |
+
- For implementations in separate packages see
|
| 505 |
+
https://filesystem-spec.readthedocs.io/en/latest/api.html#other-known-implementations
|
| 506 |
+
"""
|
| 507 |
+
expand = DEFAULT_EXPAND if expand is None else expand
|
| 508 |
+
out = open_files(
|
| 509 |
+
urlpath=[urlpath],
|
| 510 |
+
mode=mode,
|
| 511 |
+
compression=compression,
|
| 512 |
+
encoding=encoding,
|
| 513 |
+
errors=errors,
|
| 514 |
+
protocol=protocol,
|
| 515 |
+
newline=newline,
|
| 516 |
+
expand=expand,
|
| 517 |
+
**kwargs,
|
| 518 |
+
)
|
| 519 |
+
if not out:
|
| 520 |
+
raise FileNotFoundError(urlpath)
|
| 521 |
+
return out[0]
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
def open_local(
|
| 525 |
+
url: str | list[str] | Path | list[Path],
|
| 526 |
+
mode: str = "rb",
|
| 527 |
+
**storage_options: dict,
|
| 528 |
+
) -> str | list[str]:
|
| 529 |
+
"""Open file(s) which can be resolved to local
|
| 530 |
+
|
| 531 |
+
For files which either are local, or get downloaded upon open
|
| 532 |
+
(e.g., by file caching)
|
| 533 |
+
|
| 534 |
+
Parameters
|
| 535 |
+
----------
|
| 536 |
+
url: str or list(str)
|
| 537 |
+
mode: str
|
| 538 |
+
Must be read mode
|
| 539 |
+
storage_options:
|
| 540 |
+
passed on to FS for or used by open_files (e.g., compression)
|
| 541 |
+
"""
|
| 542 |
+
if "r" not in mode:
|
| 543 |
+
raise ValueError("Can only ensure local files when reading")
|
| 544 |
+
of = open_files(url, mode=mode, **storage_options)
|
| 545 |
+
if not getattr(of[0].fs, "local_file", False):
|
| 546 |
+
raise ValueError(
|
| 547 |
+
"open_local can only be used on a filesystem which"
|
| 548 |
+
" has attribute local_file=True"
|
| 549 |
+
)
|
| 550 |
+
with of as files:
|
| 551 |
+
paths = [f.name for f in files]
|
| 552 |
+
if (isinstance(url, str) and not has_magic(url)) or isinstance(url, Path):
|
| 553 |
+
return paths[0]
|
| 554 |
+
return paths
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
def get_compression(urlpath, compression):
|
| 558 |
+
if compression == "infer":
|
| 559 |
+
compression = infer_compression(urlpath)
|
| 560 |
+
if compression is not None and compression not in compr:
|
| 561 |
+
raise ValueError(f"Compression type {compression} not supported")
|
| 562 |
+
return compression
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def split_protocol(urlpath):
|
| 566 |
+
"""Return protocol, path pair"""
|
| 567 |
+
urlpath = stringify_path(urlpath)
|
| 568 |
+
if "://" in urlpath:
|
| 569 |
+
protocol, path = urlpath.split("://", 1)
|
| 570 |
+
if len(protocol) > 1:
|
| 571 |
+
# excludes Windows paths
|
| 572 |
+
return protocol, path
|
| 573 |
+
if urlpath.startswith("data:"):
|
| 574 |
+
return urlpath.split(":", 1)
|
| 575 |
+
return None, urlpath
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
def strip_protocol(urlpath):
|
| 579 |
+
"""Return only path part of full URL, according to appropriate backend"""
|
| 580 |
+
protocol, _ = split_protocol(urlpath)
|
| 581 |
+
cls = get_filesystem_class(protocol)
|
| 582 |
+
return cls._strip_protocol(urlpath)
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
def expand_paths_if_needed(paths, mode, num, fs, name_function):
|
| 586 |
+
"""Expand paths if they have a ``*`` in them (write mode) or any of ``*?[]``
|
| 587 |
+
in them (read mode).
|
| 588 |
+
|
| 589 |
+
:param paths: list of paths
|
| 590 |
+
mode: str
|
| 591 |
+
Mode in which to open files.
|
| 592 |
+
num: int
|
| 593 |
+
If opening in writing mode, number of files we expect to create.
|
| 594 |
+
fs: filesystem object
|
| 595 |
+
name_function: callable
|
| 596 |
+
If opening in writing mode, this callable is used to generate path
|
| 597 |
+
names. Names are generated for each partition by
|
| 598 |
+
``urlpath.replace('*', name_function(partition_index))``.
|
| 599 |
+
:return: list of paths
|
| 600 |
+
"""
|
| 601 |
+
expanded_paths = []
|
| 602 |
+
paths = list(paths)
|
| 603 |
+
|
| 604 |
+
if "w" in mode: # read mode
|
| 605 |
+
if sum(1 for p in paths if "*" in p) > 1:
|
| 606 |
+
raise ValueError(
|
| 607 |
+
"When writing data, only one filename mask can be specified."
|
| 608 |
+
)
|
| 609 |
+
num = max(num, len(paths))
|
| 610 |
+
|
| 611 |
+
for curr_path in paths:
|
| 612 |
+
if "*" in curr_path:
|
| 613 |
+
# expand using name_function
|
| 614 |
+
expanded_paths.extend(_expand_paths(curr_path, name_function, num))
|
| 615 |
+
else:
|
| 616 |
+
expanded_paths.append(curr_path)
|
| 617 |
+
# if we generated more paths that asked for, trim the list
|
| 618 |
+
if len(expanded_paths) > num:
|
| 619 |
+
expanded_paths = expanded_paths[:num]
|
| 620 |
+
|
| 621 |
+
else: # read mode
|
| 622 |
+
for curr_path in paths:
|
| 623 |
+
if has_magic(curr_path):
|
| 624 |
+
# expand using glob
|
| 625 |
+
expanded_paths.extend(fs.glob(curr_path))
|
| 626 |
+
else:
|
| 627 |
+
expanded_paths.append(curr_path)
|
| 628 |
+
|
| 629 |
+
return expanded_paths
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
def get_fs_token_paths(
|
| 633 |
+
urlpath,
|
| 634 |
+
mode="rb",
|
| 635 |
+
num=1,
|
| 636 |
+
name_function=None,
|
| 637 |
+
storage_options=None,
|
| 638 |
+
protocol=None,
|
| 639 |
+
expand=True,
|
| 640 |
+
):
|
| 641 |
+
"""Filesystem, deterministic token, and paths from a urlpath and options.
|
| 642 |
+
|
| 643 |
+
Parameters
|
| 644 |
+
----------
|
| 645 |
+
urlpath: string or iterable
|
| 646 |
+
Absolute or relative filepath, URL (may include protocols like
|
| 647 |
+
``s3://``), or globstring pointing to data.
|
| 648 |
+
mode: str, optional
|
| 649 |
+
Mode in which to open files.
|
| 650 |
+
num: int, optional
|
| 651 |
+
If opening in writing mode, number of files we expect to create.
|
| 652 |
+
name_function: callable, optional
|
| 653 |
+
If opening in writing mode, this callable is used to generate path
|
| 654 |
+
names. Names are generated for each partition by
|
| 655 |
+
``urlpath.replace('*', name_function(partition_index))``.
|
| 656 |
+
storage_options: dict, optional
|
| 657 |
+
Additional keywords to pass to the filesystem class.
|
| 658 |
+
protocol: str or None
|
| 659 |
+
To override the protocol specifier in the URL
|
| 660 |
+
expand: bool
|
| 661 |
+
Expand string paths for writing, assuming the path is a directory
|
| 662 |
+
"""
|
| 663 |
+
if isinstance(urlpath, (list, tuple, set)):
|
| 664 |
+
if not urlpath:
|
| 665 |
+
raise ValueError("empty urlpath sequence")
|
| 666 |
+
urlpath0 = stringify_path(next(iter(urlpath)))
|
| 667 |
+
else:
|
| 668 |
+
urlpath0 = stringify_path(urlpath)
|
| 669 |
+
storage_options = storage_options or {}
|
| 670 |
+
if protocol:
|
| 671 |
+
storage_options["protocol"] = protocol
|
| 672 |
+
chain = _un_chain(urlpath0, storage_options or {})
|
| 673 |
+
inkwargs = {}
|
| 674 |
+
# Reverse iterate the chain, creating a nested target_* structure
|
| 675 |
+
for i, ch in enumerate(reversed(chain)):
|
| 676 |
+
urls, nested_protocol, kw = ch
|
| 677 |
+
if i == len(chain) - 1:
|
| 678 |
+
inkwargs = dict(**kw, **inkwargs)
|
| 679 |
+
continue
|
| 680 |
+
inkwargs["target_options"] = dict(**kw, **inkwargs)
|
| 681 |
+
inkwargs["target_protocol"] = nested_protocol
|
| 682 |
+
inkwargs["fo"] = urls
|
| 683 |
+
paths, protocol, _ = chain[0]
|
| 684 |
+
fs = filesystem(protocol, **inkwargs)
|
| 685 |
+
if isinstance(urlpath, (list, tuple, set)):
|
| 686 |
+
pchains = [
|
| 687 |
+
_un_chain(stringify_path(u), storage_options or {})[0] for u in urlpath
|
| 688 |
+
]
|
| 689 |
+
if len({pc[1] for pc in pchains}) > 1:
|
| 690 |
+
raise ValueError("Protocol mismatch getting fs from %s", urlpath)
|
| 691 |
+
paths = [pc[0] for pc in pchains]
|
| 692 |
+
else:
|
| 693 |
+
paths = fs._strip_protocol(paths)
|
| 694 |
+
if isinstance(paths, (list, tuple, set)):
|
| 695 |
+
if expand:
|
| 696 |
+
paths = expand_paths_if_needed(paths, mode, num, fs, name_function)
|
| 697 |
+
elif not isinstance(paths, list):
|
| 698 |
+
paths = list(paths)
|
| 699 |
+
else:
|
| 700 |
+
if ("w" in mode or "x" in mode) and expand:
|
| 701 |
+
paths = _expand_paths(paths, name_function, num)
|
| 702 |
+
elif "*" in paths:
|
| 703 |
+
paths = [f for f in sorted(fs.glob(paths)) if not fs.isdir(f)]
|
| 704 |
+
else:
|
| 705 |
+
paths = [paths]
|
| 706 |
+
|
| 707 |
+
return fs, fs._fs_token, paths
|
| 708 |
+
|
| 709 |
+
|
| 710 |
+
def _expand_paths(path, name_function, num):
|
| 711 |
+
if isinstance(path, str):
|
| 712 |
+
if path.count("*") > 1:
|
| 713 |
+
raise ValueError("Output path spec must contain exactly one '*'.")
|
| 714 |
+
elif "*" not in path:
|
| 715 |
+
path = os.path.join(path, "*.part")
|
| 716 |
+
|
| 717 |
+
if name_function is None:
|
| 718 |
+
name_function = build_name_function(num - 1)
|
| 719 |
+
|
| 720 |
+
paths = [path.replace("*", name_function(i)) for i in range(num)]
|
| 721 |
+
if paths != sorted(paths):
|
| 722 |
+
logger.warning(
|
| 723 |
+
"In order to preserve order between partitions"
|
| 724 |
+
" paths created with ``name_function`` should "
|
| 725 |
+
"sort to partition order"
|
| 726 |
+
)
|
| 727 |
+
elif isinstance(path, (tuple, list)):
|
| 728 |
+
assert len(path) == num
|
| 729 |
+
paths = list(path)
|
| 730 |
+
else:
|
| 731 |
+
raise ValueError(
|
| 732 |
+
"Path should be either\n"
|
| 733 |
+
"1. A list of paths: ['foo.json', 'bar.json', ...]\n"
|
| 734 |
+
"2. A directory: 'foo/\n"
|
| 735 |
+
"3. A path with a '*' in it: 'foo.*.json'"
|
| 736 |
+
)
|
| 737 |
+
return paths
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
class PickleableTextIOWrapper(io.TextIOWrapper):
|
| 741 |
+
"""TextIOWrapper cannot be pickled. This solves it.
|
| 742 |
+
|
| 743 |
+
Requires that ``buffer`` be pickleable, which all instances of
|
| 744 |
+
AbstractBufferedFile are.
|
| 745 |
+
"""
|
| 746 |
+
|
| 747 |
+
def __init__(
|
| 748 |
+
self,
|
| 749 |
+
buffer,
|
| 750 |
+
encoding=None,
|
| 751 |
+
errors=None,
|
| 752 |
+
newline=None,
|
| 753 |
+
line_buffering=False,
|
| 754 |
+
write_through=False,
|
| 755 |
+
):
|
| 756 |
+
self.args = buffer, encoding, errors, newline, line_buffering, write_through
|
| 757 |
+
super().__init__(*self.args)
|
| 758 |
+
|
| 759 |
+
def __reduce__(self):
|
| 760 |
+
return PickleableTextIOWrapper, self.args
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/dircache.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
from collections.abc import MutableMapping
|
| 3 |
+
from functools import lru_cache
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class DirCache(MutableMapping):
|
| 7 |
+
"""
|
| 8 |
+
Caching of directory listings, in a structure like::
|
| 9 |
+
|
| 10 |
+
{"path0": [
|
| 11 |
+
{"name": "path0/file0",
|
| 12 |
+
"size": 123,
|
| 13 |
+
"type": "file",
|
| 14 |
+
...
|
| 15 |
+
},
|
| 16 |
+
{"name": "path0/file1",
|
| 17 |
+
},
|
| 18 |
+
...
|
| 19 |
+
],
|
| 20 |
+
"path1": [...]
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
Parameters to this class control listing expiry or indeed turn
|
| 24 |
+
caching off
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
def __init__(
|
| 28 |
+
self,
|
| 29 |
+
use_listings_cache=True,
|
| 30 |
+
listings_expiry_time=None,
|
| 31 |
+
max_paths=None,
|
| 32 |
+
**kwargs,
|
| 33 |
+
):
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
Parameters
|
| 37 |
+
----------
|
| 38 |
+
use_listings_cache: bool
|
| 39 |
+
If False, this cache never returns items, but always reports KeyError,
|
| 40 |
+
and setting items has no effect
|
| 41 |
+
listings_expiry_time: int or float (optional)
|
| 42 |
+
Time in seconds that a listing is considered valid. If None,
|
| 43 |
+
listings do not expire.
|
| 44 |
+
max_paths: int (optional)
|
| 45 |
+
The number of most recent listings that are considered valid; 'recent'
|
| 46 |
+
refers to when the entry was set.
|
| 47 |
+
"""
|
| 48 |
+
self._cache = {}
|
| 49 |
+
self._times = {}
|
| 50 |
+
if max_paths:
|
| 51 |
+
self._q = lru_cache(max_paths + 1)(lambda key: self._cache.pop(key, None))
|
| 52 |
+
self.use_listings_cache = use_listings_cache
|
| 53 |
+
self.listings_expiry_time = listings_expiry_time
|
| 54 |
+
self.max_paths = max_paths
|
| 55 |
+
|
| 56 |
+
def __getitem__(self, item):
|
| 57 |
+
if self.listings_expiry_time is not None:
|
| 58 |
+
if self._times.get(item, 0) - time.time() < -self.listings_expiry_time:
|
| 59 |
+
del self._cache[item]
|
| 60 |
+
if self.max_paths:
|
| 61 |
+
self._q(item)
|
| 62 |
+
return self._cache[item] # maybe raises KeyError
|
| 63 |
+
|
| 64 |
+
def clear(self):
|
| 65 |
+
self._cache.clear()
|
| 66 |
+
|
| 67 |
+
def __len__(self):
|
| 68 |
+
return len(self._cache)
|
| 69 |
+
|
| 70 |
+
def __contains__(self, item):
|
| 71 |
+
try:
|
| 72 |
+
self[item]
|
| 73 |
+
return True
|
| 74 |
+
except KeyError:
|
| 75 |
+
return False
|
| 76 |
+
|
| 77 |
+
def __setitem__(self, key, value):
|
| 78 |
+
if not self.use_listings_cache:
|
| 79 |
+
return
|
| 80 |
+
if self.max_paths:
|
| 81 |
+
self._q(key)
|
| 82 |
+
self._cache[key] = value
|
| 83 |
+
if self.listings_expiry_time is not None:
|
| 84 |
+
self._times[key] = time.time()
|
| 85 |
+
|
| 86 |
+
def __delitem__(self, key):
|
| 87 |
+
del self._cache[key]
|
| 88 |
+
|
| 89 |
+
def __iter__(self):
|
| 90 |
+
entries = list(self._cache)
|
| 91 |
+
|
| 92 |
+
return (k for k in entries if k in self)
|
| 93 |
+
|
| 94 |
+
def __reduce__(self):
|
| 95 |
+
return (
|
| 96 |
+
DirCache,
|
| 97 |
+
(self.use_listings_cache, self.listings_expiry_time, self.max_paths),
|
| 98 |
+
)
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/exceptions.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
fsspec user-defined exception classes
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class BlocksizeMismatchError(ValueError):
|
| 9 |
+
"""
|
| 10 |
+
Raised when a cached file is opened with a different blocksize than it was
|
| 11 |
+
written with
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class FSTimeoutError(asyncio.TimeoutError):
|
| 16 |
+
"""
|
| 17 |
+
Raised when a fsspec function timed out occurs
|
| 18 |
+
"""
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/fuse.py
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
import stat
|
| 5 |
+
import threading
|
| 6 |
+
import time
|
| 7 |
+
from errno import EIO, ENOENT
|
| 8 |
+
|
| 9 |
+
from fuse import FUSE, FuseOSError, LoggingMixIn, Operations
|
| 10 |
+
|
| 11 |
+
from fsspec import __version__
|
| 12 |
+
from fsspec.core import url_to_fs
|
| 13 |
+
|
| 14 |
+
logger = logging.getLogger("fsspec.fuse")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class FUSEr(Operations):
|
| 18 |
+
def __init__(self, fs, path, ready_file=False):
|
| 19 |
+
self.fs = fs
|
| 20 |
+
self.cache = {}
|
| 21 |
+
self.root = path.rstrip("/") + "/"
|
| 22 |
+
self.counter = 0
|
| 23 |
+
logger.info("Starting FUSE at %s", path)
|
| 24 |
+
self._ready_file = ready_file
|
| 25 |
+
|
| 26 |
+
def getattr(self, path, fh=None):
|
| 27 |
+
logger.debug("getattr %s", path)
|
| 28 |
+
if self._ready_file and path in ["/.fuse_ready", ".fuse_ready"]:
|
| 29 |
+
return {"type": "file", "st_size": 5}
|
| 30 |
+
|
| 31 |
+
path = "".join([self.root, path.lstrip("/")]).rstrip("/")
|
| 32 |
+
try:
|
| 33 |
+
info = self.fs.info(path)
|
| 34 |
+
except FileNotFoundError as exc:
|
| 35 |
+
raise FuseOSError(ENOENT) from exc
|
| 36 |
+
|
| 37 |
+
data = {"st_uid": info.get("uid", 1000), "st_gid": info.get("gid", 1000)}
|
| 38 |
+
perm = info.get("mode", 0o777)
|
| 39 |
+
|
| 40 |
+
if info["type"] != "file":
|
| 41 |
+
data["st_mode"] = stat.S_IFDIR | perm
|
| 42 |
+
data["st_size"] = 0
|
| 43 |
+
data["st_blksize"] = 0
|
| 44 |
+
else:
|
| 45 |
+
data["st_mode"] = stat.S_IFREG | perm
|
| 46 |
+
data["st_size"] = info["size"]
|
| 47 |
+
data["st_blksize"] = 5 * 2**20
|
| 48 |
+
data["st_nlink"] = 1
|
| 49 |
+
data["st_atime"] = info["atime"] if "atime" in info else time.time()
|
| 50 |
+
data["st_ctime"] = info["ctime"] if "ctime" in info else time.time()
|
| 51 |
+
data["st_mtime"] = info["mtime"] if "mtime" in info else time.time()
|
| 52 |
+
return data
|
| 53 |
+
|
| 54 |
+
def readdir(self, path, fh):
|
| 55 |
+
logger.debug("readdir %s", path)
|
| 56 |
+
path = "".join([self.root, path.lstrip("/")])
|
| 57 |
+
files = self.fs.ls(path, False)
|
| 58 |
+
files = [os.path.basename(f.rstrip("/")) for f in files]
|
| 59 |
+
return [".", ".."] + files
|
| 60 |
+
|
| 61 |
+
def mkdir(self, path, mode):
|
| 62 |
+
path = "".join([self.root, path.lstrip("/")])
|
| 63 |
+
self.fs.mkdir(path)
|
| 64 |
+
return 0
|
| 65 |
+
|
| 66 |
+
def rmdir(self, path):
|
| 67 |
+
path = "".join([self.root, path.lstrip("/")])
|
| 68 |
+
self.fs.rmdir(path)
|
| 69 |
+
return 0
|
| 70 |
+
|
| 71 |
+
def read(self, path, size, offset, fh):
|
| 72 |
+
logger.debug("read %s", (path, size, offset))
|
| 73 |
+
if self._ready_file and path in ["/.fuse_ready", ".fuse_ready"]:
|
| 74 |
+
# status indicator
|
| 75 |
+
return b"ready"
|
| 76 |
+
|
| 77 |
+
f = self.cache[fh]
|
| 78 |
+
f.seek(offset)
|
| 79 |
+
out = f.read(size)
|
| 80 |
+
return out
|
| 81 |
+
|
| 82 |
+
def write(self, path, data, offset, fh):
|
| 83 |
+
logger.debug("write %s", (path, offset))
|
| 84 |
+
f = self.cache[fh]
|
| 85 |
+
f.seek(offset)
|
| 86 |
+
f.write(data)
|
| 87 |
+
return len(data)
|
| 88 |
+
|
| 89 |
+
def create(self, path, flags, fi=None):
|
| 90 |
+
logger.debug("create %s", (path, flags))
|
| 91 |
+
fn = "".join([self.root, path.lstrip("/")])
|
| 92 |
+
self.fs.touch(fn) # OS will want to get attributes immediately
|
| 93 |
+
f = self.fs.open(fn, "wb")
|
| 94 |
+
self.cache[self.counter] = f
|
| 95 |
+
self.counter += 1
|
| 96 |
+
return self.counter - 1
|
| 97 |
+
|
| 98 |
+
def open(self, path, flags):
|
| 99 |
+
logger.debug("open %s", (path, flags))
|
| 100 |
+
fn = "".join([self.root, path.lstrip("/")])
|
| 101 |
+
if flags % 2 == 0:
|
| 102 |
+
# read
|
| 103 |
+
mode = "rb"
|
| 104 |
+
else:
|
| 105 |
+
# write/create
|
| 106 |
+
mode = "wb"
|
| 107 |
+
self.cache[self.counter] = self.fs.open(fn, mode)
|
| 108 |
+
self.counter += 1
|
| 109 |
+
return self.counter - 1
|
| 110 |
+
|
| 111 |
+
def truncate(self, path, length, fh=None):
|
| 112 |
+
fn = "".join([self.root, path.lstrip("/")])
|
| 113 |
+
if length != 0:
|
| 114 |
+
raise NotImplementedError
|
| 115 |
+
# maybe should be no-op since open with write sets size to zero anyway
|
| 116 |
+
self.fs.touch(fn)
|
| 117 |
+
|
| 118 |
+
def unlink(self, path):
|
| 119 |
+
fn = "".join([self.root, path.lstrip("/")])
|
| 120 |
+
try:
|
| 121 |
+
self.fs.rm(fn, False)
|
| 122 |
+
except (OSError, FileNotFoundError) as exc:
|
| 123 |
+
raise FuseOSError(EIO) from exc
|
| 124 |
+
|
| 125 |
+
def release(self, path, fh):
|
| 126 |
+
try:
|
| 127 |
+
if fh in self.cache:
|
| 128 |
+
f = self.cache[fh]
|
| 129 |
+
f.close()
|
| 130 |
+
self.cache.pop(fh)
|
| 131 |
+
except Exception as e:
|
| 132 |
+
print(e)
|
| 133 |
+
return 0
|
| 134 |
+
|
| 135 |
+
def chmod(self, path, mode):
|
| 136 |
+
if hasattr(self.fs, "chmod"):
|
| 137 |
+
path = "".join([self.root, path.lstrip("/")])
|
| 138 |
+
return self.fs.chmod(path, mode)
|
| 139 |
+
raise NotImplementedError
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def run(
|
| 143 |
+
fs,
|
| 144 |
+
path,
|
| 145 |
+
mount_point,
|
| 146 |
+
foreground=True,
|
| 147 |
+
threads=False,
|
| 148 |
+
ready_file=False,
|
| 149 |
+
ops_class=FUSEr,
|
| 150 |
+
):
|
| 151 |
+
"""Mount stuff in a local directory
|
| 152 |
+
|
| 153 |
+
This uses fusepy to make it appear as if a given path on an fsspec
|
| 154 |
+
instance is in fact resident within the local file-system.
|
| 155 |
+
|
| 156 |
+
This requires that fusepy by installed, and that FUSE be available on
|
| 157 |
+
the system (typically requiring a package to be installed with
|
| 158 |
+
apt, yum, brew, etc.).
|
| 159 |
+
|
| 160 |
+
Parameters
|
| 161 |
+
----------
|
| 162 |
+
fs: file-system instance
|
| 163 |
+
From one of the compatible implementations
|
| 164 |
+
path: str
|
| 165 |
+
Location on that file-system to regard as the root directory to
|
| 166 |
+
mount. Note that you typically should include the terminating "/"
|
| 167 |
+
character.
|
| 168 |
+
mount_point: str
|
| 169 |
+
An empty directory on the local file-system where the contents of
|
| 170 |
+
the remote path will appear.
|
| 171 |
+
foreground: bool
|
| 172 |
+
Whether or not calling this function will block. Operation will
|
| 173 |
+
typically be more stable if True.
|
| 174 |
+
threads: bool
|
| 175 |
+
Whether or not to create threads when responding to file operations
|
| 176 |
+
within the mounter directory. Operation will typically be more
|
| 177 |
+
stable if False.
|
| 178 |
+
ready_file: bool
|
| 179 |
+
Whether the FUSE process is ready. The ``.fuse_ready`` file will
|
| 180 |
+
exist in the ``mount_point`` directory if True. Debugging purpose.
|
| 181 |
+
ops_class: FUSEr or Subclass of FUSEr
|
| 182 |
+
To override the default behavior of FUSEr. For Example, logging
|
| 183 |
+
to file.
|
| 184 |
+
|
| 185 |
+
"""
|
| 186 |
+
func = lambda: FUSE(
|
| 187 |
+
ops_class(fs, path, ready_file=ready_file),
|
| 188 |
+
mount_point,
|
| 189 |
+
nothreads=not threads,
|
| 190 |
+
foreground=foreground,
|
| 191 |
+
)
|
| 192 |
+
if not foreground:
|
| 193 |
+
th = threading.Thread(target=func)
|
| 194 |
+
th.daemon = True
|
| 195 |
+
th.start()
|
| 196 |
+
return th
|
| 197 |
+
else: # pragma: no cover
|
| 198 |
+
try:
|
| 199 |
+
func()
|
| 200 |
+
except KeyboardInterrupt:
|
| 201 |
+
pass
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def main(args):
|
| 205 |
+
"""Mount filesystem from chained URL to MOUNT_POINT.
|
| 206 |
+
|
| 207 |
+
Examples:
|
| 208 |
+
|
| 209 |
+
python3 -m fsspec.fuse memory /usr/share /tmp/mem
|
| 210 |
+
|
| 211 |
+
python3 -m fsspec.fuse local /tmp/source /tmp/local \\
|
| 212 |
+
-l /tmp/fsspecfuse.log
|
| 213 |
+
|
| 214 |
+
You can also mount chained-URLs and use special settings:
|
| 215 |
+
|
| 216 |
+
python3 -m fsspec.fuse 'filecache::zip::file://data.zip' \\
|
| 217 |
+
/ /tmp/zip \\
|
| 218 |
+
-o 'filecache-cache_storage=/tmp/simplecache'
|
| 219 |
+
|
| 220 |
+
You can specify the type of the setting by using `[int]` or `[bool]`,
|
| 221 |
+
(`true`, `yes`, `1` represents the Boolean value `True`):
|
| 222 |
+
|
| 223 |
+
python3 -m fsspec.fuse 'simplecache::ftp://ftp1.at.proftpd.org' \\
|
| 224 |
+
/historic/packages/RPMS /tmp/ftp \\
|
| 225 |
+
-o 'simplecache-cache_storage=/tmp/simplecache' \\
|
| 226 |
+
-o 'simplecache-check_files=false[bool]' \\
|
| 227 |
+
-o 'ftp-listings_expiry_time=60[int]' \\
|
| 228 |
+
-o 'ftp-username=anonymous' \\
|
| 229 |
+
-o 'ftp-password=xieyanbo'
|
| 230 |
+
"""
|
| 231 |
+
|
| 232 |
+
class RawDescriptionArgumentParser(argparse.ArgumentParser):
|
| 233 |
+
def format_help(self):
|
| 234 |
+
usage = super().format_help()
|
| 235 |
+
parts = usage.split("\n\n")
|
| 236 |
+
parts[1] = self.description.rstrip()
|
| 237 |
+
return "\n\n".join(parts)
|
| 238 |
+
|
| 239 |
+
parser = RawDescriptionArgumentParser(prog="fsspec.fuse", description=main.__doc__)
|
| 240 |
+
parser.add_argument("--version", action="version", version=__version__)
|
| 241 |
+
parser.add_argument("url", type=str, help="fs url")
|
| 242 |
+
parser.add_argument("source_path", type=str, help="source directory in fs")
|
| 243 |
+
parser.add_argument("mount_point", type=str, help="local directory")
|
| 244 |
+
parser.add_argument(
|
| 245 |
+
"-o",
|
| 246 |
+
"--option",
|
| 247 |
+
action="append",
|
| 248 |
+
help="Any options of protocol included in the chained URL",
|
| 249 |
+
)
|
| 250 |
+
parser.add_argument(
|
| 251 |
+
"-l", "--log-file", type=str, help="Logging FUSE debug info (Default: '')"
|
| 252 |
+
)
|
| 253 |
+
parser.add_argument(
|
| 254 |
+
"-f",
|
| 255 |
+
"--foreground",
|
| 256 |
+
action="store_false",
|
| 257 |
+
help="Running in foreground or not (Default: False)",
|
| 258 |
+
)
|
| 259 |
+
parser.add_argument(
|
| 260 |
+
"-t",
|
| 261 |
+
"--threads",
|
| 262 |
+
action="store_false",
|
| 263 |
+
help="Running with threads support (Default: False)",
|
| 264 |
+
)
|
| 265 |
+
parser.add_argument(
|
| 266 |
+
"-r",
|
| 267 |
+
"--ready-file",
|
| 268 |
+
action="store_false",
|
| 269 |
+
help="The `.fuse_ready` file will exist after FUSE is ready. "
|
| 270 |
+
"(Debugging purpose, Default: False)",
|
| 271 |
+
)
|
| 272 |
+
args = parser.parse_args(args)
|
| 273 |
+
|
| 274 |
+
kwargs = {}
|
| 275 |
+
for item in args.option or []:
|
| 276 |
+
key, sep, value = item.partition("=")
|
| 277 |
+
if not sep:
|
| 278 |
+
parser.error(message=f"Wrong option: {item!r}")
|
| 279 |
+
val = value.lower()
|
| 280 |
+
if val.endswith("[int]"):
|
| 281 |
+
value = int(value[: -len("[int]")])
|
| 282 |
+
elif val.endswith("[bool]"):
|
| 283 |
+
value = val[: -len("[bool]")] in ["1", "yes", "true"]
|
| 284 |
+
|
| 285 |
+
if "-" in key:
|
| 286 |
+
fs_name, setting_name = key.split("-", 1)
|
| 287 |
+
if fs_name in kwargs:
|
| 288 |
+
kwargs[fs_name][setting_name] = value
|
| 289 |
+
else:
|
| 290 |
+
kwargs[fs_name] = {setting_name: value}
|
| 291 |
+
else:
|
| 292 |
+
kwargs[key] = value
|
| 293 |
+
|
| 294 |
+
if args.log_file:
|
| 295 |
+
logging.basicConfig(
|
| 296 |
+
level=logging.DEBUG,
|
| 297 |
+
filename=args.log_file,
|
| 298 |
+
format="%(asctime)s %(message)s",
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
class LoggingFUSEr(FUSEr, LoggingMixIn):
|
| 302 |
+
pass
|
| 303 |
+
|
| 304 |
+
fuser = LoggingFUSEr
|
| 305 |
+
else:
|
| 306 |
+
fuser = FUSEr
|
| 307 |
+
|
| 308 |
+
fs, url_path = url_to_fs(args.url, **kwargs)
|
| 309 |
+
logger.debug("Mounting %s to %s", url_path, str(args.mount_point))
|
| 310 |
+
run(
|
| 311 |
+
fs,
|
| 312 |
+
args.source_path,
|
| 313 |
+
args.mount_point,
|
| 314 |
+
foreground=args.foreground,
|
| 315 |
+
threads=args.threads,
|
| 316 |
+
ready_file=args.ready_file,
|
| 317 |
+
ops_class=fuser,
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
if __name__ == "__main__":
|
| 322 |
+
import sys
|
| 323 |
+
|
| 324 |
+
main(sys.argv[1:])
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/generic.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
import uuid
|
| 8 |
+
|
| 9 |
+
from .asyn import AsyncFileSystem, _run_coros_in_chunks, sync_wrapper
|
| 10 |
+
from .callbacks import DEFAULT_CALLBACK
|
| 11 |
+
from .core import filesystem, get_filesystem_class, split_protocol, url_to_fs
|
| 12 |
+
|
| 13 |
+
_generic_fs = {}
|
| 14 |
+
logger = logging.getLogger("fsspec.generic")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def set_generic_fs(protocol, **storage_options):
|
| 18 |
+
"""Populate the dict used for method=="generic" lookups"""
|
| 19 |
+
_generic_fs[protocol] = filesystem(protocol, **storage_options)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _resolve_fs(url, method, protocol=None, storage_options=None):
|
| 23 |
+
"""Pick instance of backend FS"""
|
| 24 |
+
url = url[0] if isinstance(url, (list, tuple)) else url
|
| 25 |
+
protocol = protocol or split_protocol(url)[0]
|
| 26 |
+
storage_options = storage_options or {}
|
| 27 |
+
if method == "default":
|
| 28 |
+
return filesystem(protocol)
|
| 29 |
+
if method == "generic":
|
| 30 |
+
return _generic_fs[protocol]
|
| 31 |
+
if method == "current":
|
| 32 |
+
cls = get_filesystem_class(protocol)
|
| 33 |
+
return cls.current()
|
| 34 |
+
if method == "options":
|
| 35 |
+
fs, _ = url_to_fs(url, **storage_options.get(protocol, {}))
|
| 36 |
+
return fs
|
| 37 |
+
raise ValueError(f"Unknown FS resolution method: {method}")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def rsync(
|
| 41 |
+
source,
|
| 42 |
+
destination,
|
| 43 |
+
delete_missing=False,
|
| 44 |
+
source_field="size",
|
| 45 |
+
dest_field="size",
|
| 46 |
+
update_cond="different",
|
| 47 |
+
inst_kwargs=None,
|
| 48 |
+
fs=None,
|
| 49 |
+
**kwargs,
|
| 50 |
+
):
|
| 51 |
+
"""Sync files between two directory trees
|
| 52 |
+
|
| 53 |
+
(experimental)
|
| 54 |
+
|
| 55 |
+
Parameters
|
| 56 |
+
----------
|
| 57 |
+
source: str
|
| 58 |
+
Root of the directory tree to take files from. This must be a directory, but
|
| 59 |
+
do not include any terminating "/" character
|
| 60 |
+
destination: str
|
| 61 |
+
Root path to copy into. The contents of this location should be
|
| 62 |
+
identical to the contents of ``source`` when done. This will be made a
|
| 63 |
+
directory, and the terminal "/" should not be included.
|
| 64 |
+
delete_missing: bool
|
| 65 |
+
If there are paths in the destination that don't exist in the
|
| 66 |
+
source and this is True, delete them. Otherwise, leave them alone.
|
| 67 |
+
source_field: str | callable
|
| 68 |
+
If ``update_field`` is "different", this is the key in the info
|
| 69 |
+
of source files to consider for difference. Maybe a function of the
|
| 70 |
+
info dict.
|
| 71 |
+
dest_field: str | callable
|
| 72 |
+
If ``update_field`` is "different", this is the key in the info
|
| 73 |
+
of destination files to consider for difference. May be a function of
|
| 74 |
+
the info dict.
|
| 75 |
+
update_cond: "different"|"always"|"never"
|
| 76 |
+
If "always", every file is copied, regardless of whether it exists in
|
| 77 |
+
the destination. If "never", files that exist in the destination are
|
| 78 |
+
not copied again. If "different" (default), only copy if the info
|
| 79 |
+
fields given by ``source_field`` and ``dest_field`` (usually "size")
|
| 80 |
+
are different. Other comparisons may be added in the future.
|
| 81 |
+
inst_kwargs: dict|None
|
| 82 |
+
If ``fs`` is None, use this set of keyword arguments to make a
|
| 83 |
+
GenericFileSystem instance
|
| 84 |
+
fs: GenericFileSystem|None
|
| 85 |
+
Instance to use if explicitly given. The instance defines how to
|
| 86 |
+
to make downstream file system instances from paths.
|
| 87 |
+
|
| 88 |
+
Returns
|
| 89 |
+
-------
|
| 90 |
+
dict of the copy operations that were performed, {source: destination}
|
| 91 |
+
"""
|
| 92 |
+
fs = fs or GenericFileSystem(**(inst_kwargs or {}))
|
| 93 |
+
source = fs._strip_protocol(source)
|
| 94 |
+
destination = fs._strip_protocol(destination)
|
| 95 |
+
allfiles = fs.find(source, withdirs=True, detail=True)
|
| 96 |
+
if not fs.isdir(source):
|
| 97 |
+
raise ValueError("Can only rsync on a directory")
|
| 98 |
+
otherfiles = fs.find(destination, withdirs=True, detail=True)
|
| 99 |
+
dirs = [
|
| 100 |
+
a
|
| 101 |
+
for a, v in allfiles.items()
|
| 102 |
+
if v["type"] == "directory" and a.replace(source, destination) not in otherfiles
|
| 103 |
+
]
|
| 104 |
+
logger.debug(f"{len(dirs)} directories to create")
|
| 105 |
+
if dirs:
|
| 106 |
+
fs.make_many_dirs(
|
| 107 |
+
[dirn.replace(source, destination) for dirn in dirs], exist_ok=True
|
| 108 |
+
)
|
| 109 |
+
allfiles = {a: v for a, v in allfiles.items() if v["type"] == "file"}
|
| 110 |
+
logger.debug(f"{len(allfiles)} files to consider for copy")
|
| 111 |
+
to_delete = [
|
| 112 |
+
o
|
| 113 |
+
for o, v in otherfiles.items()
|
| 114 |
+
if o.replace(destination, source) not in allfiles and v["type"] == "file"
|
| 115 |
+
]
|
| 116 |
+
for k, v in allfiles.copy().items():
|
| 117 |
+
otherfile = k.replace(source, destination)
|
| 118 |
+
if otherfile in otherfiles:
|
| 119 |
+
if update_cond == "always":
|
| 120 |
+
allfiles[k] = otherfile
|
| 121 |
+
elif update_cond == "never":
|
| 122 |
+
allfiles.pop(k)
|
| 123 |
+
elif update_cond == "different":
|
| 124 |
+
inf1 = source_field(v) if callable(source_field) else v[source_field]
|
| 125 |
+
v2 = otherfiles[otherfile]
|
| 126 |
+
inf2 = dest_field(v2) if callable(dest_field) else v2[dest_field]
|
| 127 |
+
if inf1 != inf2:
|
| 128 |
+
# details mismatch, make copy
|
| 129 |
+
allfiles[k] = otherfile
|
| 130 |
+
else:
|
| 131 |
+
# details match, don't copy
|
| 132 |
+
allfiles.pop(k)
|
| 133 |
+
else:
|
| 134 |
+
# file not in target yet
|
| 135 |
+
allfiles[k] = otherfile
|
| 136 |
+
logger.debug(f"{len(allfiles)} files to copy")
|
| 137 |
+
if allfiles:
|
| 138 |
+
source_files, target_files = zip(*allfiles.items())
|
| 139 |
+
fs.cp(source_files, target_files, **kwargs)
|
| 140 |
+
logger.debug(f"{len(to_delete)} files to delete")
|
| 141 |
+
if delete_missing and to_delete:
|
| 142 |
+
fs.rm(to_delete)
|
| 143 |
+
return allfiles
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class GenericFileSystem(AsyncFileSystem):
|
| 147 |
+
"""Wrapper over all other FS types
|
| 148 |
+
|
| 149 |
+
<experimental!>
|
| 150 |
+
|
| 151 |
+
This implementation is a single unified interface to be able to run FS operations
|
| 152 |
+
over generic URLs, and dispatch to the specific implementations using the URL
|
| 153 |
+
protocol prefix.
|
| 154 |
+
|
| 155 |
+
Note: instances of this FS are always async, even if you never use it with any async
|
| 156 |
+
backend.
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
protocol = "generic" # there is no real reason to ever use a protocol with this FS
|
| 160 |
+
|
| 161 |
+
def __init__(self, default_method="default", storage_options=None, **kwargs):
|
| 162 |
+
"""
|
| 163 |
+
|
| 164 |
+
Parameters
|
| 165 |
+
----------
|
| 166 |
+
default_method: str (optional)
|
| 167 |
+
Defines how to configure backend FS instances. Options are:
|
| 168 |
+
- "default": instantiate like FSClass(), with no
|
| 169 |
+
extra arguments; this is the default instance of that FS, and can be
|
| 170 |
+
configured via the config system
|
| 171 |
+
- "generic": takes instances from the `_generic_fs` dict in this module,
|
| 172 |
+
which you must populate before use. Keys are by protocol
|
| 173 |
+
- "options": expects storage_options, a dict mapping protocol to
|
| 174 |
+
kwargs to use when constructing the filesystem
|
| 175 |
+
- "current": takes the most recently instantiated version of each FS
|
| 176 |
+
"""
|
| 177 |
+
self.method = default_method
|
| 178 |
+
self.st_opts = storage_options
|
| 179 |
+
super().__init__(**kwargs)
|
| 180 |
+
|
| 181 |
+
def _parent(self, path):
|
| 182 |
+
fs = _resolve_fs(path, self.method, storage_options=self.st_opts)
|
| 183 |
+
return fs.unstrip_protocol(fs._parent(path))
|
| 184 |
+
|
| 185 |
+
def _strip_protocol(self, path):
|
| 186 |
+
# normalization only
|
| 187 |
+
fs = _resolve_fs(path, self.method, storage_options=self.st_opts)
|
| 188 |
+
return fs.unstrip_protocol(fs._strip_protocol(path))
|
| 189 |
+
|
| 190 |
+
async def _find(self, path, maxdepth=None, withdirs=False, detail=False, **kwargs):
|
| 191 |
+
fs = _resolve_fs(path, self.method, storage_options=self.st_opts)
|
| 192 |
+
if fs.async_impl:
|
| 193 |
+
out = await fs._find(
|
| 194 |
+
path, maxdepth=maxdepth, withdirs=withdirs, detail=True, **kwargs
|
| 195 |
+
)
|
| 196 |
+
else:
|
| 197 |
+
out = fs.find(
|
| 198 |
+
path, maxdepth=maxdepth, withdirs=withdirs, detail=True, **kwargs
|
| 199 |
+
)
|
| 200 |
+
result = {}
|
| 201 |
+
for k, v in out.items():
|
| 202 |
+
v = v.copy() # don't corrupt target FS dircache
|
| 203 |
+
name = fs.unstrip_protocol(k)
|
| 204 |
+
v["name"] = name
|
| 205 |
+
result[name] = v
|
| 206 |
+
if detail:
|
| 207 |
+
return result
|
| 208 |
+
return list(result)
|
| 209 |
+
|
| 210 |
+
async def _info(self, url, **kwargs):
|
| 211 |
+
fs = _resolve_fs(url, self.method)
|
| 212 |
+
if fs.async_impl:
|
| 213 |
+
out = await fs._info(url, **kwargs)
|
| 214 |
+
else:
|
| 215 |
+
out = fs.info(url, **kwargs)
|
| 216 |
+
out = out.copy() # don't edit originals
|
| 217 |
+
out["name"] = fs.unstrip_protocol(out["name"])
|
| 218 |
+
return out
|
| 219 |
+
|
| 220 |
+
async def _ls(
|
| 221 |
+
self,
|
| 222 |
+
url,
|
| 223 |
+
detail=True,
|
| 224 |
+
**kwargs,
|
| 225 |
+
):
|
| 226 |
+
fs = _resolve_fs(url, self.method)
|
| 227 |
+
if fs.async_impl:
|
| 228 |
+
out = await fs._ls(url, detail=True, **kwargs)
|
| 229 |
+
else:
|
| 230 |
+
out = fs.ls(url, detail=True, **kwargs)
|
| 231 |
+
out = [o.copy() for o in out] # don't edit originals
|
| 232 |
+
for o in out:
|
| 233 |
+
o["name"] = fs.unstrip_protocol(o["name"])
|
| 234 |
+
if detail:
|
| 235 |
+
return out
|
| 236 |
+
else:
|
| 237 |
+
return [o["name"] for o in out]
|
| 238 |
+
|
| 239 |
+
async def _cat_file(
|
| 240 |
+
self,
|
| 241 |
+
url,
|
| 242 |
+
**kwargs,
|
| 243 |
+
):
|
| 244 |
+
fs = _resolve_fs(url, self.method)
|
| 245 |
+
if fs.async_impl:
|
| 246 |
+
return await fs._cat_file(url, **kwargs)
|
| 247 |
+
else:
|
| 248 |
+
return fs.cat_file(url, **kwargs)
|
| 249 |
+
|
| 250 |
+
async def _pipe_file(
|
| 251 |
+
self,
|
| 252 |
+
path,
|
| 253 |
+
value,
|
| 254 |
+
**kwargs,
|
| 255 |
+
):
|
| 256 |
+
fs = _resolve_fs(path, self.method, storage_options=self.st_opts)
|
| 257 |
+
if fs.async_impl:
|
| 258 |
+
return await fs._pipe_file(path, value, **kwargs)
|
| 259 |
+
else:
|
| 260 |
+
return fs.pipe_file(path, value, **kwargs)
|
| 261 |
+
|
| 262 |
+
async def _rm(self, url, **kwargs):
|
| 263 |
+
urls = url
|
| 264 |
+
if isinstance(urls, str):
|
| 265 |
+
urls = [urls]
|
| 266 |
+
fs = _resolve_fs(urls[0], self.method)
|
| 267 |
+
if fs.async_impl:
|
| 268 |
+
await fs._rm(urls, **kwargs)
|
| 269 |
+
else:
|
| 270 |
+
fs.rm(url, **kwargs)
|
| 271 |
+
|
| 272 |
+
async def _makedirs(self, path, exist_ok=False):
|
| 273 |
+
logger.debug("Make dir %s", path)
|
| 274 |
+
fs = _resolve_fs(path, self.method, storage_options=self.st_opts)
|
| 275 |
+
if fs.async_impl:
|
| 276 |
+
await fs._makedirs(path, exist_ok=exist_ok)
|
| 277 |
+
else:
|
| 278 |
+
fs.makedirs(path, exist_ok=exist_ok)
|
| 279 |
+
|
| 280 |
+
def rsync(self, source, destination, **kwargs):
|
| 281 |
+
"""Sync files between two directory trees
|
| 282 |
+
|
| 283 |
+
See `func:rsync` for more details.
|
| 284 |
+
"""
|
| 285 |
+
rsync(source, destination, fs=self, **kwargs)
|
| 286 |
+
|
| 287 |
+
async def _cp_file(
|
| 288 |
+
self,
|
| 289 |
+
url,
|
| 290 |
+
url2,
|
| 291 |
+
blocksize=2**20,
|
| 292 |
+
callback=DEFAULT_CALLBACK,
|
| 293 |
+
tempdir: str | None = None,
|
| 294 |
+
**kwargs,
|
| 295 |
+
):
|
| 296 |
+
fs = _resolve_fs(url, self.method)
|
| 297 |
+
fs2 = _resolve_fs(url2, self.method)
|
| 298 |
+
if fs is fs2:
|
| 299 |
+
# pure remote
|
| 300 |
+
if fs.async_impl:
|
| 301 |
+
return await fs._copy(url, url2, **kwargs)
|
| 302 |
+
else:
|
| 303 |
+
return fs.copy(url, url2, **kwargs)
|
| 304 |
+
await copy_file_op(fs, [url], fs2, [url2], tempdir, 1, on_error="raise")
|
| 305 |
+
|
| 306 |
+
async def _make_many_dirs(self, urls, exist_ok=True):
|
| 307 |
+
fs = _resolve_fs(urls[0], self.method)
|
| 308 |
+
if fs.async_impl:
|
| 309 |
+
coros = [fs._makedirs(u, exist_ok=exist_ok) for u in urls]
|
| 310 |
+
await _run_coros_in_chunks(coros)
|
| 311 |
+
else:
|
| 312 |
+
for u in urls:
|
| 313 |
+
fs.makedirs(u, exist_ok=exist_ok)
|
| 314 |
+
|
| 315 |
+
make_many_dirs = sync_wrapper(_make_many_dirs)
|
| 316 |
+
|
| 317 |
+
async def _copy(
|
| 318 |
+
self,
|
| 319 |
+
path1: list[str],
|
| 320 |
+
path2: list[str],
|
| 321 |
+
recursive: bool = False,
|
| 322 |
+
on_error: str = "ignore",
|
| 323 |
+
maxdepth: int | None = None,
|
| 324 |
+
batch_size: int | None = None,
|
| 325 |
+
tempdir: str | None = None,
|
| 326 |
+
**kwargs,
|
| 327 |
+
):
|
| 328 |
+
# TODO: special case for one FS being local, which can use get/put
|
| 329 |
+
# TODO: special case for one being memFS, which can use cat/pipe
|
| 330 |
+
if recursive:
|
| 331 |
+
raise NotImplementedError("Please use fsspec.generic.rsync")
|
| 332 |
+
path1 = [path1] if isinstance(path1, str) else path1
|
| 333 |
+
path2 = [path2] if isinstance(path2, str) else path2
|
| 334 |
+
|
| 335 |
+
fs = _resolve_fs(path1, self.method)
|
| 336 |
+
fs2 = _resolve_fs(path2, self.method)
|
| 337 |
+
|
| 338 |
+
if fs is fs2:
|
| 339 |
+
if fs.async_impl:
|
| 340 |
+
return await fs._copy(path1, path2, **kwargs)
|
| 341 |
+
else:
|
| 342 |
+
return fs.copy(path1, path2, **kwargs)
|
| 343 |
+
|
| 344 |
+
await copy_file_op(
|
| 345 |
+
fs, path1, fs2, path2, tempdir, batch_size, on_error=on_error
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
async def copy_file_op(
|
| 350 |
+
fs1, url1, fs2, url2, tempdir=None, batch_size=20, on_error="ignore"
|
| 351 |
+
):
|
| 352 |
+
import tempfile
|
| 353 |
+
|
| 354 |
+
tempdir = tempdir or tempfile.mkdtemp()
|
| 355 |
+
try:
|
| 356 |
+
coros = [
|
| 357 |
+
_copy_file_op(
|
| 358 |
+
fs1,
|
| 359 |
+
u1,
|
| 360 |
+
fs2,
|
| 361 |
+
u2,
|
| 362 |
+
os.path.join(tempdir, uuid.uuid4().hex),
|
| 363 |
+
)
|
| 364 |
+
for u1, u2 in zip(url1, url2)
|
| 365 |
+
]
|
| 366 |
+
out = await _run_coros_in_chunks(
|
| 367 |
+
coros, batch_size=batch_size, return_exceptions=True
|
| 368 |
+
)
|
| 369 |
+
finally:
|
| 370 |
+
shutil.rmtree(tempdir)
|
| 371 |
+
if on_error == "return":
|
| 372 |
+
return out
|
| 373 |
+
elif on_error == "raise":
|
| 374 |
+
for o in out:
|
| 375 |
+
if isinstance(o, Exception):
|
| 376 |
+
raise o
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
async def _copy_file_op(fs1, url1, fs2, url2, local, on_error="ignore"):
|
| 380 |
+
if fs1.async_impl:
|
| 381 |
+
await fs1._get_file(url1, local)
|
| 382 |
+
else:
|
| 383 |
+
fs1.get_file(url1, local)
|
| 384 |
+
if fs2.async_impl:
|
| 385 |
+
await fs2._put_file(local, url2)
|
| 386 |
+
else:
|
| 387 |
+
fs2.put_file(local, url2)
|
| 388 |
+
os.unlink(local)
|
| 389 |
+
logger.debug("Copy %s -> %s; done", url1, url2)
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
async def maybe_await(cor):
|
| 393 |
+
if inspect.iscoroutine(cor):
|
| 394 |
+
return await cor
|
| 395 |
+
else:
|
| 396 |
+
return cor
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/gui.py
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
import contextlib
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
from collections.abc import Sequence
|
| 7 |
+
from typing import ClassVar
|
| 8 |
+
|
| 9 |
+
import panel as pn
|
| 10 |
+
|
| 11 |
+
from .core import OpenFile, get_filesystem_class, split_protocol
|
| 12 |
+
from .registry import known_implementations
|
| 13 |
+
|
| 14 |
+
pn.extension()
|
| 15 |
+
logger = logging.getLogger("fsspec.gui")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class SigSlot:
|
| 19 |
+
"""Signal-slot mixin, for Panel event passing
|
| 20 |
+
|
| 21 |
+
Include this class in a widget manager's superclasses to be able to
|
| 22 |
+
register events and callbacks on Panel widgets managed by that class.
|
| 23 |
+
|
| 24 |
+
The method ``_register`` should be called as widgets are added, and external
|
| 25 |
+
code should call ``connect`` to associate callbacks.
|
| 26 |
+
|
| 27 |
+
By default, all signals emit a DEBUG logging statement.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
# names of signals that this class may emit each of which must be
|
| 31 |
+
# set by _register for any new instance
|
| 32 |
+
signals: ClassVar[Sequence[str]] = []
|
| 33 |
+
# names of actions that this class may respond to
|
| 34 |
+
slots: ClassVar[Sequence[str]] = []
|
| 35 |
+
|
| 36 |
+
# each of which must be a method name
|
| 37 |
+
|
| 38 |
+
def __init__(self):
|
| 39 |
+
self._ignoring_events = False
|
| 40 |
+
self._sigs = {}
|
| 41 |
+
self._map = {}
|
| 42 |
+
self._setup()
|
| 43 |
+
|
| 44 |
+
def _setup(self):
|
| 45 |
+
"""Create GUI elements and register signals"""
|
| 46 |
+
self.panel = pn.pane.PaneBase()
|
| 47 |
+
# no signals to set up in the base class
|
| 48 |
+
|
| 49 |
+
def _register(
|
| 50 |
+
self, widget, name, thing="value", log_level=logging.DEBUG, auto=False
|
| 51 |
+
):
|
| 52 |
+
"""Watch the given attribute of a widget and assign it a named event
|
| 53 |
+
|
| 54 |
+
This is normally called at the time a widget is instantiated, in the
|
| 55 |
+
class which owns it.
|
| 56 |
+
|
| 57 |
+
Parameters
|
| 58 |
+
----------
|
| 59 |
+
widget : pn.layout.Panel or None
|
| 60 |
+
Widget to watch. If None, an anonymous signal not associated with
|
| 61 |
+
any widget.
|
| 62 |
+
name : str
|
| 63 |
+
Name of this event
|
| 64 |
+
thing : str
|
| 65 |
+
Attribute of the given widget to watch
|
| 66 |
+
log_level : int
|
| 67 |
+
When the signal is triggered, a logging event of the given level
|
| 68 |
+
will be fired in the dfviz logger.
|
| 69 |
+
auto : bool
|
| 70 |
+
If True, automatically connects with a method in this class of the
|
| 71 |
+
same name.
|
| 72 |
+
"""
|
| 73 |
+
if name not in self.signals:
|
| 74 |
+
raise ValueError(f"Attempt to assign an undeclared signal: {name}")
|
| 75 |
+
self._sigs[name] = {
|
| 76 |
+
"widget": widget,
|
| 77 |
+
"callbacks": [],
|
| 78 |
+
"thing": thing,
|
| 79 |
+
"log": log_level,
|
| 80 |
+
}
|
| 81 |
+
wn = "-".join(
|
| 82 |
+
[
|
| 83 |
+
getattr(widget, "name", str(widget)) if widget is not None else "none",
|
| 84 |
+
thing,
|
| 85 |
+
]
|
| 86 |
+
)
|
| 87 |
+
self._map[wn] = name
|
| 88 |
+
if widget is not None:
|
| 89 |
+
widget.param.watch(self._signal, thing, onlychanged=True)
|
| 90 |
+
if auto and hasattr(self, name):
|
| 91 |
+
self.connect(name, getattr(self, name))
|
| 92 |
+
|
| 93 |
+
def _repr_mimebundle_(self, *args, **kwargs):
|
| 94 |
+
"""Display in a notebook or a server"""
|
| 95 |
+
try:
|
| 96 |
+
return self.panel._repr_mimebundle_(*args, **kwargs)
|
| 97 |
+
except (ValueError, AttributeError) as exc:
|
| 98 |
+
raise NotImplementedError(
|
| 99 |
+
"Panel does not seem to be set up properly"
|
| 100 |
+
) from exc
|
| 101 |
+
|
| 102 |
+
def connect(self, signal, slot):
|
| 103 |
+
"""Associate call back with given event
|
| 104 |
+
|
| 105 |
+
The callback must be a function which takes the "new" value of the
|
| 106 |
+
watched attribute as the only parameter. If the callback return False,
|
| 107 |
+
this cancels any further processing of the given event.
|
| 108 |
+
|
| 109 |
+
Alternatively, the callback can be a string, in which case it means
|
| 110 |
+
emitting the correspondingly-named event (i.e., connect to self)
|
| 111 |
+
"""
|
| 112 |
+
self._sigs[signal]["callbacks"].append(slot)
|
| 113 |
+
|
| 114 |
+
def _signal(self, event):
|
| 115 |
+
"""This is called by a an action on a widget
|
| 116 |
+
|
| 117 |
+
Within an self.ignore_events context, nothing happens.
|
| 118 |
+
|
| 119 |
+
Tests can execute this method by directly changing the values of
|
| 120 |
+
widget components.
|
| 121 |
+
"""
|
| 122 |
+
if not self._ignoring_events:
|
| 123 |
+
wn = "-".join([event.obj.name, event.name])
|
| 124 |
+
if wn in self._map and self._map[wn] in self._sigs:
|
| 125 |
+
self._emit(self._map[wn], event.new)
|
| 126 |
+
|
| 127 |
+
@contextlib.contextmanager
|
| 128 |
+
def ignore_events(self):
|
| 129 |
+
"""Temporarily turn off events processing in this instance
|
| 130 |
+
|
| 131 |
+
(does not propagate to children)
|
| 132 |
+
"""
|
| 133 |
+
self._ignoring_events = True
|
| 134 |
+
try:
|
| 135 |
+
yield
|
| 136 |
+
finally:
|
| 137 |
+
self._ignoring_events = False
|
| 138 |
+
|
| 139 |
+
def _emit(self, sig, value=None):
|
| 140 |
+
"""An event happened, call its callbacks
|
| 141 |
+
|
| 142 |
+
This method can be used in tests to simulate message passing without
|
| 143 |
+
directly changing visual elements.
|
| 144 |
+
|
| 145 |
+
Calling of callbacks will halt whenever one returns False.
|
| 146 |
+
"""
|
| 147 |
+
logger.log(self._sigs[sig]["log"], f"{sig}: {value}")
|
| 148 |
+
for callback in self._sigs[sig]["callbacks"]:
|
| 149 |
+
if isinstance(callback, str):
|
| 150 |
+
self._emit(callback)
|
| 151 |
+
else:
|
| 152 |
+
try:
|
| 153 |
+
# running callbacks should not break the interface
|
| 154 |
+
ret = callback(value)
|
| 155 |
+
if ret is False:
|
| 156 |
+
break
|
| 157 |
+
except Exception as e:
|
| 158 |
+
logger.exception(
|
| 159 |
+
"Exception (%s) while executing callback for signal: %s",
|
| 160 |
+
e,
|
| 161 |
+
sig,
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
def show(self, threads=False):
|
| 165 |
+
"""Open a new browser tab and display this instance's interface"""
|
| 166 |
+
self.panel.show(threads=threads, verbose=False)
|
| 167 |
+
return self
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
class SingleSelect(SigSlot):
|
| 171 |
+
"""A multiselect which only allows you to select one item for an event"""
|
| 172 |
+
|
| 173 |
+
signals = ["_selected", "selected"] # the first is internal
|
| 174 |
+
slots = ["set_options", "set_selection", "add", "clear", "select"]
|
| 175 |
+
|
| 176 |
+
def __init__(self, **kwargs):
|
| 177 |
+
self.kwargs = kwargs
|
| 178 |
+
super().__init__()
|
| 179 |
+
|
| 180 |
+
def _setup(self):
|
| 181 |
+
self.panel = pn.widgets.MultiSelect(**self.kwargs)
|
| 182 |
+
self._register(self.panel, "_selected", "value")
|
| 183 |
+
self._register(None, "selected")
|
| 184 |
+
self.connect("_selected", self.select_one)
|
| 185 |
+
|
| 186 |
+
def _signal(self, *args, **kwargs):
|
| 187 |
+
super()._signal(*args, **kwargs)
|
| 188 |
+
|
| 189 |
+
def select_one(self, *_):
|
| 190 |
+
with self.ignore_events():
|
| 191 |
+
val = [self.panel.value[-1]] if self.panel.value else []
|
| 192 |
+
self.panel.value = val
|
| 193 |
+
self._emit("selected", self.panel.value)
|
| 194 |
+
|
| 195 |
+
def set_options(self, options):
|
| 196 |
+
self.panel.options = options
|
| 197 |
+
|
| 198 |
+
def clear(self):
|
| 199 |
+
self.panel.options = []
|
| 200 |
+
|
| 201 |
+
@property
|
| 202 |
+
def value(self):
|
| 203 |
+
return self.panel.value
|
| 204 |
+
|
| 205 |
+
def set_selection(self, selection):
|
| 206 |
+
self.panel.value = [selection]
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
class FileSelector(SigSlot):
|
| 210 |
+
"""Panel-based graphical file selector widget
|
| 211 |
+
|
| 212 |
+
Instances of this widget are interactive and can be displayed in jupyter by having
|
| 213 |
+
them as the output of a cell, or in a separate browser tab using ``.show()``.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
signals = [
|
| 217 |
+
"protocol_changed",
|
| 218 |
+
"selection_changed",
|
| 219 |
+
"directory_entered",
|
| 220 |
+
"home_clicked",
|
| 221 |
+
"up_clicked",
|
| 222 |
+
"go_clicked",
|
| 223 |
+
"filters_changed",
|
| 224 |
+
]
|
| 225 |
+
slots = ["set_filters", "go_home"]
|
| 226 |
+
|
| 227 |
+
def __init__(self, url=None, filters=None, ignore=None, kwargs=None):
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
Parameters
|
| 231 |
+
----------
|
| 232 |
+
url : str (optional)
|
| 233 |
+
Initial value of the URL to populate the dialog; should include protocol
|
| 234 |
+
filters : list(str) (optional)
|
| 235 |
+
File endings to include in the listings. If not included, all files are
|
| 236 |
+
allowed. Does not affect directories.
|
| 237 |
+
If given, the endings will appear as checkboxes in the interface
|
| 238 |
+
ignore : list(str) (optional)
|
| 239 |
+
Regex(s) of file basename patterns to ignore, e.g., "\\." for typical
|
| 240 |
+
hidden files on posix
|
| 241 |
+
kwargs : dict (optional)
|
| 242 |
+
To pass to file system instance
|
| 243 |
+
"""
|
| 244 |
+
if url:
|
| 245 |
+
self.init_protocol, url = split_protocol(url)
|
| 246 |
+
else:
|
| 247 |
+
self.init_protocol, url = "file", os.getcwd()
|
| 248 |
+
self.init_url = url
|
| 249 |
+
self.init_kwargs = (kwargs if isinstance(kwargs, str) else str(kwargs)) or "{}"
|
| 250 |
+
self.filters = filters
|
| 251 |
+
self.ignore = [re.compile(i) for i in ignore or []]
|
| 252 |
+
self._fs = None
|
| 253 |
+
super().__init__()
|
| 254 |
+
|
| 255 |
+
def _setup(self):
|
| 256 |
+
self.url = pn.widgets.TextInput(
|
| 257 |
+
name="url",
|
| 258 |
+
value=self.init_url,
|
| 259 |
+
align="end",
|
| 260 |
+
sizing_mode="stretch_width",
|
| 261 |
+
width_policy="max",
|
| 262 |
+
)
|
| 263 |
+
self.protocol = pn.widgets.Select(
|
| 264 |
+
options=sorted(known_implementations),
|
| 265 |
+
value=self.init_protocol,
|
| 266 |
+
name="protocol",
|
| 267 |
+
align="center",
|
| 268 |
+
)
|
| 269 |
+
self.kwargs = pn.widgets.TextInput(
|
| 270 |
+
name="kwargs", value=self.init_kwargs, align="center"
|
| 271 |
+
)
|
| 272 |
+
self.go = pn.widgets.Button(name="⇨", align="end", width=45)
|
| 273 |
+
self.main = SingleSelect(size=10)
|
| 274 |
+
self.home = pn.widgets.Button(name="🏠", width=40, height=30, align="end")
|
| 275 |
+
self.up = pn.widgets.Button(name="‹", width=30, height=30, align="end")
|
| 276 |
+
|
| 277 |
+
self._register(self.protocol, "protocol_changed", auto=True)
|
| 278 |
+
self._register(self.go, "go_clicked", "clicks", auto=True)
|
| 279 |
+
self._register(self.up, "up_clicked", "clicks", auto=True)
|
| 280 |
+
self._register(self.home, "home_clicked", "clicks", auto=True)
|
| 281 |
+
self._register(None, "selection_changed")
|
| 282 |
+
self.main.connect("selected", self.selection_changed)
|
| 283 |
+
self._register(None, "directory_entered")
|
| 284 |
+
self.prev_protocol = self.protocol.value
|
| 285 |
+
self.prev_kwargs = self.storage_options
|
| 286 |
+
|
| 287 |
+
self.filter_sel = pn.widgets.CheckBoxGroup(
|
| 288 |
+
value=[], options=[], inline=False, align="end", width_policy="min"
|
| 289 |
+
)
|
| 290 |
+
self._register(self.filter_sel, "filters_changed", auto=True)
|
| 291 |
+
|
| 292 |
+
self.panel = pn.Column(
|
| 293 |
+
pn.Row(self.protocol, self.kwargs),
|
| 294 |
+
pn.Row(self.home, self.up, self.url, self.go, self.filter_sel),
|
| 295 |
+
self.main.panel,
|
| 296 |
+
)
|
| 297 |
+
self.set_filters(self.filters)
|
| 298 |
+
self.go_clicked()
|
| 299 |
+
|
| 300 |
+
def set_filters(self, filters=None):
|
| 301 |
+
self.filters = filters
|
| 302 |
+
if filters:
|
| 303 |
+
self.filter_sel.options = filters
|
| 304 |
+
self.filter_sel.value = filters
|
| 305 |
+
else:
|
| 306 |
+
self.filter_sel.options = []
|
| 307 |
+
self.filter_sel.value = []
|
| 308 |
+
|
| 309 |
+
@property
|
| 310 |
+
def storage_options(self):
|
| 311 |
+
"""Value of the kwargs box as a dictionary"""
|
| 312 |
+
return ast.literal_eval(self.kwargs.value) or {}
|
| 313 |
+
|
| 314 |
+
@property
|
| 315 |
+
def fs(self):
|
| 316 |
+
"""Current filesystem instance"""
|
| 317 |
+
if self._fs is None:
|
| 318 |
+
cls = get_filesystem_class(self.protocol.value)
|
| 319 |
+
self._fs = cls(**self.storage_options)
|
| 320 |
+
return self._fs
|
| 321 |
+
|
| 322 |
+
@property
|
| 323 |
+
def urlpath(self):
|
| 324 |
+
"""URL of currently selected item"""
|
| 325 |
+
return (
|
| 326 |
+
(f"{self.protocol.value}://{self.main.value[0]}")
|
| 327 |
+
if self.main.value
|
| 328 |
+
else None
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
def open_file(self, mode="rb", compression=None, encoding=None):
|
| 332 |
+
"""Create OpenFile instance for the currently selected item
|
| 333 |
+
|
| 334 |
+
For example, in a notebook you might do something like
|
| 335 |
+
|
| 336 |
+
.. code-block::
|
| 337 |
+
|
| 338 |
+
[ ]: sel = FileSelector(); sel
|
| 339 |
+
|
| 340 |
+
# user selects their file
|
| 341 |
+
|
| 342 |
+
[ ]: with sel.open_file('rb') as f:
|
| 343 |
+
... out = f.read()
|
| 344 |
+
|
| 345 |
+
Parameters
|
| 346 |
+
----------
|
| 347 |
+
mode: str (optional)
|
| 348 |
+
Open mode for the file.
|
| 349 |
+
compression: str (optional)
|
| 350 |
+
The interact with the file as compressed. Set to 'infer' to guess
|
| 351 |
+
compression from the file ending
|
| 352 |
+
encoding: str (optional)
|
| 353 |
+
If using text mode, use this encoding; defaults to UTF8.
|
| 354 |
+
"""
|
| 355 |
+
if self.urlpath is None:
|
| 356 |
+
raise ValueError("No file selected")
|
| 357 |
+
return OpenFile(self.fs, self.urlpath, mode, compression, encoding)
|
| 358 |
+
|
| 359 |
+
def filters_changed(self, values):
|
| 360 |
+
self.filters = values
|
| 361 |
+
self.go_clicked()
|
| 362 |
+
|
| 363 |
+
def selection_changed(self, *_):
|
| 364 |
+
if self.urlpath is None:
|
| 365 |
+
return
|
| 366 |
+
if self.fs.isdir(self.urlpath):
|
| 367 |
+
self.url.value = self.fs._strip_protocol(self.urlpath)
|
| 368 |
+
self.go_clicked()
|
| 369 |
+
|
| 370 |
+
def go_clicked(self, *_):
|
| 371 |
+
if (
|
| 372 |
+
self.prev_protocol != self.protocol.value
|
| 373 |
+
or self.prev_kwargs != self.storage_options
|
| 374 |
+
):
|
| 375 |
+
self._fs = None # causes fs to be recreated
|
| 376 |
+
self.prev_protocol = self.protocol.value
|
| 377 |
+
self.prev_kwargs = self.storage_options
|
| 378 |
+
listing = sorted(
|
| 379 |
+
self.fs.ls(self.url.value, detail=True), key=lambda x: x["name"]
|
| 380 |
+
)
|
| 381 |
+
listing = [
|
| 382 |
+
l
|
| 383 |
+
for l in listing
|
| 384 |
+
if not any(i.match(l["name"].rsplit("/", 1)[-1]) for i in self.ignore)
|
| 385 |
+
]
|
| 386 |
+
folders = {
|
| 387 |
+
"📁 " + o["name"].rsplit("/", 1)[-1]: o["name"]
|
| 388 |
+
for o in listing
|
| 389 |
+
if o["type"] == "directory"
|
| 390 |
+
}
|
| 391 |
+
files = {
|
| 392 |
+
"📄 " + o["name"].rsplit("/", 1)[-1]: o["name"]
|
| 393 |
+
for o in listing
|
| 394 |
+
if o["type"] == "file"
|
| 395 |
+
}
|
| 396 |
+
if self.filters:
|
| 397 |
+
files = {
|
| 398 |
+
k: v
|
| 399 |
+
for k, v in files.items()
|
| 400 |
+
if any(v.endswith(ext) for ext in self.filters)
|
| 401 |
+
}
|
| 402 |
+
self.main.set_options(dict(**folders, **files))
|
| 403 |
+
|
| 404 |
+
def protocol_changed(self, *_):
|
| 405 |
+
self._fs = None
|
| 406 |
+
self.main.options = []
|
| 407 |
+
self.url.value = ""
|
| 408 |
+
|
| 409 |
+
def home_clicked(self, *_):
|
| 410 |
+
self.protocol.value = self.init_protocol
|
| 411 |
+
self.kwargs.value = self.init_kwargs
|
| 412 |
+
self.url.value = self.init_url
|
| 413 |
+
self.go_clicked()
|
| 414 |
+
|
| 415 |
+
def up_clicked(self, *_):
|
| 416 |
+
self.url.value = self.fs._parent(self.url.value)
|
| 417 |
+
self.go_clicked()
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/__init__.py
ADDED
|
File without changes
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/arrow.py
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import errno
|
| 2 |
+
import io
|
| 3 |
+
import os
|
| 4 |
+
import secrets
|
| 5 |
+
import shutil
|
| 6 |
+
from contextlib import suppress
|
| 7 |
+
from functools import cached_property, wraps
|
| 8 |
+
from urllib.parse import parse_qs
|
| 9 |
+
|
| 10 |
+
from fsspec.spec import AbstractFileSystem
|
| 11 |
+
from fsspec.utils import (
|
| 12 |
+
get_package_version_without_import,
|
| 13 |
+
infer_storage_options,
|
| 14 |
+
mirror_from,
|
| 15 |
+
tokenize,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def wrap_exceptions(func):
|
| 20 |
+
@wraps(func)
|
| 21 |
+
def wrapper(*args, **kwargs):
|
| 22 |
+
try:
|
| 23 |
+
return func(*args, **kwargs)
|
| 24 |
+
except OSError as exception:
|
| 25 |
+
if not exception.args:
|
| 26 |
+
raise
|
| 27 |
+
|
| 28 |
+
message, *args = exception.args
|
| 29 |
+
if isinstance(message, str) and "does not exist" in message:
|
| 30 |
+
raise FileNotFoundError(errno.ENOENT, message) from exception
|
| 31 |
+
else:
|
| 32 |
+
raise
|
| 33 |
+
|
| 34 |
+
return wrapper
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
PYARROW_VERSION = None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class ArrowFSWrapper(AbstractFileSystem):
|
| 41 |
+
"""FSSpec-compatible wrapper of pyarrow.fs.FileSystem.
|
| 42 |
+
|
| 43 |
+
Parameters
|
| 44 |
+
----------
|
| 45 |
+
fs : pyarrow.fs.FileSystem
|
| 46 |
+
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
root_marker = "/"
|
| 50 |
+
|
| 51 |
+
def __init__(self, fs, **kwargs):
|
| 52 |
+
global PYARROW_VERSION
|
| 53 |
+
PYARROW_VERSION = get_package_version_without_import("pyarrow")
|
| 54 |
+
self.fs = fs
|
| 55 |
+
super().__init__(**kwargs)
|
| 56 |
+
|
| 57 |
+
@property
|
| 58 |
+
def protocol(self):
|
| 59 |
+
return self.fs.type_name
|
| 60 |
+
|
| 61 |
+
@cached_property
|
| 62 |
+
def fsid(self):
|
| 63 |
+
return "hdfs_" + tokenize(self.fs.host, self.fs.port)
|
| 64 |
+
|
| 65 |
+
@classmethod
|
| 66 |
+
def _strip_protocol(cls, path):
|
| 67 |
+
ops = infer_storage_options(path)
|
| 68 |
+
path = ops["path"]
|
| 69 |
+
if path.startswith("//"):
|
| 70 |
+
# special case for "hdfs://path" (without the triple slash)
|
| 71 |
+
path = path[1:]
|
| 72 |
+
return path
|
| 73 |
+
|
| 74 |
+
def ls(self, path, detail=False, **kwargs):
|
| 75 |
+
path = self._strip_protocol(path)
|
| 76 |
+
from pyarrow.fs import FileSelector
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
entries = [
|
| 80 |
+
self._make_entry(entry)
|
| 81 |
+
for entry in self.fs.get_file_info(FileSelector(path))
|
| 82 |
+
]
|
| 83 |
+
except (FileNotFoundError, NotADirectoryError):
|
| 84 |
+
entries = [self.info(path, **kwargs)]
|
| 85 |
+
if detail:
|
| 86 |
+
return entries
|
| 87 |
+
else:
|
| 88 |
+
return [entry["name"] for entry in entries]
|
| 89 |
+
|
| 90 |
+
def info(self, path, **kwargs):
|
| 91 |
+
path = self._strip_protocol(path)
|
| 92 |
+
[info] = self.fs.get_file_info([path])
|
| 93 |
+
return self._make_entry(info)
|
| 94 |
+
|
| 95 |
+
def exists(self, path):
|
| 96 |
+
path = self._strip_protocol(path)
|
| 97 |
+
try:
|
| 98 |
+
self.info(path)
|
| 99 |
+
except FileNotFoundError:
|
| 100 |
+
return False
|
| 101 |
+
else:
|
| 102 |
+
return True
|
| 103 |
+
|
| 104 |
+
def _make_entry(self, info):
|
| 105 |
+
from pyarrow.fs import FileType
|
| 106 |
+
|
| 107 |
+
if info.type is FileType.Directory:
|
| 108 |
+
kind = "directory"
|
| 109 |
+
elif info.type is FileType.File:
|
| 110 |
+
kind = "file"
|
| 111 |
+
elif info.type is FileType.NotFound:
|
| 112 |
+
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), info.path)
|
| 113 |
+
else:
|
| 114 |
+
kind = "other"
|
| 115 |
+
|
| 116 |
+
return {
|
| 117 |
+
"name": info.path,
|
| 118 |
+
"size": info.size,
|
| 119 |
+
"type": kind,
|
| 120 |
+
"mtime": info.mtime,
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
@wrap_exceptions
|
| 124 |
+
def cp_file(self, path1, path2, **kwargs):
|
| 125 |
+
path1 = self._strip_protocol(path1).rstrip("/")
|
| 126 |
+
path2 = self._strip_protocol(path2).rstrip("/")
|
| 127 |
+
|
| 128 |
+
with self._open(path1, "rb") as lstream:
|
| 129 |
+
tmp_fname = f"{path2}.tmp.{secrets.token_hex(6)}"
|
| 130 |
+
try:
|
| 131 |
+
with self.open(tmp_fname, "wb") as rstream:
|
| 132 |
+
shutil.copyfileobj(lstream, rstream)
|
| 133 |
+
self.fs.move(tmp_fname, path2)
|
| 134 |
+
except BaseException:
|
| 135 |
+
with suppress(FileNotFoundError):
|
| 136 |
+
self.fs.delete_file(tmp_fname)
|
| 137 |
+
raise
|
| 138 |
+
|
| 139 |
+
@wrap_exceptions
|
| 140 |
+
def mv(self, path1, path2, **kwargs):
|
| 141 |
+
path1 = self._strip_protocol(path1).rstrip("/")
|
| 142 |
+
path2 = self._strip_protocol(path2).rstrip("/")
|
| 143 |
+
self.fs.move(path1, path2)
|
| 144 |
+
|
| 145 |
+
@wrap_exceptions
|
| 146 |
+
def rm_file(self, path):
|
| 147 |
+
path = self._strip_protocol(path)
|
| 148 |
+
self.fs.delete_file(path)
|
| 149 |
+
|
| 150 |
+
@wrap_exceptions
|
| 151 |
+
def rm(self, path, recursive=False, maxdepth=None):
|
| 152 |
+
path = self._strip_protocol(path).rstrip("/")
|
| 153 |
+
if self.isdir(path):
|
| 154 |
+
if recursive:
|
| 155 |
+
self.fs.delete_dir(path)
|
| 156 |
+
else:
|
| 157 |
+
raise ValueError("Can't delete directories without recursive=False")
|
| 158 |
+
else:
|
| 159 |
+
self.fs.delete_file(path)
|
| 160 |
+
|
| 161 |
+
@wrap_exceptions
|
| 162 |
+
def _open(self, path, mode="rb", block_size=None, seekable=True, **kwargs):
|
| 163 |
+
if mode == "rb":
|
| 164 |
+
if seekable:
|
| 165 |
+
method = self.fs.open_input_file
|
| 166 |
+
else:
|
| 167 |
+
method = self.fs.open_input_stream
|
| 168 |
+
elif mode == "wb":
|
| 169 |
+
method = self.fs.open_output_stream
|
| 170 |
+
elif mode == "ab":
|
| 171 |
+
method = self.fs.open_append_stream
|
| 172 |
+
else:
|
| 173 |
+
raise ValueError(f"unsupported mode for Arrow filesystem: {mode!r}")
|
| 174 |
+
|
| 175 |
+
_kwargs = {}
|
| 176 |
+
if mode != "rb" or not seekable:
|
| 177 |
+
if int(PYARROW_VERSION.split(".")[0]) >= 4:
|
| 178 |
+
# disable compression auto-detection
|
| 179 |
+
_kwargs["compression"] = None
|
| 180 |
+
stream = method(path, **_kwargs)
|
| 181 |
+
|
| 182 |
+
return ArrowFile(self, stream, path, mode, block_size, **kwargs)
|
| 183 |
+
|
| 184 |
+
@wrap_exceptions
|
| 185 |
+
def mkdir(self, path, create_parents=True, **kwargs):
|
| 186 |
+
path = self._strip_protocol(path)
|
| 187 |
+
if create_parents:
|
| 188 |
+
self.makedirs(path, exist_ok=True)
|
| 189 |
+
else:
|
| 190 |
+
self.fs.create_dir(path, recursive=False)
|
| 191 |
+
|
| 192 |
+
@wrap_exceptions
|
| 193 |
+
def makedirs(self, path, exist_ok=False):
|
| 194 |
+
path = self._strip_protocol(path)
|
| 195 |
+
self.fs.create_dir(path, recursive=True)
|
| 196 |
+
|
| 197 |
+
@wrap_exceptions
|
| 198 |
+
def rmdir(self, path):
|
| 199 |
+
path = self._strip_protocol(path)
|
| 200 |
+
self.fs.delete_dir(path)
|
| 201 |
+
|
| 202 |
+
@wrap_exceptions
|
| 203 |
+
def modified(self, path):
|
| 204 |
+
path = self._strip_protocol(path)
|
| 205 |
+
return self.fs.get_file_info(path).mtime
|
| 206 |
+
|
| 207 |
+
def cat_file(self, path, start=None, end=None, **kwargs):
|
| 208 |
+
kwargs.setdefault("seekable", start not in [None, 0])
|
| 209 |
+
return super().cat_file(path, start=None, end=None, **kwargs)
|
| 210 |
+
|
| 211 |
+
def get_file(self, rpath, lpath, **kwargs):
|
| 212 |
+
kwargs.setdefault("seekable", False)
|
| 213 |
+
super().get_file(rpath, lpath, **kwargs)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
@mirror_from(
|
| 217 |
+
"stream",
|
| 218 |
+
[
|
| 219 |
+
"read",
|
| 220 |
+
"seek",
|
| 221 |
+
"tell",
|
| 222 |
+
"write",
|
| 223 |
+
"readable",
|
| 224 |
+
"writable",
|
| 225 |
+
"close",
|
| 226 |
+
"seekable",
|
| 227 |
+
],
|
| 228 |
+
)
|
| 229 |
+
class ArrowFile(io.IOBase):
|
| 230 |
+
def __init__(self, fs, stream, path, mode, block_size=None, **kwargs):
|
| 231 |
+
self.path = path
|
| 232 |
+
self.mode = mode
|
| 233 |
+
|
| 234 |
+
self.fs = fs
|
| 235 |
+
self.stream = stream
|
| 236 |
+
|
| 237 |
+
self.blocksize = self.block_size = block_size
|
| 238 |
+
self.kwargs = kwargs
|
| 239 |
+
|
| 240 |
+
def __enter__(self):
|
| 241 |
+
return self
|
| 242 |
+
|
| 243 |
+
@property
|
| 244 |
+
def size(self):
|
| 245 |
+
if self.stream.seekable():
|
| 246 |
+
return self.stream.size()
|
| 247 |
+
return None
|
| 248 |
+
|
| 249 |
+
def __exit__(self, *args):
|
| 250 |
+
return self.close()
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
class HadoopFileSystem(ArrowFSWrapper):
|
| 254 |
+
"""A wrapper on top of the pyarrow.fs.HadoopFileSystem
|
| 255 |
+
to connect it's interface with fsspec"""
|
| 256 |
+
|
| 257 |
+
protocol = "hdfs"
|
| 258 |
+
|
| 259 |
+
def __init__(
|
| 260 |
+
self,
|
| 261 |
+
host="default",
|
| 262 |
+
port=0,
|
| 263 |
+
user=None,
|
| 264 |
+
kerb_ticket=None,
|
| 265 |
+
replication=3,
|
| 266 |
+
extra_conf=None,
|
| 267 |
+
**kwargs,
|
| 268 |
+
):
|
| 269 |
+
"""
|
| 270 |
+
|
| 271 |
+
Parameters
|
| 272 |
+
----------
|
| 273 |
+
host: str
|
| 274 |
+
Hostname, IP or "default" to try to read from Hadoop config
|
| 275 |
+
port: int
|
| 276 |
+
Port to connect on, or default from Hadoop config if 0
|
| 277 |
+
user: str or None
|
| 278 |
+
If given, connect as this username
|
| 279 |
+
kerb_ticket: str or None
|
| 280 |
+
If given, use this ticket for authentication
|
| 281 |
+
replication: int
|
| 282 |
+
set replication factor of file for write operations. default value is 3.
|
| 283 |
+
extra_conf: None or dict
|
| 284 |
+
Passed on to HadoopFileSystem
|
| 285 |
+
"""
|
| 286 |
+
from pyarrow.fs import HadoopFileSystem
|
| 287 |
+
|
| 288 |
+
fs = HadoopFileSystem(
|
| 289 |
+
host=host,
|
| 290 |
+
port=port,
|
| 291 |
+
user=user,
|
| 292 |
+
kerb_ticket=kerb_ticket,
|
| 293 |
+
replication=replication,
|
| 294 |
+
extra_conf=extra_conf,
|
| 295 |
+
)
|
| 296 |
+
super().__init__(fs=fs, **kwargs)
|
| 297 |
+
|
| 298 |
+
@staticmethod
|
| 299 |
+
def _get_kwargs_from_urls(path):
|
| 300 |
+
ops = infer_storage_options(path)
|
| 301 |
+
out = {}
|
| 302 |
+
if ops.get("host", None):
|
| 303 |
+
out["host"] = ops["host"]
|
| 304 |
+
if ops.get("username", None):
|
| 305 |
+
out["user"] = ops["username"]
|
| 306 |
+
if ops.get("port", None):
|
| 307 |
+
out["port"] = ops["port"]
|
| 308 |
+
if ops.get("url_query", None):
|
| 309 |
+
queries = parse_qs(ops["url_query"])
|
| 310 |
+
if queries.get("replication", None):
|
| 311 |
+
out["replication"] = int(queries["replication"][0])
|
| 312 |
+
return out
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/asyn_wrapper.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import functools
|
| 3 |
+
import inspect
|
| 4 |
+
|
| 5 |
+
import fsspec
|
| 6 |
+
from fsspec.asyn import AsyncFileSystem, running_async
|
| 7 |
+
|
| 8 |
+
from .chained import ChainedFileSystem
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def async_wrapper(func, obj=None, semaphore=None):
|
| 12 |
+
"""
|
| 13 |
+
Wraps a synchronous function to make it awaitable.
|
| 14 |
+
|
| 15 |
+
Parameters
|
| 16 |
+
----------
|
| 17 |
+
func : callable
|
| 18 |
+
The synchronous function to wrap.
|
| 19 |
+
obj : object, optional
|
| 20 |
+
The instance to bind the function to, if applicable.
|
| 21 |
+
semaphore : asyncio.Semaphore, optional
|
| 22 |
+
A semaphore to limit concurrent calls.
|
| 23 |
+
|
| 24 |
+
Returns
|
| 25 |
+
-------
|
| 26 |
+
coroutine
|
| 27 |
+
An awaitable version of the function.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
@functools.wraps(func)
|
| 31 |
+
async def wrapper(*args, **kwargs):
|
| 32 |
+
if semaphore:
|
| 33 |
+
async with semaphore:
|
| 34 |
+
return await asyncio.to_thread(func, *args, **kwargs)
|
| 35 |
+
return await asyncio.to_thread(func, *args, **kwargs)
|
| 36 |
+
|
| 37 |
+
return wrapper
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class AsyncFileSystemWrapper(AsyncFileSystem, ChainedFileSystem):
|
| 41 |
+
"""
|
| 42 |
+
A wrapper class to convert a synchronous filesystem into an asynchronous one.
|
| 43 |
+
|
| 44 |
+
This class takes an existing synchronous filesystem implementation and wraps all
|
| 45 |
+
its methods to provide an asynchronous interface.
|
| 46 |
+
|
| 47 |
+
Parameters
|
| 48 |
+
----------
|
| 49 |
+
sync_fs : AbstractFileSystem
|
| 50 |
+
The synchronous filesystem instance to wrap.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
protocol = "asyncwrapper", "async_wrapper"
|
| 54 |
+
cachable = False
|
| 55 |
+
|
| 56 |
+
def __init__(
|
| 57 |
+
self,
|
| 58 |
+
fs=None,
|
| 59 |
+
asynchronous=None,
|
| 60 |
+
target_protocol=None,
|
| 61 |
+
target_options=None,
|
| 62 |
+
semaphore=None,
|
| 63 |
+
max_concurrent_tasks=None,
|
| 64 |
+
**kwargs,
|
| 65 |
+
):
|
| 66 |
+
if asynchronous is None:
|
| 67 |
+
asynchronous = running_async()
|
| 68 |
+
super().__init__(asynchronous=asynchronous, **kwargs)
|
| 69 |
+
if fs is not None:
|
| 70 |
+
self.sync_fs = fs
|
| 71 |
+
else:
|
| 72 |
+
self.sync_fs = fsspec.filesystem(target_protocol, **target_options)
|
| 73 |
+
self.protocol = self.sync_fs.protocol
|
| 74 |
+
self.semaphore = semaphore
|
| 75 |
+
self._wrap_all_sync_methods()
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def fsid(self):
|
| 79 |
+
return f"async_{self.sync_fs.fsid}"
|
| 80 |
+
|
| 81 |
+
def _wrap_all_sync_methods(self):
|
| 82 |
+
"""
|
| 83 |
+
Wrap all synchronous methods of the underlying filesystem with asynchronous versions.
|
| 84 |
+
"""
|
| 85 |
+
excluded_methods = {"open"}
|
| 86 |
+
for method_name in dir(self.sync_fs):
|
| 87 |
+
if method_name.startswith("_") or method_name in excluded_methods:
|
| 88 |
+
continue
|
| 89 |
+
|
| 90 |
+
attr = inspect.getattr_static(self.sync_fs, method_name)
|
| 91 |
+
if isinstance(attr, property):
|
| 92 |
+
continue
|
| 93 |
+
|
| 94 |
+
method = getattr(self.sync_fs, method_name)
|
| 95 |
+
if callable(method) and not inspect.iscoroutinefunction(method):
|
| 96 |
+
async_method = async_wrapper(method, obj=self, semaphore=self.semaphore)
|
| 97 |
+
setattr(self, f"_{method_name}", async_method)
|
| 98 |
+
|
| 99 |
+
@classmethod
|
| 100 |
+
def wrap_class(cls, sync_fs_class):
|
| 101 |
+
"""
|
| 102 |
+
Create a new class that can be used to instantiate an AsyncFileSystemWrapper
|
| 103 |
+
with lazy instantiation of the underlying synchronous filesystem.
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
sync_fs_class : type
|
| 108 |
+
The class of the synchronous filesystem to wrap.
|
| 109 |
+
|
| 110 |
+
Returns
|
| 111 |
+
-------
|
| 112 |
+
type
|
| 113 |
+
A new class that wraps the provided synchronous filesystem class.
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
class GeneratedAsyncFileSystemWrapper(cls):
|
| 117 |
+
def __init__(self, *args, **kwargs):
|
| 118 |
+
sync_fs = sync_fs_class(*args, **kwargs)
|
| 119 |
+
super().__init__(sync_fs)
|
| 120 |
+
|
| 121 |
+
GeneratedAsyncFileSystemWrapper.__name__ = (
|
| 122 |
+
f"Async{sync_fs_class.__name__}Wrapper"
|
| 123 |
+
)
|
| 124 |
+
return GeneratedAsyncFileSystemWrapper
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/cache_mapper.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import abc
|
| 4 |
+
import hashlib
|
| 5 |
+
|
| 6 |
+
from fsspec.implementations.local import make_path_posix
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class AbstractCacheMapper(abc.ABC):
|
| 10 |
+
"""Abstract super-class for mappers from remote URLs to local cached
|
| 11 |
+
basenames.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
@abc.abstractmethod
|
| 15 |
+
def __call__(self, path: str) -> str: ...
|
| 16 |
+
|
| 17 |
+
def __eq__(self, other: object) -> bool:
|
| 18 |
+
# Identity only depends on class. When derived classes have attributes
|
| 19 |
+
# they will need to be included.
|
| 20 |
+
return isinstance(other, type(self))
|
| 21 |
+
|
| 22 |
+
def __hash__(self) -> int:
|
| 23 |
+
# Identity only depends on class. When derived classes have attributes
|
| 24 |
+
# they will need to be included.
|
| 25 |
+
return hash(type(self))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class BasenameCacheMapper(AbstractCacheMapper):
|
| 29 |
+
"""Cache mapper that uses the basename of the remote URL and a fixed number
|
| 30 |
+
of directory levels above this.
|
| 31 |
+
|
| 32 |
+
The default is zero directory levels, meaning different paths with the same
|
| 33 |
+
basename will have the same cached basename.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
def __init__(self, directory_levels: int = 0):
|
| 37 |
+
if directory_levels < 0:
|
| 38 |
+
raise ValueError(
|
| 39 |
+
"BasenameCacheMapper requires zero or positive directory_levels"
|
| 40 |
+
)
|
| 41 |
+
self.directory_levels = directory_levels
|
| 42 |
+
|
| 43 |
+
# Separator for directories when encoded as strings.
|
| 44 |
+
self._separator = "_@_"
|
| 45 |
+
|
| 46 |
+
def __call__(self, path: str) -> str:
|
| 47 |
+
path = make_path_posix(path)
|
| 48 |
+
prefix, *bits = path.rsplit("/", self.directory_levels + 1)
|
| 49 |
+
if bits:
|
| 50 |
+
return self._separator.join(bits)
|
| 51 |
+
else:
|
| 52 |
+
return prefix # No separator found, simple filename
|
| 53 |
+
|
| 54 |
+
def __eq__(self, other: object) -> bool:
|
| 55 |
+
return super().__eq__(other) and self.directory_levels == other.directory_levels
|
| 56 |
+
|
| 57 |
+
def __hash__(self) -> int:
|
| 58 |
+
return super().__hash__() ^ hash(self.directory_levels)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class HashCacheMapper(AbstractCacheMapper):
|
| 62 |
+
"""Cache mapper that uses a hash of the remote URL."""
|
| 63 |
+
|
| 64 |
+
def __call__(self, path: str) -> str:
|
| 65 |
+
return hashlib.sha256(path.encode()).hexdigest()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def create_cache_mapper(same_names: bool) -> AbstractCacheMapper:
|
| 69 |
+
"""Factory method to create cache mapper for backward compatibility with
|
| 70 |
+
``CachingFileSystem`` constructor using ``same_names`` kwarg.
|
| 71 |
+
"""
|
| 72 |
+
if same_names:
|
| 73 |
+
return BasenameCacheMapper()
|
| 74 |
+
else:
|
| 75 |
+
return HashCacheMapper()
|
workspace/outputs/audit_venv/lib/python3.11/site-packages/fsspec/implementations/cache_metadata.py
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
from typing import TYPE_CHECKING
|
| 6 |
+
|
| 7 |
+
from fsspec.utils import atomic_write
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
import ujson as json
|
| 11 |
+
except ImportError:
|
| 12 |
+
if not TYPE_CHECKING:
|
| 13 |
+
import json
|
| 14 |
+
|
| 15 |
+
if TYPE_CHECKING:
|
| 16 |
+
from collections.abc import Iterator
|
| 17 |
+
from typing import Any, Literal, TypeAlias
|
| 18 |
+
|
| 19 |
+
from .cached import CachingFileSystem
|
| 20 |
+
|
| 21 |
+
Detail: TypeAlias = dict[str, Any]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class CacheMetadata:
|
| 25 |
+
"""Cache metadata.
|
| 26 |
+
|
| 27 |
+
All reading and writing of cache metadata is performed by this class,
|
| 28 |
+
accessing the cached files and blocks is not.
|
| 29 |
+
|
| 30 |
+
Metadata is stored in a single file per storage directory in JSON format.
|
| 31 |
+
For backward compatibility. No longer supports pickle.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
def __init__(self, storage: list[str]):
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
Parameters
|
| 38 |
+
----------
|
| 39 |
+
storage: list[str]
|
| 40 |
+
Directories containing cached files, must be at least one. Metadata
|
| 41 |
+
is stored in the last of these directories by convention.
|
| 42 |
+
"""
|
| 43 |
+
if not storage:
|
| 44 |
+
raise ValueError("CacheMetadata expects at least one storage location")
|
| 45 |
+
|
| 46 |
+
self._storage = storage
|
| 47 |
+
self.cached_files: list[Detail] = [{}]
|
| 48 |
+
|
| 49 |
+
def _load(self, fn: str) -> Detail:
|
| 50 |
+
"""Low-level function to load metadata from specific file"""
|
| 51 |
+
with open(fn, "r") as f:
|
| 52 |
+
loaded = json.load(f)
|
| 53 |
+
for c in loaded.values():
|
| 54 |
+
if isinstance(c.get("blocks"), list):
|
| 55 |
+
c["blocks"] = set(c["blocks"])
|
| 56 |
+
return loaded
|
| 57 |
+
|
| 58 |
+
def _save(self, metadata_to_save: Detail, fn: str) -> None:
|
| 59 |
+
"""Low-level function to save metadata to specific file"""
|
| 60 |
+
with atomic_write(fn, mode="w") as f:
|
| 61 |
+
json.dump(metadata_to_save, f)
|
| 62 |
+
|
| 63 |
+
def _scan_locations(
|
| 64 |
+
self, writable_only: bool = False
|
| 65 |
+
) -> Iterator[tuple[str, str, bool]]:
|
| 66 |
+
"""Yield locations (filenames) where metadata is stored, and whether
|
| 67 |
+
writable or not.
|
| 68 |
+
|
| 69 |
+
Parameters
|
| 70 |
+
----------
|
| 71 |
+
writable: bool
|
| 72 |
+
Set to True to only yield writable locations.
|
| 73 |
+
|
| 74 |
+
Returns
|
| 75 |
+
-------
|
| 76 |
+
Yields (str, str, bool)
|
| 77 |
+
"""
|
| 78 |
+
n = len(self._storage)
|
| 79 |
+
for i, storage in enumerate(self._storage):
|
| 80 |
+
writable = i == n - 1
|
| 81 |
+
if writable_only and not writable:
|
| 82 |
+
continue
|
| 83 |
+
yield os.path.join(storage, "cache"), storage, writable
|
| 84 |
+
|
| 85 |
+
def check_file(
|
| 86 |
+
self, path: str, cfs: CachingFileSystem | None
|
| 87 |
+
) -> Literal[False] | tuple[Detail, str]:
|
| 88 |
+
"""If path is in cache return its details, otherwise return ``False``.
|
| 89 |
+
|
| 90 |
+
If the optional CachingFileSystem is specified then it is used to
|
| 91 |
+
perform extra checks to reject possible matches, such as if they are
|
| 92 |
+
too old.
|
| 93 |
+
"""
|
| 94 |
+
for (fn, base, _), cache in zip(self._scan_locations(), self.cached_files):
|
| 95 |
+
if path not in cache:
|
| 96 |
+
continue
|
| 97 |
+
detail = cache[path].copy()
|
| 98 |
+
|
| 99 |
+
if cfs is not None:
|
| 100 |
+
if cfs.check_files and detail["uid"] != cfs.fs.ukey(path):
|
| 101 |
+
# Wrong file as determined by hash of file properties
|
| 102 |
+
continue
|
| 103 |
+
if cfs.expiry and time.time() - detail["time"] > cfs.expiry:
|
| 104 |
+
# Cached file has expired
|
| 105 |
+
continue
|
| 106 |
+
|
| 107 |
+
fn = os.path.join(base, detail["fn"])
|
| 108 |
+
if os.path.exists(fn):
|
| 109 |
+
return detail, fn
|
| 110 |
+
return False
|
| 111 |
+
|
| 112 |
+
def clear_expired(self, expiry_time: int) -> tuple[list[str], bool]:
|
| 113 |
+
"""Remove expired metadata from the cache.
|
| 114 |
+
|
| 115 |
+
Returns names of files corresponding to expired metadata and a boolean
|
| 116 |
+
flag indicating whether the writable cache is empty. Caller is
|
| 117 |
+
responsible for deleting the expired files.
|
| 118 |
+
"""
|
| 119 |
+
expired_files = []
|
| 120 |
+
for path, detail in self.cached_files[-1].copy().items():
|
| 121 |
+
if time.time() - detail["time"] > expiry_time:
|
| 122 |
+
fn = detail.get("fn", "")
|
| 123 |
+
if not fn:
|
| 124 |
+
raise RuntimeError(
|
| 125 |
+
f"Cache metadata does not contain 'fn' for {path}"
|
| 126 |
+
)
|
| 127 |
+
fn = os.path.join(self._storage[-1], fn)
|
| 128 |
+
expired_files.append(fn)
|
| 129 |
+
self.cached_files[-1].pop(path)
|
| 130 |
+
|
| 131 |
+
if self.cached_files[-1]:
|
| 132 |
+
cache_path = os.path.join(self._storage[-1], "cache")
|
| 133 |
+
self._save(self.cached_files[-1], cache_path)
|
| 134 |
+
|
| 135 |
+
writable_cache_empty = not self.cached_files[-1]
|
| 136 |
+
return expired_files, writable_cache_empty
|
| 137 |
+
|
| 138 |
+
def load(self) -> None:
|
| 139 |
+
"""Load all metadata from disk and store in ``self.cached_files``"""
|
| 140 |
+
cached_files = []
|
| 141 |
+
for fn, _, _ in self._scan_locations():
|
| 142 |
+
if os.path.exists(fn):
|
| 143 |
+
# TODO: consolidate blocks here
|
| 144 |
+
cached_files.append(self._load(fn))
|
| 145 |
+
else:
|
| 146 |
+
cached_files.append({})
|
| 147 |
+
self.cached_files = cached_files or [{}]
|
| 148 |
+
|
| 149 |
+
def on_close_cached_file(self, f: Any, path: str) -> None:
|
| 150 |
+
"""Perform side-effect actions on closing a cached file.
|
| 151 |
+
|
| 152 |
+
The actual closing of the file is the responsibility of the caller.
|
| 153 |
+
"""
|
| 154 |
+
# File must be writable, so in self.cached_files[-1]
|
| 155 |
+
c = self.cached_files[-1][path]
|
| 156 |
+
if c["blocks"] is not True and len(c["blocks"]) * f.blocksize >= f.size:
|
| 157 |
+
c["blocks"] = True
|
| 158 |
+
|
| 159 |
+
def pop_file(self, path: str) -> str | None:
|
| 160 |
+
"""Remove metadata of cached file.
|
| 161 |
+
|
| 162 |
+
If path is in the cache, return the filename of the cached file,
|
| 163 |
+
otherwise return ``None``. Caller is responsible for deleting the
|
| 164 |
+
cached file.
|
| 165 |
+
"""
|
| 166 |
+
details = self.check_file(path, None)
|
| 167 |
+
if not details:
|
| 168 |
+
return None
|
| 169 |
+
_, fn = details
|
| 170 |
+
if fn.startswith(self._storage[-1]):
|
| 171 |
+
self.cached_files[-1].pop(path)
|
| 172 |
+
self.save()
|
| 173 |
+
else:
|
| 174 |
+
raise PermissionError(
|
| 175 |
+
"Can only delete cached file in last, writable cache location"
|
| 176 |
+
)
|
| 177 |
+
return fn
|
| 178 |
+
|
| 179 |
+
def save(self) -> None:
|
| 180 |
+
"""Save metadata to disk"""
|
| 181 |
+
for (fn, _, writable), cache in zip(self._scan_locations(), self.cached_files):
|
| 182 |
+
if not writable:
|
| 183 |
+
continue
|
| 184 |
+
|
| 185 |
+
if os.path.exists(fn):
|
| 186 |
+
cached_files = self._load(fn)
|
| 187 |
+
for k, c in cached_files.items():
|
| 188 |
+
if k in cache:
|
| 189 |
+
if c["blocks"] is True or cache[k]["blocks"] is True:
|
| 190 |
+
c["blocks"] = True
|
| 191 |
+
else:
|
| 192 |
+
# self.cached_files[*][*]["blocks"] must continue to
|
| 193 |
+
# point to the same set object so that updates
|
| 194 |
+
# performed by MMapCache are propagated back to
|
| 195 |
+
# self.cached_files.
|
| 196 |
+
blocks = cache[k]["blocks"]
|
| 197 |
+
blocks.update(c["blocks"])
|
| 198 |
+
c["blocks"] = blocks
|
| 199 |
+
c["time"] = max(c["time"], cache[k]["time"])
|
| 200 |
+
c["uid"] = cache[k]["uid"]
|
| 201 |
+
|
| 202 |
+
# Files can be added to cache after it was written once
|
| 203 |
+
for k, c in cache.items():
|
| 204 |
+
if k not in cached_files:
|
| 205 |
+
cached_files[k] = c
|
| 206 |
+
else:
|
| 207 |
+
cached_files = cache
|
| 208 |
+
cache = {k: v.copy() for k, v in cached_files.items()}
|
| 209 |
+
for c in cache.values():
|
| 210 |
+
if isinstance(c["blocks"], set):
|
| 211 |
+
c["blocks"] = list(c["blocks"])
|
| 212 |
+
self._save(cache, fn)
|
| 213 |
+
self.cached_files[-1] = cached_files
|
| 214 |
+
|
| 215 |
+
def update_file(self, path: str, detail: Detail) -> None:
|
| 216 |
+
"""Update metadata for specific file in memory, do not save"""
|
| 217 |
+
self.cached_files[-1][path] = detail
|