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
|
|---|---|---|---|---|---|---|---|---|
elkingtonmcb/h2o-2
|
py/testdir_multi_jvm/test_KMeans_covtype_cols_fvec.py
|
9
|
3499
|
import unittest
import random, sys, time, os
sys.path.extend(['.','..','../..','py'])
import h2o, h2o_cmd, h2o_browse as h2b, h2o_import as h2i, h2o_kmeans
class Basic(unittest.TestCase):
def tearDown(self):
h2o.check_sandbox_for_errors()
@classmethod
def setUpClass(cls):
global SEED
SEED = h2o.setup_random_seed()
h2o.init(3,java_heap_GB=4)
@classmethod
def tearDownClass(cls):
# wait while I inspect things
# time.sleep(1500)
h2o.tear_down_cloud()
def test_KMeans_covtype_cols_fvec(self):
# just do the import folder once
# make the timeout variable per dataset. it can be 10 secs for covtype 20x (col key creation)
# so probably 10x that for covtype200
csvFilenameList = [
("covtype.binary.svm", "cC", 30, 1),
# normal csv
]
### csvFilenameList = random.sample(csvFilenameAll,1)
# h2b.browseTheCloud()
lenNodes = len(h2o.nodes)
firstDone = False
importFolderPath = "libsvm"
for (csvFilename, hex_key, timeoutSecs, resultMult) in csvFilenameList:
# have to import each time, because h2o deletes source after parse
csvPathname = importFolderPath + "/" + csvFilename
# PARSE******************************************
# creates csvFilename.hex from file in importFolder dir
parseResult = h2i.import_parse(bucket='home-0xdiag-datasets', path=csvPathname,
hex_key=hex_key, timeoutSecs=2000)
print "Parse result['destination_key']:", parseResult['destination_key']
# INSPECT******************************************
start = time.time()
inspect = h2o_cmd.runInspect(None, parseResult['destination_key'], timeoutSecs=360)
print "Inspect:", parseResult['destination_key'], "took", time.time() - start, "seconds"
h2o_cmd.infoFromInspect(inspect, csvFilename)
numRows = inspect['numRows']
numCols = inspect['numCols']
# KMEANS******************************************
for trial in range(1):
kwargs = {
'k': 3,
'initialization': 'Furthest',
'ignored_cols': range(11, numCols),
'max_iter': 10,
# 'normalize': 0,
# reuse the same seed, to get deterministic results (otherwise sometimes fails
'seed': 265211114317615310,
}
# fails if I put this in kwargs..i.e. source = dest
# 'destination_key': parseResult['destination_key'],
for trial2 in range(3):
timeoutSecs = 600
start = time.time()
kmeans = h2o_cmd.runKMeans(parseResult=parseResult, timeoutSecs=timeoutSecs, **kwargs)
elapsed = time.time() - start
print "kmeans end on ", csvPathname, 'took', elapsed, 'seconds.', \
"%d pct. of timeout" % ((elapsed/timeoutSecs) * 100)
# this does an inspect of the model and prints the clusters
h2o_kmeans.simpleCheckKMeans(self, kmeans, **kwargs)
(centers, tupleResultList) = h2o_kmeans.bigCheckResults(self, kmeans, csvPathname, parseResult, 'd', **kwargs)
if __name__ == '__main__':
h2o.unit_main()
|
apache-2.0
|
[
646,
2882,
199,
646,
2196,
12,
984,
12,
900,
12,
747,
199,
1274,
14,
515,
14,
2880,
2941,
14,
1673,
703,
1673,
5093,
703,
1673,
647,
1105,
199,
646,
394,
18,
79,
12,
394,
18,
79,
63,
1760,
12,
394,
18,
79,
63,
4570,
465,
394,
18,
66,
12,
394,
18,
79,
63,
646,
465,
394,
18,
73,
12,
394,
18,
79,
63,
75,
11579,
199,
199,
533,
10082,
8,
2796,
14,
1746,
304,
272,
347,
6766,
8,
277,
304,
267,
394,
18,
79,
14,
1074,
63,
16647,
63,
509,
63,
2550,
342,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
2288,
5795,
1149,
267,
5795,
1149,
275,
394,
18,
79,
14,
2758,
63,
2355,
63,
5176,
342,
267,
394,
18,
79,
14,
826,
8,
19,
12,
6138,
63,
12492,
63,
6487,
29,
20,
9,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
327,
3618,
1830,
473,
6485,
7645,
267,
327,
900,
14,
4532,
8,
27607,
9,
267,
394,
18,
79,
14,
266,
285,
63,
2110,
63,
4091,
342,
339,
347,
511,
63,
43,
21190,
63,
8695,
466,
63,
4574,
63,
70,
6046,
8,
277,
304,
267,
327,
2951,
886,
314,
492,
4922,
5403,
267,
327,
1852,
314,
2653,
1750,
1126,
4789,
14,
652,
883,
506,
1616,
20091,
367,
13786,
466,
3388,
88,
334,
761,
790,
7143,
9,
267,
327,
880,
8646,
1616,
88,
626,
367,
13786,
466,
1840,
267,
7392,
8117,
1296,
275,
359,
288,
1689,
8695,
466,
14,
3008,
14,
16820,
401,
298,
67,
35,
401,
4233,
12,
413,
395,
288,
327,
3293,
7392,
267,
1622,
398,
6754,
7392,
8117,
1296,
275,
2196,
14,
3271,
8,
4737,
8117,
2422,
12,
17,
9,
267,
327,
394,
18,
66,
14,
4570,
1918,
9089,
342,
267,
822,
6300,
275,
822,
8,
72,
18,
79,
14,
2415,
9,
398,
1642,
10759,
275,
756,
267,
492,
7850,
2042,
275,
298,
8450,
2611,
2,
267,
367,
334,
4737,
8117,
12,
6318,
63,
498,
12,
2653,
29224,
12,
754,
30233,
9,
315,
7392,
8117,
1296,
26,
288,
327,
1172,
370,
492,
1924,
900,
12,
2952,
394,
18,
79,
21812,
1350,
2410,
2198,
288,
7392,
2042,
354,
275,
492,
7850,
2042,
435,
10609,
435,
7392,
8117,
953,
327,
10263,
899,
5815,
1801,
538,
288,
327,
8491,
7392,
8117,
14,
4097,
687,
570,
315,
492,
7850,
2935,
7205,
2198,
2889,
275,
394,
18,
73,
14,
646,
63,
1122,
8,
4623,
534,
4219,
13,
16,
88,
6706,
13,
12281,
297,
931,
29,
4737,
2042,
354,
12,
8892,
6318,
63,
498,
29,
4097,
63,
498,
12,
2653,
29224,
29,
8269,
9,
288,
870,
298,
4003,
754,
459,
6881,
63,
498,
2565,
401,
2198,
2889,
459,
6881,
63,
498,
418,
953,
327,
1621,
51,
11401,
5815,
1801,
538,
288,
1343,
275,
900,
14,
521,
342,
288,
6485,
275,
394,
18,
79,
63,
1760,
14,
1065,
13962,
1764,
8,
403,
12,
2198,
2889,
459,
6881,
63,
498,
995,
2653,
29224,
29,
11197,
9,
288,
870,
298,
13962,
1764,
6783,
2198,
2889,
459,
6881,
63,
498,
995,
298,
475,
745,
401,
900,
14,
521,
342,
446,
1343,
12,
298,
4515,
2,
288,
394,
18,
79,
63,
1760,
14,
815,
2532,
13962,
1764,
8,
10955,
12,
7392,
8117,
9,
288,
1967,
13405,
275,
6485,
459,
1507,
13405,
418,
288,
1967,
17203,
275,
6485,
459,
1507,
17203,
418,
953,
327,
1804,
3635,
5622,
5815,
1801,
538,
288,
367,
16324,
315,
1425,
8,
17,
304,
355,
2074,
275,
469,
490,
283,
75,
356,
650,
12,
15324,
283,
27876,
356,
283,
38,
300,
273,
597,
297,
490,
283,
11996,
63,
4574,
356,
1425,
8,
845,
12,
1967,
17203,
395,
490,
283,
988,
63,
1661,
356,
1616,
12,
490,
327,
283,
7721,
356,
378,
12,
490,
327,
12598,
314,
2011,
6347,
12,
370,
664,
25286,
2058,
334,
26617,
15026,
6918,
490,
283,
5176,
356,
499,
25415,
6984,
2824,
10216,
12034,
709,
12,
355,
789,
2234,
327,
6918,
340,
473,
5324,
642,
315,
2074,
703,
73,
14,
69,
14,
1350,
275,
2053,
355,
327,
283,
6881,
63,
498,
356,
2198,
2889,
459,
6881,
63,
498,
995,
2234,
367,
16324,
18,
315,
1425,
8,
19,
304,
490,
2653,
29224,
275,
11624,
490,
1343,
275,
900,
14,
521,
342,
490,
1022,
11579,
275,
394,
18,
79,
63,
1760,
14,
1065,
43,
21190,
8,
1122,
2889,
29,
1122,
2889,
12,
2653,
29224,
29,
2593,
29224,
12,
1011,
958,
9,
490,
14439,
275,
900,
14,
521,
342,
446,
1343,
490,
870,
298,
75,
11579,
1284,
641,
3872,
7392,
2042,
354,
12,
283,
475,
745,
297,
14439,
12,
283,
4515,
3130,
971,
717,
2071,
68,
299,
319,
14,
402,
2653,
2,
450,
3666,
16691,
15,
2593,
29224,
9,
627,
2948,
9,
490,
327,
642,
1630,
376,
6485,
402,
314,
1402,
436,
14767,
314,
13865,
490,
394,
18,
79,
63,
75,
11579,
14,
4129,
1799,
43,
21190,
8,
277,
12,
1022,
11579,
12,
1011,
958,
9,
4951,
334,
15660,
12,
2008,
2889,
1296,
9,
275,
394,
18,
79,
63,
75,
11579,
14,
5076,
1799,
6579,
8,
277,
12,
1022,
11579,
12,
7392,
2042,
354,
12,
2198,
2889,
12,
283,
68,
297,
1011,
958,
9,
4388,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
394,
18,
79,
14,
3248,
63,
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
] |
[
2882,
199,
646,
2196,
12,
984,
12,
900,
12,
747,
199,
1274,
14,
515,
14,
2880,
2941,
14,
1673,
703,
1673,
5093,
703,
1673,
647,
1105,
199,
646,
394,
18,
79,
12,
394,
18,
79,
63,
1760,
12,
394,
18,
79,
63,
4570,
465,
394,
18,
66,
12,
394,
18,
79,
63,
646,
465,
394,
18,
73,
12,
394,
18,
79,
63,
75,
11579,
199,
199,
533,
10082,
8,
2796,
14,
1746,
304,
272,
347,
6766,
8,
277,
304,
267,
394,
18,
79,
14,
1074,
63,
16647,
63,
509,
63,
2550,
342,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
2288,
5795,
1149,
267,
5795,
1149,
275,
394,
18,
79,
14,
2758,
63,
2355,
63,
5176,
342,
267,
394,
18,
79,
14,
826,
8,
19,
12,
6138,
63,
12492,
63,
6487,
29,
20,
9,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
327,
3618,
1830,
473,
6485,
7645,
267,
327,
900,
14,
4532,
8,
27607,
9,
267,
394,
18,
79,
14,
266,
285,
63,
2110,
63,
4091,
342,
339,
347,
511,
63,
43,
21190,
63,
8695,
466,
63,
4574,
63,
70,
6046,
8,
277,
304,
267,
327,
2951,
886,
314,
492,
4922,
5403,
267,
327,
1852,
314,
2653,
1750,
1126,
4789,
14,
652,
883,
506,
1616,
20091,
367,
13786,
466,
3388,
88,
334,
761,
790,
7143,
9,
267,
327,
880,
8646,
1616,
88,
626,
367,
13786,
466,
1840,
267,
7392,
8117,
1296,
275,
359,
288,
1689,
8695,
466,
14,
3008,
14,
16820,
401,
298,
67,
35,
401,
4233,
12,
413,
395,
288,
327,
3293,
7392,
267,
1622,
398,
6754,
7392,
8117,
1296,
275,
2196,
14,
3271,
8,
4737,
8117,
2422,
12,
17,
9,
267,
327,
394,
18,
66,
14,
4570,
1918,
9089,
342,
267,
822,
6300,
275,
822,
8,
72,
18,
79,
14,
2415,
9,
398,
1642,
10759,
275,
756,
267,
492,
7850,
2042,
275,
298,
8450,
2611,
2,
267,
367,
334,
4737,
8117,
12,
6318,
63,
498,
12,
2653,
29224,
12,
754,
30233,
9,
315,
7392,
8117,
1296,
26,
288,
327,
1172,
370,
492,
1924,
900,
12,
2952,
394,
18,
79,
21812,
1350,
2410,
2198,
288,
7392,
2042,
354,
275,
492,
7850,
2042,
435,
10609,
435,
7392,
8117,
953,
327,
10263,
899,
5815,
1801,
538,
288,
327,
8491,
7392,
8117,
14,
4097,
687,
570,
315,
492,
7850,
2935,
7205,
2198,
2889,
275,
394,
18,
73,
14,
646,
63,
1122,
8,
4623,
534,
4219,
13,
16,
88,
6706,
13,
12281,
297,
931,
29,
4737,
2042,
354,
12,
8892,
6318,
63,
498,
29,
4097,
63,
498,
12,
2653,
29224,
29,
8269,
9,
288,
870,
298,
4003,
754,
459,
6881,
63,
498,
2565,
401,
2198,
2889,
459,
6881,
63,
498,
418,
953,
327,
1621,
51,
11401,
5815,
1801,
538,
288,
1343,
275,
900,
14,
521,
342,
288,
6485,
275,
394,
18,
79,
63,
1760,
14,
1065,
13962,
1764,
8,
403,
12,
2198,
2889,
459,
6881,
63,
498,
995,
2653,
29224,
29,
11197,
9,
288,
870,
298,
13962,
1764,
6783,
2198,
2889,
459,
6881,
63,
498,
995,
298,
475,
745,
401,
900,
14,
521,
342,
446,
1343,
12,
298,
4515,
2,
288,
394,
18,
79,
63,
1760,
14,
815,
2532,
13962,
1764,
8,
10955,
12,
7392,
8117,
9,
288,
1967,
13405,
275,
6485,
459,
1507,
13405,
418,
288,
1967,
17203,
275,
6485,
459,
1507,
17203,
418,
953,
327,
1804,
3635,
5622,
5815,
1801,
538,
288,
367,
16324,
315,
1425,
8,
17,
304,
355,
2074,
275,
469,
490,
283,
75,
356,
650,
12,
15324,
283,
27876,
356,
283,
38,
300,
273,
597,
297,
490,
283,
11996,
63,
4574,
356,
1425,
8,
845,
12,
1967,
17203,
395,
490,
283,
988,
63,
1661,
356,
1616,
12,
490,
327,
283,
7721,
356,
378,
12,
490,
327,
12598,
314,
2011,
6347,
12,
370,
664,
25286,
2058,
334,
26617,
15026,
6918,
490,
283,
5176,
356,
499,
25415,
6984,
2824,
10216,
12034,
709,
12,
355,
789,
2234,
327,
6918,
340,
473,
5324,
642,
315,
2074,
703,
73,
14,
69,
14,
1350,
275,
2053,
355,
327,
283,
6881,
63,
498,
356,
2198,
2889,
459,
6881,
63,
498,
995,
2234,
367,
16324,
18,
315,
1425,
8,
19,
304,
490,
2653,
29224,
275,
11624,
490,
1343,
275,
900,
14,
521,
342,
490,
1022,
11579,
275,
394,
18,
79,
63,
1760,
14,
1065,
43,
21190,
8,
1122,
2889,
29,
1122,
2889,
12,
2653,
29224,
29,
2593,
29224,
12,
1011,
958,
9,
490,
14439,
275,
900,
14,
521,
342,
446,
1343,
490,
870,
298,
75,
11579,
1284,
641,
3872,
7392,
2042,
354,
12,
283,
475,
745,
297,
14439,
12,
283,
4515,
3130,
971,
717,
2071,
68,
299,
319,
14,
402,
2653,
2,
450,
3666,
16691,
15,
2593,
29224,
9,
627,
2948,
9,
490,
327,
642,
1630,
376,
6485,
402,
314,
1402,
436,
14767,
314,
13865,
490,
394,
18,
79,
63,
75,
11579,
14,
4129,
1799,
43,
21190,
8,
277,
12,
1022,
11579,
12,
1011,
958,
9,
4951,
334,
15660,
12,
2008,
2889,
1296,
9,
275,
394,
18,
79,
63,
75,
11579,
14,
5076,
1799,
6579,
8,
277,
12,
1022,
11579,
12,
7392,
2042,
354,
12,
2198,
2889,
12,
283,
68,
297,
1011,
958,
9,
4388,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
394,
18,
79,
14,
3248,
63,
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,
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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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
] |
frishberg/django
|
django/test/utils.py
|
16
|
29659
|
import collections
import logging
import re
import sys
import time
import warnings
from contextlib import contextmanager
from functools import wraps
from unittest import TestCase, skipIf, skipUnless
from xml.dom.minidom import Node, parseString
from django.apps import apps
from django.apps.registry import Apps
from django.conf import UserSettingsHolder, settings
from django.core import mail
from django.core.exceptions import ImproperlyConfigured
from django.core.signals import request_started
from django.db import DEFAULT_DB_ALIAS, connections, reset_queries
from django.db.models.options import Options
from django.template import Template
from django.test.signals import setting_changed, template_rendered
from django.urls import get_script_prefix, set_script_prefix
from django.utils import six
from django.utils.decorators import available_attrs
from django.utils.encoding import force_str
from django.utils.translation import deactivate
if six.PY3:
from types import SimpleNamespace
else:
class SimpleNamespace(object):
pass
try:
import jinja2
except ImportError:
jinja2 = None
__all__ = (
'Approximate', 'ContextList', 'isolate_lru_cache', 'get_runner',
'modify_settings', 'override_settings',
'requires_tz_support',
'setup_test_environment', 'teardown_test_environment',
)
TZ_SUPPORT = hasattr(time, 'tzset')
class Approximate(object):
def __init__(self, val, places=7):
self.val = val
self.places = places
def __repr__(self):
return repr(self.val)
def __eq__(self, other):
if self.val == other:
return True
return round(abs(self.val - other), self.places) == 0
class ContextList(list):
"""A wrapper that provides direct key access to context items contained
in a list of context objects.
"""
def __getitem__(self, key):
if isinstance(key, six.string_types):
for subcontext in self:
if key in subcontext:
return subcontext[key]
raise KeyError(key)
else:
return super(ContextList, self).__getitem__(key)
def __contains__(self, key):
try:
self[key]
except KeyError:
return False
return True
def keys(self):
"""
Flattened keys of subcontexts.
"""
keys = set()
for subcontext in self:
for dict in subcontext:
keys |= set(dict.keys())
return keys
def instrumented_test_render(self, context):
"""
An instrumented Template render method, providing a signal
that can be intercepted by the test system Client
"""
template_rendered.send(sender=self, template=self, context=context)
return self.nodelist.render(context)
class _TestState(object):
pass
def setup_test_environment(debug=None):
"""
Perform global pre-test setup, such as installing the instrumented template
renderer and setting the email backend to the locmem email backend.
"""
if hasattr(_TestState, 'saved_data'):
# Executing this function twice would overwrite the saved values.
raise RuntimeError(
"setup_test_environment() was already called and can't be called "
"again without first calling teardown_test_environment()."
)
if debug is None:
debug = settings.DEBUG
saved_data = SimpleNamespace()
_TestState.saved_data = saved_data
saved_data.allowed_hosts = settings.ALLOWED_HOSTS
# Add the default host of the test client.
settings.ALLOWED_HOSTS = settings.ALLOWED_HOSTS + ['testserver']
saved_data.debug = settings.DEBUG
settings.DEBUG = debug
saved_data.email_backend = settings.EMAIL_BACKEND
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
saved_data.template_render = Template._render
Template._render = instrumented_test_render
mail.outbox = []
deactivate()
def teardown_test_environment():
"""
Perform any global post-test teardown, such as restoring the original
template renderer and restoring the email sending functions.
"""
saved_data = _TestState.saved_data
settings.ALLOWED_HOSTS = saved_data.allowed_hosts
settings.DEBUG = saved_data.debug
settings.EMAIL_BACKEND = saved_data.email_backend
Template._render = saved_data.template_render
del _TestState.saved_data
del mail.outbox
def setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, parallel=0, **kwargs):
"""
Create the test databases.
"""
test_databases, mirrored_aliases = get_unique_databases_and_mirrors()
old_names = []
for signature, (db_name, aliases) in test_databases.items():
first_alias = None
for alias in aliases:
connection = connections[alias]
old_names.append((connection, db_name, first_alias is None))
# Actually create the database for the first connection
if first_alias is None:
first_alias = alias
connection.creation.create_test_db(
verbosity=verbosity,
autoclobber=not interactive,
keepdb=keepdb,
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
)
if parallel > 1:
for index in range(parallel):
connection.creation.clone_test_db(
number=index + 1,
verbosity=verbosity,
keepdb=keepdb,
)
# Configure all other connections as mirrors of the first one
else:
connections[alias].creation.set_as_test_mirror(connections[first_alias].settings_dict)
# Configure the test mirrors.
for alias, mirror_alias in mirrored_aliases.items():
connections[alias].creation.set_as_test_mirror(
connections[mirror_alias].settings_dict)
if debug_sql:
for alias in connections:
connections[alias].force_debug_cursor = True
return old_names
def dependency_ordered(test_databases, dependencies):
"""
Reorder test_databases into an order that honors the dependencies
described in TEST[DEPENDENCIES].
"""
ordered_test_databases = []
resolved_databases = set()
# Maps db signature to dependencies of all its aliases
dependencies_map = {}
# Check that no database depends on its own alias
for sig, (_, aliases) in test_databases:
all_deps = set()
for alias in aliases:
all_deps.update(dependencies.get(alias, []))
if not all_deps.isdisjoint(aliases):
raise ImproperlyConfigured(
"Circular dependency: databases %r depend on each other, "
"but are aliases." % aliases
)
dependencies_map[sig] = all_deps
while test_databases:
changed = False
deferred = []
# Try to find a DB that has all its dependencies met
for signature, (db_name, aliases) in test_databases:
if dependencies_map[signature].issubset(resolved_databases):
resolved_databases.update(aliases)
ordered_test_databases.append((signature, (db_name, aliases)))
changed = True
else:
deferred.append((signature, (db_name, aliases)))
if not changed:
raise ImproperlyConfigured("Circular dependency in TEST[DEPENDENCIES]")
test_databases = deferred
return ordered_test_databases
def get_unique_databases_and_mirrors():
"""
Figure out which databases actually need to be created.
Deduplicate entries in DATABASES that correspond the same database or are
configured as test mirrors.
Return two values:
- test_databases: ordered mapping of signatures to (name, list of aliases)
where all aliases share the same underlying database.
- mirrored_aliases: mapping of mirror aliases to original aliases.
"""
mirrored_aliases = {}
test_databases = {}
dependencies = {}
default_sig = connections[DEFAULT_DB_ALIAS].creation.test_db_signature()
for alias in connections:
connection = connections[alias]
test_settings = connection.settings_dict['TEST']
if test_settings['MIRROR']:
# If the database is marked as a test mirror, save the alias.
mirrored_aliases[alias] = test_settings['MIRROR']
else:
# Store a tuple with DB parameters that uniquely identify it.
# If we have two aliases with the same values for that tuple,
# we only need to create the test database once.
item = test_databases.setdefault(
connection.creation.test_db_signature(),
(connection.settings_dict['NAME'], set())
)
item[1].add(alias)
if 'DEPENDENCIES' in test_settings:
dependencies[alias] = test_settings['DEPENDENCIES']
else:
if alias != DEFAULT_DB_ALIAS and connection.creation.test_db_signature() != default_sig:
dependencies[alias] = test_settings.get('DEPENDENCIES', [DEFAULT_DB_ALIAS])
test_databases = dependency_ordered(test_databases.items(), dependencies)
test_databases = collections.OrderedDict(test_databases)
return test_databases, mirrored_aliases
def teardown_databases(old_config, verbosity, parallel=0, keepdb=False):
"""
Destroy all the non-mirror databases.
"""
for connection, old_name, destroy in old_config:
if destroy:
if parallel > 1:
for index in range(parallel):
connection.creation.destroy_test_db(
number=index + 1,
verbosity=verbosity,
keepdb=keepdb,
)
connection.creation.destroy_test_db(old_name, verbosity, keepdb)
def get_runner(settings, test_runner_class=None):
if not test_runner_class:
test_runner_class = settings.TEST_RUNNER
test_path = test_runner_class.split('.')
# Allow for Python 2.5 relative paths
if len(test_path) > 1:
test_module_name = '.'.join(test_path[:-1])
else:
test_module_name = '.'
test_module = __import__(test_module_name, {}, {}, force_str(test_path[-1]))
test_runner = getattr(test_module, test_path[-1])
return test_runner
class TestContextDecorator(object):
"""
A base class that can either be used as a context manager during tests
or as a test function or unittest.TestCase subclass decorator to perform
temporary alterations.
`attr_name`: attribute assigned the return value of enable() if used as
a class decorator.
`kwarg_name`: keyword argument passing the return value of enable() if
used as a function decorator.
"""
def __init__(self, attr_name=None, kwarg_name=None):
self.attr_name = attr_name
self.kwarg_name = kwarg_name
def enable(self):
raise NotImplementedError
def disable(self):
raise NotImplementedError
def __enter__(self):
return self.enable()
def __exit__(self, exc_type, exc_value, traceback):
self.disable()
def decorate_class(self, cls):
if issubclass(cls, TestCase):
decorated_setUp = cls.setUp
decorated_tearDown = cls.tearDown
def setUp(inner_self):
context = self.enable()
if self.attr_name:
setattr(inner_self, self.attr_name, context)
decorated_setUp(inner_self)
def tearDown(inner_self):
decorated_tearDown(inner_self)
self.disable()
cls.setUp = setUp
cls.tearDown = tearDown
return cls
raise TypeError('Can only decorate subclasses of unittest.TestCase')
def decorate_callable(self, func):
@wraps(func, assigned=available_attrs(func))
def inner(*args, **kwargs):
with self as context:
if self.kwarg_name:
kwargs[self.kwarg_name] = context
return func(*args, **kwargs)
return inner
def __call__(self, decorated):
if isinstance(decorated, type):
return self.decorate_class(decorated)
elif callable(decorated):
return self.decorate_callable(decorated)
raise TypeError('Cannot decorate object of type %s' % type(decorated))
class override_settings(TestContextDecorator):
"""
Acts as either a decorator or a context manager. If it's a decorator it
takes a function and returns a wrapped function. If it's a contextmanager
it's used with the ``with`` statement. In either event entering/exiting
are called before and after, respectively, the function/block is executed.
"""
def __init__(self, **kwargs):
self.options = kwargs
super(override_settings, self).__init__()
def enable(self):
# Keep this code at the beginning to leave the settings unchanged
# in case it raises an exception because INSTALLED_APPS is invalid.
if 'INSTALLED_APPS' in self.options:
try:
apps.set_installed_apps(self.options['INSTALLED_APPS'])
except Exception:
apps.unset_installed_apps()
raise
override = UserSettingsHolder(settings._wrapped)
for key, new_value in self.options.items():
setattr(override, key, new_value)
self.wrapped = settings._wrapped
settings._wrapped = override
for key, new_value in self.options.items():
setting_changed.send(sender=settings._wrapped.__class__,
setting=key, value=new_value, enter=True)
def disable(self):
if 'INSTALLED_APPS' in self.options:
apps.unset_installed_apps()
settings._wrapped = self.wrapped
del self.wrapped
for key in self.options:
new_value = getattr(settings, key, None)
setting_changed.send(sender=settings._wrapped.__class__,
setting=key, value=new_value, enter=False)
def save_options(self, test_func):
if test_func._overridden_settings is None:
test_func._overridden_settings = self.options
else:
# Duplicate dict to prevent subclasses from altering their parent.
test_func._overridden_settings = dict(
test_func._overridden_settings, **self.options)
def decorate_class(self, cls):
from django.test import SimpleTestCase
if not issubclass(cls, SimpleTestCase):
raise ValueError(
"Only subclasses of Django SimpleTestCase can be decorated "
"with override_settings")
self.save_options(cls)
return cls
class modify_settings(override_settings):
"""
Like override_settings, but makes it possible to append, prepend or remove
items instead of redefining the entire list.
"""
def __init__(self, *args, **kwargs):
if args:
# Hack used when instantiating from SimpleTestCase.setUpClass.
assert not kwargs
self.operations = args[0]
else:
assert not args
self.operations = list(kwargs.items())
super(override_settings, self).__init__()
def save_options(self, test_func):
if test_func._modified_settings is None:
test_func._modified_settings = self.operations
else:
# Duplicate list to prevent subclasses from altering their parent.
test_func._modified_settings = list(
test_func._modified_settings) + self.operations
def enable(self):
self.options = {}
for name, operations in self.operations:
try:
# When called from SimpleTestCase.setUpClass, values may be
# overridden several times; cumulate changes.
value = self.options[name]
except KeyError:
value = list(getattr(settings, name, []))
for action, items in operations.items():
# items my be a single value or an iterable.
if isinstance(items, six.string_types):
items = [items]
if action == 'append':
value = value + [item for item in items if item not in value]
elif action == 'prepend':
value = [item for item in items if item not in value] + value
elif action == 'remove':
value = [item for item in value if item not in items]
else:
raise ValueError("Unsupported action: %s" % action)
self.options[name] = value
super(modify_settings, self).enable()
class override_system_checks(TestContextDecorator):
"""
Acts as a decorator. Overrides list of registered system checks.
Useful when you override `INSTALLED_APPS`, e.g. if you exclude `auth` app,
you also need to exclude its system checks.
"""
def __init__(self, new_checks, deployment_checks=None):
from django.core.checks.registry import registry
self.registry = registry
self.new_checks = new_checks
self.deployment_checks = deployment_checks
super(override_system_checks, self).__init__()
def enable(self):
self.old_checks = self.registry.registered_checks
self.registry.registered_checks = self.new_checks
self.old_deployment_checks = self.registry.deployment_checks
if self.deployment_checks is not None:
self.registry.deployment_checks = self.deployment_checks
def disable(self):
self.registry.registered_checks = self.old_checks
self.registry.deployment_checks = self.old_deployment_checks
def compare_xml(want, got):
"""Tries to do a 'xml-comparison' of want and got. Plain string
comparison doesn't always work because, for example, attribute
ordering should not be important. Comment nodes are not considered in the
comparison. Leading and trailing whitespace is ignored on both chunks.
Based on https://github.com/lxml/lxml/blob/master/src/lxml/doctestcompare.py
"""
_norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
def norm_whitespace(v):
return _norm_whitespace_re.sub(' ', v)
def child_text(element):
return ''.join(c.data for c in element.childNodes
if c.nodeType == Node.TEXT_NODE)
def children(element):
return [c for c in element.childNodes
if c.nodeType == Node.ELEMENT_NODE]
def norm_child_text(element):
return norm_whitespace(child_text(element))
def attrs_dict(element):
return dict(element.attributes.items())
def check_element(want_element, got_element):
if want_element.tagName != got_element.tagName:
return False
if norm_child_text(want_element) != norm_child_text(got_element):
return False
if attrs_dict(want_element) != attrs_dict(got_element):
return False
want_children = children(want_element)
got_children = children(got_element)
if len(want_children) != len(got_children):
return False
for want, got in zip(want_children, got_children):
if not check_element(want, got):
return False
return True
def first_node(document):
for node in document.childNodes:
if node.nodeType != Node.COMMENT_NODE:
return node
want, got = strip_quotes(want, got)
want = want.strip().replace('\\n', '\n')
got = got.strip().replace('\\n', '\n')
# If the string is not a complete xml document, we may need to add a
# root element. This allow us to compare fragments, like "<foo/><bar/>"
if not want.startswith('<?xml'):
wrapper = '<root>%s</root>'
want = wrapper % want
got = wrapper % got
# Parse the want and got strings, and compare the parsings.
want_root = first_node(parseString(want))
got_root = first_node(parseString(got))
return check_element(want_root, got_root)
def strip_quotes(want, got):
"""
Strip quotes of doctests output values:
>>> strip_quotes("'foo'")
"foo"
>>> strip_quotes('"foo"')
"foo"
"""
def is_quoted_string(s):
s = s.strip()
return len(s) >= 2 and s[0] == s[-1] and s[0] in ('"', "'")
def is_quoted_unicode(s):
s = s.strip()
return len(s) >= 3 and s[0] == 'u' and s[1] == s[-1] and s[1] in ('"', "'")
if is_quoted_string(want) and is_quoted_string(got):
want = want.strip()[1:-1]
got = got.strip()[1:-1]
elif is_quoted_unicode(want) and is_quoted_unicode(got):
want = want.strip()[2:-1]
got = got.strip()[2:-1]
return want, got
def str_prefix(s):
return s % {'_': '' if six.PY3 else 'u'}
class CaptureQueriesContext(object):
"""
Context manager that captures queries executed by the specified connection.
"""
def __init__(self, connection):
self.connection = connection
def __iter__(self):
return iter(self.captured_queries)
def __getitem__(self, index):
return self.captured_queries[index]
def __len__(self):
return len(self.captured_queries)
@property
def captured_queries(self):
return self.connection.queries[self.initial_queries:self.final_queries]
def __enter__(self):
self.force_debug_cursor = self.connection.force_debug_cursor
self.connection.force_debug_cursor = True
self.initial_queries = len(self.connection.queries_log)
self.final_queries = None
request_started.disconnect(reset_queries)
return self
def __exit__(self, exc_type, exc_value, traceback):
self.connection.force_debug_cursor = self.force_debug_cursor
request_started.connect(reset_queries)
if exc_type is not None:
return
self.final_queries = len(self.connection.queries_log)
class ignore_warnings(TestContextDecorator):
def __init__(self, **kwargs):
self.ignore_kwargs = kwargs
if 'message' in self.ignore_kwargs or 'module' in self.ignore_kwargs:
self.filter_func = warnings.filterwarnings
else:
self.filter_func = warnings.simplefilter
super(ignore_warnings, self).__init__()
def enable(self):
self.catch_warnings = warnings.catch_warnings()
self.catch_warnings.__enter__()
self.filter_func('ignore', **self.ignore_kwargs)
def disable(self):
self.catch_warnings.__exit__(*sys.exc_info())
@contextmanager
def patch_logger(logger_name, log_level, log_kwargs=False):
"""
Context manager that takes a named logger and the logging level
and provides a simple mock-like list of messages received
"""
calls = []
def replacement(msg, *args, **kwargs):
call = msg % args
calls.append((call, kwargs) if log_kwargs else call)
logger = logging.getLogger(logger_name)
orig = getattr(logger, log_level)
setattr(logger, log_level, replacement)
try:
yield calls
finally:
setattr(logger, log_level, orig)
# On OSes that don't provide tzset (Windows), we can't set the timezone
# in which the program runs. As a consequence, we must skip tests that
# don't enforce a specific timezone (with timezone.override or equivalent),
# or attempt to interpret naive datetimes in the default timezone.
requires_tz_support = skipUnless(
TZ_SUPPORT,
"This test relies on the ability to run a program in an arbitrary "
"time zone, but your operating system isn't able to do that."
)
@contextmanager
def extend_sys_path(*paths):
"""Context manager to temporarily add paths to sys.path."""
_orig_sys_path = sys.path[:]
sys.path.extend(paths)
try:
yield
finally:
sys.path = _orig_sys_path
@contextmanager
def isolate_lru_cache(lru_cache_object):
"""Clear the cache of an LRU cache object on entering and exiting."""
lru_cache_object.cache_clear()
try:
yield
finally:
lru_cache_object.cache_clear()
@contextmanager
def captured_output(stream_name):
"""Return a context manager used by captured_stdout/stdin/stderr
that temporarily replaces the sys stream *stream_name* with a StringIO.
Note: This function and the following ``captured_std*`` are copied
from CPython's ``test.support`` module."""
orig_stdout = getattr(sys, stream_name)
setattr(sys, stream_name, six.StringIO())
try:
yield getattr(sys, stream_name)
finally:
setattr(sys, stream_name, orig_stdout)
def captured_stdout():
"""Capture the output of sys.stdout:
with captured_stdout() as stdout:
print("hello")
self.assertEqual(stdout.getvalue(), "hello\n")
"""
return captured_output("stdout")
def captured_stderr():
"""Capture the output of sys.stderr:
with captured_stderr() as stderr:
print("hello", file=sys.stderr)
self.assertEqual(stderr.getvalue(), "hello\n")
"""
return captured_output("stderr")
def captured_stdin():
"""Capture the input to sys.stdin:
with captured_stdin() as stdin:
stdin.write('hello\n')
stdin.seek(0)
# call test code that consumes from sys.stdin
captured = input()
self.assertEqual(captured, "hello")
"""
return captured_output("stdin")
def reset_warning_registry():
"""
Clear warning registry for all modules. This is required in some tests
because of a bug in Python that prevents warnings.simplefilter("always")
from always making warnings appear: http://bugs.python.org/issue4180
The bug was fixed in Python 3.4.2.
"""
key = "__warningregistry__"
for mod in sys.modules.values():
if hasattr(mod, key):
getattr(mod, key).clear()
@contextmanager
def freeze_time(t):
"""
Context manager to temporarily freeze time.time(). This temporarily
modifies the time function of the time module. Modules which import the
time function directly (e.g. `from time import time`) won't be affected
This isn't meant as a public API, but helps reduce some repetitive code in
Django's test suite.
"""
_real_time = time.time
time.time = lambda: t
try:
yield
finally:
time.time = _real_time
def require_jinja2(test_func):
"""
Decorator to enable a Jinja2 template engine in addition to the regular
Django template engine for a test or skip it if Jinja2 isn't available.
"""
test_func = skipIf(jinja2 is None, "this test requires jinja2")(test_func)
test_func = override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
}, {
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'APP_DIRS': True,
'OPTIONS': {'keep_trailing_newline': True},
}])(test_func)
return test_func
class override_script_prefix(TestContextDecorator):
"""
Decorator or context manager to temporary override the script prefix.
"""
def __init__(self, prefix):
self.prefix = prefix
super(override_script_prefix, self).__init__()
def enable(self):
self.old_prefix = get_script_prefix()
set_script_prefix(self.prefix)
def disable(self):
set_script_prefix(self.old_prefix)
class LoggingCaptureMixin(object):
"""
Capture the output from the 'django' logger and store it on the class's
logger_output attribute.
"""
def setUp(self):
self.logger = logging.getLogger('django')
self.old_stream = self.logger.handlers[0].stream
self.logger_output = six.StringIO()
self.logger.handlers[0].stream = self.logger_output
def tearDown(self):
self.logger.handlers[0].stream = self.old_stream
class isolate_apps(TestContextDecorator):
"""
Act as either a decorator or a context manager to register models defined
in its wrapped context to an isolated registry.
The list of installed apps the isolated registry should contain must be
passed as arguments.
Two optional keyword arguments can be specified:
`attr_name`: attribute assigned the isolated registry if used as a class
decorator.
`kwarg_name`: keyword argument passing the isolated registry if used as a
function decorator.
"""
def __init__(self, *installed_apps, **kwargs):
self.installed_apps = installed_apps
super(isolate_apps, self).__init__(**kwargs)
def enable(self):
self.old_apps = Options.default_apps
apps = Apps(self.installed_apps)
setattr(Options, 'default_apps', apps)
return apps
def disable(self):
setattr(Options, 'default_apps', self.old_apps)
def tag(*tags):
"""
Decorator to add tags to a test class or method.
"""
def decorator(obj):
setattr(obj, 'tags', set(tags))
return obj
return decorator
|
bsd-3-clause
|
[
646,
5055,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
646,
3598,
199,
504,
15502,
492,
27608,
199,
504,
9143,
492,
14018,
199,
504,
2882,
492,
7640,
12,
3372,
3917,
12,
3372,
5524,
199,
504,
2748,
14,
4556,
14,
21827,
492,
5013,
12,
2198,
1558,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
5181,
14,
5189,
492,
4693,
83,
199,
504,
1639,
14,
2190,
492,
2876,
5268,
22570,
12,
2202,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
10458,
492,
1056,
63,
8924,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
12,
6947,
12,
5305,
63,
10590,
199,
504,
1639,
14,
697,
14,
992,
14,
1419,
492,
8394,
199,
504,
1639,
14,
1160,
492,
5458,
199,
504,
1639,
14,
396,
14,
10458,
492,
4260,
63,
2489,
12,
1978,
63,
16841,
199,
504,
1639,
14,
3603,
492,
664,
63,
1579,
63,
1861,
12,
663,
63,
1579,
63,
1861,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
11582,
492,
2808,
63,
3288,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
25560,
199,
199,
692,
3816,
14,
4521,
19,
26,
272,
687,
2943,
492,
5870,
8814,
199,
2836,
26,
272,
1021,
5870,
8814,
8,
785,
304,
267,
986,
199,
199,
893,
26,
272,
492,
10321,
18,
199,
2590,
3545,
26,
272,
10321,
18,
275,
488,
421,
199,
363,
452,
363,
275,
334,
272,
283,
13117,
8221,
6897,
297,
283,
2998,
1296,
297,
283,
31188,
63,
25003,
63,
1637,
297,
283,
362,
63,
5933,
297,
272,
283,
8951,
63,
1751,
297,
283,
4415,
63,
1751,
297,
272,
283,
6537,
63,
3903,
63,
4058,
297,
272,
283,
2758,
63,
396,
63,
5418,
297,
283,
15236,
63,
396,
63,
5418,
297,
199,
9,
199,
199,
14226,
63,
10640,
275,
2688,
8,
521,
12,
283,
3903,
409,
358,
421,
199,
533,
13450,
8221,
6897,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1139,
12,
9825,
29,
23,
304,
267,
291,
14,
637,
275,
1139,
267,
291,
14,
10696,
275,
9825,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
637,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
291,
14,
637,
508,
1163,
26,
288,
372,
715,
267,
372,
6168,
8,
2101,
8,
277,
14,
637,
446,
1163,
395,
291,
14,
10696,
9,
508,
378,
421,
199,
533,
9470,
1296,
8,
513,
304,
272,
408,
33,
4975,
626,
6571,
4125,
790,
2879,
370,
1067,
2974,
10470,
272,
315,
282,
769,
402,
1067,
2251,
14,
272,
408,
272,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
1228,
8,
498,
12,
3816,
14,
875,
63,
1313,
304,
288,
367,
1007,
1100,
315,
291,
26,
355,
340,
790,
315,
1007,
1100,
26,
490,
372,
1007,
1100,
59,
498,
61,
288,
746,
4067,
8,
498,
9,
267,
587,
26,
288,
372,
1613,
8,
2998,
1296,
12,
291,
2843,
6095,
721,
498,
9,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
862,
26,
288,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
372,
756,
267,
372,
715,
339,
347,
2883,
8,
277,
304,
267,
408,
267,
19005,
724,
379,
2883,
402,
1007,
19010,
14,
267,
408,
267,
2883,
275,
663,
342,
267,
367,
1007,
1100,
315,
291,
26,
288,
367,
1211,
315,
1007,
1100,
26,
355,
2883,
8901,
663,
8,
807,
14,
1612,
1012,
267,
372,
2883,
421,
199,
318,
18885,
12546,
63,
396,
63,
3352,
8,
277,
12,
1067,
304,
272,
408,
272,
1626,
18885,
12546,
5458,
3795,
1083,
12,
13070,
282,
4673,
272,
626,
883,
506,
1640,
7203,
701,
314,
511,
2656,
6810,
272,
408,
272,
1978,
63,
16841,
14,
2254,
8,
8114,
29,
277,
12,
1978,
29,
277,
12,
1067,
29,
1100,
9,
272,
372,
291,
14,
14371,
14,
3352,
8,
1100,
9,
421,
199,
533,
485,
774,
2223,
8,
785,
304,
272,
986,
421,
199,
318,
3272,
63,
396,
63,
5418,
8,
1757,
29,
403,
304,
272,
408,
272,
14795,
2288,
876,
13,
396,
3272,
12,
4066,
465,
22200,
314,
18885,
12546,
1978,
272,
11889,
436,
4260,
314,
3031,
4865,
370,
314,
4355,
5286,
3031,
4865,
14,
272,
408,
272,
340,
2688,
1547,
774,
2223,
12,
283,
8420,
63,
576,
735,
267,
327,
9434,
4655,
642,
805,
13373,
3955,
8970,
314,
6290,
1338,
14,
267,
746,
6064,
8,
288,
298,
2758,
63,
396,
63,
5418,
342,
1990,
2575,
2797,
436,
883,
1133,
506,
2797,
298,
288,
298,
14199,
1928,
1642,
6358,
17558,
63,
396,
63,
5418,
1252,
2,
267,
776,
339,
340,
3105,
365,
488,
26,
267,
3105,
275,
2202,
14,
5287,
339,
6290,
63,
576,
275,
5870,
8814,
342,
272,
485,
774,
2223,
14,
8420,
63,
576,
275,
6290,
63,
576,
339,
6290,
63,
576,
14,
6541,
63,
5146,
275,
2202,
14,
17350,
63,
23775,
272,
327,
2654,
314,
849,
1591,
402,
314,
511,
1890,
14,
272,
2202,
14,
17350,
63,
23775,
275,
2202,
14,
17350,
63,
23775,
435,
788,
22471,
418,
339,
6290,
63,
576,
14,
1757,
275,
2202,
14,
5287,
272,
2202,
14,
5287,
275,
3105,
339,
6290,
63,
576,
14,
2123,
63,
4620,
275,
2202,
14,
10089,
63,
18145,
272,
2202,
14,
10089,
63,
18145,
275,
283,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
2102,
5286,
14,
7035,
8447,
7,
339,
6290,
63,
576,
14,
1160,
63,
3352,
275,
5458,
423,
3352,
272,
5458,
423,
3352,
275,
18885,
12546,
63,
396,
63,
3352,
339,
6016,
14,
17244,
275,
942,
339,
25560,
342,
421,
199,
318,
17558,
63,
396,
63,
5418,
837,
272,
408,
272,
14795,
1263,
2288,
2963,
13,
396,
17558,
12,
4066,
465,
4618,
6854,
314,
3379,
272,
1978,
11889,
436,
4618,
6854,
314,
3031,
10209,
3423,
14,
272,
408,
272,
6290,
63,
576,
275,
485,
774,
2223,
14,
8420,
63,
576,
339,
2202,
14,
17350,
63,
23775,
275,
6290,
63,
576,
14,
6541,
63,
5146,
272,
2202,
14,
5287,
275,
6290,
63,
576,
14,
1757,
272,
2202,
14,
10089,
63,
18145,
275,
6290,
63,
576,
14,
2123,
63
] |
[
5055,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
646,
3598,
199,
504,
15502,
492,
27608,
199,
504,
9143,
492,
14018,
199,
504,
2882,
492,
7640,
12,
3372,
3917,
12,
3372,
5524,
199,
504,
2748,
14,
4556,
14,
21827,
492,
5013,
12,
2198,
1558,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
5181,
14,
5189,
492,
4693,
83,
199,
504,
1639,
14,
2190,
492,
2876,
5268,
22570,
12,
2202,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
10458,
492,
1056,
63,
8924,
199,
504,
1639,
14,
697,
492,
6186,
63,
2846,
63,
12644,
12,
6947,
12,
5305,
63,
10590,
199,
504,
1639,
14,
697,
14,
992,
14,
1419,
492,
8394,
199,
504,
1639,
14,
1160,
492,
5458,
199,
504,
1639,
14,
396,
14,
10458,
492,
4260,
63,
2489,
12,
1978,
63,
16841,
199,
504,
1639,
14,
3603,
492,
664,
63,
1579,
63,
1861,
12,
663,
63,
1579,
63,
1861,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
11582,
492,
2808,
63,
3288,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
25560,
199,
199,
692,
3816,
14,
4521,
19,
26,
272,
687,
2943,
492,
5870,
8814,
199,
2836,
26,
272,
1021,
5870,
8814,
8,
785,
304,
267,
986,
199,
199,
893,
26,
272,
492,
10321,
18,
199,
2590,
3545,
26,
272,
10321,
18,
275,
488,
421,
199,
363,
452,
363,
275,
334,
272,
283,
13117,
8221,
6897,
297,
283,
2998,
1296,
297,
283,
31188,
63,
25003,
63,
1637,
297,
283,
362,
63,
5933,
297,
272,
283,
8951,
63,
1751,
297,
283,
4415,
63,
1751,
297,
272,
283,
6537,
63,
3903,
63,
4058,
297,
272,
283,
2758,
63,
396,
63,
5418,
297,
283,
15236,
63,
396,
63,
5418,
297,
199,
9,
199,
199,
14226,
63,
10640,
275,
2688,
8,
521,
12,
283,
3903,
409,
358,
421,
199,
533,
13450,
8221,
6897,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1139,
12,
9825,
29,
23,
304,
267,
291,
14,
637,
275,
1139,
267,
291,
14,
10696,
275,
9825,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
637,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
291,
14,
637,
508,
1163,
26,
288,
372,
715,
267,
372,
6168,
8,
2101,
8,
277,
14,
637,
446,
1163,
395,
291,
14,
10696,
9,
508,
378,
421,
199,
533,
9470,
1296,
8,
513,
304,
272,
408,
33,
4975,
626,
6571,
4125,
790,
2879,
370,
1067,
2974,
10470,
272,
315,
282,
769,
402,
1067,
2251,
14,
272,
408,
272,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
1228,
8,
498,
12,
3816,
14,
875,
63,
1313,
304,
288,
367,
1007,
1100,
315,
291,
26,
355,
340,
790,
315,
1007,
1100,
26,
490,
372,
1007,
1100,
59,
498,
61,
288,
746,
4067,
8,
498,
9,
267,
587,
26,
288,
372,
1613,
8,
2998,
1296,
12,
291,
2843,
6095,
721,
498,
9,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
862,
26,
288,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
372,
756,
267,
372,
715,
339,
347,
2883,
8,
277,
304,
267,
408,
267,
19005,
724,
379,
2883,
402,
1007,
19010,
14,
267,
408,
267,
2883,
275,
663,
342,
267,
367,
1007,
1100,
315,
291,
26,
288,
367,
1211,
315,
1007,
1100,
26,
355,
2883,
8901,
663,
8,
807,
14,
1612,
1012,
267,
372,
2883,
421,
199,
318,
18885,
12546,
63,
396,
63,
3352,
8,
277,
12,
1067,
304,
272,
408,
272,
1626,
18885,
12546,
5458,
3795,
1083,
12,
13070,
282,
4673,
272,
626,
883,
506,
1640,
7203,
701,
314,
511,
2656,
6810,
272,
408,
272,
1978,
63,
16841,
14,
2254,
8,
8114,
29,
277,
12,
1978,
29,
277,
12,
1067,
29,
1100,
9,
272,
372,
291,
14,
14371,
14,
3352,
8,
1100,
9,
421,
199,
533,
485,
774,
2223,
8,
785,
304,
272,
986,
421,
199,
318,
3272,
63,
396,
63,
5418,
8,
1757,
29,
403,
304,
272,
408,
272,
14795,
2288,
876,
13,
396,
3272,
12,
4066,
465,
22200,
314,
18885,
12546,
1978,
272,
11889,
436,
4260,
314,
3031,
4865,
370,
314,
4355,
5286,
3031,
4865,
14,
272,
408,
272,
340,
2688,
1547,
774,
2223,
12,
283,
8420,
63,
576,
735,
267,
327,
9434,
4655,
642,
805,
13373,
3955,
8970,
314,
6290,
1338,
14,
267,
746,
6064,
8,
288,
298,
2758,
63,
396,
63,
5418,
342,
1990,
2575,
2797,
436,
883,
1133,
506,
2797,
298,
288,
298,
14199,
1928,
1642,
6358,
17558,
63,
396,
63,
5418,
1252,
2,
267,
776,
339,
340,
3105,
365,
488,
26,
267,
3105,
275,
2202,
14,
5287,
339,
6290,
63,
576,
275,
5870,
8814,
342,
272,
485,
774,
2223,
14,
8420,
63,
576,
275,
6290,
63,
576,
339,
6290,
63,
576,
14,
6541,
63,
5146,
275,
2202,
14,
17350,
63,
23775,
272,
327,
2654,
314,
849,
1591,
402,
314,
511,
1890,
14,
272,
2202,
14,
17350,
63,
23775,
275,
2202,
14,
17350,
63,
23775,
435,
788,
22471,
418,
339,
6290,
63,
576,
14,
1757,
275,
2202,
14,
5287,
272,
2202,
14,
5287,
275,
3105,
339,
6290,
63,
576,
14,
2123,
63,
4620,
275,
2202,
14,
10089,
63,
18145,
272,
2202,
14,
10089,
63,
18145,
275,
283,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
2102,
5286,
14,
7035,
8447,
7,
339,
6290,
63,
576,
14,
1160,
63,
3352,
275,
5458,
423,
3352,
272,
5458,
423,
3352,
275,
18885,
12546,
63,
396,
63,
3352,
339,
6016,
14,
17244,
275,
942,
339,
25560,
342,
421,
199,
318,
17558,
63,
396,
63,
5418,
837,
272,
408,
272,
14795,
1263,
2288,
2963,
13,
396,
17558,
12,
4066,
465,
4618,
6854,
314,
3379,
272,
1978,
11889,
436,
4618,
6854,
314,
3031,
10209,
3423,
14,
272,
408,
272,
6290,
63,
576,
275,
485,
774,
2223,
14,
8420,
63,
576,
339,
2202,
14,
17350,
63,
23775,
275,
6290,
63,
576,
14,
6541,
63,
5146,
272,
2202,
14,
5287,
275,
6290,
63,
576,
14,
1757,
272,
2202,
14,
10089,
63,
18145,
275,
6290,
63,
576,
14,
2123,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
endlessm/chromium-browser
|
third_party/webrtc/tools_webrtc/vim/webrtc.ycm_extra_conf.py
|
5
|
12354
|
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
# Autocompletion config for YouCompleteMe in WebRTC. This is just copied from
# tools/vim in chromium with very minor modifications.
#
# USAGE:
#
# 1. Install YCM [https://github.com/Valloric/YouCompleteMe]
# (Googlers should check out [go/ycm])
#
# 2. Create a symbolic link to this file called .ycm_extra_conf.py in the
# directory above your WebRTC checkout (i.e. next to your .gclient file).
#
# cd src
# ln -rs tools_webrtc/vim/webrtc.ycm_extra_conf.py \
# ../.ycm_extra_conf.py
#
# 3. (optional) Whitelist the .ycm_extra_conf.py from step #2 by adding the
# following to your .vimrc:
#
# let g:ycm_extra_conf_globlist=['<path to .ycm_extra_conf.py>']
#
# You can also add other .ycm_extra_conf.py files you want to use to this
# list to prevent excessive prompting each time you visit a directory
# covered by a config file.
#
# 4. Profit
#
#
# Usage notes:
#
# * You must use ninja & clang to build WebRTC.
#
# * You must have run "gn gen" and built WebRTC recently.
#
#
# Hacking notes:
#
# * The purpose of this script is to construct an accurate enough command line
# for YCM to pass to clang so it can build and extract the symbols.
#
# * Right now, we only pull the -I and -D flags. That seems to be sufficient
# for everything I've used it for.
#
# * That whole ninja & clang thing? We could support other configs if someone
# were willing to write the correct commands and a parser.
#
# * This has only been tested on gPrecise.
import os
import os.path
import shlex
import subprocess
import sys
# Flags from YCM's default config.
_DEFAULT_FLAGS = [
'-DUSE_CLANG_COMPLETER',
'-std=c++11',
'-x',
'c++',
]
_HEADER_ALTERNATES = ('.cc', '.cpp', '.c', '.mm', '.m')
_EXTENSION_FLAGS = {
'.m': ['-x', 'objective-c'],
'.mm': ['-x', 'objective-c++'],
}
def PathExists(*args):
return os.path.exists(os.path.join(*args))
def FindWebrtcSrcFromFilename(filename):
"""Searches for the root of the WebRTC checkout.
Simply checks parent directories until it finds .gclient and src/.
Args:
filename: (String) Path to source file being edited.
Returns:
(String) Path of 'src/', or None if unable to find.
"""
curdir = os.path.normpath(os.path.dirname(filename))
while not (os.path.basename(curdir) == 'src'
and PathExists(curdir, 'DEPS')
and (PathExists(curdir, '..', '.gclient')
or PathExists(curdir, '.git'))):
nextdir = os.path.normpath(os.path.join(curdir, '..'))
if nextdir == curdir:
return None
curdir = nextdir
return curdir
def GetDefaultSourceFile(webrtc_root, filename):
"""Returns the default source file to use as an alternative to |filename|.
Compile flags used to build the default source file is assumed to be a
close-enough approximation for building |filename|.
Args:
webrtc_root: (String) Absolute path to the root of WebRTC checkout.
filename: (String) Absolute path to the source file.
Returns:
(String) Absolute path to substitute source file.
"""
if 'test.' in filename:
return os.path.join(webrtc_root, 'base', 'logging_unittest.cc')
return os.path.join(webrtc_root, 'base', 'logging.cc')
def GetNinjaBuildOutputsForSourceFile(out_dir, filename):
"""Returns a list of build outputs for filename.
The list is generated by invoking 'ninja -t query' tool to retrieve a list of
inputs and outputs of |filename|. This list is then filtered to only include
.o and .obj outputs.
Args:
out_dir: (String) Absolute path to ninja build output directory.
filename: (String) Absolute path to source file.
Returns:
(List of Strings) List of target names. Will return [] if |filename| doesn't
yield any .o or .obj outputs.
"""
# Ninja needs the path to the source file relative to the output build
# directory.
rel_filename = os.path.relpath(filename, out_dir)
p = subprocess.Popen(['ninja', '-C', out_dir, '-t', 'query', rel_filename],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
stdout, _ = p.communicate()
if p.returncode != 0:
return []
# The output looks like:
# ../../relative/path/to/source.cc:
# outputs:
# obj/reative/path/to/target.source.o
# obj/some/other/target2.source.o
# another/target.txt
#
outputs_text = stdout.partition('\n outputs:\n')[2]
output_lines = [line.strip() for line in outputs_text.split('\n')]
return [target for target in output_lines
if target and (target.endswith('.o') or target.endswith('.obj'))]
def GetClangCommandLineForNinjaOutput(out_dir, build_target):
"""Returns the Clang command line for building |build_target|
Asks ninja for the list of commands used to build |filename| and returns the
final Clang invocation.
Args:
out_dir: (String) Absolute path to ninja build output directory.
build_target: (String) A build target understood by ninja
Returns:
(String or None) Clang command line or None if a Clang command line couldn't
be determined.
"""
p = subprocess.Popen(['ninja', '-v', '-C', out_dir,
'-t', 'commands', build_target],
stdout=subprocess.PIPE, universal_newlines=True)
stdout, _ = p.communicate()
if p.returncode != 0:
return None
# Ninja will return multiple build steps for all dependencies up to
# |build_target|. The build step we want is the last Clang invocation, which
# is expected to be the one that outputs |build_target|.
for line in reversed(stdout.split('\n')):
if 'clang' in line:
return line
return None
def GetClangCommandLineFromNinjaForSource(out_dir, filename):
"""Returns a Clang command line used to build |filename|.
The same source file could be built multiple times using different tool
chains. In such cases, this command returns the first Clang invocation. We
currently don't prefer one toolchain over another. Hopefully the tool chain
corresponding to the Clang command line is compatible with the Clang build
used by YCM.
Args:
out_dir: (String) Absolute path to WebRTC checkout.
filename: (String) Absolute path to source file.
Returns:
(String or None): Command line for Clang invocation using |filename| as a
source. Returns None if no such command line could be found.
"""
build_targets = GetNinjaBuildOutputsForSourceFile(out_dir, filename)
for build_target in build_targets:
command_line = GetClangCommandLineForNinjaOutput(out_dir, build_target)
if command_line:
return command_line
return None
def GetClangOptionsFromCommandLine(clang_commandline, out_dir,
additional_flags):
"""Extracts relevant command line options from |clang_commandline|
Args:
clang_commandline: (String) Full Clang invocation.
out_dir: (String) Absolute path to ninja build directory. Relative paths in
the command line are relative to |out_dir|.
additional_flags: (List of String) Additional flags to return.
Returns:
(List of Strings) The list of command line flags for this source file. Can
be empty.
"""
clang_flags = [] + additional_flags
# Parse flags that are important for YCM's purposes.
clang_tokens = shlex.split(clang_commandline)
for flag_index, flag in enumerate(clang_tokens):
if flag.startswith('-I'):
# Relative paths need to be resolved, because they're relative to the
# output dir, not the source.
if flag[2] == '/':
clang_flags.append(flag)
else:
abs_path = os.path.normpath(os.path.join(out_dir, flag[2:]))
clang_flags.append('-I' + abs_path)
elif flag.startswith('-std'):
clang_flags.append(flag)
elif flag.startswith('-') and flag[1] in 'DWFfmO':
if flag == '-Wno-deprecated-register' or flag == '-Wno-header-guard':
# These flags causes libclang (3.3) to crash. Remove it until things
# are fixed.
continue
clang_flags.append(flag)
elif flag == '-isysroot':
# On Mac -isysroot <path> is used to find the system headers.
# Copy over both flags.
if flag_index + 1 < len(clang_tokens):
clang_flags.append(flag)
clang_flags.append(clang_tokens[flag_index + 1])
elif flag.startswith('--sysroot='):
# On Linux we use a sysroot image.
sysroot_path = flag.lstrip('--sysroot=')
if sysroot_path.startswith('/'):
clang_flags.append(flag)
else:
abs_path = os.path.normpath(os.path.join(out_dir, sysroot_path))
clang_flags.append('--sysroot=' + abs_path)
return clang_flags
def GetClangOptionsFromNinjaForFilename(webrtc_root, filename):
"""Returns the Clang command line options needed for building |filename|.
Command line options are based on the command used by ninja for building
|filename|. If |filename| is a .h file, uses its companion .cc or .cpp file.
If a suitable companion file can't be located or if ninja doesn't know about
|filename|, then uses default source files in WebRTC for determining the
commandline.
Args:
webrtc_root: (String) Path to src/.
filename: (String) Absolute path to source file being edited.
Returns:
(List of Strings) The list of command line flags for this source file. Can
be empty.
"""
if not webrtc_root:
return []
# Generally, everyone benefits from including WebRTC's src/, because all of
# WebRTC's includes are relative to that.
additional_flags = ['-I' + os.path.join(webrtc_root)]
# Version of Clang used to compile WebRTC can be newer then version of
# libclang that YCM uses for completion. So it's possible that YCM's libclang
# doesn't know about some used warning options, which causes compilation
# warnings (and errors, because of '-Werror');
additional_flags.append('-Wno-unknown-warning-option')
sys.path.append(os.path.join(webrtc_root, 'tools', 'vim'))
from ninja_output import GetNinjaOutputDirectory
out_dir = GetNinjaOutputDirectory(webrtc_root)
basename, extension = os.path.splitext(filename)
if extension == '.h':
candidates = [basename + ext for ext in _HEADER_ALTERNATES]
else:
candidates = [filename]
clang_line = None
buildable_extension = extension
for candidate in candidates:
clang_line = GetClangCommandLineFromNinjaForSource(out_dir, candidate)
if clang_line:
buildable_extension = os.path.splitext(candidate)[1]
break
additional_flags += _EXTENSION_FLAGS.get(buildable_extension, [])
if not clang_line:
# If ninja didn't know about filename or it's companion files, then try a
# default build target. It is possible that the file is new, or build.ninja
# is stale.
clang_line = GetClangCommandLineFromNinjaForSource(
out_dir, GetDefaultSourceFile(webrtc_root, filename))
if not clang_line:
return additional_flags
return GetClangOptionsFromCommandLine(clang_line, out_dir, additional_flags)
def FlagsForFile(filename):
"""This is the main entry point for YCM. Its interface is fixed.
Args:
filename: (String) Path to source file being edited.
Returns:
(Dictionary)
'flags': (List of Strings) Command line flags.
'do_cache': (Boolean) True if the result should be cached.
"""
abs_filename = os.path.abspath(filename)
webrtc_root = FindWebrtcSrcFromFilename(abs_filename)
clang_flags = GetClangOptionsFromNinjaForFilename(webrtc_root, abs_filename)
# If clang_flags could not be determined, then assume that was due to a
# transient failure. Preventing YCM from caching the flags allows us to try to
# determine the flags again.
should_cache_flags_for_file = bool(clang_flags)
final_flags = _DEFAULT_FLAGS + clang_flags
return {
'flags': final_flags,
'do_cache': should_cache_flags_for_file
}
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
9708,
710,
6001,
50,
5708,
2199,
11462,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
315,
314,
1738,
402,
314,
1350,
199,
3,
3123,
14,
1626,
4722,
27925,
1264,
1061,
3324,
4481,
16085,
883,
506,
1911,
199,
3,
315,
314,
570,
31467,
1309,
51,
14,
221,
2900,
5914,
4655,
2199,
11462,
1443,
199,
3,
506,
1911,
315,
314,
10610,
570,
315,
314,
1738,
402,
314,
1350,
3123,
14,
199,
199,
3,
9195,
13207,
1101,
367,
2047,
14175,
1352,
315,
6001,
50,
5708,
14,
961,
365,
2951,
8876,
687,
199,
3,
7249,
15,
16361,
315,
682,
7419,
543,
7437,
12612,
23070,
14,
199,
3,
199,
3,
19635,
2962,
26,
199,
3,
199,
3,
257,
413,
14,
13276,
1488,
9249,
359,
2859,
921,
5031,
14,
957,
15,
54,
452,
269,
530,
15,
5556,
14175,
1352,
61,
199,
3,
3515,
334,
7250,
974,
29099,
1077,
1104,
734,
359,
1939,
15,
89,
4400,
566,
199,
3,
199,
3,
257,
499,
14,
2790,
282,
13673,
2142,
370,
642,
570,
2797,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
315,
314,
199,
3,
420,
2082,
3432,
2195,
6001,
50,
5708,
15243,
334,
73,
14,
69,
14,
2163,
370,
2195,
1275,
71,
1258,
570,
680,
199,
3,
199,
3,
3515,
12829,
2928,
199,
3,
3515,
10359,
446,
2393,
7249,
63,
2520,
23392,
15,
16361,
15,
2520,
23392,
14,
89,
4400,
63,
2911,
63,
2190,
14,
647,
971,
199,
3,
3515,
2508,
8083,
89,
4400,
63,
2911,
63,
2190,
14,
647,
199,
3,
199,
3,
257,
650,
14,
334,
4144,
9,
2816,
1175,
513,
314,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
687,
3650,
327,
18,
701,
7791,
314,
199,
3,
420,
2569,
370,
2195,
1275,
16361,
1195,
26,
199,
3,
199,
3,
3515,
4691,
486,
26,
89,
4400,
63,
2911,
63,
2190,
63,
6463,
513,
2968,
28,
515,
370,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
18763,
199,
3,
199,
3,
420,
2047,
883,
2597,
1050,
1163,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
1584,
1265,
2934,
370,
675,
370,
642,
199,
3,
420,
769,
370,
7981,
444,
823,
3398,
21652,
1337,
1924,
900,
1265,
5684,
282,
2082,
199,
3,
420,
24295,
701,
282,
1101,
570,
14,
199,
3,
199,
3,
257,
841,
14,
2165,
3269,
199,
3,
199,
3,
199,
3,
11028,
12681,
26,
199,
3,
199,
3,
257,
627,
2047,
1471,
675,
14822,
1253,
25444,
370,
1900,
6001,
50,
5708,
14,
199,
3,
199,
3,
257,
627,
2047,
1471,
1172,
1255,
298,
784,
3805,
2,
436,
6137,
6001,
50,
5708,
23568,
14,
199,
3,
199,
3,
199,
3,
30802,
316,
12681,
26,
199,
3,
199,
3,
257,
627,
710,
12016,
402,
642,
2884,
365,
370,
6982,
376,
23189,
8321,
1414,
1004,
199,
3,
258,
367,
1488,
9249,
370,
986,
370,
25444,
880,
652,
883,
1900,
436,
5536,
314,
6698,
14,
199,
3,
199,
3,
257,
627,
20854,
3063,
12,
781,
1454,
10299,
314,
446,
41,
436,
446,
36,
3285,
14,
10314,
12237,
370,
506,
19258,
199,
3,
258,
367,
8137,
473,
9064,
1202,
652,
367,
14,
199,
3,
199,
3,
257,
627,
10314,
8852,
14822,
1253,
25444,
8377,
31,
2136,
4293,
2291,
1163,
11585,
340,
17122,
199,
3,
258,
4898,
911,
316,
370,
2218,
314,
3211,
3718,
436,
282,
1798,
14,
199,
3,
199,
3,
257,
627,
961,
965,
1454,
2757,
12470,
641,
486,
2398,
11900,
14,
421,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
16701,
199,
646,
3873,
199,
646,
984,
199,
199,
3,
24870,
687,
1488,
9249,
1159,
849,
1101,
14,
199,
63,
3472,
63,
4831,
275,
359,
523,
2475,
36,
4701,
63,
1981,
3986,
63,
12558,
775,
540,
297,
523,
2475,
1516,
29,
67,
4176,
845,
297,
523,
2475,
88,
297,
523,
283,
67,
31249,
199,
61,
199,
199,
63,
7311,
63,
748,
7689,
16601,
275,
23500,
2055,
297,
1987,
5910,
297,
1987,
67,
297,
1987,
596,
297,
1987,
77,
358,
199,
199,
63,
15498,
63,
4831,
275,
469,
523,
1987,
77,
356,
11573,
88,
297,
283,
24091,
13,
67,
995,
523,
1987,
596,
356,
11573,
88,
297,
283,
24091,
13,
67,
4176,
995,
199,
93,
199,
199,
318,
6912,
7965,
2031,
589,
304,
523,
372,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
2031,
589,
430,
421,
199,
318,
6668,
5926,
23392,
21261,
2532,
8117,
8,
1501,
304,
523,
408,
5278,
397,
367,
314,
1738,
402,
314,
6001,
50,
5708,
15243,
14,
819,
29094,
590,
5920,
1676,
6602,
5133,
652,
17651,
1275,
71,
1258,
436,
2928,
8083,
819,
3033,
26,
272,
1788,
26,
334,
1558,
9,
6912,
370,
1350,
570,
3769,
21062,
14,
819,
1803,
26,
272,
334,
1558,
9,
6912,
402,
283,
2164,
3678,
503,
488,
340,
17329,
370,
2342,
14,
523,
408,
523,
1094,
694,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
3475,
8,
1501,
430,
523,
1830,
440,
334,
736,
14,
515,
14,
4846,
8,
15594,
9,
508,
283,
2164,
7,
1467,
436,
6912,
7965,
8,
15594,
12,
283,
1093,
5067,
358,
1467,
436,
334,
2042,
7965,
8,
15594,
12,
19155,
1987,
71,
1258,
358,
2116,
503,
6912,
7965,
8,
15594,
12,
1987,
3187,
1333,
304,
272,
2163,
694,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
15594,
12,
11541,
1333,
272,
340,
2163,
694,
508,
1094,
694,
26,
489,
372,
488,
272,
1094,
694,
275,
2163,
694,
523,
372,
1094,
694,
421,
199,
318,
2372,
2698,
2980,
1173,
8,
2520,
23392,
63,
1231,
12,
1788,
304,
523,
408,
3407,
314,
849,
1350,
570,
370,
675,
465,
376,
13943,
370,
1204,
1501,
18257,
819,
24562,
3285,
1202,
370,
1900,
314,
849,
1350,
570,
365,
10826,
370,
506,
282,
523,
4002,
13,
30881,
22772,
367,
10015,
1204,
1501,
18257,
819,
3033,
26,
272,
3330,
23392,
63,
1231,
26,
334,
1558,
9,
24964,
931,
370,
314,
1738,
402,
6001,
50,
5708,
15243,
14,
272,
1788,
26,
334,
1558,
9,
24964,
931,
370,
314,
1350,
570,
14,
819,
1803,
26,
272,
334,
1558,
9
] |
[
1898,
334,
67,
9,
9708,
710,
6001,
50,
5708,
2199,
11462,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
199,
3,
626,
883,
506,
1911,
315,
314,
5113,
570,
315,
314,
1738,
402,
314,
1350,
199,
3,
3123,
14,
1626,
4722,
27925,
1264,
1061,
3324,
4481,
16085,
883,
506,
1911,
199,
3,
315,
314,
570,
31467,
1309,
51,
14,
221,
2900,
5914,
4655,
2199,
11462,
1443,
199,
3,
506,
1911,
315,
314,
10610,
570,
315,
314,
1738,
402,
314,
1350,
3123,
14,
199,
199,
3,
9195,
13207,
1101,
367,
2047,
14175,
1352,
315,
6001,
50,
5708,
14,
961,
365,
2951,
8876,
687,
199,
3,
7249,
15,
16361,
315,
682,
7419,
543,
7437,
12612,
23070,
14,
199,
3,
199,
3,
19635,
2962,
26,
199,
3,
199,
3,
257,
413,
14,
13276,
1488,
9249,
359,
2859,
921,
5031,
14,
957,
15,
54,
452,
269,
530,
15,
5556,
14175,
1352,
61,
199,
3,
3515,
334,
7250,
974,
29099,
1077,
1104,
734,
359,
1939,
15,
89,
4400,
566,
199,
3,
199,
3,
257,
499,
14,
2790,
282,
13673,
2142,
370,
642,
570,
2797,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
315,
314,
199,
3,
420,
2082,
3432,
2195,
6001,
50,
5708,
15243,
334,
73,
14,
69,
14,
2163,
370,
2195,
1275,
71,
1258,
570,
680,
199,
3,
199,
3,
3515,
12829,
2928,
199,
3,
3515,
10359,
446,
2393,
7249,
63,
2520,
23392,
15,
16361,
15,
2520,
23392,
14,
89,
4400,
63,
2911,
63,
2190,
14,
647,
971,
199,
3,
3515,
2508,
8083,
89,
4400,
63,
2911,
63,
2190,
14,
647,
199,
3,
199,
3,
257,
650,
14,
334,
4144,
9,
2816,
1175,
513,
314,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
687,
3650,
327,
18,
701,
7791,
314,
199,
3,
420,
2569,
370,
2195,
1275,
16361,
1195,
26,
199,
3,
199,
3,
3515,
4691,
486,
26,
89,
4400,
63,
2911,
63,
2190,
63,
6463,
513,
2968,
28,
515,
370,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
18763,
199,
3,
199,
3,
420,
2047,
883,
2597,
1050,
1163,
1275,
89,
4400,
63,
2911,
63,
2190,
14,
647,
1584,
1265,
2934,
370,
675,
370,
642,
199,
3,
420,
769,
370,
7981,
444,
823,
3398,
21652,
1337,
1924,
900,
1265,
5684,
282,
2082,
199,
3,
420,
24295,
701,
282,
1101,
570,
14,
199,
3,
199,
3,
257,
841,
14,
2165,
3269,
199,
3,
199,
3,
199,
3,
11028,
12681,
26,
199,
3,
199,
3,
257,
627,
2047,
1471,
675,
14822,
1253,
25444,
370,
1900,
6001,
50,
5708,
14,
199,
3,
199,
3,
257,
627,
2047,
1471,
1172,
1255,
298,
784,
3805,
2,
436,
6137,
6001,
50,
5708,
23568,
14,
199,
3,
199,
3,
199,
3,
30802,
316,
12681,
26,
199,
3,
199,
3,
257,
627,
710,
12016,
402,
642,
2884,
365,
370,
6982,
376,
23189,
8321,
1414,
1004,
199,
3,
258,
367,
1488,
9249,
370,
986,
370,
25444,
880,
652,
883,
1900,
436,
5536,
314,
6698,
14,
199,
3,
199,
3,
257,
627,
20854,
3063,
12,
781,
1454,
10299,
314,
446,
41,
436,
446,
36,
3285,
14,
10314,
12237,
370,
506,
19258,
199,
3,
258,
367,
8137,
473,
9064,
1202,
652,
367,
14,
199,
3,
199,
3,
257,
627,
10314,
8852,
14822,
1253,
25444,
8377,
31,
2136,
4293,
2291,
1163,
11585,
340,
17122,
199,
3,
258,
4898,
911,
316,
370,
2218,
314,
3211,
3718,
436,
282,
1798,
14,
199,
3,
199,
3,
257,
627,
961,
965,
1454,
2757,
12470,
641,
486,
2398,
11900,
14,
421,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
16701,
199,
646,
3873,
199,
646,
984,
199,
199,
3,
24870,
687,
1488,
9249,
1159,
849,
1101,
14,
199,
63,
3472,
63,
4831,
275,
359,
523,
2475,
36,
4701,
63,
1981,
3986,
63,
12558,
775,
540,
297,
523,
2475,
1516,
29,
67,
4176,
845,
297,
523,
2475,
88,
297,
523,
283,
67,
31249,
199,
61,
199,
199,
63,
7311,
63,
748,
7689,
16601,
275,
23500,
2055,
297,
1987,
5910,
297,
1987,
67,
297,
1987,
596,
297,
1987,
77,
358,
199,
199,
63,
15498,
63,
4831,
275,
469,
523,
1987,
77,
356,
11573,
88,
297,
283,
24091,
13,
67,
995,
523,
1987,
596,
356,
11573,
88,
297,
283,
24091,
13,
67,
4176,
995,
199,
93,
199,
199,
318,
6912,
7965,
2031,
589,
304,
523,
372,
747,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
2031,
589,
430,
421,
199,
318,
6668,
5926,
23392,
21261,
2532,
8117,
8,
1501,
304,
523,
408,
5278,
397,
367,
314,
1738,
402,
314,
6001,
50,
5708,
15243,
14,
819,
29094,
590,
5920,
1676,
6602,
5133,
652,
17651,
1275,
71,
1258,
436,
2928,
8083,
819,
3033,
26,
272,
1788,
26,
334,
1558,
9,
6912,
370,
1350,
570,
3769,
21062,
14,
819,
1803,
26,
272,
334,
1558,
9,
6912,
402,
283,
2164,
3678,
503,
488,
340,
17329,
370,
2342,
14,
523,
408,
523,
1094,
694,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
3475,
8,
1501,
430,
523,
1830,
440,
334,
736,
14,
515,
14,
4846,
8,
15594,
9,
508,
283,
2164,
7,
1467,
436,
6912,
7965,
8,
15594,
12,
283,
1093,
5067,
358,
1467,
436,
334,
2042,
7965,
8,
15594,
12,
19155,
1987,
71,
1258,
358,
2116,
503,
6912,
7965,
8,
15594,
12,
1987,
3187,
1333,
304,
272,
2163,
694,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
15594,
12,
11541,
1333,
272,
340,
2163,
694,
508,
1094,
694,
26,
489,
372,
488,
272,
1094,
694,
275,
2163,
694,
523,
372,
1094,
694,
421,
199,
318,
2372,
2698,
2980,
1173,
8,
2520,
23392,
63,
1231,
12,
1788,
304,
523,
408,
3407,
314,
849,
1350,
570,
370,
675,
465,
376,
13943,
370,
1204,
1501,
18257,
819,
24562,
3285,
1202,
370,
1900,
314,
849,
1350,
570,
365,
10826,
370,
506,
282,
523,
4002,
13,
30881,
22772,
367,
10015,
1204,
1501,
18257,
819,
3033,
26,
272,
3330,
23392,
63,
1231,
26,
334,
1558,
9,
24964,
931,
370,
314,
1738,
402,
6001,
50,
5708,
15243,
14,
272,
1788,
26,
334,
1558,
9,
24964,
931,
370,
314,
1350,
570,
14,
819,
1803,
26,
272,
334,
1558,
9,
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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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
helena/cassandra
|
pylib/cqlshlib/test/test_cqlsh_parsing.py
|
86
|
1038
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# to configure behavior, define $CQL_TEST_HOST to the destination address
# for Thrift connections, and $CQL_TEST_PORT to the associated port.
from unittest import TestCase
class TestCqlshParsing(TestCase):
def test_describe(self):
pass
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
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,
199,
3,
370,
7908,
5953,
12,
5627,
2672,
35,
2940,
63,
2864,
63,
5449,
370,
314,
5724,
2287,
199,
3,
367,
3868,
6501,
6947,
12,
436,
2672,
35,
2940,
63,
2864,
63,
3657,
370,
314,
4568,
1844,
14,
199,
199,
504,
2882,
492,
7640,
421,
199,
533,
1379,
35,
81,
23025,
17412,
8,
1746,
304,
272,
347,
511,
63,
11935,
8,
277,
304,
267,
986,
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
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
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,
199,
3,
370,
7908,
5953,
12,
5627,
2672,
35,
2940,
63,
2864,
63,
5449,
370,
314,
5724,
2287,
199,
3,
367,
3868,
6501,
6947,
12,
436,
2672,
35,
2940,
63,
2864,
63,
3657,
370,
314,
4568,
1844,
14,
199,
199,
504,
2882,
492,
7640,
421,
199,
533,
1379,
35,
81,
23025,
17412,
8,
1746,
304,
272,
347,
511,
63,
11935,
8,
277,
304,
267,
986,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Neitsch/ASE4156
|
authentication/graphql.py
|
1
|
9125
|
"""
GraphQL definitions for the Authentication App
"""
import datetime
from django.contrib.auth.models import User
from graphene import Argument, Field, Float, Int, List, Mutation, \
NonNull, String, relay
from graphene_django import DjangoObjectType, DjangoConnectionField
from trading.models import TradingAccount
from trading.graphql import GTradingAccount
from stocks.graphql import GInvestmentBucket, GStock, GDataPoint, DataPoint
from stocks.models import InvestmentBucket, Stock
from .models import Profile, UserBank
# pylint: disable=too-few-public-methods
class GUser(DjangoObjectType):
"""
This is the GraphQL representation of a :py:class:`django.contrib.auth.models.User`.
This should *only* be accessible for the user himself.
"""
class Meta(object):
"""
Meta Model for :py:class:`django.contrib.auth.models.User`. Most
important to note is the fields we expose:
ID, Profile, Username and UserBank(s)
"""
model = User
only_fields = ('id', 'profile', 'username', 'userbank')
interfaces = (relay.Node, )
class GProfile(DjangoObjectType):
"""
This is the GraphQL representation of a :py:class:`authentication.models.Profile`.
This is more of a publically accessible object. Even though we won't expose everything, this
object allows us to add more fields to the user object.
"""
stock_find = List(
NonNull(GStock),
args={'text': Argument(NonNull(String)),
'first': Argument(Int)})
invest_suggestions = DjangoConnectionField(GInvestmentBucket, )
selected_acc = NonNull(GTradingAccount)
class Meta(object):
"""
Meta Model for :py:class:`authentication.models.Profile`. We have edges to the
:py:class:`trading.models.TradingAccount` the User
has, a field that is the current Trading Account a User has, and a
function that allows the user to search for stocks.
"""
model = Profile
only_fields = ('id', 'trading_accounts', 'selected_acc', 'stock_find')
interfaces = (relay.Node, )
@staticmethod
def resolve_stock_find(_self, _info, text, first=None, **_args):
"""
Finds a stock given a case insensitive name.
(see :py:meth:`stocks.models.Stock.find_stock`)
:param text: The text the user want to search for.
:type name: str.
:param first: The maximum number of results to return
:type name: int.
:returns: :py:class:`django.db.models.query.QuerySet` of :py:class:`stocks.stocks.Stock`
"""
if first:
return Stock.find_stock(text, first)
return Stock.find_stock(text)
@staticmethod
def resolve_invest_suggestions(_data, info, **_args):
"""
Returns a list of buckets that the User can invest in.
(see :py:meth:`stocks.models.InvestmentBucket.available_buckets`)
:param info: Information about the user to check which recommendations
are best for the user.
:type info: Graphene Request Info.
:returns: :py:class:`django.db.models.query.QuerySet` of
:py:class:`stocks.models.InvestmentBucket`
"""
return InvestmentBucket.accessible_buckets(info.context.user.profile)
@staticmethod
def resolve_selected_acc(data, _info, **_args):
"""
Returns the current account the user has selected. Right now it just
calls the default account of the profile.
(see :py:meth:`authentication.models.Profile.default_acc`)
:returns: :py:class:`django.db.models.query.QuerySet` of
:py:class:`trading.models.TradingAccount`
"""
return data.default_acc()
class GUserBank(DjangoObjectType):
"""
GraphQL wrapper around the :py:class:`authentication.models.UserBank` model.
This should *only* be accessible to the user.
"""
balance = NonNull(Float)
income = NonNull(Float)
name = NonNull(String)
outcome = NonNull(Float)
history = NonNull(
List(NonNull(GDataPoint)), args={'start': Argument(NonNull(String))})
balance_date = NonNull(String)
monthly_start = NonNull(String)
monthly_end = NonNull(String)
class Meta(object):
"""
Meta Model for :py:class:`authentication.models.UserBank`. We want to expose the user's
balance, income and expenditure (here named outcome)
"""
model = UserBank
only_fields = ('id', 'balance', 'income', 'outcome')
interfaces = (relay.Node, )
@staticmethod
def resolve_history(data, _info, start, **_args):
"""
This method returns the account history for a user. This is, how much
value the bank account historically had.
(see :py:meth:`authentication.models.UserBank.historical_data`)
:param data: The bank we want to extract the history from.
:type data: :py:class:`authentication.models.UserBank`
:param start: The date with that the history should start. The query
will return the history from start until today.
:type start: str (YYYY-MM-dd).
:returns: `stocks.graphql.DataPoint` representing the history.
"""
return [
DataPoint(date, value)
for (date, value) in data.historical_data(start)
]
@staticmethod
def resolve_balance(data, _info, **_args):
"""
Calls :py:meth:`authentication.models.UserBank.current_balance` on
data.
:param data: The Userbank we want to extract the balance from.
:type data: :py:class:`authentication.models.UserBank`
:returns: The current balance of that the user has.
"""
return data.current_balance(False)
@staticmethod
def resolve_balance_date(_data, _info):
"""
Date of the balance
"""
return str(datetime.date.today())
@staticmethod
def resolve_monthly_start(_data, _info):
"""
Start date for measuring the monthly income/expenditure
"""
return str(datetime.date.today() - datetime.timedelta(days=30))
@staticmethod
def resolve_monthly_end(_data, _info):
"""
End date for measuring the monthly income/expenditure
"""
return str(datetime.date.today())
@staticmethod
def resolve_name(data, _info, **_args):
"""
Calls :py:meth:`authentication.models.UserBank.account_name` on
data.
:param data: The Userbank we want to get the account name.
:type data: :py:class:`authentication.models.UserBank`
:returns: The account name of the bank.
"""
return data.account_name(False)
@staticmethod
def resolve_income(data, _info, **_args):
"""
Calls :py:meth:`authentication.models.UserBank.income` on
data.
:param data: The Userbank we want to extract the income from.
:type data: :py:class:`authentication.models.UserBank`
:returns: The monthly income of the account.
"""
return data.income(False)
@staticmethod
def resolve_outcome(data, _info, **_args):
"""
Calls :py:meth:`authentication.models.UserBank.expenditure` on
data.
:param data: The Userbank we want to extract the expenditures from.
:type data: :py:class:`authentication.models.UserBank`
:returns: The monthly expenditure of the account.
"""
return data.expenditure(False)
# pylint: disable=no-init
class Query(object):
"""
The root of the viewer query. This is the base of building the user object
with all of its data.
"""
viewer = Field(GUser, )
@staticmethod
def resolve_viewer(_self, info, **_args):
"""
The viewer represents the data for the user making the request.
:param info: information about the request with context
:type data: Graphene Request Info.
"""
if not info.context.user.is_authenticated():
return None
return info.context.user
# pylint: enable=no-init
class AddTradingAccount(Mutation):
"""
AddTradingAccount creates a new :py:class:`trading.models.TradingAccount` for the user.
"""
class Arguments(object):
"""
Arguments to create a :py:class:`trading.models.TradingAccount`.
Right now we only need the name.
"""
name = String()
account = Field(lambda: GTradingAccount)
@staticmethod
def mutate(_self, info, name, **_args):
"""
Creates a new :py:class:`trading.models.TradingAccount` for the user and returns it.
:param info: Information about the request / user.
:type data: Graphene Request Info.
:param name: Name of the new trading account.
:type name: str
"""
account = TradingAccount(
profile=info.context.user.profile, account_name=name)
account.save()
return AddTradingAccount(account=account)
# pylint: enable=too-few-public-methods
|
apache-2.0
|
[
624,
199,
4578,
2940,
10269,
367,
314,
15995,
4693,
199,
624,
199,
646,
2197,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
3343,
6349,
492,
5886,
12,
5024,
12,
11140,
12,
9805,
12,
3820,
12,
603,
10326,
12,
971,
272,
10172,
8849,
12,
2624,
12,
25931,
199,
504,
3343,
6349,
63,
1176,
492,
5634,
1692,
804,
12,
5634,
3225,
792,
199,
504,
1468,
1098,
14,
992,
492,
12643,
1098,
6009,
199,
504,
1468,
1098,
14,
2180,
1710,
492,
598,
23210,
6009,
199,
504,
10952,
83,
14,
2180,
1710,
492,
598,
607,
13981,
434,
12311,
12,
598,
17103,
12,
598,
1451,
3428,
12,
3918,
3428,
199,
504,
10952,
83,
14,
992,
492,
1010,
13981,
434,
12311,
12,
28406,
199,
504,
1275,
992,
492,
14386,
12,
2876,
14814,
421,
199,
3,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
199,
533,
598,
1899,
8,
9323,
1692,
804,
304,
272,
408,
272,
961,
365,
314,
11513,
2940,
6025,
402,
282,
520,
647,
26,
533,
1705,
1176,
14,
2828,
14,
1178,
14,
992,
14,
1899,
2313,
272,
961,
1077,
627,
2118,
10,
506,
17909,
367,
314,
922,
26457,
277,
14,
272,
408,
339,
1021,
6288,
8,
785,
304,
267,
408,
267,
6288,
5822,
367,
520,
647,
26,
533,
1705,
1176,
14,
2828,
14,
1178,
14,
992,
14,
1899,
2313,
17536,
267,
11012,
370,
5317,
365,
314,
1504,
781,
23705,
26,
267,
2870,
12,
14386,
12,
29739,
436,
2876,
14814,
8,
83,
9,
267,
408,
267,
1402,
275,
2876,
267,
1454,
63,
955,
275,
661,
344,
297,
283,
2913,
297,
283,
2473,
297,
283,
751,
9860,
358,
267,
8386,
275,
334,
21855,
14,
1716,
12,
776,
421,
199,
533,
598,
5736,
8,
9323,
1692,
804,
304,
272,
408,
272,
961,
365,
314,
11513,
2940,
6025,
402,
282,
520,
647,
26,
533,
1705,
11725,
14,
992,
14,
5736,
2313,
272,
961,
365,
1655,
402,
282,
4575,
1183,
17909,
909,
14,
22207,
10617,
781,
7859,
1133,
23705,
8137,
12,
642,
272,
909,
6127,
2739,
370,
1050,
1655,
1504,
370,
314,
922,
909,
14,
272,
408,
272,
10952,
63,
1623,
275,
3820,
8,
267,
10172,
8849,
8,
39,
17103,
395,
267,
1249,
3713,
505,
356,
5886,
8,
6932,
8849,
8,
1558,
1826,
1598,
283,
2246,
356,
5886,
8,
3241,
11466,
272,
315,
13981,
63,
19957,
15293,
275,
5634,
3225,
792,
8,
39,
607,
13981,
434,
12311,
12,
776,
272,
4895,
63,
5470,
275,
10172,
8849,
8,
39,
23210,
6009,
9,
339,
1021,
6288,
8,
785,
304,
267,
408,
267,
6288,
5822,
367,
520,
647,
26,
533,
1705,
11725,
14,
992,
14,
5736,
2313,
2136,
1172,
8207,
370,
314,
267,
520,
647,
26,
533,
1705,
1239,
1098,
14,
992,
14,
23210,
6009,
64,
314,
2876,
267,
965,
12,
282,
901,
626,
365,
314,
1453,
12643,
1098,
9973,
282,
2876,
965,
12,
436,
282,
267,
805,
626,
6127,
314,
922,
370,
2754,
367,
10952,
83,
14,
267,
408,
267,
1402,
275,
14386,
267,
1454,
63,
955,
275,
661,
344,
297,
283,
1239,
1098,
63,
8370,
297,
283,
5511,
63,
5470,
297,
283,
6088,
63,
1623,
358,
267,
8386,
275,
334,
21855,
14,
1716,
12,
776,
339,
768,
4639,
272,
347,
7512,
63,
6088,
63,
1623,
1547,
277,
12,
485,
815,
12,
1318,
12,
1642,
29,
403,
12,
29666,
589,
304,
267,
408,
267,
31434,
282,
10952,
1627,
282,
1930,
27845,
536,
14,
267,
334,
3239,
520,
647,
26,
5247,
1705,
6088,
83,
14,
992,
14,
17103,
14,
1623,
63,
6088,
10522,
398,
520,
635,
1318,
26,
710,
1318,
314,
922,
2934,
370,
2754,
367,
14,
267,
520,
466,
536,
26,
620,
14,
267,
520,
635,
1642,
26,
710,
5696,
1329,
402,
2058,
370,
372,
267,
520,
466,
536,
26,
1109,
14,
267,
520,
5808,
26,
520,
647,
26,
533,
1705,
1176,
14,
697,
14,
992,
14,
1131,
14,
13689,
64,
402,
520,
647,
26,
533,
1705,
6088,
83,
14,
6088,
83,
14,
17103,
64,
267,
408,
267,
340,
1642,
26,
288,
372,
28406,
14,
1623,
63,
6088,
8,
505,
12,
1642,
9,
267,
372,
28406,
14,
1623,
63,
6088,
8,
505,
9,
339,
768,
4639,
272,
347,
7512,
63,
262,
13981,
63,
19957,
15293,
1547,
576,
12,
2256,
12,
29666,
589,
304,
267,
408,
267,
1803,
282,
769,
402,
18655,
626,
314,
2876,
883,
315,
13981,
315,
14,
267,
334,
3239,
520,
647,
26,
5247,
1705,
6088,
83,
14,
992,
14,
607,
13981,
434,
12311,
14,
4561,
63,
15065,
10522,
398,
520,
635,
2256,
26,
17064,
3595,
314,
922,
370,
1104,
1314,
27747,
1298,
288,
787,
5526,
367,
314,
922,
14,
267,
520,
466,
2256,
26,
11513,
6349,
4784,
10332,
14,
267,
520,
5808,
26,
520,
647,
26,
533,
1705,
1176,
14,
697,
14,
992,
14,
1131,
14,
13689,
64,
402,
288,
520,
647,
26,
533,
1705,
6088,
83,
14,
992,
14,
607,
13981,
434,
12311,
64,
267,
408,
267,
372,
1010,
13981,
434,
12311,
14,
24669,
63,
15065,
8,
815,
14,
1100,
14,
751,
14,
2913,
9,
339,
768,
4639,
272,
347,
7512,
63,
5511,
63,
5470,
8,
576,
12,
485,
815,
12,
29666,
589,
304,
267,
408,
267,
1803,
314,
1453,
2933,
314,
922,
965,
4895,
14,
20854,
3063,
652,
2951,
267,
4882,
314,
849,
2933,
402,
314,
4690,
14,
267,
334,
3239,
520,
647,
26,
5247,
1705,
11725,
14,
992,
14,
5736,
14,
885,
63,
5470,
10522,
398,
520,
5808,
26,
520,
647,
26,
533,
1705,
1176,
14,
697,
14,
992,
14,
1131,
14,
13689,
64,
402,
288,
520,
647,
26,
533,
1705,
1239,
1098,
14,
992,
14,
23210,
6009,
64,
267,
408,
267,
372,
666,
14,
885,
63,
5470,
342,
421,
199,
533,
598,
1899,
14814,
8,
9323,
1692,
804,
304,
272,
408,
272,
11513,
2940,
4975,
6818,
314,
520,
647,
26,
533,
1705,
11725,
14,
992,
14,
1899,
14814,
64,
1402,
14,
272,
961,
1077,
627,
2118,
10,
506,
17909,
370,
314,
922,
14,
272,
408,
272,
14094,
275,
10172,
8849,
8,
5136,
9,
272,
315,
4352,
275,
10172,
8849,
8,
5136,
9,
272,
536,
275,
10172,
8849,
8,
1558,
9,
272,
15955,
275,
10172,
8849,
8,
5136,
9,
272,
7994,
275,
10172,
8849,
8,
267,
3820,
8,
6932,
8849
] |
[
199,
4578,
2940,
10269,
367,
314,
15995,
4693,
199,
624,
199,
646,
2197,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
3343,
6349,
492,
5886,
12,
5024,
12,
11140,
12,
9805,
12,
3820,
12,
603,
10326,
12,
971,
272,
10172,
8849,
12,
2624,
12,
25931,
199,
504,
3343,
6349,
63,
1176,
492,
5634,
1692,
804,
12,
5634,
3225,
792,
199,
504,
1468,
1098,
14,
992,
492,
12643,
1098,
6009,
199,
504,
1468,
1098,
14,
2180,
1710,
492,
598,
23210,
6009,
199,
504,
10952,
83,
14,
2180,
1710,
492,
598,
607,
13981,
434,
12311,
12,
598,
17103,
12,
598,
1451,
3428,
12,
3918,
3428,
199,
504,
10952,
83,
14,
992,
492,
1010,
13981,
434,
12311,
12,
28406,
199,
504,
1275,
992,
492,
14386,
12,
2876,
14814,
421,
199,
3,
4287,
26,
3507,
29,
7354,
13,
70,
546,
13,
3455,
13,
2474,
199,
533,
598,
1899,
8,
9323,
1692,
804,
304,
272,
408,
272,
961,
365,
314,
11513,
2940,
6025,
402,
282,
520,
647,
26,
533,
1705,
1176,
14,
2828,
14,
1178,
14,
992,
14,
1899,
2313,
272,
961,
1077,
627,
2118,
10,
506,
17909,
367,
314,
922,
26457,
277,
14,
272,
408,
339,
1021,
6288,
8,
785,
304,
267,
408,
267,
6288,
5822,
367,
520,
647,
26,
533,
1705,
1176,
14,
2828,
14,
1178,
14,
992,
14,
1899,
2313,
17536,
267,
11012,
370,
5317,
365,
314,
1504,
781,
23705,
26,
267,
2870,
12,
14386,
12,
29739,
436,
2876,
14814,
8,
83,
9,
267,
408,
267,
1402,
275,
2876,
267,
1454,
63,
955,
275,
661,
344,
297,
283,
2913,
297,
283,
2473,
297,
283,
751,
9860,
358,
267,
8386,
275,
334,
21855,
14,
1716,
12,
776,
421,
199,
533,
598,
5736,
8,
9323,
1692,
804,
304,
272,
408,
272,
961,
365,
314,
11513,
2940,
6025,
402,
282,
520,
647,
26,
533,
1705,
11725,
14,
992,
14,
5736,
2313,
272,
961,
365,
1655,
402,
282,
4575,
1183,
17909,
909,
14,
22207,
10617,
781,
7859,
1133,
23705,
8137,
12,
642,
272,
909,
6127,
2739,
370,
1050,
1655,
1504,
370,
314,
922,
909,
14,
272,
408,
272,
10952,
63,
1623,
275,
3820,
8,
267,
10172,
8849,
8,
39,
17103,
395,
267,
1249,
3713,
505,
356,
5886,
8,
6932,
8849,
8,
1558,
1826,
1598,
283,
2246,
356,
5886,
8,
3241,
11466,
272,
315,
13981,
63,
19957,
15293,
275,
5634,
3225,
792,
8,
39,
607,
13981,
434,
12311,
12,
776,
272,
4895,
63,
5470,
275,
10172,
8849,
8,
39,
23210,
6009,
9,
339,
1021,
6288,
8,
785,
304,
267,
408,
267,
6288,
5822,
367,
520,
647,
26,
533,
1705,
11725,
14,
992,
14,
5736,
2313,
2136,
1172,
8207,
370,
314,
267,
520,
647,
26,
533,
1705,
1239,
1098,
14,
992,
14,
23210,
6009,
64,
314,
2876,
267,
965,
12,
282,
901,
626,
365,
314,
1453,
12643,
1098,
9973,
282,
2876,
965,
12,
436,
282,
267,
805,
626,
6127,
314,
922,
370,
2754,
367,
10952,
83,
14,
267,
408,
267,
1402,
275,
14386,
267,
1454,
63,
955,
275,
661,
344,
297,
283,
1239,
1098,
63,
8370,
297,
283,
5511,
63,
5470,
297,
283,
6088,
63,
1623,
358,
267,
8386,
275,
334,
21855,
14,
1716,
12,
776,
339,
768,
4639,
272,
347,
7512,
63,
6088,
63,
1623,
1547,
277,
12,
485,
815,
12,
1318,
12,
1642,
29,
403,
12,
29666,
589,
304,
267,
408,
267,
31434,
282,
10952,
1627,
282,
1930,
27845,
536,
14,
267,
334,
3239,
520,
647,
26,
5247,
1705,
6088,
83,
14,
992,
14,
17103,
14,
1623,
63,
6088,
10522,
398,
520,
635,
1318,
26,
710,
1318,
314,
922,
2934,
370,
2754,
367,
14,
267,
520,
466,
536,
26,
620,
14,
267,
520,
635,
1642,
26,
710,
5696,
1329,
402,
2058,
370,
372,
267,
520,
466,
536,
26,
1109,
14,
267,
520,
5808,
26,
520,
647,
26,
533,
1705,
1176,
14,
697,
14,
992,
14,
1131,
14,
13689,
64,
402,
520,
647,
26,
533,
1705,
6088,
83,
14,
6088,
83,
14,
17103,
64,
267,
408,
267,
340,
1642,
26,
288,
372,
28406,
14,
1623,
63,
6088,
8,
505,
12,
1642,
9,
267,
372,
28406,
14,
1623,
63,
6088,
8,
505,
9,
339,
768,
4639,
272,
347,
7512,
63,
262,
13981,
63,
19957,
15293,
1547,
576,
12,
2256,
12,
29666,
589,
304,
267,
408,
267,
1803,
282,
769,
402,
18655,
626,
314,
2876,
883,
315,
13981,
315,
14,
267,
334,
3239,
520,
647,
26,
5247,
1705,
6088,
83,
14,
992,
14,
607,
13981,
434,
12311,
14,
4561,
63,
15065,
10522,
398,
520,
635,
2256,
26,
17064,
3595,
314,
922,
370,
1104,
1314,
27747,
1298,
288,
787,
5526,
367,
314,
922,
14,
267,
520,
466,
2256,
26,
11513,
6349,
4784,
10332,
14,
267,
520,
5808,
26,
520,
647,
26,
533,
1705,
1176,
14,
697,
14,
992,
14,
1131,
14,
13689,
64,
402,
288,
520,
647,
26,
533,
1705,
6088,
83,
14,
992,
14,
607,
13981,
434,
12311,
64,
267,
408,
267,
372,
1010,
13981,
434,
12311,
14,
24669,
63,
15065,
8,
815,
14,
1100,
14,
751,
14,
2913,
9,
339,
768,
4639,
272,
347,
7512,
63,
5511,
63,
5470,
8,
576,
12,
485,
815,
12,
29666,
589,
304,
267,
408,
267,
1803,
314,
1453,
2933,
314,
922,
965,
4895,
14,
20854,
3063,
652,
2951,
267,
4882,
314,
849,
2933,
402,
314,
4690,
14,
267,
334,
3239,
520,
647,
26,
5247,
1705,
11725,
14,
992,
14,
5736,
14,
885,
63,
5470,
10522,
398,
520,
5808,
26,
520,
647,
26,
533,
1705,
1176,
14,
697,
14,
992,
14,
1131,
14,
13689,
64,
402,
288,
520,
647,
26,
533,
1705,
1239,
1098,
14,
992,
14,
23210,
6009,
64,
267,
408,
267,
372,
666,
14,
885,
63,
5470,
342,
421,
199,
533,
598,
1899,
14814,
8,
9323,
1692,
804,
304,
272,
408,
272,
11513,
2940,
4975,
6818,
314,
520,
647,
26,
533,
1705,
11725,
14,
992,
14,
1899,
14814,
64,
1402,
14,
272,
961,
1077,
627,
2118,
10,
506,
17909,
370,
314,
922,
14,
272,
408,
272,
14094,
275,
10172,
8849,
8,
5136,
9,
272,
315,
4352,
275,
10172,
8849,
8,
5136,
9,
272,
536,
275,
10172,
8849,
8,
1558,
9,
272,
15955,
275,
10172,
8849,
8,
5136,
9,
272,
7994,
275,
10172,
8849,
8,
267,
3820,
8,
6932,
8849,
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,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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
] |
GaussDing/django
|
tests/prefetch_related/models.py
|
42
|
7041
|
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
# Basic tests
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=50, unique=True)
first_book = models.ForeignKey('Book', related_name='first_time_authors')
favorite_authors = models.ManyToManyField(
'self', through='FavoriteAuthors', symmetrical=False, related_name='favors_me')
def __str__(self):
return self.name
class Meta:
ordering = ['id']
class AuthorWithAge(Author):
author = models.OneToOneField(Author, parent_link=True)
age = models.IntegerField()
class FavoriteAuthors(models.Model):
author = models.ForeignKey(Author, to_field='name', related_name='i_like')
likes_author = models.ForeignKey(Author, to_field='name', related_name='likes_me')
class Meta:
ordering = ['id']
@python_2_unicode_compatible
class AuthorAddress(models.Model):
author = models.ForeignKey(Author, to_field='name', related_name='addresses')
address = models.TextField()
class Meta:
ordering = ['id']
def __str__(self):
return self.address
@python_2_unicode_compatible
class Book(models.Model):
title = models.CharField(max_length=255)
authors = models.ManyToManyField(Author, related_name='books')
def __str__(self):
return self.title
class Meta:
ordering = ['id']
class BookWithYear(Book):
book = models.OneToOneField(Book, parent_link=True)
published_year = models.IntegerField()
aged_authors = models.ManyToManyField(
AuthorWithAge, related_name='books_with_year')
class Bio(models.Model):
author = models.OneToOneField(Author)
books = models.ManyToManyField(Book, blank=True)
@python_2_unicode_compatible
class Reader(models.Model):
name = models.CharField(max_length=50)
books_read = models.ManyToManyField(Book, related_name='read_by')
def __str__(self):
return self.name
class Meta:
ordering = ['id']
class BookReview(models.Model):
book = models.ForeignKey(BookWithYear)
notes = models.TextField(null=True, blank=True)
# Models for default manager tests
class Qualification(models.Model):
name = models.CharField(max_length=10)
class Meta:
ordering = ['id']
class TeacherManager(models.Manager):
def get_queryset(self):
return super(TeacherManager, self).get_queryset().prefetch_related('qualifications')
@python_2_unicode_compatible
class Teacher(models.Model):
name = models.CharField(max_length=50)
qualifications = models.ManyToManyField(Qualification)
objects = TeacherManager()
def __str__(self):
return "%s (%s)" % (self.name, ", ".join(q.name for q in self.qualifications.all()))
class Meta:
ordering = ['id']
class Department(models.Model):
name = models.CharField(max_length=50)
teachers = models.ManyToManyField(Teacher)
class Meta:
ordering = ['id']
# GenericRelation/GenericForeignKey tests
@python_2_unicode_compatible
class TaggedItem(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType, related_name="taggeditem_set2")
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
created_by_ct = models.ForeignKey(ContentType, null=True,
related_name='taggeditem_set3')
created_by_fkey = models.PositiveIntegerField(null=True)
created_by = GenericForeignKey('created_by_ct', 'created_by_fkey',)
favorite_ct = models.ForeignKey(ContentType, null=True,
related_name='taggeditem_set4')
favorite_fkey = models.CharField(max_length=64, null=True)
favorite = GenericForeignKey('favorite_ct', 'favorite_fkey')
def __str__(self):
return self.tag
class Meta:
ordering = ['id']
class Bookmark(models.Model):
url = models.URLField()
tags = GenericRelation(TaggedItem, related_query_name='bookmarks')
favorite_tags = GenericRelation(TaggedItem,
content_type_field='favorite_ct',
object_id_field='favorite_fkey',
related_query_name='favorite_bookmarks')
class Meta:
ordering = ['id']
class Comment(models.Model):
comment = models.TextField()
# Content-object field
content_type = models.ForeignKey(ContentType)
object_pk = models.TextField()
content_object = GenericForeignKey(ct_field="content_type", fk_field="object_pk")
class Meta:
ordering = ['id']
# Models for lookup ordering tests
class House(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=255)
owner = models.ForeignKey('Person', null=True)
main_room = models.OneToOneField('Room', related_name='main_room_of', null=True)
class Meta:
ordering = ['id']
class Room(models.Model):
name = models.CharField(max_length=50)
house = models.ForeignKey(House, related_name='rooms')
class Meta:
ordering = ['id']
class Person(models.Model):
name = models.CharField(max_length=50)
houses = models.ManyToManyField(House, related_name='occupants')
@property
def primary_house(self):
# Assume business logic forces every person to have at least one house.
return sorted(self.houses.all(), key=lambda house: -house.rooms.count())[0]
@property
def all_houses(self):
return list(self.houses.all())
class Meta:
ordering = ['id']
# Models for nullable FK tests
@python_2_unicode_compatible
class Employee(models.Model):
name = models.CharField(max_length=50)
boss = models.ForeignKey('self', null=True,
related_name='serfs')
def __str__(self):
return self.name
class Meta:
ordering = ['id']
# Ticket #19607
@python_2_unicode_compatible
class LessonEntry(models.Model):
name1 = models.CharField(max_length=200)
name2 = models.CharField(max_length=200)
def __str__(self):
return "%s %s" % (self.name1, self.name2)
@python_2_unicode_compatible
class WordEntry(models.Model):
lesson_entry = models.ForeignKey(LessonEntry)
name = models.CharField(max_length=200)
def __str__(self):
return "%s (%s)" % (self.name, self.id)
# Ticket #21410: Regression when related_name="+"
@python_2_unicode_compatible
class Author2(models.Model):
name = models.CharField(max_length=50, unique=True)
first_book = models.ForeignKey('Book', related_name='first_time_authors+')
favorite_books = models.ManyToManyField('Book', related_name='+')
def __str__(self):
return self.name
class Meta:
ordering = ['id']
|
bsd-3-clause
|
[
504,
1639,
14,
2828,
14,
10778,
14,
955,
492,
334,
272,
8307,
3190,
12,
8307,
12617,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
3,
10082,
2295,
199,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
6529,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
12,
3747,
29,
549,
9,
272,
1642,
63,
2706,
275,
1709,
14,
3190,
360,
8696,
297,
4048,
63,
354,
534,
2246,
63,
521,
63,
8149,
358,
272,
17914,
1175,
63,
8149,
275,
1709,
14,
7624,
8,
267,
283,
277,
297,
4012,
534,
24335,
1175,
2817,
1384,
297,
30091,
29,
797,
12,
4048,
63,
354,
534,
30763,
1384,
63,
278,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
6529,
3007,
20480,
8,
5949,
304,
272,
4132,
275,
1709,
14,
14298,
8,
5949,
12,
1676,
63,
1073,
29,
549,
9,
272,
11437,
275,
1709,
14,
3901,
342,
421,
199,
533,
481,
12958,
1175,
2817,
1384,
8,
992,
14,
1685,
304,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
370,
63,
698,
534,
354,
297,
4048,
63,
354,
534,
73,
63,
2930,
358,
272,
1212,
9246,
63,
2502,
275,
1709,
14,
3190,
8,
5949,
12,
370,
63,
698,
534,
354,
297,
4048,
63,
354,
534,
29572,
63,
278,
358,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
6529,
1476,
8,
992,
14,
1685,
304,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
370,
63,
698,
534,
354,
297,
4048,
63,
354,
534,
7423,
358,
272,
2287,
275,
1709,
14,
6254,
342,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1562,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
8944,
8,
992,
14,
1685,
304,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
9,
272,
11462,
275,
1709,
14,
7624,
8,
5949,
12,
4048,
63,
354,
534,
8858,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1213,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
8944,
3007,
15731,
8,
8696,
304,
272,
6719,
275,
1709,
14,
14298,
8,
8696,
12,
1676,
63,
1073,
29,
549,
9,
272,
3267,
63,
3403,
275,
1709,
14,
3901,
342,
272,
282,
3046,
63,
8149,
275,
1709,
14,
7624,
8,
267,
6529,
3007,
20480,
12,
4048,
63,
354,
534,
8858,
63,
1045,
63,
3403,
358,
421,
199,
533,
699,
2308,
8,
992,
14,
1685,
304,
272,
4132,
275,
1709,
14,
14298,
8,
5949,
9,
272,
19040,
275,
1709,
14,
7624,
8,
8696,
12,
4596,
29,
549,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
23099,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
19040,
63,
739,
275,
1709,
14,
7624,
8,
8696,
12,
4048,
63,
354,
534,
739,
63,
991,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
8944,
21000,
8,
992,
14,
1685,
304,
272,
6719,
275,
1709,
14,
3190,
8,
8696,
3007,
15731,
9,
272,
12681,
275,
1709,
14,
6254,
8,
2307,
29,
549,
12,
4596,
29,
549,
9,
421,
199,
3,
29941,
367,
849,
5256,
2295,
199,
199,
533,
19933,
7313,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
5773,
19728,
2988,
8,
992,
14,
2988,
304,
272,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
8,
6301,
19728,
2988,
12,
291,
680,
362,
63,
7924,
1252,
15576,
63,
2407,
360,
537,
7313,
83,
358,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
5773,
19728,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
6420,
7313,
83,
275,
1709,
14,
7624,
8,
12621,
7313,
9,
339,
2251,
275,
5773,
19728,
2988,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
4366,
83,
2924,
450,
334,
277,
14,
354,
12,
3872,
3680,
904,
8,
81,
14,
354,
367,
1894,
315,
291,
14,
537,
7313,
83,
14,
452,
4059,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
1487,
12493,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
1565,
1225,
1192,
275,
1709,
14,
7624,
8,
6301,
19728,
9,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
3,
8307,
12617,
15,
9417,
3190,
2295,
199,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
32121,
2081,
8,
992,
14,
1685,
304,
272,
1947,
275,
1709,
14,
17315,
342,
272,
1564,
63,
466,
275,
1709,
14,
3190,
8,
11282,
12,
4048,
63,
354,
628,
1450,
303,
328,
563,
63,
409,
18,
531,
272,
909,
63,
344,
275,
1709,
14,
8591,
342,
272,
1564,
63,
785,
275,
8307,
3190,
360,
1317,
63,
466,
297,
283,
785,
63,
344,
358,
272,
2737,
63,
991,
63,
319,
275,
1709,
14,
3190,
8,
11282,
12,
2973,
29,
549,
12,
4228,
4048,
63,
354,
534,
1450,
303,
328,
563,
63,
409,
19,
358,
272,
2737,
63,
991,
63,
70,
498,
275,
1709,
14,
8591,
8,
2307,
29,
549,
9,
272,
2737,
63,
991,
275,
8307,
3190,
360,
3966,
63,
991,
63,
319,
297,
283,
3966,
63,
991,
63,
70,
498,
9538,
272,
17914,
1175,
63,
319,
275,
1709,
14,
3190,
8,
11282,
12,
2973,
29,
549,
12,
2511,
4048,
63,
354,
534,
1450,
303,
328,
563,
63,
409,
20,
358,
272,
17914,
1175,
63,
70,
498,
275,
1709,
14,
2183
] |
[
1639,
14,
2828,
14,
10778,
14,
955,
492,
334,
272,
8307,
3190,
12,
8307,
12617,
12,
199,
9,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
3,
10082,
2295,
199,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
6529,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
12,
3747,
29,
549,
9,
272,
1642,
63,
2706,
275,
1709,
14,
3190,
360,
8696,
297,
4048,
63,
354,
534,
2246,
63,
521,
63,
8149,
358,
272,
17914,
1175,
63,
8149,
275,
1709,
14,
7624,
8,
267,
283,
277,
297,
4012,
534,
24335,
1175,
2817,
1384,
297,
30091,
29,
797,
12,
4048,
63,
354,
534,
30763,
1384,
63,
278,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
6529,
3007,
20480,
8,
5949,
304,
272,
4132,
275,
1709,
14,
14298,
8,
5949,
12,
1676,
63,
1073,
29,
549,
9,
272,
11437,
275,
1709,
14,
3901,
342,
421,
199,
533,
481,
12958,
1175,
2817,
1384,
8,
992,
14,
1685,
304,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
370,
63,
698,
534,
354,
297,
4048,
63,
354,
534,
73,
63,
2930,
358,
272,
1212,
9246,
63,
2502,
275,
1709,
14,
3190,
8,
5949,
12,
370,
63,
698,
534,
354,
297,
4048,
63,
354,
534,
29572,
63,
278,
358,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
6529,
1476,
8,
992,
14,
1685,
304,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
370,
63,
698,
534,
354,
297,
4048,
63,
354,
534,
7423,
358,
272,
2287,
275,
1709,
14,
6254,
342,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1562,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
8944,
8,
992,
14,
1685,
304,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
9,
272,
11462,
275,
1709,
14,
7624,
8,
5949,
12,
4048,
63,
354,
534,
8858,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
1213,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
8944,
3007,
15731,
8,
8696,
304,
272,
6719,
275,
1709,
14,
14298,
8,
8696,
12,
1676,
63,
1073,
29,
549,
9,
272,
3267,
63,
3403,
275,
1709,
14,
3901,
342,
272,
282,
3046,
63,
8149,
275,
1709,
14,
7624,
8,
267,
6529,
3007,
20480,
12,
4048,
63,
354,
534,
8858,
63,
1045,
63,
3403,
358,
421,
199,
533,
699,
2308,
8,
992,
14,
1685,
304,
272,
4132,
275,
1709,
14,
14298,
8,
5949,
9,
272,
19040,
275,
1709,
14,
7624,
8,
8696,
12,
4596,
29,
549,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
23099,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
19040,
63,
739,
275,
1709,
14,
7624,
8,
8696,
12,
4048,
63,
354,
534,
739,
63,
991,
358,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
8944,
21000,
8,
992,
14,
1685,
304,
272,
6719,
275,
1709,
14,
3190,
8,
8696,
3007,
15731,
9,
272,
12681,
275,
1709,
14,
6254,
8,
2307,
29,
549,
12,
4596,
29,
549,
9,
421,
199,
3,
29941,
367,
849,
5256,
2295,
199,
199,
533,
19933,
7313,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
5773,
19728,
2988,
8,
992,
14,
2988,
304,
272,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
8,
6301,
19728,
2988,
12,
291,
680,
362,
63,
7924,
1252,
15576,
63,
2407,
360,
537,
7313,
83,
358,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
5773,
19728,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
6420,
7313,
83,
275,
1709,
14,
7624,
8,
12621,
7313,
9,
339,
2251,
275,
5773,
19728,
2988,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
4366,
83,
2924,
450,
334,
277,
14,
354,
12,
3872,
3680,
904,
8,
81,
14,
354,
367,
1894,
315,
291,
14,
537,
7313,
83,
14,
452,
4059,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
533,
1487,
12493,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
1565,
1225,
1192,
275,
1709,
14,
7624,
8,
6301,
19728,
9,
339,
1021,
6288,
26,
267,
7794,
275,
788,
344,
418,
421,
199,
3,
8307,
12617,
15,
9417,
3190,
2295,
199,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
32121,
2081,
8,
992,
14,
1685,
304,
272,
1947,
275,
1709,
14,
17315,
342,
272,
1564,
63,
466,
275,
1709,
14,
3190,
8,
11282,
12,
4048,
63,
354,
628,
1450,
303,
328,
563,
63,
409,
18,
531,
272,
909,
63,
344,
275,
1709,
14,
8591,
342,
272,
1564,
63,
785,
275,
8307,
3190,
360,
1317,
63,
466,
297,
283,
785,
63,
344,
358,
272,
2737,
63,
991,
63,
319,
275,
1709,
14,
3190,
8,
11282,
12,
2973,
29,
549,
12,
4228,
4048,
63,
354,
534,
1450,
303,
328,
563,
63,
409,
19,
358,
272,
2737,
63,
991,
63,
70,
498,
275,
1709,
14,
8591,
8,
2307,
29,
549,
9,
272,
2737,
63,
991,
275,
8307,
3190,
360,
3966,
63,
991,
63,
319,
297,
283,
3966,
63,
991,
63,
70,
498,
9538,
272,
17914,
1175,
63,
319,
275,
1709,
14,
3190,
8,
11282,
12,
2973,
29,
549,
12,
2511,
4048,
63,
354,
534,
1450,
303,
328,
563,
63,
409,
20,
358,
272,
17914,
1175,
63,
70,
498,
275,
1709,
14,
2183,
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,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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Carralex/landlab
|
landlab/utils/jaggedarray_ma.py
|
6
|
9168
|
"""Store arrays of variable-length arrays implemented with masked arrays.
Implements a JaggedArray class using numpy masked arrays.
Examples
--------
Create a JaggedArray that stores link IDs for the links attached to the
nodes of a 3x3 grid.
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> links_at_node = JaggedArray([
... [0, 6],
... [1, 7, 0],
... [8, 1],
... [2, 9, 6],
... [3, 10, 2, 7],
... [11, 3, 8],
... [4, 7],
... [5, 10, 4],
... [5, 11]])
Make up some data that provides values at each of the links.
>>> value_at_link = np.arange(12, dtype=float)
Create another JaggedArray. Here we store the values at each of the links
attached to nodes of the grid.
>>> values_at_node = JaggedArray.empty_like(links_at_node, dtype=float)
>>> values_at_node.array = value_at_link[links_at_node.array]
Now operate on the link values for each node.
>>> values_at_node.foreach_row(np.sum)
array([ 6., 8., 9., 17., 22., 22., 11., 19., 16.])
>>> values_at_node.foreach_row(np.min)
array([ 0., 0., 1., 2., 2., 3., 4., 4., 5.])
>>> values_at_node.foreach_row(np.ptp)
array([ 6., 7., 7., 7., 8., 8., 3., 6., 6.])
"""
import numpy as np
from six.moves import range
class JaggedArray(object):
"""
A container for an array of variable-length arrays.
JaggedArray([row0, row1, ...])
JaggedArray(values, values_per_row)
Examples
--------
Create a JaggedArray with an array of arrays.
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])
Create a JaggedArray as a 1D array and a list or row lengths.
>>> x = JaggedArray([0, 1, 2, 3, 4], (3, 2))
>>> x.array
array([0, 1, 2, 3, 4])
"""
def __init__(self, *args):
"""
JaggedArray([row0, row1, ...])
JaggedArray(values, values_per_row)
Examples
--------
Create a JaggedArray with an array of arrays.
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])
Create a JaggedArray as a 1D array and a list or row lengths.
>>> x = JaggedArray([0, 1, 2, 3, 4], (3, 2))
>>> x.array
array([0, 1, 2, 3, 4])
"""
if len(args) == 1:
if isinstance(args[0], np.ma.core.MaskedArray):
mat = args[0]
else:
mat = JaggedArray.ma_from_list_of_lists(args[0])
else:
mat = JaggedArray.ma_from_flat_array(args[0], args[1])
self._values = mat
self._number_of_rows = mat.shape[0]
@staticmethod
def ma_from_list_of_lists(rows, dtype=None):
"""Create a masked array from a list of lists.
Parameters
----------
rows : array_like or array_like
Rows of the jagged array.
dtype : np.dtype, optional
The data type of the new masked array.
Returns
-------
np.masked_array
A new masked array.
"""
values_per_row = [len(row) for row in rows]
mat = np.ma.masked_all((len(rows), max(values_per_row)),
dtype=dtype or int)
for (row_number, row) in enumerate(rows):
mat[row_number, :len(row)] = row
return mat
@staticmethod
def ma_from_flat_array(array, values_per_row):
"""Create a masked array from a flat array.
Parameters
----------
array : array_like
Values of the jagged array.
values_per_row : array_like of int
Number of values in each row of the jagged array.
Returns
-------
np.masked_array
A new masked array.
"""
array = np.array(array)
mat = np.ma.masked_all((len(values_per_row), max(values_per_row)),
dtype=array.dtype)
offset = 0
for row_number in range(mat.shape[0]):
n_valid = values_per_row[row_number]
mat[row_number, :n_valid] = array[offset:offset + n_valid]
offset += n_valid
return mat
@property
def array(self):
"""The jagged array as a 1D array.
Returns
-------
array :
A view of the underlying 1D array.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.array
array([0, 1, 2, 3, 4])
>>> x.array = np.array([1, 1, 2, 3, 4])
>>> x.array
array([1, 1, 2, 3, 4])
"""
return self._values.compressed()
@property
def masked_array(self):
"""The jagged array as a masked array.
Returns
-------
np.masked_array :
The underlying masked array.
"""
return self._values
@array.setter
def array(self, array):
"""Set the data of the jagged array from a 1D array.
Parameters
----------
array : array_like
The new values of the array.
"""
self._values[~ self._values.mask] = array
@property
def size(self):
"""Number of array elements.
Returns
-------
int :
Number of values in the array.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.size
5
"""
return self.array.size
@property
def number_of_rows(self):
"""Number of array rows.
Returns
-------
int :
Number of rows in the array.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.number_of_rows == 2
True
"""
return self._number_of_rows
@staticmethod
def _offsets_from_values_per_row(values_per_row):
"""Get offsets into the base array from array lengths.
Parameters
----------
values_per_row : array of int
The number of values in each row of the JaggedArray.
Returns
-------
ndarray
An array of offsets.
"""
offset = np.empty(len(values_per_row) + 1, dtype=int)
np.cumsum(values_per_row, out=offset[1:])
offset[0] = 0
return offset
@staticmethod
def empty_like(jagged, dtype=None):
"""Create a new JaggedArray that is like another one.
Parameters
----------
jagged : JaggedArray
A JaggedArray to copy.
dtype : np.dtype
The data type of the new JaggedArray.
Returns
-------
JaggedArray
A new JaggedArray.
"""
return JaggedArray(np.ma.empty_like(jagged.masked_array, dtype=dtype))
def length_of_row(self, row):
"""Number of values in a given row.
Parameters
----------
row : int
Index to a row.
Returns
-------
int :
Number of values in the row.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.length_of_row(0)
3
>>> x.length_of_row(1)
2
"""
return len(self.row(row))
def row(self, row):
"""Get the values of a row as an array.
Parameters
----------
row : int
Index to a row.
Returns
-------
array :
Values in the row as a slice of the underlying array.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.row(0)
array([0, 1, 2])
>>> x.row(1)
array([3, 4])
"""
return self._values[row].compressed()
def __iter__(self):
"""Iterate over the rows of the array.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> for row in x: row
array([0, 1, 2])
array([3, 4])
"""
for row in self._values:
yield row.compressed()
def foreach_row(self, func, out=None):
"""Apply an operator row-by-row.
Examples
--------
>>> from landlab.utils.jaggedarray_ma import JaggedArray
>>> x = JaggedArray([[0, 1, 2], [3, 4]])
>>> x.foreach_row(np.sum)
array([3, 7])
>>> out = np.empty(2, dtype=int)
>>> x.foreach_row(np.sum, out=out) is out
True
>>> out
array([3, 7])
"""
if out is None:
return func(self._values, axis=1).compressed()
else:
return func(self._values, axis=1, out=out)
|
mit
|
[
624,
5502,
6572,
402,
1750,
13,
1267,
6572,
6366,
543,
9742,
6572,
14,
199,
199,
29452,
282,
1603,
24843,
3836,
1021,
1808,
2680,
9742,
6572,
14,
199,
199,
22787,
199,
518,
199,
199,
2499,
282,
1603,
24843,
3836,
626,
14086,
2142,
11449,
367,
314,
6220,
10102,
370,
314,
199,
2415,
402,
282,
650,
88,
19,
6068,
14,
199,
199,
6071,
687,
20078,
5561,
14,
1208,
14,
74,
24843,
1144,
63,
391,
492,
1603,
24843,
3836,
199,
6071,
6220,
63,
292,
63,
932,
275,
1603,
24843,
3836,
779,
199,
1396,
258,
359,
16,
12,
1227,
467,
199,
1396,
258,
359,
17,
12,
1520,
12,
378,
467,
199,
1396,
258,
359,
24,
12,
413,
467,
199,
1396,
258,
359,
18,
12,
1749,
12,
1227,
467,
199,
1396,
258,
359,
19,
12,
1616,
12,
499,
12,
1520,
467,
199,
1396,
258,
359,
845,
12,
650,
12,
1695,
467,
199,
1396,
258,
359,
20,
12,
1520,
467,
199,
1396,
258,
359,
21,
12,
1616,
12,
841,
467,
199,
1396,
258,
359,
21,
12,
4119,
3934,
199,
199,
5483,
1536,
2005,
666,
626,
6571,
1338,
737,
1924,
402,
314,
6220,
14,
199,
199,
6071,
574,
63,
292,
63,
1073,
275,
980,
14,
5605,
8,
713,
12,
2152,
29,
1609,
9,
199,
199,
2499,
4573,
1603,
24843,
3836,
14,
11842,
781,
3877,
314,
1338,
737,
1924,
402,
314,
6220,
199,
17099,
370,
3380,
402,
314,
6068,
14,
199,
199,
6071,
1338,
63,
292,
63,
932,
275,
1603,
24843,
3836,
14,
1667,
63,
2930,
8,
4614,
63,
292,
63,
932,
12,
2152,
29,
1609,
9,
199,
6071,
1338,
63,
292,
63,
932,
14,
1144,
275,
574,
63,
292,
63,
1073,
59,
4614,
63,
292,
63,
932,
14,
1144,
61,
199,
199,
14351,
19218,
641,
314,
2142,
1338,
367,
1924,
1031,
14,
199,
199,
6071,
1338,
63,
292,
63,
932,
14,
32591,
63,
1143,
8,
1590,
14,
1838,
9,
199,
1144,
779,
221,
1227,
2020,
257,
1695,
2020,
257,
1749,
2020,
221,
5557,
2020,
221,
6928,
2020,
221,
6928,
2020,
221,
4119,
2020,
221,
5851,
2020,
221,
3193,
14444,
199,
6071,
1338,
63,
292,
63,
932,
14,
32591,
63,
1143,
8,
1590,
14,
827,
9,
199,
1144,
779,
378,
2020,
221,
378,
2020,
221,
413,
2020,
221,
499,
2020,
221,
499,
2020,
221,
650,
2020,
221,
841,
2020,
221,
841,
2020,
221,
959,
14444,
199,
6071,
1338,
63,
292,
63,
932,
14,
32591,
63,
1143,
8,
1590,
14,
541,
80,
9,
199,
1144,
779,
1227,
2020,
221,
1520,
2020,
221,
1520,
2020,
221,
1520,
2020,
221,
1695,
2020,
221,
1695,
2020,
221,
650,
2020,
221,
1227,
2020,
221,
1227,
14444,
199,
624,
199,
646,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
1425,
421,
199,
533,
1603,
24843,
3836,
8,
785,
304,
339,
408,
272,
437,
3970,
367,
376,
1625,
402,
1750,
13,
1267,
6572,
14,
339,
1603,
24843,
3836,
779,
1143,
16,
12,
1962,
17,
12,
2263,
566,
272,
1603,
24843,
3836,
8,
1459,
12,
1338,
63,
529,
63,
1143,
9,
339,
6058,
272,
3001,
272,
2790,
282,
1603,
24843,
3836,
543,
376,
1625,
402,
6572,
14,
339,
1306,
687,
20078,
5561,
14,
1208,
14,
74,
24843,
1144,
63,
391,
492,
1603,
24843,
3836,
272,
1306,
671,
275,
1603,
24843,
3836,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
3934,
272,
1306,
671,
14,
1144,
272,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
339,
2790,
282,
1603,
24843,
3836,
465,
282,
413,
36,
1625,
436,
282,
769,
503,
1962,
17464,
14,
339,
1306,
671,
275,
1603,
24843,
3836,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
467,
334,
19,
12,
499,
430,
272,
1306,
671,
14,
1144,
272,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
408,
267,
1603,
24843,
3836,
779,
1143,
16,
12,
1962,
17,
12,
2263,
566,
267,
1603,
24843,
3836,
8,
1459,
12,
1338,
63,
529,
63,
1143,
9,
398,
6058,
267,
3001,
267,
2790,
282,
1603,
24843,
3836,
543,
376,
1625,
402,
6572,
14,
398,
1306,
687,
20078,
5561,
14,
1208,
14,
74,
24843,
1144,
63,
391,
492,
1603,
24843,
3836,
267,
1306,
671,
275,
1603,
24843,
3836,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
3934,
267,
1306,
671,
14,
1144,
267,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
398,
2790,
282,
1603,
24843,
3836,
465,
282,
413,
36,
1625,
436,
282,
769,
503,
1962,
17464,
14,
398,
1306,
671,
275,
1603,
24843,
3836,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
467,
334,
19,
12,
499,
430,
267,
1306,
671,
14,
1144,
267,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
267,
408,
267,
340,
822,
8,
589,
9,
508,
413,
26,
288,
340,
1228,
8,
589,
59,
16,
467,
980,
14,
391,
14,
1018,
14,
5144,
20999,
304,
355,
2530,
275,
1249,
59,
16,
61,
288,
587,
26,
355,
2530,
275,
1603,
24843,
3836,
14,
391,
63,
504,
63,
513,
63,
1618,
63,
6717,
8,
589,
59,
16,
566,
267,
587,
26,
288,
2530,
275,
1603,
24843,
3836,
14,
391,
63,
504,
63,
7088,
63,
1144,
8,
589,
59,
16,
467,
1249,
59,
17,
566,
398,
291,
423,
1459,
275,
2530,
267,
291,
423,
1955,
63,
1618,
63,
3838,
275,
2530,
14,
1392,
59,
16,
61,
339,
768,
4639,
272,
347,
610,
63,
504,
63,
513,
63,
1618,
63,
6717,
8,
3838,
12,
2152,
29,
403,
304,
267,
408,
2499,
282,
9742,
1625,
687,
282,
769,
402,
5548,
14,
398,
3897,
267,
4143,
267,
4730,
520,
1625,
63,
2930,
503,
1625,
63,
2930,
288,
15231,
83,
402,
314,
1335,
24843,
1625,
14,
267,
2152,
520,
980,
14,
2271,
12,
2716,
288,
710,
666,
730,
402,
314,
892,
9742,
1625,
14,
398,
1803,
267,
5514,
267,
980,
14,
11018,
63,
1144,
288,
437,
892,
9742,
1625,
14,
267,
408,
267,
1338,
63,
529,
63,
1143,
275,
359,
552,
8,
1143,
9,
367,
1962,
315,
4730,
61,
267,
2530,
275,
980,
14,
391,
14,
11018,
63,
452,
1332,
552,
8,
3838,
395,
1390
] |
[
5502,
6572,
402,
1750,
13,
1267,
6572,
6366,
543,
9742,
6572,
14,
199,
199,
29452,
282,
1603,
24843,
3836,
1021,
1808,
2680,
9742,
6572,
14,
199,
199,
22787,
199,
518,
199,
199,
2499,
282,
1603,
24843,
3836,
626,
14086,
2142,
11449,
367,
314,
6220,
10102,
370,
314,
199,
2415,
402,
282,
650,
88,
19,
6068,
14,
199,
199,
6071,
687,
20078,
5561,
14,
1208,
14,
74,
24843,
1144,
63,
391,
492,
1603,
24843,
3836,
199,
6071,
6220,
63,
292,
63,
932,
275,
1603,
24843,
3836,
779,
199,
1396,
258,
359,
16,
12,
1227,
467,
199,
1396,
258,
359,
17,
12,
1520,
12,
378,
467,
199,
1396,
258,
359,
24,
12,
413,
467,
199,
1396,
258,
359,
18,
12,
1749,
12,
1227,
467,
199,
1396,
258,
359,
19,
12,
1616,
12,
499,
12,
1520,
467,
199,
1396,
258,
359,
845,
12,
650,
12,
1695,
467,
199,
1396,
258,
359,
20,
12,
1520,
467,
199,
1396,
258,
359,
21,
12,
1616,
12,
841,
467,
199,
1396,
258,
359,
21,
12,
4119,
3934,
199,
199,
5483,
1536,
2005,
666,
626,
6571,
1338,
737,
1924,
402,
314,
6220,
14,
199,
199,
6071,
574,
63,
292,
63,
1073,
275,
980,
14,
5605,
8,
713,
12,
2152,
29,
1609,
9,
199,
199,
2499,
4573,
1603,
24843,
3836,
14,
11842,
781,
3877,
314,
1338,
737,
1924,
402,
314,
6220,
199,
17099,
370,
3380,
402,
314,
6068,
14,
199,
199,
6071,
1338,
63,
292,
63,
932,
275,
1603,
24843,
3836,
14,
1667,
63,
2930,
8,
4614,
63,
292,
63,
932,
12,
2152,
29,
1609,
9,
199,
6071,
1338,
63,
292,
63,
932,
14,
1144,
275,
574,
63,
292,
63,
1073,
59,
4614,
63,
292,
63,
932,
14,
1144,
61,
199,
199,
14351,
19218,
641,
314,
2142,
1338,
367,
1924,
1031,
14,
199,
199,
6071,
1338,
63,
292,
63,
932,
14,
32591,
63,
1143,
8,
1590,
14,
1838,
9,
199,
1144,
779,
221,
1227,
2020,
257,
1695,
2020,
257,
1749,
2020,
221,
5557,
2020,
221,
6928,
2020,
221,
6928,
2020,
221,
4119,
2020,
221,
5851,
2020,
221,
3193,
14444,
199,
6071,
1338,
63,
292,
63,
932,
14,
32591,
63,
1143,
8,
1590,
14,
827,
9,
199,
1144,
779,
378,
2020,
221,
378,
2020,
221,
413,
2020,
221,
499,
2020,
221,
499,
2020,
221,
650,
2020,
221,
841,
2020,
221,
841,
2020,
221,
959,
14444,
199,
6071,
1338,
63,
292,
63,
932,
14,
32591,
63,
1143,
8,
1590,
14,
541,
80,
9,
199,
1144,
779,
1227,
2020,
221,
1520,
2020,
221,
1520,
2020,
221,
1520,
2020,
221,
1695,
2020,
221,
1695,
2020,
221,
650,
2020,
221,
1227,
2020,
221,
1227,
14444,
199,
624,
199,
646,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
1425,
421,
199,
533,
1603,
24843,
3836,
8,
785,
304,
339,
408,
272,
437,
3970,
367,
376,
1625,
402,
1750,
13,
1267,
6572,
14,
339,
1603,
24843,
3836,
779,
1143,
16,
12,
1962,
17,
12,
2263,
566,
272,
1603,
24843,
3836,
8,
1459,
12,
1338,
63,
529,
63,
1143,
9,
339,
6058,
272,
3001,
272,
2790,
282,
1603,
24843,
3836,
543,
376,
1625,
402,
6572,
14,
339,
1306,
687,
20078,
5561,
14,
1208,
14,
74,
24843,
1144,
63,
391,
492,
1603,
24843,
3836,
272,
1306,
671,
275,
1603,
24843,
3836,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
3934,
272,
1306,
671,
14,
1144,
272,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
339,
2790,
282,
1603,
24843,
3836,
465,
282,
413,
36,
1625,
436,
282,
769,
503,
1962,
17464,
14,
339,
1306,
671,
275,
1603,
24843,
3836,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
467,
334,
19,
12,
499,
430,
272,
1306,
671,
14,
1144,
272,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
408,
267,
1603,
24843,
3836,
779,
1143,
16,
12,
1962,
17,
12,
2263,
566,
267,
1603,
24843,
3836,
8,
1459,
12,
1338,
63,
529,
63,
1143,
9,
398,
6058,
267,
3001,
267,
2790,
282,
1603,
24843,
3836,
543,
376,
1625,
402,
6572,
14,
398,
1306,
687,
20078,
5561,
14,
1208,
14,
74,
24843,
1144,
63,
391,
492,
1603,
24843,
3836,
267,
1306,
671,
275,
1603,
24843,
3836,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
3934,
267,
1306,
671,
14,
1144,
267,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
398,
2790,
282,
1603,
24843,
3836,
465,
282,
413,
36,
1625,
436,
282,
769,
503,
1962,
17464,
14,
398,
1306,
671,
275,
1603,
24843,
3836,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
467,
334,
19,
12,
499,
430,
267,
1306,
671,
14,
1144,
267,
1625,
779,
16,
12,
413,
12,
499,
12,
650,
12,
841,
566,
267,
408,
267,
340,
822,
8,
589,
9,
508,
413,
26,
288,
340,
1228,
8,
589,
59,
16,
467,
980,
14,
391,
14,
1018,
14,
5144,
20999,
304,
355,
2530,
275,
1249,
59,
16,
61,
288,
587,
26,
355,
2530,
275,
1603,
24843,
3836,
14,
391,
63,
504,
63,
513,
63,
1618,
63,
6717,
8,
589,
59,
16,
566,
267,
587,
26,
288,
2530,
275,
1603,
24843,
3836,
14,
391,
63,
504,
63,
7088,
63,
1144,
8,
589,
59,
16,
467,
1249,
59,
17,
566,
398,
291,
423,
1459,
275,
2530,
267,
291,
423,
1955,
63,
1618,
63,
3838,
275,
2530,
14,
1392,
59,
16,
61,
339,
768,
4639,
272,
347,
610,
63,
504,
63,
513,
63,
1618,
63,
6717,
8,
3838,
12,
2152,
29,
403,
304,
267,
408,
2499,
282,
9742,
1625,
687,
282,
769,
402,
5548,
14,
398,
3897,
267,
4143,
267,
4730,
520,
1625,
63,
2930,
503,
1625,
63,
2930,
288,
15231,
83,
402,
314,
1335,
24843,
1625,
14,
267,
2152,
520,
980,
14,
2271,
12,
2716,
288,
710,
666,
730,
402,
314,
892,
9742,
1625,
14,
398,
1803,
267,
5514,
267,
980,
14,
11018,
63,
1144,
288,
437,
892,
9742,
1625,
14,
267,
408,
267,
1338,
63,
529,
63,
1143,
275,
359,
552,
8,
1143,
9,
367,
1962,
315,
4730,
61,
267,
2530,
275,
980,
14,
391,
14,
11018,
63,
452,
1332,
552,
8,
3838,
395,
1390,
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,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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
] |
slozier/ironpython2
|
Src/StdLib/Lib/test/test_dbm.py
|
136
|
1266
|
from test import test_support
import unittest
dbm = test_support.import_module('dbm')
class DbmTestCase(unittest.TestCase):
def setUp(self):
self.filename = test_support.TESTFN
self.d = dbm.open(self.filename, 'c')
self.d.close()
def tearDown(self):
for suffix in ['', '.pag', '.dir', '.db']:
test_support.unlink(self.filename + suffix)
def test_keys(self):
self.d = dbm.open(self.filename, 'c')
self.assertEqual(self.d.keys(), [])
a = [('a', 'b'), ('12345678910', '019237410982340912840198242')]
for k, v in a:
self.d[k] = v
self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a))
for k, v in a:
self.assertIn(k, self.d)
self.assertEqual(self.d[k], v)
self.assertNotIn('xxx', self.d)
self.assertRaises(KeyError, lambda: self.d['xxx'])
self.d.close()
def test_modes(self):
for mode in ['r', 'rw', 'w', 'n']:
try:
self.d = dbm.open(self.filename, mode)
self.d.close()
except dbm.error:
self.fail()
def test_main():
test_support.run_unittest(DbmTestCase)
if __name__ == '__main__':
test_main()
|
apache-2.0
|
[
504,
511,
492,
511,
63,
4058,
199,
646,
2882,
199,
20666,
275,
511,
63,
4058,
14,
646,
63,
578,
360,
20666,
358,
199,
199,
533,
577,
12648,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1501,
275,
511,
63,
4058,
14,
10179,
267,
291,
14,
68,
275,
31093,
14,
1490,
8,
277,
14,
1501,
12,
283,
67,
358,
267,
291,
14,
68,
14,
1600,
342,
339,
347,
6766,
8,
277,
304,
267,
367,
4739,
315,
18179,
1987,
15351,
297,
1987,
694,
297,
1987,
697,
2565,
288,
511,
63,
4058,
14,
7162,
8,
277,
14,
1501,
435,
4739,
9,
339,
347,
511,
63,
1612,
8,
277,
304,
267,
291,
14,
68,
275,
31093,
14,
1490,
8,
277,
14,
1501,
12,
283,
67,
358,
267,
291,
14,
629,
8,
277,
14,
68,
14,
1612,
1062,
3073,
267,
282,
275,
4274,
65,
297,
283,
66,
659,
661,
11272,
709,
297,
283,
12512,
1789,
1342,
6996,
2564,
1082,
1643,
713,
1349,
614,
2905,
13212,
5440,
267,
367,
1022,
12,
373,
315,
282,
26,
288,
291,
14,
68,
59,
75,
61,
275,
373,
267,
291,
14,
629,
8,
5917,
8,
277,
14,
68,
14,
1612,
4000,
3355,
8,
75,
367,
334,
75,
12,
373,
9,
315,
282,
430,
267,
367,
1022,
12,
373,
315,
282,
26,
288,
291,
14,
4080,
8,
75,
12,
291,
14,
68,
9,
288,
291,
14,
629,
8,
277,
14,
68,
59,
75,
467,
373,
9,
267,
291,
14,
8795,
360,
10013,
297,
291,
14,
68,
9,
267,
291,
14,
1855,
8,
10230,
12,
2400,
26,
291,
14,
68,
459,
10013,
1105,
267,
291,
14,
68,
14,
1600,
342,
339,
347,
511,
63,
10433,
8,
277,
304,
267,
367,
818,
315,
788,
82,
297,
283,
13057,
297,
283,
87,
297,
283,
78,
2565,
288,
862,
26,
355,
291,
14,
68,
275,
31093,
14,
1490,
8,
277,
14,
1501,
12,
818,
9,
355,
291,
14,
68,
14,
1600,
342,
288,
871,
31093,
14,
705,
26,
355,
291,
14,
1633,
342,
199,
199,
318,
511,
63,
973,
837,
272,
511,
63,
4058,
14,
1065,
63,
2796,
8,
8882,
77,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
511,
63,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
511,
492,
511,
63,
4058,
199,
646,
2882,
199,
20666,
275,
511,
63,
4058,
14,
646,
63,
578,
360,
20666,
358,
199,
199,
533,
577,
12648,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1501,
275,
511,
63,
4058,
14,
10179,
267,
291,
14,
68,
275,
31093,
14,
1490,
8,
277,
14,
1501,
12,
283,
67,
358,
267,
291,
14,
68,
14,
1600,
342,
339,
347,
6766,
8,
277,
304,
267,
367,
4739,
315,
18179,
1987,
15351,
297,
1987,
694,
297,
1987,
697,
2565,
288,
511,
63,
4058,
14,
7162,
8,
277,
14,
1501,
435,
4739,
9,
339,
347,
511,
63,
1612,
8,
277,
304,
267,
291,
14,
68,
275,
31093,
14,
1490,
8,
277,
14,
1501,
12,
283,
67,
358,
267,
291,
14,
629,
8,
277,
14,
68,
14,
1612,
1062,
3073,
267,
282,
275,
4274,
65,
297,
283,
66,
659,
661,
11272,
709,
297,
283,
12512,
1789,
1342,
6996,
2564,
1082,
1643,
713,
1349,
614,
2905,
13212,
5440,
267,
367,
1022,
12,
373,
315,
282,
26,
288,
291,
14,
68,
59,
75,
61,
275,
373,
267,
291,
14,
629,
8,
5917,
8,
277,
14,
68,
14,
1612,
4000,
3355,
8,
75,
367,
334,
75,
12,
373,
9,
315,
282,
430,
267,
367,
1022,
12,
373,
315,
282,
26,
288,
291,
14,
4080,
8,
75,
12,
291,
14,
68,
9,
288,
291,
14,
629,
8,
277,
14,
68,
59,
75,
467,
373,
9,
267,
291,
14,
8795,
360,
10013,
297,
291,
14,
68,
9,
267,
291,
14,
1855,
8,
10230,
12,
2400,
26,
291,
14,
68,
459,
10013,
1105,
267,
291,
14,
68,
14,
1600,
342,
339,
347,
511,
63,
10433,
8,
277,
304,
267,
367,
818,
315,
788,
82,
297,
283,
13057,
297,
283,
87,
297,
283,
78,
2565,
288,
862,
26,
355,
291,
14,
68,
275,
31093,
14,
1490,
8,
277,
14,
1501,
12,
818,
9,
355,
291,
14,
68,
14,
1600,
342,
288,
871,
31093,
14,
705,
26,
355,
291,
14,
1633,
342,
199,
199,
318,
511,
63,
973,
837,
272,
511,
63,
4058,
14,
1065,
63,
2796,
8,
8882,
77,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
511,
63,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
zifeo/nest-simulator
|
topology/pynest/tests/test_plotting.py
|
13
|
4111
|
# -*- coding: utf-8 -*-
#
# test_plotting.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST 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.
#
# NEST 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 NEST. If not, see <http://www.gnu.org/licenses/>.
"""
Tests for basic topology hl_api functions.
NOTE: These tests only test whether the code runs, it does not check
whether the results produced are correct.
"""
import unittest
import nest
import nest.topology as topo
try:
import matplotlib.pyplot as plt
plt.figure() # make sure we can open a window; on Jenkins, DISPLAY is not set
PLOTTING_POSSIBLE = True
except:
PLOTTING_POSSIBLE = False
@unittest.skipIf(not PLOTTING_POSSIBLE, 'Plotting is impossible because matplotlib or display missing')
class PlottingTestCase(unittest.TestCase):
def test_PlotLayer(self):
"""Test plotting layer."""
ldict = {'elements': 'iaf_neuron', 'rows': 3, 'columns':3,
'extent': [2., 2.], 'edge_wrap': True}
nest.ResetKernel()
l = topo.CreateLayer(ldict)
topo.PlotLayer(l)
self.assertTrue(True)
def test_PlotTargets(self):
"""Test plotting targets."""
ldict = {'elements': ['iaf_neuron', 'iaf_psc_alpha'], 'rows': 3, 'columns':3,
'extent': [2., 2.], 'edge_wrap': True}
cdict = {'connection_type': 'divergent',
'mask': {'grid': {'rows':2, 'columns':2}}}
nest.ResetKernel()
l = topo.CreateLayer(ldict)
ian = [gid for gid in nest.GetLeaves(l)[0]
if nest.GetStatus([gid], 'model')[0] == 'iaf_neuron']
ipa = [gid for gid in nest.GetLeaves(l)[0]
if nest.GetStatus([gid], 'model')[0] == 'iaf_psc_alpha']
# connect ian -> all using static_synapse
cdict.update({'sources': {'model': 'iaf_neuron'},
'synapse_model': 'static_synapse'})
topo.ConnectLayers(l, l, cdict)
for k in ['sources', 'synapse_model']: cdict.pop(k)
# connect ipa -> ipa using stdp_synapse
cdict.update({'sources': {'model': 'iaf_psc_alpha'},
'targets': {'model': 'iaf_psc_alpha'},
'synapse_model': 'stdp_synapse'})
topo.ConnectLayers(l, l, cdict)
for k in ['sources', 'targets', 'synapse_model']: cdict.pop(k)
ctr = topo.FindCenterElement(l)
fig = topo.PlotTargets(ctr, l)
fig.gca().set_title('Plain call')
self.assertTrue(True)
def test_PlotKernel(self):
"""Test plotting kernels."""
ldict = {'elements': 'iaf_neuron', 'rows': 3, 'columns':3,
'extent': [2., 2.], 'edge_wrap': True}
nest.ResetKernel()
l = topo.CreateLayer(ldict)
f = plt.figure()
a1 = f.add_subplot(221)
ctr = topo.FindCenterElement(l)
topo.PlotKernel(a1, ctr, {'circular': {'radius': 1.}}, {'gaussian': {'sigma':0.2}})
a2 = f.add_subplot(222)
topo.PlotKernel(a2, ctr, {'doughnut': {'inner_radius': 0.5, 'outer_radius':0.75}})
a3 = f.add_subplot(223)
topo.PlotKernel(a3, ctr, {'rectangular': {'lower_left': [-.5,-.5],
'upper_right':[0.5,0.5]}})
self.assertTrue(True)
def suite():
suite = unittest.makeSuite(PlottingTestCase,'test')
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite())
import matplotlib.pyplot as plt
plt.show()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
511,
63,
2798,
1337,
14,
647,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28878,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
710,
28878,
21412,
1905,
199,
3,
199,
3,
28878,
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,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28878,
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,
28878,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
2925,
367,
5678,
14611,
27768,
63,
1246,
3423,
14,
199,
199,
19855,
26,
5723,
2295,
1454,
511,
3775,
314,
1233,
7858,
12,
652,
1630,
440,
1104,
489,
3775,
314,
2058,
13584,
787,
3211,
14,
199,
624,
199,
199,
646,
2882,
199,
646,
10715,
199,
646,
10715,
14,
10775,
465,
11111,
421,
199,
893,
26,
272,
492,
8027,
14,
13563,
465,
4488,
272,
4488,
14,
8941,
342,
221,
327,
1852,
3238,
781,
883,
1551,
282,
4353,
27,
641,
32516,
12,
7587,
11625,
365,
440,
663,
272,
10092,
1387,
52,
1206,
63,
1512,
2300,
7187,
275,
715,
199,
2590,
26,
272,
10092,
1387,
52,
1206,
63,
1512,
2300,
7187,
275,
756,
421,
199,
32,
2796,
14,
15118,
8,
1397,
10092,
1387,
52,
1206,
63,
1512,
2300,
7187,
12,
283,
10711,
1337,
365,
26847,
2952,
8027,
503,
2929,
4124,
358,
199,
533,
14794,
1337,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
10711,
5003,
8,
277,
304,
267,
408,
774,
25174,
4045,
1041,
267,
634,
807,
275,
791,
5527,
356,
283,
73,
2756,
63,
32054,
297,
283,
3838,
356,
650,
12,
283,
3406,
356,
19,
12,
326,
283,
11599,
356,
359,
18,
2020,
499,
8333,
283,
5173,
63,
3823,
356,
715,
93,
267,
10715,
14,
9637,
14127,
342,
267,
634,
275,
11111,
14,
2499,
5003,
8,
76,
807,
9,
267,
11111,
14,
10711,
5003,
8,
76,
9,
21695,
291,
14,
1815,
8,
549,
9,
339,
347,
511,
63,
10711,
14126,
8,
277,
304,
267,
408,
774,
25174,
4545,
1041,
267,
634,
807,
275,
791,
5527,
356,
788,
73,
2756,
63,
32054,
297,
283,
73,
2756,
63,
80,
551,
63,
4468,
995,
283,
3838,
356,
650,
12,
283,
3406,
356,
19,
12,
326,
283,
11599,
356,
359,
18,
2020,
499,
8333,
283,
5173,
63,
3823,
356,
715,
93,
267,
286,
807,
275,
791,
2105,
63,
466,
356,
283,
328,
422,
12069,
297,
20169,
283,
2629,
356,
791,
3825,
356,
791,
3838,
356,
18,
12,
283,
3406,
356,
18,
4863,
93,
420,
267,
10715,
14,
9637,
14127,
342,
267,
634,
275,
11111,
14,
2499,
5003,
8,
76,
807,
9,
267,
284,
290,
275,
359,
8787,
367,
15122,
315,
10715,
14,
1002,
2553,
7047,
8,
76,
2788,
16,
61,
2049,
340,
10715,
14,
1002,
3694,
779,
8787,
467,
283,
1238,
5832,
16,
61,
508,
283,
73,
2756,
63,
32054,
418,
267,
18210,
275,
359,
8787,
367,
15122,
315,
10715,
14,
1002,
2553,
7047,
8,
76,
2788,
16,
61,
2049,
340,
10715,
14,
1002,
3694,
779,
8787,
467,
283,
1238,
5832,
16,
61,
508,
283,
73,
2756,
63,
80,
551,
63,
4468,
418,
2728,
327,
4907,
284,
290,
1035,
1006,
1808,
2955,
63,
9466,
19111,
267,
286,
807,
14,
873,
3252,
4553,
356,
791,
1238,
356,
283,
73,
2756,
63,
32054,
2267,
1993,
283,
9466,
19111,
63,
1238,
356,
283,
1986,
63,
9466,
19111,
3071,
267,
11111,
14,
8631,
16862,
8,
76,
12,
634,
12,
286,
807,
9,
267,
367,
1022,
315,
788,
4553,
297,
283,
9466,
19111,
63,
1238,
2565,
286,
807,
14,
1935,
8,
75,
9,
2728,
327,
4907,
18210,
1035,
18210,
1808,
2418,
80,
63,
9466,
19111,
267,
286,
807,
14,
873,
3252,
4553,
356,
791,
1238,
356,
283,
73,
2756,
63,
80,
551,
63,
4468,
2267,
1993,
283,
4684,
356,
791,
1238,
356,
283,
73,
2756,
63,
80,
551,
63,
4468,
2267,
1993,
283,
9466,
19111,
63,
1238,
356,
283,
1516,
80,
63,
9466,
19111,
3071,
267,
11111,
14,
8631,
16862,
8,
76,
12,
634,
12,
286,
807,
9,
267,
367,
1022,
315,
788,
4553,
297,
283,
4684,
297,
283,
9466,
19111,
63,
1238,
2565,
286,
807,
14,
1935,
8,
75,
9,
523,
267,
286,
454,
275,
11111,
14,
6591,
13551,
2162,
8,
76,
9,
267,
6085,
275,
11111,
14,
10711,
14126,
8,
18548,
12,
634,
9,
267,
6085,
14,
71,
696,
1252,
409,
63,
1213,
360,
20711,
1240,
358,
2728,
291,
14,
1815,
8,
549,
9,
5493,
347,
511,
63,
10711,
14127,
8,
277,
304,
267,
408,
774,
25174,
26091,
1041,
267,
634,
807,
275,
791,
5527,
356,
283,
73,
2756,
63,
32054,
297,
283,
3838,
356,
650,
12,
283,
3406,
356,
19,
12,
326,
283,
11599,
356,
359,
18,
2020,
499,
8333,
283,
5173,
63,
3823,
356,
715,
93,
267,
10715,
14,
9637,
14127,
342,
267,
634,
275,
11111,
14,
2499,
5003,
8,
76,
807,
9,
267,
289,
275,
4488,
14,
8941,
342,
267,
282,
17,
275,
289,
14,
525,
63,
13334,
8,
11564,
9,
267,
286,
454,
275,
11111,
14,
6591,
13551,
2162,
8,
76,
9,
267,
11111,
14,
10711,
14127,
8,
65,
17,
12,
286,
454,
12,
791,
23022,
356,
791,
8017,
356,
413,
14,
13459,
791,
22911,
356,
791,
9412,
356,
16,
14,
18,
19575,
2728,
282,
18,
275,
289,
14,
525,
63,
13334,
8,
9485,
9,
267,
11111,
14,
10711,
14127,
8,
65,
18,
12,
286,
454,
12,
791,
68,
4937,
78,
337,
356,
791,
5216,
63,
8017,
356,
378,
14,
21,
12,
283,
7837,
63,
8017,
356,
16,
14,
2194,
19575,
2728,
282,
19
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
511,
63,
2798,
1337,
14,
647,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28878,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
710,
28878,
21412,
1905,
199,
3,
199,
3,
28878,
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,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28878,
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,
28878,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
2925,
367,
5678,
14611,
27768,
63,
1246,
3423,
14,
199,
199,
19855,
26,
5723,
2295,
1454,
511,
3775,
314,
1233,
7858,
12,
652,
1630,
440,
1104,
489,
3775,
314,
2058,
13584,
787,
3211,
14,
199,
624,
199,
199,
646,
2882,
199,
646,
10715,
199,
646,
10715,
14,
10775,
465,
11111,
421,
199,
893,
26,
272,
492,
8027,
14,
13563,
465,
4488,
272,
4488,
14,
8941,
342,
221,
327,
1852,
3238,
781,
883,
1551,
282,
4353,
27,
641,
32516,
12,
7587,
11625,
365,
440,
663,
272,
10092,
1387,
52,
1206,
63,
1512,
2300,
7187,
275,
715,
199,
2590,
26,
272,
10092,
1387,
52,
1206,
63,
1512,
2300,
7187,
275,
756,
421,
199,
32,
2796,
14,
15118,
8,
1397,
10092,
1387,
52,
1206,
63,
1512,
2300,
7187,
12,
283,
10711,
1337,
365,
26847,
2952,
8027,
503,
2929,
4124,
358,
199,
533,
14794,
1337,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
10711,
5003,
8,
277,
304,
267,
408,
774,
25174,
4045,
1041,
267,
634,
807,
275,
791,
5527,
356,
283,
73,
2756,
63,
32054,
297,
283,
3838,
356,
650,
12,
283,
3406,
356,
19,
12,
326,
283,
11599,
356,
359,
18,
2020,
499,
8333,
283,
5173,
63,
3823,
356,
715,
93,
267,
10715,
14,
9637,
14127,
342,
267,
634,
275,
11111,
14,
2499,
5003,
8,
76,
807,
9,
267,
11111,
14,
10711,
5003,
8,
76,
9,
21695,
291,
14,
1815,
8,
549,
9,
339,
347,
511,
63,
10711,
14126,
8,
277,
304,
267,
408,
774,
25174,
4545,
1041,
267,
634,
807,
275,
791,
5527,
356,
788,
73,
2756,
63,
32054,
297,
283,
73,
2756,
63,
80,
551,
63,
4468,
995,
283,
3838,
356,
650,
12,
283,
3406,
356,
19,
12,
326,
283,
11599,
356,
359,
18,
2020,
499,
8333,
283,
5173,
63,
3823,
356,
715,
93,
267,
286,
807,
275,
791,
2105,
63,
466,
356,
283,
328,
422,
12069,
297,
20169,
283,
2629,
356,
791,
3825,
356,
791,
3838,
356,
18,
12,
283,
3406,
356,
18,
4863,
93,
420,
267,
10715,
14,
9637,
14127,
342,
267,
634,
275,
11111,
14,
2499,
5003,
8,
76,
807,
9,
267,
284,
290,
275,
359,
8787,
367,
15122,
315,
10715,
14,
1002,
2553,
7047,
8,
76,
2788,
16,
61,
2049,
340,
10715,
14,
1002,
3694,
779,
8787,
467,
283,
1238,
5832,
16,
61,
508,
283,
73,
2756,
63,
32054,
418,
267,
18210,
275,
359,
8787,
367,
15122,
315,
10715,
14,
1002,
2553,
7047,
8,
76,
2788,
16,
61,
2049,
340,
10715,
14,
1002,
3694,
779,
8787,
467,
283,
1238,
5832,
16,
61,
508,
283,
73,
2756,
63,
80,
551,
63,
4468,
418,
2728,
327,
4907,
284,
290,
1035,
1006,
1808,
2955,
63,
9466,
19111,
267,
286,
807,
14,
873,
3252,
4553,
356,
791,
1238,
356,
283,
73,
2756,
63,
32054,
2267,
1993,
283,
9466,
19111,
63,
1238,
356,
283,
1986,
63,
9466,
19111,
3071,
267,
11111,
14,
8631,
16862,
8,
76,
12,
634,
12,
286,
807,
9,
267,
367,
1022,
315,
788,
4553,
297,
283,
9466,
19111,
63,
1238,
2565,
286,
807,
14,
1935,
8,
75,
9,
2728,
327,
4907,
18210,
1035,
18210,
1808,
2418,
80,
63,
9466,
19111,
267,
286,
807,
14,
873,
3252,
4553,
356,
791,
1238,
356,
283,
73,
2756,
63,
80,
551,
63,
4468,
2267,
1993,
283,
4684,
356,
791,
1238,
356,
283,
73,
2756,
63,
80,
551,
63,
4468,
2267,
1993,
283,
9466,
19111,
63,
1238,
356,
283,
1516,
80,
63,
9466,
19111,
3071,
267,
11111,
14,
8631,
16862,
8,
76,
12,
634,
12,
286,
807,
9,
267,
367,
1022,
315,
788,
4553,
297,
283,
4684,
297,
283,
9466,
19111,
63,
1238,
2565,
286,
807,
14,
1935,
8,
75,
9,
523,
267,
286,
454,
275,
11111,
14,
6591,
13551,
2162,
8,
76,
9,
267,
6085,
275,
11111,
14,
10711,
14126,
8,
18548,
12,
634,
9,
267,
6085,
14,
71,
696,
1252,
409,
63,
1213,
360,
20711,
1240,
358,
2728,
291,
14,
1815,
8,
549,
9,
5493,
347,
511,
63,
10711,
14127,
8,
277,
304,
267,
408,
774,
25174,
26091,
1041,
267,
634,
807,
275,
791,
5527,
356,
283,
73,
2756,
63,
32054,
297,
283,
3838,
356,
650,
12,
283,
3406,
356,
19,
12,
326,
283,
11599,
356,
359,
18,
2020,
499,
8333,
283,
5173,
63,
3823,
356,
715,
93,
267,
10715,
14,
9637,
14127,
342,
267,
634,
275,
11111,
14,
2499,
5003,
8,
76,
807,
9,
267,
289,
275,
4488,
14,
8941,
342,
267,
282,
17,
275,
289,
14,
525,
63,
13334,
8,
11564,
9,
267,
286,
454,
275,
11111,
14,
6591,
13551,
2162,
8,
76,
9,
267,
11111,
14,
10711,
14127,
8,
65,
17,
12,
286,
454,
12,
791,
23022,
356,
791,
8017,
356,
413,
14,
13459,
791,
22911,
356,
791,
9412,
356,
16,
14,
18,
19575,
2728,
282,
18,
275,
289,
14,
525,
63,
13334,
8,
9485,
9,
267,
11111,
14,
10711,
14127,
8,
65,
18,
12,
286,
454,
12,
791,
68,
4937,
78,
337,
356,
791,
5216,
63,
8017,
356,
378,
14,
21,
12,
283,
7837,
63,
8017,
356,
16,
14,
2194,
19575,
2728,
282,
19,
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,
1
] |
Belxjander/Kirito
|
Python-3.5.0-main/Lib/_strptime.py
|
9
|
21698
|
"""Strptime-related classes and functions.
CLASSES:
LocaleTime -- Discovers and stores locale-specific time information
TimeRE -- Creates regexes for pattern matching a string of text containing
time information
FUNCTIONS:
_getlang -- Figure out what language is being used for the locale
strptime -- Calculates the time struct represented by the passed-in string
"""
import time
import locale
import calendar
from re import compile as re_compile
from re import IGNORECASE
from re import escape as re_escape
from datetime import (date as datetime_date,
timedelta as datetime_timedelta,
timezone as datetime_timezone)
try:
from _thread import allocate_lock as _thread_allocate_lock
except ImportError:
from _dummy_thread import allocate_lock as _thread_allocate_lock
__all__ = []
def _getlang():
# Figure out what the current language is set to.
return locale.getlocale(locale.LC_TIME)
class LocaleTime(object):
"""Stores and handles locale-specific information related to time.
ATTRIBUTES:
f_weekday -- full weekday names (7-item list)
a_weekday -- abbreviated weekday names (7-item list)
f_month -- full month names (13-item list; dummy value in [0], which
is added by code)
a_month -- abbreviated month names (13-item list, dummy value in
[0], which is added by code)
am_pm -- AM/PM representation (2-item list)
LC_date_time -- format string for date/time representation (string)
LC_date -- format string for date representation (string)
LC_time -- format string for time representation (string)
timezone -- daylight- and non-daylight-savings timezone representation
(2-item list of sets)
lang -- Language used by instance (2-item tuple)
"""
def __init__(self):
"""Set all attributes.
Order of methods called matters for dependency reasons.
The locale language is set at the offset and then checked again before
exiting. This is to make sure that the attributes were not set with a
mix of information from more than one locale. This would most likely
happen when using threads where one thread calls a locale-dependent
function while another thread changes the locale while the function in
the other thread is still running. Proper coding would call for
locks to prevent changing the locale while locale-dependent code is
running. The check here is done in case someone does not think about
doing this.
Only other possible issue is if someone changed the timezone and did
not call tz.tzset . That is an issue for the programmer, though,
since changing the timezone is worthless without that call.
"""
self.lang = _getlang()
self.__calc_weekday()
self.__calc_month()
self.__calc_am_pm()
self.__calc_timezone()
self.__calc_date_time()
if _getlang() != self.lang:
raise ValueError("locale changed during initialization")
def __pad(self, seq, front):
# Add '' to seq to either the front (is True), else the back.
seq = list(seq)
if front:
seq.insert(0, '')
else:
seq.append('')
return seq
def __calc_weekday(self):
# Set self.a_weekday and self.f_weekday using the calendar
# module.
a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
f_weekday = [calendar.day_name[i].lower() for i in range(7)]
self.a_weekday = a_weekday
self.f_weekday = f_weekday
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def __calc_am_pm(self):
# Set self.am_pm by using time.strftime().
# The magic date (1999,3,17,hour,44,55,2,76,0) is not really that
# magical; just happened to have used it everywhere else where a
# static date was needed.
am_pm = []
for hour in (1, 22):
time_tuple = time.struct_time((1999,3,17,hour,44,55,2,76,0))
am_pm.append(time.strftime("%p", time_tuple).lower())
self.am_pm = am_pm
def __calc_date_time(self):
# Set self.date_time, self.date, & self.time by using
# time.strftime().
# Use (1999,3,17,22,44,55,2,76,0) for magic date because the amount of
# overloaded numbers is minimized. The order in which searches for
# values within the format string is very important; it eliminates
# possible ambiguity for what something represents.
time_tuple = time.struct_time((1999,3,17,22,44,55,2,76,0))
date_time = [None, None, None]
date_time[0] = time.strftime("%c", time_tuple).lower()
date_time[1] = time.strftime("%x", time_tuple).lower()
date_time[2] = time.strftime("%X", time_tuple).lower()
replacement_pairs = [('%', '%%'), (self.f_weekday[2], '%A'),
(self.f_month[3], '%B'), (self.a_weekday[2], '%a'),
(self.a_month[3], '%b'), (self.am_pm[1], '%p'),
('1999', '%Y'), ('99', '%y'), ('22', '%H'),
('44', '%M'), ('55', '%S'), ('76', '%j'),
('17', '%d'), ('03', '%m'), ('3', '%m'),
# '3' needed for when no leading zero.
('2', '%w'), ('10', '%I')]
replacement_pairs.extend([(tz, "%Z") for tz_values in self.timezone
for tz in tz_values])
for offset,directive in ((0,'%c'), (1,'%x'), (2,'%X')):
current_format = date_time[offset]
for old, new in replacement_pairs:
# Must deal with possible lack of locale info
# manifesting itself as the empty string (e.g., Swedish's
# lack of AM/PM info) or a platform returning a tuple of empty
# strings (e.g., MacOS 9 having timezone as ('','')).
if old:
current_format = current_format.replace(old, new)
# If %W is used, then Sunday, 2005-01-03 will fall on week 0 since
# 2005-01-03 occurs before the first Monday of the year. Otherwise
# %U is used.
time_tuple = time.struct_time((1999,1,3,1,1,1,6,3,0))
if '00' in time.strftime(directive, time_tuple):
U_W = '%W'
else:
U_W = '%U'
date_time[offset] = current_format.replace('11', U_W)
self.LC_date_time = date_time[0]
self.LC_date = date_time[1]
self.LC_time = date_time[2]
def __calc_timezone(self):
# Set self.timezone by using time.tzname.
# Do not worry about possibility of time.tzname[0] == timetzname[1]
# and time.daylight; handle that in strptime .
try:
time.tzset()
except AttributeError:
pass
no_saving = frozenset({"utc", "gmt", time.tzname[0].lower()})
if time.daylight:
has_saving = frozenset({time.tzname[1].lower()})
else:
has_saving = frozenset()
self.timezone = (no_saving, has_saving)
class TimeRE(dict):
"""Handle conversion from format directives to regexes."""
def __init__(self, locale_time=None):
"""Create keys/values.
Order of execution is important for dependency reasons.
"""
if locale_time:
self.locale_time = locale_time
else:
self.locale_time = LocaleTime()
base = super()
base.__init__({
# The " \d" part of the regex is to make %c from ANSI C work
'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
'f': r"(?P<f>[0-9]{1,6})",
'H': r"(?P<H>2[0-3]|[0-1]\d|\d)",
'I': r"(?P<I>1[0-2]|0[1-9]|[1-9])",
'j': r"(?P<j>36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])",
'm': r"(?P<m>1[0-2]|0[1-9]|[1-9])",
'M': r"(?P<M>[0-5]\d|\d)",
'S': r"(?P<S>6[0-1]|[0-5]\d|\d)",
'U': r"(?P<U>5[0-3]|[0-4]\d|\d)",
'w': r"(?P<w>[0-6])",
# W is set below by using 'U'
'y': r"(?P<y>\d\d)",
#XXX: Does 'Y' need to worry about having less or more than
# 4 digits?
'Y': r"(?P<Y>\d\d\d\d)",
'z': r"(?P<z>[+-]\d\d[0-5]\d)",
'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
'a': self.__seqToRE(self.locale_time.a_weekday, 'a'),
'B': self.__seqToRE(self.locale_time.f_month[1:], 'B'),
'b': self.__seqToRE(self.locale_time.a_month[1:], 'b'),
'p': self.__seqToRE(self.locale_time.am_pm, 'p'),
'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
for tz in tz_names),
'Z'),
'%': '%'})
base.__setitem__('W', base.__getitem__('U').replace('U', 'W'))
base.__setitem__('c', self.pattern(self.locale_time.LC_date_time))
base.__setitem__('x', self.pattern(self.locale_time.LC_date))
base.__setitem__('X', self.pattern(self.locale_time.LC_time))
def __seqToRE(self, to_convert, directive):
"""Convert a list to a regex string for matching a directive.
Want possible matching values to be from longest to shortest. This
prevents the possibility of a match occurring for a value that also
a substring of a larger value that should have matched (e.g., 'abc'
matching when 'abcdef' should have been the match).
"""
to_convert = sorted(to_convert, key=len, reverse=True)
for value in to_convert:
if value != '':
break
else:
return ''
regex = '|'.join(re_escape(stuff) for stuff in to_convert)
regex = '(?P<%s>%s' % (directive, regex)
return '%s)' % regex
def pattern(self, format):
"""Return regex pattern for the format string.
Need to make sure that any characters that might be interpreted as
regex syntax are escaped.
"""
processed_format = ''
# The sub() call escapes all characters that might be misconstrued
# as regex syntax. Cannot use re.escape since we have to deal with
# format directives (%m, etc.).
regex_chars = re_compile(r"([\\.^$*+?\(\){}\[\]|])")
format = regex_chars.sub(r"\\\1", format)
whitespace_replacement = re_compile(r'\s+')
format = whitespace_replacement.sub(r'\\s+', format)
while '%' in format:
directive_index = format.index('%')+1
processed_format = "%s%s%s" % (processed_format,
format[:directive_index-1],
self[format[directive_index]])
format = format[directive_index+1:]
return "%s%s" % (processed_format, format)
def compile(self, format):
"""Return a compiled re object for the format string."""
return re_compile(self.pattern(format), IGNORECASE)
_cache_lock = _thread_allocate_lock()
# DO NOT modify _TimeRE_cache or _regex_cache without acquiring the cache lock
# first!
_TimeRE_cache = TimeRE()
_CACHE_MAX_SIZE = 5 # Max number of regexes stored in _regex_cache
_regex_cache = {}
def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon):
"""Calculate the Julian day based on the year, week of the year, and day of
the week, with week_start_day representing whether the week of the year
assumes the week starts on Sunday or Monday (6 or 0)."""
first_weekday = datetime_date(year, 1, 1).weekday()
# If we are dealing with the %U directive (week starts on Sunday), it's
# easier to just shift the view to Sunday being the first day of the
# week.
if not week_starts_Mon:
first_weekday = (first_weekday + 1) % 7
day_of_week = (day_of_week + 1) % 7
# Need to watch out for a week 0 (when the first day of the year is not
# the same as that specified by %U or %W).
week_0_length = (7 - first_weekday) % 7
if week_of_year == 0:
return 1 + day_of_week - first_weekday
else:
days_to_week = week_0_length + (7 * (week_of_year - 1))
return 1 + days_to_week + day_of_week
def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a 2-tuple consisting of a time struct and an int containing
the number of microseconds based on the input string and the
format string."""
for index, arg in enumerate([data_string, format]):
if not isinstance(arg, str):
msg = "strptime() argument {} must be str, not {}"
raise TypeError(msg.format(index, type(arg)))
global _TimeRE_cache, _regex_cache
with _cache_lock:
if _getlang() != _TimeRE_cache.locale_time.lang:
_TimeRE_cache = TimeRE()
_regex_cache.clear()
if len(_regex_cache) > _CACHE_MAX_SIZE:
_regex_cache.clear()
locale_time = _TimeRE_cache.locale_time
format_regex = _regex_cache.get(format)
if not format_regex:
try:
format_regex = _TimeRE_cache.compile(format)
# KeyError raised when a bad format is found; can be specified as
# \\, in which case it was a stray % but with a space after it
except KeyError as err:
bad_directive = err.args[0]
if bad_directive == "\\":
bad_directive = "%"
del err
raise ValueError("'%s' is a bad directive in format '%s'" %
(bad_directive, format)) from None
# IndexError only occurs when the format string is "%"
except IndexError:
raise ValueError("stray %% in format '%s'" % format) from None
_regex_cache[format] = format_regex
found = format_regex.match(data_string)
if not found:
raise ValueError("time data %r does not match format %r" %
(data_string, format))
if len(data_string) != found.end():
raise ValueError("unconverted data remains: %s" %
data_string[found.end():])
year = None
month = day = 1
hour = minute = second = fraction = 0
tz = -1
tzoffset = None
# Default to -1 to signify that values not known; not critical to have,
# though
week_of_year = -1
week_of_year_start = -1
# weekday and julian defaulted to None so as to signal need to calculate
# values
weekday = julian = None
found_dict = found.groupdict()
for group_key in found_dict.keys():
# Directives not explicitly handled below:
# c, x, X
# handled by making out of other directives
# U, W
# worthless without day of the week
if group_key == 'y':
year = int(found_dict['y'])
# Open Group specification for strptime() states that a %y
#value in the range of [00, 68] is in the century 2000, while
#[69,99] is in the century 1900
if year <= 68:
year += 2000
else:
year += 1900
elif group_key == 'Y':
year = int(found_dict['Y'])
elif group_key == 'm':
month = int(found_dict['m'])
elif group_key == 'B':
month = locale_time.f_month.index(found_dict['B'].lower())
elif group_key == 'b':
month = locale_time.a_month.index(found_dict['b'].lower())
elif group_key == 'd':
day = int(found_dict['d'])
elif group_key == 'H':
hour = int(found_dict['H'])
elif group_key == 'I':
hour = int(found_dict['I'])
ampm = found_dict.get('p', '').lower()
# If there was no AM/PM indicator, we'll treat this like AM
if ampm in ('', locale_time.am_pm[0]):
# We're in AM so the hour is correct unless we're
# looking at 12 midnight.
# 12 midnight == 12 AM == hour 0
if hour == 12:
hour = 0
elif ampm == locale_time.am_pm[1]:
# We're in PM so we need to add 12 to the hour unless
# we're looking at 12 noon.
# 12 noon == 12 PM == hour 12
if hour != 12:
hour += 12
elif group_key == 'M':
minute = int(found_dict['M'])
elif group_key == 'S':
second = int(found_dict['S'])
elif group_key == 'f':
s = found_dict['f']
# Pad to always return microseconds.
s += "0" * (6 - len(s))
fraction = int(s)
elif group_key == 'A':
weekday = locale_time.f_weekday.index(found_dict['A'].lower())
elif group_key == 'a':
weekday = locale_time.a_weekday.index(found_dict['a'].lower())
elif group_key == 'w':
weekday = int(found_dict['w'])
if weekday == 0:
weekday = 6
else:
weekday -= 1
elif group_key == 'j':
julian = int(found_dict['j'])
elif group_key in ('U', 'W'):
week_of_year = int(found_dict[group_key])
if group_key == 'U':
# U starts week on Sunday.
week_of_year_start = 6
else:
# W starts week on Monday.
week_of_year_start = 0
elif group_key == 'z':
z = found_dict['z']
tzoffset = int(z[1:3]) * 60 + int(z[3:5])
if z.startswith("-"):
tzoffset = -tzoffset
elif group_key == 'Z':
# Since -1 is default value only need to worry about setting tz if
# it can be something other than -1.
found_zone = found_dict['Z'].lower()
for value, tz_values in enumerate(locale_time.timezone):
if found_zone in tz_values:
# Deal with bad locale setup where timezone names are the
# same and yet time.daylight is true; too ambiguous to
# be able to tell what timezone has daylight savings
if (time.tzname[0] == time.tzname[1] and
time.daylight and found_zone not in ("utc", "gmt")):
break
else:
tz = value
break
leap_year_fix = False
if year is None and month == 2 and day == 29:
year = 1904 # 1904 is first leap year of 20th century
leap_year_fix = True
elif year is None:
year = 1900
# If we know the week of the year and what day of that week, we can figure
# out the Julian day of the year.
if julian is None and week_of_year != -1 and weekday is not None:
week_starts_Mon = True if week_of_year_start == 0 else False
julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
week_starts_Mon)
# Cannot pre-calculate datetime_date() since can change in Julian
# calculation and thus could have different value for the day of the week
# calculation.
if julian is None:
# Need to add 1 to result since first day of the year is 1, not 0.
julian = datetime_date(year, month, day).toordinal() - \
datetime_date(year, 1, 1).toordinal() + 1
else: # Assume that if they bothered to include Julian day it will
# be accurate.
datetime_result = datetime_date.fromordinal((julian - 1) + datetime_date(year, 1, 1).toordinal())
year = datetime_result.year
month = datetime_result.month
day = datetime_result.day
if weekday is None:
weekday = datetime_date(year, month, day).weekday()
# Add timezone info
tzname = found_dict.get("Z")
if tzoffset is not None:
gmtoff = tzoffset * 60
else:
gmtoff = None
if leap_year_fix:
# the caller didn't supply a year but asked for Feb 29th. We couldn't
# use the default of 1900 for computations. We set it back to ensure
# that February 29th is smaller than March 1st.
year = 1900
return (year, month, day,
hour, minute, second,
weekday, julian, tz, tzname, gmtoff), fraction
def _strptime_time(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a time struct based on the input string and the
format string."""
tt = _strptime(data_string, format)[0]
return time.struct_time(tt[:time._STRUCT_TM_ITEMS])
def _strptime_datetime(cls, data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a class cls instance based on the input string and the
format string."""
tt, fraction = _strptime(data_string, format)
tzname, gmtoff = tt[-2:]
args = tt[:6] + (fraction,)
if gmtoff is not None:
tzdelta = datetime_timedelta(seconds=gmtoff)
if tzname:
tz = datetime_timezone(tzdelta, tzname)
else:
tz = datetime_timezone(tzdelta)
args += (tz,)
return cls(*args)
|
gpl-3.0
|
[
624,
2848,
9367,
13,
2407,
3992,
436,
3423,
14,
199,
199,
13748,
26,
272,
28298,
1366,
1553,
5289,
5899,
83,
436,
14086,
5867,
13,
6100,
900,
2556,
272,
4703,
907,
1553,
10560,
5163,
397,
367,
3851,
4877,
282,
1059,
402,
1318,
3035,
355,
900,
2556,
199,
199,
29865,
26,
272,
485,
362,
4159,
1553,
16266,
734,
4052,
2637,
365,
3769,
1202,
367,
314,
5867,
272,
620,
9367,
1553,
28562,
314,
900,
2702,
11159,
701,
314,
3032,
13,
262,
1059,
199,
199,
624,
199,
646,
900,
199,
646,
5867,
199,
646,
11234,
199,
504,
295,
492,
6555,
465,
295,
63,
2014,
199,
504,
295,
492,
27499,
5788,
11320,
199,
504,
295,
492,
4772,
465,
295,
63,
3765,
199,
504,
2197,
492,
334,
602,
465,
2197,
63,
602,
12,
1993,
6871,
465,
2197,
63,
7473,
12,
1993,
7137,
465,
2197,
63,
7145,
9,
199,
893,
26,
272,
687,
485,
2671,
492,
18310,
63,
831,
465,
485,
2671,
63,
12991,
63,
831,
199,
2590,
3545,
26,
272,
687,
485,
5869,
63,
2671,
492,
18310,
63,
831,
465,
485,
2671,
63,
12991,
63,
831,
199,
199,
363,
452,
363,
275,
942,
199,
199,
318,
485,
362,
4159,
837,
272,
327,
16266,
734,
4052,
314,
1453,
2637,
365,
663,
370,
14,
272,
372,
5867,
14,
362,
5508,
8,
5508,
14,
7027,
63,
4961,
9,
199,
199,
533,
28298,
1366,
8,
785,
304,
272,
408,
4759,
470,
436,
10022,
5867,
13,
6100,
2556,
4048,
370,
900,
14,
339,
10762,
16883,
26,
267,
289,
63,
12451,
1553,
2615,
20947,
1561,
334,
23,
13,
1053,
769,
9,
267,
282,
63,
12451,
1553,
2236,
23988,
972,
20947,
1561,
334,
23,
13,
1053,
769,
9,
267,
289,
63,
4482,
1553,
2615,
5794,
1561,
334,
969,
13,
1053,
769,
27,
7283,
574,
315,
359,
16,
467,
1314,
490,
365,
3483,
701,
1233,
9,
267,
282,
63,
4482,
1553,
2236,
23988,
972,
5794,
1561,
334,
969,
13,
1053,
769,
12,
7283,
574,
315,
490,
359,
16,
467,
1314,
365,
3483,
701,
1233,
9,
267,
8140,
63,
7073,
1553,
24343,
15,
10793,
6025,
334,
18,
13,
1053,
769,
9,
267,
26703,
63,
602,
63,
521,
1553,
1475,
1059,
367,
1434,
15,
521,
6025,
334,
875,
9,
267,
26703,
63,
602,
1553,
1475,
1059,
367,
1434,
6025,
334,
875,
9,
267,
26703,
63,
521,
1553,
1475,
1059,
367,
900,
6025,
334,
875,
9,
267,
7137,
1553,
5382,
4040,
13,
436,
2222,
13,
2977,
4040,
13,
23374,
780,
7137,
6025,
490,
334,
18,
13,
1053,
769,
402,
5951,
9,
267,
6339,
1553,
8466,
1202,
701,
1256,
334,
18,
13,
1053,
2008,
9,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
408,
1084,
1006,
3004,
14,
398,
9240,
402,
3102,
2797,
2530,
878,
367,
5936,
14872,
14,
398,
710,
5867,
2637,
365,
663,
737,
314,
3268,
436,
2066,
7923,
4020,
2544,
267,
24234,
14,
221,
961,
365,
370,
1852,
3238,
626,
314,
3004,
4898,
440,
663,
543,
282,
267,
13667,
402,
2556,
687,
1655,
2419,
1373,
5867,
14,
221,
961,
3955,
4750,
12060,
267,
5992,
1380,
1808,
7183,
2382,
1373,
2462,
4882,
282,
5867,
13,
7106,
267,
805,
1830,
4573,
2462,
4493,
314,
5867,
1830,
314,
805,
315,
267,
314,
1163,
2462,
365,
5139,
3879,
14,
221,
2165,
529,
2803,
3955,
1240,
367,
267,
23340,
370,
7981,
13729,
314,
5867,
1830,
5867,
13,
7106,
1233,
365,
267,
3879,
14,
221,
710,
1104,
2348,
365,
4224,
315,
1930,
17122,
1630,
440,
13516,
3595,
267,
9689,
642,
14,
398,
5972,
1163,
3962,
4976,
365,
340,
17122,
2896,
314,
7137,
436,
8103,
267,
440,
1240,
5823,
14,
3903,
409,
1275,
221,
10314,
365,
376,
4976,
367,
314,
2240,
2626,
12,
10617,
12,
267,
3967,
13729,
314,
7137,
365,
25235,
2003,
1928,
626,
1240,
14,
398,
408,
267,
291,
14,
4159,
275,
485,
362,
4159,
342,
267,
291,
855,
8104,
63,
12451,
342,
267,
291,
855,
8104,
63,
4482,
342,
267,
291,
855,
8104,
63,
455,
63,
7073,
342,
267,
291,
855,
8104,
63,
7145,
342,
267,
291,
855,
8104,
63,
602,
63,
521,
342,
267,
340,
485,
362,
4159,
342,
1137,
291,
14,
4159,
26,
288,
746,
1722,
480,
5508,
2896,
5309,
11097,
531,
339,
347,
636,
6226,
8,
277,
12,
5412,
12,
13738,
304,
267,
327,
2654,
2125,
370,
5412,
370,
1902,
314,
13738,
334,
374,
715,
395,
587,
314,
1771,
14,
267,
5412,
275,
769,
8,
3610,
9,
267,
340,
13738,
26,
288,
5412,
14,
3176,
8,
16,
12,
4074,
267,
587,
26,
288,
5412,
14,
740,
8355,
267,
372,
5412,
339,
347,
636,
8104,
63,
12451,
8,
277,
304,
267,
327,
2494,
291,
14,
65,
63,
12451,
436,
291,
14,
70,
63,
12451,
1808,
314,
11234,
267,
327,
859,
14,
267,
282,
63,
12451,
275,
359,
8183,
14,
2977,
63,
20787,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
23,
1874,
267,
289,
63,
12451,
275,
359,
8183,
14,
2977,
63,
354,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
23,
1874,
267,
291,
14,
65,
63,
12451,
275,
282,
63,
12451,
267,
291,
14,
70,
63,
12451,
275,
289,
63,
12451,
339,
347,
636,
8104,
63,
4482,
8,
277,
304,
267,
327,
2494,
291,
14,
70,
63,
4482,
436,
291,
14,
65,
63,
4482,
1808,
314,
11234,
859,
14,
267,
282,
63,
4482,
275,
359,
8183,
14,
4482,
63,
20787,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
969,
1874,
267,
289,
63,
4482,
275,
359,
8183,
14,
4482,
63,
354,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
969,
1874,
267,
291,
14,
65,
63,
4482,
275,
282,
63,
4482,
267,
291,
14,
70,
63,
4482,
275,
289,
63,
4482,
339,
347,
636,
8104,
63,
455,
63,
7073,
8,
277,
304,
267,
327,
2494,
291,
14,
455,
63,
7073,
701,
1808,
900,
14,
6205,
1252,
398,
327,
710,
10628,
1434,
334,
16278,
12,
19,
12,
1196,
12,
5180,
12,
1602,
12,
1229,
12,
18,
12,
2114,
12,
16,
9,
365,
440,
7710,
626,
267,
327,
8127,
2652,
27,
2951,
21056,
370,
1172,
1202,
652,
4036,
4509,
587,
2382,
282,
267,
327,
2955,
1434,
1990,
4346,
14,
267,
8140,
63,
7073,
275,
942,
267,
367,
6925,
315,
334,
17
] |
[
2848,
9367,
13,
2407,
3992,
436,
3423,
14,
199,
199,
13748,
26,
272,
28298,
1366,
1553,
5289,
5899,
83,
436,
14086,
5867,
13,
6100,
900,
2556,
272,
4703,
907,
1553,
10560,
5163,
397,
367,
3851,
4877,
282,
1059,
402,
1318,
3035,
355,
900,
2556,
199,
199,
29865,
26,
272,
485,
362,
4159,
1553,
16266,
734,
4052,
2637,
365,
3769,
1202,
367,
314,
5867,
272,
620,
9367,
1553,
28562,
314,
900,
2702,
11159,
701,
314,
3032,
13,
262,
1059,
199,
199,
624,
199,
646,
900,
199,
646,
5867,
199,
646,
11234,
199,
504,
295,
492,
6555,
465,
295,
63,
2014,
199,
504,
295,
492,
27499,
5788,
11320,
199,
504,
295,
492,
4772,
465,
295,
63,
3765,
199,
504,
2197,
492,
334,
602,
465,
2197,
63,
602,
12,
1993,
6871,
465,
2197,
63,
7473,
12,
1993,
7137,
465,
2197,
63,
7145,
9,
199,
893,
26,
272,
687,
485,
2671,
492,
18310,
63,
831,
465,
485,
2671,
63,
12991,
63,
831,
199,
2590,
3545,
26,
272,
687,
485,
5869,
63,
2671,
492,
18310,
63,
831,
465,
485,
2671,
63,
12991,
63,
831,
199,
199,
363,
452,
363,
275,
942,
199,
199,
318,
485,
362,
4159,
837,
272,
327,
16266,
734,
4052,
314,
1453,
2637,
365,
663,
370,
14,
272,
372,
5867,
14,
362,
5508,
8,
5508,
14,
7027,
63,
4961,
9,
199,
199,
533,
28298,
1366,
8,
785,
304,
272,
408,
4759,
470,
436,
10022,
5867,
13,
6100,
2556,
4048,
370,
900,
14,
339,
10762,
16883,
26,
267,
289,
63,
12451,
1553,
2615,
20947,
1561,
334,
23,
13,
1053,
769,
9,
267,
282,
63,
12451,
1553,
2236,
23988,
972,
20947,
1561,
334,
23,
13,
1053,
769,
9,
267,
289,
63,
4482,
1553,
2615,
5794,
1561,
334,
969,
13,
1053,
769,
27,
7283,
574,
315,
359,
16,
467,
1314,
490,
365,
3483,
701,
1233,
9,
267,
282,
63,
4482,
1553,
2236,
23988,
972,
5794,
1561,
334,
969,
13,
1053,
769,
12,
7283,
574,
315,
490,
359,
16,
467,
1314,
365,
3483,
701,
1233,
9,
267,
8140,
63,
7073,
1553,
24343,
15,
10793,
6025,
334,
18,
13,
1053,
769,
9,
267,
26703,
63,
602,
63,
521,
1553,
1475,
1059,
367,
1434,
15,
521,
6025,
334,
875,
9,
267,
26703,
63,
602,
1553,
1475,
1059,
367,
1434,
6025,
334,
875,
9,
267,
26703,
63,
521,
1553,
1475,
1059,
367,
900,
6025,
334,
875,
9,
267,
7137,
1553,
5382,
4040,
13,
436,
2222,
13,
2977,
4040,
13,
23374,
780,
7137,
6025,
490,
334,
18,
13,
1053,
769,
402,
5951,
9,
267,
6339,
1553,
8466,
1202,
701,
1256,
334,
18,
13,
1053,
2008,
9,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
408,
1084,
1006,
3004,
14,
398,
9240,
402,
3102,
2797,
2530,
878,
367,
5936,
14872,
14,
398,
710,
5867,
2637,
365,
663,
737,
314,
3268,
436,
2066,
7923,
4020,
2544,
267,
24234,
14,
221,
961,
365,
370,
1852,
3238,
626,
314,
3004,
4898,
440,
663,
543,
282,
267,
13667,
402,
2556,
687,
1655,
2419,
1373,
5867,
14,
221,
961,
3955,
4750,
12060,
267,
5992,
1380,
1808,
7183,
2382,
1373,
2462,
4882,
282,
5867,
13,
7106,
267,
805,
1830,
4573,
2462,
4493,
314,
5867,
1830,
314,
805,
315,
267,
314,
1163,
2462,
365,
5139,
3879,
14,
221,
2165,
529,
2803,
3955,
1240,
367,
267,
23340,
370,
7981,
13729,
314,
5867,
1830,
5867,
13,
7106,
1233,
365,
267,
3879,
14,
221,
710,
1104,
2348,
365,
4224,
315,
1930,
17122,
1630,
440,
13516,
3595,
267,
9689,
642,
14,
398,
5972,
1163,
3962,
4976,
365,
340,
17122,
2896,
314,
7137,
436,
8103,
267,
440,
1240,
5823,
14,
3903,
409,
1275,
221,
10314,
365,
376,
4976,
367,
314,
2240,
2626,
12,
10617,
12,
267,
3967,
13729,
314,
7137,
365,
25235,
2003,
1928,
626,
1240,
14,
398,
408,
267,
291,
14,
4159,
275,
485,
362,
4159,
342,
267,
291,
855,
8104,
63,
12451,
342,
267,
291,
855,
8104,
63,
4482,
342,
267,
291,
855,
8104,
63,
455,
63,
7073,
342,
267,
291,
855,
8104,
63,
7145,
342,
267,
291,
855,
8104,
63,
602,
63,
521,
342,
267,
340,
485,
362,
4159,
342,
1137,
291,
14,
4159,
26,
288,
746,
1722,
480,
5508,
2896,
5309,
11097,
531,
339,
347,
636,
6226,
8,
277,
12,
5412,
12,
13738,
304,
267,
327,
2654,
2125,
370,
5412,
370,
1902,
314,
13738,
334,
374,
715,
395,
587,
314,
1771,
14,
267,
5412,
275,
769,
8,
3610,
9,
267,
340,
13738,
26,
288,
5412,
14,
3176,
8,
16,
12,
4074,
267,
587,
26,
288,
5412,
14,
740,
8355,
267,
372,
5412,
339,
347,
636,
8104,
63,
12451,
8,
277,
304,
267,
327,
2494,
291,
14,
65,
63,
12451,
436,
291,
14,
70,
63,
12451,
1808,
314,
11234,
267,
327,
859,
14,
267,
282,
63,
12451,
275,
359,
8183,
14,
2977,
63,
20787,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
23,
1874,
267,
289,
63,
12451,
275,
359,
8183,
14,
2977,
63,
354,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
23,
1874,
267,
291,
14,
65,
63,
12451,
275,
282,
63,
12451,
267,
291,
14,
70,
63,
12451,
275,
289,
63,
12451,
339,
347,
636,
8104,
63,
4482,
8,
277,
304,
267,
327,
2494,
291,
14,
70,
63,
4482,
436,
291,
14,
65,
63,
4482,
1808,
314,
11234,
859,
14,
267,
282,
63,
4482,
275,
359,
8183,
14,
4482,
63,
20787,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
969,
1874,
267,
289,
63,
4482,
275,
359,
8183,
14,
4482,
63,
354,
59,
73,
1055,
2325,
342,
367,
284,
315,
1425,
8,
969,
1874,
267,
291,
14,
65,
63,
4482,
275,
282,
63,
4482,
267,
291,
14,
70,
63,
4482,
275,
289,
63,
4482,
339,
347,
636,
8104,
63,
455,
63,
7073,
8,
277,
304,
267,
327,
2494,
291,
14,
455,
63,
7073,
701,
1808,
900,
14,
6205,
1252,
398,
327,
710,
10628,
1434,
334,
16278,
12,
19,
12,
1196,
12,
5180,
12,
1602,
12,
1229,
12,
18,
12,
2114,
12,
16,
9,
365,
440,
7710,
626,
267,
327,
8127,
2652,
27,
2951,
21056,
370,
1172,
1202,
652,
4036,
4509,
587,
2382,
282,
267,
327,
2955,
1434,
1990,
4346,
14,
267,
8140,
63,
7073,
275,
942,
267,
367,
6925,
315,
334,
17,
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,
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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
] |
Facetracker-project/facetracker-core
|
lib/youtube-dl/youtube_dl/extractor/criterion.py
|
138
|
1359
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
from .common import InfoExtractor
class CriterionIE(InfoExtractor):
_VALID_URL = r'https?://www\.criterion\.com/films/(?P<id>[0-9]+)-.+'
_TEST = {
'url': 'http://www.criterion.com/films/184-le-samourai',
'md5': 'bc51beba55685509883a9a7830919ec3',
'info_dict': {
'id': '184',
'ext': 'mp4',
'title': 'Le Samouraï',
'description': 'md5:a2b4b116326558149bef81f76dcbb93f',
}
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
final_url = self._search_regex(
r'so.addVariable\("videoURL", "(.+?)"\)\;', webpage, 'video url')
title = self._og_search_title(webpage)
description = self._html_search_regex(
r'<meta name="description" content="(.+?)" />',
webpage, 'video description')
thumbnail = self._search_regex(
r'so.addVariable\("thumbnailURL", "(.+?)"\)\;',
webpage, 'thumbnail url')
return {
'id': video_id,
'url': final_url,
'title': title,
'description': description,
'thumbnail': thumbnail,
}
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
445,
7527,
265,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
1544,
4537,
21418,
4537,
957,
15,
1289,
706,
9448,
48,
28,
344,
9514,
16,
13,
25,
2807,
7216,
14,
4786,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
21418,
14,
957,
15,
1289,
706,
15,
10078,
13,
274,
13,
21660,
567,
5789,
297,
267,
283,
1064,
21,
356,
283,
3776,
2869,
1235,
2470,
1229,
2333,
1229,
1643,
16456,
65,
25,
65,
2277,
10556,
1167,
825,
19,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10078,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2553,
428,
455,
567,
65,
128,
108,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
65,
18,
66,
20,
66,
7524,
8342,
17686,
10721,
31945,
2835,
70,
2114,
3833,
2501,
3129,
70,
297,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
4242,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
3722,
2632,
401,
7340,
11198,
2924,
13670,
10805,
9248,
12,
283,
3722,
1166,
358,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
1369,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
2024,
536,
628,
1802,
2,
1564,
628,
28149,
2924,
1182,
4206,
288,
9248,
12,
283,
3722,
1369,
358,
267,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
8311,
2632,
401,
7340,
11198,
2924,
13670,
10805,
288,
9248,
12,
283,
8311,
1166,
358,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
4242,
63,
633,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
267,
789,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
445,
7527,
265,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
1544,
4537,
21418,
4537,
957,
15,
1289,
706,
9448,
48,
28,
344,
9514,
16,
13,
25,
2807,
7216,
14,
4786,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
21418,
14,
957,
15,
1289,
706,
15,
10078,
13,
274,
13,
21660,
567,
5789,
297,
267,
283,
1064,
21,
356,
283,
3776,
2869,
1235,
2470,
1229,
2333,
1229,
1643,
16456,
65,
25,
65,
2277,
10556,
1167,
825,
19,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10078,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2553,
428,
455,
567,
65,
128,
108,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
65,
18,
66,
20,
66,
7524,
8342,
17686,
10721,
31945,
2835,
70,
2114,
3833,
2501,
3129,
70,
297,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
4242,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
3722,
2632,
401,
7340,
11198,
2924,
13670,
10805,
9248,
12,
283,
3722,
1166,
358,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
1369,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
2024,
536,
628,
1802,
2,
1564,
628,
28149,
2924,
1182,
4206,
288,
9248,
12,
283,
3722,
1369,
358,
267,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
8311,
2632,
401,
7340,
11198,
2924,
13670,
10805,
288,
9248,
12,
283,
8311,
1166,
358,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
4242,
63,
633,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
267,
789,
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,
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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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
] |
open-synergy/social
|
mail_tracking/models/ir_mail_server.py
|
2
|
4093
|
# -*- coding: utf-8 -*-
# © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import re
import threading
from openerp import models, api, tools
class IrMailServer(models.Model):
_inherit = "ir.mail_server"
def _tracking_headers_add(self, tracking_email_id, headers):
"""Allow other addons to add its own tracking SMTP headers"""
headers = headers or {}
headers['X-Odoo-Database'] = getattr(
threading.currentThread(), 'dbname', None),
headers['X-Odoo-Tracking-ID'] = tracking_email_id
return headers
def _tracking_email_id_body_get(self, body):
body = body or ''
tracking_email_id = False
# https://regex101.com/r/lW4cB1/2
match = re.search(
r'<img [^>]* data-odoo-tracking-email=["\']([0-9]*)["\']', body)
if match:
try:
tracking_email_id = int(match.group(1))
except: # pragma: no cover
pass
return tracking_email_id
def build_email(self, email_from, email_to, subject, body, email_cc=None,
email_bcc=None, reply_to=False, attachments=None,
message_id=None, references=None, object_id=False,
subtype='plain', headers=None, body_alternative=None,
subtype_alternative='plain'):
tracking_email_id = self._tracking_email_id_body_get(body)
if tracking_email_id:
headers = self._tracking_headers_add(tracking_email_id, headers)
msg = super(IrMailServer, self).build_email(
email_from, email_to, subject, body, email_cc=email_cc,
email_bcc=email_bcc, reply_to=reply_to, attachments=attachments,
message_id=message_id, references=references, object_id=object_id,
subtype=subtype, headers=headers,
body_alternative=body_alternative,
subtype_alternative=subtype_alternative)
return msg
def _tracking_email_get(self, message):
tracking_email_id = False
if message.get('X-Odoo-Tracking-ID', '').isdigit():
tracking_email_id = int(message['X-Odoo-Tracking-ID'])
return self.env['mail.tracking.email'].browse(tracking_email_id)
def _smtp_server_get(self, mail_server_id, smtp_server):
smtp_server_used = False
mail_server = None
if mail_server_id:
mail_server = self.browse(mail_server_id)
elif not smtp_server:
mail_server_ids = self.search([], order='sequence', limit=1)
mail_server = mail_server_ids[0] if mail_server_ids else None
if mail_server:
smtp_server_used = mail_server.smtp_host
else: # pragma: no cover
smtp_server_used = smtp_server or tools.config.get('smtp_server')
return smtp_server_used
@api.model
def send_email(self, message, mail_server_id=None, smtp_server=None,
smtp_port=None, smtp_user=None, smtp_password=None,
smtp_encryption=None, smtp_debug=False):
message_id = False
tracking_email = self._tracking_email_get(message)
smtp_server_used = self.sudo()._smtp_server_get(
mail_server_id, smtp_server,
)
try:
message_id = super(IrMailServer, self).send_email(
message, mail_server_id=mail_server_id,
smtp_server=smtp_server, smtp_port=smtp_port,
smtp_user=smtp_user, smtp_password=smtp_password,
smtp_encryption=smtp_encryption, smtp_debug=smtp_debug)
except Exception as e:
if tracking_email:
tracking_email.smtp_error(self, smtp_server_used, e)
raise
if message_id and tracking_email:
vals = tracking_email._tracking_sent_prepare(
self, smtp_server_used, message, message_id)
if vals:
self.env['mail.tracking.event'].sudo().create(vals)
return message_id
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
22405,
103,
7800,
437,
343,
265,
2308,
662,
14809,
29295,
446,
665,
867,
265,
2308,
14,
397,
7751,
29295,
32,
266,
6413,
2159,
3042,
14,
957,
30,
199,
3,
844,
437,
12006,
13,
19,
14,
16,
503,
2945,
334,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
680,
199,
199,
646,
295,
199,
646,
5796,
199,
504,
5166,
492,
1709,
12,
2986,
12,
7249,
421,
199,
533,
473,
82,
13681,
3120,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
298,
723,
14,
1198,
63,
1000,
2,
339,
347,
485,
14428,
63,
2139,
63,
525,
8,
277,
12,
15161,
63,
2123,
63,
344,
12,
2323,
304,
267,
408,
7852,
1163,
21293,
370,
1050,
2399,
5705,
15161,
19810,
2323,
624,
267,
2323,
275,
2323,
503,
1052,
267,
2323,
459,
56,
13,
47,
16766,
13,
7243,
418,
275,
2519,
8,
288,
5796,
14,
1818,
4436,
1062,
283,
13238,
297,
488,
395,
267,
2323,
459,
56,
13,
47,
16766,
13,
23785,
13,
998,
418,
275,
15161,
63,
2123,
63,
344,
267,
372,
2323,
339,
347,
485,
14428,
63,
2123,
63,
344,
63,
2030,
63,
362,
8,
277,
12,
2396,
304,
267,
2396,
275,
2396,
503,
2125,
267,
15161,
63,
2123,
63,
344,
275,
756,
267,
327,
4178,
921,
3821,
4893,
14,
957,
15,
82,
15,
76,
55,
20,
67,
34,
17,
15,
18,
267,
1336,
275,
295,
14,
1733,
8,
288,
519,
7601,
4060,
359,
62,
30,
3672,
666,
13,
22058,
13,
14428,
13,
2123,
6270,
26889,
779,
16,
13,
25,
23849,
905,
26889,
297,
2396,
9,
267,
340,
1336,
26,
288,
862,
26,
355,
15161,
63,
2123,
63,
344,
275,
1109,
8,
1431,
14,
923,
8,
17,
430,
288,
871,
26,
221,
327,
11942,
26,
949,
8486,
355,
986,
267,
372,
15161,
63,
2123,
63,
344,
339,
347,
1900,
63,
2123,
8,
277,
12,
3031,
63,
504,
12,
3031,
63,
475,
12,
5420,
12,
2396,
12,
3031,
63,
2055,
29,
403,
12,
490,
3031,
63,
21976,
29,
403,
12,
9351,
63,
475,
29,
797,
12,
18912,
29,
403,
12,
490,
1245,
63,
344,
29,
403,
12,
6941,
29,
403,
12,
909,
63,
344,
29,
797,
12,
490,
15686,
534,
6104,
297,
2323,
29,
403,
12,
2396,
63,
19389,
29,
403,
12,
490,
15686,
63,
19389,
534,
6104,
735,
267,
15161,
63,
2123,
63,
344,
275,
291,
423,
14428,
63,
2123,
63,
344,
63,
2030,
63,
362,
8,
2030,
9,
267,
340,
15161,
63,
2123,
63,
344,
26,
288,
2323,
275,
291,
423,
14428,
63,
2139,
63,
525,
8,
14428,
63,
2123,
63,
344,
12,
2323,
9,
267,
1499,
275,
1613,
8,
32602,
13681,
3120,
12,
291,
680,
1506,
63,
2123,
8,
288,
3031,
63,
504,
12,
3031,
63,
475,
12,
5420,
12,
2396,
12,
3031,
63,
2055,
29,
2123,
63,
2055,
12,
288,
3031,
63,
21976,
29,
2123,
63,
21976,
12,
9351,
63,
475,
29,
8102,
63,
475,
12,
18912,
29,
15855,
12,
288,
1245,
63,
344,
29,
1188,
63,
344,
12,
6941,
29,
12635,
12,
909,
63,
344,
29,
785,
63,
344,
12,
288,
15686,
29,
10512,
12,
2323,
29,
2139,
12,
288,
2396,
63,
19389,
29,
2030,
63,
19389,
12,
288,
15686,
63,
19389,
29,
10512,
63,
19389,
9,
267,
372,
1499,
339,
347,
485,
14428,
63,
2123,
63,
362,
8,
277,
12,
1245,
304,
267,
15161,
63,
2123,
63,
344,
275,
756,
267,
340,
1245,
14,
362,
360,
56,
13,
47,
16766,
13,
23785,
13,
998,
297,
12548,
13896,
837,
288,
15161,
63,
2123,
63,
344,
275,
1109,
8,
1188,
459,
56,
13,
47,
16766,
13,
23785,
13,
998,
1105,
267,
372,
291,
14,
1813,
459,
1198,
14,
14428,
14,
2123,
2278,
4570,
8,
14428,
63,
2123,
63,
344,
9,
339,
347,
485,
15592,
63,
1000,
63,
362,
8,
277,
12,
6016,
63,
1000,
63,
344,
12,
14400,
63,
1000,
304,
267,
14400,
63,
1000,
63,
2972,
275,
756,
267,
6016,
63,
1000,
275,
488,
267,
340,
6016,
63,
1000,
63,
344,
26,
288,
6016,
63,
1000,
275,
291,
14,
4570,
8,
1198,
63,
1000,
63,
344,
9,
267,
916,
440,
14400,
63,
1000,
26,
288,
6016,
63,
1000,
63,
1580,
275,
291,
14,
1733,
8798,
1865,
534,
4041,
297,
2304,
29,
17,
9,
288,
6016,
63,
1000,
275,
6016,
63,
1000,
63,
1580,
59,
16,
61,
340,
6016,
63,
1000,
63,
1580,
587,
488,
267,
340,
6016,
63,
1000,
26,
288,
14400,
63,
1000,
63,
2972,
275,
6016,
63,
1000,
14,
15592,
63,
1102,
267,
587,
26,
221,
327,
11942,
26,
949,
8486,
288,
14400,
63,
1000,
63,
2972,
275,
14400,
63,
1000,
503,
7249,
14,
888,
14,
362,
360,
15592,
63,
1000,
358,
267,
372,
14400,
63,
1000,
63,
2972,
339,
768,
1246,
14,
1238,
272,
347,
3222,
63,
2123,
8,
277,
12,
1245,
12,
6016,
63,
1000,
63,
344,
29,
403,
12,
14400,
63,
1000,
29,
403,
12,
673,
14400,
63,
719,
29,
403,
12,
14400,
63,
751,
29,
403,
12,
14400,
63,
2060,
29,
403,
12,
673,
14400,
63,
15113,
29,
403,
12,
14400,
63,
1757,
29,
797,
304,
267,
1245,
63,
344,
275,
756,
267,
15161,
63,
2123,
275,
291,
423,
14428,
63,
2123,
63,
362,
8,
1188,
9,
267,
14400,
63,
1000,
63,
2972,
275,
291,
14,
12095,
19050,
15592,
63,
1000,
63,
362,
8,
288,
6016,
63,
1000,
63,
344,
12,
14400,
63,
1000,
12,
267,
776,
267,
862,
26,
288,
1245,
63,
344,
275,
1613,
8,
32602,
13681,
3120,
12,
291,
680,
2254,
63,
2123,
8,
355,
1245,
12,
6016,
63,
1000,
63,
344,
29,
1198,
63,
1000,
63,
344,
12,
355,
14400,
63,
1000,
29,
15592,
63,
1000,
12,
14400,
63,
719,
29,
15592,
63,
719,
12,
355,
14400,
63,
751,
29,
15592,
63,
751,
12,
14400,
63,
2060,
29,
15592,
63,
2060,
12,
355,
14400,
63,
15113,
29,
15592,
63,
15113,
12,
14400,
63,
1757,
29,
15592,
63,
1757,
9,
267,
871,
2186,
465,
325,
26,
288,
340,
15161,
63,
2123,
26,
355,
15161,
63,
2123,
14,
15592,
63,
705,
8,
277,
12,
14400,
63,
1000,
63,
2972,
12,
325,
9,
288,
746,
267,
340,
1245,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
22405,
103,
7800,
437,
343,
265,
2308,
662,
14809,
29295,
446,
665,
867,
265,
2308,
14,
397,
7751,
29295,
32,
266,
6413,
2159,
3042,
14,
957,
30,
199,
3,
844,
437,
12006,
13,
19,
14,
16,
503,
2945,
334,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
680,
199,
199,
646,
295,
199,
646,
5796,
199,
504,
5166,
492,
1709,
12,
2986,
12,
7249,
421,
199,
533,
473,
82,
13681,
3120,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
298,
723,
14,
1198,
63,
1000,
2,
339,
347,
485,
14428,
63,
2139,
63,
525,
8,
277,
12,
15161,
63,
2123,
63,
344,
12,
2323,
304,
267,
408,
7852,
1163,
21293,
370,
1050,
2399,
5705,
15161,
19810,
2323,
624,
267,
2323,
275,
2323,
503,
1052,
267,
2323,
459,
56,
13,
47,
16766,
13,
7243,
418,
275,
2519,
8,
288,
5796,
14,
1818,
4436,
1062,
283,
13238,
297,
488,
395,
267,
2323,
459,
56,
13,
47,
16766,
13,
23785,
13,
998,
418,
275,
15161,
63,
2123,
63,
344,
267,
372,
2323,
339,
347,
485,
14428,
63,
2123,
63,
344,
63,
2030,
63,
362,
8,
277,
12,
2396,
304,
267,
2396,
275,
2396,
503,
2125,
267,
15161,
63,
2123,
63,
344,
275,
756,
267,
327,
4178,
921,
3821,
4893,
14,
957,
15,
82,
15,
76,
55,
20,
67,
34,
17,
15,
18,
267,
1336,
275,
295,
14,
1733,
8,
288,
519,
7601,
4060,
359,
62,
30,
3672,
666,
13,
22058,
13,
14428,
13,
2123,
6270,
26889,
779,
16,
13,
25,
23849,
905,
26889,
297,
2396,
9,
267,
340,
1336,
26,
288,
862,
26,
355,
15161,
63,
2123,
63,
344,
275,
1109,
8,
1431,
14,
923,
8,
17,
430,
288,
871,
26,
221,
327,
11942,
26,
949,
8486,
355,
986,
267,
372,
15161,
63,
2123,
63,
344,
339,
347,
1900,
63,
2123,
8,
277,
12,
3031,
63,
504,
12,
3031,
63,
475,
12,
5420,
12,
2396,
12,
3031,
63,
2055,
29,
403,
12,
490,
3031,
63,
21976,
29,
403,
12,
9351,
63,
475,
29,
797,
12,
18912,
29,
403,
12,
490,
1245,
63,
344,
29,
403,
12,
6941,
29,
403,
12,
909,
63,
344,
29,
797,
12,
490,
15686,
534,
6104,
297,
2323,
29,
403,
12,
2396,
63,
19389,
29,
403,
12,
490,
15686,
63,
19389,
534,
6104,
735,
267,
15161,
63,
2123,
63,
344,
275,
291,
423,
14428,
63,
2123,
63,
344,
63,
2030,
63,
362,
8,
2030,
9,
267,
340,
15161,
63,
2123,
63,
344,
26,
288,
2323,
275,
291,
423,
14428,
63,
2139,
63,
525,
8,
14428,
63,
2123,
63,
344,
12,
2323,
9,
267,
1499,
275,
1613,
8,
32602,
13681,
3120,
12,
291,
680,
1506,
63,
2123,
8,
288,
3031,
63,
504,
12,
3031,
63,
475,
12,
5420,
12,
2396,
12,
3031,
63,
2055,
29,
2123,
63,
2055,
12,
288,
3031,
63,
21976,
29,
2123,
63,
21976,
12,
9351,
63,
475,
29,
8102,
63,
475,
12,
18912,
29,
15855,
12,
288,
1245,
63,
344,
29,
1188,
63,
344,
12,
6941,
29,
12635,
12,
909,
63,
344,
29,
785,
63,
344,
12,
288,
15686,
29,
10512,
12,
2323,
29,
2139,
12,
288,
2396,
63,
19389,
29,
2030,
63,
19389,
12,
288,
15686,
63,
19389,
29,
10512,
63,
19389,
9,
267,
372,
1499,
339,
347,
485,
14428,
63,
2123,
63,
362,
8,
277,
12,
1245,
304,
267,
15161,
63,
2123,
63,
344,
275,
756,
267,
340,
1245,
14,
362,
360,
56,
13,
47,
16766,
13,
23785,
13,
998,
297,
12548,
13896,
837,
288,
15161,
63,
2123,
63,
344,
275,
1109,
8,
1188,
459,
56,
13,
47,
16766,
13,
23785,
13,
998,
1105,
267,
372,
291,
14,
1813,
459,
1198,
14,
14428,
14,
2123,
2278,
4570,
8,
14428,
63,
2123,
63,
344,
9,
339,
347,
485,
15592,
63,
1000,
63,
362,
8,
277,
12,
6016,
63,
1000,
63,
344,
12,
14400,
63,
1000,
304,
267,
14400,
63,
1000,
63,
2972,
275,
756,
267,
6016,
63,
1000,
275,
488,
267,
340,
6016,
63,
1000,
63,
344,
26,
288,
6016,
63,
1000,
275,
291,
14,
4570,
8,
1198,
63,
1000,
63,
344,
9,
267,
916,
440,
14400,
63,
1000,
26,
288,
6016,
63,
1000,
63,
1580,
275,
291,
14,
1733,
8798,
1865,
534,
4041,
297,
2304,
29,
17,
9,
288,
6016,
63,
1000,
275,
6016,
63,
1000,
63,
1580,
59,
16,
61,
340,
6016,
63,
1000,
63,
1580,
587,
488,
267,
340,
6016,
63,
1000,
26,
288,
14400,
63,
1000,
63,
2972,
275,
6016,
63,
1000,
14,
15592,
63,
1102,
267,
587,
26,
221,
327,
11942,
26,
949,
8486,
288,
14400,
63,
1000,
63,
2972,
275,
14400,
63,
1000,
503,
7249,
14,
888,
14,
362,
360,
15592,
63,
1000,
358,
267,
372,
14400,
63,
1000,
63,
2972,
339,
768,
1246,
14,
1238,
272,
347,
3222,
63,
2123,
8,
277,
12,
1245,
12,
6016,
63,
1000,
63,
344,
29,
403,
12,
14400,
63,
1000,
29,
403,
12,
673,
14400,
63,
719,
29,
403,
12,
14400,
63,
751,
29,
403,
12,
14400,
63,
2060,
29,
403,
12,
673,
14400,
63,
15113,
29,
403,
12,
14400,
63,
1757,
29,
797,
304,
267,
1245,
63,
344,
275,
756,
267,
15161,
63,
2123,
275,
291,
423,
14428,
63,
2123,
63,
362,
8,
1188,
9,
267,
14400,
63,
1000,
63,
2972,
275,
291,
14,
12095,
19050,
15592,
63,
1000,
63,
362,
8,
288,
6016,
63,
1000,
63,
344,
12,
14400,
63,
1000,
12,
267,
776,
267,
862,
26,
288,
1245,
63,
344,
275,
1613,
8,
32602,
13681,
3120,
12,
291,
680,
2254,
63,
2123,
8,
355,
1245,
12,
6016,
63,
1000,
63,
344,
29,
1198,
63,
1000,
63,
344,
12,
355,
14400,
63,
1000,
29,
15592,
63,
1000,
12,
14400,
63,
719,
29,
15592,
63,
719,
12,
355,
14400,
63,
751,
29,
15592,
63,
751,
12,
14400,
63,
2060,
29,
15592,
63,
2060,
12,
355,
14400,
63,
15113,
29,
15592,
63,
15113,
12,
14400,
63,
1757,
29,
15592,
63,
1757,
9,
267,
871,
2186,
465,
325,
26,
288,
340,
15161,
63,
2123,
26,
355,
15161,
63,
2123,
14,
15592,
63,
705,
8,
277,
12,
14400,
63,
1000,
63,
2972,
12,
325,
9,
288,
746,
267,
340,
1245,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
niphlod/pydal
|
pydal/adapters/oracle.py
|
1
|
5716
|
import re
import sys
from .._compat import integer_types, long
from ..helpers.classes import Reference
from .base import SQLAdapter
from . import adapters, with_connection_or_raise
@adapters.register_for('')
class Oracle(SQLAdapter):
dbengine = 'oracle'
drivers = ('cx_Oracle',)
cmd_fix = re.compile(
"[^']*('[^']*'[^']*)*\:(?P<clob>CLOB\('([^']+|'')*'\))")
def _initialize_(self, do_connect):
super(Oracle, self)._initialize_(do_connect)
self.ruri = self.uri.split('://', 1)[1]
if 'threaded' not in self.driver_args:
self.driver_args['threaded'] = True
def connector(self):
return self.driver.connect(self.ruri, **self.driver_args)
def after_connection(self):
self.execute(
"ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';")
self.execute(
"ALTER SESSION SET NLS_TIMESTAMP_FORMAT = " +
"'YYYY-MM-DD HH24:MI:SS';")
def test_connection(self):
self.execute('SELECT 1 FROM DUAL;')
@with_connection_or_raise
def execute(self, *args, **kwargs):
command = self.filter_sql_command(args[0])
i = 1
while True:
m = self.oracle_fix.match(command)
if not m:
break
command = command[:m.start('clob')] + str(i) + \
command[m.end('clob'):]
args.append(m.group('clob')[6:-2].replace("''", "'"))
i += 1
if command[-1:] == ';':
command = command[:-1]
handlers = self._build_handlers_for_execution()
for handler in handlers:
handler.before_execute(command)
rv = self.cursor.execute(command, *args[1:], **kwargs)
for handler in handlers:
handler.after_execute(command)
return rv
def lastrowid(self, table):
sequence_name = table._sequence_name
self.execute('SELECT %s.currval FROM dual;' % sequence_name)
return long(self.cursor.fetchone()[0])
def create_sequence_and_triggers(self, query, table, **args):
tablename = table._rname or table._tablename
id_name = table._id.name
sequence_name = table._sequence_name
trigger_name = table._trigger_name
self.execute(query)
self.execute(
'CREATE SEQUENCE %s START WITH 1 INCREMENT BY 1 NOMAXVALUE ' +
'MINVALUE -1;' % sequence_name)
self.execute(_trigger_sql % dict(
trigger_name=trigger_name, tablename=tablename,
sequence_name=sequence_name,
id=id_name)
)
def fetchall(self):
from ..drivers import cx_Oracle
if any(x[1] == cx_Oracle.LOB or x[1] == cx_Oracle.CLOB
for x in self.cursor.description):
return [tuple(
[(c.read() if type(c) == cx_Oracle.LOB else c) for c in r]
) for r in self.cursor]
else:
return self.cursor.fetchall()
def sqlsafe_table(self, tablename, original_tablename=None):
if original_tablename is not None:
return (
self.dialect.quote_template + ' ' +
self.dialect.quote_template
) % (original_tablename, tablename)
return self.dialect.quote(tablename)
def _build_value_for_insert(self, field, value, r_values):
if field.type is 'text':
r_values[':' + field.sqlsafe_name] = self.expand(value, field.type)
return ':' + field.sqlsafe_name
return self.expand(value, field.type)
def _insert(self, table, fields):
if fields:
r_values = {}
return self.dialect.insert(
table.sqlsafe,
','.join(el[0].sqlsafe_name for el in fields),
','.join(
self._build_value_for_insert(f, v, r_values)
for f, v in fields)
), r_values
return self.dialect.insert_empty(table.sqlsafe), None
def insert(self, table, fields):
query, values = self._insert(table, fields)
try:
if not values:
self.execute(query)
else:
self.execute(query, *values)
except:
e = sys.exc_info()[1]
if hasattr(table, '_on_insert_error'):
return table._on_insert_error(table, fields, e)
raise e
if hasattr(table, '_primarykey'):
pkdict = dict([
(k[0].name, k[1]) for k in fields
if k[0].name in table._primarykey])
if pkdict:
return pkdict
id = self.lastrowid(table)
if hasattr(table, '_primarykey') and len(table._primarykey) == 1:
id = {table._primarykey[0]: id}
if not isinstance(id, integer_types):
return id
rid = Reference(id)
(rid._table, rid._record) = (table, None)
return rid
_trigger_sql = """
CREATE OR REPLACE TRIGGER %(trigger_name)s BEFORE INSERT ON %(tablename)s FOR EACH ROW
DECLARE
curr_val NUMBER;
diff_val NUMBER;
PRAGMA autonomous_transaction;
BEGIN
IF :NEW.%(id)s IS NOT NULL THEN
EXECUTE IMMEDIATE 'SELECT %(sequence_name)s.nextval FROM dual' INTO curr_val;
diff_val := :NEW.%(id)s - curr_val - 1;
IF diff_val != 0 THEN
EXECUTE IMMEDIATE 'alter sequence %(sequence_name)s increment by '|| diff_val;
EXECUTE IMMEDIATE 'SELECT %(sequence_name)s.nextval FROM dual' INTO curr_val;
EXECUTE IMMEDIATE 'alter sequence %(sequence_name)s increment by 1';
END IF;
END IF;
SELECT %(sequence_name)s.nextval INTO :NEW.%(id)s FROM DUAL;
END;"""
|
bsd-3-clause
|
[
646,
295,
199,
646,
984,
199,
504,
1275,
423,
5819,
492,
3000,
63,
1313,
12,
1846,
199,
504,
2508,
7546,
14,
2888,
492,
10944,
199,
504,
1275,
1095,
492,
5385,
10200,
199,
504,
1275,
492,
1503,
12552,
12,
543,
63,
2105,
63,
269,
63,
3730,
199,
199,
32,
21680,
14,
2683,
63,
509,
8355,
199,
533,
15309,
8,
4657,
10200,
304,
272,
1592,
3908,
275,
283,
16404,
7,
272,
19016,
275,
661,
11859,
63,
21202,
9538,
339,
2088,
63,
970,
275,
295,
14,
2014,
8,
267,
298,
4735,
20445,
360,
4735,
20445,
16122,
20445,
3342,
60,
26,
2229,
48,
28,
67,
1191,
30,
35,
9376,
60,
360,
7059,
21899,
5227,
358,
10,
1154,
430,
531,
339,
347,
485,
8489,
2531,
277,
12,
886,
63,
2242,
304,
267,
1613,
8,
21202,
12,
291,
10445,
8489,
2531,
1117,
63,
2242,
9,
267,
291,
14,
82,
2302,
275,
291,
14,
2302,
14,
1294,
6176,
501,
297,
413,
2788,
17,
61,
267,
340,
283,
19710,
7,
440,
315,
291,
14,
3090,
63,
589,
26,
288,
291,
14,
3090,
63,
589,
459,
19710,
418,
275,
715,
339,
347,
13252,
8,
277,
304,
267,
372,
291,
14,
3090,
14,
2242,
8,
277,
14,
82,
2302,
12,
1011,
277,
14,
3090,
63,
589,
9,
339,
347,
2410,
63,
2105,
8,
277,
304,
267,
291,
14,
2526,
8,
288,
298,
19350,
428,
9577,
11543,
653,
5296,
63,
5390,
63,
4807,
275,
283,
15703,
13,
3218,
13,
5745,
26922,
1194,
26,
10709,
26,
2300,
13619,
531,
267,
291,
14,
2526,
8,
288,
298,
19350,
428,
9577,
11543,
653,
5296,
63,
20277,
63,
4807,
275,
298,
435,
288,
3546,
15703,
13,
3218,
13,
5745,
26922,
1194,
26,
10709,
26,
2300,
13619,
531,
339,
347,
511,
63,
2105,
8,
277,
304,
267,
291,
14,
2526,
360,
4859,
413,
4442,
577,
13841,
10784,
339,
768,
1045,
63,
2105,
63,
269,
63,
3730,
272,
347,
5341,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1414,
275,
291,
14,
1541,
63,
3009,
63,
1531,
8,
589,
59,
16,
566,
267,
284,
275,
413,
267,
1830,
715,
26,
288,
333,
275,
291,
14,
16404,
63,
970,
14,
1431,
8,
1531,
9,
288,
340,
440,
333,
26,
355,
2059,
288,
1414,
275,
1414,
1491,
77,
14,
928,
360,
67,
1191,
5440,
435,
620,
8,
73,
9,
435,
971,
355,
1414,
59,
77,
14,
500,
360,
67,
1191,
735,
61,
288,
1249,
14,
740,
8,
77,
14,
923,
360,
67,
1191,
5832,
22,
6809,
18,
1055,
1814,
480,
891,
401,
3546,
2237,
288,
284,
847,
413,
267,
340,
1414,
1988,
17,
2938,
508,
283,
6015,
288,
1414,
275,
1414,
4439,
17,
61,
267,
8297,
275,
291,
423,
1506,
63,
5586,
63,
509,
63,
9416,
342,
267,
367,
3016,
315,
8297,
26,
288,
3016,
14,
5182,
63,
2526,
8,
1531,
9,
267,
4336,
275,
291,
14,
3937,
14,
2526,
8,
1531,
12,
627,
589,
59,
17,
8429,
1011,
958,
9,
267,
367,
3016,
315,
8297,
26,
288,
3016,
14,
4399,
63,
2526,
8,
1531,
9,
267,
372,
4336,
339,
347,
2061,
29450,
8,
277,
12,
1817,
304,
267,
3414,
63,
354,
275,
1817,
423,
4041,
63,
354,
267,
291,
14,
2526,
360,
4859,
450,
83,
14,
9808,
637,
4442,
21164,
8942,
450,
3414,
63,
354,
9,
267,
372,
1846,
8,
277,
14,
3937,
14,
11591,
3430,
16,
566,
339,
347,
1218,
63,
4041,
63,
460,
63,
26328,
8,
277,
12,
1827,
12,
1817,
12,
1011,
589,
304,
267,
20283,
275,
1817,
423,
82,
354,
503,
1817,
423,
10983,
267,
1305,
63,
354,
275,
1817,
423,
344,
14,
354,
267,
3414,
63,
354,
275,
1817,
423,
4041,
63,
354,
267,
6804,
63,
354,
275,
1817,
423,
7631,
63,
354,
267,
291,
14,
2526,
8,
1131,
9,
267,
291,
14,
2526,
8,
288,
283,
8366,
31042,
450,
83,
13910,
1663,
413,
1621,
31431,
6515,
413,
4825,
4283,
7041,
283,
435,
288,
283,
4896,
7041,
446,
17,
8942,
450,
3414,
63,
354,
9,
267,
291,
14,
2526,
1547,
7631,
63,
3009,
450,
1211,
8,
288,
6804,
63,
354,
29,
7631,
63,
354,
12,
20283,
29,
10983,
12,
288,
3414,
63,
354,
29,
4041,
63,
354,
12,
288,
1305,
29,
344,
63,
354,
9,
267,
776,
339,
347,
5267,
452,
8,
277,
304,
267,
687,
2508,
13337,
492,
17280,
63,
21202,
267,
340,
1263,
8,
88,
59,
17,
61,
508,
17280,
63,
21202,
14,
9376,
503,
671,
59,
17,
61,
508,
17280,
63,
21202,
14,
35,
9376,
2049,
367,
671,
315,
291,
14,
3937,
14,
1802,
304,
288,
372,
359,
2960,
8,
355,
3842,
67,
14,
739,
342,
340,
730,
8,
67,
9,
508,
17280,
63,
21202,
14,
9376,
587,
286,
9,
367,
286,
315,
519,
61,
288,
776,
367,
519,
315,
291,
14,
3937,
61,
267,
587,
26,
288,
372,
291,
14,
3937,
14,
10174,
342,
339,
347,
5295,
478,
6504,
63,
1224,
8,
277,
12,
20283,
12,
3379,
63,
10983,
29,
403,
304,
267,
340,
3379,
63,
10983,
365,
440,
488,
26,
288,
372,
334,
355,
291,
14,
11072,
14,
3513,
63,
1160,
435,
283,
283,
435,
355,
291,
14,
11072,
14,
3513,
63,
1160,
288,
776,
450,
334,
5043,
63,
10983,
12,
20283,
9,
267,
372,
291,
14,
11072,
14,
3513,
8,
10983,
9,
339,
347,
485,
1506,
63,
585,
63,
509,
63,
3176,
8,
277,
12,
901,
12,
574,
12,
519,
63,
1459,
304,
267,
340,
901,
14,
466,
365,
283,
505,
356,
288,
519,
63,
1459,
59,
5242,
435,
901,
14,
3526,
478,
6504,
63,
354,
61,
275,
291,
14,
4441,
8,
585,
12,
901,
14,
466,
9,
288,
372,
10871,
435,
901,
14,
3526,
478,
6504,
63,
354,
267,
372,
291,
14,
4441,
8,
585,
12,
901,
14,
466,
9,
339,
347,
485,
3176,
8,
277,
12,
1817,
12,
1504,
304,
267,
340,
1504,
26,
288,
519,
63,
1459,
275,
1052,
288,
372,
291,
14,
11072,
14,
3176,
8,
355,
1817,
14,
3526,
478,
6504,
12,
355,
12814,
904,
8,
352,
59,
16,
1055,
3526,
478,
6504,
63,
354,
367,
579,
315,
1504,
395,
355,
12814,
904,
8,
490,
291,
423,
1506,
63,
585,
63,
509,
63,
3176,
8,
70,
12,
373,
12,
519,
63,
1459,
9,
490
] |
[
295,
199,
646,
984,
199,
504,
1275,
423,
5819,
492,
3000,
63,
1313,
12,
1846,
199,
504,
2508,
7546,
14,
2888,
492,
10944,
199,
504,
1275,
1095,
492,
5385,
10200,
199,
504,
1275,
492,
1503,
12552,
12,
543,
63,
2105,
63,
269,
63,
3730,
199,
199,
32,
21680,
14,
2683,
63,
509,
8355,
199,
533,
15309,
8,
4657,
10200,
304,
272,
1592,
3908,
275,
283,
16404,
7,
272,
19016,
275,
661,
11859,
63,
21202,
9538,
339,
2088,
63,
970,
275,
295,
14,
2014,
8,
267,
298,
4735,
20445,
360,
4735,
20445,
16122,
20445,
3342,
60,
26,
2229,
48,
28,
67,
1191,
30,
35,
9376,
60,
360,
7059,
21899,
5227,
358,
10,
1154,
430,
531,
339,
347,
485,
8489,
2531,
277,
12,
886,
63,
2242,
304,
267,
1613,
8,
21202,
12,
291,
10445,
8489,
2531,
1117,
63,
2242,
9,
267,
291,
14,
82,
2302,
275,
291,
14,
2302,
14,
1294,
6176,
501,
297,
413,
2788,
17,
61,
267,
340,
283,
19710,
7,
440,
315,
291,
14,
3090,
63,
589,
26,
288,
291,
14,
3090,
63,
589,
459,
19710,
418,
275,
715,
339,
347,
13252,
8,
277,
304,
267,
372,
291,
14,
3090,
14,
2242,
8,
277,
14,
82,
2302,
12,
1011,
277,
14,
3090,
63,
589,
9,
339,
347,
2410,
63,
2105,
8,
277,
304,
267,
291,
14,
2526,
8,
288,
298,
19350,
428,
9577,
11543,
653,
5296,
63,
5390,
63,
4807,
275,
283,
15703,
13,
3218,
13,
5745,
26922,
1194,
26,
10709,
26,
2300,
13619,
531,
267,
291,
14,
2526,
8,
288,
298,
19350,
428,
9577,
11543,
653,
5296,
63,
20277,
63,
4807,
275,
298,
435,
288,
3546,
15703,
13,
3218,
13,
5745,
26922,
1194,
26,
10709,
26,
2300,
13619,
531,
339,
347,
511,
63,
2105,
8,
277,
304,
267,
291,
14,
2526,
360,
4859,
413,
4442,
577,
13841,
10784,
339,
768,
1045,
63,
2105,
63,
269,
63,
3730,
272,
347,
5341,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1414,
275,
291,
14,
1541,
63,
3009,
63,
1531,
8,
589,
59,
16,
566,
267,
284,
275,
413,
267,
1830,
715,
26,
288,
333,
275,
291,
14,
16404,
63,
970,
14,
1431,
8,
1531,
9,
288,
340,
440,
333,
26,
355,
2059,
288,
1414,
275,
1414,
1491,
77,
14,
928,
360,
67,
1191,
5440,
435,
620,
8,
73,
9,
435,
971,
355,
1414,
59,
77,
14,
500,
360,
67,
1191,
735,
61,
288,
1249,
14,
740,
8,
77,
14,
923,
360,
67,
1191,
5832,
22,
6809,
18,
1055,
1814,
480,
891,
401,
3546,
2237,
288,
284,
847,
413,
267,
340,
1414,
1988,
17,
2938,
508,
283,
6015,
288,
1414,
275,
1414,
4439,
17,
61,
267,
8297,
275,
291,
423,
1506,
63,
5586,
63,
509,
63,
9416,
342,
267,
367,
3016,
315,
8297,
26,
288,
3016,
14,
5182,
63,
2526,
8,
1531,
9,
267,
4336,
275,
291,
14,
3937,
14,
2526,
8,
1531,
12,
627,
589,
59,
17,
8429,
1011,
958,
9,
267,
367,
3016,
315,
8297,
26,
288,
3016,
14,
4399,
63,
2526,
8,
1531,
9,
267,
372,
4336,
339,
347,
2061,
29450,
8,
277,
12,
1817,
304,
267,
3414,
63,
354,
275,
1817,
423,
4041,
63,
354,
267,
291,
14,
2526,
360,
4859,
450,
83,
14,
9808,
637,
4442,
21164,
8942,
450,
3414,
63,
354,
9,
267,
372,
1846,
8,
277,
14,
3937,
14,
11591,
3430,
16,
566,
339,
347,
1218,
63,
4041,
63,
460,
63,
26328,
8,
277,
12,
1827,
12,
1817,
12,
1011,
589,
304,
267,
20283,
275,
1817,
423,
82,
354,
503,
1817,
423,
10983,
267,
1305,
63,
354,
275,
1817,
423,
344,
14,
354,
267,
3414,
63,
354,
275,
1817,
423,
4041,
63,
354,
267,
6804,
63,
354,
275,
1817,
423,
7631,
63,
354,
267,
291,
14,
2526,
8,
1131,
9,
267,
291,
14,
2526,
8,
288,
283,
8366,
31042,
450,
83,
13910,
1663,
413,
1621,
31431,
6515,
413,
4825,
4283,
7041,
283,
435,
288,
283,
4896,
7041,
446,
17,
8942,
450,
3414,
63,
354,
9,
267,
291,
14,
2526,
1547,
7631,
63,
3009,
450,
1211,
8,
288,
6804,
63,
354,
29,
7631,
63,
354,
12,
20283,
29,
10983,
12,
288,
3414,
63,
354,
29,
4041,
63,
354,
12,
288,
1305,
29,
344,
63,
354,
9,
267,
776,
339,
347,
5267,
452,
8,
277,
304,
267,
687,
2508,
13337,
492,
17280,
63,
21202,
267,
340,
1263,
8,
88,
59,
17,
61,
508,
17280,
63,
21202,
14,
9376,
503,
671,
59,
17,
61,
508,
17280,
63,
21202,
14,
35,
9376,
2049,
367,
671,
315,
291,
14,
3937,
14,
1802,
304,
288,
372,
359,
2960,
8,
355,
3842,
67,
14,
739,
342,
340,
730,
8,
67,
9,
508,
17280,
63,
21202,
14,
9376,
587,
286,
9,
367,
286,
315,
519,
61,
288,
776,
367,
519,
315,
291,
14,
3937,
61,
267,
587,
26,
288,
372,
291,
14,
3937,
14,
10174,
342,
339,
347,
5295,
478,
6504,
63,
1224,
8,
277,
12,
20283,
12,
3379,
63,
10983,
29,
403,
304,
267,
340,
3379,
63,
10983,
365,
440,
488,
26,
288,
372,
334,
355,
291,
14,
11072,
14,
3513,
63,
1160,
435,
283,
283,
435,
355,
291,
14,
11072,
14,
3513,
63,
1160,
288,
776,
450,
334,
5043,
63,
10983,
12,
20283,
9,
267,
372,
291,
14,
11072,
14,
3513,
8,
10983,
9,
339,
347,
485,
1506,
63,
585,
63,
509,
63,
3176,
8,
277,
12,
901,
12,
574,
12,
519,
63,
1459,
304,
267,
340,
901,
14,
466,
365,
283,
505,
356,
288,
519,
63,
1459,
59,
5242,
435,
901,
14,
3526,
478,
6504,
63,
354,
61,
275,
291,
14,
4441,
8,
585,
12,
901,
14,
466,
9,
288,
372,
10871,
435,
901,
14,
3526,
478,
6504,
63,
354,
267,
372,
291,
14,
4441,
8,
585,
12,
901,
14,
466,
9,
339,
347,
485,
3176,
8,
277,
12,
1817,
12,
1504,
304,
267,
340,
1504,
26,
288,
519,
63,
1459,
275,
1052,
288,
372,
291,
14,
11072,
14,
3176,
8,
355,
1817,
14,
3526,
478,
6504,
12,
355,
12814,
904,
8,
352,
59,
16,
1055,
3526,
478,
6504,
63,
354,
367,
579,
315,
1504,
395,
355,
12814,
904,
8,
490,
291,
423,
1506,
63,
585,
63,
509,
63,
3176,
8,
70,
12,
373,
12,
519,
63,
1459,
9,
490,
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,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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
] |
Shaps/ansible
|
lib/ansible/utils/plugin_docs.py
|
28
|
6674
|
# Copyright: (c) 2012, Jan-Piet Mens <jpmens () gmail.com>
# 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
from ansible import constants as C
from ansible.release import __version__ as ansible_version
from ansible.errors import AnsibleError, AnsibleAssertionError
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_native
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSet, MutableSequence
from ansible.parsing.plugin_docs import read_docstring
from ansible.parsing.yaml.loader import AnsibleLoader
from ansible.utils.display import Display
display = Display()
# modules that are ok that they do not have documentation strings
BLACKLIST = {
'MODULE': frozenset(('async_wrapper',)),
'CACHE': frozenset(('base',)),
}
def merge_fragment(target, source):
for key, value in source.items():
if key in target:
# assumes both structures have same type
if isinstance(target[key], MutableMapping):
value.update(target[key])
elif isinstance(target[key], MutableSet):
value.add(target[key])
elif isinstance(target[key], MutableSequence):
value = sorted(frozenset(value + target[key]))
else:
raise Exception("Attempt to extend a documentation fragement, invalid type for %s" % key)
target[key] = value
def add_fragments(doc, filename, fragment_loader):
fragments = doc.pop('extends_documentation_fragment', [])
if isinstance(fragments, string_types):
fragments = [fragments]
unknown_fragments = []
# doc_fragments are allowed to specify a fragment var other than DOCUMENTATION
# with a . separator; this is complicated by collections-hosted doc_fragments that
# use the same separator. Assume it's collection-hosted normally first, try to load
# as-specified. If failure, assume the right-most component is a var, split it off,
# and retry the load.
for fragment_slug in fragments:
fragment_name = fragment_slug
fragment_var = 'DOCUMENTATION'
fragment_class = fragment_loader.get(fragment_name)
if fragment_class is None and '.' in fragment_slug:
splitname = fragment_slug.rsplit('.', 1)
fragment_name = splitname[0]
fragment_var = splitname[1].upper()
fragment_class = fragment_loader.get(fragment_name)
if fragment_class is None:
unknown_fragments.append(fragment_slug)
continue
fragment_yaml = getattr(fragment_class, fragment_var, None)
if fragment_yaml is None:
if fragment_var != 'DOCUMENTATION':
# if it's asking for something specific that's missing, that's an error
unknown_fragments.append(fragment_slug)
continue
else:
fragment_yaml = '{}' # TODO: this is still an error later since we require 'options' below...
fragment = AnsibleLoader(fragment_yaml, file_name=filename).get_single_data()
if 'notes' in fragment:
notes = fragment.pop('notes')
if notes:
if 'notes' not in doc:
doc['notes'] = []
doc['notes'].extend(notes)
if 'seealso' in fragment:
seealso = fragment.pop('seealso')
if seealso:
if 'seealso' not in doc:
doc['seealso'] = []
doc['seealso'].extend(seealso)
if 'options' not in fragment:
raise Exception("missing options in fragment (%s), possibly misformatted?: %s" % (fragment_name, filename))
# ensure options themselves are directly merged
if 'options' in doc:
try:
merge_fragment(doc['options'], fragment.pop('options'))
except Exception as e:
raise AnsibleError("%s options (%s) of unknown type: %s" % (to_native(e), fragment_name, filename))
else:
doc['options'] = fragment.pop('options')
# merge rest of the sections
try:
merge_fragment(doc, fragment)
except Exception as e:
raise AnsibleError("%s (%s) of unknown type: %s" % (to_native(e), fragment_name, filename))
if unknown_fragments:
raise AnsibleError('unknown doc_fragment(s) in file {0}: {1}'.format(filename, to_native(', '.join(unknown_fragments))))
def get_docstring(filename, fragment_loader, verbose=False, ignore_errors=False):
"""
DOCUMENTATION can be extended using documentation fragments loaded by the PluginLoader from the doc_fragments plugins.
"""
data = read_docstring(filename, verbose=verbose, ignore_errors=ignore_errors)
# add fragments to documentation
if data.get('doc', False):
add_fragments(data['doc'], filename, fragment_loader=fragment_loader)
return data['doc'], data['plainexamples'], data['returndocs'], data['metadata']
def get_versioned_doclink(path):
"""
returns a versioned documentation link for the current Ansible major.minor version; used to generate
in-product warning/error links to the configured DOCSITE_ROOT_URL
(eg, https://docs.ansible.com/ansible/2.8/somepath/doc.html)
:param path: relative path to a document under docs/docsite/rst;
:return: absolute URL to the specified doc for the current version of Ansible
"""
path = to_native(path)
try:
base_url = C.config.get_config_value('DOCSITE_ROOT_URL')
if not base_url.endswith('/'):
base_url += '/'
if path.startswith('/'):
path = path[1:]
split_ver = ansible_version.split('.')
if len(split_ver) < 3:
raise RuntimeError('invalid version ({0})'.format(ansible_version))
doc_version = '{0}.{1}'.format(split_ver[0], split_ver[1])
# check to see if it's a X.Y.0 non-rc prerelease or dev release, if so, assume devel (since the X.Y doctree
# isn't published until beta-ish)
if split_ver[2].startswith('0'):
# exclude rc; we should have the X.Y doctree live by rc1
if any((pre in split_ver[2]) for pre in ['a', 'b']) or len(split_ver) > 3 and 'dev' in split_ver[3]:
doc_version = 'devel'
return '{0}{1}/{2}'.format(base_url, doc_version, path)
except Exception as ex:
return '(unable to create versioned doc link for path {0}: {1})'.format(path, to_native(ex))
|
gpl-3.0
|
[
3,
1898,
26,
334,
67,
9,
6029,
12,
17474,
13,
10542,
386,
603,
8764,
665,
11538,
278,
561,
6248,
29712,
14,
957,
30,
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,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
3221,
492,
636,
1023,
363,
465,
3242,
63,
1023,
199,
504,
3242,
14,
2550,
492,
13358,
12,
2622,
14844,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1059,
63,
1313,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
423,
7882,
63,
5819,
492,
29396,
12,
19610,
1084,
12,
19610,
5826,
199,
504,
3242,
14,
11059,
14,
2718,
63,
4757,
492,
1586,
63,
12485,
199,
504,
3242,
14,
11059,
14,
5963,
14,
3422,
492,
2622,
5455,
199,
504,
3242,
14,
1208,
14,
2918,
492,
12175,
199,
199,
2918,
275,
12175,
342,
421,
199,
3,
4621,
626,
787,
4112,
626,
2985,
886,
440,
1172,
3794,
3326,
199,
23113,
4924,
275,
469,
272,
283,
10001,
356,
9522,
4725,
4146,
63,
5029,
16256,
272,
283,
8677,
356,
9522,
4725,
1095,
16256,
199,
93,
421,
199,
318,
5389,
63,
7677,
8,
1375,
12,
1350,
304,
339,
367,
790,
12,
574,
315,
1350,
14,
1744,
837,
267,
340,
790,
315,
1347,
26,
288,
327,
15194,
3865,
13955,
1172,
2011,
730,
288,
340,
1228,
8,
1375,
59,
498,
467,
29396,
304,
355,
574,
14,
873,
8,
1375,
59,
498,
566,
288,
916,
1228,
8,
1375,
59,
498,
467,
19610,
1084,
304,
355,
574,
14,
525,
8,
1375,
59,
498,
566,
288,
916,
1228,
8,
1375,
59,
498,
467,
19610,
5826,
304,
355,
574,
275,
3355,
8,
21362,
8,
585,
435,
1347,
59,
498,
2459,
288,
587,
26,
355,
746,
2186,
480,
23272,
370,
12247,
282,
3794,
28213,
303,
434,
12,
3866,
730,
367,
450,
83,
2,
450,
790,
9,
267,
1347,
59,
498,
61,
275,
574,
421,
199,
318,
1050,
63,
18047,
8,
1301,
12,
1788,
12,
7956,
63,
3422,
304,
339,
21495,
275,
1382,
14,
1935,
360,
11036,
63,
9970,
63,
7677,
297,
3073,
339,
340,
1228,
8,
18047,
12,
1059,
63,
1313,
304,
267,
21495,
275,
359,
18047,
61,
339,
5809,
63,
18047,
275,
942,
339,
327,
1382,
63,
18047,
787,
4370,
370,
4165,
282,
7956,
2729,
1163,
2419,
29970,
2594,
272,
327,
543,
282,
1275,
9432,
27,
642,
365,
23515,
701,
5055,
13,
24127,
1382,
63,
18047,
626,
272,
327,
675,
314,
2011,
9432,
14,
16269,
652,
1159,
3245,
13,
24127,
12252,
1642,
12,
862,
370,
2248,
272,
327,
465,
13,
10085,
14,
982,
5988,
12,
5534,
314,
2451,
13,
2786,
3931,
365,
282,
2729,
12,
3715,
652,
2331,
12,
272,
327,
436,
7269,
314,
2248,
14,
272,
367,
7956,
63,
5464,
315,
21495,
26,
267,
7956,
63,
354,
275,
7956,
63,
5464,
267,
7956,
63,
1391,
275,
283,
8948,
7,
398,
7956,
63,
533,
275,
7956,
63,
3422,
14,
362,
8,
7677,
63,
354,
9,
267,
340,
7956,
63,
533,
365,
488,
436,
7815,
315,
7956,
63,
5464,
26,
288,
3715,
354,
275,
7956,
63,
5464,
14,
13490,
14078,
413,
9,
288,
7956,
63,
354,
275,
3715,
354,
59,
16,
61,
288,
7956,
63,
1391,
275,
3715,
354,
59,
17,
1055,
4142,
342,
288,
7956,
63,
533,
275,
7956,
63,
3422,
14,
362,
8,
7677,
63,
354,
9,
398,
340,
7956,
63,
533,
365,
488,
26,
288,
5809,
63,
18047,
14,
740,
8,
7677,
63,
5464,
9,
288,
1980,
398,
7956,
63,
5963,
275,
2519,
8,
7677,
63,
533,
12,
7956,
63,
1391,
12,
488,
9,
267,
340,
7956,
63,
5963,
365,
488,
26,
288,
340,
7956,
63,
1391,
1137,
283,
8948,
356,
355,
327,
340,
652,
1159,
7198,
316,
367,
6020,
2488,
626,
1159,
4124,
12,
626,
1159,
376,
1125,
355,
5809,
63,
18047,
14,
740,
8,
7677,
63,
5464,
9,
355,
1980,
288,
587,
26,
355,
7956,
63,
5963,
275,
19574,
221,
327,
3254,
26,
642,
365,
5139,
376,
1125,
2945,
3967,
781,
4409,
283,
1419,
7,
5084,
1396,
398,
7956,
275,
2622,
5455,
8,
7677,
63,
5963,
12,
570,
63,
354,
29,
1501,
680,
362,
63,
4780,
63,
576,
342,
398,
340,
283,
5983,
7,
315,
7956,
26,
288,
12681,
275,
7956,
14,
1935,
360,
5983,
358,
288,
340,
12681,
26,
355,
340,
283,
5983,
7,
440,
315,
1382,
26,
490,
1382,
459,
5983,
418,
275,
942,
355,
1382,
459,
5983,
2278,
2880,
8,
5983,
9,
398,
340,
283,
3239,
12344,
7,
315,
7956,
26,
288,
19352,
275,
7956,
14,
1935,
360,
3239,
12344,
358,
288,
340,
19352,
26,
355,
340,
283,
3239,
12344,
7,
440,
315,
1382,
26,
490,
1382,
459,
3239,
12344,
418,
275,
942,
355,
1382,
459,
3239,
12344,
2278,
2880,
8,
3239,
12344,
9,
398,
340,
283,
1419,
7,
440,
315,
7956,
26,
288,
746,
2186,
480,
4752,
1511,
315,
7956,
4366,
83,
395,
12570,
3201,
15317,
31,
26,
450,
83,
2,
450,
334,
7677,
63,
354,
12,
1788,
430,
398,
327,
4868,
1511,
17279,
787,
5370,
9545,
267,
340,
283,
1419,
7,
315,
1382,
26,
288,
862,
26,
355,
5389,
63,
7677,
8,
1301,
459,
1419,
995,
7956,
14,
1935,
360,
1419,
1333,
288,
871,
2186,
465,
325,
26,
355,
746,
13358,
3647,
83,
1511,
4366,
83,
9,
402,
5809,
730,
26,
450,
83,
2,
450,
334,
475,
63,
6106,
8,
69,
395,
7956,
63,
354,
12,
1788,
430,
267,
587,
26,
288,
1382,
459,
1419,
418,
275,
7956,
14,
1935,
360,
1419,
358,
398,
327,
5389,
4618,
402,
314,
10189,
267,
862,
26,
288,
5389,
63,
7677,
8,
1301,
12,
7956,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
13358,
3647,
83,
4366,
83,
9,
402,
5809,
730,
26,
450,
83,
2,
450,
334,
475,
63,
6106,
8,
69,
395,
7956,
63,
354,
12,
1788,
430,
339,
340,
5809,
63,
18047,
26,
267,
746,
13358,
360,
5187,
1382,
63
] |
[
1898,
26,
334,
67,
9,
6029,
12,
17474,
13,
10542,
386,
603,
8764,
665,
11538,
278,
561,
6248,
29712,
14,
957,
30,
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,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
3221,
492,
636,
1023,
363,
465,
3242,
63,
1023,
199,
504,
3242,
14,
2550,
492,
13358,
12,
2622,
14844,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
1059,
63,
1313,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
423,
7882,
63,
5819,
492,
29396,
12,
19610,
1084,
12,
19610,
5826,
199,
504,
3242,
14,
11059,
14,
2718,
63,
4757,
492,
1586,
63,
12485,
199,
504,
3242,
14,
11059,
14,
5963,
14,
3422,
492,
2622,
5455,
199,
504,
3242,
14,
1208,
14,
2918,
492,
12175,
199,
199,
2918,
275,
12175,
342,
421,
199,
3,
4621,
626,
787,
4112,
626,
2985,
886,
440,
1172,
3794,
3326,
199,
23113,
4924,
275,
469,
272,
283,
10001,
356,
9522,
4725,
4146,
63,
5029,
16256,
272,
283,
8677,
356,
9522,
4725,
1095,
16256,
199,
93,
421,
199,
318,
5389,
63,
7677,
8,
1375,
12,
1350,
304,
339,
367,
790,
12,
574,
315,
1350,
14,
1744,
837,
267,
340,
790,
315,
1347,
26,
288,
327,
15194,
3865,
13955,
1172,
2011,
730,
288,
340,
1228,
8,
1375,
59,
498,
467,
29396,
304,
355,
574,
14,
873,
8,
1375,
59,
498,
566,
288,
916,
1228,
8,
1375,
59,
498,
467,
19610,
1084,
304,
355,
574,
14,
525,
8,
1375,
59,
498,
566,
288,
916,
1228,
8,
1375,
59,
498,
467,
19610,
5826,
304,
355,
574,
275,
3355,
8,
21362,
8,
585,
435,
1347,
59,
498,
2459,
288,
587,
26,
355,
746,
2186,
480,
23272,
370,
12247,
282,
3794,
28213,
303,
434,
12,
3866,
730,
367,
450,
83,
2,
450,
790,
9,
267,
1347,
59,
498,
61,
275,
574,
421,
199,
318,
1050,
63,
18047,
8,
1301,
12,
1788,
12,
7956,
63,
3422,
304,
339,
21495,
275,
1382,
14,
1935,
360,
11036,
63,
9970,
63,
7677,
297,
3073,
339,
340,
1228,
8,
18047,
12,
1059,
63,
1313,
304,
267,
21495,
275,
359,
18047,
61,
339,
5809,
63,
18047,
275,
942,
339,
327,
1382,
63,
18047,
787,
4370,
370,
4165,
282,
7956,
2729,
1163,
2419,
29970,
2594,
272,
327,
543,
282,
1275,
9432,
27,
642,
365,
23515,
701,
5055,
13,
24127,
1382,
63,
18047,
626,
272,
327,
675,
314,
2011,
9432,
14,
16269,
652,
1159,
3245,
13,
24127,
12252,
1642,
12,
862,
370,
2248,
272,
327,
465,
13,
10085,
14,
982,
5988,
12,
5534,
314,
2451,
13,
2786,
3931,
365,
282,
2729,
12,
3715,
652,
2331,
12,
272,
327,
436,
7269,
314,
2248,
14,
272,
367,
7956,
63,
5464,
315,
21495,
26,
267,
7956,
63,
354,
275,
7956,
63,
5464,
267,
7956,
63,
1391,
275,
283,
8948,
7,
398,
7956,
63,
533,
275,
7956,
63,
3422,
14,
362,
8,
7677,
63,
354,
9,
267,
340,
7956,
63,
533,
365,
488,
436,
7815,
315,
7956,
63,
5464,
26,
288,
3715,
354,
275,
7956,
63,
5464,
14,
13490,
14078,
413,
9,
288,
7956,
63,
354,
275,
3715,
354,
59,
16,
61,
288,
7956,
63,
1391,
275,
3715,
354,
59,
17,
1055,
4142,
342,
288,
7956,
63,
533,
275,
7956,
63,
3422,
14,
362,
8,
7677,
63,
354,
9,
398,
340,
7956,
63,
533,
365,
488,
26,
288,
5809,
63,
18047,
14,
740,
8,
7677,
63,
5464,
9,
288,
1980,
398,
7956,
63,
5963,
275,
2519,
8,
7677,
63,
533,
12,
7956,
63,
1391,
12,
488,
9,
267,
340,
7956,
63,
5963,
365,
488,
26,
288,
340,
7956,
63,
1391,
1137,
283,
8948,
356,
355,
327,
340,
652,
1159,
7198,
316,
367,
6020,
2488,
626,
1159,
4124,
12,
626,
1159,
376,
1125,
355,
5809,
63,
18047,
14,
740,
8,
7677,
63,
5464,
9,
355,
1980,
288,
587,
26,
355,
7956,
63,
5963,
275,
19574,
221,
327,
3254,
26,
642,
365,
5139,
376,
1125,
2945,
3967,
781,
4409,
283,
1419,
7,
5084,
1396,
398,
7956,
275,
2622,
5455,
8,
7677,
63,
5963,
12,
570,
63,
354,
29,
1501,
680,
362,
63,
4780,
63,
576,
342,
398,
340,
283,
5983,
7,
315,
7956,
26,
288,
12681,
275,
7956,
14,
1935,
360,
5983,
358,
288,
340,
12681,
26,
355,
340,
283,
5983,
7,
440,
315,
1382,
26,
490,
1382,
459,
5983,
418,
275,
942,
355,
1382,
459,
5983,
2278,
2880,
8,
5983,
9,
398,
340,
283,
3239,
12344,
7,
315,
7956,
26,
288,
19352,
275,
7956,
14,
1935,
360,
3239,
12344,
358,
288,
340,
19352,
26,
355,
340,
283,
3239,
12344,
7,
440,
315,
1382,
26,
490,
1382,
459,
3239,
12344,
418,
275,
942,
355,
1382,
459,
3239,
12344,
2278,
2880,
8,
3239,
12344,
9,
398,
340,
283,
1419,
7,
440,
315,
7956,
26,
288,
746,
2186,
480,
4752,
1511,
315,
7956,
4366,
83,
395,
12570,
3201,
15317,
31,
26,
450,
83,
2,
450,
334,
7677,
63,
354,
12,
1788,
430,
398,
327,
4868,
1511,
17279,
787,
5370,
9545,
267,
340,
283,
1419,
7,
315,
1382,
26,
288,
862,
26,
355,
5389,
63,
7677,
8,
1301,
459,
1419,
995,
7956,
14,
1935,
360,
1419,
1333,
288,
871,
2186,
465,
325,
26,
355,
746,
13358,
3647,
83,
1511,
4366,
83,
9,
402,
5809,
730,
26,
450,
83,
2,
450,
334,
475,
63,
6106,
8,
69,
395,
7956,
63,
354,
12,
1788,
430,
267,
587,
26,
288,
1382,
459,
1419,
418,
275,
7956,
14,
1935,
360,
1419,
358,
398,
327,
5389,
4618,
402,
314,
10189,
267,
862,
26,
288,
5389,
63,
7677,
8,
1301,
12,
7956,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
13358,
3647,
83,
4366,
83,
9,
402,
5809,
730,
26,
450,
83,
2,
450,
334,
475,
63,
6106,
8,
69,
395,
7956,
63,
354,
12,
1788,
430,
339,
340,
5809,
63,
18047,
26,
267,
746,
13358,
360,
5187,
1382,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ldong/vim_youcompleteme
|
third_party/requests/requests/packages/charade/langbulgarianmodel.py
|
172
|
13013
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - 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 #########################
# 255: Control characters that usually does not exist in any text
# 254: Carriage/Return
# 253: symbol (punctuation) that does not belong to word
# 252: 0 - 9
# Character Mapping Table:
# this table is modified base on win1251BulgarianCharToOrderMap, so
# only number <64 is sure valid
Latin5_BulgarianCharToOrderMap = (
255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
253, 77, 90, 99,100, 72,109,107,101, 79,185, 81,102, 76, 94, 82, # 40
110,186,108, 91, 74,119, 84, 96,111,187,115,253,253,253,253,253, # 50
253, 65, 69, 70, 66, 63, 68,112,103, 92,194,104, 95, 86, 87, 71, # 60
116,195, 85, 93, 97,113,196,197,198,199,200,253,253,253,253,253, # 70
194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209, # 80
210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225, # 90
81,226,227,228,229,230,105,231,232,233,234,235,236, 45,237,238, # a0
31, 32, 35, 43, 37, 44, 55, 47, 40, 59, 33, 46, 38, 36, 41, 30, # b0
39, 28, 34, 51, 48, 49, 53, 50, 54, 57, 61,239, 67,240, 60, 56, # c0
1, 18, 9, 20, 11, 3, 23, 15, 2, 26, 12, 10, 14, 6, 4, 13, # d0
7, 8, 5, 19, 29, 25, 22, 21, 27, 24, 17, 75, 52,241, 42, 16, # e0
62,242,243,244, 58,245, 98,246,247,248,249,250,251, 91,252,253, # f0
)
win1251BulgarianCharToOrderMap = (
255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
253, 77, 90, 99,100, 72,109,107,101, 79,185, 81,102, 76, 94, 82, # 40
110,186,108, 91, 74,119, 84, 96,111,187,115,253,253,253,253,253, # 50
253, 65, 69, 70, 66, 63, 68,112,103, 92,194,104, 95, 86, 87, 71, # 60
116,195, 85, 93, 97,113,196,197,198,199,200,253,253,253,253,253, # 70
206,207,208,209,210,211,212,213,120,214,215,216,217,218,219,220, # 80
221, 78, 64, 83,121, 98,117,105,222,223,224,225,226,227,228,229, # 90
88,230,231,232,233,122, 89,106,234,235,236,237,238, 45,239,240, # a0
73, 80,118,114,241,242,243,244,245, 62, 58,246,247,248,249,250, # b0
31, 32, 35, 43, 37, 44, 55, 47, 40, 59, 33, 46, 38, 36, 41, 30, # c0
39, 28, 34, 51, 48, 49, 53, 50, 54, 57, 61,251, 67,252, 60, 56, # d0
1, 18, 9, 20, 11, 3, 23, 15, 2, 26, 12, 10, 14, 6, 4, 13, # e0
7, 8, 5, 19, 29, 25, 22, 21, 27, 24, 17, 75, 52,253, 42, 16, # f0
)
# Model Table:
# total sequences: 100%
# first 512 sequences: 96.9392%
# first 1024 sequences:3.0618%
# rest sequences: 0.2992%
# negative sequences: 0.0020%
BulgarianLangModel = (
0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,2,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,3,2,2,3,2,2,1,2,2,
3,1,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,3,3,3,3,3,3,3,3,0,3,0,1,
0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,2,3,3,3,3,3,3,3,3,0,3,1,0,
0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
3,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,1,3,2,3,3,3,3,3,3,3,3,0,3,0,0,
0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3,2,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,1,3,2,3,3,3,3,3,3,3,3,0,3,0,0,
0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,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,
1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,2,0,0,2,0,1,0,0,1,0,0,1,
1,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,
1,1,1,1,1,1,1,2,0,0,0,0,0,0,2,1,0,1,1,0,0,1,1,1,0,1,0,0,0,0,0,0,
2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,0,1,1,1,1,1,0,1,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
)
Latin5BulgarianModel = {
'charToOrderMap': Latin5_BulgarianCharToOrderMap,
'precedenceMatrix': BulgarianLangModel,
'mTypicalPositiveRatio': 0.969392,
'keepEnglishLetter': False,
'charsetName': "ISO-8859-5"
}
Win1251BulgarianModel = {
'charToOrderMap': win1251BulgarianCharToOrderMap,
'precedenceMatrix': BulgarianLangModel,
'mTypicalPositiveRatio': 0.969392,
'keepEnglishLetter': False,
'charsetName': "windows-1251"
}
# flake8: noqa
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
202,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
202,
199,
3,
202,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
202,
199,
3,
20433,
18686,
11098,
14,
202,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
202,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
202,
199,
3,
202,
199,
3,
17636,
8,
83,
304,
202,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
202,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
202,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
202,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
202,
199,
3,
11315,
13,
10067,
221,
8217,
202,
199,
19054,
7729,
5113,
8068,
21186,
2999,
199,
3,
5450,
26,
8612,
4110,
626,
9987,
1630,
440,
2187,
315,
1263,
1318,
202,
199,
3,
22540,
26,
14243,
25220,
15,
1767,
202,
199,
3,
26727,
26,
5272,
334,
25181,
9,
626,
1630,
440,
13511,
370,
4349,
202,
199,
3,
27210,
26,
378,
446,
1749,
2999,
199,
3,
17660,
12340,
6957,
26,
202,
199,
3,
642,
1817,
365,
6042,
1300,
641,
4747,
21381,
34,
27092,
15289,
24516,
12,
880,
202,
199,
3,
1454,
1329,
665,
772,
365,
3238,
1686,
2999,
199,
27317,
21,
63,
34,
27092,
15289,
24516,
275,
334,
202,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
202,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
202,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
202,
199,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
4233,
202,
199,
3781,
12,
8375,
12,
9137,
12,
8806,
12,
1960,
12,
15323,
12,
6996,
12,
7555,
12,
4893,
12,
13734,
12,
10233,
12,
19071,
12,
7759,
12,
14646,
12,
18729,
12,
18051,
12,
221,
327,
6335,
202,
199,
6019,
12,
11656,
12,
8079,
12,
21358,
12,
9720,
12,
7119,
12,
8264,
12,
15580,
12,
6673,
12,
11775,
12,
7680,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
202,
199,
3781,
12,
11738,
12,
14610,
12,
10045,
12,
14157,
12,
13668,
12,
10851,
12,
6094,
12,
8845,
12,
20140,
12,
10860,
12,
6785,
12,
16102,
12,
10300,
12,
10513,
12,
17245,
12,
221,
327,
5212,
202,
199,
7524,
12,
11874,
12,
16412,
12,
18969,
12,
15997,
12,
9225,
12,
10800,
12,
11165,
12,
10905,
12,
7155,
12,
1840,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
202,
199,
10860,
12,
11874,
12,
10800,
12,
11165,
12,
10905,
12,
7155,
12,
1840,
12,
1797,
12,
4999,
12,
11341,
12,
6686,
12,
10629,
12,
11089,
12,
10744,
12,
10630,
12,
11303,
12,
221,
327,
5939,
202,
199,
12725,
12,
12832,
12,
11722,
12,
14271,
12,
6886,
12,
7842,
12,
9669,
12,
9335,
12,
9252,
12,
8867,
12,
11174,
12,
11564,
12,
9485,
12,
11583,
12,
8731,
12,
10932,
12,
221,
327,
9137,
1223,
19071,
12,
11085,
12,
11385,
12,
12048,
12,
11182,
12,
9687,
12,
7320,
12,
11921,
12,
8001,
12,
10034,
12,
5533,
12,
8276,
12,
10008,
12,
10416,
12,
10638,
12,
12332,
12,
221,
327,
282,
16,
1223,
7105,
12,
4337,
12,
8685,
12,
11851,
12,
6877,
12,
10868,
12,
12766,
12,
10954,
12,
6335,
12,
8155,
12,
9404,
12,
12426,
12,
10448,
12,
8780,
12,
13385,
12,
4233,
12,
221,
327,
330,
16,
1223,
10551,
12,
7294,
12,
8177,
12,
8026,
12,
9615,
12,
12260,
12,
13564,
12,
5238,
12,
13470,
12,
12699,
12,
17017,
12,
9803,
12,
13296,
12,
9873,
12,
5212,
12,
12001,
12,
221,
327,
286,
16,
10292,
413,
12,
6155,
12,
221,
1749,
12,
3388,
12,
4119,
12,
221,
650,
12,
6546,
12,
4114,
12,
221,
499,
12,
7875,
12,
3144,
12,
1616,
12,
4329,
12,
221,
1227,
12,
221,
841,
12,
4944,
12,
221,
327,
366,
16,
10292,
1520,
12,
221,
1695,
12,
221,
959,
12,
5851,
12,
7349,
12,
5661,
12,
6928,
12,
7829,
12,
8087,
12,
5504,
12,
5557,
12,
13098,
12,
14589,
12,
13571,
12,
5685,
12,
3193,
12,
221,
327,
325,
16,
1223,
16202,
12,
13212,
12,
13440,
12,
11603,
12,
13713,
12,
11677,
12,
16096,
12,
11440,
12,
11717,
12,
11242,
12,
11032,
12,
7991,
12,
12140,
12,
21358,
12,
6390,
12,
3781,
12,
221,
327,
289,
16,
202,
199,
9,
2999,
199,
2676,
21381,
34,
27092,
15289,
24516,
275,
334,
202,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
202,
199,
2299,
12,
2299
] |
[
16427,
5113,
8068,
11945,
202,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
202,
199,
3,
202,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
202,
199,
3,
20433,
18686,
11098,
14,
202,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
202,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
202,
199,
3,
202,
199,
3,
17636,
8,
83,
304,
202,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
202,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
202,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
202,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
202,
199,
3,
11315,
13,
10067,
221,
8217,
202,
199,
19054,
7729,
5113,
8068,
21186,
2999,
199,
3,
5450,
26,
8612,
4110,
626,
9987,
1630,
440,
2187,
315,
1263,
1318,
202,
199,
3,
22540,
26,
14243,
25220,
15,
1767,
202,
199,
3,
26727,
26,
5272,
334,
25181,
9,
626,
1630,
440,
13511,
370,
4349,
202,
199,
3,
27210,
26,
378,
446,
1749,
2999,
199,
3,
17660,
12340,
6957,
26,
202,
199,
3,
642,
1817,
365,
6042,
1300,
641,
4747,
21381,
34,
27092,
15289,
24516,
12,
880,
202,
199,
3,
1454,
1329,
665,
772,
365,
3238,
1686,
2999,
199,
27317,
21,
63,
34,
27092,
15289,
24516,
275,
334,
202,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
202,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
202,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
202,
199,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
4233,
202,
199,
3781,
12,
8375,
12,
9137,
12,
8806,
12,
1960,
12,
15323,
12,
6996,
12,
7555,
12,
4893,
12,
13734,
12,
10233,
12,
19071,
12,
7759,
12,
14646,
12,
18729,
12,
18051,
12,
221,
327,
6335,
202,
199,
6019,
12,
11656,
12,
8079,
12,
21358,
12,
9720,
12,
7119,
12,
8264,
12,
15580,
12,
6673,
12,
11775,
12,
7680,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
202,
199,
3781,
12,
11738,
12,
14610,
12,
10045,
12,
14157,
12,
13668,
12,
10851,
12,
6094,
12,
8845,
12,
20140,
12,
10860,
12,
6785,
12,
16102,
12,
10300,
12,
10513,
12,
17245,
12,
221,
327,
5212,
202,
199,
7524,
12,
11874,
12,
16412,
12,
18969,
12,
15997,
12,
9225,
12,
10800,
12,
11165,
12,
10905,
12,
7155,
12,
1840,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
202,
199,
10860,
12,
11874,
12,
10800,
12,
11165,
12,
10905,
12,
7155,
12,
1840,
12,
1797,
12,
4999,
12,
11341,
12,
6686,
12,
10629,
12,
11089,
12,
10744,
12,
10630,
12,
11303,
12,
221,
327,
5939,
202,
199,
12725,
12,
12832,
12,
11722,
12,
14271,
12,
6886,
12,
7842,
12,
9669,
12,
9335,
12,
9252,
12,
8867,
12,
11174,
12,
11564,
12,
9485,
12,
11583,
12,
8731,
12,
10932,
12,
221,
327,
9137,
1223,
19071,
12,
11085,
12,
11385,
12,
12048,
12,
11182,
12,
9687,
12,
7320,
12,
11921,
12,
8001,
12,
10034,
12,
5533,
12,
8276,
12,
10008,
12,
10416,
12,
10638,
12,
12332,
12,
221,
327,
282,
16,
1223,
7105,
12,
4337,
12,
8685,
12,
11851,
12,
6877,
12,
10868,
12,
12766,
12,
10954,
12,
6335,
12,
8155,
12,
9404,
12,
12426,
12,
10448,
12,
8780,
12,
13385,
12,
4233,
12,
221,
327,
330,
16,
1223,
10551,
12,
7294,
12,
8177,
12,
8026,
12,
9615,
12,
12260,
12,
13564,
12,
5238,
12,
13470,
12,
12699,
12,
17017,
12,
9803,
12,
13296,
12,
9873,
12,
5212,
12,
12001,
12,
221,
327,
286,
16,
10292,
413,
12,
6155,
12,
221,
1749,
12,
3388,
12,
4119,
12,
221,
650,
12,
6546,
12,
4114,
12,
221,
499,
12,
7875,
12,
3144,
12,
1616,
12,
4329,
12,
221,
1227,
12,
221,
841,
12,
4944,
12,
221,
327,
366,
16,
10292,
1520,
12,
221,
1695,
12,
221,
959,
12,
5851,
12,
7349,
12,
5661,
12,
6928,
12,
7829,
12,
8087,
12,
5504,
12,
5557,
12,
13098,
12,
14589,
12,
13571,
12,
5685,
12,
3193,
12,
221,
327,
325,
16,
1223,
16202,
12,
13212,
12,
13440,
12,
11603,
12,
13713,
12,
11677,
12,
16096,
12,
11440,
12,
11717,
12,
11242,
12,
11032,
12,
7991,
12,
12140,
12,
21358,
12,
6390,
12,
3781,
12,
221,
327,
289,
16,
202,
199,
9,
2999,
199,
2676,
21381,
34,
27092,
15289,
24516,
275,
334,
202,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
202,
199,
2299,
12,
2299,
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
] |
jamiefolsom/edx-platform
|
lms/djangoapps/discussion_api/permissions.py
|
79
|
2651
|
"""
Discussion API permission logic
"""
from lms.lib.comment_client.comment import Comment
from lms.lib.comment_client.thread import Thread
def _is_author(cc_content, context):
"""
Return True if the requester authored the given content, False otherwise
"""
return context["cc_requester"]["id"] == cc_content["user_id"]
def _is_author_or_privileged(cc_content, context):
"""
Return True if the requester authored the given content or is a privileged
user, False otherwise
"""
return context["is_requester_privileged"] or _is_author(cc_content, context)
NON_UPDATABLE_THREAD_FIELDS = {"course_id"}
NON_UPDATABLE_COMMENT_FIELDS = {"thread_id", "parent_id"}
def get_initializable_thread_fields(context):
"""
Return the set of fields that the requester can initialize for a thread
Any field that is editable by the author should also be initializable.
"""
ret = get_editable_fields(
Thread(user_id=context["cc_requester"]["id"], type="thread"),
context
)
ret |= NON_UPDATABLE_THREAD_FIELDS
return ret
def get_initializable_comment_fields(context): # pylint: disable=invalid-name
"""
Return the set of fields that the requester can initialize for a comment
Any field that is editable by the author should also be initializable.
"""
ret = get_editable_fields(
Comment(user_id=context["cc_requester"]["id"], type="comment"),
context
)
ret |= NON_UPDATABLE_COMMENT_FIELDS
return ret
def get_editable_fields(cc_content, context):
"""
Return the set of fields that the requester can edit on the given content
"""
# Shared fields
ret = {"abuse_flagged", "voted"}
if _is_author_or_privileged(cc_content, context):
ret |= {"raw_body"}
# Thread fields
if cc_content["type"] == "thread":
ret |= {"following"}
if _is_author_or_privileged(cc_content, context):
ret |= {"topic_id", "type", "title"}
if context["is_requester_privileged"] and context["course"].is_cohorted:
ret |= {"group_id"}
# Comment fields
if (
cc_content["type"] == "comment" and (
context["is_requester_privileged"] or (
_is_author(context["thread"], context) and
context["thread"]["thread_type"] == "question"
)
)
):
ret |= {"endorsed"}
return ret
def can_delete(cc_content, context):
"""
Return True if the requester can delete the given content, False otherwise
"""
return _is_author_or_privileged(cc_content, context)
|
agpl-3.0
|
[
624,
199,
31410,
3261,
4983,
9661,
199,
624,
199,
504,
21577,
14,
773,
14,
3349,
63,
1258,
14,
3349,
492,
6819,
199,
504,
21577,
14,
773,
14,
3349,
63,
1258,
14,
2671,
492,
11086,
421,
199,
318,
485,
374,
63,
2502,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
715,
340,
314,
295,
18246,
1790,
2908,
314,
1627,
1564,
12,
756,
4257,
272,
408,
272,
372,
1067,
905,
2055,
63,
24199,
6611,
344,
937,
508,
7429,
63,
1317,
905,
751,
63,
344,
937,
421,
199,
318,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
715,
340,
314,
295,
18246,
1790,
2908,
314,
1627,
1564,
503,
365,
282,
1979,
21744,
272,
922,
12,
756,
4257,
272,
408,
272,
372,
1067,
905,
374,
63,
24199,
63,
27672,
937,
503,
485,
374,
63,
2502,
8,
2055,
63,
1317,
12,
1067,
9,
421,
199,
13887,
63,
23612,
2617,
63,
16103,
63,
12767,
275,
2420,
1972,
63,
344,
3570,
199,
13887,
63,
23612,
2617,
63,
10973,
63,
12767,
275,
2420,
2671,
63,
344,
401,
298,
1708,
63,
344,
3570,
421,
199,
318,
664,
63,
2747,
14065,
63,
2671,
63,
955,
8,
1100,
304,
272,
408,
272,
1432,
314,
663,
402,
1504,
626,
314,
295,
18246,
883,
8265,
367,
282,
2462,
339,
6184,
901,
626,
365,
14783,
701,
314,
4132,
1077,
2597,
506,
2536,
14065,
14,
272,
408,
272,
2203,
275,
664,
63,
10820,
63,
955,
8,
267,
11086,
8,
751,
63,
344,
29,
1100,
905,
2055,
63,
24199,
6611,
344,
2255,
730,
628,
2671,
1288,
267,
1067,
272,
776,
272,
2203,
8901,
11214,
63,
23612,
2617,
63,
16103,
63,
12767,
272,
372,
2203,
421,
199,
318,
664,
63,
2747,
14065,
63,
3349,
63,
955,
8,
1100,
304,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
408,
272,
1432,
314,
663,
402,
1504,
626,
314,
295,
18246,
883,
8265,
367,
282,
3721,
339,
6184,
901,
626,
365,
14783,
701,
314,
4132,
1077,
2597,
506,
2536,
14065,
14,
272,
408,
272,
2203,
275,
664,
63,
10820,
63,
955,
8,
267,
6819,
8,
751,
63,
344,
29,
1100,
905,
2055,
63,
24199,
6611,
344,
2255,
730,
628,
3349,
1288,
267,
1067,
272,
776,
272,
2203,
8901,
11214,
63,
23612,
2617,
63,
10973,
63,
12767,
272,
372,
2203,
421,
199,
318,
664,
63,
10820,
63,
955,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
314,
663,
402,
1504,
626,
314,
295,
18246,
883,
5283,
641,
314,
1627,
1564,
272,
408,
272,
327,
23752,
1504,
272,
2203,
275,
2420,
371,
1180,
63,
4173,
3046,
401,
298,
2392,
471,
3570,
272,
340,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
304,
267,
2203,
8901,
2420,
1773,
63,
2030,
3570,
339,
327,
11086,
1504,
272,
340,
7429,
63,
1317,
905,
466,
937,
508,
298,
2671,
582,
267,
2203,
8901,
2420,
21589,
3570,
267,
340,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
304,
288,
2203,
8901,
2420,
5746,
63,
344,
401,
298,
466,
401,
298,
1213,
3570,
267,
340,
1067,
905,
374,
63,
24199,
63,
27672,
937,
436,
1067,
905,
1972,
4140,
374,
63,
29795,
26,
288,
2203,
8901,
2420,
923,
63,
344,
3570,
339,
327,
6819,
1504,
272,
340,
334,
288,
7429,
63,
1317,
905,
466,
937,
508,
298,
3349,
2,
436,
334,
355,
1067,
905,
374,
63,
24199,
63,
27672,
937,
503,
334,
490,
485,
374,
63,
2502,
8,
1100,
905,
2671,
2255,
1067,
9,
436,
490,
1067,
905,
2671,
6611,
2671,
63,
466,
937,
508,
298,
4790,
2,
355,
776,
288,
776,
272,
3461,
267,
2203,
8901,
2420,
7454,
939,
3570,
339,
372,
2203,
421,
199,
318,
883,
63,
1807,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
715,
340,
314,
295,
18246,
883,
3145,
314,
1627,
1564,
12,
756,
4257,
272,
408,
272,
372,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
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
] |
[
199,
31410,
3261,
4983,
9661,
199,
624,
199,
504,
21577,
14,
773,
14,
3349,
63,
1258,
14,
3349,
492,
6819,
199,
504,
21577,
14,
773,
14,
3349,
63,
1258,
14,
2671,
492,
11086,
421,
199,
318,
485,
374,
63,
2502,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
715,
340,
314,
295,
18246,
1790,
2908,
314,
1627,
1564,
12,
756,
4257,
272,
408,
272,
372,
1067,
905,
2055,
63,
24199,
6611,
344,
937,
508,
7429,
63,
1317,
905,
751,
63,
344,
937,
421,
199,
318,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
715,
340,
314,
295,
18246,
1790,
2908,
314,
1627,
1564,
503,
365,
282,
1979,
21744,
272,
922,
12,
756,
4257,
272,
408,
272,
372,
1067,
905,
374,
63,
24199,
63,
27672,
937,
503,
485,
374,
63,
2502,
8,
2055,
63,
1317,
12,
1067,
9,
421,
199,
13887,
63,
23612,
2617,
63,
16103,
63,
12767,
275,
2420,
1972,
63,
344,
3570,
199,
13887,
63,
23612,
2617,
63,
10973,
63,
12767,
275,
2420,
2671,
63,
344,
401,
298,
1708,
63,
344,
3570,
421,
199,
318,
664,
63,
2747,
14065,
63,
2671,
63,
955,
8,
1100,
304,
272,
408,
272,
1432,
314,
663,
402,
1504,
626,
314,
295,
18246,
883,
8265,
367,
282,
2462,
339,
6184,
901,
626,
365,
14783,
701,
314,
4132,
1077,
2597,
506,
2536,
14065,
14,
272,
408,
272,
2203,
275,
664,
63,
10820,
63,
955,
8,
267,
11086,
8,
751,
63,
344,
29,
1100,
905,
2055,
63,
24199,
6611,
344,
2255,
730,
628,
2671,
1288,
267,
1067,
272,
776,
272,
2203,
8901,
11214,
63,
23612,
2617,
63,
16103,
63,
12767,
272,
372,
2203,
421,
199,
318,
664,
63,
2747,
14065,
63,
3349,
63,
955,
8,
1100,
304,
221,
327,
4287,
26,
3507,
29,
3197,
13,
354,
272,
408,
272,
1432,
314,
663,
402,
1504,
626,
314,
295,
18246,
883,
8265,
367,
282,
3721,
339,
6184,
901,
626,
365,
14783,
701,
314,
4132,
1077,
2597,
506,
2536,
14065,
14,
272,
408,
272,
2203,
275,
664,
63,
10820,
63,
955,
8,
267,
6819,
8,
751,
63,
344,
29,
1100,
905,
2055,
63,
24199,
6611,
344,
2255,
730,
628,
3349,
1288,
267,
1067,
272,
776,
272,
2203,
8901,
11214,
63,
23612,
2617,
63,
10973,
63,
12767,
272,
372,
2203,
421,
199,
318,
664,
63,
10820,
63,
955,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
314,
663,
402,
1504,
626,
314,
295,
18246,
883,
5283,
641,
314,
1627,
1564,
272,
408,
272,
327,
23752,
1504,
272,
2203,
275,
2420,
371,
1180,
63,
4173,
3046,
401,
298,
2392,
471,
3570,
272,
340,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
304,
267,
2203,
8901,
2420,
1773,
63,
2030,
3570,
339,
327,
11086,
1504,
272,
340,
7429,
63,
1317,
905,
466,
937,
508,
298,
2671,
582,
267,
2203,
8901,
2420,
21589,
3570,
267,
340,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
304,
288,
2203,
8901,
2420,
5746,
63,
344,
401,
298,
466,
401,
298,
1213,
3570,
267,
340,
1067,
905,
374,
63,
24199,
63,
27672,
937,
436,
1067,
905,
1972,
4140,
374,
63,
29795,
26,
288,
2203,
8901,
2420,
923,
63,
344,
3570,
339,
327,
6819,
1504,
272,
340,
334,
288,
7429,
63,
1317,
905,
466,
937,
508,
298,
3349,
2,
436,
334,
355,
1067,
905,
374,
63,
24199,
63,
27672,
937,
503,
334,
490,
485,
374,
63,
2502,
8,
1100,
905,
2671,
2255,
1067,
9,
436,
490,
1067,
905,
2671,
6611,
2671,
63,
466,
937,
508,
298,
4790,
2,
355,
776,
288,
776,
272,
3461,
267,
2203,
8901,
2420,
7454,
939,
3570,
339,
372,
2203,
421,
199,
318,
883,
63,
1807,
8,
2055,
63,
1317,
12,
1067,
304,
272,
408,
272,
1432,
715,
340,
314,
295,
18246,
883,
3145,
314,
1627,
1564,
12,
756,
4257,
272,
408,
272,
372,
485,
374,
63,
2502,
63,
269,
63,
27672,
8,
2055,
63,
1317,
12,
1067,
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,
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,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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
] |
whbruce/upm
|
tests/check_examplenames.py
|
12
|
2583
|
#!/usr/bin/python
import unittest
import re, fnmatch, os, sys
# Example name map
sampleMappingFile = '../doxy/samples.mapping.txt'
# Example directories
sampledir = {}
sampledir['cxx'] = '../examples/c++/'
sampledir['java'] = '../examples/java/'
sampledir['js'] = '../examples/javascript/'
sampledir['py'] = '../examples/python/'
# Default to all targets
test_targets = ['java', 'js', 'py']
class SampleNames(unittest.TestCase):
def test_existing_samples(self):
# Dictionary for missing examples
missing = {}
# If test target/s were provided on the command line, use them
if len(self.argv) > 0:
test_targets = self.argv
# Iterate over the mapping file and check for per-language examples
with open (sampleMappingFile, "r") as f:
for line in f:
matched = {}
fullpaths = {}
# Split out the example names per target
for target in test_targets:
match = re.match('(.*.cxx).*\t(\S+.%s)' % target, line)
if match:
matched['cxx'] = match.group(1)
matched[target] = match.group(2)
# Need at least two target files to check
if len(matched) < 2: continue
# Fail if NO .cxx file to compare against
self.assertTrue('cxx' in matched)
# Update the full path to each sample file
for k,v in matched.items():
fullpaths[k] = os.path.join(sampledir[k], v)
# Use cxx base filename as testname
basename = os.path.splitext(matched['cxx'])[0]
missing[basename] = []
# Check for all example filenames
for target, filename in fullpaths.items():
if not os.path.exists(filename):
missing[basename] += [os.path.split(filename)[-1]]
# Prune out tests with no missing files
for k in missing.keys():
if len(missing[k]) == 0: del missing[k]
# Print sorted missing example filenames
sk_missing = missing.keys()
sk_missing.sort()
self.assertEqual(len(missing), 0,
'\n\nMissing examples:\n' +
'\n'.join(['%s: %s' % (k, ', '.join(missing[k])) for k in sk_missing]))
if __name__ == '__main__':
# Allow passing from argv
SampleNames.argv = []
for arg in sys.argv[1:]:
SampleNames.argv.append(sys.argv.pop())
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
646,
2882,
199,
646,
295,
12,
15951,
12,
747,
12,
984,
199,
199,
3,
5679,
536,
2341,
199,
3271,
7674,
1173,
275,
20644,
1117,
1702,
15,
3356,
14,
4745,
14,
2424,
7,
199,
199,
3,
5679,
6602,
199,
3271,
694,
275,
1052,
199,
3271,
694,
459,
9634,
418,
275,
20644,
8589,
15,
67,
4176,
4805,
199,
3271,
694,
459,
6138,
418,
275,
20644,
8589,
15,
6138,
4805,
199,
3271,
694,
459,
3596,
418,
275,
20644,
8589,
15,
9554,
4805,
199,
3271,
694,
459,
647,
418,
275,
20644,
8589,
15,
1548,
4805,
199,
199,
3,
3758,
370,
1006,
4545,
199,
396,
63,
4684,
275,
788,
6138,
297,
283,
3596,
297,
283,
647,
418,
199,
199,
533,
15227,
5866,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
5952,
63,
3356,
8,
277,
304,
267,
327,
11932,
367,
4124,
7251,
267,
4124,
275,
1052,
398,
327,
982,
511,
1347,
15,
83,
4898,
2741,
641,
314,
1414,
1004,
12,
675,
3062,
267,
340,
822,
8,
277,
14,
3020,
9,
690,
378,
26,
1779,
511,
63,
4684,
275,
291,
14,
3020,
398,
327,
23989,
1806,
314,
4412,
570,
436,
1104,
367,
1126,
13,
3671,
7251,
267,
543,
1551,
334,
3271,
7674,
1173,
12,
298,
82,
531,
465,
289,
26,
288,
367,
1004,
315,
289,
26,
355,
7838,
275,
1052,
355,
2615,
3771,
275,
1052,
355,
327,
11740,
734,
314,
2893,
1561,
1126,
1347,
355,
367,
1347,
315,
511,
63,
4684,
26,
490,
1336,
275,
295,
14,
1431,
14097,
2795,
14,
9634,
680,
7590,
84,
2961,
51,
11,
4111,
83,
3171,
450,
1347,
12,
1004,
9,
490,
340,
1336,
26,
717,
7838,
459,
9634,
418,
275,
1336,
14,
923,
8,
17,
9,
717,
7838,
59,
1375,
61,
275,
1336,
14,
923,
8,
18,
9,
2234,
327,
14012,
737,
5210,
2877,
1347,
1584,
370,
1104,
355,
340,
822,
8,
10151,
9,
665,
499,
26,
1980,
2234,
327,
12176,
340,
4825,
1275,
9634,
570,
370,
6540,
6169,
355,
291,
14,
1815,
360,
9634,
7,
315,
7838,
9,
2234,
327,
6162,
314,
2615,
931,
370,
1924,
2690,
570,
355,
367,
1022,
12,
86,
315,
7838,
14,
1744,
837,
490,
2615,
3771,
59,
75,
61,
275,
747,
14,
515,
14,
904,
8,
3271,
694,
59,
75,
467,
373,
9,
2234,
327,
3645,
17327,
1300,
1788,
465,
511,
354,
355,
9593,
275,
747,
14,
515,
14,
7973,
8,
10151,
459,
9634,
25945,
16,
61,
2234,
4124,
59,
4846,
61,
275,
942,
2234,
327,
2670,
367,
1006,
2893,
6203,
355,
367,
1347,
12,
1788,
315,
2615,
3771,
14,
1744,
837,
490,
340,
440,
747,
14,
515,
14,
2444,
8,
1501,
304,
717,
4124,
59,
4846,
61,
847,
359,
736,
14,
515,
14,
1294,
8,
1501,
15786,
17,
2677,
398,
327,
510,
14780,
734,
2295,
543,
949,
4124,
1584,
267,
367,
1022,
315,
4124,
14,
1612,
837,
288,
340,
822,
8,
4752,
59,
75,
566,
508,
378,
26,
2150,
4124,
59,
75,
61,
398,
327,
9101,
3355,
4124,
2893,
6203,
267,
2386,
63,
4752,
275,
4124,
14,
1612,
342,
267,
2386,
63,
4752,
14,
3191,
342,
267,
291,
14,
629,
8,
552,
8,
4752,
395,
378,
12,
355,
1557,
78,
60,
78,
7718,
7251,
3427,
78,
7,
435,
355,
1557,
78,
1370,
904,
26861,
83,
26,
450,
83,
7,
450,
334,
75,
12,
1656,
1987,
904,
8,
4752,
59,
75,
2459,
367,
1022,
315,
2386,
63,
4752,
2459,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
9812,
9476,
687,
9238,
272,
15227,
5866,
14,
3020,
275,
942,
272,
367,
1680,
315,
984,
14,
3020,
59,
17,
10688,
267,
15227,
5866,
14,
3020,
14,
740,
8,
1274,
14,
3020,
14,
1935,
1012,
272,
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,
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,
646,
2882,
199,
646,
295,
12,
15951,
12,
747,
12,
984,
199,
199,
3,
5679,
536,
2341,
199,
3271,
7674,
1173,
275,
20644,
1117,
1702,
15,
3356,
14,
4745,
14,
2424,
7,
199,
199,
3,
5679,
6602,
199,
3271,
694,
275,
1052,
199,
3271,
694,
459,
9634,
418,
275,
20644,
8589,
15,
67,
4176,
4805,
199,
3271,
694,
459,
6138,
418,
275,
20644,
8589,
15,
6138,
4805,
199,
3271,
694,
459,
3596,
418,
275,
20644,
8589,
15,
9554,
4805,
199,
3271,
694,
459,
647,
418,
275,
20644,
8589,
15,
1548,
4805,
199,
199,
3,
3758,
370,
1006,
4545,
199,
396,
63,
4684,
275,
788,
6138,
297,
283,
3596,
297,
283,
647,
418,
199,
199,
533,
15227,
5866,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
5952,
63,
3356,
8,
277,
304,
267,
327,
11932,
367,
4124,
7251,
267,
4124,
275,
1052,
398,
327,
982,
511,
1347,
15,
83,
4898,
2741,
641,
314,
1414,
1004,
12,
675,
3062,
267,
340,
822,
8,
277,
14,
3020,
9,
690,
378,
26,
1779,
511,
63,
4684,
275,
291,
14,
3020,
398,
327,
23989,
1806,
314,
4412,
570,
436,
1104,
367,
1126,
13,
3671,
7251,
267,
543,
1551,
334,
3271,
7674,
1173,
12,
298,
82,
531,
465,
289,
26,
288,
367,
1004,
315,
289,
26,
355,
7838,
275,
1052,
355,
2615,
3771,
275,
1052,
355,
327,
11740,
734,
314,
2893,
1561,
1126,
1347,
355,
367,
1347,
315,
511,
63,
4684,
26,
490,
1336,
275,
295,
14,
1431,
14097,
2795,
14,
9634,
680,
7590,
84,
2961,
51,
11,
4111,
83,
3171,
450,
1347,
12,
1004,
9,
490,
340,
1336,
26,
717,
7838,
459,
9634,
418,
275,
1336,
14,
923,
8,
17,
9,
717,
7838,
59,
1375,
61,
275,
1336,
14,
923,
8,
18,
9,
2234,
327,
14012,
737,
5210,
2877,
1347,
1584,
370,
1104,
355,
340,
822,
8,
10151,
9,
665,
499,
26,
1980,
2234,
327,
12176,
340,
4825,
1275,
9634,
570,
370,
6540,
6169,
355,
291,
14,
1815,
360,
9634,
7,
315,
7838,
9,
2234,
327,
6162,
314,
2615,
931,
370,
1924,
2690,
570,
355,
367,
1022,
12,
86,
315,
7838,
14,
1744,
837,
490,
2615,
3771,
59,
75,
61,
275,
747,
14,
515,
14,
904,
8,
3271,
694,
59,
75,
467,
373,
9,
2234,
327,
3645,
17327,
1300,
1788,
465,
511,
354,
355,
9593,
275,
747,
14,
515,
14,
7973,
8,
10151,
459,
9634,
25945,
16,
61,
2234,
4124,
59,
4846,
61,
275,
942,
2234,
327,
2670,
367,
1006,
2893,
6203,
355,
367,
1347,
12,
1788,
315,
2615,
3771,
14,
1744,
837,
490,
340,
440,
747,
14,
515,
14,
2444,
8,
1501,
304,
717,
4124,
59,
4846,
61,
847,
359,
736,
14,
515,
14,
1294,
8,
1501,
15786,
17,
2677,
398,
327,
510,
14780,
734,
2295,
543,
949,
4124,
1584,
267,
367,
1022,
315,
4124,
14,
1612,
837,
288,
340,
822,
8,
4752,
59,
75,
566,
508,
378,
26,
2150,
4124,
59,
75,
61,
398,
327,
9101,
3355,
4124,
2893,
6203,
267,
2386,
63,
4752,
275,
4124,
14,
1612,
342,
267,
2386,
63,
4752,
14,
3191,
342,
267,
291,
14,
629,
8,
552,
8,
4752,
395,
378,
12,
355,
1557,
78,
60,
78,
7718,
7251,
3427,
78,
7,
435,
355,
1557,
78,
1370,
904,
26861,
83,
26,
450,
83,
7,
450,
334,
75,
12,
1656,
1987,
904,
8,
4752,
59,
75,
2459,
367,
1022,
315,
2386,
63,
4752,
2459,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
9812,
9476,
687,
9238,
272,
15227,
5866,
14,
3020,
275,
942,
272,
367,
1680,
315,
984,
14,
3020,
59,
17,
10688,
267,
15227,
5866,
14,
3020,
14,
740,
8,
1274,
14,
3020,
14,
1935,
1012,
272,
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,
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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/Perf/Trace/Util.py
|
12527
|
1935
|
# Util.py - Python extension for perf script, miscellaneous utility code
#
# Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com>
#
# This software may be distributed under the terms of the GNU General
# Public License ("GPL") version 2 as published by the Free Software
# Foundation.
import errno, os
FUTEX_WAIT = 0
FUTEX_WAKE = 1
FUTEX_PRIVATE_FLAG = 128
FUTEX_CLOCK_REALTIME = 256
FUTEX_CMD_MASK = ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
NSECS_PER_SEC = 1000000000
def avg(total, n):
return total / n
def nsecs(secs, nsecs):
return secs * NSECS_PER_SEC + nsecs
def nsecs_secs(nsecs):
return nsecs / NSECS_PER_SEC
def nsecs_nsecs(nsecs):
return nsecs % NSECS_PER_SEC
def nsecs_str(nsecs):
str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
return str
def add_stats(dict, key, value):
if not dict.has_key(key):
dict[key] = (value, value, value, 1)
else:
min, max, avg, count = dict[key]
if value < min:
min = value
if value > max:
max = value
avg = (avg + value) / 2
dict[key] = (min, max, avg, count + 1)
def clear_term():
print("\x1b[H\x1b[2J")
audit_package_warned = False
try:
import audit
machine_to_id = {
'x86_64': audit.MACH_86_64,
'alpha' : audit.MACH_ALPHA,
'ia64' : audit.MACH_IA64,
'ppc' : audit.MACH_PPC,
'ppc64' : audit.MACH_PPC64,
's390' : audit.MACH_S390,
's390x' : audit.MACH_S390X,
'i386' : audit.MACH_X86,
'i586' : audit.MACH_X86,
'i686' : audit.MACH_X86,
}
try:
machine_to_id['armeb'] = audit.MACH_ARMEB
except:
pass
machine_id = machine_to_id[os.uname()[4]]
except:
if not audit_package_warned:
audit_package_warned = True
print "Install the audit-libs-python package to get syscall names"
def syscall_name(id):
try:
return audit.audit_syscall_to_name(id, machine_id)
except:
return str(id)
def strerror(nr):
try:
return errno.errorcode[abs(nr)]
except:
return "Unknown %d errno" % nr
|
gpl-2.0
|
[
3,
21248,
14,
647,
446,
2018,
3329,
367,
8582,
2884,
12,
3201,
19549,
11420,
1233,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
1443,
506,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
199,
199,
646,
7554,
12,
747,
199,
199,
31179,
63,
12458,
275,
378,
199,
31179,
63,
9004,
2430,
275,
413,
199,
31179,
63,
18748,
63,
3719,
275,
7960,
199,
31179,
63,
30690,
63,
15508,
4961,
275,
7633,
199,
31179,
63,
9744,
63,
12880,
275,
6146,
8,
31179,
63,
18748,
63,
3719,
1204,
481,
934,
1438,
63,
30690,
63,
15508,
4961,
9,
199,
199,
46,
28466,
63,
4227,
63,
15048,
259,
275,
413,
25464,
199,
199,
318,
12402,
8,
2923,
12,
302,
304,
272,
372,
3141,
1182,
302,
199,
199,
318,
13781,
8,
4855,
12,
13781,
304,
272,
372,
20091,
627,
653,
28466,
63,
4227,
63,
15048,
435,
13781,
199,
199,
318,
13781,
63,
4855,
8,
9618,
304,
272,
372,
13781,
1182,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
9618,
8,
9618,
304,
272,
372,
13781,
450,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
495,
8,
9618,
304,
272,
620,
275,
2071,
21,
85,
4111,
1643,
85,
2,
450,
334,
9618,
63,
4855,
8,
9618,
395,
13781,
63,
9618,
8,
9618,
1826,
272,
372,
620,
199,
199,
318,
1050,
63,
3200,
8,
807,
12,
790,
12,
574,
304,
199,
198,
692,
440,
1211,
14,
1989,
63,
498,
8,
498,
304,
507,
198,
807,
59,
498,
61,
275,
334,
585,
12,
574,
12,
574,
12,
413,
9,
199,
198,
2836,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
1211,
59,
498,
61,
507,
198,
692,
574,
665,
1748,
26,
686,
198,
827,
275,
574,
507,
198,
692,
574,
690,
1390,
26,
686,
198,
988,
275,
574,
507,
198,
8595,
275,
334,
8595,
435,
574,
9,
1182,
499,
507,
198,
807,
59,
498,
61,
275,
334,
827,
12,
1390,
12,
12402,
12,
2338,
435,
413,
9,
199,
199,
318,
5436,
63,
5125,
837,
272,
870,
4582,
88,
17,
66,
59,
40,
60,
88,
17,
66,
59,
18,
42,
531,
199,
199,
14274,
63,
2491,
63,
4050,
379,
275,
756,
199,
199,
893,
26,
199,
198,
646,
13968,
199,
198,
6744,
63,
475,
63,
344,
275,
469,
507,
198,
7,
88,
1184,
63,
772,
356,
13968,
14,
13802,
63,
1184,
63,
772,
12,
507,
198,
7,
4468,
7,
198,
26,
13968,
14,
13802,
63,
18554,
12,
507,
198,
7,
4674,
772,
7,
198,
26,
13968,
14,
13802,
63,
13033,
772,
12,
507,
198,
7,
20638,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
12,
507,
198,
7,
20638,
772,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
772,
12,
507,
198,
1159,
12302,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
12,
507,
198,
1159,
12302,
88,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
56,
12,
507,
198,
7,
73,
8040,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
26888,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
10253,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
199,
198,
93,
199,
198,
893,
26,
507,
198,
6744,
63,
475,
63,
344,
459,
285,
278,
66,
418,
275,
13968,
14,
13802,
63,
689,
3635,
34,
199,
198,
2590,
26,
507,
198,
1529,
199,
198,
6744,
63,
344,
275,
6844,
63,
475,
63,
344,
59,
736,
14,
16040,
3430,
20,
2677,
199,
2590,
26,
199,
198,
692,
440,
13968,
63,
2491,
63,
4050,
379,
26,
507,
198,
14274,
63,
2491,
63,
4050,
379,
275,
715,
507,
198,
1361,
298,
8154,
314,
13968,
13,
8450,
13,
1548,
2559,
370,
664,
18901,
1561,
2,
199,
199,
318,
18901,
63,
354,
8,
344,
304,
199,
198,
893,
26,
507,
198,
1107,
13968,
14,
14274,
63,
19444,
63,
475,
63,
354,
8,
344,
12,
6844,
63,
344,
9,
199,
198,
2590,
26,
507,
198,
1107,
620,
8,
344,
9,
199,
199,
318,
410,
17844,
8,
7865,
304,
199,
198,
893,
26,
507,
198,
1107,
7554,
14,
28857,
59,
2101,
8,
7865,
1874,
199,
198,
2590,
26,
507,
198,
1107,
298,
5912,
450,
68,
7554,
2,
450,
14762,
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
] |
[
21248,
14,
647,
446,
2018,
3329,
367,
8582,
2884,
12,
3201,
19549,
11420,
1233,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
1443,
506,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
199,
199,
646,
7554,
12,
747,
199,
199,
31179,
63,
12458,
275,
378,
199,
31179,
63,
9004,
2430,
275,
413,
199,
31179,
63,
18748,
63,
3719,
275,
7960,
199,
31179,
63,
30690,
63,
15508,
4961,
275,
7633,
199,
31179,
63,
9744,
63,
12880,
275,
6146,
8,
31179,
63,
18748,
63,
3719,
1204,
481,
934,
1438,
63,
30690,
63,
15508,
4961,
9,
199,
199,
46,
28466,
63,
4227,
63,
15048,
259,
275,
413,
25464,
199,
199,
318,
12402,
8,
2923,
12,
302,
304,
272,
372,
3141,
1182,
302,
199,
199,
318,
13781,
8,
4855,
12,
13781,
304,
272,
372,
20091,
627,
653,
28466,
63,
4227,
63,
15048,
435,
13781,
199,
199,
318,
13781,
63,
4855,
8,
9618,
304,
272,
372,
13781,
1182,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
9618,
8,
9618,
304,
272,
372,
13781,
450,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
495,
8,
9618,
304,
272,
620,
275,
2071,
21,
85,
4111,
1643,
85,
2,
450,
334,
9618,
63,
4855,
8,
9618,
395,
13781,
63,
9618,
8,
9618,
1826,
272,
372,
620,
199,
199,
318,
1050,
63,
3200,
8,
807,
12,
790,
12,
574,
304,
199,
198,
692,
440,
1211,
14,
1989,
63,
498,
8,
498,
304,
507,
198,
807,
59,
498,
61,
275,
334,
585,
12,
574,
12,
574,
12,
413,
9,
199,
198,
2836,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
1211,
59,
498,
61,
507,
198,
692,
574,
665,
1748,
26,
686,
198,
827,
275,
574,
507,
198,
692,
574,
690,
1390,
26,
686,
198,
988,
275,
574,
507,
198,
8595,
275,
334,
8595,
435,
574,
9,
1182,
499,
507,
198,
807,
59,
498,
61,
275,
334,
827,
12,
1390,
12,
12402,
12,
2338,
435,
413,
9,
199,
199,
318,
5436,
63,
5125,
837,
272,
870,
4582,
88,
17,
66,
59,
40,
60,
88,
17,
66,
59,
18,
42,
531,
199,
199,
14274,
63,
2491,
63,
4050,
379,
275,
756,
199,
199,
893,
26,
199,
198,
646,
13968,
199,
198,
6744,
63,
475,
63,
344,
275,
469,
507,
198,
7,
88,
1184,
63,
772,
356,
13968,
14,
13802,
63,
1184,
63,
772,
12,
507,
198,
7,
4468,
7,
198,
26,
13968,
14,
13802,
63,
18554,
12,
507,
198,
7,
4674,
772,
7,
198,
26,
13968,
14,
13802,
63,
13033,
772,
12,
507,
198,
7,
20638,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
12,
507,
198,
7,
20638,
772,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
772,
12,
507,
198,
1159,
12302,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
12,
507,
198,
1159,
12302,
88,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
56,
12,
507,
198,
7,
73,
8040,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
26888,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
10253,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
199,
198,
93,
199,
198,
893,
26,
507,
198,
6744,
63,
475,
63,
344,
459,
285,
278,
66,
418,
275,
13968,
14,
13802,
63,
689,
3635,
34,
199,
198,
2590,
26,
507,
198,
1529,
199,
198,
6744,
63,
344,
275,
6844,
63,
475,
63,
344,
59,
736,
14,
16040,
3430,
20,
2677,
199,
2590,
26,
199,
198,
692,
440,
13968,
63,
2491,
63,
4050,
379,
26,
507,
198,
14274,
63,
2491,
63,
4050,
379,
275,
715,
507,
198,
1361,
298,
8154,
314,
13968,
13,
8450,
13,
1548,
2559,
370,
664,
18901,
1561,
2,
199,
199,
318,
18901,
63,
354,
8,
344,
304,
199,
198,
893,
26,
507,
198,
1107,
13968,
14,
14274,
63,
19444,
63,
475,
63,
354,
8,
344,
12,
6844,
63,
344,
9,
199,
198,
2590,
26,
507,
198,
1107,
620,
8,
344,
9,
199,
199,
318,
410,
17844,
8,
7865,
304,
199,
198,
893,
26,
507,
198,
1107,
7554,
14,
28857,
59,
2101,
8,
7865,
1874,
199,
198,
2590,
26,
507,
198,
1107,
298,
5912,
450,
68,
7554,
2,
450,
14762,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1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|
1097
|
#!/usr/bin/env python
from __future__ import print_function
import glob
import json
import os
import subprocess
for testfile in glob.glob("*.json"):
testdoc = json.load(open(testfile))
for test in testdoc["tests"]:
if "lambda" in test["data"]:
continue
open('data', 'w').write(json.dumps(test["data"]))
open('template', 'w').write(test["template"])
if "partials" in test:
open('partials', 'w').write(json.dumps(test["partials"]))
else:
open('partials', 'w').write("{}")
ret = subprocess.check_output("./mustachetest").decode('utf8')
print(testfile, test["name"])
if ret != test["expected"]:
if 'partials' in test:
print('partials:', json.dumps(test["partials"]))
print(json.dumps(test["data"]))
print(test["template"])
print('Expected:',repr(test["expected"]))
print('Actual:',repr(ret))
assert ret == test["expected"]
os.unlink('data')
os.unlink('template')
os.unlink('partials')
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
5739,
199,
646,
2022,
199,
646,
747,
199,
646,
3873,
199,
509,
30530,
315,
5739,
14,
6463,
480,
4856,
1001,
2349,
272,
511,
1301,
275,
2022,
14,
912,
8,
1490,
8,
21091,
430,
272,
367,
511,
315,
511,
1301,
905,
2219,
6229,
267,
340,
298,
2734,
2,
315,
511,
905,
576,
6229,
288,
1980,
267,
1551,
360,
576,
297,
283,
87,
1959,
952,
8,
1001,
14,
4180,
8,
396,
905,
576,
13045,
267,
1551,
360,
1160,
297,
283,
87,
1959,
952,
8,
396,
905,
1160,
3135,
267,
340,
298,
6672,
83,
2,
315,
511,
26,
288,
1551,
360,
6672,
83,
297,
283,
87,
1959,
952,
8,
1001,
14,
4180,
8,
396,
905,
6672,
83,
13045,
267,
587,
26,
288,
1551,
360,
6672,
83,
297,
283,
87,
1959,
952,
20794,
531,
267,
2203,
275,
3873,
14,
1074,
63,
1199,
28615,
7790,
21481,
396,
3471,
2708,
360,
1624,
24,
358,
267,
870,
8,
21091,
12,
511,
905,
354,
3135,
267,
340,
2203,
1137,
511,
905,
2062,
6229,
288,
340,
283,
6672,
83,
7,
315,
511,
26,
355,
870,
360,
6672,
83,
6536,
2022,
14,
4180,
8,
396,
905,
6672,
83,
13045,
288,
870,
8,
1001,
14,
4180,
8,
396,
905,
576,
13045,
288,
870,
8,
396,
905,
1160,
3135,
288,
870,
360,
6964,
6536,
2722,
8,
396,
905,
2062,
13045,
288,
870,
360,
30141,
6536,
2722,
8,
3292,
430,
267,
702,
2203,
508,
511,
905,
2062,
937,
267,
747,
14,
7162,
360,
576,
358,
267,
747,
14,
7162,
360,
1160,
358,
267,
747,
14,
7162,
360,
6672,
83,
358,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
5739,
199,
646,
2022,
199,
646,
747,
199,
646,
3873,
199,
509,
30530,
315,
5739,
14,
6463,
480,
4856,
1001,
2349,
272,
511,
1301,
275,
2022,
14,
912,
8,
1490,
8,
21091,
430,
272,
367,
511,
315,
511,
1301,
905,
2219,
6229,
267,
340,
298,
2734,
2,
315,
511,
905,
576,
6229,
288,
1980,
267,
1551,
360,
576,
297,
283,
87,
1959,
952,
8,
1001,
14,
4180,
8,
396,
905,
576,
13045,
267,
1551,
360,
1160,
297,
283,
87,
1959,
952,
8,
396,
905,
1160,
3135,
267,
340,
298,
6672,
83,
2,
315,
511,
26,
288,
1551,
360,
6672,
83,
297,
283,
87,
1959,
952,
8,
1001,
14,
4180,
8,
396,
905,
6672,
83,
13045,
267,
587,
26,
288,
1551,
360,
6672,
83,
297,
283,
87,
1959,
952,
20794,
531,
267,
2203,
275,
3873,
14,
1074,
63,
1199,
28615,
7790,
21481,
396,
3471,
2708,
360,
1624,
24,
358,
267,
870,
8,
21091,
12,
511,
905,
354,
3135,
267,
340,
2203,
1137,
511,
905,
2062,
6229,
288,
340,
283,
6672,
83,
7,
315,
511,
26,
355,
870,
360,
6672,
83,
6536,
2022,
14,
4180,
8,
396,
905,
6672,
83,
13045,
288,
870,
8,
1001,
14,
4180,
8,
396,
905,
576,
13045,
288,
870,
8,
396,
905,
1160,
3135,
288,
870,
360,
6964,
6536,
2722,
8,
396,
905,
2062,
13045,
288,
870,
360,
30141,
6536,
2722,
8,
3292,
430,
267,
702,
2203,
508,
511,
905,
2062,
937,
267,
747,
14,
7162,
360,
576,
358,
267,
747,
14,
7162,
360,
1160,
358,
267,
747,
14,
7162,
360,
6672,
83,
358,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
opedroso/czmq
|
bindings/python_cffi/czmq_cffi/utils.py
|
20
|
1731
|
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################
try:
from . import native
lib = native.lib
ffi = native.ffi
except ImportError:
from . import dlopen
lib = dlopen.lib
ffi = dlopen.ffi
def rebind (_lib, _ffi):
"""Rebind Lib and CompiledFFi objects for given package. Lib object MUST expose all functions
required by the classes. This is default for zproject based projects"""
global lib
global ffi
lib = _lib
ffi = _ffi
try:
text_type = unicode # Python 2
binary_type = str
except NameError:
text_type = str # Python 3
binary_type = bytes
def to_bytes(s):
return s if isinstance(s, binary_type) else text_type(s).encode("utf-8")
def to_unicode(s):
return s if isinstance(s, text_type) else binary_type(s).decode("utf-8")
def to_strings (s):
"""Convert Python native list types to zlist_t of strings"""
if issubclass (s.__class__, (list, set, frozenset, tuple)):
foo = lib.zlist_new ()
lib.zlist_autofree (foo)
for item in s:
lib.zlist_append (foo, to_bytes (item))
return foo
return None
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################
|
mpl-2.0
|
[
13289,
199,
3,
221,
5749,
13024,
2281,
2948,
5,
29087,
6989,
6515,
3107,
10797,
27,
3506,
2845,
24981,
3651,
7177,
3651,
25731,
1309,
28292,
221,
327,
199,
3,
221,
5574,
314,
1315,
1715,
15,
18195,
14,
1064,
367,
2556,
3595,
10663,
19860,
4493,
14,
327,
199,
13289,
199,
893,
26,
272,
687,
1275,
492,
5438,
272,
1973,
275,
5438,
14,
773,
272,
30865,
275,
5438,
14,
11286,
199,
2590,
3545,
26,
272,
687,
1275,
492,
366,
8329,
272,
1973,
275,
366,
8329,
14,
773,
272,
30865,
275,
366,
8329,
14,
11286,
199,
199,
318,
295,
3409,
6110,
773,
12,
485,
11286,
304,
272,
408,
497,
3409,
8003,
436,
3599,
1672,
1665,
73,
2251,
367,
1627,
2559,
14,
8003,
909,
18095,
23705,
1006,
3423,
2126,
1415,
701,
314,
3992,
14,
961,
365,
849,
367,
1315,
1715,
4079,
11336,
624,
272,
2288,
1973,
272,
2288,
30865,
272,
1973,
275,
485,
773,
272,
30865,
275,
485,
11286,
199,
199,
893,
26,
272,
1318,
63,
466,
275,
2649,
221,
327,
2018,
499,
272,
3366,
63,
466,
275,
620,
199,
2590,
12746,
26,
272,
1318,
63,
466,
275,
620,
420,
327,
2018,
650,
272,
3366,
63,
466,
275,
2783,
421,
199,
318,
370,
63,
2394,
8,
83,
304,
272,
372,
308,
340,
1228,
8,
83,
12,
3366,
63,
466,
9,
587,
1318,
63,
466,
8,
83,
680,
2143,
480,
1624,
13,
24,
531,
421,
199,
318,
370,
63,
2975,
8,
83,
304,
272,
372,
308,
340,
1228,
8,
83,
12,
1318,
63,
466,
9,
587,
3366,
63,
466,
8,
83,
680,
2708,
480,
1624,
13,
24,
531,
421,
199,
318,
370,
63,
5465,
334,
83,
304,
272,
408,
7306,
2018,
5438,
769,
2943,
370,
1315,
513,
63,
84,
402,
3326,
624,
272,
340,
11602,
334,
83,
855,
533,
3108,
334,
513,
12,
663,
12,
9522,
12,
2008,
2298,
267,
3925,
275,
1973,
14,
90,
513,
63,
1222,
6248,
267,
1973,
14,
90,
513,
63,
2495,
4624,
334,
1421,
9,
267,
367,
1242,
315,
308,
26,
288,
1973,
14,
90,
513,
63,
740,
334,
1421,
12,
370,
63,
2394,
334,
1053,
430,
267,
372,
3925,
272,
372,
488,
199,
13289,
199,
3,
221,
5749,
13024,
2281,
2948,
5,
29087,
6989,
6515,
3107,
10797,
27,
3506,
2845,
24981,
3651,
7177,
3651,
25731,
1309,
28292,
221,
327,
199,
3,
221,
5574,
314,
1315,
1715,
15,
18195,
14,
1064,
367,
2556,
3595,
10663,
19860,
4493,
14,
327,
199,
13289,
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
] |
[
199,
3,
221,
5749,
13024,
2281,
2948,
5,
29087,
6989,
6515,
3107,
10797,
27,
3506,
2845,
24981,
3651,
7177,
3651,
25731,
1309,
28292,
221,
327,
199,
3,
221,
5574,
314,
1315,
1715,
15,
18195,
14,
1064,
367,
2556,
3595,
10663,
19860,
4493,
14,
327,
199,
13289,
199,
893,
26,
272,
687,
1275,
492,
5438,
272,
1973,
275,
5438,
14,
773,
272,
30865,
275,
5438,
14,
11286,
199,
2590,
3545,
26,
272,
687,
1275,
492,
366,
8329,
272,
1973,
275,
366,
8329,
14,
773,
272,
30865,
275,
366,
8329,
14,
11286,
199,
199,
318,
295,
3409,
6110,
773,
12,
485,
11286,
304,
272,
408,
497,
3409,
8003,
436,
3599,
1672,
1665,
73,
2251,
367,
1627,
2559,
14,
8003,
909,
18095,
23705,
1006,
3423,
2126,
1415,
701,
314,
3992,
14,
961,
365,
849,
367,
1315,
1715,
4079,
11336,
624,
272,
2288,
1973,
272,
2288,
30865,
272,
1973,
275,
485,
773,
272,
30865,
275,
485,
11286,
199,
199,
893,
26,
272,
1318,
63,
466,
275,
2649,
221,
327,
2018,
499,
272,
3366,
63,
466,
275,
620,
199,
2590,
12746,
26,
272,
1318,
63,
466,
275,
620,
420,
327,
2018,
650,
272,
3366,
63,
466,
275,
2783,
421,
199,
318,
370,
63,
2394,
8,
83,
304,
272,
372,
308,
340,
1228,
8,
83,
12,
3366,
63,
466,
9,
587,
1318,
63,
466,
8,
83,
680,
2143,
480,
1624,
13,
24,
531,
421,
199,
318,
370,
63,
2975,
8,
83,
304,
272,
372,
308,
340,
1228,
8,
83,
12,
1318,
63,
466,
9,
587,
3366,
63,
466,
8,
83,
680,
2708,
480,
1624,
13,
24,
531,
421,
199,
318,
370,
63,
5465,
334,
83,
304,
272,
408,
7306,
2018,
5438,
769,
2943,
370,
1315,
513,
63,
84,
402,
3326,
624,
272,
340,
11602,
334,
83,
855,
533,
3108,
334,
513,
12,
663,
12,
9522,
12,
2008,
2298,
267,
3925,
275,
1973,
14,
90,
513,
63,
1222,
6248,
267,
1973,
14,
90,
513,
63,
2495,
4624,
334,
1421,
9,
267,
367,
1242,
315,
308,
26,
288,
1973,
14,
90,
513,
63,
740,
334,
1421,
12,
370,
63,
2394,
334,
1053,
430,
267,
372,
3925,
272,
372,
488,
199,
13289,
199,
3,
221,
5749,
13024,
2281,
2948,
5,
29087,
6989,
6515,
3107,
10797,
27,
3506,
2845,
24981,
3651,
7177,
3651,
25731,
1309,
28292,
221,
327,
199,
3,
221,
5574,
314,
1315,
1715,
15,
18195,
14,
1064,
367,
2556,
3595,
10663,
19860,
4493,
14,
327,
199,
13289,
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,
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,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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
] |
ahamilton55/ansible
|
lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py
|
19
|
27536
|
#!/usr/bin/python
#
# 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 = {
'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community',
}
DOCUMENTATION = '''
---
module: nxos_bgp_neighbor_af
extends_documentation_fragment: nxos
version_added: "2.2"
short_description: Manages BGP address-family's neighbors configuration.
description:
- Manages BGP address-family's neighbors configurations on NX-OS switches.
author: Gabriele Gerbino (@GGabriele)
notes:
- C(state=absent) removes the whole BGP address-family's
neighbor configuration.
- Default, when supported, removes properties
- In order to default maximum-prefix configuration, only
C(max_prefix_limit=default) is needed.
options:
asn:
description:
- BGP autonomous system number. Valid values are String,
Integer in ASPLAIN or ASDOT notation.
required: true
vrf:
description:
- Name of the VRF. The name 'default' is a valid VRF representing
the global bgp.
required: false
default: default
neighbor:
description:
- Neighbor Identifier. Valid values are string. Neighbors may use
IPv4 or IPv6 notation, with or without prefix length.
required: true
afi:
description:
- Address Family Identifier.
required: true
choices: ['ipv4','ipv6', 'vpnv4', 'vpnv6', 'l2vpn']
safi:
description:
- Sub Address Family Identifier.
required: true
choices: ['unicast','multicast', 'evpn']
additional_paths_receive:
description:
- Valid values are enable for basic command enablement; disable
for disabling the command at the neighbor af level
(it adds the disable keyword to the basic command); and inherit
to remove the command at this level (the command value is
inherited from a higher BGP layer).
required: false
choices: ['enable','disable', 'inherit']
default: null
additional_paths_send:
description:
- Valid values are enable for basic command enablement; disable
for disabling the command at the neighbor af level
(it adds the disable keyword to the basic command); and inherit
to remove the command at this level (the command value is
inherited from a higher BGP layer).
required: false
choices: ['enable','disable', 'inherit']
default: null
advertise_map_exist:
description:
- Conditional route advertisement. This property requires two
route maps, an advertise-map and an exist-map. Valid values are
an array specifying both the advertise-map name and the exist-map
name, or simply 'default' e.g. ['my_advertise_map',
'my_exist_map']. This command is mutually exclusive with the
advertise_map_non_exist property.
required: false
default: null
advertise_map_non_exist:
description:
- Conditional route advertisement. This property requires two
route maps, an advertise-map and an exist-map. Valid values are
an array specifying both the advertise-map name and the
non-exist-map name, or simply 'default' e.g.
['my_advertise_map', 'my_non_exist_map']. This command is mutually
exclusive with the advertise_map_exist property.
required: false
default: null
allowas_in:
description:
- Activate allowas-in property
required: false
default: null
allowas_in_max:
description:
- Optional max-occurrences value for allowas_in. Valid values are
an integer value or 'default'. Can be used independently or in
conjunction with allowas_in.
required: false
default: null
as_override:
description:
- Activate the as-override feature.
required: false
choices: ['true', 'false']
default: null
default_originate:
description:
- Activate the default-originate feature.
required: false
choices: ['true', 'false']
default: null
default_originate_route_map:
description:
- Optional route-map for the default_originate property. Can be
used independently or in conjunction with C(default_originate).
Valid values are a string defining a route-map name,
or 'default'.
required: false
default: null
filter_list_in:
description:
- Valid values are a string defining a filter-list name,
or 'default'.
required: false
default: null
filter_list_out:
description:
- Valid values are a string defining a filter-list name,
or 'default'.
required: false
default: null
max_prefix_limit:
description:
- maximum-prefix limit value. Valid values are an integer value
or 'default'.
required: false
default: null
max_prefix_interval:
description:
- Optional restart interval. Valid values are an integer.
Requires max_prefix_limit.
required: false
default: null
max_prefix_threshold:
description:
- Optional threshold percentage at which to generate a warning.
Valid values are an integer value.
Requires max_prefix_limit.
required: false
default: null
max_prefix_warning:
description:
- Optional warning-only keyword. Requires max_prefix_limit.
required: false
choices: ['true','false']
default: null
next_hop_self:
description:
- Activate the next-hop-self feature.
required: false
choices: ['true','false']
default: null
next_hop_third_party:
description:
- Activate the next-hop-third-party feature.
required: false
choices: ['true','false']
default: null
prefix_list_in:
description:
- Valid values are a string defining a prefix-list name,
or 'default'.
required: false
default: null
prefix_list_out:
description:
- Valid values are a string defining a prefix-list name,
or 'default'.
required: false
default: null
route_map_in:
description:
- Valid values are a string defining a route-map name,
or 'default'.
required: false
default: null
route_map_out:
description:
- Valid values are a string defining a route-map name,
or 'default'.
required: false
default: null
route_reflector_client:
description:
- Router reflector client.
required: false
choices: ['true','false']
default: null
send_community:
description:
- send-community attribute.
required: false
choices: ['none', 'both', 'extended', 'standard', 'default']
default: null
soft_reconfiguration_in:
description:
- Valid values are 'enable' for basic command enablement; 'always'
to add the always keyword to the basic command; and 'inherit' to
remove the command at this level (the command value is inherited
from a higher BGP layer).
required: false
choices: ['enable','always','inherit']
default: null
soo:
description:
- Site-of-origin. Valid values are a string defining a VPN
extcommunity or 'default'.
required: false
default: null
suppress_inactive:
description:
- suppress-inactive feature.
required: false
choices: ['true','false','default']
default: null
unsuppress_map:
description:
- unsuppress-map. Valid values are a string defining a route-map
name or 'default'.
required: false
default: null
weight:
description:
- Weight value. Valid values are an integer value or 'default'.
required: false
default: null
state:
description:
- Determines whether the config should be present or not
on the device.
required: false
default: present
choices: ['present','absent']
'''
EXAMPLES = '''
- name: configure RR client
nxos_bgp_neighbor_af:
asn: 65535
neighbor: '3.3.3.3'
afi: ipv4
safi: unicast
route_reflector_client: true
state: present
'''
RETURN = '''
commands:
description: commands sent to the device
returned: always
type: list
sample: ["router bgp 65535", "neighbor 3.3.3.3",
"address-family ipv4 unicast", "route-reflector-client"]
'''
import re
from ansible.module_utils.nxos import get_config, load_config
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import CustomNetworkConfig
BOOL_PARAMS = [
'allowas_in',
'as_override',
'default_originate',
'next_hop_self',
'next_hop_third_party',
'route_reflector_client',
'suppress_inactive'
]
PARAM_TO_COMMAND_KEYMAP = {
'afi': 'address-family',
'asn': 'router bgp',
'neighbor': 'neighbor',
'additional_paths_receive': 'capability additional-paths receive',
'additional_paths_send': 'capability additional-paths send',
'advertise_map_exist': 'advertise-map',
'advertise_map_non_exist': 'advertise-map',
'allowas_in': 'allowas-in',
'allowas_in_max': 'allowas-in',
'as_override': 'as-override',
'default_originate': 'default-originate',
'default_originate_route_map': 'default-originate route-map',
'filter_list_in': 'filter-list',
'filter_list_out': 'filter-list',
'max_prefix_limit': 'maximum-prefix',
'max_prefix_interval': 'maximum-prefix options',
'max_prefix_threshold': 'maximum-prefix options',
'max_prefix_warning': 'maximum-prefix options',
'next_hop_self': 'next-hop-self',
'next_hop_third_party': 'next-hop-third-party',
'prefix_list_in': 'prefix-list',
'prefix_list_out': 'prefix-list',
'route_map_in': 'route-map',
'route_map_out': 'route-map',
'route_reflector_client': 'route-reflector-client',
'safi': 'address-family',
'send_community': 'send-community',
'soft_reconfiguration_in': 'soft-reconfiguration inbound',
'soo': 'soo',
'suppress_inactive': 'suppress-inactive',
'unsuppress_map': 'unsuppress-map',
'weight': 'weight',
'vrf': 'vrf'
}
def get_value(arg, config, module):
custom = [
'allowas_in_max',
'additional_paths_send',
'additional_paths_receive',
'advertise_map_exist',
'advertise_map_non_exist',
'max_prefix_limit',
'max_prefix_interval',
'max_prefix_threshold',
'max_prefix_warning',
'next_hop_third_party',
'soft_reconfiguration_in'
]
command = PARAM_TO_COMMAND_KEYMAP[arg]
has_command = re.search(r'\s+{0}\s*'.format(command), config, re.M)
has_command_val = re.search(r'(?:{0}\s)(?P<value>.*)$'.format(command), config, re.M)
value = ''
if arg in custom:
value = get_custom_value(arg, config, module)
elif arg in BOOL_PARAMS:
value = False
if has_command:
value = True
elif command.split()[0] in ['filter-list', 'prefix-list', 'route-map']:
direction = arg.rsplit('_', 1)[1]
if has_command_val:
params = has_command_val.group('value').split()
if params[-1] == direction:
value = params[0]
elif arg == 'send_community':
if has_command:
value = 'none'
if has_command_val:
value = has_command_val.group('value')
elif has_command_val:
value = has_command_val.group('value')
return value
def get_custom_value(arg, config, module):
command = PARAM_TO_COMMAND_KEYMAP.get(arg)
splitted_config = config.splitlines()
value = ''
command_re = re.compile(r'\s+{0}\s*'.format(command), re.M)
has_command = command_re.search(config)
command_val_re = re.compile(r'(?:{0}\s)(?P<value>.*)$'.format(command), re.M)
has_command_val = command_val_re.search(config)
if arg.startswith('additional_paths'):
value = 'inherit'
for line in splitted_config:
if command in line:
if 'disable' in line:
value = 'disable'
else:
value = 'enable'
elif arg == 'advertise_map_exist':
value = []
for line in splitted_config:
if 'advertise-map' in line and 'exist-map' in line:
splitted_line = line.split()
value = [splitted_line[1], splitted_line[3]]
elif command == 'advertise-map':
value = []
exclude = 'non_exist' in arg
for line in splitted_config:
if 'advertise-map' in line and (
(exclude and 'non-exist-map' in line) or
(not exclude and 'exist-map' in line)
):
splitted_line = line.split()
value = [splitted_line[1], splitted_line[3]]
elif arg == 'allowas_in_max':
if has_command_val:
split_line = has_command_val.group('value').split()
if len(split_line) == 2:
value = splitted_line[-1]
elif arg.startswith('max_prefix'):
for line in splitted_config:
if 'maximum-prefix' in line:
splitted_line = line.split()
if arg == 'max_prefix_limit':
value = splitted_line[1]
elif arg == 'max_prefix_interval' and 'restart' in line:
value = splitted_line[-1]
elif arg == 'max_prefix_threshold' and len(splitted_line) > 2:
try:
int(splitted_line[2])
value = splitted_line[2]
except ValueError:
value = ''
elif arg == 'max_prefix_warning':
value = 'warning-only' in line
elif arg == 'soft_reconfiguration_in':
value = 'inherit'
for line in splitted_config:
if command in line:
if 'always' in line:
value = 'always'
else:
value = 'enable'
elif arg == 'next_hop_third_party':
no_command_re = re.compile(r'\s+no\s+{0}\s*'.format(command), re.M)
value = False
if not no_command_re.search(config) and command_re.search(config):
value = True
return value
def get_existing(module, args, warnings):
existing = {}
netcfg = CustomNetworkConfig(indent=2, contents=get_config(module))
asn_regex = re.compile(r'.*router\sbgp\s(?P<existing_asn>\d+).*', re.S)
match_asn = asn_regex.match(str(netcfg))
if match_asn:
existing_asn = match_asn.group('existing_asn')
parents = ["router bgp {0}".format(existing_asn)]
if module.params['vrf'] != 'default':
parents.append('vrf {0}'.format(module.params['vrf']))
parents.append('neighbor {0}'.format(module.params['neighbor']))
parents.append('address-family {0} {1}'.format(module.params['afi'], module.params['safi']))
config = netcfg.get_section(parents)
if config:
for arg in args:
if arg not in ['asn', 'vrf', 'neighbor', 'afi', 'safi']:
existing[arg] = get_value(arg, config, module)
existing['asn'] = existing_asn
existing['neighbor'] = module.params['neighbor']
existing['vrf'] = module.params['vrf']
existing['afi'] = module.params['afi']
existing['safi'] = module.params['safi']
else:
warnings.append("The BGP process didn't exist but the task just created it.")
return existing
def apply_key_map(key_map, table):
new_dict = {}
for key in table:
new_key = key_map.get(key)
if new_key:
new_dict[new_key] = table.get(key)
return new_dict
def get_default_command(key, value, existing_commands):
command = ''
if key == 'send-community' and existing_commands.get(key) == 'none':
command = 'no {0}'.format(key)
elif existing_commands.get(key):
existing_value = existing_commands.get(key)
if value == 'inherit':
if existing_value != 'inherit':
command = 'no {0}'.format(key)
else:
if key == 'advertise-map exist':
command = 'no advertise-map {0} exist-map {1}'.format(
existing_value[0], existing_value[1])
elif key == 'advertise-map non-exist':
command = 'no advertise-map {0} non-exist-map {1}'.format(
existing_value[0], existing_value[1])
elif key == 'filter-list in':
command = 'no filter-list {0} in'.format(existing_value)
elif key == 'filter-list out':
command = 'no filter-list {0} out'.format(existing_value)
elif key == 'prefix-list in':
command = 'no prefix-list {0} in'.format(existing_value)
elif key == 'prefix-list out':
command = 'no prefix-list {0} out'.format(existing_value)
elif key == 'route-map in':
command = 'no route-map {0} in'.format(existing_value)
elif key == 'route-map out':
command = 'no route-map {0} out'.format(existing_value)
elif key.startswith('maximum-prefix'):
command = 'no maximum-prefix {0}'.format(
existing_commands.get('maximum-prefix'))
elif key == 'allowas-in max':
command = ['no allowas-in {0}'.format(existing_value)]
command.append('allowas-in')
else:
command = 'no {0} {1}'.format(key, existing_value)
else:
if key.replace(' ', '_').replace('-', '_') in BOOL_PARAMS:
command = 'no {0}'.format(key)
return command
def fix_proposed(module, proposed):
allowas_in = proposed.get('allowas_in')
allowas_in_max = proposed.get('allowas_in_max')
if allowas_in is False and allowas_in_max:
proposed.pop('allowas_in_max')
elif allowas_in and allowas_in_max:
proposed.pop('allowas_in')
for key, value in proposed.items():
if key in ['filter_list_in', 'prefix_list_in', 'route_map_in']:
proposed[key] = [value, 'in']
elif key in ['filter_list_out', 'prefix_list_out', 'route_map_out']:
proposed[key] = [value, 'out']
return proposed
def state_present(module, existing, proposed, candidate):
commands = list()
proposed = fix_proposed(module, proposed)
proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed)
existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing)
for key, value in proposed_commands.items():
if key.startswith('maximum-prefix'):
command = 'maximum-prefix {0}'.format(module.params['max_prefix_limit'])
if module.params['max_prefix_threshold']:
command += ' {0}'.format(module.params['max_prefix_threshold'])
if module.params['max_prefix_interval']:
command += ' restart {0}'.format(module.params['max_prefix_interval'])
elif module.params['max_prefix_warning']:
command += ' warning-only'
commands.append(command)
elif value is True:
commands.append(key)
elif value is False:
commands.append('no {0}'.format(key))
elif value == 'default' or value == 'inherit':
command = get_default_command(key, value, existing_commands)
if isinstance(command, str):
if command and command not in commands:
commands.append(command)
elif isinstance(command, list):
for cmd in command:
if cmd not in commands:
commands.append(cmd)
elif key == 'address-family':
commands.append("address-family {0} {1}".format(module.params['afi'], module.params['safi']))
elif key.startswith('capability additional-paths'):
command = key
if value == 'disable':
command += ' disable'
commands.append(command)
elif key.startswith('advertise-map'):
direction = key.split()[0]
commands.append('advertise-map {1} {0} {2}'.format(direction, *value))
elif key in ['filter-list', 'prefix-list', 'route-map']:
commands.append('{0} {1} {2}'.format(key, *value))
elif key == 'soft-reconfiguration inbound':
command = ''
if value == 'enable':
command = key
elif value == 'always':
command = '{0} {1}'.format(key, value)
commands.append(command)
elif key == 'send-community':
command = key
if value != 'none':
command += ' {0}'.format(value)
commands.append(command)
else:
command = '{0} {1}'.format(key, value)
commands.append(command)
commands = set(commands)
if commands:
parents = ['router bgp {0}'.format(module.params['asn'])]
if module.params['vrf'] != 'default':
parents.append('vrf {0}'.format(module.params['vrf']))
parents.append('neighbor {0}'.format(module.params['neighbor']))
if len(commands) == 1:
candidate.add(commands, parents=parents)
elif len(commands) > 1:
af_command = 'address-family {0} {1}'.format(
module.params['afi'], module.params['safi'])
if af_command in commands:
commands.remove(af_command)
parents.append('address-family {0} {1}'.format(
module.params['afi'], module.params['safi']))
candidate.add(commands, parents=parents)
def state_absent(module, existing, candidate):
commands = []
parents = ["router bgp {0}".format(module.params['asn'])]
if module.params['vrf'] != 'default':
parents.append('vrf {0}'.format(module.params['vrf']))
parents.append('neighbor {0}'.format(module.params['neighbor']))
commands.append('no address-family {0} {1}'.format(
module.params['afi'], module.params['safi']))
candidate.add(commands, parents=parents)
def main():
argument_spec = dict(
asn=dict(required=True, type='str'),
vrf=dict(required=False, type='str', default='default'),
neighbor=dict(required=True, type='str'),
afi=dict(required=True, type='str'),
safi=dict(required=True, type='str'),
additional_paths_receive=dict(required=False, type='str', choices=['enable', 'disable', 'inherit']),
additional_paths_send=dict(required=False, type='str', choices=['enable', 'disable', 'inherit']),
advertise_map_exist=dict(required=False, type='list'),
advertise_map_non_exist=dict(required=False, type='list'),
allowas_in=dict(required=False, type='bool'),
allowas_in_max=dict(required=False, type='str'),
as_override=dict(required=False, type='bool'),
default_originate=dict(required=False, type='bool'),
default_originate_route_map=dict(required=False, type='str'),
filter_list_in=dict(required=False, type='str'),
filter_list_out=dict(required=False, type='str'),
max_prefix_limit=dict(required=False, type='str'),
max_prefix_interval=dict(required=False, type='str'),
max_prefix_threshold=dict(required=False, type='str'),
max_prefix_warning=dict(required=False, type='bool'),
next_hop_self=dict(required=False, type='bool'),
next_hop_third_party=dict(required=False, type='bool'),
prefix_list_in=dict(required=False, type='str'),
prefix_list_out=dict(required=False, type='str'),
route_map_in=dict(required=False, type='str'),
route_map_out=dict(required=False, type='str'),
route_reflector_client=dict(required=False, type='bool'),
send_community=dict(required=False, choices=['none', 'both', 'extended', 'standard', 'default']),
soft_reconfiguration_in=dict(required=False, type='str', choices=['enable', 'always', 'inherit']),
soo=dict(required=False, type='str'),
suppress_inactive=dict(required=False, type='bool'),
unsuppress_map=dict(required=False, type='str'),
weight=dict(required=False, type='str'),
state=dict(choices=['present', 'absent'], default='present', required=False),
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[['advertise_map_exist', 'advertise_map_non_exist']],
required_together=[['max_prefix_limit', 'max_prefix_interval'],
['max_prefix_limit', 'max_prefix_warning'],
['max_prefix_limit', 'max_prefix_threshold']],
supports_check_mode=True,
)
warnings = list()
check_args(module, warnings)
result = dict(changed=False, warnings=warnings)
state = module.params['state']
if module.params['vrf'] == 'default' and module.params['soo']:
module.fail_json(msg='SOO is only allowed in non-default VRF')
args = PARAM_TO_COMMAND_KEYMAP.keys()
existing = get_existing(module, args, warnings)
if existing.get('asn') and state == 'present':
if existing.get('asn') != module.params['asn']:
module.fail_json(msg='Another BGP ASN already exists.',
proposed_asn=module.params['asn'],
existing_asn=existing.get('asn'))
for param in ['advertise_map_exist', 'advertise_map_non_exist']:
if module.params[param] == ['default']:
module.params[param] = 'default'
proposed_args = dict((k, v) for k, v in module.params.items() if v is not None and k in args)
proposed = {}
for key, value in proposed_args.items():
if key not in ['asn', 'vrf', 'neighbor']:
if not isinstance(value, list):
if str(value).lower() == 'true':
value = True
elif str(value).lower() == 'false':
value = False
elif str(value).lower() == 'default':
if key in BOOL_PARAMS:
value = False
else:
value = 'default'
if existing.get(key) != value:
proposed[key] = value
candidate = CustomNetworkConfig(indent=3)
if state == 'present':
state_present(module, existing, proposed, candidate)
elif state == 'absent' and existing:
state_absent(module, existing, candidate)
if candidate:
candidate = candidate.items_text()
load_config(module, candidate)
result['changed'] = True
result['commands'] = candidate
else:
result['commands'] = []
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
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,
3,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
297,
199,
93,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
10132,
63,
13881,
63,
2756,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
27893,
2287,
13,
6606,
1159,
15845,
2897,
14,
199,
1802,
26,
523,
446,
21612,
27893,
2287,
13,
6606,
1159,
15845,
13422,
641,
653,
56,
13,
3100,
24563,
14,
199,
2502,
26,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
523,
446,
445,
8,
929,
29,
5575,
9,
14185,
314,
8852,
27893,
2287,
13,
6606,
1159,
272,
15503,
2897,
14,
523,
446,
3758,
12,
1380,
3748,
12,
14185,
4382,
523,
446,
1010,
1865,
370,
849,
5696,
13,
1861,
2897,
12,
1454,
272,
445,
8,
988,
63,
1861,
63,
3097,
29,
885,
9,
365,
4346,
14,
199,
1419,
26,
523,
16723,
26,
272,
1369,
26,
489,
446,
27893,
6384,
30671,
7376,
2656,
1329,
14,
4821,
1338,
787,
2624,
12,
267,
7225,
315,
4319,
2749,
9021,
503,
437,
3693,
1387,
15843,
14,
272,
1415,
26,
2549,
523,
15209,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
812,
11778,
14,
710,
536,
283,
885,
7,
365,
282,
1686,
812,
11778,
6144,
267,
314,
2288,
16884,
14,
272,
1415,
26,
3055,
272,
849,
26,
849,
523,
15503,
26,
272,
1369,
26,
489,
446,
5612,
7201,
23285,
14,
4821,
1338,
787,
1059,
14,
5612,
7398,
1443,
675,
267,
6509,
20,
503,
6509,
22,
15843,
12,
543,
503,
1928,
2403,
2582,
14,
272,
1415,
26,
2549,
523,
282,
329,
26,
272,
1369,
26,
489,
446,
9906,
481,
4632,
23285,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
4774,
20,
1673,
4774,
22,
297,
283,
9702,
86,
20,
297,
283,
9702,
86,
22,
297,
283,
76,
18,
9702,
418,
523,
2937,
329,
26,
272,
1369,
26,
489,
446,
4804,
9906,
481,
4632,
23285,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
5209,
1810,
1673,
23797,
297,
283,
6857,
4812,
418,
523,
4722,
63,
3771,
63,
9391,
26,
272,
1369,
26,
489,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
267,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
267,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
267,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
267,
12623,
687,
282,
10948,
27893,
4045,
680,
272,
1415,
26,
3055,
272,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
272,
849,
26,
2973,
523,
4722,
63,
3771,
63,
2254,
26,
272,
1369,
26,
489,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
267,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
267,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
267,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
267,
12623,
687,
282,
10948,
27893,
4045,
680,
272,
1415,
26,
3055,
272,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
272,
849,
26,
2973,
523,
19613,
261,
63,
1130,
63,
4494,
26,
272,
1369,
26,
489,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
267,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
267,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
2187,
13,
1130,
267,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
788,
1662,
63,
24576,
261,
63,
1130,
297,
267,
283,
1662,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
13914,
543,
314,
267,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
3324,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
26,
272,
1369,
26,
489,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
267,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
267,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
267,
2222,
13,
4494,
13,
1130,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
267,
788,
1662,
63,
24576,
261,
63,
1130,
297,
283,
1662,
63,
2865,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
267,
13914,
543,
314,
19613,
261,
63,
1130,
63,
4494,
3324,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2040,
305,
63,
262,
26,
272,
1369,
26,
489,
446,
21904,
2409,
2040,
305,
13,
262,
3324,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2040,
305,
63,
262,
63,
988,
26,
272,
1369,
26,
489,
446,
4879,
1390,
13,
20051,
10056,
574,
367,
2040,
305,
63,
262,
14,
4821,
1338,
787,
267,
376,
3000,
574,
503,
283,
885,
1370,
6855,
506,
1202,
30426,
503,
315,
267,
22888,
543,
2040,
305,
63,
262,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
465,
63,
4415
] |
[
2647,
15,
1393,
15,
1548,
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,
3,
199,
199,
8490,
63,
8314,
275,
469,
272,
283,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
1205,
356,
788,
7780,
995,
272,
283,
4946,
63,
991,
356,
283,
9387,
297,
199,
93,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
10132,
63,
13881,
63,
2756,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
27893,
2287,
13,
6606,
1159,
15845,
2897,
14,
199,
1802,
26,
523,
446,
21612,
27893,
2287,
13,
6606,
1159,
15845,
13422,
641,
653,
56,
13,
3100,
24563,
14,
199,
2502,
26,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
523,
446,
445,
8,
929,
29,
5575,
9,
14185,
314,
8852,
27893,
2287,
13,
6606,
1159,
272,
15503,
2897,
14,
523,
446,
3758,
12,
1380,
3748,
12,
14185,
4382,
523,
446,
1010,
1865,
370,
849,
5696,
13,
1861,
2897,
12,
1454,
272,
445,
8,
988,
63,
1861,
63,
3097,
29,
885,
9,
365,
4346,
14,
199,
1419,
26,
523,
16723,
26,
272,
1369,
26,
489,
446,
27893,
6384,
30671,
7376,
2656,
1329,
14,
4821,
1338,
787,
2624,
12,
267,
7225,
315,
4319,
2749,
9021,
503,
437,
3693,
1387,
15843,
14,
272,
1415,
26,
2549,
523,
15209,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
812,
11778,
14,
710,
536,
283,
885,
7,
365,
282,
1686,
812,
11778,
6144,
267,
314,
2288,
16884,
14,
272,
1415,
26,
3055,
272,
849,
26,
849,
523,
15503,
26,
272,
1369,
26,
489,
446,
5612,
7201,
23285,
14,
4821,
1338,
787,
1059,
14,
5612,
7398,
1443,
675,
267,
6509,
20,
503,
6509,
22,
15843,
12,
543,
503,
1928,
2403,
2582,
14,
272,
1415,
26,
2549,
523,
282,
329,
26,
272,
1369,
26,
489,
446,
9906,
481,
4632,
23285,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
4774,
20,
1673,
4774,
22,
297,
283,
9702,
86,
20,
297,
283,
9702,
86,
22,
297,
283,
76,
18,
9702,
418,
523,
2937,
329,
26,
272,
1369,
26,
489,
446,
4804,
9906,
481,
4632,
23285,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
5209,
1810,
1673,
23797,
297,
283,
6857,
4812,
418,
523,
4722,
63,
3771,
63,
9391,
26,
272,
1369,
26,
489,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
267,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
267,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
267,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
267,
12623,
687,
282,
10948,
27893,
4045,
680,
272,
1415,
26,
3055,
272,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
272,
849,
26,
2973,
523,
4722,
63,
3771,
63,
2254,
26,
272,
1369,
26,
489,
446,
4821,
1338,
787,
4756,
367,
5678,
1414,
4756,
434,
27,
3507,
267,
367,
30723,
314,
1414,
737,
314,
15503,
15871,
2166,
267,
334,
390,
9584,
314,
3507,
4252,
370,
314,
5678,
1414,
2736,
436,
8287,
267,
370,
2813,
314,
1414,
737,
642,
2166,
334,
1589,
1414,
574,
365,
267,
12623,
687,
282,
10948,
27893,
4045,
680,
272,
1415,
26,
3055,
272,
3415,
26,
788,
4296,
1673,
5993,
297,
283,
6486,
418,
272,
849,
26,
2973,
523,
19613,
261,
63,
1130,
63,
4494,
26,
272,
1369,
26,
489,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
267,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
267,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
2187,
13,
1130,
267,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
788,
1662,
63,
24576,
261,
63,
1130,
297,
267,
283,
1662,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
13914,
543,
314,
267,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
3324,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
19613,
261,
63,
1130,
63,
2865,
63,
4494,
26,
272,
1369,
26,
489,
446,
24191,
7475,
19613,
261,
434,
14,
961,
3324,
5074,
2877,
267,
7475,
9033,
12,
376,
19613,
261,
13,
1130,
436,
376,
2187,
13,
1130,
14,
4821,
1338,
787,
267,
376,
1625,
9176,
3865,
314,
19613,
261,
13,
1130,
536,
436,
314,
267,
2222,
13,
4494,
13,
1130,
536,
12,
503,
9329,
283,
885,
7,
325,
14,
71,
14,
267,
788,
1662,
63,
24576,
261,
63,
1130,
297,
283,
1662,
63,
2865,
63,
4494,
63,
1130,
2278,
961,
1414,
365,
16108,
267,
13914,
543,
314,
19613,
261,
63,
1130,
63,
4494,
3324,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2040,
305,
63,
262,
26,
272,
1369,
26,
489,
446,
21904,
2409,
2040,
305,
13,
262,
3324,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2040,
305,
63,
262,
63,
988,
26,
272,
1369,
26,
489,
446,
4879,
1390,
13,
20051,
10056,
574,
367,
2040,
305,
63,
262,
14,
4821,
1338,
787,
267,
376,
3000,
574,
503,
283,
885,
1370,
6855,
506,
1202,
30426,
503,
315,
267,
22888,
543,
2040,
305,
63,
262,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
465,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1,
1,
1,
1,
1
] |
andreasots/lrrbot
|
alembic/versions/a933db158324_drop_stats_votes.py
|
2
|
3012
|
revision = 'a933db158324'
down_revision = '7d1d0f735480'
branch_labels = None
depends_on = None
import alembic
import sqlalchemy
def upgrade():
alembic.op.drop_table("game_stats")
alembic.op.drop_table("game_votes")
alembic.op.drop_table("disabled_stats")
alembic.op.drop_table("stats")
def downgrade():
alembic.op.create_table(
"stats",
sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
sqlalchemy.Column("string_id", sqlalchemy.Text, nullable=False, unique=True),
sqlalchemy.Column("singular", sqlalchemy.Text),
sqlalchemy.Column("plural", sqlalchemy.Text),
sqlalchemy.Column("emote", sqlalchemy.Text),
)
alembic.op.create_table(
"disabled_stats",
sqlalchemy.Column("show_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("shows.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("stat_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("stats.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
)
alembic.op.create_primary_key("disabled_stats_pk", "disabled_stats", ["show_id", "stat_id"])
alembic.op.create_index('disabled_stats_show_id_idx', 'disabled_stats', ['show_id'])
alembic.op.create_index('disabled_stats_stat_id_idx', 'disabled_stats', ['stat_id'])
game_votes = alembic.op.create_table(
"game_votes",
sqlalchemy.Column("game_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("games.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("show_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("shows.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("user_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("users.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("vote", sqlalchemy.Boolean, nullable=False),
)
alembic.op.create_primary_key("game_votes_pk", "game_votes", ["game_id", "show_id", "user_id"])
alembic.op.create_index('game_votes_game_id_idx', 'game_votes', ['game_id'])
alembic.op.create_index('game_votes_show_id_idx', 'game_votes', ['show_id'])
alembic.op.create_index('game_votes_user_id_idx', 'game_votes', ['user_id'])
game_stats = alembic.op.create_table(
"game_stats",
sqlalchemy.Column("game_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("games.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("show_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("shows.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("stat_id", sqlalchemy.Integer, sqlalchemy.ForeignKey("shows.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False),
sqlalchemy.Column("count", sqlalchemy.Integer, nullable=False),
)
alembic.op.create_primary_key("game_stats_pk", "game_stats", ["game_id", "show_id", "stat_id"])
alembic.op.create_index('game_stats_game_id_idx', 'game_stats', ['game_id'])
alembic.op.create_index('game_stats_show_id_idx', 'game_stats', ['show_id'])
alembic.op.create_index('game_stats_stat_id_idx', 'game_stats', ['stat_id'])
|
apache-2.0
|
[
5792,
275,
283,
65,
25,
1153,
697,
11240,
12744,
7,
199,
2110,
63,
5792,
275,
283,
23,
68,
17,
68,
16,
70,
23,
12967,
1257,
7,
199,
4694,
63,
3512,
275,
488,
199,
8912,
63,
265,
275,
488,
199,
199,
646,
30960,
20596,
199,
646,
8335,
199,
199,
318,
10754,
837,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
5097,
63,
3200,
531,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
5097,
63,
16660,
531,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
7011,
63,
3200,
531,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
3200,
531,
199,
199,
318,
32498,
837,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
3200,
401,
507,
198,
14536,
14,
4547,
480,
344,
401,
8335,
14,
2674,
12,
5062,
63,
498,
29,
549,
395,
507,
198,
14536,
14,
4547,
480,
875,
63,
344,
401,
8335,
14,
1872,
12,
7854,
29,
797,
12,
3747,
29,
549,
395,
507,
198,
14536,
14,
4547,
480,
17045,
401,
8335,
14,
1872,
395,
507,
198,
14536,
14,
4547,
480,
10019,
401,
8335,
14,
1872,
395,
507,
198,
14536,
14,
4547,
480,
69,
2137,
401,
8335,
14,
1872,
395,
199,
198,
9,
421,
198,
1895,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
7011,
63,
3200,
401,
507,
198,
14536,
14,
4547,
480,
2384,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
3736,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
3200,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
199,
198,
9,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
3327,
63,
498,
480,
7011,
63,
3200,
63,
2051,
401,
298,
7011,
63,
3200,
401,
2097,
2384,
63,
344,
401,
298,
3736,
63,
344,
3135,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
7011,
63,
3200,
63,
2384,
63,
344,
63,
2996,
297,
283,
7011,
63,
3200,
297,
788,
2384,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
7011,
63,
3200,
63,
3736,
63,
344,
63,
2996,
297,
283,
7011,
63,
3200,
297,
788,
3736,
63,
344,
1105,
421,
198,
5097,
63,
16660,
275,
30960,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
5097,
63,
16660,
401,
507,
198,
14536,
14,
4547,
480,
5097,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
28129,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
2384,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
751,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
3707,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
14317,
401,
8335,
14,
4082,
12,
7854,
29,
797,
395,
199,
198,
9,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
3327,
63,
498,
480,
5097,
63,
16660,
63,
2051,
401,
298,
5097,
63,
16660,
401,
2097,
5097,
63,
344,
401,
298,
2384,
63,
344,
401,
298,
751,
63,
344,
3135,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
16660,
63,
5097,
63,
344,
63,
2996,
297,
283,
5097,
63,
16660,
297,
788,
5097,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
16660,
63,
2384,
63,
344,
63,
2996,
297,
283,
5097,
63,
16660,
297,
788,
2384,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
16660,
63,
751,
63,
344,
63,
2996,
297,
283,
5097,
63,
16660,
297,
788,
751,
63,
344,
1105,
421,
198,
5097,
63,
3200,
275,
30960,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
5097,
63,
3200,
401,
507,
198,
14536,
14,
4547,
480,
5097,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
28129,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
2384,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
3736,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
835,
401,
8335,
14,
2674,
12,
7854,
29,
797,
395,
199,
198,
9,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
3327,
63,
498,
480,
5097,
63,
3200,
63,
2051,
401,
298,
5097,
63,
3200,
401,
2097,
5097,
63,
344,
401,
298,
2384,
63,
344,
401,
298,
3736,
63,
344,
3135,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
3200,
63,
5097,
63,
344,
63,
2996,
297,
283,
5097,
63,
3200,
297,
788,
5097,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
3200,
63,
2384,
63,
344,
63,
2996,
297,
283,
5097,
63,
3200,
297,
788,
2384,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
3200,
63,
3736,
63,
344,
63,
2996,
297,
283,
5097,
63,
3200,
297,
788,
3736,
63,
344,
1105,
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
] |
[
275,
283,
65,
25,
1153,
697,
11240,
12744,
7,
199,
2110,
63,
5792,
275,
283,
23,
68,
17,
68,
16,
70,
23,
12967,
1257,
7,
199,
4694,
63,
3512,
275,
488,
199,
8912,
63,
265,
275,
488,
199,
199,
646,
30960,
20596,
199,
646,
8335,
199,
199,
318,
10754,
837,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
5097,
63,
3200,
531,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
5097,
63,
16660,
531,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
7011,
63,
3200,
531,
199,
198,
1895,
20596,
14,
411,
14,
4824,
63,
1224,
480,
3200,
531,
199,
199,
318,
32498,
837,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
3200,
401,
507,
198,
14536,
14,
4547,
480,
344,
401,
8335,
14,
2674,
12,
5062,
63,
498,
29,
549,
395,
507,
198,
14536,
14,
4547,
480,
875,
63,
344,
401,
8335,
14,
1872,
12,
7854,
29,
797,
12,
3747,
29,
549,
395,
507,
198,
14536,
14,
4547,
480,
17045,
401,
8335,
14,
1872,
395,
507,
198,
14536,
14,
4547,
480,
10019,
401,
8335,
14,
1872,
395,
507,
198,
14536,
14,
4547,
480,
69,
2137,
401,
8335,
14,
1872,
395,
199,
198,
9,
421,
198,
1895,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
7011,
63,
3200,
401,
507,
198,
14536,
14,
4547,
480,
2384,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
3736,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
3200,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
199,
198,
9,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
3327,
63,
498,
480,
7011,
63,
3200,
63,
2051,
401,
298,
7011,
63,
3200,
401,
2097,
2384,
63,
344,
401,
298,
3736,
63,
344,
3135,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
7011,
63,
3200,
63,
2384,
63,
344,
63,
2996,
297,
283,
7011,
63,
3200,
297,
788,
2384,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
7011,
63,
3200,
63,
3736,
63,
344,
63,
2996,
297,
283,
7011,
63,
3200,
297,
788,
3736,
63,
344,
1105,
421,
198,
5097,
63,
16660,
275,
30960,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
5097,
63,
16660,
401,
507,
198,
14536,
14,
4547,
480,
5097,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
28129,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
2384,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
751,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
3707,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
14317,
401,
8335,
14,
4082,
12,
7854,
29,
797,
395,
199,
198,
9,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
3327,
63,
498,
480,
5097,
63,
16660,
63,
2051,
401,
298,
5097,
63,
16660,
401,
2097,
5097,
63,
344,
401,
298,
2384,
63,
344,
401,
298,
751,
63,
344,
3135,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
16660,
63,
5097,
63,
344,
63,
2996,
297,
283,
5097,
63,
16660,
297,
788,
5097,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
16660,
63,
2384,
63,
344,
63,
2996,
297,
283,
5097,
63,
16660,
297,
788,
2384,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
16660,
63,
751,
63,
344,
63,
2996,
297,
283,
5097,
63,
16660,
297,
788,
751,
63,
344,
1105,
421,
198,
5097,
63,
3200,
275,
30960,
20596,
14,
411,
14,
981,
63,
1224,
8,
507,
198,
2,
5097,
63,
3200,
401,
507,
198,
14536,
14,
4547,
480,
5097,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
28129,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
2384,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
3736,
63,
344,
401,
8335,
14,
2674,
12,
8335,
14,
3190,
480,
23866,
14,
344,
401,
16549,
628,
10855,
401,
641,
873,
628,
10855,
1288,
7854,
29,
797,
395,
507,
198,
14536,
14,
4547,
480,
835,
401,
8335,
14,
2674,
12,
7854,
29,
797,
395,
199,
198,
9,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
3327,
63,
498,
480,
5097,
63,
3200,
63,
2051,
401,
298,
5097,
63,
3200,
401,
2097,
5097,
63,
344,
401,
298,
2384,
63,
344,
401,
298,
3736,
63,
344,
3135,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
3200,
63,
5097,
63,
344,
63,
2996,
297,
283,
5097,
63,
3200,
297,
788,
5097,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
3200,
63,
2384,
63,
344,
63,
2996,
297,
283,
5097,
63,
3200,
297,
788,
2384,
63,
344,
1105,
199,
198,
1895,
20596,
14,
411,
14,
981,
63,
1080,
360,
5097,
63,
3200,
63,
3736,
63,
344,
63,
2996,
297,
283,
5097,
63,
3200,
297,
788,
3736,
63,
344,
1105,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
thehyve/variant
|
eggs/django-1.3.1-py2.7.egg/django/core/context_processors.py
|
151
|
3868
|
"""
A set of request processors that return dictionaries to be merged into a
template context. Each function takes the request object as its only parameter
and returns a dictionary to add to the context.
These are referenced from the setting TEMPLATE_CONTEXT_PROCESSORS and used by
RequestContext.
"""
from django.conf import settings
from django.middleware.csrf import get_token
from django.utils.functional import lazy
def auth(request):
"""
DEPRECATED. This context processor is the old location, and has been moved
to `django.contrib.auth.context_processors`.
This function still exists for backwards-compatibility; it will be removed
in Django 1.4.
"""
import warnings
warnings.warn(
"The context processor at `django.core.context_processors.auth` is " \
"deprecated; use the path `django.contrib.auth.context_processors.auth` " \
"instead.",
DeprecationWarning
)
from django.contrib.auth.context_processors import auth as auth_context_processor
return auth_context_processor(request)
def csrf(request):
"""
Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
it has not been provided by either a view decorator or the middleware
"""
def _get_val():
token = get_token(request)
if token is None:
# In order to be able to provide debugging info in the
# case of misconfiguration, we use a sentinel value
# instead of returning an empty dict.
return 'NOTPROVIDED'
else:
return token
_get_val = lazy(_get_val, str)
return {'csrf_token': _get_val() }
def debug(request):
"Returns context variables helpful for debugging."
context_extras = {}
if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
context_extras['debug'] = True
from django.db import connection
context_extras['sql_queries'] = connection.queries
return context_extras
def i18n(request):
from django.utils import translation
context_extras = {}
context_extras['LANGUAGES'] = settings.LANGUAGES
context_extras['LANGUAGE_CODE'] = translation.get_language()
context_extras['LANGUAGE_BIDI'] = translation.get_language_bidi()
return context_extras
def static(request):
"""
Adds static-related context variables to the context.
"""
return {'STATIC_URL': settings.STATIC_URL}
def media(request):
"""
Adds media-related context variables to the context.
"""
return {'MEDIA_URL': settings.MEDIA_URL}
def request(request):
return {'request': request}
# PermWrapper and PermLookupDict proxy the permissions system into objects that
# the template system can understand. They once lived here -- they have
# been moved to django.contrib.auth.context_processors.
from django.contrib.auth.context_processors import PermLookupDict as RealPermLookupDict
from django.contrib.auth.context_processors import PermWrapper as RealPermWrapper
class PermLookupDict(RealPermLookupDict):
def __init__(self, *args, **kwargs):
import warnings
warnings.warn(
"`django.core.context_processors.PermLookupDict` is " \
"deprecated; use `django.contrib.auth.context_processors.PermLookupDict` " \
"instead.",
PendingDeprecationWarning
)
super(PermLookupDict, self).__init__(*args, **kwargs)
class PermWrapper(RealPermWrapper):
def __init__(self, *args, **kwargs):
import warnings
warnings.warn(
"`django.core.context_processors.PermWrapper` is " \
"deprecated; use `django.contrib.auth.context_processors.PermWrapper` " \
"instead.",
PendingDeprecationWarning
)
super(PermWrapper, self).__init__(*args, **kwargs)
|
apache-2.0
|
[
624,
199,
33,
663,
402,
1056,
21620,
626,
372,
11196,
370,
506,
9545,
1901,
282,
199,
1160,
1067,
14,
7048,
805,
6181,
314,
1056,
909,
465,
2399,
1454,
2725,
199,
460,
2529,
282,
2600,
370,
1050,
370,
314,
1067,
14,
199,
199,
20676,
787,
11812,
687,
314,
4260,
24877,
63,
9059,
63,
10494,
4149,
436,
1202,
701,
199,
17679,
14,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
5754,
14,
10088,
492,
664,
63,
1418,
199,
504,
1639,
14,
1208,
14,
15481,
492,
9617,
199,
199,
318,
1790,
8,
1069,
304,
272,
408,
272,
31404,
14,
961,
1067,
12495,
365,
314,
2269,
2909,
12,
436,
965,
2757,
12155,
272,
370,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
2313,
339,
961,
805,
5139,
3495,
367,
8552,
13,
15390,
27,
652,
911,
506,
4829,
272,
315,
5634,
413,
14,
20,
14,
272,
408,
272,
492,
3598,
272,
3598,
14,
4050,
8,
267,
298,
1918,
1067,
12495,
737,
658,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
1178,
64,
365,
298,
971,
267,
298,
6667,
27,
675,
314,
931,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
64,
298,
971,
267,
298,
23145,
4765,
267,
13413,
272,
776,
272,
687,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
492,
1790,
465,
1790,
63,
1100,
63,
6459,
272,
372,
1790,
63,
1100,
63,
6459,
8,
1069,
9,
199,
199,
318,
19213,
8,
1069,
304,
272,
408,
272,
9470,
12495,
626,
6571,
282,
22468,
1526,
12,
503,
314,
1059,
283,
4609,
21403,
1149,
7,
340,
272,
652,
965,
440,
2757,
2741,
701,
1902,
282,
2455,
7531,
503,
314,
10816,
272,
408,
272,
347,
485,
362,
63,
637,
837,
267,
1526,
275,
664,
63,
1418,
8,
1069,
9,
267,
340,
1526,
365,
488,
26,
288,
327,
1010,
1865,
370,
506,
7688,
370,
5647,
10201,
2256,
315,
314,
288,
327,
1930,
402,
3201,
4758,
12,
781,
675,
282,
13792,
574,
288,
327,
3140,
402,
8152,
376,
2701,
1211,
14,
288,
372,
283,
4609,
21403,
1149,
7,
267,
587,
26,
288,
372,
1526,
272,
485,
362,
63,
637,
275,
9617,
1547,
362,
63,
637,
12,
620,
9,
339,
372,
791,
10088,
63,
1418,
356,
485,
362,
63,
637,
342,
789,
199,
199,
318,
3105,
8,
1069,
304,
272,
298,
3407,
1067,
2860,
24606,
367,
10201,
2122,
272,
1067,
63,
9975,
275,
1052,
272,
340,
2202,
14,
5287,
436,
1056,
14,
10614,
14,
362,
360,
16058,
63,
7803,
358,
315,
2202,
14,
17681,
63,
12346,
26,
267,
1067,
63,
9975,
459,
1757,
418,
275,
715,
267,
687,
1639,
14,
697,
492,
1950,
267,
1067,
63,
9975,
459,
3009,
63,
10590,
418,
275,
1950,
14,
10590,
272,
372,
1067,
63,
9975,
199,
199,
318,
284,
1085,
78,
8,
1069,
304,
272,
687,
1639,
14,
1208,
492,
7761,
339,
1067,
63,
9975,
275,
1052,
272,
1067,
63,
9975,
459,
26886,
418,
275,
2202,
14,
26886,
272,
1067,
63,
9975,
459,
13947,
63,
6012,
418,
275,
7761,
14,
362,
63,
3671,
342,
272,
1067,
63,
9975,
459,
13947,
63,
34,
28904,
418,
275,
7761,
14,
362,
63,
3671,
63,
21555,
342,
339,
372,
1067,
63,
9975,
199,
199,
318,
2955,
8,
1069,
304,
272,
408,
272,
15747,
2955,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
339,
408,
272,
372,
791,
10449,
63,
2632,
356,
2202,
14,
10449,
63,
2632,
93,
199,
199,
318,
5898,
8,
1069,
304,
272,
408,
272,
15747,
5898,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
339,
408,
272,
372,
791,
13669,
63,
2632,
356,
2202,
14,
13669,
63,
2632,
93,
199,
199,
318,
1056,
8,
1069,
304,
272,
372,
791,
1069,
356,
1056,
93,
199,
199,
3,
3492,
77,
4590,
436,
3492,
77,
7521,
2141,
4566,
314,
3443,
2656,
1901,
2251,
626,
199,
3,
314,
1978,
2656,
883,
20647,
14,
9322,
5403,
1212,
1354,
2348,
1553,
2985,
1172,
199,
3,
2757,
12155,
370,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
492,
3492,
77,
7521,
2141,
465,
14849,
23554,
7521,
2141,
199,
504,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
492,
3492,
77,
4590,
465,
14849,
23554,
4590,
199,
199,
533,
3492,
77,
7521,
2141,
8,
10099,
23554,
7521,
2141,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
492,
3598,
267,
3598,
14,
4050,
8,
288,
24505,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
23554,
7521,
2141,
64,
365,
298,
971,
288,
298,
6667,
27,
675,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
23554,
7521,
2141,
64,
298,
971,
288,
298,
23145,
4765,
288,
29216,
15561,
267,
776,
267,
1613,
8,
23554,
7521,
2141,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
199,
199,
533,
3492,
77,
4590,
8,
10099,
23554,
4590,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
492,
3598,
267,
3598,
14,
4050,
8,
288,
24505,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
23554,
4590,
64,
365,
298,
971,
288,
298,
6667,
27,
675,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
23554,
4590,
64,
298,
971,
288,
298,
23145,
4765,
288,
29216,
15561,
267,
776,
267,
1613,
8,
23554,
4590,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
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
] |
[
199,
33,
663,
402,
1056,
21620,
626,
372,
11196,
370,
506,
9545,
1901,
282,
199,
1160,
1067,
14,
7048,
805,
6181,
314,
1056,
909,
465,
2399,
1454,
2725,
199,
460,
2529,
282,
2600,
370,
1050,
370,
314,
1067,
14,
199,
199,
20676,
787,
11812,
687,
314,
4260,
24877,
63,
9059,
63,
10494,
4149,
436,
1202,
701,
199,
17679,
14,
199,
624,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
5754,
14,
10088,
492,
664,
63,
1418,
199,
504,
1639,
14,
1208,
14,
15481,
492,
9617,
199,
199,
318,
1790,
8,
1069,
304,
272,
408,
272,
31404,
14,
961,
1067,
12495,
365,
314,
2269,
2909,
12,
436,
965,
2757,
12155,
272,
370,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
2313,
339,
961,
805,
5139,
3495,
367,
8552,
13,
15390,
27,
652,
911,
506,
4829,
272,
315,
5634,
413,
14,
20,
14,
272,
408,
272,
492,
3598,
272,
3598,
14,
4050,
8,
267,
298,
1918,
1067,
12495,
737,
658,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
1178,
64,
365,
298,
971,
267,
298,
6667,
27,
675,
314,
931,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
64,
298,
971,
267,
298,
23145,
4765,
267,
13413,
272,
776,
272,
687,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
492,
1790,
465,
1790,
63,
1100,
63,
6459,
272,
372,
1790,
63,
1100,
63,
6459,
8,
1069,
9,
199,
199,
318,
19213,
8,
1069,
304,
272,
408,
272,
9470,
12495,
626,
6571,
282,
22468,
1526,
12,
503,
314,
1059,
283,
4609,
21403,
1149,
7,
340,
272,
652,
965,
440,
2757,
2741,
701,
1902,
282,
2455,
7531,
503,
314,
10816,
272,
408,
272,
347,
485,
362,
63,
637,
837,
267,
1526,
275,
664,
63,
1418,
8,
1069,
9,
267,
340,
1526,
365,
488,
26,
288,
327,
1010,
1865,
370,
506,
7688,
370,
5647,
10201,
2256,
315,
314,
288,
327,
1930,
402,
3201,
4758,
12,
781,
675,
282,
13792,
574,
288,
327,
3140,
402,
8152,
376,
2701,
1211,
14,
288,
372,
283,
4609,
21403,
1149,
7,
267,
587,
26,
288,
372,
1526,
272,
485,
362,
63,
637,
275,
9617,
1547,
362,
63,
637,
12,
620,
9,
339,
372,
791,
10088,
63,
1418,
356,
485,
362,
63,
637,
342,
789,
199,
199,
318,
3105,
8,
1069,
304,
272,
298,
3407,
1067,
2860,
24606,
367,
10201,
2122,
272,
1067,
63,
9975,
275,
1052,
272,
340,
2202,
14,
5287,
436,
1056,
14,
10614,
14,
362,
360,
16058,
63,
7803,
358,
315,
2202,
14,
17681,
63,
12346,
26,
267,
1067,
63,
9975,
459,
1757,
418,
275,
715,
267,
687,
1639,
14,
697,
492,
1950,
267,
1067,
63,
9975,
459,
3009,
63,
10590,
418,
275,
1950,
14,
10590,
272,
372,
1067,
63,
9975,
199,
199,
318,
284,
1085,
78,
8,
1069,
304,
272,
687,
1639,
14,
1208,
492,
7761,
339,
1067,
63,
9975,
275,
1052,
272,
1067,
63,
9975,
459,
26886,
418,
275,
2202,
14,
26886,
272,
1067,
63,
9975,
459,
13947,
63,
6012,
418,
275,
7761,
14,
362,
63,
3671,
342,
272,
1067,
63,
9975,
459,
13947,
63,
34,
28904,
418,
275,
7761,
14,
362,
63,
3671,
63,
21555,
342,
339,
372,
1067,
63,
9975,
199,
199,
318,
2955,
8,
1069,
304,
272,
408,
272,
15747,
2955,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
339,
408,
272,
372,
791,
10449,
63,
2632,
356,
2202,
14,
10449,
63,
2632,
93,
199,
199,
318,
5898,
8,
1069,
304,
272,
408,
272,
15747,
5898,
13,
2407,
1067,
2860,
370,
314,
1067,
14,
339,
408,
272,
372,
791,
13669,
63,
2632,
356,
2202,
14,
13669,
63,
2632,
93,
199,
199,
318,
1056,
8,
1069,
304,
272,
372,
791,
1069,
356,
1056,
93,
199,
199,
3,
3492,
77,
4590,
436,
3492,
77,
7521,
2141,
4566,
314,
3443,
2656,
1901,
2251,
626,
199,
3,
314,
1978,
2656,
883,
20647,
14,
9322,
5403,
1212,
1354,
2348,
1553,
2985,
1172,
199,
3,
2757,
12155,
370,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
492,
3492,
77,
7521,
2141,
465,
14849,
23554,
7521,
2141,
199,
504,
1639,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
492,
3492,
77,
4590,
465,
14849,
23554,
4590,
199,
199,
533,
3492,
77,
7521,
2141,
8,
10099,
23554,
7521,
2141,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
492,
3598,
267,
3598,
14,
4050,
8,
288,
24505,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
23554,
7521,
2141,
64,
365,
298,
971,
288,
298,
6667,
27,
675,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
23554,
7521,
2141,
64,
298,
971,
288,
298,
23145,
4765,
288,
29216,
15561,
267,
776,
267,
1613,
8,
23554,
7521,
2141,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
199,
199,
533,
3492,
77,
4590,
8,
10099,
23554,
4590,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
492,
3598,
267,
3598,
14,
4050,
8,
288,
24505,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
23554,
4590,
64,
365,
298,
971,
288,
298,
6667,
27,
675,
658,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
23554,
4590,
64,
298,
971,
288,
298,
23145,
4765,
288,
29216,
15561,
267,
776,
267,
1613,
8,
23554,
4590,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
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,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
alex/kombu
|
kombu/tests/transport/test_filesystem.py
|
30
|
4288
|
from __future__ import absolute_import
import sys
import tempfile
from kombu import Connection, Exchange, Queue, Consumer, Producer
from kombu.tests.case import Case, SkipTest
class test_FilesystemTransport(Case):
def setUp(self):
if sys.platform == 'win32':
raise SkipTest('Needs win32con module')
try:
data_folder_in = tempfile.mkdtemp()
data_folder_out = tempfile.mkdtemp()
except Exception:
raise SkipTest('filesystem transport: cannot create tempfiles')
self.c = Connection(transport='filesystem',
transport_options={
'data_folder_in': data_folder_in,
'data_folder_out': data_folder_out,
})
self.p = Connection(transport='filesystem',
transport_options={
'data_folder_in': data_folder_out,
'data_folder_out': data_folder_in,
})
self.e = Exchange('test_transport_filesystem')
self.q = Queue('test_transport_filesystem',
exchange=self.e,
routing_key='test_transport_filesystem')
self.q2 = Queue('test_transport_filesystem2',
exchange=self.e,
routing_key='test_transport_filesystem2')
def test_produce_consume_noack(self):
producer = Producer(self.p.channel(), self.e)
consumer = Consumer(self.c.channel(), self.q, no_ack=True)
for i in range(10):
producer.publish({'foo': i},
routing_key='test_transport_filesystem')
_received = []
def callback(message_data, message):
_received.append(message)
consumer.register_callback(callback)
consumer.consume()
while 1:
if len(_received) == 10:
break
self.c.drain_events()
self.assertEqual(len(_received), 10)
def test_produce_consume(self):
producer_channel = self.p.channel()
consumer_channel = self.c.channel()
producer = Producer(producer_channel, self.e)
consumer1 = Consumer(consumer_channel, self.q)
consumer2 = Consumer(consumer_channel, self.q2)
self.q2(consumer_channel).declare()
for i in range(10):
producer.publish({'foo': i},
routing_key='test_transport_filesystem')
for i in range(10):
producer.publish({'foo': i},
routing_key='test_transport_filesystem2')
_received1 = []
_received2 = []
def callback1(message_data, message):
_received1.append(message)
message.ack()
def callback2(message_data, message):
_received2.append(message)
message.ack()
consumer1.register_callback(callback1)
consumer2.register_callback(callback2)
consumer1.consume()
consumer2.consume()
while 1:
if len(_received1) + len(_received2) == 20:
break
self.c.drain_events()
self.assertEqual(len(_received1) + len(_received2), 20)
# compression
producer.publish({'compressed': True},
routing_key='test_transport_filesystem',
compression='zlib')
m = self.q(consumer_channel).get()
self.assertDictEqual(m.payload, {'compressed': True})
# queue.delete
for i in range(10):
producer.publish({'foo': i},
routing_key='test_transport_filesystem')
self.assertTrue(self.q(consumer_channel).get())
self.q(consumer_channel).delete()
self.q(consumer_channel).declare()
self.assertIsNone(self.q(consumer_channel).get())
# queue.purge
for i in range(10):
producer.publish({'foo': i},
routing_key='test_transport_filesystem2')
self.assertTrue(self.q2(consumer_channel).get())
self.q2(consumer_channel).purge()
self.assertIsNone(self.q2(consumer_channel).get())
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
984,
199,
646,
5549,
199,
199,
504,
1022,
676,
464,
492,
8113,
12,
25655,
12,
10703,
12,
1448,
5391,
12,
2165,
7610,
199,
199,
504,
1022,
676,
464,
14,
2219,
14,
2546,
492,
12425,
12,
18795,
421,
199,
533,
511,
63,
1173,
2253,
7836,
8,
1538,
304,
339,
347,
3613,
8,
277,
304,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
746,
18795,
360,
28390,
4747,
708,
388,
859,
358,
267,
862,
26,
288,
666,
63,
3741,
63,
262,
275,
5549,
14,
11983,
342,
288,
666,
63,
3741,
63,
548,
275,
5549,
14,
11983,
342,
267,
871,
2186,
26,
288,
746,
18795,
360,
11381,
7773,
26,
3913,
1218,
2388,
1725,
358,
267,
291,
14,
67,
275,
8113,
8,
5545,
534,
11381,
297,
1169,
7773,
63,
1419,
3126,
1816,
283,
576,
63,
3741,
63,
262,
356,
666,
63,
3741,
63,
262,
12,
1816,
283,
576,
63,
3741,
63,
548,
356,
666,
63,
3741,
63,
548,
12,
1169,
3828,
267,
291,
14,
80,
275,
8113,
8,
5545,
534,
11381,
297,
1169,
7773,
63,
1419,
3126,
1816,
283,
576,
63,
3741,
63,
262,
356,
666,
63,
3741,
63,
548,
12,
1816,
283,
576,
63,
3741,
63,
548,
356,
666,
63,
3741,
63,
262,
12,
1169,
3828,
267,
291,
14,
69,
275,
25655,
360,
396,
63,
5545,
63,
11381,
358,
267,
291,
14,
81,
275,
10703,
360,
396,
63,
5545,
63,
11381,
297,
2432,
15343,
29,
277,
14,
69,
12,
2432,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
267,
291,
14,
81,
18,
275,
10703,
360,
396,
63,
5545,
63,
11381,
18,
297,
717,
15343,
29,
277,
14,
69,
12,
717,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
18,
358,
339,
347,
511,
63,
7832,
63,
10235,
63,
889,
564,
8,
277,
304,
267,
17339,
275,
2165,
7610,
8,
277,
14,
80,
14,
2775,
1062,
291,
14,
69,
9,
267,
9790,
275,
1448,
5391,
8,
277,
14,
67,
14,
2775,
1062,
291,
14,
81,
12,
949,
63,
564,
29,
549,
9,
398,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
398,
485,
9226,
275,
942,
398,
347,
3233,
8,
1188,
63,
576,
12,
1245,
304,
288,
485,
9226,
14,
740,
8,
1188,
9,
398,
9790,
14,
2683,
63,
3058,
8,
3058,
9,
267,
9790,
14,
10235,
342,
398,
1830,
413,
26,
288,
340,
822,
1547,
9226,
9,
508,
1616,
26,
355,
2059,
288,
291,
14,
67,
14,
30324,
63,
4368,
342,
398,
291,
14,
629,
8,
552,
1547,
9226,
395,
1616,
9,
339,
347,
511,
63,
7832,
63,
10235,
8,
277,
304,
267,
17339,
63,
2775,
275,
291,
14,
80,
14,
2775,
342,
267,
9790,
63,
2775,
275,
291,
14,
67,
14,
2775,
342,
267,
17339,
275,
2165,
7610,
8,
16376,
63,
2775,
12,
291,
14,
69,
9,
267,
9790,
17,
275,
1448,
5391,
8,
8542,
63,
2775,
12,
291,
14,
81,
9,
267,
9790,
18,
275,
1448,
5391,
8,
8542,
63,
2775,
12,
291,
14,
81,
18,
9,
267,
291,
14,
81,
18,
8,
8542,
63,
2775,
680,
16536,
342,
398,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
18,
358,
398,
485,
9226,
17,
275,
942,
267,
485,
9226,
18,
275,
942,
398,
347,
3233,
17,
8,
1188,
63,
576,
12,
1245,
304,
288,
485,
9226,
17,
14,
740,
8,
1188,
9,
288,
1245,
14,
564,
342,
398,
347,
3233,
18,
8,
1188,
63,
576,
12,
1245,
304,
288,
485,
9226,
18,
14,
740,
8,
1188,
9,
288,
1245,
14,
564,
342,
398,
9790,
17,
14,
2683,
63,
3058,
8,
3058,
17,
9,
267,
9790,
18,
14,
2683,
63,
3058,
8,
3058,
18,
9,
398,
9790,
17,
14,
10235,
342,
267,
9790,
18,
14,
10235,
342,
398,
1830,
413,
26,
288,
340,
822,
1547,
9226,
17,
9,
435,
822,
1547,
9226,
18,
9,
508,
3388,
26,
355,
2059,
288,
291,
14,
67,
14,
30324,
63,
4368,
342,
398,
291,
14,
629,
8,
552,
1547,
9226,
17,
9,
435,
822,
1547,
9226,
18,
395,
3388,
9,
398,
327,
10291,
267,
17339,
14,
4763,
3252,
10895,
356,
715,
1386,
586,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
297,
586,
10291,
534,
15371,
358,
267,
333,
275,
291,
14,
81,
8,
8542,
63,
2775,
680,
362,
342,
267,
291,
14,
19512,
8,
77,
14,
4749,
12,
791,
10895,
356,
715,
1552,
398,
327,
4126,
14,
1807,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
267,
291,
14,
1815,
8,
277,
14,
81,
8,
8542,
63,
2775,
680,
362,
1012,
267,
291,
14,
81,
8,
8542,
63,
2775,
680,
1807,
342,
267,
291,
14,
81,
8,
8542,
63,
2775,
680,
16536,
342,
267,
291,
14,
7702,
8,
277,
14,
81,
8,
8542,
63,
2775,
680,
362,
1012,
398,
327,
4126,
14,
18254,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
18,
358,
267,
291,
14,
1815,
8,
277,
14,
81,
18,
8,
8542,
63,
2775,
680,
362,
1012,
267,
291,
14,
81,
18,
8,
8542,
63,
2775,
680,
18254,
342,
267,
291,
14,
7702,
8,
277,
14,
81,
18,
8,
8542,
63,
2775,
680,
362,
1012,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
984,
199,
646,
5549,
199,
199,
504,
1022,
676,
464,
492,
8113,
12,
25655,
12,
10703,
12,
1448,
5391,
12,
2165,
7610,
199,
199,
504,
1022,
676,
464,
14,
2219,
14,
2546,
492,
12425,
12,
18795,
421,
199,
533,
511,
63,
1173,
2253,
7836,
8,
1538,
304,
339,
347,
3613,
8,
277,
304,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
746,
18795,
360,
28390,
4747,
708,
388,
859,
358,
267,
862,
26,
288,
666,
63,
3741,
63,
262,
275,
5549,
14,
11983,
342,
288,
666,
63,
3741,
63,
548,
275,
5549,
14,
11983,
342,
267,
871,
2186,
26,
288,
746,
18795,
360,
11381,
7773,
26,
3913,
1218,
2388,
1725,
358,
267,
291,
14,
67,
275,
8113,
8,
5545,
534,
11381,
297,
1169,
7773,
63,
1419,
3126,
1816,
283,
576,
63,
3741,
63,
262,
356,
666,
63,
3741,
63,
262,
12,
1816,
283,
576,
63,
3741,
63,
548,
356,
666,
63,
3741,
63,
548,
12,
1169,
3828,
267,
291,
14,
80,
275,
8113,
8,
5545,
534,
11381,
297,
1169,
7773,
63,
1419,
3126,
1816,
283,
576,
63,
3741,
63,
262,
356,
666,
63,
3741,
63,
548,
12,
1816,
283,
576,
63,
3741,
63,
548,
356,
666,
63,
3741,
63,
262,
12,
1169,
3828,
267,
291,
14,
69,
275,
25655,
360,
396,
63,
5545,
63,
11381,
358,
267,
291,
14,
81,
275,
10703,
360,
396,
63,
5545,
63,
11381,
297,
2432,
15343,
29,
277,
14,
69,
12,
2432,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
267,
291,
14,
81,
18,
275,
10703,
360,
396,
63,
5545,
63,
11381,
18,
297,
717,
15343,
29,
277,
14,
69,
12,
717,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
18,
358,
339,
347,
511,
63,
7832,
63,
10235,
63,
889,
564,
8,
277,
304,
267,
17339,
275,
2165,
7610,
8,
277,
14,
80,
14,
2775,
1062,
291,
14,
69,
9,
267,
9790,
275,
1448,
5391,
8,
277,
14,
67,
14,
2775,
1062,
291,
14,
81,
12,
949,
63,
564,
29,
549,
9,
398,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
398,
485,
9226,
275,
942,
398,
347,
3233,
8,
1188,
63,
576,
12,
1245,
304,
288,
485,
9226,
14,
740,
8,
1188,
9,
398,
9790,
14,
2683,
63,
3058,
8,
3058,
9,
267,
9790,
14,
10235,
342,
398,
1830,
413,
26,
288,
340,
822,
1547,
9226,
9,
508,
1616,
26,
355,
2059,
288,
291,
14,
67,
14,
30324,
63,
4368,
342,
398,
291,
14,
629,
8,
552,
1547,
9226,
395,
1616,
9,
339,
347,
511,
63,
7832,
63,
10235,
8,
277,
304,
267,
17339,
63,
2775,
275,
291,
14,
80,
14,
2775,
342,
267,
9790,
63,
2775,
275,
291,
14,
67,
14,
2775,
342,
267,
17339,
275,
2165,
7610,
8,
16376,
63,
2775,
12,
291,
14,
69,
9,
267,
9790,
17,
275,
1448,
5391,
8,
8542,
63,
2775,
12,
291,
14,
81,
9,
267,
9790,
18,
275,
1448,
5391,
8,
8542,
63,
2775,
12,
291,
14,
81,
18,
9,
267,
291,
14,
81,
18,
8,
8542,
63,
2775,
680,
16536,
342,
398,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
18,
358,
398,
485,
9226,
17,
275,
942,
267,
485,
9226,
18,
275,
942,
398,
347,
3233,
17,
8,
1188,
63,
576,
12,
1245,
304,
288,
485,
9226,
17,
14,
740,
8,
1188,
9,
288,
1245,
14,
564,
342,
398,
347,
3233,
18,
8,
1188,
63,
576,
12,
1245,
304,
288,
485,
9226,
18,
14,
740,
8,
1188,
9,
288,
1245,
14,
564,
342,
398,
9790,
17,
14,
2683,
63,
3058,
8,
3058,
17,
9,
267,
9790,
18,
14,
2683,
63,
3058,
8,
3058,
18,
9,
398,
9790,
17,
14,
10235,
342,
267,
9790,
18,
14,
10235,
342,
398,
1830,
413,
26,
288,
340,
822,
1547,
9226,
17,
9,
435,
822,
1547,
9226,
18,
9,
508,
3388,
26,
355,
2059,
288,
291,
14,
67,
14,
30324,
63,
4368,
342,
398,
291,
14,
629,
8,
552,
1547,
9226,
17,
9,
435,
822,
1547,
9226,
18,
395,
3388,
9,
398,
327,
10291,
267,
17339,
14,
4763,
3252,
10895,
356,
715,
1386,
586,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
297,
586,
10291,
534,
15371,
358,
267,
333,
275,
291,
14,
81,
8,
8542,
63,
2775,
680,
362,
342,
267,
291,
14,
19512,
8,
77,
14,
4749,
12,
791,
10895,
356,
715,
1552,
398,
327,
4126,
14,
1807,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
358,
267,
291,
14,
1815,
8,
277,
14,
81,
8,
8542,
63,
2775,
680,
362,
1012,
267,
291,
14,
81,
8,
8542,
63,
2775,
680,
1807,
342,
267,
291,
14,
81,
8,
8542,
63,
2775,
680,
16536,
342,
267,
291,
14,
7702,
8,
277,
14,
81,
8,
8542,
63,
2775,
680,
362,
1012,
398,
327,
4126,
14,
18254,
267,
367,
284,
315,
1425,
8,
709,
304,
288,
17339,
14,
4763,
3252,
1421,
356,
284,
1386,
2490,
14870,
63,
498,
534,
396,
63,
5545,
63,
11381,
18,
358,
267,
291,
14,
1815,
8,
277,
14,
81,
18,
8,
8542,
63,
2775,
680,
362,
1012,
267,
291,
14,
81,
18,
8,
8542,
63,
2775,
680,
18254,
342,
267,
291,
14,
7702,
8,
277,
14,
81,
18,
8,
8542,
63,
2775,
680,
362,
1012,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dchud/sentinel
|
bin/scripts/test-matplotlib-evidence.py
|
1
|
5562
|
#!/usr/bin/env python
from pylab import *
from canary.context import Context
from canary.loader import QueuedRecord
from canary.search import SearchIndex
from canary.study import Species, Study, Methodology
linkages = {
'rel': 'Relationships',
'inter': 'Interspecies',
'exp': 'Exposures',
'out': 'Outcomes',
'exp_sh': 'Shared Exposures',
'out_sh': 'Shared Outcomes',
'gen': 'Genomic Data'}
linkages_attrs = (
('rel', 'relationships'),
('exp', 'exposures'),
('out', 'outcomes'),
('inter', 'interspecies'),
('gen', 'genomic'),
('exp_sh', 'exposure_linkage'),
('out_sh', 'outcome_linkage'),
)
linkages_sorted = linkages.items()
linkages_sorted.sort()
linkage_keys = ('exp', 'out', 'rel', 'inter', 'exp_sh', 'out_sh', 'gen')
methodology_types = {}
for val, id in Methodology().TYPES.items():
methodology_types[id] = val
start = dict(zip(methodology_types.keys(), array([0] * len(linkages))))
def makeplot (context, token, records):
this_module = sys.modules[__name__]
N = len(linkage_keys)
ind = arange(N)
width = 0.35
meth_type_count = {}
study_count = dict(zip(linkages, array([0] * len(linkages))))
for id, type in linkages_attrs:
meth_type_count[id] = start.copy()
for rec in records:
study = Study(context, rec.study_id)
for attr, key in linkages_attrs:
if getattr(study, 'has_%s' % key):
study_count[attr] += 1
for meth in study.methodologies:
meth_type_count[attr][meth.study_type_id] += 1
rc('grid', color=0.85, linestyle='-', linewidth=0.3)
grid(True)
yoff = array([0] * N)
s = """
'experimental' : 1,
'descriptive' : 2,
'aggregate' : 3,
'cross sectional' : 4,
'cohort' : 5,
'case control' : 6,
'disease model' : 7,
"""
print ['%s %s\n' % (k, v) for k, v in meth_type_count.items()]
p_exp_x = [meth_type_count[key][1] for key in linkage_keys]
p_exp = bar(ind, p_exp_x, width, color='#993333', bottom=yoff)
yoff = yoff + p_exp_x
p_coh_x = [meth_type_count[key][5] for key in linkage_keys]
p_coh = bar(ind, p_coh_x, width, color='#FF9933', bottom=yoff)
yoff = yoff + p_coh_x
p_csec_x = [meth_type_count[key][4] for key in linkage_keys]
p_csec = bar(ind, p_csec_x, width, color='#99CC99', bottom=yoff)
yoff = yoff + p_csec_x
p_desc_x = [meth_type_count[key][2] for key in linkage_keys]
p_desc = bar(ind, p_desc_x, width, color='#6666CC', bottom=yoff)
yoff = yoff + p_desc_x
#p_agg_x = [meth_type_count[key][3] for key in linkage_keys]
#p_agg = bar(ind, p_agg_x, width, color='#CCCC00', bottom=yoff)
#yoff = yoff + p_agg_x
#p_cc_x = [meth_type_count[key][6] for key in linkage_keys]
#p_cc = bar(ind, p_cc_x, width, color='#CC66FF', bottom=yoff)
#yoff = yoff + p_cc_x
#p_dm_x = [meth_type_count[key][7] for key in linkage_keys]
#p_dm = bar(ind, p_dm_x, width, color='#993366', bottom=yoff)
#yoff = yoff + p_dm_x
precords_x = array([len(records)] * N)
#precords = bar(ind+width/3, precords_x, width/3, color='#999999', bottom=0)
precords = plot(precords_x, color='#AAAAAA', marker='-', linewidth=1.5)
pstudies_x = [study_count[k] for k in linkage_keys]
pstudies = bar(ind+width/3, pstudies_x, width/3, color='#EEEEEE', bottom=0)
max_val = max(yoff)
xlabel('Linkages to Human Health')
ylabel('# Methodologies by Type for Studies with Linkages')
title('Animal Sentinels for "%s" (%s records)' %
(token, len(records)), size=12)
xticks(ind+width/2, [linkages[k] for k in linkage_keys],
rotation=20, size=6)
step = max_val / 5
yticks(arange(0, max_val+(step*3), step))
legend((p_exp[0], p_coh[0], p_csec[0], p_desc[0],
precords[0], pstudies[0]),
('Experimental', 'Cohort',
'Cross-Sectional', 'Descriptive',
'# Studies Total', '# Records w/Linkage'))
## legend((p_exp[0], p_desc[0], p_agg[0], p_csec[0], p_coh[0],
## p_cc[0], p_dm[0], precords[0], pstudies[0]),
## ('Experimental', 'Descriptive', 'Aggregate',
## 'Cross-Sectional', 'Cohort', 'Case-Control', 'Disease Model',
#savefig(('%s' % token.replace(' ', '_')))
show()
cla()
if __name__ == '__main__':
context = Context()
search_index = SearchIndex(context)
searches = (
'Lead [exposure]',
'Hantavirus [exposure]',
'peromyscus [species]',
'Michigan [location]',
'DDT [exposure]',
'2003 [year]',
'cats and dogs',
'"Burger J" [author]',
'cross-sectional [methodology]',
'case-control [methodology] and cattle [species]',
'disease-model [methodology]',
'"age factors" [risk_factors]',
'Sarin [exposure]',
'Arsenic [exposure]',
'"Bacillus anthracis" [exposure]',
'"West Nile Virus" [exposure]',
'"Water Pollutants, Chemical" [exposure]',
)
for t in searches:
hits, searcher = search_index.search(t)
result_set = []
for i, doc in hits:
uid = doc.get(str('uid'))
record = QueuedRecord(context, uid)
if record.status == record.STATUS_CURATED:
result_set.append(record)
searcher.close()
makeplot(context, t, result_set)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
19199,
492,
627,
199,
199,
504,
883,
695,
14,
1100,
492,
9470,
199,
504,
883,
695,
14,
3422,
492,
10703,
68,
5433,
199,
504,
883,
695,
14,
1733,
492,
8730,
2681,
199,
504,
883,
695,
14,
22851,
492,
5367,
397,
12,
1933,
14181,
12,
9075,
7085,
421,
199,
1073,
7441,
275,
469,
272,
283,
3369,
356,
283,
21096,
83,
297,
5591,
283,
1058,
356,
283,
607,
878,
910,
397,
297,
5591,
283,
1474,
356,
283,
920,
1712,
1482,
297,
5591,
283,
548,
356,
283,
2204,
31430,
297,
5591,
283,
1474,
63,
609,
356,
283,
12197,
1316,
1712,
1482,
297,
272,
283,
548,
63,
609,
356,
283,
12197,
6219,
31430,
297,
272,
283,
2268,
356,
283,
8168,
676,
530,
3918,
936,
199,
1073,
7441,
63,
3288,
275,
334,
272,
661,
3369,
297,
283,
24034,
659,
272,
661,
1474,
297,
283,
476,
1712,
1482,
659,
272,
661,
548,
297,
283,
17502,
83,
659,
272,
661,
1058,
297,
283,
11005,
910,
397,
659,
272,
661,
2268,
297,
283,
2268,
676,
530,
659,
272,
661,
1474,
63,
609,
297,
283,
28480,
63,
26459,
659,
272,
661,
548,
63,
609,
297,
283,
17502,
63,
26459,
659,
272,
776,
26339,
199,
1073,
7441,
63,
5917,
275,
2142,
7441,
14,
1744,
342,
199,
1073,
7441,
63,
5917,
14,
3191,
342,
199,
26459,
63,
1612,
275,
661,
1474,
297,
283,
548,
297,
283,
3369,
297,
283,
1058,
297,
283,
1474,
63,
609,
297,
283,
548,
63,
609,
297,
283,
2268,
358,
199,
199,
765,
7085,
63,
1313,
275,
1052,
199,
509,
1139,
12,
1305,
315,
9075,
7085,
1252,
7893,
14,
1744,
837,
272,
1083,
7085,
63,
1313,
59,
344,
61,
275,
1139,
199,
928,
275,
1211,
8,
3065,
8,
765,
7085,
63,
1313,
14,
1612,
1062,
1625,
779,
16,
61,
627,
822,
8,
1073,
7441,
7845,
421,
199,
318,
1852,
2798,
334,
1100,
12,
1526,
12,
5767,
304,
339,
642,
63,
578,
275,
984,
14,
3112,
28894,
354,
22705,
272,
653,
275,
822,
8,
26459,
63,
1612,
9,
272,
7654,
275,
20461,
8,
46,
9,
272,
3462,
275,
378,
14,
1276,
339,
12750,
63,
466,
63,
835,
275,
1052,
339,
25932,
63,
835,
275,
1211,
8,
3065,
8,
1073,
7441,
12,
1625,
779,
16,
61,
627,
822,
8,
1073,
7441,
7845,
272,
367,
1305,
12,
730,
315,
2142,
7441,
63,
3288,
26,
267,
12750,
63,
466,
63,
835,
59,
344,
61,
275,
1343,
14,
1574,
342,
339,
367,
6488,
315,
5767,
26,
267,
25932,
275,
1933,
14181,
8,
1100,
12,
6488,
14,
22851,
63,
344,
9,
267,
367,
1921,
12,
790,
315,
2142,
7441,
63,
3288,
26,
288,
340,
2519,
8,
22851,
12,
283,
1989,
4970,
83,
7,
450,
790,
304,
355,
25932,
63,
835,
59,
962,
61,
847,
413,
355,
367,
12750,
315,
25932,
14,
765,
79,
15241,
26,
490,
12750,
63,
466,
63,
835,
59,
962,
1527,
5247,
14,
22851,
63,
466,
63,
344,
61,
847,
413,
2490,
586,
272,
4819,
360,
3825,
297,
3164,
29,
16,
14,
2426,
12,
27880,
534,
14382,
21213,
29,
16,
14,
19,
9,
272,
6068,
8,
549,
9,
339,
612,
1997,
275,
1625,
779,
16,
61,
627,
653,
9,
2286,
308,
275,
408,
288,
283,
18924,
7,
520,
413,
12,
267,
283,
271,
729,
21701,
7,
520,
499,
12,
267,
283,
7516,
7,
520,
650,
12,
267,
283,
7925,
3420,
279,
7,
520,
841,
12,
267,
283,
10403,
7,
520,
959,
12,
267,
283,
2546,
3304,
7,
520,
1227,
12,
267,
283,
328,
261,
482,
1402,
7,
520,
1520,
12,
267,
408,
2286,
870,
15926,
83,
450,
83,
60,
78,
7,
450,
334,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
12750,
63,
466,
63,
835,
14,
1744,
5106,
2286,
299,
63,
1474,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
17,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
1474,
275,
4681,
8,
688,
12,
299,
63,
1474,
63,
88,
12,
3462,
12,
3164,
26431,
1020,
6772,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
1474,
63,
88,
2286,
299,
63,
331,
72,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
21,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
331,
72,
275,
4681,
8,
688,
12,
299,
63,
331,
72,
63,
88,
12,
3462,
12,
3164,
26431,
1665,
1020,
1153,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
331,
72,
63,
88,
2286,
299,
63,
67,
3321,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
20,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
67,
3321,
275,
4681,
8,
688,
12,
299,
63,
67,
3321,
63,
88,
12,
3462,
12,
3164,
26431,
1020,
2571,
1020,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
67,
3321,
63,
88,
2286,
299,
63,
3257,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
18,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
3257,
275,
4681,
8,
688,
12,
299,
63,
3257,
63,
88,
12,
3462,
12,
3164,
26431,
6997,
2571,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
3257,
63,
88,
5493,
327,
80,
63,
13452,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
19,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
327,
80,
63,
13452,
275,
4681,
8,
688,
12,
299,
63,
13452,
63,
88,
12,
3462,
12,
3164,
26431,
27994,
383,
297,
9048,
29,
89,
1997,
9,
272,
327,
89,
1997,
275,
612,
1997,
435,
299,
63,
13452,
63,
88,
2286,
327,
80,
63,
2055,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
22,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
327,
80,
63,
2055,
275,
4681,
8,
688,
12,
299,
63,
2055,
63,
88,
12,
3462,
12,
3164,
26431,
2571,
1272,
1665,
297,
9048,
29,
89,
1997,
9,
272,
327,
89,
1997,
275,
612,
1997,
435,
299,
63,
2055,
63,
88,
2286,
327,
80
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
19199,
492,
627,
199,
199,
504,
883,
695,
14,
1100,
492,
9470,
199,
504,
883,
695,
14,
3422,
492,
10703,
68,
5433,
199,
504,
883,
695,
14,
1733,
492,
8730,
2681,
199,
504,
883,
695,
14,
22851,
492,
5367,
397,
12,
1933,
14181,
12,
9075,
7085,
421,
199,
1073,
7441,
275,
469,
272,
283,
3369,
356,
283,
21096,
83,
297,
5591,
283,
1058,
356,
283,
607,
878,
910,
397,
297,
5591,
283,
1474,
356,
283,
920,
1712,
1482,
297,
5591,
283,
548,
356,
283,
2204,
31430,
297,
5591,
283,
1474,
63,
609,
356,
283,
12197,
1316,
1712,
1482,
297,
272,
283,
548,
63,
609,
356,
283,
12197,
6219,
31430,
297,
272,
283,
2268,
356,
283,
8168,
676,
530,
3918,
936,
199,
1073,
7441,
63,
3288,
275,
334,
272,
661,
3369,
297,
283,
24034,
659,
272,
661,
1474,
297,
283,
476,
1712,
1482,
659,
272,
661,
548,
297,
283,
17502,
83,
659,
272,
661,
1058,
297,
283,
11005,
910,
397,
659,
272,
661,
2268,
297,
283,
2268,
676,
530,
659,
272,
661,
1474,
63,
609,
297,
283,
28480,
63,
26459,
659,
272,
661,
548,
63,
609,
297,
283,
17502,
63,
26459,
659,
272,
776,
26339,
199,
1073,
7441,
63,
5917,
275,
2142,
7441,
14,
1744,
342,
199,
1073,
7441,
63,
5917,
14,
3191,
342,
199,
26459,
63,
1612,
275,
661,
1474,
297,
283,
548,
297,
283,
3369,
297,
283,
1058,
297,
283,
1474,
63,
609,
297,
283,
548,
63,
609,
297,
283,
2268,
358,
199,
199,
765,
7085,
63,
1313,
275,
1052,
199,
509,
1139,
12,
1305,
315,
9075,
7085,
1252,
7893,
14,
1744,
837,
272,
1083,
7085,
63,
1313,
59,
344,
61,
275,
1139,
199,
928,
275,
1211,
8,
3065,
8,
765,
7085,
63,
1313,
14,
1612,
1062,
1625,
779,
16,
61,
627,
822,
8,
1073,
7441,
7845,
421,
199,
318,
1852,
2798,
334,
1100,
12,
1526,
12,
5767,
304,
339,
642,
63,
578,
275,
984,
14,
3112,
28894,
354,
22705,
272,
653,
275,
822,
8,
26459,
63,
1612,
9,
272,
7654,
275,
20461,
8,
46,
9,
272,
3462,
275,
378,
14,
1276,
339,
12750,
63,
466,
63,
835,
275,
1052,
339,
25932,
63,
835,
275,
1211,
8,
3065,
8,
1073,
7441,
12,
1625,
779,
16,
61,
627,
822,
8,
1073,
7441,
7845,
272,
367,
1305,
12,
730,
315,
2142,
7441,
63,
3288,
26,
267,
12750,
63,
466,
63,
835,
59,
344,
61,
275,
1343,
14,
1574,
342,
339,
367,
6488,
315,
5767,
26,
267,
25932,
275,
1933,
14181,
8,
1100,
12,
6488,
14,
22851,
63,
344,
9,
267,
367,
1921,
12,
790,
315,
2142,
7441,
63,
3288,
26,
288,
340,
2519,
8,
22851,
12,
283,
1989,
4970,
83,
7,
450,
790,
304,
355,
25932,
63,
835,
59,
962,
61,
847,
413,
355,
367,
12750,
315,
25932,
14,
765,
79,
15241,
26,
490,
12750,
63,
466,
63,
835,
59,
962,
1527,
5247,
14,
22851,
63,
466,
63,
344,
61,
847,
413,
2490,
586,
272,
4819,
360,
3825,
297,
3164,
29,
16,
14,
2426,
12,
27880,
534,
14382,
21213,
29,
16,
14,
19,
9,
272,
6068,
8,
549,
9,
339,
612,
1997,
275,
1625,
779,
16,
61,
627,
653,
9,
2286,
308,
275,
408,
288,
283,
18924,
7,
520,
413,
12,
267,
283,
271,
729,
21701,
7,
520,
499,
12,
267,
283,
7516,
7,
520,
650,
12,
267,
283,
7925,
3420,
279,
7,
520,
841,
12,
267,
283,
10403,
7,
520,
959,
12,
267,
283,
2546,
3304,
7,
520,
1227,
12,
267,
283,
328,
261,
482,
1402,
7,
520,
1520,
12,
267,
408,
2286,
870,
15926,
83,
450,
83,
60,
78,
7,
450,
334,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
12750,
63,
466,
63,
835,
14,
1744,
5106,
2286,
299,
63,
1474,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
17,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
1474,
275,
4681,
8,
688,
12,
299,
63,
1474,
63,
88,
12,
3462,
12,
3164,
26431,
1020,
6772,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
1474,
63,
88,
2286,
299,
63,
331,
72,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
21,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
331,
72,
275,
4681,
8,
688,
12,
299,
63,
331,
72,
63,
88,
12,
3462,
12,
3164,
26431,
1665,
1020,
1153,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
331,
72,
63,
88,
2286,
299,
63,
67,
3321,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
20,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
67,
3321,
275,
4681,
8,
688,
12,
299,
63,
67,
3321,
63,
88,
12,
3462,
12,
3164,
26431,
1020,
2571,
1020,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
67,
3321,
63,
88,
2286,
299,
63,
3257,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
18,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
299,
63,
3257,
275,
4681,
8,
688,
12,
299,
63,
3257,
63,
88,
12,
3462,
12,
3164,
26431,
6997,
2571,
297,
9048,
29,
89,
1997,
9,
272,
612,
1997,
275,
612,
1997,
435,
299,
63,
3257,
63,
88,
5493,
327,
80,
63,
13452,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
19,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
327,
80,
63,
13452,
275,
4681,
8,
688,
12,
299,
63,
13452,
63,
88,
12,
3462,
12,
3164,
26431,
27994,
383,
297,
9048,
29,
89,
1997,
9,
272,
327,
89,
1997,
275,
612,
1997,
435,
299,
63,
13452,
63,
88,
2286,
327,
80,
63,
2055,
63,
88,
275,
359,
5247,
63,
466,
63,
835,
59,
498,
1527,
22,
61,
367,
790,
315,
26087,
63,
1612,
61,
272,
327,
80,
63,
2055,
275,
4681,
8,
688,
12,
299,
63,
2055,
63,
88,
12,
3462,
12,
3164,
26431,
2571,
1272,
1665,
297,
9048,
29,
89,
1997,
9,
272,
327,
89,
1997,
275,
612,
1997,
435,
299,
63,
2055,
63,
88,
2286,
327,
80,
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,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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
] |
caesar2164/edx-platform
|
openedx/core/djangoapps/self_paced/migrations/0001_initial.py
|
86
|
1203
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='SelfPacedConfiguration',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')),
('enabled', models.BooleanField(default=False, verbose_name='Enabled')),
('enable_course_home_improvements', models.BooleanField(default=False, verbose_name='Enable course home page improvements.')),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, editable=False, to=settings.AUTH_USER_MODEL, null=True, verbose_name='Changed by')),
],
options={
'ordering': ('-change_date',),
'abstract': False,
},
),
]
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
6180,
14,
31925,
63,
8575,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
12887,
4232,
6867,
5688,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1461,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
4001,
1434,
3855,
355,
661,
3827,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6589,
3855,
355,
661,
4296,
63,
1972,
63,
4219,
63,
3236,
11750,
1470,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6476,
2518,
5629,
2034,
19053,
1470,
2659,
395,
355,
661,
2489,
63,
991,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
29148,
12,
14783,
29,
797,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
6970,
701,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
12291,
1461,
63,
602,
5529,
355,
283,
6198,
356,
756,
12,
288,
1660,
267,
2318,
272,
1622,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
6180,
14,
31925,
63,
8575,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
12887,
4232,
6867,
5688,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1461,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
4001,
1434,
3855,
355,
661,
3827,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6589,
3855,
355,
661,
4296,
63,
1972,
63,
4219,
63,
3236,
11750,
1470,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6476,
2518,
5629,
2034,
19053,
1470,
2659,
395,
355,
661,
2489,
63,
991,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
29148,
12,
14783,
29,
797,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2973,
29,
549,
12,
3376,
63,
354,
534,
6970,
701,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
7128,
356,
12291,
1461,
63,
602,
5529,
355,
283,
6198,
356,
756,
12,
288,
1660,
267,
2318,
272,
1622,
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,
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,
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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
] |
mcku/elasticsearch
|
dev-tools/upgrade-tests.py
|
118
|
15291
|
# Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch licenses this file to you 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 random
import os
import tempfile
import shutil
import subprocess
import time
import argparse
import logging
import sys
import re
from datetime import datetime
try:
from elasticsearch import Elasticsearch
from elasticsearch.exceptions import ConnectionError
from elasticsearch.exceptions import TransportError
except ImportError as e:
print('Can\'t import elasticsearch please install `sudo pip install elasticsearch`')
raise e
'''This file executes a basic upgrade test by running a full cluster restart.
The upgrade test starts 2 or more nodes of an old elasticserach version, indexes
a random number of documents into the running nodes and executes a full cluster restart.
After the nodes are recovered a small set of basic checks are executed to ensure all
documents are still searchable and field data can be loaded etc.
NOTE: This script requires the elasticsearch python client `elasticsearch-py` run the following command to install:
`sudo pip install elasticsearch`
if you are running python3 you need to install the client using pip3. On OSX `pip3` will be included in the Python 3.4
release available on `https://www.python.org/download/`:
`sudo pip3 install elasticsearch`
See `https://github.com/elasticsearch/elasticsearch-py` for details
In order to run this test two different version of elasticsearch are required. Both need to be unpacked into
the same directory:
```
$ cd /path/to/elasticsearch/clone
$ mkdir backwards && cd backwards
$ wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.1.tar.gz
$ wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.13.tar.gz
$ tar -zxvf elasticsearch-1.3.1.tar.gz && tar -zxvf elasticsearch-0.90.13.tar.gz
$ cd ..
$ python dev-tools/upgrade-tests.py --version.backwards 0.90.13 --version.current 1.3.1
```
'''
BLACK_LIST = {'1.2.0' : { 'reason': 'Contains a major bug where routing hashes are not consistent with previous version',
'issue': 'https://github.com/elasticsearch/elasticsearch/pull/6393'},
'1.3.0' : { 'reason': 'Lucene Related bug prevents upgrades from 0.90.7 and some earlier versions ',
'issue' : 'https://github.com/elasticsearch/elasticsearch/pull/7055'}}
# sometimes returns True
def rarely():
return random.randint(0, 10) == 0
# usually returns True
def frequently():
return not rarely()
# asserts the correctness of the given hits given they are sorted asc
def assert_sort(hits):
values = [hit['sort'] for hit in hits['hits']['hits']]
assert len(values) > 0, 'expected non emtpy result'
val = min(values)
for x in values:
assert x >= val, '%s >= %s' % (x, val)
val = x
# asserts that the cluster health didn't timeout etc.
def assert_health(cluster_health, num_shards, num_replicas):
assert cluster_health['timed_out'] == False, 'cluster health timed out %s' % cluster_health
# Starts a new elasticsearch node from a released & untared version.
# This node uses unicast discovery with the provided unicast host list and starts
# the nodes with the given data directory. This allows shutting down and starting up
# nodes on the same data dir simulating a full cluster restart.
def start_node(version, data_dir, node_dir, unicast_host_list, tcp_port, http_port):
es_run_path = os.path.join(node_dir, 'elasticsearch-%s' % (version), 'bin/elasticsearch')
if version.startswith('0.90.'):
foreground = '-f' # 0.90.x starts in background automatically
else:
foreground = ''
return subprocess.Popen([es_run_path,
'-Des.path.data=%s' % data_dir, '-Des.cluster.name=upgrade_test',
'-Des.discovery.zen.ping.unicast.hosts=%s' % unicast_host_list,
'-Des.transport.tcp.port=%s' % tcp_port,
'-Des.http.port=%s' % http_port,
foreground], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Indexes the given number of document into the given index
# and randomly runs refresh, optimize and flush commands
def index_documents(es, index_name, type, num_docs):
logging.info('Indexing %s docs' % num_docs)
for id in range(0, num_docs):
es.index(index=index_name, doc_type=type, id=id, body={'string': str(random.randint(0, 100)),
'long_sort': random.randint(0, 100),
'double_sort' : float(random.randint(0, 100))})
if rarely():
es.indices.refresh(index=index_name)
if rarely():
es.indices.flush(index=index_name, force=frequently())
if rarely():
es.indices.optimize(index=index_name)
es.indices.refresh(index=index_name)
# Runs a basic number of assertions including:
# - document counts
# - match all search with sort on double / long
# - Realtime GET operations
# TODO(simonw): we should add stuff like:
# - dates including sorting
# - string sorting
# - docvalues if available
# - global ordinal if available
def run_basic_asserts(es, index_name, type, num_docs):
count = es.count(index=index_name)['count']
assert count == num_docs, 'Expected %r but got %r documents' % (num_docs, count)
for _ in range(0, num_docs):
random_doc_id = random.randint(0, num_docs-1)
doc = es.get(index=index_name, doc_type=type, id=random_doc_id)
assert doc, 'Expected document for id %s but got %s' % (random_doc_id, doc)
assert_sort(es.search(index=index_name,
body={
'sort': [
{'double_sort': {'order': 'asc'}}
]
}))
assert_sort(es.search(index=index_name,
body={
'sort': [
{'long_sort': {'order': 'asc'}}
]
}))
# picks a random version or and entire random version tuple from the directory
# to run the backwards tests against.
def pick_random_upgrade_version(directory, lower_version=None, upper_version=None):
if lower_version and upper_version:
return lower_version, upper_version
assert os.path.isdir(directory), 'No such directory %s' % directory
versions = []
for version in map(lambda x : x[len('elasticsearch-'):], filter(lambda x : re.match(r'^elasticsearch-\d+[.]\d+[.]\d+$', x), os.listdir(directory))):
if not version in BLACK_LIST:
versions.append(build_tuple(version))
versions.sort()
if lower_version: # lower version is set - picking a higher one
versions = filter(lambda x : x > build_tuple(lower_version), versions)
assert len(versions) >= 1, 'Expected at least 1 higher version than %s version in %s ' % (lower_version, directory)
random.shuffle(versions)
return lower_version, build_version(versions[0])
if upper_version:
versions = filter(lambda x : x < build_tuple(upper_version), versions)
assert len(versions) >= 1, 'Expected at least 1 lower version than %s version in %s ' % (upper_version, directory)
random.shuffle(versions)
return build_version(versions[0]), upper_version
assert len(versions) >= 2, 'Expected at least 2 different version in %s but found %s' % (directory, len(versions))
random.shuffle(versions)
versions = versions[0:2]
versions.sort()
return build_version(versions[0]), build_version(versions[1])
def build_version(version_tuple):
return '.'.join([str(x) for x in version_tuple])
def build_tuple(version_string):
return [int(x) for x in version_string.split('.')]
# returns a new elasticsearch client and ensures the all nodes have joined the cluster
# this method waits at most 30 seconds for all nodes to join
def new_es_instance(num_nodes, http_port, timeout = 30):
logging.info('Waiting for %s nodes to join the cluster' % num_nodes)
for _ in range(0, timeout):
# TODO(simonw): ask Honza if there is a better way to do this?
try:
es = Elasticsearch([
{'host': '127.0.0.1', 'port': http_port + x}
for x in range(0, num_nodes)])
es.cluster.health(wait_for_nodes=num_nodes)
es.count() # can we actually search or do we get a 503? -- anyway retry
return es
except (ConnectionError, TransportError):
pass
time.sleep(1)
assert False, 'Timed out waiting for %s nodes for %s seconds' % (num_nodes, timeout)
def assert_versions(bwc_version, current_version, node_dir):
assert [int(x) for x in bwc_version.split('.')] < [int(x) for x in current_version.split('.')],\
'[%s] must be < than [%s]' % (bwc_version, current_version)
for version in [bwc_version, current_version]:
assert not version in BLACK_LIST, 'Version %s is blacklisted - %s, see %s' \
% (version, BLACK_LIST[version]['reason'],
BLACK_LIST[version]['issue'])
dir = os.path.join(node_dir, 'elasticsearch-%s' % current_version)
assert os.path.isdir(dir), 'Expected elasticsearch-%s install directory does not exists: %s' % (version, dir)
def full_cluster_restart(node_dir, current_version, bwc_version, tcp_port, http_port):
assert_versions(bwc_version, current_version, node_dir)
num_nodes = random.randint(2, 3)
nodes = []
data_dir = tempfile.mkdtemp()
logging.info('Running upgrade test from [%s] to [%s] seed: [%s] es.path.data: [%s] es.http.port [%s] es.tcp.port [%s]'
% (bwc_version, current_version, seed, data_dir, http_port, tcp_port))
try:
logging.info('Starting %s BWC nodes of version %s' % (num_nodes, bwc_version))
unicast_addresses = ','.join(['127.0.0.1:%s' % (tcp_port+x) for x in range(0, num_nodes)])
for id in range(0, num_nodes):
nodes.append(start_node(bwc_version, data_dir, node_dir, unicast_addresses, tcp_port+id, http_port+id))
es = new_es_instance(num_nodes, http_port)
es.indices.delete(index='test_index', ignore=404)
num_shards = random.randint(1, 10)
num_replicas = random.randint(0, 1)
logging.info('Create index with [%s] shards and [%s] replicas' % (num_shards, num_replicas))
es.indices.create(index='test_index', body={
# TODO(simonw): can we do more here in terms of randomization - seems hard due to all the different version
'settings': {
'number_of_shards': num_shards,
'number_of_replicas': num_replicas
}
})
logging.info('Nodes joined, waiting for green status')
health = es.cluster.health(wait_for_status='green', wait_for_relocating_shards=0)
assert_health(health, num_shards, num_replicas)
num_docs = random.randint(10, 100)
index_documents(es, 'test_index', 'test_type', num_docs)
logging.info('Run basic asserts before full cluster restart')
run_basic_asserts(es, 'test_index', 'test_type', num_docs)
logging.info('kill bwc nodes -- prepare upgrade')
for node in nodes:
node.terminate()
# now upgrade the nodes and rerun the checks
tcp_port = tcp_port + len(nodes) # bump up port to make sure we can claim them
http_port = http_port + len(nodes)
logging.info('Full Cluster restart starts upgrading to version [elasticsearch-%s] es.http.port [%s] es.tcp.port [%s]'
% (current_version, http_port, tcp_port))
nodes = []
unicast_addresses = ','.join(['127.0.0.1:%s' % (tcp_port+x) for x in range(0, num_nodes)])
for id in range(0, num_nodes+1): # one more to trigger relocation
nodes.append(start_node(current_version, data_dir, node_dir, unicast_addresses, tcp_port+id, http_port+id))
es = new_es_instance(num_nodes+1, http_port)
logging.info('Nodes joined, waiting for green status')
health = es.cluster.health(wait_for_status='green', wait_for_relocating_shards=0)
assert_health(health, num_shards, num_replicas)
run_basic_asserts(es, 'test_index', 'test_type', num_docs)
# by running the indexing again we try to catch possible mapping problems after the upgrade
index_documents(es, 'test_index', 'test_type', num_docs)
run_basic_asserts(es, 'test_index', 'test_type', num_docs)
logging.info("[SUCCESS] - all test passed upgrading from version [%s] to version [%s]" % (bwc_version, current_version))
finally:
for node in nodes:
node.terminate()
time.sleep(1) # wait a second until removing the data dirs to give the nodes a chance to shutdown
shutil.rmtree(data_dir) # remove the temp data dir
if __name__ == '__main__':
logging.basicConfig(format='[%(levelname)s] [%(asctime)s] %(message)s', level=logging.INFO,
datefmt='%Y-%m-%d %I:%M:%S %p')
logging.getLogger('elasticsearch').setLevel(logging.ERROR)
logging.getLogger('urllib3').setLevel(logging.WARN)
parser = argparse.ArgumentParser(description='Tests Full Cluster Restarts across major version')
parser.add_argument('--version.backwards', '-b', dest='backwards_version', metavar='V',
help='The elasticsearch version to upgrade from')
parser.add_argument('--version.current', '-c', dest='current_version', metavar='V',
help='The elasticsearch version to upgrade to')
parser.add_argument('--seed', '-s', dest='seed', metavar='N', type=int,
help='The random seed to use')
parser.add_argument('--backwards.dir', '-d', dest='bwc_directory', default='backwards', metavar='dir',
help='The directory to the backwards compatibility sources')
parser.add_argument('--tcp.port', '-p', dest='tcp_port', default=9300, metavar='port', type=int,
help='The port to use as the minimum port for TCP communication')
parser.add_argument('--http.port', '-t', dest='http_port', default=9200, metavar='port', type=int,
help='The port to use as the minimum port for HTTP communication')
parser.set_defaults(bwc_directory='backwards')
parser.set_defaults(seed=int(time.time()))
args = parser.parse_args()
node_dir = args.bwc_directory
current_version = args.current_version
bwc_version = args.backwards_version
seed = args.seed
random.seed(seed)
bwc_version, current_version = pick_random_upgrade_version(node_dir, bwc_version, current_version)
tcp_port = args.tcp_port
http_port = args.http_port
try:
full_cluster_restart(node_dir, current_version, bwc_version, tcp_port, http_port)
except:
logging.warn('REPRODUCE WITH: \n\t`python %s --version.backwards %s --version.current %s --seed %s --tcp.port %s --http.port %s`'
% (sys.argv[0], bwc_version, current_version, seed, tcp_port, http_port))
raise
|
apache-2.0
|
[
3,
3909,
370,
19509,
1733,
1334,
1373,
503,
1655,
11615,
199,
3,
4190,
14024,
14,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
199,
3,
12715,
14,
19509,
1733,
12378,
642,
570,
370,
1265,
1334,
199,
3,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
221,
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,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
199,
3,
376,
283,
1179,
2281,
7,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
199,
3,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
199,
646,
2196,
199,
646,
747,
199,
646,
5549,
199,
646,
5145,
199,
646,
3873,
199,
646,
900,
199,
646,
7534,
199,
646,
2050,
199,
646,
984,
199,
646,
295,
199,
199,
504,
2197,
492,
2197,
199,
893,
26,
523,
687,
24380,
1733,
492,
19509,
1733,
523,
687,
24380,
1733,
14,
3924,
492,
25417,
523,
687,
24380,
1733,
14,
3924,
492,
27018,
547,
199,
2590,
3545,
465,
325,
26,
523,
870,
360,
6049,
3985,
84,
492,
24380,
1733,
8749,
3907,
658,
12095,
7305,
3907,
24380,
1733,
64,
358,
523,
746,
325,
421,
199,
2344,
2765,
570,
24956,
282,
5678,
10754,
511,
701,
3879,
282,
2615,
4350,
11004,
14,
199,
199,
1918,
10754,
511,
9174,
499,
503,
1655,
3380,
402,
376,
2269,
24380,
332,
1225,
1015,
12,
10507,
199,
65,
2196,
1329,
402,
8247,
1901,
314,
3879,
3380,
436,
24956,
282,
2615,
4350,
11004,
14,
199,
10881,
314,
3380,
787,
295,
13560,
282,
7425,
663,
402,
5678,
5920,
787,
7934,
370,
4868,
1006,
199,
12233,
787,
5139,
2754,
461,
436,
901,
666,
883,
506,
6511,
5423,
14,
199,
199,
19855,
26,
961,
2884,
5074,
314,
24380,
1733,
2366,
1890,
658,
25651,
13,
647,
64,
1255,
314,
2569,
1414,
370,
3907,
26,
819,
658,
12095,
7305,
3907,
24380,
1733,
64,
199,
199,
692,
1265,
787,
3879,
2366,
19,
1265,
1929,
370,
3907,
314,
1890,
1808,
7305,
19,
14,
4068,
32144,
658,
9983,
19,
64,
911,
506,
5120,
315,
314,
2018,
650,
14,
20,
199,
3221,
2808,
641,
658,
2859,
921,
1544,
14,
1548,
14,
1308,
15,
4249,
15,
8340,
819,
658,
12095,
7305,
19,
3907,
24380,
1733,
64,
199,
199,
9295,
658,
2859,
921,
5031,
14,
957,
15,
25651,
15,
25651,
13,
647,
64,
367,
2436,
199,
199,
607,
1865,
370,
1255,
642,
511,
2877,
3365,
1015,
402,
24380,
1733,
787,
1415,
14,
17650,
1929,
370,
506,
23389,
1901,
199,
1589,
2011,
2082,
26,
199,
199,
32323,
2043,
2672,
12829,
1182,
515,
15,
475,
15,
25651,
15,
6311,
2043,
2672,
20366,
8552,
10883,
12829,
8552,
2043,
2672,
336,
362,
221,
4178,
921,
4249,
14,
25651,
14,
1308,
15,
25651,
15,
25651,
15,
25651,
13,
17,
14,
19,
14,
17,
14,
5369,
14,
6838,
2043,
2672,
336,
362,
221,
4178,
921,
4249,
14,
25651,
14,
1308,
15,
25651,
15,
25651,
15,
25651,
13,
16,
14,
2710,
14,
969,
14,
5369,
14,
6838,
2043,
2672,
5330,
446,
26592,
19963,
24380,
1733,
13,
17,
14,
19,
14,
17,
14,
5369,
14,
6838,
10883,
5330,
446,
26592,
19963,
24380,
1733,
13,
16,
14,
2710,
14,
969,
14,
5369,
14,
6838,
2043,
2672,
12829,
2508,
2043,
2672,
2366,
4866,
13,
2537,
15,
9375,
13,
2219,
14,
647,
1553,
1023,
14,
22269,
378,
14,
2710,
14,
969,
1553,
1023,
14,
1818,
413,
14,
19,
14,
17,
199,
32323,
199,
2344,
199,
199,
23113,
63,
4924,
275,
791,
17,
14,
18,
14,
16,
7,
520,
469,
283,
5764,
356,
283,
6906,
282,
12160,
6519,
2382,
14870,
14647,
787,
440,
12137,
543,
4136,
1015,
297,
2079,
283,
5237,
356,
283,
2859,
921,
5031,
14,
957,
15,
25651,
15,
25651,
15,
9302,
15,
22,
15490,
2267,
1598,
283,
17,
14,
19,
14,
16,
7,
520,
469,
283,
5764,
356,
283,
44,
947,
6349,
20116,
6519,
21925,
1536,
18050,
687,
378,
14,
2710,
14,
23,
436,
2005,
14119,
5459,
1656,
2079,
283,
5237,
7,
520,
283,
2859,
921,
5031,
14,
957,
15,
25651,
15,
25651,
15,
9302,
15,
2760,
1229,
18620,
199,
3,
15026,
2529,
715,
199,
318,
24063,
590,
837,
523,
372,
2196,
14,
8393,
8,
16,
12,
1616,
9,
508,
378,
199,
199,
3,
9987,
2529,
715,
199,
318,
28914,
590,
837,
523,
372,
440,
24063,
590,
342,
199,
199,
3,
702,
83,
314,
29102,
402,
314,
1627,
19745,
1627,
2985,
787,
3355,
16635,
199,
318,
702,
63,
3191,
8,
16595,
304,
523,
1338,
275,
359,
12948,
459,
3191,
418,
367,
9793,
315,
19745,
459,
16595,
2545,
16595,
6538,
523,
702,
822,
8,
1459,
9,
690,
378,
12,
283,
2062,
2222,
325,
2037,
647,
754,
7,
523,
1139,
275,
1748,
8,
1459,
9,
523,
367,
671,
315,
1338,
26,
272,
702,
671,
2356,
1139,
12,
1543,
83,
2356,
450,
83,
7,
450,
334,
88,
12,
1139,
9,
272,
1139,
275,
671,
199,
199,
3,
702,
83,
626,
314,
4350,
13822,
9980,
1133,
2653,
5423,
14,
199,
318,
702,
63,
9665,
8,
4201,
63,
9665,
12,
1967,
63,
15570,
12,
1967,
63,
16755,
304,
523,
702,
4350,
63,
9665,
459,
26687,
63,
548,
418,
508,
756,
12,
283,
4201,
13822,
18590,
734,
450,
83,
7,
450,
4350,
63,
9665,
421,
199,
3,
7707,
83,
282,
892,
24380,
1733,
1031,
687,
282,
14286,
1253,
625,
502,
581,
1015,
14,
199,
3,
961,
1031,
4440,
625,
530,
1810,
13172,
543,
314,
2741,
625,
530,
1810,
1591,
769,
436,
9174,
199,
3,
314,
3380,
543,
314,
1627,
666,
2082,
14,
961,
6127,
24761,
1337,
3224,
436,
6617,
1536,
199,
3,
3380,
641,
314,
2011,
666,
2935,
4389,
20529,
282,
2615,
4350,
11004,
14,
199,
318,
1343,
63,
932,
8,
1023,
12,
666,
63,
694,
12,
1031,
63,
694,
12,
625,
530,
1810,
63,
1102,
63,
513,
12
] |
[
3909,
370,
19509,
1733,
1334,
1373,
503,
1655,
11615,
199,
3,
4190,
14024,
14,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
199,
3,
12715,
14,
19509,
1733,
12378,
642,
570,
370,
1265,
1334,
199,
3,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
221,
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,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
199,
3,
376,
283,
1179,
2281,
7,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
199,
3,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
844,
14,
199,
199,
646,
2196,
199,
646,
747,
199,
646,
5549,
199,
646,
5145,
199,
646,
3873,
199,
646,
900,
199,
646,
7534,
199,
646,
2050,
199,
646,
984,
199,
646,
295,
199,
199,
504,
2197,
492,
2197,
199,
893,
26,
523,
687,
24380,
1733,
492,
19509,
1733,
523,
687,
24380,
1733,
14,
3924,
492,
25417,
523,
687,
24380,
1733,
14,
3924,
492,
27018,
547,
199,
2590,
3545,
465,
325,
26,
523,
870,
360,
6049,
3985,
84,
492,
24380,
1733,
8749,
3907,
658,
12095,
7305,
3907,
24380,
1733,
64,
358,
523,
746,
325,
421,
199,
2344,
2765,
570,
24956,
282,
5678,
10754,
511,
701,
3879,
282,
2615,
4350,
11004,
14,
199,
199,
1918,
10754,
511,
9174,
499,
503,
1655,
3380,
402,
376,
2269,
24380,
332,
1225,
1015,
12,
10507,
199,
65,
2196,
1329,
402,
8247,
1901,
314,
3879,
3380,
436,
24956,
282,
2615,
4350,
11004,
14,
199,
10881,
314,
3380,
787,
295,
13560,
282,
7425,
663,
402,
5678,
5920,
787,
7934,
370,
4868,
1006,
199,
12233,
787,
5139,
2754,
461,
436,
901,
666,
883,
506,
6511,
5423,
14,
199,
199,
19855,
26,
961,
2884,
5074,
314,
24380,
1733,
2366,
1890,
658,
25651,
13,
647,
64,
1255,
314,
2569,
1414,
370,
3907,
26,
819,
658,
12095,
7305,
3907,
24380,
1733,
64,
199,
199,
692,
1265,
787,
3879,
2366,
19,
1265,
1929,
370,
3907,
314,
1890,
1808,
7305,
19,
14,
4068,
32144,
658,
9983,
19,
64,
911,
506,
5120,
315,
314,
2018,
650,
14,
20,
199,
3221,
2808,
641,
658,
2859,
921,
1544,
14,
1548,
14,
1308,
15,
4249,
15,
8340,
819,
658,
12095,
7305,
19,
3907,
24380,
1733,
64,
199,
199,
9295,
658,
2859,
921,
5031,
14,
957,
15,
25651,
15,
25651,
13,
647,
64,
367,
2436,
199,
199,
607,
1865,
370,
1255,
642,
511,
2877,
3365,
1015,
402,
24380,
1733,
787,
1415,
14,
17650,
1929,
370,
506,
23389,
1901,
199,
1589,
2011,
2082,
26,
199,
199,
32323,
2043,
2672,
12829,
1182,
515,
15,
475,
15,
25651,
15,
6311,
2043,
2672,
20366,
8552,
10883,
12829,
8552,
2043,
2672,
336,
362,
221,
4178,
921,
4249,
14,
25651,
14,
1308,
15,
25651,
15,
25651,
15,
25651,
13,
17,
14,
19,
14,
17,
14,
5369,
14,
6838,
2043,
2672,
336,
362,
221,
4178,
921,
4249,
14,
25651,
14,
1308,
15,
25651,
15,
25651,
15,
25651,
13,
16,
14,
2710,
14,
969,
14,
5369,
14,
6838,
2043,
2672,
5330,
446,
26592,
19963,
24380,
1733,
13,
17,
14,
19,
14,
17,
14,
5369,
14,
6838,
10883,
5330,
446,
26592,
19963,
24380,
1733,
13,
16,
14,
2710,
14,
969,
14,
5369,
14,
6838,
2043,
2672,
12829,
2508,
2043,
2672,
2366,
4866,
13,
2537,
15,
9375,
13,
2219,
14,
647,
1553,
1023,
14,
22269,
378,
14,
2710,
14,
969,
1553,
1023,
14,
1818,
413,
14,
19,
14,
17,
199,
32323,
199,
2344,
199,
199,
23113,
63,
4924,
275,
791,
17,
14,
18,
14,
16,
7,
520,
469,
283,
5764,
356,
283,
6906,
282,
12160,
6519,
2382,
14870,
14647,
787,
440,
12137,
543,
4136,
1015,
297,
2079,
283,
5237,
356,
283,
2859,
921,
5031,
14,
957,
15,
25651,
15,
25651,
15,
9302,
15,
22,
15490,
2267,
1598,
283,
17,
14,
19,
14,
16,
7,
520,
469,
283,
5764,
356,
283,
44,
947,
6349,
20116,
6519,
21925,
1536,
18050,
687,
378,
14,
2710,
14,
23,
436,
2005,
14119,
5459,
1656,
2079,
283,
5237,
7,
520,
283,
2859,
921,
5031,
14,
957,
15,
25651,
15,
25651,
15,
9302,
15,
2760,
1229,
18620,
199,
3,
15026,
2529,
715,
199,
318,
24063,
590,
837,
523,
372,
2196,
14,
8393,
8,
16,
12,
1616,
9,
508,
378,
199,
199,
3,
9987,
2529,
715,
199,
318,
28914,
590,
837,
523,
372,
440,
24063,
590,
342,
199,
199,
3,
702,
83,
314,
29102,
402,
314,
1627,
19745,
1627,
2985,
787,
3355,
16635,
199,
318,
702,
63,
3191,
8,
16595,
304,
523,
1338,
275,
359,
12948,
459,
3191,
418,
367,
9793,
315,
19745,
459,
16595,
2545,
16595,
6538,
523,
702,
822,
8,
1459,
9,
690,
378,
12,
283,
2062,
2222,
325,
2037,
647,
754,
7,
523,
1139,
275,
1748,
8,
1459,
9,
523,
367,
671,
315,
1338,
26,
272,
702,
671,
2356,
1139,
12,
1543,
83,
2356,
450,
83,
7,
450,
334,
88,
12,
1139,
9,
272,
1139,
275,
671,
199,
199,
3,
702,
83,
626,
314,
4350,
13822,
9980,
1133,
2653,
5423,
14,
199,
318,
702,
63,
9665,
8,
4201,
63,
9665,
12,
1967,
63,
15570,
12,
1967,
63,
16755,
304,
523,
702,
4350,
63,
9665,
459,
26687,
63,
548,
418,
508,
756,
12,
283,
4201,
13822,
18590,
734,
450,
83,
7,
450,
4350,
63,
9665,
421,
199,
3,
7707,
83,
282,
892,
24380,
1733,
1031,
687,
282,
14286,
1253,
625,
502,
581,
1015,
14,
199,
3,
961,
1031,
4440,
625,
530,
1810,
13172,
543,
314,
2741,
625,
530,
1810,
1591,
769,
436,
9174,
199,
3,
314,
3380,
543,
314,
1627,
666,
2082,
14,
961,
6127,
24761,
1337,
3224,
436,
6617,
1536,
199,
3,
3380,
641,
314,
2011,
666,
2935,
4389,
20529,
282,
2615,
4350,
11004,
14,
199,
318,
1343,
63,
932,
8,
1023,
12,
666,
63,
694,
12,
1031,
63,
694,
12,
625,
530,
1810,
63,
1102,
63,
513,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
googleapis/googleapis-gen
|
google/cloud/recaptchaenterprise/v1/recaptchaenterprise-v1-py/google/cloud/recaptchaenterprise_v1/types/recaptchaenterprise.py
|
1
|
16503
|
# -*- coding: utf-8 -*-
# Copyright 2020 Google 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.
#
import proto # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
__protobuf__ = proto.module(
package='google.cloud.recaptchaenterprise.v1',
manifest={
'CreateAssessmentRequest',
'AnnotateAssessmentRequest',
'AnnotateAssessmentResponse',
'Assessment',
'Event',
'RiskAnalysis',
'TokenProperties',
'CreateKeyRequest',
'ListKeysRequest',
'ListKeysResponse',
'GetKeyRequest',
'UpdateKeyRequest',
'DeleteKeyRequest',
'Key',
'WebKeySettings',
'AndroidKeySettings',
'IOSKeySettings',
},
)
class CreateAssessmentRequest(proto.Message):
r"""The create assessment request message.
Attributes:
parent (str):
Required. The name of the project in which
the assessment will be created, in the format
"projects/{project}".
assessment (google.cloud.recaptchaenterprise_v1.types.Assessment):
Required. The assessment details.
"""
parent = proto.Field(
proto.STRING,
number=1,
)
assessment = proto.Field(
proto.MESSAGE,
number=2,
message='Assessment',
)
class AnnotateAssessmentRequest(proto.Message):
r"""The request message to annotate an Assessment.
Attributes:
name (str):
Required. The resource name of the
Assessment, in the format
"projects/{project}/assessments/{assessment}".
annotation (google.cloud.recaptchaenterprise_v1.types.AnnotateAssessmentRequest.Annotation):
Required. The annotation that will be
assigned to the Event.
"""
class Annotation(proto.Enum):
r"""Enum that reprensents the types of annotations."""
ANNOTATION_UNSPECIFIED = 0
LEGITIMATE = 1
FRAUDULENT = 2
PASSWORD_CORRECT = 3
PASSWORD_INCORRECT = 4
name = proto.Field(
proto.STRING,
number=1,
)
annotation = proto.Field(
proto.ENUM,
number=2,
enum=Annotation,
)
class AnnotateAssessmentResponse(proto.Message):
r"""Empty response for AnnotateAssessment. """
class Assessment(proto.Message):
r"""A recaptcha assessment resource.
Attributes:
name (str):
Output only. The resource name for the
Assessment in the format
"projects/{project}/assessments/{assessment}".
event (google.cloud.recaptchaenterprise_v1.types.Event):
The event being assessed.
risk_analysis (google.cloud.recaptchaenterprise_v1.types.RiskAnalysis):
Output only. The risk analysis result for the
event being assessed.
token_properties (google.cloud.recaptchaenterprise_v1.types.TokenProperties):
Output only. Properties of the provided event
token.
"""
name = proto.Field(
proto.STRING,
number=1,
)
event = proto.Field(
proto.MESSAGE,
number=2,
message='Event',
)
risk_analysis = proto.Field(
proto.MESSAGE,
number=3,
message='RiskAnalysis',
)
token_properties = proto.Field(
proto.MESSAGE,
number=4,
message='TokenProperties',
)
class Event(proto.Message):
r"""
Attributes:
token (str):
Optional. The user response token provided by
the reCAPTCHA client-side integration on your
site.
site_key (str):
Optional. The site key that was used to
invoke reCAPTCHA on your site and generate the
token.
user_agent (str):
Optional. The user agent present in the
request from the user's device related to this
event.
user_ip_address (str):
Optional. The IP address in the request from
the user's device related to this event.
expected_action (str):
Optional. The expected action for this type
of event. This should be the same action
provided at token generation time on client-side
platforms already integrated with recaptcha
enterprise.
"""
token = proto.Field(
proto.STRING,
number=1,
)
site_key = proto.Field(
proto.STRING,
number=2,
)
user_agent = proto.Field(
proto.STRING,
number=3,
)
user_ip_address = proto.Field(
proto.STRING,
number=4,
)
expected_action = proto.Field(
proto.STRING,
number=5,
)
class RiskAnalysis(proto.Message):
r"""Risk analysis result for an event.
Attributes:
score (float):
Legitimate event score from 0.0 to 1.0.
(1.0 means very likely legitimate traffic while
0.0 means very likely non-legitimate traffic).
reasons (Sequence[google.cloud.recaptchaenterprise_v1.types.RiskAnalysis.ClassificationReason]):
Reasons contributing to the risk analysis
verdict.
"""
class ClassificationReason(proto.Enum):
r"""LINT.IfChange(classification_reason) Reasons contributing to the
risk analysis verdict.
"""
CLASSIFICATION_REASON_UNSPECIFIED = 0
AUTOMATION = 1
UNEXPECTED_ENVIRONMENT = 2
TOO_MUCH_TRAFFIC = 3
UNEXPECTED_USAGE_PATTERNS = 4
LOW_CONFIDENCE_SCORE = 5
score = proto.Field(
proto.FLOAT,
number=1,
)
reasons = proto.RepeatedField(
proto.ENUM,
number=2,
enum=ClassificationReason,
)
class TokenProperties(proto.Message):
r"""
Attributes:
valid (bool):
Whether the provided user response token is valid. When
valid = false, the reason could be specified in
invalid_reason or it could also be due to a user failing to
solve a challenge or a sitekey mismatch (i.e the sitekey
used to generate the token was different than the one
specified in the assessment).
invalid_reason (google.cloud.recaptchaenterprise_v1.types.TokenProperties.InvalidReason):
Reason associated with the response when
valid = false.
create_time (google.protobuf.timestamp_pb2.Timestamp):
The timestamp corresponding to the generation
of the token.
hostname (str):
The hostname of the page on which the token
was generated.
action (str):
Action name provided at token generation.
"""
class InvalidReason(proto.Enum):
r"""LINT.IfChange
Enum that represents the types of invalid token reasons.
"""
INVALID_REASON_UNSPECIFIED = 0
UNKNOWN_INVALID_REASON = 1
MALFORMED = 2
EXPIRED = 3
DUPE = 4
MISSING = 5
valid = proto.Field(
proto.BOOL,
number=1,
)
invalid_reason = proto.Field(
proto.ENUM,
number=2,
enum=InvalidReason,
)
create_time = proto.Field(
proto.MESSAGE,
number=3,
message=timestamp_pb2.Timestamp,
)
hostname = proto.Field(
proto.STRING,
number=4,
)
action = proto.Field(
proto.STRING,
number=5,
)
class CreateKeyRequest(proto.Message):
r"""The create key request message.
Attributes:
parent (str):
Required. The name of the project in which
the key will be created, in the format
"projects/{project}".
key (google.cloud.recaptchaenterprise_v1.types.Key):
Required. Information to create a reCAPTCHA
Enterprise key.
"""
parent = proto.Field(
proto.STRING,
number=1,
)
key = proto.Field(
proto.MESSAGE,
number=2,
message='Key',
)
class ListKeysRequest(proto.Message):
r"""The list keys request message.
Attributes:
parent (str):
Required. The name of the project that
contains the keys that will be listed, in the
format "projects/{project}".
page_size (int):
Optional. The maximum number of keys to
return. Default is 10. Max limit is 1000.
page_token (str):
Optional. The next_page_token value returned from a
previous. ListKeysRequest, if any.
"""
parent = proto.Field(
proto.STRING,
number=1,
)
page_size = proto.Field(
proto.INT32,
number=2,
)
page_token = proto.Field(
proto.STRING,
number=3,
)
class ListKeysResponse(proto.Message):
r"""Response to request to list keys in a project.
Attributes:
keys (Sequence[google.cloud.recaptchaenterprise_v1.types.Key]):
Key details.
next_page_token (str):
Token to retrieve the next page of results.
It is set to empty if no keys remain in results.
"""
@property
def raw_page(self):
return self
keys = proto.RepeatedField(
proto.MESSAGE,
number=1,
message='Key',
)
next_page_token = proto.Field(
proto.STRING,
number=2,
)
class GetKeyRequest(proto.Message):
r"""The get key request message.
Attributes:
name (str):
Required. The name of the requested key, in
the format "projects/{project}/keys/{key}".
"""
name = proto.Field(
proto.STRING,
number=1,
)
class UpdateKeyRequest(proto.Message):
r"""The update key request message.
Attributes:
key (google.cloud.recaptchaenterprise_v1.types.Key):
Required. The key to update.
update_mask (google.protobuf.field_mask_pb2.FieldMask):
Optional. The mask to control which field of
the key get updated. If the mask is not present,
all fields will be updated.
"""
key = proto.Field(
proto.MESSAGE,
number=1,
message='Key',
)
update_mask = proto.Field(
proto.MESSAGE,
number=2,
message=field_mask_pb2.FieldMask,
)
class DeleteKeyRequest(proto.Message):
r"""The delete key request message.
Attributes:
name (str):
Required. The name of the key to be deleted,
in the format "projects/{project}/keys/{key}".
"""
name = proto.Field(
proto.STRING,
number=1,
)
class Key(proto.Message):
r"""A key used to identify and configure applications (web and/or
mobile) that use reCAPTCHA Enterprise.
Attributes:
name (str):
The resource name for the Key in the format
"projects/{project}/keys/{key}".
display_name (str):
Human-readable display name of this key.
Modifiable by user.
web_settings (google.cloud.recaptchaenterprise_v1.types.WebKeySettings):
Settings for keys that can be used by
websites.
android_settings (google.cloud.recaptchaenterprise_v1.types.AndroidKeySettings):
Settings for keys that can be used by Android
apps.
ios_settings (google.cloud.recaptchaenterprise_v1.types.IOSKeySettings):
Settings for keys that can be used by iOS
apps.
labels (Sequence[google.cloud.recaptchaenterprise_v1.types.Key.LabelsEntry]):
Optional. See <a
href="https://cloud.google.com/recaptcha-
enterprise/docs/labels"> Creating and managing
labels</a>.
create_time (google.protobuf.timestamp_pb2.Timestamp):
The timestamp corresponding to the creation
of this Key.
"""
name = proto.Field(
proto.STRING,
number=1,
)
display_name = proto.Field(
proto.STRING,
number=2,
)
web_settings = proto.Field(
proto.MESSAGE,
number=3,
oneof='platform_settings',
message='WebKeySettings',
)
android_settings = proto.Field(
proto.MESSAGE,
number=4,
oneof='platform_settings',
message='AndroidKeySettings',
)
ios_settings = proto.Field(
proto.MESSAGE,
number=5,
oneof='platform_settings',
message='IOSKeySettings',
)
labels = proto.MapField(
proto.STRING,
proto.STRING,
number=6,
)
create_time = proto.Field(
proto.MESSAGE,
number=7,
message=timestamp_pb2.Timestamp,
)
class WebKeySettings(proto.Message):
r"""Settings specific to keys that can be used by websites.
Attributes:
allow_all_domains (bool):
If set to true, it means allowed_domains will not be
enforced.
allowed_domains (Sequence[str]):
Domains or subdomains of websites allowed to
use the key. All subdomains of an allowed domain
are automatically allowed. A valid domain
requires a host and must not include any path,
port, query or fragment. Examples: 'example.com'
or 'subdomain.example.com'
allow_amp_traffic (bool):
Required. Whether this key can be used on AMP
(Accelerated Mobile Pages) websites.
integration_type (google.cloud.recaptchaenterprise_v1.types.WebKeySettings.IntegrationType):
Required. Describes how this key is
integrated with the website.
challenge_security_preference (google.cloud.recaptchaenterprise_v1.types.WebKeySettings.ChallengeSecurityPreference):
Settings for the frequency and difficulty at
which this key triggers captcha challenges. This
should only be specified for IntegrationTypes
CHECKBOX and INVISIBLE.
"""
class IntegrationType(proto.Enum):
r"""Enum that represents the integration types for web keys."""
INTEGRATION_TYPE_UNSPECIFIED = 0
SCORE = 1
CHECKBOX = 2
INVISIBLE = 3
class ChallengeSecurityPreference(proto.Enum):
r"""Enum that represents the possible challenge frequency and
difficulty configurations for a web key.
"""
CHALLENGE_SECURITY_PREFERENCE_UNSPECIFIED = 0
USABILITY = 1
BALANCE = 2
SECURITY = 3
allow_all_domains = proto.Field(
proto.BOOL,
number=3,
)
allowed_domains = proto.RepeatedField(
proto.STRING,
number=1,
)
allow_amp_traffic = proto.Field(
proto.BOOL,
number=2,
)
integration_type = proto.Field(
proto.ENUM,
number=4,
enum=IntegrationType,
)
challenge_security_preference = proto.Field(
proto.ENUM,
number=5,
enum=ChallengeSecurityPreference,
)
class AndroidKeySettings(proto.Message):
r"""Settings specific to keys that can be used by Android apps.
Attributes:
allowed_package_names (Sequence[str]):
Android package names of apps allowed to use
the key. Example: 'com.companyname.appname'
"""
allowed_package_names = proto.RepeatedField(
proto.STRING,
number=1,
)
class IOSKeySettings(proto.Message):
r"""Settings specific to keys that can be used by iOS apps.
Attributes:
allowed_bundle_ids (Sequence[str]):
iOS bundle ids of apps allowed to use the
key. Example:
'com.companyname.productname.appname'
"""
allowed_bundle_ids = proto.RepeatedField(
proto.STRING,
number=1,
)
__all__ = tuple(sorted(__protobuf__.manifest))
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
4475,
20376,
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,
199,
646,
4104,
221,
327,
730,
26,
3686,
199,
199,
504,
6233,
14,
7204,
492,
901,
63,
2629,
63,
3317,
18,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
7204,
492,
4913,
63,
3317,
18,
221,
327,
730,
26,
3686,
421,
199,
363,
7204,
363,
275,
4104,
14,
578,
8,
272,
2559,
534,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
14,
86,
17,
297,
272,
7712,
3126,
267,
283,
2499,
2822,
12104,
2017,
297,
267,
283,
21761,
323,
2822,
12104,
2017,
297,
267,
283,
21761,
323,
2822,
12104,
2364,
297,
267,
283,
2822,
12104,
297,
267,
283,
2390,
297,
267,
283,
50,
28600,
13182,
297,
267,
283,
3264,
8516,
297,
267,
283,
2499,
1197,
2017,
297,
267,
283,
1296,
6340,
2017,
297,
267,
283,
1296,
6340,
2364,
297,
267,
283,
1002,
1197,
2017,
297,
267,
283,
4152,
1197,
2017,
297,
267,
283,
5392,
1197,
2017,
297,
267,
283,
1197,
297,
267,
283,
5926,
1197,
5268,
297,
267,
283,
20762,
1197,
5268,
297,
267,
283,
13532,
1197,
5268,
297,
272,
1660,
199,
9,
421,
199,
533,
2790,
2822,
12104,
2017,
8,
2625,
14,
2209,
304,
272,
519,
624,
1918,
1218,
28273,
1056,
1245,
14,
272,
9382,
26,
267,
1676,
334,
495,
304,
288,
11105,
14,
710,
536,
402,
314,
2199,
315,
1314,
288,
314,
28273,
911,
506,
2737,
12,
315,
314,
1475,
288,
298,
6776,
5321,
1715,
5469,
267,
28273,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
2822,
12104,
304,
288,
11105,
14,
710,
28273,
2436,
14,
272,
408,
339,
1676,
275,
4104,
14,
792,
8,
267,
4104,
14,
5353,
12,
267,
1329,
29,
17,
12,
272,
776,
272,
28273,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
18,
12,
267,
1245,
534,
2822,
12104,
297,
272,
776,
421,
199,
533,
1626,
1397,
323,
2822,
12104,
2017,
8,
2625,
14,
2209,
304,
272,
519,
624,
1918,
1056,
1245,
370,
28987,
376,
3709,
12104,
14,
272,
9382,
26,
267,
536,
334,
495,
304,
288,
11105,
14,
710,
2073,
536,
402,
314,
288,
3709,
12104,
12,
315,
314,
1475,
288,
298,
6776,
5321,
1715,
5995,
305,
5480,
1470,
5321,
17452,
5469,
267,
11262,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
21761,
323,
2822,
12104,
2017,
14,
16768,
304,
288,
11105,
14,
710,
11262,
626,
911,
506,
288,
7943,
370,
314,
6763,
14,
272,
408,
272,
1021,
30793,
8,
2625,
14,
5081,
304,
267,
519,
624,
5081,
626,
295,
657,
78,
1150,
83,
314,
2943,
402,
15538,
1041,
267,
1261,
4609,
2594,
63,
1734,
22917,
19679,
275,
378,
267,
491,
4680,
649,
1469,
1951,
275,
413,
267,
481,
2847,
3383,
1293,
1309,
275,
499,
267,
21705,
5172,
63,
31704,
275,
650,
267,
21705,
5172,
63,
568,
31704,
275,
841,
339,
536,
275,
4104,
14,
792,
8,
267,
4104,
14,
5353,
12,
267,
1329,
29,
17,
12,
272,
776,
272,
11262,
275,
4104,
14,
792,
8,
267,
4104,
14,
17563,
12,
267,
1329,
29,
18,
12,
267,
4952,
29,
16768,
12,
272,
776,
421,
199,
533,
1626,
1397,
323,
2822,
12104,
2364,
8,
2625,
14,
2209,
304,
272,
519,
624,
4699,
1177,
367,
1626,
1397,
323,
2822,
12104,
14,
259,
408,
421,
199,
533,
3709,
12104,
8,
2625,
14,
2209,
304,
272,
519,
624,
33,
295,
20559,
28273,
2073,
14,
272,
9382,
26,
267,
536,
334,
495,
304,
288,
7242,
1454,
14,
710,
2073,
536,
367,
314,
288,
3709,
12104,
315,
314,
1475,
288,
298,
6776,
5321,
1715,
5995,
305,
5480,
1470,
5321,
17452,
5469,
267,
1566,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
2390,
304,
288,
710,
1566,
3769,
465,
874,
939,
14,
267,
22633,
63,
10466,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
50,
28600,
13182,
304,
288,
7242,
1454,
14,
710,
22633,
11284,
754,
367,
314,
288,
1566,
3769,
465,
874,
939,
14,
267,
1526,
63,
3282,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
3264,
8516,
304,
288,
7242,
1454,
14,
19329,
402,
314,
2741,
1566,
288,
1526,
14,
272,
408,
339,
536,
275,
4104,
14,
792,
8,
267,
4104,
14,
5353,
12,
267,
1329,
29,
17,
12,
272,
776,
272,
1566,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
18,
12,
267,
1245,
534,
2390,
297,
272,
776,
272,
22633,
63,
10466,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
19,
12,
267,
1245,
534,
50,
28600,
13182,
297,
272,
776,
272,
1526,
63,
3282,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
20,
12,
267,
1245,
534,
3264,
8516,
297,
272,
776,
421,
199,
533,
6763,
8,
2625,
14,
2209,
304,
272,
519,
624,
272,
9382,
26,
267,
1526,
334,
495,
304,
288,
4879,
14,
710,
922,
1177,
1526,
2741,
701,
288,
314,
295,
28342,
26363,
1890,
13,
2441,
13150,
641,
2195,
288,
4770,
14,
267,
4770,
63,
498,
334,
495,
304,
288,
4879,
14,
710,
4770,
790,
626,
1990,
1202,
370,
288,
12677,
295,
28342,
26363,
641,
2195,
4770,
436,
3550,
314,
288,
1526,
14,
267,
922,
63,
4054,
334,
495,
304,
288,
4879
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
4475,
20376,
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,
199,
646,
4104,
221,
327,
730,
26,
3686,
199,
199,
504,
6233,
14,
7204,
492,
901,
63,
2629,
63,
3317,
18,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
7204,
492,
4913,
63,
3317,
18,
221,
327,
730,
26,
3686,
421,
199,
363,
7204,
363,
275,
4104,
14,
578,
8,
272,
2559,
534,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
14,
86,
17,
297,
272,
7712,
3126,
267,
283,
2499,
2822,
12104,
2017,
297,
267,
283,
21761,
323,
2822,
12104,
2017,
297,
267,
283,
21761,
323,
2822,
12104,
2364,
297,
267,
283,
2822,
12104,
297,
267,
283,
2390,
297,
267,
283,
50,
28600,
13182,
297,
267,
283,
3264,
8516,
297,
267,
283,
2499,
1197,
2017,
297,
267,
283,
1296,
6340,
2017,
297,
267,
283,
1296,
6340,
2364,
297,
267,
283,
1002,
1197,
2017,
297,
267,
283,
4152,
1197,
2017,
297,
267,
283,
5392,
1197,
2017,
297,
267,
283,
1197,
297,
267,
283,
5926,
1197,
5268,
297,
267,
283,
20762,
1197,
5268,
297,
267,
283,
13532,
1197,
5268,
297,
272,
1660,
199,
9,
421,
199,
533,
2790,
2822,
12104,
2017,
8,
2625,
14,
2209,
304,
272,
519,
624,
1918,
1218,
28273,
1056,
1245,
14,
272,
9382,
26,
267,
1676,
334,
495,
304,
288,
11105,
14,
710,
536,
402,
314,
2199,
315,
1314,
288,
314,
28273,
911,
506,
2737,
12,
315,
314,
1475,
288,
298,
6776,
5321,
1715,
5469,
267,
28273,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
2822,
12104,
304,
288,
11105,
14,
710,
28273,
2436,
14,
272,
408,
339,
1676,
275,
4104,
14,
792,
8,
267,
4104,
14,
5353,
12,
267,
1329,
29,
17,
12,
272,
776,
272,
28273,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
18,
12,
267,
1245,
534,
2822,
12104,
297,
272,
776,
421,
199,
533,
1626,
1397,
323,
2822,
12104,
2017,
8,
2625,
14,
2209,
304,
272,
519,
624,
1918,
1056,
1245,
370,
28987,
376,
3709,
12104,
14,
272,
9382,
26,
267,
536,
334,
495,
304,
288,
11105,
14,
710,
2073,
536,
402,
314,
288,
3709,
12104,
12,
315,
314,
1475,
288,
298,
6776,
5321,
1715,
5995,
305,
5480,
1470,
5321,
17452,
5469,
267,
11262,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
21761,
323,
2822,
12104,
2017,
14,
16768,
304,
288,
11105,
14,
710,
11262,
626,
911,
506,
288,
7943,
370,
314,
6763,
14,
272,
408,
272,
1021,
30793,
8,
2625,
14,
5081,
304,
267,
519,
624,
5081,
626,
295,
657,
78,
1150,
83,
314,
2943,
402,
15538,
1041,
267,
1261,
4609,
2594,
63,
1734,
22917,
19679,
275,
378,
267,
491,
4680,
649,
1469,
1951,
275,
413,
267,
481,
2847,
3383,
1293,
1309,
275,
499,
267,
21705,
5172,
63,
31704,
275,
650,
267,
21705,
5172,
63,
568,
31704,
275,
841,
339,
536,
275,
4104,
14,
792,
8,
267,
4104,
14,
5353,
12,
267,
1329,
29,
17,
12,
272,
776,
272,
11262,
275,
4104,
14,
792,
8,
267,
4104,
14,
17563,
12,
267,
1329,
29,
18,
12,
267,
4952,
29,
16768,
12,
272,
776,
421,
199,
533,
1626,
1397,
323,
2822,
12104,
2364,
8,
2625,
14,
2209,
304,
272,
519,
624,
4699,
1177,
367,
1626,
1397,
323,
2822,
12104,
14,
259,
408,
421,
199,
533,
3709,
12104,
8,
2625,
14,
2209,
304,
272,
519,
624,
33,
295,
20559,
28273,
2073,
14,
272,
9382,
26,
267,
536,
334,
495,
304,
288,
7242,
1454,
14,
710,
2073,
536,
367,
314,
288,
3709,
12104,
315,
314,
1475,
288,
298,
6776,
5321,
1715,
5995,
305,
5480,
1470,
5321,
17452,
5469,
267,
1566,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
2390,
304,
288,
710,
1566,
3769,
465,
874,
939,
14,
267,
22633,
63,
10466,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
50,
28600,
13182,
304,
288,
7242,
1454,
14,
710,
22633,
11284,
754,
367,
314,
288,
1566,
3769,
465,
874,
939,
14,
267,
1526,
63,
3282,
334,
3098,
14,
4091,
14,
2761,
6182,
9518,
24375,
63,
86,
17,
14,
1313,
14,
3264,
8516,
304,
288,
7242,
1454,
14,
19329,
402,
314,
2741,
1566,
288,
1526,
14,
272,
408,
339,
536,
275,
4104,
14,
792,
8,
267,
4104,
14,
5353,
12,
267,
1329,
29,
17,
12,
272,
776,
272,
1566,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
18,
12,
267,
1245,
534,
2390,
297,
272,
776,
272,
22633,
63,
10466,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
19,
12,
267,
1245,
534,
50,
28600,
13182,
297,
272,
776,
272,
1526,
63,
3282,
275,
4104,
14,
792,
8,
267,
4104,
14,
8272,
12,
267,
1329,
29,
20,
12,
267,
1245,
534,
3264,
8516,
297,
272,
776,
421,
199,
533,
6763,
8,
2625,
14,
2209,
304,
272,
519,
624,
272,
9382,
26,
267,
1526,
334,
495,
304,
288,
4879,
14,
710,
922,
1177,
1526,
2741,
701,
288,
314,
295,
28342,
26363,
1890,
13,
2441,
13150,
641,
2195,
288,
4770,
14,
267,
4770,
63,
498,
334,
495,
304,
288,
4879,
14,
710,
4770,
790,
626,
1990,
1202,
370,
288,
12677,
295,
28342,
26363,
641,
2195,
4770,
436,
3550,
314,
288,
1526,
14,
267,
922,
63,
4054,
334,
495,
304,
288,
4879,
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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ayoubg/gem5-graphics
|
gem5/src/arch/x86/isa/insts/x87/transcendental_functions/trigonometric_functions.py
|
62
|
2541
|
# Copyright (c) 2007 The Hewlett-Packard Development Company
# Copyright (c) 2012-13 Mark D. Hill and David A. Wood
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# 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 copyright holders 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.
#
# Authors: Gabe Black
# Nilay Vaish
microcode = '''
def macroop FSIN {
sinfp st(0), st(0)
};
def macroop FCOS {
cosfp st(0), st(0)
};
def macroop FSINCOS {
sinfp ufp1, st(0)
cosfp ufp2, st(0)
movfp st(0), ufp1
movfp st(-1), ufp2, spm=-1
};
def macroop FPTAN {
tanfp st(0), st(0)
lfpimm ufp1, 1
movfp st(-1), ufp1, spm=-1
};
# FPATAN
'''
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
1898,
334,
67,
9,
6029,
13,
969,
7173,
577,
14,
869,
778,
436,
20232,
437,
14,
644,
23521,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
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,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
3,
3515,
653,
382,
1187,
812,
65,
2453,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
27500,
568,
469,
272,
9829,
3997,
410,
8,
16,
395,
410,
8,
16,
9,
199,
12084,
199,
199,
318,
21308,
481,
1439,
51,
469,
272,
9794,
3997,
410,
8,
16,
395,
410,
8,
16,
9,
199,
12084,
199,
199,
318,
21308,
27500,
568,
1439,
51,
469,
272,
9829,
3997,
26337,
17,
12,
410,
8,
16,
9,
272,
9794,
3997,
26337,
18,
12,
410,
8,
16,
9,
272,
26524,
3997,
410,
8,
16,
395,
26337,
17,
272,
26524,
3997,
410,
2801,
17,
395,
26337,
18,
12,
2249,
77,
4022,
17,
199,
12084,
199,
199,
318,
21308,
481,
4189,
879,
469,
272,
20162,
3997,
410,
8,
16,
395,
410,
8,
16,
9,
272,
14642,
1038,
596,
26337,
17,
12,
413,
272,
26524,
3997,
410,
2801,
17,
395,
26337,
17,
12,
2249,
77,
4022,
17,
199,
12084,
199,
199,
3,
481,
2805,
879,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
1898,
334,
67,
9,
6029,
13,
969,
7173,
577,
14,
869,
778,
436,
20232,
437,
14,
644,
23521,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
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,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
3,
3515,
653,
382,
1187,
812,
65,
2453,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
27500,
568,
469,
272,
9829,
3997,
410,
8,
16,
395,
410,
8,
16,
9,
199,
12084,
199,
199,
318,
21308,
481,
1439,
51,
469,
272,
9794,
3997,
410,
8,
16,
395,
410,
8,
16,
9,
199,
12084,
199,
199,
318,
21308,
27500,
568,
1439,
51,
469,
272,
9829,
3997,
26337,
17,
12,
410,
8,
16,
9,
272,
9794,
3997,
26337,
18,
12,
410,
8,
16,
9,
272,
26524,
3997,
410,
8,
16,
395,
26337,
17,
272,
26524,
3997,
410,
2801,
17,
395,
26337,
18,
12,
2249,
77,
4022,
17,
199,
12084,
199,
199,
318,
21308,
481,
4189,
879,
469,
272,
20162,
3997,
410,
8,
16,
395,
410,
8,
16,
9,
272,
14642,
1038,
596,
26337,
17,
12,
413,
272,
26524,
3997,
410,
2801,
17,
395,
26337,
17,
12,
2249,
77,
4022,
17,
199,
12084,
199,
199,
3,
481,
2805,
879,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
OnroerendErfgoed/crabpy
|
tests/gateway/test_crab.py
|
1
|
87963
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import six
import pytest
from mock import Mock
from crabpy.gateway.exception import (
GatewayRuntimeException,
GatewayResourceNotFoundException
)
from crabpy.gateway.crab import (
Gewest, Provincie,
Gemeente, Deelgemeente, Taal,
Bewerking, Organisatie,
Aardsubadres, Aardadres,
Aardgebouw, Aardwegobject,
Aardterreinobject, Statushuisnummer,
Statussubadres, Statusstraatnaam,
Statuswegsegment, Geometriemethodewegsegment,
Statusgebouw, Geometriemethodegebouw,
Herkomstadrespositie, Straat,
Huisnummer, Postkanton,
Wegobject, Wegsegment,
Terreinobject, Perceel,
Gebouw, Metadata, Subadres,
Adrespositie
)
class TestCrabGateway:
def test_list_gewesten(self, crab_gateway, crab_service):
crab_service.ListGewesten.return_value = Mock(
GewestItem=[
Mock(GewestId=1, TaalCodeGewestNaam='NL', GewestNaam='Vlaams')
]
)
res = crab_gateway.list_gewesten()
assert isinstance(res, list)
assert isinstance(res[0], Gewest)
def test_get_gewest_by_id(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.return_value = Mock(
GewestId=2,
)
res = crab_gateway.get_gewest_by_id(2)
assert isinstance(res, Gewest)
assert res.id == 2
assert isinstance(res.centroid, tuple)
assert isinstance(res.bounding_box, tuple)
def test_get_gewest_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.side_effect = (
GatewayResourceNotFoundException
)
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_gewest_by_id(-1)
def test_list_gemeenten_default(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.return_value = Mock(
GewestId=2,
)
crab_service.ListGemeentenByGewestId.return_value = Mock(
GemeenteItem=[
Mock(GemeenteId=1, NISGemeenteCode=10000,
TaalCode='NL', TaalCodeGemeenteNaam='NL')
]
)
res = crab_gateway.list_gemeenten()
assert isinstance(res, list)
assert isinstance(res[0], Gemeente)
assert res[0].gewest.id == 2
def test_list_gemeenten_vlaanderen(self, crab_gateway, crab_service):
crab_service.ListGemeentenByGewestId.return_value = Mock(
GemeenteItem=[
Mock(GemeenteId=1, NISGemeenteCode=10000,
TaalCode='NL', TaalCodeGemeenteNaam='NL')
]
)
gewest = Gewest(2)
res = crab_gateway.list_gemeenten(gewest)
assert isinstance(res, list)
assert isinstance(res[0], Gemeente)
assert res[0].gewest.id == 2
def test_list_provincies(self, crab_gateway):
gewest = Gewest(1)
res = crab_gateway.list_provincies(gewest)
assert isinstance(res, list)
gewest = Gewest(3)
res = crab_gateway.list_provincies(gewest)
assert isinstance(res, list)
gewest = Gewest(2)
res = crab_gateway.list_provincies(gewest)
assert isinstance(res, list)
assert isinstance(res[0], Provincie)
assert res[0].gewest.id == 2
gewest = 2
res = crab_gateway.list_provincies(gewest)
assert isinstance(res, list)
assert isinstance(res[0], Provincie)
assert res[0].gewest.id == 2
def test_get_provincie_by_id(self, crab_gateway):
res = crab_gateway.get_provincie_by_id(10000)
assert isinstance(res, Provincie)
assert res.niscode == 10000
res = crab_gateway.get_provincie_by_id(20001)
assert isinstance(res, Provincie)
assert res.niscode == 20001
res = crab_gateway.get_provincie_by_id(20002)
assert isinstance(res, Provincie)
assert res.niscode == 20002
res = crab_gateway.get_provincie_by_id(30000)
assert isinstance(res, Provincie)
assert res.niscode == 30000
res = crab_gateway.get_provincie_by_id(40000)
assert isinstance(res, Provincie)
assert res.niscode == 40000
res = crab_gateway.get_provincie_by_id(50000)
assert isinstance(res, Provincie)
assert res.niscode == 50000
res = crab_gateway.get_provincie_by_id(60000)
assert isinstance(res, Provincie)
assert res.niscode == 60000
res = crab_gateway.get_provincie_by_id(70000)
assert isinstance(res, Provincie)
assert res.niscode == 70000
res = crab_gateway.get_provincie_by_id(80000)
assert isinstance(res, Provincie)
assert res.niscode == 80000
res = crab_gateway.get_provincie_by_id(90000)
assert isinstance(res, Provincie)
assert res.niscode == 90000
def test_get_provincie_by_unexisting_id(self, crab_gateway):
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_provincie_by_id(-1)
def test_list_gemeenten_by_provincie(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.return_value = Mock(
GewestId=2
)
crab_service.ListGemeentenByGewestId.return_value = Mock(
GemeenteItem=[
Mock(GemeenteId=1, NISGemeenteCode=10000,
TaalCode='NL', TaalCodeGemeenteNaam='NL')
]
)
provincie = Provincie(10000, 'Antwerpen', Gewest(2))
res = crab_gateway.list_gemeenten_by_provincie(provincie)
assert isinstance(res, list)
assert isinstance(res[0], Gemeente)
assert str(res[0].niscode)[0] == '1'
provincie = 10000
res = crab_gateway.list_gemeenten_by_provincie(provincie)
assert isinstance(res, list)
assert isinstance(res[0], Gemeente)
assert str(res[0].niscode)[0] == '1'
def test_get_gemeente_by_id(self, crab_gateway, crab_service):
crab_service.GetGemeenteByGemeenteId.return_value = Mock(
GemeenteId=1, GewestId=1, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_gemeente_by_id(1)
assert isinstance(res, Gemeente)
assert res.id == 1
def test_get_gemeente_by_id_with_string(self, crab_gateway, crab_service):
crab_service.GetGemeenteByGemeenteId.side_effect = (
GatewayRuntimeException(None, None)
)
with pytest.raises(GatewayRuntimeException):
crab_gateway.get_gemeente_by_id('gent')
def test_get_gemeente_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetGemeenteByGemeenteId.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_gemeente_by_id(-1)
def test_get_gemeente_by_niscode(self, crab_gateway, crab_service):
crab_service.GetGemeenteByNISGemeenteCode.return_value = Mock(
GemeenteId=1, GewestId=1, NisGemeenteCode=11001, BeginBewerking=1,
BeginOrganisatie=1
)
res = crab_gateway.get_gemeente_by_niscode(11001)
assert isinstance(res, Gemeente)
assert res.niscode == 11001
def test_get_gemeente_by_unexisting_niscode(self, crab_gateway, crab_service):
crab_service.GetGemeenteByNISGemeenteCode.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_gemeente_by_niscode(-1)
def test_list_deelgemeenten(self, crab_gateway):
res = crab_gateway.list_deelgemeenten()
assert isinstance(res, list)
assert isinstance(res[0], Deelgemeente)
def test_list_deelgemeenten_wrong_gewest(self, crab_gateway, crab_service):
with pytest.raises(ValueError):
crab_gateway.list_deelgemeenten(1)
def test_list_deelgemeenten_by_gemeente(self, crab_gateway, crab_service):
crab_service.GetGemeenteByNISGemeenteCode.return_value = Mock(
GemeenteId=1, GewestId=1, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.list_deelgemeenten_by_gemeente(45062)
assert isinstance(res, list)
assert len(res) == 2
assert isinstance(res[0], Deelgemeente)
gemeente = Gemeente(1, None, 45062, None)
res = crab_gateway.list_deelgemeenten_by_gemeente(gemeente)
assert isinstance(res, list)
assert len(res) == 2
assert isinstance(res[0], Deelgemeente)
def test_get_deelgemeente_by_id(self, crab_gateway):
res = crab_gateway.get_deelgemeente_by_id('45062A')
assert isinstance(res, Deelgemeente)
assert res.id == '45062A'
def test_get_deelgemeente_by_unexisting_id(self, crab_gateway):
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_deelgemeente_by_id(-1)
def test_list_talen(self, crab_gateway, crab_service):
crab_service.ListTalen.return_value = Mock(CodeItem=[Mock()])
res = crab_gateway.list_talen()
assert isinstance(res, list)
assert isinstance(res[0], Taal)
def test_list_bewerkingen(self, crab_gateway, crab_service):
res = crab_gateway.list_bewerkingen()
assert isinstance(res, list)
assert isinstance(res[0], Bewerking)
def test_list_organisaties(self, crab_gateway, crab_service):
res = crab_gateway.list_organisaties()
assert isinstance(res, list)
assert isinstance(res[0], Organisatie)
def test_list_aardsubadressen(self, crab_gateway, crab_service):
crab_service.ListAardSubadressen.return_value = Mock(CodeItem=[Mock()])
res = crab_gateway.list_aardsubadressen()
assert isinstance(res, list)
assert isinstance(res[0], Aardsubadres)
def test_list_aardadressen(self, crab_gateway, crab_service):
crab_service.ListAardAdressen.return_value = Mock(CodeItem=[Mock()])
res = crab_gateway.list_aardadressen()
assert isinstance(res, list)
assert isinstance(res[0], Aardadres)
def test_list_aardgebouwen(self, crab_gateway, crab_service):
crab_service.ListAardGebouwen.return_value = Mock(CodeItem=[Mock()])
res = crab_gateway.list_aardgebouwen()
assert isinstance(res, list)
assert isinstance(res[0], Aardgebouw)
def test_list_aarwegobjecten(self, crab_gateway, crab_service):
crab_service.ListAardWegobjecten.return_value = Mock(CodeItem=[Mock()])
res = crab_gateway.list_aardwegobjecten()
assert isinstance(res, list)
assert isinstance(res[0], Aardwegobject)
def test_list_aardterreinobjecten(self, crab_gateway, crab_service):
crab_service.ListAardTerreinobjecten.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_aardterreinobjecten()
assert isinstance(res, list)
assert isinstance(res[0], Aardterreinobject)
def test_list_statushuisnummers(self, crab_gateway, crab_service):
crab_service.ListStatusHuisnummers.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_statushuisnummers()
assert isinstance(res, list)
assert isinstance(res[0], Statushuisnummer)
def test_list_statussubadressen(self, crab_gateway, crab_service):
crab_service.ListStatusSubadressen.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_statussubadressen()
assert isinstance(res, list)
assert isinstance(res[0], Statussubadres)
def test_list_statusstraatnamen(self, crab_gateway, crab_service):
crab_service.ListStatusStraatnamen.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_statusstraatnamen()
assert isinstance(res, list)
assert isinstance(res[0], Statusstraatnaam)
def test_list_statuswegsegmenten(self, crab_gateway, crab_service):
crab_service.ListStatusWegsegmenten.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_statuswegsegmenten()
assert isinstance(res, list)
assert isinstance(res[0], Statuswegsegment)
def test_list_geometriemethodewegsegmenten(self, crab_gateway,
crab_service):
crab_service.ListGeometriemethodeWegsegmenten.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_geometriemethodewegsegmenten()
assert isinstance(res, list)
assert isinstance(res[0], Geometriemethodewegsegment)
def test_list_statusgebouwen(self, crab_gateway, crab_service):
crab_service.ListStatusGebouwen.return_value = Mock(CodeItem=[Mock()])
res = crab_gateway.list_statusgebouwen()
assert isinstance(res, list)
assert isinstance(res[0], Statusgebouw)
def test_list_gemetriemethodegebouwen(self, crab_gateway, crab_service):
crab_service.ListGeometriemethodeGebouwen.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_geometriemethodegebouwen()
assert isinstance(res, list)
assert isinstance(res[0], Geometriemethodegebouw)
def test_list_herkomstadrespositie(self, crab_gateway, crab_service):
crab_service.ListHerkomstAdresposities.return_value = Mock(
CodeItem=[Mock()]
)
res = crab_gateway.list_herkomstadresposities()
assert isinstance(res, list)
assert isinstance(res[0], Herkomstadrespositie)
def test_list_straten(self, crab_gateway, crab_service):
crab_service.ListStraatnamenWithStatusByGemeenteId.return_value = Mock(
StraatnaamWithStatusItem=[Mock()]
)
res = crab_gateway.list_straten(1)
assert isinstance(res, list)
assert isinstance(res[0], Straat)
gemeente = Gemeente(1, None, None, None)
res = crab_gateway.list_straten(gemeente)
assert isinstance(res, list)
assert isinstance(res[0], Straat)
def test_list_straten_empty(self, crab_gateway, crab_service):
crab_service.ListStraatnamenWithStatusByGemeenteId.return_value = Mock(
StraatnaamWithStatusItem=[]
)
res = crab_gateway.list_straten(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_straat_by_id(self, crab_gateway, crab_service):
crab_service.GetStraatnaamWithStatusByStraatnaamId.return_value = Mock(
StraatnaamId=1, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_straat_by_id(1)
assert isinstance(res, Straat)
assert res.id == 1
def test_get_straat_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetStraatnaamWithStatusByStraatnaamId.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_straat_by_id(-1)
def test_list_huisnummers_by_straat(self, crab_gateway, crab_service):
crab_service.ListHuisnummersWithStatusByStraatnaamId.return_value = (
Mock(HuisnummerWithStatusItem=[Mock(HuisnummerId=1)])
)
res = crab_gateway.list_huisnummers_by_straat(1)
assert isinstance(res, list)
assert isinstance(res[0], Huisnummer)
straat = Straat(1, None, None, None)
res = crab_gateway.list_huisnummers_by_straat(straat)
assert isinstance(res, list)
assert isinstance(res[0], Huisnummer)
def test_list_huisnummers_by_straat_empty(self, crab_gateway,
crab_service):
crab_service.ListHuisnummersWithStatusByStraatnaamId.return_value = (
Mock(HuisnummerWithStatusItem=[])
)
res = crab_gateway.list_huisnummers_by_straat(0)
assert isinstance(res, list)
assert len(res) == 0
def test_list_huisnummers_by_perceel(self, crab_gateway, crab_service):
crab_service.ListHuisnummersWithStatusByIdentificatorPerceel\
.return_value = Mock(
HuisnummerWithStatusItem=[Mock(HuisnummerId=1)]
)
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = (
Mock(HuisnummerId=1, BeginBewerking=1, BeginOrganisatie=1)
)
res1 = crab_gateway.list_huisnummers_by_perceel("13040C1747/00G002")
assert isinstance(res1, list)
assert isinstance(res1[0], Huisnummer)
perceel = Perceel('13040C1747/00G002')
res2 = crab_gateway.list_huisnummers_by_perceel(perceel)
assert isinstance(res2, list)
assert isinstance(res2[0], Huisnummer)
assert [p.id for p in res1] == [p.id for p in res2]
def test_list_huisnummers_by_perceel_empty(self, crab_gateway,
crab_service):
crab_service.ListHuisnummersWithStatusByIdentificatorPerceel\
.return_value = Mock(HuisnummerWithStatusItem=[])
res = crab_gateway.list_huisnummers_by_perceel("13040A0000/00A001")
assert isinstance(res, list)
assert len(res) == 0
def test_get_huisnummer_by_id(self, crab_gateway, crab_service):
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = Mock(
HuisnummerId=1, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_huisnummer_by_id(1)
assert isinstance(res, Huisnummer)
assert res.id == 1
def test_get_huisnummer_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_huisnummer_by_id(-1)
def test_get_huisnummer_by_nummer_and_straat(self, crab_gateway,
crab_service):
crab_service.GetHuisnummerWithStatusByHuisnummer.return_value = Mock(
HuisnummerId=1, BeginBewerking=1, BeginOrganisatie=1,
Huisnummer='1'
)
crab_service.GetStraatnaamWithStatusByStraatnaamId.return_value = Mock(
StraatnaamId=1, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_huisnummer_by_nummer_and_straat(1, 1)
assert isinstance(res, Huisnummer)
assert res.huisnummer == '1'
assert res.straat.id == 1
straat = Straat(1, None, None, None)
res = crab_gateway.get_huisnummer_by_nummer_and_straat(1, straat)
assert isinstance(res, Huisnummer)
assert res.huisnummer == '1'
def test_get_huisnummer_by_unexisting_nummer_and_straat(self, crab_gateway,
crab_service):
crab_service.GetHuisnummerWithStatusByHuisnummer.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_huisnummer_by_nummer_and_straat(-1, -1)
def test_list_postkantons_by_gemeente(self, crab_gateway, crab_service):
crab_service.ListPostkantonsByGemeenteId.return_value = Mock(
PostkantonItem=[Mock(PostkantonCode=1)]
)
res = crab_gateway.list_postkantons_by_gemeente(1)
assert isinstance(res, list)
assert isinstance(res[0], Postkanton)
gemeente = Gemeente(1, None, None, None)
res = crab_gateway.list_postkantons_by_gemeente(gemeente)
assert isinstance(res, list)
assert isinstance(res[0], Postkanton)
def test_list_postkantons_by_gemeente_empty(self, crab_gateway,
crab_service):
crab_service.ListPostkantonsByGemeenteId.return_value = Mock(
PostkantonItem=[]
)
res = crab_gateway.list_postkantons_by_gemeente(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_postkanton_by_huisnummer(self, crab_gateway, crab_service):
crab_service.GetPostkantonByHuisnummerId.return_value = Mock(
PostkantonCode=1
)
res = crab_gateway.get_postkanton_by_huisnummer(1)
assert isinstance(res, Postkanton)
huisnummer = Huisnummer(1, None, None, None)
res = crab_gateway.get_postkanton_by_huisnummer(huisnummer)
assert isinstance(res, Postkanton)
def test_get_postkanton_by_unexisting_huisnummer(self, crab_gateway,
crab_service):
crab_service.GetPostkantonByHuisnummerId.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_postkanton_by_huisnummer(-1)
def test_list_wegobjecten_by_straat(self, crab_gateway, crab_service):
crab_service.ListWegobjectenByStraatnaamId.return_value = Mock(
WegobjectItem=[Mock(IdentificatorWegobject=1,
AardWegobject=1)]
)
res = crab_gateway.list_wegobjecten_by_straat(1)
assert isinstance(res, list)
assert isinstance(res[0], Wegobject)
straat = Straat(1, None, None, None)
res = crab_gateway.list_wegobjecten_by_straat(straat)
assert isinstance(res, list)
assert isinstance(res[0], Wegobject)
def test_list_wegobjecten_by_unexsiting_straat(self, crab_gateway,
crab_service):
crab_service.ListWegobjectenByStraatnaamId.return_value = Mock(
WegobjectItem=[]
)
res = crab_gateway.list_wegobjecten_by_straat(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_wegobject_by_id(self, crab_gateway, crab_service):
crab_service.GetWegobjectByIdentificatorWegobject.return_value = Mock(
IdentificatorWegobject='53839893', BeginBewerking=1,
BeginOrganisatie=1
)
res = crab_gateway.get_wegobject_by_id("53839893")
assert isinstance(res, Wegobject)
assert res.id == "53839893"
def test_get_wegobject_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetWegobjectByIdentificatorWegobject.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_wegobject_by_id(-1)
def test_list_wegsegmenten_by_straat(self, crab_gateway, crab_service):
crab_service.ListWegsegmentenByStraatnaamId.return_value = Mock(
WegsegmentItem=[Mock()]
)
res = crab_gateway.list_wegsegmenten_by_straat(1)
assert isinstance(res, list)
assert isinstance(res[0], Wegsegment)
straat = Straat(1, None, None, None)
res = crab_gateway.list_wegsegmenten_by_straat(straat)
assert isinstance(res, list)
assert isinstance(res[0], Wegsegment)
def test_list_wegsegmenten_by_straat_empty(self, crab_gateway,
crab_service):
crab_service.ListWegsegmentenByStraatnaamId.return_value = Mock(
WegsegmentItem=[]
)
res = crab_gateway.list_wegsegmenten_by_straat(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_wegsegment_by_id(self, crab_gateway, crab_service):
crab_service.GetWegsegmentByIdentificatorWegsegment.return_value = (
Mock(IdentificatorWegsegment='108724', BeginBewerking=1,
BeginOrganisatie=1)
)
res = crab_gateway.get_wegsegment_by_id("108724")
assert isinstance(res, Wegsegment)
assert res.id == "108724"
def test_get_wegsegment_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetWegsegmentByIdentificatorWegsegment.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_wegsegment_by_id(-1)
def test_list_terreinobjecten_by_huisnummer(self, crab_gateway,
crab_service):
crab_service.ListTerreinobjectenByHuisnummerId.return_value = Mock(
TerreinobjectItem=[Mock()]
)
res = crab_gateway.list_terreinobjecten_by_huisnummer(1)
assert isinstance(res, list)
assert isinstance(res[0], Terreinobject)
huisnummer = Huisnummer(1, None, None, None)
res = crab_gateway.list_terreinobjecten_by_huisnummer(huisnummer)
assert isinstance(res, list)
assert isinstance(res[0], Terreinobject)
def test_list_terreinobjecten_by_huisnummer_empty(self, crab_gateway,
crab_service):
crab_service.ListTerreinobjectenByHuisnummerId.return_value = Mock(
TerreinobjectItem=[]
)
res = crab_gateway.list_terreinobjecten_by_huisnummer(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_terreinobject_by_id(self, crab_gateway, crab_service):
crab_service.GetTerreinobjectByIdentificatorTerreinobject\
.return_value = Mock(
IdentificatorTerreinobject='13040_C_1747_G_002_00',
BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_terreinobject_by_id("13040_C_1747_G_002_00")
assert isinstance(res, Terreinobject)
assert res.id == "13040_C_1747_G_002_00"
def test_get_terreinobject_by_unexisting_id(self, crab_gateway,
crab_service):
crab_service.GetTerreinobjectByIdentificatorTerreinobject\
.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_terreinobject_by_id(-1)
def test_list_percelen_by_huisnummer(self, crab_gateway, crab_service):
crab_service.ListPercelenByHuisnummerId.return_value = Mock(
PerceelItem=[Mock()]
)
res = crab_gateway.list_percelen_by_huisnummer(1)
assert isinstance(res, list)
assert isinstance(res[0], Perceel)
huisnummer = Huisnummer(1, None, None, None)
res = crab_gateway.list_percelen_by_huisnummer(huisnummer)
assert isinstance(res, list)
assert isinstance(res[0], Perceel)
def test_list_percelen_by_huisnummer_empty(self, crab_gateway,
crab_service):
crab_service.ListPercelenByHuisnummerId.return_value = Mock(
PerceelItem=[]
)
res = crab_gateway.list_percelen_by_huisnummer(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_perceel_by_id(self, crab_gateway, crab_service):
crab_service.GetPerceelByIdentificatorPerceel.return_value = Mock(
IdentificatorPerceel='13040C1747/00G002',
BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_perceel_by_id("13040C1747/00G002")
assert isinstance(res, Perceel)
assert res.id == "13040C1747/00G002"
def test_get_perceel_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetPerceelByIdentificatorPerceel.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_perceel_by_id(-1)
def test_list_gebouwen_by_huisnummer(self, crab_gateway, crab_service):
crab_service.ListGebouwenByHuisnummerId.return_value = Mock(
GebouwItem=[Mock(IdentificatorGebouw=1)]
)
res = crab_gateway.list_gebouwen_by_huisnummer(1)
assert isinstance(res, list)
assert isinstance(res[0], Gebouw)
huisnummer = Huisnummer(1, None, None, None)
res = crab_gateway.list_gebouwen_by_huisnummer(huisnummer)
assert isinstance(res, list)
assert isinstance(res[0], Gebouw)
def test_list_gebouwen_by_huisnummer_empty(self, crab_gateway,
crab_service):
crab_service.ListGebouwenByHuisnummerId.return_value = Mock(
GebouwItem=[]
)
res = crab_gateway.list_gebouwen_by_huisnummer(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_gebouw_by_id(self, crab_gateway, crab_service):
crab_service.GetGebouwByIdentificatorGebouw.return_value = Mock(
IdentificatorGebouw=1538575, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_gebouw_by_id("1538575")
assert isinstance(res, Gebouw)
assert res.id == 1538575
def test_get_gebouw_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetGebouwByIdentificatorGebouw.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_gebouw_by_id(-1)
def test_list_subadressen_by_huisnummer(self, crab_gateway, crab_service):
crab_service.ListSubadressenWithStatusByHuisnummerId.return_value = (
Mock(SubadresWithStatusItem=[Mock(SubadresId=1)])
)
res = crab_gateway.list_subadressen_by_huisnummer(129462)
assert isinstance(res, list)
assert isinstance(res[0], Subadres)
huisnummer = Huisnummer(129462, None, None, None)
res = crab_gateway.list_subadressen_by_huisnummer(huisnummer)
assert isinstance(res, list)
assert isinstance(res[0], Subadres)
def test_list_subadressen_by_huisnummer_empty(self, crab_gateway,
crab_service):
crab_service.ListSubadressenWithStatusByHuisnummerId.return_value = (
Mock(SubadresWithStatusItem=[])
)
res = crab_gateway.list_subadressen_by_huisnummer(0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_subadres_by_id(self, crab_gateway, crab_service):
crab_service.GetSubadresWithStatusBySubadresId.return_value = Mock(
SubadresId=1120936, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_subadres_by_id(1120936)
assert isinstance(res, Subadres)
assert res.id == 1120936
def test_get_subadres_by_unexisting_id(self, crab_gateway, crab_service):
crab_service.GetSubadresWithStatusBySubadresId.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_subadres_by_id(-1)
def test_list_adresposities_by_huisnummer(self, crab_gateway, crab_service):
crab_service.ListAdrespositiesByHuisnummerId.return_value = Mock(
AdrespositieItem=[Mock()]
)
res = crab_gateway.list_adresposities_by_huisnummer(1)
assert isinstance(res, list)
assert isinstance(res[0], Adrespositie)
def test_list_adresposities_by_huisnummer_empty(self, crab_gateway,
crab_service):
crab_service.ListAdrespositiesByHuisnummerId.return_value = Mock(
AdrespositieItem=[]
)
res = crab_gateway.list_adresposities_by_huisnummer(0)
assert isinstance(res, list)
assert len(res) == 0
def test_list_adresposities_by_nummer_and_straat(self, crab_gateway,
crab_service):
crab_service.ListAdrespositiesByHuisnummer.return_value = Mock(
AdrespositieItem=[Mock()]
)
res = crab_gateway.list_adresposities_by_nummer_and_straat(1, 1)
assert isinstance(res, list)
assert isinstance(res[0], Adrespositie)
def test_list_adresposities_by_nummer_and_straat_empty(self, crab_gateway,
crab_service):
crab_service.ListAdrespositiesByHuisnummer.return_value = Mock(
AdrespositieItem=[]
)
res = crab_gateway.list_adresposities_by_nummer_and_straat(0, 0)
assert isinstance(res, list)
assert len(res) == 0
def test_list_adresposities_by_subadres(self, crab_gateway, crab_service):
crab_service.ListAdrespositiesBySubadresId.return_value = Mock(
AdrespositieItem=[Mock()]
)
res = crab_gateway.list_adresposities_by_subadres(1120936)
assert isinstance(res, list)
assert isinstance(res[0], Adrespositie)
def test_list_adresposities_by_subadres_empty(self, crab_gateway,
crab_service):
crab_service.ListAdrespositiesBySubadresId.return_value = Mock(
AdrespositieItem=[]
)
res = crab_gateway.list_adresposities_by_subadres(0)
assert isinstance(res, list)
assert len(res) == 0
def test_list_adresposities_by_subadres_and_huisnummer(self, crab_gateway,
crab_service):
crab_service.ListAdrespositiesBySubadres.return_value = Mock(
AdrespositieItem=[Mock()]
)
res = crab_gateway.list_adresposities_by_subadres_and_huisnummer('A', 129462)
assert isinstance(res, list)
assert isinstance(res[0], Adrespositie)
def test_list_adresposities_by_unexisting_subadres_and_huisnummer(
self, crab_gateway, crab_service):
crab_service.ListAdrespositiesBySubadres.return_value = Mock(
AdrespositieItem=[]
)
res = crab_gateway.list_adresposities_by_subadres_and_huisnummer(0, 0)
assert isinstance(res, list)
assert len(res) == 0
def test_get_adrespositie_by_id(self, crab_gateway, crab_service):
crab_service.GetAdrespositieByAdrespositieId.return_value = Mock(
AdrespositieId=4428005, BeginBewerking=1, BeginOrganisatie=1
)
res = crab_gateway.get_adrespositie_by_id(4428005)
assert isinstance(res, Adrespositie)
assert res.id == 4428005
def test_get_adrespositie_by_unexisting_id(self, crab_gateway,
crab_service):
crab_service.GetAdrespositieByAdrespositieId.return_value = None
with pytest.raises(GatewayResourceNotFoundException):
crab_gateway.get_adrespositie_by_id(-1)
def test_get_postadres_by_huisnummer(self, crab_gateway, crab_service):
crab_service.GetPostadresByHuisnummerId.return_value = Mock(
Postadres='Steenweg op Oosthoven 51, 2300 Turnhout'
)
res = crab_gateway.get_postadres_by_huisnummer(1)
assert res == 'Steenweg op Oosthoven 51, 2300 Turnhout'
hnr = Huisnummer(1, None, None, None)
res = crab_gateway.get_postadres_by_huisnummer(hnr)
assert res == 'Steenweg op Oosthoven 51, 2300 Turnhout'
def test_get_postadres_by_subadres(self, crab_gateway, crab_service):
crab_service.GetPostadresBySubadresId.return_value = Mock(
Postadres='Antoon van Brabantstraat 7 bus B, 2630 Aartselaar'
)
res = crab_gateway.get_postadres_by_subadres(1120936)
assert res == 'Antoon van Brabantstraat 7 bus B, 2630 Aartselaar'
subadres = Subadres(1120936, None, None)
res = crab_gateway.get_postadres_by_subadres(subadres)
assert res == 'Antoon van Brabantstraat 7 bus B, 2630 Aartselaar'
class TestGewest:
def test_fully_initialised(self):
g = Gewest(
2,
{'nl': 'Vlaams gewest', 'fr': 'Région Flamande'},
(138165.09, 189297.53),
(22279.17, 153050.23, 258873.3, 244022.31)
)
assert g.id == 2
assert g.naam =='Vlaams gewest'
assert g.centroid == (138165.09, 189297.53)
assert g.bounding_box == (22279.17, 153050.23, 258873.3, 244022.31)
assert 'Vlaams gewest (2)' == str(g)
assert "Gewest(2)" == repr(g)
def test_str_and_repr_dont_lazy_load(self):
g = Gewest(2)
assert 'Gewest 2' == str(g)
assert 'Gewest(2)'== repr(g)
def test_check_gateway_not_set(self):
g = Gewest(2)
with pytest.raises(RuntimeError):
g.check_gateway()
def test_gemeenten(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.return_value = Mock(
GewestId=2,
)
crab_service.ListGemeentenByGewestId.return_value = Mock(
GemeenteItem=[
Mock(GemeenteId=1, NISGemeenteCode=10000,
TaalCode='NL', TaalCodeGemeenteNaam='NL')
]
)
g = Gewest(2)
g.set_gateway(crab_gateway)
gemeenten = g.gemeenten
assert isinstance(gemeenten, list)
def test_provincies(self, crab_gateway):
g = Gewest(2)
g.set_gateway(crab_gateway)
provincies = g.provincies
assert isinstance(provincies, list)
assert len(provincies) == 5
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.return_value = Mock(
GewestId=2, GewestNaam='Vlaams Gewest', CenterX=138165.09,
CenterY=189297.53, MinimumX=22279.17, MinimumY=153050.23,
MaximumX=258873.3, MaximumY=244022.31
)
g = Gewest(2)
g.set_gateway(crab_gateway)
assert g.id == 2
assert str(g.naam) == 'Vlaams Gewest'
assert g.centroid == (138165.09, 189297.53)
assert g.bounding_box == (22279.17, 153050.23, 258873.3, 244022.31)
class TestProvincie:
def test_fully_initialised(self):
p = Provincie(20001, 'Vlaams-Brabant', Gewest(2))
assert p.niscode == 20001
assert p.naam == 'Vlaams-Brabant'
assert 'Vlaams-Brabant (20001)' == str(p)
assert "Provincie(20001, 'Vlaams-Brabant', Gewest(2))" == repr(p)
def test_check_gateway_not_set(self):
p = Provincie(20001, 'Vlaams-Brabant', Gewest(2))
with pytest.raises(RuntimeError):
p.check_gateway()
def test_gemeenten(self, crab_gateway, crab_service):
crab_service.GetGewestByGewestIdAndTaalCode.return_value = Mock(
GewestId=2
)
crab_service.ListGemeentenByGewestId.return_value = Mock(
GemeenteItem=[
Mock(GemeenteId=1, NISGemeenteCode=10000,
TaalCode='NL', TaalCodeGemeenteNaam='NL')
]
)
p = Provincie(20001, 'Vlaams-Brabant', Gewest(2))
p.set_gateway(crab_gateway)
gemeenten = p.gemeenten
assert isinstance(gemeenten, list)
class TestGemeente:
def test_fully_initialised(self):
g = Gemeente(
1,
'Aartselaar',
11001,
Gewest(2),
Taal('nl', 'Nederlands', 'Nederlands.'),
(150881.07, 202256.84),
(148950.36, 199938.28, 152811.77, 204575.39),
Metadata(
'1830-01-01 00:00:00',
'2002-08-13 17:32:32',
Bewerking(1, '', ''),
Organisatie(6, '', '')
)
)
assert g.id == 1
assert g.naam == 'Aartselaar'
assert g.niscode == 11001
assert isinstance(g.gewest, Gewest)
assert g.gewest.id == 2
assert g.centroid == (150881.07, 202256.84)
assert g.bounding_box == (148950.36, 199938.28, 152811.77, 204575.39)
assert int(g.gewest.id) ==2
assert isinstance(g._taal, Taal)
assert g._taal_id == 'nl'
assert isinstance(g.metadata, Metadata)
assert g.metadata.begin_datum == '1830-01-01 00:00:00'
assert g.metadata.begin_tijd == '2002-08-13 17:32:32'
assert isinstance(g.metadata.begin_bewerking, Bewerking)
assert int(g.metadata.begin_bewerking.id) == 1
assert isinstance(g.metadata.begin_organisatie, Organisatie)
assert int(g.metadata.begin_organisatie.id) == 6
assert 'Aartselaar (1)' == str(g)
assert "Gemeente(1, 'Aartselaar', 11001)" == repr(g)
@pytest.mark.skipif(
not six.PY2,
reason='This test only works on python 2.x'
)
def test_unicode_py2(self):
g = Gemeente(92, 'Biévène', 23009, Gewest(2))
assert 'Biévène (92)'.encode('utf-8') == str(g)
@pytest.mark.skipif(
not six.PY3,
reason='This test only works on python 3.x'
)
def test_unicode_py3(self):
g = Gemeente(92, 'Biévène', 23009, Gewest(2))
assert 'Biévène (92)' == str(g)
def test_str_and_repr_dont_lazy_load(self):
g = Gemeente(1, 'Aartselaar', 11001, Gewest(2))
assert 'Aartselaar (1)' == str(g)
assert "Gemeente(1, 'Aartselaar', 11001)" == repr(g)
def test_check_gateway_not_set(self):
g = Gemeente(1, 'Aartselaar', 11001, Gewest(2))
with pytest.raises(RuntimeError):
g.check_gateway()
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.ListTalen.return_value = Mock(CodeItem=[Mock(Code='nl')])
crab_service.GetGemeenteByGemeenteId.return_value = Mock(
GemeenteId=1, GewestId=1, BeginBewerking=1, BeginOrganisatie=1,
CenterX=150881.07, CenterY=202256.84, MinimumX=148950.36,
MinimumY=199938.28, MaximumX=152811.77, MaximumY=204575.39,
TaalCode='nl'
)
g = Gemeente(1, 'Aartselaar', 11001, Gewest(2))
g.set_gateway(crab_gateway)
assert g.id == 1
assert g.naam == 'Aartselaar'
assert g.niscode == 11001
assert isinstance(g.gewest, Gewest)
assert int(g.gewest.id) == 2
assert g.taal.id == 'nl'
assert g.centroid == (150881.07, 202256.84)
assert g.bounding_box == (148950.36, 199938.28, 152811.77, 204575.39)
g.metadata.set_gateway(crab_gateway)
assert isinstance(g.metadata, Metadata)
assert not g.metadata.begin_datum == None
assert not g.metadata.begin_tijd == None
assert isinstance(g.metadata.begin_bewerking, Bewerking)
assert int(g.metadata.begin_bewerking.id) == 1
assert isinstance(g.metadata.begin_organisatie, Organisatie)
assert int(g.metadata.begin_organisatie.id) == 1
def test_straten(self, crab_gateway, crab_service):
crab_service.ListStraatnamenWithStatusByGemeenteId.return_value = Mock(
StraatnaamWithStatusItem=[Mock()]
)
g = Gemeente(1, 'Aartselaar', 11001, Gewest(3))
g.set_gateway(crab_gateway)
straten = g.straten
assert isinstance(straten, list)
def test_postkantons(self, crab_gateway, crab_service):
crab_service.ListPostkantonsByGemeenteId.return_value = Mock(
PostkantonItem=[Mock(PostkantonCode=1)]
)
g = Gemeente(1, 'Aartselaar', 11001, Gewest(3))
g.set_gateway(crab_gateway)
postkanton = g.postkantons
assert isinstance(postkanton, list)
def test_provincie(self, crab_gateway):
g = Gemeente(1, 'Aartselaar', 11001, Gewest(2))
g.set_gateway(crab_gateway)
provincie = g.provincie
assert isinstance(provincie, Provincie)
assert 10000 == provincie.id
class TestDeelgemeente:
def test_fully_initialised(self):
dg = Deelgemeente('45062A', 'Sint-Maria-Horebeke', 45062)
assert dg.id == '45062A'
assert dg.naam == 'Sint-Maria-Horebeke'
assert 'Sint-Maria-Horebeke (45062A)' == str(dg)
assert "Deelgemeente('45062A', 'Sint-Maria-Horebeke', 45062)" == repr(dg)
def test_check_gateway_not_set(self):
dg = Deelgemeente('45062A', 'Sint-Maria-Horebeke', 45062)
with pytest.raises(RuntimeError):
dg.check_gateway()
def test_gemeente(self, crab_gateway, crab_service):
crab_service.GetGemeenteByNISGemeenteCode.return_value = Mock(
GemeenteId=1, GewestId=1, NisGemeenteCode=45062, BeginBewerking=1,
BeginOrganisatie=1, GemeenteNaam='Horebeke'
)
dg = Deelgemeente('45062A', 'Sint-Maria-Horebeke', 45062)
dg.set_gateway(crab_gateway)
gemeente = dg.gemeente
assert isinstance(gemeente, Gemeente)
assert gemeente.niscode == 45062
assert gemeente.naam == 'Horebeke'
class TestTaal:
def test_fully_initialised(self):
t = Taal(
"nl",
'Nederlands',
'Nederlands.'
)
assert t.id == "nl"
assert t.naam == 'Nederlands'
assert t.definitie == 'Nederlands.'
assert 'Nederlands' == str(t)
assert "Taal('nl', 'Nederlands', 'Nederlands.')" == repr(t)
class TestBewerking:
def test_repr(self):
b = Bewerking(
'3',
'correctie',
'Correctie van de attributen.'
)
assert "Bewerking(3, 'correctie', 'Correctie van de attributen.')" == repr(b)
class TestOrganisatie:
def test_repr(self):
o = Organisatie(
'6',
'NGI',
'Nationaal Geografisch Instituut.'
)
assert "Organisatie(6, 'NGI', 'Nationaal Geografisch Instituut.')" == repr(o)
class TestAardsubadres:
def test_repr(self):
a = Aardsubadres(
'1',
'appartementNummer',
'Nummer van het appartement.'
)
assert "Aardsubadres(1, 'appartementNummer', 'Nummer van het appartement.')" == repr(a)
class TestAardadres:
def test_repr(self):
a = Aardadres(
'1',
'subAdres',
'Aanduiding van een plaats op een huisnummer'
)
assert "Aardadres(1, 'subAdres', 'Aanduiding van een plaats op een huisnummer')" == repr(a)
class TestAardgebouw:
def test_repr(self):
a = Aardgebouw(
'3',
'virtueel gebouw',
'gbg afgezoomd met virtuele gvl'
)
assert "Aardgebouw(3, 'virtueel gebouw', 'gbg afgezoomd met virtuele gvl')" == repr(a)
class TestAardwegobject:
def test_repr(self):
a = Aardwegobject(
'1',
'taTEL',
'Wegverbinding volgens TeleAtlas.'
)
assert "Aardwegobject(1, 'taTEL', 'Wegverbinding volgens TeleAtlas.')" == repr(a)
class TestAardterreinobject:
def test_repr(self):
a = Aardterreinobject(
'1',
'kadPerceel',
'Perceel volgens het Kadaster.'
)
assert "Aardterreinobject(1, 'kadPerceel', 'Perceel volgens het Kadaster.')" == repr(a)
class TestStatushuisnummer:
def test_repr(self):
s = Statushuisnummer(
'1',
'voorgesteld',
None
)
assert "Statushuisnummer(1, 'voorgesteld', 'None')" == repr(s)
class TestStatussubadres:
def test_repr(self):
s = Statussubadres(
'1',
'voorgesteld',
None
)
assert "Statussubadres(1, 'voorgesteld', 'None')" == repr(s)
class TestStatusstraatnaam:
def test_repr(self):
s = Statusstraatnaam(
'1',
'voorgesteld',
None
)
assert "Statusstraatnaam(1, 'voorgesteld', 'None')" == repr(s)
class TestStatuswegsegment:
def test_repr(self):
s = Statuswegsegment(
'1',
'vergunningAangevraagd',
None
)
assert "Statuswegsegment(1, 'vergunningAangevraagd', 'None')" == repr(s)
class TestGeometriemethodewegsegment:
def test_repr(self):
g = Geometriemethodewegsegment(
'2',
'opmeting',
None
)
assert "Geometriemethodewegsegment(2, 'opmeting', 'None')" == repr(g)
class TestStatusgebouw:
def test_repr(self):
s = Statusgebouw(
'1',
'vergunningAangevraagd',
None
)
assert "Statusgebouw(1, 'vergunningAangevraagd', 'None')" == repr(s)
class TestGeometriemethodegebouw:
def test_repr(self):
g = Geometriemethodegebouw(
'2',
'opmeting',
None
)
assert "Geometriemethodegebouw(2, 'opmeting', 'None')" == repr(g)
class TestHerkomstadrespositie:
def test_repr(self):
h = Herkomstadrespositie(
'6',
'manueleAanduidingVanToegangTotDeWeg',
None
)
assert "Herkomstadrespositie(6, 'manueleAanduidingVanToegangTotDeWeg', 'None')" == repr(h)
class TestStraat:
def test_fully_initialised(self):
s = Straat(
1,
'Acacialaan',
1,
Statusstraatnaam(3, 'inGebruik', None),
'Acacialaan', 'nl', None, None,
Metadata(
'1830-01-01 00:00:00',
'2013-04-12 20:07:25.960000',
Bewerking(3, '', ''),
Organisatie(1, '', '')
)
)
assert s.id == 1
assert s.label == 'Acacialaan'
assert s.namen == (('Acacialaan', 'nl'), (None, None))
assert int(s.status_id) == 3
assert isinstance(s.status, Statusstraatnaam)
assert int(s.gemeente_id) == 1
assert isinstance(s.metadata, Metadata)
assert s.metadata.begin_datum == '1830-01-01 00:00:00'
assert s.metadata.begin_tijd == '2013-04-12 20:07:25.960000'
assert isinstance(s.metadata.begin_bewerking, Bewerking)
assert int(s.metadata.begin_bewerking.id) == 3
assert isinstance(s.metadata.begin_organisatie, Organisatie)
assert int(s.metadata.begin_organisatie.id) == 1
assert 'Acacialaan (1)' == str(s)
assert "Straat(1, 'Acacialaan', 1, 3)" == repr(s)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.ListStatusStraatnamen.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
crab_service.GetStraatnaamWithStatusByStraatnaamId.return_value = Mock(
StraatnaamId=1, BeginBewerking=1, BeginOrganisatie=1,
StraatnaamLabel='Acacialaan', Straatnaam='Acacialaan',
TaalCode='nl', StraatnaamTweedeTaal=None, TaalCodeTweedeTaal=None
)
crab_service.GetGemeenteByGemeenteId.return_value = Mock(
GemeenteId=1, GewestId=1, BeginBewerking=1, BeginOrganisatie=1
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
assert s.id == 1
assert s.label == 'Acacialaan'
assert int(s.status.id) == 3
assert s.namen == (('Acacialaan', 'nl'), (None, None))
assert int(s.gemeente.id) == 1
s.metadata.set_gateway(crab_gateway)
assert isinstance(s.metadata, Metadata)
assert s.metadata.begin_datum is not None
assert s.metadata.begin_tijd is not None
assert isinstance(s.metadata.begin_bewerking, Bewerking)
assert int(s.metadata.begin_bewerking.id) == 1
assert isinstance(s.metadata.begin_organisatie, Organisatie)
assert int(s.metadata.begin_organisatie.id) == 1
def test_str_and_repr_dont_lazy_load(self):
s = Straat(1, 'Acacialaan', 1, 3)
assert 'Acacialaan (1)' == str(s)
assert "Straat(1, 'Acacialaan', 1, 3)" == repr(s)
def test_check_gateway_not_set(self):
s = Straat(1, 'Acacialaan', 1, 3)
with pytest.raises(RuntimeError):
s.check_gateway()
def test_huisnummers(self, crab_gateway, crab_service):
crab_service.ListHuisnummersWithStatusByStraatnaamId.return_value = (
Mock(HuisnummerWithStatusItem=[Mock(HuisnummerId=1)])
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
huisnummers = s.huisnummers
assert isinstance(huisnummers, list)
def test_taal(self, crab_gateway, crab_service):
crab_service.ListTalen.return_value = Mock(CodeItem=[Mock(Code='nl')])
crab_service.GetStraatnaamWithStatusByStraatnaamId.return_value = Mock(
StraatnaamId=1, BeginBewerking=1, BeginOrganisatie=1,
StraatnaamLabel='Acacialaan', Straatnaam='Acacialaan',
TaalCode='nl', StraatnaamTweedeTaal=None, TaalCodeTweedeTaal=None
)
crab_service.GetGemeenteByGemeenteId.return_value = Mock(
GemeenteId=1, GewestId=1, BeginBewerking=1, BeginOrganisatie=1,
TaalCode='nl'
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
taal = s.taal
assert isinstance(taal, Taal)
assert s.taal.id == 'nl'
def test_gemeente(self, crab_gateway, crab_service):
crab_service.GetGemeenteByGemeenteId.return_value = Mock(
GemeenteId=1, GewestId=1, BeginBewerking=1, BeginOrganisatie=1
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
gemeente = s.gemeente
assert isinstance(gemeente, Gemeente)
def test_status(self, crab_gateway, crab_service):
crab_service.ListStatusStraatnamen.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
status = s.status
assert isinstance(status, Statusstraatnaam)
def test_wegobjecten(self, crab_gateway, crab_service):
crab_service.ListWegobjectenByStraatnaamId.return_value = Mock(
WegobjectItem=[Mock(IdentificatorWegobject=1,
AardWegobject=1)]
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
wegobjecten = s.wegobjecten
assert isinstance(wegobjecten, list)
assert isinstance(wegobjecten[0], Wegobject)
def test_wegsegmenten(self, crab_gateway, crab_service):
crab_service.ListWegsegmentenByStraatnaamId.return_value = Mock(
WegsegmentItem=[Mock()]
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
wegsegmenten = s.wegsegmenten
assert isinstance(wegsegmenten, list)
assert isinstance(wegsegmenten[0], Wegsegment)
def test_bounding_box(self, crab_gateway, crab_service):
crab_service.ListWegsegmentenByStraatnaamId.return_value = Mock(
WegsegmentItem=[Mock()]
)
crab_service.GetWegsegmentByIdentificatorWegsegment.return_value = (
Mock(IdentificatorWegsegment='108724', BeginBewerking=1,
BeginOrganisatie=1,
Geometrie='LINESTRING (150339.255243488 201166.401677653,'
'150342.836939491 201165.832525652,'
'150345.139531493 201165.466573652,'
'150349.791371495 201164.769421652)')
)
s = Straat(1, 'Acacialaan', 1, 3)
s.set_gateway(crab_gateway)
bounding = s.bounding_box
assert isinstance(bounding, list)
assert len(bounding) == 4
class TestHuisnummer:
def test_fully_initialised(self):
h = Huisnummer(
1,
Statushuisnummer(3, 'inGebruik', None),
"51",
17718,
Metadata(
'1830-01-01 00:00:00',
'2011-04-29 13:27:40.230000',
Bewerking(1, '', ''),
Organisatie(5, '', '')
)
)
assert h.id == 1
assert h.huisnummer == "51"
assert int(h.status_id) == 3
assert isinstance(h.status, Statushuisnummer)
assert int(h.straat_id) == 17718
assert isinstance(h.metadata, Metadata)
assert h.metadata.begin_datum == '1830-01-01 00:00:00'
assert h.metadata.begin_tijd, '2011-04-29 13:27:40.230000'
assert isinstance(h.metadata.begin_bewerking, Bewerking)
assert int(h.metadata.begin_bewerking.id) == 1
assert isinstance(h.metadata.begin_organisatie, Organisatie)
assert int(h.metadata.begin_organisatie.id) == 5
assert '51 (1)' == str(h)
assert "Huisnummer(1, 3, '51', 17718)" == repr(h)
def test_str_dont_lazy_load(self):
h = Huisnummer(1, 3, '51', 17718)
assert '51 (1)' == str(h)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.ListStatusHuisnummers.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
crab_service.GetStraatnaamWithStatusByStraatnaamId.return_value = Mock(
StraatnaamId=17718, BeginBewerking=1, BeginOrganisatie=1
)
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = Mock(
HuisnummerId=1, BeginBewerking=1, BeginOrganisatie=1
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
assert h.id == 1
assert int(h.status.id) == 3
assert h.huisnummer == "51"
assert int(h.straat.id) == 17718
h.metadata.set_gateway(crab_gateway)
assert isinstance(h.metadata, Metadata)
assert not h.metadata.begin_datum == None
assert not h.metadata.begin_tijd == None
assert isinstance(h.metadata.begin_bewerking, Bewerking)
assert int(h.metadata.begin_bewerking.id) == 1
assert isinstance(h.metadata.begin_organisatie, Organisatie)
assert int(h.metadata.begin_organisatie.id) == 1
def test_postkanton(self, crab_gateway, crab_service):
crab_service.GetPostkantonByHuisnummerId.return_value = Mock(
PostkantonCode=1
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
postkanton = h.postkanton
assert isinstance(postkanton, Postkanton)
def test_terreinobjecten(self, crab_gateway, crab_service):
crab_service.ListTerreinobjectenByHuisnummerId.return_value = Mock(
TerreinobjectItem=[Mock()]
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
terreinobjecten = h.terreinobjecten
assert isinstance(terreinobjecten, list)
def test_percelen(self, crab_gateway, crab_service):
crab_service.ListPercelenByHuisnummerId.return_value = Mock(
PerceelItem=[Mock()]
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
percelen = h.percelen
assert isinstance(percelen, list)
def test_gebouwen(self, crab_gateway, crab_service):
crab_service.ListGebouwenByHuisnummerId.return_value = Mock(
GebouwItem=[Mock(IdentificatorGebouw=1)]
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
gebouwen = h.gebouwen
assert isinstance(gebouwen, list)
def test_subadressen(self, crab_gateway, crab_service):
crab_service.ListSubadressenWithStatusByHuisnummerId.return_value = (
Mock(SubadresWithStatusItem=[Mock(SubadresId=1)])
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
subadressen = h.subadressen
assert isinstance(subadressen, list)
def test_adresposities(self, crab_gateway, crab_service):
crab_service.ListAdrespositiesByHuisnummerId.return_value = Mock(
AdrespositieItem=[Mock()]
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
adresposities = h.adresposities
assert isinstance(adresposities, list)
def test_status(self, crab_gateway, crab_service):
crab_service.ListStatusHuisnummers.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
status = h.status
assert isinstance(status, Statushuisnummer)
def test_bounding_box(self, crab_gateway, crab_service):
crab_service.ListTerreinobjectenByHuisnummerId.return_value = Mock(
TerreinobjectItem=[Mock()]
)
crab_service.GetTerreinobjectByIdentificatorTerreinobject\
.return_value = Mock(
IdentificatorTerreinobject='13040_C_1747_G_002_00',
BeginBewerking=1, BeginOrganisatie=1
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
bounding = h.bounding_box
assert isinstance(bounding, list)
assert len(bounding) == 4
def test_check_gateway_not_set(self):
h = Huisnummer(1, 3, '51', 17718)
with pytest.raises(RuntimeError):
h.check_gateway()
def test_postadres(self, crab_gateway, crab_service):
crab_service.GetPostadresByHuisnummerId.return_value = Mock(
Postadres='Steenweg op Oosthoven 51, 2300 Turnhout'
)
h = Huisnummer(1, 3, '51', 17718)
h.set_gateway(crab_gateway)
assert h.postadres == 'Steenweg op Oosthoven 51, 2300 Turnhout'
class TestPostkanton:
def test_fully_initialised(self):
p = Postkanton(
2630
)
assert p.id == 2630
assert 'Postkanton 2630' == str(p)
assert 'Postkanton(2630)' == repr(p)
class TestWegobject:
def test_fully_initialised(self):
w = Wegobject(
"53839893",
Aardwegobject(4, 'ntLink', 'Wegverbinding volgens NavTeq.'),
(150753.46, 200148.41),
(150693.58, 200080.56, 150813.35, 200216.27),
Metadata(
'1830-01-01 00:00:00',
'2008-04-17 16:32:11.753000',
Bewerking(1, '', ''),
Organisatie(8, '', '')
)
)
assert w.id == "53839893"
assert w.centroid == (150753.46, 200148.41)
assert w.bounding_box == (150693.58, 200080.56, 150813.35, 200216.27)
assert int(w.aard_id) == 4
assert isinstance(w.aard, Aardwegobject)
assert isinstance(w.metadata, Metadata)
assert w.metadata.begin_datum == '1830-01-01 00:00:00'
assert w.metadata.begin_tijd == '2008-04-17 16:32:11.753000'
assert isinstance(w.metadata.begin_bewerking, Bewerking)
assert int(w.metadata.begin_bewerking.id) == 1
assert isinstance(w.metadata.begin_organisatie, Organisatie)
assert int(w.metadata.begin_organisatie.id) == 8
assert 'Wegobject 53839893' == str(w)
assert 'Wegobject(53839893)' == repr(w)
def test_check_gateway_not_set(self):
w = Wegobject(1, 4)
with pytest.raises(RuntimeError):
w.check_gateway()
def test_aard(self, crab_gateway, crab_service):
crab_service.ListAardWegobjecten.return_value = Mock(
CodeItem=[Mock(Code=4)]
)
w = Wegobject("53839893", 4)
w.set_gateway(crab_gateway)
aard = w.aard
assert isinstance(aard, Aardwegobject)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.ListAardWegobjecten.return_value = Mock(
CodeItem=[Mock(Code=4)]
)
crab_service.GetWegobjectByIdentificatorWegobject.return_value = Mock(
IdentificatorWegobject='53839893', BeginBewerking=1,
BeginOrganisatie=1, CenterX=150753.46, CenterY=200148.41,
MinimumX=150693.58, MinimumY=200080.56, MaximumX=150813.35,
MaximumY=200216.27
)
w = Wegobject("53839893", 4)
w.set_gateway(crab_gateway)
assert w.id == "53839893"
assert int(w.aard.id) == 4
assert w.centroid == (150753.46, 200148.41)
assert w.bounding_box == (150693.58, 200080.56, 150813.35, 200216.27)
w.metadata.set_gateway(crab_gateway)
assert isinstance(w.metadata, Metadata)
assert not w.metadata.begin_datum == None
assert not w.metadata.begin_tijd == None
assert isinstance(w.metadata.begin_bewerking, Bewerking)
assert int(w.metadata.begin_bewerking.id) == 1
assert isinstance(w.metadata.begin_organisatie, Organisatie)
assert int(w.metadata.begin_organisatie.id) == 1
class TestWegsegment:
def test_fully_initialised(self):
w = Wegsegment(
"108724",
Statuswegsegment(4, 'inGebruik', None),
Geometriemethodewegsegment(3, 'grb', None),
"""LINESTRING (150339.255243488 201166.401677653,\
150342.836939491 201165.832525652,\
150345.139531493 201165.466573652,\
150349.791371495 201164.769421652,\
150352.512459494 201164.36161365,\
150358.512331501 201163.46241365,\
150375.039179511 201156.606669646,\
150386.901963517 201150.194893643,\
150397.470027529 201142.865485638,\
150403.464011535 201135.266637631,\
150407.825739533 201127.481037624,\
150414.301515542 201109.016653612,\
150431.792971551 201057.519821577,\
150442.85677956 201026.858701557,\
150454.530123569 200999.312717538,\
150472.404939577 200955.342029508,\
150483.516619585 200927.052237488,\
150500.807755597 200883.890765458,\
150516.94650761 200844.146253429,\
150543.214411631 200773.35943738,\
150546.079307631 200764.489805374,\
150548.592075631 200754.511565369)""",
Metadata(
'1830-01-01 00:00:00',
'2013-04-12 20:12:12.687000',
Bewerking(3, '', ''),
Organisatie(1, '', '')
)
)
assert w.id == "108724"
assert w.geometrie == """LINESTRING (150339.255243488 201166.401677653,\
150342.836939491 201165.832525652,\
150345.139531493 201165.466573652,\
150349.791371495 201164.769421652,\
150352.512459494 201164.36161365,\
150358.512331501 201163.46241365,\
150375.039179511 201156.606669646,\
150386.901963517 201150.194893643,\
150397.470027529 201142.865485638,\
150403.464011535 201135.266637631,\
150407.825739533 201127.481037624,\
150414.301515542 201109.016653612,\
150431.792971551 201057.519821577,\
150442.85677956 201026.858701557,\
150454.530123569 200999.312717538,\
150472.404939577 200955.342029508,\
150483.516619585 200927.052237488,\
150500.807755597 200883.890765458,\
150516.94650761 200844.146253429,\
150543.214411631 200773.35943738,\
150546.079307631 200764.489805374,\
150548.592075631 200754.511565369)"""
assert int(w.status_id) == 4
assert isinstance(w.status, Statuswegsegment)
assert int(w._methode_id) == 3
assert isinstance(w.methode, Geometriemethodewegsegment)
assert isinstance(w.metadata, Metadata)
assert w.metadata.begin_datum == '1830-01-01 00:00:00'
assert w.metadata.begin_tijd == '2013-04-12 20:12:12.687000'
assert isinstance(w.metadata.begin_bewerking, Bewerking)
assert int(w.metadata.begin_bewerking.id) == 3
assert isinstance(w.metadata.begin_organisatie, Organisatie)
assert int(w.metadata.begin_organisatie.id) == 1
assert 'Wegsegment 108724' == str(w)
assert 'Wegsegment(108724)' == repr(w)
def test_check_gateway_not_set(self):
w = Wegsegment(1, 4)
with pytest.raises(RuntimeError):
w.check_gateway()
def test_status(self, crab_gateway, crab_service):
crab_service.ListStatusWegsegmenten.return_value = Mock(
CodeItem=[Mock(Code=4)]
)
w = Wegsegment('108724', 4)
w.set_gateway(crab_gateway)
status = w.status
assert isinstance(status, Statuswegsegment)
def test_methode(self, crab_gateway, crab_service):
crab_service.ListGeometriemethodeWegsegmenten.return_value = Mock(
CodeItem=[Mock(Code=2)]
)
crab_service.GetWegsegmentByIdentificatorWegsegment.return_value = (
Mock(IdentificatorWegsegment='108724', BeginBewerking=1,
BeginOrganisatie=1, GeometriemethodeWegsegment=2)
)
w = Wegsegment('108724', 4)
w.set_gateway(crab_gateway)
methode = w.methode
assert isinstance(methode, Geometriemethodewegsegment)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.GetWegsegmentByIdentificatorWegsegment.return_value = (
Mock(IdentificatorWegsegment='108724', BeginBewerking=1,
BeginOrganisatie=1, GeometriemethodeWegsegment=3,
Geometrie='LINESTRING (150339.255243488 201166.401677653,'
'150342.836939491 201165.832525652,'
'150345.139531493 201165.466573652,'
'150349.791371495 201164.769421652)'
)
)
crab_service.ListGeometriemethodeWegsegmenten.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
crab_service.ListStatusWegsegmenten.return_value = Mock(
CodeItem=[Mock(Code=4)]
)
w = Wegsegment('108724', 4)
w.set_gateway(crab_gateway)
assert w.id == "108724"
assert int(w.status.id) == 4
assert int(w.methode.id) == 3
assert w.geometrie == ('LINESTRING (150339.255243488 201166.401677653,'
'150342.836939491 201165.832525652,'
'150345.139531493 201165.466573652,'
'150349.791371495 201164.769421652)')
w.metadata.set_gateway(crab_gateway)
assert isinstance(w.metadata, Metadata)
assert not w.metadata.begin_datum == None
assert not w.metadata.begin_tijd == None
assert isinstance(w.metadata.begin_bewerking, Bewerking)
assert int(w.metadata.begin_bewerking.id) == 1
assert isinstance(w.metadata.begin_organisatie, Organisatie)
assert int(w.metadata.begin_organisatie.id) == 1
class TestTerreinobject:
def test_fully_initialised(self):
t = Terreinobject(
"13040_C_1747_G_002_00",
Aardterreinobject(
1,
'kadPerceel',
'Perceel volgens het Kadaster.'
),
(190708.59, 224667.59),
(190700.24, 224649.87, 190716.95, 224701.7),
Metadata(
'1998-01-01 00:00:00',
'2009-09-11 12:46:55.693000',
Bewerking(3, '', ''),
Organisatie(3, '', '')
)
)
assert t.id == "13040_C_1747_G_002_00"
assert t.centroid == (190708.59, 224667.59)
assert t.bounding_box == (190700.24, 224649.87, 190716.95, 224701.7)
assert int(t.aard_id) == 1
assert isinstance(t.aard, Aardterreinobject)
assert isinstance(t.metadata, Metadata)
assert t.metadata.begin_datum == '1998-01-01 00:00:00'
assert t.metadata.begin_tijd == '2009-09-11 12:46:55.693000'
assert isinstance(t.metadata.begin_bewerking, Bewerking)
assert int(t.metadata.begin_bewerking.id) == 3
assert isinstance(t.metadata.begin_organisatie, Organisatie)
assert int(t.metadata.begin_organisatie.id) == 3
assert 'Terreinobject 13040_C_1747_G_002_00' == str(t)
assert 'Terreinobject(13040_C_1747_G_002_00)' == repr(t)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.GetTerreinobjectByIdentificatorTerreinobject\
.return_value = Mock(
IdentificatorTerreinobject='13040_C_1747_G_002_00',
BeginBewerking=1, BeginOrganisatie=1,
CenterX=190708.59, CenterY=224667.58,
MinimumX=190700.24, MinimumY=224649.87, MaximumX=190716.95,
MaximumY=224701.7
)
crab_service.ListAardTerreinobjecten.return_value = Mock(
CodeItem=[Mock(Code=1)]
)
t = Terreinobject("13040_C_1747_G_002_00", 1)
t.set_gateway(crab_gateway)
assert t.id == "13040_C_1747_G_002_00"
assert t.centroid == (190708.59, 224667.58)
assert t.bounding_box == (190700.24, 224649.87, 190716.95, 224701.7)
assert int(t.aard.id) == 1
t.metadata.set_gateway(crab_gateway)
assert isinstance(t.metadata, Metadata)
assert not t.metadata.begin_datum == None
assert not t.metadata.begin_tijd == None
assert isinstance(t.metadata.begin_bewerking, Bewerking)
assert int(t.metadata.begin_bewerking.id) == 1
assert isinstance(t.metadata.begin_organisatie, Organisatie)
assert int(t.metadata.begin_organisatie.id) == 1
def test_aard(self, crab_gateway, crab_service):
crab_service.ListAardTerreinobjecten.return_value = Mock(
CodeItem=[Mock(Code=1)]
)
t = Terreinobject("13040_C_1747_G_002_00", 1)
t.set_gateway(crab_gateway)
assert isinstance(t.aard, Aardterreinobject)
class TestPerceel:
def test_fully_initialised(self):
p = Perceel(
"13040C1747/00G002",
(190708.59, 224667.59),
Metadata(
'1998-01-01 00:00:00',
'2009-09-11 12:46:55.693000',
Bewerking(3, '', ''),
Organisatie(3, '', '')
)
)
assert p.id == "13040C1747/00G002"
assert p.centroid == (190708.59, 224667.59)
assert isinstance(p.metadata, Metadata)
assert p.metadata.begin_datum == '1998-01-01 00:00:00'
assert p.metadata.begin_tijd == '2009-09-11 12:46:55.693000'
assert isinstance(p.metadata.begin_bewerking, Bewerking)
assert int(p.metadata.begin_bewerking.id) == 3
assert isinstance(p.metadata.begin_organisatie, Organisatie)
assert int(p.metadata.begin_organisatie.id) == 3
assert 'Perceel 13040C1747/00G002' == str(p)
assert 'Perceel(13040C1747/00G002)' == repr(p)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.GetPerceelByIdentificatorPerceel.return_value = Mock(
IdentificatorPerceel='13040C1747/00G002',
BeginBewerking=1, BeginOrganisatie=1, CenterX=190708.59,
CenterY=224667.58,
)
p = Perceel("13040C1747/00G002")
p.set_gateway(crab_gateway)
assert p.id == "13040C1747/00G002"
assert p.centroid == (190708.59, 224667.58)
p.metadata.set_gateway(crab_gateway)
assert isinstance(p.metadata, Metadata)
assert p.metadata.begin_datum is not None
assert p.metadata.begin_tijd is not None
assert isinstance(p.metadata.begin_bewerking, Bewerking)
assert int(p.metadata.begin_bewerking.id) == 1
assert isinstance(p.metadata.begin_organisatie, Organisatie)
assert int(p.metadata.begin_organisatie.id) == 1
def test_huisnummers(self, crab_gateway, crab_service):
crab_service.GetPerceelByIdentificatorPerceel.return_value = Mock(
IdentificatorPerceel='13040C1747/00G002',
BeginBewerking=1, BeginOrganisatie=1
)
crab_service.ListHuisnummersWithStatusByIdentificatorPerceel\
.return_value = Mock(
HuisnummerWithStatusItem=[Mock(HuisnummerId=1)]
)
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = (
Mock(HuisnummerId=1, BeginBewerking=1, BeginOrganisatie=1)
)
p = crab_gateway.get_perceel_by_id('13040C1747/00G002')
hnrs = p.huisnummers
assert isinstance(hnrs, list)
assert [h.id for h in hnrs] == [h.id for h in crab_gateway.list_huisnummers_by_perceel('13040C1747/00G002')]
def test_postadressen(self, crab_gateway, crab_service):
crab_service.GetPerceelByIdentificatorPerceel.return_value = Mock(
IdentificatorPerceel='13040C1747/00G002',
BeginBewerking=1, BeginOrganisatie=1
)
crab_service.ListHuisnummersWithStatusByIdentificatorPerceel\
.return_value = Mock(
HuisnummerWithStatusItem=[Mock(HuisnummerId=1)]
)
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = (
Mock(HuisnummerId=1, BeginBewerking=1, BeginOrganisatie=1,
StatusHuisnummer=3)
)
crab_service.ListStatusHuisnummers.return_value = Mock(
CodeItem=[Mock(Code='3')]
)
crab_service.GetPostadresByHuisnummerId.return_value = Mock(
Postadres='Steenweg op Oosthoven 51, 2300 Turnhout'
)
p = crab_gateway.get_perceel_by_id('13040C1747/00G002')
postadressen = p.postadressen
assert isinstance(postadressen, list)
assert ['Steenweg op Oosthoven 51, 2300 Turnhout'] == postadressen
class TestGebouw:
def test_fully_initialised(self):
g = Gebouw(
"1538575",
Aardgebouw(1, 'hoofdgebouw', 'hoofdgebouw volgens het GRB'),
Statusgebouw(4, 'inGebruik', None),
Geometriemethodegebouw(3, 'grb', None),
"""POLYGON ((190712.36432739347 224668.5216938965,\
190706.26007138938 224667.54428589717,\
190706.03594338894 224668.89276589826,\
190704.89699938893 224668.66159789637,\
190705.350887388 224666.14575789496,\
190708.31754338741 224649.70287788659,\
190717.16349539906 224653.81065388769,\
190713.40490339696 224663.38582189381,\
190712.36432739347 224668.5216938965))""",
Metadata(
'1830-01-01 00:00:00',
'2011-05-19 10:51:09.483000',
Bewerking(1, '', ''),
Organisatie(5, '', '')
)
)
assert g.id, 1538575
assert int(g.aard_id) == 1
assert isinstance(g.aard, Aardgebouw)
assert int(g.status_id) == 4
assert isinstance(g.status, Statusgebouw)
assert int(g._methode_id) == 3
assert isinstance(g.methode, Geometriemethodegebouw)
assert g.geometrie == """POLYGON ((190712.36432739347 224668.5216938965,\
190706.26007138938 224667.54428589717,\
190706.03594338894 224668.89276589826,\
190704.89699938893 224668.66159789637,\
190705.350887388 224666.14575789496,\
190708.31754338741 224649.70287788659,\
190717.16349539906 224653.81065388769,\
190713.40490339696 224663.38582189381,\
190712.36432739347 224668.5216938965))"""
assert isinstance(g.metadata, Metadata)
assert g.metadata.begin_datum == '1830-01-01 00:00:00'
assert g.metadata.begin_tijd == '2011-05-19 10:51:09.483000'
assert isinstance(g.metadata.begin_bewerking, Bewerking)
assert int(g.metadata.begin_bewerking.id) == 1
assert isinstance(g.metadata.begin_organisatie, Organisatie)
assert int(g.metadata.begin_organisatie.id) == 5
assert 'Gebouw 1538575' == str(g)
assert 'Gebouw(1538575)' == repr(g)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.ListAardGebouwen.return_value = Mock(
CodeItem=[Mock(Code=1)]
)
crab_service.ListStatusGebouwen.return_value = Mock(
CodeItem=[Mock(Code=4)]
)
crab_service.ListGeometriemethodeGebouwen.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
crab_service.GetGebouwByIdentificatorGebouw.return_value = Mock(
IdentificatorGebouw=1538575, BeginBewerking=1, BeginOrganisatie=1,
GeometriemethodeGebouw=3,
Geometrie="POLYGON ((190712.36432739347 224668.5216938965,"
"190706.26007138938 224667.54428589717,"
"190712.36432739347 224668.5216938965))"
)
g = Gebouw("1538575", 1, 4)
g.set_gateway(crab_gateway)
assert g.id == 1538575
assert int(g.aard.id) == 1
assert int(g.status.id) == 4
assert int(g.methode.id) == 3
assert g.geometrie == (
"POLYGON ((190712.36432739347 224668.5216938965,"
"190706.26007138938 224667.54428589717,"
"190712.36432739347 224668.5216938965))"
)
g.metadata.set_gateway(crab_gateway)
assert isinstance(g.metadata, Metadata)
assert g.metadata.begin_datum is not None
assert g.metadata.begin_tijd is not None
assert isinstance(g.metadata.begin_bewerking, Bewerking)
assert int(g.metadata.begin_bewerking.id) == 1
assert isinstance(g.metadata.begin_organisatie, Organisatie)
assert int(g.metadata.begin_organisatie.id) == 1
def test_aard(self, crab_gateway, crab_service):
crab_service.ListAardGebouwen.return_value = Mock(
CodeItem=[Mock(Code=1)]
)
g = Gebouw("1538575", 1, 4)
g.set_gateway(crab_gateway)
aard = g.aard
assert isinstance(aard, Aardgebouw)
def test_status(self, crab_gateway, crab_service):
crab_service.ListStatusGebouwen.return_value = Mock(
CodeItem=[Mock(Code=4)]
)
g = Gebouw("1538575", 1, 4)
g.set_gateway(crab_gateway)
status = g.status
assert isinstance(status, Statusgebouw)
def test_methode(self, crab_gateway, crab_service):
crab_service.ListGeometriemethodeGebouwen.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
crab_service.GetGebouwByIdentificatorGebouw.return_value = Mock(
IdentificatorGebouw=1538575, BeginBewerking=1, BeginOrganisatie=1,
GeometriemethodeGebouw=3
)
g = Gebouw("1538575", 1, 4)
g.set_gateway(crab_gateway)
methode = g.methode
assert isinstance(methode, Geometriemethodegebouw)
class TestMetadata:
def test_fully_initialised(self):
m = Metadata(
'1830-01-01 00:00:00',
'2003-12-06 21:42:11.117000',
Bewerking(1, '', ''),
Organisatie(6, '', '')
)
assert m.begin_datum == '1830-01-01 00:00:00'
assert m.begin_tijd == '2003-12-06 21:42:11.117000'
assert isinstance(m.begin_bewerking, Bewerking)
assert int(m.begin_bewerking.id) == 1
assert isinstance(m.begin_organisatie, Organisatie)
assert int(m.begin_organisatie.id) == 6
assert 'Begin datum: 1830-01-01 00:00:00' == str(m)
def test_lazy_load(self, crab_gateway, crab_service):
m = Metadata(
'1830-01-01 00:00:00',
'2003-12-06 21:42:11.117000',
1,
1,
gateway=crab_gateway
)
assert m.begin_datum == '1830-01-01 00:00:00'
assert m.begin_tijd == '2003-12-06 21:42:11.117000'
assert isinstance(m.begin_bewerking, Bewerking)
assert int(m.begin_bewerking.id) == 1
assert isinstance(m.begin_organisatie, Organisatie)
assert int(m.begin_organisatie.id) == 1
class TestSubadres:
def test_fully_initialised(self):
s = Subadres(
1120936,
"B",
Statussubadres(3, 'inGebruik', 'None'),
38020,
Aardsubadres(1, 'gemeente', 'Gemeente.'),
Metadata(
'1830-01-01 00:00:00',
'2011-04-29 13:27:40.230000',
Bewerking(1, '', ''),
Organisatie(5, '', '')
)
)
assert s.id == 1120936
assert s.subadres == "B"
assert int(s.status_id) == 3
assert isinstance(s.status, Statussubadres)
assert int(s.huisnummer_id) == 38020
assert isinstance(s.metadata, Metadata)
assert s.metadata.begin_datum == '1830-01-01 00:00:00'
assert s.metadata.begin_tijd, '2011-04-29 13:27:40.230000'
assert isinstance(s.metadata.begin_bewerking, Bewerking)
assert int(s.metadata.begin_bewerking.id) == 1
assert isinstance(s.metadata.begin_organisatie, Organisatie)
assert int(s.metadata.begin_organisatie.id) == 5
assert 'B (1120936)' == str(s)
assert "Subadres(1120936, 3, 'B', 38020)" == repr(s)
def test_str_dont_lazy_load(self):
s = Subadres(1120936, 'B', 3)
assert 'B (1120936)' == str(s)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.ListStatusHuisnummers.return_value = Mock(
CodeItem=[Mock(Code=3)]
)
crab_service.GetHuisnummerWithStatusByHuisnummerId.return_value = Mock(
HuisnummerId=38020, BeginBewerking=1, BeginOrganisatie=1
)
crab_service.GetSubadresWithStatusBySubadresId.return_value = Mock(
SubadresId=1120936, BeginBewerking=1, BeginOrganisatie=1,
AardSubadres=2
)
crab_service.ListAardSubadressen.return_value = Mock(
CodeItem=[Mock(Code=2)]
)
s = Subadres(1120936, 'B', 3)
s.set_gateway(crab_gateway)
assert s.id == 1120936
assert int(s.status.id) == 3
assert s.subadres == "B"
assert isinstance(s.aard, Aardsubadres)
assert int(s.huisnummer.id) == 38020
s.metadata.set_gateway(crab_gateway)
assert isinstance(s.metadata, Metadata)
assert s.metadata.begin_datum is not None
assert s.metadata.begin_tijd is not None
assert isinstance(s.metadata.begin_bewerking, Bewerking)
assert int(s.metadata.begin_bewerking.id) == 1
assert isinstance(s.metadata.begin_organisatie, Organisatie)
assert int(s.metadata.begin_organisatie.id) == 1
def test_check_gateway_not_set(self):
s = Subadres(1, 3, 'B', 129462)
with pytest.raises(RuntimeError):
s.check_gateway()
def test_adresposities(self, crab_gateway, crab_service):
crab_service.ListAdrespositiesBySubadresId.return_value = Mock(
AdrespositieItem=[Mock()]
)
s = Subadres(1120936, 'B', 3)
s.set_gateway(crab_gateway)
adresposities = s.adresposities
assert isinstance(adresposities, list)
def test_postadres(self, crab_gateway, crab_service):
crab_service.GetPostadresBySubadresId.return_value = Mock(
Postadres='Antoon van Brabantstraat 7 bus B, 2630 Aartselaar'
)
s = Subadres(1120936, 'B', 3)
s.set_gateway(crab_gateway)
assert s.postadres == 'Antoon van Brabantstraat 7 bus B, 2630 Aartselaar'
class TestAdrespositie:
def test_fully_initialised(self):
a = Adrespositie(
4087928,
Herkomstadrespositie(
'6',
'manueleAanduidingVanToegangTotDeWeg',
None
),
"""POINT(190705.34 224675.26)""",
Aardadres(
'1',
'subAdres',
'Aanduiding van een plaats op een huisnummer'
),
Metadata(
'1830-01-01 00:00:00',
'',
None,
None
)
)
assert a.id == 4087928
assert str(a.herkomst.id) == '6'
assert a.geometrie == 'POINT(190705.34 224675.26)'
assert str(a.aard.id) == '1'
assert isinstance(a.metadata, Metadata)
assert a.metadata.begin_datum == '1830-01-01 00:00:00'
assert 'Adrespositie 4087928' == str(a)
assert "Adrespositie(4087928, 6)" == repr(a)
def test_str_dont_lazy_load(self, crab_gateway):
a = Adrespositie(4087928, 2)
a.set_gateway(crab_gateway)
assert 'Adrespositie 4087928' == str(a)
def test_lazy_load(self, crab_gateway, crab_service):
crab_service.GetAdrespositieByAdrespositieId.return_value = Mock(
AdrespositieId=4428005, BeginBewerking=1, BeginOrganisatie=1,
Geometrie='POINT (74414.91 225777.36)', AardAdres=2,
BeginDatum='1830-01-01 00:00:00'
)
crab_service.ListAardAdressen.return_value = Mock(
CodeItem=[Mock(Code=2)]
)
a = Adrespositie(4428005, 3)
a.set_gateway(crab_gateway)
assert a.id == 4428005
assert a.herkomst_id == 3
assert str(a.geometrie) == str('POINT (74414.91 225777.36)')
assert int(a.aard.id) == 2
assert isinstance(a.metadata, Metadata)
assert a.metadata.begin_datum == '1830-01-01 00:00:00'
def test_check_gateway_not_set(self):
a = Adrespositie(4087928, 2)
with pytest.raises(RuntimeError):
a.check_gateway()
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
3816,
199,
199,
646,
4613,
199,
504,
1683,
492,
4420,
199,
199,
504,
286,
14411,
647,
14,
7019,
14,
1971,
492,
334,
272,
27166,
14357,
1726,
12,
272,
27166,
4031,
22646,
199,
9,
199,
504,
286,
14411,
647,
14,
7019,
14,
67,
14411,
492,
334,
272,
598,
546,
597,
12,
2165,
11908,
559,
69,
12,
272,
5346,
278,
27036,
12,
1487,
352,
303,
278,
27036,
12,
32316,
279,
12,
272,
699,
546,
281,
17443,
12,
13125,
7199,
2159,
69,
12,
272,
437,
5596,
456,
350,
470,
12,
437,
1005,
350,
470,
12,
272,
437,
1005,
303,
28514,
87,
12,
437,
1005,
1129,
71,
785,
12,
272,
437,
1005,
351,
264,
262,
785,
12,
9795,
10616,
374,
1507,
2626,
12,
272,
27673,
27678,
456,
350,
470,
12,
9795,
14183,
292,
3540,
455,
12,
272,
9795,
1129,
71,
9255,
12,
5346,
1377,
599,
69,
5247,
380,
1129,
71,
9255,
12,
272,
9795,
303,
28514,
87,
12,
5346,
1377,
599,
69,
5247,
380,
303,
28514,
87,
12,
272,
18769,
75,
676,
270,
350,
470,
555,
338,
23958,
12,
428,
1239,
292,
12,
272,
869,
85,
374,
1507,
2626,
12,
7711,
75,
867,
265,
12,
272,
2136,
71,
785,
12,
2136,
71,
9255,
12,
272,
13861,
264,
262,
785,
12,
3492,
301,
352,
12,
272,
5346,
28514,
87,
12,
16160,
12,
4804,
350,
470,
12,
272,
4431,
470,
555,
338,
23958,
199,
9,
421,
199,
533,
1379,
35,
14411,
12455,
26,
339,
347,
511,
63,
513,
63,
303,
87,
397,
724,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1296,
39,
546,
397,
724,
14,
1107,
63,
585,
275,
4420,
8,
288,
598,
546,
597,
2081,
1524,
355,
4420,
8,
39,
546,
597,
1304,
29,
17,
12,
32316,
279,
3034,
39,
546,
597,
8565,
455,
534,
14176,
297,
598,
546,
597,
8565,
455,
534,
54,
416,
19470,
358,
288,
1622,
267,
776,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
303,
87,
397,
724,
342,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
702,
1228,
8,
470,
59,
16,
467,
598,
546,
597,
9,
339,
347,
511,
63,
362,
63,
303,
19082,
63,
991,
63,
344,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1002,
39,
546,
597,
2175,
39,
546,
597,
1304,
3325,
22620,
279,
3034,
14,
1107,
63,
585,
275,
4420,
8,
288,
598,
546,
597,
1304,
29,
18,
12,
267,
776,
267,
522,
275,
286,
14411,
63,
7019,
14,
362,
63,
303,
19082,
63,
991,
63,
344,
8,
18,
9,
267,
702,
1228,
8,
470,
12,
598,
546,
597,
9,
267,
702,
522,
14,
344,
508,
499,
267,
702,
1228,
8,
470,
14,
22098,
12,
2008,
9,
267,
702,
1228,
8,
470,
14,
24511,
63,
1977,
12,
2008,
9,
339,
347,
511,
63,
362,
63,
303,
19082,
63,
991,
63,
324,
5952,
63,
344,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1002,
39,
546,
597,
2175,
39,
546,
597,
1304,
3325,
22620,
279,
3034,
14,
2441,
63,
5881,
275,
334,
288,
27166,
4031,
22646,
267,
776,
267,
543,
4613,
14,
3536,
8,
12455,
4031,
22646,
304,
288,
286,
14411,
63,
7019,
14,
362,
63,
303,
19082,
63,
991,
63,
344,
2801,
17,
9,
339,
347,
511,
63,
513,
63,
303,
278,
287,
724,
63,
885,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1002,
39,
546,
597,
2175,
39,
546,
597,
1304,
3325,
22620,
279,
3034,
14,
1107,
63,
585,
275,
4420,
8,
288,
598,
546,
597,
1304,
29,
18,
12,
267,
776,
267,
286,
14411,
63,
1364,
14,
1296,
4240,
278,
287,
724,
2175,
39,
546,
597,
1304,
14,
1107,
63,
585,
275,
4420,
8,
288,
5346,
278,
27036,
2081,
1524,
355,
4420,
8,
4240,
278,
27036,
1304,
29,
17,
12,
653,
1311,
4240,
278,
27036,
3034,
29,
9943,
12,
2151,
32316,
279,
3034,
534,
14176,
297,
32316,
279,
3034,
4240,
278,
27036,
8565,
455,
534,
14176,
358,
288,
1622,
267,
776,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
303,
278,
287,
724,
342,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
702,
1228,
8,
470,
59,
16,
467,
5346,
278,
27036,
9,
267,
702,
522,
59,
16,
1055,
303,
19082,
14,
344,
508,
499,
339,
347,
511,
63,
513,
63,
303,
278,
287,
724,
63,
86,
416,
290,
271,
828,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1296,
4240,
278,
287,
724,
2175,
39,
546,
597,
1304,
14,
1107,
63,
585,
275,
4420,
8,
288,
5346,
278,
27036,
2081,
1524,
355,
4420,
8,
4240,
278,
27036,
1304,
29,
17,
12,
653,
1311,
4240,
278,
27036,
3034,
29,
9943,
12,
2151,
32316,
279,
3034,
534,
14176,
297,
32316,
279,
3034,
4240,
278,
27036,
8565,
455,
534,
14176,
358,
288,
1622,
267,
776,
267,
2312,
19082,
275,
598,
546,
597,
8,
18,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
303,
278,
287,
724,
8,
303,
19082,
9,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
702,
1228,
8,
470,
59,
16,
467,
5346,
278,
27036,
9,
267,
702,
522,
59,
16,
1055,
303,
19082,
14,
344,
508,
499,
339,
347,
511,
63,
513,
63,
496,
11908,
2578,
8,
277,
12,
286,
14411,
63,
7019,
304,
267,
2312,
19082,
275,
598,
546,
597,
8,
17,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
496,
11908,
2578,
8,
303,
19082,
9,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
2312,
19082,
275,
598,
546,
597,
8,
19,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
496,
11908,
2578,
8,
303,
19082,
9,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
2312,
19082,
275,
598,
546,
597,
8,
18,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
496
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
3816,
199,
199,
646,
4613,
199,
504,
1683,
492,
4420,
199,
199,
504,
286,
14411,
647,
14,
7019,
14,
1971,
492,
334,
272,
27166,
14357,
1726,
12,
272,
27166,
4031,
22646,
199,
9,
199,
504,
286,
14411,
647,
14,
7019,
14,
67,
14411,
492,
334,
272,
598,
546,
597,
12,
2165,
11908,
559,
69,
12,
272,
5346,
278,
27036,
12,
1487,
352,
303,
278,
27036,
12,
32316,
279,
12,
272,
699,
546,
281,
17443,
12,
13125,
7199,
2159,
69,
12,
272,
437,
5596,
456,
350,
470,
12,
437,
1005,
350,
470,
12,
272,
437,
1005,
303,
28514,
87,
12,
437,
1005,
1129,
71,
785,
12,
272,
437,
1005,
351,
264,
262,
785,
12,
9795,
10616,
374,
1507,
2626,
12,
272,
27673,
27678,
456,
350,
470,
12,
9795,
14183,
292,
3540,
455,
12,
272,
9795,
1129,
71,
9255,
12,
5346,
1377,
599,
69,
5247,
380,
1129,
71,
9255,
12,
272,
9795,
303,
28514,
87,
12,
5346,
1377,
599,
69,
5247,
380,
303,
28514,
87,
12,
272,
18769,
75,
676,
270,
350,
470,
555,
338,
23958,
12,
428,
1239,
292,
12,
272,
869,
85,
374,
1507,
2626,
12,
7711,
75,
867,
265,
12,
272,
2136,
71,
785,
12,
2136,
71,
9255,
12,
272,
13861,
264,
262,
785,
12,
3492,
301,
352,
12,
272,
5346,
28514,
87,
12,
16160,
12,
4804,
350,
470,
12,
272,
4431,
470,
555,
338,
23958,
199,
9,
421,
199,
533,
1379,
35,
14411,
12455,
26,
339,
347,
511,
63,
513,
63,
303,
87,
397,
724,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1296,
39,
546,
397,
724,
14,
1107,
63,
585,
275,
4420,
8,
288,
598,
546,
597,
2081,
1524,
355,
4420,
8,
39,
546,
597,
1304,
29,
17,
12,
32316,
279,
3034,
39,
546,
597,
8565,
455,
534,
14176,
297,
598,
546,
597,
8565,
455,
534,
54,
416,
19470,
358,
288,
1622,
267,
776,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
303,
87,
397,
724,
342,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
702,
1228,
8,
470,
59,
16,
467,
598,
546,
597,
9,
339,
347,
511,
63,
362,
63,
303,
19082,
63,
991,
63,
344,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1002,
39,
546,
597,
2175,
39,
546,
597,
1304,
3325,
22620,
279,
3034,
14,
1107,
63,
585,
275,
4420,
8,
288,
598,
546,
597,
1304,
29,
18,
12,
267,
776,
267,
522,
275,
286,
14411,
63,
7019,
14,
362,
63,
303,
19082,
63,
991,
63,
344,
8,
18,
9,
267,
702,
1228,
8,
470,
12,
598,
546,
597,
9,
267,
702,
522,
14,
344,
508,
499,
267,
702,
1228,
8,
470,
14,
22098,
12,
2008,
9,
267,
702,
1228,
8,
470,
14,
24511,
63,
1977,
12,
2008,
9,
339,
347,
511,
63,
362,
63,
303,
19082,
63,
991,
63,
324,
5952,
63,
344,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1002,
39,
546,
597,
2175,
39,
546,
597,
1304,
3325,
22620,
279,
3034,
14,
2441,
63,
5881,
275,
334,
288,
27166,
4031,
22646,
267,
776,
267,
543,
4613,
14,
3536,
8,
12455,
4031,
22646,
304,
288,
286,
14411,
63,
7019,
14,
362,
63,
303,
19082,
63,
991,
63,
344,
2801,
17,
9,
339,
347,
511,
63,
513,
63,
303,
278,
287,
724,
63,
885,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1002,
39,
546,
597,
2175,
39,
546,
597,
1304,
3325,
22620,
279,
3034,
14,
1107,
63,
585,
275,
4420,
8,
288,
598,
546,
597,
1304,
29,
18,
12,
267,
776,
267,
286,
14411,
63,
1364,
14,
1296,
4240,
278,
287,
724,
2175,
39,
546,
597,
1304,
14,
1107,
63,
585,
275,
4420,
8,
288,
5346,
278,
27036,
2081,
1524,
355,
4420,
8,
4240,
278,
27036,
1304,
29,
17,
12,
653,
1311,
4240,
278,
27036,
3034,
29,
9943,
12,
2151,
32316,
279,
3034,
534,
14176,
297,
32316,
279,
3034,
4240,
278,
27036,
8565,
455,
534,
14176,
358,
288,
1622,
267,
776,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
303,
278,
287,
724,
342,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
702,
1228,
8,
470,
59,
16,
467,
5346,
278,
27036,
9,
267,
702,
522,
59,
16,
1055,
303,
19082,
14,
344,
508,
499,
339,
347,
511,
63,
513,
63,
303,
278,
287,
724,
63,
86,
416,
290,
271,
828,
8,
277,
12,
286,
14411,
63,
7019,
12,
286,
14411,
63,
1364,
304,
267,
286,
14411,
63,
1364,
14,
1296,
4240,
278,
287,
724,
2175,
39,
546,
597,
1304,
14,
1107,
63,
585,
275,
4420,
8,
288,
5346,
278,
27036,
2081,
1524,
355,
4420,
8,
4240,
278,
27036,
1304,
29,
17,
12,
653,
1311,
4240,
278,
27036,
3034,
29,
9943,
12,
2151,
32316,
279,
3034,
534,
14176,
297,
32316,
279,
3034,
4240,
278,
27036,
8565,
455,
534,
14176,
358,
288,
1622,
267,
776,
267,
2312,
19082,
275,
598,
546,
597,
8,
18,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
303,
278,
287,
724,
8,
303,
19082,
9,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
702,
1228,
8,
470,
59,
16,
467,
5346,
278,
27036,
9,
267,
702,
522,
59,
16,
1055,
303,
19082,
14,
344,
508,
499,
339,
347,
511,
63,
513,
63,
496,
11908,
2578,
8,
277,
12,
286,
14411,
63,
7019,
304,
267,
2312,
19082,
275,
598,
546,
597,
8,
17,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
496,
11908,
2578,
8,
303,
19082,
9,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
2312,
19082,
275,
598,
546,
597,
8,
19,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
496,
11908,
2578,
8,
303,
19082,
9,
267,
702,
1228,
8,
470,
12,
769,
9,
267,
2312,
19082,
275,
598,
546,
597,
8,
18,
9,
267,
522,
275,
286,
14411,
63,
7019,
14,
513,
63,
496,
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,
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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
] |
xguse/ete
|
doc/old_tutorial/examples/get_distances_between_nodes.py
|
4
|
2475
|
from ete_dev import Tree
# Loads a tree with branch lenght information. Note that if no
# distance info is provided in the newick, it will be initialized with
# the default dist value = 1.0
nw = """(((A:0.1, B:0.01):0.001, C:0.0001):1.0,
(((((D:0.00001:0,I:0):0,F:0):0,G:0):0,H:0):0,
E:0.000001):0.0000001):2.0;"""
t = Tree(nw)
print t
# /-A
# /--------|
# /--------| \-B
# | |
# | \-C
# |
# | /-D
# | /--------|
#---------| /--------| \-I
# | | |
# | /--------| \-F
# | | |
# | /--------| \-G
# | | |
# \--------| \-H
# |
# \-E
#
# Locate some nodes
A = t&"A"
C = t&"C"
# Calculate distance from current node
print "The distance between A and C is", A.get_distance("C")
# Calculate distance between two descendants of current node
print "The distance between A and C is", t.get_distance("A","C")
# Calculate the toplogical distance (number of nodes in between)
print "The number of nodes between A and D is ", \
t.get_distance("A","D", topology_only=True)
# Calculate the farthest node from E within the whole structure
farthest, dist = (t&"E").get_farthest_node()
print "The farthest node from E is", farthest.name, "with dist=", dist
# Calculate the farthest node from E within the whole structure,
# regarding the number of nodes in between as distance value
# Note that the result is differnt.
farthest, dist = (t&"E").get_farthest_node(topology_only=True)
print "The farthest (topologically) node from E is", \
farthest.name, "with", dist, "nodes in between"
# Calculate farthest node from an internal node
farthest, dist = t.get_farthest_node()
print "The farthest node from root is is", farthest.name, "with dist=", dist
#
# The program results in the following information:
#
# The distance between A and C is 0.1011
# The distance between A and C is 0.1011
# The number of nodes between A and D is 8.0
# The farthest node from E is A with dist= 1.1010011
# The farthest (topologically) node from E is I with 5.0 nodes in between
# The farthest node from root is is A with dist= 1.101
|
gpl-3.0
|
[
504,
325,
266,
63,
2374,
492,
12178,
199,
199,
3,
30367,
282,
3123,
543,
5246,
822,
913,
2556,
14,
3390,
626,
340,
949,
199,
3,
6033,
2256,
365,
2741,
315,
314,
892,
2000,
12,
652,
911,
506,
10038,
543,
199,
3,
314,
849,
2917,
574,
275,
413,
14,
16,
199,
13100,
275,
408,
12925,
33,
26,
16,
14,
17,
12,
699,
26,
16,
14,
614,
304,
16,
14,
4587,
12,
445,
26,
16,
14,
4183,
304,
17,
14,
16,
12,
199,
1332,
12925,
36,
26,
16,
14,
22417,
26,
16,
12,
41,
26,
16,
304,
16,
12,
38,
26,
16,
304,
16,
12,
39,
26,
16,
304,
16,
12,
40,
26,
16,
304,
16,
12,
199,
37,
26,
16,
14,
19983,
304,
16,
14,
3273,
17,
304,
18,
14,
16,
27,
624,
199,
84,
275,
12178,
8,
13100,
9,
199,
1361,
307,
199,
3,
19242,
1182,
13,
33,
199,
3,
8540,
1182,
518,
92,
199,
3,
3515,
1182,
518,
92,
3515,
971,
13,
34,
199,
3,
260,
1204,
260,
1204,
199,
3,
260,
1204,
3515,
971,
13,
35,
199,
3,
260,
1204,
199,
3,
260,
1204,
2476,
8295,
1182,
13,
36,
199,
3,
260,
1204,
2476,
263,
1182,
518,
92,
199,
3,
9960,
92,
19242,
1182,
518,
92,
3515,
971,
13,
41,
199,
3,
260,
1204,
17907,
1204,
260,
1204,
199,
3,
260,
1204,
8540,
1182,
518,
92,
3515,
971,
13,
38,
199,
3,
260,
1204,
7861,
1204,
260,
1204,
199,
3,
260,
1204,
3515,
1182,
518,
92,
3515,
971,
13,
39,
199,
3,
260,
1204,
260,
1204,
260,
1204,
199,
3,
3515,
971,
518,
92,
3515,
971,
13,
40,
199,
3,
7861,
1204,
199,
3,
8540,
971,
13,
37,
199,
3,
199,
3,
6263,
323,
2005,
3380,
199,
33,
275,
307,
6,
2,
33,
2,
199,
35,
275,
307,
6,
2,
35,
2,
199,
3,
12707,
6033,
687,
1453,
1031,
199,
1361,
298,
1918,
6033,
3382,
437,
436,
445,
365,
401,
221,
437,
14,
362,
63,
5590,
480,
35,
531,
199,
3,
12707,
6033,
3382,
2877,
26061,
402,
1453,
1031,
199,
1361,
298,
1918,
6033,
3382,
437,
436,
445,
365,
401,
221,
307,
14,
362,
63,
5590,
480,
33,
2266,
35,
531,
199,
3,
12707,
314,
2746,
7954,
6033,
334,
1955,
402,
3380,
315,
3382,
9,
199,
1361,
298,
1918,
1329,
402,
3380,
3382,
437,
436,
577,
365,
3872,
221,
971,
272,
307,
14,
362,
63,
5590,
480,
33,
2266,
36,
401,
14611,
63,
2118,
29,
549,
9,
199,
3,
12707,
314,
12474,
273,
597,
1031,
687,
662,
4453,
314,
8852,
5523,
199,
15315,
273,
597,
12,
2917,
275,
334,
84,
6,
2,
37,
3471,
362,
63,
15315,
273,
597,
63,
932,
342,
199,
1361,
298,
1918,
12474,
273,
597,
1031,
687,
662,
365,
401,
12474,
273,
597,
14,
354,
12,
298,
1045,
2917,
11107,
2917,
199,
3,
12707,
314,
12474,
273,
597,
1031,
687,
662,
4453,
314,
8852,
5523,
12,
199,
3,
12602,
314,
1329,
402,
3380,
315,
3382,
465,
6033,
574,
199,
3,
3390,
626,
314,
754,
365,
14460,
343,
14,
199,
15315,
273,
597,
12,
2917,
275,
334,
84,
6,
2,
37,
3471,
362,
63,
15315,
273,
597,
63,
932,
8,
10775,
63,
2118,
29,
549,
9,
199,
1361,
298,
1918,
12474,
273,
597,
334,
16851,
793,
7288,
9,
1031,
687,
662,
365,
401,
971,
272,
12474,
273,
597,
14,
354,
12,
298,
1045,
401,
2917,
12,
298,
2415,
315,
3382,
2,
199,
3,
12707,
12474,
273,
597,
1031,
687,
376,
5007,
1031,
199,
15315,
273,
597,
12,
2917,
275,
307,
14,
362,
63,
15315,
273,
597,
63,
932,
342,
199,
1361,
298,
1918,
12474,
273,
597,
1031,
687,
1738,
365,
365,
401,
12474,
273,
597,
14,
354,
12,
298,
1045,
2917,
11107,
2917,
199,
3,
199,
3,
710,
2240,
2058,
315,
314,
2569,
2556,
26,
199,
3,
199,
3,
710,
6033,
3382,
437,
436,
445,
365,
378,
14,
4893,
17,
199,
3,
710,
6033,
3382,
437,
436,
445,
365,
378,
14,
4893,
17,
199,
3,
710,
1329,
402,
3380,
3382,
437,
436,
577,
365,
221,
1695,
14,
16,
199,
3,
710,
12474,
273,
597,
1031,
687,
662,
365,
437,
543,
2917,
29,
413,
14,
4893,
20679,
199,
3,
710,
12474,
273,
597,
334,
16851,
793,
7288,
9,
1031,
687,
662,
365,
473,
543,
959,
14,
16,
3380,
315,
3382,
199,
3,
710,
12474,
273,
597,
1031,
687,
1738,
365,
365,
437,
543,
2917,
29,
413,
14,
4893,
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
] |
[
325,
266,
63,
2374,
492,
12178,
199,
199,
3,
30367,
282,
3123,
543,
5246,
822,
913,
2556,
14,
3390,
626,
340,
949,
199,
3,
6033,
2256,
365,
2741,
315,
314,
892,
2000,
12,
652,
911,
506,
10038,
543,
199,
3,
314,
849,
2917,
574,
275,
413,
14,
16,
199,
13100,
275,
408,
12925,
33,
26,
16,
14,
17,
12,
699,
26,
16,
14,
614,
304,
16,
14,
4587,
12,
445,
26,
16,
14,
4183,
304,
17,
14,
16,
12,
199,
1332,
12925,
36,
26,
16,
14,
22417,
26,
16,
12,
41,
26,
16,
304,
16,
12,
38,
26,
16,
304,
16,
12,
39,
26,
16,
304,
16,
12,
40,
26,
16,
304,
16,
12,
199,
37,
26,
16,
14,
19983,
304,
16,
14,
3273,
17,
304,
18,
14,
16,
27,
624,
199,
84,
275,
12178,
8,
13100,
9,
199,
1361,
307,
199,
3,
19242,
1182,
13,
33,
199,
3,
8540,
1182,
518,
92,
199,
3,
3515,
1182,
518,
92,
3515,
971,
13,
34,
199,
3,
260,
1204,
260,
1204,
199,
3,
260,
1204,
3515,
971,
13,
35,
199,
3,
260,
1204,
199,
3,
260,
1204,
2476,
8295,
1182,
13,
36,
199,
3,
260,
1204,
2476,
263,
1182,
518,
92,
199,
3,
9960,
92,
19242,
1182,
518,
92,
3515,
971,
13,
41,
199,
3,
260,
1204,
17907,
1204,
260,
1204,
199,
3,
260,
1204,
8540,
1182,
518,
92,
3515,
971,
13,
38,
199,
3,
260,
1204,
7861,
1204,
260,
1204,
199,
3,
260,
1204,
3515,
1182,
518,
92,
3515,
971,
13,
39,
199,
3,
260,
1204,
260,
1204,
260,
1204,
199,
3,
3515,
971,
518,
92,
3515,
971,
13,
40,
199,
3,
7861,
1204,
199,
3,
8540,
971,
13,
37,
199,
3,
199,
3,
6263,
323,
2005,
3380,
199,
33,
275,
307,
6,
2,
33,
2,
199,
35,
275,
307,
6,
2,
35,
2,
199,
3,
12707,
6033,
687,
1453,
1031,
199,
1361,
298,
1918,
6033,
3382,
437,
436,
445,
365,
401,
221,
437,
14,
362,
63,
5590,
480,
35,
531,
199,
3,
12707,
6033,
3382,
2877,
26061,
402,
1453,
1031,
199,
1361,
298,
1918,
6033,
3382,
437,
436,
445,
365,
401,
221,
307,
14,
362,
63,
5590,
480,
33,
2266,
35,
531,
199,
3,
12707,
314,
2746,
7954,
6033,
334,
1955,
402,
3380,
315,
3382,
9,
199,
1361,
298,
1918,
1329,
402,
3380,
3382,
437,
436,
577,
365,
3872,
221,
971,
272,
307,
14,
362,
63,
5590,
480,
33,
2266,
36,
401,
14611,
63,
2118,
29,
549,
9,
199,
3,
12707,
314,
12474,
273,
597,
1031,
687,
662,
4453,
314,
8852,
5523,
199,
15315,
273,
597,
12,
2917,
275,
334,
84,
6,
2,
37,
3471,
362,
63,
15315,
273,
597,
63,
932,
342,
199,
1361,
298,
1918,
12474,
273,
597,
1031,
687,
662,
365,
401,
12474,
273,
597,
14,
354,
12,
298,
1045,
2917,
11107,
2917,
199,
3,
12707,
314,
12474,
273,
597,
1031,
687,
662,
4453,
314,
8852,
5523,
12,
199,
3,
12602,
314,
1329,
402,
3380,
315,
3382,
465,
6033,
574,
199,
3,
3390,
626,
314,
754,
365,
14460,
343,
14,
199,
15315,
273,
597,
12,
2917,
275,
334,
84,
6,
2,
37,
3471,
362,
63,
15315,
273,
597,
63,
932,
8,
10775,
63,
2118,
29,
549,
9,
199,
1361,
298,
1918,
12474,
273,
597,
334,
16851,
793,
7288,
9,
1031,
687,
662,
365,
401,
971,
272,
12474,
273,
597,
14,
354,
12,
298,
1045,
401,
2917,
12,
298,
2415,
315,
3382,
2,
199,
3,
12707,
12474,
273,
597,
1031,
687,
376,
5007,
1031,
199,
15315,
273,
597,
12,
2917,
275,
307,
14,
362,
63,
15315,
273,
597,
63,
932,
342,
199,
1361,
298,
1918,
12474,
273,
597,
1031,
687,
1738,
365,
365,
401,
12474,
273,
597,
14,
354,
12,
298,
1045,
2917,
11107,
2917,
199,
3,
199,
3,
710,
2240,
2058,
315,
314,
2569,
2556,
26,
199,
3,
199,
3,
710,
6033,
3382,
437,
436,
445,
365,
378,
14,
4893,
17,
199,
3,
710,
6033,
3382,
437,
436,
445,
365,
378,
14,
4893,
17,
199,
3,
710,
1329,
402,
3380,
3382,
437,
436,
577,
365,
221,
1695,
14,
16,
199,
3,
710,
12474,
273,
597,
1031,
687,
662,
365,
437,
543,
2917,
29,
413,
14,
4893,
20679,
199,
3,
710,
12474,
273,
597,
334,
16851,
793,
7288,
9,
1031,
687,
662,
365,
473,
543,
959,
14,
16,
3380,
315,
3382,
199,
3,
710,
12474,
273,
597,
1031,
687,
1738,
365,
365,
437,
543,
2917,
29,
413,
14,
4893,
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,
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,
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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
] |
some-0n3/imgcls_utils
|
training.py
|
1
|
21638
|
"""This module implements the training for lasagne models.
The classes are designed to train a lasagne model on a fixed data set
with different learning rates. The training schedule can be epoch or
iteration based.
The classes print the training and test error to the standard output
every epoch or in a given interval of iterations.
Please use the :class:`EpochTrainer` and :class:`IterationTrainer`
for training, the class :class:`Trainer` does not implements a
training mechanisms.
Example
-------
>>> input_var = ...
>>> target_var = ...
>>> model = ...
>>>
>>> trainer = EpochTrainer(model)
>>> trainer.dataset = MNIST(interval=(0, 1))
>>>
>>> prediction = get_output(model, inputs=input_var, deterministic=False)
>>> loss = categorical_crossentropy(prediction, target_var)
>>> params = get_all_params(model, trainable=True)
>>> updates = momentum(loss, params, momentum=0.9,
learning_rate=trainer.learning_rate)
>>> trainer.set_training(input_var, target_var, loss, updates)
>>>
>>> trainer.train_epochs(50, 0.001)
>>> trainer.train_epochs(20, 0.0001)
>>> save_model(trainer.model, 'mnist_model.npz')
"""
import os
import pickle
import time
from collections import OrderedDict
from warnings import warn
import numpy
from lasagne.layers.helper import get_all_layers
from lasagne.utils import floatX
from theano import function, shared, tensor
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
from . import load_model, load_updates, loss_acc, mini_batch_func, save_model,\
save_updates
from .data import DataSet
__all__ = ('EpochTrainer', 'IterationTrainer')
def get_random_streams(model):
"""Return a list with all ``RandomStreams`` in the model."""
return [l._srng for l in get_all_layers(model) if hasattr(l, '_srng')]
def save_random_streams(streams, path):
"""Save a list of random streams to a file."""
dct = {}
for i, stream in enumerate(streams):
stream.seed()
dct[f'seed_{i}'] = stream.default_instance_seed
numpy.savez(path, **dct)
def load_random_streams(model, path):
"""Load the random streams from a file into a model."""
layers = [l for l in get_all_layers(model) if hasattr(l, '_srng')]
with numpy.load(path) as fobj:
for i, layer in enumerate(layers):
layer._srng = RandomStreams(fobj[f'seed_{i}'].item())
class Trainer():
"""The default super class for all trainers.
This class implements basic mechanisms for the training, but not the
training itself.
Parameters
----------
model : a :class:`Layer` instance
The model to train.
dataset : a :class:`Dataset` instance or ``None`` (``None``)
The data set used for training and testing.
batchsize : integer (``256``)
The batch size used for training.
val_batchsize : integer (``500``)
The batch size used for testing and validation.
"""
dataset_cls = DataSet
def __init__(self, model, dataset=None, batchsize=256, val_batchsize=500):
self.model = model
self.dataset = dataset
self.batchsize = batchsize
self.val_bsize = val_batchsize
self._learn_rate = shared(floatX(0.0))
self.journal = []
self.updates = None
self._train = None
self._value_names = []
# compile validation function
input_var = tensor.tensor4('inputs')
target_var = tensor.ivector('targets')
loss, acc = loss_acc(model, input_var, target_var)
self._validate = function([input_var, target_var], [loss, acc])
@property
def learning_rate(self):
"""The learning rate used for training (shared variable)."""
return self._learn_rate
@learning_rate.setter
def learning_rate(self, learning_rate):
"""Set the learning rate to the given value.
Parameters
----------
learning_rate : float
The value for the learning rate.
"""
# TODO : support other types (e.g. shared variable)
self._learn_rate.set_value(floatX(learning_rate))
def set_training(self, input_var, target_var, loss, updates, values=None):
"""Set the updates and compile the training function.
Parameters
----------
input_var : theano symbolic variable
A variable representing the network input.
target_var : theano symbolic variable
A variable representing the desired network
output.
loss : scalar
The theano expression for the loss.
updates : OrderedDict
The dictionary, mapping all of the network parameters
to their update expressions.
values : dictionary or ``None`` (``None``)
A dictionary with additional values to be logged for the
training. The dictionary should map names for the logging
to their respective theano variables.
"""
self.updates = updates
logging = OrderedDict([('train_err', loss), ])
if values is not None:
logging.update(values)
self._value_names = list(logging.keys())
self._train = function([input_var, target_var], list(logging.values()),
updates=updates)
def _batch_valid_(self, data, labels):
# TODO : replace with `DataSet.iter`
val_fn = mini_batch_func(self._validate, self.val_bsize)
err, acc = val_fn(data, labels)
return err, acc
def test(self):
"""Return the loss and accuracy over the test set."""
if self.dataset.test:
return self._batch_valid_(*self.dataset.test.set)
return floatX('nan'), floatX('nan')
def validate(self):
"""Return the loss and accuracy over the validation set."""
return self._batch_valid_(*self.dataset.validation.set)
def save_state(self, prefix, resume=False):
"""Save the state of a trainer into 2 or 5 files.
The trainer saves the parameter for the current model, the
updates from the optimizer, state information about the
random number generation, the journal and the dataset into 5
separate files. All files will have the given prefix and
different endings.
Parameters
----------
prefix : string
The file name prefix for the files.
resume : boolean (``False``)
If ``True`` also save data needed for resuming the training.
Otherwise only the model parameters and the journal is saved.
"""
save_model(self.model, f'{prefix}.npz')
with open(f'{prefix}_journal.pkl', 'wb') as fobj:
pickle.dump(self.journal, fobj)
if not resume:
return
save_updates(self.updates, f'{prefix}_updates.npz')
if self.dataset:
self.dataset.save_state(f'{prefix}_data.npz')
streams = get_random_streams(self.model)
if streams:
save_random_streams(streams, f'{prefix}_rng_data.npz')
@classmethod
def load_state(cls, model, prefix, **kwargs):
"""Load the state of the trainer from files.
This method will create a new trainer instance from the files
with the given prefix. This method is to load a trainer that was
saved via `save_state`.
Parameters
----------
model: a :class:`Layer` instance
The (uninitialized) model.
prefix: string
The Prefix for the files.
**kwargs : keyword arguments
Key-word arguments that will be passed down to the
constructor.
Returns
-------
a :class:`Trainer` instance
The new trainer with all the parameters loaded from the
files.
"""
# model parameters
model = load_model(model, f'{prefix}.npz')
# random stream data
filename = f'{prefix}_rng_data.npz'
if os.path.isfile(filename):
load_random_streams(model, filename)
trainer = cls(model, **kwargs)
# updates
filename = f'{prefix}_updates.npz'
if os.path.isfile(filename):
if trainer.updates is None:
warn('Could not load update parameters.')
else:
load_updates(trainer.updates, filename)
# journal
with open(f'{prefix}_journal.pkl', 'rb') as fobj:
trainer.journal = pickle.load(fobj)
# dataset
filename = f'{prefix}_data.npz'
if os.path.isfile(filename):
trainer.dataset = cls.dataset_cls.from_state(filename)
return trainer
def train(self, *args, **kwargs):
"""Train the network according to a given schedule."""
raise NotImplementedError('')
@staticmethod
def _log_error_(values, valid_err, valid_acc):
"""Print the training, val. loss and val. acc."""
print(f' Training Loss: {values[0].mean():>10.6f}')
print(f' Validation Loss: {valid_err:>10.6f}')
print(f' Validation Accuracy: {valid_acc:>10.2%}')
@staticmethod
def load_journal(path):
"""Load a journal from a given file path.
Parameters
----------
path : string
path to the journal file.
Returns
-------
dictionary
A dictionary containing the following training information:
``'train_err'`` the training error (loss) for each iteration.
``'valid_err'`` the error (cross-entropy) on the test set.
``'valid_acc'`` the accuracy on the test set.
``'valid_itr'`` the number of iteration at any point in
``'valid_err'`` or ``'valid_acc'``.
Additionally to that, there is also a ``numpy.array`` for
every entry in the ``values`` parameter that was passed to
the ``Trainer.set_training`` method. The array contains the
corresponding values to the logged variables for every
iteration.
"""
raise NotImplementedError('')
class EpochTrainer(Trainer):
"""Implements a epoch based training scheduling.
Parameters
----------
model : a :class:`Layer` instance
The model to train.
dataset : a :class:`Dataset` instance or ``None`` (``None``)
The data set used for training and testing.
batchsize : integer (``256``)
The batch size used for training.
val_batchsize : integer (``500``)
The batch size used for testing and validation.
"""
def __init__(self, *args, **kwargs):
super(EpochTrainer, self).__init__(*args, **kwargs)
self._total_epochs = 0
@classmethod
def load_state(cls, model, prefix, **kwargs):
trainer = super(EpochTrainer, cls).load_state(model, prefix, **kwargs)
trainer._total_epochs = len(trainer.journal)
return trainer
def _train_epochs_(self, epochs, learning_rate):
"""Train the network for a given amount of epochs."""
self.learning_rate = learning_rate
def train_fn():
iterator = self.dataset.training.iter(self.batchsize)
results = [self._train(d, l) for d, l in iterator]
return [numpy.array(r) for r in zip(*results)]
print(f'Training {epochs:>3} epochs '
f'with a learning rate of {learning_rate:.6f}.')
done_epochs = len(self.journal) + 1
for current in range(done_epochs, done_epochs + epochs):
entry = {'learning rate': learning_rate,
'batchsize': self.batchsize, 'epoch': current}
start_time = time.time()
values = train_fn()
entry.update(zip(self._value_names, values))
valid_err, valid_acc = self.test()
entry['valid_err'] = valid_err
entry['valid_acc'] = valid_acc
duration = time.time() - start_time
self.journal.append(entry)
print(f'Epoch {current:>3}/{self._total_epochs:>3}'
f' took {duration:.3f}s')
self._log_error_(values, valid_err, valid_acc)
def train_epochs(self, epochs, learning_rate, **kwargs):
"""Train the network for a given number of epochs.
Parameters
----------
epochs : integer
The number of epochs to train.
learning_rate : float
The learning rate to use.
"""
self._total_epochs += epochs
start_time = time.time()
self._train_epochs_(epochs, learning_rate, **kwargs)
duration = time.time() - start_time
print(f'Training done. Time:{duration:>15.3f}s \t({epochs} epochs,'
f' ~{duration / epochs:.3f}s/epoch).')
def train(self, config, **kwargs):
"""Train the network according to a given schedule.
Parameters
----------
config : list of dictionaries
A learning schedule for training. It is represented as a
list of dictionaries, each containing a ``'learning rate'``
and a ``'epochs'`` field that state how many epochs are to
be trained with that learning rate.
"""
print('Start training...')
num_epochs = sum(e['epochs'] for e in config)
self._total_epochs += num_epochs
start_time = time.time()
for entry in config:
self._train_epochs_(entry['epochs'], entry['learning rate'],
**kwargs)
duration = time.time() - start_time
print(f'Training done. Time: {duration:>15.3f}s \t({num_epochs}'
f' epochs, ~{duration / num_epochs:.3f}s/epoch).')
@staticmethod
def load_journal(path):
"""Load a journal from a given file path.
Parameters
----------
path : string
path to the journal file.
Returns
-------
dictionary
A dictionary containing the following training information:
``'train_err'`` the training error (loss) for each iteration.
``'valid_err'`` the error (cross-entropy) on the test set.
``'valid_acc'`` the accuracy on the test set.
``'valid_itr'`` the number of iteration at any point in
``'valid_err'`` or ``'valid_acc'``.
``'train_err_epoch'`` the training error by epoch
(as 2d-array).
Additionally to that, there are also two ``numpy.array``
for every entry in the ``values`` parameter that was passed
to the ``Trainer.set_training`` method. One is named after
the entry in the parameter and contains the corresponding
values to the theano variable for every iteration. The other
has the additional postfix ``'_epoch'`` and contains the
epoch wise entries just like ``'train_err_epoch'``.
"""
with open(path, 'rb') as fobj:
journal = pickle.load(fobj)
assert all(a == b for a, b in zip((j['epoch'] for j in journal),
range(1, 1 + len(journal))))
train_err = numpy.array([j['train_err'] for j in journal])
epochs, step = train_err.shape
learningrates = [[j['learning rate'], ] * step for j in journal]
batchsizes = [[j['batchsize'], ] * step for j in journal]
result = {
'train_err_epoch': train_err,
'learning_rates_epoch': numpy.array(learningrates),
'batchsizes_epoch': numpy.array(batchsizes),
'train_err': numpy.hstack(train_err),
'train_itr': numpy.arange(1, epochs * step + 1),
'valid_acc': numpy.array([j['valid_acc'] for j in journal]),
'valid_err': numpy.array([j['valid_err'] for j in journal]),
'valid_itr': numpy.arange(1, epochs + 1) * step,
'learning_rates': numpy.hstack(learningrates),
'batchsizes': numpy.hstack(batchsizes),
}
keys = set()
keys.update(*[j.keys() for j in journal])
keys -= {'train_err', 'epoch', 'learning rate', 'batchsize',
'valid_acc', 'valid_err'}
for key in keys:
result[key + '_epoch'] = numpy.array([j[key] for j in journal])
result[key] = numpy.hstack([j[key] for j in journal])
return result
class IterationTrainer(Trainer):
"""Implements a iteration based training scheduling.
Parameters
----------
model : a :class:`Layer` instance
The model to train.
dataset : a :class:`Dataset` instance or ``None`` (``None``)
The data set used for training and testing.
batchsize : integer (``256``)
The batch size used for training.
val_batchsize : integer (``500``)
The batch size used for testing and validation.
"""
def __init__(self, *args, **kwargs):
super(IterationTrainer, self).__init__(*args, **kwargs)
self._total_iters = 0
@classmethod
def load_state(cls, model, prefix, **kwargs):
trainer = super(IterationTrainer, cls).load_state(model, prefix,
**kwargs)
trainer._total_iters = len(trainer.journal)
return trainer
def _train_iters_(self, iterations, learning_rate, tick=200):
"""Train the model for a given amount of iterations."""
self.learning_rate = learning_rate
iterator = self.dataset.training.endless_iter(self.batchsize)
print(f'Training {iterations:>3} iterations'
f' with a learning rate of {learning_rate:.6f}.')
tmpl = 'Iteration {:>7}/{:>7} @ ~{:.3f} iterations/s'
done_iters = len(self.journal) + 1
start_time = time.time()
for current in range(done_iters, done_iters + iterations):
entry = {'learning rate': learning_rate,
'batchsize': self.batchsize,
'iteration': current}
self.journal.append(entry)
data, labels = next(iterator)
values = self._train(data, labels)
entry.update(zip(self._value_names, values))
if current % tick == 0:
duration = time.time() - start_time
valid_err, valid_acc = self.test()
entry['valid_err'] = valid_err
entry['valid_acc'] = valid_acc
print(tmpl.format(current, self._total_iters, tick / duration))
self._log_error_(values, valid_err, valid_acc)
start_time = time.time()
def train_iters(self, iterations, learning_rate, **kwargs):
"""Train the model for a given number of iterations.
Parameters
----------
iterations : integer
The number of iterations to train.
learning_rate : float
The learning rate to use for training.
tick : integer (``200``)
The network will be evaluated on the test set every
``tick`` iterations.
"""
self._total_iters += iterations
start_time = time.time()
self._train_iters_(iterations, learning_rate, **kwargs)
duration = time.time() - start_time
print(f'Training done. Time:{duration:>15.3f}s \t({iterations} iters.,'
f' ~{iterations / duration:.3f} iter/s).')
def train(self, config, **kwargs):
"""Train the network according to a given schedule.
Parameters
----------
config : list of dictionaries
A learning schedule for training. It is represented as a
list of dictionaries, each containing a ``'learning rate'``
and a ``'iterations'`` field that state how many iterations
are to be trained with that learning rate.
tick : integer (``200``)
The network will be evaluated on the test set every
``tick`` iterations.
"""
print("Start training...")
iterations = sum(e['iterations'] for e in config)
self._total_iters += iterations
start_time = time.time()
for entry in config:
self._train_iters_(entry['iterations'], entry['learning rate'],
**kwargs)
delta = time.time() - start_time
print(f'Training done. Time:{delta:>15.3f}s \t({iterations} iters,'
f' ~{iterations / delta:.3f} iter/s).')
@staticmethod
def load_journal(path):
with open(path, 'rb') as fobj:
journal = pickle.load(fobj)
assert all(a == b for a, b in zip(
(j['iteration'] for j in journal),
range(1, 1 + len(journal))
))
keys = set()
keys.update(*[j.keys() for j in journal])
keys -= {'valid_err', 'valid_acc'}
result = {k: numpy.array([j[k] for j in journal]) for k in keys}
result['train_itr'] = numpy.arange(1, len(journal) + 1)
result['valid_acc'] = numpy.array([j['valid_acc'] for j in journal
if 'valid_acc' in j])
result['valid_err'] = numpy.array([j['valid_err'] for j in journal
if 'valid_err' in j])
result['valid_itr'] = numpy.array(
[i for i, j in enumerate(journal, 1) if 'valid_acc' in j])
return result
|
mit
|
[
624,
2765,
859,
9031,
314,
6093,
367,
23325,
29575,
1709,
14,
199,
199,
1918,
3992,
787,
19829,
370,
3560,
282,
23325,
29575,
1402,
641,
282,
6317,
666,
663,
199,
1045,
3365,
9328,
24434,
14,
710,
6093,
8732,
883,
506,
9463,
503,
199,
12575,
4079,
14,
199,
1918,
3992,
870,
314,
6093,
436,
511,
1125,
370,
314,
4465,
1072,
199,
14287,
9463,
503,
315,
282,
1627,
6252,
402,
10615,
14,
199,
199,
8254,
675,
314,
520,
533,
1705,
29322,
2437,
16187,
64,
436,
520,
533,
1705,
8666,
2437,
16187,
64,
199,
509,
6093,
12,
314,
1021,
520,
533,
1705,
2437,
16187,
64,
1630,
440,
9031,
282,
199,
7588,
562,
10832,
706,
14,
199,
199,
9846,
199,
12797,
199,
6071,
1324,
63,
1391,
275,
2263,
199,
6071,
1347,
63,
1391,
275,
2263,
199,
6071,
1402,
275,
2263,
199,
6071,
199,
6071,
3560,
281,
275,
662,
5132,
2437,
16187,
8,
1238,
9,
199,
6071,
3560,
281,
14,
5214,
275,
603,
25392,
8,
4284,
2687,
16,
12,
413,
430,
199,
6071,
199,
6071,
12044,
275,
664,
63,
1199,
8,
1238,
12,
4153,
29,
1210,
63,
1391,
12,
25286,
29,
797,
9,
199,
6071,
5621,
275,
22138,
63,
20363,
1150,
7537,
8,
14845,
12,
1347,
63,
1391,
9,
199,
6071,
1862,
275,
664,
63,
452,
63,
1162,
8,
1238,
12,
17029,
29,
549,
9,
199,
6071,
7029,
275,
23887,
8,
4358,
12,
1862,
12,
23887,
29,
16,
14,
25,
12,
2432,
9328,
63,
1866,
29,
2834,
281,
14,
10546,
63,
1866,
9,
199,
6071,
3560,
281,
14,
409,
63,
7588,
8,
1210,
63,
1391,
12,
1347,
63,
1391,
12,
5621,
12,
7029,
9,
199,
6071,
199,
6071,
3560,
281,
14,
2834,
63,
13161,
8,
1400,
12,
378,
14,
4587,
9,
199,
6071,
3560,
281,
14,
2834,
63,
13161,
8,
1165,
12,
378,
14,
4183,
9,
199,
6071,
3354,
63,
1238,
8,
2834,
281,
14,
1238,
12,
283,
32164,
63,
1238,
14,
1590,
90,
358,
199,
624,
199,
646,
747,
199,
646,
5927,
199,
646,
900,
199,
504,
5055,
492,
8773,
199,
504,
3598,
492,
7987,
199,
199,
646,
2680,
199,
504,
23325,
29575,
14,
4359,
14,
3676,
492,
664,
63,
452,
63,
4359,
199,
504,
23325,
29575,
14,
1208,
492,
2069,
56,
199,
504,
14377,
492,
805,
12,
5709,
12,
2345,
199,
504,
14377,
14,
16647,
14,
12686,
63,
77,
12430,
492,
603,
14058,
63,
3883,
19358,
465,
9571,
19358,
199,
199,
504,
1275,
492,
2248,
63,
1238,
12,
2248,
63,
7618,
12,
5621,
63,
5470,
12,
20536,
63,
2912,
63,
1532,
12,
3354,
63,
1238,
4202,
272,
3354,
63,
7618,
199,
504,
1275,
576,
492,
3918,
1084,
421,
199,
363,
452,
363,
275,
661,
29322,
2437,
16187,
297,
283,
8666,
2437,
16187,
358,
421,
199,
318,
664,
63,
2355,
63,
11231,
8,
1238,
304,
272,
408,
1767,
282,
769,
543,
1006,
1124,
3883,
19358,
1040,
315,
314,
1402,
1041,
272,
372,
359,
76,
423,
5474,
2753,
367,
634,
315,
664,
63,
452,
63,
4359,
8,
1238,
9,
340,
2688,
8,
76,
12,
2513,
5474,
2753,
5440,
421,
199,
318,
3354,
63,
2355,
63,
11231,
8,
11231,
12,
931,
304,
272,
408,
8229,
282,
769,
402,
2196,
13788,
370,
282,
570,
1041,
272,
16354,
275,
1052,
272,
367,
284,
12,
2547,
315,
3874,
8,
11231,
304,
267,
2547,
14,
5176,
342,
267,
16354,
59,
70,
1159,
69,
379,
7348,
73,
93,
418,
275,
2547,
14,
885,
63,
842,
63,
5176,
272,
2680,
14,
2117,
90,
8,
515,
12,
1011,
20660,
9,
421,
199,
318,
2248,
63,
2355,
63,
11231,
8,
1238,
12,
931,
304,
272,
408,
6200,
314,
2196,
13788,
687,
282,
570,
1901,
282,
1402,
1041,
272,
9393,
275,
359,
76,
367,
634,
315,
664,
63,
452,
63,
4359,
8,
1238,
9,
340,
2688,
8,
76,
12,
2513,
5474,
2753,
5440,
272,
543,
2680,
14,
912,
8,
515,
9,
465,
29962,
26,
267,
367,
284,
12,
4045,
315,
3874,
8,
4359,
304,
288,
4045,
423,
5474,
2753,
275,
9571,
19358,
8,
32755,
59,
70,
1159,
69,
379,
7348,
73,
93,
2278,
1053,
1012,
421,
199,
533,
16732,
281,
837,
272,
408,
1918,
849,
1613,
1021,
367,
1006,
3560,
1192,
14,
339,
961,
1021,
9031,
5678,
562,
10832,
706,
367,
314,
6093,
12,
1325,
440,
314,
272,
6093,
6337,
14,
339,
3897,
272,
4143,
272,
1402,
520,
282,
520,
533,
1705,
5003,
64,
1256,
267,
710,
1402,
370,
3560,
14,
272,
4789,
520,
282,
520,
533,
1705,
9271,
64,
1256,
503,
1124,
403,
1040,
15693,
403,
16580,
267,
710,
666,
663,
1202,
367,
6093,
436,
5343,
14,
272,
3522,
890,
520,
3000,
15693,
3912,
16580,
267,
710,
3522,
1568,
1202,
367,
6093,
14,
272,
1139,
63,
2912,
890,
520,
3000,
15693,
5783,
16580,
267,
710,
3522,
1568,
1202,
367,
5343,
436,
6411,
14,
272,
408,
339,
4789,
63,
1886,
275,
3918,
1084,
339,
347,
636,
826,
721,
277,
12,
1402,
12,
4789,
29,
403,
12,
3522,
890,
29,
3912,
12,
1139,
63,
2912,
890,
29,
5783,
304,
267,
291,
14,
1238,
275,
1402,
267,
291,
14,
5214,
275,
4789,
267,
291,
14,
2912,
890,
275,
3522,
890,
267,
291,
14,
637,
63,
66,
890,
275,
1139,
63,
2912,
890,
267,
291,
423,
4643,
63,
1866,
275,
5709,
8,
31293,
8,
16,
14,
16,
430,
267,
291,
14,
7067,
275,
942,
267,
291,
14,
7618,
275,
488,
267,
291,
423,
2834,
275,
488,
267,
291,
423,
585,
63,
1247,
275,
942,
398,
327,
6555,
6411,
805,
267,
1324,
63,
1391,
275,
2345,
14,
3128,
20,
360,
3711,
358,
267,
1347,
63,
1391,
275,
2345,
14,
1912,
630,
360,
4684,
358,
267,
5621,
12,
6907,
275,
5621,
63,
5470,
8,
1238,
12,
1324,
63,
1391,
12,
1347,
63,
1391,
9,
267,
291,
423,
3502,
275,
805,
779,
1210,
63,
1391,
12,
1347,
63,
1391,
467,
359,
4358,
12,
6907,
566,
339,
768,
1829,
272,
347,
9328,
63,
1866,
8,
277,
304,
267,
408,
1918,
9328,
6634,
1202,
367,
6093,
334,
5555,
1750,
10477,
267,
372,
291,
423,
4643,
63,
1866,
339,
768,
10546,
63,
1866,
14,
8345,
272,
347,
9328,
63,
1866,
8,
277,
12,
9328,
63,
1866,
304,
267,
408,
1084,
314,
9328,
6634,
370,
314,
1627,
574,
14,
398
] |
[
2765,
859,
9031,
314,
6093,
367,
23325,
29575,
1709,
14,
199,
199,
1918,
3992,
787,
19829,
370,
3560,
282,
23325,
29575,
1402,
641,
282,
6317,
666,
663,
199,
1045,
3365,
9328,
24434,
14,
710,
6093,
8732,
883,
506,
9463,
503,
199,
12575,
4079,
14,
199,
1918,
3992,
870,
314,
6093,
436,
511,
1125,
370,
314,
4465,
1072,
199,
14287,
9463,
503,
315,
282,
1627,
6252,
402,
10615,
14,
199,
199,
8254,
675,
314,
520,
533,
1705,
29322,
2437,
16187,
64,
436,
520,
533,
1705,
8666,
2437,
16187,
64,
199,
509,
6093,
12,
314,
1021,
520,
533,
1705,
2437,
16187,
64,
1630,
440,
9031,
282,
199,
7588,
562,
10832,
706,
14,
199,
199,
9846,
199,
12797,
199,
6071,
1324,
63,
1391,
275,
2263,
199,
6071,
1347,
63,
1391,
275,
2263,
199,
6071,
1402,
275,
2263,
199,
6071,
199,
6071,
3560,
281,
275,
662,
5132,
2437,
16187,
8,
1238,
9,
199,
6071,
3560,
281,
14,
5214,
275,
603,
25392,
8,
4284,
2687,
16,
12,
413,
430,
199,
6071,
199,
6071,
12044,
275,
664,
63,
1199,
8,
1238,
12,
4153,
29,
1210,
63,
1391,
12,
25286,
29,
797,
9,
199,
6071,
5621,
275,
22138,
63,
20363,
1150,
7537,
8,
14845,
12,
1347,
63,
1391,
9,
199,
6071,
1862,
275,
664,
63,
452,
63,
1162,
8,
1238,
12,
17029,
29,
549,
9,
199,
6071,
7029,
275,
23887,
8,
4358,
12,
1862,
12,
23887,
29,
16,
14,
25,
12,
2432,
9328,
63,
1866,
29,
2834,
281,
14,
10546,
63,
1866,
9,
199,
6071,
3560,
281,
14,
409,
63,
7588,
8,
1210,
63,
1391,
12,
1347,
63,
1391,
12,
5621,
12,
7029,
9,
199,
6071,
199,
6071,
3560,
281,
14,
2834,
63,
13161,
8,
1400,
12,
378,
14,
4587,
9,
199,
6071,
3560,
281,
14,
2834,
63,
13161,
8,
1165,
12,
378,
14,
4183,
9,
199,
6071,
3354,
63,
1238,
8,
2834,
281,
14,
1238,
12,
283,
32164,
63,
1238,
14,
1590,
90,
358,
199,
624,
199,
646,
747,
199,
646,
5927,
199,
646,
900,
199,
504,
5055,
492,
8773,
199,
504,
3598,
492,
7987,
199,
199,
646,
2680,
199,
504,
23325,
29575,
14,
4359,
14,
3676,
492,
664,
63,
452,
63,
4359,
199,
504,
23325,
29575,
14,
1208,
492,
2069,
56,
199,
504,
14377,
492,
805,
12,
5709,
12,
2345,
199,
504,
14377,
14,
16647,
14,
12686,
63,
77,
12430,
492,
603,
14058,
63,
3883,
19358,
465,
9571,
19358,
199,
199,
504,
1275,
492,
2248,
63,
1238,
12,
2248,
63,
7618,
12,
5621,
63,
5470,
12,
20536,
63,
2912,
63,
1532,
12,
3354,
63,
1238,
4202,
272,
3354,
63,
7618,
199,
504,
1275,
576,
492,
3918,
1084,
421,
199,
363,
452,
363,
275,
661,
29322,
2437,
16187,
297,
283,
8666,
2437,
16187,
358,
421,
199,
318,
664,
63,
2355,
63,
11231,
8,
1238,
304,
272,
408,
1767,
282,
769,
543,
1006,
1124,
3883,
19358,
1040,
315,
314,
1402,
1041,
272,
372,
359,
76,
423,
5474,
2753,
367,
634,
315,
664,
63,
452,
63,
4359,
8,
1238,
9,
340,
2688,
8,
76,
12,
2513,
5474,
2753,
5440,
421,
199,
318,
3354,
63,
2355,
63,
11231,
8,
11231,
12,
931,
304,
272,
408,
8229,
282,
769,
402,
2196,
13788,
370,
282,
570,
1041,
272,
16354,
275,
1052,
272,
367,
284,
12,
2547,
315,
3874,
8,
11231,
304,
267,
2547,
14,
5176,
342,
267,
16354,
59,
70,
1159,
69,
379,
7348,
73,
93,
418,
275,
2547,
14,
885,
63,
842,
63,
5176,
272,
2680,
14,
2117,
90,
8,
515,
12,
1011,
20660,
9,
421,
199,
318,
2248,
63,
2355,
63,
11231,
8,
1238,
12,
931,
304,
272,
408,
6200,
314,
2196,
13788,
687,
282,
570,
1901,
282,
1402,
1041,
272,
9393,
275,
359,
76,
367,
634,
315,
664,
63,
452,
63,
4359,
8,
1238,
9,
340,
2688,
8,
76,
12,
2513,
5474,
2753,
5440,
272,
543,
2680,
14,
912,
8,
515,
9,
465,
29962,
26,
267,
367,
284,
12,
4045,
315,
3874,
8,
4359,
304,
288,
4045,
423,
5474,
2753,
275,
9571,
19358,
8,
32755,
59,
70,
1159,
69,
379,
7348,
73,
93,
2278,
1053,
1012,
421,
199,
533,
16732,
281,
837,
272,
408,
1918,
849,
1613,
1021,
367,
1006,
3560,
1192,
14,
339,
961,
1021,
9031,
5678,
562,
10832,
706,
367,
314,
6093,
12,
1325,
440,
314,
272,
6093,
6337,
14,
339,
3897,
272,
4143,
272,
1402,
520,
282,
520,
533,
1705,
5003,
64,
1256,
267,
710,
1402,
370,
3560,
14,
272,
4789,
520,
282,
520,
533,
1705,
9271,
64,
1256,
503,
1124,
403,
1040,
15693,
403,
16580,
267,
710,
666,
663,
1202,
367,
6093,
436,
5343,
14,
272,
3522,
890,
520,
3000,
15693,
3912,
16580,
267,
710,
3522,
1568,
1202,
367,
6093,
14,
272,
1139,
63,
2912,
890,
520,
3000,
15693,
5783,
16580,
267,
710,
3522,
1568,
1202,
367,
5343,
436,
6411,
14,
272,
408,
339,
4789,
63,
1886,
275,
3918,
1084,
339,
347,
636,
826,
721,
277,
12,
1402,
12,
4789,
29,
403,
12,
3522,
890,
29,
3912,
12,
1139,
63,
2912,
890,
29,
5783,
304,
267,
291,
14,
1238,
275,
1402,
267,
291,
14,
5214,
275,
4789,
267,
291,
14,
2912,
890,
275,
3522,
890,
267,
291,
14,
637,
63,
66,
890,
275,
1139,
63,
2912,
890,
267,
291,
423,
4643,
63,
1866,
275,
5709,
8,
31293,
8,
16,
14,
16,
430,
267,
291,
14,
7067,
275,
942,
267,
291,
14,
7618,
275,
488,
267,
291,
423,
2834,
275,
488,
267,
291,
423,
585,
63,
1247,
275,
942,
398,
327,
6555,
6411,
805,
267,
1324,
63,
1391,
275,
2345,
14,
3128,
20,
360,
3711,
358,
267,
1347,
63,
1391,
275,
2345,
14,
1912,
630,
360,
4684,
358,
267,
5621,
12,
6907,
275,
5621,
63,
5470,
8,
1238,
12,
1324,
63,
1391,
12,
1347,
63,
1391,
9,
267,
291,
423,
3502,
275,
805,
779,
1210,
63,
1391,
12,
1347,
63,
1391,
467,
359,
4358,
12,
6907,
566,
339,
768,
1829,
272,
347,
9328,
63,
1866,
8,
277,
304,
267,
408,
1918,
9328,
6634,
1202,
367,
6093,
334,
5555,
1750,
10477,
267,
372,
291,
423,
4643,
63,
1866,
339,
768,
10546,
63,
1866,
14,
8345,
272,
347,
9328,
63,
1866,
8,
277,
12,
9328,
63,
1866,
304,
267,
408,
1084,
314,
9328,
6634,
370,
314,
1627,
574,
14,
398,
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,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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
] |
LLNL/spack
|
var/spack/repos/builtin/packages/kallisto/package.py
|
2
|
1805
|
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
class Kallisto(CMakePackage):
"""kallisto is a program for quantifying abundances of transcripts from
RNA-Seq data."""
homepage = "http://pachterlab.github.io/kallisto"
url = "https://github.com/pachterlab/kallisto/archive/v0.43.1.tar.gz"
version('0.46.2', sha256='c447ca8ddc40fcbd7d877d7c868bc8b72807aa8823a8a8d659e19bdd515baaf2')
version('0.43.1', sha256='7baef1b3b67bcf81dc7c604db2ef30f5520b48d532bf28ec26331cb60ce69400')
depends_on('zlib')
depends_on('hdf5')
depends_on('mpich')
# htslib isn't built in time to be used....
parallel = False
# v0.44.0 vendored a copy of htslib and uses auto* to build
# its configure script.
depends_on('autoconf', type='build', when='@0.44.0:')
depends_on('automake', type='build', when='@0.44.0:')
depends_on('libtool', type='build', when='@0.44.0:')
depends_on('m4', type='build', when='@0.44.0:')
# Including '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON' in the cmake args
# causes bits of cmake's output to end up in the autoconf-generated
# configure script.
# See https://github.com/spack/spack/issues/15274 and
# https://github.com/pachterlab/kallisto/issues/253
@property
def std_cmake_args(self):
"""Call the original std_cmake_args and then filter the verbose
setting.
"""
a = super(Kallisto, self).std_cmake_args
if (self.spec.version >= Version('0.44.0')):
args = [i for i in a if i != '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON']
else:
args = a
return args
|
lgpl-2.1
|
[
3,
1898,
6171,
13,
13934,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
436,
1163,
199,
3,
428,
1389,
7290,
23493,
14,
1666,
314,
2746,
13,
1896,
5877,
570,
367,
2436,
14,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
334,
28993,
13,
18,
14,
16,
1549,
10697,
9,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
1804,
279,
513,
79,
8,
27984,
8599,
304,
272,
408,
26446,
513,
79,
365,
282,
2240,
367,
2173,
290,
3338,
316,
2236,
725,
13236,
402,
7115,
6429,
687,
2126,
820,
7170,
13,
11205,
666,
1041,
339,
26586,
275,
298,
1014,
921,
387,
335,
351,
5561,
14,
5031,
14,
2308,
15,
26446,
513,
79,
2,
272,
1166,
420,
275,
298,
2859,
921,
5031,
14,
957,
15,
387,
335,
351,
5561,
15,
26446,
513,
79,
15,
6404,
15,
86,
16,
14,
2824,
14,
17,
14,
5369,
14,
6838,
2,
339,
1015,
360,
16,
14,
2466,
14,
18,
297,
7793,
3912,
534,
67,
20773,
696,
24,
617,
67,
2167,
70,
2894,
68,
23,
68,
24,
1138,
68,
23,
67,
15430,
3776,
24,
66,
2819,
11369,
2158,
1299,
1789,
65,
24,
65,
24,
68,
31485,
69,
1167,
26293,
28082,
66,
31498,
18,
358,
272,
1015,
360,
16,
14,
2824,
14,
17,
297,
7793,
3912,
534,
23,
2470,
2829,
17,
66,
19,
66,
1822,
66,
2177,
2835,
3833,
23,
67,
30320,
697,
18,
2829,
1216,
70,
1229,
1165,
66,
2006,
68,
30102,
4361,
1651,
825,
1479,
15638,
2894,
2259,
301,
1876,
5303,
358,
339,
8350,
63,
265,
360,
15371,
358,
272,
8350,
63,
265,
360,
19912,
21,
358,
272,
8350,
63,
265,
360,
311,
1158,
358,
339,
327,
394,
1086,
773,
5712,
1133,
6137,
315,
900,
370,
506,
1202,
4496,
272,
9861,
275,
756,
339,
327,
373,
16,
14,
1602,
14,
16,
373,
500,
2908,
282,
1331,
402,
394,
1086,
773,
436,
4440,
2599,
10,
370,
1900,
272,
327,
2399,
7908,
2884,
14,
272,
8350,
63,
265,
360,
2495,
2190,
297,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
272,
8350,
63,
265,
360,
2495,
1875,
297,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
272,
8350,
63,
265,
360,
773,
3557,
297,
221,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
272,
8350,
63,
265,
360,
77,
20,
297,
755,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
339,
327,
1010,
4923,
2475,
5196,
18421,
63,
16075,
63,
18421,
3817,
26,
16026,
29,
615,
7,
315,
314,
19773,
1249,
272,
327,
14486,
5821,
402,
19773,
1159,
1072,
370,
1284,
1536,
315,
314,
2599,
2190,
13,
10176,
272,
327,
7908,
2884,
14,
272,
327,
1666,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
15,
10115,
15,
1046,
9014,
436,
272,
327,
4178,
921,
5031,
14,
957,
15,
387,
335,
351,
5561,
15,
26446,
513,
79,
15,
10115,
15,
3781,
272,
768,
1829,
272,
347,
2418,
63,
16472,
63,
589,
8,
277,
304,
267,
408,
2176,
314,
3379,
2418,
63,
16472,
63,
589,
436,
2066,
2457,
314,
3376,
267,
4260,
14,
267,
408,
267,
282,
275,
1613,
8,
43,
279,
513,
79,
12,
291,
680,
1516,
63,
16472,
63,
589,
267,
340,
334,
277,
14,
1650,
14,
1023,
2356,
3394,
360,
16,
14,
1602,
14,
16,
8109,
288,
1249,
275,
359,
73,
367,
284,
315,
282,
340,
284,
1137,
2475,
5196,
18421,
63,
16075,
63,
18421,
3817,
26,
16026,
29,
615,
418,
267,
587,
26,
288,
1249,
275,
282,
398,
372,
1249,
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
] |
[
1898,
6171,
13,
13934,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
436,
1163,
199,
3,
428,
1389,
7290,
23493,
14,
1666,
314,
2746,
13,
1896,
5877,
570,
367,
2436,
14,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
334,
28993,
13,
18,
14,
16,
1549,
10697,
9,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
1804,
279,
513,
79,
8,
27984,
8599,
304,
272,
408,
26446,
513,
79,
365,
282,
2240,
367,
2173,
290,
3338,
316,
2236,
725,
13236,
402,
7115,
6429,
687,
2126,
820,
7170,
13,
11205,
666,
1041,
339,
26586,
275,
298,
1014,
921,
387,
335,
351,
5561,
14,
5031,
14,
2308,
15,
26446,
513,
79,
2,
272,
1166,
420,
275,
298,
2859,
921,
5031,
14,
957,
15,
387,
335,
351,
5561,
15,
26446,
513,
79,
15,
6404,
15,
86,
16,
14,
2824,
14,
17,
14,
5369,
14,
6838,
2,
339,
1015,
360,
16,
14,
2466,
14,
18,
297,
7793,
3912,
534,
67,
20773,
696,
24,
617,
67,
2167,
70,
2894,
68,
23,
68,
24,
1138,
68,
23,
67,
15430,
3776,
24,
66,
2819,
11369,
2158,
1299,
1789,
65,
24,
65,
24,
68,
31485,
69,
1167,
26293,
28082,
66,
31498,
18,
358,
272,
1015,
360,
16,
14,
2824,
14,
17,
297,
7793,
3912,
534,
23,
2470,
2829,
17,
66,
19,
66,
1822,
66,
2177,
2835,
3833,
23,
67,
30320,
697,
18,
2829,
1216,
70,
1229,
1165,
66,
2006,
68,
30102,
4361,
1651,
825,
1479,
15638,
2894,
2259,
301,
1876,
5303,
358,
339,
8350,
63,
265,
360,
15371,
358,
272,
8350,
63,
265,
360,
19912,
21,
358,
272,
8350,
63,
265,
360,
311,
1158,
358,
339,
327,
394,
1086,
773,
5712,
1133,
6137,
315,
900,
370,
506,
1202,
4496,
272,
9861,
275,
756,
339,
327,
373,
16,
14,
1602,
14,
16,
373,
500,
2908,
282,
1331,
402,
394,
1086,
773,
436,
4440,
2599,
10,
370,
1900,
272,
327,
2399,
7908,
2884,
14,
272,
8350,
63,
265,
360,
2495,
2190,
297,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
272,
8350,
63,
265,
360,
2495,
1875,
297,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
272,
8350,
63,
265,
360,
773,
3557,
297,
221,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
272,
8350,
63,
265,
360,
77,
20,
297,
755,
730,
534,
1506,
297,
1380,
534,
32,
16,
14,
1602,
14,
16,
10993,
339,
327,
1010,
4923,
2475,
5196,
18421,
63,
16075,
63,
18421,
3817,
26,
16026,
29,
615,
7,
315,
314,
19773,
1249,
272,
327,
14486,
5821,
402,
19773,
1159,
1072,
370,
1284,
1536,
315,
314,
2599,
2190,
13,
10176,
272,
327,
7908,
2884,
14,
272,
327,
1666,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
15,
10115,
15,
1046,
9014,
436,
272,
327,
4178,
921,
5031,
14,
957,
15,
387,
335,
351,
5561,
15,
26446,
513,
79,
15,
10115,
15,
3781,
272,
768,
1829,
272,
347,
2418,
63,
16472,
63,
589,
8,
277,
304,
267,
408,
2176,
314,
3379,
2418,
63,
16472,
63,
589,
436,
2066,
2457,
314,
3376,
267,
4260,
14,
267,
408,
267,
282,
275,
1613,
8,
43,
279,
513,
79,
12,
291,
680,
1516,
63,
16472,
63,
589,
267,
340,
334,
277,
14,
1650,
14,
1023,
2356,
3394,
360,
16,
14,
1602,
14,
16,
8109,
288,
1249,
275,
359,
73,
367,
284,
315,
282,
340,
284,
1137,
2475,
5196,
18421,
63,
16075,
63,
18421,
3817,
26,
16026,
29,
615,
418,
267,
587,
26,
288,
1249,
275,
282,
398,
372,
1249,
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,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SUSE/azure-sdk-for-python
|
azure-mgmt-resource/azure/mgmt/resource/resources/v2017_05_10/resource_management_client.py
|
2
|
5058
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.service_client import ServiceClient
from msrest import Serializer, Deserializer
from msrestazure import AzureConfiguration
from .version import VERSION
from .operations.deployments_operations import DeploymentsOperations
from .operations.providers_operations import ProvidersOperations
from .operations.resources_operations import ResourcesOperations
from .operations.resource_groups_operations import ResourceGroupsOperations
from .operations.tags_operations import TagsOperations
from .operations.deployment_operations import DeploymentOperations
from . import models
class ResourceManagementClientConfiguration(AzureConfiguration):
"""Configuration for ResourceManagementClient
Note that all parameters used to create this instance are saved as instance
attributes.
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param subscription_id: The ID of the target subscription.
:type subscription_id: str
:param str base_url: Service URL
"""
def __init__(
self, credentials, subscription_id, base_url=None):
if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if subscription_id is None:
raise ValueError("Parameter 'subscription_id' must not be None.")
if not isinstance(subscription_id, str):
raise TypeError("Parameter 'subscription_id' must be str.")
if not base_url:
base_url = 'https://management.azure.com'
super(ResourceManagementClientConfiguration, self).__init__(base_url)
self.add_user_agent('resourcemanagementclient/{}'.format(VERSION))
self.add_user_agent('Azure-SDK-For-Python')
self.credentials = credentials
self.subscription_id = subscription_id
class ResourceManagementClient(object):
"""Provides operations for working with resources and resource groups.
:ivar config: Configuration for client.
:vartype config: ResourceManagementClientConfiguration
:ivar deployments: Deployments operations
:vartype deployments: azure.mgmt.resource.resources.v2017_05_10.operations.DeploymentsOperations
:ivar providers: Providers operations
:vartype providers: azure.mgmt.resource.resources.v2017_05_10.operations.ProvidersOperations
:ivar resources: Resources operations
:vartype resources: azure.mgmt.resource.resources.v2017_05_10.operations.ResourcesOperations
:ivar resource_groups: ResourceGroups operations
:vartype resource_groups: azure.mgmt.resource.resources.v2017_05_10.operations.ResourceGroupsOperations
:ivar tags: Tags operations
:vartype tags: azure.mgmt.resource.resources.v2017_05_10.operations.TagsOperations
:ivar deployment_operations: DeploymentOperations operations
:vartype deployment_operations: azure.mgmt.resource.resources.v2017_05_10.operations.DeploymentOperations
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param subscription_id: The ID of the target subscription.
:type subscription_id: str
:param str base_url: Service URL
"""
def __init__(
self, credentials, subscription_id, base_url=None):
self.config = ResourceManagementClientConfiguration(credentials, subscription_id, base_url)
self._client = ServiceClient(self.config.credentials, self.config)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self.api_version = '2017-05-10'
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self.deployments = DeploymentsOperations(
self._client, self.config, self._serialize, self._deserialize)
self.providers = ProvidersOperations(
self._client, self.config, self._serialize, self._deserialize)
self.resources = ResourcesOperations(
self._client, self.config, self._serialize, self._deserialize)
self.resource_groups = ResourceGroupsOperations(
self._client, self.config, self._serialize, self._deserialize)
self.tags = TagsOperations(
self._client, self.config, self._serialize, self._deserialize)
self.deployment_operations = DeploymentOperations(
self._client, self.config, self._serialize, self._deserialize)
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
1364,
63,
1258,
492,
7591,
3041,
199,
504,
6605,
3911,
492,
25555,
12,
1487,
8349,
199,
504,
6605,
264,
1207,
7895,
492,
15474,
5688,
199,
504,
1275,
1023,
492,
15945,
199,
504,
1275,
8170,
14,
11060,
1470,
63,
8170,
492,
21588,
3374,
1470,
12929,
199,
504,
1275,
8170,
14,
9710,
63,
8170,
492,
18489,
83,
12929,
199,
504,
1275,
8170,
14,
4435,
63,
8170,
492,
26250,
12929,
199,
504,
1275,
8170,
14,
1927,
63,
2634,
63,
8170,
492,
7337,
10177,
12929,
199,
504,
1275,
8170,
14,
2969,
63,
8170,
492,
25204,
12929,
199,
504,
1275,
8170,
14,
13605,
63,
8170,
492,
21588,
7775,
12929,
199,
504,
1275,
492,
1709,
421,
199,
533,
7337,
14552,
3041,
5688,
8,
22386,
5688,
304,
272,
408,
5688,
367,
7337,
14552,
3041,
272,
3390,
626,
1006,
2633,
1202,
370,
1218,
642,
1256,
787,
6290,
465,
1256,
272,
3004,
14,
339,
520,
635,
6235,
26,
23934,
4346,
367,
314,
1890,
370,
4907,
370,
15474,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
710,
2870,
402,
314,
1347,
9966,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
6235,
12,
9966,
63,
344,
12,
1300,
63,
633,
29,
403,
304,
398,
340,
6235,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6942,
7,
1471,
440,
506,
488,
2685,
267,
340,
9966,
63,
344,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6645,
63,
344,
7,
1471,
440,
506,
488,
2685,
267,
340,
440,
1228,
8,
6645,
63,
344,
12,
620,
304,
288,
746,
3146,
480,
4720,
283,
6645,
63,
344,
7,
1471,
506,
620,
2685,
267,
340,
440,
1300,
63,
633,
26,
288,
1300,
63,
633,
275,
283,
2859,
921,
8110,
14,
9078,
14,
957,
7,
398,
1613,
8,
4031,
14552,
3041,
5688,
12,
291,
2843,
826,
721,
1095,
63,
633,
9,
398,
291,
14,
525,
63,
751,
63,
4054,
360,
1927,
8110,
1258,
30837,
908,
8,
4612,
430,
267,
291,
14,
525,
63,
751,
63,
4054,
360,
22386,
13,
14939,
13,
1858,
13,
4718,
358,
398,
291,
14,
6942,
275,
6235,
267,
291,
14,
6645,
63,
344,
275,
9966,
63,
344,
421,
199,
533,
7337,
14552,
3041,
8,
785,
304,
272,
408,
17473,
5331,
367,
6449,
543,
5944,
436,
2073,
4652,
14,
339,
520,
7725,
1101,
26,
11595,
367,
1890,
14,
272,
520,
19729,
1101,
26,
7337,
14552,
3041,
5688,
339,
520,
7725,
12287,
1470,
26,
21588,
3374,
1470,
5331,
272,
520,
19729,
12287,
1470,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
27597,
1470,
12929,
272,
520,
7725,
18032,
26,
18489,
83,
5331,
272,
520,
19729,
18032,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
6663,
83,
12929,
272,
520,
7725,
5944,
26,
26250,
5331,
272,
520,
19729,
5944,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
13745,
12929,
272,
520,
7725,
2073,
63,
2634,
26,
7337,
10177,
5331,
272,
520,
19729,
2073,
63,
2634,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
4031,
10177,
12929,
272,
520,
7725,
3762,
26,
25204,
5331,
272,
520,
19729,
3762,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
9440,
12929,
272,
520,
7725,
14295,
63,
8170,
26,
21588,
7775,
12929,
5331,
272,
520,
19729,
14295,
63,
8170,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
25434,
12929,
339,
520,
635,
6235,
26,
23934,
4346,
367,
314,
1890,
370,
4907,
370,
15474,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
710,
2870,
402,
314,
1347,
9966,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
6235,
12,
9966,
63,
344,
12,
1300,
63,
633,
29,
403,
304,
398,
291,
14,
888,
275,
7337,
14552,
3041,
5688,
8,
6942,
12,
9966,
63,
344,
12,
1300,
63,
633,
9,
267,
291,
423,
1258,
275,
7591,
3041,
8,
277,
14,
888,
14,
6942,
12,
291,
14,
888,
9,
398,
1890,
63,
992,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
1709,
855,
807,
4343,
1744,
342,
340,
1228,
8,
86,
12,
730,
6769,
267,
291,
14,
1246,
63,
1023,
275,
283,
10680,
13,
1717,
13,
709,
7,
267,
291,
423,
3549,
275,
25555,
8,
1258,
63,
992,
9,
267,
291,
423,
11143,
275,
1487,
8349,
8,
1258,
63,
992,
9,
398,
291,
14,
11060,
1470,
275,
21588,
3374,
1470,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
9,
267,
291,
14,
9710,
275,
18489,
83,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
9,
267,
291,
14,
4435,
275,
26250,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
9,
267,
291,
14,
1927,
63,
2634,
275,
7337,
10177,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888
] |
[
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
1364,
63,
1258,
492,
7591,
3041,
199,
504,
6605,
3911,
492,
25555,
12,
1487,
8349,
199,
504,
6605,
264,
1207,
7895,
492,
15474,
5688,
199,
504,
1275,
1023,
492,
15945,
199,
504,
1275,
8170,
14,
11060,
1470,
63,
8170,
492,
21588,
3374,
1470,
12929,
199,
504,
1275,
8170,
14,
9710,
63,
8170,
492,
18489,
83,
12929,
199,
504,
1275,
8170,
14,
4435,
63,
8170,
492,
26250,
12929,
199,
504,
1275,
8170,
14,
1927,
63,
2634,
63,
8170,
492,
7337,
10177,
12929,
199,
504,
1275,
8170,
14,
2969,
63,
8170,
492,
25204,
12929,
199,
504,
1275,
8170,
14,
13605,
63,
8170,
492,
21588,
7775,
12929,
199,
504,
1275,
492,
1709,
421,
199,
533,
7337,
14552,
3041,
5688,
8,
22386,
5688,
304,
272,
408,
5688,
367,
7337,
14552,
3041,
272,
3390,
626,
1006,
2633,
1202,
370,
1218,
642,
1256,
787,
6290,
465,
1256,
272,
3004,
14,
339,
520,
635,
6235,
26,
23934,
4346,
367,
314,
1890,
370,
4907,
370,
15474,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
710,
2870,
402,
314,
1347,
9966,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
6235,
12,
9966,
63,
344,
12,
1300,
63,
633,
29,
403,
304,
398,
340,
6235,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6942,
7,
1471,
440,
506,
488,
2685,
267,
340,
9966,
63,
344,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6645,
63,
344,
7,
1471,
440,
506,
488,
2685,
267,
340,
440,
1228,
8,
6645,
63,
344,
12,
620,
304,
288,
746,
3146,
480,
4720,
283,
6645,
63,
344,
7,
1471,
506,
620,
2685,
267,
340,
440,
1300,
63,
633,
26,
288,
1300,
63,
633,
275,
283,
2859,
921,
8110,
14,
9078,
14,
957,
7,
398,
1613,
8,
4031,
14552,
3041,
5688,
12,
291,
2843,
826,
721,
1095,
63,
633,
9,
398,
291,
14,
525,
63,
751,
63,
4054,
360,
1927,
8110,
1258,
30837,
908,
8,
4612,
430,
267,
291,
14,
525,
63,
751,
63,
4054,
360,
22386,
13,
14939,
13,
1858,
13,
4718,
358,
398,
291,
14,
6942,
275,
6235,
267,
291,
14,
6645,
63,
344,
275,
9966,
63,
344,
421,
199,
533,
7337,
14552,
3041,
8,
785,
304,
272,
408,
17473,
5331,
367,
6449,
543,
5944,
436,
2073,
4652,
14,
339,
520,
7725,
1101,
26,
11595,
367,
1890,
14,
272,
520,
19729,
1101,
26,
7337,
14552,
3041,
5688,
339,
520,
7725,
12287,
1470,
26,
21588,
3374,
1470,
5331,
272,
520,
19729,
12287,
1470,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
27597,
1470,
12929,
272,
520,
7725,
18032,
26,
18489,
83,
5331,
272,
520,
19729,
18032,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
6663,
83,
12929,
272,
520,
7725,
5944,
26,
26250,
5331,
272,
520,
19729,
5944,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
13745,
12929,
272,
520,
7725,
2073,
63,
2634,
26,
7337,
10177,
5331,
272,
520,
19729,
2073,
63,
2634,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
4031,
10177,
12929,
272,
520,
7725,
3762,
26,
25204,
5331,
272,
520,
19729,
3762,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
9440,
12929,
272,
520,
7725,
14295,
63,
8170,
26,
21588,
7775,
12929,
5331,
272,
520,
19729,
14295,
63,
8170,
26,
13601,
14,
9752,
14,
1927,
14,
4435,
14,
86,
10680,
63,
1717,
63,
709,
14,
8170,
14,
25434,
12929,
339,
520,
635,
6235,
26,
23934,
4346,
367,
314,
1890,
370,
4907,
370,
15474,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
710,
2870,
402,
314,
1347,
9966,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
6235,
12,
9966,
63,
344,
12,
1300,
63,
633,
29,
403,
304,
398,
291,
14,
888,
275,
7337,
14552,
3041,
5688,
8,
6942,
12,
9966,
63,
344,
12,
1300,
63,
633,
9,
267,
291,
423,
1258,
275,
7591,
3041,
8,
277,
14,
888,
14,
6942,
12,
291,
14,
888,
9,
398,
1890,
63,
992,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
1709,
855,
807,
4343,
1744,
342,
340,
1228,
8,
86,
12,
730,
6769,
267,
291,
14,
1246,
63,
1023,
275,
283,
10680,
13,
1717,
13,
709,
7,
267,
291,
423,
3549,
275,
25555,
8,
1258,
63,
992,
9,
267,
291,
423,
11143,
275,
1487,
8349,
8,
1258,
63,
992,
9,
398,
291,
14,
11060,
1470,
275,
21588,
3374,
1470,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
9,
267,
291,
14,
9710,
275,
18489,
83,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
9,
267,
291,
14,
4435,
275,
26250,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
12,
291,
423,
3549,
12,
291,
423,
11143,
9,
267,
291,
14,
1927,
63,
2634,
275,
7337,
10177,
12929,
8,
288,
291,
423,
1258,
12,
291,
14,
888,
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,
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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 print_function
from .layers.control_flow import BlockGuard, equal
from .framework import Operator
from .layer_helper import LayerHelper, unique_name
from .layers import fill_constant
from . import core
__all__ = [
'make_channel', 'channel_send', 'channel_recv', 'channel_close', 'Select'
]
class Go(BlockGuard):
def __init__(self, name=None):
self.helper = LayerHelper("go", name=name)
super(Go, self).__init__(self.helper.main_program)
def __enter__(self):
super(Go, self).__enter__()
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
return False
self._construct_go_op()
return super(Go, self).__exit__(exc_type, exc_val, exc_tb)
def _construct_go_op(self):
main_program = self.helper.main_program
go_block = main_program.current_block()
parent_block = main_program.block(main_program.current_block()
.parent_idx)
inner_outputs = set()
x_name_list = set()
for op in go_block.ops:
# Iterate over all operators, get all the inputs
# and add as input to the Go operator.
for iname in op.input_names:
for in_var_name in op.input(iname):
if in_var_name not in inner_outputs:
x_name_list.add(in_var_name)
for oname in op.output_names:
for out_var_name in op.output(oname):
inner_outputs.add(out_var_name)
# Iterate over all operators , get all the outputs
# add to the output list of Go operator only if
# they exist in the parent block.
out_vars = []
for inner_out_name in inner_outputs:
if inner_out_name in parent_block.vars:
out_vars.append(parent_block.var(inner_out_name))
parent_block.append_op(
type='go',
inputs={
'X': [
parent_block._var_recursive(x_name)
for x_name in x_name_list
]
},
outputs={},
attrs={'sub_block': go_block})
class SelectCase(object):
DEFAULT = 0
SEND = 1
RECEIVE = 2
def __init__(self,
select,
case_idx,
case_to_execute,
channel_action_fn=None,
channel=None,
value=None,
is_copy=False):
self.select = select
self.helper = LayerHelper('conditional_block')
self.main_program = self.helper.main_program
self.is_scalar_condition = True
self.case_to_execute = case_to_execute
self.idx = case_idx
# Since we aren't going to use the `channel_send` or `channel_recv`
# functions directly, we just need to capture the name.
self.action = (self.SEND
if channel_action_fn.__name__ == ('channel_send') else
self.RECEIVE) if channel_action_fn else self.DEFAULT
X = value
if self.action == self.SEND and is_copy:
# We create of copy of the data we want to send
copied_X = self.select.parent_block.create_var(
name=unique_name.generate(value.name + '_copy'),
type=value.type,
dtype=value.dtype,
shape=value.shape,
lod_level=value.lod_level,
capacity=value.capacity
if hasattr(value, 'capacity') else None, )
self.select.parent_block.append_op(
type="assign", inputs={"X": value}, outputs={"Out": copied_X})
X = copied_X
self.value = X
self.channel = channel
def __enter__(self):
self.block = self.main_program.create_block()
def construct_op(self):
main_program = self.helper.main_program
cases_block = main_program.current_block()
inner_outputs = set()
input_set = set()
params = set()
for op in self.block.ops:
# Iterate over all operators, get all the inputs
# and add as input to the SelectCase operator.
for iname in op.input_names:
for in_var_name in op.input(iname):
if in_var_name not in inner_outputs:
input_set.add(in_var_name)
for oname in op.output_names:
for out_var_name in op.output(oname):
inner_outputs.add(out_var_name)
param_list = [
cases_block.var(each_name) for each_name in params
if each_name not in input_set
]
# Iterate over all operators, get all the outputs
# add to the output list of SelectCase operator only if
# they exist in the parent block.
out_vars = []
for inner_out_name in inner_outputs:
if inner_out_name in cases_block.vars:
out_vars.append(cases_block.var(inner_out_name))
# First, create an op that will determine whether or not this is the
# conditional variable to execute.
should_execute_block = equal(
fill_constant(
shape=[1], dtype=core.VarDesc.VarType.INT32, value=self.idx),
self.case_to_execute)
step_scope = cases_block.create_var(
type=core.VarDesc.VarType.STEP_SCOPES)
cases_block.append_op(
type='conditional_block',
inputs={'X': [should_execute_block],
'Params': param_list},
outputs={'Out': out_vars,
'Scope': [step_scope]},
attrs={
'sub_block': self.block,
'is_scalar_condition': self.is_scalar_condition
})
return '%s,%s,%s,%s' % (self.idx, self.action, self.channel.name
if self.channel else '', self.value.name
if self.value else '')
def __exit__(self, exc_type, exc_val, exc_tb):
self.main_program.rollback()
if exc_type is not None:
return False # re-raise exception
return True
class Select(BlockGuard):
def __init__(self, name=None):
self.helper = LayerHelper('select', name=name)
self.parent_block = self.helper.main_program.current_block()
self.cases = []
super(Select, self).__init__(self.helper.main_program)
self.case_to_execute = fill_constant(
shape=[1], dtype=core.VarDesc.VarType.INT32, value=-1)
def __enter__(self):
super(Select, self).__enter__()
return self
def case(self, channel_action_fn, channel, value, is_copy=False):
"""Create a new block for this condition.
"""
select_case = SelectCase(self,
len(self.cases), self.case_to_execute,
channel_action_fn, channel, value, is_copy)
self.cases.append(select_case)
return select_case
def default(self):
"""Create a default case block for this condition.
"""
default_case = SelectCase(self, len(self.cases), self.case_to_execute)
self.cases.append(default_case)
return default_case
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
return False
# Create a select op and another block to wrap its
# case blocks.
select_block = self.helper.main_program.current_block()
parent_block = self.helper.main_program.block(select_block.parent_idx)
# Construct each case op, inside the newly created select block.
serialized_cases = []
for case in self.cases:
serialized_cases.append(case.construct_op())
intermediate = set()
params = set()
for case_block in select_block.ops:
if case_block.attrs and 'sub_block' in case_block.attrs:
for each_op in case_block.attrs['sub_block'].ops:
assert isinstance(each_op, Operator)
for iname in each_op.input_names:
for in_var_name in each_op.input(iname):
if in_var_name not in intermediate:
params.add(in_var_name)
for oname in each_op.output_names:
for out_var_name in each_op.output(oname):
intermediate.add(out_var_name)
out_list = [
parent_block.var(var_name) for var_name in parent_block.vars
if var_name in intermediate
]
X = [select_block._var_recursive(x_name) for x_name in params]
# Needs to be used by `equal` inside the cases block.
X.append(self.case_to_execute)
# Construct the select op.
parent_block.append_op(
type='select',
inputs={'X': X,
'case_to_execute': self.case_to_execute},
attrs={'sub_block': select_block,
'cases': serialized_cases},
outputs={'Out': out_list})
return super(Select, self).__exit__(exc_type, exc_val, exc_tb)
def make_channel(dtype, capacity=0):
"""
Helps implementation of a concurrent program by creating a "channel" of
a defined data type. Channels allow for the passing of data in
concurrent scenarios - such as when using threads to divide computation.
Channels can be used to "send" and "receive" such data concurrently.
There are two kinds of channels: unbuffered and buffered. Unbuffered
channels have no capacity - and thus, block on send and only unblock only
once what they have sent has been received.
On the other hand, buffered channels are initialized with a capacity -
and do not block on sends.
Use this method in combination with `channel_send`, `channel_recv`,
`channel_close`, and `Go` to design a concurrent Paddle program.
Args:
dtype (ParamAttr|string): Data type of the data sent in the channel.
This data type should be the string name of a numpy data type.
capacity (ParamAttr|int): Size of the channel. Defaults to 0 for
to create an unbuffered channel.
Returns:
Variable: The channel variable that can be used to send an receive data
of the defined dtype.
Examples:
.. code-block:: python
ch = fluid.make_channel(dtype='int32', capacity=10)
...
# Code to execute in a Go block, which receives the channel data.
fluid.channel_send(ch, 100)
fluid.channel_close(ch)
"""
helper = LayerHelper('channel_create', **locals())
main_program = helper.main_program
make_channel_block = main_program.current_block()
# Make a channel variable (using the channel data type) and make sure it
# persists into the global scope.
channel = helper.create_variable(
name=unique_name.generate('channel'),
type=core.VarDesc.VarType.CHANNEL,
persistable=True)
create_channel_op = make_channel_block.append_op(
type="channel_create",
outputs={"Out": channel},
attrs={"data_type": dtype,
"capacity": capacity})
return channel
def channel_send(channel, value, is_copy=False):
"""
Sends a value through a channel variable. Used by an unbuffered or buffered
channel to pass data from within or to a concurrent Go block, where
`channel_recv` to used to get the passed value.
Args:
channel (Variable|Channel): Channel variable created using
`make_channel`.
value (Variable): Value to send to channel
is_copy (bool): Copy data while channel send. If False, then data
is moved. The input cannot be used after move. (default False)
Returns:
Variable: The boolean status on whether or not the channel
successfully sent the passed value.
Examples:
.. code-block:: python
ch = fluid.make_channel(dtype='int32', capacity=10)
...
# Code to execute in a Go block, which receives the channel data.
fluid.channel_send(ch, 100)
"""
helper = LayerHelper('channel_send', **locals())
main_program = helper.main_program
channel_send_block = main_program.current_block()
X = value
if is_copy:
copied_X = helper.create_variable(
name=unique_name.generate(value.name + '_copy'),
type=value.type,
dtype=value.dtype,
shape=value.shape,
lod_level=value.lod_level,
capacity=value.capacity if hasattr(value, 'capacity') else None)
assign_op = channel_send_block.append_op(
type="assign", inputs={"X": value}, outputs={"Out": copied_X})
X = copied_X
channel_send_block.append_op(
type="channel_send", inputs={
"Channel": channel,
"X": X,
})
def channel_recv(channel, return_value):
"""
Receives a value through a channel variable. Used by an unbuffered or
buffered channel within a concurrent Go block to get data from originally
sent using `channel_send`, or from outside such a block where
`channel_send` is used to send the value.
Args:
channel (Variable|Channel): Channel variable created using
`make_channel`.
return_value (Variable): Variable to set as a result of running channel_recv_op
Returns:
Variable: The received value from the channel.
Variable: The boolean status on whether or not the channel
successfully received the passed value.
Examples:
.. code-block:: python
ch = fluid.make_channel(dtype='int32', capacity=10)
with fluid.Go():
returned_value, return_status = fluid.channel_recv(ch, 'int32')
# Code to send data through the channel.
"""
helper = LayerHelper('channel_recv', **locals())
main_program = helper.main_program
channel_recv_block = main_program.current_block()
status = helper.create_variable(
name=unique_name.generate('status'),
type=core.VarDesc.VarType.LOD_TENSOR,
dtype=core.VarDesc.VarType.BOOL)
channel_recv_op = channel_recv_block.append_op(
type="channel_recv",
inputs={"Channel": channel},
outputs={"Out": return_value,
"Status": status})
return return_value, status
def channel_close(channel):
"""
Closes a channel created using `make_channel`.
Args:
channel (Variable|Channel): Channel variable created using
`make_channel`.
Examples:
.. code-block:: python
ch = fluid.make_channel(dtype='int32', capacity=10)
...
# Code to receive and send data through a channel
...
fluid.channel_close(ch)
"""
helper = LayerHelper('channel_close', **locals())
main_program = helper.main_program
channel_close_block = main_program.current_block()
channel_close_op = channel_close_block.append_op(
type="channel_close", inputs={"Channel": channel})
|
apache-2.0
|
[
3,
257,
1898,
334,
67,
9,
14894,
510,
20101,
48,
20101,
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,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
1275,
4359,
14,
2785,
63,
1659,
492,
8651,
18183,
12,
4472,
199,
504,
1275,
4857,
492,
11013,
199,
504,
1275,
1897,
63,
3676,
492,
11915,
4433,
12,
3747,
63,
354,
199,
504,
1275,
4359,
492,
5554,
63,
4083,
199,
504,
1275,
492,
6170,
199,
199,
363,
452,
363,
275,
359,
272,
283,
1875,
63,
2775,
297,
283,
2775,
63,
2254,
297,
283,
2775,
63,
7637,
297,
283,
2775,
63,
1600,
297,
283,
5446,
7,
199,
61,
421,
199,
533,
3971,
8,
3142,
18183,
304,
272,
347,
636,
826,
721,
277,
12,
536,
29,
403,
304,
267,
291,
14,
3676,
275,
11915,
4433,
480,
1939,
401,
536,
29,
354,
9,
267,
1613,
8,
7250,
12,
291,
2843,
826,
721,
277,
14,
3676,
14,
973,
63,
6815,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
1613,
8,
7250,
12,
291,
2843,
4200,
4533,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
340,
3178,
63,
466,
365,
440,
488,
26,
288,
372,
756,
267,
291,
423,
8514,
63,
1939,
63,
411,
342,
267,
372,
1613,
8,
7250,
12,
291,
2843,
2224,
721,
2804,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
9,
339,
347,
485,
8514,
63,
1939,
63,
411,
8,
277,
304,
267,
2446,
63,
6815,
275,
291,
14,
3676,
14,
973,
63,
6815,
267,
2621,
63,
1457,
275,
2446,
63,
6815,
14,
1818,
63,
1457,
342,
267,
1676,
63,
1457,
275,
2446,
63,
6815,
14,
1457,
8,
973,
63,
6815,
14,
1818,
63,
1457,
342,
5101,
1275,
1708,
63,
2996,
9,
398,
6506,
63,
4467,
275,
663,
342,
267,
671,
63,
354,
63,
513,
275,
663,
342,
267,
367,
1687,
315,
2621,
63,
1457,
14,
1483,
26,
288,
327,
23989,
1806,
1006,
10211,
12,
664,
1006,
314,
4153,
288,
327,
436,
1050,
465,
1324,
370,
314,
3971,
4182,
14,
288,
367,
315,
313,
315,
1687,
14,
1210,
63,
1247,
26,
355,
367,
315,
63,
1391,
63,
354,
315,
1687,
14,
1210,
8,
32228,
304,
490,
340,
315,
63,
1391,
63,
354,
440,
315,
6506,
63,
4467,
26,
717,
671,
63,
354,
63,
513,
14,
525,
8,
262,
63,
1391,
63,
354,
9,
953,
367,
641,
313,
315,
1687,
14,
1199,
63,
1247,
26,
355,
367,
734,
63,
1391,
63,
354,
315,
1687,
14,
1199,
8,
32203,
304,
490,
6506,
63,
4467,
14,
525,
8,
548,
63,
1391,
63,
354,
9,
398,
327,
23989,
1806,
1006,
10211,
2360,
664,
1006,
314,
4704,
267,
327,
1050,
370,
314,
1072,
769,
402,
3971,
4182,
1454,
340,
267,
327,
2985,
2187,
315,
314,
1676,
1853,
14,
267,
734,
63,
2936,
275,
942,
267,
367,
6506,
63,
548,
63,
354,
315,
6506,
63,
4467,
26,
288,
340,
6506,
63,
548,
63,
354,
315,
1676,
63,
1457,
14,
2936,
26,
355,
734,
63,
2936,
14,
740,
8,
1708,
63,
1457,
14,
1391,
8,
5216,
63,
548,
63,
354,
430,
398,
1676,
63,
1457,
14,
740,
63,
411,
8,
288,
730,
534,
1939,
297,
288,
4153,
3126,
355,
283,
56,
356,
359,
490,
1676,
63,
1457,
423,
1391,
63,
9931,
8,
88,
63,
354,
9,
490,
367,
671,
63,
354,
315,
671,
63,
354,
63,
513,
355,
1622,
288,
1660,
288,
4704,
10324,
288,
3290,
3713,
954,
63,
1457,
356,
2621,
63,
1457,
1552,
421,
199,
533,
9496,
1538,
8,
785,
304,
272,
6186,
275,
378,
272,
428,
3902,
275,
413,
272,
5363,
2089,
5399,
275,
499,
339,
347,
636,
826,
721,
277,
12,
326,
3504,
12,
326,
1930,
63,
2996,
12,
326,
1930,
63,
475,
63,
2526,
12,
326,
3623,
63,
1287,
63,
2324,
29,
403,
12,
326,
3623,
29,
403,
12,
326,
574,
29,
403,
12,
326,
365,
63,
1574,
29,
797,
304,
267,
291,
14,
2416,
275,
3504,
267,
291,
14,
3676,
275,
11915,
4433,
360,
14353,
63,
1457,
358,
267,
291,
14,
973,
63,
6815,
275,
291,
14,
3676,
14,
973,
63,
6815,
267,
291,
14,
374,
63,
7033,
63,
5394,
275,
715,
398,
291,
14,
2546,
63,
475,
63,
2526,
275,
1930,
63,
475,
63,
2526,
267,
291,
14,
2996,
275,
1930,
63,
2996,
398,
327,
9336,
781,
10621,
1133,
9995,
370,
675,
314,
658,
2775,
63,
2254,
64,
503,
658,
2775,
63,
7637,
64,
267,
327,
3423,
5370,
12,
781,
2951,
1929,
370,
12296,
314,
536,
14,
267,
291,
14,
1287,
275,
334,
277,
14,
20469,
2432,
340,
3623,
63,
1287,
63,
2324,
855,
354,
363,
508,
661,
2775,
63,
2254,
358,
587,
2432,
291,
14,
28467,
5399,
9,
340,
3623,
63,
1287,
63,
2324,
587,
291,
14,
3472,
398,
1323,
275,
574,
267,
340,
291,
14,
1287,
508,
291,
14,
20469,
436,
365,
63,
1574,
26,
288,
327,
2136,
1218,
402,
1331,
402,
314,
666,
781,
2934,
370,
3222,
288,
8876,
63,
56,
275,
291,
14,
2416,
14,
1708,
63,
1457,
14,
981,
63,
1391,
8,
355,
536,
29,
3235,
63,
354,
14,
4208,
8,
585,
14,
354,
435,
2513,
1574,
659,
355,
730,
29,
585,
14,
466,
12,
355,
2152,
29,
585,
14,
2271,
12,
355,
2215,
29,
585,
14,
1392,
12,
355,
560,
68,
63,
1896,
29,
585,
14,
320,
68,
63,
1896,
12,
355,
14893,
29
] |
[
257,
1898,
334,
67,
9,
14894,
510,
20101,
48,
20101,
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,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
1275,
4359,
14,
2785,
63,
1659,
492,
8651,
18183,
12,
4472,
199,
504,
1275,
4857,
492,
11013,
199,
504,
1275,
1897,
63,
3676,
492,
11915,
4433,
12,
3747,
63,
354,
199,
504,
1275,
4359,
492,
5554,
63,
4083,
199,
504,
1275,
492,
6170,
199,
199,
363,
452,
363,
275,
359,
272,
283,
1875,
63,
2775,
297,
283,
2775,
63,
2254,
297,
283,
2775,
63,
7637,
297,
283,
2775,
63,
1600,
297,
283,
5446,
7,
199,
61,
421,
199,
533,
3971,
8,
3142,
18183,
304,
272,
347,
636,
826,
721,
277,
12,
536,
29,
403,
304,
267,
291,
14,
3676,
275,
11915,
4433,
480,
1939,
401,
536,
29,
354,
9,
267,
1613,
8,
7250,
12,
291,
2843,
826,
721,
277,
14,
3676,
14,
973,
63,
6815,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
1613,
8,
7250,
12,
291,
2843,
4200,
4533,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
340,
3178,
63,
466,
365,
440,
488,
26,
288,
372,
756,
267,
291,
423,
8514,
63,
1939,
63,
411,
342,
267,
372,
1613,
8,
7250,
12,
291,
2843,
2224,
721,
2804,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
9,
339,
347,
485,
8514,
63,
1939,
63,
411,
8,
277,
304,
267,
2446,
63,
6815,
275,
291,
14,
3676,
14,
973,
63,
6815,
267,
2621,
63,
1457,
275,
2446,
63,
6815,
14,
1818,
63,
1457,
342,
267,
1676,
63,
1457,
275,
2446,
63,
6815,
14,
1457,
8,
973,
63,
6815,
14,
1818,
63,
1457,
342,
5101,
1275,
1708,
63,
2996,
9,
398,
6506,
63,
4467,
275,
663,
342,
267,
671,
63,
354,
63,
513,
275,
663,
342,
267,
367,
1687,
315,
2621,
63,
1457,
14,
1483,
26,
288,
327,
23989,
1806,
1006,
10211,
12,
664,
1006,
314,
4153,
288,
327,
436,
1050,
465,
1324,
370,
314,
3971,
4182,
14,
288,
367,
315,
313,
315,
1687,
14,
1210,
63,
1247,
26,
355,
367,
315,
63,
1391,
63,
354,
315,
1687,
14,
1210,
8,
32228,
304,
490,
340,
315,
63,
1391,
63,
354,
440,
315,
6506,
63,
4467,
26,
717,
671,
63,
354,
63,
513,
14,
525,
8,
262,
63,
1391,
63,
354,
9,
953,
367,
641,
313,
315,
1687,
14,
1199,
63,
1247,
26,
355,
367,
734,
63,
1391,
63,
354,
315,
1687,
14,
1199,
8,
32203,
304,
490,
6506,
63,
4467,
14,
525,
8,
548,
63,
1391,
63,
354,
9,
398,
327,
23989,
1806,
1006,
10211,
2360,
664,
1006,
314,
4704,
267,
327,
1050,
370,
314,
1072,
769,
402,
3971,
4182,
1454,
340,
267,
327,
2985,
2187,
315,
314,
1676,
1853,
14,
267,
734,
63,
2936,
275,
942,
267,
367,
6506,
63,
548,
63,
354,
315,
6506,
63,
4467,
26,
288,
340,
6506,
63,
548,
63,
354,
315,
1676,
63,
1457,
14,
2936,
26,
355,
734,
63,
2936,
14,
740,
8,
1708,
63,
1457,
14,
1391,
8,
5216,
63,
548,
63,
354,
430,
398,
1676,
63,
1457,
14,
740,
63,
411,
8,
288,
730,
534,
1939,
297,
288,
4153,
3126,
355,
283,
56,
356,
359,
490,
1676,
63,
1457,
423,
1391,
63,
9931,
8,
88,
63,
354,
9,
490,
367,
671,
63,
354,
315,
671,
63,
354,
63,
513,
355,
1622,
288,
1660,
288,
4704,
10324,
288,
3290,
3713,
954,
63,
1457,
356,
2621,
63,
1457,
1552,
421,
199,
533,
9496,
1538,
8,
785,
304,
272,
6186,
275,
378,
272,
428,
3902,
275,
413,
272,
5363,
2089,
5399,
275,
499,
339,
347,
636,
826,
721,
277,
12,
326,
3504,
12,
326,
1930,
63,
2996,
12,
326,
1930,
63,
475,
63,
2526,
12,
326,
3623,
63,
1287,
63,
2324,
29,
403,
12,
326,
3623,
29,
403,
12,
326,
574,
29,
403,
12,
326,
365,
63,
1574,
29,
797,
304,
267,
291,
14,
2416,
275,
3504,
267,
291,
14,
3676,
275,
11915,
4433,
360,
14353,
63,
1457,
358,
267,
291,
14,
973,
63,
6815,
275,
291,
14,
3676,
14,
973,
63,
6815,
267,
291,
14,
374,
63,
7033,
63,
5394,
275,
715,
398,
291,
14,
2546,
63,
475,
63,
2526,
275,
1930,
63,
475,
63,
2526,
267,
291,
14,
2996,
275,
1930,
63,
2996,
398,
327,
9336,
781,
10621,
1133,
9995,
370,
675,
314,
658,
2775,
63,
2254,
64,
503,
658,
2775,
63,
7637,
64,
267,
327,
3423,
5370,
12,
781,
2951,
1929,
370,
12296,
314,
536,
14,
267,
291,
14,
1287,
275,
334,
277,
14,
20469,
2432,
340,
3623,
63,
1287,
63,
2324,
855,
354,
363,
508,
661,
2775,
63,
2254,
358,
587,
2432,
291,
14,
28467,
5399,
9,
340,
3623,
63,
1287,
63,
2324,
587,
291,
14,
3472,
398,
1323,
275,
574,
267,
340,
291,
14,
1287,
508,
291,
14,
20469,
436,
365,
63,
1574,
26,
288,
327,
2136,
1218,
402,
1331,
402,
314,
666,
781,
2934,
370,
3222,
288,
8876,
63,
56,
275,
291,
14,
2416,
14,
1708,
63,
1457,
14,
981,
63,
1391,
8,
355,
536,
29,
3235,
63,
354,
14,
4208,
8,
585,
14,
354,
435,
2513,
1574,
659,
355,
730,
29,
585,
14,
466,
12,
355,
2152,
29,
585,
14,
2271,
12,
355,
2215,
29,
585,
14,
1392,
12,
355,
560,
68,
63,
1896,
29,
585,
14,
320,
68,
63,
1896,
12,
355,
14893,
29,
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,
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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
] |
RichardWilliamPearse/namebench
|
tools/split_instance_in_csv.py
|
174
|
1077
|
#!/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.
"""Split instance from provider"""
__author__ = 'tstromberg@google.com (Thomas Stromberg)'
import csv
import re
reader = csv.reader(open('../config/servers.csv'))
writer = csv.writer(open('output.csv', 'w'))
for row in reader:
name = row[2]
matches = re.match('(.*?) \((.*)\)', name)
if matches:
name = matches.group(1)
instance = matches.group(2)
else:
instance = ''
row[2] = name
row.insert(3, instance)
writer.writerow(row)
|
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,
8862,
1256,
687,
5022,
624,
199,
199,
363,
2502,
363,
275,
283,
84,
31672,
14630,
32,
3098,
14,
957,
334,
52,
526,
5892,
1933,
417,
14630,
3171,
199,
199,
646,
7392,
199,
646,
295,
199,
5503,
275,
7392,
14,
5503,
8,
1490,
24592,
888,
15,
5871,
14,
4737,
1333,
199,
5491,
275,
7392,
14,
5491,
8,
1490,
360,
1199,
14,
4737,
297,
283,
87,
1333,
199,
509,
1962,
315,
7002,
26,
523,
536,
275,
1962,
59,
18,
61,
523,
4450,
275,
295,
14,
1431,
14097,
6697,
9,
971,
1332,
2795,
2862,
3196,
536,
9,
523,
340,
4450,
26,
272,
536,
275,
4450,
14,
923,
8,
17,
9,
272,
1256,
275,
4450,
14,
923,
8,
18,
9,
523,
587,
26,
272,
1256,
275,
2125,
819,
1962,
59,
18,
61,
275,
536,
523,
1962,
14,
3176,
8,
19,
12,
1256,
9,
523,
7060,
14,
22686,
8,
1143,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
8862,
1256,
687,
5022,
624,
199,
199,
363,
2502,
363,
275,
283,
84,
31672,
14630,
32,
3098,
14,
957,
334,
52,
526,
5892,
1933,
417,
14630,
3171,
199,
199,
646,
7392,
199,
646,
295,
199,
5503,
275,
7392,
14,
5503,
8,
1490,
24592,
888,
15,
5871,
14,
4737,
1333,
199,
5491,
275,
7392,
14,
5491,
8,
1490,
360,
1199,
14,
4737,
297,
283,
87,
1333,
199,
509,
1962,
315,
7002,
26,
523,
536,
275,
1962,
59,
18,
61,
523,
4450,
275,
295,
14,
1431,
14097,
6697,
9,
971,
1332,
2795,
2862,
3196,
536,
9,
523,
340,
4450,
26,
272,
536,
275,
4450,
14,
923,
8,
17,
9,
272,
1256,
275,
4450,
14,
923,
8,
18,
9,
523,
587,
26,
272,
1256,
275,
2125,
819,
1962,
59,
18,
61,
275,
536,
523,
1962,
14,
3176,
8,
19,
12,
1256,
9,
523,
7060,
14,
22686,
8,
1143,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
indictranstech/trufil-erpnext
|
erpnext/patches/v4_0/update_account_root_type.py
|
90
|
1480
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "account")
account_table_columns = frappe.db.get_table_columns("Account")
if "debit_or_credit" in account_table_columns and "is_pl_account" in account_table_columns:
frappe.db.sql("""UPDATE tabAccount
SET root_type = CASE
WHEN (debit_or_credit='Debit' and is_pl_account = 'No') THEN 'Asset'
WHEN (debit_or_credit='Credit' and is_pl_account = 'No') THEN 'Liability'
WHEN (debit_or_credit='Debit' and is_pl_account = 'Yes') THEN 'Expense'
WHEN (debit_or_credit='Credit' and is_pl_account = 'Yes') THEN 'Income'
END
WHERE ifnull(parent_account, '') = ''
""")
else:
for key, root_type in (("asset", "Asset"), ("liabilities", "Liability"), ("expense", "Expense"),
("income", "Income")):
frappe.db.sql("""update tabAccount set root_type=%s where name like %s
and ifnull(parent_account, '')=''""", (root_type, "%" + key + "%"))
for root in frappe.db.sql("""SELECT name, lft, rgt, root_type FROM `tabAccount`
WHERE ifnull(parent_account, '')=''""", as_dict=True):
if root.root_type:
frappe.db.sql("""UPDATE tabAccount SET root_type=%s WHERE lft>%s and rgt<%s""",
(root.root_type, root.lft, root.rgt))
else:
print b"Root type not found for {0}".format(root.name.encode("utf-8"))
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
199,
318,
5341,
837,
199,
198,
9098,
14,
9233,
63,
1301,
480,
8370,
401,
298,
6356,
401,
298,
2048,
531,
421,
198,
2048,
63,
1224,
63,
3406,
275,
6950,
14,
697,
14,
362,
63,
1224,
63,
3406,
480,
6009,
531,
199,
198,
692,
298,
12964,
63,
269,
63,
9365,
2,
315,
2933,
63,
1224,
63,
3406,
436,
298,
374,
63,
1168,
63,
2048,
2,
315,
2933,
63,
1224,
63,
3406,
26,
507,
198,
9098,
14,
697,
14,
3009,
4852,
10383,
5174,
6009,
686,
198,
3597,
1738,
63,
466,
275,
7240,
899,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
872,
2075,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
1944,
358,
27299,
283,
19979,
7,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
27228,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
1944,
358,
27299,
283,
13009,
3616,
7,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
872,
2075,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
12555,
358,
27299,
283,
4527,
677,
7,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
27228,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
12555,
358,
27299,
283,
607,
4352,
7,
1585,
198,
3902,
686,
198,
17688,
340,
2307,
8,
1708,
63,
2048,
12,
4074,
275,
2125,
507,
198,
6141,
421,
198,
2836,
26,
507,
198,
509,
790,
12,
1738,
63,
466,
315,
19110,
6562,
401,
298,
19979,
1288,
1689,
317,
5807,
401,
298,
13009,
3616,
1288,
1689,
16886,
401,
298,
4527,
677,
1288,
686,
198,
480,
23607,
401,
298,
607,
4352,
14150,
686,
198,
9098,
14,
697,
14,
3009,
4852,
873,
5174,
6009,
663,
1738,
63,
466,
2458,
83,
2382,
536,
2839,
450,
83,
1585,
198,
460,
340,
2307,
8,
1708,
63,
2048,
12,
4074,
19070,
7208,
334,
1231,
63,
466,
12,
2071,
2,
435,
790,
435,
2071,
2237,
421,
198,
509,
1738,
315,
6950,
14,
697,
14,
3009,
4852,
4859,
536,
12,
14642,
84,
12,
519,
3308,
12,
1738,
63,
466,
4442,
658,
2902,
6009,
64,
507,
198,
17688,
340,
2307,
8,
1708,
63,
2048,
12,
4074,
19070,
7208,
198,
305,
63,
807,
29,
549,
304,
686,
198,
692,
1738,
14,
1231,
63,
466,
26,
1585,
198,
9098,
14,
697,
14,
3009,
4852,
10383,
5174,
6009,
11543,
1738,
63,
466,
2458,
83,
6038,
14642,
84,
6598,
83,
436,
519,
3308,
21110,
83,
7208,
1871,
198,
8,
1231,
14,
1231,
63,
466,
12,
1738,
14,
32462,
12,
1738,
14,
82,
3308,
430,
686,
198,
2836,
26,
1585,
198,
1361,
330,
2,
6405,
730,
440,
1911,
367,
469,
16,
5469,
908,
8,
1231,
14,
354,
14,
2143,
480,
1624,
13,
24,
2237,
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
] |
[
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
199,
318,
5341,
837,
199,
198,
9098,
14,
9233,
63,
1301,
480,
8370,
401,
298,
6356,
401,
298,
2048,
531,
421,
198,
2048,
63,
1224,
63,
3406,
275,
6950,
14,
697,
14,
362,
63,
1224,
63,
3406,
480,
6009,
531,
199,
198,
692,
298,
12964,
63,
269,
63,
9365,
2,
315,
2933,
63,
1224,
63,
3406,
436,
298,
374,
63,
1168,
63,
2048,
2,
315,
2933,
63,
1224,
63,
3406,
26,
507,
198,
9098,
14,
697,
14,
3009,
4852,
10383,
5174,
6009,
686,
198,
3597,
1738,
63,
466,
275,
7240,
899,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
872,
2075,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
1944,
358,
27299,
283,
19979,
7,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
27228,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
1944,
358,
27299,
283,
13009,
3616,
7,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
872,
2075,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
12555,
358,
27299,
283,
4527,
677,
7,
1585,
198,
9792,
742,
334,
12964,
63,
269,
63,
9365,
534,
27228,
7,
436,
365,
63,
1168,
63,
2048,
275,
283,
12555,
358,
27299,
283,
607,
4352,
7,
1585,
198,
3902,
686,
198,
17688,
340,
2307,
8,
1708,
63,
2048,
12,
4074,
275,
2125,
507,
198,
6141,
421,
198,
2836,
26,
507,
198,
509,
790,
12,
1738,
63,
466,
315,
19110,
6562,
401,
298,
19979,
1288,
1689,
317,
5807,
401,
298,
13009,
3616,
1288,
1689,
16886,
401,
298,
4527,
677,
1288,
686,
198,
480,
23607,
401,
298,
607,
4352,
14150,
686,
198,
9098,
14,
697,
14,
3009,
4852,
873,
5174,
6009,
663,
1738,
63,
466,
2458,
83,
2382,
536,
2839,
450,
83,
1585,
198,
460,
340,
2307,
8,
1708,
63,
2048,
12,
4074,
19070,
7208,
334,
1231,
63,
466,
12,
2071,
2,
435,
790,
435,
2071,
2237,
421,
198,
509,
1738,
315,
6950,
14,
697,
14,
3009,
4852,
4859,
536,
12,
14642,
84,
12,
519,
3308,
12,
1738,
63,
466,
4442,
658,
2902,
6009,
64,
507,
198,
17688,
340,
2307,
8,
1708,
63,
2048,
12,
4074,
19070,
7208,
198,
305,
63,
807,
29,
549,
304,
686,
198,
692,
1738,
14,
1231,
63,
466,
26,
1585,
198,
9098,
14,
697,
14,
3009,
4852,
10383,
5174,
6009,
11543,
1738,
63,
466,
2458,
83,
6038,
14642,
84,
6598,
83,
436,
519,
3308,
21110,
83,
7208,
1871,
198,
8,
1231,
14,
1231,
63,
466,
12,
1738,
14,
32462,
12,
1738,
14,
82,
3308,
430,
686,
198,
2836,
26,
1585,
198,
1361,
330,
2,
6405,
730,
440,
1911,
367,
469,
16,
5469,
908,
8,
1231,
14,
354,
14,
2143,
480,
1624,
13,
24,
2237,
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,
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,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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
] |
tbeadle/django
|
django/utils/html.py
|
56
|
14422
|
"""HTML utilities suitable for global use."""
from __future__ import unicode_literals
import re
from django.utils import six
from django.utils.encoding import force_str, force_text
from django.utils.functional import keep_lazy, keep_lazy_text
from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS
from django.utils.safestring import SafeData, SafeText, mark_safe
from django.utils.six.moves.urllib.parse import (
parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit,
)
from django.utils.text import normalize_newlines
from .html_parser import HTMLParseError, HTMLParser
# Configuration for urlize() function.
TRAILING_PUNCTUATION_RE = re.compile(
'^' # Beginning of word
'(.*?)' # The URL in word
'([.,:;!]+)' # Allowed non-wrapping, trailing punctuation
'$' # End of word
)
WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('<', '>'), ('"', '"'), ('\'', '\'')]
# List of possible strings used for bullets in bulleted lists.
DOTS = ['·', '*', '\u2022', '•', '•', '•']
unencoded_ampersands_re = re.compile(r'&(?!(\w+|#\d+);)')
word_split_re = re.compile(r'''([\s<>"']+)''')
simple_url_re = re.compile(r'^https?://\[?\w', re.IGNORECASE)
simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)($|/.*)$', re.IGNORECASE)
simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
link_target_attribute_re = re.compile(r'(<a [^>]*?)target=[^\s>]+')
html_gunk_re = re.compile(
r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|'
'<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
hard_coded_bullets_re = re.compile(
r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join(re.escape(x) for x in DOTS), re.DOTALL
)
trailing_empty_content_re = re.compile(r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z')
@keep_lazy(six.text_type, SafeText)
def escape(text):
"""
Returns the given text with ampersands, quotes and angle brackets encoded
for use in HTML.
This function always escapes its input, even if it's already escaped and
marked as such. This may result in double-escaping. If this is a concern,
use conditional_escape() instead.
"""
return mark_safe(
force_text(text).replace('&', '&').replace('<', '<')
.replace('>', '>').replace('"', '"').replace("'", ''')
)
_js_escapes = {
ord('\\'): '\\u005C',
ord('\''): '\\u0027',
ord('"'): '\\u0022',
ord('>'): '\\u003E',
ord('<'): '\\u003C',
ord('&'): '\\u0026',
ord('='): '\\u003D',
ord('-'): '\\u002D',
ord(';'): '\\u003B',
ord('\u2028'): '\\u2028',
ord('\u2029'): '\\u2029'
}
# Escape every ASCII character with a value less than 32.
_js_escapes.update((ord('%c' % z), '\\u%04X' % z) for z in range(32))
@keep_lazy(six.text_type, SafeText)
def escapejs(value):
"""Hex encodes characters for use in JavaScript strings."""
return mark_safe(force_text(value).translate(_js_escapes))
def conditional_escape(text):
"""
Similar to escape(), except that it doesn't operate on pre-escaped strings.
This function relies on the __html__ convention used both by Django's
SafeData class and by third-party libraries like markupsafe.
"""
if hasattr(text, '__html__'):
return text.__html__()
else:
return escape(text)
def format_html(format_string, *args, **kwargs):
"""
Similar to str.format, but passes all arguments through conditional_escape,
and calls 'mark_safe' on the result. This function should be used instead
of str.format or % interpolation to build up small HTML fragments.
"""
args_safe = map(conditional_escape, args)
kwargs_safe = {k: conditional_escape(v) for (k, v) in six.iteritems(kwargs)}
return mark_safe(format_string.format(*args_safe, **kwargs_safe))
def format_html_join(sep, format_string, args_generator):
"""
A wrapper of format_html, for the common case of a group of arguments that
need to be formatted using the same format string, and then joined using
'sep'. 'sep' is also passed through conditional_escape.
'args_generator' should be an iterator that returns the sequence of 'args'
that will be passed to format_html.
Example:
format_html_join('\n', "<li>{} {}</li>", ((u.first_name, u.last_name)
for u in users))
"""
return mark_safe(conditional_escape(sep).join(
format_html(format_string, *tuple(args))
for args in args_generator))
@keep_lazy_text
def linebreaks(value, autoescape=False):
"""Converts newlines into <p> and <br />s."""
value = normalize_newlines(force_text(value))
paras = re.split('\n{2,}', value)
if autoescape:
paras = ['<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras]
else:
paras = ['<p>%s</p>' % p.replace('\n', '<br />') for p in paras]
return '\n\n'.join(paras)
class MLStripper(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def handle_entityref(self, name):
self.fed.append('&%s;' % name)
def handle_charref(self, name):
self.fed.append('&#%s;' % name)
def get_data(self):
return ''.join(self.fed)
def _strip_once(value):
"""
Internal tag stripping utility used by strip_tags.
"""
s = MLStripper()
try:
s.feed(value)
except HTMLParseError:
return value
try:
s.close()
except HTMLParseError:
return s.get_data() + s.rawdata
else:
return s.get_data()
@keep_lazy_text
def strip_tags(value):
"""Returns the given HTML with all tags stripped."""
# Note: in typical case this loop executes _strip_once once. Loop condition
# is redundant, but helps to reduce number of executions of _strip_once.
value = force_text(value)
while '<' in value and '>' in value:
new_value = _strip_once(value)
if len(new_value) >= len(value):
# _strip_once was not able to detect more tags or length increased
# due to http://bugs.python.org/issue20288
# (affects Python 2 < 2.7.7 and Python 3 < 3.3.5)
break
value = new_value
return value
@keep_lazy_text
def strip_spaces_between_tags(value):
"""Returns the given HTML with spaces between tags removed."""
return re.sub(r'>\s+<', '><', force_text(value))
def smart_urlquote(url):
"Quotes a URL if it isn't already quoted."
def unquote_quote(segment):
segment = unquote(force_str(segment))
# Tilde is part of RFC3986 Unreserved Characters
# http://tools.ietf.org/html/rfc3986#section-2.3
# See also http://bugs.python.org/issue16285
segment = quote(segment, safe=RFC3986_SUBDELIMS + RFC3986_GENDELIMS + str('~'))
return force_text(segment)
# Handle IDN before quoting.
try:
scheme, netloc, path, query, fragment = urlsplit(url)
except ValueError:
# invalid IPv6 URL (normally square brackets in hostname part).
return unquote_quote(url)
try:
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
except UnicodeError: # invalid domain part
return unquote_quote(url)
if query:
# Separately unquoting key/value, so as to not mix querystring separators
# included in query values. See #22267.
query_parts = [(unquote(force_str(q[0])), unquote(force_str(q[1])))
for q in parse_qsl(query, keep_blank_values=True)]
# urlencode will take care of quoting
query = urlencode(query_parts)
path = unquote_quote(path)
fragment = unquote_quote(fragment)
return urlunsplit((scheme, netloc, path, query, fragment))
@keep_lazy_text
def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
"""
Converts any URLs in text into clickable links.
Works on http://, https://, www. links, and also on links ending in one of
the original seven gTLDs (.com, .edu, .gov, .int, .mil, .net, and .org).
Links can have trailing punctuation (periods, commas, close-parens) and
leading punctuation (opening parens) and it'll still do the right thing.
If trim_url_limit is not None, the URLs in the link text longer than this
limit will be truncated to trim_url_limit-3 characters and appended with
an ellipsis.
If nofollow is True, the links will get a rel="nofollow" attribute.
If autoescape is True, the link text and URLs will be autoescaped.
"""
safe_input = isinstance(text, SafeData)
def trim_url(x, limit=trim_url_limit):
if limit is None or len(x) <= limit:
return x
return '%s...' % x[:max(0, limit - 3)]
def unescape(text, trail):
"""
If input URL is HTML-escaped, unescape it so as we can safely feed it to
smart_urlquote. For example:
http://example.com?x=1&y=<2> => http://example.com?x=1&y=<2>
"""
unescaped = (text + trail).replace(
'&', '&').replace('<', '<').replace(
'>', '>').replace('"', '"').replace(''', "'")
if trail and unescaped.endswith(trail):
# Remove trail for unescaped if it was not consumed by unescape
unescaped = unescaped[:-len(trail)]
elif trail == ';':
# Trail was consumed by unescape (as end-of-entity marker), move it to text
text += trail
trail = ''
return text, unescaped, trail
def trim_punctuation(lead, middle, trail):
"""
Trim trailing and wrapping punctuation from `middle`. Return the items
of the new state.
"""
# Continue trimming until middle remains unchanged.
trimmed_something = True
while trimmed_something:
trimmed_something = False
# Trim trailing punctuation.
match = TRAILING_PUNCTUATION_RE.match(middle)
if match:
middle = match.group(1)
trail = match.group(2) + trail
trimmed_something = True
# Trim wrapping punctuation.
for opening, closing in WRAPPING_PUNCTUATION:
if middle.startswith(opening):
middle = middle[len(opening):]
lead += opening
trimmed_something = True
# Keep parentheses at the end only if they're balanced.
if (middle.endswith(closing) and
middle.count(closing) == middle.count(opening) + 1):
middle = middle[:-len(closing)]
trail = closing + trail
trimmed_something = True
return lead, middle, trail
words = word_split_re.split(force_text(text))
for i, word in enumerate(words):
if '.' in word or '@' in word or ':' in word:
# lead: Current punctuation trimmed from the beginning of the word.
# middle: Current state of the word.
# trail: Current punctuation trimmed from the end of the word.
lead, middle, trail = '', word, ''
# Deal with punctuation.
lead, middle, trail = trim_punctuation(lead, middle, trail)
# Make URL we want to point to.
url = None
nofollow_attr = ' rel="nofollow"' if nofollow else ''
if simple_url_re.match(middle):
middle, middle_unescaped, trail = unescape(middle, trail)
url = smart_urlquote(middle_unescaped)
elif simple_url_2_re.match(middle):
middle, middle_unescaped, trail = unescape(middle, trail)
url = smart_urlquote('http://%s' % middle_unescaped)
elif ':' not in middle and simple_email_re.match(middle):
local, domain = middle.rsplit('@', 1)
try:
domain = domain.encode('idna').decode('ascii')
except UnicodeError:
continue
url = 'mailto:%s@%s' % (local, domain)
nofollow_attr = ''
# Make link.
if url:
trimmed = trim_url(middle)
if autoescape and not safe_input:
lead, trail = escape(lead), escape(trail)
trimmed = escape(trimmed)
middle = '<a href="%s"%s>%s</a>' % (escape(url), nofollow_attr, trimmed)
words[i] = mark_safe('%s%s%s' % (lead, middle, trail))
else:
if safe_input:
words[i] = mark_safe(word)
elif autoescape:
words[i] = escape(word)
elif safe_input:
words[i] = mark_safe(word)
elif autoescape:
words[i] = escape(word)
return ''.join(words)
def avoid_wrapping(value):
"""
Avoid text wrapping in the middle of a phrase by adding non-breaking
spaces where there previously were normal spaces.
"""
return value.replace(" ", "\xa0")
def html_safe(klass):
"""
A decorator that defines the __html__ method. This helps non-Django
templates to detect classes whose __str__ methods return SafeText.
"""
if '__html__' in klass.__dict__:
raise ValueError(
"can't apply @html_safe to %s because it defines "
"__html__()." % klass.__name__
)
if six.PY2:
if '__unicode__' not in klass.__dict__:
raise ValueError(
"can't apply @html_safe to %s because it doesn't "
"define __unicode__()." % klass.__name__
)
klass_unicode = klass.__unicode__
klass.__unicode__ = lambda self: mark_safe(klass_unicode(self))
klass.__html__ = lambda self: unicode(self) # NOQA: unicode undefined on PY3
else:
if '__str__' not in klass.__dict__:
raise ValueError(
"can't apply @html_safe to %s because it doesn't "
"define __str__()." % klass.__name__
)
klass_str = klass.__str__
klass.__str__ = lambda self: mark_safe(klass_str(self))
klass.__html__ = lambda self: str(self)
return klass
|
bsd-3-clause
|
[
624,
4943,
15841,
11233,
367,
2288,
675,
1041,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
12,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
4215,
63,
6395,
12,
4215,
63,
6395,
63,
505,
199,
504,
1639,
14,
1208,
14,
1014,
492,
7329,
29451,
63,
9289,
4424,
1469,
51,
12,
7329,
29451,
63,
6348,
4424,
1469,
51,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
1451,
12,
14969,
1872,
12,
2216,
63,
3489,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
334,
272,
2198,
63,
26714,
12,
6313,
12,
14342,
12,
16511,
12,
29596,
12,
1166,
30038,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
505,
492,
7666,
63,
13839,
199,
199,
504,
1275,
1360,
63,
2087,
492,
4163,
9123,
12,
24581,
199,
199,
3,
11595,
367,
7629,
13559,
342,
805,
14,
199,
1766,
6593,
1206,
63,
48,
1734,
1028,
53,
2594,
63,
907,
275,
295,
14,
2014,
8,
272,
14452,
7,
3698,
327,
25754,
1835,
402,
4349,
272,
8189,
6697,
3171,
755,
327,
710,
2851,
315,
4349,
272,
283,
779,
2020,
26,
27,
1,
29716,
221,
327,
27301,
2222,
13,
87,
15521,
12,
8520,
22929,
272,
25271,
3698,
327,
9599,
402,
4349,
199,
9,
199,
6524,
7121,
1206,
63,
48,
1734,
1028,
53,
2594,
275,
4274,
5102,
5320,
659,
19990,
297,
12696,
659,
23734,
297,
24710,
659,
661,
6,
4116,
10805,
7673,
3308,
27,
659,
661,
6949,
5522,
659,
661,
3985,
297,
32496,
5440,
199,
199,
3,
3820,
402,
3962,
3326,
1202,
367,
330,
348,
16537,
315,
330,
348,
3496,
5548,
14,
199,
13203,
51,
275,
788,
6,
8523,
3287,
10805,
24999,
1557,
85,
13859,
297,
7673,
3,
10721,
10805,
7673,
66,
979,
10805,
7673,
3,
10228,
22,
27,
418,
199,
199,
324,
8167,
63,
5282,
1192,
5915,
63,
264,
275,
295,
14,
2014,
8,
82,
21840,
26313,
2961,
87,
21449,
20262,
68,
11,
2736,
5942,
199,
1027,
63,
1294,
63,
264,
275,
295,
14,
2014,
8,
82,
2344,
16510,
83,
28,
4335,
418,
8771,
12310,
199,
4129,
63,
633,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
2859,
14144,
25621,
8995,
87,
297,
295,
14,
15434,
9,
199,
4129,
63,
633,
63,
18,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
1544,
32327,
62,
26313,
1014,
2862,
87,
4735,
32,
2807,
4537,
8,
957,
92,
8654,
92,
16294,
92,
442,
92,
77,
382,
92,
846,
92,
1308,
5130,
31686,
15,
12432,
4268,
295,
14,
15434,
9,
199,
4129,
63,
2123,
63,
264,
275,
295,
14,
2014,
8,
82,
15542,
51,
11,
32,
60,
51,
23294,
51,
11,
9988,
199,
1073,
63,
1375,
63,
3215,
63,
264,
275,
295,
14,
2014,
8,
82,
6774,
28,
65,
359,
62,
30,
3672,
17076,
1375,
1524,
12773,
83,
30,
2807,
358,
199,
1360,
63,
71,
1778,
63,
264,
275,
295,
14,
2014,
8,
272,
519,
20459,
28,
3289,
5436,
628,
452,
1743,
92,
28,
73,
2535,
19814,
73,
21521,
28,
66,
2535,
19814,
66,
21521,
28,
5633,
2535,
19814,
5633,
21521,
28,
9370,
2535,
19814,
9370,
30,
5227,
272,
2650,
60,
10197,
7241,
12029,
21521,
31873,
10197,
26831,
30,
3196,
295,
14,
15434,
9,
199,
8726,
63,
15282,
63,
25792,
16537,
63,
264,
275,
295,
14,
2014,
8,
272,
519,
7,
17304,
16875,
80,
30,
2229,
2689,
83,
680,
15279,
59,
65,
13,
6353,
13,
58,
1055,
15279,
1108,
80,
3072,
83,
10,
6393,
3171,
450,
21590,
904,
8,
264,
14,
3765,
8,
88,
9,
367,
671,
315,
15854,
51,
395,
295,
14,
16504,
199,
9,
199,
15910,
63,
1667,
63,
1317,
63,
264,
275,
295,
14,
2014,
8,
82,
20459,
28,
80,
30,
5169,
6,
10758,
27,
6113,
83,
92,
28,
3289,
971,
3133,
3342,
31,
1108,
80,
3072,
83,
10,
6393,
60,
58,
358,
421,
199,
32,
3250,
63,
6395,
8,
4174,
14,
505,
63,
466,
12,
14969,
1872,
9,
199,
318,
4772,
8,
505,
304,
272,
408,
272,
1803,
314,
1627,
1318,
543,
15204,
1192,
5915,
12,
9344,
436,
9324,
21873,
5737,
272,
367,
675,
315,
4163,
14,
339,
961,
805,
3544,
24644,
2399,
1324,
12,
2755,
340,
652,
1159,
2575,
11077,
436,
272,
11584,
465,
4066,
14,
961,
1443,
754,
315,
4270,
13,
26306,
14,
982,
642,
365,
282,
406,
22082,
12,
272,
675,
12303,
63,
3765,
342,
3140,
14,
272,
408,
272,
372,
2216,
63,
3489,
8,
267,
3542,
63,
505,
8,
505,
680,
1814,
360,
16749,
7673,
5282,
27,
1959,
1814,
4827,
297,
7673,
4116,
10784,
267,
1275,
1814,
360,
4206,
7673,
3308,
27,
1959,
1814,
20630,
7673,
5184,
27,
1959,
1814,
27769,
7673,
3,
1355,
10784,
272,
776,
199,
199,
63,
3596,
63,
3765,
83,
275,
469,
272,
6206,
11671,
735,
6468,
85,
7972,
35,
297,
272,
6206,
2258,
7,
735,
6468,
85,
28355,
297,
272,
6206,
14088,
735,
6468,
85,
27846,
297,
272,
6206,
16099,
735,
6468,
85,
8262,
37,
297,
272,
6206,
4827,
735,
6468,
85,
8262,
35,
297,
272,
6206,
20040,
735,
6468,
85,
28193,
297,
272,
6206,
360,
534,
304,
6468,
85,
8262,
36,
297,
272,
6206,
3654,
735,
6468,
85,
7432,
36,
297,
272,
6206,
25282,
735,
6468,
85,
8262,
34,
297,
272,
6206,
2258,
85,
25247,
735,
6468,
85,
25247,
297,
272,
6206,
2258,
85,
25078,
735,
6468,
85,
25078,
7,
199,
93,
199,
199,
3,
21067,
4036,
10485,
4528,
543,
282,
574,
6656,
2419,
4337,
14,
199,
63,
3596,
63,
3765,
83,
14,
873,
1332,
2181,
3508,
67,
7,
450,
1315,
395,
6468,
85,
5,
966,
56,
7,
450,
1315,
9,
367,
1315,
315,
1425,
8,
708,
430,
421,
199,
32,
3250,
63,
6395,
8,
4174,
14,
505,
63,
466,
12,
14969,
1872,
9,
199,
318,
4772,
3596,
8,
585,
304,
272,
408,
10373,
3752,
83,
4110,
367,
675,
315,
15250,
3326,
1041,
272,
372,
2216,
63,
3489,
8,
3990,
63,
505,
8,
585,
680,
5275,
1547,
3596,
63,
3765,
83,
430,
421,
199,
318,
12303,
63,
3765,
8,
505,
304,
272,
408,
272,
20046,
370,
4772,
1062,
871,
626,
652,
3181,
1133,
19218
] |
[
4943,
15841,
11233,
367,
2288,
675,
1041,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
12,
3542,
63,
505,
199,
504,
1639,
14,
1208,
14,
15481,
492,
4215,
63,
6395,
12,
4215,
63,
6395,
63,
505,
199,
504,
1639,
14,
1208,
14,
1014,
492,
7329,
29451,
63,
9289,
4424,
1469,
51,
12,
7329,
29451,
63,
6348,
4424,
1469,
51,
199,
504,
1639,
14,
1208,
14,
28389,
492,
14969,
1451,
12,
14969,
1872,
12,
2216,
63,
3489,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
334,
272,
2198,
63,
26714,
12,
6313,
12,
14342,
12,
16511,
12,
29596,
12,
1166,
30038,
12,
199,
9,
199,
504,
1639,
14,
1208,
14,
505,
492,
7666,
63,
13839,
199,
199,
504,
1275,
1360,
63,
2087,
492,
4163,
9123,
12,
24581,
199,
199,
3,
11595,
367,
7629,
13559,
342,
805,
14,
199,
1766,
6593,
1206,
63,
48,
1734,
1028,
53,
2594,
63,
907,
275,
295,
14,
2014,
8,
272,
14452,
7,
3698,
327,
25754,
1835,
402,
4349,
272,
8189,
6697,
3171,
755,
327,
710,
2851,
315,
4349,
272,
283,
779,
2020,
26,
27,
1,
29716,
221,
327,
27301,
2222,
13,
87,
15521,
12,
8520,
22929,
272,
25271,
3698,
327,
9599,
402,
4349,
199,
9,
199,
6524,
7121,
1206,
63,
48,
1734,
1028,
53,
2594,
275,
4274,
5102,
5320,
659,
19990,
297,
12696,
659,
23734,
297,
24710,
659,
661,
6,
4116,
10805,
7673,
3308,
27,
659,
661,
6949,
5522,
659,
661,
3985,
297,
32496,
5440,
199,
199,
3,
3820,
402,
3962,
3326,
1202,
367,
330,
348,
16537,
315,
330,
348,
3496,
5548,
14,
199,
13203,
51,
275,
788,
6,
8523,
3287,
10805,
24999,
1557,
85,
13859,
297,
7673,
3,
10721,
10805,
7673,
66,
979,
10805,
7673,
3,
10228,
22,
27,
418,
199,
199,
324,
8167,
63,
5282,
1192,
5915,
63,
264,
275,
295,
14,
2014,
8,
82,
21840,
26313,
2961,
87,
21449,
20262,
68,
11,
2736,
5942,
199,
1027,
63,
1294,
63,
264,
275,
295,
14,
2014,
8,
82,
2344,
16510,
83,
28,
4335,
418,
8771,
12310,
199,
4129,
63,
633,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
2859,
14144,
25621,
8995,
87,
297,
295,
14,
15434,
9,
199,
4129,
63,
633,
63,
18,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
1544,
32327,
62,
26313,
1014,
2862,
87,
4735,
32,
2807,
4537,
8,
957,
92,
8654,
92,
16294,
92,
442,
92,
77,
382,
92,
846,
92,
1308,
5130,
31686,
15,
12432,
4268,
295,
14,
15434,
9,
199,
4129,
63,
2123,
63,
264,
275,
295,
14,
2014,
8,
82,
15542,
51,
11,
32,
60,
51,
23294,
51,
11,
9988,
199,
1073,
63,
1375,
63,
3215,
63,
264,
275,
295,
14,
2014,
8,
82,
6774,
28,
65,
359,
62,
30,
3672,
17076,
1375,
1524,
12773,
83,
30,
2807,
358,
199,
1360,
63,
71,
1778,
63,
264,
275,
295,
14,
2014,
8,
272,
519,
20459,
28,
3289,
5436,
628,
452,
1743,
92,
28,
73,
2535,
19814,
73,
21521,
28,
66,
2535,
19814,
66,
21521,
28,
5633,
2535,
19814,
5633,
21521,
28,
9370,
2535,
19814,
9370,
30,
5227,
272,
2650,
60,
10197,
7241,
12029,
21521,
31873,
10197,
26831,
30,
3196,
295,
14,
15434,
9,
199,
8726,
63,
15282,
63,
25792,
16537,
63,
264,
275,
295,
14,
2014,
8,
272,
519,
7,
17304,
16875,
80,
30,
2229,
2689,
83,
680,
15279,
59,
65,
13,
6353,
13,
58,
1055,
15279,
1108,
80,
3072,
83,
10,
6393,
3171,
450,
21590,
904,
8,
264,
14,
3765,
8,
88,
9,
367,
671,
315,
15854,
51,
395,
295,
14,
16504,
199,
9,
199,
15910,
63,
1667,
63,
1317,
63,
264,
275,
295,
14,
2014,
8,
82,
20459,
28,
80,
30,
5169,
6,
10758,
27,
6113,
83,
92,
28,
3289,
971,
3133,
3342,
31,
1108,
80,
3072,
83,
10,
6393,
60,
58,
358,
421,
199,
32,
3250,
63,
6395,
8,
4174,
14,
505,
63,
466,
12,
14969,
1872,
9,
199,
318,
4772,
8,
505,
304,
272,
408,
272,
1803,
314,
1627,
1318,
543,
15204,
1192,
5915,
12,
9344,
436,
9324,
21873,
5737,
272,
367,
675,
315,
4163,
14,
339,
961,
805,
3544,
24644,
2399,
1324,
12,
2755,
340,
652,
1159,
2575,
11077,
436,
272,
11584,
465,
4066,
14,
961,
1443,
754,
315,
4270,
13,
26306,
14,
982,
642,
365,
282,
406,
22082,
12,
272,
675,
12303,
63,
3765,
342,
3140,
14,
272,
408,
272,
372,
2216,
63,
3489,
8,
267,
3542,
63,
505,
8,
505,
680,
1814,
360,
16749,
7673,
5282,
27,
1959,
1814,
4827,
297,
7673,
4116,
10784,
267,
1275,
1814,
360,
4206,
7673,
3308,
27,
1959,
1814,
20630,
7673,
5184,
27,
1959,
1814,
27769,
7673,
3,
1355,
10784,
272,
776,
199,
199,
63,
3596,
63,
3765,
83,
275,
469,
272,
6206,
11671,
735,
6468,
85,
7972,
35,
297,
272,
6206,
2258,
7,
735,
6468,
85,
28355,
297,
272,
6206,
14088,
735,
6468,
85,
27846,
297,
272,
6206,
16099,
735,
6468,
85,
8262,
37,
297,
272,
6206,
4827,
735,
6468,
85,
8262,
35,
297,
272,
6206,
20040,
735,
6468,
85,
28193,
297,
272,
6206,
360,
534,
304,
6468,
85,
8262,
36,
297,
272,
6206,
3654,
735,
6468,
85,
7432,
36,
297,
272,
6206,
25282,
735,
6468,
85,
8262,
34,
297,
272,
6206,
2258,
85,
25247,
735,
6468,
85,
25247,
297,
272,
6206,
2258,
85,
25078,
735,
6468,
85,
25078,
7,
199,
93,
199,
199,
3,
21067,
4036,
10485,
4528,
543,
282,
574,
6656,
2419,
4337,
14,
199,
63,
3596,
63,
3765,
83,
14,
873,
1332,
2181,
3508,
67,
7,
450,
1315,
395,
6468,
85,
5,
966,
56,
7,
450,
1315,
9,
367,
1315,
315,
1425,
8,
708,
430,
421,
199,
32,
3250,
63,
6395,
8,
4174,
14,
505,
63,
466,
12,
14969,
1872,
9,
199,
318,
4772,
3596,
8,
585,
304,
272,
408,
10373,
3752,
83,
4110,
367,
675,
315,
15250,
3326,
1041,
272,
372,
2216,
63,
3489,
8,
3990,
63,
505,
8,
585,
680,
5275,
1547,
3596,
63,
3765,
83,
430,
421,
199,
318,
12303,
63,
3765,
8,
505,
304,
272,
408,
272,
20046,
370,
4772,
1062,
871,
626,
652,
3181,
1133,
19218,
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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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
] |
nikhilsaraf/Twitter-Analytics
|
venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/packages/six.py
|
2375
|
11628
|
"""Utilities for writing code that runs on Python 2 and 3"""
#Copyright (c) 2010-2011 Benjamin Peterson
#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.
import operator
import sys
import types
__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.2.0" # Revision 41c74fef2ded
# True if we are running on Python 3.
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
MAXSIZE = sys.maxsize
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = str
if sys.platform.startswith("java"):
# Jython always uses 32 bits.
MAXSIZE = int((1 << 31) - 1)
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
MAXSIZE = int((1 << 31) - 1)
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
def _add_doc(func, doc):
"""Add documentation to a function."""
func.__doc__ = doc
def _import_module(name):
"""Import module, returning the module after the last dot."""
__import__(name)
return sys.modules[name]
class _LazyDescr(object):
def __init__(self, name):
self.name = name
def __get__(self, obj, tp):
result = self._resolve()
setattr(obj, self.name, result)
# This is a bit ugly, but it avoids running this again.
delattr(tp, self.name)
return result
class MovedModule(_LazyDescr):
def __init__(self, name, old, new=None):
super(MovedModule, self).__init__(name)
if PY3:
if new is None:
new = name
self.mod = new
else:
self.mod = old
def _resolve(self):
return _import_module(self.mod)
class MovedAttribute(_LazyDescr):
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
super(MovedAttribute, self).__init__(name)
if PY3:
if new_mod is None:
new_mod = name
self.mod = new_mod
if new_attr is None:
if old_attr is None:
new_attr = name
else:
new_attr = old_attr
self.attr = new_attr
else:
self.mod = old_mod
if old_attr is None:
old_attr = name
self.attr = old_attr
def _resolve(self):
module = _import_module(self.mod)
return getattr(module, self.attr)
class _MovedItems(types.ModuleType):
"""Lazy loading of moved objects"""
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("StringIO", "StringIO", "io"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
MovedModule("http_client", "httplib", "http.client"),
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
MovedModule("cPickle", "cPickle", "pickle"),
MovedModule("queue", "Queue"),
MovedModule("reprlib", "repr"),
MovedModule("socketserver", "SocketServer"),
MovedModule("tkinter", "Tkinter"),
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
MovedModule("tkinter_colorchooser", "tkColorChooser",
"tkinter.colorchooser"),
MovedModule("tkinter_commondialog", "tkCommonDialog",
"tkinter.commondialog"),
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
"tkinter.simpledialog"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("winreg", "_winreg"),
]
for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
del attr
moves = sys.modules[__name__ + ".moves"] = _MovedItems("moves")
def add_move(move):
"""Add an item to six.moves."""
setattr(_MovedItems, move.name, move)
def remove_move(name):
"""Remove item from six.moves."""
try:
delattr(_MovedItems, name)
except AttributeError:
try:
del moves.__dict__[name]
except KeyError:
raise AttributeError("no such move, %r" % (name,))
if PY3:
_meth_func = "__func__"
_meth_self = "__self__"
_func_code = "__code__"
_func_defaults = "__defaults__"
_iterkeys = "keys"
_itervalues = "values"
_iteritems = "items"
else:
_meth_func = "im_func"
_meth_self = "im_self"
_func_code = "func_code"
_func_defaults = "func_defaults"
_iterkeys = "iterkeys"
_itervalues = "itervalues"
_iteritems = "iteritems"
try:
advance_iterator = next
except NameError:
def advance_iterator(it):
return it.next()
next = advance_iterator
if PY3:
def get_unbound_function(unbound):
return unbound
Iterator = object
def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
else:
def get_unbound_function(unbound):
return unbound.im_func
class Iterator(object):
def next(self):
return type(self).__next__(self)
callable = callable
_add_doc(get_unbound_function,
"""Get the function out of a possibly unbound function""")
get_method_function = operator.attrgetter(_meth_func)
get_method_self = operator.attrgetter(_meth_self)
get_function_code = operator.attrgetter(_func_code)
get_function_defaults = operator.attrgetter(_func_defaults)
def iterkeys(d):
"""Return an iterator over the keys of a dictionary."""
return iter(getattr(d, _iterkeys)())
def itervalues(d):
"""Return an iterator over the values of a dictionary."""
return iter(getattr(d, _itervalues)())
def iteritems(d):
"""Return an iterator over the (key, value) pairs of a dictionary."""
return iter(getattr(d, _iteritems)())
if PY3:
def b(s):
return s.encode("latin-1")
def u(s):
return s
if sys.version_info[1] <= 1:
def int2byte(i):
return bytes((i,))
else:
# This is about 2x faster than the implementation above on 3.2+
int2byte = operator.methodcaller("to_bytes", 1, "big")
import io
StringIO = io.StringIO
BytesIO = io.BytesIO
else:
def b(s):
return s
def u(s):
return unicode(s, "unicode_escape")
int2byte = chr
import StringIO
StringIO = BytesIO = StringIO.StringIO
_add_doc(b, """Byte literal""")
_add_doc(u, """Text literal""")
if PY3:
import builtins
exec_ = getattr(builtins, "exec")
def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
print_ = getattr(builtins, "print")
del builtins
else:
def exec_(code, globs=None, locs=None):
"""Execute code in a namespace."""
if globs is None:
frame = sys._getframe(1)
globs = frame.f_globals
if locs is None:
locs = frame.f_locals
del frame
elif locs is None:
locs = globs
exec("""exec code in globs, locs""")
exec_("""def reraise(tp, value, tb=None):
raise tp, value, tb
""")
def print_(*args, **kwargs):
"""The new-style print function."""
fp = kwargs.pop("file", sys.stdout)
if fp is None:
return
def write(data):
if not isinstance(data, basestring):
data = str(data)
fp.write(data)
want_unicode = False
sep = kwargs.pop("sep", None)
if sep is not None:
if isinstance(sep, unicode):
want_unicode = True
elif not isinstance(sep, str):
raise TypeError("sep must be None or a string")
end = kwargs.pop("end", None)
if end is not None:
if isinstance(end, unicode):
want_unicode = True
elif not isinstance(end, str):
raise TypeError("end must be None or a string")
if kwargs:
raise TypeError("invalid keyword arguments to print()")
if not want_unicode:
for arg in args:
if isinstance(arg, unicode):
want_unicode = True
break
if want_unicode:
newline = unicode("\n")
space = unicode(" ")
else:
newline = "\n"
space = " "
if sep is None:
sep = space
if end is None:
end = newline
for i, arg in enumerate(args):
if i:
write(sep)
write(arg)
write(end)
_add_doc(reraise, """Reraise an exception.""")
def with_metaclass(meta, base=object):
"""Create a base class with a metaclass."""
return meta("NewBase", (base,), {})
|
gpl-3.0
|
[
624,
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
7384,
334,
67,
9,
7129,
13,
8128,
26844,
16997,
262,
22912,
834,
199,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
199,
3,
3749,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
199,
3,
1589,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
199,
3,
1180,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
199,
3,
1589,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5875,
370,
314,
2569,
3704,
26,
199,
199,
3,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
16847,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
199,
3,
2707,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
199,
3,
32324,
5716,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
199,
3,
568,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
18389,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
18,
14,
16,
2,
221,
327,
27095,
13385,
67,
1342,
32688,
18,
770,
421,
199,
3,
715,
340,
781,
787,
3879,
641,
2018,
650,
14,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
288,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
683,
12,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
421,
199,
533,
8863,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
63,
1494,
12,
892,
63,
1494,
12,
2269,
63,
962,
29,
403,
12,
892,
63,
962,
29,
403,
304,
267,
1613,
8,
20774,
1646,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
63,
1494,
365,
488,
26,
355,
892,
63,
1494,
275,
536,
288,
291,
14,
1494,
275,
892,
63,
1494,
288,
340,
892,
63,
962,
365,
488,
26,
355,
340,
2269,
63,
962,
365,
488,
26,
490,
892,
63,
962,
275,
536,
355,
587,
26,
490,
892,
63,
962,
275,
2269,
63,
962,
288,
291,
14,
962,
275,
892,
63,
962,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
63,
1494,
288,
340,
2269,
63,
962,
365,
488,
26,
355,
2269,
63,
962,
275,
536,
288,
291,
14,
962,
275,
2269,
63,
962,
339,
347,
485,
6983,
8,
277,
304,
267,
859,
275,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
267,
372,
2519,
8,
578,
12,
291,
14,
962,
9,
4388,
199,
533,
485,
20774,
7412,
8,
1313,
14,
21820,
304,
272,
408,
14269,
8697,
402,
12155,
2251,
624,
421,
199,
63,
3539,
63,
2987,
275,
359,
272,
8863,
480,
67,
6424,
401,
298,
67,
6424,
401,
298,
2308,
401,
298,
6424,
1288,
272,
8863,
480,
1541,
401,
298,
17691,
401,
298,
10372,
401,
298,
73,
1541,
401,
298,
1541,
1288,
272,
8863,
480,
1210,
401,
4396,
5351,
13915,
298
] |
[
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
7384,
334,
67,
9,
7129,
13,
8128,
26844,
16997,
262,
22912,
834,
199,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
199,
3,
3749,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
199,
3,
1589,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
199,
3,
1180,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
199,
3,
1589,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5875,
370,
314,
2569,
3704,
26,
199,
199,
3,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
16847,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
199,
3,
2707,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
199,
3,
32324,
5716,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
199,
3,
568,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
18389,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
18,
14,
16,
2,
221,
327,
27095,
13385,
67,
1342,
32688,
18,
770,
421,
199,
3,
715,
340,
781,
787,
3879,
641,
2018,
650,
14,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
288,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
683,
12,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
421,
199,
533,
8863,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
63,
1494,
12,
892,
63,
1494,
12,
2269,
63,
962,
29,
403,
12,
892,
63,
962,
29,
403,
304,
267,
1613,
8,
20774,
1646,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
63,
1494,
365,
488,
26,
355,
892,
63,
1494,
275,
536,
288,
291,
14,
1494,
275,
892,
63,
1494,
288,
340,
892,
63,
962,
365,
488,
26,
355,
340,
2269,
63,
962,
365,
488,
26,
490,
892,
63,
962,
275,
536,
355,
587,
26,
490,
892,
63,
962,
275,
2269,
63,
962,
288,
291,
14,
962,
275,
892,
63,
962,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
63,
1494,
288,
340,
2269,
63,
962,
365,
488,
26,
355,
2269,
63,
962,
275,
536,
288,
291,
14,
962,
275,
2269,
63,
962,
339,
347,
485,
6983,
8,
277,
304,
267,
859,
275,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
267,
372,
2519,
8,
578,
12,
291,
14,
962,
9,
4388,
199,
533,
485,
20774,
7412,
8,
1313,
14,
21820,
304,
272,
408,
14269,
8697,
402,
12155,
2251,
624,
421,
199,
63,
3539,
63,
2987,
275,
359,
272,
8863,
480,
67,
6424,
401,
298,
67,
6424,
401,
298,
2308,
401,
298,
6424,
1288,
272,
8863,
480,
1541,
401,
298,
17691,
401,
298,
10372,
401,
298,
73,
1541,
401,
298,
1541,
1288,
272,
8863,
480,
1210,
401,
4396,
5351,
13915,
298,
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,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ions import collector
import sys
import os
import difflib
class Mock(object):
def __init__(self, **kw):
for name, value in kw.items():
setattr(self, name, value)
class Supplement(Mock):
object = 'test_object'
source_url = 'http://whatever.com'
info = 'This is some supplemental information'
args = ()
def getInfo(self):
return self.info
def __call__(self, *args):
self.args = args
return self
class BadSupplement(Supplement):
def getInfo(self):
raise ValueError("This supplemental info is buggy")
def call_error(sup):
1 + 2
__traceback_supplement__ = (sup, ())
assert 0, "I am an error"
def raise_error(sup='default'):
if sup == 'default':
sup = Supplement()
for i in range(10):
__traceback_info__ = i
if i == 5:
call_error(sup=sup)
def hide(t, inner, *args, **kw):
__traceback_hide__ = t
return inner(*args, **kw)
def pass_through(info, inner, *args, **kw):
"""
To add another frame to the call; detectable because
__tracback_info__ is set to `info`
"""
__traceback_info__ = info
return inner(*args, **kw)
def format(type='html', **ops):
data = collector.collect_exception(*sys.exc_info())
report = getattr(formatter, 'format_' + type)(data, **ops)
return report
formats = ('text', 'html')
def test_excersize():
for f in formats:
try:
raise_error()
except:
format(f)
def test_content():
for f in formats:
try:
raise_error()
except:
result = format(f)
print(result)
assert 'test_object' in result
assert 'http://whatever.com' in result
assert 'This is some supplemental information' in result
assert 'raise_error' in result
assert 'call_error' in result
assert '5' in result
assert 'test_content' in result
else:
assert 0
def test_trim():
current = os.path.abspath(os.getcwd())
for f in formats:
try:
raise_error()
except:
result = format(f, trim_source_paths=[(current, '.')])
assert current not in result
assert ('%stest_formatter.py' % os.sep) in result, ValueError(repr(result))
else:
assert 0
def test_hide():
for f in formats:
try:
hide(True, raise_error)
except:
result = format(f)
print(result)
assert 'in hide_inner' not in result
assert 'inner(*args, **kw)' not in result
else:
assert 0
def print_diff(s1, s2):
differ = difflib.Differ()
result = list(differ.compare(s1.splitlines(), s2.splitlines()))
print('\n'.join(result))
def test_hide_supppressed():
"""
When an error occurs and __traceback_stop__ is true for the
erroneous frame, then that setting should be ignored.
"""
for f in ['html']: #formats:
results = []
for hide_value in (False, 'after'):
try:
pass_through(
'a',
hide,
hide_value,
pass_through,
'b',
raise_error)
except:
results.append(format(f))
else:
assert 0
if results[0] != results[1]:
print_diff(results[0], results[1])
assert 0
def test_hide_after():
for f in formats:
try:
pass_through(
'AABB',
hide, 'after',
pass_through, 'CCDD',
# A little whitespace to keep this line out of the
# content part of the report
hide, 'reset',
raise_error)
except:
result = format(f)
assert 'AABB' in result
assert 'CCDD' not in result
assert 'raise_error' in result
else:
assert 0
def test_hide_before():
for f in formats:
try:
pass_through(
'AABB',
hide, 'before',
raise_error)
except:
result = format(f)
print(result)
assert 'AABB' not in result
assert 'raise_error' in result
else:
assert 0
def test_make_wrappable():
assert '<wbr>' in formatter.make_wrappable('x'*1000)
# I'm just going to test that this doesn't excede the stack limit:
formatter.make_wrappable(';'*2000)
assert (formatter.make_wrappable('this that the other')
== 'this that the other')
assert (formatter.make_wrappable('this that ' + ('x'*50) + ';' + ('y'*50) + ' and the other')
== 'this that '+('x'*50) + ';<wbr>' + ('y'*50) + ' and the other')
|
bsd-3-clause
|
[
504,
20901,
14,
3924,
492,
9698,
199,
504,
20901,
14,
3924,
492,
14910,
199,
646,
984,
199,
646,
747,
199,
646,
27070,
199,
199,
533,
4420,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1011,
829,
304,
267,
367,
536,
12,
574,
315,
4775,
14,
1744,
837,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
199,
199,
533,
29083,
968,
8,
3346,
304,
339,
909,
275,
283,
396,
63,
785,
7,
272,
1350,
63,
633,
275,
283,
1014,
921,
26517,
14,
957,
7,
272,
2256,
275,
283,
2765,
365,
2005,
4973,
968,
279,
2556,
7,
272,
1249,
275,
6248,
272,
347,
664,
2354,
8,
277,
304,
267,
372,
291,
14,
815,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
291,
14,
589,
275,
1249,
267,
372,
291,
199,
199,
533,
8857,
17127,
968,
8,
17127,
968,
304,
339,
347,
664,
2354,
8,
277,
304,
267,
746,
1722,
480,
2765,
4973,
968,
279,
2256,
365,
1032,
26435,
531,
199,
199,
318,
1240,
63,
705,
8,
1961,
304,
272,
413,
435,
499,
272,
636,
6894,
63,
8621,
968,
363,
275,
334,
1961,
12,
14515,
272,
702,
378,
12,
298,
41,
8140,
376,
1125,
2,
199,
199,
318,
746,
63,
705,
8,
1961,
534,
885,
735,
272,
340,
1029,
508,
283,
885,
356,
267,
1029,
275,
29083,
968,
342,
272,
367,
284,
315,
1425,
8,
709,
304,
267,
636,
6894,
63,
815,
363,
275,
284,
267,
340,
284,
508,
959,
26,
288,
1240,
63,
705,
8,
1961,
29,
1961,
9,
199,
199,
318,
13714,
8,
84,
12,
6506,
12,
627,
589,
12,
1011,
829,
304,
272,
636,
6894,
63,
8191,
363,
275,
307,
272,
372,
6506,
2031,
589,
12,
1011,
829,
9,
199,
199,
318,
986,
63,
8304,
8,
815,
12,
6506,
12,
627,
589,
12,
1011,
829,
304,
272,
408,
272,
4005,
1050,
4573,
2787,
370,
314,
1240,
27,
9696,
461,
2952,
272,
636,
23047,
894,
63,
815,
363,
365,
663,
370,
658,
815,
64,
272,
408,
272,
636,
6894,
63,
815,
363,
275,
2256,
272,
372,
6506,
2031,
589,
12,
1011,
829,
9,
199,
199,
318,
1475,
8,
466,
534,
1360,
297,
1011,
1483,
304,
272,
666,
275,
14910,
14,
7112,
63,
1971,
2031,
1274,
14,
2804,
63,
815,
1012,
272,
3622,
275,
2519,
8,
8911,
12,
283,
908,
8650,
435,
730,
5130,
576,
12,
1011,
1483,
9,
272,
372,
3622,
199,
199,
6321,
275,
661,
505,
297,
283,
1360,
358,
199,
199,
318,
511,
63,
476,
2247,
890,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
746,
63,
705,
342,
267,
871,
26,
288,
1475,
8,
70,
9,
199,
199,
318,
511,
63,
1317,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
746,
63,
705,
342,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
9,
288,
870,
8,
1099,
9,
288,
702,
283,
396,
63,
785,
7,
315,
754,
288,
702,
283,
1014,
921,
26517,
14,
957,
7,
315,
754,
288,
702,
283,
2765,
365,
2005,
4973,
968,
279,
2556,
7,
315,
754,
288,
702,
283,
3730,
63,
705,
7,
315,
754,
288,
702,
283,
1250,
63,
705,
7,
315,
754,
288,
702,
283,
21,
7,
315,
754,
288,
702,
283,
396,
63,
1317,
7,
315,
754,
267,
587,
26,
288,
702,
378,
199,
199,
318,
511,
63,
12263,
837,
272,
1453,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
9458,
1012,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
746,
63,
705,
342,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
12,
11639,
63,
1365,
63,
3771,
17497,
1818,
12,
1987,
2023,
288,
702,
1453,
440,
315,
754,
288,
702,
16651,
83,
396,
63,
8911,
14,
647,
7,
450,
747,
14,
4127,
9,
315,
754,
12,
1722,
8,
2722,
8,
1099,
430,
267,
587,
26,
288,
702,
378,
199,
199,
318,
511,
63,
8191,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
13714,
8,
549,
12,
746,
63,
705,
9,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
9,
288,
870,
8,
1099,
9,
288,
702,
283,
262,
13714,
63,
5216,
7,
440,
315,
754,
288,
702,
283,
5216,
2031,
589,
12,
1011,
829,
3171,
440,
315,
754,
267,
587,
26,
288,
702,
378,
199,
199,
318,
870,
63,
3028,
8,
83,
17,
12,
308,
18,
304,
272,
14460,
275,
27070,
14,
1341,
1260,
342,
272,
754,
275,
769,
8,
328,
1260,
14,
5785,
8,
83,
17,
14,
7644,
1062,
308,
18,
14,
7644,
4059,
272,
870,
2258,
78,
1370,
904,
8,
1099,
430,
199,
199,
318,
511,
63,
8191,
63,
1961,
802,
5111,
837,
272,
408,
272,
3979,
376,
1125,
11058,
436,
636,
6894,
63,
2379,
363,
365,
2549,
367,
314,
272,
2329,
368,
1785,
2787,
12,
2066,
626,
4260,
1077,
506,
5525,
14,
272,
408,
272,
367,
289,
315,
788,
1360,
2565,
327,
6321,
26,
267,
2058,
275,
942,
267,
367,
13714,
63,
585,
315,
334,
797,
12,
283,
4399,
735,
288,
862,
26,
355,
986,
63,
8304,
8,
490,
283,
65,
297,
490,
13714,
12,
490,
13714,
63,
585,
12,
490,
986,
63,
8304,
12,
490,
283,
66,
297,
490,
746,
63,
705,
9,
288,
871,
26,
355,
2058,
14,
740,
8,
908,
8,
70,
430,
288,
587,
26,
355,
702,
378,
267,
340,
2058,
59,
16,
61,
1137,
2058,
59,
17,
2189,
288,
870,
63,
3028,
8,
2604,
59,
16,
467,
2058,
59,
17,
566,
288,
702,
378,
199,
199,
318,
511,
63,
8191,
63,
4399,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
986,
63,
8304,
8,
355,
283,
33,
1217,
34,
297,
355,
13714,
12,
283,
4399,
297,
355,
986,
63,
8304,
12,
283,
2571,
5745,
297,
355,
327,
437,
12050,
8139,
370,
4215,
642,
1004,
734,
402,
314,
355,
327,
1564,
1777,
402,
314,
3622,
421,
355,
13714,
12,
283,
3958,
297,
355,
746,
63,
705,
9,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
9,
288,
702,
283,
33,
1217,
34,
7,
315,
754,
288,
702,
283,
2571,
5745,
7,
440,
315,
754,
288,
702,
283,
3730,
63,
705,
7,
315,
754,
267,
587,
26,
288,
702,
378,
199,
199
] |
[
20901,
14,
3924,
492,
9698,
199,
504,
20901,
14,
3924,
492,
14910,
199,
646,
984,
199,
646,
747,
199,
646,
27070,
199,
199,
533,
4420,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1011,
829,
304,
267,
367,
536,
12,
574,
315,
4775,
14,
1744,
837,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
199,
199,
533,
29083,
968,
8,
3346,
304,
339,
909,
275,
283,
396,
63,
785,
7,
272,
1350,
63,
633,
275,
283,
1014,
921,
26517,
14,
957,
7,
272,
2256,
275,
283,
2765,
365,
2005,
4973,
968,
279,
2556,
7,
272,
1249,
275,
6248,
272,
347,
664,
2354,
8,
277,
304,
267,
372,
291,
14,
815,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
291,
14,
589,
275,
1249,
267,
372,
291,
199,
199,
533,
8857,
17127,
968,
8,
17127,
968,
304,
339,
347,
664,
2354,
8,
277,
304,
267,
746,
1722,
480,
2765,
4973,
968,
279,
2256,
365,
1032,
26435,
531,
199,
199,
318,
1240,
63,
705,
8,
1961,
304,
272,
413,
435,
499,
272,
636,
6894,
63,
8621,
968,
363,
275,
334,
1961,
12,
14515,
272,
702,
378,
12,
298,
41,
8140,
376,
1125,
2,
199,
199,
318,
746,
63,
705,
8,
1961,
534,
885,
735,
272,
340,
1029,
508,
283,
885,
356,
267,
1029,
275,
29083,
968,
342,
272,
367,
284,
315,
1425,
8,
709,
304,
267,
636,
6894,
63,
815,
363,
275,
284,
267,
340,
284,
508,
959,
26,
288,
1240,
63,
705,
8,
1961,
29,
1961,
9,
199,
199,
318,
13714,
8,
84,
12,
6506,
12,
627,
589,
12,
1011,
829,
304,
272,
636,
6894,
63,
8191,
363,
275,
307,
272,
372,
6506,
2031,
589,
12,
1011,
829,
9,
199,
199,
318,
986,
63,
8304,
8,
815,
12,
6506,
12,
627,
589,
12,
1011,
829,
304,
272,
408,
272,
4005,
1050,
4573,
2787,
370,
314,
1240,
27,
9696,
461,
2952,
272,
636,
23047,
894,
63,
815,
363,
365,
663,
370,
658,
815,
64,
272,
408,
272,
636,
6894,
63,
815,
363,
275,
2256,
272,
372,
6506,
2031,
589,
12,
1011,
829,
9,
199,
199,
318,
1475,
8,
466,
534,
1360,
297,
1011,
1483,
304,
272,
666,
275,
14910,
14,
7112,
63,
1971,
2031,
1274,
14,
2804,
63,
815,
1012,
272,
3622,
275,
2519,
8,
8911,
12,
283,
908,
8650,
435,
730,
5130,
576,
12,
1011,
1483,
9,
272,
372,
3622,
199,
199,
6321,
275,
661,
505,
297,
283,
1360,
358,
199,
199,
318,
511,
63,
476,
2247,
890,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
746,
63,
705,
342,
267,
871,
26,
288,
1475,
8,
70,
9,
199,
199,
318,
511,
63,
1317,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
746,
63,
705,
342,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
9,
288,
870,
8,
1099,
9,
288,
702,
283,
396,
63,
785,
7,
315,
754,
288,
702,
283,
1014,
921,
26517,
14,
957,
7,
315,
754,
288,
702,
283,
2765,
365,
2005,
4973,
968,
279,
2556,
7,
315,
754,
288,
702,
283,
3730,
63,
705,
7,
315,
754,
288,
702,
283,
1250,
63,
705,
7,
315,
754,
288,
702,
283,
21,
7,
315,
754,
288,
702,
283,
396,
63,
1317,
7,
315,
754,
267,
587,
26,
288,
702,
378,
199,
199,
318,
511,
63,
12263,
837,
272,
1453,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
9458,
1012,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
746,
63,
705,
342,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
12,
11639,
63,
1365,
63,
3771,
17497,
1818,
12,
1987,
2023,
288,
702,
1453,
440,
315,
754,
288,
702,
16651,
83,
396,
63,
8911,
14,
647,
7,
450,
747,
14,
4127,
9,
315,
754,
12,
1722,
8,
2722,
8,
1099,
430,
267,
587,
26,
288,
702,
378,
199,
199,
318,
511,
63,
8191,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
13714,
8,
549,
12,
746,
63,
705,
9,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
9,
288,
870,
8,
1099,
9,
288,
702,
283,
262,
13714,
63,
5216,
7,
440,
315,
754,
288,
702,
283,
5216,
2031,
589,
12,
1011,
829,
3171,
440,
315,
754,
267,
587,
26,
288,
702,
378,
199,
199,
318,
870,
63,
3028,
8,
83,
17,
12,
308,
18,
304,
272,
14460,
275,
27070,
14,
1341,
1260,
342,
272,
754,
275,
769,
8,
328,
1260,
14,
5785,
8,
83,
17,
14,
7644,
1062,
308,
18,
14,
7644,
4059,
272,
870,
2258,
78,
1370,
904,
8,
1099,
430,
199,
199,
318,
511,
63,
8191,
63,
1961,
802,
5111,
837,
272,
408,
272,
3979,
376,
1125,
11058,
436,
636,
6894,
63,
2379,
363,
365,
2549,
367,
314,
272,
2329,
368,
1785,
2787,
12,
2066,
626,
4260,
1077,
506,
5525,
14,
272,
408,
272,
367,
289,
315,
788,
1360,
2565,
327,
6321,
26,
267,
2058,
275,
942,
267,
367,
13714,
63,
585,
315,
334,
797,
12,
283,
4399,
735,
288,
862,
26,
355,
986,
63,
8304,
8,
490,
283,
65,
297,
490,
13714,
12,
490,
13714,
63,
585,
12,
490,
986,
63,
8304,
12,
490,
283,
66,
297,
490,
746,
63,
705,
9,
288,
871,
26,
355,
2058,
14,
740,
8,
908,
8,
70,
430,
288,
587,
26,
355,
702,
378,
267,
340,
2058,
59,
16,
61,
1137,
2058,
59,
17,
2189,
288,
870,
63,
3028,
8,
2604,
59,
16,
467,
2058,
59,
17,
566,
288,
702,
378,
199,
199,
318,
511,
63,
8191,
63,
4399,
837,
272,
367,
289,
315,
6752,
26,
267,
862,
26,
288,
986,
63,
8304,
8,
355,
283,
33,
1217,
34,
297,
355,
13714,
12,
283,
4399,
297,
355,
986,
63,
8304,
12,
283,
2571,
5745,
297,
355,
327,
437,
12050,
8139,
370,
4215,
642,
1004,
734,
402,
314,
355,
327,
1564,
1777,
402,
314,
3622,
421,
355,
13714,
12,
283,
3958,
297,
355,
746,
63,
705,
9,
267,
871,
26,
288,
754,
275,
1475,
8,
70,
9,
288,
702,
283,
33,
1217,
34,
7,
315,
754,
288,
702,
283,
2571,
5745,
7,
440,
315,
754,
288,
702,
283,
3730,
63,
705,
7,
315,
754,
267,
587,
26,
288,
702,
378,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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__ import absolute_import
import pickle
import datetime
from django.test import TestCase
from .models import Group, Event, Happening
class PickleabilityTestCase(TestCase):
def assert_pickles(self, qs):
self.assertEqual(list(pickle.loads(pickle.dumps(qs))), list(qs))
def test_related_field(self):
g = Group.objects.create(name="Ponies Who Own Maybachs")
self.assert_pickles(Event.objects.filter(group=g.id))
def test_datetime_callable_default_all(self):
self.assert_pickles(Happening.objects.all())
def test_datetime_callable_default_filter(self):
self.assert_pickles(Happening.objects.filter(when=datetime.datetime.now()))
def test_lambda_as_default(self):
self.assert_pickles(Happening.objects.filter(name="test"))
def test_standalone_method_as_default(self):
self.assert_pickles(Happening.objects.filter(number1=1))
def test_staticmethod_as_default(self):
self.assert_pickles(Happening.objects.filter(number2=1))
def test_classmethod_as_default(self):
self.assert_pickles(Happening.objects.filter(number3=1))
def test_membermethod_as_default(self):
self.assert_pickles(Happening.objects.filter(number4=1))
def test_doesnotexist_exception(self):
# Ticket #17776
original = Event.DoesNotExist("Doesn't exist")
unpickled = pickle.loads(pickle.dumps(original))
# Exceptions are not equal to equivalent instances of themselves, so
# can't just use assertEqual(original, unpickled)
self.assertEqual(original.__class__, unpickled.__class__)
self.assertEqual(original.args, unpickled.args)
|
lgpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
5927,
199,
646,
2197,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
5611,
12,
6763,
12,
869,
5435,
316,
421,
199,
533,
31732,
3616,
1746,
8,
1746,
304,
272,
347,
702,
63,
4510,
2978,
8,
277,
12,
6377,
304,
267,
291,
14,
629,
8,
513,
8,
8092,
14,
3640,
8,
8092,
14,
4180,
8,
6177,
11508,
769,
8,
6177,
430,
339,
347,
511,
63,
2407,
63,
698,
8,
277,
304,
267,
486,
275,
5611,
14,
1462,
14,
981,
8,
354,
628,
48,
265,
1500,
644,
526,
593,
3501,
10162,
31983,
83,
531,
267,
291,
14,
479,
63,
4510,
2978,
8,
2390,
14,
1462,
14,
1541,
8,
923,
29,
71,
14,
344,
430,
339,
347,
511,
63,
2083,
63,
8296,
63,
885,
63,
452,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
452,
1012,
339,
347,
511,
63,
2083,
63,
8296,
63,
885,
63,
1541,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
6526,
29,
2083,
14,
2083,
14,
2131,
4059,
339,
347,
511,
63,
2734,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
354,
628,
396,
2237,
339,
347,
511,
63,
20323,
63,
765,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
17,
29,
17,
430,
339,
347,
511,
63,
4639,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
18,
29,
17,
430,
339,
347,
511,
63,
3744,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
19,
29,
17,
430,
339,
347,
511,
63,
1114,
765,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
20,
29,
17,
430,
339,
347,
511,
63,
9105,
889,
3858,
631,
63,
1971,
8,
277,
304,
267,
327,
21932,
327,
8881,
2114,
267,
3379,
275,
6763,
14,
7400,
480,
6586,
78,
1133,
2187,
531,
267,
625,
20428,
275,
5927,
14,
3640,
8,
8092,
14,
4180,
8,
5043,
430,
398,
327,
24873,
787,
440,
4472,
370,
7353,
4454,
402,
17279,
12,
880,
267,
327,
883,
1133,
2951,
675,
26400,
8,
5043,
12,
625,
20428,
9,
267,
291,
14,
629,
8,
5043,
855,
533,
3108,
625,
20428,
855,
533,
3368,
267,
291,
14,
629,
8,
5043,
14,
589,
12,
625,
20428,
14,
589,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
5927,
199,
646,
2197,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
5611,
12,
6763,
12,
869,
5435,
316,
421,
199,
533,
31732,
3616,
1746,
8,
1746,
304,
272,
347,
702,
63,
4510,
2978,
8,
277,
12,
6377,
304,
267,
291,
14,
629,
8,
513,
8,
8092,
14,
3640,
8,
8092,
14,
4180,
8,
6177,
11508,
769,
8,
6177,
430,
339,
347,
511,
63,
2407,
63,
698,
8,
277,
304,
267,
486,
275,
5611,
14,
1462,
14,
981,
8,
354,
628,
48,
265,
1500,
644,
526,
593,
3501,
10162,
31983,
83,
531,
267,
291,
14,
479,
63,
4510,
2978,
8,
2390,
14,
1462,
14,
1541,
8,
923,
29,
71,
14,
344,
430,
339,
347,
511,
63,
2083,
63,
8296,
63,
885,
63,
452,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
452,
1012,
339,
347,
511,
63,
2083,
63,
8296,
63,
885,
63,
1541,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
6526,
29,
2083,
14,
2083,
14,
2131,
4059,
339,
347,
511,
63,
2734,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
354,
628,
396,
2237,
339,
347,
511,
63,
20323,
63,
765,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
17,
29,
17,
430,
339,
347,
511,
63,
4639,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
18,
29,
17,
430,
339,
347,
511,
63,
3744,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
19,
29,
17,
430,
339,
347,
511,
63,
1114,
765,
63,
305,
63,
885,
8,
277,
304,
267,
291,
14,
479,
63,
4510,
2978,
8,
40,
5435,
316,
14,
1462,
14,
1541,
8,
1955,
20,
29,
17,
430,
339,
347,
511,
63,
9105,
889,
3858,
631,
63,
1971,
8,
277,
304,
267,
327,
21932,
327,
8881,
2114,
267,
3379,
275,
6763,
14,
7400,
480,
6586,
78,
1133,
2187,
531,
267,
625,
20428,
275,
5927,
14,
3640,
8,
8092,
14,
4180,
8,
5043,
430,
398,
327,
24873,
787,
440,
4472,
370,
7353,
4454,
402,
17279,
12,
880,
267,
327,
883,
1133,
2951,
675,
26400,
8,
5043,
12,
625,
20428,
9,
267,
291,
14,
629,
8,
5043,
855,
533,
3108,
625,
20428,
855,
533,
3368,
267,
291,
14,
629,
8,
5043,
14,
589,
12,
625,
20428,
14,
589,
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,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|
20
|
6579
|
# Copyright (c) 2014 Rackspace Hosting
# 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.
import errno
import socket
import mock
from nova import exception
from nova.tests.unit.virt.xenapi import stubs
from nova import version
from nova.virt.xenapi.client import session
class SessionTestCase(stubs.XenAPITestBaseNoDB):
@mock.patch.object(session.XenAPISession, '_create_session')
@mock.patch.object(session.XenAPISession, '_get_product_version_and_brand')
@mock.patch.object(session.XenAPISession, '_verify_plugin_version')
def test_session_passes_version(self, mock_verify, mock_version,
create_session):
sess = mock.Mock()
create_session.return_value = sess
mock_version.return_value = ('version', 'brand')
session.XenAPISession('url', 'username', 'password')
expected_version = '%s %s %s' % (version.vendor_string(),
version.product_string(),
version.version_string_with_package())
sess.login_with_password.assert_called_with('username', 'password',
expected_version,
'OpenStack')
class ApplySessionHelpersTestCase(stubs.XenAPITestBaseNoDB):
def setUp(self):
super(ApplySessionHelpersTestCase, self).setUp()
self.session = mock.Mock()
session.apply_session_helpers(self.session)
def test_apply_session_helpers_add_VM(self):
self.session.VM.get_X("ref")
self.session.call_xenapi.assert_called_once_with("VM.get_X", "ref")
def test_apply_session_helpers_add_SR(self):
self.session.SR.get_X("ref")
self.session.call_xenapi.assert_called_once_with("SR.get_X", "ref")
def test_apply_session_helpers_add_VDI(self):
self.session.VDI.get_X("ref")
self.session.call_xenapi.assert_called_once_with("VDI.get_X", "ref")
def test_apply_session_helpers_add_VBD(self):
self.session.VBD.get_X("ref")
self.session.call_xenapi.assert_called_once_with("VBD.get_X", "ref")
def test_apply_session_helpers_add_PBD(self):
self.session.PBD.get_X("ref")
self.session.call_xenapi.assert_called_once_with("PBD.get_X", "ref")
def test_apply_session_helpers_add_PIF(self):
self.session.PIF.get_X("ref")
self.session.call_xenapi.assert_called_once_with("PIF.get_X", "ref")
def test_apply_session_helpers_add_VLAN(self):
self.session.VLAN.get_X("ref")
self.session.call_xenapi.assert_called_once_with("VLAN.get_X", "ref")
def test_apply_session_helpers_add_host(self):
self.session.host.get_X("ref")
self.session.call_xenapi.assert_called_once_with("host.get_X", "ref")
def test_apply_session_helpers_add_network(self):
self.session.network.get_X("ref")
self.session.call_xenapi.assert_called_once_with("network.get_X",
"ref")
def test_apply_session_helpers_add_pool(self):
self.session.pool.get_X("ref")
self.session.call_xenapi.assert_called_once_with("pool.get_X", "ref")
class CallPluginTestCase(stubs.XenAPITestBaseNoDB):
def _get_fake_xapisession(self):
class FakeXapiSession(session.XenAPISession):
def __init__(self, **kwargs):
"Skip the superclass's dirty init"
self.XenAPI = mock.MagicMock()
return FakeXapiSession()
def setUp(self):
super(CallPluginTestCase, self).setUp()
self.session = self._get_fake_xapisession()
def test_serialized_with_retry_socket_error_conn_reset(self):
exc = socket.error()
exc.errno = errno.ECONNRESET
plugin = 'glance'
fn = 'download_vhd'
num_retries = 1
callback = None
retry_cb = mock.Mock()
with mock.patch.object(self.session, 'call_plugin_serialized',
autospec=True) as call_plugin_serialized:
call_plugin_serialized.side_effect = exc
self.assertRaises(exception.PluginRetriesExceeded,
self.session.call_plugin_serialized_with_retry, plugin, fn,
num_retries, callback, retry_cb)
call_plugin_serialized.assert_called_with(plugin, fn)
self.assertEqual(2, call_plugin_serialized.call_count)
self.assertEqual(2, retry_cb.call_count)
def test_serialized_with_retry_socket_error_reraised(self):
exc = socket.error()
exc.errno = errno.ECONNREFUSED
plugin = 'glance'
fn = 'download_vhd'
num_retries = 1
callback = None
retry_cb = mock.Mock()
with mock.patch.object(self.session, 'call_plugin_serialized',
autospec=True) as call_plugin_serialized:
call_plugin_serialized.side_effect = exc
self.assertRaises(socket.error,
self.session.call_plugin_serialized_with_retry, plugin, fn,
num_retries, callback, retry_cb)
call_plugin_serialized.assert_called_once_with(plugin, fn)
self.assertEqual(0, retry_cb.call_count)
def test_serialized_with_retry_socket_reset_reraised(self):
exc = socket.error()
exc.errno = errno.ECONNRESET
plugin = 'glance'
fn = 'download_vhd'
num_retries = 1
callback = None
retry_cb = mock.Mock()
with mock.patch.object(self.session, 'call_plugin_serialized',
autospec=True) as call_plugin_serialized:
call_plugin_serialized.side_effect = exc
self.assertRaises(exception.PluginRetriesExceeded,
self.session.call_plugin_serialized_with_retry, plugin, fn,
num_retries, callback, retry_cb)
call_plugin_serialized.assert_called_with(plugin, fn)
self.assertEqual(2, call_plugin_serialized.call_count)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
32679,
10891,
316,
199,
3,
2900,
5924,
5702,
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,
7554,
199,
646,
2838,
199,
199,
646,
1683,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
2219,
14,
3248,
14,
4549,
14,
20392,
492,
22312,
199,
504,
5913,
492,
1015,
199,
504,
5913,
14,
4549,
14,
20392,
14,
1258,
492,
2351,
421,
199,
533,
8596,
1746,
8,
8957,
14,
30643,
2642,
597,
1563,
1944,
2846,
304,
272,
768,
1805,
14,
2068,
14,
785,
8,
1730,
14,
30643,
1282,
1311,
3552,
12,
2513,
981,
63,
1730,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1730,
14,
30643,
1282,
1311,
3552,
12,
2513,
362,
63,
2558,
63,
1023,
63,
460,
63,
19026,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1730,
14,
30643,
1282,
1311,
3552,
12,
2513,
4712,
63,
2718,
63,
1023,
358,
272,
347,
511,
63,
1730,
63,
16027,
63,
1023,
8,
277,
12,
1683,
63,
4712,
12,
1683,
63,
1023,
12,
2511,
1218,
63,
1730,
304,
267,
4043,
275,
1683,
14,
3346,
342,
267,
1218,
63,
1730,
14,
1107,
63,
585,
275,
4043,
267,
1683,
63,
1023,
14,
1107,
63,
585,
275,
661,
1023,
297,
283,
19026,
358,
398,
2351,
14,
30643,
1282,
1311,
3552,
360,
633,
297,
283,
2473,
297,
283,
2060,
358,
398,
1420,
63,
1023,
275,
1543,
83,
450,
83,
450,
83,
7,
450,
334,
1023,
14,
9884,
63,
875,
1062,
1460,
1015,
14,
2558,
63,
875,
1062,
1460,
1015,
14,
1023,
63,
875,
63,
1045,
63,
2491,
1012,
267,
4043,
14,
2886,
63,
1045,
63,
2060,
14,
479,
63,
3527,
63,
1045,
360,
2473,
297,
283,
2060,
297,
8105,
1420,
63,
1023,
12,
8105,
283,
26208,
358,
421,
199,
533,
14618,
4434,
4433,
83,
1746,
8,
8957,
14,
30643,
2642,
597,
1563,
1944,
2846,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
16581,
4434,
4433,
83,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
1730,
275,
1683,
14,
3346,
342,
267,
2351,
14,
4998,
63,
1730,
63,
7546,
8,
277,
14,
1730,
9,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
6849,
8,
277,
304,
267,
291,
14,
1730,
14,
6849,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
6849,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
5943,
8,
277,
304,
267,
291,
14,
1730,
14,
5943,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
5943,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
32421,
8,
277,
304,
267,
291,
14,
1730,
14,
32421,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
32421,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
54,
11156,
8,
277,
304,
267,
291,
14,
1730,
14,
54,
11156,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
54,
11156,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
48,
11156,
8,
277,
304,
267,
291,
14,
1730,
14,
48,
11156,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
48,
11156,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
2252,
38,
8,
277,
304,
267,
291,
14,
1730,
14,
2252,
38,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
2252,
38,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
22716,
8,
277,
304,
267,
291,
14,
1730,
14,
22716,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
22716,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
1102,
8,
277,
304,
267,
291,
14,
1730,
14,
1102,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
1102,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
1200,
8,
277,
304,
267,
291,
14,
1730,
14,
1200,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
1200,
14,
362,
63,
56,
401,
12740,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
2293,
8,
277,
304,
267,
291,
14,
1730,
14,
2293,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392
] |
[
1898,
334,
67,
9,
6927,
32679,
10891,
316,
199,
3,
2900,
5924,
5702,
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,
7554,
199,
646,
2838,
199,
199,
646,
1683,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
2219,
14,
3248,
14,
4549,
14,
20392,
492,
22312,
199,
504,
5913,
492,
1015,
199,
504,
5913,
14,
4549,
14,
20392,
14,
1258,
492,
2351,
421,
199,
533,
8596,
1746,
8,
8957,
14,
30643,
2642,
597,
1563,
1944,
2846,
304,
272,
768,
1805,
14,
2068,
14,
785,
8,
1730,
14,
30643,
1282,
1311,
3552,
12,
2513,
981,
63,
1730,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1730,
14,
30643,
1282,
1311,
3552,
12,
2513,
362,
63,
2558,
63,
1023,
63,
460,
63,
19026,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
1730,
14,
30643,
1282,
1311,
3552,
12,
2513,
4712,
63,
2718,
63,
1023,
358,
272,
347,
511,
63,
1730,
63,
16027,
63,
1023,
8,
277,
12,
1683,
63,
4712,
12,
1683,
63,
1023,
12,
2511,
1218,
63,
1730,
304,
267,
4043,
275,
1683,
14,
3346,
342,
267,
1218,
63,
1730,
14,
1107,
63,
585,
275,
4043,
267,
1683,
63,
1023,
14,
1107,
63,
585,
275,
661,
1023,
297,
283,
19026,
358,
398,
2351,
14,
30643,
1282,
1311,
3552,
360,
633,
297,
283,
2473,
297,
283,
2060,
358,
398,
1420,
63,
1023,
275,
1543,
83,
450,
83,
450,
83,
7,
450,
334,
1023,
14,
9884,
63,
875,
1062,
1460,
1015,
14,
2558,
63,
875,
1062,
1460,
1015,
14,
1023,
63,
875,
63,
1045,
63,
2491,
1012,
267,
4043,
14,
2886,
63,
1045,
63,
2060,
14,
479,
63,
3527,
63,
1045,
360,
2473,
297,
283,
2060,
297,
8105,
1420,
63,
1023,
12,
8105,
283,
26208,
358,
421,
199,
533,
14618,
4434,
4433,
83,
1746,
8,
8957,
14,
30643,
2642,
597,
1563,
1944,
2846,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
16581,
4434,
4433,
83,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
1730,
275,
1683,
14,
3346,
342,
267,
2351,
14,
4998,
63,
1730,
63,
7546,
8,
277,
14,
1730,
9,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
6849,
8,
277,
304,
267,
291,
14,
1730,
14,
6849,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
6849,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
5943,
8,
277,
304,
267,
291,
14,
1730,
14,
5943,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
5943,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
32421,
8,
277,
304,
267,
291,
14,
1730,
14,
32421,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
32421,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
54,
11156,
8,
277,
304,
267,
291,
14,
1730,
14,
54,
11156,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
54,
11156,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
48,
11156,
8,
277,
304,
267,
291,
14,
1730,
14,
48,
11156,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
48,
11156,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
2252,
38,
8,
277,
304,
267,
291,
14,
1730,
14,
2252,
38,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
2252,
38,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
22716,
8,
277,
304,
267,
291,
14,
1730,
14,
22716,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
22716,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
1102,
8,
277,
304,
267,
291,
14,
1730,
14,
1102,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
1102,
14,
362,
63,
56,
401,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
1200,
8,
277,
304,
267,
291,
14,
1730,
14,
1200,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,
63,
20392,
14,
479,
63,
3527,
63,
5089,
63,
1045,
480,
1200,
14,
362,
63,
56,
401,
12740,
298,
1121,
531,
339,
347,
511,
63,
4998,
63,
1730,
63,
7546,
63,
525,
63,
2293,
8,
277,
304,
267,
291,
14,
1730,
14,
2293,
14,
362,
63,
56,
480,
1121,
531,
267,
291,
14,
1730,
14,
1250,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1,
1,
1,
1,
1
] |
BT-fgarbely/odoo
|
addons/product_visible_discount/__init__.py
|
433
|
1054
|
##############################################################################
#
# 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/>.
#
##############################################################################
import product_visible_discount
# 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,
646,
3336,
63,
6604,
63,
15446,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
646,
3336,
63,
6604,
63,
15446,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,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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
] |
jonnary/keystone
|
keystone/token/routers.py
|
34
|
2709
|
# Copyright 2012 OpenStack Foundation
#
# 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 keystone.common import wsgi
from keystone.token import controllers
class Router(wsgi.ComposableRouter):
def add_routes(self, mapper):
token_controller = controllers.Auth()
mapper.connect('/tokens',
controller=token_controller,
action='authenticate',
conditions=dict(method=['POST']))
mapper.connect('/tokens/revoked',
controller=token_controller,
action='revocation_list',
conditions=dict(method=['GET']))
mapper.connect('/tokens/{token_id}',
controller=token_controller,
action='validate_token',
conditions=dict(method=['GET']))
# NOTE(morganfainberg): For policy enforcement reasons, the
# ``validate_token_head`` method is still used for HEAD requests.
# The controller method makes the same call as the validate_token
# call and lets wsgi.render_response remove the body data.
mapper.connect('/tokens/{token_id}',
controller=token_controller,
action='validate_token_head',
conditions=dict(method=['HEAD']))
mapper.connect('/tokens/{token_id}',
controller=token_controller,
action='delete_token',
conditions=dict(method=['DELETE']))
mapper.connect('/tokens/{token_id}/endpoints',
controller=token_controller,
action='endpoints',
conditions=dict(method=['GET']))
# Certificates used to verify auth tokens
mapper.connect('/certificates/ca',
controller=token_controller,
action='ca_cert',
conditions=dict(method=['GET']))
mapper.connect('/certificates/signing',
controller=token_controller,
action='signing_cert',
conditions=dict(method=['GET']))
|
apache-2.0
|
[
3,
1898,
6029,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
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,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
504,
19395,
14,
2330,
492,
12464,
199,
504,
19395,
14,
1418,
492,
27325,
421,
199,
533,
22708,
8,
6508,
14,
2404,
736,
461,
11691,
304,
272,
347,
1050,
63,
13243,
8,
277,
12,
7796,
304,
267,
1526,
63,
5538,
275,
27325,
14,
2817,
342,
267,
7796,
14,
2242,
2336,
4504,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
13975,
297,
2432,
3704,
29,
807,
8,
765,
2968,
4030,
5156,
267,
7796,
14,
2242,
2336,
4504,
15,
4964,
7620,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
4964,
13364,
63,
513,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
7293,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
3502,
63,
1418,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
267,
327,
6944,
8,
77,
19916,
667,
262,
14630,
304,
2104,
4592,
15814,
434,
14872,
12,
314,
267,
327,
1124,
3502,
63,
1418,
63,
2993,
1040,
1083,
365,
5139,
1202,
367,
13053,
4145,
14,
267,
327,
710,
7614,
1083,
7704,
314,
2011,
1240,
465,
314,
4107,
63,
1418,
267,
327,
1240,
436,
19083,
12464,
14,
3352,
63,
1310,
2813,
314,
2396,
666,
14,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
7293,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
3502,
63,
1418,
63,
2993,
297,
2432,
3704,
29,
807,
8,
765,
2968,
5211,
5156,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
7293,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
1807,
63,
1418,
297,
2432,
3704,
29,
807,
8,
765,
2968,
7014,
5156,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
5995,
14461,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
14461,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
398,
327,
12904,
83,
1202,
370,
4911,
1790,
4645,
267,
7796,
14,
2242,
2336,
16159,
15,
696,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
696,
63,
4736,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
398,
7796,
14,
2242,
2336,
16159,
15,
23238,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
23238,
63,
4736,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
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
] |
[
1898,
6029,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
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,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
504,
19395,
14,
2330,
492,
12464,
199,
504,
19395,
14,
1418,
492,
27325,
421,
199,
533,
22708,
8,
6508,
14,
2404,
736,
461,
11691,
304,
272,
347,
1050,
63,
13243,
8,
277,
12,
7796,
304,
267,
1526,
63,
5538,
275,
27325,
14,
2817,
342,
267,
7796,
14,
2242,
2336,
4504,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
13975,
297,
2432,
3704,
29,
807,
8,
765,
2968,
4030,
5156,
267,
7796,
14,
2242,
2336,
4504,
15,
4964,
7620,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
4964,
13364,
63,
513,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
7293,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
3502,
63,
1418,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
267,
327,
6944,
8,
77,
19916,
667,
262,
14630,
304,
2104,
4592,
15814,
434,
14872,
12,
314,
267,
327,
1124,
3502,
63,
1418,
63,
2993,
1040,
1083,
365,
5139,
1202,
367,
13053,
4145,
14,
267,
327,
710,
7614,
1083,
7704,
314,
2011,
1240,
465,
314,
4107,
63,
1418,
267,
327,
1240,
436,
19083,
12464,
14,
3352,
63,
1310,
2813,
314,
2396,
666,
14,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
7293,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
3502,
63,
1418,
63,
2993,
297,
2432,
3704,
29,
807,
8,
765,
2968,
5211,
5156,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
7293,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
1807,
63,
1418,
297,
2432,
3704,
29,
807,
8,
765,
2968,
7014,
5156,
267,
7796,
14,
2242,
2336,
4504,
5321,
1418,
63,
344,
5995,
14461,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
14461,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
398,
327,
12904,
83,
1202,
370,
4911,
1790,
4645,
267,
7796,
14,
2242,
2336,
16159,
15,
696,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
696,
63,
4736,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
398,
7796,
14,
2242,
2336,
16159,
15,
23238,
297,
2432,
7614,
29,
1418,
63,
5538,
12,
2432,
1595,
534,
23238,
63,
4736,
297,
2432,
3704,
29,
807,
8,
765,
2968,
2970,
5156,
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,
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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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
] |
40223240/2015cdb_w17_test
|
static/Brython3.1.1-20150328-091302/Lib/test/re_tests.py
|
879
|
31796
|
#!/usr/bin/env python3
# -*- mode: python -*-
# Re test suite and benchmark suite v1.5
# The 3 possible outcomes for each pattern
[SUCCEED, FAIL, SYNTAX_ERROR] = range(3)
# Benchmark suite (needs expansion)
#
# The benchmark suite does not test correctness, just speed. The
# first element of each tuple is the regex pattern; the second is a
# string to match it against. The benchmarking code will embed the
# second string inside several sizes of padding, to test how regex
# matching performs on large strings.
benchmarks = [
# test common prefix
('Python|Perl', 'Perl'), # Alternation
('(Python|Perl)', 'Perl'), # Grouped alternation
('Python|Perl|Tcl', 'Perl'), # Alternation
('(Python|Perl|Tcl)', 'Perl'), # Grouped alternation
('(Python)\\1', 'PythonPython'), # Backreference
('([0a-z][a-z0-9]*,)+', 'a5,b7,c9,'), # Disable the fastmap optimization
('([a-z][a-z0-9]*,)+', 'a5,b7,c9,'), # A few sets
('Python', 'Python'), # Simple text literal
('.*Python', 'Python'), # Bad text literal
('.*Python.*', 'Python'), # Worse text literal
('.*(Python)', 'Python'), # Bad text literal with grouping
]
# Test suite (for verifying correctness)
#
# The test suite is a list of 5- or 3-tuples. The 5 parts of a
# complete tuple are:
# element 0: a string containing the pattern
# 1: the string to match against the pattern
# 2: the expected result (SUCCEED, FAIL, SYNTAX_ERROR)
# 3: a string that will be eval()'ed to produce a test string.
# This is an arbitrary Python expression; the available
# variables are "found" (the whole match), and "g1", "g2", ...
# up to "g99" contain the contents of each group, or the
# string 'None' if the group wasn't given a value, or the
# string 'Error' if the group index was out of range;
# also "groups", the return value of m.group() (a tuple).
# 4: The expected result of evaluating the expression.
# If the two don't match, an error is reported.
#
# If the regex isn't expected to work, the latter two elements can be omitted.
tests = [
# Test ?P< and ?P= extensions
('(?P<foo_123', '', SYNTAX_ERROR), # Unterminated group identifier
('(?P<1>a)', '', SYNTAX_ERROR), # Begins with a digit
('(?P<!>a)', '', SYNTAX_ERROR), # Begins with an illegal char
('(?P<foo!>a)', '', SYNTAX_ERROR), # Begins with an illegal char
# Same tests, for the ?P= form
('(?P<foo_123>a)(?P=foo_123', 'aa', SYNTAX_ERROR),
('(?P<foo_123>a)(?P=1)', 'aa', SYNTAX_ERROR),
('(?P<foo_123>a)(?P=!)', 'aa', SYNTAX_ERROR),
('(?P<foo_123>a)(?P=foo_124', 'aa', SYNTAX_ERROR), # Backref to undefined group
('(?P<foo_123>a)', 'a', SUCCEED, 'g1', 'a'),
('(?P<foo_123>a)(?P=foo_123)', 'aa', SUCCEED, 'g1', 'a'),
# Test octal escapes
('\\1', 'a', SYNTAX_ERROR), # Backreference
('[\\1]', '\1', SUCCEED, 'found', '\1'), # Character
('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'),
('\\141', 'a', SUCCEED, 'found', 'a'),
('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'),
# Test \0 is handled everywhere
(r'\0', '\0', SUCCEED, 'found', '\0'),
(r'[\0a]', '\0', SUCCEED, 'found', '\0'),
(r'[a\0]', '\0', SUCCEED, 'found', '\0'),
(r'[^a\0]', '\0', FAIL),
# Test various letter escapes
(r'\a[\b]\f\n\r\t\v', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'),
(r'[\a][\b][\f][\n][\r][\t][\v]', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'),
# NOTE: not an error under PCRE/PRE:
# (r'\u', '', SYNTAX_ERROR), # A Perl escape
(r'\c\e\g\h\i\j\k\m\o\p\q\y\z', 'ceghijkmopqyz', SUCCEED, 'found', 'ceghijkmopqyz'),
(r'\xff', '\377', SUCCEED, 'found', chr(255)),
# new \x semantics
(r'\x00ffffffffffffff', '\377', FAIL, 'found', chr(255)),
(r'\x00f', '\017', FAIL, 'found', chr(15)),
(r'\x00fe', '\376', FAIL, 'found', chr(254)),
# (r'\x00ffffffffffffff', '\377', SUCCEED, 'found', chr(255)),
# (r'\x00f', '\017', SUCCEED, 'found', chr(15)),
# (r'\x00fe', '\376', SUCCEED, 'found', chr(254)),
(r"^\w+=(\\[\000-\277]|[^\n\\])*", "SRC=eval.c g.c blah blah blah \\\\\n\tapes.c",
SUCCEED, 'found', "SRC=eval.c g.c blah blah blah \\\\"),
# Test that . only matches \n in DOTALL mode
('a.b', 'acb', SUCCEED, 'found', 'acb'),
('a.b', 'a\nb', FAIL),
('a.*b', 'acc\nccb', FAIL),
('a.{4,5}b', 'acc\nccb', FAIL),
('a.b', 'a\rb', SUCCEED, 'found', 'a\rb'),
('a.b(?s)', 'a\nb', SUCCEED, 'found', 'a\nb'),
('a.*(?s)b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),
('(?s)a.{4,5}b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),
('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'),
(')', '', SYNTAX_ERROR), # Unmatched right bracket
('', '', SUCCEED, 'found', ''), # Empty pattern
('abc', 'abc', SUCCEED, 'found', 'abc'),
('abc', 'xbc', FAIL),
('abc', 'axc', FAIL),
('abc', 'abx', FAIL),
('abc', 'xabcy', SUCCEED, 'found', 'abc'),
('abc', 'ababc', SUCCEED, 'found', 'abc'),
('ab*c', 'abc', SUCCEED, 'found', 'abc'),
('ab*bc', 'abc', SUCCEED, 'found', 'abc'),
('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'),
('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'),
('ab+bc', 'abc', FAIL),
('ab+bc', 'abq', FAIL),
('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'),
('ab?bc', 'abc', SUCCEED, 'found', 'abc'),
('ab?bc', 'abbbbc', FAIL),
('ab?c', 'abc', SUCCEED, 'found', 'abc'),
('^abc$', 'abc', SUCCEED, 'found', 'abc'),
('^abc$', 'abcc', FAIL),
('^abc', 'abcc', SUCCEED, 'found', 'abc'),
('^abc$', 'aabc', FAIL),
('abc$', 'aabc', SUCCEED, 'found', 'abc'),
('^', 'abc', SUCCEED, 'found+"-"', '-'),
('$', 'abc', SUCCEED, 'found+"-"', '-'),
('a.c', 'abc', SUCCEED, 'found', 'abc'),
('a.c', 'axc', SUCCEED, 'found', 'axc'),
('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'),
('a.*c', 'axyzd', FAIL),
('a[bc]d', 'abc', FAIL),
('a[bc]d', 'abd', SUCCEED, 'found', 'abd'),
('a[b-d]e', 'abd', FAIL),
('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'),
('a[b-d]', 'aac', SUCCEED, 'found', 'ac'),
('a[-b]', 'a-', SUCCEED, 'found', 'a-'),
('a[\\-b]', 'a-', SUCCEED, 'found', 'a-'),
# NOTE: not an error under PCRE/PRE:
# ('a[b-]', 'a-', SYNTAX_ERROR),
('a[]b', '-', SYNTAX_ERROR),
('a[', '-', SYNTAX_ERROR),
('a\\', '-', SYNTAX_ERROR),
('abc)', '-', SYNTAX_ERROR),
('(abc', '-', SYNTAX_ERROR),
('a]', 'a]', SUCCEED, 'found', 'a]'),
('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),
('a[\]]b', 'a]b', SUCCEED, 'found', 'a]b'),
('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),
('a[^bc]d', 'abd', FAIL),
('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),
('a[^-b]c', 'a-c', FAIL),
('a[^]b]c', 'a]c', FAIL),
('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'),
('\\ba\\b', 'a-', SUCCEED, '"-"', '-'),
('\\ba\\b', '-a', SUCCEED, '"-"', '-'),
('\\ba\\b', '-a-', SUCCEED, '"-"', '-'),
('\\by\\b', 'xy', FAIL),
('\\by\\b', 'yz', FAIL),
('\\by\\b', 'xyz', FAIL),
('x\\b', 'xyz', FAIL),
('x\\B', 'xyz', SUCCEED, '"-"', '-'),
('\\Bz', 'xyz', SUCCEED, '"-"', '-'),
('z\\B', 'xyz', FAIL),
('\\Bx', 'xyz', FAIL),
('\\Ba\\B', 'a-', FAIL, '"-"', '-'),
('\\Ba\\B', '-a', FAIL, '"-"', '-'),
('\\Ba\\B', '-a-', FAIL, '"-"', '-'),
('\\By\\B', 'xy', FAIL),
('\\By\\B', 'yz', FAIL),
('\\By\\b', 'xy', SUCCEED, '"-"', '-'),
('\\by\\B', 'yz', SUCCEED, '"-"', '-'),
('\\By\\B', 'xyz', SUCCEED, '"-"', '-'),
('ab|cd', 'abc', SUCCEED, 'found', 'ab'),
('ab|cd', 'abcd', SUCCEED, 'found', 'ab'),
('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'),
('$b', 'b', FAIL),
('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'),
('a\\(*b', 'ab', SUCCEED, 'found', 'ab'),
('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'),
('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'),
('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'),
('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'),
('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'),
('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),
('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),
('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'),
(')(', '-', SYNTAX_ERROR),
('[^ab]*', 'cde', SUCCEED, 'found', 'cde'),
('abc', '', FAIL),
('a*', '', SUCCEED, 'found', ''),
('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'),
('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'),
('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'),
('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'),
('ab*', 'xayabbbz', SUCCEED, 'found', 'a'),
('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'),
('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'),
('^(ab|cd)e', 'abcde', FAIL, 'xg1y', 'xy'),
('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'),
('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'),
('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'),
('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'),
('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'),
('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'),
('a[bcd]+dcdcde', 'adcdcde', FAIL),
('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'),
('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'),
('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'),
('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'),
('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'),
('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL),
('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL),
('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'),
('multiple words of text', 'uh-uh', FAIL),
('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'),
('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'),
('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'),
('[k]', 'ab', FAIL),
('a[-]?c', 'ac', SUCCEED, 'found', 'ac'),
('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),
('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),
('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'),
('(a+).\\1$', 'aaaaa', SUCCEED, 'found+"-"+g1', 'aaaaa-aa'),
('^(a+).\\1$', 'aaaa', FAIL),
('(abc)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'),
('([a-c]+)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'),
('(a)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'),
('(a+)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'),
('(a+)+\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'),
('(a).+\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'),
('(a)ba*\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'),
('(aa|a)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'),
('(a|aa)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'),
('(a+)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'),
('([abc]*)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'),
('(a)(b)c|ab', 'ab', SUCCEED, 'found+"-"+g1+"-"+g2', 'ab-None-None'),
('(a)+x', 'aaax', SUCCEED, 'found+"-"+g1', 'aaax-a'),
('([ac])+x', 'aacx', SUCCEED, 'found+"-"+g1', 'aacx-c'),
('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', SUCCEED, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/'),
('([^.]*)\\.([^:]*):[T ]+(.*)', 'track1.title:TBlah blah blah', SUCCEED, 'found+"-"+g1+"-"+g2+"-"+g3', 'track1.title:TBlah blah blah-track1-title-Blah blah blah'),
('([^N]*N)+', 'abNNxyzN', SUCCEED, 'found+"-"+g1', 'abNNxyzN-xyzN'),
('([^N]*N)+', 'abNNxyz', SUCCEED, 'found+"-"+g1', 'abNN-N'),
('([abc]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'abcx-abc'),
('([abc]*)x', 'abc', FAIL),
('([xyz]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'x-'),
('(a)+b|aac', 'aac', SUCCEED, 'found+"-"+g1', 'aac-None'),
# Test symbolic groups
('(?P<i d>aaa)a', 'aaaa', SYNTAX_ERROR),
('(?P<id>aaa)a', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aaa'),
('(?P<id>aa)(?P=id)', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aa'),
('(?P<id>aa)(?P=xd)', 'aaaa', SYNTAX_ERROR),
# Test octal escapes/memory references
('\\1', 'a', SYNTAX_ERROR),
('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'),
('\\141', 'a', SUCCEED, 'found', 'a'),
('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'),
# All tests from Perl
('abc', 'abc', SUCCEED, 'found', 'abc'),
('abc', 'xbc', FAIL),
('abc', 'axc', FAIL),
('abc', 'abx', FAIL),
('abc', 'xabcy', SUCCEED, 'found', 'abc'),
('abc', 'ababc', SUCCEED, 'found', 'abc'),
('ab*c', 'abc', SUCCEED, 'found', 'abc'),
('ab*bc', 'abc', SUCCEED, 'found', 'abc'),
('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'),
('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab{0,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'),
('ab+bc', 'abc', FAIL),
('ab+bc', 'abq', FAIL),
('ab{1,}bc', 'abq', FAIL),
('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab{1,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab{1,3}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab{3,4}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),
('ab{4,5}bc', 'abbbbc', FAIL),
('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'),
('ab?bc', 'abc', SUCCEED, 'found', 'abc'),
('ab{0,1}bc', 'abc', SUCCEED, 'found', 'abc'),
('ab?bc', 'abbbbc', FAIL),
('ab?c', 'abc', SUCCEED, 'found', 'abc'),
('ab{0,1}c', 'abc', SUCCEED, 'found', 'abc'),
('^abc$', 'abc', SUCCEED, 'found', 'abc'),
('^abc$', 'abcc', FAIL),
('^abc', 'abcc', SUCCEED, 'found', 'abc'),
('^abc$', 'aabc', FAIL),
('abc$', 'aabc', SUCCEED, 'found', 'abc'),
('^', 'abc', SUCCEED, 'found', ''),
('$', 'abc', SUCCEED, 'found', ''),
('a.c', 'abc', SUCCEED, 'found', 'abc'),
('a.c', 'axc', SUCCEED, 'found', 'axc'),
('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'),
('a.*c', 'axyzd', FAIL),
('a[bc]d', 'abc', FAIL),
('a[bc]d', 'abd', SUCCEED, 'found', 'abd'),
('a[b-d]e', 'abd', FAIL),
('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'),
('a[b-d]', 'aac', SUCCEED, 'found', 'ac'),
('a[-b]', 'a-', SUCCEED, 'found', 'a-'),
('a[b-]', 'a-', SUCCEED, 'found', 'a-'),
('a[b-a]', '-', SYNTAX_ERROR),
('a[]b', '-', SYNTAX_ERROR),
('a[', '-', SYNTAX_ERROR),
('a]', 'a]', SUCCEED, 'found', 'a]'),
('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),
('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),
('a[^bc]d', 'abd', FAIL),
('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),
('a[^-b]c', 'a-c', FAIL),
('a[^]b]c', 'a]c', FAIL),
('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'),
('ab|cd', 'abc', SUCCEED, 'found', 'ab'),
('ab|cd', 'abcd', SUCCEED, 'found', 'ab'),
('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'),
('*a', '-', SYNTAX_ERROR),
('(*)b', '-', SYNTAX_ERROR),
('$b', 'b', FAIL),
('a\\', '-', SYNTAX_ERROR),
('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'),
('a\\(*b', 'ab', SUCCEED, 'found', 'ab'),
('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'),
('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'),
('abc)', '-', SYNTAX_ERROR),
('(abc', '-', SYNTAX_ERROR),
('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'),
('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'),
('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'),
('a{1,}b{1,}c', 'aabbabc', SUCCEED, 'found', 'abc'),
('a**', '-', SYNTAX_ERROR),
('a.+?c', 'abcabc', SUCCEED, 'found', 'abc'),
('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),
('(a+|b){0,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),
('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),
('(a+|b){1,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),
('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'),
('(a+|b){0,1}', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'),
(')(', '-', SYNTAX_ERROR),
('[^ab]*', 'cde', SUCCEED, 'found', 'cde'),
('abc', '', FAIL),
('a*', '', SUCCEED, 'found', ''),
('([abc])*d', 'abbbcd', SUCCEED, 'found+"-"+g1', 'abbbcd-c'),
('([abc])*bcd', 'abcd', SUCCEED, 'found+"-"+g1', 'abcd-a'),
('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'),
('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'),
('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'),
('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'),
('ab*', 'xayabbbz', SUCCEED, 'found', 'a'),
('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'),
('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'),
('^(ab|cd)e', 'abcde', FAIL),
('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'),
('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'),
('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'),
('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'),
('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),
('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'),
('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'),
('a[bcd]+dcdcde', 'adcdcde', FAIL),
('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'),
('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'),
('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'),
('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'),
('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'),
('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL),
('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL),
('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),
('((((((((((a))))))))))', 'a', SUCCEED, 'g10', 'a'),
('((((((((((a))))))))))\\10', 'aa', SUCCEED, 'found', 'aa'),
# Python does not have the same rules for \\41 so this is a syntax error
# ('((((((((((a))))))))))\\41', 'aa', FAIL),
# ('((((((((((a))))))))))\\41', 'a!', SUCCEED, 'found', 'a!'),
('((((((((((a))))))))))\\41', '', SYNTAX_ERROR),
('(?i)((((((((((a))))))))))\\41', '', SYNTAX_ERROR),
('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'),
('multiple words of text', 'uh-uh', FAIL),
('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'),
('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'),
('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'),
('[k]', 'ab', FAIL),
('a[-]?c', 'ac', SUCCEED, 'found', 'ac'),
('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),
('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),
('(?i)abc', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)abc', 'XBC', FAIL),
('(?i)abc', 'AXC', FAIL),
('(?i)abc', 'ABX', FAIL),
('(?i)abc', 'XABCY', SUCCEED, 'found', 'ABC'),
('(?i)abc', 'ABABC', SUCCEED, 'found', 'ABC'),
('(?i)ab*c', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)ab*bc', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)ab*bc', 'ABBC', SUCCEED, 'found', 'ABBC'),
('(?i)ab*?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),
('(?i)ab{0,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),
('(?i)ab+?bc', 'ABBC', SUCCEED, 'found', 'ABBC'),
('(?i)ab+bc', 'ABC', FAIL),
('(?i)ab+bc', 'ABQ', FAIL),
('(?i)ab{1,}bc', 'ABQ', FAIL),
('(?i)ab+bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),
('(?i)ab{1,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),
('(?i)ab{1,3}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),
('(?i)ab{3,4}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),
('(?i)ab{4,5}?bc', 'ABBBBC', FAIL),
('(?i)ab??bc', 'ABBC', SUCCEED, 'found', 'ABBC'),
('(?i)ab??bc', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)ab{0,1}?bc', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)ab??bc', 'ABBBBC', FAIL),
('(?i)ab??c', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)ab{0,1}?c', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)^abc$', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)^abc$', 'ABCC', FAIL),
('(?i)^abc', 'ABCC', SUCCEED, 'found', 'ABC'),
('(?i)^abc$', 'AABC', FAIL),
('(?i)abc$', 'AABC', SUCCEED, 'found', 'ABC'),
('(?i)^', 'ABC', SUCCEED, 'found', ''),
('(?i)$', 'ABC', SUCCEED, 'found', ''),
('(?i)a.c', 'ABC', SUCCEED, 'found', 'ABC'),
('(?i)a.c', 'AXC', SUCCEED, 'found', 'AXC'),
('(?i)a.*?c', 'AXYZC', SUCCEED, 'found', 'AXYZC'),
('(?i)a.*c', 'AXYZD', FAIL),
('(?i)a[bc]d', 'ABC', FAIL),
('(?i)a[bc]d', 'ABD', SUCCEED, 'found', 'ABD'),
('(?i)a[b-d]e', 'ABD', FAIL),
('(?i)a[b-d]e', 'ACE', SUCCEED, 'found', 'ACE'),
('(?i)a[b-d]', 'AAC', SUCCEED, 'found', 'AC'),
('(?i)a[-b]', 'A-', SUCCEED, 'found', 'A-'),
('(?i)a[b-]', 'A-', SUCCEED, 'found', 'A-'),
('(?i)a[b-a]', '-', SYNTAX_ERROR),
('(?i)a[]b', '-', SYNTAX_ERROR),
('(?i)a[', '-', SYNTAX_ERROR),
('(?i)a]', 'A]', SUCCEED, 'found', 'A]'),
('(?i)a[]]b', 'A]B', SUCCEED, 'found', 'A]B'),
('(?i)a[^bc]d', 'AED', SUCCEED, 'found', 'AED'),
('(?i)a[^bc]d', 'ABD', FAIL),
('(?i)a[^-b]c', 'ADC', SUCCEED, 'found', 'ADC'),
('(?i)a[^-b]c', 'A-C', FAIL),
('(?i)a[^]b]c', 'A]C', FAIL),
('(?i)a[^]b]c', 'ADC', SUCCEED, 'found', 'ADC'),
('(?i)ab|cd', 'ABC', SUCCEED, 'found', 'AB'),
('(?i)ab|cd', 'ABCD', SUCCEED, 'found', 'AB'),
('(?i)()ef', 'DEF', SUCCEED, 'found+"-"+g1', 'EF-'),
('(?i)*a', '-', SYNTAX_ERROR),
('(?i)(*)b', '-', SYNTAX_ERROR),
('(?i)$b', 'B', FAIL),
('(?i)a\\', '-', SYNTAX_ERROR),
('(?i)a\\(b', 'A(B', SUCCEED, 'found+"-"+g1', 'A(B-Error'),
('(?i)a\\(*b', 'AB', SUCCEED, 'found', 'AB'),
('(?i)a\\(*b', 'A((B', SUCCEED, 'found', 'A((B'),
('(?i)a\\\\b', 'A\\B', SUCCEED, 'found', 'A\\B'),
('(?i)abc)', '-', SYNTAX_ERROR),
('(?i)(abc', '-', SYNTAX_ERROR),
('(?i)((a))', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'A-A-A'),
('(?i)(a)b(c)', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABC-A-C'),
('(?i)a+b+c', 'AABBABC', SUCCEED, 'found', 'ABC'),
('(?i)a{1,}b{1,}c', 'AABBABC', SUCCEED, 'found', 'ABC'),
('(?i)a**', '-', SYNTAX_ERROR),
('(?i)a.+?c', 'ABCABC', SUCCEED, 'found', 'ABC'),
('(?i)a.*?c', 'ABCABC', SUCCEED, 'found', 'ABC'),
('(?i)a.{0,5}?c', 'ABCABC', SUCCEED, 'found', 'ABC'),
('(?i)(a+|b)*', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),
('(?i)(a+|b){0,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),
('(?i)(a+|b)+', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),
('(?i)(a+|b){1,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),
('(?i)(a+|b)?', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'),
('(?i)(a+|b){0,1}', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'),
('(?i)(a+|b){0,1}?', 'AB', SUCCEED, 'found+"-"+g1', '-None'),
('(?i))(', '-', SYNTAX_ERROR),
('(?i)[^ab]*', 'CDE', SUCCEED, 'found', 'CDE'),
('(?i)abc', '', FAIL),
('(?i)a*', '', SUCCEED, 'found', ''),
('(?i)([abc])*d', 'ABBBCD', SUCCEED, 'found+"-"+g1', 'ABBBCD-C'),
('(?i)([abc])*bcd', 'ABCD', SUCCEED, 'found+"-"+g1', 'ABCD-A'),
('(?i)a|b|c|d|e', 'E', SUCCEED, 'found', 'E'),
('(?i)(a|b|c|d|e)f', 'EF', SUCCEED, 'found+"-"+g1', 'EF-E'),
('(?i)abcd*efg', 'ABCDEFG', SUCCEED, 'found', 'ABCDEFG'),
('(?i)ab*', 'XABYABBBZ', SUCCEED, 'found', 'AB'),
('(?i)ab*', 'XAYABBBZ', SUCCEED, 'found', 'A'),
('(?i)(ab|cd)e', 'ABCDE', SUCCEED, 'found+"-"+g1', 'CDE-CD'),
('(?i)[abhgefdc]ij', 'HIJ', SUCCEED, 'found', 'HIJ'),
('(?i)^(ab|cd)e', 'ABCDE', FAIL),
('(?i)(abc|)ef', 'ABCDEF', SUCCEED, 'found+"-"+g1', 'EF-'),
('(?i)(a|b)c*d', 'ABCD', SUCCEED, 'found+"-"+g1', 'BCD-B'),
('(?i)(ab|ab*)bc', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-A'),
('(?i)a([bc]*)c*', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-BC'),
('(?i)a([bc]*)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'),
('(?i)a([bc]+)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'),
('(?i)a([bc]*)(c+d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-B-CD'),
('(?i)a[bcd]*dcdcde', 'ADCDCDE', SUCCEED, 'found', 'ADCDCDE'),
('(?i)a[bcd]+dcdcde', 'ADCDCDE', FAIL),
('(?i)(ab|a)b*c', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-AB'),
('(?i)((a)(b)c)(d)', 'ABCD', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'ABC-A-B-D'),
('(?i)[a-zA-Z_][a-zA-Z0-9_]*', 'ALPHA', SUCCEED, 'found', 'ALPHA'),
('(?i)^a(bc+|b[eh])g|.h$', 'ABH', SUCCEED, 'found+"-"+g1', 'BH-None'),
('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'),
('(?i)(bc+d$|ef*g.|h?i(j|k))', 'IJ', SUCCEED, 'found+"-"+g1+"-"+g2', 'IJ-IJ-J'),
('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFG', FAIL),
('(?i)(bc+d$|ef*g.|h?i(j|k))', 'BCDD', FAIL),
('(?i)(bc+d$|ef*g.|h?i(j|k))', 'REFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'),
('(?i)((((((((((a))))))))))', 'A', SUCCEED, 'g10', 'A'),
('(?i)((((((((((a))))))))))\\10', 'AA', SUCCEED, 'found', 'AA'),
#('(?i)((((((((((a))))))))))\\41', 'AA', FAIL),
#('(?i)((((((((((a))))))))))\\41', 'A!', SUCCEED, 'found', 'A!'),
('(?i)(((((((((a)))))))))', 'A', SUCCEED, 'found', 'A'),
('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))', 'A', SUCCEED, 'g1', 'A'),
('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))', 'C', SUCCEED, 'g1', 'C'),
('(?i)multiple words of text', 'UH-UH', FAIL),
('(?i)multiple words', 'MULTIPLE WORDS, YEAH', SUCCEED, 'found', 'MULTIPLE WORDS'),
('(?i)(.*)c(.*)', 'ABCDE', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCDE-AB-DE'),
('(?i)\\((.*), (.*)\\)', '(A, B)', SUCCEED, 'g2+"-"+g1', 'B-A'),
('(?i)[k]', 'AB', FAIL),
# ('(?i)abcd', 'ABCD', SUCCEED, 'found+"-"+\\found+"-"+\\\\found', 'ABCD-$&-\\ABCD'),
# ('(?i)a(bc)d', 'ABCD', SUCCEED, 'g1+"-"+\\g1+"-"+\\\\g1', 'BC-$1-\\BC'),
('(?i)a[-]?c', 'AC', SUCCEED, 'found', 'AC'),
('(?i)(abc)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'),
('(?i)([a-c]*)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'),
('a(?!b).', 'abad', SUCCEED, 'found', 'ad'),
('a(?=d).', 'abad', SUCCEED, 'found', 'ad'),
('a(?=c|d).', 'abad', SUCCEED, 'found', 'ad'),
('a(?:b|c|d)(.)', 'ace', SUCCEED, 'g1', 'e'),
('a(?:b|c|d)*(.)', 'ace', SUCCEED, 'g1', 'e'),
('a(?:b|c|d)+?(.)', 'ace', SUCCEED, 'g1', 'e'),
('a(?:b|(c|e){1,2}?|d)+?(.)', 'ace', SUCCEED, 'g1 + g2', 'ce'),
('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'),
# lookbehind: split by : but not if it is escaped by -.
('(?<!-):(.*?)(?<!-):', 'a:bc-:de:f', SUCCEED, 'g1', 'bc-:de' ),
# escaping with \ as we know it
('(?<!\\\):(.*?)(?<!\\\):', 'a:bc\\:de:f', SUCCEED, 'g1', 'bc\\:de' ),
# terminating with ' and escaping with ? as in edifact
("(?<!\\?)'(.*?)(?<!\\?)'", "a'bc?'de'f", SUCCEED, 'g1', "bc?'de" ),
# Comments using the (?#...) syntax
('w(?# comment', 'w', SYNTAX_ERROR),
('w(?# comment 1)xy(?# comment 2)z', 'wxyz', SUCCEED, 'found', 'wxyz'),
# Check odd placement of embedded pattern modifiers
# not an error under PCRE/PRE:
('w(?i)', 'W', SUCCEED, 'found', 'W'),
# ('w(?i)', 'W', SYNTAX_ERROR),
# Comments using the x embedded pattern modifier
("""(?x)w# comment 1
x y
# comment 2
z""", 'wxyz', SUCCEED, 'found', 'wxyz'),
# using the m embedded pattern modifier
('^abc', """jkl
abc
xyz""", FAIL),
('(?m)^abc', """jkl
abc
xyz""", SUCCEED, 'found', 'abc'),
('(?m)abc$', """jkl
xyzabc
123""", SUCCEED, 'found', 'abc'),
# using the s embedded pattern modifier
('a.b', 'a\nb', FAIL),
('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'),
# test \w, etc. both inside and outside character classes
('\\w+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'),
('[\\w]+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'),
('\\D+', '1234abc5678', SUCCEED, 'found', 'abc'),
('[\\D]+', '1234abc5678', SUCCEED, 'found', 'abc'),
('[\\da-fA-F]+', '123abc', SUCCEED, 'found', '123abc'),
# not an error under PCRE/PRE:
# ('[\\d-x]', '-', SYNTAX_ERROR),
(r'([\s]*)([\S]*)([\s]*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '),
(r'(\s*)(\S*)(\s*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '),
(r'\xff', '\377', SUCCEED, 'found', chr(255)),
# new \x semantics
(r'\x00ff', '\377', FAIL),
# (r'\x00ff', '\377', SUCCEED, 'found', chr(255)),
(r'\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'),
('\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'),
(r'\t\n\v\r\f\a', '\t\n\v\r\f\a', SUCCEED, 'found', chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)),
(r'[\t][\n][\v][\r][\f][\b]', '\t\n\v\r\f\b', SUCCEED, 'found', '\t\n\v\r\f\b'),
#
# post-1.5.2 additions
# xmllib problem
(r'(([a-z]+):)?([a-z]+)$', 'smil', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-smil'),
# bug 110866: reference to undefined group
(r'((.)\1+)', '', SYNTAX_ERROR),
# bug 111869: search (PRE/PCRE fails on this one, SRE doesn't)
(r'.*d', 'abc\nabd', SUCCEED, 'found', 'abd'),
# bug 112468: various expected syntax errors
(r'(', '', SYNTAX_ERROR),
(r'[\41]', '!', SUCCEED, 'found', '!'),
# bug 114033: nothing to repeat
(r'(x?)?', 'x', SUCCEED, 'found', 'x'),
# bug 115040: rescan if flags are modified inside pattern
(r' (?x)foo ', 'foo', SUCCEED, 'found', 'foo'),
# bug 115618: negative lookahead
(r'(?<!abc)(d.f)', 'abcdefdof', SUCCEED, 'found', 'dof'),
# bug 116251: character class bug
(r'[\w-]+', 'laser_beam', SUCCEED, 'found', 'laser_beam'),
# bug 123769+127259: non-greedy backtracking bug
(r'.*?\S *:', 'xx:', SUCCEED, 'found', 'xx:'),
(r'a[ ]*?\ (\d+).*', 'a 10', SUCCEED, 'found', 'a 10'),
(r'a[ ]*?\ (\d+).*', 'a 10', SUCCEED, 'found', 'a 10'),
# bug 127259: \Z shouldn't depend on multiline mode
(r'(?ms).*?x\s*\Z(.*)','xx\nx\n', SUCCEED, 'g1', ''),
# bug 128899: uppercase literals under the ignorecase flag
(r'(?i)M+', 'MMM', SUCCEED, 'found', 'MMM'),
(r'(?i)m+', 'MMM', SUCCEED, 'found', 'MMM'),
(r'(?i)[M]+', 'MMM', SUCCEED, 'found', 'MMM'),
(r'(?i)[m]+', 'MMM', SUCCEED, 'found', 'MMM'),
# bug 130748: ^* should be an error (nothing to repeat)
(r'^*', '', SYNTAX_ERROR),
# bug 133283: minimizing repeat problem
(r'"(?:\\"|[^"])*?"', r'"\""', SUCCEED, 'found', r'"\""'),
# bug 477728: minimizing repeat problem
(r'^.*?$', 'one\ntwo\nthree\n', FAIL),
# bug 483789: minimizing repeat problem
(r'a[^>]*?b', 'a>b', FAIL),
# bug 490573: minimizing repeat problem
(r'^a*?$', 'foo', FAIL),
# bug 470582: nested groups problem
(r'^((a)c)?(ab)$', 'ab', SUCCEED, 'g1+"-"+g2+"-"+g3', 'None-None-ab'),
# another minimizing repeat problem (capturing groups in assertions)
('^([ab]*?)(?=(b)?)c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'),
('^([ab]*?)(?!(b))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'),
('^([ab]*?)(?<!(a))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'),
]
u = '\N{LATIN CAPITAL LETTER A WITH DIAERESIS}'
tests.extend([
# bug 410271: \b broken under locales
(r'\b.\b', 'a', SUCCEED, 'found', 'a'),
(r'(?u)\b.\b', u, SUCCEED, 'found', u),
(r'(?u)\w', u, SUCCEED, 'found', u),
])
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
818,
26,
2366,
1882,
199,
199,
3,
799,
511,
5241,
436,
12338,
5241,
373,
17,
14,
21,
199,
199,
3,
710,
650,
3962,
15955,
83,
367,
1924,
3851,
199,
59,
6195,
8890,
12,
10341,
12,
25486,
63,
3170,
61,
275,
1425,
8,
19,
9,
199,
199,
3,
27067,
5241,
334,
10065,
14819,
9,
199,
3,
199,
3,
710,
12338,
5241,
1630,
440,
511,
29102,
12,
2951,
8112,
14,
221,
710,
199,
3,
1642,
1819,
402,
1924,
2008,
365,
314,
5163,
3851,
27,
314,
3499,
365,
282,
199,
3,
1059,
370,
1336,
652,
6169,
14,
221,
710,
12338,
316,
1233,
911,
6441,
314,
199,
3,
3499,
1059,
6272,
9978,
10627,
402,
6273,
12,
370,
511,
4212,
5163,
199,
3,
4877,
18628,
641,
7031,
3326,
14,
199,
199,
11861,
83,
275,
359,
339,
327,
511,
2863,
2403,
272,
661,
4718,
92,
2623,
76,
297,
283,
2623,
76,
659,
259,
327,
17669,
425,
272,
23845,
4718,
92,
2623,
76,
3196,
283,
2623,
76,
659,
221,
327,
598,
11330,
8679,
425,
339,
661,
4718,
92,
2623,
76,
92,
29175,
297,
283,
2623,
76,
659,
263,
327,
17669,
425,
272,
23845,
4718,
92,
2623,
76,
92,
29175,
3196,
283,
2623,
76,
659,
420,
327,
598,
11330,
8679,
425,
339,
23845,
4718,
22532,
17,
297,
283,
4718,
4718,
659,
259,
327,
10257,
4443,
272,
661,
779,
16,
65,
13,
90,
1527,
65,
13,
90,
16,
13,
25,
3672,
4258,
7386,
283,
65,
21,
12,
66,
23,
12,
67,
25,
12,
659,
327,
17534,
314,
7377,
1130,
13712,
272,
661,
779,
65,
13,
90,
1527,
65,
13,
90,
16,
13,
25,
3672,
4258,
7386,
283,
65,
21,
12,
66,
23,
12,
67,
25,
12,
659,
327,
437,
9284,
5951,
339,
661,
4718,
297,
283,
4718,
659,
5185,
327,
5870,
1318,
8785,
272,
661,
2795,
4718,
297,
283,
4718,
659,
3777,
327,
8857,
1318,
8785,
272,
661,
2795,
4718,
16110,
283,
4718,
659,
3698,
327,
644,
9050,
1318,
8785,
272,
661,
2795,
8,
4718,
3196,
283,
4718,
659,
3698,
327,
8857,
1318,
8785,
543,
17786,
199,
199,
61,
199,
199,
3,
1379,
5241,
334,
509,
31866,
29102,
9,
199,
3,
199,
3,
710,
511,
5241,
365,
282,
769,
402,
959,
13,
503,
650,
13,
11760,
14,
221,
710,
959,
4184,
402,
282,
199,
3,
4890,
2008,
787,
26,
199,
3,
1819,
378,
26,
282,
1059,
3035,
314,
3851,
199,
3,
260,
413,
26,
314,
1059,
370,
1336,
6169,
314,
3851,
199,
3,
260,
499,
26,
314,
1420,
754,
334,
6195,
8890,
12,
10341,
12,
25486,
63,
3170,
9,
199,
3,
260,
650,
26,
282,
1059,
626,
911,
506,
3468,
11716,
379,
370,
7389,
282,
511,
1059,
14,
199,
3,
3322,
961,
365,
376,
9697,
2018,
3965,
27,
314,
2808,
199,
3,
3322,
2860,
787,
298,
4214,
2,
334,
1589,
8852,
1336,
395,
436,
298,
71,
17,
401,
298,
71,
18,
401,
2263,
199,
3,
3322,
1536,
370,
298,
71,
1020,
2,
1395,
314,
4072,
402,
1924,
1572,
12,
503,
314,
199,
3,
3322,
1059,
283,
403,
7,
340,
314,
1572,
17373,
1133,
1627,
282,
574,
12,
503,
314,
199,
3,
3322,
1059,
283,
547,
7,
340,
314,
1572,
1478,
1990,
734,
402,
1425,
27,
199,
3,
3322,
2597,
298,
2634,
401,
314,
372,
574,
402,
333,
14,
923,
342,
334,
65,
2008,
680,
199,
3,
260,
841,
26,
710,
1420,
754,
402,
27083,
314,
3965,
14,
199,
3,
3322,
982,
314,
2877,
2793,
1133,
1336,
12,
376,
1125,
365,
14581,
14,
199,
3,
199,
3,
982,
314,
5163,
5712,
1133,
1420,
370,
1736,
12,
314,
19045,
2877,
4008,
883,
506,
11684,
14,
199,
199,
2219,
275,
359,
272,
327,
1379,
5805,
48,
28,
436,
5805,
48,
29,
5478,
272,
15950,
48,
28,
1421,
63,
4288,
297,
3260,
25486,
63,
3170,
395,
420,
327,
1910,
18375,
1572,
5148,
272,
15950,
48,
28,
17,
30,
65,
3196,
3260,
25486,
63,
3170,
395,
260,
327,
25754,
83,
543,
282,
10964,
272,
15950,
48,
11230,
30,
65,
3196,
3260,
25486,
63,
3170,
395,
260,
327,
25754,
83,
543,
376,
20282,
1495,
272,
15950,
48,
28,
1421,
1,
30,
65,
3196,
3260,
25486,
63,
3170,
395,
420,
327,
25754,
83,
543,
376,
20282,
1495,
339,
327,
14766,
2295,
12,
367,
314,
5805,
48,
29,
1824,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1421,
63,
4288,
297,
283,
2158,
297,
25486,
63,
3170,
395,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
17,
3196,
283,
2158,
297,
25486,
63,
3170,
395,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1,
3196,
283,
2158,
297,
25486,
63,
3170,
395,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1421,
63,
7214,
297,
283,
2158,
297,
25486,
63,
3170,
395,
221,
327,
10257,
1121,
370,
10942,
1572,
339,
15950,
48,
28,
1421,
63,
4288,
30,
65,
3196,
283,
65,
297,
8955,
12,
283,
71,
17,
297,
283,
65,
659,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1421,
63,
4288,
3196,
283,
2158,
297,
8955,
12,
283,
71,
17,
297,
283,
65,
659,
339,
327,
1379,
30100,
24644,
272,
661,
1103,
17,
297,
283,
65,
297,
25486,
63,
3170,
395,
259,
327,
10257,
4443,
272,
23734,
1103,
17,
4300,
1557,
17,
297,
8955,
12,
283,
4214,
297,
1557,
17,
659,
221,
327,
17660,
272,
661,
1103,
1643,
297,
8678,
8,
16,
9,
435,
283,
25,
297,
8955,
12,
283,
4214,
297,
8678,
8,
16,
9,
435,
283,
25,
659,
272,
661,
1103,
12735,
297,
283,
65,
297,
8955,
12,
283,
4214,
297,
283,
65,
659,
272,
23845,
65,
5130,
66,
5130,
67,
5130,
68,
5130,
69,
5130,
70,
5130,
71,
5130,
72,
5130,
73,
5130,
74,
5130,
75,
5130,
76,
22532,
7119,
297,
283,
18677,
9503,
75,
25,
297,
8955,
12,
283,
4214,
15200,
71,
845,
297,
283,
18677,
9503,
75,
25,
13,
75,
659,
339,
327,
1379,
971,
16,
365,
8860,
4036,
4509,
272,
334,
82,
1154,
16,
297,
1557,
16,
297,
8955,
12,
283,
4214,
297,
1557,
16,
659,
272,
334,
82,
22123,
16,
65,
4300,
1557
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
818,
26,
2366,
1882,
199,
199,
3,
799,
511,
5241,
436,
12338,
5241,
373,
17,
14,
21,
199,
199,
3,
710,
650,
3962,
15955,
83,
367,
1924,
3851,
199,
59,
6195,
8890,
12,
10341,
12,
25486,
63,
3170,
61,
275,
1425,
8,
19,
9,
199,
199,
3,
27067,
5241,
334,
10065,
14819,
9,
199,
3,
199,
3,
710,
12338,
5241,
1630,
440,
511,
29102,
12,
2951,
8112,
14,
221,
710,
199,
3,
1642,
1819,
402,
1924,
2008,
365,
314,
5163,
3851,
27,
314,
3499,
365,
282,
199,
3,
1059,
370,
1336,
652,
6169,
14,
221,
710,
12338,
316,
1233,
911,
6441,
314,
199,
3,
3499,
1059,
6272,
9978,
10627,
402,
6273,
12,
370,
511,
4212,
5163,
199,
3,
4877,
18628,
641,
7031,
3326,
14,
199,
199,
11861,
83,
275,
359,
339,
327,
511,
2863,
2403,
272,
661,
4718,
92,
2623,
76,
297,
283,
2623,
76,
659,
259,
327,
17669,
425,
272,
23845,
4718,
92,
2623,
76,
3196,
283,
2623,
76,
659,
221,
327,
598,
11330,
8679,
425,
339,
661,
4718,
92,
2623,
76,
92,
29175,
297,
283,
2623,
76,
659,
263,
327,
17669,
425,
272,
23845,
4718,
92,
2623,
76,
92,
29175,
3196,
283,
2623,
76,
659,
420,
327,
598,
11330,
8679,
425,
339,
23845,
4718,
22532,
17,
297,
283,
4718,
4718,
659,
259,
327,
10257,
4443,
272,
661,
779,
16,
65,
13,
90,
1527,
65,
13,
90,
16,
13,
25,
3672,
4258,
7386,
283,
65,
21,
12,
66,
23,
12,
67,
25,
12,
659,
327,
17534,
314,
7377,
1130,
13712,
272,
661,
779,
65,
13,
90,
1527,
65,
13,
90,
16,
13,
25,
3672,
4258,
7386,
283,
65,
21,
12,
66,
23,
12,
67,
25,
12,
659,
327,
437,
9284,
5951,
339,
661,
4718,
297,
283,
4718,
659,
5185,
327,
5870,
1318,
8785,
272,
661,
2795,
4718,
297,
283,
4718,
659,
3777,
327,
8857,
1318,
8785,
272,
661,
2795,
4718,
16110,
283,
4718,
659,
3698,
327,
644,
9050,
1318,
8785,
272,
661,
2795,
8,
4718,
3196,
283,
4718,
659,
3698,
327,
8857,
1318,
8785,
543,
17786,
199,
199,
61,
199,
199,
3,
1379,
5241,
334,
509,
31866,
29102,
9,
199,
3,
199,
3,
710,
511,
5241,
365,
282,
769,
402,
959,
13,
503,
650,
13,
11760,
14,
221,
710,
959,
4184,
402,
282,
199,
3,
4890,
2008,
787,
26,
199,
3,
1819,
378,
26,
282,
1059,
3035,
314,
3851,
199,
3,
260,
413,
26,
314,
1059,
370,
1336,
6169,
314,
3851,
199,
3,
260,
499,
26,
314,
1420,
754,
334,
6195,
8890,
12,
10341,
12,
25486,
63,
3170,
9,
199,
3,
260,
650,
26,
282,
1059,
626,
911,
506,
3468,
11716,
379,
370,
7389,
282,
511,
1059,
14,
199,
3,
3322,
961,
365,
376,
9697,
2018,
3965,
27,
314,
2808,
199,
3,
3322,
2860,
787,
298,
4214,
2,
334,
1589,
8852,
1336,
395,
436,
298,
71,
17,
401,
298,
71,
18,
401,
2263,
199,
3,
3322,
1536,
370,
298,
71,
1020,
2,
1395,
314,
4072,
402,
1924,
1572,
12,
503,
314,
199,
3,
3322,
1059,
283,
403,
7,
340,
314,
1572,
17373,
1133,
1627,
282,
574,
12,
503,
314,
199,
3,
3322,
1059,
283,
547,
7,
340,
314,
1572,
1478,
1990,
734,
402,
1425,
27,
199,
3,
3322,
2597,
298,
2634,
401,
314,
372,
574,
402,
333,
14,
923,
342,
334,
65,
2008,
680,
199,
3,
260,
841,
26,
710,
1420,
754,
402,
27083,
314,
3965,
14,
199,
3,
3322,
982,
314,
2877,
2793,
1133,
1336,
12,
376,
1125,
365,
14581,
14,
199,
3,
199,
3,
982,
314,
5163,
5712,
1133,
1420,
370,
1736,
12,
314,
19045,
2877,
4008,
883,
506,
11684,
14,
199,
199,
2219,
275,
359,
272,
327,
1379,
5805,
48,
28,
436,
5805,
48,
29,
5478,
272,
15950,
48,
28,
1421,
63,
4288,
297,
3260,
25486,
63,
3170,
395,
420,
327,
1910,
18375,
1572,
5148,
272,
15950,
48,
28,
17,
30,
65,
3196,
3260,
25486,
63,
3170,
395,
260,
327,
25754,
83,
543,
282,
10964,
272,
15950,
48,
11230,
30,
65,
3196,
3260,
25486,
63,
3170,
395,
260,
327,
25754,
83,
543,
376,
20282,
1495,
272,
15950,
48,
28,
1421,
1,
30,
65,
3196,
3260,
25486,
63,
3170,
395,
420,
327,
25754,
83,
543,
376,
20282,
1495,
339,
327,
14766,
2295,
12,
367,
314,
5805,
48,
29,
1824,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1421,
63,
4288,
297,
283,
2158,
297,
25486,
63,
3170,
395,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
17,
3196,
283,
2158,
297,
25486,
63,
3170,
395,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1,
3196,
283,
2158,
297,
25486,
63,
3170,
395,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1421,
63,
7214,
297,
283,
2158,
297,
25486,
63,
3170,
395,
221,
327,
10257,
1121,
370,
10942,
1572,
339,
15950,
48,
28,
1421,
63,
4288,
30,
65,
3196,
283,
65,
297,
8955,
12,
283,
71,
17,
297,
283,
65,
659,
272,
15950,
48,
28,
1421,
63,
4288,
30,
65,
18168,
48,
29,
1421,
63,
4288,
3196,
283,
2158,
297,
8955,
12,
283,
71,
17,
297,
283,
65,
659,
339,
327,
1379,
30100,
24644,
272,
661,
1103,
17,
297,
283,
65,
297,
25486,
63,
3170,
395,
259,
327,
10257,
4443,
272,
23734,
1103,
17,
4300,
1557,
17,
297,
8955,
12,
283,
4214,
297,
1557,
17,
659,
221,
327,
17660,
272,
661,
1103,
1643,
297,
8678,
8,
16,
9,
435,
283,
25,
297,
8955,
12,
283,
4214,
297,
8678,
8,
16,
9,
435,
283,
25,
659,
272,
661,
1103,
12735,
297,
283,
65,
297,
8955,
12,
283,
4214,
297,
283,
65,
659,
272,
23845,
65,
5130,
66,
5130,
67,
5130,
68,
5130,
69,
5130,
70,
5130,
71,
5130,
72,
5130,
73,
5130,
74,
5130,
75,
5130,
76,
22532,
7119,
297,
283,
18677,
9503,
75,
25,
297,
8955,
12,
283,
4214,
15200,
71,
845,
297,
283,
18677,
9503,
75,
25,
13,
75,
659,
339,
327,
1379,
971,
16,
365,
8860,
4036,
4509,
272,
334,
82,
1154,
16,
297,
1557,
16,
297,
8955,
12,
283,
4214,
297,
1557,
16,
659,
272,
334,
82,
22123,
16,
65,
4300,
1557,
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,
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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
] |
ryfeus/lambda-packs
|
LightGBM_sklearn_scipy_numpy/source/scipy/special/tests/test_precompute_gammainc.py
|
10
|
4652
|
from __future__ import division, print_function, absolute_import
import numpy as np
import pytest
from scipy.special._testutils import MissingModule, check_version
from scipy.special._mptestutils import (
Arg, IntArg, mp_assert_allclose, assert_mpmath_equal)
from scipy.special._precompute.gammainc_asy import (
compute_g, compute_alpha, compute_d)
from scipy.special._precompute.gammainc_data import gammainc, gammaincc
try:
import sympy
except ImportError:
sympy = MissingModule('sympy')
try:
import mpmath as mp
except ImportError:
mp = MissingModule('mpmath')
_is_32bit_platform = np.intp(0).itemsize < 8
@check_version(mp, '0.19')
def test_g():
# Test data for the g_k. See DLMF 5.11.4.
with mp.workdps(30):
g = [mp.mpf(1), mp.mpf(1)/12, mp.mpf(1)/288,
-mp.mpf(139)/51840, -mp.mpf(571)/2488320,
mp.mpf(163879)/209018880, mp.mpf(5246819)/75246796800]
mp_assert_allclose(compute_g(7), g)
@pytest.mark.slow
@check_version(mp, '0.19')
@check_version(sympy, '0.7')
@pytest.mark.xfail(condition=_is_32bit_platform, reason="rtol only 2e-11, see gh-6938")
def test_alpha():
# Test data for the alpha_k. See DLMF 8.12.14.
with mp.workdps(30):
alpha = [mp.mpf(0), mp.mpf(1), mp.mpf(1)/3, mp.mpf(1)/36,
-mp.mpf(1)/270, mp.mpf(1)/4320, mp.mpf(1)/17010,
-mp.mpf(139)/5443200, mp.mpf(1)/204120]
mp_assert_allclose(compute_alpha(9), alpha)
@pytest.mark.xslow
@check_version(mp, '0.19')
@check_version(sympy, '0.7')
def test_d():
# Compare the d_{k, n} to the results in appendix F of [1].
#
# Sources
# -------
# [1] DiDonato and Morris, Computation of the Incomplete Gamma
# Function Ratios and their Inverse, ACM Transactions on
# Mathematical Software, 1986.
with mp.workdps(50):
dataset = [(0, 0, -mp.mpf('0.333333333333333333333333333333')),
(0, 12, mp.mpf('0.102618097842403080425739573227e-7')),
(1, 0, -mp.mpf('0.185185185185185185185185185185e-2')),
(1, 12, mp.mpf('0.119516285997781473243076536700e-7')),
(2, 0, mp.mpf('0.413359788359788359788359788360e-2')),
(2, 12, -mp.mpf('0.140925299108675210532930244154e-7')),
(3, 0, mp.mpf('0.649434156378600823045267489712e-3')),
(3, 12, -mp.mpf('0.191111684859736540606728140873e-7')),
(4, 0, -mp.mpf('0.861888290916711698604702719929e-3')),
(4, 12, mp.mpf('0.288658297427087836297341274604e-7')),
(5, 0, -mp.mpf('0.336798553366358150308767592718e-3')),
(5, 12, mp.mpf('0.482409670378941807563762631739e-7')),
(6, 0, mp.mpf('0.531307936463992223165748542978e-3')),
(6, 12, -mp.mpf('0.882860074633048352505085243179e-7')),
(7, 0, mp.mpf('0.344367606892377671254279625109e-3')),
(7, 12, -mp.mpf('0.175629733590604619378669693914e-6')),
(8, 0, -mp.mpf('0.652623918595309418922034919727e-3')),
(8, 12, mp.mpf('0.377358774161109793380344937299e-6')),
(9, 0, -mp.mpf('0.596761290192746250124390067179e-3')),
(9, 12, mp.mpf('0.870823417786464116761231237189e-6'))]
d = compute_d(10, 13)
res = []
for k, n, std in dataset:
res.append(d[k][n])
std = map(lambda x: x[2], dataset)
mp_assert_allclose(res, std)
@check_version(mp, '0.19')
def test_gammainc():
# Quick check that the gammainc in
# special._precompute.gammainc_data agrees with mpmath's
# gammainc.
assert_mpmath_equal(gammainc,
lambda a, x: mp.gammainc(a, b=x, regularized=True),
[Arg(0, 100, inclusive_a=False), Arg(0, 100)],
nan_ok=False, rtol=1e-17, n=50, dps=50)
@check_version(mp, '0.19')
def test_gammaincc():
# Quick check that the gammaincc in
# special._precompute.gammainc_data agrees with mpmath's
# gammainc.
assert_mpmath_equal(lambda a, x: gammaincc(a, x, dps=1000),
lambda a, x: mp.gammainc(a, a=x, regularized=True),
[Arg(20, 100), Arg(20, 100)],
nan_ok=False, rtol=1e-17, n=50, dps=1000)
# Test the fast integer path
assert_mpmath_equal(gammaincc,
lambda a, x: mp.gammainc(a, a=x, regularized=True),
[IntArg(1, 100), Arg(0, 100)],
nan_ok=False, rtol=1e-17, n=50, dps=50)
|
mit
|
[
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
646,
4613,
199,
199,
504,
7026,
14,
6664,
423,
396,
1208,
492,
15626,
2377,
12,
1104,
63,
1023,
199,
504,
7026,
14,
6664,
423,
311,
396,
1208,
492,
334,
272,
29560,
12,
9805,
6373,
12,
6118,
63,
479,
63,
7520,
12,
702,
63,
311,
3442,
63,
1452,
9,
199,
504,
7026,
14,
6664,
423,
657,
3357,
14,
17740,
973,
67,
63,
5660,
492,
334,
272,
4526,
63,
71,
12,
4526,
63,
4468,
12,
4526,
63,
68,
9,
199,
504,
7026,
14,
6664,
423,
657,
3357,
14,
17740,
973,
67,
63,
576,
492,
486,
455,
973,
67,
12,
486,
455,
973,
2055,
199,
199,
893,
26,
272,
492,
5840,
199,
2590,
3545,
26,
272,
5840,
275,
15626,
2377,
360,
18132,
358,
199,
199,
893,
26,
272,
492,
6118,
3442,
465,
6118,
199,
2590,
3545,
26,
272,
6118,
275,
15626,
2377,
360,
311,
3442,
358,
421,
199,
63,
374,
63,
708,
2075,
63,
3246,
275,
980,
14,
25319,
8,
16,
680,
21210,
665,
1695,
421,
199,
32,
1074,
63,
1023,
8,
311,
12,
283,
16,
14,
1167,
358,
199,
318,
511,
63,
71,
837,
272,
327,
1379,
666,
367,
314,
486,
63,
75,
14,
1666,
577,
44,
13463,
959,
14,
845,
14,
20,
14,
272,
543,
6118,
14,
800,
30168,
8,
1216,
304,
267,
486,
275,
359,
311,
14,
26716,
8,
17,
395,
6118,
14,
26716,
8,
17,
2447,
713,
12,
6118,
14,
26716,
8,
17,
2447,
10740,
12,
1467,
446,
311,
14,
26716,
8,
7491,
2447,
27015,
2167,
12,
446,
311,
14,
26716,
8,
17136,
2447,
1194,
1299,
12122,
12,
1467,
6118,
14,
26716,
8,
11931,
13657,
2447,
11303,
614,
1299,
1257,
12,
6118,
14,
26716,
8,
26419,
2333,
1167,
2447,
2194,
1194,
18450,
2333,
383,
61,
267,
6118,
63,
479,
63,
7520,
8,
3357,
63,
71,
8,
23,
395,
486,
9,
421,
199,
32,
4462,
14,
1657,
14,
14362,
199,
32,
1074,
63,
1023,
8,
311,
12,
283,
16,
14,
1167,
358,
199,
32,
1074,
63,
1023,
8,
18132,
12,
283,
16,
14,
23,
358,
199,
32,
4462,
14,
1657,
14,
22557,
8,
5394,
3699,
374,
63,
708,
2075,
63,
3246,
12,
4499,
628,
23565,
1454,
499,
69,
13,
845,
12,
1937,
23310,
13,
1876,
1703,
531,
199,
318,
511,
63,
4468,
837,
272,
327,
1379,
666,
367,
314,
5131,
63,
75,
14,
1666,
577,
44,
13463,
1695,
14,
713,
14,
1079,
14,
272,
543,
6118,
14,
800,
30168,
8,
1216,
304,
267,
5131,
275,
359,
311,
14,
26716,
8,
16,
395,
6118,
14,
26716,
8,
17,
395,
6118,
14,
26716,
8,
17,
2447,
19,
12,
6118,
14,
26716,
8,
17,
2447,
1344,
12,
326,
446,
311,
14,
26716,
8,
17,
2447,
13299,
12,
6118,
14,
26716,
8,
17,
2447,
10657,
16,
12,
6118,
14,
26716,
8,
17,
2447,
1196,
9523,
12,
326,
446,
311,
14,
26716,
8,
7491,
2447,
1477,
10657,
383,
12,
6118,
14,
26716,
8,
17,
2447,
6686,
6708,
61,
267,
6118,
63,
479,
63,
7520,
8,
3357,
63,
4468,
8,
25,
395,
5131,
9,
421,
199,
32,
4462,
14,
1657,
14,
7977,
674,
199,
32,
1074,
63,
1023,
8,
311,
12,
283,
16,
14,
1167,
358,
199,
32,
1074,
63,
1023,
8,
18132,
12,
283,
16,
14,
23,
358,
199,
318,
511,
63,
68,
837,
272,
327,
18955,
314,
366,
7348,
75,
12,
302,
93,
370,
314,
2058,
315,
23806,
481,
402,
359,
17,
1055,
272,
327,
272,
327,
5800,
83,
272,
327,
5514,
272,
327,
359,
17,
61,
3757,
16932,
11318,
436,
603,
269,
5719,
12,
3599,
10326,
402,
314,
1010,
4883,
598,
4746,
272,
327,
258,
6801,
820,
2159,
736,
436,
3932,
1010,
2077,
12,
6570,
45,
6266,
3723,
641,
272,
327,
258,
16593,
28491,
2290,
12,
5851,
1184,
14,
339,
543,
6118,
14,
800,
30168,
8,
1400,
304,
267,
4789,
275,
3842,
16,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
15093,
15093,
15093,
28380,
3855,
673,
334,
16,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
32351,
1085,
17790,
1349,
9873,
12127,
966,
11551,
1355,
1641,
708,
1465,
69,
13,
23,
3855,
673,
334,
17,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
69,
13,
18,
3855,
673,
334,
17,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
845,
2720,
975,
14523,
1020,
16156,
11160,
12744,
1216,
19335,
12684,
383,
69,
13,
23,
3855,
673,
334,
18,
12,
378,
12,
6118,
14,
26716,
360,
16,
14,
23663,
1276,
2576,
1299,
1276,
2576,
1299,
1276,
2576,
1299,
1276,
2576,
1299,
11197,
69,
13,
18,
3855,
673,
334,
18,
12,
3144,
12,
446,
311,
14,
26716,
360,
16,
14,
1079,
1643,
6390,
1020,
709,
1184,
18778,
7320,
708,
3129,
996,
1602,
10478,
69,
13,
23,
3855,
673,
334,
19,
12,
378,
12,
6118,
14,
26716,
360,
16,
14,
772,
2635,
1082,
11309,
1401,
1184,
8662,
1789,
12618,
1479,
1342,
8483,
713,
69,
13,
19,
3855,
673,
334,
19,
12,
3144,
12,
446,
311,
14,
26716,
360,
16,
14,
1167,
6984,
22,
15186,
15459,
1344,
1477,
1690,
19338,
1651,
10037,
17430,
69,
13,
23,
3855,
673,
334,
20,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
1184,
1085,
1299,
1398,
1643,
10806,
845,
1876,
1184,
12931,
996,
3172,
1020,
1398,
69,
13,
19,
3855,
673,
334,
20,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
1651,
1184,
2010,
1398,
1342,
13299,
14681,
1344,
12615,
1082,
713,
17718,
966,
69,
13,
23,
3855,
673,
334,
21,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
1153,
1822,
2905,
1229,
1153,
1272,
14321,
8251,
1216,
1555,
1822,
1427,
1465,
1085,
69,
13,
19,
3855,
673,
334,
21,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
2006,
1194,
1643,
1822,
18325,
12128,
1085,
1780,
1367,
11452,
14622,
1196,
1355,
69,
13,
23,
3855,
673,
334,
22,
12,
378,
12,
6118,
14,
26716,
360,
16,
14,
2481,
13421,
3129,
772,
2766,
1020,
1081,
1789,
10355,
18770,
1477,
1398,
2277,
69,
13,
19,
3855,
673,
334,
22,
12,
3144,
12,
446,
311
] |
[
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
646,
4613,
199,
199,
504,
7026,
14,
6664,
423,
396,
1208,
492,
15626,
2377,
12,
1104,
63,
1023,
199,
504,
7026,
14,
6664,
423,
311,
396,
1208,
492,
334,
272,
29560,
12,
9805,
6373,
12,
6118,
63,
479,
63,
7520,
12,
702,
63,
311,
3442,
63,
1452,
9,
199,
504,
7026,
14,
6664,
423,
657,
3357,
14,
17740,
973,
67,
63,
5660,
492,
334,
272,
4526,
63,
71,
12,
4526,
63,
4468,
12,
4526,
63,
68,
9,
199,
504,
7026,
14,
6664,
423,
657,
3357,
14,
17740,
973,
67,
63,
576,
492,
486,
455,
973,
67,
12,
486,
455,
973,
2055,
199,
199,
893,
26,
272,
492,
5840,
199,
2590,
3545,
26,
272,
5840,
275,
15626,
2377,
360,
18132,
358,
199,
199,
893,
26,
272,
492,
6118,
3442,
465,
6118,
199,
2590,
3545,
26,
272,
6118,
275,
15626,
2377,
360,
311,
3442,
358,
421,
199,
63,
374,
63,
708,
2075,
63,
3246,
275,
980,
14,
25319,
8,
16,
680,
21210,
665,
1695,
421,
199,
32,
1074,
63,
1023,
8,
311,
12,
283,
16,
14,
1167,
358,
199,
318,
511,
63,
71,
837,
272,
327,
1379,
666,
367,
314,
486,
63,
75,
14,
1666,
577,
44,
13463,
959,
14,
845,
14,
20,
14,
272,
543,
6118,
14,
800,
30168,
8,
1216,
304,
267,
486,
275,
359,
311,
14,
26716,
8,
17,
395,
6118,
14,
26716,
8,
17,
2447,
713,
12,
6118,
14,
26716,
8,
17,
2447,
10740,
12,
1467,
446,
311,
14,
26716,
8,
7491,
2447,
27015,
2167,
12,
446,
311,
14,
26716,
8,
17136,
2447,
1194,
1299,
12122,
12,
1467,
6118,
14,
26716,
8,
11931,
13657,
2447,
11303,
614,
1299,
1257,
12,
6118,
14,
26716,
8,
26419,
2333,
1167,
2447,
2194,
1194,
18450,
2333,
383,
61,
267,
6118,
63,
479,
63,
7520,
8,
3357,
63,
71,
8,
23,
395,
486,
9,
421,
199,
32,
4462,
14,
1657,
14,
14362,
199,
32,
1074,
63,
1023,
8,
311,
12,
283,
16,
14,
1167,
358,
199,
32,
1074,
63,
1023,
8,
18132,
12,
283,
16,
14,
23,
358,
199,
32,
4462,
14,
1657,
14,
22557,
8,
5394,
3699,
374,
63,
708,
2075,
63,
3246,
12,
4499,
628,
23565,
1454,
499,
69,
13,
845,
12,
1937,
23310,
13,
1876,
1703,
531,
199,
318,
511,
63,
4468,
837,
272,
327,
1379,
666,
367,
314,
5131,
63,
75,
14,
1666,
577,
44,
13463,
1695,
14,
713,
14,
1079,
14,
272,
543,
6118,
14,
800,
30168,
8,
1216,
304,
267,
5131,
275,
359,
311,
14,
26716,
8,
16,
395,
6118,
14,
26716,
8,
17,
395,
6118,
14,
26716,
8,
17,
2447,
19,
12,
6118,
14,
26716,
8,
17,
2447,
1344,
12,
326,
446,
311,
14,
26716,
8,
17,
2447,
13299,
12,
6118,
14,
26716,
8,
17,
2447,
10657,
16,
12,
6118,
14,
26716,
8,
17,
2447,
1196,
9523,
12,
326,
446,
311,
14,
26716,
8,
7491,
2447,
1477,
10657,
383,
12,
6118,
14,
26716,
8,
17,
2447,
6686,
6708,
61,
267,
6118,
63,
479,
63,
7520,
8,
3357,
63,
4468,
8,
25,
395,
5131,
9,
421,
199,
32,
4462,
14,
1657,
14,
7977,
674,
199,
32,
1074,
63,
1023,
8,
311,
12,
283,
16,
14,
1167,
358,
199,
32,
1074,
63,
1023,
8,
18132,
12,
283,
16,
14,
23,
358,
199,
318,
511,
63,
68,
837,
272,
327,
18955,
314,
366,
7348,
75,
12,
302,
93,
370,
314,
2058,
315,
23806,
481,
402,
359,
17,
1055,
272,
327,
272,
327,
5800,
83,
272,
327,
5514,
272,
327,
359,
17,
61,
3757,
16932,
11318,
436,
603,
269,
5719,
12,
3599,
10326,
402,
314,
1010,
4883,
598,
4746,
272,
327,
258,
6801,
820,
2159,
736,
436,
3932,
1010,
2077,
12,
6570,
45,
6266,
3723,
641,
272,
327,
258,
16593,
28491,
2290,
12,
5851,
1184,
14,
339,
543,
6118,
14,
800,
30168,
8,
1400,
304,
267,
4789,
275,
3842,
16,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
15093,
15093,
15093,
28380,
3855,
673,
334,
16,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
32351,
1085,
17790,
1349,
9873,
12127,
966,
11551,
1355,
1641,
708,
1465,
69,
13,
23,
3855,
673,
334,
17,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
10233,
69,
13,
18,
3855,
673,
334,
17,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
845,
2720,
975,
14523,
1020,
16156,
11160,
12744,
1216,
19335,
12684,
383,
69,
13,
23,
3855,
673,
334,
18,
12,
378,
12,
6118,
14,
26716,
360,
16,
14,
23663,
1276,
2576,
1299,
1276,
2576,
1299,
1276,
2576,
1299,
1276,
2576,
1299,
11197,
69,
13,
18,
3855,
673,
334,
18,
12,
3144,
12,
446,
311,
14,
26716,
360,
16,
14,
1079,
1643,
6390,
1020,
709,
1184,
18778,
7320,
708,
3129,
996,
1602,
10478,
69,
13,
23,
3855,
673,
334,
19,
12,
378,
12,
6118,
14,
26716,
360,
16,
14,
772,
2635,
1082,
11309,
1401,
1184,
8662,
1789,
12618,
1479,
1342,
8483,
713,
69,
13,
19,
3855,
673,
334,
19,
12,
3144,
12,
446,
311,
14,
26716,
360,
16,
14,
1167,
6984,
22,
15186,
15459,
1344,
1477,
1690,
19338,
1651,
10037,
17430,
69,
13,
23,
3855,
673,
334,
20,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
1184,
1085,
1299,
1398,
1643,
10806,
845,
1876,
1184,
12931,
996,
3172,
1020,
1398,
69,
13,
19,
3855,
673,
334,
20,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
1651,
1184,
2010,
1398,
1342,
13299,
14681,
1344,
12615,
1082,
713,
17718,
966,
69,
13,
23,
3855,
673,
334,
21,
12,
378,
12,
446,
311,
14,
26716,
360,
16,
14,
1153,
1822,
2905,
1229,
1153,
1272,
14321,
8251,
1216,
1555,
1822,
1427,
1465,
1085,
69,
13,
19,
3855,
673,
334,
21,
12,
3144,
12,
6118,
14,
26716,
360,
16,
14,
2006,
1194,
1643,
1822,
18325,
12128,
1085,
1780,
1367,
11452,
14622,
1196,
1355,
69,
13,
23,
3855,
673,
334,
22,
12,
378,
12,
6118,
14,
26716,
360,
16,
14,
2481,
13421,
3129,
772,
2766,
1020,
1081,
1789,
10355,
18770,
1477,
1398,
2277,
69,
13,
19,
3855,
673,
334,
22,
12,
3144,
12,
446,
311,
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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
agentr13/python-phonenumbers
|
python/phonenumbers/data/region_ZA.py
|
11
|
2469
|
"""Auto-generated file, do not edit by hand. ZA metadata"""
from ..phonemetadata import NumberFormat, PhoneNumberDesc, PhoneMetadata
PHONE_METADATA_ZA = PhoneMetadata(id='ZA', country_code=27, international_prefix='00',
general_desc=PhoneNumberDesc(national_number_pattern='[1-79]\\d{8}|8(?:[067]\\d{7}|[1-4]\\d{3,7})', possible_number_pattern='\\d{5,9}'),
fixed_line=PhoneNumberDesc(national_number_pattern='(?:1[0-8]|2[0-378]|3[1-69]|4\\d|5[1346-8])\\d{7}', possible_number_pattern='\\d{9}', example_number='101234567'),
mobile=PhoneNumberDesc(national_number_pattern='(?:6[0-5]|7[0-46-9])\\d{7}|8[1-4]\\d{3,7}', possible_number_pattern='\\d{5,9}', example_number='711234567'),
toll_free=PhoneNumberDesc(national_number_pattern='80\\d{7}', possible_number_pattern='\\d{9}', example_number='801234567'),
premium_rate=PhoneNumberDesc(national_number_pattern='86[2-9]\\d{6}|90\\d{7}', possible_number_pattern='\\d{9}', example_number='862345678'),
shared_cost=PhoneNumberDesc(national_number_pattern='860\\d{6}', possible_number_pattern='\\d{9}', example_number='860123456'),
personal_number=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'),
voip=PhoneNumberDesc(national_number_pattern='87\\d{7}', possible_number_pattern='\\d{9}', example_number='871234567'),
pager=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'),
uan=PhoneNumberDesc(national_number_pattern='861\\d{6}', possible_number_pattern='\\d{9}', example_number='861123456'),
voicemail=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'),
no_international_dialling=PhoneNumberDesc(national_number_pattern='NA', possible_number_pattern='NA'),
national_prefix='0',
national_prefix_for_parsing='0',
number_format=[NumberFormat(pattern='(860)(\\d{3})(\\d{3})', format='\\1 \\2 \\3', leading_digits_pattern=['860'], national_prefix_formatting_rule='0\\1'),
NumberFormat(pattern='(\\d{2})(\\d{3})(\\d{4})', format='\\1 \\2 \\3', leading_digits_pattern=['[1-79]|8(?:[0-47]|6[1-9])'], national_prefix_formatting_rule='0\\1'),
NumberFormat(pattern='(\\d{2})(\\d{3,4})', format='\\1 \\2', leading_digits_pattern=['8[1-4]'], national_prefix_formatting_rule='0\\1'),
NumberFormat(pattern='(\\d{2})(\\d{3})(\\d{2,3})', format='\\1 \\2 \\3', leading_digits_pattern=['8[1-4]'], national_prefix_formatting_rule='0\\1')],
mobile_number_portable_region=True)
|
apache-2.0
|
[
624,
3358,
13,
10176,
570,
12,
886,
440,
5283,
701,
4926,
14,
3107,
33,
3341,
624,
199,
504,
2508,
9339,
2343,
492,
4860,
3484,
12,
27585,
3259,
9921,
12,
27585,
5142,
199,
199,
9791,
4817,
63,
8314,
63,
21959,
275,
27585,
5142,
8,
344,
534,
21959,
297,
9023,
63,
600,
29,
1465,
12,
10757,
6279,
63,
1861,
534,
383,
297,
272,
8605,
63,
3257,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
30845,
17,
13,
1965,
61,
1103,
68,
91,
24,
22441,
24,
25060,
19338,
61,
1103,
68,
91,
23,
93,
17884,
17,
13,
20,
61,
1103,
68,
91,
19,
12,
23,
25583,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
21,
12,
25,
93,
659,
272,
6317,
63,
604,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
5169,
17,
59,
16,
13,
24,
11752,
18,
59,
16,
13,
12046,
11752,
19,
59,
17,
13,
1876,
11752,
20,
1103,
68,
92,
21,
59,
969,
2466,
13,
24,
566,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
4893,
5533,
5308,
659,
272,
21305,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
5169,
22,
59,
16,
13,
21,
11752,
23,
59,
16,
13,
2466,
13,
25,
566,
1103,
68,
91,
23,
22441,
24,
59,
17,
13,
20,
61,
1103,
68,
91,
19,
12,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
21,
12,
25,
7293,
2893,
63,
1955,
534,
3172,
30217,
659,
272,
370,
914,
63,
4624,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
1257,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
24,
9461,
5308,
659,
272,
876,
23481,
63,
1866,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
1184,
59,
18,
13,
25,
61,
1103,
68,
91,
22,
22441,
2710,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
1184,
5533,
12970,
659,
272,
5709,
63,
6336,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
14832,
1103,
68,
91,
22,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
1184,
9461,
1367,
659,
272,
25994,
63,
1955,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
14164,
711,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
1555,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
1555,
30217,
659,
272,
26581,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
12998,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
16253,
1103,
68,
91,
22,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
16253,
19060,
659,
272,
26563,
1198,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
949,
63,
4404,
6279,
63,
328,
26039,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
302,
6279,
63,
1861,
534,
16,
297,
272,
302,
6279,
63,
1861,
63,
509,
63,
11059,
534,
16,
297,
272,
1329,
63,
908,
1524,
3259,
3484,
8,
3401,
534,
8,
14832,
5130,
1103,
68,
91,
19,
1552,
27910,
68,
91,
19,
25583,
1475,
534,
1103,
17,
8522,
18,
8522,
19,
297,
9186,
63,
7022,
63,
3401,
2968,
14832,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
659,
267,
4860,
3484,
8,
3401,
534,
27910,
68,
91,
18,
1552,
27910,
68,
91,
19,
1552,
27910,
68,
91,
20,
25583,
1475,
534,
1103,
17,
8522,
18,
8522,
19,
297,
9186,
63,
7022,
63,
3401,
2968,
59,
17,
13,
1965,
11752,
24,
25060,
16,
13,
2417,
11752,
22,
59,
17,
13,
25,
566,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
659,
267,
4860,
3484,
8,
3401,
534,
27910,
68,
91,
18,
1552,
27910,
68,
91,
19,
12,
20,
25583,
1475,
534,
1103,
17,
8522,
18,
297,
9186,
63,
7022,
63,
3401,
2968,
24,
59,
17,
13,
20,
61,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
659,
267,
4860,
3484,
8,
3401,
534,
27910,
68,
91,
18,
1552,
27910,
68,
91,
19,
1552,
27910,
68,
91,
18,
12,
19,
25583,
1475,
534,
1103,
17,
8522,
18,
8522,
19,
297,
9186,
63,
7022,
63,
3401,
2968,
24,
59,
17,
13,
20,
61,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
2665,
272,
21305,
63,
1955,
63,
719,
461,
63,
4551,
29,
549,
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
] |
[
3358,
13,
10176,
570,
12,
886,
440,
5283,
701,
4926,
14,
3107,
33,
3341,
624,
199,
504,
2508,
9339,
2343,
492,
4860,
3484,
12,
27585,
3259,
9921,
12,
27585,
5142,
199,
199,
9791,
4817,
63,
8314,
63,
21959,
275,
27585,
5142,
8,
344,
534,
21959,
297,
9023,
63,
600,
29,
1465,
12,
10757,
6279,
63,
1861,
534,
383,
297,
272,
8605,
63,
3257,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
30845,
17,
13,
1965,
61,
1103,
68,
91,
24,
22441,
24,
25060,
19338,
61,
1103,
68,
91,
23,
93,
17884,
17,
13,
20,
61,
1103,
68,
91,
19,
12,
23,
25583,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
21,
12,
25,
93,
659,
272,
6317,
63,
604,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
5169,
17,
59,
16,
13,
24,
11752,
18,
59,
16,
13,
12046,
11752,
19,
59,
17,
13,
1876,
11752,
20,
1103,
68,
92,
21,
59,
969,
2466,
13,
24,
566,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
4893,
5533,
5308,
659,
272,
21305,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
5169,
22,
59,
16,
13,
21,
11752,
23,
59,
16,
13,
2466,
13,
25,
566,
1103,
68,
91,
23,
22441,
24,
59,
17,
13,
20,
61,
1103,
68,
91,
19,
12,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
21,
12,
25,
7293,
2893,
63,
1955,
534,
3172,
30217,
659,
272,
370,
914,
63,
4624,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
1257,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
24,
9461,
5308,
659,
272,
876,
23481,
63,
1866,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
1184,
59,
18,
13,
25,
61,
1103,
68,
91,
22,
22441,
2710,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
1184,
5533,
12970,
659,
272,
5709,
63,
6336,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
14832,
1103,
68,
91,
22,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
1184,
9461,
1367,
659,
272,
25994,
63,
1955,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
14164,
711,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
1555,
1103,
68,
91,
23,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
1555,
30217,
659,
272,
26581,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
12998,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
16253,
1103,
68,
91,
22,
7293,
3962,
63,
1955,
63,
3401,
534,
1103,
68,
91,
25,
7293,
2893,
63,
1955,
534,
16253,
19060,
659,
272,
26563,
1198,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
949,
63,
4404,
6279,
63,
328,
26039,
29,
25640,
9921,
8,
26021,
63,
1955,
63,
3401,
534,
7170,
297,
3962,
63,
1955,
63,
3401,
534,
7170,
659,
272,
302,
6279,
63,
1861,
534,
16,
297,
272,
302,
6279,
63,
1861,
63,
509,
63,
11059,
534,
16,
297,
272,
1329,
63,
908,
1524,
3259,
3484,
8,
3401,
534,
8,
14832,
5130,
1103,
68,
91,
19,
1552,
27910,
68,
91,
19,
25583,
1475,
534,
1103,
17,
8522,
18,
8522,
19,
297,
9186,
63,
7022,
63,
3401,
2968,
14832,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
659,
267,
4860,
3484,
8,
3401,
534,
27910,
68,
91,
18,
1552,
27910,
68,
91,
19,
1552,
27910,
68,
91,
20,
25583,
1475,
534,
1103,
17,
8522,
18,
8522,
19,
297,
9186,
63,
7022,
63,
3401,
2968,
59,
17,
13,
1965,
11752,
24,
25060,
16,
13,
2417,
11752,
22,
59,
17,
13,
25,
566,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
659,
267,
4860,
3484,
8,
3401,
534,
27910,
68,
91,
18,
1552,
27910,
68,
91,
19,
12,
20,
25583,
1475,
534,
1103,
17,
8522,
18,
297,
9186,
63,
7022,
63,
3401,
2968,
24,
59,
17,
13,
20,
61,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
659,
267,
4860,
3484,
8,
3401,
534,
27910,
68,
91,
18,
1552,
27910,
68,
91,
19,
1552,
27910,
68,
91,
18,
12,
19,
25583,
1475,
534,
1103,
17,
8522,
18,
8522,
19,
297,
9186,
63,
7022,
63,
3401,
2968,
24,
59,
17,
13,
20,
61,
995,
302,
6279,
63,
1861,
63,
20034,
63,
2200,
534,
16,
1103,
17,
2665,
272,
21305,
63,
1955,
63,
719,
461,
63,
4551,
29,
549,
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,
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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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
] |
zhangxiaoli73/BigDL
|
pyspark/bigdl/models/ml_pipeline/dl_classifier.py
|
6
|
6226
|
from pyspark.ml.pipeline import Estimator, Model
from pyspark.ml.param.shared import *
from bigdl.util.common import *
if sys.version >= '3':
long = int
unicode = str
class HasBatchSize(Params):
"""
Mixin for param batchSize: batch size.
"""
# a placeholder to make it appear in the generated doc
batchSize = Param(Params._dummy(), "batchSize", "batchSize")
def __init__(self):
super(HasBatchSize, self).__init__()
#: param for batch size.
self.batchSize = Param(self, "batchSize", "batchSize")
self._setDefault(batchSize=1)
def setBatchSize(self, val):
"""
Sets the value of :py:attr:`batchSize`.
"""
self._paramMap[self.batchSize] = val
pythonBigDL_method_name = "setBatchSize" + self.__class__.__name__
callBigDlFunc(self.bigdl_type, pythonBigDL_method_name, self.value, val)
return self
def getBatchSize(self):
"""
Gets the value of batchSize or its default value.
"""
return self.getOrDefault(self.batchSize)
class HasMaxEpoch(Params):
maxEpoch = Param(Params._dummy(), "maxEpoch", "number of max Epoch")
def __init__(self):
super(HasMaxEpoch, self).__init__()
self.maxEpoch = Param(self, "maxEpoch", "maxEpoch")
self._setDefault(maxEpoch=100)
def setMaxEpoch(self, val):
self._paramMap[self.maxEpoch] = val
pythonBigDL_method_name = "setMaxEpoch" + self.__class__.__name__
callBigDlFunc(self.bigdl_type, pythonBigDL_method_name, self.value, val)
return self
def getMaxEpoch(self):
"""
Gets the value of maxEpoch or its default value.
"""
return self.getOrDefault(self.maxEpoch)
class HasFeatureSize(Params):
featureSize = Param(Params._dummy(), "featureSize", "size of the feature")
def __init__(self):
super(HasFeatureSize, self).__init__()
self.featureSize = Param(self, "featureSize", "featureSize")
self._setDefault(featureSize=None)
def setFeatureSize(self, val):
self._paramMap[self.featureSize] = val
pythonBigDL_mehtod_name = "setFeatureSize" + self.__class__.__name__
callBigDlFunc(self.bigdl_type, pythonBigDL_mehtod_name, self.value, val)
return self
def getFeatureSize(self):
return self.getOrDefault(self.featureSize)
class HasLearningRate(Params):
learningRate = Param(Params._dummy(), "learningRate", "learning rate")
def __init__(self):
super(HasLearningRate, self).__init__()
self.learningRate = Param(self, "learningRate", "learning rate")
self._setDefault(learningRate=100)
def setLearningRate(self, val):
self._paramMap[self.learningRate] = val
pythonBigDL_method_name = "setLearningRate" + self.__class__.__name__
callBigDlFunc(self.bigdl_type, pythonBigDL_method_name, self.value, val)
return self
def getLearningRate(self):
"""
Gets the value of maxEpoch or its default value.
"""
return self.getOrDefault(self.learningRate)
class DLEstimator(Estimator, HasFeaturesCol, HasLabelCol, HasPredictionCol, HasBatchSize, HasMaxEpoch, HasLearningRate, JavaValue):
"""
.. note:: Deprecated in 0.5.0. `DLEstimator` has been migrated to package
`bigdl.dlframes`. This will be removed in BigDL 0.6.
"""
def __init__(self, model, criterion, feature_size, label_size, jvalue=None, bigdl_type="float"):
super(DLEstimator, self).__init__()
self.value = jvalue if jvalue else callBigDlFunc(
bigdl_type, self.jvm_class_constructor(), model, criterion, feature_size, label_size)
self.bigdl_type = bigdl_type
self.featureSize = feature_size
def _fit(self, dataset):
#self._transfer_params_to_java()
jmodel = callBigDlFunc(self.bigdl_type, "fitEstimator", self.value, dataset)
model = DLModel.of(jmodel, self.featureSize, self.bigdl_type)
return model
class DLModel(Model, HasFeaturesCol, HasPredictionCol, HasBatchSize, HasFeatureSize, JavaValue):
"""
.. note:: Deprecated in 0.5.0. `DLModel` has been migrated to package
`bigdl.dlframes`. This will be removed in BigDL 0.6.
"""
def __init__(self, model, featureSize, jvalue=None, bigdl_type="float"):
super(DLModel, self).__init__()
self.value = jvalue if jvalue else callBigDlFunc(
bigdl_type, self.jvm_class_constructor(), model, featureSize)
self.bigdl_type = bigdl_type
self.setFeatureSize(featureSize)
def _transform(self, dataset):
return callBigDlFunc(self.bigdl_type, "dlModelTransform", self.value, dataset)
@classmethod
def of(self, jvalue, feature_size=None, bigdl_type="float"):
model = DLModel(model=None, featureSize=feature_size, jvalue=jvalue, bigdl_type=bigdl_type)
return model
class DLClassifier(DLEstimator):
"""
.. note:: Deprecated in 0.5.0. `DLClassifier` has been migrated to package
`bigdl.dlframes`. This will be removed in BigDL 0.6.
"""
def __init__(self, model, criterion, feature_size, bigdl_type="float"):
super(DLClassifier, self).__init__(model, criterion, feature_size, [1], None, bigdl_type)
def _fit(self, dataset):
jmodel = callBigDlFunc(self.bigdl_type, "fitClassifier", self.value, dataset)
model = DLClassifierModel.of(jmodel, self.featureSize, self.bigdl_type)
return model
class DLClassifierModel(DLModel):
"""
.. note:: Deprecated in 0.5.0. `DLClassifierModel` has been migrated to package
`bigdl.dlframes`. This will be removed in BigDL 0.6.
"""
def __init__(self, model, featureSize, jvalue=None, bigdl_type="float"):
super(DLClassifierModel, self).__init__(model, featureSize, jvalue, bigdl_type)
def _transform(self, dataset):
return callBigDlFunc(self.bigdl_type, "dlClassifierModelTransform", self.value, dataset)
@classmethod
def of(self, jvalue, feature_size=None, bigdl_type="float"):
model = DLClassifierModel(model=None, featureSize=feature_size, jvalue=jvalue, bigdl_type=bigdl_type)
return model
|
apache-2.0
|
[
504,
15847,
14,
757,
14,
7379,
492,
28992,
12,
5822,
199,
504,
15847,
14,
757,
14,
635,
14,
5555,
492,
627,
199,
504,
7282,
5030,
14,
1974,
14,
2330,
492,
627,
421,
199,
692,
984,
14,
1023,
2356,
283,
19,
356,
272,
1846,
275,
1109,
272,
2649,
275,
620,
421,
199,
533,
13481,
8842,
2320,
8,
6007,
304,
272,
408,
272,
28438,
367,
1215,
3522,
2320,
26,
3522,
1568,
14,
272,
408,
339,
327,
282,
10069,
370,
1852,
652,
7468,
315,
314,
4046,
1382,
272,
3522,
2320,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
2912,
2320,
401,
298,
2912,
2320,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
8842,
2320,
12,
291,
2843,
826,
4533,
267,
6079,
1215,
367,
3522,
1568,
14,
267,
291,
14,
2912,
2320,
275,
12608,
8,
277,
12,
298,
2912,
2320,
401,
298,
2912,
2320,
531,
267,
291,
423,
409,
2698,
8,
2912,
2320,
29,
17,
9,
339,
347,
663,
8842,
2320,
8,
277,
12,
1139,
304,
267,
408,
267,
10729,
314,
574,
402,
520,
647,
26,
962,
1705,
2912,
2320,
2313,
267,
408,
267,
291,
423,
635,
2956,
59,
277,
14,
2912,
2320,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
765,
63,
354,
275,
298,
409,
8842,
2320,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
765,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
8842,
2320,
8,
277,
304,
267,
408,
267,
14509,
314,
574,
402,
3522,
2320,
503,
2399,
849,
574,
14,
267,
408,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
2912,
2320,
9,
199,
199,
533,
13481,
4261,
29322,
8,
6007,
304,
272,
1390,
29322,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
988,
29322,
401,
298,
1955,
402,
1390,
662,
5132,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
4261,
29322,
12,
291,
2843,
826,
4533,
267,
291,
14,
988,
29322,
275,
12608,
8,
277,
12,
298,
988,
29322,
401,
298,
988,
29322,
531,
267,
291,
423,
409,
2698,
8,
988,
29322,
29,
1960,
9,
339,
347,
663,
4261,
29322,
8,
277,
12,
1139,
304,
267,
291,
423,
635,
2956,
59,
277,
14,
988,
29322,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
765,
63,
354,
275,
298,
409,
4261,
29322,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
765,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
4261,
29322,
8,
277,
304,
267,
408,
267,
14509,
314,
574,
402,
1390,
29322,
503,
2399,
849,
574,
14,
267,
408,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
988,
29322,
9,
199,
199,
533,
13481,
5968,
2320,
8,
6007,
304,
272,
3878,
2320,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
4445,
2320,
401,
298,
890,
402,
314,
3878,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
5968,
2320,
12,
291,
2843,
826,
4533,
267,
291,
14,
4445,
2320,
275,
12608,
8,
277,
12,
298,
4445,
2320,
401,
298,
4445,
2320,
531,
267,
291,
423,
409,
2698,
8,
4445,
2320,
29,
403,
9,
339,
347,
663,
5968,
2320,
8,
277,
12,
1139,
304,
267,
291,
423,
635,
2956,
59,
277,
14,
4445,
2320,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
278,
517,
364,
63,
354,
275,
298,
409,
5968,
2320,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
278,
517,
364,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
5968,
2320,
8,
277,
304,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
4445,
2320,
9,
199,
199,
533,
13481,
25519,
6621,
8,
6007,
304,
272,
9328,
6621,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
10546,
6621,
401,
298,
10546,
6634,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
25519,
6621,
12,
291,
2843,
826,
4533,
267,
291,
14,
10546,
6621,
275,
12608,
8,
277,
12,
298,
10546,
6621,
401,
298,
10546,
6634,
531,
267,
291,
423,
409,
2698,
8,
10546,
6621,
29,
1960,
9,
339,
347,
663,
25519,
6621,
8,
277,
12,
1139,
304,
267,
291,
423,
635,
2956,
59,
277,
14,
10546,
6621,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
765,
63,
354,
275,
298,
409,
25519,
6621,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
765,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
25519,
6621,
8,
277,
304,
267,
408,
267,
14509,
314,
574,
402,
1390,
29322,
503,
2399,
849,
574,
14,
267,
408,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
10546,
6621,
9,
199,
199,
533,
577,
906,
270,
4841,
8,
13183,
12,
13481,
10807,
2001,
12,
13481,
4314,
2001,
12,
13481,
24261,
2001,
12,
13481,
8842,
2320,
12,
13481,
4261,
29322,
12,
13481,
25519,
6621,
12,
9586,
1110,
304,
272,
408,
272,
2508,
5317,
447,
17993,
315,
378,
14,
21,
14,
16,
14,
658,
36,
906,
270,
4841,
64,
965,
2757,
28322,
370,
2559,
1362,
658,
5076,
5030,
14,
68,
276,
1186,
83,
2313,
961,
911,
506,
4829,
315,
13123,
8045,
378,
14,
22,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
221,
1402,
12,
17392,
12,
3878,
63,
890,
12,
1768,
63,
890,
12,
1335,
585,
29,
403,
12,
7282,
5030,
63,
466,
628,
1609,
2349,
267,
1613,
8,
36,
906,
270,
4841,
12,
291,
2843,
826,
4533,
267,
291,
14,
585,
275,
1335,
585,
340,
1335,
585,
587,
1240,
7279,
22904,
7465,
8,
288,
7282,
5030,
63,
466,
12,
291,
14,
15813,
63,
533,
63,
1880,
1062,
1402,
12,
17392,
12,
3878,
63,
890,
12,
1768,
63,
890,
9,
267,
291,
14,
5076,
5030,
63,
466,
275,
7282,
5030,
63,
466,
267,
291,
14,
4445,
2320,
275,
3878,
63,
890,
339,
347,
485,
3269
] |
[
15847,
14,
757,
14,
7379,
492,
28992,
12,
5822,
199,
504,
15847,
14,
757,
14,
635,
14,
5555,
492,
627,
199,
504,
7282,
5030,
14,
1974,
14,
2330,
492,
627,
421,
199,
692,
984,
14,
1023,
2356,
283,
19,
356,
272,
1846,
275,
1109,
272,
2649,
275,
620,
421,
199,
533,
13481,
8842,
2320,
8,
6007,
304,
272,
408,
272,
28438,
367,
1215,
3522,
2320,
26,
3522,
1568,
14,
272,
408,
339,
327,
282,
10069,
370,
1852,
652,
7468,
315,
314,
4046,
1382,
272,
3522,
2320,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
2912,
2320,
401,
298,
2912,
2320,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
8842,
2320,
12,
291,
2843,
826,
4533,
267,
6079,
1215,
367,
3522,
1568,
14,
267,
291,
14,
2912,
2320,
275,
12608,
8,
277,
12,
298,
2912,
2320,
401,
298,
2912,
2320,
531,
267,
291,
423,
409,
2698,
8,
2912,
2320,
29,
17,
9,
339,
347,
663,
8842,
2320,
8,
277,
12,
1139,
304,
267,
408,
267,
10729,
314,
574,
402,
520,
647,
26,
962,
1705,
2912,
2320,
2313,
267,
408,
267,
291,
423,
635,
2956,
59,
277,
14,
2912,
2320,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
765,
63,
354,
275,
298,
409,
8842,
2320,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
765,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
8842,
2320,
8,
277,
304,
267,
408,
267,
14509,
314,
574,
402,
3522,
2320,
503,
2399,
849,
574,
14,
267,
408,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
2912,
2320,
9,
199,
199,
533,
13481,
4261,
29322,
8,
6007,
304,
272,
1390,
29322,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
988,
29322,
401,
298,
1955,
402,
1390,
662,
5132,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
4261,
29322,
12,
291,
2843,
826,
4533,
267,
291,
14,
988,
29322,
275,
12608,
8,
277,
12,
298,
988,
29322,
401,
298,
988,
29322,
531,
267,
291,
423,
409,
2698,
8,
988,
29322,
29,
1960,
9,
339,
347,
663,
4261,
29322,
8,
277,
12,
1139,
304,
267,
291,
423,
635,
2956,
59,
277,
14,
988,
29322,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
765,
63,
354,
275,
298,
409,
4261,
29322,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
765,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
4261,
29322,
8,
277,
304,
267,
408,
267,
14509,
314,
574,
402,
1390,
29322,
503,
2399,
849,
574,
14,
267,
408,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
988,
29322,
9,
199,
199,
533,
13481,
5968,
2320,
8,
6007,
304,
272,
3878,
2320,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
4445,
2320,
401,
298,
890,
402,
314,
3878,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
5968,
2320,
12,
291,
2843,
826,
4533,
267,
291,
14,
4445,
2320,
275,
12608,
8,
277,
12,
298,
4445,
2320,
401,
298,
4445,
2320,
531,
267,
291,
423,
409,
2698,
8,
4445,
2320,
29,
403,
9,
339,
347,
663,
5968,
2320,
8,
277,
12,
1139,
304,
267,
291,
423,
635,
2956,
59,
277,
14,
4445,
2320,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
278,
517,
364,
63,
354,
275,
298,
409,
5968,
2320,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
278,
517,
364,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
5968,
2320,
8,
277,
304,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
4445,
2320,
9,
199,
199,
533,
13481,
25519,
6621,
8,
6007,
304,
272,
9328,
6621,
275,
12608,
8,
6007,
423,
5869,
1062,
298,
10546,
6621,
401,
298,
10546,
6634,
531,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6362,
25519,
6621,
12,
291,
2843,
826,
4533,
267,
291,
14,
10546,
6621,
275,
12608,
8,
277,
12,
298,
10546,
6621,
401,
298,
10546,
6634,
531,
267,
291,
423,
409,
2698,
8,
10546,
6621,
29,
1960,
9,
339,
347,
663,
25519,
6621,
8,
277,
12,
1139,
304,
267,
291,
423,
635,
2956,
59,
277,
14,
10546,
6621,
61,
275,
1139,
267,
2366,
7279,
8045,
63,
765,
63,
354,
275,
298,
409,
25519,
6621,
2,
435,
291,
855,
533,
4914,
354,
363,
267,
1240,
7279,
22904,
7465,
8,
277,
14,
5076,
5030,
63,
466,
12,
2366,
7279,
8045,
63,
765,
63,
354,
12,
291,
14,
585,
12,
1139,
9,
267,
372,
291,
339,
347,
664,
25519,
6621,
8,
277,
304,
267,
408,
267,
14509,
314,
574,
402,
1390,
29322,
503,
2399,
849,
574,
14,
267,
408,
267,
372,
291,
14,
30457,
2698,
8,
277,
14,
10546,
6621,
9,
199,
199,
533,
577,
906,
270,
4841,
8,
13183,
12,
13481,
10807,
2001,
12,
13481,
4314,
2001,
12,
13481,
24261,
2001,
12,
13481,
8842,
2320,
12,
13481,
4261,
29322,
12,
13481,
25519,
6621,
12,
9586,
1110,
304,
272,
408,
272,
2508,
5317,
447,
17993,
315,
378,
14,
21,
14,
16,
14,
658,
36,
906,
270,
4841,
64,
965,
2757,
28322,
370,
2559,
1362,
658,
5076,
5030,
14,
68,
276,
1186,
83,
2313,
961,
911,
506,
4829,
315,
13123,
8045,
378,
14,
22,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
221,
1402,
12,
17392,
12,
3878,
63,
890,
12,
1768,
63,
890,
12,
1335,
585,
29,
403,
12,
7282,
5030,
63,
466,
628,
1609,
2349,
267,
1613,
8,
36,
906,
270,
4841,
12,
291,
2843,
826,
4533,
267,
291,
14,
585,
275,
1335,
585,
340,
1335,
585,
587,
1240,
7279,
22904,
7465,
8,
288,
7282,
5030,
63,
466,
12,
291,
14,
15813,
63,
533,
63,
1880,
1062,
1402,
12,
17392,
12,
3878,
63,
890,
12,
1768,
63,
890,
9,
267,
291,
14,
5076,
5030,
63,
466,
275,
7282,
5030,
63,
466,
267,
291,
14,
4445,
2320,
275,
3878,
63,
890,
339,
347,
485,
3269,
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,
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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
] |
rrooij/youtube-dl
|
youtube_dl/extractor/sohu.py
|
50
|
6911
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import (
compat_str,
compat_urllib_parse_urlencode,
)
from ..utils import (
ExtractorError,
int_or_none,
try_get,
)
class SohuIE(InfoExtractor):
_VALID_URL = r'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
# Sohu videos give different MD5 sums on Travis CI and my machine
_TESTS = [{
'note': 'This video is available only in Mainland China',
'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
'info_dict': {
'id': '382479172',
'ext': 'mp4',
'title': 'MV:Far East Movement《The Illest》',
},
'skip': 'On available in China',
}, {
'url': 'http://tv.sohu.com/20150305/n409385080.shtml',
'info_dict': {
'id': '409385080',
'ext': 'mp4',
'title': '《2015湖南卫视羊年元宵晚会》唐嫣《花好月圆》',
}
}, {
'url': 'http://my.tv.sohu.com/us/232799889/78693464.shtml',
'info_dict': {
'id': '78693464',
'ext': 'mp4',
'title': '【爱范品】第31期:MWC见不到的奇葩手机',
}
}, {
'note': 'Multipart video',
'url': 'http://my.tv.sohu.com/pl/8384802/78910339.shtml',
'info_dict': {
'id': '78910339',
'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
},
'playlist': [{
'info_dict': {
'id': '78910339_part1',
'ext': 'mp4',
'duration': 294,
'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
}
}, {
'info_dict': {
'id': '78910339_part2',
'ext': 'mp4',
'duration': 300,
'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
}
}, {
'info_dict': {
'id': '78910339_part3',
'ext': 'mp4',
'duration': 150,
'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
}
}]
}, {
'note': 'Video with title containing dash',
'url': 'http://my.tv.sohu.com/us/249884221/78932792.shtml',
'info_dict': {
'id': '78932792',
'ext': 'mp4',
'title': 'youtube-dl testing video',
},
'params': {
'skip_download': True
}
}]
def _real_extract(self, url):
def _fetch_data(vid_id, mytv=False):
if mytv:
base_data_url = 'http://my.tv.sohu.com/play/videonew.do?vid='
else:
base_data_url = 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
return self._download_json(
base_data_url + vid_id, video_id,
'Downloading JSON data for %s' % vid_id,
headers=self.geo_verification_headers())
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
mytv = mobj.group('mytv') is not None
webpage = self._download_webpage(url, video_id)
title = re.sub(r' - 搜狐视频$', '', self._og_search_title(webpage))
vid = self._html_search_regex(
r'var vid ?= ?["\'](\d+)["\']',
webpage, 'video path')
vid_data = _fetch_data(vid, mytv)
if vid_data['play'] != 1:
if vid_data.get('status') == 12:
raise ExtractorError(
'%s said: There\'s something wrong in the video.' % self.IE_NAME,
expected=True)
else:
self.raise_geo_restricted(
'%s said: The video is only licensed to users in Mainland China.' % self.IE_NAME)
formats_json = {}
for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
vid_id = vid_data['data'].get('%sVid' % format_id)
if not vid_id:
continue
vid_id = compat_str(vid_id)
formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
part_count = vid_data['data']['totalBlocks']
playlist = []
for i in range(part_count):
formats = []
for format_id, format_data in formats_json.items():
allot = format_data['allot']
data = format_data['data']
clips_url = data['clipsURL']
su = data['su']
video_url = 'newflv.sohu.ccgslb.net'
cdnId = None
retries = 0
while 'newflv.sohu.ccgslb.net' in video_url:
params = {
'prot': 9,
'file': clips_url[i],
'new': su[i],
'prod': 'flash',
'rb': 1,
}
if cdnId is not None:
params['idc'] = cdnId
download_note = 'Downloading %s video URL part %d of %d' % (
format_id, i + 1, part_count)
if retries > 0:
download_note += ' (retry #%d)' % retries
part_info = self._parse_json(self._download_webpage(
'http://%s/?%s' % (allot, compat_urllib_parse_urlencode(params)),
video_id, download_note), video_id)
video_url = part_info['url']
cdnId = part_info.get('nid')
retries += 1
if retries > 5:
raise ExtractorError('Failed to get video URL')
formats.append({
'url': video_url,
'format_id': format_id,
'filesize': int_or_none(
try_get(data, lambda x: x['clipsBytes'][i])),
'width': int_or_none(data.get('width')),
'height': int_or_none(data.get('height')),
'fps': int_or_none(data.get('fps')),
})
self._sort_formats(formats)
playlist.append({
'id': '%s_part%d' % (video_id, i + 1),
'title': title,
'duration': vid_data['data']['clipsDuration'][i],
'formats': formats,
})
if len(playlist) == 1:
info = playlist[0]
info['id'] = video_id
else:
info = {
'_type': 'multi_video',
'entries': playlist,
'id': video_id,
'title': title,
}
return info
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
495,
12,
272,
8434,
63,
4078,
63,
1122,
63,
10738,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
862,
63,
362,
12,
199,
9,
421,
199,
533,
2002,
10616,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
2229,
48,
28,
1662,
6993,
30,
1662,
20316,
6993,
4537,
1152,
10616,
4537,
957,
15,
11198,
9448,
8,
1662,
6993,
8636,
78,
18168,
48,
28,
344,
3072,
68,
13439,
14,
83,
1360,
6697,
7,
339,
327,
2002,
10616,
22010,
8120,
3365,
15830,
21,
27690,
641,
12643,
5068,
445,
41,
436,
3002,
6844,
272,
485,
7569,
275,
8910,
267,
283,
4610,
356,
283,
2765,
3991,
365,
2808,
1454,
315,
11298,
9688,
2799,
13765,
297,
267,
283,
633,
356,
283,
1014,
921,
6993,
14,
1152,
10616,
14,
957,
15,
1797,
11516,
1194,
15,
78,
1703,
1194,
1965,
10419,
14,
83,
1360,
3,
4792,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1703,
1194,
1965,
10419,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
25875,
25742,
38,
285,
662,
1810,
14171,
434,
12805,
233,
1918,
473,
76,
14899,
12805,
234,
297,
267,
1660,
267,
283,
2759,
356,
283,
3314,
2808,
315,
2799,
13765,
297,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14,
1152,
10616,
14,
957,
15,
1797,
1400,
11565,
15,
78,
12443,
1703,
1400,
1257,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
12443,
1703,
1400,
1257,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
12805,
233,
7806,
163,
118,
245,
10450,
246,
10450,
105,
21482,
229,
164,
123,
233,
16322,
113,
8379,
226,
10270,
114,
163,
248,
249,
27085,
12805,
234,
162,
243,
239,
162,
105,
97,
12805,
233,
165,
233,
110,
25440,
122,
31452,
11987,
229,
12805,
234,
297,
267,
789,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
527,
15,
8001,
31486,
13976,
15,
23,
13254,
1082,
772,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
23,
13254,
1082,
772,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
12805,
239,
164,
231,
110,
165,
235,
226,
32531,
12805,
240,
25238,
106,
2192,
14152,
25742,
32726,
35,
21482,
224,
19594,
29507,
8106,
25440,
230,
165,
240,
103,
10862,
234,
25138,
297,
267,
789,
272,
1660,
469,
267,
283,
4610,
356,
283,
27242,
3991,
297,
267,
283,
633,
356,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
1168,
15,
2658,
1349,
11366,
15,
24407,
709,
11870,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24407,
709,
11870,
297,
288,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
267,
1660,
267,
283,
10411,
356,
8910,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
24407,
709,
11870,
63,
2064,
17,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
5553,
356,
499,
2635,
12,
355,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
288,
789,
267,
1660,
469,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
24407,
709,
11870,
63,
2064,
18,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
5553,
356,
9601,
12,
355,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
288,
789,
267,
1660,
469,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
24407,
709,
11870,
63,
2064,
19,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
5553,
356,
14711,
12,
355,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
288,
789,
267,
14877,
272,
1660,
469,
267,
283,
4610,
356,
283,
9166,
543,
2538,
3035,
11847,
297,
267,
283,
633,
356,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
527,
15,
11032,
16303,
11564,
15,
24407,
708,
22364,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24407,
708,
22364,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
9788,
13,
5030,
5343,
3991,
297,
267,
1660,
267,
283,
1162,
356,
469,
288,
283,
2759,
63,
4249,
356,
715,
267,
789,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
398,
347,
485,
3535,
63,
576,
8,
5017,
63,
344,
12,
3002,
6993,
29,
797,
304,
288,
340,
3002,
6993,
26,
355,
1300,
63,
576,
63,
633,
275,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
2802,
15,
5624,
368,
87,
14,
1117,
31,
5017,
534,
288,
587,
26,
355,
1300,
63,
576,
63,
633,
275,
283,
1014,
921,
8885,
14,
86,
2393,
14,
1152,
10616,
14,
957,
15,
86,
2393,
63,
11331,
14,
1287,
31,
5017,
534,
953,
372,
291,
423,
4249,
63,
1001,
8,
355
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
334,
272,
8434,
63,
495,
12,
272,
8434,
63,
4078,
63,
1122,
63,
10738,
12,
199,
9,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
862,
63,
362,
12,
199,
9,
421,
199,
533,
2002,
10616,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
2229,
48,
28,
1662,
6993,
30,
1662,
20316,
6993,
4537,
1152,
10616,
4537,
957,
15,
11198,
9448,
8,
1662,
6993,
8636,
78,
18168,
48,
28,
344,
3072,
68,
13439,
14,
83,
1360,
6697,
7,
339,
327,
2002,
10616,
22010,
8120,
3365,
15830,
21,
27690,
641,
12643,
5068,
445,
41,
436,
3002,
6844,
272,
485,
7569,
275,
8910,
267,
283,
4610,
356,
283,
2765,
3991,
365,
2808,
1454,
315,
11298,
9688,
2799,
13765,
297,
267,
283,
633,
356,
283,
1014,
921,
6993,
14,
1152,
10616,
14,
957,
15,
1797,
11516,
1194,
15,
78,
1703,
1194,
1965,
10419,
14,
83,
1360,
3,
4792,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1703,
1194,
1965,
10419,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
25875,
25742,
38,
285,
662,
1810,
14171,
434,
12805,
233,
1918,
473,
76,
14899,
12805,
234,
297,
267,
1660,
267,
283,
2759,
356,
283,
3314,
2808,
315,
2799,
13765,
297,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
6993,
14,
1152,
10616,
14,
957,
15,
1797,
1400,
11565,
15,
78,
12443,
1703,
1400,
1257,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
12443,
1703,
1400,
1257,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
12805,
233,
7806,
163,
118,
245,
10450,
246,
10450,
105,
21482,
229,
164,
123,
233,
16322,
113,
8379,
226,
10270,
114,
163,
248,
249,
27085,
12805,
234,
162,
243,
239,
162,
105,
97,
12805,
233,
165,
233,
110,
25440,
122,
31452,
11987,
229,
12805,
234,
297,
267,
789,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
527,
15,
8001,
31486,
13976,
15,
23,
13254,
1082,
772,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
23,
13254,
1082,
772,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
12805,
239,
164,
231,
110,
165,
235,
226,
32531,
12805,
240,
25238,
106,
2192,
14152,
25742,
32726,
35,
21482,
224,
19594,
29507,
8106,
25440,
230,
165,
240,
103,
10862,
234,
25138,
297,
267,
789,
272,
1660,
469,
267,
283,
4610,
356,
283,
27242,
3991,
297,
267,
283,
633,
356,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
1168,
15,
2658,
1349,
11366,
15,
24407,
709,
11870,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24407,
709,
11870,
297,
288,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
267,
1660,
267,
283,
10411,
356,
8910,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
24407,
709,
11870,
63,
2064,
17,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
5553,
356,
499,
2635,
12,
355,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
288,
789,
267,
1660,
469,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
24407,
709,
11870,
63,
2064,
18,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
5553,
356,
9601,
12,
355,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
288,
789,
267,
1660,
469,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
24407,
709,
11870,
63,
2064,
19,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
5553,
356,
14711,
12,
355,
283,
1213,
356,
283,
12805,
239,
164,
99,
253,
17797,
96,
165,
234,
236,
10270,
253,
9077,
247,
19012,
247,
9474,
236,
12805,
240,
25238,
106,
969,
14152,
8853,
231,
247,
6923,
232,
17837,
234,
22918,
110,
9065,
114,
105,
10450,
95,
10770,
235,
25712,
229,
297,
288,
789,
267,
14877,
272,
1660,
469,
267,
283,
4610,
356,
283,
9166,
543,
2538,
3035,
11847,
297,
267,
283,
633,
356,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
527,
15,
11032,
16303,
11564,
15,
24407,
708,
22364,
14,
83,
1360,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
24407,
708,
22364,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
9788,
13,
5030,
5343,
3991,
297,
267,
1660,
267,
283,
1162,
356,
469,
288,
283,
2759,
63,
4249,
356,
715,
267,
789,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
398,
347,
485,
3535,
63,
576,
8,
5017,
63,
344,
12,
3002,
6993,
29,
797,
304,
288,
340,
3002,
6993,
26,
355,
1300,
63,
576,
63,
633,
275,
283,
1014,
921,
1662,
14,
6993,
14,
1152,
10616,
14,
957,
15,
2802,
15,
5624,
368,
87,
14,
1117,
31,
5017,
534,
288,
587,
26,
355,
1300,
63,
576,
63,
633,
275,
283,
1014,
921,
8885,
14,
86,
2393,
14,
1152,
10616,
14,
957,
15,
86,
2393,
63,
11331,
14,
1287,
31,
5017,
534,
953,
372,
291,
423,
4249,
63,
1001,
8,
355,
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,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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
] |
openfun/edx-platform
|
common/lib/capa/capa/tests/test_hint_functionality.py
|
23
|
32238
|
# -*- coding: utf-8 -*-
"""
Tests of extended hints
"""
import unittest
from ddt import ddt, data, unpack
# With the use of ddt, some of the data expected_string cases below are naturally long stretches
# of text text without whitespace. I think it's best to leave such lines intact
# in the test code. Therefore:
# pylint: disable=line-too-long
# For out many ddt data cases, prefer a compact form of { .. }
# pylint: disable=bad-continuation
from . import new_loncapa_problem, load_fixture
class HintTest(unittest.TestCase):
"""Base class for tests of extended hinting functionality."""
def correctness(self, problem_id, choice):
"""Grades the problem and returns the 'correctness' string from cmap."""
student_answers = {problem_id: choice}
cmap = self.problem.grade_answers(answers=student_answers) # pylint: disable=no-member
return cmap[problem_id]['correctness']
def get_hint(self, problem_id, choice):
"""Grades the problem and returns its hint from cmap or the empty string."""
student_answers = {problem_id: choice}
cmap = self.problem.grade_answers(answers=student_answers) # pylint: disable=no-member
adict = cmap.cmap.get(problem_id)
if adict:
return adict['msg']
else:
return ''
# It is a little surprising how much more complicated TextInput is than all the other cases.
@ddt
class TextInputHintsTest(HintTest):
"""
Test Text Input Hints Test
"""
xml = load_fixture('extended_hints_text_input.xml')
problem = new_loncapa_problem(xml)
def test_tracking_log(self):
"""Test that the tracking log comes out right."""
self.problem.capa_module.reset_mock()
self.get_hint(u'1_3_1', u'Blue')
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'module_id': 'i4x://Foo/bar/mock/abc',
'problem_part_id': '1_2',
'trigger_type': 'single',
'hint_label': u'Correct',
'correctness': True,
'student_answer': [u'Blue'],
'question_type': 'stringresponse',
'hints': [{'text': 'The red light is scattered by water molecules leaving only blue light.'}]}
)
@data(
{'problem_id': u'1_2_1', u'choice': u'GermanyΩ',
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">I do not think so.Ω</div></div>'},
{'problem_id': u'1_2_1', u'choice': u'franceΩ',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">Viva la France!Ω</div></div>'},
{'problem_id': u'1_2_1', u'choice': u'FranceΩ',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">Viva la France!Ω</div></div>'},
{'problem_id': u'1_2_1', u'choice': u'Mexico',
'expected_string': ''},
{'problem_id': u'1_2_1', u'choice': u'USAΩ',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">Less well known, but yes, there is a Paris, Texas.Ω</div></div>'},
{'problem_id': u'1_2_1', u'choice': u'usaΩ',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">Less well known, but yes, there is a Paris, Texas.Ω</div></div>'},
{'problem_id': u'1_2_1', u'choice': u'uSAxΩ',
'expected_string': u''},
{'problem_id': u'1_2_1', u'choice': u'NICKLANDΩ',
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">The country name does not end in LANDΩ</div></div>'},
{'problem_id': u'1_3_1', u'choice': u'Blue',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">The red light is scattered by water molecules leaving only blue light.</div></div>'},
{'problem_id': u'1_3_1', u'choice': u'blue',
'expected_string': u''},
{'problem_id': u'1_3_1', u'choice': u'b',
'expected_string': u''},
)
@unpack
def test_text_input_hints(self, problem_id, choice, expected_string):
hint = self.get_hint(problem_id, choice)
self.assertEqual(hint, expected_string)
@ddt
class TextInputExtendedHintsCaseInsensitive(HintTest):
"""Test Text Input Extended hints Case Insensitive"""
xml = load_fixture('extended_hints_text_input.xml')
problem = new_loncapa_problem(xml)
@data(
{'problem_id': u'1_5_1', 'choice': 'abc', 'expected_string': ''}, # wrong answer yielding no hint
{'problem_id': u'1_5_1', 'choice': 'A', 'expected_string':
u'<div class="feedback-hint-correct"><div class="hint-label">Woo Hoo: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_5_1', 'choice': 'a', 'expected_string':
u'<div class="feedback-hint-correct"><div class="hint-label">Woo Hoo: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_5_1', 'choice': 'B', 'expected_string':
u'<div class="feedback-hint-correct"><div class="hint-text">hint2</div></div>'},
{'problem_id': u'1_5_1', 'choice': 'b', 'expected_string':
u'<div class="feedback-hint-correct"><div class="hint-text">hint2</div></div>'},
{'problem_id': u'1_5_1', 'choice': 'C', 'expected_string':
u'<div class="feedback-hint-incorrect"><div class="hint-text">hint4</div></div>'},
{'problem_id': u'1_5_1', 'choice': 'c', 'expected_string':
u'<div class="feedback-hint-incorrect"><div class="hint-text">hint4</div></div>'},
# regexp cases
{'problem_id': u'1_5_1', 'choice': 'FGGG', 'expected_string':
u'<div class="feedback-hint-incorrect"><div class="hint-text">hint6</div></div>'},
{'problem_id': u'1_5_1', 'choice': 'fgG', 'expected_string':
u'<div class="feedback-hint-incorrect"><div class="hint-text">hint6</div></div>'},
)
@unpack
def test_text_input_hints(self, problem_id, choice, expected_string):
hint = self.get_hint(problem_id, choice)
self.assertEqual(hint, expected_string)
@ddt
class TextInputExtendedHintsCaseSensitive(HintTest):
"""Sometimes the semantics can be encoded in the class name."""
xml = load_fixture('extended_hints_text_input.xml')
problem = new_loncapa_problem(xml)
@data(
{'problem_id': u'1_6_1', 'choice': 'abc', 'expected_string': ''},
{'problem_id': u'1_6_1', 'choice': 'A', 'expected_string':
u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_6_1', 'choice': 'a', 'expected_string': u''},
{'problem_id': u'1_6_1', 'choice': 'B', 'expected_string':
u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint2</div></div>'},
{'problem_id': u'1_6_1', 'choice': 'b', 'expected_string': u''},
{'problem_id': u'1_6_1', 'choice': 'C', 'expected_string':
u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">hint4</div></div>'},
{'problem_id': u'1_6_1', 'choice': 'c', 'expected_string': u''},
# regexp cases
{'problem_id': u'1_6_1', 'choice': 'FGG', 'expected_string':
u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">hint6</div></div>'},
{'problem_id': u'1_6_1', 'choice': 'fgG', 'expected_string': u''},
)
@unpack
def test_text_input_hints(self, problem_id, choice, expected_string):
message_text = self.get_hint(problem_id, choice)
self.assertEqual(message_text, expected_string)
@ddt
class TextInputExtendedHintsCompatible(HintTest):
"""
Compatibility test with mixed old and new style additional_answer tags.
"""
xml = load_fixture('extended_hints_text_input.xml')
problem = new_loncapa_problem(xml)
@data(
{'problem_id': u'1_7_1', 'choice': 'A', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_7_1', 'choice': 'B', 'correct': 'correct', 'expected_string': ''},
{'problem_id': u'1_7_1', 'choice': 'C', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint2</div></div>'},
{'problem_id': u'1_7_1', 'choice': 'D', 'correct': 'incorrect', 'expected_string': ''},
# check going through conversion with difficult chars
{'problem_id': u'1_7_1', 'choice': """<&"'>""", 'correct': 'correct', 'expected_string': ''},
)
@unpack
def test_text_input_hints(self, problem_id, choice, correct, expected_string):
message_text = self.get_hint(problem_id, choice)
self.assertEqual(message_text, expected_string)
self.assertEqual(self.correctness(problem_id, choice), correct)
@ddt
class TextInputExtendedHintsRegex(HintTest):
"""
Extended hints where the answer is regex mode.
"""
xml = load_fixture('extended_hints_text_input.xml')
problem = new_loncapa_problem(xml)
@data(
{'problem_id': u'1_8_1', 'choice': 'ABwrong', 'correct': 'incorrect', 'expected_string': ''},
{'problem_id': u'1_8_1', 'choice': 'ABC', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'ABBBBC', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'aBc', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint1</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'BBBB', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint2</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'bbb', 'correct': 'correct',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">hint2</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'C', 'correct': 'incorrect',
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">hint4</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'c', 'correct': 'incorrect',
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">hint4</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'D', 'correct': 'incorrect',
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">hint6</div></div>'},
{'problem_id': u'1_8_1', 'choice': 'd', 'correct': 'incorrect',
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">hint6</div></div>'},
)
@unpack
def test_text_input_hints(self, problem_id, choice, correct, expected_string):
message_text = self.get_hint(problem_id, choice)
self.assertEqual(message_text, expected_string)
self.assertEqual(self.correctness(problem_id, choice), correct)
@ddt
class NumericInputHintsTest(HintTest):
"""
This class consists of a suite of test cases to be run on the numeric input problem represented by the XML below.
"""
xml = load_fixture('extended_hints_numeric_input.xml')
problem = new_loncapa_problem(xml) # this problem is properly constructed
def test_tracking_log(self):
self.get_hint(u'1_2_1', u'1.141')
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'module_id': 'i4x://Foo/bar/mock/abc', 'problem_part_id': '1_1', 'trigger_type': 'single',
'hint_label': u'Nice',
'correctness': True,
'student_answer': [u'1.141'],
'question_type': 'numericalresponse',
'hints': [{'text': 'The square root of two turns up in the strangest places.'}]}
)
@data(
{'problem_id': u'1_2_1', 'choice': '1.141',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Nice: </div><div class="hint-text">The square root of two turns up in the strangest places.</div></div>'},
{'problem_id': u'1_3_1', 'choice': '4',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">Pretty easy, uh?.</div></div>'},
# should get hint, when correct via numeric-tolerance
{'problem_id': u'1_2_1', 'choice': '1.15',
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Nice: </div><div class="hint-text">The square root of two turns up in the strangest places.</div></div>'},
# when they answer wrong, nothing
{'problem_id': u'1_2_1', 'choice': '2', 'expected_string': ''},
)
@unpack
def test_numeric_input_hints(self, problem_id, choice, expected_string):
hint = self.get_hint(problem_id, choice)
self.assertEqual(hint, expected_string)
@ddt
class CheckboxHintsTest(HintTest):
"""
This class consists of a suite of test cases to be run on the checkbox problem represented by the XML below.
"""
xml = load_fixture('extended_hints_checkbox.xml')
problem = new_loncapa_problem(xml) # this problem is properly constructed
@data(
{'problem_id': u'1_2_1', 'choice': [u'choice_0'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">You are right that apple is a fruit.</div><div class="hint-text">You are right that mushrooms are not fruit</div><div class="hint-text">Remember that grape is also a fruit.</div><div class="hint-text">What is a camero anyway?</div></div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_1'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">Remember that apple is also a fruit.</div><div class="hint-text">Mushroom is a fungus, not a fruit.</div><div class="hint-text">Remember that grape is also a fruit.</div><div class="hint-text">What is a camero anyway?</div></div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_2'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">Remember that apple is also a fruit.</div><div class="hint-text">You are right that mushrooms are not fruit</div><div class="hint-text">You are right that grape is a fruit</div><div class="hint-text">What is a camero anyway?</div></div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_3'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">Remember that apple is also a fruit.</div><div class="hint-text">You are right that mushrooms are not fruit</div><div class="hint-text">Remember that grape is also a fruit.</div><div class="hint-text">What is a camero anyway?</div></div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_4'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">Remember that apple is also a fruit.</div><div class="hint-text">You are right that mushrooms are not fruit</div><div class="hint-text">Remember that grape is also a fruit.</div><div class="hint-text">I do not know what a Camero is but it is not a fruit.</div></div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_0', u'choice_1'], # compound
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Almost right: </div><div class="hint-text">You are right that apple is a fruit, but there is one you are missing. Also, mushroom is not a fruit.</div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_1', u'choice_2'], # compound
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">You are right that grape is a fruit, but there is one you are missing. Also, mushroom is not a fruit.</div></div>'},
{'problem_id': u'1_2_1', 'choice': [u'choice_0', u'choice_2'],
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="feedback-hint-multi"><div class="hint-text">You are right that apple is a fruit.</div><div class="hint-text">You are right that mushrooms are not fruit</div><div class="hint-text">You are right that grape is a fruit</div><div class="hint-text">What is a camero anyway?</div></div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_0'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">No, sorry, a banana is a fruit.</div><div class="hint-text">You are right that mushrooms are not vegatbles</div><div class="hint-text">Brussel sprout is the only vegetable in this list.</div></div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_1'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">poor banana.</div><div class="hint-text">You are right that mushrooms are not vegatbles</div><div class="hint-text">Brussel sprout is the only vegetable in this list.</div></div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_2'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">poor banana.</div><div class="hint-text">Mushroom is a fungus, not a vegetable.</div><div class="hint-text">Brussel sprout is the only vegetable in this list.</div></div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_3'],
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="feedback-hint-multi"><div class="hint-text">poor banana.</div><div class="hint-text">You are right that mushrooms are not vegatbles</div><div class="hint-text">Brussel sprouts are vegetables.</div></div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_0', u'choice_1'], # compound
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Very funny: </div><div class="hint-text">Making a banana split?</div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_1', u'choice_2'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">poor banana.</div><div class="hint-text">Mushroom is a fungus, not a vegetable.</div><div class="hint-text">Brussel sprout is the only vegetable in this list.</div></div></div>'},
{'problem_id': u'1_3_1', 'choice': [u'choice_0', u'choice_2'],
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">No, sorry, a banana is a fruit.</div><div class="hint-text">Mushroom is a fungus, not a vegetable.</div><div class="hint-text">Brussel sprout is the only vegetable in this list.</div></div></div>'},
# check for interaction between compoundhint and correct/incorrect
{'problem_id': u'1_4_1', 'choice': [u'choice_0', u'choice_1'], # compound
'expected_string': u'<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">AB</div></div>'},
{'problem_id': u'1_4_1', 'choice': [u'choice_0', u'choice_2'], # compound
'expected_string': u'<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">AC</div></div>'},
# check for labeling where multiple child hints have labels
# These are some tricky cases
{'problem_id': '1_5_1', 'choice': ['choice_0', 'choice_1'],
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">AA: </div><div class="feedback-hint-multi"><div class="hint-text">aa</div></div></div>'},
{'problem_id': '1_5_1', 'choice': ['choice_0'],
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">aa</div><div class="hint-text">bb</div></div></div>'},
{'problem_id': '1_5_1', 'choice': ['choice_1'],
'expected_string': ''},
{'problem_id': '1_5_1', 'choice': [],
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">BB: </div><div class="feedback-hint-multi"><div class="hint-text">bb</div></div></div>'},
{'problem_id': '1_6_1', 'choice': ['choice_0'],
'expected_string': '<div class="feedback-hint-incorrect"><div class="feedback-hint-multi"><div class="hint-text">aa</div></div></div>'},
{'problem_id': '1_6_1', 'choice': ['choice_0', 'choice_1'],
'expected_string': '<div class="feedback-hint-correct"><div class="hint-text">compoundo</div></div>'},
# The user selects *nothing*, but can still get "unselected" feedback
{'problem_id': '1_7_1', 'choice': [],
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="feedback-hint-multi"><div class="hint-text">bb</div></div></div>'},
# 100% not match of sel/unsel feedback
{'problem_id': '1_7_1', 'choice': ['choice_1'],
'expected_string': ''},
# Here we have the correct combination, and that makes feedback too
{'problem_id': '1_7_1', 'choice': ['choice_0'],
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="feedback-hint-multi"><div class="hint-text">aa</div><div class="hint-text">bb</div></div></div>'},
)
@unpack
def test_checkbox_hints(self, problem_id, choice, expected_string):
self.maxDiff = None # pylint: disable=invalid-name
hint = self.get_hint(problem_id, choice)
self.assertEqual(hint, expected_string)
class CheckboxHintsTestTracking(HintTest):
"""
Test the rather complicated tracking log output for checkbox cases.
"""
xml = """
<problem>
<p>question</p>
<choiceresponse>
<checkboxgroup direction="vertical">
<choice correct="true">Apple
<choicehint selected="true">A true</choicehint>
<choicehint selected="false">A false</choicehint>
</choice>
<choice correct="false">Banana
</choice>
<choice correct="true">Cronut
<choicehint selected="true">C true</choicehint>
</choice>
<compoundhint value="A C">A C Compound</compoundhint>
</checkboxgroup>
</choiceresponse>
</problem>
"""
problem = new_loncapa_problem(xml)
def test_tracking_log(self):
"""Test checkbox tracking log - by far the most complicated case"""
# A -> 1 hint
self.get_hint(u'1_2_1', [u'choice_0'])
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'hint_label': u'Incorrect',
'module_id': 'i4x://Foo/bar/mock/abc',
'problem_part_id': '1_1',
'choice_all': ['choice_0', 'choice_1', 'choice_2'],
'correctness': False,
'trigger_type': 'single',
'student_answer': [u'choice_0'],
'hints': [{'text': 'A true', 'trigger': [{'choice': 'choice_0', 'selected': True}]}],
'question_type': 'choiceresponse'}
)
# B C -> 2 hints
self.problem.capa_module.runtime.track_function.reset_mock()
self.get_hint(u'1_2_1', [u'choice_1', u'choice_2'])
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'hint_label': u'Incorrect',
'module_id': 'i4x://Foo/bar/mock/abc',
'problem_part_id': '1_1',
'choice_all': ['choice_0', 'choice_1', 'choice_2'],
'correctness': False,
'trigger_type': 'single',
'student_answer': [u'choice_1', u'choice_2'],
'hints': [
{'text': 'A false', 'trigger': [{'choice': 'choice_0', 'selected': False}]},
{'text': 'C true', 'trigger': [{'choice': 'choice_2', 'selected': True}]}
],
'question_type': 'choiceresponse'}
)
# A C -> 1 Compound hint
self.problem.capa_module.runtime.track_function.reset_mock()
self.get_hint(u'1_2_1', [u'choice_0', u'choice_2'])
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'hint_label': u'Correct',
'module_id': 'i4x://Foo/bar/mock/abc',
'problem_part_id': '1_1',
'choice_all': ['choice_0', 'choice_1', 'choice_2'],
'correctness': True,
'trigger_type': 'compound',
'student_answer': [u'choice_0', u'choice_2'],
'hints': [
{'text': 'A C Compound',
'trigger': [{'choice': 'choice_0', 'selected': True}, {'choice': 'choice_2', 'selected': True}]}
],
'question_type': 'choiceresponse'}
)
@ddt
class MultpleChoiceHintsTest(HintTest):
"""
This class consists of a suite of test cases to be run on the multiple choice problem represented by the XML below.
"""
xml = load_fixture('extended_hints_multiple_choice.xml')
problem = new_loncapa_problem(xml)
def test_tracking_log(self):
"""Test that the tracking log comes out right."""
self.problem.capa_module.reset_mock()
self.get_hint(u'1_3_1', u'choice_2')
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'module_id': 'i4x://Foo/bar/mock/abc', 'problem_part_id': '1_2', 'trigger_type': 'single',
'student_answer': [u'choice_2'], 'correctness': False, 'question_type': 'multiplechoiceresponse',
'hint_label': 'OOPS', 'hints': [{'text': 'Apple is a fruit.'}]}
)
@data(
{'problem_id': u'1_2_1', 'choice': u'choice_0',
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-text">Mushroom is a fungus, not a fruit.</div></div>'},
{'problem_id': u'1_2_1', 'choice': u'choice_1',
'expected_string': ''},
{'problem_id': u'1_3_1', 'choice': u'choice_1',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">Potato is a root vegetable.</div></div>'},
{'problem_id': u'1_2_1', 'choice': u'choice_2',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">OUTSTANDING: </div><div class="hint-text">Apple is indeed a fruit.</div></div>'},
{'problem_id': u'1_3_1', 'choice': u'choice_2',
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">OOPS: </div><div class="hint-text">Apple is a fruit.</div></div>'},
{'problem_id': u'1_3_1', 'choice': u'choice_9',
'expected_string': ''},
)
@unpack
def test_multiplechoice_hints(self, problem_id, choice, expected_string):
hint = self.get_hint(problem_id, choice)
self.assertEqual(hint, expected_string)
@ddt
class DropdownHintsTest(HintTest):
"""
This class consists of a suite of test cases to be run on the drop down problem represented by the XML below.
"""
xml = load_fixture('extended_hints_dropdown.xml')
problem = new_loncapa_problem(xml)
def test_tracking_log(self):
"""Test that the tracking log comes out right."""
self.problem.capa_module.reset_mock()
self.get_hint(u'1_3_1', u'FACES')
self.problem.capa_module.runtime.track_function.assert_called_with(
'edx.problem.hint.feedback_displayed',
{'module_id': 'i4x://Foo/bar/mock/abc', 'problem_part_id': '1_2', 'trigger_type': 'single',
'student_answer': [u'FACES'], 'correctness': True, 'question_type': 'optionresponse',
'hint_label': 'Correct', 'hints': [{'text': 'With lots of makeup, doncha know?'}]}
)
@data(
{'problem_id': u'1_2_1', 'choice': 'Multiple Choice',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Good Job: </div><div class="hint-text">Yes, multiple choice is the right answer.</div></div>'},
{'problem_id': u'1_2_1', 'choice': 'Text Input',
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">No, text input problems do not present options.</div></div>'},
{'problem_id': u'1_2_1', 'choice': 'Numerical Input',
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">No, numerical input problems do not present options.</div></div>'},
{'problem_id': u'1_3_1', 'choice': 'FACES',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">With lots of makeup, doncha know?</div></div>'},
{'problem_id': u'1_3_1', 'choice': 'dogs',
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">NOPE: </div><div class="hint-text">Not dogs, not cats, not toads</div></div>'},
{'problem_id': u'1_3_1', 'choice': 'wrongo',
'expected_string': ''},
# Regression case where feedback includes answer substring
{'problem_id': u'1_4_1', 'choice': 'AAA',
'expected_string': '<div class="feedback-hint-incorrect"><div class="hint-label">Incorrect: </div><div class="hint-text">AAABBB1</div></div>'},
{'problem_id': u'1_4_1', 'choice': 'BBB',
'expected_string': '<div class="feedback-hint-correct"><div class="hint-label">Correct: </div><div class="hint-text">AAABBB2</div></div>'},
{'problem_id': u'1_4_1', 'choice': 'not going to match',
'expected_string': ''},
)
@unpack
def test_dropdown_hints(self, problem_id, choice, expected_string):
hint = self.get_hint(problem_id, choice)
self.assertEqual(hint, expected_string)
class ErrorConditionsTest(HintTest):
"""
Erroneous xml should raise exception.
"""
def test_error_conditions_illegal_element(self):
xml_with_errors = load_fixture('extended_hints_with_errors.xml')
with self.assertRaises(Exception):
new_loncapa_problem(xml_with_errors) # this problem is improperly constructed
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2925,
402,
9243,
18069,
199,
624,
421,
199,
646,
2882,
199,
199,
504,
366,
3583,
492,
366,
3583,
12,
666,
12,
7787,
199,
199,
3,
8777,
314,
675,
402,
366,
3583,
12,
2005,
402,
314,
666,
1420,
63,
875,
5560,
5084,
787,
13872,
300,
1183,
1846,
410,
3292,
12253,
199,
3,
402,
1318,
1318,
1928,
8139,
14,
473,
13516,
652,
1159,
5526,
370,
10137,
4066,
2385,
315,
4552,
199,
3,
315,
314,
511,
1233,
14,
21039,
26,
199,
3,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
199,
3,
2104,
734,
5002,
366,
3583,
666,
5560,
12,
16602,
282,
23314,
1824,
402,
469,
2508,
789,
199,
3,
4287,
26,
3507,
29,
4087,
13,
20305,
199,
199,
504,
1275,
492,
892,
63,
5298,
18182,
63,
6462,
12,
2248,
63,
5997,
421,
199,
533,
869,
442,
774,
8,
2796,
14,
1746,
304,
272,
408,
1563,
1021,
367,
2295,
402,
9243,
8328,
316,
9330,
1041,
339,
347,
29102,
8,
277,
12,
5160,
63,
344,
12,
7141,
304,
267,
408,
5761,
3424,
314,
5160,
436,
2529,
314,
283,
4525,
4171,
7,
1059,
687,
14920,
1041,
267,
6474,
63,
13379,
275,
469,
6462,
63,
344,
26,
7141,
93,
267,
14920,
275,
291,
14,
6462,
14,
4523,
63,
13379,
8,
13379,
29,
5500,
63,
13379,
9,
259,
327,
4287,
26,
3507,
29,
889,
13,
1114,
267,
372,
14920,
59,
6462,
63,
344,
2733,
4525,
4171,
418,
339,
347,
664,
63,
6479,
8,
277,
12,
5160,
63,
344,
12,
7141,
304,
267,
408,
5761,
3424,
314,
5160,
436,
2529,
2399,
8328,
687,
14920,
503,
314,
2701,
1059,
1041,
267,
6474,
63,
13379,
275,
469,
6462,
63,
344,
26,
7141,
93,
267,
14920,
275,
291,
14,
6462,
14,
4523,
63,
13379,
8,
13379,
29,
5500,
63,
13379,
9,
259,
327,
4287,
26,
3507,
29,
889,
13,
1114,
267,
282,
807,
275,
14920,
14,
16513,
14,
362,
8,
6462,
63,
344,
9,
267,
340,
282,
807,
26,
288,
372,
282,
807,
459,
1328,
418,
267,
587,
26,
288,
372,
2125,
421,
199,
3,
2779,
365,
282,
12050,
6296,
1359,
1044,
4212,
8298,
1655,
23515,
4516,
3205,
365,
2419,
1006,
314,
1163,
5560,
14,
199,
32,
11138,
199,
533,
4516,
3205,
40,
13141,
774,
8,
20891,
774,
304,
272,
408,
272,
1379,
4516,
6924,
869,
13141,
1379,
272,
408,
272,
2748,
275,
2248,
63,
5997,
360,
10525,
63,
12354,
63,
505,
63,
1210,
14,
1652,
358,
272,
5160,
275,
892,
63,
5298,
18182,
63,
6462,
8,
1652,
9,
339,
347,
511,
63,
14428,
63,
793,
8,
277,
304,
267,
408,
774,
626,
314,
15161,
943,
12477,
734,
2451,
1041,
267,
291,
14,
6462,
14,
18182,
63,
578,
14,
3958,
63,
1805,
342,
267,
291,
14,
362,
63,
6479,
8,
85,
7,
17,
63,
19,
63,
17,
297,
399,
7,
15617,
358,
267,
291,
14,
6462,
14,
18182,
63,
578,
14,
7726,
14,
3885,
63,
1593,
14,
479,
63,
3527,
63,
1045,
8,
288,
283,
8268,
14,
6462,
14,
6479,
14,
13485,
63,
22283,
297,
288,
791,
578,
63,
344,
356,
283,
73,
20,
88,
921,
5686,
15,
1700,
15,
1805,
15,
3175,
297,
1467,
283,
6462,
63,
2064,
63,
344,
356,
283,
17,
63,
18,
297,
1467,
283,
7631,
63,
466,
356,
283,
4780,
297,
1467,
283,
6479,
63,
1302,
356,
399,
7,
19993,
297,
1467,
283,
4525,
4171,
356,
715,
12,
1467,
283,
5500,
63,
5934,
356,
359,
85,
7,
15617,
995,
1467,
283,
4790,
63,
466,
356,
283,
875,
1310,
297,
1467,
283,
12354,
356,
9016,
505,
356,
283,
1918,
8992,
10540,
365,
308,
3385,
3014,
701,
22834,
26350,
83,
23188,
1454,
10030,
10540,
14,
936,
9420,
267,
776,
339,
768,
576,
8,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
27866,
3479,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
15448,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
18298,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
41,
886,
440,
13516,
880,
14,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
4391,
554,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
54,
1003,
65,
1127,
481,
31331,
1,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
13848,
554,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
54,
1003,
65,
1127,
481,
31331,
1,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
45,
476,
12802,
297,
268,
283,
2062,
63,
875,
356,
28599,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
1668,
33,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
10958,
5521,
6040,
12,
1325,
9456,
12,
2337,
365,
282,
2235,
374,
12,
20566,
305,
14,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
527,
65,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
10958,
5521,
6040
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2925,
402,
9243,
18069,
199,
624,
421,
199,
646,
2882,
199,
199,
504,
366,
3583,
492,
366,
3583,
12,
666,
12,
7787,
199,
199,
3,
8777,
314,
675,
402,
366,
3583,
12,
2005,
402,
314,
666,
1420,
63,
875,
5560,
5084,
787,
13872,
300,
1183,
1846,
410,
3292,
12253,
199,
3,
402,
1318,
1318,
1928,
8139,
14,
473,
13516,
652,
1159,
5526,
370,
10137,
4066,
2385,
315,
4552,
199,
3,
315,
314,
511,
1233,
14,
21039,
26,
199,
3,
4287,
26,
3507,
29,
604,
13,
7354,
13,
2809,
199,
3,
2104,
734,
5002,
366,
3583,
666,
5560,
12,
16602,
282,
23314,
1824,
402,
469,
2508,
789,
199,
3,
4287,
26,
3507,
29,
4087,
13,
20305,
199,
199,
504,
1275,
492,
892,
63,
5298,
18182,
63,
6462,
12,
2248,
63,
5997,
421,
199,
533,
869,
442,
774,
8,
2796,
14,
1746,
304,
272,
408,
1563,
1021,
367,
2295,
402,
9243,
8328,
316,
9330,
1041,
339,
347,
29102,
8,
277,
12,
5160,
63,
344,
12,
7141,
304,
267,
408,
5761,
3424,
314,
5160,
436,
2529,
314,
283,
4525,
4171,
7,
1059,
687,
14920,
1041,
267,
6474,
63,
13379,
275,
469,
6462,
63,
344,
26,
7141,
93,
267,
14920,
275,
291,
14,
6462,
14,
4523,
63,
13379,
8,
13379,
29,
5500,
63,
13379,
9,
259,
327,
4287,
26,
3507,
29,
889,
13,
1114,
267,
372,
14920,
59,
6462,
63,
344,
2733,
4525,
4171,
418,
339,
347,
664,
63,
6479,
8,
277,
12,
5160,
63,
344,
12,
7141,
304,
267,
408,
5761,
3424,
314,
5160,
436,
2529,
2399,
8328,
687,
14920,
503,
314,
2701,
1059,
1041,
267,
6474,
63,
13379,
275,
469,
6462,
63,
344,
26,
7141,
93,
267,
14920,
275,
291,
14,
6462,
14,
4523,
63,
13379,
8,
13379,
29,
5500,
63,
13379,
9,
259,
327,
4287,
26,
3507,
29,
889,
13,
1114,
267,
282,
807,
275,
14920,
14,
16513,
14,
362,
8,
6462,
63,
344,
9,
267,
340,
282,
807,
26,
288,
372,
282,
807,
459,
1328,
418,
267,
587,
26,
288,
372,
2125,
421,
199,
3,
2779,
365,
282,
12050,
6296,
1359,
1044,
4212,
8298,
1655,
23515,
4516,
3205,
365,
2419,
1006,
314,
1163,
5560,
14,
199,
32,
11138,
199,
533,
4516,
3205,
40,
13141,
774,
8,
20891,
774,
304,
272,
408,
272,
1379,
4516,
6924,
869,
13141,
1379,
272,
408,
272,
2748,
275,
2248,
63,
5997,
360,
10525,
63,
12354,
63,
505,
63,
1210,
14,
1652,
358,
272,
5160,
275,
892,
63,
5298,
18182,
63,
6462,
8,
1652,
9,
339,
347,
511,
63,
14428,
63,
793,
8,
277,
304,
267,
408,
774,
626,
314,
15161,
943,
12477,
734,
2451,
1041,
267,
291,
14,
6462,
14,
18182,
63,
578,
14,
3958,
63,
1805,
342,
267,
291,
14,
362,
63,
6479,
8,
85,
7,
17,
63,
19,
63,
17,
297,
399,
7,
15617,
358,
267,
291,
14,
6462,
14,
18182,
63,
578,
14,
7726,
14,
3885,
63,
1593,
14,
479,
63,
3527,
63,
1045,
8,
288,
283,
8268,
14,
6462,
14,
6479,
14,
13485,
63,
22283,
297,
288,
791,
578,
63,
344,
356,
283,
73,
20,
88,
921,
5686,
15,
1700,
15,
1805,
15,
3175,
297,
1467,
283,
6462,
63,
2064,
63,
344,
356,
283,
17,
63,
18,
297,
1467,
283,
7631,
63,
466,
356,
283,
4780,
297,
1467,
283,
6479,
63,
1302,
356,
399,
7,
19993,
297,
1467,
283,
4525,
4171,
356,
715,
12,
1467,
283,
5500,
63,
5934,
356,
359,
85,
7,
15617,
995,
1467,
283,
4790,
63,
466,
356,
283,
875,
1310,
297,
1467,
283,
12354,
356,
9016,
505,
356,
283,
1918,
8992,
10540,
365,
308,
3385,
3014,
701,
22834,
26350,
83,
23188,
1454,
10030,
10540,
14,
936,
9420,
267,
776,
339,
768,
576,
8,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
27866,
3479,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
15448,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
18298,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
41,
886,
440,
13516,
880,
14,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
4391,
554,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
54,
1003,
65,
1127,
481,
31331,
1,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
13848,
554,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
54,
1003,
65,
1127,
481,
31331,
1,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
45,
476,
12802,
297,
268,
283,
2062,
63,
875,
356,
28599,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
1668,
33,
139,
103,
297,
268,
283,
2062,
63,
875,
356,
399,
7601,
3015,
1021,
628,
13485,
13,
6479,
13,
4525,
8186,
3015,
1021,
628,
6479,
13,
1302,
1743,
19993,
26,
3068,
3015,
2535,
3015,
1021,
628,
6479,
13,
505,
1743,
10958,
5521,
6040,
12,
1325,
9456,
12,
2337,
365,
282,
2235,
374,
12,
20566,
305,
14,
139,
103,
1108,
3015,
2957,
3015,
30,
2267,
267,
791,
6462,
63,
344,
356,
399,
7,
17,
63,
18,
63,
17,
297,
399,
7,
5095,
356,
399,
7,
527,
65,
139,
103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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
] |
kcavagnolo/astroML
|
book_figures/chapter6/fig_great_wall_MST.py
|
3
|
5216
|
"""
Euclidean Minimum Spanning Tree
-------------------------------
Figure 6.15
An approximate Euclidean minimum spanning tree over the two-dimensional
projection of the SDSS Great Wall. The upper panel shows the input points, and
the middle panel shows the dendrogram connecting them. The lower panel shows
clustering based on this dendrogram, created by removing the largest 10% of the
graph edges, and keeping the remaining connected clusters with 30 or more
members.
Additional information
~~~~~~~~~~~~~~~~~~~~~~
This figure is based on the data presented in Figure 1 of Cowan & Ivezic
(2008). A similar figure appears in the book
"Statistics, Data Mining, and Machine Learning in Astronomy", by
Ivezic, Connolly, Vanderplas, and Gray (2013).
The three panels of this figure show a hierarchical clustering of a subset
of galaxies from the Sloan Digital Sky Survey (SDSS). This region is known
as the "SDSS Great Wall", and contains an extended cluster of several thousand
galaxies approximately 300Mpc (about 1 billion light years) from earth. The
top panel shows the positions of over 8,000 galaxies projected to a 2D plane
with Earth at the point (0, 0). The middle panel shows a dendrogram
representation of a Euclidean Minimum Spanning Tree (MST) over the galaxy
locations. By eliminating edges of a MST which are greater than a given
length, we can measure the amount of clustering at that scale: this is one
version of a class of models known as Hierarchical Clustering. The bottom
panel shows the results of this clustering approach for an edge cutoff of
3.5Mpc, along with a Gaussian Mixture Model fit to the distribution within
each cluster.
"""
# Author: Jake VanderPlas
# License: BSD
# The figure produced by this code is published in the textbook
# "Statistics, Data Mining, and Machine Learning in Astronomy" (2013)
# For more information, see http://astroML.github.com
# To report a bug or issue, use the following forum:
# https://groups.google.com/forum/#!forum/astroml-general
from __future__ import print_function, division
import numpy as np
from matplotlib import pyplot as plt
from scipy import sparse
from sklearn.mixture import GMM
from astroML.clustering import HierarchicalClustering, get_graph_segments
from astroML.datasets import fetch_great_wall
#----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX. This may
# result in an error if LaTeX is not installed on your system. In that case,
# you can set usetex to False.
from astroML.plotting import setup_text_plots
setup_text_plots(fontsize=8, usetex=True)
#------------------------------------------------------------
# get data
X = fetch_great_wall()
xmin, xmax = (-375, -175)
ymin, ymax = (-300, 200)
#------------------------------------------------------------
# Compute the MST clustering model
n_neighbors = 10
edge_cutoff = 0.9
cluster_cutoff = 10
model = HierarchicalClustering(n_neighbors=10,
edge_cutoff=edge_cutoff,
min_cluster_size=cluster_cutoff)
model.fit(X)
print(" scale: %2g Mpc" % np.percentile(model.full_tree_.data,
100 * edge_cutoff))
n_components = model.n_components_
labels = model.labels_
#------------------------------------------------------------
# Get the x, y coordinates of the beginning and end of each line segment
T_x, T_y = get_graph_segments(model.X_train_,
model.full_tree_)
T_trunc_x, T_trunc_y = get_graph_segments(model.X_train_,
model.cluster_graph_)
#------------------------------------------------------------
# Fit a GMM to each individual cluster
Nx = 100
Ny = 250
Xgrid = np.vstack(map(np.ravel, np.meshgrid(np.linspace(xmin, xmax, Nx),
np.linspace(ymin, ymax, Ny)))).T
density = np.zeros(Xgrid.shape[0])
for i in range(n_components):
ind = (labels == i)
Npts = ind.sum()
Nclusters = min(12, Npts // 5)
gmm = GMM(Nclusters, random_state=0).fit(X[ind])
dens = np.exp(gmm.score(Xgrid))
density += dens / dens.max()
density = density.reshape((Ny, Nx))
#----------------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(5, 6))
fig.subplots_adjust(hspace=0, left=0.1, right=0.95, bottom=0.1, top=0.9)
ax = fig.add_subplot(311, aspect='equal')
ax.scatter(X[:, 1], X[:, 0], s=1, lw=0, c='k')
ax.set_xlim(ymin, ymax)
ax.set_ylim(xmin, xmax)
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.set_ylabel('(Mpc)')
ax = fig.add_subplot(312, aspect='equal')
ax.plot(T_y, T_x, c='k', lw=0.5)
ax.set_xlim(ymin, ymax)
ax.set_ylim(xmin, xmax)
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.set_ylabel('(Mpc)')
ax = fig.add_subplot(313, aspect='equal')
ax.plot(T_trunc_y, T_trunc_x, c='k', lw=0.5)
ax.imshow(density.T, origin='lower', cmap=plt.cm.hot_r,
extent=[ymin, ymax, xmin, xmax])
ax.set_xlim(ymin, ymax)
ax.set_ylim(xmin, xmax)
ax.set_xlabel('(Mpc)')
ax.set_ylabel('(Mpc)')
plt.show()
|
bsd-2-clause
|
[
624,
199,
37,
24941,
22466,
8360,
11495,
12178,
199,
777,
18964,
199,
25590,
1227,
14,
1046,
199,
199,
2493,
19917,
662,
24941,
7481,
2249,
11495,
3123,
1806,
314,
2877,
13,
13014,
199,
16539,
402,
314,
428,
36,
2300,
598,
8319,
644,
452,
14,
710,
7008,
12748,
13703,
314,
1324,
4501,
12,
436,
199,
1589,
12180,
12748,
13703,
314,
477,
977,
293,
1679,
18170,
3062,
14,
710,
5117,
12748,
13703,
199,
25802,
4079,
641,
642,
477,
977,
293,
1679,
12,
2737,
701,
12881,
314,
17451,
1616,
5,
402,
314,
199,
2180,
8207,
12,
436,
22181,
314,
7971,
8539,
13865,
543,
4233,
503,
1655,
199,
6334,
14,
199,
199,
8824,
2556,
199,
9753,
2878,
1714,
199,
2765,
9658,
365,
4079,
641,
314,
666,
26568,
315,
16266,
413,
402,
445,
583,
290,
1253,
473,
432,
90,
530,
199,
8,
9300,
680,
437,
8545,
9658,
11337,
315,
314,
6719,
199,
2,
20750,
12,
3918,
603,
7969,
12,
436,
18722,
29127,
315,
437,
495,
17293,
401,
701,
199,
41,
432,
90,
530,
12,
13482,
393,
590,
12,
812,
11438,
1168,
305,
12,
436,
598,
803,
334,
6965,
680,
199,
199,
1918,
7795,
12748,
83,
402,
642,
9658,
2498,
282,
24787,
19454,
402,
282,
10026,
199,
1618,
486,
15151,
1500,
687,
314,
428,
320,
290,
29979,
428,
10562,
29013,
334,
3693,
2300,
680,
221,
961,
4897,
365,
6040,
199,
305,
314,
298,
3693,
2300,
598,
8319,
644,
452,
401,
436,
3509,
376,
9243,
4350,
402,
9978,
294,
1785,
460,
199,
71,
15151,
1500,
19917,
590,
9601,
45,
2352,
334,
10254,
413,
330,
8148,
265,
10540,
17399,
9,
687,
8413,
273,
14,
221,
710,
199,
2119,
12748,
13703,
314,
12266,
402,
1806,
1695,
12,
1493,
486,
15151,
1500,
27294,
370,
282,
499,
36,
16388,
199,
1045,
662,
19677,
737,
314,
2376,
334,
16,
12,
378,
680,
221,
710,
12180,
12748,
13703,
282,
477,
977,
293,
1679,
199,
22903,
402,
282,
662,
24941,
22466,
8360,
11495,
12178,
334,
45,
840,
9,
1806,
314,
486,
15914,
199,
8022,
14,
221,
4885,
20714,
1958,
8207,
402,
282,
603,
840,
1314,
787,
8932,
2419,
282,
1627,
199,
1267,
12,
781,
883,
9775,
314,
5982,
402,
19454,
737,
626,
4666,
26,
642,
365,
1373,
199,
1023,
402,
282,
1021,
402,
1709,
6040,
465,
869,
16437,
16454,
316,
14,
221,
710,
9048,
199,
7885,
13703,
314,
2058,
402,
642,
19454,
18140,
367,
376,
6275,
17875,
402,
199,
19,
14,
21,
45,
2352,
12,
3180,
543,
282,
17131,
603,
73,
4167,
5822,
5542,
370,
314,
4084,
4453,
199,
10885,
4350,
14,
199,
624,
199,
3,
6529,
26,
1603,
1728,
812,
11438,
3714,
305,
199,
3,
844,
26,
6289,
199,
3,
257,
710,
9658,
13584,
701,
642,
1233,
365,
3267,
315,
314,
1318,
2706,
199,
3,
257,
298,
20750,
12,
3918,
603,
7969,
12,
436,
18722,
29127,
315,
437,
495,
17293,
2,
334,
6965,
9,
199,
3,
257,
2104,
1655,
2556,
12,
1937,
1455,
921,
1810,
293,
1698,
14,
5031,
14,
957,
199,
3,
257,
4005,
3622,
282,
6519,
503,
4976,
12,
675,
314,
2569,
21575,
26,
199,
3,
259,
4178,
921,
2634,
14,
3098,
14,
957,
15,
10044,
15,
3168,
10044,
15,
1810,
417,
76,
13,
10706,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
646,
2680,
465,
980,
199,
504,
8027,
492,
1134,
2798,
465,
4488,
199,
199,
504,
7026,
492,
5178,
199,
504,
6357,
14,
2664,
4167,
492,
598,
3218,
199,
199,
504,
6073,
293,
1698,
14,
25802,
492,
869,
16437,
31174,
12,
664,
63,
2180,
63,
13879,
199,
504,
6073,
293,
1698,
14,
12281,
492,
5267,
63,
71,
8319,
63,
7567,
199,
199,
7656,
8648,
199,
3,
961,
805,
11311,
83,
8027,
2202,
367,
282,
14818,
23109,
315,
314,
1318,
2706,
14,
199,
3,
3390,
626,
543,
675,
3858,
29,
549,
12,
26219,
787,
8018,
543,
14081,
14,
221,
961,
1443,
199,
3,
754,
315,
376,
1125,
340,
14081,
365,
440,
4903,
641,
2195,
2656,
14,
221,
1010,
626,
1930,
12,
199,
3,
1265,
883,
663,
675,
3858,
370,
756,
14,
199,
504,
6073,
293,
1698,
14,
2798,
1337,
492,
3272,
63,
505,
63,
13701,
199,
2758,
63,
505,
63,
13701,
8,
22124,
29,
24,
12,
675,
3858,
29,
549,
9,
199,
199,
17807,
4559,
199,
3,
664,
666,
199,
56,
275,
5267,
63,
71,
8319,
63,
7567,
342,
199,
199,
21601,
12,
19906,
275,
5868,
9946,
12,
446,
10848,
9,
199,
27429,
12,
21023,
275,
5868,
5863,
12,
1926,
9,
199,
199,
17807,
4559,
199,
3,
8354,
314,
603,
840,
19454,
1402,
199,
78,
63,
11113,
275,
1616,
199,
5173,
63,
17708,
275,
378,
14,
25,
199,
4201,
63,
17708,
275,
1616,
199,
1238,
275,
869,
16437,
31174,
8,
78,
63,
11113,
29,
709,
12,
3044,
6275,
63,
17708,
29,
5173,
63,
17708,
12,
3044,
1748,
63,
4201,
63,
890,
29,
4201,
63,
17708,
9,
199,
1238,
14,
3269,
8,
56,
9,
199,
1361,
480,
4666,
26,
450,
18,
71,
603,
2352,
2,
450,
980,
14,
21188,
8,
1238,
14,
2861,
63,
2350,
3754,
576,
12,
3147,
2948,
627,
6275,
63,
17708,
430,
199,
199,
78,
63,
4608,
275,
1402,
14,
78,
63,
4608,
63,
199,
3512,
275,
1402,
14,
3512,
63,
199,
199,
17807,
4559,
199,
3,
2372,
314,
671,
12,
612,
8983,
402,
314,
9608,
436,
1284,
402,
1924,
1004,
8135,
199,
52,
63,
88,
12,
377,
63,
89,
275,
664,
63,
2180,
63,
13879,
8,
1238,
14,
56,
63,
2834,
3131,
2892,
1402,
14,
2861,
63,
2350,
4602,
199,
52,
63,
8208,
63,
88,
12,
377,
63,
8208,
63,
89,
275,
664,
63,
2180,
63,
13879,
8,
1238,
14,
56,
63,
2834,
3131,
5101,
1402,
14,
4201,
63,
2180,
4602,
199,
199,
17807,
4559,
199,
3,
25971,
282,
598,
3218,
370,
1924,
8212,
4350,
199,
46,
88,
275,
2948,
199,
22781,
275,
16074,
199,
56,
3825,
275,
980,
14,
20221,
8,
1130,
8,
1590,
14,
11186,
12,
980,
14,
6480,
3825,
8,
1590,
14,
11649,
8,
21601,
12,
19906,
12,
653,
88,
395,
4490,
980,
14,
11649,
8,
27429,
12,
21023,
12,
653,
89,
430,
4992,
52,
199,
15669,
275,
980,
14,
4250,
8,
56,
3825,
14,
1392,
59,
16,
566,
199,
199,
509,
284
] |
[
199,
37,
24941,
22466,
8360,
11495,
12178,
199,
777,
18964,
199,
25590,
1227,
14,
1046,
199,
199,
2493,
19917,
662,
24941,
7481,
2249,
11495,
3123,
1806,
314,
2877,
13,
13014,
199,
16539,
402,
314,
428,
36,
2300,
598,
8319,
644,
452,
14,
710,
7008,
12748,
13703,
314,
1324,
4501,
12,
436,
199,
1589,
12180,
12748,
13703,
314,
477,
977,
293,
1679,
18170,
3062,
14,
710,
5117,
12748,
13703,
199,
25802,
4079,
641,
642,
477,
977,
293,
1679,
12,
2737,
701,
12881,
314,
17451,
1616,
5,
402,
314,
199,
2180,
8207,
12,
436,
22181,
314,
7971,
8539,
13865,
543,
4233,
503,
1655,
199,
6334,
14,
199,
199,
8824,
2556,
199,
9753,
2878,
1714,
199,
2765,
9658,
365,
4079,
641,
314,
666,
26568,
315,
16266,
413,
402,
445,
583,
290,
1253,
473,
432,
90,
530,
199,
8,
9300,
680,
437,
8545,
9658,
11337,
315,
314,
6719,
199,
2,
20750,
12,
3918,
603,
7969,
12,
436,
18722,
29127,
315,
437,
495,
17293,
401,
701,
199,
41,
432,
90,
530,
12,
13482,
393,
590,
12,
812,
11438,
1168,
305,
12,
436,
598,
803,
334,
6965,
680,
199,
199,
1918,
7795,
12748,
83,
402,
642,
9658,
2498,
282,
24787,
19454,
402,
282,
10026,
199,
1618,
486,
15151,
1500,
687,
314,
428,
320,
290,
29979,
428,
10562,
29013,
334,
3693,
2300,
680,
221,
961,
4897,
365,
6040,
199,
305,
314,
298,
3693,
2300,
598,
8319,
644,
452,
401,
436,
3509,
376,
9243,
4350,
402,
9978,
294,
1785,
460,
199,
71,
15151,
1500,
19917,
590,
9601,
45,
2352,
334,
10254,
413,
330,
8148,
265,
10540,
17399,
9,
687,
8413,
273,
14,
221,
710,
199,
2119,
12748,
13703,
314,
12266,
402,
1806,
1695,
12,
1493,
486,
15151,
1500,
27294,
370,
282,
499,
36,
16388,
199,
1045,
662,
19677,
737,
314,
2376,
334,
16,
12,
378,
680,
221,
710,
12180,
12748,
13703,
282,
477,
977,
293,
1679,
199,
22903,
402,
282,
662,
24941,
22466,
8360,
11495,
12178,
334,
45,
840,
9,
1806,
314,
486,
15914,
199,
8022,
14,
221,
4885,
20714,
1958,
8207,
402,
282,
603,
840,
1314,
787,
8932,
2419,
282,
1627,
199,
1267,
12,
781,
883,
9775,
314,
5982,
402,
19454,
737,
626,
4666,
26,
642,
365,
1373,
199,
1023,
402,
282,
1021,
402,
1709,
6040,
465,
869,
16437,
16454,
316,
14,
221,
710,
9048,
199,
7885,
13703,
314,
2058,
402,
642,
19454,
18140,
367,
376,
6275,
17875,
402,
199,
19,
14,
21,
45,
2352,
12,
3180,
543,
282,
17131,
603,
73,
4167,
5822,
5542,
370,
314,
4084,
4453,
199,
10885,
4350,
14,
199,
624,
199,
3,
6529,
26,
1603,
1728,
812,
11438,
3714,
305,
199,
3,
844,
26,
6289,
199,
3,
257,
710,
9658,
13584,
701,
642,
1233,
365,
3267,
315,
314,
1318,
2706,
199,
3,
257,
298,
20750,
12,
3918,
603,
7969,
12,
436,
18722,
29127,
315,
437,
495,
17293,
2,
334,
6965,
9,
199,
3,
257,
2104,
1655,
2556,
12,
1937,
1455,
921,
1810,
293,
1698,
14,
5031,
14,
957,
199,
3,
257,
4005,
3622,
282,
6519,
503,
4976,
12,
675,
314,
2569,
21575,
26,
199,
3,
259,
4178,
921,
2634,
14,
3098,
14,
957,
15,
10044,
15,
3168,
10044,
15,
1810,
417,
76,
13,
10706,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
646,
2680,
465,
980,
199,
504,
8027,
492,
1134,
2798,
465,
4488,
199,
199,
504,
7026,
492,
5178,
199,
504,
6357,
14,
2664,
4167,
492,
598,
3218,
199,
199,
504,
6073,
293,
1698,
14,
25802,
492,
869,
16437,
31174,
12,
664,
63,
2180,
63,
13879,
199,
504,
6073,
293,
1698,
14,
12281,
492,
5267,
63,
71,
8319,
63,
7567,
199,
199,
7656,
8648,
199,
3,
961,
805,
11311,
83,
8027,
2202,
367,
282,
14818,
23109,
315,
314,
1318,
2706,
14,
199,
3,
3390,
626,
543,
675,
3858,
29,
549,
12,
26219,
787,
8018,
543,
14081,
14,
221,
961,
1443,
199,
3,
754,
315,
376,
1125,
340,
14081,
365,
440,
4903,
641,
2195,
2656,
14,
221,
1010,
626,
1930,
12,
199,
3,
1265,
883,
663,
675,
3858,
370,
756,
14,
199,
504,
6073,
293,
1698,
14,
2798,
1337,
492,
3272,
63,
505,
63,
13701,
199,
2758,
63,
505,
63,
13701,
8,
22124,
29,
24,
12,
675,
3858,
29,
549,
9,
199,
199,
17807,
4559,
199,
3,
664,
666,
199,
56,
275,
5267,
63,
71,
8319,
63,
7567,
342,
199,
199,
21601,
12,
19906,
275,
5868,
9946,
12,
446,
10848,
9,
199,
27429,
12,
21023,
275,
5868,
5863,
12,
1926,
9,
199,
199,
17807,
4559,
199,
3,
8354,
314,
603,
840,
19454,
1402,
199,
78,
63,
11113,
275,
1616,
199,
5173,
63,
17708,
275,
378,
14,
25,
199,
4201,
63,
17708,
275,
1616,
199,
1238,
275,
869,
16437,
31174,
8,
78,
63,
11113,
29,
709,
12,
3044,
6275,
63,
17708,
29,
5173,
63,
17708,
12,
3044,
1748,
63,
4201,
63,
890,
29,
4201,
63,
17708,
9,
199,
1238,
14,
3269,
8,
56,
9,
199,
1361,
480,
4666,
26,
450,
18,
71,
603,
2352,
2,
450,
980,
14,
21188,
8,
1238,
14,
2861,
63,
2350,
3754,
576,
12,
3147,
2948,
627,
6275,
63,
17708,
430,
199,
199,
78,
63,
4608,
275,
1402,
14,
78,
63,
4608,
63,
199,
3512,
275,
1402,
14,
3512,
63,
199,
199,
17807,
4559,
199,
3,
2372,
314,
671,
12,
612,
8983,
402,
314,
9608,
436,
1284,
402,
1924,
1004,
8135,
199,
52,
63,
88,
12,
377,
63,
89,
275,
664,
63,
2180,
63,
13879,
8,
1238,
14,
56,
63,
2834,
3131,
2892,
1402,
14,
2861,
63,
2350,
4602,
199,
52,
63,
8208,
63,
88,
12,
377,
63,
8208,
63,
89,
275,
664,
63,
2180,
63,
13879,
8,
1238,
14,
56,
63,
2834,
3131,
5101,
1402,
14,
4201,
63,
2180,
4602,
199,
199,
17807,
4559,
199,
3,
25971,
282,
598,
3218,
370,
1924,
8212,
4350,
199,
46,
88,
275,
2948,
199,
22781,
275,
16074,
199,
56,
3825,
275,
980,
14,
20221,
8,
1130,
8,
1590,
14,
11186,
12,
980,
14,
6480,
3825,
8,
1590,
14,
11649,
8,
21601,
12,
19906,
12,
653,
88,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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
] |
sinuos/breakpad
|
src/tools/gyp/tools/pretty_sln.py
|
137
|
4977
|
#!/usr/bin/python2.5
# Copyright 2009 Google Inc.
# All Rights Reserved.
"""Prints the information in a sln file in a diffable way.
It first outputs each projects in alphabetical order with their
dependencies.
Then it outputs a possible build order.
"""
__author__ = 'nsylvain (Nicolas Sylvain)'
import os
import re
import sys
import pretty_vcproj
def BuildProject(project, built, projects, deps):
# if all dependencies are done, we can build it, otherwise we try to build the
# dependency.
# This is not infinite-recursion proof.
for dep in deps[project]:
if dep not in built:
BuildProject(dep, built, projects, deps)
print project
built.append(project)
def ParseSolution(solution_file):
# All projects, their clsid and paths.
projects = dict()
# A list of dependencies associated with a project.
dependencies = dict()
# Regular expressions that matches the SLN format.
# The first line of a project definition.
begin_project = re.compile(('^Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942'
'}"\) = "(.*)", "(.*)", "(.*)"$'))
# The last line of a project definition.
end_project = re.compile('^EndProject$')
# The first line of a dependency list.
begin_dep = re.compile('ProjectSection\(ProjectDependencies\) = postProject$')
# The last line of a dependency list.
end_dep = re.compile('EndProjectSection$')
# A line describing a dependency.
dep_line = re.compile(' *({.*}) = ({.*})$')
in_deps = False
solution = open(solution_file)
for line in solution:
results = begin_project.search(line)
if results:
# Hack to remove icu because the diff is too different.
if results.group(1).find('icu') != -1:
continue
# We remove "_gyp" from the names because it helps to diff them.
current_project = results.group(1).replace('_gyp', '')
projects[current_project] = [results.group(2).replace('_gyp', ''),
results.group(3),
results.group(2)]
dependencies[current_project] = []
continue
results = end_project.search(line)
if results:
current_project = None
continue
results = begin_dep.search(line)
if results:
in_deps = True
continue
results = end_dep.search(line)
if results:
in_deps = False
continue
results = dep_line.search(line)
if results and in_deps and current_project:
dependencies[current_project].append(results.group(1))
continue
# Change all dependencies clsid to name instead.
for project in dependencies:
# For each dependencies in this project
new_dep_array = []
for dep in dependencies[project]:
# Look for the project name matching this cldis
for project_info in projects:
if projects[project_info][1] == dep:
new_dep_array.append(project_info)
dependencies[project] = sorted(new_dep_array)
return (projects, dependencies)
def PrintDependencies(projects, deps):
print "---------------------------------------"
print "Dependencies for all projects"
print "---------------------------------------"
print "-- --"
for (project, dep_list) in sorted(deps.items()):
print "Project : %s" % project
print "Path : %s" % projects[project][0]
if dep_list:
for dep in dep_list:
print " - %s" % dep
print ""
print "-- --"
def PrintBuildOrder(projects, deps):
print "---------------------------------------"
print "Build order "
print "---------------------------------------"
print "-- --"
built = []
for (project, dep_list) in sorted(deps.items()):
if project not in built:
BuildProject(project, built, projects, deps)
print "-- --"
def PrintVCProj(projects):
for project in projects:
print "-------------------------------------"
print "-------------------------------------"
print project
print project
print project
print "-------------------------------------"
print "-------------------------------------"
project_path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[1]),
projects[project][2]))
pretty = pretty_vcproj
argv = [ '',
project_path,
'$(SolutionDir)=%s\\' % os.path.dirname(sys.argv[1]),
]
argv.extend(sys.argv[3:])
pretty.main(argv)
def main():
# check if we have exactly 1 parameter.
if len(sys.argv) < 2:
print 'Usage: %s "c:\\path\\to\\project.sln"' % sys.argv[0]
return
(projects, deps) = ParseSolution(sys.argv[1])
PrintDependencies(projects, deps)
PrintBuildOrder(projects, deps)
if '--recursive' in sys.argv:
PrintVCProj(projects)
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
21,
199,
3,
1898,
8937,
4475,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
199,
624,
26113,
314,
2556,
315,
282,
5340,
78,
570,
315,
282,
3915,
461,
4340,
14,
8410,
2779,
1642,
4704,
1924,
11336,
315,
23331,
3294,
1865,
543,
3932,
2043,
5124,
14,
8410,
9442,
652,
4704,
282,
3962,
1900,
1865,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
21320,
6371,
1581,
334,
20959,
761,
305,
5515,
6371,
1581,
3171,
199,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
7268,
63,
6737,
5468,
199,
199,
318,
6516,
4761,
8,
1715,
12,
6137,
12,
11336,
12,
10140,
304,
523,
327,
340,
1006,
5124,
787,
4224,
12,
781,
883,
1900,
652,
12,
4257,
781,
862,
370,
1900,
314,
523,
327,
5936,
14,
523,
327,
961,
365,
440,
15258,
13,
21314,
557,
1618,
14,
523,
367,
2657,
315,
10140,
59,
1715,
2189,
272,
340,
2657,
440,
315,
6137,
26,
489,
6516,
4761,
8,
2601,
12,
6137,
12,
11336,
12,
10140,
9,
523,
870,
2199,
523,
6137,
14,
740,
8,
1715,
9,
199,
199,
318,
6077,
24277,
8,
14458,
63,
493,
304,
523,
327,
2900,
11336,
12,
3932,
824,
4148,
436,
3792,
14,
523,
11336,
275,
1211,
342,
819,
327,
437,
769,
402,
5124,
4568,
543,
282,
2199,
14,
523,
5124,
275,
1211,
342,
819,
327,
18528,
8455,
626,
4450,
314,
428,
44,
46,
1475,
14,
523,
327,
710,
1642,
1004,
402,
282,
2199,
5492,
14,
523,
5386,
63,
1715,
275,
295,
14,
2014,
4725,
62,
4761,
60,
13076,
24,
6265,
25,
2089,
34,
24,
13,
24,
34,
20,
33,
13,
845,
36,
16,
13,
24,
36,
845,
13,
383,
33,
16,
35,
3328,
6265,
25,
2260,
7,
2892,
28544,
3212,
9,
275,
7340,
2795,
4186,
7340,
2795,
4186,
7340,
2795,
2924,
4,
1333,
523,
327,
710,
2061,
1004,
402,
282,
2199,
5492,
14,
523,
1284,
63,
1715,
275,
295,
14,
2014,
9097,
3005,
4761,
9988,
523,
327,
710,
1642,
1004,
402,
282,
5936,
769,
14,
523,
5386,
63,
2601,
275,
295,
14,
2014,
360,
4761,
8660,
24805,
4761,
11927,
31736,
275,
2963,
4761,
9988,
523,
327,
710,
2061,
1004,
402,
282,
5936,
769,
14,
523,
1284,
63,
2601,
275,
295,
14,
2014,
360,
3005,
4761,
8660,
9988,
523,
327,
437,
1004,
13660,
282,
5936,
14,
523,
2657,
63,
604,
275,
295,
14,
2014,
360,
627,
2561,
2795,
1552,
275,
11459,
2795,
1552,
9988,
819,
315,
63,
5846,
275,
756,
523,
8744,
275,
1551,
8,
14458,
63,
493,
9,
523,
367,
1004,
315,
8744,
26,
272,
2058,
275,
5386,
63,
1715,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
327,
30802,
370,
2813,
284,
15140,
2952,
314,
3915,
365,
4634,
3365,
14,
489,
340,
2058,
14,
923,
8,
17,
680,
1623,
360,
530,
85,
358,
1137,
446,
17,
26,
267,
1980,
489,
327,
2136,
2813,
2668,
6179,
2,
687,
314,
1561,
2952,
652,
22577,
370,
3915,
3062,
14,
489,
1453,
63,
1715,
275,
2058,
14,
923,
8,
17,
680,
1814,
6412,
6179,
297,
4074,
489,
11336,
59,
1818,
63,
1715,
61,
275,
359,
2604,
14,
923,
8,
18,
680,
1814,
6412,
6179,
297,
9929,
3521,
2058,
14,
923,
8,
19,
395,
3521,
2058,
14,
923,
8,
18,
1874,
489,
5124,
59,
1818,
63,
1715,
61,
275,
942,
489,
1980,
339,
2058,
275,
1284,
63,
1715,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
1453,
63,
1715,
275,
488,
489,
1980,
339,
2058,
275,
5386,
63,
2601,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
315,
63,
5846,
275,
715,
489,
1980,
339,
2058,
275,
1284,
63,
2601,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
315,
63,
5846,
275,
756,
489,
1980,
339,
2058,
275,
2657,
63,
604,
14,
1733,
8,
604,
9,
272,
340,
2058,
436,
315,
63,
5846,
436,
1453,
63,
1715,
26,
489,
5124,
59,
1818,
63,
1715,
1055,
740,
8,
2604,
14,
923,
8,
17,
430,
489,
1980,
819,
327,
7743,
1006,
5124,
824,
4148,
370,
536,
3140,
14,
523,
367,
2199,
315,
5124,
26,
272,
327,
2104,
1924,
5124,
315,
642,
2199,
272,
892,
63,
2601,
63,
1144,
275,
942,
272,
367,
2657,
315,
5124,
59,
1715,
2189,
489,
327,
12077,
367,
314,
2199,
536,
4877,
642,
824,
2297,
489,
367,
2199,
63,
815,
315,
11336,
26,
267,
340,
11336,
59,
1715,
63,
815,
1527,
17,
61,
508,
2657,
26,
881,
892,
63,
2601,
63,
1144,
14,
740,
8,
1715,
63,
815,
9,
272,
5124,
59,
1715,
61,
275,
3355,
8,
1222,
63,
2601,
63,
1144,
9,
819,
372,
334,
6776,
12,
5124,
9,
199,
199,
318,
9101,
11927,
8,
6776,
12,
10140,
304,
523,
870,
298,
1444,
12797,
2,
523,
870,
298,
11927,
367,
1006,
11336,
2,
523,
870,
298,
1444,
12797,
2,
523,
870,
4320,
15530,
1553,
2,
819,
367,
334,
1715,
12,
2657,
63,
513,
9,
315,
3355,
8,
5846,
14,
1744,
5109,
272,
870,
298,
4761,
520,
450,
83,
2,
450,
2199,
272,
870,
298,
2042,
520,
450,
83,
2,
450,
11336,
59,
1715,
1527,
16,
61,
272,
340,
2657,
63,
513,
26,
489,
367,
2657,
315,
2657,
63,
513,
26,
267,
870,
298,
221,
446,
450,
83,
2,
450,
2657,
272,
870,
3087,
819,
870,
4320,
15530,
1553,
2,
199,
199,
318,
9101,
3425,
4738,
8,
6776,
12,
10140,
304,
523,
870,
298,
1444,
12797,
2,
523,
870,
298,
3425,
1865,
14960,
298,
523,
870,
298,
1444,
12797,
2,
523,
870,
4320,
15530,
1553,
2,
819,
6137,
275,
942,
523,
367,
334,
1715,
12,
2657,
63,
513,
9,
315,
3355,
8,
5846,
14,
1744,
5109,
23855,
340,
2199,
440,
315,
6137,
26,
489,
6516,
4761,
8,
1715,
12,
6137,
12,
11336,
12,
10140,
9,
819,
870,
4320,
15530,
1553,
2,
199,
199,
318,
9101,
9454,
23657,
8,
6776,
304,
819,
367,
2199,
315,
11336,
26,
272,
870,
298,
1444,
9858,
2,
272,
870,
298,
1444,
9858,
2,
272,
870,
2199,
272,
870,
2199,
272,
870,
2199,
272,
870,
298,
1444,
9858,
2,
272,
870,
298,
1444,
9858,
2,
339,
2199,
63,
515,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
21,
199,
3,
1898,
8937,
4475,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
199,
624,
26113,
314,
2556,
315,
282,
5340,
78,
570,
315,
282,
3915,
461,
4340,
14,
8410,
2779,
1642,
4704,
1924,
11336,
315,
23331,
3294,
1865,
543,
3932,
2043,
5124,
14,
8410,
9442,
652,
4704,
282,
3962,
1900,
1865,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
21320,
6371,
1581,
334,
20959,
761,
305,
5515,
6371,
1581,
3171,
199,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
7268,
63,
6737,
5468,
199,
199,
318,
6516,
4761,
8,
1715,
12,
6137,
12,
11336,
12,
10140,
304,
523,
327,
340,
1006,
5124,
787,
4224,
12,
781,
883,
1900,
652,
12,
4257,
781,
862,
370,
1900,
314,
523,
327,
5936,
14,
523,
327,
961,
365,
440,
15258,
13,
21314,
557,
1618,
14,
523,
367,
2657,
315,
10140,
59,
1715,
2189,
272,
340,
2657,
440,
315,
6137,
26,
489,
6516,
4761,
8,
2601,
12,
6137,
12,
11336,
12,
10140,
9,
523,
870,
2199,
523,
6137,
14,
740,
8,
1715,
9,
199,
199,
318,
6077,
24277,
8,
14458,
63,
493,
304,
523,
327,
2900,
11336,
12,
3932,
824,
4148,
436,
3792,
14,
523,
11336,
275,
1211,
342,
819,
327,
437,
769,
402,
5124,
4568,
543,
282,
2199,
14,
523,
5124,
275,
1211,
342,
819,
327,
18528,
8455,
626,
4450,
314,
428,
44,
46,
1475,
14,
523,
327,
710,
1642,
1004,
402,
282,
2199,
5492,
14,
523,
5386,
63,
1715,
275,
295,
14,
2014,
4725,
62,
4761,
60,
13076,
24,
6265,
25,
2089,
34,
24,
13,
24,
34,
20,
33,
13,
845,
36,
16,
13,
24,
36,
845,
13,
383,
33,
16,
35,
3328,
6265,
25,
2260,
7,
2892,
28544,
3212,
9,
275,
7340,
2795,
4186,
7340,
2795,
4186,
7340,
2795,
2924,
4,
1333,
523,
327,
710,
2061,
1004,
402,
282,
2199,
5492,
14,
523,
1284,
63,
1715,
275,
295,
14,
2014,
9097,
3005,
4761,
9988,
523,
327,
710,
1642,
1004,
402,
282,
5936,
769,
14,
523,
5386,
63,
2601,
275,
295,
14,
2014,
360,
4761,
8660,
24805,
4761,
11927,
31736,
275,
2963,
4761,
9988,
523,
327,
710,
2061,
1004,
402,
282,
5936,
769,
14,
523,
1284,
63,
2601,
275,
295,
14,
2014,
360,
3005,
4761,
8660,
9988,
523,
327,
437,
1004,
13660,
282,
5936,
14,
523,
2657,
63,
604,
275,
295,
14,
2014,
360,
627,
2561,
2795,
1552,
275,
11459,
2795,
1552,
9988,
819,
315,
63,
5846,
275,
756,
523,
8744,
275,
1551,
8,
14458,
63,
493,
9,
523,
367,
1004,
315,
8744,
26,
272,
2058,
275,
5386,
63,
1715,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
327,
30802,
370,
2813,
284,
15140,
2952,
314,
3915,
365,
4634,
3365,
14,
489,
340,
2058,
14,
923,
8,
17,
680,
1623,
360,
530,
85,
358,
1137,
446,
17,
26,
267,
1980,
489,
327,
2136,
2813,
2668,
6179,
2,
687,
314,
1561,
2952,
652,
22577,
370,
3915,
3062,
14,
489,
1453,
63,
1715,
275,
2058,
14,
923,
8,
17,
680,
1814,
6412,
6179,
297,
4074,
489,
11336,
59,
1818,
63,
1715,
61,
275,
359,
2604,
14,
923,
8,
18,
680,
1814,
6412,
6179,
297,
9929,
3521,
2058,
14,
923,
8,
19,
395,
3521,
2058,
14,
923,
8,
18,
1874,
489,
5124,
59,
1818,
63,
1715,
61,
275,
942,
489,
1980,
339,
2058,
275,
1284,
63,
1715,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
1453,
63,
1715,
275,
488,
489,
1980,
339,
2058,
275,
5386,
63,
2601,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
315,
63,
5846,
275,
715,
489,
1980,
339,
2058,
275,
1284,
63,
2601,
14,
1733,
8,
604,
9,
272,
340,
2058,
26,
489,
315,
63,
5846,
275,
756,
489,
1980,
339,
2058,
275,
2657,
63,
604,
14,
1733,
8,
604,
9,
272,
340,
2058,
436,
315,
63,
5846,
436,
1453,
63,
1715,
26,
489,
5124,
59,
1818,
63,
1715,
1055,
740,
8,
2604,
14,
923,
8,
17,
430,
489,
1980,
819,
327,
7743,
1006,
5124,
824,
4148,
370,
536,
3140,
14,
523,
367,
2199,
315,
5124,
26,
272,
327,
2104,
1924,
5124,
315,
642,
2199,
272,
892,
63,
2601,
63,
1144,
275,
942,
272,
367,
2657,
315,
5124,
59,
1715,
2189,
489,
327,
12077,
367,
314,
2199,
536,
4877,
642,
824,
2297,
489,
367,
2199,
63,
815,
315,
11336,
26,
267,
340,
11336,
59,
1715,
63,
815,
1527,
17,
61,
508,
2657,
26,
881,
892,
63,
2601,
63,
1144,
14,
740,
8,
1715,
63,
815,
9,
272,
5124,
59,
1715,
61,
275,
3355,
8,
1222,
63,
2601,
63,
1144,
9,
819,
372,
334,
6776,
12,
5124,
9,
199,
199,
318,
9101,
11927,
8,
6776,
12,
10140,
304,
523,
870,
298,
1444,
12797,
2,
523,
870,
298,
11927,
367,
1006,
11336,
2,
523,
870,
298,
1444,
12797,
2,
523,
870,
4320,
15530,
1553,
2,
819,
367,
334,
1715,
12,
2657,
63,
513,
9,
315,
3355,
8,
5846,
14,
1744,
5109,
272,
870,
298,
4761,
520,
450,
83,
2,
450,
2199,
272,
870,
298,
2042,
520,
450,
83,
2,
450,
11336,
59,
1715,
1527,
16,
61,
272,
340,
2657,
63,
513,
26,
489,
367,
2657,
315,
2657,
63,
513,
26,
267,
870,
298,
221,
446,
450,
83,
2,
450,
2657,
272,
870,
3087,
819,
870,
4320,
15530,
1553,
2,
199,
199,
318,
9101,
3425,
4738,
8,
6776,
12,
10140,
304,
523,
870,
298,
1444,
12797,
2,
523,
870,
298,
3425,
1865,
14960,
298,
523,
870,
298,
1444,
12797,
2,
523,
870,
4320,
15530,
1553,
2,
819,
6137,
275,
942,
523,
367,
334,
1715,
12,
2657,
63,
513,
9,
315,
3355,
8,
5846,
14,
1744,
5109,
23855,
340,
2199,
440,
315,
6137,
26,
489,
6516,
4761,
8,
1715,
12,
6137,
12,
11336,
12,
10140,
9,
819,
870,
4320,
15530,
1553,
2,
199,
199,
318,
9101,
9454,
23657,
8,
6776,
304,
819,
367,
2199,
315,
11336,
26,
272,
870,
298,
1444,
9858,
2,
272,
870,
298,
1444,
9858,
2,
272,
870,
2199,
272,
870,
2199,
272,
870,
2199,
272,
870,
298,
1444,
9858,
2,
272,
870,
298,
1444,
9858,
2,
339,
2199,
63,
515,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
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,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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
] |
napkindrawing/ansible
|
lib/ansible/modules/network/junos/junos_rpc.py
|
23
|
4807
|
#!/usr/bin/python
#
# 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 = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'core'}
DOCUMENTATION = """
---
module: junos_rpc
version_added: "2.3"
author: "Peter Sprygada (@privateip)"
short_description: Runs an arbitrary RPC over NetConf on an Juniper JUNOS device
description:
- Sends a request to the remote device running JUNOS to execute the
specified RPC using the NetConf transport. The reply is then
returned to the playbook in the c(xml) key. If an alternate output
format is requested, the reply is transformed to the requested output.
extends_documentation_fragment: junos
options:
rpc:
description:
- The C(rpc) argument specifies the RPC call to send to the
remote devices to be executed. The RPC Reply message is parsed
and the contents are returned to the playbook.
required: true
args:
description:
- The C(args) argument provides a set of arguments for the RPC
call and are encoded in the request message. This argument
accepts a set of key=value arguments.
required: false
default: null
output:
description:
- The C(output) argument specifies the desired output of the
return data. This argument accepts one of C(xml), C(text),
or C(json). For C(json), the JUNOS device must be running a
version of software that supports native JSON output.
required: false
default: xml
"""
EXAMPLES = """
- name: collect interface information using rpc
junos_rpc:
rpc: get-interface-information
args:
interface-name: em0
media: True
- name: get system information
junos_rpc:
rpc: get-system-information
"""
RETURN = """
xml:
description: The xml return string from the rpc request.
returned: always
type: string
output:
description: The rpc rely converted to the output format.
returned: always
type: string
output_lines:
description: The text output split into lines for readability.
returned: always
type: list
"""
from xml.etree.ElementTree import Element, SubElement, tostring
from ansible.module_utils.junos import junos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netconf import send_request
from ansible.module_utils.six import iteritems
USE_PERSISTENT_CONNECTION = True
def main():
"""main entry point for Ansible module
"""
argument_spec = dict(
rpc=dict(required=True),
args=dict(type='dict'),
output=dict(default='xml', choices=['xml', 'json', 'text']),
)
argument_spec.update(junos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=False)
warnings = list()
check_args(module, warnings)
result = {'changed': False, 'warnings': warnings}
rpc = str(module.params['rpc']).replace('_', '-')
if all((module.check_mode, not rpc.startswith('get'))):
module.fail_json(msg='invalid rpc for running in check_mode')
args = module.params['args'] or {}
xattrs = {'format': module.params['output']}
element = Element(module.params['rpc'], xattrs)
for key, value in iteritems(args):
key = str(key).replace('_', '-')
if isinstance(value, list):
for item in value:
child = SubElement(element, key)
if item is not True:
child.text = item
else:
child = SubElement(element, key)
if value is not True:
child.text = value
reply = send_request(module, element)
result['xml'] = str(tostring(reply))
if module.params['output'] == 'text':
data = reply.find('.//output')
result['output'] = data.text.strip()
result['output_lines'] = result['output'].split('\n')
elif module.params['output'] == 'json':
result['output'] = module.from_json(reply.text.strip())
else:
result['output'] = str(tostring(reply)).split('\n')
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
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,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
1335,
21003,
63,
4354,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
23773,
376,
9697,
11785,
1806,
5365,
8930,
641,
376,
1603,
5411,
529,
1603,
1734,
3100,
2243,
199,
1802,
26,
523,
446,
428,
3198,
282,
1056,
370,
314,
3982,
2243,
3879,
1603,
1734,
3100,
370,
5341,
314,
272,
2013,
11785,
1808,
314,
5365,
8930,
7773,
14,
221,
710,
9351,
365,
2066,
272,
2138,
370,
314,
15695,
315,
314,
286,
8,
1652,
9,
790,
14,
221,
982,
376,
18034,
1072,
272,
1475,
365,
5839,
12,
314,
9351,
365,
14834,
370,
314,
5839,
1072,
14,
199,
11036,
63,
9970,
63,
7677,
26,
1335,
21003,
199,
1419,
26,
523,
8985,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
4354,
9,
1423,
9314,
314,
11785,
1240,
370,
3222,
370,
314,
267,
3982,
7256,
370,
506,
7934,
14,
221,
710,
11785,
16000,
590,
1245,
365,
4565,
267,
436,
314,
4072,
787,
2138,
370,
314,
15695,
14,
272,
1415,
26,
2549,
523,
1249,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
589,
9,
1423,
6571,
282,
663,
402,
2368,
367,
314,
11785,
267,
1240,
436,
787,
5737,
315,
314,
1056,
1245,
14,
221,
961,
1423,
267,
11479,
282,
663,
402,
790,
29,
585,
2368,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1072,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
1199,
9,
1423,
9314,
314,
6387,
1072,
402,
314,
267,
372,
666,
14,
221,
961,
1423,
11479,
1373,
402,
445,
8,
1652,
395,
445,
8,
505,
395,
267,
503,
445,
8,
1001,
680,
221,
2104,
445,
8,
1001,
395,
314,
1603,
1734,
3100,
2243,
1471,
506,
3879,
282,
267,
1015,
402,
2032,
626,
5171,
5438,
4840,
1072,
14,
272,
1415,
26,
3055,
272,
849,
26,
2748,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
8775,
3217,
2556,
1808,
8985,
523,
1335,
21003,
63,
4354,
26,
272,
8985,
26,
664,
13,
3266,
13,
11697,
272,
1249,
26,
489,
3217,
13,
354,
26,
18564,
16,
489,
5898,
26,
715,
199,
199,
13,
536,
26,
664,
2656,
2556,
523,
1335,
21003,
63,
4354,
26,
272,
8985,
26,
664,
13,
2253,
13,
11697,
199,
624,
199,
199,
9677,
275,
408,
199,
1652,
26,
523,
1369,
26,
710,
2748,
372,
1059,
687,
314,
8985,
1056,
14,
523,
2138,
26,
3544,
523,
730,
26,
1059,
199,
1199,
26,
523,
1369,
26,
710,
8985,
19687,
6702,
370,
314,
1072,
1475,
14,
523,
2138,
26,
3544,
523,
730,
26,
1059,
199,
1199,
63,
1278,
26,
523,
1369,
26,
710,
1318,
1072,
3715,
1901,
2385,
367,
1586,
3616,
14,
523,
2138,
26,
3544,
523,
730,
26,
769,
199,
624,
199,
504,
2748,
14,
9464,
14,
15325,
492,
6566,
12,
22356,
12,
370,
875,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
31959,
492,
1335,
21003,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
18242,
492,
3222,
63,
1069,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
199,
199,
4701,
63,
4227,
29367,
1309,
63,
18389,
275,
715,
421,
199,
318,
2446,
837,
272,
408,
973,
2397,
2376,
367,
2622,
859,
272,
408,
272,
1423,
63,
1650,
275,
1211,
8,
267,
8985,
29,
807,
8,
2427,
29,
549,
395,
267,
1249,
29,
807,
8,
466,
534,
807,
659,
267,
1072,
29,
807,
8,
885,
534,
1652,
297,
3415,
2968,
1652,
297,
283,
1001,
297,
283,
505,
3815,
272,
776,
339,
1423,
63,
1650,
14,
873,
8,
31959,
63,
2094,
63,
1650,
9,
339,
859,
275,
6953,
8,
2094,
63,
1650,
29,
2094,
63,
1650,
12,
2574,
5171,
63,
1074,
63,
632,
29,
797,
9,
339,
3598,
275,
769,
342,
272,
1104,
63,
589,
8,
578,
12,
3598,
9,
339,
754,
275,
791,
2489,
356,
756,
12,
283,
5451,
356,
3598,
93,
339,
8985,
275,
620,
8,
578,
14,
1162,
459,
4354,
13227,
1814,
20928,
26942,
339,
340,
1006,
1332,
578,
14,
1074,
63,
632,
12,
440,
8985,
14,
2460,
360,
362,
1333,
304,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
3197,
8985,
367,
3879,
315,
1104,
63,
632,
358,
339,
1249,
275,
859,
14,
1162,
459,
589,
418,
503,
1052,
339,
671,
3288,
275,
791,
908,
356,
859,
14,
1162,
459,
1199,
12074,
339,
1819,
275,
6566,
8,
578,
14,
1162,
459,
4354,
995,
671,
3288,
9,
339,
367,
790,
12,
574,
315,
10849,
8,
589,
304,
267,
790,
275,
620,
8,
498,
680,
1814,
20928,
26942,
267,
340,
1228,
8,
585,
12,
769,
304,
288,
367,
1242,
315,
574,
26,
355,
1982,
275,
22356,
8,
2108,
12,
790,
9,
355,
340,
1242,
365,
440,
715,
26,
490,
1982,
14,
505,
275,
1242,
267,
587,
26,
288,
1982,
275,
22356,
8,
2108,
12,
790,
9,
288
] |
[
2647,
15,
1393,
15,
1548,
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,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1018,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
1335,
21003,
63,
4354,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
23773,
376,
9697,
11785,
1806,
5365,
8930,
641,
376,
1603,
5411,
529,
1603,
1734,
3100,
2243,
199,
1802,
26,
523,
446,
428,
3198,
282,
1056,
370,
314,
3982,
2243,
3879,
1603,
1734,
3100,
370,
5341,
314,
272,
2013,
11785,
1808,
314,
5365,
8930,
7773,
14,
221,
710,
9351,
365,
2066,
272,
2138,
370,
314,
15695,
315,
314,
286,
8,
1652,
9,
790,
14,
221,
982,
376,
18034,
1072,
272,
1475,
365,
5839,
12,
314,
9351,
365,
14834,
370,
314,
5839,
1072,
14,
199,
11036,
63,
9970,
63,
7677,
26,
1335,
21003,
199,
1419,
26,
523,
8985,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
4354,
9,
1423,
9314,
314,
11785,
1240,
370,
3222,
370,
314,
267,
3982,
7256,
370,
506,
7934,
14,
221,
710,
11785,
16000,
590,
1245,
365,
4565,
267,
436,
314,
4072,
787,
2138,
370,
314,
15695,
14,
272,
1415,
26,
2549,
523,
1249,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
589,
9,
1423,
6571,
282,
663,
402,
2368,
367,
314,
11785,
267,
1240,
436,
787,
5737,
315,
314,
1056,
1245,
14,
221,
961,
1423,
267,
11479,
282,
663,
402,
790,
29,
585,
2368,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1072,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
1199,
9,
1423,
9314,
314,
6387,
1072,
402,
314,
267,
372,
666,
14,
221,
961,
1423,
11479,
1373,
402,
445,
8,
1652,
395,
445,
8,
505,
395,
267,
503,
445,
8,
1001,
680,
221,
2104,
445,
8,
1001,
395,
314,
1603,
1734,
3100,
2243,
1471,
506,
3879,
282,
267,
1015,
402,
2032,
626,
5171,
5438,
4840,
1072,
14,
272,
1415,
26,
3055,
272,
849,
26,
2748,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
8775,
3217,
2556,
1808,
8985,
523,
1335,
21003,
63,
4354,
26,
272,
8985,
26,
664,
13,
3266,
13,
11697,
272,
1249,
26,
489,
3217,
13,
354,
26,
18564,
16,
489,
5898,
26,
715,
199,
199,
13,
536,
26,
664,
2656,
2556,
523,
1335,
21003,
63,
4354,
26,
272,
8985,
26,
664,
13,
2253,
13,
11697,
199,
624,
199,
199,
9677,
275,
408,
199,
1652,
26,
523,
1369,
26,
710,
2748,
372,
1059,
687,
314,
8985,
1056,
14,
523,
2138,
26,
3544,
523,
730,
26,
1059,
199,
1199,
26,
523,
1369,
26,
710,
8985,
19687,
6702,
370,
314,
1072,
1475,
14,
523,
2138,
26,
3544,
523,
730,
26,
1059,
199,
1199,
63,
1278,
26,
523,
1369,
26,
710,
1318,
1072,
3715,
1901,
2385,
367,
1586,
3616,
14,
523,
2138,
26,
3544,
523,
730,
26,
769,
199,
624,
199,
504,
2748,
14,
9464,
14,
15325,
492,
6566,
12,
22356,
12,
370,
875,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
31959,
492,
1335,
21003,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
18242,
492,
3222,
63,
1069,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
199,
199,
4701,
63,
4227,
29367,
1309,
63,
18389,
275,
715,
421,
199,
318,
2446,
837,
272,
408,
973,
2397,
2376,
367,
2622,
859,
272,
408,
272,
1423,
63,
1650,
275,
1211,
8,
267,
8985,
29,
807,
8,
2427,
29,
549,
395,
267,
1249,
29,
807,
8,
466,
534,
807,
659,
267,
1072,
29,
807,
8,
885,
534,
1652,
297,
3415,
2968,
1652,
297,
283,
1001,
297,
283,
505,
3815,
272,
776,
339,
1423,
63,
1650,
14,
873,
8,
31959,
63,
2094,
63,
1650,
9,
339,
859,
275,
6953,
8,
2094,
63,
1650,
29,
2094,
63,
1650,
12,
2574,
5171,
63,
1074,
63,
632,
29,
797,
9,
339,
3598,
275,
769,
342,
272,
1104,
63,
589,
8,
578,
12,
3598,
9,
339,
754,
275,
791,
2489,
356,
756,
12,
283,
5451,
356,
3598,
93,
339,
8985,
275,
620,
8,
578,
14,
1162,
459,
4354,
13227,
1814,
20928,
26942,
339,
340,
1006,
1332,
578,
14,
1074,
63,
632,
12,
440,
8985,
14,
2460,
360,
362,
1333,
304,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
3197,
8985,
367,
3879,
315,
1104,
63,
632,
358,
339,
1249,
275,
859,
14,
1162,
459,
589,
418,
503,
1052,
339,
671,
3288,
275,
791,
908,
356,
859,
14,
1162,
459,
1199,
12074,
339,
1819,
275,
6566,
8,
578,
14,
1162,
459,
4354,
995,
671,
3288,
9,
339,
367,
790,
12,
574,
315,
10849,
8,
589,
304,
267,
790,
275,
620,
8,
498,
680,
1814,
20928,
26942,
267,
340,
1228,
8,
585,
12,
769,
304,
288,
367,
1242,
315,
574,
26,
355,
1982,
275,
22356,
8,
2108,
12,
790,
9,
355,
340,
1242,
365,
440,
715,
26,
490,
1982,
14,
505,
275,
1242,
267,
587,
26,
288,
1982,
275,
22356,
8,
2108,
12,
790,
9,
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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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
yashodhank/erpnext
|
erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.py
|
53
|
1922
|
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.desk.reportview import build_match_conditions
def execute(filters=None):
if not filters:
filters = {}
elif filters.get("from_date") or filters.get("to_date"):
filters["from_time"] = "00:00:00"
filters["to_time"] = "24:00:00"
columns = get_column()
conditions = get_conditions(filters)
data = get_data(conditions, filters)
return columns, data
def get_column():
return [_("Timesheet") + ":Link/Timesheet:120", _("Employee") + "::150", _("Employee Name") + "::150",
_("From Datetime") + "::140", _("To Datetime") + "::140", _("Hours") + "::70",
_("Activity Type") + "::120", _("Task") + ":Link/Task:150",
_("Project") + ":Link/Project:120", _("Status") + "::70"]
def get_data(conditions, filters):
time_sheet = frappe.db.sql(""" select `tabTimesheet`.name, `tabTimesheet`.employee, `tabTimesheet`.employee_name,
`tabTimesheet Detail`.from_time, `tabTimesheet Detail`.to_time, `tabTimesheet Detail`.hours,
`tabTimesheet Detail`.activity_type, `tabTimesheet Detail`.task, `tabTimesheet Detail`.project,
`tabTimesheet`.status from `tabTimesheet Detail`, `tabTimesheet` where
`tabTimesheet Detail`.parent = `tabTimesheet`.name and %s order by `tabTimesheet`.name"""%(conditions), filters, as_list=1)
return time_sheet
def get_conditions(filters):
conditions = "`tabTimesheet`.docstatus = 1"
if filters.get("from_date"):
conditions += " and `tabTimesheet Detail`.from_time >= timestamp(%(from_date)s, %(from_time)s)"
if filters.get("to_date"):
conditions += " and `tabTimesheet Detail`.to_time <= timestamp(%(to_date)s, %(to_time)s)"
match_conditions = build_match_conditions("Timesheet")
if match_conditions:
conditions += " and %s" % match_conditions
return conditions
|
agpl-3.0
|
[
3,
1898,
334,
67,
9,
6171,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
8417,
199,
3,
2104,
4190,
2556,
12,
8749,
1937,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
485,
199,
504,
6950,
14,
10368,
14,
3070,
1345,
492,
1900,
63,
1431,
63,
9855,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
692,
440,
4766,
26,
507,
198,
4273,
275,
1052,
199,
198,
4164,
4766,
14,
362,
480,
504,
63,
602,
531,
503,
4766,
14,
362,
480,
475,
63,
602,
2349,
507,
198,
4273,
905,
504,
63,
521,
937,
275,
298,
383,
26,
383,
26,
383,
2,
507,
198,
4273,
905,
475,
63,
521,
937,
275,
298,
1194,
26,
383,
26,
383,
2,
421,
198,
3406,
275,
664,
63,
2301,
342,
199,
198,
9855,
275,
664,
63,
9855,
8,
4273,
9,
199,
198,
576,
275,
664,
63,
576,
8,
9855,
12,
4766,
9,
421,
198,
1107,
4362,
12,
666,
199,
199,
318,
664,
63,
2301,
837,
199,
198,
1107,
359,
14332,
1366,
5069,
531,
435,
7244,
3834,
15,
1366,
5069,
26,
6708,
401,
3824,
22635,
531,
435,
27472,
8251,
401,
3824,
22635,
2812,
531,
435,
27472,
8251,
401,
11083,
198,
14332,
2532,
29825,
531,
435,
27472,
10037,
401,
3824,
1378,
29825,
531,
435,
27472,
10037,
401,
3824,
30927,
531,
435,
27472,
2760,
401,
11083,
198,
14332,
14350,
2434,
531,
435,
27472,
6708,
401,
3824,
4476,
531,
435,
7244,
3834,
15,
4476,
26,
8251,
401,
507,
198,
14332,
4761,
531,
435,
7244,
3834,
15,
4761,
26,
6708,
401,
3824,
3694,
531,
435,
27472,
2760,
937,
199,
199,
318,
664,
63,
576,
8,
9855,
12,
4766,
304,
199,
198,
521,
63,
5069,
275,
6950,
14,
697,
14,
3009,
4852,
3504,
658,
2902,
1366,
5069,
2313,
354,
12,
658,
2902,
1366,
5069,
2313,
10103,
12,
658,
2902,
1366,
5069,
2313,
10103,
63,
354,
12,
507,
198,
64,
2902,
1366,
5069,
13302,
2313,
504,
63,
521,
12,
658,
2902,
1366,
5069,
13302,
2313,
475,
63,
521,
12,
658,
2902,
1366,
5069,
13302,
2313,
8419,
12,
507,
198,
64,
2902,
1366,
5069,
13302,
2313,
8240,
63,
466,
12,
658,
2902,
1366,
5069,
13302,
2313,
1765,
12,
658,
2902,
1366,
5069,
13302,
2313,
1715,
12,
507,
198,
64,
2902,
1366,
5069,
2313,
1205,
687,
658,
2902,
1366,
5069,
13302,
3559,
658,
2902,
1366,
5069,
64,
2382,
507,
198,
64,
2902,
1366,
5069,
13302,
2313,
1708,
275,
658,
2902,
1366,
5069,
2313,
354,
436,
450,
83,
1865,
701,
658,
2902,
1366,
5069,
2313,
354,
624,
2840,
9855,
395,
4766,
12,
465,
63,
513,
29,
17,
9,
421,
198,
1107,
900,
63,
5069,
199,
199,
318,
664,
63,
9855,
8,
4273,
304,
199,
198,
9855,
275,
24505,
2902,
1366,
5069,
2313,
30461,
275,
413,
2,
199,
198,
692,
4766,
14,
362,
480,
504,
63,
602,
2349,
507,
198,
9855,
847,
298,
436,
658,
2902,
1366,
5069,
13302,
2313,
504,
63,
521,
2356,
4913,
12473,
504,
63,
602,
9,
83,
12,
2818,
504,
63,
521,
9,
83,
2924,
199,
198,
692,
4766,
14,
362,
480,
475,
63,
602,
2349,
507,
198,
9855,
847,
298,
436,
658,
2902,
1366,
5069,
13302,
2313,
475,
63,
521,
2695,
4913,
12473,
475,
63,
602,
9,
83,
12,
2818,
475,
63,
521,
9,
83,
2924,
421,
198,
1431,
63,
9855,
275,
1900,
63,
1431,
63,
9855,
480,
1366,
5069,
531,
199,
198,
692,
1336,
63,
9855,
26,
507,
198,
9855,
847,
298,
436,
450,
83,
2,
450,
1336,
63,
9855,
421,
198,
1107,
3704,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6171,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
8417,
199,
3,
2104,
4190,
2556,
12,
8749,
1937,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
485,
199,
504,
6950,
14,
10368,
14,
3070,
1345,
492,
1900,
63,
1431,
63,
9855,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
692,
440,
4766,
26,
507,
198,
4273,
275,
1052,
199,
198,
4164,
4766,
14,
362,
480,
504,
63,
602,
531,
503,
4766,
14,
362,
480,
475,
63,
602,
2349,
507,
198,
4273,
905,
504,
63,
521,
937,
275,
298,
383,
26,
383,
26,
383,
2,
507,
198,
4273,
905,
475,
63,
521,
937,
275,
298,
1194,
26,
383,
26,
383,
2,
421,
198,
3406,
275,
664,
63,
2301,
342,
199,
198,
9855,
275,
664,
63,
9855,
8,
4273,
9,
199,
198,
576,
275,
664,
63,
576,
8,
9855,
12,
4766,
9,
421,
198,
1107,
4362,
12,
666,
199,
199,
318,
664,
63,
2301,
837,
199,
198,
1107,
359,
14332,
1366,
5069,
531,
435,
7244,
3834,
15,
1366,
5069,
26,
6708,
401,
3824,
22635,
531,
435,
27472,
8251,
401,
3824,
22635,
2812,
531,
435,
27472,
8251,
401,
11083,
198,
14332,
2532,
29825,
531,
435,
27472,
10037,
401,
3824,
1378,
29825,
531,
435,
27472,
10037,
401,
3824,
30927,
531,
435,
27472,
2760,
401,
11083,
198,
14332,
14350,
2434,
531,
435,
27472,
6708,
401,
3824,
4476,
531,
435,
7244,
3834,
15,
4476,
26,
8251,
401,
507,
198,
14332,
4761,
531,
435,
7244,
3834,
15,
4761,
26,
6708,
401,
3824,
3694,
531,
435,
27472,
2760,
937,
199,
199,
318,
664,
63,
576,
8,
9855,
12,
4766,
304,
199,
198,
521,
63,
5069,
275,
6950,
14,
697,
14,
3009,
4852,
3504,
658,
2902,
1366,
5069,
2313,
354,
12,
658,
2902,
1366,
5069,
2313,
10103,
12,
658,
2902,
1366,
5069,
2313,
10103,
63,
354,
12,
507,
198,
64,
2902,
1366,
5069,
13302,
2313,
504,
63,
521,
12,
658,
2902,
1366,
5069,
13302,
2313,
475,
63,
521,
12,
658,
2902,
1366,
5069,
13302,
2313,
8419,
12,
507,
198,
64,
2902,
1366,
5069,
13302,
2313,
8240,
63,
466,
12,
658,
2902,
1366,
5069,
13302,
2313,
1765,
12,
658,
2902,
1366,
5069,
13302,
2313,
1715,
12,
507,
198,
64,
2902,
1366,
5069,
2313,
1205,
687,
658,
2902,
1366,
5069,
13302,
3559,
658,
2902,
1366,
5069,
64,
2382,
507,
198,
64,
2902,
1366,
5069,
13302,
2313,
1708,
275,
658,
2902,
1366,
5069,
2313,
354,
436,
450,
83,
1865,
701,
658,
2902,
1366,
5069,
2313,
354,
624,
2840,
9855,
395,
4766,
12,
465,
63,
513,
29,
17,
9,
421,
198,
1107,
900,
63,
5069,
199,
199,
318,
664,
63,
9855,
8,
4273,
304,
199,
198,
9855,
275,
24505,
2902,
1366,
5069,
2313,
30461,
275,
413,
2,
199,
198,
692,
4766,
14,
362,
480,
504,
63,
602,
2349,
507,
198,
9855,
847,
298,
436,
658,
2902,
1366,
5069,
13302,
2313,
504,
63,
521,
2356,
4913,
12473,
504,
63,
602,
9,
83,
12,
2818,
504,
63,
521,
9,
83,
2924,
199,
198,
692,
4766,
14,
362,
480,
475,
63,
602,
2349,
507,
198,
9855,
847,
298,
436,
658,
2902,
1366,
5069,
13302,
2313,
475,
63,
521,
2695,
4913,
12473,
475,
63,
602,
9,
83,
12,
2818,
475,
63,
521,
9,
83,
2924,
421,
198,
1431,
63,
9855,
275,
1900,
63,
1431,
63,
9855,
480,
1366,
5069,
531,
199,
198,
692,
1336,
63,
9855,
26,
507,
198,
9855,
847,
298,
436,
450,
83,
2,
450,
1336,
63,
9855,
421,
198,
1107,
3704,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
kuri65536/python-for-android
|
python-modules/twisted/twisted/internet/test/fakeendpoint.py
|
49
|
1484
|
# -*- test-case-name: twisted.internet.test.test_endpoints -*-
# Copyright (c) 2010 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Fake client and server endpoint string parser plugins for testing purposes.
"""
from zope.interface.declarations import implements
from twisted.plugin import IPlugin
from twisted.internet.interfaces import (IStreamClientEndpoint,
IStreamServerEndpoint,
IStreamClientEndpointStringParser,
IStreamServerEndpointStringParser)
class PluginBase(object):
implements(IPlugin)
def __init__(self, pfx):
self.prefix = pfx
class FakeClientParser(PluginBase):
implements(IStreamClientEndpointStringParser)
def parseStreamClient(self, *a, **kw):
return StreamClient(self, a, kw)
class FakeParser(PluginBase):
implements(IStreamServerEndpointStringParser)
def parseStreamServer(self, *a, **kw):
return StreamServer(self, a, kw)
class EndpointBase(object):
def __init__(self, parser, args, kwargs):
self.parser = parser
self.args = args
self.kwargs = kwargs
class StreamClient(EndpointBase):
implements(IStreamClientEndpoint)
class StreamServer(EndpointBase):
implements(IStreamServerEndpoint)
# Instantiate plugin interface providers to register them.
fake = FakeParser('fake')
fakeClient = FakeClientParser('cfake')
|
apache-2.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
4901,
14,
396,
14,
396,
63,
14461,
1882,
199,
3,
1898,
334,
67,
9,
7129,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
8249,
1890,
436,
1654,
6037,
1059,
1798,
8963,
367,
5343,
12901,
14,
199,
624,
199,
199,
504,
20110,
14,
3266,
14,
21200,
492,
9031,
199,
504,
7390,
14,
2718,
492,
3531,
76,
1632,
199,
504,
7390,
14,
4901,
14,
7436,
492,
334,
41,
3296,
3041,
11442,
12,
1460,
473,
3296,
3120,
11442,
12,
1460,
473,
3296,
3041,
11442,
1558,
2842,
12,
1460,
473,
3296,
3120,
11442,
1558,
2842,
9,
199,
199,
533,
11349,
1563,
8,
785,
304,
272,
9031,
8,
1772,
76,
1632,
9,
339,
347,
636,
826,
721,
277,
12,
299,
12220,
304,
267,
291,
14,
1861,
275,
299,
12220,
4388,
199,
533,
7777,
3041,
2842,
8,
5061,
1563,
304,
339,
9031,
8,
41,
3296,
3041,
11442,
1558,
2842,
9,
339,
347,
2198,
3296,
3041,
8,
277,
12,
627,
65,
12,
1011,
829,
304,
267,
372,
8271,
3041,
8,
277,
12,
282,
12,
4775,
9,
4388,
199,
533,
7777,
2842,
8,
5061,
1563,
304,
339,
9031,
8,
41,
3296,
3120,
11442,
1558,
2842,
9,
339,
347,
2198,
3296,
3120,
8,
277,
12,
627,
65,
12,
1011,
829,
304,
267,
372,
8271,
3120,
8,
277,
12,
282,
12,
4775,
9,
4388,
199,
533,
9599,
1403,
1563,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1798,
12,
1249,
12,
2074,
304,
267,
291,
14,
2087,
275,
1798,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
4388,
199,
533,
8271,
3041,
8,
11442,
1563,
304,
339,
9031,
8,
41,
3296,
3041,
11442,
9,
4388,
199,
533,
8271,
3120,
8,
11442,
1563,
304,
339,
9031,
8,
41,
3296,
3120,
11442,
9,
4388,
199,
3,
32092,
3589,
3217,
18032,
370,
2274,
3062,
14,
199,
3183,
275,
7777,
2842,
360,
3183,
358,
199,
3183,
3041,
275,
7777,
3041,
2842,
360,
67,
3183,
358,
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
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
4901,
14,
396,
14,
396,
63,
14461,
1882,
199,
3,
1898,
334,
67,
9,
7129,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
8249,
1890,
436,
1654,
6037,
1059,
1798,
8963,
367,
5343,
12901,
14,
199,
624,
199,
199,
504,
20110,
14,
3266,
14,
21200,
492,
9031,
199,
504,
7390,
14,
2718,
492,
3531,
76,
1632,
199,
504,
7390,
14,
4901,
14,
7436,
492,
334,
41,
3296,
3041,
11442,
12,
1460,
473,
3296,
3120,
11442,
12,
1460,
473,
3296,
3041,
11442,
1558,
2842,
12,
1460,
473,
3296,
3120,
11442,
1558,
2842,
9,
199,
199,
533,
11349,
1563,
8,
785,
304,
272,
9031,
8,
1772,
76,
1632,
9,
339,
347,
636,
826,
721,
277,
12,
299,
12220,
304,
267,
291,
14,
1861,
275,
299,
12220,
4388,
199,
533,
7777,
3041,
2842,
8,
5061,
1563,
304,
339,
9031,
8,
41,
3296,
3041,
11442,
1558,
2842,
9,
339,
347,
2198,
3296,
3041,
8,
277,
12,
627,
65,
12,
1011,
829,
304,
267,
372,
8271,
3041,
8,
277,
12,
282,
12,
4775,
9,
4388,
199,
533,
7777,
2842,
8,
5061,
1563,
304,
339,
9031,
8,
41,
3296,
3120,
11442,
1558,
2842,
9,
339,
347,
2198,
3296,
3120,
8,
277,
12,
627,
65,
12,
1011,
829,
304,
267,
372,
8271,
3120,
8,
277,
12,
282,
12,
4775,
9,
4388,
199,
533,
9599,
1403,
1563,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1798,
12,
1249,
12,
2074,
304,
267,
291,
14,
2087,
275,
1798,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
4388,
199,
533,
8271,
3041,
8,
11442,
1563,
304,
339,
9031,
8,
41,
3296,
3041,
11442,
9,
4388,
199,
533,
8271,
3120,
8,
11442,
1563,
304,
339,
9031,
8,
41,
3296,
3120,
11442,
9,
4388,
199,
3,
32092,
3589,
3217,
18032,
370,
2274,
3062,
14,
199,
3183,
275,
7777,
2842,
360,
3183,
358,
199,
3183,
3041,
275,
7777,
3041,
2842,
360,
67,
3183,
358,
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,
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,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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
] |
Wilbeibi/rethinkdb
|
external/v8_3.30.33.16/tools/push-to-trunk/script_test.py
|
95
|
2294
|
#!/usr/bin/env python
# Copyright 2014 the V8 project authors. 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.
# Wraps test execution with a coverage analysis. To get the best speed, the
# native python coverage version >= 3.7.1 should be installed.
import coverage
import os
import unittest
import sys
def Main(argv):
script_path = os.path.dirname(os.path.abspath(__file__))
cov = coverage.coverage(include=([os.path.join(script_path, '*.py')]))
cov.start()
import test_scripts
alltests = map(unittest.TestLoader().loadTestsFromTestCase, [
test_scripts.ToplevelTest,
test_scripts.ScriptTest,
test_scripts.SystemTest,
])
unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(alltests))
cov.stop()
print cov.report()
if __name__ == '__main__':
sys.exit(Main(sys.argv))
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6927,
314,
812,
24,
2199,
11462,
14,
2900,
4481,
4644,
14,
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,
755,
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,
755,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
755,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
755,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
755,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
755,
687,
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,
3,
644,
8146,
511,
6451,
543,
282,
11745,
11284,
14,
4005,
664,
314,
5526,
8112,
12,
314,
199,
3,
5438,
2366,
11745,
1015,
2356,
650,
14,
23,
14,
17,
1077,
506,
4903,
14,
199,
199,
646,
11745,
199,
646,
747,
199,
646,
2882,
199,
646,
984,
421,
199,
318,
11298,
8,
3020,
304,
523,
2884,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
523,
13786,
275,
11745,
14,
10828,
8,
2613,
30982,
736,
14,
515,
14,
904,
8,
1579,
63,
515,
12,
11937,
647,
358,
2459,
523,
13786,
14,
928,
342,
523,
492,
511,
63,
6429,
523,
1006,
2219,
275,
2341,
8,
2796,
14,
15824,
1252,
26946,
12,
359,
272,
511,
63,
6429,
14,
6105,
1896,
774,
12,
272,
511,
63,
6429,
14,
5229,
774,
12,
272,
511,
63,
6429,
14,
3989,
774,
12,
523,
4794,
523,
2882,
14,
24285,
8,
9833,
29,
18,
680,
1065,
8,
2796,
14,
10591,
8,
452,
2219,
430,
523,
13786,
14,
2379,
342,
523,
870,
13786,
14,
3070,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
6756,
8,
1274,
14,
3020,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6927,
314,
812,
24,
2199,
11462,
14,
2900,
4481,
4644,
14,
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,
755,
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,
755,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
755,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
755,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
755,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
755,
687,
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,
3,
644,
8146,
511,
6451,
543,
282,
11745,
11284,
14,
4005,
664,
314,
5526,
8112,
12,
314,
199,
3,
5438,
2366,
11745,
1015,
2356,
650,
14,
23,
14,
17,
1077,
506,
4903,
14,
199,
199,
646,
11745,
199,
646,
747,
199,
646,
2882,
199,
646,
984,
421,
199,
318,
11298,
8,
3020,
304,
523,
2884,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
523,
13786,
275,
11745,
14,
10828,
8,
2613,
30982,
736,
14,
515,
14,
904,
8,
1579,
63,
515,
12,
11937,
647,
358,
2459,
523,
13786,
14,
928,
342,
523,
492,
511,
63,
6429,
523,
1006,
2219,
275,
2341,
8,
2796,
14,
15824,
1252,
26946,
12,
359,
272,
511,
63,
6429,
14,
6105,
1896,
774,
12,
272,
511,
63,
6429,
14,
5229,
774,
12,
272,
511,
63,
6429,
14,
3989,
774,
12,
523,
4794,
523,
2882,
14,
24285,
8,
9833,
29,
18,
680,
1065,
8,
2796,
14,
10591,
8,
452,
2219,
430,
523,
13786,
14,
2379,
342,
523,
870,
13786,
14,
3070,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
6756,
8,
1274,
14,
3020,
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,
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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.net/date for format strings
Usage:
>>> import datetime
>>> d = datetime.datetime.now()
>>> df = DateFormat(d)
>>> print df.format('jS F Y H:i')
7th October 2003 11:39
>>>
"""
import re
import time
import calendar
from django.utils.dates import MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
from django.utils.tzinfo import LocalTimezone
from django.utils.translation import ugettext as _
from django.utils.encoding import force_unicode
re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
re_escaped = re.compile(r'\\(.)')
class Formatter(object):
def format(self, formatstr):
pieces = []
for i, piece in enumerate(re_formatchars.split(force_unicode(formatstr))):
if i % 2:
pieces.append(force_unicode(getattr(self, piece)()))
elif piece:
pieces.append(re_escaped.sub(r'\1', piece))
return u''.join(pieces)
class TimeFormat(Formatter):
def __init__(self, t):
self.data = t
def a(self):
"'a.m.' or 'p.m.'"
if self.data.hour > 11:
return _('p.m.')
return _('a.m.')
def A(self):
"'AM' or 'PM'"
if self.data.hour > 11:
return _('PM')
return _('AM')
def B(self):
"Swatch Internet time"
raise NotImplementedError
def f(self):
"""
Time, in 12-hour hours and minutes, with minutes left off if they're
zero.
Examples: '1', '1:30', '2:05', '2'
Proprietary extension.
"""
if self.data.minute == 0:
return self.g()
return u'%s:%s' % (self.g(), self.i())
def g(self):
"Hour, 12-hour format without leading zeros; i.e. '1' to '12'"
if self.data.hour == 0:
return 12
if self.data.hour > 12:
return self.data.hour - 12
return self.data.hour
def G(self):
"Hour, 24-hour format without leading zeros; i.e. '0' to '23'"
return self.data.hour
def h(self):
"Hour, 12-hour format; i.e. '01' to '12'"
return u'%02d' % self.g()
def H(self):
"Hour, 24-hour format; i.e. '00' to '23'"
return u'%02d' % self.G()
def i(self):
"Minutes; i.e. '00' to '59'"
return u'%02d' % self.data.minute
def P(self):
"""
Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off
if they're zero and the strings 'midnight' and 'noon' if appropriate.
Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
Proprietary extension.
"""
if self.data.minute == 0 and self.data.hour == 0:
return _('midnight')
if self.data.minute == 0 and self.data.hour == 12:
return _('noon')
return u'%s %s' % (self.f(), self.a())
def s(self):
"Seconds; i.e. '00' to '59'"
return u'%02d' % self.data.second
def u(self):
"Microseconds"
return self.data.microsecond
class DateFormat(TimeFormat):
year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
def __init__(self, dt):
# Accepts either a datetime or date object.
self.data = dt
self.timezone = getattr(dt, 'tzinfo', None)
if hasattr(self.data, 'hour') and not self.timezone:
self.timezone = LocalTimezone(dt)
def b(self):
"Month, textual, 3 letters, lowercase; e.g. 'jan'"
return MONTHS_3[self.data.month]
def c(self):
"""
ISO 8601 Format
Example : '2008-01-02T10:30:00.000123'
"""
return self.data.isoformat()
def d(self):
"Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"
return u'%02d' % self.data.day
def D(self):
"Day of the week, textual, 3 letters; e.g. 'Fri'"
return WEEKDAYS_ABBR[self.data.weekday()]
def E(self):
"Alternative month names as required by some locales. Proprietary extension."
return MONTHS_ALT[self.data.month]
def F(self):
"Month, textual, long; e.g. 'January'"
return MONTHS[self.data.month]
def I(self):
"'1' if Daylight Savings Time, '0' otherwise."
if self.timezone and self.timezone.dst(self.data):
return u'1'
else:
return u'0'
def j(self):
"Day of the month without leading zeros; i.e. '1' to '31'"
return self.data.day
def l(self):
"Day of the week, textual, long; e.g. 'Friday'"
return WEEKDAYS[self.data.weekday()]
def L(self):
"Boolean for whether it is a leap year; i.e. True or False"
return calendar.isleap(self.data.year)
def m(self):
"Month; i.e. '01' to '12'"
return u'%02d' % self.data.month
def M(self):
"Month, textual, 3 letters; e.g. 'Jan'"
return MONTHS_3[self.data.month].title()
def n(self):
"Month without leading zeros; i.e. '1' to '12'"
return self.data.month
def N(self):
"Month abbreviation in Associated Press style. Proprietary extension."
return MONTHS_AP[self.data.month]
def O(self):
"Difference to Greenwich time in hours; e.g. '+0200'"
seconds = self.Z()
return u"%+03d%02d" % (seconds // 3600, (seconds // 60) % 60)
def r(self):
"RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'"
return self.format('D, j M Y H:i:s O')
def S(self):
"English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'"
if self.data.day in (11, 12, 13): # Special case
return u'th'
last = self.data.day % 10
if last == 1:
return u'st'
if last == 2:
return u'nd'
if last == 3:
return u'rd'
return u'th'
def t(self):
"Number of days in the given month; i.e. '28' to '31'"
return u'%02d' % calendar.monthrange(self.data.year, self.data.month)[1]
def T(self):
"Time zone of this machine; e.g. 'EST' or 'MDT'"
name = self.timezone and self.timezone.tzname(self.data) or None
if name is None:
name = self.format('O')
return unicode(name)
def U(self):
"Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"
if getattr(self.data, 'tzinfo', None):
return int(calendar.timegm(self.data.utctimetuple()))
else:
return int(time.mktime(self.data.timetuple()))
def w(self):
"Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)"
return (self.data.weekday() + 1) % 7
def W(self):
"ISO-8601 week number of year, weeks starting on Monday"
# Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
week_number = None
jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
weekday = self.data.weekday() + 1
day_of_year = self.z()
if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year-1)):
week_number = 53
else:
week_number = 52
else:
if calendar.isleap(self.data.year):
i = 366
else:
i = 365
if (i - day_of_year) < (4 - weekday):
week_number = 1
else:
j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
week_number = j // 7
if jan1_weekday > 4:
week_number -= 1
return week_number
def y(self):
"Year, 2 digits; e.g. '99'"
return unicode(self.data.year)[2:]
def Y(self):
"Year, 4 digits; e.g. '1999'"
return self.data.year
def z(self):
"Day of the year; i.e. '0' to '365'"
doy = self.year_days[self.data.month] + self.data.day
if self.L() and self.data.month > 2:
doy += 1
return doy
def Z(self):
"""
Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for
timezones west of UTC is always negative, and for those east of UTC is
always positive.
"""
if not self.timezone:
return 0
offset = self.timezone.utcoffset(self.data)
# Only days can be negative, so negative offsets have days=-1 and
# seconds positive. Positive offsets have days=0
return offset.days * 86400 + offset.seconds
def format(value, format_string):
"Convenience function"
df = DateFormat(value)
return df.format(format_string)
def time_format(value, format_string):
"Convenience function"
tf = TimeFormat(value)
return tf.format(format_string)
|
bsd-3-clause
|
[
624,
199,
31300,
1434,
342,
3449,
1434,
10803,
199,
9295,
1455,
921,
1544,
14,
8624,
14,
846,
15,
602,
367,
1475,
3326,
199,
199,
7692,
26,
199,
6071,
492,
2197,
199,
6071,
366,
275,
2197,
14,
2083,
14,
2131,
342,
199,
6071,
4051,
275,
6148,
3484,
8,
68,
9,
199,
6071,
870,
4051,
14,
908,
360,
74,
51,
481,
1488,
869,
26,
73,
358,
199,
23,
273,
18365,
22459,
13004,
4119,
26,
1355,
199,
6071,
199,
624,
199,
199,
646,
295,
199,
646,
900,
199,
646,
11234,
199,
504,
1639,
14,
1208,
14,
9356,
492,
603,
615,
2080,
51,
12,
603,
615,
2080,
51,
63,
19,
12,
603,
615,
2080,
51,
63,
19600,
12,
603,
615,
2080,
51,
63,
1282,
12,
644,
8699,
43,
25683,
12,
644,
8699,
43,
25683,
63,
1217,
7184,
199,
504,
1639,
14,
1208,
14,
9374,
492,
10111,
28705,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2975,
199,
199,
264,
63,
908,
6574,
275,
295,
14,
2014,
8,
82,
10120,
11230,
1103,
31440,
65,
5583,
34,
2866,
1093,
70,
38,
71,
39,
72,
16106,
41,
74,
76,
23041,
45,
78,
46,
1938,
2393,
933,
21364,
29638,
55,
89,
30879,
58,
566,
358,
199,
264,
63,
13572,
275,
295,
14,
2014,
8,
82,
8124,
8,
4959,
358,
199,
199,
533,
31084,
8,
785,
304,
272,
347,
1475,
8,
277,
12,
1475,
495,
304,
267,
10338,
275,
942,
267,
367,
284,
12,
14854,
315,
3874,
8,
264,
63,
908,
6574,
14,
1294,
8,
3990,
63,
2975,
8,
908,
495,
15206,
288,
340,
284,
450,
499,
26,
355,
10338,
14,
740,
8,
3990,
63,
2975,
8,
5675,
8,
277,
12,
14854,
9,
4059,
288,
916,
14854,
26,
355,
10338,
14,
740,
8,
264,
63,
13572,
14,
954,
8,
82,
1154,
17,
297,
14854,
430,
267,
372,
399,
17067,
904,
8,
15655,
9,
199,
199,
533,
4703,
3484,
8,
7772,
304,
272,
347,
636,
826,
721,
277,
12,
307,
304,
267,
291,
14,
576,
275,
307,
339,
347,
282,
8,
277,
304,
267,
3546,
65,
14,
77,
3530,
503,
283,
80,
14,
77,
3530,
2,
267,
340,
291,
14,
576,
14,
5180,
690,
4119,
26,
288,
372,
4018,
80,
14,
77,
2659,
267,
372,
4018,
65,
14,
77,
2659,
339,
347,
437,
8,
277,
304,
267,
3546,
1156,
7,
503,
283,
10793,
4065,
267,
340,
291,
14,
576,
14,
5180,
690,
4119,
26,
288,
372,
4018,
10793,
358,
267,
372,
4018,
1156,
358,
339,
347,
699,
8,
277,
304,
267,
298,
51,
6821,
22026,
900,
2,
267,
746,
4279,
339,
347,
289,
8,
277,
304,
267,
408,
267,
4703,
12,
315,
3144,
13,
5180,
10857,
436,
9395,
12,
543,
9395,
3602,
2331,
340,
2985,
3984,
267,
4697,
14,
267,
6058,
26,
283,
17,
297,
283,
17,
26,
1216,
297,
283,
18,
26,
1717,
297,
283,
18,
7,
267,
2165,
1359,
386,
695,
3329,
14,
267,
408,
267,
340,
291,
14,
576,
14,
10698,
508,
378,
26,
288,
372,
291,
14,
71,
342,
267,
372,
399,
5956,
83,
2689,
83,
7,
450,
334,
277,
14,
71,
1062,
291,
14,
73,
1012,
339,
347,
486,
8,
277,
304,
267,
298,
24246,
12,
3144,
13,
5180,
1475,
1928,
9186,
10136,
27,
284,
14,
69,
14,
283,
17,
7,
370,
283,
713,
4065,
267,
340,
291,
14,
576,
14,
5180,
508,
378,
26,
288,
372,
3144,
267,
340,
291,
14,
576,
14,
5180,
690,
3144,
26,
288,
372,
291,
14,
576,
14,
5180,
446,
3144,
267,
372,
291,
14,
576,
14,
5180,
339,
347,
598,
8,
277,
304,
267,
298,
24246,
12,
5504,
13,
5180,
1475,
1928,
9186,
10136,
27,
284,
14,
69,
14,
283,
16,
7,
370,
283,
1789,
4065,
267,
372,
291,
14,
576,
14,
5180,
339,
347,
394,
8,
277,
304,
267,
298,
24246,
12,
3144,
13,
5180,
1475,
27,
284,
14,
69,
14,
283,
614,
7,
370,
283,
713,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
71,
342,
339,
347,
869,
8,
277,
304,
267,
298,
24246,
12,
5504,
13,
5180,
1475,
27,
284,
14,
69,
14,
283,
383,
7,
370,
283,
1789,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
39,
342,
339,
347,
284,
8,
277,
304,
267,
298,
4649,
3862,
27,
284,
14,
69,
14,
283,
383,
7,
370,
283,
1427,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
576,
14,
10698,
339,
347,
510,
8,
277,
304,
267,
408,
267,
4703,
12,
315,
3144,
13,
5180,
10857,
12,
9395,
436,
283,
65,
14,
77,
3530,
4805,
80,
14,
77,
3130,
543,
9395,
3602,
2331,
267,
340,
2985,
3984,
4697,
436,
314,
3326,
283,
8523,
14873,
7,
436,
283,
889,
265,
7,
340,
5827,
14,
267,
6058,
26,
283,
17,
282,
14,
77,
3130,
283,
17,
26,
1216,
299,
14,
77,
3130,
283,
8523,
14873,
297,
283,
889,
265,
297,
283,
713,
26,
1216,
299,
14,
77,
3530,
267,
2165,
1359,
386,
695,
3329,
14,
267,
408,
267,
340,
291,
14,
576,
14,
10698,
508,
378,
436,
291,
14,
576,
14,
5180,
508,
378,
26,
288,
372,
4018,
8523,
14873,
358,
267,
340,
291,
14,
576,
14,
10698,
508,
378,
436,
291,
14,
576,
14,
5180,
508,
3144,
26,
288,
372,
4018,
889,
265,
358,
267,
372,
399,
5956,
83,
450,
83,
7,
450,
334,
277,
14,
70,
1062,
291,
14,
65,
1012,
339,
347,
308,
8,
277,
304,
267,
298,
13165,
27,
284,
14,
69,
14,
283,
383,
7,
370,
283,
1427,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
576,
14,
4375,
339,
347,
399,
8,
277,
304,
267,
298,
23990,
4515,
2,
267,
372,
291,
14,
576,
14,
16627,
421,
199,
533,
6148,
3484,
8,
1366,
3484,
304,
272,
5361,
63,
4899,
275,
359,
403,
12,
378,
12,
7105,
12,
8155,
12,
9137,
12,
13960,
12,
413,
2869,
12,
413,
2835,
12,
29532,
12,
499,
2824,
12,
499,
2898,
12,
20398,
12,
650,
1082,
61,
339,
347,
636,
826,
721,
277,
12,
4487,
304,
267,
327,
15506,
83,
1902,
282,
2197,
503,
1434,
909,
14,
267,
291,
14,
576,
275,
4487
] |
[
199,
31300,
1434,
342,
3449,
1434,
10803,
199,
9295,
1455,
921,
1544,
14,
8624,
14,
846,
15,
602,
367,
1475,
3326,
199,
199,
7692,
26,
199,
6071,
492,
2197,
199,
6071,
366,
275,
2197,
14,
2083,
14,
2131,
342,
199,
6071,
4051,
275,
6148,
3484,
8,
68,
9,
199,
6071,
870,
4051,
14,
908,
360,
74,
51,
481,
1488,
869,
26,
73,
358,
199,
23,
273,
18365,
22459,
13004,
4119,
26,
1355,
199,
6071,
199,
624,
199,
199,
646,
295,
199,
646,
900,
199,
646,
11234,
199,
504,
1639,
14,
1208,
14,
9356,
492,
603,
615,
2080,
51,
12,
603,
615,
2080,
51,
63,
19,
12,
603,
615,
2080,
51,
63,
19600,
12,
603,
615,
2080,
51,
63,
1282,
12,
644,
8699,
43,
25683,
12,
644,
8699,
43,
25683,
63,
1217,
7184,
199,
504,
1639,
14,
1208,
14,
9374,
492,
10111,
28705,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2975,
199,
199,
264,
63,
908,
6574,
275,
295,
14,
2014,
8,
82,
10120,
11230,
1103,
31440,
65,
5583,
34,
2866,
1093,
70,
38,
71,
39,
72,
16106,
41,
74,
76,
23041,
45,
78,
46,
1938,
2393,
933,
21364,
29638,
55,
89,
30879,
58,
566,
358,
199,
264,
63,
13572,
275,
295,
14,
2014,
8,
82,
8124,
8,
4959,
358,
199,
199,
533,
31084,
8,
785,
304,
272,
347,
1475,
8,
277,
12,
1475,
495,
304,
267,
10338,
275,
942,
267,
367,
284,
12,
14854,
315,
3874,
8,
264,
63,
908,
6574,
14,
1294,
8,
3990,
63,
2975,
8,
908,
495,
15206,
288,
340,
284,
450,
499,
26,
355,
10338,
14,
740,
8,
3990,
63,
2975,
8,
5675,
8,
277,
12,
14854,
9,
4059,
288,
916,
14854,
26,
355,
10338,
14,
740,
8,
264,
63,
13572,
14,
954,
8,
82,
1154,
17,
297,
14854,
430,
267,
372,
399,
17067,
904,
8,
15655,
9,
199,
199,
533,
4703,
3484,
8,
7772,
304,
272,
347,
636,
826,
721,
277,
12,
307,
304,
267,
291,
14,
576,
275,
307,
339,
347,
282,
8,
277,
304,
267,
3546,
65,
14,
77,
3530,
503,
283,
80,
14,
77,
3530,
2,
267,
340,
291,
14,
576,
14,
5180,
690,
4119,
26,
288,
372,
4018,
80,
14,
77,
2659,
267,
372,
4018,
65,
14,
77,
2659,
339,
347,
437,
8,
277,
304,
267,
3546,
1156,
7,
503,
283,
10793,
4065,
267,
340,
291,
14,
576,
14,
5180,
690,
4119,
26,
288,
372,
4018,
10793,
358,
267,
372,
4018,
1156,
358,
339,
347,
699,
8,
277,
304,
267,
298,
51,
6821,
22026,
900,
2,
267,
746,
4279,
339,
347,
289,
8,
277,
304,
267,
408,
267,
4703,
12,
315,
3144,
13,
5180,
10857,
436,
9395,
12,
543,
9395,
3602,
2331,
340,
2985,
3984,
267,
4697,
14,
267,
6058,
26,
283,
17,
297,
283,
17,
26,
1216,
297,
283,
18,
26,
1717,
297,
283,
18,
7,
267,
2165,
1359,
386,
695,
3329,
14,
267,
408,
267,
340,
291,
14,
576,
14,
10698,
508,
378,
26,
288,
372,
291,
14,
71,
342,
267,
372,
399,
5956,
83,
2689,
83,
7,
450,
334,
277,
14,
71,
1062,
291,
14,
73,
1012,
339,
347,
486,
8,
277,
304,
267,
298,
24246,
12,
3144,
13,
5180,
1475,
1928,
9186,
10136,
27,
284,
14,
69,
14,
283,
17,
7,
370,
283,
713,
4065,
267,
340,
291,
14,
576,
14,
5180,
508,
378,
26,
288,
372,
3144,
267,
340,
291,
14,
576,
14,
5180,
690,
3144,
26,
288,
372,
291,
14,
576,
14,
5180,
446,
3144,
267,
372,
291,
14,
576,
14,
5180,
339,
347,
598,
8,
277,
304,
267,
298,
24246,
12,
5504,
13,
5180,
1475,
1928,
9186,
10136,
27,
284,
14,
69,
14,
283,
16,
7,
370,
283,
1789,
4065,
267,
372,
291,
14,
576,
14,
5180,
339,
347,
394,
8,
277,
304,
267,
298,
24246,
12,
3144,
13,
5180,
1475,
27,
284,
14,
69,
14,
283,
614,
7,
370,
283,
713,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
71,
342,
339,
347,
869,
8,
277,
304,
267,
298,
24246,
12,
5504,
13,
5180,
1475,
27,
284,
14,
69,
14,
283,
383,
7,
370,
283,
1789,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
39,
342,
339,
347,
284,
8,
277,
304,
267,
298,
4649,
3862,
27,
284,
14,
69,
14,
283,
383,
7,
370,
283,
1427,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
576,
14,
10698,
339,
347,
510,
8,
277,
304,
267,
408,
267,
4703,
12,
315,
3144,
13,
5180,
10857,
12,
9395,
436,
283,
65,
14,
77,
3530,
4805,
80,
14,
77,
3130,
543,
9395,
3602,
2331,
267,
340,
2985,
3984,
4697,
436,
314,
3326,
283,
8523,
14873,
7,
436,
283,
889,
265,
7,
340,
5827,
14,
267,
6058,
26,
283,
17,
282,
14,
77,
3130,
283,
17,
26,
1216,
299,
14,
77,
3130,
283,
8523,
14873,
297,
283,
889,
265,
297,
283,
713,
26,
1216,
299,
14,
77,
3530,
267,
2165,
1359,
386,
695,
3329,
14,
267,
408,
267,
340,
291,
14,
576,
14,
10698,
508,
378,
436,
291,
14,
576,
14,
5180,
508,
378,
26,
288,
372,
4018,
8523,
14873,
358,
267,
340,
291,
14,
576,
14,
10698,
508,
378,
436,
291,
14,
576,
14,
5180,
508,
3144,
26,
288,
372,
4018,
889,
265,
358,
267,
372,
399,
5956,
83,
450,
83,
7,
450,
334,
277,
14,
70,
1062,
291,
14,
65,
1012,
339,
347,
308,
8,
277,
304,
267,
298,
13165,
27,
284,
14,
69,
14,
283,
383,
7,
370,
283,
1427,
4065,
267,
372,
399,
5956,
996,
68,
7,
450,
291,
14,
576,
14,
4375,
339,
347,
399,
8,
277,
304,
267,
298,
23990,
4515,
2,
267,
372,
291,
14,
576,
14,
16627,
421,
199,
533,
6148,
3484,
8,
1366,
3484,
304,
272,
5361,
63,
4899,
275,
359,
403,
12,
378,
12,
7105,
12,
8155,
12,
9137,
12,
13960,
12,
413,
2869,
12,
413,
2835,
12,
29532,
12,
499,
2824,
12,
499,
2898,
12,
20398,
12,
650,
1082,
61,
339,
347,
636,
826,
721,
277,
12,
4487,
304,
267,
327,
15506,
83,
1902,
282,
2197,
503,
1434,
909,
14,
267,
291,
14,
576,
275,
4487,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ESOedX/edx-platform
|
lms/djangoapps/shoppingcart/context_processor.py
|
19
|
1677
|
"""
This is the shoppingcart context_processor module.
Currently the only context_processor detects whether request.user has a cart that should be displayed in the
navigation. We want to do this in the context_processor to
1) keep database accesses out of templates (this led to a transaction bug with user email changes)
2) because navigation.html is "called" by being included in other templates, there's no "views.py" to put this.
"""
from .models import CourseRegCodeItem, Order, PaidCourseRegistration
from .utils import is_shopping_cart_enabled
def user_has_cart_context_processor(request):
"""
Checks if request has an authenticated user. If so, checks if request.user has a cart that should
be displayed. Anonymous users don't.
Adds `display_shopping_cart` to the context
"""
def should_display_shopping_cart():
"""
Returns a boolean if the user has an items in a cart whereby the shopping cart should be
displayed to the logged in user
"""
return (
# user is logged in and
request.user.is_authenticated and
# do we have the feature turned on
is_shopping_cart_enabled() and
# does the user actually have a cart (optimized query to prevent creation of a cart when not needed)
Order.does_user_have_cart(request.user) and
# user's cart has PaidCourseRegistrations or CourseRegCodeItem
Order.user_cart_has_items(
request.user,
[PaidCourseRegistration, CourseRegCodeItem]
)
)
return {'should_display_shopping_cart_func': should_display_shopping_cart}
|
agpl-3.0
|
[
624,
199,
2765,
365,
314,
25630,
4073,
8153,
1067,
63,
6459,
859,
14,
199,
31499,
314,
1454,
1067,
63,
6459,
477,
28853,
3775,
1056,
14,
751,
965,
282,
16942,
626,
1077,
506,
9080,
315,
314,
199,
24148,
14,
221,
2136,
2934,
370,
886,
642,
315,
314,
1067,
63,
6459,
370,
199,
17,
9,
4215,
3050,
1066,
5804,
734,
402,
7009,
334,
3749,
29239,
370,
282,
6008,
6519,
543,
922,
3031,
4493,
9,
199,
18,
9,
2952,
19191,
14,
1360,
365,
298,
3527,
2,
701,
3769,
5120,
315,
1163,
7009,
12,
2337,
1159,
949,
298,
4196,
14,
647,
2,
370,
5324,
642,
14,
199,
624,
199,
199,
504,
1275,
992,
492,
5531,
2872,
3034,
2081,
12,
9240,
12,
10164,
344,
6979,
11757,
199,
504,
1275,
1208,
492,
365,
63,
15842,
63,
8153,
63,
3827,
421,
199,
318,
922,
63,
1989,
63,
8153,
63,
1100,
63,
6459,
8,
1069,
304,
272,
408,
272,
13813,
340,
1056,
965,
376,
15082,
922,
14,
221,
982,
880,
12,
5920,
340,
1056,
14,
751,
965,
282,
16942,
626,
1077,
272,
506,
9080,
14,
221,
24523,
4390,
2793,
1133,
14,
272,
15747,
658,
2918,
63,
15842,
63,
8153,
64,
370,
314,
1067,
272,
408,
272,
347,
1077,
63,
2918,
63,
15842,
63,
8153,
837,
267,
408,
267,
1803,
282,
5046,
340,
314,
922,
965,
376,
2974,
315,
282,
16942,
2382,
991,
314,
25630,
4073,
16942,
1077,
506,
267,
9080,
370,
314,
10367,
315,
922,
267,
408,
267,
372,
334,
288,
327,
922,
365,
10367,
315,
436,
288,
1056,
14,
751,
14,
374,
63,
12177,
436,
288,
327,
886,
781,
1172,
314,
3878,
19136,
641,
288,
365,
63,
15842,
63,
8153,
63,
3827,
342,
436,
288,
327,
1630,
314,
922,
5965,
1172,
282,
16942,
334,
25499,
1827,
370,
7981,
7143,
402,
282,
16942,
1380,
440,
4346,
9,
288,
9240,
14,
9105,
63,
751,
63,
7804,
63,
8153,
8,
1069,
14,
751,
9,
436,
288,
327,
922,
1159,
16942,
965,
10164,
344,
6979,
2872,
631,
3801,
503,
5531,
2872,
3034,
2081,
288,
9240,
14,
751,
63,
8153,
63,
1989,
63,
1744,
8,
355,
1056,
14,
751,
12,
355,
359,
4232,
344,
6979,
11757,
12,
5531,
2872,
3034,
2081,
61,
288,
776,
267,
776,
339,
372,
791,
5626,
63,
2918,
63,
15842,
63,
8153,
63,
1532,
356,
1077,
63,
2918,
63,
15842,
63,
8153,
93,
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
] |
[
199,
2765,
365,
314,
25630,
4073,
8153,
1067,
63,
6459,
859,
14,
199,
31499,
314,
1454,
1067,
63,
6459,
477,
28853,
3775,
1056,
14,
751,
965,
282,
16942,
626,
1077,
506,
9080,
315,
314,
199,
24148,
14,
221,
2136,
2934,
370,
886,
642,
315,
314,
1067,
63,
6459,
370,
199,
17,
9,
4215,
3050,
1066,
5804,
734,
402,
7009,
334,
3749,
29239,
370,
282,
6008,
6519,
543,
922,
3031,
4493,
9,
199,
18,
9,
2952,
19191,
14,
1360,
365,
298,
3527,
2,
701,
3769,
5120,
315,
1163,
7009,
12,
2337,
1159,
949,
298,
4196,
14,
647,
2,
370,
5324,
642,
14,
199,
624,
199,
199,
504,
1275,
992,
492,
5531,
2872,
3034,
2081,
12,
9240,
12,
10164,
344,
6979,
11757,
199,
504,
1275,
1208,
492,
365,
63,
15842,
63,
8153,
63,
3827,
421,
199,
318,
922,
63,
1989,
63,
8153,
63,
1100,
63,
6459,
8,
1069,
304,
272,
408,
272,
13813,
340,
1056,
965,
376,
15082,
922,
14,
221,
982,
880,
12,
5920,
340,
1056,
14,
751,
965,
282,
16942,
626,
1077,
272,
506,
9080,
14,
221,
24523,
4390,
2793,
1133,
14,
272,
15747,
658,
2918,
63,
15842,
63,
8153,
64,
370,
314,
1067,
272,
408,
272,
347,
1077,
63,
2918,
63,
15842,
63,
8153,
837,
267,
408,
267,
1803,
282,
5046,
340,
314,
922,
965,
376,
2974,
315,
282,
16942,
2382,
991,
314,
25630,
4073,
16942,
1077,
506,
267,
9080,
370,
314,
10367,
315,
922,
267,
408,
267,
372,
334,
288,
327,
922,
365,
10367,
315,
436,
288,
1056,
14,
751,
14,
374,
63,
12177,
436,
288,
327,
886,
781,
1172,
314,
3878,
19136,
641,
288,
365,
63,
15842,
63,
8153,
63,
3827,
342,
436,
288,
327,
1630,
314,
922,
5965,
1172,
282,
16942,
334,
25499,
1827,
370,
7981,
7143,
402,
282,
16942,
1380,
440,
4346,
9,
288,
9240,
14,
9105,
63,
751,
63,
7804,
63,
8153,
8,
1069,
14,
751,
9,
436,
288,
327,
922,
1159,
16942,
965,
10164,
344,
6979,
2872,
631,
3801,
503,
5531,
2872,
3034,
2081,
288,
9240,
14,
751,
63,
8153,
63,
1989,
63,
1744,
8,
355,
1056,
14,
751,
12,
355,
359,
4232,
344,
6979,
11757,
12,
5531,
2872,
3034,
2081,
61,
288,
776,
267,
776,
339,
372,
791,
5626,
63,
2918,
63,
15842,
63,
8153,
63,
1532,
356,
1077,
63,
2918,
63,
15842,
63,
8153,
93,
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,
0
] |
[
1,
1,
1,
1,
1,
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
youtube_dl/extractor/trilulilu.py
|
109
|
2890
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import ExtractorError
class TriluliluIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?trilulilu\.ro/(?:video-[^/]+/)?(?P<id>[^/#\?]+)'
_TEST = {
'url': 'http://www.trilulilu.ro/video-animatie/big-buck-bunny-1',
'md5': 'c1450a00da251e2769b74b9005601cac',
'info_dict': {
'id': 'ae2899e124140b',
'ext': 'mp4',
'title': 'Big Buck Bunny',
'description': ':) pentru copilul din noi',
},
}
def _real_extract(self, url):
display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id)
if re.search(r'Fişierul nu este disponibil pentru vizionare în ţara dumneavoastră', webpage):
raise ExtractorError(
'This video is not available in your country.', expected=True)
elif re.search('Fişierul poate fi accesat doar de către prietenii lui', webpage):
raise ExtractorError('This video is private.', expected=True)
flashvars_str = self._search_regex(
r'block_flash_vars\s*=\s*(\{[^\}]+\})', webpage, 'flashvars', fatal=False, default=None)
if flashvars_str:
flashvars = self._parse_json(flashvars_str, display_id)
else:
raise ExtractorError(
'This page does not contain videos', expected=True)
if flashvars['isMP3'] == 'true':
raise ExtractorError(
'Audio downloads are currently not supported', expected=True)
video_id = flashvars['hash']
title = self._og_search_title(webpage)
thumbnail = self._og_search_thumbnail(webpage)
description = self._og_search_description(webpage, default=None)
format_url = ('http://fs%(server)s.trilulilu.ro/%(hash)s/'
'video-formats2' % flashvars)
format_doc = self._download_xml(
format_url, video_id,
note='Downloading formats',
errnote='Error while downloading formats')
video_url_template = (
'http://fs%(server)s.trilulilu.ro/stream.php?type=video'
'&source=site&hash=%(hash)s&username=%(userid)s&'
'key=ministhebest&format=%%s&sig=&exp=' %
flashvars)
formats = [
{
'format_id': fnode.text.partition('-')[2],
'url': video_url_template % fnode.text,
'ext': fnode.text.partition('-')[0]
}
for fnode in format_doc.findall('./formats/format')
]
return {
'id': video_id,
'display_id': display_id,
'formats': formats,
'title': title,
'description': description,
'thumbnail': thumbnail,
}
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
19783,
421,
199,
533,
377,
10363,
13987,
10836,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
599,
10836,
317,
10836,
4537,
293,
32576,
3722,
13,
26285,
15,
5547,
2229,
48,
28,
344,
13489,
12645,
29635,
29716,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
599,
10836,
317,
10836,
14,
293,
15,
3722,
13,
290,
11744,
23958,
15,
5076,
13,
27954,
13,
66,
324,
9745,
13,
17,
297,
267,
283,
1064,
21,
356,
283,
67,
1079,
1400,
65,
383,
983,
12140,
69,
1465,
1876,
66,
1342,
66,
17518,
1367,
614,
11055,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
3624,
1651,
1020,
69,
7214,
10037,
66,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
7279,
4779,
346,
699,
324,
9745,
297,
288,
283,
1802,
356,
7596,
9,
12374,
454,
85,
4870,
382,
348,
366,
262,
949,
73,
297,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
2929,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2929,
63,
344,
9,
398,
340,
295,
14,
1733,
8,
82,
7,
9047,
130,
254,
4446,
348,
15699,
325,
1597,
2153,
678,
1892,
382,
12374,
454,
85,
373,
565,
1636,
1530,
13333,
107,
78,
221,
130,
97,
17956,
366,
453,
685,
1214,
20047,
495,
129,
226,
297,
9248,
304,
288,
746,
19783,
8,
355,
283,
2765,
3991,
365,
440,
2808,
315,
2195,
9023,
3130,
1420,
29,
549,
9,
267,
916,
295,
14,
1733,
360,
9047,
130,
254,
4446,
348,
1115,
323,
5883,
1066,
823,
292,
886,
285,
477,
286,
129,
226,
18468,
1979,
69,
724,
5908,
634,
1907,
297,
9248,
304,
288,
746,
19783,
360,
2765,
3991,
365,
5726,
3130,
1420,
29,
549,
9,
398,
14775,
2936,
63,
495,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
1457,
63,
11331,
63,
2936,
60,
83,
23440,
83,
22588,
91,
16045,
93,
24621,
25583,
9248,
12,
283,
11331,
2936,
297,
14294,
29,
797,
12,
849,
29,
403,
9,
398,
340,
14775,
2936,
63,
495,
26,
288,
14775,
2936,
275,
291,
423,
1122,
63,
1001,
8,
11331,
2936,
63,
495,
12,
2929,
63,
344,
9,
267,
587,
26,
288,
746,
19783,
8,
355,
283,
2765,
2034,
1630,
440,
1395,
22010,
297,
1420,
29,
549,
9,
398,
340,
14775,
2936,
459,
374,
1658,
19,
418,
508,
283,
2052,
356,
288,
746,
19783,
8,
355,
283,
15484,
28242,
787,
5544,
440,
3748,
297,
1420,
29,
549,
9,
398,
3991,
63,
344,
275,
14775,
2936,
459,
2227,
418,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
10062,
275,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
9,
267,
1369,
275,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
12,
849,
29,
403,
9,
398,
1475,
63,
633,
275,
661,
1014,
921,
2319,
2840,
1000,
9,
83,
14,
599,
10836,
317,
10836,
14,
293,
21275,
2227,
9,
83,
4805,
1993,
283,
3722,
13,
6321,
18,
7,
450,
14775,
2936,
9,
267,
1475,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
288,
1475,
63,
633,
12,
3991,
63,
344,
12,
288,
5317,
534,
18085,
6752,
297,
288,
2329,
4610,
534,
547,
1830,
25937,
6752,
358,
398,
3991,
63,
633,
63,
1160,
275,
334,
288,
283,
1014,
921,
2319,
2840,
1000,
9,
83,
14,
599,
10836,
317,
10836,
14,
293,
15,
1745,
14,
8624,
31,
466,
29,
3722,
7,
288,
7673,
1365,
29,
2124,
6,
2227,
15438,
2227,
9,
83,
6,
2473,
15438,
19737,
9,
83,
6,
7,
288,
283,
498,
29,
827,
631,
426,
7010,
6,
908,
2458,
5,
83,
6,
4093,
19167,
1474,
534,
450,
288,
14775,
2936,
9,
267,
6752,
275,
359,
288,
469,
355,
283,
908,
63,
344,
356,
289,
932,
14,
505,
14,
5312,
3654,
5832,
18,
467,
355,
283,
633,
356,
3991,
63,
633,
63,
1160,
450,
289,
932,
14,
505,
12,
355,
283,
832,
356,
289,
932,
14,
505,
14,
5312,
3654,
5832,
16,
61,
288,
789,
953,
367,
289,
932,
315,
1475,
63,
1301,
14,
6452,
17371,
6321,
15,
908,
358,
267,
1622,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
2918,
63,
344,
356,
2929,
63,
344,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
267,
789,
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
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
19783,
421,
199,
533,
377,
10363,
13987,
10836,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
599,
10836,
317,
10836,
4537,
293,
32576,
3722,
13,
26285,
15,
5547,
2229,
48,
28,
344,
13489,
12645,
29635,
29716,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
599,
10836,
317,
10836,
14,
293,
15,
3722,
13,
290,
11744,
23958,
15,
5076,
13,
27954,
13,
66,
324,
9745,
13,
17,
297,
267,
283,
1064,
21,
356,
283,
67,
1079,
1400,
65,
383,
983,
12140,
69,
1465,
1876,
66,
1342,
66,
17518,
1367,
614,
11055,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
3624,
1651,
1020,
69,
7214,
10037,
66,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
7279,
4779,
346,
699,
324,
9745,
297,
288,
283,
1802,
356,
7596,
9,
12374,
454,
85,
4870,
382,
348,
366,
262,
949,
73,
297,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
2929,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2929,
63,
344,
9,
398,
340,
295,
14,
1733,
8,
82,
7,
9047,
130,
254,
4446,
348,
15699,
325,
1597,
2153,
678,
1892,
382,
12374,
454,
85,
373,
565,
1636,
1530,
13333,
107,
78,
221,
130,
97,
17956,
366,
453,
685,
1214,
20047,
495,
129,
226,
297,
9248,
304,
288,
746,
19783,
8,
355,
283,
2765,
3991,
365,
440,
2808,
315,
2195,
9023,
3130,
1420,
29,
549,
9,
267,
916,
295,
14,
1733,
360,
9047,
130,
254,
4446,
348,
1115,
323,
5883,
1066,
823,
292,
886,
285,
477,
286,
129,
226,
18468,
1979,
69,
724,
5908,
634,
1907,
297,
9248,
304,
288,
746,
19783,
360,
2765,
3991,
365,
5726,
3130,
1420,
29,
549,
9,
398,
14775,
2936,
63,
495,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
1457,
63,
11331,
63,
2936,
60,
83,
23440,
83,
22588,
91,
16045,
93,
24621,
25583,
9248,
12,
283,
11331,
2936,
297,
14294,
29,
797,
12,
849,
29,
403,
9,
398,
340,
14775,
2936,
63,
495,
26,
288,
14775,
2936,
275,
291,
423,
1122,
63,
1001,
8,
11331,
2936,
63,
495,
12,
2929,
63,
344,
9,
267,
587,
26,
288,
746,
19783,
8,
355,
283,
2765,
2034,
1630,
440,
1395,
22010,
297,
1420,
29,
549,
9,
398,
340,
14775,
2936,
459,
374,
1658,
19,
418,
508,
283,
2052,
356,
288,
746,
19783,
8,
355,
283,
15484,
28242,
787,
5544,
440,
3748,
297,
1420,
29,
549,
9,
398,
3991,
63,
344,
275,
14775,
2936,
459,
2227,
418,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
10062,
275,
291,
423,
974,
63,
1733,
63,
8311,
8,
12022,
9,
267,
1369,
275,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
12,
849,
29,
403,
9,
398,
1475,
63,
633,
275,
661,
1014,
921,
2319,
2840,
1000,
9,
83,
14,
599,
10836,
317,
10836,
14,
293,
21275,
2227,
9,
83,
4805,
1993,
283,
3722,
13,
6321,
18,
7,
450,
14775,
2936,
9,
267,
1475,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
288,
1475,
63,
633,
12,
3991,
63,
344,
12,
288,
5317,
534,
18085,
6752,
297,
288,
2329,
4610,
534,
547,
1830,
25937,
6752,
358,
398,
3991,
63,
633,
63,
1160,
275,
334,
288,
283,
1014,
921,
2319,
2840,
1000,
9,
83,
14,
599,
10836,
317,
10836,
14,
293,
15,
1745,
14,
8624,
31,
466,
29,
3722,
7,
288,
7673,
1365,
29,
2124,
6,
2227,
15438,
2227,
9,
83,
6,
2473,
15438,
19737,
9,
83,
6,
7,
288,
283,
498,
29,
827,
631,
426,
7010,
6,
908,
2458,
5,
83,
6,
4093,
19167,
1474,
534,
450,
288,
14775,
2936,
9,
267,
6752,
275,
359,
288,
469,
355,
283,
908,
63,
344,
356,
289,
932,
14,
505,
14,
5312,
3654,
5832,
18,
467,
355,
283,
633,
356,
3991,
63,
633,
63,
1160,
450,
289,
932,
14,
505,
12,
355,
283,
832,
356,
289,
932,
14,
505,
14,
5312,
3654,
5832,
16,
61,
288,
789,
953,
367,
289,
932,
315,
1475,
63,
1301,
14,
6452,
17371,
6321,
15,
908,
358,
267,
1622,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
2918,
63,
344,
356,
2929,
63,
344,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
267,
789,
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,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
0,
0,
0,
0,
0
] |
sspreitzer/tahoe-lafs
|
setuptools-0.6c16dev6.egg/setuptools/__init__.py
|
5
|
3119
|
"""Extensions to the 'distutils' for large or complex distributions"""
from setuptools.extension import Extension, Library
from setuptools.dist import Distribution, Feature, _get_unpatched
import distutils.core, setuptools.command
from setuptools.depends import Require
from distutils.core import Command as _Command
from distutils.util import convert_path
import os.path
import os
import sys
__version__ = '0.6c16dev6'
__all__ = [
'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
'find_packages'
]
bootstrap_install_from = None
def find_packages(where='.', exclude=()):
"""Return a list all Python packages found within directory 'where'
'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
will be converted to the appropriate local path syntax. 'exclude' is a
sequence of package names to exclude; '*' can be used as a wildcard in the
names, such that 'foo.*' will exclude all subpackages of 'foo' (but not
'foo' itself).
"""
out = []
stack=[(convert_path(where), '')]
while stack:
where,prefix = stack.pop(0)
for name in os.listdir(where):
fn = os.path.join(where,name)
if ('.' not in name and os.path.isdir(fn) and
os.path.isfile(os.path.join(fn,'__init__.py'))
):
out.append(prefix+name); stack.append((fn,prefix+name+'.'))
for pat in list(exclude)+['ez_setup']:
from fnmatch import fnmatchcase
out = [item for item in out if not fnmatchcase(item,pat)]
return out
setup = distutils.core.setup
_Command = _get_unpatched(_Command)
class Command(_Command):
__doc__ = _Command.__doc__
command_consumes_arguments = False
def __init__(self, dist, **kw):
# Add support for keyword arguments
_Command.__init__(self,dist)
for k,v in kw.items():
setattr(self,k,v)
def reinitialize_command(self, command, reinit_subcommands=0, **kw):
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
for k,v in kw.items():
setattr(cmd,k,v) # update command with keywords
return cmd
import distutils.core
distutils.core.Command = Command # we can't patch distutils.cmd, alas
def findall(dir = os.curdir):
"""Find all files under 'dir' and return the list of full filenames
(relative to 'dir').
"""
all_files = []
for base, dirs, files in os.walk(dir):
if base==os.curdir or base.startswith(os.curdir+os.sep):
base = base[2:]
if base:
files = [os.path.join(base, f) for f in files]
all_files.extend(filter(os.path.isfile, files))
return all_files
import distutils.filelist
distutils.filelist.findall = findall # fix findall bug in distutils.
# sys.dont_write_bytecode was introduced in Python 2.6.
if ((hasattr(sys, "dont_write_bytecode") and sys.dont_write_bytecode) or
(not hasattr(sys, "dont_write_bytecode") and os.environ.get("PYTHONDONTWRITEBYTECODE"))):
_dont_write_bytecode = True
else:
_dont_write_bytecode = False
|
gpl-2.0
|
[
624,
10597,
370,
314,
283,
13350,
7,
367,
7031,
503,
6114,
10208,
624,
199,
504,
9116,
14,
3435,
492,
13282,
12,
11243,
199,
504,
9116,
14,
2686,
492,
11839,
12,
13407,
12,
485,
362,
63,
324,
22631,
199,
646,
7065,
14,
1018,
12,
9116,
14,
1531,
199,
504,
9116,
14,
8912,
492,
18513,
199,
504,
7065,
14,
1018,
492,
5817,
465,
485,
3110,
199,
504,
7065,
14,
1974,
492,
3957,
63,
515,
199,
646,
747,
14,
515,
199,
646,
747,
199,
646,
984,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
22,
67,
975,
2374,
22,
7,
199,
363,
452,
363,
275,
359,
272,
283,
2758,
297,
283,
8580,
297,
283,
5968,
297,
283,
3110,
297,
283,
6382,
297,
283,
13902,
297,
272,
283,
1623,
63,
5154,
7,
199,
61,
199,
199,
11146,
63,
3174,
63,
504,
275,
488,
199,
199,
318,
2342,
63,
5154,
8,
4509,
534,
3130,
5760,
23603,
272,
408,
1767,
282,
769,
1006,
2018,
6117,
1911,
4453,
2082,
283,
4509,
7,
339,
283,
4509,
7,
1077,
506,
6841,
465,
282,
298,
7925,
13,
3246,
2,
334,
73,
14,
69,
14,
2851,
13,
2487,
9,
931,
27,
652,
272,
911,
506,
6702,
370,
314,
5827,
2257,
931,
6302,
14,
221,
283,
5473,
7,
365,
282,
272,
3414,
402,
2559,
1561,
370,
5760,
27,
13626,
883,
506,
1202,
465,
282,
16792,
315,
314,
272,
1561,
12,
4066,
626,
283,
1421,
25737,
911,
5760,
1006,
1007,
5154,
402,
283,
1421,
7,
334,
7911,
440,
272,
283,
1421,
7,
6337,
680,
272,
408,
272,
734,
275,
942,
272,
3464,
17497,
3916,
63,
515,
8,
4509,
395,
4074,
61,
272,
1830,
3464,
26,
267,
2382,
12,
1861,
275,
3464,
14,
1935,
8,
16,
9,
267,
367,
536,
315,
747,
14,
7374,
8,
4509,
304,
288,
4325,
275,
747,
14,
515,
14,
904,
8,
4509,
12,
354,
9,
288,
340,
661,
3530,
440,
315,
536,
436,
747,
14,
515,
14,
6027,
8,
2324,
9,
436,
355,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
2324,
2584,
363,
826,
4343,
647,
1333,
288,
3461,
355,
734,
14,
740,
8,
1861,
11,
354,
2736,
3464,
14,
740,
1332,
2324,
12,
1861,
11,
354,
18098,
1333,
272,
367,
12713,
315,
769,
8,
5473,
6393,
459,
27263,
63,
2758,
2565,
267,
687,
15951,
492,
15951,
2546,
267,
734,
275,
359,
1053,
367,
1242,
315,
734,
340,
440,
15951,
2546,
8,
1053,
12,
10853,
1874,
272,
372,
734,
199,
199,
2758,
275,
7065,
14,
1018,
14,
2758,
199,
199,
63,
3110,
275,
485,
362,
63,
324,
22631,
1547,
3110,
9,
199,
199,
533,
5817,
1547,
3110,
304,
272,
636,
1301,
363,
275,
485,
3110,
855,
1301,
363,
339,
1414,
63,
10235,
83,
63,
4958,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2917,
12,
1011,
829,
304,
267,
327,
2654,
2291,
367,
4252,
2368,
267,
485,
3110,
855,
826,
721,
277,
12,
2686,
9,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
5371,
8,
277,
12,
75,
12,
86,
9,
339,
347,
295,
8489,
63,
1531,
8,
277,
12,
1414,
12,
295,
826,
63,
954,
4405,
29,
16,
12,
1011,
829,
304,
267,
2088,
275,
485,
3110,
14,
264,
8489,
63,
1531,
8,
277,
12,
1414,
12,
295,
826,
63,
954,
4405,
9,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
5371,
8,
1760,
12,
75,
12,
86,
9,
259,
327,
1678,
1414,
543,
7681,
267,
372,
2088,
199,
199,
646,
7065,
14,
1018,
199,
13350,
14,
1018,
14,
3110,
275,
5817,
259,
327,
781,
883,
1133,
3371,
7065,
14,
1760,
12,
741,
305,
199,
199,
318,
2342,
452,
8,
694,
275,
747,
14,
15594,
304,
272,
408,
6591,
1006,
1584,
1334,
283,
694,
7,
436,
372,
314,
769,
402,
2615,
6203,
272,
334,
6188,
370,
283,
694,
1959,
272,
408,
272,
1006,
63,
1725,
275,
942,
272,
367,
1300,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
694,
304,
267,
340,
1300,
389,
736,
14,
15594,
503,
1300,
14,
2460,
8,
736,
14,
15594,
11,
736,
14,
4127,
304,
288,
1300,
275,
1300,
59,
18,
2938,
267,
340,
1300,
26,
288,
1584,
275,
359,
736,
14,
515,
14,
904,
8,
1095,
12,
289,
9,
367,
289,
315,
1584,
61,
267,
1006,
63,
1725,
14,
2880,
8,
1541,
8,
736,
14,
515,
14,
6292,
12,
1584,
430,
272,
372,
1006,
63,
1725,
199,
199,
646,
7065,
14,
14964,
199,
13350,
14,
14964,
14,
6452,
275,
2342,
452,
259,
327,
5325,
2342,
452,
6519,
315,
7065,
14,
421,
199,
3,
984,
14,
18671,
63,
952,
63,
19812,
1990,
21399,
315,
2018,
499,
14,
22,
14,
199,
692,
3666,
11161,
8,
1274,
12,
298,
18671,
63,
952,
63,
19812,
531,
436,
984,
14,
18671,
63,
952,
63,
19812,
9,
503,
272,
334,
1397,
2688,
8,
1274,
12,
298,
18671,
63,
952,
63,
19812,
531,
436,
747,
14,
2314,
14,
362,
480,
11720,
31874,
10387,
19714,
6012,
2237,
304,
272,
485,
18671,
63,
952,
63,
19812,
275,
715,
199,
2836,
26,
272,
485,
18671,
63,
952,
63,
19812,
275,
756,
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
] |
[
10597,
370,
314,
283,
13350,
7,
367,
7031,
503,
6114,
10208,
624,
199,
504,
9116,
14,
3435,
492,
13282,
12,
11243,
199,
504,
9116,
14,
2686,
492,
11839,
12,
13407,
12,
485,
362,
63,
324,
22631,
199,
646,
7065,
14,
1018,
12,
9116,
14,
1531,
199,
504,
9116,
14,
8912,
492,
18513,
199,
504,
7065,
14,
1018,
492,
5817,
465,
485,
3110,
199,
504,
7065,
14,
1974,
492,
3957,
63,
515,
199,
646,
747,
14,
515,
199,
646,
747,
199,
646,
984,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
22,
67,
975,
2374,
22,
7,
199,
363,
452,
363,
275,
359,
272,
283,
2758,
297,
283,
8580,
297,
283,
5968,
297,
283,
3110,
297,
283,
6382,
297,
283,
13902,
297,
272,
283,
1623,
63,
5154,
7,
199,
61,
199,
199,
11146,
63,
3174,
63,
504,
275,
488,
199,
199,
318,
2342,
63,
5154,
8,
4509,
534,
3130,
5760,
23603,
272,
408,
1767,
282,
769,
1006,
2018,
6117,
1911,
4453,
2082,
283,
4509,
7,
339,
283,
4509,
7,
1077,
506,
6841,
465,
282,
298,
7925,
13,
3246,
2,
334,
73,
14,
69,
14,
2851,
13,
2487,
9,
931,
27,
652,
272,
911,
506,
6702,
370,
314,
5827,
2257,
931,
6302,
14,
221,
283,
5473,
7,
365,
282,
272,
3414,
402,
2559,
1561,
370,
5760,
27,
13626,
883,
506,
1202,
465,
282,
16792,
315,
314,
272,
1561,
12,
4066,
626,
283,
1421,
25737,
911,
5760,
1006,
1007,
5154,
402,
283,
1421,
7,
334,
7911,
440,
272,
283,
1421,
7,
6337,
680,
272,
408,
272,
734,
275,
942,
272,
3464,
17497,
3916,
63,
515,
8,
4509,
395,
4074,
61,
272,
1830,
3464,
26,
267,
2382,
12,
1861,
275,
3464,
14,
1935,
8,
16,
9,
267,
367,
536,
315,
747,
14,
7374,
8,
4509,
304,
288,
4325,
275,
747,
14,
515,
14,
904,
8,
4509,
12,
354,
9,
288,
340,
661,
3530,
440,
315,
536,
436,
747,
14,
515,
14,
6027,
8,
2324,
9,
436,
355,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
2324,
2584,
363,
826,
4343,
647,
1333,
288,
3461,
355,
734,
14,
740,
8,
1861,
11,
354,
2736,
3464,
14,
740,
1332,
2324,
12,
1861,
11,
354,
18098,
1333,
272,
367,
12713,
315,
769,
8,
5473,
6393,
459,
27263,
63,
2758,
2565,
267,
687,
15951,
492,
15951,
2546,
267,
734,
275,
359,
1053,
367,
1242,
315,
734,
340,
440,
15951,
2546,
8,
1053,
12,
10853,
1874,
272,
372,
734,
199,
199,
2758,
275,
7065,
14,
1018,
14,
2758,
199,
199,
63,
3110,
275,
485,
362,
63,
324,
22631,
1547,
3110,
9,
199,
199,
533,
5817,
1547,
3110,
304,
272,
636,
1301,
363,
275,
485,
3110,
855,
1301,
363,
339,
1414,
63,
10235,
83,
63,
4958,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2917,
12,
1011,
829,
304,
267,
327,
2654,
2291,
367,
4252,
2368,
267,
485,
3110,
855,
826,
721,
277,
12,
2686,
9,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
5371,
8,
277,
12,
75,
12,
86,
9,
339,
347,
295,
8489,
63,
1531,
8,
277,
12,
1414,
12,
295,
826,
63,
954,
4405,
29,
16,
12,
1011,
829,
304,
267,
2088,
275,
485,
3110,
14,
264,
8489,
63,
1531,
8,
277,
12,
1414,
12,
295,
826,
63,
954,
4405,
9,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
5371,
8,
1760,
12,
75,
12,
86,
9,
259,
327,
1678,
1414,
543,
7681,
267,
372,
2088,
199,
199,
646,
7065,
14,
1018,
199,
13350,
14,
1018,
14,
3110,
275,
5817,
259,
327,
781,
883,
1133,
3371,
7065,
14,
1760,
12,
741,
305,
199,
199,
318,
2342,
452,
8,
694,
275,
747,
14,
15594,
304,
272,
408,
6591,
1006,
1584,
1334,
283,
694,
7,
436,
372,
314,
769,
402,
2615,
6203,
272,
334,
6188,
370,
283,
694,
1959,
272,
408,
272,
1006,
63,
1725,
275,
942,
272,
367,
1300,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
694,
304,
267,
340,
1300,
389,
736,
14,
15594,
503,
1300,
14,
2460,
8,
736,
14,
15594,
11,
736,
14,
4127,
304,
288,
1300,
275,
1300,
59,
18,
2938,
267,
340,
1300,
26,
288,
1584,
275,
359,
736,
14,
515,
14,
904,
8,
1095,
12,
289,
9,
367,
289,
315,
1584,
61,
267,
1006,
63,
1725,
14,
2880,
8,
1541,
8,
736,
14,
515,
14,
6292,
12,
1584,
430,
272,
372,
1006,
63,
1725,
199,
199,
646,
7065,
14,
14964,
199,
13350,
14,
14964,
14,
6452,
275,
2342,
452,
259,
327,
5325,
2342,
452,
6519,
315,
7065,
14,
421,
199,
3,
984,
14,
18671,
63,
952,
63,
19812,
1990,
21399,
315,
2018,
499,
14,
22,
14,
199,
692,
3666,
11161,
8,
1274,
12,
298,
18671,
63,
952,
63,
19812,
531,
436,
984,
14,
18671,
63,
952,
63,
19812,
9,
503,
272,
334,
1397,
2688,
8,
1274,
12,
298,
18671,
63,
952,
63,
19812,
531,
436,
747,
14,
2314,
14,
362,
480,
11720,
31874,
10387,
19714,
6012,
2237,
304,
272,
485,
18671,
63,
952,
63,
19812,
275,
715,
199,
2836,
26,
272,
485,
18671,
63,
952,
63,
19812,
275,
756,
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,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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
] |
gerald-yang/ubuntu-iotivity-demo
|
snappy/grovepi/python-env/local/lib/python2.7/encodings/unicode_internal.py
|
827
|
1196
|
""" Python 'unicode-internal' Codec
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""
import codecs
### Codec APIs
class Codec(codecs.Codec):
# Note: Binding these as C functions will result in the class not
# converting them to methods. This is intended.
encode = codecs.unicode_internal_encode
decode = codecs.unicode_internal_decode
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.unicode_internal_encode(input, self.errors)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.unicode_internal_decode(input, self.errors)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='unicode-internal',
encode=Codec.encode,
decode=Codec.decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamwriter=StreamWriter,
streamreader=StreamReader,
)
|
apache-2.0
|
[
624,
2018,
283,
2975,
13,
4672,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
327,
3390,
26,
22630,
316,
3520,
465,
445,
3423,
911,
754,
315,
314,
1021,
440,
272,
327,
13806,
3062,
370,
3102,
14,
961,
365,
11619,
14,
272,
3752,
275,
6010,
14,
2975,
63,
4672,
63,
2143,
272,
4849,
275,
6010,
14,
2975,
63,
4672,
63,
2708,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
4672,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
4672,
63,
2708,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
2975,
13,
4672,
297,
267,
3752,
29,
8818,
14,
2143,
12,
267,
4849,
29,
8818,
14,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26112,
29,
16551,
12,
267,
26101,
29,
16132,
12,
272,
776,
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
] |
[
2018,
283,
2975,
13,
4672,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
327,
3390,
26,
22630,
316,
3520,
465,
445,
3423,
911,
754,
315,
314,
1021,
440,
272,
327,
13806,
3062,
370,
3102,
14,
961,
365,
11619,
14,
272,
3752,
275,
6010,
14,
2975,
63,
4672,
63,
2143,
272,
4849,
275,
6010,
14,
2975,
63,
4672,
63,
2708,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
4672,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
4672,
63,
2708,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
2975,
13,
4672,
297,
267,
3752,
29,
8818,
14,
2143,
12,
267,
4849,
29,
8818,
14,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26112,
29,
16551,
12,
267,
26101,
29,
16132,
12,
272,
776,
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,
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,
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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
] |
ckc6cz/osf.io
|
scripts/dataverse/migrate_user_settings_field.py
|
44
|
1267
|
"""
First run the following in a mongo shell:
db.getCollection('addondataversenodesettings').update({'user_settings': {'$type': 2}}, {$rename: { user_settings: 'foreign_user_settings'}}, {multi: true})
Then change the user_settings field of AddonDataverseNodeSettings to foreign_user_settings
"""
import sys
import logging
from scripts import utils as script_utils
from framework.transactions.context import TokuTransaction
from website.app import init_app
from website.addons.dataverse.model import AddonDataverseNodeSettings
logger = logging.getLogger('migrate_user_settings_field')
def do_migration():
for dvs in AddonDataverseNodeSettings.find():
if dvs.foreign_user_settings is None:
continue
logger.info('Migrating user_settings for dataverse {}'.format(dvs._id))
dvs.user_settings = dvs.foreign_user_settings
dvs.save()
def main(dry=True):
init_app(set_backends=True, routes=False) # Sets the storage backends on all models
with TokuTransaction():
do_migration()
if dry:
raise Exception('Abort Transaction - Dry Run')
if __name__ == '__main__':
dry = 'dry' in sys.argv
if not dry:
script_utils.add_file_logger(logger, __file__)
main(dry=dry)
|
apache-2.0
|
[
624,
199,
199,
7147,
1255,
314,
2569,
315,
282,
18006,
5218,
26,
339,
1592,
14,
362,
7768,
360,
9291,
576,
2077,
932,
1751,
1959,
873,
3252,
751,
63,
1751,
356,
30108,
466,
356,
499,
13459,
469,
4,
8165,
26,
469,
922,
63,
1751,
26,
283,
6846,
63,
751,
63,
1751,
28400,
469,
3029,
26,
2549,
1552,
199,
199,
28226,
1570,
314,
922,
63,
1751,
901,
402,
29366,
1451,
2077,
1716,
5268,
370,
11608,
63,
751,
63,
1751,
199,
624,
199,
646,
984,
199,
646,
2050,
199,
199,
504,
10554,
492,
3778,
465,
2884,
63,
1208,
199,
504,
10059,
14,
13754,
14,
1100,
492,
377,
745,
85,
10161,
199,
199,
504,
10691,
14,
571,
492,
4205,
63,
571,
199,
504,
10691,
14,
10788,
14,
576,
2077,
14,
1238,
492,
29366,
1451,
2077,
1716,
5268,
199,
199,
2921,
275,
2050,
14,
5572,
360,
8462,
63,
751,
63,
1751,
63,
698,
358,
199,
199,
318,
886,
63,
8998,
837,
272,
367,
366,
3122,
315,
29366,
1451,
2077,
1716,
5268,
14,
1623,
837,
267,
340,
366,
3122,
14,
6846,
63,
751,
63,
1751,
365,
488,
26,
288,
1980,
267,
2512,
14,
815,
360,
19322,
10417,
922,
63,
1751,
367,
666,
2077,
9499,
908,
8,
68,
3122,
423,
344,
430,
267,
366,
3122,
14,
751,
63,
1751,
275,
366,
3122,
14,
6846,
63,
751,
63,
1751,
267,
366,
3122,
14,
2117,
342,
199,
199,
318,
2446,
8,
10481,
29,
549,
304,
272,
4205,
63,
571,
8,
409,
63,
7765,
29,
549,
12,
15777,
29,
797,
9,
221,
327,
10729,
314,
4887,
14745,
641,
1006,
1709,
272,
543,
377,
745,
85,
10161,
837,
267,
886,
63,
8998,
342,
267,
340,
9951,
26,
288,
746,
2186,
360,
16682,
18244,
446,
577,
651,
3378,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9951,
275,
283,
10481,
7,
315,
984,
14,
3020,
272,
340,
440,
9951,
26,
267,
2884,
63,
1208,
14,
525,
63,
493,
63,
2921,
8,
2921,
12,
636,
493,
3368,
272,
2446,
8,
10481,
29,
10481,
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,
32768,
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,
199,
7147,
1255,
314,
2569,
315,
282,
18006,
5218,
26,
339,
1592,
14,
362,
7768,
360,
9291,
576,
2077,
932,
1751,
1959,
873,
3252,
751,
63,
1751,
356,
30108,
466,
356,
499,
13459,
469,
4,
8165,
26,
469,
922,
63,
1751,
26,
283,
6846,
63,
751,
63,
1751,
28400,
469,
3029,
26,
2549,
1552,
199,
199,
28226,
1570,
314,
922,
63,
1751,
901,
402,
29366,
1451,
2077,
1716,
5268,
370,
11608,
63,
751,
63,
1751,
199,
624,
199,
646,
984,
199,
646,
2050,
199,
199,
504,
10554,
492,
3778,
465,
2884,
63,
1208,
199,
504,
10059,
14,
13754,
14,
1100,
492,
377,
745,
85,
10161,
199,
199,
504,
10691,
14,
571,
492,
4205,
63,
571,
199,
504,
10691,
14,
10788,
14,
576,
2077,
14,
1238,
492,
29366,
1451,
2077,
1716,
5268,
199,
199,
2921,
275,
2050,
14,
5572,
360,
8462,
63,
751,
63,
1751,
63,
698,
358,
199,
199,
318,
886,
63,
8998,
837,
272,
367,
366,
3122,
315,
29366,
1451,
2077,
1716,
5268,
14,
1623,
837,
267,
340,
366,
3122,
14,
6846,
63,
751,
63,
1751,
365,
488,
26,
288,
1980,
267,
2512,
14,
815,
360,
19322,
10417,
922,
63,
1751,
367,
666,
2077,
9499,
908,
8,
68,
3122,
423,
344,
430,
267,
366,
3122,
14,
751,
63,
1751,
275,
366,
3122,
14,
6846,
63,
751,
63,
1751,
267,
366,
3122,
14,
2117,
342,
199,
199,
318,
2446,
8,
10481,
29,
549,
304,
272,
4205,
63,
571,
8,
409,
63,
7765,
29,
549,
12,
15777,
29,
797,
9,
221,
327,
10729,
314,
4887,
14745,
641,
1006,
1709,
272,
543,
377,
745,
85,
10161,
837,
267,
886,
63,
8998,
342,
267,
340,
9951,
26,
288,
746,
2186,
360,
16682,
18244,
446,
577,
651,
3378,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9951,
275,
283,
10481,
7,
315,
984,
14,
3020,
272,
340,
440,
9951,
26,
267,
2884,
63,
1208,
14,
525,
63,
493,
63,
2921,
8,
2921,
12,
636,
493,
3368,
272,
2446,
8,
10481,
29,
10481,
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,
32768,
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,
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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
] |
preed/quickrelease
|
quickrelease/step.py
|
1
|
12237
|
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
r"""
The base class for QuickRelease steps, along with error reporting classes,
custom subclasses of steps, and classes to run the individual parts of the
steps.
L{Step}s are usually searched for in the C{quickrelease/steps} directory. This behavior can be modified by setting the B{C{QUICKRELEASE_DEFINITIONS_PATH}} to the name of a directory containing both a "processes" and "steps" directory.
To exclude the inclusion of any L{Process}es or L{Step<quickrelease.step.Step>}s in the standard QuickRelease directories, set B{C{QUICKRELEASE_OVERRIDE_DEFAULT_DEFINITIONS}} in the environment.
"""
import os
from quickrelease.exception import ReleaseFrameworkError, ReleaseFrameworkErrorCollection
from quickrelease.utils import GetActivePartners, PrintReleaseFrameworkError
class StepError(ReleaseFrameworkError):
"""
An exception subclassed from L{ReleaseFrameworkError<quickrelease.exception.ReleaseFrameworkError>} which provides a more useful error message about the specific L{Step} the error occured in.
"""
def __init__(self, stepObj, errStr, *args, **kwargs):
ReleaseFrameworkError.__init__(self, errStr, stepObj)
assert isinstance(stepObj, Step), "StepErrors require a Step object"
self._partnerStr = ""
if isinstance(stepObj, PartnerStep):
self._partnerStr = " (partner: %s)" % (stepObj.activePartner)
def _GetErroredStep(self): return self.details
erroredStep = property(_GetErroredStep)
def __str__(self):
return "Error in step %s%s: %s" % (self.erroredStep, self._partnerStr,
ReleaseFrameworkError.__str__(self))
class _StandardStepRunner(object):
def __init__(self, *args, **kwargs):
object.__init__(self)
def DoPreflight(self, stepObj):
stepObj.Preflight()
def DoExecute(self, stepObj):
stepObj.Execute()
def DoVerify(self, stepObj):
stepObj.Verify()
def DoNotify(self, stepObj):
stepObj.Notify()
class Step(object):
"""
An object representing a single step of a defined L{Process<quickrelease.process.Process>}
"""
def __init__(self, *args, **kwargs):
"""
Construct a L{Step} object.
@param process: The parent-process this L{Step} belongs to.
@type process: L{Process<quickrelease.process.Process>}
@param runner: The L{Step}-runner to use for this L{Step}. This allows different types of L{Step}'s to modify the logic of what it means to "run" a step if they so choose (e.g. a L{PartnerStep}).
@type runner: object
"""
object.__init__(self)
self._parentProcess = None
self._runner = _StandardStepRunner()
if kwargs.has_key('process'):
self._parentProcess = kwargs['process']
if kwargs.has_key('runner'):
self._runner = kwargs['runner']
def __str__(self):
"""The L{Step}'s name."""
return self.__class__.__name__
def _GetName(self): return str(self)
def _GetRunner(self): return self._runner
def _GetParentProcess(self): return self._parentProcess
def _GetConfig(self):
if self.process is None:
raise self.SimpleStepError("%s has no associated process to "
"obtain a ConfigSpec." % (self))
elif self.process.config is None:
raise self.SimpleStepError("Process %s has no associated "
"ConfigSpec." % (self.process))
else:
return self.process.config
def _GetLogger(self):
if self.process is None:
raise self.SimpleStepError("%s has no associated process to "
"obtain a Logger." % (self))
elif self.process.logger is None:
raise self.SimpleStepError("Process %s has no associated Logger."
% (self.process))
else:
return self.process.logger
def Log(self, msg):
return self.logger.Log(msg, step=self)
def LogErr(self, msg):
return self.logger.LogErr(msg, step=self)
def LogDebug(self, msg):
return self.logger.LogDebug(msg, step=self)
def ShellCommandLog(self, combined=True):
# TODO: handle to a named file for a log command
pass
name = property(_GetName)
runner = property(_GetRunner)
"""Return the runner object responsible for running the parts of the step. Read-only.
@type: Runner object"""
config = property(_GetConfig)
"""The config associated with the L{Step}'s parent process, if any. Read-only.
@type: L{ConfigSpec<quickrelease.config.ConfigSpec>} or C{None}."""
process = property(_GetParentProcess)
"""The process this step is a part of, if any. Read-only.
@type: L{Process<quickrelease.process.Process>} or C{None}"""
logger = property(_GetLogger)
"""The logger associated with the L{Step}'s parent process, if any. Read-only.
@type: L{Logger<quickrelease.logger.Logger>} or C{None}."""
def Preflight(self):
"""
A method intended for L{Step}s to override with any activities which
must be executed before I{either} the L{Execute<quickrelease.step.Step.Execute>} or L{Verify<quickrelease.step.Step.Verify>} methods need to be executed, if any such activities exist.
"""
pass
def Execute(self):
"""
A method intended for dervied L{Step}s to override with the execution logic of the particular L{Process} step.
B{Note}: This method B{must} be redefined by the dervied L{Step}.
@raise NotImplementedError: If the derived L{Step} does not define an C{Execute} method.
"""
raise NotImplementedError("Need implementation for %s::Execute()" %
(str(self)))
def Verify(self):
"""
A method intended for dervied L{Step}s to override with the unit test-like verification logic of the particular L{Process} step.
B{Note}: This method B{must} be redefined by the dervied L{Step}.
@raise NotImplementedError: If the derived L{Step} does not define an C{Verify} method.
"""
raise NotImplementedError("Need implementation for %s::Verify()" %
(str(self)))
def Notify(self):
"""
A method intended for L{Step}s to override with any notifications that should occur after a step has successful been executed and/or verified.
B{Note}: Currently, these notifications will fire even if only the verification-steps are run.
"""
pass
# We're kinda cheating here; when using it, it looks like SimpleStepError
# is an exception type, not a function; it's mostly a convenience function
# for creating a StepError Exception with a simple message, so we don't
# have to pass the step object the StepError expects explicitly.
def SimpleStepError(self, errStr, details=None):
"""
A convenience method for creating a L{StepError} with a simple message,
so users don't have to pass the L{Step} object the L{StepError} expects
explicitly.
@param errStr: the error string
@type errStr: C{str}
@param details: Extra details about the error condition.
@type details: Variable
@return: An initialized L{StepError} with the current step associated to it.
@rtype: L{StepError}
"""
return StepError(self, errStr, details=details)
class _PartnerStepRunner(object):
def __init__(self, *args, **kwargs):
object.__init__(self)
def _RunPartnerStepMethod(self, stepObj, methodName):
conf = stepObj.config
rootDir = conf.rootDir
errors = []
for p in GetActivePartners(conf):
try:
os.chdir(rootDir)
stepObj.activePartner = p
stepMethod = getattr(stepObj, methodName)
stepMethod()
except ReleaseFrameworkError, ex:
if stepObj._haltOnFirstError:
raise ex
else:
# Unless we're in quiet mode...
PrintReleaseFrameworkError(ex)
errors.append(ex)
if len(errors) != 0:
raise ReleaseFrameworkErrorCollection(errors)
def DoPreflight(self, stepObj):
self._RunPartnerStepMethod(stepObj, "Preflight")
def DoExecute(self, stepObj):
self._RunPartnerStepMethod(stepObj, "Execute")
def DoVerify(self, stepObj):
self._RunPartnerStepMethod(stepObj, "Verify")
def DoNotify(self, stepObj):
self._RunPartnerStepMethod(stepObj, "Notify")
class PartnerStep(Step):
"""
A special type of L{Step} which will perform the requested C{Execute} and
C{Verify} methods for all active partners (as determined by L{GetActivePartners<quickrelease.utils.GetActivePartners>}).
Subclasses may call the the constructor of C{PartnerStep} with the following
keywords to modify its behavior:
1. C{auto_set_partner_config}: By default, when the L{PartnerStep} sets the next partner to execute or verify the portion of the current step, it will also set the section of the associated L{ConfigSpec<quickrelease.config.ConfigSpec>} to the active partner section (via a call to L{SetPartnerSection<quickrelease.config.ConfigSpec.SetPartnerSection>}. Setting this to C{False} will disable that bahavior and make the subclassed L{PartnerStep}s responsible for managing the state of their L{ConfigSpec<quickrelease.config.ConfigSpec>}.
2. C{halt_on_first_error}: By default, if an error is encountered during the execution or verification portion of a L{PartnerStep}, the error will be reported and noted, but the L{Step} will continue for each active partner. Once each active partner's step has been called, I{then} the L{PartnerStep} will halt. For example, say there exist two partners, "Acme" and "Biffco" and a three-step process, consisting of L{PartnerStep}s named C{WillBeOK}, C{WillFailForAcme}, and C{WillNotRun}. By default, C{WillBeOK} will run for Acme and Biffco; C{WillFailForAcme} will run for Acme and fail, and will then run for Biffco, and succeed. At this point, the L{PartnerStep} will halt with the errors, and the last step will not run. If this is set to C{True}, the L{PartnerStep} would immediately halt when it encountered the Acme-error.
"""
def __init__(self, *args, **kwargs):
Step.__init__(self, *args, **kwargs)
self._runner = _PartnerStepRunner()
self._activePartner = None
self._partnerData = {}
self._autoSetPartnerConfig = True
self._haltOnFirstError = False
if kwargs.has_key('auto_set_partner_config'):
self._autoSetPartnerConfig = kwargs['auto_set_partner_config']
if kwargs.has_key('halt_on_first_error'):
self._haltOnFirstError = kwargs['halt_on_first_error']
def _GetActivePartner(self): return self._activePartner
def _SetActivePartner(self, partner):
if partner not in GetActivePartners(self.config):
raise self.SimpleStepError("Unknown partner '%s'" % (partner))
self._activePartner = partner
if self._autoSetPartnerConfig:
self.config.SetPartnerSection(partner)
if partner not in self._partnerData.keys():
self._partnerData[partner] = {}
activePartner = property(_GetActivePartner, _SetActivePartner)
def Save(self, key, data):
"""
Store partner-specific data that may need to persist across a set of C{Execute}/C{Verify} calls.
@param key: Key to retrieve the data.
@type key: C{str}
@param data: The data to store.
@type data: Variable
"""
self._partnerData[self.activePartner][key] = data
def Load(self, key):
"""
Retrieve partner-specific data that may need to persist across a set of C{Execute}/C{Verify} calls.
@param key: Key of data to retrieve
@type key: C{str}
@raise KeyError: If the data described by the specified key does not exist.
"""
return self._partnerData[self.activePartner][key]
|
mit
|
[
3,
444,
26,
1086,
29,
20,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
386,
199,
3,
1882,
5174,
13,
2063,
26,
841,
27,
286,
13,
4316,
13,
2743,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
199,
82,
624,
199,
1918,
1300,
1021,
367,
27534,
9625,
7124,
12,
3180,
543,
1125,
17290,
3992,
12,
221,
199,
4229,
9180,
402,
7124,
12,
436,
3992,
370,
1255,
314,
8212,
4184,
402,
314,
221,
199,
5895,
14,
199,
199,
44,
91,
7801,
93,
83,
787,
9987,
17543,
367,
315,
314,
445,
91,
13239,
3221,
15,
5895,
93,
2082,
14,
961,
5953,
883,
506,
6042,
701,
4260,
314,
699,
91,
35,
91,
2328,
13884,
19736,
63,
5638,
8727,
2823,
63,
3243,
4863,
370,
314,
536,
402,
282,
2082,
3035,
3865,
282,
298,
11816,
2,
436,
298,
5895,
2,
2082,
14,
199,
199,
1378,
5760,
314,
20396,
402,
1263,
491,
91,
3498,
93,
397,
503,
491,
91,
7801,
28,
13239,
3221,
14,
2926,
14,
7801,
23307,
83,
315,
314,
4465,
27534,
9625,
6602,
12,
663,
699,
91,
35,
91,
2328,
13884,
19736,
63,
30024,
11259,
63,
3472,
63,
5638,
8727,
2823,
4863,
315,
314,
3734,
14,
199,
624,
199,
199,
646,
747,
199,
199,
504,
12530,
3221,
14,
1971,
492,
17646,
16442,
547,
12,
17646,
16442,
547,
7768,
199,
504,
12530,
3221,
14,
1208,
492,
2372,
7472,
8416,
8715,
12,
9101,
9625,
16442,
547,
199,
199,
533,
13382,
547,
8,
9625,
16442,
547,
304,
272,
408,
272,
1626,
1919,
1007,
28271,
687,
491,
91,
9625,
16442,
547,
28,
13239,
3221,
14,
1971,
14,
9625,
16442,
547,
23307,
1314,
6571,
282,
1655,
2997,
1125,
1245,
3595,
314,
2488,
491,
91,
7801,
93,
314,
1125,
28408,
315,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3650,
5665,
12,
2329,
2848,
12,
627,
589,
12,
1011,
958,
304,
267,
17646,
16442,
547,
855,
826,
721,
277,
12,
2329,
2848,
12,
3650,
5665,
9,
398,
702,
1228,
8,
2926,
5665,
12,
13382,
395,
298,
7801,
9298,
4409,
282,
13382,
909,
2,
398,
291,
423,
3899,
2848,
275,
3087,
267,
340,
1228,
8,
2926,
5665,
12,
31351,
7801,
304,
288,
291,
423,
3899,
2848,
275,
298,
334,
3899,
26,
450,
83,
2924,
450,
334,
2926,
5665,
14,
2682,
24120,
9,
339,
347,
485,
1002,
539,
20878,
7801,
8,
277,
304,
372,
291,
14,
5087,
272,
9266,
20878,
7801,
275,
3324,
1547,
1002,
539,
20878,
7801,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
547,
315,
3650,
450,
83,
5,
83,
26,
450,
83,
2,
450,
334,
277,
14,
281,
20878,
7801,
12,
291,
423,
3899,
2848,
12,
268,
17646,
16442,
547,
855,
495,
721,
277,
430,
199,
199,
533,
485,
9232,
7801,
7446,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
909,
855,
826,
721,
277,
9,
339,
347,
4226,
18441,
4040,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
18441,
4040,
342,
339,
347,
4226,
12049,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
12049,
342,
339,
347,
4226,
7496,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
7496,
342,
339,
347,
4226,
8645,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
8645,
342,
199,
199,
533,
13382,
8,
785,
304,
272,
408,
272,
1626,
909,
6144,
282,
2849,
3650,
402,
282,
3247,
491,
91,
3498,
28,
13239,
3221,
14,
1412,
14,
3498,
23307,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
9215,
282,
491,
91,
7801,
93,
909,
14,
398,
768,
635,
2112,
26,
710,
1676,
13,
1412,
642,
491,
91,
7801,
93,
15006,
370,
14,
267,
768,
466,
2112,
26,
491,
91,
3498,
28,
13239,
3221,
14,
1412,
14,
3498,
23307,
398,
768,
635,
7876,
26,
710,
491,
91,
7801,
17063,
5933,
370,
675,
367,
642,
491,
91,
7801,
5565,
961,
6127,
3365,
2943,
402,
491,
91,
7801,
6834,
83,
370,
2811,
314,
9661,
402,
4052,
652,
4910,
370,
298,
1065,
2,
282,
3650,
340,
2985,
880,
11496,
334,
69,
14,
71,
14,
282,
491,
91,
24120,
7801,
21385,
267,
768,
466,
7876,
26,
909,
267,
408,
267,
909,
855,
826,
721,
277,
9,
267,
291,
423,
1708,
3498,
275,
488,
267,
291,
423,
5933,
275,
485,
9232,
7801,
7446,
342,
398,
340,
2074,
14,
1989,
63,
498,
360,
1412,
735,
288,
291,
423,
1708,
3498,
275,
221,
2074,
459,
1412,
418,
398,
340,
2074,
14,
1989,
63,
498,
360,
5933,
735,
288,
291,
423,
5933,
275,
2074,
459,
5933,
418,
339,
347,
636,
495,
721,
277,
304,
267,
408,
1918,
491,
91,
7801,
6834,
83,
536,
1041,
267,
372,
291,
855,
533,
4914,
354,
363,
18407,
347,
485,
21266,
8,
277,
304,
372,
620,
8,
277,
9,
272,
347,
485,
1002,
7446,
8,
277,
304,
372,
291,
423,
5933,
272,
347,
485,
1002,
6652,
3498,
8,
277,
304,
372,
291,
423,
1708,
3498,
272,
347,
485,
1002,
2028,
8,
277,
304,
267,
340,
291,
14,
1412,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
3647,
83,
965,
949,
4568,
2112,
370,
298,
1467,
298,
2873,
877,
282,
4094,
5307,
2122,
450,
334,
277,
430,
267,
916,
291,
14,
1412,
14,
888,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
480,
3498,
450,
83,
965,
949,
4568,
298,
1467,
298,
2028,
5307,
2122,
450,
334,
277,
14,
1412,
430,
267,
587,
26,
288,
372,
291,
14,
1412,
14,
888,
339,
347,
485,
1002,
4455,
8,
277,
304,
267,
340,
291,
14,
1412,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
3647,
83,
965,
949,
4568,
2112,
370,
298,
1467,
298,
2873,
877,
282,
15996,
2122,
450,
334,
277,
430,
267,
916,
291,
14,
1412,
14,
2921,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
480,
3498,
450,
83,
965,
949,
4568,
15996,
2122,
1467,
450,
334,
277,
14,
1412,
430,
267,
587,
26,
288,
372,
291,
14,
1412,
14,
2921,
339,
347,
5297,
8,
277,
12,
1499,
304,
267,
372,
291,
14,
2921,
14,
2445,
8,
1328,
12,
3650,
29,
277,
9,
2286,
347,
5297
] |
[
444,
26,
1086,
29,
20,
26,
3519,
29,
20,
26,
10329,
29,
20,
26,
386,
199,
3,
1882,
5174,
13,
2063,
26,
841,
27,
286,
13,
4316,
13,
2743,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
1882,
199,
199,
82,
624,
199,
1918,
1300,
1021,
367,
27534,
9625,
7124,
12,
3180,
543,
1125,
17290,
3992,
12,
221,
199,
4229,
9180,
402,
7124,
12,
436,
3992,
370,
1255,
314,
8212,
4184,
402,
314,
221,
199,
5895,
14,
199,
199,
44,
91,
7801,
93,
83,
787,
9987,
17543,
367,
315,
314,
445,
91,
13239,
3221,
15,
5895,
93,
2082,
14,
961,
5953,
883,
506,
6042,
701,
4260,
314,
699,
91,
35,
91,
2328,
13884,
19736,
63,
5638,
8727,
2823,
63,
3243,
4863,
370,
314,
536,
402,
282,
2082,
3035,
3865,
282,
298,
11816,
2,
436,
298,
5895,
2,
2082,
14,
199,
199,
1378,
5760,
314,
20396,
402,
1263,
491,
91,
3498,
93,
397,
503,
491,
91,
7801,
28,
13239,
3221,
14,
2926,
14,
7801,
23307,
83,
315,
314,
4465,
27534,
9625,
6602,
12,
663,
699,
91,
35,
91,
2328,
13884,
19736,
63,
30024,
11259,
63,
3472,
63,
5638,
8727,
2823,
4863,
315,
314,
3734,
14,
199,
624,
199,
199,
646,
747,
199,
199,
504,
12530,
3221,
14,
1971,
492,
17646,
16442,
547,
12,
17646,
16442,
547,
7768,
199,
504,
12530,
3221,
14,
1208,
492,
2372,
7472,
8416,
8715,
12,
9101,
9625,
16442,
547,
199,
199,
533,
13382,
547,
8,
9625,
16442,
547,
304,
272,
408,
272,
1626,
1919,
1007,
28271,
687,
491,
91,
9625,
16442,
547,
28,
13239,
3221,
14,
1971,
14,
9625,
16442,
547,
23307,
1314,
6571,
282,
1655,
2997,
1125,
1245,
3595,
314,
2488,
491,
91,
7801,
93,
314,
1125,
28408,
315,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3650,
5665,
12,
2329,
2848,
12,
627,
589,
12,
1011,
958,
304,
267,
17646,
16442,
547,
855,
826,
721,
277,
12,
2329,
2848,
12,
3650,
5665,
9,
398,
702,
1228,
8,
2926,
5665,
12,
13382,
395,
298,
7801,
9298,
4409,
282,
13382,
909,
2,
398,
291,
423,
3899,
2848,
275,
3087,
267,
340,
1228,
8,
2926,
5665,
12,
31351,
7801,
304,
288,
291,
423,
3899,
2848,
275,
298,
334,
3899,
26,
450,
83,
2924,
450,
334,
2926,
5665,
14,
2682,
24120,
9,
339,
347,
485,
1002,
539,
20878,
7801,
8,
277,
304,
372,
291,
14,
5087,
272,
9266,
20878,
7801,
275,
3324,
1547,
1002,
539,
20878,
7801,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
547,
315,
3650,
450,
83,
5,
83,
26,
450,
83,
2,
450,
334,
277,
14,
281,
20878,
7801,
12,
291,
423,
3899,
2848,
12,
268,
17646,
16442,
547,
855,
495,
721,
277,
430,
199,
199,
533,
485,
9232,
7801,
7446,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
909,
855,
826,
721,
277,
9,
339,
347,
4226,
18441,
4040,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
18441,
4040,
342,
339,
347,
4226,
12049,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
12049,
342,
339,
347,
4226,
7496,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
7496,
342,
339,
347,
4226,
8645,
8,
277,
12,
3650,
5665,
304,
267,
3650,
5665,
14,
8645,
342,
199,
199,
533,
13382,
8,
785,
304,
272,
408,
272,
1626,
909,
6144,
282,
2849,
3650,
402,
282,
3247,
491,
91,
3498,
28,
13239,
3221,
14,
1412,
14,
3498,
23307,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
9215,
282,
491,
91,
7801,
93,
909,
14,
398,
768,
635,
2112,
26,
710,
1676,
13,
1412,
642,
491,
91,
7801,
93,
15006,
370,
14,
267,
768,
466,
2112,
26,
491,
91,
3498,
28,
13239,
3221,
14,
1412,
14,
3498,
23307,
398,
768,
635,
7876,
26,
710,
491,
91,
7801,
17063,
5933,
370,
675,
367,
642,
491,
91,
7801,
5565,
961,
6127,
3365,
2943,
402,
491,
91,
7801,
6834,
83,
370,
2811,
314,
9661,
402,
4052,
652,
4910,
370,
298,
1065,
2,
282,
3650,
340,
2985,
880,
11496,
334,
69,
14,
71,
14,
282,
491,
91,
24120,
7801,
21385,
267,
768,
466,
7876,
26,
909,
267,
408,
267,
909,
855,
826,
721,
277,
9,
267,
291,
423,
1708,
3498,
275,
488,
267,
291,
423,
5933,
275,
485,
9232,
7801,
7446,
342,
398,
340,
2074,
14,
1989,
63,
498,
360,
1412,
735,
288,
291,
423,
1708,
3498,
275,
221,
2074,
459,
1412,
418,
398,
340,
2074,
14,
1989,
63,
498,
360,
5933,
735,
288,
291,
423,
5933,
275,
2074,
459,
5933,
418,
339,
347,
636,
495,
721,
277,
304,
267,
408,
1918,
491,
91,
7801,
6834,
83,
536,
1041,
267,
372,
291,
855,
533,
4914,
354,
363,
18407,
347,
485,
21266,
8,
277,
304,
372,
620,
8,
277,
9,
272,
347,
485,
1002,
7446,
8,
277,
304,
372,
291,
423,
5933,
272,
347,
485,
1002,
6652,
3498,
8,
277,
304,
372,
291,
423,
1708,
3498,
272,
347,
485,
1002,
2028,
8,
277,
304,
267,
340,
291,
14,
1412,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
3647,
83,
965,
949,
4568,
2112,
370,
298,
1467,
298,
2873,
877,
282,
4094,
5307,
2122,
450,
334,
277,
430,
267,
916,
291,
14,
1412,
14,
888,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
480,
3498,
450,
83,
965,
949,
4568,
298,
1467,
298,
2028,
5307,
2122,
450,
334,
277,
14,
1412,
430,
267,
587,
26,
288,
372,
291,
14,
1412,
14,
888,
339,
347,
485,
1002,
4455,
8,
277,
304,
267,
340,
291,
14,
1412,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
3647,
83,
965,
949,
4568,
2112,
370,
298,
1467,
298,
2873,
877,
282,
15996,
2122,
450,
334,
277,
430,
267,
916,
291,
14,
1412,
14,
2921,
365,
488,
26,
288,
746,
291,
14,
3184,
7801,
547,
480,
3498,
450,
83,
965,
949,
4568,
15996,
2122,
1467,
450,
334,
277,
14,
1412,
430,
267,
587,
26,
288,
372,
291,
14,
1412,
14,
2921,
339,
347,
5297,
8,
277,
12,
1499,
304,
267,
372,
291,
14,
2921,
14,
2445,
8,
1328,
12,
3650,
29,
277,
9,
2286,
347,
5297,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
lyfkevin/MIUIv5_iproj_kernel
|
Documentation/target/tcm_mod_builder.py
|
3119
|
42754
|
#!/usr/bin/python
# The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD
#
# Copyright (c) 2010 Rising Tide Systems
# Copyright (c) 2010 Linux-iSCSI.org
#
# Author: nab@kernel.org
#
import os, sys
import subprocess as sub
import string
import re
import optparse
tcm_dir = ""
fabric_ops = []
fabric_mod_dir = ""
fabric_mod_port = ""
fabric_mod_init_port = ""
def tcm_mod_err(msg):
print msg
sys.exit(1)
def tcm_mod_create_module_subdir(fabric_mod_dir_var):
if os.path.isdir(fabric_mod_dir_var) == True:
return 1
print "Creating fabric_mod_dir: " + fabric_mod_dir_var
ret = os.mkdir(fabric_mod_dir_var)
if ret:
tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)
return
def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* Binary World Wide unique Port Name for FC Initiator Nport */\n"
buf += " u64 nport_wwpn;\n"
buf += " /* ASCII formatted WWPN for FC Initiator Nport */\n"
buf += " char nport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* FC lport target portal group tag for TCM */\n"
buf += " u16 lport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n"
buf += " struct " + fabric_mod_name + "_lport *lport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_lport {\n"
buf += " /* SCSI protocol the lport is providing */\n"
buf += " u8 lport_proto_id;\n"
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
buf += " u64 lport_wwpn;\n"
buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n"
buf += " struct se_wwn lport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "lport"
fabric_mod_init_port = "nport"
return
def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* Binary World Wide unique Port Name for SAS Initiator port */\n"
buf += " u64 iport_wwpn;\n"
buf += " /* ASCII formatted WWPN for Sas Initiator port */\n"
buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* SAS port target portal group tag for TCM */\n"
buf += " u16 tport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
buf += " struct " + fabric_mod_name + "_tport *tport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tport {\n"
buf += " /* SCSI protocol the tport is providing */\n"
buf += " u8 tport_proto_id;\n"
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
buf += " u64 tport_wwpn;\n"
buf += " /* ASCII formatted WWPN for SAS Target port */\n"
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
buf += " struct se_wwn tport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "tport"
fabric_mod_init_port = "iport"
return
def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
global fabric_mod_port
global fabric_mod_init_port
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
buf += "\n"
buf += "struct " + fabric_mod_name + "_nacl {\n"
buf += " /* ASCII formatted InitiatorName */\n"
buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
buf += " struct se_node_acl se_node_acl;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tpg {\n"
buf += " /* iSCSI target portal group tag for TCM */\n"
buf += " u16 tport_tpgt;\n"
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
buf += " struct " + fabric_mod_name + "_tport *tport;\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
buf += " struct se_portal_group se_tpg;\n"
buf += "};\n\n"
buf += "struct " + fabric_mod_name + "_tport {\n"
buf += " /* SCSI protocol the tport is providing */\n"
buf += " u8 tport_proto_id;\n"
buf += " /* ASCII formatted TargetName for IQN */\n"
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
buf += " struct se_wwn tport_wwn;\n"
buf += "};\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
fabric_mod_port = "tport"
fabric_mod_init_port = "iport"
return
def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name):
if proto_ident == "FC":
tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name)
elif proto_ident == "SAS":
tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name)
elif proto_ident == "iSCSI":
tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name)
else:
print "Unsupported proto_ident: " + proto_ident
sys.exit(1)
return
def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c"
print "Writing file: " + f
p = open(f, 'w');
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "#include <linux/module.h>\n"
buf += "#include <linux/moduleparam.h>\n"
buf += "#include <linux/version.h>\n"
buf += "#include <generated/utsrelease.h>\n"
buf += "#include <linux/utsname.h>\n"
buf += "#include <linux/init.h>\n"
buf += "#include <linux/slab.h>\n"
buf += "#include <linux/kthread.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/string.h>\n"
buf += "#include <linux/configfs.h>\n"
buf += "#include <linux/ctype.h>\n"
buf += "#include <asm/unaligned.h>\n\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/target_core_transport.h>\n"
buf += "#include <target/target_core_fabric_ops.h>\n"
buf += "#include <target/target_core_fabric_configfs.h>\n"
buf += "#include <target/target_core_fabric_lib.h>\n"
buf += "#include <target/target_core_device.h>\n"
buf += "#include <target/target_core_tpg.h>\n"
buf += "#include <target/target_core_configfs.h>\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/configfs_macros.h>\n\n"
buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
buf += "/* Local pointer to allocated TCM configfs fabric module */\n"
buf += "struct target_fabric_configfs *" + fabric_mod_name + "_fabric_configfs;\n\n"
buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl;\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " u64 wwpn = 0;\n"
buf += " u32 nexus_depth;\n\n"
buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
buf += " return ERR_PTR(-EINVAL); */\n"
buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"
buf += " if (!(se_nacl_new))\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"
buf += " nexus_depth = 1;\n"
buf += " /*\n"
buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"
buf += " * when converting a NodeACL from demo mode -> explict\n"
buf += " */\n"
buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"
buf += " name, nexus_depth);\n"
buf += " if (IS_ERR(se_nacl)) {\n"
buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"
buf += " return se_nacl;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"
buf += " */\n"
buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"
buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
buf += " return se_nacl;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"
buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
buf += " kfree(nacl);\n"
buf += "}\n\n"
buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
buf += " struct se_wwn *wwn,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
buf += " unsigned long tpgt;\n"
buf += " int ret;\n\n"
buf += " if (strstr(name, \"tpgt_\") != name)\n"
buf += " return ERR_PTR(-EINVAL);\n"
buf += " if (strict_strtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
buf += " return ERR_PTR(-EINVAL);\n\n"
buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
buf += " if (!(tpg)) {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += " }\n"
buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
buf += " ret = core_tpg_register(&" + fabric_mod_name + "_fabric_configfs->tf_ops, wwn,\n"
buf += " &tpg->se_tpg, (void *)tpg,\n"
buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
buf += " if (ret < 0) {\n"
buf += " kfree(tpg);\n"
buf += " return NULL;\n"
buf += " }\n"
buf += " return &tpg->se_tpg;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
buf += " core_tpg_deregister(se_tpg);\n"
buf += " kfree(tpg);\n"
buf += "}\n\n"
buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
buf += " struct target_fabric_configfs *tf,\n"
buf += " struct config_group *group,\n"
buf += " const char *name)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " u64 wwpn = 0;\n\n"
buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
buf += " return ERR_PTR(-EINVAL); */\n\n"
buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
buf += " if (!(" + fabric_mod_port + ")) {\n"
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
buf += " return ERR_PTR(-ENOMEM);\n"
buf += " }\n"
if proto_ident == "FC" or proto_ident == "SAS":
buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "__NAMELEN, wwpn); */\n\n"
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
buf += "}\n\n"
buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
buf += " kfree(" + fabric_mod_port + ");\n"
buf += "}\n\n"
buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
buf += " struct target_fabric_configfs *tf,\n"
buf += " char *page)\n"
buf += "{\n"
buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
buf += " utsname()->machine);\n"
buf += "}\n\n"
buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
buf += " NULL,\n"
buf += "};\n\n"
buf += "static struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n"
buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n"
buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n"
buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
buf += " .release_cmd_to_pool = " + fabric_mod_name + "_release_cmd,\n"
buf += " .release_cmd_direct = " + fabric_mod_name + "_release_cmd,\n"
buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
buf += " .stop_session = " + fabric_mod_name + "_stop_session,\n"
buf += " .fall_back_to_erl0 = " + fabric_mod_name + "_reset_nexus,\n"
buf += " .sess_logged_in = " + fabric_mod_name + "_sess_logged_in,\n"
buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
buf += " .sess_get_initiator_sid = NULL,\n"
buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"
buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"
buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
buf += " .new_cmd_failure = " + fabric_mod_name + "_new_cmd_failure,\n"
buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
buf += " .get_fabric_sense_len = " + fabric_mod_name + "_get_fabric_sense_len,\n"
buf += " .set_fabric_sense_len = " + fabric_mod_name + "_set_fabric_sense_len,\n"
buf += " .is_state_remove = " + fabric_mod_name + "_is_state_remove,\n"
buf += " .pack_lun = " + fabric_mod_name + "_pack_lun,\n"
buf += " /*\n"
buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
buf += " */\n"
buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
buf += " .fabric_post_link = NULL,\n"
buf += " .fabric_pre_unlink = NULL,\n"
buf += " .fabric_make_np = NULL,\n"
buf += " .fabric_drop_np = NULL,\n"
buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"
buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"
buf += "};\n\n"
buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"
buf += "{\n"
buf += " struct target_fabric_configfs *fabric;\n"
buf += " int ret;\n\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
buf += " \" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
buf += " utsname()->machine);\n"
buf += " /*\n"
buf += " * Register the top level struct config_item_type with TCM core\n"
buf += " */\n"
buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n"
buf += " if (!(fabric)) {\n"
buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
buf += " return -ENOMEM;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"
buf += " */\n"
buf += " fabric->tf_ops = " + fabric_mod_name + "_ops;\n"
buf += " /*\n"
buf += " * Setup default attribute lists for various fabric->tf_cit_tmpl\n"
buf += " */\n"
buf += " TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"
buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"
buf += " /*\n"
buf += " * Register the fabric for use within TCM\n"
buf += " */\n"
buf += " ret = target_fabric_configfs_register(fabric);\n"
buf += " if (ret < 0) {\n"
buf += " printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"
buf += " \" for " + fabric_mod_name.upper() + "\\n\");\n"
buf += " return ret;\n"
buf += " }\n"
buf += " /*\n"
buf += " * Setup our local pointer to *fabric\n"
buf += " */\n"
buf += " " + fabric_mod_name + "_fabric_configfs = fabric;\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"
buf += " return 0;\n"
buf += "};\n\n"
buf += "static void " + fabric_mod_name + "_deregister_configfs(void)\n"
buf += "{\n"
buf += " if (!(" + fabric_mod_name + "_fabric_configfs))\n"
buf += " return;\n\n"
buf += " target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"
buf += " " + fabric_mod_name + "_fabric_configfs = NULL;\n"
buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"
buf += "};\n\n"
buf += "static int __init " + fabric_mod_name + "_init(void)\n"
buf += "{\n"
buf += " int ret;\n\n"
buf += " ret = " + fabric_mod_name + "_register_configfs();\n"
buf += " if (ret < 0)\n"
buf += " return ret;\n\n"
buf += " return 0;\n"
buf += "};\n\n"
buf += "static void " + fabric_mod_name + "_exit(void)\n"
buf += "{\n"
buf += " " + fabric_mod_name + "_deregister_configfs();\n"
buf += "};\n\n"
buf += "#ifdef MODULE\n"
buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
buf += "MODULE_LICENSE(\"GPL\");\n"
buf += "module_init(" + fabric_mod_name + "_init);\n"
buf += "module_exit(" + fabric_mod_name + "_exit);\n"
buf += "#endif\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_scan_fabric_ops(tcm_dir):
fabric_ops_api = tcm_dir + "include/target/target_core_fabric_ops.h"
print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
process_fo = 0;
p = open(fabric_ops_api, 'r')
line = p.readline()
while line:
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
line = p.readline()
continue
if process_fo == 0:
process_fo = 1;
line = p.readline()
# Search for function pointer
if not re.search('\(\*', line):
continue
fabric_ops.append(line.rstrip())
continue
line = p.readline()
# Search for function pointer
if not re.search('\(\*', line):
continue
fabric_ops.append(line.rstrip())
p.close()
return
def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
buf = ""
bufi = ""
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
print "Writing file: " + fi
pi = open(fi, 'w')
if not pi:
tcm_mod_err("Unable to open file: " + fi)
buf = "#include <linux/slab.h>\n"
buf += "#include <linux/kthread.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/list.h>\n"
buf += "#include <linux/types.h>\n"
buf += "#include <linux/string.h>\n"
buf += "#include <linux/ctype.h>\n"
buf += "#include <asm/unaligned.h>\n"
buf += "#include <scsi/scsi.h>\n"
buf += "#include <scsi/scsi_host.h>\n"
buf += "#include <scsi/scsi_device.h>\n"
buf += "#include <scsi/scsi_cmnd.h>\n"
buf += "#include <scsi/libfc.h>\n\n"
buf += "#include <target/target_core_base.h>\n"
buf += "#include <target/target_core_transport.h>\n"
buf += "#include <target/target_core_fabric_ops.h>\n"
buf += "#include <target/target_core_fabric_lib.h>\n"
buf += "#include <target/target_core_device.h>\n"
buf += "#include <target/target_core_tpg.h>\n"
buf += "#include <target/target_core_configfs.h>\n\n"
buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
total_fabric_ops = len(fabric_ops)
i = 0
while i < total_fabric_ops:
fo = fabric_ops[i]
i += 1
# print "fabric_ops: " + fo
if re.search('get_fabric_name', fo):
buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
buf += "{\n"
buf += " return \"" + fabric_mod_name[4:] + "\";\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
continue
if re.search('get_fabric_proto_ident', fo):
buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " u8 proto_id;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return proto_id;\n"
buf += "}\n\n"
bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
if re.search('get_wwn', fo):
buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
if re.search('get_tag', fo):
buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
if re.search('get_default_depth', fo):
buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"
if re.search('get_pr_transport_id\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl,\n"
buf += " struct t10_pr_registration *pr_reg,\n"
buf += " int *format_code,\n"
buf += " unsigned char *buf)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " int ret = 0;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code, buf);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return ret;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
bufi += " int *, unsigned char *);\n"
if re.search('get_pr_transport_id_len\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl,\n"
buf += " struct t10_pr_registration *pr_reg,\n"
buf += " int *format_code)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " int ret = 0;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
buf += " format_code);\n"
buf += " break;\n"
buf += " }\n\n"
buf += " return ret;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
bufi += " int *);\n"
if re.search('parse_pr_out_transport_id\)\(', fo):
buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " const char *buf,\n"
buf += " u32 *out_tid_len,\n"
buf += " char **port_nexus_ptr)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
buf += " char *tid = NULL;\n\n"
buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
if proto_ident == "FC":
buf += " case SCSI_PROTOCOL_FCP:\n"
buf += " default:\n"
buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
elif proto_ident == "SAS":
buf += " case SCSI_PROTOCOL_SAS:\n"
buf += " default:\n"
buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
elif proto_ident == "iSCSI":
buf += " case SCSI_PROTOCOL_ISCSI:\n"
buf += " default:\n"
buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
buf += " port_nexus_ptr);\n"
buf += " }\n\n"
buf += " return tid;\n"
buf += "}\n\n"
bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
bufi += " const char *, u32 *, char **);\n"
if re.search('alloc_fabric_acl\)\(', fo):
buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n"
buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"
buf += " if (!(nacl)) {\n"
buf += " printk(KERN_ERR \"Unable to alocate struct " + fabric_mod_name + "_nacl\\n\");\n"
buf += " return NULL;\n"
buf += " }\n\n"
buf += " return &nacl->se_node_acl;\n"
buf += "}\n\n"
bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"
if re.search('release_fabric_acl\)\(', fo):
buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"
buf += " struct se_portal_group *se_tpg,\n"
buf += " struct se_node_acl *se_nacl)\n"
buf += "{\n"
buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"
buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
buf += " kfree(nacl);\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"
bufi += " struct se_node_acl *);\n"
if re.search('tpg_get_inst_index\)\(', fo):
buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
buf += "{\n"
buf += " return 1;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
if re.search('release_cmd_to_pool', fo):
buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
if re.search('shutdown_session\)\(', fo):
buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
if re.search('close_session\)\(', fo):
buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
if re.search('stop_session\)\(', fo):
buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"
if re.search('fall_back_to_erl0\)\(', fo):
buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"
if re.search('sess_logged_in\)\(', fo):
buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"
if re.search('sess_get_index\)\(', fo):
buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
if re.search('write_pending\)\(', fo):
buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
if re.search('write_pending_status\)\(', fo):
buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
if re.search('set_default_node_attributes\)\(', fo):
buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
if re.search('get_task_tag\)\(', fo):
buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
if re.search('get_cmd_state\)\(', fo):
buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
if re.search('new_cmd_failure\)\(', fo):
buf += "void " + fabric_mod_name + "_new_cmd_failure(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return;\n"
buf += "}\n\n"
bufi += "void " + fabric_mod_name + "_new_cmd_failure(struct se_cmd *);\n"
if re.search('queue_data_in\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
if re.search('queue_status\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
if re.search('queue_tm_rsp\)\(', fo):
buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
if re.search('get_fabric_sense_len\)\(', fo):
buf += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void);\n"
if re.search('set_fabric_sense_len\)\(', fo):
buf += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *, u32);\n"
if re.search('is_state_remove\)\(', fo):
buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"
buf += "{\n"
buf += " return 0;\n"
buf += "}\n\n"
bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n"
if re.search('pack_lun\)\(', fo):
buf += "u64 " + fabric_mod_name + "_pack_lun(unsigned int lun)\n"
buf += "{\n"
buf += " WARN_ON(lun >= 256);\n"
buf += " /* Caller wants this byte-swapped */\n"
buf += " return cpu_to_le64((lun & 0xff) << 8);\n"
buf += "}\n\n"
bufi += "u64 " + fabric_mod_name + "_pack_lun(unsigned int);\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
ret = pi.write(bufi)
if ret:
tcm_mod_err("Unable to write fi: " + fi)
pi.close()
return
def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/Makefile"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
buf += " " + fabric_mod_name + "_configfs.o\n"
buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
buf = ""
f = fabric_mod_dir_var + "/Kconfig"
print "Writing file: " + f
p = open(f, 'w')
if not p:
tcm_mod_err("Unable to open file: " + f)
buf = "config " + fabric_mod_name.upper() + "\n"
buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
buf += " default n\n"
buf += " ---help---\n"
buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
ret = p.write(buf)
if ret:
tcm_mod_err("Unable to write f: " + f)
p.close()
return
def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
kbuild = tcm_dir + "/drivers/target/Makefile"
f = open(kbuild, 'a')
f.write(buf)
f.close()
return
def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
kconfig = tcm_dir + "/drivers/target/Kconfig"
f = open(kconfig, 'a')
f.write(buf)
f.close()
return
def main(modname, proto_ident):
# proto_ident = "FC"
# proto_ident = "SAS"
# proto_ident = "iSCSI"
tcm_dir = os.getcwd();
tcm_dir += "/../../"
print "tcm_dir: " + tcm_dir
fabric_mod_name = modname
fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
print "Set fabric_mod_name: " + fabric_mod_name
print "Set fabric_mod_dir: " + fabric_mod_dir
print "Using proto_ident: " + proto_ident
if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
print "Unsupported proto_ident: " + proto_ident
sys.exit(1)
ret = tcm_mod_create_module_subdir(fabric_mod_dir)
if ret:
print "tcm_mod_create_module_subdir() failed because module already exists!"
sys.exit(1)
tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_scan_fabric_ops(tcm_dir)
tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ")
if input == "yes" or input == "y":
tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ")
if input == "yes" or input == "y":
tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
return
parser = optparse.OptionParser()
parser.add_option('-m', '--modulename', help='Module name', dest='modname',
action='store', nargs=1, type='string')
parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
action='store', nargs=1, type='string')
(opts, args) = parser.parse_args()
mandatories = ['modname', 'protoident']
for m in mandatories:
if not opts.__dict__[m]:
print "mandatory option is missing\n"
parser.print_help()
exit(-1)
if __name__ == "__main__":
main(str(opts.modname), opts.protoident)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
710,
28526,
373,
20,
3510,
13,
3922,
2630,
859,
10152,
2884,
367,
19016,
15,
1375,
21792,
11365,
63,
8816,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
820,
11136,
377,
2655,
15285,
199,
3,
1898,
334,
67,
9,
7129,
10130,
13,
21534,
14,
1308,
199,
3,
199,
3,
6529,
26,
302,
371,
32,
4989,
14,
1308,
199,
3,
199,
646,
747,
12,
984,
199,
646,
3873,
465,
1007,
199,
646,
1059,
199,
646,
295,
199,
646,
8691,
199,
199,
10606,
63,
694,
275,
3087,
199,
199,
4991,
63,
1483,
275,
942,
199,
4991,
63,
1494,
63,
694,
275,
3087,
199,
4991,
63,
1494,
63,
719,
275,
3087,
199,
4991,
63,
1494,
63,
826,
63,
719,
275,
3087,
199,
199,
318,
15288,
63,
1494,
63,
1508,
8,
1328,
304,
199,
198,
1361,
1499,
199,
198,
1274,
14,
2224,
8,
17,
9,
199,
199,
318,
15288,
63,
1494,
63,
981,
63,
578,
63,
10622,
8,
4991,
63,
1494,
63,
694,
63,
1391,
304,
421,
198,
692,
747,
14,
515,
14,
6027,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
508,
715,
26,
507,
198,
1107,
413,
421,
198,
1361,
298,
14380,
2630,
63,
1494,
63,
694,
26,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
199,
198,
3292,
275,
747,
14,
8215,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
20366,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
9,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
4161,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
199,
198,
2966,
2630,
63,
1494,
63,
719,
199,
198,
2966,
2630,
63,
1494,
63,
826,
63,
719,
199,
198,
1436,
275,
3087,
421,
198,
70,
275,
2630,
63,
1494,
63,
694,
63,
1391,
435,
10609,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1095,
14,
72,
2,
199,
198,
1361,
298,
16646,
570,
26,
298,
435,
289,
421,
198,
80,
275,
1551,
8,
70,
12,
283,
87,
11339,
199,
198,
692,
440,
299,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
1551,
570,
26,
298,
435,
289,
9,
421,
198,
1436,
275,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
4612,
198,
4451,
86,
16,
14,
17,
13356,
78,
2,
199,
198,
1436,
847,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
198,
708,
60,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
7745,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
302,
719,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
302,
719,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
23964,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
932,
63,
5853,
542,
63,
932,
63,
5853,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
5249,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
20934,
27167,
1347,
18428,
1572,
1947,
367,
28526,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
975,
27167,
63,
28552,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
28833,
1771,
370,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
627,
25623,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
5249,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
8707,
63,
923,
542,
63,
5249,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
17822,
4113,
314,
27167,
365,
13070,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
24,
27167,
63,
2625,
63,
344,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
27167,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
27167,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
25623,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
10988,
27167,
63,
10988,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
421,
198,
3292,
275,
299,
14,
952,
8,
1436,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
2218,
289,
26,
298,
435,
289,
9,
421,
198,
80,
14,
1600,
342,
421,
198,
4991,
63,
1494,
63,
719,
275,
298,
25623,
2,
199,
198,
4991,
63,
1494,
63,
826,
63,
719,
275,
298,
78,
719,
2,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
15319,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
710,
28526,
373,
20,
3510,
13,
3922,
2630,
859,
10152,
2884,
367,
19016,
15,
1375,
21792,
11365,
63,
8816,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
820,
11136,
377,
2655,
15285,
199,
3,
1898,
334,
67,
9,
7129,
10130,
13,
21534,
14,
1308,
199,
3,
199,
3,
6529,
26,
302,
371,
32,
4989,
14,
1308,
199,
3,
199,
646,
747,
12,
984,
199,
646,
3873,
465,
1007,
199,
646,
1059,
199,
646,
295,
199,
646,
8691,
199,
199,
10606,
63,
694,
275,
3087,
199,
199,
4991,
63,
1483,
275,
942,
199,
4991,
63,
1494,
63,
694,
275,
3087,
199,
4991,
63,
1494,
63,
719,
275,
3087,
199,
4991,
63,
1494,
63,
826,
63,
719,
275,
3087,
199,
199,
318,
15288,
63,
1494,
63,
1508,
8,
1328,
304,
199,
198,
1361,
1499,
199,
198,
1274,
14,
2224,
8,
17,
9,
199,
199,
318,
15288,
63,
1494,
63,
981,
63,
578,
63,
10622,
8,
4991,
63,
1494,
63,
694,
63,
1391,
304,
421,
198,
692,
747,
14,
515,
14,
6027,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
508,
715,
26,
507,
198,
1107,
413,
421,
198,
1361,
298,
14380,
2630,
63,
1494,
63,
694,
26,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
199,
198,
3292,
275,
747,
14,
8215,
8,
4991,
63,
1494,
63,
694,
63,
1391,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
20366,
298,
435,
2630,
63,
1494,
63,
694,
63,
1391,
9,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
4161,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
199,
198,
2966,
2630,
63,
1494,
63,
719,
199,
198,
2966,
2630,
63,
1494,
63,
826,
63,
719,
199,
198,
1436,
275,
3087,
421,
198,
70,
275,
2630,
63,
1494,
63,
694,
63,
1391,
435,
10609,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1095,
14,
72,
2,
199,
198,
1361,
298,
16646,
570,
26,
298,
435,
289,
421,
198,
80,
275,
1551,
8,
70,
12,
283,
87,
11339,
199,
198,
692,
440,
299,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
1551,
570,
26,
298,
435,
289,
9,
421,
198,
1436,
275,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
4612,
198,
4451,
86,
16,
14,
17,
13356,
78,
2,
199,
198,
1436,
847,
5426,
4640,
298,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
198,
708,
60,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
7745,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
302,
719,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
21412,
707,
653,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
302,
719,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
23964,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
932,
63,
5853,
542,
63,
932,
63,
5853,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
5249,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
20934,
27167,
1347,
18428,
1572,
1947,
367,
28526,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
975,
27167,
63,
28552,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
28833,
1771,
370,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
627,
25623,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
5249,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
8707,
63,
923,
542,
63,
5249,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
199,
198,
1436,
847,
1867,
78,
2,
199,
198,
1436,
847,
298,
1820,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
25623,
9459,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
17822,
4113,
314,
27167,
365,
13070,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
24,
27167,
63,
2625,
63,
344,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
14161,
13064,
32612,
3747,
10977,
2812,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
85,
772,
27167,
63,
25944,
3779,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
10485,
7871,
30415,
9060,
367,
20934,
10256,
491,
719,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1560,
27167,
63,
354,
905,
435,
2630,
63,
1494,
63,
354,
14,
4142,
342,
435,
2668,
22168,
22842,
78,
2,
199,
198,
1436,
847,
298,
198,
6331,
19907,
701,
298,
435,
2630,
63,
1494,
63,
354,
435,
2668,
1875,
63,
25623,
342,
9399,
78,
2,
199,
198,
1436,
847,
298,
198,
1820,
542,
63,
10988,
27167,
63,
10988,
3779,
78,
2,
199,
198,
1436,
847,
18262,
78,
2,
421,
198,
3292,
275,
299,
14,
952,
8,
1436,
9,
199,
198,
692,
2203,
26,
507,
198,
10606,
63,
1494,
63,
1508,
480,
6005,
370,
2218,
289,
26,
298,
435,
289,
9,
421,
198,
80,
14,
1600,
342,
421,
198,
4991,
63,
1494,
63,
719,
275,
298,
25623,
2,
199,
198,
4991,
63,
1494,
63,
826,
63,
719,
275,
298,
78,
719,
2,
421,
198,
1107,
199,
199,
318,
15288,
63,
1494,
63,
1506,
63,
15319,
63,
2613,
8,
4991,
63,
1494,
63,
694,
63,
1391,
12,
2630,
63,
1494,
63,
354,
304,
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,
1
] |
wreckJ/intellij-community
|
python/helpers/pydev/pydevd_traceproperty.py
|
53
|
3777
|
'''For debug purpose we are replacing actual builtin property by the debug property
'''
from pydevd_comm import GetGlobalDebugger
from pydevd_constants import * #@UnusedWildImport
import pydevd_tracing
#=======================================================================================================================
# replace_builtin_property
#=======================================================================================================================
def replace_builtin_property(new_property=None):
if new_property is None:
new_property = DebugProperty
original = property
if not IS_PY3K:
try:
import __builtin__
__builtin__.__dict__['property'] = new_property
except:
if DebugInfoHolder.DEBUG_TRACE_LEVEL:
import traceback;traceback.print_exc() #@Reimport
else:
try:
import builtins #Python 3.0 does not have the __builtin__ module @UnresolvedImport
builtins.__dict__['property'] = new_property
except:
if DebugInfoHolder.DEBUG_TRACE_LEVEL:
import traceback;traceback.print_exc() #@Reimport
return original
#=======================================================================================================================
# DebugProperty
#=======================================================================================================================
class DebugProperty(object):
"""A custom property which allows python property to get
controlled by the debugger and selectively disable/re-enable
the tracing.
"""
def __init__(self, fget=None, fset=None, fdel=None, doc=None):
self.fget = fget
self.fset = fset
self.fdel = fdel
self.__doc__ = doc
def __get__(self, obj, objtype=None):
if obj is None:
return self
global_debugger = GetGlobalDebugger()
try:
if global_debugger is not None and global_debugger.disable_property_getter_trace:
pydevd_tracing.SetTrace(None)
if self.fget is None:
raise AttributeError("unreadable attribute")
return self.fget(obj)
finally:
if global_debugger is not None:
pydevd_tracing.SetTrace(global_debugger.trace_dispatch)
def __set__(self, obj, value):
global_debugger = GetGlobalDebugger()
try:
if global_debugger is not None and global_debugger.disable_property_setter_trace:
pydevd_tracing.SetTrace(None)
if self.fset is None:
raise AttributeError("can't set attribute")
self.fset(obj, value)
finally:
if global_debugger is not None:
pydevd_tracing.SetTrace(global_debugger.trace_dispatch)
def __delete__(self, obj):
global_debugger = GetGlobalDebugger()
try:
if global_debugger is not None and global_debugger.disable_property_deleter_trace:
pydevd_tracing.SetTrace(None)
if self.fdel is None:
raise AttributeError("can't delete attribute")
self.fdel(obj)
finally:
if global_debugger is not None:
pydevd_tracing.SetTrace(global_debugger.trace_dispatch)
def getter(self, fget):
"""Overriding getter decorator for the property
"""
self.fget = fget
return self
def setter(self, fset):
"""Overriding setter decorator for the property
"""
self.fset = fset
return self
def deleter(self, fdel):
"""Overriding deleter decorator for the property
"""
self.fdel = fdel
return self
|
apache-2.0
|
[
2344,
1858,
3105,
12016,
781,
787,
15810,
3503,
6762,
3324,
701,
314,
3105,
3324,
199,
2344,
199,
504,
29240,
68,
63,
1404,
492,
2372,
7025,
31521,
199,
504,
29240,
68,
63,
5559,
492,
627,
9213,
20782,
55,
668,
6295,
199,
646,
29240,
68,
63,
21635,
199,
199,
14813,
12813,
18673,
199,
3,
3350,
63,
5351,
63,
1829,
199,
14813,
12813,
18673,
199,
318,
3350,
63,
5351,
63,
1829,
8,
1222,
63,
1829,
29,
403,
304,
272,
340,
892,
63,
1829,
365,
488,
26,
267,
892,
63,
1829,
275,
14245,
3697,
272,
3379,
275,
3324,
272,
340,
440,
2281,
63,
4521,
19,
43,
26,
267,
862,
26,
288,
492,
636,
5351,
363,
288,
636,
5351,
4914,
807,
23010,
1829,
418,
275,
892,
63,
1829,
267,
871,
26,
288,
340,
14245,
2354,
22570,
14,
5287,
63,
20112,
63,
11817,
26,
355,
492,
5190,
27,
6894,
14,
1361,
63,
2804,
342,
9213,
497,
646,
272,
587,
26,
267,
862,
26,
288,
492,
12963,
327,
4718,
650,
14,
16,
1630,
440,
1172,
314,
636,
5351,
363,
859,
768,
1358,
13697,
6295,
288,
12963,
855,
807,
23010,
1829,
418,
275,
892,
63,
1829,
267,
871,
26,
288,
340,
14245,
2354,
22570,
14,
5287,
63,
20112,
63,
11817,
26,
355,
492,
5190,
27,
6894,
14,
1361,
63,
2804,
342,
9213,
497,
646,
272,
372,
3379,
421,
199,
14813,
12813,
18673,
199,
3,
14245,
3697,
199,
14813,
12813,
18673,
199,
533,
14245,
3697,
8,
785,
304,
272,
408,
33,
3537,
3324,
1314,
6127,
2366,
3324,
370,
664,
272,
22284,
701,
314,
14958,
436,
542,
10251,
9462,
3507,
15,
264,
13,
4296,
272,
314,
23465,
14,
272,
408,
2378,
347,
636,
826,
721,
277,
12,
289,
362,
29,
403,
12,
289,
409,
29,
403,
12,
289,
2264,
29,
403,
12,
1382,
29,
403,
304,
267,
291,
14,
27823,
275,
289,
362,
267,
291,
14,
70,
409,
275,
289,
409,
267,
291,
14,
70,
2264,
275,
289,
2264,
267,
291,
855,
1301,
363,
275,
1382,
2378,
347,
636,
362,
721,
277,
12,
1559,
12,
1559,
466,
29,
403,
304,
267,
340,
1559,
365,
488,
26,
288,
372,
291,
267,
2288,
63,
17612,
275,
2372,
7025,
31521,
342,
267,
862,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
436,
2288,
63,
17612,
14,
5993,
63,
1829,
63,
7416,
63,
3446,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
403,
9,
288,
340,
291,
14,
27823,
365,
488,
26,
355,
746,
4281,
480,
324,
11875,
2225,
531,
288,
372,
291,
14,
27823,
8,
1113,
9,
267,
3753,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
2966,
63,
17612,
14,
3446,
63,
6052,
9,
2378,
347,
636,
409,
721,
277,
12,
1559,
12,
574,
304,
267,
2288,
63,
17612,
275,
2372,
7025,
31521,
342,
267,
862,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
436,
2288,
63,
17612,
14,
5993,
63,
1829,
63,
8345,
63,
3446,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
403,
9,
288,
340,
291,
14,
70,
409,
365,
488,
26,
355,
746,
4281,
480,
2425,
1133,
663,
2225,
531,
288,
291,
14,
70,
409,
8,
1113,
12,
574,
9,
267,
3753,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
2966,
63,
17612,
14,
3446,
63,
6052,
9,
2378,
347,
636,
1807,
721,
277,
12,
1559,
304,
267,
2288,
63,
17612,
275,
2372,
7025,
31521,
342,
267,
862,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
436,
2288,
63,
17612,
14,
5993,
63,
1829,
63,
7346,
351,
63,
3446,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
403,
9,
288,
340,
291,
14,
70,
2264,
365,
488,
26,
355,
746,
4281,
480,
2425,
1133,
3145,
2225,
531,
288,
291,
14,
70,
2264,
8,
1113,
9,
267,
3753,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
2966,
63,
17612,
14,
3446,
63,
6052,
9,
2378,
347,
15917,
8,
277,
12,
289,
362,
304,
267,
408,
5674,
15526,
15917,
7531,
367,
314,
3324,
267,
408,
267,
291,
14,
27823,
275,
289,
362,
267,
372,
291,
2378,
347,
18743,
8,
277,
12,
289,
409,
304,
267,
408,
5674,
15526,
18743,
7531,
367,
314,
3324,
267,
408,
267,
291,
14,
70,
409,
275,
289,
409,
267,
372,
291,
2378,
347,
6070,
351,
8,
277,
12,
289,
2264,
304,
267,
408,
5674,
15526,
6070,
351,
7531,
367,
314,
3324,
267,
408,
267,
291,
14,
70,
2264,
275,
289,
2264,
267,
372,
291,
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
] |
[
1858,
3105,
12016,
781,
787,
15810,
3503,
6762,
3324,
701,
314,
3105,
3324,
199,
2344,
199,
504,
29240,
68,
63,
1404,
492,
2372,
7025,
31521,
199,
504,
29240,
68,
63,
5559,
492,
627,
9213,
20782,
55,
668,
6295,
199,
646,
29240,
68,
63,
21635,
199,
199,
14813,
12813,
18673,
199,
3,
3350,
63,
5351,
63,
1829,
199,
14813,
12813,
18673,
199,
318,
3350,
63,
5351,
63,
1829,
8,
1222,
63,
1829,
29,
403,
304,
272,
340,
892,
63,
1829,
365,
488,
26,
267,
892,
63,
1829,
275,
14245,
3697,
272,
3379,
275,
3324,
272,
340,
440,
2281,
63,
4521,
19,
43,
26,
267,
862,
26,
288,
492,
636,
5351,
363,
288,
636,
5351,
4914,
807,
23010,
1829,
418,
275,
892,
63,
1829,
267,
871,
26,
288,
340,
14245,
2354,
22570,
14,
5287,
63,
20112,
63,
11817,
26,
355,
492,
5190,
27,
6894,
14,
1361,
63,
2804,
342,
9213,
497,
646,
272,
587,
26,
267,
862,
26,
288,
492,
12963,
327,
4718,
650,
14,
16,
1630,
440,
1172,
314,
636,
5351,
363,
859,
768,
1358,
13697,
6295,
288,
12963,
855,
807,
23010,
1829,
418,
275,
892,
63,
1829,
267,
871,
26,
288,
340,
14245,
2354,
22570,
14,
5287,
63,
20112,
63,
11817,
26,
355,
492,
5190,
27,
6894,
14,
1361,
63,
2804,
342,
9213,
497,
646,
272,
372,
3379,
421,
199,
14813,
12813,
18673,
199,
3,
14245,
3697,
199,
14813,
12813,
18673,
199,
533,
14245,
3697,
8,
785,
304,
272,
408,
33,
3537,
3324,
1314,
6127,
2366,
3324,
370,
664,
272,
22284,
701,
314,
14958,
436,
542,
10251,
9462,
3507,
15,
264,
13,
4296,
272,
314,
23465,
14,
272,
408,
2378,
347,
636,
826,
721,
277,
12,
289,
362,
29,
403,
12,
289,
409,
29,
403,
12,
289,
2264,
29,
403,
12,
1382,
29,
403,
304,
267,
291,
14,
27823,
275,
289,
362,
267,
291,
14,
70,
409,
275,
289,
409,
267,
291,
14,
70,
2264,
275,
289,
2264,
267,
291,
855,
1301,
363,
275,
1382,
2378,
347,
636,
362,
721,
277,
12,
1559,
12,
1559,
466,
29,
403,
304,
267,
340,
1559,
365,
488,
26,
288,
372,
291,
267,
2288,
63,
17612,
275,
2372,
7025,
31521,
342,
267,
862,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
436,
2288,
63,
17612,
14,
5993,
63,
1829,
63,
7416,
63,
3446,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
403,
9,
288,
340,
291,
14,
27823,
365,
488,
26,
355,
746,
4281,
480,
324,
11875,
2225,
531,
288,
372,
291,
14,
27823,
8,
1113,
9,
267,
3753,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
2966,
63,
17612,
14,
3446,
63,
6052,
9,
2378,
347,
636,
409,
721,
277,
12,
1559,
12,
574,
304,
267,
2288,
63,
17612,
275,
2372,
7025,
31521,
342,
267,
862,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
436,
2288,
63,
17612,
14,
5993,
63,
1829,
63,
8345,
63,
3446,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
403,
9,
288,
340,
291,
14,
70,
409,
365,
488,
26,
355,
746,
4281,
480,
2425,
1133,
663,
2225,
531,
288,
291,
14,
70,
409,
8,
1113,
12,
574,
9,
267,
3753,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
2966,
63,
17612,
14,
3446,
63,
6052,
9,
2378,
347,
636,
1807,
721,
277,
12,
1559,
304,
267,
2288,
63,
17612,
275,
2372,
7025,
31521,
342,
267,
862,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
436,
2288,
63,
17612,
14,
5993,
63,
1829,
63,
7346,
351,
63,
3446,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
403,
9,
288,
340,
291,
14,
70,
2264,
365,
488,
26,
355,
746,
4281,
480,
2425,
1133,
3145,
2225,
531,
288,
291,
14,
70,
2264,
8,
1113,
9,
267,
3753,
26,
288,
340,
2288,
63,
17612,
365,
440,
488,
26,
355,
29240,
68,
63,
21635,
14,
1084,
3921,
8,
2966,
63,
17612,
14,
3446,
63,
6052,
9,
2378,
347,
15917,
8,
277,
12,
289,
362,
304,
267,
408,
5674,
15526,
15917,
7531,
367,
314,
3324,
267,
408,
267,
291,
14,
27823,
275,
289,
362,
267,
372,
291,
2378,
347,
18743,
8,
277,
12,
289,
409,
304,
267,
408,
5674,
15526,
18743,
7531,
367,
314,
3324,
267,
408,
267,
291,
14,
70,
409,
275,
289,
409,
267,
372,
291,
2378,
347,
6070,
351,
8,
277,
12,
289,
2264,
304,
267,
408,
5674,
15526,
6070,
351,
7531,
367,
314,
3324,
267,
408,
267,
291,
14,
70,
2264,
275,
289,
2264,
267,
372,
291,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
'''
SASSIE: Copyright (C) 2011 Joseph E. Curtis, Ph.D.
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/>.
'''
# SASPROPERTIES
#
# 12/10/2009 -- initial coding : jc
# 11/24/2011 -- moved to seperate file : jc
# 1 2 3 4 5 6 7
# LC4567890123456789012345678901234567890123456789012345678901234567890123456789
# * **
'''
SasProperties contains the classes that contain
atomic and molecular properties
'''
# OPEN Need a consistent way to initialize "Selection/Atm" to avoid duplication
class Atomic(object):
'''
This class contains atomic information used my other modules.
http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl?ele=&ascii=html&isotype=some
standard atomic weight is based on the natural istopic composition
'''
one_to_three_letter_protein_residue_dictionary = {
'A' : 'ALA',
'R' : 'ARG',
'D' : 'ASP',
'N' : 'ASN',
'C' : 'CYS',
'E' : 'GLU',
'Q' : 'GLN',
'G' : 'GLY',
'H' : 'HSE',
'I' : 'ILE',
'L' : 'LEU',
'K' : 'LYS',
'M' : 'MET',
'F' : 'PHE',
'P' : 'PRO',
'S' : 'SER',
'T' : 'THR',
'W' : 'TRP',
'Y' : 'TYR',
'V' : 'VAL'
}
one_to_three_letter_nucleic_residue_dictionary = {
'G' : 'GUA',
'C' : 'CYT',
'A' : 'ADE',
'T' : 'THY',
'U' : 'URA'
}
def amu(self, **kwargs):
mixed_standard_atomic_weight = {'H': 1.007947, 'He': 4.0026022,
'Li': 6.9412, 'Be': 9.0121823, 'B': 10.8117, 'C': 12.01078,
'N': 14.00672, 'O': 15.99943, 'F': 18.99840325, 'Ne': 20.17976,
'Na': 22.9897702, 'Mg': 24.30506, 'Al': 26.9815382, 'Si': 28.08553,
'P': 30.9737612, 'S': 32.0655, 'Cl': 35.4532, 'Ar': 39.9481,
'K': 39.09831, 'Ca': 40.0784, 'Sc': 44.9559108, 'Ti': 47.8671,
'V': 50.94151, 'Cr': 51.99616, 'Mn': 54.9380499, 'Fe': 55.8452,
'Co': 58.9332009, 'Ni': 58.69342, 'Cu': 63.5463, 'Zn': 65.4094,
'Ga': 69.7231, 'Ge': 72.641, 'As': 74.921602, 'Se': 78.963,
'Br': 79.9041, 'Kr': 83.7982, 'Rb': 85.46783, 'Sr': 87.621,
'Y': 88.905852, 'Zr': 91.2242, 'Nb': 92.906382, 'Mo': 95.942,
'Tc': 98.0, 'Ru': 101.072, 'Rh': 102.905502, 'Pd': 106.421,
'Ag': 107.86822, 'Cd': 112.4118, 'In': 114.8183, 'Sn': 118.7107,
'Sb': 121.7601, 'Te': 127.603, 'I': 126.904473, 'Xe': 131.2936,
'Cs': 132.905452, 'Ba': 137.3277, 'La': 138.90552, 'Ce': 140.1161,
'Pr': 140.907652, 'Nd': 144.243, 'Pm': 145.0, 'Sm': 150.363,
'Eu': 151.9641, 'Gd': 157.253, 'Tb': 158.925342, 'Dy': 162.5001,
'Ho': 164.930322, 'Er': 167.2593, 'Tm': 168.93421, 'Yb': 173.043,
'Lu': 174.9671, 'Hf': 174.9671, 'Ta': 180.94791, 'W': 183.841,
'Re': 186.2071, 'Os': 190.233, 'Ir': 192.2173, 'Pt': 195.0782,
'Au': 196.966552, 'Hg': 200.592, 'Tl': 204.38332, 'Pb': 207.21,
'Bi': 208.980382, 'Po': 209.0, 'At': 210.0, 'Rn': 222.0, 'Fr': 223.0,
'Ra': 226.0, 'Ac': 227.0, 'Th': 232.03811, 'Pa': 231.035882,
'U': 238.028913, 'D': 2.01410177804, '1H': 1.00782503214}
#'U': 238.028913, 'D': 2.01410177804, '1H': 1.00782503214}
standard_atomic_weight = {}
for key, item in mixed_standard_atomic_weight.items():
if 'keep_lower_case' in kwargs:
standard_atomic_weight[key] = item
else:
standard_atomic_weight[key.upper()] = item
# print 'saw = ',standard_atomic_weight
return standard_atomic_weight
def charmm_names(self):
hydrogen = ['HN', 'HA', 'HB1', 'HB2', 'HB3', 'HG1', 'HG2', 'HD1', 'HD2', 'HE', 'HH11', 'HH12', 'HH21', 'HH22', 'HD21', 'HD22', 'HE21', 'HE22', 'HA1', 'HA2', 'HE1', 'HE2', 'HB', 'HG21', 'HG22', 'HG23', 'HG11', 'HG12', 'HD3', 'HG', 'HD11', 'HD12', 'HD13', 'HD23', 'HZ1', 'HZ2', 'HZ3', 'HE3', 'HZ', 'HH2', 'HH', 'HG13', 'H1', 'H2', 'HC', 'HD', 'HMA1', 'HMA2', 'HMA3', 'HAA1', 'HAA2', 'HBA1', 'HBA2', 'HMB1', 'HMB2', 'HMB3', 'HAB', 'HBB1', 'HBB2', 'HMC1', 'HMC2', 'HMC3', 'HAC', 'HBC1', 'HBC2', 'HMD1', 'HMD2', 'HMD3', 'HAD1', 'HAD2', 'HBD1', 'HBD2', 'HT1', 'HT2', 'HT3', 'HN1', 'HN2', 'HY1', 'HY2',
'HY3', 'HNT', "H5'", "H5''", "H4'", "H1'", 'H21', 'H22', 'H8', "H2''", "H2'", "H3'", 'H61', 'H62', 'H6', 'H5', 'H41', 'H42', 'H3', 'H51', 'H52', 'H53', 'H11', 'H12', 'H13', 'H23', 'H9', 'H5T', "H53'", 'H5T1', 'H5T2', 'H5T3', 'H3T', 'H3T1', 'H3T2', 'H3T3', 'H91', 'H92', 'H93', 'H9B1', 'H9B2', 'H9B3', 'H5M1', 'H5M2', 'H5M3', 'H4', 'H15', 'H16', 'H17', "H11'", "H12'", "H21'", "H22'", "H31'", "H32'", "H41'", "H42'", "H51'", "H52'", "H1''", "H4''", "H3''", "1H3'", "1H3''", "1H2''", "2H5'", "2H5''", "AH4'", "AH1'", 'AH8', 'AH2', "AH2'", 'AH61', 'AH62', 'AH2T', "AH3'", 'AH3T', "AH5'", 'AH5S']
carbon = ["CA", "CB", "C", "CG", "CD", "CZ", "CE1", "CD2", "CG2", "CG1", "CD1", "CE", "CE2", "CE3", "CZ3", "CZ2", "CH2", "C1A", "C2A", "C3A", "C4A", "C1B", 'C2B', 'C3B', 'C4B', 'C1C', 'C2C', 'C3C', 'C4C', 'C1D', 'C2D', 'C3D', 'C4D', 'CHA', 'CHB', 'CHC', 'CHD', 'CMA', 'CAA', 'CBA', 'CGA', 'CMB', 'CAB', 'CBB', 'CMC',
'CAC', 'CBC', 'CMD', 'CAD', 'CBD', 'CGD', 'CAY', 'CY', 'CT', 'CAT', "C5'", "C4'", "C1'", 'C4', 'C2', 'C6', 'C5', 'C8', "C2'", "C3'", 'C5M', 'C1', 'C5T', 'C3T', 'C9', 'C9B', 'C3', 'C7', 'C10', 'C12', '1CB', '2CB', "1C3'", "1C2'", "2C5'", "AC4'", "AC1'", 'AC5', 'AC8', 'AC2', 'AC4', 'AC6', "AC2'", "AC3'", "AC5'"]
nitrogen = ['N', 'NH1', 'NH2', 'ND2', 'NE2', 'ND1', 'NZ', 'NE1', 'NA', 'NB', 'NC', 'ND', 'NT', 'N9', 'N2', 'N3', 'N1', 'N7', 'N6', 'N4', 'N14', 'NP', 'NO1', 'NO2', "NO5'", "NC5'", 'NH5S', "NH5'", "NC2'", "NH2'", "NO2'",
'NH2T', "NC3'", "NH3'", "NO3'", 'NH3T', "NC1'", "NH1'", "NC4'", "NH4'", "NO4'", 'NN1', 'NC6', 'NH6', 'NC5', 'NH5', 'NC4', 'NH4', 'NC3', 'NC2', 'NC7', 'NO7', 'NN7', 'NH71', 'NH72', 'NH42', 'AN7', 'AN9', 'AN1', 'AN3', 'AN6']
oxygen = ['O', 'OD1', 'OD2', 'OE1', 'OE2', 'OG', 'OG1', 'OH', 'OH2', 'O1A', 'O2A', 'O1D', 'O2D', 'OY', 'OT1', 'OT2', 'O1', 'O2', 'O3', 'O4', 'O1P', 'O2P', "O5'", "O4'", 'O6', "O2'", "O3'", 'O5T', 'O1P3', 'O2P3', 'O3T', 'O3P3', 'O13',
'O11', 'O12', 'O14', 'O22', 'O23', 'O24', 'O3A', 'O1B', 'O2B', 'O3B', 'O1G', 'O2G', 'O3G', 'O21', 'O3P', 'O31P', 'O32P', 'O33P', "1O2'", '2O1P', '2O2P', "2O5'", "AO4'", "AO2'", "AO3'", 'AO1', 'AO2', "AO5'", 'AO1P', 'AO2P', 'AO2T', 'OM']
sulfur = ['SG', 'SD', '1SG', '2SG']
phosphorus = [
'P1', 'P', 'P3', 'P2', 'PA', 'PB', 'PG', '2P', 'AP', 'AP2']
other = ['AS', 'AG', 'AL', 'AR', 'AC', 'AT', 'AU', 'BI', 'BE', 'B', 'BR', 'BA', 'CR', 'CS', 'CU', 'CO', 'D', 'DY', 'EU', 'ER', 'F', 'FE', 'FR', 'GA', 'GE', 'GD', 'HO', 'HF', 'IN', 'I', 'IR', 'K', 'KR', 'LI', 'LA', 'LU', 'MG', 'MN', 'MO', 'NE',
'NI', 'OS', 'PD', 'PR', 'PM', 'PT', 'PO', 'RB', 'RU', 'RH', 'RE', 'RN', 'RA', 'SI', 'SC', 'SE', 'SR', 'SN', 'SB', 'SM', 'TI', 'TC', 'TE', 'TB', 'TA', 'TL', 'TH', 'U', 'V', 'W', 'XE', 'Y', 'YB', 'ZN', 'ZR', 'SS', 'CAL', 'DUM', 'POT', 'CES', 'CLA']
# note that SM is C-S-S-C not Sm (the element)
# note that SM is C-S-S-C not Sm (the element)
return hydrogen, carbon, nitrogen, oxygen, sulfur, phosphorus, other
def amino_acid_sld(self):
# residue name : [vol Ang^3, eSL, SLprot Ang, SLdeut Ang, #exchngH]
residue_scattering = {
'ALA': [88.6, 38, 20.1466, 61.7942, 1],
'ARG': [173.4, 85, 56.9491, 129.8324, 6],
'ASP': [111.1, 59, 42.149, 73.3816, 1],
'ASN': [114.1, 60, 45.7009, 76.9366, 3],
'CYS': [108.5, 54, 26.7345, 57.9702, 2],
'GLU': [138.4, 67, 41.371, 93.372, 1],
'GLN': [143.8, 68, 44.8675, 96.927, 3],
'GLY': [60.1, 30, 20.98, 41.8038, 1],
'HSD': [153.2, 72, 55.0709, 107.1304, 2],
'HIS': [153.2, 72, 55.0709, 107.1304, 2],
'HSE': [153.2, 72, 55.0709, 107.1304, 2],
'HSP': [153.2, 72, 55.0709, 107.1304, 3],
'ILE': [166.7, 62, 17.6464, 121.7654, 1],
'LEU': [166.7, 62, 17.6464, 121.7654, 1],
'LYS': [168.6, 71, 30.7473, 124.4544, 4],
'MET': [162.9, 70, 21.3268, 104.622, 1],
'PHE': [189.9, 78, 45.0734, 128.3686, 1],
'PRO': [112.7, 52, 22.2207, 95.104, 0],
'SER': [89.0, 46, 29.6925, 60.9282, 2],
'THR': [116.1, 54, 25.1182, 87.5896, 2],
'TRP': [227.8, 98, 67.7302, 151.0254, 2],
'TYR': [193.6, 86, 54.6193, 127.5026, 2],
'VAL': [140.0, 54, 18.4798, 101.775, 1]}
return residue_scattering
def element_sl(self):
# element name : [MW, vol Ang^3, eSL Ang, nSL Ang]
# approx volumes are per Whitten 2008
atomic_scattering = {
'D': [2.014, 5.15, 0.282, 0.6671],
'H': [1.008, 5.15, 0.282, -0.3741],
'C': [12.01, 16.44, 1.692, 0.6646],
'N': [14.01, 2.49, 1.974, 0.9360],
'O': [16.00, 9.130, 2.256, 0.5803],
'Na': [22.99, 4.45, 3.102, 0.3630],
'Mg': [24.31, 1.56, 3.384, 0.5375],
'K': [39.10, 11.01, 5.358, 0.3670],
'Ca': [40.08, 4.19, 5.640, 0.4700],
'Cl': [35.45, 24.84, 4.794, 0.9577],
'Br': [79.90, 31.54, 9.870, 0.6795],
'I': [126.9, 44.6, 14.946, 0.5280],
'P': [30.97, 3.37, 4.230, 0.5130],
'S': [32.07, 26.09, 4.512, 0.2847],
'Fe': [55.85, 7.99, 7.332, 0.9450],
'Co': [58.93, 7.99, 7.614, 0.2490],
'Ni': [58.69, 8.18, 7.896, 1.0300],
'Cu': [63.55, 8.78, 8.178, 0.7718],
'Zn': [65.39, 9.85, 8.460, 0.5680]}
return atomic_scattering
def nucleotide_sl(self):
# nucleotide name : [MW, vol Ang^3, eSL Ang, SLprot Ang, SLdeut Ang, #exchngH, #totalH]
# vol = MW*(0.586 cm^3/g)/NA
# electron scattering lengths = Thompson radius (2.82 x 10^-13 cm) * atomic number
# molecule formulae are for nucleotides as embedded in a chain, per
# Jacrot 1976
residue_scattering = {
'DA': [313.0, 304.7, 45.3, 10.65, 12.73, 2, 11],
'DT': [304.0, 294.9, 44.2, 8.61, 9.65, 1, 12], # 303
'DG': [329.0, 319.2, 47.6, 11.23, 14.35, 3, 11], # 328
'DC': [289.0, 280.3, 41.9, 8.68, 10.77, 2, 11], # 288
'U': [305.0, 296.9, 44.2, 9.28, 11.36, 2, 10],
'A': [328.0, 319.2, 47.6, 10.65, 12.73, 2, 11],
'G': [344.0, 334.9, 49.8, 11.23, 14.35, 3, 11],
'C': [304.0, 295.9, 44.2, 8.68, 10.77, 2, 11]}
return residue_scattering
def dna_sl(self):
# nucleotide name : [MW, vol Ang^3, eSL Ang, SLprot Ang, SLdeut Ang, #exchngH, #totalH]
# vol = MW*(0.56 cm^3/g)/NA, where partial specific volume of 0.56 is per Hearst 1962, JMB 4, 415-417
# psv depends on pH and salt, so there is a range between ~0.55-0.59
# electron scattering lengths = Thompson radius (2.82 x 10^-13 cm) * atomic number
# molecule formulae are for nucleotides as embedded in a chain, per
# Jacrot 1976
residue_scattering = {
'DA': [313.0, 304.7, 45.3, 10.65, 12.73, 2, 11],
'DT': [304.0, 294.9, 44.2, 8.61, 9.65, 1, 12], # 303
'DG': [329.0, 319.2, 47.6, 11.23, 14.35, 3, 11], # 328
'DC': [289.0, 280.3, 41.9, 8.68, 10.77, 2, 11],
'ADE': [313.0, 304.7, 45.3, 10.65, 12.73, 2, 11],
'THY': [304.0, 294.9, 44.2, 8.61, 9.65, 1, 12], # 303
'GUA': [329.0, 319.2, 47.6, 11.23, 14.35, 3, 11], # 328
'CYT': [289.0, 280.3, 41.9, 8.68, 10.77, 2, 11],
'A': [313.0, 304.7, 45.3, 10.65, 12.73, 2, 11],
'T': [304.0, 294.9, 44.2, 8.61, 9.65, 1, 12], # 303
'G': [329.0, 319.2, 47.6, 11.23, 14.35, 3, 11], # 328
'C': [289.0, 280.3, 41.9, 8.68, 10.77, 2, 11]} # 288
return residue_scattering
def rna_sl(self):
# nucleotide name : [MW, vol Ang^3, eSL Ang, SLprot Ang, SLdeut Ang, #exchngH, #totalH]
# vol = MW*(0.55 cm^3/g)/NA, where the partial specific volume of 0.55 is from Chien, et al. 2004,
# Biochemistry 43, 1950-1962. psv depends on pH and salt and whether RNA is ss or ds. This value
# is at the high end of the range for ssRNA, ~0.47-0.55. psv is larger
# for dsRNA, ~0.57.
# electron scattering lengths = Thompson radius (2.82 x 10^-13 cm) * atomic number
# molecule formulae are for nucleotides as embedded in a chain, per
# Jacrot 1976
residue_scattering = {
'U': [305.0, 296.9, 44.2, 9.28, 11.36, 2, 10],
'A': [328.0, 319.2, 47.6, 10.65, 12.73, 2, 11],
'G': [344.0, 334.9, 49.8, 11.23, 14.35, 3, 11],
'C': [304.0, 295.9, 44.2, 8.68, 10.77, 2, 11],
'URA': [305.0, 296.9, 44.2, 9.28, 11.36, 2, 10],
'ADE': [328.0, 319.2, 47.6, 10.65, 12.73, 2, 11],
'GUA': [344.0, 334.9, 49.8, 11.23, 14.35, 3, 11],
'CYT': [304.0, 295.9, 44.2, 8.68, 10.77, 2, 11]}
return residue_scattering
def protein_sl(self):
# aa residue name : [MW, vol Ang^3, eSL Ang, SLprot Ang, SLdeut Ang,
# #exchngH, #totalH]
# electron scattering lengths = Thompson radius (2.82 x 10^-13 cm) * atomic number
# molecule formulae are for residues embedded in a chain, per Jacrot
# 1976
# NOTE!!! column SLdeut is SLprot in D2O and is not used!!!!!
residue_scattering = {
'ALA': [71.1, 88.6, 10.7, 1.645, 2.686, 1, 5],
'ARG': [156.2, 173.4, 24.0, 3.466, 9.714, 6, 13],
'ASP': [115.1, 111.1, 16.7, 3.845, 4.886, 1, 4],
'ASN': [114.1, 114.1, 16.9, 3.456, 6.580, 3, 6],
'CYS': [103.1, 108.5, 15.2, 1.930, 4.013, 1, 5],
'GLU': [129.1, 138.4, 18.9, 3.762, 4.803, 1, 6],
'GLN': [128.1, 143.8, 19.2, 3.373, 6.497, 3, 8],
'GLY': [57.1, 60.1, 8.5, 1.728, 2.769, 1, 3],
'HSD': [137.2, 153.2, 20.2, 4.771, 6.521, 2, 7],
'HIS': [137.2, 153.2, 20.2, 4.771, 6.521, 2, 7],
'HSE': [137.2, 153.2, 20.2, 4.771, 6.521, 2, 7],
'HSP': [138.2, 153.2, 20.2, 4.771, 6.521, 3, 7],
'ILE': [113.2, 166.7, 17.5, 1.395, 2.437, 1, 11],
'LEU': [113.2, 166.7, 17.5, 1.395, 2.437, 1, 11],
'LYS': [128.2, 168.6, 20.1, 1.586, 5.752, 4, 13],
'MET': [131.2, 162.9, 19.8, 1.763, 2.805, 1, 9],
'PHE': [147.2, 189.9, 22.0, 4.139, 5.180, 1, 9],
'PRO': [97.1, 112.7, 14.7, 2.227, 2.227, 0, 7],
'SER': [87.1, 89.0, 13.0, 2.225, 4.308, 2, 5],
'THR': [101.1, 116.1, 15.3, 2.142, 4.224, 2, 7],
'TRP': [186.2, 227.8, 27.7, 6.035, 8.118, 2, 10],
'TYR': [163.2, 193.6, 24.3, 4.719, 6.802, 2, 9],
'VAL': [99.1, 140.0, 15.3, 1.478, 2.520, 1, 9],
'A': [71.1, 88.6, 10.7, 1.645, 2.686, 1, 5],
'R': [156.2, 173.4, 24.0, 3.466, 9.714, 6, 13],
'D': [115.1, 111.1, 16.7, 3.845, 4.886, 1, 4],
'N': [114.1, 114.1, 16.9, 3.456, 6.580, 3, 6],
'C': [103.1, 108.5, 15.2, 1.930, 4.013, 1, 5],
'E': [129.1, 138.4, 18.9, 3.762, 4.803, 1, 6],
'Q': [128.1, 143.8, 19.2, 3.373, 6.497, 3, 8],
'G': [57.1, 60.1, 8.5, 1.728, 2.769, 1, 3],
'H': [138.2, 153.2, 20.2, 4.771, 6.521, 3, 7],
'I': [113.2, 166.7, 17.5, 1.395, 2.437, 1, 11],
'L': [113.2, 166.7, 17.5, 1.395, 2.437, 1, 11],
'K': [128.2, 168.6, 20.1, 1.586, 5.752, 4, 13],
'M': [131.2, 162.9, 19.8, 1.763, 2.805, 1, 9],
'F': [147.2, 189.9, 22.0, 4.139, 5.180, 1, 9],
'P': [97.1, 112.7, 14.7, 2.227, 2.227, 0, 7],
'S': [87.1, 89.0, 13.0, 2.225, 4.308, 2, 5],
'T': [101.1, 116.1, 15.3, 2.142, 4.224, 2, 7],
'W': [186.2, 227.8, 27.7, 6.035, 8.118, 2, 10],
'Y': [163.2, 193.6, 24.3, 4.719, 6.802, 2, 9],
'V': [99.1, 140.0, 15.3, 1.478, 2.520, 1, 9]}
return residue_scattering
def create_fasta(self, **kwargs):
'''
http://en.wikipedia.org/wiki/FASTA_format
usage:
m = sasmol.SasMol(0)
m.read_pdb(pdbfile)
... do stuff ...
m.create_fasta()
print m.fasta()
m.create_fasta(format=True)
print m.fasta()
m.create_fasta(format=True,width='60')
print m.fasta()
m.create_fasta(format=True,width='60',name='aar')
print m.fasta()
print '>>> testing by_chain (t.py): '
m.create_fasta(format=True,exclude_hetatm=True,by_chain=True)
print m.fasta()
print '>>> testing by_chain with HETATM (t.py): '
m.create_fasta(format=True,by_chain=True)
print m.fasta()
print '>>> testing by_segname (t.py): '
m.create_fasta(format=True,exclude_hetatm=True,by_segname=True)
print m.fasta()
Note that this creates a simple string that is associated with the molecule (self)
and it will return without assigning a string if a non-standard three letter code
is supplied.
'''
format = False
by_chain = False
by_segname = False
single_chain = False
single_segname = False
exclude_hetatm = False
if 'format' in kwargs:
format = True
if 'name' in kwargs:
name = kwargs['name']
header = '>' + name
else:
header = '>'
if 'width' in kwargs:
width = kwargs['width']
else:
width = '80'
if 'exclude_hetatm' in kwargs:
exclude_hetatm = True
if 'by_chain' in kwargs:
by_chain = True
elif 'by_segname' in kwargs:
by_segname = True
one_resname = []
resname = self.resname()
atom = self.atom()
chain = self.chain()
segname = self.segname()
residue_dictionary = {
'ALA': 'A',
'ARG': 'R',
'ASP': 'D',
'ASN': 'N',
'CYS': 'C',
'GLU': 'E',
'GLN': 'Q',
'GLY': 'G',
'HSD': 'H',
'HIS': 'H',
'HSE': 'H',
'HSP': 'H',
'ILE': 'I',
'LEU': 'L',
'LYS': 'K',
'MET': 'M',
'PHE': 'F',
'PRO': 'P',
'SER': 'S',
'THR': 'T',
'TRP': 'W',
'TYR': 'Y',
'VAL': 'V',
'GUA': 'G',
'CYT': 'C',
'ADE': 'A',
'THY': 'T',
'URA': 'U'
}
for i in xrange(len(resname)):
this_resname = resname[i]
if this_resname in residue_dictionary:
one_resname.append(residue_dictionary[this_resname])
elif (atom[i] == 'HETATM'):
# print 'skipping non-standard resname in HETATM record:
# ',this_resname
one_resname.append("X")
else:
print 'non standard resname: ', this_resname
print 'unable to make Fasta conversion'
return
self.setOne_letter_resname(one_resname)
resid = self.resid()
last_resid = None
last_chain = None
last_segname = None
fasta = []
local_fasta = []
number_of_chains = 0
number_of_segnames = 0
chain_name = []
segname_name = []
first = True
for i in xrange(len(resid)):
this_resid = resid[i]
if by_chain:
this_chain = chain[i]
if this_chain != last_chain:
number_of_chains += 1
chain_name.append(this_chain)
if first:
first = False
else:
fasta.append(local_fasta)
last_chain = this_chain
local_fasta = []
if by_segname:
this_segname = segname[i]
if this_segname != last_segname:
number_of_segnames += 1
segname_name.append(this_segname)
if first:
first = False
else:
fasta.append(local_fasta)
last_segname = this_segname
local_fasta = []
this_resname = self.one_letter_resname()[i]
if this_resid != last_resid:
local_fasta.append(this_resname)
last_resid = this_resid
if by_chain or by_segname:
fasta.append(local_fasta)
elif not by_chain and not by_segname:
fasta = local_fasta
number_of_chains = 1
chain_name = chain[0]
final_fasta = ''
if by_segname:
number_of_chains = number_of_segnames
for i in xrange(number_of_chains):
saveme = False
if format:
from textwrap import TextWrapper
wrapper = TextWrapper(width=int(width))
if by_chain or by_segname:
if exclude_hetatm:
while "X" in fasta[i]:
fasta[i].remove("X")
joined_fasta = ''.join(fasta[i])
else:
if exclude_hetatm:
while "X" in fasta:
fasta.remove("X")
joined_fasta = ''.join(fasta)
formatted_fasta = "\n".join(wrapper.wrap(joined_fasta))
if(len(formatted_fasta.strip()) > 0):
saveme = True
if(len(header) > 1):
if by_chain:
formatted_fasta = header + ' chain:' + \
chain_name[i] + '\n' + formatted_fasta
elif by_segname:
formatted_fasta = header + ' segname:' + \
segname_name[i] + '\n' + formatted_fasta
else:
formatted_fasta = header + '\n' + formatted_fasta
else:
if by_chain:
formatted_fasta = header + 'chain:' + \
chain_name[i] + '\n' + formatted_fasta
elif by_segname:
formatted_fasta = header + 'segname:' + \
segname_name[i] + '\n' + formatted_fasta
else:
formatted_fasta = header + '\n' + formatted_fasta
if saveme:
final_fasta += formatted_fasta + '\n'
else:
final_fasta += '\n'
if format:
self.setFasta(final_fasta)
else:
self.setFasta(fasta)
return
# van der Waals radii: values for (Ti,V,Cr,Mn,Fe,Co,Y,Zr,Nb,Mo,Tc,Ru,Rh,La,Hf,Ta,W,Re,Os,Ir,Th) are taken from
# Batsanov, S.S. (2001). "Van der Waals Raddi of Elements", Inorganic Materials 37, 871-88.
# All others are from Bondi, A. (1964). "van der Waals Volumes and Radii",
# J. Phys. Chem. 68, 441-451.
def van_der_Waals_radii(self, **kwargs):
non_bonded_vdw = {'H': 1.20, 'He': 1.40,
'Li': 1.82, 'Be': 1.53, 'B': 1.92, 'C': 1.70,
'N': 1.55, 'O': 1.52, 'F': 1.47, 'Ne': 1.54,
'Na': 2.27, 'Mg': 1.73, 'Al': 1.84, 'Si': 2.1,
'P': 1.8, 'S': 1.8, 'Cl': 1.75, 'Ar': 1.88,
'K': 2.75, 'Ca': 2.31, 'Sc': 2.11, 'Ti': 2.15,
'V': 2.05, 'Cr': 2.05, 'Mn': 2.05, 'Fe': 2.05,
'Co': 2.0, 'Ni': 1.63, 'Cu': 1.4, 'Zn': 1.39,
'Ga': 1.87, 'Ge': 2.11, 'As': 1.85, 'Se': 1.9,
'Br': 1.85, 'Kr': 2.02, 'Rb': 3.03, 'Sr': 2.49,
'Y': 2.4, 'Zr': 2.3, 'Nb': 2.15, 'Mo': 2.1,
'Tc': 2.05, 'Ru': 2.05, 'Rh': 2.0, 'Pd': 1.63,
'Ag': 1.72, 'Cd': 1.58, 'In': 1.93, 'Sn': 2.17,
'Sb': 2.06, 'Te': 2.06, 'I': 1.98, 'Xe': 2.16,
'Cs': 3.43, 'Ba': 2.68, 'La': 2.5, 'Ce': None,
'Pr': None, 'Nd': None, 'Pm': None, 'Sm': None,
'Eu': None, 'Gd': None, 'Tb': None, 'Dy': None,
'Ho': None, 'Er': None, 'Tm': None, 'Yb': None,
'Lu': None, 'Hf': 2.25, 'Ta': 2.2, 'W': 2.1,
'Re': 2.05, 'Os': 2.0, 'Ir': 2.0, 'Pt': 1.75,
'Au': 1.66, 'Hg': 1.55, 'Tl': 1.96, 'Pb': 2.02,
'Bi': 2.07, 'Po': 1.97, 'At': 2.02, 'Rn': 2.20, 'Fr': 3.48,
'Ra': 2.83, 'Ac': None, 'Th': 2.4, 'Pa': None,
'U': 1.86, 'D': 1.2, '1H': 1.2}
vdw = {}
for key, item in non_bonded_vdw.items():
if 'keep_lower_case' in kwargs:
vdw[key] = item
else:
vdw[key.upper()] = item
# print 'vdw = ',vdw
return vdw
def set_average_vdw(self):
'''
using scripts/survey_vdw.py ...
C -0.0763111111111 2.00249333333
F -0.105 1.7
H -0.0368384615385 0.928619230769
O -0.13805625 1.7392625
N -0.2 1.85
P -0.585 2.15
{'C': [-3.4340000000000015, 90.11220000000004, 45], 'F': [-0.21, 3.4, 2], 'H': [-0.9578000000000003, 24.1441, 26], 'O': [-2.2088999999999994, 27.828199999999995, 16], 'N': [-5.000000000000002, 46.25000000000002, 25], 'P': [-1.17, 4.3, 2]}
NONBONDED nbxmod 5 atom cdiel shift vatom vdistance vswitch -
cutnb 14.0 ctofnb 12.0 ctonnb 10.0 eps 1.0 e14fac 1.0 wmin 1.5
!adm jr., 5/08/91, suggested cutoff scheme
!
!V(Lennard-Jones) = Eps,i,j[(Rmin,i,j/ri,j)**12 - 2(Rmin,i,j/ri,j)**6]
!
!epsilon: kcal/mole, Eps,i,j = sqrt(eps,i * eps,j)
!Rmin/2: A, Rmin,i,j = Rmin/2,i + Rmin/2,j
!
FE 0.010000 0.000000 0.650000 ! ALLOW HEM
S 0.000000 -0.450000 2.000000 ! ALLOW SUL ION
SM 0.000000 -0.380000 1.975000 ! ALLOW SUL ION
SS 0.000000 -0.470000 2.200000 ! ALLOW SUL
ZN 0.000000 -0.250000 1.090000 ! ALLOW ION
DUM 0.000000 -0.000000 0.000000 !
HE 0.000000 -0.021270 1.4800 !
NE 0.000000 -0.086000 1.5300
SOD 0.0 -0.0469 1.36375 ! sodium
POT 0.0 -0.0870 1.76375 ! potassium
CLA 0.0 -0.150 2.27 ! chloride
CAL 0.0 -0.120 1.367 ! Calcium
MG 0.0 -0.0150 1.18500 ! Magnesium
CES 0.0 -0.1900 2.100
'''
element = self.element()
van_der_waals = {'H': [-0.0368384615385, 0.928619230769],
'He': 4.0026022,
'Li': 6.9412, 'Be': 9.0121823, 'B': 10.8117,
'C': [-0.0763111111111, 2.00249333333],
'N': [-0.2, 1.85],
'O': [-0.13805625, 1.7392625],
'F': [-0.105, 1.7],
'Ne': [-0.086000, 1.5300],
'Na': [-0.0469, 1.36375],
'Mg': [-0.0150, 1.18500],
'Al': 26.9815382, 'Si': 28.08553,
'P': [-0.585, 2.15],
'S': [-0.450000, 2.000000],
'Cl': [-0.150, 2.27],
'Ar': 39.9481,
'K': [-0.0870, 1.76375],
'Ca': [-0.120, 1.367],
'Sc': 44.9559108, 'Ti': 47.8671,
'V': 50.94151, 'Cr': 51.99616, 'Mn': 54.9380499,
'Fe': [0.000000, 0.650000],
'Co': 58.9332009, 'Ni': 58.69342, 'Cu': 63.5463,
'Zn': [-0.250000, 1.09000],
'Ga': 69.7231, 'Ge': 72.641, 'As': 74.921602, 'Se': 78.963,
'Br': 79.9041, 'Kr': 83.7982, 'Rb': 85.46783, 'Sr': 87.621,
'Y': 88.905852, 'Zr': 91.2242, 'Nb': 92.906382, 'Mo': 95.942,
'Tc': 98.0, 'Ru': 101.072, 'Rh': 102.905502, 'Pd': 106.421,
'Ag': 107.86822, 'Cd': 112.4118, 'In': 114.8183, 'Sn': 118.7107,
'Sb': 121.7601, 'Te': 127.603, 'I': 126.904473, 'Xe': 131.2936,
'Cs': [-0.1900, 2.100],
'Ba': 137.3277, 'La': 138.90552, 'Ce': 140.1161,
'Pr': 140.907652, 'Nd': 144.243, 'Pm': 145.0, 'Sm': 150.363,
'Eu': 151.9641, 'Gd': 157.253, 'Tb': 158.925342, 'Dy': 162.5001,
'Ho': 164.930322, 'Er': 167.2593, 'Tm': 168.93421, 'Yb': 173.043,
'Lu': 174.9671, 'Hf': 174.9671, 'Ta': 180.94791, 'W': 183.841,
'Re': 186.2071, 'Os': 190.233, 'Ir': 192.2173, 'Pt': 195.0782,
'Au': 196.966552, 'Hg': 200.592, 'Tl': 204.38332, 'Pb': 207.21,
'Bi': 208.980382, 'Po': 209.0, 'At': 210.0, 'Rn': 222.0, 'Fr': 223.0,
'Ra': 226.0, 'Ac': 227.0, 'Th': 232.03811, 'Pa': 231.035882, 'U': 238.028913,
'D': [-0.0368384615385, 0.928619230769],
'1H': [-0.0368384615385, 0.928619230769]}
element_vdw = []
for this_element in element:
for key, item in van_der_waals.items():
if this_element == key:
try:
if len(item) > 1:
element_vdw.append(item)
except:
element_vdw.append([None, None])
self.setAtom_vdw(element_vdw)
return
|
gpl-3.0
|
[
2344,
272,
428,
16435,
37,
26,
1898,
334,
35,
9,
7760,
1603,
3362,
838,
662,
14,
7319,
16753,
12,
11308,
14,
36,
14,
18407,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
199,
199,
3,
198,
15319,
18858,
29807,
199,
3,
199,
3,
198,
713,
15,
709,
15,
8664,
198,
306,
198,
2747,
2803,
9622,
198,
26,
198,
22760,
199,
3,
198,
845,
15,
1194,
15,
8128,
198,
306,
221,
198,
3539,
370,
542,
529,
323,
570,
1057,
198,
26,
198,
22760,
199,
3,
198,
413,
260,
499,
260,
650,
260,
841,
260,
959,
260,
1227,
260,
1520,
199,
3,
26703,
20,
6690,
25588,
25588,
25588,
11371,
199,
3,
24564,
755,
627,
420,
1011,
199,
2344,
199,
198,
51,
305,
8516,
3509,
314,
3992,
626,
1395,
9948,
198,
10910,
436,
1303,
10251,
2238,
4382,
199,
199,
2344,
199,
3,
24164,
198,
17809,
282,
12137,
4340,
370,
8265,
298,
7713,
15,
1271,
77,
2,
370,
5126,
11866,
1863,
421,
199,
533,
18840,
530,
8,
785,
304,
339,
1449,
272,
961,
1021,
3509,
15374,
2556,
1202,
3002,
1163,
4621,
14,
339,
1455,
921,
24724,
14,
78,
631,
14,
16294,
15,
13814,
13,
1393,
15,
16273,
6150,
15,
7935,
63,
10636,
14,
1168,
31,
8081,
19167,
4371,
29,
1360,
6,
374,
7818,
29,
3972,
339,
4465,
15374,
5401,
365,
4079,
641,
314,
19981,
284,
2379,
530,
31586,
339,
1449,
272,
1373,
63,
475,
63,
10480,
63,
9269,
63,
496,
15859,
63,
19581,
310,
63,
9086,
275,
469,
199,
198,
7,
33,
7,
520,
283,
26674,
297,
199,
198,
7,
50,
7,
520,
283,
11611,
297,
199,
198,
7,
36,
7,
520,
283,
1179,
48,
297,
199,
198,
7,
46,
7,
520,
283,
21696,
297,
199,
198,
7,
35,
7,
520,
283,
15068,
51,
297,
199,
198,
7,
37,
7,
520,
283,
20935,
297,
199,
198,
7,
49,
7,
520,
283,
2226,
46,
297,
199,
198,
7,
39,
7,
520,
283,
2226,
57,
297,
199,
198,
7,
40,
7,
520,
283,
40,
899,
297,
199,
198,
7,
41,
7,
520,
283,
8453,
297,
199,
198,
7,
44,
7,
520,
283,
23391,
297,
199,
198,
7,
43,
7,
520,
283,
6084,
51,
297,
199,
198,
7,
45,
7,
520,
283,
3940,
297,
199,
198,
7,
38,
7,
520,
283,
48,
1645,
297,
199,
198,
7,
48,
7,
520,
283,
2514,
297,
199,
198,
7,
51,
7,
520,
283,
3279,
297,
199,
198,
7,
52,
7,
520,
283,
2080,
50,
297,
199,
198,
7,
55,
7,
520,
283,
1766,
48,
297,
199,
198,
7,
57,
7,
520,
283,
2099,
50,
297,
199,
198,
7,
54,
7,
520,
283,
3204,
7,
523,
198,
93,
20950,
1373,
63,
475,
63,
10480,
63,
9269,
63,
30984,
274,
530,
63,
19581,
310,
63,
9086,
275,
469,
199,
198,
7,
39,
7,
520,
283,
17188,
33,
297,
199,
198,
7,
35,
7,
520,
283,
15068,
52,
297,
199,
198,
7,
33,
7,
520,
283,
33,
1093,
297,
199,
198,
7,
52,
7,
520,
283,
2080,
57,
297,
199,
198,
7,
53,
7,
520,
283,
1230,
33,
7,
272,
789,
2742,
339,
347,
282,
6553,
8,
277,
12,
1011,
958,
304,
398,
13492,
63,
6807,
63,
10910,
63,
3463,
275,
791,
40,
356,
413,
14,
31108,
2417,
12,
283,
1966,
356,
841,
14,
28193,
16348,
12,
3147,
283,
13009,
356,
1227,
14,
2635,
713,
12,
283,
3655,
356,
1749,
14,
614,
9252,
1789,
12,
283,
34,
356,
1616,
14,
24,
7362,
12,
283,
35,
356,
3144,
14,
614,
19226,
12,
3147,
283,
46,
356,
4329,
14,
383,
20298,
12,
283,
47,
356,
4114,
14,
1020,
28163,
12,
283,
38,
356,
6155,
14,
1020,
13462,
13288,
12,
283,
4698,
356,
3388,
14,
10699,
2114,
12,
3147,
283,
8565,
356,
6928,
14,
30924,
1138,
996,
12,
283,
45,
71,
356,
5504,
14,
1216,
13725,
12,
283,
2439,
356,
7875,
14,
2905,
1046,
16244,
12,
283,
18934,
356,
7294,
14,
2036,
24412,
12,
3147,
283,
48,
356,
4233,
14,
2576,
11452,
713,
12,
283,
51,
356,
4337,
14,
1690,
1229,
12,
283,
1968,
356,
8685,
14,
2322,
708,
12,
283,
1596,
356,
10551,
14,
25,
24923,
12,
3147,
283,
43,
356,
10551,
14,
17764,
2192,
12,
283,
3630,
356,
6335,
14,
1780,
1349,
12,
283,
7181,
356,
10868,
14,
25,
17257,
8079,
12,
283,
22731,
356,
10954,
14,
1184,
3172,
12,
3147,
283,
54,
356,
5238,
14,
2635,
12768,
12,
283,
17345,
356,
8026,
14,
14140,
975,
12,
283,
45,
78,
356,
13470,
14,
25,
1703,
966,
1020,
12,
283,
3456,
356,
12766,
14,
1349,
2528,
12,
3147,
283,
967,
356,
13713,
14,
3129,
708,
8581,
12,
283,
20959,
356,
13713,
14,
1876,
14519,
12,
283,
35,
85,
356,
13668,
14,
1477,
2766,
12,
283,
26713,
356,
11738,
14,
12443,
20,
12,
3147,
283,
17295,
356,
14610,
14,
23,
11921,
12,
283,
4240,
356,
15323,
14,
15233,
12,
283,
2822,
356,
9720,
14,
2942,
975,
996,
12,
283,
1513,
356,
14679,
14,
24548,
12,
3147,
283,
12771,
356,
13734,
14,
25,
10531,
12,
283,
27399,
356,
20582,
14,
1965,
2564,
12,
283,
50,
66,
356,
16412,
14,
16226,
2658,
12,
283,
51,
82,
356,
10513,
14,
22,
2025,
12,
3147,
283,
57,
356,
10523,
14,
29888,
22719,
12,
283,
58,
82,
356,
21358,
14,
1081,
2260,
12,
283,
26183,
356,
20140,
14,
31640,
16244,
12,
283,
3716,
356,
16102,
14,
25,
2260,
12,
3147,
283,
52,
67,
356,
16096,
14,
16
] |
[
272,
428,
16435,
37,
26,
1898,
334,
35,
9,
7760,
1603,
3362,
838,
662,
14,
7319,
16753,
12,
11308,
14,
36,
14,
18407,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
199,
199,
3,
198,
15319,
18858,
29807,
199,
3,
199,
3,
198,
713,
15,
709,
15,
8664,
198,
306,
198,
2747,
2803,
9622,
198,
26,
198,
22760,
199,
3,
198,
845,
15,
1194,
15,
8128,
198,
306,
221,
198,
3539,
370,
542,
529,
323,
570,
1057,
198,
26,
198,
22760,
199,
3,
198,
413,
260,
499,
260,
650,
260,
841,
260,
959,
260,
1227,
260,
1520,
199,
3,
26703,
20,
6690,
25588,
25588,
25588,
11371,
199,
3,
24564,
755,
627,
420,
1011,
199,
2344,
199,
198,
51,
305,
8516,
3509,
314,
3992,
626,
1395,
9948,
198,
10910,
436,
1303,
10251,
2238,
4382,
199,
199,
2344,
199,
3,
24164,
198,
17809,
282,
12137,
4340,
370,
8265,
298,
7713,
15,
1271,
77,
2,
370,
5126,
11866,
1863,
421,
199,
533,
18840,
530,
8,
785,
304,
339,
1449,
272,
961,
1021,
3509,
15374,
2556,
1202,
3002,
1163,
4621,
14,
339,
1455,
921,
24724,
14,
78,
631,
14,
16294,
15,
13814,
13,
1393,
15,
16273,
6150,
15,
7935,
63,
10636,
14,
1168,
31,
8081,
19167,
4371,
29,
1360,
6,
374,
7818,
29,
3972,
339,
4465,
15374,
5401,
365,
4079,
641,
314,
19981,
284,
2379,
530,
31586,
339,
1449,
272,
1373,
63,
475,
63,
10480,
63,
9269,
63,
496,
15859,
63,
19581,
310,
63,
9086,
275,
469,
199,
198,
7,
33,
7,
520,
283,
26674,
297,
199,
198,
7,
50,
7,
520,
283,
11611,
297,
199,
198,
7,
36,
7,
520,
283,
1179,
48,
297,
199,
198,
7,
46,
7,
520,
283,
21696,
297,
199,
198,
7,
35,
7,
520,
283,
15068,
51,
297,
199,
198,
7,
37,
7,
520,
283,
20935,
297,
199,
198,
7,
49,
7,
520,
283,
2226,
46,
297,
199,
198,
7,
39,
7,
520,
283,
2226,
57,
297,
199,
198,
7,
40,
7,
520,
283,
40,
899,
297,
199,
198,
7,
41,
7,
520,
283,
8453,
297,
199,
198,
7,
44,
7,
520,
283,
23391,
297,
199,
198,
7,
43,
7,
520,
283,
6084,
51,
297,
199,
198,
7,
45,
7,
520,
283,
3940,
297,
199,
198,
7,
38,
7,
520,
283,
48,
1645,
297,
199,
198,
7,
48,
7,
520,
283,
2514,
297,
199,
198,
7,
51,
7,
520,
283,
3279,
297,
199,
198,
7,
52,
7,
520,
283,
2080,
50,
297,
199,
198,
7,
55,
7,
520,
283,
1766,
48,
297,
199,
198,
7,
57,
7,
520,
283,
2099,
50,
297,
199,
198,
7,
54,
7,
520,
283,
3204,
7,
523,
198,
93,
20950,
1373,
63,
475,
63,
10480,
63,
9269,
63,
30984,
274,
530,
63,
19581,
310,
63,
9086,
275,
469,
199,
198,
7,
39,
7,
520,
283,
17188,
33,
297,
199,
198,
7,
35,
7,
520,
283,
15068,
52,
297,
199,
198,
7,
33,
7,
520,
283,
33,
1093,
297,
199,
198,
7,
52,
7,
520,
283,
2080,
57,
297,
199,
198,
7,
53,
7,
520,
283,
1230,
33,
7,
272,
789,
2742,
339,
347,
282,
6553,
8,
277,
12,
1011,
958,
304,
398,
13492,
63,
6807,
63,
10910,
63,
3463,
275,
791,
40,
356,
413,
14,
31108,
2417,
12,
283,
1966,
356,
841,
14,
28193,
16348,
12,
3147,
283,
13009,
356,
1227,
14,
2635,
713,
12,
283,
3655,
356,
1749,
14,
614,
9252,
1789,
12,
283,
34,
356,
1616,
14,
24,
7362,
12,
283,
35,
356,
3144,
14,
614,
19226,
12,
3147,
283,
46,
356,
4329,
14,
383,
20298,
12,
283,
47,
356,
4114,
14,
1020,
28163,
12,
283,
38,
356,
6155,
14,
1020,
13462,
13288,
12,
283,
4698,
356,
3388,
14,
10699,
2114,
12,
3147,
283,
8565,
356,
6928,
14,
30924,
1138,
996,
12,
283,
45,
71,
356,
5504,
14,
1216,
13725,
12,
283,
2439,
356,
7875,
14,
2905,
1046,
16244,
12,
283,
18934,
356,
7294,
14,
2036,
24412,
12,
3147,
283,
48,
356,
4233,
14,
2576,
11452,
713,
12,
283,
51,
356,
4337,
14,
1690,
1229,
12,
283,
1968,
356,
8685,
14,
2322,
708,
12,
283,
1596,
356,
10551,
14,
25,
24923,
12,
3147,
283,
43,
356,
10551,
14,
17764,
2192,
12,
283,
3630,
356,
6335,
14,
1780,
1349,
12,
283,
7181,
356,
10868,
14,
25,
17257,
8079,
12,
283,
22731,
356,
10954,
14,
1184,
3172,
12,
3147,
283,
54,
356,
5238,
14,
2635,
12768,
12,
283,
17345,
356,
8026,
14,
14140,
975,
12,
283,
45,
78,
356,
13470,
14,
25,
1703,
966,
1020,
12,
283,
3456,
356,
12766,
14,
1349,
2528,
12,
3147,
283,
967,
356,
13713,
14,
3129,
708,
8581,
12,
283,
20959,
356,
13713,
14,
1876,
14519,
12,
283,
35,
85,
356,
13668,
14,
1477,
2766,
12,
283,
26713,
356,
11738,
14,
12443,
20,
12,
3147,
283,
17295,
356,
14610,
14,
23,
11921,
12,
283,
4240,
356,
15323,
14,
15233,
12,
283,
2822,
356,
9720,
14,
2942,
975,
996,
12,
283,
1513,
356,
14679,
14,
24548,
12,
3147,
283,
12771,
356,
13734,
14,
25,
10531,
12,
283,
27399,
356,
20582,
14,
1965,
2564,
12,
283,
50,
66,
356,
16412,
14,
16226,
2658,
12,
283,
51,
82,
356,
10513,
14,
22,
2025,
12,
3147,
283,
57,
356,
10523,
14,
29888,
22719,
12,
283,
58,
82,
356,
21358,
14,
1081,
2260,
12,
283,
26183,
356,
20140,
14,
31640,
16244,
12,
283,
3716,
356,
16102,
14,
25,
2260,
12,
3147,
283,
52,
67,
356,
16096,
14,
16,
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,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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
] |
chrisdunelm/grpc
|
src/python/grpcio/grpc/framework/foundation/callable_util.py
|
26
|
3151
|
# Copyright 2015 gRPC authors.
#
# 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.
"""Utilities for working with callables."""
import abc
import collections
import enum
import functools
import logging
import six
_LOGGER = logging.getLogger(__name__)
class Outcome(six.with_metaclass(abc.ABCMeta)):
"""A sum type describing the outcome of some call.
Attributes:
kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the
call returned a value or raised an exception.
return_value: The value returned by the call. Must be present if kind is
Kind.RETURNED.
exception: The exception raised by the call. Must be present if kind is
Kind.RAISED.
"""
@enum.unique
class Kind(enum.Enum):
"""Identifies the general kind of the outcome of some call."""
RETURNED = object()
RAISED = object()
class _EasyOutcome(
collections.namedtuple('_EasyOutcome',
['kind', 'return_value', 'exception']), Outcome):
"""A trivial implementation of Outcome."""
def _call_logging_exceptions(behavior, message, *args, **kwargs):
try:
return _EasyOutcome(Outcome.Kind.RETURNED, behavior(*args, **kwargs),
None)
except Exception as e: # pylint: disable=broad-except
_LOGGER.exception(message)
return _EasyOutcome(Outcome.Kind.RAISED, None, e)
def with_exceptions_logged(behavior, message):
"""Wraps a callable in a try-except that logs any exceptions it raises.
Args:
behavior: Any callable.
message: A string to log if the behavior raises an exception.
Returns:
A callable that when executed invokes the given behavior. The returned
callable takes the same arguments as the given behavior but returns a
future.Outcome describing whether the given behavior returned a value or
raised an exception.
"""
@functools.wraps(behavior)
def wrapped_behavior(*args, **kwargs):
return _call_logging_exceptions(behavior, message, *args, **kwargs)
return wrapped_behavior
def call_logging_exceptions(behavior, message, *args, **kwargs):
"""Calls a behavior in a try-except that logs any exceptions it raises.
Args:
behavior: Any callable.
message: A string to log if the behavior raises an exception.
*args: Positional arguments to pass to the given behavior.
**kwargs: Keyword arguments to pass to the given behavior.
Returns:
An Outcome describing whether the given behavior returned a value or raised
an exception.
"""
return _call_logging_exceptions(behavior, message, *args, **kwargs)
|
apache-2.0
|
[
3,
1898,
6900,
30700,
11462,
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,
624,
22905,
367,
6449,
543,
28041,
1041,
199,
199,
646,
13022,
199,
646,
5055,
199,
646,
4952,
199,
646,
9143,
199,
646,
2050,
199,
199,
646,
3816,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
6219,
4352,
8,
4174,
14,
1045,
63,
6577,
8,
3175,
14,
22254,
2298,
272,
408,
33,
3089,
730,
13660,
314,
15955,
402,
2005,
1240,
14,
819,
9382,
26,
272,
4928,
26,
7309,
402,
1804,
688,
14,
9677,
1149,
503,
1804,
688,
14,
2847,
9359,
17342,
9297,
626,
314,
489,
1240,
2138,
282,
574,
503,
4915,
376,
1919,
14,
272,
372,
63,
585,
26,
710,
574,
2138,
701,
314,
1240,
14,
9498,
506,
3451,
340,
4928,
365,
489,
1804,
688,
14,
9677,
1149,
14,
272,
1919,
26,
710,
1919,
4915,
701,
314,
1240,
14,
9498,
506,
3451,
340,
4928,
365,
489,
1804,
688,
14,
2847,
9359,
14,
523,
408,
339,
768,
4869,
14,
3235,
272,
1021,
1804,
688,
8,
4869,
14,
5081,
304,
267,
408,
41,
2433,
397,
314,
8605,
4928,
402,
314,
15955,
402,
2005,
1240,
1041,
398,
24646,
1149,
275,
909,
342,
267,
31632,
9359,
275,
909,
342,
421,
199,
533,
485,
28326,
2204,
4352,
8,
267,
5055,
14,
18921,
6412,
28326,
2204,
4352,
297,
3044,
788,
5091,
297,
283,
1107,
63,
585,
297,
283,
1971,
3815,
6219,
4352,
304,
272,
408,
33,
28586,
4514,
402,
6219,
4352,
1041,
421,
199,
318,
485,
1250,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
304,
272,
862,
26,
267,
372,
485,
28326,
2204,
4352,
8,
2204,
4352,
14,
13028,
14,
9677,
1149,
12,
5953,
2031,
589,
12,
1011,
958,
395,
1169,
488,
9,
272,
871,
2186,
465,
325,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
267,
485,
10186,
14,
1971,
8,
1188,
9,
267,
372,
485,
28326,
2204,
4352,
8,
2204,
4352,
14,
13028,
14,
2847,
9359,
12,
488,
12,
325,
9,
421,
199,
318,
543,
63,
3924,
63,
12419,
8,
17537,
12,
1245,
304,
272,
408,
55,
8146,
282,
4550,
315,
282,
862,
13,
2590,
626,
9610,
1263,
4967,
652,
6534,
14,
819,
3033,
26,
272,
5953,
26,
6184,
4550,
14,
272,
1245,
26,
437,
1059,
370,
943,
340,
314,
5953,
6534,
376,
1919,
14,
819,
1803,
26,
272,
437,
4550,
626,
1380,
7934,
29761,
314,
1627,
5953,
14,
710,
2138,
489,
4550,
6181,
314,
2011,
2368,
465,
314,
1627,
5953,
1325,
2529,
282,
489,
6466,
14,
2204,
4352,
13660,
3775,
314,
1627,
5953,
2138,
282,
574,
503,
489,
4915,
376,
1919,
14,
523,
408,
339,
768,
17869,
14,
13582,
8,
17537,
9,
272,
347,
8072,
63,
17537,
2031,
589,
12,
1011,
958,
304,
267,
372,
485,
1250,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
9,
339,
372,
8072,
63,
17537,
421,
199,
318,
1240,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
18287,
282,
5953,
315,
282,
862,
13,
2590,
626,
9610,
1263,
4967,
652,
6534,
14,
819,
3033,
26,
272,
5953,
26,
6184,
4550,
14,
272,
1245,
26,
437,
1059,
370,
943,
340,
314,
5953,
6534,
376,
1919,
14,
272,
627,
589,
26,
15483,
279,
2368,
370,
986,
370,
314,
1627,
5953,
14,
272,
1011,
958,
26,
6431,
2368,
370,
986,
370,
314,
1627,
5953,
14,
819,
1803,
26,
272,
1626,
6219,
4352,
13660,
3775,
314,
1627,
5953,
2138,
282,
574,
503,
4915,
489,
376,
1919,
14,
523,
408,
272,
372,
485,
1250,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
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
] |
[
1898,
6900,
30700,
11462,
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,
624,
22905,
367,
6449,
543,
28041,
1041,
199,
199,
646,
13022,
199,
646,
5055,
199,
646,
4952,
199,
646,
9143,
199,
646,
2050,
199,
199,
646,
3816,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
6219,
4352,
8,
4174,
14,
1045,
63,
6577,
8,
3175,
14,
22254,
2298,
272,
408,
33,
3089,
730,
13660,
314,
15955,
402,
2005,
1240,
14,
819,
9382,
26,
272,
4928,
26,
7309,
402,
1804,
688,
14,
9677,
1149,
503,
1804,
688,
14,
2847,
9359,
17342,
9297,
626,
314,
489,
1240,
2138,
282,
574,
503,
4915,
376,
1919,
14,
272,
372,
63,
585,
26,
710,
574,
2138,
701,
314,
1240,
14,
9498,
506,
3451,
340,
4928,
365,
489,
1804,
688,
14,
9677,
1149,
14,
272,
1919,
26,
710,
1919,
4915,
701,
314,
1240,
14,
9498,
506,
3451,
340,
4928,
365,
489,
1804,
688,
14,
2847,
9359,
14,
523,
408,
339,
768,
4869,
14,
3235,
272,
1021,
1804,
688,
8,
4869,
14,
5081,
304,
267,
408,
41,
2433,
397,
314,
8605,
4928,
402,
314,
15955,
402,
2005,
1240,
1041,
398,
24646,
1149,
275,
909,
342,
267,
31632,
9359,
275,
909,
342,
421,
199,
533,
485,
28326,
2204,
4352,
8,
267,
5055,
14,
18921,
6412,
28326,
2204,
4352,
297,
3044,
788,
5091,
297,
283,
1107,
63,
585,
297,
283,
1971,
3815,
6219,
4352,
304,
272,
408,
33,
28586,
4514,
402,
6219,
4352,
1041,
421,
199,
318,
485,
1250,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
304,
272,
862,
26,
267,
372,
485,
28326,
2204,
4352,
8,
2204,
4352,
14,
13028,
14,
9677,
1149,
12,
5953,
2031,
589,
12,
1011,
958,
395,
1169,
488,
9,
272,
871,
2186,
465,
325,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
267,
485,
10186,
14,
1971,
8,
1188,
9,
267,
372,
485,
28326,
2204,
4352,
8,
2204,
4352,
14,
13028,
14,
2847,
9359,
12,
488,
12,
325,
9,
421,
199,
318,
543,
63,
3924,
63,
12419,
8,
17537,
12,
1245,
304,
272,
408,
55,
8146,
282,
4550,
315,
282,
862,
13,
2590,
626,
9610,
1263,
4967,
652,
6534,
14,
819,
3033,
26,
272,
5953,
26,
6184,
4550,
14,
272,
1245,
26,
437,
1059,
370,
943,
340,
314,
5953,
6534,
376,
1919,
14,
819,
1803,
26,
272,
437,
4550,
626,
1380,
7934,
29761,
314,
1627,
5953,
14,
710,
2138,
489,
4550,
6181,
314,
2011,
2368,
465,
314,
1627,
5953,
1325,
2529,
282,
489,
6466,
14,
2204,
4352,
13660,
3775,
314,
1627,
5953,
2138,
282,
574,
503,
489,
4915,
376,
1919,
14,
523,
408,
339,
768,
17869,
14,
13582,
8,
17537,
9,
272,
347,
8072,
63,
17537,
2031,
589,
12,
1011,
958,
304,
267,
372,
485,
1250,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
9,
339,
372,
8072,
63,
17537,
421,
199,
318,
1240,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
18287,
282,
5953,
315,
282,
862,
13,
2590,
626,
9610,
1263,
4967,
652,
6534,
14,
819,
3033,
26,
272,
5953,
26,
6184,
4550,
14,
272,
1245,
26,
437,
1059,
370,
943,
340,
314,
5953,
6534,
376,
1919,
14,
272,
627,
589,
26,
15483,
279,
2368,
370,
986,
370,
314,
1627,
5953,
14,
272,
1011,
958,
26,
6431,
2368,
370,
986,
370,
314,
1627,
5953,
14,
819,
1803,
26,
272,
1626,
6219,
4352,
13660,
3775,
314,
1627,
5953,
2138,
282,
574,
503,
4915,
489,
376,
1919,
14,
523,
408,
272,
372,
485,
1250,
63,
4806,
63,
3924,
8,
17537,
12,
1245,
12,
627,
589,
12,
1011,
958,
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,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
page-io/Cactus
|
cactus/config/file.py
|
9
|
1173
|
#coding:utf-8
import json
import logging
logger = logging.getLogger(__name__)
class ConfigFile(object):
"""
A single config file, as present on the filesystem.
"""
_dirty = None
def __init__(self, path):
self.path = path
self.load()
def get(self, key, default=None):
return self._data.get(key, default)
def set(self, key, value):
self._data[key] = value
self._dirty = True
def has_key(self, key):
return key in self._data
def load(self):
try:
self._data = json.load(open(self.path, 'rU'))
self._dirty = False
except IOError:
logger.warning('No configuration file found at {0}'.format(self.path))
self._data = {}
except Exception: #TODO: Specify
logger.error('Unable to load configuration at {0}'.format(self.path))
self._data = {}
def write(self):
if self._dirty:
json.dump(self._data, open(self.path, 'w'), sort_keys=True, indent=4, separators=(',', ': '))
self._dirty = False
logger.debug('Saved configuration at {0}'.format(self.path))
|
bsd-3-clause
|
[
3,
1523,
26,
1624,
13,
24,
199,
646,
2022,
199,
646,
2050,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
4094,
1173,
8,
785,
304,
272,
408,
272,
437,
2849,
1101,
570,
12,
465,
3451,
641,
314,
10036,
14,
272,
408,
272,
485,
8799,
275,
488,
339,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
515,
275,
931,
267,
291,
14,
912,
342,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
372,
291,
423,
576,
14,
362,
8,
498,
12,
849,
9,
339,
347,
663,
8,
277,
12,
790,
12,
574,
304,
267,
291,
423,
576,
59,
498,
61,
275,
574,
267,
291,
423,
8799,
275,
715,
339,
347,
965,
63,
498,
8,
277,
12,
790,
304,
267,
372,
790,
315,
291,
423,
576,
339,
347,
2248,
8,
277,
304,
267,
862,
26,
288,
291,
423,
576,
275,
2022,
14,
912,
8,
1490,
8,
277,
14,
515,
12,
283,
28978,
1333,
288,
291,
423,
8799,
275,
756,
267,
871,
5925,
26,
288,
2512,
14,
3764,
360,
1944,
2897,
570,
1911,
737,
469,
16,
5285,
908,
8,
277,
14,
515,
430,
288,
291,
423,
576,
275,
1052,
267,
871,
2186,
26,
327,
11768,
26,
13327,
288,
2512,
14,
705,
360,
6005,
370,
2248,
2897,
737,
469,
16,
5285,
908,
8,
277,
14,
515,
430,
288,
291,
423,
576,
275,
1052,
339,
347,
2218,
8,
277,
304,
267,
340,
291,
423,
8799,
26,
288,
2022,
14,
2724,
8,
277,
423,
576,
12,
1551,
8,
277,
14,
515,
12,
283,
87,
659,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
12,
17658,
2687,
23324,
7596,
20005,
288,
291,
423,
8799,
275,
756,
267,
2512,
14,
1757,
360,
21969,
2897,
737,
469,
16,
5285,
908,
8,
277,
14,
515,
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
] |
[
1523,
26,
1624,
13,
24,
199,
646,
2022,
199,
646,
2050,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
4094,
1173,
8,
785,
304,
272,
408,
272,
437,
2849,
1101,
570,
12,
465,
3451,
641,
314,
10036,
14,
272,
408,
272,
485,
8799,
275,
488,
339,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
515,
275,
931,
267,
291,
14,
912,
342,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
372,
291,
423,
576,
14,
362,
8,
498,
12,
849,
9,
339,
347,
663,
8,
277,
12,
790,
12,
574,
304,
267,
291,
423,
576,
59,
498,
61,
275,
574,
267,
291,
423,
8799,
275,
715,
339,
347,
965,
63,
498,
8,
277,
12,
790,
304,
267,
372,
790,
315,
291,
423,
576,
339,
347,
2248,
8,
277,
304,
267,
862,
26,
288,
291,
423,
576,
275,
2022,
14,
912,
8,
1490,
8,
277,
14,
515,
12,
283,
28978,
1333,
288,
291,
423,
8799,
275,
756,
267,
871,
5925,
26,
288,
2512,
14,
3764,
360,
1944,
2897,
570,
1911,
737,
469,
16,
5285,
908,
8,
277,
14,
515,
430,
288,
291,
423,
576,
275,
1052,
267,
871,
2186,
26,
327,
11768,
26,
13327,
288,
2512,
14,
705,
360,
6005,
370,
2248,
2897,
737,
469,
16,
5285,
908,
8,
277,
14,
515,
430,
288,
291,
423,
576,
275,
1052,
339,
347,
2218,
8,
277,
304,
267,
340,
291,
423,
8799,
26,
288,
2022,
14,
2724,
8,
277,
423,
576,
12,
1551,
8,
277,
14,
515,
12,
283,
87,
659,
4069,
63,
1612,
29,
549,
12,
4363,
29,
20,
12,
17658,
2687,
23324,
7596,
20005,
288,
291,
423,
8799,
275,
756,
267,
2512,
14,
1757,
360,
21969,
2897,
737,
469,
16,
5285,
908,
8,
277,
14,
515,
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,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
shuggiefisher/crowdstock
|
django/contrib/gis/tests/test_measure.py
|
231
|
8820
|
"""
Distance and Area objects to allow for sensible and convienient calculation
and conversions. Here are some tests.
"""
from django.contrib.gis.measure import Distance, Area, D, A
from django.utils import unittest
class DistanceTest(unittest.TestCase):
"Testing the Distance object"
def testInit(self):
"Testing initialisation from valid units"
d = Distance(m=100)
self.assertEqual(d.m, 100)
d1, d2, d3 = D(m=100), D(meter=100), D(metre=100)
for d in (d1, d2, d3):
self.assertEqual(d.m, 100)
d = D(nm=100)
self.assertEqual(d.m, 185200)
y1, y2, y3 = D(yd=100), D(yard=100), D(Yard=100)
for d in (y1, y2, y3):
self.assertEqual(d.yd, 100)
mm1, mm2 = D(millimeter=1000), D(MiLLiMeTeR=1000)
for d in (mm1, mm2):
self.assertEqual(d.m, 1.0)
self.assertEqual(d.mm, 1000.0)
def testInitInvalid(self):
"Testing initialisation from invalid units"
self.assertRaises(AttributeError, D, banana=100)
def testAccess(self):
"Testing access in different units"
d = D(m=100)
self.assertEqual(d.km, 0.1)
self.assertAlmostEqual(d.ft, 328.084, 3)
def testAccessInvalid(self):
"Testing access in invalid units"
d = D(m=100)
self.failIf(hasattr(d, 'banana'))
def testAddition(self):
"Test addition & subtraction"
d1 = D(m=100)
d2 = D(m=200)
d3 = d1 + d2
self.assertEqual(d3.m, 300)
d3 += d1
self.assertEqual(d3.m, 400)
d4 = d1 - d2
self.assertEqual(d4.m, -100)
d4 -= d1
self.assertEqual(d4.m, -200)
try:
d5 = d1 + 1
except TypeError, e:
pass
else:
self.fail('Distance + number should raise TypeError')
try:
d5 = d1 - 1
except TypeError, e:
pass
else:
self.fail('Distance - number should raise TypeError')
try:
d1 += 1
except TypeError, e:
pass
else:
self.fail('Distance += number should raise TypeError')
try:
d1 -= 1
except TypeError, e:
pass
else:
self.fail('Distance -= number should raise TypeError')
def testMultiplication(self):
"Test multiplication & division"
d1 = D(m=100)
d3 = d1 * 2
self.assertEqual(d3.m, 200)
d3 = 2 * d1
self.assertEqual(d3.m, 200)
d3 *= 5
self.assertEqual(d3.m, 1000)
d4 = d1 / 2
self.assertEqual(d4.m, 50)
d4 /= 5
self.assertEqual(d4.m, 10)
a5 = d1 * D(m=10)
self.assertTrue(isinstance(a5, Area))
self.assertEqual(a5.sq_m, 100*10)
try:
d1 *= D(m=1)
except TypeError, e:
pass
else:
self.fail('Distance *= Distance should raise TypeError')
try:
d5 = d1 / D(m=1)
except TypeError, e:
pass
else:
self.fail('Distance / Distance should raise TypeError')
try:
d1 /= D(m=1)
except TypeError, e:
pass
else:
self.fail('Distance /= Distance should raise TypeError')
def testUnitConversions(self):
"Testing default units during maths"
d1 = D(m=100)
d2 = D(km=1)
d3 = d1 + d2
self.assertEqual(d3._default_unit, 'm')
d4 = d2 + d1
self.assertEqual(d4._default_unit, 'km')
d5 = d1 * 2
self.assertEqual(d5._default_unit, 'm')
d6 = d1 / 2
self.assertEqual(d6._default_unit, 'm')
def testComparisons(self):
"Testing comparisons"
d1 = D(m=100)
d2 = D(km=1)
d3 = D(km=0)
self.assertTrue(d2 > d1)
self.assertTrue(d1 == d1)
self.assertTrue(d1 < d2)
self.failIf(d3)
def testUnitsStr(self):
"Testing conversion to strings"
d1 = D(m=100)
d2 = D(km=3.5)
self.assertEqual(str(d1), '100.0 m')
self.assertEqual(str(d2), '3.5 km')
self.assertEqual(repr(d1), 'Distance(m=100.0)')
self.assertEqual(repr(d2), 'Distance(km=3.5)')
def testUnitAttName(self):
"Testing the `unit_attname` class method"
unit_tuple = [('Yard', 'yd'), ('Nautical Mile', 'nm'), ('German legal metre', 'german_m'),
('Indian yard', 'indian_yd'), ('Chain (Sears)', 'chain_sears'), ('Chain', 'chain')]
for nm, att in unit_tuple:
self.assertEqual(att, D.unit_attname(nm))
class AreaTest(unittest.TestCase):
"Testing the Area object"
def testInit(self):
"Testing initialisation from valid units"
a = Area(sq_m=100)
self.assertEqual(a.sq_m, 100)
a = A(sq_m=100)
self.assertEqual(a.sq_m, 100)
a = A(sq_mi=100)
self.assertEqual(a.sq_m, 258998811.0336)
def testInitInvaliA(self):
"Testing initialisation from invalid units"
self.assertRaises(AttributeError, A, banana=100)
def testAccess(self):
"Testing access in different units"
a = A(sq_m=100)
self.assertEqual(a.sq_km, 0.0001)
self.assertAlmostEqual(a.sq_ft, 1076.391, 3)
def testAccessInvaliA(self):
"Testing access in invalid units"
a = A(sq_m=100)
self.failIf(hasattr(a, 'banana'))
def testAddition(self):
"Test addition & subtraction"
a1 = A(sq_m=100)
a2 = A(sq_m=200)
a3 = a1 + a2
self.assertEqual(a3.sq_m, 300)
a3 += a1
self.assertEqual(a3.sq_m, 400)
a4 = a1 - a2
self.assertEqual(a4.sq_m, -100)
a4 -= a1
self.assertEqual(a4.sq_m, -200)
try:
a5 = a1 + 1
except TypeError, e:
pass
else:
self.fail('Area + number should raise TypeError')
try:
a5 = a1 - 1
except TypeError, e:
pass
else:
self.fail('Area - number should raise TypeError')
try:
a1 += 1
except TypeError, e:
pass
else:
self.fail('Area += number should raise TypeError')
try:
a1 -= 1
except TypeError, e:
pass
else:
self.fail('Area -= number should raise TypeError')
def testMultiplication(self):
"Test multiplication & division"
a1 = A(sq_m=100)
a3 = a1 * 2
self.assertEqual(a3.sq_m, 200)
a3 = 2 * a1
self.assertEqual(a3.sq_m, 200)
a3 *= 5
self.assertEqual(a3.sq_m, 1000)
a4 = a1 / 2
self.assertEqual(a4.sq_m, 50)
a4 /= 5
self.assertEqual(a4.sq_m, 10)
try:
a5 = a1 * A(sq_m=1)
except TypeError, e:
pass
else:
self.fail('Area * Area should raise TypeError')
try:
a1 *= A(sq_m=1)
except TypeError, e:
pass
else:
self.fail('Area *= Area should raise TypeError')
try:
a5 = a1 / A(sq_m=1)
except TypeError, e:
pass
else:
self.fail('Area / Area should raise TypeError')
try:
a1 /= A(sq_m=1)
except TypeError, e:
pass
else:
self.fail('Area /= Area should raise TypeError')
def testUnitConversions(self):
"Testing default units during maths"
a1 = A(sq_m=100)
a2 = A(sq_km=1)
a3 = a1 + a2
self.assertEqual(a3._default_unit, 'sq_m')
a4 = a2 + a1
self.assertEqual(a4._default_unit, 'sq_km')
a5 = a1 * 2
self.assertEqual(a5._default_unit, 'sq_m')
a6 = a1 / 2
self.assertEqual(a6._default_unit, 'sq_m')
def testComparisons(self):
"Testing comparisons"
a1 = A(sq_m=100)
a2 = A(sq_km=1)
a3 = A(sq_km=0)
self.assertTrue(a2 > a1)
self.assertTrue(a1 == a1)
self.assertTrue(a1 < a2)
self.failIf(a3)
def testUnitsStr(self):
"Testing conversion to strings"
a1 = A(sq_m=100)
a2 = A(sq_km=3.5)
self.assertEqual(str(a1), '100.0 sq_m')
self.assertEqual(str(a2), '3.5 sq_km')
self.assertEqual(repr(a1), 'Area(sq_m=100.0)')
self.assertEqual(repr(a2), 'Area(sq_km=3.5)')
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(DistanceTest))
s.addTest(unittest.makeSuite(AreaTest))
return s
def run(verbosity=2):
unittest.TextTestRunner(verbosity=verbosity).run(suite())
if __name__=="__main__":
run()
|
bsd-3-clause
|
[
624,
199,
10076,
436,
26280,
2251,
370,
2040,
367,
27962,
436,
406,
433,
287,
6792,
15232,
199,
460,
24796,
14,
11842,
787,
2005,
2295,
14,
199,
624,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
9580,
492,
21892,
12,
26280,
12,
577,
12,
437,
199,
504,
1639,
14,
1208,
492,
2882,
421,
199,
533,
21892,
774,
8,
2796,
14,
1746,
304,
272,
298,
9029,
314,
21892,
909,
2,
339,
347,
511,
9346,
8,
277,
304,
267,
298,
9029,
2536,
19914,
687,
1686,
6204,
2,
267,
366,
275,
21892,
8,
77,
29,
1960,
9,
267,
291,
14,
629,
8,
68,
14,
77,
12,
2948,
9,
398,
366,
17,
12,
366,
18,
12,
366,
19,
275,
577,
8,
77,
29,
1960,
395,
577,
8,
10011,
29,
1960,
395,
577,
8,
10207,
264,
29,
1960,
9,
267,
367,
366,
315,
334,
68,
17,
12,
366,
18,
12,
366,
19,
304,
288,
291,
14,
629,
8,
68,
14,
77,
12,
2948,
9,
398,
366,
275,
577,
8,
10756,
29,
1960,
9,
267,
291,
14,
629,
8,
68,
14,
77,
12,
413,
2426,
1840,
9,
398,
612,
17,
12,
612,
18,
12,
612,
19,
275,
577,
8,
24503,
29,
1960,
395,
577,
8,
89,
1005,
29,
1960,
395,
577,
8,
57,
1005,
29,
1960,
9,
267,
367,
366,
315,
334,
89,
17,
12,
612,
18,
12,
612,
19,
304,
288,
291,
14,
629,
8,
68,
14,
24503,
12,
2948,
9,
398,
8562,
17,
12,
8562,
18,
275,
577,
8,
19579,
10011,
29,
5279,
395,
577,
8,
14738,
4464,
73,
1352,
6301,
50,
29,
5279,
9,
267,
367,
366,
315,
334,
596,
17,
12,
8562,
18,
304,
288,
291,
14,
629,
8,
68,
14,
77,
12,
413,
14,
16,
9,
288,
291,
14,
629,
8,
68,
14,
596,
12,
5198,
14,
16,
9,
2378,
347,
511,
9346,
3364,
8,
277,
304,
267,
298,
9029,
2536,
19914,
687,
3866,
6204,
2,
267,
291,
14,
1855,
8,
10227,
12,
577,
12,
30354,
6738,
29,
1960,
9,
339,
347,
511,
3946,
8,
277,
304,
267,
298,
9029,
2879,
315,
3365,
6204,
2,
267,
366,
275,
577,
8,
77,
29,
1960,
9,
267,
291,
14,
629,
8,
68,
14,
14595,
12,
378,
14,
17,
9,
267,
291,
14,
7904,
8,
68,
14,
856,
12,
650,
1651,
14,
26107,
12,
650,
9,
339,
347,
511,
3946,
3364,
8,
277,
304,
267,
298,
9029,
2879,
315,
3866,
6204,
2,
267,
366,
275,
577,
8,
77,
29,
1960,
9,
267,
291,
14,
19670,
8,
11161,
8,
68,
12,
283,
13206,
6738,
1333,
339,
347,
511,
2767,
1671,
8,
277,
304,
267,
298,
774,
10234,
1253,
1007,
26137,
2,
267,
366,
17,
275,
577,
8,
77,
29,
1960,
9,
267,
366,
18,
275,
577,
8,
77,
29,
1840,
9,
398,
366,
19,
275,
366,
17,
435,
366,
18,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
9601,
9,
267,
366,
19,
847,
366,
17,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
8290,
9,
398,
366,
20,
275,
366,
17,
446,
366,
18,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
446,
1960,
9,
267,
366,
20,
4862,
366,
17,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
446,
1840,
9,
398,
862,
26,
288,
366,
21,
275,
366,
17,
435,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
435,
1329,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
21,
275,
366,
17,
446,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
446,
1329,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
17,
847,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
847,
1329,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
17,
4862,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
4862,
1329,
1077,
746,
3146,
358,
339,
347,
511,
25314,
1863,
8,
277,
304,
267,
298,
774,
24638,
1253,
4629,
2,
267,
366,
17,
275,
577,
8,
77,
29,
1960,
9,
398,
366,
19,
275,
366,
17,
627,
499,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
1926,
9,
267,
366,
19,
275,
499,
627,
366,
17,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
1926,
9,
267,
366,
19,
9000,
959,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
5198,
9,
398,
366,
20,
275,
366,
17,
1182,
499,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
5238,
9,
267,
366,
20,
12257,
959,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
1616,
9,
398,
282,
21,
275,
366,
17,
627,
577,
8,
77,
29,
709,
9,
267,
291,
14,
1815,
8,
6074,
8,
65,
21,
12,
26280,
430,
267,
291,
14,
629,
8,
65,
21,
14,
3526,
63,
77,
12,
2948,
10,
709,
9,
398,
862,
26,
288,
366,
17,
9000,
577,
8,
77,
29,
17,
9,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
9000,
21892,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
21,
275,
366,
17,
1182,
577,
8,
77,
29,
17,
9,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
1182,
21892,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
17,
12257,
577,
8,
77,
29,
17,
9,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
12257,
21892,
1077,
746,
3146,
358,
339,
347,
511,
5072,
714,
6234,
8,
277,
304,
267,
298,
9029,
849,
6204,
5309,
3473,
83,
2,
267,
366,
17,
275,
577,
8,
77,
29,
1960,
9,
267,
366,
18,
275,
577,
8,
14595,
29,
17,
9,
398,
366,
19,
275,
366,
17,
435,
366,
18,
267,
291,
14,
629,
8,
68,
19,
423,
885,
63,
3248,
12,
283,
77,
358,
267,
366,
20,
275,
366,
18,
435,
366,
17,
267,
291,
14,
629,
8,
68,
20,
423,
885,
63,
3248,
12,
283,
14595,
358,
267
] |
[
199,
10076,
436,
26280,
2251,
370,
2040,
367,
27962,
436,
406,
433,
287,
6792,
15232,
199,
460,
24796,
14,
11842,
787,
2005,
2295,
14,
199,
624,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
9580,
492,
21892,
12,
26280,
12,
577,
12,
437,
199,
504,
1639,
14,
1208,
492,
2882,
421,
199,
533,
21892,
774,
8,
2796,
14,
1746,
304,
272,
298,
9029,
314,
21892,
909,
2,
339,
347,
511,
9346,
8,
277,
304,
267,
298,
9029,
2536,
19914,
687,
1686,
6204,
2,
267,
366,
275,
21892,
8,
77,
29,
1960,
9,
267,
291,
14,
629,
8,
68,
14,
77,
12,
2948,
9,
398,
366,
17,
12,
366,
18,
12,
366,
19,
275,
577,
8,
77,
29,
1960,
395,
577,
8,
10011,
29,
1960,
395,
577,
8,
10207,
264,
29,
1960,
9,
267,
367,
366,
315,
334,
68,
17,
12,
366,
18,
12,
366,
19,
304,
288,
291,
14,
629,
8,
68,
14,
77,
12,
2948,
9,
398,
366,
275,
577,
8,
10756,
29,
1960,
9,
267,
291,
14,
629,
8,
68,
14,
77,
12,
413,
2426,
1840,
9,
398,
612,
17,
12,
612,
18,
12,
612,
19,
275,
577,
8,
24503,
29,
1960,
395,
577,
8,
89,
1005,
29,
1960,
395,
577,
8,
57,
1005,
29,
1960,
9,
267,
367,
366,
315,
334,
89,
17,
12,
612,
18,
12,
612,
19,
304,
288,
291,
14,
629,
8,
68,
14,
24503,
12,
2948,
9,
398,
8562,
17,
12,
8562,
18,
275,
577,
8,
19579,
10011,
29,
5279,
395,
577,
8,
14738,
4464,
73,
1352,
6301,
50,
29,
5279,
9,
267,
367,
366,
315,
334,
596,
17,
12,
8562,
18,
304,
288,
291,
14,
629,
8,
68,
14,
77,
12,
413,
14,
16,
9,
288,
291,
14,
629,
8,
68,
14,
596,
12,
5198,
14,
16,
9,
2378,
347,
511,
9346,
3364,
8,
277,
304,
267,
298,
9029,
2536,
19914,
687,
3866,
6204,
2,
267,
291,
14,
1855,
8,
10227,
12,
577,
12,
30354,
6738,
29,
1960,
9,
339,
347,
511,
3946,
8,
277,
304,
267,
298,
9029,
2879,
315,
3365,
6204,
2,
267,
366,
275,
577,
8,
77,
29,
1960,
9,
267,
291,
14,
629,
8,
68,
14,
14595,
12,
378,
14,
17,
9,
267,
291,
14,
7904,
8,
68,
14,
856,
12,
650,
1651,
14,
26107,
12,
650,
9,
339,
347,
511,
3946,
3364,
8,
277,
304,
267,
298,
9029,
2879,
315,
3866,
6204,
2,
267,
366,
275,
577,
8,
77,
29,
1960,
9,
267,
291,
14,
19670,
8,
11161,
8,
68,
12,
283,
13206,
6738,
1333,
339,
347,
511,
2767,
1671,
8,
277,
304,
267,
298,
774,
10234,
1253,
1007,
26137,
2,
267,
366,
17,
275,
577,
8,
77,
29,
1960,
9,
267,
366,
18,
275,
577,
8,
77,
29,
1840,
9,
398,
366,
19,
275,
366,
17,
435,
366,
18,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
9601,
9,
267,
366,
19,
847,
366,
17,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
8290,
9,
398,
366,
20,
275,
366,
17,
446,
366,
18,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
446,
1960,
9,
267,
366,
20,
4862,
366,
17,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
446,
1840,
9,
398,
862,
26,
288,
366,
21,
275,
366,
17,
435,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
435,
1329,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
21,
275,
366,
17,
446,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
446,
1329,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
17,
847,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
847,
1329,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
17,
4862,
413,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
4862,
1329,
1077,
746,
3146,
358,
339,
347,
511,
25314,
1863,
8,
277,
304,
267,
298,
774,
24638,
1253,
4629,
2,
267,
366,
17,
275,
577,
8,
77,
29,
1960,
9,
398,
366,
19,
275,
366,
17,
627,
499,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
1926,
9,
267,
366,
19,
275,
499,
627,
366,
17,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
1926,
9,
267,
366,
19,
9000,
959,
267,
291,
14,
629,
8,
68,
19,
14,
77,
12,
5198,
9,
398,
366,
20,
275,
366,
17,
1182,
499,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
5238,
9,
267,
366,
20,
12257,
959,
267,
291,
14,
629,
8,
68,
20,
14,
77,
12,
1616,
9,
398,
282,
21,
275,
366,
17,
627,
577,
8,
77,
29,
709,
9,
267,
291,
14,
1815,
8,
6074,
8,
65,
21,
12,
26280,
430,
267,
291,
14,
629,
8,
65,
21,
14,
3526,
63,
77,
12,
2948,
10,
709,
9,
398,
862,
26,
288,
366,
17,
9000,
577,
8,
77,
29,
17,
9,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
9000,
21892,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
21,
275,
366,
17,
1182,
577,
8,
77,
29,
17,
9,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
1182,
21892,
1077,
746,
3146,
358,
398,
862,
26,
288,
366,
17,
12257,
577,
8,
77,
29,
17,
9,
267,
871,
3146,
12,
325,
26,
288,
986,
267,
587,
26,
288,
291,
14,
1633,
360,
10076,
12257,
21892,
1077,
746,
3146,
358,
339,
347,
511,
5072,
714,
6234,
8,
277,
304,
267,
298,
9029,
849,
6204,
5309,
3473,
83,
2,
267,
366,
17,
275,
577,
8,
77,
29,
1960,
9,
267,
366,
18,
275,
577,
8,
14595,
29,
17,
9,
398,
366,
19,
275,
366,
17,
435,
366,
18,
267,
291,
14,
629,
8,
68,
19,
423,
885,
63,
3248,
12,
283,
77,
358,
267,
366,
20,
275,
366,
18,
435,
366,
17,
267,
291,
14,
629,
8,
68,
20,
423,
885,
63,
3248,
12,
283,
14595,
358,
267,
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,
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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
] |
highco-groupe/odoo
|
addons/project/report/project_report.py
|
5
|
5630
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 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/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp import tools
class report_project_task_user(osv.osv):
_name = "report.project.task.user"
_description = "Tasks by user and project"
_auto = False
_columns = {
'name': fields.char('Task Summary', readonly=True),
'user_id': fields.many2one('res.users', 'Assigned To', readonly=True),
'date_start': fields.datetime('Assignation Date', readonly=True),
'no_of_days': fields.integer('# of Days', size=128, readonly=True),
'date_end': fields.datetime('Ending Date', readonly=True),
'date_deadline': fields.date('Deadline', readonly=True),
'date_last_stage_update': fields.datetime('Last Stage Update', readonly=True),
'project_id': fields.many2one('project.project', 'Project', readonly=True),
'hours_planned': fields.float('Planned Hours', readonly=True),
'hours_effective': fields.float('Effective Hours', readonly=True),
'hours_delay': fields.float('Avg. Plan.-Eff.', readonly=True),
'remaining_hours': fields.float('Remaining Hours', readonly=True),
'progress': fields.float('Progress', readonly=True, group_operator='avg'),
'total_hours': fields.float('Total Hours', readonly=True),
'closing_days': fields.float('Days to Close', digits=(16,2), readonly=True, group_operator="avg",
help="Number of Days to close the task"),
'opening_days': fields.float('Days to Assign', digits=(16,2), readonly=True, group_operator="avg",
help="Number of Days to Open the task"),
'delay_endings_days': fields.float('Overpassed Deadline', digits=(16,2), readonly=True),
'nbr': fields.integer('# of Tasks', readonly=True), # TDE FIXME master: rename into nbr_tasks
'priority': fields.selection([('0','Low'), ('1','Normal'), ('2','High')],
string='Priority', size=1, readonly=True),
'state': fields.selection([('normal', 'In Progress'),('blocked', 'Blocked'),('done', 'Ready for next stage')],'Status', readonly=True),
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'partner_id': fields.many2one('res.partner', 'Contact', readonly=True),
'stage_id': fields.many2one('project.task.type', 'Stage'),
}
_order = 'name desc, project_id'
def init(self, cr):
tools.sql.drop_view_if_exists(cr, 'report_project_task_user')
cr.execute("""
CREATE view report_project_task_user as
SELECT
(select 1 ) AS nbr,
t.id as id,
t.date_start as date_start,
t.date_end as date_end,
t.date_last_stage_update as date_last_stage_update,
t.date_deadline as date_deadline,
abs((extract('epoch' from (t.write_date-t.date_start)))/(3600*24)) as no_of_days,
t.user_id,
progress as progress,
t.project_id,
t.effective_hours as hours_effective,
t.priority,
t.name as name,
t.company_id,
t.partner_id,
t.stage_id as stage_id,
t.kanban_state as state,
remaining_hours as remaining_hours,
total_hours as total_hours,
t.delay_hours as hours_delay,
planned_hours as hours_planned,
(extract('epoch' from (t.write_date-t.create_date)))/(3600*24) as closing_days,
(extract('epoch' from (t.date_start-t.create_date)))/(3600*24) as opening_days,
abs((extract('epoch' from (t.date_deadline-t.write_date)))/(3600*24)) as delay_endings_days
FROM project_task t
WHERE t.active = 'true'
GROUP BY
t.id,
remaining_hours,
t.effective_hours,
progress,
total_hours,
planned_hours,
hours_delay,
create_date,
write_date,
date_start,
date_end,
date_deadline,
date_last_stage_update,
t.user_id,
t.project_id,
t.priority,
name,
t.company_id,
t.partner_id,
stage_id
""")
|
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,
8353,
13,
6542,
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,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
492,
7249,
421,
199,
533,
3622,
63,
1715,
63,
1765,
63,
751,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
3070,
14,
1715,
14,
1765,
14,
751,
2,
272,
485,
1802,
275,
298,
19295,
701,
922,
436,
2199,
2,
272,
485,
2495,
275,
756,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
4476,
22486,
297,
6863,
29,
549,
395,
267,
283,
751,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
2822,
1737,
4005,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
928,
356,
1504,
14,
2083,
360,
9595,
425,
6148,
297,
6863,
29,
549,
395,
267,
283,
889,
63,
1618,
63,
4899,
356,
1504,
14,
4115,
7863,
402,
577,
5758,
297,
1568,
29,
3933,
12,
6863,
29,
549,
395,
267,
283,
602,
63,
500,
356,
1504,
14,
2083,
360,
3005,
316,
6148,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
22357,
356,
1504,
14,
602,
360,
22147,
604,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
2019,
63,
8614,
63,
873,
356,
1504,
14,
2083,
360,
6090,
1933,
474,
6162,
297,
6863,
29,
549,
395,
267,
283,
1715,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
1715,
14,
1715,
297,
283,
4761,
297,
6863,
29,
549,
395,
267,
283,
8419,
63,
20235,
356,
1504,
14,
1609,
360,
3714,
9386,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
8419,
63,
20427,
356,
1504,
14,
1609,
360,
30754,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
8419,
63,
5814,
356,
1504,
14,
1609,
360,
16650,
14,
32427,
23683,
21469,
3130,
6863,
29,
549,
395,
267,
283,
11266,
63,
8419,
356,
1504,
14,
1609,
360,
31109,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
5734,
356,
1504,
14,
1609,
360,
11504,
297,
6863,
29,
549,
12,
1572,
63,
3856,
534,
8595,
659,
267,
283,
2923,
63,
8419,
356,
1504,
14,
1609,
360,
7316,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
11707,
63,
4899,
356,
1504,
14,
1609,
360,
25589,
370,
15524,
297,
7576,
2687,
975,
12,
18,
395,
6863,
29,
549,
12,
1572,
63,
3856,
628,
8595,
401,
4318,
1720,
628,
3259,
402,
577,
5758,
370,
4002,
314,
2120,
1288,
267,
283,
21849,
63,
4899,
356,
1504,
14,
1609,
360,
25589,
370,
16927,
297,
7576,
2687,
975,
12,
18,
395,
6863,
29,
549,
12,
1572,
63,
3856,
628,
8595,
401,
4318,
1720,
628,
3259,
402,
577,
5758,
370,
3232,
314,
2120,
1288,
267,
283,
5814,
63,
500,
780,
63,
4899,
356,
1504,
14,
1609,
360,
5674,
12070,
1487,
350,
604,
297,
7576,
2687,
975,
12,
18,
395,
6863,
29,
549,
395,
267,
283,
23299,
356,
1504,
14,
4115,
7863,
402,
8495,
83,
297,
6863,
29,
549,
395,
221,
327,
377,
1093,
7600,
5288,
26,
11441,
1901,
31646,
63,
5054,
267,
283,
6693,
356,
1504,
14,
5592,
8318,
16,
1673,
10281,
659,
661,
17,
1673,
6241,
659,
661,
18,
1673,
11688,
2665,
288,
1059,
534,
14354,
297,
1568,
29,
17,
12,
6863,
29,
549,
395,
267,
283,
929,
356,
1504,
14,
5592,
8318,
3302,
297,
283,
607,
21211,
8157,
17726,
297,
283,
3142,
379,
8157,
4456,
297,
283,
17960,
367,
2163,
9546,
2665,
7,
3694,
297,
6863,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
395,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
14499,
297,
6863,
29,
549,
395,
267,
283,
8614,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
1715,
14,
1765,
14,
466,
297,
283,
21052,
659,
272,
789,
272,
485,
1648,
275,
283,
354,
4328,
12,
2199,
63,
344,
7,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
7249,
14,
3009,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
3070,
63,
1715,
63,
1765,
63,
751,
358,
267,
2467,
14,
2526,
4852,
288,
16999,
2455,
3622,
63,
1715,
63,
1765,
63,
751,
465,
1598,
10468,
490,
334,
2416,
413,
776,
4319,
31646,
12,
490,
307,
14,
344,
465,
1305,
12,
490,
307,
14,
602,
63,
928,
465,
1434,
63,
928,
12,
490,
307,
14,
602,
63,
500,
465,
1434,
63,
500,
12,
490,
307,
14,
602,
63,
2019,
63,
8614,
63,
873,
465,
1434,
63,
2019,
63,
8614,
63,
873,
12,
490,
307,
14,
602,
63,
22357,
465,
1434,
63,
22357,
12,
490,
2853,
1332,
5005,
360,
7367,
7,
687,
334,
84,
14,
952,
63,
602,
13,
84,
14,
602,
63,
928,
1724,
7985,
11035,
10,
1194,
430,
221,
465,
949,
63,
1618,
63,
4899,
12,
490,
307,
14,
751,
63,
344,
12,
490,
6696,
465,
6696,
12,
490,
307,
14,
1715,
63,
344,
12,
490,
307,
14,
20427,
63,
8419,
465,
10857,
63,
20427,
12,
490,
307,
14
] |
[
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,
8353,
13,
6542,
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,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
492,
7249,
421,
199,
533,
3622,
63,
1715,
63,
1765,
63,
751,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
3070,
14,
1715,
14,
1765,
14,
751,
2,
272,
485,
1802,
275,
298,
19295,
701,
922,
436,
2199,
2,
272,
485,
2495,
275,
756,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
4476,
22486,
297,
6863,
29,
549,
395,
267,
283,
751,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
2822,
1737,
4005,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
928,
356,
1504,
14,
2083,
360,
9595,
425,
6148,
297,
6863,
29,
549,
395,
267,
283,
889,
63,
1618,
63,
4899,
356,
1504,
14,
4115,
7863,
402,
577,
5758,
297,
1568,
29,
3933,
12,
6863,
29,
549,
395,
267,
283,
602,
63,
500,
356,
1504,
14,
2083,
360,
3005,
316,
6148,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
22357,
356,
1504,
14,
602,
360,
22147,
604,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
2019,
63,
8614,
63,
873,
356,
1504,
14,
2083,
360,
6090,
1933,
474,
6162,
297,
6863,
29,
549,
395,
267,
283,
1715,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
1715,
14,
1715,
297,
283,
4761,
297,
6863,
29,
549,
395,
267,
283,
8419,
63,
20235,
356,
1504,
14,
1609,
360,
3714,
9386,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
8419,
63,
20427,
356,
1504,
14,
1609,
360,
30754,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
8419,
63,
5814,
356,
1504,
14,
1609,
360,
16650,
14,
32427,
23683,
21469,
3130,
6863,
29,
549,
395,
267,
283,
11266,
63,
8419,
356,
1504,
14,
1609,
360,
31109,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
5734,
356,
1504,
14,
1609,
360,
11504,
297,
6863,
29,
549,
12,
1572,
63,
3856,
534,
8595,
659,
267,
283,
2923,
63,
8419,
356,
1504,
14,
1609,
360,
7316,
869,
16363,
297,
6863,
29,
549,
395,
267,
283,
11707,
63,
4899,
356,
1504,
14,
1609,
360,
25589,
370,
15524,
297,
7576,
2687,
975,
12,
18,
395,
6863,
29,
549,
12,
1572,
63,
3856,
628,
8595,
401,
4318,
1720,
628,
3259,
402,
577,
5758,
370,
4002,
314,
2120,
1288,
267,
283,
21849,
63,
4899,
356,
1504,
14,
1609,
360,
25589,
370,
16927,
297,
7576,
2687,
975,
12,
18,
395,
6863,
29,
549,
12,
1572,
63,
3856,
628,
8595,
401,
4318,
1720,
628,
3259,
402,
577,
5758,
370,
3232,
314,
2120,
1288,
267,
283,
5814,
63,
500,
780,
63,
4899,
356,
1504,
14,
1609,
360,
5674,
12070,
1487,
350,
604,
297,
7576,
2687,
975,
12,
18,
395,
6863,
29,
549,
395,
267,
283,
23299,
356,
1504,
14,
4115,
7863,
402,
8495,
83,
297,
6863,
29,
549,
395,
221,
327,
377,
1093,
7600,
5288,
26,
11441,
1901,
31646,
63,
5054,
267,
283,
6693,
356,
1504,
14,
5592,
8318,
16,
1673,
10281,
659,
661,
17,
1673,
6241,
659,
661,
18,
1673,
11688,
2665,
288,
1059,
534,
14354,
297,
1568,
29,
17,
12,
6863,
29,
549,
395,
267,
283,
929,
356,
1504,
14,
5592,
8318,
3302,
297,
283,
607,
21211,
8157,
17726,
297,
283,
3142,
379,
8157,
4456,
297,
283,
17960,
367,
2163,
9546,
2665,
7,
3694,
297,
6863,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
395,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
14499,
297,
6863,
29,
549,
395,
267,
283,
8614,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
1715,
14,
1765,
14,
466,
297,
283,
21052,
659,
272,
789,
272,
485,
1648,
275,
283,
354,
4328,
12,
2199,
63,
344,
7,
339,
347,
4205,
8,
277,
12,
2467,
304,
267,
7249,
14,
3009,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
3070,
63,
1715,
63,
1765,
63,
751,
358,
267,
2467,
14,
2526,
4852,
288,
16999,
2455,
3622,
63,
1715,
63,
1765,
63,
751,
465,
1598,
10468,
490,
334,
2416,
413,
776,
4319,
31646,
12,
490,
307,
14,
344,
465,
1305,
12,
490,
307,
14,
602,
63,
928,
465,
1434,
63,
928,
12,
490,
307,
14,
602,
63,
500,
465,
1434,
63,
500,
12,
490,
307,
14,
602,
63,
2019,
63,
8614,
63,
873,
465,
1434,
63,
2019,
63,
8614,
63,
873,
12,
490,
307,
14,
602,
63,
22357,
465,
1434,
63,
22357,
12,
490,
2853,
1332,
5005,
360,
7367,
7,
687,
334,
84,
14,
952,
63,
602,
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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
] |
johnkit/vtk-dev
|
Charts/Core/Testing/Python/TestLinePlot.py
|
26
|
2094
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import vtk
import vtk.test.Testing
import math
class TestLinePlot(vtk.test.Testing.vtkTest):
def testLinePlot(self):
"Test if line plots can be built with python"
# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1.0,1.0,1.0)
view.GetRenderWindow().SetSize(400,300)
chart = vtk.vtkChartXY()
view.GetScene().AddItem(chart)
# Create a table with some points in it
table = vtk.vtkTable()
arrX = vtk.vtkFloatArray()
arrX.SetName("X Axis")
arrC = vtk.vtkFloatArray()
arrC.SetName("Cosine")
arrS = vtk.vtkFloatArray()
arrS.SetName("Sine")
arrS2 = vtk.vtkFloatArray()
arrS2.SetName("Sine2")
numPoints = 69
inc = 7.5 / (numPoints - 1)
for i in range(0,numPoints):
arrX.InsertNextValue(i*inc)
arrC.InsertNextValue(math.cos(i * inc) + 0.0)
arrS.InsertNextValue(math.sin(i * inc) + 0.0)
arrS2.InsertNextValue(math.sin(i * inc) + 0.5)
table.AddColumn(arrX)
table.AddColumn(arrC)
table.AddColumn(arrS)
table.AddColumn(arrS2)
# Now add the line plots with appropriate colors
line = chart.AddPlot(0)
line.SetInputData(table,0,1)
line.SetColor(0,255,0,255)
line.SetWidth(1.0)
line = chart.AddPlot(0)
line.SetInputData(table,0,2)
line.SetColor(255,0,0,255)
line.SetWidth(5.0)
line = chart.AddPlot(0)
line.SetInputData(table,0,3)
line.SetColor(0,0,255,255)
line.SetWidth(4.0)
view.GetRenderWindow().SetMultiSamples(0)
view.GetRenderWindow().Render()
img_file = "TestLinePlot.png"
vtk.test.Testing.compareImage(view.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
vtk.test.Testing.interact()
if __name__ == "__main__":
vtk.test.Testing.main([(TestLinePlot, 'test')])
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
11144,
199,
646,
11144,
14,
396,
14,
9029,
199,
646,
3473,
199,
199,
533,
1379,
3049,
10711,
8,
11919,
14,
396,
14,
9029,
14,
11919,
774,
304,
272,
347,
511,
3049,
10711,
8,
277,
304,
267,
298,
774,
340,
1004,
19695,
883,
506,
6137,
543,
2366,
2,
398,
327,
2494,
1536,
282,
499,
36,
13856,
12,
1050,
376,
1323,
57,
10943,
370,
652,
267,
2455,
275,
11144,
14,
11919,
2998,
2768,
342,
267,
2455,
14,
1002,
11355,
1252,
1084,
14148,
8,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
9,
267,
2455,
14,
1002,
9216,
4301,
1252,
1084,
2320,
8,
5303,
12,
5863,
9,
267,
10943,
275,
11144,
14,
11919,
16372,
8195,
342,
267,
2455,
14,
1002,
14216,
1252,
1123,
2081,
8,
9019,
9,
398,
327,
2790,
282,
1817,
543,
2005,
4501,
315,
652,
267,
1817,
275,
11144,
14,
11919,
3186,
342,
398,
7953,
56,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
56,
14,
1084,
985,
480,
56,
23205,
531,
398,
7953,
35,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
35,
14,
1084,
985,
480,
26253,
1132,
531,
398,
7953,
51,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
51,
14,
1084,
985,
480,
51,
1132,
531,
398,
7953,
51,
18,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
51,
18,
14,
1084,
985,
480,
51,
1132,
18,
531,
398,
1967,
10225,
275,
14610,
267,
12864,
275,
1520,
14,
21,
1182,
334,
1507,
10225,
446,
413,
9,
398,
367,
284,
315,
1425,
8,
16,
12,
1507,
10225,
304,
288,
7953,
56,
14,
9971,
5765,
1110,
8,
73,
10,
6559,
9,
288,
7953,
35,
14,
9971,
5765,
1110,
8,
3442,
14,
5197,
8,
73,
627,
12864,
9,
435,
378,
14,
16,
9,
288,
7953,
51,
14,
9971,
5765,
1110,
8,
3442,
14,
5911,
8,
73,
627,
12864,
9,
435,
378,
14,
16,
9,
288,
7953,
51,
18,
14,
9971,
5765,
1110,
8,
3442,
14,
5911,
8,
73,
627,
12864,
9,
435,
378,
14,
21,
9,
398,
1817,
14,
1123,
4547,
8,
5250,
56,
9,
267,
1817,
14,
1123,
4547,
8,
5250,
35,
9,
267,
1817,
14,
1123,
4547,
8,
5250,
51,
9,
267,
1817,
14,
1123,
4547,
8,
5250,
51,
18,
9,
398,
327,
7356,
1050,
314,
1004,
19695,
543,
5827,
9229,
267,
1004,
275,
10943,
14,
1123,
10711,
8,
16,
9,
267,
1004,
14,
24029,
1451,
8,
1224,
12,
16,
12,
17,
9,
267,
1004,
14,
1084,
4117,
8,
16,
12,
2299,
12,
16,
12,
2299,
9,
267,
1004,
14,
1084,
6216,
8,
17,
14,
16,
9,
398,
1004,
275,
10943,
14,
1123,
10711,
8,
16,
9,
267,
1004,
14,
24029,
1451,
8,
1224,
12,
16,
12,
18,
9,
267,
1004,
14,
1084,
4117,
8,
2299,
12,
16,
12,
16,
12,
2299,
9,
267,
1004,
14,
1084,
6216,
8,
21,
14,
16,
9,
398,
1004,
275,
10943,
14,
1123,
10711,
8,
16,
9,
267,
1004,
14,
24029,
1451,
8,
1224,
12,
16,
12,
19,
9,
267,
1004,
14,
1084,
4117,
8,
16,
12,
16,
12,
2299,
12,
2299,
9,
267,
1004,
14,
1084,
6216,
8,
20,
14,
16,
9,
398,
2455,
14,
1002,
9216,
4301,
1252,
1084,
3947,
27665,
8,
16,
9,
267,
2455,
14,
1002,
9216,
4301,
1252,
9216,
342,
398,
6050,
63,
493,
275,
298,
774,
3049,
10711,
14,
4524,
2,
267,
11144,
14,
396,
14,
9029,
14,
5785,
3491,
8,
1345,
14,
1002,
9216,
4301,
1062,
11919,
14,
396,
14,
9029,
14,
362,
15447,
3491,
2042,
8,
4060,
63,
493,
395,
7227,
29,
821,
9,
267,
11144,
14,
396,
14,
9029,
14,
25850,
342,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
11144,
14,
396,
14,
9029,
14,
973,
7694,
774,
3049,
10711,
12,
283,
396,
2023,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
11144,
199,
646,
11144,
14,
396,
14,
9029,
199,
646,
3473,
199,
199,
533,
1379,
3049,
10711,
8,
11919,
14,
396,
14,
9029,
14,
11919,
774,
304,
272,
347,
511,
3049,
10711,
8,
277,
304,
267,
298,
774,
340,
1004,
19695,
883,
506,
6137,
543,
2366,
2,
398,
327,
2494,
1536,
282,
499,
36,
13856,
12,
1050,
376,
1323,
57,
10943,
370,
652,
267,
2455,
275,
11144,
14,
11919,
2998,
2768,
342,
267,
2455,
14,
1002,
11355,
1252,
1084,
14148,
8,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
9,
267,
2455,
14,
1002,
9216,
4301,
1252,
1084,
2320,
8,
5303,
12,
5863,
9,
267,
10943,
275,
11144,
14,
11919,
16372,
8195,
342,
267,
2455,
14,
1002,
14216,
1252,
1123,
2081,
8,
9019,
9,
398,
327,
2790,
282,
1817,
543,
2005,
4501,
315,
652,
267,
1817,
275,
11144,
14,
11919,
3186,
342,
398,
7953,
56,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
56,
14,
1084,
985,
480,
56,
23205,
531,
398,
7953,
35,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
35,
14,
1084,
985,
480,
26253,
1132,
531,
398,
7953,
51,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
51,
14,
1084,
985,
480,
51,
1132,
531,
398,
7953,
51,
18,
275,
11144,
14,
11919,
5136,
3836,
342,
267,
7953,
51,
18,
14,
1084,
985,
480,
51,
1132,
18,
531,
398,
1967,
10225,
275,
14610,
267,
12864,
275,
1520,
14,
21,
1182,
334,
1507,
10225,
446,
413,
9,
398,
367,
284,
315,
1425,
8,
16,
12,
1507,
10225,
304,
288,
7953,
56,
14,
9971,
5765,
1110,
8,
73,
10,
6559,
9,
288,
7953,
35,
14,
9971,
5765,
1110,
8,
3442,
14,
5197,
8,
73,
627,
12864,
9,
435,
378,
14,
16,
9,
288,
7953,
51,
14,
9971,
5765,
1110,
8,
3442,
14,
5911,
8,
73,
627,
12864,
9,
435,
378,
14,
16,
9,
288,
7953,
51,
18,
14,
9971,
5765,
1110,
8,
3442,
14,
5911,
8,
73,
627,
12864,
9,
435,
378,
14,
21,
9,
398,
1817,
14,
1123,
4547,
8,
5250,
56,
9,
267,
1817,
14,
1123,
4547,
8,
5250,
35,
9,
267,
1817,
14,
1123,
4547,
8,
5250,
51,
9,
267,
1817,
14,
1123,
4547,
8,
5250,
51,
18,
9,
398,
327,
7356,
1050,
314,
1004,
19695,
543,
5827,
9229,
267,
1004,
275,
10943,
14,
1123,
10711,
8,
16,
9,
267,
1004,
14,
24029,
1451,
8,
1224,
12,
16,
12,
17,
9,
267,
1004,
14,
1084,
4117,
8,
16,
12,
2299,
12,
16,
12,
2299,
9,
267,
1004,
14,
1084,
6216,
8,
17,
14,
16,
9,
398,
1004,
275,
10943,
14,
1123,
10711,
8,
16,
9,
267,
1004,
14,
24029,
1451,
8,
1224,
12,
16,
12,
18,
9,
267,
1004,
14,
1084,
4117,
8,
2299,
12,
16,
12,
16,
12,
2299,
9,
267,
1004,
14,
1084,
6216,
8,
21,
14,
16,
9,
398,
1004,
275,
10943,
14,
1123,
10711,
8,
16,
9,
267,
1004,
14,
24029,
1451,
8,
1224,
12,
16,
12,
19,
9,
267,
1004,
14,
1084,
4117,
8,
16,
12,
16,
12,
2299,
12,
2299,
9,
267,
1004,
14,
1084,
6216,
8,
20,
14,
16,
9,
398,
2455,
14,
1002,
9216,
4301,
1252,
1084,
3947,
27665,
8,
16,
9,
267,
2455,
14,
1002,
9216,
4301,
1252,
9216,
342,
398,
6050,
63,
493,
275,
298,
774,
3049,
10711,
14,
4524,
2,
267,
11144,
14,
396,
14,
9029,
14,
5785,
3491,
8,
1345,
14,
1002,
9216,
4301,
1062,
11919,
14,
396,
14,
9029,
14,
362,
15447,
3491,
2042,
8,
4060,
63,
493,
395,
7227,
29,
821,
9,
267,
11144,
14,
396,
14,
9029,
14,
25850,
342,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
11144,
14,
396,
14,
9029,
14,
973,
7694,
774,
3049,
10711,
12,
283,
396,
2023,
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,
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
] |
oblank/pydjango-froum
|
forum/admin.py
|
6
|
1277
|
from django.contrib import admin
from forum.models import ForumUser, Plane, Node, Topic, Reply, Favorite, Notification, Transaction, Vote
class ForumUserAdmin(admin.ModelAdmin):
list_display = ('username', 'email', 'is_active', 'is_staff', 'date_joined')
search_fields = ('username', 'email', 'nickname')
list_filter = ('is_active', 'is_staff', 'date_joined')
class PlaneAdmin(admin.ModelAdmin):
list_display = ('name', 'created')
search_fields = ('name',)
list_filter = ('created',)
class NodeAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', 'created')
search_fields = ('name',)
list_filter = ('created',)
class TopicAdmin(admin.ModelAdmin):
list_display = ('title', 'created')
search_fields = ('title', 'content')
list_filter = ('created',)
class ReplyAdmin(admin.ModelAdmin):
list_display = ('content', 'created')
search_fields = ('content',)
list_filter = ('created',)
admin.site.register(ForumUser, ForumUserAdmin)
admin.site.register(Plane, PlaneAdmin)
admin.site.register(Node, NodeAdmin)
admin.site.register(Topic, TopicAdmin)
admin.site.register(Reply, ReplyAdmin)
admin.site.register(Favorite)
admin.site.register(Notification)
admin.site.register(Transaction)
admin.site.register(Vote)
|
mit
|
[
504,
1639,
14,
2828,
492,
4628,
202,
504,
21575,
14,
992,
492,
2104,
453,
1899,
12,
510,
24064,
12,
5013,
12,
32166,
12,
16000,
590,
12,
481,
12958,
1175,
12,
23362,
12,
18244,
12,
812,
1583,
202,
202,
202,
533,
2104,
453,
1899,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
2473,
297,
283,
2123,
297,
283,
374,
63,
2682,
297,
283,
374,
63,
7018,
297,
283,
602,
63,
11806,
358,
202,
259,
2754,
63,
955,
275,
661,
2473,
297,
283,
2123,
297,
283,
18544,
358,
202,
259,
769,
63,
1541,
275,
661,
374,
63,
2682,
297,
283,
374,
63,
7018,
297,
283,
602,
63,
11806,
358,
202,
202,
202,
533,
510,
24064,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
354,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
354,
9538,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
533,
5013,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
354,
297,
283,
5464,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
354,
9538,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
533,
32166,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
1213,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
1213,
297,
283,
1317,
358,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
533,
16000,
590,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
1317,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
1317,
9538,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
2113,
14,
2124,
14,
2683,
8,
1858,
453,
1899,
12,
2104,
453,
1899,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
23363,
12,
510,
24064,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
1716,
12,
5013,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
12157,
12,
32166,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
14166,
12,
16000,
590,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
24335,
1175,
9,
202,
2113,
14,
2124,
14,
2683,
8,
11598,
9,
202,
2113,
14,
2124,
14,
2683,
8,
10161,
9,
202,
2113,
14,
2124,
14,
2683,
8,
54,
1583,
9,
202,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
202,
504,
21575,
14,
992,
492,
2104,
453,
1899,
12,
510,
24064,
12,
5013,
12,
32166,
12,
16000,
590,
12,
481,
12958,
1175,
12,
23362,
12,
18244,
12,
812,
1583,
202,
202,
202,
533,
2104,
453,
1899,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
2473,
297,
283,
2123,
297,
283,
374,
63,
2682,
297,
283,
374,
63,
7018,
297,
283,
602,
63,
11806,
358,
202,
259,
2754,
63,
955,
275,
661,
2473,
297,
283,
2123,
297,
283,
18544,
358,
202,
259,
769,
63,
1541,
275,
661,
374,
63,
2682,
297,
283,
374,
63,
7018,
297,
283,
602,
63,
11806,
358,
202,
202,
202,
533,
510,
24064,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
354,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
354,
9538,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
533,
5013,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
354,
297,
283,
5464,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
354,
9538,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
533,
32166,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
1213,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
1213,
297,
283,
1317,
358,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
533,
16000,
590,
4880,
8,
2113,
14,
12976,
304,
202,
259,
769,
63,
2918,
275,
661,
1317,
297,
283,
3966,
358,
202,
259,
2754,
63,
955,
275,
661,
1317,
9538,
202,
259,
769,
63,
1541,
275,
661,
3966,
9538,
202,
202,
202,
2113,
14,
2124,
14,
2683,
8,
1858,
453,
1899,
12,
2104,
453,
1899,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
23363,
12,
510,
24064,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
1716,
12,
5013,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
12157,
12,
32166,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
14166,
12,
16000,
590,
4880,
9,
202,
2113,
14,
2124,
14,
2683,
8,
24335,
1175,
9,
202,
2113,
14,
2124,
14,
2683,
8,
11598,
9,
202,
2113,
14,
2124,
14,
2683,
8,
10161,
9,
202,
2113,
14,
2124,
14,
2683,
8,
54,
1583,
9,
202,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Beauhurst/django
|
tests/auth_tests/urls.py
|
16
|
5533
|
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth import views
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.urls import urlpatterns as auth_urlpatterns
from django.contrib.messages.api import info
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.template import RequestContext, Template
from django.urls import reverse_lazy
from django.views.decorators.cache import never_cache
class CustomRequestAuthenticationForm(AuthenticationForm):
def __init__(self, request, *args, **kwargs):
assert isinstance(request, HttpRequest)
super().__init__(request, *args, **kwargs)
@never_cache
def remote_user_auth_view(request):
"Dummy view for remote user tests"
t = Template("Username is {{ user }}.")
c = RequestContext(request, {})
return HttpResponse(t.render(c))
def auth_processor_no_attr_access(request):
render(request, 'context_processors/auth_attrs_no_access.html')
# *After* rendering, we check whether the session was accessed
return render(request,
'context_processors/auth_attrs_test_access.html',
{'session_accessed': request.session.accessed})
def auth_processor_attr_access(request):
render(request, 'context_processors/auth_attrs_access.html')
return render(request,
'context_processors/auth_attrs_test_access.html',
{'session_accessed': request.session.accessed})
def auth_processor_user(request):
return render(request, 'context_processors/auth_attrs_user.html')
def auth_processor_perms(request):
return render(request, 'context_processors/auth_attrs_perms.html')
def auth_processor_perm_in_perms(request):
return render(request, 'context_processors/auth_attrs_perm_in_perms.html')
def auth_processor_messages(request):
info(request, "Message 1")
return render(request, 'context_processors/auth_attrs_messages.html')
def userpage(request):
pass
uid_token = r'(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})'
# special urls for auth test cases
urlpatterns = auth_urlpatterns + [
url(r'^logout/custom_query/$', views.LogoutView.as_view(redirect_field_name='follow')),
url(r'^logout/next_page/$', views.LogoutView.as_view(next_page='/somewhere/')),
url(r'^logout/next_page/named/$', views.LogoutView.as_view(next_page='password_reset')),
url(r'^logout/allowed_hosts/$', views.LogoutView.as_view(success_url_allowed_hosts={'otherserver'})),
url(r'^remote_user/$', remote_user_auth_view),
url(r'^password_reset_from_email/$',
views.PasswordResetView.as_view(from_email='staffmember@example.com')),
url(r'^password_reset_extra_email_context/$',
views.PasswordResetView.as_view(extra_email_context=dict(greeting='Hello!'))),
url(r'^password_reset/custom_redirect/$',
views.PasswordResetView.as_view(success_url='/custom/')),
url(r'^password_reset/custom_redirect/named/$',
views.PasswordResetView.as_view(success_url=reverse_lazy('password_reset'))),
url(r'^password_reset/html_email_template/$',
views.PasswordResetView.as_view(
html_email_template_name='registration/html_password_reset_email.html'
)),
url(r'^reset/custom/{}/$'.format(uid_token),
views.PasswordResetConfirmView.as_view(success_url='/custom/')),
url(r'^reset/custom/named/{}/$'.format(uid_token),
views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('password_reset'))),
url(r'^reset/post_reset_login/{}/$'.format(uid_token),
views.PasswordResetConfirmView.as_view(post_reset_login=True)),
url(
r'^reset/post_reset_login_custom_backend/{}/$'.format(uid_token),
views.PasswordResetConfirmView.as_view(
post_reset_login=True,
post_reset_login_backend='django.contrib.auth.backends.AllowAllUsersModelBackend',
),
),
url(r'^password_change/custom/$',
views.PasswordChangeView.as_view(success_url='/custom/')),
url(r'^password_change/custom/named/$',
views.PasswordChangeView.as_view(success_url=reverse_lazy('password_reset'))),
url(r'^login_required/$', login_required(views.PasswordResetView.as_view())),
url(r'^login_required_login_url/$', login_required(views.PasswordResetView.as_view(), login_url='/somewhere/')),
url(r'^auth_processor_no_attr_access/$', auth_processor_no_attr_access),
url(r'^auth_processor_attr_access/$', auth_processor_attr_access),
url(r'^auth_processor_user/$', auth_processor_user),
url(r'^auth_processor_perms/$', auth_processor_perms),
url(r'^auth_processor_perm_in_perms/$', auth_processor_perm_in_perms),
url(r'^auth_processor_messages/$', auth_processor_messages),
url(r'^custom_request_auth_login/$',
views.LoginView.as_view(authentication_form=CustomRequestAuthenticationForm)),
url(r'^userpage/(.+)/$', userpage, name="userpage"),
url(r'^login/redirect_authenticated_user_default/$', views.LoginView.as_view()),
url(r'^login/redirect_authenticated_user/$',
views.LoginView.as_view(redirect_authenticated_user=True)),
url(r'^login/allowed_hosts/$',
views.LoginView.as_view(success_url_allowed_hosts={'otherserver'})),
# This line is only required to render the password reset with is_admin=True
url(r'^admin/', admin.site.urls),
]
|
bsd-3-clause
|
[
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
1178,
492,
6858,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
15995,
2821,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3603,
492,
26177,
465,
1790,
63,
20050,
199,
504,
1639,
14,
2828,
14,
3431,
14,
1246,
492,
2256,
199,
504,
1639,
14,
1014,
492,
20730,
12,
6183,
199,
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
1160,
492,
22538,
12,
5458,
199,
504,
1639,
14,
3603,
492,
3837,
63,
6395,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
7078,
63,
1637,
421,
199,
533,
8388,
2017,
10348,
2821,
8,
10348,
2821,
304,
272,
347,
636,
826,
721,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
702,
1228,
8,
1069,
12,
20730,
9,
267,
1613,
11027,
826,
721,
1069,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
18178,
63,
1637,
199,
318,
3982,
63,
751,
63,
1178,
63,
1345,
8,
1069,
304,
272,
298,
11324,
2455,
367,
3982,
922,
2295,
2,
272,
307,
275,
5458,
480,
13355,
365,
8448,
922,
3586,
2685,
272,
286,
275,
22538,
8,
1069,
12,
5009,
272,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
421,
199,
318,
1790,
63,
6459,
63,
889,
63,
962,
63,
2732,
8,
1069,
304,
272,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
889,
63,
2732,
14,
1360,
358,
272,
327,
627,
10881,
10,
14066,
12,
781,
1104,
3775,
314,
2351,
1990,
13810,
272,
372,
3795,
8,
1069,
12,
2116,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
396,
63,
2732,
14,
1360,
297,
2116,
791,
1730,
63,
29433,
356,
1056,
14,
1730,
14,
29433,
1552,
421,
199,
318,
1790,
63,
6459,
63,
962,
63,
2732,
8,
1069,
304,
272,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
2732,
14,
1360,
358,
272,
372,
3795,
8,
1069,
12,
2116,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
396,
63,
2732,
14,
1360,
297,
2116,
791,
1730,
63,
29433,
356,
1056,
14,
1730,
14,
29433,
1552,
421,
199,
318,
1790,
63,
6459,
63,
751,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
751,
14,
1360,
358,
421,
199,
318,
1790,
63,
6459,
63,
12068,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
12068,
14,
1360,
358,
421,
199,
318,
1790,
63,
6459,
63,
8220,
63,
262,
63,
12068,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
8220,
63,
262,
63,
12068,
14,
1360,
358,
421,
199,
318,
1790,
63,
6459,
63,
3431,
8,
1069,
304,
272,
2256,
8,
1069,
12,
298,
2209,
413,
531,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
3431,
14,
1360,
358,
421,
199,
318,
922,
1606,
8,
1069,
304,
272,
986,
421,
199,
1535,
63,
1418,
275,
519,
10120,
48,
28,
1535,
66,
772,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
63,
16185,
24598,
2229,
48,
28,
1418,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
969,
17063,
59,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
1165,
29668,
199,
199,
3,
4539,
8187,
367,
1790,
511,
5560,
199,
20050,
275,
1790,
63,
20050,
435,
359,
272,
1166,
8,
82,
4289,
11646,
15,
4229,
63,
1131,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
4876,
63,
698,
63,
354,
534,
7207,
3855,
272,
1166,
8,
82,
4289,
11646,
15,
2184,
63,
1606,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
2184,
63,
1606,
8805,
3972,
4509,
15,
3855,
272,
1166,
8,
82,
4289,
11646,
15,
2184,
63,
1606,
15,
4579,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
2184,
63,
1606,
534,
2060,
63,
3958,
3855,
272,
1166,
8,
82,
4289,
11646,
15,
6541,
63,
5146,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
63,
6541,
63,
5146,
3713,
1848,
1000,
936,
1826,
272,
1166,
8,
82,
4289,
3846,
63,
751,
10884,
3982,
63,
751,
63,
1178,
63,
1345,
395,
339,
1166,
8,
82,
4289,
2060,
63,
3958,
63,
504,
63,
2123,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
504,
63,
2123,
534,
7018,
1114,
32,
2694,
14,
957,
3855,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
63,
2911,
63,
2123,
63,
1100,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
2911,
63,
2123,
63,
1100,
29,
807,
8,
71,
23457,
534,
6257,
1,
22645,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
4229,
63,
4876,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
8805,
4229,
15,
3855,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
4229,
63,
4876,
15,
4579,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
29,
4471,
63,
6395,
360,
2060,
63,
3958,
22645,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
1360,
63,
2123,
63,
1160,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
288,
3517,
63,
2123,
63,
1160,
63,
354,
534,
8054,
15,
1360,
63,
2060,
63,
3958,
63,
2123,
14,
1360,
7,
267,
22583,
272,
1166,
8,
82,
4289,
3958,
15,
4229,
19655,
4,
1370,
908,
8,
1535,
63,
1418,
395,
267,
6858,
14,
6139,
9637,
26857,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
8805,
4229,
15,
3855,
272,
1166,
8,
82,
4289,
3958,
15,
4229,
15,
4579,
19655,
4,
1370,
908,
8,
1535,
63,
1418,
395,
267,
6858,
14,
6139,
9637,
26857,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
29,
4471,
63,
6395,
360,
2060,
63,
3958,
22645,
272,
1166,
8,
82,
4289,
3958,
15,
1932,
63,
3958,
63,
2886,
19655,
4,
1370,
908,
8,
1535,
63
] |
[
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
1178,
492,
6858,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3351,
492,
15995,
2821,
199,
504,
1639,
14,
2828,
14,
1178,
14,
3603,
492,
26177,
465,
1790,
63,
20050,
199,
504,
1639,
14,
2828,
14,
3431,
14,
1246,
492,
2256,
199,
504,
1639,
14,
1014,
492,
20730,
12,
6183,
199,
504,
1639,
14,
17469,
492,
3795,
199,
504,
1639,
14,
1160,
492,
22538,
12,
5458,
199,
504,
1639,
14,
3603,
492,
3837,
63,
6395,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
7078,
63,
1637,
421,
199,
533,
8388,
2017,
10348,
2821,
8,
10348,
2821,
304,
272,
347,
636,
826,
721,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
702,
1228,
8,
1069,
12,
20730,
9,
267,
1613,
11027,
826,
721,
1069,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
18178,
63,
1637,
199,
318,
3982,
63,
751,
63,
1178,
63,
1345,
8,
1069,
304,
272,
298,
11324,
2455,
367,
3982,
922,
2295,
2,
272,
307,
275,
5458,
480,
13355,
365,
8448,
922,
3586,
2685,
272,
286,
275,
22538,
8,
1069,
12,
5009,
272,
372,
6183,
8,
84,
14,
3352,
8,
67,
430,
421,
199,
318,
1790,
63,
6459,
63,
889,
63,
962,
63,
2732,
8,
1069,
304,
272,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
889,
63,
2732,
14,
1360,
358,
272,
327,
627,
10881,
10,
14066,
12,
781,
1104,
3775,
314,
2351,
1990,
13810,
272,
372,
3795,
8,
1069,
12,
2116,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
396,
63,
2732,
14,
1360,
297,
2116,
791,
1730,
63,
29433,
356,
1056,
14,
1730,
14,
29433,
1552,
421,
199,
318,
1790,
63,
6459,
63,
962,
63,
2732,
8,
1069,
304,
272,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
2732,
14,
1360,
358,
272,
372,
3795,
8,
1069,
12,
2116,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
396,
63,
2732,
14,
1360,
297,
2116,
791,
1730,
63,
29433,
356,
1056,
14,
1730,
14,
29433,
1552,
421,
199,
318,
1790,
63,
6459,
63,
751,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
751,
14,
1360,
358,
421,
199,
318,
1790,
63,
6459,
63,
12068,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
12068,
14,
1360,
358,
421,
199,
318,
1790,
63,
6459,
63,
8220,
63,
262,
63,
12068,
8,
1069,
304,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
8220,
63,
262,
63,
12068,
14,
1360,
358,
421,
199,
318,
1790,
63,
6459,
63,
3431,
8,
1069,
304,
272,
2256,
8,
1069,
12,
298,
2209,
413,
531,
272,
372,
3795,
8,
1069,
12,
283,
1100,
63,
10547,
15,
1178,
63,
3288,
63,
3431,
14,
1360,
358,
421,
199,
318,
922,
1606,
8,
1069,
304,
272,
986,
421,
199,
1535,
63,
1418,
275,
519,
10120,
48,
28,
1535,
66,
772,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
63,
16185,
24598,
2229,
48,
28,
1418,
9514,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
969,
17063,
59,
16,
13,
25,
33,
13,
13163,
13,
90,
8194,
17,
12,
1165,
29668,
199,
199,
3,
4539,
8187,
367,
1790,
511,
5560,
199,
20050,
275,
1790,
63,
20050,
435,
359,
272,
1166,
8,
82,
4289,
11646,
15,
4229,
63,
1131,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
4876,
63,
698,
63,
354,
534,
7207,
3855,
272,
1166,
8,
82,
4289,
11646,
15,
2184,
63,
1606,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
2184,
63,
1606,
8805,
3972,
4509,
15,
3855,
272,
1166,
8,
82,
4289,
11646,
15,
2184,
63,
1606,
15,
4579,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
2184,
63,
1606,
534,
2060,
63,
3958,
3855,
272,
1166,
8,
82,
4289,
11646,
15,
6541,
63,
5146,
10884,
6858,
14,
2445,
548,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
63,
6541,
63,
5146,
3713,
1848,
1000,
936,
1826,
272,
1166,
8,
82,
4289,
3846,
63,
751,
10884,
3982,
63,
751,
63,
1178,
63,
1345,
395,
339,
1166,
8,
82,
4289,
2060,
63,
3958,
63,
504,
63,
2123,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
504,
63,
2123,
534,
7018,
1114,
32,
2694,
14,
957,
3855,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
63,
2911,
63,
2123,
63,
1100,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
2911,
63,
2123,
63,
1100,
29,
807,
8,
71,
23457,
534,
6257,
1,
22645,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
4229,
63,
4876,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
8805,
4229,
15,
3855,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
4229,
63,
4876,
15,
4579,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
29,
4471,
63,
6395,
360,
2060,
63,
3958,
22645,
272,
1166,
8,
82,
4289,
2060,
63,
3958,
15,
1360,
63,
2123,
63,
1160,
10884,
267,
6858,
14,
6139,
9637,
2768,
14,
305,
63,
1345,
8,
288,
3517,
63,
2123,
63,
1160,
63,
354,
534,
8054,
15,
1360,
63,
2060,
63,
3958,
63,
2123,
14,
1360,
7,
267,
22583,
272,
1166,
8,
82,
4289,
3958,
15,
4229,
19655,
4,
1370,
908,
8,
1535,
63,
1418,
395,
267,
6858,
14,
6139,
9637,
26857,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
8805,
4229,
15,
3855,
272,
1166,
8,
82,
4289,
3958,
15,
4229,
15,
4579,
19655,
4,
1370,
908,
8,
1535,
63,
1418,
395,
267,
6858,
14,
6139,
9637,
26857,
2768,
14,
305,
63,
1345,
8,
3742,
63,
633,
29,
4471,
63,
6395,
360,
2060,
63,
3958,
22645,
272,
1166,
8,
82,
4289,
3958,
15,
1932,
63,
3958,
63,
2886,
19655,
4,
1370,
908,
8,
1535,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
punker76/SmartAlarmClock
|
SmartAlarmClock/www/temboo/Library/Google/Calendar/GetNextEvent.py
|
2
|
4346
|
# -*- coding: utf-8 -*-
###############################################################################
#
# GetNextEvent
# Retrieves the next upcoming event in a Google calendar based on the current timestamp and the specified calendar's timezone setting.
#
# Python version 2.6
#
###############################################################################
from temboo.core.choreography import Choreography
from temboo.core.choreography import InputSet
from temboo.core.choreography import ResultSet
from temboo.core.choreography import ChoreographyExecution
import json
class GetNextEvent(Choreography):
def __init__(self, temboo_session):
"""
Create a new instance of the GetNextEvent Choreo. A TembooSession object, containing a valid
set of Temboo credentials, must be supplied.
"""
Choreography.__init__(self, temboo_session, '/Library/Google/Calendar/GetNextEvent')
def new_input_set(self):
return GetNextEventInputSet()
def _make_result_set(self, result, path):
return GetNextEventResultSet(result, path)
def _make_execution(self, session, exec_id, path):
return GetNextEventChoreographyExecution(session, exec_id, path)
class GetNextEventInputSet(InputSet):
"""
An InputSet with methods appropriate for specifying the inputs to the GetNextEvent
Choreo. The InputSet object is used to specify input parameters when executing this Choreo.
"""
def set_AccessToken(self, value):
"""
Set the value of the AccessToken input for this Choreo. ((optional, string) A valid access token retrieved during the OAuth process. This is required unless you provide the ClientID, ClientSecret, and RefreshToken to generate a new access token.)
"""
InputSet._set_input(self, 'AccessToken', value)
def set_CalendarID(self, value):
"""
Set the value of the CalendarID input for this Choreo. ((required, string) The unique ID for the calendar that contains the next event to retrieve.)
"""
InputSet._set_input(self, 'CalendarID', value)
def set_ClientID(self, value):
"""
Set the value of the ClientID input for this Choreo. ((conditional, string) The Client ID provided by Google. Required unless providing a valid AccessToken.)
"""
InputSet._set_input(self, 'ClientID', value)
def set_ClientSecret(self, value):
"""
Set the value of the ClientSecret input for this Choreo. ((conditional, string) The Client Secret provided by Google. Required unless providing a valid AccessToken.)
"""
InputSet._set_input(self, 'ClientSecret', value)
def set_RefreshToken(self, value):
"""
Set the value of the RefreshToken input for this Choreo. ((conditional, string) An OAuth Refresh Token used to generate a new access token when the original token is expired. Required unless providing a valid AccessToken.)
"""
InputSet._set_input(self, 'RefreshToken', value)
def set_ResponseFormat(self, value):
"""
Set the value of the ResponseFormat input for this Choreo. ((optional, string) The format that response should be in. Can be set to xml or json. Defaults to json.)
"""
InputSet._set_input(self, 'ResponseFormat', value)
class GetNextEventResultSet(ResultSet):
"""
A ResultSet with methods tailored to the values returned by the GetNextEvent Choreo.
The ResultSet object is used to retrieve the results of a Choreo execution.
"""
def getJSONFromString(self, str):
return json.loads(str)
def get_Response(self):
"""
Retrieve the value for the "Response" output from this Choreo execution. (The response from Google. Corresponds to the ResponseFormat input. Defaults to JSON.)
"""
return self._output.get('Response', None)
def get_NewAccessToken(self):
"""
Retrieve the value for the "NewAccessToken" output from this Choreo execution. ((string) Contains a new AccessToken when the RefreshToken is provided.)
"""
return self._output.get('NewAccessToken', None)
class GetNextEventChoreographyExecution(ChoreographyExecution):
def _make_result_set(self, response, path):
return GetNextEventResultSet(response, path)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
11490,
199,
3,
199,
3,
2372,
5765,
2390,
199,
3,
27940,
314,
2163,
1536,
7909,
1566,
315,
282,
4475,
11234,
4079,
641,
314,
1453,
4913,
436,
314,
2013,
11234,
1159,
7137,
4260,
14,
199,
3,
199,
3,
2018,
1015,
499,
14,
22,
199,
3,
199,
11490,
199,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
18747,
9773,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
6924,
1084,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
30751,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
18747,
9773,
11310,
199,
199,
646,
2022,
199,
199,
533,
2372,
5765,
2390,
8,
6209,
13322,
9773,
304,
339,
347,
636,
826,
721,
277,
12,
29072,
15056,
63,
1730,
304,
267,
408,
267,
2790,
282,
892,
1256,
402,
314,
2372,
5765,
2390,
18747,
14,
437,
377,
5633,
15056,
4434,
909,
12,
3035,
282,
1686,
267,
663,
402,
377,
5633,
15056,
6235,
12,
1471,
506,
6841,
14,
267,
408,
267,
18747,
9773,
855,
826,
721,
277,
12,
29072,
15056,
63,
1730,
12,
1994,
7424,
15,
13266,
15,
18688,
15,
20079,
2390,
358,
2378,
347,
892,
63,
1210,
63,
409,
8,
277,
304,
267,
372,
2372,
5765,
2390,
24478,
342,
339,
347,
485,
1875,
63,
1099,
63,
409,
8,
277,
12,
754,
12,
931,
304,
267,
372,
2372,
5765,
2390,
21722,
8,
1099,
12,
931,
9,
339,
347,
485,
1875,
63,
9416,
8,
277,
12,
2351,
12,
2146,
63,
344,
12,
931,
304,
267,
372,
2372,
5765,
2390,
6209,
13322,
9773,
11310,
8,
1730,
12,
2146,
63,
344,
12,
931,
9,
199,
199,
533,
2372,
5765,
2390,
24478,
8,
24478,
304,
272,
408,
272,
1626,
6924,
1084,
543,
3102,
5827,
367,
9176,
314,
4153,
370,
314,
2372,
5765,
2390,
272,
18747,
14,
710,
6924,
1084,
909,
365,
1202,
370,
4165,
1324,
2633,
1380,
14043,
642,
18747,
14,
272,
408,
272,
347,
663,
63,
3946,
3264,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
11003,
3264,
1324,
367,
642,
18747,
14,
3666,
4144,
12,
1059,
9,
437,
1686,
2879,
1526,
12396,
5309,
314,
11715,
2112,
14,
961,
365,
1415,
7444,
1265,
5647,
314,
6810,
998,
12,
6810,
13790,
12,
436,
30345,
3264,
370,
3550,
282,
892,
2879,
1526,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
3946,
3264,
297,
574,
9,
272,
347,
663,
63,
18688,
998,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
27779,
998,
1324,
367,
642,
18747,
14,
3666,
2427,
12,
1059,
9,
710,
3747,
2870,
367,
314,
11234,
626,
3509,
314,
2163,
1566,
370,
8044,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
18688,
998,
297,
574,
9,
272,
347,
663,
63,
3041,
998,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
6810,
998,
1324,
367,
642,
18747,
14,
3666,
14353,
12,
1059,
9,
710,
6810,
2870,
2741,
701,
4475,
14,
11105,
7444,
13070,
282,
1686,
11003,
3264,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
3041,
998,
297,
574,
9,
272,
347,
663,
63,
3041,
13790,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
6810,
13790,
1324,
367,
642,
18747,
14,
3666,
14353,
12,
1059,
9,
710,
6810,
23580,
2741,
701,
4475,
14,
11105,
7444,
13070,
282,
1686,
11003,
3264,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
3041,
13790,
297,
574,
9,
272,
347,
663,
63,
18730,
3264,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
30345,
3264,
1324,
367,
642,
18747,
14,
3666,
14353,
12,
1059,
9,
1626,
11715,
30345,
8767,
1202,
370,
3550,
282,
892,
2879,
1526,
1380,
314,
3379,
1526,
365,
14721,
14,
11105,
7444,
13070,
282,
1686,
11003,
3264,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
18730,
3264,
297,
574,
9,
272,
347,
663,
63,
2364,
3484,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
7232,
3484,
1324,
367,
642,
18747,
14,
3666,
4144,
12,
1059,
9,
710,
1475,
626,
1177,
1077,
506,
315,
14,
6855,
506,
663,
370,
2748,
503,
2022,
14,
7827,
370,
2022,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
2364,
3484,
297,
574,
9,
199,
199,
533,
2372,
5765,
2390,
21722,
8,
21722,
304,
272,
408,
272,
437,
30751,
543,
3102,
3052,
11737,
581,
370,
314,
1338,
2138,
701,
314,
2372,
5765,
2390,
18747,
14,
272,
710,
30751,
909,
365,
1202,
370,
8044,
314,
2058,
402,
282,
18747,
6451,
14,
272,
408,
1362,
1057,
272,
347,
664,
6243,
7671,
8,
277,
12,
620,
304,
267,
372,
2022,
14,
3640,
8,
495,
9,
2286,
347,
664,
63,
2364,
8,
277,
304,
267,
408,
267,
13939,
314,
574,
367,
314,
298,
2364,
2,
1072,
687,
642,
18747,
6451,
14,
334,
1918,
1177,
687,
4475,
14,
7499,
3853,
795,
370,
314,
7232,
3484,
1324,
14,
7827,
370,
4840,
4959,
267,
408,
267,
372,
291,
423,
1199,
14,
362,
360,
2364,
297,
488,
9,
272,
347,
664,
63,
4665,
3946,
3264,
8,
277,
304,
267,
408,
267,
13939,
314,
574,
367,
314,
298,
4665,
3946,
3264,
2,
1072,
687,
642,
18747,
6451,
14,
3666,
875,
9,
22493,
282,
892,
11003,
3264,
1380,
314,
30345,
3264,
365,
2741,
4959,
267,
408,
267,
372,
291,
423,
1199,
14,
362,
360,
4665,
3946,
3264,
297,
488,
9,
199,
199,
533,
2372,
5765,
2390,
6209,
13322,
9773,
11310,
8,
6209,
13322,
9773,
11310,
304,
2286,
347,
485,
1875,
63,
1099,
63,
409,
8,
277,
12,
1177,
12,
931,
304,
267,
372,
2372,
5765,
2390,
21722,
8,
1310,
12,
931,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
11490,
199,
3,
199,
3,
2372,
5765,
2390,
199,
3,
27940,
314,
2163,
1536,
7909,
1566,
315,
282,
4475,
11234,
4079,
641,
314,
1453,
4913,
436,
314,
2013,
11234,
1159,
7137,
4260,
14,
199,
3,
199,
3,
2018,
1015,
499,
14,
22,
199,
3,
199,
11490,
199,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
18747,
9773,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
6924,
1084,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
30751,
199,
504,
29072,
15056,
14,
1018,
14,
335,
720,
32157,
492,
18747,
9773,
11310,
199,
199,
646,
2022,
199,
199,
533,
2372,
5765,
2390,
8,
6209,
13322,
9773,
304,
339,
347,
636,
826,
721,
277,
12,
29072,
15056,
63,
1730,
304,
267,
408,
267,
2790,
282,
892,
1256,
402,
314,
2372,
5765,
2390,
18747,
14,
437,
377,
5633,
15056,
4434,
909,
12,
3035,
282,
1686,
267,
663,
402,
377,
5633,
15056,
6235,
12,
1471,
506,
6841,
14,
267,
408,
267,
18747,
9773,
855,
826,
721,
277,
12,
29072,
15056,
63,
1730,
12,
1994,
7424,
15,
13266,
15,
18688,
15,
20079,
2390,
358,
2378,
347,
892,
63,
1210,
63,
409,
8,
277,
304,
267,
372,
2372,
5765,
2390,
24478,
342,
339,
347,
485,
1875,
63,
1099,
63,
409,
8,
277,
12,
754,
12,
931,
304,
267,
372,
2372,
5765,
2390,
21722,
8,
1099,
12,
931,
9,
339,
347,
485,
1875,
63,
9416,
8,
277,
12,
2351,
12,
2146,
63,
344,
12,
931,
304,
267,
372,
2372,
5765,
2390,
6209,
13322,
9773,
11310,
8,
1730,
12,
2146,
63,
344,
12,
931,
9,
199,
199,
533,
2372,
5765,
2390,
24478,
8,
24478,
304,
272,
408,
272,
1626,
6924,
1084,
543,
3102,
5827,
367,
9176,
314,
4153,
370,
314,
2372,
5765,
2390,
272,
18747,
14,
710,
6924,
1084,
909,
365,
1202,
370,
4165,
1324,
2633,
1380,
14043,
642,
18747,
14,
272,
408,
272,
347,
663,
63,
3946,
3264,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
11003,
3264,
1324,
367,
642,
18747,
14,
3666,
4144,
12,
1059,
9,
437,
1686,
2879,
1526,
12396,
5309,
314,
11715,
2112,
14,
961,
365,
1415,
7444,
1265,
5647,
314,
6810,
998,
12,
6810,
13790,
12,
436,
30345,
3264,
370,
3550,
282,
892,
2879,
1526,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
3946,
3264,
297,
574,
9,
272,
347,
663,
63,
18688,
998,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
27779,
998,
1324,
367,
642,
18747,
14,
3666,
2427,
12,
1059,
9,
710,
3747,
2870,
367,
314,
11234,
626,
3509,
314,
2163,
1566,
370,
8044,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
18688,
998,
297,
574,
9,
272,
347,
663,
63,
3041,
998,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
6810,
998,
1324,
367,
642,
18747,
14,
3666,
14353,
12,
1059,
9,
710,
6810,
2870,
2741,
701,
4475,
14,
11105,
7444,
13070,
282,
1686,
11003,
3264,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
3041,
998,
297,
574,
9,
272,
347,
663,
63,
3041,
13790,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
6810,
13790,
1324,
367,
642,
18747,
14,
3666,
14353,
12,
1059,
9,
710,
6810,
23580,
2741,
701,
4475,
14,
11105,
7444,
13070,
282,
1686,
11003,
3264,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
3041,
13790,
297,
574,
9,
272,
347,
663,
63,
18730,
3264,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
30345,
3264,
1324,
367,
642,
18747,
14,
3666,
14353,
12,
1059,
9,
1626,
11715,
30345,
8767,
1202,
370,
3550,
282,
892,
2879,
1526,
1380,
314,
3379,
1526,
365,
14721,
14,
11105,
7444,
13070,
282,
1686,
11003,
3264,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
18730,
3264,
297,
574,
9,
272,
347,
663,
63,
2364,
3484,
8,
277,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
314,
7232,
3484,
1324,
367,
642,
18747,
14,
3666,
4144,
12,
1059,
9,
710,
1475,
626,
1177,
1077,
506,
315,
14,
6855,
506,
663,
370,
2748,
503,
2022,
14,
7827,
370,
2022,
4959,
267,
408,
267,
6924,
1084,
423,
409,
63,
1210,
8,
277,
12,
283,
2364,
3484,
297,
574,
9,
199,
199,
533,
2372,
5765,
2390,
21722,
8,
21722,
304,
272,
408,
272,
437,
30751,
543,
3102,
3052,
11737,
581,
370,
314,
1338,
2138,
701,
314,
2372,
5765,
2390,
18747,
14,
272,
710,
30751,
909,
365,
1202,
370,
8044,
314,
2058,
402,
282,
18747,
6451,
14,
272,
408,
1362,
1057,
272,
347,
664,
6243,
7671,
8,
277,
12,
620,
304,
267,
372,
2022,
14,
3640,
8,
495,
9,
2286,
347,
664,
63,
2364,
8,
277,
304,
267,
408,
267,
13939,
314,
574,
367,
314,
298,
2364,
2,
1072,
687,
642,
18747,
6451,
14,
334,
1918,
1177,
687,
4475,
14,
7499,
3853,
795,
370,
314,
7232,
3484,
1324,
14,
7827,
370,
4840,
4959,
267,
408,
267,
372,
291,
423,
1199,
14,
362,
360,
2364,
297,
488,
9,
272,
347,
664,
63,
4665,
3946,
3264,
8,
277,
304,
267,
408,
267,
13939,
314,
574,
367,
314,
298,
4665,
3946,
3264,
2,
1072,
687,
642,
18747,
6451,
14,
3666,
875,
9,
22493,
282,
892,
11003,
3264,
1380,
314,
30345,
3264,
365,
2741,
4959,
267,
408,
267,
372,
291,
423,
1199,
14,
362,
360,
4665,
3946,
3264,
297,
488,
9,
199,
199,
533,
2372,
5765,
2390,
6209,
13322,
9773,
11310,
8,
6209,
13322,
9773,
11310,
304,
2286,
347,
485,
1875,
63,
1099,
63,
409,
8,
277,
12,
1177,
12,
931,
304,
267,
372,
2372,
5765,
2390,
21722,
8,
1310,
12,
931,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mancoast/CPythonPyc_test
|
cpython/230_test_userlist.py
|
9
|
6949
|
# Check every path through every method of UserList
from UserList import UserList
import unittest, test.test_support
class UserListTest(unittest.TestCase):
def test_constructors(self):
l0 = []
l1 = [0]
l2 = [0, 1]
u = UserList()
u0 = UserList(l0)
u1 = UserList(l1)
u2 = UserList(l2)
uu = UserList(u)
uu0 = UserList(u0)
uu1 = UserList(u1)
uu2 = UserList(u2)
v = UserList(tuple(u))
class OtherList:
def __init__(self, initlist):
self.__data = initlist
def __len__(self):
return len(self.__data)
def __getitem__(self, i):
return self.__data[i]
v0 = UserList(OtherList(u0))
vv = UserList("this is also a sequence")
def test_repr(self):
l0 = []
l2 = [0, 1, 2]
u0 = UserList(l0)
u2 = UserList(l2)
self.assertEqual(str(u0), str(l0))
self.assertEqual(repr(u0), repr(l0))
self.assertEqual(`u2`, `l2`)
def test_cmplen(self):
l0 = []
l1 = [0]
l2 = [0, 1]
# Test constructors
u = UserList()
u0 = UserList(l0)
u1 = UserList(l1)
u2 = UserList(l2)
uu = UserList(u)
uu0 = UserList(u0)
uu1 = UserList(u1)
uu2 = UserList(u2)
def mycmp(x, y):
r = cmp(x, y)
if r < 0: return -1
if r > 0: return 1
return r
all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2]
for a in all:
for b in all:
self.assertEqual(mycmp(a, b), mycmp(len(a), len(b)))
self.assert_(u0 <= u2)
self.assert_(u2 >= u0)
def test_getitem(self):
u = UserList([0, 1, 2])
for i in xrange(len(u)):
self.assertEqual(u[i], i)
def test_setitem(self):
u = UserList([0, 1])
u[0] = 0
u[1] = 100
self.assertEqual(u, [0, 100])
self.assertRaises(IndexError, u.__setitem__, 2, 200)
def test_delitem(self):
u = UserList([0, 1])
del u[1]
del u[0]
self.assertRaises(IndexError, u.__delitem__, 0)
def test_getslice(self):
l = [0, 1]
u = UserList(l)
for i in xrange(-3, 4):
self.assertEqual(u[:i], l[:i])
self.assertEqual(u[i:], l[i:])
for j in xrange(-3, 4):
self.assertEqual(u[i:j], l[i:j])
def test_setslice(self):
l = [0, 1]
u = UserList(l)
# Test __setslice__
for i in range(-3, 4):
u[:i] = l[:i]
self.assertEqual(u, l)
u2 = u[:]
u2[:i] = u[:i]
self.assertEqual(u2, u)
u[i:] = l[i:]
self.assertEqual(u, l)
u2 = u[:]
u2[i:] = u[i:]
self.assertEqual(u2, u)
for j in range(-3, 4):
u[i:j] = l[i:j]
self.assertEqual(u, l)
u2 = u[:]
u2[i:j] = u[i:j]
self.assertEqual(u2, u)
uu2 = u2[:]
uu2[:0] = [-2, -1]
self.assertEqual(uu2, [-2, -1, 0, 1])
uu2[0:] = []
self.assertEqual(uu2, [])
def test_contains(self):
u = UserList([0, 1, 2])
for i in u:
self.assert_(i in u)
for i in min(u)-1, max(u)+1:
self.assert_(i not in u)
def test_delslice(self):
u = UserList([0, 1])
del u[1:2]
del u[0:1]
self.assertEqual(u, [])
u = UserList([0, 1])
del u[1:]
del u[:1]
self.assertEqual(u, [])
def test_addmul(self):
u1 = UserList([0])
u2 = UserList([0, 1])
self.assertEqual(u1, u1 + [])
self.assertEqual(u1, [] + u1)
self.assertEqual(u1 + [1], u2)
self.assertEqual([-1] + u1, [-1, 0])
self.assertEqual(u2, u2*1)
self.assertEqual(u2, 1*u2)
self.assertEqual(u2+u2, u2*2)
self.assertEqual(u2+u2, 2*u2)
self.assertEqual(u2+u2+u2, u2*3)
self.assertEqual(u2+u2+u2, 3*u2)
def test_add_specials(self):
u = UserList("spam")
u2 = u + "eggs"
self.assertEqual(u2, list("spameggs"))
def test_radd_specials(self):
u = UserList("eggs")
u2 = "spam" + u
self.assertEqual(u2, list("spameggs"))
u2 = u.__radd__(UserList("spam"))
self.assertEqual(u2, list("spameggs"))
def test_append(self):
u = UserList((0, ))
u.append(1)
self.assertEqual(u, [0, 1])
def test_insert(self):
u = UserList((0, 1))
u.insert(0, -1)
self.assertEqual(u, [-1, 0, 1])
def test_pop(self):
u = UserList((-1, 0, 1))
u.pop()
self.assertEqual(u, [-1, 0])
u.pop(0)
self.assertEqual(u, [0])
def test_remove(self):
u = UserList((0, 1))
u.remove(1)
self.assertEqual(u, [0])
def test_count(self):
u = UserList((0, 1))*3
self.assertEqual(u.count(0), 3)
self.assertEqual(u.count(1), 3)
self.assertEqual(u.count(2), 0)
def test_index(self):
u = UserList((0, 1))
self.assertEqual(u.index(0), 0)
self.assertEqual(u.index(1), 1)
self.assertRaises(ValueError, u.index, 2)
u = UserList([-2,-1,0,0,1,2])
self.assertEqual(u.count(0), 2)
self.assertEqual(u.index(0), 2)
self.assertEqual(u.index(0,2), 2)
self.assertEqual(u.index(-2,-10), 0)
self.assertEqual(u.index(0,3), 3)
self.assertEqual(u.index(0,3,4), 3)
self.assertRaises(ValueError, u.index, 2,0,-10)
def test_reverse(self):
u = UserList((0, 1))
u2 = u[:]
u.reverse()
self.assertEqual(u, [1, 0])
u.reverse()
self.assertEqual(u, u2)
def test_sort(self):
u = UserList([1, 0])
u.sort()
self.assertEqual(u, [0, 1])
def test_slice(self):
u = UserList("spam")
u[:2] = "h"
self.assertEqual(u, list("ham"))
def test_iadd(self):
u = UserList((0, 1))
u += [0, 1]
self.assertEqual(u, [0, 1, 0, 1])
u += UserList([0, 1])
self.assertEqual(u, [0, 1, 0, 1, 0, 1])
u = UserList("spam")
u += "eggs"
self.assertEqual(u, list("spameggs"))
def test_extend(self):
u1 = UserList((0, ))
u2 = UserList((0, 1))
u = u1[:]
u.extend(u2)
self.assertEqual(u, u1 + u2)
u = UserList("spam")
u.extend("eggs")
self.assertEqual(u, list("spameggs"))
def test_imul(self):
u = UserList((0, 1))
u *= 3
self.assertEqual(u, [0, 1, 0, 1, 0, 1])
def test_main():
test.test_support.run_unittest(UserListTest)
if __name__ == "__main__":
test_main()
|
gpl-3.0
|
[
3,
2670,
4036,
931,
4012,
4036,
1083,
402,
28639,
199,
199,
504,
28639,
492,
28639,
199,
646,
2882,
12,
511,
14,
396,
63,
4058,
199,
199,
533,
28639,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1880,
83,
8,
277,
304,
267,
634,
16,
275,
942,
267,
634,
17,
275,
359,
16,
61,
267,
634,
18,
275,
359,
16,
12,
413,
61,
398,
399,
275,
28639,
342,
267,
399,
16,
275,
28639,
8,
76,
16,
9,
267,
399,
17,
275,
28639,
8,
76,
17,
9,
267,
399,
18,
275,
28639,
8,
76,
18,
9,
398,
399,
85,
275,
28639,
8,
85,
9,
267,
399,
85,
16,
275,
28639,
8,
85,
16,
9,
267,
399,
85,
17,
275,
28639,
8,
85,
17,
9,
267,
399,
85,
18,
275,
28639,
8,
85,
18,
9,
398,
373,
275,
28639,
8,
2960,
8,
85,
430,
267,
1021,
5439,
1296,
26,
288,
347,
636,
826,
721,
277,
12,
4205,
513,
304,
355,
291,
855,
576,
275,
4205,
513,
288,
347,
636,
552,
721,
277,
304,
355,
372,
822,
8,
277,
855,
576,
9,
288,
347,
636,
6095,
721,
277,
12,
284,
304,
355,
372,
291,
855,
576,
59,
73,
61,
267,
373,
16,
275,
28639,
8,
8632,
1296,
8,
85,
16,
430,
267,
373,
86,
275,
28639,
480,
3749,
365,
2597,
282,
3414,
531,
339,
347,
511,
63,
2722,
8,
277,
304,
267,
634,
16,
275,
942,
267,
634,
18,
275,
359,
16,
12,
413,
12,
499,
61,
267,
399,
16,
275,
28639,
8,
76,
16,
9,
267,
399,
18,
275,
28639,
8,
76,
18,
9,
398,
291,
14,
629,
8,
495,
8,
85,
16,
395,
620,
8,
76,
16,
430,
267,
291,
14,
629,
8,
2722,
8,
85,
16,
395,
4700,
8,
76,
16,
430,
267,
291,
14,
629,
8,
64,
85,
18,
3559,
658,
76,
18,
10522,
339,
347,
511,
63,
5730,
552,
8,
277,
304,
267,
634,
16,
275,
942,
267,
634,
17,
275,
359,
16,
61,
267,
634,
18,
275,
359,
16,
12,
413,
61,
398,
327,
1379,
31604,
398,
399,
275,
28639,
342,
267,
399,
16,
275,
28639,
8,
76,
16,
9,
267,
399,
17,
275,
28639,
8,
76,
17,
9,
267,
399,
18,
275,
28639,
8,
76,
18,
9,
398,
399,
85,
275,
28639,
8,
85,
9,
267,
399,
85,
16,
275,
28639,
8,
85,
16,
9,
267,
399,
85,
17,
275,
28639,
8,
85,
17,
9,
267,
399,
85,
18,
275,
28639,
8,
85,
18,
9,
398,
347,
3002,
5730,
8,
88,
12,
612,
304,
288,
519,
275,
10467,
8,
88,
12,
612,
9,
288,
340,
519,
665,
378,
26,
372,
446,
17,
288,
340,
519,
690,
378,
26,
372,
413,
288,
372,
519,
398,
1006,
275,
359,
76,
16,
12,
634,
17,
12,
634,
18,
12,
399,
12,
399,
16,
12,
399,
17,
12,
399,
18,
12,
399,
85,
12,
399,
85,
16,
12,
399,
85,
17,
12,
399,
85,
18,
61,
267,
367,
282,
315,
1006,
26,
288,
367,
330,
315,
1006,
26,
355,
291,
14,
629,
8,
1662,
5730,
8,
65,
12,
330,
395,
3002,
5730,
8,
552,
8,
65,
395,
822,
8,
66,
1724,
398,
291,
14,
479,
2531,
85,
16,
2695,
399,
18,
9,
267,
291,
14,
479,
2531,
85,
18,
2356,
399,
16,
9,
339,
347,
511,
63,
6095,
8,
277,
304,
267,
399,
275,
28639,
779,
16,
12,
413,
12,
499,
566,
267,
367,
284,
315,
4945,
8,
552,
8,
85,
2298,
288,
291,
14,
629,
8,
85,
59,
73,
467,
284,
9,
339,
347,
511,
63,
8617,
8,
277,
304,
267,
399,
275,
28639,
779,
16,
12,
413,
566,
267,
399,
59,
16,
61,
275,
378,
267,
399,
59,
17,
61,
275,
2948,
267,
291,
14,
629,
8,
85,
12,
359,
16,
12,
2948,
566,
267,
291,
14,
1855,
8,
12129,
12,
399,
855,
8617,
3108,
499,
12,
1926,
9,
339,
347,
511,
63,
13228,
8,
277,
304,
267,
399,
275,
28639,
779,
16,
12,
413,
566,
267,
2150,
399,
59,
17,
61,
267,
2150,
399,
59,
16,
61,
267,
291,
14,
1855,
8,
12129,
12,
399,
855,
13228,
3108,
378,
9,
339,
347,
511,
63,
32131,
8,
277,
304,
267,
634,
275,
359,
16,
12,
413,
61,
267,
399,
275,
28639,
8,
76,
9,
267,
367,
284,
315,
4945,
2801,
19,
12,
841,
304,
288,
291,
14,
629,
8,
85,
1491,
73,
467,
634,
1491,
73,
566,
288,
291,
14,
629,
8,
85,
59,
73,
8429,
634,
59,
73,
5728,
288,
367,
1335,
315,
4945,
2801,
19,
12,
841,
304,
355,
291,
14,
629,
8,
85,
59,
73,
26,
74,
467,
634,
59,
73,
26,
74,
566,
339,
347,
511,
63,
2193,
3037,
8,
277,
304,
267,
634,
275,
359,
16,
12,
413,
61,
267,
399,
275,
28639,
8,
76,
9,
398,
327,
1379,
636,
2193,
3037,
363,
267,
367,
284,
315,
1425,
2801,
19,
12,
841,
304,
288,
399,
1491,
73,
61,
275,
634,
1491,
73,
61,
288,
291,
14,
629,
8,
85,
12,
634,
9,
288,
399,
18,
275,
399,
5873,
288,
399,
18,
1491,
73,
61,
275,
399,
1491,
73,
61,
288,
291,
14,
629,
8,
85,
18,
12,
399,
9,
288,
399,
59,
73,
2938,
275,
634,
59,
73,
2938,
288,
291,
14,
629,
8,
85,
12,
634,
9,
288,
399,
18,
275,
399,
5873,
288,
399,
18,
59,
73,
2938,
275,
399,
59,
73,
2938,
288,
291,
14,
629,
8,
85,
18,
12,
399,
9,
288,
367,
1335,
315,
1425,
2801,
19,
12,
841,
304,
355,
399,
59,
73,
26,
74,
61,
275,
634,
59,
73,
26,
74,
61,
355,
291,
14,
629,
8,
85,
12,
634,
9,
355,
399,
18,
275,
399,
5873,
355,
399,
18,
59,
73,
26,
74,
61,
275,
399,
59,
73,
26,
74,
61,
355,
291,
14,
629,
8,
85,
18,
12,
399,
9,
398,
399,
85,
18,
275,
399,
18,
5873,
267,
399,
85,
18,
1491,
16,
61,
275,
5243,
18,
12,
446,
17,
61,
267,
291,
14,
629,
8,
17031,
18,
12,
5243,
18,
12,
446,
17,
12,
378,
12,
413,
566,
267,
399,
85,
18,
59,
16,
2938,
275,
942,
267,
291,
14,
629,
8,
17031,
18,
12
] |
[
2670,
4036,
931,
4012,
4036,
1083,
402,
28639,
199,
199,
504,
28639,
492,
28639,
199,
646,
2882,
12,
511,
14,
396,
63,
4058,
199,
199,
533,
28639,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1880,
83,
8,
277,
304,
267,
634,
16,
275,
942,
267,
634,
17,
275,
359,
16,
61,
267,
634,
18,
275,
359,
16,
12,
413,
61,
398,
399,
275,
28639,
342,
267,
399,
16,
275,
28639,
8,
76,
16,
9,
267,
399,
17,
275,
28639,
8,
76,
17,
9,
267,
399,
18,
275,
28639,
8,
76,
18,
9,
398,
399,
85,
275,
28639,
8,
85,
9,
267,
399,
85,
16,
275,
28639,
8,
85,
16,
9,
267,
399,
85,
17,
275,
28639,
8,
85,
17,
9,
267,
399,
85,
18,
275,
28639,
8,
85,
18,
9,
398,
373,
275,
28639,
8,
2960,
8,
85,
430,
267,
1021,
5439,
1296,
26,
288,
347,
636,
826,
721,
277,
12,
4205,
513,
304,
355,
291,
855,
576,
275,
4205,
513,
288,
347,
636,
552,
721,
277,
304,
355,
372,
822,
8,
277,
855,
576,
9,
288,
347,
636,
6095,
721,
277,
12,
284,
304,
355,
372,
291,
855,
576,
59,
73,
61,
267,
373,
16,
275,
28639,
8,
8632,
1296,
8,
85,
16,
430,
267,
373,
86,
275,
28639,
480,
3749,
365,
2597,
282,
3414,
531,
339,
347,
511,
63,
2722,
8,
277,
304,
267,
634,
16,
275,
942,
267,
634,
18,
275,
359,
16,
12,
413,
12,
499,
61,
267,
399,
16,
275,
28639,
8,
76,
16,
9,
267,
399,
18,
275,
28639,
8,
76,
18,
9,
398,
291,
14,
629,
8,
495,
8,
85,
16,
395,
620,
8,
76,
16,
430,
267,
291,
14,
629,
8,
2722,
8,
85,
16,
395,
4700,
8,
76,
16,
430,
267,
291,
14,
629,
8,
64,
85,
18,
3559,
658,
76,
18,
10522,
339,
347,
511,
63,
5730,
552,
8,
277,
304,
267,
634,
16,
275,
942,
267,
634,
17,
275,
359,
16,
61,
267,
634,
18,
275,
359,
16,
12,
413,
61,
398,
327,
1379,
31604,
398,
399,
275,
28639,
342,
267,
399,
16,
275,
28639,
8,
76,
16,
9,
267,
399,
17,
275,
28639,
8,
76,
17,
9,
267,
399,
18,
275,
28639,
8,
76,
18,
9,
398,
399,
85,
275,
28639,
8,
85,
9,
267,
399,
85,
16,
275,
28639,
8,
85,
16,
9,
267,
399,
85,
17,
275,
28639,
8,
85,
17,
9,
267,
399,
85,
18,
275,
28639,
8,
85,
18,
9,
398,
347,
3002,
5730,
8,
88,
12,
612,
304,
288,
519,
275,
10467,
8,
88,
12,
612,
9,
288,
340,
519,
665,
378,
26,
372,
446,
17,
288,
340,
519,
690,
378,
26,
372,
413,
288,
372,
519,
398,
1006,
275,
359,
76,
16,
12,
634,
17,
12,
634,
18,
12,
399,
12,
399,
16,
12,
399,
17,
12,
399,
18,
12,
399,
85,
12,
399,
85,
16,
12,
399,
85,
17,
12,
399,
85,
18,
61,
267,
367,
282,
315,
1006,
26,
288,
367,
330,
315,
1006,
26,
355,
291,
14,
629,
8,
1662,
5730,
8,
65,
12,
330,
395,
3002,
5730,
8,
552,
8,
65,
395,
822,
8,
66,
1724,
398,
291,
14,
479,
2531,
85,
16,
2695,
399,
18,
9,
267,
291,
14,
479,
2531,
85,
18,
2356,
399,
16,
9,
339,
347,
511,
63,
6095,
8,
277,
304,
267,
399,
275,
28639,
779,
16,
12,
413,
12,
499,
566,
267,
367,
284,
315,
4945,
8,
552,
8,
85,
2298,
288,
291,
14,
629,
8,
85,
59,
73,
467,
284,
9,
339,
347,
511,
63,
8617,
8,
277,
304,
267,
399,
275,
28639,
779,
16,
12,
413,
566,
267,
399,
59,
16,
61,
275,
378,
267,
399,
59,
17,
61,
275,
2948,
267,
291,
14,
629,
8,
85,
12,
359,
16,
12,
2948,
566,
267,
291,
14,
1855,
8,
12129,
12,
399,
855,
8617,
3108,
499,
12,
1926,
9,
339,
347,
511,
63,
13228,
8,
277,
304,
267,
399,
275,
28639,
779,
16,
12,
413,
566,
267,
2150,
399,
59,
17,
61,
267,
2150,
399,
59,
16,
61,
267,
291,
14,
1855,
8,
12129,
12,
399,
855,
13228,
3108,
378,
9,
339,
347,
511,
63,
32131,
8,
277,
304,
267,
634,
275,
359,
16,
12,
413,
61,
267,
399,
275,
28639,
8,
76,
9,
267,
367,
284,
315,
4945,
2801,
19,
12,
841,
304,
288,
291,
14,
629,
8,
85,
1491,
73,
467,
634,
1491,
73,
566,
288,
291,
14,
629,
8,
85,
59,
73,
8429,
634,
59,
73,
5728,
288,
367,
1335,
315,
4945,
2801,
19,
12,
841,
304,
355,
291,
14,
629,
8,
85,
59,
73,
26,
74,
467,
634,
59,
73,
26,
74,
566,
339,
347,
511,
63,
2193,
3037,
8,
277,
304,
267,
634,
275,
359,
16,
12,
413,
61,
267,
399,
275,
28639,
8,
76,
9,
398,
327,
1379,
636,
2193,
3037,
363,
267,
367,
284,
315,
1425,
2801,
19,
12,
841,
304,
288,
399,
1491,
73,
61,
275,
634,
1491,
73,
61,
288,
291,
14,
629,
8,
85,
12,
634,
9,
288,
399,
18,
275,
399,
5873,
288,
399,
18,
1491,
73,
61,
275,
399,
1491,
73,
61,
288,
291,
14,
629,
8,
85,
18,
12,
399,
9,
288,
399,
59,
73,
2938,
275,
634,
59,
73,
2938,
288,
291,
14,
629,
8,
85,
12,
634,
9,
288,
399,
18,
275,
399,
5873,
288,
399,
18,
59,
73,
2938,
275,
399,
59,
73,
2938,
288,
291,
14,
629,
8,
85,
18,
12,
399,
9,
288,
367,
1335,
315,
1425,
2801,
19,
12,
841,
304,
355,
399,
59,
73,
26,
74,
61,
275,
634,
59,
73,
26,
74,
61,
355,
291,
14,
629,
8,
85,
12,
634,
9,
355,
399,
18,
275,
399,
5873,
355,
399,
18,
59,
73,
26,
74,
61,
275,
399,
59,
73,
26,
74,
61,
355,
291,
14,
629,
8,
85,
18,
12,
399,
9,
398,
399,
85,
18,
275,
399,
18,
5873,
267,
399,
85,
18,
1491,
16,
61,
275,
5243,
18,
12,
446,
17,
61,
267,
291,
14,
629,
8,
17031,
18,
12,
5243,
18,
12,
446,
17,
12,
378,
12,
413,
566,
267,
399,
85,
18,
59,
16,
2938,
275,
942,
267,
291,
14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
1,
1,
1,
1,
1,
1,
1,
1
] |
thaumos/ansible
|
test/units/modules/network/fortimanager/test_fmgr_fwobj_vip.py
|
39
|
24644
|
# Copyright 2018 Fortinet, Inc.
#
# 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 Ansible. If not, see <https://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler
import pytest
try:
from ansible.modules.network.fortimanager import fmgr_fwobj_vip
except ImportError:
pytest.skip("Could not load required modules for testing", allow_module_level=True)
def load_fixtures():
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') + "/{filename}.json".format(
filename=os.path.splitext(os.path.basename(__file__))[0])
try:
with open(fixture_path, "r") as fixture_file:
fixture_data = json.load(fixture_file)
except IOError:
return []
return [fixture_data]
@pytest.fixture(autouse=True)
def module_mock(mocker):
connection_class_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule')
return connection_class_mock
@pytest.fixture(autouse=True)
def connection_mock(mocker):
connection_class_mock = mocker.patch('ansible.modules.network.fortimanager.fmgr_fwobj_vip.Connection')
return connection_class_mock
@pytest.fixture(scope="function", params=load_fixtures())
def fixture_data(request):
func_name = request.function.__name__.replace("test_", "")
return request.param.get(func_name, None)
fmg_instance = FortiManagerHandler(connection_mock, module_mock)
def test_fmgr_firewall_vip_modify(fixture_data, mocker):
mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request",
side_effect=fixture_data)
# Fixture sets used:###########################
##################################################
# comment: Created by Ansible
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# ssl-hpkp: None
# mapped-addr: None
# ssl-client-session-state-timeout: None
# src-filter: None
# server-type: None
# ssl-hpkp-include-subdomains: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# mappedip: 10.7.220.25
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: tcp
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# extaddr: None
# ssl-client-renegotiation: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# weblogic-server: None
# http-cookie-share: None
# color: 17
# ssl-mode: None
# portforward: enable
# http-multiplex: None
# http-cookie-generation: None
# ssl-client-fallback: None
# extip: 82.72.192.185
# extintf: any
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# adom: ansible
# ssl-client-session-state-max: None
# http-ip-header: None
# http-ip-header-name: None
# ssl-certificate: None
# ssl-hsts: None
# arp-reply: None
# ssl-hsts-include-subdomains: None
# ssl-min-version: None
# ldb-method: None
# ssl-server-session-state-timeout: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: 443
# name: Basic PNAT Map Port 10443
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# outlook-web-access: None
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-server-max-version: None
# ssl-hpkp-report-uri: None
# http-cookie-domain-from-host: None
# ssl-algorithm: None
# gratuitous-arp-interval: None
# extport: 10443
# max-embryonic-connections: None
# mode: set
# http-cookie-path: None
# ssl-pfs: None
# ssl-server-algorithm: None
##################################################
##################################################
# comment: Created by Ansible
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# ssl-hpkp: None
# ssl-hsts-include-subdomains: None
# mapped-addr: None
# src-filter: None
# server-type: None
# mode: set
# ssl-hpkp-include-subdomains: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# mappedip: 3.3.3.0/24, 4.0.0.0/24
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# ssl-client-renegotiation: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# adom: ansible
# http-cookie-share: None
# ssl-server-session-state-timeout: None
# color: 12
# ssl-mode: None
# portforward: None
# http-cookie-generation: None
# max-embryonic-connections: None
# ssl-client-fallback: None
# ssl-hpkp-report-uri: None
# extip: 192.168.0.1-192.168.0.100
# extintf: dmz
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# http-ip-header-name: None
# weblogic-server: None
# ssl-client-session-state-max: None
# http-ip-header: None
# ssl-hsts: None
# arp-reply: None
# extaddr: None
# ssl-min-version: None
# ldb-method: None
# ssl-certificate: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# outlook-web-access: None
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# name: Basic DNS Translation
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-pfs: None
# ssl-server-max-version: None
# ssl-client-session-state-timeout: None
# http-cookie-domain-from-host: None
# extport: None
# ssl-server-algorithm: None
# gratuitous-arp-interval: None
# http-cookie-path: None
# ssl-algorithm: None
# http-multiplex: None
##################################################
##################################################
# comment: Created by Ansible
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# ssl-hpkp: None
# mapped-addr: google-play
# ssl-client-session-state-timeout: None
# src-filter: None
# ldb-method: None
# server-type: None
# ssl-hpkp-include-subdomains: None
# ssl-client-renegotiation: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# mappedip: None
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# extaddr: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# weblogic-server: None
# http-cookie-share: None
# color: 5
# ssl-mode: None
# portforward: None
# http-cookie-generation: None
# ssl-client-fallback: None
# extip: None
# extintf: None
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# adom: ansible
# ssl-client-session-state-max: None
# http-ip-header: None
# http-ip-header-name: None
# ssl-certificate: None
# ssl-hsts: None
# arp-reply: None
# extport: None
# ssl-min-version: None
# ssl-server-algorithm: None
# ssl-server-session-state-timeout: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# name: Basic FQDN Translation
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# outlook-web-access: None
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-server-max-version: None
# ssl-hpkp-report-uri: None
# http-cookie-domain-from-host: None
# ssl-algorithm: None
# gratuitous-arp-interval: None
# ssl-hsts-include-subdomains: None
# max-embryonic-connections: None
# mode: set
# http-cookie-path: None
# ssl-pfs: None
# http-multiplex: None
##################################################
##################################################
# comment: Created by Ansible
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# ssl-hpkp: None
# mapped-addr: None
# src-filter: None
# server-type: None
# mode: set
# ssl-hpkp-include-subdomains: None
# extport: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# mappedip: 10.7.220.25
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# ssl-server-algorithm: None
# extaddr: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# adom: ansible
# http-cookie-share: None
# ssl-server-session-state-timeout: None
# color: 17
# ssl-mode: None
# portforward: None
# http-cookie-generation: None
# max-embryonic-connections: None
# ssl-client-fallback: None
# ssl-hpkp-report-uri: None
# extip: 82.72.192.185
# extintf: any
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# http-ip-header-name: None
# weblogic-server: None
# ssl-client-session-state-max: None
# http-ip-header: None
# ssl-hsts: None
# arp-reply: None
# ssl-client-renegotiation: None
# ssl-min-version: None
# ldb-method: None
# ssl-certificate: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# outlook-web-access: None
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# name: Basic StaticNAT Map
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-pfs: None
# ssl-client-session-state-timeout: None
# http-cookie-domain-from-host: None
# ssl-hsts-include-subdomains: None
# ssl-server-max-version: None
# gratuitous-arp-interval: None
# http-cookie-path: None
# ssl-algorithm: None
# http-multiplex: None
##################################################
##################################################
# comment: Created by Ansible
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# ssl-hpkp: None
# mapped-addr: None
# ssl-client-session-state-timeout: None
# src-filter: None
# server-type: None
# ssl-hpkp-include-subdomains: None
# ssl-client-renegotiation: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# mappedip: 10.7.220.25
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: tcp
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# extaddr: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# weblogic-server: None
# http-cookie-share: None
# color: 17
# ssl-mode: None
# portforward: enable
# http-cookie-generation: None
# ssl-client-fallback: None
# extip: 82.72.192.185
# extintf: any
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# adom: ansible
# ssl-client-session-state-max: None
# http-ip-header: None
# http-ip-header-name: None
# ssl-min-version: None
# ssl-certificate: None
# ssl-hsts: None
# arp-reply: None
# ssl-hsts-include-subdomains: None
# http-multiplex: None
# ldb-method: None
# ssl-server-session-state-timeout: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: 443
# name: Basic PNAT Map Port 10443
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# outlook-web-access: None
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-server-max-version: None
# ssl-hpkp-report-uri: None
# http-cookie-domain-from-host: None
# ssl-algorithm: None
# gratuitous-arp-interval: None
# extport: 10443
# max-embryonic-connections: None
# mode: set
# http-cookie-path: None
# ssl-pfs: None
# ssl-server-algorithm: None
##################################################
##################################################
# comment: None
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# ssl-hpkp: None
# ssl-hsts-include-subdomains: None
# mapped-addr: None
# src-filter: None
# server-type: None
# mode: delete
# ssl-hpkp-include-subdomains: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# mappedip: None
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# extaddr: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# adom: ansible
# http-cookie-share: None
# ssl-server-session-state-timeout: None
# color: None
# ssl-mode: None
# portforward: None
# http-cookie-generation: None
# max-embryonic-connections: None
# ssl-client-fallback: None
# ssl-hpkp-report-uri: None
# extip: None
# extintf: None
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# http-ip-header-name: None
# weblogic-server: None
# ssl-client-session-state-max: None
# http-ip-header: None
# ssl-hsts: None
# arp-reply: None
# ssl-client-renegotiation: None
# http-multiplex: None
# ldb-method: None
# ssl-certificate: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# outlook-web-access: None
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# name: Basic PNAT Map Port 10443
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-pfs: None
# ssl-server-max-version: None
# ssl-client-session-state-timeout: None
# http-cookie-domain-from-host: None
# extport: None
# ssl-server-algorithm: None
# gratuitous-arp-interval: None
# http-cookie-path: None
# ssl-algorithm: None
# ssl-min-version: None
##################################################
##################################################
# comment: None
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# mappedip: None
# mapped-addr: None
# ssl-client-session-state-timeout: None
# src-filter: None
# ldb-method: None
# server-type: None
# ssl-hpkp-include-subdomains: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# ssl-hpkp: None
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# extaddr: None
# ssl-client-renegotiation: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# weblogic-server: None
# http-cookie-share: None
# color: None
# ssl-mode: None
# portforward: None
# http-cookie-generation: None
# ssl-client-fallback: None
# extip: None
# extintf: None
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# adom: ansible
# ssl-client-session-state-max: None
# http-ip-header: None
# http-ip-header-name: None
# ssl-certificate: None
# ssl-hsts: None
# arp-reply: None
# extport: None
# http-multiplex: None
# ssl-server-algorithm: None
# ssl-server-session-state-timeout: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# name: Basic StaticNAT Map
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-hpkp-primary: None
# outlook-web-access: None
# ssl-server-session-state-type: None
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-server-max-version: None
# ssl-hpkp-report-uri: None
# http-cookie-domain-from-host: None
# ssl-algorithm: None
# gratuitous-arp-interval: None
# ssl-hsts-include-subdomains: None
# max-embryonic-connections: None
# mode: delete
# http-cookie-path: None
# ssl-pfs: None
# ssl-min-version: None
##################################################
##################################################
# comment: None
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# mappedip: None
# mapped-addr: None
# src-filter: None
# server-type: None
# mode: delete
# ssl-hpkp-include-subdomains: None
# extport: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# ssl-hpkp: None
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# ssl-server-algorithm: None
# ssl-client-renegotiation: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# adom: ansible
# http-cookie-share: None
# ssl-server-session-state-timeout: None
# color: None
# ssl-mode: None
# portforward: None
# http-multiplex: None
# http-cookie-generation: None
# max-embryonic-connections: None
# ssl-client-fallback: None
# ssl-hpkp-report-uri: None
# extip: None
# extintf: None
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# http-ip-header-name: None
# weblogic-server: None
# ssl-client-session-state-max: None
# http-ip-header: None
# ssl-hsts: None
# arp-reply: None
# extaddr: None
# ssl-hpkp-primary: None
# ldb-method: None
# ssl-certificate: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# outlook-web-access: None
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-client-session-state-type: None
# name: Basic DNS Translation
# ssl-server-session-state-type: None
# ssl-http-match-host: None
# ssl-pfs: None
# ssl-client-session-state-timeout: None
# http-cookie-domain-from-host: None
# ssl-hsts-include-subdomains: None
# ssl-server-max-version: None
# gratuitous-arp-interval: None
# http-cookie-path: None
# ssl-algorithm: None
# ssl-min-version: None
##################################################
##################################################
# ldb-method: None
# ssl-send-empty-frags: None
# srcintf-filter: None
# ssl-max-version: None
# ssl-server-session-state-max: None
# mappedip: None
# ssl-hsts: None
# mapped-addr: None
# src-filter: None
# server-type: None
# ssl-hpkp-include-subdomains: None
# ssl-client-renegotiation: None
# ssl-http-location-conversion: None
# https-cookie-secure: None
# extip: None
# ssl-hpkp: None
# ssl-server-cipher-suites: {'priority': None, 'cipher': None, 'versions': None}
# protocol: None
# ssl-hpkp-backup: None
# ssl-dh-bits: None
# dns-mapping-ttl: None
# ssl-hsts-age: None
# extaddr: None
# ssl-hpkp-primary: None
# monitor: None
# service: None
# ssl-hpkp-age: None
# http-cookie-age: None
# weblogic-server: None
# http-cookie-share: None
# name: Basic FQDN Translation
# color: None
# ssl-mode: None
# portforward: None
# http-cookie-generation: None
# ssl-client-fallback: None
# http-ip-header: None
# persistence: None
# websphere-server: None
# nat-source-vip: None
# portmapping-type: None
# adom: ansible
# ssl-client-session-state-max: None
# extintf: None
# ssl-server-max-version: None
# http-ip-header-name: None
# ssl-certificate: None
# ssl-server-session-state-type: None
# arp-reply: None
# ssl-hsts-include-subdomains: None
# ssl-min-version: None
# ssl-server-algorithm: None
# ssl-server-session-state-timeout: None
# ssl-server-min-version: None
# http-cookie-domain: None
# mappedport: None
# outlook-web-access: None
# ssl-cipher-suites: {'cipher': None, 'versions': None}
# ssl-client-session-state-type: None
# ssl-http-match-host: None
# ssl-client-session-state-timeout: None
# comment: None
# ssl-hpkp-report-uri: None
# http-cookie-domain-from-host: None
# ssl-algorithm: None
# gratuitous-arp-interval: None
# extport: None
# max-embryonic-connections: None
# mode: delete
# http-cookie-path: None
# ssl-pfs: None
# http-multiplex: None
##################################################
# Test using fixture 1 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[0]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 2 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[1]['paramgram_used'])
assert output['raw_response']['status']['code'] == -10131
# Test using fixture 3 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[2]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 4 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[3]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 5 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[4]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 6 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[5]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 7 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[6]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 8 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[7]['paramgram_used'])
assert output['raw_response']['status']['code'] == -3
# Test using fixture 9 #
output = fmgr_fwobj_vip.fmgr_firewall_vip_modify(fmg_instance, fixture_data[8]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
|
gpl-3.0
|
[
3,
1898,
14894,
30205,
10811,
12,
3277,
14,
199,
3,
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,
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,
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,
2622,
14,
221,
982,
440,
12,
1937,
665,
2859,
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,
646,
747,
199,
646,
2022,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
509,
280,
2609,
14,
509,
280,
2609,
492,
13694,
2988,
2461,
199,
646,
4613,
199,
199,
893,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
509,
280,
2609,
492,
289,
7755,
63,
8835,
1113,
63,
18607,
199,
2590,
3545,
26,
272,
4613,
14,
2759,
480,
6531,
440,
2248,
1415,
4621,
367,
5343,
401,
2040,
63,
578,
63,
1896,
29,
549,
9,
421,
199,
318,
2248,
63,
8769,
837,
272,
10949,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
435,
3286,
91,
1501,
5565,
1001,
1674,
908,
8,
267,
1788,
29,
736,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
3460,
493,
8964,
59,
16,
566,
272,
862,
26,
267,
543,
1551,
8,
5997,
63,
515,
12,
298,
82,
531,
465,
10949,
63,
493,
26,
288,
10949,
63,
576,
275,
2022,
14,
912,
8,
5997,
63,
493,
9,
272,
871,
5925,
26,
267,
372,
942,
272,
372,
359,
5997,
63,
576,
61,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
859,
63,
1805,
8,
27899,
304,
272,
1950,
63,
533,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
358,
272,
372,
1950,
63,
533,
63,
1805,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
1950,
63,
1805,
8,
27899,
304,
272,
1950,
63,
533,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
3112,
14,
1200,
14,
509,
280,
2609,
14,
70,
7755,
63,
8835,
1113,
63,
18607,
14,
3225,
358,
272,
372,
1950,
63,
533,
63,
1805,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
1593,
401,
1862,
29,
912,
63,
8769,
1012,
199,
318,
10949,
63,
576,
8,
1069,
304,
272,
2562,
63,
354,
275,
1056,
14,
1593,
855,
354,
4343,
1814,
480,
396,
29808,
6899,
272,
372,
1056,
14,
635,
14,
362,
8,
1532,
63,
354,
12,
488,
9,
421,
199,
70,
6649,
63,
842,
275,
13694,
2988,
2461,
8,
2105,
63,
1805,
12,
859,
63,
1805,
9,
421,
199,
318,
511,
63,
70,
7755,
63,
10794,
63,
18607,
63,
8951,
8,
5997,
63,
576,
12,
15981,
304,
272,
15981,
14,
2068,
480,
4853,
14,
578,
63,
1208,
14,
1200,
14,
509,
280,
2609,
14,
509,
280,
2609,
14,
28027,
2988,
2461,
14,
1412,
63,
1069,
401,
326,
5366,
63,
5881,
29,
5997,
63,
576,
9,
272,
327,
221,
31574,
4167,
5951,
1202,
26,
6565,
5680,
339,
20286,
309,
272,
327,
3721,
26,
18208,
701,
2622,
272,
327,
6149,
13,
2254,
13,
1667,
13,
21844,
458,
26,
488,
272,
327,
2928,
21100,
13,
1541,
26,
488,
272,
327,
6149,
13,
988,
13,
1023,
26,
488,
272,
327,
6149,
13,
1000,
13,
1730,
13,
929,
13,
988,
26,
488,
272,
327,
6149,
13,
72,
2051,
80,
26,
488,
272,
327,
9994,
13,
2697,
26,
488,
272,
327,
6149,
13,
1258,
13,
1730,
13,
929,
13,
2593,
26,
488,
272,
327,
2928,
13,
1541,
26,
488,
272,
327,
1654,
13,
466,
26,
488,
272,
327,
6149,
13,
72,
2051,
80,
13,
2613,
13,
954,
9756,
26,
488,
272,
327,
6149,
13,
1014,
13,
1985,
13,
15083,
26,
488,
272,
327,
4178,
13,
5306,
13,
7817,
26,
488,
272,
327,
2341,
321,
21846,
26,
1616,
14,
23,
14,
11174,
14,
821,
272,
327,
6149,
13,
1000,
13,
9231,
13,
27034,
26,
791,
6693,
356,
488,
12,
283,
9231,
356,
488,
12,
283,
6234,
356,
488,
93,
272,
327,
4113,
26,
14719,
272,
327,
6149,
13,
72,
2051,
80,
13,
5751,
26,
488,
272,
327,
6149,
13,
7821,
13,
5609,
26,
488,
272,
327,
6715,
13,
4745,
13,
12130,
26,
488,
272,
327,
6149,
13,
72,
10329,
13,
474,
26,
488,
272,
327,
1599,
2697,
26,
488,
272,
327,
6149,
13,
1258,
13,
264,
21961,
425,
26,
488,
272,
327,
8372,
26,
488,
272,
327,
2435,
26,
488,
272,
327,
6149,
13,
72,
2051,
80,
13,
474,
26,
488,
272,
327,
1455,
13,
5306,
13,
474,
26,
488,
272,
327,
3330,
15370,
13,
1000,
26,
488,
272,
327,
1455,
13,
5306,
13,
6251,
26,
488,
272,
327,
3164,
26,
5557,
272,
327,
6149,
13,
632,
26,
488,
272,
327,
1844,
6688,
26,
4756,
272,
327,
1455,
13,
6048,
88,
26,
488,
272,
327,
1455,
13,
5306,
13,
15043,
26,
488,
272,
327,
6149,
13,
1258,
13,
10538,
26,
488,
272,
327,
444,
8996,
26,
18051,
14,
2819,
14,
5756,
14,
10233,
272,
327,
1599,
21100,
26,
1263,
272,
327,
26882,
26,
488,
272,
327,
3330,
14980,
13,
1000,
26,
488,
272,
327,
13872,
13,
1365,
13,
18607,
26,
488,
272,
327,
1844,
4745,
13,
466,
26,
488,
339,
327,
1503,
676,
26,
3242,
272,
327,
6149,
13,
1258,
13,
1730,
13,
929,
13,
988,
26,
488,
272,
327,
1455,
13,
711,
13,
1291,
26,
488,
272,
327,
1455,
13,
711,
13
] |
[
1898,
14894,
30205,
10811,
12,
3277,
14,
199,
3,
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,
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,
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,
2622,
14,
221,
982,
440,
12,
1937,
665,
2859,
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,
646,
747,
199,
646,
2022,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
509,
280,
2609,
14,
509,
280,
2609,
492,
13694,
2988,
2461,
199,
646,
4613,
199,
199,
893,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
509,
280,
2609,
492,
289,
7755,
63,
8835,
1113,
63,
18607,
199,
2590,
3545,
26,
272,
4613,
14,
2759,
480,
6531,
440,
2248,
1415,
4621,
367,
5343,
401,
2040,
63,
578,
63,
1896,
29,
549,
9,
421,
199,
318,
2248,
63,
8769,
837,
272,
10949,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
435,
3286,
91,
1501,
5565,
1001,
1674,
908,
8,
267,
1788,
29,
736,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
3460,
493,
8964,
59,
16,
566,
272,
862,
26,
267,
543,
1551,
8,
5997,
63,
515,
12,
298,
82,
531,
465,
10949,
63,
493,
26,
288,
10949,
63,
576,
275,
2022,
14,
912,
8,
5997,
63,
493,
9,
272,
871,
5925,
26,
267,
372,
942,
272,
372,
359,
5997,
63,
576,
61,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
859,
63,
1805,
8,
27899,
304,
272,
1950,
63,
533,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
358,
272,
372,
1950,
63,
533,
63,
1805,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
1950,
63,
1805,
8,
27899,
304,
272,
1950,
63,
533,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
3112,
14,
1200,
14,
509,
280,
2609,
14,
70,
7755,
63,
8835,
1113,
63,
18607,
14,
3225,
358,
272,
372,
1950,
63,
533,
63,
1805,
421,
199,
32,
4462,
14,
5997,
8,
2645,
628,
1593,
401,
1862,
29,
912,
63,
8769,
1012,
199,
318,
10949,
63,
576,
8,
1069,
304,
272,
2562,
63,
354,
275,
1056,
14,
1593,
855,
354,
4343,
1814,
480,
396,
29808,
6899,
272,
372,
1056,
14,
635,
14,
362,
8,
1532,
63,
354,
12,
488,
9,
421,
199,
70,
6649,
63,
842,
275,
13694,
2988,
2461,
8,
2105,
63,
1805,
12,
859,
63,
1805,
9,
421,
199,
318,
511,
63,
70,
7755,
63,
10794,
63,
18607,
63,
8951,
8,
5997,
63,
576,
12,
15981,
304,
272,
15981,
14,
2068,
480,
4853,
14,
578,
63,
1208,
14,
1200,
14,
509,
280,
2609,
14,
509,
280,
2609,
14,
28027,
2988,
2461,
14,
1412,
63,
1069,
401,
326,
5366,
63,
5881,
29,
5997,
63,
576,
9,
272,
327,
221,
31574,
4167,
5951,
1202,
26,
6565,
5680,
339,
20286,
309,
272,
327,
3721,
26,
18208,
701,
2622,
272,
327,
6149,
13,
2254,
13,
1667,
13,
21844,
458,
26,
488,
272,
327,
2928,
21100,
13,
1541,
26,
488,
272,
327,
6149,
13,
988,
13,
1023,
26,
488,
272,
327,
6149,
13,
1000,
13,
1730,
13,
929,
13,
988,
26,
488,
272,
327,
6149,
13,
72,
2051,
80,
26,
488,
272,
327,
9994,
13,
2697,
26,
488,
272,
327,
6149,
13,
1258,
13,
1730,
13,
929,
13,
2593,
26,
488,
272,
327,
2928,
13,
1541,
26,
488,
272,
327,
1654,
13,
466,
26,
488,
272,
327,
6149,
13,
72,
2051,
80,
13,
2613,
13,
954,
9756,
26,
488,
272,
327,
6149,
13,
1014,
13,
1985,
13,
15083,
26,
488,
272,
327,
4178,
13,
5306,
13,
7817,
26,
488,
272,
327,
2341,
321,
21846,
26,
1616,
14,
23,
14,
11174,
14,
821,
272,
327,
6149,
13,
1000,
13,
9231,
13,
27034,
26,
791,
6693,
356,
488,
12,
283,
9231,
356,
488,
12,
283,
6234,
356,
488,
93,
272,
327,
4113,
26,
14719,
272,
327,
6149,
13,
72,
2051,
80,
13,
5751,
26,
488,
272,
327,
6149,
13,
7821,
13,
5609,
26,
488,
272,
327,
6715,
13,
4745,
13,
12130,
26,
488,
272,
327,
6149,
13,
72,
10329,
13,
474,
26,
488,
272,
327,
1599,
2697,
26,
488,
272,
327,
6149,
13,
1258,
13,
264,
21961,
425,
26,
488,
272,
327,
8372,
26,
488,
272,
327,
2435,
26,
488,
272,
327,
6149,
13,
72,
2051,
80,
13,
474,
26,
488,
272,
327,
1455,
13,
5306,
13,
474,
26,
488,
272,
327,
3330,
15370,
13,
1000,
26,
488,
272,
327,
1455,
13,
5306,
13,
6251,
26,
488,
272,
327,
3164,
26,
5557,
272,
327,
6149,
13,
632,
26,
488,
272,
327,
1844,
6688,
26,
4756,
272,
327,
1455,
13,
6048,
88,
26,
488,
272,
327,
1455,
13,
5306,
13,
15043,
26,
488,
272,
327,
6149,
13,
1258,
13,
10538,
26,
488,
272,
327,
444,
8996,
26,
18051,
14,
2819,
14,
5756,
14,
10233,
272,
327,
1599,
21100,
26,
1263,
272,
327,
26882,
26,
488,
272,
327,
3330,
14980,
13,
1000,
26,
488,
272,
327,
13872,
13,
1365,
13,
18607,
26,
488,
272,
327,
1844,
4745,
13,
466,
26,
488,
339,
327,
1503,
676,
26,
3242,
272,
327,
6149,
13,
1258,
13,
1730,
13,
929,
13,
988,
26,
488,
272,
327,
1455,
13,
711,
13,
1291,
26,
488,
272,
327,
1455,
13,
711,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tiancj/emesene
|
emesene/e3/xmpp/SleekXMPP/sleekxmpp/plugins/xep_0066/oob.py
|
14
|
5530
|
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
This file is part of SleekXMPP.
See the file LICENSE for copying permission.
"""
import logging
from sleekxmpp.stanza import Message, Presence, Iq
from sleekxmpp.exceptions import XMPPError
from sleekxmpp.xmlstream import register_stanza_plugin
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.xmlstream.matcher import StanzaPath
from sleekxmpp.plugins import BasePlugin
from sleekxmpp.plugins.xep_0066 import stanza
log = logging.getLogger(__name__)
class XEP_0066(BasePlugin):
"""
XEP-0066: Out of Band Data
Out of Band Data is a basic method for transferring files between
XMPP agents. The URL of the resource in question is sent to the receiving
entity, which then downloads the resource before responding to the OOB
request. OOB is also used as a generic means to transmit URLs in other
stanzas to indicate where to find additional information.
Also see <http://www.xmpp.org/extensions/xep-0066.html>.
Events:
oob_transfer -- Raised when a request to download a resource
has been received.
Methods:
send_oob -- Send a request to another entity to download a file
or other addressable resource.
"""
name = 'xep_0066'
description = 'XEP-0066: Out of Band Data'
dependencies = set(['xep_0030'])
stanza = stanza
def plugin_init(self):
"""Start the XEP-0066 plugin."""
self.url_handlers = {'global': self._default_handler,
'jid': {}}
register_stanza_plugin(Iq, stanza.OOBTransfer)
register_stanza_plugin(Message, stanza.OOB)
register_stanza_plugin(Presence, stanza.OOB)
self.xmpp.register_handler(
Callback('OOB Transfer',
StanzaPath('iq@type=set/oob_transfer'),
self._handle_transfer))
def plugin_end(self):
self.xmpp.remove_handler('OOB Transfer')
self.xmpp['xep_0030'].del_feature(feature=stanza.OOBTransfer.namespace)
self.xmpp['xep_0030'].del_feature(feature=stanza.OOB.namespace)
def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature(stanza.OOBTransfer.namespace)
self.xmpp['xep_0030'].add_feature(stanza.OOB.namespace)
def register_url_handler(self, jid=None, handler=None):
"""
Register a handler to process download requests, either for all
JIDs or a single JID.
Arguments:
jid -- If None, then set the handler as a global default.
handler -- If None, then remove the existing handler for the
given JID, or reset the global handler if the JID
is None.
"""
if jid is None:
if handler is not None:
self.url_handlers['global'] = handler
else:
self.url_handlers['global'] = self._default_handler
else:
if handler is not None:
self.url_handlers['jid'][jid] = handler
else:
del self.url_handlers['jid'][jid]
def send_oob(self, to, url, desc=None, ifrom=None, **iqargs):
"""
Initiate a basic file transfer by sending the URL of
a file or other resource.
Arguments:
url -- The URL of the resource to transfer.
desc -- An optional human readable description of the item
that is to be transferred.
ifrom -- Specifiy the sender's JID.
block -- If true, block and wait for the stanzas' reply.
timeout -- The time in seconds to block while waiting for
a reply. If None, then wait indefinitely.
callback -- Optional callback to execute when a reply is
received instead of blocking and waiting for
the reply.
"""
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['to'] = to
iq['from'] = ifrom
iq['oob_transfer']['url'] = url
iq['oob_transfer']['desc'] = desc
return iq.send(**iqargs)
def _run_url_handler(self, iq):
"""
Execute the appropriate handler for a transfer request.
Arguments:
iq -- The Iq stanza containing the OOB transfer request.
"""
if iq['to'] in self.url_handlers['jid']:
return self.url_handlers['jid'][iq['to']](iq)
else:
if self.url_handlers['global']:
self.url_handlers['global'](iq)
else:
raise XMPPError('service-unavailable')
def _default_handler(self, iq):
"""
As a safe default, don't actually download files.
Register a new handler using self.register_url_handler to
screen requests and download files.
Arguments:
iq -- The Iq stanza containing the OOB transfer request.
"""
raise XMPPError('service-unavailable')
def _handle_transfer(self, iq):
"""
Handle receiving an out-of-band transfer request.
Arguments:
iq -- An Iq stanza containing an OOB transfer request.
"""
log.debug('Received out-of-band data request for %s from %s:' % (
iq['oob_transfer']['url'], iq['from']))
self._run_url_handler(iq)
iq.reply().send()
|
gpl-3.0
|
[
624,
272,
428,
274,
5711,
56,
1658,
48,
26,
710,
428,
274,
5711,
1323,
1658,
48,
11243,
272,
1898,
334,
35,
9,
7760,
653,
1619,
6738,
352,
445,
14,
31712,
3903,
12,
491,
554,
1603,
14,
52,
14,
9785,
337,
272,
961,
570,
365,
1777,
402,
428,
274,
5711,
56,
1658,
48,
14,
339,
1666,
314,
570,
5113,
367,
16743,
4983,
14,
199,
624,
199,
199,
646,
2050,
199,
199,
504,
26220,
5711,
26608,
14,
29455,
492,
6430,
12,
5543,
14073,
12,
473,
81,
199,
504,
26220,
5711,
26608,
14,
3924,
492,
1323,
1658,
48,
547,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
492,
2274,
63,
29455,
63,
2718,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
2232,
492,
17555,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
16135,
492,
1933,
19024,
2042,
199,
504,
26220,
5711,
26608,
14,
5265,
492,
3523,
5061,
199,
504,
26220,
5711,
26608,
14,
5265,
14,
88,
1545,
63,
29327,
492,
24267,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1323,
6102,
63,
29327,
8,
1563,
5061,
304,
339,
408,
272,
1323,
6102,
13,
29327,
26,
6219,
402,
27709,
3918,
339,
6219,
402,
27709,
3918,
365,
282,
5678,
1083,
367,
28183,
17756,
1584,
3382,
272,
1323,
1658,
48,
22867,
14,
710,
2851,
402,
314,
2073,
315,
7894,
365,
4847,
370,
314,
18390,
272,
4642,
12,
1314,
2066,
28242,
314,
2073,
2544,
9163,
1098,
370,
314,
593,
5488,
272,
1056,
14,
593,
5488,
365,
2597,
1202,
465,
282,
7809,
4910,
370,
27754,
10867,
315,
1163,
272,
410,
290,
90,
305,
370,
6623,
2382,
370,
2342,
4722,
2556,
14,
339,
6121,
1937,
665,
1014,
921,
1544,
14,
26608,
14,
1308,
15,
5359,
15,
88,
1545,
13,
29327,
14,
1360,
10827,
339,
27982,
26,
267,
312,
2873,
63,
9609,
1553,
24997,
1380,
282,
1056,
370,
5235,
282,
2073,
717,
965,
2757,
3086,
14,
339,
17653,
26,
267,
3222,
63,
25189,
1553,
10217,
282,
1056,
370,
4573,
4642,
370,
5235,
282,
570,
490,
503,
1163,
2287,
461,
2073,
14,
272,
408,
339,
536,
275,
283,
88,
1545,
63,
29327,
7,
272,
1369,
275,
283,
56,
6102,
13,
29327,
26,
6219,
402,
27709,
3918,
7,
272,
5124,
275,
663,
2941,
88,
1545,
63,
24281,
1105,
272,
24267,
275,
24267,
339,
347,
3589,
63,
826,
8,
277,
304,
267,
408,
3162,
314,
1323,
6102,
13,
29327,
3589,
1041,
398,
291,
14,
633,
63,
5586,
275,
791,
2966,
356,
291,
423,
885,
63,
2232,
12,
2490,
283,
14203,
356,
24312,
398,
2274,
63,
29455,
63,
2718,
8,
29961,
12,
24267,
14,
47,
5488,
11761,
9,
267,
2274,
63,
29455,
63,
2718,
8,
2209,
12,
24267,
14,
47,
5488,
9,
267,
2274,
63,
29455,
63,
2718,
8,
2398,
14073,
12,
24267,
14,
47,
5488,
9,
398,
291,
14,
26608,
14,
2683,
63,
2232,
8,
355,
17555,
360,
47,
5488,
27507,
297,
586,
1933,
19024,
2042,
360,
9962,
32,
466,
29,
409,
15,
25189,
63,
9609,
659,
586,
291,
423,
2479,
63,
9609,
430,
339,
347,
3589,
63,
500,
8,
277,
304,
267,
291,
14,
26608,
14,
2168,
63,
2232,
360,
47,
5488,
27507,
358,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
2264,
63,
4445,
8,
4445,
29,
29455,
14,
47,
5488,
11761,
14,
3251,
9,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
2264,
63,
4445,
8,
4445,
29,
29455,
14,
47,
5488,
14,
3251,
9,
339,
347,
2351,
63,
3409,
8,
277,
12,
21752,
304,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
525,
63,
4445,
8,
29455,
14,
47,
5488,
11761,
14,
3251,
9,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
525,
63,
4445,
8,
29455,
14,
47,
5488,
14,
3251,
9,
339,
347,
2274,
63,
633,
63,
2232,
8,
277,
12,
21752,
29,
403,
12,
3016,
29,
403,
304,
267,
408,
267,
11828,
282,
3016,
370,
2112,
5235,
4145,
12,
1902,
367,
1006,
267,
1603,
12818,
503,
282,
2849,
1603,
998,
14,
398,
7628,
26,
288,
21752,
258,
1553,
982,
488,
12,
2066,
663,
314,
3016,
465,
282,
2288,
849,
14,
288,
3016,
1553,
982,
488,
12,
2066,
2813,
314,
3411,
3016,
367,
314,
2432,
1627,
1603,
998,
12,
503,
5305,
314,
2288,
3016,
340,
314,
1603,
998,
2432,
365,
488,
14,
267,
408,
267,
340,
21752,
365,
488,
26,
288,
340,
3016,
365,
440,
488,
26,
355,
291,
14,
633,
63,
5586,
459,
2966,
418,
275,
3016,
288,
587,
26,
355,
291,
14,
633,
63,
5586,
459,
2966,
418,
275,
291,
423,
885,
63,
2232,
267,
587,
26,
288,
340,
3016,
365,
440,
488,
26,
355,
291,
14,
633,
63,
5586,
459,
14203,
3488,
14203,
61,
275,
3016,
288,
587,
26,
355,
2150,
291,
14,
633,
63,
5586,
459,
14203,
3488,
14203,
61,
339,
347,
3222,
63,
25189,
8,
277,
12,
370,
12,
1166,
12,
4328,
29,
403,
12,
340,
417,
29,
403,
12,
1011,
9962,
589,
304,
267,
408,
267,
21412,
323,
282,
5678,
570,
9307,
701,
10209,
314,
2851,
402,
267,
282,
570,
503,
1163,
2073,
14,
398,
7628,
26,
288,
1166,
420,
1553,
710,
2851,
402,
314,
2073,
370,
9307,
14,
288,
4328,
258,
1553,
1626,
2716,
11779,
12701,
1369,
402,
314,
1242,
717,
626,
365,
370,
506,
1752,
5057,
14,
288,
340,
417,
259,
1553,
5367,
329,
89,
314,
8904,
1159,
1603,
998,
14,
288,
1853,
259,
1553,
982,
2549,
12,
1853,
436,
3618,
367,
314,
410,
290,
90,
305,
7,
9351,
14,
288,
2653,
221,
1553,
710,
900,
315,
4696,
370,
1853,
1830,
10923,
367,
717,
282,
9351,
14,
982,
488,
12,
2066,
3618,
315,
23442,
590,
14,
288,
3233,
1553,
4879,
3233,
370,
5341,
1380,
282,
9351,
365,
717,
3086,
3140,
402,
14592,
436,
10923,
367,
717,
314,
9351,
14,
267,
408,
267,
284,
81,
275,
291,
14,
26608,
14,
29961,
342,
267,
284,
81,
459,
466,
418,
275,
283,
409,
7,
267,
284,
81,
459,
475,
418,
275,
370,
267,
284,
81,
459,
504,
418,
275,
340,
417,
267,
284,
81,
459,
25189,
63,
9609,
2545,
633,
418,
275,
1166,
267,
284,
81,
459,
25189,
63,
9609,
2545,
3257,
418,
275,
4328,
267,
372,
284,
81,
14,
2254
] |
[
272,
428,
274,
5711,
56,
1658,
48,
26,
710,
428,
274,
5711,
1323,
1658,
48,
11243,
272,
1898,
334,
35,
9,
7760,
653,
1619,
6738,
352,
445,
14,
31712,
3903,
12,
491,
554,
1603,
14,
52,
14,
9785,
337,
272,
961,
570,
365,
1777,
402,
428,
274,
5711,
56,
1658,
48,
14,
339,
1666,
314,
570,
5113,
367,
16743,
4983,
14,
199,
624,
199,
199,
646,
2050,
199,
199,
504,
26220,
5711,
26608,
14,
29455,
492,
6430,
12,
5543,
14073,
12,
473,
81,
199,
504,
26220,
5711,
26608,
14,
3924,
492,
1323,
1658,
48,
547,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
492,
2274,
63,
29455,
63,
2718,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
2232,
492,
17555,
199,
504,
26220,
5711,
26608,
14,
1652,
1745,
14,
16135,
492,
1933,
19024,
2042,
199,
504,
26220,
5711,
26608,
14,
5265,
492,
3523,
5061,
199,
504,
26220,
5711,
26608,
14,
5265,
14,
88,
1545,
63,
29327,
492,
24267,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1323,
6102,
63,
29327,
8,
1563,
5061,
304,
339,
408,
272,
1323,
6102,
13,
29327,
26,
6219,
402,
27709,
3918,
339,
6219,
402,
27709,
3918,
365,
282,
5678,
1083,
367,
28183,
17756,
1584,
3382,
272,
1323,
1658,
48,
22867,
14,
710,
2851,
402,
314,
2073,
315,
7894,
365,
4847,
370,
314,
18390,
272,
4642,
12,
1314,
2066,
28242,
314,
2073,
2544,
9163,
1098,
370,
314,
593,
5488,
272,
1056,
14,
593,
5488,
365,
2597,
1202,
465,
282,
7809,
4910,
370,
27754,
10867,
315,
1163,
272,
410,
290,
90,
305,
370,
6623,
2382,
370,
2342,
4722,
2556,
14,
339,
6121,
1937,
665,
1014,
921,
1544,
14,
26608,
14,
1308,
15,
5359,
15,
88,
1545,
13,
29327,
14,
1360,
10827,
339,
27982,
26,
267,
312,
2873,
63,
9609,
1553,
24997,
1380,
282,
1056,
370,
5235,
282,
2073,
717,
965,
2757,
3086,
14,
339,
17653,
26,
267,
3222,
63,
25189,
1553,
10217,
282,
1056,
370,
4573,
4642,
370,
5235,
282,
570,
490,
503,
1163,
2287,
461,
2073,
14,
272,
408,
339,
536,
275,
283,
88,
1545,
63,
29327,
7,
272,
1369,
275,
283,
56,
6102,
13,
29327,
26,
6219,
402,
27709,
3918,
7,
272,
5124,
275,
663,
2941,
88,
1545,
63,
24281,
1105,
272,
24267,
275,
24267,
339,
347,
3589,
63,
826,
8,
277,
304,
267,
408,
3162,
314,
1323,
6102,
13,
29327,
3589,
1041,
398,
291,
14,
633,
63,
5586,
275,
791,
2966,
356,
291,
423,
885,
63,
2232,
12,
2490,
283,
14203,
356,
24312,
398,
2274,
63,
29455,
63,
2718,
8,
29961,
12,
24267,
14,
47,
5488,
11761,
9,
267,
2274,
63,
29455,
63,
2718,
8,
2209,
12,
24267,
14,
47,
5488,
9,
267,
2274,
63,
29455,
63,
2718,
8,
2398,
14073,
12,
24267,
14,
47,
5488,
9,
398,
291,
14,
26608,
14,
2683,
63,
2232,
8,
355,
17555,
360,
47,
5488,
27507,
297,
586,
1933,
19024,
2042,
360,
9962,
32,
466,
29,
409,
15,
25189,
63,
9609,
659,
586,
291,
423,
2479,
63,
9609,
430,
339,
347,
3589,
63,
500,
8,
277,
304,
267,
291,
14,
26608,
14,
2168,
63,
2232,
360,
47,
5488,
27507,
358,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
2264,
63,
4445,
8,
4445,
29,
29455,
14,
47,
5488,
11761,
14,
3251,
9,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
2264,
63,
4445,
8,
4445,
29,
29455,
14,
47,
5488,
14,
3251,
9,
339,
347,
2351,
63,
3409,
8,
277,
12,
21752,
304,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
525,
63,
4445,
8,
29455,
14,
47,
5488,
11761,
14,
3251,
9,
267,
291,
14,
26608,
459,
88,
1545,
63,
24281,
2278,
525,
63,
4445,
8,
29455,
14,
47,
5488,
14,
3251,
9,
339,
347,
2274,
63,
633,
63,
2232,
8,
277,
12,
21752,
29,
403,
12,
3016,
29,
403,
304,
267,
408,
267,
11828,
282,
3016,
370,
2112,
5235,
4145,
12,
1902,
367,
1006,
267,
1603,
12818,
503,
282,
2849,
1603,
998,
14,
398,
7628,
26,
288,
21752,
258,
1553,
982,
488,
12,
2066,
663,
314,
3016,
465,
282,
2288,
849,
14,
288,
3016,
1553,
982,
488,
12,
2066,
2813,
314,
3411,
3016,
367,
314,
2432,
1627,
1603,
998,
12,
503,
5305,
314,
2288,
3016,
340,
314,
1603,
998,
2432,
365,
488,
14,
267,
408,
267,
340,
21752,
365,
488,
26,
288,
340,
3016,
365,
440,
488,
26,
355,
291,
14,
633,
63,
5586,
459,
2966,
418,
275,
3016,
288,
587,
26,
355,
291,
14,
633,
63,
5586,
459,
2966,
418,
275,
291,
423,
885,
63,
2232,
267,
587,
26,
288,
340,
3016,
365,
440,
488,
26,
355,
291,
14,
633,
63,
5586,
459,
14203,
3488,
14203,
61,
275,
3016,
288,
587,
26,
355,
2150,
291,
14,
633,
63,
5586,
459,
14203,
3488,
14203,
61,
339,
347,
3222,
63,
25189,
8,
277,
12,
370,
12,
1166,
12,
4328,
29,
403,
12,
340,
417,
29,
403,
12,
1011,
9962,
589,
304,
267,
408,
267,
21412,
323,
282,
5678,
570,
9307,
701,
10209,
314,
2851,
402,
267,
282,
570,
503,
1163,
2073,
14,
398,
7628,
26,
288,
1166,
420,
1553,
710,
2851,
402,
314,
2073,
370,
9307,
14,
288,
4328,
258,
1553,
1626,
2716,
11779,
12701,
1369,
402,
314,
1242,
717,
626,
365,
370,
506,
1752,
5057,
14,
288,
340,
417,
259,
1553,
5367,
329,
89,
314,
8904,
1159,
1603,
998,
14,
288,
1853,
259,
1553,
982,
2549,
12,
1853,
436,
3618,
367,
314,
410,
290,
90,
305,
7,
9351,
14,
288,
2653,
221,
1553,
710,
900,
315,
4696,
370,
1853,
1830,
10923,
367,
717,
282,
9351,
14,
982,
488,
12,
2066,
3618,
315,
23442,
590,
14,
288,
3233,
1553,
4879,
3233,
370,
5341,
1380,
282,
9351,
365,
717,
3086,
3140,
402,
14592,
436,
10923,
367,
717,
314,
9351,
14,
267,
408,
267,
284,
81,
275,
291,
14,
26608,
14,
29961,
342,
267,
284,
81,
459,
466,
418,
275,
283,
409,
7,
267,
284,
81,
459,
475,
418,
275,
370,
267,
284,
81,
459,
504,
418,
275,
340,
417,
267,
284,
81,
459,
25189,
63,
9609,
2545,
633,
418,
275,
1166,
267,
284,
81,
459,
25189,
63,
9609,
2545,
3257,
418,
275,
4328,
267,
372,
284,
81,
14,
2254,
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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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,
1,
1,
1,
1,
1,
1,
1,
1
] |
kasper93/brotli
|
python/tests/test_utils.py
|
98
|
1128
|
from __future__ import print_function
import sys
import os
import sysconfig
import filecmp
def diff_q(first_file, second_file):
"""Simulate call to POSIX diff with -q argument"""
if not filecmp.cmp(first_file, second_file, shallow=False):
print("Files %s and %s differ" % (first_file, second_file),
file=sys.stderr)
return 1
return 0
PYTHON = sys.executable or "python"
# 'bro.py' script should be in parent directory
BRO = os.path.abspath("../bro.py")
# get platform- and version-specific build/lib folder
platform_lib_name = "lib.{platform}-{version[0]}.{version[1]}".format(
platform=sysconfig.get_platform(),
version=sys.version_info)
# by default, distutils' build base is in the same location as setup.py
build_base = os.path.abspath(os.path.join("..", "..", "build"))
build_lib = os.path.join(build_base, platform_lib_name)
# prepend build/lib to PYTHONPATH environment variable
TEST_ENV = os.environ.copy()
if 'PYTHONPATH' not in TEST_ENV:
TEST_ENV['PYTHONPATH'] = build_lib
else:
TEST_ENV['PYTHONPATH'] = build_lib + os.pathsep + TEST_ENV['PYTHONPATH']
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
747,
199,
646,
22381,
199,
646,
570,
5730,
421,
199,
318,
3915,
63,
81,
8,
2246,
63,
493,
12,
3499,
63,
493,
304,
272,
408,
7467,
5434,
1240,
370,
18169,
3915,
543,
446,
81,
1423,
624,
272,
340,
440,
570,
5730,
14,
5730,
8,
2246,
63,
493,
12,
3499,
63,
493,
12,
23834,
29,
797,
304,
267,
870,
480,
5535,
450,
83,
436,
450,
83,
14460,
2,
450,
334,
2246,
63,
493,
12,
3499,
63,
493,
395,
1598,
570,
29,
1274,
14,
3083,
9,
267,
372,
413,
272,
372,
378,
421,
199,
11720,
275,
984,
14,
5904,
503,
298,
1548,
2,
199,
199,
3,
283,
20670,
14,
647,
7,
2884,
1077,
506,
315,
1676,
2082,
199,
21111,
275,
747,
14,
515,
14,
4832,
480,
5093,
20670,
14,
647,
531,
199,
199,
3,
664,
4298,
13,
436,
1015,
13,
6100,
1900,
15,
773,
4922,
199,
3246,
63,
773,
63,
354,
275,
298,
773,
23379,
3246,
30289,
1023,
59,
16,
61,
26944,
1023,
59,
17,
61,
5469,
908,
8,
272,
4298,
29,
24030,
14,
362,
63,
3246,
1062,
272,
1015,
29,
1274,
14,
1023,
63,
815,
9,
199,
199,
3,
701,
849,
12,
7065,
7,
1900,
1300,
365,
315,
314,
2011,
2909,
465,
3272,
14,
647,
199,
1506,
63,
1095,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
480,
703,
401,
21777,
401,
298,
1506,
2237,
199,
1506,
63,
773,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
1095,
12,
4298,
63,
773,
63,
354,
9,
199,
199,
3,
18213,
1900,
15,
773,
370,
31176,
3734,
1750,
199,
2864,
63,
9984,
275,
747,
14,
2314,
14,
1574,
342,
199,
692,
283,
29266,
7,
440,
315,
7393,
63,
9984,
26,
272,
7393,
63,
9984,
459,
29266,
418,
275,
1900,
63,
773,
199,
2836,
26,
272,
7393,
63,
9984,
459,
29266,
418,
275,
1900,
63,
773,
435,
747,
14,
17843,
435,
7393,
63,
9984,
459,
29266,
418,
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
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
747,
199,
646,
22381,
199,
646,
570,
5730,
421,
199,
318,
3915,
63,
81,
8,
2246,
63,
493,
12,
3499,
63,
493,
304,
272,
408,
7467,
5434,
1240,
370,
18169,
3915,
543,
446,
81,
1423,
624,
272,
340,
440,
570,
5730,
14,
5730,
8,
2246,
63,
493,
12,
3499,
63,
493,
12,
23834,
29,
797,
304,
267,
870,
480,
5535,
450,
83,
436,
450,
83,
14460,
2,
450,
334,
2246,
63,
493,
12,
3499,
63,
493,
395,
1598,
570,
29,
1274,
14,
3083,
9,
267,
372,
413,
272,
372,
378,
421,
199,
11720,
275,
984,
14,
5904,
503,
298,
1548,
2,
199,
199,
3,
283,
20670,
14,
647,
7,
2884,
1077,
506,
315,
1676,
2082,
199,
21111,
275,
747,
14,
515,
14,
4832,
480,
5093,
20670,
14,
647,
531,
199,
199,
3,
664,
4298,
13,
436,
1015,
13,
6100,
1900,
15,
773,
4922,
199,
3246,
63,
773,
63,
354,
275,
298,
773,
23379,
3246,
30289,
1023,
59,
16,
61,
26944,
1023,
59,
17,
61,
5469,
908,
8,
272,
4298,
29,
24030,
14,
362,
63,
3246,
1062,
272,
1015,
29,
1274,
14,
1023,
63,
815,
9,
199,
199,
3,
701,
849,
12,
7065,
7,
1900,
1300,
365,
315,
314,
2011,
2909,
465,
3272,
14,
647,
199,
1506,
63,
1095,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
480,
703,
401,
21777,
401,
298,
1506,
2237,
199,
1506,
63,
773,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
1095,
12,
4298,
63,
773,
63,
354,
9,
199,
199,
3,
18213,
1900,
15,
773,
370,
31176,
3734,
1750,
199,
2864,
63,
9984,
275,
747,
14,
2314,
14,
1574,
342,
199,
692,
283,
29266,
7,
440,
315,
7393,
63,
9984,
26,
272,
7393,
63,
9984,
459,
29266,
418,
275,
1900,
63,
773,
199,
2836,
26,
272,
7393,
63,
9984,
459,
29266,
418,
275,
1900,
63,
773,
435,
747,
14,
17843,
435,
7393,
63,
9984,
459,
29266,
418,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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bin/python
#
# @author: Gaurav Rastogi (grastogi@avinetworks.com)
# Eric Anderson (eanderson@avinetworks.com)
# module_check: supported
# Avi Version: 17.1.1
#
# Copyright: (c) 2017 Gaurav Rastogi, <grastogi@avinetworks.com>
# 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: avi_network
author: Gaurav Rastogi (@grastogi23) <grastogi@avinetworks.com>
short_description: Module for setup of Network Avi RESTful Object
description:
- This module is used to configure Network object
- more examples at U(https://github.com/avinetworks/devops)
requirements: [ avisdk ]
version_added: "2.4"
options:
state:
description:
- The state that should be applied on the entity.
default: present
choices: ["absent", "present"]
avi_api_update_method:
description:
- Default method for object update is HTTP PUT.
- Setting to patch will override that behavior to use HTTP PATCH.
version_added: "2.5"
default: put
choices: ["put", "patch"]
avi_api_patch_op:
description:
- Patch operation to use when using avi_api_update_method as patch.
version_added: "2.5"
choices: ["add", "replace", "delete"]
cloud_ref:
description:
- It is a reference to an object of type cloud.
configured_subnets:
description:
- List of subnet.
dhcp_enabled:
description:
- Select the ip address management scheme for this network.
- Default value when not specified in API or module is interpreted by Avi Controller as True.
type: bool
exclude_discovered_subnets:
description:
- When selected, excludes all discovered subnets in this network from consideration for virtual service placement.
- Default value when not specified in API or module is interpreted by Avi Controller as False.
type: bool
name:
description:
- Name of the object.
required: true
synced_from_se:
description:
- Boolean flag to set synced_from_se.
- Default value when not specified in API or module is interpreted by Avi Controller as False.
type: bool
tenant_ref:
description:
- It is a reference to an object of type tenant.
url:
description:
- Avi controller URL of the object.
uuid:
description:
- Unique object identifier of the object.
vcenter_dvs:
description:
- Boolean flag to set vcenter_dvs.
- Default value when not specified in API or module is interpreted by Avi Controller as True.
type: bool
vimgrnw_ref:
description:
- It is a reference to an object of type vimgrnwruntime.
vrf_context_ref:
description:
- It is a reference to an object of type vrfcontext.
extends_documentation_fragment:
- avi
'''
EXAMPLES = """
- name: Example to create Network object
avi_network:
controller: 10.10.25.42
username: admin
password: something
state: present
name: sample_network
"""
RETURN = '''
obj:
description: Network (api/network) object
returned: success, changed
type: dict
'''
from ansible.module_utils.basic import AnsibleModule
try:
from ansible.module_utils.network.avi.avi import (
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
except ImportError:
HAS_AVI = False
def main():
argument_specs = dict(
state=dict(default='present',
choices=['absent', 'present']),
avi_api_update_method=dict(default='put',
choices=['put', 'patch']),
avi_api_patch_op=dict(choices=['add', 'replace', 'delete']),
cloud_ref=dict(type='str',),
configured_subnets=dict(type='list',),
dhcp_enabled=dict(type='bool',),
exclude_discovered_subnets=dict(type='bool',),
name=dict(type='str', required=True),
synced_from_se=dict(type='bool',),
tenant_ref=dict(type='str',),
url=dict(type='str',),
uuid=dict(type='str',),
vcenter_dvs=dict(type='bool',),
vimgrnw_ref=dict(type='str',),
vrf_context_ref=dict(type='str',),
)
argument_specs.update(avi_common_argument_spec())
module = AnsibleModule(
argument_spec=argument_specs, supports_check_mode=True)
if not HAS_AVI:
return module.fail_json(msg=(
'Avi python API SDK (avisdk>=17.1) is not installed. '
'For more details visit https://github.com/avinetworks/sdk.'))
return avi_ansible_api(module, 'network',
set([]))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
768,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
3,
3515,
662,
1567,
1626,
424,
834,
334,
69,
11438,
834,
32,
31808,
14,
957,
9,
199,
3,
859,
63,
1074,
26,
3748,
199,
3,
21710,
3394,
26,
5557,
14,
17,
14,
17,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
9708,
9647,
300,
1214,
820,
1810,
31114,
12,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
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,
3,
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,
2595,
199,
578,
26,
21661,
63,
1200,
199,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
8593,
926,
270,
31114,
1789,
9,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
199,
199,
3612,
63,
1802,
26,
5673,
367,
3272,
402,
7220,
21710,
14880,
1893,
6935,
199,
1802,
26,
272,
446,
961,
859,
365,
1202,
370,
7908,
7220,
909,
272,
446,
1655,
7251,
737,
738,
8,
2859,
921,
5031,
14,
957,
15,
31808,
15,
2374,
1483,
9,
199,
7538,
26,
359,
2289,
374,
6341,
1622,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
710,
1174,
626,
1077,
506,
6781,
641,
314,
4642,
14,
267,
849,
26,
3451,
267,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
272,
21661,
63,
1246,
63,
873,
63,
765,
26,
267,
1369,
26,
288,
446,
3758,
1083,
367,
909,
1678,
365,
3101,
18337,
14,
288,
446,
13510,
370,
3371,
911,
4278,
626,
5953,
370,
675,
3101,
510,
8078,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
849,
26,
5324,
267,
3415,
26,
2097,
524,
401,
298,
2068,
937,
272,
21661,
63,
1246,
63,
2068,
63,
411,
26,
267,
1369,
26,
288,
446,
19292,
3439,
370,
675,
1380,
1808,
21661,
63,
1246,
63,
873,
63,
765,
465,
3371,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
3415,
26,
2097,
525,
401,
298,
1814,
401,
298,
1807,
937,
272,
8002,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8002,
14,
272,
7526,
63,
14967,
26,
267,
1369,
26,
288,
446,
3820,
402,
6303,
14,
272,
19064,
63,
3827,
26,
267,
1369,
26,
288,
446,
9496,
314,
3384,
2287,
10041,
5687,
367,
642,
2784,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
715,
14,
267,
730,
26,
2155,
272,
5760,
63,
2297,
13560,
63,
14967,
26,
267,
1369,
26,
288,
446,
3979,
4895,
12,
23388,
1006,
24983,
18709,
315,
642,
2784,
687,
8219,
1754,
367,
5791,
2435,
22286,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
756,
14,
267,
730,
26,
2155,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
909,
14,
267,
1415,
26,
2549,
272,
9560,
6867,
63,
504,
63,
261,
26,
267,
1369,
26,
288,
446,
9411,
3305,
370,
663,
9560,
6867,
63,
504,
63,
261,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
756,
14,
267,
730,
26,
2155,
272,
8261,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8261,
14,
272,
1166,
26,
267,
1369,
26,
288,
446,
21710,
7614,
2851,
402,
314,
909,
14,
272,
5377,
26,
267,
1369,
26,
288,
446,
18276,
909,
5148,
402,
314,
909,
14,
272,
27127,
63,
68,
3122,
26,
267,
1369,
26,
288,
446,
9411,
3305,
370,
663,
27127,
63,
68,
3122,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
715,
14,
267,
730,
26,
2155,
272,
6695,
2587,
13100,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
6695,
2587,
13100,
7726,
14,
272,
15209,
63,
1100,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
15209,
1100,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
21661,
199,
2344,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
5679,
370,
1218,
7220,
909,
523,
21661,
63,
1200,
26,
272,
7614,
26,
1616,
14,
709,
14,
821,
14,
2260,
272,
3434,
26,
4628,
272,
2505,
26,
6020,
272,
1174,
26,
3451,
272,
536,
26,
2690,
63,
1200,
199,
624,
199,
199,
9677,
275,
1449,
199,
1113,
26,
272,
1369,
26,
7220,
334,
1246,
15,
1200,
9,
909,
272,
2138,
26,
3182,
12,
2896,
272,
730,
26,
1211,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
7194,
14,
7194,
492,
334,
267,
21661,
63,
2330,
63,
2094,
63,
1650,
12,
7509,
63,
32636,
12,
21661,
63,
4853,
63,
1246,
9,
199,
2590,
3545,
26,
272,
7509,
63,
32636,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
7273,
275,
1211,
8,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
673,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
21661,
63,
1246,
63,
873,
63,
765,
29,
807,
8,
885,
534,
524,
297,
3521,
3415,
2968,
524,
297,
283,
2068,
3815,
267,
21661,
63,
1246,
63,
2068,
63,
411,
29,
807,
8,
4577,
2968,
525,
297,
283,
1814,
297,
283,
1807,
3815,
267,
8002,
63,
1121,
29,
807,
8,
466,
534,
495,
5529,
267,
7526,
63,
14967,
29,
807,
8,
466,
534,
513,
5529,
267,
19064,
63,
3827,
29,
807,
8,
466,
534,
2245,
5529,
267,
5760,
63,
2297,
13560,
63,
14967,
29,
807,
8,
466,
534,
2245,
5529,
267,
536,
29,
807,
8,
466,
534,
495,
297,
1415,
29
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
768,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
334,
926,
270,
31114,
32,
31808,
14,
957,
9,
199,
3,
3515,
662,
1567,
1626,
424,
834,
334,
69,
11438,
834,
32,
31808,
14,
957,
9,
199,
3,
859,
63,
1074,
26,
3748,
199,
3,
21710,
3394,
26,
5557,
14,
17,
14,
17,
199,
3,
199,
3,
1898,
26,
334,
67,
9,
9708,
9647,
300,
1214,
820,
1810,
31114,
12,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
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,
3,
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,
2595,
199,
578,
26,
21661,
63,
1200,
199,
2502,
26,
9647,
300,
1214,
820,
1810,
31114,
8593,
926,
270,
31114,
1789,
9,
665,
926,
270,
31114,
32,
31808,
14,
957,
30,
199,
199,
3612,
63,
1802,
26,
5673,
367,
3272,
402,
7220,
21710,
14880,
1893,
6935,
199,
1802,
26,
272,
446,
961,
859,
365,
1202,
370,
7908,
7220,
909,
272,
446,
1655,
7251,
737,
738,
8,
2859,
921,
5031,
14,
957,
15,
31808,
15,
2374,
1483,
9,
199,
7538,
26,
359,
2289,
374,
6341,
1622,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
2,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
288,
446,
710,
1174,
626,
1077,
506,
6781,
641,
314,
4642,
14,
267,
849,
26,
3451,
267,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
272,
21661,
63,
1246,
63,
873,
63,
765,
26,
267,
1369,
26,
288,
446,
3758,
1083,
367,
909,
1678,
365,
3101,
18337,
14,
288,
446,
13510,
370,
3371,
911,
4278,
626,
5953,
370,
675,
3101,
510,
8078,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
849,
26,
5324,
267,
3415,
26,
2097,
524,
401,
298,
2068,
937,
272,
21661,
63,
1246,
63,
2068,
63,
411,
26,
267,
1369,
26,
288,
446,
19292,
3439,
370,
675,
1380,
1808,
21661,
63,
1246,
63,
873,
63,
765,
465,
3371,
14,
267,
1015,
63,
3270,
26,
298,
18,
14,
21,
2,
267,
3415,
26,
2097,
525,
401,
298,
1814,
401,
298,
1807,
937,
272,
8002,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8002,
14,
272,
7526,
63,
14967,
26,
267,
1369,
26,
288,
446,
3820,
402,
6303,
14,
272,
19064,
63,
3827,
26,
267,
1369,
26,
288,
446,
9496,
314,
3384,
2287,
10041,
5687,
367,
642,
2784,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
715,
14,
267,
730,
26,
2155,
272,
5760,
63,
2297,
13560,
63,
14967,
26,
267,
1369,
26,
288,
446,
3979,
4895,
12,
23388,
1006,
24983,
18709,
315,
642,
2784,
687,
8219,
1754,
367,
5791,
2435,
22286,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
756,
14,
267,
730,
26,
2155,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
909,
14,
267,
1415,
26,
2549,
272,
9560,
6867,
63,
504,
63,
261,
26,
267,
1369,
26,
288,
446,
9411,
3305,
370,
663,
9560,
6867,
63,
504,
63,
261,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
756,
14,
267,
730,
26,
2155,
272,
8261,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
8261,
14,
272,
1166,
26,
267,
1369,
26,
288,
446,
21710,
7614,
2851,
402,
314,
909,
14,
272,
5377,
26,
267,
1369,
26,
288,
446,
18276,
909,
5148,
402,
314,
909,
14,
272,
27127,
63,
68,
3122,
26,
267,
1369,
26,
288,
446,
9411,
3305,
370,
663,
27127,
63,
68,
3122,
14,
288,
446,
3758,
574,
1380,
440,
2013,
315,
3261,
503,
859,
365,
11922,
701,
21710,
16282,
465,
715,
14,
267,
730,
26,
2155,
272,
6695,
2587,
13100,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
6695,
2587,
13100,
7726,
14,
272,
15209,
63,
1100,
63,
1121,
26,
267,
1369,
26,
288,
446,
2779,
365,
282,
3659,
370,
376,
909,
402,
730,
15209,
1100,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
21661,
199,
2344,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
5679,
370,
1218,
7220,
909,
523,
21661,
63,
1200,
26,
272,
7614,
26,
1616,
14,
709,
14,
821,
14,
2260,
272,
3434,
26,
4628,
272,
2505,
26,
6020,
272,
1174,
26,
3451,
272,
536,
26,
2690,
63,
1200,
199,
624,
199,
199,
9677,
275,
1449,
199,
1113,
26,
272,
1369,
26,
7220,
334,
1246,
15,
1200,
9,
909,
272,
2138,
26,
3182,
12,
2896,
272,
730,
26,
1211,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
893,
26,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
7194,
14,
7194,
492,
334,
267,
21661,
63,
2330,
63,
2094,
63,
1650,
12,
7509,
63,
32636,
12,
21661,
63,
4853,
63,
1246,
9,
199,
2590,
3545,
26,
272,
7509,
63,
32636,
275,
756,
421,
199,
318,
2446,
837,
272,
1423,
63,
7273,
275,
1211,
8,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
673,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
21661,
63,
1246,
63,
873,
63,
765,
29,
807,
8,
885,
534,
524,
297,
3521,
3415,
2968,
524,
297,
283,
2068,
3815,
267,
21661,
63,
1246,
63,
2068,
63,
411,
29,
807,
8,
4577,
2968,
525,
297,
283,
1814,
297,
283,
1807,
3815,
267,
8002,
63,
1121,
29,
807,
8,
466,
534,
495,
5529,
267,
7526,
63,
14967,
29,
807,
8,
466,
534,
513,
5529,
267,
19064,
63,
3827,
29,
807,
8,
466,
534,
2245,
5529,
267,
5760,
63,
2297,
13560,
63,
14967,
29,
807,
8,
466,
534,
2245,
5529,
267,
536,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
lsd/dotfiles-1
|
vim/bundle/eclim/eclim/autoload/eclim/python/rope/refactor/importutils/__init__.py
|
90
|
12748
|
"""A package for handling imports
This package provides tools for modifying module imports after
refactorings or as a separate task.
"""
import rope.base.evaluate
from rope.base.change import ChangeSet, ChangeContents
from rope.refactor import occurrences, rename
from rope.refactor.importutils import module_imports, actions
from rope.refactor.importutils.importinfo import NormalImport, FromImport
import rope.base.codeanalyze
class ImportOrganizer(object):
"""Perform some import-related commands
Each method returns a `rope.base.change.Change` object.
"""
def __init__(self, project):
self.project = project
self.pycore = project.pycore
self.import_tools = ImportTools(self.pycore)
def organize_imports(self, resource, offset=None):
return self._perform_command_on_import_tools(
self.import_tools.organize_imports, resource, offset)
def expand_star_imports(self, resource, offset=None):
return self._perform_command_on_import_tools(
self.import_tools.expand_stars, resource, offset)
def froms_to_imports(self, resource, offset=None):
return self._perform_command_on_import_tools(
self.import_tools.froms_to_imports, resource, offset)
def relatives_to_absolutes(self, resource, offset=None):
return self._perform_command_on_import_tools(
self.import_tools.relatives_to_absolutes, resource, offset)
def handle_long_imports(self, resource, offset=None):
return self._perform_command_on_import_tools(
self.import_tools.handle_long_imports, resource, offset)
def _perform_command_on_import_tools(self, method, resource, offset):
pymodule = self.pycore.resource_to_pyobject(resource)
before_performing = pymodule.source_code
import_filter = None
if offset is not None:
import_filter = self._line_filter(
pymodule.lines.get_line_number(offset))
result = method(pymodule, import_filter=import_filter)
if result is not None and result != before_performing:
changes = ChangeSet(method.__name__.replace('_', ' ') +
' in <%s>' % resource.path)
changes.add_change(ChangeContents(resource, result))
return changes
def _line_filter(self, lineno):
def import_filter(import_stmt):
return import_stmt.start_line <= lineno < import_stmt.end_line
return import_filter
class ImportTools(object):
def __init__(self, pycore):
self.pycore = pycore
def get_import(self, resource):
"""The import statement for `resource`"""
module_name = self.pycore.modname(resource)
return NormalImport(((module_name, None), ))
def get_from_import(self, resource, name):
"""The from import statement for `name` in `resource`"""
module_name = self.pycore.modname(resource)
names = []
if isinstance(name, list):
names = [(imported, None) for imported in name]
else:
names = [(name, None),]
return FromImport(module_name, 0, tuple(names))
def module_imports(self, module, imports_filter=None):
return module_imports.ModuleImports(self.pycore, module,
imports_filter)
def froms_to_imports(self, pymodule, import_filter=None):
pymodule = self._clean_up_imports(pymodule, import_filter)
module_imports = self.module_imports(pymodule, import_filter)
for import_stmt in module_imports.imports:
if import_stmt.readonly or \
not self._is_transformable_to_normal(import_stmt.import_info):
continue
pymodule = self._from_to_normal(pymodule, import_stmt)
# Adding normal imports in place of froms
module_imports = self.module_imports(pymodule, import_filter)
for import_stmt in module_imports.imports:
if not import_stmt.readonly and \
self._is_transformable_to_normal(import_stmt.import_info):
import_stmt.import_info = \
NormalImport(((import_stmt.import_info.module_name, None),))
module_imports.remove_duplicates()
return module_imports.get_changed_source()
def expand_stars(self, pymodule, import_filter=None):
module_imports = self.module_imports(pymodule, import_filter)
module_imports.expand_stars()
return module_imports.get_changed_source()
def _from_to_normal(self, pymodule, import_stmt):
resource = pymodule.get_resource()
from_import = import_stmt.import_info
module_name = from_import.module_name
for name, alias in from_import.names_and_aliases:
imported = name
if alias is not None:
imported = alias
occurrence_finder = occurrences.create_finder(
self.pycore, imported, pymodule[imported], imports=False)
source = rename.rename_in_module(
occurrence_finder, module_name + '.' + name,
pymodule=pymodule, replace_primary=True)
if source is not None:
pymodule = self.pycore.get_string_module(source, resource)
return pymodule
def _clean_up_imports(self, pymodule, import_filter):
resource = pymodule.get_resource()
module_with_imports = self.module_imports(pymodule, import_filter)
module_with_imports.expand_stars()
source = module_with_imports.get_changed_source()
if source is not None:
pymodule = self.pycore.get_string_module(source, resource)
source = self.relatives_to_absolutes(pymodule)
if source is not None:
pymodule = self.pycore.get_string_module(source, resource)
module_with_imports = self.module_imports(pymodule, import_filter)
module_with_imports.remove_duplicates()
module_with_imports.remove_unused_imports()
source = module_with_imports.get_changed_source()
if source is not None:
pymodule = self.pycore.get_string_module(source, resource)
return pymodule
def relatives_to_absolutes(self, pymodule, import_filter=None):
module_imports = self.module_imports(pymodule, import_filter)
to_be_absolute_list = module_imports.get_relative_to_absolute_list()
for name, absolute_name in to_be_absolute_list:
pymodule = self._rename_in_module(pymodule, name, absolute_name)
module_imports = self.module_imports(pymodule, import_filter)
module_imports.get_relative_to_absolute_list()
source = module_imports.get_changed_source()
if source is None:
source = pymodule.source_code
return source
def _is_transformable_to_normal(self, import_info):
if not isinstance(import_info, FromImport):
return False
return True
def organize_imports(self, pymodule,
unused=True, duplicates=True,
selfs=True, sort=True, import_filter=None):
if unused or duplicates:
module_imports = self.module_imports(pymodule, import_filter)
if unused:
module_imports.remove_unused_imports()
if duplicates:
module_imports.remove_duplicates()
source = module_imports.get_changed_source()
if source is not None:
pymodule = self.pycore.get_string_module(
source, pymodule.get_resource())
if selfs:
pymodule = self._remove_self_imports(pymodule, import_filter)
if sort:
return self.sort_imports(pymodule, import_filter)
else:
return pymodule.source_code
def _remove_self_imports(self, pymodule, import_filter=None):
module_imports = self.module_imports(pymodule, import_filter)
to_be_fixed, to_be_renamed = module_imports.get_self_import_fix_and_rename_list()
for name in to_be_fixed:
try:
pymodule = self._rename_in_module(pymodule, name, '', till_dot=True)
except ValueError:
# There is a self import with direct access to it
return pymodule
for name, new_name in to_be_renamed:
pymodule = self._rename_in_module(pymodule, name, new_name)
module_imports = self.module_imports(pymodule, import_filter)
module_imports.get_self_import_fix_and_rename_list()
source = module_imports.get_changed_source()
if source is not None:
pymodule = self.pycore.get_string_module(source, pymodule.get_resource())
return pymodule
def _rename_in_module(self, pymodule, name, new_name, till_dot=False):
old_name = name.split('.')[-1]
old_pyname = rope.base.evaluate.eval_str(pymodule.get_scope(), name)
occurrence_finder = occurrences.create_finder(
self.pycore, old_name, old_pyname, imports=False)
changes = rope.base.codeanalyze.ChangeCollector(pymodule.source_code)
for occurrence in occurrence_finder.find_occurrences(pymodule=pymodule):
start, end = occurrence.get_primary_range()
if till_dot:
new_end = pymodule.source_code.index('.', end) + 1
space = pymodule.source_code[end:new_end - 1].strip()
if not space == '':
for c in space:
if not c.isspace() and c not in '\\':
raise ValueError()
end = new_end
changes.add_change(start, end, new_name)
source = changes.get_changed()
if source is not None:
pymodule = self.pycore.get_string_module(source, pymodule.get_resource())
return pymodule
def sort_imports(self, pymodule, import_filter=None):
module_imports = self.module_imports(pymodule, import_filter)
module_imports.sort_imports()
return module_imports.get_changed_source()
def handle_long_imports(self, pymodule, maxdots=2, maxlength=27,
import_filter=None):
# IDEA: `maxdots` and `maxlength` can be specified in project config
# adding new from imports
module_imports = self.module_imports(pymodule, import_filter)
to_be_fixed = module_imports.handle_long_imports(maxdots, maxlength)
# performing the renaming
pymodule = self.pycore.get_string_module(
module_imports.get_changed_source(),
resource=pymodule.get_resource())
for name in to_be_fixed:
pymodule = self._rename_in_module(pymodule, name,
name.split('.')[-1])
# organizing imports
return self.organize_imports(pymodule, selfs=False, sort=False,
import_filter=import_filter)
def get_imports(pycore, pydefined):
"""A shortcut for getting the `ImportInfo`\s used in a scope"""
pymodule = pydefined.get_module()
module = module_imports.ModuleImports(pycore, pymodule)
if pymodule == pydefined:
return [stmt.import_info for stmt in module.imports]
return module.get_used_imports(pydefined)
def get_module_imports(pycore, pymodule):
"""A shortcut for creating a `module_imports.ModuleImports` object"""
return module_imports.ModuleImports(pycore, pymodule)
def add_import(pycore, pymodule, module_name, name=None):
imports = get_module_imports(pycore, pymodule)
candidates = []
names = []
# from mod import name
if name is not None:
from_import = FromImport(module_name, 0, [(name, None)])
names.append(name)
candidates.append(from_import)
# from pkg import mod
if '.' in module_name:
pkg, mod = module_name.rsplit('.', 1)
candidates.append(FromImport(pkg, 0, [(mod, None)]))
if name:
names.append(mod + '.' + name)
else:
names.append(mod)
# import mod
normal_import = NormalImport([(module_name, None)])
if name:
names.append(module_name + '.' + name)
else:
names.append(module_name)
candidates.append(normal_import)
visitor = actions.AddingVisitor(pycore, candidates)
selected_import = normal_import
for import_statement in imports.imports:
if import_statement.accept(visitor):
selected_import = visitor.import_info
break
imports.add_import(selected_import)
imported_name = names[candidates.index(selected_import)]
return imports.get_changed_source(), imported_name
|
mit
|
[
624,
33,
2559,
367,
7252,
8925,
199,
199,
2765,
2559,
6571,
7249,
367,
24662,
859,
8925,
2410,
199,
264,
4778,
780,
503,
465,
282,
7396,
2120,
14,
199,
199,
624,
199,
646,
882,
321,
14,
1095,
14,
7383,
199,
504,
882,
321,
14,
1095,
14,
1461,
492,
7743,
1084,
12,
7743,
11383,
199,
504,
882,
321,
14,
264,
4778,
492,
22099,
12,
11441,
199,
504,
882,
321,
14,
264,
4778,
14,
646,
1208,
492,
859,
63,
12775,
12,
5445,
199,
504,
882,
321,
14,
264,
4778,
14,
646,
1208,
14,
646,
815,
492,
11514,
6295,
12,
11606,
6295,
199,
646,
882,
321,
14,
1095,
14,
600,
21184,
421,
199,
533,
3161,
11014,
290,
1793,
8,
785,
304,
272,
408,
20906,
2005,
492,
13,
2407,
3718,
339,
7048,
1083,
2529,
282,
658,
293,
321,
14,
1095,
14,
1461,
14,
4001,
64,
909,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
2199,
304,
267,
291,
14,
1715,
275,
2199,
267,
291,
14,
647,
1018,
275,
2199,
14,
647,
1018,
267,
291,
14,
646,
63,
2537,
275,
3161,
11654,
8,
277,
14,
647,
1018,
9,
339,
347,
20765,
794,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
19916,
794,
63,
12775,
12,
2073,
12,
3268,
9,
339,
347,
6544,
63,
7848,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
4441,
63,
270,
4291,
12,
2073,
12,
3268,
9,
339,
347,
687,
83,
63,
475,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
504,
83,
63,
475,
63,
12775,
12,
2073,
12,
3268,
9,
339,
347,
13773,
7301,
63,
475,
63,
2101,
393,
3862,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
17060,
7301,
63,
475,
63,
2101,
393,
3862,
12,
2073,
12,
3268,
9,
339,
347,
2429,
63,
2809,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
2479,
63,
2809,
63,
12775,
12,
2073,
12,
3268,
9,
339,
347,
485,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
277,
12,
1083,
12,
2073,
12,
3268,
304,
267,
1134,
578,
275,
291,
14,
647,
1018,
14,
1927,
63,
475,
63,
31614,
8,
1927,
9,
267,
2544,
63,
15795,
316,
275,
1134,
578,
14,
1365,
63,
600,
267,
492,
63,
1541,
275,
488,
267,
340,
3268,
365,
440,
488,
26,
288,
492,
63,
1541,
275,
291,
423,
604,
63,
1541,
8,
355,
1134,
578,
14,
1278,
14,
362,
63,
604,
63,
1955,
8,
2743,
430,
267,
754,
275,
1083,
8,
647,
578,
12,
492,
63,
1541,
29,
646,
63,
1541,
9,
267,
340,
754,
365,
440,
488,
436,
754,
1137,
2544,
63,
15795,
316,
26,
288,
4493,
275,
7743,
1084,
8,
765,
855,
354,
4343,
1814,
20928,
283,
5320,
435,
1816,
283,
315,
21808,
83,
3524,
450,
2073,
14,
515,
9,
288,
4493,
14,
525,
63,
1461,
8,
4001,
11383,
8,
1927,
12,
754,
430,
288,
372,
4493,
339,
347,
485,
604,
63,
1541,
8,
277,
12,
5874,
304,
267,
347,
492,
63,
1541,
8,
646,
63,
9649,
304,
288,
372,
492,
63,
9649,
14,
928,
63,
604,
2695,
5874,
665,
492,
63,
9649,
14,
500,
63,
604,
267,
372,
492,
63,
1541,
421,
199,
533,
3161,
11654,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1134,
1018,
304,
267,
291,
14,
647,
1018,
275,
1134,
1018,
339,
347,
664,
63,
646,
8,
277,
12,
2073,
304,
267,
408,
1918,
492,
5164,
367,
658,
1927,
64,
624,
267,
859,
63,
354,
275,
291,
14,
647,
1018,
14,
14789,
8,
1927,
9,
267,
372,
11514,
6295,
12925,
578,
63,
354,
12,
488,
395,
5082,
339,
347,
664,
63,
504,
63,
646,
8,
277,
12,
2073,
12,
536,
304,
267,
408,
1918,
687,
492,
5164,
367,
658,
354,
64,
315,
658,
1927,
64,
624,
267,
859,
63,
354,
275,
291,
14,
647,
1018,
14,
14789,
8,
1927,
9,
267,
1561,
275,
942,
267,
340,
1228,
8,
354,
12,
769,
304,
288,
1561,
275,
3842,
17932,
12,
488,
9,
367,
8439,
315,
536,
61,
267,
587,
26,
288,
1561,
275,
3842,
354,
12,
488,
395,
61,
267,
372,
11606,
6295,
8,
578,
63,
354,
12,
378,
12,
2008,
8,
1247,
430,
339,
347,
859,
63,
12775,
8,
277,
12,
859,
12,
8925,
63,
1541,
29,
403,
304,
267,
372,
859,
63,
12775,
14,
2377,
32447,
8,
277,
14,
647,
1018,
12,
859,
12,
4490,
8925,
63,
1541,
9,
339,
347,
687,
83,
63,
475,
63,
12775,
8,
277,
12,
1134,
578,
12,
492,
63,
1541,
29,
403,
304,
267,
1134,
578,
275,
291,
423,
3118,
63,
384,
63,
12775,
8,
647,
578,
12,
492,
63,
1541,
9,
267,
859,
63,
12775,
275,
291,
14,
578,
63,
12775,
8,
647,
578,
12,
492,
63,
1541,
9,
267,
367,
492,
63,
9649,
315,
859,
63,
12775,
14,
12775,
26,
288,
340,
492,
63,
9649,
14,
6753,
503,
971,
2049,
440,
291,
423,
374,
63,
4711,
461,
63,
475,
63,
3302,
8,
646,
63,
9649,
14,
646,
63,
815,
304,
355,
1980,
288,
1134,
578,
275,
291,
423,
504,
63,
475,
63,
3302,
8,
647,
578,
12,
492,
63,
9649,
9,
398,
327,
12934,
3293,
8925,
315,
4192,
402,
687,
83,
267,
859,
63,
12775,
275,
291,
14,
578,
63,
12775,
8,
647,
578,
12,
492,
63,
1541,
9,
267,
367,
492,
63,
9649,
315,
859,
63,
12775,
14,
12775,
26,
288,
340,
440,
492,
63,
9649,
14,
6753,
436,
971,
2049,
291,
423,
374,
63,
4711,
461,
63,
475,
63,
3302,
8,
646,
63,
9649,
14,
646,
63,
815,
304
] |
[
33,
2559,
367,
7252,
8925,
199,
199,
2765,
2559,
6571,
7249,
367,
24662,
859,
8925,
2410,
199,
264,
4778,
780,
503,
465,
282,
7396,
2120,
14,
199,
199,
624,
199,
646,
882,
321,
14,
1095,
14,
7383,
199,
504,
882,
321,
14,
1095,
14,
1461,
492,
7743,
1084,
12,
7743,
11383,
199,
504,
882,
321,
14,
264,
4778,
492,
22099,
12,
11441,
199,
504,
882,
321,
14,
264,
4778,
14,
646,
1208,
492,
859,
63,
12775,
12,
5445,
199,
504,
882,
321,
14,
264,
4778,
14,
646,
1208,
14,
646,
815,
492,
11514,
6295,
12,
11606,
6295,
199,
646,
882,
321,
14,
1095,
14,
600,
21184,
421,
199,
533,
3161,
11014,
290,
1793,
8,
785,
304,
272,
408,
20906,
2005,
492,
13,
2407,
3718,
339,
7048,
1083,
2529,
282,
658,
293,
321,
14,
1095,
14,
1461,
14,
4001,
64,
909,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
2199,
304,
267,
291,
14,
1715,
275,
2199,
267,
291,
14,
647,
1018,
275,
2199,
14,
647,
1018,
267,
291,
14,
646,
63,
2537,
275,
3161,
11654,
8,
277,
14,
647,
1018,
9,
339,
347,
20765,
794,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
19916,
794,
63,
12775,
12,
2073,
12,
3268,
9,
339,
347,
6544,
63,
7848,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
4441,
63,
270,
4291,
12,
2073,
12,
3268,
9,
339,
347,
687,
83,
63,
475,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
504,
83,
63,
475,
63,
12775,
12,
2073,
12,
3268,
9,
339,
347,
13773,
7301,
63,
475,
63,
2101,
393,
3862,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
17060,
7301,
63,
475,
63,
2101,
393,
3862,
12,
2073,
12,
3268,
9,
339,
347,
2429,
63,
2809,
63,
12775,
8,
277,
12,
2073,
12,
3268,
29,
403,
304,
267,
372,
291,
423,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
288,
291,
14,
646,
63,
2537,
14,
2479,
63,
2809,
63,
12775,
12,
2073,
12,
3268,
9,
339,
347,
485,
15795,
63,
1531,
63,
265,
63,
646,
63,
2537,
8,
277,
12,
1083,
12,
2073,
12,
3268,
304,
267,
1134,
578,
275,
291,
14,
647,
1018,
14,
1927,
63,
475,
63,
31614,
8,
1927,
9,
267,
2544,
63,
15795,
316,
275,
1134,
578,
14,
1365,
63,
600,
267,
492,
63,
1541,
275,
488,
267,
340,
3268,
365,
440,
488,
26,
288,
492,
63,
1541,
275,
291,
423,
604,
63,
1541,
8,
355,
1134,
578,
14,
1278,
14,
362,
63,
604,
63,
1955,
8,
2743,
430,
267,
754,
275,
1083,
8,
647,
578,
12,
492,
63,
1541,
29,
646,
63,
1541,
9,
267,
340,
754,
365,
440,
488,
436,
754,
1137,
2544,
63,
15795,
316,
26,
288,
4493,
275,
7743,
1084,
8,
765,
855,
354,
4343,
1814,
20928,
283,
5320,
435,
1816,
283,
315,
21808,
83,
3524,
450,
2073,
14,
515,
9,
288,
4493,
14,
525,
63,
1461,
8,
4001,
11383,
8,
1927,
12,
754,
430,
288,
372,
4493,
339,
347,
485,
604,
63,
1541,
8,
277,
12,
5874,
304,
267,
347,
492,
63,
1541,
8,
646,
63,
9649,
304,
288,
372,
492,
63,
9649,
14,
928,
63,
604,
2695,
5874,
665,
492,
63,
9649,
14,
500,
63,
604,
267,
372,
492,
63,
1541,
421,
199,
533,
3161,
11654,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1134,
1018,
304,
267,
291,
14,
647,
1018,
275,
1134,
1018,
339,
347,
664,
63,
646,
8,
277,
12,
2073,
304,
267,
408,
1918,
492,
5164,
367,
658,
1927,
64,
624,
267,
859,
63,
354,
275,
291,
14,
647,
1018,
14,
14789,
8,
1927,
9,
267,
372,
11514,
6295,
12925,
578,
63,
354,
12,
488,
395,
5082,
339,
347,
664,
63,
504,
63,
646,
8,
277,
12,
2073,
12,
536,
304,
267,
408,
1918,
687,
492,
5164,
367,
658,
354,
64,
315,
658,
1927,
64,
624,
267,
859,
63,
354,
275,
291,
14,
647,
1018,
14,
14789,
8,
1927,
9,
267,
1561,
275,
942,
267,
340,
1228,
8,
354,
12,
769,
304,
288,
1561,
275,
3842,
17932,
12,
488,
9,
367,
8439,
315,
536,
61,
267,
587,
26,
288,
1561,
275,
3842,
354,
12,
488,
395,
61,
267,
372,
11606,
6295,
8,
578,
63,
354,
12,
378,
12,
2008,
8,
1247,
430,
339,
347,
859,
63,
12775,
8,
277,
12,
859,
12,
8925,
63,
1541,
29,
403,
304,
267,
372,
859,
63,
12775,
14,
2377,
32447,
8,
277,
14,
647,
1018,
12,
859,
12,
4490,
8925,
63,
1541,
9,
339,
347,
687,
83,
63,
475,
63,
12775,
8,
277,
12,
1134,
578,
12,
492,
63,
1541,
29,
403,
304,
267,
1134,
578,
275,
291,
423,
3118,
63,
384,
63,
12775,
8,
647,
578,
12,
492,
63,
1541,
9,
267,
859,
63,
12775,
275,
291,
14,
578,
63,
12775,
8,
647,
578,
12,
492,
63,
1541,
9,
267,
367,
492,
63,
9649,
315,
859,
63,
12775,
14,
12775,
26,
288,
340,
492,
63,
9649,
14,
6753,
503,
971,
2049,
440,
291,
423,
374,
63,
4711,
461,
63,
475,
63,
3302,
8,
646,
63,
9649,
14,
646,
63,
815,
304,
355,
1980,
288,
1134,
578,
275,
291,
423,
504,
63,
475,
63,
3302,
8,
647,
578,
12,
492,
63,
9649,
9,
398,
327,
12934,
3293,
8925,
315,
4192,
402,
687,
83,
267,
859,
63,
12775,
275,
291,
14,
578,
63,
12775,
8,
647,
578,
12,
492,
63,
1541,
9,
267,
367,
492,
63,
9649,
315,
859,
63,
12775,
14,
12775,
26,
288,
340,
440,
492,
63,
9649,
14,
6753,
436,
971,
2049,
291,
423,
374,
63,
4711,
461,
63,
475,
63,
3302,
8,
646,
63,
9649,
14,
646,
63,
815,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ncated SVD transformer."""
import numpy as np
import scipy.sparse as sp
from sklearn.decomposition import TruncatedSVD
from sklearn.utils import check_random_state
from sklearn.utils.testing import (assert_array_almost_equal, assert_equal,
assert_raises, assert_greater,
assert_array_less)
# Make an X that looks somewhat like a small tf-idf matrix.
# XXX newer versions of SciPy have scipy.sparse.rand for this.
shape = 60, 55
n_samples, n_features = shape
rng = check_random_state(42)
X = rng.randint(-100, 20, np.product(shape)).reshape(shape)
X = sp.csr_matrix(np.maximum(X, 0), dtype=np.float64)
X.data[:] = 1 + np.log(X.data)
Xdense = X.A
def test_algorithms():
svd_a = TruncatedSVD(30, algorithm="arpack")
svd_r = TruncatedSVD(30, algorithm="randomized", random_state=42)
Xa = svd_a.fit_transform(X)[:, :6]
Xr = svd_r.fit_transform(X)[:, :6]
assert_array_almost_equal(Xa, Xr, decimal=5)
comp_a = np.abs(svd_a.components_)
comp_r = np.abs(svd_r.components_)
# All elements are equal, but some elements are more equal than others.
assert_array_almost_equal(comp_a[:9], comp_r[:9])
assert_array_almost_equal(comp_a[9:], comp_r[9:], decimal=2)
def test_attributes():
for n_components in (10, 25, 41):
tsvd = TruncatedSVD(n_components).fit(X)
assert_equal(tsvd.n_components, n_components)
assert_equal(tsvd.components_.shape, (n_components, n_features))
def test_too_many_components():
for algorithm in ["arpack", "randomized"]:
for n_components in (n_features, n_features + 1):
tsvd = TruncatedSVD(n_components=n_components, algorithm=algorithm)
assert_raises(ValueError, tsvd.fit, X)
def test_sparse_formats():
for fmt in ("array", "csr", "csc", "coo", "lil"):
Xfmt = Xdense if fmt == "dense" else getattr(X, "to" + fmt)()
tsvd = TruncatedSVD(n_components=11)
Xtrans = tsvd.fit_transform(Xfmt)
assert_equal(Xtrans.shape, (n_samples, 11))
Xtrans = tsvd.transform(Xfmt)
assert_equal(Xtrans.shape, (n_samples, 11))
def test_inverse_transform():
for algo in ("arpack", "randomized"):
# We need a lot of components for the reconstruction to be "almost
# equal" in all positions. XXX Test means or sums instead?
tsvd = TruncatedSVD(n_components=52, random_state=42, algorithm=algo)
Xt = tsvd.fit_transform(X)
Xinv = tsvd.inverse_transform(Xt)
assert_array_almost_equal(Xinv, Xdense, decimal=1)
def test_integers():
Xint = X.astype(np.int64)
tsvd = TruncatedSVD(n_components=6)
Xtrans = tsvd.fit_transform(Xint)
assert_equal(Xtrans.shape, (n_samples, tsvd.n_components))
def test_explained_variance():
# Test sparse data
svd_a_10_sp = TruncatedSVD(10, algorithm="arpack")
svd_r_10_sp = TruncatedSVD(10, algorithm="randomized", random_state=42)
svd_a_20_sp = TruncatedSVD(20, algorithm="arpack")
svd_r_20_sp = TruncatedSVD(20, algorithm="randomized", random_state=42)
X_trans_a_10_sp = svd_a_10_sp.fit_transform(X)
X_trans_r_10_sp = svd_r_10_sp.fit_transform(X)
X_trans_a_20_sp = svd_a_20_sp.fit_transform(X)
X_trans_r_20_sp = svd_r_20_sp.fit_transform(X)
# Test dense data
svd_a_10_de = TruncatedSVD(10, algorithm="arpack")
svd_r_10_de = TruncatedSVD(10, algorithm="randomized", random_state=42)
svd_a_20_de = TruncatedSVD(20, algorithm="arpack")
svd_r_20_de = TruncatedSVD(20, algorithm="randomized", random_state=42)
X_trans_a_10_de = svd_a_10_de.fit_transform(X.toarray())
X_trans_r_10_de = svd_r_10_de.fit_transform(X.toarray())
X_trans_a_20_de = svd_a_20_de.fit_transform(X.toarray())
X_trans_r_20_de = svd_r_20_de.fit_transform(X.toarray())
# helper arrays for tests below
svds = (svd_a_10_sp, svd_r_10_sp, svd_a_20_sp, svd_r_20_sp, svd_a_10_de,
svd_r_10_de, svd_a_20_de, svd_r_20_de)
svds_trans = (
(svd_a_10_sp, X_trans_a_10_sp),
(svd_r_10_sp, X_trans_r_10_sp),
(svd_a_20_sp, X_trans_a_20_sp),
(svd_r_20_sp, X_trans_r_20_sp),
(svd_a_10_de, X_trans_a_10_de),
(svd_r_10_de, X_trans_r_10_de),
(svd_a_20_de, X_trans_a_20_de),
(svd_r_20_de, X_trans_r_20_de),
)
svds_10_v_20 = (
(svd_a_10_sp, svd_a_20_sp),
(svd_r_10_sp, svd_r_20_sp),
(svd_a_10_de, svd_a_20_de),
(svd_r_10_de, svd_r_20_de),
)
svds_sparse_v_dense = (
(svd_a_10_sp, svd_a_10_de),
(svd_a_20_sp, svd_a_20_de),
(svd_r_10_sp, svd_r_10_de),
(svd_r_20_sp, svd_r_20_de),
)
# Assert the 1st component is equal
for svd_10, svd_20 in svds_10_v_20:
assert_array_almost_equal(
svd_10.explained_variance_ratio_,
svd_20.explained_variance_ratio_[:10],
decimal=5,
)
# Assert that 20 components has higher explained variance than 10
for svd_10, svd_20 in svds_10_v_20:
assert_greater(
svd_20.explained_variance_ratio_.sum(),
svd_10.explained_variance_ratio_.sum(),
)
# Assert that all the values are greater than 0
for svd in svds:
assert_array_less(0.0, svd.explained_variance_ratio_)
# Assert that total explained variance is less than 1
for svd in svds:
assert_array_less(svd.explained_variance_ratio_.sum(), 1.0)
# Compare sparse vs. dense
for svd_sparse, svd_dense in svds_sparse_v_dense:
assert_array_almost_equal(svd_sparse.explained_variance_ratio_,
svd_dense.explained_variance_ratio_)
# Test that explained_variance is correct
for svd, transformed in svds_trans:
total_variance = np.var(X.toarray(), axis=0).sum()
variances = np.var(transformed, axis=0)
true_explained_variance_ratio = variances / total_variance
assert_array_almost_equal(
svd.explained_variance_ratio_,
true_explained_variance_ratio,
)
def test_singular_values():
# Check that the TruncatedSVD output has the correct singular values
rng = np.random.RandomState(0)
n_samples = 100
n_features = 80
X = rng.randn(n_samples, n_features)
apca = TruncatedSVD(n_components=2, algorithm='arpack',
random_state=rng).fit(X)
rpca = TruncatedSVD(n_components=2, algorithm='arpack',
random_state=rng).fit(X)
assert_array_almost_equal(apca.singular_values_, rpca.singular_values_, 12)
# Compare to the Frobenius norm
X_apca = apca.transform(X)
X_rpca = rpca.transform(X)
assert_array_almost_equal(np.sum(apca.singular_values_**2.0),
np.linalg.norm(X_apca, "fro")**2.0, 12)
assert_array_almost_equal(np.sum(rpca.singular_values_**2.0),
np.linalg.norm(X_rpca, "fro")**2.0, 12)
# Compare to the 2-norms of the score vectors
assert_array_almost_equal(apca.singular_values_,
np.sqrt(np.sum(X_apca**2.0, axis=0)), 12)
assert_array_almost_equal(rpca.singular_values_,
np.sqrt(np.sum(X_rpca**2.0, axis=0)), 12)
# Set the singular values and see what we get back
rng = np.random.RandomState(0)
n_samples = 100
n_features = 110
X = rng.randn(n_samples, n_features)
apca = TruncatedSVD(n_components=3, algorithm='arpack',
random_state=rng)
rpca = TruncatedSVD(n_components=3, algorithm='randomized',
random_state=rng)
X_apca = apca.fit_transform(X)
X_rpca = rpca.fit_transform(X)
X_apca /= np.sqrt(np.sum(X_apca**2.0, axis=0))
X_rpca /= np.sqrt(np.sum(X_rpca**2.0, axis=0))
X_apca[:, 0] *= 3.142
X_apca[:, 1] *= 2.718
X_rpca[:, 0] *= 3.142
X_rpca[:, 1] *= 2.718
X_hat_apca = np.dot(X_apca, apca.components_)
X_hat_rpca = np.dot(X_rpca, rpca.components_)
apca.fit(X_hat_apca)
rpca.fit(X_hat_rpca)
assert_array_almost_equal(apca.singular_values_, [3.142, 2.718, 1.0], 14)
assert_array_almost_equal(rpca.singular_values_, [3.142, 2.718, 1.0], 14)
|
bsd-3-clause
|
[
624,
774,
17661,
14056,
36,
21484,
1041,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
199,
504,
6357,
14,
31384,
492,
25594,
3153,
4985,
36,
199,
504,
6357,
14,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
6357,
14,
1208,
14,
4776,
492,
334,
479,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
1452,
12,
3521,
702,
63,
3536,
12,
702,
63,
13154,
12,
3521,
702,
63,
1144,
63,
2003,
9,
421,
199,
3,
4155,
376,
1323,
626,
10734,
30362,
2839,
282,
7425,
2833,
13,
24003,
3634,
14,
199,
3,
5787,
15666,
5459,
402,
16578,
2713,
1172,
7026,
14,
4421,
14,
3759,
367,
642,
14,
199,
1392,
275,
5212,
12,
12766,
199,
78,
63,
3356,
12,
302,
63,
3179,
275,
2215,
199,
12686,
275,
1104,
63,
2355,
63,
929,
8,
2260,
9,
199,
56,
275,
9038,
14,
8393,
2801,
1960,
12,
3388,
12,
980,
14,
2558,
8,
1392,
4992,
5217,
8,
1392,
9,
199,
56,
275,
2249,
14,
10101,
63,
3642,
8,
1590,
14,
11555,
8,
56,
12,
378,
395,
2152,
29,
1590,
14,
1609,
772,
9,
199,
56,
14,
576,
5873,
275,
413,
435,
980,
14,
793,
8,
56,
14,
576,
9,
199,
56,
7253,
275,
1323,
14,
33,
421,
199,
318,
511,
63,
24365,
837,
272,
26937,
63,
65,
275,
25594,
3153,
4985,
36,
8,
1216,
12,
5563,
628,
285,
1389,
531,
272,
26937,
63,
82,
275,
25594,
3153,
4985,
36,
8,
1216,
12,
5563,
628,
2355,
1759,
401,
2196,
63,
929,
29,
2260,
9,
339,
1323,
65,
275,
26937,
63,
65,
14,
3269,
63,
4711,
8,
56,
24517,
520,
22,
61,
272,
1323,
82,
275,
26937,
63,
82,
14,
3269,
63,
4711,
8,
56,
24517,
520,
22,
61,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
56,
65,
12,
1323,
82,
12,
6107,
29,
21,
9,
339,
1013,
63,
65,
275,
980,
14,
2101,
8,
18675,
63,
65,
14,
4608,
4602,
272,
1013,
63,
82,
275,
980,
14,
2101,
8,
18675,
63,
82,
14,
4608,
4602,
272,
327,
2900,
4008,
787,
4472,
12,
1325,
2005,
4008,
787,
1655,
4472,
2419,
11789,
14,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
863,
63,
65,
1491,
25,
467,
1013,
63,
82,
1491,
25,
566,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
863,
63,
65,
59,
25,
8429,
1013,
63,
82,
59,
25,
8429,
6107,
29,
18,
9,
421,
199,
318,
511,
63,
2987,
837,
272,
367,
302,
63,
4608,
315,
334,
709,
12,
5661,
12,
13385,
304,
267,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
680,
3269,
8,
56,
9,
267,
702,
63,
1452,
8,
1086,
11549,
14,
78,
63,
4608,
12,
302,
63,
4608,
9,
267,
702,
63,
1452,
8,
1086,
11549,
14,
4608,
3754,
1392,
12,
334,
78,
63,
4608,
12,
302,
63,
3179,
430,
421,
199,
318,
511,
63,
7354,
63,
3479,
63,
4608,
837,
272,
367,
5563,
315,
2097,
285,
1389,
401,
298,
2355,
1759,
6229,
267,
367,
302,
63,
4608,
315,
334,
78,
63,
3179,
12,
302,
63,
3179,
435,
413,
304,
288,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
5563,
29,
8833,
9,
288,
702,
63,
3536,
8,
3393,
12,
307,
18675,
14,
3269,
12,
1323,
9,
421,
199,
318,
511,
63,
4421,
63,
6321,
837,
272,
367,
7104,
315,
1689,
1144,
401,
298,
10101,
401,
298,
17000,
401,
298,
22684,
401,
298,
317,
76,
2349,
267,
1323,
5045,
275,
1323,
7253,
340,
7104,
508,
298,
7253,
2,
587,
2519,
8,
56,
12,
298,
475,
2,
435,
7104,
16315,
267,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
845,
9,
267,
1323,
1515,
275,
307,
18675,
14,
3269,
63,
4711,
8,
56,
5045,
9,
267,
702,
63,
1452,
8,
56,
1515,
14,
1392,
12,
334,
78,
63,
3356,
12,
4119,
430,
267,
1323,
1515,
275,
307,
18675,
14,
4711,
8,
56,
5045,
9,
267,
702,
63,
1452,
8,
56,
1515,
14,
1392,
12,
334,
78,
63,
3356,
12,
4119,
430,
421,
199,
318,
511,
63,
11668,
63,
4711,
837,
272,
367,
24633,
315,
1689,
285,
1389,
401,
298,
2355,
1759,
2349,
267,
327,
2136,
1929,
282,
13918,
402,
7323,
367,
314,
295,
12708,
370,
506,
298,
4398,
267,
327,
4472,
2,
315,
1006,
12266,
14,
5787,
1379,
4910,
503,
27690,
3140,
31,
267,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
2528,
12,
2196,
63,
929,
29,
2260,
12,
5563,
29,
21734,
9,
267,
1323,
84,
275,
307,
18675,
14,
3269,
63,
4711,
8,
56,
9,
267,
1323,
5350,
275,
307,
18675,
14,
11668,
63,
4711,
8,
56,
84,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
56,
5350,
12,
1323,
7253,
12,
6107,
29,
17,
9,
421,
199,
318,
511,
63,
23931,
837,
272,
1323,
442,
275,
1323,
14,
6041,
8,
1590,
14,
442,
772,
9,
272,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
22,
9,
272,
1323,
1515,
275,
307,
18675,
14,
3269,
63,
4711,
8,
56,
442,
9,
272,
702,
63,
1452,
8,
56,
1515,
14,
1392,
12,
334,
78,
63,
3356,
12,
307,
18675,
14,
78,
63,
4608,
430,
421,
199,
318,
511,
63,
1474,
23918,
63,
6221,
837,
272,
327,
1379,
5178,
666,
272,
26937,
63,
65,
63,
709,
63,
681,
275,
25594,
3153,
4985,
36,
8,
709,
12,
5563,
628,
285,
1389,
531,
272,
26937,
63,
82,
63,
709,
63,
681,
275,
25594,
3153,
4985,
36,
8,
709,
12,
5563,
628,
2355,
1759,
401,
2196,
63,
929,
29,
2260,
9,
272,
26937,
63,
65,
63,
1165,
63,
681,
275,
25594,
3153,
4985,
36,
8,
1165,
12,
5563,
628,
285,
1389,
531,
272,
26937,
63,
82,
63,
1165,
63,
681,
275,
25594,
3153,
4985,
36,
8,
1165,
12,
5563,
628,
2355,
1759,
401,
2196,
63,
929,
29,
2260,
9,
272,
1323,
63,
1515,
63,
65,
63,
709,
63,
681,
275,
26937,
63,
65,
63,
709,
63,
681,
14,
3269,
63,
4711,
8,
56,
9,
272,
1323,
63,
1515,
63,
82,
63,
709,
63,
681,
275,
26937,
63,
82,
63,
709,
63,
681
] |
[
774,
17661,
14056,
36,
21484,
1041,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4421,
465,
2249,
199,
199,
504,
6357,
14,
31384,
492,
25594,
3153,
4985,
36,
199,
504,
6357,
14,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
6357,
14,
1208,
14,
4776,
492,
334,
479,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
1452,
12,
3521,
702,
63,
3536,
12,
702,
63,
13154,
12,
3521,
702,
63,
1144,
63,
2003,
9,
421,
199,
3,
4155,
376,
1323,
626,
10734,
30362,
2839,
282,
7425,
2833,
13,
24003,
3634,
14,
199,
3,
5787,
15666,
5459,
402,
16578,
2713,
1172,
7026,
14,
4421,
14,
3759,
367,
642,
14,
199,
1392,
275,
5212,
12,
12766,
199,
78,
63,
3356,
12,
302,
63,
3179,
275,
2215,
199,
12686,
275,
1104,
63,
2355,
63,
929,
8,
2260,
9,
199,
56,
275,
9038,
14,
8393,
2801,
1960,
12,
3388,
12,
980,
14,
2558,
8,
1392,
4992,
5217,
8,
1392,
9,
199,
56,
275,
2249,
14,
10101,
63,
3642,
8,
1590,
14,
11555,
8,
56,
12,
378,
395,
2152,
29,
1590,
14,
1609,
772,
9,
199,
56,
14,
576,
5873,
275,
413,
435,
980,
14,
793,
8,
56,
14,
576,
9,
199,
56,
7253,
275,
1323,
14,
33,
421,
199,
318,
511,
63,
24365,
837,
272,
26937,
63,
65,
275,
25594,
3153,
4985,
36,
8,
1216,
12,
5563,
628,
285,
1389,
531,
272,
26937,
63,
82,
275,
25594,
3153,
4985,
36,
8,
1216,
12,
5563,
628,
2355,
1759,
401,
2196,
63,
929,
29,
2260,
9,
339,
1323,
65,
275,
26937,
63,
65,
14,
3269,
63,
4711,
8,
56,
24517,
520,
22,
61,
272,
1323,
82,
275,
26937,
63,
82,
14,
3269,
63,
4711,
8,
56,
24517,
520,
22,
61,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
56,
65,
12,
1323,
82,
12,
6107,
29,
21,
9,
339,
1013,
63,
65,
275,
980,
14,
2101,
8,
18675,
63,
65,
14,
4608,
4602,
272,
1013,
63,
82,
275,
980,
14,
2101,
8,
18675,
63,
82,
14,
4608,
4602,
272,
327,
2900,
4008,
787,
4472,
12,
1325,
2005,
4008,
787,
1655,
4472,
2419,
11789,
14,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
863,
63,
65,
1491,
25,
467,
1013,
63,
82,
1491,
25,
566,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
863,
63,
65,
59,
25,
8429,
1013,
63,
82,
59,
25,
8429,
6107,
29,
18,
9,
421,
199,
318,
511,
63,
2987,
837,
272,
367,
302,
63,
4608,
315,
334,
709,
12,
5661,
12,
13385,
304,
267,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
680,
3269,
8,
56,
9,
267,
702,
63,
1452,
8,
1086,
11549,
14,
78,
63,
4608,
12,
302,
63,
4608,
9,
267,
702,
63,
1452,
8,
1086,
11549,
14,
4608,
3754,
1392,
12,
334,
78,
63,
4608,
12,
302,
63,
3179,
430,
421,
199,
318,
511,
63,
7354,
63,
3479,
63,
4608,
837,
272,
367,
5563,
315,
2097,
285,
1389,
401,
298,
2355,
1759,
6229,
267,
367,
302,
63,
4608,
315,
334,
78,
63,
3179,
12,
302,
63,
3179,
435,
413,
304,
288,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
5563,
29,
8833,
9,
288,
702,
63,
3536,
8,
3393,
12,
307,
18675,
14,
3269,
12,
1323,
9,
421,
199,
318,
511,
63,
4421,
63,
6321,
837,
272,
367,
7104,
315,
1689,
1144,
401,
298,
10101,
401,
298,
17000,
401,
298,
22684,
401,
298,
317,
76,
2349,
267,
1323,
5045,
275,
1323,
7253,
340,
7104,
508,
298,
7253,
2,
587,
2519,
8,
56,
12,
298,
475,
2,
435,
7104,
16315,
267,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
845,
9,
267,
1323,
1515,
275,
307,
18675,
14,
3269,
63,
4711,
8,
56,
5045,
9,
267,
702,
63,
1452,
8,
56,
1515,
14,
1392,
12,
334,
78,
63,
3356,
12,
4119,
430,
267,
1323,
1515,
275,
307,
18675,
14,
4711,
8,
56,
5045,
9,
267,
702,
63,
1452,
8,
56,
1515,
14,
1392,
12,
334,
78,
63,
3356,
12,
4119,
430,
421,
199,
318,
511,
63,
11668,
63,
4711,
837,
272,
367,
24633,
315,
1689,
285,
1389,
401,
298,
2355,
1759,
2349,
267,
327,
2136,
1929,
282,
13918,
402,
7323,
367,
314,
295,
12708,
370,
506,
298,
4398,
267,
327,
4472,
2,
315,
1006,
12266,
14,
5787,
1379,
4910,
503,
27690,
3140,
31,
267,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
2528,
12,
2196,
63,
929,
29,
2260,
12,
5563,
29,
21734,
9,
267,
1323,
84,
275,
307,
18675,
14,
3269,
63,
4711,
8,
56,
9,
267,
1323,
5350,
275,
307,
18675,
14,
11668,
63,
4711,
8,
56,
84,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
56,
5350,
12,
1323,
7253,
12,
6107,
29,
17,
9,
421,
199,
318,
511,
63,
23931,
837,
272,
1323,
442,
275,
1323,
14,
6041,
8,
1590,
14,
442,
772,
9,
272,
307,
18675,
275,
25594,
3153,
4985,
36,
8,
78,
63,
4608,
29,
22,
9,
272,
1323,
1515,
275,
307,
18675,
14,
3269,
63,
4711,
8,
56,
442,
9,
272,
702,
63,
1452,
8,
56,
1515,
14,
1392,
12,
334,
78,
63,
3356,
12,
307,
18675,
14,
78,
63,
4608,
430,
421,
199,
318,
511,
63,
1474,
23918,
63,
6221,
837,
272,
327,
1379,
5178,
666,
272,
26937,
63,
65,
63,
709,
63,
681,
275,
25594,
3153,
4985,
36,
8,
709,
12,
5563,
628,
285,
1389,
531,
272,
26937,
63,
82,
63,
709,
63,
681,
275,
25594,
3153,
4985,
36,
8,
709,
12,
5563,
628,
2355,
1759,
401,
2196,
63,
929,
29,
2260,
9,
272,
26937,
63,
65,
63,
1165,
63,
681,
275,
25594,
3153,
4985,
36,
8,
1165,
12,
5563,
628,
285,
1389,
531,
272,
26937,
63,
82,
63,
1165,
63,
681,
275,
25594,
3153,
4985,
36,
8,
1165,
12,
5563,
628,
2355,
1759,
401,
2196,
63,
929,
29,
2260,
9,
272,
1323,
63,
1515,
63,
65,
63,
709,
63,
681,
275,
26937,
63,
65,
63,
709,
63,
681,
14,
3269,
63,
4711,
8,
56,
9,
272,
1323,
63,
1515,
63,
82,
63,
709,
63,
681,
275,
26937,
63,
82,
63,
709,
63,
681,
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,
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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
] |
StefanRijnhart/odoo
|
addons/report/models/abstract_report.py
|
96
|
2900
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014-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/>.
#
##############################################################################
from openerp.osv import osv
class AbstractReport(osv.AbstractModel):
"""Model used to embed old style reports"""
_name = 'report.abstract_report'
_template = None
_wrapped_report_class = None
def render_html(self, cr, uid, ids, data=None, context=None):
context = dict(context or {})
# If the key 'landscape' is present in data['form'], passing it into the context
if data and data.get('form', {}).get('landscape'):
context['landscape'] = True
if context and context.get('active_ids'):
# Browse the selected objects via their reference in context
model = context.get('active_model') or context.get('model')
objects_model = self.pool[model]
objects = objects_model.browse(cr, uid, context['active_ids'], context=context)
else:
# If no context is set (for instance, during test execution), build one
model = self.pool['report']._get_report_from_name(cr, uid, self._template).model
objects_model = self.pool[model]
objects = objects_model.browse(cr, uid, ids, context=context)
context['active_model'] = model
context['active_ids'] = ids
# Generate the old style report
wrapped_report = self._wrapped_report_class(cr, uid, '', context=context)
wrapped_report.set_context(objects, data, context['active_ids'])
# Rendering self._template with the wrapped report instance localcontext as
# rendering environment
docargs = wrapped_report.localcontext
docargs['docs'] = docargs.get('objects')
# Used in template translation (see translate_doc method from report model)
docargs['doc_ids'] = context['active_ids']
docargs['doc_model'] = model
return self.pool['report'].render(cr, uid, [], self._template, docargs, context=context)
|
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,
6927,
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,
199,
504,
5166,
14,
4795,
492,
9506,
421,
199,
533,
11836,
7457,
8,
4795,
14,
8458,
1685,
304,
272,
408,
1685,
1202,
370,
6441,
2269,
3449,
13924,
624,
272,
485,
354,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
488,
272,
485,
9130,
63,
3070,
63,
533,
275,
488,
339,
347,
3795,
63,
1360,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
666,
29,
403,
12,
1067,
29,
403,
304,
267,
1067,
275,
1211,
8,
1100,
503,
5009,
398,
327,
982,
314,
790,
283,
9688,
3588,
7,
365,
3451,
315,
666,
459,
964,
995,
9476,
652,
1901,
314,
1067,
267,
340,
666,
436,
666,
14,
362,
360,
964,
297,
13056,
362,
360,
9688,
3588,
735,
288,
1067,
459,
9688,
3588,
418,
275,
715,
398,
340,
1067,
436,
1067,
14,
362,
360,
2682,
63,
1580,
735,
288,
327,
699,
13300,
314,
4895,
2251,
4799,
3932,
3659,
315,
1067,
288,
1402,
275,
1067,
14,
362,
360,
2682,
63,
1238,
358,
503,
1067,
14,
362,
360,
1238,
358,
288,
2251,
63,
1238,
275,
291,
14,
2293,
59,
1238,
61,
288,
2251,
275,
2251,
63,
1238,
14,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
1580,
995,
1067,
29,
1100,
9,
267,
587,
26,
288,
327,
982,
949,
1067,
365,
663,
334,
509,
1256,
12,
5309,
511,
6451,
395,
1900,
1373,
288,
1402,
275,
291,
14,
2293,
459,
3070,
26099,
362,
63,
3070,
63,
504,
63,
354,
8,
1556,
12,
1747,
12,
291,
423,
1160,
680,
1238,
288,
2251,
63,
1238,
275,
291,
14,
2293,
59,
1238,
61,
288,
2251,
275,
2251,
63,
1238,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
288,
1067,
459,
2682,
63,
1238,
418,
275,
1402,
288,
1067,
459,
2682,
63,
1580,
418,
275,
2762,
398,
327,
7958,
314,
2269,
3449,
3622,
267,
8072,
63,
3070,
275,
291,
423,
9130,
63,
3070,
63,
533,
8,
1556,
12,
1747,
12,
3260,
221,
1067,
29,
1100,
9,
267,
8072,
63,
3070,
14,
409,
63,
1100,
8,
1462,
12,
666,
12,
1067,
459,
2682,
63,
1580,
1105,
398,
327,
17769,
316,
291,
423,
1160,
543,
314,
8072,
3622,
1256,
2257,
1100,
465,
267,
327,
14066,
3734,
267,
1382,
589,
275,
8072,
63,
3070,
14,
17886,
267,
1382,
589,
459,
4757,
418,
275,
1382,
589,
14,
362,
360,
1462,
358,
398,
327,
8051,
315,
1978,
7761,
334,
3239,
9028,
63,
1301,
1083,
687,
3622,
1402,
9,
267,
1382,
589,
459,
1301,
63,
1580,
418,
275,
1067,
459,
2682,
63,
1580,
418,
267,
1382,
589,
459,
1301,
63,
1238,
418,
275,
1402,
398,
372,
291,
14,
2293,
459,
3070,
2278,
3352,
8,
1556,
12,
1747,
12,
990,
291,
423,
1160,
12,
1382,
589,
12,
1067,
29,
1100,
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
] |
[
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,
6927,
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,
199,
504,
5166,
14,
4795,
492,
9506,
421,
199,
533,
11836,
7457,
8,
4795,
14,
8458,
1685,
304,
272,
408,
1685,
1202,
370,
6441,
2269,
3449,
13924,
624,
272,
485,
354,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
488,
272,
485,
9130,
63,
3070,
63,
533,
275,
488,
339,
347,
3795,
63,
1360,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
666,
29,
403,
12,
1067,
29,
403,
304,
267,
1067,
275,
1211,
8,
1100,
503,
5009,
398,
327,
982,
314,
790,
283,
9688,
3588,
7,
365,
3451,
315,
666,
459,
964,
995,
9476,
652,
1901,
314,
1067,
267,
340,
666,
436,
666,
14,
362,
360,
964,
297,
13056,
362,
360,
9688,
3588,
735,
288,
1067,
459,
9688,
3588,
418,
275,
715,
398,
340,
1067,
436,
1067,
14,
362,
360,
2682,
63,
1580,
735,
288,
327,
699,
13300,
314,
4895,
2251,
4799,
3932,
3659,
315,
1067,
288,
1402,
275,
1067,
14,
362,
360,
2682,
63,
1238,
358,
503,
1067,
14,
362,
360,
1238,
358,
288,
2251,
63,
1238,
275,
291,
14,
2293,
59,
1238,
61,
288,
2251,
275,
2251,
63,
1238,
14,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
1580,
995,
1067,
29,
1100,
9,
267,
587,
26,
288,
327,
982,
949,
1067,
365,
663,
334,
509,
1256,
12,
5309,
511,
6451,
395,
1900,
1373,
288,
1402,
275,
291,
14,
2293,
459,
3070,
26099,
362,
63,
3070,
63,
504,
63,
354,
8,
1556,
12,
1747,
12,
291,
423,
1160,
680,
1238,
288,
2251,
63,
1238,
275,
291,
14,
2293,
59,
1238,
61,
288,
2251,
275,
2251,
63,
1238,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
288,
1067,
459,
2682,
63,
1238,
418,
275,
1402,
288,
1067,
459,
2682,
63,
1580,
418,
275,
2762,
398,
327,
7958,
314,
2269,
3449,
3622,
267,
8072,
63,
3070,
275,
291,
423,
9130,
63,
3070,
63,
533,
8,
1556,
12,
1747,
12,
3260,
221,
1067,
29,
1100,
9,
267,
8072,
63,
3070,
14,
409,
63,
1100,
8,
1462,
12,
666,
12,
1067,
459,
2682,
63,
1580,
1105,
398,
327,
17769,
316,
291,
423,
1160,
543,
314,
8072,
3622,
1256,
2257,
1100,
465,
267,
327,
14066,
3734,
267,
1382,
589,
275,
8072,
63,
3070,
14,
17886,
267,
1382,
589,
459,
4757,
418,
275,
1382,
589,
14,
362,
360,
1462,
358,
398,
327,
8051,
315,
1978,
7761,
334,
3239,
9028,
63,
1301,
1083,
687,
3622,
1402,
9,
267,
1382,
589,
459,
1301,
63,
1580,
418,
275,
1067,
459,
2682,
63,
1580,
418,
267,
1382,
589,
459,
1301,
63,
1238,
418,
275,
1402,
398,
372,
291,
14,
2293,
459,
3070,
2278,
3352,
8,
1556,
12,
1747,
12,
990,
291,
423,
1160,
12,
1382,
589,
12,
1067,
29,
1100,
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,
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,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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
] |
StephenRJ/cm12_kernel_moto_shamu
|
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
|
12527
|
1935
|
# Util.py - Python extension for perf script, miscellaneous utility code
#
# Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com>
#
# This software may be distributed under the terms of the GNU General
# Public License ("GPL") version 2 as published by the Free Software
# Foundation.
import errno, os
FUTEX_WAIT = 0
FUTEX_WAKE = 1
FUTEX_PRIVATE_FLAG = 128
FUTEX_CLOCK_REALTIME = 256
FUTEX_CMD_MASK = ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
NSECS_PER_SEC = 1000000000
def avg(total, n):
return total / n
def nsecs(secs, nsecs):
return secs * NSECS_PER_SEC + nsecs
def nsecs_secs(nsecs):
return nsecs / NSECS_PER_SEC
def nsecs_nsecs(nsecs):
return nsecs % NSECS_PER_SEC
def nsecs_str(nsecs):
str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
return str
def add_stats(dict, key, value):
if not dict.has_key(key):
dict[key] = (value, value, value, 1)
else:
min, max, avg, count = dict[key]
if value < min:
min = value
if value > max:
max = value
avg = (avg + value) / 2
dict[key] = (min, max, avg, count + 1)
def clear_term():
print("\x1b[H\x1b[2J")
audit_package_warned = False
try:
import audit
machine_to_id = {
'x86_64': audit.MACH_86_64,
'alpha' : audit.MACH_ALPHA,
'ia64' : audit.MACH_IA64,
'ppc' : audit.MACH_PPC,
'ppc64' : audit.MACH_PPC64,
's390' : audit.MACH_S390,
's390x' : audit.MACH_S390X,
'i386' : audit.MACH_X86,
'i586' : audit.MACH_X86,
'i686' : audit.MACH_X86,
}
try:
machine_to_id['armeb'] = audit.MACH_ARMEB
except:
pass
machine_id = machine_to_id[os.uname()[4]]
except:
if not audit_package_warned:
audit_package_warned = True
print "Install the audit-libs-python package to get syscall names"
def syscall_name(id):
try:
return audit.audit_syscall_to_name(id, machine_id)
except:
return str(id)
def strerror(nr):
try:
return errno.errorcode[abs(nr)]
except:
return "Unknown %d errno" % nr
|
gpl-2.0
|
[
3,
21248,
14,
647,
446,
2018,
3329,
367,
8582,
2884,
12,
3201,
19549,
11420,
1233,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
1443,
506,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
199,
199,
646,
7554,
12,
747,
199,
199,
31179,
63,
12458,
275,
378,
199,
31179,
63,
9004,
2430,
275,
413,
199,
31179,
63,
18748,
63,
3719,
275,
7960,
199,
31179,
63,
30690,
63,
15508,
4961,
275,
7633,
199,
31179,
63,
9744,
63,
12880,
275,
6146,
8,
31179,
63,
18748,
63,
3719,
1204,
481,
934,
1438,
63,
30690,
63,
15508,
4961,
9,
199,
199,
46,
28466,
63,
4227,
63,
15048,
259,
275,
413,
25464,
199,
199,
318,
12402,
8,
2923,
12,
302,
304,
272,
372,
3141,
1182,
302,
199,
199,
318,
13781,
8,
4855,
12,
13781,
304,
272,
372,
20091,
627,
653,
28466,
63,
4227,
63,
15048,
435,
13781,
199,
199,
318,
13781,
63,
4855,
8,
9618,
304,
272,
372,
13781,
1182,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
9618,
8,
9618,
304,
272,
372,
13781,
450,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
495,
8,
9618,
304,
272,
620,
275,
2071,
21,
85,
4111,
1643,
85,
2,
450,
334,
9618,
63,
4855,
8,
9618,
395,
13781,
63,
9618,
8,
9618,
1826,
272,
372,
620,
199,
199,
318,
1050,
63,
3200,
8,
807,
12,
790,
12,
574,
304,
199,
198,
692,
440,
1211,
14,
1989,
63,
498,
8,
498,
304,
507,
198,
807,
59,
498,
61,
275,
334,
585,
12,
574,
12,
574,
12,
413,
9,
199,
198,
2836,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
1211,
59,
498,
61,
507,
198,
692,
574,
665,
1748,
26,
686,
198,
827,
275,
574,
507,
198,
692,
574,
690,
1390,
26,
686,
198,
988,
275,
574,
507,
198,
8595,
275,
334,
8595,
435,
574,
9,
1182,
499,
507,
198,
807,
59,
498,
61,
275,
334,
827,
12,
1390,
12,
12402,
12,
2338,
435,
413,
9,
199,
199,
318,
5436,
63,
5125,
837,
272,
870,
4582,
88,
17,
66,
59,
40,
60,
88,
17,
66,
59,
18,
42,
531,
199,
199,
14274,
63,
2491,
63,
4050,
379,
275,
756,
199,
199,
893,
26,
199,
198,
646,
13968,
199,
198,
6744,
63,
475,
63,
344,
275,
469,
507,
198,
7,
88,
1184,
63,
772,
356,
13968,
14,
13802,
63,
1184,
63,
772,
12,
507,
198,
7,
4468,
7,
198,
26,
13968,
14,
13802,
63,
18554,
12,
507,
198,
7,
4674,
772,
7,
198,
26,
13968,
14,
13802,
63,
13033,
772,
12,
507,
198,
7,
20638,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
12,
507,
198,
7,
20638,
772,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
772,
12,
507,
198,
1159,
12302,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
12,
507,
198,
1159,
12302,
88,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
56,
12,
507,
198,
7,
73,
8040,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
26888,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
10253,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
199,
198,
93,
199,
198,
893,
26,
507,
198,
6744,
63,
475,
63,
344,
459,
285,
278,
66,
418,
275,
13968,
14,
13802,
63,
689,
3635,
34,
199,
198,
2590,
26,
507,
198,
1529,
199,
198,
6744,
63,
344,
275,
6844,
63,
475,
63,
344,
59,
736,
14,
16040,
3430,
20,
2677,
199,
2590,
26,
199,
198,
692,
440,
13968,
63,
2491,
63,
4050,
379,
26,
507,
198,
14274,
63,
2491,
63,
4050,
379,
275,
715,
507,
198,
1361,
298,
8154,
314,
13968,
13,
8450,
13,
1548,
2559,
370,
664,
18901,
1561,
2,
199,
199,
318,
18901,
63,
354,
8,
344,
304,
199,
198,
893,
26,
507,
198,
1107,
13968,
14,
14274,
63,
19444,
63,
475,
63,
354,
8,
344,
12,
6844,
63,
344,
9,
199,
198,
2590,
26,
507,
198,
1107,
620,
8,
344,
9,
199,
199,
318,
410,
17844,
8,
7865,
304,
199,
198,
893,
26,
507,
198,
1107,
7554,
14,
28857,
59,
2101,
8,
7865,
1874,
199,
198,
2590,
26,
507,
198,
1107,
298,
5912,
450,
68,
7554,
2,
450,
14762,
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
] |
[
21248,
14,
647,
446,
2018,
3329,
367,
8582,
2884,
12,
3201,
19549,
11420,
1233,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
1443,
506,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
199,
199,
646,
7554,
12,
747,
199,
199,
31179,
63,
12458,
275,
378,
199,
31179,
63,
9004,
2430,
275,
413,
199,
31179,
63,
18748,
63,
3719,
275,
7960,
199,
31179,
63,
30690,
63,
15508,
4961,
275,
7633,
199,
31179,
63,
9744,
63,
12880,
275,
6146,
8,
31179,
63,
18748,
63,
3719,
1204,
481,
934,
1438,
63,
30690,
63,
15508,
4961,
9,
199,
199,
46,
28466,
63,
4227,
63,
15048,
259,
275,
413,
25464,
199,
199,
318,
12402,
8,
2923,
12,
302,
304,
272,
372,
3141,
1182,
302,
199,
199,
318,
13781,
8,
4855,
12,
13781,
304,
272,
372,
20091,
627,
653,
28466,
63,
4227,
63,
15048,
435,
13781,
199,
199,
318,
13781,
63,
4855,
8,
9618,
304,
272,
372,
13781,
1182,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
9618,
8,
9618,
304,
272,
372,
13781,
450,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
495,
8,
9618,
304,
272,
620,
275,
2071,
21,
85,
4111,
1643,
85,
2,
450,
334,
9618,
63,
4855,
8,
9618,
395,
13781,
63,
9618,
8,
9618,
1826,
272,
372,
620,
199,
199,
318,
1050,
63,
3200,
8,
807,
12,
790,
12,
574,
304,
199,
198,
692,
440,
1211,
14,
1989,
63,
498,
8,
498,
304,
507,
198,
807,
59,
498,
61,
275,
334,
585,
12,
574,
12,
574,
12,
413,
9,
199,
198,
2836,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
1211,
59,
498,
61,
507,
198,
692,
574,
665,
1748,
26,
686,
198,
827,
275,
574,
507,
198,
692,
574,
690,
1390,
26,
686,
198,
988,
275,
574,
507,
198,
8595,
275,
334,
8595,
435,
574,
9,
1182,
499,
507,
198,
807,
59,
498,
61,
275,
334,
827,
12,
1390,
12,
12402,
12,
2338,
435,
413,
9,
199,
199,
318,
5436,
63,
5125,
837,
272,
870,
4582,
88,
17,
66,
59,
40,
60,
88,
17,
66,
59,
18,
42,
531,
199,
199,
14274,
63,
2491,
63,
4050,
379,
275,
756,
199,
199,
893,
26,
199,
198,
646,
13968,
199,
198,
6744,
63,
475,
63,
344,
275,
469,
507,
198,
7,
88,
1184,
63,
772,
356,
13968,
14,
13802,
63,
1184,
63,
772,
12,
507,
198,
7,
4468,
7,
198,
26,
13968,
14,
13802,
63,
18554,
12,
507,
198,
7,
4674,
772,
7,
198,
26,
13968,
14,
13802,
63,
13033,
772,
12,
507,
198,
7,
20638,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
12,
507,
198,
7,
20638,
772,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
772,
12,
507,
198,
1159,
12302,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
12,
507,
198,
1159,
12302,
88,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
56,
12,
507,
198,
7,
73,
8040,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
26888,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
10253,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
199,
198,
93,
199,
198,
893,
26,
507,
198,
6744,
63,
475,
63,
344,
459,
285,
278,
66,
418,
275,
13968,
14,
13802,
63,
689,
3635,
34,
199,
198,
2590,
26,
507,
198,
1529,
199,
198,
6744,
63,
344,
275,
6844,
63,
475,
63,
344,
59,
736,
14,
16040,
3430,
20,
2677,
199,
2590,
26,
199,
198,
692,
440,
13968,
63,
2491,
63,
4050,
379,
26,
507,
198,
14274,
63,
2491,
63,
4050,
379,
275,
715,
507,
198,
1361,
298,
8154,
314,
13968,
13,
8450,
13,
1548,
2559,
370,
664,
18901,
1561,
2,
199,
199,
318,
18901,
63,
354,
8,
344,
304,
199,
198,
893,
26,
507,
198,
1107,
13968,
14,
14274,
63,
19444,
63,
475,
63,
354,
8,
344,
12,
6844,
63,
344,
9,
199,
198,
2590,
26,
507,
198,
1107,
620,
8,
344,
9,
199,
199,
318,
410,
17844,
8,
7865,
304,
199,
198,
893,
26,
507,
198,
1107,
7554,
14,
28857,
59,
2101,
8,
7865,
1874,
199,
198,
2590,
26,
507,
198,
1107,
298,
5912,
450,
68,
7554,
2,
450,
14762,
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,
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,
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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
] |
braiins/paparazzi
|
sw/ground_segment/python/ivytoredis/ivy_to_redis.py
|
39
|
2358
|
#!/usr/bin/env python
from __future__ import print_function
import redis
import time
import signal
import argparse
import sys
import os
# if PAPARAZZI_SRC not set, then assume the tree containing this
# file is a reasonable substitute
PPRZ_SRC = os.getenv("PAPARAZZI_SRC", os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'../../../../')))
PPRZ_LIB_PYTHON = os.path.join(PPRZ_SRC, "sw/lib/python")
sys.path.append(PPRZ_LIB_PYTHON)
from ivy_msg_interface import IvyMessagesInterface
server = None
class Ivy2RedisServer():
def __init__(self, redishost, redisport, verbose=False):
self.verbose = verbose
self.interface = IvyMessagesInterface(self.message_recv)
self.r = redis.StrictRedis(host=redishost, port=redisport, db=0)
self.keep_running = True
print("Connected to redis server %s on port %i" % (redishost, redisport))
def message_recv(self, ac_id, msg):
# if ac_id is not 0 (i.e. telemetry from an aircraft) include it in the key
# don't add it to the key for ground messages
if ac_id:
key = "{0}.{1}.{2}".format(msg.msg_class, msg.name, ac_id)
else:
key = "{0}.{1}".format(msg.msg_class, msg.name)
if self.verbose:
print("received message, key=%s, msg=%s" % (key, msg.to_json(payload_only=True)))
sys.stdout.flush()
self.r.publish(key, msg.to_json(payload_only=True))
self.r.set(key, msg.to_json(payload_only=True))
def run(self):
while self.keep_running:
time.sleep(0.1)
def stop(self):
self.keep_running = False
self.interface.shutdown()
def signal_handler(signal, frame):
global server
server.stop()
def main():
global server
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--server", help="hostname here redis runs", default="localhost")
parser.add_argument("-p", "--port", help="port used by redis", type=int, default=6379)
parser.add_argument("-v", "--verbose", dest="verbose", action="store_true")
args = parser.parse_args()
server = Ivy2RedisServer(args.server, args.port, args.verbose)
signal.signal(signal.SIGINT, signal_handler)
server.run()
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
16967,
199,
646,
900,
199,
646,
4673,
199,
646,
7534,
199,
646,
984,
199,
646,
747,
199,
199,
3,
340,
510,
1282,
689,
33,
9909,
41,
63,
12447,
440,
663,
12,
2066,
5534,
314,
3123,
3035,
642,
199,
3,
570,
365,
282,
23255,
23080,
199,
48,
3311,
58,
63,
12447,
275,
747,
14,
12959,
480,
48,
1282,
689,
33,
9909,
41,
63,
12447,
401,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
25405,
283,
9707,
9707,
7058,
199,
48,
3311,
58,
63,
5617,
63,
11720,
275,
747,
14,
515,
14,
904,
8,
48,
3311,
58,
63,
12447,
12,
298,
3519,
15,
773,
15,
1548,
531,
199,
1274,
14,
515,
14,
740,
8,
48,
3311,
58,
63,
5617,
63,
11720,
9,
199,
199,
504,
284,
16091,
63,
1328,
63,
3266,
492,
473,
16091,
14508,
4267,
199,
199,
1000,
275,
488,
421,
199,
533,
473,
16091,
18,
29605,
3120,
837,
272,
347,
636,
826,
721,
277,
12,
16967,
1102,
12,
295,
328,
3275,
12,
3376,
29,
797,
304,
267,
291,
14,
3832,
275,
3376,
267,
291,
14,
3266,
275,
473,
16091,
14508,
4267,
8,
277,
14,
1188,
63,
7637,
9,
267,
291,
14,
82,
275,
16967,
14,
18625,
29605,
8,
1102,
29,
15369,
1102,
12,
1844,
29,
264,
328,
3275,
12,
1592,
29,
16,
9,
267,
291,
14,
3250,
63,
5720,
275,
715,
267,
870,
480,
16382,
370,
16967,
1654,
450,
83,
641,
1844,
450,
73,
2,
450,
334,
15369,
1102,
12,
295,
328,
3275,
430,
339,
347,
1245,
63,
7637,
8,
277,
12,
1066,
63,
344,
12,
1499,
304,
267,
327,
340,
1066,
63,
344,
365,
440,
378,
334,
73,
14,
69,
14,
17298,
687,
376,
282,
5958,
4800,
9,
2387,
652,
315,
314,
790,
267,
327,
2793,
1133,
1050,
652,
370,
314,
790,
367,
19252,
3788,
267,
340,
1066,
63,
344,
26,
288,
790,
275,
5310,
16,
26944,
17,
26944,
18,
5469,
908,
8,
1328,
14,
1328,
63,
533,
12,
1499,
14,
354,
12,
1066,
63,
344,
9,
267,
587,
26,
288,
790,
275,
5310,
16,
26944,
17,
5469,
908,
8,
1328,
14,
1328,
63,
533,
12,
1499,
14,
354,
9,
267,
340,
291,
14,
3832,
26,
288,
870,
480,
9226,
1245,
12,
790,
2458,
83,
12,
1499,
2458,
83,
2,
450,
334,
498,
12,
1499,
14,
475,
63,
1001,
8,
4749,
63,
2118,
29,
549,
1724,
288,
984,
14,
2703,
14,
4939,
342,
267,
291,
14,
82,
14,
4763,
8,
498,
12,
1499,
14,
475,
63,
1001,
8,
4749,
63,
2118,
29,
549,
430,
267,
291,
14,
82,
14,
409,
8,
498,
12,
1499,
14,
475,
63,
1001,
8,
4749,
63,
2118,
29,
549,
430,
339,
347,
1255,
8,
277,
304,
267,
1830,
291,
14,
3250,
63,
5720,
26,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
339,
347,
3631,
8,
277,
304,
267,
291,
14,
3250,
63,
5720,
275,
756,
267,
291,
14,
3266,
14,
8831,
342,
421,
199,
318,
4673,
63,
2232,
8,
4653,
12,
2787,
304,
272,
2288,
1654,
272,
1654,
14,
2379,
342,
421,
199,
318,
2446,
837,
272,
2288,
1654,
272,
1798,
275,
7534,
14,
10730,
342,
272,
1798,
14,
525,
63,
2094,
6096,
83,
401,
4320,
1000,
401,
1720,
628,
4269,
2348,
16967,
7858,
401,
849,
628,
5967,
531,
272,
1798,
14,
525,
63,
2094,
6096,
80,
401,
4320,
719,
401,
1720,
628,
719,
1202,
701,
16967,
401,
730,
29,
442,
12,
849,
29,
22,
12015,
9,
272,
1798,
14,
525,
63,
2094,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
1595,
628,
1617,
63,
2052,
531,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
1654,
275,
473,
16091,
18,
29605,
3120,
8,
589,
14,
1000,
12,
1249,
14,
719,
12,
1249,
14,
3832,
9,
272,
4673,
14,
4653,
8,
4653,
14,
21223,
12,
4673,
63,
2232,
9,
272,
1654,
14,
1065,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
16967,
199,
646,
900,
199,
646,
4673,
199,
646,
7534,
199,
646,
984,
199,
646,
747,
199,
199,
3,
340,
510,
1282,
689,
33,
9909,
41,
63,
12447,
440,
663,
12,
2066,
5534,
314,
3123,
3035,
642,
199,
3,
570,
365,
282,
23255,
23080,
199,
48,
3311,
58,
63,
12447,
275,
747,
14,
12959,
480,
48,
1282,
689,
33,
9909,
41,
63,
12447,
401,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
25405,
283,
9707,
9707,
7058,
199,
48,
3311,
58,
63,
5617,
63,
11720,
275,
747,
14,
515,
14,
904,
8,
48,
3311,
58,
63,
12447,
12,
298,
3519,
15,
773,
15,
1548,
531,
199,
1274,
14,
515,
14,
740,
8,
48,
3311,
58,
63,
5617,
63,
11720,
9,
199,
199,
504,
284,
16091,
63,
1328,
63,
3266,
492,
473,
16091,
14508,
4267,
199,
199,
1000,
275,
488,
421,
199,
533,
473,
16091,
18,
29605,
3120,
837,
272,
347,
636,
826,
721,
277,
12,
16967,
1102,
12,
295,
328,
3275,
12,
3376,
29,
797,
304,
267,
291,
14,
3832,
275,
3376,
267,
291,
14,
3266,
275,
473,
16091,
14508,
4267,
8,
277,
14,
1188,
63,
7637,
9,
267,
291,
14,
82,
275,
16967,
14,
18625,
29605,
8,
1102,
29,
15369,
1102,
12,
1844,
29,
264,
328,
3275,
12,
1592,
29,
16,
9,
267,
291,
14,
3250,
63,
5720,
275,
715,
267,
870,
480,
16382,
370,
16967,
1654,
450,
83,
641,
1844,
450,
73,
2,
450,
334,
15369,
1102,
12,
295,
328,
3275,
430,
339,
347,
1245,
63,
7637,
8,
277,
12,
1066,
63,
344,
12,
1499,
304,
267,
327,
340,
1066,
63,
344,
365,
440,
378,
334,
73,
14,
69,
14,
17298,
687,
376,
282,
5958,
4800,
9,
2387,
652,
315,
314,
790,
267,
327,
2793,
1133,
1050,
652,
370,
314,
790,
367,
19252,
3788,
267,
340,
1066,
63,
344,
26,
288,
790,
275,
5310,
16,
26944,
17,
26944,
18,
5469,
908,
8,
1328,
14,
1328,
63,
533,
12,
1499,
14,
354,
12,
1066,
63,
344,
9,
267,
587,
26,
288,
790,
275,
5310,
16,
26944,
17,
5469,
908,
8,
1328,
14,
1328,
63,
533,
12,
1499,
14,
354,
9,
267,
340,
291,
14,
3832,
26,
288,
870,
480,
9226,
1245,
12,
790,
2458,
83,
12,
1499,
2458,
83,
2,
450,
334,
498,
12,
1499,
14,
475,
63,
1001,
8,
4749,
63,
2118,
29,
549,
1724,
288,
984,
14,
2703,
14,
4939,
342,
267,
291,
14,
82,
14,
4763,
8,
498,
12,
1499,
14,
475,
63,
1001,
8,
4749,
63,
2118,
29,
549,
430,
267,
291,
14,
82,
14,
409,
8,
498,
12,
1499,
14,
475,
63,
1001,
8,
4749,
63,
2118,
29,
549,
430,
339,
347,
1255,
8,
277,
304,
267,
1830,
291,
14,
3250,
63,
5720,
26,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
339,
347,
3631,
8,
277,
304,
267,
291,
14,
3250,
63,
5720,
275,
756,
267,
291,
14,
3266,
14,
8831,
342,
421,
199,
318,
4673,
63,
2232,
8,
4653,
12,
2787,
304,
272,
2288,
1654,
272,
1654,
14,
2379,
342,
421,
199,
318,
2446,
837,
272,
2288,
1654,
272,
1798,
275,
7534,
14,
10730,
342,
272,
1798,
14,
525,
63,
2094,
6096,
83,
401,
4320,
1000,
401,
1720,
628,
4269,
2348,
16967,
7858,
401,
849,
628,
5967,
531,
272,
1798,
14,
525,
63,
2094,
6096,
80,
401,
4320,
719,
401,
1720,
628,
719,
1202,
701,
16967,
401,
730,
29,
442,
12,
849,
29,
22,
12015,
9,
272,
1798,
14,
525,
63,
2094,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
1595,
628,
1617,
63,
2052,
531,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
1654,
275,
473,
16091,
18,
29605,
3120,
8,
589,
14,
1000,
12,
1249,
14,
719,
12,
1249,
14,
3832,
9,
272,
4673,
14,
4653,
8,
4653,
14,
21223,
12,
4673,
63,
2232,
9,
272,
1654,
14,
1065,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
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,
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,
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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
] |
abo-abo/edx-platform
|
common/lib/xmodule/xmodule/tests/test_graders.py
|
102
|
12238
|
"""Grading tests"""
import unittest
from xmodule import graders
from xmodule.graders import Score, aggregate_scores
class GradesheetTest(unittest.TestCase):
'''Tests the aggregate_scores method'''
def test_weighted_grading(self):
scores = []
Score.__sub__ = lambda me, other: (me.earned - other.earned) + (me.possible - other.possible)
all_total, graded_total = aggregate_scores(scores)
self.assertEqual(all_total, Score(earned=0, possible=0, graded=False, section="summary"))
self.assertEqual(graded_total, Score(earned=0, possible=0, graded=True, section="summary"))
scores.append(Score(earned=0, possible=5, graded=False, section="summary"))
all_total, graded_total = aggregate_scores(scores)
self.assertEqual(all_total, Score(earned=0, possible=5, graded=False, section="summary"))
self.assertEqual(graded_total, Score(earned=0, possible=0, graded=True, section="summary"))
scores.append(Score(earned=3, possible=5, graded=True, section="summary"))
all_total, graded_total = aggregate_scores(scores)
self.assertAlmostEqual(all_total, Score(earned=3, possible=10, graded=False, section="summary"))
self.assertAlmostEqual(graded_total, Score(earned=3, possible=5, graded=True, section="summary"))
scores.append(Score(earned=2, possible=5, graded=True, section="summary"))
all_total, graded_total = aggregate_scores(scores)
self.assertAlmostEqual(all_total, Score(earned=5, possible=15, graded=False, section="summary"))
self.assertAlmostEqual(graded_total, Score(earned=5, possible=10, graded=True, section="summary"))
class GraderTest(unittest.TestCase):
'''Tests grader implementations'''
empty_gradesheet = {
}
incomplete_gradesheet = {
'Homework': [],
'Lab': [],
'Midterm': [],
}
test_gradesheet = {
'Homework': [Score(earned=2, possible=20.0, graded=True, section='hw1'),
Score(earned=16, possible=16.0, graded=True, section='hw2')],
# The dropped scores should be from the assignments that don't exist yet
'Lab': [Score(earned=1, possible=2.0, graded=True, section='lab1'), # Dropped
Score(earned=1, possible=1.0, graded=True, section='lab2'),
Score(earned=1, possible=1.0, graded=True, section='lab3'),
Score(earned=5, possible=25.0, graded=True, section='lab4'), # Dropped
Score(earned=3, possible=4.0, graded=True, section='lab5'), # Dropped
Score(earned=6, possible=7.0, graded=True, section='lab6'),
Score(earned=5, possible=6.0, graded=True, section='lab7')],
'Midterm': [Score(earned=50.5, possible=100, graded=True, section="Midterm Exam"), ],
}
def test_single_section_grader(self):
midterm_grader = graders.SingleSectionGrader("Midterm", "Midterm Exam")
lab4_grader = graders.SingleSectionGrader("Lab", "lab4")
bad_lab_grader = graders.SingleSectionGrader("Lab", "lab42")
for graded in [midterm_grader.grade(self.empty_gradesheet),
midterm_grader.grade(self.incomplete_gradesheet),
bad_lab_grader.grade(self.test_gradesheet)]:
self.assertEqual(len(graded['section_breakdown']), 1)
self.assertEqual(graded['percent'], 0.0)
graded = midterm_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.505)
self.assertEqual(len(graded['section_breakdown']), 1)
graded = lab4_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.2)
self.assertEqual(len(graded['section_breakdown']), 1)
def test_assignment_format_grader(self):
homework_grader = graders.AssignmentFormatGrader("Homework", 12, 2)
no_drop_grader = graders.AssignmentFormatGrader("Homework", 12, 0)
# Even though the minimum number is 3, this should grade correctly when 7 assignments are found
overflow_grader = graders.AssignmentFormatGrader("Lab", 3, 2)
lab_grader = graders.AssignmentFormatGrader("Lab", 7, 3)
# Test the grading of an empty gradesheet
for graded in [homework_grader.grade(self.empty_gradesheet),
no_drop_grader.grade(self.empty_gradesheet),
homework_grader.grade(self.incomplete_gradesheet),
no_drop_grader.grade(self.incomplete_gradesheet)]:
self.assertAlmostEqual(graded['percent'], 0.0)
# Make sure the breakdown includes 12 sections, plus one summary
self.assertEqual(len(graded['section_breakdown']), 12 + 1)
graded = homework_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.11) # 100% + 10% / 10 assignments
self.assertEqual(len(graded['section_breakdown']), 12 + 1)
graded = no_drop_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.0916666666666666) # 100% + 10% / 12 assignments
self.assertEqual(len(graded['section_breakdown']), 12 + 1)
graded = overflow_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.8880952380952382) # 100% + 10% / 5 assignments
self.assertEqual(len(graded['section_breakdown']), 7 + 1)
graded = lab_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.9226190476190477)
self.assertEqual(len(graded['section_breakdown']), 7 + 1)
def test_assignment_format_grader_on_single_section_entry(self):
midterm_grader = graders.AssignmentFormatGrader("Midterm", 1, 0)
# Test the grading on a section with one item:
for graded in [midterm_grader.grade(self.empty_gradesheet),
midterm_grader.grade(self.incomplete_gradesheet)]:
self.assertAlmostEqual(graded['percent'], 0.0)
# Make sure the breakdown includes just the one summary
self.assertEqual(len(graded['section_breakdown']), 0 + 1)
self.assertEqual(graded['section_breakdown'][0]['label'], 'Midterm')
graded = midterm_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.505)
self.assertEqual(len(graded['section_breakdown']), 0 + 1)
def test_weighted_subsections_grader(self):
# First, a few sub graders
homework_grader = graders.AssignmentFormatGrader("Homework", 12, 2)
lab_grader = graders.AssignmentFormatGrader("Lab", 7, 3)
# phasing out the use of SingleSectionGraders, and instead using AssignmentFormatGraders that
# will act like SingleSectionGraders on single sections.
midterm_grader = graders.AssignmentFormatGrader("Midterm", 1, 0)
weighted_grader = graders.WeightedSubsectionsGrader([(homework_grader, homework_grader.category, 0.25),
(lab_grader, lab_grader.category, 0.25),
(midterm_grader, midterm_grader.category, 0.5)])
over_one_weights_grader = graders.WeightedSubsectionsGrader([(homework_grader, homework_grader.category, 0.5),
(lab_grader, lab_grader.category, 0.5),
(midterm_grader, midterm_grader.category, 0.5)])
# The midterm should have all weight on this one
zero_weights_grader = graders.WeightedSubsectionsGrader([(homework_grader, homework_grader.category, 0.0),
(lab_grader, lab_grader.category, 0.0),
(midterm_grader, midterm_grader.category, 0.5)])
# This should always have a final percent of zero
all_zero_weights_grader = graders.WeightedSubsectionsGrader([(homework_grader, homework_grader.category, 0.0),
(lab_grader, lab_grader.category, 0.0),
(midterm_grader, midterm_grader.category, 0.0)])
empty_grader = graders.WeightedSubsectionsGrader([])
graded = weighted_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.5106547619047619)
self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
self.assertEqual(len(graded['grade_breakdown']), 3)
graded = over_one_weights_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.7688095238095238)
self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
self.assertEqual(len(graded['grade_breakdown']), 3)
graded = zero_weights_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.2525)
self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
self.assertEqual(len(graded['grade_breakdown']), 3)
graded = all_zero_weights_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.0)
self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
self.assertEqual(len(graded['grade_breakdown']), 3)
for graded in [weighted_grader.grade(self.empty_gradesheet),
weighted_grader.grade(self.incomplete_gradesheet),
zero_weights_grader.grade(self.empty_gradesheet),
all_zero_weights_grader.grade(self.empty_gradesheet)]:
self.assertAlmostEqual(graded['percent'], 0.0)
self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
self.assertEqual(len(graded['grade_breakdown']), 3)
graded = empty_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.0)
self.assertEqual(len(graded['section_breakdown']), 0)
self.assertEqual(len(graded['grade_breakdown']), 0)
def test_grader_from_conf(self):
# Confs always produce a graders.WeightedSubsectionsGrader, so we test this by repeating the test
# in test_graders.WeightedSubsectionsGrader, but generate the graders with confs.
weighted_grader = graders.grader_from_conf([
{
'type': "Homework",
'min_count': 12,
'drop_count': 2,
'short_label': "HW",
'weight': 0.25,
},
{
'type': "Lab",
'min_count': 7,
'drop_count': 3,
'category': "Labs",
'weight': 0.25
},
{
'type': "Midterm",
'name': "Midterm Exam",
'short_label': "Midterm",
'weight': 0.5,
},
])
empty_grader = graders.grader_from_conf([])
graded = weighted_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.5106547619047619)
self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1)
self.assertEqual(len(graded['grade_breakdown']), 3)
graded = empty_grader.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.0)
self.assertEqual(len(graded['section_breakdown']), 0)
self.assertEqual(len(graded['grade_breakdown']), 0)
# Test that graders can also be used instead of lists of dictionaries
homework_grader = graders.AssignmentFormatGrader("Homework", 12, 2)
homework_grader2 = graders.grader_from_conf(homework_grader)
graded = homework_grader2.grade(self.test_gradesheet)
self.assertAlmostEqual(graded['percent'], 0.11)
self.assertEqual(len(graded['section_breakdown']), 12 + 1)
# TODO: How do we test failure cases? The parser only logs an error when
# it can't parse something. Maybe it should throw exceptions?
|
agpl-3.0
|
[
624,
5761,
1098,
2295,
624,
199,
646,
2882,
199,
199,
504,
9872,
492,
1999,
7735,
199,
504,
9872,
14,
926,
7735,
492,
25318,
12,
9531,
63,
7107,
421,
199,
533,
10268,
3424,
3797,
774,
8,
2796,
14,
1746,
304,
272,
1449,
2925,
314,
9531,
63,
7107,
1083,
2344,
339,
347,
511,
63,
13522,
63,
16050,
8,
277,
304,
267,
9342,
275,
942,
267,
25318,
855,
954,
363,
275,
2400,
562,
12,
1163,
26,
334,
278,
14,
69,
31772,
446,
1163,
14,
69,
31772,
9,
435,
334,
278,
14,
13893,
446,
1163,
14,
13893,
9,
398,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
629,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
16,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
629,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
16,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
398,
9342,
14,
740,
8,
12642,
8,
69,
31772,
29,
16,
12,
3962,
29,
21,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
629,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
21,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
629,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
16,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
398,
9342,
14,
740,
8,
12642,
8,
69,
31772,
29,
19,
12,
3962,
29,
21,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
267,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
7904,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
19,
12,
3962,
29,
709,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
7904,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
19,
12,
3962,
29,
21,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
398,
9342,
14,
740,
8,
12642,
8,
69,
31772,
29,
18,
12,
3962,
29,
21,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
267,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
7904,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
1046,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
7904,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
709,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
421,
199,
533,
10268,
424,
774,
8,
2796,
14,
1746,
304,
272,
1449,
2925,
27741,
12591,
2344,
339,
2701,
63,
18050,
3797,
275,
469,
272,
789,
339,
17110,
63,
18050,
3797,
275,
469,
267,
283,
12054,
800,
356,
990,
267,
283,
22511,
356,
990,
267,
283,
28735,
5125,
356,
990,
272,
789,
339,
511,
63,
18050,
3797,
275,
469,
267,
283,
12054,
800,
356,
359,
12642,
8,
69,
31772,
29,
18,
12,
3962,
29,
1165,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
8090,
17,
659,
2151,
25318,
8,
69,
31772,
29,
975,
12,
3962,
29,
975,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
8090,
18,
2665,
267,
327,
710,
17481,
9342,
1077,
506,
687,
314,
18121,
626,
2793,
1133,
2187,
5966,
398,
283,
22511,
356,
359,
12642,
8,
69,
31772,
29,
17,
12,
3962,
29,
18,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
17,
659,
221,
327,
18110,
1915,
355,
25318,
8,
69,
31772,
29,
17,
12,
3962,
29,
17,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
18,
659,
355,
25318,
8,
69,
31772,
29,
17,
12,
3962,
29,
17,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
19,
659,
355,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
821,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
20,
659,
221,
327,
18110,
1915,
355,
25318,
8,
69,
31772,
29,
19,
12,
3962,
29,
20,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
21,
659,
221,
327,
18110,
1915,
355,
25318,
8,
69,
31772,
29,
22,
12,
3962,
29,
23,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
22,
659,
355,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
22,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
23,
2665,
398,
283,
28735,
5125,
356,
359,
12642,
8,
69,
31772,
29,
1400,
14,
21,
12,
3962,
29,
1960,
12,
1999,
770,
29,
549,
12,
3420,
628,
28735,
5125,
1316,
455,
1288,
2156,
272,
789,
339,
347,
511,
63,
4780,
63,
2792,
63,
17556,
8,
277,
304,
267,
10887,
5125,
63,
17556,
275,
1999,
7735,
14,
7200,
8660,
5761,
424,
480,
28735,
5125,
401,
298,
28735,
5125,
1316,
455,
531,
267,
19888,
20,
63,
17556,
275,
1999,
7735,
14,
7200,
8660,
5761,
424,
480,
22511,
401,
298,
5561,
20,
531,
267,
4875,
63,
5561,
63,
17556,
275,
1999,
7735,
14,
7200,
8660,
5761,
424,
480,
22511,
401,
298,
5561,
2260,
531,
398,
367,
1999,
770,
315,
359,
8523,
5125,
63,
17556,
14,
4523,
8,
277,
14,
1667,
63,
18050,
3797,
395,
2432,
10887,
5125,
63,
17556,
14,
4523,
8,
277,
14,
24575,
63,
18050,
3797,
395,
2432,
4875,
63,
5561,
63,
17556,
14,
4523,
8,
277,
14,
396,
63,
18050,
3797,
19532,
288,
291,
14,
629,
8,
552,
8,
13688,
459,
2792,
63,
4785,
2110,
3815,
413,
9,
288,
291,
14,
629,
8,
13688,
459,
7045,
995,
378,
14,
16,
9,
398,
1999,
770,
275,
10887,
5125,
63,
17556,
14,
4523,
8,
277,
14,
396,
63,
18050,
3797,
9,
267,
291,
14,
7904,
8,
13688,
459,
7045,
995,
378,
14,
13938,
9,
267,
291,
14,
629,
8,
552,
8,
13688,
459,
2792,
63,
4785,
2110,
3815,
413,
9,
398,
1999,
770,
275,
19888,
20,
63,
17556,
14,
4523,
8
] |
[
5761,
1098,
2295,
624,
199,
646,
2882,
199,
199,
504,
9872,
492,
1999,
7735,
199,
504,
9872,
14,
926,
7735,
492,
25318,
12,
9531,
63,
7107,
421,
199,
533,
10268,
3424,
3797,
774,
8,
2796,
14,
1746,
304,
272,
1449,
2925,
314,
9531,
63,
7107,
1083,
2344,
339,
347,
511,
63,
13522,
63,
16050,
8,
277,
304,
267,
9342,
275,
942,
267,
25318,
855,
954,
363,
275,
2400,
562,
12,
1163,
26,
334,
278,
14,
69,
31772,
446,
1163,
14,
69,
31772,
9,
435,
334,
278,
14,
13893,
446,
1163,
14,
13893,
9,
398,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
629,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
16,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
629,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
16,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
398,
9342,
14,
740,
8,
12642,
8,
69,
31772,
29,
16,
12,
3962,
29,
21,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
629,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
21,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
629,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
16,
12,
3962,
29,
16,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
398,
9342,
14,
740,
8,
12642,
8,
69,
31772,
29,
19,
12,
3962,
29,
21,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
267,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
7904,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
19,
12,
3962,
29,
709,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
7904,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
19,
12,
3962,
29,
21,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
398,
9342,
14,
740,
8,
12642,
8,
69,
31772,
29,
18,
12,
3962,
29,
21,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
267,
1006,
63,
2923,
12,
1999,
770,
63,
2923,
275,
9531,
63,
7107,
8,
7107,
9,
267,
291,
14,
7904,
8,
452,
63,
2923,
12,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
1046,
12,
1999,
770,
29,
797,
12,
3420,
628,
4705,
2237,
267,
291,
14,
7904,
8,
13688,
63,
2923,
12,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
709,
12,
1999,
770,
29,
549,
12,
3420,
628,
4705,
2237,
421,
199,
533,
10268,
424,
774,
8,
2796,
14,
1746,
304,
272,
1449,
2925,
27741,
12591,
2344,
339,
2701,
63,
18050,
3797,
275,
469,
272,
789,
339,
17110,
63,
18050,
3797,
275,
469,
267,
283,
12054,
800,
356,
990,
267,
283,
22511,
356,
990,
267,
283,
28735,
5125,
356,
990,
272,
789,
339,
511,
63,
18050,
3797,
275,
469,
267,
283,
12054,
800,
356,
359,
12642,
8,
69,
31772,
29,
18,
12,
3962,
29,
1165,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
8090,
17,
659,
2151,
25318,
8,
69,
31772,
29,
975,
12,
3962,
29,
975,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
8090,
18,
2665,
267,
327,
710,
17481,
9342,
1077,
506,
687,
314,
18121,
626,
2793,
1133,
2187,
5966,
398,
283,
22511,
356,
359,
12642,
8,
69,
31772,
29,
17,
12,
3962,
29,
18,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
17,
659,
221,
327,
18110,
1915,
355,
25318,
8,
69,
31772,
29,
17,
12,
3962,
29,
17,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
18,
659,
355,
25318,
8,
69,
31772,
29,
17,
12,
3962,
29,
17,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
19,
659,
355,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
821,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
20,
659,
221,
327,
18110,
1915,
355,
25318,
8,
69,
31772,
29,
19,
12,
3962,
29,
20,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
21,
659,
221,
327,
18110,
1915,
355,
25318,
8,
69,
31772,
29,
22,
12,
3962,
29,
23,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
22,
659,
355,
25318,
8,
69,
31772,
29,
21,
12,
3962,
29,
22,
14,
16,
12,
1999,
770,
29,
549,
12,
3420,
534,
5561,
23,
2665,
398,
283,
28735,
5125,
356,
359,
12642,
8,
69,
31772,
29,
1400,
14,
21,
12,
3962,
29,
1960,
12,
1999,
770,
29,
549,
12,
3420,
628,
28735,
5125,
1316,
455,
1288,
2156,
272,
789,
339,
347,
511,
63,
4780,
63,
2792,
63,
17556,
8,
277,
304,
267,
10887,
5125,
63,
17556,
275,
1999,
7735,
14,
7200,
8660,
5761,
424,
480,
28735,
5125,
401,
298,
28735,
5125,
1316,
455,
531,
267,
19888,
20,
63,
17556,
275,
1999,
7735,
14,
7200,
8660,
5761,
424,
480,
22511,
401,
298,
5561,
20,
531,
267,
4875,
63,
5561,
63,
17556,
275,
1999,
7735,
14,
7200,
8660,
5761,
424,
480,
22511,
401,
298,
5561,
2260,
531,
398,
367,
1999,
770,
315,
359,
8523,
5125,
63,
17556,
14,
4523,
8,
277,
14,
1667,
63,
18050,
3797,
395,
2432,
10887,
5125,
63,
17556,
14,
4523,
8,
277,
14,
24575,
63,
18050,
3797,
395,
2432,
4875,
63,
5561,
63,
17556,
14,
4523,
8,
277,
14,
396,
63,
18050,
3797,
19532,
288,
291,
14,
629,
8,
552,
8,
13688,
459,
2792,
63,
4785,
2110,
3815,
413,
9,
288,
291,
14,
629,
8,
13688,
459,
7045,
995,
378,
14,
16,
9,
398,
1999,
770,
275,
10887,
5125,
63,
17556,
14,
4523,
8,
277,
14,
396,
63,
18050,
3797,
9,
267,
291,
14,
7904,
8,
13688,
459,
7045,
995,
378,
14,
13938,
9,
267,
291,
14,
629,
8,
552,
8,
13688,
459,
2792,
63,
4785,
2110,
3815,
413,
9,
398,
1999,
770,
275,
19888,
20,
63,
17556,
14,
4523,
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,
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
] |
ozamiatin/oslo.messaging
|
oslo_messaging/_drivers/zmq_driver/zmq_version.py
|
2
|
2194
|
# Copyright 2016 Mirantis, 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 re
from oslo_messaging._drivers import common as rpc_common
from oslo_messaging._i18n import _
# current driver's version for representing internal message format
MESSAGE_VERSION = '1.0'
class UnsupportedMessageVersionError(rpc_common.RPCException):
msg_fmt = _("Message version %(version)s is not supported.")
def __init__(self, version):
super(UnsupportedMessageVersionError, self).__init__(version=version)
def get_method_versions(obj, method_name):
"""Useful function for initializing versioned senders/receivers.
Returns a dictionary of different internal versions of the given method.
Assumes that the object has the particular versioned method and this method
is public. Thus versions are private implementations of the method.
For example, for a method 'func' methods '_func_v_1_0', '_func_v_1_5',
'_func_v_2_0', etc. are assumed as its respective 1.0, 1.5, 2.0 versions.
"""
assert callable(getattr(obj, method_name, None)), \
"Object must have specified method!"
assert not method_name.startswith('_'), "Method must be public!"
method_versions = {}
for attr_name in dir(obj):
if attr_name == method_name:
continue
attr = getattr(obj, attr_name, None)
if not callable(attr):
continue
match_obj = re.match(r'^_%s_v_(\d)_(\d)$' % method_name, attr_name)
if match_obj is not None:
version = '.'.join([match_obj.group(1), match_obj.group(2)])
method_versions[version] = attr
return method_versions
|
apache-2.0
|
[
3,
259,
1898,
7800,
603,
723,
4466,
83,
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,
646,
295,
199,
199,
504,
11258,
63,
27782,
423,
13337,
492,
2863,
465,
8985,
63,
2330,
199,
504,
11258,
63,
27782,
423,
73,
1085,
78,
492,
485,
421,
199,
3,
1453,
5253,
1159,
1015,
367,
6144,
5007,
1245,
1475,
199,
8272,
63,
4612,
275,
283,
17,
14,
16,
7,
421,
199,
533,
19022,
2209,
3353,
547,
8,
4354,
63,
2330,
14,
8171,
1726,
304,
272,
1499,
63,
5045,
275,
3824,
2209,
1015,
2818,
1023,
9,
83,
365,
440,
3748,
2685,
339,
347,
636,
826,
721,
277,
12,
1015,
304,
267,
1613,
8,
12647,
2209,
3353,
547,
12,
291,
2843,
826,
721,
1023,
29,
1023,
9,
421,
199,
318,
664,
63,
765,
63,
6234,
8,
1113,
12,
1083,
63,
354,
304,
272,
408,
6119,
1893,
805,
367,
29141,
31792,
4334,
7735,
15,
29494,
14,
339,
1803,
282,
2600,
402,
3365,
5007,
5459,
402,
314,
1627,
1083,
14,
339,
30451,
626,
314,
909,
965,
314,
6770,
31792,
1083,
436,
642,
1083,
272,
365,
4575,
14,
20227,
5459,
787,
5726,
12591,
402,
314,
1083,
14,
339,
2104,
2893,
12,
367,
282,
1083,
283,
1532,
7,
3102,
2513,
1532,
63,
86,
63,
17,
63,
16,
297,
2513,
1532,
63,
86,
63,
17,
63,
21,
297,
272,
2513,
1532,
63,
86,
63,
18,
63,
16,
297,
5423,
14,
787,
10826,
465,
2399,
26820,
413,
14,
16,
12,
413,
14,
21,
12,
499,
14,
16,
5459,
14,
272,
408,
339,
702,
4550,
8,
5675,
8,
1113,
12,
1083,
63,
354,
12,
488,
1826,
971,
267,
298,
1692,
1471,
1172,
2013,
1083,
9539,
272,
702,
440,
1083,
63,
354,
14,
2460,
6412,
659,
298,
3767,
1471,
506,
4575,
9539,
339,
1083,
63,
6234,
275,
1052,
272,
367,
1921,
63,
354,
315,
2935,
8,
1113,
304,
267,
340,
1921,
63,
354,
508,
1083,
63,
354,
26,
288,
1980,
267,
1921,
275,
2519,
8,
1113,
12,
1921,
63,
354,
12,
488,
9,
267,
340,
440,
4550,
8,
962,
304,
288,
1980,
267,
1336,
63,
1113,
275,
295,
14,
1431,
8,
82,
4289,
4970,
83,
63,
86,
2531,
60,
68,
9,
2531,
60,
68,
9,
12913,
450,
1083,
63,
354,
12,
1921,
63,
354,
9,
267,
340,
1336,
63,
1113,
365,
440,
488,
26,
288,
1015,
275,
15671,
904,
779,
1431,
63,
1113,
14,
923,
8,
17,
395,
1336,
63,
1113,
14,
923,
8,
18,
3948,
288,
1083,
63,
6234,
59,
1023,
61,
275,
1921,
339,
372,
1083,
63,
6234,
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
] |
[
259,
1898,
7800,
603,
723,
4466,
83,
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,
646,
295,
199,
199,
504,
11258,
63,
27782,
423,
13337,
492,
2863,
465,
8985,
63,
2330,
199,
504,
11258,
63,
27782,
423,
73,
1085,
78,
492,
485,
421,
199,
3,
1453,
5253,
1159,
1015,
367,
6144,
5007,
1245,
1475,
199,
8272,
63,
4612,
275,
283,
17,
14,
16,
7,
421,
199,
533,
19022,
2209,
3353,
547,
8,
4354,
63,
2330,
14,
8171,
1726,
304,
272,
1499,
63,
5045,
275,
3824,
2209,
1015,
2818,
1023,
9,
83,
365,
440,
3748,
2685,
339,
347,
636,
826,
721,
277,
12,
1015,
304,
267,
1613,
8,
12647,
2209,
3353,
547,
12,
291,
2843,
826,
721,
1023,
29,
1023,
9,
421,
199,
318,
664,
63,
765,
63,
6234,
8,
1113,
12,
1083,
63,
354,
304,
272,
408,
6119,
1893,
805,
367,
29141,
31792,
4334,
7735,
15,
29494,
14,
339,
1803,
282,
2600,
402,
3365,
5007,
5459,
402,
314,
1627,
1083,
14,
339,
30451,
626,
314,
909,
965,
314,
6770,
31792,
1083,
436,
642,
1083,
272,
365,
4575,
14,
20227,
5459,
787,
5726,
12591,
402,
314,
1083,
14,
339,
2104,
2893,
12,
367,
282,
1083,
283,
1532,
7,
3102,
2513,
1532,
63,
86,
63,
17,
63,
16,
297,
2513,
1532,
63,
86,
63,
17,
63,
21,
297,
272,
2513,
1532,
63,
86,
63,
18,
63,
16,
297,
5423,
14,
787,
10826,
465,
2399,
26820,
413,
14,
16,
12,
413,
14,
21,
12,
499,
14,
16,
5459,
14,
272,
408,
339,
702,
4550,
8,
5675,
8,
1113,
12,
1083,
63,
354,
12,
488,
1826,
971,
267,
298,
1692,
1471,
1172,
2013,
1083,
9539,
272,
702,
440,
1083,
63,
354,
14,
2460,
6412,
659,
298,
3767,
1471,
506,
4575,
9539,
339,
1083,
63,
6234,
275,
1052,
272,
367,
1921,
63,
354,
315,
2935,
8,
1113,
304,
267,
340,
1921,
63,
354,
508,
1083,
63,
354,
26,
288,
1980,
267,
1921,
275,
2519,
8,
1113,
12,
1921,
63,
354,
12,
488,
9,
267,
340,
440,
4550,
8,
962,
304,
288,
1980,
267,
1336,
63,
1113,
275,
295,
14,
1431,
8,
82,
4289,
4970,
83,
63,
86,
2531,
60,
68,
9,
2531,
60,
68,
9,
12913,
450,
1083,
63,
354,
12,
1921,
63,
354,
9,
267,
340,
1336,
63,
1113,
365,
440,
488,
26,
288,
1015,
275,
15671,
904,
779,
1431,
63,
1113,
14,
923,
8,
17,
395,
1336,
63,
1113,
14,
923,
8,
18,
3948,
288,
1083,
63,
6234,
59,
1023,
61,
275,
1921,
339,
372,
1083,
63,
6234,
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,
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,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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
] |
RedHatInsights/insights-core
|
insights/combiners/selinux.py
|
1
|
4702
|
"""
SELinux
=======
Combiner for more complex handling of SELinux being disabled by any means
available to the users. It uses results of
:class:`insights.parsers.sestatus.SEStatus`, and
:class:`insights.parsers.selinux_config.SelinuxConfig` parsers and
:class:`insights.combiners.grub_conf.GrubConf` combiner.
It contains a dictionary ``problems`` in which it stores detected problems with
keys as follows and values are parsed lines with detected problem:
* ``sestatus_disabled`` - SELinux is disabled on runtime.
* ``sestatus_not_enforcing`` - SELinux is not in enforcing mode.
* ``grub_disabled`` - SELinux is set in Grub to be disabled.
* ``grub_not_enforcing`` - SELinux is set in Grub to not be in enforcing mode.
* ``selinux_conf_disabled`` - SELinux is set in configuration file to be disabled.
* ``sestatus_not_enforcing`` - SELinux is set in configuration file to not be in enforcing mode.
Examples:
>>> selinux = shared[SELinux]
>>> selinux.ok()
False
>>> selinux.problems
{'grub_disabled': ['/vmlinuz-2.6.32-642.el6.x86_64 selinux=0 ro root= ...'],
'selinux_conf_disabled': 'disabled',
'sestatus_not_enforcing': 'permissive'}
"""
from ..core.plugins import combiner
from ..parsers.sestatus import SEStatus
from ..combiners.grub_conf import GrubConf
from ..parsers.selinux_config import SelinuxConfig
GRUB_DISABLED = 'grub_disabled'
GRUB_NOT_ENFORCING = 'grub_not_enforcing'
RUNTIME_DISABLED = 'sestatus_disabled'
RUNTIME_NOT_ENFORCING = 'sestatus_not_enforcing'
BOOT_DISABLED = 'selinux_conf_disabled'
BOOT_NOT_ENFORCING = 'selinux_conf_not_enforcing'
@combiner(SEStatus, SelinuxConfig, optional=[GrubConf])
class SELinux(object):
"""
A combiner for detecting that SELinux is enabled and running and also enabled at boot time.
"""
def __init__(self, se_status, selinux_config, grub_conf):
self.problems = {}
self.sestatus = se_status
self.selinux_config = selinux_config
self.grub_config = grub_conf.grub if grub_conf else None
self._check_sestatus()
self._check_boot_config()
self._check_grub_config()
def _check_sestatus(self):
"""
Check runtime SELinux configuration from sestatus output.
Values of output from sestatus command are always lowercase.
"""
if self.sestatus.data['selinux_status'] != 'enabled':
self.problems[RUNTIME_DISABLED] = self.sestatus.data['selinux_status']
elif self.sestatus.data['current_mode'] != 'enforcing':
self.problems[RUNTIME_NOT_ENFORCING] = self.sestatus.data['current_mode']
def _check_boot_config(self):
"""
Check that SELinux is not disabled in /etc/sysconfig/selinux.
This file determines the boot configuration for SELinux.
"""
opt_value = self.selinux_config.data.get('SELINUX')
if opt_value is None:
self.problems[BOOT_NOT_ENFORCING] = 'Missing in config (Permissive by default)'
elif opt_value == 'disabled':
self.problems[BOOT_DISABLED] = opt_value
elif opt_value != 'enforcing':
self.problems[BOOT_NOT_ENFORCING] = opt_value
def _check_grub_config(self):
"""
Check grub and grub 2 for kernel boot options if selinux settings is not overriden.
Experiments confirmed that only lowercase is accepted in grub configuration.
grub is in rhel-6 and the boot line looks usually like
kernel /boot/vmlinuz-2.4.20-selinux-2003040709 ro root=/dev/hda1 nousb selinux=0
grub 2 is in rhel-7 and rhel-8, the boot line of grub 2 in rhel-7 looks usually like
linux16 /vmlinuz-0-rescue-9f20b35c9faa49aebe171f62a11b236f root=/dev/mapper/rhel-root ro crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
the boot line of grub 2 in rhel-8 looks usually like
options root=/dev/mapper/rhel_vm37--146-root ro crashkernel=auto resume=/dev/mapper/rhel_vm37--146-swap rd.lvm.lv=rhel_vm37-146/root rd.lvm.lv=rhel_vm37-146/swap $tuned_params
"""
conf = self.grub_config.boot_entries if self.grub_config is not None else []
se_dis = [e.cmdline for e in conf if 'selinux=0' in e.cmdline]
if se_dis:
self.problems[GRUB_DISABLED] = se_dis
se_noe = [e.cmdline for e in conf if 'enforcing=0' in e.cmdline]
if se_noe:
self.problems[GRUB_NOT_ENFORCING] = se_noe
def ok(self):
"""
Checks if there are any problems with SELinux configuration.
Returns
bool: True if SELinux is enabled and functional, false otherwise.
"""
return not bool(self.problems)
|
apache-2.0
|
[
624,
199,
899,
14091,
199,
18673,
199,
199,
17039,
281,
367,
1655,
6114,
7252,
402,
428,
2901,
7226,
3769,
6980,
701,
1263,
4910,
199,
4561,
370,
314,
4390,
14,
2779,
4440,
2058,
402,
199,
26,
533,
1705,
262,
22727,
83,
14,
11531,
14,
261,
1205,
14,
51,
654,
84,
896,
3559,
436,
199,
26,
533,
1705,
262,
22727,
83,
14,
11531,
14,
19931,
63,
888,
14,
20920,
7226,
2028,
64,
21295,
436,
199,
26,
533,
1705,
262,
22727,
83,
14,
6560,
262,
1192,
14,
2587,
456,
63,
2190,
14,
23765,
456,
8930,
64,
5300,
16187,
14,
199,
199,
7940,
3509,
282,
2600,
1124,
22959,
1040,
315,
1314,
652,
14086,
10501,
8826,
543,
199,
1612,
465,
11924,
436,
1338,
787,
4565,
2385,
543,
10501,
5160,
26,
199,
199,
10,
1124,
261,
1205,
63,
7011,
1040,
446,
428,
2901,
7226,
365,
6980,
641,
8836,
14,
199,
10,
1124,
261,
1205,
63,
1397,
63,
287,
509,
4477,
1040,
446,
428,
2901,
7226,
365,
440,
315,
655,
509,
4477,
818,
14,
199,
10,
1124,
2587,
456,
63,
7011,
1040,
446,
428,
2901,
7226,
365,
663,
315,
598,
82,
456,
370,
506,
6980,
14,
199,
10,
1124,
2587,
456,
63,
1397,
63,
287,
509,
4477,
1040,
446,
428,
2901,
7226,
365,
663,
315,
598,
82,
456,
370,
440,
506,
315,
655,
509,
4477,
818,
14,
199,
10,
1124,
19931,
63,
2190,
63,
7011,
1040,
446,
428,
2901,
7226,
365,
663,
315,
2897,
570,
370,
506,
6980,
14,
199,
10,
1124,
261,
1205,
63,
1397,
63,
287,
509,
4477,
1040,
446,
428,
2901,
7226,
365,
663,
315,
2897,
570,
370,
440,
506,
315,
655,
509,
4477,
818,
14,
199,
199,
22787,
26,
272,
1306,
542,
5135,
275,
5709,
59,
899,
14091,
61,
272,
1306,
542,
5135,
14,
745,
342,
272,
756,
272,
1306,
542,
5135,
14,
22959,
272,
791,
2587,
456,
63,
7011,
356,
18744,
2611,
472,
9494,
13,
18,
14,
22,
14,
708,
13,
15463,
14,
352,
22,
14,
88,
1184,
63,
772,
542,
5135,
29,
16,
882,
1738,
29,
2263,
995,
1362,
283,
19931,
63,
2190,
63,
7011,
356,
283,
7011,
297,
1362,
283,
261,
1205,
63,
1397,
63,
287,
509,
4477,
356,
283,
529,
32237,
936,
199,
624,
199,
199,
504,
2508,
1018,
14,
5265,
492,
5300,
16187,
199,
504,
2508,
11531,
14,
261,
1205,
492,
428,
654,
84,
896,
199,
504,
2508,
6560,
262,
1192,
14,
2587,
456,
63,
2190,
492,
598,
82,
456,
8930,
199,
504,
2508,
11531,
14,
19931,
63,
888,
492,
428,
352,
7226,
2028,
199,
199,
3975,
2533,
63,
16205,
275,
283,
2587,
456,
63,
7011,
7,
199,
3975,
2533,
63,
4609,
63,
742,
2707,
35,
1206,
275,
283,
2587,
456,
63,
1397,
63,
287,
509,
4477,
7,
199,
9390,
4961,
63,
16205,
275,
283,
261,
1205,
63,
7011,
7,
199,
9390,
4961,
63,
4609,
63,
742,
2707,
35,
1206,
275,
283,
261,
1205,
63,
1397,
63,
287,
509,
4477,
7,
199,
22679,
63,
16205,
275,
283,
19931,
63,
2190,
63,
7011,
7,
199,
22679,
63,
4609,
63,
742,
2707,
35,
1206,
275,
283,
19931,
63,
2190,
63,
1397,
63,
287,
509,
4477,
7,
421,
199,
32,
6560,
16187,
8,
51,
654,
84,
896,
12,
428,
352,
7226,
2028,
12,
2716,
1524,
23765,
456,
8930,
566,
199,
533,
428,
2901,
7226,
8,
785,
304,
272,
408,
272,
437,
5300,
16187,
367,
9696,
316,
626,
428,
2901,
7226,
365,
5223,
436,
3879,
436,
2597,
5223,
737,
8498,
900,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
542,
63,
1205,
12,
542,
5135,
63,
888,
12,
7192,
456,
63,
2190,
304,
267,
291,
14,
22959,
275,
1052,
267,
291,
14,
261,
1205,
275,
542,
63,
1205,
267,
291,
14,
19931,
63,
888,
275,
542,
5135,
63,
888,
267,
291,
14,
2587,
456,
63,
888,
275,
7192,
456,
63,
2190,
14,
2587,
456,
340,
7192,
456,
63,
2190,
587,
488,
398,
291,
423,
1074,
63,
261,
1205,
342,
267,
291,
423,
1074,
63,
4930,
63,
888,
342,
267,
291,
423,
1074,
63,
2587,
456,
63,
888,
342,
339,
347,
485,
1074,
63,
261,
1205,
8,
277,
304,
267,
408,
267,
2670,
8836,
428,
2901,
7226,
2897,
687,
542,
1205,
1072,
14,
398,
13468,
402,
1072,
687,
542,
1205,
1414,
787,
3544,
12141,
14,
267,
408,
267,
340,
291,
14,
261,
1205,
14,
576,
459,
19931,
63,
1205,
418,
1137,
283,
3827,
356,
288,
291,
14,
22959,
59,
9390,
4961,
63,
16205,
61,
275,
291,
14,
261,
1205,
14,
576,
459,
19931,
63,
1205,
418,
267,
916,
291,
14,
261,
1205,
14,
576,
459,
1818,
63,
632,
418,
1137,
283,
287,
509,
4477,
356,
288,
291,
14,
22959,
59,
9390,
4961,
63,
4609,
63,
742,
2707,
35,
1206,
61,
275,
291,
14,
261,
1205,
14,
576,
459,
1818,
63,
632,
418,
339,
347,
485,
1074,
63,
4930,
63,
888,
8,
277,
304,
267,
408,
267,
2670,
626,
428,
2901,
7226,
365,
440,
6980,
315,
1182,
6839,
15,
24030,
15,
19931,
14,
398,
961,
570,
16756,
314,
8498,
2897,
367,
428,
2901,
7226,
14,
267,
408,
267,
2450,
63,
585,
275,
291,
14,
19931,
63,
888,
14,
576,
14,
362,
360,
899,
26030,
358,
267,
340,
2450,
63,
585,
365,
488,
26,
288,
291,
14,
22959,
59,
22679,
63,
4609,
63,
742,
2707,
35,
1206,
61,
275,
283,
7718,
315,
1101,
334,
2623,
32237,
701,
849,
3171,
267,
916,
2450,
63,
585,
508,
283,
7011,
356,
288,
291,
14,
22959,
59,
22679,
63,
16205,
61,
275,
2450,
63,
585,
267,
916,
2450,
63,
585,
1137,
283,
287,
509,
4477,
356,
288,
291,
14,
22959,
59,
22679,
63,
4609,
63,
742,
2707,
35,
1206,
61,
275,
2450,
63,
585,
339,
347,
485,
1074,
63,
2587,
456,
63,
888,
8,
277,
304,
267,
408,
267,
2670,
7192,
456,
436,
7192,
456,
499,
367,
5114,
8498,
1511,
340,
542,
5135,
2202,
365,
440,
1806,
25045,
14,
398,
1316,
22263,
22763,
626,
1454,
12141,
365,
10226,
315,
7192,
456,
2897,
14,
398,
7192,
456,
365,
315,
26006,
352,
13,
22,
436,
314,
8498,
1004,
10734,
9987,
2839,
288,
5114,
1182,
4930,
15,
2611,
472,
9494,
13,
18,
14,
20,
14,
1165,
13,
19931,
13,
1840,
8533,
1780,
1643,
882
] |
[
199,
899,
14091,
199,
18673,
199,
199,
17039,
281,
367,
1655,
6114,
7252,
402,
428,
2901,
7226,
3769,
6980,
701,
1263,
4910,
199,
4561,
370,
314,
4390,
14,
2779,
4440,
2058,
402,
199,
26,
533,
1705,
262,
22727,
83,
14,
11531,
14,
261,
1205,
14,
51,
654,
84,
896,
3559,
436,
199,
26,
533,
1705,
262,
22727,
83,
14,
11531,
14,
19931,
63,
888,
14,
20920,
7226,
2028,
64,
21295,
436,
199,
26,
533,
1705,
262,
22727,
83,
14,
6560,
262,
1192,
14,
2587,
456,
63,
2190,
14,
23765,
456,
8930,
64,
5300,
16187,
14,
199,
199,
7940,
3509,
282,
2600,
1124,
22959,
1040,
315,
1314,
652,
14086,
10501,
8826,
543,
199,
1612,
465,
11924,
436,
1338,
787,
4565,
2385,
543,
10501,
5160,
26,
199,
199,
10,
1124,
261,
1205,
63,
7011,
1040,
446,
428,
2901,
7226,
365,
6980,
641,
8836,
14,
199,
10,
1124,
261,
1205,
63,
1397,
63,
287,
509,
4477,
1040,
446,
428,
2901,
7226,
365,
440,
315,
655,
509,
4477,
818,
14,
199,
10,
1124,
2587,
456,
63,
7011,
1040,
446,
428,
2901,
7226,
365,
663,
315,
598,
82,
456,
370,
506,
6980,
14,
199,
10,
1124,
2587,
456,
63,
1397,
63,
287,
509,
4477,
1040,
446,
428,
2901,
7226,
365,
663,
315,
598,
82,
456,
370,
440,
506,
315,
655,
509,
4477,
818,
14,
199,
10,
1124,
19931,
63,
2190,
63,
7011,
1040,
446,
428,
2901,
7226,
365,
663,
315,
2897,
570,
370,
506,
6980,
14,
199,
10,
1124,
261,
1205,
63,
1397,
63,
287,
509,
4477,
1040,
446,
428,
2901,
7226,
365,
663,
315,
2897,
570,
370,
440,
506,
315,
655,
509,
4477,
818,
14,
199,
199,
22787,
26,
272,
1306,
542,
5135,
275,
5709,
59,
899,
14091,
61,
272,
1306,
542,
5135,
14,
745,
342,
272,
756,
272,
1306,
542,
5135,
14,
22959,
272,
791,
2587,
456,
63,
7011,
356,
18744,
2611,
472,
9494,
13,
18,
14,
22,
14,
708,
13,
15463,
14,
352,
22,
14,
88,
1184,
63,
772,
542,
5135,
29,
16,
882,
1738,
29,
2263,
995,
1362,
283,
19931,
63,
2190,
63,
7011,
356,
283,
7011,
297,
1362,
283,
261,
1205,
63,
1397,
63,
287,
509,
4477,
356,
283,
529,
32237,
936,
199,
624,
199,
199,
504,
2508,
1018,
14,
5265,
492,
5300,
16187,
199,
504,
2508,
11531,
14,
261,
1205,
492,
428,
654,
84,
896,
199,
504,
2508,
6560,
262,
1192,
14,
2587,
456,
63,
2190,
492,
598,
82,
456,
8930,
199,
504,
2508,
11531,
14,
19931,
63,
888,
492,
428,
352,
7226,
2028,
199,
199,
3975,
2533,
63,
16205,
275,
283,
2587,
456,
63,
7011,
7,
199,
3975,
2533,
63,
4609,
63,
742,
2707,
35,
1206,
275,
283,
2587,
456,
63,
1397,
63,
287,
509,
4477,
7,
199,
9390,
4961,
63,
16205,
275,
283,
261,
1205,
63,
7011,
7,
199,
9390,
4961,
63,
4609,
63,
742,
2707,
35,
1206,
275,
283,
261,
1205,
63,
1397,
63,
287,
509,
4477,
7,
199,
22679,
63,
16205,
275,
283,
19931,
63,
2190,
63,
7011,
7,
199,
22679,
63,
4609,
63,
742,
2707,
35,
1206,
275,
283,
19931,
63,
2190,
63,
1397,
63,
287,
509,
4477,
7,
421,
199,
32,
6560,
16187,
8,
51,
654,
84,
896,
12,
428,
352,
7226,
2028,
12,
2716,
1524,
23765,
456,
8930,
566,
199,
533,
428,
2901,
7226,
8,
785,
304,
272,
408,
272,
437,
5300,
16187,
367,
9696,
316,
626,
428,
2901,
7226,
365,
5223,
436,
3879,
436,
2597,
5223,
737,
8498,
900,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
542,
63,
1205,
12,
542,
5135,
63,
888,
12,
7192,
456,
63,
2190,
304,
267,
291,
14,
22959,
275,
1052,
267,
291,
14,
261,
1205,
275,
542,
63,
1205,
267,
291,
14,
19931,
63,
888,
275,
542,
5135,
63,
888,
267,
291,
14,
2587,
456,
63,
888,
275,
7192,
456,
63,
2190,
14,
2587,
456,
340,
7192,
456,
63,
2190,
587,
488,
398,
291,
423,
1074,
63,
261,
1205,
342,
267,
291,
423,
1074,
63,
4930,
63,
888,
342,
267,
291,
423,
1074,
63,
2587,
456,
63,
888,
342,
339,
347,
485,
1074,
63,
261,
1205,
8,
277,
304,
267,
408,
267,
2670,
8836,
428,
2901,
7226,
2897,
687,
542,
1205,
1072,
14,
398,
13468,
402,
1072,
687,
542,
1205,
1414,
787,
3544,
12141,
14,
267,
408,
267,
340,
291,
14,
261,
1205,
14,
576,
459,
19931,
63,
1205,
418,
1137,
283,
3827,
356,
288,
291,
14,
22959,
59,
9390,
4961,
63,
16205,
61,
275,
291,
14,
261,
1205,
14,
576,
459,
19931,
63,
1205,
418,
267,
916,
291,
14,
261,
1205,
14,
576,
459,
1818,
63,
632,
418,
1137,
283,
287,
509,
4477,
356,
288,
291,
14,
22959,
59,
9390,
4961,
63,
4609,
63,
742,
2707,
35,
1206,
61,
275,
291,
14,
261,
1205,
14,
576,
459,
1818,
63,
632,
418,
339,
347,
485,
1074,
63,
4930,
63,
888,
8,
277,
304,
267,
408,
267,
2670,
626,
428,
2901,
7226,
365,
440,
6980,
315,
1182,
6839,
15,
24030,
15,
19931,
14,
398,
961,
570,
16756,
314,
8498,
2897,
367,
428,
2901,
7226,
14,
267,
408,
267,
2450,
63,
585,
275,
291,
14,
19931,
63,
888,
14,
576,
14,
362,
360,
899,
26030,
358,
267,
340,
2450,
63,
585,
365,
488,
26,
288,
291,
14,
22959,
59,
22679,
63,
4609,
63,
742,
2707,
35,
1206,
61,
275,
283,
7718,
315,
1101,
334,
2623,
32237,
701,
849,
3171,
267,
916,
2450,
63,
585,
508,
283,
7011,
356,
288,
291,
14,
22959,
59,
22679,
63,
16205,
61,
275,
2450,
63,
585,
267,
916,
2450,
63,
585,
1137,
283,
287,
509,
4477,
356,
288,
291,
14,
22959,
59,
22679,
63,
4609,
63,
742,
2707,
35,
1206,
61,
275,
2450,
63,
585,
339,
347,
485,
1074,
63,
2587,
456,
63,
888,
8,
277,
304,
267,
408,
267,
2670,
7192,
456,
436,
7192,
456,
499,
367,
5114,
8498,
1511,
340,
542,
5135,
2202,
365,
440,
1806,
25045,
14,
398,
1316,
22263,
22763,
626,
1454,
12141,
365,
10226,
315,
7192,
456,
2897,
14,
398,
7192,
456,
365,
315,
26006,
352,
13,
22,
436,
314,
8498,
1004,
10734,
9987,
2839,
288,
5114,
1182,
4930,
15,
2611,
472,
9494,
13,
18,
14,
20,
14,
1165,
13,
19931,
13,
1840,
8533,
1780,
1643,
882,
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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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
] |
Dawny33/luigi
|
test/worker_test.py
|
5
|
27132
|
# -*- coding: utf-8 -*-
#
# Copyright 2012-2015 Spotify AB
#
# 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 print_function
import functools
import logging
import os
import shutil
import signal
import tempfile
import threading
import time
from helpers import unittest
import luigi.notifications
import luigi.worker
import mock
from helpers import with_config, skipOnTravis
from luigi import ExternalTask, RemoteScheduler, Task
from luigi.mock import MockTarget, MockFileSystem
from luigi.scheduler import CentralPlannerScheduler
from luigi.worker import Worker
from luigi import six
luigi.notifications.DEBUG = True
class DummyTask(Task):
def __init__(self, *args, **kwargs):
super(DummyTask, self).__init__(*args, **kwargs)
self.has_run = False
def complete(self):
return self.has_run
def run(self):
logging.debug("%s - setting has_run", self.task_id)
self.has_run = True
class DynamicDummyTask(Task):
p = luigi.Parameter()
def output(self):
return luigi.LocalTarget(self.p)
def run(self):
with self.output().open('w') as f:
f.write('Done!')
time.sleep(0.5) # so we can benchmark & see if parallelization works
class DynamicDummyTaskWithNamespace(DynamicDummyTask):
task_namespace = 'banana'
class DynamicRequires(Task):
p = luigi.Parameter()
use_banana_task = luigi.BoolParameter(default=False)
def output(self):
return luigi.LocalTarget(os.path.join(self.p, 'parent'))
def run(self):
if self.use_banana_task:
task_cls = DynamicDummyTaskWithNamespace
else:
task_cls = DynamicDummyTask
dummy_targets = yield [task_cls(os.path.join(self.p, str(i)))
for i in range(5)]
dummy_targets += yield [task_cls(os.path.join(self.p, str(i)))
for i in range(5, 7)]
with self.output().open('w') as f:
for i, d in enumerate(dummy_targets):
for line in d.open('r'):
print('%d: %s' % (i, line.strip()), file=f)
class DynamicRequiresOtherModule(Task):
p = luigi.Parameter()
def output(self):
return luigi.LocalTarget(os.path.join(self.p, 'baz'))
def run(self):
import other_module
other_target_foo = yield other_module.OtherModuleTask(os.path.join(self.p, 'foo'))
other_target_bar = yield other_module.OtherModuleTask(os.path.join(self.p, 'bar'))
with self.output().open('w') as f:
f.write('Done!')
class WorkerTest(unittest.TestCase):
def setUp(self):
# InstanceCache.disable()
self.sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
self.w = Worker(scheduler=self.sch, worker_id='X')
self.w2 = Worker(scheduler=self.sch, worker_id='Y')
self.time = time.time
def tearDown(self):
if time.time != self.time:
time.time = self.time
self.w.stop()
self.w2.stop()
def setTime(self, t):
time.time = lambda: t
def test_dep(self):
class A(Task):
def run(self):
self.has_run = True
def complete(self):
return self.has_run
a = A()
class B(Task):
def requires(self):
return a
def run(self):
self.has_run = True
def complete(self):
return self.has_run
b = B()
a.has_run = False
b.has_run = False
self.assertTrue(self.w.add(b))
self.assertTrue(self.w.run())
self.assertTrue(a.has_run)
self.assertTrue(b.has_run)
def test_stop_getting_new_work(self):
d = DummyTask()
self.w.add(d)
self.assertFalse(d.complete())
self.w.handle_interrupt(signal.SIGUSR1, None)
self.w.run()
self.assertFalse(d.complete())
def test_external_dep(self):
class A(ExternalTask):
def complete(self):
return False
a = A()
class B(Task):
def requires(self):
return a
def run(self):
self.has_run = True
def complete(self):
return self.has_run
b = B()
a.has_run = False
b.has_run = False
self.assertTrue(self.w.add(b))
self.assertTrue(self.w.run())
self.assertFalse(a.has_run)
self.assertFalse(b.has_run)
def test_fail(self):
class A(Task):
def run(self):
self.has_run = True
raise Exception()
def complete(self):
return self.has_run
a = A()
class B(Task):
def requires(self):
return a
def run(self):
self.has_run = True
def complete(self):
return self.has_run
b = B()
a.has_run = False
b.has_run = False
self.assertTrue(self.w.add(b))
self.assertFalse(self.w.run())
self.assertTrue(a.has_run)
self.assertFalse(b.has_run)
def test_unknown_dep(self):
# see central_planner_test.CentralPlannerTest.test_remove_dep
class A(ExternalTask):
def complete(self):
return False
class C(Task):
def complete(self):
return True
def get_b(dep):
class B(Task):
def requires(self):
return dep
def run(self):
self.has_run = True
def complete(self):
return False
b = B()
b.has_run = False
return b
b_a = get_b(A())
b_c = get_b(C())
self.assertTrue(self.w.add(b_a))
# So now another worker goes in and schedules C -> B
# This should remove the dep A -> B but will screw up the first worker
self.assertTrue(self.w2.add(b_c))
self.assertFalse(self.w.run()) # should not run anything - the worker should detect that A is broken
self.assertFalse(b_a.has_run)
# not sure what should happen??
# self.w2.run() # should run B since C is fulfilled
# self.assertTrue(b_c.has_run)
def test_unfulfilled_dep(self):
class A(Task):
def complete(self):
return self.done
def run(self):
self.done = True
def get_b(a):
class B(A):
def requires(self):
return a
b = B()
b.done = False
a.done = True
return b
a = A()
b = get_b(a)
self.assertTrue(self.w.add(b))
a.done = False
self.w.run()
self.assertTrue(a.complete())
self.assertTrue(b.complete())
def test_avoid_infinite_reschedule(self):
class A(Task):
def complete(self):
return False
class B(Task):
def complete(self):
return False
def requires(self):
return A()
self.assertTrue(self.w.add(B()))
self.assertFalse(self.w.run())
def test_allow_reschedule_with_many_missing_deps(self):
class A(Task):
""" Task that must run twice to succeed """
i = luigi.IntParameter()
runs = 0
def complete(self):
return self.runs >= 2
def run(self):
self.runs += 1
class B(Task):
done = False
def requires(self):
return map(A, range(20))
def complete(self):
return self.done
def run(self):
self.done = True
b = B()
w = Worker(scheduler=self.sch, worker_id='X', max_reschedules=1)
self.assertTrue(w.add(b))
self.assertFalse(w.run())
# For b to be done, we must have rescheduled its dependencies to run them twice
self.assertTrue(b.complete())
self.assertTrue(all(a.complete() for a in b.deps()))
def test_interleaved_workers(self):
class A(DummyTask):
pass
a = A()
class B(DummyTask):
def requires(self):
return a
class ExternalB(ExternalTask):
task_family = "B"
def complete(self):
return False
b = B()
eb = ExternalB()
self.assertEqual(eb.task_id, "B()")
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
w = Worker(scheduler=sch, worker_id='X')
w2 = Worker(scheduler=sch, worker_id='Y')
self.assertTrue(w.add(b))
self.assertTrue(w2.add(eb))
logging.debug("RUNNING BROKEN WORKER")
self.assertTrue(w2.run())
self.assertFalse(a.complete())
self.assertFalse(b.complete())
logging.debug("RUNNING FUNCTIONAL WORKER")
self.assertTrue(w.run())
self.assertTrue(a.complete())
self.assertTrue(b.complete())
w.stop()
w2.stop()
def test_interleaved_workers2(self):
# two tasks without dependencies, one external, one not
class B(DummyTask):
pass
class ExternalB(ExternalTask):
task_family = "B"
def complete(self):
return False
b = B()
eb = ExternalB()
self.assertEqual(eb.task_id, "B()")
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
w = Worker(scheduler=sch, worker_id='X')
w2 = Worker(scheduler=sch, worker_id='Y')
self.assertTrue(w2.add(eb))
self.assertTrue(w.add(b))
self.assertTrue(w2.run())
self.assertFalse(b.complete())
self.assertTrue(w.run())
self.assertTrue(b.complete())
w.stop()
w2.stop()
def test_interleaved_workers3(self):
class A(DummyTask):
def run(self):
logging.debug('running A')
time.sleep(0.1)
super(A, self).run()
a = A()
class B(DummyTask):
def requires(self):
return a
def run(self):
logging.debug('running B')
super(B, self).run()
b = B()
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
w = Worker(scheduler=sch, worker_id='X', keep_alive=True, count_uniques=True)
w2 = Worker(scheduler=sch, worker_id='Y', keep_alive=True, count_uniques=True, wait_interval=0.1)
self.assertTrue(w.add(a))
self.assertTrue(w2.add(b))
threading.Thread(target=w.run).start()
self.assertTrue(w2.run())
self.assertTrue(a.complete())
self.assertTrue(b.complete())
w.stop()
w2.stop()
def test_die_for_non_unique_pending(self):
class A(DummyTask):
def run(self):
logging.debug('running A')
time.sleep(0.1)
super(A, self).run()
a = A()
class B(DummyTask):
def requires(self):
return a
def run(self):
logging.debug('running B')
super(B, self).run()
b = B()
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
w = Worker(scheduler=sch, worker_id='X', keep_alive=True, count_uniques=True)
w2 = Worker(scheduler=sch, worker_id='Y', keep_alive=True, count_uniques=True, wait_interval=0.1)
self.assertTrue(w.add(b))
self.assertTrue(w2.add(b))
self.assertEqual(w._get_work()[0], 'A()')
self.assertTrue(w2.run())
self.assertFalse(a.complete())
self.assertFalse(b.complete())
w2.stop()
def test_complete_exception(self):
"Tests that a task is still scheduled if its sister task crashes in the complete() method"
class A(DummyTask):
def complete(self):
raise Exception("doh")
a = A()
class C(DummyTask):
pass
c = C()
class B(DummyTask):
def requires(self):
return a, c
b = B()
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
w = Worker(scheduler=sch, worker_id="foo")
self.assertFalse(w.add(b))
self.assertTrue(w.run())
self.assertFalse(b.has_run)
self.assertTrue(c.has_run)
self.assertFalse(a.has_run)
w.stop()
def test_requires_exception(self):
class A(DummyTask):
def requires(self):
raise Exception("doh")
a = A()
class C(DummyTask):
pass
c = C()
class B(DummyTask):
def requires(self):
return a, c
b = B()
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
w = Worker(scheduler=sch, worker_id="foo")
self.assertFalse(w.add(b))
self.assertTrue(w.run())
self.assertFalse(b.has_run)
self.assertTrue(c.has_run)
self.assertFalse(a.has_run)
w.stop()
class DynamicDependenciesTest(unittest.TestCase):
n_workers = 1
timeout = float('inf')
def setUp(self):
self.p = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.p)
def test_dynamic_dependencies(self, use_banana_task=False):
t0 = time.time()
t = DynamicRequires(p=self.p, use_banana_task=use_banana_task)
luigi.build([t], local_scheduler=True, workers=self.n_workers)
self.assertTrue(t.complete())
# loop through output and verify
f = t.output().open('r')
for i in range(7):
self.assertEqual(f.readline().strip(), '%d: Done!' % i)
self.assertTrue(time.time() - t0 < self.timeout)
def test_dynamic_dependencies_with_namespace(self):
self.test_dynamic_dependencies(use_banana_task=True)
def test_dynamic_dependencies_other_module(self):
t = DynamicRequiresOtherModule(p=self.p)
luigi.build([t], local_scheduler=True, workers=self.n_workers)
self.assertTrue(t.complete())
class DynamicDependenciesWithMultipleWorkersTest(DynamicDependenciesTest):
n_workers = 100
timeout = 3.0 # We run 7 tasks that take 0.5s each so it should take less than 3.5s
class WorkerPingThreadTests(unittest.TestCase):
def test_ping_retry(self):
""" Worker ping fails once. Ping continues to try to connect to scheduler
Kind of ugly since it uses actual timing with sleep to test the thread
"""
sch = CentralPlannerScheduler(
retry_delay=100,
remove_delay=1000,
worker_disconnect_delay=10,
)
self._total_pings = 0 # class var so it can be accessed from fail_ping
def fail_ping(worker):
# this will be called from within keep-alive thread...
self._total_pings += 1
raise Exception("Some random exception")
sch.ping = fail_ping
w = Worker(
scheduler=sch,
worker_id="foo",
ping_interval=0.01 # very short between pings to make test fast
)
# let the keep-alive thread run for a bit...
time.sleep(0.1) # yes, this is ugly but it's exactly what we need to test
w.stop()
self.assertTrue(
self._total_pings > 1,
msg="Didn't retry pings (%d pings performed)" % (self._total_pings,)
)
def test_ping_thread_shutdown(self):
w = Worker(ping_interval=0.01)
self.assertTrue(w._keep_alive_thread.is_alive())
w.stop() # should stop within 0.01 s
self.assertFalse(w._keep_alive_thread.is_alive())
def email_patch(test_func):
EMAIL_CONFIG = {"core": {"error-email": "not-a-real-email-address-for-test-only"}, "email": {"force-send": "true"}}
emails = []
def mock_send_email(sender, recipients, msg):
emails.append(msg)
@with_config(EMAIL_CONFIG)
@functools.wraps(test_func)
@mock.patch('smtplib.SMTP')
def run_test(self, smtp):
smtp().sendmail.side_effect = mock_send_email
test_func(self, emails)
return run_test
class WorkerEmailTest(unittest.TestCase):
def setUp(self):
super(WorkerEmailTest, self).setUp()
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
self.worker = Worker(scheduler=sch, worker_id="foo")
def tearDown(self):
self.worker.stop()
@email_patch
def test_connection_error(self, emails):
sch = RemoteScheduler('http://tld.invalid:1337', connect_timeout=1)
worker = Worker(scheduler=sch)
self.waits = 0
def dummy_wait():
self.waits += 1
sch._wait = dummy_wait
class A(DummyTask):
pass
a = A()
self.assertEqual(emails, [])
worker.add(a)
self.assertEqual(self.waits, 2) # should attempt to add it 3 times
self.assertNotEquals(emails, [])
self.assertTrue(emails[0].find("Luigi: Framework error while scheduling %s" % (a,)) != -1)
worker.stop()
@email_patch
def test_complete_error(self, emails):
class A(DummyTask):
def complete(self):
raise Exception("b0rk")
a = A()
self.assertEqual(emails, [])
self.worker.add(a)
self.assertTrue(emails[0].find("Luigi: %s failed scheduling" % (a,)) != -1)
self.worker.run()
self.assertTrue(emails[0].find("Luigi: %s failed scheduling" % (a,)) != -1)
self.assertFalse(a.has_run)
@email_patch
def test_complete_return_value(self, emails):
class A(DummyTask):
def complete(self):
pass # no return value should be an error
a = A()
self.assertEqual(emails, [])
self.worker.add(a)
self.assertTrue(emails[0].find("Luigi: %s failed scheduling" % (a,)) != -1)
self.worker.run()
self.assertTrue(emails[0].find("Luigi: %s failed scheduling" % (a,)) != -1)
self.assertFalse(a.has_run)
@email_patch
def test_run_error(self, emails):
class A(luigi.Task):
def complete(self):
return False
def run(self):
raise Exception("b0rk")
a = A()
self.worker.add(a)
self.assertEqual(emails, [])
self.worker.run()
self.assertTrue(emails[0].find("Luigi: %s FAILED" % (a,)) != -1)
@email_patch
def test_no_error(self, emails):
class A(DummyTask):
pass
a = A()
self.assertEqual(emails, [])
self.worker.add(a)
self.assertEqual(emails, [])
self.worker.run()
self.assertEqual(emails, [])
self.assertTrue(a.complete())
class RaiseSystemExit(luigi.Task):
def run(self):
raise SystemExit("System exit!!")
class SuicidalWorker(luigi.Task):
signal = luigi.IntParameter()
def run(self):
os.kill(os.getpid(), self.signal)
class HungWorker(luigi.Task):
worker_timeout = luigi.IntParameter(default=None)
def run(self):
while True:
pass
def complete(self):
return False
class MultipleWorkersTest(unittest.TestCase):
@unittest.skip('Always skip. There are many intermittent failures')
# This pass under python3 when run as `nosetests test/worker_test.py`
# but not as `nosetests test`. Probably some side effect on previous tests
@unittest.skipIf(six.PY3, 'This test fail on python3 when run with tox.')
def test_multiple_workers(self):
# Test using multiple workers
# Also test generating classes dynamically since this may reflect issues with
# various platform and how multiprocessing is implemented. If it's using os.fork
# under the hood it should be fine, but dynamic classses can't be pickled, so
# other implementations of multiprocessing (using spawn etc) may fail
class MyDynamicTask(luigi.Task):
x = luigi.Parameter()
def run(self):
time.sleep(0.1)
t0 = time.time()
luigi.build([MyDynamicTask(i) for i in range(100)], workers=100, local_scheduler=True)
self.assertTrue(time.time() < t0 + 5.0) # should ideally take exactly 0.1s, but definitely less than 10.0
def test_zero_workers(self):
d = DummyTask()
luigi.build([d], workers=0, local_scheduler=True)
self.assertFalse(d.complete())
def test_system_exit(self):
# This would hang indefinitely before this fix:
# https://github.com/spotify/luigi/pull/439
luigi.build([RaiseSystemExit()], workers=2, local_scheduler=True)
def test_term_worker(self):
luigi.build([SuicidalWorker(signal.SIGTERM)], workers=2, local_scheduler=True)
def test_kill_worker(self):
luigi.build([SuicidalWorker(signal.SIGKILL)], workers=2, local_scheduler=True)
def test_purge_multiple_workers(self):
w = Worker(worker_processes=2, wait_interval=0.01)
t1 = SuicidalWorker(signal.SIGTERM)
t2 = SuicidalWorker(signal.SIGKILL)
w.add(t1)
w.add(t2)
w._run_task(t1.task_id)
w._run_task(t2.task_id)
time.sleep(1.0)
w._handle_next_task()
w._handle_next_task()
w._handle_next_task()
def test_time_out_hung_worker(self):
luigi.build([HungWorker(0.1)], workers=2, local_scheduler=True)
@skipOnTravis('https://travis-ci.org/spotify/luigi/jobs/72953986')
@mock.patch('luigi.worker.time')
def test_purge_hung_worker_default_timeout_time(self, mock_time):
w = Worker(worker_processes=2, wait_interval=0.01, timeout=5)
mock_time.time.return_value = 0
w.add(HungWorker())
w._run_task('HungWorker(worker_timeout=None)')
mock_time.time.return_value = 5
w._handle_next_task()
self.assertEqual(1, len(w._running_tasks))
mock_time.time.return_value = 6
w._handle_next_task()
self.assertEqual(0, len(w._running_tasks))
@mock.patch('luigi.worker.time')
def test_purge_hung_worker_override_timeout_time(self, mock_time):
w = Worker(worker_processes=2, wait_interval=0.01, timeout=5)
mock_time.time.return_value = 0
w.add(HungWorker(10))
w._run_task('HungWorker(worker_timeout=10)')
mock_time.time.return_value = 10
w._handle_next_task()
self.assertEqual(1, len(w._running_tasks))
mock_time.time.return_value = 11
w._handle_next_task()
self.assertEqual(0, len(w._running_tasks))
class Dummy2Task(Task):
p = luigi.Parameter()
def output(self):
return MockTarget(self.p)
def run(self):
f = self.output().open('w')
f.write('test')
f.close()
class AssistantTest(unittest.TestCase):
def setUp(self):
self.sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
self.w = Worker(scheduler=self.sch, worker_id='X')
self.assistant = Worker(scheduler=self.sch, worker_id='Y', assistant=True)
def test_get_work(self):
d = Dummy2Task('123')
self.w.add(d)
self.assertFalse(d.complete())
self.assistant.run()
self.assertTrue(d.complete())
def test_bad_job_type(self):
class Dummy3Task(Dummy2Task):
task_family = 'UnknownTaskFamily'
d = Dummy3Task('123')
self.w.add(d)
self.assertFalse(d.complete())
self.assertFalse(self.assistant.run())
self.assertFalse(d.complete())
self.assertEqual(list(self.sch.task_list('FAILED', '').keys()), [str(d)])
def test_unimported_job_type(self):
class NotImportedTask(luigi.Task):
task_family = 'UnimportedTask'
task_module = None
task = NotImportedTask()
# verify that it can't run the task without the module info necessary to import it
self.w.add(task)
self.assertFalse(self.assistant.run())
self.assertEqual(list(self.sch.task_list('FAILED', '').keys()), ['UnimportedTask()'])
# check that it can import with the right module
task.task_module = 'dummy_test_module.not_imported'
self.w.add(task)
self.assertTrue(self.assistant.run())
self.assertEqual(list(self.sch.task_list('DONE', '').keys()), ['UnimportedTask()'])
class ForkBombTask(luigi.Task):
depth = luigi.IntParameter()
breadth = luigi.IntParameter()
p = luigi.Parameter(default=(0, )) # ehm for some weird reason [0] becomes a tuple...?
def output(self):
return MockTarget('.'.join(map(str, self.p)))
def run(self):
with self.output().open('w') as f:
f.write('Done!')
def requires(self):
if len(self.p) < self.depth:
for i in range(self.breadth):
yield ForkBombTask(self.depth, self.breadth, self.p + (i, ))
class TaskLimitTest(unittest.TestCase):
def tearDown(self):
MockFileSystem().remove('')
@with_config({'core': {'worker-task-limit': '6'}})
def test_task_limit_exceeded(self):
w = Worker()
t = ForkBombTask(3, 2)
w.add(t)
w.run()
self.assertFalse(t.complete())
leaf_tasks = [ForkBombTask(3, 2, branch) for branch in [(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1)]]
self.assertEquals(3, sum(t.complete() for t in leaf_tasks), "should have gracefully completed as much as possible even though the single last leaf didn't get scheduled")
@with_config({'core': {'worker-task-limit': '7'}})
def test_task_limit_not_exceeded(self):
w = Worker()
t = ForkBombTask(3, 2)
w.add(t)
w.run()
self.assertTrue(t.complete())
def test_no_task_limit(self):
w = Worker()
t = ForkBombTask(4, 2)
w.add(t)
w.run()
self.assertTrue(t.complete())
if __name__ == '__main__':
luigi.run()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
428,
555,
3338,
14840,
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,
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,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
9143,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
4673,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
504,
10897,
492,
2882,
199,
199,
646,
19485,
14,
12782,
199,
646,
19485,
14,
6599,
199,
646,
1683,
199,
504,
10897,
492,
543,
63,
888,
12,
3372,
3314,
2437,
5068,
199,
504,
19485,
492,
18802,
4476,
12,
17283,
11251,
12,
8495,
199,
504,
19485,
14,
1805,
492,
4420,
4277,
12,
4420,
17521,
199,
504,
19485,
14,
8874,
492,
32267,
9117,
3714,
5161,
11251,
199,
504,
19485,
14,
6599,
492,
23886,
199,
504,
19485,
492,
3816,
199,
199,
26795,
14,
12782,
14,
5287,
275,
715,
421,
199,
533,
9762,
4476,
8,
4476,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
11324,
4476,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1989,
63,
1065,
275,
756,
339,
347,
4890,
8,
277,
304,
267,
372,
291,
14,
1989,
63,
1065,
339,
347,
1255,
8,
277,
304,
267,
2050,
14,
1757,
3647,
83,
446,
4260,
965,
63,
1065,
401,
291,
14,
1765,
63,
344,
9,
267,
291,
14,
1989,
63,
1065,
275,
715,
421,
199,
533,
21907,
11324,
4476,
8,
4476,
304,
272,
299,
275,
19485,
14,
4720,
342,
339,
347,
1072,
8,
277,
304,
267,
372,
19485,
14,
5339,
4277,
8,
277,
14,
80,
9,
339,
347,
1255,
8,
277,
304,
267,
543,
291,
14,
1199,
1252,
1490,
360,
87,
358,
465,
289,
26,
288,
289,
14,
952,
360,
10759,
10916,
267,
900,
14,
4532,
8,
16,
14,
21,
9,
221,
327,
880,
781,
883,
12338,
1253,
1937,
340,
30042,
25698,
5419,
421,
199,
533,
21907,
11324,
4476,
3007,
8814,
8,
14451,
11324,
4476,
304,
272,
2120,
63,
3251,
275,
283,
13206,
6738,
7,
421,
199,
533,
21907,
18153,
8,
4476,
304,
272,
299,
275,
19485,
14,
4720,
342,
272,
675,
63,
13206,
6738,
63,
1765,
275,
19485,
14,
10349,
4720,
8,
885,
29,
797,
9,
339,
347,
1072,
8,
277,
304,
267,
372,
19485,
14,
5339,
4277,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
1708,
1333,
339,
347,
1255,
8,
277,
304,
267,
340,
291,
14,
1180,
63,
13206,
6738,
63,
1765,
26,
288,
2120,
63,
1886,
275,
21907,
11324,
4476,
3007,
8814,
267,
587,
26,
288,
2120,
63,
1886,
275,
21907,
11324,
4476,
267,
7283,
63,
4684,
275,
1995,
359,
1765,
63,
1886,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
620,
8,
73,
1724,
3044,
367,
284,
315,
1425,
8,
21,
1874,
267,
7283,
63,
4684,
847,
1995,
359,
1765,
63,
1886,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
620,
8,
73,
1724,
1816,
367,
284,
315,
1425,
8,
21,
12,
1520,
1874,
267,
543,
291,
14,
1199,
1252,
1490,
360,
87,
358,
465,
289,
26,
288,
367,
284,
12,
366,
315,
3874,
8,
5869,
63,
4684,
304,
355,
367,
1004,
315,
366,
14,
1490,
360,
82,
735,
490,
870,
3508,
68,
26,
450,
83,
7,
450,
334,
73,
12,
1004,
14,
1913,
4000,
570,
29,
70,
9,
421,
199,
533,
21907,
18153,
8632,
2377,
8,
4476,
304,
272,
299,
275,
19485,
14,
4720,
342,
339,
347,
1072,
8,
277,
304,
267,
372,
19485,
14,
5339,
4277,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
6185,
1333,
339,
347,
1255,
8,
277,
304,
267,
492,
1163,
63,
578,
267,
1163,
63,
1375,
63,
1421,
275,
1995,
1163,
63,
578,
14,
8632,
2377,
4476,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
1421,
1333,
267,
1163,
63,
1375,
63,
1700,
275,
1995,
1163,
63,
578,
14,
8632,
2377,
4476,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
1700,
1333,
398,
543,
291,
14,
1199,
1252,
1490,
360,
87,
358,
465,
289,
26,
288,
289,
14,
952,
360,
10759,
10916,
421,
199,
533,
23886,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
327,
10066,
4437,
14,
5993,
342,
267,
291,
14,
15820,
275,
32267,
9117,
3714,
5161,
11251,
8,
7154,
63,
5814,
29,
1960,
12,
2813,
63,
5814,
29,
5279,
12,
7239,
63,
10673,
63,
5814,
29,
709,
9,
267,
291,
14,
87,
275,
23886,
8,
8874,
29,
277,
14,
15820,
12,
7239,
63,
344,
534,
56,
358,
267,
291,
14,
87,
18,
275,
23886,
8,
8874,
29,
277,
14,
15820,
12,
7239,
63,
344,
534,
57,
358,
267,
291,
14,
521,
275,
900,
14,
521,
339,
347,
6766,
8,
277,
304,
267,
340,
900,
14,
521,
1137,
291,
14,
521,
26,
288,
900,
14,
521,
275,
291,
14,
521,
267,
291,
14,
87,
14,
2379,
342,
267,
291,
14,
87,
18,
14,
2379,
342,
339,
347,
663,
1366,
8,
277,
12,
307,
304,
267,
900,
14,
521,
275,
2400,
26,
307,
339,
347,
511,
63,
2601,
8,
277,
304,
267,
1021,
437,
8,
4476,
304,
953,
347,
1255,
8,
277,
304,
355,
291,
14,
1989,
63,
1065,
275,
715,
953,
347,
4890,
8,
277,
304,
355,
372,
291,
14,
1989,
63,
1065,
267,
282,
275,
437,
342,
398,
1021,
699,
8,
4476,
304,
953,
347
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6029,
13,
7806,
428,
555,
3338,
14840,
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,
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,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
9143,
199,
646,
2050,
199,
646,
747,
199,
646,
5145,
199,
646,
4673,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
504,
10897,
492,
2882,
199,
199,
646,
19485,
14,
12782,
199,
646,
19485,
14,
6599,
199,
646,
1683,
199,
504,
10897,
492,
543,
63,
888,
12,
3372,
3314,
2437,
5068,
199,
504,
19485,
492,
18802,
4476,
12,
17283,
11251,
12,
8495,
199,
504,
19485,
14,
1805,
492,
4420,
4277,
12,
4420,
17521,
199,
504,
19485,
14,
8874,
492,
32267,
9117,
3714,
5161,
11251,
199,
504,
19485,
14,
6599,
492,
23886,
199,
504,
19485,
492,
3816,
199,
199,
26795,
14,
12782,
14,
5287,
275,
715,
421,
199,
533,
9762,
4476,
8,
4476,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
11324,
4476,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
1989,
63,
1065,
275,
756,
339,
347,
4890,
8,
277,
304,
267,
372,
291,
14,
1989,
63,
1065,
339,
347,
1255,
8,
277,
304,
267,
2050,
14,
1757,
3647,
83,
446,
4260,
965,
63,
1065,
401,
291,
14,
1765,
63,
344,
9,
267,
291,
14,
1989,
63,
1065,
275,
715,
421,
199,
533,
21907,
11324,
4476,
8,
4476,
304,
272,
299,
275,
19485,
14,
4720,
342,
339,
347,
1072,
8,
277,
304,
267,
372,
19485,
14,
5339,
4277,
8,
277,
14,
80,
9,
339,
347,
1255,
8,
277,
304,
267,
543,
291,
14,
1199,
1252,
1490,
360,
87,
358,
465,
289,
26,
288,
289,
14,
952,
360,
10759,
10916,
267,
900,
14,
4532,
8,
16,
14,
21,
9,
221,
327,
880,
781,
883,
12338,
1253,
1937,
340,
30042,
25698,
5419,
421,
199,
533,
21907,
11324,
4476,
3007,
8814,
8,
14451,
11324,
4476,
304,
272,
2120,
63,
3251,
275,
283,
13206,
6738,
7,
421,
199,
533,
21907,
18153,
8,
4476,
304,
272,
299,
275,
19485,
14,
4720,
342,
272,
675,
63,
13206,
6738,
63,
1765,
275,
19485,
14,
10349,
4720,
8,
885,
29,
797,
9,
339,
347,
1072,
8,
277,
304,
267,
372,
19485,
14,
5339,
4277,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
1708,
1333,
339,
347,
1255,
8,
277,
304,
267,
340,
291,
14,
1180,
63,
13206,
6738,
63,
1765,
26,
288,
2120,
63,
1886,
275,
21907,
11324,
4476,
3007,
8814,
267,
587,
26,
288,
2120,
63,
1886,
275,
21907,
11324,
4476,
267,
7283,
63,
4684,
275,
1995,
359,
1765,
63,
1886,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
620,
8,
73,
1724,
3044,
367,
284,
315,
1425,
8,
21,
1874,
267,
7283,
63,
4684,
847,
1995,
359,
1765,
63,
1886,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
620,
8,
73,
1724,
1816,
367,
284,
315,
1425,
8,
21,
12,
1520,
1874,
267,
543,
291,
14,
1199,
1252,
1490,
360,
87,
358,
465,
289,
26,
288,
367,
284,
12,
366,
315,
3874,
8,
5869,
63,
4684,
304,
355,
367,
1004,
315,
366,
14,
1490,
360,
82,
735,
490,
870,
3508,
68,
26,
450,
83,
7,
450,
334,
73,
12,
1004,
14,
1913,
4000,
570,
29,
70,
9,
421,
199,
533,
21907,
18153,
8632,
2377,
8,
4476,
304,
272,
299,
275,
19485,
14,
4720,
342,
339,
347,
1072,
8,
277,
304,
267,
372,
19485,
14,
5339,
4277,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
6185,
1333,
339,
347,
1255,
8,
277,
304,
267,
492,
1163,
63,
578,
267,
1163,
63,
1375,
63,
1421,
275,
1995,
1163,
63,
578,
14,
8632,
2377,
4476,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
1421,
1333,
267,
1163,
63,
1375,
63,
1700,
275,
1995,
1163,
63,
578,
14,
8632,
2377,
4476,
8,
736,
14,
515,
14,
904,
8,
277,
14,
80,
12,
283,
1700,
1333,
398,
543,
291,
14,
1199,
1252,
1490,
360,
87,
358,
465,
289,
26,
288,
289,
14,
952,
360,
10759,
10916,
421,
199,
533,
23886,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
327,
10066,
4437,
14,
5993,
342,
267,
291,
14,
15820,
275,
32267,
9117,
3714,
5161,
11251,
8,
7154,
63,
5814,
29,
1960,
12,
2813,
63,
5814,
29,
5279,
12,
7239,
63,
10673,
63,
5814,
29,
709,
9,
267,
291,
14,
87,
275,
23886,
8,
8874,
29,
277,
14,
15820,
12,
7239,
63,
344,
534,
56,
358,
267,
291,
14,
87,
18,
275,
23886,
8,
8874,
29,
277,
14,
15820,
12,
7239,
63,
344,
534,
57,
358,
267,
291,
14,
521,
275,
900,
14,
521,
339,
347,
6766,
8,
277,
304,
267,
340,
900,
14,
521,
1137,
291,
14,
521,
26,
288,
900,
14,
521,
275,
291,
14,
521,
267,
291,
14,
87,
14,
2379,
342,
267,
291,
14,
87,
18,
14,
2379,
342,
339,
347,
663,
1366,
8,
277,
12,
307,
304,
267,
900,
14,
521,
275,
2400,
26,
307,
339,
347,
511,
63,
2601,
8,
277,
304,
267,
1021,
437,
8,
4476,
304,
953,
347,
1255,
8,
277,
304,
355,
291,
14,
1989,
63,
1065,
275,
715,
953,
347,
4890,
8,
277,
304,
355,
372,
291,
14,
1989,
63,
1065,
267,
282,
275,
437,
342,
398,
1021,
699,
8,
4476,
304,
953,
347,
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,
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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
] |
darjus-amzn/boto
|
tests/unit/ec2/test_blockdevicemapping.py
|
111
|
6739
|
from tests.compat import unittest
from boto.ec2.connection import EC2Connection
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
from tests.compat import OrderedDict
from tests.unit import AWSMockServiceTestCase
class BlockDeviceTypeTests(unittest.TestCase):
def setUp(self):
self.block_device_type = BlockDeviceType()
def check_that_attribute_has_been_set(self, name, value, attribute):
self.block_device_type.endElement(name, value, None)
self.assertEqual(getattr(self.block_device_type, attribute), value)
def test_endElement_sets_correct_attributes_with_values(self):
for arguments in [("volumeId", 1, "volume_id"),
("virtualName", "some name", "ephemeral_name"),
("snapshotId", 1, "snapshot_id"),
("volumeSize", 1, "size"),
("status", "some status", "status"),
("attachTime", 1, "attach_time"),
("somethingRandom", "somethingRandom", "somethingRandom")]:
self.check_that_attribute_has_been_set(arguments[0], arguments[1], arguments[2])
def test_endElement_with_name_NoDevice_value_true(self):
self.block_device_type.endElement("NoDevice", 'true', None)
self.assertEqual(self.block_device_type.no_device, True)
def test_endElement_with_name_NoDevice_value_other(self):
self.block_device_type.endElement("NoDevice", 'something else', None)
self.assertEqual(self.block_device_type.no_device, False)
def test_endElement_with_name_deleteOnTermination_value_true(self):
self.block_device_type.endElement("deleteOnTermination", "true", None)
self.assertEqual(self.block_device_type.delete_on_termination, True)
def test_endElement_with_name_deleteOnTermination_value_other(self):
self.block_device_type.endElement("deleteOnTermination", 'something else', None)
self.assertEqual(self.block_device_type.delete_on_termination, False)
def test_endElement_with_name_encrypted_value_true(self):
self.block_device_type.endElement("Encrypted", "true", None)
self.assertEqual(self.block_device_type.encrypted, True)
def test_endElement_with_name_Encrypted_value_other(self):
self.block_device_type.endElement("Encrypted", 'something else', None)
self.assertEqual(self.block_device_type.encrypted, False)
class BlockDeviceMappingTests(unittest.TestCase):
def setUp(self):
self.block_device_mapping = BlockDeviceMapping()
def block_device_type_eq(self, b1, b2):
if isinstance(b1, BlockDeviceType) and isinstance(b2, BlockDeviceType):
return all([b1.connection == b2.connection,
b1.ephemeral_name == b2.ephemeral_name,
b1.no_device == b2.no_device,
b1.volume_id == b2.volume_id,
b1.snapshot_id == b2.snapshot_id,
b1.status == b2.status,
b1.attach_time == b2.attach_time,
b1.delete_on_termination == b2.delete_on_termination,
b1.size == b2.size,
b1.encrypted == b2.encrypted])
def test_startElement_with_name_ebs_sets_and_returns_current_value(self):
retval = self.block_device_mapping.startElement("ebs", None, None)
assert self.block_device_type_eq(retval, BlockDeviceType(self.block_device_mapping))
def test_startElement_with_name_virtualName_sets_and_returns_current_value(self):
retval = self.block_device_mapping.startElement("virtualName", None, None)
assert self.block_device_type_eq(retval, BlockDeviceType(self.block_device_mapping))
def test_endElement_with_name_device_sets_current_name_dev_null(self):
self.block_device_mapping.endElement("device", "/dev/null", None)
self.assertEqual(self.block_device_mapping.current_name, "/dev/null")
def test_endElement_with_name_device_sets_current_name(self):
self.block_device_mapping.endElement("deviceName", "some device name", None)
self.assertEqual(self.block_device_mapping.current_name, "some device name")
def test_endElement_with_name_item_sets_current_name_key_to_current_value(self):
self.block_device_mapping.current_name = "some name"
self.block_device_mapping.current_value = "some value"
self.block_device_mapping.endElement("item", "some item", None)
self.assertEqual(self.block_device_mapping["some name"], "some value")
class TestLaunchConfiguration(AWSMockServiceTestCase):
connection_class = EC2Connection
def default_body(self):
# This is a dummy response
return b"""
<DescribeLaunchConfigurationsResponse>
</DescribeLaunchConfigurationsResponse>
"""
def test_run_instances_block_device_mapping(self):
# Same as the test in ``unit/ec2/autoscale/test_group.py:TestLaunchConfiguration``,
# but with modified request parameters (due to a mismatch between EC2 &
# Autoscaling).
self.set_http_response(status_code=200)
dev_sdf = BlockDeviceType(snapshot_id='snap-12345')
dev_sdg = BlockDeviceType(snapshot_id='snap-12346', delete_on_termination=True, encrypted=True)
class OrderedBlockDeviceMapping(OrderedDict, BlockDeviceMapping):
pass
bdm = OrderedBlockDeviceMapping()
bdm.update(OrderedDict((('/dev/sdf', dev_sdf), ('/dev/sdg', dev_sdg))))
response = self.service_connection.run_instances(
image_id='123456',
instance_type='m1.large',
security_groups=['group1', 'group2'],
block_device_map=bdm
)
self.assert_request_parameters({
'Action': 'RunInstances',
'BlockDeviceMapping.1.DeviceName': '/dev/sdf',
'BlockDeviceMapping.1.Ebs.DeleteOnTermination': 'false',
'BlockDeviceMapping.1.Ebs.SnapshotId': 'snap-12345',
'BlockDeviceMapping.2.DeviceName': '/dev/sdg',
'BlockDeviceMapping.2.Ebs.DeleteOnTermination': 'true',
'BlockDeviceMapping.2.Ebs.SnapshotId': 'snap-12346',
'BlockDeviceMapping.2.Ebs.Encrypted': 'true',
'ImageId': '123456',
'InstanceType': 'm1.large',
'MaxCount': 1,
'MinCount': 1,
'SecurityGroup.1': 'group1',
'SecurityGroup.2': 'group2',
}, ignore_params_values=[
'Version', 'AWSAccessKeyId', 'SignatureMethod', 'SignatureVersion',
'Timestamp'
])
if __name__ == "__main__":
unittest.main()
|
mit
|
[
504,
2295,
14,
5819,
492,
2882,
199,
199,
504,
6055,
14,
825,
18,
14,
2105,
492,
15352,
18,
3225,
199,
504,
6055,
14,
825,
18,
14,
1457,
1782,
4745,
492,
8651,
2510,
804,
12,
8651,
2510,
7674,
199,
199,
504,
2295,
14,
5819,
492,
8773,
199,
504,
2295,
14,
3248,
492,
10168,
3346,
3167,
1746,
421,
199,
533,
8651,
2510,
804,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
275,
8651,
2510,
804,
342,
339,
347,
1104,
63,
9099,
63,
3215,
63,
1989,
63,
1235,
287,
63,
409,
8,
277,
12,
536,
12,
574,
12,
2225,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
8,
354,
12,
574,
12,
488,
9,
267,
291,
14,
629,
8,
5675,
8,
277,
14,
1457,
63,
1782,
63,
466,
12,
2225,
395,
574,
9,
339,
347,
511,
63,
31290,
63,
2193,
63,
4525,
63,
2987,
63,
1045,
63,
1459,
8,
277,
304,
267,
367,
2368,
315,
10003,
2405,
1304,
401,
413,
12,
298,
2405,
63,
344,
1288,
2079,
1689,
2065,
985,
401,
298,
3972,
536,
401,
298,
19562,
63,
354,
1288,
2079,
1689,
4753,
1304,
401,
413,
12,
298,
4753,
63,
344,
1288,
2079,
1689,
2405,
2320,
401,
413,
12,
298,
890,
1288,
2079,
1689,
1205,
401,
298,
3972,
2004,
401,
298,
1205,
1288,
2079,
1689,
5040,
1366,
401,
413,
12,
298,
5040,
63,
521,
1288,
2079,
1689,
10297,
3883,
401,
298,
10297,
3883,
401,
298,
10297,
3883,
531,
2189,
288,
291,
14,
1074,
63,
9099,
63,
3215,
63,
1989,
63,
1235,
287,
63,
409,
8,
4958,
59,
16,
467,
2368,
59,
17,
467,
2368,
59,
18,
566,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1944,
2510,
63,
585,
63,
2052,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1944,
2510,
401,
283,
2052,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
889,
63,
1782,
12,
715,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1944,
2510,
63,
585,
63,
1848,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1944,
2510,
401,
283,
10297,
587,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
889,
63,
1782,
12,
756,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1807,
3314,
12154,
425,
63,
585,
63,
2052,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1807,
3314,
12154,
425,
401,
298,
2052,
401,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
1807,
63,
265,
63,
20667,
12,
715,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1807,
3314,
12154,
425,
63,
585,
63,
1848,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1807,
3314,
12154,
425,
401,
283,
10297,
587,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
1807,
63,
265,
63,
20667,
12,
756,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
15078,
63,
585,
63,
2052,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1327,
8274,
401,
298,
2052,
401,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
15078,
12,
715,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1327,
8274,
63,
585,
63,
1848,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1327,
8274,
401,
283,
10297,
587,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
15078,
12,
756,
9,
421,
199,
533,
8651,
2510,
7674,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
4745,
275,
8651,
2510,
7674,
342,
339,
347,
1853,
63,
1782,
63,
466,
63,
4077,
8,
277,
12,
330,
17,
12,
330,
18,
304,
267,
340,
1228,
8,
66,
17,
12,
8651,
2510,
804,
9,
436,
1228,
8,
66,
18,
12,
8651,
2510,
804,
304,
288,
372,
1006,
779,
66,
17,
14,
2105,
508,
330,
18,
14,
2105,
12,
717,
330,
17,
14,
19562,
63,
354,
508,
330,
18,
14,
19562,
63,
354,
12,
717,
330,
17,
14,
889,
63,
1782,
508,
330,
18,
14,
889,
63,
1782,
12,
717,
330,
17,
14,
2405,
63,
344,
508,
330,
18,
14,
2405,
63,
344,
12,
717,
330,
17,
14,
4753,
63,
344,
508,
330,
18,
14,
4753,
63,
344,
12,
717,
330,
17,
14,
1205,
508,
330,
18,
14,
1205,
12,
717,
330,
17,
14,
5040,
63,
521,
508,
330,
18,
14,
5040,
63,
521,
12,
717,
330,
17,
14,
1807,
63,
265,
63,
20667,
508,
330,
18,
14,
1807,
63,
265,
63,
20667,
12,
717,
330,
17,
14,
890,
508,
330,
18,
14,
890,
12,
717,
330,
17,
14,
15078,
508,
330,
18,
14,
15078,
566,
339,
347,
511,
63,
30398,
63,
1045,
63,
354,
63,
69,
1533,
63,
2193,
63,
460,
63,
5808,
63,
1818,
63,
585,
8,
277,
304,
267,
9151,
275,
291,
14,
1457,
63,
1782,
63,
4745,
14,
30398,
480,
69,
1533,
401,
488,
12,
488,
9,
267,
702,
291,
14,
1457,
63,
1782,
63,
466,
63,
4077,
8,
18476,
12,
8651,
2510,
804,
8,
277,
14,
1457,
63,
1782,
63,
4745,
430,
339,
347,
511,
63,
30398,
63,
1045,
63,
354,
63,
2065,
985,
63,
2193,
63,
460,
63,
5808,
63,
1818,
63,
585,
8,
277,
304,
267,
9151,
275,
291,
14,
1457,
63,
1782,
63,
4745,
14,
30398,
480,
2065,
985,
401,
488,
12,
488,
9,
267,
702,
291,
14,
1457,
63,
1782,
63,
466,
63,
4077,
8,
18476,
12,
8651,
2510,
804,
8,
277,
14,
1457,
63,
1782,
63,
4745,
430,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1782,
63,
2193,
63,
1818,
63,
354,
63,
2374,
63,
2307,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
4745,
14,
31290,
480,
1782,
401,
3286,
2374,
15
] |
[
2295,
14,
5819,
492,
2882,
199,
199,
504,
6055,
14,
825,
18,
14,
2105,
492,
15352,
18,
3225,
199,
504,
6055,
14,
825,
18,
14,
1457,
1782,
4745,
492,
8651,
2510,
804,
12,
8651,
2510,
7674,
199,
199,
504,
2295,
14,
5819,
492,
8773,
199,
504,
2295,
14,
3248,
492,
10168,
3346,
3167,
1746,
421,
199,
533,
8651,
2510,
804,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
275,
8651,
2510,
804,
342,
339,
347,
1104,
63,
9099,
63,
3215,
63,
1989,
63,
1235,
287,
63,
409,
8,
277,
12,
536,
12,
574,
12,
2225,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
8,
354,
12,
574,
12,
488,
9,
267,
291,
14,
629,
8,
5675,
8,
277,
14,
1457,
63,
1782,
63,
466,
12,
2225,
395,
574,
9,
339,
347,
511,
63,
31290,
63,
2193,
63,
4525,
63,
2987,
63,
1045,
63,
1459,
8,
277,
304,
267,
367,
2368,
315,
10003,
2405,
1304,
401,
413,
12,
298,
2405,
63,
344,
1288,
2079,
1689,
2065,
985,
401,
298,
3972,
536,
401,
298,
19562,
63,
354,
1288,
2079,
1689,
4753,
1304,
401,
413,
12,
298,
4753,
63,
344,
1288,
2079,
1689,
2405,
2320,
401,
413,
12,
298,
890,
1288,
2079,
1689,
1205,
401,
298,
3972,
2004,
401,
298,
1205,
1288,
2079,
1689,
5040,
1366,
401,
413,
12,
298,
5040,
63,
521,
1288,
2079,
1689,
10297,
3883,
401,
298,
10297,
3883,
401,
298,
10297,
3883,
531,
2189,
288,
291,
14,
1074,
63,
9099,
63,
3215,
63,
1989,
63,
1235,
287,
63,
409,
8,
4958,
59,
16,
467,
2368,
59,
17,
467,
2368,
59,
18,
566,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1944,
2510,
63,
585,
63,
2052,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1944,
2510,
401,
283,
2052,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
889,
63,
1782,
12,
715,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1944,
2510,
63,
585,
63,
1848,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1944,
2510,
401,
283,
10297,
587,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
889,
63,
1782,
12,
756,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1807,
3314,
12154,
425,
63,
585,
63,
2052,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1807,
3314,
12154,
425,
401,
298,
2052,
401,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
1807,
63,
265,
63,
20667,
12,
715,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1807,
3314,
12154,
425,
63,
585,
63,
1848,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1807,
3314,
12154,
425,
401,
283,
10297,
587,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
1807,
63,
265,
63,
20667,
12,
756,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
15078,
63,
585,
63,
2052,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1327,
8274,
401,
298,
2052,
401,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
15078,
12,
715,
9,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1327,
8274,
63,
585,
63,
1848,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
466,
14,
31290,
480,
1327,
8274,
401,
283,
10297,
587,
297,
488,
9,
267,
291,
14,
629,
8,
277,
14,
1457,
63,
1782,
63,
466,
14,
15078,
12,
756,
9,
421,
199,
533,
8651,
2510,
7674,
2925,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
4745,
275,
8651,
2510,
7674,
342,
339,
347,
1853,
63,
1782,
63,
466,
63,
4077,
8,
277,
12,
330,
17,
12,
330,
18,
304,
267,
340,
1228,
8,
66,
17,
12,
8651,
2510,
804,
9,
436,
1228,
8,
66,
18,
12,
8651,
2510,
804,
304,
288,
372,
1006,
779,
66,
17,
14,
2105,
508,
330,
18,
14,
2105,
12,
717,
330,
17,
14,
19562,
63,
354,
508,
330,
18,
14,
19562,
63,
354,
12,
717,
330,
17,
14,
889,
63,
1782,
508,
330,
18,
14,
889,
63,
1782,
12,
717,
330,
17,
14,
2405,
63,
344,
508,
330,
18,
14,
2405,
63,
344,
12,
717,
330,
17,
14,
4753,
63,
344,
508,
330,
18,
14,
4753,
63,
344,
12,
717,
330,
17,
14,
1205,
508,
330,
18,
14,
1205,
12,
717,
330,
17,
14,
5040,
63,
521,
508,
330,
18,
14,
5040,
63,
521,
12,
717,
330,
17,
14,
1807,
63,
265,
63,
20667,
508,
330,
18,
14,
1807,
63,
265,
63,
20667,
12,
717,
330,
17,
14,
890,
508,
330,
18,
14,
890,
12,
717,
330,
17,
14,
15078,
508,
330,
18,
14,
15078,
566,
339,
347,
511,
63,
30398,
63,
1045,
63,
354,
63,
69,
1533,
63,
2193,
63,
460,
63,
5808,
63,
1818,
63,
585,
8,
277,
304,
267,
9151,
275,
291,
14,
1457,
63,
1782,
63,
4745,
14,
30398,
480,
69,
1533,
401,
488,
12,
488,
9,
267,
702,
291,
14,
1457,
63,
1782,
63,
466,
63,
4077,
8,
18476,
12,
8651,
2510,
804,
8,
277,
14,
1457,
63,
1782,
63,
4745,
430,
339,
347,
511,
63,
30398,
63,
1045,
63,
354,
63,
2065,
985,
63,
2193,
63,
460,
63,
5808,
63,
1818,
63,
585,
8,
277,
304,
267,
9151,
275,
291,
14,
1457,
63,
1782,
63,
4745,
14,
30398,
480,
2065,
985,
401,
488,
12,
488,
9,
267,
702,
291,
14,
1457,
63,
1782,
63,
466,
63,
4077,
8,
18476,
12,
8651,
2510,
804,
8,
277,
14,
1457,
63,
1782,
63,
4745,
430,
339,
347,
511,
63,
31290,
63,
1045,
63,
354,
63,
1782,
63,
2193,
63,
1818,
63,
354,
63,
2374,
63,
2307,
8,
277,
304,
267,
291,
14,
1457,
63,
1782,
63,
4745,
14,
31290,
480,
1782,
401,
3286,
2374,
15,
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
] |
biolab/orange3-imageanalytics
|
orangecontrib/imageanalytics/tests/test_image_grid.py
|
1
|
1102
|
import logging
import unittest
from Orange.data import Table
from orangecontrib.imageanalytics.image_grid import ImageGrid
class ImageGridTest(unittest.TestCase):
def setUp(self):
logging.disable(logging.CRITICAL)
self.grid = ImageGrid(Table("iris"))
def tearDown(self):
logging.disable(logging.NOTSET)
def test_init(self):
s = self.grid.norm_data.shape
self.assertTrue(s[0] > 0 and s[1] == 2)
self.assertTrue(all(map(lambda x: 0 <= x[0] <= 1 and 0 <= x[1] <= 1, self.grid.norm_data)))
def check_process(self):
self.assertTrue(self.grid.size_x * self.grid.size_y >= len(self.grid.data))
self.assertTrue(all([len(self.grid.grid_indices), len(self.grid.assignments)]))
self.assertTrue(all([d in self.grid.image_list for d in self.grid.data]))
def test_process1(self):
self.grid.process()
self.check_process()
def test_process2(self):
with self.assertRaises(AssertionError):
self.grid.process(2, 3)
self.grid.process(20, 20)
self.check_process()
|
gpl-3.0
|
[
646,
2050,
199,
646,
2882,
199,
199,
504,
593,
1842,
14,
576,
492,
6957,
199,
199,
504,
29713,
2828,
14,
1569,
20211,
14,
1569,
63,
3825,
492,
6047,
7900,
421,
199,
533,
6047,
7900,
774,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
2050,
14,
5993,
8,
4806,
14,
21539,
9,
267,
291,
14,
3825,
275,
6047,
7900,
8,
3186,
480,
11885,
2237,
339,
347,
6766,
8,
277,
304,
267,
2050,
14,
5993,
8,
4806,
14,
4609,
3597,
9,
339,
347,
511,
63,
826,
8,
277,
304,
267,
308,
275,
291,
14,
3825,
14,
4791,
63,
576,
14,
1392,
267,
291,
14,
1815,
8,
83,
59,
16,
61,
690,
378,
436,
308,
59,
17,
61,
508,
499,
9,
267,
291,
14,
1815,
8,
452,
8,
1130,
8,
2734,
671,
26,
378,
2695,
671,
59,
16,
61,
2695,
413,
436,
378,
2695,
671,
59,
17,
61,
2695,
413,
12,
291,
14,
3825,
14,
4791,
63,
576,
1724,
339,
347,
1104,
63,
1412,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
3825,
14,
890,
63,
88,
627,
291,
14,
3825,
14,
890,
63,
89,
2356,
822,
8,
277,
14,
3825,
14,
576,
430,
267,
291,
14,
1815,
8,
452,
779,
552,
8,
277,
14,
3825,
14,
3825,
63,
4108,
395,
822,
8,
277,
14,
3825,
14,
18922,
19563,
267,
291,
14,
1815,
8,
452,
779,
68,
315,
291,
14,
3825,
14,
1569,
63,
513,
367,
366,
315,
291,
14,
3825,
14,
576,
2459,
339,
347,
511,
63,
1412,
17,
8,
277,
304,
267,
291,
14,
3825,
14,
1412,
342,
267,
291,
14,
1074,
63,
1412,
342,
339,
347,
511,
63,
1412,
18,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
14844,
304,
288,
291,
14,
3825,
14,
1412,
8,
18,
12,
650,
9,
398,
291,
14,
3825,
14,
1412,
8,
1165,
12,
3388,
9,
267,
291,
14,
1074,
63,
1412,
342,
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
] |
[
2050,
199,
646,
2882,
199,
199,
504,
593,
1842,
14,
576,
492,
6957,
199,
199,
504,
29713,
2828,
14,
1569,
20211,
14,
1569,
63,
3825,
492,
6047,
7900,
421,
199,
533,
6047,
7900,
774,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
2050,
14,
5993,
8,
4806,
14,
21539,
9,
267,
291,
14,
3825,
275,
6047,
7900,
8,
3186,
480,
11885,
2237,
339,
347,
6766,
8,
277,
304,
267,
2050,
14,
5993,
8,
4806,
14,
4609,
3597,
9,
339,
347,
511,
63,
826,
8,
277,
304,
267,
308,
275,
291,
14,
3825,
14,
4791,
63,
576,
14,
1392,
267,
291,
14,
1815,
8,
83,
59,
16,
61,
690,
378,
436,
308,
59,
17,
61,
508,
499,
9,
267,
291,
14,
1815,
8,
452,
8,
1130,
8,
2734,
671,
26,
378,
2695,
671,
59,
16,
61,
2695,
413,
436,
378,
2695,
671,
59,
17,
61,
2695,
413,
12,
291,
14,
3825,
14,
4791,
63,
576,
1724,
339,
347,
1104,
63,
1412,
8,
277,
304,
267,
291,
14,
1815,
8,
277,
14,
3825,
14,
890,
63,
88,
627,
291,
14,
3825,
14,
890,
63,
89,
2356,
822,
8,
277,
14,
3825,
14,
576,
430,
267,
291,
14,
1815,
8,
452,
779,
552,
8,
277,
14,
3825,
14,
3825,
63,
4108,
395,
822,
8,
277,
14,
3825,
14,
18922,
19563,
267,
291,
14,
1815,
8,
452,
779,
68,
315,
291,
14,
3825,
14,
1569,
63,
513,
367,
366,
315,
291,
14,
3825,
14,
576,
2459,
339,
347,
511,
63,
1412,
17,
8,
277,
304,
267,
291,
14,
3825,
14,
1412,
342,
267,
291,
14,
1074,
63,
1412,
342,
339,
347,
511,
63,
1412,
18,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
14844,
304,
288,
291,
14,
3825,
14,
1412,
8,
18,
12,
650,
9,
398,
291,
14,
3825,
14,
1412,
8,
1165,
12,
3388,
9,
267,
291,
14,
1074,
63,
1412,
342,
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,
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,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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
] |
ElementsProject/elements
|
test/functional/mempool_packages.py
|
1
|
17298
|
#!/usr/bin/env python3
# Copyright (c) 2014-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test descendant package tracking code."""
from decimal import Decimal
from test_framework.messages import COIN
from test_framework.p2p import P2PTxInvStore
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_greater_than,
assert_raises_rpc_error,
satoshi_round,
)
import time
# default limits
MAX_ANCESTORS = 25
MAX_DESCENDANTS = 25
# custom limits for node1
MAX_ANCESTORS_CUSTOM = 5
MAX_DESCENDANTS_CUSTOM = 10
assert MAX_DESCENDANTS_CUSTOM >= MAX_ANCESTORS_CUSTOM
class MempoolPackagesTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [
[
"-maxorphantx=1000",
"-whitelist=noban@127.0.0.1", # immediate tx relay
],
[
"-maxorphantx=1000",
"-limitancestorcount={}".format(MAX_ANCESTORS_CUSTOM),
"-limitdescendantcount={}".format(MAX_DESCENDANTS_CUSTOM),
],
]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
# Build a transaction that spends parent_txid:vout
# Return amount sent
def chain_transaction(self, node, parent_txid, vout, value, fee, num_outputs):
send_value = satoshi_round((value - fee)/num_outputs)
inputs = [ {'txid' : parent_txid, 'vout' : vout} ]
outputs = []
for _ in range(num_outputs):
outputs.append({node.getnewaddress(): send_value})
outputs.append({"fee": value - (num_outputs * send_value)})
rawtx = node.createrawtransaction(inputs, outputs)
signedtx = node.signrawtransactionwithwallet(rawtx)
txid = node.sendrawtransaction(signedtx['hex'])
fulltx = node.getrawtransaction(txid, 1)
assert len(fulltx['vout']) == num_outputs + 1 # make sure we didn't generate a change output
return (txid, send_value)
def run_test(self):
# Create transaction with 3-second block delay, should fail to enter the template
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
block = self.nodes[0].getnewblockhex(min_tx_age=3)
self.nodes[0].submitblock(block)
assert txid in self.nodes[0].getrawmempool()
time.sleep(3)
block = self.nodes[0].getnewblockhex(min_tx_age=3)
self.nodes[0].submitblock(block)
assert txid not in self.nodes[0].getrawmempool()
# Once more with no delay (default is 0, just testing default arg)
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
block = self.nodes[0].getnewblockhex(min_tx_age=0)
self.nodes[0].submitblock(block)
assert txid not in self.nodes[0].getrawmempool()
assert_raises_rpc_error(-8, "min_tx_age must be non-negative.", self.nodes[0].getnewblockhex, -1)
# Mine some blocks and have them mature.
peer_inv_store = self.nodes[0].add_p2p_connection(P2PTxInvStore()) # keep track of invs
self.nodes[0].generate(101)
utxos = []
for utxo in self.nodes[0].listunspent(10):
# Skip change/fees we scooped up
if utxo['amount'] != Decimal(50):
continue
utxos.append(utxo)
assert_greater_than(len(utxos), 1)
txid = utxos[0]['txid']
vout = utxos[0]['vout']
value = utxos[0]['amount']
fee = Decimal("0.0001")
# MAX_ANCESTORS transactions off a confirmed tx should be fine
chain = []
witness_chain = []
for _ in range(MAX_ANCESTORS):
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, 0, value, fee, 1)
value = sent_value
chain.append(txid)
# We need the wtxids to check P2P announcements
fulltx = self.nodes[0].getrawtransaction(txid)
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
witness_chain.append(witnesstx['hash'])
# Wait until mempool transactions have passed initial broadcast (sent inv and received getdata)
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if unbroadcast changes in between
peer_inv_store.wait_for_broadcast(witness_chain)
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
# count and fees should look correct
mempool = self.nodes[0].getrawmempool(True)
assert_equal(len(mempool), MAX_ANCESTORS)
descendant_count = 1
descendant_fees = 0
descendant_vsize = 0
ancestor_vsize = sum([mempool[tx]['vsize'] for tx in mempool])
ancestor_count = MAX_ANCESTORS
ancestor_fees = sum([mempool[tx]['fee'] for tx in mempool])
descendants = []
ancestors = list(chain)
for x in reversed(chain):
# Check that getmempoolentry is consistent with getrawmempool
entry = self.nodes[0].getmempoolentry(x)
assert_equal(entry, mempool[x])
# Check that the descendant calculations are correct
assert_equal(mempool[x]['descendantcount'], descendant_count)
descendant_fees += mempool[x]['fee']
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee'])
assert_equal(mempool[x]['fees']['base'], mempool[x]['fee'])
assert_equal(mempool[x]['fees']['modified'], mempool[x]['modifiedfee'])
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN)
assert_equal(mempool[x]['fees']['descendant'], descendant_fees)
descendant_vsize += mempool[x]['vsize']
assert_equal(mempool[x]['descendantsize'], descendant_vsize)
descendant_count += 1
# Check that ancestor calculations are correct
assert_equal(mempool[x]['ancestorcount'], ancestor_count)
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN)
assert_equal(mempool[x]['ancestorsize'], ancestor_vsize)
ancestor_vsize -= mempool[x]['vsize']
ancestor_fees -= mempool[x]['fee']
ancestor_count -= 1
# Check that parent/child list is correct
assert_equal(mempool[x]['spentby'], descendants[-1:])
assert_equal(mempool[x]['depends'], ancestors[-2:-1])
# Check that getmempooldescendants is correct
assert_equal(sorted(descendants), sorted(self.nodes[0].getmempooldescendants(x)))
# Check getmempooldescendants verbose output is correct
for descendant, dinfo in self.nodes[0].getmempooldescendants(x, True).items():
assert_equal(dinfo['depends'], [chain[chain.index(descendant)-1]])
if dinfo['descendantcount'] > 1:
assert_equal(dinfo['spentby'], [chain[chain.index(descendant)+1]])
else:
assert_equal(dinfo['spentby'], [])
descendants.append(x)
# Check that getmempoolancestors is correct
ancestors.remove(x)
assert_equal(sorted(ancestors), sorted(self.nodes[0].getmempoolancestors(x)))
# Check that getmempoolancestors verbose output is correct
for ancestor, ainfo in self.nodes[0].getmempoolancestors(x, True).items():
assert_equal(ainfo['spentby'], [chain[chain.index(ancestor)+1]])
if ainfo['ancestorcount'] > 1:
assert_equal(ainfo['depends'], [chain[chain.index(ancestor)-1]])
else:
assert_equal(ainfo['depends'], [])
# Check that getmempoolancestors/getmempooldescendants correctly handle verbose=true
v_ancestors = self.nodes[0].getmempoolancestors(chain[-1], True)
assert_equal(len(v_ancestors), len(chain)-1)
for x in v_ancestors.keys():
assert_equal(mempool[x], v_ancestors[x])
assert chain[-1] not in v_ancestors.keys()
v_descendants = self.nodes[0].getmempooldescendants(chain[0], True)
assert_equal(len(v_descendants), len(chain)-1)
for x in v_descendants.keys():
assert_equal(mempool[x], v_descendants[x])
assert chain[0] not in v_descendants.keys()
# Check that ancestor modified fees includes fee deltas from
# prioritisetransaction
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=1000)
mempool = self.nodes[0].getrawmempool(True)
ancestor_fees = 0
for x in chain:
ancestor_fees += mempool[x]['fee']
assert_equal(mempool[x]['fees']['ancestor'], ancestor_fees + Decimal('0.00001'))
assert_equal(mempool[x]['ancestorfees'], ancestor_fees * COIN + 1000)
# Undo the prioritisetransaction for later tests
self.nodes[0].prioritisetransaction(txid=chain[0], fee_delta=-1000)
# Check that descendant modified fees includes fee deltas from
# prioritisetransaction
self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=1000)
mempool = self.nodes[0].getrawmempool(True)
descendant_fees = 0
for x in reversed(chain):
descendant_fees += mempool[x]['fee']
assert_equal(mempool[x]['fees']['descendant'], descendant_fees + Decimal('0.00001'))
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 1000)
# Adding one more transaction on to the chain should fail.
assert_raises_rpc_error(-26, "too-long-mempool-chain", self.chain_transaction, self.nodes[0], txid, vout, value, fee, 1)
# Check that prioritising a tx before it's added to the mempool works
# First clear the mempool by mining a block.
self.nodes[0].generate(1)
self.sync_blocks()
assert_equal(len(self.nodes[0].getrawmempool()), 0)
# Prioritise a transaction that has been mined, then add it back to the
# mempool by using invalidateblock.
self.nodes[0].prioritisetransaction(txid=chain[-1], fee_delta=2000)
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# Keep node1's tip synced with node0
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
# Now check that the transaction is in the mempool, with the right modified fee
mempool = self.nodes[0].getrawmempool(True)
descendant_fees = 0
for x in reversed(chain):
descendant_fees += mempool[x]['fee']
if (x == chain[-1]):
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['fees']['modified'], mempool[x]['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 2000)
assert_equal(mempool[x]['fees']['descendant'], descendant_fees+satoshi_round(0.00002))
# Check that node1's mempool is as expected (-> custom ancestor limit)
mempool0 = self.nodes[0].getrawmempool(False)
mempool1 = self.nodes[1].getrawmempool(False)
assert_equal(len(mempool1), MAX_ANCESTORS_CUSTOM)
assert set(mempool1).issubset(set(mempool0))
for tx in chain[:MAX_ANCESTORS_CUSTOM]:
assert tx in mempool1
# TODO: more detailed check of node1's mempool (fees etc.)
# check transaction unbroadcast info (should be false if in both mempools)
mempool = self.nodes[0].getrawmempool(True)
for tx in mempool:
assert_equal(mempool[tx]['unbroadcast'], False)
# TODO: test ancestor size limits
# Now test descendant chain limits
txid = utxos[1]['txid']
value = utxos[1]['amount']
vout = utxos[1]['vout']
transaction_package = []
tx_children = []
# First create one parent tx with 10 children
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, vout, value, fee, 10)
parent_transaction = txid
for i in range(10):
transaction_package.append({'txid': txid, 'vout': i, 'amount': sent_value})
# Sign and send up to MAX_DESCENDANT transactions chained off the parent tx
chain = [] # save sent txs for the purpose of checking node1's mempool later (see below)
for _ in range(MAX_DESCENDANTS - 1):
utxo = transaction_package.pop(0)
(txid, sent_value) = self.chain_transaction(self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
chain.append(txid)
if utxo['txid'] is parent_transaction:
tx_children.append(txid)
for j in range(10):
transaction_package.append({'txid': txid, 'vout': j, 'amount': sent_value})
mempool = self.nodes[0].getrawmempool(True)
assert_equal(mempool[parent_transaction]['descendantcount'], MAX_DESCENDANTS)
assert_equal(sorted(mempool[parent_transaction]['spentby']), sorted(tx_children))
for child in tx_children:
assert_equal(mempool[child]['depends'], [parent_transaction])
# Sending one more chained transaction will fail
utxo = transaction_package.pop(0)
assert_raises_rpc_error(-26, "too-long-mempool-chain", self.chain_transaction, self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
# Check that node1's mempool is as expected, containing:
# - txs from previous ancestor test (-> custom ancestor limit)
# - parent tx for descendant test
# - txs chained off parent tx (-> custom descendant limit)
self.wait_until(lambda: len(self.nodes[1].getrawmempool(False)) ==
MAX_ANCESTORS_CUSTOM + 1 + MAX_DESCENDANTS_CUSTOM, timeout=10)
mempool0 = self.nodes[0].getrawmempool(False)
mempool1 = self.nodes[1].getrawmempool(False)
assert set(mempool1).issubset(set(mempool0))
assert parent_transaction in mempool1
for tx in chain[:MAX_DESCENDANTS_CUSTOM]:
assert tx in mempool1
for tx in chain[MAX_DESCENDANTS_CUSTOM:]:
assert tx not in mempool1
# TODO: more detailed check of node1's mempool (fees etc.)
# TODO: test descendant size limits
# Test reorg handling
# First, the basics:
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash())
self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash())
# Now test the case where node1 has a transaction T in its mempool that
# depends on transactions A and B which are in a mined block, and the
# block containing A and B is disconnected, AND B is not accepted back
# into node1's mempool because its ancestor count is too high.
# Create 8 transactions, like so:
# Tx0 -> Tx1 (vout0)
# \--> Tx2 (vout1) -> Tx3 -> Tx4 -> Tx5 -> Tx6 -> Tx7
#
# Mine them in the next block, then generate a new tx8 that spends
# Tx1 and Tx7, and add to node1's mempool, then disconnect the
# last block.
# Create tx0 with 2 outputs
utxo = self.nodes[0].listunspent()
txid = utxo[0]['txid']
value = utxo[0]['amount']
vout = utxo[0]['vout']
send_value = satoshi_round((value - fee)/2)
inputs = [ {'txid' : txid, 'vout' : vout} ]
outputs = []
for _ in range(2):
outputs.append({self.nodes[0].getnewaddress():send_value})
outputs.append({"fee": fee})
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
tx0_id = txid
value = send_value
# Create tx1
tx1_id, _ = self.chain_transaction(self.nodes[0], tx0_id, 0, value, fee, 1)
# Create tx2-7
vout = 1
txid = tx0_id
for _ in range(6):
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, vout, value, fee, 1)
vout = 0
value = sent_value
# Mine these in a block
self.nodes[0].generate(1)
self.sync_all()
# Now generate tx8, with a big fee
inputs = [ {'txid' : tx1_id, 'vout': 0}, {'txid' : txid, 'vout': 0} ]
outputs = [{ self.nodes[0].getnewaddress() : send_value + value - 4*fee }, {"fee": 3*fee}]
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
self.sync_mempools()
# Now try to disconnect the tip on each node...
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
self.sync_blocks()
if __name__ == '__main__':
MempoolPackagesTest().main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6927,
13,
14982,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
27509,
2559,
15161,
1233,
1041,
199,
199,
504,
6107,
492,
6345,
199,
199,
504,
511,
63,
4857,
14,
3431,
492,
5099,
568,
199,
504,
511,
63,
4857,
14,
80,
18,
80,
492,
510,
18,
4189,
88,
14883,
5502,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
272,
702,
63,
13154,
63,
13797,
12,
272,
702,
63,
3536,
63,
4354,
63,
705,
12,
272,
308,
11318,
19377,
63,
2363,
12,
199,
9,
199,
646,
900,
199,
199,
3,
849,
10976,
199,
4283,
63,
879,
35,
1719,
4149,
275,
5661,
199,
4283,
63,
15119,
3902,
1441,
51,
275,
5661,
199,
199,
3,
3537,
10976,
367,
1031,
17,
199,
4283,
63,
879,
35,
1719,
4149,
63,
20519,
275,
959,
199,
4283,
63,
15119,
3902,
1441,
51,
63,
20519,
275,
1616,
199,
479,
9141,
63,
15119,
3902,
1441,
51,
63,
20519,
2356,
9141,
63,
879,
35,
1719,
4149,
63,
20519,
199,
199,
533,
603,
2109,
21943,
25135,
774,
8,
4734,
9061,
26203,
304,
272,
347,
663,
63,
396,
63,
1162,
8,
277,
304,
267,
291,
14,
1507,
63,
2415,
275,
499,
267,
291,
14,
2911,
63,
589,
275,
359,
288,
359,
355,
3905,
988,
6847,
867,
88,
29,
5279,
401,
355,
3905,
14189,
29,
889,
13206,
32,
4195,
14,
16,
14,
16,
14,
17,
401,
221,
327,
8569,
4773,
25931,
288,
2156,
288,
359,
355,
3905,
988,
6847,
867,
88,
29,
5279,
401,
355,
3905,
3097,
20745,
835,
7622,
1674,
908,
8,
4283,
63,
879,
35,
1719,
4149,
63,
20519,
395,
355,
3905,
3097,
31759,
835,
7622,
1674,
908,
8,
4283,
63,
15119,
3902,
1441,
51,
63,
20519,
395,
288,
2156,
267,
1622,
339,
347,
3372,
63,
396,
63,
692,
63,
4752,
63,
578,
8,
277,
304,
267,
291,
14,
2759,
63,
692,
63,
889,
63,
13892,
342,
339,
327,
6516,
282,
6008,
626,
2249,
3198,
1676,
63,
14113,
26,
17853,
272,
327,
1432,
5982,
4847,
272,
347,
6036,
63,
5945,
8,
277,
12,
1031,
12,
1676,
63,
14113,
12,
373,
548,
12,
574,
12,
14751,
12,
1967,
63,
4467,
304,
267,
3222,
63,
585,
275,
308,
11318,
19377,
63,
2363,
1332,
585,
446,
14751,
2447,
1507,
63,
4467,
9,
267,
4153,
275,
359,
791,
14113,
7,
520,
1676,
63,
14113,
12,
283,
17853,
7,
520,
373,
548,
93,
1622,
267,
4704,
275,
942,
267,
367,
485,
315,
1425,
8,
1507,
63,
4467,
304,
288,
4704,
14,
740,
2561,
932,
14,
21102,
837,
3222,
63,
585,
1552,
267,
4704,
14,
740,
6333,
11195,
582,
574,
446,
334,
1507,
63,
4467,
627,
3222,
63,
585,
11466,
267,
3066,
2347,
275,
1031,
14,
981,
16900,
8,
3711,
12,
4704,
9,
267,
10514,
2347,
275,
1031,
14,
1037,
16900,
1045,
13892,
8,
1773,
2347,
9,
267,
22083,
275,
1031,
14,
2254,
16900,
8,
1737,
2347,
459,
4097,
1105,
267,
2615,
2347,
275,
1031,
14,
362,
16900,
8,
14113,
12,
413,
9,
267,
702,
822,
8,
2861,
2347,
459,
17853,
1105,
508,
1967,
63,
4467,
435,
413,
221,
327,
1852,
3238,
781,
9980,
1133,
3550,
282,
1570,
1072,
267,
372,
334,
14113,
12,
3222,
63,
585,
9,
339,
347,
1255,
63,
396,
8,
277,
304,
398,
327,
2790,
6008,
543,
650,
13,
4375,
1853,
7339,
12,
1077,
2449,
370,
9509,
314,
1978,
267,
22083,
275,
291,
14,
2415,
59,
16,
1055,
23267,
1562,
8,
277,
14,
2415,
59,
16,
1055,
21102,
1062,
413,
9,
267,
1853,
275,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
8,
827,
63,
2347,
63,
474,
29,
19,
9,
267,
291,
14,
2415,
59,
16,
1055,
7275,
1457,
8,
1457,
9,
267,
702,
22083,
315,
291,
14,
2415,
59,
16,
1055,
362,
1773,
25341,
342,
267,
900,
14,
4532,
8,
19,
9,
267,
1853,
275,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
8,
827,
63,
2347,
63,
474,
29,
19,
9,
267,
291,
14,
2415,
59,
16,
1055,
7275,
1457,
8,
1457,
9,
267,
702,
22083,
440,
315,
291,
14,
2415,
59,
16,
1055,
362,
1773,
25341,
342,
267,
327,
19468,
1655,
543,
949,
7339,
334,
885,
365,
378,
12,
2951,
5343,
849,
1680,
9,
267,
22083,
275,
291,
14,
2415,
59,
16,
1055,
23267,
1562,
8,
277,
14,
2415,
59,
16,
1055,
21102,
1062,
413,
9,
267,
1853,
275,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
8,
827,
63,
2347,
63,
474,
29,
16,
9,
267,
291,
14,
2415,
59,
16,
1055,
7275,
1457,
8,
1457,
9,
267,
702,
22083,
440,
315,
291,
14,
2415,
59,
16,
1055,
362,
1773,
25341,
342,
267,
702,
63,
3536,
63,
4354,
63,
705,
2801,
24,
12,
298,
827,
63,
2347,
63,
474,
1471,
506,
2222,
13,
7371,
4765,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
12,
446,
17,
9,
398,
327,
603,
1132,
2005,
5664,
436,
1172,
3062,
333,
1463,
14,
267,
9104,
63,
5350,
63,
1617,
275,
291,
14,
2415,
59,
16,
1055,
525,
63,
80,
18,
80,
63,
2105,
8,
48,
18,
4189,
88,
14883,
5502,
1012,
327,
4215,
4426,
402,
315,
3122,
267,
291,
14,
2415,
59,
16,
1055,
4208,
8,
4893,
9,
267,
11430,
22101,
275,
942,
267,
367,
11430,
15987,
315,
291,
14,
2415,
59,
16,
1055,
513,
324,
19435,
8,
709,
304,
288,
327,
8232,
1570,
15,
771,
397,
781,
308,
22684,
1915,
1536,
288,
340,
11430,
15987,
459,
4606,
418,
1137,
6345,
8,
1400,
304,
355,
1980,
288,
11430,
22101,
14,
740,
8,
30275,
9,
267,
702,
63,
13154,
63,
13797,
8,
552,
8,
337,
22101,
395,
413,
9,
398,
22083,
275,
11430,
22101,
59,
16,
2733,
14113,
418,
267,
373,
548,
275,
11430,
22101,
59,
16,
2733,
17853,
418,
267,
574,
275,
11430,
22101,
59,
16,
2733,
4606,
418,
398,
14751,
275,
6345,
480,
16,
14,
4183,
531,
267
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6927,
13,
14982,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
774,
27509,
2559,
15161,
1233,
1041,
199,
199,
504,
6107,
492,
6345,
199,
199,
504,
511,
63,
4857,
14,
3431,
492,
5099,
568,
199,
504,
511,
63,
4857,
14,
80,
18,
80,
492,
510,
18,
4189,
88,
14883,
5502,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
334,
272,
702,
63,
1452,
12,
272,
702,
63,
13154,
63,
13797,
12,
272,
702,
63,
3536,
63,
4354,
63,
705,
12,
272,
308,
11318,
19377,
63,
2363,
12,
199,
9,
199,
646,
900,
199,
199,
3,
849,
10976,
199,
4283,
63,
879,
35,
1719,
4149,
275,
5661,
199,
4283,
63,
15119,
3902,
1441,
51,
275,
5661,
199,
199,
3,
3537,
10976,
367,
1031,
17,
199,
4283,
63,
879,
35,
1719,
4149,
63,
20519,
275,
959,
199,
4283,
63,
15119,
3902,
1441,
51,
63,
20519,
275,
1616,
199,
479,
9141,
63,
15119,
3902,
1441,
51,
63,
20519,
2356,
9141,
63,
879,
35,
1719,
4149,
63,
20519,
199,
199,
533,
603,
2109,
21943,
25135,
774,
8,
4734,
9061,
26203,
304,
272,
347,
663,
63,
396,
63,
1162,
8,
277,
304,
267,
291,
14,
1507,
63,
2415,
275,
499,
267,
291,
14,
2911,
63,
589,
275,
359,
288,
359,
355,
3905,
988,
6847,
867,
88,
29,
5279,
401,
355,
3905,
14189,
29,
889,
13206,
32,
4195,
14,
16,
14,
16,
14,
17,
401,
221,
327,
8569,
4773,
25931,
288,
2156,
288,
359,
355,
3905,
988,
6847,
867,
88,
29,
5279,
401,
355,
3905,
3097,
20745,
835,
7622,
1674,
908,
8,
4283,
63,
879,
35,
1719,
4149,
63,
20519,
395,
355,
3905,
3097,
31759,
835,
7622,
1674,
908,
8,
4283,
63,
15119,
3902,
1441,
51,
63,
20519,
395,
288,
2156,
267,
1622,
339,
347,
3372,
63,
396,
63,
692,
63,
4752,
63,
578,
8,
277,
304,
267,
291,
14,
2759,
63,
692,
63,
889,
63,
13892,
342,
339,
327,
6516,
282,
6008,
626,
2249,
3198,
1676,
63,
14113,
26,
17853,
272,
327,
1432,
5982,
4847,
272,
347,
6036,
63,
5945,
8,
277,
12,
1031,
12,
1676,
63,
14113,
12,
373,
548,
12,
574,
12,
14751,
12,
1967,
63,
4467,
304,
267,
3222,
63,
585,
275,
308,
11318,
19377,
63,
2363,
1332,
585,
446,
14751,
2447,
1507,
63,
4467,
9,
267,
4153,
275,
359,
791,
14113,
7,
520,
1676,
63,
14113,
12,
283,
17853,
7,
520,
373,
548,
93,
1622,
267,
4704,
275,
942,
267,
367,
485,
315,
1425,
8,
1507,
63,
4467,
304,
288,
4704,
14,
740,
2561,
932,
14,
21102,
837,
3222,
63,
585,
1552,
267,
4704,
14,
740,
6333,
11195,
582,
574,
446,
334,
1507,
63,
4467,
627,
3222,
63,
585,
11466,
267,
3066,
2347,
275,
1031,
14,
981,
16900,
8,
3711,
12,
4704,
9,
267,
10514,
2347,
275,
1031,
14,
1037,
16900,
1045,
13892,
8,
1773,
2347,
9,
267,
22083,
275,
1031,
14,
2254,
16900,
8,
1737,
2347,
459,
4097,
1105,
267,
2615,
2347,
275,
1031,
14,
362,
16900,
8,
14113,
12,
413,
9,
267,
702,
822,
8,
2861,
2347,
459,
17853,
1105,
508,
1967,
63,
4467,
435,
413,
221,
327,
1852,
3238,
781,
9980,
1133,
3550,
282,
1570,
1072,
267,
372,
334,
14113,
12,
3222,
63,
585,
9,
339,
347,
1255,
63,
396,
8,
277,
304,
398,
327,
2790,
6008,
543,
650,
13,
4375,
1853,
7339,
12,
1077,
2449,
370,
9509,
314,
1978,
267,
22083,
275,
291,
14,
2415,
59,
16,
1055,
23267,
1562,
8,
277,
14,
2415,
59,
16,
1055,
21102,
1062,
413,
9,
267,
1853,
275,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
8,
827,
63,
2347,
63,
474,
29,
19,
9,
267,
291,
14,
2415,
59,
16,
1055,
7275,
1457,
8,
1457,
9,
267,
702,
22083,
315,
291,
14,
2415,
59,
16,
1055,
362,
1773,
25341,
342,
267,
900,
14,
4532,
8,
19,
9,
267,
1853,
275,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
8,
827,
63,
2347,
63,
474,
29,
19,
9,
267,
291,
14,
2415,
59,
16,
1055,
7275,
1457,
8,
1457,
9,
267,
702,
22083,
440,
315,
291,
14,
2415,
59,
16,
1055,
362,
1773,
25341,
342,
267,
327,
19468,
1655,
543,
949,
7339,
334,
885,
365,
378,
12,
2951,
5343,
849,
1680,
9,
267,
22083,
275,
291,
14,
2415,
59,
16,
1055,
23267,
1562,
8,
277,
14,
2415,
59,
16,
1055,
21102,
1062,
413,
9,
267,
1853,
275,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
8,
827,
63,
2347,
63,
474,
29,
16,
9,
267,
291,
14,
2415,
59,
16,
1055,
7275,
1457,
8,
1457,
9,
267,
702,
22083,
440,
315,
291,
14,
2415,
59,
16,
1055,
362,
1773,
25341,
342,
267,
702,
63,
3536,
63,
4354,
63,
705,
2801,
24,
12,
298,
827,
63,
2347,
63,
474,
1471,
506,
2222,
13,
7371,
4765,
291,
14,
2415,
59,
16,
1055,
18768,
1457,
4097,
12,
446,
17,
9,
398,
327,
603,
1132,
2005,
5664,
436,
1172,
3062,
333,
1463,
14,
267,
9104,
63,
5350,
63,
1617,
275,
291,
14,
2415,
59,
16,
1055,
525,
63,
80,
18,
80,
63,
2105,
8,
48,
18,
4189,
88,
14883,
5502,
1012,
327,
4215,
4426,
402,
315,
3122,
267,
291,
14,
2415,
59,
16,
1055,
4208,
8,
4893,
9,
267,
11430,
22101,
275,
942,
267,
367,
11430,
15987,
315,
291,
14,
2415,
59,
16,
1055,
513,
324,
19435,
8,
709,
304,
288,
327,
8232,
1570,
15,
771,
397,
781,
308,
22684,
1915,
1536,
288,
340,
11430,
15987,
459,
4606,
418,
1137,
6345,
8,
1400,
304,
355,
1980,
288,
11430,
22101,
14,
740,
8,
30275,
9,
267,
702,
63,
13154,
63,
13797,
8,
552,
8,
337,
22101,
395,
413,
9,
398,
22083,
275,
11430,
22101,
59,
16,
2733,
14113,
418,
267,
373,
548,
275,
11430,
22101,
59,
16,
2733,
17853,
418,
267,
574,
275,
11430,
22101,
59,
16,
2733,
4606,
418,
398,
14751,
275,
6345,
480,
16,
14,
4183,
531,
267,
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,
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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
] |
JohnGriffiths/nipype
|
nipype/interfaces/slicer/filtering/resamplescalarvectordwivolume.py
|
15
|
5494
|
# -*- coding: utf8 -*-
"""Autogenerated file - DO NOT EDIT
If you spot a bug, please report it on the mailing list and/or change the generator."""
from nipype.interfaces.base import CommandLine, CommandLineInputSpec, SEMLikeCommandLine, TraitedSpec, File, Directory, traits, isdefined, InputMultiPath, OutputMultiPath
import os
class ResampleScalarVectorDWIVolumeInputSpec(CommandLineInputSpec):
inputVolume = File(position=-2, desc="Input Volume to be resampled", exists=True, argstr="%s")
outputVolume = traits.Either(traits.Bool, File(), position=-1, hash_files=False, desc="Resampled Volume", argstr="%s")
Reference = File(desc="Reference Volume (spacing,size,orientation,origin)", exists=True, argstr="--Reference %s")
transformationFile = File(exists=True, argstr="--transformationFile %s")
defField = File(desc="File containing the deformation field (3D vector image containing vectors with 3 components)", exists=True, argstr="--defField %s")
hfieldtype = traits.Enum("displacement", "h-Field", desc="Set if the deformation field is an h-Field", argstr="--hfieldtype %s")
interpolation = traits.Enum("linear", "nn", "ws", "bs", desc="Sampling algorithm (linear or nn (nearest neighborhoor), ws (WindowedSinc), bs (BSpline) )", argstr="--interpolation %s")
transform_order = traits.Enum("input-to-output", "output-to-input", desc="Select in what order the transforms are read", argstr="--transform_order %s")
notbulk = traits.Bool(desc="The transform following the BSpline transform is not set as a bulk transform for the BSpline transform", argstr="--notbulk ")
spaceChange = traits.Bool(desc="Space Orientation between transform and image is different (RAS/LPS) (warning: if the transform is a Transform Node in Slicer3, do not select)", argstr="--spaceChange ")
rotation_point = traits.List(desc="Rotation Point in case of rotation around a point (otherwise useless)", argstr="--rotation_point %s")
centered_transform = traits.Bool(desc="Set the center of the transformation to the center of the input image", argstr="--centered_transform ")
image_center = traits.Enum("input", "output", desc="Image to use to center the transform (used only if \'Centered Transform\' is selected)", argstr="--image_center %s")
Inverse_ITK_Transformation = traits.Bool(desc="Inverse the transformation before applying it from output image to input image", argstr="--Inverse_ITK_Transformation ")
spacing = InputMultiPath(traits.Float, desc="Spacing along each dimension (0 means use input spacing)", sep=",", argstr="--spacing %s")
size = InputMultiPath(traits.Float, desc="Size along each dimension (0 means use input size)", sep=",", argstr="--size %s")
origin = traits.List(desc="Origin of the output Image", argstr="--origin %s")
direction_matrix = InputMultiPath(traits.Float, desc="9 parameters of the direction matrix by rows (ijk to LPS if LPS transform, ijk to RAS if RAS transform)", sep=",", argstr="--direction_matrix %s")
number_of_thread = traits.Int(desc="Number of thread used to compute the output image", argstr="--number_of_thread %d")
default_pixel_value = traits.Float(desc="Default pixel value for samples falling outside of the input region", argstr="--default_pixel_value %f")
window_function = traits.Enum("h", "c", "w", "l", "b", desc="Window Function , h = Hamming , c = Cosine , w = Welch , l = Lanczos , b = Blackman", argstr="--window_function %s")
spline_order = traits.Int(desc="Spline Order", argstr="--spline_order %d")
transform_matrix = InputMultiPath(traits.Float, desc="12 parameters of the transform matrix by rows ( --last 3 being translation-- )", sep=",", argstr="--transform_matrix %s")
transform = traits.Enum("rt", "a", desc="Transform algorithm, rt = Rigid Transform, a = Affine Transform", argstr="--transform %s")
class ResampleScalarVectorDWIVolumeOutputSpec(TraitedSpec):
outputVolume = File(position=-1, desc="Resampled Volume", exists=True)
class ResampleScalarVectorDWIVolume(SEMLikeCommandLine):
"""title: Resample Scalar/Vector/DWI Volume
category: Filtering
description: This module implements image and vector-image resampling through the use of itk Transforms.It can also handle diffusion weighted MRI image resampling. "Resampling" is performed in space coordinates, not pixel/grid coordinates. It is quite important to ensure that image spacing is properly set on the images involved. The interpolator is required since the mapping from one space to the other will often require evaluation of the intensity of the image at non-grid positions.
Warning: To resample DWMR Images, use nrrd input and output files.
Warning: Do not use to resample Diffusion Tensor Images, tensors would not be reoriented
version: 0.1
documentation-url: http://www.slicer.org/slicerWiki/index.php/Documentation/4.1/Modules/ResampleScalarVectorDWIVolume
contributor: Francois Budin (UNC)
acknowledgements: This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB005149. Information on the National Centers for Biomedical Computing can be obtained from http://nihroadmap.nih.gov/bioinformatics
"""
input_spec = ResampleScalarVectorDWIVolumeInputSpec
output_spec = ResampleScalarVectorDWIVolumeOutputSpec
_cmd = "ResampleScalarVectorDWIVolume "
_outputs_filenames = {'outputVolume':'outputVolume.nii'}
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
24,
1882,
199,
624,
23570,
16741,
570,
446,
3506,
2845,
24981,
199,
3917,
1265,
23226,
282,
6519,
12,
8749,
3622,
652,
641,
314,
30939,
769,
436,
15,
269,
1570,
314,
4306,
1041,
199,
199,
504,
302,
711,
514,
14,
7436,
14,
1095,
492,
5817,
3049,
12,
5817,
3049,
3205,
5307,
12,
5795,
1698,
7455,
16926,
12,
12643,
5703,
5307,
12,
3814,
12,
15191,
12,
19692,
12,
365,
4037,
12,
6924,
3947,
2042,
12,
7242,
3947,
2042,
199,
646,
747,
421,
199,
533,
3591,
865,
13090,
3646,
36,
18759,
6464,
3205,
5307,
8,
16926,
3205,
5307,
304,
272,
1324,
6464,
275,
3814,
8,
3124,
4022,
18,
12,
4328,
628,
3205,
15018,
370,
506,
31744,
68,
401,
3495,
29,
549,
12,
22494,
5961,
83,
531,
272,
1072,
6464,
275,
19692,
14,
37,
1711,
8,
17668,
14,
10349,
12,
3814,
1062,
3421,
4022,
17,
12,
2631,
63,
1725,
29,
797,
12,
4328,
628,
1322,
865,
68,
15018,
401,
22494,
5961,
83,
531,
272,
10944,
275,
3814,
8,
3257,
628,
5083,
15018,
334,
15880,
12,
890,
12,
17001,
12,
6493,
4186,
3495,
29,
549,
12,
22494,
28953,
5083,
450,
83,
531,
272,
13315,
1173,
275,
3814,
8,
2444,
29,
549,
12,
22494,
28953,
31400,
1173,
450,
83,
531,
272,
347,
792,
275,
3814,
8,
3257,
628,
1173,
3035,
314,
347,
269,
1615,
901,
334,
19,
36,
5477,
1834,
3035,
11102,
543,
650,
7323,
4186,
3495,
29,
549,
12,
22494,
28953,
318,
792,
450,
83,
531,
272,
394,
698,
466,
275,
19692,
14,
5081,
480,
13654,
27350,
401,
298,
72,
13,
792,
401,
4328,
628,
1084,
340,
314,
347,
269,
1615,
901,
365,
376,
394,
13,
792,
401,
22494,
28953,
72,
698,
466,
450,
83,
531,
272,
14046,
275,
19692,
14,
5081,
480,
6676,
401,
298,
4411,
401,
298,
3569,
401,
298,
1533,
401,
4328,
628,
12226,
8922,
5563,
334,
6676,
503,
11542,
334,
16615,
15503,
526,
269,
395,
10900,
334,
4301,
379,
51,
6559,
395,
9922,
334,
34,
27558,
9,
776,
401,
22494,
28953,
21080,
450,
83,
531,
272,
5793,
63,
1648,
275,
19692,
14,
5081,
480,
1210,
13,
475,
13,
1199,
401,
298,
1199,
13,
475,
13,
1210,
401,
4328,
628,
5446,
315,
4052,
1865,
314,
18501,
787,
1586,
401,
22494,
28953,
4711,
63,
1648,
450,
83,
531,
272,
440,
9377,
275,
19692,
14,
10349,
8,
3257,
628,
1918,
5793,
2569,
314,
699,
27558,
5793,
365,
440,
663,
465,
282,
13137,
5793,
367,
314,
699,
27558,
5793,
401,
22494,
28953,
1397,
9377,
6099,
272,
4601,
4001,
275,
19692,
14,
10349,
8,
3257,
628,
7643,
593,
322,
484,
425,
3382,
5793,
436,
1834,
365,
3365,
334,
50,
1179,
15,
44,
5067,
9,
334,
3764,
26,
340,
314,
5793,
365,
282,
19463,
5013,
315,
428,
27975,
19,
12,
886,
440,
3504,
4186,
22494,
28953,
2638,
4001,
6099,
272,
13038,
63,
1403,
275,
19692,
14,
1296,
8,
3257,
628,
28247,
7584,
315,
1930,
402,
13038,
6818,
282,
2376,
334,
26617,
31291,
4186,
22494,
28953,
15362,
63,
1403,
450,
83,
531,
272,
23903,
63,
4711,
275,
19692,
14,
10349,
8,
3257,
628,
1084,
314,
8126,
402,
314,
13315,
370,
314,
8126,
402,
314,
1324,
1834,
401,
22494,
28953,
20080,
63,
4711,
6099,
272,
1834,
63,
4218,
275,
19692,
14,
5081,
480,
1210,
401,
298,
1199,
401,
4328,
628,
3491,
370,
675,
370,
8126,
314,
5793,
334,
2972,
1454,
340,
8891,
18345,
3014,
19463,
3985,
365,
4895,
4186,
22494,
28953,
1569,
63,
4218,
450,
83,
531,
272,
1010,
2077,
63,
649,
43,
63,
26283,
275,
19692,
14,
10349,
8,
3257,
628,
28274,
314,
13315,
2544,
18876,
652,
687,
1072,
1834,
370,
1324,
1834,
401,
22494,
28953,
28274,
63,
649,
43,
63,
26283,
6099,
272,
19621,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
24052,
3180,
1924,
6240,
334,
16,
4910,
675,
1324,
19621,
4186,
7375,
11107,
401,
22494,
28953,
15880,
450,
83,
531,
272,
1568,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
2320,
3180,
1924,
6240,
334,
16,
4910,
675,
1324,
1568,
4186,
7375,
11107,
401,
22494,
28953,
890,
450,
83,
531,
272,
6330,
275,
19692,
14,
1296,
8,
3257,
628,
12834,
402,
314,
1072,
6047,
401,
22494,
28953,
6493,
450,
83,
531,
272,
7581,
63,
3642,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
25,
2633,
402,
314,
7581,
3634,
701,
4730,
334,
7879,
75,
370,
491,
5067,
340,
491,
5067,
5793,
12,
284,
17421,
370,
820,
1179,
340,
820,
1179,
5793,
4186,
7375,
11107,
401,
22494,
28953,
6874,
63,
3642,
450,
83,
531,
272,
1329,
63,
1618,
63,
2671,
275,
19692,
14,
3241,
8,
3257,
628,
3259,
402,
2462,
1202,
370,
4526,
314,
1072,
1834,
401,
22494,
28953,
1955,
63,
1618,
63,
2671,
450,
68,
531,
272,
849,
63,
8435,
63,
585,
275,
19692,
14,
5136,
8,
3257,
628,
2698,
7148,
574,
367,
5845,
32039,
9682,
402,
314,
1324,
4897,
401,
22494,
28953,
885,
63,
8435,
63,
585,
450,
70,
531,
272,
4353,
63,
1593,
275,
19692,
14,
5081,
480,
72,
401,
298,
67,
401,
298,
87,
401,
298,
76,
401,
298,
66,
401,
4328,
628,
4301,
6801,
2360,
394,
275,
869,
455,
14566,
2360,
286,
275,
445,
736,
1132,
2360,
336,
275,
644,
352,
335,
2360,
634,
275,
491,
290,
16823,
736,
2360,
330,
275,
30593,
1237,
401,
22494,
28953,
3806,
63,
1593,
450,
83,
531,
272,
30213,
63,
1648,
275,
19692,
14,
3241,
8,
3257,
628,
27558,
9240,
401,
22494,
28953,
27066,
63,
1648,
450,
68,
531,
272,
5793,
63,
3642,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
713,
2633,
402,
314,
5793,
3634,
701,
4730,
334,
1553,
2019,
650,
3769,
7761,
306,
776,
401,
7375,
11107,
401,
22494,
28953,
4711,
63,
3642,
450,
83,
531,
272,
5793,
275,
19692,
14,
5081,
480,
2591,
401,
298,
65,
401,
4328,
628,
6939,
5563,
12,
14059,
275,
820,
528,
344,
19463,
12,
282,
275,
31030,
1132,
19463,
401,
22494,
28953,
4711,
450,
83,
531,
421,
199,
533,
3591,
865,
13090,
3646,
36,
18759,
6464,
2959,
5307,
8,
2437,
5703,
5307,
304,
272,
1072,
6464,
275,
3814,
8,
3124,
4022,
17,
12,
4328,
628,
1322,
865,
68,
15018,
401,
3495,
29,
549
] |
[
1882,
2803,
26,
2774,
24,
1882,
199,
624,
23570,
16741,
570,
446,
3506,
2845,
24981,
199,
3917,
1265,
23226,
282,
6519,
12,
8749,
3622,
652,
641,
314,
30939,
769,
436,
15,
269,
1570,
314,
4306,
1041,
199,
199,
504,
302,
711,
514,
14,
7436,
14,
1095,
492,
5817,
3049,
12,
5817,
3049,
3205,
5307,
12,
5795,
1698,
7455,
16926,
12,
12643,
5703,
5307,
12,
3814,
12,
15191,
12,
19692,
12,
365,
4037,
12,
6924,
3947,
2042,
12,
7242,
3947,
2042,
199,
646,
747,
421,
199,
533,
3591,
865,
13090,
3646,
36,
18759,
6464,
3205,
5307,
8,
16926,
3205,
5307,
304,
272,
1324,
6464,
275,
3814,
8,
3124,
4022,
18,
12,
4328,
628,
3205,
15018,
370,
506,
31744,
68,
401,
3495,
29,
549,
12,
22494,
5961,
83,
531,
272,
1072,
6464,
275,
19692,
14,
37,
1711,
8,
17668,
14,
10349,
12,
3814,
1062,
3421,
4022,
17,
12,
2631,
63,
1725,
29,
797,
12,
4328,
628,
1322,
865,
68,
15018,
401,
22494,
5961,
83,
531,
272,
10944,
275,
3814,
8,
3257,
628,
5083,
15018,
334,
15880,
12,
890,
12,
17001,
12,
6493,
4186,
3495,
29,
549,
12,
22494,
28953,
5083,
450,
83,
531,
272,
13315,
1173,
275,
3814,
8,
2444,
29,
549,
12,
22494,
28953,
31400,
1173,
450,
83,
531,
272,
347,
792,
275,
3814,
8,
3257,
628,
1173,
3035,
314,
347,
269,
1615,
901,
334,
19,
36,
5477,
1834,
3035,
11102,
543,
650,
7323,
4186,
3495,
29,
549,
12,
22494,
28953,
318,
792,
450,
83,
531,
272,
394,
698,
466,
275,
19692,
14,
5081,
480,
13654,
27350,
401,
298,
72,
13,
792,
401,
4328,
628,
1084,
340,
314,
347,
269,
1615,
901,
365,
376,
394,
13,
792,
401,
22494,
28953,
72,
698,
466,
450,
83,
531,
272,
14046,
275,
19692,
14,
5081,
480,
6676,
401,
298,
4411,
401,
298,
3569,
401,
298,
1533,
401,
4328,
628,
12226,
8922,
5563,
334,
6676,
503,
11542,
334,
16615,
15503,
526,
269,
395,
10900,
334,
4301,
379,
51,
6559,
395,
9922,
334,
34,
27558,
9,
776,
401,
22494,
28953,
21080,
450,
83,
531,
272,
5793,
63,
1648,
275,
19692,
14,
5081,
480,
1210,
13,
475,
13,
1199,
401,
298,
1199,
13,
475,
13,
1210,
401,
4328,
628,
5446,
315,
4052,
1865,
314,
18501,
787,
1586,
401,
22494,
28953,
4711,
63,
1648,
450,
83,
531,
272,
440,
9377,
275,
19692,
14,
10349,
8,
3257,
628,
1918,
5793,
2569,
314,
699,
27558,
5793,
365,
440,
663,
465,
282,
13137,
5793,
367,
314,
699,
27558,
5793,
401,
22494,
28953,
1397,
9377,
6099,
272,
4601,
4001,
275,
19692,
14,
10349,
8,
3257,
628,
7643,
593,
322,
484,
425,
3382,
5793,
436,
1834,
365,
3365,
334,
50,
1179,
15,
44,
5067,
9,
334,
3764,
26,
340,
314,
5793,
365,
282,
19463,
5013,
315,
428,
27975,
19,
12,
886,
440,
3504,
4186,
22494,
28953,
2638,
4001,
6099,
272,
13038,
63,
1403,
275,
19692,
14,
1296,
8,
3257,
628,
28247,
7584,
315,
1930,
402,
13038,
6818,
282,
2376,
334,
26617,
31291,
4186,
22494,
28953,
15362,
63,
1403,
450,
83,
531,
272,
23903,
63,
4711,
275,
19692,
14,
10349,
8,
3257,
628,
1084,
314,
8126,
402,
314,
13315,
370,
314,
8126,
402,
314,
1324,
1834,
401,
22494,
28953,
20080,
63,
4711,
6099,
272,
1834,
63,
4218,
275,
19692,
14,
5081,
480,
1210,
401,
298,
1199,
401,
4328,
628,
3491,
370,
675,
370,
8126,
314,
5793,
334,
2972,
1454,
340,
8891,
18345,
3014,
19463,
3985,
365,
4895,
4186,
22494,
28953,
1569,
63,
4218,
450,
83,
531,
272,
1010,
2077,
63,
649,
43,
63,
26283,
275,
19692,
14,
10349,
8,
3257,
628,
28274,
314,
13315,
2544,
18876,
652,
687,
1072,
1834,
370,
1324,
1834,
401,
22494,
28953,
28274,
63,
649,
43,
63,
26283,
6099,
272,
19621,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
24052,
3180,
1924,
6240,
334,
16,
4910,
675,
1324,
19621,
4186,
7375,
11107,
401,
22494,
28953,
15880,
450,
83,
531,
272,
1568,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
2320,
3180,
1924,
6240,
334,
16,
4910,
675,
1324,
1568,
4186,
7375,
11107,
401,
22494,
28953,
890,
450,
83,
531,
272,
6330,
275,
19692,
14,
1296,
8,
3257,
628,
12834,
402,
314,
1072,
6047,
401,
22494,
28953,
6493,
450,
83,
531,
272,
7581,
63,
3642,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
25,
2633,
402,
314,
7581,
3634,
701,
4730,
334,
7879,
75,
370,
491,
5067,
340,
491,
5067,
5793,
12,
284,
17421,
370,
820,
1179,
340,
820,
1179,
5793,
4186,
7375,
11107,
401,
22494,
28953,
6874,
63,
3642,
450,
83,
531,
272,
1329,
63,
1618,
63,
2671,
275,
19692,
14,
3241,
8,
3257,
628,
3259,
402,
2462,
1202,
370,
4526,
314,
1072,
1834,
401,
22494,
28953,
1955,
63,
1618,
63,
2671,
450,
68,
531,
272,
849,
63,
8435,
63,
585,
275,
19692,
14,
5136,
8,
3257,
628,
2698,
7148,
574,
367,
5845,
32039,
9682,
402,
314,
1324,
4897,
401,
22494,
28953,
885,
63,
8435,
63,
585,
450,
70,
531,
272,
4353,
63,
1593,
275,
19692,
14,
5081,
480,
72,
401,
298,
67,
401,
298,
87,
401,
298,
76,
401,
298,
66,
401,
4328,
628,
4301,
6801,
2360,
394,
275,
869,
455,
14566,
2360,
286,
275,
445,
736,
1132,
2360,
336,
275,
644,
352,
335,
2360,
634,
275,
491,
290,
16823,
736,
2360,
330,
275,
30593,
1237,
401,
22494,
28953,
3806,
63,
1593,
450,
83,
531,
272,
30213,
63,
1648,
275,
19692,
14,
3241,
8,
3257,
628,
27558,
9240,
401,
22494,
28953,
27066,
63,
1648,
450,
68,
531,
272,
5793,
63,
3642,
275,
6924,
3947,
2042,
8,
17668,
14,
5136,
12,
4328,
628,
713,
2633,
402,
314,
5793,
3634,
701,
4730,
334,
1553,
2019,
650,
3769,
7761,
306,
776,
401,
7375,
11107,
401,
22494,
28953,
4711,
63,
3642,
450,
83,
531,
272,
5793,
275,
19692,
14,
5081,
480,
2591,
401,
298,
65,
401,
4328,
628,
6939,
5563,
12,
14059,
275,
820,
528,
344,
19463,
12,
282,
275,
31030,
1132,
19463,
401,
22494,
28953,
4711,
450,
83,
531,
421,
199,
533,
3591,
865,
13090,
3646,
36,
18759,
6464,
2959,
5307,
8,
2437,
5703,
5307,
304,
272,
1072,
6464,
275,
3814,
8,
3124,
4022,
17,
12,
4328,
628,
1322,
865,
68,
15018,
401,
3495,
29,
549,
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
] |
harmslab/pytc
|
pytc/fitters/bayesian.py
|
2
|
7462
|
__description__ = \
"""
Fitter subclass for performing bayesian (MCMC) fits.
"""
__author__ = "Michael J. Harms"
__date__ = "2017-05-10"
from .base import Fitter
import emcee, corner
import numpy as np
import scipy.optimize as optimize
import multiprocessing
class BayesianFitter(Fitter):
"""
"""
def __init__(self,num_walkers=100,initial_walker_spread=1e-4,ml_guess=True,
num_steps=100,burn_in=0.1,num_threads=1):
"""
Initialize the bayesian fitter
Parameters
----------
num_walkers : int > 0
how many markov chains to have in the analysis
initial_walker_spread : float
each walker is initialized with parameters sampled from normal
distributions with mean equal to the initial guess and a standard
deviation of guess*initial_walker_spread
ml_guess : bool
if true, do an ML optimization to get the initial guess
num_steps:
number of steps to run the markov chains
burn_in : float between 0 and 1
fraction of samples to discard from the start of the run
num_threads : int or `"max"`
number of threads to use. if `"max"`, use the total number of
cpus. [NOT YET IMPLEMENTED]
"""
Fitter.__init__(self)
self._num_walkers = num_walkers
self._initial_walker_spread = initial_walker_spread
self._ml_guess = ml_guess
self._num_steps = num_steps
self._burn_in = burn_in
self._num_threads = num_threads
if self._num_threads == "max":
self._num_threads = multiprocessing.cpu_count()
if not type(self._num_threads) == int and self._num_threads > 0:
err = "num_threads must be 'max' or a positive integer\n"
raise ValueError(err)
if self._num_threads != 1:
err = "multithreading has not yet been (fully) implemented.\n"
raise NotImplementedError(err)
self._success = None
self.fit_type = "bayesian"
def ln_prior(self,param):
"""
Log prior of fit parameters. Priors are uniform between bounds and
set to -np.inf outside of bounds.
Parameters
----------
param : array of floats
parameters to fit
Returns
-------
float value for log of priors.
"""
# If a paramter falls outside of the bounds, make the prior -infinity
if np.sum(param < self._bounds[0,:]) > 0 or np.sum(param > self._bounds[1,:]) > 0:
return -np.inf
# otherwise, uniform
return 0.0
def ln_prob(self,param):
"""
Posterior probability of model parameters.
Parameters
----------
param : array of floats
parameters to fit
Returns
-------
float value for log posterior proability
"""
# Calcualte prior. If not finite, this solution has an -infinity log
# likelihood
ln_prior = self.ln_prior(param)
if not np.isfinite(ln_prior):
return -np.inf
# Calcualte likelihood. If not finite, this solution has an -infinity
# log likelihood
ln_like = self.ln_like(param)
if not np.isfinite(ln_like):
return -np.inf
# log posterior is log prior plus log likelihood
return ln_prior + ln_like
def fit(self,model,parameters,bounds,y_obs,y_err=None,param_names=None):
"""
Fit the parameters.
Parameters
----------
model : callable
model to fit. model should take "parameters" as its only argument.
this should (usually) be GlobalFit._y_calc
parameters : array of floats
parameters to be optimized. usually constructed by GlobalFit._prep_fit
bounds : list
list of two lists containing lower and upper bounds
y_obs : array of floats
observations in an concatenated array
y_err : array of floats or None
standard deviation of each observation. if None, each observation
is assigned an error of 1/num_obs
param_names : array of str
names of parameters. If None, parameters assigned names p0,p1,..pN
"""
self._model = model
self._y_obs = y_obs
# Convert the bounds (list of lower and upper lists) into a 2d numpy array
self._bounds = np.array(bounds)
# If no error is specified, assign the error as 1/N, identical for all
# points
self._y_err = y_err
if y_err is None:
self._y_err = np.array([1/len(self._y_obs) for i in range(len(self._y_obs))])
if param_names is None:
self._param_names = ["p{}".format(i) for i in range(len(parameters))]
else:
self._param_names = param_names[:]
# Make initial guess (ML or just whatever the paramters sent in were)
if self._ml_guess:
fn = lambda *args: -self.weighted_residuals(*args)
ml_fit = optimize.least_squares(fn,x0=parameters,bounds=self._bounds)
self._initial_guess = np.copy(ml_fit.x)
else:
self._initial_guess = np.copy(parameters)
# Create walker positions
# Size of perturbation in parameter depends on the scale of the parameter
perturb_size = self._initial_guess*self._initial_walker_spread
ndim = len(parameters)
pos = [self._initial_guess + np.random.randn(ndim)*perturb_size
for i in range(self._num_walkers)]
# Sample using walkers
self._fit_result = emcee.EnsembleSampler(self._num_walkers, ndim, self.ln_prob,
threads=self._num_threads)
self._fit_result.run_mcmc(pos, self._num_steps)
# Create list of samples
to_discard = int(round(self._burn_in*self._num_steps,0))
self._samples = self._fit_result.chain[:,to_discard:,:].reshape((-1,ndim))
self._lnprob = self._fit_result.lnprobability[:,:].reshape(-1)
# Get mean and standard deviation
self._estimate = np.mean(self._samples,axis=0)
self._stdev = np.std(self._samples,axis=0)
# Calculate 95% confidence intervals
self._ninetyfive = []
lower = int(round(0.025*self._samples.shape[0],0))
upper = int(round(0.975*self._samples.shape[0],0))
for i in range(self._samples.shape[1]):
nf = np.sort(self._samples[:,i])
self._ninetyfive.append([nf[lower],nf[upper]])
self._ninetyfive = np.array(self._ninetyfive)
self._success = True
@property
def fit_info(self):
"""
Information about the Bayesian run.
"""
output = {}
output["Num walkers"] = self._num_walkers
output["Initial walker spread"] = self._initial_walker_spread
output["Use ML guess"] = self._ml_guess
output["Num steps"] = self._num_steps
output["Burn in"] = self._burn_in
output["Final sample number"] = len(self._samples[:,0])
output["Num threads"] = self._num_threads
return output
@property
def samples(self):
"""
Bayesian samples.
"""
return self._samples
|
unlicense
|
[
363,
1802,
363,
275,
971,
199,
624,
199,
13776,
351,
5516,
367,
19203,
30933,
69,
6214,
334,
7608,
7608,
9,
20147,
14,
199,
624,
199,
363,
2502,
363,
275,
298,
45,
11781,
1603,
14,
869,
25005,
2,
199,
363,
602,
363,
275,
298,
10680,
13,
1717,
13,
709,
2,
199,
199,
504,
1275,
1095,
492,
25971,
351,
199,
199,
646,
18564,
29377,
12,
17703,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
13416,
465,
13497,
199,
199,
646,
12866,
199,
199,
533,
29434,
69,
6214,
13776,
351,
8,
13776,
351,
304,
272,
408,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1507,
63,
7757,
1192,
29,
1960,
12,
2747,
63,
87,
14976,
63,
29889,
29,
17,
69,
13,
20,
12,
757,
63,
11636,
29,
549,
12,
326,
1967,
63,
5895,
29,
1960,
12,
30736,
63,
262,
29,
16,
14,
17,
12,
1507,
63,
6962,
29,
17,
304,
267,
408,
267,
11578,
314,
30933,
69,
6214,
5542,
351,
398,
3897,
267,
4143,
263,
523,
267,
1967,
63,
7757,
1192,
520,
1109,
690,
378,
288,
4212,
5002,
2216,
8822,
30640,
370,
1172,
315,
314,
11284,
267,
2536,
63,
87,
14976,
63,
29889,
520,
2069,
288,
1924,
336,
14976,
365,
10038,
543,
2633,
24914,
687,
3293,
7205,
10208,
543,
4615,
4472,
370,
314,
2536,
9519,
436,
282,
4465,
288,
18458,
402,
9519,
10,
2747,
63,
87,
14976,
63,
29889,
4960,
19184,
63,
11636,
520,
2155,
288,
340,
2549,
12,
886,
376,
28007,
13712,
370,
664,
314,
2536,
9519,
267,
1967,
63,
5895,
26,
288,
1329,
402,
7124,
370,
1255,
314,
2216,
8822,
30640,
267,
330,
349,
63,
262,
520,
2069,
3382,
378,
436,
413,
288,
12347,
402,
5845,
370,
16895,
687,
314,
1343,
402,
314,
1255,
267,
1967,
63,
6962,
520,
1109,
503,
28531,
988,
2,
64,
288,
1329,
402,
7183,
370,
675,
14,
221,
340,
28531,
988,
2,
3559,
675,
314,
3141,
1329,
402,
7205,
24174,
14,
359,
4609,
1488,
775,
5025,
10320,
1149,
61,
4960,
408,
398,
25971,
351,
855,
826,
721,
277,
9,
398,
291,
423,
1507,
63,
7757,
1192,
275,
1967,
63,
7757,
1192,
267,
291,
423,
2747,
63,
87,
14976,
63,
29889,
275,
2536,
63,
87,
14976,
63,
29889,
267,
291,
423,
757,
63,
11636,
275,
19184,
63,
11636,
267,
291,
423,
1507,
63,
5895,
275,
1967,
63,
5895,
267,
291,
423,
30736,
63,
262,
275,
330,
349,
63,
262,
398,
291,
423,
1507,
63,
6962,
275,
1967,
63,
6962,
267,
340,
291,
423,
1507,
63,
6962,
508,
298,
988,
582,
288,
291,
423,
1507,
63,
6962,
275,
12866,
14,
3541,
63,
835,
342,
398,
340,
440,
730,
8,
277,
423,
1507,
63,
6962,
9,
508,
1109,
436,
291,
423,
1507,
63,
6962,
690,
378,
26,
288,
2329,
275,
298,
1507,
63,
6962,
1471,
506,
283,
988,
7,
503,
282,
7317,
3000,
60,
78,
2,
288,
746,
1722,
8,
1508,
9,
398,
340,
291,
423,
1507,
63,
6962,
1137,
413,
26,
288,
2329,
275,
298,
3029,
12562,
965,
440,
5966,
2757,
334,
5836,
9,
6366,
3134,
78,
2,
288,
746,
4279,
8,
1508,
9,
398,
291,
423,
3742,
275,
488,
398,
291,
14,
3269,
63,
466,
275,
298,
19558,
69,
6214,
2,
339,
347,
10359,
63,
13775,
8,
277,
12,
635,
304,
267,
408,
267,
5297,
6791,
402,
5542,
2633,
14,
221,
8538,
1384,
787,
14818,
3382,
10461,
436,
4960,
663,
370,
446,
1590,
14,
4904,
9682,
402,
10461,
14,
398,
3897,
267,
4143,
398,
1215,
520,
1625,
402,
15657,
288,
2633,
370,
5542,
398,
1803,
267,
5514,
398,
2069,
574,
367,
943,
402,
1979,
1384,
14,
4960,
408,
398,
327,
982,
282,
1215,
351,
26945,
9682,
402,
314,
10461,
12,
1852,
314,
6791,
446,
262,
9693,
267,
340,
980,
14,
1838,
8,
635,
665,
291,
423,
9632,
59,
16,
12,
5728,
690,
378,
503,
980,
14,
1838,
8,
635,
690,
291,
423,
9632,
59,
17,
12,
5728,
690,
378,
26,
288,
372,
446,
1590,
14,
4904,
398,
327,
4257,
12,
14818,
267,
372,
378,
14,
16,
339,
347,
10359,
63,
6101,
8,
277,
12,
635,
304,
267,
408,
267,
25987,
17514,
12224,
402,
1402,
2633,
14,
398,
3897,
267,
4143,
398,
1215,
520,
1625,
402,
15657,
288,
2633,
370,
5542,
398,
1803,
267,
5514,
398,
2069,
574,
367,
943,
2086,
17514,
557,
3616,
267,
408,
398,
327,
8256,
67,
1061,
266,
6791,
14,
221,
982,
440,
21837,
12,
642,
8744,
965,
376,
446,
262,
9693,
943,
4960,
327,
22046,
267,
10359,
63,
13775,
275,
291,
14,
6066,
63,
13775,
8,
635,
9,
267,
340,
440,
980,
14,
30276,
8,
6066,
63,
13775,
304,
288,
372,
446,
1590,
14,
4904,
523,
267,
327,
8256,
67,
1061,
266,
22046,
14,
221,
982,
440,
21837,
12,
642,
8744,
965,
376,
446,
262,
9693,
267,
327,
943,
22046,
267,
10359,
63,
2930,
275,
291,
14,
6066,
63,
2930,
8,
635,
9,
267,
340,
440,
980,
14,
30276,
8,
6066,
63,
2930,
304,
288,
372,
446,
1590,
14,
4904,
398,
327,
943,
2086,
17514,
365,
943,
6791,
12254,
943,
22046,
4960,
372,
10359,
63,
13775,
435,
10359,
63,
2930,
339,
347,
5542,
8,
277,
12,
1238,
12,
3214,
12,
9632,
12,
89,
63,
11226,
12,
89,
63,
1508,
29,
403,
12,
635,
63,
1247,
29,
403,
304,
267,
408,
267,
25971,
314,
2633,
14,
263,
523,
267,
3897,
267,
4143,
398,
1402,
520,
4550,
288,
1402,
370,
5542,
14,
221,
1402,
1077,
5452,
298,
3214,
2,
465,
2399,
1454,
1423,
14,
288,
642,
1077,
334,
25118,
9,
506,
13641,
13776,
423,
89,
63,
8104,
267,
2633,
520,
1625,
402,
15657,
288,
2633,
370,
506,
20212,
14,
221,
9987,
14701,
701,
13641,
13776,
423,
10837,
63,
3269,
267,
10461,
520,
769,
288,
769,
402,
2877,
5548,
3035,
5117,
436,
7008,
10461,
267,
612,
63,
11226,
520,
1625,
402,
15657,
288,
19739,
315,
376,
26271,
1625,
267,
612,
63,
1508,
520,
1625,
402,
15657,
503,
488,
288,
4465,
18458,
402,
1924,
20038,
14,
221,
340,
488,
12,
1924,
20038,
288,
365,
7943,
376,
1125,
402,
413,
15,
1507,
63,
11226,
4960,
1215,
63,
1247,
520,
1625,
402,
620,
288,
1561,
402,
2633,
14,
221,
982,
488,
12,
2633,
7943,
1561,
299,
16,
12,
80,
17
] |
[
1802,
363,
275,
971,
199,
624,
199,
13776,
351,
5516,
367,
19203,
30933,
69,
6214,
334,
7608,
7608,
9,
20147,
14,
199,
624,
199,
363,
2502,
363,
275,
298,
45,
11781,
1603,
14,
869,
25005,
2,
199,
363,
602,
363,
275,
298,
10680,
13,
1717,
13,
709,
2,
199,
199,
504,
1275,
1095,
492,
25971,
351,
199,
199,
646,
18564,
29377,
12,
17703,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
13416,
465,
13497,
199,
199,
646,
12866,
199,
199,
533,
29434,
69,
6214,
13776,
351,
8,
13776,
351,
304,
272,
408,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1507,
63,
7757,
1192,
29,
1960,
12,
2747,
63,
87,
14976,
63,
29889,
29,
17,
69,
13,
20,
12,
757,
63,
11636,
29,
549,
12,
326,
1967,
63,
5895,
29,
1960,
12,
30736,
63,
262,
29,
16,
14,
17,
12,
1507,
63,
6962,
29,
17,
304,
267,
408,
267,
11578,
314,
30933,
69,
6214,
5542,
351,
398,
3897,
267,
4143,
263,
523,
267,
1967,
63,
7757,
1192,
520,
1109,
690,
378,
288,
4212,
5002,
2216,
8822,
30640,
370,
1172,
315,
314,
11284,
267,
2536,
63,
87,
14976,
63,
29889,
520,
2069,
288,
1924,
336,
14976,
365,
10038,
543,
2633,
24914,
687,
3293,
7205,
10208,
543,
4615,
4472,
370,
314,
2536,
9519,
436,
282,
4465,
288,
18458,
402,
9519,
10,
2747,
63,
87,
14976,
63,
29889,
4960,
19184,
63,
11636,
520,
2155,
288,
340,
2549,
12,
886,
376,
28007,
13712,
370,
664,
314,
2536,
9519,
267,
1967,
63,
5895,
26,
288,
1329,
402,
7124,
370,
1255,
314,
2216,
8822,
30640,
267,
330,
349,
63,
262,
520,
2069,
3382,
378,
436,
413,
288,
12347,
402,
5845,
370,
16895,
687,
314,
1343,
402,
314,
1255,
267,
1967,
63,
6962,
520,
1109,
503,
28531,
988,
2,
64,
288,
1329,
402,
7183,
370,
675,
14,
221,
340,
28531,
988,
2,
3559,
675,
314,
3141,
1329,
402,
7205,
24174,
14,
359,
4609,
1488,
775,
5025,
10320,
1149,
61,
4960,
408,
398,
25971,
351,
855,
826,
721,
277,
9,
398,
291,
423,
1507,
63,
7757,
1192,
275,
1967,
63,
7757,
1192,
267,
291,
423,
2747,
63,
87,
14976,
63,
29889,
275,
2536,
63,
87,
14976,
63,
29889,
267,
291,
423,
757,
63,
11636,
275,
19184,
63,
11636,
267,
291,
423,
1507,
63,
5895,
275,
1967,
63,
5895,
267,
291,
423,
30736,
63,
262,
275,
330,
349,
63,
262,
398,
291,
423,
1507,
63,
6962,
275,
1967,
63,
6962,
267,
340,
291,
423,
1507,
63,
6962,
508,
298,
988,
582,
288,
291,
423,
1507,
63,
6962,
275,
12866,
14,
3541,
63,
835,
342,
398,
340,
440,
730,
8,
277,
423,
1507,
63,
6962,
9,
508,
1109,
436,
291,
423,
1507,
63,
6962,
690,
378,
26,
288,
2329,
275,
298,
1507,
63,
6962,
1471,
506,
283,
988,
7,
503,
282,
7317,
3000,
60,
78,
2,
288,
746,
1722,
8,
1508,
9,
398,
340,
291,
423,
1507,
63,
6962,
1137,
413,
26,
288,
2329,
275,
298,
3029,
12562,
965,
440,
5966,
2757,
334,
5836,
9,
6366,
3134,
78,
2,
288,
746,
4279,
8,
1508,
9,
398,
291,
423,
3742,
275,
488,
398,
291,
14,
3269,
63,
466,
275,
298,
19558,
69,
6214,
2,
339,
347,
10359,
63,
13775,
8,
277,
12,
635,
304,
267,
408,
267,
5297,
6791,
402,
5542,
2633,
14,
221,
8538,
1384,
787,
14818,
3382,
10461,
436,
4960,
663,
370,
446,
1590,
14,
4904,
9682,
402,
10461,
14,
398,
3897,
267,
4143,
398,
1215,
520,
1625,
402,
15657,
288,
2633,
370,
5542,
398,
1803,
267,
5514,
398,
2069,
574,
367,
943,
402,
1979,
1384,
14,
4960,
408,
398,
327,
982,
282,
1215,
351,
26945,
9682,
402,
314,
10461,
12,
1852,
314,
6791,
446,
262,
9693,
267,
340,
980,
14,
1838,
8,
635,
665,
291,
423,
9632,
59,
16,
12,
5728,
690,
378,
503,
980,
14,
1838,
8,
635,
690,
291,
423,
9632,
59,
17,
12,
5728,
690,
378,
26,
288,
372,
446,
1590,
14,
4904,
398,
327,
4257,
12,
14818,
267,
372,
378,
14,
16,
339,
347,
10359,
63,
6101,
8,
277,
12,
635,
304,
267,
408,
267,
25987,
17514,
12224,
402,
1402,
2633,
14,
398,
3897,
267,
4143,
398,
1215,
520,
1625,
402,
15657,
288,
2633,
370,
5542,
398,
1803,
267,
5514,
398,
2069,
574,
367,
943,
2086,
17514,
557,
3616,
267,
408,
398,
327,
8256,
67,
1061,
266,
6791,
14,
221,
982,
440,
21837,
12,
642,
8744,
965,
376,
446,
262,
9693,
943,
4960,
327,
22046,
267,
10359,
63,
13775,
275,
291,
14,
6066,
63,
13775,
8,
635,
9,
267,
340,
440,
980,
14,
30276,
8,
6066,
63,
13775,
304,
288,
372,
446,
1590,
14,
4904,
523,
267,
327,
8256,
67,
1061,
266,
22046,
14,
221,
982,
440,
21837,
12,
642,
8744,
965,
376,
446,
262,
9693,
267,
327,
943,
22046,
267,
10359,
63,
2930,
275,
291,
14,
6066,
63,
2930,
8,
635,
9,
267,
340,
440,
980,
14,
30276,
8,
6066,
63,
2930,
304,
288,
372,
446,
1590,
14,
4904,
398,
327,
943,
2086,
17514,
365,
943,
6791,
12254,
943,
22046,
4960,
372,
10359,
63,
13775,
435,
10359,
63,
2930,
339,
347,
5542,
8,
277,
12,
1238,
12,
3214,
12,
9632,
12,
89,
63,
11226,
12,
89,
63,
1508,
29,
403,
12,
635,
63,
1247,
29,
403,
304,
267,
408,
267,
25971,
314,
2633,
14,
263,
523,
267,
3897,
267,
4143,
398,
1402,
520,
4550,
288,
1402,
370,
5542,
14,
221,
1402,
1077,
5452,
298,
3214,
2,
465,
2399,
1454,
1423,
14,
288,
642,
1077,
334,
25118,
9,
506,
13641,
13776,
423,
89,
63,
8104,
267,
2633,
520,
1625,
402,
15657,
288,
2633,
370,
506,
20212,
14,
221,
9987,
14701,
701,
13641,
13776,
423,
10837,
63,
3269,
267,
10461,
520,
769,
288,
769,
402,
2877,
5548,
3035,
5117,
436,
7008,
10461,
267,
612,
63,
11226,
520,
1625,
402,
15657,
288,
19739,
315,
376,
26271,
1625,
267,
612,
63,
1508,
520,
1625,
402,
15657,
503,
488,
288,
4465,
18458,
402,
1924,
20038,
14,
221,
340,
488,
12,
1924,
20038,
288,
365,
7943,
376,
1125,
402,
413,
15,
1507,
63,
11226,
4960,
1215,
63,
1247,
520,
1625,
402,
620,
288,
1561,
402,
2633,
14,
221,
982,
488,
12,
2633,
7943,
1561,
299,
16,
12,
80,
17,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Intel-Corporation/tensorflow
|
tensorflow/python/debug/lib/debug_gradients_test.py
|
14
|
15759
|
# Copyright 2017 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.
# ==============================================================================
"""Unit tests for debug_gradients module."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import shutil
import tempfile
from tensorflow.core.protobuf import config_pb2
from tensorflow.core.protobuf import rewriter_config_pb2
from tensorflow.python.client import session
from tensorflow.python.debug.lib import debug_data
from tensorflow.python.debug.lib import debug_gradients
from tensorflow.python.debug.lib import debug_utils
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.ops import gradients_impl
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import googletest
from tensorflow.python.training import gradient_descent
@test_util.run_deprecated_v1
class IdentifyGradientTest(test_util.TensorFlowTestCase):
def setUp(self):
rewriter_config = rewriter_config_pb2.RewriterConfig(
disable_model_pruning=True,
dependency_optimization=rewriter_config_pb2.RewriterConfig.OFF)
graph_options = config_pb2.GraphOptions(rewrite_options=rewriter_config)
config = config_pb2.ConfigProto(graph_options=graph_options)
self.sess = session.Session(config=config)
with self.sess.as_default():
self.u = variables.Variable(2.0, name="u")
self.v = variables.Variable(3.0, name="v")
self.w = math_ops.multiply(self.u.value(), self.v.value(), name="w")
def tearDown(self):
ops.reset_default_graph()
debug_gradients.clear_gradient_debuggers()
def testIdentifyGradientGivesCorrectTensorObjectWithoutContextManager(self):
grad_debugger = debug_gradients.GradientsDebugger()
id_grad_w = grad_debugger.identify_gradient(self.w)
y = math_ops.add(id_grad_w, -1.0, name="y")
grads = gradients_impl.gradients(y, [self.u, self.v])
self.assertEqual(2, len(grads))
u_grad = grads[0]
v_grad = grads[1]
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(5.0, self.sess.run(y))
self.assertAllClose(3.0, self.sess.run(u_grad))
self.assertAllClose(2.0, self.sess.run(v_grad))
# Fetch the gradient tensor with the x-tensor object.
w_grad = grad_debugger.gradient_tensor(self.w)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
# Fetch the gradient tensor with the x-tensor's name.
w_grad = grad_debugger.gradient_tensor(self.w.name)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
# Fetch the gradient tensor with the x-tensor name.
w_grad = grad_debugger.gradient_tensor(self.w.name)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
def testIdentifyGradientGivesCorrectTensorObjectWithTfGradients(self):
grad_debugger = debug_gradients.GradientsDebugger()
id_grad_w = grad_debugger.identify_gradient(self.w)
y = math_ops.add(id_grad_w, -1.0, name="y")
with grad_debugger:
grads = gradients_impl.gradients(y, [self.u, self.v])
self.assertEqual(2, len(grads))
u_grad = grads[0]
v_grad = grads[1]
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(5.0, self.sess.run(y))
self.assertAllClose(3.0, self.sess.run(u_grad))
self.assertAllClose(2.0, self.sess.run(v_grad))
# Fetch the gradient tensor with the x-tensor object.
w_grad = grad_debugger.gradient_tensor(self.w)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
# Fetch the gradient tensor with the x-tensor's name.
w_grad = grad_debugger.gradient_tensor(self.w.name)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
# Fetch the gradient tensor with the x-tensor name.
w_grad = grad_debugger.gradient_tensor(self.w.name)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
def testCallingIdentifyGradientTwiceWithTheSameGradientsDebuggerErrors(self):
grad_debugger = debug_gradients.GradientsDebugger()
grad_debugger.identify_gradient(self.w)
with self.assertRaisesRegexp(ValueError,
"The graph already contains an op named .*"):
grad_debugger.identify_gradient(self.w)
def testIdentifyGradientWorksOnMultipleLosses(self):
grad_debugger_1 = debug_gradients.GradientsDebugger()
grad_debugger_2 = debug_gradients.GradientsDebugger()
y = math_ops.add(self.w, -1.0, name="y")
debug_y = grad_debugger_1.identify_gradient(y)
z1 = math_ops.square(debug_y, name="z1")
debug_y = grad_debugger_2.identify_gradient(y)
z2 = math_ops.sqrt(debug_y, name="z2")
with grad_debugger_1:
gradient_descent.GradientDescentOptimizer(0.1).minimize(z1)
with grad_debugger_2:
gradient_descent.GradientDescentOptimizer(0.1).minimize(z2)
dz1_dy = grad_debugger_1.gradient_tensor(y)
dz2_dy = grad_debugger_2.gradient_tensor(y)
self.assertIsInstance(dz1_dy, ops.Tensor)
self.assertIsInstance(dz2_dy, ops.Tensor)
self.assertIsNot(dz1_dy, dz2_dy)
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(5.0**2, self.sess.run(z1))
self.assertAllClose(5.0**0.5, self.sess.run(z2))
self.assertAllClose(2.0 * 5.0, self.sess.run(dz1_dy))
self.assertAllClose(0.5 * (5.0**-0.5), self.sess.run(dz2_dy))
def testIdentifyGradientRaisesLookupErrorForUnknownXTensor(self):
grad_debugger_1 = debug_gradients.GradientsDebugger()
grad_debugger_2 = debug_gradients.GradientsDebugger()
id_grad_w = grad_debugger_1.identify_gradient(self.w)
y = math_ops.add(id_grad_w, -1.0, name="y")
# There are >1 gradient debuggers registered, and grad_debugger is not used
# as a context manager here, so the gradient w.r.t. self.w will not be
# registered.
gradients_impl.gradients(y, [self.u, self.v])
with self.assertRaisesRegexp(
LookupError,
r"This GradientsDebugger has not received any gradient tensor for "):
grad_debugger_1.gradient_tensor(self.w)
with self.assertRaisesRegexp(
LookupError,
r"This GradientsDebugger has not received any gradient tensor for "):
grad_debugger_2.gradient_tensor(self.w)
def testIdentifyGradientRaisesTypeErrorForNonTensorOrTensorNameInput(self):
grad_debugger = debug_gradients.GradientsDebugger()
with self.assertRaisesRegexp(
TypeError,
r"x_tensor must be a str or tf\.Tensor or tf\.Variable, but instead "
r"has type .*Operation.*"):
grad_debugger.gradient_tensor(variables.global_variables_initializer())
def testIdentifyGradientTensorWorksWithGradientDescentOptimizer(self):
grad_debugger = debug_gradients.GradientsDebugger()
id_grad_w = grad_debugger.identify_gradient(self.w)
y = math_ops.add(id_grad_w, -1.0, name="y")
with grad_debugger:
gradient_descent.GradientDescentOptimizer(0.1).minimize(y)
self.sess.run(variables.global_variables_initializer())
# Fetch the gradient tensor with the x-tensor object.
w_grad = grad_debugger.gradient_tensor(self.w)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
def testWatchGradientsByXTensorNamesWorks(self):
y = math_ops.add(self.w, -1.0, name="y")
# The constructrion of the forward graph has completed.
# But we can still get the gradient tensors by using
# watch_gradients_by_tensor_names().
grad_debugger = debug_gradients.GradientsDebugger()
with grad_debugger.watch_gradients_by_tensor_names(self.sess.graph, "w:0$"):
grads = gradients_impl.gradients(y, [self.u, self.v])
self.assertEqual(2, len(grads))
u_grad = grads[0]
v_grad = grads[1]
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(5.0, self.sess.run(y))
self.assertAllClose(3.0, self.sess.run(u_grad))
self.assertAllClose(2.0, self.sess.run(v_grad))
w_grad = grad_debugger.gradient_tensor(self.w)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
w_grad = grad_debugger.gradient_tensor("w:0")
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
def testWatchGradientsByXTensorNamesWorksWithoutContextManager(self):
y = math_ops.add(self.w, -1.0, name="y")
# The constructrion of the forward graph has completed.
# But we can still get the gradient tensors by using
# watch_gradients_by_tensor_names().
grad_debugger = debug_gradients.GradientsDebugger()
grad_debugger.watch_gradients_by_tensor_names(self.sess.graph, "w:0$")
grads = gradients_impl.gradients(y, [self.u, self.v])
self.assertEqual(2, len(grads))
u_grad = grads[0]
v_grad = grads[1]
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(5.0, self.sess.run(y))
self.assertAllClose(3.0, self.sess.run(u_grad))
self.assertAllClose(2.0, self.sess.run(v_grad))
w_grad = grad_debugger.gradient_tensor(self.w)
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
w_grad = grad_debugger.gradient_tensor("w:0")
self.assertIsInstance(w_grad, ops.Tensor)
self.assertAllClose(1.0, self.sess.run(w_grad))
def testWatchGradientsWorksOnRefTensor(self):
y = math_ops.add(self.w, -1.0, name="y")
grad_debugger = debug_gradients.GradientsDebugger()
with grad_debugger.watch_gradients_by_tensor_names(self.sess.graph, "u:0$"):
grads = gradients_impl.gradients(y, [self.u, self.v])
self.assertEqual(2, len(grads))
u_grad = grads[0]
v_grad = grads[1]
self.assertIs(u_grad, grad_debugger.gradient_tensor("u:0"))
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(3.0, self.sess.run(u_grad))
self.assertAllClose(2.0, self.sess.run(v_grad))
self.assertAllClose(3.0, self.sess.run(
grad_debugger.gradient_tensor("u:0")))
def testWatchGradientsWorksOnMultipleTensors(self):
y = math_ops.add(self.w, -1.0, name="y")
grad_debugger = debug_gradients.GradientsDebugger()
with grad_debugger.watch_gradients_by_tensor_names(self.sess.graph,
"(u|w):0$"):
grads = gradients_impl.gradients(y, [self.u, self.v])
self.assertEqual(2, len(grads))
u_grad = grads[0]
self.assertEqual(2, len(grad_debugger.gradient_tensors()))
self.assertIs(u_grad, grad_debugger.gradient_tensor("u:0"))
self.assertIsInstance(grad_debugger.gradient_tensor("w:0"), ops.Tensor)
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(1.0, self.sess.run(
grad_debugger.gradient_tensor("w:0")))
self.assertAllClose(3.0, self.sess.run(
grad_debugger.gradient_tensor("u:0")))
def testWatchGradientsByXTensorsWorks(self):
y = math_ops.add(self.w, -1.0, name="foo/y")
z = math_ops.square(y, name="foo/z")
# The constructrion of the forward graph has completed.
# But we can still get the gradient tensors by using
# watch_gradients_by_x_tensors().
grad_debugger = debug_gradients.GradientsDebugger()
with grad_debugger.watch_gradients_by_tensors(self.sess.graph,
[self.w, self.u, y]):
gradient_descent.GradientDescentOptimizer(0.1).minimize(z)
self.assertEqual(3, len(grad_debugger.gradient_tensors()))
u_grad = grad_debugger.gradient_tensor(self.u)
w_grad = grad_debugger.gradient_tensor(self.w)
y_grad = grad_debugger.gradient_tensor(y)
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(10.0, self.sess.run(y_grad))
self.assertAllClose(10.0, self.sess.run(w_grad))
self.assertAllClose(30.0, self.sess.run(u_grad))
def testWatchGradientsByTensorCanWorkOnMultipleLosses(self):
y = math_ops.add(self.w, -1.0, name="y")
z1 = math_ops.square(y, name="z1")
z2 = math_ops.sqrt(y, name="z2")
grad_debugger_1 = debug_gradients.GradientsDebugger()
with grad_debugger_1.watch_gradients_by_tensors(self.sess.graph, y):
gradient_descent.GradientDescentOptimizer(0.1).minimize(z1)
grad_debugger_2 = debug_gradients.GradientsDebugger()
with grad_debugger_2.watch_gradients_by_tensors(self.sess.graph, y):
gradient_descent.GradientDescentOptimizer(0.1).minimize(z2)
dz1_dy = grad_debugger_1.gradient_tensor(y)
dz2_dy = grad_debugger_2.gradient_tensor(y)
self.assertIsInstance(dz1_dy, ops.Tensor)
self.assertIsInstance(dz2_dy, ops.Tensor)
self.assertIsNot(dz1_dy, dz2_dy)
self.sess.run(variables.global_variables_initializer())
self.assertAllClose(5.0**2, self.sess.run(z1))
self.assertAllClose(5.0**0.5, self.sess.run(z2))
self.assertAllClose(2.0 * 5.0, self.sess.run(dz1_dy))
self.assertAllClose(0.5 * (5.0**-0.5), self.sess.run(dz2_dy))
def testGradientsValuesFromDumpWorks(self):
y = math_ops.add(self.w, -1.0, name="y")
z = math_ops.square(y, name="z")
grad_debugger = debug_gradients.GradientsDebugger()
with grad_debugger.watch_gradients_by_tensors(self.sess.graph,
[self.w, self.u, y]):
train_op = gradient_descent.GradientDescentOptimizer(0.1).minimize(z)
self.sess.run(variables.global_variables_initializer())
run_options = config_pb2.RunOptions(output_partition_graphs=True)
dump_dir = tempfile.mkdtemp()
debug_url = "file://" + dump_dir
debug_utils.watch_graph(run_options, self.sess.graph, debug_urls=debug_url)
run_metadata = config_pb2.RunMetadata()
self.assertAllClose(2.0, self.sess.run(self.u))
self.sess.run(train_op, options=run_options, run_metadata=run_metadata)
self.assertAllClose(-1.0, self.sess.run(self.u))
dump = debug_data.DebugDumpDir(
dump_dir, partition_graphs=run_metadata.partition_graphs)
dump.set_python_graph(self.sess.graph)
y_grad_values = debug_gradients.gradient_values_from_dump(
grad_debugger, y, dump)
self.assertEqual(1, len(y_grad_values))
self.assertAllClose(10.0, y_grad_values[0])
w_grad_values = debug_gradients.gradient_values_from_dump(
grad_debugger, self.w, dump)
self.assertEqual(1, len(w_grad_values))
self.assertAllClose(10.0, w_grad_values[0])
u_grad_values = debug_gradients.gradient_values_from_dump(
grad_debugger, self.u, dump)
self.assertEqual(1, len(u_grad_values))
self.assertAllClose(30.0, u_grad_values[0])
with self.assertRaisesRegexp(
LookupError,
r"This GradientsDebugger has not received any gradient tensor for "
r"x-tensor v:0"):
debug_gradients.gradient_values_from_dump(grad_debugger, self.v, dump)
# Cleanup.
shutil.rmtree(dump_dir)
if __name__ == "__main__":
googletest.main()
|
apache-2.0
|
[
3,
1898,
9708,
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,
5072,
2295,
367,
3105,
63,
13065,
859,
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,
646,
5145,
199,
646,
5549,
199,
199,
504,
3228,
14,
1018,
14,
7204,
492,
1101,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
7204,
492,
295,
5491,
63,
888,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
576,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
13065,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
1208,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
12661,
63,
5472,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
199,
504,
3228,
14,
1548,
14,
7588,
492,
6709,
63,
26269,
421,
199,
32,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
199,
533,
473,
848,
3338,
9942,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
295,
5491,
63,
888,
275,
295,
5491,
63,
888,
63,
3317,
18,
14,
497,
5491,
2028,
8,
267,
3507,
63,
1238,
63,
28461,
316,
29,
549,
12,
267,
5936,
63,
31405,
29,
264,
5491,
63,
888,
63,
3317,
18,
14,
497,
5491,
2028,
14,
7517,
9,
272,
3343,
63,
1419,
275,
1101,
63,
3317,
18,
14,
4578,
4558,
8,
14366,
63,
1419,
29,
264,
5491,
63,
888,
9,
272,
1101,
275,
1101,
63,
3317,
18,
14,
2028,
8548,
8,
2180,
63,
1419,
29,
2180,
63,
1419,
9,
272,
291,
14,
5480,
275,
2351,
14,
4434,
8,
888,
29,
888,
9,
272,
543,
291,
14,
5480,
14,
305,
63,
885,
837,
489,
291,
14,
85,
275,
2860,
14,
2773,
8,
18,
14,
16,
12,
536,
628,
85,
531,
489,
291,
14,
86,
275,
2860,
14,
2773,
8,
19,
14,
16,
12,
536,
628,
86,
531,
489,
291,
14,
87,
275,
3473,
63,
1483,
14,
13710,
8,
277,
14,
85,
14,
585,
1062,
291,
14,
86,
14,
585,
1062,
536,
628,
87,
531,
819,
347,
6766,
8,
277,
304,
272,
4156,
14,
3958,
63,
885,
63,
2180,
342,
272,
3105,
63,
13065,
14,
3584,
63,
7490,
63,
17612,
83,
342,
819,
347,
511,
17062,
3338,
9942,
39,
7602,
19993,
3861,
1692,
19742,
2988,
8,
277,
304,
272,
7659,
63,
17612,
275,
3105,
63,
13065,
14,
9942,
83,
31521,
342,
272,
1305,
63,
6017,
63,
87,
275,
7659,
63,
17612,
14,
22232,
63,
7490,
8,
277,
14,
87,
9,
272,
612,
275,
3473,
63,
1483,
14,
525,
8,
344,
63,
6017,
63,
87,
12,
446,
17,
14,
16,
12,
536,
628,
89,
531,
339,
18300,
275,
12661,
63,
5472,
14,
13065,
8,
89,
12,
359,
277,
14,
85,
12,
291,
14,
86,
566,
272,
291,
14,
629,
8,
18,
12,
822,
8,
16525,
430,
272,
399,
63,
6017,
275,
18300,
59,
16,
61,
272,
373,
63,
6017,
275,
18300,
59,
17,
61,
339,
291,
14,
5480,
14,
1065,
8,
3669,
14,
2966,
63,
3669,
63,
6498,
1012,
272,
291,
14,
7260,
8,
21,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
89,
430,
272,
291,
14,
7260,
8,
19,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
85,
63,
6017,
430,
272,
291,
14,
7260,
8,
18,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
86,
63,
6017,
430,
339,
327,
16347,
314,
6709,
2345,
543,
314,
671,
13,
3128,
909,
14,
272,
336,
63,
6017,
275,
7659,
63,
17612,
14,
7490,
63,
3128,
8,
277,
14,
87,
9,
272,
291,
14,
6926,
8,
87,
63,
6017,
12,
4156,
14,
3861,
9,
272,
291,
14,
7260,
8,
17,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
87,
63,
6017,
430,
339,
327,
16347,
314,
6709,
2345,
543,
314,
671,
13,
3128,
1159,
536,
14,
272,
336,
63,
6017,
275,
7659,
63,
17612,
14,
7490,
63,
3128,
8,
277,
14,
87,
14,
354,
9,
272,
291,
14,
6926,
8,
87,
63,
6017,
12,
4156,
14,
3861,
9,
272,
291,
14,
7260,
8,
17,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
87,
63,
6017,
430,
339,
327,
16347,
314,
6709,
2345,
543,
314,
671,
13,
3128,
536,
14,
272,
336,
63,
6017,
275,
7659,
63,
17612,
14,
7490,
63,
3128,
8,
277,
14,
87,
14,
354,
9,
272,
291,
14,
6926,
8,
87,
63,
6017,
12,
4156,
14,
3861,
9,
272,
291,
14,
7260,
8,
17,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
87,
63,
6017,
430,
819,
347,
511,
17062,
3338,
9942,
39,
7602,
19993,
3861,
1692,
3007,
52,
70,
9942,
83,
8,
277,
304,
272,
7659,
63,
17612,
275,
3105,
63,
13065,
14,
9942,
83,
31521,
342,
272,
1305,
63,
6017,
63,
87,
275,
7659,
63,
17612,
14,
22232,
63,
7490,
8,
277,
14,
87,
9,
272,
612,
275,
3473,
63,
1483,
14,
525,
8,
344,
63,
6017,
63,
87,
12,
446,
17,
14,
16,
12,
536,
628,
89
] |
[
1898,
9708,
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,
5072,
2295,
367,
3105,
63,
13065,
859,
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,
646,
5145,
199,
646,
5549,
199,
199,
504,
3228,
14,
1018,
14,
7204,
492,
1101,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
7204,
492,
295,
5491,
63,
888,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
576,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
13065,
199,
504,
3228,
14,
1548,
14,
1757,
14,
773,
492,
3105,
63,
1208,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
12661,
63,
5472,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
199,
504,
3228,
14,
1548,
14,
7588,
492,
6709,
63,
26269,
421,
199,
32,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
199,
533,
473,
848,
3338,
9942,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
295,
5491,
63,
888,
275,
295,
5491,
63,
888,
63,
3317,
18,
14,
497,
5491,
2028,
8,
267,
3507,
63,
1238,
63,
28461,
316,
29,
549,
12,
267,
5936,
63,
31405,
29,
264,
5491,
63,
888,
63,
3317,
18,
14,
497,
5491,
2028,
14,
7517,
9,
272,
3343,
63,
1419,
275,
1101,
63,
3317,
18,
14,
4578,
4558,
8,
14366,
63,
1419,
29,
264,
5491,
63,
888,
9,
272,
1101,
275,
1101,
63,
3317,
18,
14,
2028,
8548,
8,
2180,
63,
1419,
29,
2180,
63,
1419,
9,
272,
291,
14,
5480,
275,
2351,
14,
4434,
8,
888,
29,
888,
9,
272,
543,
291,
14,
5480,
14,
305,
63,
885,
837,
489,
291,
14,
85,
275,
2860,
14,
2773,
8,
18,
14,
16,
12,
536,
628,
85,
531,
489,
291,
14,
86,
275,
2860,
14,
2773,
8,
19,
14,
16,
12,
536,
628,
86,
531,
489,
291,
14,
87,
275,
3473,
63,
1483,
14,
13710,
8,
277,
14,
85,
14,
585,
1062,
291,
14,
86,
14,
585,
1062,
536,
628,
87,
531,
819,
347,
6766,
8,
277,
304,
272,
4156,
14,
3958,
63,
885,
63,
2180,
342,
272,
3105,
63,
13065,
14,
3584,
63,
7490,
63,
17612,
83,
342,
819,
347,
511,
17062,
3338,
9942,
39,
7602,
19993,
3861,
1692,
19742,
2988,
8,
277,
304,
272,
7659,
63,
17612,
275,
3105,
63,
13065,
14,
9942,
83,
31521,
342,
272,
1305,
63,
6017,
63,
87,
275,
7659,
63,
17612,
14,
22232,
63,
7490,
8,
277,
14,
87,
9,
272,
612,
275,
3473,
63,
1483,
14,
525,
8,
344,
63,
6017,
63,
87,
12,
446,
17,
14,
16,
12,
536,
628,
89,
531,
339,
18300,
275,
12661,
63,
5472,
14,
13065,
8,
89,
12,
359,
277,
14,
85,
12,
291,
14,
86,
566,
272,
291,
14,
629,
8,
18,
12,
822,
8,
16525,
430,
272,
399,
63,
6017,
275,
18300,
59,
16,
61,
272,
373,
63,
6017,
275,
18300,
59,
17,
61,
339,
291,
14,
5480,
14,
1065,
8,
3669,
14,
2966,
63,
3669,
63,
6498,
1012,
272,
291,
14,
7260,
8,
21,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
89,
430,
272,
291,
14,
7260,
8,
19,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
85,
63,
6017,
430,
272,
291,
14,
7260,
8,
18,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
86,
63,
6017,
430,
339,
327,
16347,
314,
6709,
2345,
543,
314,
671,
13,
3128,
909,
14,
272,
336,
63,
6017,
275,
7659,
63,
17612,
14,
7490,
63,
3128,
8,
277,
14,
87,
9,
272,
291,
14,
6926,
8,
87,
63,
6017,
12,
4156,
14,
3861,
9,
272,
291,
14,
7260,
8,
17,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
87,
63,
6017,
430,
339,
327,
16347,
314,
6709,
2345,
543,
314,
671,
13,
3128,
1159,
536,
14,
272,
336,
63,
6017,
275,
7659,
63,
17612,
14,
7490,
63,
3128,
8,
277,
14,
87,
14,
354,
9,
272,
291,
14,
6926,
8,
87,
63,
6017,
12,
4156,
14,
3861,
9,
272,
291,
14,
7260,
8,
17,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
87,
63,
6017,
430,
339,
327,
16347,
314,
6709,
2345,
543,
314,
671,
13,
3128,
536,
14,
272,
336,
63,
6017,
275,
7659,
63,
17612,
14,
7490,
63,
3128,
8,
277,
14,
87,
14,
354,
9,
272,
291,
14,
6926,
8,
87,
63,
6017,
12,
4156,
14,
3861,
9,
272,
291,
14,
7260,
8,
17,
14,
16,
12,
291,
14,
5480,
14,
1065,
8,
87,
63,
6017,
430,
819,
347,
511,
17062,
3338,
9942,
39,
7602,
19993,
3861,
1692,
3007,
52,
70,
9942,
83,
8,
277,
304,
272,
7659,
63,
17612,
275,
3105,
63,
13065,
14,
9942,
83,
31521,
342,
272,
1305,
63,
6017,
63,
87,
275,
7659,
63,
17612,
14,
22232,
63,
7490,
8,
277,
14,
87,
9,
272,
612,
275,
3473,
63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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
] |
sysalexis/kbengine
|
kbe/src/lib/python/Lib/test/test_asyncio/test_windows_events.py
|
60
|
4592
|
import os
import sys
import unittest
if sys.platform != 'win32':
raise unittest.SkipTest('Windows only')
import _winapi
import asyncio
from asyncio import _overlapped
from asyncio import test_utils
from asyncio import windows_events
class UpperProto(asyncio.Protocol):
def __init__(self):
self.buf = []
def connection_made(self, trans):
self.trans = trans
def data_received(self, data):
self.buf.append(data)
if b'\n' in data:
self.trans.write(b''.join(self.buf).upper())
self.trans.close()
class ProactorTests(test_utils.TestCase):
def setUp(self):
self.loop = asyncio.ProactorEventLoop()
self.set_event_loop(self.loop)
def test_close(self):
a, b = self.loop._socketpair()
trans = self.loop._make_socket_transport(a, asyncio.Protocol())
f = asyncio.async(self.loop.sock_recv(b, 100))
trans.close()
self.loop.run_until_complete(f)
self.assertEqual(f.result(), b'')
b.close()
def test_double_bind(self):
ADDRESS = r'\\.\pipe\test_double_bind-%s' % os.getpid()
server1 = windows_events.PipeServer(ADDRESS)
with self.assertRaises(PermissionError):
windows_events.PipeServer(ADDRESS)
server1.close()
def test_pipe(self):
res = self.loop.run_until_complete(self._test_pipe())
self.assertEqual(res, 'done')
def _test_pipe(self):
ADDRESS = r'\\.\pipe\_test_pipe-%s' % os.getpid()
with self.assertRaises(FileNotFoundError):
yield from self.loop.create_pipe_connection(
asyncio.Protocol, ADDRESS)
[server] = yield from self.loop.start_serving_pipe(
UpperProto, ADDRESS)
self.assertIsInstance(server, windows_events.PipeServer)
clients = []
for i in range(5):
stream_reader = asyncio.StreamReader(loop=self.loop)
protocol = asyncio.StreamReaderProtocol(stream_reader)
trans, proto = yield from self.loop.create_pipe_connection(
lambda: protocol, ADDRESS)
self.assertIsInstance(trans, asyncio.Transport)
self.assertEqual(protocol, proto)
clients.append((stream_reader, trans))
for i, (r, w) in enumerate(clients):
w.write('lower-{}\n'.format(i).encode())
for i, (r, w) in enumerate(clients):
response = yield from r.readline()
self.assertEqual(response, 'LOWER-{}\n'.format(i).encode())
w.close()
server.close()
with self.assertRaises(FileNotFoundError):
yield from self.loop.create_pipe_connection(
asyncio.Protocol, ADDRESS)
return 'done'
def test_wait_for_handle(self):
event = _overlapped.CreateEvent(None, True, False, None)
self.addCleanup(_winapi.CloseHandle, event)
# Wait for unset event with 0.5s timeout;
# result should be False at timeout
fut = self.loop._proactor.wait_for_handle(event, 0.5)
start = self.loop.time()
self.loop.run_until_complete(fut)
elapsed = self.loop.time() - start
self.assertFalse(fut.result())
self.assertTrue(0.48 < elapsed < 0.9, elapsed)
_overlapped.SetEvent(event)
# Wait for for set event;
# result should be True immediately
fut = self.loop._proactor.wait_for_handle(event, 10)
start = self.loop.time()
self.loop.run_until_complete(fut)
elapsed = self.loop.time() - start
self.assertTrue(fut.result())
self.assertTrue(0 <= elapsed < 0.3, elapsed)
# Tulip issue #195: cancelling a done _WaitHandleFuture must not crash
fut.cancel()
def test_wait_for_handle_cancel(self):
event = _overlapped.CreateEvent(None, True, False, None)
self.addCleanup(_winapi.CloseHandle, event)
# Wait for unset event with a cancelled future;
# CancelledError should be raised immediately
fut = self.loop._proactor.wait_for_handle(event, 10)
fut.cancel()
start = self.loop.time()
with self.assertRaises(asyncio.CancelledError):
self.loop.run_until_complete(fut)
elapsed = self.loop.time() - start
self.assertTrue(0 <= elapsed < 0.1, elapsed)
# Tulip issue #195: cancelling a _WaitHandleFuture twice must not crash
fut = self.loop._proactor.wait_for_handle(event)
fut.cancel()
fut.cancel()
if __name__ == '__main__':
unittest.main()
|
lgpl-3.0
|
[
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
692,
984,
14,
3246,
1137,
283,
2676,
708,
356,
272,
746,
2882,
14,
25755,
360,
8647,
1454,
358,
199,
199,
646,
485,
2676,
1246,
199,
199,
646,
16195,
199,
504,
16195,
492,
485,
16736,
1915,
199,
504,
16195,
492,
511,
63,
1208,
199,
504,
16195,
492,
10061,
63,
4368,
421,
199,
533,
4949,
529,
8548,
8,
19343,
14,
3658,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1436,
275,
942,
339,
347,
1950,
63,
29519,
8,
277,
12,
1752,
304,
267,
291,
14,
1515,
275,
1752,
339,
347,
666,
63,
9226,
8,
277,
12,
666,
304,
267,
291,
14,
1436,
14,
740,
8,
576,
9,
267,
340,
330,
1154,
78,
7,
315,
666,
26,
288,
291,
14,
1515,
14,
952,
8,
66,
17067,
904,
8,
277,
14,
1436,
680,
4142,
1012,
288,
291,
14,
1515,
14,
1600,
342,
421,
199,
533,
2165,
5021,
2925,
8,
396,
63,
1208,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3813,
275,
16195,
14,
919,
5021,
2390,
7382,
342,
267,
291,
14,
409,
63,
1430,
63,
3813,
8,
277,
14,
3813,
9,
339,
347,
511,
63,
1600,
8,
277,
304,
267,
282,
12,
330,
275,
291,
14,
3813,
423,
3450,
3852,
342,
267,
1752,
275,
291,
14,
3813,
423,
1875,
63,
3450,
63,
5545,
8,
65,
12,
16195,
14,
3658,
1012,
267,
289,
275,
16195,
14,
4146,
8,
277,
14,
3813,
14,
5096,
63,
7637,
8,
66,
12,
2948,
430,
267,
1752,
14,
1600,
342,
267,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
70,
9,
267,
291,
14,
629,
8,
70,
14,
1099,
1062,
330,
17483,
267,
330,
14,
1600,
342,
339,
347,
511,
63,
3157,
63,
3409,
8,
277,
304,
267,
16271,
4564,
1608,
275,
519,
8124,
3134,
4990,
60,
396,
63,
3157,
63,
3409,
3295,
83,
7,
450,
747,
14,
17829,
342,
267,
1654,
17,
275,
10061,
63,
4368,
14,
11867,
3120,
8,
12368,
9,
267,
543,
291,
14,
1855,
8,
7980,
547,
304,
288,
10061,
63,
4368,
14,
11867,
3120,
8,
12368,
9,
267,
1654,
17,
14,
1600,
342,
339,
347,
511,
63,
4990,
8,
277,
304,
267,
522,
275,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
277,
423,
396,
63,
4990,
1012,
267,
291,
14,
629,
8,
470,
12,
283,
4456,
358,
339,
347,
485,
396,
63,
4990,
8,
277,
304,
267,
16271,
4564,
1608,
275,
519,
8124,
3134,
4990,
60,
63,
396,
63,
4990,
3295,
83,
7,
450,
747,
14,
17829,
342,
398,
543,
291,
14,
1855,
8,
1173,
10870,
304,
288,
1995,
687,
291,
14,
3813,
14,
981,
63,
4990,
63,
2105,
8,
355,
16195,
14,
3658,
12,
16271,
4564,
1608,
9,
398,
359,
1000,
61,
275,
1995,
687,
291,
14,
3813,
14,
928,
63,
14717,
63,
4990,
8,
288,
4949,
529,
8548,
12,
16271,
4564,
1608,
9,
267,
291,
14,
6926,
8,
1000,
12,
10061,
63,
4368,
14,
11867,
3120,
9,
398,
13431,
275,
942,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
2547,
63,
5503,
275,
16195,
14,
16132,
8,
3813,
29,
277,
14,
3813,
9,
288,
4113,
275,
16195,
14,
16132,
3658,
8,
1745,
63,
5503,
9,
288,
1752,
12,
4104,
275,
1995,
687,
291,
14,
3813,
14,
981,
63,
4990,
63,
2105,
8,
355,
2400,
26,
4113,
12,
16271,
4564,
1608,
9,
288,
291,
14,
6926,
8,
1515,
12,
16195,
14,
7836,
9,
288,
291,
14,
629,
8,
3922,
12,
4104,
9,
288,
13431,
14,
740,
1332,
1745,
63,
5503,
12,
1752,
430,
398,
367,
284,
12,
334,
82,
12,
336,
9,
315,
3874,
8,
14555,
304,
288,
336,
14,
952,
360,
2325,
13,
24423,
78,
1370,
908,
8,
73,
680,
2143,
1012,
398,
367,
284,
12,
334,
82,
12,
336,
9,
315,
3874,
8,
14555,
304,
288,
1177,
275,
1995,
687,
519,
14,
6407,
342,
288,
291,
14,
629,
8,
1310,
12,
283,
5896,
540,
13,
24423,
78,
1370,
908,
8,
73,
680,
2143,
1012,
288,
336,
14,
1600,
342,
398,
1654,
14,
1600,
342,
398,
543,
291,
14,
1855,
8,
1173,
10870,
304,
288,
1995,
687,
291,
14,
3813,
14,
981,
63,
4990,
63,
2105,
8,
355,
16195,
14,
3658,
12,
16271,
4564,
1608,
9,
398,
372,
283,
4456,
7,
339,
347,
511,
63,
2573,
63,
509,
63,
2479,
8,
277,
304,
267,
1566,
275,
485,
16736,
1915,
14,
2499,
2390,
8,
403,
12,
715,
12,
756,
12,
488,
9,
267,
291,
14,
12808,
1547,
2676,
1246,
14,
4724,
5940,
12,
1566,
9,
398,
327,
13144,
367,
15376,
1566,
543,
378,
14,
21,
83,
2653,
27,
267,
327,
754,
1077,
506,
756,
737,
2653,
267,
289,
337,
275,
291,
14,
3813,
423,
496,
5021,
14,
2573,
63,
509,
63,
2479,
8,
1430,
12,
378,
14,
21,
9,
267,
1343,
275,
291,
14,
3813,
14,
521,
342,
267,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
70,
337,
9,
267,
14439,
275,
291,
14,
3813,
14,
521,
342,
446,
1343,
267,
291,
14,
3334,
8,
70,
337,
14,
1099,
1012,
267,
291,
14,
1815,
8,
16,
14,
2006,
665,
14439,
665,
378,
14,
25,
12,
14439,
9,
398,
485,
16736,
1915,
14,
1084,
2390,
8,
1430,
9,
398,
327,
13144,
367,
367,
663,
1566,
27,
267,
327,
754,
1077,
506,
715,
9939,
267,
289,
337,
275,
291,
14,
3813,
423,
496,
5021,
14,
2573,
63,
509,
63,
2479,
8,
1430,
12,
1616,
9,
267,
1343,
275,
291,
14,
3813,
14,
521,
342,
267,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
70,
337,
9,
267,
14439,
275,
291,
14,
3813,
14,
521,
342,
446,
1343,
267,
291,
14,
1815,
8,
70,
337,
14,
1099,
1012,
267,
291,
14,
1815,
8,
16,
2695,
14439,
665,
378,
14,
19,
12,
14439,
9,
398,
327,
377,
11294,
4976,
327,
11874,
26,
286,
554,
10564,
282,
4224,
485,
7536,
5940,
14224,
1471,
440,
12420,
267,
289,
337,
14,
6406,
342,
339,
347,
511,
63,
2573,
63,
509,
63,
2479,
63,
6406,
8,
277,
304,
267,
1566,
275,
485,
16736,
1915,
14,
2499,
2390,
8,
403,
12,
715,
12,
756,
12,
488,
9,
267
] |
[
747,
199,
646,
984,
199,
646,
2882,
199,
199,
692,
984,
14,
3246,
1137,
283,
2676,
708,
356,
272,
746,
2882,
14,
25755,
360,
8647,
1454,
358,
199,
199,
646,
485,
2676,
1246,
199,
199,
646,
16195,
199,
504,
16195,
492,
485,
16736,
1915,
199,
504,
16195,
492,
511,
63,
1208,
199,
504,
16195,
492,
10061,
63,
4368,
421,
199,
533,
4949,
529,
8548,
8,
19343,
14,
3658,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1436,
275,
942,
339,
347,
1950,
63,
29519,
8,
277,
12,
1752,
304,
267,
291,
14,
1515,
275,
1752,
339,
347,
666,
63,
9226,
8,
277,
12,
666,
304,
267,
291,
14,
1436,
14,
740,
8,
576,
9,
267,
340,
330,
1154,
78,
7,
315,
666,
26,
288,
291,
14,
1515,
14,
952,
8,
66,
17067,
904,
8,
277,
14,
1436,
680,
4142,
1012,
288,
291,
14,
1515,
14,
1600,
342,
421,
199,
533,
2165,
5021,
2925,
8,
396,
63,
1208,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3813,
275,
16195,
14,
919,
5021,
2390,
7382,
342,
267,
291,
14,
409,
63,
1430,
63,
3813,
8,
277,
14,
3813,
9,
339,
347,
511,
63,
1600,
8,
277,
304,
267,
282,
12,
330,
275,
291,
14,
3813,
423,
3450,
3852,
342,
267,
1752,
275,
291,
14,
3813,
423,
1875,
63,
3450,
63,
5545,
8,
65,
12,
16195,
14,
3658,
1012,
267,
289,
275,
16195,
14,
4146,
8,
277,
14,
3813,
14,
5096,
63,
7637,
8,
66,
12,
2948,
430,
267,
1752,
14,
1600,
342,
267,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
70,
9,
267,
291,
14,
629,
8,
70,
14,
1099,
1062,
330,
17483,
267,
330,
14,
1600,
342,
339,
347,
511,
63,
3157,
63,
3409,
8,
277,
304,
267,
16271,
4564,
1608,
275,
519,
8124,
3134,
4990,
60,
396,
63,
3157,
63,
3409,
3295,
83,
7,
450,
747,
14,
17829,
342,
267,
1654,
17,
275,
10061,
63,
4368,
14,
11867,
3120,
8,
12368,
9,
267,
543,
291,
14,
1855,
8,
7980,
547,
304,
288,
10061,
63,
4368,
14,
11867,
3120,
8,
12368,
9,
267,
1654,
17,
14,
1600,
342,
339,
347,
511,
63,
4990,
8,
277,
304,
267,
522,
275,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
277,
423,
396,
63,
4990,
1012,
267,
291,
14,
629,
8,
470,
12,
283,
4456,
358,
339,
347,
485,
396,
63,
4990,
8,
277,
304,
267,
16271,
4564,
1608,
275,
519,
8124,
3134,
4990,
60,
63,
396,
63,
4990,
3295,
83,
7,
450,
747,
14,
17829,
342,
398,
543,
291,
14,
1855,
8,
1173,
10870,
304,
288,
1995,
687,
291,
14,
3813,
14,
981,
63,
4990,
63,
2105,
8,
355,
16195,
14,
3658,
12,
16271,
4564,
1608,
9,
398,
359,
1000,
61,
275,
1995,
687,
291,
14,
3813,
14,
928,
63,
14717,
63,
4990,
8,
288,
4949,
529,
8548,
12,
16271,
4564,
1608,
9,
267,
291,
14,
6926,
8,
1000,
12,
10061,
63,
4368,
14,
11867,
3120,
9,
398,
13431,
275,
942,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
2547,
63,
5503,
275,
16195,
14,
16132,
8,
3813,
29,
277,
14,
3813,
9,
288,
4113,
275,
16195,
14,
16132,
3658,
8,
1745,
63,
5503,
9,
288,
1752,
12,
4104,
275,
1995,
687,
291,
14,
3813,
14,
981,
63,
4990,
63,
2105,
8,
355,
2400,
26,
4113,
12,
16271,
4564,
1608,
9,
288,
291,
14,
6926,
8,
1515,
12,
16195,
14,
7836,
9,
288,
291,
14,
629,
8,
3922,
12,
4104,
9,
288,
13431,
14,
740,
1332,
1745,
63,
5503,
12,
1752,
430,
398,
367,
284,
12,
334,
82,
12,
336,
9,
315,
3874,
8,
14555,
304,
288,
336,
14,
952,
360,
2325,
13,
24423,
78,
1370,
908,
8,
73,
680,
2143,
1012,
398,
367,
284,
12,
334,
82,
12,
336,
9,
315,
3874,
8,
14555,
304,
288,
1177,
275,
1995,
687,
519,
14,
6407,
342,
288,
291,
14,
629,
8,
1310,
12,
283,
5896,
540,
13,
24423,
78,
1370,
908,
8,
73,
680,
2143,
1012,
288,
336,
14,
1600,
342,
398,
1654,
14,
1600,
342,
398,
543,
291,
14,
1855,
8,
1173,
10870,
304,
288,
1995,
687,
291,
14,
3813,
14,
981,
63,
4990,
63,
2105,
8,
355,
16195,
14,
3658,
12,
16271,
4564,
1608,
9,
398,
372,
283,
4456,
7,
339,
347,
511,
63,
2573,
63,
509,
63,
2479,
8,
277,
304,
267,
1566,
275,
485,
16736,
1915,
14,
2499,
2390,
8,
403,
12,
715,
12,
756,
12,
488,
9,
267,
291,
14,
12808,
1547,
2676,
1246,
14,
4724,
5940,
12,
1566,
9,
398,
327,
13144,
367,
15376,
1566,
543,
378,
14,
21,
83,
2653,
27,
267,
327,
754,
1077,
506,
756,
737,
2653,
267,
289,
337,
275,
291,
14,
3813,
423,
496,
5021,
14,
2573,
63,
509,
63,
2479,
8,
1430,
12,
378,
14,
21,
9,
267,
1343,
275,
291,
14,
3813,
14,
521,
342,
267,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
70,
337,
9,
267,
14439,
275,
291,
14,
3813,
14,
521,
342,
446,
1343,
267,
291,
14,
3334,
8,
70,
337,
14,
1099,
1012,
267,
291,
14,
1815,
8,
16,
14,
2006,
665,
14439,
665,
378,
14,
25,
12,
14439,
9,
398,
485,
16736,
1915,
14,
1084,
2390,
8,
1430,
9,
398,
327,
13144,
367,
367,
663,
1566,
27,
267,
327,
754,
1077,
506,
715,
9939,
267,
289,
337,
275,
291,
14,
3813,
423,
496,
5021,
14,
2573,
63,
509,
63,
2479,
8,
1430,
12,
1616,
9,
267,
1343,
275,
291,
14,
3813,
14,
521,
342,
267,
291,
14,
3813,
14,
1065,
63,
8111,
63,
4883,
8,
70,
337,
9,
267,
14439,
275,
291,
14,
3813,
14,
521,
342,
446,
1343,
267,
291,
14,
1815,
8,
70,
337,
14,
1099,
1012,
267,
291,
14,
1815,
8,
16,
2695,
14439,
665,
378,
14,
19,
12,
14439,
9,
398,
327,
377,
11294,
4976,
327,
11874,
26,
286,
554,
10564,
282,
4224,
485,
7536,
5940,
14224,
1471,
440,
12420,
267,
289,
337,
14,
6406,
342,
339,
347,
511,
63,
2573,
63,
509,
63,
2479,
63,
6406,
8,
277,
304,
267,
1566,
275,
485,
16736,
1915,
14,
2499,
2390,
8,
403,
12,
715,
12,
756,
12,
488,
9,
267,
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,
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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
] |
dezelin/virtualbox
|
src/libs/libxml2-2.6.31/python/tests/build.py
|
87
|
1542
|
#!/usr/bin/python -u
import libxml2
import sys
# Memory debug specific
libxml2.debugMemory(1)
doc = libxml2.newDoc("1.0")
comment = doc.newDocComment("This is a generated document")
doc.addChild(comment)
pi = libxml2.newPI("test", "PI content")
doc.addChild(pi)
root = doc.newChild(None, "doc", None)
ns = root.newNs("http://example.com/doc", "my")
root.setNs(ns)
elem = root.newChild(None, "foo", "bar")
elem.setBase("http://example.com/imgs")
elem.setProp("img", "image.gif")
doc.saveFile("tmp.xml")
doc.freeDoc()
doc = libxml2.parseFile("tmp.xml")
comment = doc.children
if comment.type != "comment" or \
comment.content != "This is a generated document":
print "error rereading comment"
sys.exit(1)
pi = comment.next
if pi.type != "pi" or pi.name != "test" or pi.content != "PI content":
print "error rereading PI"
sys.exit(1)
root = pi.next
if root.name != "doc":
print "error rereading root"
sys.exit(1)
ns = root.ns()
if ns.name != "my" or ns.content != "http://example.com/doc":
print "error rereading namespace"
sys.exit(1)
elem = root.children
if elem.name != "foo":
print "error rereading elem"
sys.exit(1)
if elem.getBase(None) != "http://example.com/imgs":
print "error rereading base"
sys.exit(1)
if elem.prop("img") != "image.gif":
print "error rereading property"
sys.exit(1)
doc.freeDoc()
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
85,
199,
646,
15404,
18,
199,
646,
984,
199,
199,
3,
15825,
3105,
2488,
199,
773,
1652,
18,
14,
1757,
8628,
8,
17,
9,
199,
199,
1301,
275,
15404,
18,
14,
1222,
3768,
480,
17,
14,
16,
531,
199,
3349,
275,
1382,
14,
1222,
3768,
7488,
480,
2765,
365,
282,
4046,
2213,
531,
199,
1301,
14,
23897,
8,
3349,
9,
199,
1038,
275,
15404,
18,
14,
1222,
2252,
480,
396,
401,
298,
2252,
1564,
531,
199,
1301,
14,
23897,
8,
1038,
9,
199,
1231,
275,
1382,
14,
1222,
3493,
8,
403,
12,
298,
1301,
401,
488,
9,
199,
561,
275,
1738,
14,
1222,
2438,
480,
1014,
921,
2694,
14,
957,
15,
1301,
401,
298,
1662,
531,
199,
1231,
14,
409,
2438,
8,
561,
9,
199,
6086,
275,
1738,
14,
1222,
3493,
8,
403,
12,
298,
1421,
401,
298,
1700,
531,
199,
6086,
14,
409,
1563,
480,
1014,
921,
2694,
14,
957,
15,
1017,
458,
531,
199,
6086,
14,
409,
9955,
480,
4060,
401,
298,
1569,
14,
14513,
531,
199,
1301,
14,
2117,
1173,
480,
2791,
14,
1652,
531,
199,
1301,
14,
4624,
3768,
342,
199,
199,
1301,
275,
15404,
18,
14,
1122,
1173,
480,
2791,
14,
1652,
531,
199,
3349,
275,
1382,
14,
3223,
199,
692,
3721,
14,
466,
1137,
298,
3349,
2,
503,
971,
2043,
3721,
14,
1317,
1137,
298,
2765,
365,
282,
4046,
2213,
582,
2043,
870,
298,
705,
295,
19332,
3721,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
1038,
275,
3721,
14,
2184,
199,
692,
6682,
14,
466,
1137,
298,
1038,
2,
503,
6682,
14,
354,
1137,
298,
396,
2,
503,
6682,
14,
1317,
1137,
298,
2252,
1564,
582,
2043,
870,
298,
705,
295,
19332,
16678,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
1231,
275,
6682,
14,
2184,
199,
692,
1738,
14,
354,
1137,
298,
1301,
582,
2043,
870,
298,
705,
295,
19332,
1738,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
561,
275,
1738,
14,
561,
342,
199,
692,
700,
14,
354,
1137,
298,
1662,
2,
503,
700,
14,
1317,
1137,
298,
1014,
921,
2694,
14,
957,
15,
1301,
582,
2043,
870,
298,
705,
295,
19332,
3231,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
6086,
275,
1738,
14,
3223,
199,
692,
6193,
14,
354,
1137,
298,
1421,
582,
2043,
870,
298,
705,
295,
19332,
6193,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
692,
6193,
14,
362,
1563,
8,
403,
9,
1137,
298,
1014,
921,
2694,
14,
957,
15,
1017,
458,
582,
2043,
870,
298,
705,
295,
19332,
1300,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
692,
6193,
14,
4469,
480,
4060,
531,
1137,
298,
1569,
14,
14513,
582,
2043,
870,
298,
705,
295,
19332,
3324,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
199,
1301,
14,
4624,
3768,
342,
199,
199,
3,
15825,
3105,
2488,
199,
773,
1652,
18,
14,
7661,
2842,
342,
199,
692,
15404,
18,
14,
1757,
8628,
8,
17,
9,
508,
378,
26,
272,
870,
298,
3593,
2,
199,
2836,
26,
272,
870,
298,
8628,
25831,
450,
68,
2783,
2,
450,
334,
773,
1652,
18,
14,
1757,
8628,
8,
17,
430,
272,
15404,
18,
14,
2724,
8628,
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
] |
[
2647,
15,
1393,
15,
1548,
446,
85,
199,
646,
15404,
18,
199,
646,
984,
199,
199,
3,
15825,
3105,
2488,
199,
773,
1652,
18,
14,
1757,
8628,
8,
17,
9,
199,
199,
1301,
275,
15404,
18,
14,
1222,
3768,
480,
17,
14,
16,
531,
199,
3349,
275,
1382,
14,
1222,
3768,
7488,
480,
2765,
365,
282,
4046,
2213,
531,
199,
1301,
14,
23897,
8,
3349,
9,
199,
1038,
275,
15404,
18,
14,
1222,
2252,
480,
396,
401,
298,
2252,
1564,
531,
199,
1301,
14,
23897,
8,
1038,
9,
199,
1231,
275,
1382,
14,
1222,
3493,
8,
403,
12,
298,
1301,
401,
488,
9,
199,
561,
275,
1738,
14,
1222,
2438,
480,
1014,
921,
2694,
14,
957,
15,
1301,
401,
298,
1662,
531,
199,
1231,
14,
409,
2438,
8,
561,
9,
199,
6086,
275,
1738,
14,
1222,
3493,
8,
403,
12,
298,
1421,
401,
298,
1700,
531,
199,
6086,
14,
409,
1563,
480,
1014,
921,
2694,
14,
957,
15,
1017,
458,
531,
199,
6086,
14,
409,
9955,
480,
4060,
401,
298,
1569,
14,
14513,
531,
199,
1301,
14,
2117,
1173,
480,
2791,
14,
1652,
531,
199,
1301,
14,
4624,
3768,
342,
199,
199,
1301,
275,
15404,
18,
14,
1122,
1173,
480,
2791,
14,
1652,
531,
199,
3349,
275,
1382,
14,
3223,
199,
692,
3721,
14,
466,
1137,
298,
3349,
2,
503,
971,
2043,
3721,
14,
1317,
1137,
298,
2765,
365,
282,
4046,
2213,
582,
2043,
870,
298,
705,
295,
19332,
3721,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
1038,
275,
3721,
14,
2184,
199,
692,
6682,
14,
466,
1137,
298,
1038,
2,
503,
6682,
14,
354,
1137,
298,
396,
2,
503,
6682,
14,
1317,
1137,
298,
2252,
1564,
582,
2043,
870,
298,
705,
295,
19332,
16678,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
1231,
275,
6682,
14,
2184,
199,
692,
1738,
14,
354,
1137,
298,
1301,
582,
2043,
870,
298,
705,
295,
19332,
1738,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
561,
275,
1738,
14,
561,
342,
199,
692,
700,
14,
354,
1137,
298,
1662,
2,
503,
700,
14,
1317,
1137,
298,
1014,
921,
2694,
14,
957,
15,
1301,
582,
2043,
870,
298,
705,
295,
19332,
3231,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
6086,
275,
1738,
14,
3223,
199,
692,
6193,
14,
354,
1137,
298,
1421,
582,
2043,
870,
298,
705,
295,
19332,
6193,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
692,
6193,
14,
362,
1563,
8,
403,
9,
1137,
298,
1014,
921,
2694,
14,
957,
15,
1017,
458,
582,
2043,
870,
298,
705,
295,
19332,
1300,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
692,
6193,
14,
4469,
480,
4060,
531,
1137,
298,
1569,
14,
14513,
582,
2043,
870,
298,
705,
295,
19332,
3324,
2,
2043,
984,
14,
2224,
8,
17,
9,
199,
199,
1301,
14,
4624,
3768,
342,
199,
199,
3,
15825,
3105,
2488,
199,
773,
1652,
18,
14,
7661,
2842,
342,
199,
692,
15404,
18,
14,
1757,
8628,
8,
17,
9,
508,
378,
26,
272,
870,
298,
3593,
2,
199,
2836,
26,
272,
870,
298,
8628,
25831,
450,
68,
2783,
2,
450,
334,
773,
1652,
18,
14,
1757,
8628,
8,
17,
430,
272,
15404,
18,
14,
2724,
8628,
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,
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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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
] |
miipl-naveen/optibizz
|
addons/subscription/subscription.py
|
337
|
8906
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 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/>.
#
##############################################################################
# TODO:
# Error treatment: exception, request, ... -> send request to user_id
import time
from openerp.osv import fields,osv
from openerp.tools.translate import _
class subscription_document(osv.osv):
_name = "subscription.document"
_description = "Subscription Document"
_columns = {
'name': fields.char('Name', required=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the subscription document without removing it."),
'model': fields.many2one('ir.model', 'Object', required=True),
'field_ids': fields.one2many('subscription.document.fields', 'document_id', 'Fields', copy=True)
}
_defaults = {
'active' : lambda *a: True,
}
class subscription_document_fields(osv.osv):
_name = "subscription.document.fields"
_description = "Subscription Document Fields"
_rec_name = 'field'
_columns = {
'field': fields.many2one('ir.model.fields', 'Field', domain="[('model_id', '=', parent.model)]", required=True),
'value': fields.selection([('false','False'),('date','Current Date')], 'Default Value', size=40, help="Default value is considered for field when new document is generated."),
'document_id': fields.many2one('subscription.document', 'Subscription Document', ondelete='cascade'),
}
_defaults = {}
def _get_document_types(self, cr, uid, context=None):
cr.execute('select m.model, s.name from subscription_document s, ir_model m WHERE s.model = m.id order by s.name')
return cr.fetchall()
class subscription_subscription(osv.osv):
_name = "subscription.subscription"
_description = "Subscription"
_columns = {
'name': fields.char('Name', required=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the subscription without removing it."),
'partner_id': fields.many2one('res.partner', 'Partner'),
'notes': fields.text('Internal Notes'),
'user_id': fields.many2one('res.users', 'User', required=True),
'interval_number': fields.integer('Interval Qty'),
'interval_type': fields.selection([('days', 'Days'), ('weeks', 'Weeks'), ('months', 'Months')], 'Interval Unit'),
'exec_init': fields.integer('Number of documents'),
'date_init': fields.datetime('First Date'),
'state': fields.selection([('draft','Draft'),('running','Running'),('done','Done')], 'Status', copy=False),
'doc_source': fields.reference('Source Document', required=True, selection=_get_document_types, size=128, help="User can choose the source document on which he wants to create documents"),
'doc_lines': fields.one2many('subscription.subscription.history', 'subscription_id', 'Documents created', readonly=True),
'cron_id': fields.many2one('ir.cron', 'Cron Job', help="Scheduler which runs on subscription", states={'running':[('readonly',True)], 'done':[('readonly',True)]}),
'note': fields.text('Notes', help="Description or Summary of Subscription"),
}
_defaults = {
'date_init': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'user_id': lambda obj,cr,uid,context: uid,
'active': lambda *a: True,
'interval_number': lambda *a: 1,
'interval_type': lambda *a: 'months',
'doc_source': lambda *a: False,
'state': lambda *a: 'draft'
}
def _auto_end(self, cr, context=None):
super(subscription_subscription, self)._auto_end(cr, context=context)
# drop the FK from subscription to ir.cron, as it would cause deadlocks
# during cron job execution. When model_copy() tries to write() on the subscription,
# it has to wait for an ExclusiveLock on the cron job record, but the latter
# is locked by the cron system for the duration of the job!
# FIXME: the subscription module should be reviewed to simplify the scheduling process
# and to use a unique cron job for all subscriptions, so that it never needs to
# be updated during its execution.
cr.execute("ALTER TABLE %s DROP CONSTRAINT %s" % (self._table, '%s_cron_id_fkey' % self._table))
def set_process(self, cr, uid, ids, context=None):
for row in self.read(cr, uid, ids, context=context):
mapping = {'name':'name','interval_number':'interval_number','interval_type':'interval_type','exec_init':'numbercall','date_init':'nextcall'}
res = {'model':'subscription.subscription', 'args': repr([[row['id']]]), 'function':'model_copy', 'priority':6, 'user_id':row['user_id'] and row['user_id'][0]}
for key,value in mapping.items():
res[value] = row[key]
id = self.pool.get('ir.cron').create(cr, uid, res)
self.write(cr, uid, [row['id']], {'cron_id':id, 'state':'running'})
return True
def model_copy(self, cr, uid, ids, context=None):
for row in self.read(cr, uid, ids, context=context):
if not row.get('cron_id',False):
continue
cron_ids = [row['cron_id'][0]]
remaining = self.pool.get('ir.cron').read(cr, uid, cron_ids, ['numbercall'])[0]['numbercall']
try:
(model_name, id) = row['doc_source'].split(',')
id = int(id)
model = self.pool[model_name]
except:
raise osv.except_osv(_('Wrong Source Document!'), _('Please provide another source document.\nThis one does not exist!'))
default = {'state':'draft'}
doc_obj = self.pool.get('subscription.document')
document_ids = doc_obj.search(cr, uid, [('model.model','=',model_name)])
doc = doc_obj.browse(cr, uid, document_ids)[0]
for f in doc.field_ids:
if f.value=='date':
value = time.strftime('%Y-%m-%d')
else:
value = False
default[f.field.name] = value
state = 'running'
# if there was only one remaining document to generate
# the subscription is over and we mark it as being done
if remaining == 1:
state = 'done'
id = self.pool[model_name].copy(cr, uid, id, default, context)
self.pool.get('subscription.subscription.history').create(cr, uid, {'subscription_id': row['id'], 'date':time.strftime('%Y-%m-%d %H:%M:%S'), 'document_id': model_name+','+str(id)})
self.write(cr, uid, [row['id']], {'state':state})
return True
def unlink(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids, context or {}):
if record.state=="running":
raise osv.except_osv(_('Error!'),_('You cannot delete an active subscription!'))
return super(subscription_subscription, self).unlink(cr, uid, ids, context)
def set_done(self, cr, uid, ids, context=None):
res = self.read(cr,uid, ids, ['cron_id'])
ids2 = [x['cron_id'][0] for x in res if x['id']]
self.pool.get('ir.cron').write(cr, uid, ids2, {'active':False})
self.write(cr, uid, ids, {'state':'done'})
return True
def set_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state':'draft'})
return True
class subscription_subscription_history(osv.osv):
_name = "subscription.subscription.history"
_description = "Subscription history"
_rec_name = 'date'
_columns = {
'date': fields.datetime('Date'),
'subscription_id': fields.many2one('subscription.subscription', 'Subscription', ondelete='cascade'),
'document_id': fields.reference('Source Document', required=True, selection=_get_document_types, size=128),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
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,
420,
199,
3,
199,
4605,
199,
199,
3,
3254,
26,
199,
3,
257,
4520,
14312,
434,
26,
1919,
12,
1056,
12,
2263,
1035,
3222,
1056,
370,
922,
63,
344,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
1504,
12,
4795,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
9966,
63,
3554,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6645,
14,
3554,
2,
272,
485,
1802,
275,
298,
19120,
7543,
2,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
267,
283,
2682,
356,
1504,
14,
4871,
360,
7472,
297,
1720,
628,
3917,
314,
4702,
901,
365,
663,
370,
756,
12,
652,
911,
2040,
1265,
370,
13714,
314,
9966,
2213,
1928,
12881,
652,
7651,
267,
283,
1238,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
297,
283,
1692,
297,
1415,
29,
549,
395,
267,
283,
698,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
6645,
14,
3554,
14,
955,
297,
283,
3554,
63,
344,
297,
283,
7304,
297,
1331,
29,
549,
9,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
2682,
7,
520,
2400,
627,
65,
26,
715,
12,
272,
789,
199,
199,
533,
9966,
63,
3554,
63,
955,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6645,
14,
3554,
14,
955,
2,
272,
485,
1802,
275,
298,
19120,
7543,
16424,
2,
272,
485,
2761,
63,
354,
275,
283,
698,
7,
272,
485,
3406,
275,
469,
267,
283,
698,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
14,
955,
297,
283,
792,
297,
2881,
628,
19412,
1238,
63,
344,
297,
6291,
1676,
14,
1238,
1874,
401,
1415,
29,
549,
395,
267,
283,
585,
356,
1504,
14,
5592,
8318,
3910,
1673,
797,
8157,
602,
1673,
5639,
6148,
2665,
283,
2698,
1594,
297,
1568,
29,
2167,
12,
1720,
628,
2698,
574,
365,
8652,
367,
901,
1380,
892,
2213,
365,
4046,
7651,
267,
283,
3554,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6645,
14,
3554,
297,
283,
19120,
7543,
297,
16549,
534,
15377,
659,
272,
789,
272,
485,
4322,
275,
1052,
199,
199,
318,
485,
362,
63,
3554,
63,
1313,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
272,
2467,
14,
2526,
360,
2416,
333,
14,
1238,
12,
308,
14,
354,
687,
9966,
63,
3554,
308,
12,
8190,
63,
1238,
333,
6038,
308,
14,
1238,
275,
333,
14,
344,
1865,
701,
308,
14,
354,
358,
272,
372,
2467,
14,
10174,
342,
199,
199,
533,
9966,
63,
6645,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6645,
14,
6645,
2,
272,
485,
1802,
275,
298,
19120,
2,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
267,
283,
2682,
356,
1504,
14,
4871,
360,
7472,
297,
1720,
628,
3917,
314,
4702,
901,
365,
663,
370,
756,
12,
652,
911,
2040,
1265,
370,
13714,
314,
9966,
1928,
12881,
652,
7651,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
24120,
659,
267,
283,
5983,
356,
1504,
14,
505,
360,
8405,
8144,
659,
267,
283,
751,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
1899,
297,
1415,
29,
549,
395,
267,
283,
4284,
63,
1955,
356,
1504,
14,
4115,
360,
8227,
1413,
369,
659,
267,
283,
4284,
63,
466,
356,
1504,
14,
5592,
8318,
4899,
297,
283,
25589,
659,
661,
25287,
297,
283,
20995,
83,
659,
661,
16745,
297,
283,
14306,
83,
2665,
283,
8227,
12008,
659,
267,
283,
1628,
63,
826,
356,
1504,
14,
4115,
360,
3259,
402,
8247,
659,
267,
283,
602,
63,
826,
356,
1504,
14,
2083,
360,
7147,
6148,
659,
267,
283,
929,
356,
1504,
14,
5592,
8318,
7185,
1673,
18332,
8157,
5720,
1673,
9602,
8157,
4456,
1673,
10759,
2665,
283,
3694,
297,
1331,
29,
797,
395,
267,
283,
1301,
63,
1365,
356,
1504,
14,
4443,
360,
2980,
7543,
297,
1415,
29,
549,
12,
7267,
3699,
362,
63,
3554,
63,
1313,
12,
1568,
29,
3933,
12,
1720,
628,
1899,
883,
11496,
314,
1350,
2213,
641,
1314,
946,
15061,
370,
1218,
8247,
1288,
267,
283,
1301,
63,
1278,
356,
1504,
14,
368,
18,
3479,
360,
6645,
14,
6645,
14,
5570,
297,
283,
6645,
63,
344,
297,
283,
26872,
2737,
297,
6863,
29,
549,
395,
267,
283,
14829,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
14829,
297,
283,
35,
2641,
15057,
297,
1720,
628,
11251,
1314,
7858,
641,
9966,
401,
6363,
3713,
5720,
30536,
6753,
297,
549,
4360,
283,
4456,
30536,
6753,
297,
549,
29609,
267,
283,
4610,
356,
1504,
14,
505,
360,
18685,
297,
1720,
628,
5831,
503,
22486,
402,
29763,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
602,
63,
826,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
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,
420,
199,
3,
199,
4605,
199,
199,
3,
3254,
26,
199,
3,
257,
4520,
14312,
434,
26,
1919,
12,
1056,
12,
2263,
1035,
3222,
1056,
370,
922,
63,
344,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
1504,
12,
4795,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
9966,
63,
3554,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6645,
14,
3554,
2,
272,
485,
1802,
275,
298,
19120,
7543,
2,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
267,
283,
2682,
356,
1504,
14,
4871,
360,
7472,
297,
1720,
628,
3917,
314,
4702,
901,
365,
663,
370,
756,
12,
652,
911,
2040,
1265,
370,
13714,
314,
9966,
2213,
1928,
12881,
652,
7651,
267,
283,
1238,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
297,
283,
1692,
297,
1415,
29,
549,
395,
267,
283,
698,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
6645,
14,
3554,
14,
955,
297,
283,
3554,
63,
344,
297,
283,
7304,
297,
1331,
29,
549,
9,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
2682,
7,
520,
2400,
627,
65,
26,
715,
12,
272,
789,
199,
199,
533,
9966,
63,
3554,
63,
955,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6645,
14,
3554,
14,
955,
2,
272,
485,
1802,
275,
298,
19120,
7543,
16424,
2,
272,
485,
2761,
63,
354,
275,
283,
698,
7,
272,
485,
3406,
275,
469,
267,
283,
698,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
1238,
14,
955,
297,
283,
792,
297,
2881,
628,
19412,
1238,
63,
344,
297,
6291,
1676,
14,
1238,
1874,
401,
1415,
29,
549,
395,
267,
283,
585,
356,
1504,
14,
5592,
8318,
3910,
1673,
797,
8157,
602,
1673,
5639,
6148,
2665,
283,
2698,
1594,
297,
1568,
29,
2167,
12,
1720,
628,
2698,
574,
365,
8652,
367,
901,
1380,
892,
2213,
365,
4046,
7651,
267,
283,
3554,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6645,
14,
3554,
297,
283,
19120,
7543,
297,
16549,
534,
15377,
659,
272,
789,
272,
485,
4322,
275,
1052,
199,
199,
318,
485,
362,
63,
3554,
63,
1313,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
272,
2467,
14,
2526,
360,
2416,
333,
14,
1238,
12,
308,
14,
354,
687,
9966,
63,
3554,
308,
12,
8190,
63,
1238,
333,
6038,
308,
14,
1238,
275,
333,
14,
344,
1865,
701,
308,
14,
354,
358,
272,
372,
2467,
14,
10174,
342,
199,
199,
533,
9966,
63,
6645,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6645,
14,
6645,
2,
272,
485,
1802,
275,
298,
19120,
2,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
267,
283,
2682,
356,
1504,
14,
4871,
360,
7472,
297,
1720,
628,
3917,
314,
4702,
901,
365,
663,
370,
756,
12,
652,
911,
2040,
1265,
370,
13714,
314,
9966,
1928,
12881,
652,
7651,
267,
283,
3899,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3899,
297,
283,
24120,
659,
267,
283,
5983,
356,
1504,
14,
505,
360,
8405,
8144,
659,
267,
283,
751,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
1899,
297,
1415,
29,
549,
395,
267,
283,
4284,
63,
1955,
356,
1504,
14,
4115,
360,
8227,
1413,
369,
659,
267,
283,
4284,
63,
466,
356,
1504,
14,
5592,
8318,
4899,
297,
283,
25589,
659,
661,
25287,
297,
283,
20995,
83,
659,
661,
16745,
297,
283,
14306,
83,
2665,
283,
8227,
12008,
659,
267,
283,
1628,
63,
826,
356,
1504,
14,
4115,
360,
3259,
402,
8247,
659,
267,
283,
602,
63,
826,
356,
1504,
14,
2083,
360,
7147,
6148,
659,
267,
283,
929,
356,
1504,
14,
5592,
8318,
7185,
1673,
18332,
8157,
5720,
1673,
9602,
8157,
4456,
1673,
10759,
2665,
283,
3694,
297,
1331,
29,
797,
395,
267,
283,
1301,
63,
1365,
356,
1504,
14,
4443,
360,
2980,
7543,
297,
1415,
29,
549,
12,
7267,
3699,
362,
63,
3554,
63,
1313,
12,
1568,
29,
3933,
12,
1720,
628,
1899,
883,
11496,
314,
1350,
2213,
641,
1314,
946,
15061,
370,
1218,
8247,
1288,
267,
283,
1301,
63,
1278,
356,
1504,
14,
368,
18,
3479,
360,
6645,
14,
6645,
14,
5570,
297,
283,
6645,
63,
344,
297,
283,
26872,
2737,
297,
6863,
29,
549,
395,
267,
283,
14829,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
723,
14,
14829,
297,
283,
35,
2641,
15057,
297,
1720,
628,
11251,
1314,
7858,
641,
9966,
401,
6363,
3713,
5720,
30536,
6753,
297,
549,
4360,
283,
4456,
30536,
6753,
297,
549,
29609,
267,
283,
4610,
356,
1504,
14,
505,
360,
18685,
297,
1720,
628,
5831,
503,
22486,
402,
29763,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
602,
63,
826,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
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,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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
] |
gunzy83/ansible-modules-extras
|
cloud/amazon/sns_topic.py
|
33
|
13805
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# This is a 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 Ansible 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = """
module: sns_topic
short_description: Manages AWS SNS topics and subscriptions
description:
- The M(sns_topic) module allows you to create, delete, and manage subscriptions for AWS SNS topics.
version_added: 2.0
author:
- "Joel Thompson (@joelthompson)"
- "Fernando Jose Pando (@nand0p)"
options:
name:
description:
- The name or ARN of the SNS topic to converge
required: True
state:
description:
- Whether to create or destroy an SNS topic
required: False
default: present
choices: ["absent", "present"]
display_name:
description:
- Display name of the topic
required: False
default: None
policy:
description:
- Policy to apply to the SNS topic
required: False
default: None
delivery_policy:
description:
- Delivery policy to apply to the SNS topic
required: False
default: None
subscriptions:
description:
- List of subscriptions to apply to the topic. Note that AWS requires
subscriptions to be confirmed, so you will need to confirm any new
subscriptions.
required: False
default: []
purge_subscriptions:
description:
- "Whether to purge any subscriptions not listed here. NOTE: AWS does not
allow you to purge any PendingConfirmation subscriptions, so if any
exist and would be purged, they are silently skipped. This means that
somebody could come back later and confirm the subscription. Sorry.
Blame Amazon."
required: False
default: True
extends_documentation_fragment: aws
requirements: [ "boto" ]
"""
EXAMPLES = """
- name: Create alarm SNS topic
sns_topic:
name: "alarms"
state: present
display_name: "alarm SNS topic"
delivery_policy:
http:
defaultHealthyRetryPolicy:
minDelayTarget: 2
maxDelayTarget: 4
numRetries: 3
numMaxDelayRetries: 5
backoffFunction: "<linear|arithmetic|geometric|exponential>"
disableSubscriptionOverrides: True
defaultThrottlePolicy:
maxReceivesPerSecond: 10
subscriptions:
- endpoint: "my_email_address@example.com"
protocol: "email"
- endpoint: "my_mobile_number"
protocol: "sms"
"""
RETURN = '''
sns_arn:
description: The ARN of the topic you are modifying
type: string
sample: "arn:aws:sns:us-east-1:123456789012:my_topic_name"
sns_topic:
description: Dict of sns topic details
type: dict
sample:
name: sns-topic-name
state: present
display_name: default
policy: {}
delivery_policy: {}
subscriptions_new: []
subscriptions_existing: []
subscriptions_deleted: []
subscriptions_added: []
subscriptions_purge': false
check_mode: false
topic_created: false
topic_deleted: false
attributes_set: []
'''
import sys
import time
import json
import re
try:
import boto.sns
from boto.exception import BotoServerError
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
class SnsTopicManager(object):
""" Handles SNS Topic creation and destruction """
def __init__(self,
module,
name,
state,
display_name,
policy,
delivery_policy,
subscriptions,
purge_subscriptions,
check_mode,
region,
**aws_connect_params):
self.region = region
self.aws_connect_params = aws_connect_params
self.connection = self._get_boto_connection()
self.changed = False
self.module = module
self.name = name
self.state = state
self.display_name = display_name
self.policy = policy
self.delivery_policy = delivery_policy
self.subscriptions = subscriptions
self.subscriptions_existing = []
self.subscriptions_deleted = []
self.subscriptions_added = []
self.purge_subscriptions = purge_subscriptions
self.check_mode = check_mode
self.topic_created = False
self.topic_deleted = False
self.arn_topic = None
self.attributes_set = []
def _get_boto_connection(self):
try:
return connect_to_aws(boto.sns, self.region,
**self.aws_connect_params)
except BotoServerError, err:
self.module.fail_json(msg=err.message)
def _get_all_topics(self):
next_token = None
topics = []
while True:
try:
response = self.connection.get_all_topics(next_token)
except BotoServerError, err:
module.fail_json(msg=err.message)
topics.extend(response['ListTopicsResponse']['ListTopicsResult']['Topics'])
next_token = response['ListTopicsResponse']['ListTopicsResult']['NextToken']
if not next_token:
break
return [t['TopicArn'] for t in topics]
def _arn_topic_lookup(self):
# topic names cannot have colons, so this captures the full topic name
all_topics = self._get_all_topics()
lookup_topic = ':%s' % self.name
for topic in all_topics:
if topic.endswith(lookup_topic):
return topic
def _create_topic(self):
self.changed = True
self.topic_created = True
if not self.check_mode:
self.connection.create_topic(self.name)
self.arn_topic = self._arn_topic_lookup()
while not self.arn_topic:
time.sleep(3)
self.arn_topic = self._arn_topic_lookup()
def _set_topic_attrs(self):
topic_attributes = self.connection.get_topic_attributes(self.arn_topic) \
['GetTopicAttributesResponse'] ['GetTopicAttributesResult'] \
['Attributes']
if self.display_name and self.display_name != topic_attributes['DisplayName']:
self.changed = True
self.attributes_set.append('display_name')
if not self.check_mode:
self.connection.set_topic_attributes(self.arn_topic, 'DisplayName',
self.display_name)
if self.policy and self.policy != json.loads(topic_attributes['Policy']):
self.changed = True
self.attributes_set.append('policy')
if not self.check_mode:
self.connection.set_topic_attributes(self.arn_topic, 'Policy',
json.dumps(self.policy))
if self.delivery_policy and ('DeliveryPolicy' not in topic_attributes or \
self.delivery_policy != json.loads(topic_attributes['DeliveryPolicy'])):
self.changed = True
self.attributes_set.append('delivery_policy')
if not self.check_mode:
self.connection.set_topic_attributes(self.arn_topic, 'DeliveryPolicy',
json.dumps(self.delivery_policy))
def _canonicalize_endpoint(self, protocol, endpoint):
if protocol == 'sms':
return re.sub('[^0-9]*', '', endpoint)
return endpoint
def _get_topic_subs(self):
next_token = None
while True:
response = self.connection.get_all_subscriptions_by_topic(self.arn_topic, next_token)
self.subscriptions_existing.extend(response['ListSubscriptionsByTopicResponse'] \
['ListSubscriptionsByTopicResult']['Subscriptions'])
next_token = response['ListSubscriptionsByTopicResponse'] \
['ListSubscriptionsByTopicResult']['NextToken']
if not next_token:
break
def _set_topic_subs(self):
subscriptions_existing_list = []
desired_subscriptions = [(sub['protocol'],
self._canonicalize_endpoint(sub['protocol'], sub['endpoint'])) for sub in
self.subscriptions]
if self.subscriptions_existing:
for sub in self.subscriptions_existing:
sub_key = (sub['Protocol'], sub['Endpoint'])
subscriptions_existing_list.append(sub_key)
if self.purge_subscriptions and sub_key not in desired_subscriptions and \
sub['SubscriptionArn'] != 'PendingConfirmation':
self.changed = True
self.subscriptions_deleted.append(sub_key)
if not self.check_mode:
self.connection.unsubscribe(sub['SubscriptionArn'])
for (protocol, endpoint) in desired_subscriptions:
if (protocol, endpoint) not in subscriptions_existing_list:
self.changed = True
self.subscriptions_added.append(sub)
if not self.check_mode:
self.connection.subscribe(self.arn_topic, protocol, endpoint)
def _delete_subscriptions(self):
# NOTE: subscriptions in 'PendingConfirmation' timeout in 3 days
# https://forums.aws.amazon.com/thread.jspa?threadID=85993
for sub in self.subscriptions_existing:
if sub['SubscriptionArn'] != 'PendingConfirmation':
self.subscriptions_deleted.append(sub['SubscriptionArn'])
self.changed = True
if not self.check_mode:
self.connection.unsubscribe(sub['SubscriptionArn'])
def _delete_topic(self):
self.topic_deleted = True
self.changed = True
if not self.check_mode:
self.connection.delete_topic(self.arn_topic)
def ensure_ok(self):
self.arn_topic = self._arn_topic_lookup()
if not self.arn_topic:
self._create_topic()
self._set_topic_attrs()
self._get_topic_subs()
self._set_topic_subs()
def ensure_gone(self):
self.arn_topic = self._arn_topic_lookup()
if self.arn_topic:
self._get_topic_subs()
if self.subscriptions_existing:
self._delete_subscriptions()
self._delete_topic()
def get_info(self):
info = {
'name': self.name,
'state': self.state,
'display_name': self.display_name,
'policy': self.policy,
'delivery_policy': self.delivery_policy,
'subscriptions_new': self.subscriptions,
'subscriptions_existing': self.subscriptions_existing,
'subscriptions_deleted': self.subscriptions_deleted,
'subscriptions_added': self.subscriptions_added,
'subscriptions_purge': self.purge_subscriptions,
'check_mode': self.check_mode,
'topic_created': self.topic_created,
'topic_deleted': self.topic_deleted,
'attributes_set': self.attributes_set
}
return info
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(
dict(
name=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['present',
'absent']),
display_name=dict(type='str', required=False),
policy=dict(type='dict', required=False),
delivery_policy=dict(type='dict', required=False),
subscriptions=dict(default=[], type='list', required=False),
purge_subscriptions=dict(type='bool', default=True),
)
)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
if not HAS_BOTO:
module.fail_json(msg='boto required for this module')
name = module.params.get('name')
state = module.params.get('state')
display_name = module.params.get('display_name')
policy = module.params.get('policy')
delivery_policy = module.params.get('delivery_policy')
subscriptions = module.params.get('subscriptions')
purge_subscriptions = module.params.get('purge_subscriptions')
check_mode = module.check_mode
region, ec2_url, aws_connect_params = get_aws_connection_info(module)
if not region:
module.fail_json(msg="region must be specified")
sns_topic = SnsTopicManager(module,
name,
state,
display_name,
policy,
delivery_policy,
subscriptions,
purge_subscriptions,
check_mode,
region,
**aws_connect_params)
if state == 'present':
sns_topic.ensure_ok()
elif state == 'absent':
sns_topic.ensure_gone()
sns_facts = dict(changed=sns_topic.changed,
sns_arn=sns_topic.arn_topic,
sns_topic=sns_topic.get_info())
module.exit_json(**sns_facts)
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
365,
282,
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,
961,
2622,
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,
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,
3555,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
8948,
275,
408,
199,
578,
26,
308,
561,
63,
5746,
199,
3612,
63,
1802,
26,
21612,
10168,
428,
2709,
17398,
436,
25708,
199,
1802,
26,
272,
446,
710,
603,
8,
83,
561,
63,
5746,
9,
859,
6127,
1265,
370,
1218,
12,
3145,
12,
436,
9635,
25708,
367,
10168,
428,
2709,
17398,
14,
199,
1023,
63,
3270,
26,
499,
14,
16,
199,
2502,
26,
523,
446,
298,
5691,
352,
18049,
311,
834,
8593,
743,
352,
273,
22527,
834,
2924,
523,
446,
298,
38,
27569,
22066,
1603,
3362,
510,
22066,
8593,
78,
460,
16,
80,
2924,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
503,
4160,
46,
402,
314,
428,
2709,
7482,
370,
3818,
303,
272,
1415,
26,
715,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
1218,
503,
11972,
376,
428,
2709,
7482,
272,
1415,
26,
756,
272,
849,
26,
3451,
272,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
523,
2929,
63,
354,
26,
272,
1369,
26,
489,
446,
12175,
536,
402,
314,
7482,
272,
1415,
26,
756,
272,
849,
26,
488,
523,
4592,
26,
272,
1369,
26,
489,
446,
18141,
370,
4838,
370,
314,
428,
2709,
7482,
272,
1415,
26,
756,
272,
849,
26,
488,
523,
18719,
63,
3185,
26,
272,
1369,
26,
489,
446,
1487,
317,
2588,
4592,
370,
4838,
370,
314,
428,
2709,
7482,
272,
1415,
26,
756,
272,
849,
26,
488,
523,
25708,
26,
272,
1369,
26,
489,
446,
3820,
402,
25708,
370,
4838,
370,
314,
7482,
14,
3390,
626,
10168,
5074,
267,
25708,
370,
506,
22763,
12,
880,
1265,
911,
1929,
370,
12679,
1263,
892,
267,
25708,
14,
272,
1415,
26,
756,
272,
849,
26,
942,
523,
18503,
63,
13233,
26,
272,
1369,
26,
489,
446,
298,
26625,
370,
18503,
1263,
25708,
440,
10532,
2348,
14,
6944,
26,
10168,
1630,
440,
267,
2040,
1265,
370,
18503,
1263,
29216,
714,
11701,
25708,
12,
880,
340,
1263,
267,
2187,
436,
3955,
506,
5861,
3046,
12,
2985,
787,
18030,
9645,
14,
961,
4910,
626,
267,
2005,
2030,
4293,
11492,
1771,
2945,
436,
12679,
314,
9966,
14,
428,
21342,
14,
267,
699,
76,
313,
14347,
2122,
272,
1415,
26,
756,
272,
849,
26,
715,
199,
11036,
63,
9970,
63,
7677,
26,
11488,
199,
7538,
26,
359,
298,
10914,
2,
1622,
199,
624,
199,
199,
8918,
275,
408,
199,
199,
13,
536,
26,
2790,
17987,
428,
2709,
7482,
523,
308,
561,
63,
5746,
26,
272,
536,
26,
298,
279,
25005,
2,
272,
1174,
26,
3451,
272,
2929,
63,
354,
26,
298,
14160,
428,
2709,
7482,
2,
272,
18719,
63,
3185,
26,
15166,
1455,
26,
267,
849,
18850,
89,
12989,
4845,
26,
7205,
1748,
10796,
4277,
26,
499,
288,
1390,
10796,
4277,
26,
841,
288,
1967,
32720,
26,
650,
288,
1967,
4261,
10796,
32720,
26,
959,
288,
22735,
3481,
26,
3886,
6676,
92,
18327,
15307,
92,
31509,
92,
27093,
4335,
267,
3507,
19120,
27586,
26,
715,
267,
849,
26192,
4845,
26,
7205,
1390,
497,
2375,
397,
2623,
11906,
26,
1616,
272,
25708,
26,
489,
446,
6037,
26,
298,
1662,
63,
2123,
63,
1562,
32,
2694,
14,
957,
2,
267,
4113,
26,
298,
2123,
2,
489,
446,
6037,
26,
298,
1662,
63,
11375,
63,
1955,
2,
267,
4113,
26,
298,
18751,
2,
199,
199,
624,
199,
199,
9677,
275,
1449,
199,
83,
561,
63,
1060,
26,
272,
1369,
26,
710,
4160,
46,
402,
314,
7482,
1265,
787,
24662,
272,
730,
26,
1059,
272,
2690,
26,
298,
1060,
26,
7231,
26,
83,
561,
26,
527,
13,
14346,
13,
17,
26,
11272,
11533,
26,
1662,
63,
5746,
63,
354,
2,
199,
199,
83,
561,
63,
5746,
26,
272,
1369,
26,
7448,
402,
308,
561,
7482,
2436,
272,
730,
26,
1211,
272,
2690,
26,
489,
536,
26,
308,
561,
13,
5746,
13,
354,
489,
1174,
26,
3451,
489,
2929,
63,
354,
26,
849,
489,
4592,
26,
1052,
489,
18719,
63,
3185,
26,
1052,
489,
25708,
63,
1222,
26,
942,
489,
25708,
63,
5952,
26,
942,
489,
25708,
63,
6062,
26,
942,
489,
25708,
63,
3270,
26,
942,
489,
25708,
63,
18254,
356,
3055,
489,
1104,
63,
632,
26,
3055,
489,
7482,
63,
3966,
26,
3055,
489,
7482,
63,
6062,
26,
3055,
489,
3004,
63,
409,
26,
942,
199,
2344,
199,
199,
646,
984,
199,
646,
900,
199,
646,
2022,
199,
646,
295,
199,
199,
893,
26,
272,
492,
6055,
14,
83,
561,
272,
687,
6055,
14,
1971,
492,
24411,
17692,
272,
7509,
63,
21373,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
21373,
275,
756,
421,
199,
533,
428,
561,
12157,
2988,
8,
785,
304,
272,
408,
23873,
428,
2709,
32166,
7143,
436,
477,
4742,
408,
339,
347,
636,
826,
721,
277,
12,
326,
859,
12,
326,
536,
12,
326,
1174,
12,
326,
2929,
63,
354,
12,
326,
4592,
12,
326,
18719,
63,
3185,
12,
326,
25708,
12,
326,
18503,
63,
13233,
12,
326,
1104,
63,
632,
12,
326,
4897,
12,
326,
1011,
7231,
63,
2242,
63,
1162,
304,
398,
291,
14,
4551,
275,
4897,
267,
291,
14,
7231,
63,
2242,
63,
1162,
275,
11488,
63,
2242,
63,
1162,
267,
291,
14,
2105,
275,
291,
423,
362,
63,
10914,
63,
2105,
342
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
365,
282,
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,
961,
2622,
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,
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,
3555,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
8948,
275,
408,
199,
578,
26,
308,
561,
63,
5746,
199,
3612,
63,
1802,
26,
21612,
10168,
428,
2709,
17398,
436,
25708,
199,
1802,
26,
272,
446,
710,
603,
8,
83,
561,
63,
5746,
9,
859,
6127,
1265,
370,
1218,
12,
3145,
12,
436,
9635,
25708,
367,
10168,
428,
2709,
17398,
14,
199,
1023,
63,
3270,
26,
499,
14,
16,
199,
2502,
26,
523,
446,
298,
5691,
352,
18049,
311,
834,
8593,
743,
352,
273,
22527,
834,
2924,
523,
446,
298,
38,
27569,
22066,
1603,
3362,
510,
22066,
8593,
78,
460,
16,
80,
2924,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
503,
4160,
46,
402,
314,
428,
2709,
7482,
370,
3818,
303,
272,
1415,
26,
715,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
1218,
503,
11972,
376,
428,
2709,
7482,
272,
1415,
26,
756,
272,
849,
26,
3451,
272,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
523,
2929,
63,
354,
26,
272,
1369,
26,
489,
446,
12175,
536,
402,
314,
7482,
272,
1415,
26,
756,
272,
849,
26,
488,
523,
4592,
26,
272,
1369,
26,
489,
446,
18141,
370,
4838,
370,
314,
428,
2709,
7482,
272,
1415,
26,
756,
272,
849,
26,
488,
523,
18719,
63,
3185,
26,
272,
1369,
26,
489,
446,
1487,
317,
2588,
4592,
370,
4838,
370,
314,
428,
2709,
7482,
272,
1415,
26,
756,
272,
849,
26,
488,
523,
25708,
26,
272,
1369,
26,
489,
446,
3820,
402,
25708,
370,
4838,
370,
314,
7482,
14,
3390,
626,
10168,
5074,
267,
25708,
370,
506,
22763,
12,
880,
1265,
911,
1929,
370,
12679,
1263,
892,
267,
25708,
14,
272,
1415,
26,
756,
272,
849,
26,
942,
523,
18503,
63,
13233,
26,
272,
1369,
26,
489,
446,
298,
26625,
370,
18503,
1263,
25708,
440,
10532,
2348,
14,
6944,
26,
10168,
1630,
440,
267,
2040,
1265,
370,
18503,
1263,
29216,
714,
11701,
25708,
12,
880,
340,
1263,
267,
2187,
436,
3955,
506,
5861,
3046,
12,
2985,
787,
18030,
9645,
14,
961,
4910,
626,
267,
2005,
2030,
4293,
11492,
1771,
2945,
436,
12679,
314,
9966,
14,
428,
21342,
14,
267,
699,
76,
313,
14347,
2122,
272,
1415,
26,
756,
272,
849,
26,
715,
199,
11036,
63,
9970,
63,
7677,
26,
11488,
199,
7538,
26,
359,
298,
10914,
2,
1622,
199,
624,
199,
199,
8918,
275,
408,
199,
199,
13,
536,
26,
2790,
17987,
428,
2709,
7482,
523,
308,
561,
63,
5746,
26,
272,
536,
26,
298,
279,
25005,
2,
272,
1174,
26,
3451,
272,
2929,
63,
354,
26,
298,
14160,
428,
2709,
7482,
2,
272,
18719,
63,
3185,
26,
15166,
1455,
26,
267,
849,
18850,
89,
12989,
4845,
26,
7205,
1748,
10796,
4277,
26,
499,
288,
1390,
10796,
4277,
26,
841,
288,
1967,
32720,
26,
650,
288,
1967,
4261,
10796,
32720,
26,
959,
288,
22735,
3481,
26,
3886,
6676,
92,
18327,
15307,
92,
31509,
92,
27093,
4335,
267,
3507,
19120,
27586,
26,
715,
267,
849,
26192,
4845,
26,
7205,
1390,
497,
2375,
397,
2623,
11906,
26,
1616,
272,
25708,
26,
489,
446,
6037,
26,
298,
1662,
63,
2123,
63,
1562,
32,
2694,
14,
957,
2,
267,
4113,
26,
298,
2123,
2,
489,
446,
6037,
26,
298,
1662,
63,
11375,
63,
1955,
2,
267,
4113,
26,
298,
18751,
2,
199,
199,
624,
199,
199,
9677,
275,
1449,
199,
83,
561,
63,
1060,
26,
272,
1369,
26,
710,
4160,
46,
402,
314,
7482,
1265,
787,
24662,
272,
730,
26,
1059,
272,
2690,
26,
298,
1060,
26,
7231,
26,
83,
561,
26,
527,
13,
14346,
13,
17,
26,
11272,
11533,
26,
1662,
63,
5746,
63,
354,
2,
199,
199,
83,
561,
63,
5746,
26,
272,
1369,
26,
7448,
402,
308,
561,
7482,
2436,
272,
730,
26,
1211,
272,
2690,
26,
489,
536,
26,
308,
561,
13,
5746,
13,
354,
489,
1174,
26,
3451,
489,
2929,
63,
354,
26,
849,
489,
4592,
26,
1052,
489,
18719,
63,
3185,
26,
1052,
489,
25708,
63,
1222,
26,
942,
489,
25708,
63,
5952,
26,
942,
489,
25708,
63,
6062,
26,
942,
489,
25708,
63,
3270,
26,
942,
489,
25708,
63,
18254,
356,
3055,
489,
1104,
63,
632,
26,
3055,
489,
7482,
63,
3966,
26,
3055,
489,
7482,
63,
6062,
26,
3055,
489,
3004,
63,
409,
26,
942,
199,
2344,
199,
199,
646,
984,
199,
646,
900,
199,
646,
2022,
199,
646,
295,
199,
199,
893,
26,
272,
492,
6055,
14,
83,
561,
272,
687,
6055,
14,
1971,
492,
24411,
17692,
272,
7509,
63,
21373,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
21373,
275,
756,
421,
199,
533,
428,
561,
12157,
2988,
8,
785,
304,
272,
408,
23873,
428,
2709,
32166,
7143,
436,
477,
4742,
408,
339,
347,
636,
826,
721,
277,
12,
326,
859,
12,
326,
536,
12,
326,
1174,
12,
326,
2929,
63,
354,
12,
326,
4592,
12,
326,
18719,
63,
3185,
12,
326,
25708,
12,
326,
18503,
63,
13233,
12,
326,
1104,
63,
632,
12,
326,
4897,
12,
326,
1011,
7231,
63,
2242,
63,
1162,
304,
398,
291,
14,
4551,
275,
4897,
267,
291,
14,
7231,
63,
2242,
63,
1162,
275,
11488,
63,
2242,
63,
1162,
267,
291,
14,
2105,
275,
291,
423,
362,
63,
10914,
63,
2105,
342,
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,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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
] |
logonod/sshuttle
|
server.py
|
13
|
7434
|
import re, struct, socket, select, traceback, time
if not globals().get('skip_imports'):
import ssnet, helpers, hostwatch
import compat.ssubprocess as ssubprocess
from ssnet import SockWrapper, Handler, Proxy, Mux, MuxWrapper
from helpers import *
def _ipmatch(ipstr):
if ipstr == 'default':
ipstr = '0.0.0.0/0'
m = re.match(r'^(\d+(\.\d+(\.\d+(\.\d+)?)?)?)(?:/(\d+))?$', ipstr)
if m:
g = m.groups()
ips = g[0]
width = int(g[4] or 32)
if g[1] == None:
ips += '.0.0.0'
width = min(width, 8)
elif g[2] == None:
ips += '.0.0'
width = min(width, 16)
elif g[3] == None:
ips += '.0'
width = min(width, 24)
return (struct.unpack('!I', socket.inet_aton(ips))[0], width)
def _ipstr(ip, width):
if width >= 32:
return ip
else:
return "%s/%d" % (ip, width)
def _maskbits(netmask):
if not netmask:
return 32
for i in range(32):
if netmask[0] & shl(1, i):
return 32-i
return 0
def _list_routes():
argv = ['netstat', '-rn']
p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE)
routes = []
for line in p.stdout:
cols = re.split(r'\s+', line)
ipw = _ipmatch(cols[0])
if not ipw:
continue # some lines won't be parseable; never mind
maskw = _ipmatch(cols[2]) # linux only
mask = _maskbits(maskw) # returns 32 if maskw is null
width = min(ipw[1], mask)
ip = ipw[0] & shl(shl(1, width) - 1, 32-width)
routes.append((socket.inet_ntoa(struct.pack('!I', ip)), width))
rv = p.wait()
if rv != 0:
log('WARNING: %r returned %d\n' % (argv, rv))
log('WARNING: That prevents --auto-nets from working.\n')
return routes
def list_routes():
l = []
for (ip,width) in _list_routes():
if not ip.startswith('0.') and not ip.startswith('127.'):
l.append((ip,width))
return l
def _exc_dump():
exc_info = sys.exc_info()
return ''.join(traceback.format_exception(*exc_info))
def start_hostwatch(seed_hosts):
s1,s2 = socket.socketpair()
pid = os.fork()
if not pid:
# child
rv = 99
try:
try:
s2.close()
os.dup2(s1.fileno(), 1)
os.dup2(s1.fileno(), 0)
s1.close()
rv = hostwatch.hw_main(seed_hosts) or 0
except Exception, e:
log('%s\n' % _exc_dump())
rv = 98
finally:
os._exit(rv)
s1.close()
return pid,s2
class Hostwatch:
def __init__(self):
self.pid = 0
self.sock = None
class DnsProxy(Handler):
def __init__(self, mux, chan, request):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Handler.__init__(self, [sock])
self.timeout = time.time()+30
self.mux = mux
self.chan = chan
self.tries = 0
self.peer = None
self.request = request
self.sock = sock
self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
self.try_send()
def try_send(self):
if self.tries >= 3:
return
self.tries += 1
self.peer = resolvconf_random_nameserver()
self.sock.connect((self.peer, 53))
debug2('DNS: sending to %r\n' % self.peer)
try:
self.sock.send(self.request)
except socket.error, e:
if e.args[0] in ssnet.NET_ERRS:
# might have been spurious; try again.
# Note: these errors sometimes are reported by recv(),
# and sometimes by send(). We have to catch both.
debug2('DNS send to %r: %s\n' % (self.peer, e))
self.try_send()
return
else:
log('DNS send to %r: %s\n' % (self.peer, e))
return
def callback(self):
try:
data = self.sock.recv(4096)
except socket.error, e:
if e.args[0] in ssnet.NET_ERRS:
# might have been spurious; try again.
# Note: these errors sometimes are reported by recv(),
# and sometimes by send(). We have to catch both.
debug2('DNS recv from %r: %s\n' % (self.peer, e))
self.try_send()
return
else:
log('DNS recv from %r: %s\n' % (self.peer, e))
return
debug2('DNS response: %d bytes\n' % len(data))
self.mux.send(self.chan, ssnet.CMD_DNS_RESPONSE, data)
self.ok = False
def main():
if helpers.verbose >= 1:
helpers.logprefix = ' s: '
else:
helpers.logprefix = 'server: '
debug1('latency control setting = %r\n' % latency_control)
routes = list(list_routes())
debug1('available routes:\n')
for r in routes:
debug1(' %s/%d\n' % r)
# synchronization header
sys.stdout.write('\0\0SSHUTTLE0001')
sys.stdout.flush()
handlers = []
mux = Mux(socket.fromfd(sys.stdin.fileno(),
socket.AF_INET, socket.SOCK_STREAM),
socket.fromfd(sys.stdout.fileno(),
socket.AF_INET, socket.SOCK_STREAM))
handlers.append(mux)
routepkt = ''
for r in routes:
routepkt += '%s,%d\n' % r
mux.send(0, ssnet.CMD_ROUTES, routepkt)
hw = Hostwatch()
hw.leftover = ''
def hostwatch_ready():
assert(hw.pid)
content = hw.sock.recv(4096)
if content:
lines = (hw.leftover + content).split('\n')
if lines[-1]:
# no terminating newline: entry isn't complete yet!
hw.leftover = lines.pop()
lines.append('')
else:
hw.leftover = ''
mux.send(0, ssnet.CMD_HOST_LIST, '\n'.join(lines))
else:
raise Fatal('hostwatch process died')
def got_host_req(data):
if not hw.pid:
(hw.pid,hw.sock) = start_hostwatch(data.strip().split())
handlers.append(Handler(socks = [hw.sock],
callback = hostwatch_ready))
mux.got_host_req = got_host_req
def new_channel(channel, data):
(dstip,dstport) = data.split(',', 1)
dstport = int(dstport)
outwrap = ssnet.connect_dst(dstip,dstport)
handlers.append(Proxy(MuxWrapper(mux, channel), outwrap))
mux.new_channel = new_channel
dnshandlers = {}
def dns_req(channel, data):
debug2('Incoming DNS request.\n')
h = DnsProxy(mux, channel, data)
handlers.append(h)
dnshandlers[channel] = h
mux.got_dns_req = dns_req
while mux.ok:
if hw.pid:
assert(hw.pid > 0)
(rpid, rv) = os.waitpid(hw.pid, os.WNOHANG)
if rpid:
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv)
ssnet.runonce(handlers, mux)
if latency_control:
mux.check_fullness()
mux.callback()
if dnshandlers:
now = time.time()
for channel,h in dnshandlers.items():
if h.timeout < now or not h.ok:
del dnshandlers[channel]
h.ok = False
|
lgpl-2.1
|
[
646,
295,
12,
2702,
12,
2838,
12,
3504,
12,
5190,
12,
900,
199,
692,
440,
7992,
1252,
362,
360,
2759,
63,
12775,
735,
272,
492,
10110,
846,
12,
10897,
12,
1591,
6821,
272,
492,
8434,
14,
385,
456,
1412,
465,
308,
5781,
272,
687,
10110,
846,
492,
428,
766,
4590,
12,
18599,
12,
12373,
12,
603,
2521,
12,
603,
2521,
4590,
272,
687,
10897,
492,
627,
421,
199,
318,
485,
711,
1431,
8,
711,
495,
304,
272,
340,
3384,
495,
508,
283,
885,
356,
267,
3384,
495,
275,
283,
16,
14,
16,
14,
16,
14,
16,
15,
16,
7,
272,
333,
275,
295,
14,
1431,
8,
82,
31344,
68,
20900,
3134,
68,
20900,
3134,
68,
20900,
3134,
68,
19544,
5547,
5547,
9,
5169,
15,
2961,
68,
11,
22119,
4268,
3384,
495,
9,
272,
340,
333,
26,
267,
486,
275,
333,
14,
2634,
342,
267,
15017,
275,
486,
59,
16,
61,
267,
3462,
275,
1109,
8,
71,
59,
20,
61,
503,
4337,
9,
267,
340,
486,
59,
17,
61,
508,
488,
26,
288,
15017,
847,
1987,
16,
14,
16,
14,
16,
7,
288,
3462,
275,
1748,
8,
2063,
12,
1695,
9,
267,
916,
486,
59,
18,
61,
508,
488,
26,
288,
15017,
847,
1987,
16,
14,
16,
7,
288,
3462,
275,
1748,
8,
2063,
12,
3193,
9,
267,
916,
486,
59,
19,
61,
508,
488,
26,
288,
15017,
847,
1987,
16,
7,
288,
3462,
275,
1748,
8,
2063,
12,
5504,
9,
267,
372,
334,
1820,
14,
5301,
16157,
41,
297,
2838,
14,
10811,
63,
25685,
8,
6142,
11515,
16,
467,
3462,
9,
421,
199,
318,
485,
711,
495,
8,
711,
12,
3462,
304,
272,
340,
3462,
2356,
4337,
26,
267,
372,
3384,
272,
587,
26,
267,
372,
2071,
83,
3149,
68,
2,
450,
334,
711,
12,
3462,
9,
421,
199,
318,
485,
2629,
5609,
8,
14588,
304,
272,
340,
440,
20225,
26,
267,
372,
4337,
272,
367,
284,
315,
1425,
8,
708,
304,
267,
340,
20225,
59,
16,
61,
1253,
1033,
76,
8,
17,
12,
284,
304,
288,
372,
4337,
13,
73,
272,
372,
378,
26339,
199,
318,
485,
513,
63,
13243,
837,
272,
9238,
275,
788,
846,
3736,
297,
2475,
11641,
418,
272,
299,
275,
308,
5781,
14,
7942,
8,
3020,
12,
3839,
29,
385,
456,
1412,
14,
6089,
9,
272,
15777,
275,
942,
272,
367,
1004,
315,
299,
14,
2703,
26,
267,
8850,
275,
295,
14,
1294,
8,
82,
1154,
83,
7386,
1004,
9,
267,
3384,
87,
275,
485,
711,
1431,
8,
4574,
59,
16,
566,
267,
340,
440,
3384,
87,
26,
288,
1980,
221,
327,
2005,
2385,
7859,
1133,
506,
2198,
461,
27,
7078,
25169,
267,
3656,
87,
275,
485,
711,
1431,
8,
4574,
59,
18,
566,
221,
327,
18369,
1454,
267,
3656,
275,
485,
2629,
5609,
8,
2629,
87,
9,
257,
327,
2529,
4337,
340,
3656,
87,
365,
2973,
267,
3462,
275,
1748,
8,
711,
87,
59,
17,
467,
3656,
9,
267,
3384,
275,
3384,
87,
59,
16,
61,
1253,
1033,
76,
8,
609,
76,
8,
17,
12,
3462,
9,
446,
413,
12,
4337,
13,
2063,
9,
267,
15777,
14,
740,
1332,
3450,
14,
10811,
63,
343,
20047,
8,
1820,
14,
1389,
16157,
41,
297,
3384,
1826,
3462,
430,
272,
4336,
275,
299,
14,
2573,
342,
272,
340,
4336,
1137,
378,
26,
267,
943,
360,
9171,
26,
450,
82,
2138,
450,
68,
60,
78,
7,
450,
334,
3020,
12,
4336,
430,
267,
943,
360,
9171,
26,
10314,
21925,
1553,
2495,
13,
20490,
687,
6449,
3134,
78,
358,
272,
372,
15777,
421,
199,
318,
769,
63,
13243,
837,
272,
634,
275,
942,
272,
367,
334,
711,
12,
2063,
9,
315,
485,
513,
63,
13243,
837,
267,
340,
440,
3384,
14,
2460,
360,
16,
2659,
436,
440,
3384,
14,
2460,
360,
4195,
30194,
288,
634,
14,
740,
1332,
711,
12,
2063,
430,
272,
372,
634,
421,
199,
318,
485,
2804,
63,
2724,
837,
272,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
272,
372,
6522,
904,
8,
6894,
14,
908,
63,
1971,
2031,
2804,
63,
815,
430,
421,
199,
318,
1343,
63,
1102,
6821,
8,
5176,
63,
5146,
304,
272,
308,
17,
12,
83,
18,
275,
2838,
14,
3450,
3852,
342,
272,
4422,
275,
747,
14,
11796,
342,
272,
340,
440,
4422,
26,
267,
327,
1982,
267,
4336,
275,
8806,
267,
862,
26,
288,
862,
26,
355,
308,
18,
14,
1600,
342,
355,
747,
14,
11048,
18,
8,
83,
17,
14,
9843,
1062,
413,
9,
355,
747,
14,
11048,
18,
8,
83,
17,
14,
9843,
1062,
378,
9,
355,
308,
17,
14,
1600,
342,
355,
4336,
275,
1591,
6821,
14,
8090,
63,
973,
8,
5176,
63,
5146,
9,
503,
378,
288,
871,
2186,
12,
325,
26,
355,
943,
3508,
83,
60,
78,
7,
450,
485,
2804,
63,
2724,
1012,
355,
4336,
275,
16096,
267,
3753,
26,
288,
747,
423,
2224,
8,
6310,
9,
272,
308,
17,
14,
1600,
342,
272,
372,
4422,
12,
83,
18,
421,
199,
533,
10891,
6821,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3150,
275,
378,
267,
291,
14,
5096,
275,
488,
421,
199,
533,
577,
561,
4936,
8,
2461,
304,
272,
347,
636,
826,
721,
277,
12,
22343,
12,
15985,
12,
1056,
304,
267,
6771,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
267,
18599,
855,
826,
721,
277,
12,
359,
5096,
566,
267,
291,
14,
2593,
275,
900,
14,
521,
24543,
1216,
267,
291,
14,
20521,
275,
22343,
267,
291,
14,
11984,
275,
15985,
267,
291,
14,
6264,
275,
378,
267,
291,
14,
7866,
275,
488,
267,
291,
14,
1069,
275,
1056,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
5096,
14,
27689,
8,
3450,
14,
15096,
63,
1772,
12,
2838,
14,
1772,
63,
25567,
12,
5685,
9,
267,
291,
14,
893,
63,
2254,
342,
339,
347,
862,
63,
2254,
8,
277,
304,
267,
340,
291,
14,
6264,
2356,
650,
26,
288,
372,
267,
291,
14,
6264,
847,
413,
267,
291,
14,
7866,
275,
17416,
86,
2190,
63,
2355,
63,
354,
1000,
342,
267,
291,
14,
5096,
14,
2242,
1332,
277,
14,
7866,
12,
13564,
430,
267,
3105,
18,
360,
12323
] |
[
295,
12,
2702,
12,
2838,
12,
3504,
12,
5190,
12,
900,
199,
692,
440,
7992,
1252,
362,
360,
2759,
63,
12775,
735,
272,
492,
10110,
846,
12,
10897,
12,
1591,
6821,
272,
492,
8434,
14,
385,
456,
1412,
465,
308,
5781,
272,
687,
10110,
846,
492,
428,
766,
4590,
12,
18599,
12,
12373,
12,
603,
2521,
12,
603,
2521,
4590,
272,
687,
10897,
492,
627,
421,
199,
318,
485,
711,
1431,
8,
711,
495,
304,
272,
340,
3384,
495,
508,
283,
885,
356,
267,
3384,
495,
275,
283,
16,
14,
16,
14,
16,
14,
16,
15,
16,
7,
272,
333,
275,
295,
14,
1431,
8,
82,
31344,
68,
20900,
3134,
68,
20900,
3134,
68,
20900,
3134,
68,
19544,
5547,
5547,
9,
5169,
15,
2961,
68,
11,
22119,
4268,
3384,
495,
9,
272,
340,
333,
26,
267,
486,
275,
333,
14,
2634,
342,
267,
15017,
275,
486,
59,
16,
61,
267,
3462,
275,
1109,
8,
71,
59,
20,
61,
503,
4337,
9,
267,
340,
486,
59,
17,
61,
508,
488,
26,
288,
15017,
847,
1987,
16,
14,
16,
14,
16,
7,
288,
3462,
275,
1748,
8,
2063,
12,
1695,
9,
267,
916,
486,
59,
18,
61,
508,
488,
26,
288,
15017,
847,
1987,
16,
14,
16,
7,
288,
3462,
275,
1748,
8,
2063,
12,
3193,
9,
267,
916,
486,
59,
19,
61,
508,
488,
26,
288,
15017,
847,
1987,
16,
7,
288,
3462,
275,
1748,
8,
2063,
12,
5504,
9,
267,
372,
334,
1820,
14,
5301,
16157,
41,
297,
2838,
14,
10811,
63,
25685,
8,
6142,
11515,
16,
467,
3462,
9,
421,
199,
318,
485,
711,
495,
8,
711,
12,
3462,
304,
272,
340,
3462,
2356,
4337,
26,
267,
372,
3384,
272,
587,
26,
267,
372,
2071,
83,
3149,
68,
2,
450,
334,
711,
12,
3462,
9,
421,
199,
318,
485,
2629,
5609,
8,
14588,
304,
272,
340,
440,
20225,
26,
267,
372,
4337,
272,
367,
284,
315,
1425,
8,
708,
304,
267,
340,
20225,
59,
16,
61,
1253,
1033,
76,
8,
17,
12,
284,
304,
288,
372,
4337,
13,
73,
272,
372,
378,
26339,
199,
318,
485,
513,
63,
13243,
837,
272,
9238,
275,
788,
846,
3736,
297,
2475,
11641,
418,
272,
299,
275,
308,
5781,
14,
7942,
8,
3020,
12,
3839,
29,
385,
456,
1412,
14,
6089,
9,
272,
15777,
275,
942,
272,
367,
1004,
315,
299,
14,
2703,
26,
267,
8850,
275,
295,
14,
1294,
8,
82,
1154,
83,
7386,
1004,
9,
267,
3384,
87,
275,
485,
711,
1431,
8,
4574,
59,
16,
566,
267,
340,
440,
3384,
87,
26,
288,
1980,
221,
327,
2005,
2385,
7859,
1133,
506,
2198,
461,
27,
7078,
25169,
267,
3656,
87,
275,
485,
711,
1431,
8,
4574,
59,
18,
566,
221,
327,
18369,
1454,
267,
3656,
275,
485,
2629,
5609,
8,
2629,
87,
9,
257,
327,
2529,
4337,
340,
3656,
87,
365,
2973,
267,
3462,
275,
1748,
8,
711,
87,
59,
17,
467,
3656,
9,
267,
3384,
275,
3384,
87,
59,
16,
61,
1253,
1033,
76,
8,
609,
76,
8,
17,
12,
3462,
9,
446,
413,
12,
4337,
13,
2063,
9,
267,
15777,
14,
740,
1332,
3450,
14,
10811,
63,
343,
20047,
8,
1820,
14,
1389,
16157,
41,
297,
3384,
1826,
3462,
430,
272,
4336,
275,
299,
14,
2573,
342,
272,
340,
4336,
1137,
378,
26,
267,
943,
360,
9171,
26,
450,
82,
2138,
450,
68,
60,
78,
7,
450,
334,
3020,
12,
4336,
430,
267,
943,
360,
9171,
26,
10314,
21925,
1553,
2495,
13,
20490,
687,
6449,
3134,
78,
358,
272,
372,
15777,
421,
199,
318,
769,
63,
13243,
837,
272,
634,
275,
942,
272,
367,
334,
711,
12,
2063,
9,
315,
485,
513,
63,
13243,
837,
267,
340,
440,
3384,
14,
2460,
360,
16,
2659,
436,
440,
3384,
14,
2460,
360,
4195,
30194,
288,
634,
14,
740,
1332,
711,
12,
2063,
430,
272,
372,
634,
421,
199,
318,
485,
2804,
63,
2724,
837,
272,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
272,
372,
6522,
904,
8,
6894,
14,
908,
63,
1971,
2031,
2804,
63,
815,
430,
421,
199,
318,
1343,
63,
1102,
6821,
8,
5176,
63,
5146,
304,
272,
308,
17,
12,
83,
18,
275,
2838,
14,
3450,
3852,
342,
272,
4422,
275,
747,
14,
11796,
342,
272,
340,
440,
4422,
26,
267,
327,
1982,
267,
4336,
275,
8806,
267,
862,
26,
288,
862,
26,
355,
308,
18,
14,
1600,
342,
355,
747,
14,
11048,
18,
8,
83,
17,
14,
9843,
1062,
413,
9,
355,
747,
14,
11048,
18,
8,
83,
17,
14,
9843,
1062,
378,
9,
355,
308,
17,
14,
1600,
342,
355,
4336,
275,
1591,
6821,
14,
8090,
63,
973,
8,
5176,
63,
5146,
9,
503,
378,
288,
871,
2186,
12,
325,
26,
355,
943,
3508,
83,
60,
78,
7,
450,
485,
2804,
63,
2724,
1012,
355,
4336,
275,
16096,
267,
3753,
26,
288,
747,
423,
2224,
8,
6310,
9,
272,
308,
17,
14,
1600,
342,
272,
372,
4422,
12,
83,
18,
421,
199,
533,
10891,
6821,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3150,
275,
378,
267,
291,
14,
5096,
275,
488,
421,
199,
533,
577,
561,
4936,
8,
2461,
304,
272,
347,
636,
826,
721,
277,
12,
22343,
12,
15985,
12,
1056,
304,
267,
6771,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
267,
18599,
855,
826,
721,
277,
12,
359,
5096,
566,
267,
291,
14,
2593,
275,
900,
14,
521,
24543,
1216,
267,
291,
14,
20521,
275,
22343,
267,
291,
14,
11984,
275,
15985,
267,
291,
14,
6264,
275,
378,
267,
291,
14,
7866,
275,
488,
267,
291,
14,
1069,
275,
1056,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
5096,
14,
27689,
8,
3450,
14,
15096,
63,
1772,
12,
2838,
14,
1772,
63,
25567,
12,
5685,
9,
267,
291,
14,
893,
63,
2254,
342,
339,
347,
862,
63,
2254,
8,
277,
304,
267,
340,
291,
14,
6264,
2356,
650,
26,
288,
372,
267,
291,
14,
6264,
847,
413,
267,
291,
14,
7866,
275,
17416,
86,
2190,
63,
2355,
63,
354,
1000,
342,
267,
291,
14,
5096,
14,
2242,
1332,
277,
14,
7866,
12,
13564,
430,
267,
3105,
18,
360,
12323,
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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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ziethan/decanter
|
decanter/install.py
|
1
|
3967
|
from __future__ import absolute_import, print_function
import tarfile
import json
import yaml
import os
import errno
import requests
import xml.etree.ElementTree as ET
from xml.etree.ElementTree import ParseError
from decanter import config
def InstallFromFile(**kwargs):
if kwargs.get('path') is None:
exts = ['package.json', 'package.yaml', 'package.yml', 'package.xml']
for x in exts:
result = file_check(x)
if result is not None:
break
else:
result = kwargs.get('path')
try:
f = open(result, 'r')
except TypeError, IOError:
f = None
if f is None:
print('No package file provided')
return False
if result.endswith('.json'):
data = json.loads(f.read())
elif result.endswith('.yaml') or result.endswith('.yml'):
data = yaml.load(f.read())
else:
try:
package = ET.fromstring(f.read())
data = {}
for i in range(0, package.__len__()):
data[package.findall('package')[i].get('name')] = package.findall('package')[i].get('version')
except ParseError:
print('Error parsing XML package file')
return False
if not os.path.exists('components') or not os.path.isdir('components'):
mkdir('components')
if data is None:
print('No data in package file')
return False
for x in data:
get_package(x, data[x])
def Install(**kwargs):
if kwargs.get('package') is None:
InstallFromFile(**kwargs)
return False
if kwargs.get('version') is None:
Warning('Using latest version.')
kwargs['version'] = 'latest'
if os.path.exists('components') and os.path.isdir('components'):
get_package(kwargs['package'], kwargs['version'])
else:
mkdir('components')
get_package(kwargs['package'], kwargs['version'])
def file_check(f):
try:
open(f, 'r')
return f
except IOError:
return None
def mkdir(path):
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def get_package(package, version):
p_data = json.dumps({'package': package, 'version': version})
headers = {'Content-Type': 'application/json'}
r = requests.get('{0}/api/package'.format(config.get('defaults', 'registry_server')), data=p_data, headers=headers)
response = json.loads(r.text)
if r.status_code != 200:
print(response['error'], '::: {0} {1}'.format(package, version))
return False
url = response['result']['data']['package']['url']
if os.path.exists('/tmp/decanter') and os.path.isdir('/tmp/decanter'):
tarball = download_package(url, package, version)
else:
mkdir('/tmp/decanter')
tarball = download_package(url, package, version)
if not tarball:
return False
t = tarfile.open('/tmp/decanter/{0}-{1}.tar.gz'.format(package, version))
t.extractall(path="components")
t.close()
def download_package(url, package, version):
with open('/tmp/decanter/{0}-{1}.tar.gz'.format(package, version), 'wb') as handle:
response = requests.get(url, stream=True)
if not response.ok:
print('Failed to get package ::: {0} {1}'.format(package, version))
return False
for block in response.iter_content(1024):
if not block:
break
handle.write(block)
return True
# print('else if package exists but not the right version')
# print('warn that the supplied version does not exist')
# print('install latest package')
# print('else if package does not exist at all')
# print('raise exception saying package does not exist')
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
13608,
199,
646,
2022,
199,
646,
8864,
199,
646,
747,
199,
646,
7554,
199,
646,
4145,
199,
646,
2748,
14,
9464,
14,
15325,
465,
12265,
199,
504,
221,
2748,
14,
9464,
14,
15325,
492,
21743,
199,
199,
504,
477,
2425,
351,
492,
1101,
421,
199,
318,
13276,
26637,
3682,
958,
304,
272,
340,
2074,
14,
362,
360,
515,
358,
365,
488,
26,
267,
27688,
275,
788,
2491,
14,
1001,
297,
283,
2491,
14,
5963,
297,
283,
2491,
14,
11714,
297,
283,
2491,
14,
1652,
418,
267,
367,
671,
315,
27688,
26,
288,
754,
275,
570,
63,
1074,
8,
88,
9,
288,
340,
754,
365,
440,
488,
26,
355,
2059,
272,
587,
26,
267,
754,
275,
2074,
14,
362,
360,
515,
358,
2286,
862,
26,
267,
289,
275,
1551,
8,
1099,
12,
283,
82,
358,
272,
871,
3146,
12,
5925,
26,
267,
289,
275,
488,
339,
340,
289,
365,
488,
26,
267,
870,
360,
1944,
2559,
570,
2741,
358,
267,
372,
756,
339,
340,
754,
14,
4130,
5175,
1001,
735,
267,
666,
275,
2022,
14,
3640,
8,
70,
14,
739,
1012,
272,
916,
754,
14,
4130,
5175,
5963,
358,
503,
754,
14,
4130,
5175,
11714,
735,
267,
666,
275,
8864,
14,
912,
8,
70,
14,
739,
1012,
272,
587,
26,
267,
862,
26,
288,
2559,
275,
12265,
14,
13521,
8,
70,
14,
739,
1012,
288,
666,
275,
1052,
288,
367,
284,
315,
1425,
8,
16,
12,
2559,
855,
552,
4533,
304,
355,
666,
59,
2491,
14,
6452,
360,
2491,
5832,
73,
1055,
362,
360,
354,
5440,
275,
2559,
14,
6452,
360,
2491,
5832,
73,
1055,
362,
360,
1023,
358,
267,
871,
21743,
26,
288,
870,
360,
547,
6057,
4692,
2559,
570,
358,
288,
372,
756,
5493,
340,
440,
747,
14,
515,
14,
2444,
360,
4608,
358,
503,
440,
747,
14,
515,
14,
6027,
360,
4608,
735,
267,
20366,
360,
4608,
358,
2286,
340,
666,
365,
488,
26,
267,
870,
360,
1944,
666,
315,
2559,
570,
358,
267,
372,
756,
2286,
367,
671,
315,
666,
26,
267,
664,
63,
2491,
8,
88,
12,
666,
59,
88,
566,
16872,
199,
318,
13276,
3682,
958,
304,
272,
340,
2074,
14,
362,
360,
2491,
358,
365,
488,
26,
267,
13276,
26637,
3682,
958,
9,
267,
372,
756,
272,
340,
2074,
14,
362,
360,
1023,
358,
365,
488,
26,
267,
15902,
360,
10369,
8839,
1015,
2659,
267,
2074,
459,
1023,
418,
275,
283,
7410,
7,
2286,
340,
747,
14,
515,
14,
2444,
360,
4608,
358,
436,
747,
14,
515,
14,
6027,
360,
4608,
735,
267,
664,
63,
2491,
8,
958,
459,
2491,
995,
2074,
459,
1023,
1105,
272,
587,
26,
267,
20366,
360,
4608,
358,
267,
664,
63,
2491,
8,
958,
459,
2491,
995,
2074,
459,
1023,
1105,
199,
199,
318,
570,
63,
1074,
8,
70,
304,
272,
862,
26,
267,
1551,
8,
70,
12,
283,
82,
358,
267,
372,
289,
272,
871,
5925,
26,
267,
372,
488,
1362,
199,
318,
20366,
8,
515,
304,
272,
862,
26,
267,
747,
14,
8347,
8,
515,
9,
272,
871,
6440,
465,
3178,
26,
267,
340,
3178,
14,
7931,
508,
7554,
14,
28596,
436,
747,
14,
515,
14,
6027,
8,
515,
304,
288,
986,
267,
587,
26,
288,
746,
199,
199,
318,
664,
63,
2491,
8,
2491,
12,
1015,
304,
272,
299,
63,
576,
275,
2022,
14,
4180,
3252,
2491,
356,
2559,
12,
283,
1023,
356,
1015,
1552,
272,
2323,
275,
791,
2714,
13,
804,
356,
283,
3578,
15,
1001,
936,
272,
519,
275,
4145,
14,
362,
11117,
16,
5995,
1246,
15,
2491,
1370,
908,
8,
888,
14,
362,
360,
4322,
297,
283,
5189,
63,
1000,
3855,
666,
29,
80,
63,
576,
12,
2323,
29,
2139,
9,
2286,
1177,
275,
2022,
14,
3640,
8,
82,
14,
505,
9,
272,
340,
519,
14,
1205,
63,
600,
1137,
1926,
26,
267,
870,
8,
1310,
459,
705,
995,
19069,
26,
469,
16,
93,
469,
17,
5285,
908,
8,
2491,
12,
1015,
430,
267,
372,
756,
2286,
1166,
275,
1177,
459,
1099,
2545,
576,
2545,
2491,
2545,
633,
418,
2286,
340,
747,
14,
515,
14,
2444,
2336,
2791,
15,
271,
2425,
351,
358,
436,
747,
14,
515,
14,
6027,
2336,
2791,
15,
271,
2425,
351,
735,
267,
17641,
275,
5235,
63,
2491,
8,
633,
12,
2559,
12,
1015,
9,
272,
587,
26,
267,
20366,
2336,
2791,
15,
271,
2425,
351,
358,
267,
17641,
275,
5235,
63,
2491,
8,
633,
12,
2559,
12,
1015,
9,
2286,
340,
440,
17641,
26,
267,
372,
756,
2286,
307,
275,
13608,
14,
1490,
2336,
2791,
15,
271,
2425,
351,
5321,
16,
30289,
17,
5565,
5369,
14,
6838,
1370,
908,
8,
2491,
12,
1015,
430,
272,
307,
14,
5005,
452,
8,
515,
628,
4608,
531,
272,
307,
14,
1600,
342,
1362,
199,
318,
5235,
63,
2491,
8,
633,
12,
2559,
12,
1015,
304,
272,
543,
1551,
2336,
2791,
15,
271,
2425,
351,
5321,
16,
30289,
17,
5565,
5369,
14,
6838,
1370,
908,
8,
2491,
12,
1015,
395,
283,
6603,
358,
465,
2429,
26,
267,
1177,
275,
4145,
14,
362,
8,
633,
12,
2547,
29,
549,
9,
2728,
340,
440,
1177,
14,
745,
26,
288,
870,
360,
4276,
370,
664,
2559,
3800,
26,
469,
16,
93,
469,
17,
5285,
908,
8,
2491,
12,
1015,
430,
288,
372,
756,
10631,
367,
1853,
315,
1177,
14,
1661,
63,
1317,
8,
7727,
304,
288,
340,
440,
1853,
26,
355,
2059,
288,
2429,
14,
952,
8,
1457,
9,
2728,
372,
715,
1362,
199,
3,
258,
870,
360,
2836,
340,
2559,
3495,
1325,
440,
314,
2451,
1015,
358,
199,
3,
258,
870,
360,
4050,
626,
314,
6841,
1015,
1630,
440,
2187,
358,
199,
3,
258,
870,
360,
3174,
8839,
2559,
358,
199,
3,
258,
870,
360,
2836,
340,
2559,
1630,
440,
2187,
737,
1006,
358,
199,
3,
258,
870,
360,
3730,
1919,
14722,
316,
2559,
1630,
440,
2187,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
13608,
199,
646,
2022,
199,
646,
8864,
199,
646,
747,
199,
646,
7554,
199,
646,
4145,
199,
646,
2748,
14,
9464,
14,
15325,
465,
12265,
199,
504,
221,
2748,
14,
9464,
14,
15325,
492,
21743,
199,
199,
504,
477,
2425,
351,
492,
1101,
421,
199,
318,
13276,
26637,
3682,
958,
304,
272,
340,
2074,
14,
362,
360,
515,
358,
365,
488,
26,
267,
27688,
275,
788,
2491,
14,
1001,
297,
283,
2491,
14,
5963,
297,
283,
2491,
14,
11714,
297,
283,
2491,
14,
1652,
418,
267,
367,
671,
315,
27688,
26,
288,
754,
275,
570,
63,
1074,
8,
88,
9,
288,
340,
754,
365,
440,
488,
26,
355,
2059,
272,
587,
26,
267,
754,
275,
2074,
14,
362,
360,
515,
358,
2286,
862,
26,
267,
289,
275,
1551,
8,
1099,
12,
283,
82,
358,
272,
871,
3146,
12,
5925,
26,
267,
289,
275,
488,
339,
340,
289,
365,
488,
26,
267,
870,
360,
1944,
2559,
570,
2741,
358,
267,
372,
756,
339,
340,
754,
14,
4130,
5175,
1001,
735,
267,
666,
275,
2022,
14,
3640,
8,
70,
14,
739,
1012,
272,
916,
754,
14,
4130,
5175,
5963,
358,
503,
754,
14,
4130,
5175,
11714,
735,
267,
666,
275,
8864,
14,
912,
8,
70,
14,
739,
1012,
272,
587,
26,
267,
862,
26,
288,
2559,
275,
12265,
14,
13521,
8,
70,
14,
739,
1012,
288,
666,
275,
1052,
288,
367,
284,
315,
1425,
8,
16,
12,
2559,
855,
552,
4533,
304,
355,
666,
59,
2491,
14,
6452,
360,
2491,
5832,
73,
1055,
362,
360,
354,
5440,
275,
2559,
14,
6452,
360,
2491,
5832,
73,
1055,
362,
360,
1023,
358,
267,
871,
21743,
26,
288,
870,
360,
547,
6057,
4692,
2559,
570,
358,
288,
372,
756,
5493,
340,
440,
747,
14,
515,
14,
2444,
360,
4608,
358,
503,
440,
747,
14,
515,
14,
6027,
360,
4608,
735,
267,
20366,
360,
4608,
358,
2286,
340,
666,
365,
488,
26,
267,
870,
360,
1944,
666,
315,
2559,
570,
358,
267,
372,
756,
2286,
367,
671,
315,
666,
26,
267,
664,
63,
2491,
8,
88,
12,
666,
59,
88,
566,
16872,
199,
318,
13276,
3682,
958,
304,
272,
340,
2074,
14,
362,
360,
2491,
358,
365,
488,
26,
267,
13276,
26637,
3682,
958,
9,
267,
372,
756,
272,
340,
2074,
14,
362,
360,
1023,
358,
365,
488,
26,
267,
15902,
360,
10369,
8839,
1015,
2659,
267,
2074,
459,
1023,
418,
275,
283,
7410,
7,
2286,
340,
747,
14,
515,
14,
2444,
360,
4608,
358,
436,
747,
14,
515,
14,
6027,
360,
4608,
735,
267,
664,
63,
2491,
8,
958,
459,
2491,
995,
2074,
459,
1023,
1105,
272,
587,
26,
267,
20366,
360,
4608,
358,
267,
664,
63,
2491,
8,
958,
459,
2491,
995,
2074,
459,
1023,
1105,
199,
199,
318,
570,
63,
1074,
8,
70,
304,
272,
862,
26,
267,
1551,
8,
70,
12,
283,
82,
358,
267,
372,
289,
272,
871,
5925,
26,
267,
372,
488,
1362,
199,
318,
20366,
8,
515,
304,
272,
862,
26,
267,
747,
14,
8347,
8,
515,
9,
272,
871,
6440,
465,
3178,
26,
267,
340,
3178,
14,
7931,
508,
7554,
14,
28596,
436,
747,
14,
515,
14,
6027,
8,
515,
304,
288,
986,
267,
587,
26,
288,
746,
199,
199,
318,
664,
63,
2491,
8,
2491,
12,
1015,
304,
272,
299,
63,
576,
275,
2022,
14,
4180,
3252,
2491,
356,
2559,
12,
283,
1023,
356,
1015,
1552,
272,
2323,
275,
791,
2714,
13,
804,
356,
283,
3578,
15,
1001,
936,
272,
519,
275,
4145,
14,
362,
11117,
16,
5995,
1246,
15,
2491,
1370,
908,
8,
888,
14,
362,
360,
4322,
297,
283,
5189,
63,
1000,
3855,
666,
29,
80,
63,
576,
12,
2323,
29,
2139,
9,
2286,
1177,
275,
2022,
14,
3640,
8,
82,
14,
505,
9,
272,
340,
519,
14,
1205,
63,
600,
1137,
1926,
26,
267,
870,
8,
1310,
459,
705,
995,
19069,
26,
469,
16,
93,
469,
17,
5285,
908,
8,
2491,
12,
1015,
430,
267,
372,
756,
2286,
1166,
275,
1177,
459,
1099,
2545,
576,
2545,
2491,
2545,
633,
418,
2286,
340,
747,
14,
515,
14,
2444,
2336,
2791,
15,
271,
2425,
351,
358,
436,
747,
14,
515,
14,
6027,
2336,
2791,
15,
271,
2425,
351,
735,
267,
17641,
275,
5235,
63,
2491,
8,
633,
12,
2559,
12,
1015,
9,
272,
587,
26,
267,
20366,
2336,
2791,
15,
271,
2425,
351,
358,
267,
17641,
275,
5235,
63,
2491,
8,
633,
12,
2559,
12,
1015,
9,
2286,
340,
440,
17641,
26,
267,
372,
756,
2286,
307,
275,
13608,
14,
1490,
2336,
2791,
15,
271,
2425,
351,
5321,
16,
30289,
17,
5565,
5369,
14,
6838,
1370,
908,
8,
2491,
12,
1015,
430,
272,
307,
14,
5005,
452,
8,
515,
628,
4608,
531,
272,
307,
14,
1600,
342,
1362,
199,
318,
5235,
63,
2491,
8,
633,
12,
2559,
12,
1015,
304,
272,
543,
1551,
2336,
2791,
15,
271,
2425,
351,
5321,
16,
30289,
17,
5565,
5369,
14,
6838,
1370,
908,
8,
2491,
12,
1015,
395,
283,
6603,
358,
465,
2429,
26,
267,
1177,
275,
4145,
14,
362,
8,
633,
12,
2547,
29,
549,
9,
2728,
340,
440,
1177,
14,
745,
26,
288,
870,
360,
4276,
370,
664,
2559,
3800,
26,
469,
16,
93,
469,
17,
5285,
908,
8,
2491,
12,
1015,
430,
288,
372,
756,
10631,
367,
1853,
315,
1177,
14,
1661,
63,
1317,
8,
7727,
304,
288,
340,
440,
1853,
26,
355,
2059,
288,
2429,
14,
952,
8,
1457,
9,
2728,
372,
715,
1362,
199,
3,
258,
870,
360,
2836,
340,
2559,
3495,
1325,
440,
314,
2451,
1015,
358,
199,
3,
258,
870,
360,
4050,
626,
314,
6841,
1015,
1630,
440,
2187,
358,
199,
3,
258,
870,
360,
3174,
8839,
2559,
358,
199,
3,
258,
870,
360,
2836,
340,
2559,
1630,
440,
2187,
737,
1006,
358,
199,
3,
258,
870,
360,
3730,
1919,
14722,
316,
2559,
1630,
440,
2187,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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