Package pythonids
1
2 """*pythonids* provides common information about the Python syntax.
3 """
4
5
6
7
8
9
10 import sys
11 import os
12 import re
13
14
15 __author__ = 'Arno-Can Uestuensoez'
16 __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints"
17 __copyright__ = "Copyright (C) 2010-2018 Arno-Can Uestuensoez" \
18 " @Ingenieurbuero Arno-Can Uestuensoez"
19 __version__ = '0.1.31'
20 __uuid__ = "5624dc41-775a-4d17-ac42-14a0d5c41d1a"
21
22 __docformat__ = "restructuredtext en"
23
24
25 _debug = 0
26 _verbose = 0
27
28
30 """Subsystem *PythonIDs*.
31 """
32 pass
33
34
36 """Python implementation not supported.
37 """
38 pass
39
40
42 """Decodes the compressed version 16bit integer bitmask
43 into the corresponding string.
44
45 The optional format string *form* provides the formatting
46 of a 3-value interger tuple. E.g. *form="%02d.%02d.%03d"*.
47
48 Due to the spared error checks the string has to be correct!
49
50 """
51 return form % (
52 (xyz >> 13) & 7,
53 (xyz >> 8) & 31,
54 xyz & 255,
55 )
56
57
59 """ Decodes the compressed version 16bit integer bitmask
60 into the corresponding tuple of integer values.
61
62 """
63 return (
64 (xyz >> 13) & 7,
65 (xyz >> 8) & 31,
66 xyz & 255,
67 )
68
69
71 """Decodes the compressed version 16bit integer bitmask
72 into the corresponding tuple of integer values.
73
74 """
75 return (
76 str((xyz >> 13) & 7),
77 str((xyz >> 8) & 31),
78 str(xyz & 255),
79 )
80
81
83 """ Split a version string separated by '.' into an integer
84 tuple. ::
85
86 decode_pysyntax_str_to_num('1.22.17') => (1, 22, 17)
87
88 A tiny utility - frequently required.
89
90 Args:
91
92 Version string 'x.y.z'.
93
94 Returns:
95
96 Integer tuple (x, y, z)
97
98 Raises:
99
100 ValueError
101
102 """
103 return tuple(int(x) for x in v.split('.'))
104
105
107 """ Encodes the version by calculating the 16bit integer
108 bitmask for the provided Python release values.
109
110 Args:
111 x:
112 The major version number. ::
113
114 0 <= x
115
116 0 <= x0 < 8 # internal low-level 16-bit optimization threshold
117
118 y:
119 The minor version number. ::
120
121 0 <= y < 32
122
123 z:
124 The numeric relase-build tag. ::
125
126 0 <= z < 256
127
128 Returns:
129
130 The bitmask.
131
132 Raises:
133
134 pass-through
135
136 """
137 return (
138 (x & 7) << 13
139 | (y & 31) << 8
140 | (z & 255)
141 )
142
143
144
145
146
147 PYV2 = 16384
148 PYV27 = 18176
149 PYV3 = 24576
150 PYV33 = 25344
151 PYV35 = 25856
152 PYV36 = 26112
153 PYV37 = 26368
154 PYV38 = 26624
155 PYV39 = 26880
156
157
158
159
160
161 PYV2715 = 18191
162 PYV2716 = 18192
163 PYV31 = 24832
164 PYV32 = 25088
165 PYV34 = 25600
166 PYV362 = 26114
167 PYV365 = 26117
168 PYV366 = 26118
169 PYV367 = 26119
170 PYV368 = 26120
171 PYV369 = 26121
172 PYV371 = 26369
173 PYV372 = 26370
174 PYV373 = 26371
175 PYV374 = 26372
176 PYV375 = 26373
177 PYV376 = 26374
178 PYV381 = 26625
179
180
181
182 PYVxyz = encode_pysyntax_to_16bit(*sys.version_info[:3])
183
184
185
186
187 PYV27X = PYVxyz & PYV27 == PYV27
188 PYV3X = PYVxyz >= PYV3
189 PYV3X3 = PYVxyz >= PYV3 and PYVxyz < PYV34
190 PYV35Less = PYVxyz < PYV35
191 PYV35Plus = PYVxyz >= PYV35
192
193 if PYV35Plus:
194 ISSTR = (str, bytes)
195 ISSTRBASE = (str,)
196
197
198 unicode = str
199
200 elif PYV3X:
201 ISSTR = (str, bytes)
202 ISSTRBASE = (str,)
203
204
205 unicode = str
206
207 elif PYV27X:
208 ISSTR = (str, unicode)
209 ISSTRBASE = (str, unicode,)
210 unicode = unicode
211
212 else:
213 raise PythonIDsError(
214 "Requires Python 2.7+, or 3.5+, current: "
215 + str(sys.version_info[:2]))
216