fonttools 4.60.2__cp311-cp311-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. fontTools/__init__.py +8 -0
  2. fontTools/__main__.py +35 -0
  3. fontTools/afmLib.py +439 -0
  4. fontTools/agl.py +5233 -0
  5. fontTools/annotations.py +30 -0
  6. fontTools/cffLib/CFF2ToCFF.py +258 -0
  7. fontTools/cffLib/CFFToCFF2.py +305 -0
  8. fontTools/cffLib/__init__.py +3694 -0
  9. fontTools/cffLib/specializer.py +927 -0
  10. fontTools/cffLib/transforms.py +495 -0
  11. fontTools/cffLib/width.py +210 -0
  12. fontTools/colorLib/__init__.py +0 -0
  13. fontTools/colorLib/builder.py +664 -0
  14. fontTools/colorLib/errors.py +2 -0
  15. fontTools/colorLib/geometry.py +143 -0
  16. fontTools/colorLib/table_builder.py +223 -0
  17. fontTools/colorLib/unbuilder.py +81 -0
  18. fontTools/config/__init__.py +90 -0
  19. fontTools/cu2qu/__init__.py +15 -0
  20. fontTools/cu2qu/__main__.py +6 -0
  21. fontTools/cu2qu/benchmark.py +54 -0
  22. fontTools/cu2qu/cli.py +198 -0
  23. fontTools/cu2qu/cu2qu.c +15817 -0
  24. fontTools/cu2qu/cu2qu.cp311-win32.pyd +0 -0
  25. fontTools/cu2qu/cu2qu.py +563 -0
  26. fontTools/cu2qu/errors.py +77 -0
  27. fontTools/cu2qu/ufo.py +363 -0
  28. fontTools/designspaceLib/__init__.py +3343 -0
  29. fontTools/designspaceLib/__main__.py +6 -0
  30. fontTools/designspaceLib/split.py +475 -0
  31. fontTools/designspaceLib/statNames.py +260 -0
  32. fontTools/designspaceLib/types.py +147 -0
  33. fontTools/encodings/MacRoman.py +258 -0
  34. fontTools/encodings/StandardEncoding.py +258 -0
  35. fontTools/encodings/__init__.py +1 -0
  36. fontTools/encodings/codecs.py +135 -0
  37. fontTools/feaLib/__init__.py +4 -0
  38. fontTools/feaLib/__main__.py +78 -0
  39. fontTools/feaLib/ast.py +2143 -0
  40. fontTools/feaLib/builder.py +1814 -0
  41. fontTools/feaLib/error.py +22 -0
  42. fontTools/feaLib/lexer.c +17029 -0
  43. fontTools/feaLib/lexer.cp311-win32.pyd +0 -0
  44. fontTools/feaLib/lexer.py +287 -0
  45. fontTools/feaLib/location.py +12 -0
  46. fontTools/feaLib/lookupDebugInfo.py +12 -0
  47. fontTools/feaLib/parser.py +2394 -0
  48. fontTools/feaLib/variableScalar.py +118 -0
  49. fontTools/fontBuilder.py +1014 -0
  50. fontTools/help.py +36 -0
  51. fontTools/merge/__init__.py +248 -0
  52. fontTools/merge/__main__.py +6 -0
  53. fontTools/merge/base.py +81 -0
  54. fontTools/merge/cmap.py +173 -0
  55. fontTools/merge/layout.py +526 -0
  56. fontTools/merge/options.py +85 -0
  57. fontTools/merge/tables.py +352 -0
  58. fontTools/merge/unicode.py +78 -0
  59. fontTools/merge/util.py +143 -0
  60. fontTools/misc/__init__.py +1 -0
  61. fontTools/misc/arrayTools.py +424 -0
  62. fontTools/misc/bezierTools.c +39731 -0
  63. fontTools/misc/bezierTools.cp311-win32.pyd +0 -0
  64. fontTools/misc/bezierTools.py +1500 -0
  65. fontTools/misc/classifyTools.py +170 -0
  66. fontTools/misc/cliTools.py +53 -0
  67. fontTools/misc/configTools.py +349 -0
  68. fontTools/misc/cython.py +27 -0
  69. fontTools/misc/dictTools.py +83 -0
  70. fontTools/misc/eexec.py +119 -0
  71. fontTools/misc/encodingTools.py +72 -0
  72. fontTools/misc/enumTools.py +23 -0
  73. fontTools/misc/etree.py +456 -0
  74. fontTools/misc/filenames.py +245 -0
  75. fontTools/misc/filesystem/__init__.py +68 -0
  76. fontTools/misc/filesystem/_base.py +134 -0
  77. fontTools/misc/filesystem/_copy.py +45 -0
  78. fontTools/misc/filesystem/_errors.py +54 -0
  79. fontTools/misc/filesystem/_info.py +75 -0
  80. fontTools/misc/filesystem/_osfs.py +164 -0
  81. fontTools/misc/filesystem/_path.py +67 -0
  82. fontTools/misc/filesystem/_subfs.py +92 -0
  83. fontTools/misc/filesystem/_tempfs.py +34 -0
  84. fontTools/misc/filesystem/_tools.py +34 -0
  85. fontTools/misc/filesystem/_walk.py +55 -0
  86. fontTools/misc/filesystem/_zipfs.py +204 -0
  87. fontTools/misc/fixedTools.py +253 -0
  88. fontTools/misc/intTools.py +25 -0
  89. fontTools/misc/iterTools.py +12 -0
  90. fontTools/misc/lazyTools.py +42 -0
  91. fontTools/misc/loggingTools.py +543 -0
  92. fontTools/misc/macCreatorType.py +56 -0
  93. fontTools/misc/macRes.py +261 -0
  94. fontTools/misc/plistlib/__init__.py +681 -0
  95. fontTools/misc/plistlib/py.typed +0 -0
  96. fontTools/misc/psCharStrings.py +1511 -0
  97. fontTools/misc/psLib.py +398 -0
  98. fontTools/misc/psOperators.py +572 -0
  99. fontTools/misc/py23.py +96 -0
  100. fontTools/misc/roundTools.py +110 -0
  101. fontTools/misc/sstruct.py +227 -0
  102. fontTools/misc/symfont.py +242 -0
  103. fontTools/misc/testTools.py +233 -0
  104. fontTools/misc/textTools.py +156 -0
  105. fontTools/misc/timeTools.py +88 -0
  106. fontTools/misc/transform.py +516 -0
  107. fontTools/misc/treeTools.py +45 -0
  108. fontTools/misc/vector.py +147 -0
  109. fontTools/misc/visitor.py +158 -0
  110. fontTools/misc/xmlReader.py +188 -0
  111. fontTools/misc/xmlWriter.py +231 -0
  112. fontTools/mtiLib/__init__.py +1400 -0
  113. fontTools/mtiLib/__main__.py +5 -0
  114. fontTools/otlLib/__init__.py +1 -0
  115. fontTools/otlLib/builder.py +3465 -0
  116. fontTools/otlLib/error.py +11 -0
  117. fontTools/otlLib/maxContextCalc.py +96 -0
  118. fontTools/otlLib/optimize/__init__.py +53 -0
  119. fontTools/otlLib/optimize/__main__.py +6 -0
  120. fontTools/otlLib/optimize/gpos.py +439 -0
  121. fontTools/pens/__init__.py +1 -0
  122. fontTools/pens/areaPen.py +52 -0
  123. fontTools/pens/basePen.py +475 -0
  124. fontTools/pens/boundsPen.py +98 -0
  125. fontTools/pens/cairoPen.py +26 -0
  126. fontTools/pens/cocoaPen.py +26 -0
  127. fontTools/pens/cu2quPen.py +325 -0
  128. fontTools/pens/explicitClosingLinePen.py +101 -0
  129. fontTools/pens/filterPen.py +433 -0
  130. fontTools/pens/freetypePen.py +462 -0
  131. fontTools/pens/hashPointPen.py +89 -0
  132. fontTools/pens/momentsPen.c +13378 -0
  133. fontTools/pens/momentsPen.cp311-win32.pyd +0 -0
  134. fontTools/pens/momentsPen.py +879 -0
  135. fontTools/pens/perimeterPen.py +69 -0
  136. fontTools/pens/pointInsidePen.py +192 -0
  137. fontTools/pens/pointPen.py +643 -0
  138. fontTools/pens/qtPen.py +29 -0
  139. fontTools/pens/qu2cuPen.py +105 -0
  140. fontTools/pens/quartzPen.py +43 -0
  141. fontTools/pens/recordingPen.py +335 -0
  142. fontTools/pens/reportLabPen.py +79 -0
  143. fontTools/pens/reverseContourPen.py +96 -0
  144. fontTools/pens/roundingPen.py +130 -0
  145. fontTools/pens/statisticsPen.py +312 -0
  146. fontTools/pens/svgPathPen.py +310 -0
  147. fontTools/pens/t2CharStringPen.py +88 -0
  148. fontTools/pens/teePen.py +55 -0
  149. fontTools/pens/transformPen.py +115 -0
  150. fontTools/pens/ttGlyphPen.py +335 -0
  151. fontTools/pens/wxPen.py +29 -0
  152. fontTools/qu2cu/__init__.py +15 -0
  153. fontTools/qu2cu/__main__.py +7 -0
  154. fontTools/qu2cu/benchmark.py +56 -0
  155. fontTools/qu2cu/cli.py +125 -0
  156. fontTools/qu2cu/qu2cu.c +16682 -0
  157. fontTools/qu2cu/qu2cu.cp311-win32.pyd +0 -0
  158. fontTools/qu2cu/qu2cu.py +405 -0
  159. fontTools/subset/__init__.py +4096 -0
  160. fontTools/subset/__main__.py +6 -0
  161. fontTools/subset/cff.py +184 -0
  162. fontTools/subset/svg.py +253 -0
  163. fontTools/subset/util.py +25 -0
  164. fontTools/svgLib/__init__.py +3 -0
  165. fontTools/svgLib/path/__init__.py +65 -0
  166. fontTools/svgLib/path/arc.py +154 -0
  167. fontTools/svgLib/path/parser.py +322 -0
  168. fontTools/svgLib/path/shapes.py +183 -0
  169. fontTools/t1Lib/__init__.py +648 -0
  170. fontTools/tfmLib.py +460 -0
  171. fontTools/ttLib/__init__.py +30 -0
  172. fontTools/ttLib/__main__.py +148 -0
  173. fontTools/ttLib/macUtils.py +54 -0
  174. fontTools/ttLib/removeOverlaps.py +395 -0
  175. fontTools/ttLib/reorderGlyphs.py +285 -0
  176. fontTools/ttLib/scaleUpem.py +436 -0
  177. fontTools/ttLib/sfnt.py +661 -0
  178. fontTools/ttLib/standardGlyphOrder.py +271 -0
  179. fontTools/ttLib/tables/B_A_S_E_.py +14 -0
  180. fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
  181. fontTools/ttLib/tables/C_B_D_T_.py +113 -0
  182. fontTools/ttLib/tables/C_B_L_C_.py +19 -0
  183. fontTools/ttLib/tables/C_F_F_.py +61 -0
  184. fontTools/ttLib/tables/C_F_F__2.py +26 -0
  185. fontTools/ttLib/tables/C_O_L_R_.py +165 -0
  186. fontTools/ttLib/tables/C_P_A_L_.py +305 -0
  187. fontTools/ttLib/tables/D_S_I_G_.py +158 -0
  188. fontTools/ttLib/tables/D__e_b_g.py +35 -0
  189. fontTools/ttLib/tables/DefaultTable.py +49 -0
  190. fontTools/ttLib/tables/E_B_D_T_.py +835 -0
  191. fontTools/ttLib/tables/E_B_L_C_.py +718 -0
  192. fontTools/ttLib/tables/F_F_T_M_.py +52 -0
  193. fontTools/ttLib/tables/F__e_a_t.py +149 -0
  194. fontTools/ttLib/tables/G_D_E_F_.py +13 -0
  195. fontTools/ttLib/tables/G_M_A_P_.py +148 -0
  196. fontTools/ttLib/tables/G_P_K_G_.py +133 -0
  197. fontTools/ttLib/tables/G_P_O_S_.py +14 -0
  198. fontTools/ttLib/tables/G_S_U_B_.py +13 -0
  199. fontTools/ttLib/tables/G_V_A_R_.py +5 -0
  200. fontTools/ttLib/tables/G__l_a_t.py +235 -0
  201. fontTools/ttLib/tables/G__l_o_c.py +85 -0
  202. fontTools/ttLib/tables/H_V_A_R_.py +13 -0
  203. fontTools/ttLib/tables/J_S_T_F_.py +13 -0
  204. fontTools/ttLib/tables/L_T_S_H_.py +58 -0
  205. fontTools/ttLib/tables/M_A_T_H_.py +13 -0
  206. fontTools/ttLib/tables/M_E_T_A_.py +352 -0
  207. fontTools/ttLib/tables/M_V_A_R_.py +13 -0
  208. fontTools/ttLib/tables/O_S_2f_2.py +752 -0
  209. fontTools/ttLib/tables/S_I_N_G_.py +99 -0
  210. fontTools/ttLib/tables/S_T_A_T_.py +15 -0
  211. fontTools/ttLib/tables/S_V_G_.py +223 -0
  212. fontTools/ttLib/tables/S__i_l_f.py +1040 -0
  213. fontTools/ttLib/tables/S__i_l_l.py +92 -0
  214. fontTools/ttLib/tables/T_S_I_B_.py +13 -0
  215. fontTools/ttLib/tables/T_S_I_C_.py +14 -0
  216. fontTools/ttLib/tables/T_S_I_D_.py +13 -0
  217. fontTools/ttLib/tables/T_S_I_J_.py +13 -0
  218. fontTools/ttLib/tables/T_S_I_P_.py +13 -0
  219. fontTools/ttLib/tables/T_S_I_S_.py +13 -0
  220. fontTools/ttLib/tables/T_S_I_V_.py +26 -0
  221. fontTools/ttLib/tables/T_S_I__0.py +70 -0
  222. fontTools/ttLib/tables/T_S_I__1.py +163 -0
  223. fontTools/ttLib/tables/T_S_I__2.py +17 -0
  224. fontTools/ttLib/tables/T_S_I__3.py +22 -0
  225. fontTools/ttLib/tables/T_S_I__5.py +60 -0
  226. fontTools/ttLib/tables/T_T_F_A_.py +14 -0
  227. fontTools/ttLib/tables/TupleVariation.py +884 -0
  228. fontTools/ttLib/tables/V_A_R_C_.py +12 -0
  229. fontTools/ttLib/tables/V_D_M_X_.py +249 -0
  230. fontTools/ttLib/tables/V_O_R_G_.py +165 -0
  231. fontTools/ttLib/tables/V_V_A_R_.py +13 -0
  232. fontTools/ttLib/tables/__init__.py +98 -0
  233. fontTools/ttLib/tables/_a_n_k_r.py +15 -0
  234. fontTools/ttLib/tables/_a_v_a_r.py +193 -0
  235. fontTools/ttLib/tables/_b_s_l_n.py +15 -0
  236. fontTools/ttLib/tables/_c_i_d_g.py +24 -0
  237. fontTools/ttLib/tables/_c_m_a_p.py +1591 -0
  238. fontTools/ttLib/tables/_c_v_a_r.py +94 -0
  239. fontTools/ttLib/tables/_c_v_t.py +56 -0
  240. fontTools/ttLib/tables/_f_e_a_t.py +15 -0
  241. fontTools/ttLib/tables/_f_p_g_m.py +62 -0
  242. fontTools/ttLib/tables/_f_v_a_r.py +261 -0
  243. fontTools/ttLib/tables/_g_a_s_p.py +63 -0
  244. fontTools/ttLib/tables/_g_c_i_d.py +13 -0
  245. fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
  246. fontTools/ttLib/tables/_g_v_a_r.py +340 -0
  247. fontTools/ttLib/tables/_h_d_m_x.py +127 -0
  248. fontTools/ttLib/tables/_h_e_a_d.py +130 -0
  249. fontTools/ttLib/tables/_h_h_e_a.py +147 -0
  250. fontTools/ttLib/tables/_h_m_t_x.py +164 -0
  251. fontTools/ttLib/tables/_k_e_r_n.py +289 -0
  252. fontTools/ttLib/tables/_l_c_a_r.py +13 -0
  253. fontTools/ttLib/tables/_l_o_c_a.py +70 -0
  254. fontTools/ttLib/tables/_l_t_a_g.py +72 -0
  255. fontTools/ttLib/tables/_m_a_x_p.py +147 -0
  256. fontTools/ttLib/tables/_m_e_t_a.py +112 -0
  257. fontTools/ttLib/tables/_m_o_r_t.py +14 -0
  258. fontTools/ttLib/tables/_m_o_r_x.py +15 -0
  259. fontTools/ttLib/tables/_n_a_m_e.py +1242 -0
  260. fontTools/ttLib/tables/_o_p_b_d.py +14 -0
  261. fontTools/ttLib/tables/_p_o_s_t.py +319 -0
  262. fontTools/ttLib/tables/_p_r_e_p.py +16 -0
  263. fontTools/ttLib/tables/_p_r_o_p.py +12 -0
  264. fontTools/ttLib/tables/_s_b_i_x.py +129 -0
  265. fontTools/ttLib/tables/_t_r_a_k.py +332 -0
  266. fontTools/ttLib/tables/_v_h_e_a.py +139 -0
  267. fontTools/ttLib/tables/_v_m_t_x.py +19 -0
  268. fontTools/ttLib/tables/asciiTable.py +20 -0
  269. fontTools/ttLib/tables/grUtils.py +92 -0
  270. fontTools/ttLib/tables/otBase.py +1458 -0
  271. fontTools/ttLib/tables/otConverters.py +2068 -0
  272. fontTools/ttLib/tables/otData.py +6400 -0
  273. fontTools/ttLib/tables/otTables.py +2703 -0
  274. fontTools/ttLib/tables/otTraverse.py +163 -0
  275. fontTools/ttLib/tables/sbixGlyph.py +149 -0
  276. fontTools/ttLib/tables/sbixStrike.py +177 -0
  277. fontTools/ttLib/tables/table_API_readme.txt +91 -0
  278. fontTools/ttLib/tables/ttProgram.py +594 -0
  279. fontTools/ttLib/ttCollection.py +125 -0
  280. fontTools/ttLib/ttFont.py +1148 -0
  281. fontTools/ttLib/ttGlyphSet.py +490 -0
  282. fontTools/ttLib/ttVisitor.py +32 -0
  283. fontTools/ttLib/woff2.py +1680 -0
  284. fontTools/ttx.py +479 -0
  285. fontTools/ufoLib/__init__.py +2575 -0
  286. fontTools/ufoLib/converters.py +407 -0
  287. fontTools/ufoLib/errors.py +30 -0
  288. fontTools/ufoLib/etree.py +6 -0
  289. fontTools/ufoLib/filenames.py +356 -0
  290. fontTools/ufoLib/glifLib.py +2120 -0
  291. fontTools/ufoLib/kerning.py +141 -0
  292. fontTools/ufoLib/plistlib.py +47 -0
  293. fontTools/ufoLib/pointPen.py +6 -0
  294. fontTools/ufoLib/utils.py +107 -0
  295. fontTools/ufoLib/validators.py +1208 -0
  296. fontTools/unicode.py +50 -0
  297. fontTools/unicodedata/Blocks.py +817 -0
  298. fontTools/unicodedata/Mirrored.py +446 -0
  299. fontTools/unicodedata/OTTags.py +50 -0
  300. fontTools/unicodedata/ScriptExtensions.py +832 -0
  301. fontTools/unicodedata/Scripts.py +3639 -0
  302. fontTools/unicodedata/__init__.py +306 -0
  303. fontTools/varLib/__init__.py +1600 -0
  304. fontTools/varLib/__main__.py +6 -0
  305. fontTools/varLib/avar/__init__.py +0 -0
  306. fontTools/varLib/avar/__main__.py +72 -0
  307. fontTools/varLib/avar/build.py +79 -0
  308. fontTools/varLib/avar/map.py +108 -0
  309. fontTools/varLib/avar/plan.py +1004 -0
  310. fontTools/varLib/avar/unbuild.py +271 -0
  311. fontTools/varLib/avarPlanner.py +8 -0
  312. fontTools/varLib/builder.py +215 -0
  313. fontTools/varLib/cff.py +631 -0
  314. fontTools/varLib/errors.py +219 -0
  315. fontTools/varLib/featureVars.py +703 -0
  316. fontTools/varLib/hvar.py +113 -0
  317. fontTools/varLib/instancer/__init__.py +2052 -0
  318. fontTools/varLib/instancer/__main__.py +5 -0
  319. fontTools/varLib/instancer/featureVars.py +190 -0
  320. fontTools/varLib/instancer/names.py +388 -0
  321. fontTools/varLib/instancer/solver.py +309 -0
  322. fontTools/varLib/interpolatable.py +1209 -0
  323. fontTools/varLib/interpolatableHelpers.py +399 -0
  324. fontTools/varLib/interpolatablePlot.py +1269 -0
  325. fontTools/varLib/interpolatableTestContourOrder.py +82 -0
  326. fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
  327. fontTools/varLib/interpolate_layout.py +124 -0
  328. fontTools/varLib/iup.c +19815 -0
  329. fontTools/varLib/iup.cp311-win32.pyd +0 -0
  330. fontTools/varLib/iup.py +490 -0
  331. fontTools/varLib/merger.py +1717 -0
  332. fontTools/varLib/models.py +642 -0
  333. fontTools/varLib/multiVarStore.py +253 -0
  334. fontTools/varLib/mutator.py +529 -0
  335. fontTools/varLib/mvar.py +40 -0
  336. fontTools/varLib/plot.py +238 -0
  337. fontTools/varLib/stat.py +149 -0
  338. fontTools/varLib/varStore.py +739 -0
  339. fontTools/voltLib/__init__.py +5 -0
  340. fontTools/voltLib/__main__.py +206 -0
  341. fontTools/voltLib/ast.py +452 -0
  342. fontTools/voltLib/error.py +12 -0
  343. fontTools/voltLib/lexer.py +99 -0
  344. fontTools/voltLib/parser.py +664 -0
  345. fontTools/voltLib/voltToFea.py +911 -0
  346. fonttools-4.60.2.data/data/share/man/man1/ttx.1 +225 -0
  347. fonttools-4.60.2.dist-info/METADATA +2250 -0
  348. fonttools-4.60.2.dist-info/RECORD +353 -0
  349. fonttools-4.60.2.dist-info/WHEEL +5 -0
  350. fonttools-4.60.2.dist-info/entry_points.txt +5 -0
  351. fonttools-4.60.2.dist-info/licenses/LICENSE +21 -0
  352. fonttools-4.60.2.dist-info/licenses/LICENSE.external +388 -0
  353. fonttools-4.60.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,681 @@
