fonttools 4.55.6__cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.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.

Potentially problematic release.


This version of fonttools might be problematic. Click here for more details.

Files changed (329) 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/cffLib/CFF2ToCFF.py +203 -0
  6. fontTools/cffLib/CFFToCFF2.py +305 -0
  7. fontTools/cffLib/__init__.py +3659 -0
  8. fontTools/cffLib/specializer.py +924 -0
  9. fontTools/cffLib/transforms.py +490 -0
  10. fontTools/cffLib/width.py +210 -0
  11. fontTools/colorLib/__init__.py +0 -0
  12. fontTools/colorLib/builder.py +664 -0
  13. fontTools/colorLib/errors.py +2 -0
  14. fontTools/colorLib/geometry.py +143 -0
  15. fontTools/colorLib/table_builder.py +223 -0
  16. fontTools/colorLib/unbuilder.py +81 -0
  17. fontTools/config/__init__.py +75 -0
  18. fontTools/cu2qu/__init__.py +15 -0
  19. fontTools/cu2qu/__main__.py +6 -0
  20. fontTools/cu2qu/benchmark.py +54 -0
  21. fontTools/cu2qu/cli.py +198 -0
  22. fontTools/cu2qu/cu2qu.c +14829 -0
  23. fontTools/cu2qu/cu2qu.cpython-39-x86_64-linux-gnu.so +0 -0
  24. fontTools/cu2qu/cu2qu.py +531 -0
  25. fontTools/cu2qu/errors.py +77 -0
  26. fontTools/cu2qu/ufo.py +349 -0
  27. fontTools/designspaceLib/__init__.py +3338 -0
  28. fontTools/designspaceLib/__main__.py +6 -0
  29. fontTools/designspaceLib/split.py +475 -0
  30. fontTools/designspaceLib/statNames.py +253 -0
  31. fontTools/designspaceLib/types.py +147 -0
  32. fontTools/encodings/MacRoman.py +258 -0
  33. fontTools/encodings/StandardEncoding.py +258 -0
  34. fontTools/encodings/__init__.py +1 -0
  35. fontTools/encodings/codecs.py +135 -0
  36. fontTools/feaLib/__init__.py +4 -0
  37. fontTools/feaLib/__main__.py +78 -0
  38. fontTools/feaLib/ast.py +2134 -0
  39. fontTools/feaLib/builder.py +1747 -0
  40. fontTools/feaLib/error.py +22 -0
  41. fontTools/feaLib/lexer.c +17986 -0
  42. fontTools/feaLib/lexer.cpython-39-x86_64-linux-gnu.so +0 -0
  43. fontTools/feaLib/lexer.py +287 -0
  44. fontTools/feaLib/location.py +12 -0
  45. fontTools/feaLib/lookupDebugInfo.py +12 -0
  46. fontTools/feaLib/parser.py +2359 -0
  47. fontTools/feaLib/variableScalar.py +113 -0
  48. fontTools/fontBuilder.py +1008 -0
  49. fontTools/help.py +36 -0
  50. fontTools/merge/__init__.py +248 -0
  51. fontTools/merge/__main__.py +6 -0
  52. fontTools/merge/base.py +81 -0
  53. fontTools/merge/cmap.py +141 -0
  54. fontTools/merge/layout.py +526 -0
  55. fontTools/merge/options.py +85 -0
  56. fontTools/merge/tables.py +341 -0
  57. fontTools/merge/unicode.py +78 -0
  58. fontTools/merge/util.py +143 -0
  59. fontTools/misc/__init__.py +1 -0
  60. fontTools/misc/arrayTools.py +424 -0
  61. fontTools/misc/bezierTools.c +41831 -0
  62. fontTools/misc/bezierTools.cpython-39-x86_64-linux-gnu.so +0 -0
  63. fontTools/misc/bezierTools.py +1497 -0
  64. fontTools/misc/classifyTools.py +170 -0
  65. fontTools/misc/cliTools.py +53 -0
  66. fontTools/misc/configTools.py +349 -0
  67. fontTools/misc/cython.py +27 -0
  68. fontTools/misc/dictTools.py +83 -0
  69. fontTools/misc/eexec.py +119 -0
  70. fontTools/misc/encodingTools.py +72 -0
  71. fontTools/misc/etree.py +479 -0
  72. fontTools/misc/filenames.py +245 -0
  73. fontTools/misc/fixedTools.py +253 -0
  74. fontTools/misc/intTools.py +25 -0
  75. fontTools/misc/iterTools.py +12 -0
  76. fontTools/misc/lazyTools.py +42 -0
  77. fontTools/misc/loggingTools.py +543 -0
  78. fontTools/misc/macCreatorType.py +56 -0
  79. fontTools/misc/macRes.py +261 -0
  80. fontTools/misc/plistlib/__init__.py +681 -0
  81. fontTools/misc/plistlib/py.typed +0 -0
  82. fontTools/misc/psCharStrings.py +1496 -0
  83. fontTools/misc/psLib.py +398 -0
  84. fontTools/misc/psOperators.py +572 -0
  85. fontTools/misc/py23.py +96 -0
  86. fontTools/misc/roundTools.py +110 -0
  87. fontTools/misc/sstruct.py +231 -0
  88. fontTools/misc/symfont.py +244 -0
  89. fontTools/misc/testTools.py +229 -0
  90. fontTools/misc/textTools.py +154 -0
  91. fontTools/misc/timeTools.py +88 -0
  92. fontTools/misc/transform.py +516 -0
  93. fontTools/misc/treeTools.py +45 -0
  94. fontTools/misc/vector.py +147 -0
  95. fontTools/misc/visitor.py +142 -0
  96. fontTools/misc/xmlReader.py +188 -0
  97. fontTools/misc/xmlWriter.py +204 -0
  98. fontTools/mtiLib/__init__.py +1402 -0
  99. fontTools/mtiLib/__main__.py +5 -0
  100. fontTools/otlLib/__init__.py +1 -0
  101. fontTools/otlLib/builder.py +3221 -0
  102. fontTools/otlLib/error.py +11 -0
  103. fontTools/otlLib/maxContextCalc.py +96 -0
  104. fontTools/otlLib/optimize/__init__.py +53 -0
  105. fontTools/otlLib/optimize/__main__.py +6 -0
  106. fontTools/otlLib/optimize/gpos.py +453 -0
  107. fontTools/pens/__init__.py +1 -0
  108. fontTools/pens/areaPen.py +52 -0
  109. fontTools/pens/basePen.py +475 -0
  110. fontTools/pens/boundsPen.py +98 -0
  111. fontTools/pens/cairoPen.py +26 -0
  112. fontTools/pens/cocoaPen.py +26 -0
  113. fontTools/pens/cu2quPen.py +325 -0
  114. fontTools/pens/explicitClosingLinePen.py +101 -0
  115. fontTools/pens/filterPen.py +241 -0
  116. fontTools/pens/freetypePen.py +462 -0
  117. fontTools/pens/hashPointPen.py +89 -0
  118. fontTools/pens/momentsPen.c +13448 -0
  119. fontTools/pens/momentsPen.cpython-39-x86_64-linux-gnu.so +0 -0
  120. fontTools/pens/momentsPen.py +879 -0
  121. fontTools/pens/perimeterPen.py +69 -0
  122. fontTools/pens/pointInsidePen.py +192 -0
  123. fontTools/pens/pointPen.py +600 -0
  124. fontTools/pens/qtPen.py +29 -0
  125. fontTools/pens/qu2cuPen.py +105 -0
  126. fontTools/pens/quartzPen.py +43 -0
  127. fontTools/pens/recordingPen.py +335 -0
  128. fontTools/pens/reportLabPen.py +79 -0
  129. fontTools/pens/reverseContourPen.py +96 -0
  130. fontTools/pens/roundingPen.py +130 -0
  131. fontTools/pens/statisticsPen.py +312 -0
  132. fontTools/pens/svgPathPen.py +310 -0
  133. fontTools/pens/t2CharStringPen.py +68 -0
  134. fontTools/pens/teePen.py +55 -0
  135. fontTools/pens/transformPen.py +115 -0
  136. fontTools/pens/ttGlyphPen.py +335 -0
  137. fontTools/pens/wxPen.py +29 -0
  138. fontTools/qu2cu/__init__.py +15 -0
  139. fontTools/qu2cu/__main__.py +7 -0
  140. fontTools/qu2cu/benchmark.py +56 -0
  141. fontTools/qu2cu/cli.py +125 -0
  142. fontTools/qu2cu/qu2cu.c +16269 -0
  143. fontTools/qu2cu/qu2cu.cpython-39-x86_64-linux-gnu.so +0 -0
  144. fontTools/qu2cu/qu2cu.py +405 -0
  145. fontTools/subset/__init__.py +3838 -0
  146. fontTools/subset/__main__.py +6 -0
  147. fontTools/subset/cff.py +184 -0
  148. fontTools/subset/svg.py +253 -0
  149. fontTools/subset/util.py +25 -0
  150. fontTools/svgLib/__init__.py +3 -0
  151. fontTools/svgLib/path/__init__.py +65 -0
  152. fontTools/svgLib/path/arc.py +154 -0
  153. fontTools/svgLib/path/parser.py +322 -0
  154. fontTools/svgLib/path/shapes.py +183 -0
  155. fontTools/t1Lib/__init__.py +648 -0
  156. fontTools/tfmLib.py +460 -0
  157. fontTools/ttLib/__init__.py +26 -0
  158. fontTools/ttLib/__main__.py +109 -0
  159. fontTools/ttLib/macUtils.py +54 -0
  160. fontTools/ttLib/removeOverlaps.py +393 -0
  161. fontTools/ttLib/reorderGlyphs.py +284 -0
  162. fontTools/ttLib/scaleUpem.py +436 -0
  163. fontTools/ttLib/sfnt.py +662 -0
  164. fontTools/ttLib/standardGlyphOrder.py +271 -0
  165. fontTools/ttLib/tables/B_A_S_E_.py +14 -0
  166. fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
  167. fontTools/ttLib/tables/C_B_D_T_.py +113 -0
  168. fontTools/ttLib/tables/C_B_L_C_.py +19 -0
  169. fontTools/ttLib/tables/C_F_F_.py +61 -0
  170. fontTools/ttLib/tables/C_F_F__2.py +26 -0
  171. fontTools/ttLib/tables/C_O_L_R_.py +165 -0
  172. fontTools/ttLib/tables/C_P_A_L_.py +305 -0
  173. fontTools/ttLib/tables/D_S_I_G_.py +158 -0
  174. fontTools/ttLib/tables/D__e_b_g.py +17 -0
  175. fontTools/ttLib/tables/DefaultTable.py +49 -0
  176. fontTools/ttLib/tables/E_B_D_T_.py +835 -0
  177. fontTools/ttLib/tables/E_B_L_C_.py +718 -0
  178. fontTools/ttLib/tables/F_F_T_M_.py +52 -0
  179. fontTools/ttLib/tables/F__e_a_t.py +149 -0
  180. fontTools/ttLib/tables/G_D_E_F_.py +13 -0
  181. fontTools/ttLib/tables/G_M_A_P_.py +148 -0
  182. fontTools/ttLib/tables/G_P_K_G_.py +133 -0
  183. fontTools/ttLib/tables/G_P_O_S_.py +14 -0
  184. fontTools/ttLib/tables/G_S_U_B_.py +13 -0
  185. fontTools/ttLib/tables/G__l_a_t.py +235 -0
  186. fontTools/ttLib/tables/G__l_o_c.py +85 -0
  187. fontTools/ttLib/tables/H_V_A_R_.py +13 -0
  188. fontTools/ttLib/tables/J_S_T_F_.py +13 -0
  189. fontTools/ttLib/tables/L_T_S_H_.py +58 -0
  190. fontTools/ttLib/tables/M_A_T_H_.py +13 -0
  191. fontTools/ttLib/tables/M_E_T_A_.py +352 -0
  192. fontTools/ttLib/tables/M_V_A_R_.py +13 -0
  193. fontTools/ttLib/tables/O_S_2f_2.py +752 -0
  194. fontTools/ttLib/tables/S_I_N_G_.py +99 -0
  195. fontTools/ttLib/tables/S_T_A_T_.py +15 -0
  196. fontTools/ttLib/tables/S_V_G_.py +223 -0
  197. fontTools/ttLib/tables/S__i_l_f.py +1040 -0
  198. fontTools/ttLib/tables/S__i_l_l.py +92 -0
  199. fontTools/ttLib/tables/T_S_I_B_.py +13 -0
  200. fontTools/ttLib/tables/T_S_I_C_.py +14 -0
  201. fontTools/ttLib/tables/T_S_I_D_.py +13 -0
  202. fontTools/ttLib/tables/T_S_I_J_.py +13 -0
  203. fontTools/ttLib/tables/T_S_I_P_.py +13 -0
  204. fontTools/ttLib/tables/T_S_I_S_.py +13 -0
  205. fontTools/ttLib/tables/T_S_I_V_.py +26 -0
  206. fontTools/ttLib/tables/T_S_I__0.py +59 -0
  207. fontTools/ttLib/tables/T_S_I__1.py +166 -0
  208. fontTools/ttLib/tables/T_S_I__2.py +17 -0
  209. fontTools/ttLib/tables/T_S_I__3.py +22 -0
  210. fontTools/ttLib/tables/T_S_I__5.py +49 -0
  211. fontTools/ttLib/tables/T_T_F_A_.py +14 -0
  212. fontTools/ttLib/tables/TupleVariation.py +884 -0
  213. fontTools/ttLib/tables/V_A_R_C_.py +12 -0
  214. fontTools/ttLib/tables/V_D_M_X_.py +249 -0
  215. fontTools/ttLib/tables/V_O_R_G_.py +165 -0
  216. fontTools/ttLib/tables/V_V_A_R_.py +13 -0
  217. fontTools/ttLib/tables/__init__.py +97 -0
  218. fontTools/ttLib/tables/_a_n_k_r.py +15 -0
  219. fontTools/ttLib/tables/_a_v_a_r.py +191 -0
  220. fontTools/ttLib/tables/_b_s_l_n.py +15 -0
  221. fontTools/ttLib/tables/_c_i_d_g.py +24 -0
  222. fontTools/ttLib/tables/_c_m_a_p.py +1578 -0
  223. fontTools/ttLib/tables/_c_v_a_r.py +94 -0
  224. fontTools/ttLib/tables/_c_v_t.py +55 -0
  225. fontTools/ttLib/tables/_f_e_a_t.py +15 -0
  226. fontTools/ttLib/tables/_f_p_g_m.py +60 -0
  227. fontTools/ttLib/tables/_f_v_a_r.py +261 -0
  228. fontTools/ttLib/tables/_g_a_s_p.py +63 -0
  229. fontTools/ttLib/tables/_g_c_i_d.py +13 -0
  230. fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
  231. fontTools/ttLib/tables/_g_v_a_r.py +292 -0
  232. fontTools/ttLib/tables/_h_d_m_x.py +127 -0
  233. fontTools/ttLib/tables/_h_e_a_d.py +130 -0
  234. fontTools/ttLib/tables/_h_h_e_a.py +147 -0
  235. fontTools/ttLib/tables/_h_m_t_x.py +160 -0
  236. fontTools/ttLib/tables/_k_e_r_n.py +289 -0
  237. fontTools/ttLib/tables/_l_c_a_r.py +13 -0
  238. fontTools/ttLib/tables/_l_o_c_a.py +70 -0
  239. fontTools/ttLib/tables/_l_t_a_g.py +72 -0
  240. fontTools/ttLib/tables/_m_a_x_p.py +147 -0
  241. fontTools/ttLib/tables/_m_e_t_a.py +112 -0
  242. fontTools/ttLib/tables/_m_o_r_t.py +14 -0
  243. fontTools/ttLib/tables/_m_o_r_x.py +15 -0
  244. fontTools/ttLib/tables/_n_a_m_e.py +1237 -0
  245. fontTools/ttLib/tables/_o_p_b_d.py +14 -0
  246. fontTools/ttLib/tables/_p_o_s_t.py +317 -0
  247. fontTools/ttLib/tables/_p_r_e_p.py +16 -0
  248. fontTools/ttLib/tables/_p_r_o_p.py +12 -0
  249. fontTools/ttLib/tables/_s_b_i_x.py +129 -0
  250. fontTools/ttLib/tables/_t_r_a_k.py +332 -0
  251. fontTools/ttLib/tables/_v_h_e_a.py +139 -0
  252. fontTools/ttLib/tables/_v_m_t_x.py +19 -0
  253. fontTools/ttLib/tables/asciiTable.py +20 -0
  254. fontTools/ttLib/tables/grUtils.py +92 -0
  255. fontTools/ttLib/tables/otBase.py +1465 -0
  256. fontTools/ttLib/tables/otConverters.py +2065 -0
  257. fontTools/ttLib/tables/otData.py +6400 -0
  258. fontTools/ttLib/tables/otTables.py +2700 -0
  259. fontTools/ttLib/tables/otTraverse.py +162 -0
  260. fontTools/ttLib/tables/sbixGlyph.py +149 -0
  261. fontTools/ttLib/tables/sbixStrike.py +177 -0
  262. fontTools/ttLib/tables/table_API_readme.txt +91 -0
  263. fontTools/ttLib/tables/ttProgram.py +594 -0
  264. fontTools/ttLib/ttCollection.py +125 -0
  265. fontTools/ttLib/ttFont.py +1155 -0
  266. fontTools/ttLib/ttGlyphSet.py +500 -0
  267. fontTools/ttLib/ttVisitor.py +32 -0
  268. fontTools/ttLib/woff2.py +1683 -0
  269. fontTools/ttx.py +467 -0
  270. fontTools/ufoLib/__init__.py +2477 -0
  271. fontTools/ufoLib/converters.py +334 -0
  272. fontTools/ufoLib/errors.py +22 -0
  273. fontTools/ufoLib/etree.py +6 -0
  274. fontTools/ufoLib/filenames.py +291 -0
  275. fontTools/ufoLib/glifLib.py +2022 -0
  276. fontTools/ufoLib/kerning.py +91 -0
  277. fontTools/ufoLib/plistlib.py +47 -0
  278. fontTools/ufoLib/pointPen.py +6 -0
  279. fontTools/ufoLib/utils.py +76 -0
  280. fontTools/ufoLib/validators.py +1186 -0
  281. fontTools/unicode.py +50 -0
  282. fontTools/unicodedata/Blocks.py +802 -0
  283. fontTools/unicodedata/OTTags.py +50 -0
  284. fontTools/unicodedata/ScriptExtensions.py +806 -0
  285. fontTools/unicodedata/Scripts.py +3618 -0
  286. fontTools/unicodedata/__init__.py +298 -0
  287. fontTools/varLib/__init__.py +1511 -0
  288. fontTools/varLib/__main__.py +6 -0
  289. fontTools/varLib/avar.py +260 -0
  290. fontTools/varLib/avarPlanner.py +1004 -0
  291. fontTools/varLib/builder.py +215 -0
  292. fontTools/varLib/cff.py +631 -0
  293. fontTools/varLib/errors.py +219 -0
  294. fontTools/varLib/featureVars.py +689 -0
  295. fontTools/varLib/instancer/__init__.py +1937 -0
  296. fontTools/varLib/instancer/__main__.py +5 -0
  297. fontTools/varLib/instancer/featureVars.py +190 -0
  298. fontTools/varLib/instancer/names.py +388 -0
  299. fontTools/varLib/instancer/solver.py +309 -0
  300. fontTools/varLib/interpolatable.py +1209 -0
  301. fontTools/varLib/interpolatableHelpers.py +396 -0
  302. fontTools/varLib/interpolatablePlot.py +1269 -0
  303. fontTools/varLib/interpolatableTestContourOrder.py +82 -0
  304. fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
  305. fontTools/varLib/interpolate_layout.py +124 -0
  306. fontTools/varLib/iup.c +19154 -0
  307. fontTools/varLib/iup.cpython-39-x86_64-linux-gnu.so +0 -0
  308. fontTools/varLib/iup.py +490 -0
  309. fontTools/varLib/merger.py +1717 -0
  310. fontTools/varLib/models.py +642 -0
  311. fontTools/varLib/multiVarStore.py +253 -0
  312. fontTools/varLib/mutator.py +518 -0
  313. fontTools/varLib/mvar.py +40 -0
  314. fontTools/varLib/plot.py +238 -0
  315. fontTools/varLib/stat.py +149 -0
  316. fontTools/varLib/varStore.py +767 -0
  317. fontTools/voltLib/__init__.py +5 -0
  318. fontTools/voltLib/ast.py +448 -0
  319. fontTools/voltLib/error.py +12 -0
  320. fontTools/voltLib/lexer.py +99 -0
  321. fontTools/voltLib/parser.py +656 -0
  322. fontTools/voltLib/voltToFea.py +730 -0
  323. fonttools-4.55.6.data/data/share/man/man1/ttx.1 +225 -0
  324. fonttools-4.55.6.dist-info/LICENSE +21 -0
  325. fonttools-4.55.6.dist-info/METADATA +3413 -0
  326. fonttools-4.55.6.dist-info/RECORD +329 -0
  327. fonttools-4.55.6.dist-info/WHEEL +6 -0
  328. fonttools-4.55.6.dist-info/entry_points.txt +5 -0
  329. fonttools-4.55.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,119 @@
