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.
- fontTools/__init__.py +8 -0
- fontTools/__main__.py +35 -0
- fontTools/afmLib.py +439 -0
- fontTools/agl.py +5233 -0
- fontTools/annotations.py +30 -0
- fontTools/cffLib/CFF2ToCFF.py +258 -0
- fontTools/cffLib/CFFToCFF2.py +305 -0
- fontTools/cffLib/__init__.py +3694 -0
- fontTools/cffLib/specializer.py +927 -0
- fontTools/cffLib/transforms.py +495 -0
- fontTools/cffLib/width.py +210 -0
- fontTools/colorLib/__init__.py +0 -0
- fontTools/colorLib/builder.py +664 -0
- fontTools/colorLib/errors.py +2 -0
- fontTools/colorLib/geometry.py +143 -0
- fontTools/colorLib/table_builder.py +223 -0
- fontTools/colorLib/unbuilder.py +81 -0
- fontTools/config/__init__.py +90 -0
- fontTools/cu2qu/__init__.py +15 -0
- fontTools/cu2qu/__main__.py +6 -0
- fontTools/cu2qu/benchmark.py +54 -0
- fontTools/cu2qu/cli.py +198 -0
- fontTools/cu2qu/cu2qu.c +15817 -0
- fontTools/cu2qu/cu2qu.cp311-win32.pyd +0 -0
- fontTools/cu2qu/cu2qu.py +563 -0
- fontTools/cu2qu/errors.py +77 -0
- fontTools/cu2qu/ufo.py +363 -0
- fontTools/designspaceLib/__init__.py +3343 -0
- fontTools/designspaceLib/__main__.py +6 -0
- fontTools/designspaceLib/split.py +475 -0
- fontTools/designspaceLib/statNames.py +260 -0
- fontTools/designspaceLib/types.py +147 -0
- fontTools/encodings/MacRoman.py +258 -0
- fontTools/encodings/StandardEncoding.py +258 -0
- fontTools/encodings/__init__.py +1 -0
- fontTools/encodings/codecs.py +135 -0
- fontTools/feaLib/__init__.py +4 -0
- fontTools/feaLib/__main__.py +78 -0
- fontTools/feaLib/ast.py +2143 -0
- fontTools/feaLib/builder.py +1814 -0
- fontTools/feaLib/error.py +22 -0
- fontTools/feaLib/lexer.c +17029 -0
- fontTools/feaLib/lexer.cp311-win32.pyd +0 -0
- fontTools/feaLib/lexer.py +287 -0
- fontTools/feaLib/location.py +12 -0
- fontTools/feaLib/lookupDebugInfo.py +12 -0
- fontTools/feaLib/parser.py +2394 -0
- fontTools/feaLib/variableScalar.py +118 -0
- fontTools/fontBuilder.py +1014 -0
- fontTools/help.py +36 -0
- fontTools/merge/__init__.py +248 -0
- fontTools/merge/__main__.py +6 -0
- fontTools/merge/base.py +81 -0
- fontTools/merge/cmap.py +173 -0
- fontTools/merge/layout.py +526 -0
- fontTools/merge/options.py +85 -0
- fontTools/merge/tables.py +352 -0
- fontTools/merge/unicode.py +78 -0
- fontTools/merge/util.py +143 -0
- fontTools/misc/__init__.py +1 -0
- fontTools/misc/arrayTools.py +424 -0
- fontTools/misc/bezierTools.c +39731 -0
- fontTools/misc/bezierTools.cp311-win32.pyd +0 -0
- fontTools/misc/bezierTools.py +1500 -0
- fontTools/misc/classifyTools.py +170 -0
- fontTools/misc/cliTools.py +53 -0
- fontTools/misc/configTools.py +349 -0
- fontTools/misc/cython.py +27 -0
- fontTools/misc/dictTools.py +83 -0
- fontTools/misc/eexec.py +119 -0
- fontTools/misc/encodingTools.py +72 -0
- fontTools/misc/enumTools.py +23 -0
- fontTools/misc/etree.py +456 -0
- fontTools/misc/filenames.py +245 -0
- fontTools/misc/filesystem/__init__.py +68 -0
- fontTools/misc/filesystem/_base.py +134 -0
- fontTools/misc/filesystem/_copy.py +45 -0
- fontTools/misc/filesystem/_errors.py +54 -0
- fontTools/misc/filesystem/_info.py +75 -0
- fontTools/misc/filesystem/_osfs.py +164 -0
- fontTools/misc/filesystem/_path.py +67 -0
- fontTools/misc/filesystem/_subfs.py +92 -0
- fontTools/misc/filesystem/_tempfs.py +34 -0
- fontTools/misc/filesystem/_tools.py +34 -0
- fontTools/misc/filesystem/_walk.py +55 -0
- fontTools/misc/filesystem/_zipfs.py +204 -0
- fontTools/misc/fixedTools.py +253 -0
- fontTools/misc/intTools.py +25 -0
- fontTools/misc/iterTools.py +12 -0
- fontTools/misc/lazyTools.py +42 -0
- fontTools/misc/loggingTools.py +543 -0
- fontTools/misc/macCreatorType.py +56 -0
- fontTools/misc/macRes.py +261 -0
- fontTools/misc/plistlib/__init__.py +681 -0
- fontTools/misc/plistlib/py.typed +0 -0
- fontTools/misc/psCharStrings.py +1511 -0
- fontTools/misc/psLib.py +398 -0
- fontTools/misc/psOperators.py +572 -0
- fontTools/misc/py23.py +96 -0
- fontTools/misc/roundTools.py +110 -0
- fontTools/misc/sstruct.py +227 -0
- fontTools/misc/symfont.py +242 -0
- fontTools/misc/testTools.py +233 -0
- fontTools/misc/textTools.py +156 -0
- fontTools/misc/timeTools.py +88 -0
- fontTools/misc/transform.py +516 -0
- fontTools/misc/treeTools.py +45 -0
- fontTools/misc/vector.py +147 -0
- fontTools/misc/visitor.py +158 -0
- fontTools/misc/xmlReader.py +188 -0
- fontTools/misc/xmlWriter.py +231 -0
- fontTools/mtiLib/__init__.py +1400 -0
- fontTools/mtiLib/__main__.py +5 -0
- fontTools/otlLib/__init__.py +1 -0
- fontTools/otlLib/builder.py +3465 -0
- fontTools/otlLib/error.py +11 -0
- fontTools/otlLib/maxContextCalc.py +96 -0
- fontTools/otlLib/optimize/__init__.py +53 -0
- fontTools/otlLib/optimize/__main__.py +6 -0
- fontTools/otlLib/optimize/gpos.py +439 -0
- fontTools/pens/__init__.py +1 -0
- fontTools/pens/areaPen.py +52 -0
- fontTools/pens/basePen.py +475 -0
- fontTools/pens/boundsPen.py +98 -0
- fontTools/pens/cairoPen.py +26 -0
- fontTools/pens/cocoaPen.py +26 -0
- fontTools/pens/cu2quPen.py +325 -0
- fontTools/pens/explicitClosingLinePen.py +101 -0
- fontTools/pens/filterPen.py +433 -0
- fontTools/pens/freetypePen.py +462 -0
- fontTools/pens/hashPointPen.py +89 -0
- fontTools/pens/momentsPen.c +13378 -0
- fontTools/pens/momentsPen.cp311-win32.pyd +0 -0
- fontTools/pens/momentsPen.py +879 -0
- fontTools/pens/perimeterPen.py +69 -0
- fontTools/pens/pointInsidePen.py +192 -0
- fontTools/pens/pointPen.py +643 -0
- fontTools/pens/qtPen.py +29 -0
- fontTools/pens/qu2cuPen.py +105 -0
- fontTools/pens/quartzPen.py +43 -0
- fontTools/pens/recordingPen.py +335 -0
- fontTools/pens/reportLabPen.py +79 -0
- fontTools/pens/reverseContourPen.py +96 -0
- fontTools/pens/roundingPen.py +130 -0
- fontTools/pens/statisticsPen.py +312 -0
- fontTools/pens/svgPathPen.py +310 -0
- fontTools/pens/t2CharStringPen.py +88 -0
- fontTools/pens/teePen.py +55 -0
- fontTools/pens/transformPen.py +115 -0
- fontTools/pens/ttGlyphPen.py +335 -0
- fontTools/pens/wxPen.py +29 -0
- fontTools/qu2cu/__init__.py +15 -0
- fontTools/qu2cu/__main__.py +7 -0
- fontTools/qu2cu/benchmark.py +56 -0
- fontTools/qu2cu/cli.py +125 -0
- fontTools/qu2cu/qu2cu.c +16682 -0
- fontTools/qu2cu/qu2cu.cp311-win32.pyd +0 -0
- fontTools/qu2cu/qu2cu.py +405 -0
- fontTools/subset/__init__.py +4096 -0
- fontTools/subset/__main__.py +6 -0
- fontTools/subset/cff.py +184 -0
- fontTools/subset/svg.py +253 -0
- fontTools/subset/util.py +25 -0
- fontTools/svgLib/__init__.py +3 -0
- fontTools/svgLib/path/__init__.py +65 -0
- fontTools/svgLib/path/arc.py +154 -0
- fontTools/svgLib/path/parser.py +322 -0
- fontTools/svgLib/path/shapes.py +183 -0
- fontTools/t1Lib/__init__.py +648 -0
- fontTools/tfmLib.py +460 -0
- fontTools/ttLib/__init__.py +30 -0
- fontTools/ttLib/__main__.py +148 -0
- fontTools/ttLib/macUtils.py +54 -0
- fontTools/ttLib/removeOverlaps.py +395 -0
- fontTools/ttLib/reorderGlyphs.py +285 -0
- fontTools/ttLib/scaleUpem.py +436 -0
- fontTools/ttLib/sfnt.py +661 -0
- fontTools/ttLib/standardGlyphOrder.py +271 -0
- fontTools/ttLib/tables/B_A_S_E_.py +14 -0
- fontTools/ttLib/tables/BitmapGlyphMetrics.py +64 -0
- fontTools/ttLib/tables/C_B_D_T_.py +113 -0
- fontTools/ttLib/tables/C_B_L_C_.py +19 -0
- fontTools/ttLib/tables/C_F_F_.py +61 -0
- fontTools/ttLib/tables/C_F_F__2.py +26 -0
- fontTools/ttLib/tables/C_O_L_R_.py +165 -0
- fontTools/ttLib/tables/C_P_A_L_.py +305 -0
- fontTools/ttLib/tables/D_S_I_G_.py +158 -0
- fontTools/ttLib/tables/D__e_b_g.py +35 -0
- fontTools/ttLib/tables/DefaultTable.py +49 -0
- fontTools/ttLib/tables/E_B_D_T_.py +835 -0
- fontTools/ttLib/tables/E_B_L_C_.py +718 -0
- fontTools/ttLib/tables/F_F_T_M_.py +52 -0
- fontTools/ttLib/tables/F__e_a_t.py +149 -0
- fontTools/ttLib/tables/G_D_E_F_.py +13 -0
- fontTools/ttLib/tables/G_M_A_P_.py +148 -0
- fontTools/ttLib/tables/G_P_K_G_.py +133 -0
- fontTools/ttLib/tables/G_P_O_S_.py +14 -0
- fontTools/ttLib/tables/G_S_U_B_.py +13 -0
- fontTools/ttLib/tables/G_V_A_R_.py +5 -0
- fontTools/ttLib/tables/G__l_a_t.py +235 -0
- fontTools/ttLib/tables/G__l_o_c.py +85 -0
- fontTools/ttLib/tables/H_V_A_R_.py +13 -0
- fontTools/ttLib/tables/J_S_T_F_.py +13 -0
- fontTools/ttLib/tables/L_T_S_H_.py +58 -0
- fontTools/ttLib/tables/M_A_T_H_.py +13 -0
- fontTools/ttLib/tables/M_E_T_A_.py +352 -0
- fontTools/ttLib/tables/M_V_A_R_.py +13 -0
- fontTools/ttLib/tables/O_S_2f_2.py +752 -0
- fontTools/ttLib/tables/S_I_N_G_.py +99 -0
- fontTools/ttLib/tables/S_T_A_T_.py +15 -0
- fontTools/ttLib/tables/S_V_G_.py +223 -0
- fontTools/ttLib/tables/S__i_l_f.py +1040 -0
- fontTools/ttLib/tables/S__i_l_l.py +92 -0
- fontTools/ttLib/tables/T_S_I_B_.py +13 -0
- fontTools/ttLib/tables/T_S_I_C_.py +14 -0
- fontTools/ttLib/tables/T_S_I_D_.py +13 -0
- fontTools/ttLib/tables/T_S_I_J_.py +13 -0
- fontTools/ttLib/tables/T_S_I_P_.py +13 -0
- fontTools/ttLib/tables/T_S_I_S_.py +13 -0
- fontTools/ttLib/tables/T_S_I_V_.py +26 -0
- fontTools/ttLib/tables/T_S_I__0.py +70 -0
- fontTools/ttLib/tables/T_S_I__1.py +163 -0
- fontTools/ttLib/tables/T_S_I__2.py +17 -0
- fontTools/ttLib/tables/T_S_I__3.py +22 -0
- fontTools/ttLib/tables/T_S_I__5.py +60 -0
- fontTools/ttLib/tables/T_T_F_A_.py +14 -0
- fontTools/ttLib/tables/TupleVariation.py +884 -0
- fontTools/ttLib/tables/V_A_R_C_.py +12 -0
- fontTools/ttLib/tables/V_D_M_X_.py +249 -0
- fontTools/ttLib/tables/V_O_R_G_.py +165 -0
- fontTools/ttLib/tables/V_V_A_R_.py +13 -0
- fontTools/ttLib/tables/__init__.py +98 -0
- fontTools/ttLib/tables/_a_n_k_r.py +15 -0
- fontTools/ttLib/tables/_a_v_a_r.py +193 -0
- fontTools/ttLib/tables/_b_s_l_n.py +15 -0
- fontTools/ttLib/tables/_c_i_d_g.py +24 -0
- fontTools/ttLib/tables/_c_m_a_p.py +1591 -0
- fontTools/ttLib/tables/_c_v_a_r.py +94 -0
- fontTools/ttLib/tables/_c_v_t.py +56 -0
- fontTools/ttLib/tables/_f_e_a_t.py +15 -0
- fontTools/ttLib/tables/_f_p_g_m.py +62 -0
- fontTools/ttLib/tables/_f_v_a_r.py +261 -0
- fontTools/ttLib/tables/_g_a_s_p.py +63 -0
- fontTools/ttLib/tables/_g_c_i_d.py +13 -0
- fontTools/ttLib/tables/_g_l_y_f.py +2311 -0
- fontTools/ttLib/tables/_g_v_a_r.py +340 -0
- fontTools/ttLib/tables/_h_d_m_x.py +127 -0
- fontTools/ttLib/tables/_h_e_a_d.py +130 -0
- fontTools/ttLib/tables/_h_h_e_a.py +147 -0
- fontTools/ttLib/tables/_h_m_t_x.py +164 -0
- fontTools/ttLib/tables/_k_e_r_n.py +289 -0
- fontTools/ttLib/tables/_l_c_a_r.py +13 -0
- fontTools/ttLib/tables/_l_o_c_a.py +70 -0
- fontTools/ttLib/tables/_l_t_a_g.py +72 -0
- fontTools/ttLib/tables/_m_a_x_p.py +147 -0
- fontTools/ttLib/tables/_m_e_t_a.py +112 -0
- fontTools/ttLib/tables/_m_o_r_t.py +14 -0
- fontTools/ttLib/tables/_m_o_r_x.py +15 -0
- fontTools/ttLib/tables/_n_a_m_e.py +1242 -0
- fontTools/ttLib/tables/_o_p_b_d.py +14 -0
- fontTools/ttLib/tables/_p_o_s_t.py +319 -0
- fontTools/ttLib/tables/_p_r_e_p.py +16 -0
- fontTools/ttLib/tables/_p_r_o_p.py +12 -0
- fontTools/ttLib/tables/_s_b_i_x.py +129 -0
- fontTools/ttLib/tables/_t_r_a_k.py +332 -0
- fontTools/ttLib/tables/_v_h_e_a.py +139 -0
- fontTools/ttLib/tables/_v_m_t_x.py +19 -0
- fontTools/ttLib/tables/asciiTable.py +20 -0
- fontTools/ttLib/tables/grUtils.py +92 -0
- fontTools/ttLib/tables/otBase.py +1458 -0
- fontTools/ttLib/tables/otConverters.py +2068 -0
- fontTools/ttLib/tables/otData.py +6400 -0
- fontTools/ttLib/tables/otTables.py +2703 -0
- fontTools/ttLib/tables/otTraverse.py +163 -0
- fontTools/ttLib/tables/sbixGlyph.py +149 -0
- fontTools/ttLib/tables/sbixStrike.py +177 -0
- fontTools/ttLib/tables/table_API_readme.txt +91 -0
- fontTools/ttLib/tables/ttProgram.py +594 -0
- fontTools/ttLib/ttCollection.py +125 -0
- fontTools/ttLib/ttFont.py +1148 -0
- fontTools/ttLib/ttGlyphSet.py +490 -0
- fontTools/ttLib/ttVisitor.py +32 -0
- fontTools/ttLib/woff2.py +1680 -0
- fontTools/ttx.py +479 -0
- fontTools/ufoLib/__init__.py +2575 -0
- fontTools/ufoLib/converters.py +407 -0
- fontTools/ufoLib/errors.py +30 -0
- fontTools/ufoLib/etree.py +6 -0
- fontTools/ufoLib/filenames.py +356 -0
- fontTools/ufoLib/glifLib.py +2120 -0
- fontTools/ufoLib/kerning.py +141 -0
- fontTools/ufoLib/plistlib.py +47 -0
- fontTools/ufoLib/pointPen.py +6 -0
- fontTools/ufoLib/utils.py +107 -0
- fontTools/ufoLib/validators.py +1208 -0
- fontTools/unicode.py +50 -0
- fontTools/unicodedata/Blocks.py +817 -0
- fontTools/unicodedata/Mirrored.py +446 -0
- fontTools/unicodedata/OTTags.py +50 -0
- fontTools/unicodedata/ScriptExtensions.py +832 -0
- fontTools/unicodedata/Scripts.py +3639 -0
- fontTools/unicodedata/__init__.py +306 -0
- fontTools/varLib/__init__.py +1600 -0
- fontTools/varLib/__main__.py +6 -0
- fontTools/varLib/avar/__init__.py +0 -0
- fontTools/varLib/avar/__main__.py +72 -0
- fontTools/varLib/avar/build.py +79 -0
- fontTools/varLib/avar/map.py +108 -0
- fontTools/varLib/avar/plan.py +1004 -0
- fontTools/varLib/avar/unbuild.py +271 -0
- fontTools/varLib/avarPlanner.py +8 -0
- fontTools/varLib/builder.py +215 -0
- fontTools/varLib/cff.py +631 -0
- fontTools/varLib/errors.py +219 -0
- fontTools/varLib/featureVars.py +703 -0
- fontTools/varLib/hvar.py +113 -0
- fontTools/varLib/instancer/__init__.py +2052 -0
- fontTools/varLib/instancer/__main__.py +5 -0
- fontTools/varLib/instancer/featureVars.py +190 -0
- fontTools/varLib/instancer/names.py +388 -0
- fontTools/varLib/instancer/solver.py +309 -0
- fontTools/varLib/interpolatable.py +1209 -0
- fontTools/varLib/interpolatableHelpers.py +399 -0
- fontTools/varLib/interpolatablePlot.py +1269 -0
- fontTools/varLib/interpolatableTestContourOrder.py +82 -0
- fontTools/varLib/interpolatableTestStartingPoint.py +107 -0
- fontTools/varLib/interpolate_layout.py +124 -0
- fontTools/varLib/iup.c +19815 -0
- fontTools/varLib/iup.cp311-win32.pyd +0 -0
- fontTools/varLib/iup.py +490 -0
- fontTools/varLib/merger.py +1717 -0
- fontTools/varLib/models.py +642 -0
- fontTools/varLib/multiVarStore.py +253 -0
- fontTools/varLib/mutator.py +529 -0
- fontTools/varLib/mvar.py +40 -0
- fontTools/varLib/plot.py +238 -0
- fontTools/varLib/stat.py +149 -0
- fontTools/varLib/varStore.py +739 -0
- fontTools/voltLib/__init__.py +5 -0
- fontTools/voltLib/__main__.py +206 -0
- fontTools/voltLib/ast.py +452 -0
- fontTools/voltLib/error.py +12 -0
- fontTools/voltLib/lexer.py +99 -0
- fontTools/voltLib/parser.py +664 -0
- fontTools/voltLib/voltToFea.py +911 -0
- fonttools-4.60.2.data/data/share/man/man1/ttx.1 +225 -0
- fonttools-4.60.2.dist-info/METADATA +2250 -0
- fonttools-4.60.2.dist-info/RECORD +353 -0
- fonttools-4.60.2.dist-info/WHEEL +5 -0
- fonttools-4.60.2.dist-info/entry_points.txt +5 -0
- fonttools-4.60.2.dist-info/licenses/LICENSE +21 -0
- fonttools-4.60.2.dist-info/licenses/LICENSE.external +388 -0
- fonttools-4.60.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
_accessstrings = {0: "", 1: "readonly", 2: "executeonly", 3: "noaccess"}
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ps_object(object):
|
|
5
|
+
literal = 1
|
|
6
|
+
access = 0
|
|
7
|
+
value = None
|
|
8
|
+
|
|
9
|
+
def __init__(self, value):
|
|
10
|
+
self.value = value
|
|
11
|
+
self.type = self.__class__.__name__[3:] + "type"
|
|
12
|
+
|
|
13
|
+
def __repr__(self):
|
|
14
|
+
return "<%s %s>" % (self.__class__.__name__[3:], repr(self.value))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ps_operator(ps_object):
|
|
18
|
+
literal = 0
|
|
19
|
+
|
|
20
|
+
def __init__(self, name, function):
|
|
21
|
+
self.name = name
|
|
22
|
+
self.function = function
|
|
23
|
+
self.type = self.__class__.__name__[3:] + "type"
|
|
24
|
+
|
|
25
|
+
def __repr__(self):
|
|
26
|
+
return "<operator %s>" % self.name
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ps_procedure(ps_object):
|
|
30
|
+
literal = 0
|
|
31
|
+
|
|
32
|
+
def __repr__(self):
|
|
33
|
+
return "<procedure>"
|
|
34
|
+
|
|
35
|
+
def __str__(self):
|
|
36
|
+
psstring = "{"
|
|
37
|
+
for i in range(len(self.value)):
|
|
38
|
+
if i:
|
|
39
|
+
psstring = psstring + " " + str(self.value[i])
|
|
40
|
+
else:
|
|
41
|
+
psstring = psstring + str(self.value[i])
|
|
42
|
+
return psstring + "}"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ps_name(ps_object):
|
|
46
|
+
literal = 0
|
|
47
|
+
|
|
48
|
+
def __str__(self):
|
|
49
|
+
if self.literal:
|
|
50
|
+
return "/" + self.value
|
|
51
|
+
else:
|
|
52
|
+
return self.value
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ps_literal(ps_object):
|
|
56
|
+
def __str__(self):
|
|
57
|
+
return "/" + self.value
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class ps_array(ps_object):
|
|
61
|
+
def __str__(self):
|
|
62
|
+
psstring = "["
|
|
63
|
+
for i in range(len(self.value)):
|
|
64
|
+
item = self.value[i]
|
|
65
|
+
access = _accessstrings[item.access]
|
|
66
|
+
if access:
|
|
67
|
+
access = " " + access
|
|
68
|
+
if i:
|
|
69
|
+
psstring = psstring + " " + str(item) + access
|
|
70
|
+
else:
|
|
71
|
+
psstring = psstring + str(item) + access
|
|
72
|
+
return psstring + "]"
|
|
73
|
+
|
|
74
|
+
def __repr__(self):
|
|
75
|
+
return "<array>"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
_type1_pre_eexec_order = [
|
|
79
|
+
"FontInfo",
|
|
80
|
+
"FontName",
|
|
81
|
+
"Encoding",
|
|
82
|
+
"PaintType",
|
|
83
|
+
"FontType",
|
|
84
|
+
"FontMatrix",
|
|
85
|
+
"FontBBox",
|
|
86
|
+
"UniqueID",
|
|
87
|
+
"Metrics",
|
|
88
|
+
"StrokeWidth",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
_type1_fontinfo_order = [
|
|
92
|
+
"version",
|
|
93
|
+
"Notice",
|
|
94
|
+
"FullName",
|
|
95
|
+
"FamilyName",
|
|
96
|
+
"Weight",
|
|
97
|
+
"ItalicAngle",
|
|
98
|
+
"isFixedPitch",
|
|
99
|
+
"UnderlinePosition",
|
|
100
|
+
"UnderlineThickness",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
_type1_post_eexec_order = ["Private", "CharStrings", "FID"]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _type1_item_repr(key, value):
|
|
107
|
+
psstring = ""
|
|
108
|
+
access = _accessstrings[value.access]
|
|
109
|
+
if access:
|
|
110
|
+
access = access + " "
|
|
111
|
+
if key == "CharStrings":
|
|
112
|
+
psstring = psstring + "/%s %s def\n" % (
|
|
113
|
+
key,
|
|
114
|
+
_type1_CharString_repr(value.value),
|
|
115
|
+
)
|
|
116
|
+
elif key == "Encoding":
|
|
117
|
+
psstring = psstring + _type1_Encoding_repr(value, access)
|
|
118
|
+
else:
|
|
119
|
+
psstring = psstring + "/%s %s %sdef\n" % (str(key), str(value), access)
|
|
120
|
+
return psstring
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _type1_Encoding_repr(encoding, access):
|
|
124
|
+
encoding = encoding.value
|
|
125
|
+
psstring = "/Encoding 256 array\n0 1 255 {1 index exch /.notdef put} for\n"
|
|
126
|
+
for i in range(256):
|
|
127
|
+
name = encoding[i].value
|
|
128
|
+
if name != ".notdef":
|
|
129
|
+
psstring = psstring + "dup %d /%s put\n" % (i, name)
|
|
130
|
+
return psstring + access + "def\n"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _type1_CharString_repr(charstrings):
|
|
134
|
+
items = sorted(charstrings.items())
|
|
135
|
+
return "xxx"
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class ps_font(ps_object):
|
|
139
|
+
def __str__(self):
|
|
140
|
+
psstring = "%d dict dup begin\n" % len(self.value)
|
|
141
|
+
for key in _type1_pre_eexec_order:
|
|
142
|
+
try:
|
|
143
|
+
value = self.value[key]
|
|
144
|
+
except KeyError:
|
|
145
|
+
pass
|
|
146
|
+
else:
|
|
147
|
+
psstring = psstring + _type1_item_repr(key, value)
|
|
148
|
+
items = sorted(self.value.items())
|
|
149
|
+
for key, value in items:
|
|
150
|
+
if key not in _type1_pre_eexec_order + _type1_post_eexec_order:
|
|
151
|
+
psstring = psstring + _type1_item_repr(key, value)
|
|
152
|
+
psstring = psstring + "currentdict end\ncurrentfile eexec\ndup "
|
|
153
|
+
for key in _type1_post_eexec_order:
|
|
154
|
+
try:
|
|
155
|
+
value = self.value[key]
|
|
156
|
+
except KeyError:
|
|
157
|
+
pass
|
|
158
|
+
else:
|
|
159
|
+
psstring = psstring + _type1_item_repr(key, value)
|
|
160
|
+
return (
|
|
161
|
+
psstring
|
|
162
|
+
+ "dup/FontName get exch definefont pop\nmark currentfile closefile\n"
|
|
163
|
+
+ 8 * (64 * "0" + "\n")
|
|
164
|
+
+ "cleartomark"
|
|
165
|
+
+ "\n"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
def __repr__(self):
|
|
169
|
+
return "<font>"
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class ps_file(ps_object):
|
|
173
|
+
pass
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class ps_dict(ps_object):
|
|
177
|
+
def __str__(self):
|
|
178
|
+
psstring = "%d dict dup begin\n" % len(self.value)
|
|
179
|
+
items = sorted(self.value.items())
|
|
180
|
+
for key, value in items:
|
|
181
|
+
access = _accessstrings[value.access]
|
|
182
|
+
if access:
|
|
183
|
+
access = access + " "
|
|
184
|
+
psstring = psstring + "/%s %s %sdef\n" % (str(key), str(value), access)
|
|
185
|
+
return psstring + "end "
|
|
186
|
+
|
|
187
|
+
def __repr__(self):
|
|
188
|
+
return "<dict>"
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class ps_mark(ps_object):
|
|
192
|
+
def __init__(self):
|
|
193
|
+
self.value = "mark"
|
|
194
|
+
self.type = self.__class__.__name__[3:] + "type"
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class ps_procmark(ps_object):
|
|
198
|
+
def __init__(self):
|
|
199
|
+
self.value = "procmark"
|
|
200
|
+
self.type = self.__class__.__name__[3:] + "type"
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class ps_null(ps_object):
|
|
204
|
+
def __init__(self):
|
|
205
|
+
self.type = self.__class__.__name__[3:] + "type"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class ps_boolean(ps_object):
|
|
209
|
+
def __str__(self):
|
|
210
|
+
if self.value:
|
|
211
|
+
return "true"
|
|
212
|
+
else:
|
|
213
|
+
return "false"
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class ps_string(ps_object):
|
|
217
|
+
def __str__(self):
|
|
218
|
+
return "(%s)" % repr(self.value)[1:-1]
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class ps_integer(ps_object):
|
|
222
|
+
def __str__(self):
|
|
223
|
+
return repr(self.value)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class ps_real(ps_object):
|
|
227
|
+
def __str__(self):
|
|
228
|
+
return repr(self.value)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class PSOperators(object):
|
|
232
|
+
def ps_def(self):
|
|
233
|
+
obj = self.pop()
|
|
234
|
+
name = self.pop()
|
|
235
|
+
self.dictstack[-1][name.value] = obj
|
|
236
|
+
|
|
237
|
+
def ps_bind(self):
|
|
238
|
+
proc = self.pop("proceduretype")
|
|
239
|
+
self.proc_bind(proc)
|
|
240
|
+
self.push(proc)
|
|
241
|
+
|
|
242
|
+
def proc_bind(self, proc):
|
|
243
|
+
for i in range(len(proc.value)):
|
|
244
|
+
item = proc.value[i]
|
|
245
|
+
if item.type == "proceduretype":
|
|
246
|
+
self.proc_bind(item)
|
|
247
|
+
else:
|
|
248
|
+
if not item.literal:
|
|
249
|
+
try:
|
|
250
|
+
obj = self.resolve_name(item.value)
|
|
251
|
+
except:
|
|
252
|
+
pass
|
|
253
|
+
else:
|
|
254
|
+
if obj.type == "operatortype":
|
|
255
|
+
proc.value[i] = obj
|
|
256
|
+
|
|
257
|
+
def ps_exch(self):
|
|
258
|
+
if len(self.stack) < 2:
|
|
259
|
+
raise RuntimeError("stack underflow")
|
|
260
|
+
obj1 = self.pop()
|
|
261
|
+
obj2 = self.pop()
|
|
262
|
+
self.push(obj1)
|
|
263
|
+
self.push(obj2)
|
|
264
|
+
|
|
265
|
+
def ps_dup(self):
|
|
266
|
+
if not self.stack:
|
|
267
|
+
raise RuntimeError("stack underflow")
|
|
268
|
+
self.push(self.stack[-1])
|
|
269
|
+
|
|
270
|
+
def ps_exec(self):
|
|
271
|
+
obj = self.pop()
|
|
272
|
+
if obj.type == "proceduretype":
|
|
273
|
+
self.call_procedure(obj)
|
|
274
|
+
else:
|
|
275
|
+
self.handle_object(obj)
|
|
276
|
+
|
|
277
|
+
def ps_count(self):
|
|
278
|
+
self.push(ps_integer(len(self.stack)))
|
|
279
|
+
|
|
280
|
+
def ps_eq(self):
|
|
281
|
+
any1 = self.pop()
|
|
282
|
+
any2 = self.pop()
|
|
283
|
+
self.push(ps_boolean(any1.value == any2.value))
|
|
284
|
+
|
|
285
|
+
def ps_ne(self):
|
|
286
|
+
any1 = self.pop()
|
|
287
|
+
any2 = self.pop()
|
|
288
|
+
self.push(ps_boolean(any1.value != any2.value))
|
|
289
|
+
|
|
290
|
+
def ps_cvx(self):
|
|
291
|
+
obj = self.pop()
|
|
292
|
+
obj.literal = 0
|
|
293
|
+
self.push(obj)
|
|
294
|
+
|
|
295
|
+
def ps_matrix(self):
|
|
296
|
+
matrix = [
|
|
297
|
+
ps_real(1.0),
|
|
298
|
+
ps_integer(0),
|
|
299
|
+
ps_integer(0),
|
|
300
|
+
ps_real(1.0),
|
|
301
|
+
ps_integer(0),
|
|
302
|
+
ps_integer(0),
|
|
303
|
+
]
|
|
304
|
+
self.push(ps_array(matrix))
|
|
305
|
+
|
|
306
|
+
def ps_string(self):
|
|
307
|
+
num = self.pop("integertype").value
|
|
308
|
+
self.push(ps_string("\0" * num))
|
|
309
|
+
|
|
310
|
+
def ps_type(self):
|
|
311
|
+
obj = self.pop()
|
|
312
|
+
self.push(ps_string(obj.type))
|
|
313
|
+
|
|
314
|
+
def ps_store(self):
|
|
315
|
+
value = self.pop()
|
|
316
|
+
key = self.pop()
|
|
317
|
+
name = key.value
|
|
318
|
+
for i in range(len(self.dictstack) - 1, -1, -1):
|
|
319
|
+
if name in self.dictstack[i]:
|
|
320
|
+
self.dictstack[i][name] = value
|
|
321
|
+
break
|
|
322
|
+
self.dictstack[-1][name] = value
|
|
323
|
+
|
|
324
|
+
def ps_where(self):
|
|
325
|
+
name = self.pop()
|
|
326
|
+
# XXX
|
|
327
|
+
self.push(ps_boolean(0))
|
|
328
|
+
|
|
329
|
+
def ps_systemdict(self):
|
|
330
|
+
self.push(ps_dict(self.dictstack[0]))
|
|
331
|
+
|
|
332
|
+
def ps_userdict(self):
|
|
333
|
+
self.push(ps_dict(self.dictstack[1]))
|
|
334
|
+
|
|
335
|
+
def ps_currentdict(self):
|
|
336
|
+
self.push(ps_dict(self.dictstack[-1]))
|
|
337
|
+
|
|
338
|
+
def ps_currentfile(self):
|
|
339
|
+
self.push(ps_file(self.tokenizer))
|
|
340
|
+
|
|
341
|
+
def ps_eexec(self):
|
|
342
|
+
f = self.pop("filetype").value
|
|
343
|
+
f.starteexec()
|
|
344
|
+
|
|
345
|
+
def ps_closefile(self):
|
|
346
|
+
f = self.pop("filetype").value
|
|
347
|
+
f.skipwhite()
|
|
348
|
+
f.stopeexec()
|
|
349
|
+
|
|
350
|
+
def ps_cleartomark(self):
|
|
351
|
+
obj = self.pop()
|
|
352
|
+
while obj != self.mark:
|
|
353
|
+
obj = self.pop()
|
|
354
|
+
|
|
355
|
+
def ps_readstring(self, ps_boolean=ps_boolean, len=len):
|
|
356
|
+
s = self.pop("stringtype")
|
|
357
|
+
oldstr = s.value
|
|
358
|
+
f = self.pop("filetype")
|
|
359
|
+
# pad = file.value.read(1)
|
|
360
|
+
# for StringIO, this is faster
|
|
361
|
+
f.value.pos = f.value.pos + 1
|
|
362
|
+
newstr = f.value.read(len(oldstr))
|
|
363
|
+
s.value = newstr
|
|
364
|
+
self.push(s)
|
|
365
|
+
self.push(ps_boolean(len(oldstr) == len(newstr)))
|
|
366
|
+
|
|
367
|
+
def ps_known(self):
|
|
368
|
+
key = self.pop()
|
|
369
|
+
d = self.pop("dicttype", "fonttype")
|
|
370
|
+
self.push(ps_boolean(key.value in d.value))
|
|
371
|
+
|
|
372
|
+
def ps_if(self):
|
|
373
|
+
proc = self.pop("proceduretype")
|
|
374
|
+
if self.pop("booleantype").value:
|
|
375
|
+
self.call_procedure(proc)
|
|
376
|
+
|
|
377
|
+
def ps_ifelse(self):
|
|
378
|
+
proc2 = self.pop("proceduretype")
|
|
379
|
+
proc1 = self.pop("proceduretype")
|
|
380
|
+
if self.pop("booleantype").value:
|
|
381
|
+
self.call_procedure(proc1)
|
|
382
|
+
else:
|
|
383
|
+
self.call_procedure(proc2)
|
|
384
|
+
|
|
385
|
+
def ps_readonly(self):
|
|
386
|
+
obj = self.pop()
|
|
387
|
+
if obj.access < 1:
|
|
388
|
+
obj.access = 1
|
|
389
|
+
self.push(obj)
|
|
390
|
+
|
|
391
|
+
def ps_executeonly(self):
|
|
392
|
+
obj = self.pop()
|
|
393
|
+
if obj.access < 2:
|
|
394
|
+
obj.access = 2
|
|
395
|
+
self.push(obj)
|
|
396
|
+
|
|
397
|
+
def ps_noaccess(self):
|
|
398
|
+
obj = self.pop()
|
|
399
|
+
if obj.access < 3:
|
|
400
|
+
obj.access = 3
|
|
401
|
+
self.push(obj)
|
|
402
|
+
|
|
403
|
+
def ps_not(self):
|
|
404
|
+
obj = self.pop("booleantype", "integertype")
|
|
405
|
+
if obj.type == "booleantype":
|
|
406
|
+
self.push(ps_boolean(not obj.value))
|
|
407
|
+
else:
|
|
408
|
+
self.push(ps_integer(~obj.value))
|
|
409
|
+
|
|
410
|
+
def ps_print(self):
|
|
411
|
+
str = self.pop("stringtype")
|
|
412
|
+
print("PS output --->", str.value)
|
|
413
|
+
|
|
414
|
+
def ps_anchorsearch(self):
|
|
415
|
+
seek = self.pop("stringtype")
|
|
416
|
+
s = self.pop("stringtype")
|
|
417
|
+
seeklen = len(seek.value)
|
|
418
|
+
if s.value[:seeklen] == seek.value:
|
|
419
|
+
self.push(ps_string(s.value[seeklen:]))
|
|
420
|
+
self.push(seek)
|
|
421
|
+
self.push(ps_boolean(1))
|
|
422
|
+
else:
|
|
423
|
+
self.push(s)
|
|
424
|
+
self.push(ps_boolean(0))
|
|
425
|
+
|
|
426
|
+
def ps_array(self):
|
|
427
|
+
num = self.pop("integertype")
|
|
428
|
+
array = ps_array([None] * num.value)
|
|
429
|
+
self.push(array)
|
|
430
|
+
|
|
431
|
+
def ps_astore(self):
|
|
432
|
+
array = self.pop("arraytype")
|
|
433
|
+
for i in range(len(array.value) - 1, -1, -1):
|
|
434
|
+
array.value[i] = self.pop()
|
|
435
|
+
self.push(array)
|
|
436
|
+
|
|
437
|
+
def ps_load(self):
|
|
438
|
+
name = self.pop()
|
|
439
|
+
self.push(self.resolve_name(name.value))
|
|
440
|
+
|
|
441
|
+
def ps_put(self):
|
|
442
|
+
obj1 = self.pop()
|
|
443
|
+
obj2 = self.pop()
|
|
444
|
+
obj3 = self.pop("arraytype", "dicttype", "stringtype", "proceduretype")
|
|
445
|
+
tp = obj3.type
|
|
446
|
+
if tp == "arraytype" or tp == "proceduretype":
|
|
447
|
+
obj3.value[obj2.value] = obj1
|
|
448
|
+
elif tp == "dicttype":
|
|
449
|
+
obj3.value[obj2.value] = obj1
|
|
450
|
+
elif tp == "stringtype":
|
|
451
|
+
index = obj2.value
|
|
452
|
+
obj3.value = obj3.value[:index] + chr(obj1.value) + obj3.value[index + 1 :]
|
|
453
|
+
|
|
454
|
+
def ps_get(self):
|
|
455
|
+
obj1 = self.pop()
|
|
456
|
+
if obj1.value == "Encoding":
|
|
457
|
+
pass
|
|
458
|
+
obj2 = self.pop(
|
|
459
|
+
"arraytype", "dicttype", "stringtype", "proceduretype", "fonttype"
|
|
460
|
+
)
|
|
461
|
+
tp = obj2.type
|
|
462
|
+
if tp in ("arraytype", "proceduretype"):
|
|
463
|
+
self.push(obj2.value[obj1.value])
|
|
464
|
+
elif tp in ("dicttype", "fonttype"):
|
|
465
|
+
self.push(obj2.value[obj1.value])
|
|
466
|
+
elif tp == "stringtype":
|
|
467
|
+
self.push(ps_integer(ord(obj2.value[obj1.value])))
|
|
468
|
+
else:
|
|
469
|
+
assert False, "shouldn't get here"
|
|
470
|
+
|
|
471
|
+
def ps_getinterval(self):
|
|
472
|
+
obj1 = self.pop("integertype")
|
|
473
|
+
obj2 = self.pop("integertype")
|
|
474
|
+
obj3 = self.pop("arraytype", "stringtype")
|
|
475
|
+
tp = obj3.type
|
|
476
|
+
if tp == "arraytype":
|
|
477
|
+
self.push(ps_array(obj3.value[obj2.value : obj2.value + obj1.value]))
|
|
478
|
+
elif tp == "stringtype":
|
|
479
|
+
self.push(ps_string(obj3.value[obj2.value : obj2.value + obj1.value]))
|
|
480
|
+
|
|
481
|
+
def ps_putinterval(self):
|
|
482
|
+
obj1 = self.pop("arraytype", "stringtype")
|
|
483
|
+
obj2 = self.pop("integertype")
|
|
484
|
+
obj3 = self.pop("arraytype", "stringtype")
|
|
485
|
+
tp = obj3.type
|
|
486
|
+
if tp == "arraytype":
|
|
487
|
+
obj3.value[obj2.value : obj2.value + len(obj1.value)] = obj1.value
|
|
488
|
+
elif tp == "stringtype":
|
|
489
|
+
newstr = obj3.value[: obj2.value]
|
|
490
|
+
newstr = newstr + obj1.value
|
|
491
|
+
newstr = newstr + obj3.value[obj2.value + len(obj1.value) :]
|
|
492
|
+
obj3.value = newstr
|
|
493
|
+
|
|
494
|
+
def ps_cvn(self):
|
|
495
|
+
self.push(ps_name(self.pop("stringtype").value))
|
|
496
|
+
|
|
497
|
+
def ps_index(self):
|
|
498
|
+
n = self.pop("integertype").value
|
|
499
|
+
if n < 0:
|
|
500
|
+
raise RuntimeError("index may not be negative")
|
|
501
|
+
self.push(self.stack[-1 - n])
|
|
502
|
+
|
|
503
|
+
def ps_for(self):
|
|
504
|
+
proc = self.pop("proceduretype")
|
|
505
|
+
limit = self.pop("integertype", "realtype").value
|
|
506
|
+
increment = self.pop("integertype", "realtype").value
|
|
507
|
+
i = self.pop("integertype", "realtype").value
|
|
508
|
+
while 1:
|
|
509
|
+
if increment > 0:
|
|
510
|
+
if i > limit:
|
|
511
|
+
break
|
|
512
|
+
else:
|
|
513
|
+
if i < limit:
|
|
514
|
+
break
|
|
515
|
+
if type(i) == type(0.0):
|
|
516
|
+
self.push(ps_real(i))
|
|
517
|
+
else:
|
|
518
|
+
self.push(ps_integer(i))
|
|
519
|
+
self.call_procedure(proc)
|
|
520
|
+
i = i + increment
|
|
521
|
+
|
|
522
|
+
def ps_forall(self):
|
|
523
|
+
proc = self.pop("proceduretype")
|
|
524
|
+
obj = self.pop("arraytype", "stringtype", "dicttype")
|
|
525
|
+
tp = obj.type
|
|
526
|
+
if tp == "arraytype":
|
|
527
|
+
for item in obj.value:
|
|
528
|
+
self.push(item)
|
|
529
|
+
self.call_procedure(proc)
|
|
530
|
+
elif tp == "stringtype":
|
|
531
|
+
for item in obj.value:
|
|
532
|
+
self.push(ps_integer(ord(item)))
|
|
533
|
+
self.call_procedure(proc)
|
|
534
|
+
elif tp == "dicttype":
|
|
535
|
+
for key, value in obj.value.items():
|
|
536
|
+
self.push(ps_name(key))
|
|
537
|
+
self.push(value)
|
|
538
|
+
self.call_procedure(proc)
|
|
539
|
+
|
|
540
|
+
def ps_definefont(self):
|
|
541
|
+
font = self.pop("dicttype")
|
|
542
|
+
name = self.pop()
|
|
543
|
+
font = ps_font(font.value)
|
|
544
|
+
self.dictstack[0]["FontDirectory"].value[name.value] = font
|
|
545
|
+
self.push(font)
|
|
546
|
+
|
|
547
|
+
def ps_findfont(self):
|
|
548
|
+
name = self.pop()
|
|
549
|
+
font = self.dictstack[0]["FontDirectory"].value[name.value]
|
|
550
|
+
self.push(font)
|
|
551
|
+
|
|
552
|
+
def ps_pop(self):
|
|
553
|
+
self.pop()
|
|
554
|
+
|
|
555
|
+
def ps_dict(self):
|
|
556
|
+
self.pop("integertype")
|
|
557
|
+
self.push(ps_dict({}))
|
|
558
|
+
|
|
559
|
+
def ps_begin(self):
|
|
560
|
+
self.dictstack.append(self.pop("dicttype").value)
|
|
561
|
+
|
|
562
|
+
def ps_end(self):
|
|
563
|
+
if len(self.dictstack) > 2:
|
|
564
|
+
del self.dictstack[-1]
|
|
565
|
+
else:
|
|
566
|
+
raise RuntimeError("dictstack underflow")
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
notdef = ".notdef"
|
|
570
|
+
from fontTools.encodings.StandardEncoding import StandardEncoding
|
|
571
|
+
|
|
572
|
+
ps_StandardEncoding = list(map(ps_name, StandardEncoding))
|
fontTools/misc/py23.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Python 2/3 compat layer leftovers."""
|
|
2
|
+
|
|
3
|
+
import decimal as _decimal
|
|
4
|
+
import math as _math
|
|
5
|
+
import warnings
|
|
6
|
+
from contextlib import redirect_stderr, redirect_stdout
|
|
7
|
+
from io import BytesIO
|
|
8
|
+
from io import StringIO as UnicodeIO
|
|
9
|
+
from types import SimpleNamespace
|
|
10
|
+
|
|
11
|
+
from .textTools import Tag, bytechr, byteord, bytesjoin, strjoin, tobytes, tostr
|
|
12
|
+
|
|
13
|
+
warnings.warn(
|
|
14
|
+
"The py23 module has been deprecated and will be removed in a future release. "
|
|
15
|
+
"Please update your code.",
|
|
16
|
+
DeprecationWarning,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"basestring",
|
|
21
|
+
"bytechr",
|
|
22
|
+
"byteord",
|
|
23
|
+
"BytesIO",
|
|
24
|
+
"bytesjoin",
|
|
25
|
+
"open",
|
|
26
|
+
"Py23Error",
|
|
27
|
+
"range",
|
|
28
|
+
"RecursionError",
|
|
29
|
+
"round",
|
|
30
|
+
"SimpleNamespace",
|
|
31
|
+
"StringIO",
|
|
32
|
+
"strjoin",
|
|
33
|
+
"Tag",
|
|
34
|
+
"tobytes",
|
|
35
|
+
"tostr",
|
|
36
|
+
"tounicode",
|
|
37
|
+
"unichr",
|
|
38
|
+
"unicode",
|
|
39
|
+
"UnicodeIO",
|
|
40
|
+
"xrange",
|
|
41
|
+
"zip",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Py23Error(NotImplementedError):
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
RecursionError = RecursionError
|
|
50
|
+
StringIO = UnicodeIO
|
|
51
|
+
|
|
52
|
+
basestring = str
|
|
53
|
+
isclose = _math.isclose
|
|
54
|
+
isfinite = _math.isfinite
|
|
55
|
+
open = open
|
|
56
|
+
range = range
|
|
57
|
+
round = round3 = round
|
|
58
|
+
unichr = chr
|
|
59
|
+
unicode = str
|
|
60
|
+
zip = zip
|
|
61
|
+
|
|
62
|
+
tounicode = tostr
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def xrange(*args, **kwargs):
|
|
66
|
+
raise Py23Error("'xrange' is not defined. Use 'range' instead.")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def round2(number, ndigits=None):
|
|
70
|
+
"""
|
|
71
|
+
Implementation of Python 2 built-in round() function.
|
|
72
|
+
Rounds a number to a given precision in decimal digits (default
|
|
73
|
+
0 digits). The result is a floating point number. Values are rounded
|
|
74
|
+
to the closest multiple of 10 to the power minus ndigits; if two
|
|
75
|
+
multiples are equally close, rounding is done away from 0.
|
|
76
|
+
ndigits may be negative.
|
|
77
|
+
See Python 2 documentation:
|
|
78
|
+
https://docs.python.org/2/library/functions.html?highlight=round#round
|
|
79
|
+
"""
|
|
80
|
+
if ndigits is None:
|
|
81
|
+
ndigits = 0
|
|
82
|
+
|
|
83
|
+
if ndigits < 0:
|
|
84
|
+
exponent = 10 ** (-ndigits)
|
|
85
|
+
quotient, remainder = divmod(number, exponent)
|
|
86
|
+
if remainder >= exponent // 2 and number >= 0:
|
|
87
|
+
quotient += 1
|
|
88
|
+
return float(quotient * exponent)
|
|
89
|
+
else:
|
|
90
|
+
exponent = _decimal.Decimal("10") ** (-ndigits)
|
|
91
|
+
|
|
92
|
+
d = _decimal.Decimal.from_float(number).quantize(
|
|
93
|
+
exponent, rounding=_decimal.ROUND_HALF_UP
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
return float(d)
|