1
+ import collections.abc
2
+ import re
3
+ from typing import (
4
+ Any,
5
+ Callable,
6
+ Dict,
7
+ List,
8
+ Mapping,
9
+ MutableMapping,
10
+ Optional,
11
+ Sequence,
12
+ Type,
13
+ Union,
14
+ IO,
15
+ )
16
+ import warnings
17
+ from io import BytesIO
18
+ from datetime import datetime
19
+ from base64 import b64encode, b64decode
20
+ from numbers import Integral
21
+ from types import SimpleNamespace
22
+ from functools import singledispatch
23
+
24
+ from fontTools.misc import etree
25
+
26
+ from fontTools.misc.textTools import tostr
27
+
28
+
29
+ # By default, we
30
+ # - deserialize <data> elements as bytes and
31
+ # - serialize bytes as <data> elements.
32
+ # Before, on Python 2, we
33
+ # - deserialized <data> elements as plistlib.Data objects, in order to
34
+ # distinguish them from the built-in str type (which is bytes on python2)
35
+ # - serialized bytes as <string> elements (they must have only contained
36
+ # ASCII characters in this case)
37
+ # You can pass use_builtin_types=[True|False] to the load/dump etc. functions
38
+ # to enforce a specific treatment.
39
+ # NOTE that unicode type always maps to <string> element, and plistlib.Data
40
+ # always maps to <data> element, regardless of use_builtin_types.
41
+ USE_BUILTIN_TYPES = True
42
+
43
+ XML_DECLARATION = b"""<?xml version='1.0' encoding='UTF-8'?>"""
44
+
45
+ PLIST_DOCTYPE = (
46
+ b'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '
47
+ b'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
48
+ )
49
+
50
+
51
+ # Date should conform to a subset of ISO 8601:
52
+ # YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'
53
+ _date_parser = re.compile(
54
+ r"(?P<year>\d\d\d\d)"
55
+ r"(?:-(?P<month>\d\d)"
56
+ r"(?:-(?P<day>\d\d)"
57
+ r"(?:T(?P<hour>\d\d)"
58
+ r"(?::(?P<minute>\d\d)"
59
+ r"(?::(?P<second>\d\d))"
60
+ r"?)?)?)?)?Z",
61
+ re.ASCII,
62
+ )
63
+
64
+
65
+ def _date_from_string(s: str) -> datetime:
66
+ order = ("year", "month", "day", "hour", "minute", "second")
67
+ m = _date_parser.match(s)
68
+ if m is None:
69
+ raise ValueError(f"Expected ISO 8601 date string, but got '{s:r}'.")
70
+ gd = m.groupdict()
71
+ lst = []
72
+ for key in order:
73
+ val = gd[key]
74
+ if val is None:
75
+ break
76
+ lst.append(int(val))
77
+ # NOTE: mypy doesn't know that lst is 6 elements long.
78
+ return datetime(*lst) # type:ignore
79
+
80
+
81
+ def _date_to_string(d: datetime) -> str:
82
+ return "%04d-%02d-%02dT%02d:%02d:%02dZ" % (
83
+ d.year,
84
+ d.month,
85
+ d.day,
86
+ d.hour,
87
+ d.minute,
88
+ d.second,
89
+ )
90
+
91
+
92
+ class Data:
93
+ """Represents binary data when ``use_builtin_types=False.``
94
+
95
+ This class wraps binary data loaded from a plist file when the
96
+ ``use_builtin_types`` argument to the loading function (:py:func:`fromtree`,
97
+ :py:func:`load`, :py:func:`loads`) is false.
98
+
99
+ The actual binary data is retrieved using the ``data`` attribute.
100
+ """
101
+
102
+ def __init__(self, data: bytes) -> None:
103
+ if not isinstance(data, bytes):
104
+ raise TypeError("Expected bytes, found %s" % type(data).__name__)
105
+ self.data = data
106
+
107
+ @classmethod
108
+ def fromBase64(cls, data: Union[bytes, str]) -> "Data":
109
+ return cls(b64decode(data))
110
+
111
+ def asBase64(self, maxlinelength: int = 76, indent_level: int = 1) -> bytes:
112
+ return _encode_base64(
113
+ self.data, maxlinelength=maxlinelength, indent_level=indent_level
114
+ )
115
+
116
+ def __eq__(self, other: Any) -> bool:
117
+ if isinstance(other, self.__class__):
118
+ return self.data == other.data
119
+ elif isinstance(other, bytes):
120
+ return self.data == other
121
+ else:
122
+ return NotImplemented
123
+
124
+ def __repr__(self) -> str:
125
+ return "%s(%s)" % (self.__class__.__name__, repr(self.data))
126
+
127
+
128
+ def _encode_base64(
129
+ data: bytes, maxlinelength: Optional[int] = 76, indent_level: int = 1
130
+ ) -> bytes:
131
+ data = b64encode(data)
132
+ if data and maxlinelength:
133
+ # split into multiple lines right-justified to 'maxlinelength' chars
134
+ indent = b"\n" + b" " * indent_level
135
+ max_length = max(16, maxlinelength - len(indent))
136
+ chunks = []
137
+ for i in range(0, len(data), max_length):
138
+ chunks.append(indent)
139
+ chunks.append(data[i : i + max_length])
140
+ chunks.append(indent)
141
+ data = b"".join(chunks)
142
+ return data
143
+
144
+
145
+ # Mypy does not support recursive type aliases as of 0.782, Pylance does.
146
+ # https://github.com/python/mypy/issues/731
147
+ # https://devblogs.microsoft.com/python/pylance-introduces-five-new-features-that-enable-type-magic-for-python-developers/#1-support-for-recursive-type-aliases
148
+ PlistEncodable = Union[
149
+ bool,
150
+ bytes,
151
+ Data,
152
+ datetime,
153
+ float,
154
+ Integral,
155
+ Mapping[str, Any],
156
+ Sequence[Any],
157
+ str,
158
+ ]
159
+
160
+
161
+ class PlistTarget:
162
+ """Event handler using the ElementTree Target API that can be
163
+ passed to a XMLParser to produce property list objects from XML.
164
+ It is based on the CPython plistlib module's _PlistParser class,
165
+ but does not use the expat parser.
166
+
167
+ >>> from fontTools.misc import etree
168
+ >>> parser = etree.XMLParser(target=PlistTarget())
169
+ >>> result = etree.XML(
170
+ ... "<dict>"
171
+ ... " <key>something</key>"
172
+ ... " <string>blah</string>"
173
+ ... "</dict>",
174
+ ... parser=parser)
175
+ >>> result == {"something": "blah"}
176
+ True
177
+
178
+ Links:
179
+ https://github.com/python/cpython/blob/main/Lib/plistlib.py
180
+ http://lxml.de/parsing.html#the-target-parser-interface
181
+ """
182
+
183
+ def __init__(
184
+ self,
185
+ use_builtin_types: Optional[bool] = None,
186
+ dict_type: Type[MutableMapping[str, Any]] = dict,
187
+ ) -> None:
188
+ self.stack: List[PlistEncodable] = []
189
+ self.current_key: Optional[str] = None
190
+ self.root: Optional[PlistEncodable] = None
191
+ if use_builtin_types is None:
192
+ self._use_builtin_types = USE_BUILTIN_TYPES
193
+ else:
194
+ if use_builtin_types is False:
195
+ warnings.warn(
196
+ "Setting use_builtin_types to False is deprecated and will be "
197
+ "removed soon.",
198
+ DeprecationWarning,
199
+ )
200
+ self._use_builtin_types = use_builtin_types
201
+ self._dict_type = dict_type
202
+
203
+ def start(self, tag: str, attrib: Mapping[str, str]) -> None:
204
+ self._data: List[str] = []
205
+ handler = _TARGET_START_HANDLERS.get(tag)
206
+ if handler is not None:
207
+ handler(self)
208
+
209
+ def end(self, tag: str) -> None:
210
+ handler = _TARGET_END_HANDLERS.get(tag)
211
+ if handler is not None:
212
+ handler(self)
213
+
214
+ def data(self, data: str) -> None:
215
+ self._data.append(data)
216
+
217
+ def close(self) -> PlistEncodable:
218
+ if self.root is None:
219
+ raise ValueError("No root set.")
220
+ return self.root
221
+
222
+ # helpers
223
+
224
+ def add_object(self, value: PlistEncodable) -> None:
225
+ if self.current_key is not None:
226
+ stack_top = self.stack[-1]
227
+ if not isinstance(stack_top, collections.abc.MutableMapping):
228
+ raise ValueError("unexpected element: %r" % stack_top)
229
+ stack_top[self.current_key] = value
230
+ self.current_key = None
231
+ elif not self.stack:
232
+ # this is the root object
233
+ self.root = value
234
+ else:
235
+ stack_top = self.stack[-1]
236
+ if not isinstance(stack_top, list):
237
+ raise ValueError("unexpected element: %r" % stack_top)
238
+ stack_top.append(value)
239
+
240
+ def get_data(self) -> str:
241
+ data = "".join(self._data)
242
+ self._data = []
243
+ return data
244
+
245
+
246
+ # event handlers
247
+
248
+
249
+ def start_dict(self: PlistTarget) -> None:
250
+ d = self._dict_type()
251
+ self.add_object(d)
252
+ self.stack.append(d)
253
+
254
+
255
+ def end_dict(self: PlistTarget) -> None:
256
+ if self.current_key:
257
+ raise ValueError("missing value for key '%s'" % self.current_key)
258
+ self.stack.pop()
259
+
260
+
261
+ def end_key(self: PlistTarget) -> None:
262
+ if self.current_key or not isinstance(self.stack[-1], collections.abc.Mapping):
263
+ raise ValueError("unexpected key")
264
+ self.current_key = self.get_data()
265
+
266
+
267
+ def start_array(self: PlistTarget) -> None:
268
+ a: List[PlistEncodable] = []
269
+ self.add_object(a)
270
+ self.stack.append(a)
271
+
272
+
273
+ def end_array(self: PlistTarget) -> None:
274
+ self.stack.pop()
275
+
276
+
277
+ def end_true(self: PlistTarget) -> None:
278
+ self.add_object(True)
279
+
280
+
281
+ def end_false(self: PlistTarget) -> None:
282
+ self.add_object(False)
283
+
284
+
285
+ def end_integer(self: PlistTarget) -> None:
286
+ self.add_object(int(self.get_data()))
287
+
288
+
289
+ def end_real(self: PlistTarget) -> None:
290
+ self.add_object(float(self.get_data()))
291
+
292
+
293
+ def end_string(self: PlistTarget) -> None:
294
+ self.add_object(self.get_data())
295
+
296
+
297
+ def end_data(self: PlistTarget) -> None:
298
+ if self._use_builtin_types:
299
+ self.add_object(b64decode(self.get_data()))
300
+ else:
301
+ self.add_object(Data.fromBase64(self.get_data()))
302
+
303
+
304
+ def end_date(self: PlistTarget) -> None:
305
+ self.add_object(_date_from_string(self.get_data()))
306
+
307
+
308
+ _TARGET_START_HANDLERS: Dict[str, Callable[[PlistTarget], None]] = {
309
+ "dict": start_dict,
310
+ "array": start_array,
311
+ }
312
+
313
+ _TARGET_END_HANDLERS: Dict[str, Callable[[PlistTarget], None]] = {
314
+ "dict": end_dict,
315
+ "array": end_array,
316
+ "key": end_key,
317
+ "true": end_true,
318
+ "false": end_false,
319
+ "integer": end_integer,
320
+ "real": end_real,
321
+ "string": end_string,
322
+ "data": end_data,
323
+ "date": end_date,
324
+ }
325
+
326
+
327
+ # functions to build element tree from plist data
328
+
329
+
330
+ def _string_element(value: str, ctx: SimpleNamespace) -> etree.Element:
331
+ el = etree.Element("string")
332
+ el.text = value
333
+ return el
334
+
335
+
336
+ def _bool_element(value: bool, ctx: SimpleNamespace) -> etree.Element:
337
+ if value:
338
+ return etree.Element("true")
339
+ return etree.Element("false")
340
+
341
+
342
+ def _integer_element(value: int, ctx: SimpleNamespace) -> etree.Element:
343
+ if -1 << 63 <= value < 1 << 64:
344
+ el = etree.Element("integer")
345
+ el.text = "%d" % value
346
+ return el
347
+ raise OverflowError(value)
348
+
349
+
350
+ def _real_element(value: float, ctx: SimpleNamespace) -> etree.Element:
351
+ el = etree.Element("real")
352
+ el.text = repr(value)
353
+ return el
354
+
355
+
356
+ def _dict_element(
357
+ d: Mapping[str, PlistEncodable], ctx: SimpleNamespace
358
+ ) -> etree.Element:
359
+ el = etree.Element("dict")
360
+ items = d.items()
361
+ if ctx.sort_keys:
362
+ items = sorted(items) # type: ignore
363
+ ctx.indent_level += 1
364
+ for key, value in items:
365
+ if not isinstance(key, str):
366
+ if ctx.skipkeys:
367
+ continue
368
+ raise TypeError("keys must be strings")
369
+ k = etree.SubElement(el, "key")
370
+ k.text = tostr(key, "utf-8")
371
+ el.append(_make_element(value, ctx))
372
+ ctx.indent_level -= 1
373
+ return el
374
+
375
+
376
+ def _array_element(
377
+ array: Sequence[PlistEncodable], ctx: SimpleNamespace
378
+ ) -> etree.Element:
379
+ el = etree.Element("array")
380
+ if len(array) == 0:
381
+ return el
382
+ ctx.indent_level += 1
383
+ for value in array:
384
+ el.append(_make_element(value, ctx))
385
+ ctx.indent_level -= 1
386
+ return el
387
+
388
+
389
+ def _date_element(date: datetime, ctx: SimpleNamespace) -> etree.Element:
390
+ el = etree.Element("date")
391
+ el.text = _date_to_string(date)
392
+ return el
393
+
394
+
395
+ def _data_element(data: bytes, ctx: SimpleNamespace) -> etree.Element:
396
+ el = etree.Element("data")
397
+ # NOTE: mypy is confused about whether el.text should be str or bytes.
398
+ el.text = _encode_base64( # type: ignore
399
+ data,
400
+ maxlinelength=(76 if ctx.pretty_print else None),
401
+ indent_level=ctx.indent_level,
402
+ )
403
+ return el
404
+
405
+
406
+ def _string_or_data_element(raw_bytes: bytes, ctx: SimpleNamespace) -> etree.Element:
407
+ if ctx.use_builtin_types:
408
+ return _data_element(raw_bytes, ctx)
409
+ else:
410
+ try:
411
+ string = raw_bytes.decode(encoding="ascii", errors="strict")
412
+ except UnicodeDecodeError:
413
+ raise ValueError(
414
+ "invalid non-ASCII bytes; use unicode string instead: %r" % raw_bytes
415
+ )
416
+ return _string_element(string, ctx)
417
+
418
+
419
+ # The following is probably not entirely correct. The signature should take `Any`
420
+ # and return `NoReturn`. At the time of this writing, neither mypy nor Pyright
421
+ # can deal with singledispatch properly and will apply the signature of the base
422
+ # function to all others. Being slightly dishonest makes it type-check and return
423
+ # usable typing information for the optimistic case.
424
+ @singledispatch
425
+ def _make_element(value: PlistEncodable, ctx: SimpleNamespace) -> etree.Element:
426
+ raise TypeError("unsupported type: %s" % type(value))
427
+
428
+
429
+ _make_element.register(str)(_string_element)
430
+ _make_element.register(bool)(_bool_element)
431
+ _make_element.register(Integral)(_integer_element)
432
+ _make_element.register(float)(_real_element)
433
+ _make_element.register(collections.abc.Mapping)(_dict_element)
434
+ _make_element.register(list)(_array_element)
435
+ _make_element.register(tuple)(_array_element)
436
+ _make_element.register(datetime)(_date_element)
437
+ _make_element.register(bytes)(_string_or_data_element)
438
+ _make_element.register(bytearray)(_data_element)
439
+ _make_element.register(Data)(lambda v, ctx: _data_element(v.data, ctx))
440
+
441
+
442
+ # Public functions to create element tree from plist-compatible python
443
+ # data structures and viceversa, for use when (de)serializing GLIF xml.
444
+
445
+
446
+ def totree(
447
+ value: PlistEncodable,
448
+ sort_keys: bool = True,
449
+ skipkeys: bool = False,
450
+ use_builtin_types: Optional[bool] = None,
451
+ pretty_print: bool = True,
452
+ indent_level: int = 1,
453
+ ) -> etree.Element:
454
+ """Convert a value derived from a plist into an XML tree.
455
+
456
+ Args:
457
+ value: Any kind of value to be serialized to XML.
458
+ sort_keys: Whether keys of dictionaries should be sorted.
459
+ skipkeys (bool): Whether to silently skip non-string dictionary
460
+ keys.
461
+ use_builtin_types (bool): If true, byte strings will be
462
+ encoded in Base-64 and wrapped in a ``data`` tag; if
463
+ false, they will be either stored as ASCII strings or an
464
+ exception raised if they cannot be decoded as such. Defaults
465
+ to ``True`` if not present. Deprecated.
466
+ pretty_print (bool): Whether to indent the output.
467
+ indent_level (int): Level of indentation when serializing.
468
+
469
+ Returns: an ``etree`` ``Element`` object.
470
+
471
+ Raises:
472
+ ``TypeError``
473
+ if non-string dictionary keys are serialized
474
+ and ``skipkeys`` is false.
475
+ ``ValueError``
476
+ if non-ASCII binary data is present
477
+ and `use_builtin_types` is false.
478
+ """
479
+ if use_builtin_types is None:
480
+ use_builtin_types = USE_BUILTIN_TYPES
481
+ else:
482
+ use_builtin_types = use_builtin_types
483
+ context = SimpleNamespace(
484
+ sort_keys=sort_keys,
485
+ skipkeys=skipkeys,
486
+ use_builtin_types=use_builtin_types,
487
+ pretty_print=pretty_print,
488
+ indent_level=indent_level,
489
+ )
490
+ return _make_element(value, context)
491
+
492
+
493
+ def fromtree(
494
+ tree: etree.Element,
495
+ use_builtin_types: Optional[bool] = None,
496
+ dict_type: Type[MutableMapping[str, Any]] = dict,
497
+ ) -> Any:
498
+ """Convert an XML tree to a plist structure.
499
+
500
+ Args:
501
+ tree: An ``etree`` ``Element``.
502
+ use_builtin_types: If True, binary data is deserialized to
503
+ bytes strings. If False, it is wrapped in :py:class:`Data`
504
+ objects. Defaults to True if not provided. Deprecated.
505
+ dict_type: What type to use for dictionaries.
506
+
507
+ Returns: An object (usually a dictionary).
508
+ """
509
+ target = PlistTarget(use_builtin_types=use_builtin_types, dict_type=dict_type)
510
+ for action, element in etree.iterwalk(tree, events=("start", "end")):
511
+ if action == "start":
512
+ target.start(element.tag, element.attrib)
513
+ elif action == "end":
514
+ # if there are no children, parse the leaf's data
515
+ if not len(element):
516
+ # always pass str, not None
517
+ target.data(element.text or "")
518
+ target.end(element.tag)
519
+ return target.close()
520
+
521
+
522
+ # python3 plistlib API
523
+
524
+
525
+ def load(
526
+ fp: IO[bytes],
527
+ use_builtin_types: Optional[bool] = None,
528
+ dict_type: Type[MutableMapping[str, Any]] = dict,
529
+ ) -> Any:
530
+ """Load a plist file into an object.
531
+
532
+ Args:
533
+ fp: An opened file.
534
+ use_builtin_types: If True, binary data is deserialized to
535
+ bytes strings. If False, it is wrapped in :py:class:`Data`
536
+ objects. Defaults to True if not provided. Deprecated.
537
+ dict_type: What type to use for dictionaries.
538
+
539
+ Returns:
540
+ An object (usually a dictionary) representing the top level of
541
+ the plist file.
542
+ """
543
+
544
+ if not hasattr(fp, "read"):
545
+ raise AttributeError("'%s' object has no attribute 'read'" % type(fp).__name__)
546
+ target = PlistTarget(use_builtin_types=use_builtin_types, dict_type=dict_type)
547
+ parser = etree.XMLParser(target=target)
548
+ result = etree.parse(fp, parser=parser)
549
+ # lxml returns the target object directly, while ElementTree wraps
550
+ # it as the root of an ElementTree object
551
+ try:
552
+ return result.getroot()
553
+ except AttributeError:
554
+ return result
555
+
556
+
557
+ def loads(
558
+ value: bytes,
559
+ use_builtin_types: Optional[bool] = None,
560
+ dict_type: Type[MutableMapping[str, Any]] = dict,
561
+ ) -> Any:
562
+ """Load a plist file from a string into an object.
563
+
564
+ Args:
565
+ value: A bytes string containing a plist.
566
+ use_builtin_types: If True, binary data is deserialized to
567
+ bytes strings. If False, it is wrapped in :py:class:`Data`
568
+ objects. Defaults to True if not provided. Deprecated.
569
+ dict_type: What type to use for dictionaries.
570
+
571
+ Returns:
572
+ An object (usually a dictionary) representing the top level of
573
+ the plist file.
574
+ """
575
+
576
+ fp = BytesIO(value)
577
+ return load(fp, use_builtin_types=use_builtin_types, dict_type=dict_type)
578
+
579
+
580
+ def dump(
581
+ value: PlistEncodable,
582
+ fp: IO[bytes],
583
+ sort_keys: bool = True,
584
+ skipkeys: bool = False,
585
+ use_builtin_types: Optional[bool] = None,
586
+ pretty_print: bool = True,
587
+ ) -> None:
588
+ """Write a Python object to a plist file.
589
+
590
+ Args:
591
+ value: An object to write.
592
+ fp: A file opened for writing.
593
+ sort_keys (bool): Whether keys of dictionaries should be sorted.
594
+ skipkeys (bool): Whether to silently skip non-string dictionary
595
+ keys.
596
+ use_builtin_types (bool): If true, byte strings will be
597
+ encoded in Base-64 and wrapped in a ``data`` tag; if
598
+ false, they will be either stored as ASCII strings or an
599
+ exception raised if they cannot be represented. Defaults
600
+ pretty_print (bool): Whether to indent the output.
601
+ indent_level (int): Level of indentation when serializing.
602
+
603
+ Raises:
604
+ ``TypeError``
605
+ if non-string dictionary keys are serialized
606
+ and ``skipkeys`` is false.
607
+ ``ValueError``
608
+ if non-representable binary data is present
609
+ and `use_builtin_types` is false.
610
+ """
611
+
612
+ if not hasattr(fp, "write"):
613
+ raise AttributeError("'%s' object has no attribute 'write'" % type(fp).__name__)
614
+ root = etree.Element("plist", version="1.0")
615
+ el = totree(
616
+ value,
617
+ sort_keys=sort_keys,
618
+ skipkeys=skipkeys,
619
+ use_builtin_types=use_builtin_types,
620
+ pretty_print=pretty_print,
621
+ )
622
+ root.append(el)
623
+ tree = etree.ElementTree(root)
624
+ # we write the doctype ourselves instead of using the 'doctype' argument
625
+ # of 'write' method, becuse lxml will force adding a '\n' even when
626
+ # pretty_print is False.
627
+ if pretty_print:
628
+ header = b"\n".join((XML_DECLARATION, PLIST_DOCTYPE, b""))
629
+ else:
630
+ header = XML_DECLARATION + PLIST_DOCTYPE
631
+ fp.write(header)
632
+ tree.write( # type: ignore
633
+ fp,
634
+ encoding="utf-8",
635
+ pretty_print=pretty_print,
636
+ xml_declaration=False,
637
+ )
638
+
639
+
640
+ def dumps(
641
+ value: PlistEncodable,
642
+ sort_keys: bool = True,
643
+ skipkeys: bool = False,
644
+ use_builtin_types: Optional[bool] = None,
645
+ pretty_print: bool = True,
646
+ ) -> bytes:
647
+ """Write a Python object to a string in plist format.
648
+
649
+ Args:
650
+ value: An object to write.
651
+ sort_keys (bool): Whether keys of dictionaries should be sorted.
652
+ skipkeys (bool): Whether to silently skip non-string dictionary
653
+ keys.
654
+ use_builtin_types (bool): If true, byte strings will be
655
+ encoded in Base-64 and wrapped in a ``data`` tag; if
656
+ false, they will be either stored as strings or an
657
+ exception raised if they cannot be represented. Defaults
658
+ pretty_print (bool): Whether to indent the output.
659
+ indent_level (int): Level of indentation when serializing.
660
+
661
+ Returns:
662
+ string: A plist representation of the Python object.
663
+
664
+ Raises:
665
+ ``TypeError``
666
+ if non-string dictionary keys are serialized
667
+ and ``skipkeys`` is false.
668
+ ``ValueError``
669
+ if non-representable binary data is present
670
+ and `use_builtin_types` is false.
671
+ """
672
+ fp = BytesIO()
673
+ dump(
674
+ value,
675
+ fp,
676
+ sort_keys=sort_keys,
677
+ skipkeys=skipkeys,
678
+ use_builtin_types=use_builtin_types,
679
+ pretty_print=pretty_print,
680
+ )
681
+ return fp.getvalue()
File without changes