1
+ """
2
+ PostScript Type 1 fonts make use of two types of encryption: charstring
3
+ encryption and ``eexec`` encryption. Charstring encryption is used for
4
+ the charstrings themselves, while ``eexec`` is used to encrypt larger
5
+ sections of the font program, such as the ``Private`` and ``CharStrings``
6
+ dictionaries. Despite the different names, the algorithm is the same,
7
+ although ``eexec`` encryption uses a fixed initial key R=55665.
8
+
9
+ The algorithm uses cipher feedback, meaning that the ciphertext is used
10
+ to modify the key. Because of this, the routines in this module return
11
+ the new key at the end of the operation.
12
+
13
+ """
14
+
15
+ from fontTools.misc.textTools import bytechr, bytesjoin, byteord
16
+
17
+
18
+ def _decryptChar(cipher, R):
19
+ cipher = byteord(cipher)
20
+ plain = ((cipher ^ (R >> 8))) & 0xFF
21
+ R = ((cipher + R) * 52845 + 22719) & 0xFFFF
22
+ return bytechr(plain), R
23
+
24
+
25
+ def _encryptChar(plain, R):
26
+ plain = byteord(plain)
27
+ cipher = ((plain ^ (R >> 8))) & 0xFF
28
+ R = ((cipher + R) * 52845 + 22719) & 0xFFFF
29
+ return bytechr(cipher), R
30
+
31
+
32
+ def decrypt(cipherstring, R):
33
+ r"""
34
+ Decrypts a string using the Type 1 encryption algorithm.
35
+
36
+ Args:
37
+ cipherstring: String of ciphertext.
38
+ R: Initial key.
39
+
40
+ Returns:
41
+ decryptedStr: Plaintext string.
42
+ R: Output key for subsequent decryptions.
43
+
44
+ Examples::
45
+
46
+ >>> testStr = b"\0\0asdadads asds\265"
47
+ >>> decryptedStr, R = decrypt(testStr, 12321)
48
+ >>> decryptedStr == b'0d\nh\x15\xe8\xc4\xb2\x15\x1d\x108\x1a<6\xa1'
49
+ True
50
+ >>> R == 36142
51
+ True
52
+ """
53
+ plainList = []
54
+ for cipher in cipherstring:
55
+ plain, R = _decryptChar(cipher, R)
56
+ plainList.append(plain)
57
+ plainstring = bytesjoin(plainList)
58
+ return plainstring, int(R)
59
+
60
+
61
+ def encrypt(plainstring, R):
62
+ r"""
63
+ Encrypts a string using the Type 1 encryption algorithm.
64
+
65
+ Note that the algorithm as described in the Type 1 specification requires the
66
+ plaintext to be prefixed with a number of random bytes. (For ``eexec`` the
67
+ number of random bytes is set to 4.) This routine does *not* add the random
68
+ prefix to its input.
69
+
70
+ Args:
71
+ plainstring: String of plaintext.
72
+ R: Initial key.
73
+
74
+ Returns:
75
+ cipherstring: Ciphertext string.
76
+ R: Output key for subsequent encryptions.
77
+
78
+ Examples::
79
+
80
+ >>> testStr = b"\0\0asdadads asds\265"
81
+ >>> decryptedStr, R = decrypt(testStr, 12321)
82
+ >>> decryptedStr == b'0d\nh\x15\xe8\xc4\xb2\x15\x1d\x108\x1a<6\xa1'
83
+ True
84
+ >>> R == 36142
85
+ True
86
+
87
+ >>> testStr = b'0d\nh\x15\xe8\xc4\xb2\x15\x1d\x108\x1a<6\xa1'
88
+ >>> encryptedStr, R = encrypt(testStr, 12321)
89
+ >>> encryptedStr == b"\0\0asdadads asds\265"
90
+ True
91
+ >>> R == 36142
92
+ True
93
+ """
94
+ cipherList = []
95
+ for plain in plainstring:
96
+ cipher, R = _encryptChar(plain, R)
97
+ cipherList.append(cipher)
98
+ cipherstring = bytesjoin(cipherList)
99
+ return cipherstring, int(R)
100
+
101
+
102
+ def hexString(s):
103
+ import binascii
104
+
105
+ return binascii.hexlify(s)
106
+
107
+
108
+ def deHexString(h):
109
+ import binascii
110
+
111
+ h = bytesjoin(h.split())
112
+ return binascii.unhexlify(h)
113
+
114
+
115
+ if __name__ == "__main__":
116
+ import sys
117
+ import doctest
118
+
119
+ sys.exit(doctest.testmod().failed)
@@ -0,0 +1,72 @@
1
+ """fontTools.misc.encodingTools.py -- tools for working with OpenType encodings.
2
+ """
3
+
4
+ import fontTools.encodings.codecs
5
+
6
+ # Map keyed by platformID, then platEncID, then possibly langID
7
+ _encodingMap = {
8
+ 0: { # Unicode
9
+ 0: "utf_16_be",
10
+ 1: "utf_16_be",
11
+ 2: "utf_16_be",
12
+ 3: "utf_16_be",
13
+ 4: "utf_16_be",
14
+ 5: "utf_16_be",
15
+ 6: "utf_16_be",
16
+ },
17
+ 1: { # Macintosh
18
+ # See
19
+ # https://github.com/fonttools/fonttools/issues/236
20
+ 0: { # Macintosh, platEncID==0, keyed by langID
21
+ 15: "mac_iceland",
22
+ 17: "mac_turkish",
23
+ 18: "mac_croatian",
24
+ 24: "mac_latin2",
25
+ 25: "mac_latin2",
26
+ 26: "mac_latin2",
27
+ 27: "mac_latin2",
28
+ 28: "mac_latin2",
29
+ 36: "mac_latin2",
30
+ 37: "mac_romanian",
31
+ 38: "mac_latin2",
32
+ 39: "mac_latin2",
33
+ 40: "mac_latin2",
34
+ Ellipsis: "mac_roman", # Other
35
+ },
36
+ 1: "x_mac_japanese_ttx",
37
+ 2: "x_mac_trad_chinese_ttx",
38
+ 3: "x_mac_korean_ttx",
39
+ 6: "mac_greek",
40
+ 7: "mac_cyrillic",
41
+ 25: "x_mac_simp_chinese_ttx",
42
+ 29: "mac_latin2",
43
+ 35: "mac_turkish",
44
+ 37: "mac_iceland",
45
+ },
46
+ 2: { # ISO
47
+ 0: "ascii",
48
+ 1: "utf_16_be",
49
+ 2: "latin1",
50
+ },
51
+ 3: { # Microsoft
52
+ 0: "utf_16_be",
53
+ 1: "utf_16_be",
54
+ 2: "shift_jis",
55
+ 3: "gb2312",
56
+ 4: "big5",
57
+ 5: "euc_kr",
58
+ 6: "johab",
59
+ 10: "utf_16_be",
60
+ },
61
+ }
62
+
63
+
64
+ def getEncoding(platformID, platEncID, langID, default=None):
65
+ """Returns the Python encoding name for OpenType platformID/encodingID/langID
66
+ triplet. If encoding for these values is not known, by default None is
67
+ returned. That can be overriden by passing a value to the default argument.
68
+ """
69
+ encoding = _encodingMap.get(platformID, {}).get(platEncID, default)
70
+ if isinstance(encoding, dict):
71
+ encoding = encoding.get(langID, encoding[Ellipsis])
72
+ return encoding
@@ -0,0 +1,479 @@
1
+ """Shim module exporting the same ElementTree API for lxml and
2
+ xml.etree backends.
3
+
4
+ When lxml is installed, it is automatically preferred over the built-in
5
+ xml.etree module.
6
+ On Python 2.7, the cElementTree module is preferred over the pure-python
7
+ ElementTree module.
8
+
9
+ Besides exporting a unified interface, this also defines extra functions
10
+ or subclasses built-in ElementTree classes to add features that are
11
+ only availble in lxml, like OrderedDict for attributes, pretty_print and
12
+ iterwalk.
13
+ """
14
+
15
+ from fontTools.misc.textTools import tostr
16
+
17
+
18
+ XML_DECLARATION = """<?xml version='1.0' encoding='%s'?>"""
19
+
20
+ __all__ = [
21
+ # public symbols
22
+ "Comment",
23
+ "dump",
24
+ "Element",
25
+ "ElementTree",
26
+ "fromstring",
27
+ "fromstringlist",
28
+ "iselement",
29
+ "iterparse",
30
+ "parse",
31
+ "ParseError",
32
+ "PI",
33
+ "ProcessingInstruction",
34
+ "QName",
35
+ "SubElement",
36
+ "tostring",
37
+ "tostringlist",
38
+ "TreeBuilder",
39
+ "XML",
40
+ "XMLParser",
41
+ "register_namespace",
42
+ ]
43
+
44
+ try:
45
+ from lxml.etree import *
46
+
47
+ _have_lxml = True
48
+ except ImportError:
49
+ try:
50
+ from xml.etree.cElementTree import *
51
+
52
+ # the cElementTree version of XML function doesn't support
53
+ # the optional 'parser' keyword argument
54
+ from xml.etree.ElementTree import XML
55
+ except ImportError: # pragma: no cover
56
+ from xml.etree.ElementTree import *
57
+ _have_lxml = False
58
+
59
+ import sys
60
+
61
+ # dict is always ordered in python >= 3.6 and on pypy
62
+ PY36 = sys.version_info >= (3, 6)
63
+ try:
64
+ import __pypy__
65
+ except ImportError:
66
+ __pypy__ = None
67
+ _dict_is_ordered = bool(PY36 or __pypy__)
68
+ del PY36, __pypy__
69
+
70
+ if _dict_is_ordered:
71
+ _Attrib = dict
72
+ else:
73
+ from collections import OrderedDict as _Attrib
74
+
75
+ if isinstance(Element, type):
76
+ _Element = Element
77
+ else:
78
+ # in py27, cElementTree.Element cannot be subclassed, so
79
+ # we need to import the pure-python class
80
+ from xml.etree.ElementTree import Element as _Element
81
+
82
+ class Element(_Element):
83
+ """Element subclass that keeps the order of attributes."""
84
+
85
+ def __init__(self, tag, attrib=_Attrib(), **extra):
86
+ super(Element, self).__init__(tag)
87
+ self.attrib = _Attrib()
88
+ if attrib:
89
+ self.attrib.update(attrib)
90
+ if extra:
91
+ self.attrib.update(extra)
92
+
93
+ def SubElement(parent, tag, attrib=_Attrib(), **extra):
94
+ """Must override SubElement as well otherwise _elementtree.SubElement
95
+ fails if 'parent' is a subclass of Element object.
96
+ """
97
+ element = parent.__class__(tag, attrib, **extra)
98
+ parent.append(element)
99
+ return element
100
+
101
+ def _iterwalk(element, events, tag):
102
+ include = tag is None or element.tag == tag
103
+ if include and "start" in events:
104
+ yield ("start", element)
105
+ for e in element:
106
+ for item in _iterwalk(e, events, tag):
107
+ yield item
108
+ if include:
109
+ yield ("end", element)
110
+
111
+ def iterwalk(element_or_tree, events=("end",), tag=None):
112
+ """A tree walker that generates events from an existing tree as
113
+ if it was parsing XML data with iterparse().
114
+ Drop-in replacement for lxml.etree.iterwalk.
115
+ """
116
+ if iselement(element_or_tree):
117
+ element = element_or_tree
118
+ else:
119
+ element = element_or_tree.getroot()
120
+ if tag == "*":
121
+ tag = None
122
+ for item in _iterwalk(element, events, tag):
123
+ yield item
124
+
125
+ _ElementTree = ElementTree
126
+
127
+ class ElementTree(_ElementTree):
128
+ """ElementTree subclass that adds 'pretty_print' and 'doctype'
129
+ arguments to the 'write' method.
130
+ Currently these are only supported for the default XML serialization
131
+ 'method', and not also for "html" or "text", for these are delegated
132
+ to the base class.
133
+ """
134
+
135
+ def write(
136
+ self,
137
+ file_or_filename,
138
+ encoding=None,
139
+ xml_declaration=False,
140
+ method=None,
141
+ doctype=None,
142
+ pretty_print=False,
143
+ ):
144
+ if method and method != "xml":
145
+ # delegate to super-class
146
+ super(ElementTree, self).write(
147
+ file_or_filename,
148
+ encoding=encoding,
149
+ xml_declaration=xml_declaration,
150
+ method=method,
151
+ )
152
+ return
153
+
154
+ if encoding is not None and encoding.lower() == "unicode":
155
+ if xml_declaration:
156
+ raise ValueError(
157
+ "Serialisation to unicode must not request an XML declaration"
158
+ )
159
+ write_declaration = False
160
+ encoding = "unicode"
161
+ elif xml_declaration is None:
162
+ # by default, write an XML declaration only for non-standard encodings
163
+ write_declaration = encoding is not None and encoding.upper() not in (
164
+ "ASCII",
165
+ "UTF-8",
166
+ "UTF8",
167
+ "US-ASCII",
168
+ )
169
+ else:
170
+ write_declaration = xml_declaration
171
+
172
+ if encoding is None:
173
+ encoding = "ASCII"
174
+
175
+ if pretty_print:
176
+ # NOTE this will modify the tree in-place
177
+ _indent(self._root)
178
+
179
+ with _get_writer(file_or_filename, encoding) as write:
180
+ if write_declaration:
181
+ write(XML_DECLARATION % encoding.upper())
182
+ if pretty_print:
183
+ write("\n")
184
+ if doctype:
185
+ write(_tounicode(doctype))
186
+ if pretty_print:
187
+ write("\n")
188
+
189
+ qnames, namespaces = _namespaces(self._root)
190
+ _serialize_xml(write, self._root, qnames, namespaces)
191
+
192
+ import io
193
+
194
+ def tostring(
195
+ element,
196
+ encoding=None,
197
+ xml_declaration=None,
198
+ method=None,
199
+ doctype=None,
200
+ pretty_print=False,
201
+ ):
202
+ """Custom 'tostring' function that uses our ElementTree subclass, with
203
+ pretty_print support.
204
+ """
205
+ stream = io.StringIO() if encoding == "unicode" else io.BytesIO()
206
+ ElementTree(element).write(
207
+ stream,
208
+ encoding=encoding,
209
+ xml_declaration=xml_declaration,
210
+ method=method,
211
+ doctype=doctype,
212
+ pretty_print=pretty_print,
213
+ )
214
+ return stream.getvalue()
215
+
216
+ # serialization support
217
+
218
+ import re
219
+
220
+ # Valid XML strings can include any Unicode character, excluding control
221
+ # characters, the surrogate blocks, FFFE, and FFFF:
222
+ # Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
223
+ # Here we reversed the pattern to match only the invalid characters.
224
+ # For the 'narrow' python builds supporting only UCS-2, which represent
225
+ # characters beyond BMP as UTF-16 surrogate pairs, we need to pass through
226
+ # the surrogate block. I haven't found a more elegant solution...
227
+ UCS2 = sys.maxunicode < 0x10FFFF
228
+ if UCS2:
229
+ _invalid_xml_string = re.compile(
230
+ "[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uFFFE-\uFFFF]"
231
+ )
232
+ else:
233
+ _invalid_xml_string = re.compile(
234
+ "[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE-\uFFFF]"
235
+ )
236
+
237
+ def _tounicode(s):
238
+ """Test if a string is valid user input and decode it to unicode string
239
+ using ASCII encoding if it's a bytes string.
240
+ Reject all bytes/unicode input that contains non-XML characters.
241
+ Reject all bytes input that contains non-ASCII characters.
242
+ """
243
+ try:
244
+ s = tostr(s, encoding="ascii", errors="strict")
245
+ except UnicodeDecodeError:
246
+ raise ValueError(
247
+ "Bytes strings can only contain ASCII characters. "
248
+ "Use unicode strings for non-ASCII characters."
249
+ )
250
+ except AttributeError:
251
+ _raise_serialization_error(s)
252
+ if s and _invalid_xml_string.search(s):
253
+ raise ValueError(
254
+ "All strings must be XML compatible: Unicode or ASCII, "
255
+ "no NULL bytes or control characters"
256
+ )
257
+ return s
258
+
259
+ import contextlib
260
+
261
+ @contextlib.contextmanager
262
+ def _get_writer(file_or_filename, encoding):
263
+ # returns text write method and release all resources after using
264
+ try:
265
+ write = file_or_filename.write
266
+ except AttributeError:
267
+ # file_or_filename is a file name
268
+ f = open(
269
+ file_or_filename,
270
+ "w",
271
+ encoding="utf-8" if encoding == "unicode" else encoding,
272
+ errors="xmlcharrefreplace",
273
+ )
274
+ with f:
275
+ yield f.write
276
+ else:
277
+ # file_or_filename is a file-like object
278
+ # encoding determines if it is a text or binary writer
279
+ if encoding == "unicode":
280
+ # use a text writer as is
281
+ yield write
282
+ else:
283
+ # wrap a binary writer with TextIOWrapper
284
+ detach_buffer = False
285
+ if isinstance(file_or_filename, io.BufferedIOBase):
286
+ buf = file_or_filename
287
+ elif isinstance(file_or_filename, io.RawIOBase):
288
+ buf = io.BufferedWriter(file_or_filename)
289
+ detach_buffer = True
290
+ else:
291
+ # This is to handle passed objects that aren't in the
292
+ # IOBase hierarchy, but just have a write method
293
+ buf = io.BufferedIOBase()
294
+ buf.writable = lambda: True
295
+ buf.write = write
296
+ try:
297
+ # TextIOWrapper uses this methods to determine
298
+ # if BOM (for UTF-16, etc) should be added
299
+ buf.seekable = file_or_filename.seekable
300
+ buf.tell = file_or_filename.tell
301
+ except AttributeError:
302
+ pass
303
+ wrapper = io.TextIOWrapper(
304
+ buf,
305
+ encoding=encoding,
306
+ errors="xmlcharrefreplace",
307
+ newline="\n",
308
+ )
309
+ try:
310
+ yield wrapper.write
311
+ finally:
312
+ # Keep the original file open when the TextIOWrapper and
313
+ # the BufferedWriter are destroyed
314
+ wrapper.detach()
315
+ if detach_buffer:
316
+ buf.detach()
317
+
318
+ from xml.etree.ElementTree import _namespace_map
319
+
320
+ def _namespaces(elem):
321
+ # identify namespaces used in this tree
322
+
323
+ # maps qnames to *encoded* prefix:local names
324
+ qnames = {None: None}
325
+
326
+ # maps uri:s to prefixes
327
+ namespaces = {}
328
+
329
+ def add_qname(qname):
330
+ # calculate serialized qname representation
331
+ try:
332
+ qname = _tounicode(qname)
333
+ if qname[:1] == "{":
334
+ uri, tag = qname[1:].rsplit("}", 1)
335
+ prefix = namespaces.get(uri)
336
+ if prefix is None:
337
+ prefix = _namespace_map.get(uri)
338
+ if prefix is None:
339
+ prefix = "ns%d" % len(namespaces)
340
+ else:
341
+ prefix = _tounicode(prefix)
342
+ if prefix != "xml":
343
+ namespaces[uri] = prefix
344
+ if prefix:
345
+ qnames[qname] = "%s:%s" % (prefix, tag)
346
+ else:
347
+ qnames[qname] = tag # default element
348
+ else:
349
+ qnames[qname] = qname
350
+ except TypeError:
351
+ _raise_serialization_error(qname)
352
+
353
+ # populate qname and namespaces table
354
+ for elem in elem.iter():
355
+ tag = elem.tag
356
+ if isinstance(tag, QName):
357
+ if tag.text not in qnames:
358
+ add_qname(tag.text)
359
+ elif isinstance(tag, str):
360
+ if tag not in qnames:
361
+ add_qname(tag)
362
+ elif tag is not None and tag is not Comment and tag is not PI:
363
+ _raise_serialization_error(tag)
364
+ for key, value in elem.items():
365
+ if isinstance(key, QName):
366
+ key = key.text
367
+ if key not in qnames:
368
+ add_qname(key)
369
+ if isinstance(value, QName) and value.text not in qnames:
370
+ add_qname(value.text)
371
+ text = elem.text
372
+ if isinstance(text, QName) and text.text not in qnames:
373
+ add_qname(text.text)
374
+ return qnames, namespaces
375
+
376
+ def _serialize_xml(write, elem, qnames, namespaces, **kwargs):
377
+ tag = elem.tag
378
+ text = elem.text
379
+ if tag is Comment:
380
+ write("<!--%s-->" % _tounicode(text))
381
+ elif tag is ProcessingInstruction:
382
+ write("<?%s?>" % _tounicode(text))
383
+ else:
384
+ tag = qnames[_tounicode(tag) if tag is not None else None]
385
+ if tag is None:
386
+ if text:
387
+ write(_escape_cdata(text))
388
+ for e in elem:
389
+ _serialize_xml(write, e, qnames, None)
390
+ else:
391
+ write("<" + tag)
392
+ if namespaces:
393
+ for uri, prefix in sorted(
394
+ namespaces.items(), key=lambda x: x[1]
395
+ ): # sort on prefix
396
+ if prefix:
397
+ prefix = ":" + prefix
398
+ write(' xmlns%s="%s"' % (prefix, _escape_attrib(uri)))
399
+ attrs = elem.attrib
400
+ if attrs:
401
+ # try to keep existing attrib order
402
+ if len(attrs) <= 1 or type(attrs) is _Attrib:
403
+ items = attrs.items()
404
+ else:
405
+ # if plain dict, use lexical order
406
+ items = sorted(attrs.items())
407
+ for k, v in items:
408
+ if isinstance(k, QName):
409
+ k = _tounicode(k.text)
410
+ else:
411
+ k = _tounicode(k)
412
+ if isinstance(v, QName):
413
+ v = qnames[_tounicode(v.text)]
414
+ else:
415
+ v = _escape_attrib(v)
416
+ write(' %s="%s"' % (qnames[k], v))
417
+ if text is not None or len(elem):
418
+ write(">")
419
+ if text:
420
+ write(_escape_cdata(text))
421
+ for e in elem:
422
+ _serialize_xml(write, e, qnames, None)
423
+ write("</" + tag + ">")
424
+ else:
425
+ write("/>")
426
+ if elem.tail:
427
+ write(_escape_cdata(elem.tail))
428
+
429
+ def _raise_serialization_error(text):
430
+ raise TypeError("cannot serialize %r (type %s)" % (text, type(text).__name__))
431
+
432
+ def _escape_cdata(text):
433
+ # escape character data
434
+ try:
435
+ text = _tounicode(text)
436
+ # it's worth avoiding do-nothing calls for short strings
437
+ if "&" in text:
438
+ text = text.replace("&", "&amp;")
439
+ if "<" in text:
440
+ text = text.replace("<", "&lt;")
441
+ if ">" in text:
442
+ text = text.replace(">", "&gt;")
443
+ return text
444
+ except (TypeError, AttributeError):
445
+ _raise_serialization_error(text)
446
+
447
+ def _escape_attrib(text):
448
+ # escape attribute value
449
+ try:
450
+ text = _tounicode(text)
451
+ if "&" in text:
452
+ text = text.replace("&", "&amp;")
453
+ if "<" in text:
454
+ text = text.replace("<", "&lt;")
455
+ if ">" in text:
456
+ text = text.replace(">", "&gt;")
457
+ if '"' in text:
458
+ text = text.replace('"', "&quot;")
459
+ if "\n" in text:
460
+ text = text.replace("\n", "&#10;")
461
+ return text
462
+ except (TypeError, AttributeError):
463
+ _raise_serialization_error(text)
464
+
465
+ def _indent(elem, level=0):
466
+ # From http://effbot.org/zone/element-lib.htm#prettyprint
467
+ i = "\n" + level * " "
468
+ if len(elem):
469
+ if not elem.text or not elem.text.strip():
470
+ elem.text = i + " "
471
+ if not elem.tail or not elem.tail.strip():
472
+ elem.tail = i
473
+ for elem in elem:
474
+ _indent(elem, level + 1)
475
+ if not elem.tail or not elem.tail.strip():
476
+ elem.tail = i
477
+ else:
478
+ if level and (not elem.tail or not elem.tail.strip()):
479
+ elem.tail = i