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
|
|---|---|---|---|---|---|---|---|---|
tony5856/repository.tonysrepo
|
plugin.program.xmlerator/unidecode/x00b.py
|
252
|
4132
|
data = (
'[?]', # 0x00
'N', # 0x01
'N', # 0x02
'H', # 0x03
'[?]', # 0x04
'a', # 0x05
'aa', # 0x06
'i', # 0x07
'ii', # 0x08
'u', # 0x09
'uu', # 0x0a
'R', # 0x0b
'L', # 0x0c
'[?]', # 0x0d
'[?]', # 0x0e
'e', # 0x0f
'ai', # 0x10
'[?]', # 0x11
'[?]', # 0x12
'o', # 0x13
'au', # 0x14
'k', # 0x15
'kh', # 0x16
'g', # 0x17
'gh', # 0x18
'ng', # 0x19
'c', # 0x1a
'ch', # 0x1b
'j', # 0x1c
'jh', # 0x1d
'ny', # 0x1e
'tt', # 0x1f
'tth', # 0x20
'dd', # 0x21
'ddh', # 0x22
'nn', # 0x23
't', # 0x24
'th', # 0x25
'd', # 0x26
'dh', # 0x27
'n', # 0x28
'[?]', # 0x29
'p', # 0x2a
'ph', # 0x2b
'b', # 0x2c
'bh', # 0x2d
'm', # 0x2e
'y', # 0x2f
'r', # 0x30
'[?]', # 0x31
'l', # 0x32
'll', # 0x33
'[?]', # 0x34
'', # 0x35
'sh', # 0x36
'ss', # 0x37
's', # 0x38
'h', # 0x39
'[?]', # 0x3a
'[?]', # 0x3b
'\'', # 0x3c
'\'', # 0x3d
'aa', # 0x3e
'i', # 0x3f
'ii', # 0x40
'u', # 0x41
'uu', # 0x42
'R', # 0x43
'[?]', # 0x44
'[?]', # 0x45
'[?]', # 0x46
'e', # 0x47
'ai', # 0x48
'[?]', # 0x49
'[?]', # 0x4a
'o', # 0x4b
'au', # 0x4c
'', # 0x4d
'[?]', # 0x4e
'[?]', # 0x4f
'[?]', # 0x50
'[?]', # 0x51
'[?]', # 0x52
'[?]', # 0x53
'[?]', # 0x54
'[?]', # 0x55
'+', # 0x56
'+', # 0x57
'[?]', # 0x58
'[?]', # 0x59
'[?]', # 0x5a
'[?]', # 0x5b
'rr', # 0x5c
'rh', # 0x5d
'[?]', # 0x5e
'yy', # 0x5f
'RR', # 0x60
'LL', # 0x61
'[?]', # 0x62
'[?]', # 0x63
'[?]', # 0x64
'[?]', # 0x65
'0', # 0x66
'1', # 0x67
'2', # 0x68
'3', # 0x69
'4', # 0x6a
'5', # 0x6b
'6', # 0x6c
'7', # 0x6d
'8', # 0x6e
'9', # 0x6f
'', # 0x70
'[?]', # 0x71
'[?]', # 0x72
'[?]', # 0x73
'[?]', # 0x74
'[?]', # 0x75
'[?]', # 0x76
'[?]', # 0x77
'[?]', # 0x78
'[?]', # 0x79
'[?]', # 0x7a
'[?]', # 0x7b
'[?]', # 0x7c
'[?]', # 0x7d
'[?]', # 0x7e
'[?]', # 0x7f
'[?]', # 0x80
'[?]', # 0x81
'N', # 0x82
'H', # 0x83
'[?]', # 0x84
'a', # 0x85
'aa', # 0x86
'i', # 0x87
'ii', # 0x88
'u', # 0x89
'uu', # 0x8a
'[?]', # 0x8b
'[?]', # 0x8c
'[?]', # 0x8d
'e', # 0x8e
'ee', # 0x8f
'ai', # 0x90
'[?]', # 0x91
'o', # 0x92
'oo', # 0x93
'au', # 0x94
'k', # 0x95
'[?]', # 0x96
'[?]', # 0x97
'[?]', # 0x98
'ng', # 0x99
'c', # 0x9a
'[?]', # 0x9b
'j', # 0x9c
'[?]', # 0x9d
'ny', # 0x9e
'tt', # 0x9f
'[?]', # 0xa0
'[?]', # 0xa1
'[?]', # 0xa2
'nn', # 0xa3
't', # 0xa4
'[?]', # 0xa5
'[?]', # 0xa6
'[?]', # 0xa7
'n', # 0xa8
'nnn', # 0xa9
'p', # 0xaa
'[?]', # 0xab
'[?]', # 0xac
'[?]', # 0xad
'm', # 0xae
'y', # 0xaf
'r', # 0xb0
'rr', # 0xb1
'l', # 0xb2
'll', # 0xb3
'lll', # 0xb4
'v', # 0xb5
'[?]', # 0xb6
'ss', # 0xb7
's', # 0xb8
'h', # 0xb9
'[?]', # 0xba
'[?]', # 0xbb
'[?]', # 0xbc
'[?]', # 0xbd
'aa', # 0xbe
'i', # 0xbf
'ii', # 0xc0
'u', # 0xc1
'uu', # 0xc2
'[?]', # 0xc3
'[?]', # 0xc4
'[?]', # 0xc5
'e', # 0xc6
'ee', # 0xc7
'ai', # 0xc8
'[?]', # 0xc9
'o', # 0xca
'oo', # 0xcb
'au', # 0xcc
'', # 0xcd
'[?]', # 0xce
'[?]', # 0xcf
'[?]', # 0xd0
'[?]', # 0xd1
'[?]', # 0xd2
'[?]', # 0xd3
'[?]', # 0xd4
'[?]', # 0xd5
'[?]', # 0xd6
'+', # 0xd7
'[?]', # 0xd8
'[?]', # 0xd9
'[?]', # 0xda
'[?]', # 0xdb
'[?]', # 0xdc
'[?]', # 0xdd
'[?]', # 0xde
'[?]', # 0xdf
'[?]', # 0xe0
'[?]', # 0xe1
'[?]', # 0xe2
'[?]', # 0xe3
'[?]', # 0xe4
'[?]', # 0xe5
'0', # 0xe6
'1', # 0xe7
'2', # 0xe8
'3', # 0xe9
'4', # 0xea
'5', # 0xeb
'6', # 0xec
'7', # 0xed
'8', # 0xee
'9', # 0xef
'+10+', # 0xf0
'+100+', # 0xf1
'+1000+', # 0xf2
'[?]', # 0xf3
'[?]', # 0xf4
'[?]', # 0xf5
'[?]', # 0xf6
'[?]', # 0xf7
'[?]', # 0xf8
'[?]', # 0xf9
'[?]', # 0xfa
'[?]', # 0xfb
'[?]', # 0xfc
'[?]', # 0xfd
'[?]', # 0xfe
)
|
gpl-3.0
|
[
576,
275,
334,
199,
6880,
259,
327,
378,
88,
383,
199,
7,
46,
297,
259,
327,
378,
88,
614,
199,
7,
46,
297,
259,
327,
378,
88,
996,
199,
7,
40,
297,
259,
327,
378,
88,
1644,
199,
6880,
259,
327,
378,
88,
966,
199,
7,
65,
297,
259,
327,
378,
88,
1717,
199,
7,
2158,
297,
259,
327,
378,
88,
1690,
199,
7,
73,
297,
259,
327,
378,
88,
1780,
199,
7,
5908,
297,
259,
327,
378,
88,
2036,
199,
7,
85,
297,
259,
327,
378,
88,
1643,
199,
7,
17031,
297,
259,
327,
378,
88,
16,
65,
199,
7,
50,
297,
259,
327,
378,
88,
16,
66,
199,
7,
44,
297,
259,
327,
378,
88,
16,
67,
199,
6880,
259,
327,
378,
88,
16,
68,
199,
6880,
259,
327,
378,
88,
16,
69,
199,
7,
69,
297,
259,
327,
378,
88,
16,
70,
199,
7,
5789,
297,
259,
327,
378,
88,
709,
199,
6880,
259,
327,
378,
88,
845,
199,
6880,
259,
327,
378,
88,
713,
199,
7,
79,
297,
259,
327,
378,
88,
969,
199,
7,
3844,
297,
259,
327,
378,
88,
1079,
199,
7,
75,
297,
259,
327,
378,
88,
1046,
199,
7,
21889,
297,
259,
327,
378,
88,
975,
199,
7,
71,
297,
259,
327,
378,
88,
1196,
199,
7,
3561,
297,
259,
327,
378,
88,
1085,
199,
7,
2753,
297,
259,
327,
378,
88,
1167,
199,
7,
67,
297,
259,
327,
378,
88,
17,
65,
199,
7,
335,
297,
259,
327,
378,
88,
17,
66,
199,
7,
74,
297,
259,
327,
378,
88,
17,
67,
199,
7,
31623,
297,
259,
327,
378,
88,
17,
68,
199,
7,
9745,
297,
259,
327,
378,
88,
17,
69,
199,
1133,
84,
297,
259,
327,
378,
88,
17,
70,
199,
1133,
273,
297,
259,
327,
378,
88,
1165,
199,
5121,
68,
297,
259,
327,
378,
88,
2025,
199,
5121,
7821,
297,
259,
327,
378,
88,
1081,
199,
7,
4411,
297,
259,
327,
378,
88,
1789,
199,
1133,
297,
259,
327,
378,
88,
1194,
199,
1133,
72,
297,
259,
327,
378,
88,
821,
199,
5121,
297,
259,
327,
378,
88,
1479,
199,
5121,
72,
297,
259,
327,
378,
88,
1465,
199,
7,
78,
297,
259,
327,
378,
88,
1651,
199,
6880,
259,
327,
378,
88,
1398,
199,
7,
80,
297,
259,
327,
378,
88,
18,
65,
199,
7,
838,
297,
259,
327,
378,
88,
18,
66,
199,
7,
66,
297,
259,
327,
378,
88,
18,
67,
199,
7,
26397,
297,
259,
327,
378,
88,
18,
68,
199,
6704,
297,
259,
327,
378,
88,
18,
69,
199,
7,
89,
297,
259,
327,
378,
88,
18,
70,
199,
7,
82,
297,
259,
327,
378,
88,
1216,
199,
6880,
259,
327,
378,
88,
2192,
199,
7,
76,
297,
259,
327,
378,
88,
708,
199,
7171,
297,
259,
327,
378,
88,
1153,
199,
6880,
259,
327,
378,
88,
1082,
199,
6448,
259,
327,
378,
88,
1276,
199,
1159,
72,
297,
259,
327,
378,
88,
1344,
199,
1159,
83,
297,
259,
327,
378,
88,
1401,
199,
1159,
297,
259,
327,
378,
88,
1703,
199,
7,
72,
297,
259,
327,
378,
88,
1355,
199,
6880,
259,
327,
378,
88,
19,
65,
199,
6880,
259,
327,
378,
88,
19,
66,
199,
1154,
6448,
259,
327,
378,
88,
19,
67,
199,
1154,
6448,
259,
327,
378,
88,
19,
68,
199,
7,
2158,
297,
259,
327,
378,
88,
19,
69,
199,
7,
73,
297,
259,
327,
378,
88,
19,
70,
199,
7,
5908,
297,
259,
327,
378,
88,
2167,
199,
7,
85,
297,
259,
327,
378,
88,
2953,
199,
7,
17031,
297,
259,
327,
378,
88,
2260,
199,
7,
50,
297,
259,
327,
378,
88,
2824,
199,
6880,
259,
327,
378,
88,
1602,
199,
6880,
259,
327,
378,
88,
2322,
199,
6880,
259,
327,
378,
88,
2466,
199,
7,
69,
297,
259,
327,
378,
88,
2417,
199,
7,
5789,
297,
259,
327,
378,
88,
2006,
199,
6880,
259,
327,
378,
88,
1887,
199,
6880,
259,
327,
378,
88,
20,
65,
199,
7,
79,
297,
259,
327,
378,
88,
20,
66,
199,
7,
3844,
297,
259,
327,
378,
88,
20,
67,
199,
6448,
259,
327,
378,
88,
20,
68,
199,
6880,
259,
327,
378,
88,
20,
69,
199,
6880,
259,
327,
378,
88,
20,
70,
199,
6880,
259,
327,
378,
88,
1400,
199,
6880,
259,
327,
378,
88,
2869,
199,
6880,
259,
327,
378,
88,
2528,
199,
6880,
259,
327,
378,
88,
2481,
199,
6880,
259,
327,
378,
88,
1477,
199,
6880,
259,
327,
378,
88,
1229,
199,
6828,
297,
259,
327,
378,
88,
1367,
199,
6828,
297,
259,
327,
378,
88,
1641,
199,
6880,
259,
327,
378,
88,
2010,
199,
6880,
259,
327,
378,
88,
1427,
199,
6880,
259,
327,
378,
88,
21,
65,
199,
6880,
259,
327,
378,
88,
21,
66,
199,
7,
9734,
297,
259,
327,
378,
88,
21,
67,
199,
7,
17157,
297,
259,
327,
378,
88,
21,
68,
199,
6880,
259,
327,
378,
88,
21,
69,
199,
7,
7566,
297,
259,
327,
378,
88,
21,
70,
199,
7,
13381,
297,
259,
327,
378,
88,
2259,
199,
7,
4464,
297,
259,
327,
378,
88,
2976,
199,
6880,
259,
327,
378,
88,
2789,
199,
6880,
259,
327,
378,
88,
2766,
199,
6880,
259,
327,
378,
88,
772,
199,
6880,
259,
327,
378,
88,
2182,
199,
7,
16,
297,
259,
327,
378,
88,
1272,
199,
7,
17,
297,
259,
327,
378,
88,
1822,
199,
7,
18,
297,
259,
327,
378,
88,
2333,
199,
7,
19,
297,
259,
327,
378,
88,
1876,
199,
7,
20,
297,
259,
327,
378,
88,
22,
65,
199,
7,
21,
297,
259,
327,
378,
88,
22,
66,
199,
7,
22,
297,
259,
327,
378,
88,
22,
67,
199,
7,
23,
297,
259,
327,
378,
88,
22,
68,
199,
7,
24,
297,
259,
327,
378,
88,
22,
69,
199,
7,
25,
297,
259,
327,
378,
88,
22,
70,
199,
6448,
259,
327,
378,
88,
2760,
199,
6880,
259,
327,
378,
88,
3172,
199,
6880,
259,
327,
378,
88,
2819,
199,
6880,
259,
327,
378,
88,
2898,
199,
6880,
259,
327,
378,
88,
1342,
199,
6880,
259,
327,
378,
88,
2194,
199,
6880,
259,
327,
378,
88,
2114,
199
] |
[
275,
334,
199,
6880,
259,
327,
378,
88,
383,
199,
7,
46,
297,
259,
327,
378,
88,
614,
199,
7,
46,
297,
259,
327,
378,
88,
996,
199,
7,
40,
297,
259,
327,
378,
88,
1644,
199,
6880,
259,
327,
378,
88,
966,
199,
7,
65,
297,
259,
327,
378,
88,
1717,
199,
7,
2158,
297,
259,
327,
378,
88,
1690,
199,
7,
73,
297,
259,
327,
378,
88,
1780,
199,
7,
5908,
297,
259,
327,
378,
88,
2036,
199,
7,
85,
297,
259,
327,
378,
88,
1643,
199,
7,
17031,
297,
259,
327,
378,
88,
16,
65,
199,
7,
50,
297,
259,
327,
378,
88,
16,
66,
199,
7,
44,
297,
259,
327,
378,
88,
16,
67,
199,
6880,
259,
327,
378,
88,
16,
68,
199,
6880,
259,
327,
378,
88,
16,
69,
199,
7,
69,
297,
259,
327,
378,
88,
16,
70,
199,
7,
5789,
297,
259,
327,
378,
88,
709,
199,
6880,
259,
327,
378,
88,
845,
199,
6880,
259,
327,
378,
88,
713,
199,
7,
79,
297,
259,
327,
378,
88,
969,
199,
7,
3844,
297,
259,
327,
378,
88,
1079,
199,
7,
75,
297,
259,
327,
378,
88,
1046,
199,
7,
21889,
297,
259,
327,
378,
88,
975,
199,
7,
71,
297,
259,
327,
378,
88,
1196,
199,
7,
3561,
297,
259,
327,
378,
88,
1085,
199,
7,
2753,
297,
259,
327,
378,
88,
1167,
199,
7,
67,
297,
259,
327,
378,
88,
17,
65,
199,
7,
335,
297,
259,
327,
378,
88,
17,
66,
199,
7,
74,
297,
259,
327,
378,
88,
17,
67,
199,
7,
31623,
297,
259,
327,
378,
88,
17,
68,
199,
7,
9745,
297,
259,
327,
378,
88,
17,
69,
199,
1133,
84,
297,
259,
327,
378,
88,
17,
70,
199,
1133,
273,
297,
259,
327,
378,
88,
1165,
199,
5121,
68,
297,
259,
327,
378,
88,
2025,
199,
5121,
7821,
297,
259,
327,
378,
88,
1081,
199,
7,
4411,
297,
259,
327,
378,
88,
1789,
199,
1133,
297,
259,
327,
378,
88,
1194,
199,
1133,
72,
297,
259,
327,
378,
88,
821,
199,
5121,
297,
259,
327,
378,
88,
1479,
199,
5121,
72,
297,
259,
327,
378,
88,
1465,
199,
7,
78,
297,
259,
327,
378,
88,
1651,
199,
6880,
259,
327,
378,
88,
1398,
199,
7,
80,
297,
259,
327,
378,
88,
18,
65,
199,
7,
838,
297,
259,
327,
378,
88,
18,
66,
199,
7,
66,
297,
259,
327,
378,
88,
18,
67,
199,
7,
26397,
297,
259,
327,
378,
88,
18,
68,
199,
6704,
297,
259,
327,
378,
88,
18,
69,
199,
7,
89,
297,
259,
327,
378,
88,
18,
70,
199,
7,
82,
297,
259,
327,
378,
88,
1216,
199,
6880,
259,
327,
378,
88,
2192,
199,
7,
76,
297,
259,
327,
378,
88,
708,
199,
7171,
297,
259,
327,
378,
88,
1153,
199,
6880,
259,
327,
378,
88,
1082,
199,
6448,
259,
327,
378,
88,
1276,
199,
1159,
72,
297,
259,
327,
378,
88,
1344,
199,
1159,
83,
297,
259,
327,
378,
88,
1401,
199,
1159,
297,
259,
327,
378,
88,
1703,
199,
7,
72,
297,
259,
327,
378,
88,
1355,
199,
6880,
259,
327,
378,
88,
19,
65,
199,
6880,
259,
327,
378,
88,
19,
66,
199,
1154,
6448,
259,
327,
378,
88,
19,
67,
199,
1154,
6448,
259,
327,
378,
88,
19,
68,
199,
7,
2158,
297,
259,
327,
378,
88,
19,
69,
199,
7,
73,
297,
259,
327,
378,
88,
19,
70,
199,
7,
5908,
297,
259,
327,
378,
88,
2167,
199,
7,
85,
297,
259,
327,
378,
88,
2953,
199,
7,
17031,
297,
259,
327,
378,
88,
2260,
199,
7,
50,
297,
259,
327,
378,
88,
2824,
199,
6880,
259,
327,
378,
88,
1602,
199,
6880,
259,
327,
378,
88,
2322,
199,
6880,
259,
327,
378,
88,
2466,
199,
7,
69,
297,
259,
327,
378,
88,
2417,
199,
7,
5789,
297,
259,
327,
378,
88,
2006,
199,
6880,
259,
327,
378,
88,
1887,
199,
6880,
259,
327,
378,
88,
20,
65,
199,
7,
79,
297,
259,
327,
378,
88,
20,
66,
199,
7,
3844,
297,
259,
327,
378,
88,
20,
67,
199,
6448,
259,
327,
378,
88,
20,
68,
199,
6880,
259,
327,
378,
88,
20,
69,
199,
6880,
259,
327,
378,
88,
20,
70,
199,
6880,
259,
327,
378,
88,
1400,
199,
6880,
259,
327,
378,
88,
2869,
199,
6880,
259,
327,
378,
88,
2528,
199,
6880,
259,
327,
378,
88,
2481,
199,
6880,
259,
327,
378,
88,
1477,
199,
6880,
259,
327,
378,
88,
1229,
199,
6828,
297,
259,
327,
378,
88,
1367,
199,
6828,
297,
259,
327,
378,
88,
1641,
199,
6880,
259,
327,
378,
88,
2010,
199,
6880,
259,
327,
378,
88,
1427,
199,
6880,
259,
327,
378,
88,
21,
65,
199,
6880,
259,
327,
378,
88,
21,
66,
199,
7,
9734,
297,
259,
327,
378,
88,
21,
67,
199,
7,
17157,
297,
259,
327,
378,
88,
21,
68,
199,
6880,
259,
327,
378,
88,
21,
69,
199,
7,
7566,
297,
259,
327,
378,
88,
21,
70,
199,
7,
13381,
297,
259,
327,
378,
88,
2259,
199,
7,
4464,
297,
259,
327,
378,
88,
2976,
199,
6880,
259,
327,
378,
88,
2789,
199,
6880,
259,
327,
378,
88,
2766,
199,
6880,
259,
327,
378,
88,
772,
199,
6880,
259,
327,
378,
88,
2182,
199,
7,
16,
297,
259,
327,
378,
88,
1272,
199,
7,
17,
297,
259,
327,
378,
88,
1822,
199,
7,
18,
297,
259,
327,
378,
88,
2333,
199,
7,
19,
297,
259,
327,
378,
88,
1876,
199,
7,
20,
297,
259,
327,
378,
88,
22,
65,
199,
7,
21,
297,
259,
327,
378,
88,
22,
66,
199,
7,
22,
297,
259,
327,
378,
88,
22,
67,
199,
7,
23,
297,
259,
327,
378,
88,
22,
68,
199,
7,
24,
297,
259,
327,
378,
88,
22,
69,
199,
7,
25,
297,
259,
327,
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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
] |
ruslanloman/nova
|
nova/tests/unit/objects/test_dns_domain.py
|
70
|
3002
|
# Copyright (C) 2014, Red Hat, 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 mock
from nova import db
from nova.objects import dns_domain
from nova.tests.unit.objects import test_objects
fake_dnsd = {
'created_at': None,
'updated_at': None,
'deleted_at': None,
'deleted': 0,
'domain': 'blah.example.com',
'scope': 'private',
'availability_zone': 'overthere',
'project_id': '867530niner',
}
class _TestDNSDomain(object):
@staticmethod
def _compare(test, db, obj):
for field, value in db.items():
test.assertEqual(db[field], obj[field])
def test_get_by_domain(self):
with mock.patch.object(db, 'dnsdomain_get') as get:
get.return_value = fake_dnsd
dnsd = dns_domain.DNSDomain.get_by_domain(self.context, 'domain')
self._compare(self, fake_dnsd, dnsd)
def test_register_for_zone(self):
dns_domain.DNSDomain.register_for_zone(self.context.elevated(),
'domain', 'zone')
dnsd = dns_domain.DNSDomain.get_by_domain(self.context, 'domain')
self.assertEqual('domain', dnsd.domain)
self.assertEqual('zone', dnsd.availability_zone)
def test_register_for_project(self):
dns_domain.DNSDomain.register_for_project(self.context.elevated(),
'domain', 'project')
dnsd = dns_domain.DNSDomain.get_by_domain(self.context, 'domain')
self.assertEqual('domain', dnsd.domain)
self.assertEqual('project', dnsd.project_id)
def test_delete_by_domain(self):
dns_domain.DNSDomain.register_for_zone(self.context.elevated(),
'domain', 'zone')
dnsd = dns_domain.DNSDomain.get_by_domain(self.context, 'domain')
self.assertEqual('domain', dnsd.domain)
self.assertEqual('zone', dnsd.availability_zone)
dns_domain.DNSDomain.delete_by_domain(self.context.elevated(),
'domain')
dnsd = dns_domain.DNSDomain.get_by_domain(self.context, 'domain')
self.assertIsNone(dnsd)
def test_get_all(self):
with mock.patch.object(db, 'dnsdomain_get_all') as get:
get.return_value = [fake_dnsd]
dns_domain.DNSDomainList.get_all(self.context)
class TestDNSDomainObject(test_objects._LocalTest,
_TestDNSDomain):
pass
class TestRemoteDNSDomainObject(test_objects._RemoteTest,
_TestDNSDomain):
pass
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
6927,
12,
9572,
13002,
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,
1683,
199,
199,
504,
5913,
492,
1592,
199,
504,
5913,
14,
1462,
492,
6715,
63,
2261,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1462,
492,
511,
63,
1462,
421,
199,
3183,
63,
5797,
68,
275,
469,
272,
283,
3966,
63,
292,
356,
488,
12,
272,
283,
5334,
63,
292,
356,
488,
12,
272,
283,
6062,
63,
292,
356,
488,
12,
272,
283,
6062,
356,
378,
12,
272,
283,
2261,
356,
283,
12702,
14,
2694,
14,
957,
297,
272,
283,
2645,
356,
283,
4239,
297,
272,
283,
11856,
63,
2619,
356,
283,
1883,
16990,
297,
272,
283,
1715,
63,
344,
356,
283,
1184,
2194,
1216,
78,
16187,
297,
199,
93,
421,
199,
533,
485,
774,
12323,
7705,
8,
785,
304,
272,
768,
4639,
272,
347,
485,
5785,
8,
396,
12,
1592,
12,
1559,
304,
267,
367,
901,
12,
574,
315,
1592,
14,
1744,
837,
288,
511,
14,
629,
8,
697,
59,
698,
467,
1559,
59,
698,
566,
339,
347,
511,
63,
362,
63,
991,
63,
2261,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
697,
12,
283,
5797,
2261,
63,
362,
358,
465,
664,
26,
288,
664,
14,
1107,
63,
585,
275,
4026,
63,
5797,
68,
288,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
288,
291,
423,
5785,
8,
277,
12,
4026,
63,
5797,
68,
12,
6715,
68,
9,
339,
347,
511,
63,
2683,
63,
509,
63,
2619,
8,
277,
304,
267,
6715,
63,
2261,
14,
12323,
7705,
14,
2683,
63,
509,
63,
2619,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
297,
283,
2619,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
629,
360,
2261,
297,
6715,
68,
14,
2261,
9,
267,
291,
14,
629,
360,
2619,
297,
6715,
68,
14,
11856,
63,
2619,
9,
339,
347,
511,
63,
2683,
63,
509,
63,
1715,
8,
277,
304,
267,
6715,
63,
2261,
14,
12323,
7705,
14,
2683,
63,
509,
63,
1715,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
297,
283,
1715,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
629,
360,
2261,
297,
6715,
68,
14,
2261,
9,
267,
291,
14,
629,
360,
1715,
297,
6715,
68,
14,
1715,
63,
344,
9,
339,
347,
511,
63,
1807,
63,
991,
63,
2261,
8,
277,
304,
267,
6715,
63,
2261,
14,
12323,
7705,
14,
2683,
63,
509,
63,
2619,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
297,
283,
2619,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
629,
360,
2261,
297,
6715,
68,
14,
2261,
9,
267,
291,
14,
629,
360,
2619,
297,
6715,
68,
14,
11856,
63,
2619,
9,
398,
6715,
63,
2261,
14,
12323,
7705,
14,
1807,
63,
991,
63,
2261,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
7702,
8,
5797,
68,
9,
339,
347,
511,
63,
362,
63,
452,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
697,
12,
283,
5797,
2261,
63,
362,
63,
452,
358,
465,
664,
26,
288,
664,
14,
1107,
63,
585,
275,
359,
3183,
63,
5797,
68,
61,
288,
6715,
63,
2261,
14,
12323,
7705,
1296,
14,
362,
63,
452,
8,
277,
14,
1100,
9,
421,
199,
533,
1379,
12323,
7705,
1692,
8,
396,
63,
1462,
423,
5339,
774,
12,
2079,
485,
774,
12323,
7705,
304,
272,
986,
421,
199,
533,
1379,
6713,
12323,
7705,
1692,
8,
396,
63,
1462,
423,
6713,
774,
12,
1816,
485,
774,
12323,
7705,
304,
272,
986,
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
] |
[
1898,
334,
35,
9,
6927,
12,
9572,
13002,
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,
1683,
199,
199,
504,
5913,
492,
1592,
199,
504,
5913,
14,
1462,
492,
6715,
63,
2261,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1462,
492,
511,
63,
1462,
421,
199,
3183,
63,
5797,
68,
275,
469,
272,
283,
3966,
63,
292,
356,
488,
12,
272,
283,
5334,
63,
292,
356,
488,
12,
272,
283,
6062,
63,
292,
356,
488,
12,
272,
283,
6062,
356,
378,
12,
272,
283,
2261,
356,
283,
12702,
14,
2694,
14,
957,
297,
272,
283,
2645,
356,
283,
4239,
297,
272,
283,
11856,
63,
2619,
356,
283,
1883,
16990,
297,
272,
283,
1715,
63,
344,
356,
283,
1184,
2194,
1216,
78,
16187,
297,
199,
93,
421,
199,
533,
485,
774,
12323,
7705,
8,
785,
304,
272,
768,
4639,
272,
347,
485,
5785,
8,
396,
12,
1592,
12,
1559,
304,
267,
367,
901,
12,
574,
315,
1592,
14,
1744,
837,
288,
511,
14,
629,
8,
697,
59,
698,
467,
1559,
59,
698,
566,
339,
347,
511,
63,
362,
63,
991,
63,
2261,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
697,
12,
283,
5797,
2261,
63,
362,
358,
465,
664,
26,
288,
664,
14,
1107,
63,
585,
275,
4026,
63,
5797,
68,
288,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
288,
291,
423,
5785,
8,
277,
12,
4026,
63,
5797,
68,
12,
6715,
68,
9,
339,
347,
511,
63,
2683,
63,
509,
63,
2619,
8,
277,
304,
267,
6715,
63,
2261,
14,
12323,
7705,
14,
2683,
63,
509,
63,
2619,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
297,
283,
2619,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
629,
360,
2261,
297,
6715,
68,
14,
2261,
9,
267,
291,
14,
629,
360,
2619,
297,
6715,
68,
14,
11856,
63,
2619,
9,
339,
347,
511,
63,
2683,
63,
509,
63,
1715,
8,
277,
304,
267,
6715,
63,
2261,
14,
12323,
7705,
14,
2683,
63,
509,
63,
1715,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
297,
283,
1715,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
629,
360,
2261,
297,
6715,
68,
14,
2261,
9,
267,
291,
14,
629,
360,
1715,
297,
6715,
68,
14,
1715,
63,
344,
9,
339,
347,
511,
63,
1807,
63,
991,
63,
2261,
8,
277,
304,
267,
6715,
63,
2261,
14,
12323,
7705,
14,
2683,
63,
509,
63,
2619,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
297,
283,
2619,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
629,
360,
2261,
297,
6715,
68,
14,
2261,
9,
267,
291,
14,
629,
360,
2619,
297,
6715,
68,
14,
11856,
63,
2619,
9,
398,
6715,
63,
2261,
14,
12323,
7705,
14,
1807,
63,
991,
63,
2261,
8,
277,
14,
1100,
14,
32168,
1062,
355,
283,
2261,
358,
267,
6715,
68,
275,
6715,
63,
2261,
14,
12323,
7705,
14,
362,
63,
991,
63,
2261,
8,
277,
14,
1100,
12,
283,
2261,
358,
267,
291,
14,
7702,
8,
5797,
68,
9,
339,
347,
511,
63,
362,
63,
452,
8,
277,
304,
267,
543,
1683,
14,
2068,
14,
785,
8,
697,
12,
283,
5797,
2261,
63,
362,
63,
452,
358,
465,
664,
26,
288,
664,
14,
1107,
63,
585,
275,
359,
3183,
63,
5797,
68,
61,
288,
6715,
63,
2261,
14,
12323,
7705,
1296,
14,
362,
63,
452,
8,
277,
14,
1100,
9,
421,
199,
533,
1379,
12323,
7705,
1692,
8,
396,
63,
1462,
423,
5339,
774,
12,
2079,
485,
774,
12323,
7705,
304,
272,
986,
421,
199,
533,
1379,
6713,
12323,
7705,
1692,
8,
396,
63,
1462,
423,
6713,
774,
12,
1816,
485,
774,
12323,
7705,
304,
272,
986,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mgit-at/ansible
|
lib/ansible/module_utils/network/aruba/aruba.py
|
84
|
4862
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# (c) 2016 Red Hat Inc.
#
# 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.
#
# 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 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
import re
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import env_fallback, return_values
from ansible.module_utils.network.common.utils import to_list, ComplexList
from ansible.module_utils.connection import exec_command
_DEVICE_CONFIGS = {}
aruba_provider_spec = {
'host': dict(),
'port': dict(type='int'),
'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True),
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
'timeout': dict(type='int'),
}
aruba_argument_spec = {
'provider': dict(type='dict', options=aruba_provider_spec)
}
aruba_top_spec = {
'host': dict(removed_in_version=2.9),
'port': dict(removed_in_version=2.9, type='int'),
'username': dict(removed_in_version=2.9),
'password': dict(removed_in_version=2.9, no_log=True),
'ssh_keyfile': dict(removed_in_version=2.9, type='path'),
'timeout': dict(removed_in_version=2.9, type='int'),
}
aruba_argument_spec.update(aruba_top_spec)
def get_provider_argspec():
return aruba_provider_spec
def check_args(module, warnings):
pass
def get_config(module, flags=None):
flags = [] if flags is None else flags
cmd = 'show running-config '
cmd += ' '.join(flags)
cmd = cmd.strip()
try:
return _DEVICE_CONFIGS[cmd]
except KeyError:
rc, out, err = exec_command(module, cmd)
if rc != 0:
module.fail_json(msg='unable to retrieve current config', stderr=to_text(err, errors='surrogate_then_replace'))
cfg = sanitize(to_text(out, errors='surrogate_then_replace').strip())
_DEVICE_CONFIGS[cmd] = cfg
return cfg
def sanitize(resp):
# Takes response from device and adjusts leading whitespace to just 1 space
cleaned = []
for line in resp.splitlines():
cleaned.append(re.sub(r"^\s+", " ", line))
return '\n'.join(cleaned).strip()
def to_commands(module, commands):
spec = {
'command': dict(key=True),
'prompt': dict(),
'answer': dict()
}
transform = ComplexList(spec, module)
return transform(commands)
def run_commands(module, commands, check_rc=True):
responses = list()
commands = to_commands(module, to_list(commands))
for cmd in commands:
cmd = module.jsonify(cmd)
rc, out, err = exec_command(module, cmd)
if check_rc and rc != 0:
module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), rc=rc)
responses.append(to_text(out, errors='surrogate_then_replace'))
return responses
def load_config(module, commands):
rc, out, err = exec_command(module, 'configure terminal')
if rc != 0:
module.fail_json(msg='unable to enter configuration mode', err=to_text(out, errors='surrogate_then_replace'))
for command in to_list(commands):
if command == 'end':
continue
rc, out, err = exec_command(module, command)
if rc != 0:
module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), command=command, rc=rc)
exec_command(module, 'end')
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2589,
63,
10538,
12,
372,
63,
1459,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
1208,
492,
370,
63,
513,
12,
19178,
1296,
199,
504,
3242,
14,
578,
63,
1208,
14,
2105,
492,
2146,
63,
1531,
199,
199,
63,
10555,
63,
5569,
51,
275,
1052,
199,
199,
285,
9405,
63,
3780,
63,
1650,
275,
469,
272,
283,
1102,
356,
1211,
1062,
272,
283,
719,
356,
1211,
8,
466,
534,
442,
659,
272,
283,
2473,
356,
1211,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
8490,
63,
7278,
63,
11958,
16607,
272,
283,
2060,
356,
1211,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
8490,
63,
7278,
63,
9032,
3815,
949,
63,
793,
29,
549,
395,
272,
283,
5510,
63,
21856,
356,
1211,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
8490,
63,
7278,
63,
13716,
63,
3078,
3817,
3815,
730,
534,
515,
659,
272,
283,
2593,
356,
1211,
8,
466,
534,
442,
659,
199,
93,
199,
285,
9405,
63,
2094,
63,
1650,
275,
469,
272,
283,
3780,
356,
1211,
8,
466,
534,
807,
297,
1511,
29,
285,
9405,
63,
3780,
63,
1650,
9,
199,
93,
199,
199,
285,
9405,
63,
2119,
63,
1650,
275,
469,
272,
283,
1102,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
395,
272,
283,
719,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
730,
534,
442,
659,
272,
283,
2473,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
395,
272,
283,
2060,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
949,
63,
793,
29,
549,
395,
272,
283,
5510,
63,
21856,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
730,
534,
515,
659,
272,
283,
2593,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
730,
534,
442,
659,
199,
93,
199,
199,
285,
9405,
63,
2094,
63,
1650,
14,
873,
8,
285,
9405,
63,
2119,
63,
1650,
9,
421,
199,
318,
664,
63,
3780,
63,
15644,
837,
272,
372,
601,
9405,
63,
3780,
63,
1650,
421,
199,
318,
1104,
63,
589,
8,
578,
12,
3598,
304,
272,
986,
421,
199,
318,
664,
63,
888,
8,
578,
12,
3285,
29,
403,
304,
272,
3285,
275,
942,
340,
3285,
365,
488,
587,
3285,
339,
2088,
275,
283,
2384,
3879,
13,
888,
283,
272,
2088,
847,
283,
1987,
904,
8,
2469,
9,
272,
2088,
275,
2088,
14,
1913,
342,
339,
862,
26,
267,
372,
485,
10555,
63,
5569,
51,
59,
1760,
61,
272,
871,
4067,
26,
267,
4819,
12,
734,
12,
2329,
275,
2146,
63,
1531,
8,
578,
12,
2088,
9,
267,
340,
4819,
1137,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
534,
17200,
370,
8044,
1453,
1101,
297,
4635,
29,
475,
63,
505,
8,
1508,
12,
2552,
534,
16380,
63,
12726,
63,
1814,
1333,
267,
4810,
275,
21077,
8,
475,
63,
505,
8,
548,
12,
2552,
534,
16380,
63,
12726,
63,
1814,
1959,
1913,
1012,
267,
485,
10555,
63,
5569,
51,
59,
1760,
61,
275,
4810,
267,
372,
4810,
421,
199,
318,
21077,
8,
4518,
304,
272,
327,
17415,
1177,
687,
2243,
436,
11311,
83,
9186,
8139,
370,
2951,
413,
4601,
272,
12364,
275,
942,
272,
367,
1004,
315,
3085,
14,
7644,
837,
267,
12364,
14,
740,
8,
264,
14,
954,
8,
82,
2,
12773,
83,
22758,
298,
3872,
1004,
430,
272,
372,
1557,
78,
1370,
904,
8,
8275,
680,
1913,
342,
421,
199,
318,
370,
63,
4405,
8,
578,
12,
3718,
304,
272,
3158,
275,
469,
267,
283,
1531,
356,
1211,
8,
498,
29,
549,
395,
267,
283,
7650,
356,
1211,
1062,
267,
283,
5934,
356,
1211,
342,
272,
789,
272,
5793,
275,
19178,
1296,
8,
1650,
12,
859,
9,
272,
372,
5793,
8,
4405,
9,
421,
199,
318,
1255,
63,
4405,
8,
578,
12,
3718,
12,
1104,
63,
1195
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
2589,
63,
10538,
12,
372,
63,
1459,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
2330,
14,
1208,
492,
370,
63,
513,
12,
19178,
1296,
199,
504,
3242,
14,
578,
63,
1208,
14,
2105,
492,
2146,
63,
1531,
199,
199,
63,
10555,
63,
5569,
51,
275,
1052,
199,
199,
285,
9405,
63,
3780,
63,
1650,
275,
469,
272,
283,
1102,
356,
1211,
1062,
272,
283,
719,
356,
1211,
8,
466,
534,
442,
659,
272,
283,
2473,
356,
1211,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
8490,
63,
7278,
63,
11958,
16607,
272,
283,
2060,
356,
1211,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
8490,
63,
7278,
63,
9032,
3815,
949,
63,
793,
29,
549,
395,
272,
283,
5510,
63,
21856,
356,
1211,
8,
10538,
2687,
1813,
63,
10538,
12,
788,
8490,
63,
7278,
63,
13716,
63,
3078,
3817,
3815,
730,
534,
515,
659,
272,
283,
2593,
356,
1211,
8,
466,
534,
442,
659,
199,
93,
199,
285,
9405,
63,
2094,
63,
1650,
275,
469,
272,
283,
3780,
356,
1211,
8,
466,
534,
807,
297,
1511,
29,
285,
9405,
63,
3780,
63,
1650,
9,
199,
93,
199,
199,
285,
9405,
63,
2119,
63,
1650,
275,
469,
272,
283,
1102,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
395,
272,
283,
719,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
730,
534,
442,
659,
272,
283,
2473,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
395,
272,
283,
2060,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
949,
63,
793,
29,
549,
395,
272,
283,
5510,
63,
21856,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
730,
534,
515,
659,
272,
283,
2593,
356,
1211,
8,
10649,
63,
262,
63,
1023,
29,
18,
14,
25,
12,
730,
534,
442,
659,
199,
93,
199,
199,
285,
9405,
63,
2094,
63,
1650,
14,
873,
8,
285,
9405,
63,
2119,
63,
1650,
9,
421,
199,
318,
664,
63,
3780,
63,
15644,
837,
272,
372,
601,
9405,
63,
3780,
63,
1650,
421,
199,
318,
1104,
63,
589,
8,
578,
12,
3598,
304,
272,
986,
421,
199,
318,
664,
63,
888,
8,
578,
12,
3285,
29,
403,
304,
272,
3285,
275,
942,
340,
3285,
365,
488,
587,
3285,
339,
2088,
275,
283,
2384,
3879,
13,
888,
283,
272,
2088,
847,
283,
1987,
904,
8,
2469,
9,
272,
2088,
275,
2088,
14,
1913,
342,
339,
862,
26,
267,
372,
485,
10555,
63,
5569,
51,
59,
1760,
61,
272,
871,
4067,
26,
267,
4819,
12,
734,
12,
2329,
275,
2146,
63,
1531,
8,
578,
12,
2088,
9,
267,
340,
4819,
1137,
378,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
534,
17200,
370,
8044,
1453,
1101,
297,
4635,
29,
475,
63,
505,
8,
1508,
12,
2552,
534,
16380,
63,
12726,
63,
1814,
1333,
267,
4810,
275,
21077,
8,
475,
63,
505,
8,
548,
12,
2552,
534,
16380,
63,
12726,
63,
1814,
1959,
1913,
1012,
267,
485,
10555,
63,
5569,
51,
59,
1760,
61,
275,
4810,
267,
372,
4810,
421,
199,
318,
21077,
8,
4518,
304,
272,
327,
17415,
1177,
687,
2243,
436,
11311,
83,
9186,
8139,
370,
2951,
413,
4601,
272,
12364,
275,
942,
272,
367,
1004,
315,
3085,
14,
7644,
837,
267,
12364,
14,
740,
8,
264,
14,
954,
8,
82,
2,
12773,
83,
22758,
298,
3872,
1004,
430,
272,
372,
1557,
78,
1370,
904,
8,
8275,
680,
1913,
342,
421,
199,
318,
370,
63,
4405,
8,
578,
12,
3718,
304,
272,
3158,
275,
469,
267,
283,
1531,
356,
1211,
8,
498,
29,
549,
395,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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
] |
ac769/continuum_technologies
|
twitter/sample_twitter_codes.py
|
1
|
1644
|
''''
In this code we'll have a bunch of examples you can use at your own discretion.
Simply remove the three ' marks above and below the code you want in order to run it, while
leaving the text within a new set of three ' marks.
Once that's done, go to your Terminal, navigate to where this code and the twitter_follow_bot
code is (they have to be in the same folder), and just type in "python sample_twitter_codes.py" (without quotes)
WARNING: Following too many people, favoriting too many things, CAN and WILL get you banned.
Be smart. And have fun :).
Justin and Nat
'''
'''
#1 Here you can automatically follow people who tweet about a certain phrase. Just replace the phrase
with something relevant to you! Also you can set the count to whatever makes you most comfortable.
'''
#from twitter_follow_bot import auto_follow
#auto_follow("sharing economy 2.0", count=100)
'''
#2 In this code, change "jwmares" to the twitter handle whose followers you want to follow,
and set the count to how many people should be followed. Default is 100.
'''
#from twitter_follow_bot import auto_follow_followers_for_user
#auto_follow_followers_for_user("@InnoCentive", count=100)
'''
#3 This code will let you favourite things that are relevant to you. Just replace "phrase" with the phrase
you want to favorite for, and set the count to how many things you want to favorite.
'''
#from twitter_follow_bot import auto_fav
#auto_fav("#openinnovation", count=100)
'''
#4 This code will automatically un-follow everyone who hasn't followed you back.
from twitter_follow_bot import auto_unfollow_nonfollowers
auto_unfollow_nonfollowers()
'''
|
mit
|
[
17701,
199,
607,
642,
1233,
781,
7171,
1172,
282,
22219,
402,
7251,
1265,
883,
675,
737,
2195,
5705,
4339,
264,
296,
14,
9948,
199,
51,
3236,
590,
2813,
314,
7795,
283,
17370,
3432,
436,
5084,
314,
1233,
1265,
2934,
315,
1865,
370,
1255,
652,
12,
1830,
199,
274,
5519,
314,
1318,
4453,
282,
892,
663,
402,
7795,
283,
17370,
14,
199,
199,
25690,
626,
1159,
4224,
12,
2621,
370,
2195,
20429,
279,
12,
20850,
370,
2382,
642,
1233,
436,
314,
15811,
63,
7207,
63,
3018,
199,
600,
365,
334,
29002,
1172,
370,
506,
315,
314,
2011,
4922,
395,
436,
2951,
730,
315,
298,
1548,
2690,
63,
13746,
63,
6021,
14,
647,
2,
334,
7395,
9344,
9,
199,
199,
9171,
26,
21876,
316,
4634,
5002,
13135,
12,
17914,
390,
316,
4634,
5002,
7645,
12,
29661,
436,
644,
14961,
664,
1265,
330,
9386,
14,
199,
199,
3655,
11179,
14,
6061,
1172,
9627,
520,
680,
9948,
199,
22850,
262,
436,
653,
292,
199,
2344,
199,
199,
2344,
199,
3,
17,
11842,
1265,
883,
5847,
2035,
13135,
3963,
21217,
3595,
282,
9842,
21621,
14,
13870,
3350,
314,
21621,
199,
1045,
6020,
12082,
370,
1265,
1,
6121,
1265,
883,
663,
314,
2338,
370,
15685,
7704,
1265,
4750,
2414,
10279,
461,
14,
199,
2344,
199,
199,
3,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
7207,
199,
3,
2495,
63,
7207,
480,
29122,
325,
25129,
89,
499,
14,
16,
401,
2338,
29,
1960,
9,
421,
199,
2344,
199,
3,
18,
1010,
642,
1233,
12,
1570,
298,
30561,
391,
470,
2,
370,
314,
15811,
2429,
7447,
31474,
1265,
2934,
370,
2035,
12,
221,
199,
460,
663,
314,
2338,
370,
4212,
5002,
13135,
1077,
506,
9437,
14,
3758,
365,
2948,
14,
199,
2344,
199,
199,
3,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
7207,
63,
22648,
63,
509,
63,
751,
199,
3,
2495,
63,
7207,
63,
22648,
63,
509,
63,
751,
25915,
607,
889,
18345,
857,
401,
2338,
29,
1960,
9,
421,
199,
2344,
199,
3,
19,
961,
1233,
911,
4691,
1265,
289,
1214,
567,
1175,
7645,
626,
787,
12082,
370,
1265,
14,
13870,
3350,
298,
10906,
2,
543,
314,
21621,
199,
13297,
2934,
370,
17914,
1175,
367,
12,
436,
663,
314,
2338,
370,
4212,
5002,
7645,
1265,
2934,
370,
17914,
1175,
14,
199,
2344,
199,
199,
3,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
30763,
199,
3,
2495,
63,
30763,
10064,
1490,
262,
889,
4255,
401,
2338,
29,
1960,
9,
199,
199,
2344,
199,
3,
20,
961,
1233,
911,
5847,
625,
13,
7207,
4036,
368,
3963,
18699,
1133,
9437,
1265,
1771,
14,
199,
199,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
324,
7207,
63,
2865,
22648,
199,
2495,
63,
324,
7207,
63,
2865,
22648,
342,
199,
2344,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
607,
642,
1233,
781,
7171,
1172,
282,
22219,
402,
7251,
1265,
883,
675,
737,
2195,
5705,
4339,
264,
296,
14,
9948,
199,
51,
3236,
590,
2813,
314,
7795,
283,
17370,
3432,
436,
5084,
314,
1233,
1265,
2934,
315,
1865,
370,
1255,
652,
12,
1830,
199,
274,
5519,
314,
1318,
4453,
282,
892,
663,
402,
7795,
283,
17370,
14,
199,
199,
25690,
626,
1159,
4224,
12,
2621,
370,
2195,
20429,
279,
12,
20850,
370,
2382,
642,
1233,
436,
314,
15811,
63,
7207,
63,
3018,
199,
600,
365,
334,
29002,
1172,
370,
506,
315,
314,
2011,
4922,
395,
436,
2951,
730,
315,
298,
1548,
2690,
63,
13746,
63,
6021,
14,
647,
2,
334,
7395,
9344,
9,
199,
199,
9171,
26,
21876,
316,
4634,
5002,
13135,
12,
17914,
390,
316,
4634,
5002,
7645,
12,
29661,
436,
644,
14961,
664,
1265,
330,
9386,
14,
199,
199,
3655,
11179,
14,
6061,
1172,
9627,
520,
680,
9948,
199,
22850,
262,
436,
653,
292,
199,
2344,
199,
199,
2344,
199,
3,
17,
11842,
1265,
883,
5847,
2035,
13135,
3963,
21217,
3595,
282,
9842,
21621,
14,
13870,
3350,
314,
21621,
199,
1045,
6020,
12082,
370,
1265,
1,
6121,
1265,
883,
663,
314,
2338,
370,
15685,
7704,
1265,
4750,
2414,
10279,
461,
14,
199,
2344,
199,
199,
3,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
7207,
199,
3,
2495,
63,
7207,
480,
29122,
325,
25129,
89,
499,
14,
16,
401,
2338,
29,
1960,
9,
421,
199,
2344,
199,
3,
18,
1010,
642,
1233,
12,
1570,
298,
30561,
391,
470,
2,
370,
314,
15811,
2429,
7447,
31474,
1265,
2934,
370,
2035,
12,
221,
199,
460,
663,
314,
2338,
370,
4212,
5002,
13135,
1077,
506,
9437,
14,
3758,
365,
2948,
14,
199,
2344,
199,
199,
3,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
7207,
63,
22648,
63,
509,
63,
751,
199,
3,
2495,
63,
7207,
63,
22648,
63,
509,
63,
751,
25915,
607,
889,
18345,
857,
401,
2338,
29,
1960,
9,
421,
199,
2344,
199,
3,
19,
961,
1233,
911,
4691,
1265,
289,
1214,
567,
1175,
7645,
626,
787,
12082,
370,
1265,
14,
13870,
3350,
298,
10906,
2,
543,
314,
21621,
199,
13297,
2934,
370,
17914,
1175,
367,
12,
436,
663,
314,
2338,
370,
4212,
5002,
7645,
1265,
2934,
370,
17914,
1175,
14,
199,
2344,
199,
199,
3,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
30763,
199,
3,
2495,
63,
30763,
10064,
1490,
262,
889,
4255,
401,
2338,
29,
1960,
9,
199,
199,
2344,
199,
3,
20,
961,
1233,
911,
5847,
625,
13,
7207,
4036,
368,
3963,
18699,
1133,
9437,
1265,
1771,
14,
199,
199,
504,
15811,
63,
7207,
63,
3018,
492,
2599,
63,
324,
7207,
63,
2865,
22648,
199,
2495,
63,
324,
7207,
63,
2865,
22648,
342,
199,
2344,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
e-gob/plataforma-kioscos-autoatencion
|
scripts/ansible-play/.venv/lib/python2.7/site-packages/ansible/modules/network/netvisor/pn_vlag.py
|
29
|
10765
|
#!/usr/bin/python
""" PN CLI vlag-create/vlag-delete/vlag-modify """
#
# 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.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = """
---
module: pn_vlag
author: "Pluribus Networks (@amitsi)"
version_added: "2.2"
short_description: CLI command to create/delete/modify vlag.
description:
- Execute vlag-create/vlag-delete/vlag-modify command.
- A virtual link aggregation group (VLAG) allows links that are physically
connected to two different Pluribus Networks devices to appear as a single
trunk to a third device. The third device can be a switch, server, or any
Ethernet device. A VLAG can provide Layer 2 multipathing, which allows you
to create redundancy by increasing bandwidth, enabling multiple parallel
paths between nodes and loadbalancing traffic where alternative paths exist.
options:
pn_cliusername:
description:
- Provide login username if user is not root.
required: False
pn_clipassword:
description:
- Provide login password if user is not root.
required: False
pn_cliswitch:
description:
- Target switch(es) to run this command on.
state:
description:
- State the action to perform. Use 'present' to create vlag,
'absent' to delete vlag and 'update' to modify vlag.
required: True
choices: ['present', 'absent', 'update']
pn_name:
description:
- The C(pn_name) takes a valid name for vlag configuration.
required: true
pn_port:
description:
- Specify the local VLAG port.
- Required for vlag-create.
pn_peer_port:
description:
- Specify the peer VLAG port.
- Required for vlag-create.
pn_mode:
description:
- Specify the mode for the VLAG. Active-standby indicates one side is
active and the other side is in standby mode. Active-active indicates
that both sides of the vlag are up by default.
choices: ['active-active', 'active-standby']
pn_peer_switch:
description:
- Specify the fabric-name of the peer switch.
pn_failover_action:
description:
- Specify the failover action as move or ignore.
choices: ['move', 'ignore']
pn_lacp_mode:
description:
- Specify the LACP mode.
choices: ['off', 'passive', 'active']
pn_lacp_timeout:
description:
- Specify the LACP timeout as slow(30 seconds) or fast(4 seconds).
choices: ['slow', 'fast']
pn_lacp_fallback:
description:
- Specify the LACP fallback mode as bundles or individual.
choices: ['bundle', 'individual']
pn_lacp_fallback_timeout:
description:
- Specify the LACP fallback timeout in seconds. The range is between 30
and 60 seconds with a default value of 50 seconds.
"""
EXAMPLES = """
- name: create a VLAG
pn_vlag:
state: 'present'
pn_name: spine-to-leaf
pn_port: 'spine01-to-leaf'
pn_peer_port: 'spine02-to-leaf'
pn_peer_switch: spine02
pn_mode: 'active-active'
- name: delete VLAGs
pn_vlag:
state: 'absent'
pn_name: spine-to-leaf
"""
RETURN = """
command:
description: The CLI command run on the target node(s).
returned: always
type: str
stdout:
description: The set of responses from the vlag command.
returned: always
type: list
stderr:
description: The set of error responses from the vlag command.
returned: on error
type: list
changed:
description: Indicates whether the CLI caused changes on the target.
returned: always
type: bool
"""
import shlex
VLAG_EXISTS = None
def pn_cli(module):
"""
This method is to generate the cli portion to launch the Netvisor cli.
It parses the username, password, switch parameters from module.
:param module: The Ansible module to fetch username, password and switch
:return: returns the cli string for further processing
"""
username = module.params['pn_cliusername']
password = module.params['pn_clipassword']
cliswitch = module.params['pn_cliswitch']
if username and password:
cli = '/usr/bin/cli --quiet --user %s:%s ' % (username, password)
else:
cli = '/usr/bin/cli --quiet '
if cliswitch == 'local':
cli += ' switch-local '
else:
cli += ' switch ' + cliswitch
return cli
def check_cli(module, cli):
"""
This method checks for idempotency using the vlag-show command.
If a vlag with given vlag exists, return VLAG_EXISTS as True else False.
:param module: The Ansible module to fetch input parameters
:param cli: The CLI string
:return Global Booleans: VLAG_EXISTS
"""
name = module.params['pn_name']
show = cli + ' vlag-show format name no-show-headers'
show = shlex.split(show)
out = module.run_command(show)[1]
out = out.split()
# Global flags
global VLAG_EXISTS
if name in out:
VLAG_EXISTS = True
else:
VLAG_EXISTS = False
def run_cli(module, cli):
"""
This method executes the cli command on the target node(s) and returns the
output. The module then exits based on the output.
:param cli: the complete cli string to be executed on the target node(s).
:param module: The Ansible module to fetch command
"""
cliswitch = module.params['pn_cliswitch']
state = module.params['state']
command = get_command_from_state(state)
cmd = shlex.split(cli)
# 'out' contains the output
# 'err' contains the error messages
result, out, err = module.run_command(cmd)
print_cli = cli.split(cliswitch)[1]
# Response in JSON format
if result != 0:
module.exit_json(
command=print_cli,
stderr=err.strip(),
msg="%s operation failed" % command,
changed=False
)
if out:
module.exit_json(
command=print_cli,
stdout=out.strip(),
msg="%s operation completed" % command,
changed=True
)
else:
module.exit_json(
command=print_cli,
msg="%s operation completed" % command,
changed=True
)
def get_command_from_state(state):
"""
This method gets appropriate command name for the state specified. It
returns the command name for the specified state.
:param state: The state for which the respective command name is required.
"""
command = None
if state == 'present':
command = 'vlag-create'
if state == 'absent':
command = 'vlag-delete'
if state == 'update':
command = 'vlag-modify'
return command
def main():
""" This section is for argument parsing """
module = AnsibleModule(
argument_spec=dict(
pn_cliusername=dict(required=False, type='str'),
pn_clipassword=dict(required=False, type='str', no_log=True),
pn_cliswitch=dict(required=False, type='str', default='local'),
state =dict(required=True, type='str',
choices=['present', 'absent', 'update']),
pn_name=dict(required=True, type='str'),
pn_port=dict(type='str'),
pn_peer_port=dict(type='str'),
pn_mode=dict(type='str', choices=[
'active-standby', 'active-active']),
pn_peer_switch=dict(type='str'),
pn_failover_action=dict(type='str', choices=['move', 'ignore']),
pn_lacp_mode=dict(type='str', choices=[
'off', 'passive', 'active']),
pn_lacp_timeout=dict(type='str', choices=['slow', 'fast']),
pn_lacp_fallback=dict(type='str', choices=[
'individual', 'bundled']),
pn_lacp_fallback_timeout=dict(type='str')
),
required_if=(
["state", "present", ["pn_name", "pn_port", "pn_peer_port",
"pn_peer_switch"]],
["state", "absent", ["pn_name"]],
["state", "update", ["pn_name"]]
)
)
# Argument accessing
state = module.params['state']
name = module.params['pn_name']
port = module.params['pn_port']
peer_port = module.params['pn_peer_port']
mode = module.params['pn_mode']
peer_switch = module.params['pn_peer_switch']
failover_action = module.params['pn_failover_action']
lacp_mode = module.params['pn_lacp_mode']
lacp_timeout = module.params['pn_lacp_timeout']
lacp_fallback = module.params['pn_lacp_fallback']
lacp_fallback_timeout = module.params['pn_lacp_fallback_timeout']
command = get_command_from_state(state)
# Building the CLI command string
cli = pn_cli(module)
if command == 'vlag-delete':
check_cli(module, cli)
if VLAG_EXISTS is False:
module.exit_json(
skipped=True,
msg='VLAG with name %s does not exist' % name
)
cli += ' %s name %s ' % (command, name)
else:
if command == 'vlag-create':
check_cli(module, cli)
if VLAG_EXISTS is True:
module.exit_json(
skipped=True,
msg='VLAG with name %s already exists' % name
)
cli += ' %s name %s ' % (command, name)
if port:
cli += ' port %s peer-port %s ' % (port, peer_port)
if mode:
cli += ' mode ' + mode
if peer_switch:
cli += ' peer-switch ' + peer_switch
if failover_action:
cli += ' failover-' + failover_action + '-L2 '
if lacp_mode:
cli += ' lacp-mode ' + lacp_mode
if lacp_timeout:
cli += ' lacp-timeout ' + lacp_timeout
if lacp_fallback:
cli += ' lacp-fallback ' + lacp_fallback
if lacp_fallback_timeout:
cli += ' lacp-fallback-timeout ' + lacp_fallback_timeout
run_cli(module, cli)
# AnsibleModule boilerplate
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
624,
510,
46,
14214,
373,
1823,
13,
981,
15,
86,
1823,
13,
1807,
15,
86,
1823,
13,
8951,
408,
199,
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,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
13631,
63,
86,
1823,
199,
2502,
26,
298,
3714,
2302,
5610,
17138,
8593,
455,
390,
338,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
14214,
1414,
370,
1218,
15,
1807,
15,
8951,
373,
1823,
14,
199,
1802,
26,
523,
446,
17009,
373,
1823,
13,
981,
15,
86,
1823,
13,
1807,
15,
86,
1823,
13,
8951,
1414,
14,
523,
446,
437,
5791,
2142,
18384,
1572,
334,
32458,
1254,
9,
6127,
6220,
626,
787,
11831,
9916,
1183,
272,
8539,
370,
2877,
3365,
7497,
2302,
5610,
17138,
7256,
370,
7468,
465,
282,
2849,
272,
24764,
370,
282,
10919,
2243,
14,
710,
10919,
2243,
883,
506,
282,
6258,
12,
1654,
12,
503,
1263,
272,
26125,
2243,
14,
437,
812,
44,
1254,
883,
5647,
11915,
499,
3510,
515,
316,
12,
1314,
6127,
1265,
272,
370,
1218,
8992,
32270,
701,
22255,
20434,
12,
29310,
3663,
9861,
272,
3792,
3382,
3380,
436,
2248,
30260,
15602,
2382,
13943,
3792,
2187,
14,
199,
1419,
26,
523,
13631,
63,
2764,
2473,
26,
272,
1369,
26,
489,
446,
22896,
4676,
3434,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
2060,
26,
272,
1369,
26,
489,
446,
22896,
4676,
2505,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
5656,
26,
272,
1369,
26,
489,
446,
10256,
6258,
8,
397,
9,
370,
1255,
642,
1414,
641,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
314,
1595,
370,
5147,
14,
3645,
283,
1881,
7,
370,
1218,
373,
1823,
12,
267,
283,
5575,
7,
370,
3145,
373,
1823,
436,
283,
873,
7,
370,
2811,
373,
1823,
14,
272,
1415,
26,
715,
272,
3415,
26,
788,
1881,
297,
283,
5575,
297,
283,
873,
418,
523,
13631,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
4812,
63,
354,
9,
6181,
282,
1686,
536,
367,
373,
1823,
2897,
14,
272,
1415,
26,
2549,
523,
13631,
63,
719,
26,
272,
1369,
26,
489,
446,
13327,
314,
2257,
812,
44,
1254,
1844,
14,
489,
446,
11105,
367,
373,
1823,
13,
981,
14,
523,
13631,
63,
7866,
63,
719,
26,
272,
1369,
26,
489,
446,
13327,
314,
9104,
812,
44,
1254,
1844,
14,
489,
446,
11105,
367,
373,
1823,
13,
981,
14,
523,
13631,
63,
632,
26,
272,
1369,
26,
489,
446,
13327,
314,
818,
367,
314,
812,
44,
1254,
14,
23241,
13,
26071,
9126,
1373,
5366,
365,
267,
4702,
436,
314,
1163,
5366,
365,
315,
10584,
991,
818,
14,
23241,
13,
2682,
9126,
267,
626,
3865,
27613,
402,
314,
373,
1823,
787,
1536,
701,
849,
14,
272,
3415,
26,
788,
2682,
13,
2682,
297,
283,
2682,
13,
26071,
418,
523,
13631,
63,
7866,
63,
5656,
26,
272,
1369,
26,
489,
446,
13327,
314,
2630,
13,
354,
402,
314,
9104,
6258,
14,
523,
13631,
63,
667,
23165,
63,
1287,
26,
272,
1369,
26,
489,
446,
13327,
314,
1433,
23165,
1595,
465,
4057,
503,
3686,
14,
272,
3415,
26,
788,
1185,
297,
283,
4247,
418,
523,
13631,
63,
416,
1850,
63,
632,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
818,
14,
272,
3415,
26,
788,
1997,
297,
283,
25166,
297,
283,
2682,
418,
523,
13631,
63,
416,
1850,
63,
2593,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
2653,
465,
11999,
8,
1216,
4696,
9,
503,
7377,
8,
20,
4696,
680,
272,
3415,
26,
788,
14362,
297,
283,
7015,
418,
523,
13631,
63,
416,
1850,
63,
10538,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
9567,
818,
465,
27206,
503,
8212,
14,
272,
3415,
26,
788,
6469,
297,
283,
23001,
418,
523,
13631,
63,
416,
1850,
63,
10538,
63,
2593,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
9567,
2653,
315,
4696,
14,
710,
1425,
365,
3382,
4233,
267,
436,
5212,
4696,
543,
282,
849,
574,
402,
5238,
4696,
14,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1218,
282,
812,
44,
1254,
523,
13631,
63,
86,
1823,
26,
272,
1174,
26,
283,
1881,
7,
272,
13631,
63,
354,
26,
2249,
1132,
13,
475,
13,
8914,
272,
13631,
63,
719,
26,
283,
681,
1132,
614,
13,
475,
13,
8914,
7,
272,
13631,
63,
7866,
63,
719,
26,
283,
681,
1132,
996,
13,
475,
13,
8914,
7,
272,
13631,
63,
7866,
63,
5656,
26,
2249,
1132,
996,
272,
13631,
63,
632,
26,
283,
2682,
13,
2682,
7,
199,
199,
13,
536,
26,
3145,
812,
44,
1254,
83,
523,
13631,
63,
86,
1823,
26,
272,
1174,
26,
283,
5575,
7,
272,
13631,
63,
354,
26,
2249,
1132,
13,
475,
13,
8914,
199,
624,
199,
199,
9677,
275,
408,
199,
1531,
26,
523,
1369,
26,
710,
14214,
1414,
1255,
641,
314,
1347,
1031,
8,
83,
680,
523,
2138,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
624,
510,
46,
14214,
373,
1823,
13,
981,
15,
86,
1823,
13,
1807,
15,
86,
1823,
13,
8951,
408,
199,
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,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
13631,
63,
86,
1823,
199,
2502,
26,
298,
3714,
2302,
5610,
17138,
8593,
455,
390,
338,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
14214,
1414,
370,
1218,
15,
1807,
15,
8951,
373,
1823,
14,
199,
1802,
26,
523,
446,
17009,
373,
1823,
13,
981,
15,
86,
1823,
13,
1807,
15,
86,
1823,
13,
8951,
1414,
14,
523,
446,
437,
5791,
2142,
18384,
1572,
334,
32458,
1254,
9,
6127,
6220,
626,
787,
11831,
9916,
1183,
272,
8539,
370,
2877,
3365,
7497,
2302,
5610,
17138,
7256,
370,
7468,
465,
282,
2849,
272,
24764,
370,
282,
10919,
2243,
14,
710,
10919,
2243,
883,
506,
282,
6258,
12,
1654,
12,
503,
1263,
272,
26125,
2243,
14,
437,
812,
44,
1254,
883,
5647,
11915,
499,
3510,
515,
316,
12,
1314,
6127,
1265,
272,
370,
1218,
8992,
32270,
701,
22255,
20434,
12,
29310,
3663,
9861,
272,
3792,
3382,
3380,
436,
2248,
30260,
15602,
2382,
13943,
3792,
2187,
14,
199,
1419,
26,
523,
13631,
63,
2764,
2473,
26,
272,
1369,
26,
489,
446,
22896,
4676,
3434,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
2060,
26,
272,
1369,
26,
489,
446,
22896,
4676,
2505,
340,
922,
365,
440,
1738,
14,
272,
1415,
26,
756,
523,
13631,
63,
2764,
5656,
26,
272,
1369,
26,
489,
446,
10256,
6258,
8,
397,
9,
370,
1255,
642,
1414,
641,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
314,
1595,
370,
5147,
14,
3645,
283,
1881,
7,
370,
1218,
373,
1823,
12,
267,
283,
5575,
7,
370,
3145,
373,
1823,
436,
283,
873,
7,
370,
2811,
373,
1823,
14,
272,
1415,
26,
715,
272,
3415,
26,
788,
1881,
297,
283,
5575,
297,
283,
873,
418,
523,
13631,
63,
354,
26,
272,
1369,
26,
489,
446,
710,
445,
8,
4812,
63,
354,
9,
6181,
282,
1686,
536,
367,
373,
1823,
2897,
14,
272,
1415,
26,
2549,
523,
13631,
63,
719,
26,
272,
1369,
26,
489,
446,
13327,
314,
2257,
812,
44,
1254,
1844,
14,
489,
446,
11105,
367,
373,
1823,
13,
981,
14,
523,
13631,
63,
7866,
63,
719,
26,
272,
1369,
26,
489,
446,
13327,
314,
9104,
812,
44,
1254,
1844,
14,
489,
446,
11105,
367,
373,
1823,
13,
981,
14,
523,
13631,
63,
632,
26,
272,
1369,
26,
489,
446,
13327,
314,
818,
367,
314,
812,
44,
1254,
14,
23241,
13,
26071,
9126,
1373,
5366,
365,
267,
4702,
436,
314,
1163,
5366,
365,
315,
10584,
991,
818,
14,
23241,
13,
2682,
9126,
267,
626,
3865,
27613,
402,
314,
373,
1823,
787,
1536,
701,
849,
14,
272,
3415,
26,
788,
2682,
13,
2682,
297,
283,
2682,
13,
26071,
418,
523,
13631,
63,
7866,
63,
5656,
26,
272,
1369,
26,
489,
446,
13327,
314,
2630,
13,
354,
402,
314,
9104,
6258,
14,
523,
13631,
63,
667,
23165,
63,
1287,
26,
272,
1369,
26,
489,
446,
13327,
314,
1433,
23165,
1595,
465,
4057,
503,
3686,
14,
272,
3415,
26,
788,
1185,
297,
283,
4247,
418,
523,
13631,
63,
416,
1850,
63,
632,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
818,
14,
272,
3415,
26,
788,
1997,
297,
283,
25166,
297,
283,
2682,
418,
523,
13631,
63,
416,
1850,
63,
2593,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
2653,
465,
11999,
8,
1216,
4696,
9,
503,
7377,
8,
20,
4696,
680,
272,
3415,
26,
788,
14362,
297,
283,
7015,
418,
523,
13631,
63,
416,
1850,
63,
10538,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
9567,
818,
465,
27206,
503,
8212,
14,
272,
3415,
26,
788,
6469,
297,
283,
23001,
418,
523,
13631,
63,
416,
1850,
63,
10538,
63,
2593,
26,
272,
1369,
26,
489,
446,
13327,
314,
491,
1348,
48,
9567,
2653,
315,
4696,
14,
710,
1425,
365,
3382,
4233,
267,
436,
5212,
4696,
543,
282,
849,
574,
402,
5238,
4696,
14,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1218,
282,
812,
44,
1254,
523,
13631,
63,
86,
1823,
26,
272,
1174,
26,
283,
1881,
7,
272,
13631,
63,
354,
26,
2249,
1132,
13,
475,
13,
8914,
272,
13631,
63,
719,
26,
283,
681,
1132,
614,
13,
475,
13,
8914,
7,
272,
13631,
63,
7866,
63,
719,
26,
283,
681,
1132,
996,
13,
475,
13,
8914,
7,
272,
13631,
63,
7866,
63,
5656,
26,
2249,
1132,
996,
272,
13631,
63,
632,
26,
283,
2682,
13,
2682,
7,
199,
199,
13,
536,
26,
3145,
812,
44,
1254,
83,
523,
13631,
63,
86,
1823,
26,
272,
1174,
26,
283,
5575,
7,
272,
13631,
63,
354,
26,
2249,
1132,
13,
475,
13,
8914,
199,
624,
199,
199,
9677,
275,
408,
199,
1531,
26,
523,
1369,
26,
710,
14214,
1414,
1255,
641,
314,
1347,
1031,
8,
83,
680,
523,
2138,
26,
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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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
] |
UniversalMasterEgg8679/ansible
|
lib/ansible/modules/network/nxos/_nxos_template.py
|
67
|
5984
|
#!/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': ['deprecated'],
'supported_by': 'community'}
DOCUMENTATION = """
---
module: nxos_template
version_added: "2.1"
author: "Peter Sprygada (@privateip)"
short_description: Manage Cisco NXOS device configurations
description:
- Manages network device configurations over SSH or NXAPI. This module
allows implementers to work with the device running-config. It
provides a way to push a set of commands onto a network device
by evaluating the current running-config and only pushing configuration
commands that are not already configured. The config source can
be a set of commands or a template.
deprecated: Deprecated in 2.2. Use M(nxos_config) instead.
options:
src:
description:
- The path to the config source. The source can be either a
file with config or a template that will be merged during
runtime. By default the task will search for the source
file in role or playbook root folder in templates directory.
required: false
default: null
force:
description:
- The force argument instructs the module to not consider the
current devices running-config. When set to true, this will
cause the module to push the contents of I(src) into the device
without first checking if already configured.
required: false
default: false
choices: [ "true", "false" ]
include_defaults:
description:
- The module, by default, will collect the current device
running-config to use as a base for comparisons to the commands
in I(src). Setting this value to true will cause the module
to issue the command C(show running-config all) to include all
device settings.
required: false
default: false
choices: [ "true", "false" ]
backup:
description:
- When this argument is configured true, the module will backup
the running-config from the node prior to making any changes.
The backup file will be written to backup_{{ hostname }} in
the root of the playbook directory.
required: false
default: false
choices: [ "true", "false" ]
config:
description:
- The module, by default, will connect to the remote device and
retrieve the current running-config to use as a base for comparing
against the contents of source. There are times when it is not
desirable to have the task get the current running-config for
every task in a playbook. The I(config) argument allows the
implementer to pass in the configuration to use as the base
config for comparison.
required: false
default: null
"""
EXAMPLES = """
- name: push a configuration onto the device
nxos_template:
src: config.j2
- name: forceable push a configuration onto the device
nxos_template:
src: config.j2
force: yes
- name: provide the base configuration for comparison
nxos_template:
src: candidate_config.txt
config: current_config.txt
"""
RETURN = """
updates:
description: The set of commands that will be pushed to the remote device
returned: always
type: list
sample: ['...', '...']
responses:
description: The set of responses from issuing the commands on the device
returned: when not check_mode
type: list
sample: ['...', '...']
"""
from ansible.module_utils.nxos import load_config, get_config
from ansible.module_utils.nxos import nxos_argument_spec
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netcfg import NetworkConfig, dumps
def get_current_config(module):
config = module.params.get('config')
if not config and not module.params['force']:
flags = []
if module.params['include_defaults']:
flags.append('all')
config = get_config(module, flags)
return config
def main():
""" main entry point for module execution
"""
argument_spec = dict(
src=dict(),
force=dict(default=False, type='bool'),
include_defaults=dict(default=True, type='bool'),
backup=dict(default=False, type='bool'),
config=dict(),
)
argument_spec.update(nxos_argument_spec)
mutually_exclusive = [('config', 'backup'), ('config', 'force')]
module = AnsibleModule(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True)
result = dict(changed=False)
candidate = NetworkConfig(contents=module.params['src'], indent=2)
contents = get_current_config(module)
if contents:
config = NetworkConfig(contents=contents, indent=2)
result['__backup__'] = str(contents)
if not module.params['force']:
commands = candidate.difference(config)
commands = dumps(commands, 'commands').split('\n')
commands = [str(c) for c in commands if c]
else:
commands = str(candidate).split('\n')
if commands:
if not module.check_mode:
load_config(module, commands)
result['changed'] = True
result['updates'] = commands
result['commands'] = 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,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
6667,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
22072,
63,
1160,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
14944,
28356,
653,
56,
3100,
2243,
13422,
199,
1802,
26,
523,
446,
21612,
2784,
2243,
13422,
1806,
12027,
503,
653,
56,
3735,
14,
221,
961,
859,
272,
6127,
2456,
1410,
878,
370,
1736,
543,
314,
2243,
3879,
13,
888,
14,
221,
2779,
272,
6571,
282,
4340,
370,
6675,
282,
663,
402,
3718,
14602,
282,
2784,
2243,
272,
701,
27083,
314,
1453,
3879,
13,
888,
436,
1454,
6675,
316,
2897,
272,
3718,
626,
787,
440,
2575,
7526,
14,
221,
710,
1101,
1350,
883,
272,
506,
282,
663,
402,
3718,
503,
282,
1978,
14,
199,
6667,
26,
17993,
315,
499,
14,
18,
14,
3645,
603,
8,
17982,
63,
888,
9,
3140,
14,
199,
1419,
26,
523,
2928,
26,
272,
1369,
26,
489,
446,
710,
931,
370,
314,
1101,
1350,
14,
221,
710,
1350,
883,
506,
1902,
282,
267,
570,
543,
1101,
503,
282,
1978,
626,
911,
506,
9545,
5309,
267,
8836,
14,
221,
4885,
849,
314,
2120,
911,
2754,
367,
314,
1350,
267,
570,
315,
4719,
503,
15695,
1738,
4922,
315,
7009,
2082,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
3542,
26,
272,
1369,
26,
489,
446,
710,
3542,
1423,
315,
23253,
314,
859,
370,
440,
11201,
314,
267,
1453,
7256,
3879,
13,
888,
14,
221,
3979,
663,
370,
2549,
12,
642,
911,
267,
7675,
314,
859,
370,
6675,
314,
4072,
402,
473,
8,
2164,
9,
1901,
314,
2243,
267,
1928,
1642,
7907,
340,
2575,
7526,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
523,
2387,
63,
4322,
26,
272,
1369,
26,
489,
446,
710,
859,
12,
701,
849,
12,
911,
8775,
314,
1453,
2243,
267,
3879,
13,
888,
370,
675,
465,
282,
1300,
367,
20448,
370,
314,
3718,
267,
315,
473,
8,
2164,
680,
221,
13510,
642,
574,
370,
2549,
911,
7675,
314,
859,
267,
370,
4976,
314,
1414,
445,
8,
2384,
3879,
13,
888,
1006,
9,
370,
2387,
1006,
267,
2243,
2202,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
523,
6902,
26,
272,
1369,
26,
489,
446,
3979,
642,
1423,
365,
7526,
2549,
12,
314,
859,
911,
6902,
267,
314,
3879,
13,
888,
687,
314,
1031,
6791,
370,
10663,
1263,
4493,
14,
267,
710,
6902,
570,
911,
506,
5313,
370,
6902,
63,
3638,
6246,
3586,
315,
267,
314,
1738,
402,
314,
15695,
2082,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
523,
1101,
26,
272,
1369,
26,
489,
446,
710,
859,
12,
701,
849,
12,
911,
4907,
370,
314,
3982,
2243,
436,
267,
8044,
314,
1453,
3879,
13,
888,
370,
675,
465,
282,
1300,
367,
20234,
267,
6169,
314,
4072,
402,
1350,
14,
221,
6006,
787,
5431,
1380,
652,
365,
440,
267,
477,
338,
6842,
370,
1172,
314,
2120,
664,
314,
1453,
3879,
13,
888,
367,
267,
4036,
2120,
315,
282,
15695,
14,
221,
710,
473,
8,
888,
9,
1423,
6127,
314,
267,
2456,
28826,
370,
986,
315,
314,
2897,
370,
675,
465,
314,
1300,
267,
1101,
367,
9132,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
6675,
282,
2897,
14602,
314,
2243,
523,
22072,
63,
1160,
26,
272,
2928,
26,
1101,
14,
74,
18,
199,
199,
13,
536,
26,
3542,
461,
6675,
282,
2897,
14602,
314,
2243,
523,
22072,
63,
1160,
26,
272,
2928,
26,
1101,
14,
74,
18,
272,
3542,
26,
9456,
199,
199,
13,
536,
26,
5647,
314,
1300,
2897,
367,
9132,
523,
22072,
63,
1160,
26,
272,
2928,
26,
7627,
63,
888,
14,
2424,
272,
1101,
26,
1453,
63,
888,
14,
2424,
199,
624,
199,
199,
9677,
275,
408,
199,
7618,
26,
523,
1369,
26,
710,
663,
402,
3718,
626,
911,
506,
22319,
370,
314,
3982,
2243,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
199,
10360,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
365,
9648,
316,
314,
3718,
641,
314,
2243,
523,
2138,
26,
1380,
440,
1104,
63,
632,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
624,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
2248,
63,
888,
12,
664,
63,
888,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
846,
4128,
492,
7220,
2028,
12,
16864,
199,
199,
318,
664,
63,
1818,
63,
888,
8,
578,
304,
272,
1101,
275,
859,
14,
1162,
14,
362,
360,
888,
358,
272,
340,
440,
1101,
436
] |
[
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,
6667,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
22072,
63,
1160,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
14944,
28356,
653,
56,
3100,
2243,
13422,
199,
1802,
26,
523,
446,
21612,
2784,
2243,
13422,
1806,
12027,
503,
653,
56,
3735,
14,
221,
961,
859,
272,
6127,
2456,
1410,
878,
370,
1736,
543,
314,
2243,
3879,
13,
888,
14,
221,
2779,
272,
6571,
282,
4340,
370,
6675,
282,
663,
402,
3718,
14602,
282,
2784,
2243,
272,
701,
27083,
314,
1453,
3879,
13,
888,
436,
1454,
6675,
316,
2897,
272,
3718,
626,
787,
440,
2575,
7526,
14,
221,
710,
1101,
1350,
883,
272,
506,
282,
663,
402,
3718,
503,
282,
1978,
14,
199,
6667,
26,
17993,
315,
499,
14,
18,
14,
3645,
603,
8,
17982,
63,
888,
9,
3140,
14,
199,
1419,
26,
523,
2928,
26,
272,
1369,
26,
489,
446,
710,
931,
370,
314,
1101,
1350,
14,
221,
710,
1350,
883,
506,
1902,
282,
267,
570,
543,
1101,
503,
282,
1978,
626,
911,
506,
9545,
5309,
267,
8836,
14,
221,
4885,
849,
314,
2120,
911,
2754,
367,
314,
1350,
267,
570,
315,
4719,
503,
15695,
1738,
4922,
315,
7009,
2082,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
3542,
26,
272,
1369,
26,
489,
446,
710,
3542,
1423,
315,
23253,
314,
859,
370,
440,
11201,
314,
267,
1453,
7256,
3879,
13,
888,
14,
221,
3979,
663,
370,
2549,
12,
642,
911,
267,
7675,
314,
859,
370,
6675,
314,
4072,
402,
473,
8,
2164,
9,
1901,
314,
2243,
267,
1928,
1642,
7907,
340,
2575,
7526,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
523,
2387,
63,
4322,
26,
272,
1369,
26,
489,
446,
710,
859,
12,
701,
849,
12,
911,
8775,
314,
1453,
2243,
267,
3879,
13,
888,
370,
675,
465,
282,
1300,
367,
20448,
370,
314,
3718,
267,
315,
473,
8,
2164,
680,
221,
13510,
642,
574,
370,
2549,
911,
7675,
314,
859,
267,
370,
4976,
314,
1414,
445,
8,
2384,
3879,
13,
888,
1006,
9,
370,
2387,
1006,
267,
2243,
2202,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
523,
6902,
26,
272,
1369,
26,
489,
446,
3979,
642,
1423,
365,
7526,
2549,
12,
314,
859,
911,
6902,
267,
314,
3879,
13,
888,
687,
314,
1031,
6791,
370,
10663,
1263,
4493,
14,
267,
710,
6902,
570,
911,
506,
5313,
370,
6902,
63,
3638,
6246,
3586,
315,
267,
314,
1738,
402,
314,
15695,
2082,
14,
272,
1415,
26,
3055,
272,
849,
26,
3055,
272,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
523,
1101,
26,
272,
1369,
26,
489,
446,
710,
859,
12,
701,
849,
12,
911,
4907,
370,
314,
3982,
2243,
436,
267,
8044,
314,
1453,
3879,
13,
888,
370,
675,
465,
282,
1300,
367,
20234,
267,
6169,
314,
4072,
402,
1350,
14,
221,
6006,
787,
5431,
1380,
652,
365,
440,
267,
477,
338,
6842,
370,
1172,
314,
2120,
664,
314,
1453,
3879,
13,
888,
367,
267,
4036,
2120,
315,
282,
15695,
14,
221,
710,
473,
8,
888,
9,
1423,
6127,
314,
267,
2456,
28826,
370,
986,
315,
314,
2897,
370,
675,
465,
314,
1300,
267,
1101,
367,
9132,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
6675,
282,
2897,
14602,
314,
2243,
523,
22072,
63,
1160,
26,
272,
2928,
26,
1101,
14,
74,
18,
199,
199,
13,
536,
26,
3542,
461,
6675,
282,
2897,
14602,
314,
2243,
523,
22072,
63,
1160,
26,
272,
2928,
26,
1101,
14,
74,
18,
272,
3542,
26,
9456,
199,
199,
13,
536,
26,
5647,
314,
1300,
2897,
367,
9132,
523,
22072,
63,
1160,
26,
272,
2928,
26,
7627,
63,
888,
14,
2424,
272,
1101,
26,
1453,
63,
888,
14,
2424,
199,
624,
199,
199,
9677,
275,
408,
199,
7618,
26,
523,
1369,
26,
710,
663,
402,
3718,
626,
911,
506,
22319,
370,
314,
3982,
2243,
523,
2138,
26,
3544,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
199,
10360,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
365,
9648,
316,
314,
3718,
641,
314,
2243,
523,
2138,
26,
1380,
440,
1104,
63,
632,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
624,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
2248,
63,
888,
12,
664,
63,
888,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
846,
4128,
492,
7220,
2028,
12,
16864,
199,
199,
318,
664,
63,
1818,
63,
888,
8,
578,
304,
272,
1101,
275,
859,
14,
1162,
14,
362,
360,
888,
358,
272,
340,
440,
1101,
436,
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,
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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
] |
Micket/CCBuilder
|
make_cc.py
|
1
|
8680
|
#!/usr/bin/env python3
from __future__ import print_function
from __future__ import division
import argparse
import pickle
import time
import CCBuilder as ccb
import CCBuilder_c as ccb_c
import numpy as np
import scipy.special
def uniform_dist(x):
""" Returns uniform distributions of given range """
return lambda: np.random.uniform(x[0], x[1])
def weibull_dist(a, mu):
""" Returns Weibull distributions for given shape parameter and average """
return lambda: np.random.weibull(a) * mu / scipy.special.gamma(1/a + 1)
def parse_dist(arg):
# Parses input string for given distribution.
# Returns a distribution, and the average
d, params = arg.split(':')
params = [float(x) for x in params.split(',')]
if d == 'U':
return uniform_dist(params), np.mean(params)
elif d == 'W':
a, mu = params
return weibull_dist(a, mu), mu
parser = argparse.ArgumentParser(description='''Generate a WC microstructure.
Grain shape/size supports 2 types of distributions:
Uniform: U:low,high
Weibull: U:a,mu (a=k in some notation, mu=mean)
''',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# parser.add_argument('-V', dest='verbose', action='store_true', help='Verbose mode.')
parser.add_argument('-f', dest='fname', metavar='basename', required=True, help='Output base filename.')
parser.add_argument('-L', dest='L', metavar='length', required=True, type=float, help='Cell length (volume is L^3)')
parser.add_argument('-m', dest='m', metavar='m', required=True, type=int,
help='Grid resolution. Total number of voxels are (m*L)^3')
parser.add_argument('--vol_frac_goal', dest="vol_frac_goal", metavar='v', required=True, type=float,
help='Goal for volume fraction WC (excluding overlap)')
parser.add_argument('-s', dest='seed', metavar='s', default=None, type=int,
help='Seed for RNG. Given identical parameters, ' +
'CCBuilder will generate identical output given a controlled seed.')
parser.add_argument('--stray_cleanup', action='store_true', help='Clean up stray voxels')
group = parser.add_argument_group('WC grain shape')
group.add_argument('-k', dest='k_dist', metavar='type,[params]', default='U:0.4,1.4',
help='k distribution')
group.add_argument('-r', dest='r_dist', metavar='type,[params]', default='U:0.1,0.4',
help='r distribution')
group.add_argument('-d', dest='d_dist', metavar='type,[params]', default='U:0.5,1.5',
help='d distribution')
group = parser.add_argument_group('Packing')
group.add_argument('--use_potential', action='store_true', help='Use repulsive potential.')
group.add_argument('--nr_tries', dest='nr_tries', metavar='n', default=2500, type=int,
help='Number of random translations.')
group.add_argument('--delta', dest='delta', metavar='d', type=float,
help='Maximum distance for randomized translations.')
group.add_argument('--m_coarse', dest="m_coarse", metavar='mc', default=10,
help='Grid resolution during packing.')
group = parser.add_argument_group('Potts simulation')
group.add_argument('--mc_steps', dest="mc_steps", metavar='steps', default=0.05, type=float,
help='Monte-Carlo steps (scales with (m*L)^4. Set to zero to turn off.')
group.add_argument('--tau', dest='tau', metavar='t', default=0.5, type=float,
help='Ficticious temperature in Potts model.')
options = parser.parse_args()
if options.seed is not None:
np.random.seed(options.seed)
# Heuristic mapping from actual to goal volume fraction
# vol_frac_goal = (alpha - 2)/(2 * alpha) + 1/alpha * np.sqrt(1 - alpha * np.log(-2*(vol_frac - 1)))
d_eq, d_0 = parse_dist(options.d_dist)
r, r_0 = parse_dist(options.r_dist)
k, k_0 = parse_dist(options.k_dist)
fname = options.fname
# to avoid confusion with types:
m = np.int(options.m)
m_coarse = np.int(options.m_coarse)
L = np.float(options.L)
mc_steps = np.float(options.mc_steps)
vol_frac_goal = np.double(options.vol_frac_goal)
tau = np.double(options.tau)
nr_tries = np.int(options.nr_tries)
delta_x = d_0/float(m)
M = np.int(m * L / d_0)
M_coarse = np.int(m_coarse * L / d_0)
idelta = M
idelta_coarse = M_coarse
if options.delta:
idelta = np.int(M * options.delta / L)
idelta_coarse = np.int(M_coarse * options.delta / L)
trunc_triangles = ccb.prepare_triangles(vol_frac_goal, L, r, k, d_eq)
# trunc_triangles = trunc_triangles[:1]
# trunc_triangles[0].rot_matrix = np.eye(3)
# trunc_triangles[0].rot_matrix_tr = np.eye(3)
# trunc_triangles[0].midpoint = np.array([2., 2., 2.])
# Sort triangles w.r.t. volume, so that large triangles are added to the box first (better packing)
trunc_triangles.sort(key=lambda x: x.volume, reverse=True)
print('Prepared', len(trunc_triangles), 'triangles')
if options.use_potential:
ccb.optimize_midpoints(L, trunc_triangles)
if m_coarse == m:
grain_ids, overlaps, voxel_indices = ccb_c.populate_voxels(M, L, trunc_triangles, nr_tries, idelta, 1.0)
else:
if nr_tries > 0:
# Optimization: Use coarser grid for packing, then insert packed grains into fine grid
# No need to get the return values, trunc_triangles
ccb_c.populate_voxels(M_coarse, L, trunc_triangles, nr_tries, idelta_coarse, 1.0)
grain_ids, overlaps, voxel_indices = ccb_c.populate_voxels(M, L, trunc_triangles, 1, 0, 1.0)
if mc_steps > 0:
start_time = time.time()
# Do Potts on coarse grid first for an improved initial guess.
M_coarseMC = M//2
grain_ids_coarse, overlaps_coarse, voxel_indices_coarse = ccb_c.populate_voxels(M_coarseMC, L, trunc_triangles, 0, 0, 1.0)
_, gb_voxels_coarse, _ = ccb_c.calc_surface_prop(M_coarseMC, grain_ids_coarse)
ccb_c.make_mcp_bound(M_coarseMC, grain_ids_coarse, gb_voxels_coarse, overlaps_coarse, voxel_indices_coarse,
np.int(mc_steps * M_coarseMC**4), tau)
# Copy over that solution to the overlap regions of the fine grid as a starting point
M2 = M**2
i = np.nonzero(overlaps)[0]
iz = i // M2
iy = (i - iz*M2) // M
ix = i - iz*M2 - iy*M
cix = ix * M_coarseMC // M
ciy = iy * M_coarseMC // M
ciz = iz * M_coarseMC // M
ci = cix + ciy*M_coarseMC + ciz*M_coarseMC**2
gid = grain_ids_coarse[ci]
# Could use a Cython implementation for efficiency.
for ii, g in zip(i, gid):
if g != grain_ids[ii] and np.searchsorted(voxel_indices[g-2], ii) < len(voxel_indices[g-2]):
grain_ids[ii] = g
# This might change a few voxels to a value that they shouldn't obtain, but it's barely noticeable
# grain_ids_1[i] = grain_ids_coarse[ci]
_, gb_voxels, _ = ccb_c.calc_surface_prop(M, grain_ids)
# and run the full resolution MCP:
ccb_c.make_mcp_bound(M, grain_ids, gb_voxels, overlaps, voxel_indices, np.int(mc_steps * M ** 4), tau)
print('Potts model took {} seconds'.format(np.str(time.time() - start_time)))
if options.stray_cleanup:
start_time = time.time()
ccb_c.stray_cleanup(M, grain_ids)
print('Stray voxel cleanup took {} seconds'.format(np.str(time.time() - start_time)))
surface_voxels, gb_voxels, interface_voxels = ccb_c.calc_surface_prop(M, grain_ids)
phases, good_voxels, euler_angles = ccb_c.calc_grain_prop(M, grain_ids, trunc_triangles)
phase_volumes = np.bincount(phases)
vol_frac_WC = phase_volumes[2] / np.float(M ** 3)
vol_frac_Co = 1 - vol_frac_WC
mass_frac_WC = ccb.mass_fraction(vol_frac_WC)
sum_gb_voxels = np.sum(gb_voxels)
contiguity = sum_gb_voxels / np.float(sum_gb_voxels + np.sum(interface_voxels))
print('Contiguity {:5f}, Co volume frac {:.5f}, mass frac {:.5f}'.format(
contiguity, 1 - vol_frac_WC, ccb.mass_fraction(vol_frac_WC)))
ccb.write_dream3d(fname, 3 * [M], 3 * [delta_x], trunc_triangles, grain_ids, phases, good_voxels,
euler_angles, surface_voxels, gb_voxels, interface_voxels, overlaps)
with open(fname + '_trunc_triangles.data', 'wb') as f:
pickle.dump([t.rot_matrix for t in trunc_triangles], f)
# Saving grain volume data
if False:
grain_volumes = np.bincount(grain_ids)
d_eq = ccb.volume_to_eq_d(grain_volumes[2:] * delta_x ** 3)
# np.savetxt(fname + '_d_orig.txt', [t.d_eq for t in trunc_triangles])
np.savetxt(fname + '_d.txt', d_eq)
# Plot initial and final distributions
import matplotlib.pyplot as plt
plt.hist(np.array([t.d_eq for t in trunc_triangles]), alpha=0.5, bins=15, normed=True, label='Initial')
plt.hist(d_eq, alpha=0.5, bins=15, normed=True, label='Final')
plt.legend(loc='upper right')
plt.show()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
7534,
199,
646,
5927,
199,
646,
900,
199,
646,
17586,
6437,
465,
286,
2894,
199,
646,
17586,
6437,
63,
67,
465,
286,
2894,
63,
67,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
6664,
421,
199,
318,
14818,
63,
2686,
8,
88,
304,
272,
408,
1803,
14818,
10208,
402,
1627,
1425,
408,
272,
372,
2400,
26,
980,
14,
2355,
14,
8830,
8,
88,
59,
16,
467,
671,
59,
17,
566,
421,
199,
318,
781,
20587,
63,
2686,
8,
65,
12,
8504,
304,
272,
408,
1803,
2136,
20587,
10208,
367,
1627,
2215,
2725,
436,
8095,
408,
272,
372,
2400,
26,
980,
14,
2355,
14,
1129,
20587,
8,
65,
9,
627,
8504,
1182,
7026,
14,
6664,
14,
7325,
8,
17,
15,
65,
435,
413,
9,
421,
199,
318,
2198,
63,
2686,
8,
1273,
304,
272,
327,
29968,
1324,
1059,
367,
1627,
4084,
14,
272,
327,
1803,
282,
4084,
12,
436,
314,
8095,
272,
366,
12,
1862,
275,
1680,
14,
1294,
11633,
272,
1862,
275,
359,
1609,
8,
88,
9,
367,
671,
315,
1862,
14,
1294,
29972,
272,
340,
366,
508,
283,
53,
356,
267,
372,
14818,
63,
2686,
8,
1162,
395,
980,
14,
3670,
8,
1162,
9,
272,
916,
366,
508,
283,
55,
356,
267,
282,
12,
8504,
275,
1862,
267,
372,
781,
20587,
63,
2686,
8,
65,
12,
8504,
395,
8504,
421,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
19938,
6864,
282,
644,
35,
9967,
6976,
14,
199,
5761,
262,
2215,
15,
890,
5171,
499,
2943,
402,
10208,
26,
199,
12421,
26,
738,
26,
674,
12,
6260,
199,
24689,
26,
738,
26,
65,
12,
6553,
258,
334,
65,
29,
75,
315,
2005,
15843,
12,
8504,
29,
3670,
9,
199,
18108,
639,
9698,
63,
533,
29,
18978,
14,
5201,
16986,
22779,
9,
199,
199,
3,
1798,
14,
525,
63,
2094,
3654,
54,
297,
2053,
534,
3832,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
21879,
818,
2659,
199,
199,
2087,
14,
525,
63,
2094,
3654,
70,
297,
2053,
534,
5252,
297,
8214,
534,
4846,
297,
1415,
29,
549,
12,
1720,
534,
2959,
1300,
1788,
2659,
199,
199,
2087,
14,
525,
63,
2094,
3654,
44,
297,
2053,
534,
44,
297,
8214,
534,
1267,
297,
1415,
29,
549,
12,
730,
29,
1609,
12,
1720,
534,
8108,
2582,
334,
2405,
365,
491,
62,
19,
5942,
199,
199,
2087,
14,
525,
63,
2094,
3654,
77,
297,
2053,
534,
77,
297,
8214,
534,
77,
297,
1415,
29,
549,
12,
730,
29,
442,
12,
490,
1720,
534,
7900,
12401,
14,
19271,
1329,
402,
14164,
88,
18099,
787,
334,
77,
10,
44,
18979,
19,
358,
199,
199,
2087,
14,
525,
63,
2094,
4517,
5650,
63,
10865,
63,
16117,
297,
2053,
628,
5650,
63,
10865,
63,
16117,
401,
8214,
534,
86,
297,
1415,
29,
549,
12,
730,
29,
1609,
12,
490,
1720,
534,
31274,
367,
3301,
12347,
644,
35,
334,
476,
4923,
15145,
5942,
199,
199,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2053,
534,
5176,
297,
8214,
534,
83,
297,
849,
29,
403,
12,
730,
29,
442,
12,
490,
1720,
534,
19554,
367,
820,
12259,
14,
9138,
13130,
2633,
12,
283,
435,
586,
283,
2571,
6437,
911,
3550,
13130,
1072,
1627,
282,
22284,
6347,
2659,
199,
199,
2087,
14,
525,
63,
2094,
4517,
270,
803,
63,
7661,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
6580,
1536,
410,
803,
14164,
88,
18099,
358,
199,
199,
923,
275,
1798,
14,
525,
63,
2094,
63,
923,
360,
55,
35,
1999,
262,
2215,
358,
199,
923,
14,
525,
63,
2094,
3654,
75,
297,
2053,
534,
75,
63,
2686,
297,
8214,
534,
466,
14343,
1162,
4300,
849,
534,
53,
26,
16,
14,
20,
12,
17,
14,
20,
297,
673,
1720,
534,
75,
4084,
358,
199,
923,
14,
525,
63,
2094,
3654,
82,
297,
2053,
534,
82,
63,
2686,
297,
8214,
534,
466,
14343,
1162,
4300,
849,
534,
53,
26,
16,
14,
17,
12,
16,
14,
20,
297,
673,
1720,
534,
82,
4084,
358,
199,
923,
14,
525,
63,
2094,
3654,
68,
297,
2053,
534,
68,
63,
2686,
297,
8214,
534,
466,
14343,
1162,
4300,
849,
534,
53,
26,
16,
14,
21,
12,
17,
14,
21,
297,
673,
1720,
534,
68,
4084,
358,
199,
199,
923,
275,
1798,
14,
525,
63,
2094,
63,
923,
360,
2305,
316,
358,
199,
923,
14,
525,
63,
2094,
4517,
1180,
63,
24668,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
6119,
1833,
348,
3398,
12330,
2659,
199,
923,
14,
525,
63,
2094,
4517,
7865,
63,
6264,
297,
2053,
534,
7865,
63,
6264,
297,
8214,
534,
78,
297,
849,
29,
21962,
12,
730,
29,
442,
12,
673,
1720,
534,
3259,
402,
2196,
15547,
2659,
199,
923,
14,
525,
63,
2094,
4517,
3136,
297,
2053,
534,
3136,
297,
8214,
534,
68,
297,
730,
29,
1609,
12,
673,
1720,
534,
10915,
6033,
367,
2196,
1759,
15547,
2659,
199,
923,
14,
525,
63,
2094,
4517,
77,
63,
331,
30672,
297,
2053,
628,
77,
63,
331,
30672,
401,
8214,
534,
5466,
297,
849,
29,
709,
12,
673,
1720,
534,
7900,
12401,
5309,
1706,
316,
2659,
199,
199,
923,
275,
1798,
14,
525,
63,
2094,
63,
923,
360,
48,
357,
1086,
17625,
358,
199,
923,
14,
525,
63,
2094,
4517,
5466,
63,
5895,
297,
2053,
628,
5466,
63,
5895,
401,
8214,
534,
5895,
297,
849,
29,
16,
14,
1717,
12,
730,
29,
1609,
12,
673,
1720,
534,
6671,
266,
13,
16034,
320,
7124,
334,
30832,
543,
334,
77,
10,
44,
18979,
20,
14,
2494,
370,
4697,
370,
7485,
2331,
2659,
199,
923,
14,
525,
63,
2094,
4517,
16656,
297,
2053,
534,
16656,
297,
8214,
534,
84,
297,
849,
29,
16,
14,
21,
12,
730,
29,
1609,
12,
673,
1720,
534,
38,
530,
31089,
1785,
14843,
315,
510,
357,
1086,
1402,
2659,
199,
199,
1419,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
692,
1511,
14,
5176,
365,
440,
488,
26,
272,
980,
14,
2355,
14,
5176,
8,
1419,
14,
5176,
9,
199,
199,
3,
5311,
20911,
4412,
687,
3503,
370,
14850,
3301,
12347,
199,
3
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
7534,
199,
646,
5927,
199,
646,
900,
199,
646,
17586,
6437,
465,
286,
2894,
199,
646,
17586,
6437,
63,
67,
465,
286,
2894,
63,
67,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
6664,
421,
199,
318,
14818,
63,
2686,
8,
88,
304,
272,
408,
1803,
14818,
10208,
402,
1627,
1425,
408,
272,
372,
2400,
26,
980,
14,
2355,
14,
8830,
8,
88,
59,
16,
467,
671,
59,
17,
566,
421,
199,
318,
781,
20587,
63,
2686,
8,
65,
12,
8504,
304,
272,
408,
1803,
2136,
20587,
10208,
367,
1627,
2215,
2725,
436,
8095,
408,
272,
372,
2400,
26,
980,
14,
2355,
14,
1129,
20587,
8,
65,
9,
627,
8504,
1182,
7026,
14,
6664,
14,
7325,
8,
17,
15,
65,
435,
413,
9,
421,
199,
318,
2198,
63,
2686,
8,
1273,
304,
272,
327,
29968,
1324,
1059,
367,
1627,
4084,
14,
272,
327,
1803,
282,
4084,
12,
436,
314,
8095,
272,
366,
12,
1862,
275,
1680,
14,
1294,
11633,
272,
1862,
275,
359,
1609,
8,
88,
9,
367,
671,
315,
1862,
14,
1294,
29972,
272,
340,
366,
508,
283,
53,
356,
267,
372,
14818,
63,
2686,
8,
1162,
395,
980,
14,
3670,
8,
1162,
9,
272,
916,
366,
508,
283,
55,
356,
267,
282,
12,
8504,
275,
1862,
267,
372,
781,
20587,
63,
2686,
8,
65,
12,
8504,
395,
8504,
421,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
19938,
6864,
282,
644,
35,
9967,
6976,
14,
199,
5761,
262,
2215,
15,
890,
5171,
499,
2943,
402,
10208,
26,
199,
12421,
26,
738,
26,
674,
12,
6260,
199,
24689,
26,
738,
26,
65,
12,
6553,
258,
334,
65,
29,
75,
315,
2005,
15843,
12,
8504,
29,
3670,
9,
199,
18108,
639,
9698,
63,
533,
29,
18978,
14,
5201,
16986,
22779,
9,
199,
199,
3,
1798,
14,
525,
63,
2094,
3654,
54,
297,
2053,
534,
3832,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
21879,
818,
2659,
199,
199,
2087,
14,
525,
63,
2094,
3654,
70,
297,
2053,
534,
5252,
297,
8214,
534,
4846,
297,
1415,
29,
549,
12,
1720,
534,
2959,
1300,
1788,
2659,
199,
199,
2087,
14,
525,
63,
2094,
3654,
44,
297,
2053,
534,
44,
297,
8214,
534,
1267,
297,
1415,
29,
549,
12,
730,
29,
1609,
12,
1720,
534,
8108,
2582,
334,
2405,
365,
491,
62,
19,
5942,
199,
199,
2087,
14,
525,
63,
2094,
3654,
77,
297,
2053,
534,
77,
297,
8214,
534,
77,
297,
1415,
29,
549,
12,
730,
29,
442,
12,
490,
1720,
534,
7900,
12401,
14,
19271,
1329,
402,
14164,
88,
18099,
787,
334,
77,
10,
44,
18979,
19,
358,
199,
199,
2087,
14,
525,
63,
2094,
4517,
5650,
63,
10865,
63,
16117,
297,
2053,
628,
5650,
63,
10865,
63,
16117,
401,
8214,
534,
86,
297,
1415,
29,
549,
12,
730,
29,
1609,
12,
490,
1720,
534,
31274,
367,
3301,
12347,
644,
35,
334,
476,
4923,
15145,
5942,
199,
199,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2053,
534,
5176,
297,
8214,
534,
83,
297,
849,
29,
403,
12,
730,
29,
442,
12,
490,
1720,
534,
19554,
367,
820,
12259,
14,
9138,
13130,
2633,
12,
283,
435,
586,
283,
2571,
6437,
911,
3550,
13130,
1072,
1627,
282,
22284,
6347,
2659,
199,
199,
2087,
14,
525,
63,
2094,
4517,
270,
803,
63,
7661,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
6580,
1536,
410,
803,
14164,
88,
18099,
358,
199,
199,
923,
275,
1798,
14,
525,
63,
2094,
63,
923,
360,
55,
35,
1999,
262,
2215,
358,
199,
923,
14,
525,
63,
2094,
3654,
75,
297,
2053,
534,
75,
63,
2686,
297,
8214,
534,
466,
14343,
1162,
4300,
849,
534,
53,
26,
16,
14,
20,
12,
17,
14,
20,
297,
673,
1720,
534,
75,
4084,
358,
199,
923,
14,
525,
63,
2094,
3654,
82,
297,
2053,
534,
82,
63,
2686,
297,
8214,
534,
466,
14343,
1162,
4300,
849,
534,
53,
26,
16,
14,
17,
12,
16,
14,
20,
297,
673,
1720,
534,
82,
4084,
358,
199,
923,
14,
525,
63,
2094,
3654,
68,
297,
2053,
534,
68,
63,
2686,
297,
8214,
534,
466,
14343,
1162,
4300,
849,
534,
53,
26,
16,
14,
21,
12,
17,
14,
21,
297,
673,
1720,
534,
68,
4084,
358,
199,
199,
923,
275,
1798,
14,
525,
63,
2094,
63,
923,
360,
2305,
316,
358,
199,
923,
14,
525,
63,
2094,
4517,
1180,
63,
24668,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
6119,
1833,
348,
3398,
12330,
2659,
199,
923,
14,
525,
63,
2094,
4517,
7865,
63,
6264,
297,
2053,
534,
7865,
63,
6264,
297,
8214,
534,
78,
297,
849,
29,
21962,
12,
730,
29,
442,
12,
673,
1720,
534,
3259,
402,
2196,
15547,
2659,
199,
923,
14,
525,
63,
2094,
4517,
3136,
297,
2053,
534,
3136,
297,
8214,
534,
68,
297,
730,
29,
1609,
12,
673,
1720,
534,
10915,
6033,
367,
2196,
1759,
15547,
2659,
199,
923,
14,
525,
63,
2094,
4517,
77,
63,
331,
30672,
297,
2053,
628,
77,
63,
331,
30672,
401,
8214,
534,
5466,
297,
849,
29,
709,
12,
673,
1720,
534,
7900,
12401,
5309,
1706,
316,
2659,
199,
199,
923,
275,
1798,
14,
525,
63,
2094,
63,
923,
360,
48,
357,
1086,
17625,
358,
199,
923,
14,
525,
63,
2094,
4517,
5466,
63,
5895,
297,
2053,
628,
5466,
63,
5895,
401,
8214,
534,
5895,
297,
849,
29,
16,
14,
1717,
12,
730,
29,
1609,
12,
673,
1720,
534,
6671,
266,
13,
16034,
320,
7124,
334,
30832,
543,
334,
77,
10,
44,
18979,
20,
14,
2494,
370,
4697,
370,
7485,
2331,
2659,
199,
923,
14,
525,
63,
2094,
4517,
16656,
297,
2053,
534,
16656,
297,
8214,
534,
84,
297,
849,
29,
16,
14,
21,
12,
730,
29,
1609,
12,
673,
1720,
534,
38,
530,
31089,
1785,
14843,
315,
510,
357,
1086,
1402,
2659,
199,
199,
1419,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
692,
1511,
14,
5176,
365,
440,
488,
26,
272,
980,
14,
2355,
14,
5176,
8,
1419,
14,
5176,
9,
199,
199,
3,
5311,
20911,
4412,
687,
3503,
370,
14850,
3301,
12347,
199,
3,
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,
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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
] |
lyoniionly/django-cobra
|
src/cobra/models/fields/node.py
|
1
|
3306
|
from __future__ import absolute_import, print_function
import collections
import logging
import six
import warnings
from django.db import models
from django.db.models.signals import post_delete
from cobra.core.cache import memoize
from cobra.core.compat import pickle
from cobra.core.strings import decompress, compress
from .gzippeddict import GzippedDictField
try:
from south.modelsinspector import add_introspection_rules
except ImportError:
pass
else:
add_introspection_rules([], ["^cobra\.models\.fields\.node\.NodeField"])
__all__ = ('NodeField',)
logger = logging.getLogger('cobra.errors')
class NodeData(collections.MutableMapping):
def __init__(self, id, data=None):
self.id = id
self._node_data = data
def __getitem__(self, key):
return self.data[key]
def __setitem__(self, key, value):
self.data[key] = value
def __delitem__(self, key):
del self.data[key]
def __iter__(self):
return iter(self.data)
def __len__(self):
return len(self.data)
def __repr__(self):
cls_name = type(self).__name__
if self._node_data:
return '<%s: id=%s data=%r>' % (
cls_name, self.id, repr(self._node_data))
return '<%s: id=%s>' % (cls_name, self.id,)
@memoize
def data(self):
from cobra import singleton
if self._node_data is not None:
return self._node_data
elif self.id:
warnings.warn('You should populate node data before accessing it.')
return singleton.nodestore.get(self.id) or {}
return {}
def bind_data(self, data):
self._node_data = data
class NodeField(GzippedDictField):
"""
Similar to the gzippedictfield except that it stores a reference
to an external node.
"""
def contribute_to_class(self, cls, name):
super(NodeField, self).contribute_to_class(cls, name)
post_delete.connect(
self.on_delete,
sender=self.model,
weak=False)
def on_delete(self, instance, **kwargs):
from cobra import singleton
value = getattr(instance, self.name)
if not value.id:
return
singleton.nodestore.delete(value.id)
def to_python(self, value):
if isinstance(value, six.string_types) and value:
try:
value = pickle.loads(decompress(value))
except Exception as e:
logger.exception(e)
value = {}
elif not value:
value = {}
if 'node_id' in value:
node_id = value.pop('node_id')
data = None
else:
node_id = None
data = value
return NodeData(node_id, data)
def get_prep_value(self, value):
from cobra import singleton
if not value and self.null:
# save ourselves some storage
return None
# TODO(dcramer): we should probably do this more intelligently
# and manually
if not value.id:
value.id = singleton.nodestore.create(value.data)
else:
singleton.nodestore.set(value.id, value.data)
return compress(pickle.dumps({
'node_id': value.id
}))
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
5055,
199,
646,
2050,
199,
646,
3816,
199,
646,
3598,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
1807,
199,
199,
504,
512,
7828,
14,
1018,
14,
1637,
492,
11955,
794,
199,
504,
512,
7828,
14,
1018,
14,
5819,
492,
5927,
199,
504,
512,
7828,
14,
1018,
14,
5465,
492,
24733,
12,
11029,
199,
199,
504,
1275,
12256,
1915,
807,
492,
598,
3065,
1915,
2141,
792,
199,
199,
893,
26,
272,
687,
12919,
14,
992,
26047,
492,
1050,
63,
21627,
63,
4423,
199,
2590,
3545,
26,
272,
986,
199,
2836,
26,
272,
1050,
63,
21627,
63,
4423,
8798,
2097,
62,
331,
7828,
4537,
992,
4537,
955,
4537,
932,
4537,
1716,
792,
3135,
199,
199,
363,
452,
363,
275,
661,
1716,
792,
9538,
199,
199,
2921,
275,
2050,
14,
5572,
360,
331,
7828,
14,
2550,
358,
421,
199,
533,
5013,
1451,
8,
7882,
14,
17707,
7674,
304,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
666,
29,
403,
304,
267,
291,
14,
344,
275,
1305,
267,
291,
423,
932,
63,
576,
275,
666,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
14,
576,
59,
498,
61,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
291,
14,
576,
59,
498,
61,
275,
574,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
2150,
291,
14,
576,
59,
498,
61,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
576,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
576,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
843,
63,
354,
275,
730,
8,
277,
2843,
354,
363,
267,
340,
291,
423,
932,
63,
576,
26,
288,
372,
18342,
83,
26,
1305,
2458,
83,
666,
2458,
82,
3524,
450,
334,
355,
843,
63,
354,
12,
291,
14,
344,
12,
4700,
8,
277,
423,
932,
63,
576,
430,
267,
372,
18342,
83,
26,
1305,
2458,
83,
3524,
450,
334,
1886,
63,
354,
12,
291,
14,
344,
4258,
339,
768,
11979,
794,
272,
347,
666,
8,
277,
304,
267,
687,
512,
7828,
492,
19768,
398,
340,
291,
423,
932,
63,
576,
365,
440,
488,
26,
288,
372,
291,
423,
932,
63,
576,
398,
916,
291,
14,
344,
26,
288,
3598,
14,
4050,
360,
5556,
1077,
13904,
1031,
666,
2544,
18549,
652,
2659,
288,
372,
19768,
14,
932,
1617,
14,
362,
8,
277,
14,
344,
9,
503,
1052,
398,
372,
1052,
339,
347,
5398,
63,
576,
8,
277,
12,
666,
304,
267,
291,
423,
932,
63,
576,
275,
666,
421,
199,
533,
5013,
792,
8,
21975,
1915,
2141,
792,
304,
272,
408,
272,
20046,
370,
314,
11756,
321,
807,
698,
871,
626,
652,
14086,
282,
3659,
272,
370,
376,
5957,
1031,
14,
272,
408,
272,
347,
28567,
63,
475,
63,
533,
8,
277,
12,
843,
12,
536,
304,
267,
1613,
8,
1716,
792,
12,
291,
680,
388,
999,
63,
475,
63,
533,
8,
1886,
12,
536,
9,
267,
2963,
63,
1807,
14,
2242,
8,
288,
291,
14,
265,
63,
1807,
12,
288,
8904,
29,
277,
14,
1238,
12,
288,
9282,
29,
797,
9,
339,
347,
641,
63,
1807,
8,
277,
12,
1256,
12,
1011,
958,
304,
267,
687,
512,
7828,
492,
19768,
398,
574,
275,
2519,
8,
842,
12,
291,
14,
354,
9,
267,
340,
440,
574,
14,
344,
26,
288,
372,
398,
19768,
14,
932,
1617,
14,
1807,
8,
585,
14,
344,
9,
339,
347,
370,
63,
1548,
8,
277,
12,
574,
304,
267,
340,
1228,
8,
585,
12,
3816,
14,
875,
63,
1313,
9,
436,
574,
26,
288,
862,
26,
355,
574,
275,
5927,
14,
3640,
8,
14954,
8,
585,
430,
288,
871,
2186,
465,
325,
26,
355,
2512,
14,
1971,
8,
69,
9,
355,
574,
275,
1052,
267,
916,
440,
574,
26,
288,
574,
275,
1052,
398,
340,
283,
932,
63,
344,
7,
315,
574,
26,
288,
1031,
63,
344,
275,
574,
14,
1935,
360,
932,
63,
344,
358,
288,
666,
275,
488,
267,
587,
26,
288,
1031,
63,
344,
275,
488,
288,
666,
275,
574,
398,
372,
5013,
1451,
8,
932,
63,
344,
12,
666,
9,
339,
347,
664,
63,
10837,
63,
585,
8,
277,
12,
574,
304,
267,
687,
512,
7828,
492,
19768,
398,
340,
440,
574,
436,
291,
14,
2307,
26,
288,
327,
3354,
26495,
2005,
4887,
288,
372,
488,
398,
327,
3254,
8,
3833,
1186,
82,
304,
781,
1077,
8646,
886,
642,
1655,
4661,
24024,
590,
267,
327,
436,
10250,
267,
340,
440,
574,
14,
344,
26,
288,
574,
14,
344,
275,
19768,
14,
932,
1617,
14,
981,
8,
585,
14,
576,
9,
267,
587,
26,
288,
19768,
14,
932,
1617,
14,
409,
8,
585,
14,
344,
12,
574,
14,
576,
9,
398,
372,
11029,
8,
8092,
14,
4180,
2561,
288,
283,
932,
63,
344,
356,
574,
14,
344,
267,
23451,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
5055,
199,
646,
2050,
199,
646,
3816,
199,
646,
3598,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
1807,
199,
199,
504,
512,
7828,
14,
1018,
14,
1637,
492,
11955,
794,
199,
504,
512,
7828,
14,
1018,
14,
5819,
492,
5927,
199,
504,
512,
7828,
14,
1018,
14,
5465,
492,
24733,
12,
11029,
199,
199,
504,
1275,
12256,
1915,
807,
492,
598,
3065,
1915,
2141,
792,
199,
199,
893,
26,
272,
687,
12919,
14,
992,
26047,
492,
1050,
63,
21627,
63,
4423,
199,
2590,
3545,
26,
272,
986,
199,
2836,
26,
272,
1050,
63,
21627,
63,
4423,
8798,
2097,
62,
331,
7828,
4537,
992,
4537,
955,
4537,
932,
4537,
1716,
792,
3135,
199,
199,
363,
452,
363,
275,
661,
1716,
792,
9538,
199,
199,
2921,
275,
2050,
14,
5572,
360,
331,
7828,
14,
2550,
358,
421,
199,
533,
5013,
1451,
8,
7882,
14,
17707,
7674,
304,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
666,
29,
403,
304,
267,
291,
14,
344,
275,
1305,
267,
291,
423,
932,
63,
576,
275,
666,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
372,
291,
14,
576,
59,
498,
61,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
291,
14,
576,
59,
498,
61,
275,
574,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
2150,
291,
14,
576,
59,
498,
61,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
576,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
576,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
843,
63,
354,
275,
730,
8,
277,
2843,
354,
363,
267,
340,
291,
423,
932,
63,
576,
26,
288,
372,
18342,
83,
26,
1305,
2458,
83,
666,
2458,
82,
3524,
450,
334,
355,
843,
63,
354,
12,
291,
14,
344,
12,
4700,
8,
277,
423,
932,
63,
576,
430,
267,
372,
18342,
83,
26,
1305,
2458,
83,
3524,
450,
334,
1886,
63,
354,
12,
291,
14,
344,
4258,
339,
768,
11979,
794,
272,
347,
666,
8,
277,
304,
267,
687,
512,
7828,
492,
19768,
398,
340,
291,
423,
932,
63,
576,
365,
440,
488,
26,
288,
372,
291,
423,
932,
63,
576,
398,
916,
291,
14,
344,
26,
288,
3598,
14,
4050,
360,
5556,
1077,
13904,
1031,
666,
2544,
18549,
652,
2659,
288,
372,
19768,
14,
932,
1617,
14,
362,
8,
277,
14,
344,
9,
503,
1052,
398,
372,
1052,
339,
347,
5398,
63,
576,
8,
277,
12,
666,
304,
267,
291,
423,
932,
63,
576,
275,
666,
421,
199,
533,
5013,
792,
8,
21975,
1915,
2141,
792,
304,
272,
408,
272,
20046,
370,
314,
11756,
321,
807,
698,
871,
626,
652,
14086,
282,
3659,
272,
370,
376,
5957,
1031,
14,
272,
408,
272,
347,
28567,
63,
475,
63,
533,
8,
277,
12,
843,
12,
536,
304,
267,
1613,
8,
1716,
792,
12,
291,
680,
388,
999,
63,
475,
63,
533,
8,
1886,
12,
536,
9,
267,
2963,
63,
1807,
14,
2242,
8,
288,
291,
14,
265,
63,
1807,
12,
288,
8904,
29,
277,
14,
1238,
12,
288,
9282,
29,
797,
9,
339,
347,
641,
63,
1807,
8,
277,
12,
1256,
12,
1011,
958,
304,
267,
687,
512,
7828,
492,
19768,
398,
574,
275,
2519,
8,
842,
12,
291,
14,
354,
9,
267,
340,
440,
574,
14,
344,
26,
288,
372,
398,
19768,
14,
932,
1617,
14,
1807,
8,
585,
14,
344,
9,
339,
347,
370,
63,
1548,
8,
277,
12,
574,
304,
267,
340,
1228,
8,
585,
12,
3816,
14,
875,
63,
1313,
9,
436,
574,
26,
288,
862,
26,
355,
574,
275,
5927,
14,
3640,
8,
14954,
8,
585,
430,
288,
871,
2186,
465,
325,
26,
355,
2512,
14,
1971,
8,
69,
9,
355,
574,
275,
1052,
267,
916,
440,
574,
26,
288,
574,
275,
1052,
398,
340,
283,
932,
63,
344,
7,
315,
574,
26,
288,
1031,
63,
344,
275,
574,
14,
1935,
360,
932,
63,
344,
358,
288,
666,
275,
488,
267,
587,
26,
288,
1031,
63,
344,
275,
488,
288,
666,
275,
574,
398,
372,
5013,
1451,
8,
932,
63,
344,
12,
666,
9,
339,
347,
664,
63,
10837,
63,
585,
8,
277,
12,
574,
304,
267,
687,
512,
7828,
492,
19768,
398,
340,
440,
574,
436,
291,
14,
2307,
26,
288,
327,
3354,
26495,
2005,
4887,
288,
372,
488,
398,
327,
3254,
8,
3833,
1186,
82,
304,
781,
1077,
8646,
886,
642,
1655,
4661,
24024,
590,
267,
327,
436,
10250,
267,
340,
440,
574,
14,
344,
26,
288,
574,
14,
344,
275,
19768,
14,
932,
1617,
14,
981,
8,
585,
14,
576,
9,
267,
587,
26,
288,
19768,
14,
932,
1617,
14,
409,
8,
585,
14,
344,
12,
574,
14,
576,
9,
398,
372,
11029,
8,
8092,
14,
4180,
2561,
288,
283,
932,
63,
344,
356,
574,
14,
344,
267,
23451,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
technologiescollege/Blockly-rduino-communication
|
scripts_XP/Lib/site-packages/jedi/evaluate/arguments.py
|
8
|
9709
|
from parso.python import tree
from jedi._compatibility import zip_longest
from jedi import debug
from jedi.evaluate import analysis
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts, \
LazyTreeContext, get_merged_lazy_context
from jedi.evaluate.filters import ParamName
from jedi.evaluate.base_context import NO_CONTEXTS
from jedi.evaluate.context import iterable
from jedi.evaluate.param import get_params, ExecutedParam
def try_iter_content(types, depth=0):
"""Helper method for static analysis."""
if depth > 10:
# It's possible that a loop has references on itself (especially with
# CompiledObject). Therefore don't loop infinitely.
return
for typ in types:
try:
f = typ.py__iter__
except AttributeError:
pass
else:
for lazy_context in f():
try_iter_content(lazy_context.infer(), depth + 1)
class AbstractArguments(object):
context = None
argument_node = None
trailer = None
def eval_argument_clinic(self, parameters):
"""Uses a list with argument clinic information (see PEP 436)."""
iterator = self.unpack()
for i, (name, optional, allow_kwargs) in enumerate(parameters):
key, argument = next(iterator, (None, None))
if key is not None:
raise NotImplementedError
if argument is None and not optional:
debug.warning('TypeError: %s expected at least %s arguments, got %s',
name, len(parameters), i)
raise ValueError
values = NO_CONTEXTS if argument is None else argument.infer()
if not values and not optional:
# For the stdlib we always want values. If we don't get them,
# that's ok, maybe something is too hard to resolve, however,
# we will not proceed with the evaluation of that function.
debug.warning('argument_clinic "%s" not resolvable.', name)
raise ValueError
yield values
def eval_all(self, funcdef=None):
"""
Evaluates all arguments as a support for static analysis
(normally Jedi).
"""
for key, lazy_context in self.unpack():
types = lazy_context.infer()
try_iter_content(types)
def get_calling_nodes(self):
raise NotImplementedError
def unpack(self, funcdef=None):
raise NotImplementedError
def get_params(self, execution_context):
return get_params(execution_context, self)
class AnonymousArguments(AbstractArguments):
def get_params(self, execution_context):
from jedi.evaluate.dynamic import search_params
return search_params(
execution_context.evaluator,
execution_context,
execution_context.tree_node
)
class TreeArguments(AbstractArguments):
def __init__(self, evaluator, context, argument_node, trailer=None):
"""
The argument_node is either a parser node or a list of evaluated
objects. Those evaluated objects may be lists of evaluated objects
themselves (one list for the first argument, one for the second, etc).
:param argument_node: May be an argument_node or a list of nodes.
"""
self.argument_node = argument_node
self.context = context
self._evaluator = evaluator
self.trailer = trailer # Can be None, e.g. in a class definition.
def _split(self):
if self.argument_node is None:
return
# Allow testlist here as well for Python2's class inheritance
# definitions.
if not (self.argument_node.type in ('arglist', 'testlist') or (
# in python 3.5 **arg is an argument, not arglist
(self.argument_node.type == 'argument') and
self.argument_node.children[0] in ('*', '**'))):
yield 0, self.argument_node
return
iterator = iter(self.argument_node.children)
for child in iterator:
if child == ',':
continue
elif child in ('*', '**'):
yield len(child.value), next(iterator)
elif child.type == 'argument' and \
child.children[0] in ('*', '**'):
assert len(child.children) == 2
yield len(child.children[0].value), child.children[1]
else:
yield 0, child
def unpack(self, funcdef=None):
named_args = []
for star_count, el in self._split():
if star_count == 1:
arrays = self.context.eval_node(el)
iterators = [_iterate_star_args(self.context, a, el, funcdef)
for a in arrays]
for values in list(zip_longest(*iterators)):
# TODO zip_longest yields None, that means this would raise
# an exception?
yield None, get_merged_lazy_context(
[v for v in values if v is not None]
)
elif star_count == 2:
arrays = self.context.eval_node(el)
for dct in arrays:
for key, values in _star_star_dict(self.context, dct, el, funcdef):
yield key, values
else:
if el.type == 'argument':
c = el.children
if len(c) == 3: # Keyword argument.
named_args.append((c[0].value, LazyTreeContext(self.context, c[2]),))
else: # Generator comprehension.
# Include the brackets with the parent.
comp = iterable.GeneratorComprehension(
self._evaluator, self.context, self.argument_node.parent)
yield None, LazyKnownContext(comp)
else:
yield None, LazyTreeContext(self.context, el)
# Reordering var_args is necessary, because star args sometimes appear
# after named argument, but in the actual order it's prepended.
for named_arg in named_args:
yield named_arg
def as_tree_tuple_objects(self):
for star_count, argument in self._split():
if argument.type == 'argument':
argument, default = argument.children[::2]
else:
default = None
yield argument, default, star_count
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.argument_node)
def get_calling_nodes(self):
from jedi.evaluate.dynamic import MergedExecutedParams
old_arguments_list = []
arguments = self
while arguments not in old_arguments_list:
if not isinstance(arguments, TreeArguments):
break
old_arguments_list.append(arguments)
for name, default, star_count in reversed(list(arguments.as_tree_tuple_objects())):
if not star_count or not isinstance(name, tree.Name):
continue
names = self._evaluator.goto(arguments.context, name)
if len(names) != 1:
break
if not isinstance(names[0], ParamName):
break
param = names[0].get_param()
if isinstance(param, MergedExecutedParams):
# For dynamic searches we don't even want to see errors.
return []
if not isinstance(param, ExecutedParam):
break
if param.var_args is None:
break
arguments = param.var_args
break
if arguments.argument_node is not None:
return [arguments.argument_node]
if arguments.trailer is not None:
return [arguments.trailer]
return []
class ValuesArguments(AbstractArguments):
def __init__(self, values_list):
self._values_list = values_list
def unpack(self, funcdef=None):
for values in self._values_list:
yield None, LazyKnownContexts(values)
def get_calling_nodes(self):
return []
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self._values_list)
def _iterate_star_args(context, array, input_node, funcdef=None):
try:
iter_ = array.py__iter__
except AttributeError:
if funcdef is not None:
# TODO this funcdef should not be needed.
m = "TypeError: %s() argument after * must be a sequence, not %s" \
% (funcdef.name.value, array)
analysis.add(context, 'type-error-star', input_node, message=m)
else:
for lazy_context in iter_():
yield lazy_context
def _star_star_dict(context, array, input_node, funcdef):
from jedi.evaluate.context.instance import CompiledInstance
if isinstance(array, CompiledInstance) and array.name.string_name == 'dict':
# For now ignore this case. In the future add proper iterators and just
# make one call without crazy isinstance checks.
return {}
elif isinstance(array, iterable.Sequence) and array.array_type == 'dict':
return array.exact_key_items()
else:
if funcdef is not None:
m = "TypeError: %s argument after ** must be a mapping, not %s" \
% (funcdef.name.value, array)
analysis.add(context, 'type-error-star-star', input_node, message=m)
return {}
|
gpl-3.0
|
[
504,
623,
1152,
14,
1548,
492,
3123,
199,
199,
504,
1335,
6297,
423,
15390,
492,
3482,
63,
20820,
199,
504,
1335,
6297,
492,
3105,
199,
504,
1335,
6297,
14,
7383,
492,
11284,
199,
504,
1335,
6297,
14,
7383,
14,
6395,
63,
1100,
492,
22373,
24574,
2998,
12,
22373,
24574,
2998,
83,
12,
971,
272,
22373,
3987,
2998,
12,
664,
63,
15269,
63,
6395,
63,
1100,
199,
504,
1335,
6297,
14,
7383,
14,
4273,
492,
12608,
985,
199,
504,
1335,
6297,
14,
7383,
14,
1095,
63,
1100,
492,
4825,
63,
9059,
51,
199,
504,
1335,
6297,
14,
7383,
14,
1100,
492,
6076,
199,
504,
1335,
6297,
14,
7383,
14,
635,
492,
664,
63,
1162,
12,
9434,
4241,
4098,
421,
199,
318,
862,
63,
1661,
63,
1317,
8,
1313,
12,
5818,
29,
16,
304,
272,
408,
4433,
1083,
367,
2955,
11284,
1041,
272,
340,
5818,
690,
1616,
26,
267,
327,
2779,
1159,
3962,
626,
282,
4438,
965,
6941,
641,
6337,
334,
397,
910,
1183,
543,
267,
327,
3599,
1672,
1692,
680,
21039,
2793,
1133,
4438,
15258,
590,
14,
267,
372,
339,
367,
6211,
315,
2943,
26,
267,
862,
26,
288,
289,
275,
6211,
14,
647,
363,
1661,
363,
267,
871,
4281,
26,
288,
986,
267,
587,
26,
288,
367,
9617,
63,
1100,
315,
289,
837,
355,
862,
63,
1661,
63,
1317,
8,
6395,
63,
1100,
14,
14578,
1062,
5818,
435,
413,
9,
421,
199,
533,
11836,
14517,
8,
785,
304,
272,
1067,
275,
488,
272,
1423,
63,
932,
275,
488,
272,
17357,
275,
488,
339,
347,
3468,
63,
2094,
63,
429,
26715,
8,
277,
12,
2633,
304,
267,
408,
21896,
282,
769,
543,
1423,
286,
472,
530,
2556,
334,
3239,
13663,
841,
1344,
10477,
267,
6122,
275,
291,
14,
5301,
342,
267,
367,
284,
12,
334,
354,
12,
2716,
12,
2040,
63,
958,
9,
315,
3874,
8,
3214,
304,
288,
790,
12,
1423,
275,
2163,
8,
5778,
12,
334,
403,
12,
488,
430,
288,
340,
790,
365,
440,
488,
26,
355,
746,
4279,
288,
340,
1423,
365,
488,
436,
440,
2716,
26,
355,
3105,
14,
3764,
360,
4333,
26,
450,
83,
1420,
737,
5210,
450,
83,
2368,
12,
4788,
450,
83,
297,
2892,
536,
12,
822,
8,
3214,
395,
284,
9,
355,
746,
1722,
288,
1338,
275,
4825,
63,
9059,
51,
340,
1423,
365,
488,
587,
1423,
14,
14578,
342,
953,
340,
440,
1338,
436,
440,
2716,
26,
355,
327,
2104,
314,
26678,
781,
3544,
2934,
1338,
14,
982,
781,
2793,
1133,
664,
3062,
12,
355,
327,
626,
1159,
4112,
12,
11703,
6020,
365,
4634,
7508,
370,
7512,
12,
13432,
12,
355,
327,
781,
911,
440,
20320,
543,
314,
11735,
402,
626,
805,
14,
355,
3105,
14,
3764,
360,
2094,
63,
429,
26715,
2071,
83,
2,
440,
17416,
30456,
3130,
536,
9,
355,
746,
1722,
288,
1995,
1338,
339,
347,
3468,
63,
452,
8,
277,
12,
2562,
318,
29,
403,
304,
267,
408,
267,
16494,
85,
2335,
1006,
2368,
465,
282,
2291,
367,
2955,
11284,
267,
334,
4791,
1183,
1603,
6297,
680,
267,
408,
267,
367,
790,
12,
9617,
63,
1100,
315,
291,
14,
5301,
837,
288,
2943,
275,
9617,
63,
1100,
14,
14578,
342,
288,
862,
63,
1661,
63,
1317,
8,
1313,
9,
339,
347,
664,
63,
25566,
63,
2415,
8,
277,
304,
267,
746,
4279,
339,
347,
7787,
8,
277,
12,
2562,
318,
29,
403,
304,
267,
746,
4279,
339,
347,
664,
63,
1162,
8,
277,
12,
6451,
63,
1100,
304,
267,
372,
664,
63,
1162,
8,
9416,
63,
1100,
12,
291,
9,
421,
199,
533,
24523,
14517,
8,
8458,
14517,
304,
272,
347,
664,
63,
1162,
8,
277,
12,
6451,
63,
1100,
304,
267,
687,
1335,
6297,
14,
7383,
14,
7764,
492,
2754,
63,
1162,
267,
372,
2754,
63,
1162,
8,
288,
6451,
63,
1100,
14,
27406,
12,
288,
6451,
63,
1100,
12,
288,
6451,
63,
1100,
14,
2350,
63,
932,
267,
776,
421,
199,
533,
12178,
14517,
8,
8458,
14517,
304,
272,
347,
636,
826,
721,
277,
12,
29207,
12,
1067,
12,
1423,
63,
932,
12,
17357,
29,
403,
304,
267,
408,
267,
710,
1423,
63,
932,
365,
1902,
282,
1798,
1031,
503,
282,
769,
402,
13006,
267,
2251,
14,
18049,
261,
13006,
2251,
1443,
506,
5548,
402,
13006,
2251,
267,
17279,
334,
368,
769,
367,
314,
1642,
1423,
12,
1373,
367,
314,
3499,
12,
5423,
680,
398,
520,
635,
1423,
63,
932,
26,
10162,
506,
376,
1423,
63,
932,
503,
282,
769,
402,
3380,
14,
267,
408,
267,
291,
14,
2094,
63,
932,
275,
1423,
63,
932,
267,
291,
14,
1100,
275,
1067,
267,
291,
423,
27406,
275,
29207,
267,
291,
14,
21606,
275,
17357,
221,
327,
6855,
506,
488,
12,
325,
14,
71,
14,
315,
282,
1021,
5492,
14,
339,
347,
485,
1294,
8,
277,
304,
267,
340,
291,
14,
2094,
63,
932,
365,
488,
26,
288,
372,
398,
327,
9812,
511,
513,
2348,
465,
5521,
367,
2018,
18,
1159,
1021,
15433,
267,
327,
10269,
14,
267,
340,
440,
334,
277,
14,
2094,
63,
932,
14,
466,
315,
661,
26995,
297,
283,
396,
513,
358,
503,
334,
355,
327,
315,
2366,
650,
14,
21,
1011,
1273,
365,
376,
1423,
12,
440,
24660,
355,
334,
277,
14,
2094,
63,
932,
14,
466,
508,
283,
2094,
358,
436,
326,
291,
14,
2094,
63,
932,
14,
3223,
59,
16,
61,
315,
661,
7693,
23940,
1333,
304,
288,
1995,
378,
12,
291,
14,
2094,
63,
932,
288,
372,
398,
6122,
275,
2740,
8,
277,
14,
2094,
63,
932,
14,
3223,
9,
267,
367,
1982,
315,
6122,
26,
288,
340,
1982,
508,
1656,
356,
355,
1980,
288,
916,
1982,
315,
661,
7693,
23940,
735,
355,
1995,
822,
8,
1739,
14,
585,
395,
2163,
8,
5778,
9,
288,
916,
1982,
14,
466,
508,
283,
2094,
7,
436,
971,
490,
1982,
14,
3223,
59,
16,
61,
315,
661,
7693,
23940,
735,
355,
702,
822,
8,
1739,
14,
3223,
9,
508,
499,
355,
1995,
822,
8,
1739,
14,
3223,
59,
16,
1055,
585,
395,
1982,
14,
3223,
59,
17,
61,
288,
587,
26,
355,
1995,
378,
12,
1982,
339,
347,
7787,
8,
277,
12,
2562,
318,
29,
403,
304,
267,
4310,
63,
589,
275,
942,
267,
367,
14664
] |
[
623,
1152,
14,
1548,
492,
3123,
199,
199,
504,
1335,
6297,
423,
15390,
492,
3482,
63,
20820,
199,
504,
1335,
6297,
492,
3105,
199,
504,
1335,
6297,
14,
7383,
492,
11284,
199,
504,
1335,
6297,
14,
7383,
14,
6395,
63,
1100,
492,
22373,
24574,
2998,
12,
22373,
24574,
2998,
83,
12,
971,
272,
22373,
3987,
2998,
12,
664,
63,
15269,
63,
6395,
63,
1100,
199,
504,
1335,
6297,
14,
7383,
14,
4273,
492,
12608,
985,
199,
504,
1335,
6297,
14,
7383,
14,
1095,
63,
1100,
492,
4825,
63,
9059,
51,
199,
504,
1335,
6297,
14,
7383,
14,
1100,
492,
6076,
199,
504,
1335,
6297,
14,
7383,
14,
635,
492,
664,
63,
1162,
12,
9434,
4241,
4098,
421,
199,
318,
862,
63,
1661,
63,
1317,
8,
1313,
12,
5818,
29,
16,
304,
272,
408,
4433,
1083,
367,
2955,
11284,
1041,
272,
340,
5818,
690,
1616,
26,
267,
327,
2779,
1159,
3962,
626,
282,
4438,
965,
6941,
641,
6337,
334,
397,
910,
1183,
543,
267,
327,
3599,
1672,
1692,
680,
21039,
2793,
1133,
4438,
15258,
590,
14,
267,
372,
339,
367,
6211,
315,
2943,
26,
267,
862,
26,
288,
289,
275,
6211,
14,
647,
363,
1661,
363,
267,
871,
4281,
26,
288,
986,
267,
587,
26,
288,
367,
9617,
63,
1100,
315,
289,
837,
355,
862,
63,
1661,
63,
1317,
8,
6395,
63,
1100,
14,
14578,
1062,
5818,
435,
413,
9,
421,
199,
533,
11836,
14517,
8,
785,
304,
272,
1067,
275,
488,
272,
1423,
63,
932,
275,
488,
272,
17357,
275,
488,
339,
347,
3468,
63,
2094,
63,
429,
26715,
8,
277,
12,
2633,
304,
267,
408,
21896,
282,
769,
543,
1423,
286,
472,
530,
2556,
334,
3239,
13663,
841,
1344,
10477,
267,
6122,
275,
291,
14,
5301,
342,
267,
367,
284,
12,
334,
354,
12,
2716,
12,
2040,
63,
958,
9,
315,
3874,
8,
3214,
304,
288,
790,
12,
1423,
275,
2163,
8,
5778,
12,
334,
403,
12,
488,
430,
288,
340,
790,
365,
440,
488,
26,
355,
746,
4279,
288,
340,
1423,
365,
488,
436,
440,
2716,
26,
355,
3105,
14,
3764,
360,
4333,
26,
450,
83,
1420,
737,
5210,
450,
83,
2368,
12,
4788,
450,
83,
297,
2892,
536,
12,
822,
8,
3214,
395,
284,
9,
355,
746,
1722,
288,
1338,
275,
4825,
63,
9059,
51,
340,
1423,
365,
488,
587,
1423,
14,
14578,
342,
953,
340,
440,
1338,
436,
440,
2716,
26,
355,
327,
2104,
314,
26678,
781,
3544,
2934,
1338,
14,
982,
781,
2793,
1133,
664,
3062,
12,
355,
327,
626,
1159,
4112,
12,
11703,
6020,
365,
4634,
7508,
370,
7512,
12,
13432,
12,
355,
327,
781,
911,
440,
20320,
543,
314,
11735,
402,
626,
805,
14,
355,
3105,
14,
3764,
360,
2094,
63,
429,
26715,
2071,
83,
2,
440,
17416,
30456,
3130,
536,
9,
355,
746,
1722,
288,
1995,
1338,
339,
347,
3468,
63,
452,
8,
277,
12,
2562,
318,
29,
403,
304,
267,
408,
267,
16494,
85,
2335,
1006,
2368,
465,
282,
2291,
367,
2955,
11284,
267,
334,
4791,
1183,
1603,
6297,
680,
267,
408,
267,
367,
790,
12,
9617,
63,
1100,
315,
291,
14,
5301,
837,
288,
2943,
275,
9617,
63,
1100,
14,
14578,
342,
288,
862,
63,
1661,
63,
1317,
8,
1313,
9,
339,
347,
664,
63,
25566,
63,
2415,
8,
277,
304,
267,
746,
4279,
339,
347,
7787,
8,
277,
12,
2562,
318,
29,
403,
304,
267,
746,
4279,
339,
347,
664,
63,
1162,
8,
277,
12,
6451,
63,
1100,
304,
267,
372,
664,
63,
1162,
8,
9416,
63,
1100,
12,
291,
9,
421,
199,
533,
24523,
14517,
8,
8458,
14517,
304,
272,
347,
664,
63,
1162,
8,
277,
12,
6451,
63,
1100,
304,
267,
687,
1335,
6297,
14,
7383,
14,
7764,
492,
2754,
63,
1162,
267,
372,
2754,
63,
1162,
8,
288,
6451,
63,
1100,
14,
27406,
12,
288,
6451,
63,
1100,
12,
288,
6451,
63,
1100,
14,
2350,
63,
932,
267,
776,
421,
199,
533,
12178,
14517,
8,
8458,
14517,
304,
272,
347,
636,
826,
721,
277,
12,
29207,
12,
1067,
12,
1423,
63,
932,
12,
17357,
29,
403,
304,
267,
408,
267,
710,
1423,
63,
932,
365,
1902,
282,
1798,
1031,
503,
282,
769,
402,
13006,
267,
2251,
14,
18049,
261,
13006,
2251,
1443,
506,
5548,
402,
13006,
2251,
267,
17279,
334,
368,
769,
367,
314,
1642,
1423,
12,
1373,
367,
314,
3499,
12,
5423,
680,
398,
520,
635,
1423,
63,
932,
26,
10162,
506,
376,
1423,
63,
932,
503,
282,
769,
402,
3380,
14,
267,
408,
267,
291,
14,
2094,
63,
932,
275,
1423,
63,
932,
267,
291,
14,
1100,
275,
1067,
267,
291,
423,
27406,
275,
29207,
267,
291,
14,
21606,
275,
17357,
221,
327,
6855,
506,
488,
12,
325,
14,
71,
14,
315,
282,
1021,
5492,
14,
339,
347,
485,
1294,
8,
277,
304,
267,
340,
291,
14,
2094,
63,
932,
365,
488,
26,
288,
372,
398,
327,
9812,
511,
513,
2348,
465,
5521,
367,
2018,
18,
1159,
1021,
15433,
267,
327,
10269,
14,
267,
340,
440,
334,
277,
14,
2094,
63,
932,
14,
466,
315,
661,
26995,
297,
283,
396,
513,
358,
503,
334,
355,
327,
315,
2366,
650,
14,
21,
1011,
1273,
365,
376,
1423,
12,
440,
24660,
355,
334,
277,
14,
2094,
63,
932,
14,
466,
508,
283,
2094,
358,
436,
326,
291,
14,
2094,
63,
932,
14,
3223,
59,
16,
61,
315,
661,
7693,
23940,
1333,
304,
288,
1995,
378,
12,
291,
14,
2094,
63,
932,
288,
372,
398,
6122,
275,
2740,
8,
277,
14,
2094,
63,
932,
14,
3223,
9,
267,
367,
1982,
315,
6122,
26,
288,
340,
1982,
508,
1656,
356,
355,
1980,
288,
916,
1982,
315,
661,
7693,
23940,
735,
355,
1995,
822,
8,
1739,
14,
585,
395,
2163,
8,
5778,
9,
288,
916,
1982,
14,
466,
508,
283,
2094,
7,
436,
971,
490,
1982,
14,
3223,
59,
16,
61,
315,
661,
7693,
23940,
735,
355,
702,
822,
8,
1739,
14,
3223,
9,
508,
499,
355,
1995,
822,
8,
1739,
14,
3223,
59,
16,
1055,
585,
395,
1982,
14,
3223,
59,
17,
61,
288,
587,
26,
355,
1995,
378,
12,
1982,
339,
347,
7787,
8,
277,
12,
2562,
318,
29,
403,
304,
267,
4310,
63,
589,
275,
942,
267,
367,
14664,
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,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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
] |
amgowano/oppia
|
core/domain/config_domain.py
|
6
|
7850
|
# coding: utf-8
#
# Copyright 2014 The Oppia 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.
"""Domain objects for configuration properties."""
from core.domain import user_services
from core.platform import models
import schema_utils
(config_models,) = models.Registry.import_models([models.NAMES.config])
memcache_services = models.Registry.import_memcache_services()
CMD_CHANGE_PROPERTY_VALUE = 'change_property_value'
SET_OF_STRINGS_SCHEMA = {
'type': 'list',
'items': {
'type': 'unicode',
},
'validators': [{
'id': 'is_uniquified',
}],
}
class ConfigProperty(object):
"""A property with a name and a default value.
NOTE TO DEVELOPERS: These config properties are deprecated. Do not reuse
these names:
- about_page_youtube_video_id
- admin_email_address
- allow_yaml_file_upload
- banner_alt_text
- before_end_body_tag_hook
- carousel_slides_config
- contact_email_address
- contribute_gallery_page_announcement
- disabled_explorations
- editor_page_announcement
- editor_prerequisites_agreement
- embedded_google_group_url
- full_site_url
- moderator_request_forum_url
- sharing_options
- sharing_options_twitter_text
- sidebar_menu_additional_links
- site_forum_url
- social_media_buttons
- splash_page_exploration_id
- splash_page_exploration_version
- splash_page_youtube_video_id
"""
def refresh_default_value(self, default_value):
pass
def __init__(self, name, schema, description, default_value,
post_set_hook=None, is_directly_settable=True):
if Registry.get_config_property(name):
raise Exception('Property with name %s already exists' % name)
self._name = name
self._schema = schema
self._description = description
self._default_value = schema_utils.normalize_against_schema(
default_value, self._schema)
self._post_set_hook = post_set_hook
self._is_directly_settable = is_directly_settable
Registry.init_config_property(self.name, self)
@property
def name(self):
return self._name
@property
def schema(self):
return self._schema
@property
def description(self):
return self._description
@property
def default_value(self):
return self._default_value
@property
def is_directly_settable(self):
return self._is_directly_settable
@property
def value(self):
"""Get the latest value from memcache, datastore, or use default."""
memcached_items = memcache_services.get_multi([self.name])
if self.name in memcached_items:
return memcached_items[self.name]
datastore_item = config_models.ConfigPropertyModel.get(
self.name, strict=False)
if datastore_item is not None:
memcache_services.set_multi({
datastore_item.id: datastore_item.value})
return datastore_item.value
return self.default_value
def set_value(self, committer_id, raw_value):
"""Sets the value of the property. In general, this should not be
called directly -- use config_services.set_property() instead.
"""
value = self.normalize(raw_value)
# Set value in datastore.
model_instance = config_models.ConfigPropertyModel.get(
self.name, strict=False)
if model_instance is None:
model_instance = config_models.ConfigPropertyModel(
id=self.name)
model_instance.value = value
model_instance.commit(committer_id, [{
'cmd': CMD_CHANGE_PROPERTY_VALUE,
'new_value': value
}])
# Set value in memcache.
memcache_services.set_multi({
model_instance.id: model_instance.value})
if self._post_set_hook is not None:
self._post_set_hook(committer_id, value)
def normalize(self, value):
return schema_utils.normalize_against_schema(value, self._schema)
class Registry(object):
"""Registry of all configuration properties."""
# The keys of _config_registry are the property names, and the values are
# ConfigProperty instances.
_config_registry = {}
@classmethod
def init_config_property(cls, name, instance):
cls._config_registry[name] = instance
@classmethod
def get_config_property(cls, name):
return cls._config_registry.get(name)
@classmethod
def get_config_property_schemas(cls):
"""Return a dict of editable config property schemas.
The keys of the dict are config property names. The values are dicts
with the following keys: schema, description, value.
"""
schemas_dict = {}
for (property_name, instance) in cls._config_registry.iteritems():
if instance.is_directly_settable:
schemas_dict[property_name] = {
'schema': instance.schema,
'description': instance.description,
'value': instance.value
}
return schemas_dict
def update_admin_ids(committer_id, admin_usernames):
"""Refresh the list of admin user_ids based on the usernames entered."""
admin_ids = []
for username in admin_usernames:
user_id = user_services.get_user_id_from_username(username)
if user_id is not None:
admin_ids.append(user_id)
else:
raise Exception('Bad admin username: %s' % username)
Registry.get_config_property('admin_ids').set_value(
committer_id, admin_ids)
def update_moderator_ids(committer_id, moderator_usernames):
"""Refresh the list of moderator user_ids based on the usernames
entered.
"""
moderator_ids = []
for username in moderator_usernames:
user_id = user_services.get_user_id_from_username(username)
if user_id is not None:
moderator_ids.append(user_id)
else:
raise Exception('Bad moderator username: %s' % username)
Registry.get_config_property('moderator_ids').set_value(
committer_id, moderator_ids)
ADMIN_IDS = ConfigProperty(
'admin_ids', SET_OF_STRINGS_SCHEMA, 'Admin ids', [],
is_directly_settable=False)
MODERATOR_IDS = ConfigProperty(
'moderator_ids', SET_OF_STRINGS_SCHEMA, 'Moderator ids', [],
is_directly_settable=False)
ADMIN_USERNAMES = ConfigProperty(
'admin_usernames', SET_OF_STRINGS_SCHEMA, 'Usernames of admins', [],
post_set_hook=update_admin_ids)
MODERATOR_USERNAMES = ConfigProperty(
'moderator_usernames', SET_OF_STRINGS_SCHEMA, 'Usernames of moderators',
[], post_set_hook=update_moderator_ids)
BANNED_USERNAMES = ConfigProperty(
'banned_usernames',
SET_OF_STRINGS_SCHEMA,
'Banned usernames (editing permissions for these users have been removed)',
[])
WHITELISTED_COLLECTION_EDITOR_USERNAMES = ConfigProperty(
'collection_editor_whitelist', SET_OF_STRINGS_SCHEMA,
'Names of users allowed to use the collection editor',
[])
WHITELISTED_EMAIL_SENDERS = ConfigProperty(
'whitelisted_email_senders', SET_OF_STRINGS_SCHEMA,
'Names of users allowed to send emails via the query interface.', [])
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
6927,
710,
593,
802,
4674,
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,
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,
13,
1311,
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,
7705,
2251,
367,
2897,
4382,
1041,
199,
199,
504,
6170,
14,
2261,
492,
922,
63,
5950,
199,
504,
6170,
14,
3246,
492,
1709,
199,
646,
4177,
63,
1208,
199,
199,
8,
888,
63,
992,
4258,
275,
1709,
14,
10899,
14,
646,
63,
992,
779,
992,
14,
14546,
14,
888,
566,
199,
25835,
63,
5950,
275,
1709,
14,
10899,
14,
646,
63,
25835,
63,
5950,
342,
199,
199,
9744,
63,
16062,
63,
25091,
63,
7041,
275,
283,
1461,
63,
1829,
63,
585,
7,
199,
199,
3597,
63,
3359,
63,
31271,
63,
10926,
275,
469,
272,
283,
466,
356,
283,
513,
297,
272,
283,
1744,
356,
469,
267,
283,
466,
356,
283,
2975,
297,
272,
1660,
272,
283,
11346,
356,
8910,
267,
283,
344,
356,
283,
374,
63,
5411,
783,
1290,
297,
272,
19971,
199,
93,
421,
199,
533,
4094,
3697,
8,
785,
304,
272,
408,
33,
3324,
543,
282,
536,
436,
282,
849,
574,
14,
339,
6944,
2296,
3265,
2524,
26515,
3960,
26,
5723,
1101,
4382,
787,
5906,
14,
4226,
440,
12598,
272,
3520,
1561,
26,
272,
446,
3595,
63,
1606,
63,
9788,
63,
3722,
63,
344,
272,
446,
4628,
63,
2123,
63,
1562,
272,
446,
2040,
63,
5963,
63,
493,
63,
5064,
272,
446,
20997,
63,
4478,
63,
505,
272,
446,
2544,
63,
500,
63,
2030,
63,
1450,
63,
3664,
272,
446,
9590,
810,
5891,
63,
23766,
3424,
63,
888,
272,
446,
8966,
63,
2123,
63,
1562,
272,
446,
28567,
63,
25372,
63,
1606,
63,
17803,
434,
272,
446,
6980,
63,
476,
1168,
269,
1298,
272,
446,
8823,
63,
1606,
63,
17803,
434,
272,
446,
8823,
63,
657,
30140,
63,
24128,
272,
446,
12169,
63,
3098,
63,
923,
63,
633,
272,
446,
2615,
63,
2124,
63,
633,
272,
446,
818,
9043,
63,
1069,
63,
10044,
63,
633,
272,
446,
26994,
63,
1419,
272,
446,
26994,
63,
1419,
63,
13746,
63,
505,
272,
446,
18437,
63,
4470,
63,
8460,
63,
4614,
272,
446,
4770,
63,
10044,
63,
633,
272,
446,
20295,
63,
4603,
63,
15687,
272,
446,
23168,
1119,
63,
1606,
63,
29028,
63,
344,
272,
446,
23168,
1119,
63,
1606,
63,
29028,
63,
1023,
272,
446,
23168,
1119,
63,
1606,
63,
9788,
63,
3722,
63,
344,
272,
408,
339,
347,
9236,
63,
885,
63,
585,
8,
277,
12,
849,
63,
585,
304,
267,
986,
339,
347,
636,
826,
721,
277,
12,
536,
12,
4177,
12,
1369,
12,
849,
63,
585,
12,
326,
2963,
63,
409,
63,
3664,
29,
403,
12,
365,
63,
2275,
590,
63,
409,
1224,
29,
549,
304,
267,
340,
20738,
14,
362,
63,
888,
63,
1829,
8,
354,
304,
288,
746,
2186,
360,
3697,
543,
536,
450,
83,
2575,
3495,
7,
450,
536,
9,
398,
291,
423,
354,
275,
536,
267,
291,
423,
3629,
275,
4177,
267,
291,
423,
1802,
275,
1369,
267,
291,
423,
885,
63,
585,
275,
4177,
63,
1208,
14,
7721,
63,
17777,
63,
3629,
8,
288,
849,
63,
585,
12,
291,
423,
3629,
9,
267,
291,
423,
1932,
63,
409,
63,
3664,
275,
2963,
63,
409,
63,
3664,
267,
291,
423,
374,
63,
2275,
590,
63,
409,
1224,
275,
365,
63,
2275,
590,
63,
409,
1224,
398,
20738,
14,
826,
63,
888,
63,
1829,
8,
277,
14,
354,
12,
291,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
4177,
8,
277,
304,
267,
372,
291,
423,
3629,
339,
768,
1829,
272,
347,
1369,
8,
277,
304,
267,
372,
291,
423,
1802,
339,
768,
1829,
272,
347,
849,
63,
585,
8,
277,
304,
267,
372,
291,
423,
885,
63,
585,
339,
768,
1829,
272,
347,
365,
63,
2275,
590,
63,
409,
1224,
8,
277,
304,
267,
372,
291,
423,
374,
63,
2275,
590,
63,
409,
1224,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
408,
1002,
314,
8839,
574,
687,
21598,
12,
12007,
12,
503,
675,
849,
1041,
398,
7573,
5245,
63,
1744,
275,
21598,
63,
5950,
14,
362,
63,
3029,
779,
277,
14,
354,
566,
267,
340,
291,
14,
354,
315,
7573,
5245,
63,
1744,
26,
288,
372,
7573,
5245,
63,
1744,
59,
277,
14,
354,
61,
398,
12007,
63,
1053,
275,
1101,
63,
992,
14,
2028,
3697,
1685,
14,
362,
8,
288,
291,
14,
354,
12,
7478,
29,
797,
9,
267,
340,
12007,
63,
1053,
365,
440,
488,
26,
288,
21598,
63,
5950,
14,
409,
63,
3029,
2561,
355,
12007,
63,
1053,
14,
344,
26,
12007,
63,
1053,
14,
585,
1552,
288,
372,
12007,
63,
1053,
14,
585,
398,
372,
291,
14,
885,
63,
585,
339,
347,
663,
63,
585,
8,
277,
12,
5532,
351,
63,
344,
12,
3066,
63,
585,
304,
267,
408,
9899,
314,
574,
402,
314,
3324,
14,
1010,
8605,
12,
642,
1077,
440,
506,
267,
2797,
5370,
1553,
675,
1101,
63,
5950,
14,
409,
63,
1829,
342,
3140,
14,
267,
408,
267,
574,
275,
291,
14,
7721,
8,
1773,
63,
585,
9,
398,
327,
2494,
574,
315,
12007,
14,
267,
1402,
63,
842,
275,
1101,
63,
992,
14,
2028,
3697,
1685,
14,
362,
8,
288,
291,
14,
354,
12,
7478,
29,
797,
9,
267,
340,
1402,
63,
842,
365,
488,
26,
288,
1402,
63,
842,
275,
1101,
63,
992,
14,
2028
] |
[
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
6927,
710,
593,
802,
4674,
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,
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,
13,
1311,
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,
7705,
2251,
367,
2897,
4382,
1041,
199,
199,
504,
6170,
14,
2261,
492,
922,
63,
5950,
199,
504,
6170,
14,
3246,
492,
1709,
199,
646,
4177,
63,
1208,
199,
199,
8,
888,
63,
992,
4258,
275,
1709,
14,
10899,
14,
646,
63,
992,
779,
992,
14,
14546,
14,
888,
566,
199,
25835,
63,
5950,
275,
1709,
14,
10899,
14,
646,
63,
25835,
63,
5950,
342,
199,
199,
9744,
63,
16062,
63,
25091,
63,
7041,
275,
283,
1461,
63,
1829,
63,
585,
7,
199,
199,
3597,
63,
3359,
63,
31271,
63,
10926,
275,
469,
272,
283,
466,
356,
283,
513,
297,
272,
283,
1744,
356,
469,
267,
283,
466,
356,
283,
2975,
297,
272,
1660,
272,
283,
11346,
356,
8910,
267,
283,
344,
356,
283,
374,
63,
5411,
783,
1290,
297,
272,
19971,
199,
93,
421,
199,
533,
4094,
3697,
8,
785,
304,
272,
408,
33,
3324,
543,
282,
536,
436,
282,
849,
574,
14,
339,
6944,
2296,
3265,
2524,
26515,
3960,
26,
5723,
1101,
4382,
787,
5906,
14,
4226,
440,
12598,
272,
3520,
1561,
26,
272,
446,
3595,
63,
1606,
63,
9788,
63,
3722,
63,
344,
272,
446,
4628,
63,
2123,
63,
1562,
272,
446,
2040,
63,
5963,
63,
493,
63,
5064,
272,
446,
20997,
63,
4478,
63,
505,
272,
446,
2544,
63,
500,
63,
2030,
63,
1450,
63,
3664,
272,
446,
9590,
810,
5891,
63,
23766,
3424,
63,
888,
272,
446,
8966,
63,
2123,
63,
1562,
272,
446,
28567,
63,
25372,
63,
1606,
63,
17803,
434,
272,
446,
6980,
63,
476,
1168,
269,
1298,
272,
446,
8823,
63,
1606,
63,
17803,
434,
272,
446,
8823,
63,
657,
30140,
63,
24128,
272,
446,
12169,
63,
3098,
63,
923,
63,
633,
272,
446,
2615,
63,
2124,
63,
633,
272,
446,
818,
9043,
63,
1069,
63,
10044,
63,
633,
272,
446,
26994,
63,
1419,
272,
446,
26994,
63,
1419,
63,
13746,
63,
505,
272,
446,
18437,
63,
4470,
63,
8460,
63,
4614,
272,
446,
4770,
63,
10044,
63,
633,
272,
446,
20295,
63,
4603,
63,
15687,
272,
446,
23168,
1119,
63,
1606,
63,
29028,
63,
344,
272,
446,
23168,
1119,
63,
1606,
63,
29028,
63,
1023,
272,
446,
23168,
1119,
63,
1606,
63,
9788,
63,
3722,
63,
344,
272,
408,
339,
347,
9236,
63,
885,
63,
585,
8,
277,
12,
849,
63,
585,
304,
267,
986,
339,
347,
636,
826,
721,
277,
12,
536,
12,
4177,
12,
1369,
12,
849,
63,
585,
12,
326,
2963,
63,
409,
63,
3664,
29,
403,
12,
365,
63,
2275,
590,
63,
409,
1224,
29,
549,
304,
267,
340,
20738,
14,
362,
63,
888,
63,
1829,
8,
354,
304,
288,
746,
2186,
360,
3697,
543,
536,
450,
83,
2575,
3495,
7,
450,
536,
9,
398,
291,
423,
354,
275,
536,
267,
291,
423,
3629,
275,
4177,
267,
291,
423,
1802,
275,
1369,
267,
291,
423,
885,
63,
585,
275,
4177,
63,
1208,
14,
7721,
63,
17777,
63,
3629,
8,
288,
849,
63,
585,
12,
291,
423,
3629,
9,
267,
291,
423,
1932,
63,
409,
63,
3664,
275,
2963,
63,
409,
63,
3664,
267,
291,
423,
374,
63,
2275,
590,
63,
409,
1224,
275,
365,
63,
2275,
590,
63,
409,
1224,
398,
20738,
14,
826,
63,
888,
63,
1829,
8,
277,
14,
354,
12,
291,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
4177,
8,
277,
304,
267,
372,
291,
423,
3629,
339,
768,
1829,
272,
347,
1369,
8,
277,
304,
267,
372,
291,
423,
1802,
339,
768,
1829,
272,
347,
849,
63,
585,
8,
277,
304,
267,
372,
291,
423,
885,
63,
585,
339,
768,
1829,
272,
347,
365,
63,
2275,
590,
63,
409,
1224,
8,
277,
304,
267,
372,
291,
423,
374,
63,
2275,
590,
63,
409,
1224,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
408,
1002,
314,
8839,
574,
687,
21598,
12,
12007,
12,
503,
675,
849,
1041,
398,
7573,
5245,
63,
1744,
275,
21598,
63,
5950,
14,
362,
63,
3029,
779,
277,
14,
354,
566,
267,
340,
291,
14,
354,
315,
7573,
5245,
63,
1744,
26,
288,
372,
7573,
5245,
63,
1744,
59,
277,
14,
354,
61,
398,
12007,
63,
1053,
275,
1101,
63,
992,
14,
2028,
3697,
1685,
14,
362,
8,
288,
291,
14,
354,
12,
7478,
29,
797,
9,
267,
340,
12007,
63,
1053,
365,
440,
488,
26,
288,
21598,
63,
5950,
14,
409,
63,
3029,
2561,
355,
12007,
63,
1053,
14,
344,
26,
12007,
63,
1053,
14,
585,
1552,
288,
372,
12007,
63,
1053,
14,
585,
398,
372,
291,
14,
885,
63,
585,
339,
347,
663,
63,
585,
8,
277,
12,
5532,
351,
63,
344,
12,
3066,
63,
585,
304,
267,
408,
9899,
314,
574,
402,
314,
3324,
14,
1010,
8605,
12,
642,
1077,
440,
506,
267,
2797,
5370,
1553,
675,
1101,
63,
5950,
14,
409,
63,
1829,
342,
3140,
14,
267,
408,
267,
574,
275,
291,
14,
7721,
8,
1773,
63,
585,
9,
398,
327,
2494,
574,
315,
12007,
14,
267,
1402,
63,
842,
275,
1101,
63,
992,
14,
2028,
3697,
1685,
14,
362,
8,
288,
291,
14,
354,
12,
7478,
29,
797,
9,
267,
340,
1402,
63,
842,
365,
488,
26,
288,
1402,
63,
842,
275,
1101,
63,
992,
14,
2028,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
alikins/ansible
|
lib/ansible/modules/storage/netapp/sf_check_connections.py
|
49
|
5271
|
#!/usr/bin/python
# (c) 2017, NetApp, Inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
module: sf_check_connections
short_description: Check connectivity to MVIP and SVIP.
extends_documentation_fragment:
- netapp.solidfire
version_added: '2.3'
author: Sumit Kumar (sumit4@netapp.com)
description:
- Used to test the management connection to the cluster.
- The test pings the MVIP and SVIP, and executes a simple API method to verify connectivity.
options:
skip:
description:
- Skip checking connection to SVIP or MVIP.
required: false
choices: ['svip', 'mvip']
default: None
mvip:
description:
- Optionally, use to test connection of a different MVIP.
- This is not needed to test the connection to the target cluster.
required: false
default: None
svip:
description:
- Optionally, use to test connection of a different SVIP.
- This is not needed to test the connection to the target cluster.
required: false
default: None
'''
EXAMPLES = """
- name: Check connections to MVIP and SVIP
sf_check_connections:
hostname: "{{ solidfire_hostname }}"
username: "{{ solidfire_username }}"
password: "{{ solidfire_password }}"
"""
RETURN = """
"""
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
HAS_SF_SDK = netapp_utils.has_sf_sdk()
class SolidFireConnection(object):
def __init__(self):
self.argument_spec = netapp_utils.ontap_sf_host_argument_spec()
self.argument_spec.update(dict(
skip=dict(required=False, type='str', default=None, choices=['mvip', 'svip']),
mvip=dict(required=False, type='str', default=None),
svip=dict(required=False, type='str', default=None)
))
self.module = AnsibleModule(
argument_spec=self.argument_spec,
supports_check_mode=True
)
p = self.module.params
# set up state variables
self.skip = p['skip']
self.mvip = p['mvip']
self.svip = p['svip']
if HAS_SF_SDK is False:
self.module.fail_json(msg="Unable to import the SolidFire Python SDK")
else:
self.sfe = netapp_utils.ElementFactory.create(p['hostname'], p['username'], p['password'], port=442)
def check_mvip_connection(self):
"""
Check connection to MVIP
:return: true if connection was successful, false otherwise.
:rtype: bool
"""
try:
test = self.sfe.test_connect_mvip(mvip=self.mvip)
result = test.details.connected
# Todo - Log details about the test
return result
except Exception as e:
self.module.fail_json(msg='Error checking connection to MVIP: %s' % to_native(e), exception=traceback.format_exc())
return False
def check_svip_connection(self):
"""
Check connection to SVIP
:return: true if connection was successful, false otherwise.
:rtype: bool
"""
try:
test = self.sfe.test_connect_svip(svip=self.svip)
result = test.details.connected
# Todo - Log details about the test
return result
except Exception as e:
self.module.fail_json(msg='Error checking connection to SVIP: %s' % to_native(e), exception=traceback.format_exc())
return False
def check(self):
failed = True
msg = ''
if self.skip is None:
mvip_connection_established = self.check_mvip_connection()
svip_connection_established = self.check_svip_connection()
# Set failed and msg
if not mvip_connection_established:
failed = True
msg = 'Connection to MVIP failed.'
elif not svip_connection_established:
failed = True
msg = 'Connection to SVIP failed.'
else:
failed = False
elif self.skip == 'mvip':
svip_connection_established = self.check_svip_connection()
# Set failed and msg
if not svip_connection_established:
failed = True
msg = 'Connection to SVIP failed.'
else:
failed = False
elif self.skip == 'svip':
mvip_connection_established = self.check_mvip_connection()
# Set failed and msg
if not mvip_connection_established:
failed = True
msg = 'Connection to MVIP failed.'
else:
failed = False
if failed:
self.module.fail_json(msg=msg)
else:
self.module.exit_json()
def main():
v = SolidFireConnection()
v.check()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
9708,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
199,
578,
26,
13330,
63,
1074,
63,
7995,
199,
199,
3612,
63,
1802,
26,
2670,
20170,
370,
603,
54,
1772,
436,
14056,
1772,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
15742,
14,
18533,
8935,
199,
1023,
63,
3270,
26,
283,
18,
14,
19,
7,
199,
2502,
26,
12094,
390,
1804,
453,
285,
334,
1838,
390,
20,
32,
25830,
14,
957,
9,
199,
1802,
26,
199,
13,
8051,
370,
511,
314,
10041,
1950,
370,
314,
4350,
14,
199,
13,
710,
511,
299,
780,
314,
603,
54,
1772,
436,
14056,
1772,
12,
436,
24956,
282,
3486,
3261,
1083,
370,
4911,
20170,
14,
199,
199,
1419,
26,
819,
3372,
26,
272,
1369,
26,
272,
446,
8232,
7907,
1950,
370,
14056,
1772,
503,
603,
54,
1772,
14,
272,
1415,
26,
3055,
272,
3415,
26,
788,
83,
18607,
297,
283,
77,
18607,
418,
272,
849,
26,
488,
819,
333,
18607,
26,
272,
1369,
26,
272,
446,
22383,
12,
675,
370,
511,
1950,
402,
282,
3365,
603,
54,
1772,
14,
272,
446,
961,
365,
440,
4346,
370,
511,
314,
1950,
370,
314,
1347,
4350,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
819,
308,
18607,
26,
272,
1369,
26,
272,
446,
22383,
12,
675,
370,
511,
1950,
402,
282,
3365,
14056,
1772,
14,
272,
446,
961,
365,
440,
4346,
370,
511,
314,
1950,
370,
314,
1347,
4350,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
199,
199,
2344,
421,
199,
8918,
275,
408,
2043,
446,
536,
26,
2670,
6947,
370,
603,
54,
1772,
436,
14056,
1772,
1362,
13330,
63,
1074,
63,
7995,
26,
2126,
6246,
26,
7370,
18609,
8935,
63,
4269,
7820,
2126,
3434,
26,
7370,
18609,
8935,
63,
2473,
7820,
2126,
2505,
26,
7370,
18609,
8935,
63,
2060,
7820,
199,
624,
199,
199,
9677,
275,
408,
199,
199,
624,
199,
646,
5190,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
646,
3242,
14,
578,
63,
1208,
14,
25830,
465,
15742,
63,
1208,
421,
199,
13533,
63,
13107,
63,
14939,
275,
15742,
63,
1208,
14,
1989,
63,
7646,
63,
9277,
342,
421,
199,
533,
2002,
7401,
13081,
3225,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2094,
63,
1650,
275,
15742,
63,
1208,
14,
1888,
439,
63,
7646,
63,
1102,
63,
2094,
63,
1650,
342,
267,
291,
14,
2094,
63,
1650,
14,
873,
8,
807,
8,
288,
3372,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
297,
849,
29,
403,
12,
3415,
2968,
77,
18607,
297,
283,
83,
18607,
3815,
288,
333,
18607,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
297,
849,
29,
403,
395,
288,
308,
18607,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
297,
849,
29,
403,
9,
267,
5082,
398,
291,
14,
578,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
549,
267,
776,
398,
299,
275,
291,
14,
578,
14,
1162,
398,
327,
663,
1536,
1174,
2860,
267,
291,
14,
2759,
275,
299,
459,
2759,
418,
267,
291,
14,
77,
18607,
275,
299,
459,
77,
18607,
418,
267,
291,
14,
83,
18607,
275,
299,
459,
83,
18607,
418,
398,
340,
7509,
63,
13107,
63,
14939,
365,
756,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
628,
6005,
370,
492,
314,
2002,
7401,
13081,
2018,
15610,
531,
267,
587,
26,
288,
291,
14,
83,
771,
275,
15742,
63,
1208,
14,
2162,
2927,
14,
981,
8,
80,
459,
4269,
995,
299,
459,
2473,
995,
299,
459,
2060,
995,
1844,
29,
24338,
9,
339,
347,
1104,
63,
77,
18607,
63,
2105,
8,
277,
304,
267,
408,
288,
2670,
1950,
370,
603,
54,
1772,
953,
520,
1107,
26,
2549,
340,
1950,
1990,
9512,
12,
3055,
4257,
14,
288,
520,
4500,
26,
2155,
267,
408,
267,
862,
26,
288,
511,
275,
291,
14,
83,
771,
14,
396,
63,
2242,
63,
77,
18607,
8,
77,
18607,
29,
277,
14,
77,
18607,
9,
288,
754,
275,
511,
14,
5087,
14,
7113,
288,
327,
377,
19657,
446,
5297,
2436,
3595,
314,
511,
288,
372,
754,
398,
871,
2186,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
534,
547,
7907,
1950,
370,
603,
54,
1772,
26,
450,
83,
7,
450,
370,
63,
6106,
8,
69,
395,
1919,
29,
6894,
14,
908,
63,
2804,
1012,
288,
372,
756,
339,
347,
1104,
63,
83,
18607,
63,
2105,
8,
277,
304,
267,
408,
288,
2670,
1950,
370,
14056,
1772,
953,
520,
1107,
26,
2549,
340,
1950,
1990,
9512,
12,
3055,
4257,
14,
288,
520,
4500,
26,
2155,
267,
408,
267,
862,
26,
288,
511,
275,
291,
14,
83,
771,
14,
396,
63,
2242,
63,
83,
18607,
8,
83,
18607,
29,
277,
14,
83,
18607,
9,
288,
754,
275,
511,
14,
5087,
14,
7113,
288,
327,
377,
19657,
446,
5297,
2436,
3595,
314,
511,
288,
372,
754,
398,
871,
2186,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
534,
547,
7907,
1950,
370,
14056,
1772,
26,
450,
83,
7,
450,
370,
63,
6106,
8,
69,
395,
1919,
29,
6894,
14,
908,
63,
2804,
1012,
288,
372,
756,
339,
347,
1104,
8,
277,
304,
398,
3405,
275,
715,
267,
1499,
275,
2125,
398,
340,
291,
14,
2759,
365,
488,
26,
288,
333,
18607,
63,
2105,
63,
597,
13306,
379,
275,
291,
14,
1074,
63,
77,
18607,
63,
2105
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
334,
67,
9,
9708,
12,
28076,
12,
3277,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
199,
578,
26,
13330,
63,
1074,
63,
7995,
199,
199,
3612,
63,
1802,
26,
2670,
20170,
370,
603,
54,
1772,
436,
14056,
1772,
14,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
15742,
14,
18533,
8935,
199,
1023,
63,
3270,
26,
283,
18,
14,
19,
7,
199,
2502,
26,
12094,
390,
1804,
453,
285,
334,
1838,
390,
20,
32,
25830,
14,
957,
9,
199,
1802,
26,
199,
13,
8051,
370,
511,
314,
10041,
1950,
370,
314,
4350,
14,
199,
13,
710,
511,
299,
780,
314,
603,
54,
1772,
436,
14056,
1772,
12,
436,
24956,
282,
3486,
3261,
1083,
370,
4911,
20170,
14,
199,
199,
1419,
26,
819,
3372,
26,
272,
1369,
26,
272,
446,
8232,
7907,
1950,
370,
14056,
1772,
503,
603,
54,
1772,
14,
272,
1415,
26,
3055,
272,
3415,
26,
788,
83,
18607,
297,
283,
77,
18607,
418,
272,
849,
26,
488,
819,
333,
18607,
26,
272,
1369,
26,
272,
446,
22383,
12,
675,
370,
511,
1950,
402,
282,
3365,
603,
54,
1772,
14,
272,
446,
961,
365,
440,
4346,
370,
511,
314,
1950,
370,
314,
1347,
4350,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
819,
308,
18607,
26,
272,
1369,
26,
272,
446,
22383,
12,
675,
370,
511,
1950,
402,
282,
3365,
14056,
1772,
14,
272,
446,
961,
365,
440,
4346,
370,
511,
314,
1950,
370,
314,
1347,
4350,
14,
272,
1415,
26,
3055,
272,
849,
26,
488,
199,
199,
2344,
421,
199,
8918,
275,
408,
2043,
446,
536,
26,
2670,
6947,
370,
603,
54,
1772,
436,
14056,
1772,
1362,
13330,
63,
1074,
63,
7995,
26,
2126,
6246,
26,
7370,
18609,
8935,
63,
4269,
7820,
2126,
3434,
26,
7370,
18609,
8935,
63,
2473,
7820,
2126,
2505,
26,
7370,
18609,
8935,
63,
2060,
7820,
199,
624,
199,
199,
9677,
275,
408,
199,
199,
624,
199,
646,
5190,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
199,
646,
3242,
14,
578,
63,
1208,
14,
25830,
465,
15742,
63,
1208,
421,
199,
13533,
63,
13107,
63,
14939,
275,
15742,
63,
1208,
14,
1989,
63,
7646,
63,
9277,
342,
421,
199,
533,
2002,
7401,
13081,
3225,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2094,
63,
1650,
275,
15742,
63,
1208,
14,
1888,
439,
63,
7646,
63,
1102,
63,
2094,
63,
1650,
342,
267,
291,
14,
2094,
63,
1650,
14,
873,
8,
807,
8,
288,
3372,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
297,
849,
29,
403,
12,
3415,
2968,
77,
18607,
297,
283,
83,
18607,
3815,
288,
333,
18607,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
297,
849,
29,
403,
395,
288,
308,
18607,
29,
807,
8,
2427,
29,
797,
12,
730,
534,
495,
297,
849,
29,
403,
9,
267,
5082,
398,
291,
14,
578,
275,
6953,
8,
288,
1423,
63,
1650,
29,
277,
14,
2094,
63,
1650,
12,
288,
5171,
63,
1074,
63,
632,
29,
549,
267,
776,
398,
299,
275,
291,
14,
578,
14,
1162,
398,
327,
663,
1536,
1174,
2860,
267,
291,
14,
2759,
275,
299,
459,
2759,
418,
267,
291,
14,
77,
18607,
275,
299,
459,
77,
18607,
418,
267,
291,
14,
83,
18607,
275,
299,
459,
83,
18607,
418,
398,
340,
7509,
63,
13107,
63,
14939,
365,
756,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
628,
6005,
370,
492,
314,
2002,
7401,
13081,
2018,
15610,
531,
267,
587,
26,
288,
291,
14,
83,
771,
275,
15742,
63,
1208,
14,
2162,
2927,
14,
981,
8,
80,
459,
4269,
995,
299,
459,
2473,
995,
299,
459,
2060,
995,
1844,
29,
24338,
9,
339,
347,
1104,
63,
77,
18607,
63,
2105,
8,
277,
304,
267,
408,
288,
2670,
1950,
370,
603,
54,
1772,
953,
520,
1107,
26,
2549,
340,
1950,
1990,
9512,
12,
3055,
4257,
14,
288,
520,
4500,
26,
2155,
267,
408,
267,
862,
26,
288,
511,
275,
291,
14,
83,
771,
14,
396,
63,
2242,
63,
77,
18607,
8,
77,
18607,
29,
277,
14,
77,
18607,
9,
288,
754,
275,
511,
14,
5087,
14,
7113,
288,
327,
377,
19657,
446,
5297,
2436,
3595,
314,
511,
288,
372,
754,
398,
871,
2186,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
534,
547,
7907,
1950,
370,
603,
54,
1772,
26,
450,
83,
7,
450,
370,
63,
6106,
8,
69,
395,
1919,
29,
6894,
14,
908,
63,
2804,
1012,
288,
372,
756,
339,
347,
1104,
63,
83,
18607,
63,
2105,
8,
277,
304,
267,
408,
288,
2670,
1950,
370,
14056,
1772,
953,
520,
1107,
26,
2549,
340,
1950,
1990,
9512,
12,
3055,
4257,
14,
288,
520,
4500,
26,
2155,
267,
408,
267,
862,
26,
288,
511,
275,
291,
14,
83,
771,
14,
396,
63,
2242,
63,
83,
18607,
8,
83,
18607,
29,
277,
14,
83,
18607,
9,
288,
754,
275,
511,
14,
5087,
14,
7113,
288,
327,
377,
19657,
446,
5297,
2436,
3595,
314,
511,
288,
372,
754,
398,
871,
2186,
465,
325,
26,
288,
291,
14,
578,
14,
1633,
63,
1001,
8,
1328,
534,
547,
7907,
1950,
370,
14056,
1772,
26,
450,
83,
7,
450,
370,
63,
6106,
8,
69,
395,
1919,
29,
6894,
14,
908,
63,
2804,
1012,
288,
372,
756,
339,
347,
1104,
8,
277,
304,
398,
3405,
275,
715,
267,
1499,
275,
2125,
398,
340,
291,
14,
2759,
365,
488,
26,
288,
333,
18607,
63,
2105,
63,
597,
13306,
379,
275,
291,
14,
1074,
63,
77,
18607,
63,
2105,
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
] |
augmify/omim
|
tools/python/stylesheet/webcolors/webcolors.py
|
53
|
28314
|
# -*- coding: utf-8 -*-
"""
A simple library for working with the color names and color codes
defined by the HTML and CSS specifications.
An overview of HTML and CSS colors
----------------------------------
Colors on the Web are specified in `the sRGB color space`_, where each
color is made up of a red component, a green component and a blue
component. This is useful because it maps (fairly) cleanly to the red,
green and blue components of pixels on a computer display, and to the
cone cells of a human eye, which come in three sets roughly
corresponding to the wavelengths of light associated with red, green
and blue.
`The HTML 4 standard`_ defines two ways to specify sRGB colors:
* A hash mark ('#') followed by three pairs of hexdecimal digits,
specifying values for red, green and blue components in that order;
for example, ``#0099cc``. Since each pair of hexadecimal digits can
express 256 different values, this allows up to 256**3 or 16,777,216
unique colors to be specified (though, due to differences in display
technology, not all of these colors may be clearly distinguished on
any given physical display).
* A set of predefined color names which correspond to specific
hexadecimal values; for example, ``white``. HTML 4 defines sixteen
such colors.
`The CSS 2 standard`_ allows any valid HTML 4 color specification, and
adds three new ways to specify sRGB colors:
* A hash mark followed by three hexadecimal digits, which is expanded
into three hexadecimal pairs by repeating each digit; thus ``#09c``
is equivalent to ``#0099cc``.
* The string 'rgb', followed by parentheses, between which are three
numeric values each between 0 and 255, inclusive, which are taken to
be the values of the red, green and blue components in that order;
for example, ``rgb(0, 153, 204)``.
* The same as above, except using percentages instead of numeric
values; for example, ``rgb(0%, 60%, 80%)``.
`The CSS 2.1 revision`_ does not add any new methods of specifying
sRGB colors, but does add one additional named color.
`The CSS 3 color module`_ (currently a W3C Candidate Recommendation)
adds one new way to specify sRGB colors:
* A hue-saturation-lightness triple (HSL), using the construct
``hsl()``.
It also adds support for variable opacity of colors, by allowing the
specification of alpha-channel information, through the ``rgba()`` and
``hsla()`` constructs, which are identical to ``rgb()`` and ``hsl()``
with one exception: a fourth value is supplied, indicating the level
of opacity from ``0.0`` (completely transparent) to ``1.0``
(completely opaque). Though not technically a color, the keyword
``transparent`` is also made available in lieu of a color value, and
corresponds to ``rgba(0,0,0,0)``.
Additionally, CSS3 defines a new set of color names; this set is taken
directly from the named colors defined for SVG (Scalable Vector
Graphics) markup, and is a proper superset of the named colors defined
in CSS 2.1. This set also has significant overlap with traditional X11
color sets as defined by the ``rgb.txt`` file on many Unix and
Unix-like operating systems, though the correspondence is not exact;
the set of X11 colors is not standardized, and the set of CSS3 colors
contains some definitions which diverge significantly from customary
X11 definitions (for example, CSS3's ``green`` is not equivalent to
X11's ``green``; the value which X11 designates ``green`` is
designated ``lime`` in CSS3).
.. _the sRGB color space: http://www.w3.org/Graphics/Color/sRGB
.. _The HTML 4 standard: http://www.w3.org/TR/html401/types.html#h-6.5
.. _The CSS 2 standard: http://www.w3.org/TR/REC-CSS2/syndata.html#value-def-color
.. _The CSS 2.1 revision: http://www.w3.org/TR/CSS21/
.. _The CSS 3 color module: http://www.w3.org/TR/css3-color/
What this module supports
-------------------------
The mappings and functions within this module support the following
methods of specifying sRGB colors, and conversions between them:
* Six-digit hexadecimal.
* Three-digit hexadecimal.
* Integer ``rgb()`` triplet.
* Percentage ``rgb()`` triplet.
* Varying selections of predefined color names (see below).
This module does not support ``hsl()`` triplets, nor does it support
opacity/alpha-channel information via ``rgba()`` or ``hsla()``.
If you need to convert between RGB-specified colors and HSL-specified
colors, or colors specified via other means, consult `the colorsys
module`_ in the Python standard library, which can perform conversions
amongst several common color spaces.
.. _the colorsys module: http://docs.python.org/library/colorsys.html
Normalization
-------------
For colors specified via hexadecimal values, this module will accept
input in the following formats:
* A hash mark (#) followed by three hexadecimal digits, where letters
may be upper- or lower-case.
* A hash mark (#) followed by six hexadecimal digits, where letters
may be upper- or lower-case.
For output which consists of a color specified via hexadecimal values,
and for functions which perform intermediate conversion to hexadecimal
before returning a result in another format, this module always
normalizes such values to the following format:
* A hash mark (#) followed by six hexadecimal digits, with letters
forced to lower-case.
The function ``normalize_hex()`` in this module can be used to perform
this normalization manually if desired; see its documentation for an
explanation of the normalization process.
For colors specified via predefined names, this module will accept
input in the following formats:
* An entirely lower-case name, such as ``aliceblue``.
* A name using initial capitals, such as ``AliceBlue``.
For output which consists of a color specified via a predefined name,
and for functions which perform intermediate conversion to a
predefined name before returning a result in another format, this
module always normalizes such values to be entirely lower-case.
Mappings of color names
-----------------------
For each set of defined color names -- HTML 4, CSS 2, CSS 2.1 and CSS
3 -- this module exports two mappings: one of normalized color names
to normalized hexadecimal values, and one of normalized hexadecimal
values to normalized color names. These eight mappings are as follows:
``html4_names_to_hex``
Mapping of normalized HTML 4 color names to normalized hexadecimal
values.
``html4_hex_to_names``
Mapping of normalized hexadecimal values to normalized HTML 4
color names.
``css2_names_to_hex``
Mapping of normalized CSS 2 color names to normalized hexadecimal
values. Because CSS 2 defines the same set of named colors as HTML
4, this is merely an alias for ``html4_names_to_hex``.
``css2_hex_to_names``
Mapping of normalized hexadecimal values to normalized CSS 2 color
nams. For the reasons described above, this is merely an alias for
``html4_hex_to_names``.
``css21_names_to_hex``
Mapping of normalized CSS 2.1 color names to normalized
hexadecimal values. This is identical to ``html4_names_to_hex``,
except for one addition: ``orange``.
``css21_hex_to_names``
Mapping of normalized hexadecimal values to normalized CSS 2.1
color names. As above, this is identical to ``html4_hex_to_names``
except for the addition of ``orange``.
``css3_names_to_hex``
Mapping of normalized CSS3 color names to normalized hexadecimal
values.
``css3_hex_to_names``
Mapping of normalized hexadecimal values to normalized CSS3 color
names.
"""
import math
import re
from hashlib import md5
def _reversedict(d):
"""
Internal helper for generating reverse mappings; given a
dictionary, returns a new dictionary with keys and values swapped.
"""
return dict(zip(d.values(), d.keys()))
HEX_COLOR_RE = re.compile(r'^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$')
SUPPORTED_SPECIFICATIONS = ('html4', 'css2', 'css21', 'css3')
######################################################################
# Mappings of color names to normalized hexadecimal color values.
######################################################################
html4_names_to_hex = {
'aqua': '#00ffff',
'black': '#000000',
'blue': '#0000ff',
'fuchsia': '#ff00ff',
'green': '#008000',
'grey': '#808080',
'lime': '#00ff00',
'maroon': '#800000',
'navy': '#000080',
'olive': '#808000',
'purple': '#800080',
'red': '#ff0000',
'silver': '#c0c0c0',
'teal': '#008080',
'white': '#ffffff',
'yellow': '#ffff00'
}
css2_names_to_hex = html4_names_to_hex
css21_names_to_hex = dict(html4_names_to_hex, orange='#ffa500')
css3_names_to_hex = {
'aliceblue': '#f0f8ff',
'antiquewhite': '#faebd7',
'aqua': '#00ffff',
'aquamarine': '#7fffd4',
'azure': '#f0ffff',
'beige': '#f5f5dc',
'bisque': '#ffe4c4',
'black': '#000000',
'blanchedalmond': '#ffebcd',
'blue': '#0000ff',
'blueviolet': '#8a2be2',
'brown': '#a52a2a',
'burlywood': '#deb887',
'cadetblue': '#5f9ea0',
'chartreuse': '#7fff00',
'chocolate': '#d2691e',
'coral': '#ff7f50',
'cornflowerblue': '#6495ed',
'cornsilk': '#fff8dc',
'crimson': '#dc143c',
'cyan': '#00ffff',
'darkblue': '#00008b',
'darkcyan': '#008b8b',
'darkgoldenrod': '#b8860b',
'darkgray': '#a9a9a9',
'darkgrey': '#a9a9a9',
'darkgreen': '#006400',
'darkkhaki': '#bdb76b',
'darkmagenta': '#8b008b',
'darkolivegreen': '#556b2f',
'darkorange': '#ff8c00',
'darkorchid': '#9932cc',
'darkred': '#8b0000',
'darksalmon': '#e9967a',
'darkseagreen': '#8fbc8f',
'darkslateblue': '#483d8b',
'darkslategray': '#2f4f4f',
'darkslategrey': '#2f4f4f',
'darkturquoise': '#00ced1',
'darkviolet': '#9400d3',
'deeppink': '#ff1493',
'deepskyblue': '#00bfff',
'dimgray': '#696969',
'dimgrey': '#696969',
'dodgerblue': '#1e90ff',
'firebrick': '#b22222',
'floralwhite': '#fffaf0',
'forestgreen': '#228b22',
'fuchsia': '#ff00ff',
'gainsboro': '#dcdcdc',
'ghostwhite': '#f8f8ff',
'gold': '#ffd700',
'goldenrod': '#daa520',
'gray': '#808080',
'grey': '#808080',
'green': '#008000',
'greenyellow': '#adff2f',
'honeydew': '#f0fff0',
'hotpink': '#ff69b4',
'indianred': '#cd5c5c',
'indigo': '#4b0082',
'ivory': '#fffff0',
'khaki': '#f0e68c',
'lavender': '#e6e6fa',
'lavenderblush': '#fff0f5',
'lawngreen': '#7cfc00',
'lemonchiffon': '#fffacd',
'lightblue': '#add8e6',
'lightcoral': '#f08080',
'lightcyan': '#e0ffff',
'lightgoldenrodyellow': '#fafad2',
'lightgray': '#d3d3d3',
'lightgrey': '#d3d3d3',
'lightgreen': '#90ee90',
'lightpink': '#ffb6c1',
'lightsalmon': '#ffa07a',
'lightseagreen': '#20b2aa',
'lightskyblue': '#87cefa',
'lightslategray': '#778899',
'lightslategrey': '#778899',
'lightsteelblue': '#b0c4de',
'lightyellow': '#ffffe0',
'lime': '#00ff00',
'limegreen': '#32cd32',
'linen': '#faf0e6',
'magenta': '#ff00ff',
'maroon': '#800000',
'mediumaquamarine': '#66cdaa',
'mediumblue': '#0000cd',
'mediumorchid': '#ba55d3',
'mediumpurple': '#9370d8',
'mediumseagreen': '#3cb371',
'mediumslateblue': '#7b68ee',
'mediumspringgreen': '#00fa9a',
'mediumturquoise': '#48d1cc',
'mediumvioletred': '#c71585',
'midnightblue': '#191970',
'mintcream': '#f5fffa',
'mistyrose': '#ffe4e1',
'moccasin': '#ffe4b5',
'navajowhite': '#ffdead',
'navy': '#000080',
'oldlace': '#fdf5e6',
'olive': '#808000',
'olivedrab': '#6b8e23',
'orange': '#ffa500',
'orangered': '#ff4500',
'orchid': '#da70d6',
'palegoldenrod': '#eee8aa',
'palegreen': '#98fb98',
'paleturquoise': '#afeeee',
'palevioletred': '#d87093',
'papayawhip': '#ffefd5',
'peachpuff': '#ffdab9',
'peru': '#cd853f',
'pink': '#ffc0cb',
'plum': '#dda0dd',
'powderblue': '#b0e0e6',
'purple': '#800080',
'red': '#ff0000',
'rosybrown': '#bc8f8f',
'royalblue': '#4169e1',
'saddlebrown': '#8b4513',
'salmon': '#fa8072',
'sandybrown': '#f4a460',
'seagreen': '#2e8b57',
'seashell': '#fff5ee',
'sienna': '#a0522d',
'silver': '#c0c0c0',
'skyblue': '#87ceeb',
'slateblue': '#6a5acd',
'slategray': '#708090',
'slategrey': '#708090',
'snow': '#fffafa',
'springgreen': '#00ff7f',
'steelblue': '#4682b4',
'tan': '#d2b48c',
'teal': '#008080',
'thistle': '#d8bfd8',
'tomato': '#ff6347',
'turquoise': '#40e0d0',
'violet': '#ee82ee',
'wheat': '#f5deb3',
'white': '#ffffff',
'whitesmoke': '#f5f5f5',
'yellow': '#ffff00',
'yellowgreen': '#9acd32',
}
######################################################################
# Mappings of normalized hexadecimal color values to color names.
######################################################################
html4_hex_to_names = _reversedict(html4_names_to_hex)
css2_hex_to_names = html4_hex_to_names
css21_hex_to_names = _reversedict(css21_names_to_hex)
css3_hex_to_names = _reversedict(css3_names_to_hex)
######################################################################
# Normalization routines.
######################################################################
def normalize_hex(hex_value):
"""
Normalize a hexadecimal color value to the following form and
return the result::
#[a-f0-9]{6}
In other words, the following transformations are applied as
needed:
* If the value contains only three hexadecimal digits, it is
expanded to six.
* The value is normalized to lower-case.
If the supplied value cannot be interpreted as a hexadecimal color
value, ``ValueError`` is raised.
Examples:
>>> normalize_hex('#09c')
'#0099cc'
>>> normalize_hex('#0099cc')
'#0099cc'
>>> normalize_hex('#09C')
'#0099cc'
>>> normalize_hex('#0099CC')
'#0099cc'
>>> normalize_hex('0099cc')
Traceback (most recent call last):
...
ValueError: '0099cc' is not a valid hexadecimal color value.
>>> normalize_hex('#0099QX')
Traceback (most recent call last):
...
ValueError: '#0099QX' is not a valid hexadecimal color value.
>>> normalize_hex('foobarbaz')
Traceback (most recent call last):
...
ValueError: 'foobarbaz' is not a valid hexadecimal color value.
>>> normalize_hex('#0')
Traceback (most recent call last):
...
ValueError: '#0' is not a valid hexadecimal color value.
"""
try:
hex_digits = HEX_COLOR_RE.match(hex_value).groups()[0]
except AttributeError:
raise ValueError("'%s' is not a valid hexadecimal color value." % hex_value)
if len(hex_digits) == 3:
hex_digits = ''.join(map(lambda s: 2 * s, hex_digits))
return '#%s' % hex_digits.lower()
######################################################################
# Conversions from color names to various formats.
######################################################################
def name_to_hex(name, spec='css3'):
"""
Convert a color name to a normalized hexadecimal color value.
The optional keyword argument ``spec`` determines which
specification's list of color names will be used; valid values are
``html4``, ``css2``, ``css21`` and ``css3``, and the default is
``css3``.
The color name will be normalized to lower-case before being
looked up, and when no color of that name exists in the given
specification, ``ValueError`` is raised.
Examples:
>>> name_to_hex('deepskyblue')
'#00bfff'
>>> name_to_hex('DeepSkyBlue')
'#00bfff'
>>> name_to_hex('white', spec='html4')
'#ffffff'
>>> name_to_hex('white', spec='css2')
'#ffffff'
>>> name_to_hex('white', spec='css21')
'#ffffff'
>>> name_to_hex('white', spec='css3')
'#ffffff'
>>> name_to_hex('white', spec='css4')
Traceback (most recent call last):
...
TypeError: 'css4' is not a supported specification for color name lookups; supported specifications are: html4, css2, css21, css3.
>>> name_to_hex('deepskyblue', spec='css2')
Traceback (most recent call last):
...
ValueError: 'deepskyblue' is not defined as a named color in css2.
"""
if spec not in SUPPORTED_SPECIFICATIONS:
raise TypeError("'%s' is not a supported specification for color name lookups; supported specifications are: %s." % (spec,
', '.join(SUPPORTED_SPECIFICATIONS)))
normalized = name.lower()
try:
hex_value = globals()['%s_names_to_hex' % spec][normalized]
except KeyError:
raise ValueError("'%s' is not defined as a named color in %s." % (name, spec))
return hex_value
def name_to_rgb(name, spec='css3'):
"""
Convert a color name to a 3-tuple of integers suitable for use in
an ``rgb()`` triplet specifying that color.
The optional keyword argument ``spec`` determines which
specification's list of color names will be used; valid values are
``html4``, ``css2``, ``css21`` and ``css3``, and the default is
``css3``.
The color name will be normalized to lower-case before being
looked up, and when no color of that name exists in the given
specification, ``ValueError`` is raised.
Examples:
>>> name_to_rgb('navy')
(0, 0, 128)
>>> name_to_rgb('cadetblue')
(95, 158, 160)
>>> name_to_rgb('cadetblue', spec='html4')
Traceback (most recent call last):
...
ValueError: 'cadetblue' is not defined as a named color in html4.
"""
return hex_to_rgb(name_to_hex(name, spec=spec))
def name_to_rgb_percent(name, spec='css3'):
"""
Convert a color name to a 3-tuple of percentages suitable for use
in an ``rgb()`` triplet specifying that color.
The optional keyword argument ``spec`` determines which
specification's list of color names will be used; valid values are
``html4``, ``css2``, ``css21`` and ``css3``, and the default is
``css3``.
The color name will be normalized to lower-case before being
looked up, and when no color of that name exists in the given
specification, ``ValueError`` is raised.
Examples:
>>> name_to_rgb_percent('white')
('100%', '100%', '100%')
>>> name_to_rgb_percent('navy')
('0%', '0%', '50%')
>>> name_to_rgb_percent('goldenrod')
('85.49%', '64.71%', '12.5%')
"""
return rgb_to_rgb_percent(name_to_rgb(name, spec=spec))
######################################################################
# Conversions from hexadecimal color values to various formats.
######################################################################
def hex_to_name(hex_value, spec='css3'):
"""
Convert a hexadecimal color value to its corresponding normalized
color name, if any such name exists.
The optional keyword argument ``spec`` determines which
specification's list of color names will be used; valid values are
``html4``, ``css2``, ``css21`` and ``css3``, and the default is
``css3``.
The hexadecimal value will be normalized before being looked up,
and when no color name for the value is found in the given
specification, ``ValueError`` is raised.
Examples:
>>> hex_to_name('#000080')
'navy'
>>> hex_to_name('#000080', spec='html4')
'navy'
>>> hex_to_name('#000080', spec='css2')
'navy'
>>> hex_to_name('#000080', spec='css21')
'navy'
>>> hex_to_name('#8b4513')
'saddlebrown'
>>> hex_to_name('#8b4513', spec='html4')
Traceback (most recent call last):
...
ValueError: '#8b4513' has no defined color name in html4.
>>> hex_to_name('#8b4513', spec='css4')
Traceback (most recent call last):
...
TypeError: 'css4' is not a supported specification for color name lookups; supported specifications are: html4, css2, css21, css3.
"""
if spec not in SUPPORTED_SPECIFICATIONS:
raise TypeError("'%s' is not a supported specification for color name lookups; supported specifications are: %s." % (spec,
', '.join(SUPPORTED_SPECIFICATIONS)))
normalized = normalize_hex(hex_value)
try:
name = globals()['%s_hex_to_names' % spec][normalized]
except KeyError:
raise ValueError("'%s' has no defined color name in %s." % (hex_value, spec))
return name
def hex_to_color_name(hex_value):
hex_value = hex_value.strip('#')
hex_value = "#" + "0" * (6 - len(hex_value)) + hex_value
try:
return hex_to_name(hex_value)
except ValueError:
return hex_value
def hex_to_rgb(hex_value):
"""
Convert a hexadecimal color value to a 3-tuple of integers
suitable for use in an ``rgb()`` triplet specifying that color.
The hexadecimal value will be normalized before being converted.
Examples:
>>> hex_to_rgb('#000080')
(0, 0, 128)
>>> hex_to_rgb('#ffff00')
(255, 255, 0)
>>> hex_to_rgb('#f00')
(255, 0, 0)
>>> hex_to_rgb('#deb887')
(222, 184, 135)
"""
hex_digits = normalize_hex(hex_value)
return tuple(map(lambda s: int(s, 16),
(hex_digits[1:3], hex_digits[3:5], hex_digits[5:7])))
def hex_to_rgb_percent(hex_value):
"""
Convert a hexadecimal color value to a 3-tuple of percentages
suitable for use in an ``rgb()`` triplet representing that color.
The hexadecimal value will be normalized before converting.
Examples:
>>> hex_to_rgb_percent('#ffffff')
('100%', '100%', '100%')
>>> hex_to_rgb_percent('#000080')
('0%', '0%', '50%')
"""
return rgb_to_rgb_percent(hex_to_rgb(hex_value))
######################################################################
# Conversions from integer rgb() triplets to various formats.
######################################################################
def rgb_to_name(rgb_triplet, spec='css3'):
"""
Convert a 3-tuple of integers, suitable for use in an ``rgb()``
color triplet, to its corresponding normalized color name, if any
such name exists.
The optional keyword argument ``spec`` determines which
specification's list of color names will be used; valid values are
``html4``, ``css2``, ``css21`` and ``css3``, and the default is
``css3``.
If there is no matching name, ``ValueError`` is raised.
Examples:
>>> rgb_to_name((0, 0, 0))
'black'
>>> rgb_to_name((0, 0, 128))
'navy'
>>> rgb_to_name((95, 158, 160))
'cadetblue'
"""
return hex_to_name(rgb_to_hex(rgb_triplet), spec=spec)
def rgb_to_hex(rgb_triplet):
"""
Convert a 3-tuple of integers, suitable for use in an ``rgb()``
color triplet, to a normalized hexadecimal value for that color.
Examples:
>>> rgb_to_hex((255, 255, 255))
'#ffffff'
>>> rgb_to_hex((0, 0, 128))
'#000080'
>>> rgb_to_hex((33, 56, 192))
'#2138c0'
"""
return '#%02x%02x%02x' % rgb_triplet
def rgb_to_rgb_percent(rgb_triplet):
"""
Convert a 3-tuple of integers, suitable for use in an ``rgb()``
color triplet, to a 3-tuple of percentages suitable for use in
representing that color.
This function makes some trade-offs in terms of the accuracy of
the final representation; for some common integer values,
special-case logic is used to ensure a precise result (e.g.,
integer 128 will always convert to '50%', integer 32 will always
convert to '12.5%'), but for all other values a standard Python
``float`` is used and rounded to two decimal places, which may
result in a loss of precision for some values.
Examples:
>>> rgb_to_rgb_percent((255, 255, 255))
('100%', '100%', '100%')
>>> rgb_to_rgb_percent((0, 0, 128))
('0%', '0%', '50%')
>>> rgb_to_rgb_percent((33, 56, 192))
('12.94%', '21.96%', '75.29%')
>>> rgb_to_rgb_percent((64, 32, 16))
('25%', '12.5%', '6.25%')
"""
# In order to maintain precision for common values,
# 256 / 2**n is special-cased for values of n
# from 0 through 4, as well as 0 itself.
specials = {255: '100%', 128: '50%', 64: '25%',
32: '12.5%', 16: '6.25%', 0: '0%'}
return tuple(map(lambda d: specials.get(d, '%.02f%%' % ((d / 255.0) * 100)),
rgb_triplet))
######################################################################
# Conversions from percentage rgb() triplets to various formats.
######################################################################
def rgb_percent_to_name(rgb_percent_triplet, spec='css3'):
"""
Convert a 3-tuple of percentages, suitable for use in an ``rgb()``
color triplet, to its corresponding normalized color name, if any
such name exists.
The optional keyword argument ``spec`` determines which
specification's list of color names will be used; valid values are
``html4``, ``css2``, ``css21`` and ``css3``, and the default is
``css3``.
If there is no matching name, ``ValueError`` is raised.
Examples:
>>> rgb_percent_to_name(('0%', '0%', '0%'))
'black'
>>> rgb_percent_to_name(('0%', '0%', '50%'))
'navy'
>>> rgb_percent_to_name(('85.49%', '64.71%', '12.5%'))
'goldenrod'
"""
return rgb_to_name(rgb_percent_to_rgb(rgb_percent_triplet), spec=spec)
def rgb_percent_to_hex(rgb_percent_triplet):
"""
Convert a 3-tuple of percentages, suitable for use in an ``rgb()``
color triplet, to a normalized hexadecimal color value for that
color.
Examples:
>>> rgb_percent_to_hex(('100%', '100%', '0%'))
'#ffff00'
>>> rgb_percent_to_hex(('0%', '0%', '50%'))
'#000080'
>>> rgb_percent_to_hex(('85.49%', '64.71%', '12.5%'))
'#daa520'
"""
return rgb_to_hex(rgb_percent_to_rgb(rgb_percent_triplet))
def _percent_to_integer(percent):
"""
Internal helper for converting a percentage value to an integer
between 0 and 255 inclusive.
"""
num = float(percent.split('%')[0]) / 100.0 * 255
e = num - math.floor(num)
return e < 0.5 and int(math.floor(num)) or int(math.ceil(num))
def rgb_percent_to_rgb(rgb_percent_triplet):
"""
Convert a 3-tuple of percentages, suitable for use in an ``rgb()``
color triplet, to a 3-tuple of integers suitable for use in
representing that color.
Some precision may be lost in this conversion. See the note
regarding precision for ``rgb_to_rgb_percent()`` for details;
generally speaking, the following is true for any 3-tuple ``t`` of
integers in the range 0...255 inclusive::
t == rgb_percent_to_rgb(rgb_to_rgb_percent(t))
Examples:
>>> rgb_percent_to_rgb(('100%', '100%', '100%'))
(255, 255, 255)
>>> rgb_percent_to_rgb(('0%', '0%', '50%'))
(0, 0, 128)
>>> rgb_percent_to_rgb(('25%', '12.5%', '6.25%'))
(64, 32, 16)
>>> rgb_percent_to_rgb(('12.94%', '21.96%', '75.29%'))
(33, 56, 192)
"""
return tuple(map(_percent_to_integer, rgb_percent_triplet))
def whatever_to_rgb(string):
"""
Converts CSS3 color or a hex into rgb triplet; hash of string if fails.
"""
string = string.strip().lower()
try:
return name_to_rgb(string)
except ValueError:
try:
return hex_to_rgb(string)
except ValueError:
try:
if string[:3] == "rgb":
return tuple([float(i) for i in string[4:-1].split(",")][0:3])
except:
return hex_to_rgb("#" + md5(string).hexdigest()[:6])
def whatever_to_hex(string):
if type(string) == tuple:
return cairo_to_hex(string)
return rgb_to_hex(whatever_to_rgb(string))
def whatever_to_cairo(string):
a = whatever_to_rgb(string)
return a[0] / 255., a[1] / 255., a[2] / 255.,
def cairo_to_hex(cairo):
return rgb_to_hex((cairo[0] * 255, cairo[1] * 255, cairo[2] * 255,))
if __name__ == '__main__':
import doctest
doctest.testmod()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
33,
3486,
3555,
367,
6449,
543,
314,
3164,
1561,
436,
3164,
9479,
199,
4037,
701,
314,
4163,
436,
15750,
28754,
14,
199,
199,
2493,
23503,
402,
4163,
436,
15750,
9229,
199,
1444,
306,
199,
199,
20094,
641,
314,
6001,
787,
2013,
315,
658,
1589,
308,
12067,
3164,
4601,
64,
3131,
2382,
1924,
199,
2326,
365,
6326,
1536,
402,
282,
8992,
3931,
12,
282,
12431,
3931,
436,
282,
10030,
199,
3173,
14,
961,
365,
2997,
2952,
652,
9033,
334,
667,
723,
590,
9,
3633,
590,
370,
314,
8992,
12,
199,
7731,
436,
10030,
7323,
402,
11094,
641,
282,
24189,
2929,
12,
436,
370,
314,
199,
67,
368,
10106,
402,
282,
11779,
25892,
12,
1314,
11492,
315,
7795,
5951,
28568,
590,
199,
989,
31137,
370,
314,
12204,
14563,
402,
10540,
4568,
543,
8992,
12,
12431,
199,
460,
10030,
14,
199,
199,
64,
1918,
4163,
841,
4465,
18417,
7890,
2877,
15217,
370,
4165,
308,
12067,
9229,
26,
199,
199,
10,
437,
2631,
2216,
22870,
358,
9437,
701,
7795,
6342,
402,
6318,
6355,
7576,
12,
523,
9176,
1338,
367,
8992,
12,
12431,
436,
10030,
7323,
315,
626,
1865,
27,
523,
367,
2893,
12,
1124,
3,
29660,
2055,
4345,
9336,
1924,
4092,
402,
20379,
7576,
883,
523,
4056,
7633,
3365,
1338,
12,
642,
6127,
1536,
370,
7633,
538,
19,
503,
3193,
12,
11956,
12,
9669,
523,
3747,
9229,
370,
506,
2013,
334,
15401,
12,
7037,
370,
15109,
315,
2929,
523,
1565,
24731,
12,
440,
1006,
402,
3520,
9229,
1443,
506,
5436,
590,
2917,
14659,
4387,
641,
523,
1263,
1627,
14095,
2929,
680,
199,
199,
10,
437,
663,
402,
27684,
3164,
1561,
1314,
17118,
370,
2488,
523,
20379,
1338,
27,
367,
2893,
12,
1124,
7510,
4345,
4163,
841,
7890,
3816,
25076,
523,
4066,
9229,
14,
199,
199,
64,
1918,
15750,
499,
4465,
18417,
6127,
1263,
1686,
4163,
841,
3164,
8929,
12,
436,
199,
525,
83,
7795,
892,
15217,
370,
4165,
308,
12067,
9229,
26,
199,
199,
10,
437,
2631,
2216,
9437,
701,
7795,
20379,
7576,
12,
1314,
365,
11507,
523,
1901,
7795,
20379,
6342,
701,
6375,
1958,
1924,
10964,
27,
12850,
1124,
3,
1643,
67,
1040,
523,
365,
7353,
370,
1124,
3,
29660,
2055,
4345,
199,
199,
10,
710,
1059,
283,
10090,
297,
9437,
701,
23592,
12,
3382,
1314,
787,
7795,
523,
8950,
1338,
1924,
3382,
378,
436,
5450,
12,
20728,
12,
1314,
787,
9394,
370,
523,
506,
314,
1338,
402,
314,
8992,
12,
12431,
436,
10030,
7323,
315,
626,
1865,
27,
523,
367,
2893,
12,
1124,
10090,
8,
16,
12,
25828,
12,
14785,
20642,
199,
199,
10,
710,
2011,
465,
3432,
12,
871,
1808,
8878,
7441,
3140,
402,
8950,
523,
1338,
27,
367,
2893,
12,
1124,
10090,
8,
16,
5,
12,
5212,
5,
12,
5939,
5,
20642,
199,
199,
64,
1918,
15750,
499,
14,
17,
6974,
18417,
1630,
440,
1050,
1263,
892,
3102,
402,
9176,
199,
83,
12067,
9229,
12,
1325,
1630,
1050,
1373,
4722,
4310,
3164,
14,
199,
199,
64,
1918,
15750,
650,
3164,
859,
18417,
334,
19767,
282,
644,
19,
35,
6855,
5168,
799,
22105,
9,
199,
525,
83,
1373,
892,
4340,
370,
4165,
308,
12067,
9229,
26,
199,
199,
10,
437,
28679,
13,
14997,
1542,
13,
4040,
4171,
19671,
334,
40,
4929,
395,
1808,
314,
6982,
523,
1124,
72,
2482,
28566,
199,
199,
7940,
2597,
9584,
2291,
367,
1750,
31835,
402,
9229,
12,
701,
17266,
314,
199,
22271,
402,
5131,
13,
2775,
2556,
12,
4012,
314,
1124,
22118,
8497,
436,
199,
1040,
4213,
416,
8497,
21638,
12,
1314,
787,
13130,
370,
1124,
10090,
8497,
436,
1124,
72,
2482,
8497,
199,
1045,
1373,
1919,
26,
282,
11648,
273,
574,
365,
6841,
12,
9297,
314,
2166,
199,
1618,
31835,
687,
1124,
16,
14,
16,
1040,
334,
4883,
590,
17265,
9,
370,
1124,
17,
14,
16,
1040,
199,
8,
4883,
590,
15058,
680,
18049,
3080,
440,
18077,
7288,
282,
3164,
12,
314,
4252,
199,
1040,
24420,
1040,
365,
2597,
6326,
2808,
315,
1212,
16913,
402,
282,
3164,
574,
12,
436,
199,
989,
3853,
795,
370,
1124,
22118,
8,
16,
12,
16,
12,
16,
12,
16,
20642,
199,
199,
2767,
22565,
12,
15750,
19,
7890,
282,
892,
663,
402,
3164,
1561,
27,
642,
663,
365,
9394,
199,
2275,
590,
687,
314,
4310,
9229,
3247,
367,
32062,
334,
10249,
461,
11388,
199,
18859,
9,
9189,
12,
436,
365,
282,
5576,
1613,
409,
402,
314,
4310,
9229,
3247,
199,
262,
15750,
499,
14,
17,
14,
961,
663,
2597,
965,
16474,
15145,
543,
1468,
2603,
1323,
845,
199,
2326,
5951,
465,
3247,
701,
314,
1124,
10090,
14,
2424,
1040,
570,
641,
5002,
13074,
436,
199,
21607,
13,
2930,
17406,
10460,
12,
10617,
314,
4327,
5606,
365,
440,
5835,
27,
199,
1589,
663,
402,
1323,
845,
9229,
365,
440,
28974,
7068,
12,
436,
314,
663,
402,
15750,
19,
9229,
199,
6134,
2005,
10269,
1314,
487,
422,
303,
16474,
590,
687,
3537,
695,
199,
56,
845,
10269,
334,
509,
2893,
12,
15750,
19,
1159,
1124,
7731,
1040,
365,
440,
7353,
370,
199,
56,
845,
1159,
1124,
7731,
1040,
27,
314,
574,
1314,
1323,
845,
12899,
2335,
1124,
7731,
1040,
365,
199,
14748,
972,
1124,
18687,
1040,
315,
15750,
19,
680,
199,
199,
703,
485,
1589,
308,
12067,
3164,
4601,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
18859,
15,
4117,
15,
83,
12067,
199,
703,
485,
1918,
4163,
841,
4465,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
1360,
8854,
15,
1313,
14,
1360,
3,
72,
13,
22,
14,
21,
199,
703,
485,
1918,
15750,
499,
4465,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
9481,
13,
14391,
18,
15,
9466,
576,
14,
1360,
3,
585,
13,
318,
13,
2326,
199,
703,
485,
1918,
15750,
499,
14,
17,
6974,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
14391,
2025,
15,
199,
703,
485,
1918,
15750,
650,
3164,
859,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
3919,
19,
13,
2326,
15,
199,
199,
21015,
642,
859,
5171,
199,
777,
9960,
199,
199,
1918,
13546,
436,
3423,
4453,
642,
859,
2291,
314,
2569,
199,
2474,
402,
9176
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
33,
3486,
3555,
367,
6449,
543,
314,
3164,
1561,
436,
3164,
9479,
199,
4037,
701,
314,
4163,
436,
15750,
28754,
14,
199,
199,
2493,
23503,
402,
4163,
436,
15750,
9229,
199,
1444,
306,
199,
199,
20094,
641,
314,
6001,
787,
2013,
315,
658,
1589,
308,
12067,
3164,
4601,
64,
3131,
2382,
1924,
199,
2326,
365,
6326,
1536,
402,
282,
8992,
3931,
12,
282,
12431,
3931,
436,
282,
10030,
199,
3173,
14,
961,
365,
2997,
2952,
652,
9033,
334,
667,
723,
590,
9,
3633,
590,
370,
314,
8992,
12,
199,
7731,
436,
10030,
7323,
402,
11094,
641,
282,
24189,
2929,
12,
436,
370,
314,
199,
67,
368,
10106,
402,
282,
11779,
25892,
12,
1314,
11492,
315,
7795,
5951,
28568,
590,
199,
989,
31137,
370,
314,
12204,
14563,
402,
10540,
4568,
543,
8992,
12,
12431,
199,
460,
10030,
14,
199,
199,
64,
1918,
4163,
841,
4465,
18417,
7890,
2877,
15217,
370,
4165,
308,
12067,
9229,
26,
199,
199,
10,
437,
2631,
2216,
22870,
358,
9437,
701,
7795,
6342,
402,
6318,
6355,
7576,
12,
523,
9176,
1338,
367,
8992,
12,
12431,
436,
10030,
7323,
315,
626,
1865,
27,
523,
367,
2893,
12,
1124,
3,
29660,
2055,
4345,
9336,
1924,
4092,
402,
20379,
7576,
883,
523,
4056,
7633,
3365,
1338,
12,
642,
6127,
1536,
370,
7633,
538,
19,
503,
3193,
12,
11956,
12,
9669,
523,
3747,
9229,
370,
506,
2013,
334,
15401,
12,
7037,
370,
15109,
315,
2929,
523,
1565,
24731,
12,
440,
1006,
402,
3520,
9229,
1443,
506,
5436,
590,
2917,
14659,
4387,
641,
523,
1263,
1627,
14095,
2929,
680,
199,
199,
10,
437,
663,
402,
27684,
3164,
1561,
1314,
17118,
370,
2488,
523,
20379,
1338,
27,
367,
2893,
12,
1124,
7510,
4345,
4163,
841,
7890,
3816,
25076,
523,
4066,
9229,
14,
199,
199,
64,
1918,
15750,
499,
4465,
18417,
6127,
1263,
1686,
4163,
841,
3164,
8929,
12,
436,
199,
525,
83,
7795,
892,
15217,
370,
4165,
308,
12067,
9229,
26,
199,
199,
10,
437,
2631,
2216,
9437,
701,
7795,
20379,
7576,
12,
1314,
365,
11507,
523,
1901,
7795,
20379,
6342,
701,
6375,
1958,
1924,
10964,
27,
12850,
1124,
3,
1643,
67,
1040,
523,
365,
7353,
370,
1124,
3,
29660,
2055,
4345,
199,
199,
10,
710,
1059,
283,
10090,
297,
9437,
701,
23592,
12,
3382,
1314,
787,
7795,
523,
8950,
1338,
1924,
3382,
378,
436,
5450,
12,
20728,
12,
1314,
787,
9394,
370,
523,
506,
314,
1338,
402,
314,
8992,
12,
12431,
436,
10030,
7323,
315,
626,
1865,
27,
523,
367,
2893,
12,
1124,
10090,
8,
16,
12,
25828,
12,
14785,
20642,
199,
199,
10,
710,
2011,
465,
3432,
12,
871,
1808,
8878,
7441,
3140,
402,
8950,
523,
1338,
27,
367,
2893,
12,
1124,
10090,
8,
16,
5,
12,
5212,
5,
12,
5939,
5,
20642,
199,
199,
64,
1918,
15750,
499,
14,
17,
6974,
18417,
1630,
440,
1050,
1263,
892,
3102,
402,
9176,
199,
83,
12067,
9229,
12,
1325,
1630,
1050,
1373,
4722,
4310,
3164,
14,
199,
199,
64,
1918,
15750,
650,
3164,
859,
18417,
334,
19767,
282,
644,
19,
35,
6855,
5168,
799,
22105,
9,
199,
525,
83,
1373,
892,
4340,
370,
4165,
308,
12067,
9229,
26,
199,
199,
10,
437,
28679,
13,
14997,
1542,
13,
4040,
4171,
19671,
334,
40,
4929,
395,
1808,
314,
6982,
523,
1124,
72,
2482,
28566,
199,
199,
7940,
2597,
9584,
2291,
367,
1750,
31835,
402,
9229,
12,
701,
17266,
314,
199,
22271,
402,
5131,
13,
2775,
2556,
12,
4012,
314,
1124,
22118,
8497,
436,
199,
1040,
4213,
416,
8497,
21638,
12,
1314,
787,
13130,
370,
1124,
10090,
8497,
436,
1124,
72,
2482,
8497,
199,
1045,
1373,
1919,
26,
282,
11648,
273,
574,
365,
6841,
12,
9297,
314,
2166,
199,
1618,
31835,
687,
1124,
16,
14,
16,
1040,
334,
4883,
590,
17265,
9,
370,
1124,
17,
14,
16,
1040,
199,
8,
4883,
590,
15058,
680,
18049,
3080,
440,
18077,
7288,
282,
3164,
12,
314,
4252,
199,
1040,
24420,
1040,
365,
2597,
6326,
2808,
315,
1212,
16913,
402,
282,
3164,
574,
12,
436,
199,
989,
3853,
795,
370,
1124,
22118,
8,
16,
12,
16,
12,
16,
12,
16,
20642,
199,
199,
2767,
22565,
12,
15750,
19,
7890,
282,
892,
663,
402,
3164,
1561,
27,
642,
663,
365,
9394,
199,
2275,
590,
687,
314,
4310,
9229,
3247,
367,
32062,
334,
10249,
461,
11388,
199,
18859,
9,
9189,
12,
436,
365,
282,
5576,
1613,
409,
402,
314,
4310,
9229,
3247,
199,
262,
15750,
499,
14,
17,
14,
961,
663,
2597,
965,
16474,
15145,
543,
1468,
2603,
1323,
845,
199,
2326,
5951,
465,
3247,
701,
314,
1124,
10090,
14,
2424,
1040,
570,
641,
5002,
13074,
436,
199,
21607,
13,
2930,
17406,
10460,
12,
10617,
314,
4327,
5606,
365,
440,
5835,
27,
199,
1589,
663,
402,
1323,
845,
9229,
365,
440,
28974,
7068,
12,
436,
314,
663,
402,
15750,
19,
9229,
199,
6134,
2005,
10269,
1314,
487,
422,
303,
16474,
590,
687,
3537,
695,
199,
56,
845,
10269,
334,
509,
2893,
12,
15750,
19,
1159,
1124,
7731,
1040,
365,
440,
7353,
370,
199,
56,
845,
1159,
1124,
7731,
1040,
27,
314,
574,
1314,
1323,
845,
12899,
2335,
1124,
7731,
1040,
365,
199,
14748,
972,
1124,
18687,
1040,
315,
15750,
19,
680,
199,
199,
703,
485,
1589,
308,
12067,
3164,
4601,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
18859,
15,
4117,
15,
83,
12067,
199,
703,
485,
1918,
4163,
841,
4465,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
1360,
8854,
15,
1313,
14,
1360,
3,
72,
13,
22,
14,
21,
199,
703,
485,
1918,
15750,
499,
4465,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
9481,
13,
14391,
18,
15,
9466,
576,
14,
1360,
3,
585,
13,
318,
13,
2326,
199,
703,
485,
1918,
15750,
499,
14,
17,
6974,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
14391,
2025,
15,
199,
703,
485,
1918,
15750,
650,
3164,
859,
26,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
3919,
19,
13,
2326,
15,
199,
199,
21015,
642,
859,
5171,
199,
777,
9960,
199,
199,
1918,
13546,
436,
3423,
4453,
642,
859,
2291,
314,
2569,
199,
2474,
402,
9176,
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,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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
] |
twaldrop/ursula
|
library/keystone_user.py
|
87
|
14056
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# 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/>.
# Based on Jimmy Tang's implementation
DOCUMENTATION = '''
---
module: keystone_user
version_added: "1.2"
short_description: Manage OpenStack Identity (keystone) users, tenants and roles
description:
- Manage users,tenants, roles from OpenStack.
options:
login_user:
description:
- login username to authenticate to keystone
required: false
default: admin
login_password:
description:
- Password of login user
required: false
default: 'yes'
login_tenant_name:
description:
- The tenant login_user belongs to
required: false
default: None
version_added: "1.3"
token:
description:
- The token to be uses in case the password is not specified
required: false
default: None
endpoint:
description:
- The keystone url for authentication
required: false
default: 'http://127.0.0.1:35357/v2.0/'
user:
description:
- The name of the user that has to added/removed from OpenStack
required: false
default: None
password:
description:
- The password to be assigned to the user
required: false
default: None
tenant:
description:
- The tenant name that has be added/removed
required: false
default: None
tenant_description:
description:
- A description for the tenant
required: false
default: None
email:
description:
- An email address for the user
required: false
default: None
role:
description:
- The name of the role to be assigned or created
required: false
default: None
state:
description:
- Indicate desired state of the resource
choices: ['present', 'absent']
default: present
requirements:
- "python >= 2.6"
- python-keystoneclient
author: "Lorin Hochstein (@lorin)"
'''
EXAMPLES = '''
# Create a tenant
- keystone_user: tenant=demo tenant_description="Default Tenant"
# Create a user
- keystone_user: user=john tenant=demo password=secrete
# Apply the admin role to the john user in the demo tenant
- keystone_user: role=admin user=john tenant=demo
'''
try:
from keystoneclient.v2_0 import client
except ImportError:
keystoneclient_found = False
else:
keystoneclient_found = True
def authenticate(endpoint, token, login_user, login_password, login_tenant_name):
"""Return a keystone client object"""
if token:
return client.Client(endpoint=endpoint, token=token)
else:
return client.Client(auth_url=endpoint, username=login_user,
password=login_password, tenant_name=login_tenant_name)
def tenant_exists(keystone, tenant):
""" Return True if tenant already exists"""
return tenant in [x.name for x in keystone.tenants.list()]
def user_exists(keystone, user):
"""" Return True if user already exists"""
return user in [x.name for x in keystone.users.list()]
def get_tenant(keystone, name):
""" Retrieve a tenant by name"""
tenants = [x for x in keystone.tenants.list() if x.name == name]
count = len(tenants)
if count == 0:
raise KeyError("No keystone tenants with name %s" % name)
elif count > 1:
raise ValueError("%d tenants with name %s" % (count, name))
else:
return tenants[0]
def get_user(keystone, name):
""" Retrieve a user by name"""
users = [x for x in keystone.users.list() if x.name == name]
count = len(users)
if count == 0:
raise KeyError("No keystone users with name %s" % name)
elif count > 1:
raise ValueError("%d users with name %s" % (count, name))
else:
return users[0]
def get_role(keystone, name):
""" Retrieve a role by name"""
roles = [x for x in keystone.roles.list() if x.name == name]
count = len(roles)
if count == 0:
raise KeyError("No keystone roles with name %s" % name)
elif count > 1:
raise ValueError("%d roles with name %s" % (count, name))
else:
return roles[0]
def get_tenant_id(keystone, name):
return get_tenant(keystone, name).id
def get_user_id(keystone, name):
return get_user(keystone, name).id
def ensure_tenant_exists(keystone, tenant_name, tenant_description,
check_mode):
""" Ensure that a tenant exists.
Return (True, id) if a new tenant was created, (False, None) if it
already existed.
"""
# Check if tenant already exists
try:
tenant = get_tenant(keystone, tenant_name)
except KeyError:
# Tenant doesn't exist yet
pass
else:
if tenant.description == tenant_description:
return (False, tenant.id)
else:
# We need to update the tenant description
if check_mode:
return (True, tenant.id)
else:
tenant.update(description=tenant_description)
return (True, tenant.id)
# We now know we will have to create a new tenant
if check_mode:
return (True, None)
ks_tenant = keystone.tenants.create(tenant_name=tenant_name,
description=tenant_description,
enabled=True)
return (True, ks_tenant.id)
def ensure_tenant_absent(keystone, tenant, check_mode):
""" Ensure that a tenant does not exist
Return True if the tenant was removed, False if it didn't exist
in the first place
"""
if not tenant_exists(keystone, tenant):
return False
# We now know we will have to delete the tenant
if check_mode:
return True
def ensure_user_exists(keystone, user_name, password, email, tenant_name,
check_mode):
""" Check if user exists
Return (True, id) if a new user was created, (False, id) user alrady
exists
"""
# Check if tenant already exists
try:
user = get_user(keystone, user_name)
except KeyError:
# Tenant doesn't exist yet
pass
else:
# User does exist, we're done
return (False, user.id)
# We now know we will have to create a new user
if check_mode:
return (True, None)
tenant = get_tenant(keystone, tenant_name)
user = keystone.users.create(name=user_name, password=password,
email=email, tenant_id=tenant.id)
return (True, user.id)
def ensure_role_exists(keystone, role_name):
# Get the role if it exists
try:
role = get_role(keystone, role_name)
# Role does exist, we're done
return (False, role.id)
except KeyError:
# Role doesn't exist yet
pass
role = keystone.roles.create(role_name)
return (True, role.id)
def ensure_user_role_exists(keystone, user_name, tenant_name, role_name,
check_mode):
""" Check if role exists
Return (True, id) if a new role was created or if the role was newly
assigned to the user for the tenant. (False, id) if the role already
exists and was already assigned to the user ofr the tenant.
"""
# Check if the user has the role in the tenant
user = get_user(keystone, user_name)
tenant = get_tenant(keystone, tenant_name)
roles = [x for x in keystone.roles.roles_for_user(user, tenant)
if x.name == role_name]
count = len(roles)
if count == 1:
# If the role is in there, we are done
role = roles[0]
return (False, role.id)
elif count > 1:
# Too many roles with the same name, throw an error
raise ValueError("%d roles with name %s" % (count, role_name))
# At this point, we know we will need to make changes
if check_mode:
return (True, None)
# Get the role if it exists
try:
role = get_role(keystone, role_name)
except KeyError:
# Role doesn't exist yet
role = keystone.roles.create(role_name)
# Associate the role with the user in the admin
keystone.roles.add_user_role(user, role, tenant)
return (True, role.id)
def ensure_user_absent(keystone, user, check_mode):
raise NotImplementedError("Not yet implemented")
def ensure_user_role_absent(keystone, uesr, tenant, role, check_mode):
raise NotImplementedError("Not yet implemented")
def ensure_role_absent(keystone, role_name):
raise NotImplementedError("Not yet implemented")
def main():
argument_spec = openstack_argument_spec()
argument_spec.update(dict(
tenant_description=dict(required=False),
email=dict(required=False),
user=dict(required=False),
tenant=dict(required=False),
password=dict(required=False),
role=dict(required=False),
state=dict(default='present', choices=['present', 'absent']),
endpoint=dict(required=False,
default="http://127.0.0.1:35357/v2.0"),
token=dict(required=False),
login_user=dict(required=False),
login_password=dict(required=False),
login_tenant_name=dict(required=False)
))
# keystone operations themselves take an endpoint, not a keystone auth_url
del(argument_spec['auth_url'])
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
mutually_exclusive=[['token', 'login_user'],
['token', 'login_password'],
['token', 'login_tenant_name']]
)
if not keystoneclient_found:
module.fail_json(msg="the python-keystoneclient module is required")
user = module.params['user']
password = module.params['password']
tenant = module.params['tenant']
tenant_description = module.params['tenant_description']
email = module.params['email']
role = module.params['role']
state = module.params['state']
endpoint = module.params['endpoint']
token = module.params['token']
login_user = module.params['login_user']
login_password = module.params['login_password']
login_tenant_name = module.params['login_tenant_name']
keystone = authenticate(endpoint, token, login_user, login_password, login_tenant_name)
check_mode = module.check_mode
try:
d = dispatch(keystone, user, password, tenant, tenant_description,
email, role, state, endpoint, token, login_user,
login_password, check_mode)
except Exception, e:
if check_mode:
# If we have a failure in check mode
module.exit_json(changed=True,
msg="exception: %s" % e)
else:
module.fail_json(msg="exception: %s" % e)
else:
module.exit_json(**d)
def dispatch(keystone, user=None, password=None, tenant=None,
tenant_description=None, email=None, role=None,
state="present", endpoint=None, token=None, login_user=None,
login_password=None, check_mode=False):
""" Dispatch to the appropriate method.
Returns a dict that will be passed to exit_json
tenant user role state
------ ---- ---- --------
X present ensure_tenant_exists
X absent ensure_tenant_absent
X X present ensure_user_exists
X X absent ensure_user_absent
X X X present ensure_user_role_exists
X X X absent ensure_user_role_absent
X present ensure_role_exists
X absent ensure_role_absent
"""
changed = False
id = None
if not tenant and not user and role and state == "present":
changed, id = ensure_role_exists(keystone, role)
elif not tenant and not user and role and state == "absent":
changed = ensure_role_absent(keystone, role)
elif tenant and not user and not role and state == "present":
changed, id = ensure_tenant_exists(keystone, tenant,
tenant_description, check_mode)
elif tenant and not user and not role and state == "absent":
changed = ensure_tenant_absent(keystone, tenant, check_mode)
elif tenant and user and not role and state == "present":
changed, id = ensure_user_exists(keystone, user, password,
email, tenant, check_mode)
elif tenant and user and not role and state == "absent":
changed = ensure_user_absent(keystone, user, check_mode)
elif tenant and user and role and state == "present":
changed, id = ensure_user_role_exists(keystone, user, tenant, role,
check_mode)
elif tenant and user and role and state == "absent":
changed = ensure_user_role_absent(keystone, user, tenant, role, check_mode)
else:
# Should never reach here
raise ValueError("Code should never reach here")
return dict(changed=changed, id=id)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.openstack import *
if __name__ == '__main__':
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
21311,
641,
1603,
20066,
89,
377,
621,
1159,
4514,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
19395,
63,
751,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
3612,
63,
1802,
26,
14944,
14260,
22034,
334,
19143,
9,
4390,
12,
16685,
2285,
436,
11689,
199,
1802,
26,
2043,
446,
14944,
4390,
12,
25021,
12,
11689,
687,
14260,
14,
199,
1419,
26,
2043,
4676,
63,
751,
26,
1362,
1369,
26,
267,
446,
4676,
3434,
370,
12895,
370,
19395,
1362,
1415,
26,
3055,
1362,
849,
26,
4628,
2043,
4676,
63,
2060,
26,
1362,
1369,
26,
267,
446,
13635,
402,
4676,
922,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
5066,
7,
2043,
4676,
63,
4647,
63,
354,
26,
1362,
1369,
26,
267,
446,
710,
8261,
4676,
63,
751,
15006,
370,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
1362,
1015,
63,
3270,
26,
298,
17,
14,
19,
2,
2043,
1526,
26,
1362,
1369,
26,
267,
446,
710,
1526,
370,
506,
4440,
315,
1930,
314,
2505,
365,
440,
2013,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
6037,
26,
1362,
1369,
26,
267,
446,
710,
19395,
1166,
367,
6299,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1276,
13155,
15,
86,
18,
14,
16,
4805,
2043,
922,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
922,
626,
965,
370,
3483,
15,
10649,
687,
14260,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
2505,
26,
1362,
1369,
26,
267,
446,
710,
2505,
370,
506,
7943,
370,
314,
922,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
8261,
26,
1362,
1369,
26,
267,
446,
710,
8261,
536,
626,
965,
506,
3483,
15,
10649,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
8261,
63,
1802,
26,
1362,
1369,
26,
267,
446,
437,
1369,
367,
314,
8261,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
3031,
26,
1362,
1369,
26,
267,
446,
1626,
3031,
2287,
367,
314,
922,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
4719,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
4719,
370,
506,
7943,
503,
2737,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1174,
26,
1362,
1369,
26,
267,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
1362,
3415,
26,
788,
1881,
297,
283,
5575,
418,
1362,
849,
26,
3451,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
221,
2366,
13,
19143,
1258,
199,
2502,
26,
298,
44,
269,
262,
28673,
335,
1597,
262,
8593,
25339,
262,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
8261,
199,
13,
19395,
63,
751,
26,
8261,
29,
8768,
8261,
63,
1802,
628,
2698,
377,
287,
867,
2,
199,
199,
3,
2790,
282,
922,
199,
13,
19395,
63,
751,
26,
922,
29,
20216,
8261,
29,
8768,
2505,
29,
261,
7564,
199,
199,
3,
14618,
314,
4628,
4719,
370,
314,
5225,
6164,
922,
315,
314,
14779,
8261,
199,
13,
19395,
63,
751,
26,
4719,
29,
2113,
922,
29,
20216,
8261,
29,
8768,
199,
2344,
199,
199,
893,
26,
272,
687,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
199,
2590,
3545,
26,
272,
19395,
1258,
63,
4214,
275,
756,
199,
2836,
26,
272,
19395,
1258,
63,
4214,
275,
715,
421,
199,
318,
12895,
8,
6520,
12,
1526,
12,
4676,
63,
751,
12,
4676,
63,
2060,
12,
4676,
63,
4647,
63,
354,
304,
272,
408,
1767,
282,
19395,
1890,
909,
624,
339,
340,
1526,
26,
267,
372,
1890,
14,
3041,
8,
6520,
29,
6520,
12,
1526,
29,
1418,
9,
272,
587,
26,
267,
372,
1890,
14,
3041,
8,
1178,
63,
633,
29,
6520,
12,
3434,
29,
2886,
63,
751,
12,
2490,
2505,
29,
2886,
63,
2060,
12,
8261,
63,
354,
29,
2886,
63,
4647,
63,
354,
9,
421,
199,
318,
8261,
63,
2444,
8,
19143,
12,
8261,
304,
272,
408,
1432,
715,
340,
8261,
2575,
3495,
624,
272,
372,
8261,
315,
359,
88,
14,
354,
367,
671,
315,
19395,
14,
25021,
14,
513,
5106,
421,
199,
318,
922,
63,
2444,
8,
19143,
12,
922,
304,
272,
408,
2,
1432,
715,
340,
922,
2575,
3495,
624,
272,
372,
922,
315,
359,
88,
14,
354,
367,
671,
315,
19395,
14,
3707,
14,
513,
5106,
421,
199,
318,
664,
63,
4647,
8,
19143,
12,
536,
304,
272,
408,
13939,
282,
8261,
701,
536,
624,
272,
16685,
2285,
275,
359,
88,
367,
671,
315,
19395,
14,
25021,
14,
513,
342,
340,
671,
14,
354,
508,
536,
61,
272,
2338,
275,
822,
8,
25021,
9,
272,
340,
2338,
508,
378,
26,
267,
746,
4067,
480,
1944,
19395,
16685,
2285,
543,
536,
450,
83,
2,
450,
536,
9,
272,
916,
2338,
690,
413,
26,
267,
746,
1722,
3647,
68,
16685,
2285,
543,
536,
450,
83,
2,
450,
334,
835,
12,
536,
430,
272,
587,
26,
267,
372,
16685,
2285,
59,
16,
61,
421,
199,
318,
664,
63,
751,
8,
19143,
12,
536,
304,
272,
408,
13939,
282,
922,
701,
536,
624,
272,
4390,
275,
359,
88,
367,
671,
315,
19395,
14,
3707,
14,
513,
342,
340
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
21311,
641,
1603,
20066,
89,
377,
621,
1159,
4514,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
19395,
63,
751,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
3612,
63,
1802,
26,
14944,
14260,
22034,
334,
19143,
9,
4390,
12,
16685,
2285,
436,
11689,
199,
1802,
26,
2043,
446,
14944,
4390,
12,
25021,
12,
11689,
687,
14260,
14,
199,
1419,
26,
2043,
4676,
63,
751,
26,
1362,
1369,
26,
267,
446,
4676,
3434,
370,
12895,
370,
19395,
1362,
1415,
26,
3055,
1362,
849,
26,
4628,
2043,
4676,
63,
2060,
26,
1362,
1369,
26,
267,
446,
13635,
402,
4676,
922,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
5066,
7,
2043,
4676,
63,
4647,
63,
354,
26,
1362,
1369,
26,
267,
446,
710,
8261,
4676,
63,
751,
15006,
370,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
1362,
1015,
63,
3270,
26,
298,
17,
14,
19,
2,
2043,
1526,
26,
1362,
1369,
26,
267,
446,
710,
1526,
370,
506,
4440,
315,
1930,
314,
2505,
365,
440,
2013,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
6037,
26,
1362,
1369,
26,
267,
446,
710,
19395,
1166,
367,
6299,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1276,
13155,
15,
86,
18,
14,
16,
4805,
2043,
922,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
922,
626,
965,
370,
3483,
15,
10649,
687,
14260,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
2505,
26,
1362,
1369,
26,
267,
446,
710,
2505,
370,
506,
7943,
370,
314,
922,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
8261,
26,
1362,
1369,
26,
267,
446,
710,
8261,
536,
626,
965,
506,
3483,
15,
10649,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
8261,
63,
1802,
26,
1362,
1369,
26,
267,
446,
437,
1369,
367,
314,
8261,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
3031,
26,
1362,
1369,
26,
267,
446,
1626,
3031,
2287,
367,
314,
922,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
4719,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
4719,
370,
506,
7943,
503,
2737,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1174,
26,
1362,
1369,
26,
267,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
1362,
3415,
26,
788,
1881,
297,
283,
5575,
418,
1362,
849,
26,
3451,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
221,
2366,
13,
19143,
1258,
199,
2502,
26,
298,
44,
269,
262,
28673,
335,
1597,
262,
8593,
25339,
262,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
282,
8261,
199,
13,
19395,
63,
751,
26,
8261,
29,
8768,
8261,
63,
1802,
628,
2698,
377,
287,
867,
2,
199,
199,
3,
2790,
282,
922,
199,
13,
19395,
63,
751,
26,
922,
29,
20216,
8261,
29,
8768,
2505,
29,
261,
7564,
199,
199,
3,
14618,
314,
4628,
4719,
370,
314,
5225,
6164,
922,
315,
314,
14779,
8261,
199,
13,
19395,
63,
751,
26,
4719,
29,
2113,
922,
29,
20216,
8261,
29,
8768,
199,
2344,
199,
199,
893,
26,
272,
687,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
199,
2590,
3545,
26,
272,
19395,
1258,
63,
4214,
275,
756,
199,
2836,
26,
272,
19395,
1258,
63,
4214,
275,
715,
421,
199,
318,
12895,
8,
6520,
12,
1526,
12,
4676,
63,
751,
12,
4676,
63,
2060,
12,
4676,
63,
4647,
63,
354,
304,
272,
408,
1767,
282,
19395,
1890,
909,
624,
339,
340,
1526,
26,
267,
372,
1890,
14,
3041,
8,
6520,
29,
6520,
12,
1526,
29,
1418,
9,
272,
587,
26,
267,
372,
1890,
14,
3041,
8,
1178,
63,
633,
29,
6520,
12,
3434,
29,
2886,
63,
751,
12,
2490,
2505,
29,
2886,
63,
2060,
12,
8261,
63,
354,
29,
2886,
63,
4647,
63,
354,
9,
421,
199,
318,
8261,
63,
2444,
8,
19143,
12,
8261,
304,
272,
408,
1432,
715,
340,
8261,
2575,
3495,
624,
272,
372,
8261,
315,
359,
88,
14,
354,
367,
671,
315,
19395,
14,
25021,
14,
513,
5106,
421,
199,
318,
922,
63,
2444,
8,
19143,
12,
922,
304,
272,
408,
2,
1432,
715,
340,
922,
2575,
3495,
624,
272,
372,
922,
315,
359,
88,
14,
354,
367,
671,
315,
19395,
14,
3707,
14,
513,
5106,
421,
199,
318,
664,
63,
4647,
8,
19143,
12,
536,
304,
272,
408,
13939,
282,
8261,
701,
536,
624,
272,
16685,
2285,
275,
359,
88,
367,
671,
315,
19395,
14,
25021,
14,
513,
342,
340,
671,
14,
354,
508,
536,
61,
272,
2338,
275,
822,
8,
25021,
9,
272,
340,
2338,
508,
378,
26,
267,
746,
4067,
480,
1944,
19395,
16685,
2285,
543,
536,
450,
83,
2,
450,
536,
9,
272,
916,
2338,
690,
413,
26,
267,
746,
1722,
3647,
68,
16685,
2285,
543,
536,
450,
83,
2,
450,
334,
835,
12,
536,
430,
272,
587,
26,
267,
372,
16685,
2285,
59,
16,
61,
421,
199,
318,
664,
63,
751,
8,
19143,
12,
536,
304,
272,
408,
13939,
282,
922,
701,
536,
624,
272,
4390,
275,
359,
88,
367,
671,
315,
19395,
14,
3707,
14,
513,
342,
340,
0
] |
[
1,
1,
1,
1,
1,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ittest/run_fluidsynth_tests.py
|
12
|
1094
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# mingus - Music theory Python package, run_fluidsynth_tests module.
# Copyright (C) 2008, Bart Spaans
#
# 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/>.
"""Separated fluidsynth tests.
Remember: you need a running fluidsynth server process listening at port
9800 to pass this test.
"""
import unittest
import test_fluidsynth
suite = unittest.TestSuite([test_fluidsynth.suite()])
unittest.TextTestRunner(verbosity=2).run(suite)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
259,
333,
316,
527,
446,
28919,
9916,
30629,
2018,
2559,
12,
1255,
63,
31515,
9466,
273,
63,
2219,
859,
14,
199,
3,
259,
1898,
334,
35,
9,
9079,
12,
699,
580,
17812,
796,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
20727,
25462,
9466,
273,
2295,
14,
199,
199,
497,
1114,
26,
1265,
1929,
282,
3879,
25462,
9466,
273,
1654,
2112,
22721,
737,
1844,
199,
2905,
383,
370,
986,
642,
511,
14,
199,
624,
199,
199,
646,
2882,
199,
646,
511,
63,
31515,
9466,
273,
199,
5768,
275,
2882,
14,
10591,
779,
396,
63,
31515,
9466,
273,
14,
5768,
9383,
199,
2796,
14,
24285,
8,
9833,
29,
18,
680,
1065,
8,
5768,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
259,
333,
316,
527,
446,
28919,
9916,
30629,
2018,
2559,
12,
1255,
63,
31515,
9466,
273,
63,
2219,
859,
14,
199,
3,
259,
1898,
334,
35,
9,
9079,
12,
699,
580,
17812,
796,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
20727,
25462,
9466,
273,
2295,
14,
199,
199,
497,
1114,
26,
1265,
1929,
282,
3879,
25462,
9466,
273,
1654,
2112,
22721,
737,
1844,
199,
2905,
383,
370,
986,
642,
511,
14,
199,
624,
199,
199,
646,
2882,
199,
646,
511,
63,
31515,
9466,
273,
199,
5768,
275,
2882,
14,
10591,
779,
396,
63,
31515,
9466,
273,
14,
5768,
9383,
199,
2796,
14,
24285,
8,
9833,
29,
18,
680,
1065,
8,
5768,
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,
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
] |
GiovanniConserva/TestDeploy
|
venv/Lib/site-packages/django/conf/locale/tr/formats.py
|
504
|
1141
|
# -*- encoding: utf-8 -*-
# This file is distributed under the same license as the Django package.
#
from __future__ import unicode_literals
# The *_FORMAT strings use the Django date format syntax,
# see http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = 'd F Y'
TIME_FORMAT = 'H:i'
DATETIME_FORMAT = 'd F Y H:i'
YEAR_MONTH_FORMAT = 'F Y'
MONTH_DAY_FORMAT = 'd F'
SHORT_DATE_FORMAT = 'd M Y'
SHORT_DATETIME_FORMAT = 'd M Y H:i'
FIRST_DAY_OF_WEEK = 1 # Pazartesi
# The *_INPUT_FORMATS strings use the Python strftime format syntax,
# see http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_INPUT_FORMATS = [
'%d/%m/%Y', '%d/%m/%y', # '25/10/2006', '25/10/06'
'%y-%m-%d', # '06-10-25'
# '%d %B %Y', '%d %b. %Y', # '25 Ekim 2006', '25 Eki. 2006'
]
DATETIME_INPUT_FORMATS = [
'%d/%m/%Y %H:%M:%S', # '25/10/2006 14:30:59'
'%d/%m/%Y %H:%M:%S.%f', # '25/10/2006 14:30:59.000200'
'%d/%m/%Y %H:%M', # '25/10/2006 14:30'
'%d/%m/%Y', # '25/10/2006'
]
DECIMAL_SEPARATOR = ','
THOUSAND_SEPARATOR = '.'
NUMBER_GROUPING = 3
|
bsd-3-clause
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
7,
199,
12488,
63,
4807,
275,
283,
68,
481,
1488,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
68,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
603,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
603,
1488,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
221,
327,
510,
4651,
285,
266,
338,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
3149,
77,
3149,
57,
297,
1543,
68,
3149,
77,
3149,
89,
297,
258,
327,
283,
821,
15,
709,
15,
7968,
297,
283,
821,
15,
709,
15,
1690,
7,
272,
1543,
89,
3295,
77,
3295,
68,
297,
463,
327,
283,
1690,
13,
709,
13,
821,
7,
272,
327,
1543,
68,
450,
34,
450,
57,
297,
1543,
68,
450,
66,
14,
450,
57,
297,
221,
327,
283,
821,
662,
75,
1017,
8315,
297,
283,
821,
662,
8810,
14,
8315,
7,
199,
61,
199,
12488,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
221,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3149,
77,
3149,
57,
297,
4519,
327,
283,
821,
15,
709,
15,
7968,
7,
199,
61,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
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
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1854,
1334,
314,
2011,
4190,
465,
314,
5634,
2559,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
710,
20841,
4807,
3326,
675,
314,
5634,
1434,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
10372,
12645,
602,
199,
5390,
63,
4807,
275,
283,
68,
481,
1488,
7,
199,
4961,
63,
4807,
275,
283,
40,
26,
73,
7,
199,
12488,
63,
4807,
275,
283,
68,
481,
1488,
869,
26,
73,
7,
199,
19216,
63,
16413,
63,
4807,
275,
283,
38,
1488,
7,
199,
16413,
63,
11655,
63,
4807,
275,
283,
68,
481,
7,
199,
13003,
63,
5390,
63,
4807,
275,
283,
68,
603,
1488,
7,
199,
13003,
63,
12488,
63,
4807,
275,
283,
68,
603,
1488,
869,
26,
73,
7,
199,
12903,
63,
11655,
63,
3359,
63,
24929,
275,
413,
221,
327,
510,
4651,
285,
266,
338,
199,
199,
3,
710,
20841,
7321,
63,
14019,
3326,
675,
314,
2018,
14053,
1475,
6302,
12,
199,
3,
1937,
1455,
921,
4757,
14,
1548,
14,
1308,
15,
4342,
15,
2083,
14,
1360,
3,
6205,
13,
9866,
13,
17537,
199,
5390,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
3149,
77,
3149,
57,
297,
1543,
68,
3149,
77,
3149,
89,
297,
258,
327,
283,
821,
15,
709,
15,
7968,
297,
283,
821,
15,
709,
15,
1690,
7,
272,
1543,
89,
3295,
77,
3295,
68,
297,
463,
327,
283,
1690,
13,
709,
13,
821,
7,
272,
327,
1543,
68,
450,
34,
450,
57,
297,
1543,
68,
450,
66,
14,
450,
57,
297,
221,
327,
283,
821,
662,
75,
1017,
8315,
297,
283,
821,
662,
8810,
14,
8315,
7,
199,
61,
199,
12488,
63,
7321,
63,
14019,
275,
359,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
297,
258,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
2689,
51,
4111,
70,
297,
221,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
1427,
14,
25080,
7,
272,
1543,
68,
3149,
77,
3149,
57,
450,
40,
2689,
45,
297,
263,
327,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
7,
272,
1543,
68,
3149,
77,
3149,
57,
297,
4519,
327,
283,
821,
15,
709,
15,
7968,
7,
199,
61,
199,
23925,
63,
15828,
275,
13647,
199,
28714,
63,
15828,
275,
7815,
199,
9190,
63,
7823,
1206,
275,
650,
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,
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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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
] |
ANR-kamoulox/Telemeta
|
telemeta/models/query.py
|
2
|
21153
|
# -*- coding: utf-8 -*-
# Copyright (C) 2007-2010 Samalyse SARL
# Copyright (C) 2010-2011 Parisson SARL
#
# This file is part of Telemeta.
# 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/>.
#
# Authors: Olivier Guilyardi <olivier@samalyse.com>
# David LIPSZYC <davidlipszyc@gmail.com>
# Guillaume Pellerin <yomguy@parisson.com>
from django.conf import settings
from django.db.models import Q, Max, Min
from telemeta.models.core import *
from telemeta.util.unaccent import unaccent, unaccent_icmp
from telemeta.models.enum import EthnicGroup
import re
engine = settings.DATABASES['default']['ENGINE']
class MediaItemQuerySet(CoreQuerySet):
"Base class for all media item query sets"
def quick_search(self, pattern):
"Perform a quick search on code, title and collector name"
# from telemeta.models.media import MediaItem
# pattern = pattern.strip()
# mod = MediaItem()
# fields = mod.to_dict()
# keys = fields.keys()
# q = self.by_fuzzy_collector_q(pattern)
# for field in keys:
# field_str = str(mod._meta.get_field(field))
# if 'CharField' in field_str or 'TextField' in field_str:
# q = q | word_search_q(field, pattern)
q = (Q(code__contains=pattern) |
Q(old_code__contains=pattern) |
word_search_q('title', pattern) |
word_search_q('comment', pattern) |
self.by_fuzzy_collector_q(pattern))
return self.filter(q)
def without_collection(self):
"Find items which do not belong to any collection"
return self.extra(
where=["collection_id NOT IN (SELECT id FROM media_collections)"])
def by_public_id(self, public_id):
"Find items by public_id"
return self.filter(public_id=public_id)
def by_recording_date(self, from_date, to_date=None):
"Find items by recording date"
if to_date is None:
return (self.filter(recorded_from_date__lte=from_date, recorded_to_date__gte=from_date))
else:
return (self.filter(Q(recorded_from_date__range=(from_date, to_date))
| Q(recorded_to_date__range=(from_date, to_date))))
def by_title(self, pattern):
"Find items by title"
# to (sort of) sync with models.media.MediaItem.get_title()
return self.filter(word_search_q("title", pattern) |
(Q(title="") & word_search_q("collection__title", pattern)))
def by_publish_year(self, from_year, to_year=None):
"Find items by publishing year"
if to_year is None:
to_year = from_year
return self.filter(collection__year_published__range=(from_year, to_year))
def by_change_time(self, from_time=None, until_time=None):
"Find items by last change time"
return self._by_change_time('item', from_time, until_time)
def by_location(self, location):
"Find items by location"
return self.filter(location__in=location.apparented())
@staticmethod
def __name_cmp(obj1, obj2):
return unaccent_icmp(obj1.name, obj2.name)
def locations(self):
from telemeta.models import Location, LocationRelation
l = self.values('location')
c = self.values('location__current_location')
r = LocationRelation.objects.filter(location__in=l).values('ancestor_location')
return Location.objects.filter(Q(pk__in=l) | Q(pk__in=r) | Q(pk__in=c))
def countries(self, group_by_continent=False):
countries = []
from telemeta.models import Location
for id in self.filter(location__isnull=False).values_list('location', flat=True).distinct():
location = Location.objects.get(pk=id)
for l in location.countries():
c = l.current_location
if not c in countries:
countries.append(c)
if group_by_continent:
grouped = {}
for country in countries:
for continent in country.continents():
if not grouped.has_key(continent):
grouped[continent] = []
grouped[continent].append(country)
keys = grouped.keys()
keys.sort(self.__name_cmp)
ordered = []
for c in keys:
grouped[c].sort(self.__name_cmp)
ordered.append({'continent': c, 'countries': grouped[c]})
countries = ordered
else:
countries.sort(self.__name_cmp)
return countries
def virtual(self, *args):
qs = self
need_collection = False
related = []
from telemeta.models import Location
for f in args:
if f == 'apparent_collector':
if not 'sqlite3' in engine and not 'postgresql_psycopg2' in engine:
related.append('collection')
qs = qs.extra(select={f:
'IF(collector_from_collection, '
'IF(media_collections.collector_is_creator, '
'media_collections.creator, '
'media_collections.collector),'
'media_items.collector)'})
elif f == 'country_or_continent':
related.append('location')
if not 'sqlite3' in engine and not 'postgresql_psycopg2' in engine:
qs = qs.extra(select={f:
'IF(locations.type = ' + str(Location.COUNTRY) + ' '
'OR locations.type = ' + str(Location.CONTINENT) + ','
'locations.name, '
'(SELECT l2.name FROM location_relations AS r INNER JOIN locations AS l2 '
'ON r.ancestor_location_id = l2.id '
'WHERE r.location_id = media_items.location_id AND l2.type = ' + str(Location.COUNTRY) + ' LIMIT 1))'
})
else:
raise Exception("Unsupported virtual field: %s" % f)
if related:
qs = qs.select_related(*related)
return qs
def ethnic_groups(self):
ids = self.filter(ethnic_group__isnull=False).values('ethnic_group')
return EthnicGroup.objects.filter(pk__in=ids)
@staticmethod
def by_fuzzy_collector_q(pattern):
return (word_search_q('collection__creator', pattern) |
word_search_q('collection__collector', pattern) |
word_search_q('collector', pattern))
def by_fuzzy_collector(self, pattern):
return self.filter(self.by_fuzzy_collector_q(pattern))
def sound(self):
return self.filter(Q(file__contains='/') | Q(url__contains='/'))
def sound_public(self):
return self.filter(Q(file__contains='/') | Q(url__contains='/'),
public_access='full', collection__public_access='full')
def by_instrument(self, name):
"Find items by instrument"
from telemeta.models.instrument import Instrument, InstrumentAlias
from telemeta.models.item import MediaItemPerformance
instruments = Instrument.objects.filter(name__icontains=name)
aliases = InstrumentAlias.objects.filter(name__icontains=name)
perf = []
performances = MediaItemPerformance.objects.filter(Q(instrument__in=instruments) | Q(alias__in=aliases))
for performance in performances:
perf.append(performance)
return self.filter(performances__in=perf).distinct()
class MediaItemManager(CoreManager):
"Manage media items queries"
def get_queryset(self):
"Return media query sets"
return MediaItemQuerySet(self.model)
def enriched(self):
"Query set with additional virtual fields such as apparent_collector and country_or_continent"
return self.get_queryset().virtual('apparent_collector', 'country_or_continent')
def quick_search(self, *args, **kwargs):
return self.get_queryset().quick_search(*args, **kwargs)
quick_search.__doc__ = MediaItemQuerySet.quick_search.__doc__
def without_collection(self, *args, **kwargs):
return self.get_queryset().without_collection(*args, **kwargs)
without_collection.__doc__ = MediaItemQuerySet.without_collection.__doc__
def by_recording_date(self, *args, **kwargs):
return self.get_queryset().by_recording_date(*args, **kwargs)
by_recording_date.__doc__ = MediaItemQuerySet.by_recording_date.__doc__
def by_title(self, *args, **kwargs):
return self.get_queryset().by_title(*args, **kwargs)
by_title.__doc__ = MediaItemQuerySet.by_title.__doc__
def by_publish_year(self, *args, **kwargs):
return self.get_queryset().by_publish_year(*args, **kwargs)
by_publish_year.__doc__ = MediaItemQuerySet.by_publish_year.__doc__
def by_change_time(self, *args, **kwargs):
return self.get_queryset().by_change_time(*args, **kwargs)
by_change_time.__doc__ = MediaItemQuerySet.by_change_time.__doc__
def by_location(self, *args, **kwargs):
return self.get_queryset().by_location(*args, **kwargs)
by_location.__doc__ = MediaItemQuerySet.by_location.__doc__
def sound(self, *args, **kwargs):
return self.get_queryset().sound(*args, **kwargs)
sound.__doc__ = MediaItemQuerySet.sound.__doc__
def sound_public(self, *args, **kwargs):
return self.get_queryset().sound_public(*args, **kwargs)
sound_public.__doc__ = MediaItemQuerySet.sound_public.__doc__
def by_instrument(self, *args, **kwargs):
return self.get_queryset().by_instrument(*args, **kwargs)
by_instrument.__doc__ = MediaItemQuerySet.by_instrument.__doc__
class MediaCollectionQuerySet(CoreQuerySet):
def quick_search(self, pattern):
"Perform a quick search on code, title and collector name"
from telemeta.models.collection import MediaCollection
pattern = pattern.strip()
mod = MediaCollection()
fields = mod.to_dict()
keys = fields.keys()
q = self.by_fuzzy_collector_q(pattern)
for field in keys:
field_str = repr(MediaCollection._meta.get_field(field))
if 'CharField' in field_str or 'TextField' in field_str:
q = q | word_search_q(field, pattern)
return self.filter(q)
def by_location(self, location):
"Find collections by location"
return self.filter(items__location__in=location.apparented()).distinct()
def by_recording_year(self, from_year, to_year=None):
"Find collections by recording year"
if to_year is None:
return (self.filter(recorded_from_year__lte=from_year, recorded_to_year__gte=from_year))
else:
return (self.filter(Q(recorded_from_year__range=(from_year, to_year)) |
Q(recorded_to_year__range=(from_year, to_year))))
def by_publish_year(self, from_year, to_year=None):
"Find collections by publishing year"
if to_year is None:
to_year = from_year
return self.filter(year_published__range=(from_year, to_year))
def by_ethnic_group(self, group):
"Find collections by ethnic group"
return self.filter(items__ethnic_group=group).distinct()
def by_change_time(self, from_time=None, until_time=None):
"Find collections between two dates"
return self._by_change_time('collection', from_time, until_time)
def virtual(self, *args):
qs = self
for f in args:
if f == 'apparent_collector':
if not 'sqlite3' in engine and not 'postgresql_psycopg2' in engine:
qs = qs.extra(select={f: 'IF(media_collections.collector_is_creator, '
'media_collections.creator, media_collections.collector)'})
else:
raise Exception("Unsupported virtual field: %s" % f)
return qs
def recording_year_range(self):
from_max = self.aggregate(Max('recorded_from_year'))['recorded_from_year__max']
to_max = self.aggregate(Max('recorded_to_year'))['recorded_to_year__max']
year_max = max(from_max, to_max)
from_min = self.filter(recorded_from_year__gt=0).aggregate(Min('recorded_from_year'))['recorded_from_year__min']
to_min = self.filter(recorded_to_year__gt=0).aggregate(Min('recorded_to_year'))['recorded_to_year__min']
year_min = min(from_min, to_min)
if not year_max:
year_max = year_min
elif not year_min:
year_min = year_max
return year_min, year_max
def publishing_year_range(self):
year_max = self.aggregate(Max('year_published'))['year_published__max']
year_min = self.filter(year_published__gt=0).aggregate(Min('year_published'))['year_published__min']
return year_min, year_max
@staticmethod
def by_fuzzy_collector_q(pattern):
return word_search_q('creator', pattern) | word_search_q('collector', pattern)
def by_fuzzy_collector(self, pattern):
return self.filter(self.by_fuzzy_collector_q(pattern))
def sound(self):
return self.filter(Q(items__file__contains='/') | Q(items__url__contains='/')).distinct()
def by_instrument(self, name):
"Find collections by instrument"
from telemeta.models.item import MediaItemPerformance
from telemeta.models.instrument import Instrument, InstrumentAlias
instruments = Instrument.objects.filter(name__icontains=name)
aliases = InstrumentAlias.objects.filter(name__icontains=name)
items = []
performances = MediaItemPerformance.objects.filter(Q(instrument__in=instruments) | Q(alias__in=aliases))
for performance in performances:
items.append(performance.media_item)
return self.filter(items__in=items).distinct()
class MediaCollectionManager(CoreManager):
"Manage collection queries"
def get_queryset(self):
"Return the collection query"
return MediaCollectionQuerySet(self.model)
def enriched(self):
"Query set with additional virtual fields such as apparent_collector"
return self.get_queryset().virtual('apparent_collector')
def quick_search(self, *args, **kwargs):
return self.get_queryset().quick_search(*args, **kwargs)
quick_search.__doc__ = MediaCollectionQuerySet.quick_search.__doc__
def by_location(self, *args, **kwargs):
return self.get_queryset().by_location(*args, **kwargs)
by_location.__doc__ = MediaCollectionQuerySet.by_location.__doc__
def by_recording_year(self, *args, **kwargs):
return self.get_queryset().by_recording_year(*args, **kwargs)
by_recording_year.__doc__ = MediaCollectionQuerySet.by_recording_year.__doc__
def by_publish_year(self, *args, **kwargs):
return self.get_queryset().by_publish_year(*args, **kwargs)
by_publish_year.__doc__ = MediaCollectionQuerySet.by_publish_year.__doc__
def by_ethnic_group(self, *args, **kwargs):
return self.get_queryset().by_ethnic_group(*args, **kwargs)
by_ethnic_group.__doc__ = MediaCollectionQuerySet.by_ethnic_group.__doc__
def by_change_time(self, *args, **kwargs):
return self.get_queryset().by_change_time(*args, **kwargs)
by_change_time.__doc__ = MediaCollectionQuerySet.by_change_time.__doc__
@staticmethod
def __name_cmp(obj1, obj2):
return unaccent_icmp(obj1.name, obj2.name)
def sound(self, *args, **kwargs):
return self.get_queryset().sound(*args, **kwargs)
sound.__doc__ = MediaCollectionQuerySet.sound.__doc__
def by_instrument(self, *args, **kwargs):
return self.get_queryset().by_instrument(*args, **kwargs)
by_instrument.__doc__ = MediaCollectionQuerySet.by_instrument.__doc__
class LocationQuerySet(CoreQuerySet):
__flatname_map = None
def by_flatname(self, flatname):
map = self.flatname_map()
return self.filter(pk=map[flatname])
def flatname_map(self):
if self.__class__.__flatname_map:
return self.__class__.__flatname_map
map = {}
locations = self.filter(Q(type=self.model.COUNTRY) | Q(type=self.model.CONTINENT))
for l in locations:
flatname = unaccent(l.name).lower()
flatname = re.sub('[^a-z]', '_', flatname)
while map.has_key(flatname):
flatname = '_' + flatname
map[flatname] = l.id
self.__class__.__flatname_map = map
return map
def current(self):
return self.filter(id__in=self.values_list('current_location_id', flat=True)).distinct()
class LocationManager(CoreManager):
def get_queryset(self):
"Return location query set"
return LocationQuerySet(self.model)
def by_flatname(self, *args, **kwargs):
return self.get_queryset().by_flatname(*args, **kwargs)
by_flatname.__doc__ = LocationQuerySet.by_flatname.__doc__
def flatname_map(self, *args, **kwargs):
return self.get_queryset().flatname_map(*args, **kwargs)
flatname_map.__doc__ = LocationQuerySet.flatname_map.__doc__
class MediaCorpusQuerySet(CoreQuerySet):
"Base class for all media resource query sets"
def quick_search(self, pattern):
"Perform a quick search on text and char fields"
from telemeta.models.corpus import MediaCorpus
mod = MediaCorpus()
pattern = pattern.strip()
q = Q(code__contains=pattern)
fields = mod.to_dict()
keys = fields.keys()
for field in keys:
field_str = str(mod._meta.get_field(field))
if 'CharField' in field_str or 'TextField' in field_str:
q = q | word_search_q(field, pattern)
return self.filter(q)
class MediaCorpusManager(CoreManager):
"Manage media resource queries"
def get_queryset(self):
"Return resource query sets"
return MediaCorpusQuerySet(self.model)
def quick_search(self, *args, **kwargs):
return self.get_queryset().quick_search(*args, **kwargs)
quick_search.__doc__ = MediaCorpusQuerySet.quick_search.__doc__
class MediaFondsQuerySet(CoreQuerySet):
"Base class for all media resource query sets"
def quick_search(self, pattern):
"Perform a quick search on text and char fields"
from telemeta.models.fonds import MediaFonds
mod = MediaFonds()
pattern = pattern.strip()
q = Q(code__contains=pattern)
fields = mod.to_dict()
keys = fields.keys()
for field in keys:
field_str = str(mod._meta.get_field(field))
if 'CharField' in field_str or 'TextField' in field_str:
q = q | word_search_q(field, pattern)
return self.filter(q)
class MediaFondsManager(CoreManager):
"Manage media resource queries"
def get_queryset(self):
"Return resource query sets"
return MediaFondsQuerySet(self.model)
def quick_search(self, *args, **kwargs):
return self.get_queryset().quick_search(*args, **kwargs)
quick_search.__doc__ = MediaFondsQuerySet.quick_search.__doc__
class InstrumentQuerySet(CoreQuerySet):
"Base class for all media instrument query sets"
def quick_search(self, pattern):
"Perform a quick search on text and char fields"
from telemeta.models.instrument import Instrument
mod = Instrument()
pattern = pattern.strip()
q = Q(code__contains=pattern)
fields = mod.to_dict()
keys = fields.keys()
for field in keys:
field_str = str(mod._meta.get_field(field))
if 'CharField' in field_str or 'TextField' in field_str:
q = q | word_search_q(field, pattern)
return self.filter(q)
class InstrumentManager(CoreManager):
"Manage instrument queries"
def get_queryset(self):
"Return instrument query sets"
return InstrumentQuerySet(self.model)
def quick_search(self, *args, **kwargs):
return self.get_queryset().quick_search(*args, **kwargs)
quick_search.__doc__ = InstrumentQuerySet.quick_search.__doc__
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
35,
9,
10219,
13,
6542,
428,
455,
2618,
261,
428,
689,
44,
199,
3,
1898,
334,
35,
9,
7129,
13,
8128,
2235,
18571,
428,
689,
44,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
23884,
2024,
14,
199,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
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,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
6642,
26,
593,
317,
26645,
12436,
3444,
18980,
665,
23711,
26645,
32,
21660,
2618,
261,
14,
957,
30,
199,
3,
3515,
20232,
491,
12346,
58,
57,
35,
665,
983,
5017,
317,
1190,
3605,
67,
32,
6799,
14,
957,
30,
199,
3,
3515,
12436,
6165,
940,
510,
352,
1435,
262,
665,
89,
676,
6051,
89,
32,
462,
18571,
14,
957,
30,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
12,
8228,
12,
10195,
199,
504,
14001,
2024,
14,
992,
14,
1018,
492,
627,
199,
504,
14001,
2024,
14,
1974,
14,
324,
18028,
492,
625,
18028,
12,
625,
18028,
63,
18799,
199,
504,
14001,
2024,
14,
992,
14,
4869,
492,
662,
273,
12165,
2448,
199,
646,
295,
199,
199,
3908,
275,
2202,
14,
27260,
459,
885,
2545,
15956,
418,
421,
199,
533,
12300,
2081,
13689,
8,
5402,
13689,
304,
272,
298,
1563,
1021,
367,
1006,
5898,
1242,
1827,
5951,
2,
339,
347,
12530,
63,
1733,
8,
277,
12,
3851,
304,
267,
298,
20906,
282,
12530,
2754,
641,
1233,
12,
2538,
436,
14910,
536,
2,
398,
327,
687,
14001,
2024,
14,
992,
14,
4603,
492,
12300,
2081,
267,
327,
3851,
275,
3851,
14,
1913,
342,
267,
327,
3413,
275,
12300,
2081,
342,
267,
327,
1504,
275,
3413,
14,
475,
63,
807,
342,
267,
327,
2883,
275,
221,
1504,
14,
1612,
342,
267,
327,
1894,
275,
291,
14,
991,
63,
24529,
63,
10946,
63,
81,
8,
3401,
9,
267,
327,
367,
901,
315,
2883,
26,
267,
327,
258,
901,
63,
495,
275,
620,
8,
1494,
423,
2024,
14,
362,
63,
698,
8,
698,
430,
267,
327,
258,
340,
283,
2183,
7,
315,
901,
63,
495,
503,
283,
6254,
7,
315,
901,
63,
495,
26,
267,
327,
260,
1894,
275,
1894,
1204,
4349,
63,
1733,
63,
81,
8,
698,
12,
3851,
9,
398,
1894,
275,
334,
49,
8,
600,
363,
6134,
29,
3401,
9,
1204,
1467,
1413,
8,
1753,
63,
600,
363,
6134,
29,
3401,
9,
1204,
1467,
4349,
63,
1733,
63,
81,
360,
1213,
297,
3851,
9,
1204,
1467,
4349,
63,
1733,
63,
81,
360,
3349,
297,
3851,
9,
1204,
1467,
291,
14,
991,
63,
24529,
63,
10946,
63,
81,
8,
3401,
430,
398,
372,
291,
14,
1541,
8,
81,
9,
339,
347,
1928,
63,
3627,
8,
277,
304,
267,
298,
6591,
2974,
1314,
886,
440,
13511,
370,
1263,
3245,
2,
267,
372,
291,
14,
2911,
8,
288,
2382,
6270,
3627,
63,
344,
2845,
1621,
334,
4859,
1305,
4442,
5898,
63,
7882,
2924,
566,
339,
347,
701,
63,
3455,
63,
344,
8,
277,
12,
4575,
63,
344,
304,
267,
298,
6591,
2974,
701,
4575,
63,
344,
2,
267,
372,
291,
14,
1541,
8,
3455,
63,
344,
29,
3455,
63,
344,
9,
339,
347,
701,
63,
24616,
63,
602,
8,
277,
12,
687,
63,
602,
12,
370,
63,
602,
29,
403,
304,
267,
298,
6591,
2974,
701,
20952,
1434,
2,
267,
340,
370,
63,
602,
365,
488,
26,
288,
372,
334,
277,
14,
1541,
8,
264,
15402,
63,
504,
63,
602,
363,
20740,
29,
504,
63,
602,
12,
18894,
63,
475,
63,
602,
363,
19586,
29,
504,
63,
602,
430,
267,
587,
26,
288,
372,
334,
277,
14,
1541,
8,
49,
8,
264,
15402,
63,
504,
63,
602,
363,
1842,
2687,
504,
63,
602,
12,
370,
63,
602,
430,
1816,
1204,
1413,
8,
264,
15402,
63,
475,
63,
602,
363,
1842,
2687,
504,
63,
602,
12,
370,
63,
602,
7845,
339,
347,
701,
63,
1213,
8,
277,
12,
3851,
304,
267,
298,
6591,
2974,
701,
2538,
2,
267,
327,
370,
334,
3191,
402,
9,
7604,
543,
1709,
14,
4603,
14,
11398,
2081,
14,
362,
63,
1213,
342,
267,
372,
291,
14,
1541,
8,
1027,
63,
1733,
63,
81,
480,
1213,
401,
3851,
9,
1204,
2574,
334,
49,
8,
1213,
18413,
1253,
4349,
63,
1733,
63,
81,
480,
3627,
363,
1213,
401,
3851,
1724,
339,
347,
701,
63,
4763,
63,
3403,
8,
277,
12,
687,
63,
3403,
12,
370,
63,
3403,
29,
403,
304,
267,
298,
6591,
2974,
701,
2780,
316,
5361,
2,
267,
340,
370,
63,
3403,
365,
488,
26,
288,
370,
63,
3403,
275,
687,
63,
3403,
267,
372,
291,
14,
1541,
8,
3627,
363,
3403,
63,
8987,
363,
1842,
2687,
504,
63,
3403,
12,
370,
63,
3403,
430,
339,
347,
701,
63,
1461,
63,
521,
8,
277,
12,
687,
63,
521,
29,
403,
12,
5133,
63,
521,
29,
403,
304,
267,
298,
6591,
2974,
701,
2061,
1570,
900,
2,
267,
372,
291,
423,
991,
63,
1461,
63,
521,
360,
1053,
297,
687,
63,
521,
12,
5133,
63,
521,
9,
339,
347,
701,
63,
1985,
8,
277,
12,
2909,
304,
267,
298,
6591,
2974,
701,
2909,
2,
267,
372,
291,
14,
1541,
8,
1985,
363,
262,
29,
1985,
14,
439,
9575,
471,
1012,
339,
768,
4639,
272,
347,
636,
354,
63,
5730,
8,
1113,
17,
12,
1559,
18,
304,
267,
372,
625,
18028,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
35,
9,
10219,
13,
6542,
428,
455,
2618,
261,
428,
689,
44,
199,
3,
1898,
334,
35,
9,
7129,
13,
8128,
2235,
18571,
428,
689,
44,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
23884,
2024,
14,
199,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
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,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
6642,
26,
593,
317,
26645,
12436,
3444,
18980,
665,
23711,
26645,
32,
21660,
2618,
261,
14,
957,
30,
199,
3,
3515,
20232,
491,
12346,
58,
57,
35,
665,
983,
5017,
317,
1190,
3605,
67,
32,
6799,
14,
957,
30,
199,
3,
3515,
12436,
6165,
940,
510,
352,
1435,
262,
665,
89,
676,
6051,
89,
32,
462,
18571,
14,
957,
30,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
14,
992,
492,
1413,
12,
8228,
12,
10195,
199,
504,
14001,
2024,
14,
992,
14,
1018,
492,
627,
199,
504,
14001,
2024,
14,
1974,
14,
324,
18028,
492,
625,
18028,
12,
625,
18028,
63,
18799,
199,
504,
14001,
2024,
14,
992,
14,
4869,
492,
662,
273,
12165,
2448,
199,
646,
295,
199,
199,
3908,
275,
2202,
14,
27260,
459,
885,
2545,
15956,
418,
421,
199,
533,
12300,
2081,
13689,
8,
5402,
13689,
304,
272,
298,
1563,
1021,
367,
1006,
5898,
1242,
1827,
5951,
2,
339,
347,
12530,
63,
1733,
8,
277,
12,
3851,
304,
267,
298,
20906,
282,
12530,
2754,
641,
1233,
12,
2538,
436,
14910,
536,
2,
398,
327,
687,
14001,
2024,
14,
992,
14,
4603,
492,
12300,
2081,
267,
327,
3851,
275,
3851,
14,
1913,
342,
267,
327,
3413,
275,
12300,
2081,
342,
267,
327,
1504,
275,
3413,
14,
475,
63,
807,
342,
267,
327,
2883,
275,
221,
1504,
14,
1612,
342,
267,
327,
1894,
275,
291,
14,
991,
63,
24529,
63,
10946,
63,
81,
8,
3401,
9,
267,
327,
367,
901,
315,
2883,
26,
267,
327,
258,
901,
63,
495,
275,
620,
8,
1494,
423,
2024,
14,
362,
63,
698,
8,
698,
430,
267,
327,
258,
340,
283,
2183,
7,
315,
901,
63,
495,
503,
283,
6254,
7,
315,
901,
63,
495,
26,
267,
327,
260,
1894,
275,
1894,
1204,
4349,
63,
1733,
63,
81,
8,
698,
12,
3851,
9,
398,
1894,
275,
334,
49,
8,
600,
363,
6134,
29,
3401,
9,
1204,
1467,
1413,
8,
1753,
63,
600,
363,
6134,
29,
3401,
9,
1204,
1467,
4349,
63,
1733,
63,
81,
360,
1213,
297,
3851,
9,
1204,
1467,
4349,
63,
1733,
63,
81,
360,
3349,
297,
3851,
9,
1204,
1467,
291,
14,
991,
63,
24529,
63,
10946,
63,
81,
8,
3401,
430,
398,
372,
291,
14,
1541,
8,
81,
9,
339,
347,
1928,
63,
3627,
8,
277,
304,
267,
298,
6591,
2974,
1314,
886,
440,
13511,
370,
1263,
3245,
2,
267,
372,
291,
14,
2911,
8,
288,
2382,
6270,
3627,
63,
344,
2845,
1621,
334,
4859,
1305,
4442,
5898,
63,
7882,
2924,
566,
339,
347,
701,
63,
3455,
63,
344,
8,
277,
12,
4575,
63,
344,
304,
267,
298,
6591,
2974,
701,
4575,
63,
344,
2,
267,
372,
291,
14,
1541,
8,
3455,
63,
344,
29,
3455,
63,
344,
9,
339,
347,
701,
63,
24616,
63,
602,
8,
277,
12,
687,
63,
602,
12,
370,
63,
602,
29,
403,
304,
267,
298,
6591,
2974,
701,
20952,
1434,
2,
267,
340,
370,
63,
602,
365,
488,
26,
288,
372,
334,
277,
14,
1541,
8,
264,
15402,
63,
504,
63,
602,
363,
20740,
29,
504,
63,
602,
12,
18894,
63,
475,
63,
602,
363,
19586,
29,
504,
63,
602,
430,
267,
587,
26,
288,
372,
334,
277,
14,
1541,
8,
49,
8,
264,
15402,
63,
504,
63,
602,
363,
1842,
2687,
504,
63,
602,
12,
370,
63,
602,
430,
1816,
1204,
1413,
8,
264,
15402,
63,
475,
63,
602,
363,
1842,
2687,
504,
63,
602,
12,
370,
63,
602,
7845,
339,
347,
701,
63,
1213,
8,
277,
12,
3851,
304,
267,
298,
6591,
2974,
701,
2538,
2,
267,
327,
370,
334,
3191,
402,
9,
7604,
543,
1709,
14,
4603,
14,
11398,
2081,
14,
362,
63,
1213,
342,
267,
372,
291,
14,
1541,
8,
1027,
63,
1733,
63,
81,
480,
1213,
401,
3851,
9,
1204,
2574,
334,
49,
8,
1213,
18413,
1253,
4349,
63,
1733,
63,
81,
480,
3627,
363,
1213,
401,
3851,
1724,
339,
347,
701,
63,
4763,
63,
3403,
8,
277,
12,
687,
63,
3403,
12,
370,
63,
3403,
29,
403,
304,
267,
298,
6591,
2974,
701,
2780,
316,
5361,
2,
267,
340,
370,
63,
3403,
365,
488,
26,
288,
370,
63,
3403,
275,
687,
63,
3403,
267,
372,
291,
14,
1541,
8,
3627,
363,
3403,
63,
8987,
363,
1842,
2687,
504,
63,
3403,
12,
370,
63,
3403,
430,
339,
347,
701,
63,
1461,
63,
521,
8,
277,
12,
687,
63,
521,
29,
403,
12,
5133,
63,
521,
29,
403,
304,
267,
298,
6591,
2974,
701,
2061,
1570,
900,
2,
267,
372,
291,
423,
991,
63,
1461,
63,
521,
360,
1053,
297,
687,
63,
521,
12,
5133,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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
] |
franga2000/django-machina
|
machina/apps/forum_moderation/app.py
|
2
|
2945
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import url
from django.utils.translation import ugettext_lazy as _
from machina.core.app import Application
from machina.core.loading import get_class
class ModerationApp(Application):
name = 'forum_moderation'
topic_lock_view = get_class('forum_moderation.views', 'TopicLockView')
topic_unlock_view = get_class('forum_moderation.views', 'TopicUnlockView')
topic_delete_view = get_class('forum_moderation.views', 'TopicDeleteView')
topic_move_view = get_class('forum_moderation.views', 'TopicMoveView')
topic_update_to_normal_topic_view = get_class(
'forum_moderation.views', 'TopicUpdateToNormalTopicView')
topic_update_to_sticky_topic_view = get_class(
'forum_moderation.views', 'TopicUpdateToStickyTopicView')
topic_update_to_announce_view = get_class('forum_moderation.views', 'TopicUpdateToAnnounceView')
moderation_queue_list_view = get_class('forum_moderation.views', 'ModerationQueueListView')
moderation_queue_detail_view = get_class('forum_moderation.views', 'ModerationQueueDetailView')
post_approve_view = get_class('forum_moderation.views', 'PostApproveView')
post_disapprove_view = get_class('forum_moderation.views', 'PostDisapproveView')
def get_urls(self):
return [
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/lock/$'),
self.topic_lock_view.as_view(), name='topic_lock'),
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/unlock/$'),
self.topic_unlock_view.as_view(), name='topic_unlock'),
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/delete/$'),
self.topic_delete_view.as_view(), name='topic_delete'),
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/move/$'),
self.topic_move_view.as_view(), name='topic_move'),
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/change/topic/$'),
self.topic_update_to_normal_topic_view.as_view(), name='topic_update_to_post'),
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/change/sticky/$'),
self.topic_update_to_sticky_topic_view.as_view(), name='topic_update_to_sticky'),
url(_(r'^topic/(?P<slug>[\w-]+)-(?P<pk>\d+)/change/announce/$'),
self.topic_update_to_announce_view.as_view(), name='topic_update_to_announce'),
url(_(r'^queue/$'), self.moderation_queue_list_view.as_view(), name='queue'),
url(_(r'^queue/(?P<pk>\d+)/$'),
self.moderation_queue_detail_view.as_view(), name='queued_post'),
url(_(r'^queue/(?P<pk>\d+)/approve/$'),
self.post_approve_view.as_view(), name='approve_queued_post'),
url(_(r'^queue/(?P<pk>\d+)/disapprove/$'),
self.post_disapprove_view.as_view(), name='disapprove_queued_post'),
]
application = ModerationApp()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
14401,
13765,
14,
1018,
14,
571,
492,
13515,
199,
504,
14401,
13765,
14,
1018,
14,
8786,
492,
664,
63,
533,
421,
199,
533,
4900,
1754,
2640,
8,
5039,
304,
272,
536,
275,
283,
10044,
63,
632,
1754,
7,
339,
7482,
63,
831,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
6432,
2768,
358,
272,
7482,
63,
17966,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
1358,
831,
2768,
358,
272,
7482,
63,
1807,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
5392,
2768,
358,
272,
7482,
63,
1185,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
10370,
2768,
358,
272,
7482,
63,
873,
63,
475,
63,
3302,
63,
5746,
63,
1345,
275,
664,
63,
533,
8,
267,
283,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
4152,
1378,
6241,
12157,
2768,
358,
272,
7482,
63,
873,
63,
475,
63,
27364,
63,
5746,
63,
1345,
275,
664,
63,
533,
8,
267,
283,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
4152,
1378,
51,
8284,
89,
12157,
2768,
358,
272,
7482,
63,
873,
63,
475,
63,
17803,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
4152,
1378,
2493,
13348,
2768,
358,
272,
818,
1754,
63,
1825,
63,
513,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
1385,
1754,
3737,
23239,
358,
272,
818,
1754,
63,
1825,
63,
5506,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
1385,
1754,
3737,
28539,
358,
272,
2963,
63,
29886,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
6564,
25923,
432,
2768,
358,
272,
2963,
63,
2297,
29886,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
6564,
2825,
29886,
2768,
358,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
372,
359,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
831,
21792,
659,
355,
291,
14,
5746,
63,
831,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
831,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
17966,
21792,
659,
355,
291,
14,
5746,
63,
17966,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
17966,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1807,
21792,
659,
355,
291,
14,
5746,
63,
1807,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
1807,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1185,
21792,
659,
355,
291,
14,
5746,
63,
1185,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
1185,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1461,
15,
5746,
21792,
659,
355,
291,
14,
5746,
63,
873,
63,
475,
63,
3302,
63,
5746,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
873,
63,
475,
63,
1932,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1461,
15,
27364,
21792,
659,
355,
291,
14,
5746,
63,
873,
63,
475,
63,
27364,
63,
5746,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
873,
63,
475,
63,
27364,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1461,
15,
17803,
21792,
659,
355,
291,
14,
5746,
63,
873,
63,
475,
63,
17803,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
873,
63,
475,
63,
17803,
659,
288,
1166,
27594,
82,
4289,
1825,
21792,
659,
291,
14,
632,
1754,
63,
1825,
63,
513,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1825,
659,
288,
1166,
27594,
82,
4289,
1825,
9448,
48,
28,
2051,
3072,
68,
18830,
26712,
355,
291,
14,
632,
1754,
63,
1825,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
14268,
63,
1932,
659,
288,
1166,
27594,
82,
4289,
1825,
9448,
48,
28,
2051,
3072,
68,
18830,
29886,
21792,
659,
355,
291,
14,
1932,
63,
29886,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
29886,
63,
14268,
63,
1932,
659,
288,
1166,
27594,
82,
4289,
1825,
9448,
48,
28,
2051,
3072,
68,
18830,
2297,
29886,
21792,
659,
355,
291,
14,
1932,
63,
2297,
29886,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
2297,
29886,
63,
14268,
63,
1932,
659,
267,
1622,
421,
199,
3578,
275,
4900,
1754,
2640,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
14401,
13765,
14,
1018,
14,
571,
492,
13515,
199,
504,
14401,
13765,
14,
1018,
14,
8786,
492,
664,
63,
533,
421,
199,
533,
4900,
1754,
2640,
8,
5039,
304,
272,
536,
275,
283,
10044,
63,
632,
1754,
7,
339,
7482,
63,
831,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
6432,
2768,
358,
272,
7482,
63,
17966,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
1358,
831,
2768,
358,
272,
7482,
63,
1807,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
5392,
2768,
358,
272,
7482,
63,
1185,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
10370,
2768,
358,
272,
7482,
63,
873,
63,
475,
63,
3302,
63,
5746,
63,
1345,
275,
664,
63,
533,
8,
267,
283,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
4152,
1378,
6241,
12157,
2768,
358,
272,
7482,
63,
873,
63,
475,
63,
27364,
63,
5746,
63,
1345,
275,
664,
63,
533,
8,
267,
283,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
4152,
1378,
51,
8284,
89,
12157,
2768,
358,
272,
7482,
63,
873,
63,
475,
63,
17803,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
12157,
4152,
1378,
2493,
13348,
2768,
358,
272,
818,
1754,
63,
1825,
63,
513,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
1385,
1754,
3737,
23239,
358,
272,
818,
1754,
63,
1825,
63,
5506,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
1385,
1754,
3737,
28539,
358,
272,
2963,
63,
29886,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
6564,
25923,
432,
2768,
358,
272,
2963,
63,
2297,
29886,
63,
1345,
275,
664,
63,
533,
360,
10044,
63,
632,
1754,
14,
4196,
297,
283,
6564,
2825,
29886,
2768,
358,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
372,
359,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
831,
21792,
659,
355,
291,
14,
5746,
63,
831,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
831,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
17966,
21792,
659,
355,
291,
14,
5746,
63,
17966,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
17966,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1807,
21792,
659,
355,
291,
14,
5746,
63,
1807,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
1807,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1185,
21792,
659,
355,
291,
14,
5746,
63,
1185,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
1185,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1461,
15,
5746,
21792,
659,
355,
291,
14,
5746,
63,
873,
63,
475,
63,
3302,
63,
5746,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
873,
63,
475,
63,
1932,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1461,
15,
27364,
21792,
659,
355,
291,
14,
5746,
63,
873,
63,
475,
63,
27364,
63,
5746,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
873,
63,
475,
63,
27364,
659,
288,
1166,
27594,
82,
4289,
5746,
9448,
48,
28,
5464,
24693,
87,
20253,
7216,
2229,
48,
28,
2051,
3072,
68,
18830,
1461,
15,
17803,
21792,
659,
355,
291,
14,
5746,
63,
873,
63,
475,
63,
17803,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
5746,
63,
873,
63,
475,
63,
17803,
659,
288,
1166,
27594,
82,
4289,
1825,
21792,
659,
291,
14,
632,
1754,
63,
1825,
63,
513,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
1825,
659,
288,
1166,
27594,
82,
4289,
1825,
9448,
48,
28,
2051,
3072,
68,
18830,
26712,
355,
291,
14,
632,
1754,
63,
1825,
63,
5506,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
14268,
63,
1932,
659,
288,
1166,
27594,
82,
4289,
1825,
9448,
48,
28,
2051,
3072,
68,
18830,
29886,
21792,
659,
355,
291,
14,
1932,
63,
29886,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
29886,
63,
14268,
63,
1932,
659,
288,
1166,
27594,
82,
4289,
1825,
9448,
48,
28,
2051,
3072,
68,
18830,
2297,
29886,
21792,
659,
355,
291,
14,
1932,
63,
2297,
29886,
63,
1345,
14,
305,
63,
1345,
1062,
536,
534,
2297,
29886,
63,
14268,
63,
1932,
659,
267,
1622,
421,
199,
3578,
275,
4900,
1754,
2640,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
andersgs/dingo
|
dingo/random_forest.py
|
1
|
2551
|
'''
Some functions to fit a random forest
'''
import sklearn.ensemble
import pandas
import progressbar
bar = progressbar.ProgressBar()
def test_max_features(max_features):
if (max_features not in ['sqrt', 'auto', 'log2', None]):
try:
max_features = int(max_features)
except ValueError:
print("max_features has to be an integer or one of 'sqrt', 'auto', 'log2' or None.")
raise
return max_features
def learn(X,y, n_trees = 10, criterion = 'entropy', max_features = "sqrt", max_depth = None, min_samples_split = 2, min_samples_leaf = 1, min_weight_fraction_leaf = 0, max_leaf_nodes = None, min_impurity_split = 1e-7, bootstrap = False, oob_score = False, n_jobs = 10, random_state = None, warm_start = False, class_weight = 'balanced_subsample'):
rf = sklearn.ensemble.RandomForestClassifier(n_estimators = n_trees, \
criterion = criterion, \
max_features = max_features, \
max_depth = max_depth, \
min_samples_split = min_samples_split, \
min_samples_leaf = min_samples_leaf, \
min_weight_fraction_leaf = min_weight_fraction_leaf, \
max_leaf_nodes = max_leaf_nodes, \
min_impurity_split = min_impurity_split, \
bootstrap = bootstrap, \
oob_score = oob_score, \
n_jobs = n_jobs, \
random_state = random_state, \
warm_start = warm_start, \
class_weight = class_weight, \
verbose = 1
)
rf.fit(X, y)
return rf
def importance(rf, kmers):
importance = rf.estimators_[0].feature_importances_
for est in bar(rf.estimators_[1:]):
importance += est.feature_importances_
importance = importance/rf.n_estimators
d = {"kmer": kmers,
"importance": importance}
d = pandas.DataFrame(d)
d = d.sort_values(by = "importance", ascending = 0)
d = d.loc[d.importance > 0]
return d
|
bsd-3-clause
|
[
2344,
199,
7700,
3423,
370,
5542,
282,
2196,
27882,
199,
2344,
199,
199,
646,
6357,
14,
15628,
199,
646,
10634,
199,
646,
6696,
1700,
199,
199,
1700,
275,
6696,
1700,
14,
11504,
5281,
342,
199,
199,
318,
511,
63,
988,
63,
3179,
8,
988,
63,
3179,
304,
272,
340,
334,
988,
63,
3179,
440,
315,
788,
5079,
297,
283,
2495,
297,
283,
793,
18,
297,
488,
4682,
267,
862,
26,
288,
1390,
63,
3179,
275,
1109,
8,
988,
63,
3179,
9,
267,
871,
1722,
26,
288,
870,
480,
988,
63,
3179,
965,
370,
506,
376,
3000,
503,
1373,
402,
283,
5079,
297,
283,
2495,
297,
283,
793,
18,
7,
503,
488,
2685,
288,
746,
272,
372,
1390,
63,
3179,
199,
199,
318,
12537,
8,
56,
12,
89,
12,
302,
63,
14635,
275,
1616,
12,
17392,
275,
283,
10435,
297,
1390,
63,
3179,
275,
298,
5079,
401,
1390,
63,
4631,
275,
488,
12,
1748,
63,
3356,
63,
1294,
275,
499,
12,
1748,
63,
3356,
63,
8914,
275,
413,
12,
1748,
63,
3463,
63,
13054,
63,
8914,
275,
378,
12,
1390,
63,
8914,
63,
2415,
275,
488,
12,
1748,
63,
3236,
5581,
63,
1294,
275,
413,
69,
13,
23,
12,
15865,
275,
756,
12,
312,
2873,
63,
3397,
275,
756,
12,
302,
63,
6920,
275,
1616,
12,
2196,
63,
929,
275,
488,
12,
20060,
63,
928,
275,
756,
12,
1021,
63,
3463,
275,
283,
18923,
63,
954,
3271,
735,
272,
17781,
275,
6357,
14,
15628,
14,
3883,
21668,
8508,
8,
78,
63,
10646,
275,
302,
63,
14635,
12,
971,
6059,
17392,
275,
17392,
12,
971,
6059,
1390,
63,
3179,
275,
1390,
63,
3179,
12,
971,
6059,
1390,
63,
4631,
275,
1390,
63,
4631,
12,
971,
6059,
1748,
63,
3356,
63,
1294,
275,
1748,
63,
3356,
63,
1294,
12,
971,
6059,
1748,
63,
3356,
63,
8914,
275,
1748,
63,
3356,
63,
8914,
12,
971,
6059,
1748,
63,
3463,
63,
13054,
63,
8914,
275,
1748,
63,
3463,
63,
13054,
63,
8914,
12,
971,
6059,
1390,
63,
8914,
63,
2415,
275,
1390,
63,
8914,
63,
2415,
12,
971,
6059,
1748,
63,
3236,
5581,
63,
1294,
275,
1748,
63,
3236,
5581,
63,
1294,
12,
971,
6059,
15865,
275,
15865,
12,
971,
6059,
312,
2873,
63,
3397,
275,
312,
2873,
63,
3397,
12,
971,
6059,
302,
63,
6920,
275,
302,
63,
6920,
12,
971,
6059,
2196,
63,
929,
275,
2196,
63,
929,
12,
971,
6059,
20060,
63,
928,
275,
20060,
63,
928,
12,
971,
6059,
1021,
63,
3463,
275,
1021,
63,
3463,
12,
971,
6059,
3376,
275,
413,
6059,
776,
272,
17781,
14,
3269,
8,
56,
12,
612,
9,
272,
372,
17781,
199,
199,
318,
492,
554,
8,
3941,
12,
1022,
16465,
304,
272,
492,
554,
275,
17781,
14,
10646,
9925,
16,
1055,
4445,
63,
646,
13236,
63,
272,
367,
4347,
315,
4681,
8,
3941,
14,
10646,
9925,
17,
28847,
267,
492,
554,
847,
4347,
14,
4445,
63,
646,
13236,
63,
272,
492,
554,
275,
492,
554,
15,
3941,
14,
78,
63,
10646,
272,
366,
275,
2420,
75,
2626,
582,
1022,
16465,
12,
267,
298,
646,
554,
582,
492,
554,
93,
272,
366,
275,
10634,
14,
9205,
8,
68,
9,
272,
366,
275,
366,
14,
3191,
63,
1459,
8,
991,
275,
298,
646,
554,
401,
24525,
275,
378,
9,
272,
366,
275,
366,
14,
2102,
59,
68,
14,
646,
554,
690,
378,
61,
272,
372,
366,
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
] |
[
199,
7700,
3423,
370,
5542,
282,
2196,
27882,
199,
2344,
199,
199,
646,
6357,
14,
15628,
199,
646,
10634,
199,
646,
6696,
1700,
199,
199,
1700,
275,
6696,
1700,
14,
11504,
5281,
342,
199,
199,
318,
511,
63,
988,
63,
3179,
8,
988,
63,
3179,
304,
272,
340,
334,
988,
63,
3179,
440,
315,
788,
5079,
297,
283,
2495,
297,
283,
793,
18,
297,
488,
4682,
267,
862,
26,
288,
1390,
63,
3179,
275,
1109,
8,
988,
63,
3179,
9,
267,
871,
1722,
26,
288,
870,
480,
988,
63,
3179,
965,
370,
506,
376,
3000,
503,
1373,
402,
283,
5079,
297,
283,
2495,
297,
283,
793,
18,
7,
503,
488,
2685,
288,
746,
272,
372,
1390,
63,
3179,
199,
199,
318,
12537,
8,
56,
12,
89,
12,
302,
63,
14635,
275,
1616,
12,
17392,
275,
283,
10435,
297,
1390,
63,
3179,
275,
298,
5079,
401,
1390,
63,
4631,
275,
488,
12,
1748,
63,
3356,
63,
1294,
275,
499,
12,
1748,
63,
3356,
63,
8914,
275,
413,
12,
1748,
63,
3463,
63,
13054,
63,
8914,
275,
378,
12,
1390,
63,
8914,
63,
2415,
275,
488,
12,
1748,
63,
3236,
5581,
63,
1294,
275,
413,
69,
13,
23,
12,
15865,
275,
756,
12,
312,
2873,
63,
3397,
275,
756,
12,
302,
63,
6920,
275,
1616,
12,
2196,
63,
929,
275,
488,
12,
20060,
63,
928,
275,
756,
12,
1021,
63,
3463,
275,
283,
18923,
63,
954,
3271,
735,
272,
17781,
275,
6357,
14,
15628,
14,
3883,
21668,
8508,
8,
78,
63,
10646,
275,
302,
63,
14635,
12,
971,
6059,
17392,
275,
17392,
12,
971,
6059,
1390,
63,
3179,
275,
1390,
63,
3179,
12,
971,
6059,
1390,
63,
4631,
275,
1390,
63,
4631,
12,
971,
6059,
1748,
63,
3356,
63,
1294,
275,
1748,
63,
3356,
63,
1294,
12,
971,
6059,
1748,
63,
3356,
63,
8914,
275,
1748,
63,
3356,
63,
8914,
12,
971,
6059,
1748,
63,
3463,
63,
13054,
63,
8914,
275,
1748,
63,
3463,
63,
13054,
63,
8914,
12,
971,
6059,
1390,
63,
8914,
63,
2415,
275,
1390,
63,
8914,
63,
2415,
12,
971,
6059,
1748,
63,
3236,
5581,
63,
1294,
275,
1748,
63,
3236,
5581,
63,
1294,
12,
971,
6059,
15865,
275,
15865,
12,
971,
6059,
312,
2873,
63,
3397,
275,
312,
2873,
63,
3397,
12,
971,
6059,
302,
63,
6920,
275,
302,
63,
6920,
12,
971,
6059,
2196,
63,
929,
275,
2196,
63,
929,
12,
971,
6059,
20060,
63,
928,
275,
20060,
63,
928,
12,
971,
6059,
1021,
63,
3463,
275,
1021,
63,
3463,
12,
971,
6059,
3376,
275,
413,
6059,
776,
272,
17781,
14,
3269,
8,
56,
12,
612,
9,
272,
372,
17781,
199,
199,
318,
492,
554,
8,
3941,
12,
1022,
16465,
304,
272,
492,
554,
275,
17781,
14,
10646,
9925,
16,
1055,
4445,
63,
646,
13236,
63,
272,
367,
4347,
315,
4681,
8,
3941,
14,
10646,
9925,
17,
28847,
267,
492,
554,
847,
4347,
14,
4445,
63,
646,
13236,
63,
272,
492,
554,
275,
492,
554,
15,
3941,
14,
78,
63,
10646,
272,
366,
275,
2420,
75,
2626,
582,
1022,
16465,
12,
267,
298,
646,
554,
582,
492,
554,
93,
272,
366,
275,
10634,
14,
9205,
8,
68,
9,
272,
366,
275,
366,
14,
3191,
63,
1459,
8,
991,
275,
298,
646,
554,
401,
24525,
275,
378,
9,
272,
366,
275,
366,
14,
2102,
59,
68,
14,
646,
554,
690,
378,
61,
272,
372,
366,
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,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
william-richard/moto
|
tests/test_ec2/test_internet_gateways.py
|
2
|
9612
|
from __future__ import unicode_literals
import pytest
import re
import boto
import boto3
from boto.exception import EC2ResponseError
import sure # noqa
from moto import mock_ec2_deprecated, mock_ec2
VPC_CIDR = "10.0.0.0/16"
BAD_VPC = "vpc-deadbeef"
BAD_IGW = "igw-deadbeef"
@mock_ec2_deprecated
def test_igw_create():
""" internet gateway create """
conn = boto.connect_vpc("the_key", "the_secret")
conn.get_all_internet_gateways().should.have.length_of(0)
with pytest.raises(EC2ResponseError) as ex:
igw = conn.create_internet_gateway(dry_run=True)
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the CreateInternetGateway operation: Request would have succeeded, but DryRun flag is set"
)
igw = conn.create_internet_gateway()
conn.get_all_internet_gateways().should.have.length_of(1)
igw.id.should.match(r"igw-[0-9a-f]+")
igw = conn.get_all_internet_gateways()[0]
igw.attachments.should.have.length_of(0)
@mock_ec2_deprecated
def test_igw_attach():
""" internet gateway attach """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
with pytest.raises(EC2ResponseError) as ex:
conn.attach_internet_gateway(igw.id, vpc.id, dry_run=True)
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the AttachInternetGateway operation: Request would have succeeded, but DryRun flag is set"
)
conn.attach_internet_gateway(igw.id, vpc.id)
igw = conn.get_all_internet_gateways()[0]
igw.attachments[0].vpc_id.should.be.equal(vpc.id)
@mock_ec2_deprecated
def test_igw_attach_bad_vpc():
""" internet gateway fail to attach w/ bad vpc """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
with pytest.raises(EC2ResponseError) as cm:
conn.attach_internet_gateway(igw.id, BAD_VPC)
cm.value.code.should.equal("InvalidVpcID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_attach_twice():
""" internet gateway fail to attach twice """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc1 = conn.create_vpc(VPC_CIDR)
vpc2 = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw.id, vpc1.id)
with pytest.raises(EC2ResponseError) as cm:
conn.attach_internet_gateway(igw.id, vpc2.id)
cm.value.code.should.equal("Resource.AlreadyAssociated")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_detach():
""" internet gateway detach"""
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw.id, vpc.id)
with pytest.raises(EC2ResponseError) as ex:
conn.detach_internet_gateway(igw.id, vpc.id, dry_run=True)
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the DetachInternetGateway operation: Request would have succeeded, but DryRun flag is set"
)
conn.detach_internet_gateway(igw.id, vpc.id)
igw = conn.get_all_internet_gateways()[0]
igw.attachments.should.have.length_of(0)
@mock_ec2_deprecated
def test_igw_detach_wrong_vpc():
""" internet gateway fail to detach w/ wrong vpc """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc1 = conn.create_vpc(VPC_CIDR)
vpc2 = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw.id, vpc1.id)
with pytest.raises(EC2ResponseError) as cm:
conn.detach_internet_gateway(igw.id, vpc2.id)
cm.value.code.should.equal("Gateway.NotAttached")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_detach_invalid_vpc():
""" internet gateway fail to detach w/ invalid vpc """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw.id, vpc.id)
with pytest.raises(EC2ResponseError) as cm:
conn.detach_internet_gateway(igw.id, BAD_VPC)
cm.value.code.should.equal("Gateway.NotAttached")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_detach_unattached():
""" internet gateway fail to detach unattached """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
with pytest.raises(EC2ResponseError) as cm:
conn.detach_internet_gateway(igw.id, vpc.id)
cm.value.code.should.equal("Gateway.NotAttached")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_delete():
""" internet gateway delete"""
conn = boto.connect_vpc("the_key", "the_secret")
vpc = conn.create_vpc(VPC_CIDR)
conn.get_all_internet_gateways().should.have.length_of(0)
igw = conn.create_internet_gateway()
conn.get_all_internet_gateways().should.have.length_of(1)
with pytest.raises(EC2ResponseError) as ex:
conn.delete_internet_gateway(igw.id, dry_run=True)
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the DeleteInternetGateway operation: Request would have succeeded, but DryRun flag is set"
)
conn.delete_internet_gateway(igw.id)
conn.get_all_internet_gateways().should.have.length_of(0)
@mock_ec2_deprecated
def test_igw_delete_attached():
""" internet gateway fail to delete attached """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw.id, vpc.id)
with pytest.raises(EC2ResponseError) as cm:
conn.delete_internet_gateway(igw.id)
cm.value.code.should.equal("DependencyViolation")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_desribe():
""" internet gateway fetch by id """
conn = boto.connect_vpc("the_key", "the_secret")
igw = conn.create_internet_gateway()
igw_by_search = conn.get_all_internet_gateways([igw.id])[0]
igw.id.should.equal(igw_by_search.id)
@mock_ec2_deprecated
def test_igw_describe_bad_id():
""" internet gateway fail to fetch by bad id """
conn = boto.connect_vpc("the_key", "the_secret")
with pytest.raises(EC2ResponseError) as cm:
conn.get_all_internet_gateways([BAD_IGW])
cm.value.code.should.equal("InvalidInternetGatewayID.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_filter_by_vpc_id():
""" internet gateway filter by vpc id """
conn = boto.connect_vpc("the_key", "the_secret")
igw1 = conn.create_internet_gateway()
igw2 = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw1.id, vpc.id)
result = conn.get_all_internet_gateways(filters={"attachment.vpc-id": vpc.id})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)
@mock_ec2_deprecated
def test_igw_filter_by_tags():
""" internet gateway filter by vpc id """
conn = boto.connect_vpc("the_key", "the_secret")
igw1 = conn.create_internet_gateway()
igw2 = conn.create_internet_gateway()
igw1.add_tag("tests", "yes")
result = conn.get_all_internet_gateways(filters={"tag:tests": "yes"})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)
@mock_ec2_deprecated
def test_igw_filter_by_internet_gateway_id():
""" internet gateway filter by internet gateway id """
conn = boto.connect_vpc("the_key", "the_secret")
igw1 = conn.create_internet_gateway()
igw2 = conn.create_internet_gateway()
result = conn.get_all_internet_gateways(filters={"internet-gateway-id": igw1.id})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)
@mock_ec2_deprecated
def test_igw_filter_by_attachment_state():
""" internet gateway filter by attachment state """
conn = boto.connect_vpc("the_key", "the_secret")
igw1 = conn.create_internet_gateway()
igw2 = conn.create_internet_gateway()
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw1.id, vpc.id)
result = conn.get_all_internet_gateways(filters={"attachment.state": "available"})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)
@mock_ec2
def test_create_internet_gateway_with_tags():
ec2 = boto3.resource("ec2", region_name="eu-central-1")
igw = ec2.create_internet_gateway(
TagSpecifications=[
{
"ResourceType": "internet-gateway",
"Tags": [{"Key": "test", "Value": "TestRouteTable"}],
}
],
)
igw.tags.should.have.length_of(1)
igw.tags.should.equal([{"Key": "test", "Value": "TestRouteTable"}])
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
4613,
199,
199,
646,
295,
199,
199,
646,
6055,
199,
646,
6055,
19,
199,
199,
504,
6055,
14,
1971,
492,
15352,
18,
19712,
199,
199,
646,
3238,
221,
327,
8151,
199,
199,
504,
333,
3459,
492,
1683,
63,
825,
18,
63,
6667,
12,
1683,
63,
825,
18,
421,
199,
54,
4222,
63,
35,
22052,
275,
298,
709,
14,
16,
14,
16,
14,
16,
15,
975,
2,
199,
9439,
63,
54,
4222,
275,
298,
11742,
13,
10957,
19446,
70,
2,
199,
9439,
63,
1277,
55,
275,
298,
528,
87,
13,
10957,
19446,
70,
2,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
981,
837,
272,
408,
21408,
10391,
1218,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
339,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
1252,
5626,
14,
7804,
14,
1267,
63,
1618,
8,
16,
9,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
444,
26,
267,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
8,
10481,
63,
1065,
29,
549,
9,
272,
444,
14,
585,
14,
705,
63,
600,
14,
5626,
14,
1452,
480,
36,
651,
2540,
6044,
531,
272,
444,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
444,
14,
585,
14,
1188,
14,
5626,
14,
1452,
8,
267,
298,
2493,
1125,
8920,
334,
36,
651,
2540,
6044,
9,
1380,
6358,
314,
2790,
29820,
12455,
3439,
26,
4784,
3955,
1172,
19268,
12,
1325,
577,
651,
2540,
3305,
365,
663,
2,
272,
776,
339,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
1252,
5626,
14,
7804,
14,
1267,
63,
1618,
8,
17,
9,
272,
284,
8392,
14,
344,
14,
5626,
14,
1431,
8,
82,
2,
528,
87,
13,
59,
16,
13,
25,
65,
13,
70,
2807,
531,
339,
284,
8392,
275,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
3430,
16,
61,
272,
284,
8392,
14,
15855,
14,
5626,
14,
7804,
14,
1267,
63,
1618,
8,
16,
9,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
5040,
837,
272,
408,
21408,
10391,
6554,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
12830,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
444,
26,
267,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
14,
344,
12,
9951,
63,
1065,
29,
549,
9,
272,
444,
14,
585,
14,
705,
63,
600,
14,
5626,
14,
1452,
480,
36,
651,
2540,
6044,
531,
272,
444,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
444,
14,
585,
14,
1188,
14,
5626,
14,
1452,
8,
267,
298,
2493,
1125,
8920,
334,
36,
651,
2540,
6044,
9,
1380,
6358,
314,
21328,
29820,
12455,
3439,
26,
4784,
3955,
1172,
19268,
12,
1325,
577,
651,
2540,
3305,
365,
663,
2,
272,
776,
339,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
14,
344,
9,
339,
284,
8392,
275,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
3430,
16,
61,
272,
284,
8392,
14,
15855,
59,
16,
1055,
11742,
63,
344,
14,
5626,
14,
1235,
14,
1452,
8,
11742,
14,
344,
9,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
5040,
63,
4087,
63,
11742,
837,
272,
408,
21408,
10391,
2449,
370,
6554,
336,
15,
4875,
12830,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
6904,
26,
267,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
699,
1554,
63,
54,
4222,
9,
272,
6904,
14,
585,
14,
600,
14,
5626,
14,
1452,
480,
3364,
28893,
998,
14,
4667,
531,
272,
6904,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
6904,
14,
585,
14,
1069,
63,
344,
14,
5626,
63,
1397,
14,
1235,
14,
3592,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
5040,
63,
8122,
1885,
837,
272,
408,
21408,
10391,
2449,
370,
6554,
13373,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
12830,
17,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
272,
12830,
18,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
272,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
17,
14,
344,
9,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
6904,
26,
267,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
18,
14,
344,
9,
272,
6904,
14,
585,
14,
600,
14,
5626,
14,
1452,
480,
4031,
14,
16760,
14889,
972,
531,
272,
6904,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
6904,
14,
585,
14,
1069,
63,
344,
14,
5626,
63,
1397,
14,
1235,
14,
3592,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
14481,
837,
272,
408,
21408,
10391,
21236,
624,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
12830,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
272,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
14,
344,
9
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
4613,
199,
199,
646,
295,
199,
199,
646,
6055,
199,
646,
6055,
19,
199,
199,
504,
6055,
14,
1971,
492,
15352,
18,
19712,
199,
199,
646,
3238,
221,
327,
8151,
199,
199,
504,
333,
3459,
492,
1683,
63,
825,
18,
63,
6667,
12,
1683,
63,
825,
18,
421,
199,
54,
4222,
63,
35,
22052,
275,
298,
709,
14,
16,
14,
16,
14,
16,
15,
975,
2,
199,
9439,
63,
54,
4222,
275,
298,
11742,
13,
10957,
19446,
70,
2,
199,
9439,
63,
1277,
55,
275,
298,
528,
87,
13,
10957,
19446,
70,
2,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
981,
837,
272,
408,
21408,
10391,
1218,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
339,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
1252,
5626,
14,
7804,
14,
1267,
63,
1618,
8,
16,
9,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
444,
26,
267,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
8,
10481,
63,
1065,
29,
549,
9,
272,
444,
14,
585,
14,
705,
63,
600,
14,
5626,
14,
1452,
480,
36,
651,
2540,
6044,
531,
272,
444,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
444,
14,
585,
14,
1188,
14,
5626,
14,
1452,
8,
267,
298,
2493,
1125,
8920,
334,
36,
651,
2540,
6044,
9,
1380,
6358,
314,
2790,
29820,
12455,
3439,
26,
4784,
3955,
1172,
19268,
12,
1325,
577,
651,
2540,
3305,
365,
663,
2,
272,
776,
339,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
1252,
5626,
14,
7804,
14,
1267,
63,
1618,
8,
17,
9,
272,
284,
8392,
14,
344,
14,
5626,
14,
1431,
8,
82,
2,
528,
87,
13,
59,
16,
13,
25,
65,
13,
70,
2807,
531,
339,
284,
8392,
275,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
3430,
16,
61,
272,
284,
8392,
14,
15855,
14,
5626,
14,
7804,
14,
1267,
63,
1618,
8,
16,
9,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
5040,
837,
272,
408,
21408,
10391,
6554,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
12830,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
444,
26,
267,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
14,
344,
12,
9951,
63,
1065,
29,
549,
9,
272,
444,
14,
585,
14,
705,
63,
600,
14,
5626,
14,
1452,
480,
36,
651,
2540,
6044,
531,
272,
444,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
444,
14,
585,
14,
1188,
14,
5626,
14,
1452,
8,
267,
298,
2493,
1125,
8920,
334,
36,
651,
2540,
6044,
9,
1380,
6358,
314,
21328,
29820,
12455,
3439,
26,
4784,
3955,
1172,
19268,
12,
1325,
577,
651,
2540,
3305,
365,
663,
2,
272,
776,
339,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
14,
344,
9,
339,
284,
8392,
275,
2557,
14,
362,
63,
452,
63,
4901,
63,
3237,
2885,
3430,
16,
61,
272,
284,
8392,
14,
15855,
59,
16,
1055,
11742,
63,
344,
14,
5626,
14,
1235,
14,
1452,
8,
11742,
14,
344,
9,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
5040,
63,
4087,
63,
11742,
837,
272,
408,
21408,
10391,
2449,
370,
6554,
336,
15,
4875,
12830,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
6904,
26,
267,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
699,
1554,
63,
54,
4222,
9,
272,
6904,
14,
585,
14,
600,
14,
5626,
14,
1452,
480,
3364,
28893,
998,
14,
4667,
531,
272,
6904,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
6904,
14,
585,
14,
1069,
63,
344,
14,
5626,
63,
1397,
14,
1235,
14,
3592,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
5040,
63,
8122,
1885,
837,
272,
408,
21408,
10391,
2449,
370,
6554,
13373,
408,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
12830,
17,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
272,
12830,
18,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
272,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
17,
14,
344,
9,
339,
543,
4613,
14,
3536,
8,
4220,
18,
19712,
9,
465,
6904,
26,
267,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
18,
14,
344,
9,
272,
6904,
14,
585,
14,
600,
14,
5626,
14,
1452,
480,
4031,
14,
16760,
14889,
972,
531,
272,
6904,
14,
585,
14,
1205,
14,
5626,
14,
1452,
8,
5303,
9,
272,
6904,
14,
585,
14,
1069,
63,
344,
14,
5626,
63,
1397,
14,
1235,
14,
3592,
421,
199,
32,
1805,
63,
825,
18,
63,
6667,
199,
318,
511,
63,
528,
87,
63,
14481,
837,
272,
408,
21408,
10391,
21236,
624,
272,
2557,
275,
6055,
14,
2242,
63,
11742,
480,
1589,
63,
498,
401,
298,
1589,
63,
4731,
531,
272,
284,
8392,
275,
2557,
14,
981,
63,
4901,
63,
7019,
342,
272,
12830,
275,
2557,
14,
981,
63,
11742,
8,
54,
4222,
63,
35,
22052,
9,
272,
2557,
14,
5040,
63,
4901,
63,
7019,
8,
528,
87,
14,
344,
12,
12830,
14,
344,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MemeticParadigm/TensorFlow
|
tensorflow/python/summary/impl/directory_watcher_test.py
|
5
|
3056
|
"""Tests for directory_watcher."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import shutil
from tensorflow.python.framework import test_util
from tensorflow.python.platform import googletest
from tensorflow.python.summary.impl import directory_watcher
class _ByteLoader(object):
"""A loader that loads individual bytes from a file."""
def __init__(self, path):
self._f = open(path)
def Load(self):
while True:
byte = self._f.read(1)
if byte:
yield byte
else:
return
class DirectoryWatcherTest(test_util.TensorFlowTestCase):
def setUp(self):
# Put everything in a directory so it's easier to delete.
self._directory = os.path.join(self.get_temp_dir(), 'monitor_dir')
os.mkdir(self._directory)
self._watcher = directory_watcher.DirectoryWatcher(
self._directory, _ByteLoader)
def tearDown(self):
shutil.rmtree(self._directory)
def _WriteToFile(self, filename, data):
path = os.path.join(self._directory, filename)
with open(path, 'a') as f:
f.write(data)
def assertWatcherYields(self, values):
self.assertEqual(list(self._watcher.Load()), values)
def testRaisesWithBadArguments(self):
with self.assertRaises(ValueError):
directory_watcher.DirectoryWatcher(None, lambda x: [])
with self.assertRaises(ValueError):
directory_watcher.DirectoryWatcher('asdf', None)
def testEmptyDirectory(self):
self.assertWatcherYields([])
def testSingleWrite(self):
self._WriteToFile('a', 'abc')
self.assertWatcherYields(['a', 'b', 'c'])
def testMultipleWrites(self):
self._WriteToFile('a', 'abc')
self.assertWatcherYields(['a', 'b', 'c'])
self._WriteToFile('a', 'xyz')
self.assertWatcherYields(['x', 'y', 'z'])
def testMultipleLoads(self):
self._WriteToFile('a', 'a')
self._watcher.Load()
self._watcher.Load()
self.assertWatcherYields(['a'])
def testMultipleFilesAtOnce(self):
self._WriteToFile('b', 'b')
self._WriteToFile('a', 'a')
self.assertWatcherYields(['a', 'b'])
def testFinishesLoadingFileWhenSwitchingToNewFile(self):
self._WriteToFile('a', 'a')
# Empty the iterator.
self.assertEquals(['a'], list(self._watcher.Load()))
self._WriteToFile('a', 'b')
self._WriteToFile('b', 'c')
# The watcher should finish its current file before starting a new one.
self.assertWatcherYields(['b', 'c'])
def testIntermediateEmptyFiles(self):
self._WriteToFile('a', 'a')
self._WriteToFile('b', '')
self._WriteToFile('c', 'c')
self.assertWatcherYields(['a', 'c'])
def testFileFilter(self):
self._watcher = directory_watcher.DirectoryWatcher(
self._directory, _ByteLoader,
path_filter=lambda path: 'do_not_watch_me' not in path)
self._WriteToFile('a', 'a')
self._WriteToFile('do_not_watch_me', 'b')
self._WriteToFile('c', 'c')
self.assertWatcherYields(['a', 'c'])
if __name__ == '__main__':
googletest.main()
|
apache-2.0
|
[
624,
2925,
367,
2082,
63,
22226,
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,
747,
199,
646,
5145,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
199,
504,
3228,
14,
1548,
14,
4705,
14,
5472,
492,
2082,
63,
22226,
421,
199,
533,
485,
4861,
5455,
8,
785,
304,
523,
408,
33,
5077,
626,
14404,
8212,
2783,
687,
282,
570,
1041,
819,
347,
636,
826,
721,
277,
12,
931,
304,
272,
291,
423,
70,
275,
1551,
8,
515,
9,
819,
347,
7190,
8,
277,
304,
272,
1830,
715,
26,
489,
3696,
275,
291,
423,
70,
14,
739,
8,
17,
9,
489,
340,
3696,
26,
267,
1995,
3696,
489,
587,
26,
267,
372,
421,
199,
533,
15191,
13978,
281,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
327,
16280,
8137,
315,
282,
2082,
880,
652,
1159,
14905,
370,
3145,
14,
272,
291,
423,
3619,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
283,
7157,
63,
694,
358,
272,
747,
14,
8215,
8,
277,
423,
3619,
9,
272,
291,
423,
22226,
275,
2082,
63,
22226,
14,
6231,
13978,
281,
8,
267,
291,
423,
3619,
12,
485,
4861,
5455,
9,
819,
347,
6766,
8,
277,
304,
272,
5145,
14,
9242,
8,
277,
423,
3619,
9,
819,
347,
485,
3534,
24320,
8,
277,
12,
1788,
12,
666,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
277,
423,
3619,
12,
1788,
9,
272,
543,
1551,
8,
515,
12,
283,
65,
358,
465,
289,
26,
489,
289,
14,
952,
8,
576,
9,
819,
347,
702,
13978,
281,
22889,
83,
8,
277,
12,
1338,
304,
272,
291,
14,
629,
8,
513,
8,
277,
423,
22226,
14,
6200,
4000,
1338,
9,
819,
347,
511,
1811,
3007,
5725,
14517,
8,
277,
304,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2082,
63,
22226,
14,
6231,
13978,
281,
8,
403,
12,
2400,
671,
26,
3073,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2082,
63,
22226,
14,
6231,
13978,
281,
360,
18196,
297,
488,
9,
819,
347,
511,
4699,
6231,
8,
277,
304,
272,
291,
14,
479,
13978,
281,
22889,
83,
4157,
819,
347,
511,
7200,
3534,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
3175,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
66,
297,
283,
67,
1105,
819,
347,
511,
8433,
20908,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
3175,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
66,
297,
283,
67,
1105,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
8568,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
88,
297,
283,
89,
297,
283,
90,
1105,
819,
347,
511,
8433,
30777,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
423,
22226,
14,
6200,
342,
272,
291,
423,
22226,
14,
6200,
342,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
1105,
819,
347,
511,
8433,
5535,
1271,
25690,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
66,
297,
283,
66,
358,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
66,
1105,
819,
347,
511,
22084,
397,
19236,
1173,
11423,
10167,
316,
1378,
4665,
1173,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
327,
9630,
314,
6122,
14,
272,
291,
14,
2947,
2941,
65,
995,
769,
8,
277,
423,
22226,
14,
6200,
4059,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
66,
358,
272,
291,
423,
3534,
24320,
360,
66,
297,
283,
67,
358,
272,
327,
710,
9626,
281,
1077,
9578,
2399,
1453,
570,
2544,
6617,
282,
892,
1373,
14,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
66,
297,
283,
67,
1105,
819,
347,
511,
2620,
5050,
4699,
5535,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
423,
3534,
24320,
360,
66,
297,
4074,
272,
291,
423,
3534,
24320,
360,
67,
297,
283,
67,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
67,
1105,
819,
347,
511,
1173,
4131,
8,
277,
304,
272,
291,
423,
22226,
275,
2082,
63,
22226,
14,
6231,
13978,
281,
8,
267,
291,
423,
3619,
12,
485,
4861,
5455,
12,
267,
931,
63,
1541,
29,
2734,
931,
26,
283,
1117,
63,
1397,
63,
6821,
63,
278,
7,
440,
315,
931,
9,
339,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
423,
3534,
24320,
360,
1117,
63,
1397,
63,
6821,
63,
278,
297,
283,
66,
358,
272,
291,
423,
3534,
24320,
360,
67,
297,
283,
67,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
67,
1105,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
31141,
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
] |
[
2925,
367,
2082,
63,
22226,
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,
747,
199,
646,
5145,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
199,
504,
3228,
14,
1548,
14,
4705,
14,
5472,
492,
2082,
63,
22226,
421,
199,
533,
485,
4861,
5455,
8,
785,
304,
523,
408,
33,
5077,
626,
14404,
8212,
2783,
687,
282,
570,
1041,
819,
347,
636,
826,
721,
277,
12,
931,
304,
272,
291,
423,
70,
275,
1551,
8,
515,
9,
819,
347,
7190,
8,
277,
304,
272,
1830,
715,
26,
489,
3696,
275,
291,
423,
70,
14,
739,
8,
17,
9,
489,
340,
3696,
26,
267,
1995,
3696,
489,
587,
26,
267,
372,
421,
199,
533,
15191,
13978,
281,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
327,
16280,
8137,
315,
282,
2082,
880,
652,
1159,
14905,
370,
3145,
14,
272,
291,
423,
3619,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
283,
7157,
63,
694,
358,
272,
747,
14,
8215,
8,
277,
423,
3619,
9,
272,
291,
423,
22226,
275,
2082,
63,
22226,
14,
6231,
13978,
281,
8,
267,
291,
423,
3619,
12,
485,
4861,
5455,
9,
819,
347,
6766,
8,
277,
304,
272,
5145,
14,
9242,
8,
277,
423,
3619,
9,
819,
347,
485,
3534,
24320,
8,
277,
12,
1788,
12,
666,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
277,
423,
3619,
12,
1788,
9,
272,
543,
1551,
8,
515,
12,
283,
65,
358,
465,
289,
26,
489,
289,
14,
952,
8,
576,
9,
819,
347,
702,
13978,
281,
22889,
83,
8,
277,
12,
1338,
304,
272,
291,
14,
629,
8,
513,
8,
277,
423,
22226,
14,
6200,
4000,
1338,
9,
819,
347,
511,
1811,
3007,
5725,
14517,
8,
277,
304,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2082,
63,
22226,
14,
6231,
13978,
281,
8,
403,
12,
2400,
671,
26,
3073,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2082,
63,
22226,
14,
6231,
13978,
281,
360,
18196,
297,
488,
9,
819,
347,
511,
4699,
6231,
8,
277,
304,
272,
291,
14,
479,
13978,
281,
22889,
83,
4157,
819,
347,
511,
7200,
3534,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
3175,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
66,
297,
283,
67,
1105,
819,
347,
511,
8433,
20908,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
3175,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
66,
297,
283,
67,
1105,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
8568,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
88,
297,
283,
89,
297,
283,
90,
1105,
819,
347,
511,
8433,
30777,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
423,
22226,
14,
6200,
342,
272,
291,
423,
22226,
14,
6200,
342,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
1105,
819,
347,
511,
8433,
5535,
1271,
25690,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
66,
297,
283,
66,
358,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
66,
1105,
819,
347,
511,
22084,
397,
19236,
1173,
11423,
10167,
316,
1378,
4665,
1173,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
327,
9630,
314,
6122,
14,
272,
291,
14,
2947,
2941,
65,
995,
769,
8,
277,
423,
22226,
14,
6200,
4059,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
66,
358,
272,
291,
423,
3534,
24320,
360,
66,
297,
283,
67,
358,
272,
327,
710,
9626,
281,
1077,
9578,
2399,
1453,
570,
2544,
6617,
282,
892,
1373,
14,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
66,
297,
283,
67,
1105,
819,
347,
511,
2620,
5050,
4699,
5535,
8,
277,
304,
272,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
423,
3534,
24320,
360,
66,
297,
4074,
272,
291,
423,
3534,
24320,
360,
67,
297,
283,
67,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
67,
1105,
819,
347,
511,
1173,
4131,
8,
277,
304,
272,
291,
423,
22226,
275,
2082,
63,
22226,
14,
6231,
13978,
281,
8,
267,
291,
423,
3619,
12,
485,
4861,
5455,
12,
267,
931,
63,
1541,
29,
2734,
931,
26,
283,
1117,
63,
1397,
63,
6821,
63,
278,
7,
440,
315,
931,
9,
339,
291,
423,
3534,
24320,
360,
65,
297,
283,
65,
358,
272,
291,
423,
3534,
24320,
360,
1117,
63,
1397,
63,
6821,
63,
278,
297,
283,
66,
358,
272,
291,
423,
3534,
24320,
360,
67,
297,
283,
67,
358,
272,
291,
14,
479,
13978,
281,
22889,
83,
2941,
65,
297,
283,
67,
1105,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
31141,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Permutatrix/servo
|
components/script/dom/bindings/codegen/parser/tests/test_global_extended_attr.py
|
107
|
2977
|
def WebIDLTest(parser, harness):
parser.parse("""
[Global]
interface Foo : Bar {
getter any(DOMString name);
};
interface Bar {};
""")
results = parser.finish()
harness.ok(results[0].isOnGlobalProtoChain(),
"[Global] interface should be on global's proto chain")
harness.ok(results[1].isOnGlobalProtoChain(),
"[Global] interface should be on global's proto chain")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Global]
interface Foo {
getter any(DOMString name);
setter void(DOMString name, any arg);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should have thrown for [Global] used on an interface with a "
"named setter")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Global]
interface Foo {
getter any(DOMString name);
creator void(DOMString name, any arg);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should have thrown for [Global] used on an interface with a "
"named creator")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Global]
interface Foo {
getter any(DOMString name);
deleter void(DOMString name);
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should have thrown for [Global] used on an interface with a "
"named deleter")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Global, OverrideBuiltins]
interface Foo {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should have thrown for [Global] used on an interface with a "
"[OverrideBuiltins]")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Global]
interface Foo : Bar {
};
[OverrideBuiltins]
interface Bar {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should have thrown for [Global] used on an interface with an "
"[OverrideBuiltins] ancestor")
parser = parser.reset()
threw = False
try:
parser.parse("""
[Global]
interface Foo {
};
interface Bar : Foo {
};
""")
results = parser.finish()
except:
threw = True
harness.ok(threw,
"Should have thrown for [Global] used on an interface with a "
"descendant")
|
mpl-2.0
|
[
318,
22817,
774,
8,
2087,
12,
20458,
304,
272,
1798,
14,
1122,
4852,
489,
359,
7025,
61,
489,
3217,
8024,
520,
12377,
469,
267,
15917,
1263,
8,
10462,
1558,
536,
2736,
489,
16735,
489,
3217,
12377,
27978,
272,
7857,
339,
2058,
275,
1798,
14,
8192,
342,
339,
20458,
14,
745,
8,
2604,
59,
16,
1055,
374,
3314,
7025,
8548,
10720,
1062,
2049,
7369,
7025,
61,
3217,
1077,
506,
641,
2288,
1159,
4104,
6036,
531,
272,
20458,
14,
745,
8,
2604,
59,
17,
1055,
374,
3314,
7025,
8548,
10720,
1062,
2049,
7369,
7025,
61,
3217,
1077,
506,
641,
2288,
1159,
4104,
6036,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
288,
15917,
1263,
8,
10462,
1558,
536,
2736,
288,
18743,
2309,
8,
10462,
1558,
536,
12,
1263,
1680,
2736,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
4579,
18743,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
288,
15917,
1263,
8,
10462,
1558,
536,
2736,
288,
14875,
2309,
8,
10462,
1558,
536,
12,
1263,
1680,
2736,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
4579,
14875,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
288,
15917,
1263,
8,
10462,
1558,
536,
2736,
288,
6070,
351,
2309,
8,
10462,
1558,
536,
2736,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
4579,
6070,
351,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
12,
11041,
12306,
83,
61,
881,
3217,
8024,
469,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
7369,
11954,
12306,
83,
12523,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
520,
12377,
469,
881,
16735,
881,
359,
11954,
12306,
83,
61,
881,
3217,
12377,
469,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
376,
298,
2049,
7369,
11954,
12306,
83,
61,
18432,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
881,
16735,
881,
3217,
12377,
520,
8024,
469,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
31759,
531,
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
] |
[
22817,
774,
8,
2087,
12,
20458,
304,
272,
1798,
14,
1122,
4852,
489,
359,
7025,
61,
489,
3217,
8024,
520,
12377,
469,
267,
15917,
1263,
8,
10462,
1558,
536,
2736,
489,
16735,
489,
3217,
12377,
27978,
272,
7857,
339,
2058,
275,
1798,
14,
8192,
342,
339,
20458,
14,
745,
8,
2604,
59,
16,
1055,
374,
3314,
7025,
8548,
10720,
1062,
2049,
7369,
7025,
61,
3217,
1077,
506,
641,
2288,
1159,
4104,
6036,
531,
272,
20458,
14,
745,
8,
2604,
59,
17,
1055,
374,
3314,
7025,
8548,
10720,
1062,
2049,
7369,
7025,
61,
3217,
1077,
506,
641,
2288,
1159,
4104,
6036,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
288,
15917,
1263,
8,
10462,
1558,
536,
2736,
288,
18743,
2309,
8,
10462,
1558,
536,
12,
1263,
1680,
2736,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
4579,
18743,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
288,
15917,
1263,
8,
10462,
1558,
536,
2736,
288,
14875,
2309,
8,
10462,
1558,
536,
12,
1263,
1680,
2736,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
4579,
14875,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
288,
15917,
1263,
8,
10462,
1558,
536,
2736,
288,
6070,
351,
2309,
8,
10462,
1558,
536,
2736,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
4579,
6070,
351,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
12,
11041,
12306,
83,
61,
881,
3217,
8024,
469,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
7369,
11954,
12306,
83,
12523,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
520,
12377,
469,
881,
16735,
881,
359,
11954,
12306,
83,
61,
881,
3217,
12377,
469,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
376,
298,
2049,
7369,
11954,
12306,
83,
61,
18432,
531,
339,
1798,
275,
1798,
14,
3958,
342,
272,
28176,
275,
756,
272,
862,
26,
267,
1798,
14,
1122,
4852,
881,
359,
7025,
61,
881,
3217,
8024,
469,
881,
16735,
881,
3217,
12377,
520,
8024,
469,
881,
16735,
267,
7857,
267,
2058,
275,
1798,
14,
8192,
342,
272,
871,
26,
267,
28176,
275,
715,
339,
20458,
14,
745,
8,
273,
5257,
12,
2049,
298,
11408,
1172,
14031,
367,
359,
7025,
61,
1202,
641,
376,
3217,
543,
282,
298,
2049,
298,
31759,
531,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Proggie02/TestRepo
|
tests/modeltests/proxy_model_inheritance/tests.py
|
6
|
2131
|
from __future__ import absolute_import
import os
import sys
from django.conf import settings
from django.core.management import call_command
from django.db.models.loading import cache, load_app
from django.test import TestCase, TransactionTestCase
from django.test.utils import override_settings
from .models import (ConcreteModel, ConcreteModelSubclass,
ConcreteModelSubclassProxy)
@override_settings(INSTALLED_APPS=('app1', 'app2'))
class ProxyModelInheritanceTests(TransactionTestCase):
"""
Proxy model inheritance across apps can result in syncdb not creating the table
for the proxied model (as described in #12286). This test creates two dummy
apps and calls syncdb, then verifies that the table has been created.
"""
def setUp(self):
self.old_sys_path = sys.path[:]
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
for app in settings.INSTALLED_APPS:
load_app(app)
def tearDown(self):
sys.path = self.old_sys_path
del cache.app_store[cache.app_labels['app1']]
del cache.app_store[cache.app_labels['app2']]
del cache.app_labels['app1']
del cache.app_labels['app2']
del cache.app_models['app1']
del cache.app_models['app2']
def test_table_exists(self):
call_command('syncdb', verbosity=0)
from .app1.models import ProxyModel
from .app2.models import NiceModel
self.assertEqual(NiceModel.objects.all().count(), 0)
self.assertEqual(ProxyModel.objects.all().count(), 0)
class MultiTableInheritanceProxyTest(TestCase):
def test_model_subclass_proxy(self):
"""
Deleting an instance of a model proxying a multi-table inherited
subclass should cascade delete down the whole inheritance chain (see
#18083).
"""
instance = ConcreteModelSubclassProxy.objects.create()
instance.delete()
self.assertEqual(0, ConcreteModelSubclassProxy.objects.count())
self.assertEqual(0, ConcreteModelSubclass.objects.count())
self.assertEqual(0, ConcreteModel.objects.count())
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
747,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
492,
1240,
63,
1531,
199,
504,
1639,
14,
697,
14,
992,
14,
8786,
492,
2581,
12,
2248,
63,
571,
199,
504,
1639,
14,
396,
492,
7640,
12,
18244,
1746,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
199,
504,
1275,
992,
492,
334,
714,
7564,
1685,
12,
1448,
7564,
1685,
23636,
12,
272,
1448,
7564,
1685,
23636,
4936,
9,
421,
199,
32,
4415,
63,
1751,
8,
15942,
63,
14219,
7782,
571,
17,
297,
283,
571,
18,
1333,
199,
533,
12373,
1685,
23542,
554,
2925,
8,
10161,
1746,
304,
272,
408,
272,
12373,
1402,
15433,
9371,
8686,
883,
754,
315,
7604,
697,
440,
6425,
314,
1817,
272,
367,
314,
10645,
5299,
1402,
334,
305,
11736,
315,
327,
7507,
1184,
680,
221,
961,
511,
8491,
2877,
7283,
272,
8686,
436,
4882,
7604,
697,
12,
2066,
22694,
626,
314,
1817,
965,
2757,
2737,
14,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1753,
63,
1274,
63,
515,
275,
984,
14,
515,
5873,
267,
984,
14,
515,
14,
740,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
267,
367,
1145,
315,
2202,
14,
15942,
63,
14219,
26,
288,
2248,
63,
571,
8,
571,
9,
339,
347,
6766,
8,
277,
304,
267,
984,
14,
515,
275,
291,
14,
1753,
63,
1274,
63,
515,
267,
2150,
2581,
14,
571,
63,
1617,
59,
1637,
14,
571,
63,
3512,
459,
571,
17,
6538,
267,
2150,
2581,
14,
571,
63,
1617,
59,
1637,
14,
571,
63,
3512,
459,
571,
18,
6538,
267,
2150,
2581,
14,
571,
63,
3512,
459,
571,
17,
418,
267,
2150,
2581,
14,
571,
63,
3512,
459,
571,
18,
418,
267,
2150,
2581,
14,
571,
63,
992,
459,
571,
17,
418,
267,
2150,
2581,
14,
571,
63,
992,
459,
571,
18,
418,
339,
347,
511,
63,
1224,
63,
2444,
8,
277,
304,
267,
1240,
63,
1531,
360,
5186,
697,
297,
8661,
29,
16,
9,
267,
687,
1275,
571,
17,
14,
992,
492,
12373,
1685,
267,
687,
1275,
571,
18,
14,
992,
492,
653,
1885,
1685,
267,
291,
14,
629,
8,
46,
1885,
1685,
14,
1462,
14,
452,
1252,
835,
1062,
378,
9,
267,
291,
14,
629,
8,
4936,
1685,
14,
1462,
14,
452,
1252,
835,
1062,
378,
9,
421,
199,
533,
6879,
3186,
23542,
554,
4936,
774,
8,
1746,
304,
339,
347,
511,
63,
1238,
63,
6083,
63,
3280,
8,
277,
304,
267,
408,
267,
15920,
376,
1256,
402,
282,
1402,
4566,
316,
282,
3510,
13,
1224,
12623,
267,
5516,
1077,
22809,
3145,
3224,
314,
8852,
15433,
6036,
334,
3239,
267,
327,
1085,
19573,
680,
398,
408,
267,
1256,
275,
1448,
7564,
1685,
23636,
4936,
14,
1462,
14,
981,
342,
267,
1256,
14,
1807,
342,
267,
291,
14,
629,
8,
16,
12,
1448,
7564,
1685,
23636,
4936,
14,
1462,
14,
835,
1012,
267,
291,
14,
629,
8,
16,
12,
1448,
7564,
1685,
23636,
14,
1462,
14,
835,
1012,
267,
291,
14,
629,
8,
16,
12,
1448,
7564,
1685,
14,
1462,
14,
835,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
747,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
492,
1240,
63,
1531,
199,
504,
1639,
14,
697,
14,
992,
14,
8786,
492,
2581,
12,
2248,
63,
571,
199,
504,
1639,
14,
396,
492,
7640,
12,
18244,
1746,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
199,
504,
1275,
992,
492,
334,
714,
7564,
1685,
12,
1448,
7564,
1685,
23636,
12,
272,
1448,
7564,
1685,
23636,
4936,
9,
421,
199,
32,
4415,
63,
1751,
8,
15942,
63,
14219,
7782,
571,
17,
297,
283,
571,
18,
1333,
199,
533,
12373,
1685,
23542,
554,
2925,
8,
10161,
1746,
304,
272,
408,
272,
12373,
1402,
15433,
9371,
8686,
883,
754,
315,
7604,
697,
440,
6425,
314,
1817,
272,
367,
314,
10645,
5299,
1402,
334,
305,
11736,
315,
327,
7507,
1184,
680,
221,
961,
511,
8491,
2877,
7283,
272,
8686,
436,
4882,
7604,
697,
12,
2066,
22694,
626,
314,
1817,
965,
2757,
2737,
14,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1753,
63,
1274,
63,
515,
275,
984,
14,
515,
5873,
267,
984,
14,
515,
14,
740,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
267,
367,
1145,
315,
2202,
14,
15942,
63,
14219,
26,
288,
2248,
63,
571,
8,
571,
9,
339,
347,
6766,
8,
277,
304,
267,
984,
14,
515,
275,
291,
14,
1753,
63,
1274,
63,
515,
267,
2150,
2581,
14,
571,
63,
1617,
59,
1637,
14,
571,
63,
3512,
459,
571,
17,
6538,
267,
2150,
2581,
14,
571,
63,
1617,
59,
1637,
14,
571,
63,
3512,
459,
571,
18,
6538,
267,
2150,
2581,
14,
571,
63,
3512,
459,
571,
17,
418,
267,
2150,
2581,
14,
571,
63,
3512,
459,
571,
18,
418,
267,
2150,
2581,
14,
571,
63,
992,
459,
571,
17,
418,
267,
2150,
2581,
14,
571,
63,
992,
459,
571,
18,
418,
339,
347,
511,
63,
1224,
63,
2444,
8,
277,
304,
267,
1240,
63,
1531,
360,
5186,
697,
297,
8661,
29,
16,
9,
267,
687,
1275,
571,
17,
14,
992,
492,
12373,
1685,
267,
687,
1275,
571,
18,
14,
992,
492,
653,
1885,
1685,
267,
291,
14,
629,
8,
46,
1885,
1685,
14,
1462,
14,
452,
1252,
835,
1062,
378,
9,
267,
291,
14,
629,
8,
4936,
1685,
14,
1462,
14,
452,
1252,
835,
1062,
378,
9,
421,
199,
533,
6879,
3186,
23542,
554,
4936,
774,
8,
1746,
304,
339,
347,
511,
63,
1238,
63,
6083,
63,
3280,
8,
277,
304,
267,
408,
267,
15920,
376,
1256,
402,
282,
1402,
4566,
316,
282,
3510,
13,
1224,
12623,
267,
5516,
1077,
22809,
3145,
3224,
314,
8852,
15433,
6036,
334,
3239,
267,
327,
1085,
19573,
680,
398,
408,
267,
1256,
275,
1448,
7564,
1685,
23636,
4936,
14,
1462,
14,
981,
342,
267,
1256,
14,
1807,
342,
267,
291,
14,
629,
8,
16,
12,
1448,
7564,
1685,
23636,
4936,
14,
1462,
14,
835,
1012,
267,
291,
14,
629,
8,
16,
12,
1448,
7564,
1685,
23636,
14,
1462,
14,
835,
1012,
267,
291,
14,
629,
8,
16,
12,
1448,
7564,
1685,
14,
1462,
14,
835,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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/>.
# Script to check correlation_detector.
# Calculates spike cross correlation function of both spike trains in
# spike_detector-0-0-3.gdf. The file is generated after running the
# testscript testsuite/unittests/test_mip_corrdet.sli
#
# Author: Helias
# Date: 08-04-07
#
from scipy import *
from matplotlib.pylab import * # for plot
# Auto- and crosscorrelation functions for spike trains.
#
# A time bin of size tbin is centered around the time difference it
# represents If the correlation function is calculated for tau in
# [-tau_max, tau_max], the pair events contributing to the left-most
# bin are those for which tau in [-tau_max-tbin/2, tau_max+tbin/2) and
# so on.
# correlate two spike trains with each other
# assumes spike times to be ordered in time
# tau > 0 means spike2 is later than spike1
#
# tau_max: maximum time lag in ms correlation function
# tbin: bin size
# spike1: first spike train [tspike...]
# spike2: second spike train [tspike...]
#
def corr_spikes_sorted(spike1, spike2, tbin, tau_max, h):
tau_max_i = int(tau_max/h)
tbin_i = int(tbin/h)
cross = zeros(int(2*tau_max_i/tbin_i+1), 'd')
j0 = 0
for spki in spike1:
j = j0
while j < len(spike2) and spike2[j] - spki < -tau_max_i - tbin_i/2.0:
j += 1
j0 = j
while j < len(spike2) and spike2[j] - spki < tau_max_i + tbin_i/2.0:
cross[int((spike2[j] - spki + tau_max_i + 0.5*tbin_i)/tbin_i)] += 1.0
j += 1
return cross
def main():
# resolution
h = 0.1
tau_max = 100.0 # ms correlation window
t_bin = 10.0 # ms bin size
# read input from spike detector
spikes = load('spike_detector-0-0-3.gdf')
sp1 = spikes[find(spikes[:,0] == 4), 1]
sp2 = spikes[find(spikes[:,0] == 5), 1]
cross = corr_spikes_sorted(sp1, sp2, t_bin, tau_max, h)
print cross
print sum(cross)
main()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
8059,
63,
1074,
63,
396,
63,
20496,
63,
16742,
9886,
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,
3,
14914,
370,
1104,
21280,
63,
19401,
14,
199,
199,
3,
28562,
19441,
415,
8059,
21280,
805,
402,
3865,
19441,
415,
3560,
83,
315,
199,
3,
19441,
415,
63,
19401,
13,
16,
13,
16,
13,
19,
14,
71,
1587,
14,
710,
570,
365,
4046,
2410,
3879,
314,
199,
3,
511,
1579,
2295,
2577,
15,
31053,
15,
396,
63,
20496,
63,
16742,
9886,
14,
23766,
199,
3,
199,
3,
6529,
26,
5311,
317,
305,
199,
3,
6148,
26,
19363,
13,
966,
13,
1780,
199,
3,
199,
199,
504,
7026,
492,
627,
199,
504,
8027,
14,
32538,
492,
627,
327,
367,
5137,
199,
199,
3,
9195,
13,
436,
8059,
26487,
3423,
367,
19441,
415,
3560,
83,
14,
199,
3,
199,
3,
437,
900,
2517,
402,
1568,
307,
1393,
365,
23903,
6818,
314,
900,
8865,
652,
199,
3,
8469,
982,
314,
21280,
805,
365,
12950,
367,
19188,
315,
199,
3,
5243,
16656,
63,
988,
12,
19188,
63,
988,
467,
314,
4092,
4474,
5914,
4655,
370,
314,
3602,
13,
2786,
199,
3,
2517,
787,
5204,
367,
1314,
19188,
315,
5243,
16656,
63,
988,
13,
84,
1393,
15,
18,
12,
19188,
63,
988,
11,
84,
1393,
15,
18,
9,
436,
199,
3,
880,
641,
14,
421,
199,
3,
1970,
17322,
2877,
19441,
415,
3560,
83,
543,
1924,
1163,
199,
3,
15194,
19441,
415,
5431,
370,
506,
7741,
315,
900,
199,
3,
19188,
690,
378,
4910,
19441,
415,
18,
365,
2945,
2419,
19441,
415,
17,
199,
3,
199,
3,
19188,
63,
988,
26,
258,
5696,
900,
17891,
315,
6605,
21280,
805,
199,
3,
307,
1393,
26,
257,
2517,
1568,
199,
3,
19441,
415,
17,
26,
1642,
19441,
415,
3560,
359,
84,
29774,
18737,
199,
3,
19441,
415,
18,
26,
3499,
19441,
415,
3560,
359,
84,
29774,
18737,
199,
3,
199,
318,
25948,
63,
32757,
397,
63,
5917,
8,
29774,
17,
12,
19441,
415,
18,
12,
307,
1393,
12,
19188,
63,
988,
12,
394,
304,
819,
19188,
63,
988,
63,
73,
275,
1109,
8,
16656,
63,
988,
15,
72,
9,
523,
307,
1393,
63,
73,
275,
1109,
8,
84,
1393,
15,
72,
9,
819,
8059,
275,
10136,
8,
442,
8,
18,
10,
16656,
63,
988,
63,
73,
15,
84,
1393,
63,
73,
11,
17,
395,
283,
68,
358,
819,
1335,
16,
275,
378,
819,
367,
308,
2051,
73,
315,
19441,
415,
17,
26,
272,
1335,
275,
1335,
16,
272,
1830,
1335,
665,
822,
8,
29774,
18,
9,
436,
19441,
415,
18,
59,
74,
61,
446,
308,
2051,
73,
665,
446,
16656,
63,
988,
63,
73,
446,
307,
1393,
63,
73,
15,
18,
14,
16,
26,
489,
1335,
847,
413,
272,
1335,
16,
275,
1335,
2286,
1830,
1335,
665,
822,
8,
29774,
18,
9,
436,
19441,
415,
18,
59,
74,
61,
446,
308,
2051,
73,
665,
19188,
63,
988,
63,
73,
435,
307,
1393,
63,
73,
15,
18,
14,
16,
26,
489,
8059,
59,
442,
1332,
29774,
18,
59,
74,
61,
446,
308,
2051,
73,
435,
19188,
63,
988,
63,
73,
435,
378,
14,
21,
10,
84,
1393,
63,
73,
2447,
84,
1393,
63,
73,
1874,
847,
413,
14,
16,
489,
1335,
847,
413,
2126,
523,
372,
8059,
421,
199,
318,
2446,
837,
819,
327,
12401,
523,
394,
275,
378,
14,
17,
523,
19188,
63,
988,
275,
2948,
14,
16,
327,
6605,
21280,
4353,
523,
307,
63,
1393,
275,
1616,
14,
16,
327,
6605,
2517,
1568,
2043,
819,
327,
1586,
1324,
687,
19441,
415,
17842,
523,
19441,
9246,
275,
2248,
360,
29774,
63,
19401,
13,
16,
13,
16,
13,
19,
14,
71,
1587,
358,
819,
2249,
17,
275,
19441,
9246,
59,
1623,
8,
32757,
397,
3981,
16,
61,
508,
841,
395,
413,
61,
523,
2249,
18,
275,
19441,
9246,
59,
1623,
8,
32757,
397,
3981,
16,
61,
508,
959,
395,
413,
61,
819,
8059,
275,
25948,
63,
32757,
397,
63,
5917,
8,
681,
17,
12,
2249,
18,
12,
307,
63,
1393,
12,
19188,
63,
988,
12,
394,
9,
819,
870,
8059,
523,
870,
3089,
8,
7925,
9,
421,
199,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
8059,
63,
1074,
63,
396,
63,
20496,
63,
16742,
9886,
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,
3,
14914,
370,
1104,
21280,
63,
19401,
14,
199,
199,
3,
28562,
19441,
415,
8059,
21280,
805,
402,
3865,
19441,
415,
3560,
83,
315,
199,
3,
19441,
415,
63,
19401,
13,
16,
13,
16,
13,
19,
14,
71,
1587,
14,
710,
570,
365,
4046,
2410,
3879,
314,
199,
3,
511,
1579,
2295,
2577,
15,
31053,
15,
396,
63,
20496,
63,
16742,
9886,
14,
23766,
199,
3,
199,
3,
6529,
26,
5311,
317,
305,
199,
3,
6148,
26,
19363,
13,
966,
13,
1780,
199,
3,
199,
199,
504,
7026,
492,
627,
199,
504,
8027,
14,
32538,
492,
627,
327,
367,
5137,
199,
199,
3,
9195,
13,
436,
8059,
26487,
3423,
367,
19441,
415,
3560,
83,
14,
199,
3,
199,
3,
437,
900,
2517,
402,
1568,
307,
1393,
365,
23903,
6818,
314,
900,
8865,
652,
199,
3,
8469,
982,
314,
21280,
805,
365,
12950,
367,
19188,
315,
199,
3,
5243,
16656,
63,
988,
12,
19188,
63,
988,
467,
314,
4092,
4474,
5914,
4655,
370,
314,
3602,
13,
2786,
199,
3,
2517,
787,
5204,
367,
1314,
19188,
315,
5243,
16656,
63,
988,
13,
84,
1393,
15,
18,
12,
19188,
63,
988,
11,
84,
1393,
15,
18,
9,
436,
199,
3,
880,
641,
14,
421,
199,
3,
1970,
17322,
2877,
19441,
415,
3560,
83,
543,
1924,
1163,
199,
3,
15194,
19441,
415,
5431,
370,
506,
7741,
315,
900,
199,
3,
19188,
690,
378,
4910,
19441,
415,
18,
365,
2945,
2419,
19441,
415,
17,
199,
3,
199,
3,
19188,
63,
988,
26,
258,
5696,
900,
17891,
315,
6605,
21280,
805,
199,
3,
307,
1393,
26,
257,
2517,
1568,
199,
3,
19441,
415,
17,
26,
1642,
19441,
415,
3560,
359,
84,
29774,
18737,
199,
3,
19441,
415,
18,
26,
3499,
19441,
415,
3560,
359,
84,
29774,
18737,
199,
3,
199,
318,
25948,
63,
32757,
397,
63,
5917,
8,
29774,
17,
12,
19441,
415,
18,
12,
307,
1393,
12,
19188,
63,
988,
12,
394,
304,
819,
19188,
63,
988,
63,
73,
275,
1109,
8,
16656,
63,
988,
15,
72,
9,
523,
307,
1393,
63,
73,
275,
1109,
8,
84,
1393,
15,
72,
9,
819,
8059,
275,
10136,
8,
442,
8,
18,
10,
16656,
63,
988,
63,
73,
15,
84,
1393,
63,
73,
11,
17,
395,
283,
68,
358,
819,
1335,
16,
275,
378,
819,
367,
308,
2051,
73,
315,
19441,
415,
17,
26,
272,
1335,
275,
1335,
16,
272,
1830,
1335,
665,
822,
8,
29774,
18,
9,
436,
19441,
415,
18,
59,
74,
61,
446,
308,
2051,
73,
665,
446,
16656,
63,
988,
63,
73,
446,
307,
1393,
63,
73,
15,
18,
14,
16,
26,
489,
1335,
847,
413,
272,
1335,
16,
275,
1335,
2286,
1830,
1335,
665,
822,
8,
29774,
18,
9,
436,
19441,
415,
18,
59,
74,
61,
446,
308,
2051,
73,
665,
19188,
63,
988,
63,
73,
435,
307,
1393,
63,
73,
15,
18,
14,
16,
26,
489,
8059,
59,
442,
1332,
29774,
18,
59,
74,
61,
446,
308,
2051,
73,
435,
19188,
63,
988,
63,
73,
435,
378,
14,
21,
10,
84,
1393,
63,
73,
2447,
84,
1393,
63,
73,
1874,
847,
413,
14,
16,
489,
1335,
847,
413,
2126,
523,
372,
8059,
421,
199,
318,
2446,
837,
819,
327,
12401,
523,
394,
275,
378,
14,
17,
523,
19188,
63,
988,
275,
2948,
14,
16,
327,
6605,
21280,
4353,
523,
307,
63,
1393,
275,
1616,
14,
16,
327,
6605,
2517,
1568,
2043,
819,
327,
1586,
1324,
687,
19441,
415,
17842,
523,
19441,
9246,
275,
2248,
360,
29774,
63,
19401,
13,
16,
13,
16,
13,
19,
14,
71,
1587,
358,
819,
2249,
17,
275,
19441,
9246,
59,
1623,
8,
32757,
397,
3981,
16,
61,
508,
841,
395,
413,
61,
523,
2249,
18,
275,
19441,
9246,
59,
1623,
8,
32757,
397,
3981,
16,
61,
508,
959,
395,
413,
61,
819,
8059,
275,
25948,
63,
32757,
397,
63,
5917,
8,
681,
17,
12,
2249,
18,
12,
307,
63,
1393,
12,
19188,
63,
988,
12,
394,
9,
819,
870,
8059,
523,
870,
3089,
8,
7925,
9,
421,
199,
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,
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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actuator Handler
=========================================
The actions for the spider. Will be able to change the gaits that the spider will do.
"""
import lib.handlers.handlerTemplates as handlerTemplates
class SpiderActuatorHandler(handlerTemplates.ActuatorHandler):
def __init__(self, executor, shared_data):
self.currentGaits = "normal"
self.loadGait("normal", 1)
try:
self.loco = executor.hsub.getHandlerInstanceByType(handlerTemplates.LocomotionCommandHandler)
self.gaits = shared_data["Gaits"]
except NameError:
print "(ACTU) ERROR: Loco or Gaits not found."
exit(-1)
def sitDown(self, actuatorVal, initial=False):
"""
Will tell the spider to sit down and turn off servos
"""
if initial:
return
if int(actuatorVal) == 0:
self.standUp('1', False)
elif self.loco.state != "sitting":
self.loco.setMoving(False)
self.loco.streamGait(self.gaits["stand"])
self.loco.performGait("sitDown")
self.loco.turnOffServos()
self.loco.state = "sitting"
self.loco.currentDir = None
def standUp(self, actuatorVal, initial=False):
"""
Will tell the spider to stand up
"""
if initial or int(actuatorVal) == 0:
return
if self.loco.state != "standing":
self.loco.performGait("standUp")
self.loco.state = "standing"
self.loco.currentDir = None
def wave(self, actuatorVal, initial=False):
"""
Tell the spider to wave and then return to a standing position
"""
if initial or int(actuatorVal) == 0:
return
self.loco.setMoving(False)
self.loco.streamGait(self.gaits["stand"])
self.loco.streamGait(self.gaits["wave"])
self.loco.streamGait(self.gaits["stand"])
self.loco.state = "standing"
self.loco.currentDir = None
def clap(self, actuatorVal, initial=False):
"""
Tell the spider to clap and then return to a standing position
"""
if initial or int(actuatorVal) == 0:
return
self.loco.setMoving(False)
self.loco.streamGait(self.gaits["stand"])
self.loco.streamGait(self.gaits["clap"])
self.loco.streamGait(self.gaits["stand"])
self.loco.state = "standing"
self.loco.currentDir = None
def threaten(self, actuatorVal, initial=False):
"""
Tell the spider to threaten and then return to a standing position
"""
if initial or int(actuatorVal) == 0:
return
dir = self.loco.currentDir
self.loco.setMoving(False)
self.loco.streamGait(self.gaits["stand"])
if dir is None:
print "(ACTU) no direction"
self.loco.streamGait(self.gaits["threaten"])
else:
print "(ACTU) got dirrection"
self.loco.streamGait(self.gaits["threaten"].cloneAndRotate(dir))
self.loco.streamGait(self.gaits["stand"])
self.loco.state = "standing"
self.loco.currentDir = None
def loadGait(self, typeOfGait, actuatorVal, initial=False):
"""
Load different types of gaits for the spider to use while walking
typeOfGait (string): The type of gait (ex. normal, incline, gravel)
"""
if initial:
return
if (typeOfGait == "normal" or int(actuatorVal) == 0) and self.currentGaits != "normal":
self.loco.storeGait(self.gaits["walk1"], 2)
self.loco.storeGait(self.gaits["walk2"], 4)
self.currentGaits = "normal"
elif typeOfGait == "incline" and self.currentGaits != "incline":
self.loco.storeGait(self.gaits["walk1Incline"], 2)
self.loco.storeGait(self.gaits["walk2Incline"], 4)
self.currentGaits = "incline"
elif typeOfGait == "gravel" and self.currentGaits != "gravel":
self.loco.storeGait(self.gaits["walk1Gravel"], 2)
self.loco.storeGait(self.gaits["walk2Gravel"], 4)
self.currentGaits = "gravel"
else:
print "(ACTU) Unknown gait requested"
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
2486,
15495,
199,
5869,
19348,
16530,
14,
647,
446,
9762,
18982,
16530,
18599,
199,
2486,
15495,
199,
199,
1918,
5445,
367,
314,
18094,
14,
12823,
506,
7688,
370,
1570,
314,
16072,
1405,
626,
314,
18094,
911,
886,
14,
199,
624,
199,
199,
646,
1973,
14,
5586,
14,
2232,
17969,
465,
3016,
17969,
199,
199,
533,
428,
12508,
19348,
16530,
2461,
8,
2232,
17969,
14,
19348,
16530,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
13270,
12,
5709,
63,
576,
304,
267,
291,
14,
1818,
17295,
1405,
275,
298,
3302,
2,
267,
291,
14,
912,
39,
2781,
480,
3302,
401,
413,
9,
398,
862,
26,
288,
291,
14,
320,
331,
275,
13270,
14,
72,
954,
14,
362,
2461,
3244,
2175,
804,
8,
2232,
17969,
14,
2041,
331,
15335,
3110,
2461,
9,
288,
291,
14,
5294,
1405,
275,
5709,
63,
576,
905,
17295,
1405,
937,
267,
871,
12746,
26,
288,
870,
7340,
3036,
53,
9,
12539,
26,
3835,
331,
503,
9647,
1405,
440,
1911,
2122,
288,
4458,
2801,
17,
9,
2378,
347,
13867,
3514,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
12823,
11480,
314,
18094,
370,
13867,
3224,
436,
7485,
2331,
27415,
736,
267,
408,
267,
340,
2536,
26,
288,
372,
398,
340,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
291,
14,
7935,
1721,
360,
17,
297,
756,
9,
398,
916,
291,
14,
320,
331,
14,
929,
1137,
298,
2221,
1337,
582,
288,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
288,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
288,
291,
14,
320,
331,
14,
15795,
39,
2781,
480,
2221,
3514,
531,
288,
291,
14,
320,
331,
14,
353,
5195,
1505,
86,
736,
342,
288,
291,
14,
320,
331,
14,
929,
275,
298,
2221,
1337,
2,
288,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
10584,
1721,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
12823,
11480,
314,
18094,
370,
10584,
1536,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
340,
291,
14,
320,
331,
14,
929,
1137,
298,
18126,
582,
288,
291,
14,
320,
331,
14,
15795,
39,
2781,
480,
7935,
1721,
531,
288,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
288,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
12204,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
30528,
314,
18094,
370,
12204,
436,
2066,
372,
370,
282,
10584,
316,
3421,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
10024,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
267,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
286,
4762,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
30528,
314,
18094,
370,
286,
4762,
436,
2066,
372,
370,
282,
10584,
316,
3421,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
3995,
80,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
267,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
294,
622,
78,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
30528,
314,
18094,
370,
294,
622,
78,
436,
2066,
372,
370,
282,
10584,
316,
3421,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
2935,
275,
291,
14,
320,
331,
14,
1818,
3567,
398,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
340,
2935,
365,
488,
26,
288,
870,
7340,
3036,
53,
9,
949,
7581,
2,
288,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
273,
622,
78,
3135,
267,
587,
26,
288,
870,
7340,
3036,
53,
9,
4788,
2935,
4017,
2,
288,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
273,
622,
78,
4140,
6311,
3325,
32638,
8,
694,
430,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
267,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
2248,
39,
2781,
8,
277,
12,
730,
3466,
39,
2781,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
7190,
3365,
2943,
402,
16072,
1405,
367,
314,
18094,
370,
675,
1830,
12778,
316,
398,
730,
3466,
39,
2781,
334,
875,
304,
710,
730,
402,
486,
2781,
334,
476,
14,
3293,
12,
315,
429,
1132,
12,
1999,
1090,
9,
267,
408,
267,
340,
2536,
26,
288,
372,
398,
340,
334,
466,
3466,
39,
2781,
508,
298,
3302,
2,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
9,
436,
291,
14,
1818,
17295,
1405,
1137,
298,
3302,
582,
288,
291,
14,
320,
331,
14,
1617,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7757,
17,
2255,
499,
9,
288,
291,
14,
320,
331,
14,
1617,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7757,
18,
2255,
841,
9,
288,
291,
14,
1818,
17295,
1405
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
2486,
15495,
199,
5869,
19348,
16530,
14,
647,
446,
9762,
18982,
16530,
18599,
199,
2486,
15495,
199,
199,
1918,
5445,
367,
314,
18094,
14,
12823,
506,
7688,
370,
1570,
314,
16072,
1405,
626,
314,
18094,
911,
886,
14,
199,
624,
199,
199,
646,
1973,
14,
5586,
14,
2232,
17969,
465,
3016,
17969,
199,
199,
533,
428,
12508,
19348,
16530,
2461,
8,
2232,
17969,
14,
19348,
16530,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
13270,
12,
5709,
63,
576,
304,
267,
291,
14,
1818,
17295,
1405,
275,
298,
3302,
2,
267,
291,
14,
912,
39,
2781,
480,
3302,
401,
413,
9,
398,
862,
26,
288,
291,
14,
320,
331,
275,
13270,
14,
72,
954,
14,
362,
2461,
3244,
2175,
804,
8,
2232,
17969,
14,
2041,
331,
15335,
3110,
2461,
9,
288,
291,
14,
5294,
1405,
275,
5709,
63,
576,
905,
17295,
1405,
937,
267,
871,
12746,
26,
288,
870,
7340,
3036,
53,
9,
12539,
26,
3835,
331,
503,
9647,
1405,
440,
1911,
2122,
288,
4458,
2801,
17,
9,
2378,
347,
13867,
3514,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
12823,
11480,
314,
18094,
370,
13867,
3224,
436,
7485,
2331,
27415,
736,
267,
408,
267,
340,
2536,
26,
288,
372,
398,
340,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
291,
14,
7935,
1721,
360,
17,
297,
756,
9,
398,
916,
291,
14,
320,
331,
14,
929,
1137,
298,
2221,
1337,
582,
288,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
288,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
288,
291,
14,
320,
331,
14,
15795,
39,
2781,
480,
2221,
3514,
531,
288,
291,
14,
320,
331,
14,
353,
5195,
1505,
86,
736,
342,
288,
291,
14,
320,
331,
14,
929,
275,
298,
2221,
1337,
2,
288,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
10584,
1721,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
12823,
11480,
314,
18094,
370,
10584,
1536,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
340,
291,
14,
320,
331,
14,
929,
1137,
298,
18126,
582,
288,
291,
14,
320,
331,
14,
15795,
39,
2781,
480,
7935,
1721,
531,
288,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
288,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
12204,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
30528,
314,
18094,
370,
12204,
436,
2066,
372,
370,
282,
10584,
316,
3421,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
10024,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
267,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
286,
4762,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
30528,
314,
18094,
370,
286,
4762,
436,
2066,
372,
370,
282,
10584,
316,
3421,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
3995,
80,
3135,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
267,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
294,
622,
78,
8,
277,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
30528,
314,
18094,
370,
294,
622,
78,
436,
2066,
372,
370,
282,
10584,
316,
3421,
267,
408,
267,
340,
2536,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
26,
288,
372,
398,
2935,
275,
291,
14,
320,
331,
14,
1818,
3567,
398,
291,
14,
320,
331,
14,
409,
29783,
8,
797,
9,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
340,
2935,
365,
488,
26,
288,
870,
7340,
3036,
53,
9,
949,
7581,
2,
288,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
273,
622,
78,
3135,
267,
587,
26,
288,
870,
7340,
3036,
53,
9,
4788,
2935,
4017,
2,
288,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
273,
622,
78,
4140,
6311,
3325,
32638,
8,
694,
430,
267,
291,
14,
320,
331,
14,
1745,
39,
2781,
8,
277,
14,
5294,
1405,
905,
7935,
3135,
267,
291,
14,
320,
331,
14,
929,
275,
298,
18126,
2,
267,
291,
14,
320,
331,
14,
1818,
3567,
275,
488,
339,
347,
2248,
39,
2781,
8,
277,
12,
730,
3466,
39,
2781,
12,
2454,
16530,
7562,
12,
2536,
29,
797,
304,
267,
408,
267,
7190,
3365,
2943,
402,
16072,
1405,
367,
314,
18094,
370,
675,
1830,
12778,
316,
398,
730,
3466,
39,
2781,
334,
875,
304,
710,
730,
402,
486,
2781,
334,
476,
14,
3293,
12,
315,
429,
1132,
12,
1999,
1090,
9,
267,
408,
267,
340,
2536,
26,
288,
372,
398,
340,
334,
466,
3466,
39,
2781,
508,
298,
3302,
2,
503,
1109,
8,
2442,
16530,
7562,
9,
508,
378,
9,
436,
291,
14,
1818,
17295,
1405,
1137,
298,
3302,
582,
288,
291,
14,
320,
331,
14,
1617,
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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
] |
alphafoobar/intellij-community
|
python/helpers/pycharm/nose_utils.py
|
28
|
7224
|
import sys
import traceback
import datetime
import unittest
from tcmessages import TeamcityServiceMessages
from tcunittest import strclass
from tcunittest import TeamcityTestResult
try:
from nose.util import isclass # backwards compat
from nose.config import Config
from nose.result import TextTestResult
from nose import SkipTest
from nose.plugins.errorclass import ErrorClassPlugin
except (Exception, ):
e = sys.exc_info()[1]
raise NameError(
"Something went wrong, do you have nosetest installed? I got this error: %s" % e)
class TeamcityPlugin(ErrorClassPlugin, TextTestResult, TeamcityTestResult):
"""
TeamcityTest plugin for nose tests
"""
name = "TeamcityPlugin"
enabled = True
def __init__(self, stream=sys.stderr, descriptions=None, verbosity=1,
config=None, errorClasses=None):
super(TeamcityPlugin, self).__init__()
if errorClasses is None:
errorClasses = {}
self.errorClasses = errorClasses
if config is None:
config = Config()
self.config = config
self.output = stream
self.messages = TeamcityServiceMessages(self.output,
prepend_linebreak=True)
self.messages.testMatrixEntered()
self.current_suite = None
TextTestResult.__init__(self, stream, descriptions, verbosity, config,
errorClasses)
TeamcityTestResult.__init__(self, stream)
def configure(self, options, conf):
if not self.can_configure:
return
self.conf = conf
def addError(self, test, err):
exctype, value, tb = err
err = self.formatErr(err)
if exctype == SkipTest:
self.messages.testIgnored(self.getTestName(test), message='Skip')
else:
self.messages.testError(self.getTestName(test), message='Error', details=err, duration=self.__getDuration(test))
def formatErr(self, err):
exctype, value, tb = err
if isinstance(value, str):
try:
value = exctype(value)
except TypeError:
pass
return ''.join(traceback.format_exception(exctype, value, tb))
def is_gen(self, test):
if hasattr(test, "test") and hasattr(test.test, "descriptor"):
if test.test.descriptor is not None:
return True
return False
def getTestName(self, test):
if hasattr(test, "error_context"):
return test.error_context
test_name_full = str(test)
if self.is_gen(test):
return test_name_full
ind_1 = test_name_full.rfind('(')
if ind_1 != -1:
return test_name_full[:ind_1]
return test_name_full
def addFailure(self, test, err):
err = self.formatErr(err)
self.messages.testFailed(self.getTestName(test),
message='Failure', details=err)
def addSkip(self, test, reason):
self.messages.testIgnored(self.getTestName(test), message=reason)
def _getSuite(self, test):
if hasattr(test, "suite"):
suite = strclass(test.suite)
suite_location = test.suite.location
location = test.suite.abs_location
if hasattr(test, "lineno"):
location = location + ":" + str(test.lineno)
else:
location = location + ":" + str(test.test.lineno)
else:
suite = strclass(test.__class__)
suite_location = "python_nosetestid://" + suite
try:
from nose.util import func_lineno
if hasattr(test.test, "descriptor") and test.test.descriptor:
suite_location = "file://" + self.test_address(
test.test.descriptor)
location = suite_location + ":" + str(
func_lineno(test.test.descriptor))
else:
suite_location = "file://" + self.test_address(
test.test.test)
location = "file://" + self.test_address(
test.test.test) + ":" + str(func_lineno(test.test.test))
except:
test_id = test.id()
suite_id = test_id[:test_id.rfind(".")]
suite_location = "python_nosetestid://" + str(suite_id)
location = "python_nosetestid://" + str(test_id)
return (location, suite_location)
def test_address(self, test):
if hasattr(test, "address"):
return test.address()[0]
t = type(test)
file = None
import types, os
if (t == types.FunctionType or issubclass(t, type) or t == type
or isclass(test)):
module = getattr(test, '__module__', None)
if module is not None:
m = sys.modules[module]
file = getattr(m, '__file__', None)
if file is not None:
file = os.path.abspath(file)
if file.endswith("pyc"):
file = file[:-1]
return file
raise TypeError("I don't know what %s is (%s)" % (test, t))
def getSuiteName(self, test):
test_name_full = str(test)
ind_1 = test_name_full.rfind('(')
if self.is_gen(test) and ind_1 != -1:
ind = test_name_full[:ind_1].rfind('.')
if ind != -1:
return test_name_full[:ind]
if ind_1 != -1:
return test_name_full[ind_1 + 1: -1]
ind = test_name_full.rfind('.')
if ind != -1:
return test_name_full[:test_name_full.rfind(".")]
return test_name_full
def startTest(self, test):
location, suite_location = self._getSuite(test)
suite = self.getSuiteName(test)
if suite != self.current_suite:
if self.current_suite:
self.messages.testSuiteFinished(self.current_suite)
self.current_suite = suite
self.messages.testSuiteStarted(self.current_suite,
location=suite_location)
setattr(test, "startTime", datetime.datetime.now())
self.messages.testStarted(self.getTestName(test), location=location)
def stopTest(self, test):
duration = self.__getDuration(test)
self.messages.testFinished(self.getTestName(test),
duration=int(duration))
def __getDuration(self, test):
start = getattr(test, "startTime", datetime.datetime.now())
d = datetime.datetime.now() - start
duration = d.microseconds / 1000 + d.seconds * 1000 + d.days * 86400000
return duration
def finalize(self, result):
if self.current_suite:
self.messages.testSuiteFinished(self.current_suite)
self.current_suite = None
class TeamcityNoseRunner(unittest.TextTestRunner):
"""Test runner that supports teamcity output
"""
def __init__(self, stream=sys.stdout, descriptions=1, verbosity=1,
config=None):
if config is None:
config = Config()
self.config = config
unittest.TextTestRunner.__init__(self, stream, descriptions, verbosity)
def _makeResult(self):
return TeamcityPlugin(self.stream,
self.descriptions,
self.verbosity,
self.config)
def run(self, test):
"""Overrides to provide plugin hooks and defer all output to
the test result class.
"""
#for 2.5 compat
plugins = self.config.plugins
plugins.configure(self.config.options, self.config)
plugins.begin()
wrapper = plugins.prepareTest(test)
if wrapper is not None:
test = wrapper
# plugins can decorate or capture the output stream
wrapped = self.config.plugins.setOutputStream(self.stream)
if wrapped is not None:
self.stream = wrapped
result = self._makeResult()
test(result)
result.endLastSuite()
plugins.finalize(result)
return result
|
apache-2.0
|
[
646,
984,
199,
646,
5190,
199,
646,
2197,
199,
646,
2882,
199,
199,
504,
14415,
3431,
492,
11682,
3690,
3167,
14508,
199,
504,
14415,
2796,
492,
620,
533,
199,
504,
14415,
2796,
492,
11682,
3690,
13120,
421,
199,
893,
26,
523,
687,
11354,
14,
1974,
492,
365,
533,
327,
8552,
8434,
523,
687,
11354,
14,
888,
492,
4094,
523,
687,
11354,
14,
1099,
492,
4516,
13120,
523,
687,
11354,
492,
18795,
523,
687,
11354,
14,
5265,
14,
705,
533,
492,
4520,
2543,
5061,
199,
2590,
334,
1726,
12,
3461,
523,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
523,
746,
12746,
8,
272,
298,
20641,
22396,
6835,
12,
886,
1265,
1172,
11354,
396,
4903,
31,
473,
4788,
642,
1125,
26,
450,
83,
2,
450,
325,
9,
199,
199,
533,
11682,
3690,
5061,
8,
547,
2543,
5061,
12,
4516,
13120,
12,
11682,
3690,
13120,
304,
523,
408,
523,
11682,
3690,
774,
3589,
367,
11354,
2295,
523,
408,
523,
536,
275,
298,
13126,
3690,
5061,
2,
523,
5223,
275,
715,
819,
347,
636,
826,
721,
277,
12,
2547,
29,
1274,
14,
3083,
12,
18714,
29,
403,
12,
8661,
29,
17,
12,
2049,
1101,
29,
403,
12,
1125,
15711,
29,
403,
304,
272,
1613,
8,
13126,
3690,
5061,
12,
291,
2843,
826,
4533,
339,
340,
1125,
15711,
365,
488,
26,
489,
1125,
15711,
275,
1052,
339,
291,
14,
705,
15711,
275,
1125,
15711,
272,
340,
1101,
365,
488,
26,
489,
1101,
275,
4094,
342,
272,
291,
14,
888,
275,
1101,
272,
291,
14,
1199,
275,
2547,
272,
291,
14,
3431,
275,
11682,
3690,
3167,
14508,
8,
277,
14,
1199,
12,
489,
18213,
63,
604,
4785,
29,
549,
9,
272,
291,
14,
3431,
14,
396,
6443,
1327,
3014,
342,
272,
291,
14,
1818,
63,
5768,
275,
488,
272,
4516,
13120,
855,
826,
721,
277,
12,
2547,
12,
18714,
12,
8661,
12,
1101,
12,
489,
1125,
15711,
9,
272,
11682,
3690,
13120,
855,
826,
721,
277,
12,
2547,
9,
819,
347,
7908,
8,
277,
12,
1511,
12,
3743,
304,
272,
340,
440,
291,
14,
2425,
63,
6472,
26,
489,
372,
272,
291,
14,
2190,
275,
3743,
8330,
347,
1050,
547,
8,
277,
12,
511,
12,
2329,
304,
272,
444,
3667,
12,
574,
12,
7070,
275,
2329,
272,
2329,
275,
291,
14,
908,
5432,
8,
1508,
9,
272,
340,
444,
3667,
508,
18795,
26,
267,
291,
14,
3431,
14,
396,
19399,
2908,
8,
277,
14,
362,
774,
985,
8,
396,
395,
1245,
534,
7738,
358,
272,
587,
26,
267,
291,
14,
3431,
14,
396,
547,
8,
277,
14,
362,
774,
985,
8,
396,
395,
1245,
534,
547,
297,
2436,
29,
1508,
12,
7373,
29,
277,
855,
362,
13283,
8,
396,
430,
819,
347,
1475,
5432,
8,
277,
12,
2329,
304,
272,
444,
3667,
12,
574,
12,
7070,
275,
2329,
272,
340,
1228,
8,
585,
12,
620,
304,
489,
862,
26,
267,
574,
275,
444,
3667,
8,
585,
9,
489,
871,
3146,
26,
267,
986,
272,
372,
6522,
904,
8,
6894,
14,
908,
63,
1971,
8,
476,
3667,
12,
574,
12,
7070,
430,
819,
347,
365,
63,
2268,
8,
277,
12,
511,
304,
272,
340,
2688,
8,
396,
12,
298,
396,
531,
436,
2688,
8,
396,
14,
396,
12,
298,
4120,
2349,
489,
340,
511,
14,
396,
14,
4120,
365,
440,
488,
26,
267,
372,
715,
272,
372,
756,
8330,
347,
664,
774,
985,
8,
277,
12,
511,
304,
272,
340,
2688,
8,
396,
12,
298,
705,
63,
1100,
2349,
489,
372,
511,
14,
705,
63,
1100,
272,
511,
63,
354,
63,
2861,
275,
620,
8,
396,
9,
272,
340,
291,
14,
374,
63,
2268,
8,
396,
304,
489,
372,
511,
63,
354,
63,
2861,
339,
7654,
63,
17,
275,
511,
63,
354,
63,
2861,
14,
14542,
14097,
358,
272,
340,
7654,
63,
17,
1137,
446,
17,
26,
489,
372,
511,
63,
354,
63,
2861,
1491,
688,
63,
17,
61,
272,
372,
511,
63,
354,
63,
2861,
8330,
347,
1050,
6782,
8,
277,
12,
511,
12,
2329,
304,
272,
2329,
275,
291,
14,
908,
5432,
8,
1508,
9,
339,
291,
14,
3431,
14,
396,
4276,
8,
277,
14,
362,
774,
985,
8,
396,
395,
489,
1245,
534,
6782,
297,
2436,
29,
1508,
9,
8330,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
272,
291,
14,
3431,
14,
396,
19399,
2908,
8,
277,
14,
362,
774,
985,
8,
396,
395,
1245,
29,
5764,
9,
8330,
347,
485,
362,
6207,
8,
277,
12,
511,
304,
272,
340,
2688,
8,
396,
12,
298,
5768,
2349,
489,
5241,
275,
620,
533,
8,
396,
14,
5768,
9,
489,
5241,
63,
1985,
275,
511,
14,
5768,
14,
1985,
489,
2909,
275,
511,
14,
5768,
14,
2101,
63,
1985,
489,
340,
2688,
8,
396,
12,
298,
3469,
2349,
267,
2909,
275,
2909,
435,
14725,
435,
620,
8,
396,
14,
3469,
9,
489,
587,
26,
267,
2909,
275,
2909,
435,
14725,
435,
620,
8,
396,
14,
396,
14,
3469,
9,
272,
587,
26,
489,
5241,
275,
620,
533,
8,
396,
855,
533,
3368,
489,
5241,
63,
1985,
275,
298,
1548,
63,
21085,
396,
344,
30443,
435,
5241,
489,
862,
26,
267,
687,
11354,
14,
1974,
492,
2562,
63,
3469,
398,
340,
2688,
8,
396,
14,
396,
12,
298,
4120,
531,
436,
511,
14,
396,
14,
4120,
26,
881,
5241,
63,
1985,
275,
298,
493,
30443,
435,
291,
14,
396,
63,
1562,
8,
288,
511,
14,
396,
14,
4120,
9,
881,
2909,
275,
5241,
63,
1985,
435,
14725,
435,
620,
8,
288,
2562,
63,
3469,
8,
396,
14,
396,
14,
4120,
430,
267,
587,
26,
881,
5241,
63,
1985,
275,
298,
493,
30443,
435,
291,
14,
396,
63,
1562,
8,
288,
511,
14,
396,
14,
396,
9,
881,
2909,
275,
298,
493,
30443,
435,
291,
14,
396,
63,
1562,
8,
288,
511,
14,
396,
14,
396,
9,
435,
14725,
435,
620,
8,
1532,
63,
3469,
8,
396,
14,
396,
14,
396,
430,
489,
871,
26,
267,
511,
63,
344,
275,
511,
14,
344,
342,
267,
5241,
63,
344,
275,
511,
63,
344,
1491,
396,
63,
344,
14,
14542,
15857,
61,
267,
5241,
63,
1985,
275,
298,
1548,
63,
21085,
396,
344,
30443,
435,
620,
8,
5768
] |
[
984,
199,
646,
5190,
199,
646,
2197,
199,
646,
2882,
199,
199,
504,
14415,
3431,
492,
11682,
3690,
3167,
14508,
199,
504,
14415,
2796,
492,
620,
533,
199,
504,
14415,
2796,
492,
11682,
3690,
13120,
421,
199,
893,
26,
523,
687,
11354,
14,
1974,
492,
365,
533,
327,
8552,
8434,
523,
687,
11354,
14,
888,
492,
4094,
523,
687,
11354,
14,
1099,
492,
4516,
13120,
523,
687,
11354,
492,
18795,
523,
687,
11354,
14,
5265,
14,
705,
533,
492,
4520,
2543,
5061,
199,
2590,
334,
1726,
12,
3461,
523,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
523,
746,
12746,
8,
272,
298,
20641,
22396,
6835,
12,
886,
1265,
1172,
11354,
396,
4903,
31,
473,
4788,
642,
1125,
26,
450,
83,
2,
450,
325,
9,
199,
199,
533,
11682,
3690,
5061,
8,
547,
2543,
5061,
12,
4516,
13120,
12,
11682,
3690,
13120,
304,
523,
408,
523,
11682,
3690,
774,
3589,
367,
11354,
2295,
523,
408,
523,
536,
275,
298,
13126,
3690,
5061,
2,
523,
5223,
275,
715,
819,
347,
636,
826,
721,
277,
12,
2547,
29,
1274,
14,
3083,
12,
18714,
29,
403,
12,
8661,
29,
17,
12,
2049,
1101,
29,
403,
12,
1125,
15711,
29,
403,
304,
272,
1613,
8,
13126,
3690,
5061,
12,
291,
2843,
826,
4533,
339,
340,
1125,
15711,
365,
488,
26,
489,
1125,
15711,
275,
1052,
339,
291,
14,
705,
15711,
275,
1125,
15711,
272,
340,
1101,
365,
488,
26,
489,
1101,
275,
4094,
342,
272,
291,
14,
888,
275,
1101,
272,
291,
14,
1199,
275,
2547,
272,
291,
14,
3431,
275,
11682,
3690,
3167,
14508,
8,
277,
14,
1199,
12,
489,
18213,
63,
604,
4785,
29,
549,
9,
272,
291,
14,
3431,
14,
396,
6443,
1327,
3014,
342,
272,
291,
14,
1818,
63,
5768,
275,
488,
272,
4516,
13120,
855,
826,
721,
277,
12,
2547,
12,
18714,
12,
8661,
12,
1101,
12,
489,
1125,
15711,
9,
272,
11682,
3690,
13120,
855,
826,
721,
277,
12,
2547,
9,
819,
347,
7908,
8,
277,
12,
1511,
12,
3743,
304,
272,
340,
440,
291,
14,
2425,
63,
6472,
26,
489,
372,
272,
291,
14,
2190,
275,
3743,
8330,
347,
1050,
547,
8,
277,
12,
511,
12,
2329,
304,
272,
444,
3667,
12,
574,
12,
7070,
275,
2329,
272,
2329,
275,
291,
14,
908,
5432,
8,
1508,
9,
272,
340,
444,
3667,
508,
18795,
26,
267,
291,
14,
3431,
14,
396,
19399,
2908,
8,
277,
14,
362,
774,
985,
8,
396,
395,
1245,
534,
7738,
358,
272,
587,
26,
267,
291,
14,
3431,
14,
396,
547,
8,
277,
14,
362,
774,
985,
8,
396,
395,
1245,
534,
547,
297,
2436,
29,
1508,
12,
7373,
29,
277,
855,
362,
13283,
8,
396,
430,
819,
347,
1475,
5432,
8,
277,
12,
2329,
304,
272,
444,
3667,
12,
574,
12,
7070,
275,
2329,
272,
340,
1228,
8,
585,
12,
620,
304,
489,
862,
26,
267,
574,
275,
444,
3667,
8,
585,
9,
489,
871,
3146,
26,
267,
986,
272,
372,
6522,
904,
8,
6894,
14,
908,
63,
1971,
8,
476,
3667,
12,
574,
12,
7070,
430,
819,
347,
365,
63,
2268,
8,
277,
12,
511,
304,
272,
340,
2688,
8,
396,
12,
298,
396,
531,
436,
2688,
8,
396,
14,
396,
12,
298,
4120,
2349,
489,
340,
511,
14,
396,
14,
4120,
365,
440,
488,
26,
267,
372,
715,
272,
372,
756,
8330,
347,
664,
774,
985,
8,
277,
12,
511,
304,
272,
340,
2688,
8,
396,
12,
298,
705,
63,
1100,
2349,
489,
372,
511,
14,
705,
63,
1100,
272,
511,
63,
354,
63,
2861,
275,
620,
8,
396,
9,
272,
340,
291,
14,
374,
63,
2268,
8,
396,
304,
489,
372,
511,
63,
354,
63,
2861,
339,
7654,
63,
17,
275,
511,
63,
354,
63,
2861,
14,
14542,
14097,
358,
272,
340,
7654,
63,
17,
1137,
446,
17,
26,
489,
372,
511,
63,
354,
63,
2861,
1491,
688,
63,
17,
61,
272,
372,
511,
63,
354,
63,
2861,
8330,
347,
1050,
6782,
8,
277,
12,
511,
12,
2329,
304,
272,
2329,
275,
291,
14,
908,
5432,
8,
1508,
9,
339,
291,
14,
3431,
14,
396,
4276,
8,
277,
14,
362,
774,
985,
8,
396,
395,
489,
1245,
534,
6782,
297,
2436,
29,
1508,
9,
8330,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
272,
291,
14,
3431,
14,
396,
19399,
2908,
8,
277,
14,
362,
774,
985,
8,
396,
395,
1245,
29,
5764,
9,
8330,
347,
485,
362,
6207,
8,
277,
12,
511,
304,
272,
340,
2688,
8,
396,
12,
298,
5768,
2349,
489,
5241,
275,
620,
533,
8,
396,
14,
5768,
9,
489,
5241,
63,
1985,
275,
511,
14,
5768,
14,
1985,
489,
2909,
275,
511,
14,
5768,
14,
2101,
63,
1985,
489,
340,
2688,
8,
396,
12,
298,
3469,
2349,
267,
2909,
275,
2909,
435,
14725,
435,
620,
8,
396,
14,
3469,
9,
489,
587,
26,
267,
2909,
275,
2909,
435,
14725,
435,
620,
8,
396,
14,
396,
14,
3469,
9,
272,
587,
26,
489,
5241,
275,
620,
533,
8,
396,
855,
533,
3368,
489,
5241,
63,
1985,
275,
298,
1548,
63,
21085,
396,
344,
30443,
435,
5241,
489,
862,
26,
267,
687,
11354,
14,
1974,
492,
2562,
63,
3469,
398,
340,
2688,
8,
396,
14,
396,
12,
298,
4120,
531,
436,
511,
14,
396,
14,
4120,
26,
881,
5241,
63,
1985,
275,
298,
493,
30443,
435,
291,
14,
396,
63,
1562,
8,
288,
511,
14,
396,
14,
4120,
9,
881,
2909,
275,
5241,
63,
1985,
435,
14725,
435,
620,
8,
288,
2562,
63,
3469,
8,
396,
14,
396,
14,
4120,
430,
267,
587,
26,
881,
5241,
63,
1985,
275,
298,
493,
30443,
435,
291,
14,
396,
63,
1562,
8,
288,
511,
14,
396,
14,
396,
9,
881,
2909,
275,
298,
493,
30443,
435,
291,
14,
396,
63,
1562,
8,
288,
511,
14,
396,
14,
396,
9,
435,
14725,
435,
620,
8,
1532,
63,
3469,
8,
396,
14,
396,
14,
396,
430,
489,
871,
26,
267,
511,
63,
344,
275,
511,
14,
344,
342,
267,
5241,
63,
344,
275,
511,
63,
344,
1491,
396,
63,
344,
14,
14542,
15857,
61,
267,
5241,
63,
1985,
275,
298,
1548,
63,
21085,
396,
344,
30443,
435,
620,
8,
5768,
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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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
] |
iulianbute/labs
|
python/solutii/marius_ilau/paint/fill.py
|
2
|
2137
|
#!/usr/bin/env python
# *-* coding: UTF-8 *-*
"""Tuxy dorește să împlementeze un nou paint pentru consolă.
În timpul dezvoltării proiectului s-a izbit de o problemă
pe care nu o poate rezolva singur și a apelat la ajutorul tău.
El dorește să adauge o unealtă care să permită umplerea unei
forme închise.
Exemplu:
Pornim de la imaginea inițială reprezentată mai jos, trebuie să
umplem formele în care se află "x":
|-----*------| |******------| |************|
|--x--*------| |******------| |************|
|******------| -----> |******------| -----> |************|
|-----******-| |-----******-| |-----*******|
|-----*---*--| |-----*---*--| |-----*---***|
|-----*---*-x| |-----*---*--| |-----*---***|
"""
def umple(imagine, punct):
"""Funcția primește reprezentarea imaginii și coordonatele unui
punct.
În cazul în care punctul se află într-o formă închisă trebuie să
umple forma respectivă cu caracterul "*"
"""
start_x = punct[0]
start_y = punct[1]
if imagine[start_x][start_y] == '*':
return
imagine[start_x][start_y] = '*'
if punct[1] < (len(imagine[0]) - 1):
umple(imagine, (start_x, start_y + 1))
if punct[1] >= 1:
umple(imagine, (start_x, start_y - 1))
if punct[0] < (len(imagine) - 1):
umple(imagine, (start_x + 1, start_y))
if punct[0] >= 1:
umple(imagine, (start_x - 1, start_y))
return imagine
def main():
""" It's the main function Sherlock """
imaginea = [
["-", "-", "-", "-", "-", "*", "-", "-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-", "*", "-", "-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-", "*", "-", "-", "-", "-", "-", "-"],
["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "-"],
["-", "-", "-", "-", "-", "*", "-", "*", "-", "-", "*", "-"],
["-", "-", "-", "-", "-", "*", "-", "*", "-", "-", "*", "-"],
]
umple(imaginea, (1, 3))
umple(imaginea, (5, 11))
if __name__ == "__main__":
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
627,
13,
10,
2803,
26,
9094,
13,
24,
627,
13,
10,
199,
199,
624,
30669,
1702,
366,
720,
133,
248,
266,
308,
129,
226,
13333,
107,
575,
1410,
266,
806,
625,
302,
810,
32055,
12374,
454,
85,
406,
7873,
129,
226,
14,
199,
199,
128,
237,
78,
3367,
311,
348,
477,
90,
5650,
84,
129,
226,
322,
73,
557,
73,
449,
348,
1907,
308,
13,
65,
284,
90,
2075,
477,
312,
5160,
129,
226,
199,
321,
10296,
15699,
312,
1115,
323,
295,
90,
393,
3042,
308,
316,
300,
221,
133,
248,
73,
282,
282,
321,
4452,
1127,
282,
74,
4139,
348,
307,
129,
226,
85,
14,
199,
199,
10420,
366,
720,
133,
248,
266,
308,
129,
226,
282,
983,
17730,
312,
625,
69,
4478,
129,
226,
10296,
308,
129,
226,
11291,
129,
226,
399,
575,
8273,
625,
24708,
199,
509,
278,
13333,
107,
78,
335,
572,
14,
199,
199,
920,
2109,
10836,
26,
199,
199,
48,
6161,
1017,
477,
1127,
18884,
2598,
65,
20364,
133,
250,
2380,
129,
226,
295,
657,
90,
484,
292,
129,
226,
610,
73,
1335,
736,
12,
20991,
464,
1873,
308,
129,
226,
199,
85,
575,
77,
367,
278,
274,
13333,
107,
78,
10296,
542,
282,
2327,
129,
226,
298,
88,
582,
819,
1204,
9858,
10,
8648,
92,
3515,
1204,
26537,
8648,
92,
260,
1204,
1801,
1116,
92,
523,
1204,
306,
88,
306,
10,
8648,
92,
3515,
1204,
26537,
8648,
92,
260,
1204,
1801,
1116,
92,
523,
1204,
26537,
8648,
92,
221,
4099,
5118,
221,
1204,
26537,
8648,
92,
221,
4099,
5118,
1204,
1801,
1116,
92,
523,
1204,
9858,
1116,
25376,
92,
3515,
1204,
9858,
1116,
25376,
92,
260,
1204,
9858,
1116,
9153,
92,
523,
1204,
9858,
10,
2595,
10,
306,
92,
3515,
1204,
9858,
10,
2595,
10,
306,
92,
260,
1204,
9858,
10,
2595,
9153,
92,
523,
1204,
9858,
10,
2595,
1837,
88,
92,
3515,
1204,
9858,
10,
2595,
10,
306,
92,
260,
1204,
9858,
10,
2595,
9153,
92,
199,
199,
624,
421,
199,
318,
399,
575,
8,
11744,
2598,
12,
299,
4638,
304,
272,
408,
7465,
133,
250,
4674,
21619,
133,
248,
266,
295,
657,
90,
484,
6789,
18884,
903,
5908,
221,
133,
248,
73,
11021,
265,
323,
274,
625,
1907,
272,
299,
4638,
14,
339,
13333,
237,
78,
1704,
90,
348,
13333,
107,
78,
10296,
299,
4638,
348,
542,
282,
2327,
129,
226,
13333,
107,
343,
82,
13,
79,
1824,
129,
226,
13333,
107,
78,
30883,
129,
226,
20991,
464,
1873,
308,
129,
226,
272,
399,
575,
367,
391,
13917,
280,
86,
129,
226,
30353,
9590,
6747,
348,
22423,
272,
408,
272,
1343,
63,
88,
275,
299,
4638,
59,
16,
61,
272,
1343,
63,
89,
275,
299,
4638,
59,
17,
61,
272,
340,
18884,
2598,
59,
928,
63,
88,
1527,
928,
63,
89,
61,
508,
22969,
267,
372,
272,
18884,
2598,
59,
928,
63,
88,
1527,
928,
63,
89,
61,
275,
13626,
272,
340,
299,
4638,
59,
17,
61,
665,
334,
552,
8,
11744,
2598,
59,
16,
566,
446,
413,
304,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
12,
1343,
63,
89,
435,
413,
430,
272,
340,
299,
4638,
59,
17,
61,
2356,
413,
26,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
12,
1343,
63,
89,
446,
413,
430,
272,
340,
299,
4638,
59,
16,
61,
665,
334,
552,
8,
11744,
2598,
9,
446,
413,
304,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
435,
413,
12,
1343,
63,
89,
430,
272,
340,
299,
4638,
59,
16,
61,
2356,
413,
26,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
446,
413,
12,
1343,
63,
89,
430,
272,
372,
18884,
2598,
421,
199,
318,
2446,
837,
272,
408,
2779,
1159,
314,
2446,
805,
428,
2523,
831,
408,
272,
18884,
2598,
65,
275,
359,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
2255,
267,
2097,
14421,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
2255,
272,
1622,
272,
399,
575,
8,
11744,
2598,
65,
12,
334,
17,
12,
650,
430,
272,
399,
575,
8,
11744,
2598,
65,
12,
334,
21,
12,
4119,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
627,
13,
10,
2803,
26,
9094,
13,
24,
627,
13,
10,
199,
199,
624,
30669,
1702,
366,
720,
133,
248,
266,
308,
129,
226,
13333,
107,
575,
1410,
266,
806,
625,
302,
810,
32055,
12374,
454,
85,
406,
7873,
129,
226,
14,
199,
199,
128,
237,
78,
3367,
311,
348,
477,
90,
5650,
84,
129,
226,
322,
73,
557,
73,
449,
348,
1907,
308,
13,
65,
284,
90,
2075,
477,
312,
5160,
129,
226,
199,
321,
10296,
15699,
312,
1115,
323,
295,
90,
393,
3042,
308,
316,
300,
221,
133,
248,
73,
282,
282,
321,
4452,
1127,
282,
74,
4139,
348,
307,
129,
226,
85,
14,
199,
199,
10420,
366,
720,
133,
248,
266,
308,
129,
226,
282,
983,
17730,
312,
625,
69,
4478,
129,
226,
10296,
308,
129,
226,
11291,
129,
226,
399,
575,
8273,
625,
24708,
199,
509,
278,
13333,
107,
78,
335,
572,
14,
199,
199,
920,
2109,
10836,
26,
199,
199,
48,
6161,
1017,
477,
1127,
18884,
2598,
65,
20364,
133,
250,
2380,
129,
226,
295,
657,
90,
484,
292,
129,
226,
610,
73,
1335,
736,
12,
20991,
464,
1873,
308,
129,
226,
199,
85,
575,
77,
367,
278,
274,
13333,
107,
78,
10296,
542,
282,
2327,
129,
226,
298,
88,
582,
819,
1204,
9858,
10,
8648,
92,
3515,
1204,
26537,
8648,
92,
260,
1204,
1801,
1116,
92,
523,
1204,
306,
88,
306,
10,
8648,
92,
3515,
1204,
26537,
8648,
92,
260,
1204,
1801,
1116,
92,
523,
1204,
26537,
8648,
92,
221,
4099,
5118,
221,
1204,
26537,
8648,
92,
221,
4099,
5118,
1204,
1801,
1116,
92,
523,
1204,
9858,
1116,
25376,
92,
3515,
1204,
9858,
1116,
25376,
92,
260,
1204,
9858,
1116,
9153,
92,
523,
1204,
9858,
10,
2595,
10,
306,
92,
3515,
1204,
9858,
10,
2595,
10,
306,
92,
260,
1204,
9858,
10,
2595,
9153,
92,
523,
1204,
9858,
10,
2595,
1837,
88,
92,
3515,
1204,
9858,
10,
2595,
10,
306,
92,
260,
1204,
9858,
10,
2595,
9153,
92,
199,
199,
624,
421,
199,
318,
399,
575,
8,
11744,
2598,
12,
299,
4638,
304,
272,
408,
7465,
133,
250,
4674,
21619,
133,
248,
266,
295,
657,
90,
484,
6789,
18884,
903,
5908,
221,
133,
248,
73,
11021,
265,
323,
274,
625,
1907,
272,
299,
4638,
14,
339,
13333,
237,
78,
1704,
90,
348,
13333,
107,
78,
10296,
299,
4638,
348,
542,
282,
2327,
129,
226,
13333,
107,
343,
82,
13,
79,
1824,
129,
226,
13333,
107,
78,
30883,
129,
226,
20991,
464,
1873,
308,
129,
226,
272,
399,
575,
367,
391,
13917,
280,
86,
129,
226,
30353,
9590,
6747,
348,
22423,
272,
408,
272,
1343,
63,
88,
275,
299,
4638,
59,
16,
61,
272,
1343,
63,
89,
275,
299,
4638,
59,
17,
61,
272,
340,
18884,
2598,
59,
928,
63,
88,
1527,
928,
63,
89,
61,
508,
22969,
267,
372,
272,
18884,
2598,
59,
928,
63,
88,
1527,
928,
63,
89,
61,
275,
13626,
272,
340,
299,
4638,
59,
17,
61,
665,
334,
552,
8,
11744,
2598,
59,
16,
566,
446,
413,
304,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
12,
1343,
63,
89,
435,
413,
430,
272,
340,
299,
4638,
59,
17,
61,
2356,
413,
26,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
12,
1343,
63,
89,
446,
413,
430,
272,
340,
299,
4638,
59,
16,
61,
665,
334,
552,
8,
11744,
2598,
9,
446,
413,
304,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
435,
413,
12,
1343,
63,
89,
430,
272,
340,
299,
4638,
59,
16,
61,
2356,
413,
26,
267,
399,
575,
8,
11744,
2598,
12,
334,
928,
63,
88,
446,
413,
12,
1343,
63,
89,
430,
272,
372,
18884,
2598,
421,
199,
318,
2446,
837,
272,
408,
2779,
1159,
314,
2446,
805,
428,
2523,
831,
408,
272,
18884,
2598,
65,
275,
359,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
2255,
267,
2097,
14421,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
8969,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
2255,
267,
16984,
401,
3905,
401,
3905,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
401,
8969,
401,
3905,
401,
3905,
401,
8969,
401,
3905,
2255,
272,
1622,
272,
399,
575,
8,
11744,
2598,
65,
12,
334,
17,
12,
650,
430,
272,
399,
575,
8,
11744,
2598,
65,
12,
334,
21,
12,
4119,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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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
] |
ksasi/PerfKitBenchmarker
|
perfkitbenchmarker/packages/mongodb_server.py
|
10
|
1715
|
# Copyright 2014 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.
"""Module containing mongodb installation and cleanup functions."""
def YumInstall(vm):
"""Installs the mongodb package on the VM."""
mongodb_repo = (
'[mongodb]\nname=MongoDB Repository\nbaseurl='
'http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/\n'
'gpgcheck=0\nenabled=1')
vm.RemoteCommand('echo "%s" | sudo tee /etc/yum.repos.d/mongodb.repo' %
mongodb_repo)
vm.InstallPackages('mongodb-org-server')
def AptInstall(vm):
"""Installs the mongodb package on the VM."""
vm.InstallPackages('mongodb-server')
def YumUninstall(vm):
"""Uninstalls the mongodb package on the VM."""
vm.RemoteCommand('sudo rm /etc/yum.repos.d/mongodb.repo')
def YumGetServiceName(vm):
"""Returns the name of the mongodb service."""
return 'mongod'
def AptGetServiceName(vm):
"""Returns the name of the mongodb service."""
return 'mongodb'
def YumGetPathToConfig(vm):
"""Returns the path to the mongodb config file."""
return '/etc/mongod.conf'
def AptGetPathToConfig(vm):
"""Returns the path to the mongodb config file."""
return '/etc/mongodb.conf'
|
apache-2.0
|
[
3,
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
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,
257,
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,
421,
199,
624,
2377,
3035,
32315,
13152,
12096,
436,
9058,
3423,
1041,
421,
199,
318,
1488,
453,
8154,
8,
2611,
304,
523,
408,
8154,
83,
314,
32315,
13152,
2559,
641,
314,
7525,
1041,
523,
32315,
13152,
63,
3417,
275,
334,
489,
6730,
22130,
13152,
7272,
78,
354,
29,
20393,
2846,
24426,
60,
78,
28937,
534,
489,
283,
1014,
921,
20373,
13,
18371,
14,
22130,
13152,
14,
1308,
15,
3417,
15,
17164,
15,
736,
15,
88,
1184,
63,
772,
6307,
78,
7,
489,
283,
21284,
1074,
29,
16,
60,
78,
3827,
29,
17,
358,
523,
4169,
14,
6713,
3110,
360,
7878,
2071,
83,
2,
1204,
14682,
1565,
69,
1182,
6839,
15,
22108,
14,
11857,
14,
68,
15,
22130,
13152,
14,
3417,
7,
450,
673,
32315,
13152,
63,
3417,
9,
523,
4169,
14,
8154,
25135,
360,
22130,
13152,
13,
1308,
13,
1000,
358,
421,
199,
318,
437,
541,
8154,
8,
2611,
304,
523,
408,
8154,
83,
314,
32315,
13152,
2559,
641,
314,
7525,
1041,
523,
4169,
14,
8154,
25135,
360,
22130,
13152,
13,
1000,
358,
421,
199,
318,
1488,
453,
1358,
3174,
8,
2611,
304,
523,
408,
1358,
3174,
83,
314,
32315,
13152,
2559,
641,
314,
7525,
1041,
523,
4169,
14,
6713,
3110,
360,
12095,
14267,
1182,
6839,
15,
22108,
14,
11857,
14,
68,
15,
22130,
13152,
14,
3417,
358,
421,
199,
318,
1488,
453,
1002,
3167,
985,
8,
2611,
304,
523,
408,
3407,
314,
536,
402,
314,
32315,
13152,
2435,
1041,
523,
372,
283,
22130,
364,
7,
421,
199,
318,
437,
541,
1002,
3167,
985,
8,
2611,
304,
523,
408,
3407,
314,
536,
402,
314,
32315,
13152,
2435,
1041,
523,
372,
283,
22130,
13152,
7,
421,
199,
318,
1488,
453,
1002,
21271,
2028,
8,
2611,
304,
523,
408,
3407,
314,
931,
370,
314,
32315,
13152,
1101,
570,
1041,
523,
372,
1994,
6839,
15,
22130,
364,
14,
2190,
7,
421,
199,
318,
437,
541,
1002,
21271,
2028,
8,
2611,
304,
523,
408,
3407,
314,
931,
370,
314,
32315,
13152,
1101,
570,
1041,
523,
372,
1994,
6839,
15,
22130,
13152,
14,
2190,
7,
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
] |
[
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
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,
257,
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,
421,
199,
624,
2377,
3035,
32315,
13152,
12096,
436,
9058,
3423,
1041,
421,
199,
318,
1488,
453,
8154,
8,
2611,
304,
523,
408,
8154,
83,
314,
32315,
13152,
2559,
641,
314,
7525,
1041,
523,
32315,
13152,
63,
3417,
275,
334,
489,
6730,
22130,
13152,
7272,
78,
354,
29,
20393,
2846,
24426,
60,
78,
28937,
534,
489,
283,
1014,
921,
20373,
13,
18371,
14,
22130,
13152,
14,
1308,
15,
3417,
15,
17164,
15,
736,
15,
88,
1184,
63,
772,
6307,
78,
7,
489,
283,
21284,
1074,
29,
16,
60,
78,
3827,
29,
17,
358,
523,
4169,
14,
6713,
3110,
360,
7878,
2071,
83,
2,
1204,
14682,
1565,
69,
1182,
6839,
15,
22108,
14,
11857,
14,
68,
15,
22130,
13152,
14,
3417,
7,
450,
673,
32315,
13152,
63,
3417,
9,
523,
4169,
14,
8154,
25135,
360,
22130,
13152,
13,
1308,
13,
1000,
358,
421,
199,
318,
437,
541,
8154,
8,
2611,
304,
523,
408,
8154,
83,
314,
32315,
13152,
2559,
641,
314,
7525,
1041,
523,
4169,
14,
8154,
25135,
360,
22130,
13152,
13,
1000,
358,
421,
199,
318,
1488,
453,
1358,
3174,
8,
2611,
304,
523,
408,
1358,
3174,
83,
314,
32315,
13152,
2559,
641,
314,
7525,
1041,
523,
4169,
14,
6713,
3110,
360,
12095,
14267,
1182,
6839,
15,
22108,
14,
11857,
14,
68,
15,
22130,
13152,
14,
3417,
358,
421,
199,
318,
1488,
453,
1002,
3167,
985,
8,
2611,
304,
523,
408,
3407,
314,
536,
402,
314,
32315,
13152,
2435,
1041,
523,
372,
283,
22130,
364,
7,
421,
199,
318,
437,
541,
1002,
3167,
985,
8,
2611,
304,
523,
408,
3407,
314,
536,
402,
314,
32315,
13152,
2435,
1041,
523,
372,
283,
22130,
13152,
7,
421,
199,
318,
1488,
453,
1002,
21271,
2028,
8,
2611,
304,
523,
408,
3407,
314,
931,
370,
314,
32315,
13152,
1101,
570,
1041,
523,
372,
1994,
6839,
15,
22130,
364,
14,
2190,
7,
421,
199,
318,
437,
541,
1002,
21271,
2028,
8,
2611,
304,
523,
408,
3407,
314,
931,
370,
314,
32315,
13152,
1101,
570,
1041,
523,
372,
1994,
6839,
15,
22130,
13152,
14,
2190,
7,
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,
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,
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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
] |
Orav/kbengine
|
kbe/src/lib/python/Tools/demo/life.py
|
1
|
9249
|
#!/usr/bin/env python3
"""
A curses-based version of Conway's Game of Life.
An empty board will be displayed, and the following commands are available:
E : Erase the board
R : Fill the board randomly
S : Step for a single generation
C : Update continuously until a key is struck
Q : Quit
Cursor keys : Move the cursor around the board
Space or Enter : Toggle the contents of the cursor's position
Contributed by Andrew Kuchling, Mouse support and color by Dafydd Crosby.
"""
import curses
import random
class LifeBoard:
"""Encapsulates a Life board
Attributes:
X,Y : horizontal and vertical size of the board
state : dictionary mapping (x,y) to 0 or 1
Methods:
display(update_board) -- If update_board is true, compute the
next generation. Then display the state
of the board and refresh the screen.
erase() -- clear the entire board
make_random() -- fill the board randomly
set(y,x) -- set the given cell to Live; doesn't refresh the screen
toggle(y,x) -- change the given cell from live to dead, or vice
versa, and refresh the screen display
"""
def __init__(self, scr, char=ord('*')):
"""Create a new LifeBoard instance.
scr -- curses screen object to use for display
char -- character used to render live cells (default: '*')
"""
self.state = {}
self.scr = scr
Y, X = self.scr.getmaxyx()
self.X, self.Y = X - 2, Y - 2 - 1
self.char = char
self.scr.clear()
# Draw a border around the board
border_line = '+' + (self.X * '-') + '+'
self.scr.addstr(0, 0, border_line)
self.scr.addstr(self.Y + 1, 0, border_line)
for y in range(0, self.Y):
self.scr.addstr(1 + y, 0, '|')
self.scr.addstr(1 + y, self.X + 1, '|')
self.scr.refresh()
def set(self, y, x):
"""Set a cell to the live state"""
if x < 0 or self.X <= x or y < 0 or self.Y <= y:
raise ValueError("Coordinates out of range %i,%i" % (y, x))
self.state[x, y] = 1
def toggle(self, y, x):
"""Toggle a cell's state between live and dead"""
if x < 0 or self.X <= x or y < 0 or self.Y <= y:
raise ValueError("Coordinates out of range %i,%i" % (y, x))
if (x, y) in self.state:
del self.state[x, y]
self.scr.addch(y + 1, x + 1, ' ')
else:
self.state[x, y] = 1
if curses.has_colors():
# Let's pick a random color!
self.scr.attrset(curses.color_pair(random.randrange(1, 7)))
self.scr.addch(y + 1, x + 1, self.char)
self.scr.attrset(0)
self.scr.refresh()
def erase(self):
"""Clear the entire board and update the board display"""
self.state = {}
self.display(update_board=False)
def display(self, update_board=True):
"""Display the whole board, optionally computing one generation"""
M, N = self.X, self.Y
if not update_board:
for i in range(0, M):
for j in range(0, N):
if (i, j) in self.state:
self.scr.addch(j + 1, i + 1, self.char)
else:
self.scr.addch(j + 1, i + 1, ' ')
self.scr.refresh()
return
d = {}
self.boring = 1
for i in range(0, M):
L = range(max(0, i - 1), min(M, i + 2))
for j in range(0, N):
s = 0
live = (i, j) in self.state
for k in range(max(0, j - 1), min(N, j + 2)):
for l in L:
if (l, k) in self.state:
s += 1
s -= live
if s == 3:
# Birth
d[i, j] = 1
if curses.has_colors():
# Let's pick a random color!
self.scr.attrset(curses.color_pair(
random.randrange(1, 7)))
self.scr.addch(j + 1, i + 1, self.char)
self.scr.attrset(0)
if not live:
self.boring = 0
elif s == 2 and live:
# Survival
d[i, j] = 1
elif live:
# Death
self.scr.addch(j + 1, i + 1, ' ')
self.boring = 0
self.state = d
self.scr.refresh()
def make_random(self):
"Fill the board with a random pattern"
self.state = {}
for i in range(0, self.X):
for j in range(0, self.Y):
if random.random() > 0.5:
self.set(j, i)
def erase_menu(stdscr, menu_y):
"Clear the space where the menu resides"
stdscr.move(menu_y, 0)
stdscr.clrtoeol()
stdscr.move(menu_y + 1, 0)
stdscr.clrtoeol()
def display_menu(stdscr, menu_y):
"Display the menu of possible keystroke commands"
erase_menu(stdscr, menu_y)
# If color, then light the menu up :-)
if curses.has_colors():
stdscr.attrset(curses.color_pair(1))
stdscr.addstr(menu_y, 4,
'Use the cursor keys to move, and space or Enter to toggle a cell.')
stdscr.addstr(menu_y + 1, 4,
'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit')
stdscr.attrset(0)
def keyloop(stdscr):
# Clear the screen and display the menu of keys
stdscr.clear()
stdscr_y, stdscr_x = stdscr.getmaxyx()
menu_y = (stdscr_y - 3) - 1
display_menu(stdscr, menu_y)
# If color, then initialize the color pairs
if curses.has_colors():
curses.init_pair(1, curses.COLOR_BLUE, 0)
curses.init_pair(2, curses.COLOR_CYAN, 0)
curses.init_pair(3, curses.COLOR_GREEN, 0)
curses.init_pair(4, curses.COLOR_MAGENTA, 0)
curses.init_pair(5, curses.COLOR_RED, 0)
curses.init_pair(6, curses.COLOR_YELLOW, 0)
curses.init_pair(7, curses.COLOR_WHITE, 0)
# Set up the mask to listen for mouse events
curses.mousemask(curses.BUTTON1_CLICKED)
# Allocate a subwindow for the Life board and create the board object
subwin = stdscr.subwin(stdscr_y - 3, stdscr_x, 0, 0)
board = LifeBoard(subwin, char=ord('*'))
board.display(update_board=False)
# xpos, ypos are the cursor's position
xpos, ypos = board.X // 2, board.Y // 2
# Main loop:
while True:
stdscr.move(1 + ypos, 1 + xpos) # Move the cursor
c = stdscr.getch() # Get a keystroke
if 0 < c < 256:
c = chr(c)
if c in ' \n':
board.toggle(ypos, xpos)
elif c in 'Cc':
erase_menu(stdscr, menu_y)
stdscr.addstr(menu_y, 6, ' Hit any key to stop continuously '
'updating the screen.')
stdscr.refresh()
# Activate nodelay mode; getch() will return -1
# if no keystroke is available, instead of waiting.
stdscr.nodelay(1)
while True:
c = stdscr.getch()
if c != -1:
break
stdscr.addstr(0, 0, '/')
stdscr.refresh()
board.display()
stdscr.addstr(0, 0, '+')
stdscr.refresh()
stdscr.nodelay(0) # Disable nodelay mode
display_menu(stdscr, menu_y)
elif c in 'Ee':
board.erase()
elif c in 'Qq':
break
elif c in 'Rr':
board.make_random()
board.display(update_board=False)
elif c in 'Ss':
board.display()
else:
# Ignore incorrect keys
pass
elif c == curses.KEY_UP and ypos > 0:
ypos -= 1
elif c == curses.KEY_DOWN and ypos + 1 < board.Y:
ypos += 1
elif c == curses.KEY_LEFT and xpos > 0:
xpos -= 1
elif c == curses.KEY_RIGHT and xpos + 1 < board.X:
xpos += 1
elif c == curses.KEY_MOUSE:
mouse_id, mouse_x, mouse_y, mouse_z, button_state = curses.getmouse()
if (mouse_x > 0 and mouse_x < board.X + 1 and
mouse_y > 0 and mouse_y < board.Y + 1):
xpos = mouse_x - 1
ypos = mouse_y - 1
board.toggle(ypos, xpos)
else:
# They've clicked outside the board
curses.flash()
else:
# Ignore incorrect keys
pass
def main(stdscr):
keyloop(stdscr) # Enter the main loop
if __name__ == '__main__':
curses.wrapper(main)
|
lgpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
2999,
199,
624,
202,
199,
33,
15429,
13,
6788,
1015,
402,
1448,
3316,
1159,
25132,
402,
491,
16839,
14,
2999,
199,
2493,
2701,
13811,
911,
506,
9080,
12,
436,
314,
2569,
3718,
787,
2808,
26,
1223,
662,
520,
662,
8062,
314,
13811,
1223,
820,
520,
24797,
314,
13811,
19311,
1223,
428,
520,
13382,
367,
282,
2849,
10152,
1223,
445,
520,
6162,
19922,
590,
5133,
282,
790,
365,
620,
10112,
1223,
1413,
520,
1413,
4993,
1223,
20385,
2883,
520,
221,
14171,
314,
3920,
6818,
314,
13811,
1223,
19326,
503,
16401,
520,
377,
19403,
314,
4072,
402,
314,
3920,
1159,
3421,
2999,
199,
714,
24855,
701,
6061,
5257,
1804,
2133,
2983,
12,
603,
7130,
2291,
436,
3164,
701,
577,
65,
1399,
617,
445,
4796,
991,
14,
202,
199,
624,
2999,
199,
646,
15429,
202,
199,
646,
2196,
8065,
199,
533,
491,
16839,
18995,
26,
1128,
408,
1327,
12029,
15409,
282,
491,
16839,
13811,
2958,
9382,
26,
1128,
1323,
12,
57,
520,
17528,
436,
13763,
1568,
402,
314,
13811,
1128,
1174,
520,
2600,
4412,
334,
88,
12,
89,
9,
370,
378,
503,
413,
2958,
17653,
26,
1128,
2929,
8,
873,
63,
3576,
9,
1553,
982,
1678,
63,
3576,
365,
2549,
12,
4526,
314,
202,
2490,
2163,
10152,
14,
221,
9442,
2929,
314,
1174,
202,
2490,
402,
314,
13811,
436,
9236,
314,
6426,
14,
1128,
28343,
342,
1553,
5436,
314,
8039,
13811,
1128,
1852,
63,
2355,
342,
1553,
5554,
314,
13811,
19311,
1128,
663,
8,
89,
12,
88,
9,
1553,
663,
314,
1627,
4917,
370,
24683,
27,
3181,
1133,
9236,
314,
6426,
1128,
19420,
8,
89,
12,
88,
9,
1553,
1570,
314,
1627,
4917,
687,
12166,
370,
12314,
12,
503,
1321,
301,
202,
673,
809,
2231,
12,
436,
9236,
314,
6426,
2929,
2958,
408,
1128,
347,
636,
826,
721,
277,
12,
19270,
12,
1495,
29,
2181,
18225,
8109,
1039,
408,
2499,
282,
892,
491,
16839,
18995,
1256,
14,
4341,
19270,
1553,
15429,
6426,
909,
370,
675,
367,
2929,
1039,
1495,
1553,
4528,
1202,
370,
3795,
12166,
10106,
334,
885,
26,
6438,
358,
1039,
408,
1039,
291,
14,
929,
275,
1052,
1039,
291,
14,
11047,
275,
19270,
1039,
1488,
12,
1323,
275,
291,
14,
11047,
14,
362,
988,
20937,
342,
1039,
291,
14,
56,
12,
291,
14,
57,
275,
1323,
446,
499,
12,
1488,
446,
499,
446,
413,
1039,
291,
14,
1560,
275,
1495,
1039,
291,
14,
11047,
14,
3584,
342,
4341,
327,
17813,
282,
9162,
6818,
314,
13811,
1039,
9162,
63,
604,
275,
20246,
435,
334,
277,
14,
56,
627,
26942,
435,
20246,
1039,
291,
14,
11047,
14,
525,
495,
8,
16,
12,
378,
12,
9162,
63,
604,
9,
1039,
291,
14,
11047,
14,
525,
495,
8,
277,
14,
57,
435,
413,
12,
378,
12,
9162,
63,
604,
9,
1039,
367,
612,
315,
1425,
8,
16,
12,
291,
14,
57,
304,
1675,
291,
14,
11047,
14,
525,
495,
8,
17,
435,
612,
12,
378,
12,
11280,
358,
1675,
291,
14,
11047,
14,
525,
495,
8,
17,
435,
612,
12,
291,
14,
56,
435,
413,
12,
11280,
358,
1039,
291,
14,
11047,
14,
6635,
342,
2958,
347,
663,
8,
277,
12,
612,
12,
671,
304,
1039,
408,
1084,
282,
4917,
370,
314,
12166,
1174,
624,
1039,
340,
671,
665,
378,
503,
291,
14,
56,
2695,
671,
503,
612,
665,
378,
503,
291,
14,
57,
2695,
612,
26,
1675,
746,
1722,
480,
13940,
2335,
734,
402,
1425,
450,
73,
8719,
73,
2,
450,
334,
89,
12,
671,
430,
1039,
291,
14,
929,
59,
88,
12,
612,
61,
275,
413,
2958,
347,
19420,
8,
277,
12,
612,
12,
671,
304,
1039,
408,
24743,
282,
4917,
1159,
1174,
3382,
12166,
436,
12314,
624,
1039,
340,
671,
665,
378,
503,
291,
14,
56,
2695,
671,
503,
612,
665,
378,
503,
291,
14,
57,
2695,
612,
26,
1675,
746,
1722,
480,
13940,
2335,
734,
402,
1425,
450,
73,
8719,
73,
2,
450,
334,
89,
12,
671,
430,
1039,
340,
334,
88,
12,
612,
9,
315,
291,
14,
929,
26,
1675,
2150,
291,
14,
929,
59,
88,
12,
612,
61,
1675,
291,
14,
11047,
14,
525,
335,
8,
89,
435,
413,
12,
671,
435,
413,
12,
283,
5320,
1039,
587,
26,
1675,
291,
14,
929,
59,
88,
12,
612,
61,
275,
413,
1675,
340,
15429,
14,
1989,
63,
7120,
837,
2628,
327,
12230,
1159,
3732,
282,
2196,
3164,
1,
2628,
291,
14,
11047,
14,
962,
409,
8,
12026,
14,
2326,
63,
3852,
8,
2355,
14,
20539,
8,
17,
12,
1520,
1724,
1675,
291,
14,
11047,
14,
525,
335,
8,
89,
435,
413,
12,
671,
435,
413,
12,
291,
14,
1560,
9,
1675,
291,
14,
11047,
14,
962,
409,
8,
16,
9,
1039,
291,
14,
11047,
14,
6635,
342,
2958,
347,
28343,
8,
277,
304,
1039,
408,
9721,
314,
8039,
13811,
436,
1678,
314,
13811,
2929,
624,
1039,
291,
14,
929,
275,
1052,
1039,
291,
14,
2918,
8,
873,
63,
3576,
29,
797,
9,
2958,
347,
2929,
8,
277,
12,
1678,
63,
3576,
29,
549,
304,
1039,
408,
7687,
314,
8852,
13811,
12,
14190,
17226,
1373,
10152,
624,
1039,
603,
12,
653,
275,
291,
14,
56,
12,
291,
14,
57,
1039,
340,
440,
1678,
63,
3576,
26,
1675,
367,
284,
315,
1425,
8,
16,
12,
603,
304,
2628,
367,
1335,
315,
1425,
8,
16,
12,
653,
304,
4906,
340,
334,
73,
12,
1335,
9,
315,
291,
14,
929,
26,
8282,
291,
14,
11047,
14,
525,
335,
8,
74,
435,
413,
12,
284,
435,
413,
12,
291,
14,
1560,
9,
4906,
587,
26,
8282,
291,
14,
11047,
14,
525,
335,
8,
74,
435,
413,
12,
284,
435,
413,
12,
283,
5320,
1675,
291,
14,
11047,
14,
6635,
342,
1675,
372,
4341,
366,
275,
1052,
1039,
291,
14,
66,
6854,
275,
413,
1039,
367,
284,
315,
1425,
8,
16,
12,
603,
304,
1675,
491,
275,
1425,
8,
988,
8,
16,
12,
284,
446,
413,
395,
1748,
8,
45,
12,
284,
435,
499,
430,
1675,
367,
1335,
315,
1425,
8,
16,
12,
653,
304,
2628,
308,
275,
378,
2628,
12166,
275,
334,
73,
12,
1335,
9,
315,
291,
14,
929,
2628,
367,
1022,
315,
1425,
8,
988,
8,
16,
12,
1335
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
2999,
199,
624,
202,
199,
33,
15429,
13,
6788,
1015,
402,
1448,
3316,
1159,
25132,
402,
491,
16839,
14,
2999,
199,
2493,
2701,
13811,
911,
506,
9080,
12,
436,
314,
2569,
3718,
787,
2808,
26,
1223,
662,
520,
662,
8062,
314,
13811,
1223,
820,
520,
24797,
314,
13811,
19311,
1223,
428,
520,
13382,
367,
282,
2849,
10152,
1223,
445,
520,
6162,
19922,
590,
5133,
282,
790,
365,
620,
10112,
1223,
1413,
520,
1413,
4993,
1223,
20385,
2883,
520,
221,
14171,
314,
3920,
6818,
314,
13811,
1223,
19326,
503,
16401,
520,
377,
19403,
314,
4072,
402,
314,
3920,
1159,
3421,
2999,
199,
714,
24855,
701,
6061,
5257,
1804,
2133,
2983,
12,
603,
7130,
2291,
436,
3164,
701,
577,
65,
1399,
617,
445,
4796,
991,
14,
202,
199,
624,
2999,
199,
646,
15429,
202,
199,
646,
2196,
8065,
199,
533,
491,
16839,
18995,
26,
1128,
408,
1327,
12029,
15409,
282,
491,
16839,
13811,
2958,
9382,
26,
1128,
1323,
12,
57,
520,
17528,
436,
13763,
1568,
402,
314,
13811,
1128,
1174,
520,
2600,
4412,
334,
88,
12,
89,
9,
370,
378,
503,
413,
2958,
17653,
26,
1128,
2929,
8,
873,
63,
3576,
9,
1553,
982,
1678,
63,
3576,
365,
2549,
12,
4526,
314,
202,
2490,
2163,
10152,
14,
221,
9442,
2929,
314,
1174,
202,
2490,
402,
314,
13811,
436,
9236,
314,
6426,
14,
1128,
28343,
342,
1553,
5436,
314,
8039,
13811,
1128,
1852,
63,
2355,
342,
1553,
5554,
314,
13811,
19311,
1128,
663,
8,
89,
12,
88,
9,
1553,
663,
314,
1627,
4917,
370,
24683,
27,
3181,
1133,
9236,
314,
6426,
1128,
19420,
8,
89,
12,
88,
9,
1553,
1570,
314,
1627,
4917,
687,
12166,
370,
12314,
12,
503,
1321,
301,
202,
673,
809,
2231,
12,
436,
9236,
314,
6426,
2929,
2958,
408,
1128,
347,
636,
826,
721,
277,
12,
19270,
12,
1495,
29,
2181,
18225,
8109,
1039,
408,
2499,
282,
892,
491,
16839,
18995,
1256,
14,
4341,
19270,
1553,
15429,
6426,
909,
370,
675,
367,
2929,
1039,
1495,
1553,
4528,
1202,
370,
3795,
12166,
10106,
334,
885,
26,
6438,
358,
1039,
408,
1039,
291,
14,
929,
275,
1052,
1039,
291,
14,
11047,
275,
19270,
1039,
1488,
12,
1323,
275,
291,
14,
11047,
14,
362,
988,
20937,
342,
1039,
291,
14,
56,
12,
291,
14,
57,
275,
1323,
446,
499,
12,
1488,
446,
499,
446,
413,
1039,
291,
14,
1560,
275,
1495,
1039,
291,
14,
11047,
14,
3584,
342,
4341,
327,
17813,
282,
9162,
6818,
314,
13811,
1039,
9162,
63,
604,
275,
20246,
435,
334,
277,
14,
56,
627,
26942,
435,
20246,
1039,
291,
14,
11047,
14,
525,
495,
8,
16,
12,
378,
12,
9162,
63,
604,
9,
1039,
291,
14,
11047,
14,
525,
495,
8,
277,
14,
57,
435,
413,
12,
378,
12,
9162,
63,
604,
9,
1039,
367,
612,
315,
1425,
8,
16,
12,
291,
14,
57,
304,
1675,
291,
14,
11047,
14,
525,
495,
8,
17,
435,
612,
12,
378,
12,
11280,
358,
1675,
291,
14,
11047,
14,
525,
495,
8,
17,
435,
612,
12,
291,
14,
56,
435,
413,
12,
11280,
358,
1039,
291,
14,
11047,
14,
6635,
342,
2958,
347,
663,
8,
277,
12,
612,
12,
671,
304,
1039,
408,
1084,
282,
4917,
370,
314,
12166,
1174,
624,
1039,
340,
671,
665,
378,
503,
291,
14,
56,
2695,
671,
503,
612,
665,
378,
503,
291,
14,
57,
2695,
612,
26,
1675,
746,
1722,
480,
13940,
2335,
734,
402,
1425,
450,
73,
8719,
73,
2,
450,
334,
89,
12,
671,
430,
1039,
291,
14,
929,
59,
88,
12,
612,
61,
275,
413,
2958,
347,
19420,
8,
277,
12,
612,
12,
671,
304,
1039,
408,
24743,
282,
4917,
1159,
1174,
3382,
12166,
436,
12314,
624,
1039,
340,
671,
665,
378,
503,
291,
14,
56,
2695,
671,
503,
612,
665,
378,
503,
291,
14,
57,
2695,
612,
26,
1675,
746,
1722,
480,
13940,
2335,
734,
402,
1425,
450,
73,
8719,
73,
2,
450,
334,
89,
12,
671,
430,
1039,
340,
334,
88,
12,
612,
9,
315,
291,
14,
929,
26,
1675,
2150,
291,
14,
929,
59,
88,
12,
612,
61,
1675,
291,
14,
11047,
14,
525,
335,
8,
89,
435,
413,
12,
671,
435,
413,
12,
283,
5320,
1039,
587,
26,
1675,
291,
14,
929,
59,
88,
12,
612,
61,
275,
413,
1675,
340,
15429,
14,
1989,
63,
7120,
837,
2628,
327,
12230,
1159,
3732,
282,
2196,
3164,
1,
2628,
291,
14,
11047,
14,
962,
409,
8,
12026,
14,
2326,
63,
3852,
8,
2355,
14,
20539,
8,
17,
12,
1520,
1724,
1675,
291,
14,
11047,
14,
525,
335,
8,
89,
435,
413,
12,
671,
435,
413,
12,
291,
14,
1560,
9,
1675,
291,
14,
11047,
14,
962,
409,
8,
16,
9,
1039,
291,
14,
11047,
14,
6635,
342,
2958,
347,
28343,
8,
277,
304,
1039,
408,
9721,
314,
8039,
13811,
436,
1678,
314,
13811,
2929,
624,
1039,
291,
14,
929,
275,
1052,
1039,
291,
14,
2918,
8,
873,
63,
3576,
29,
797,
9,
2958,
347,
2929,
8,
277,
12,
1678,
63,
3576,
29,
549,
304,
1039,
408,
7687,
314,
8852,
13811,
12,
14190,
17226,
1373,
10152,
624,
1039,
603,
12,
653,
275,
291,
14,
56,
12,
291,
14,
57,
1039,
340,
440,
1678,
63,
3576,
26,
1675,
367,
284,
315,
1425,
8,
16,
12,
603,
304,
2628,
367,
1335,
315,
1425,
8,
16,
12,
653,
304,
4906,
340,
334,
73,
12,
1335,
9,
315,
291,
14,
929,
26,
8282,
291,
14,
11047,
14,
525,
335,
8,
74,
435,
413,
12,
284,
435,
413,
12,
291,
14,
1560,
9,
4906,
587,
26,
8282,
291,
14,
11047,
14,
525,
335,
8,
74,
435,
413,
12,
284,
435,
413,
12,
283,
5320,
1675,
291,
14,
11047,
14,
6635,
342,
1675,
372,
4341,
366,
275,
1052,
1039,
291,
14,
66,
6854,
275,
413,
1039,
367,
284,
315,
1425,
8,
16,
12,
603,
304,
1675,
491,
275,
1425,
8,
988,
8,
16,
12,
284,
446,
413,
395,
1748,
8,
45,
12,
284,
435,
499,
430,
1675,
367,
1335,
315,
1425,
8,
16,
12,
653,
304,
2628,
308,
275,
378,
2628,
12166,
275,
334,
73,
12,
1335,
9,
315,
291,
14,
929,
2628,
367,
1022,
315,
1425,
8,
988,
8,
16,
12,
1335,
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
] |
jwilliamn/handwritten
|
extraction/FormatModel/CreatePage3Variable.py
|
1
|
6106
|
import pickle
from extraction.FormatModel.VariableDefinitions import *
from extraction.FormatModel.RawVariableDefinitions import *
import json
def jsonDefault(object):
return object.__dict__
if __name__ == '__main__':
Page3 = Category('page3', 'pagina 3')
############
for r in range(1,6):
str_r = str(r)
if len(str_r) == 1:
str_r = '0'+str_r
P = Category('P'+str_r,'Persona '+str_r)
ap_paterno=Category('apellido_paterno','Apellido paterno')
variable_ap_paterno=Variable('pos_TL_BR','posicion final', None)
ap_paterno.addSubType(variable_ap_paterno)
ap_materno = Category('apellido_materno', 'Apellido materno')
variable_ap_materno = Variable('pos_TL_BR', 'posicion final', None)
ap_materno.addSubType(variable_ap_materno)
nombres = Category('nombres', 'nombres')
variable_nombres = Variable('pos_TL_BR', 'posicion final', None)
nombres.addSubType(variable_nombres)
fecha_nacimiento = Category('fecha_nacimiento', 'Fecha de nacimiento')
variable_fecha_nacimiento = Variable('pos_TL_BR', 'posicion final', None)
fecha_nacimiento.addSubType(variable_fecha_nacimiento)
edad_anhos = Category('edad_anhos', 'edad_anios')
variable_edad_anhos = Variable('pos_TL_BR', 'posicion final', None)
edad_anhos.addSubType(variable_edad_anhos)
edad_meses = Category('edad_meses', 'edad_meses')
variable_edad_meses = Variable('pos_TL_BR', 'posicion final', None)
edad_meses.addSubType(variable_edad_meses)
tipo_documento = Category('tipo_documento', 'tipo_documento')
variable_tipo_documento = Variable('pos_TL_BR', 'posicion final', None)
tipo_documento.addSubType(variable_tipo_documento)
numero_documento = Category('numero_documento', 'numero_documento')
variable_numero_documento = Variable('pos_TL_BR', 'posicion final', None)
numero_documento.addSubType(variable_numero_documento)
parentesco_jefe_hogar = Category('parentesco_jefe_hogar', 'parentesco_jefe_hogar')
variable_parentesco_jefe_hogar = Variable('pos_TL_BR', 'posicion final', None)
parentesco_jefe_hogar.addSubType(variable_parentesco_jefe_hogar)
num_nucleo_familiar = Category('num_nucleo_familiar', 'num_nucleo_familiar')
variable_num_nucleo_familiar = Variable('pos_TL_BR', 'posicion final', None)
num_nucleo_familiar.addSubType(variable_num_nucleo_familiar)
sexo = Category('sexo', 'sexo')
variable_sexo = Variable('pos_TL_BR', 'posicion final', None)
sexo.addSubType(variable_sexo)
estado_civil = Category('estado_civil', 'estado_civil')
variable_estado_civil = Variable('pos_TL_BR', 'posicion final', None)
estado_civil.addSubType(variable_estado_civil)
tipo_seguro = Category('tipo_seguro', 'tipo_seguro')
variable_tipo_seguro = Variable('pos_TL_BR', 'posicion final', None)
tipo_seguro.addSubType(variable_tipo_seguro)
lengua_materna = Category('lengua_materna', 'lengua_materna')
variable_lengua_materna = Variable('pos_TL_BR', 'posicion final', None)
lengua_materna.addSubType(variable_lengua_materna)
sabe_leer_escribir = Category('sabe_leer_escribir', 'sabe_leer_escribir')
variable_sabe_leer_escribir = Variable('pos_TL_BR', 'posicion final', None)
sabe_leer_escribir.addSubType(variable_sabe_leer_escribir)
nivel_educativo = Category('nivel_educativo', 'nivel_educativo')
variable_nivel_educativo = Variable('pos_TL_BR', 'posicion final', None)
nivel_educativo.addSubType(variable_nivel_educativo)
ultimo_grado_aprobado = Category('ultimo_grado_aprobado', 'ultimo_grado_aprobado')
variable_ultimo_grado_aprobado = Variable('pos_TL_BR', 'posicion final', None)
ultimo_grado_aprobado.addSubType(variable_ultimo_grado_aprobado)
ultimo_mes_era_un = Category('ultimo_mes_era_un', 'ultimo_mes_era_un')
variable_ultimo_mes_era_un = Variable('pos_TL_BR', 'posicion final', None)
ultimo_mes_era_un.addSubType(variable_ultimo_mes_era_un)
sector_desempenho = Category('sector_desempenho', 'sector_desempenho')
variable_sector_desempenho = Variable('pos_TL_BR', 'posicion final', None)
sector_desempenho.addSubType(variable_sector_desempenho)
presenta_discapacidad = Category('presenta_discapacidad', 'presenta_discapacidad')
variable_presenta_discapacidad = Variable('pos_TL_BR', 'posicion final', None)
presenta_discapacidad.addSubType(variable_presenta_discapacidad)
programa_social_beneficiario = Category('programa_social_beneficiario', 'programa_social_beneficiario')
variable_programa_social_beneficiario = Variable('pos_TL_BR', 'posicion final', None)
programa_social_beneficiario.addSubType(variable_programa_social_beneficiario)
#############
P.addSubType(ap_paterno)
P.addSubType(ap_materno)
P.addSubType(nombres)
P.addSubType(fecha_nacimiento)
P.addSubType(edad_anhos)
P.addSubType(edad_meses)
P.addSubType(tipo_documento)
P.addSubType(numero_documento)
P.addSubType(parentesco_jefe_hogar)
P.addSubType(num_nucleo_familiar)
P.addSubType(sexo)
P.addSubType(estado_civil)
P.addSubType(tipo_seguro)
P.addSubType(lengua_materna)
P.addSubType(sabe_leer_escribir)
P.addSubType(nivel_educativo)
P.addSubType(ultimo_grado_aprobado)
P.addSubType(ultimo_mes_era_un)
P.addSubType(sector_desempenho)
P.addSubType(presenta_discapacidad)
P.addSubType(programa_social_beneficiario)
Page3.addSubType(P)
with open('pagina3.json', 'w') as output:
json.dump(Page3, output, default=jsonDefault, indent=4)
Page3.describe(True)
|
gpl-3.0
|
[
646,
5927,
199,
199,
504,
19967,
14,
3484,
1685,
14,
2773,
16738,
492,
627,
199,
504,
19967,
14,
3484,
1685,
14,
7963,
2773,
16738,
492,
627,
199,
646,
2022,
421,
199,
318,
2022,
2698,
8,
785,
304,
272,
372,
909,
855,
807,
363,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
10331,
19,
275,
13573,
360,
1606,
19,
297,
283,
11069,
65,
650,
358,
272,
21937,
381,
272,
367,
519,
315,
1425,
8,
17,
12,
22,
304,
267,
620,
63,
82,
275,
620,
8,
82,
9,
267,
340,
822,
8,
495,
63,
82,
9,
508,
413,
26,
288,
620,
63,
82,
275,
283,
16,
6828,
495,
63,
82,
267,
510,
275,
13573,
360,
48,
6828,
495,
63,
82,
2584,
7344,
65,
6681,
495,
63,
82,
9,
2728,
2771,
63,
80,
6618,
889,
29,
7841,
360,
924,
13876,
1117,
63,
80,
6618,
889,
1673,
33,
321,
13876,
1117,
299,
6618,
889,
358,
267,
1750,
63,
439,
63,
80,
6618,
889,
29,
2773,
360,
1712,
63,
7308,
63,
7184,
1673,
555,
338,
9718,
4242,
297,
488,
9,
267,
2771,
63,
80,
6618,
889,
14,
525,
2610,
804,
8,
1975,
63,
439,
63,
80,
6618,
889,
9,
13857,
2771,
63,
77,
6618,
889,
275,
13573,
360,
924,
13876,
1117,
63,
77,
6618,
889,
297,
283,
33,
321,
13876,
1117,
333,
6618,
889,
358,
267,
1750,
63,
439,
63,
77,
6618,
889,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
2771,
63,
77,
6618,
889,
14,
525,
2610,
804,
8,
1975,
63,
439,
63,
77,
6618,
889,
9,
13857,
17468,
66,
470,
275,
13573,
360,
15998,
66,
470,
297,
283,
15998,
66,
470,
358,
267,
1750,
63,
15998,
66,
470,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
17468,
66,
470,
14,
525,
2610,
804,
8,
1975,
63,
15998,
66,
470,
9,
13857,
1964,
9518,
63,
3540,
559,
2664,
287,
475,
275,
13573,
360,
771,
9518,
63,
3540,
559,
2664,
287,
475,
297,
283,
3456,
9518,
477,
11802,
559,
2664,
287,
475,
358,
267,
1750,
63,
771,
9518,
63,
3540,
559,
2664,
287,
475,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
1964,
9518,
63,
3540,
559,
2664,
287,
475,
14,
525,
2610,
804,
8,
1975,
63,
771,
9518,
63,
3540,
559,
2664,
287,
475,
9,
13857,
3988,
350,
63,
290,
526,
83,
275,
13573,
360,
379,
350,
63,
290,
526,
83,
297,
283,
379,
350,
63,
290,
9207,
358,
267,
1750,
63,
379,
350,
63,
290,
526,
83,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3988,
350,
63,
290,
526,
83,
14,
525,
2610,
804,
8,
1975,
63,
379,
350,
63,
290,
526,
83,
9,
13857,
3988,
350,
63,
278,
874,
275,
13573,
360,
379,
350,
63,
278,
874,
297,
283,
379,
350,
63,
278,
874,
358,
267,
1750,
63,
379,
350,
63,
278,
874,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3988,
350,
63,
278,
874,
14,
525,
2610,
804,
8,
1975,
63,
379,
350,
63,
278,
874,
9,
2728,
3367,
555,
63,
3554,
79,
275,
13573,
360,
280,
555,
63,
3554,
79,
297,
283,
280,
555,
63,
3554,
79,
358,
267,
1750,
63,
280,
555,
63,
3554,
79,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3367,
555,
63,
3554,
79,
14,
525,
2610,
804,
8,
1975,
63,
280,
555,
63,
3554,
79,
9,
30712,
10330,
293,
63,
3554,
79,
275,
13573,
360,
10563,
293,
63,
3554,
79,
297,
283,
10563,
293,
63,
3554,
79,
358,
267,
1750,
63,
10563,
293,
63,
3554,
79,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
10330,
293,
63,
3554,
79,
14,
525,
2610,
804,
8,
1975,
63,
10563,
293,
63,
3554,
79,
9,
2728,
13566,
744,
331,
63,
6532,
771,
63,
526,
23909,
275,
13573,
360,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
297,
283,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
358,
267,
1750,
63,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
13566,
744,
331,
63,
6532,
771,
63,
526,
23909,
14,
525,
2610,
804,
8,
1975,
63,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
9,
2728,
1967,
63,
30984,
274,
79,
63,
18493,
1638,
285,
275,
13573,
360,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
297,
283,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
358,
267,
1750,
63,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
1967,
63,
30984,
274,
79,
63,
18493,
1638,
285,
14,
525,
2610,
804,
8,
1975,
63,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
9,
13857,
542,
15987,
275,
13573,
360,
261,
15987,
297,
283,
261,
15987,
358,
267,
1750,
63,
261,
15987,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
542,
15987,
14,
525,
2610,
804,
8,
1975,
63,
261,
15987,
9,
2728,
4347,
5129,
63,
559,
29792,
275,
13573,
360,
597,
5129,
63,
559,
29792,
297,
283,
597,
5129,
63,
559,
29792,
358,
267,
1750,
63,
597,
5129,
63,
559,
29792,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
4347,
5129,
63,
559,
29792,
14,
525,
2610,
804,
8,
1975,
63,
597,
5129,
63,
559,
29792,
9,
2728,
3367,
555,
63,
261,
6051,
293,
275,
13573,
360,
280,
555,
63,
261,
6051,
293,
297,
283,
280,
555,
63,
261,
6051,
293,
358,
267,
1750,
63,
280,
555,
63,
261,
6051,
293,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3367,
555,
63,
261
] |
[
5927,
199,
199,
504,
19967,
14,
3484,
1685,
14,
2773,
16738,
492,
627,
199,
504,
19967,
14,
3484,
1685,
14,
7963,
2773,
16738,
492,
627,
199,
646,
2022,
421,
199,
318,
2022,
2698,
8,
785,
304,
272,
372,
909,
855,
807,
363,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
10331,
19,
275,
13573,
360,
1606,
19,
297,
283,
11069,
65,
650,
358,
272,
21937,
381,
272,
367,
519,
315,
1425,
8,
17,
12,
22,
304,
267,
620,
63,
82,
275,
620,
8,
82,
9,
267,
340,
822,
8,
495,
63,
82,
9,
508,
413,
26,
288,
620,
63,
82,
275,
283,
16,
6828,
495,
63,
82,
267,
510,
275,
13573,
360,
48,
6828,
495,
63,
82,
2584,
7344,
65,
6681,
495,
63,
82,
9,
2728,
2771,
63,
80,
6618,
889,
29,
7841,
360,
924,
13876,
1117,
63,
80,
6618,
889,
1673,
33,
321,
13876,
1117,
299,
6618,
889,
358,
267,
1750,
63,
439,
63,
80,
6618,
889,
29,
2773,
360,
1712,
63,
7308,
63,
7184,
1673,
555,
338,
9718,
4242,
297,
488,
9,
267,
2771,
63,
80,
6618,
889,
14,
525,
2610,
804,
8,
1975,
63,
439,
63,
80,
6618,
889,
9,
13857,
2771,
63,
77,
6618,
889,
275,
13573,
360,
924,
13876,
1117,
63,
77,
6618,
889,
297,
283,
33,
321,
13876,
1117,
333,
6618,
889,
358,
267,
1750,
63,
439,
63,
77,
6618,
889,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
2771,
63,
77,
6618,
889,
14,
525,
2610,
804,
8,
1975,
63,
439,
63,
77,
6618,
889,
9,
13857,
17468,
66,
470,
275,
13573,
360,
15998,
66,
470,
297,
283,
15998,
66,
470,
358,
267,
1750,
63,
15998,
66,
470,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
17468,
66,
470,
14,
525,
2610,
804,
8,
1975,
63,
15998,
66,
470,
9,
13857,
1964,
9518,
63,
3540,
559,
2664,
287,
475,
275,
13573,
360,
771,
9518,
63,
3540,
559,
2664,
287,
475,
297,
283,
3456,
9518,
477,
11802,
559,
2664,
287,
475,
358,
267,
1750,
63,
771,
9518,
63,
3540,
559,
2664,
287,
475,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
1964,
9518,
63,
3540,
559,
2664,
287,
475,
14,
525,
2610,
804,
8,
1975,
63,
771,
9518,
63,
3540,
559,
2664,
287,
475,
9,
13857,
3988,
350,
63,
290,
526,
83,
275,
13573,
360,
379,
350,
63,
290,
526,
83,
297,
283,
379,
350,
63,
290,
9207,
358,
267,
1750,
63,
379,
350,
63,
290,
526,
83,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3988,
350,
63,
290,
526,
83,
14,
525,
2610,
804,
8,
1975,
63,
379,
350,
63,
290,
526,
83,
9,
13857,
3988,
350,
63,
278,
874,
275,
13573,
360,
379,
350,
63,
278,
874,
297,
283,
379,
350,
63,
278,
874,
358,
267,
1750,
63,
379,
350,
63,
278,
874,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3988,
350,
63,
278,
874,
14,
525,
2610,
804,
8,
1975,
63,
379,
350,
63,
278,
874,
9,
2728,
3367,
555,
63,
3554,
79,
275,
13573,
360,
280,
555,
63,
3554,
79,
297,
283,
280,
555,
63,
3554,
79,
358,
267,
1750,
63,
280,
555,
63,
3554,
79,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3367,
555,
63,
3554,
79,
14,
525,
2610,
804,
8,
1975,
63,
280,
555,
63,
3554,
79,
9,
30712,
10330,
293,
63,
3554,
79,
275,
13573,
360,
10563,
293,
63,
3554,
79,
297,
283,
10563,
293,
63,
3554,
79,
358,
267,
1750,
63,
10563,
293,
63,
3554,
79,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
10330,
293,
63,
3554,
79,
14,
525,
2610,
804,
8,
1975,
63,
10563,
293,
63,
3554,
79,
9,
2728,
13566,
744,
331,
63,
6532,
771,
63,
526,
23909,
275,
13573,
360,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
297,
283,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
358,
267,
1750,
63,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
13566,
744,
331,
63,
6532,
771,
63,
526,
23909,
14,
525,
2610,
804,
8,
1975,
63,
9575,
744,
331,
63,
6532,
771,
63,
526,
23909,
9,
2728,
1967,
63,
30984,
274,
79,
63,
18493,
1638,
285,
275,
13573,
360,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
297,
283,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
358,
267,
1750,
63,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
1967,
63,
30984,
274,
79,
63,
18493,
1638,
285,
14,
525,
2610,
804,
8,
1975,
63,
1507,
63,
30984,
274,
79,
63,
18493,
1638,
285,
9,
13857,
542,
15987,
275,
13573,
360,
261,
15987,
297,
283,
261,
15987,
358,
267,
1750,
63,
261,
15987,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
542,
15987,
14,
525,
2610,
804,
8,
1975,
63,
261,
15987,
9,
2728,
4347,
5129,
63,
559,
29792,
275,
13573,
360,
597,
5129,
63,
559,
29792,
297,
283,
597,
5129,
63,
559,
29792,
358,
267,
1750,
63,
597,
5129,
63,
559,
29792,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
4347,
5129,
63,
559,
29792,
14,
525,
2610,
804,
8,
1975,
63,
597,
5129,
63,
559,
29792,
9,
2728,
3367,
555,
63,
261,
6051,
293,
275,
13573,
360,
280,
555,
63,
261,
6051,
293,
297,
283,
280,
555,
63,
261,
6051,
293,
358,
267,
1750,
63,
280,
555,
63,
261,
6051,
293,
275,
4905,
360,
1712,
63,
7308,
63,
7184,
297,
283,
555,
338,
9718,
4242,
297,
488,
9,
267,
3367,
555,
63,
261,
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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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
] |
huzhifeng/py12306
|
py12306.py
|
1
|
62739
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 标准库
import argparse
import urllib
import time
import datetime
import sys
import re
import ConfigParser
import random
import smtplib
from email.mime.text import MIMEText
# 第三方库
import requests
from huzhifeng import dumpObj, hasKeys
# Set default encoding to utf-8
reload(sys)
sys.setdefaultencoding('utf-8')
requests.packages.urllib3.disable_warnings()
# 全局变量
RET_OK = 0
RET_ERR = -1
MAX_TRIES = 3
MAX_DAYS = 60
stations = []
seatMaps = [
('1', u'硬座'), # 硬座/无座
('3', u'硬卧'),
('4', u'软卧'),
('7', u'一等软座'),
('8', u'二等软座'),
('9', u'商务座'),
('M', u'一等座'),
('O', u'二等座'),
('B', u'混编硬座'),
('P', u'特等座')
]
# 全局函数
def printDelimiter():
print('-' * 64)
def getTime():
return time.strftime('%Y-%m-%d %X', time.localtime()) # 2014-01-01 12:00:00
def date2UTC(d):
# Convert '2014-01-01' to 'Wed Jan 01 00:00:00 UTC+0800 2014'
t = time.strptime(d, '%Y-%m-%d')
asc = time.asctime(t) # 'Wed Jan 01 00:00:00 2014'
# 'Wed Jan 01 00:00:00 UTC+0800 2014'
return (asc[0:-4] + 'UTC+0800 ' + asc[-4:])
def getCardType(key):
d = {
'1': u'二代身份证',
'2': u'一代身份证',
'C': u'港澳通行证',
'G': u'台湾通行证',
'B': u'护照'
}
return d[key] if key in d else u'未知证件类型'
def getTicketType(key):
d = {
'1': u'成人票',
'2': u'儿童票',
'3': u'学生票',
'4': u'残军票'
}
return d[key] if key in d else u'未知票种'
def getSeatType(key):
d = dict(seatMaps)
return d[key] if key in d else u'未知席别'
def selectSeatType():
key = '1' # 默认硬座
while True:
print(u'请选择席别编码(即左边第一个英文字母):')
for xb in seatMaps:
print(u'%s: %s' % (xb[0], xb[1]))
key = raw_input().upper()
d = dict(seatMaps)
if key in d:
return key
else:
print(u'无效的席别类型!')
def checkDate(date):
m = re.match(r'^\d{4}-\d{2}-\d{2}$', date) # 2014-01-01
if m:
today = datetime.datetime.now()
fmt = '%Y-%m-%d'
today = datetime.datetime.strptime(today.strftime(fmt), fmt)
train_date = datetime.datetime.strptime(m.group(0), fmt)
delta = train_date - today
if delta.days < 0:
print(u'乘车日期%s无效, 只能预订%s以后的车票' % (
train_date.strftime(fmt),
today.strftime(fmt)))
return False
else:
return True
else:
return False
def selectDate():
fmt = '%Y-%m-%d'
week_days = [u'星期一', u'星期二', u'星期三', u'星期四', u'星期五', u'星期六', u'星期天']
now = datetime.datetime.now()
available_date = [(now + datetime.timedelta(days=i)) for i in xrange(MAX_DAYS)]
for i in xrange(0, MAX_DAYS, 2):
print(u'第%2d天: %s(%s)' % (
i + 1, available_date[i].strftime(fmt), week_days[available_date[i].weekday()])),
if i + 1 < MAX_DAYS:
print(u'\t\t第%2d天: %s(%s)' % (
i + 2, available_date[i + 1].strftime(fmt), week_days[available_date[i + 1].weekday()]))
else:
print('')
while True:
print(u'请选择乘车日期(1~%d)' % (MAX_DAYS))
index = raw_input()
if not index.isdigit():
print(u'只能输入数字序号, 请重新选择乘车日期(1~%d)' % (MAX_DAYS))
continue
index = int(index)
if index < 1 or index > MAX_DAYS:
print(u'输入的序号无效, 请重新选择乘车日期(1~%d)' % (MAX_DAYS))
continue
index -= 1
train_date = available_date[index].strftime(fmt)
return train_date
def getStationByName(name):
matched_stations = []
for station in stations:
if (
station['name'] == name
or station['abbr'].find(name.lower()) != -1
or station['pinyin'].find(name.lower()) != -1
or station['pyabbr'].find(name.lower()) != -1):
matched_stations.append(station)
count = len(matched_stations)
if count <= 0:
return None
elif count == 1:
return matched_stations[0]
else:
for i in xrange(0, count):
print(u'%d:\t%s' % (i + 1, matched_stations[i]['name']))
print(u'请选择站点(1~%d)' % (count))
index = raw_input()
if not index.isdigit():
print(u'只能输入数字序号(1~%d)' % (count))
return None
index = int(index)
if index < 1 or index > count:
print(u'输入的序号无效(1~%d)' % (count))
return None
else:
return matched_stations[index - 1]
def inputStation():
while True:
print(u'支持中文, 拼音和拼音缩写(如: 北京,beijing,bj)')
name = raw_input().decode('gb2312', 'ignore')
station = getStationByName(name)
if station:
return station
else:
print(u'站点错误, 没有站点"%s", 请重新输入.' % (name))
def selectTrain(trains):
trains_num = len(trains)
index = 0
while True: # 必须选择有效的车次
index = raw_input()
if not index.isdigit():
print(u'只能输入数字序号,请重新选择车次(1~%d)' % (trains_num))
continue
index = int(index)
if index < 1 or index > trains_num:
print(u'输入的序号无效,请重新选择车次(1~%d)' % (trains_num))
continue
if trains[index - 1]['queryLeftNewDTO']['canWebBuy'] != 'Y':
print(u'您选择的车次%s没票啦,请重新选择车次' % (
trains[index - 1]['queryLeftNewDTO']['station_train_code']))
continue
else:
break
return index
class MyOrder(object):
'''docstring for MyOrder'''
def __init__(
self,
username='',
password='',
train_date='',
from_city_name='',
to_city_name=''):
super(MyOrder, self).__init__()
self.username = username # 账号
self.password = password # 密码
self.train_date = train_date # 乘车日期[2014-01-01]
today = datetime.datetime.now()
self.back_train_date = today.strftime('%Y-%m-%d') # 返程日期[2014-01-01]
self.tour_flag = 'dc' # 单程dc/往返wf
self.purpose_code = 'ADULT' # 成人票
self.from_city_name = from_city_name # 对应查询界面'出发地'输入框中的内容
self.to_city_name = to_city_name # 对应查询界面'目的地'输入框中的内容
self.from_station_telecode = '' # 出发站编码
self.to_station_telecode = '' # 目的站编码
self.passengers = [] # 乘车人列表,最多5人
self.normal_passengers = [] # 我的联系人列表
self.trains = [] # 列车列表, 查询余票后自动更新
self.current_train_index = 0 # 当前选中的列车索引序号
self.captcha = '' # 图片验证码
self.orderId = '' # 订单流水号
self.canWebBuy = False # 可预订
self.notify = {
'mail_enable': 0,
'mail_username': '',
'mail_password': '',
'mail_server': '',
'mail_to': [],
'dates': [],
'trains': [],
'xb': [],
'focus': {}
}
def initSession(self):
self.session = requests.Session()
self.session.headers = {
'Accept': 'application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)',
'Referer': 'https://kyfw.12306.cn/otn/index/init',
'Host': 'kyfw.12306.cn',
'Connection': 'Keep-Alive'
}
def updateHeaders(self, url):
d = {
'https://kyfw.12306.cn/otn/resources/js/framework/station_name.js': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/'
},
'https://kyfw.12306.cn/otn/login/init': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/'
},
'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/login/init'
},
'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc'
},
'https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/login/init',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/login/loginAysnSuggest': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/login/init',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/login/userLogin': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/login/init'
},
'https://kyfw.12306.cn/otn/index/init': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/login/init'
},
'https://kyfw.12306.cn/otn/leftTicket/init': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/index/init',
'Content-Type': 'application/x-www-form-urlencoded'
},
'https://kyfw.12306.cn/otn/leftTicket/log?': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/leftTicket/init',
'x-requested-with': 'XMLHttpRequest',
'Cache-Control': 'no-cache',
'If-Modified-Since': '0'
},
'https://kyfw.12306.cn/otn/leftTicket/query?': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/leftTicket/init',
'x-requested-with': 'XMLHttpRequest',
'Cache-Control': 'no-cache',
'If-Modified-Since': '0'
},
'https://kyfw.12306.cn/otn/leftTicket/queryT?': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/leftTicket/init',
'x-requested-with': 'XMLHttpRequest',
'Cache-Control': 'no-cache',
'If-Modified-Since': '0'
},
'https://kyfw.12306.cn/otn/login/checkUser': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/leftTicket/init',
'Cache-Control': 'no-cache',
'If-Modified-Since': '0',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/confirmPassenger/initDc': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/leftTicket/init',
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache'
},
'https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/confirmPassenger/checkOrderInfo': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/confirmPassenger/getQueueCount': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'x-requested-with': 'XMLHttpRequest'
},
'https://kyfw.12306.cn/otn/confirmPassenger/resultOrderForDcQueue': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
'https://kyfw.12306.cn/otn//payOrder/init?': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded'
},
'https://kyfw.12306.cn/otn/queryOrder/initNoComplete': {
'method': 'GET',
'Referer': 'https://kyfw.12306.cn/otn//payOrder/init?random=1417862054369'
},
'https://kyfw.12306.cn/otn/queryOrder/queryMyOrderNoComplete': {
'method': 'POST',
'Referer': 'https://kyfw.12306.cn/otn/queryOrder/initNoComplete',
'Cache-Control': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}
l = [
'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&',
'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&',
'https://kyfw.12306.cn/otn/leftTicket/log?',
'https://kyfw.12306.cn/otn/leftTicket/query?',
'https://kyfw.12306.cn/otn/leftTicket/queryT?',
'https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?',
'https://kyfw.12306.cn/otn//payOrder/init?'
]
for s in l:
if url.find(s) == 0:
url = s
if not url in d:
print(u'未知 url: %s' % url)
return RET_ERR
self.session.headers.update({'Referer': d[url]['Referer']})
keys = [
'Referer',
'Cache-Control',
'x-requested-with',
'Content-Type'
]
for key in keys:
if key in d[url]:
self.session.headers.update({key: d[url][key]})
else:
self.session.headers.update({key: None})
def get(self, url):
self.updateHeaders(url)
tries = 0
while tries < MAX_TRIES:
tries += 1
try:
r = self.session.get(url, verify=False, timeout=16)
except requests.exceptions.ConnectionError as e:
print('ConnectionError(%s): e=%s' % (url, e))
continue
except requests.exceptions.Timeout as e:
print('Timeout(%s): e=%s' % (url, e))
continue
except requests.exceptions.TooManyRedirects as e:
print('TooManyRedirects(%s): e=%s' % (url, e))
continue
except requests.exceptions.HTTPError as e:
print('HTTPError(%s): e=%s' % (url, e))
continue
except requests.exceptions.RequestException as e:
print('RequestException(%s): e=%s' % (url, e))
continue
except:
print('Unknown exception(%s)' % (url))
continue
if r.status_code != 200:
print('Request %s failed %d times, status_code=%d' % (
url,
tries,
r.status_code))
else:
return r
else:
return None
def post(self, url, payload):
self.updateHeaders(url)
if url == 'https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn':
if payload.find('REPEAT_SUBMIT_TOKEN') != -1:
self.session.headers.update({'Referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc'})
else:
self.session.headers.update({'Referer': 'https://kyfw.12306.cn/otn/login/init'})
tries = 0
while tries < MAX_TRIES:
tries += 1
try:
r = self.session.post(url, data=payload, verify=False, timeout=16)
except requests.exceptions.ConnectionError as e:
print('ConnectionError(%s): e=%s' % (url, e))
continue
except requests.exceptions.Timeout as e:
print('Timeout(%s): e=%s' % (url, e))
continue
except requests.exceptions.TooManyRedirects as e:
print('TooManyRedirects(%s): e=%s' % (url, e))
continue
except requests.exceptions.HTTPError as e:
print('HTTPError(%s): e=%s' % (url, e))
continue
except requests.exceptions.RequestException as e:
print('RequestException(%s): e=%s' % (url, e))
continue
except:
print('Unknown exception(%s)' % (url))
continue
if r.status_code != 200:
print('Request %s failed %d times, status_code=%d' % (
url,
tries,
r.status_code))
else:
return r
else:
return None
def getCaptcha(self, url):
self.updateHeaders(url)
r = self.session.get(url, verify=False, stream=True, timeout=16)
with open('captcha.gif', 'wb') as fd:
for chunk in r.iter_content():
fd.write(chunk)
print(u'请输入4位图片验证码(回车刷新验证码):')
captcha = raw_input()
if len(captcha) == 4:
return captcha
elif len(captcha) != 0:
print(u'%s是无效的图片验证码, 必须是4位' % (captcha))
return None
else:
return 1 # 刷新
def initStation(self):
url = 'https://kyfw.12306.cn/otn/resources/js/framework/station_name.js'
r = self.get(url)
if not r:
print(u'站点数据库初始化失败, 请求异常')
return None
data = r.text
station_list = data.split('@')
if len(station_list) < 1:
print(u'站点数据库初始化失败, 数据异常')
return None
station_list = station_list[1:]
for station in station_list:
items = station.split('|') # bji|北京|BJP|beijing|bj|2
if len(items) < 5:
print(u'忽略无效站点: %s' % (items))
continue
stations.append({'abbr': items[0],
'name': items[1],
'telecode': items[2],
'pinyin': items[3],
'pyabbr': items[4]})
return stations
def readConfig(self, config_file='config.ini'):
cp = ConfigParser.ConfigParser()
try:
cp.readfp(open(config_file, 'r'))
except IOError as e:
print(u'打开配置文件"%s"失败啦, 请先创建或者拷贝一份配置文件config.ini' % (config_file))
raw_input('Press any key to continue')
sys.exit()
self.username = cp.get('login', 'username')
self.password = cp.get('login', 'password')
self.train_date = cp.get('train', 'date')
self.from_city_name = cp.get('train', 'from')
self.to_city_name = cp.get('train', 'to')
self.notify['mail_enable'] = int(cp.get('notify', 'mail_enable'))
self.notify['mail_username'] = cp.get('notify', 'mail_username')
self.notify['mail_password'] = cp.get('notify', 'mail_password')
self.notify['mail_server'] = cp.get('notify', 'mail_server')
self.notify['mail_to'] = cp.get('notify', 'mail_to').split(',')
self.notify['dates'] = cp.get('notify', 'dates').split(',')
self.notify['trains'] = cp.get('notify', 'trains').split(',')
self.notify['xb'] = cp.get('notify', 'xb').split(',')
for t in self.notify['trains']:
self.notify['focus'][t] = self.notify['xb']
# 检查出发站
station = getStationByName(self.from_city_name)
if not station:
print(u'出发站错误, 请重新输入')
station = inputStation()
self.from_city_name = station['name']
self.from_station_telecode = station['telecode']
# 检查目的站
station = getStationByName(self.to_city_name)
if not station:
print(u'目的站错误,请重新输入')
station = inputStation()
self.to_city_name = station['name']
self.to_station_telecode = station['telecode']
# 检查乘车日期
if not checkDate(self.train_date):
print(u'乘车日期无效, 请重新选择')
self.train_date = selectDate()
# 分析乘客信息
self.passengers = []
index = 1
passenger_sections = ['passenger%d' % (i) for i in xrange(1, 6)]
sections = cp.sections()
for section in passenger_sections:
if section in sections:
passenger = {}
passenger['index'] = index
passenger['name'] = cp.get(section, 'name') # 必选参数
passenger['cardtype'] = cp.get(
section,
'cardtype') if cp.has_option(
section,
'cardtype') else '1' # 证件类型:可选参数,默认值1,即二代身份证
passenger['id'] = cp.get(section, 'id') # 必选参数
passenger['phone'] = cp.get(
section,
'phone') if cp.has_option(
section,
'phone') else '13800138000' # 手机号码
passenger['seattype'] = cp.get(
section,
'seattype') if cp.has_option(
section,
'seattype') else '1' # 席别:可选参数, 默认值1, 即硬座
passenger['tickettype'] = cp.get(
section,
'tickettype') if cp.has_option(
section,
'tickettype') else '1' # 票种:可选参数, 默认值1, 即成人票
self.passengers.append(passenger)
index += 1
def printConfig(self):
printDelimiter()
print(u'订票信息:\n%s\t%s\t%s--->%s' % (
self.username,
self.train_date,
self.from_city_name,
self.to_city_name))
printDelimiter()
th = [u'序号', u'姓名', u'证件类型', u'证件号码', u'席别', u'票种']
print(u'%s\t%s\t%s\t%s\t%s\t%s' % (
th[0].ljust(2), th[1].ljust(4), th[2].ljust(5),
th[3].ljust(12), th[4].ljust(2), th[5].ljust(3)))
for p in self.passengers:
print(u'%s\t%s\t%s\t%s\t%s\t%s' % (
p['index'],
p['name'].decode('utf-8', 'ignore').ljust(4),
getCardType(p['cardtype']).ljust(5),
p['id'].ljust(20),
getSeatType(p['seattype']).ljust(2),
getTicketType(p['tickettype']).ljust(3)))
def checkRandCodeAnsyn(self, module):
d = {
'login': { # 登陆验证码
'rand': 'sjrand',
'referer': 'https://kyfw.12306.cn/otn/login/init'
},
'passenger': { # 订单验证码
'rand': 'randp',
'referer': 'https://kyfw.12306.cn/otn/confirmPassenger/initDc'
}
}
if not module in d:
print(u'无效的 module: %s' % (module))
return RET_ERR
tries = 0
while tries < MAX_TRIES:
tries += 1
url = 'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=%s&rand=%s&' % (module, d[module]['rand'])
if tries > 1:
url = '%s%1.16f' % (url, random.random())
print(u'正在等待验证码...')
self.captcha = self.getCaptcha(url)
if not self.captcha:
continue
if self.captcha == 1: # 刷新不计数
tries -= 1
continue
url = 'https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn'
parameters = [
('randCode', self.captcha),
('rand', d[module]['rand'])
]
if module == 'login':
parameters.append(('randCode_validate', ''))
else:
parameters.append(('_json_att', ''))
parameters.append(('REPEAT_SUBMIT_TOKEN', self.repeatSubmitToken))
payload = urllib.urlencode(parameters)
print(u'正在校验验证码...')
r = self.post(url, payload)
if not r:
print(u'校验验证码异常')
continue
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"result":"1","msg":"randCodeRight"},"messages":[],"validateMessages":{}}
obj = r.json()
if (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['result', 'msg'])
and (obj['data']['result'] == '1')):
print(u'校验验证码成功')
return RET_OK
else:
print(u'校验验证码失败')
dumpObj(obj)
continue
else:
return RET_ERR
def login(self):
url = 'https://kyfw.12306.cn/otn/login/init'
r = self.get(url)
if not r:
print(u'登录失败, 请求异常')
return RET_ERR
if self.session.cookies:
cookies = requests.utils.dict_from_cookiejar(self.session.cookies)
if cookies['JSESSIONID']:
self.jsessionid = cookies['JSESSIONID']
if self.checkRandCodeAnsyn('login') == RET_ERR:
return RET_ERR
print(u'正在登录...')
url = 'https://kyfw.12306.cn/otn/login/loginAysnSuggest'
parameters = [
('loginUserDTO.user_name', self.username),
('userDTO.password', self.password),
('randCode', self.captcha),
('randCode_validate', ''),
#('ODg3NzQ0', 'OTIyNmFhNmQwNmI5ZmQ2OA%3D%3D'),
('myversion', 'undefined')
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'登录失败, 请求异常')
return RET_ERR
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"loginCheck":"Y"},"messages":[],"validateMessages":{}}
obj = r.json()
if (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['loginCheck'])
and (obj['data']['loginCheck'] == 'Y')):
print(u'登陆成功^_^')
url = 'https://kyfw.12306.cn/otn/login/userLogin'
parameters = [
('_json_att', ''),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
return RET_OK
else:
print(u'登陆失败啦!重新登陆...')
dumpObj(obj)
return RET_ERR
def getPassengerDTOs(self):
url = 'https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs'
parameters = [
('', ''),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'获取乘客信息异常')
return RET_ERR
obj = r.json()
if (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['normal_passengers'])
and obj['data']['normal_passengers']):
self.normal_passengers = obj['data']['normal_passengers']
return RET_OK
else:
print(u'获取乘客信息失败')
if hasKeys(obj, ['messages']):
dumpObj(obj['messages'])
if hasKeys(obj, ['data']) and hasKeys(obj['data'], ['exMsg']):
dumpObj(obj['data']['exMsg'])
return RET_ERR
def selectPassengers(self, prompt):
if prompt == 1:
print(u'是否重新选择乘客?(如需选择请输入y或者yes, 默认使用配置文件提供的乘客信息)')
act = raw_input()
act = act.lower()
if act != 'y' and act != 'yes':
self.printConfig()
return RET_OK
if not (self.normal_passengers and len(self.normal_passengers)):
tries = 0
while tries < MAX_TRIES:
tries += 1
if self.getPassengerDTOs() == RET_OK:
break
else:
print(u'获取乘客信息失败次数太多, 使用配置文件提供的乘客信息')
return RET_ERR
num = len(self.normal_passengers)
for i in xrange(0, num):
p = self.normal_passengers[i]
print(u'%d.%s \t' % (i + 1, p['passenger_name'])),
if (i + 1) % 5 == 0:
print('')
while True:
print(u'\n请选择乘车人(最多选择5个, 以逗号隔开, 如:1,2,3,4,5, 直接回车不选择, 使用配置文件中的乘客信息)')
buf = raw_input()
if not buf:
return RET_ERR
pattern = re.compile(r'^[0-9,]*\d$') # 只能输入数字和逗号, 并且必须以数字结束
if pattern.match(buf):
break
else:
print(u'输入格式错误, 只能输入数字和逗号, 并且必须以数字结束, 如:1,2,3,4,5')
ids = buf.split(',')
if not (ids and 1 <= len(ids) <= 5):
return RET_ERR
seattype = selectSeatType()
ids = [int(id) for id in ids]
del self.passengers[:]
for id in ids:
if id < 1 or id > num:
print(u'不存在的联系人, 忽略')
else:
passenger = {}
id = id - 1
passenger['index'] = len(self.passengers) + 1
passenger['name'] = self.normal_passengers[id]['passenger_name']
passenger['cardtype'] = self.normal_passengers[id]['passenger_id_type_code']
passenger['id'] = self.normal_passengers[id]['passenger_id_no']
passenger['phone'] = self.normal_passengers[id]['mobile_no']
passenger['seattype'] = seattype
passenger['tickettype'] = self.normal_passengers[id]['passenger_type']
self.passengers.append(passenger)
self.printConfig()
return RET_OK
def queryTickets(self):
self.canWebBuy = False
url = 'https://kyfw.12306.cn/otn/leftTicket/init'
parameters = [
('_json_att', ''),
('leftTicketDTO.from_station_name', self.from_city_name),
('leftTicketDTO.to_station_name', self.to_city_name),
('leftTicketDTO.from_station', self.from_station_telecode),
('leftTicketDTO.to_station', self.to_station_telecode),
('leftTicketDTO.train_date', self.train_date),
('back_train_date', self.back_train_date),
('purpose_codes', self.purpose_code),
('pre_step_flag', 'index')
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'查询车票异常')
url = 'https://kyfw.12306.cn/otn/leftTicket/log?'
parameters = [
('leftTicketDTO.train_date', self.train_date),
('leftTicketDTO.from_station', self.from_station_telecode),
('leftTicketDTO.to_station', self.to_station_telecode),
('purpose_codes', self.purpose_code),
]
url += urllib.urlencode(parameters)
r = self.get(url)
if not r:
print(u'查询车票异常')
url = 'https://kyfw.12306.cn/otn/leftTicket/queryT?'
parameters = [
('leftTicketDTO.train_date', self.train_date),
('leftTicketDTO.from_station', self.from_station_telecode),
('leftTicketDTO.to_station', self.to_station_telecode),
('purpose_codes', self.purpose_code),
]
url += urllib.urlencode(parameters)
r = self.get(url)
if not r:
print(u'查询车票异常')
return RET_ERR
obj = r.json()
if (hasKeys(obj, ['status', 'httpstatus', 'data']) and len(obj['data'])):
self.trains = obj['data']
return RET_OK
else:
print(u'查询车票失败')
if hasKeys(obj, ['messages']):
dumpObj(obj['messages'])
return RET_ERR
def sendMailNotification(self):
print(u'正在发送邮件提醒...')
me = u'订票提醒<%s>' % (self.notify['mail_username'])
msg = MIMEText(
self.notify['mail_content'],
_subtype='plain',
_charset='gb2312')
msg['Subject'] = u'余票信息'
msg['From'] = me
msg['To'] = ';'.join(self.notify['mail_to'])
try:
server = smtplib.SMTP()
server.connect(self.notify['mail_server'])
server.login(
self.notify['mail_username'],
self.notify['mail_password'])
server.sendmail(me, self.notify['mail_to'], msg.as_string())
server.close()
print(u'发送邮件提醒成功')
return True
except Exception as e:
print(u'发送邮件提醒失败, %s' % str(e))
return False
def printTrains(self):
printDelimiter()
print(u'余票查询结果如下:')
print(u"%s\t%s--->%s\n'有':票源充足 '无':票已售完 '*':未到起售时间 '--':无此席别" % (
self.train_date,
self.from_city_name,
self.to_city_name))
printDelimiter()
print(u'序号/车次\t乘车站\t目的站\t一等\t二等\t软卧\t硬卧\t硬座\t无座')
seatTypeCode = {
'swz': '商务座',
'tz': '特等座',
'zy': '一等座',
'ze': '二等座',
'gr': '高级软卧',
'rw': '软卧',
'yw': '硬卧',
'rz': '软座',
'yz': '硬座',
'wz': '无座',
'qt': '其它',
}
# TODO 余票数量和票价 https://kyfw.12306.cn/otn/leftTicket/queryTicketPrice?train_no=770000K77505&from_station_no=09&to_station_no=13&seat_types=1431&train_date=2014-01-01
# yp_info=4022300000301440004610078033421007800536 代表
# 4022300000 软卧0
# 3014400046 硬卧46
# 1007803342 无座342
# 1007800536 硬座536
index = 1
self.notify['mail_content'] = ''
for train in self.trains:
t = train['queryLeftNewDTO']
status = '售完' if t['canWebBuy'] == 'N' else '预定'
i = 0
ypInfo = {
'wz': { # 无座
'price': 0,
'left': 0
},
'yz': { # 硬座
'price': 0,
'left': 0
},
'yw': { # 硬卧
'price': 0,
'left': 0
},
'rw': { # 软卧
'price': 0,
'left': 0
},
}
# 分析票价和余票数量
while i < (len(t['yp_info']) / 10):
tmp = t['yp_info'][i * 10:(i + 1) * 10]
price = int(tmp[1:5])
left = int(tmp[-3:])
if tmp[0] == '1':
if tmp[6] == '3':
ypInfo['wz']['price'] = price
ypInfo['wz']['left'] = left
else:
ypInfo['yz']['price'] = price
ypInfo['yz']['left'] = left
elif tmp[0] == '3':
ypInfo['yw']['price'] = price
ypInfo['yw']['left'] = left
elif tmp[0] == '4':
ypInfo['rw']['price'] = price
ypInfo['rw']['left'] = left
i = i + 1
yz_price = u'硬座%s' % (
ypInfo['yz']['price']) if ypInfo['yz']['price'] else ''
yw_price = u'硬卧%s' % (
ypInfo['yw']['price']) if ypInfo['yw']['price'] else ''
print(u'(%d) %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' % (
index,
t['station_train_code'],
t['from_station_name'][0:3], # 最多保留3个中文
t['to_station_name'][0:3], # 最多保留3个中文
t['zy_num'],
t['ze_num'],
ypInfo['rw']['left'] if ypInfo['rw']['left'] else t['rw_num'],
ypInfo['yw']['left'] if ypInfo['yw']['left'] else t['yw_num'],
#t['rz_num'],
ypInfo['yz']['left'] if ypInfo['yz']['left'] else t['yz_num'],
ypInfo['wz']['left'] if ypInfo['wz']['left'] else t['wz_num'],
#yz_price,
#yw_price
))
if t['canWebBuy'] == 'Y':
self.canWebBuy = True
index += 1
if self.notify['mail_enable'] == 1 and t['canWebBuy'] == 'Y':
msg = ''
prefix = u'[%s]车次%s[%s/%s->%s/%s, 历时%s]现在有票啦\n' % (
t['start_train_date'],
t['station_train_code'],
t['from_station_name'],
t['start_time'],
t['to_station_name'],
t['arrive_time'],
t['lishi'])
if 'all' in self.notify['focus']: # 任意车次
if self.notify['focus']['all'][0] == 'all': # 任意席位
msg = prefix
else: # 指定席位
for seat in self.notify['focus']['all']:
if seat in ypInfo and ypInfo[seat]['left']:
msg += u'座位类型:%s, 剩余车票数量:%s, 票价:%s \n' % (
seat if seat not in seatTypeCode else seatTypeCode[seat],
ypInfo[seat]['left'],
ypInfo[seat]['price'])
if msg:
msg = prefix + msg + u'\n'
elif t['station_train_code'] in self.notify['focus']: # 指定车次
# 任意席位
if self.notify['focus'][t['station_train_code']][0] == 'all':
msg = prefix
else: # 指定席位
for seat in self.notify['focus'][t['station_train_code']]:
if seat in ypInfo and ypInfo[seat]['left']:
msg += u'座位类型:%s, 剩余车票数量:%s, 票价:%s \n' % (
seat if seat not in seatTypeCode else seatTypeCode[seat],
ypInfo[seat]['left'],
ypInfo[seat]['price'])
if msg:
msg = prefix + msg + u'\n'
self.notify['mail_content'] += msg
printDelimiter()
if self.notify['mail_enable'] == 1:
if self.notify['mail_content']:
self.sendMailNotification()
return RET_OK
else:
length = len(self.notify['dates'])
if length > 1:
self.train_date = self.notify['dates'][
random.randint(
0,
length -
1)]
return RET_ERR
else:
return RET_OK
# -1->重新查询/0->退出程序/1~len->车次序号
def selectAction(self):
ret = -1
self.current_train_index = 0
trains_num = len(self.trains)
print(u'您可以选择:')
if self.canWebBuy:
print(u'1~%d.选择车次开始订票' % (trains_num))
print(u'p.更换乘车人')
print(u's.更改席别')
print(u'd.更改乘车日期')
print(u'f.更改出发站')
print(u't.更改目的站')
print(u'a.同时更改乘车日期,出发站和目的站')
print(u'u.查询未完成订单')
print(u'c.查看订票信息')
print(u'r.刷票模式')
print(u'n.普通模式')
print(u'q.退出')
print(u'刷新车票请直接回车')
printDelimiter()
select = raw_input()
select = select.lower()
if select.isdigit():
if not self.canWebBuy:
print(u'没有可预订的车次, 请刷新车票或者更改查询条件')
return -1
index = int(select)
if index < 1 or index > trains_num:
print(u'输入的序号无效,请重新选择车次(1~%d)' % (trains_num))
index = selectTrain(self.trains)
if self.trains[index - 1]['queryLeftNewDTO']['canWebBuy'] != 'Y':
print(u'您选择的车次%s没票啦,请重新选择车次' % (self.trains[index - 1]['queryLeftNewDTO']['station_train_code']))
index = selectTrain(self.trains)
ret = index
self.current_train_index = index - 1
elif select == 'p':
self.selectPassengers(0)
elif select == 's':
seattype = selectSeatType()
for p in self.passengers:
p['seattype'] = seattype
self.printConfig()
elif select == 'd':
self.train_date = selectDate()
elif select == 'f':
print(u'请输入出发站:')
station = inputStation()
self.from_city_name = station['name']
self.from_station_telecode = station['telecode']
elif select == 't':
print(u'请输入目的站:')
station = inputStation()
self.to_city_name = station['name']
self.to_station_telecode = station['telecode']
elif select == 'a':
self.train_date = selectDate()
print(u'请输入出发站:')
station = inputStation()
self.from_city_name = station['name']
self.from_station_telecode = station['telecode']
print(u'请输入目的站:')
station = inputStation()
self.to_city_name = station['name']
self.to_station_telecode = station['telecode']
elif select == 'u':
ret = self.queryMyOrderNotComplete()
ret = self.selectAction()
elif select == 'c':
ret = self.printConfig()
ret = self.selectAction()
elif select == 'r':
self.notify['mail_enable'] = 1
ret = -1
elif select == 'n':
self.notify['mail_enable'] = 0
ret = -1
elif select == 'q':
ret = 0
return ret
def initOrder(self):
url = 'https://kyfw.12306.cn/otn/login/checkUser'
parameters = [
('_json_att', ''),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'初始化订单异常')
print(u'准备下单喽')
url = 'https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest'
parameters = [
#('ODA4NzIx', 'MTU0MTczYmQ2N2I3MjJkOA%3D%3D'),
('myversion', 'undefined'),
('secretStr', self.trains[self.current_train_index]['secretStr']),
('train_date', self.train_date),
('back_train_date', self.back_train_date),
('tour_flag', self.tour_flag),
('purpose_codes', self.purpose_code),
('query_from_station_name', self.from_city_name),
('query_to_station_name', self.to_city_name),
('undefined', '')
]
# TODO 注意:此处post不需要做urlencode, 比较奇怪, 不能用urllib.urlencode(parameters)
payload = ''
length = len(parameters)
for i in range(0, length):
payload += parameters[i][0] + '=' + parameters[i][1]
if i < (length - 1):
payload += '&'
r = self.post(url, payload)
if not r:
print(u'下单异常')
return RET_ERR
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"messages":[],"validateMessages":{}}
obj = r.json()
if not (hasKeys(obj, ['status', 'httpstatus'])
and obj['status']):
print(u'下单失败啦')
dumpObj(obj)
return RET_ERR
print(u'订单初始化...')
self.session.close() # TODO
url = 'https://kyfw.12306.cn/otn/confirmPassenger/initDc'
parameters = [
('_json_att', ''),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'订单初始化异常')
return RET_ERR
data = r.text
s = data.find('globalRepeatSubmitToken') # TODO
e = data.find('global_lang')
if s == -1 or e == -1:
print(u'找不到 globalRepeatSubmitToken')
return RET_ERR
buf = data[s:e]
s = buf.find("'")
e = buf.find("';")
if s == -1 or e == -1:
print(u'很遗憾, 找不到 globalRepeatSubmitToken')
return RET_ERR
self.repeatSubmitToken = buf[s + 1:e]
s = data.find('key_check_isChange')
e = data.find('leftDetails')
if s == -1 or e == -1:
print(u'找不到 key_check_isChange')
return RET_ERR
self.keyCheckIsChange = data[s + len('key_check_isChange') + 3:e - 3]
return RET_OK
def checkOrderInfo(self):
if self.checkRandCodeAnsyn('passenger') == RET_ERR:
return RET_ERR
passengerTicketStr = ''
oldPassengerStr = ''
passenger_seat_detail = '0' # TODO [0->随机][1->下铺][2->中铺][3->上铺]
for p in self.passengers:
if p['index'] != 1:
passengerTicketStr += 'N_'
oldPassengerStr += '1_'
passengerTicketStr += '%s,%s,%s,%s,%s,%s,%s,' % (
p['seattype'],
passenger_seat_detail,
p['tickettype'],
p['name'],
p['cardtype'],
p['id'],
p['phone'])
oldPassengerStr += '%s,%s,%s,' % (
p['name'],
p['cardtype'],
p['id'])
passengerTicketStr += 'N'
oldPassengerStr += '1_'
self.passengerTicketStr = passengerTicketStr
self.oldPassengerStr = oldPassengerStr
print(u'检查订单...')
url = 'https://kyfw.12306.cn/otn/confirmPassenger/checkOrderInfo'
parameters = [
('cancel_flag', '2'), # TODO
('bed_level_order_num', '000000000000000000000000000000'), # TODO
('passengerTicketStr', self.passengerTicketStr),
('oldPassengerStr', self.oldPassengerStr),
('tour_flag', self.tour_flag),
('randCode', self.captcha),
#('NzA4MTc1', 'NmYyYzZkYWY2OWZkNzg2YQ%3D%3D'), # TODO
('_json_att', ''),
('REPEAT_SUBMIT_TOKEN', self.repeatSubmitToken),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'检查订单异常')
return RET_ERR
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"submitStatus":true},"messages":[],"validateMessages":{}}
obj = r.json()
if (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['submitStatus'])
and obj['status']
and obj['data']['submitStatus']):
print(u'检查订单成功')
return RET_OK
else:
print(u'检查订单失败')
dumpObj(obj)
return RET_ERR
def getQueueCount(self):
print(u'查询排队情况...')
url = 'https://kyfw.12306.cn/otn/confirmPassenger/getQueueCount'
t = self.trains[self.current_train_index]['queryLeftNewDTO']
parameters = [
('train_date', date2UTC(self.train_date)),
('train_no', t['train_no']),
('stationTrainCode', t['station_train_code']),
('seatType', '1'), # TODO
('fromStationTelecode', t['from_station_telecode']),
('toStationTelecode', t['to_station_telecode']),
('leftTicket', t['yp_info']),
('purpose_codes', '00'), # TODO
('_json_att', ''),
('REPEAT_SUBMIT_TOKEN', self.repeatSubmitToken)
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'查询排队情况异常')
return RET_ERR
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"count":"0","ticket":"100985109710098535003021350212","op_2":"false","countT":"0","op_1":"false"},"messages":[],"validateMessages":{}}
obj = r.json()
if not (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['op_1', 'op_2'])
and obj['status']):
print(u'查询排队情况失败')
dumpObj(obj)
return RET_ERR
if obj['data']['op_1'] != 'false':
print(u'已有人先于您提交相同的购票需求, 到处理您的需求时可能已无票, 建议根据当前余票确定是否排队.')
if obj['data']['op_2'] != 'false':
print(u'目前排队人数已经超过余票张数,请您选择其他席别或车次,特此提醒。')
if 'ticket' in obj['data']:
print(u'排队详情:%s' % (obj['data']['ticket'])) # TODO
return RET_OK
def confirmSingleForQueue(self):
print(u'提交订单排队...')
url = 'https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue'
t = self.trains[self.current_train_index]['queryLeftNewDTO']
parameters = [
('passengerTicketStr', self.passengerTicketStr),
('oldPassengerStr', self.oldPassengerStr),
('randCode', self.captcha),
('purpose_codes', '00'), # TODO
('key_check_isChange', self.keyCheckIsChange),
('leftTicketStr', t['yp_info']),
('train_location', t['location_code']),
('_json_att', ''),
('REPEAT_SUBMIT_TOKEN', self.repeatSubmitToken),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'提交订单排队异常')
return RET_ERR
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"submitStatus":true},"messages":[],"validateMessages":{}}
obj = r.json()
if (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['submitStatus'])
and obj['status'] and obj['data']['submitStatus']):
print(u'订单排队中...')
return RET_OK
else:
print(u'提交订单排队失败')
dumpObj(obj)
return RET_ERR
def queryOrderWaitTime(self):
print(u'等待订单流水号...')
url = 'https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?random=%13d&tourFlag=dc&_json_att=&REPEAT_SUBMIT_TOKEN=%s' % (
random.randint(1000000000000, 1999999999999), self.repeatSubmitToken)
r = self.get(url)
if not r:
print(u'等待订单流水号异常')
return RET_ERR
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"queryOrderWaitTimeStatus":true,"count":0,"waitTime":4,"requestId":5944637152210732219,"waitCount":2,"tourFlag":"dc","orderId":null},"messages":[],"validateMessages":{}}
# {"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{"queryOrderWaitTimeStatus":true,"count":0,"waitTime":-1,"requestId":5944637152210732219,"waitCount":0,"tourFlag":"dc","orderId":"E739900792"},"messages":[],"validateMessages":{}}
obj = r.json()
if not (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['orderId'])
and obj['status']
and obj['data']['orderId']):
print(u'等待订单流水号失败')
dumpObj(obj)
return RET_ERR
self.orderId = obj['data']['orderId']
if (self.orderId and self.orderId != 'null'):
print(u'订单流水号为:')
print(self.orderId)
return RET_OK
else:
print(u'等待订单流水号失败')
return RET_ERR
def payOrder(self):
print(u'等待订票结果...')
url = 'https://kyfw.12306.cn/otn/confirmPassenger/resultOrderForDcQueue'
parameters = [
('orderSequence_no', self.orderId),
('_json_att', ''),
('REPEAT_SUBMIT_TOKEN', self.repeatSubmitToken),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'等待订票结果异常')
return RET_ERR
# {'validateMessagesShowId':'_validatorMessage','status':true,'httpstatus':200,'data':{'submitStatus':true},'messages':[],'validateMessages':{}}
# {'validateMessagesShowId':'_validatorMessage','status':true,'httpstatus':200,'data':{'errMsg':'获取订单信息失败,请查看未完成订单,继续支付!','submitStatus':false},'messages':[],'validateMessages':{}}
obj = r.json()
if not (
hasKeys(obj, ['status', 'httpstatus', 'data'])
and hasKeys(obj['data'], ['submitStatus'])
and obj['status']
and obj['data']['submitStatus']):
print(u'等待订票结果失败')
dumpObj(obj)
return RET_ERR
url = 'https://kyfw.12306.cn/otn//payOrder/init?random=%13d' % (
random.randint(1000000000000, 1999999999999))
parameters = [
('_json_att', ''),
('REPEAT_SUBMIT_TOKEN', self.repeatSubmitToken),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'请求异常')
return RET_ERR
data = r.text
if data.find(u'席位已锁定') != -1:
print(u'订票成功^_^请在45分钟内完成网上支付,否则系统将自动取消')
return RET_OK
else:
return RET_ERR
def queryMyOrderNotComplete(self):
print(u'正在查询未完成订单...')
url = 'https://kyfw.12306.cn/otn/queryOrder/queryMyOrderNoComplete'
parameters = [
('_json_att', ''),
]
payload = urllib.urlencode(parameters)
r = self.post(url, payload)
if not r:
print(u'查询未完成订单异常')
return RET_ERR
obj = r.json()
if not (hasKeys(obj, ['status', 'httpstatus', 'data']) and obj['status']):
print(u'查询未完成订单失败')
dumpObj(obj)
return RET_ERR
if (hasKeys(obj['data'], ['orderDBList']) and len(obj['data']['orderDBList'])):
print(u'查询到有未完成订单,请先处理')
return RET_OK
if (
hasKeys(obj['data'], ['orderCacheDTO'])
and obj['data']['orderCacheDTO']
and hasKeys(obj['data']['orderCacheDTO'], ['status'])):
if obj['data']['orderCacheDTO']['status'] == 0:
print(u'查询到cache有未完成订单,请先处理')
return RET_OK
else:
if (hasKeys(obj['data']['orderCacheDTO'], ['message'])):
dumpObj(obj['data']['orderCacheDTO']['message'])
return RET_ERR
def main():
print(getTime())
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', help='Specify config file')
parser.add_argument('-u', '--username', help='Specify username to login')
parser.add_argument('-p', '--password', help='Specify password to login')
parser.add_argument('-d', '--date', help='Specify train date, 2014-01-01')
parser.add_argument('-m', '--mail', help='Send email notification')
args = parser.parse_args()
order = MyOrder()
order.initSession()
order.initStation()
if args.config:
order.readConfig(args.config) # 使用指定的配置文件
else:
order.readConfig() # 使用默认的配置文件config.ini
if args.username:
order.username = args.username # 使用指定的账号代替配置文件中的账号
if args.password:
order.password = args.password # 使用指定的密码代替配置文件中的密码
if args.date:
if checkDate(args.date):
order.train_date = args.date # 使用指定的乘车日期代替配置文件中的乘车日期
else:
print(u'乘车日期无效, 请重新选择')
order.train_date = selectDate()
if args.mail:
# 有票时自动发送邮件通知
order.notify['mail_enable'] = 1 if args.mail == '1' else 0
tries = 0
while tries < MAX_TRIES:
tries += 1
if order.login() == RET_OK:
break
else:
print(u'失败次数太多,自动退出程序')
sys.exit()
order.selectPassengers(1)
while True:
time.sleep(1)
# 查询车票
if order.queryTickets() != RET_OK:
continue
# 显示查询结果
if order.printTrains() != RET_OK:
continue
# 选择菜单列举的动作之一
action = order.selectAction()
if action == -1:
continue
elif action == 0:
break
# 订单初始化
if order.initOrder() != RET_OK:
continue
# 检查订单信息
if order.checkOrderInfo() != RET_OK:
continue
# 查询排队和余票情况
# if order.getQueueCount() != RET_OK:
# continue
# 提交订单到队里中
tries = 0
while tries < 2:
tries += 1
if order.confirmSingleForQueue() == RET_OK:
break
# 获取orderId
tries = 0
while tries < 2:
tries += 1
if order.queryOrderWaitTime() == RET_OK:
break
# 正式提交订单
if order.payOrder() == RET_OK:
break
# 访问未完成订单页面检查是否订票成功
if order.queryMyOrderNotComplete() == RET_OK:
print(u'订票成功^_^请在45分钟内完成网上支付,否则系统将自动取消')
break
print(getTime())
raw_input('Press any key to continue')
if __name__ == '__main__':
main()
# EOF
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8853,
255,
230,
15977,
229,
15013,
242,
199,
646,
7534,
199,
646,
4011,
199,
646,
900,
199,
646,
2197,
199,
646,
984,
199,
646,
295,
199,
646,
14196,
199,
646,
2196,
199,
646,
30475,
199,
504,
3031,
14,
7626,
14,
505,
492,
603,
26567,
199,
199,
3,
9112,
106,
106,
4344,
232,
24302,
15013,
242,
199,
646,
4145,
199,
504,
394,
85,
3951,
692,
7420,
492,
5461,
5665,
12,
965,
6340,
199,
199,
3,
2494,
849,
2644,
370,
2774,
13,
24,
199,
9233,
8,
1274,
9,
199,
1274,
14,
409,
27205,
28139,
360,
1624,
13,
24,
358,
199,
6615,
14,
5154,
14,
4078,
19,
14,
5993,
63,
5451,
342,
199,
199,
3,
7094,
228,
102,
27289,
223,
6075,
247,
22485,
199,
7341,
63,
3593,
275,
378,
199,
7341,
63,
2666,
275,
446,
17,
199,
4283,
63,
1766,
2563,
275,
650,
199,
4283,
63,
25683,
275,
5212,
199,
270,
1298,
275,
942,
199,
261,
292,
24995,
275,
359,
272,
661,
17,
297,
399,
7,
164,
95,
106,
15013,
101,
659,
221,
327,
9112,
95,
106,
15013,
101,
15,
11373,
255,
15013,
101,
272,
661,
19,
297,
399,
7,
164,
95,
106,
10450,
101,
659,
272,
661,
20,
297,
399,
7,
19182,
108,
10450,
101,
659,
272,
661,
23,
297,
399,
7,
9372,
24181,
232,
19182,
108,
15013,
101,
659,
272,
661,
24,
297,
399,
7,
6923,
235,
24181,
232,
19182,
108,
15013,
101,
659,
272,
661,
25,
297,
399,
7,
29548,
229,
30521,
15013,
101,
659,
272,
661,
45,
297,
399,
7,
9372,
24181,
232,
15013,
101,
659,
272,
661,
47,
297,
399,
7,
6923,
235,
24181,
232,
15013,
101,
659,
272,
661,
34,
297,
399,
7,
163,
116,
116,
17637,
164,
95,
106,
15013,
101,
659,
272,
661,
48,
297,
399,
7,
19431,
118,
24181,
232,
15013,
101,
358,
199,
61,
421,
199,
3,
7094,
228,
102,
27289,
223,
15977,
122,
12211,
199,
318,
870,
872,
7919,
837,
272,
870,
3654,
7,
627,
5049,
9,
421,
199,
318,
664,
1366,
837,
272,
372,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
56,
297,
900,
14,
15198,
1012,
221,
327,
6927,
13,
614,
13,
614,
3144,
26,
383,
26,
383,
421,
199,
318,
1434,
18,
11288,
8,
68,
304,
272,
327,
7905,
283,
7280,
13,
614,
13,
614,
7,
370,
283,
55,
379,
17474,
17163,
8733,
26,
383,
26,
383,
12174,
11,
25822,
6927,
7,
272,
307,
275,
900,
14,
9866,
8,
68,
12,
1543,
57,
3295,
77,
3295,
68,
358,
272,
16635,
275,
900,
14,
18331,
8,
84,
9,
221,
327,
283,
55,
379,
17474,
17163,
8733,
26,
383,
26,
383,
6927,
7,
272,
327,
283,
55,
379,
17474,
17163,
8733,
26,
383,
26,
383,
12174,
11,
25822,
6927,
7,
272,
372,
334,
10125,
59,
16,
6809,
20,
61,
435,
283,
11288,
11,
25822,
283,
435,
16635,
1988,
20,
5728,
421,
199,
318,
664,
13832,
804,
8,
498,
304,
272,
366,
275,
469,
267,
283,
17,
356,
399,
7,
6923,
235,
10192,
165,
119,
105,
5498,
122,
20886,
297,
267,
283,
18,
356,
399,
7,
9372,
10192,
165,
119,
105,
5498,
122,
20886,
297,
267,
283,
35,
356,
399,
7,
163,
117,
108,
163,
123,
112,
14333,
249,
12609,
20886,
297,
267,
283,
39,
356,
399,
7,
6075,
109,
163,
118,
123,
14333,
249,
12609,
20886,
297,
267,
283,
34,
356,
399,
7,
11825,
98,
164,
228,
101,
7,
272,
789,
272,
372,
366,
59,
498,
61,
340,
790,
315,
366,
587,
399,
7,
6587,
104,
164,
18304,
20886,
15054,
10278,
7,
421,
199,
318,
664,
25813,
804,
8,
498,
304,
272,
366,
275,
469,
267,
283,
17,
356,
399,
7,
16888,
25196,
164,
99,
102,
297,
267,
283,
18,
356,
399,
7,
162,
227,
124,
21341,
99,
164,
99,
102,
297,
267,
283,
19,
356,
399,
7,
14651,
100,
29319,
164,
99,
102,
297,
267,
283,
20,
356,
399,
7,
163,
107,
234,
17950,
250,
164,
99,
102,
7,
272,
789,
272,
372,
366,
59,
498,
61,
340,
790,
315,
366,
587,
399,
7,
6587,
104,
164,
18304,
164,
99,
102,
19012,
236,
7,
421,
199,
318,
664,
1513,
292,
804,
8,
498,
304,
272,
366,
275,
1211,
8,
261,
292,
24995,
9,
272,
372,
366,
59,
498,
61,
340,
790,
315,
366,
587,
399,
7,
6587,
104,
164,
18304,
15280,
256,
9051,
105,
7,
421,
199,
318,
3504,
1513,
292,
804,
837,
272,
790,
275,
283,
17,
7,
221,
327,
10469,
120,
247,
14082,
98,
164,
95,
106,
15013,
101,
272,
1830,
715,
26,
267,
870,
8,
85,
7,
25977,
14333,
232,
163,
234,
103,
15280,
256,
9051,
105,
17637,
8967,
8,
10450,
112,
18189,
100,
27252,
118,
25238,
106,
12033,
165,
234,
110,
20918,
26032,
28285,
236,
304,
358,
267,
367,
10346,
315,
542,
292,
24995,
26,
288,
870,
8,
85,
5956,
83,
26,
450,
83,
7,
450,
334,
1774,
59,
16,
467,
10346,
59,
17,
2459,
267,
790,
275,
3066,
63,
1210,
1252,
4142,
342,
267,
366,
275,
1211,
8,
261,
292,
24995,
9,
267,
340,
790,
315,
366,
26,
288,
372,
790,
267,
587,
26,
288,
870,
8,
85,
7,
11373,
255,
9221,
231,
8106,
15280,
256,
9051,
105,
10278,
10916,
421,
199,
318,
1104,
2506,
8,
602,
304,
272,
333,
275,
295,
14,
1431,
8,
82,
15542,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
19204,
1434,
9,
221,
327,
6927,
13,
614,
13,
614,
272,
340,
333,
26,
267,
11168,
275,
2197,
14,
2083,
14,
2131,
342,
267,
7104,
275,
1543,
57,
3295,
77,
3295,
68,
7,
267,
11168,
275,
2197,
14,
2083,
14,
9866,
8,
8136,
14,
6205,
8,
5045,
395,
7104,
9,
267,
3560,
63,
602,
275,
2197,
14,
2083,
14,
9866,
8,
77,
14,
923,
8,
16,
395,
7104,
9,
267,
5762,
275,
3560,
63,
602,
446,
11168,
267,
340,
5762,
14,
4899,
665,
378,
26,
288,
870,
8,
85,
7,
17837,
247,
19182,
100,
31502,
5,
83,
11373,
255,
9221,
231,
12,
221,
6075,
104,
28371,
21262,
227,
14082,
96,
5,
83,
23681,
30368,
8106,
19182,
100
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8853,
255,
230,
15977,
229,
15013,
242,
199,
646,
7534,
199,
646,
4011,
199,
646,
900,
199,
646,
2197,
199,
646,
984,
199,
646,
295,
199,
646,
14196,
199,
646,
2196,
199,
646,
30475,
199,
504,
3031,
14,
7626,
14,
505,
492,
603,
26567,
199,
199,
3,
9112,
106,
106,
4344,
232,
24302,
15013,
242,
199,
646,
4145,
199,
504,
394,
85,
3951,
692,
7420,
492,
5461,
5665,
12,
965,
6340,
199,
199,
3,
2494,
849,
2644,
370,
2774,
13,
24,
199,
9233,
8,
1274,
9,
199,
1274,
14,
409,
27205,
28139,
360,
1624,
13,
24,
358,
199,
6615,
14,
5154,
14,
4078,
19,
14,
5993,
63,
5451,
342,
199,
199,
3,
7094,
228,
102,
27289,
223,
6075,
247,
22485,
199,
7341,
63,
3593,
275,
378,
199,
7341,
63,
2666,
275,
446,
17,
199,
4283,
63,
1766,
2563,
275,
650,
199,
4283,
63,
25683,
275,
5212,
199,
270,
1298,
275,
942,
199,
261,
292,
24995,
275,
359,
272,
661,
17,
297,
399,
7,
164,
95,
106,
15013,
101,
659,
221,
327,
9112,
95,
106,
15013,
101,
15,
11373,
255,
15013,
101,
272,
661,
19,
297,
399,
7,
164,
95,
106,
10450,
101,
659,
272,
661,
20,
297,
399,
7,
19182,
108,
10450,
101,
659,
272,
661,
23,
297,
399,
7,
9372,
24181,
232,
19182,
108,
15013,
101,
659,
272,
661,
24,
297,
399,
7,
6923,
235,
24181,
232,
19182,
108,
15013,
101,
659,
272,
661,
25,
297,
399,
7,
29548,
229,
30521,
15013,
101,
659,
272,
661,
45,
297,
399,
7,
9372,
24181,
232,
15013,
101,
659,
272,
661,
47,
297,
399,
7,
6923,
235,
24181,
232,
15013,
101,
659,
272,
661,
34,
297,
399,
7,
163,
116,
116,
17637,
164,
95,
106,
15013,
101,
659,
272,
661,
48,
297,
399,
7,
19431,
118,
24181,
232,
15013,
101,
358,
199,
61,
421,
199,
3,
7094,
228,
102,
27289,
223,
15977,
122,
12211,
199,
318,
870,
872,
7919,
837,
272,
870,
3654,
7,
627,
5049,
9,
421,
199,
318,
664,
1366,
837,
272,
372,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
56,
297,
900,
14,
15198,
1012,
221,
327,
6927,
13,
614,
13,
614,
3144,
26,
383,
26,
383,
421,
199,
318,
1434,
18,
11288,
8,
68,
304,
272,
327,
7905,
283,
7280,
13,
614,
13,
614,
7,
370,
283,
55,
379,
17474,
17163,
8733,
26,
383,
26,
383,
12174,
11,
25822,
6927,
7,
272,
307,
275,
900,
14,
9866,
8,
68,
12,
1543,
57,
3295,
77,
3295,
68,
358,
272,
16635,
275,
900,
14,
18331,
8,
84,
9,
221,
327,
283,
55,
379,
17474,
17163,
8733,
26,
383,
26,
383,
6927,
7,
272,
327,
283,
55,
379,
17474,
17163,
8733,
26,
383,
26,
383,
12174,
11,
25822,
6927,
7,
272,
372,
334,
10125,
59,
16,
6809,
20,
61,
435,
283,
11288,
11,
25822,
283,
435,
16635,
1988,
20,
5728,
421,
199,
318,
664,
13832,
804,
8,
498,
304,
272,
366,
275,
469,
267,
283,
17,
356,
399,
7,
6923,
235,
10192,
165,
119,
105,
5498,
122,
20886,
297,
267,
283,
18,
356,
399,
7,
9372,
10192,
165,
119,
105,
5498,
122,
20886,
297,
267,
283,
35,
356,
399,
7,
163,
117,
108,
163,
123,
112,
14333,
249,
12609,
20886,
297,
267,
283,
39,
356,
399,
7,
6075,
109,
163,
118,
123,
14333,
249,
12609,
20886,
297,
267,
283,
34,
356,
399,
7,
11825,
98,
164,
228,
101,
7,
272,
789,
272,
372,
366,
59,
498,
61,
340,
790,
315,
366,
587,
399,
7,
6587,
104,
164,
18304,
20886,
15054,
10278,
7,
421,
199,
318,
664,
25813,
804,
8,
498,
304,
272,
366,
275,
469,
267,
283,
17,
356,
399,
7,
16888,
25196,
164,
99,
102,
297,
267,
283,
18,
356,
399,
7,
162,
227,
124,
21341,
99,
164,
99,
102,
297,
267,
283,
19,
356,
399,
7,
14651,
100,
29319,
164,
99,
102,
297,
267,
283,
20,
356,
399,
7,
163,
107,
234,
17950,
250,
164,
99,
102,
7,
272,
789,
272,
372,
366,
59,
498,
61,
340,
790,
315,
366,
587,
399,
7,
6587,
104,
164,
18304,
164,
99,
102,
19012,
236,
7,
421,
199,
318,
664,
1513,
292,
804,
8,
498,
304,
272,
366,
275,
1211,
8,
261,
292,
24995,
9,
272,
372,
366,
59,
498,
61,
340,
790,
315,
366,
587,
399,
7,
6587,
104,
164,
18304,
15280,
256,
9051,
105,
7,
421,
199,
318,
3504,
1513,
292,
804,
837,
272,
790,
275,
283,
17,
7,
221,
327,
10469,
120,
247,
14082,
98,
164,
95,
106,
15013,
101,
272,
1830,
715,
26,
267,
870,
8,
85,
7,
25977,
14333,
232,
163,
234,
103,
15280,
256,
9051,
105,
17637,
8967,
8,
10450,
112,
18189,
100,
27252,
118,
25238,
106,
12033,
165,
234,
110,
20918,
26032,
28285,
236,
304,
358,
267,
367,
10346,
315,
542,
292,
24995,
26,
288,
870,
8,
85,
5956,
83,
26,
450,
83,
7,
450,
334,
1774,
59,
16,
467,
10346,
59,
17,
2459,
267,
790,
275,
3066,
63,
1210,
1252,
4142,
342,
267,
366,
275,
1211,
8,
261,
292,
24995,
9,
267,
340,
790,
315,
366,
26,
288,
372,
790,
267,
587,
26,
288,
870,
8,
85,
7,
11373,
255,
9221,
231,
8106,
15280,
256,
9051,
105,
10278,
10916,
421,
199,
318,
1104,
2506,
8,
602,
304,
272,
333,
275,
295,
14,
1431,
8,
82,
15542,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
19204,
1434,
9,
221,
327,
6927,
13,
614,
13,
614,
272,
340,
333,
26,
267,
11168,
275,
2197,
14,
2083,
14,
2131,
342,
267,
7104,
275,
1543,
57,
3295,
77,
3295,
68,
7,
267,
11168,
275,
2197,
14,
2083,
14,
9866,
8,
8136,
14,
6205,
8,
5045,
395,
7104,
9,
267,
3560,
63,
602,
275,
2197,
14,
2083,
14,
9866,
8,
77,
14,
923,
8,
16,
395,
7104,
9,
267,
5762,
275,
3560,
63,
602,
446,
11168,
267,
340,
5762,
14,
4899,
665,
378,
26,
288,
870,
8,
85,
7,
17837,
247,
19182,
100,
31502,
5,
83,
11373,
255,
9221,
231,
12,
221,
6075,
104,
28371,
21262,
227,
14082,
96,
5,
83,
23681,
30368,
8106,
19182,
100,
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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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
] |
csdl/makahiki
|
makahiki/apps/widgets/participation/migrations/0001_initial.py
|
2
|
4348
|
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'ParticipationSetting'
db.create_table(u'participation_participationsetting', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('name', self.gf('django.db.models.fields.CharField')(default='Participation Settings', max_length='30')),
('points_50_percent', self.gf('django.db.models.fields.IntegerField')(default=5)),
('points_75_percent', self.gf('django.db.models.fields.IntegerField')(default=5)),
('points_100_percent', self.gf('django.db.models.fields.IntegerField')(default=10)),
))
db.send_create_signal(u'participation', ['ParticipationSetting'])
# Adding model 'TeamParticipation'
db.create_table(u'participation_teamparticipation', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('round_name', self.gf('django.db.models.fields.CharField')(max_length=50, null=True, blank=True)),
('team', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['team_mgr.Team'])),
('participation', self.gf('django.db.models.fields.IntegerField')(default=0)),
('awarded_percent', self.gf('django.db.models.fields.CharField')(max_length=10, null=True, blank=True)),
('updated_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal(u'participation', ['TeamParticipation'])
def backwards(self, orm):
# Deleting model 'ParticipationSetting'
db.delete_table(u'participation_participationsetting')
# Deleting model 'TeamParticipation'
db.delete_table(u'participation_teamparticipation')
models = {
u'participation.participationsetting': {
'Meta': {'object_name': 'ParticipationSetting'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'default': "'Participation Settings'", 'max_length': "'30'"}),
'points_100_percent': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
'points_50_percent': ('django.db.models.fields.IntegerField', [], {'default': '5'}),
'points_75_percent': ('django.db.models.fields.IntegerField', [], {'default': '5'})
},
u'participation.teamparticipation': {
'Meta': {'ordering': "['-participation']", 'object_name': 'TeamParticipation'},
'awarded_percent': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'participation': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'round_name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
'team': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['team_mgr.Team']"}),
'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
},
u'team_mgr.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200'})
},
u'team_mgr.team': {
'Meta': {'ordering': "('group', 'name')", 'object_name': 'Team'},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['team_mgr.Group']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'logo': ('django.db.models.fields.files.ImageField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
'size': ('django.db.models.fields.IntegerField', [], {'default': '0', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['participation']
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
1208,
492,
2197,
63,
1208,
465,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
1262,
31089,
387,
296,
7776,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
23512,
559,
387,
296,
6031,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
354,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
1262,
31089,
387,
296,
13303,
297,
1390,
63,
1267,
534,
1216,
3855,
288,
661,
3438,
63,
1400,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
21,
1826,
288,
661,
3438,
63,
2194,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
21,
1826,
288,
661,
3438,
63,
1960,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
709,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
7,
23512,
559,
387,
296,
297,
788,
1262,
31089,
387,
296,
7776,
1105,
398,
327,
12934,
1402,
283,
13126,
1262,
31089,
387,
296,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
266,
5282,
285,
31089,
387,
296,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
2363,
63,
354,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1400,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
5969,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
5969,
63,
7755,
14,
13126,
16607,
288,
661,
23512,
559,
387,
296,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
16,
1826,
288,
661,
65,
15295,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
709,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
5334,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
29,
549,
12,
4596,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
7,
23512,
559,
387,
296,
297,
788,
13126,
1262,
31089,
387,
296,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
1262,
31089,
387,
296,
7776,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
23512,
559,
387,
296,
6031,
358,
398,
327,
15920,
1402,
283,
13126,
1262,
31089,
387,
296,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
266,
5282,
285,
31089,
387,
296,
358,
2378,
1709,
275,
469,
267,
399,
7,
23512,
559,
387,
296,
14,
23512,
559,
387,
296,
6031,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1262,
31089,
387,
296,
7776,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
3546,
1262,
31089,
387,
296,
13303,
4662,
283,
988,
63,
1267,
356,
3546,
1216,
7,
5593,
288,
283,
3438,
63,
1960,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
709,
1604,
288,
283,
3438,
63,
1400,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
21,
1604,
288,
283,
3438,
63,
2194,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
21,
3071,
267,
1660,
267,
399,
7,
23512,
559,
387,
296,
14,
266,
5282,
285,
31089,
387,
296,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
25280,
13,
23512,
559,
387,
296,
6256,
283,
785,
63,
354,
356,
283,
13126,
1262,
31089,
387,
296,
2267,
288,
283,
65,
15295,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
709,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
23512,
559,
387,
296,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
2363,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
5969,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
5969,
63,
7755,
14,
13126,
6097,
288,
283,
5334,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
1133,
69,
455,
63,
7755,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
1208,
492,
2197,
63,
1208,
465,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
1402,
283,
1262,
31089,
387,
296,
7776,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
23512,
559,
387,
296,
6031,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
354,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
1262,
31089,
387,
296,
13303,
297,
1390,
63,
1267,
534,
1216,
3855,
288,
661,
3438,
63,
1400,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
21,
1826,
288,
661,
3438,
63,
2194,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
21,
1826,
288,
661,
3438,
63,
1960,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
709,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
7,
23512,
559,
387,
296,
297,
788,
1262,
31089,
387,
296,
7776,
1105,
398,
327,
12934,
1402,
283,
13126,
1262,
31089,
387,
296,
7,
267,
1592,
14,
981,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
266,
5282,
285,
31089,
387,
296,
297,
334,
288,
334,
85,
7,
344,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
7533,
3327,
63,
498,
29,
549,
1826,
288,
661,
2363,
63,
354,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
1400,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
5969,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
7533,
475,
29,
1025,
459,
5969,
63,
7755,
14,
13126,
16607,
288,
661,
23512,
559,
387,
296,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
7533,
885,
29,
16,
1826,
288,
661,
65,
15295,
63,
7045,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
988,
63,
1267,
29,
709,
12,
2973,
29,
549,
12,
4596,
29,
549,
1826,
288,
661,
5334,
63,
292,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2495,
63,
2131,
29,
549,
12,
4596,
29,
549,
1826,
267,
5082,
267,
1592,
14,
2254,
63,
981,
63,
4653,
8,
85,
7,
23512,
559,
387,
296,
297,
788,
13126,
1262,
31089,
387,
296,
1105,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
1402,
283,
1262,
31089,
387,
296,
7776,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
23512,
559,
387,
296,
6031,
358,
398,
327,
15920,
1402,
283,
13126,
1262,
31089,
387,
296,
7,
267,
1592,
14,
1807,
63,
1224,
8,
85,
7,
23512,
559,
387,
296,
63,
266,
5282,
285,
31089,
387,
296,
358,
2378,
1709,
275,
469,
267,
399,
7,
23512,
559,
387,
296,
14,
23512,
559,
387,
296,
6031,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1262,
31089,
387,
296,
7776,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
3546,
1262,
31089,
387,
296,
13303,
4662,
283,
988,
63,
1267,
356,
3546,
1216,
7,
5593,
288,
283,
3438,
63,
1960,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
709,
1604,
288,
283,
3438,
63,
1400,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
21,
1604,
288,
283,
3438,
63,
2194,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
21,
3071,
267,
1660,
267,
399,
7,
23512,
559,
387,
296,
14,
266,
5282,
285,
31089,
387,
296,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
25280,
13,
23512,
559,
387,
296,
6256,
283,
785,
63,
354,
356,
283,
13126,
1262,
31089,
387,
296,
2267,
288,
283,
65,
15295,
63,
7045,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
709,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
23512,
559,
387,
296,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
2363,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
297,
283,
2307,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
5969,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
399,
2,
1025,
459,
5969,
63,
7755,
14,
13126,
6097,
288,
283,
5334,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
399,
1133,
69,
455,
63,
7755,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
TheWardoctor/Wardoctors-repo
|
script.module.master.common/lib/js2py/utils/injector.py
|
34
|
5447
|
__all__ = ['fix_js_args']
import types
import opcode
# Opcode constants used for comparison and replacecment
LOAD_FAST = opcode.opmap['LOAD_FAST']
LOAD_GLOBAL = opcode.opmap['LOAD_GLOBAL']
STORE_FAST = opcode.opmap['STORE_FAST']
def fix_js_args(func):
'''Use this function when unsure whether func takes this and arguments as its last 2 args.
It will append 2 args if it does not.'''
fcode = func.func_code
fargs = fcode.co_varnames[fcode.co_argcount-2:fcode.co_argcount]
if fargs==('this', 'arguments') or fargs==('arguments', 'var'):
return func
code = append_arguments(func.func_code, ('this','arguments'))
return types.FunctionType(code, func.func_globals, func.func_name, closure=func.func_closure)
def append_arguments(code_obj, new_locals):
co_varnames = code_obj.co_varnames # Old locals
co_names = code_obj.co_names # Old globals
co_names+=tuple(e for e in new_locals if e not in co_names)
co_argcount = code_obj.co_argcount # Argument count
co_code = code_obj.co_code # The actual bytecode as a string
# Make one pass over the bytecode to identify names that should be
# left in code_obj.co_names.
not_removed = set(opcode.hasname) - set([LOAD_GLOBAL])
saved_names = set()
for inst in instructions(co_code):
if inst[0] in not_removed:
saved_names.add(co_names[inst[1]])
# Build co_names for the new code object. This should consist of
# globals that were only accessed via LOAD_GLOBAL
names = tuple(name for name in co_names
if name not in set(new_locals) - saved_names)
# Build a dictionary that maps the indices of the entries in co_names
# to their entry in the new co_names
name_translations = dict((co_names.index(name), i)
for i, name in enumerate(names))
# Build co_varnames for the new code object. This should consist of
# the entirety of co_varnames with new_locals spliced in after the
# arguments
new_locals_len = len(new_locals)
varnames = (co_varnames[:co_argcount] + new_locals +
co_varnames[co_argcount:])
# Build the dictionary that maps indices of entries in the old co_varnames
# to their indices in the new co_varnames
range1, range2 = xrange(co_argcount), xrange(co_argcount, len(co_varnames))
varname_translations = dict((i, i) for i in range1)
varname_translations.update((i, i + new_locals_len) for i in range2)
# Build the dictionary that maps indices of deleted entries of co_names
# to their indices in the new co_varnames
names_to_varnames = dict((co_names.index(name), varnames.index(name))
for name in new_locals)
# Now we modify the actual bytecode
modified = []
for inst in instructions(code_obj.co_code):
# If the instruction is a LOAD_GLOBAL, we have to check to see if
# it's one of the globals that we are replacing. Either way,
# update its arg using the appropriate dict.
if inst[0] == LOAD_GLOBAL:
if inst[1] in names_to_varnames:
inst[0] = LOAD_FAST
inst[1] = names_to_varnames[inst[1]]
elif inst[1] in name_translations:
inst[1] = name_translations[inst[1]]
else:
raise ValueError("a name was lost in translation")
# If it accesses co_varnames or co_names then update its argument.
elif inst[0] in opcode.haslocal:
inst[1] = varname_translations[inst[1]]
elif inst[0] in opcode.hasname:
inst[1] = name_translations[inst[1]]
modified.extend(write_instruction(inst))
code = ''.join(modified)
# Done modifying codestring - make the code object
return types.CodeType(co_argcount + new_locals_len,
code_obj.co_nlocals + new_locals_len,
code_obj.co_stacksize,
code_obj.co_flags,
code,
code_obj.co_consts,
names,
varnames,
code_obj.co_filename,
code_obj.co_name,
code_obj.co_firstlineno,
code_obj.co_lnotab,
code_obj.co_freevars,
code_obj.co_cellvars)
def instructions(code):
code = map(ord, code)
i, L = 0, len(code)
extended_arg = 0
while i < L:
op = code[i]
i+= 1
if op < opcode.HAVE_ARGUMENT:
yield [op, None]
continue
oparg = code[i] + (code[i+1] << 8) + extended_arg
extended_arg = 0
i += 2
if op == opcode.EXTENDED_ARG:
extended_arg = oparg << 16
continue
yield [op, oparg]
def write_instruction(inst):
op, oparg = inst
if oparg is None:
return [chr(op)]
elif oparg <= 65536L:
return [chr(op), chr(oparg & 255), chr((oparg >> 8) & 255)]
elif oparg <= 4294967296L:
return [chr(opcode.EXTENDED_ARG),
chr((oparg >> 16) & 255),
chr((oparg >> 24) & 255),
chr(op),
chr(oparg & 255),
chr((oparg >> 8) & 255)]
else:
raise ValueError("Invalid oparg: {0} is too large".format(oparg))
|
apache-2.0
|
[
363,
452,
363,
275,
788,
970,
63,
3596,
63,
589,
418,
199,
199,
646,
2943,
199,
646,
10508,
199,
199,
3,
24301,
5262,
1202,
367,
9132,
436,
3350,
67,
434,
199,
7405,
63,
24661,
275,
10508,
14,
411,
1130,
459,
7405,
63,
24661,
418,
199,
7405,
63,
13808,
275,
10508,
14,
411,
1130,
459,
7405,
63,
13808,
418,
199,
16169,
63,
24661,
275,
10508,
14,
411,
1130,
459,
16169,
63,
24661,
418,
199,
199,
318,
5325,
63,
3596,
63,
589,
8,
1532,
304,
272,
1449,
6119,
642,
805,
1380,
625,
3253,
3775,
2562,
6181,
642,
436,
2368,
465,
2399,
2061,
499,
1249,
14,
2126,
2779,
911,
5666,
499,
1249,
340,
652,
1630,
440,
10595,
272,
289,
600,
275,
2562,
14,
1532,
63,
600,
272,
289,
589,
275,
289,
600,
14,
331,
63,
1391,
1247,
59,
70,
600,
14,
331,
63,
30513,
13,
18,
26,
70,
600,
14,
331,
63,
30513,
61,
272,
340,
289,
589,
389,
360,
3749,
297,
283,
4958,
358,
503,
289,
589,
389,
360,
4958,
297,
283,
1391,
735,
267,
372,
2562,
272,
1233,
275,
5666,
63,
4958,
8,
1532,
14,
1532,
63,
600,
12,
661,
3749,
1673,
4958,
1333,
272,
372,
2943,
14,
26371,
8,
600,
12,
2562,
14,
1532,
63,
8473,
12,
2562,
14,
1532,
63,
354,
12,
17903,
29,
1532,
14,
1532,
63,
13008,
9,
10813,
199,
318,
5666,
63,
4958,
8,
600,
63,
1113,
12,
892,
63,
9350,
304,
272,
512,
63,
1391,
1247,
275,
1233,
63,
1113,
14,
331,
63,
1391,
1247,
257,
327,
21238,
9480,
272,
512,
63,
1247,
275,
1233,
63,
1113,
14,
331,
63,
1247,
257,
327,
21238,
7992,
272,
512,
63,
1247,
10365,
2960,
8,
69,
367,
325,
315,
892,
63,
9350,
340,
325,
440,
315,
512,
63,
1247,
9,
272,
512,
63,
30513,
275,
1233,
63,
1113,
14,
331,
63,
30513,
258,
327,
5886,
2338,
272,
512,
63,
600,
275,
1233,
63,
1113,
14,
331,
63,
600,
260,
327,
710,
3503,
16855,
465,
282,
1059,
339,
327,
4155,
1373,
986,
1806,
314,
16855,
370,
10405,
1561,
626,
1077,
506,
272,
327,
3602,
315,
1233,
63,
1113,
14,
331,
63,
1247,
14,
272,
440,
63,
10649,
275,
663,
8,
14325,
14,
1989,
354,
9,
446,
663,
779,
7405,
63,
13808,
566,
272,
6290,
63,
1247,
275,
663,
342,
272,
367,
2727,
315,
15794,
8,
331,
63,
600,
304,
267,
340,
2727,
59,
16,
61,
315,
440,
63,
10649,
26,
288,
6290,
63,
1247,
14,
525,
8,
331,
63,
1247,
59,
3615,
59,
17,
3934,
339,
327,
6516,
512,
63,
1247,
367,
314,
892,
1233,
909,
14,
961,
1077,
17568,
402,
272,
327,
7992,
626,
4898,
1454,
13810,
4799,
3412,
1554,
63,
13808,
272,
1561,
275,
2008,
8,
354,
367,
536,
315,
512,
63,
1247,
2116,
340,
536,
440,
315,
663,
8,
1222,
63,
9350,
9,
446,
6290,
63,
1247,
9,
339,
327,
6516,
282,
2600,
626,
9033,
314,
4918,
402,
314,
4811,
315,
512,
63,
1247,
272,
327,
370,
3932,
2397,
315,
314,
892,
512,
63,
1247,
272,
536,
63,
13982,
275,
1211,
1332,
331,
63,
1247,
14,
1080,
8,
354,
395,
284,
9,
2490,
367,
284,
12,
536,
315,
3874,
8,
1247,
430,
339,
327,
6516,
512,
63,
1391,
1247,
367,
314,
892,
1233,
909,
14,
961,
1077,
17568,
402,
272,
327,
314,
8039,
369,
402,
512,
63,
1391,
1247,
543,
892,
63,
9350,
2249,
3037,
68,
315,
2410,
314,
272,
327,
2368,
272,
892,
63,
9350,
63,
552,
275,
822,
8,
1222,
63,
9350,
9,
272,
2729,
1247,
275,
334,
331,
63,
1391,
1247,
1491,
331,
63,
30513,
61,
435,
892,
63,
9350,
435,
355,
512,
63,
1391,
1247,
59,
331,
63,
30513,
5728,
339,
327,
6516,
314,
2600,
626,
9033,
4918,
402,
4811,
315,
314,
2269,
512,
63,
1391,
1247,
272,
327,
370,
3932,
4918,
315,
314,
892,
512,
63,
1391,
1247,
272,
1425,
17,
12,
1425,
18,
275,
4945,
8,
331,
63,
30513,
395,
4945,
8,
331,
63,
30513,
12,
822,
8,
331,
63,
1391,
1247,
430,
272,
22071,
63,
13982,
275,
1211,
1332,
73,
12,
284,
9,
367,
284,
315,
1425,
17,
9,
272,
22071,
63,
13982,
14,
873,
1332,
73,
12,
284,
435,
892,
63,
9350,
63,
552,
9,
367,
284,
315,
1425,
18,
9,
339,
327,
6516,
314,
2600,
626,
9033,
4918,
402,
5463,
4811,
402,
512,
63,
1247,
272,
327,
370,
3932,
4918,
315,
314,
892,
512,
63,
1391,
1247,
272,
1561,
63,
475,
63,
1391,
1247,
275,
1211,
1332,
331,
63,
1247,
14,
1080,
8,
354,
395,
2729,
1247,
14,
1080,
8,
354,
430,
2490,
367,
536,
315,
892,
63,
9350,
9,
339,
327,
7356,
781,
2811,
314,
3503,
16855,
272,
6042,
275,
942,
272,
367,
2727,
315,
15794,
8,
600,
63,
1113,
14,
331,
63,
600,
304,
267,
327,
982,
314,
16329,
365,
282,
3412,
1554,
63,
13808,
12,
781,
1172,
370,
1104,
370,
1937,
340,
267,
327,
652,
1159,
1373,
402,
314,
7992,
626,
781,
787,
15810,
14,
13083,
4340,
12,
267,
327,
1678,
2399,
1680,
1808,
314,
5827,
1211,
14,
267,
340,
2727,
59,
16,
61,
508,
3412,
1554,
63,
13808,
26,
288,
340,
2727,
59,
17,
61,
315,
1561,
63,
475,
63,
1391,
1247,
26,
355,
2727,
59,
16,
61,
275,
3412,
1554,
63,
24661,
355,
2727,
59,
17,
61,
275,
1561,
63,
475,
63,
1391,
1247,
59,
3615,
59,
17,
2677,
288,
916,
2727,
59,
17,
61,
315,
536,
63,
13982,
26,
258,
355,
2727,
59,
17,
61,
275,
536,
63,
13982,
59,
3615,
59,
17,
2677,
288,
587,
26,
355,
746,
1722,
480,
65,
536,
1990,
14669,
315,
7761,
531,
267,
327,
982,
652,
1066,
5804,
512,
63,
1391,
1247,
503,
512,
63,
1247,
2066,
1678,
2399,
1423,
14,
267,
916,
2727,
59,
16,
61,
315,
10508,
14,
1989,
1832,
26,
288,
2727,
59,
17,
61,
275,
22071,
63,
13982,
59,
3615,
59,
17,
2677,
267,
916,
2727,
59,
16,
61,
315,
10508,
14,
1989,
354,
26,
288,
2727,
59,
17,
61,
275,
536,
63,
13982,
59,
3615,
59,
17,
2677,
267,
6042,
14,
2880,
8,
952,
63,
22880,
8,
3615,
430,
339,
1233,
275,
6522,
904,
8,
5540,
9,
272,
327,
23541,
24662,
1233,
875,
446
] |
[
452,
363,
275,
788,
970,
63,
3596,
63,
589,
418,
199,
199,
646,
2943,
199,
646,
10508,
199,
199,
3,
24301,
5262,
1202,
367,
9132,
436,
3350,
67,
434,
199,
7405,
63,
24661,
275,
10508,
14,
411,
1130,
459,
7405,
63,
24661,
418,
199,
7405,
63,
13808,
275,
10508,
14,
411,
1130,
459,
7405,
63,
13808,
418,
199,
16169,
63,
24661,
275,
10508,
14,
411,
1130,
459,
16169,
63,
24661,
418,
199,
199,
318,
5325,
63,
3596,
63,
589,
8,
1532,
304,
272,
1449,
6119,
642,
805,
1380,
625,
3253,
3775,
2562,
6181,
642,
436,
2368,
465,
2399,
2061,
499,
1249,
14,
2126,
2779,
911,
5666,
499,
1249,
340,
652,
1630,
440,
10595,
272,
289,
600,
275,
2562,
14,
1532,
63,
600,
272,
289,
589,
275,
289,
600,
14,
331,
63,
1391,
1247,
59,
70,
600,
14,
331,
63,
30513,
13,
18,
26,
70,
600,
14,
331,
63,
30513,
61,
272,
340,
289,
589,
389,
360,
3749,
297,
283,
4958,
358,
503,
289,
589,
389,
360,
4958,
297,
283,
1391,
735,
267,
372,
2562,
272,
1233,
275,
5666,
63,
4958,
8,
1532,
14,
1532,
63,
600,
12,
661,
3749,
1673,
4958,
1333,
272,
372,
2943,
14,
26371,
8,
600,
12,
2562,
14,
1532,
63,
8473,
12,
2562,
14,
1532,
63,
354,
12,
17903,
29,
1532,
14,
1532,
63,
13008,
9,
10813,
199,
318,
5666,
63,
4958,
8,
600,
63,
1113,
12,
892,
63,
9350,
304,
272,
512,
63,
1391,
1247,
275,
1233,
63,
1113,
14,
331,
63,
1391,
1247,
257,
327,
21238,
9480,
272,
512,
63,
1247,
275,
1233,
63,
1113,
14,
331,
63,
1247,
257,
327,
21238,
7992,
272,
512,
63,
1247,
10365,
2960,
8,
69,
367,
325,
315,
892,
63,
9350,
340,
325,
440,
315,
512,
63,
1247,
9,
272,
512,
63,
30513,
275,
1233,
63,
1113,
14,
331,
63,
30513,
258,
327,
5886,
2338,
272,
512,
63,
600,
275,
1233,
63,
1113,
14,
331,
63,
600,
260,
327,
710,
3503,
16855,
465,
282,
1059,
339,
327,
4155,
1373,
986,
1806,
314,
16855,
370,
10405,
1561,
626,
1077,
506,
272,
327,
3602,
315,
1233,
63,
1113,
14,
331,
63,
1247,
14,
272,
440,
63,
10649,
275,
663,
8,
14325,
14,
1989,
354,
9,
446,
663,
779,
7405,
63,
13808,
566,
272,
6290,
63,
1247,
275,
663,
342,
272,
367,
2727,
315,
15794,
8,
331,
63,
600,
304,
267,
340,
2727,
59,
16,
61,
315,
440,
63,
10649,
26,
288,
6290,
63,
1247,
14,
525,
8,
331,
63,
1247,
59,
3615,
59,
17,
3934,
339,
327,
6516,
512,
63,
1247,
367,
314,
892,
1233,
909,
14,
961,
1077,
17568,
402,
272,
327,
7992,
626,
4898,
1454,
13810,
4799,
3412,
1554,
63,
13808,
272,
1561,
275,
2008,
8,
354,
367,
536,
315,
512,
63,
1247,
2116,
340,
536,
440,
315,
663,
8,
1222,
63,
9350,
9,
446,
6290,
63,
1247,
9,
339,
327,
6516,
282,
2600,
626,
9033,
314,
4918,
402,
314,
4811,
315,
512,
63,
1247,
272,
327,
370,
3932,
2397,
315,
314,
892,
512,
63,
1247,
272,
536,
63,
13982,
275,
1211,
1332,
331,
63,
1247,
14,
1080,
8,
354,
395,
284,
9,
2490,
367,
284,
12,
536,
315,
3874,
8,
1247,
430,
339,
327,
6516,
512,
63,
1391,
1247,
367,
314,
892,
1233,
909,
14,
961,
1077,
17568,
402,
272,
327,
314,
8039,
369,
402,
512,
63,
1391,
1247,
543,
892,
63,
9350,
2249,
3037,
68,
315,
2410,
314,
272,
327,
2368,
272,
892,
63,
9350,
63,
552,
275,
822,
8,
1222,
63,
9350,
9,
272,
2729,
1247,
275,
334,
331,
63,
1391,
1247,
1491,
331,
63,
30513,
61,
435,
892,
63,
9350,
435,
355,
512,
63,
1391,
1247,
59,
331,
63,
30513,
5728,
339,
327,
6516,
314,
2600,
626,
9033,
4918,
402,
4811,
315,
314,
2269,
512,
63,
1391,
1247,
272,
327,
370,
3932,
4918,
315,
314,
892,
512,
63,
1391,
1247,
272,
1425,
17,
12,
1425,
18,
275,
4945,
8,
331,
63,
30513,
395,
4945,
8,
331,
63,
30513,
12,
822,
8,
331,
63,
1391,
1247,
430,
272,
22071,
63,
13982,
275,
1211,
1332,
73,
12,
284,
9,
367,
284,
315,
1425,
17,
9,
272,
22071,
63,
13982,
14,
873,
1332,
73,
12,
284,
435,
892,
63,
9350,
63,
552,
9,
367,
284,
315,
1425,
18,
9,
339,
327,
6516,
314,
2600,
626,
9033,
4918,
402,
5463,
4811,
402,
512,
63,
1247,
272,
327,
370,
3932,
4918,
315,
314,
892,
512,
63,
1391,
1247,
272,
1561,
63,
475,
63,
1391,
1247,
275,
1211,
1332,
331,
63,
1247,
14,
1080,
8,
354,
395,
2729,
1247,
14,
1080,
8,
354,
430,
2490,
367,
536,
315,
892,
63,
9350,
9,
339,
327,
7356,
781,
2811,
314,
3503,
16855,
272,
6042,
275,
942,
272,
367,
2727,
315,
15794,
8,
600,
63,
1113,
14,
331,
63,
600,
304,
267,
327,
982,
314,
16329,
365,
282,
3412,
1554,
63,
13808,
12,
781,
1172,
370,
1104,
370,
1937,
340,
267,
327,
652,
1159,
1373,
402,
314,
7992,
626,
781,
787,
15810,
14,
13083,
4340,
12,
267,
327,
1678,
2399,
1680,
1808,
314,
5827,
1211,
14,
267,
340,
2727,
59,
16,
61,
508,
3412,
1554,
63,
13808,
26,
288,
340,
2727,
59,
17,
61,
315,
1561,
63,
475,
63,
1391,
1247,
26,
355,
2727,
59,
16,
61,
275,
3412,
1554,
63,
24661,
355,
2727,
59,
17,
61,
275,
1561,
63,
475,
63,
1391,
1247,
59,
3615,
59,
17,
2677,
288,
916,
2727,
59,
17,
61,
315,
536,
63,
13982,
26,
258,
355,
2727,
59,
17,
61,
275,
536,
63,
13982,
59,
3615,
59,
17,
2677,
288,
587,
26,
355,
746,
1722,
480,
65,
536,
1990,
14669,
315,
7761,
531,
267,
327,
982,
652,
1066,
5804,
512,
63,
1391,
1247,
503,
512,
63,
1247,
2066,
1678,
2399,
1423,
14,
267,
916,
2727,
59,
16,
61,
315,
10508,
14,
1989,
1832,
26,
288,
2727,
59,
17,
61,
275,
22071,
63,
13982,
59,
3615,
59,
17,
2677,
267,
916,
2727,
59,
16,
61,
315,
10508,
14,
1989,
354,
26,
288,
2727,
59,
17,
61,
275,
536,
63,
13982,
59,
3615,
59,
17,
2677,
267,
6042,
14,
2880,
8,
952,
63,
22880,
8,
3615,
430,
339,
1233,
275,
6522,
904,
8,
5540,
9,
272,
327,
23541,
24662,
1233,
875,
446,
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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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
] |
gavioto/rethinkdb
|
test/rql_test/connections/http_support/werkzeug/contrib/securecookie.py
|
294
|
12204
|
# -*- coding: utf-8 -*-
r"""
werkzeug.contrib.securecookie
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This module implements a cookie that is not alterable from the client
because it adds a checksum the server checks for. You can use it as
session replacement if all you have is a user id or something to mark
a logged in user.
Keep in mind that the data is still readable from the client as a
normal cookie is. However you don't have to store and flush the
sessions you have at the server.
Example usage:
>>> from werkzeug.contrib.securecookie import SecureCookie
>>> x = SecureCookie({"foo": 42, "baz": (1, 2, 3)}, "deadbeef")
Dumping into a string so that one can store it in a cookie:
>>> value = x.serialize()
Loading from that string again:
>>> x = SecureCookie.unserialize(value, "deadbeef")
>>> x["baz"]
(1, 2, 3)
If someone modifies the cookie and the checksum is wrong the unserialize
method will fail silently and return a new empty `SecureCookie` object.
Keep in mind that the values will be visible in the cookie so do not
store data in a cookie you don't want the user to see.
Application Integration
=======================
If you are using the werkzeug request objects you could integrate the
secure cookie into your application like this::
from werkzeug.utils import cached_property
from werkzeug.wrappers import BaseRequest
from werkzeug.contrib.securecookie import SecureCookie
# don't use this key but a different one; you could just use
# os.urandom(20) to get something random
SECRET_KEY = '\xfa\xdd\xb8z\xae\xe0}4\x8b\xea'
class Request(BaseRequest):
@cached_property
def client_session(self):
data = self.cookies.get('session_data')
if not data:
return SecureCookie(secret_key=SECRET_KEY)
return SecureCookie.unserialize(data, SECRET_KEY)
def application(environ, start_response):
request = Request(environ, start_response)
# get a response object here
response = ...
if request.client_session.should_save:
session_data = request.client_session.serialize()
response.set_cookie('session_data', session_data,
httponly=True)
return response(environ, start_response)
A less verbose integration can be achieved by using shorthand methods::
class Request(BaseRequest):
@cached_property
def client_session(self):
return SecureCookie.load_cookie(self, secret_key=COOKIE_SECRET)
def application(environ, start_response):
request = Request(environ, start_response)
# get a response object here
response = ...
request.client_session.save_cookie(response)
return response(environ, start_response)
:copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import pickle
import base64
from hmac import new as hmac
from time import time
from hashlib import sha1 as _default_hash
from werkzeug._compat import iteritems, text_type
from werkzeug.urls import url_quote_plus, url_unquote_plus
from werkzeug._internal import _date_to_unix
from werkzeug.contrib.sessions import ModificationTrackingDict
from werkzeug.security import safe_str_cmp
from werkzeug._compat import to_native
class UnquoteError(Exception):
"""Internal exception used to signal failures on quoting."""
class SecureCookie(ModificationTrackingDict):
"""Represents a secure cookie. You can subclass this class and provide
an alternative mac method. The import thing is that the mac method
is a function with a similar interface to the hashlib. Required
methods are update() and digest().
Example usage:
>>> x = SecureCookie({"foo": 42, "baz": (1, 2, 3)}, "deadbeef")
>>> x["foo"]
42
>>> x["baz"]
(1, 2, 3)
>>> x["blafasel"] = 23
>>> x.should_save
True
:param data: the initial data. Either a dict, list of tuples or `None`.
:param secret_key: the secret key. If not set `None` or not specified
it has to be set before :meth:`serialize` is called.
:param new: The initial value of the `new` flag.
"""
#: The hash method to use. This has to be a module with a new function
#: or a function that creates a hashlib object. Such as `hashlib.md5`
#: Subclasses can override this attribute. The default hash is sha1.
#: Make sure to wrap this in staticmethod() if you store an arbitrary
#: function there such as hashlib.sha1 which might be implemented
#: as a function.
hash_method = staticmethod(_default_hash)
#: the module used for serialization. Unless overriden by subclasses
#: the standard pickle module is used.
serialization_method = pickle
#: if the contents should be base64 quoted. This can be disabled if the
#: serialization process returns cookie safe strings only.
quote_base64 = True
def __init__(self, data=None, secret_key=None, new=True):
ModificationTrackingDict.__init__(self, data or ())
# explicitly convert it into a bytestring because python 2.6
# no longer performs an implicit string conversion on hmac
if secret_key is not None:
secret_key = bytes(secret_key)
self.secret_key = secret_key
self.new = new
def __repr__(self):
return '<%s %s%s>' % (
self.__class__.__name__,
dict.__repr__(self),
self.should_save and '*' or ''
)
@property
def should_save(self):
"""True if the session should be saved. By default this is only true
for :attr:`modified` cookies, not :attr:`new`.
"""
return self.modified
@classmethod
def quote(cls, value):
"""Quote the value for the cookie. This can be any object supported
by :attr:`serialization_method`.
:param value: the value to quote.
"""
if cls.serialization_method is not None:
value = cls.serialization_method.dumps(value)
if cls.quote_base64:
value = b''.join(base64.b64encode(value).splitlines()).strip()
return value
@classmethod
def unquote(cls, value):
"""Unquote the value for the cookie. If unquoting does not work a
:exc:`UnquoteError` is raised.
:param value: the value to unquote.
"""
try:
if cls.quote_base64:
value = base64.b64decode(value)
if cls.serialization_method is not None:
value = cls.serialization_method.loads(value)
return value
except Exception:
# unfortunately pickle and other serialization modules can
# cause pretty every error here. if we get one we catch it
# and convert it into an UnquoteError
raise UnquoteError()
def serialize(self, expires=None):
"""Serialize the secure cookie into a string.
If expires is provided, the session will be automatically invalidated
after expiration when you unseralize it. This provides better
protection against session cookie theft.
:param expires: an optional expiration date for the cookie (a
:class:`datetime.datetime` object)
"""
if self.secret_key is None:
raise RuntimeError('no secret key defined')
if expires:
self['_expires'] = _date_to_unix(expires)
result = []
mac = hmac(self.secret_key, None, self.hash_method)
for key, value in sorted(self.items()):
result.append(('%s=%s' % (
url_quote_plus(key),
self.quote(value).decode('ascii')
)).encode('ascii'))
mac.update(b'|' + result[-1])
return b'?'.join([
base64.b64encode(mac.digest()).strip(),
b'&'.join(result)
])
@classmethod
def unserialize(cls, string, secret_key):
"""Load the secure cookie from a serialized string.
:param string: the cookie value to unserialize.
:param secret_key: the secret key used to serialize the cookie.
:return: a new :class:`SecureCookie`.
"""
if isinstance(string, text_type):
string = string.encode('utf-8', 'replace')
if isinstance(secret_key, text_type):
secret_key = secret_key.encode('utf-8', 'replace')
try:
base64_hash, data = string.split(b'?', 1)
except (ValueError, IndexError):
items = ()
else:
items = {}
mac = hmac(secret_key, None, cls.hash_method)
for item in data.split(b'&'):
mac.update(b'|' + item)
if not b'=' in item:
items = None
break
key, value = item.split(b'=', 1)
# try to make the key a string
key = url_unquote_plus(key.decode('ascii'))
try:
key = to_native(key)
except UnicodeError:
pass
items[key] = value
# no parsing error and the mac looks okay, we can now
# sercurely unpickle our cookie.
try:
client_hash = base64.b64decode(base64_hash)
except TypeError:
items = client_hash = None
if items is not None and safe_str_cmp(client_hash, mac.digest()):
try:
for key, value in iteritems(items):
items[key] = cls.unquote(value)
except UnquoteError:
items = ()
else:
if '_expires' in items:
if time() > items['_expires']:
items = ()
else:
del items['_expires']
else:
items = ()
return cls(items, secret_key, False)
@classmethod
def load_cookie(cls, request, key='session', secret_key=None):
"""Loads a :class:`SecureCookie` from a cookie in request. If the
cookie is not set, a new :class:`SecureCookie` instanced is
returned.
:param request: a request object that has a `cookies` attribute
which is a dict of all cookie values.
:param key: the name of the cookie.
:param secret_key: the secret key used to unquote the cookie.
Always provide the value even though it has
no default!
"""
data = request.cookies.get(key)
if not data:
return cls(secret_key=secret_key)
return cls.unserialize(data, secret_key)
def save_cookie(self, response, key='session', expires=None,
session_expires=None, max_age=None, path='/', domain=None,
secure=None, httponly=False, force=False):
"""Saves the SecureCookie in a cookie on response object. All
parameters that are not described here are forwarded directly
to :meth:`~BaseResponse.set_cookie`.
:param response: a response object that has a
:meth:`~BaseResponse.set_cookie` method.
:param key: the name of the cookie.
:param session_expires: the expiration date of the secure cookie
stored information. If this is not provided
the cookie `expires` date is used instead.
"""
if force or self.should_save:
data = self.serialize(session_expires or expires)
response.set_cookie(key, data, expires=expires, max_age=max_age,
path=path, domain=domain, secure=secure,
httponly=httponly)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
82,
624,
272,
10380,
14,
2828,
14,
7817,
5306,
272,
18294,
22935,
94,
339,
961,
859,
9031,
282,
5494,
626,
365,
440,
741,
13048,
687,
314,
1890,
272,
2952,
652,
9584,
282,
9040,
314,
1654,
5920,
367,
14,
221,
2047,
883,
675,
652,
465,
272,
2351,
8343,
340,
1006,
1265,
1172,
365,
282,
922,
1305,
503,
6020,
370,
2216,
272,
282,
10367,
315,
922,
14,
339,
14797,
315,
25169,
626,
314,
666,
365,
5139,
12701,
687,
314,
1890,
465,
282,
272,
3293,
5494,
365,
14,
221,
9738,
1265,
2793,
1133,
1172,
370,
3877,
436,
8976,
314,
272,
12184,
1265,
1172,
737,
314,
1654,
14,
339,
5679,
4503,
26,
339,
1306,
687,
10380,
14,
2828,
14,
7817,
5306,
492,
30894,
7810,
272,
1306,
671,
275,
30894,
7810,
6333,
1421,
582,
5685,
12,
298,
6185,
582,
334,
17,
12,
499,
12,
650,
16658,
298,
10957,
19446,
70,
531,
339,
19460,
316,
1901,
282,
1059,
880,
626,
1373,
883,
3877,
652,
315,
282,
5494,
26,
339,
1306,
574,
275,
671,
14,
3549,
342,
339,
3835,
5384,
687,
626,
1059,
4020,
26,
339,
1306,
671,
275,
30894,
7810,
14,
324,
3549,
8,
585,
12,
298,
10957,
19446,
70,
531,
272,
1306,
671,
905,
6185,
937,
272,
334,
17,
12,
499,
12,
650,
9,
339,
982,
17122,
26473,
314,
5494,
436,
314,
9040,
365,
6835,
314,
625,
3549,
272,
1083,
911,
2449,
18030,
436,
372,
282,
892,
2701,
658,
24117,
7810,
64,
909,
14,
339,
14797,
315,
25169,
626,
314,
1338,
911,
506,
8917,
315,
314,
5494,
880,
886,
440,
272,
3877,
666,
315,
282,
5494,
1265,
2793,
1133,
2934,
314,
922,
370,
1937,
14,
339,
13515,
27561,
272,
16248,
23476,
339,
982,
1265,
787,
1808,
314,
10380,
1056,
2251,
1265,
4293,
21494,
314,
272,
11153,
5494,
1901,
2195,
4223,
2839,
642,
447,
398,
687,
10380,
14,
1208,
492,
6328,
63,
1829,
267,
687,
10380,
14,
21148,
492,
3523,
2017,
267,
687,
10380,
14,
2828,
14,
7817,
5306,
492,
30894,
7810,
398,
327,
2793,
1133,
675,
642,
790,
1325,
282,
3365,
1373,
27,
1265,
4293,
2951,
675,
267,
327,
747,
14,
22776,
8,
1165,
9,
370,
664,
6020,
2196,
267,
5795,
11771,
63,
3078,
275,
1557,
10500,
60,
11110,
60,
1774,
24,
90,
60,
10183,
60,
1845,
16,
93,
20,
60,
88,
24,
66,
60,
10656,
7,
398,
1021,
4784,
8,
1563,
2017,
304,
953,
768,
5245,
63,
1829,
288,
347,
1890,
63,
1730,
8,
277,
304,
355,
666,
275,
291,
14,
7792,
14,
362,
360,
1730,
63,
576,
358,
355,
340,
440,
666,
26,
490,
372,
30894,
7810,
8,
4731,
63,
498,
29,
12961,
63,
3078,
9,
355,
372,
30894,
7810,
14,
324,
3549,
8,
576,
12,
5795,
11771,
63,
3078,
9,
398,
347,
4223,
8,
2314,
12,
1343,
63,
1310,
304,
288,
1056,
275,
4784,
8,
2314,
12,
1343,
63,
1310,
9,
953,
327,
664,
282,
1177,
909,
2348,
288,
1177,
275,
2263,
953,
340,
1056,
14,
1258,
63,
1730,
14,
5626,
63,
2117,
26,
355,
2351,
63,
576,
275,
1056,
14,
1258,
63,
1730,
14,
3549,
342,
355,
1177,
14,
409,
63,
5306,
360,
1730,
63,
576,
297,
2351,
63,
576,
12,
2511,
22768,
26960,
29,
549,
9,
288,
372,
1177,
8,
2314,
12,
1343,
63,
1310,
9,
339,
437,
6656,
3376,
13150,
883,
506,
22175,
1354,
701,
1808,
1033,
23999,
3102,
447,
398,
1021,
4784,
8,
1563,
2017,
304,
953,
768,
5245,
63,
1829,
288,
347,
1890,
63,
1730,
8,
277,
304,
355,
372,
30894,
7810,
14,
912,
63,
5306,
8,
277,
12,
7565,
63,
498,
29,
13665,
63,
12961,
9,
398,
347,
4223,
8,
2314,
12,
1343,
63,
1310,
304,
288,
1056,
275,
4784,
8,
2314,
12,
1343,
63,
1310,
9,
953,
327,
664,
282,
1177,
909,
2348,
288,
1177,
275,
2263,
953,
1056,
14,
1258,
63,
1730,
14,
2117,
63,
5306,
8,
1310,
9,
288,
372,
1177,
8,
2314,
12,
1343,
63,
1310,
9,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
5927,
199,
646,
1300,
772,
199,
504,
20330,
492,
892,
465,
20330,
199,
504,
900,
492,
900,
199,
504,
8337,
492,
7793,
17,
465,
485,
885,
63,
2227,
199,
199,
504,
10380,
423,
5819,
492,
10849,
12,
1318,
63,
466,
199,
504,
10380,
14,
3603,
492,
1166,
63,
3513,
63,
6666,
12,
1166,
63,
12240,
63,
6666,
199,
504,
10380,
423,
4672,
492,
485,
602,
63,
475,
63,
11864,
199,
504,
10380,
14,
2828,
14,
11676,
492,
12972,
3477,
23785,
2141,
199,
504,
10380,
14,
4416,
492,
5048,
63,
495,
63,
5730,
199,
504,
10380,
423,
5819,
492,
370,
63,
6106,
421,
199,
533,
1910,
3513,
547,
8,
1726,
304,
272,
408,
8405,
1919,
1202,
370,
4673,
9081,
641,
18593,
1041,
421,
199,
533,
30894,
7810,
8,
29188,
23785,
2141,
304,
272,
408,
18089,
282,
11153,
5494,
14,
221,
2047,
883,
5516,
642,
1021,
436,
5647,
272,
376,
13943,
4497,
1083,
14,
221,
710,
492,
8377,
365,
626,
314,
4497,
1083,
272,
365,
282,
805,
543,
282,
8545,
3217,
370,
314,
8337,
14,
221,
11105,
272,
3102,
787,
1678,
342,
436,
10017,
1252,
339,
5679,
4503,
26,
339,
1306,
671,
275,
30894,
7810,
6333,
1421,
582,
5685,
12,
298,
6185,
582,
334,
17,
12,
499,
12,
650,
16658,
298,
10957,
19446,
70,
531,
272,
1306,
671,
905,
1421,
937,
272,
5685,
272,
1306,
671,
905,
6185,
937,
272,
334,
17,
12,
499,
12,
650,
9,
272,
1306,
671,
905,
21244,
70,
482,
76,
937,
275,
6546,
272,
1306,
671,
14,
5626,
63,
2117,
272,
715,
339,
520,
635,
666,
26,
314,
2536,
666,
14,
221,
13083,
282,
1211,
12,
769,
402,
6346,
503,
658,
403,
2313,
272,
520,
635,
7565,
63,
498,
26,
314,
7565,
790,
14,
221,
982,
440,
663,
658,
403,
64,
503,
440,
2013,
2432,
652,
965,
370,
506,
663,
2544,
520,
5247,
1705,
3549,
64,
365,
2797,
14,
272,
520,
635,
892,
26,
710,
2536,
574,
402,
314,
658,
1222,
64,
3305,
14,
272,
408,
339,
6079,
710,
2631,
1083,
370
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
82,
624,
272,
10380,
14,
2828,
14,
7817,
5306,
272,
18294,
22935,
94,
339,
961,
859,
9031,
282,
5494,
626,
365,
440,
741,
13048,
687,
314,
1890,
272,
2952,
652,
9584,
282,
9040,
314,
1654,
5920,
367,
14,
221,
2047,
883,
675,
652,
465,
272,
2351,
8343,
340,
1006,
1265,
1172,
365,
282,
922,
1305,
503,
6020,
370,
2216,
272,
282,
10367,
315,
922,
14,
339,
14797,
315,
25169,
626,
314,
666,
365,
5139,
12701,
687,
314,
1890,
465,
282,
272,
3293,
5494,
365,
14,
221,
9738,
1265,
2793,
1133,
1172,
370,
3877,
436,
8976,
314,
272,
12184,
1265,
1172,
737,
314,
1654,
14,
339,
5679,
4503,
26,
339,
1306,
687,
10380,
14,
2828,
14,
7817,
5306,
492,
30894,
7810,
272,
1306,
671,
275,
30894,
7810,
6333,
1421,
582,
5685,
12,
298,
6185,
582,
334,
17,
12,
499,
12,
650,
16658,
298,
10957,
19446,
70,
531,
339,
19460,
316,
1901,
282,
1059,
880,
626,
1373,
883,
3877,
652,
315,
282,
5494,
26,
339,
1306,
574,
275,
671,
14,
3549,
342,
339,
3835,
5384,
687,
626,
1059,
4020,
26,
339,
1306,
671,
275,
30894,
7810,
14,
324,
3549,
8,
585,
12,
298,
10957,
19446,
70,
531,
272,
1306,
671,
905,
6185,
937,
272,
334,
17,
12,
499,
12,
650,
9,
339,
982,
17122,
26473,
314,
5494,
436,
314,
9040,
365,
6835,
314,
625,
3549,
272,
1083,
911,
2449,
18030,
436,
372,
282,
892,
2701,
658,
24117,
7810,
64,
909,
14,
339,
14797,
315,
25169,
626,
314,
1338,
911,
506,
8917,
315,
314,
5494,
880,
886,
440,
272,
3877,
666,
315,
282,
5494,
1265,
2793,
1133,
2934,
314,
922,
370,
1937,
14,
339,
13515,
27561,
272,
16248,
23476,
339,
982,
1265,
787,
1808,
314,
10380,
1056,
2251,
1265,
4293,
21494,
314,
272,
11153,
5494,
1901,
2195,
4223,
2839,
642,
447,
398,
687,
10380,
14,
1208,
492,
6328,
63,
1829,
267,
687,
10380,
14,
21148,
492,
3523,
2017,
267,
687,
10380,
14,
2828,
14,
7817,
5306,
492,
30894,
7810,
398,
327,
2793,
1133,
675,
642,
790,
1325,
282,
3365,
1373,
27,
1265,
4293,
2951,
675,
267,
327,
747,
14,
22776,
8,
1165,
9,
370,
664,
6020,
2196,
267,
5795,
11771,
63,
3078,
275,
1557,
10500,
60,
11110,
60,
1774,
24,
90,
60,
10183,
60,
1845,
16,
93,
20,
60,
88,
24,
66,
60,
10656,
7,
398,
1021,
4784,
8,
1563,
2017,
304,
953,
768,
5245,
63,
1829,
288,
347,
1890,
63,
1730,
8,
277,
304,
355,
666,
275,
291,
14,
7792,
14,
362,
360,
1730,
63,
576,
358,
355,
340,
440,
666,
26,
490,
372,
30894,
7810,
8,
4731,
63,
498,
29,
12961,
63,
3078,
9,
355,
372,
30894,
7810,
14,
324,
3549,
8,
576,
12,
5795,
11771,
63,
3078,
9,
398,
347,
4223,
8,
2314,
12,
1343,
63,
1310,
304,
288,
1056,
275,
4784,
8,
2314,
12,
1343,
63,
1310,
9,
953,
327,
664,
282,
1177,
909,
2348,
288,
1177,
275,
2263,
953,
340,
1056,
14,
1258,
63,
1730,
14,
5626,
63,
2117,
26,
355,
2351,
63,
576,
275,
1056,
14,
1258,
63,
1730,
14,
3549,
342,
355,
1177,
14,
409,
63,
5306,
360,
1730,
63,
576,
297,
2351,
63,
576,
12,
2511,
22768,
26960,
29,
549,
9,
288,
372,
1177,
8,
2314,
12,
1343,
63,
1310,
9,
339,
437,
6656,
3376,
13150,
883,
506,
22175,
1354,
701,
1808,
1033,
23999,
3102,
447,
398,
1021,
4784,
8,
1563,
2017,
304,
953,
768,
5245,
63,
1829,
288,
347,
1890,
63,
1730,
8,
277,
304,
355,
372,
30894,
7810,
14,
912,
63,
5306,
8,
277,
12,
7565,
63,
498,
29,
13665,
63,
12961,
9,
398,
347,
4223,
8,
2314,
12,
1343,
63,
1310,
304,
288,
1056,
275,
4784,
8,
2314,
12,
1343,
63,
1310,
9,
953,
327,
664,
282,
1177,
909,
2348,
288,
1177,
275,
2263,
953,
1056,
14,
1258,
63,
1730,
14,
2117,
63,
5306,
8,
1310,
9,
288,
372,
1177,
8,
2314,
12,
1343,
63,
1310,
9,
339,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
5927,
199,
646,
1300,
772,
199,
504,
20330,
492,
892,
465,
20330,
199,
504,
900,
492,
900,
199,
504,
8337,
492,
7793,
17,
465,
485,
885,
63,
2227,
199,
199,
504,
10380,
423,
5819,
492,
10849,
12,
1318,
63,
466,
199,
504,
10380,
14,
3603,
492,
1166,
63,
3513,
63,
6666,
12,
1166,
63,
12240,
63,
6666,
199,
504,
10380,
423,
4672,
492,
485,
602,
63,
475,
63,
11864,
199,
504,
10380,
14,
2828,
14,
11676,
492,
12972,
3477,
23785,
2141,
199,
504,
10380,
14,
4416,
492,
5048,
63,
495,
63,
5730,
199,
504,
10380,
423,
5819,
492,
370,
63,
6106,
421,
199,
533,
1910,
3513,
547,
8,
1726,
304,
272,
408,
8405,
1919,
1202,
370,
4673,
9081,
641,
18593,
1041,
421,
199,
533,
30894,
7810,
8,
29188,
23785,
2141,
304,
272,
408,
18089,
282,
11153,
5494,
14,
221,
2047,
883,
5516,
642,
1021,
436,
5647,
272,
376,
13943,
4497,
1083,
14,
221,
710,
492,
8377,
365,
626,
314,
4497,
1083,
272,
365,
282,
805,
543,
282,
8545,
3217,
370,
314,
8337,
14,
221,
11105,
272,
3102,
787,
1678,
342,
436,
10017,
1252,
339,
5679,
4503,
26,
339,
1306,
671,
275,
30894,
7810,
6333,
1421,
582,
5685,
12,
298,
6185,
582,
334,
17,
12,
499,
12,
650,
16658,
298,
10957,
19446,
70,
531,
272,
1306,
671,
905,
1421,
937,
272,
5685,
272,
1306,
671,
905,
6185,
937,
272,
334,
17,
12,
499,
12,
650,
9,
272,
1306,
671,
905,
21244,
70,
482,
76,
937,
275,
6546,
272,
1306,
671,
14,
5626,
63,
2117,
272,
715,
339,
520,
635,
666,
26,
314,
2536,
666,
14,
221,
13083,
282,
1211,
12,
769,
402,
6346,
503,
658,
403,
2313,
272,
520,
635,
7565,
63,
498,
26,
314,
7565,
790,
14,
221,
982,
440,
663,
658,
403,
64,
503,
440,
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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
] |
geekboxzone/lollipop_external_owasp_sanitizer
|
tools/cut_release.py
|
9
|
6031
|
#!/usr/bin/python
"""
Packages a new maven release.
"""
import os
import re
import shutil
import subprocess
import sys
import xml.dom.minidom
def mime_type_from_path(path):
if path.endswith(".pom"):
return "text/xml;charset=UTF-8"
elif path.endswith(".jar"):
return "application/java-archive"
return None
if "__main__" == __name__:
# Compute directories relative to tools.
trunk_directory_path = os.path.realpath(os.path.join(
os.path.dirname(sys.argv[0]),
".."))
maven_directory_path = os.path.realpath(os.path.join(
os.path.dirname(sys.argv[0]),
"..",
"..",
"maven",
"owasp-java-html-sanitizer",
"owasp-java-html-sanitizer"))
maven_metadata_path = os.path.join(
maven_directory_path,
"maven-metadata.xml")
version_template_directory_path = os.path.join(
maven_directory_path,
"+++version+++")
jar_path = os.path.join(
trunk_directory_path,
"distrib",
"lib",
"owasp-java-html-sanitizer.jar")
src_jar_path = os.path.join(
trunk_directory_path,
"distrib",
"lib",
"owasp-java-html-sanitizer-sources.jar")
doc_jar_path = os.path.join(
trunk_directory_path,
"distrib",
"lib",
"owasp-java-html-sanitizer-javadoc.jar")
# Make sure the directory_structures we expect exist.
assert os.path.isdir(maven_directory_path), maven_directory_path
assert os.path.isdir(trunk_directory_path), trunk_directory_path
assert os.path.isfile(maven_metadata_path), maven_metadata_path
assert os.path.isdir(version_template_directory_path), (
version_template_directory_path)
assert os.path.isfile(jar_path), jar_path
assert os.path.isfile(src_jar_path), src_jar_path
assert os.path.isfile(doc_jar_path), doc_jar_path
# Get svn info of the trunk directory.
svn_info_xml = (
subprocess.Popen(["svn", "info", "--xml", trunk_directory_path],
stdout=subprocess.PIPE)
.communicate()[0])
svn_info = xml.dom.minidom.parseString(svn_info_xml)
# Process SVN output XML to find fields.
date_element = svn_info.getElementsByTagName("date")[0]
entry_element = svn_info.getElementsByTagName("entry")[0]
def inner_text(node):
if node.nodeType == 3: return node.nodeValue
if node.nodeType == 1:
return "".join([inner_text(child) for child in node.childNodes])
return ""
# Create a list of fields to use in substitution.
fields = {
"version": "r%s" % entry_element.getAttribute("revision"),
"timestamp": re.sub(r"[^.\d]|\.\d+", "", inner_text(date_element))
}
def replace_fields(s):
return re.sub(r"\+\+\+(\w+)\+\+\+", lambda m: fields[m.group(1)], s)
# List of files that need to have ##DUPE## and ##REPLACE## sections expanded
# NOTE(12 February 2013): We no longer rewrite maven_metadata_path since this
# project is now hosted in Maven Central, and maven_metadata used a
# groupId/artifactId pair that is incompatible with the convention used by
# Maven Central.
# All maven versions after 12 February are undiscoverable by looking at
# maven_metadata.
files_to_rewrite = []
new_file_paths = []
def copy_directory_structure_template(src_path, container_path):
dest_path = os.path.join(
container_path,
replace_fields(os.path.basename(src_path)))
if os.path.isdir(src_path):
os.mkdir(dest_path)
for child in os.listdir(src_path):
# Skip .svn directories.
if "." == child[0:1]: continue
copy_directory_structure_template(
os.path.join(src_path, child), dest_path)
else:
shutil.copyfile(src_path, dest_path)
mime_type = mime_type_from_path(dest_path)
if mime_type is None or mime_type.startswith("text/"):
files_to_rewrite.append(dest_path)
new_file_paths.append(dest_path)
return dest_path
def rewrite_file(path):
lines = []
in_file = open(path, "r")
try:
file_content = in_file.read()
finally:
in_file.close()
for line in file_content.split("\n"):
indentation = re.match(r"^\s*", line).group()
matches = re.findall(r"(<!--##REPLACE##(.*)##END##-->)", line)
if len(matches) >= 2: raise Error("%s: %s" % (path, line))
if len(matches):
match = matches[0]
line = "%s%s %s" % (indentation, replace_fields(match[1]), match[0])
else:
matches = re.findall("##DUPE##(.*)##END##", line)
if len(matches) >= 2: raise Error("%s: %s" % (path, line))
if len(matches):
match = matches[0]
lines.append("%s%s" % (indentation, replace_fields(match)))
lines.append(line)
out_file = open(path, "w")
try:
out_file.write("\n".join(lines))
finally:
out_file.close()
versioned_jar_path = os.path.join(
version_template_directory_path,
"owasp-java-html-sanitizer-+++version+++.jar")
versioned_src_jar_path = os.path.join(
version_template_directory_path,
"owasp-java-html-sanitizer-+++version+++-sources.jar")
versioned_doc_jar_path = os.path.join(
version_template_directory_path,
"owasp-java-html-sanitizer-+++version+++-javadoc.jar")
shutil.copyfile(jar_path, versioned_jar_path)
shutil.copyfile(src_jar_path, versioned_src_jar_path)
shutil.copyfile(doc_jar_path, versioned_doc_jar_path)
ok = False
version_directory_path = None
try:
version_directory_path = copy_directory_structure_template(
version_template_directory_path, maven_directory_path)
for file_to_rewrite in files_to_rewrite:
rewrite_file(file_to_rewrite)
ok = True
finally:
os.unlink(versioned_jar_path)
os.unlink(versioned_src_jar_path)
os.unlink(versioned_doc_jar_path)
if not ok and version_directory_path is not None:
shutil.rmtree(version_directory_path)
print "svn add '%s'" % version_directory_path
for new_file_path in new_file_paths:
mime_type = mime_type_from_path(new_file_path)
if mime_type is not None:
print "svn propset svn:mime-type '%s' '%s'" % (mime_type, new_file_path)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
25135,
282,
892,
610,
1856,
4683,
14,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
2748,
14,
4556,
14,
21827,
199,
199,
318,
6660,
63,
466,
63,
504,
63,
515,
8,
515,
304,
523,
340,
931,
14,
4130,
9520,
555,
77,
2349,
272,
372,
298,
505,
15,
1652,
27,
6043,
29,
6610,
13,
24,
2,
523,
916,
931,
14,
4130,
9520,
7338,
2349,
272,
372,
298,
3578,
15,
6138,
13,
6404,
2,
523,
372,
488,
199,
199,
692,
4396,
973,
16526,
508,
636,
354,
10651,
523,
327,
8354,
6602,
3847,
370,
7249,
14,
523,
24764,
63,
3619,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
272,
21777,
2237,
523,
610,
1856,
63,
3619,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
272,
21777,
401,
272,
21777,
401,
272,
298,
391,
1856,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
2237,
523,
610,
1856,
63,
2343,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
610,
1856,
63,
3619,
63,
515,
12,
272,
298,
391,
1856,
13,
2343,
14,
1652,
531,
523,
1015,
63,
1160,
63,
3619,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
610,
1856,
63,
3619,
63,
515,
12,
272,
298,
4176,
11,
1023,
4176,
21425,
523,
16290,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
24764,
63,
3619,
63,
515,
12,
272,
298,
20231,
401,
272,
298,
773,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
14,
7338,
531,
523,
2928,
63,
7338,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
24764,
63,
3619,
63,
515,
12,
272,
298,
20231,
401,
272,
298,
773,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
13,
4553,
14,
7338,
531,
523,
1382,
63,
7338,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
24764,
63,
3619,
63,
515,
12,
272,
298,
20231,
401,
272,
298,
773,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
13,
30738,
350,
679,
14,
7338,
531,
819,
327,
4155,
3238,
314,
2082,
63,
13547,
781,
4282,
2187,
14,
523,
702,
747,
14,
515,
14,
6027,
8,
391,
1856,
63,
3619,
63,
515,
395,
610,
1856,
63,
3619,
63,
515,
523,
702,
747,
14,
515,
14,
6027,
8,
13409,
63,
3619,
63,
515,
395,
24764,
63,
3619,
63,
515,
523,
702,
747,
14,
515,
14,
6292,
8,
391,
1856,
63,
2343,
63,
515,
395,
610,
1856,
63,
2343,
63,
515,
523,
702,
747,
14,
515,
14,
6027,
8,
1023,
63,
1160,
63,
3619,
63,
515,
395,
334,
268,
1015,
63,
1160,
63,
3619,
63,
515,
9,
523,
702,
747,
14,
515,
14,
6292,
8,
7338,
63,
515,
395,
16290,
63,
515,
523,
702,
747,
14,
515,
14,
6292,
8,
2164,
63,
7338,
63,
515,
395,
2928,
63,
7338,
63,
515,
523,
702,
747,
14,
515,
14,
6292,
8,
1301,
63,
7338,
63,
515,
395,
1382,
63,
7338,
63,
515,
819,
327,
2372,
11327,
2256,
402,
314,
24764,
2082,
14,
523,
11327,
63,
815,
63,
1652,
275,
334,
1362,
3873,
14,
7942,
5234,
6836,
401,
298,
815,
401,
4320,
1652,
401,
24764,
63,
3619,
63,
515,
467,
1993,
3839,
29,
5781,
14,
6089,
9,
272,
1275,
10664,
3430,
16,
566,
523,
11327,
63,
815,
275,
2748,
14,
4556,
14,
21827,
14,
14934,
8,
6836,
63,
815,
63,
1652,
9,
819,
327,
7132,
24639,
1072,
4692,
370,
2342,
1504,
14,
523,
1434,
63,
2108,
275,
11327,
63,
815,
14,
15045,
480,
602,
9981,
16,
61,
523,
2397,
63,
2108,
275,
11327,
63,
815,
14,
15045,
480,
2373,
9981,
16,
61,
523,
347,
6506,
63,
505,
8,
932,
304,
272,
340,
1031,
14,
12412,
508,
650,
26,
372,
1031,
14,
17240,
272,
340,
1031,
14,
12412,
508,
413,
26,
489,
372,
10587,
904,
779,
5216,
63,
505,
8,
1739,
9,
367,
1982,
315,
1031,
14,
10626,
566,
272,
372,
3087,
819,
327,
2790,
282,
769,
402,
1504,
370,
675,
315,
20584,
14,
523,
1504,
275,
469,
272,
298,
1023,
582,
298,
82,
5,
83,
2,
450,
2397,
63,
2108,
14,
12956,
480,
5792,
1288,
272,
298,
3954,
582,
295,
14,
954,
8,
82,
2,
4735,
3134,
68,
61,
6113,
3134,
68,
22758,
4873,
6506,
63,
505,
8,
602,
63,
2108,
430,
523,
789,
819,
347,
3350,
63,
955,
8,
83,
304,
272,
372,
295,
14,
954,
8,
82,
3212,
7896,
7896,
20900,
87,
13439,
7896,
7896,
22758,
2400,
333,
26,
1504,
59,
77,
14,
923,
8,
17,
4360,
308,
9,
819,
327,
3820,
402,
1584,
626,
1929,
370,
1172,
925,
4980,
1510,
309,
436,
925,
27010,
309,
10189,
11507,
523,
327,
6944,
8,
713,
21141,
26709,
6171,
304,
2136,
949,
8088,
19913,
610,
1856,
63,
2343,
63,
515,
3967,
642,
523,
327,
2199,
365,
3063,
28311,
315,
603,
15556,
32267,
9117,
12,
436,
610,
1856,
63,
2343,
1202,
282,
523,
327,
1572,
1304,
15,
16154,
1304,
4092,
626,
365,
18457,
543,
314,
16129,
1202,
701,
523,
327,
603,
15556,
32267,
9117,
14,
523,
327,
2900,
610,
1856,
5459,
2410,
3144,
21141,
26709,
787,
625,
18861,
461,
701,
10023,
737,
523,
327,
610,
1856,
63,
2343,
14,
523,
1584,
63,
475,
63,
14366,
275,
942,
523,
892,
63,
493,
63,
3771,
275,
942,
819,
347,
1331,
63,
3619,
63,
6976,
63,
1160,
8,
2164,
63,
515,
12,
3970,
63,
515,
304,
272,
2053,
63,
515,
275,
747,
14,
515,
14,
904,
8,
489,
3970,
63,
515,
12,
489,
3350,
63,
955,
8,
736,
14,
515,
14,
4846,
8,
2164,
63,
515,
1724,
272,
340,
747,
14,
515,
14,
6027,
8,
2164,
63,
515,
304,
489,
747,
14,
8215,
8,
2614,
63,
515,
9,
489,
367,
1982,
315,
747,
14,
7374,
8
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
25135,
282,
892,
610,
1856,
4683,
14,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
2748,
14,
4556,
14,
21827,
199,
199,
318,
6660,
63,
466,
63,
504,
63,
515,
8,
515,
304,
523,
340,
931,
14,
4130,
9520,
555,
77,
2349,
272,
372,
298,
505,
15,
1652,
27,
6043,
29,
6610,
13,
24,
2,
523,
916,
931,
14,
4130,
9520,
7338,
2349,
272,
372,
298,
3578,
15,
6138,
13,
6404,
2,
523,
372,
488,
199,
199,
692,
4396,
973,
16526,
508,
636,
354,
10651,
523,
327,
8354,
6602,
3847,
370,
7249,
14,
523,
24764,
63,
3619,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
272,
21777,
2237,
523,
610,
1856,
63,
3619,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
272,
21777,
401,
272,
21777,
401,
272,
298,
391,
1856,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
2237,
523,
610,
1856,
63,
2343,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
610,
1856,
63,
3619,
63,
515,
12,
272,
298,
391,
1856,
13,
2343,
14,
1652,
531,
523,
1015,
63,
1160,
63,
3619,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
610,
1856,
63,
3619,
63,
515,
12,
272,
298,
4176,
11,
1023,
4176,
21425,
523,
16290,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
24764,
63,
3619,
63,
515,
12,
272,
298,
20231,
401,
272,
298,
773,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
14,
7338,
531,
523,
2928,
63,
7338,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
24764,
63,
3619,
63,
515,
12,
272,
298,
20231,
401,
272,
298,
773,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
13,
4553,
14,
7338,
531,
523,
1382,
63,
7338,
63,
515,
275,
747,
14,
515,
14,
904,
8,
272,
24764,
63,
3619,
63,
515,
12,
272,
298,
20231,
401,
272,
298,
773,
401,
272,
298,
583,
20222,
13,
6138,
13,
1360,
13,
83,
9385,
2282,
13,
30738,
350,
679,
14,
7338,
531,
819,
327,
4155,
3238,
314,
2082,
63,
13547,
781,
4282,
2187,
14,
523,
702,
747,
14,
515,
14,
6027,
8,
391,
1856,
63,
3619,
63,
515,
395,
610,
1856,
63,
3619,
63,
515,
523,
702,
747,
14,
515,
14,
6027,
8,
13409,
63,
3619,
63,
515,
395,
24764,
63,
3619,
63,
515,
523,
702,
747,
14,
515,
14,
6292,
8,
391,
1856,
63,
2343,
63,
515,
395,
610,
1856,
63,
2343,
63,
515,
523,
702,
747,
14,
515,
14,
6027,
8,
1023,
63,
1160,
63,
3619,
63,
515,
395,
334,
268,
1015,
63,
1160,
63,
3619,
63,
515,
9,
523,
702,
747,
14,
515,
14,
6292,
8,
7338,
63,
515,
395,
16290,
63,
515,
523,
702,
747,
14,
515,
14,
6292,
8,
2164,
63,
7338,
63,
515,
395,
2928,
63,
7338,
63,
515,
523,
702,
747,
14,
515,
14,
6292,
8,
1301,
63,
7338,
63,
515,
395,
1382,
63,
7338,
63,
515,
819,
327,
2372,
11327,
2256,
402,
314,
24764,
2082,
14,
523,
11327,
63,
815,
63,
1652,
275,
334,
1362,
3873,
14,
7942,
5234,
6836,
401,
298,
815,
401,
4320,
1652,
401,
24764,
63,
3619,
63,
515,
467,
1993,
3839,
29,
5781,
14,
6089,
9,
272,
1275,
10664,
3430,
16,
566,
523,
11327,
63,
815,
275,
2748,
14,
4556,
14,
21827,
14,
14934,
8,
6836,
63,
815,
63,
1652,
9,
819,
327,
7132,
24639,
1072,
4692,
370,
2342,
1504,
14,
523,
1434,
63,
2108,
275,
11327,
63,
815,
14,
15045,
480,
602,
9981,
16,
61,
523,
2397,
63,
2108,
275,
11327,
63,
815,
14,
15045,
480,
2373,
9981,
16,
61,
523,
347,
6506,
63,
505,
8,
932,
304,
272,
340,
1031,
14,
12412,
508,
650,
26,
372,
1031,
14,
17240,
272,
340,
1031,
14,
12412,
508,
413,
26,
489,
372,
10587,
904,
779,
5216,
63,
505,
8,
1739,
9,
367,
1982,
315,
1031,
14,
10626,
566,
272,
372,
3087,
819,
327,
2790,
282,
769,
402,
1504,
370,
675,
315,
20584,
14,
523,
1504,
275,
469,
272,
298,
1023,
582,
298,
82,
5,
83,
2,
450,
2397,
63,
2108,
14,
12956,
480,
5792,
1288,
272,
298,
3954,
582,
295,
14,
954,
8,
82,
2,
4735,
3134,
68,
61,
6113,
3134,
68,
22758,
4873,
6506,
63,
505,
8,
602,
63,
2108,
430,
523,
789,
819,
347,
3350,
63,
955,
8,
83,
304,
272,
372,
295,
14,
954,
8,
82,
3212,
7896,
7896,
20900,
87,
13439,
7896,
7896,
22758,
2400,
333,
26,
1504,
59,
77,
14,
923,
8,
17,
4360,
308,
9,
819,
327,
3820,
402,
1584,
626,
1929,
370,
1172,
925,
4980,
1510,
309,
436,
925,
27010,
309,
10189,
11507,
523,
327,
6944,
8,
713,
21141,
26709,
6171,
304,
2136,
949,
8088,
19913,
610,
1856,
63,
2343,
63,
515,
3967,
642,
523,
327,
2199,
365,
3063,
28311,
315,
603,
15556,
32267,
9117,
12,
436,
610,
1856,
63,
2343,
1202,
282,
523,
327,
1572,
1304,
15,
16154,
1304,
4092,
626,
365,
18457,
543,
314,
16129,
1202,
701,
523,
327,
603,
15556,
32267,
9117,
14,
523,
327,
2900,
610,
1856,
5459,
2410,
3144,
21141,
26709,
787,
625,
18861,
461,
701,
10023,
737,
523,
327,
610,
1856,
63,
2343,
14,
523,
1584,
63,
475,
63,
14366,
275,
942,
523,
892,
63,
493,
63,
3771,
275,
942,
819,
347,
1331,
63,
3619,
63,
6976,
63,
1160,
8,
2164,
63,
515,
12,
3970,
63,
515,
304,
272,
2053,
63,
515,
275,
747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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
] |
SRabbelier/Melange
|
thirdparty/google_appengine/lib/django_1_2/django/contrib/gis/gdal/envelope.py
|
321
|
7044
|
"""
The GDAL/OGR library uses an Envelope structure to hold the bounding
box information for a geometry. The envelope (bounding box) contains
two pairs of coordinates, one for the lower left coordinate and one
for the upper right coordinate:
+----------o Upper right; (max_x, max_y)
| |
| |
| |
Lower left (min_x, min_y) o----------+
"""
from ctypes import Structure, c_double
from django.contrib.gis.gdal.error import OGRException
# The OGR definition of an Envelope is a C structure containing four doubles.
# See the 'ogr_core.h' source file for more information:
# http://www.gdal.org/ogr/ogr__core_8h-source.html
class OGREnvelope(Structure):
"Represents the OGREnvelope C Structure."
_fields_ = [("MinX", c_double),
("MaxX", c_double),
("MinY", c_double),
("MaxY", c_double),
]
class Envelope(object):
"""
The Envelope object is a C structure that contains the minimum and
maximum X, Y coordinates for a rectangle bounding box. The naming
of the variables is compatible with the OGR Envelope structure.
"""
def __init__(self, *args):
"""
The initialization function may take an OGREnvelope structure, 4-element
tuple or list, or 4 individual arguments.
"""
if len(args) == 1:
if isinstance(args[0], OGREnvelope):
# OGREnvelope (a ctypes Structure) was passed in.
self._envelope = args[0]
elif isinstance(args[0], (tuple, list)):
# A tuple was passed in.
if len(args[0]) != 4:
raise OGRException('Incorrect number of tuple elements (%d).' % len(args[0]))
else:
self._from_sequence(args[0])
else:
raise TypeError('Incorrect type of argument: %s' % str(type(args[0])))
elif len(args) == 4:
# Individiual parameters passed in.
# Thanks to ww for the help
self._from_sequence(map(float, args))
else:
raise OGRException('Incorrect number (%d) of arguments.' % len(args))
# Checking the x,y coordinates
if self.min_x > self.max_x:
raise OGRException('Envelope minimum X > maximum X.')
if self.min_y > self.max_y:
raise OGRException('Envelope minimum Y > maximum Y.')
def __eq__(self, other):
"""
Returns True if the envelopes are equivalent; can compare against
other Envelopes and 4-tuples.
"""
if isinstance(other, Envelope):
return (self.min_x == other.min_x) and (self.min_y == other.min_y) and \
(self.max_x == other.max_x) and (self.max_y == other.max_y)
elif isinstance(other, tuple) and len(other) == 4:
return (self.min_x == other[0]) and (self.min_y == other[1]) and \
(self.max_x == other[2]) and (self.max_y == other[3])
else:
raise OGRException('Equivalence testing only works with other Envelopes.')
def __str__(self):
"Returns a string representation of the tuple."
return str(self.tuple)
def _from_sequence(self, seq):
"Initializes the C OGR Envelope structure from the given sequence."
self._envelope = OGREnvelope()
self._envelope.MinX = seq[0]
self._envelope.MinY = seq[1]
self._envelope.MaxX = seq[2]
self._envelope.MaxY = seq[3]
def expand_to_include(self, *args):
"""
Modifies the envelope to expand to include the boundaries of
the passed-in 2-tuple (a point), 4-tuple (an extent) or
envelope.
"""
# We provide a number of different signatures for this method,
# and the logic here is all about converting them into a
# 4-tuple single parameter which does the actual work of
# expanding the envelope.
if len(args) == 1:
if isinstance(args[0], Envelope):
return self.expand_to_include(args[0].tuple)
elif hasattr(args[0], 'x') and hasattr(args[0], 'y'):
return self.expand_to_include(args[0].x, args[0].y, args[0].x, args[0].y)
elif isinstance(args[0], (tuple, list)):
# A tuple was passed in.
if len(args[0]) == 2:
return self.expand_to_include((args[0][0], args[0][1], args[0][0], args[0][1]))
elif len(args[0]) == 4:
(minx, miny, maxx, maxy) = args[0]
if minx < self._envelope.MinX:
self._envelope.MinX = minx
if miny < self._envelope.MinY:
self._envelope.MinY = miny
if maxx > self._envelope.MaxX:
self._envelope.MaxX = maxx
if maxy > self._envelope.MaxY:
self._envelope.MaxY = maxy
else:
raise OGRException('Incorrect number of tuple elements (%d).' % len(args[0]))
else:
raise TypeError('Incorrect type of argument: %s' % str(type(args[0])))
elif len(args) == 2:
# An x and an y parameter were passed in
return self.expand_to_include((args[0], args[1], args[0], args[1]))
elif len(args) == 4:
# Individiual parameters passed in.
return self.expand_to_include(args)
else:
raise OGRException('Incorrect number (%d) of arguments.' % len(args[0]))
@property
def min_x(self):
"Returns the value of the minimum X coordinate."
return self._envelope.MinX
@property
def min_y(self):
"Returns the value of the minimum Y coordinate."
return self._envelope.MinY
@property
def max_x(self):
"Returns the value of the maximum X coordinate."
return self._envelope.MaxX
@property
def max_y(self):
"Returns the value of the maximum Y coordinate."
return self._envelope.MaxY
@property
def ur(self):
"Returns the upper-right coordinate."
return (self.max_x, self.max_y)
@property
def ll(self):
"Returns the lower-left coordinate."
return (self.min_x, self.min_y)
@property
def tuple(self):
"Returns a tuple representing the envelope."
return (self.min_x, self.min_y, self.max_x, self.max_y)
@property
def wkt(self):
"Returns WKT representing a Polygon for this envelope."
# TODO: Fix significant figures.
return 'POLYGON((%s %s,%s %s,%s %s,%s %s,%s %s))' % \
(self.min_x, self.min_y, self.min_x, self.max_y,
self.max_x, self.max_y, self.max_x, self.min_y,
self.min_x, self.min_y)
|
apache-2.0
|
[
624,
199,
710,
15801,
15,
17275,
3555,
4440,
376,
29143,
5523,
370,
10266,
314,
16842,
199,
5689,
2556,
367,
282,
3400,
14,
221,
710,
24631,
334,
24511,
5689,
9,
3509,
199,
2877,
6342,
402,
8983,
12,
1373,
367,
314,
5117,
3602,
10021,
436,
1373,
199,
367,
314,
7008,
2451,
10021,
26,
199,
2574,
435,
9460,
79,
4949,
529,
2451,
27,
334,
988,
63,
88,
12,
1390,
63,
89,
9,
2574,
1204,
3515,
1204,
2574,
1204,
3515,
1204,
2574,
1204,
3515,
1204,
199,
29893,
3602,
334,
827,
63,
88,
12,
1748,
63,
89,
9,
312,
30978,
199,
624,
199,
504,
5577,
492,
21730,
12,
286,
63,
3157,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
199,
199,
3,
710,
10904,
5492,
402,
376,
29143,
365,
282,
445,
5523,
3035,
11648,
4270,
83,
14,
199,
3,
221,
1666,
314,
283,
14945,
63,
1018,
14,
72,
7,
1350,
570,
367,
1655,
2556,
26,
199,
3,
257,
1455,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
15,
14945,
363,
1018,
63,
24,
72,
13,
1365,
14,
1360,
199,
533,
19746,
907,
78,
10658,
8,
10766,
304,
272,
298,
18089,
314,
19746,
907,
78,
10658,
445,
21730,
2122,
272,
485,
955,
63,
275,
10003,
4649,
56,
401,
286,
63,
3157,
395,
355,
1689,
4261,
56,
401,
286,
63,
3157,
395,
355,
1689,
4649,
57,
401,
286,
63,
3157,
395,
355,
1689,
4261,
57,
401,
286,
63,
3157,
395,
355,
1622,
199,
199,
533,
29143,
8,
785,
304,
272,
408,
272,
710,
29143,
909,
365,
282,
445,
5523,
626,
3509,
314,
7481,
436,
272,
5696,
1323,
12,
1488,
8983,
367,
282,
20412,
16842,
5689,
14,
221,
710,
19720,
272,
402,
314,
2860,
365,
9025,
543,
314,
10904,
29143,
5523,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
408,
267,
710,
11097,
805,
1443,
5452,
376,
19746,
907,
78,
10658,
5523,
12,
841,
13,
2108,
267,
2008,
503,
769,
12,
503,
841,
8212,
2368,
14,
267,
408,
2728,
340,
822,
8,
589,
9,
508,
413,
26,
288,
340,
1228,
8,
589,
59,
16,
467,
19746,
907,
78,
10658,
304,
355,
327,
19746,
907,
78,
10658,
334,
65,
5577,
21730,
9,
1990,
3032,
315,
14,
355,
291,
423,
19707,
275,
1249,
59,
16,
61,
288,
916,
1228,
8,
589,
59,
16,
467,
334,
2960,
12,
769,
2298,
355,
327,
437,
2008,
1990,
3032,
315,
14,
355,
340,
822,
8,
589,
59,
16,
566,
1137,
841,
26,
490,
746,
19746,
907,
16010,
360,
18298,
1329,
402,
2008,
4008,
4366,
68,
28823,
450,
822,
8,
589,
59,
16,
2459,
355,
587,
26,
490,
291,
423,
504,
63,
4041,
8,
589,
59,
16,
566,
288,
587,
26,
355,
746,
3146,
360,
18298,
730,
402,
1423,
26,
450,
83,
7,
450,
620,
8,
466,
8,
589,
59,
16,
11845,
267,
916,
822,
8,
589,
9,
508,
841,
26,
288,
327,
1010,
328,
433,
328,
1061,
2633,
3032,
315,
14,
288,
327,
221,
3868,
25088,
370,
24618,
367,
314,
1720,
288,
291,
423,
504,
63,
4041,
8,
1130,
8,
1609,
12,
1249,
430,
267,
587,
26,
288,
746,
19746,
907,
16010,
360,
18298,
1329,
4366,
68,
9,
402,
2368,
3530,
450,
822,
8,
589,
430,
398,
327,
25109,
314,
671,
12,
89,
8983,
267,
340,
291,
14,
827,
63,
88,
690,
291,
14,
988,
63,
88,
26,
288,
746,
19746,
907,
16010,
360,
28278,
7481,
1323,
690,
5696,
1323,
2659,
267,
340,
291,
14,
827,
63,
89,
690,
291,
14,
988,
63,
89,
26,
288,
746,
19746,
907,
16010,
360,
28278,
7481,
1488,
690,
5696,
1488,
2659,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
715,
340,
314,
24631,
83,
787,
7353,
27,
883,
6540,
6169,
267,
1163,
29143,
83,
436,
841,
13,
11760,
14,
267,
408,
267,
340,
1228,
8,
1848,
12,
29143,
304,
288,
372,
334,
277,
14,
827,
63,
88,
508,
1163,
14,
827,
63,
88,
9,
436,
334,
277,
14,
827,
63,
89,
508,
1163,
14,
827,
63,
89,
9,
436,
971,
673,
334,
277,
14,
988,
63,
88,
508,
1163,
14,
988,
63,
88,
9,
436,
334,
277,
14,
988,
63,
89,
508,
1163,
14,
988,
63,
89,
9,
267,
916,
1228,
8,
1848,
12,
2008,
9,
436,
822,
8,
1848,
9,
508,
841,
26,
288,
372,
334,
277,
14,
827,
63,
88,
508,
1163,
59,
16,
566,
436,
334,
277,
14,
827,
63,
89,
508,
1163,
59,
17,
566,
436,
971,
673,
334,
277,
14,
988,
63,
88,
508,
1163,
59,
18,
566,
436,
334,
277,
14,
988,
63,
89,
508,
1163,
59,
19,
566,
267,
587,
26,
288,
746,
19746,
907,
16010,
360,
37,
22810,
5343,
1454,
5419,
543,
1163,
29143,
83,
2659,
339,
347,
636,
495,
721,
277,
304,
267,
298,
3407,
282,
1059,
6025,
402,
314,
2008,
2122,
267,
372,
620,
8,
277,
14,
2960,
9,
339,
347,
485,
504,
63,
4041,
8,
277,
12,
5412,
304,
267,
298,
23489,
314,
445,
10904,
29143,
5523,
687,
314,
1627,
3414,
2122,
267,
291,
423,
19707,
275,
19746,
907,
78,
10658,
342,
267,
291,
423,
19707,
14,
4649,
56,
275,
5412,
59,
16,
61,
267,
291,
423,
19707,
14,
4649,
57,
275,
5412,
59,
17,
61,
267,
291,
423,
19707,
14,
4261,
56,
275,
5412,
59,
18,
61,
267,
291,
423,
19707,
14,
4261,
57,
275,
5412,
59,
19,
61,
2286,
347,
6544,
63,
475,
63,
2613,
8,
277,
12,
627,
589,
304,
4960,
408,
4960,
12972,
5604,
314,
24631,
370,
6544,
370,
2387,
314,
18135,
402,
4960,
314,
3032,
13,
262,
499,
13,
2960,
334,
65,
2376,
395,
841,
13,
2960,
334,
290,
13675,
9,
503,
4960,
24631,
14,
4960,
408,
4960,
327,
2136,
5647,
282,
1329,
402,
3365,
17597,
367,
642,
1083,
12,
4960,
327,
436,
314,
9661,
2348,
365,
1006,
3595,
13806,
3062,
1901,
282,
4960,
327,
841,
13,
2960,
2849,
2725,
1314,
1630,
314,
3503,
1736,
402,
4960,
327,
6544,
316,
314,
24631,
14,
4960,
340,
822,
8,
589,
9,
508,
413,
26,
7205,
340,
1228,
8,
589,
59,
16,
467,
29143,
304,
8892,
372,
291,
14,
4441,
63,
475,
63,
2613,
8,
589,
59,
16,
1055,
2960
] |
[
199,
710,
15801,
15,
17275,
3555,
4440,
376,
29143,
5523,
370,
10266,
314,
16842,
199,
5689,
2556,
367,
282,
3400,
14,
221,
710,
24631,
334,
24511,
5689,
9,
3509,
199,
2877,
6342,
402,
8983,
12,
1373,
367,
314,
5117,
3602,
10021,
436,
1373,
199,
367,
314,
7008,
2451,
10021,
26,
199,
2574,
435,
9460,
79,
4949,
529,
2451,
27,
334,
988,
63,
88,
12,
1390,
63,
89,
9,
2574,
1204,
3515,
1204,
2574,
1204,
3515,
1204,
2574,
1204,
3515,
1204,
199,
29893,
3602,
334,
827,
63,
88,
12,
1748,
63,
89,
9,
312,
30978,
199,
624,
199,
504,
5577,
492,
21730,
12,
286,
63,
3157,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
199,
199,
3,
710,
10904,
5492,
402,
376,
29143,
365,
282,
445,
5523,
3035,
11648,
4270,
83,
14,
199,
3,
221,
1666,
314,
283,
14945,
63,
1018,
14,
72,
7,
1350,
570,
367,
1655,
2556,
26,
199,
3,
257,
1455,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
15,
14945,
363,
1018,
63,
24,
72,
13,
1365,
14,
1360,
199,
533,
19746,
907,
78,
10658,
8,
10766,
304,
272,
298,
18089,
314,
19746,
907,
78,
10658,
445,
21730,
2122,
272,
485,
955,
63,
275,
10003,
4649,
56,
401,
286,
63,
3157,
395,
355,
1689,
4261,
56,
401,
286,
63,
3157,
395,
355,
1689,
4649,
57,
401,
286,
63,
3157,
395,
355,
1689,
4261,
57,
401,
286,
63,
3157,
395,
355,
1622,
199,
199,
533,
29143,
8,
785,
304,
272,
408,
272,
710,
29143,
909,
365,
282,
445,
5523,
626,
3509,
314,
7481,
436,
272,
5696,
1323,
12,
1488,
8983,
367,
282,
20412,
16842,
5689,
14,
221,
710,
19720,
272,
402,
314,
2860,
365,
9025,
543,
314,
10904,
29143,
5523,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
408,
267,
710,
11097,
805,
1443,
5452,
376,
19746,
907,
78,
10658,
5523,
12,
841,
13,
2108,
267,
2008,
503,
769,
12,
503,
841,
8212,
2368,
14,
267,
408,
2728,
340,
822,
8,
589,
9,
508,
413,
26,
288,
340,
1228,
8,
589,
59,
16,
467,
19746,
907,
78,
10658,
304,
355,
327,
19746,
907,
78,
10658,
334,
65,
5577,
21730,
9,
1990,
3032,
315,
14,
355,
291,
423,
19707,
275,
1249,
59,
16,
61,
288,
916,
1228,
8,
589,
59,
16,
467,
334,
2960,
12,
769,
2298,
355,
327,
437,
2008,
1990,
3032,
315,
14,
355,
340,
822,
8,
589,
59,
16,
566,
1137,
841,
26,
490,
746,
19746,
907,
16010,
360,
18298,
1329,
402,
2008,
4008,
4366,
68,
28823,
450,
822,
8,
589,
59,
16,
2459,
355,
587,
26,
490,
291,
423,
504,
63,
4041,
8,
589,
59,
16,
566,
288,
587,
26,
355,
746,
3146,
360,
18298,
730,
402,
1423,
26,
450,
83,
7,
450,
620,
8,
466,
8,
589,
59,
16,
11845,
267,
916,
822,
8,
589,
9,
508,
841,
26,
288,
327,
1010,
328,
433,
328,
1061,
2633,
3032,
315,
14,
288,
327,
221,
3868,
25088,
370,
24618,
367,
314,
1720,
288,
291,
423,
504,
63,
4041,
8,
1130,
8,
1609,
12,
1249,
430,
267,
587,
26,
288,
746,
19746,
907,
16010,
360,
18298,
1329,
4366,
68,
9,
402,
2368,
3530,
450,
822,
8,
589,
430,
398,
327,
25109,
314,
671,
12,
89,
8983,
267,
340,
291,
14,
827,
63,
88,
690,
291,
14,
988,
63,
88,
26,
288,
746,
19746,
907,
16010,
360,
28278,
7481,
1323,
690,
5696,
1323,
2659,
267,
340,
291,
14,
827,
63,
89,
690,
291,
14,
988,
63,
89,
26,
288,
746,
19746,
907,
16010,
360,
28278,
7481,
1488,
690,
5696,
1488,
2659,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
715,
340,
314,
24631,
83,
787,
7353,
27,
883,
6540,
6169,
267,
1163,
29143,
83,
436,
841,
13,
11760,
14,
267,
408,
267,
340,
1228,
8,
1848,
12,
29143,
304,
288,
372,
334,
277,
14,
827,
63,
88,
508,
1163,
14,
827,
63,
88,
9,
436,
334,
277,
14,
827,
63,
89,
508,
1163,
14,
827,
63,
89,
9,
436,
971,
673,
334,
277,
14,
988,
63,
88,
508,
1163,
14,
988,
63,
88,
9,
436,
334,
277,
14,
988,
63,
89,
508,
1163,
14,
988,
63,
89,
9,
267,
916,
1228,
8,
1848,
12,
2008,
9,
436,
822,
8,
1848,
9,
508,
841,
26,
288,
372,
334,
277,
14,
827,
63,
88,
508,
1163,
59,
16,
566,
436,
334,
277,
14,
827,
63,
89,
508,
1163,
59,
17,
566,
436,
971,
673,
334,
277,
14,
988,
63,
88,
508,
1163,
59,
18,
566,
436,
334,
277,
14,
988,
63,
89,
508,
1163,
59,
19,
566,
267,
587,
26,
288,
746,
19746,
907,
16010,
360,
37,
22810,
5343,
1454,
5419,
543,
1163,
29143,
83,
2659,
339,
347,
636,
495,
721,
277,
304,
267,
298,
3407,
282,
1059,
6025,
402,
314,
2008,
2122,
267,
372,
620,
8,
277,
14,
2960,
9,
339,
347,
485,
504,
63,
4041,
8,
277,
12,
5412,
304,
267,
298,
23489,
314,
445,
10904,
29143,
5523,
687,
314,
1627,
3414,
2122,
267,
291,
423,
19707,
275,
19746,
907,
78,
10658,
342,
267,
291,
423,
19707,
14,
4649,
56,
275,
5412,
59,
16,
61,
267,
291,
423,
19707,
14,
4649,
57,
275,
5412,
59,
17,
61,
267,
291,
423,
19707,
14,
4261,
56,
275,
5412,
59,
18,
61,
267,
291,
423,
19707,
14,
4261,
57,
275,
5412,
59,
19,
61,
2286,
347,
6544,
63,
475,
63,
2613,
8,
277,
12,
627,
589,
304,
4960,
408,
4960,
12972,
5604,
314,
24631,
370,
6544,
370,
2387,
314,
18135,
402,
4960,
314,
3032,
13,
262,
499,
13,
2960,
334,
65,
2376,
395,
841,
13,
2960,
334,
290,
13675,
9,
503,
4960,
24631,
14,
4960,
408,
4960,
327,
2136,
5647,
282,
1329,
402,
3365,
17597,
367,
642,
1083,
12,
4960,
327,
436,
314,
9661,
2348,
365,
1006,
3595,
13806,
3062,
1901,
282,
4960,
327,
841,
13,
2960,
2849,
2725,
1314,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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
] |
wainersm/buildbot
|
master/buildbot/test/unit/test_interpolate_secrets.py
|
6
|
2056
|
from __future__ import absolute_import
from __future__ import print_function
from twisted.internet import defer
from twisted.trial import unittest
from buildbot.process.properties import Interpolate
from buildbot.secrets.manager import SecretManager
from buildbot.test.fake import fakemaster
from buildbot.test.fake.fakebuild import FakeBuild
from buildbot.test.fake.secrets import FakeSecretStorage
from buildbot.test.util.config import ConfigErrorsMixin
class FakeBuildWithMaster(FakeBuild):
def __init__(self, master):
super(FakeBuildWithMaster, self).__init__()
self.master = master
class TestInterpolateSecrets(unittest.TestCase, ConfigErrorsMixin):
def setUp(self):
self.master = fakemaster.make_master()
fakeStorageService = FakeSecretStorage()
fakeStorageService.reconfigService(secretdict={"foo": "bar",
"other": "value"})
self.secretsrv = SecretManager()
self.secretsrv.services = [fakeStorageService]
self.secretsrv.setServiceParent(self.master)
self.build = FakeBuildWithMaster(self.master)
@defer.inlineCallbacks
def test_secret(self):
command = Interpolate("echo %(secrets:foo)s")
rendered = yield self.build.render(command)
self.assertEqual(rendered, "echo bar")
def test_secret_not_found(self):
command = Interpolate("echo %(secrets:fuo)s")
self.assertFailure(self.build.render(command), defer.FirstError)
self.flushLoggedErrors(defer.FirstError)
self.flushLoggedErrors(KeyError)
class TestInterpolateSecretsNoService(unittest.TestCase, ConfigErrorsMixin):
def setUp(self):
self.master = fakemaster.make_master()
self.build = FakeBuildWithMaster(self.master)
def test_secret(self):
command = Interpolate("echo %(secrets:fuo)s")
self.assertFailure(self.build.render(command), defer.FirstError)
self.flushLoggedErrors(defer.FirstError)
self.flushLoggedErrors(KeyError)
|
gpl-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
21306,
14,
1412,
14,
3282,
492,
6551,
14641,
199,
504,
21306,
14,
16153,
14,
2609,
492,
23580,
2988,
199,
504,
21306,
14,
396,
14,
3183,
492,
4026,
4133,
199,
504,
21306,
14,
396,
14,
3183,
14,
3183,
1506,
492,
7777,
3425,
199,
504,
21306,
14,
396,
14,
3183,
14,
16153,
492,
7777,
13790,
6408,
199,
504,
21306,
14,
396,
14,
1974,
14,
888,
492,
4094,
9298,
4256,
421,
199,
533,
7777,
3425,
3007,
12288,
8,
8249,
3425,
304,
339,
347,
636,
826,
721,
277,
12,
5288,
304,
267,
1613,
8,
8249,
3425,
3007,
12288,
12,
291,
2843,
826,
4533,
267,
291,
14,
4133,
275,
5288,
421,
199,
533,
1379,
2620,
14641,
4933,
264,
1086,
8,
2796,
14,
1746,
12,
4094,
9298,
4256,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4133,
275,
4026,
4133,
14,
1875,
63,
4133,
342,
267,
4026,
6408,
3167,
275,
7777,
13790,
6408,
342,
267,
4026,
6408,
3167,
14,
264,
888,
3167,
8,
4731,
807,
8871,
1421,
582,
298,
1700,
401,
10940,
298,
1848,
582,
298,
585,
5984,
267,
291,
14,
16153,
6310,
275,
23580,
2988,
342,
267,
291,
14,
16153,
6310,
14,
5950,
275,
359,
3183,
6408,
3167,
61,
267,
291,
14,
16153,
6310,
14,
409,
3167,
6652,
8,
277,
14,
4133,
9,
267,
291,
14,
1506,
275,
7777,
3425,
3007,
12288,
8,
277,
14,
4133,
9,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
4731,
8,
277,
304,
267,
1414,
275,
6551,
14641,
480,
7878,
2818,
16153,
26,
1421,
9,
83,
531,
267,
8018,
275,
1995,
291,
14,
1506,
14,
3352,
8,
1531,
9,
267,
291,
14,
629,
8,
16841,
12,
298,
7878,
4681,
531,
339,
347,
511,
63,
4731,
63,
1397,
63,
4214,
8,
277,
304,
267,
1414,
275,
6551,
14641,
480,
7878,
2818,
16153,
26,
13499,
79,
9,
83,
531,
267,
291,
14,
479,
6782,
8,
277,
14,
1506,
14,
3352,
8,
1531,
395,
10133,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
11610,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
10230,
9,
421,
199,
533,
1379,
2620,
14641,
4933,
264,
1086,
1944,
3167,
8,
2796,
14,
1746,
12,
4094,
9298,
4256,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4133,
275,
4026,
4133,
14,
1875,
63,
4133,
342,
267,
291,
14,
1506,
275,
7777,
3425,
3007,
12288,
8,
277,
14,
4133,
9,
339,
347,
511,
63,
4731,
8,
277,
304,
267,
1414,
275,
6551,
14641,
480,
7878,
2818,
16153,
26,
13499,
79,
9,
83,
531,
267,
291,
14,
479,
6782,
8,
277,
14,
1506,
14,
3352,
8,
1531,
395,
10133,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
11610,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
10230,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
21306,
14,
1412,
14,
3282,
492,
6551,
14641,
199,
504,
21306,
14,
16153,
14,
2609,
492,
23580,
2988,
199,
504,
21306,
14,
396,
14,
3183,
492,
4026,
4133,
199,
504,
21306,
14,
396,
14,
3183,
14,
3183,
1506,
492,
7777,
3425,
199,
504,
21306,
14,
396,
14,
3183,
14,
16153,
492,
7777,
13790,
6408,
199,
504,
21306,
14,
396,
14,
1974,
14,
888,
492,
4094,
9298,
4256,
421,
199,
533,
7777,
3425,
3007,
12288,
8,
8249,
3425,
304,
339,
347,
636,
826,
721,
277,
12,
5288,
304,
267,
1613,
8,
8249,
3425,
3007,
12288,
12,
291,
2843,
826,
4533,
267,
291,
14,
4133,
275,
5288,
421,
199,
533,
1379,
2620,
14641,
4933,
264,
1086,
8,
2796,
14,
1746,
12,
4094,
9298,
4256,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4133,
275,
4026,
4133,
14,
1875,
63,
4133,
342,
267,
4026,
6408,
3167,
275,
7777,
13790,
6408,
342,
267,
4026,
6408,
3167,
14,
264,
888,
3167,
8,
4731,
807,
8871,
1421,
582,
298,
1700,
401,
10940,
298,
1848,
582,
298,
585,
5984,
267,
291,
14,
16153,
6310,
275,
23580,
2988,
342,
267,
291,
14,
16153,
6310,
14,
5950,
275,
359,
3183,
6408,
3167,
61,
267,
291,
14,
16153,
6310,
14,
409,
3167,
6652,
8,
277,
14,
4133,
9,
267,
291,
14,
1506,
275,
7777,
3425,
3007,
12288,
8,
277,
14,
4133,
9,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
4731,
8,
277,
304,
267,
1414,
275,
6551,
14641,
480,
7878,
2818,
16153,
26,
1421,
9,
83,
531,
267,
8018,
275,
1995,
291,
14,
1506,
14,
3352,
8,
1531,
9,
267,
291,
14,
629,
8,
16841,
12,
298,
7878,
4681,
531,
339,
347,
511,
63,
4731,
63,
1397,
63,
4214,
8,
277,
304,
267,
1414,
275,
6551,
14641,
480,
7878,
2818,
16153,
26,
13499,
79,
9,
83,
531,
267,
291,
14,
479,
6782,
8,
277,
14,
1506,
14,
3352,
8,
1531,
395,
10133,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
11610,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
10230,
9,
421,
199,
533,
1379,
2620,
14641,
4933,
264,
1086,
1944,
3167,
8,
2796,
14,
1746,
12,
4094,
9298,
4256,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4133,
275,
4026,
4133,
14,
1875,
63,
4133,
342,
267,
291,
14,
1506,
275,
7777,
3425,
3007,
12288,
8,
277,
14,
4133,
9,
339,
347,
511,
63,
4731,
8,
277,
304,
267,
1414,
275,
6551,
14641,
480,
7878,
2818,
16153,
26,
13499,
79,
9,
83,
531,
267,
291,
14,
479,
6782,
8,
277,
14,
1506,
14,
3352,
8,
1531,
395,
10133,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
11610,
14,
7147,
547,
9,
267,
291,
14,
4939,
28985,
9298,
8,
10230,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
fti7/ansible-modules-core
|
cloud/rax_scaling_policy.py
|
60
|
9059
|
#!/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/>.
# This is a DOCUMENTATION stub specific to this module, it extends
# a documentation fragment located in ansible.utils.module_docs_fragments
DOCUMENTATION = '''
---
module: rax_scaling_policy
short_description: Manipulate Rackspace Cloud Autoscale Scaling Policy
description:
- Manipulate Rackspace Cloud Autoscale Scaling Policy
version_added: 1.7
options:
at:
description:
- The UTC time when this policy will be executed. The time must be
formatted according to C(yyyy-MM-dd'T'HH:mm:ss.SSS) such as
C(2013-05-19T08:07:08Z)
change:
description:
- The change, either as a number of servers or as a percentage, to make
in the scaling group. If this is a percentage, you must set
I(is_percent) to C(true) also.
cron:
description:
- The time when the policy will be executed, as a cron entry. For
example, if this is parameter is set to C(1 0 * * *)
cooldown:
description:
- The period of time, in seconds, that must pass before any scaling can
occur after the previous scaling. Must be an integer between 0 and
86400 (24 hrs).
desired_capacity:
description:
- The desired server capacity of the scaling the group; that is, how
many servers should be in the scaling group.
is_percent:
description:
- Whether the value in I(change) is a percent value
default: false
name:
description:
- Name to give the policy
required: true
policy_type:
description:
- The type of policy that will be executed for the current release.
choices:
- webhook
- schedule
required: true
scaling_group:
description:
- Name of the scaling group that this policy will be added to
required: true
state:
description:
- Indicate desired state of the resource
choices:
- present
- absent
default: present
author: Matt Martz
extends_documentation_fragment: rackspace
'''
EXAMPLES = '''
---
- hosts: localhost
gather_facts: false
connection: local
tasks:
- rax_scaling_policy:
credentials: ~/.raxpub
region: ORD
at: '2013-05-19T08:07:08Z'
change: 25
cooldown: 300
is_percent: true
name: ASG Test Policy - at
policy_type: schedule
scaling_group: ASG Test
register: asps_at
- rax_scaling_policy:
credentials: ~/.raxpub
region: ORD
cron: '1 0 * * *'
change: 25
cooldown: 300
is_percent: true
name: ASG Test Policy - cron
policy_type: schedule
scaling_group: ASG Test
register: asp_cron
- rax_scaling_policy:
credentials: ~/.raxpub
region: ORD
cooldown: 300
desired_capacity: 5
name: ASG Test Policy - webhook
policy_type: webhook
scaling_group: ASG Test
register: asp_webhook
'''
try:
import pyrax
HAS_PYRAX = True
except ImportError:
HAS_PYRAX = False
def rax_asp(module, at=None, change=0, cron=None, cooldown=300,
desired_capacity=0, is_percent=False, name=None,
policy_type=None, scaling_group=None, state='present'):
changed = False
au = pyrax.autoscale
if not au:
module.fail_json(msg='Failed to instantiate client. This '
'typically indicates an invalid region or an '
'incorrectly capitalized region name.')
try:
UUID(scaling_group)
except ValueError:
try:
sg = au.find(name=scaling_group)
except Exception, e:
module.fail_json(msg='%s' % e.message)
else:
try:
sg = au.get(scaling_group)
except Exception, e:
module.fail_json(msg='%s' % e.message)
if state == 'present':
policies = filter(lambda p: name == p.name, sg.list_policies())
if len(policies) > 1:
module.fail_json(msg='No unique policy match found by name')
if at:
args = dict(at=at)
elif cron:
args = dict(cron=cron)
else:
args = None
if not policies:
try:
policy = sg.add_policy(name, policy_type=policy_type,
cooldown=cooldown, change=change,
is_percent=is_percent,
desired_capacity=desired_capacity,
args=args)
changed = True
except Exception, e:
module.fail_json(msg='%s' % e.message)
else:
policy = policies[0]
kwargs = {}
if policy_type != policy.type:
kwargs['policy_type'] = policy_type
if cooldown != policy.cooldown:
kwargs['cooldown'] = cooldown
if hasattr(policy, 'change') and change != policy.change:
kwargs['change'] = change
if hasattr(policy, 'changePercent') and is_percent is False:
kwargs['change'] = change
kwargs['is_percent'] = False
elif hasattr(policy, 'change') and is_percent is True:
kwargs['change'] = change
kwargs['is_percent'] = True
if hasattr(policy, 'desiredCapacity') and change:
kwargs['change'] = change
elif ((hasattr(policy, 'change') or
hasattr(policy, 'changePercent')) and desired_capacity):
kwargs['desired_capacity'] = desired_capacity
if hasattr(policy, 'args') and args != policy.args:
kwargs['args'] = args
if kwargs:
policy.update(**kwargs)
changed = True
policy.get()
module.exit_json(changed=changed, autoscale_policy=rax_to_dict(policy))
else:
try:
policies = filter(lambda p: name == p.name, sg.list_policies())
if len(policies) > 1:
module.fail_json(msg='No unique policy match found by name')
elif not policies:
policy = {}
else:
policy.delete()
changed = True
except Exception, e:
module.fail_json(msg='%s' % e.message)
module.exit_json(changed=changed, autoscale_policy=rax_to_dict(policy))
def main():
argument_spec = rax_argument_spec()
argument_spec.update(
dict(
at=dict(),
change=dict(type='int'),
cron=dict(),
cooldown=dict(type='int', default=300),
desired_capacity=dict(type='int'),
is_percent=dict(type='bool', default=False),
name=dict(required=True),
policy_type=dict(required=True, choices=['webhook', 'schedule']),
scaling_group=dict(required=True),
state=dict(default='present', choices=['present', 'absent']),
)
)
module = AnsibleModule(
argument_spec=argument_spec,
required_together=rax_required_together(),
mutually_exclusive=[
['cron', 'at'],
['change', 'desired_capacity'],
]
)
if not HAS_PYRAX:
module.fail_json(msg='pyrax is required for this module')
at = module.params.get('at')
change = module.params.get('change')
cron = module.params.get('cron')
cooldown = module.params.get('cooldown')
desired_capacity = module.params.get('desired_capacity')
is_percent = module.params.get('is_percent')
name = module.params.get('name')
policy_type = module.params.get('policy_type')
scaling_group = module.params.get('scaling_group')
state = module.params.get('state')
if (at or cron) and policy_type == 'webhook':
module.fail_json(msg='policy_type=schedule is required for a time '
'based policy')
setup_rax_module(module, pyrax)
rax_asp(module, at=at, change=change, cron=cron, cooldown=cooldown,
desired_capacity=desired_capacity, is_percent=is_percent,
name=name, policy_type=policy_type, scaling_group=scaling_group,
state=state)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.rax import *
# invoke the module
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
961,
365,
282,
29970,
2594,
10098,
2488,
370,
642,
859,
12,
652,
16879,
199,
3,
282,
3794,
7956,
16180,
315,
3242,
14,
1208,
14,
578,
63,
4757,
63,
18047,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
16937,
63,
12153,
63,
3185,
199,
3612,
63,
1802,
26,
4688,
711,
5434,
32679,
8142,
9195,
3467,
17619,
316,
18141,
199,
1802,
26,
272,
446,
4688,
711,
5434,
32679,
8142,
9195,
3467,
17619,
316,
18141,
199,
1023,
63,
3270,
26,
413,
14,
23,
199,
1419,
26,
523,
737,
26,
272,
1369,
26,
489,
446,
710,
12174,
900,
1380,
642,
4592,
911,
506,
7934,
14,
710,
900,
1471,
506,
267,
7871,
7182,
370,
445,
8,
18322,
13,
3218,
13,
617,
7,
52,
7,
10213,
26,
596,
26,
385,
14,
2300,
51,
9,
4066,
465,
267,
445,
8,
6965,
13,
1717,
13,
1167,
52,
2036,
26,
1780,
26,
2036,
58,
9,
523,
1570,
26,
272,
1369,
26,
489,
446,
710,
1570,
12,
1902,
465,
282,
1329,
402,
8037,
503,
465,
282,
16327,
12,
370,
1852,
267,
315,
314,
13690,
1572,
14,
982,
642,
365,
282,
16327,
12,
1265,
1471,
663,
267,
473,
8,
374,
63,
7045,
9,
370,
445,
8,
2052,
9,
2597,
14,
523,
19818,
26,
272,
1369,
26,
489,
446,
710,
900,
1380,
314,
4592,
911,
506,
7934,
12,
465,
282,
19818,
2397,
14,
2104,
267,
2893,
12,
340,
642,
365,
2725,
365,
663,
370,
445,
8,
17,
378,
627,
627,
24104,
523,
512,
27898,
26,
272,
1369,
26,
489,
446,
710,
6247,
402,
900,
12,
315,
4696,
12,
626,
1471,
986,
2544,
1263,
13690,
883,
267,
4781,
2410,
314,
4136,
13690,
14,
9498,
506,
376,
3000,
3382,
378,
436,
267,
31200,
334,
1194,
394,
2393,
680,
523,
6387,
63,
10457,
26,
272,
1369,
26,
489,
446,
710,
6387,
1654,
14893,
402,
314,
13690,
314,
1572,
27,
626,
365,
12,
4212,
267,
5002,
8037,
1077,
506,
315,
314,
13690,
1572,
14,
523,
365,
63,
7045,
26,
272,
1369,
26,
489,
446,
7480,
314,
574,
315,
473,
8,
1461,
9,
365,
282,
8878,
574,
272,
849,
26,
3055,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
370,
8120,
314,
4592,
272,
1415,
26,
2549,
523,
4592,
63,
466,
26,
272,
1369,
26,
489,
446,
710,
730,
402,
4592,
626,
911,
506,
7934,
367,
314,
1453,
4683,
14,
272,
3415,
26,
489,
446,
30053,
489,
446,
8732,
272,
1415,
26,
2549,
523,
13690,
63,
923,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
13690,
1572,
626,
642,
4592,
911,
506,
3483,
370,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
272,
849,
26,
3451,
199,
2502,
26,
31653,
603,
28124,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
199,
2344,
199,
199,
8918,
275,
1449,
199,
2595,
199,
13,
7057,
26,
11667,
523,
13082,
63,
5047,
26,
3055,
523,
1950,
26,
2257,
523,
6527,
26,
272,
446,
16937,
63,
12153,
63,
3185,
26,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
30502,
267,
737,
26,
283,
6965,
13,
1717,
13,
1167,
52,
2036,
26,
1780,
26,
2036,
58,
7,
267,
1570,
26,
5661,
267,
512,
27898,
26,
9601,
267,
365,
63,
7045,
26,
2549,
267,
536,
26,
437,
4254,
1379,
18141,
446,
737,
267,
4592,
63,
466,
26,
8732,
267,
13690,
63,
923,
26,
437,
4254,
1379,
489,
2274,
26,
465,
1190,
63,
292,
339,
446,
16937,
63,
12153,
63,
3185,
26,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
30502,
267,
19818,
26,
283,
17,
378,
627,
627,
627,
7,
267,
1570,
26,
5661,
267,
512,
27898,
26,
9601,
267,
365,
63,
7045,
26,
2549,
267,
536,
26,
437,
4254,
1379,
18141,
446,
19818,
267,
4592,
63,
466,
26,
8732,
267,
13690,
63,
923,
26,
437,
4254,
1379,
489,
2274,
26,
465,
80,
63,
14829,
339,
446,
16937,
63,
12153,
63,
3185,
26,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
30502,
267,
512,
27898,
26,
9601,
267,
6387,
63,
10457,
26,
959,
267,
536,
26,
437,
4254,
1379,
18141,
446,
30053,
267,
4592,
63,
466,
26,
30053,
267,
13690,
63,
923,
26,
437,
4254,
1379,
489,
2274,
26,
465,
80,
63,
22944,
199,
2344,
199,
199,
893,
26,
272,
492,
23944,
272,
7509,
63,
4521,
2847,
56,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
2847,
56,
275,
756,
421,
199,
318,
16937,
63,
20222,
8,
578,
12,
737,
29,
403,
12,
1570,
29,
16,
12,
19818,
29,
403,
12,
512,
27898,
29,
5863,
12,
288,
6387,
63,
10457,
29,
16,
12,
365,
63,
7045,
29,
797,
12,
536,
29,
403,
12,
288,
4592,
63,
466,
29,
403,
12,
13690,
63,
923,
29,
403,
12,
1174,
534,
1881,
735,
272,
2896,
275,
756,
339,
10576,
275,
23944,
14,
29906,
272,
340,
440,
10576,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
4276,
370,
17321,
1890,
14,
961,
283,
2490,
283,
32251,
9126,
376,
3866,
4897,
503,
376,
283,
2490,
283,
15448,
590,
17094,
1759,
4897,
536,
2659,
339,
862,
26,
267,
11134,
8,
12153,
63,
923,
9,
272,
871,
1722
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
961,
365,
282,
29970,
2594,
10098,
2488,
370,
642,
859,
12,
652,
16879,
199,
3,
282,
3794,
7956,
16180,
315,
3242,
14,
1208,
14,
578,
63,
4757,
63,
18047,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
16937,
63,
12153,
63,
3185,
199,
3612,
63,
1802,
26,
4688,
711,
5434,
32679,
8142,
9195,
3467,
17619,
316,
18141,
199,
1802,
26,
272,
446,
4688,
711,
5434,
32679,
8142,
9195,
3467,
17619,
316,
18141,
199,
1023,
63,
3270,
26,
413,
14,
23,
199,
1419,
26,
523,
737,
26,
272,
1369,
26,
489,
446,
710,
12174,
900,
1380,
642,
4592,
911,
506,
7934,
14,
710,
900,
1471,
506,
267,
7871,
7182,
370,
445,
8,
18322,
13,
3218,
13,
617,
7,
52,
7,
10213,
26,
596,
26,
385,
14,
2300,
51,
9,
4066,
465,
267,
445,
8,
6965,
13,
1717,
13,
1167,
52,
2036,
26,
1780,
26,
2036,
58,
9,
523,
1570,
26,
272,
1369,
26,
489,
446,
710,
1570,
12,
1902,
465,
282,
1329,
402,
8037,
503,
465,
282,
16327,
12,
370,
1852,
267,
315,
314,
13690,
1572,
14,
982,
642,
365,
282,
16327,
12,
1265,
1471,
663,
267,
473,
8,
374,
63,
7045,
9,
370,
445,
8,
2052,
9,
2597,
14,
523,
19818,
26,
272,
1369,
26,
489,
446,
710,
900,
1380,
314,
4592,
911,
506,
7934,
12,
465,
282,
19818,
2397,
14,
2104,
267,
2893,
12,
340,
642,
365,
2725,
365,
663,
370,
445,
8,
17,
378,
627,
627,
24104,
523,
512,
27898,
26,
272,
1369,
26,
489,
446,
710,
6247,
402,
900,
12,
315,
4696,
12,
626,
1471,
986,
2544,
1263,
13690,
883,
267,
4781,
2410,
314,
4136,
13690,
14,
9498,
506,
376,
3000,
3382,
378,
436,
267,
31200,
334,
1194,
394,
2393,
680,
523,
6387,
63,
10457,
26,
272,
1369,
26,
489,
446,
710,
6387,
1654,
14893,
402,
314,
13690,
314,
1572,
27,
626,
365,
12,
4212,
267,
5002,
8037,
1077,
506,
315,
314,
13690,
1572,
14,
523,
365,
63,
7045,
26,
272,
1369,
26,
489,
446,
7480,
314,
574,
315,
473,
8,
1461,
9,
365,
282,
8878,
574,
272,
849,
26,
3055,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
370,
8120,
314,
4592,
272,
1415,
26,
2549,
523,
4592,
63,
466,
26,
272,
1369,
26,
489,
446,
710,
730,
402,
4592,
626,
911,
506,
7934,
367,
314,
1453,
4683,
14,
272,
3415,
26,
489,
446,
30053,
489,
446,
8732,
272,
1415,
26,
2549,
523,
13690,
63,
923,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
13690,
1572,
626,
642,
4592,
911,
506,
3483,
370,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
272,
849,
26,
3451,
199,
2502,
26,
31653,
603,
28124,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
199,
2344,
199,
199,
8918,
275,
1449,
199,
2595,
199,
13,
7057,
26,
11667,
523,
13082,
63,
5047,
26,
3055,
523,
1950,
26,
2257,
523,
6527,
26,
272,
446,
16937,
63,
12153,
63,
3185,
26,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
30502,
267,
737,
26,
283,
6965,
13,
1717,
13,
1167,
52,
2036,
26,
1780,
26,
2036,
58,
7,
267,
1570,
26,
5661,
267,
512,
27898,
26,
9601,
267,
365,
63,
7045,
26,
2549,
267,
536,
26,
437,
4254,
1379,
18141,
446,
737,
267,
4592,
63,
466,
26,
8732,
267,
13690,
63,
923,
26,
437,
4254,
1379,
489,
2274,
26,
465,
1190,
63,
292,
339,
446,
16937,
63,
12153,
63,
3185,
26,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
30502,
267,
19818,
26,
283,
17,
378,
627,
627,
627,
7,
267,
1570,
26,
5661,
267,
512,
27898,
26,
9601,
267,
365,
63,
7045,
26,
2549,
267,
536,
26,
437,
4254,
1379,
18141,
446,
19818,
267,
4592,
63,
466,
26,
8732,
267,
13690,
63,
923,
26,
437,
4254,
1379,
489,
2274,
26,
465,
80,
63,
14829,
339,
446,
16937,
63,
12153,
63,
3185,
26,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
30502,
267,
512,
27898,
26,
9601,
267,
6387,
63,
10457,
26,
959,
267,
536,
26,
437,
4254,
1379,
18141,
446,
30053,
267,
4592,
63,
466,
26,
30053,
267,
13690,
63,
923,
26,
437,
4254,
1379,
489,
2274,
26,
465,
80,
63,
22944,
199,
2344,
199,
199,
893,
26,
272,
492,
23944,
272,
7509,
63,
4521,
2847,
56,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
2847,
56,
275,
756,
421,
199,
318,
16937,
63,
20222,
8,
578,
12,
737,
29,
403,
12,
1570,
29,
16,
12,
19818,
29,
403,
12,
512,
27898,
29,
5863,
12,
288,
6387,
63,
10457,
29,
16,
12,
365,
63,
7045,
29,
797,
12,
536,
29,
403,
12,
288,
4592,
63,
466,
29,
403,
12,
13690,
63,
923,
29,
403,
12,
1174,
534,
1881,
735,
272,
2896,
275,
756,
339,
10576,
275,
23944,
14,
29906,
272,
340,
440,
10576,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
4276,
370,
17321,
1890,
14,
961,
283,
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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
] |
jotes/ansible
|
v2/test/parsing/test_data_loader.py
|
13
|
2219
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from yaml.scanner import ScannerError
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch
from ansible.errors import AnsibleParserError
from ansible.parsing import DataLoader
from ansible.parsing.yaml.objects import AnsibleMapping
class TestDataLoader(unittest.TestCase):
def setUp(self):
# FIXME: need to add tests that utilize vault_password
self._loader = DataLoader()
def tearDown(self):
pass
@patch.object(DataLoader, '_get_file_contents')
def test_parse_json_from_file(self, mock_def):
mock_def.return_value = ("""{"a": 1, "b": 2, "c": 3}""", True)
output = self._loader.load_from_file('dummy_json.txt')
self.assertEqual(output, dict(a=1,b=2,c=3))
@patch.object(DataLoader, '_get_file_contents')
def test_parse_yaml_from_file(self, mock_def):
mock_def.return_value = ("""
a: 1
b: 2
c: 3
""", True)
output = self._loader.load_from_file('dummy_yaml.txt')
self.assertEqual(output, dict(a=1,b=2,c=3))
@patch.object(DataLoader, '_get_file_contents')
def test_parse_fail_from_file(self, mock_def):
mock_def.return_value = ("""
TEXT:
***
NOT VALID
""", True)
self.assertRaises(AnsibleParserError, self._loader.load_from_file, 'dummy_yaml_bad.txt')
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
8864,
14,
16378,
492,
28628,
547,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
199,
504,
3242,
14,
2550,
492,
31775,
199,
199,
504,
3242,
14,
11059,
492,
3918,
5455,
199,
504,
3242,
14,
11059,
14,
5963,
14,
1462,
492,
2622,
7674,
199,
199,
533,
1379,
1451,
5455,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
327,
7600,
26,
1929,
370,
1050,
2295,
626,
7678,
13559,
12738,
63,
2060,
267,
291,
423,
3422,
275,
3918,
5455,
342,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
768,
2068,
14,
785,
8,
1451,
5455,
12,
2513,
362,
63,
493,
63,
4407,
358,
272,
347,
511,
63,
1122,
63,
1001,
63,
504,
63,
493,
8,
277,
12,
1683,
63,
318,
304,
267,
1683,
63,
318,
14,
1107,
63,
585,
275,
334,
624,
6641,
65,
582,
413,
12,
298,
66,
582,
499,
12,
298,
67,
582,
650,
93,
7208,
715,
9,
267,
1072,
275,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
360,
5869,
63,
1001,
14,
2424,
358,
267,
291,
14,
629,
8,
1199,
12,
1211,
8,
65,
29,
17,
12,
66,
29,
18,
12,
67,
29,
19,
430,
339,
768,
2068,
14,
785,
8,
1451,
5455,
12,
2513,
362,
63,
493,
63,
4407,
358,
272,
347,
511,
63,
1122,
63,
5963,
63,
504,
63,
493,
8,
277,
12,
1683,
63,
318,
304,
267,
1683,
63,
318,
14,
1107,
63,
585,
275,
334,
624,
267,
282,
26,
413,
267,
330,
26,
499,
267,
286,
26,
650,
267,
10327,
715,
9,
267,
1072,
275,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
360,
5869,
63,
5963,
14,
2424,
358,
267,
291,
14,
629,
8,
1199,
12,
1211,
8,
65,
29,
17,
12,
66,
29,
18,
12,
67,
29,
19,
430,
339,
768,
2068,
14,
785,
8,
1451,
5455,
12,
2513,
362,
63,
493,
63,
4407,
358,
272,
347,
511,
63,
1122,
63,
1633,
63,
504,
63,
493,
8,
277,
12,
1683,
63,
318,
304,
267,
1683,
63,
318,
14,
1107,
63,
585,
275,
334,
624,
267,
11951,
26,
288,
19688,
2049,
2845,
22049,
267,
10327,
715,
9,
267,
291,
14,
1855,
8,
10047,
21811,
12,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
12,
283,
5869,
63,
5963,
63,
4087,
14,
2424,
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
] |
[
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
8864,
14,
16378,
492,
28628,
547,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
199,
504,
3242,
14,
2550,
492,
31775,
199,
199,
504,
3242,
14,
11059,
492,
3918,
5455,
199,
504,
3242,
14,
11059,
14,
5963,
14,
1462,
492,
2622,
7674,
199,
199,
533,
1379,
1451,
5455,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
327,
7600,
26,
1929,
370,
1050,
2295,
626,
7678,
13559,
12738,
63,
2060,
267,
291,
423,
3422,
275,
3918,
5455,
342,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
768,
2068,
14,
785,
8,
1451,
5455,
12,
2513,
362,
63,
493,
63,
4407,
358,
272,
347,
511,
63,
1122,
63,
1001,
63,
504,
63,
493,
8,
277,
12,
1683,
63,
318,
304,
267,
1683,
63,
318,
14,
1107,
63,
585,
275,
334,
624,
6641,
65,
582,
413,
12,
298,
66,
582,
499,
12,
298,
67,
582,
650,
93,
7208,
715,
9,
267,
1072,
275,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
360,
5869,
63,
1001,
14,
2424,
358,
267,
291,
14,
629,
8,
1199,
12,
1211,
8,
65,
29,
17,
12,
66,
29,
18,
12,
67,
29,
19,
430,
339,
768,
2068,
14,
785,
8,
1451,
5455,
12,
2513,
362,
63,
493,
63,
4407,
358,
272,
347,
511,
63,
1122,
63,
5963,
63,
504,
63,
493,
8,
277,
12,
1683,
63,
318,
304,
267,
1683,
63,
318,
14,
1107,
63,
585,
275,
334,
624,
267,
282,
26,
413,
267,
330,
26,
499,
267,
286,
26,
650,
267,
10327,
715,
9,
267,
1072,
275,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
360,
5869,
63,
5963,
14,
2424,
358,
267,
291,
14,
629,
8,
1199,
12,
1211,
8,
65,
29,
17,
12,
66,
29,
18,
12,
67,
29,
19,
430,
339,
768,
2068,
14,
785,
8,
1451,
5455,
12,
2513,
362,
63,
493,
63,
4407,
358,
272,
347,
511,
63,
1122,
63,
1633,
63,
504,
63,
493,
8,
277,
12,
1683,
63,
318,
304,
267,
1683,
63,
318,
14,
1107,
63,
585,
275,
334,
624,
267,
11951,
26,
288,
19688,
2049,
2845,
22049,
267,
10327,
715,
9,
267,
291,
14,
1855,
8,
10047,
21811,
12,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
12,
283,
5869,
63,
5963,
63,
4087,
14,
2424,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ntt-sic/glance
|
glance/image_cache/drivers/sqlite.py
|
4
|
16418
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack LLC.
# 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.
"""
Cache driver that uses SQLite to store information about cached images
"""
from __future__ import absolute_import
from contextlib import contextmanager
import os
import stat
import time
from eventlet import sleep, timeout
from oslo.config import cfg
import sqlite3
from glance.common import exception
from glance.image_cache.drivers import base
import glance.openstack.common.log as logging
LOG = logging.getLogger(__name__)
sqlite_opts = [
cfg.StrOpt('image_cache_sqlite_db', default='cache.db',
help=_('The path to the sqlite file database that will be '
'used for image cache management.')),
]
CONF = cfg.CONF
CONF.register_opts(sqlite_opts)
DEFAULT_SQL_CALL_TIMEOUT = 2
class SqliteConnection(sqlite3.Connection):
"""
SQLite DB Connection handler that plays well with eventlet,
slightly modified from Swift's similar code.
"""
def __init__(self, *args, **kwargs):
self.timeout_seconds = kwargs.get('timeout', DEFAULT_SQL_CALL_TIMEOUT)
kwargs['timeout'] = 0
sqlite3.Connection.__init__(self, *args, **kwargs)
def _timeout(self, call):
with timeout.Timeout(self.timeout_seconds):
while True:
try:
return call()
except sqlite3.OperationalError as e:
if 'locked' not in str(e):
raise
sleep(0.05)
def execute(self, *args, **kwargs):
return self._timeout(lambda: sqlite3.Connection.execute(
self, *args, **kwargs))
def commit(self):
return self._timeout(lambda: sqlite3.Connection.commit(self))
def dict_factory(cur, row):
return dict(
((col[0], row[idx]) for idx, col in enumerate(cur.description)))
class Driver(base.Driver):
"""
Cache driver that uses xattr file tags and requires a filesystem
that has atimes set.
"""
def configure(self):
"""
Configure the driver to use the stored configuration options
Any store that needs special configuration should implement
this method. If the store was not able to successfully configure
itself, it should raise `exception.BadDriverConfiguration`
"""
super(Driver, self).configure()
# Create the SQLite database that will hold our cache attributes
self.initialize_db()
def initialize_db(self):
db = CONF.image_cache_sqlite_db
self.db_path = os.path.join(self.base_dir, db)
try:
conn = sqlite3.connect(self.db_path, check_same_thread=False,
factory=SqliteConnection)
conn.executescript("""
CREATE TABLE IF NOT EXISTS cached_images (
image_id TEXT PRIMARY KEY,
last_accessed REAL DEFAULT 0.0,
last_modified REAL DEFAULT 0.0,
size INTEGER DEFAULT 0,
hits INTEGER DEFAULT 0,
checksum TEXT
);
""")
conn.close()
except sqlite3.DatabaseError as e:
msg = _("Failed to initialize the image cache database. "
"Got error: %s") % e
LOG.error(msg)
raise exception.BadDriverConfiguration(driver_name='sqlite',
reason=msg)
def get_cache_size(self):
"""
Returns the total size in bytes of the image cache.
"""
sizes = []
for path in self.get_cache_files(self.base_dir):
if path == self.db_path:
continue
file_info = os.stat(path)
sizes.append(file_info[stat.ST_SIZE])
return sum(sizes)
def get_hit_count(self, image_id):
"""
Return the number of hits that an image has.
:param image_id: Opaque image identifier
"""
if not self.is_cached(image_id):
return 0
hits = 0
with self.get_db() as db:
cur = db.execute("""SELECT hits FROM cached_images
WHERE image_id = ?""",
(image_id,))
hits = cur.fetchone()[0]
return hits
def get_cached_images(self):
"""
Returns a list of records about cached images.
"""
LOG.debug(_("Gathering cached image entries."))
with self.get_db() as db:
cur = db.execute("""SELECT
image_id, hits, last_accessed, last_modified, size
FROM cached_images
ORDER BY image_id""")
cur.row_factory = dict_factory
return [r for r in cur]
def is_cached(self, image_id):
"""
Returns True if the image with the supplied ID has its image
file cached.
:param image_id: Image ID
"""
return os.path.exists(self.get_image_filepath(image_id))
def is_cacheable(self, image_id):
"""
Returns True if the image with the supplied ID can have its
image file cached, False otherwise.
:param image_id: Image ID
"""
# Make sure we're not already cached or caching the image
return not (self.is_cached(image_id) or
self.is_being_cached(image_id))
def is_being_cached(self, image_id):
"""
Returns True if the image with supplied id is currently
in the process of having its image file cached.
:param image_id: Image ID
"""
path = self.get_image_filepath(image_id, 'incomplete')
return os.path.exists(path)
def is_queued(self, image_id):
"""
Returns True if the image identifier is in our cache queue.
:param image_id: Image ID
"""
path = self.get_image_filepath(image_id, 'queue')
return os.path.exists(path)
def delete_all_cached_images(self):
"""
Removes all cached image files and any attributes about the images
"""
deleted = 0
with self.get_db() as db:
for path in self.get_cache_files(self.base_dir):
delete_cached_file(path)
deleted += 1
db.execute("""DELETE FROM cached_images""")
db.commit()
return deleted
def delete_cached_image(self, image_id):
"""
Removes a specific cached image file and any attributes about the image
:param image_id: Image ID
"""
path = self.get_image_filepath(image_id)
with self.get_db() as db:
delete_cached_file(path)
db.execute("""DELETE FROM cached_images WHERE image_id = ?""",
(image_id, ))
db.commit()
def delete_all_queued_images(self):
"""
Removes all queued image files and any attributes about the images
"""
files = [f for f in self.get_cache_files(self.queue_dir)]
for file in files:
os.unlink(file)
return len(files)
def delete_queued_image(self, image_id):
"""
Removes a specific queued image file and any attributes about the image
:param image_id: Image ID
"""
path = self.get_image_filepath(image_id, 'queue')
if os.path.exists(path):
os.unlink(path)
def clean(self, stall_time=None):
"""
Delete any image files in the invalid directory and any
files in the incomplete directory that are older than a
configurable amount of time.
"""
self.delete_invalid_files()
if stall_time is None:
stall_time = CONF.image_cache_stall_time
now = time.time()
older_than = now - stall_time
self.delete_stalled_files(older_than)
def get_least_recently_accessed(self):
"""
Return a tuple containing the image_id and size of the least recently
accessed cached file, or None if no cached files.
"""
with self.get_db() as db:
cur = db.execute("""SELECT image_id FROM cached_images
ORDER BY last_accessed LIMIT 1""")
try:
image_id = cur.fetchone()[0]
except TypeError:
# There are no more cached images
return None
path = self.get_image_filepath(image_id)
file_info = os.stat(path)
return image_id, file_info[stat.ST_SIZE]
@contextmanager
def open_for_write(self, image_id):
"""
Open a file for writing the image file for an image
with supplied identifier.
:param image_id: Image ID
"""
incomplete_path = self.get_image_filepath(image_id, 'incomplete')
def commit():
with self.get_db() as db:
final_path = self.get_image_filepath(image_id)
LOG.debug(_("Fetch finished, moving "
"'%(incomplete_path)s' to '%(final_path)s'"),
dict(incomplete_path=incomplete_path,
final_path=final_path))
os.rename(incomplete_path, final_path)
# Make sure that we "pop" the image from the queue...
if self.is_queued(image_id):
os.unlink(self.get_image_filepath(image_id, 'queue'))
filesize = os.path.getsize(final_path)
now = time.time()
db.execute("""INSERT INTO cached_images
(image_id, last_accessed, last_modified, hits, size)
VALUES (?, 0, ?, 0, ?)""",
(image_id, now, filesize))
db.commit()
def rollback(e):
with self.get_db() as db:
if os.path.exists(incomplete_path):
invalid_path = self.get_image_filepath(image_id, 'invalid')
LOG.debug(_("Fetch of cache file failed (%(e)s), rolling "
"back by moving '%(incomplete_path)s' to "
"'%(invalid_path)s'") % locals())
os.rename(incomplete_path, invalid_path)
db.execute("""DELETE FROM cached_images
WHERE image_id = ?""", (image_id, ))
db.commit()
try:
with open(incomplete_path, 'wb') as cache_file:
yield cache_file
except Exception as e:
rollback(e)
raise
else:
commit()
finally:
# if the generator filling the cache file neither raises an
# exception, nor completes fetching all data, neither rollback
# nor commit will have been called, so the incomplete file
# will persist - in that case remove it as it is unusable
# example: ^c from client fetch
if os.path.exists(incomplete_path):
rollback('incomplete fetch')
@contextmanager
def open_for_read(self, image_id):
"""
Open and yield file for reading the image file for an image
with supplied identifier.
:param image_id: Image ID
"""
path = self.get_image_filepath(image_id)
with open(path, 'rb') as cache_file:
yield cache_file
now = time.time()
with self.get_db() as db:
db.execute("""UPDATE cached_images
SET hits = hits + 1, last_accessed = ?
WHERE image_id = ?""",
(now, image_id))
db.commit()
@contextmanager
def get_db(self):
"""
Returns a context manager that produces a database connection that
self-closes and calls rollback if an error occurs while using the
database connection
"""
conn = sqlite3.connect(self.db_path, check_same_thread=False,
factory=SqliteConnection)
conn.row_factory = sqlite3.Row
conn.text_factory = str
conn.execute('PRAGMA synchronous = NORMAL')
conn.execute('PRAGMA count_changes = OFF')
conn.execute('PRAGMA temp_store = MEMORY')
try:
yield conn
except sqlite3.DatabaseError as e:
msg = _("Error executing SQLite call. Got error: %s") % e
LOG.error(msg)
conn.rollback()
finally:
conn.close()
def queue_image(self, image_id):
"""
This adds a image to be cache to the queue.
If the image already exists in the queue or has already been
cached, we return False, True otherwise
:param image_id: Image ID
"""
if self.is_cached(image_id):
msg = _("Not queueing image '%s'. Already cached.") % image_id
LOG.warn(msg)
return False
if self.is_being_cached(image_id):
msg = _("Not queueing image '%s'. Already being "
"written to cache") % image_id
LOG.warn(msg)
return False
if self.is_queued(image_id):
msg = _("Not queueing image '%s'. Already queued.") % image_id
LOG.warn(msg)
return False
path = self.get_image_filepath(image_id, 'queue')
# Touch the file to add it to the queue
with open(path, "w") as f:
pass
return True
def delete_invalid_files(self):
"""
Removes any invalid cache entries
"""
for path in self.get_cache_files(self.invalid_dir):
os.unlink(path)
LOG.info(_("Removed invalid cache file %s"), path)
def delete_stalled_files(self, older_than):
"""
Removes any incomplete cache entries older than a
supplied modified time.
:param older_than: Files written to on or before this timestemp
will be deleted.
"""
for path in self.get_cache_files(self.incomplete_dir):
if os.path.getmtime(path) < older_than:
try:
os.unlink(path)
LOG.info(_("Removed stalled cache file %s"), path)
except Exception as e:
msg = (_("Failed to delete file %(path)s. "
"Got error: %(e)s") %
dict(path=path, e=e))
LOG.warn(msg)
def get_queued_images(self):
"""
Returns a list of image IDs that are in the queue. The
list should be sorted by the time the image ID was inserted
into the queue.
"""
files = [f for f in self.get_cache_files(self.queue_dir)]
items = []
for path in files:
mtime = os.path.getmtime(path)
items.append((mtime, os.path.basename(path)))
items.sort()
return [image_id for (mtime, image_id) in items]
def get_cache_files(self, basepath):
"""
Returns cache files in the supplied directory
:param basepath: Directory to look in for cache files
"""
for fname in os.listdir(basepath):
path = os.path.join(basepath, fname)
if path != self.db_path and os.path.isfile(path):
yield path
def delete_cached_file(path):
if os.path.exists(path):
LOG.debug(_("Deleting image cache file '%s'"), path)
os.unlink(path)
else:
LOG.warn(_("Cached image file '%s' doesn't exist, unable to"
" delete"), path)
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
14260,
20376,
14,
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,
624,
199,
4437,
5253,
626,
4440,
19245,
370,
3877,
2556,
3595,
6328,
5935,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
15502,
492,
27608,
199,
646,
747,
199,
646,
5672,
199,
646,
900,
199,
199,
504,
21819,
492,
9435,
12,
2653,
199,
504,
11258,
14,
888,
492,
4810,
199,
646,
11723,
19,
199,
199,
504,
21785,
14,
2330,
492,
1919,
199,
504,
21785,
14,
1569,
63,
1637,
14,
13337,
492,
1300,
199,
646,
21785,
14,
8512,
14,
2330,
14,
793,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
10659,
63,
3291,
275,
359,
272,
4810,
14,
19340,
360,
1569,
63,
1637,
63,
10659,
63,
697,
297,
849,
534,
1637,
14,
697,
297,
2049,
1720,
12397,
1918,
931,
370,
314,
11723,
570,
3050,
626,
911,
506,
283,
1993,
283,
2972,
367,
1834,
2581,
10041,
2659,
395,
199,
61,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
10659,
63,
3291,
9,
199,
199,
3472,
63,
4657,
63,
11978,
63,
8899,
275,
499,
421,
199,
533,
428,
29498,
3225,
8,
10659,
19,
14,
3225,
304,
339,
408,
272,
19245,
6249,
8113,
3016,
626,
299,
9316,
5521,
543,
21819,
12,
272,
18023,
6042,
687,
16666,
2949,
1159,
8545,
1233,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2593,
63,
4515,
275,
2074,
14,
362,
360,
2593,
297,
6186,
63,
4657,
63,
11978,
63,
8899,
9,
267,
2074,
459,
2593,
418,
275,
378,
267,
11723,
19,
14,
3225,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
485,
2593,
8,
277,
12,
1240,
304,
267,
543,
2653,
14,
6372,
8,
277,
14,
2593,
63,
4515,
304,
288,
1830,
715,
26,
355,
862,
26,
490,
372,
1240,
342,
355,
871,
11723,
19,
14,
31998,
547,
465,
325,
26,
490,
340,
283,
9325,
7,
440,
315,
620,
8,
69,
304,
717,
746,
355,
9435,
8,
16,
14,
1717,
9,
339,
347,
5341,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
423,
2593,
8,
2734,
26,
11723,
19,
14,
3225,
14,
2526,
8,
3147,
291,
12,
627,
589,
12,
1011,
958,
430,
339,
347,
5532,
8,
277,
304,
267,
372,
291,
423,
2593,
8,
2734,
26,
11723,
19,
14,
3225,
14,
3543,
8,
277,
430,
421,
199,
318,
1211,
63,
3702,
8,
895,
12,
1962,
304,
272,
372,
1211,
8,
267,
3666,
761,
59,
16,
467,
1962,
59,
2996,
566,
367,
4280,
12,
1048,
315,
3874,
8,
895,
14,
1802,
1724,
421,
199,
533,
19447,
8,
1095,
14,
6158,
304,
339,
408,
272,
11977,
5253,
626,
4440,
671,
962,
570,
3762,
436,
5074,
282,
10036,
272,
626,
965,
282,
4508,
663,
14,
272,
408,
339,
347,
7908,
8,
277,
304,
267,
408,
267,
15453,
314,
5253,
370,
675,
314,
5489,
2897,
1511,
267,
6184,
3877,
626,
4839,
4539,
2897,
1077,
5669,
267,
642,
1083,
14,
982,
314,
3877,
1990,
440,
7688,
370,
8792,
7908,
267,
6337,
12,
652,
1077,
746,
658,
1971,
14,
5725,
6158,
5688,
64,
267,
408,
267,
1613,
8,
6158,
12,
291,
680,
6472,
342,
398,
327,
2790,
314,
19245,
3050,
626,
911,
10266,
4154,
2581,
3004,
267,
291,
14,
8489,
63,
697,
342,
339,
347,
8265,
63,
697,
8,
277,
304,
267,
1592,
275,
6392,
14,
1569,
63,
1637,
63,
10659,
63,
697,
267,
291,
14,
697,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1095,
63,
694,
12,
1592,
9,
267,
862,
26,
288,
2557,
275,
11723,
19,
14,
2242,
8,
277,
14,
697,
63,
515,
12,
1104,
63,
7191,
63,
2671,
29,
797,
12,
3521,
6434,
29,
24614,
5333,
3225,
9,
288,
2557,
14,
2526,
1579,
4852,
355,
16999,
9934,
8036,
2845,
23875,
6328,
63,
4782,
334,
490,
1834,
63,
344,
11951,
19770,
9301,
12,
490,
2061,
63,
29433,
5363,
748,
6186,
378,
14,
16,
12,
490,
2061,
63,
5540,
5363,
748,
6186,
378,
14,
16,
12,
490,
1568,
17086,
6186,
378,
12,
490,
19745,
17086,
6186,
378,
12,
490,
9040,
11951,
355,
20682,
288,
7857,
288,
2557,
14,
1600,
342,
267,
871,
11723,
19,
14,
25198,
465,
325,
26,
288,
1499,
275,
3824,
4276,
370,
8265,
314,
1834,
2581,
3050,
14,
298,
490,
298,
13662,
1125,
26,
450,
83,
531,
450,
325,
288,
5051,
14,
705,
8,
1328,
9,
288,
746,
1919,
14,
5725,
6158,
5688,
8,
3090,
63,
354,
534,
10659,
297,
8962,
4499,
29,
1328,
9,
339,
347,
664,
63,
1637,
63,
890,
8,
277,
304,
267,
408,
267,
1803,
314,
3141,
1568,
315,
2783,
402,
314,
1834,
2581,
14,
267,
408,
267,
10627,
275,
942,
267,
367,
931,
315,
291,
14,
362,
63,
1637,
63,
1725,
8,
277,
14,
1095,
63,
694,
304,
288,
340,
931,
508,
291,
14,
697,
63,
515,
26,
355,
1980,
288,
570,
63,
815,
275,
747,
14,
3736,
8,
515,
9,
288,
10627,
14,
740,
8,
493,
63,
815,
59,
3736,
14,
840,
63,
4305,
566,
267,
372,
3089,
8,
7723,
9,
339,
347,
664,
63,
12948,
63,
835,
8,
277,
12,
1834,
63,
344,
304,
267,
408,
267,
1432
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
14260,
20376,
14,
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,
624,
199,
4437,
5253,
626,
4440,
19245,
370,
3877,
2556,
3595,
6328,
5935,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
15502,
492,
27608,
199,
646,
747,
199,
646,
5672,
199,
646,
900,
199,
199,
504,
21819,
492,
9435,
12,
2653,
199,
504,
11258,
14,
888,
492,
4810,
199,
646,
11723,
19,
199,
199,
504,
21785,
14,
2330,
492,
1919,
199,
504,
21785,
14,
1569,
63,
1637,
14,
13337,
492,
1300,
199,
646,
21785,
14,
8512,
14,
2330,
14,
793,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
10659,
63,
3291,
275,
359,
272,
4810,
14,
19340,
360,
1569,
63,
1637,
63,
10659,
63,
697,
297,
849,
534,
1637,
14,
697,
297,
2049,
1720,
12397,
1918,
931,
370,
314,
11723,
570,
3050,
626,
911,
506,
283,
1993,
283,
2972,
367,
1834,
2581,
10041,
2659,
395,
199,
61,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
10659,
63,
3291,
9,
199,
199,
3472,
63,
4657,
63,
11978,
63,
8899,
275,
499,
421,
199,
533,
428,
29498,
3225,
8,
10659,
19,
14,
3225,
304,
339,
408,
272,
19245,
6249,
8113,
3016,
626,
299,
9316,
5521,
543,
21819,
12,
272,
18023,
6042,
687,
16666,
2949,
1159,
8545,
1233,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
2593,
63,
4515,
275,
2074,
14,
362,
360,
2593,
297,
6186,
63,
4657,
63,
11978,
63,
8899,
9,
267,
2074,
459,
2593,
418,
275,
378,
267,
11723,
19,
14,
3225,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
485,
2593,
8,
277,
12,
1240,
304,
267,
543,
2653,
14,
6372,
8,
277,
14,
2593,
63,
4515,
304,
288,
1830,
715,
26,
355,
862,
26,
490,
372,
1240,
342,
355,
871,
11723,
19,
14,
31998,
547,
465,
325,
26,
490,
340,
283,
9325,
7,
440,
315,
620,
8,
69,
304,
717,
746,
355,
9435,
8,
16,
14,
1717,
9,
339,
347,
5341,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
423,
2593,
8,
2734,
26,
11723,
19,
14,
3225,
14,
2526,
8,
3147,
291,
12,
627,
589,
12,
1011,
958,
430,
339,
347,
5532,
8,
277,
304,
267,
372,
291,
423,
2593,
8,
2734,
26,
11723,
19,
14,
3225,
14,
3543,
8,
277,
430,
421,
199,
318,
1211,
63,
3702,
8,
895,
12,
1962,
304,
272,
372,
1211,
8,
267,
3666,
761,
59,
16,
467,
1962,
59,
2996,
566,
367,
4280,
12,
1048,
315,
3874,
8,
895,
14,
1802,
1724,
421,
199,
533,
19447,
8,
1095,
14,
6158,
304,
339,
408,
272,
11977,
5253,
626,
4440,
671,
962,
570,
3762,
436,
5074,
282,
10036,
272,
626,
965,
282,
4508,
663,
14,
272,
408,
339,
347,
7908,
8,
277,
304,
267,
408,
267,
15453,
314,
5253,
370,
675,
314,
5489,
2897,
1511,
267,
6184,
3877,
626,
4839,
4539,
2897,
1077,
5669,
267,
642,
1083,
14,
982,
314,
3877,
1990,
440,
7688,
370,
8792,
7908,
267,
6337,
12,
652,
1077,
746,
658,
1971,
14,
5725,
6158,
5688,
64,
267,
408,
267,
1613,
8,
6158,
12,
291,
680,
6472,
342,
398,
327,
2790,
314,
19245,
3050,
626,
911,
10266,
4154,
2581,
3004,
267,
291,
14,
8489,
63,
697,
342,
339,
347,
8265,
63,
697,
8,
277,
304,
267,
1592,
275,
6392,
14,
1569,
63,
1637,
63,
10659,
63,
697,
267,
291,
14,
697,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1095,
63,
694,
12,
1592,
9,
267,
862,
26,
288,
2557,
275,
11723,
19,
14,
2242,
8,
277,
14,
697,
63,
515,
12,
1104,
63,
7191,
63,
2671,
29,
797,
12,
3521,
6434,
29,
24614,
5333,
3225,
9,
288,
2557,
14,
2526,
1579,
4852,
355,
16999,
9934,
8036,
2845,
23875,
6328,
63,
4782,
334,
490,
1834,
63,
344,
11951,
19770,
9301,
12,
490,
2061,
63,
29433,
5363,
748,
6186,
378,
14,
16,
12,
490,
2061,
63,
5540,
5363,
748,
6186,
378,
14,
16,
12,
490,
1568,
17086,
6186,
378,
12,
490,
19745,
17086,
6186,
378,
12,
490,
9040,
11951,
355,
20682,
288,
7857,
288,
2557,
14,
1600,
342,
267,
871,
11723,
19,
14,
25198,
465,
325,
26,
288,
1499,
275,
3824,
4276,
370,
8265,
314,
1834,
2581,
3050,
14,
298,
490,
298,
13662,
1125,
26,
450,
83,
531,
450,
325,
288,
5051,
14,
705,
8,
1328,
9,
288,
746,
1919,
14,
5725,
6158,
5688,
8,
3090,
63,
354,
534,
10659,
297,
8962,
4499,
29,
1328,
9,
339,
347,
664,
63,
1637,
63,
890,
8,
277,
304,
267,
408,
267,
1803,
314,
3141,
1568,
315,
2783,
402,
314,
1834,
2581,
14,
267,
408,
267,
10627,
275,
942,
267,
367,
931,
315,
291,
14,
362,
63,
1637,
63,
1725,
8,
277,
14,
1095,
63,
694,
304,
288,
340,
931,
508,
291,
14,
697,
63,
515,
26,
355,
1980,
288,
570,
63,
815,
275,
747,
14,
3736,
8,
515,
9,
288,
10627,
14,
740,
8,
493,
63,
815,
59,
3736,
14,
840,
63,
4305,
566,
267,
372,
3089,
8,
7723,
9,
339,
347,
664,
63,
12948,
63,
835,
8,
277,
12,
1834,
63,
344,
304,
267,
408,
267,
1432,
0
] |
[
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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argparse import ArgumentParser
import json
import os
import re
from jenkins import Jenkins
from jujuci import (
add_credential_args,
get_credentials,
)
from utility import (
find_candidates,
get_candidates_path,
)
def get_args(argv=None):
parser = ArgumentParser()
parser.add_argument(
'root_dir', help='Directory containing releases and candidates dir')
parser.add_argument(
'--all', action='store_true', default=False,
help='Schedule all candidates for client-server testing.')
add_credential_args(parser)
args = parser.parse_args(argv)
return args, get_credentials(args)
def get_releases(root):
release_path = os.path.join(root, 'old-juju')
released_pattern = re.compile('^\d+\.\d+\.\d+[^~]*$')
for entry in os.listdir(release_path):
if not os.path.isdir(os.path.join(release_path, entry)):
continue
if released_pattern.match(entry):
yield entry
def get_candidate_info(candidate_path):
""" Return candidate version and revision build number. """
with open(os.path.join(candidate_path, 'buildvars.json')) as fp:
build_vars = json.load(fp)
return build_vars['version'], build_vars['revision_build']
def calculate_jobs(root, schedule_all=False):
releases = list(get_releases(root))
candidates_path = get_candidates_path(root)
for candidate_path in find_candidates(root, schedule_all):
parent, candidate = os.path.split(candidate_path)
if candidate.startswith('1.26'):
# 1.26 was renamed to 2.0 because it is not compatible with 1.x
continue
if parent != candidates_path:
raise ValueError('Wrong path')
candidate_version, revision_build = get_candidate_info(candidate_path)
for release in releases:
# Releases with the same major number must be compatible.
if release[:2] != candidate[:2]:
continue
for client_os in ('ubuntu', 'osx', 'windows'):
yield {
'old_version': release, # Client
'candidate': candidate_version, # Server
'new_to_old': 'true',
'candidate_path': candidate,
'client_os': client_os,
'revision_build': revision_build,
}
yield {
'old_version': release, # Server
'candidate': candidate_version, # Client
'new_to_old': 'false',
'candidate_path': candidate,
'client_os': client_os,
'revision_build': revision_build,
}
def build_jobs(credentials, root, jobs):
jenkins = Jenkins('http://juju-ci.vapour.ws:8080', *credentials)
os_str = {"ubuntu": "", "osx": "-osx", "windows": "-windows"}
for job in jobs:
jenkins.build_job(
'compatibility-control{}'.format(os_str[job['client_os']]), job)
def main():
args, credentials = get_args()
build_jobs(
credentials, args.root_dir, calculate_jobs(args.root_dir, args.all))
if __name__ == '__main__':
main()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
7534,
492,
27615,
199,
646,
2022,
199,
646,
747,
199,
646,
295,
199,
199,
504,
29537,
492,
32516,
199,
504,
1335,
17189,
85,
559,
492,
334,
272,
1050,
63,
15591,
63,
589,
12,
272,
664,
63,
6942,
12,
272,
776,
199,
504,
11420,
492,
334,
272,
2342,
63,
16389,
12,
272,
664,
63,
16389,
63,
515,
12,
272,
776,
421,
199,
318,
664,
63,
589,
8,
3020,
29,
403,
304,
272,
1798,
275,
27615,
342,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
1231,
63,
694,
297,
1720,
534,
6231,
3035,
19015,
436,
15101,
2935,
358,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
452,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
12,
267,
1720,
534,
15535,
1006,
15101,
367,
1890,
13,
1000,
5343,
2659,
272,
1050,
63,
15591,
63,
589,
8,
2087,
9,
272,
1249,
275,
1798,
14,
1122,
63,
589,
8,
3020,
9,
272,
372,
1249,
12,
664,
63,
6942,
8,
589,
9,
421,
199,
318,
664,
63,
11840,
8,
1231,
304,
272,
4683,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
283,
1753,
13,
74,
17189,
85,
358,
272,
14286,
63,
3401,
275,
295,
14,
2014,
9097,
60,
68,
23294,
68,
23294,
68,
11,
4735,
94,
3672,
9988,
272,
367,
2397,
315,
747,
14,
7374,
8,
3221,
63,
515,
304,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
904,
8,
3221,
63,
515,
12,
2397,
2298,
288,
1980,
267,
340,
14286,
63,
3401,
14,
1431,
8,
2373,
304,
288,
1995,
2397,
421,
199,
318,
664,
63,
9007,
63,
815,
8,
9007,
63,
515,
304,
272,
408,
1432,
7627,
1015,
436,
6974,
1900,
1329,
14,
408,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
9007,
63,
515,
12,
283,
1506,
2936,
14,
1001,
1333,
465,
4090,
26,
267,
1900,
63,
2936,
275,
2022,
14,
912,
8,
3997,
9,
272,
372,
1900,
63,
2936,
459,
1023,
995,
1900,
63,
2936,
459,
5792,
63,
1506,
418,
421,
199,
318,
8671,
63,
6920,
8,
1231,
12,
8732,
63,
452,
29,
797,
304,
272,
19015,
275,
769,
8,
362,
63,
11840,
8,
1231,
430,
272,
15101,
63,
515,
275,
664,
63,
16389,
63,
515,
8,
1231,
9,
272,
367,
7627,
63,
515,
315,
2342,
63,
16389,
8,
1231,
12,
8732,
63,
452,
304,
267,
1676,
12,
7627,
275,
747,
14,
515,
14,
1294,
8,
9007,
63,
515,
9,
267,
340,
7627,
14,
2460,
360,
17,
14,
1479,
735,
288,
327,
413,
14,
1479,
1990,
17864,
370,
499,
14,
16,
2952,
652,
365,
440,
9025,
543,
413,
14,
88,
288,
1980,
267,
340,
1676,
1137,
15101,
63,
515,
26,
288,
746,
1722,
360,
14858,
931,
358,
267,
7627,
63,
1023,
12,
6974,
63,
1506,
275,
664,
63,
9007,
63,
815,
8,
9007,
63,
515,
9,
267,
367,
4683,
315,
19015,
26,
288,
327,
17646,
83,
543,
314,
2011,
12160,
1329,
1471,
506,
9025,
14,
288,
340,
4683,
1491,
18,
61,
1137,
7627,
1491,
18,
2189,
355,
1980,
288,
367,
1890,
63,
736,
315,
661,
21151,
297,
283,
28197,
297,
283,
8258,
735,
355,
1995,
469,
490,
283,
1753,
63,
1023,
356,
4683,
12,
221,
327,
6810,
490,
283,
9007,
356,
7627,
63,
1023,
12,
221,
327,
7146,
490,
283,
1222,
63,
475,
63,
1753,
356,
283,
2052,
297,
490,
283,
9007,
63,
515,
356,
7627,
12,
490,
283,
1258,
63,
736,
356,
1890,
63,
736,
12,
490,
283,
5792,
63,
1506,
356,
6974,
63,
1506,
12,
355,
789,
355,
1995,
469,
490,
283,
1753,
63,
1023,
356,
4683,
12,
221,
327,
7146,
490,
283,
9007,
356,
7627,
63,
1023,
12,
221,
327,
6810,
490,
283,
1222,
63,
475,
63,
1753,
356,
283,
3910,
297,
490,
283,
9007,
63,
515,
356,
7627,
12,
490,
283,
1258,
63,
736,
356,
1890,
63,
736,
12,
490,
283,
5792,
63,
1506,
356,
6974,
63,
1506,
12,
355,
789,
421,
199,
318,
1900,
63,
6920,
8,
6942,
12,
1738,
12,
9643,
304,
272,
29537,
275,
32516,
360,
1014,
921,
74,
17189,
85,
13,
559,
14,
86,
439,
567,
14,
3569,
26,
15844,
297,
627,
6942,
9,
272,
747,
63,
495,
275,
2420,
21151,
582,
4873,
298,
28197,
582,
3905,
28197,
401,
298,
8258,
582,
3905,
8258,
3570,
272,
367,
3906,
315,
9643,
26,
267,
29537,
14,
1506,
63,
2423,
8,
288,
283,
15390,
13,
2785,
11123,
908,
8,
736,
63,
495,
59,
2423,
459,
1258,
63,
736,
418,
2522,
3906,
9,
421,
199,
318,
2446,
837,
272,
1249,
12,
6235,
275,
664,
63,
589,
342,
272,
1900,
63,
6920,
8,
267,
6235,
12,
1249,
14,
1231,
63,
694,
12,
8671,
63,
6920,
8,
589,
14,
1231,
63,
694,
12,
1249,
14,
452,
430,
421,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
7534,
492,
27615,
199,
646,
2022,
199,
646,
747,
199,
646,
295,
199,
199,
504,
29537,
492,
32516,
199,
504,
1335,
17189,
85,
559,
492,
334,
272,
1050,
63,
15591,
63,
589,
12,
272,
664,
63,
6942,
12,
272,
776,
199,
504,
11420,
492,
334,
272,
2342,
63,
16389,
12,
272,
664,
63,
16389,
63,
515,
12,
272,
776,
421,
199,
318,
664,
63,
589,
8,
3020,
29,
403,
304,
272,
1798,
275,
27615,
342,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
1231,
63,
694,
297,
1720,
534,
6231,
3035,
19015,
436,
15101,
2935,
358,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
452,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
797,
12,
267,
1720,
534,
15535,
1006,
15101,
367,
1890,
13,
1000,
5343,
2659,
272,
1050,
63,
15591,
63,
589,
8,
2087,
9,
272,
1249,
275,
1798,
14,
1122,
63,
589,
8,
3020,
9,
272,
372,
1249,
12,
664,
63,
6942,
8,
589,
9,
421,
199,
318,
664,
63,
11840,
8,
1231,
304,
272,
4683,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
12,
283,
1753,
13,
74,
17189,
85,
358,
272,
14286,
63,
3401,
275,
295,
14,
2014,
9097,
60,
68,
23294,
68,
23294,
68,
11,
4735,
94,
3672,
9988,
272,
367,
2397,
315,
747,
14,
7374,
8,
3221,
63,
515,
304,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
736,
14,
515,
14,
904,
8,
3221,
63,
515,
12,
2397,
2298,
288,
1980,
267,
340,
14286,
63,
3401,
14,
1431,
8,
2373,
304,
288,
1995,
2397,
421,
199,
318,
664,
63,
9007,
63,
815,
8,
9007,
63,
515,
304,
272,
408,
1432,
7627,
1015,
436,
6974,
1900,
1329,
14,
408,
272,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
9007,
63,
515,
12,
283,
1506,
2936,
14,
1001,
1333,
465,
4090,
26,
267,
1900,
63,
2936,
275,
2022,
14,
912,
8,
3997,
9,
272,
372,
1900,
63,
2936,
459,
1023,
995,
1900,
63,
2936,
459,
5792,
63,
1506,
418,
421,
199,
318,
8671,
63,
6920,
8,
1231,
12,
8732,
63,
452,
29,
797,
304,
272,
19015,
275,
769,
8,
362,
63,
11840,
8,
1231,
430,
272,
15101,
63,
515,
275,
664,
63,
16389,
63,
515,
8,
1231,
9,
272,
367,
7627,
63,
515,
315,
2342,
63,
16389,
8,
1231,
12,
8732,
63,
452,
304,
267,
1676,
12,
7627,
275,
747,
14,
515,
14,
1294,
8,
9007,
63,
515,
9,
267,
340,
7627,
14,
2460,
360,
17,
14,
1479,
735,
288,
327,
413,
14,
1479,
1990,
17864,
370,
499,
14,
16,
2952,
652,
365,
440,
9025,
543,
413,
14,
88,
288,
1980,
267,
340,
1676,
1137,
15101,
63,
515,
26,
288,
746,
1722,
360,
14858,
931,
358,
267,
7627,
63,
1023,
12,
6974,
63,
1506,
275,
664,
63,
9007,
63,
815,
8,
9007,
63,
515,
9,
267,
367,
4683,
315,
19015,
26,
288,
327,
17646,
83,
543,
314,
2011,
12160,
1329,
1471,
506,
9025,
14,
288,
340,
4683,
1491,
18,
61,
1137,
7627,
1491,
18,
2189,
355,
1980,
288,
367,
1890,
63,
736,
315,
661,
21151,
297,
283,
28197,
297,
283,
8258,
735,
355,
1995,
469,
490,
283,
1753,
63,
1023,
356,
4683,
12,
221,
327,
6810,
490,
283,
9007,
356,
7627,
63,
1023,
12,
221,
327,
7146,
490,
283,
1222,
63,
475,
63,
1753,
356,
283,
2052,
297,
490,
283,
9007,
63,
515,
356,
7627,
12,
490,
283,
1258,
63,
736,
356,
1890,
63,
736,
12,
490,
283,
5792,
63,
1506,
356,
6974,
63,
1506,
12,
355,
789,
355,
1995,
469,
490,
283,
1753,
63,
1023,
356,
4683,
12,
221,
327,
7146,
490,
283,
9007,
356,
7627,
63,
1023,
12,
221,
327,
6810,
490,
283,
1222,
63,
475,
63,
1753,
356,
283,
3910,
297,
490,
283,
9007,
63,
515,
356,
7627,
12,
490,
283,
1258,
63,
736,
356,
1890,
63,
736,
12,
490,
283,
5792,
63,
1506,
356,
6974,
63,
1506,
12,
355,
789,
421,
199,
318,
1900,
63,
6920,
8,
6942,
12,
1738,
12,
9643,
304,
272,
29537,
275,
32516,
360,
1014,
921,
74,
17189,
85,
13,
559,
14,
86,
439,
567,
14,
3569,
26,
15844,
297,
627,
6942,
9,
272,
747,
63,
495,
275,
2420,
21151,
582,
4873,
298,
28197,
582,
3905,
28197,
401,
298,
8258,
582,
3905,
8258,
3570,
272,
367,
3906,
315,
9643,
26,
267,
29537,
14,
1506,
63,
2423,
8,
288,
283,
15390,
13,
2785,
11123,
908,
8,
736,
63,
495,
59,
2423,
459,
1258,
63,
736,
418,
2522,
3906,
9,
421,
199,
318,
2446,
837,
272,
1249,
12,
6235,
275,
664,
63,
589,
342,
272,
1900,
63,
6920,
8,
267,
6235,
12,
1249,
14,
1231,
63,
694,
12,
8671,
63,
6920,
8,
589,
14,
1231,
63,
694,
12,
1249,
14,
452,
430,
421,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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py
|
9
|
1645
|
'''OpenGL extension ATI.element_array
This module customises the behaviour of the
OpenGL.raw.GL.ATI.element_array to provide a more
Python-friendly API
Overview (from the spec)
This extension provides a mechanism for an application to create
an array of index data for use in specifying geometric primitives.
This extension is most useful when used in conjunction with the
ATI_vertex_array_object extension. ATI_vertex_array_object
provides an interface for storing vertex array data in persistent,
hardware-addressable memory. In cases where large amounts of
vertex data are in use, the index data used to construct
primitives (typically as passed to the GL through DrawElements)
can impose a significant bandwidth burden. ATI_element_array
allows the application to specify independent arrays of elements,
which can then be cached using ATI_vertex_array_object.
The official definition of this extension is available here:
http://www.opengl.org/registry/specs/ATI/element_array.txt
'''
from OpenGL import platform, constant, arrays
from OpenGL import extensions, wrapper
import ctypes
from OpenGL.raw.GL import _types, _glgets
from OpenGL.raw.GL.ATI.element_array import *
from OpenGL.raw.GL.ATI.element_array import _EXTENSION_NAME
def glInitElementArrayATI():
'''Return boolean indicating whether this extension is available'''
from OpenGL import extensions
return extensions.hasGLExtension( _EXTENSION_NAME )
# INPUT glElementPointerATI.pointer size not checked against 'type'
glElementPointerATI=wrapper.wrapper(glElementPointerATI).setInputArraySize(
'pointer', None
)
### END AUTOGENERATED SECTION
|
gpl-3.0
|
[
2344,
4299,
2226,
3329,
437,
13247,
14,
2108,
63,
1144,
199,
199,
2765,
859,
3537,
1388,
314,
13942,
402,
314,
221,
199,
4299,
2226,
14,
1773,
14,
2226,
14,
19735,
14,
2108,
63,
1144,
370,
5647,
282,
1655,
221,
199,
4718,
13,
17317,
3261,
199,
199,
28077,
334,
504,
314,
3158,
9,
8299,
198,
2765,
3329,
6571,
282,
14729,
367,
376,
4223,
370,
1218,
199,
198,
290,
1625,
402,
1478,
666,
367,
675,
315,
9176,
2312,
15890,
1979,
22337,
14,
8299,
198,
2765,
3329,
365,
4750,
2997,
1380,
1202,
315,
22888,
543,
314,
199,
198,
19735,
63,
11417,
63,
1144,
63,
785,
3329,
14,
437,
13247,
63,
11417,
63,
1144,
63,
785,
199,
198,
20121,
376,
3217,
367,
16915,
12759,
1625,
666,
315,
16149,
12,
199,
198,
16529,
13,
1562,
461,
4402,
14,
1010,
5560,
2382,
7031,
32247,
402,
199,
198,
11417,
666,
787,
315,
675,
12,
314,
1478,
666,
1202,
370,
6982,
199,
198,
1359,
22337,
334,
32251,
465,
3032,
370,
314,
3563,
4012,
17813,
6255,
9,
199,
198,
2425,
1742,
3362,
282,
16474,
20434,
330,
300,
848,
14,
437,
13247,
63,
2108,
63,
1144,
199,
198,
24077,
314,
4223,
370,
4165,
12717,
6572,
402,
4008,
12,
199,
198,
6777,
883,
2066,
506,
6328,
1808,
437,
13247,
63,
11417,
63,
1144,
63,
785,
14,
8299,
199,
1918,
25410,
5492,
402,
642,
3329,
365,
2808,
2348,
26,
199,
1014,
921,
1544,
14,
32477,
14,
1308,
15,
5189,
15,
7273,
15,
19735,
15,
2108,
63,
1144,
14,
2424,
199,
2344,
199,
504,
24374,
492,
4298,
12,
4413,
12,
6572,
199,
504,
24374,
492,
5478,
12,
4975,
199,
646,
5577,
199,
504,
24374,
14,
1773,
14,
2226,
492,
485,
1313,
12,
485,
3528,
24894,
199,
504,
24374,
14,
1773,
14,
2226,
14,
19735,
14,
2108,
63,
1144,
492,
627,
199,
504,
24374,
14,
1773,
14,
2226,
14,
19735,
14,
2108,
63,
1144,
492,
485,
15498,
63,
2339,
199,
199,
318,
6482,
9346,
2162,
3836,
19735,
837,
272,
1449,
1767,
5046,
9297,
3775,
642,
3329,
365,
2808,
2344,
272,
687,
24374,
492,
5478,
272,
372,
5478,
14,
1989,
12827,
88,
724,
438,
8,
485,
15498,
63,
2339,
776,
199,
199,
3,
21955,
6482,
2162,
12190,
19735,
14,
3929,
1568,
440,
7923,
6169,
283,
466,
7,
199,
3528,
2162,
12190,
19735,
29,
5029,
14,
5029,
8,
3528,
2162,
12190,
19735,
680,
409,
3205,
3836,
2320,
8,
272,
283,
3929,
297,
488,
199,
9,
199,
5680,
7729,
25420,
12795,
6989,
29074,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4299,
2226,
3329,
437,
13247,
14,
2108,
63,
1144,
199,
199,
2765,
859,
3537,
1388,
314,
13942,
402,
314,
221,
199,
4299,
2226,
14,
1773,
14,
2226,
14,
19735,
14,
2108,
63,
1144,
370,
5647,
282,
1655,
221,
199,
4718,
13,
17317,
3261,
199,
199,
28077,
334,
504,
314,
3158,
9,
8299,
198,
2765,
3329,
6571,
282,
14729,
367,
376,
4223,
370,
1218,
199,
198,
290,
1625,
402,
1478,
666,
367,
675,
315,
9176,
2312,
15890,
1979,
22337,
14,
8299,
198,
2765,
3329,
365,
4750,
2997,
1380,
1202,
315,
22888,
543,
314,
199,
198,
19735,
63,
11417,
63,
1144,
63,
785,
3329,
14,
437,
13247,
63,
11417,
63,
1144,
63,
785,
199,
198,
20121,
376,
3217,
367,
16915,
12759,
1625,
666,
315,
16149,
12,
199,
198,
16529,
13,
1562,
461,
4402,
14,
1010,
5560,
2382,
7031,
32247,
402,
199,
198,
11417,
666,
787,
315,
675,
12,
314,
1478,
666,
1202,
370,
6982,
199,
198,
1359,
22337,
334,
32251,
465,
3032,
370,
314,
3563,
4012,
17813,
6255,
9,
199,
198,
2425,
1742,
3362,
282,
16474,
20434,
330,
300,
848,
14,
437,
13247,
63,
2108,
63,
1144,
199,
198,
24077,
314,
4223,
370,
4165,
12717,
6572,
402,
4008,
12,
199,
198,
6777,
883,
2066,
506,
6328,
1808,
437,
13247,
63,
11417,
63,
1144,
63,
785,
14,
8299,
199,
1918,
25410,
5492,
402,
642,
3329,
365,
2808,
2348,
26,
199,
1014,
921,
1544,
14,
32477,
14,
1308,
15,
5189,
15,
7273,
15,
19735,
15,
2108,
63,
1144,
14,
2424,
199,
2344,
199,
504,
24374,
492,
4298,
12,
4413,
12,
6572,
199,
504,
24374,
492,
5478,
12,
4975,
199,
646,
5577,
199,
504,
24374,
14,
1773,
14,
2226,
492,
485,
1313,
12,
485,
3528,
24894,
199,
504,
24374,
14,
1773,
14,
2226,
14,
19735,
14,
2108,
63,
1144,
492,
627,
199,
504,
24374,
14,
1773,
14,
2226,
14,
19735,
14,
2108,
63,
1144,
492,
485,
15498,
63,
2339,
199,
199,
318,
6482,
9346,
2162,
3836,
19735,
837,
272,
1449,
1767,
5046,
9297,
3775,
642,
3329,
365,
2808,
2344,
272,
687,
24374,
492,
5478,
272,
372,
5478,
14,
1989,
12827,
88,
724,
438,
8,
485,
15498,
63,
2339,
776,
199,
199,
3,
21955,
6482,
2162,
12190,
19735,
14,
3929,
1568,
440,
7923,
6169,
283,
466,
7,
199,
3528,
2162,
12190,
19735,
29,
5029,
14,
5029,
8,
3528,
2162,
12190,
19735,
680,
409,
3205,
3836,
2320,
8,
272,
283,
3929,
297,
488,
199,
9,
199,
5680,
7729,
25420,
12795,
6989,
29074,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
fishcorn/pylearn2
|
pylearn2/rbm_tools.py
|
44
|
20714
|
"""Tools for estimating the partition function of an RBM"""
import numpy
from theano.compat.six.moves import xrange
import theano
from theano import tensor, config
from theano.tensor import nnet
from pylearn2.utils.exc import reraise_as
from pylearn2.utils.rng import make_np_rng, make_theano_rng
from pylearn2.utils.mem import improve_memory_error_message
def compute_log_z(rbm, free_energy_fn, max_bits=15):
"""
Compute the log partition function of an (binary-binary) RBM.
Parameters
----------
rbm : object
An RBM object from `pylearn2.models`.
free_energy_fn : callable
A callable object (e.g. Theano function) that computes the
free energy of a stack of configuration for this RBM.
max_bits : int, optional
The (base-2) log of the number of states to enumerate (and
compute free energy for) at a time.
Notes
-----
This function enumerates a sum with exponentially many terms, and
should not be used with more than a small, toy model.
"""
# Pick whether to iterate over visible or hidden states.
if rbm.nvis < rbm.nhid:
width = rbm.nvis
type = 'vis'
else:
width = rbm.nhid
type = 'hid'
# Determine in how many steps to compute Z.
block_bits = width if (not max_bits or width < max_bits) else max_bits
block_size = 2 ** block_bits
# Allocate storage for 2**block_bits of the 2**width possible
# configurations.
try:
logz_data_c = numpy.zeros(
(block_size, width),
order='C',
dtype=config.floatX
)
except MemoryError:
reraise_as(MemoryError("failed to allocate (%d, %d) matrix of "
"type %s in compute_log_z; try a smaller "
"value of max_bits" %
(block_size, width, str(config.floatX))))
# fill in the first block_bits, which will remain fixed for all
# 2**width configs
tensor_10D_idx = numpy.ndindex(*([2] * block_bits))
for i, j in enumerate(tensor_10D_idx):
logz_data_c[i, -block_bits:] = j
try:
logz_data = numpy.array(logz_data_c, order='F', dtype=config.floatX)
except MemoryError:
reraise_as(MemoryError("failed to allocate (%d, %d) matrix of "
"type %s in compute_log_z; try a smaller "
"value of max_bits" %
(block_size, width, str(config.floatX))))
# Allocate storage for (negative) free-energy of all 2**width
# configurations.
try:
nFE = numpy.zeros(2 ** width, dtype=config.floatX)
except MemoryError as e:
improve_memory_error_message(e,
"failed to allocate free energy storage "
"array in compute_log_z; your model is too "
"big to use with this function")
# now loop 2**(width - block_bits) times, filling in the
# most-significant bits
for bi, up_bits in enumerate(numpy.ndindex(*([2] * (width - block_bits)))):
logz_data[:, :width - block_bits] = up_bits
nFE[bi * block_size:(bi + 1) * block_size] = -free_energy_fn(logz_data)
alpha = nFE.max()
# Do the subtraction and exponentiation in-place so as to not incur a copy.
nFE -= alpha
numpy.exp(nFE, nFE)
log_z = numpy.log(nFE.sum()) + alpha
return log_z
def compute_nll(rbm, data, log_z, free_energy_fn, bufsize=1000, preproc=None):
"""
.. todo::
WRITEME
"""
i = 0.
nll = 0
for i in xrange(0, len(data), bufsize):
# recast data as floatX and apply preprocessing if required
x = numpy.array(data[i:i + bufsize, :], dtype=config.floatX)
if preproc:
x = preproc(x)
# compute sum of likelihood for current buffer
x_nll = -numpy.sum(-free_energy_fn(x) - log_z)
# perform moving average of negative likelihood
# divide by len(x) and not bufsize, since last buffer might be smaller
nll = (i * nll + x_nll) / (i + len(x))
return nll
def rbm_ais(rbm_params, n_runs, visbias_a=None, data=None,
betas=None, key_betas=None, rng=None, seed=23098):
"""
Implements Annealed Importance Sampling for Binary-Binary RBMs
Parameters
----------
rbm_params : list
list of `numpy.ndarrays` containing model parameters:
[weights,visbias,hidbias]
n_runs : int
Number of particles to use in AIS simulation (size of minibatch)
visbias_a : numpy.ndarray, optional
Optional override for visible biases. If both visbias_a and data
are None, visible biases will be set to the same values of the
temperature 1 model. For best results, use the `data` parameter.
data : numpy.ndarray, optional
Training data used to initialize the visible biases of the
base-rate model (usually infinite temperature), to the log-mean
of the distribution (maximum likelihood solution assuming a
zero-weight matrix). This ensures that the base-rate model is
the "closest" to the model at temperature 1.
betas : numpy.ndarray, optional
Vector specifying inverse temperature of intermediate
distributions (in increasing order).
If None, defaults to AIS.dflt_betas
key_betas : numpy.ndarray, optional
If not None, AIS.run will save the log AIS weights for all
temperatures in `key_betas`. This allows the user to estimate
logZ at several temperatures in a single pass of AIS.
rng : None or RandomStream, optional
Random number generator object to use.
seed : int, optional
If rng is None, initialize rng with this seed.
References
----------
.. [1] Neal, R. M. (1998) "Annealed importance sampling",
Technical Report No. 9805 (revised), Dept. of Statistics,
University of Toronto, 25 pages
.. [2] Ruslan Salakhutdinov, Iain Murray. "On the quantitative
analysis of deep belief networks". Proceedings of the 25th
International Conference on Machine Learning, p.872-879,
July 5--9, 2008, Helsinki, Finland
"""
(weights, visbias, hidbias) = rbm_params
rng = make_np_rng(rng, seed, ['random_sample', 'rand'])
if data is None:
if visbias_a is None:
# configure base-rate biases to those supplied by user
visbias_a = visbias
else:
visbias_a = visbias_a
else:
# set biases of base-rate model to ML solution
data = numpy.asarray(data, dtype=config.floatX)
data = numpy.mean(data, axis=0)
data = numpy.minimum(data, 1 - 1e-5)
data = numpy.maximum(data, 1e-5)
visbias_a = -numpy.log(1. / data - 1)
hidbias_a = numpy.zeros_like(hidbias)
weights_a = numpy.zeros_like(weights)
# generate exact sample for the base model
v0 = numpy.tile(1. / (1 + numpy.exp(-visbias_a)), (n_runs, 1))
v0 = numpy.array(v0 > rng.random_sample(v0.shape), dtype=config.floatX)
# we now compute the log AIS weights for the ratio log(Zb/Za)
ais = rbm_z_ratio((weights_a, visbias_a, hidbias_a),
rbm_params, n_runs, v0,
betas=betas, key_betas=key_betas, rng=rng)
dlogz, var_dlogz = ais.estimate_from_weights()
# log Z = log_za + dlogz
ais.log_za = weights_a.shape[1] * numpy.log(2) + \
numpy.sum(numpy.log(1 + numpy.exp(visbias_a)))
ais.log_zb = ais.log_za + dlogz
return (ais.log_zb, var_dlogz), ais
def rbm_z_ratio(rbmA_params, rbmB_params, n_runs, v0=None,
betas=None, key_betas=None, rng=None, seed=23098):
"""
Computes the AIS log-weights :math:`log\:w^{(i)}`, such that
.. math::
\\log Z_b = \\log Z_a + \\log \\frac{1}{M} \\sum_{i=1}^M
\\exp(log_{ais} w^{(i)})
Parameters
----------
rbmA_params : list
List of `numpy.ndarrays`, corresponding to parameters of RBM
whose partition :math:`Z_a` is usually known (i.e. baserate
model at beta=0). Parameters are given in the order:
[weights, visbias, hidbias]
rbmB_params : list
List of `numpy.ndarrays`, corresponding to parameters of RBM
whose partition :math:`Z_a` is usually known (i.e. baserate
model at beta=0). Parameters are given in the order:
[weights, visbias, hidbias]
n_runs : int
WRITEME
v0 : WRITEME
betas : WRITEME
key_betas : WRITEME
rng : WRITEME
seed : int
WRITEME
Notes
-----
Additional parameters are as described in the docstring for
`rbm_ais`.
"""
# check that both models have the same number of hidden units
assert rbmA_params[0].shape[0] == rbmB_params[0].shape[0]
# check that both models have the same number of visible units
assert len(rbmA_params[1]) == len(rbmB_params[1])
rng = make_np_rng(rng, seed, 'rand')
# make sure parameters are in floatX format for GPU support
rbmA_params = [numpy.asarray(q, dtype=config.floatX) for q in rbmA_params]
rbmB_params = [numpy.asarray(q, dtype=config.floatX) for q in rbmB_params]
# declare symbolic vars for current sample `v_sample` and temp `beta`
v_sample = tensor.matrix('ais_v_sample')
beta = tensor.scalar('ais_beta')
### given current sample `v_sample`, generate new samples from inv.
### temperature `beta`
new_v_sample = rbm_ais_gibbs_for_v(rbmA_params, rbmB_params,
beta, v_sample)
sample_fn = theano.function([beta, v_sample], new_v_sample)
### build theano function to compute the free-energy
fe = rbm_ais_pk_free_energy(rbmA_params, rbmB_params, beta, v_sample)
free_energy_fn = theano.function([beta, v_sample],
fe, allow_input_downcast=False)
### RUN AIS ###
weights_b = rbmB_params
v0 = rng.rand(n_runs, weights_b.shape[0]) if v0 is None else v0
ais = AIS(sample_fn, free_energy_fn, v0, n_runs)
ais.set_betas(betas, key_betas=key_betas)
ais.run()
return ais
def rbm_ais_pk_free_energy(rbmA_params, rbmB_params, beta, v_sample):
"""
Computes the free-energy of visible unit configuration `v_sample`,
according to the interpolating distribution at temperature beta.
The interpolating distributions are given by
:math:`p_a(v)^{1-\\beta} p_b(v)^\\beta`.
See equation 10, of Salakhutdinov & Murray 2008.
Parameters
----------
rbmA_params : list
See `rbm_z_ratio`
rbmB_params : list
See `rbm_z_ratio`
beta : int
Inverse temperature at which to compute the free-energy.
v_sample : tensor.matrix
Matrix whose rows indexes into the minibatch, and columns into
the data dimensions.
Returns
-------
f : float (scalar)
Free-energy of configuration `v_sample` given by the
interpolating distribution at temperature beta.
"""
def rbm_fe(rbm_params, v, b):
(weights, visbias, hidbias) = rbm_params
vis_term = b * tensor.dot(v, visbias)
hid_act = b * (tensor.dot(v, weights) + hidbias)
fe = -vis_term - tensor.sum(tensor.log(1 + tensor.exp(hid_act)),
axis=1)
return fe
fe_a = rbm_fe(rbmA_params, v_sample, (1 - beta))
fe_b = rbm_fe(rbmB_params, v_sample, beta)
return fe_a + fe_b
def rbm_ais_gibbs_for_v(rbmA_params, rbmB_params, beta, v_sample, seed=23098):
"""
.. todo::
WRITEME
Parameters
----------
rbmA_params : list
Parameters of the baserate model (usually infinite temperature).
List should be of length 3 and contain numpy.ndarrays
corresponding to model parameters (weights, visbias, hidbias).
rbmB_params : list
Similar to `rbmA_params`, but for model at temperature 1.
beta : theano.shared
Scalar, represents inverse temperature at which we wish to sample from.
v_sample : theano.shared
Matrix of shape (n_runs, nvis), state of current particles.
seed : int, optional
Optional seed parameter for sampling from binomial units.
"""
(weights_a, visbias_a, hidbias_a) = rbmA_params
(weights_b, visbias_b, hidbias_b) = rbmB_params
theano_rng = make_theano_rng(seed, which_method='binomial')
# equation 15 (Salakhutdinov & Murray 2008)
ph_a = nnet.sigmoid((1 - beta) * (tensor.dot(v_sample, weights_a) +
hidbias_a))
ha_sample = theano_rng.binomial(size=(v_sample.shape[0], len(hidbias_a)),
n=1, p=ph_a, dtype=config.floatX)
# equation 16 (Salakhutdinov & Murray 2008)
ph_b = nnet.sigmoid(beta * (tensor.dot(v_sample, weights_b) + hidbias_b))
hb_sample = theano_rng.binomial(size=(v_sample.shape[0], len(hidbias_b)),
n=1, p=ph_b, dtype=config.floatX)
# equation 17 (Salakhutdinov & Murray 2008)
pv_act = (1 - beta) * (tensor.dot(ha_sample, weights_a.T) + visbias_a) + \
beta * (tensor.dot(hb_sample, weights_b.T) + visbias_b)
pv = nnet.sigmoid(pv_act)
new_v_sample = theano_rng.binomial(
size=(v_sample.shape[0], len(visbias_b)),
n=1, p=pv, dtype=config.floatX
)
return new_v_sample
class AIS(object):
"""
Compute the log AIS weights to approximate a ratio of partition functions.
After being initialized, the user should call the `run()` method which will
compute the log AIS weights. `estimate_from_weights` will then compute the
mean & variance of :math:`log(Z_b/Z_a)` (Eq.11).
The notation used here is slightly different than in Salakhutdinov & Murray
2008. We write the AIS weights as follows (note that the denominator is
always of the form :math:`p_i(x_i)` to indicate that
:math:`x_i \sim p_i`). The free energy is denoted by :math:`\mathcal{F}`.
.. math::
w^{(i)} = p_1(v_0)*p_2(v_1)*...*p_k(v_{k-1}) /
[p_0(v_0)*p_1(v_1)*...*p_{k-1}(v_{k-1})]
= p_1(v_0)/p_0(v_0) * p_2(v_1)/p_1(v_1) * ...
* p_k(v_{k-1})/p_{k-1}(v_{k-1})
log\:w^{(i)} = \mathcal{F}_0(v_0) - \mathcal{F}_1(v_0) +
\mathcal{F}_1(v_1) - \mathcal{F}_2(v_1) + ... +
\mathcal{F}_{k-1}(v_{k-1}) - \mathcal{F}_{k}(v_{k-1})
Parameters
----------
sample_fn : compiled theano function
`sample_fn(beta, v_sample)` returns new model samples, at
inverse temperature `beta`. Internally, we do this by
performing block gibbs sampling using Eq.(15-17) (implemented
in `rbm_ais_gibbs_for_v`) starting from configuration
`v_sample`.
free_energy_fn : theano function
`free_energy_fn(beta,v_sample)` computes the free-energy of
configuration `v_sample` at the interpolating distribution
:math:`p_a^{1-\\beta} p_b^{\\beta}`.
v_sample0 : numpy.ndarray
Initial samples from model A.
n_runs : int
Number of AIS runs (i.e. minibatch size)
log_int : int
Log standard deviation of log ais weights every `log_int`
temperatures.
"""
# default configuration for interpolating distributions
dflt_beta = numpy.hstack((numpy.asarray(numpy.linspace(0, 0.5, 1e3),
dtype=config.floatX),
numpy.asarray(numpy.linspace(0.5, 0.9, 1e4),
dtype=config.floatX),
numpy.asarray(numpy.linspace(0.9, 1.0, 1e4),
dtype=config.floatX)))
def __init__(self, sample_fn, free_energy_fn, v_sample0, n_runs,
log_int=500):
self.sample_fn = sample_fn
self.free_energy_fn = free_energy_fn
self.v_sample0 = v_sample0
self.n_runs = n_runs
self.log_int = log_int
# initialize log importance weights
self.log_ais_w = numpy.zeros(n_runs, dtype=config.floatX)
# utility function for safely computing log-mean of the ais weights
ais_w = tensor.vector()
dlogz = (
tensor.log(tensor.mean(tensor.exp(ais_w - tensor.max(ais_w))))
+ tensor.max(ais_w)
)
self.log_mean = theano.function([ais_w], dlogz,
allow_input_downcast=False)
def set_betas(self, betas=None, key_betas=None):
"""
Set the inverse temperature parameters of the AIS procedure.
Parameters
----------
betas : numpy.ndarray, optional
Vector of temperatures specifying interpolating distributions
key_betas : numpy.ndarray, optional
If specified (not None), specifies specific temperatures at
which we want to compute the AIS estimate. AIS.run will
then return a vector, containing AIS at each key_beta
temperature, including the nominal temperature.
"""
self.key_betas = None if key_betas is None else numpy.sort(key_betas)
betas = numpy.array(betas, dtype=config.floatX) \
if betas is not None else self.dflt_beta
# insert key temperatures within
if key_betas is not None:
betas = numpy.hstack((betas, key_betas))
betas.sort()
self.betas = betas
def run(self, n_steps=1):
"""
Performs the grunt-work, implementing
.. math::
log\:w^{(i)} += \mathcal{F}_{k-1}(v_{k-1}) - \mathcal{F}_{k}(v_{k-1})
recursively for all temperatures.
Parameters
----------
n_steps : int, optional
WRITEME
"""
if not hasattr(self, 'betas'):
self.set_betas()
self.std_ais_w = [] # used to log std of log_ais_w regularly
self.logz_beta = [] # used to log log_ais_w at every `key_beta` value
self.var_logz_beta = [] # used to log variance of log_ais_w as above
# initial sample
state = self.v_sample0
ki = 0
# loop over all temperatures from beta=0 to beta=1
for i in range(len(self.betas) - 1):
bp, bp1 = self.betas[i], self.betas[i + 1]
# log-ratio of (free) energies for two nearby temperatures
self.log_ais_w += \
self.free_energy_fn(bp, state) - \
self.free_energy_fn(bp1, state)
# log standard deviation of AIS weights (kind of deprecated)
if (i + 1) % self.log_int == 0:
m = numpy.max(self.log_ais_w)
std_ais = (numpy.log(numpy.std(numpy.exp(self.log_ais_w - m)))
+ m - numpy.log(self.n_runs) / 2)
self.std_ais_w.append(std_ais)
# whenever we reach a "key" beta value, log log_ais_w and
# var(log_ais_w) so we can estimate log_Z_{beta=key_betas[i]} after
# the fact.
if self.key_betas is not None and \
ki < len(self.key_betas) and \
bp1 == self.key_betas[ki]:
log_ais_w_bi, var_log_ais_w_bi = \
self.estimate_from_weights(self.log_ais_w)
self.logz_beta.insert(0, log_ais_w_bi)
self.var_logz_beta.insert(0, var_log_ais_w_bi)
ki += 1
# generate a new sample at temperature beta_{i+1}
state = self.sample_fn(bp1, state)
def estimate_from_weights(self, log_ais_w=None):
"""
Once run() method has been called, estimates the mean and variance of
log(Zb/Za).
Parameters
----------
log_ais_w : None or 1D numpy.ndarray
optional override for log_ais_w. When None, estimates log(Zb/Za)
using the log AIS weights computed by AIS.run() method.
Returns
-------
f : float
Estimated mean of log(Zb/Za), log-ratio of partition functions of
model B and A.
v : float
Estimated variance of log(Zb/Za)
"""
log_ais_w = self.log_ais_w if log_ais_w is None else log_ais_w
# estimate the log-mean of the AIS weights
dlogz = self.log_mean(log_ais_w)
# estimate log-variance of the AIS weights
# VAR(log(X)) \approx VAR(X) / E(X)^2 = E(X^2)/E(X)^2 - 1
m = numpy.max(log_ais_w)
var_dlogz = (log_ais_w.shape[0] *
numpy.sum(numpy.exp(2 * (log_ais_w - m))) /
numpy.sum(numpy.exp(log_ais_w - m)) ** 2 - 1.)
return dlogz, var_dlogz
|
bsd-3-clause
|
[
624,
11654,
367,
4347,
3969,
316,
314,
6484,
805,
402,
376,
820,
15225,
624,
199,
646,
2680,
199,
504,
14377,
14,
5819,
14,
4174,
14,
4912,
492,
4945,
199,
646,
14377,
199,
504,
14377,
492,
2345,
12,
1101,
199,
504,
14377,
14,
3128,
492,
302,
846,
199,
504,
27959,
18,
14,
1208,
14,
2804,
492,
24139,
63,
305,
199,
504,
27959,
18,
14,
1208,
14,
12686,
492,
1852,
63,
1590,
63,
12686,
12,
1852,
63,
32057,
63,
12686,
199,
504,
27959,
18,
14,
1208,
14,
5286,
492,
19053,
63,
4844,
63,
705,
63,
1188,
421,
199,
318,
4526,
63,
793,
63,
90,
8,
4848,
77,
12,
2867,
63,
8443,
63,
2324,
12,
1390,
63,
5609,
29,
1046,
304,
272,
408,
272,
8354,
314,
943,
6484,
805,
402,
376,
334,
3008,
13,
3008,
9,
820,
15225,
14,
339,
3897,
272,
4143,
272,
11587,
77,
520,
909,
267,
1626,
820,
15225,
909,
687,
658,
647,
4643,
18,
14,
992,
2313,
272,
2867,
63,
8443,
63,
2324,
520,
4550,
267,
437,
4550,
909,
334,
69,
14,
71,
14,
710,
8143,
805,
9,
626,
21445,
314,
267,
2867,
12304,
402,
282,
3464,
402,
2897,
367,
642,
820,
15225,
14,
272,
1390,
63,
5609,
520,
1109,
12,
2716,
267,
710,
334,
1095,
13,
18,
9,
943,
402,
314,
1329,
402,
6363,
370,
3874,
334,
460,
267,
4526,
2867,
12304,
367,
9,
737,
282,
900,
14,
339,
8144,
272,
9063,
272,
961,
805,
3874,
83,
282,
3089,
543,
444,
10995,
9406,
5002,
2895,
12,
436,
272,
1077,
440,
506,
1202,
543,
1655,
2419,
282,
7425,
12,
31239,
1402,
14,
272,
408,
272,
327,
16568,
3775,
370,
13974,
1806,
8917,
503,
8752,
6363,
14,
272,
340,
11587,
77,
14,
78,
5068,
665,
11587,
77,
14,
78,
18209,
26,
267,
3462,
275,
11587,
77,
14,
78,
5068,
267,
730,
275,
283,
5068,
7,
272,
587,
26,
267,
3462,
275,
11587,
77,
14,
78,
18209,
267,
730,
275,
283,
18209,
7,
339,
327,
14703,
315,
4212,
5002,
7124,
370,
4526,
3107,
14,
272,
1853,
63,
5609,
275,
3462,
340,
334,
1397,
1390,
63,
5609,
503,
3462,
665,
1390,
63,
5609,
9,
587,
1390,
63,
5609,
272,
1853,
63,
890,
275,
499,
1011,
1853,
63,
5609,
339,
327,
4580,
6280,
4887,
367,
499,
538,
1457,
63,
5609,
402,
314,
499,
538,
2063,
3962,
272,
327,
13422,
14,
272,
862,
26,
267,
943,
90,
63,
576,
63,
67,
275,
2680,
14,
4250,
8,
288,
334,
1457,
63,
890,
12,
3462,
395,
288,
1865,
534,
35,
297,
288,
2152,
29,
888,
14,
31293,
267,
776,
272,
871,
15825,
547,
26,
267,
24139,
63,
305,
8,
8628,
547,
480,
4892,
370,
18310,
4366,
68,
12,
450,
68,
9,
3634,
402,
298,
3044,
298,
466,
450,
83,
315,
4526,
63,
793,
63,
90,
27,
862,
282,
12700,
298,
3044,
298,
585,
402,
1390,
63,
5609,
2,
450,
2079,
334,
1457,
63,
890,
12,
3462,
12,
620,
8,
888,
14,
31293,
7845,
339,
327,
5554,
315,
314,
1642,
1853,
63,
5609,
12,
1314,
911,
5706,
6317,
367,
1006,
272,
327,
499,
538,
2063,
11585,
272,
2345,
63,
709,
36,
63,
2996,
275,
2680,
14,
977,
1080,
2031,
779,
18,
61,
627,
1853,
63,
5609,
430,
272,
367,
284,
12,
1335,
315,
3874,
8,
3128,
63,
709,
36,
63,
2996,
304,
267,
943,
90,
63,
576,
63,
67,
59,
73,
12,
446,
1457,
63,
5609,
2938,
275,
1335,
272,
862,
26,
267,
943,
90,
63,
576,
275,
2680,
14,
1144,
8,
793,
90,
63,
576,
63,
67,
12,
1865,
534,
38,
297,
2152,
29,
888,
14,
31293,
9,
272,
871,
15825,
547,
26,
267,
24139,
63,
305,
8,
8628,
547,
480,
4892,
370,
18310,
4366,
68,
12,
450,
68,
9,
3634,
402,
298,
3044,
298,
466,
450,
83,
315,
4526,
63,
793,
63,
90,
27,
862,
282,
12700,
298,
3044,
298,
585,
402,
1390,
63,
5609,
2,
450,
2079,
334,
1457,
63,
890,
12,
3462,
12,
620,
8,
888,
14,
31293,
7845,
339,
327,
4580,
6280,
4887,
367,
334,
7371,
9,
2867,
13,
8443,
402,
1006,
499,
538,
2063,
272,
327,
13422,
14,
272,
862,
26,
267,
302,
5100,
275,
2680,
14,
4250,
8,
18,
1011,
3462,
12,
2152,
29,
888,
14,
31293,
9,
272,
871,
15825,
547,
465,
325,
26,
267,
19053,
63,
4844,
63,
705,
63,
1188,
8,
69,
12,
7205,
298,
4892,
370,
18310,
2867,
12304,
4887,
298,
288,
298,
1144,
315,
4526,
63,
793,
63,
90,
27,
2195,
1402,
365,
4634,
298,
288,
298,
5076,
370,
675,
543,
642,
805,
531,
339,
327,
3063,
4438,
499,
14192,
2063,
446,
1853,
63,
5609,
9,
5431,
12,
32499,
315,
314,
272,
327,
4750,
13,
1037,
14266,
5821,
272,
367,
12111,
12,
1536,
63,
5609,
315,
3874,
8,
4714,
14,
977,
1080,
2031,
779,
18,
61,
627,
334,
2063,
446,
1853,
63,
5609,
1724,
304,
267,
943,
90,
63,
576,
3981,
520,
2063,
446,
1853,
63,
5609,
61,
275,
1536,
63,
5609,
267,
302,
5100,
59,
4492,
627,
1853,
63,
890,
20334,
4492,
435,
413,
9,
627,
1853,
63,
890,
61,
275,
446,
4624,
63,
8443,
63,
2324,
8,
793,
90,
63,
576,
9,
272,
5131,
275,
302,
5100,
14,
988,
342,
272,
327,
4226,
314,
1007,
26137,
436,
444,
10995,
280,
425,
315,
13,
2778,
880,
465,
370,
440,
315,
895,
282,
1331,
14,
272,
302,
5100,
4862,
5131,
272,
2680,
14,
1474,
8,
78,
5100,
12,
302,
5100,
9,
272,
943,
63,
90,
275,
2680,
14,
793,
8,
78,
5100,
14,
1838,
1012,
435,
5131,
272,
372,
943,
63,
90,
421,
199,
318,
4526,
63,
78,
914,
8,
4848,
77,
12,
666,
12,
943,
63,
90,
12,
2867,
63,
8443,
63,
2324,
12,
17080,
29,
5279,
12,
876,
4687,
29,
403,
304,
272,
408,
272,
2508,
11386,
447,
398,
25727,
272,
408,
272,
284,
275,
378,
14,
272,
302,
914,
275,
378,
272,
367,
284,
315,
4945,
8,
16,
12,
822,
8,
576,
395,
17080,
304,
267,
327,
295,
2931,
666,
465,
2069,
56,
436,
4838,
26471,
340,
1415,
267,
671,
275,
2680,
14,
1144,
8,
576,
59,
73,
26,
73,
435,
17080,
12,
26450,
2152,
29,
888,
14,
31293,
9,
267,
340,
876,
4687,
26,
288
] |
[
11654,
367,
4347,
3969,
316,
314,
6484,
805,
402,
376,
820,
15225,
624,
199,
646,
2680,
199,
504,
14377,
14,
5819,
14,
4174,
14,
4912,
492,
4945,
199,
646,
14377,
199,
504,
14377,
492,
2345,
12,
1101,
199,
504,
14377,
14,
3128,
492,
302,
846,
199,
504,
27959,
18,
14,
1208,
14,
2804,
492,
24139,
63,
305,
199,
504,
27959,
18,
14,
1208,
14,
12686,
492,
1852,
63,
1590,
63,
12686,
12,
1852,
63,
32057,
63,
12686,
199,
504,
27959,
18,
14,
1208,
14,
5286,
492,
19053,
63,
4844,
63,
705,
63,
1188,
421,
199,
318,
4526,
63,
793,
63,
90,
8,
4848,
77,
12,
2867,
63,
8443,
63,
2324,
12,
1390,
63,
5609,
29,
1046,
304,
272,
408,
272,
8354,
314,
943,
6484,
805,
402,
376,
334,
3008,
13,
3008,
9,
820,
15225,
14,
339,
3897,
272,
4143,
272,
11587,
77,
520,
909,
267,
1626,
820,
15225,
909,
687,
658,
647,
4643,
18,
14,
992,
2313,
272,
2867,
63,
8443,
63,
2324,
520,
4550,
267,
437,
4550,
909,
334,
69,
14,
71,
14,
710,
8143,
805,
9,
626,
21445,
314,
267,
2867,
12304,
402,
282,
3464,
402,
2897,
367,
642,
820,
15225,
14,
272,
1390,
63,
5609,
520,
1109,
12,
2716,
267,
710,
334,
1095,
13,
18,
9,
943,
402,
314,
1329,
402,
6363,
370,
3874,
334,
460,
267,
4526,
2867,
12304,
367,
9,
737,
282,
900,
14,
339,
8144,
272,
9063,
272,
961,
805,
3874,
83,
282,
3089,
543,
444,
10995,
9406,
5002,
2895,
12,
436,
272,
1077,
440,
506,
1202,
543,
1655,
2419,
282,
7425,
12,
31239,
1402,
14,
272,
408,
272,
327,
16568,
3775,
370,
13974,
1806,
8917,
503,
8752,
6363,
14,
272,
340,
11587,
77,
14,
78,
5068,
665,
11587,
77,
14,
78,
18209,
26,
267,
3462,
275,
11587,
77,
14,
78,
5068,
267,
730,
275,
283,
5068,
7,
272,
587,
26,
267,
3462,
275,
11587,
77,
14,
78,
18209,
267,
730,
275,
283,
18209,
7,
339,
327,
14703,
315,
4212,
5002,
7124,
370,
4526,
3107,
14,
272,
1853,
63,
5609,
275,
3462,
340,
334,
1397,
1390,
63,
5609,
503,
3462,
665,
1390,
63,
5609,
9,
587,
1390,
63,
5609,
272,
1853,
63,
890,
275,
499,
1011,
1853,
63,
5609,
339,
327,
4580,
6280,
4887,
367,
499,
538,
1457,
63,
5609,
402,
314,
499,
538,
2063,
3962,
272,
327,
13422,
14,
272,
862,
26,
267,
943,
90,
63,
576,
63,
67,
275,
2680,
14,
4250,
8,
288,
334,
1457,
63,
890,
12,
3462,
395,
288,
1865,
534,
35,
297,
288,
2152,
29,
888,
14,
31293,
267,
776,
272,
871,
15825,
547,
26,
267,
24139,
63,
305,
8,
8628,
547,
480,
4892,
370,
18310,
4366,
68,
12,
450,
68,
9,
3634,
402,
298,
3044,
298,
466,
450,
83,
315,
4526,
63,
793,
63,
90,
27,
862,
282,
12700,
298,
3044,
298,
585,
402,
1390,
63,
5609,
2,
450,
2079,
334,
1457,
63,
890,
12,
3462,
12,
620,
8,
888,
14,
31293,
7845,
339,
327,
5554,
315,
314,
1642,
1853,
63,
5609,
12,
1314,
911,
5706,
6317,
367,
1006,
272,
327,
499,
538,
2063,
11585,
272,
2345,
63,
709,
36,
63,
2996,
275,
2680,
14,
977,
1080,
2031,
779,
18,
61,
627,
1853,
63,
5609,
430,
272,
367,
284,
12,
1335,
315,
3874,
8,
3128,
63,
709,
36,
63,
2996,
304,
267,
943,
90,
63,
576,
63,
67,
59,
73,
12,
446,
1457,
63,
5609,
2938,
275,
1335,
272,
862,
26,
267,
943,
90,
63,
576,
275,
2680,
14,
1144,
8,
793,
90,
63,
576,
63,
67,
12,
1865,
534,
38,
297,
2152,
29,
888,
14,
31293,
9,
272,
871,
15825,
547,
26,
267,
24139,
63,
305,
8,
8628,
547,
480,
4892,
370,
18310,
4366,
68,
12,
450,
68,
9,
3634,
402,
298,
3044,
298,
466,
450,
83,
315,
4526,
63,
793,
63,
90,
27,
862,
282,
12700,
298,
3044,
298,
585,
402,
1390,
63,
5609,
2,
450,
2079,
334,
1457,
63,
890,
12,
3462,
12,
620,
8,
888,
14,
31293,
7845,
339,
327,
4580,
6280,
4887,
367,
334,
7371,
9,
2867,
13,
8443,
402,
1006,
499,
538,
2063,
272,
327,
13422,
14,
272,
862,
26,
267,
302,
5100,
275,
2680,
14,
4250,
8,
18,
1011,
3462,
12,
2152,
29,
888,
14,
31293,
9,
272,
871,
15825,
547,
465,
325,
26,
267,
19053,
63,
4844,
63,
705,
63,
1188,
8,
69,
12,
7205,
298,
4892,
370,
18310,
2867,
12304,
4887,
298,
288,
298,
1144,
315,
4526,
63,
793,
63,
90,
27,
2195,
1402,
365,
4634,
298,
288,
298,
5076,
370,
675,
543,
642,
805,
531,
339,
327,
3063,
4438,
499,
14192,
2063,
446,
1853,
63,
5609,
9,
5431,
12,
32499,
315,
314,
272,
327,
4750,
13,
1037,
14266,
5821,
272,
367,
12111,
12,
1536,
63,
5609,
315,
3874,
8,
4714,
14,
977,
1080,
2031,
779,
18,
61,
627,
334,
2063,
446,
1853,
63,
5609,
1724,
304,
267,
943,
90,
63,
576,
3981,
520,
2063,
446,
1853,
63,
5609,
61,
275,
1536,
63,
5609,
267,
302,
5100,
59,
4492,
627,
1853,
63,
890,
20334,
4492,
435,
413,
9,
627,
1853,
63,
890,
61,
275,
446,
4624,
63,
8443,
63,
2324,
8,
793,
90,
63,
576,
9,
272,
5131,
275,
302,
5100,
14,
988,
342,
272,
327,
4226,
314,
1007,
26137,
436,
444,
10995,
280,
425,
315,
13,
2778,
880,
465,
370,
440,
315,
895,
282,
1331,
14,
272,
302,
5100,
4862,
5131,
272,
2680,
14,
1474,
8,
78,
5100,
12,
302,
5100,
9,
272,
943,
63,
90,
275,
2680,
14,
793,
8,
78,
5100,
14,
1838,
1012,
435,
5131,
272,
372,
943,
63,
90,
421,
199,
318,
4526,
63,
78,
914,
8,
4848,
77,
12,
666,
12,
943,
63,
90,
12,
2867,
63,
8443,
63,
2324,
12,
17080,
29,
5279,
12,
876,
4687,
29,
403,
304,
272,
408,
272,
2508,
11386,
447,
398,
25727,
272,
408,
272,
284,
275,
378,
14,
272,
302,
914,
275,
378,
272,
367,
284,
315,
4945,
8,
16,
12,
822,
8,
576,
395,
17080,
304,
267,
327,
295,
2931,
666,
465,
2069,
56,
436,
4838,
26471,
340,
1415,
267,
671,
275,
2680,
14,
1144,
8,
576,
59,
73,
26,
73,
435,
17080,
12,
26450,
2152,
29,
888,
14,
31293,
9,
267,
340,
876,
4687,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Alwnikrotikz/pybluez
|
examples/bluezchat/bluezchat.py
|
19
|
6006
|
#!/usr/bin/python
""" A simple graphical chat client to demonstrate the use of pybluez.
Opens a l2cap socket and listens on PSM 0x1001
Provides the ability to scan for nearby bluetooth devices and establish chat
sessions with them.
"""
import os
import sys
import time
import gtk
import gobject
import gtk.glade
import bluetooth
GLADEFILE="bluezchat.glade"
# *****************
def alert(text, buttons=gtk.BUTTONS_NONE, type=gtk.MESSAGE_INFO):
md = gtk.MessageDialog(buttons=buttons, type=type)
md.label.set_text(text)
md.run()
md.destroy()
class BluezChatGui:
def __init__(self):
self.main_window_xml = gtk.glade.XML(GLADEFILE, "bluezchat_window")
# connect our signal handlers
dic = { "on_quit_button_clicked" : self.quit_button_clicked,
"on_send_button_clicked" : self.send_button_clicked,
"on_chat_button_clicked" : self.chat_button_clicked,
"on_scan_button_clicked" : self.scan_button_clicked,
"on_devices_tv_cursor_changed" : self.devices_tv_cursor_changed
}
self.main_window_xml.signal_autoconnect(dic)
# prepare the floor listbox
self.devices_tv = self.main_window_xml.get_widget("devices_tv")
self.discovered = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING)
self.devices_tv.set_model(self.discovered)
renderer = gtk.CellRendererText()
column1=gtk.TreeViewColumn("addr", renderer, text=0)
column2=gtk.TreeViewColumn("name", renderer, text=1)
self.devices_tv.append_column(column1)
self.devices_tv.append_column(column2)
self.quit_button = self.main_window_xml.get_widget("quit_button")
self.scan_button = self.main_window_xml.get_widget("scan_button")
self.chat_button = self.main_window_xml.get_widget("chat_button")
self.send_button = self.main_window_xml.get_widget("send_button")
self.main_text = self.main_window_xml.get_widget("main_text")
self.text_buffer = self.main_text.get_buffer()
self.input_tb = self.main_window_xml.get_widget("input_tb")
self.listed_devs = []
self.chat_button.set_sensitive(False)
self.peers = {}
self.sources = {}
self.addresses = {}
# the listening sockets
self.server_sock = None
# --- gui signal handlers
def quit_button_clicked(self, widget):
gtk.main_quit()
def scan_button_clicked(self, widget):
self.quit_button.set_sensitive(False)
self.scan_button.set_sensitive(False)
# self.chat_button.set_sensitive(False)
self.discovered.clear()
for addr, name in bluetooth.discover_devices (lookup_names = True):
self.discovered.append ((addr, name))
self.quit_button.set_sensitive(True)
self.scan_button.set_sensitive(True)
# self.chat_button.set_sensitive(True)
def send_button_clicked(self, widget):
text = self.input_tb.get_text()
if len(text) == 0: return
for addr, sock in list(self.peers.items()):
sock.send(text)
self.input_tb.set_text("")
self.add_text("\nme - %s" % text)
def chat_button_clicked(self, widget):
(model, iter) = self.devices_tv.get_selection().get_selected()
if iter is not None:
addr = model.get_value(iter, 0)
if addr not in self.peers:
self.add_text("\nconnecting to %s" % addr)
self.connect(addr)
else:
self.add_text("\nAlready connected to %s!" % addr)
def devices_tv_cursor_changed(self, widget):
(model, iter) = self.devices_tv.get_selection().get_selected()
if iter is not None:
self.chat_button.set_sensitive(True)
else:
self.chat_button.set_sensitive(False)
# --- network events
def incoming_connection(self, source, condition):
sock, info = self.server_sock.accept()
address, psm = info
self.add_text("\naccepted connection from %s" % str(address))
# add new connection to list of peers
self.peers[address] = sock
self.addresses[sock] = address
source = gobject.io_add_watch (sock, gobject.IO_IN, self.data_ready)
self.sources[address] = source
return True
def data_ready(self, sock, condition):
address = self.addresses[sock]
data = sock.recv(1024)
if len(data) == 0:
self.add_text("\nlost connection with %s" % address)
gobject.source_remove(self.sources[address])
del self.sources[address]
del self.peers[address]
del self.addresses[sock]
sock.close()
else:
self.add_text("\n%s - %s" % (address, str(data)))
return True
# --- other stuff
def cleanup(self):
self.hci_sock.close()
def connect(self, addr):
sock = bluetooth.BluetoothSocket (bluetooth.L2CAP)
try:
sock.connect((addr, 0x1001))
except bluez.error as e:
self.add_text("\n%s" % str(e))
sock.close()
return
self.peers[addr] = sock
source = gobject.io_add_watch (sock, gobject.IO_IN, self.data_ready)
self.sources[addr] = source
self.addresses[sock] = addr
def add_text(self, text):
self.text_buffer.insert(self.text_buffer.get_end_iter(), text)
def start_server(self):
self.server_sock = bluetooth.BluetoothSocket (bluetooth.L2CAP)
self.server_sock.bind(("",0x1001))
self.server_sock.listen(1)
gobject.io_add_watch(self.server_sock,
gobject.IO_IN, self.incoming_connection)
def run(self):
self.text_buffer.insert(self.text_buffer.get_end_iter(), "loading..")
self.start_server()
gtk.main()
if __name__ == "__main__":
gui = BluezChatGui()
gui.run()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
624,
437,
3486,
3343,
2652,
21472,
1890,
370,
23789,
18161,
314,
675,
402,
1134,
6304,
90,
14,
199,
199,
4299,
83,
282,
634,
18,
2874,
2838,
436,
1212,
1597,
561,
641,
510,
4029,
378,
88,
22167,
199,
199,
17473,
314,
21255,
370,
8000,
367,
17429,
991,
10030,
16453,
7256,
436,
16873,
21472,
199,
11676,
543,
3062,
14,
199,
624,
421,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
646,
8116,
199,
646,
25595,
199,
646,
8116,
14,
31589,
199,
199,
646,
10030,
16453,
199,
199,
2226,
33,
1093,
3817,
628,
6304,
90,
10289,
14,
31589,
2,
199,
199,
3,
1011,
1801,
1116,
9153,
199,
199,
318,
10459,
8,
505,
12,
15766,
29,
12275,
14,
13272,
51,
63,
9185,
12,
730,
29,
12275,
14,
8272,
63,
4531,
304,
272,
6128,
275,
8116,
14,
2209,
5619,
8,
15687,
29,
15687,
12,
730,
29,
466,
9,
272,
6128,
14,
1302,
14,
409,
63,
505,
8,
505,
9,
272,
6128,
14,
1065,
342,
272,
6128,
14,
7237,
342,
199,
199,
533,
22447,
90,
21954,
4324,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
973,
63,
3806,
63,
1652,
275,
8116,
14,
31589,
14,
4317,
8,
2226,
33,
1093,
3817,
12,
298,
6304,
90,
10289,
63,
3806,
531,
398,
327,
4907,
4154,
4673,
8297,
267,
12219,
275,
469,
298,
265,
63,
10589,
63,
3887,
63,
11276,
2,
520,
291,
14,
10589,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
2254,
63,
3887,
63,
11276,
2,
520,
291,
14,
2254,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
10289,
63,
3887,
63,
11276,
2,
520,
291,
14,
10289,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
6282,
63,
3887,
63,
11276,
2,
520,
291,
14,
6282,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
6410,
63,
6993,
63,
3937,
63,
2489,
2,
520,
291,
14,
6410,
63,
6993,
63,
3937,
63,
2489,
355,
789,
398,
291,
14,
973,
63,
3806,
63,
1652,
14,
4653,
63,
2495,
2242,
8,
5000,
9,
398,
327,
9275,
314,
19841,
769,
1977,
267,
291,
14,
6410,
63,
6993,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
6410,
63,
6993,
531,
267,
291,
14,
2297,
13560,
275,
8116,
14,
1296,
5502,
8,
71,
785,
14,
2711,
63,
5353,
12,
8892,
25595,
14,
2711,
63,
5353,
9,
267,
291,
14,
6410,
63,
6993,
14,
409,
63,
1238,
8,
277,
14,
2297,
13560,
9,
267,
11889,
275,
8116,
14,
8108,
11355,
1872,
342,
267,
2763,
17,
29,
12275,
14,
32656,
4547,
480,
2697,
401,
11889,
12,
1318,
29,
16,
9,
267,
2763,
18,
29,
12275,
14,
32656,
4547,
480,
354,
401,
11889,
12,
1318,
29,
17,
9,
267,
291,
14,
6410,
63,
6993,
14,
740,
63,
2301,
8,
2301,
17,
9,
267,
291,
14,
6410,
63,
6993,
14,
740,
63,
2301,
8,
2301,
18,
9,
398,
291,
14,
10589,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
10589,
63,
3887,
531,
267,
291,
14,
6282,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
6282,
63,
3887,
531,
267,
291,
14,
10289,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
10289,
63,
3887,
531,
267,
291,
14,
2254,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
2254,
63,
3887,
531,
267,
291,
14,
973,
63,
505,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
973,
63,
505,
531,
267,
291,
14,
505,
63,
2738,
275,
291,
14,
973,
63,
505,
14,
362,
63,
2738,
342,
398,
291,
14,
1210,
63,
5842,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
1210,
63,
5842,
531,
398,
291,
14,
15023,
63,
18804,
275,
942,
398,
291,
14,
10289,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
398,
291,
14,
22416,
275,
1052,
267,
291,
14,
4553,
275,
1052,
267,
291,
14,
7423,
275,
1052,
398,
327,
314,
22721,
18772,
267,
291,
14,
1000,
63,
5096,
275,
488,
199,
199,
3,
10894,
11621,
4673,
8297,
339,
347,
17242,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
8116,
14,
973,
63,
10589,
342,
339,
347,
8000,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
291,
14,
10589,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
267,
291,
14,
6282,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
199,
3,
263,
291,
14,
10289,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
2728,
291,
14,
2297,
13560,
14,
3584,
342,
267,
367,
5552,
12,
536,
315,
10030,
16453,
14,
18861,
63,
6410,
334,
3892,
63,
1247,
275,
715,
304,
288,
291,
14,
2297,
13560,
14,
740,
3666,
2697,
12,
536,
430,
398,
291,
14,
10589,
63,
3887,
14,
409,
63,
7361,
8,
549,
9,
267,
291,
14,
6282,
63,
3887,
14,
409,
63,
7361,
8,
549,
9,
199,
3,
263,
291,
14,
10289,
63,
3887,
14,
409,
63,
7361,
8,
549,
9,
339,
347,
3222,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
1318,
275,
291,
14,
1210,
63,
5842,
14,
362,
63,
505,
342,
267,
340,
822,
8,
505,
9,
508,
378,
26,
372,
398,
367,
5552,
12,
6771,
315,
769,
8,
277,
14,
22416,
14,
1744,
5109,
288,
6771,
14,
2254,
8,
505,
9,
398,
291,
14,
1210,
63,
5842,
14,
409,
63,
505,
10804,
267,
291,
14,
525,
63,
505,
4582,
78,
278,
446,
450,
83,
2,
450,
1318,
9,
339,
347,
21472,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
334,
1238,
12,
2740,
9,
275,
291,
14,
6410,
63,
6993,
14,
362,
63,
5592,
1252,
362,
63,
5511,
342,
267,
340,
2740,
365,
440,
488,
26,
288,
5552,
275,
1402,
14,
362,
63,
585,
8,
1661,
12,
378,
9,
288,
340,
5552,
440,
315,
291,
14,
22416,
26,
355,
291,
14,
525,
63,
505,
4582,
78,
2242,
316,
370,
450,
83,
2,
450,
5552,
9,
355,
291,
14,
2242,
8,
2697,
9,
288,
587,
26,
355,
291
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
624,
437,
3486,
3343,
2652,
21472,
1890,
370,
23789,
18161,
314,
675,
402,
1134,
6304,
90,
14,
199,
199,
4299,
83,
282,
634,
18,
2874,
2838,
436,
1212,
1597,
561,
641,
510,
4029,
378,
88,
22167,
199,
199,
17473,
314,
21255,
370,
8000,
367,
17429,
991,
10030,
16453,
7256,
436,
16873,
21472,
199,
11676,
543,
3062,
14,
199,
624,
421,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
199,
646,
8116,
199,
646,
25595,
199,
646,
8116,
14,
31589,
199,
199,
646,
10030,
16453,
199,
199,
2226,
33,
1093,
3817,
628,
6304,
90,
10289,
14,
31589,
2,
199,
199,
3,
1011,
1801,
1116,
9153,
199,
199,
318,
10459,
8,
505,
12,
15766,
29,
12275,
14,
13272,
51,
63,
9185,
12,
730,
29,
12275,
14,
8272,
63,
4531,
304,
272,
6128,
275,
8116,
14,
2209,
5619,
8,
15687,
29,
15687,
12,
730,
29,
466,
9,
272,
6128,
14,
1302,
14,
409,
63,
505,
8,
505,
9,
272,
6128,
14,
1065,
342,
272,
6128,
14,
7237,
342,
199,
199,
533,
22447,
90,
21954,
4324,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
973,
63,
3806,
63,
1652,
275,
8116,
14,
31589,
14,
4317,
8,
2226,
33,
1093,
3817,
12,
298,
6304,
90,
10289,
63,
3806,
531,
398,
327,
4907,
4154,
4673,
8297,
267,
12219,
275,
469,
298,
265,
63,
10589,
63,
3887,
63,
11276,
2,
520,
291,
14,
10589,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
2254,
63,
3887,
63,
11276,
2,
520,
291,
14,
2254,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
10289,
63,
3887,
63,
11276,
2,
520,
291,
14,
10289,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
6282,
63,
3887,
63,
11276,
2,
520,
291,
14,
6282,
63,
3887,
63,
11276,
12,
355,
298,
265,
63,
6410,
63,
6993,
63,
3937,
63,
2489,
2,
520,
291,
14,
6410,
63,
6993,
63,
3937,
63,
2489,
355,
789,
398,
291,
14,
973,
63,
3806,
63,
1652,
14,
4653,
63,
2495,
2242,
8,
5000,
9,
398,
327,
9275,
314,
19841,
769,
1977,
267,
291,
14,
6410,
63,
6993,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
6410,
63,
6993,
531,
267,
291,
14,
2297,
13560,
275,
8116,
14,
1296,
5502,
8,
71,
785,
14,
2711,
63,
5353,
12,
8892,
25595,
14,
2711,
63,
5353,
9,
267,
291,
14,
6410,
63,
6993,
14,
409,
63,
1238,
8,
277,
14,
2297,
13560,
9,
267,
11889,
275,
8116,
14,
8108,
11355,
1872,
342,
267,
2763,
17,
29,
12275,
14,
32656,
4547,
480,
2697,
401,
11889,
12,
1318,
29,
16,
9,
267,
2763,
18,
29,
12275,
14,
32656,
4547,
480,
354,
401,
11889,
12,
1318,
29,
17,
9,
267,
291,
14,
6410,
63,
6993,
14,
740,
63,
2301,
8,
2301,
17,
9,
267,
291,
14,
6410,
63,
6993,
14,
740,
63,
2301,
8,
2301,
18,
9,
398,
291,
14,
10589,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
10589,
63,
3887,
531,
267,
291,
14,
6282,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
6282,
63,
3887,
531,
267,
291,
14,
10289,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
10289,
63,
3887,
531,
267,
291,
14,
2254,
63,
3887,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
2254,
63,
3887,
531,
267,
291,
14,
973,
63,
505,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
973,
63,
505,
531,
267,
291,
14,
505,
63,
2738,
275,
291,
14,
973,
63,
505,
14,
362,
63,
2738,
342,
398,
291,
14,
1210,
63,
5842,
275,
291,
14,
973,
63,
3806,
63,
1652,
14,
362,
63,
3440,
480,
1210,
63,
5842,
531,
398,
291,
14,
15023,
63,
18804,
275,
942,
398,
291,
14,
10289,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
398,
291,
14,
22416,
275,
1052,
267,
291,
14,
4553,
275,
1052,
267,
291,
14,
7423,
275,
1052,
398,
327,
314,
22721,
18772,
267,
291,
14,
1000,
63,
5096,
275,
488,
199,
199,
3,
10894,
11621,
4673,
8297,
339,
347,
17242,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
8116,
14,
973,
63,
10589,
342,
339,
347,
8000,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
291,
14,
10589,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
267,
291,
14,
6282,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
199,
3,
263,
291,
14,
10289,
63,
3887,
14,
409,
63,
7361,
8,
797,
9,
2728,
291,
14,
2297,
13560,
14,
3584,
342,
267,
367,
5552,
12,
536,
315,
10030,
16453,
14,
18861,
63,
6410,
334,
3892,
63,
1247,
275,
715,
304,
288,
291,
14,
2297,
13560,
14,
740,
3666,
2697,
12,
536,
430,
398,
291,
14,
10589,
63,
3887,
14,
409,
63,
7361,
8,
549,
9,
267,
291,
14,
6282,
63,
3887,
14,
409,
63,
7361,
8,
549,
9,
199,
3,
263,
291,
14,
10289,
63,
3887,
14,
409,
63,
7361,
8,
549,
9,
339,
347,
3222,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
1318,
275,
291,
14,
1210,
63,
5842,
14,
362,
63,
505,
342,
267,
340,
822,
8,
505,
9,
508,
378,
26,
372,
398,
367,
5552,
12,
6771,
315,
769,
8,
277,
14,
22416,
14,
1744,
5109,
288,
6771,
14,
2254,
8,
505,
9,
398,
291,
14,
1210,
63,
5842,
14,
409,
63,
505,
10804,
267,
291,
14,
525,
63,
505,
4582,
78,
278,
446,
450,
83,
2,
450,
1318,
9,
339,
347,
21472,
63,
3887,
63,
11276,
8,
277,
12,
3938,
304,
267,
334,
1238,
12,
2740,
9,
275,
291,
14,
6410,
63,
6993,
14,
362,
63,
5592,
1252,
362,
63,
5511,
342,
267,
340,
2740,
365,
440,
488,
26,
288,
5552,
275,
1402,
14,
362,
63,
585,
8,
1661,
12,
378,
9,
288,
340,
5552,
440,
315,
291,
14,
22416,
26,
355,
291,
14,
525,
63,
505,
4582,
78,
2242,
316,
370,
450,
83,
2,
450,
5552,
9,
355,
291,
14,
2242,
8,
2697,
9,
288,
587,
26,
355,
291,
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,
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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
] |
NicovincX2/Python-3.5
|
Algèbre/Opération/scalar_product.py
|
1
|
1933
|
# -*- coding: utf-8 -*-
import os
import seaborn
seaborn.set()
colors = seaborn.color_palette()
import utils
# For 3D plotting we need to import some extra stuff
from mpl_toolkits.mplot3d import Axes3D
# First create two random vectors in 3 dimensional space
v1 = rand(3, 1)
v2 = rand(3, 1)
# And scale them to unit length
v1 = v1 / norm(v1)
v2 = v2 / norm(v2)
# Plot the vectors
o = zeros(3) # origin
# We'll use the object oriented plotting interface
f = figure(figsize=(8, 8))
ax = f.add_subplot(111, projection="3d", axisbg="white")
ax.plot(*[[o[i], v1[i]] for i in range(3)], linewidth=3, label="vector1")
ax.plot(*[[o[i], v2[i]] for i in range(3)], linewidth=3, label="vector2")
for axisl in ["x", "y", "z"]:
getattr(ax, "set_%slabel" % axisl)(axisl) # Here's a fun trick
legend()
f = figure(figsize=(8, 8))
ax = f.add_subplot(111, projection="3d", axisbg="white")
ax.plot(*[[o[i], v1[i]] for i in range(3)], linewidth=3, label="vector1")
ax.plot(*[[o[i], v2[i]] for i in range(3)], linewidth=3, label="vector2")
for axisl in ["x", "y", "z"]:
getattr(ax, "set_%slabel" % axisl)(axisl) # Here's a fun trick
legend()
for i in range(100):
# generate a point that is a weighted sum of the 2 vectors
w1 = randn(1)
w2 = randn(1)
point = w1 * v1 + w2 * v2
ax.plot(*point, marker=".", color="k")
# We can find a vector that is orthogonal to the plane defined by v1 and v2
# by taking the vector cross product. See the wikipedia page for a
# definition of cross product
# Must be right shape for cross()
v3 = cross(v1.reshape(1, 3), v2.reshape(1, 3)).squeeze()
ax.plot(*[[o[i], v3[i]] for i in range(3)],
linewidth=3, label="orthogonal vector")
legend()
print(v3[0] * v1[0] + v3[1] * v1[1] + v3[2] * v1[2])
print(dot(v3, v1))
theta = arccos(dot(v2.T, v1)).squeeze()
# and radians can be converted to degrees
theta_deg = theta * (180 / pi)
print(theta, theta_deg)
os.system("pause")
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
542,
371,
6161,
199,
199,
261,
371,
6161,
14,
409,
342,
199,
7120,
275,
542,
371,
6161,
14,
2326,
63,
16506,
342,
199,
199,
646,
3778,
199,
199,
3,
2104,
650,
36,
25174,
781,
1929,
370,
492,
2005,
2402,
8292,
199,
504,
22513,
63,
3557,
75,
1405,
14,
311,
1653,
19,
68,
492,
437,
12908,
19,
36,
199,
199,
3,
7758,
1218,
2877,
2196,
11102,
315,
650,
28341,
4601,
199,
86,
17,
275,
10261,
8,
19,
12,
413,
9,
199,
86,
18,
275,
10261,
8,
19,
12,
413,
9,
199,
199,
3,
6061,
4666,
3062,
370,
4137,
2582,
199,
86,
17,
275,
373,
17,
1182,
6316,
8,
86,
17,
9,
199,
86,
18,
275,
373,
18,
1182,
6316,
8,
86,
18,
9,
199,
199,
3,
14794,
314,
11102,
199,
79,
275,
10136,
8,
19,
9,
221,
327,
6330,
199,
199,
3,
2136,
7171,
675,
314,
909,
503,
24555,
471,
25174,
3217,
199,
70,
275,
9658,
8,
23899,
2687,
24,
12,
1695,
430,
199,
1219,
275,
289,
14,
525,
63,
13334,
8,
6673,
12,
14777,
628,
19,
68,
401,
3114,
6856,
628,
7510,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
17,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
17,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
18,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
18,
531,
199,
509,
3114,
76,
315,
2097,
88,
401,
298,
89,
401,
298,
90,
6229,
272,
2519,
8,
1219,
12,
298,
409,
4970,
83,
1302,
2,
450,
3114,
76,
5130,
3127,
76,
9,
221,
327,
11842,
1159,
282,
9627,
20907,
199,
10231,
342,
199,
199,
70,
275,
9658,
8,
23899,
2687,
24,
12,
1695,
430,
199,
1219,
275,
289,
14,
525,
63,
13334,
8,
6673,
12,
14777,
628,
19,
68,
401,
3114,
6856,
628,
7510,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
17,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
17,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
18,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
18,
531,
199,
509,
3114,
76,
315,
2097,
88,
401,
298,
89,
401,
298,
90,
6229,
272,
2519,
8,
1219,
12,
298,
409,
4970,
83,
1302,
2,
450,
3114,
76,
5130,
3127,
76,
9,
221,
327,
11842,
1159,
282,
9627,
20907,
199,
10231,
342,
199,
199,
509,
284,
315,
1425,
8,
1960,
304,
272,
327,
3550,
282,
2376,
626,
365,
282,
14609,
3089,
402,
314,
499,
11102,
272,
336,
17,
275,
10261,
78,
8,
17,
9,
272,
336,
18,
275,
10261,
78,
8,
17,
9,
272,
2376,
275,
336,
17,
627,
373,
17,
435,
336,
18,
627,
373,
18,
272,
2185,
14,
2798,
2031,
1403,
12,
3608,
628,
4765,
3164,
628,
75,
531,
199,
199,
3,
2136,
883,
2342,
282,
5477,
626,
365,
29069,
370,
314,
16388,
3247,
701,
373,
17,
436,
373,
18,
199,
3,
701,
16466,
314,
5477,
8059,
3336,
14,
221,
1666,
314,
336,
29386,
2034,
367,
282,
199,
3,
5492,
402,
8059,
3336,
199,
3,
9498,
506,
2451,
2215,
367,
8059,
342,
199,
86,
19,
275,
8059,
8,
86,
17,
14,
5217,
8,
17,
12,
650,
395,
373,
18,
14,
5217,
8,
17,
12,
650,
4992,
16597,
342,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
19,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
267,
21213,
29,
19,
12,
1768,
628,
11297,
19133,
5477,
531,
199,
10231,
342,
199,
199,
1361,
8,
86,
19,
59,
16,
61,
627,
373,
17,
59,
16,
61,
435,
373,
19,
59,
17,
61,
627,
373,
17,
59,
17,
61,
435,
373,
19,
59,
18,
61,
627,
373,
17,
59,
18,
566,
199,
1361,
8,
3287,
8,
86,
19,
12,
373,
17,
430,
199,
199,
9337,
275,
14972,
5197,
8,
3287,
8,
86,
18,
14,
52,
12,
373,
17,
4992,
16597,
342,
199,
3,
436,
26874,
883,
506,
6702,
370,
14358,
199,
9337,
63,
6458,
275,
12724,
627,
334,
7663,
1182,
6682,
9,
199,
1361,
8,
9337,
12,
12724,
63,
6458,
9,
199,
199,
736,
14,
2253,
480,
11241,
531,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
542,
371,
6161,
199,
199,
261,
371,
6161,
14,
409,
342,
199,
7120,
275,
542,
371,
6161,
14,
2326,
63,
16506,
342,
199,
199,
646,
3778,
199,
199,
3,
2104,
650,
36,
25174,
781,
1929,
370,
492,
2005,
2402,
8292,
199,
504,
22513,
63,
3557,
75,
1405,
14,
311,
1653,
19,
68,
492,
437,
12908,
19,
36,
199,
199,
3,
7758,
1218,
2877,
2196,
11102,
315,
650,
28341,
4601,
199,
86,
17,
275,
10261,
8,
19,
12,
413,
9,
199,
86,
18,
275,
10261,
8,
19,
12,
413,
9,
199,
199,
3,
6061,
4666,
3062,
370,
4137,
2582,
199,
86,
17,
275,
373,
17,
1182,
6316,
8,
86,
17,
9,
199,
86,
18,
275,
373,
18,
1182,
6316,
8,
86,
18,
9,
199,
199,
3,
14794,
314,
11102,
199,
79,
275,
10136,
8,
19,
9,
221,
327,
6330,
199,
199,
3,
2136,
7171,
675,
314,
909,
503,
24555,
471,
25174,
3217,
199,
70,
275,
9658,
8,
23899,
2687,
24,
12,
1695,
430,
199,
1219,
275,
289,
14,
525,
63,
13334,
8,
6673,
12,
14777,
628,
19,
68,
401,
3114,
6856,
628,
7510,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
17,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
17,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
18,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
18,
531,
199,
509,
3114,
76,
315,
2097,
88,
401,
298,
89,
401,
298,
90,
6229,
272,
2519,
8,
1219,
12,
298,
409,
4970,
83,
1302,
2,
450,
3114,
76,
5130,
3127,
76,
9,
221,
327,
11842,
1159,
282,
9627,
20907,
199,
10231,
342,
199,
199,
70,
275,
9658,
8,
23899,
2687,
24,
12,
1695,
430,
199,
1219,
275,
289,
14,
525,
63,
13334,
8,
6673,
12,
14777,
628,
19,
68,
401,
3114,
6856,
628,
7510,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
17,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
17,
531,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
18,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
21213,
29,
19,
12,
1768,
628,
4106,
18,
531,
199,
509,
3114,
76,
315,
2097,
88,
401,
298,
89,
401,
298,
90,
6229,
272,
2519,
8,
1219,
12,
298,
409,
4970,
83,
1302,
2,
450,
3114,
76,
5130,
3127,
76,
9,
221,
327,
11842,
1159,
282,
9627,
20907,
199,
10231,
342,
199,
199,
509,
284,
315,
1425,
8,
1960,
304,
272,
327,
3550,
282,
2376,
626,
365,
282,
14609,
3089,
402,
314,
499,
11102,
272,
336,
17,
275,
10261,
78,
8,
17,
9,
272,
336,
18,
275,
10261,
78,
8,
17,
9,
272,
2376,
275,
336,
17,
627,
373,
17,
435,
336,
18,
627,
373,
18,
272,
2185,
14,
2798,
2031,
1403,
12,
3608,
628,
4765,
3164,
628,
75,
531,
199,
199,
3,
2136,
883,
2342,
282,
5477,
626,
365,
29069,
370,
314,
16388,
3247,
701,
373,
17,
436,
373,
18,
199,
3,
701,
16466,
314,
5477,
8059,
3336,
14,
221,
1666,
314,
336,
29386,
2034,
367,
282,
199,
3,
5492,
402,
8059,
3336,
199,
3,
9498,
506,
2451,
2215,
367,
8059,
342,
199,
86,
19,
275,
8059,
8,
86,
17,
14,
5217,
8,
17,
12,
650,
395,
373,
18,
14,
5217,
8,
17,
12,
650,
4992,
16597,
342,
199,
1219,
14,
2798,
2031,
9046,
79,
59,
73,
467,
373,
19,
59,
73,
2677,
367,
284,
315,
1425,
8,
19,
4360,
267,
21213,
29,
19,
12,
1768,
628,
11297,
19133,
5477,
531,
199,
10231,
342,
199,
199,
1361,
8,
86,
19,
59,
16,
61,
627,
373,
17,
59,
16,
61,
435,
373,
19,
59,
17,
61,
627,
373,
17,
59,
17,
61,
435,
373,
19,
59,
18,
61,
627,
373,
17,
59,
18,
566,
199,
1361,
8,
3287,
8,
86,
19,
12,
373,
17,
430,
199,
199,
9337,
275,
14972,
5197,
8,
3287,
8,
86,
18,
14,
52,
12,
373,
17,
4992,
16597,
342,
199,
3,
436,
26874,
883,
506,
6702,
370,
14358,
199,
9337,
63,
6458,
275,
12724,
627,
334,
7663,
1182,
6682,
9,
199,
1361,
8,
9337,
12,
12724,
63,
6458,
9,
199,
199,
736,
14,
2253,
480,
11241,
531,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rimbalinux/MSISDNArea
|
djangotoolbox/test.py
|
4
|
1957
|
from .utils import object_list_to_table, equal_lists
from django.test import TestCase
from django.test.simple import DjangoTestSuiteRunner
from django.utils.unittest import TextTestRunner
import sys
try:
from StringIO import StringIO
except ImportError:
from cStringIO import StringIO
class ModelTestCase(TestCase):
"""
A test case for models that provides an easy way to validate the DB
contents against a given list of row-values.
You have to specify the model to validate using the 'model' attribute:
class MyTestCase(ModelTestCase):
model = MyModel
"""
def validate_state(self, columns, *state_table):
"""
Validates that the DB contains exactly the values given in the state
table. The list of columns is given in the columns tuple.
Example:
self.validate_state(
('a', 'b', 'c'),
(1, 2, 3),
(11, 12, 13),
)
validates that the table contains exactly two rows and that their
'a', 'b', and 'c' attributes are 1, 2, 3 for one row and 11, 12, 13
for the other row. The order of the rows doesn't matter.
"""
current_state = object_list_to_table(columns,
self.model.all())[1:]
if not equal_lists(current_state, state_table):
print 'DB state not valid:'
print 'Current state:'
print columns
for state in current_state:
print state
print 'Should be:'
for state in state_table:
print state
self.fail('DB state not valid')
class CapturingTestSuiteRunner(DjangoTestSuiteRunner):
"""Captures stdout/stderr during test and shows them next to tracebacks"""
def run_suite(self, suite, **kwargs):
return TextTestRunner(verbosity=self.verbosity, failfast=self.failfast, buffer=True).run(suite)
|
bsd-3-clause
|
[
504,
1275,
1208,
492,
909,
63,
513,
63,
475,
63,
1224,
12,
4472,
63,
6717,
202,
199,
504,
1639,
14,
396,
492,
7640,
202,
199,
504,
1639,
14,
396,
14,
4129,
492,
5634,
10591,
7446,
202,
199,
504,
1639,
14,
1208,
14,
2796,
492,
4516,
13649,
202,
199,
646,
984,
2999,
199,
893,
26,
1128,
687,
5228,
492,
5228,
202,
199,
2590,
3545,
26,
1128,
687,
15073,
492,
5228,
2999,
199,
533,
5822,
1746,
8,
1746,
304,
1128,
408,
1128,
437,
511,
1930,
367,
1709,
626,
6571,
376,
8837,
4340,
370,
4107,
314,
6249,
1128,
4072,
6169,
282,
1627,
769,
402,
1962,
13,
1459,
14,
2958,
2047,
1172,
370,
4165,
314,
1402,
370,
4107,
1808,
314,
283,
1238,
7,
2225,
26,
1128,
1021,
4932,
1746,
8,
1685,
1746,
304,
1039,
1402,
275,
4932,
1685,
1128,
408,
1128,
347,
4107,
63,
929,
8,
277,
12,
4362,
12,
627,
929,
63,
1224,
304,
1039,
408,
1039,
4821,
2335,
626,
314,
6249,
3509,
8840,
314,
1338,
1627,
315,
314,
1174,
1039,
1817,
14,
710,
769,
402,
4362,
365,
1627,
315,
314,
4362,
2008,
14,
4341,
5679,
26,
1039,
291,
14,
3502,
63,
929,
8,
1675,
661,
65,
297,
283,
66,
297,
283,
67,
659,
1675,
334,
17,
12,
499,
12,
650,
395,
1675,
334,
845,
12,
3144,
12,
4944,
395,
1039,
776,
1039,
29280,
626,
314,
1817,
3509,
8840,
2877,
4730,
436,
626,
3932,
1039,
283,
65,
297,
283,
66,
297,
436,
283,
67,
7,
3004,
787,
413,
12,
499,
12,
650,
367,
1373,
1962,
436,
4119,
12,
3144,
12,
4944,
1039,
367,
314,
1163,
1962,
14,
710,
1865,
402,
314,
4730,
3181,
1133,
17247,
14,
1039,
408,
1039,
1453,
63,
929,
275,
909,
63,
513,
63,
475,
63,
1224,
8,
3406,
12,
1675,
291,
14,
1238,
14,
452,
18756,
17,
2938,
1039,
340,
440,
4472,
63,
6717,
8,
1818,
63,
929,
12,
1174,
63,
1224,
304,
1675,
870,
283,
2846,
1174,
440,
1686,
4881,
1675,
870,
283,
5639,
1174,
4881,
1675,
870,
4362,
1675,
367,
1174,
315,
1453,
63,
929,
26,
2628,
870,
1174,
1675,
870,
283,
11408,
506,
4881,
1675,
367,
1174,
315,
1174,
63,
1224,
26,
2628,
870,
1174,
1675,
291,
14,
1633,
360,
2846,
1174,
440,
1686,
358,
2999,
199,
533,
25534,
4039,
10591,
7446,
8,
9323,
10591,
7446,
304,
1128,
408,
13519,
1482,
3839,
15,
3083,
5309,
511,
436,
13703,
3062,
2163,
370,
5190,
83,
624,
1128,
347,
1255,
63,
5768,
8,
277,
12,
5241,
12,
1011,
958,
304,
1039,
372,
4516,
13649,
8,
9833,
29,
277,
14,
9833,
12,
1433,
20803,
29,
277,
14,
25829,
12,
3335,
29,
549,
680,
1065,
8,
5768,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1275,
1208,
492,
909,
63,
513,
63,
475,
63,
1224,
12,
4472,
63,
6717,
202,
199,
504,
1639,
14,
396,
492,
7640,
202,
199,
504,
1639,
14,
396,
14,
4129,
492,
5634,
10591,
7446,
202,
199,
504,
1639,
14,
1208,
14,
2796,
492,
4516,
13649,
202,
199,
646,
984,
2999,
199,
893,
26,
1128,
687,
5228,
492,
5228,
202,
199,
2590,
3545,
26,
1128,
687,
15073,
492,
5228,
2999,
199,
533,
5822,
1746,
8,
1746,
304,
1128,
408,
1128,
437,
511,
1930,
367,
1709,
626,
6571,
376,
8837,
4340,
370,
4107,
314,
6249,
1128,
4072,
6169,
282,
1627,
769,
402,
1962,
13,
1459,
14,
2958,
2047,
1172,
370,
4165,
314,
1402,
370,
4107,
1808,
314,
283,
1238,
7,
2225,
26,
1128,
1021,
4932,
1746,
8,
1685,
1746,
304,
1039,
1402,
275,
4932,
1685,
1128,
408,
1128,
347,
4107,
63,
929,
8,
277,
12,
4362,
12,
627,
929,
63,
1224,
304,
1039,
408,
1039,
4821,
2335,
626,
314,
6249,
3509,
8840,
314,
1338,
1627,
315,
314,
1174,
1039,
1817,
14,
710,
769,
402,
4362,
365,
1627,
315,
314,
4362,
2008,
14,
4341,
5679,
26,
1039,
291,
14,
3502,
63,
929,
8,
1675,
661,
65,
297,
283,
66,
297,
283,
67,
659,
1675,
334,
17,
12,
499,
12,
650,
395,
1675,
334,
845,
12,
3144,
12,
4944,
395,
1039,
776,
1039,
29280,
626,
314,
1817,
3509,
8840,
2877,
4730,
436,
626,
3932,
1039,
283,
65,
297,
283,
66,
297,
436,
283,
67,
7,
3004,
787,
413,
12,
499,
12,
650,
367,
1373,
1962,
436,
4119,
12,
3144,
12,
4944,
1039,
367,
314,
1163,
1962,
14,
710,
1865,
402,
314,
4730,
3181,
1133,
17247,
14,
1039,
408,
1039,
1453,
63,
929,
275,
909,
63,
513,
63,
475,
63,
1224,
8,
3406,
12,
1675,
291,
14,
1238,
14,
452,
18756,
17,
2938,
1039,
340,
440,
4472,
63,
6717,
8,
1818,
63,
929,
12,
1174,
63,
1224,
304,
1675,
870,
283,
2846,
1174,
440,
1686,
4881,
1675,
870,
283,
5639,
1174,
4881,
1675,
870,
4362,
1675,
367,
1174,
315,
1453,
63,
929,
26,
2628,
870,
1174,
1675,
870,
283,
11408,
506,
4881,
1675,
367,
1174,
315,
1174,
63,
1224,
26,
2628,
870,
1174,
1675,
291,
14,
1633,
360,
2846,
1174,
440,
1686,
358,
2999,
199,
533,
25534,
4039,
10591,
7446,
8,
9323,
10591,
7446,
304,
1128,
408,
13519,
1482,
3839,
15,
3083,
5309,
511,
436,
13703,
3062,
2163,
370,
5190,
83,
624,
1128,
347,
1255,
63,
5768,
8,
277,
12,
5241,
12,
1011,
958,
304,
1039,
372,
4516,
13649,
8,
9833,
29,
277,
14,
9833,
12,
1433,
20803,
29,
277,
14,
25829,
12,
3335,
29,
549,
680,
1065,
8,
5768,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
rgarcia-herrera/MCAC
|
prediction_intersect_mongodb/fuse.py
|
2
|
3865
|
import argparse
import csv
import pymongo
from bson.objectid import ObjectId
from pprint import pprint
parser = argparse.ArgumentParser(description='Load variant effect prediction file to variants table.')
parser.add_argument('--type', required=True, choices=['provean','vep'])
parser.add_argument('--sample', required=True)
parser.add_argument('--file', type=argparse.FileType('r'))
args = parser.parse_args()
client = pymongo.MongoClient("notron", 27017)
db = client.mcac
if args.type == 'provean':
bulk = db.mcac.initialize_ordered_bulk_op()
provean_file = csv.reader(args.file, delimiter="\t")
for row in provean_file:
(ROW_NO, INPUT, PROTEIN_ID,
LENGTH, STRAND, CODON_CHANGE,
POS, RESIDUE_REF, RESIDUE_ALT,
TYPE, SCORE, PREDICTION2_5,
SEQ1, CLUSTER, SCORE, PREDICTION0_05,
MEDIAN_INFO, SEQ2, dbSNP_ID, GENE_ID,
GENE_NAME, TRANSCRIPT_ID, TRANSCRIPT_STATUS,
DESCRIPTION, GC_CONTENT, CHR_BAND, FAMILY_ID,
FAMILY_DESC, UNIPROT_ID, REFSEQ_PROTEIN_ID,
MIM_ACCESSION, PFAM_ID, TIGRFAM_ID, INTERPRO_ID,
GO_TERM_ACCESSION, GO_SLIM_GOA_ACCESSION) = row
if ROW_NO.startswith('#'):
continue
if PROTEIN_ID == 'record not found':
continue
(chrom, pos, ref, alt) = INPUT.split(',')
v = { 'chrom': chrom, 'pos': pos, 'ref': ref, 'alt': alt,
'protein_id' : PROTEIN_ID,
'gene_id' : GENE_ID,
'transcript_id' : TRANSCRIPT_ID,
'provean_prediction_1': PREDICTION2_5,
'provean_prediction_2': PREDICTION0_05,
'sample' : args.sample,
}
bulk.find( { 'chrom': chrom, 'pos': pos, 'ref': ref, 'alt': alt,
'protein_id' : PROTEIN_ID,
'gene_id' : GENE_ID,
'transcript_id' : TRANSCRIPT_ID, }
).upsert().update( {'$set': v, '$push': {'provean_rows': row}} )
result = bulk.execute()
pprint(result)
if args.type == 'vep':
bulk = db.mcac.initialize_ordered_bulk_op()
vep_file = csv.reader(args.file, delimiter="\t")
for row in vep_file:
if row[0].startswith('#'):
continue
(Uploaded_variation, Location, Allele,
Gene, Feature, Feature_type, Consequence,
cDNA_position, CDS_position, Protein_position,
Amino_acids, Codons, Existing_variation, Extra) = row
(chrom, pos, variation) = Uploaded_variation.split('_')
try:
(ref, alt) = variation.split('/')
except:
continue
# grab stuff from the extra field
protein_id = ''
polyphen = ''
sift = ''
for field in Extra.split(';'):
(key, value) = field.split('=')
if key == 'ENSP':
protein_id = value
if key == 'PolyPhen':
polyphen = value.split('(')[0]
if key == 'SIFT':
sift = value.split('(')[0]
v = { 'chrom': chrom, 'pos': pos, 'ref': ref, 'alt': alt,
'protein_id' : protein_id,
'gene_id' : Gene,
'transcript_id' : Feature,
'sample' : args.sample,
'polyphen' : polyphen,
'sift' : sift,
'consequence' : Consequence
}
bulk.find( { 'chrom': chrom, 'pos': pos, 'ref': ref, 'alt': alt,
'protein_id' : protein_id,
'gene_id' : Gene,
'transcript_id' : Feature, }
).upsert().update( {'$set': v, '$push': {'vep_rows': row}} )
result = bulk.execute()
pprint(result)
|
gpl-3.0
|
[
646,
7534,
199,
646,
7392,
199,
646,
21878,
199,
504,
330,
834,
14,
1113,
31157,
492,
6935,
1304,
199,
504,
10933,
492,
10933,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
6200,
9854,
7763,
12044,
570,
370,
21169,
1817,
2659,
199,
2087,
14,
525,
63,
2094,
4517,
466,
297,
1415,
29,
549,
12,
3415,
2968,
496,
432,
290,
1673,
432,
80,
1105,
199,
2087,
14,
525,
63,
2094,
4517,
3271,
297,
1415,
29,
549,
9,
199,
2087,
14,
525,
63,
2094,
4517,
493,
297,
730,
29,
18978,
14,
20683,
360,
82,
1333,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
1258,
275,
21878,
14,
20393,
3041,
480,
1397,
2641,
401,
8087,
9570,
9,
199,
697,
275,
1890,
14,
5466,
645,
199,
199,
692,
1249,
14,
466,
508,
283,
496,
432,
290,
356,
272,
13137,
275,
1592,
14,
5466,
645,
14,
8489,
63,
8235,
63,
9377,
63,
411,
342,
5591,
557,
432,
290,
63,
493,
275,
7392,
14,
5503,
8,
589,
14,
493,
12,
11172,
21024,
84,
531,
272,
367,
1962,
315,
557,
432,
290,
63,
493,
26,
10631,
334,
11415,
63,
2826,
12,
21955,
12,
3611,
3727,
568,
63,
998,
12,
268,
491,
32106,
12,
7553,
3649,
12,
5099,
36,
615,
63,
16062,
12,
268,
510,
3100,
12,
12565,
998,
4187,
63,
8279,
12,
12565,
998,
4187,
63,
19600,
12,
268,
11511,
12,
12075,
5788,
12,
510,
7387,
6196,
1075,
18,
63,
21,
12,
268,
5795,
49,
17,
12,
13354,
22992,
12,
12075,
5788,
12,
510,
7387,
6196,
1075,
16,
63,
1717,
12,
268,
17424,
879,
63,
4531,
12,
5795,
49,
18,
12,
1592,
8199,
48,
63,
998,
12,
22813,
37,
63,
998,
12,
268,
22813,
37,
63,
2339,
12,
9074,
5622,
4461,
63,
998,
12,
9074,
5622,
4461,
63,
6305,
12,
268,
17410,
1075,
12,
31555,
63,
9663,
12,
6624,
50,
63,
23297,
12,
481,
1156,
1193,
57,
63,
998,
12,
268,
481,
1156,
1193,
57,
63,
15119,
12,
6778,
1772,
31075,
63,
998,
12,
5363,
38,
28674,
63,
2514,
3727,
568,
63,
998,
12,
268,
603,
1469,
63,
7372,
9577,
12,
17689,
1156,
63,
998,
12,
377,
1277,
11778,
1156,
63,
998,
12,
8729,
2514,
63,
998,
12,
268,
598,
47,
63,
16718,
63,
7372,
9577,
12,
598,
47,
63,
4929,
1469,
63,
13160,
33,
63,
7372,
9577,
9,
275,
1962,
398,
340,
9769,
55,
63,
2826,
14,
2460,
7863,
735,
288,
1980,
398,
340,
3611,
3727,
568,
63,
998,
508,
283,
3059,
440,
1911,
356,
288,
1980,
10631,
334,
23473,
12,
2086,
12,
2984,
12,
8791,
9,
275,
21955,
14,
1294,
11917,
398,
373,
275,
469,
283,
23473,
356,
20074,
12,
283,
1712,
356,
2086,
12,
283,
1121,
356,
2984,
12,
283,
4478,
356,
8791,
12,
1598,
283,
496,
15859,
63,
344,
7,
259,
520,
3611,
3727,
568,
63,
998,
12,
1598,
283,
10654,
63,
344,
7,
755,
520,
22813,
37,
63,
998,
12,
1598,
283,
21656,
63,
344,
7,
520,
9074,
5622,
4461,
63,
998,
12,
1598,
283,
496,
432,
290,
63,
14845,
63,
17,
356,
510,
7387,
6196,
1075,
18,
63,
21,
12,
1598,
283,
496,
432,
290,
63,
14845,
63,
18,
356,
510,
7387,
6196,
1075,
16,
63,
1717,
12,
1598,
283,
3271,
7,
3515,
520,
1249,
14,
3271,
12,
267,
789,
398,
13137,
14,
1623,
8,
469,
283,
23473,
356,
20074,
12,
283,
1712,
356,
2086,
12,
283,
1121,
356,
2984,
12,
283,
4478,
356,
8791,
12,
2151,
283,
496,
15859,
63,
344,
7,
259,
520,
3611,
3727,
568,
63,
998,
12,
2151,
283,
10654,
63,
344,
7,
755,
520,
22813,
37,
63,
998,
12,
2151,
283,
21656,
63,
344,
7,
520,
9074,
5622,
4461,
63,
998,
12,
789,
267,
7092,
384,
407,
1252,
873,
8,
30108,
409,
356,
373,
12,
4505,
5335,
356,
791,
496,
432,
290,
63,
3838,
356,
1962,
4863,
776,
15567,
754,
275,
13137,
14,
2526,
342,
5493,
10933,
8,
1099,
9,
1362,
199,
692,
1249,
14,
466,
508,
283,
432,
80,
356,
272,
13137,
275,
1592,
14,
5466,
645,
14,
8489,
63,
8235,
63,
9377,
63,
411,
342,
272,
373,
1545,
63,
493,
275,
7392,
14,
5503,
8,
589,
14,
493,
12,
11172,
21024,
84,
531,
272,
367,
1962,
315,
373,
1545,
63,
493,
26,
267,
340,
1962,
59,
16,
1055,
2460,
7863,
735,
288,
1980,
2728,
334,
21145,
63,
3808,
425,
12,
12625,
12,
4580,
274,
274,
12,
267,
598,
6349,
12,
13407,
12,
13407,
63,
466,
12,
1448,
4041,
12,
267,
286,
23372,
63,
3124,
12,
445,
3177,
63,
3124,
12,
2165,
15859,
63,
3124,
12,
267,
437,
827,
79,
63,
645,
1580,
12,
445,
364,
4654,
12,
1316,
26958,
63,
3808,
425,
12,
11177,
9,
275,
1962,
30712,
334,
23473,
12,
2086,
12,
29844,
9,
275,
4949,
4591,
63,
3808,
425,
14,
1294,
26341,
267,
862,
26,
288,
334,
1121,
12,
8791,
9,
275,
29844,
14,
1294,
7825,
267,
871,
26,
288,
1980,
398,
327,
18200,
8292,
687,
314,
2402,
901,
267,
557,
15859,
63,
344,
275,
2125,
267,
8446,
17579,
257,
275,
2125,
267,
308,
2949,
755,
275,
2125,
267,
367,
901,
315,
11177,
14,
1294,
25282,
735,
288,
334,
498,
12,
574,
9,
275,
901,
14,
1294,
23917,
288,
340,
790,
508,
283,
742,
5763,
356,
355,
557,
15859,
63,
344,
275,
574,
288,
340,
790,
508,
283,
12747,
5663,
287,
356,
355,
8446,
17579,
275,
574,
14,
1294,
14097,
5832,
16,
61,
288,
340,
790,
508,
283,
2684,
2161,
356,
355,
308,
2949,
275,
574,
14,
1294,
14097,
5832,
16,
61,
2728,
373,
275,
469,
283,
23473,
356,
20074,
12,
283,
1712,
356,
2086,
12,
283,
1121,
356,
2984,
12,
283,
4478,
356,
8791,
12,
1598,
283,
496,
15859,
63,
344,
7,
259,
520,
557,
15859,
63,
344,
12,
1598,
283,
10654,
63,
344,
7,
755,
520,
598,
6349,
12,
1598,
283,
21656,
63,
344,
7,
520,
13407,
12,
1598,
283,
3271,
7,
263,
520,
1249,
14,
3271,
12,
1598,
283,
6023,
17579,
7,
420,
520,
8446,
17579,
12,
1598,
283,
338,
856,
7,
3515,
520,
308,
2949,
12,
1598,
283,
388,
4041,
7,
257,
520,
1448,
4041,
2049,
267,
789,
398,
13137,
14,
1623,
8,
469,
283,
23473,
356,
20074
] |
[
7534,
199,
646,
7392,
199,
646,
21878,
199,
504,
330,
834,
14,
1113,
31157,
492,
6935,
1304,
199,
504,
10933,
492,
10933,
199,
199,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
6200,
9854,
7763,
12044,
570,
370,
21169,
1817,
2659,
199,
2087,
14,
525,
63,
2094,
4517,
466,
297,
1415,
29,
549,
12,
3415,
2968,
496,
432,
290,
1673,
432,
80,
1105,
199,
2087,
14,
525,
63,
2094,
4517,
3271,
297,
1415,
29,
549,
9,
199,
2087,
14,
525,
63,
2094,
4517,
493,
297,
730,
29,
18978,
14,
20683,
360,
82,
1333,
199,
589,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
1258,
275,
21878,
14,
20393,
3041,
480,
1397,
2641,
401,
8087,
9570,
9,
199,
697,
275,
1890,
14,
5466,
645,
199,
199,
692,
1249,
14,
466,
508,
283,
496,
432,
290,
356,
272,
13137,
275,
1592,
14,
5466,
645,
14,
8489,
63,
8235,
63,
9377,
63,
411,
342,
5591,
557,
432,
290,
63,
493,
275,
7392,
14,
5503,
8,
589,
14,
493,
12,
11172,
21024,
84,
531,
272,
367,
1962,
315,
557,
432,
290,
63,
493,
26,
10631,
334,
11415,
63,
2826,
12,
21955,
12,
3611,
3727,
568,
63,
998,
12,
268,
491,
32106,
12,
7553,
3649,
12,
5099,
36,
615,
63,
16062,
12,
268,
510,
3100,
12,
12565,
998,
4187,
63,
8279,
12,
12565,
998,
4187,
63,
19600,
12,
268,
11511,
12,
12075,
5788,
12,
510,
7387,
6196,
1075,
18,
63,
21,
12,
268,
5795,
49,
17,
12,
13354,
22992,
12,
12075,
5788,
12,
510,
7387,
6196,
1075,
16,
63,
1717,
12,
268,
17424,
879,
63,
4531,
12,
5795,
49,
18,
12,
1592,
8199,
48,
63,
998,
12,
22813,
37,
63,
998,
12,
268,
22813,
37,
63,
2339,
12,
9074,
5622,
4461,
63,
998,
12,
9074,
5622,
4461,
63,
6305,
12,
268,
17410,
1075,
12,
31555,
63,
9663,
12,
6624,
50,
63,
23297,
12,
481,
1156,
1193,
57,
63,
998,
12,
268,
481,
1156,
1193,
57,
63,
15119,
12,
6778,
1772,
31075,
63,
998,
12,
5363,
38,
28674,
63,
2514,
3727,
568,
63,
998,
12,
268,
603,
1469,
63,
7372,
9577,
12,
17689,
1156,
63,
998,
12,
377,
1277,
11778,
1156,
63,
998,
12,
8729,
2514,
63,
998,
12,
268,
598,
47,
63,
16718,
63,
7372,
9577,
12,
598,
47,
63,
4929,
1469,
63,
13160,
33,
63,
7372,
9577,
9,
275,
1962,
398,
340,
9769,
55,
63,
2826,
14,
2460,
7863,
735,
288,
1980,
398,
340,
3611,
3727,
568,
63,
998,
508,
283,
3059,
440,
1911,
356,
288,
1980,
10631,
334,
23473,
12,
2086,
12,
2984,
12,
8791,
9,
275,
21955,
14,
1294,
11917,
398,
373,
275,
469,
283,
23473,
356,
20074,
12,
283,
1712,
356,
2086,
12,
283,
1121,
356,
2984,
12,
283,
4478,
356,
8791,
12,
1598,
283,
496,
15859,
63,
344,
7,
259,
520,
3611,
3727,
568,
63,
998,
12,
1598,
283,
10654,
63,
344,
7,
755,
520,
22813,
37,
63,
998,
12,
1598,
283,
21656,
63,
344,
7,
520,
9074,
5622,
4461,
63,
998,
12,
1598,
283,
496,
432,
290,
63,
14845,
63,
17,
356,
510,
7387,
6196,
1075,
18,
63,
21,
12,
1598,
283,
496,
432,
290,
63,
14845,
63,
18,
356,
510,
7387,
6196,
1075,
16,
63,
1717,
12,
1598,
283,
3271,
7,
3515,
520,
1249,
14,
3271,
12,
267,
789,
398,
13137,
14,
1623,
8,
469,
283,
23473,
356,
20074,
12,
283,
1712,
356,
2086,
12,
283,
1121,
356,
2984,
12,
283,
4478,
356,
8791,
12,
2151,
283,
496,
15859,
63,
344,
7,
259,
520,
3611,
3727,
568,
63,
998,
12,
2151,
283,
10654,
63,
344,
7,
755,
520,
22813,
37,
63,
998,
12,
2151,
283,
21656,
63,
344,
7,
520,
9074,
5622,
4461,
63,
998,
12,
789,
267,
7092,
384,
407,
1252,
873,
8,
30108,
409,
356,
373,
12,
4505,
5335,
356,
791,
496,
432,
290,
63,
3838,
356,
1962,
4863,
776,
15567,
754,
275,
13137,
14,
2526,
342,
5493,
10933,
8,
1099,
9,
1362,
199,
692,
1249,
14,
466,
508,
283,
432,
80,
356,
272,
13137,
275,
1592,
14,
5466,
645,
14,
8489,
63,
8235,
63,
9377,
63,
411,
342,
272,
373,
1545,
63,
493,
275,
7392,
14,
5503,
8,
589,
14,
493,
12,
11172,
21024,
84,
531,
272,
367,
1962,
315,
373,
1545,
63,
493,
26,
267,
340,
1962,
59,
16,
1055,
2460,
7863,
735,
288,
1980,
2728,
334,
21145,
63,
3808,
425,
12,
12625,
12,
4580,
274,
274,
12,
267,
598,
6349,
12,
13407,
12,
13407,
63,
466,
12,
1448,
4041,
12,
267,
286,
23372,
63,
3124,
12,
445,
3177,
63,
3124,
12,
2165,
15859,
63,
3124,
12,
267,
437,
827,
79,
63,
645,
1580,
12,
445,
364,
4654,
12,
1316,
26958,
63,
3808,
425,
12,
11177,
9,
275,
1962,
30712,
334,
23473,
12,
2086,
12,
29844,
9,
275,
4949,
4591,
63,
3808,
425,
14,
1294,
26341,
267,
862,
26,
288,
334,
1121,
12,
8791,
9,
275,
29844,
14,
1294,
7825,
267,
871,
26,
288,
1980,
398,
327,
18200,
8292,
687,
314,
2402,
901,
267,
557,
15859,
63,
344,
275,
2125,
267,
8446,
17579,
257,
275,
2125,
267,
308,
2949,
755,
275,
2125,
267,
367,
901,
315,
11177,
14,
1294,
25282,
735,
288,
334,
498,
12,
574,
9,
275,
901,
14,
1294,
23917,
288,
340,
790,
508,
283,
742,
5763,
356,
355,
557,
15859,
63,
344,
275,
574,
288,
340,
790,
508,
283,
12747,
5663,
287,
356,
355,
8446,
17579,
275,
574,
14,
1294,
14097,
5832,
16,
61,
288,
340,
790,
508,
283,
2684,
2161,
356,
355,
308,
2949,
275,
574,
14,
1294,
14097,
5832,
16,
61,
2728,
373,
275,
469,
283,
23473,
356,
20074,
12,
283,
1712,
356,
2086,
12,
283,
1121,
356,
2984,
12,
283,
4478,
356,
8791,
12,
1598,
283,
496,
15859,
63,
344,
7,
259,
520,
557,
15859,
63,
344,
12,
1598,
283,
10654,
63,
344,
7,
755,
520,
598,
6349,
12,
1598,
283,
21656,
63,
344,
7,
520,
13407,
12,
1598,
283,
3271,
7,
263,
520,
1249,
14,
3271,
12,
1598,
283,
6023,
17579,
7,
420,
520,
8446,
17579,
12,
1598,
283,
338,
856,
7,
3515,
520,
308,
2949,
12,
1598,
283,
388,
4041,
7,
257,
520,
1448,
4041,
2049,
267,
789,
398,
13137,
14,
1623,
8,
469,
283,
23473,
356,
20074,
0
] |
[
1,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nuobit/odoo-addons
|
connector_sage/models/payroll_sage_payslip_line_payroll/binding.py
|
1
|
1439
|
# Copyright NuoBiT Solutions, S.L. (<https://www.nuobit.com>)
# Eric Antones <eantones@nuobit.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import models, fields
from odoo.addons.queue_job.job import job
class PayslipLinePayrollBinding(models.Model):
_name = 'sage.payroll.sage.payslip.line.payroll'
_inherit = 'sage.payroll.sage.payslip.line'
_sql_constraints = [
('uniq',
'unique(sage_codigo_empresa, sage_codigo_convenio, sage_fecha_registro_cv, '
'sage_ano, sage_mesd, sage_tipo_proceso, '
'sage_codigo_empleado, sage_codigo_concepto_nom)',
'Payroll Payslip with same ID on Sage already exists.'),
]
@job(default_channel='root.sage')
def import_payslip_lines(self, payslip_id, backend_record):
""" Prepare the import of payslip from Sage """
filters = {
'CodigoEmpresa': backend_record.sage_company_id,
'CodigoConvenio': payslip_id.labour_agreement_id.code,
'FechaRegistroCV': fields.Date.from_string(payslip_id.labour_agreement_id.registration_date_cv),
'Año': payslip_id.year,
'MesD': ('between', (payslip_id.month_from, payslip_id.month_to)),
'TipoProceso': payslip_id.process,
}
self.env['sage.payroll.sage.payslip.line.payroll'].import_batch(
backend=backend_record, filters=filters)
return True
|
agpl-3.0
|
[
3,
1898,
653,
13780,
17975,
52,
17991,
8653,
12,
428,
14,
44,
14,
8642,
2859,
921,
1544,
14,
4850,
79,
2075,
14,
957,
18956,
199,
3,
662,
1567,
437,
343,
4548,
665,
69,
867,
4548,
32,
4850,
79,
2075,
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,
9,
199,
199,
504,
28811,
492,
1709,
12,
1504,
199,
504,
28811,
14,
10788,
14,
1825,
63,
2423,
14,
2423,
492,
3906,
421,
199,
533,
510,
5758,
3587,
3049,
10517,
2827,
17490,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
5648,
14,
5989,
2827,
14,
5648,
14,
25854,
14,
604,
14,
5989,
2827,
7,
272,
485,
6486,
275,
283,
5648,
14,
5989,
2827,
14,
5648,
14,
25854,
14,
604,
7,
339,
485,
3009,
63,
9882,
275,
359,
267,
661,
22484,
297,
268,
283,
3235,
8,
5648,
63,
331,
28963,
63,
2109,
470,
65,
12,
28510,
63,
331,
28963,
63,
388,
7597,
12,
28510,
63,
771,
9518,
63,
18724,
293,
63,
5107,
12,
283,
268,
283,
5648,
63,
8143,
12,
28510,
63,
278,
3893,
12,
28510,
63,
280,
555,
63,
496,
823,
79,
12,
283,
268,
283,
5648,
63,
331,
28963,
63,
69,
575,
5129,
12,
28510,
63,
331,
28963,
63,
388,
301,
5816,
63,
15998,
3196,
268,
283,
10517,
2827,
510,
5758,
3587,
543,
2011,
2870,
641,
428,
474,
2575,
3495,
8038,
272,
1622,
339,
768,
2423,
8,
885,
63,
2775,
534,
1231,
14,
5648,
358,
272,
347,
492,
63,
25854,
63,
1278,
8,
277,
12,
691,
18909,
63,
344,
12,
4865,
63,
3059,
304,
267,
408,
17008,
314,
492,
402,
691,
18909,
687,
428,
474,
408,
267,
4766,
275,
469,
288,
283,
967,
28963,
37,
311,
470,
65,
356,
4865,
63,
3059,
14,
5648,
63,
4627,
63,
344,
12,
288,
283,
967,
28963,
714,
7597,
356,
691,
18909,
63,
344,
14,
5561,
567,
63,
24128,
63,
344,
14,
600,
12,
288,
283,
3456,
9518,
2872,
631,
293,
12847,
356,
1504,
14,
2506,
14,
504,
63,
875,
8,
25854,
63,
344,
14,
5561,
567,
63,
24128,
63,
344,
14,
8054,
63,
602,
63,
5107,
395,
953,
283,
33,
22692,
79,
356,
691,
18909,
63,
344,
14,
3403,
12,
288,
283,
45,
397,
36,
356,
661,
13007,
297,
334,
25854,
63,
344,
14,
4482,
63,
504,
12,
691,
18909,
63,
344,
14,
4482,
63,
475,
1826,
953,
283,
22731,
555,
919,
823,
79,
356,
691,
18909,
63,
344,
14,
1412,
12,
267,
789,
398,
291,
14,
1813,
459,
5648,
14,
5989,
2827,
14,
5648,
14,
25854,
14,
604,
14,
5989,
2827,
2278,
646,
63,
2912,
8,
288,
4865,
29,
4620,
63,
3059,
12,
4766,
29,
4273,
9,
398,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
653,
13780,
17975,
52,
17991,
8653,
12,
428,
14,
44,
14,
8642,
2859,
921,
1544,
14,
4850,
79,
2075,
14,
957,
18956,
199,
3,
662,
1567,
437,
343,
4548,
665,
69,
867,
4548,
32,
4850,
79,
2075,
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,
9,
199,
199,
504,
28811,
492,
1709,
12,
1504,
199,
504,
28811,
14,
10788,
14,
1825,
63,
2423,
14,
2423,
492,
3906,
421,
199,
533,
510,
5758,
3587,
3049,
10517,
2827,
17490,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
5648,
14,
5989,
2827,
14,
5648,
14,
25854,
14,
604,
14,
5989,
2827,
7,
272,
485,
6486,
275,
283,
5648,
14,
5989,
2827,
14,
5648,
14,
25854,
14,
604,
7,
339,
485,
3009,
63,
9882,
275,
359,
267,
661,
22484,
297,
268,
283,
3235,
8,
5648,
63,
331,
28963,
63,
2109,
470,
65,
12,
28510,
63,
331,
28963,
63,
388,
7597,
12,
28510,
63,
771,
9518,
63,
18724,
293,
63,
5107,
12,
283,
268,
283,
5648,
63,
8143,
12,
28510,
63,
278,
3893,
12,
28510,
63,
280,
555,
63,
496,
823,
79,
12,
283,
268,
283,
5648,
63,
331,
28963,
63,
69,
575,
5129,
12,
28510,
63,
331,
28963,
63,
388,
301,
5816,
63,
15998,
3196,
268,
283,
10517,
2827,
510,
5758,
3587,
543,
2011,
2870,
641,
428,
474,
2575,
3495,
8038,
272,
1622,
339,
768,
2423,
8,
885,
63,
2775,
534,
1231,
14,
5648,
358,
272,
347,
492,
63,
25854,
63,
1278,
8,
277,
12,
691,
18909,
63,
344,
12,
4865,
63,
3059,
304,
267,
408,
17008,
314,
492,
402,
691,
18909,
687,
428,
474,
408,
267,
4766,
275,
469,
288,
283,
967,
28963,
37,
311,
470,
65,
356,
4865,
63,
3059,
14,
5648,
63,
4627,
63,
344,
12,
288,
283,
967,
28963,
714,
7597,
356,
691,
18909,
63,
344,
14,
5561,
567,
63,
24128,
63,
344,
14,
600,
12,
288,
283,
3456,
9518,
2872,
631,
293,
12847,
356,
1504,
14,
2506,
14,
504,
63,
875,
8,
25854,
63,
344,
14,
5561,
567,
63,
24128,
63,
344,
14,
8054,
63,
602,
63,
5107,
395,
953,
283,
33,
22692,
79,
356,
691,
18909,
63,
344,
14,
3403,
12,
288,
283,
45,
397,
36,
356,
661,
13007,
297,
334,
25854,
63,
344,
14,
4482,
63,
504,
12,
691,
18909,
63,
344,
14,
4482,
63,
475,
1826,
953,
283,
22731,
555,
919,
823,
79,
356,
691,
18909,
63,
344,
14,
1412,
12,
267,
789,
398,
291,
14,
1813,
459,
5648,
14,
5989,
2827,
14,
5648,
14,
25854,
14,
604,
14,
5989,
2827,
2278,
646,
63,
2912,
8,
288,
4865,
29,
4620,
63,
3059,
12,
4766,
29,
4273,
9,
398,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
lerouxb/PyCAPTCHA
|
Captcha/Visual/Tests.py
|
4
|
1760
|
""" Captcha.Visual.Tests
Visual CAPTCHA tests
"""
#
# PyCAPTCHA Package
# Copyright (C) 2004 Micah Dowty <micah@navi.cx>
#
from Captcha.Visual import Text, Backgrounds, Distortions, ImageCaptcha
from Captcha import Words
import random
__all__ = ["PseudoGimpy", "AngryGimpy", "AntiSpam"]
class PseudoGimpy(ImageCaptcha):
"""A relatively easy CAPTCHA that's somewhat easy on the eyes"""
def getLayers(self):
word = Words.defaultWordList.pick()
self.addSolution(word)
return [
random.choice([
Backgrounds.CroppedImage(),
Backgrounds.TiledImage(),
]),
Text.TextLayer(word, borderSize=1),
Distortions.SineWarp(),
]
class AngryGimpy(ImageCaptcha):
"""A harder but less visually pleasing CAPTCHA"""
def getLayers(self):
word = Words.defaultWordList.pick()
self.addSolution(word)
return [
Backgrounds.TiledImage(),
Backgrounds.RandomDots(),
Text.TextLayer(word, borderSize=1),
Distortions.WigglyBlocks(),
]
class AntiSpam(ImageCaptcha):
"""A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
fontFactory = Text.FontFactory(20, "vera/VeraBd.ttf")
defaultSize = (512,50)
def getLayers(self, solution="murray@example.com"):
self.addSolution(solution)
textLayer = Text.TextLayer(solution,
borderSize = 2,
fontFactory = self.fontFactory)
return [
Backgrounds.CroppedImage(),
textLayer,
Distortions.SineWarp(amplitudeRange = (2, 4)),
]
### The End ###
|
mit
|
[
624,
25534,
9518,
14,
15039,
14,
2925,
199,
199,
15039,
445,
26086,
26363,
2295,
199,
624,
199,
3,
199,
3,
1611,
28342,
26363,
15665,
199,
3,
1898,
334,
35,
9,
8353,
603,
530,
11326,
577,
583,
369,
665,
15003,
11326,
32,
15595,
14,
11859,
30,
199,
3,
199,
199,
504,
25534,
9518,
14,
15039,
492,
4516,
12,
10257,
3928,
83,
12,
10113,
18434,
12,
6047,
13519,
9518,
199,
504,
25534,
9518,
492,
644,
5630,
199,
646,
2196,
199,
199,
363,
452,
363,
275,
2097,
23414,
39,
3236,
89,
401,
298,
2493,
71,
651,
39,
3236,
89,
401,
298,
32522,
12739,
77,
937,
421,
199,
533,
510,
9917,
39,
3236,
89,
8,
3491,
13519,
9518,
304,
272,
408,
33,
13773,
9462,
8837,
445,
26086,
26363,
626,
1159,
30362,
8837,
641,
314,
325,
5066,
624,
272,
347,
664,
16862,
8,
277,
304,
267,
4349,
275,
644,
5630,
14,
885,
10155,
1296,
14,
4510,
342,
267,
291,
14,
525,
24277,
8,
1027,
9,
267,
372,
359,
288,
2196,
14,
5095,
779,
355,
10257,
3928,
83,
14,
35,
2675,
1915,
3491,
1062,
355,
10257,
3928,
83,
14,
52,
1672,
3491,
1062,
288,
17318,
288,
4516,
14,
1872,
5003,
8,
1027,
12,
9162,
2320,
29,
17,
395,
288,
10113,
18434,
14,
51,
1132,
55,
12868,
1062,
288,
1622,
421,
199,
533,
1626,
71,
651,
39,
3236,
89,
8,
3491,
13519,
9518,
304,
272,
408,
33,
12159,
424,
1325,
6656,
21370,
3163,
299,
274,
11571,
445,
26086,
26363,
624,
272,
347,
664,
16862,
8,
277,
304,
267,
4349,
275,
644,
5630,
14,
885,
10155,
1296,
14,
4510,
342,
267,
291,
14,
525,
24277,
8,
1027,
9,
267,
372,
359,
288,
10257,
3928,
83,
14,
52,
1672,
3491,
1062,
288,
10257,
3928,
83,
14,
3883,
14004,
83,
1062,
288,
4516,
14,
1872,
5003,
8,
1027,
12,
9162,
2320,
29,
17,
395,
288,
10113,
18434,
14,
55,
528,
20984,
24996,
1062,
288,
1622,
421,
199,
533,
1626,
280,
12739,
77,
8,
3491,
13519,
9518,
304,
272,
408,
33,
6317,
13,
14458,
445,
26086,
26363,
626,
883,
506,
1202,
370,
13714,
3031,
7149,
503,
10867,
687,
31726,
624,
272,
5023,
2927,
275,
4516,
14,
6986,
2927,
8,
1165,
12,
298,
422,
65,
15,
3673,
65,
34,
68,
14,
32264,
531,
272,
849,
2320,
275,
334,
7736,
12,
1400,
9,
339,
347,
664,
16862,
8,
277,
12,
8744,
628,
77,
300,
803,
32,
2694,
14,
957,
2349,
267,
291,
14,
525,
24277,
8,
14458,
9,
398,
1318,
5003,
275,
4516,
14,
1872,
5003,
8,
14458,
12,
3521,
9162,
2320,
275,
499,
12,
3521,
5023,
2927,
275,
291,
14,
4246,
2927,
9,
398,
372,
359,
288,
10257,
3928,
83,
14,
35,
2675,
1915,
3491,
1062,
288,
1318,
5003,
12,
288,
10113,
18434,
14,
51,
1132,
55,
12868,
8,
31928,
4709,
275,
334,
18,
12,
841,
1826,
288,
1622,
199,
199,
5680,
710,
9599,
6754,
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
] |
[
25534,
9518,
14,
15039,
14,
2925,
199,
199,
15039,
445,
26086,
26363,
2295,
199,
624,
199,
3,
199,
3,
1611,
28342,
26363,
15665,
199,
3,
1898,
334,
35,
9,
8353,
603,
530,
11326,
577,
583,
369,
665,
15003,
11326,
32,
15595,
14,
11859,
30,
199,
3,
199,
199,
504,
25534,
9518,
14,
15039,
492,
4516,
12,
10257,
3928,
83,
12,
10113,
18434,
12,
6047,
13519,
9518,
199,
504,
25534,
9518,
492,
644,
5630,
199,
646,
2196,
199,
199,
363,
452,
363,
275,
2097,
23414,
39,
3236,
89,
401,
298,
2493,
71,
651,
39,
3236,
89,
401,
298,
32522,
12739,
77,
937,
421,
199,
533,
510,
9917,
39,
3236,
89,
8,
3491,
13519,
9518,
304,
272,
408,
33,
13773,
9462,
8837,
445,
26086,
26363,
626,
1159,
30362,
8837,
641,
314,
325,
5066,
624,
272,
347,
664,
16862,
8,
277,
304,
267,
4349,
275,
644,
5630,
14,
885,
10155,
1296,
14,
4510,
342,
267,
291,
14,
525,
24277,
8,
1027,
9,
267,
372,
359,
288,
2196,
14,
5095,
779,
355,
10257,
3928,
83,
14,
35,
2675,
1915,
3491,
1062,
355,
10257,
3928,
83,
14,
52,
1672,
3491,
1062,
288,
17318,
288,
4516,
14,
1872,
5003,
8,
1027,
12,
9162,
2320,
29,
17,
395,
288,
10113,
18434,
14,
51,
1132,
55,
12868,
1062,
288,
1622,
421,
199,
533,
1626,
71,
651,
39,
3236,
89,
8,
3491,
13519,
9518,
304,
272,
408,
33,
12159,
424,
1325,
6656,
21370,
3163,
299,
274,
11571,
445,
26086,
26363,
624,
272,
347,
664,
16862,
8,
277,
304,
267,
4349,
275,
644,
5630,
14,
885,
10155,
1296,
14,
4510,
342,
267,
291,
14,
525,
24277,
8,
1027,
9,
267,
372,
359,
288,
10257,
3928,
83,
14,
52,
1672,
3491,
1062,
288,
10257,
3928,
83,
14,
3883,
14004,
83,
1062,
288,
4516,
14,
1872,
5003,
8,
1027,
12,
9162,
2320,
29,
17,
395,
288,
10113,
18434,
14,
55,
528,
20984,
24996,
1062,
288,
1622,
421,
199,
533,
1626,
280,
12739,
77,
8,
3491,
13519,
9518,
304,
272,
408,
33,
6317,
13,
14458,
445,
26086,
26363,
626,
883,
506,
1202,
370,
13714,
3031,
7149,
503,
10867,
687,
31726,
624,
272,
5023,
2927,
275,
4516,
14,
6986,
2927,
8,
1165,
12,
298,
422,
65,
15,
3673,
65,
34,
68,
14,
32264,
531,
272,
849,
2320,
275,
334,
7736,
12,
1400,
9,
339,
347,
664,
16862,
8,
277,
12,
8744,
628,
77,
300,
803,
32,
2694,
14,
957,
2349,
267,
291,
14,
525,
24277,
8,
14458,
9,
398,
1318,
5003,
275,
4516,
14,
1872,
5003,
8,
14458,
12,
3521,
9162,
2320,
275,
499,
12,
3521,
5023,
2927,
275,
291,
14,
4246,
2927,
9,
398,
372,
359,
288,
10257,
3928,
83,
14,
35,
2675,
1915,
3491,
1062,
288,
1318,
5003,
12,
288,
10113,
18434,
14,
51,
1132,
55,
12868,
8,
31928,
4709,
275,
334,
18,
12,
841,
1826,
288,
1622,
199,
199,
5680,
710,
9599,
6754,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wehkamp/ansible-modules-extras
|
database/vertica/vertica_role.py
|
148
|
8202
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# 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/>.
DOCUMENTATION = """
---
module: vertica_role
version_added: '2.0'
short_description: Adds or removes Vertica database roles and assigns roles to them.
description:
- Adds or removes Vertica database role and, optionally, assign other roles.
options:
name:
description:
- Name of the role to add or remove.
required: true
assigned_roles:
description:
- Comma separated list of roles to assign to the role.
aliases: ['assigned_role']
required: false
default: null
state:
description:
- Whether to create C(present), drop C(absent) or lock C(locked) a role.
required: false
choices: ['present', 'absent']
default: present
db:
description:
- Name of the Vertica database.
required: false
default: null
cluster:
description:
- Name of the Vertica cluster.
required: false
default: localhost
port:
description:
- Vertica cluster port to connect to.
required: false
default: 5433
login_user:
description:
- The username used to authenticate with.
required: false
default: dbadmin
login_password:
description:
- The password used to authenticate with.
required: false
default: null
notes:
- The default authentication assumes that you are either logging in as or sudo'ing
to the C(dbadmin) account on the host.
- This module uses C(pyodbc), a Python ODBC database adapter. You must ensure
that C(unixODBC) and C(pyodbc) is installed on the host and properly configured.
- Configuring C(unixODBC) for Vertica requires C(Driver = /opt/vertica/lib64/libverticaodbc.so)
to be added to the C(Vertica) section of either C(/etc/odbcinst.ini) or C($HOME/.odbcinst.ini)
and both C(ErrorMessagesPath = /opt/vertica/lib64) and C(DriverManagerEncoding = UTF-16)
to be added to the C(Driver) section of either C(/etc/vertica.ini) or C($HOME/.vertica.ini).
requirements: [ 'unixODBC', 'pyodbc' ]
author: "Dariusz Owczarek (@dareko)"
"""
EXAMPLES = """
- name: creating a new vertica role
vertica_role: name=role_name db=db_name state=present
- name: creating a new vertica role with other role assigned
vertica_role: name=role_name assigned_role=other_role_name state=present
"""
try:
import pyodbc
except ImportError:
pyodbc_found = False
else:
pyodbc_found = True
class NotSupportedError(Exception):
pass
class CannotDropError(Exception):
pass
# module specific functions
def get_role_facts(cursor, role=''):
facts = {}
cursor.execute("""
select r.name, r.assigned_roles
from roles r
where (? = '' or r.name ilike ?)
""", role, role)
while True:
rows = cursor.fetchmany(100)
if not rows:
break
for row in rows:
role_key = row.name.lower()
facts[role_key] = {
'name': row.name,
'assigned_roles': []}
if row.assigned_roles:
facts[role_key]['assigned_roles'] = row.assigned_roles.replace(' ', '').split(',')
return facts
def update_roles(role_facts, cursor, role,
existing, required):
for assigned_role in set(existing) - set(required):
cursor.execute("revoke {0} from {1}".format(assigned_role, role))
for assigned_role in set(required) - set(existing):
cursor.execute("grant {0} to {1}".format(assigned_role, role))
def check(role_facts, role, assigned_roles):
role_key = role.lower()
if role_key not in role_facts:
return False
if assigned_roles and cmp(sorted(assigned_roles), sorted(role_facts[role_key]['assigned_roles'])) != 0:
return False
return True
def present(role_facts, cursor, role, assigned_roles):
role_key = role.lower()
if role_key not in role_facts:
cursor.execute("create role {0}".format(role))
update_roles(role_facts, cursor, role, [], assigned_roles)
role_facts.update(get_role_facts(cursor, role))
return True
else:
changed = False
if assigned_roles and cmp(sorted(assigned_roles), sorted(role_facts[role_key]['assigned_roles'])) != 0:
update_roles(role_facts, cursor, role,
role_facts[role_key]['assigned_roles'], assigned_roles)
changed = True
if changed:
role_facts.update(get_role_facts(cursor, role))
return changed
def absent(role_facts, cursor, role, assigned_roles):
role_key = role.lower()
if role_key in role_facts:
update_roles(role_facts, cursor, role,
role_facts[role_key]['assigned_roles'], [])
cursor.execute("drop role {0} cascade".format(role_facts[role_key]['name']))
del role_facts[role_key]
return True
else:
return False
# module logic
def main():
module = AnsibleModule(
argument_spec=dict(
role=dict(required=True, aliases=['name']),
assigned_roles=dict(default=None, aliases=['assigned_role']),
state=dict(default='present', choices=['absent', 'present']),
db=dict(default=None),
cluster=dict(default='localhost'),
port=dict(default='5433'),
login_user=dict(default='dbadmin'),
login_password=dict(default=None),
), supports_check_mode = True)
if not pyodbc_found:
module.fail_json(msg="The python pyodbc module is required.")
role = module.params['role']
assigned_roles = []
if module.params['assigned_roles']:
assigned_roles = module.params['assigned_roles'].split(',')
assigned_roles = filter(None, assigned_roles)
state = module.params['state']
db = ''
if module.params['db']:
db = module.params['db']
changed = False
try:
dsn = (
"Driver=Vertica;"
"Server={0};"
"Port={1};"
"Database={2};"
"User={3};"
"Password={4};"
"ConnectionLoadBalance={5}"
).format(module.params['cluster'], module.params['port'], db,
module.params['login_user'], module.params['login_password'], 'true')
db_conn = pyodbc.connect(dsn, autocommit=True)
cursor = db_conn.cursor()
except Exception, e:
module.fail_json(msg="Unable to connect to database: {0}.".format(e))
try:
role_facts = get_role_facts(cursor)
if module.check_mode:
changed = not check(role_facts, role, assigned_roles)
elif state == 'absent':
try:
changed = absent(role_facts, cursor, role, assigned_roles)
except pyodbc.Error, e:
module.fail_json(msg=str(e))
elif state == 'present':
try:
changed = present(role_facts, cursor, role, assigned_roles)
except pyodbc.Error, e:
module.fail_json(msg=str(e))
except NotSupportedError, e:
module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts})
except CannotDropError, e:
module.fail_json(msg=str(e), ansible_facts={'vertica_roles': role_facts})
except SystemExit:
# avoid catching this on python 2.4
raise
except Exception, e:
module.fail_json(msg=e)
module.exit_json(changed=changed, role=role, ansible_facts={'vertica_roles': role_facts})
# import ansible utilities
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
809,
15922,
63,
3756,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
3612,
63,
1802,
26,
15747,
503,
14185,
5444,
15922,
3050,
11689,
436,
465,
20440,
11689,
370,
3062,
14,
199,
1802,
26,
523,
446,
15747,
503,
14185,
5444,
15922,
3050,
4719,
436,
12,
14190,
12,
5090,
1163,
11689,
14,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4719,
370,
1050,
503,
2813,
14,
272,
1415,
26,
2549,
523,
7943,
63,
8050,
26,
272,
1369,
26,
489,
446,
5429,
391,
11673,
769,
402,
11689,
370,
5090,
370,
314,
4719,
14,
272,
5481,
26,
788,
12941,
63,
3756,
418,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
1218,
445,
8,
1881,
395,
5978,
445,
8,
5575,
9,
503,
4650,
445,
8,
9325,
9,
282,
4719,
14,
272,
1415,
26,
3055,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
849,
26,
3451,
523,
1592,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5444,
15922,
3050,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
4350,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5444,
15922,
4350,
14,
272,
1415,
26,
3055,
272,
849,
26,
11667,
523,
1844,
26,
272,
1369,
26,
489,
446,
5444,
15922,
4350,
1844,
370,
4907,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
13470,
1153,
523,
4676,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
3434,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
1592,
2113,
523,
4676,
63,
2060,
26,
272,
1369,
26,
489,
446,
710,
2505,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
5983,
26,
523,
446,
710,
849,
6299,
15194,
626,
1265,
787,
1902,
2050,
315,
465,
503,
14682,
7,
316,
272,
370,
314,
445,
8,
697,
2113,
9,
2933,
641,
314,
1591,
14,
523,
446,
961,
859,
4440,
445,
8,
647,
19887,
395,
282,
2018,
593,
23317,
3050,
12146,
14,
2047,
1471,
4868,
272,
626,
445,
8,
11864,
47,
23317,
9,
436,
445,
8,
647,
19887,
9,
365,
4903,
641,
314,
1591,
436,
7684,
7526,
14,
523,
446,
4094,
4039,
445,
8,
11864,
47,
23317,
9,
367,
5444,
15922,
5074,
445,
8,
6158,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
15,
773,
12101,
696,
19887,
14,
1152,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
3673,
15922,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
19887,
3615,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
19887,
3615,
14,
2730,
9,
272,
436,
3865,
445,
8,
547,
14508,
2042,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
9,
436,
445,
8,
6158,
2988,
7630,
275,
9094,
13,
975,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
6158,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
12101,
696,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
12101,
696,
14,
2730,
680,
199,
7538,
26,
359,
283,
11864,
47,
23317,
297,
283,
647,
19887,
7,
1622,
199,
2502,
26,
298,
36,
759,
527,
90,
593,
13683,
90,
1530,
75,
8593,
983,
264,
7697,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
6425,
282,
892,
809,
15922,
4719,
523,
809,
15922,
63,
3756,
26,
536,
29,
3756,
63,
354,
1592,
29,
697,
63,
354,
1174,
29,
1881,
199,
199,
13,
536,
26,
6425,
282,
892,
809,
15922,
4719,
543,
1163,
4719,
7943,
523,
809,
15922,
63,
3756,
26,
536,
29,
3756,
63,
354,
7943,
63,
3756,
29,
1848,
63,
3756,
63,
354,
1174,
29,
1881,
199,
624,
199,
199,
893,
26,
272,
492,
1134,
19887,
199,
2590,
3545,
26,
272,
1134,
19887,
63,
4214,
275,
756,
199,
2836,
26,
272,
1134,
19887,
63,
4214,
275,
715,
199,
199,
533,
2832,
10682,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
18435,
11070,
547,
8,
1726,
304,
272,
986,
199,
199,
3,
859,
2488,
3423,
199,
199,
318,
664,
63,
3756,
63,
5047,
8,
3937,
12,
4719,
9280,
272,
9036,
275,
1052,
272,
3920,
14,
2526,
4852,
267,
3504,
519,
14,
354,
12,
519,
14,
12941,
63,
8050,
267,
687,
11689,
519,
267,
2382,
7558,
275,
2125,
503,
519,
14,
354,
284,
2930,
5805,
9,
272,
10327,
4719,
12,
4719,
9,
272,
1830,
715,
26,
267,
4730,
275,
3920,
14,
3535,
3479,
8,
1960,
9,
267,
340,
440,
4730,
26,
288,
2059,
267,
367,
1962,
315,
4730,
26,
288,
4719,
63,
498,
275,
1962,
14,
354,
14,
2325,
342,
288,
9036,
59,
3756,
63,
498,
61,
275,
469,
355,
283,
354,
356,
1962,
14,
354,
12,
355,
283,
12941,
63,
8050,
356,
23455,
288,
340,
1962,
14,
12941,
63,
8050,
26,
355,
9036,
59,
3756,
63,
498,
2733,
12941,
63,
8050,
418,
275,
1962,
14,
12941,
63,
8050,
14,
1814,
360,
1656,
12548,
1294,
11917,
272,
372,
9036,
199,
199,
318,
1678,
63,
8050,
8,
3756,
63,
5047,
12,
3920,
12,
4719,
12,
326,
3411,
12,
1415,
304,
272,
367,
7943,
63,
3756,
315,
663,
8,
5952,
9,
446,
663,
8,
2427,
304,
267,
3920
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
809,
15922,
63,
3756,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
3612,
63,
1802,
26,
15747,
503,
14185,
5444,
15922,
3050,
11689,
436,
465,
20440,
11689,
370,
3062,
14,
199,
1802,
26,
523,
446,
15747,
503,
14185,
5444,
15922,
3050,
4719,
436,
12,
14190,
12,
5090,
1163,
11689,
14,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4719,
370,
1050,
503,
2813,
14,
272,
1415,
26,
2549,
523,
7943,
63,
8050,
26,
272,
1369,
26,
489,
446,
5429,
391,
11673,
769,
402,
11689,
370,
5090,
370,
314,
4719,
14,
272,
5481,
26,
788,
12941,
63,
3756,
418,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
1218,
445,
8,
1881,
395,
5978,
445,
8,
5575,
9,
503,
4650,
445,
8,
9325,
9,
282,
4719,
14,
272,
1415,
26,
3055,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
849,
26,
3451,
523,
1592,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5444,
15922,
3050,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
4350,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5444,
15922,
4350,
14,
272,
1415,
26,
3055,
272,
849,
26,
11667,
523,
1844,
26,
272,
1369,
26,
489,
446,
5444,
15922,
4350,
1844,
370,
4907,
370,
14,
272,
1415,
26,
3055,
272,
849,
26,
13470,
1153,
523,
4676,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
3434,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
1592,
2113,
523,
4676,
63,
2060,
26,
272,
1369,
26,
489,
446,
710,
2505,
1202,
370,
12895,
543,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
5983,
26,
523,
446,
710,
849,
6299,
15194,
626,
1265,
787,
1902,
2050,
315,
465,
503,
14682,
7,
316,
272,
370,
314,
445,
8,
697,
2113,
9,
2933,
641,
314,
1591,
14,
523,
446,
961,
859,
4440,
445,
8,
647,
19887,
395,
282,
2018,
593,
23317,
3050,
12146,
14,
2047,
1471,
4868,
272,
626,
445,
8,
11864,
47,
23317,
9,
436,
445,
8,
647,
19887,
9,
365,
4903,
641,
314,
1591,
436,
7684,
7526,
14,
523,
446,
4094,
4039,
445,
8,
11864,
47,
23317,
9,
367,
5444,
15922,
5074,
445,
8,
6158,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
15,
773,
12101,
696,
19887,
14,
1152,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
3673,
15922,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
19887,
3615,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
19887,
3615,
14,
2730,
9,
272,
436,
3865,
445,
8,
547,
14508,
2042,
275,
1182,
2992,
15,
12101,
696,
15,
773,
772,
9,
436,
445,
8,
6158,
2988,
7630,
275,
9094,
13,
975,
9,
272,
370,
506,
3483,
370,
314,
445,
8,
6158,
9,
3420,
402,
1902,
445,
29478,
6839,
15,
12101,
696,
14,
2730,
9,
503,
445,
22187,
9524,
8083,
12101,
696,
14,
2730,
680,
199,
7538,
26,
359,
283,
11864,
47,
23317,
297,
283,
647,
19887,
7,
1622,
199,
2502,
26,
298,
36,
759,
527,
90,
593,
13683,
90,
1530,
75,
8593,
983,
264,
7697,
2924,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
6425,
282,
892,
809,
15922,
4719,
523,
809,
15922,
63,
3756,
26,
536,
29,
3756,
63,
354,
1592,
29,
697,
63,
354,
1174,
29,
1881,
199,
199,
13,
536,
26,
6425,
282,
892,
809,
15922,
4719,
543,
1163,
4719,
7943,
523,
809,
15922,
63,
3756,
26,
536,
29,
3756,
63,
354,
7943,
63,
3756,
29,
1848,
63,
3756,
63,
354,
1174,
29,
1881,
199,
624,
199,
199,
893,
26,
272,
492,
1134,
19887,
199,
2590,
3545,
26,
272,
1134,
19887,
63,
4214,
275,
756,
199,
2836,
26,
272,
1134,
19887,
63,
4214,
275,
715,
199,
199,
533,
2832,
10682,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
18435,
11070,
547,
8,
1726,
304,
272,
986,
199,
199,
3,
859,
2488,
3423,
199,
199,
318,
664,
63,
3756,
63,
5047,
8,
3937,
12,
4719,
9280,
272,
9036,
275,
1052,
272,
3920,
14,
2526,
4852,
267,
3504,
519,
14,
354,
12,
519,
14,
12941,
63,
8050,
267,
687,
11689,
519,
267,
2382,
7558,
275,
2125,
503,
519,
14,
354,
284,
2930,
5805,
9,
272,
10327,
4719,
12,
4719,
9,
272,
1830,
715,
26,
267,
4730,
275,
3920,
14,
3535,
3479,
8,
1960,
9,
267,
340,
440,
4730,
26,
288,
2059,
267,
367,
1962,
315,
4730,
26,
288,
4719,
63,
498,
275,
1962,
14,
354,
14,
2325,
342,
288,
9036,
59,
3756,
63,
498,
61,
275,
469,
355,
283,
354,
356,
1962,
14,
354,
12,
355,
283,
12941,
63,
8050,
356,
23455,
288,
340,
1962,
14,
12941,
63,
8050,
26,
355,
9036,
59,
3756,
63,
498,
2733,
12941,
63,
8050,
418,
275,
1962,
14,
12941,
63,
8050,
14,
1814,
360,
1656,
12548,
1294,
11917,
272,
372,
9036,
199,
199,
318,
1678,
63,
8050,
8,
3756,
63,
5047,
12,
3920,
12,
4719,
12,
326,
3411,
12,
1415,
304,
272,
367,
7943,
63,
3756,
315,
663,
8,
5952,
9,
446,
663,
8,
2427,
304,
267,
3920,
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
] |
ArtemTeleshev/raspberrypi-linux
|
scripts/analyze_suspend.py
|
1537
|
120394
|
#!/usr/bin/python
#
# Tool for analyzing suspend/resume timing
# Copyright (c) 2013, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
#
# Authors:
# Todd Brandt <todd.e.brandt@linux.intel.com>
#
# Description:
# This tool is designed to assist kernel and OS developers in optimizing
# their linux stack's suspend/resume time. Using a kernel image built
# with a few extra options enabled, the tool will execute a suspend and
# will capture dmesg and ftrace data until resume is complete. This data
# is transformed into a device timeline and a callgraph to give a quick
# and detailed view of which devices and callbacks are taking the most
# time in suspend/resume. The output is a single html file which can be
# viewed in firefox or chrome.
#
# The following kernel build options are required:
# CONFIG_PM_DEBUG=y
# CONFIG_PM_SLEEP_DEBUG=y
# CONFIG_FTRACE=y
# CONFIG_FUNCTION_TRACER=y
# CONFIG_FUNCTION_GRAPH_TRACER=y
#
# For kernel versions older than 3.15:
# The following additional kernel parameters are required:
# (e.g. in file /etc/default/grub)
# GRUB_CMDLINE_LINUX_DEFAULT="... initcall_debug log_buf_len=16M ..."
#
# ----------------- LIBRARIES --------------------
import sys
import time
import os
import string
import re
import platform
from datetime import datetime
import struct
# ----------------- CLASSES --------------------
# Class: SystemValues
# Description:
# A global, single-instance container used to
# store system values and test parameters
class SystemValues:
version = 3.0
verbose = False
testdir = '.'
tpath = '/sys/kernel/debug/tracing/'
fpdtpath = '/sys/firmware/acpi/tables/FPDT'
epath = '/sys/kernel/debug/tracing/events/power/'
traceevents = [
'suspend_resume',
'device_pm_callback_end',
'device_pm_callback_start'
]
modename = {
'freeze': 'Suspend-To-Idle (S0)',
'standby': 'Power-On Suspend (S1)',
'mem': 'Suspend-to-RAM (S3)',
'disk': 'Suspend-to-disk (S4)'
}
mempath = '/dev/mem'
powerfile = '/sys/power/state'
suspendmode = 'mem'
hostname = 'localhost'
prefix = 'test'
teststamp = ''
dmesgfile = ''
ftracefile = ''
htmlfile = ''
rtcwake = False
rtcwaketime = 10
rtcpath = ''
android = False
adb = 'adb'
devicefilter = []
stamp = 0
execcount = 1
x2delay = 0
usecallgraph = False
usetraceevents = False
usetraceeventsonly = False
notestrun = False
altdevname = dict()
postresumetime = 0
tracertypefmt = '# tracer: (?P<t>.*)'
firmwarefmt = '# fwsuspend (?P<s>[0-9]*) fwresume (?P<r>[0-9]*)$'
postresumefmt = '# post resume time (?P<t>[0-9]*)$'
stampfmt = '# suspend-(?P<m>[0-9]{2})(?P<d>[0-9]{2})(?P<y>[0-9]{2})-'+\
'(?P<H>[0-9]{2})(?P<M>[0-9]{2})(?P<S>[0-9]{2})'+\
' (?P<host>.*) (?P<mode>.*) (?P<kernel>.*)$'
def __init__(self):
self.hostname = platform.node()
if(self.hostname == ''):
self.hostname = 'localhost'
rtc = "rtc0"
if os.path.exists('/dev/rtc'):
rtc = os.readlink('/dev/rtc')
rtc = '/sys/class/rtc/'+rtc
if os.path.exists(rtc) and os.path.exists(rtc+'/date') and \
os.path.exists(rtc+'/time') and os.path.exists(rtc+'/wakealarm'):
self.rtcpath = rtc
def setOutputFile(self):
if((self.htmlfile == '') and (self.dmesgfile != '')):
m = re.match('(?P<name>.*)_dmesg\.txt$', self.dmesgfile)
if(m):
self.htmlfile = m.group('name')+'.html'
if((self.htmlfile == '') and (self.ftracefile != '')):
m = re.match('(?P<name>.*)_ftrace\.txt$', self.ftracefile)
if(m):
self.htmlfile = m.group('name')+'.html'
if(self.htmlfile == ''):
self.htmlfile = 'output.html'
def initTestOutput(self, subdir):
if(not self.android):
self.prefix = self.hostname
v = open('/proc/version', 'r').read().strip()
kver = string.split(v)[2]
else:
self.prefix = 'android'
v = os.popen(self.adb+' shell cat /proc/version').read().strip()
kver = string.split(v)[2]
testtime = datetime.now().strftime('suspend-%m%d%y-%H%M%S')
if(subdir != "."):
self.testdir = subdir+"/"+testtime
else:
self.testdir = testtime
self.teststamp = \
'# '+testtime+' '+self.prefix+' '+self.suspendmode+' '+kver
self.dmesgfile = \
self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_dmesg.txt'
self.ftracefile = \
self.testdir+'/'+self.prefix+'_'+self.suspendmode+'_ftrace.txt'
self.htmlfile = \
self.testdir+'/'+self.prefix+'_'+self.suspendmode+'.html'
os.mkdir(self.testdir)
def setDeviceFilter(self, devnames):
self.devicefilter = string.split(devnames)
def rtcWakeAlarm(self):
os.system('echo 0 > '+self.rtcpath+'/wakealarm')
outD = open(self.rtcpath+'/date', 'r').read().strip()
outT = open(self.rtcpath+'/time', 'r').read().strip()
mD = re.match('^(?P<y>[0-9]*)-(?P<m>[0-9]*)-(?P<d>[0-9]*)', outD)
mT = re.match('^(?P<h>[0-9]*):(?P<m>[0-9]*):(?P<s>[0-9]*)', outT)
if(mD and mT):
# get the current time from hardware
utcoffset = int((datetime.now() - datetime.utcnow()).total_seconds())
dt = datetime(\
int(mD.group('y')), int(mD.group('m')), int(mD.group('d')),
int(mT.group('h')), int(mT.group('m')), int(mT.group('s')))
nowtime = int(dt.strftime('%s')) + utcoffset
else:
# if hardware time fails, use the software time
nowtime = int(datetime.now().strftime('%s'))
alarm = nowtime + self.rtcwaketime
os.system('echo %d > %s/wakealarm' % (alarm, self.rtcpath))
sysvals = SystemValues()
# Class: DeviceNode
# Description:
# A container used to create a device hierachy, with a single root node
# and a tree of child nodes. Used by Data.deviceTopology()
class DeviceNode:
name = ''
children = 0
depth = 0
def __init__(self, nodename, nodedepth):
self.name = nodename
self.children = []
self.depth = nodedepth
# Class: Data
# Description:
# The primary container for suspend/resume test data. There is one for
# each test run. The data is organized into a cronological hierarchy:
# Data.dmesg {
# root structure, started as dmesg & ftrace, but now only ftrace
# contents: times for suspend start/end, resume start/end, fwdata
# phases {
# 10 sequential, non-overlapping phases of S/R
# contents: times for phase start/end, order/color data for html
# devlist {
# device callback or action list for this phase
# device {
# a single device callback or generic action
# contents: start/stop times, pid/cpu/driver info
# parents/children, html id for timeline/callgraph
# optionally includes an ftrace callgraph
# optionally includes intradev trace events
# }
# }
# }
# }
#
class Data:
dmesg = {} # root data structure
phases = [] # ordered list of phases
start = 0.0 # test start
end = 0.0 # test end
tSuspended = 0.0 # low-level suspend start
tResumed = 0.0 # low-level resume start
tLow = 0.0 # time spent in low-level suspend (standby/freeze)
fwValid = False # is firmware data available
fwSuspend = 0 # time spent in firmware suspend
fwResume = 0 # time spent in firmware resume
dmesgtext = [] # dmesg text file in memory
testnumber = 0
idstr = ''
html_device_id = 0
stamp = 0
outfile = ''
def __init__(self, num):
idchar = 'abcdefghijklmnopqrstuvwxyz'
self.testnumber = num
self.idstr = idchar[num]
self.dmesgtext = []
self.phases = []
self.dmesg = { # fixed list of 10 phases
'suspend_prepare': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#CCFFCC', 'order': 0},
'suspend': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#88FF88', 'order': 1},
'suspend_late': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#00AA00', 'order': 2},
'suspend_noirq': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#008888', 'order': 3},
'suspend_machine': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#0000FF', 'order': 4},
'resume_machine': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#FF0000', 'order': 5},
'resume_noirq': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#FF9900', 'order': 6},
'resume_early': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#FFCC00', 'order': 7},
'resume': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#FFFF88', 'order': 8},
'resume_complete': {'list': dict(), 'start': -1.0, 'end': -1.0,
'row': 0, 'color': '#FFFFCC', 'order': 9}
}
self.phases = self.sortedPhases()
def getStart(self):
return self.dmesg[self.phases[0]]['start']
def setStart(self, time):
self.start = time
self.dmesg[self.phases[0]]['start'] = time
def getEnd(self):
return self.dmesg[self.phases[-1]]['end']
def setEnd(self, time):
self.end = time
self.dmesg[self.phases[-1]]['end'] = time
def isTraceEventOutsideDeviceCalls(self, pid, time):
for phase in self.phases:
list = self.dmesg[phase]['list']
for dev in list:
d = list[dev]
if(d['pid'] == pid and time >= d['start'] and
time <= d['end']):
return False
return True
def addIntraDevTraceEvent(self, action, name, pid, time):
if(action == 'mutex_lock_try'):
color = 'red'
elif(action == 'mutex_lock_pass'):
color = 'green'
elif(action == 'mutex_unlock'):
color = 'blue'
else:
# create separate colors based on the name
v1 = len(name)*10 % 256
v2 = string.count(name, 'e')*100 % 256
v3 = ord(name[0])*20 % 256
color = '#%06X' % ((v1*0x10000) + (v2*0x100) + v3)
for phase in self.phases:
list = self.dmesg[phase]['list']
for dev in list:
d = list[dev]
if(d['pid'] == pid and time >= d['start'] and
time <= d['end']):
e = TraceEvent(action, name, color, time)
if('traceevents' not in d):
d['traceevents'] = []
d['traceevents'].append(e)
return d
break
return 0
def capIntraDevTraceEvent(self, action, name, pid, time):
for phase in self.phases:
list = self.dmesg[phase]['list']
for dev in list:
d = list[dev]
if(d['pid'] == pid and time >= d['start'] and
time <= d['end']):
if('traceevents' not in d):
return
for e in d['traceevents']:
if(e.action == action and
e.name == name and not e.ready):
e.length = time - e.time
e.ready = True
break
return
def trimTimeVal(self, t, t0, dT, left):
if left:
if(t > t0):
if(t - dT < t0):
return t0
return t - dT
else:
return t
else:
if(t < t0 + dT):
if(t > t0):
return t0 + dT
return t + dT
else:
return t
def trimTime(self, t0, dT, left):
self.tSuspended = self.trimTimeVal(self.tSuspended, t0, dT, left)
self.tResumed = self.trimTimeVal(self.tResumed, t0, dT, left)
self.start = self.trimTimeVal(self.start, t0, dT, left)
self.end = self.trimTimeVal(self.end, t0, dT, left)
for phase in self.phases:
p = self.dmesg[phase]
p['start'] = self.trimTimeVal(p['start'], t0, dT, left)
p['end'] = self.trimTimeVal(p['end'], t0, dT, left)
list = p['list']
for name in list:
d = list[name]
d['start'] = self.trimTimeVal(d['start'], t0, dT, left)
d['end'] = self.trimTimeVal(d['end'], t0, dT, left)
if('ftrace' in d):
cg = d['ftrace']
cg.start = self.trimTimeVal(cg.start, t0, dT, left)
cg.end = self.trimTimeVal(cg.end, t0, dT, left)
for line in cg.list:
line.time = self.trimTimeVal(line.time, t0, dT, left)
if('traceevents' in d):
for e in d['traceevents']:
e.time = self.trimTimeVal(e.time, t0, dT, left)
def normalizeTime(self, tZero):
# first trim out any standby or freeze clock time
if(self.tSuspended != self.tResumed):
if(self.tResumed > tZero):
self.trimTime(self.tSuspended, \
self.tResumed-self.tSuspended, True)
else:
self.trimTime(self.tSuspended, \
self.tResumed-self.tSuspended, False)
# shift the timeline so that tZero is the new 0
self.tSuspended -= tZero
self.tResumed -= tZero
self.start -= tZero
self.end -= tZero
for phase in self.phases:
p = self.dmesg[phase]
p['start'] -= tZero
p['end'] -= tZero
list = p['list']
for name in list:
d = list[name]
d['start'] -= tZero
d['end'] -= tZero
if('ftrace' in d):
cg = d['ftrace']
cg.start -= tZero
cg.end -= tZero
for line in cg.list:
line.time -= tZero
if('traceevents' in d):
for e in d['traceevents']:
e.time -= tZero
def newPhaseWithSingleAction(self, phasename, devname, start, end, color):
for phase in self.phases:
self.dmesg[phase]['order'] += 1
self.html_device_id += 1
devid = '%s%d' % (self.idstr, self.html_device_id)
list = dict()
list[devname] = \
{'start': start, 'end': end, 'pid': 0, 'par': '',
'length': (end-start), 'row': 0, 'id': devid, 'drv': '' };
self.dmesg[phasename] = \
{'list': list, 'start': start, 'end': end,
'row': 0, 'color': color, 'order': 0}
self.phases = self.sortedPhases()
def newPhase(self, phasename, start, end, color, order):
if(order < 0):
order = len(self.phases)
for phase in self.phases[order:]:
self.dmesg[phase]['order'] += 1
if(order > 0):
p = self.phases[order-1]
self.dmesg[p]['end'] = start
if(order < len(self.phases)):
p = self.phases[order]
self.dmesg[p]['start'] = end
list = dict()
self.dmesg[phasename] = \
{'list': list, 'start': start, 'end': end,
'row': 0, 'color': color, 'order': order}
self.phases = self.sortedPhases()
def setPhase(self, phase, ktime, isbegin):
if(isbegin):
self.dmesg[phase]['start'] = ktime
else:
self.dmesg[phase]['end'] = ktime
def dmesgSortVal(self, phase):
return self.dmesg[phase]['order']
def sortedPhases(self):
return sorted(self.dmesg, key=self.dmesgSortVal)
def sortedDevices(self, phase):
list = self.dmesg[phase]['list']
slist = []
tmp = dict()
for devname in list:
dev = list[devname]
tmp[dev['start']] = devname
for t in sorted(tmp):
slist.append(tmp[t])
return slist
def fixupInitcalls(self, phase, end):
# if any calls never returned, clip them at system resume end
phaselist = self.dmesg[phase]['list']
for devname in phaselist:
dev = phaselist[devname]
if(dev['end'] < 0):
dev['end'] = end
vprint('%s (%s): callback didnt return' % (devname, phase))
def deviceFilter(self, devicefilter):
# remove all by the relatives of the filter devnames
filter = []
for phase in self.phases:
list = self.dmesg[phase]['list']
for name in devicefilter:
dev = name
while(dev in list):
if(dev not in filter):
filter.append(dev)
dev = list[dev]['par']
children = self.deviceDescendants(name, phase)
for dev in children:
if(dev not in filter):
filter.append(dev)
for phase in self.phases:
list = self.dmesg[phase]['list']
rmlist = []
for name in list:
pid = list[name]['pid']
if(name not in filter and pid >= 0):
rmlist.append(name)
for name in rmlist:
del list[name]
def fixupInitcallsThatDidntReturn(self):
# if any calls never returned, clip them at system resume end
for phase in self.phases:
self.fixupInitcalls(phase, self.getEnd())
def newActionGlobal(self, name, start, end):
# which phase is this device callback or action "in"
targetphase = "none"
overlap = 0.0
for phase in self.phases:
pstart = self.dmesg[phase]['start']
pend = self.dmesg[phase]['end']
o = max(0, min(end, pend) - max(start, pstart))
if(o > overlap):
targetphase = phase
overlap = o
if targetphase in self.phases:
self.newAction(targetphase, name, -1, '', start, end, '')
return True
return False
def newAction(self, phase, name, pid, parent, start, end, drv):
# new device callback for a specific phase
self.html_device_id += 1
devid = '%s%d' % (self.idstr, self.html_device_id)
list = self.dmesg[phase]['list']
length = -1.0
if(start >= 0 and end >= 0):
length = end - start
list[name] = {'start': start, 'end': end, 'pid': pid, 'par': parent,
'length': length, 'row': 0, 'id': devid, 'drv': drv }
def deviceIDs(self, devlist, phase):
idlist = []
list = self.dmesg[phase]['list']
for devname in list:
if devname in devlist:
idlist.append(list[devname]['id'])
return idlist
def deviceParentID(self, devname, phase):
pdev = ''
pdevid = ''
list = self.dmesg[phase]['list']
if devname in list:
pdev = list[devname]['par']
if pdev in list:
return list[pdev]['id']
return pdev
def deviceChildren(self, devname, phase):
devlist = []
list = self.dmesg[phase]['list']
for child in list:
if(list[child]['par'] == devname):
devlist.append(child)
return devlist
def deviceDescendants(self, devname, phase):
children = self.deviceChildren(devname, phase)
family = children
for child in children:
family += self.deviceDescendants(child, phase)
return family
def deviceChildrenIDs(self, devname, phase):
devlist = self.deviceChildren(devname, phase)
return self.deviceIDs(devlist, phase)
def printDetails(self):
vprint(' test start: %f' % self.start)
for phase in self.phases:
dc = len(self.dmesg[phase]['list'])
vprint(' %16s: %f - %f (%d devices)' % (phase, \
self.dmesg[phase]['start'], self.dmesg[phase]['end'], dc))
vprint(' test end: %f' % self.end)
def masterTopology(self, name, list, depth):
node = DeviceNode(name, depth)
for cname in list:
clist = self.deviceChildren(cname, 'resume')
cnode = self.masterTopology(cname, clist, depth+1)
node.children.append(cnode)
return node
def printTopology(self, node):
html = ''
if node.name:
info = ''
drv = ''
for phase in self.phases:
list = self.dmesg[phase]['list']
if node.name in list:
s = list[node.name]['start']
e = list[node.name]['end']
if list[node.name]['drv']:
drv = ' {'+list[node.name]['drv']+'}'
info += ('<li>%s: %.3fms</li>' % (phase, (e-s)*1000))
html += '<li><b>'+node.name+drv+'</b>'
if info:
html += '<ul>'+info+'</ul>'
html += '</li>'
if len(node.children) > 0:
html += '<ul>'
for cnode in node.children:
html += self.printTopology(cnode)
html += '</ul>'
return html
def rootDeviceList(self):
# list of devices graphed
real = []
for phase in self.dmesg:
list = self.dmesg[phase]['list']
for dev in list:
if list[dev]['pid'] >= 0 and dev not in real:
real.append(dev)
# list of top-most root devices
rootlist = []
for phase in self.dmesg:
list = self.dmesg[phase]['list']
for dev in list:
pdev = list[dev]['par']
if(re.match('[0-9]*-[0-9]*\.[0-9]*[\.0-9]*\:[\.0-9]*$', pdev)):
continue
if pdev and pdev not in real and pdev not in rootlist:
rootlist.append(pdev)
return rootlist
def deviceTopology(self):
rootlist = self.rootDeviceList()
master = self.masterTopology('', rootlist, 0)
return self.printTopology(master)
# Class: TraceEvent
# Description:
# A container for trace event data found in the ftrace file
class TraceEvent:
ready = False
name = ''
time = 0.0
color = '#FFFFFF'
length = 0.0
action = ''
def __init__(self, a, n, c, t):
self.action = a
self.name = n
self.color = c
self.time = t
# Class: FTraceLine
# Description:
# A container for a single line of ftrace data. There are six basic types:
# callgraph line:
# call: " dpm_run_callback() {"
# return: " }"
# leaf: " dpm_run_callback();"
# trace event:
# tracing_mark_write: SUSPEND START or RESUME COMPLETE
# suspend_resume: phase or custom exec block data
# device_pm_callback: device callback info
class FTraceLine:
time = 0.0
length = 0.0
fcall = False
freturn = False
fevent = False
depth = 0
name = ''
type = ''
def __init__(self, t, m, d):
self.time = float(t)
# is this a trace event
if(d == 'traceevent' or re.match('^ *\/\* *(?P<msg>.*) \*\/ *$', m)):
if(d == 'traceevent'):
# nop format trace event
msg = m
else:
# function_graph format trace event
em = re.match('^ *\/\* *(?P<msg>.*) \*\/ *$', m)
msg = em.group('msg')
emm = re.match('^(?P<call>.*?): (?P<msg>.*)', msg)
if(emm):
self.name = emm.group('msg')
self.type = emm.group('call')
else:
self.name = msg
self.fevent = True
return
# convert the duration to seconds
if(d):
self.length = float(d)/1000000
# the indentation determines the depth
match = re.match('^(?P<d> *)(?P<o>.*)$', m)
if(not match):
return
self.depth = self.getDepth(match.group('d'))
m = match.group('o')
# function return
if(m[0] == '}'):
self.freturn = True
if(len(m) > 1):
# includes comment with function name
match = re.match('^} *\/\* *(?P<n>.*) *\*\/$', m)
if(match):
self.name = match.group('n')
# function call
else:
self.fcall = True
# function call with children
if(m[-1] == '{'):
match = re.match('^(?P<n>.*) *\(.*', m)
if(match):
self.name = match.group('n')
# function call with no children (leaf)
elif(m[-1] == ';'):
self.freturn = True
match = re.match('^(?P<n>.*) *\(.*', m)
if(match):
self.name = match.group('n')
# something else (possibly a trace marker)
else:
self.name = m
def getDepth(self, str):
return len(str)/2
def debugPrint(self, dev):
if(self.freturn and self.fcall):
print('%s -- %f (%02d): %s(); (%.3f us)' % (dev, self.time, \
self.depth, self.name, self.length*1000000))
elif(self.freturn):
print('%s -- %f (%02d): %s} (%.3f us)' % (dev, self.time, \
self.depth, self.name, self.length*1000000))
else:
print('%s -- %f (%02d): %s() { (%.3f us)' % (dev, self.time, \
self.depth, self.name, self.length*1000000))
# Class: FTraceCallGraph
# Description:
# A container for the ftrace callgraph of a single recursive function.
# This can be a dpm_run_callback, dpm_prepare, or dpm_complete callgraph
# Each instance is tied to a single device in a single phase, and is
# comprised of an ordered list of FTraceLine objects
class FTraceCallGraph:
start = -1.0
end = -1.0
list = []
invalid = False
depth = 0
def __init__(self):
self.start = -1.0
self.end = -1.0
self.list = []
self.depth = 0
def setDepth(self, line):
if(line.fcall and not line.freturn):
line.depth = self.depth
self.depth += 1
elif(line.freturn and not line.fcall):
self.depth -= 1
line.depth = self.depth
else:
line.depth = self.depth
def addLine(self, line, match):
if(not self.invalid):
self.setDepth(line)
if(line.depth == 0 and line.freturn):
if(self.start < 0):
self.start = line.time
self.end = line.time
self.list.append(line)
return True
if(self.invalid):
return False
if(len(self.list) >= 1000000 or self.depth < 0):
if(len(self.list) > 0):
first = self.list[0]
self.list = []
self.list.append(first)
self.invalid = True
if(not match):
return False
id = 'task %s cpu %s' % (match.group('pid'), match.group('cpu'))
window = '(%f - %f)' % (self.start, line.time)
if(self.depth < 0):
print('Too much data for '+id+\
' (buffer overflow), ignoring this callback')
else:
print('Too much data for '+id+\
' '+window+', ignoring this callback')
return False
self.list.append(line)
if(self.start < 0):
self.start = line.time
return False
def slice(self, t0, tN):
minicg = FTraceCallGraph()
count = -1
firstdepth = 0
for l in self.list:
if(l.time < t0 or l.time > tN):
continue
if(count < 0):
if(not l.fcall or l.name == 'dev_driver_string'):
continue
firstdepth = l.depth
count = 0
l.depth -= firstdepth
minicg.addLine(l, 0)
if((count == 0 and l.freturn and l.fcall) or
(count > 0 and l.depth <= 0)):
break
count += 1
return minicg
def sanityCheck(self):
stack = dict()
cnt = 0
for l in self.list:
if(l.fcall and not l.freturn):
stack[l.depth] = l
cnt += 1
elif(l.freturn and not l.fcall):
if(l.depth not in stack):
return False
stack[l.depth].length = l.length
stack[l.depth] = 0
l.length = 0
cnt -= 1
if(cnt == 0):
return True
return False
def debugPrint(self, filename):
if(filename == 'stdout'):
print('[%f - %f]') % (self.start, self.end)
for l in self.list:
if(l.freturn and l.fcall):
print('%f (%02d): %s(); (%.3f us)' % (l.time, \
l.depth, l.name, l.length*1000000))
elif(l.freturn):
print('%f (%02d): %s} (%.3f us)' % (l.time, \
l.depth, l.name, l.length*1000000))
else:
print('%f (%02d): %s() { (%.3f us)' % (l.time, \
l.depth, l.name, l.length*1000000))
print(' ')
else:
fp = open(filename, 'w')
print(filename)
for l in self.list:
if(l.freturn and l.fcall):
fp.write('%f (%02d): %s(); (%.3f us)\n' % (l.time, \
l.depth, l.name, l.length*1000000))
elif(l.freturn):
fp.write('%f (%02d): %s} (%.3f us)\n' % (l.time, \
l.depth, l.name, l.length*1000000))
else:
fp.write('%f (%02d): %s() { (%.3f us)\n' % (l.time, \
l.depth, l.name, l.length*1000000))
fp.close()
# Class: Timeline
# Description:
# A container for a suspend/resume html timeline. In older versions
# of the script there were multiple timelines, but in the latest
# there is only one.
class Timeline:
html = {}
scaleH = 0.0 # height of the row as a percent of the timeline height
rowH = 0.0 # height of each row in percent of the timeline height
row_height_pixels = 30
maxrows = 0
height = 0
def __init__(self):
self.html = {
'timeline': '',
'legend': '',
'scale': ''
}
def setRows(self, rows):
self.maxrows = int(rows)
self.scaleH = 100.0/float(self.maxrows)
self.height = self.maxrows*self.row_height_pixels
r = float(self.maxrows - 1)
if(r < 1.0):
r = 1.0
self.rowH = (100.0 - self.scaleH)/r
# Class: TestRun
# Description:
# A container for a suspend/resume test run. This is necessary as
# there could be more than one, and they need to be separate.
class TestRun:
ftrace_line_fmt_fg = \
'^ *(?P<time>[0-9\.]*) *\| *(?P<cpu>[0-9]*)\)'+\
' *(?P<proc>.*)-(?P<pid>[0-9]*) *\|'+\
'[ +!]*(?P<dur>[0-9\.]*) .*\| (?P<msg>.*)'
ftrace_line_fmt_nop = \
' *(?P<proc>.*)-(?P<pid>[0-9]*) *\[(?P<cpu>[0-9]*)\] *'+\
'(?P<flags>.{4}) *(?P<time>[0-9\.]*): *'+\
'(?P<msg>.*)'
ftrace_line_fmt = ftrace_line_fmt_nop
cgformat = False
ftemp = dict()
ttemp = dict()
inthepipe = False
tracertype = ''
data = 0
def __init__(self, dataobj):
self.data = dataobj
self.ftemp = dict()
self.ttemp = dict()
def isReady(self):
if(tracertype == '' or not data):
return False
return True
def setTracerType(self, tracer):
self.tracertype = tracer
if(tracer == 'function_graph'):
self.cgformat = True
self.ftrace_line_fmt = self.ftrace_line_fmt_fg
elif(tracer == 'nop'):
self.ftrace_line_fmt = self.ftrace_line_fmt_nop
else:
doError('Invalid tracer format: [%s]' % tracer, False)
# ----------------- FUNCTIONS --------------------
# Function: vprint
# Description:
# verbose print (prints only with -verbose option)
# Arguments:
# msg: the debug/log message to print
def vprint(msg):
global sysvals
if(sysvals.verbose):
print(msg)
# Function: initFtrace
# Description:
# Configure ftrace to use trace events and/or a callgraph
def initFtrace():
global sysvals
tp = sysvals.tpath
cf = 'dpm_run_callback'
if(sysvals.usetraceeventsonly):
cf = '-e dpm_prepare -e dpm_complete -e dpm_run_callback'
if(sysvals.usecallgraph or sysvals.usetraceevents):
print('INITIALIZING FTRACE...')
# turn trace off
os.system('echo 0 > '+tp+'tracing_on')
# set the trace clock to global
os.system('echo global > '+tp+'trace_clock')
# set trace buffer to a huge value
os.system('echo nop > '+tp+'current_tracer')
os.system('echo 100000 > '+tp+'buffer_size_kb')
# initialize the callgraph trace, unless this is an x2 run
if(sysvals.usecallgraph and sysvals.execcount == 1):
# set trace type
os.system('echo function_graph > '+tp+'current_tracer')
os.system('echo "" > '+tp+'set_ftrace_filter')
# set trace format options
os.system('echo funcgraph-abstime > '+tp+'trace_options')
os.system('echo funcgraph-proc > '+tp+'trace_options')
# focus only on device suspend and resume
os.system('cat '+tp+'available_filter_functions | grep '+\
cf+' > '+tp+'set_graph_function')
if(sysvals.usetraceevents):
# turn trace events on
events = iter(sysvals.traceevents)
for e in events:
os.system('echo 1 > '+sysvals.epath+e+'/enable')
# clear the trace buffer
os.system('echo "" > '+tp+'trace')
# Function: initFtraceAndroid
# Description:
# Configure ftrace to capture trace events
def initFtraceAndroid():
global sysvals
tp = sysvals.tpath
if(sysvals.usetraceevents):
print('INITIALIZING FTRACE...')
# turn trace off
os.system(sysvals.adb+" shell 'echo 0 > "+tp+"tracing_on'")
# set the trace clock to global
os.system(sysvals.adb+" shell 'echo global > "+tp+"trace_clock'")
# set trace buffer to a huge value
os.system(sysvals.adb+" shell 'echo nop > "+tp+"current_tracer'")
os.system(sysvals.adb+" shell 'echo 10000 > "+tp+"buffer_size_kb'")
# turn trace events on
events = iter(sysvals.traceevents)
for e in events:
os.system(sysvals.adb+" shell 'echo 1 > "+\
sysvals.epath+e+"/enable'")
# clear the trace buffer
os.system(sysvals.adb+" shell 'echo \"\" > "+tp+"trace'")
# Function: verifyFtrace
# Description:
# Check that ftrace is working on the system
# Output:
# True or False
def verifyFtrace():
global sysvals
# files needed for any trace data
files = ['buffer_size_kb', 'current_tracer', 'trace', 'trace_clock',
'trace_marker', 'trace_options', 'tracing_on']
# files needed for callgraph trace data
tp = sysvals.tpath
if(sysvals.usecallgraph):
files += [
'available_filter_functions',
'set_ftrace_filter',
'set_graph_function'
]
for f in files:
if(sysvals.android):
out = os.popen(sysvals.adb+' shell ls '+tp+f).read().strip()
if(out != tp+f):
return False
else:
if(os.path.exists(tp+f) == False):
return False
return True
# Function: parseStamp
# Description:
# Pull in the stamp comment line from the data file(s),
# create the stamp, and add it to the global sysvals object
# Arguments:
# m: the valid re.match output for the stamp line
def parseStamp(m, data):
global sysvals
data.stamp = {'time': '', 'host': '', 'mode': ''}
dt = datetime(int(m.group('y'))+2000, int(m.group('m')),
int(m.group('d')), int(m.group('H')), int(m.group('M')),
int(m.group('S')))
data.stamp['time'] = dt.strftime('%B %d %Y, %I:%M:%S %p')
data.stamp['host'] = m.group('host')
data.stamp['mode'] = m.group('mode')
data.stamp['kernel'] = m.group('kernel')
sysvals.suspendmode = data.stamp['mode']
if not sysvals.stamp:
sysvals.stamp = data.stamp
# Function: diffStamp
# Description:
# compare the host, kernel, and mode fields in 3 stamps
# Arguments:
# stamp1: string array with mode, kernel, and host
# stamp2: string array with mode, kernel, and host
# Return:
# True if stamps differ, False if they're the same
def diffStamp(stamp1, stamp2):
if 'host' in stamp1 and 'host' in stamp2:
if stamp1['host'] != stamp2['host']:
return True
if 'kernel' in stamp1 and 'kernel' in stamp2:
if stamp1['kernel'] != stamp2['kernel']:
return True
if 'mode' in stamp1 and 'mode' in stamp2:
if stamp1['mode'] != stamp2['mode']:
return True
return False
# Function: doesTraceLogHaveTraceEvents
# Description:
# Quickly determine if the ftrace log has some or all of the trace events
# required for primary parsing. Set the usetraceevents and/or
# usetraceeventsonly flags in the global sysvals object
def doesTraceLogHaveTraceEvents():
global sysvals
sysvals.usetraceeventsonly = True
sysvals.usetraceevents = False
for e in sysvals.traceevents:
out = os.popen('cat '+sysvals.ftracefile+' | grep "'+e+': "').read()
if(not out):
sysvals.usetraceeventsonly = False
if(e == 'suspend_resume' and out):
sysvals.usetraceevents = True
# Function: appendIncompleteTraceLog
# Description:
# [deprecated for kernel 3.15 or newer]
# Legacy support of ftrace outputs that lack the device_pm_callback
# and/or suspend_resume trace events. The primary data should be
# taken from dmesg, and this ftrace is used only for callgraph data
# or custom actions in the timeline. The data is appended to the Data
# objects provided.
# Arguments:
# testruns: the array of Data objects obtained from parseKernelLog
def appendIncompleteTraceLog(testruns):
global sysvals
# create TestRun vessels for ftrace parsing
testcnt = len(testruns)
testidx = -1
testrun = []
for data in testruns:
testrun.append(TestRun(data))
# extract the callgraph and traceevent data
vprint('Analyzing the ftrace data...')
tf = open(sysvals.ftracefile, 'r')
for line in tf:
# remove any latent carriage returns
line = line.replace('\r\n', '')
# grab the time stamp first (signifies the start of the test run)
m = re.match(sysvals.stampfmt, line)
if(m):
testidx += 1
parseStamp(m, testrun[testidx].data)
continue
# pull out any firmware data
if(re.match(sysvals.firmwarefmt, line)):
continue
# if we havent found a test time stamp yet keep spinning til we do
if(testidx < 0):
continue
# determine the trace data type (required for further parsing)
m = re.match(sysvals.tracertypefmt, line)
if(m):
tracer = m.group('t')
testrun[testidx].setTracerType(tracer)
continue
# parse only valid lines, if this isnt one move on
m = re.match(testrun[testidx].ftrace_line_fmt, line)
if(not m):
continue
# gather the basic message data from the line
m_time = m.group('time')
m_pid = m.group('pid')
m_msg = m.group('msg')
if(testrun[testidx].cgformat):
m_param3 = m.group('dur')
else:
m_param3 = 'traceevent'
if(m_time and m_pid and m_msg):
t = FTraceLine(m_time, m_msg, m_param3)
pid = int(m_pid)
else:
continue
# the line should be a call, return, or event
if(not t.fcall and not t.freturn and not t.fevent):
continue
# only parse the ftrace data during suspend/resume
data = testrun[testidx].data
if(not testrun[testidx].inthepipe):
# look for the suspend start marker
if(t.fevent):
if(t.name == 'SUSPEND START'):
testrun[testidx].inthepipe = True
data.setStart(t.time)
continue
else:
# trace event processing
if(t.fevent):
if(t.name == 'RESUME COMPLETE'):
testrun[testidx].inthepipe = False
data.setEnd(t.time)
if(testidx == testcnt - 1):
break
continue
# general trace events have two types, begin and end
if(re.match('(?P<name>.*) begin$', t.name)):
isbegin = True
elif(re.match('(?P<name>.*) end$', t.name)):
isbegin = False
else:
continue
m = re.match('(?P<name>.*)\[(?P<val>[0-9]*)\] .*', t.name)
if(m):
val = m.group('val')
if val == '0':
name = m.group('name')
else:
name = m.group('name')+'['+val+']'
else:
m = re.match('(?P<name>.*) .*', t.name)
name = m.group('name')
# special processing for trace events
if re.match('dpm_prepare\[.*', name):
continue
elif re.match('machine_suspend.*', name):
continue
elif re.match('suspend_enter\[.*', name):
if(not isbegin):
data.dmesg['suspend_prepare']['end'] = t.time
continue
elif re.match('dpm_suspend\[.*', name):
if(not isbegin):
data.dmesg['suspend']['end'] = t.time
continue
elif re.match('dpm_suspend_late\[.*', name):
if(isbegin):
data.dmesg['suspend_late']['start'] = t.time
else:
data.dmesg['suspend_late']['end'] = t.time
continue
elif re.match('dpm_suspend_noirq\[.*', name):
if(isbegin):
data.dmesg['suspend_noirq']['start'] = t.time
else:
data.dmesg['suspend_noirq']['end'] = t.time
continue
elif re.match('dpm_resume_noirq\[.*', name):
if(isbegin):
data.dmesg['resume_machine']['end'] = t.time
data.dmesg['resume_noirq']['start'] = t.time
else:
data.dmesg['resume_noirq']['end'] = t.time
continue
elif re.match('dpm_resume_early\[.*', name):
if(isbegin):
data.dmesg['resume_early']['start'] = t.time
else:
data.dmesg['resume_early']['end'] = t.time
continue
elif re.match('dpm_resume\[.*', name):
if(isbegin):
data.dmesg['resume']['start'] = t.time
else:
data.dmesg['resume']['end'] = t.time
continue
elif re.match('dpm_complete\[.*', name):
if(isbegin):
data.dmesg['resume_complete']['start'] = t.time
else:
data.dmesg['resume_complete']['end'] = t.time
continue
# is this trace event outside of the devices calls
if(data.isTraceEventOutsideDeviceCalls(pid, t.time)):
# global events (outside device calls) are simply graphed
if(isbegin):
# store each trace event in ttemp
if(name not in testrun[testidx].ttemp):
testrun[testidx].ttemp[name] = []
testrun[testidx].ttemp[name].append(\
{'begin': t.time, 'end': t.time})
else:
# finish off matching trace event in ttemp
if(name in testrun[testidx].ttemp):
testrun[testidx].ttemp[name][-1]['end'] = t.time
else:
if(isbegin):
data.addIntraDevTraceEvent('', name, pid, t.time)
else:
data.capIntraDevTraceEvent('', name, pid, t.time)
# call/return processing
elif sysvals.usecallgraph:
# create a callgraph object for the data
if(pid not in testrun[testidx].ftemp):
testrun[testidx].ftemp[pid] = []
testrun[testidx].ftemp[pid].append(FTraceCallGraph())
# when the call is finished, see which device matches it
cg = testrun[testidx].ftemp[pid][-1]
if(cg.addLine(t, m)):
testrun[testidx].ftemp[pid].append(FTraceCallGraph())
tf.close()
for test in testrun:
# add the traceevent data to the device hierarchy
if(sysvals.usetraceevents):
for name in test.ttemp:
for event in test.ttemp[name]:
begin = event['begin']
end = event['end']
# if event starts before timeline start, expand timeline
if(begin < test.data.start):
test.data.setStart(begin)
# if event ends after timeline end, expand the timeline
if(end > test.data.end):
test.data.setEnd(end)
test.data.newActionGlobal(name, begin, end)
# add the callgraph data to the device hierarchy
for pid in test.ftemp:
for cg in test.ftemp[pid]:
if(not cg.sanityCheck()):
id = 'task %s cpu %s' % (pid, m.group('cpu'))
vprint('Sanity check failed for '+\
id+', ignoring this callback')
continue
callstart = cg.start
callend = cg.end
for p in test.data.phases:
if(test.data.dmesg[p]['start'] <= callstart and
callstart <= test.data.dmesg[p]['end']):
list = test.data.dmesg[p]['list']
for devname in list:
dev = list[devname]
if(pid == dev['pid'] and
callstart <= dev['start'] and
callend >= dev['end']):
dev['ftrace'] = cg
break
if(sysvals.verbose):
test.data.printDetails()
# add the time in between the tests as a new phase so we can see it
if(len(testruns) > 1):
t1e = testruns[0].getEnd()
t2s = testruns[-1].getStart()
testruns[-1].newPhaseWithSingleAction('user mode', \
'user mode', t1e, t2s, '#FF9966')
# Function: parseTraceLog
# Description:
# Analyze an ftrace log output file generated from this app during
# the execution phase. Used when the ftrace log is the primary data source
# and includes the suspend_resume and device_pm_callback trace events
# The ftrace filename is taken from sysvals
# Output:
# An array of Data objects
def parseTraceLog():
global sysvals
vprint('Analyzing the ftrace data...')
if(os.path.exists(sysvals.ftracefile) == False):
doError('%s doesnt exist' % sysvals.ftracefile, False)
# extract the callgraph and traceevent data
testruns = []
testdata = []
testrun = 0
data = 0
tf = open(sysvals.ftracefile, 'r')
phase = 'suspend_prepare'
for line in tf:
# remove any latent carriage returns
line = line.replace('\r\n', '')
# stamp line: each stamp means a new test run
m = re.match(sysvals.stampfmt, line)
if(m):
data = Data(len(testdata))
testdata.append(data)
testrun = TestRun(data)
testruns.append(testrun)
parseStamp(m, data)
continue
if(not data):
continue
# firmware line: pull out any firmware data
m = re.match(sysvals.firmwarefmt, line)
if(m):
data.fwSuspend = int(m.group('s'))
data.fwResume = int(m.group('r'))
if(data.fwSuspend > 0 or data.fwResume > 0):
data.fwValid = True
continue
# tracer type line: determine the trace data type
m = re.match(sysvals.tracertypefmt, line)
if(m):
tracer = m.group('t')
testrun.setTracerType(tracer)
continue
# post resume time line: did this test run include post-resume data
m = re.match(sysvals.postresumefmt, line)
if(m):
t = int(m.group('t'))
if(t > 0):
sysvals.postresumetime = t
continue
# ftrace line: parse only valid lines
m = re.match(testrun.ftrace_line_fmt, line)
if(not m):
continue
# gather the basic message data from the line
m_time = m.group('time')
m_pid = m.group('pid')
m_msg = m.group('msg')
if(testrun.cgformat):
m_param3 = m.group('dur')
else:
m_param3 = 'traceevent'
if(m_time and m_pid and m_msg):
t = FTraceLine(m_time, m_msg, m_param3)
pid = int(m_pid)
else:
continue
# the line should be a call, return, or event
if(not t.fcall and not t.freturn and not t.fevent):
continue
# only parse the ftrace data during suspend/resume
if(not testrun.inthepipe):
# look for the suspend start marker
if(t.fevent):
if(t.name == 'SUSPEND START'):
testrun.inthepipe = True
data.setStart(t.time)
continue
# trace event processing
if(t.fevent):
if(t.name == 'RESUME COMPLETE'):
if(sysvals.postresumetime > 0):
phase = 'post_resume'
data.newPhase(phase, t.time, t.time, '#FF9966', -1)
else:
testrun.inthepipe = False
data.setEnd(t.time)
continue
if(phase == 'post_resume'):
data.setEnd(t.time)
if(t.type == 'suspend_resume'):
# suspend_resume trace events have two types, begin and end
if(re.match('(?P<name>.*) begin$', t.name)):
isbegin = True
elif(re.match('(?P<name>.*) end$', t.name)):
isbegin = False
else:
continue
m = re.match('(?P<name>.*)\[(?P<val>[0-9]*)\] .*', t.name)
if(m):
val = m.group('val')
if val == '0':
name = m.group('name')
else:
name = m.group('name')+'['+val+']'
else:
m = re.match('(?P<name>.*) .*', t.name)
name = m.group('name')
# ignore these events
if(re.match('acpi_suspend\[.*', t.name) or
re.match('suspend_enter\[.*', name)):
continue
# -- phase changes --
# suspend_prepare start
if(re.match('dpm_prepare\[.*', t.name)):
phase = 'suspend_prepare'
if(not isbegin):
data.dmesg[phase]['end'] = t.time
continue
# suspend start
elif(re.match('dpm_suspend\[.*', t.name)):
phase = 'suspend'
data.setPhase(phase, t.time, isbegin)
continue
# suspend_late start
elif(re.match('dpm_suspend_late\[.*', t.name)):
phase = 'suspend_late'
data.setPhase(phase, t.time, isbegin)
continue
# suspend_noirq start
elif(re.match('dpm_suspend_noirq\[.*', t.name)):
phase = 'suspend_noirq'
data.setPhase(phase, t.time, isbegin)
if(not isbegin):
phase = 'suspend_machine'
data.dmesg[phase]['start'] = t.time
continue
# suspend_machine/resume_machine
elif(re.match('machine_suspend\[.*', t.name)):
if(isbegin):
phase = 'suspend_machine'
data.dmesg[phase]['end'] = t.time
data.tSuspended = t.time
else:
if(sysvals.suspendmode in ['mem', 'disk']):
data.dmesg['suspend_machine']['end'] = t.time
data.tSuspended = t.time
phase = 'resume_machine'
data.dmesg[phase]['start'] = t.time
data.tResumed = t.time
data.tLow = data.tResumed - data.tSuspended
continue
# resume_noirq start
elif(re.match('dpm_resume_noirq\[.*', t.name)):
phase = 'resume_noirq'
data.setPhase(phase, t.time, isbegin)
if(isbegin):
data.dmesg['resume_machine']['end'] = t.time
continue
# resume_early start
elif(re.match('dpm_resume_early\[.*', t.name)):
phase = 'resume_early'
data.setPhase(phase, t.time, isbegin)
continue
# resume start
elif(re.match('dpm_resume\[.*', t.name)):
phase = 'resume'
data.setPhase(phase, t.time, isbegin)
continue
# resume complete start
elif(re.match('dpm_complete\[.*', t.name)):
phase = 'resume_complete'
if(isbegin):
data.dmesg[phase]['start'] = t.time
continue
# is this trace event outside of the devices calls
if(data.isTraceEventOutsideDeviceCalls(pid, t.time)):
# global events (outside device calls) are simply graphed
if(name not in testrun.ttemp):
testrun.ttemp[name] = []
if(isbegin):
# create a new list entry
testrun.ttemp[name].append(\
{'begin': t.time, 'end': t.time})
else:
if(len(testrun.ttemp[name]) > 0):
# if an antry exists, assume this is its end
testrun.ttemp[name][-1]['end'] = t.time
elif(phase == 'post_resume'):
# post resume events can just have ends
testrun.ttemp[name].append({
'begin': data.dmesg[phase]['start'],
'end': t.time})
else:
if(isbegin):
data.addIntraDevTraceEvent('', name, pid, t.time)
else:
data.capIntraDevTraceEvent('', name, pid, t.time)
# device callback start
elif(t.type == 'device_pm_callback_start'):
m = re.match('(?P<drv>.*) (?P<d>.*), parent: *(?P<p>.*), .*',\
t.name);
if(not m):
continue
drv = m.group('drv')
n = m.group('d')
p = m.group('p')
if(n and p):
data.newAction(phase, n, pid, p, t.time, -1, drv)
# device callback finish
elif(t.type == 'device_pm_callback_end'):
m = re.match('(?P<drv>.*) (?P<d>.*), err.*', t.name);
if(not m):
continue
n = m.group('d')
list = data.dmesg[phase]['list']
if(n in list):
dev = list[n]
dev['length'] = t.time - dev['start']
dev['end'] = t.time
# callgraph processing
elif sysvals.usecallgraph:
# this shouldn't happen, but JIC, ignore callgraph data post-res
if(phase == 'post_resume'):
continue
# create a callgraph object for the data
if(pid not in testrun.ftemp):
testrun.ftemp[pid] = []
testrun.ftemp[pid].append(FTraceCallGraph())
# when the call is finished, see which device matches it
cg = testrun.ftemp[pid][-1]
if(cg.addLine(t, m)):
testrun.ftemp[pid].append(FTraceCallGraph())
tf.close()
for test in testruns:
# add the traceevent data to the device hierarchy
if(sysvals.usetraceevents):
for name in test.ttemp:
for event in test.ttemp[name]:
begin = event['begin']
end = event['end']
# if event starts before timeline start, expand timeline
if(begin < test.data.start):
test.data.setStart(begin)
# if event ends after timeline end, expand the timeline
if(end > test.data.end):
test.data.setEnd(end)
test.data.newActionGlobal(name, begin, end)
# add the callgraph data to the device hierarchy
borderphase = {
'dpm_prepare': 'suspend_prepare',
'dpm_complete': 'resume_complete'
}
for pid in test.ftemp:
for cg in test.ftemp[pid]:
if len(cg.list) < 2:
continue
if(not cg.sanityCheck()):
id = 'task %s cpu %s' % (pid, m.group('cpu'))
vprint('Sanity check failed for '+\
id+', ignoring this callback')
continue
callstart = cg.start
callend = cg.end
if(cg.list[0].name in borderphase):
p = borderphase[cg.list[0].name]
list = test.data.dmesg[p]['list']
for devname in list:
dev = list[devname]
if(pid == dev['pid'] and
callstart <= dev['start'] and
callend >= dev['end']):
dev['ftrace'] = cg.slice(dev['start'], dev['end'])
continue
if(cg.list[0].name != 'dpm_run_callback'):
continue
for p in test.data.phases:
if(test.data.dmesg[p]['start'] <= callstart and
callstart <= test.data.dmesg[p]['end']):
list = test.data.dmesg[p]['list']
for devname in list:
dev = list[devname]
if(pid == dev['pid'] and
callstart <= dev['start'] and
callend >= dev['end']):
dev['ftrace'] = cg
break
# fill in any missing phases
for data in testdata:
lp = data.phases[0]
for p in data.phases:
if(data.dmesg[p]['start'] < 0 and data.dmesg[p]['end'] < 0):
print('WARNING: phase "%s" is missing!' % p)
if(data.dmesg[p]['start'] < 0):
data.dmesg[p]['start'] = data.dmesg[lp]['end']
if(p == 'resume_machine'):
data.tSuspended = data.dmesg[lp]['end']
data.tResumed = data.dmesg[lp]['end']
data.tLow = 0
if(data.dmesg[p]['end'] < 0):
data.dmesg[p]['end'] = data.dmesg[p]['start']
lp = p
if(len(sysvals.devicefilter) > 0):
data.deviceFilter(sysvals.devicefilter)
data.fixupInitcallsThatDidntReturn()
if(sysvals.verbose):
data.printDetails()
# add the time in between the tests as a new phase so we can see it
if(len(testdata) > 1):
t1e = testdata[0].getEnd()
t2s = testdata[-1].getStart()
testdata[-1].newPhaseWithSingleAction('user mode', \
'user mode', t1e, t2s, '#FF9966')
return testdata
# Function: loadKernelLog
# Description:
# [deprecated for kernel 3.15.0 or newer]
# load the dmesg file into memory and fix up any ordering issues
# The dmesg filename is taken from sysvals
# Output:
# An array of empty Data objects with only their dmesgtext attributes set
def loadKernelLog():
global sysvals
vprint('Analyzing the dmesg data...')
if(os.path.exists(sysvals.dmesgfile) == False):
doError('%s doesnt exist' % sysvals.dmesgfile, False)
# there can be multiple test runs in a single file delineated by stamps
testruns = []
data = 0
lf = open(sysvals.dmesgfile, 'r')
for line in lf:
line = line.replace('\r\n', '')
idx = line.find('[')
if idx > 1:
line = line[idx:]
m = re.match(sysvals.stampfmt, line)
if(m):
if(data):
testruns.append(data)
data = Data(len(testruns))
parseStamp(m, data)
continue
if(not data):
continue
m = re.match(sysvals.firmwarefmt, line)
if(m):
data.fwSuspend = int(m.group('s'))
data.fwResume = int(m.group('r'))
if(data.fwSuspend > 0 or data.fwResume > 0):
data.fwValid = True
continue
m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
if(m):
data.dmesgtext.append(line)
if(re.match('ACPI: resume from mwait', m.group('msg'))):
print('NOTE: This suspend appears to be freeze rather than'+\
' %s, it will be treated as such' % sysvals.suspendmode)
sysvals.suspendmode = 'freeze'
else:
vprint('ignoring dmesg line: %s' % line.replace('\n', ''))
testruns.append(data)
lf.close()
if(not data):
print('ERROR: analyze_suspend header missing from dmesg log')
sys.exit()
# fix lines with same timestamp/function with the call and return swapped
for data in testruns:
last = ''
for line in data.dmesgtext:
mc = re.match('.*(\[ *)(?P<t>[0-9\.]*)(\]) calling '+\
'(?P<f>.*)\+ @ .*, parent: .*', line)
mr = re.match('.*(\[ *)(?P<t>[0-9\.]*)(\]) call '+\
'(?P<f>.*)\+ returned .* after (?P<dt>.*) usecs', last)
if(mc and mr and (mc.group('t') == mr.group('t')) and
(mc.group('f') == mr.group('f'))):
i = data.dmesgtext.index(last)
j = data.dmesgtext.index(line)
data.dmesgtext[i] = line
data.dmesgtext[j] = last
last = line
return testruns
# Function: parseKernelLog
# Description:
# [deprecated for kernel 3.15.0 or newer]
# Analyse a dmesg log output file generated from this app during
# the execution phase. Create a set of device structures in memory
# for subsequent formatting in the html output file
# This call is only for legacy support on kernels where the ftrace
# data lacks the suspend_resume or device_pm_callbacks trace events.
# Arguments:
# data: an empty Data object (with dmesgtext) obtained from loadKernelLog
# Output:
# The filled Data object
def parseKernelLog(data):
global sysvals
phase = 'suspend_runtime'
if(data.fwValid):
vprint('Firmware Suspend = %u ns, Firmware Resume = %u ns' % \
(data.fwSuspend, data.fwResume))
# dmesg phase match table
dm = {
'suspend_prepare': 'PM: Syncing filesystems.*',
'suspend': 'PM: Entering [a-z]* sleep.*',
'suspend_late': 'PM: suspend of devices complete after.*',
'suspend_noirq': 'PM: late suspend of devices complete after.*',
'suspend_machine': 'PM: noirq suspend of devices complete after.*',
'resume_machine': 'ACPI: Low-level resume complete.*',
'resume_noirq': 'ACPI: Waking up from system sleep state.*',
'resume_early': 'PM: noirq resume of devices complete after.*',
'resume': 'PM: early resume of devices complete after.*',
'resume_complete': 'PM: resume of devices complete after.*',
'post_resume': '.*Restarting tasks \.\.\..*',
}
if(sysvals.suspendmode == 'standby'):
dm['resume_machine'] = 'PM: Restoring platform NVS memory'
elif(sysvals.suspendmode == 'disk'):
dm['suspend_late'] = 'PM: freeze of devices complete after.*'
dm['suspend_noirq'] = 'PM: late freeze of devices complete after.*'
dm['suspend_machine'] = 'PM: noirq freeze of devices complete after.*'
dm['resume_machine'] = 'PM: Restoring platform NVS memory'
dm['resume_early'] = 'PM: noirq restore of devices complete after.*'
dm['resume'] = 'PM: early restore of devices complete after.*'
dm['resume_complete'] = 'PM: restore of devices complete after.*'
elif(sysvals.suspendmode == 'freeze'):
dm['resume_machine'] = 'ACPI: resume from mwait'
# action table (expected events that occur and show up in dmesg)
at = {
'sync_filesystems': {
'smsg': 'PM: Syncing filesystems.*',
'emsg': 'PM: Preparing system for mem sleep.*' },
'freeze_user_processes': {
'smsg': 'Freezing user space processes .*',
'emsg': 'Freezing remaining freezable tasks.*' },
'freeze_tasks': {
'smsg': 'Freezing remaining freezable tasks.*',
'emsg': 'PM: Entering (?P<mode>[a-z,A-Z]*) sleep.*' },
'ACPI prepare': {
'smsg': 'ACPI: Preparing to enter system sleep state.*',
'emsg': 'PM: Saving platform NVS memory.*' },
'PM vns': {
'smsg': 'PM: Saving platform NVS memory.*',
'emsg': 'Disabling non-boot CPUs .*' },
}
t0 = -1.0
cpu_start = -1.0
prevktime = -1.0
actions = dict()
for line in data.dmesgtext:
# -- preprocessing --
# parse each dmesg line into the time and message
m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
if(m):
val = m.group('ktime')
try:
ktime = float(val)
except:
doWarning('INVALID DMESG LINE: '+\
line.replace('\n', ''), 'dmesg')
continue
msg = m.group('msg')
# initialize data start to first line time
if t0 < 0:
data.setStart(ktime)
t0 = ktime
else:
continue
# hack for determining resume_machine end for freeze
if(not sysvals.usetraceevents and sysvals.suspendmode == 'freeze' \
and phase == 'resume_machine' and \
re.match('calling (?P<f>.*)\+ @ .*, parent: .*', msg)):
data.dmesg['resume_machine']['end'] = ktime
phase = 'resume_noirq'
data.dmesg[phase]['start'] = ktime
# -- phase changes --
# suspend start
if(re.match(dm['suspend_prepare'], msg)):
phase = 'suspend_prepare'
data.dmesg[phase]['start'] = ktime
data.setStart(ktime)
# suspend start
elif(re.match(dm['suspend'], msg)):
data.dmesg['suspend_prepare']['end'] = ktime
phase = 'suspend'
data.dmesg[phase]['start'] = ktime
# suspend_late start
elif(re.match(dm['suspend_late'], msg)):
data.dmesg['suspend']['end'] = ktime
phase = 'suspend_late'
data.dmesg[phase]['start'] = ktime
# suspend_noirq start
elif(re.match(dm['suspend_noirq'], msg)):
data.dmesg['suspend_late']['end'] = ktime
phase = 'suspend_noirq'
data.dmesg[phase]['start'] = ktime
# suspend_machine start
elif(re.match(dm['suspend_machine'], msg)):
data.dmesg['suspend_noirq']['end'] = ktime
phase = 'suspend_machine'
data.dmesg[phase]['start'] = ktime
# resume_machine start
elif(re.match(dm['resume_machine'], msg)):
if(sysvals.suspendmode in ['freeze', 'standby']):
data.tSuspended = prevktime
data.dmesg['suspend_machine']['end'] = prevktime
else:
data.tSuspended = ktime
data.dmesg['suspend_machine']['end'] = ktime
phase = 'resume_machine'
data.tResumed = ktime
data.tLow = data.tResumed - data.tSuspended
data.dmesg[phase]['start'] = ktime
# resume_noirq start
elif(re.match(dm['resume_noirq'], msg)):
data.dmesg['resume_machine']['end'] = ktime
phase = 'resume_noirq'
data.dmesg[phase]['start'] = ktime
# resume_early start
elif(re.match(dm['resume_early'], msg)):
data.dmesg['resume_noirq']['end'] = ktime
phase = 'resume_early'
data.dmesg[phase]['start'] = ktime
# resume start
elif(re.match(dm['resume'], msg)):
data.dmesg['resume_early']['end'] = ktime
phase = 'resume'
data.dmesg[phase]['start'] = ktime
# resume complete start
elif(re.match(dm['resume_complete'], msg)):
data.dmesg['resume']['end'] = ktime
phase = 'resume_complete'
data.dmesg[phase]['start'] = ktime
# post resume start
elif(re.match(dm['post_resume'], msg)):
data.dmesg['resume_complete']['end'] = ktime
data.setEnd(ktime)
phase = 'post_resume'
break
# -- device callbacks --
if(phase in data.phases):
# device init call
if(re.match('calling (?P<f>.*)\+ @ .*, parent: .*', msg)):
sm = re.match('calling (?P<f>.*)\+ @ '+\
'(?P<n>.*), parent: (?P<p>.*)', msg);
f = sm.group('f')
n = sm.group('n')
p = sm.group('p')
if(f and n and p):
data.newAction(phase, f, int(n), p, ktime, -1, '')
# device init return
elif(re.match('call (?P<f>.*)\+ returned .* after '+\
'(?P<t>.*) usecs', msg)):
sm = re.match('call (?P<f>.*)\+ returned .* after '+\
'(?P<t>.*) usecs(?P<a>.*)', msg);
f = sm.group('f')
t = sm.group('t')
list = data.dmesg[phase]['list']
if(f in list):
dev = list[f]
dev['length'] = int(t)
dev['end'] = ktime
# -- non-devicecallback actions --
# if trace events are not available, these are better than nothing
if(not sysvals.usetraceevents):
# look for known actions
for a in at:
if(re.match(at[a]['smsg'], msg)):
if(a not in actions):
actions[a] = []
actions[a].append({'begin': ktime, 'end': ktime})
if(re.match(at[a]['emsg'], msg)):
actions[a][-1]['end'] = ktime
# now look for CPU on/off events
if(re.match('Disabling non-boot CPUs .*', msg)):
# start of first cpu suspend
cpu_start = ktime
elif(re.match('Enabling non-boot CPUs .*', msg)):
# start of first cpu resume
cpu_start = ktime
elif(re.match('smpboot: CPU (?P<cpu>[0-9]*) is now offline', msg)):
# end of a cpu suspend, start of the next
m = re.match('smpboot: CPU (?P<cpu>[0-9]*) is now offline', msg)
cpu = 'CPU'+m.group('cpu')
if(cpu not in actions):
actions[cpu] = []
actions[cpu].append({'begin': cpu_start, 'end': ktime})
cpu_start = ktime
elif(re.match('CPU(?P<cpu>[0-9]*) is up', msg)):
# end of a cpu resume, start of the next
m = re.match('CPU(?P<cpu>[0-9]*) is up', msg)
cpu = 'CPU'+m.group('cpu')
if(cpu not in actions):
actions[cpu] = []
actions[cpu].append({'begin': cpu_start, 'end': ktime})
cpu_start = ktime
prevktime = ktime
# fill in any missing phases
lp = data.phases[0]
for p in data.phases:
if(data.dmesg[p]['start'] < 0 and data.dmesg[p]['end'] < 0):
print('WARNING: phase "%s" is missing, something went wrong!' % p)
print(' In %s, this dmesg line denotes the start of %s:' % \
(sysvals.suspendmode, p))
print(' "%s"' % dm[p])
if(data.dmesg[p]['start'] < 0):
data.dmesg[p]['start'] = data.dmesg[lp]['end']
if(p == 'resume_machine'):
data.tSuspended = data.dmesg[lp]['end']
data.tResumed = data.dmesg[lp]['end']
data.tLow = 0
if(data.dmesg[p]['end'] < 0):
data.dmesg[p]['end'] = data.dmesg[p]['start']
lp = p
# fill in any actions we've found
for name in actions:
for event in actions[name]:
begin = event['begin']
end = event['end']
# if event starts before timeline start, expand timeline
if(begin < data.start):
data.setStart(begin)
# if event ends after timeline end, expand the timeline
if(end > data.end):
data.setEnd(end)
data.newActionGlobal(name, begin, end)
if(sysvals.verbose):
data.printDetails()
if(len(sysvals.devicefilter) > 0):
data.deviceFilter(sysvals.devicefilter)
data.fixupInitcallsThatDidntReturn()
return True
# Function: setTimelineRows
# Description:
# Organize the timeline entries into the smallest
# number of rows possible, with no entry overlapping
# Arguments:
# list: the list of devices/actions for a single phase
# sortedkeys: cronologically sorted key list to use
# Output:
# The total number of rows needed to display this phase of the timeline
def setTimelineRows(list, sortedkeys):
# clear all rows and set them to undefined
remaining = len(list)
rowdata = dict()
row = 0
for item in list:
list[item]['row'] = -1
# try to pack each row with as many ranges as possible
while(remaining > 0):
if(row not in rowdata):
rowdata[row] = []
for item in sortedkeys:
if(list[item]['row'] < 0):
s = list[item]['start']
e = list[item]['end']
valid = True
for ritem in rowdata[row]:
rs = ritem['start']
re = ritem['end']
if(not (((s <= rs) and (e <= rs)) or
((s >= re) and (e >= re)))):
valid = False
break
if(valid):
rowdata[row].append(list[item])
list[item]['row'] = row
remaining -= 1
row += 1
return row
# Function: createTimeScale
# Description:
# Create the timescale header for the html timeline
# Arguments:
# t0: start time (suspend begin)
# tMax: end time (resume end)
# tSuspend: time when suspend occurs, i.e. the zero time
# Output:
# The html code needed to display the time scale
def createTimeScale(t0, tMax, tSuspended):
timescale = '<div class="t" style="right:{0}%">{1}</div>\n'
output = '<div id="timescale">\n'
# set scale for timeline
tTotal = tMax - t0
tS = 0.1
if(tTotal <= 0):
return output
if(tTotal > 4):
tS = 1
if(tSuspended < 0):
for i in range(int(tTotal/tS)+1):
pos = '%0.3f' % (100 - ((float(i)*tS*100)/tTotal))
if(i > 0):
val = '%0.fms' % (float(i)*tS*1000)
else:
val = ''
output += timescale.format(pos, val)
else:
tSuspend = tSuspended - t0
divTotal = int(tTotal/tS) + 1
divSuspend = int(tSuspend/tS)
s0 = (tSuspend - tS*divSuspend)*100/tTotal
for i in range(divTotal):
pos = '%0.3f' % (100 - ((float(i)*tS*100)/tTotal) - s0)
if((i == 0) and (s0 < 3)):
val = ''
elif(i == divSuspend):
val = 'S/R'
else:
val = '%0.fms' % (float(i-divSuspend)*tS*1000)
output += timescale.format(pos, val)
output += '</div>\n'
return output
# Function: createHTMLSummarySimple
# Description:
# Create summary html file for a series of tests
# Arguments:
# testruns: array of Data objects from parseTraceLog
def createHTMLSummarySimple(testruns, htmlfile):
global sysvals
# print out the basic summary of all the tests
hf = open(htmlfile, 'w')
# write the html header first (html head, css code, up to body start)
html = '<!DOCTYPE html>\n<html>\n<head>\n\
<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
<title>AnalyzeSuspend Summary</title>\n\
<style type=\'text/css\'>\n\
body {overflow-y: scroll;}\n\
.stamp {width: 100%;text-align:center;background-color:#495E09;line-height:30px;color:white;font: 25px Arial;}\n\
table {width:100%;border-collapse: collapse;}\n\
.summary {font: 22px Arial;border:1px solid;}\n\
th {border: 1px solid black;background-color:#A7C942;color:white;}\n\
td {text-align: center;}\n\
tr.alt td {background-color:#EAF2D3;}\n\
tr.avg td {background-color:#BDE34C;}\n\
a:link {color: #90B521;}\n\
a:visited {color: #495E09;}\n\
a:hover {color: #B1DF28;}\n\
a:active {color: #FFFFFF;}\n\
</style>\n</head>\n<body>\n'
# group test header
count = len(testruns)
headline_stamp = '<div class="stamp">{0} {1} {2} {3} ({4} tests)</div>\n'
html += headline_stamp.format(sysvals.stamp['host'],
sysvals.stamp['kernel'], sysvals.stamp['mode'],
sysvals.stamp['time'], count)
# check to see if all the tests have the same value
stampcolumns = False
for data in testruns:
if diffStamp(sysvals.stamp, data.stamp):
stampcolumns = True
break
th = '\t<th>{0}</th>\n'
td = '\t<td>{0}</td>\n'
tdlink = '\t<td><a href="{0}">Click Here</a></td>\n'
# table header
html += '<table class="summary">\n<tr>\n'
html += th.format("Test #")
if stampcolumns:
html += th.format("Hostname")
html += th.format("Kernel Version")
html += th.format("Suspend Mode")
html += th.format("Test Time")
html += th.format("Suspend Time")
html += th.format("Resume Time")
html += th.format("Detail")
html += '</tr>\n'
# test data, 1 row per test
sTimeAvg = 0.0
rTimeAvg = 0.0
num = 1
for data in testruns:
# data.end is the end of post_resume
resumeEnd = data.dmesg['resume_complete']['end']
if num % 2 == 1:
html += '<tr class="alt">\n'
else:
html += '<tr>\n'
# test num
html += td.format("test %d" % num)
num += 1
if stampcolumns:
# host name
val = "unknown"
if('host' in data.stamp):
val = data.stamp['host']
html += td.format(val)
# host kernel
val = "unknown"
if('kernel' in data.stamp):
val = data.stamp['kernel']
html += td.format(val)
# suspend mode
val = "unknown"
if('mode' in data.stamp):
val = data.stamp['mode']
html += td.format(val)
# test time
val = "unknown"
if('time' in data.stamp):
val = data.stamp['time']
html += td.format(val)
# suspend time
sTime = (data.tSuspended - data.start)*1000
sTimeAvg += sTime
html += td.format("%3.3f ms" % sTime)
# resume time
rTime = (resumeEnd - data.tResumed)*1000
rTimeAvg += rTime
html += td.format("%3.3f ms" % rTime)
# link to the output html
html += tdlink.format(data.outfile)
html += '</tr>\n'
# last line: test average
if(count > 0):
sTimeAvg /= count
rTimeAvg /= count
html += '<tr class="avg">\n'
html += td.format('Average') # name
if stampcolumns:
html += td.format('') # host
html += td.format('') # kernel
html += td.format('') # mode
html += td.format('') # time
html += td.format("%3.3f ms" % sTimeAvg) # suspend time
html += td.format("%3.3f ms" % rTimeAvg) # resume time
html += td.format('') # output link
html += '</tr>\n'
# flush the data to file
hf.write(html+'</table>\n')
hf.write('</body>\n</html>\n')
hf.close()
# Function: createHTML
# Description:
# Create the output html file from the resident test data
# Arguments:
# testruns: array of Data objects from parseKernelLog or parseTraceLog
# Output:
# True if the html file was created, false if it failed
def createHTML(testruns):
global sysvals
for data in testruns:
data.normalizeTime(testruns[-1].tSuspended)
x2changes = ['', 'absolute']
if len(testruns) > 1:
x2changes = ['1', 'relative']
# html function templates
headline_stamp = '<div class="stamp">{0} {1} {2} {3}</div>\n'
html_devlist1 = '<button id="devlist1" class="devlist" style="float:left;">Device Detail%s</button>' % x2changes[0]
html_zoombox = '<center><button id="zoomin">ZOOM IN</button><button id="zoomout">ZOOM OUT</button><button id="zoomdef">ZOOM 1:1</button></center>\n'
html_devlist2 = '<button id="devlist2" class="devlist" style="float:right;">Device Detail2</button>\n'
html_timeline = '<div id="dmesgzoombox" class="zoombox">\n<div id="{0}" class="timeline" style="height:{1}px">\n'
html_device = '<div id="{0}" title="{1}" class="thread" style="left:{2}%;top:{3}%;height:{4}%;width:{5}%;">{6}</div>\n'
html_traceevent = '<div title="{0}" class="traceevent" style="left:{1}%;top:{2}%;height:{3}%;width:{4}%;border:1px solid {5};background-color:{5}">{6}</div>\n'
html_phase = '<div class="phase" style="left:{0}%;width:{1}%;top:{2}%;height:{3}%;background-color:{4}">{5}</div>\n'
html_phaselet = '<div id="{0}" class="phaselet" style="left:{1}%;width:{2}%;background-color:{3}"></div>\n'
html_legend = '<div class="square" style="left:{0}%;background-color:{1}"> {2}</div>\n'
html_timetotal = '<table class="time1">\n<tr>'\
'<td class="green">{2} Suspend Time: <b>{0} ms</b></td>'\
'<td class="yellow">{2} Resume Time: <b>{1} ms</b></td>'\
'</tr>\n</table>\n'
html_timetotal2 = '<table class="time1">\n<tr>'\
'<td class="green">{3} Suspend Time: <b>{0} ms</b></td>'\
'<td class="gray">'+sysvals.suspendmode+' time: <b>{1} ms</b></td>'\
'<td class="yellow">{3} Resume Time: <b>{2} ms</b></td>'\
'</tr>\n</table>\n'
html_timegroups = '<table class="time2">\n<tr>'\
'<td class="green">{4}Kernel Suspend: {0} ms</td>'\
'<td class="purple">{4}Firmware Suspend: {1} ms</td>'\
'<td class="purple">{4}Firmware Resume: {2} ms</td>'\
'<td class="yellow">{4}Kernel Resume: {3} ms</td>'\
'</tr>\n</table>\n'
# device timeline
vprint('Creating Device Timeline...')
devtl = Timeline()
# Generate the header for this timeline
textnum = ['First', 'Second']
for data in testruns:
tTotal = data.end - data.start
tEnd = data.dmesg['resume_complete']['end']
if(tTotal == 0):
print('ERROR: No timeline data')
sys.exit()
if(data.tLow > 0):
low_time = '%.0f'%(data.tLow*1000)
if data.fwValid:
suspend_time = '%.0f'%((data.tSuspended-data.start)*1000 + \
(data.fwSuspend/1000000.0))
resume_time = '%.0f'%((tEnd-data.tSuspended)*1000 + \
(data.fwResume/1000000.0))
testdesc1 = 'Total'
testdesc2 = ''
if(len(testruns) > 1):
testdesc1 = testdesc2 = textnum[data.testnumber]
testdesc2 += ' '
if(data.tLow == 0):
thtml = html_timetotal.format(suspend_time, \
resume_time, testdesc1)
else:
thtml = html_timetotal2.format(suspend_time, low_time, \
resume_time, testdesc1)
devtl.html['timeline'] += thtml
sktime = '%.3f'%((data.dmesg['suspend_machine']['end'] - \
data.getStart())*1000)
sftime = '%.3f'%(data.fwSuspend / 1000000.0)
rftime = '%.3f'%(data.fwResume / 1000000.0)
rktime = '%.3f'%((data.getEnd() - \
data.dmesg['resume_machine']['start'])*1000)
devtl.html['timeline'] += html_timegroups.format(sktime, \
sftime, rftime, rktime, testdesc2)
else:
suspend_time = '%.0f'%((data.tSuspended-data.start)*1000)
resume_time = '%.0f'%((tEnd-data.tSuspended)*1000)
testdesc = 'Kernel'
if(len(testruns) > 1):
testdesc = textnum[data.testnumber]+' '+testdesc
if(data.tLow == 0):
thtml = html_timetotal.format(suspend_time, \
resume_time, testdesc)
else:
thtml = html_timetotal2.format(suspend_time, low_time, \
resume_time, testdesc)
devtl.html['timeline'] += thtml
# time scale for potentially multiple datasets
t0 = testruns[0].start
tMax = testruns[-1].end
tSuspended = testruns[-1].tSuspended
tTotal = tMax - t0
# determine the maximum number of rows we need to draw
timelinerows = 0
for data in testruns:
for phase in data.dmesg:
list = data.dmesg[phase]['list']
rows = setTimelineRows(list, list)
data.dmesg[phase]['row'] = rows
if(rows > timelinerows):
timelinerows = rows
# calculate the timeline height and create bounding box, add buttons
devtl.setRows(timelinerows + 1)
devtl.html['timeline'] += html_devlist1
if len(testruns) > 1:
devtl.html['timeline'] += html_devlist2
devtl.html['timeline'] += html_zoombox
devtl.html['timeline'] += html_timeline.format('dmesg', devtl.height)
# draw the colored boxes for each of the phases
for data in testruns:
for b in data.dmesg:
phase = data.dmesg[b]
length = phase['end']-phase['start']
left = '%.3f' % (((phase['start']-t0)*100.0)/tTotal)
width = '%.3f' % ((length*100.0)/tTotal)
devtl.html['timeline'] += html_phase.format(left, width, \
'%.3f'%devtl.scaleH, '%.3f'%(100-devtl.scaleH), \
data.dmesg[b]['color'], '')
# draw the time scale, try to make the number of labels readable
devtl.html['scale'] = createTimeScale(t0, tMax, tSuspended)
devtl.html['timeline'] += devtl.html['scale']
for data in testruns:
for b in data.dmesg:
phaselist = data.dmesg[b]['list']
for d in phaselist:
name = d
drv = ''
dev = phaselist[d]
if(d in sysvals.altdevname):
name = sysvals.altdevname[d]
if('drv' in dev and dev['drv']):
drv = ' {%s}' % dev['drv']
height = (100.0 - devtl.scaleH)/data.dmesg[b]['row']
top = '%.3f' % ((dev['row']*height) + devtl.scaleH)
left = '%.3f' % (((dev['start']-t0)*100)/tTotal)
width = '%.3f' % (((dev['end']-dev['start'])*100)/tTotal)
length = ' (%0.3f ms) ' % ((dev['end']-dev['start'])*1000)
color = 'rgba(204,204,204,0.5)'
devtl.html['timeline'] += html_device.format(dev['id'], \
d+drv+length+b, left, top, '%.3f'%height, width, name+drv)
# draw any trace events found
for data in testruns:
for b in data.dmesg:
phaselist = data.dmesg[b]['list']
for name in phaselist:
dev = phaselist[name]
if('traceevents' in dev):
vprint('Debug trace events found for device %s' % name)
vprint('%20s %20s %10s %8s' % ('action', \
'name', 'time(ms)', 'length(ms)'))
for e in dev['traceevents']:
vprint('%20s %20s %10.3f %8.3f' % (e.action, \
e.name, e.time*1000, e.length*1000))
height = (100.0 - devtl.scaleH)/data.dmesg[b]['row']
top = '%.3f' % ((dev['row']*height) + devtl.scaleH)
left = '%.3f' % (((e.time-t0)*100)/tTotal)
width = '%.3f' % (e.length*100/tTotal)
color = 'rgba(204,204,204,0.5)'
devtl.html['timeline'] += \
html_traceevent.format(e.action+' '+e.name, \
left, top, '%.3f'%height, \
width, e.color, '')
# timeline is finished
devtl.html['timeline'] += '</div>\n</div>\n'
# draw a legend which describes the phases by color
data = testruns[-1]
devtl.html['legend'] = '<div class="legend">\n'
pdelta = 100.0/len(data.phases)
pmargin = pdelta / 4.0
for phase in data.phases:
order = '%.2f' % ((data.dmesg[phase]['order'] * pdelta) + pmargin)
name = string.replace(phase, '_', ' ')
devtl.html['legend'] += html_legend.format(order, \
data.dmesg[phase]['color'], name)
devtl.html['legend'] += '</div>\n'
hf = open(sysvals.htmlfile, 'w')
thread_height = 0
# write the html header first (html head, css code, up to body start)
html_header = '<!DOCTYPE html>\n<html>\n<head>\n\
<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
<title>AnalyzeSuspend</title>\n\
<style type=\'text/css\'>\n\
body {overflow-y: scroll;}\n\
.stamp {width: 100%;text-align:center;background-color:gray;line-height:30px;color:white;font: 25px Arial;}\n\
.callgraph {margin-top: 30px;box-shadow: 5px 5px 20px black;}\n\
.callgraph article * {padding-left: 28px;}\n\
h1 {color:black;font: bold 30px Times;}\n\
t0 {color:black;font: bold 30px Times;}\n\
t1 {color:black;font: 30px Times;}\n\
t2 {color:black;font: 25px Times;}\n\
t3 {color:black;font: 20px Times;white-space:nowrap;}\n\
t4 {color:black;font: bold 30px Times;line-height:60px;white-space:nowrap;}\n\
table {width:100%;}\n\
.gray {background-color:rgba(80,80,80,0.1);}\n\
.green {background-color:rgba(204,255,204,0.4);}\n\
.purple {background-color:rgba(128,0,128,0.2);}\n\
.yellow {background-color:rgba(255,255,204,0.4);}\n\
.time1 {font: 22px Arial;border:1px solid;}\n\
.time2 {font: 15px Arial;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;}\n\
td {text-align: center;}\n\
r {color:#500000;font:15px Tahoma;}\n\
n {color:#505050;font:15px Tahoma;}\n\
.tdhl {color: red;}\n\
.hide {display: none;}\n\
.pf {display: none;}\n\
.pf:checked + label {background: url(\'data:image/svg+xml;utf,<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" version="1.1"><circle cx="9" cy="9" r="8" stroke="black" stroke-width="1" fill="white"/><rect x="4" y="8" width="10" height="2" style="fill:black;stroke-width:0"/><rect x="8" y="4" width="2" height="10" style="fill:black;stroke-width:0"/></svg>\') no-repeat left center;}\n\
.pf:not(:checked) ~ label {background: url(\'data:image/svg+xml;utf,<?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" version="1.1"><circle cx="9" cy="9" r="8" stroke="black" stroke-width="1" fill="white"/><rect x="4" y="8" width="10" height="2" style="fill:black;stroke-width:0"/></svg>\') no-repeat left center;}\n\
.pf:checked ~ *:not(:nth-child(2)) {display: none;}\n\
.zoombox {position: relative; width: 100%; overflow-x: scroll;}\n\
.timeline {position: relative; font-size: 14px;cursor: pointer;width: 100%; overflow: hidden; background-color:#dddddd;}\n\
.thread {position: absolute; height: '+'%.3f'%thread_height+'%; overflow: hidden; line-height: 30px; border:1px solid;text-align:center;white-space:nowrap;background-color:rgba(204,204,204,0.5);}\n\
.thread:hover {background-color:white;border:1px solid red;z-index:10;}\n\
.hover {background-color:white;border:1px solid red;z-index:10;}\n\
.traceevent {position: absolute;opacity: 0.3;height: '+'%.3f'%thread_height+'%;width:0;overflow:hidden;line-height:30px;text-align:center;white-space:nowrap;}\n\
.phase {position: absolute;overflow: hidden;border:0px;text-align:center;}\n\
.phaselet {position:absolute;overflow:hidden;border:0px;text-align:center;height:100px;font-size:24px;}\n\
.t {position:absolute;top:0%;height:100%;border-right:1px solid black;}\n\
.legend {position: relative; width: 100%; height: 40px; text-align: center;margin-bottom:20px}\n\
.legend .square {position:absolute;top:10px; width: 0px;height: 20px;border:1px solid;padding-left:20px;}\n\
button {height:40px;width:200px;margin-bottom:20px;margin-top:20px;font-size:24px;}\n\
.devlist {position:'+x2changes[1]+';width:190px;}\n\
#devicedetail {height:100px;box-shadow: 5px 5px 20px black;}\n\
</style>\n</head>\n<body>\n'
hf.write(html_header)
# write the test title and general info header
if(sysvals.stamp['time'] != ""):
hf.write(headline_stamp.format(sysvals.stamp['host'],
sysvals.stamp['kernel'], sysvals.stamp['mode'], \
sysvals.stamp['time']))
# write the device timeline
hf.write(devtl.html['timeline'])
hf.write(devtl.html['legend'])
hf.write('<div id="devicedetailtitle"></div>\n')
hf.write('<div id="devicedetail" style="display:none;">\n')
# draw the colored boxes for the device detail section
for data in testruns:
hf.write('<div id="devicedetail%d">\n' % data.testnumber)
for b in data.phases:
phase = data.dmesg[b]
length = phase['end']-phase['start']
left = '%.3f' % (((phase['start']-t0)*100.0)/tTotal)
width = '%.3f' % ((length*100.0)/tTotal)
hf.write(html_phaselet.format(b, left, width, \
data.dmesg[b]['color']))
hf.write('</div>\n')
hf.write('</div>\n')
# write the ftrace data (callgraph)
data = testruns[-1]
if(sysvals.usecallgraph):
hf.write('<section id="callgraphs" class="callgraph">\n')
# write out the ftrace data converted to html
html_func_top = '<article id="{0}" class="atop" style="background-color:{1}">\n<input type="checkbox" class="pf" id="f{2}" checked/><label for="f{2}">{3} {4}</label>\n'
html_func_start = '<article>\n<input type="checkbox" class="pf" id="f{0}" checked/><label for="f{0}">{1} {2}</label>\n'
html_func_end = '</article>\n'
html_func_leaf = '<article>{0} {1}</article>\n'
num = 0
for p in data.phases:
list = data.dmesg[p]['list']
for devname in data.sortedDevices(p):
if('ftrace' not in list[devname]):
continue
name = devname
if(devname in sysvals.altdevname):
name = sysvals.altdevname[devname]
devid = list[devname]['id']
cg = list[devname]['ftrace']
flen = '<r>(%.3f ms @ %.3f to %.3f)</r>' % \
((cg.end - cg.start)*1000, cg.start*1000, cg.end*1000)
hf.write(html_func_top.format(devid, data.dmesg[p]['color'], \
num, name+' '+p, flen))
num += 1
for line in cg.list:
if(line.length < 0.000000001):
flen = ''
else:
flen = '<n>(%.3f ms @ %.3f)</n>' % (line.length*1000, \
line.time*1000)
if(line.freturn and line.fcall):
hf.write(html_func_leaf.format(line.name, flen))
elif(line.freturn):
hf.write(html_func_end)
else:
hf.write(html_func_start.format(num, line.name, flen))
num += 1
hf.write(html_func_end)
hf.write('\n\n </section>\n')
# write the footer and close
addScriptCode(hf, testruns)
hf.write('</body>\n</html>\n')
hf.close()
return True
# Function: addScriptCode
# Description:
# Adds the javascript code to the output html
# Arguments:
# hf: the open html file pointer
# testruns: array of Data objects from parseKernelLog or parseTraceLog
def addScriptCode(hf, testruns):
t0 = (testruns[0].start - testruns[-1].tSuspended) * 1000
tMax = (testruns[-1].end - testruns[-1].tSuspended) * 1000
# create an array in javascript memory with the device details
detail = ' var devtable = [];\n'
for data in testruns:
topo = data.deviceTopology()
detail += ' devtable[%d] = "%s";\n' % (data.testnumber, topo)
detail += ' var bounds = [%f,%f];\n' % (t0, tMax)
# add the code which will manipulate the data in the browser
script_code = \
'<script type="text/javascript">\n'+detail+\
' function zoomTimeline() {\n'\
' var timescale = document.getElementById("timescale");\n'\
' var dmesg = document.getElementById("dmesg");\n'\
' var zoombox = document.getElementById("dmesgzoombox");\n'\
' var val = parseFloat(dmesg.style.width);\n'\
' var newval = 100;\n'\
' var sh = window.outerWidth / 2;\n'\
' if(this.id == "zoomin") {\n'\
' newval = val * 1.2;\n'\
' if(newval > 40000) newval = 40000;\n'\
' dmesg.style.width = newval+"%";\n'\
' zoombox.scrollLeft = ((zoombox.scrollLeft + sh) * newval / val) - sh;\n'\
' } else if (this.id == "zoomout") {\n'\
' newval = val / 1.2;\n'\
' if(newval < 100) newval = 100;\n'\
' dmesg.style.width = newval+"%";\n'\
' zoombox.scrollLeft = ((zoombox.scrollLeft + sh) * newval / val) - sh;\n'\
' } else {\n'\
' zoombox.scrollLeft = 0;\n'\
' dmesg.style.width = "100%";\n'\
' }\n'\
' var html = "";\n'\
' var t0 = bounds[0];\n'\
' var tMax = bounds[1];\n'\
' var tTotal = tMax - t0;\n'\
' var wTotal = tTotal * 100.0 / newval;\n'\
' for(var tS = 1000; (wTotal / tS) < 3; tS /= 10);\n'\
' if(tS < 1) tS = 1;\n'\
' for(var s = ((t0 / tS)|0) * tS; s < tMax; s += tS) {\n'\
' var pos = (tMax - s) * 100.0 / tTotal;\n'\
' var name = (s == 0)?"S/R":(s+"ms");\n'\
' html += "<div class=\\"t\\" style=\\"right:"+pos+"%\\">"+name+"</div>";\n'\
' }\n'\
' timescale.innerHTML = html;\n'\
' }\n'\
' function deviceHover() {\n'\
' var name = this.title.slice(0, this.title.indexOf(" ("));\n'\
' var dmesg = document.getElementById("dmesg");\n'\
' var dev = dmesg.getElementsByClassName("thread");\n'\
' var cpu = -1;\n'\
' if(name.match("CPU_ON\[[0-9]*\]"))\n'\
' cpu = parseInt(name.slice(7));\n'\
' else if(name.match("CPU_OFF\[[0-9]*\]"))\n'\
' cpu = parseInt(name.slice(8));\n'\
' for (var i = 0; i < dev.length; i++) {\n'\
' dname = dev[i].title.slice(0, dev[i].title.indexOf(" ("));\n'\
' if((cpu >= 0 && dname.match("CPU_O[NF]*\\\[*"+cpu+"\\\]")) ||\n'\
' (name == dname))\n'\
' {\n'\
' dev[i].className = "thread hover";\n'\
' } else {\n'\
' dev[i].className = "thread";\n'\
' }\n'\
' }\n'\
' }\n'\
' function deviceUnhover() {\n'\
' var dmesg = document.getElementById("dmesg");\n'\
' var dev = dmesg.getElementsByClassName("thread");\n'\
' for (var i = 0; i < dev.length; i++) {\n'\
' dev[i].className = "thread";\n'\
' }\n'\
' }\n'\
' function deviceTitle(title, total, cpu) {\n'\
' var prefix = "Total";\n'\
' if(total.length > 3) {\n'\
' prefix = "Average";\n'\
' total[1] = (total[1]+total[3])/2;\n'\
' total[2] = (total[2]+total[4])/2;\n'\
' }\n'\
' var devtitle = document.getElementById("devicedetailtitle");\n'\
' var name = title.slice(0, title.indexOf(" "));\n'\
' if(cpu >= 0) name = "CPU"+cpu;\n'\
' var driver = "";\n'\
' var tS = "<t2>(</t2>";\n'\
' var tR = "<t2>)</t2>";\n'\
' if(total[1] > 0)\n'\
' tS = "<t2>("+prefix+" Suspend:</t2><t0> "+total[1].toFixed(3)+" ms</t0> ";\n'\
' if(total[2] > 0)\n'\
' tR = " <t2>"+prefix+" Resume:</t2><t0> "+total[2].toFixed(3)+" ms<t2>)</t2></t0>";\n'\
' var s = title.indexOf("{");\n'\
' var e = title.indexOf("}");\n'\
' if((s >= 0) && (e >= 0))\n'\
' driver = title.slice(s+1, e) + " <t1>@</t1> ";\n'\
' if(total[1] > 0 && total[2] > 0)\n'\
' devtitle.innerHTML = "<t0>"+driver+name+"</t0> "+tS+tR;\n'\
' else\n'\
' devtitle.innerHTML = "<t0>"+title+"</t0>";\n'\
' return name;\n'\
' }\n'\
' function deviceDetail() {\n'\
' var devinfo = document.getElementById("devicedetail");\n'\
' devinfo.style.display = "block";\n'\
' var name = this.title.slice(0, this.title.indexOf(" ("));\n'\
' var cpu = -1;\n'\
' if(name.match("CPU_ON\[[0-9]*\]"))\n'\
' cpu = parseInt(name.slice(7));\n'\
' else if(name.match("CPU_OFF\[[0-9]*\]"))\n'\
' cpu = parseInt(name.slice(8));\n'\
' var dmesg = document.getElementById("dmesg");\n'\
' var dev = dmesg.getElementsByClassName("thread");\n'\
' var idlist = [];\n'\
' var pdata = [[]];\n'\
' var pd = pdata[0];\n'\
' var total = [0.0, 0.0, 0.0];\n'\
' for (var i = 0; i < dev.length; i++) {\n'\
' dname = dev[i].title.slice(0, dev[i].title.indexOf(" ("));\n'\
' if((cpu >= 0 && dname.match("CPU_O[NF]*\\\[*"+cpu+"\\\]")) ||\n'\
' (name == dname))\n'\
' {\n'\
' idlist[idlist.length] = dev[i].id;\n'\
' var tidx = 1;\n'\
' if(dev[i].id[0] == "a") {\n'\
' pd = pdata[0];\n'\
' } else {\n'\
' if(pdata.length == 1) pdata[1] = [];\n'\
' if(total.length == 3) total[3]=total[4]=0.0;\n'\
' pd = pdata[1];\n'\
' tidx = 3;\n'\
' }\n'\
' var info = dev[i].title.split(" ");\n'\
' var pname = info[info.length-1];\n'\
' pd[pname] = parseFloat(info[info.length-3].slice(1));\n'\
' total[0] += pd[pname];\n'\
' if(pname.indexOf("suspend") >= 0)\n'\
' total[tidx] += pd[pname];\n'\
' else\n'\
' total[tidx+1] += pd[pname];\n'\
' }\n'\
' }\n'\
' var devname = deviceTitle(this.title, total, cpu);\n'\
' var left = 0.0;\n'\
' for (var t = 0; t < pdata.length; t++) {\n'\
' pd = pdata[t];\n'\
' devinfo = document.getElementById("devicedetail"+t);\n'\
' var phases = devinfo.getElementsByClassName("phaselet");\n'\
' for (var i = 0; i < phases.length; i++) {\n'\
' if(phases[i].id in pd) {\n'\
' var w = 100.0*pd[phases[i].id]/total[0];\n'\
' var fs = 32;\n'\
' if(w < 8) fs = 4*w | 0;\n'\
' var fs2 = fs*3/4;\n'\
' phases[i].style.width = w+"%";\n'\
' phases[i].style.left = left+"%";\n'\
' phases[i].title = phases[i].id+" "+pd[phases[i].id]+" ms";\n'\
' left += w;\n'\
' var time = "<t4 style=\\"font-size:"+fs+"px\\">"+pd[phases[i].id]+" ms<br></t4>";\n'\
' var pname = "<t3 style=\\"font-size:"+fs2+"px\\">"+phases[i].id.replace("_", " ")+"</t3>";\n'\
' phases[i].innerHTML = time+pname;\n'\
' } else {\n'\
' phases[i].style.width = "0%";\n'\
' phases[i].style.left = left+"%";\n'\
' }\n'\
' }\n'\
' }\n'\
' var cglist = document.getElementById("callgraphs");\n'\
' if(!cglist) return;\n'\
' var cg = cglist.getElementsByClassName("atop");\n'\
' for (var i = 0; i < cg.length; i++) {\n'\
' if(idlist.indexOf(cg[i].id) >= 0) {\n'\
' cg[i].style.display = "block";\n'\
' } else {\n'\
' cg[i].style.display = "none";\n'\
' }\n'\
' }\n'\
' }\n'\
' function devListWindow(e) {\n'\
' var sx = e.clientX;\n'\
' if(sx > window.innerWidth - 440)\n'\
' sx = window.innerWidth - 440;\n'\
' var cfg="top="+e.screenY+", left="+sx+", width=440, height=720, scrollbars=yes";\n'\
' var win = window.open("", "_blank", cfg);\n'\
' if(window.chrome) win.moveBy(sx, 0);\n'\
' var html = "<title>"+e.target.innerHTML+"</title>"+\n'\
' "<style type=\\"text/css\\">"+\n'\
' " ul {list-style-type:circle;padding-left:10px;margin-left:10px;}"+\n'\
' "</style>"\n'\
' var dt = devtable[0];\n'\
' if(e.target.id != "devlist1")\n'\
' dt = devtable[1];\n'\
' win.document.write(html+dt);\n'\
' }\n'\
' window.addEventListener("load", function () {\n'\
' var dmesg = document.getElementById("dmesg");\n'\
' dmesg.style.width = "100%"\n'\
' document.getElementById("zoomin").onclick = zoomTimeline;\n'\
' document.getElementById("zoomout").onclick = zoomTimeline;\n'\
' document.getElementById("zoomdef").onclick = zoomTimeline;\n'\
' var devlist = document.getElementsByClassName("devlist");\n'\
' for (var i = 0; i < devlist.length; i++)\n'\
' devlist[i].onclick = devListWindow;\n'\
' var dev = dmesg.getElementsByClassName("thread");\n'\
' for (var i = 0; i < dev.length; i++) {\n'\
' dev[i].onclick = deviceDetail;\n'\
' dev[i].onmouseover = deviceHover;\n'\
' dev[i].onmouseout = deviceUnhover;\n'\
' }\n'\
' zoomTimeline();\n'\
' });\n'\
'</script>\n'
hf.write(script_code);
# Function: executeSuspend
# Description:
# Execute system suspend through the sysfs interface, then copy the output
# dmesg and ftrace files to the test output directory.
def executeSuspend():
global sysvals
detectUSB(False)
t0 = time.time()*1000
tp = sysvals.tpath
# execute however many s/r runs requested
for count in range(1,sysvals.execcount+1):
# clear the kernel ring buffer just as we start
os.system('dmesg -C')
# enable callgraph ftrace only for the second run
if(sysvals.usecallgraph and count == 2):
# set trace type
os.system('echo function_graph > '+tp+'current_tracer')
os.system('echo "" > '+tp+'set_ftrace_filter')
# set trace format options
os.system('echo funcgraph-abstime > '+tp+'trace_options')
os.system('echo funcgraph-proc > '+tp+'trace_options')
# focus only on device suspend and resume
os.system('cat '+tp+'available_filter_functions | '+\
'grep dpm_run_callback > '+tp+'set_graph_function')
# if this is test2 and there's a delay, start here
if(count > 1 and sysvals.x2delay > 0):
tN = time.time()*1000
while (tN - t0) < sysvals.x2delay:
tN = time.time()*1000
time.sleep(0.001)
# start ftrace
if(sysvals.usecallgraph or sysvals.usetraceevents):
print('START TRACING')
os.system('echo 1 > '+tp+'tracing_on')
# initiate suspend
if(sysvals.usecallgraph or sysvals.usetraceevents):
os.system('echo SUSPEND START > '+tp+'trace_marker')
if(sysvals.rtcwake):
print('SUSPEND START')
print('will autoresume in %d seconds' % sysvals.rtcwaketime)
sysvals.rtcWakeAlarm()
else:
print('SUSPEND START (press a key to resume)')
pf = open(sysvals.powerfile, 'w')
pf.write(sysvals.suspendmode)
# execution will pause here
pf.close()
t0 = time.time()*1000
# return from suspend
print('RESUME COMPLETE')
if(sysvals.usecallgraph or sysvals.usetraceevents):
os.system('echo RESUME COMPLETE > '+tp+'trace_marker')
# see if there's firmware timing data to be had
t = sysvals.postresumetime
if(t > 0):
print('Waiting %d seconds for POST-RESUME trace events...' % t)
time.sleep(t)
# stop ftrace
if(sysvals.usecallgraph or sysvals.usetraceevents):
os.system('echo 0 > '+tp+'tracing_on')
print('CAPTURING TRACE')
writeDatafileHeader(sysvals.ftracefile)
os.system('cat '+tp+'trace >> '+sysvals.ftracefile)
os.system('echo "" > '+tp+'trace')
# grab a copy of the dmesg output
print('CAPTURING DMESG')
writeDatafileHeader(sysvals.dmesgfile)
os.system('dmesg -c >> '+sysvals.dmesgfile)
def writeDatafileHeader(filename):
global sysvals
fw = getFPDT(False)
prt = sysvals.postresumetime
fp = open(filename, 'a')
fp.write(sysvals.teststamp+'\n')
if(fw):
fp.write('# fwsuspend %u fwresume %u\n' % (fw[0], fw[1]))
if(prt > 0):
fp.write('# post resume time %u\n' % prt)
fp.close()
# Function: executeAndroidSuspend
# Description:
# Execute system suspend through the sysfs interface
# on a remote android device, then transfer the output
# dmesg and ftrace files to the local output directory.
def executeAndroidSuspend():
global sysvals
# check to see if the display is currently off
tp = sysvals.tpath
out = os.popen(sysvals.adb+\
' shell dumpsys power | grep mScreenOn').read().strip()
# if so we need to turn it on so we can issue a new suspend
if(out.endswith('false')):
print('Waking the device up for the test...')
# send the KEYPAD_POWER keyevent to wake it up
os.system(sysvals.adb+' shell input keyevent 26')
# wait a few seconds so the user can see the device wake up
time.sleep(3)
# execute however many s/r runs requested
for count in range(1,sysvals.execcount+1):
# clear the kernel ring buffer just as we start
os.system(sysvals.adb+' shell dmesg -c > /dev/null 2>&1')
# start ftrace
if(sysvals.usetraceevents):
print('START TRACING')
os.system(sysvals.adb+" shell 'echo 1 > "+tp+"tracing_on'")
# initiate suspend
for count in range(1,sysvals.execcount+1):
if(sysvals.usetraceevents):
os.system(sysvals.adb+\
" shell 'echo SUSPEND START > "+tp+"trace_marker'")
print('SUSPEND START (press a key on the device to resume)')
os.system(sysvals.adb+" shell 'echo "+sysvals.suspendmode+\
" > "+sysvals.powerfile+"'")
# execution will pause here, then adb will exit
while(True):
check = os.popen(sysvals.adb+\
' shell pwd 2>/dev/null').read().strip()
if(len(check) > 0):
break
time.sleep(1)
if(sysvals.usetraceevents):
os.system(sysvals.adb+" shell 'echo RESUME COMPLETE > "+tp+\
"trace_marker'")
# return from suspend
print('RESUME COMPLETE')
# stop ftrace
if(sysvals.usetraceevents):
os.system(sysvals.adb+" shell 'echo 0 > "+tp+"tracing_on'")
print('CAPTURING TRACE')
os.system('echo "'+sysvals.teststamp+'" > '+sysvals.ftracefile)
os.system(sysvals.adb+' shell cat '+tp+\
'trace >> '+sysvals.ftracefile)
# grab a copy of the dmesg output
print('CAPTURING DMESG')
os.system('echo "'+sysvals.teststamp+'" > '+sysvals.dmesgfile)
os.system(sysvals.adb+' shell dmesg >> '+sysvals.dmesgfile)
# Function: setUSBDevicesAuto
# Description:
# Set the autosuspend control parameter of all USB devices to auto
# This can be dangerous, so use at your own risk, most devices are set
# to always-on since the kernel cant determine if the device can
# properly autosuspend
def setUSBDevicesAuto():
global sysvals
rootCheck()
for dirname, dirnames, filenames in os.walk('/sys/devices'):
if(re.match('.*/usb[0-9]*.*', dirname) and
'idVendor' in filenames and 'idProduct' in filenames):
os.system('echo auto > %s/power/control' % dirname)
name = dirname.split('/')[-1]
desc = os.popen('cat %s/product 2>/dev/null' % \
dirname).read().replace('\n', '')
ctrl = os.popen('cat %s/power/control 2>/dev/null' % \
dirname).read().replace('\n', '')
print('control is %s for %6s: %s' % (ctrl, name, desc))
# Function: yesno
# Description:
# Print out an equivalent Y or N for a set of known parameter values
# Output:
# 'Y', 'N', or ' ' if the value is unknown
def yesno(val):
yesvals = ['auto', 'enabled', 'active', '1']
novals = ['on', 'disabled', 'suspended', 'forbidden', 'unsupported']
if val in yesvals:
return 'Y'
elif val in novals:
return 'N'
return ' '
# Function: ms2nice
# Description:
# Print out a very concise time string in minutes and seconds
# Output:
# The time string, e.g. "1901m16s"
def ms2nice(val):
ms = 0
try:
ms = int(val)
except:
return 0.0
m = ms / 60000
s = (ms / 1000) - (m * 60)
return '%3dm%2ds' % (m, s)
# Function: detectUSB
# Description:
# Detect all the USB hosts and devices currently connected and add
# a list of USB device names to sysvals for better timeline readability
# Arguments:
# output: True to output the info to stdout, False otherwise
def detectUSB(output):
global sysvals
field = {'idVendor':'', 'idProduct':'', 'product':'', 'speed':''}
power = {'async':'', 'autosuspend':'', 'autosuspend_delay_ms':'',
'control':'', 'persist':'', 'runtime_enabled':'',
'runtime_status':'', 'runtime_usage':'',
'runtime_active_time':'',
'runtime_suspended_time':'',
'active_duration':'',
'connected_duration':''}
if(output):
print('LEGEND')
print('---------------------------------------------------------------------------------------------')
print(' A = async/sync PM queue Y/N D = autosuspend delay (seconds)')
print(' S = autosuspend Y/N rACTIVE = runtime active (min/sec)')
print(' P = persist across suspend Y/N rSUSPEN = runtime suspend (min/sec)')
print(' E = runtime suspend enabled/forbidden Y/N ACTIVE = active duration (min/sec)')
print(' R = runtime status active/suspended Y/N CONNECT = connected duration (min/sec)')
print(' U = runtime usage count')
print('---------------------------------------------------------------------------------------------')
print(' NAME ID DESCRIPTION SPEED A S P E R U D rACTIVE rSUSPEN ACTIVE CONNECT')
print('---------------------------------------------------------------------------------------------')
for dirname, dirnames, filenames in os.walk('/sys/devices'):
if(re.match('.*/usb[0-9]*.*', dirname) and
'idVendor' in filenames and 'idProduct' in filenames):
for i in field:
field[i] = os.popen('cat %s/%s 2>/dev/null' % \
(dirname, i)).read().replace('\n', '')
name = dirname.split('/')[-1]
if(len(field['product']) > 0):
sysvals.altdevname[name] = \
'%s [%s]' % (field['product'], name)
else:
sysvals.altdevname[name] = \
'%s:%s [%s]' % (field['idVendor'], \
field['idProduct'], name)
if(output):
for i in power:
power[i] = os.popen('cat %s/power/%s 2>/dev/null' % \
(dirname, i)).read().replace('\n', '')
if(re.match('usb[0-9]*', name)):
first = '%-8s' % name
else:
first = '%8s' % name
print('%s [%s:%s] %-20s %-4s %1s %1s %1s %1s %1s %1s %1s %s %s %s %s' % \
(first, field['idVendor'], field['idProduct'], \
field['product'][0:20], field['speed'], \
yesno(power['async']), \
yesno(power['control']), \
yesno(power['persist']), \
yesno(power['runtime_enabled']), \
yesno(power['runtime_status']), \
power['runtime_usage'], \
power['autosuspend'], \
ms2nice(power['runtime_active_time']), \
ms2nice(power['runtime_suspended_time']), \
ms2nice(power['active_duration']), \
ms2nice(power['connected_duration'])))
# Function: getModes
# Description:
# Determine the supported power modes on this system
# Output:
# A string list of the available modes
def getModes():
global sysvals
modes = ''
if(not sysvals.android):
if(os.path.exists(sysvals.powerfile)):
fp = open(sysvals.powerfile, 'r')
modes = string.split(fp.read())
fp.close()
else:
line = os.popen(sysvals.adb+' shell cat '+\
sysvals.powerfile).read().strip()
modes = string.split(line)
return modes
# Function: getFPDT
# Description:
# Read the acpi bios tables and pull out FPDT, the firmware data
# Arguments:
# output: True to output the info to stdout, False otherwise
def getFPDT(output):
global sysvals
rectype = {}
rectype[0] = 'Firmware Basic Boot Performance Record'
rectype[1] = 'S3 Performance Table Record'
prectype = {}
prectype[0] = 'Basic S3 Resume Performance Record'
prectype[1] = 'Basic S3 Suspend Performance Record'
rootCheck()
if(not os.path.exists(sysvals.fpdtpath)):
if(output):
doError('file doesnt exist: %s' % sysvals.fpdtpath, False)
return False
if(not os.access(sysvals.fpdtpath, os.R_OK)):
if(output):
doError('file isnt readable: %s' % sysvals.fpdtpath, False)
return False
if(not os.path.exists(sysvals.mempath)):
if(output):
doError('file doesnt exist: %s' % sysvals.mempath, False)
return False
if(not os.access(sysvals.mempath, os.R_OK)):
if(output):
doError('file isnt readable: %s' % sysvals.mempath, False)
return False
fp = open(sysvals.fpdtpath, 'rb')
buf = fp.read()
fp.close()
if(len(buf) < 36):
if(output):
doError('Invalid FPDT table data, should '+\
'be at least 36 bytes', False)
return False
table = struct.unpack('4sIBB6s8sI4sI', buf[0:36])
if(output):
print('')
print('Firmware Performance Data Table (%s)' % table[0])
print(' Signature : %s' % table[0])
print(' Table Length : %u' % table[1])
print(' Revision : %u' % table[2])
print(' Checksum : 0x%x' % table[3])
print(' OEM ID : %s' % table[4])
print(' OEM Table ID : %s' % table[5])
print(' OEM Revision : %u' % table[6])
print(' Creator ID : %s' % table[7])
print(' Creator Revision : 0x%x' % table[8])
print('')
if(table[0] != 'FPDT'):
if(output):
doError('Invalid FPDT table')
return False
if(len(buf) <= 36):
return False
i = 0
fwData = [0, 0]
records = buf[36:]
fp = open(sysvals.mempath, 'rb')
while(i < len(records)):
header = struct.unpack('HBB', records[i:i+4])
if(header[0] not in rectype):
continue
if(header[1] != 16):
continue
addr = struct.unpack('Q', records[i+8:i+16])[0]
try:
fp.seek(addr)
first = fp.read(8)
except:
doError('Bad address 0x%x in %s' % (addr, sysvals.mempath), False)
rechead = struct.unpack('4sI', first)
recdata = fp.read(rechead[1]-8)
if(rechead[0] == 'FBPT'):
record = struct.unpack('HBBIQQQQQ', recdata)
if(output):
print('%s (%s)' % (rectype[header[0]], rechead[0]))
print(' Reset END : %u ns' % record[4])
print(' OS Loader LoadImage Start : %u ns' % record[5])
print(' OS Loader StartImage Start : %u ns' % record[6])
print(' ExitBootServices Entry : %u ns' % record[7])
print(' ExitBootServices Exit : %u ns' % record[8])
elif(rechead[0] == 'S3PT'):
if(output):
print('%s (%s)' % (rectype[header[0]], rechead[0]))
j = 0
while(j < len(recdata)):
prechead = struct.unpack('HBB', recdata[j:j+4])
if(prechead[0] not in prectype):
continue
if(prechead[0] == 0):
record = struct.unpack('IIQQ', recdata[j:j+prechead[1]])
fwData[1] = record[2]
if(output):
print(' %s' % prectype[prechead[0]])
print(' Resume Count : %u' % \
record[1])
print(' FullResume : %u ns' % \
record[2])
print(' AverageResume : %u ns' % \
record[3])
elif(prechead[0] == 1):
record = struct.unpack('QQ', recdata[j+4:j+prechead[1]])
fwData[0] = record[1] - record[0]
if(output):
print(' %s' % prectype[prechead[0]])
print(' SuspendStart : %u ns' % \
record[0])
print(' SuspendEnd : %u ns' % \
record[1])
print(' SuspendTime : %u ns' % \
fwData[0])
j += prechead[1]
if(output):
print('')
i += header[1]
fp.close()
return fwData
# Function: statusCheck
# Description:
# Verify that the requested command and options will work, and
# print the results to the terminal
# Output:
# True if the test will work, False if not
def statusCheck():
global sysvals
status = True
if(sysvals.android):
print('Checking the android system ...')
else:
print('Checking this system (%s)...' % platform.node())
# check if adb is connected to a device
if(sysvals.android):
res = 'NO'
out = os.popen(sysvals.adb+' get-state').read().strip()
if(out == 'device'):
res = 'YES'
print(' is android device connected: %s' % res)
if(res != 'YES'):
print(' Please connect the device before using this tool')
return False
# check we have root access
res = 'NO (No features of this tool will work!)'
if(sysvals.android):
out = os.popen(sysvals.adb+' shell id').read().strip()
if('root' in out):
res = 'YES'
else:
if(os.environ['USER'] == 'root'):
res = 'YES'
print(' have root access: %s' % res)
if(res != 'YES'):
if(sysvals.android):
print(' Try running "adb root" to restart the daemon as root')
else:
print(' Try running this script with sudo')
return False
# check sysfs is mounted
res = 'NO (No features of this tool will work!)'
if(sysvals.android):
out = os.popen(sysvals.adb+' shell ls '+\
sysvals.powerfile).read().strip()
if(out == sysvals.powerfile):
res = 'YES'
else:
if(os.path.exists(sysvals.powerfile)):
res = 'YES'
print(' is sysfs mounted: %s' % res)
if(res != 'YES'):
return False
# check target mode is a valid mode
res = 'NO'
modes = getModes()
if(sysvals.suspendmode in modes):
res = 'YES'
else:
status = False
print(' is "%s" a valid power mode: %s' % (sysvals.suspendmode, res))
if(res == 'NO'):
print(' valid power modes are: %s' % modes)
print(' please choose one with -m')
# check if the tool can unlock the device
if(sysvals.android):
res = 'YES'
out1 = os.popen(sysvals.adb+\
' shell dumpsys power | grep mScreenOn').read().strip()
out2 = os.popen(sysvals.adb+\
' shell input').read().strip()
if(not out1.startswith('mScreenOn') or not out2.startswith('usage')):
res = 'NO (wake the android device up before running the test)'
print(' can I unlock the screen: %s' % res)
# check if ftrace is available
res = 'NO'
ftgood = verifyFtrace()
if(ftgood):
res = 'YES'
elif(sysvals.usecallgraph):
status = False
print(' is ftrace supported: %s' % res)
# what data source are we using
res = 'DMESG'
if(ftgood):
sysvals.usetraceeventsonly = True
sysvals.usetraceevents = False
for e in sysvals.traceevents:
check = False
if(sysvals.android):
out = os.popen(sysvals.adb+' shell ls -d '+\
sysvals.epath+e).read().strip()
if(out == sysvals.epath+e):
check = True
else:
if(os.path.exists(sysvals.epath+e)):
check = True
if(not check):
sysvals.usetraceeventsonly = False
if(e == 'suspend_resume' and check):
sysvals.usetraceevents = True
if(sysvals.usetraceevents and sysvals.usetraceeventsonly):
res = 'FTRACE (all trace events found)'
elif(sysvals.usetraceevents):
res = 'DMESG and FTRACE (suspend_resume trace event found)'
print(' timeline data source: %s' % res)
# check if rtcwake
res = 'NO'
if(sysvals.rtcpath != ''):
res = 'YES'
elif(sysvals.rtcwake):
status = False
print(' is rtcwake supported: %s' % res)
return status
# Function: doError
# Description:
# generic error function for catastrphic failures
# Arguments:
# msg: the error message to print
# help: True if printHelp should be called after, False otherwise
def doError(msg, help):
if(help == True):
printHelp()
print('ERROR: %s\n') % msg
sys.exit()
# Function: doWarning
# Description:
# generic warning function for non-catastrophic anomalies
# Arguments:
# msg: the warning message to print
# file: If not empty, a filename to request be sent to the owner for debug
def doWarning(msg, file):
print('/* %s */') % msg
if(file):
print('/* For a fix, please send this'+\
' %s file to <todd.e.brandt@intel.com> */' % file)
# Function: rootCheck
# Description:
# quick check to see if we have root access
def rootCheck():
if(os.environ['USER'] != 'root'):
doError('This script must be run as root', False)
# Function: getArgInt
# Description:
# pull out an integer argument from the command line with checks
def getArgInt(name, args, min, max):
try:
arg = args.next()
except:
doError(name+': no argument supplied', True)
try:
val = int(arg)
except:
doError(name+': non-integer value given', True)
if(val < min or val > max):
doError(name+': value should be between %d and %d' % (min, max), True)
return val
# Function: rerunTest
# Description:
# generate an output from an existing set of ftrace/dmesg logs
def rerunTest():
global sysvals
if(sysvals.ftracefile != ''):
doesTraceLogHaveTraceEvents()
if(sysvals.dmesgfile == '' and not sysvals.usetraceeventsonly):
doError('recreating this html output '+\
'requires a dmesg file', False)
sysvals.setOutputFile()
vprint('Output file: %s' % sysvals.htmlfile)
print('PROCESSING DATA')
if(sysvals.usetraceeventsonly):
testruns = parseTraceLog()
else:
testruns = loadKernelLog()
for data in testruns:
parseKernelLog(data)
if(sysvals.ftracefile != ''):
appendIncompleteTraceLog(testruns)
createHTML(testruns)
# Function: runTest
# Description:
# execute a suspend/resume, gather the logs, and generate the output
def runTest(subdir):
global sysvals
# prepare for the test
if(not sysvals.android):
initFtrace()
else:
initFtraceAndroid()
sysvals.initTestOutput(subdir)
vprint('Output files:\n %s' % sysvals.dmesgfile)
if(sysvals.usecallgraph or
sysvals.usetraceevents or
sysvals.usetraceeventsonly):
vprint(' %s' % sysvals.ftracefile)
vprint(' %s' % sysvals.htmlfile)
# execute the test
if(not sysvals.android):
executeSuspend()
else:
executeAndroidSuspend()
# analyze the data and create the html output
print('PROCESSING DATA')
if(sysvals.usetraceeventsonly):
# data for kernels 3.15 or newer is entirely in ftrace
testruns = parseTraceLog()
else:
# data for kernels older than 3.15 is primarily in dmesg
testruns = loadKernelLog()
for data in testruns:
parseKernelLog(data)
if(sysvals.usecallgraph or sysvals.usetraceevents):
appendIncompleteTraceLog(testruns)
createHTML(testruns)
# Function: runSummary
# Description:
# create a summary of tests in a sub-directory
def runSummary(subdir, output):
global sysvals
# get a list of ftrace output files
files = []
for dirname, dirnames, filenames in os.walk(subdir):
for filename in filenames:
if(re.match('.*_ftrace.txt', filename)):
files.append("%s/%s" % (dirname, filename))
# process the files in order and get an array of data objects
testruns = []
for file in sorted(files):
if output:
print("Test found in %s" % os.path.dirname(file))
sysvals.ftracefile = file
sysvals.dmesgfile = file.replace('_ftrace.txt', '_dmesg.txt')
doesTraceLogHaveTraceEvents()
sysvals.usecallgraph = False
if not sysvals.usetraceeventsonly:
if(not os.path.exists(sysvals.dmesgfile)):
print("Skipping %s: not a valid test input" % file)
continue
else:
if output:
f = os.path.basename(sysvals.ftracefile)
d = os.path.basename(sysvals.dmesgfile)
print("\tInput files: %s and %s" % (f, d))
testdata = loadKernelLog()
data = testdata[0]
parseKernelLog(data)
testdata = [data]
appendIncompleteTraceLog(testdata)
else:
if output:
print("\tInput file: %s" % os.path.basename(sysvals.ftracefile))
testdata = parseTraceLog()
data = testdata[0]
data.normalizeTime(data.tSuspended)
link = file.replace(subdir+'/', '').replace('_ftrace.txt', '.html')
data.outfile = link
testruns.append(data)
createHTMLSummarySimple(testruns, subdir+'/summary.html')
# Function: printHelp
# Description:
# print out the help text
def printHelp():
global sysvals
modes = getModes()
print('')
print('AnalyzeSuspend v%.1f' % sysvals.version)
print('Usage: sudo analyze_suspend.py <options>')
print('')
print('Description:')
print(' This tool is designed to assist kernel and OS developers in optimizing')
print(' their linux stack\'s suspend/resume time. Using a kernel image built')
print(' with a few extra options enabled, the tool will execute a suspend and')
print(' capture dmesg and ftrace data until resume is complete. This data is')
print(' transformed into a device timeline and an optional callgraph to give')
print(' a detailed view of which devices/subsystems are taking the most')
print(' time in suspend/resume.')
print('')
print(' Generates output files in subdirectory: suspend-mmddyy-HHMMSS')
print(' HTML output: <hostname>_<mode>.html')
print(' raw dmesg output: <hostname>_<mode>_dmesg.txt')
print(' raw ftrace output: <hostname>_<mode>_ftrace.txt')
print('')
print('Options:')
print(' [general]')
print(' -h Print this help text')
print(' -v Print the current tool version')
print(' -verbose Print extra information during execution and analysis')
print(' -status Test to see if the system is enabled to run this tool')
print(' -modes List available suspend modes')
print(' -m mode Mode to initiate for suspend %s (default: %s)') % (modes, sysvals.suspendmode)
print(' -rtcwake t Use rtcwake to autoresume after <t> seconds (default: disabled)')
print(' [advanced]')
print(' -f Use ftrace to create device callgraphs (default: disabled)')
print(' -filter "d1 d2 ..." Filter out all but this list of dev names')
print(' -x2 Run two suspend/resumes back to back (default: disabled)')
print(' -x2delay t Minimum millisecond delay <t> between the two test runs (default: 0 ms)')
print(' -postres t Time after resume completion to wait for post-resume events (default: 0 S)')
print(' -multi n d Execute <n> consecutive tests at <d> seconds intervals. The outputs will')
print(' be created in a new subdirectory with a summary page.')
print(' [utilities]')
print(' -fpdt Print out the contents of the ACPI Firmware Performance Data Table')
print(' -usbtopo Print out the current USB topology with power info')
print(' -usbauto Enable autosuspend for all connected USB devices')
print(' [android testing]')
print(' -adb binary Use the given adb binary to run the test on an android device.')
print(' The device should already be connected and with root access.')
print(' Commands will be executed on the device using "adb shell"')
print(' [re-analyze data from previous runs]')
print(' -ftrace ftracefile Create HTML output using ftrace input')
print(' -dmesg dmesgfile Create HTML output using dmesg (not needed for kernel >= 3.15)')
print(' -summary directory Create a summary of all test in this dir')
print('')
return True
# ----------------- MAIN --------------------
# exec start (skipped if script is loaded as library)
if __name__ == '__main__':
cmd = ''
cmdarg = ''
multitest = {'run': False, 'count': 0, 'delay': 0}
# loop through the command line arguments
args = iter(sys.argv[1:])
for arg in args:
if(arg == '-m'):
try:
val = args.next()
except:
doError('No mode supplied', True)
sysvals.suspendmode = val
elif(arg == '-adb'):
try:
val = args.next()
except:
doError('No adb binary supplied', True)
if(not os.path.exists(val)):
doError('file doesnt exist: %s' % val, False)
if(not os.access(val, os.X_OK)):
doError('file isnt executable: %s' % val, False)
try:
check = os.popen(val+' version').read().strip()
except:
doError('adb version failed to execute', False)
if(not re.match('Android Debug Bridge .*', check)):
doError('adb version failed to execute', False)
sysvals.adb = val
sysvals.android = True
elif(arg == '-x2'):
if(sysvals.postresumetime > 0):
doError('-x2 is not compatible with -postres', False)
sysvals.execcount = 2
elif(arg == '-x2delay'):
sysvals.x2delay = getArgInt('-x2delay', args, 0, 60000)
elif(arg == '-postres'):
if(sysvals.execcount != 1):
doError('-x2 is not compatible with -postres', False)
sysvals.postresumetime = getArgInt('-postres', args, 0, 3600)
elif(arg == '-f'):
sysvals.usecallgraph = True
elif(arg == '-modes'):
cmd = 'modes'
elif(arg == '-fpdt'):
cmd = 'fpdt'
elif(arg == '-usbtopo'):
cmd = 'usbtopo'
elif(arg == '-usbauto'):
cmd = 'usbauto'
elif(arg == '-status'):
cmd = 'status'
elif(arg == '-verbose'):
sysvals.verbose = True
elif(arg == '-v'):
print("Version %.1f" % sysvals.version)
sys.exit()
elif(arg == '-rtcwake'):
sysvals.rtcwake = True
sysvals.rtcwaketime = getArgInt('-rtcwake', args, 0, 3600)
elif(arg == '-multi'):
multitest['run'] = True
multitest['count'] = getArgInt('-multi n (exec count)', args, 2, 1000000)
multitest['delay'] = getArgInt('-multi d (delay between tests)', args, 0, 3600)
elif(arg == '-dmesg'):
try:
val = args.next()
except:
doError('No dmesg file supplied', True)
sysvals.notestrun = True
sysvals.dmesgfile = val
if(os.path.exists(sysvals.dmesgfile) == False):
doError('%s doesnt exist' % sysvals.dmesgfile, False)
elif(arg == '-ftrace'):
try:
val = args.next()
except:
doError('No ftrace file supplied', True)
sysvals.notestrun = True
sysvals.usecallgraph = True
sysvals.ftracefile = val
if(os.path.exists(sysvals.ftracefile) == False):
doError('%s doesnt exist' % sysvals.ftracefile, False)
elif(arg == '-summary'):
try:
val = args.next()
except:
doError('No directory supplied', True)
cmd = 'summary'
cmdarg = val
sysvals.notestrun = True
if(os.path.isdir(val) == False):
doError('%s isnt accesible' % val, False)
elif(arg == '-filter'):
try:
val = args.next()
except:
doError('No devnames supplied', True)
sysvals.setDeviceFilter(val)
elif(arg == '-h'):
printHelp()
sys.exit()
else:
doError('Invalid argument: '+arg, True)
# just run a utility command and exit
if(cmd != ''):
if(cmd == 'status'):
statusCheck()
elif(cmd == 'fpdt'):
if(sysvals.android):
doError('cannot read FPDT on android device', False)
getFPDT(True)
elif(cmd == 'usbtopo'):
if(sysvals.android):
doError('cannot read USB topology '+\
'on an android device', False)
detectUSB(True)
elif(cmd == 'modes'):
modes = getModes()
print modes
elif(cmd == 'usbauto'):
setUSBDevicesAuto()
elif(cmd == 'summary'):
print("Generating a summary of folder \"%s\"" % cmdarg)
runSummary(cmdarg, True)
sys.exit()
# run test on android device
if(sysvals.android):
if(sysvals.usecallgraph):
doError('ftrace (-f) is not yet supported '+\
'in the android kernel', False)
if(sysvals.notestrun):
doError('cannot analyze test files on the '+\
'android device', False)
# if instructed, re-analyze existing data files
if(sysvals.notestrun):
rerunTest()
sys.exit()
# verify that we can run a test
if(not statusCheck()):
print('Check FAILED, aborting the test run!')
sys.exit()
if multitest['run']:
# run multiple tests in a separte subdirectory
s = 'x%d' % multitest['count']
subdir = datetime.now().strftime('suspend-'+s+'-%m%d%y-%H%M%S')
os.mkdir(subdir)
for i in range(multitest['count']):
if(i != 0):
print('Waiting %d seconds...' % (multitest['delay']))
time.sleep(multitest['delay'])
print('TEST (%d/%d) START' % (i+1, multitest['count']))
runTest(subdir)
print('TEST (%d/%d) COMPLETE' % (i+1, multitest['count']))
runSummary(subdir, False)
else:
# run the test in the current directory
runTest(".")
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
15650,
367,
5909,
20135,
20288,
15,
9964,
20542,
199,
3,
1898,
334,
67,
9,
6171,
12,
20619,
11098,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
436,
3704,
402,
314,
1664,
1696,
1684,
844,
12,
199,
3,
1015,
499,
12,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
1933,
446,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
198,
377,
16216,
699,
3759,
84,
665,
5766,
68,
14,
69,
14,
19026,
84,
32,
5135,
14,
22264,
14,
957,
30,
199,
3,
199,
3,
11994,
26,
199,
3,
198,
961,
4744,
365,
19829,
370,
465,
11734,
5114,
436,
4403,
19782,
315,
5323,
9147,
199,
3,
198,
3932,
18369,
3464,
1159,
20288,
15,
9964,
900,
14,
11719,
282,
5114,
1834,
6137,
199,
3,
198,
543,
282,
9284,
2402,
1511,
5223,
12,
314,
4744,
911,
5341,
282,
20288,
436,
199,
3,
198,
911,
12296,
30396,
436,
29517,
666,
5133,
14604,
365,
4890,
14,
961,
666,
199,
3,
198,
365,
14834,
1901,
282,
2243,
20780,
436,
282,
1240,
2180,
370,
8120,
282,
12530,
199,
3,
198,
436,
16212,
2455,
402,
1314,
7256,
436,
13484,
787,
16466,
314,
4750,
199,
3,
198,
900,
315,
20288,
15,
9964,
14,
710,
1072,
365,
282,
2849,
3517,
570,
1314,
883,
506,
199,
3,
198,
2455,
379,
315,
8344,
9849,
503,
18221,
14,
199,
3,
199,
3,
198,
710,
2569,
5114,
1900,
1511,
787,
1415,
26,
199,
3,
1057,
15869,
63,
10793,
63,
5287,
29,
89,
199,
3,
1057,
15869,
63,
10793,
63,
51,
906,
6102,
63,
5287,
29,
89,
199,
3,
1057,
15869,
63,
38,
20112,
29,
89,
199,
3,
1057,
15869,
63,
15476,
63,
1766,
1348,
540,
29,
89,
199,
3,
1057,
15869,
63,
15476,
63,
25302,
63,
1766,
1348,
540,
29,
89,
199,
3,
199,
3,
198,
2104,
5114,
5459,
12731,
2419,
650,
14,
1046,
26,
199,
3,
198,
710,
2569,
4722,
5114,
2633,
787,
1415,
26,
199,
3,
1057,
334,
69,
14,
71,
14,
315,
570,
1182,
6839,
15,
885,
15,
2587,
456,
9,
199,
3,
1057,
21772,
2533,
63,
9744,
6174,
63,
26030,
63,
3472,
628,
1396,
4205,
1250,
63,
1757,
943,
63,
1436,
63,
552,
29,
975,
45,
21742,
199,
3,
199,
199,
3,
10652,
13,
25764,
50,
25244,
10652,
375,
199,
199,
646,
984,
199,
646,
900,
199,
646,
747,
199,
646,
1059,
199,
646,
295,
199,
646,
4298,
199,
504,
2197,
492,
2197,
199,
646,
2702,
199,
199,
3,
10652,
13,
24221,
654,
10652,
375,
199,
199,
3,
8089,
26,
6187,
6550,
199,
3,
11994,
26,
199,
3,
198,
437,
2288,
12,
2849,
13,
842,
3970,
1202,
370,
199,
3,
198,
3877,
2656,
1338,
436,
511,
2633,
199,
533,
6187,
6550,
26,
199,
198,
1023,
275,
650,
14,
16,
199,
198,
3832,
275,
756,
199,
198,
16634,
275,
7815,
199,
198,
84,
515,
275,
1994,
1274,
15,
4989,
15,
1757,
15,
21635,
4805,
199,
198,
3997,
3583,
515,
275,
1994,
1274,
15,
26374,
15,
645,
1038,
15,
5987,
15,
17095,
7438,
7,
199,
198,
69,
515,
275,
1994,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
4368,
15,
5652,
4805,
199,
198,
3446,
4368,
275,
359,
507,
198,
1159,
9145,
63,
9964,
297,
507,
198,
5121,
69,
722,
63,
7073,
63,
3058,
63,
500,
297,
507,
198,
5121,
69,
722,
63,
7073,
63,
3058,
63,
928,
7,
199,
198,
61,
199,
198,
632,
354,
275,
469,
507,
198,
7,
18459,
356,
283,
26396,
13,
1378,
13,
21068,
334,
51,
16,
3196,
507,
198,
1159,
84,
460,
991,
356,
283,
6921,
13,
3314,
428,
9145,
334,
51,
17,
3196,
507,
198,
6704,
5633,
356,
283,
26396,
13,
475,
13,
30839,
334,
51,
19,
3196,
507,
198,
5121,
28600,
356,
283,
26396,
13,
475,
13,
4032,
334,
51,
20,
3171,
199,
198,
93,
199,
198,
278,
8075,
275,
1994,
2374,
15,
5286,
7,
199,
198,
5652,
493,
275,
1994,
1274,
15,
5652,
15,
929,
7,
199,
198,
14480,
632,
275,
283,
5286,
7,
199,
198,
4269,
275,
283,
5967,
7,
199,
198,
1861,
275,
283,
396,
7,
199,
198,
396,
2359,
275,
2125,
199,
198,
12673,
493,
275,
2125,
199,
198,
24856,
493,
275,
2125,
199,
198,
15575,
12059,
275,
2125,
199,
198,
23392,
15181,
275,
756,
199,
198,
23392,
15181,
521,
275,
1616,
199,
198,
23392,
515,
275,
2125,
199,
198,
6238,
275,
756,
199,
198,
13741,
275,
283,
13741,
7,
199,
198,
1782,
1541,
275,
942,
199,
198,
2359,
275,
378,
199,
198,
1628,
835,
275,
413,
199,
198,
88,
18,
5814,
275,
378,
199,
198,
1180,
1250,
2180,
275,
756,
199,
198,
29589,
5986,
4368,
275,
756,
199,
198,
29589,
5986,
1430,
834,
590,
275,
756,
199,
198,
889,
396,
1065,
275,
756,
199,
198,
4478,
2374,
354,
275,
1211,
342,
199,
198,
1932,
9964,
521,
275,
378,
199,
198,
16825,
466,
5045,
275,
3943,
29140,
26,
7558,
48,
28,
84,
23742,
3171,
199,
198,
26374,
5045,
275,
3943,
289,
3569,
9145,
7558,
48,
28,
83,
9514,
16,
13,
25,
23849,
13908,
9964,
7558,
48,
28,
82,
9514,
16,
13,
25,
23849,
12913,
199,
198,
1932,
9964,
5045,
275,
3943,
2963,
14604,
900,
7558,
48,
28,
84,
9514,
16,
13,
25,
23849,
12913,
199,
198,
2359,
5045,
275,
3943,
20288,
13,
2229,
48,
28,
77,
9514,
16,
13,
25,
8194,
18,
1552,
2229,
48,
28,
68,
9514,
16,
13,
25,
8194,
18,
1552,
2229,
48,
28,
89,
9514,
16,
13,
25,
8194,
18,
1552,
13
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
15650,
367,
5909,
20135,
20288,
15,
9964,
20542,
199,
3,
1898,
334,
67,
9,
6171,
12,
20619,
11098,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
436,
3704,
402,
314,
1664,
1696,
1684,
844,
12,
199,
3,
1015,
499,
12,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
1933,
446,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
6642,
26,
199,
3,
198,
377,
16216,
699,
3759,
84,
665,
5766,
68,
14,
69,
14,
19026,
84,
32,
5135,
14,
22264,
14,
957,
30,
199,
3,
199,
3,
11994,
26,
199,
3,
198,
961,
4744,
365,
19829,
370,
465,
11734,
5114,
436,
4403,
19782,
315,
5323,
9147,
199,
3,
198,
3932,
18369,
3464,
1159,
20288,
15,
9964,
900,
14,
11719,
282,
5114,
1834,
6137,
199,
3,
198,
543,
282,
9284,
2402,
1511,
5223,
12,
314,
4744,
911,
5341,
282,
20288,
436,
199,
3,
198,
911,
12296,
30396,
436,
29517,
666,
5133,
14604,
365,
4890,
14,
961,
666,
199,
3,
198,
365,
14834,
1901,
282,
2243,
20780,
436,
282,
1240,
2180,
370,
8120,
282,
12530,
199,
3,
198,
436,
16212,
2455,
402,
1314,
7256,
436,
13484,
787,
16466,
314,
4750,
199,
3,
198,
900,
315,
20288,
15,
9964,
14,
710,
1072,
365,
282,
2849,
3517,
570,
1314,
883,
506,
199,
3,
198,
2455,
379,
315,
8344,
9849,
503,
18221,
14,
199,
3,
199,
3,
198,
710,
2569,
5114,
1900,
1511,
787,
1415,
26,
199,
3,
1057,
15869,
63,
10793,
63,
5287,
29,
89,
199,
3,
1057,
15869,
63,
10793,
63,
51,
906,
6102,
63,
5287,
29,
89,
199,
3,
1057,
15869,
63,
38,
20112,
29,
89,
199,
3,
1057,
15869,
63,
15476,
63,
1766,
1348,
540,
29,
89,
199,
3,
1057,
15869,
63,
15476,
63,
25302,
63,
1766,
1348,
540,
29,
89,
199,
3,
199,
3,
198,
2104,
5114,
5459,
12731,
2419,
650,
14,
1046,
26,
199,
3,
198,
710,
2569,
4722,
5114,
2633,
787,
1415,
26,
199,
3,
1057,
334,
69,
14,
71,
14,
315,
570,
1182,
6839,
15,
885,
15,
2587,
456,
9,
199,
3,
1057,
21772,
2533,
63,
9744,
6174,
63,
26030,
63,
3472,
628,
1396,
4205,
1250,
63,
1757,
943,
63,
1436,
63,
552,
29,
975,
45,
21742,
199,
3,
199,
199,
3,
10652,
13,
25764,
50,
25244,
10652,
375,
199,
199,
646,
984,
199,
646,
900,
199,
646,
747,
199,
646,
1059,
199,
646,
295,
199,
646,
4298,
199,
504,
2197,
492,
2197,
199,
646,
2702,
199,
199,
3,
10652,
13,
24221,
654,
10652,
375,
199,
199,
3,
8089,
26,
6187,
6550,
199,
3,
11994,
26,
199,
3,
198,
437,
2288,
12,
2849,
13,
842,
3970,
1202,
370,
199,
3,
198,
3877,
2656,
1338,
436,
511,
2633,
199,
533,
6187,
6550,
26,
199,
198,
1023,
275,
650,
14,
16,
199,
198,
3832,
275,
756,
199,
198,
16634,
275,
7815,
199,
198,
84,
515,
275,
1994,
1274,
15,
4989,
15,
1757,
15,
21635,
4805,
199,
198,
3997,
3583,
515,
275,
1994,
1274,
15,
26374,
15,
645,
1038,
15,
5987,
15,
17095,
7438,
7,
199,
198,
69,
515,
275,
1994,
1274,
15,
4989,
15,
1757,
15,
21635,
15,
4368,
15,
5652,
4805,
199,
198,
3446,
4368,
275,
359,
507,
198,
1159,
9145,
63,
9964,
297,
507,
198,
5121,
69,
722,
63,
7073,
63,
3058,
63,
500,
297,
507,
198,
5121,
69,
722,
63,
7073,
63,
3058,
63,
928,
7,
199,
198,
61,
199,
198,
632,
354,
275,
469,
507,
198,
7,
18459,
356,
283,
26396,
13,
1378,
13,
21068,
334,
51,
16,
3196,
507,
198,
1159,
84,
460,
991,
356,
283,
6921,
13,
3314,
428,
9145,
334,
51,
17,
3196,
507,
198,
6704,
5633,
356,
283,
26396,
13,
475,
13,
30839,
334,
51,
19,
3196,
507,
198,
5121,
28600,
356,
283,
26396,
13,
475,
13,
4032,
334,
51,
20,
3171,
199,
198,
93,
199,
198,
278,
8075,
275,
1994,
2374,
15,
5286,
7,
199,
198,
5652,
493,
275,
1994,
1274,
15,
5652,
15,
929,
7,
199,
198,
14480,
632,
275,
283,
5286,
7,
199,
198,
4269,
275,
283,
5967,
7,
199,
198,
1861,
275,
283,
396,
7,
199,
198,
396,
2359,
275,
2125,
199,
198,
12673,
493,
275,
2125,
199,
198,
24856,
493,
275,
2125,
199,
198,
15575,
12059,
275,
2125,
199,
198,
23392,
15181,
275,
756,
199,
198,
23392,
15181,
521,
275,
1616,
199,
198,
23392,
515,
275,
2125,
199,
198,
6238,
275,
756,
199,
198,
13741,
275,
283,
13741,
7,
199,
198,
1782,
1541,
275,
942,
199,
198,
2359,
275,
378,
199,
198,
1628,
835,
275,
413,
199,
198,
88,
18,
5814,
275,
378,
199,
198,
1180,
1250,
2180,
275,
756,
199,
198,
29589,
5986,
4368,
275,
756,
199,
198,
29589,
5986,
1430,
834,
590,
275,
756,
199,
198,
889,
396,
1065,
275,
756,
199,
198,
4478,
2374,
354,
275,
1211,
342,
199,
198,
1932,
9964,
521,
275,
378,
199,
198,
16825,
466,
5045,
275,
3943,
29140,
26,
7558,
48,
28,
84,
23742,
3171,
199,
198,
26374,
5045,
275,
3943,
289,
3569,
9145,
7558,
48,
28,
83,
9514,
16,
13,
25,
23849,
13908,
9964,
7558,
48,
28,
82,
9514,
16,
13,
25,
23849,
12913,
199,
198,
1932,
9964,
5045,
275,
3943,
2963,
14604,
900,
7558,
48,
28,
84,
9514,
16,
13,
25,
23849,
12913,
199,
198,
2359,
5045,
275,
3943,
20288,
13,
2229,
48,
28,
77,
9514,
16,
13,
25,
8194,
18,
1552,
2229,
48,
28,
68,
9514,
16,
13,
25,
8194,
18,
1552,
2229,
48,
28,
89,
9514,
16,
13,
25,
8194,
18,
1552,
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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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
] |
divio/django-cms
|
cms/extensions/models.py
|
7
|
5644
|
from django.db.models import ManyToManyField
from cms.constants import PUBLISHER_STATE_DIRTY
from django.db import models
from cms.models import Page, Title
class BaseExtension(models.Model):
public_extension = models.OneToOneField(
'self',
on_delete=models.CASCADE,
null=True,
editable=False,
related_name='draft_extension',
)
extended_object = None
class Meta:
abstract = True
def get_page(self): # pragma: no cover
raise NotImplementedError('Function must be overwritten in subclasses and return the extended page object.')
def copy_relations(self, oldinstance, language):
"""
Copy relations like many to many or foreign key relations to the public version.
Similar to the same named cms plugin function.
:param oldinstance: the draft version of the extension
"""
pass
@classmethod
def _get_related_objects(cls):
fields = cls._meta._get_fields(
forward=False, reverse=True,
include_parents=True,
include_hidden=False,
)
return list(obj for obj in fields if not isinstance(obj.field, ManyToManyField))
def copy(self, target, language):
"""
This method copies this extension to an unrelated-target. If you intend
to "publish" this extension to the publisher counterpart of target, then
use copy_to_publish() instead.
"""
clone = self.__class__.objects.get(pk=self.pk) # get a copy of this instance
clone.pk = None
clone.public_extension = None
clone.extended_object = target # set the new public object
# Nullify all concrete parent primary keys. See issue #5494
for parent, field in clone._meta.parents.items():
if field:
setattr(clone, parent._meta.pk.attname, None)
clone.save(mark_page=False)
# If the target we're copying already has a publisher counterpart, then
# connect the dots.
target_prime = getattr(target, 'publisher_public')
if target_prime:
related_name = self.__class__.__name__.lower()
clone_prime = getattr(target_prime, related_name)
if clone_prime:
clone.public_extension = clone_prime
else:
clone.public_extension = None
clone.copy_relations(self, language)
clone.save(force_update=True, mark_page=False)
return clone
def copy_to_public(self, public_object, language):
"""
This method is used to "publish" this extension as part of the a larger
operation on the target. If you intend to copy this extension to an
unrelated object, use copy() instead.
"""
this = self.__class__.objects.get(pk=self.pk) # get a copy of this instance
public_extension = self.public_extension # get the public version of this instance if any
this.extended_object = public_object # set the new public object
if public_extension:
this.pk = public_extension.pk # overwrite current public extension
this.public_extension = None # remove public extension or it will point to itself and raise duplicate entry
# Set public_extension concrete parents PKs. See issue #5494
for parent, field in this._meta.parents.items():
if field:
setattr(this, parent._meta.pk.attname, getattr(public_extension, parent._meta.pk.attname))
else:
this.pk = None # create new public extension
# Nullify all concrete parent primary keys. See issue #5494
for parent, field in this._meta.parents.items():
if field:
setattr(this, parent._meta.pk.attname, None)
this.save(mark_page=False)
self.public_extension = this
self.save(mark_page=False)
this.copy_relations(self, language)
this.save(force_update=True, mark_page=False)
return this
class PageExtension(BaseExtension):
extended_object = models.OneToOneField(Page, on_delete=models.CASCADE, editable=False)
class Meta:
abstract = True
def get_page(self):
return self.extended_object
def save(self, *args, **kwargs):
if kwargs.pop('mark_page', True):
self.get_page().title_set.update(publisher_state=PUBLISHER_STATE_DIRTY) # mark page dirty
return super(BaseExtension, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
if kwargs.pop('mark_page', True):
self.get_page().title_set.update(publisher_state=PUBLISHER_STATE_DIRTY) # mark page dirty
return super(BaseExtension, self).delete(*args, **kwargs)
class TitleExtension(BaseExtension):
extended_object = models.OneToOneField(Title, on_delete=models.CASCADE, editable=False)
class Meta:
abstract = True
def get_page(self):
return self.extended_object.page
def save(self, *args, **kwargs):
if kwargs.pop('mark_page', True):
Title.objects.filter(pk=self.extended_object.pk).update(
publisher_state=PUBLISHER_STATE_DIRTY) # mark title dirty
return super(BaseExtension, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
if kwargs.pop('mark_page', True):
Title.objects.filter(pk=self.extended_object.pk).update(
publisher_state=PUBLISHER_STATE_DIRTY) # mark title dirty
return super(BaseExtension, self).delete(*args, **kwargs)
|
bsd-3-clause
|
[
504,
1639,
14,
697,
14,
992,
492,
28409,
199,
199,
504,
19240,
14,
5559,
492,
18787,
44,
1311,
3452,
63,
6689,
63,
3022,
2099,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
19240,
14,
992,
492,
10331,
12,
16881,
421,
199,
533,
3523,
6382,
8,
992,
14,
1685,
304,
272,
4575,
63,
3435,
275,
1709,
14,
14298,
8,
267,
283,
277,
297,
267,
641,
63,
1807,
29,
992,
14,
10855,
12,
267,
2973,
29,
549,
12,
267,
14783,
29,
797,
12,
267,
4048,
63,
354,
534,
7185,
63,
3435,
297,
272,
776,
272,
9243,
63,
785,
275,
488,
339,
1021,
6288,
26,
267,
9006,
275,
715,
339,
347,
664,
63,
1606,
8,
277,
304,
221,
327,
11942,
26,
949,
8486,
267,
746,
4279,
360,
3481,
1471,
506,
20200,
315,
9180,
436,
372,
314,
9243,
2034,
909,
2659,
339,
347,
1331,
63,
15741,
8,
277,
12,
2269,
842,
12,
2637,
304,
267,
408,
267,
11247,
16109,
2839,
5002,
370,
5002,
503,
11608,
790,
16109,
370,
314,
4575,
1015,
14,
267,
20046,
370,
314,
2011,
4310,
19240,
3589,
805,
14,
398,
520,
635,
2269,
842,
26,
314,
11872,
1015,
402,
314,
3329,
267,
408,
267,
986,
339,
768,
3744,
272,
347,
485,
362,
63,
2407,
63,
1462,
8,
1886,
304,
267,
1504,
275,
843,
423,
2024,
423,
362,
63,
955,
8,
288,
7568,
29,
797,
12,
3837,
29,
549,
12,
288,
2387,
63,
8859,
29,
549,
12,
288,
2387,
63,
5642,
29,
797,
12,
267,
776,
267,
372,
769,
8,
1113,
367,
1559,
315,
1504,
340,
440,
1228,
8,
1113,
14,
698,
12,
28409,
430,
339,
347,
1331,
8,
277,
12,
1347,
12,
2637,
304,
267,
408,
267,
961,
1083,
6866,
642,
3329,
370,
376,
625,
2407,
13,
1375,
14,
982,
1265,
315,
7169,
267,
370,
298,
4763,
2,
642,
3329,
370,
314,
19704,
7055,
2064,
402,
1347,
12,
2066,
267,
675,
1331,
63,
475,
63,
4763,
342,
3140,
14,
267,
408,
267,
7289,
275,
291,
855,
533,
4343,
1462,
14,
362,
8,
2051,
29,
277,
14,
2051,
9,
221,
327,
664,
282,
1331,
402,
642,
1256,
267,
7289,
14,
2051,
275,
488,
267,
7289,
14,
3455,
63,
3435,
275,
488,
267,
7289,
14,
10525,
63,
785,
275,
1347,
221,
327,
663,
314,
892,
4575,
909,
398,
327,
653,
348,
8209,
1006,
13801,
1676,
5062,
2883,
14,
1666,
4976,
327,
1477,
2635,
267,
367,
1676,
12,
901,
315,
7289,
423,
2024,
14,
8859,
14,
1744,
837,
288,
340,
901,
26,
355,
5371,
8,
6311,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
12,
488,
9,
398,
7289,
14,
2117,
8,
1657,
63,
1606,
29,
797,
9,
398,
327,
982,
314,
1347,
781,
3984,
16743,
2575,
965,
282,
19704,
7055,
2064,
12,
2066,
267,
327,
4907,
314,
21185,
14,
267,
1347,
63,
12446,
275,
2519,
8,
1375,
12,
283,
12789,
63,
3455,
358,
267,
340,
1347,
63,
12446,
26,
288,
4048,
63,
354,
275,
291,
855,
533,
4914,
354,
4343,
2325,
342,
288,
7289,
63,
12446,
275,
2519,
8,
1375,
63,
12446,
12,
4048,
63,
354,
9,
288,
340,
7289,
63,
12446,
26,
355,
7289,
14,
3455,
63,
3435,
275,
7289,
63,
12446,
288,
587,
26,
355,
7289,
14,
3455,
63,
3435,
275,
488,
398,
7289,
14,
1574,
63,
15741,
8,
277,
12,
2637,
9,
267,
7289,
14,
2117,
8,
3990,
63,
873,
29,
549,
12,
2216,
63,
1606,
29,
797,
9,
267,
372,
7289,
339,
347,
1331,
63,
475,
63,
3455,
8,
277,
12,
4575,
63,
785,
12,
2637,
304,
267,
408,
267,
961,
1083,
365,
1202,
370,
298,
4763,
2,
642,
3329,
465,
1777,
402,
314,
282,
12142,
267,
3439,
641,
314,
1347,
14,
982,
1265,
315,
7169,
370,
1331,
642,
3329,
370,
376,
267,
625,
2407,
909,
12,
675,
1331,
342,
3140,
14,
267,
408,
267,
642,
275,
291,
855,
533,
4343,
1462,
14,
362,
8,
2051,
29,
277,
14,
2051,
9,
221,
327,
664,
282,
1331,
402,
642,
1256,
267,
4575,
63,
3435,
275,
291,
14,
3455,
63,
3435,
221,
327,
664,
314,
4575,
1015,
402,
642,
1256,
340,
1263,
398,
642,
14,
10525,
63,
785,
275,
4575,
63,
785,
221,
327,
663,
314,
892,
4575,
909,
398,
340,
4575,
63,
3435,
26,
288,
642,
14,
2051,
275,
4575,
63,
3435,
14,
2051,
221,
327,
8970,
1453,
4575,
3329,
288,
642,
14,
3455,
63,
3435,
275,
488,
221,
327,
2813,
4575,
3329,
503,
652,
911,
2376,
370,
6337,
436,
746,
9250,
2397,
953,
327,
2494,
4575,
63,
3435,
13801,
8623,
18368,
83,
14,
1666,
4976,
327,
1477,
2635,
288,
367,
1676,
12,
901,
315,
642,
423,
2024,
14,
8859,
14,
1744,
837,
355,
340,
901,
26,
490,
5371,
8,
3749,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
12,
2519,
8,
3455,
63,
3435,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
430,
267,
587,
26,
288,
642,
14,
2051,
275,
488,
221,
327,
1218,
892,
4575,
3329,
953,
327,
653,
348,
8209,
1006,
13801,
1676,
5062,
2883,
14,
1666,
4976,
327,
1477,
2635,
288,
367,
1676,
12,
901,
315,
642,
423,
2024,
14,
8859,
14,
1744,
837,
355,
340,
901,
26,
490,
5371,
8,
3749,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
12,
488,
9,
953,
642,
14,
2117,
8,
1657,
63,
1606,
29,
797,
9,
288,
291,
14,
3455,
63,
3435,
275,
642,
288,
291,
14,
2117,
8,
1657,
63,
1606,
29,
797,
9,
398,
642,
14,
1574,
63,
15741,
8,
277,
12,
2637,
9,
267,
642,
14,
2117,
8,
3990,
63,
873,
29,
549,
12,
2216,
63,
1606,
29,
797,
9,
398,
372,
642,
421,
199,
533,
10331,
6382,
8,
1563,
6382,
304,
272,
9243,
63,
785,
275,
1709,
14,
14298,
8,
3276,
12,
641,
63,
1807,
29,
992,
14,
10855,
12,
14783,
29,
797,
9,
339,
1021,
6288,
26,
267,
9006,
275,
715,
339,
347,
664,
63,
1606,
8,
277,
304,
267,
372,
291,
14,
10525,
63,
785,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
2074,
14,
1935,
360,
1657,
63,
1606,
297,
715,
304,
288,
291,
14,
362,
63,
1606,
1252,
1213,
63,
409,
14,
873,
8,
12789,
63,
929,
29,
30266,
1311,
3452,
63,
6689,
63,
3022
] |
[
1639,
14,
697,
14,
992,
492,
28409,
199,
199,
504,
19240,
14,
5559,
492,
18787,
44,
1311,
3452,
63,
6689,
63,
3022,
2099,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
19240,
14,
992,
492,
10331,
12,
16881,
421,
199,
533,
3523,
6382,
8,
992,
14,
1685,
304,
272,
4575,
63,
3435,
275,
1709,
14,
14298,
8,
267,
283,
277,
297,
267,
641,
63,
1807,
29,
992,
14,
10855,
12,
267,
2973,
29,
549,
12,
267,
14783,
29,
797,
12,
267,
4048,
63,
354,
534,
7185,
63,
3435,
297,
272,
776,
272,
9243,
63,
785,
275,
488,
339,
1021,
6288,
26,
267,
9006,
275,
715,
339,
347,
664,
63,
1606,
8,
277,
304,
221,
327,
11942,
26,
949,
8486,
267,
746,
4279,
360,
3481,
1471,
506,
20200,
315,
9180,
436,
372,
314,
9243,
2034,
909,
2659,
339,
347,
1331,
63,
15741,
8,
277,
12,
2269,
842,
12,
2637,
304,
267,
408,
267,
11247,
16109,
2839,
5002,
370,
5002,
503,
11608,
790,
16109,
370,
314,
4575,
1015,
14,
267,
20046,
370,
314,
2011,
4310,
19240,
3589,
805,
14,
398,
520,
635,
2269,
842,
26,
314,
11872,
1015,
402,
314,
3329,
267,
408,
267,
986,
339,
768,
3744,
272,
347,
485,
362,
63,
2407,
63,
1462,
8,
1886,
304,
267,
1504,
275,
843,
423,
2024,
423,
362,
63,
955,
8,
288,
7568,
29,
797,
12,
3837,
29,
549,
12,
288,
2387,
63,
8859,
29,
549,
12,
288,
2387,
63,
5642,
29,
797,
12,
267,
776,
267,
372,
769,
8,
1113,
367,
1559,
315,
1504,
340,
440,
1228,
8,
1113,
14,
698,
12,
28409,
430,
339,
347,
1331,
8,
277,
12,
1347,
12,
2637,
304,
267,
408,
267,
961,
1083,
6866,
642,
3329,
370,
376,
625,
2407,
13,
1375,
14,
982,
1265,
315,
7169,
267,
370,
298,
4763,
2,
642,
3329,
370,
314,
19704,
7055,
2064,
402,
1347,
12,
2066,
267,
675,
1331,
63,
475,
63,
4763,
342,
3140,
14,
267,
408,
267,
7289,
275,
291,
855,
533,
4343,
1462,
14,
362,
8,
2051,
29,
277,
14,
2051,
9,
221,
327,
664,
282,
1331,
402,
642,
1256,
267,
7289,
14,
2051,
275,
488,
267,
7289,
14,
3455,
63,
3435,
275,
488,
267,
7289,
14,
10525,
63,
785,
275,
1347,
221,
327,
663,
314,
892,
4575,
909,
398,
327,
653,
348,
8209,
1006,
13801,
1676,
5062,
2883,
14,
1666,
4976,
327,
1477,
2635,
267,
367,
1676,
12,
901,
315,
7289,
423,
2024,
14,
8859,
14,
1744,
837,
288,
340,
901,
26,
355,
5371,
8,
6311,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
12,
488,
9,
398,
7289,
14,
2117,
8,
1657,
63,
1606,
29,
797,
9,
398,
327,
982,
314,
1347,
781,
3984,
16743,
2575,
965,
282,
19704,
7055,
2064,
12,
2066,
267,
327,
4907,
314,
21185,
14,
267,
1347,
63,
12446,
275,
2519,
8,
1375,
12,
283,
12789,
63,
3455,
358,
267,
340,
1347,
63,
12446,
26,
288,
4048,
63,
354,
275,
291,
855,
533,
4914,
354,
4343,
2325,
342,
288,
7289,
63,
12446,
275,
2519,
8,
1375,
63,
12446,
12,
4048,
63,
354,
9,
288,
340,
7289,
63,
12446,
26,
355,
7289,
14,
3455,
63,
3435,
275,
7289,
63,
12446,
288,
587,
26,
355,
7289,
14,
3455,
63,
3435,
275,
488,
398,
7289,
14,
1574,
63,
15741,
8,
277,
12,
2637,
9,
267,
7289,
14,
2117,
8,
3990,
63,
873,
29,
549,
12,
2216,
63,
1606,
29,
797,
9,
267,
372,
7289,
339,
347,
1331,
63,
475,
63,
3455,
8,
277,
12,
4575,
63,
785,
12,
2637,
304,
267,
408,
267,
961,
1083,
365,
1202,
370,
298,
4763,
2,
642,
3329,
465,
1777,
402,
314,
282,
12142,
267,
3439,
641,
314,
1347,
14,
982,
1265,
315,
7169,
370,
1331,
642,
3329,
370,
376,
267,
625,
2407,
909,
12,
675,
1331,
342,
3140,
14,
267,
408,
267,
642,
275,
291,
855,
533,
4343,
1462,
14,
362,
8,
2051,
29,
277,
14,
2051,
9,
221,
327,
664,
282,
1331,
402,
642,
1256,
267,
4575,
63,
3435,
275,
291,
14,
3455,
63,
3435,
221,
327,
664,
314,
4575,
1015,
402,
642,
1256,
340,
1263,
398,
642,
14,
10525,
63,
785,
275,
4575,
63,
785,
221,
327,
663,
314,
892,
4575,
909,
398,
340,
4575,
63,
3435,
26,
288,
642,
14,
2051,
275,
4575,
63,
3435,
14,
2051,
221,
327,
8970,
1453,
4575,
3329,
288,
642,
14,
3455,
63,
3435,
275,
488,
221,
327,
2813,
4575,
3329,
503,
652,
911,
2376,
370,
6337,
436,
746,
9250,
2397,
953,
327,
2494,
4575,
63,
3435,
13801,
8623,
18368,
83,
14,
1666,
4976,
327,
1477,
2635,
288,
367,
1676,
12,
901,
315,
642,
423,
2024,
14,
8859,
14,
1744,
837,
355,
340,
901,
26,
490,
5371,
8,
3749,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
12,
2519,
8,
3455,
63,
3435,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
430,
267,
587,
26,
288,
642,
14,
2051,
275,
488,
221,
327,
1218,
892,
4575,
3329,
953,
327,
653,
348,
8209,
1006,
13801,
1676,
5062,
2883,
14,
1666,
4976,
327,
1477,
2635,
288,
367,
1676,
12,
901,
315,
642,
423,
2024,
14,
8859,
14,
1744,
837,
355,
340,
901,
26,
490,
5371,
8,
3749,
12,
1676,
423,
2024,
14,
2051,
14,
13651,
12,
488,
9,
953,
642,
14,
2117,
8,
1657,
63,
1606,
29,
797,
9,
288,
291,
14,
3455,
63,
3435,
275,
642,
288,
291,
14,
2117,
8,
1657,
63,
1606,
29,
797,
9,
398,
642,
14,
1574,
63,
15741,
8,
277,
12,
2637,
9,
267,
642,
14,
2117,
8,
3990,
63,
873,
29,
549,
12,
2216,
63,
1606,
29,
797,
9,
398,
372,
642,
421,
199,
533,
10331,
6382,
8,
1563,
6382,
304,
272,
9243,
63,
785,
275,
1709,
14,
14298,
8,
3276,
12,
641,
63,
1807,
29,
992,
14,
10855,
12,
14783,
29,
797,
9,
339,
1021,
6288,
26,
267,
9006,
275,
715,
339,
347,
664,
63,
1606,
8,
277,
304,
267,
372,
291,
14,
10525,
63,
785,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
2074,
14,
1935,
360,
1657,
63,
1606,
297,
715,
304,
288,
291,
14,
362,
63,
1606,
1252,
1213,
63,
409,
14,
873,
8,
12789,
63,
929,
29,
30266,
1311,
3452,
63,
6689,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1,
1,
1,
1,
1
] |
j-greffe/mbed-os
|
tools/host_tests/host_tests_plugins/module_copy_mps2.py
|
55
|
5528
|
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
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
import os, shutil
from os.path import join
from host_test_plugins import HostTestPluginBase
from time import sleep
class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):
# MPS2 specific flashing / binary setup funcitons
def mps2_set_board_image_file(self, disk, images_cfg_path, image0file_path, image_name='images.txt'):
""" This function will alter image cfg file.
Main goal of this function is to change number of images to 1, comment all
existing image entries and append at the end of file new entry with test path.
@return True when all steps succeed.
"""
MBED_SDK_TEST_STAMP = 'test suite entry'
image_path = join(disk, images_cfg_path, image_name)
new_file_lines = [] # New configuration file lines (entries)
# Check each line of the image configuration file
try:
with open(image_path, 'r') as file:
for line in file:
if re.search('^TOTALIMAGES', line):
# Check number of total images, should be 1
new_file_lines.append(re.sub('^TOTALIMAGES:[\t ]*[\d]+', 'TOTALIMAGES: 1', line))
elif re.search('; - %s[\n\r]*$'% MBED_SDK_TEST_STAMP, line):
# Look for test suite entries and remove them
pass # Omit all test suite entries
elif re.search('^IMAGE[\d]+FILE', line):
# Check all image entries and mark the ';'
new_file_lines.append(';' + line) # Comment non test suite lines
else:
# Append line to new file
new_file_lines.append(line)
except IOError as e:
return False
# Add new image entry with proper commented stamp
new_file_lines.append('IMAGE0FILE: %s ; - %s\r\n'% (image0file_path, MBED_SDK_TEST_STAMP))
# Write all lines to file
try:
with open(image_path, 'w') as file:
for line in new_file_lines:
file.write(line),
except IOError:
return False
return True
def mps2_select_core(self, disk, mobo_config_name=""):
""" Function selects actual core
"""
# TODO: implement core selection
pass
def mps2_switch_usb_auto_mounting_after_restart(self, disk, usb_config_name=""):
""" Function alters configuration to allow USB MSD to be mounted after restarts
"""
# TODO: implement USB MSD restart detection
pass
def copy_file(self, file, disk):
if not file:
return
_, ext = os.path.splitext(file)
ext = ext.lower()
dfile = disk + "/SOFTWARE/mbed" + ext
if os.path.isfile(dfile):
print('Remove old binary %s' % dfile)
os.remove(dfile)
shutil.copy(file, dfile)
return True
def touch_file(self, file):
""" Touch file and set timestamp to items
"""
tfile = file+'.tmp'
fhandle = open(tfile, 'a')
try:
fhandle.close()
finally:
os.rename(tfile, file)
return True
# Plugin interface
name = 'HostTestPluginCopyMethod_MPS2'
type = 'CopyMethod'
capabilities = ['mps2-copy']
required_parameters = ['image_path', 'destination_disk']
def setup(self, *args, **kwargs):
""" Configure plugin, this function should be called before plugin execute() method is used.
"""
return True
def execute(self, capabilitity, *args, **kwargs):
""" Executes capability by name.
Each capability may directly just call some command line
program or execute building pythonic function
"""
result = False
if self.check_parameters(capabilitity, *args, **kwargs) is True:
file = kwargs['image_path']
disk = kwargs['destination_disk']
""" Add a delay in case there a test just finished
Prevents interface firmware hiccups
"""
sleep(20)
if capabilitity == 'mps2-copy' and self.copy_file(file, disk):
sleep(3)
if self.touch_file(disk + 'reboot.txt'):
""" Add a delay after the board was rebooted.
The actual reboot time is 20 seconds, but using 15 seconds
allows us to open the COM port and save a board reset.
This also prevents interface firmware hiccups.
"""
sleep(7)
result = True
return result
def load_plugin():
""" Returns plugin available in this module
"""
return HostTestPluginCopyMethod_MPS2()
|
apache-2.0
|
[
624,
199,
3665,
15610,
199,
7384,
334,
67,
9,
7760,
13,
6965,
27155,
23954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
646,
295,
199,
646,
747,
12,
5145,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
1591,
63,
396,
63,
5265,
492,
10891,
774,
5061,
1563,
199,
504,
900,
492,
9435,
421,
199,
533,
10891,
774,
5061,
5116,
3767,
63,
1658,
51,
18,
8,
4965,
774,
5061,
1563,
304,
339,
327,
603,
5067,
18,
2488,
14775,
316,
1182,
3366,
3272,
2562,
390,
4654,
272,
347,
6118,
83,
18,
63,
409,
63,
3576,
63,
1569,
63,
493,
8,
277,
12,
4543,
12,
5935,
63,
4128,
63,
515,
12,
1834,
16,
493,
63,
515,
12,
1834,
63,
354,
534,
4782,
14,
2424,
735,
267,
408,
961,
805,
911,
17355,
1834,
4810,
570,
14,
288,
11298,
14850,
402,
642,
805,
365,
370,
1570,
1329,
402,
5935,
370,
413,
12,
3721,
1006,
288,
3411,
1834,
4811,
436,
5666,
737,
314,
1284,
402,
570,
892,
2397,
543,
511,
931,
14,
288,
768,
1107,
715,
1380,
1006,
7124,
17961,
14,
267,
408,
267,
19487,
1149,
63,
14939,
63,
2864,
63,
840,
7089,
275,
283,
396,
5241,
2397,
7,
267,
1834,
63,
515,
275,
4263,
8,
4032,
12,
5935,
63,
4128,
63,
515,
12,
1834,
63,
354,
9,
267,
892,
63,
493,
63,
1278,
275,
942,
327,
7053,
2897,
570,
2385,
334,
3189,
9,
398,
327,
2670,
1924,
1004,
402,
314,
1834,
2897,
570,
267,
862,
26,
288,
543,
1551,
8,
1569,
63,
515,
12,
283,
82,
358,
465,
570,
26,
355,
367,
1004,
315,
570,
26,
490,
340,
295,
14,
1733,
9097,
15386,
1469,
5383,
297,
1004,
304,
717,
327,
2670,
1329,
402,
3141,
5935,
12,
1077,
506,
413,
717,
892,
63,
493,
63,
1278,
14,
740,
8,
264,
14,
954,
9097,
15386,
1469,
5383,
26,
7023,
84,
1622,
10,
7023,
68,
11529,
283,
15386,
1469,
5383,
26,
413,
297,
1004,
430,
490,
916,
295,
14,
1733,
25282,
446,
450,
83,
7023,
78,
60,
82,
3672,
4,
5956,
19487,
1149,
63,
14939,
63,
2864,
63,
840,
7089,
12,
1004,
304,
717,
327,
12077,
367,
511,
5241,
4811,
436,
2813,
3062,
717,
986,
259,
327,
593,
1147,
1006,
511,
5241,
4811,
490,
916,
295,
14,
1733,
9097,
9438,
7023,
68,
2807,
3817,
297,
1004,
304,
717,
327,
2670,
1006,
1834,
4811,
436,
2216,
314,
20054,
717,
892,
63,
493,
63,
1278,
14,
740,
360,
8942,
435,
1004,
9,
257,
327,
6819,
2222,
511,
5241,
2385,
490,
587,
26,
717,
327,
18726,
1004,
370,
892,
570,
717,
892,
63,
493,
63,
1278,
14,
740,
8,
604,
9,
267,
871,
5925,
465,
325,
26,
288,
372,
756,
398,
327,
2654,
892,
1834,
2397,
543,
5576,
21804,
16206,
267,
892,
63,
493,
63,
1278,
14,
740,
360,
9438,
16,
3817,
26,
450,
83,
259,
8700,
446,
450,
83,
60,
82,
60,
78,
5956,
334,
1569,
16,
493,
63,
515,
12,
19487,
1149,
63,
14939,
63,
2864,
63,
840,
7089,
430,
398,
327,
6990,
1006,
2385,
370,
570,
267,
862,
26,
288,
543,
1551,
8,
1569,
63,
515,
12,
283,
87,
358,
465,
570,
26,
355,
367,
1004,
315,
892,
63,
493,
63,
1278,
26,
490,
570,
14,
952,
8,
604,
395,
267,
871,
5925,
26,
288,
372,
756,
398,
372,
715,
339,
347,
6118,
83,
18,
63,
2416,
63,
1018,
8,
277,
12,
4543,
12,
1303,
656,
63,
888,
63,
354,
17364,
267,
408,
6801,
24750,
3503,
6170,
267,
408,
267,
327,
3254,
26,
5669,
6170,
7267,
267,
986,
339,
347,
6118,
83,
18,
63,
5656,
63,
17411,
63,
2495,
63,
3956,
316,
63,
4399,
63,
10506,
8,
277,
12,
4543,
12,
27923,
63,
888,
63,
354,
17364,
267,
408,
6801,
741,
878,
2897,
370,
2040,
28655,
603,
3693,
370,
506,
27979,
2410,
11004,
83,
267,
408,
267,
327,
3254,
26,
5669,
28655,
603,
3693,
11004,
15212,
267,
986,
339,
347,
1331,
63,
493,
8,
277,
12,
570,
12,
4543,
304,
267,
340,
440,
570,
26,
288,
372,
10631,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
493,
9,
267,
1599,
275,
1599,
14,
2325,
342,
267,
366,
493,
275,
4543,
435,
3286,
26734,
15,
3665,
2,
435,
1599,
2728,
340,
747,
14,
515,
14,
6292,
8,
68,
493,
304,
288,
870,
360,
5587,
2269,
3366,
450,
83,
7,
450,
366,
493,
9,
288,
747,
14,
2168,
8,
68,
493,
9,
398,
5145,
14,
1574,
8,
493,
12,
366,
493,
9,
267,
372,
715,
5493,
347,
12943,
63,
493,
8,
277,
12,
570,
304,
267,
408,
377,
13087,
570,
436,
663,
4913,
370,
2974,
267,
408,
267,
307,
493,
275,
570,
18098,
2791,
7,
267,
289,
2479,
275,
1551,
8,
84,
493,
12,
283,
65,
358,
267,
862,
26,
288,
289,
2479,
14,
1600,
342,
267,
3753,
26,
288,
747,
14,
8165,
8,
84,
493,
12,
570,
9,
288,
372,
715,
339,
327,
11349,
3217,
272,
536,
275,
283,
4965,
774,
5061,
5116,
3767,
63,
1658,
51,
18,
7,
272,
730,
275,
283,
5116,
3767,
7,
272,
14918,
275,
788,
13408,
18,
13,
1574,
418,
272,
1415,
63,
3214,
275,
788,
1569,
63,
515,
297,
283,
6881,
63,
4032,
418,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
15453,
3589,
12,
642,
805,
1077,
506,
2797,
2544,
3589,
5341,
342,
1083,
365,
1202,
14,
267,
408,
267,
372,
715,
339,
347,
5341,
8,
277,
12,
4021,
25007,
1701,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9434,
3862,
19854,
701
] |
[
199,
3665,
15610,
199,
7384,
334,
67,
9,
7760,
13,
6965,
27155,
23954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
646,
295,
199,
646,
747,
12,
5145,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
1591,
63,
396,
63,
5265,
492,
10891,
774,
5061,
1563,
199,
504,
900,
492,
9435,
421,
199,
533,
10891,
774,
5061,
5116,
3767,
63,
1658,
51,
18,
8,
4965,
774,
5061,
1563,
304,
339,
327,
603,
5067,
18,
2488,
14775,
316,
1182,
3366,
3272,
2562,
390,
4654,
272,
347,
6118,
83,
18,
63,
409,
63,
3576,
63,
1569,
63,
493,
8,
277,
12,
4543,
12,
5935,
63,
4128,
63,
515,
12,
1834,
16,
493,
63,
515,
12,
1834,
63,
354,
534,
4782,
14,
2424,
735,
267,
408,
961,
805,
911,
17355,
1834,
4810,
570,
14,
288,
11298,
14850,
402,
642,
805,
365,
370,
1570,
1329,
402,
5935,
370,
413,
12,
3721,
1006,
288,
3411,
1834,
4811,
436,
5666,
737,
314,
1284,
402,
570,
892,
2397,
543,
511,
931,
14,
288,
768,
1107,
715,
1380,
1006,
7124,
17961,
14,
267,
408,
267,
19487,
1149,
63,
14939,
63,
2864,
63,
840,
7089,
275,
283,
396,
5241,
2397,
7,
267,
1834,
63,
515,
275,
4263,
8,
4032,
12,
5935,
63,
4128,
63,
515,
12,
1834,
63,
354,
9,
267,
892,
63,
493,
63,
1278,
275,
942,
327,
7053,
2897,
570,
2385,
334,
3189,
9,
398,
327,
2670,
1924,
1004,
402,
314,
1834,
2897,
570,
267,
862,
26,
288,
543,
1551,
8,
1569,
63,
515,
12,
283,
82,
358,
465,
570,
26,
355,
367,
1004,
315,
570,
26,
490,
340,
295,
14,
1733,
9097,
15386,
1469,
5383,
297,
1004,
304,
717,
327,
2670,
1329,
402,
3141,
5935,
12,
1077,
506,
413,
717,
892,
63,
493,
63,
1278,
14,
740,
8,
264,
14,
954,
9097,
15386,
1469,
5383,
26,
7023,
84,
1622,
10,
7023,
68,
11529,
283,
15386,
1469,
5383,
26,
413,
297,
1004,
430,
490,
916,
295,
14,
1733,
25282,
446,
450,
83,
7023,
78,
60,
82,
3672,
4,
5956,
19487,
1149,
63,
14939,
63,
2864,
63,
840,
7089,
12,
1004,
304,
717,
327,
12077,
367,
511,
5241,
4811,
436,
2813,
3062,
717,
986,
259,
327,
593,
1147,
1006,
511,
5241,
4811,
490,
916,
295,
14,
1733,
9097,
9438,
7023,
68,
2807,
3817,
297,
1004,
304,
717,
327,
2670,
1006,
1834,
4811,
436,
2216,
314,
20054,
717,
892,
63,
493,
63,
1278,
14,
740,
360,
8942,
435,
1004,
9,
257,
327,
6819,
2222,
511,
5241,
2385,
490,
587,
26,
717,
327,
18726,
1004,
370,
892,
570,
717,
892,
63,
493,
63,
1278,
14,
740,
8,
604,
9,
267,
871,
5925,
465,
325,
26,
288,
372,
756,
398,
327,
2654,
892,
1834,
2397,
543,
5576,
21804,
16206,
267,
892,
63,
493,
63,
1278,
14,
740,
360,
9438,
16,
3817,
26,
450,
83,
259,
8700,
446,
450,
83,
60,
82,
60,
78,
5956,
334,
1569,
16,
493,
63,
515,
12,
19487,
1149,
63,
14939,
63,
2864,
63,
840,
7089,
430,
398,
327,
6990,
1006,
2385,
370,
570,
267,
862,
26,
288,
543,
1551,
8,
1569,
63,
515,
12,
283,
87,
358,
465,
570,
26,
355,
367,
1004,
315,
892,
63,
493,
63,
1278,
26,
490,
570,
14,
952,
8,
604,
395,
267,
871,
5925,
26,
288,
372,
756,
398,
372,
715,
339,
347,
6118,
83,
18,
63,
2416,
63,
1018,
8,
277,
12,
4543,
12,
1303,
656,
63,
888,
63,
354,
17364,
267,
408,
6801,
24750,
3503,
6170,
267,
408,
267,
327,
3254,
26,
5669,
6170,
7267,
267,
986,
339,
347,
6118,
83,
18,
63,
5656,
63,
17411,
63,
2495,
63,
3956,
316,
63,
4399,
63,
10506,
8,
277,
12,
4543,
12,
27923,
63,
888,
63,
354,
17364,
267,
408,
6801,
741,
878,
2897,
370,
2040,
28655,
603,
3693,
370,
506,
27979,
2410,
11004,
83,
267,
408,
267,
327,
3254,
26,
5669,
28655,
603,
3693,
11004,
15212,
267,
986,
339,
347,
1331,
63,
493,
8,
277,
12,
570,
12,
4543,
304,
267,
340,
440,
570,
26,
288,
372,
10631,
5501,
1599,
275,
747,
14,
515,
14,
7973,
8,
493,
9,
267,
1599,
275,
1599,
14,
2325,
342,
267,
366,
493,
275,
4543,
435,
3286,
26734,
15,
3665,
2,
435,
1599,
2728,
340,
747,
14,
515,
14,
6292,
8,
68,
493,
304,
288,
870,
360,
5587,
2269,
3366,
450,
83,
7,
450,
366,
493,
9,
288,
747,
14,
2168,
8,
68,
493,
9,
398,
5145,
14,
1574,
8,
493,
12,
366,
493,
9,
267,
372,
715,
5493,
347,
12943,
63,
493,
8,
277,
12,
570,
304,
267,
408,
377,
13087,
570,
436,
663,
4913,
370,
2974,
267,
408,
267,
307,
493,
275,
570,
18098,
2791,
7,
267,
289,
2479,
275,
1551,
8,
84,
493,
12,
283,
65,
358,
267,
862,
26,
288,
289,
2479,
14,
1600,
342,
267,
3753,
26,
288,
747,
14,
8165,
8,
84,
493,
12,
570,
9,
288,
372,
715,
339,
327,
11349,
3217,
272,
536,
275,
283,
4965,
774,
5061,
5116,
3767,
63,
1658,
51,
18,
7,
272,
730,
275,
283,
5116,
3767,
7,
272,
14918,
275,
788,
13408,
18,
13,
1574,
418,
272,
1415,
63,
3214,
275,
788,
1569,
63,
515,
297,
283,
6881,
63,
4032,
418,
339,
347,
3272,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
15453,
3589,
12,
642,
805,
1077,
506,
2797,
2544,
3589,
5341,
342,
1083,
365,
1202,
14,
267,
408,
267,
372,
715,
339,
347,
5341,
8,
277,
12,
4021,
25007,
1701,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9434,
3862,
19854,
701,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
johnweber/bbxm-kernel
|
arch/ia64/scripts/unwcheck.py
|
13143
|
1714
|
#!/usr/bin/python
#
# Usage: unwcheck.py FILE
#
# This script checks the unwind info of each function in file FILE
# and verifies that the sum of the region-lengths matches the total
# length of the function.
#
# Based on a shell/awk script originally written by Harish Patil,
# which was converted to Perl by Matthew Chapman, which was converted
# to Python by David Mosberger.
#
import os
import re
import sys
if len(sys.argv) != 2:
print "Usage: %s FILE" % sys.argv[0]
sys.exit(2)
readelf = os.getenv("READELF", "readelf")
start_pattern = re.compile("<([^>]*)>: \[0x([0-9a-f]+)-0x([0-9a-f]+)\]")
rlen_pattern = re.compile(".*rlen=([0-9]+)")
def check_func (func, slots, rlen_sum):
if slots != rlen_sum:
global num_errors
num_errors += 1
if not func: func = "[%#x-%#x]" % (start, end)
print "ERROR: %s: %lu slots, total region length = %lu" % (func, slots, rlen_sum)
return
num_funcs = 0
num_errors = 0
func = False
slots = 0
rlen_sum = 0
for line in os.popen("%s -u %s" % (readelf, sys.argv[1])):
m = start_pattern.match(line)
if m:
check_func(func, slots, rlen_sum)
func = m.group(1)
start = long(m.group(2), 16)
end = long(m.group(3), 16)
slots = 3 * (end - start) / 16
rlen_sum = 0L
num_funcs += 1
else:
m = rlen_pattern.match(line)
if m:
rlen_sum += long(m.group(1))
check_func(func, slots, rlen_sum)
if num_errors == 0:
print "No errors detected in %u functions." % num_funcs
else:
if num_errors > 1:
err="errors"
else:
err="error"
print "%u %s detected in %u functions." % (num_errors, err, num_funcs)
sys.exit(1)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
11028,
26,
625,
87,
1074,
14,
647,
13024,
199,
3,
199,
3,
961,
2884,
5920,
314,
625,
11530,
2256,
402,
1924,
805,
315,
570,
13024,
199,
3,
436,
22694,
626,
314,
3089,
402,
314,
4897,
13,
14563,
4450,
314,
3141,
199,
3,
2582,
402,
314,
805,
14,
199,
3,
199,
3,
21311,
641,
282,
5218,
15,
10084,
75,
2884,
20657,
5313,
701,
25378,
2453,
510,
2159,
76,
12,
199,
3,
1314,
1990,
6702,
370,
3492,
76,
701,
18619,
29640,
2799,
439,
1237,
12,
1314,
1990,
6702,
199,
3,
370,
2018,
701,
20232,
603,
736,
605,
836,
14,
199,
3,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
13024,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
18,
9,
199,
199,
8273,
271,
276,
275,
747,
14,
12959,
480,
24345,
4424,
38,
401,
298,
8273,
271,
276,
531,
199,
199,
928,
63,
3401,
275,
295,
14,
2014,
6757,
7059,
30,
3672,
13032,
26,
30257,
16,
88,
779,
16,
13,
25,
65,
13,
70,
2807,
7216,
16,
88,
779,
16,
13,
25,
65,
13,
70,
18096,
12523,
199,
82,
552,
63,
3401,
221,
275,
295,
14,
2014,
480,
2795,
82,
552,
30982,
16,
13,
25,
2807,
6320,
199,
199,
318,
1104,
63,
1532,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
304,
272,
340,
14319,
1137,
24746,
63,
1838,
26,
267,
2288,
1967,
63,
2550,
267,
1967,
63,
2550,
847,
413,
267,
340,
440,
2562,
26,
2562,
275,
26503,
3,
88,
3295,
3,
88,
8480,
450,
334,
928,
12,
1284,
9,
267,
870,
298,
3170,
26,
450,
83,
26,
450,
10836,
14319,
12,
3141,
4897,
2582,
275,
450,
10836,
2,
450,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
272,
372,
199,
199,
1507,
63,
9204,
275,
378,
199,
1507,
63,
2550,
275,
378,
199,
1532,
275,
756,
199,
7257,
275,
378,
199,
82,
552,
63,
1838,
275,
378,
199,
509,
1004,
315,
747,
14,
12207,
3647,
83,
446,
85,
450,
83,
2,
450,
334,
8273,
271,
276,
12,
984,
14,
3020,
59,
17,
18710,
272,
333,
275,
1343,
63,
3401,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
267,
1104,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
398,
2562,
221,
275,
333,
14,
923,
8,
17,
9,
267,
1343,
275,
1846,
8,
77,
14,
923,
8,
18,
395,
3193,
9,
267,
1284,
257,
275,
1846,
8,
77,
14,
923,
8,
19,
395,
3193,
9,
267,
14319,
275,
650,
627,
334,
500,
446,
1343,
9,
1182,
3193,
267,
24746,
63,
1838,
275,
378,
44,
267,
1967,
63,
9204,
847,
413,
272,
587,
26,
267,
333,
275,
24746,
63,
3401,
14,
1431,
8,
604,
9,
267,
340,
333,
26,
288,
24746,
63,
1838,
847,
1846,
8,
77,
14,
923,
8,
17,
430,
199,
1074,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
199,
199,
692,
1967,
63,
2550,
508,
378,
26,
272,
870,
298,
1944,
2552,
10501,
315,
450,
85,
3423,
2122,
450,
1967,
63,
9204,
199,
2836,
26,
272,
340,
1967,
63,
2550,
690,
413,
26,
267,
2329,
628,
2550,
2,
272,
587,
26,
267,
2329,
628,
705,
2,
272,
870,
2071,
85,
450,
83,
10501,
315,
450,
85,
3423,
2122,
450,
334,
1507,
63,
2550,
12,
2329,
12,
1967,
63,
9204,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
11028,
26,
625,
87,
1074,
14,
647,
13024,
199,
3,
199,
3,
961,
2884,
5920,
314,
625,
11530,
2256,
402,
1924,
805,
315,
570,
13024,
199,
3,
436,
22694,
626,
314,
3089,
402,
314,
4897,
13,
14563,
4450,
314,
3141,
199,
3,
2582,
402,
314,
805,
14,
199,
3,
199,
3,
21311,
641,
282,
5218,
15,
10084,
75,
2884,
20657,
5313,
701,
25378,
2453,
510,
2159,
76,
12,
199,
3,
1314,
1990,
6702,
370,
3492,
76,
701,
18619,
29640,
2799,
439,
1237,
12,
1314,
1990,
6702,
199,
3,
370,
2018,
701,
20232,
603,
736,
605,
836,
14,
199,
3,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
13024,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
18,
9,
199,
199,
8273,
271,
276,
275,
747,
14,
12959,
480,
24345,
4424,
38,
401,
298,
8273,
271,
276,
531,
199,
199,
928,
63,
3401,
275,
295,
14,
2014,
6757,
7059,
30,
3672,
13032,
26,
30257,
16,
88,
779,
16,
13,
25,
65,
13,
70,
2807,
7216,
16,
88,
779,
16,
13,
25,
65,
13,
70,
18096,
12523,
199,
82,
552,
63,
3401,
221,
275,
295,
14,
2014,
480,
2795,
82,
552,
30982,
16,
13,
25,
2807,
6320,
199,
199,
318,
1104,
63,
1532,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
304,
272,
340,
14319,
1137,
24746,
63,
1838,
26,
267,
2288,
1967,
63,
2550,
267,
1967,
63,
2550,
847,
413,
267,
340,
440,
2562,
26,
2562,
275,
26503,
3,
88,
3295,
3,
88,
8480,
450,
334,
928,
12,
1284,
9,
267,
870,
298,
3170,
26,
450,
83,
26,
450,
10836,
14319,
12,
3141,
4897,
2582,
275,
450,
10836,
2,
450,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
272,
372,
199,
199,
1507,
63,
9204,
275,
378,
199,
1507,
63,
2550,
275,
378,
199,
1532,
275,
756,
199,
7257,
275,
378,
199,
82,
552,
63,
1838,
275,
378,
199,
509,
1004,
315,
747,
14,
12207,
3647,
83,
446,
85,
450,
83,
2,
450,
334,
8273,
271,
276,
12,
984,
14,
3020,
59,
17,
18710,
272,
333,
275,
1343,
63,
3401,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
267,
1104,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
398,
2562,
221,
275,
333,
14,
923,
8,
17,
9,
267,
1343,
275,
1846,
8,
77,
14,
923,
8,
18,
395,
3193,
9,
267,
1284,
257,
275,
1846,
8,
77,
14,
923,
8,
19,
395,
3193,
9,
267,
14319,
275,
650,
627,
334,
500,
446,
1343,
9,
1182,
3193,
267,
24746,
63,
1838,
275,
378,
44,
267,
1967,
63,
9204,
847,
413,
272,
587,
26,
267,
333,
275,
24746,
63,
3401,
14,
1431,
8,
604,
9,
267,
340,
333,
26,
288,
24746,
63,
1838,
847,
1846,
8,
77,
14,
923,
8,
17,
430,
199,
1074,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
199,
199,
692,
1967,
63,
2550,
508,
378,
26,
272,
870,
298,
1944,
2552,
10501,
315,
450,
85,
3423,
2122,
450,
1967,
63,
9204,
199,
2836,
26,
272,
340,
1967,
63,
2550,
690,
413,
26,
267,
2329,
628,
2550,
2,
272,
587,
26,
267,
2329,
628,
705,
2,
272,
870,
2071,
85,
450,
83,
10501,
315,
450,
85,
3423,
2122,
450,
334,
1507,
63,
2550,
12,
2329,
12,
1967,
63,
9204,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
Thraxis/pymedusa
|
lib/requests/packages/chardet/euckrfreq.py
|
3121
|
45978
|
######################## 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 #########################
# Sampling from about 20M text materials include literature and computer technology
# 128 --> 0.79
# 256 --> 0.92
# 512 --> 0.986
# 1024 --> 0.99944
# 2048 --> 0.99999
#
# Idea Distribution Ratio = 0.98653 / (1-0.98653) = 73.24
# Random Distribution Ration = 512 / (2350-512) = 0.279.
#
# Typical Distribution Ratio
EUCKR_TYPICAL_DISTRIBUTION_RATIO = 6.0
EUCKR_TABLE_SIZE = 2352
# Char to FreqOrder table ,
EUCKRCharToFreqOrder = ( \
13, 130, 120,1396, 481,1719,1720, 328, 609, 212,1721, 707, 400, 299,1722, 87,
1397,1723, 104, 536,1117,1203,1724,1267, 685,1268, 508,1725,1726,1727,1728,1398,
1399,1729,1730,1731, 141, 621, 326,1057, 368,1732, 267, 488, 20,1733,1269,1734,
945,1400,1735, 47, 904,1270,1736,1737, 773, 248,1738, 409, 313, 786, 429,1739,
116, 987, 813,1401, 683, 75,1204, 145,1740,1741,1742,1743, 16, 847, 667, 622,
708,1744,1745,1746, 966, 787, 304, 129,1747, 60, 820, 123, 676,1748,1749,1750,
1751, 617,1752, 626,1753,1754,1755,1756, 653,1757,1758,1759,1760,1761,1762, 856,
344,1763,1764,1765,1766, 89, 401, 418, 806, 905, 848,1767,1768,1769, 946,1205,
709,1770,1118,1771, 241,1772,1773,1774,1271,1775, 569,1776, 999,1777,1778,1779,
1780, 337, 751,1058, 28, 628, 254,1781, 177, 906, 270, 349, 891,1079,1782, 19,
1783, 379,1784, 315,1785, 629, 754,1402, 559,1786, 636, 203,1206,1787, 710, 567,
1788, 935, 814,1789,1790,1207, 766, 528,1791,1792,1208,1793,1794,1795,1796,1797,
1403,1798,1799, 533,1059,1404,1405,1156,1406, 936, 884,1080,1800, 351,1801,1802,
1803,1804,1805, 801,1806,1807,1808,1119,1809,1157, 714, 474,1407,1810, 298, 899,
885,1811,1120, 802,1158,1812, 892,1813,1814,1408, 659,1815,1816,1121,1817,1818,
1819,1820,1821,1822, 319,1823, 594, 545,1824, 815, 937,1209,1825,1826, 573,1409,
1022,1827,1210,1828,1829,1830,1831,1832,1833, 556, 722, 807,1122,1060,1834, 697,
1835, 900, 557, 715,1836,1410, 540,1411, 752,1159, 294, 597,1211, 976, 803, 770,
1412,1837,1838, 39, 794,1413, 358,1839, 371, 925,1840, 453, 661, 788, 531, 723,
544,1023,1081, 869, 91,1841, 392, 430, 790, 602,1414, 677,1082, 457,1415,1416,
1842,1843, 475, 327,1024,1417, 795, 121,1844, 733, 403,1418,1845,1846,1847, 300,
119, 711,1212, 627,1848,1272, 207,1849,1850, 796,1213, 382,1851, 519,1852,1083,
893,1853,1854,1855, 367, 809, 487, 671,1856, 663,1857,1858, 956, 471, 306, 857,
1859,1860,1160,1084,1861,1862,1863,1864,1865,1061,1866,1867,1868,1869,1870,1871,
282, 96, 574,1872, 502,1085,1873,1214,1874, 907,1875,1876, 827, 977,1419,1420,
1421, 268,1877,1422,1878,1879,1880, 308,1881, 2, 537,1882,1883,1215,1884,1885,
127, 791,1886,1273,1423,1887, 34, 336, 404, 643,1888, 571, 654, 894, 840,1889,
0, 886,1274, 122, 575, 260, 908, 938,1890,1275, 410, 316,1891,1892, 100,1893,
1894,1123, 48,1161,1124,1025,1895, 633, 901,1276,1896,1897, 115, 816,1898, 317,
1899, 694,1900, 909, 734,1424, 572, 866,1425, 691, 85, 524,1010, 543, 394, 841,
1901,1902,1903,1026,1904,1905,1906,1907,1908,1909, 30, 451, 651, 988, 310,1910,
1911,1426, 810,1216, 93,1912,1913,1277,1217,1914, 858, 759, 45, 58, 181, 610,
269,1915,1916, 131,1062, 551, 443,1000, 821,1427, 957, 895,1086,1917,1918, 375,
1919, 359,1920, 687,1921, 822,1922, 293,1923,1924, 40, 662, 118, 692, 29, 939,
887, 640, 482, 174,1925, 69,1162, 728,1428, 910,1926,1278,1218,1279, 386, 870,
217, 854,1163, 823,1927,1928,1929,1930, 834,1931, 78,1932, 859,1933,1063,1934,
1935,1936,1937, 438,1164, 208, 595,1938,1939,1940,1941,1219,1125,1942, 280, 888,
1429,1430,1220,1431,1943,1944,1945,1946,1947,1280, 150, 510,1432,1948,1949,1950,
1951,1952,1953,1954,1011,1087,1955,1433,1043,1956, 881,1957, 614, 958,1064,1065,
1221,1958, 638,1001, 860, 967, 896,1434, 989, 492, 553,1281,1165,1959,1282,1002,
1283,1222,1960,1961,1962,1963, 36, 383, 228, 753, 247, 454,1964, 876, 678,1965,
1966,1284, 126, 464, 490, 835, 136, 672, 529, 940,1088,1435, 473,1967,1968, 467,
50, 390, 227, 587, 279, 378, 598, 792, 968, 240, 151, 160, 849, 882,1126,1285,
639,1044, 133, 140, 288, 360, 811, 563,1027, 561, 142, 523,1969,1970,1971, 7,
103, 296, 439, 407, 506, 634, 990,1972,1973,1974,1975, 645,1976,1977,1978,1979,
1980,1981, 236,1982,1436,1983,1984,1089, 192, 828, 618, 518,1166, 333,1127,1985,
818,1223,1986,1987,1988,1989,1990,1991,1992,1993, 342,1128,1286, 746, 842,1994,
1995, 560, 223,1287, 98, 8, 189, 650, 978,1288,1996,1437,1997, 17, 345, 250,
423, 277, 234, 512, 226, 97, 289, 42, 167,1998, 201,1999,2000, 843, 836, 824,
532, 338, 783,1090, 182, 576, 436,1438,1439, 527, 500,2001, 947, 889,2002,2003,
2004,2005, 262, 600, 314, 447,2006, 547,2007, 693, 738,1129,2008, 71,1440, 745,
619, 688,2009, 829,2010,2011, 147,2012, 33, 948,2013,2014, 74, 224,2015, 61,
191, 918, 399, 637,2016,1028,1130, 257, 902,2017,2018,2019,2020,2021,2022,2023,
2024,2025,2026, 837,2027,2028,2029,2030, 179, 874, 591, 52, 724, 246,2031,2032,
2033,2034,1167, 969,2035,1289, 630, 605, 911,1091,1168,2036,2037,2038,1441, 912,
2039, 623,2040,2041, 253,1169,1290,2042,1442, 146, 620, 611, 577, 433,2043,1224,
719,1170, 959, 440, 437, 534, 84, 388, 480,1131, 159, 220, 198, 679,2044,1012,
819,1066,1443, 113,1225, 194, 318,1003,1029,2045,2046,2047,2048,1067,2049,2050,
2051,2052,2053, 59, 913, 112,2054, 632,2055, 455, 144, 739,1291,2056, 273, 681,
499,2057, 448,2058,2059, 760,2060,2061, 970, 384, 169, 245,1132,2062,2063, 414,
1444,2064,2065, 41, 235,2066, 157, 252, 877, 568, 919, 789, 580,2067, 725,2068,
2069,1292,2070,2071,1445,2072,1446,2073,2074, 55, 588, 66,1447, 271,1092,2075,
1226,2076, 960,1013, 372,2077,2078,2079,2080,2081,1293,2082,2083,2084,2085, 850,
2086,2087,2088,2089,2090, 186,2091,1068, 180,2092,2093,2094, 109,1227, 522, 606,
2095, 867,1448,1093, 991,1171, 926, 353,1133,2096, 581,2097,2098,2099,1294,1449,
1450,2100, 596,1172,1014,1228,2101,1451,1295,1173,1229,2102,2103,1296,1134,1452,
949,1135,2104,2105,1094,1453,1454,1455,2106,1095,2107,2108,2109,2110,2111,2112,
2113,2114,2115,2116,2117, 804,2118,2119,1230,1231, 805,1456, 405,1136,2120,2121,
2122,2123,2124, 720, 701,1297, 992,1457, 927,1004,2125,2126,2127,2128,2129,2130,
22, 417,2131, 303,2132, 385,2133, 971, 520, 513,2134,1174, 73,1096, 231, 274,
962,1458, 673,2135,1459,2136, 152,1137,2137,2138,2139,2140,1005,1138,1460,1139,
2141,2142,2143,2144, 11, 374, 844,2145, 154,1232, 46,1461,2146, 838, 830, 721,
1233, 106,2147, 90, 428, 462, 578, 566,1175, 352,2148,2149, 538,1234, 124,1298,
2150,1462, 761, 565,2151, 686,2152, 649,2153, 72, 173,2154, 460, 415,2155,1463,
2156,1235, 305,2157,2158,2159,2160,2161,2162, 579,2163,2164,2165,2166,2167, 747,
2168,2169,2170,2171,1464, 669,2172,2173,2174,2175,2176,1465,2177, 23, 530, 285,
2178, 335, 729,2179, 397,2180,2181,2182,1030,2183,2184, 698,2185,2186, 325,2187,
2188, 369,2189, 799,1097,1015, 348,2190,1069, 680,2191, 851,1466,2192,2193, 10,
2194, 613, 424,2195, 979, 108, 449, 589, 27, 172, 81,1031, 80, 774, 281, 350,
1032, 525, 301, 582,1176,2196, 674,1045,2197,2198,1467, 730, 762,2199,2200,2201,
2202,1468,2203, 993,2204,2205, 266,1070, 963,1140,2206,2207,2208, 664,1098, 972,
2209,2210,2211,1177,1469,1470, 871,2212,2213,2214,2215,2216,1471,2217,2218,2219,
2220,2221,2222,2223,2224,2225,2226,2227,1472,1236,2228,2229,2230,2231,2232,2233,
2234,2235,1299,2236,2237, 200,2238, 477, 373,2239,2240, 731, 825, 777,2241,2242,
2243, 521, 486, 548,2244,2245,2246,1473,1300, 53, 549, 137, 875, 76, 158,2247,
1301,1474, 469, 396,1016, 278, 712,2248, 321, 442, 503, 767, 744, 941,1237,1178,
1475,2249, 82, 178,1141,1179, 973,2250,1302,2251, 297,2252,2253, 570,2254,2255,
2256, 18, 450, 206,2257, 290, 292,1142,2258, 511, 162, 99, 346, 164, 735,2259,
1476,1477, 4, 554, 343, 798,1099,2260,1100,2261, 43, 171,1303, 139, 215,2262,
2263, 717, 775,2264,1033, 322, 216,2265, 831,2266, 149,2267,1304,2268,2269, 702,
1238, 135, 845, 347, 309,2270, 484,2271, 878, 655, 238,1006,1478,2272, 67,2273,
295,2274,2275, 461,2276, 478, 942, 412,2277,1034,2278,2279,2280, 265,2281, 541,
2282,2283,2284,2285,2286, 70, 852,1071,2287,2288,2289,2290, 21, 56, 509, 117,
432,2291,2292, 331, 980, 552,1101, 148, 284, 105, 393,1180,1239, 755,2293, 187,
2294,1046,1479,2295, 340,2296, 63,1047, 230,2297,2298,1305, 763,1306, 101, 800,
808, 494,2299,2300,2301, 903,2302, 37,1072, 14, 5,2303, 79, 675,2304, 312,
2305,2306,2307,2308,2309,1480, 6,1307,2310,2311,2312, 1, 470, 35, 24, 229,
2313, 695, 210, 86, 778, 15, 784, 592, 779, 32, 77, 855, 964,2314, 259,2315,
501, 380,2316,2317, 83, 981, 153, 689,1308,1481,1482,1483,2318,2319, 716,1484,
2320,2321,2322,2323,2324,2325,1485,2326,2327, 128, 57, 68, 261,1048, 211, 170,
1240, 31,2328, 51, 435, 742,2329,2330,2331, 635,2332, 264, 456,2333,2334,2335,
425,2336,1486, 143, 507, 263, 943,2337, 363, 920,1487, 256,1488,1102, 243, 601,
1489,2338,2339,2340,2341,2342,2343,2344, 861,2345,2346,2347,2348,2349,2350, 395,
2351,1490,1491, 62, 535, 166, 225,2352,2353, 668, 419,1241, 138, 604, 928,2354,
1181,2355,1492,1493,2356,2357,2358,1143,2359, 696,2360, 387, 307,1309, 682, 476,
2361,2362, 332, 12, 222, 156,2363, 232,2364, 641, 276, 656, 517,1494,1495,1035,
416, 736,1496,2365,1017, 586,2366,2367,2368,1497,2369, 242,2370,2371,2372,1498,
2373, 965, 713,2374,2375,2376,2377, 740, 982,1499, 944,1500,1007,2378,2379,1310,
1501,2380,2381,2382, 785, 329,2383,2384,1502,2385,2386,2387, 932,2388,1503,2389,
2390,2391,2392,1242,2393,2394,2395,2396,2397, 994, 950,2398,2399,2400,2401,1504,
1311,2402,2403,2404,2405,1049, 749,2406,2407, 853, 718,1144,1312,2408,1182,1505,
2409,2410, 255, 516, 479, 564, 550, 214,1506,1507,1313, 413, 239, 444, 339,1145,
1036,1508,1509,1314,1037,1510,1315,2411,1511,2412,2413,2414, 176, 703, 497, 624,
593, 921, 302,2415, 341, 165,1103,1512,2416,1513,2417,2418,2419, 376,2420, 700,
2421,2422,2423, 258, 768,1316,2424,1183,2425, 995, 608,2426,2427,2428,2429, 221,
2430,2431,2432,2433,2434,2435,2436,2437, 195, 323, 726, 188, 897, 983,1317, 377,
644,1050, 879,2438, 452,2439,2440,2441,2442,2443,2444, 914,2445,2446,2447,2448,
915, 489,2449,1514,1184,2450,2451, 515, 64, 427, 495,2452, 583,2453, 483, 485,
1038, 562, 213,1515, 748, 666,2454,2455,2456,2457, 334,2458, 780, 996,1008, 705,
1243,2459,2460,2461,2462,2463, 114,2464, 493,1146, 366, 163,1516, 961,1104,2465,
291,2466,1318,1105,2467,1517, 365,2468, 355, 951,1244,2469,1319,2470, 631,2471,
2472, 218,1320, 364, 320, 756,1518,1519,1321,1520,1322,2473,2474,2475,2476, 997,
2477,2478,2479,2480, 665,1185,2481, 916,1521,2482,2483,2484, 584, 684,2485,2486,
797,2487,1051,1186,2488,2489,2490,1522,2491,2492, 370,2493,1039,1187, 65,2494,
434, 205, 463,1188,2495, 125, 812, 391, 402, 826, 699, 286, 398, 155, 781, 771,
585,2496, 590, 505,1073,2497, 599, 244, 219, 917,1018, 952, 646,1523,2498,1323,
2499,2500, 49, 984, 354, 741,2501, 625,2502,1324,2503,1019, 190, 357, 757, 491,
95, 782, 868,2504,2505,2506,2507,2508,2509, 134,1524,1074, 422,1525, 898,2510,
161,2511,2512,2513,2514, 769,2515,1526,2516,2517, 411,1325,2518, 472,1527,2519,
2520,2521,2522,2523,2524, 985,2525,2526,2527,2528,2529,2530, 764,2531,1245,2532,
2533, 25, 204, 311,2534, 496,2535,1052,2536,2537,2538,2539,2540,2541,2542, 199,
704, 504, 468, 758, 657,1528, 196, 44, 839,1246, 272, 750,2543, 765, 862,2544,
2545,1326,2546, 132, 615, 933,2547, 732,2548,2549,2550,1189,1529,2551, 283,1247,
1053, 607, 929,2552,2553,2554, 930, 183, 872, 616,1040,1147,2555,1148,1020, 441,
249,1075,2556,2557,2558, 466, 743,2559,2560,2561, 92, 514, 426, 420, 526,2562,
2563,2564,2565,2566,2567,2568, 185,2569,2570,2571,2572, 776,1530, 658,2573, 362,
2574, 361, 922,1076, 793,2575,2576,2577,2578,2579,2580,1531, 251,2581,2582,2583,
2584,1532, 54, 612, 237,1327,2585,2586, 275, 408, 647, 111,2587,1533,1106, 465,
3, 458, 9, 38,2588, 107, 110, 890, 209, 26, 737, 498,2589,1534,2590, 431,
202, 88,1535, 356, 287,1107, 660,1149,2591, 381,1536, 986,1150, 445,1248,1151,
974,2592,2593, 846,2594, 446, 953, 184,1249,1250, 727,2595, 923, 193, 883,2596,
2597,2598, 102, 324, 539, 817,2599, 421,1041,2600, 832,2601, 94, 175, 197, 406,
2602, 459,2603,2604,2605,2606,2607, 330, 555,2608,2609,2610, 706,1108, 389,2611,
2612,2613,2614, 233,2615, 833, 558, 931, 954,1251,2616,2617,1537, 546,2618,2619,
1009,2620,2621,2622,1538, 690,1328,2623, 955,2624,1539,2625,2626, 772,2627,2628,
2629,2630,2631, 924, 648, 863, 603,2632,2633, 934,1540, 864, 865,2634, 642,1042,
670,1190,2635,2636,2637,2638, 168,2639, 652, 873, 542,1054,1541,2640,2641,2642, # 512, 256
#Everything below is of no interest for detection purpose
2643,2644,2645,2646,2647,2648,2649,2650,2651,2652,2653,2654,2655,2656,2657,2658,
2659,2660,2661,2662,2663,2664,2665,2666,2667,2668,2669,2670,2671,2672,2673,2674,
2675,2676,2677,2678,2679,2680,2681,2682,2683,2684,2685,2686,2687,2688,2689,2690,
2691,2692,2693,2694,2695,2696,2697,2698,2699,1542, 880,2700,2701,2702,2703,2704,
2705,2706,2707,2708,2709,2710,2711,2712,2713,2714,2715,2716,2717,2718,2719,2720,
2721,2722,2723,2724,2725,1543,2726,2727,2728,2729,2730,2731,2732,1544,2733,2734,
2735,2736,2737,2738,2739,2740,2741,2742,2743,2744,2745,2746,2747,2748,2749,2750,
2751,2752,2753,2754,1545,2755,2756,2757,2758,2759,2760,2761,2762,2763,2764,2765,
2766,1546,2767,1547,2768,2769,2770,2771,2772,2773,2774,2775,2776,2777,2778,2779,
2780,2781,2782,2783,2784,2785,2786,1548,2787,2788,2789,1109,2790,2791,2792,2793,
2794,2795,2796,2797,2798,2799,2800,2801,2802,2803,2804,2805,2806,2807,2808,2809,
2810,2811,2812,1329,2813,2814,2815,2816,2817,2818,2819,2820,2821,2822,2823,2824,
2825,2826,2827,2828,2829,2830,2831,2832,2833,2834,2835,2836,2837,2838,2839,2840,
2841,2842,2843,2844,2845,2846,2847,2848,2849,2850,2851,2852,2853,2854,2855,2856,
1549,2857,2858,2859,2860,1550,2861,2862,1551,2863,2864,2865,2866,2867,2868,2869,
2870,2871,2872,2873,2874,1110,1330,2875,2876,2877,2878,2879,2880,2881,2882,2883,
2884,2885,2886,2887,2888,2889,2890,2891,2892,2893,2894,2895,2896,2897,2898,2899,
2900,2901,2902,2903,2904,2905,2906,2907,2908,2909,2910,2911,2912,2913,2914,2915,
2916,2917,2918,2919,2920,2921,2922,2923,2924,2925,2926,2927,2928,2929,2930,1331,
2931,2932,2933,2934,2935,2936,2937,2938,2939,2940,2941,2942,2943,1552,2944,2945,
2946,2947,2948,2949,2950,2951,2952,2953,2954,2955,2956,2957,2958,2959,2960,2961,
2962,2963,2964,1252,2965,2966,2967,2968,2969,2970,2971,2972,2973,2974,2975,2976,
2977,2978,2979,2980,2981,2982,2983,2984,2985,2986,2987,2988,2989,2990,2991,2992,
2993,2994,2995,2996,2997,2998,2999,3000,3001,3002,3003,3004,3005,3006,3007,3008,
3009,3010,3011,3012,1553,3013,3014,3015,3016,3017,1554,3018,1332,3019,3020,3021,
3022,3023,3024,3025,3026,3027,3028,3029,3030,3031,3032,3033,3034,3035,3036,3037,
3038,3039,3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,3050,1555,3051,3052,
3053,1556,1557,3054,3055,3056,3057,3058,3059,3060,3061,3062,3063,3064,3065,3066,
3067,1558,3068,3069,3070,3071,3072,3073,3074,3075,3076,1559,3077,3078,3079,3080,
3081,3082,3083,1253,3084,3085,3086,3087,3088,3089,3090,3091,3092,3093,3094,3095,
3096,3097,3098,3099,3100,3101,3102,3103,3104,3105,3106,3107,3108,1152,3109,3110,
3111,3112,3113,1560,3114,3115,3116,3117,1111,3118,3119,3120,3121,3122,3123,3124,
3125,3126,3127,3128,3129,3130,3131,3132,3133,3134,3135,3136,3137,3138,3139,3140,
3141,3142,3143,3144,3145,3146,3147,3148,3149,3150,3151,3152,3153,3154,3155,3156,
3157,3158,3159,3160,3161,3162,3163,3164,3165,3166,3167,3168,3169,3170,3171,3172,
3173,3174,3175,3176,1333,3177,3178,3179,3180,3181,3182,3183,3184,3185,3186,3187,
3188,3189,1561,3190,3191,1334,3192,3193,3194,3195,3196,3197,3198,3199,3200,3201,
3202,3203,3204,3205,3206,3207,3208,3209,3210,3211,3212,3213,3214,3215,3216,3217,
3218,3219,3220,3221,3222,3223,3224,3225,3226,3227,3228,3229,3230,3231,3232,3233,
3234,1562,3235,3236,3237,3238,3239,3240,3241,3242,3243,3244,3245,3246,3247,3248,
3249,3250,3251,3252,3253,3254,3255,3256,3257,3258,3259,3260,3261,3262,3263,3264,
3265,3266,3267,3268,3269,3270,3271,3272,3273,3274,3275,3276,3277,1563,3278,3279,
3280,3281,3282,3283,3284,3285,3286,3287,3288,3289,3290,3291,3292,3293,3294,3295,
3296,3297,3298,3299,3300,3301,3302,3303,3304,3305,3306,3307,3308,3309,3310,3311,
3312,3313,3314,3315,3316,3317,3318,3319,3320,3321,3322,3323,3324,3325,3326,3327,
3328,3329,3330,3331,3332,3333,3334,3335,3336,3337,3338,3339,3340,3341,3342,3343,
3344,3345,3346,3347,3348,3349,3350,3351,3352,3353,3354,3355,3356,3357,3358,3359,
3360,3361,3362,3363,3364,1335,3365,3366,3367,3368,3369,3370,3371,3372,3373,3374,
3375,3376,3377,3378,3379,3380,3381,3382,3383,3384,3385,3386,3387,1336,3388,3389,
3390,3391,3392,3393,3394,3395,3396,3397,3398,3399,3400,3401,3402,3403,3404,3405,
3406,3407,3408,3409,3410,3411,3412,3413,3414,1337,3415,3416,3417,3418,3419,1338,
3420,3421,3422,1564,1565,3423,3424,3425,3426,3427,3428,3429,3430,3431,1254,3432,
3433,3434,1339,3435,3436,3437,3438,3439,1566,3440,3441,3442,3443,3444,3445,3446,
3447,3448,3449,3450,3451,3452,3453,3454,1255,3455,3456,3457,3458,3459,1567,1191,
3460,1568,1569,3461,3462,3463,1570,3464,3465,3466,3467,3468,1571,3469,3470,3471,
3472,3473,1572,3474,3475,3476,3477,3478,3479,3480,3481,3482,3483,3484,3485,3486,
1340,3487,3488,3489,3490,3491,3492,1021,3493,3494,3495,3496,3497,3498,1573,3499,
1341,3500,3501,3502,3503,3504,3505,3506,3507,3508,3509,3510,3511,1342,3512,3513,
3514,3515,3516,1574,1343,3517,3518,3519,1575,3520,1576,3521,3522,3523,3524,3525,
3526,3527,3528,3529,3530,3531,3532,3533,3534,3535,3536,3537,3538,3539,3540,3541,
3542,3543,3544,3545,3546,3547,3548,3549,3550,3551,3552,3553,3554,3555,3556,3557,
3558,3559,3560,3561,3562,3563,3564,3565,3566,3567,3568,3569,3570,3571,3572,3573,
3574,3575,3576,3577,3578,3579,3580,1577,3581,3582,1578,3583,3584,3585,3586,3587,
3588,3589,3590,3591,3592,3593,3594,3595,3596,3597,3598,3599,3600,3601,3602,3603,
3604,1579,3605,3606,3607,3608,3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,
3619,3620,3621,3622,3623,3624,3625,3626,3627,3628,3629,1580,3630,3631,1581,3632,
3633,3634,3635,3636,3637,3638,3639,3640,3641,3642,3643,3644,3645,3646,3647,3648,
3649,3650,3651,3652,3653,3654,3655,3656,1582,3657,3658,3659,3660,3661,3662,3663,
3664,3665,3666,3667,3668,3669,3670,3671,3672,3673,3674,3675,3676,3677,3678,3679,
3680,3681,3682,3683,3684,3685,3686,3687,3688,3689,3690,3691,3692,3693,3694,3695,
3696,3697,3698,3699,3700,1192,3701,3702,3703,3704,1256,3705,3706,3707,3708,1583,
1257,3709,3710,3711,3712,3713,3714,3715,3716,1584,3717,3718,3719,3720,3721,3722,
3723,3724,3725,3726,3727,3728,3729,3730,3731,3732,3733,3734,3735,3736,3737,3738,
3739,3740,3741,3742,3743,3744,3745,1344,3746,3747,3748,3749,3750,3751,3752,3753,
3754,3755,3756,1585,3757,3758,3759,3760,3761,3762,3763,3764,3765,3766,1586,3767,
3768,3769,3770,3771,3772,3773,3774,3775,3776,3777,3778,1345,3779,3780,3781,3782,
3783,3784,3785,3786,3787,3788,3789,3790,3791,3792,3793,3794,3795,1346,1587,3796,
3797,1588,3798,3799,3800,3801,3802,3803,3804,3805,3806,1347,3807,3808,3809,3810,
3811,1589,3812,3813,3814,3815,3816,3817,3818,3819,3820,3821,1590,3822,3823,1591,
1348,3824,3825,3826,3827,3828,3829,3830,1592,3831,3832,1593,3833,3834,3835,3836,
3837,3838,3839,3840,3841,3842,3843,3844,1349,3845,3846,3847,3848,3849,3850,3851,
3852,3853,3854,3855,3856,3857,3858,1594,3859,3860,3861,3862,3863,3864,3865,3866,
3867,3868,3869,1595,3870,3871,3872,3873,1596,3874,3875,3876,3877,3878,3879,3880,
3881,3882,3883,3884,3885,3886,1597,3887,3888,3889,3890,3891,3892,3893,3894,3895,
1598,3896,3897,3898,1599,1600,3899,1350,3900,1351,3901,3902,1352,3903,3904,3905,
3906,3907,3908,3909,3910,3911,3912,3913,3914,3915,3916,3917,3918,3919,3920,3921,
3922,3923,3924,1258,3925,3926,3927,3928,3929,3930,3931,1193,3932,1601,3933,3934,
3935,3936,3937,3938,3939,3940,3941,3942,3943,1602,3944,3945,3946,3947,3948,1603,
3949,3950,3951,3952,3953,3954,3955,3956,3957,3958,3959,3960,3961,3962,3963,3964,
3965,1604,3966,3967,3968,3969,3970,3971,3972,3973,3974,3975,3976,3977,1353,3978,
3979,3980,3981,3982,3983,3984,3985,3986,3987,3988,3989,3990,3991,1354,3992,3993,
3994,3995,3996,3997,3998,3999,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,
4010,4011,4012,4013,4014,4015,4016,4017,4018,4019,4020,4021,4022,4023,1355,4024,
4025,4026,4027,4028,4029,4030,4031,4032,4033,4034,4035,4036,4037,4038,4039,4040,
1605,4041,4042,4043,4044,4045,4046,4047,4048,4049,4050,4051,4052,4053,4054,4055,
4056,4057,4058,4059,4060,1606,4061,4062,4063,4064,1607,4065,4066,4067,4068,4069,
4070,4071,4072,4073,4074,4075,4076,1194,4077,4078,1608,4079,4080,4081,4082,4083,
4084,4085,4086,4087,1609,4088,4089,4090,4091,4092,4093,4094,4095,4096,4097,4098,
4099,4100,4101,4102,4103,4104,4105,4106,4107,4108,1259,4109,4110,4111,4112,4113,
4114,4115,4116,4117,4118,4119,4120,4121,4122,4123,4124,1195,4125,4126,4127,1610,
4128,4129,4130,4131,4132,4133,4134,4135,4136,4137,1356,4138,4139,4140,4141,4142,
4143,4144,1611,4145,4146,4147,4148,4149,4150,4151,4152,4153,4154,4155,4156,4157,
4158,4159,4160,4161,4162,4163,4164,4165,4166,4167,4168,4169,4170,4171,4172,4173,
4174,4175,4176,4177,4178,4179,4180,4181,4182,4183,4184,4185,4186,4187,4188,4189,
4190,4191,4192,4193,4194,4195,4196,4197,4198,4199,4200,4201,4202,4203,4204,4205,
4206,4207,4208,4209,4210,4211,4212,4213,4214,4215,4216,4217,4218,4219,1612,4220,
4221,4222,4223,4224,4225,4226,4227,1357,4228,1613,4229,4230,4231,4232,4233,4234,
4235,4236,4237,4238,4239,4240,4241,4242,4243,1614,4244,4245,4246,4247,4248,4249,
4250,4251,4252,4253,4254,4255,4256,4257,4258,4259,4260,4261,4262,4263,4264,4265,
4266,4267,4268,4269,4270,1196,1358,4271,4272,4273,4274,4275,4276,4277,4278,4279,
4280,4281,4282,4283,4284,4285,4286,4287,1615,4288,4289,4290,4291,4292,4293,4294,
4295,4296,4297,4298,4299,4300,4301,4302,4303,4304,4305,4306,4307,4308,4309,4310,
4311,4312,4313,4314,4315,4316,4317,4318,4319,4320,4321,4322,4323,4324,4325,4326,
4327,4328,4329,4330,4331,4332,4333,4334,1616,4335,4336,4337,4338,4339,4340,4341,
4342,4343,4344,4345,4346,4347,4348,4349,4350,4351,4352,4353,4354,4355,4356,4357,
4358,4359,4360,1617,4361,4362,4363,4364,4365,1618,4366,4367,4368,4369,4370,4371,
4372,4373,4374,4375,4376,4377,4378,4379,4380,4381,4382,4383,4384,4385,4386,4387,
4388,4389,4390,4391,4392,4393,4394,4395,4396,4397,4398,4399,4400,4401,4402,4403,
4404,4405,4406,4407,4408,4409,4410,4411,4412,4413,4414,4415,4416,1619,4417,4418,
4419,4420,4421,4422,4423,4424,4425,1112,4426,4427,4428,4429,4430,1620,4431,4432,
4433,4434,4435,4436,4437,4438,4439,4440,4441,4442,1260,1261,4443,4444,4445,4446,
4447,4448,4449,4450,4451,4452,4453,4454,4455,1359,4456,4457,4458,4459,4460,4461,
4462,4463,4464,4465,1621,4466,4467,4468,4469,4470,4471,4472,4473,4474,4475,4476,
4477,4478,4479,4480,4481,4482,4483,4484,4485,4486,4487,4488,4489,1055,4490,4491,
4492,4493,4494,4495,4496,4497,4498,4499,4500,4501,4502,4503,4504,4505,4506,4507,
4508,4509,4510,4511,4512,4513,4514,4515,4516,4517,4518,1622,4519,4520,4521,1623,
4522,4523,4524,4525,4526,4527,4528,4529,4530,4531,4532,4533,4534,4535,1360,4536,
4537,4538,4539,4540,4541,4542,4543, 975,4544,4545,4546,4547,4548,4549,4550,4551,
4552,4553,4554,4555,4556,4557,4558,4559,4560,4561,4562,4563,4564,4565,4566,4567,
4568,4569,4570,4571,1624,4572,4573,4574,4575,4576,1625,4577,4578,4579,4580,4581,
4582,4583,4584,1626,4585,4586,4587,4588,4589,4590,4591,4592,4593,4594,4595,1627,
4596,4597,4598,4599,4600,4601,4602,4603,4604,4605,4606,4607,4608,4609,4610,4611,
4612,4613,4614,4615,1628,4616,4617,4618,4619,4620,4621,4622,4623,4624,4625,4626,
4627,4628,4629,4630,4631,4632,4633,4634,4635,4636,4637,4638,4639,4640,4641,4642,
4643,4644,4645,4646,4647,4648,4649,1361,4650,4651,4652,4653,4654,4655,4656,4657,
4658,4659,4660,4661,1362,4662,4663,4664,4665,4666,4667,4668,4669,4670,4671,4672,
4673,4674,4675,4676,4677,4678,4679,4680,4681,4682,1629,4683,4684,4685,4686,4687,
1630,4688,4689,4690,4691,1153,4692,4693,4694,1113,4695,4696,4697,4698,4699,4700,
4701,4702,4703,4704,4705,4706,4707,4708,4709,4710,4711,1197,4712,4713,4714,4715,
4716,4717,4718,4719,4720,4721,4722,4723,4724,4725,4726,4727,4728,4729,4730,4731,
4732,4733,4734,4735,1631,4736,1632,4737,4738,4739,4740,4741,4742,4743,4744,1633,
4745,4746,4747,4748,4749,1262,4750,4751,4752,4753,4754,1363,4755,4756,4757,4758,
4759,4760,4761,4762,4763,4764,4765,4766,4767,4768,1634,4769,4770,4771,4772,4773,
4774,4775,4776,4777,4778,1635,4779,4780,4781,4782,4783,4784,4785,4786,4787,4788,
4789,1636,4790,4791,4792,4793,4794,4795,4796,4797,4798,4799,4800,4801,4802,4803,
4804,4805,4806,1637,4807,4808,4809,1638,4810,4811,4812,4813,4814,4815,4816,4817,
4818,1639,4819,4820,4821,4822,4823,4824,4825,4826,4827,4828,4829,4830,4831,4832,
4833,1077,4834,4835,4836,4837,4838,4839,4840,4841,4842,4843,4844,4845,4846,4847,
4848,4849,4850,4851,4852,4853,4854,4855,4856,4857,4858,4859,4860,4861,4862,4863,
4864,4865,4866,4867,4868,4869,4870,4871,4872,4873,4874,4875,4876,4877,4878,4879,
4880,4881,4882,4883,1640,4884,4885,1641,4886,4887,4888,4889,4890,4891,4892,4893,
4894,4895,4896,4897,4898,4899,4900,4901,4902,4903,4904,4905,4906,4907,4908,4909,
4910,4911,1642,4912,4913,4914,1364,4915,4916,4917,4918,4919,4920,4921,4922,4923,
4924,4925,4926,4927,4928,4929,4930,4931,1643,4932,4933,4934,4935,4936,4937,4938,
4939,4940,4941,4942,4943,4944,4945,4946,4947,4948,4949,4950,4951,4952,4953,4954,
4955,4956,4957,4958,4959,4960,4961,4962,4963,4964,4965,4966,4967,4968,4969,4970,
4971,4972,4973,4974,4975,4976,4977,4978,4979,4980,1644,4981,4982,4983,4984,1645,
4985,4986,1646,4987,4988,4989,4990,4991,4992,4993,4994,4995,4996,4997,4998,4999,
5000,5001,5002,5003,5004,5005,1647,5006,1648,5007,5008,5009,5010,5011,5012,1078,
5013,5014,5015,5016,5017,5018,5019,5020,5021,5022,5023,5024,5025,5026,5027,5028,
1365,5029,5030,5031,5032,5033,5034,5035,5036,5037,5038,5039,1649,5040,5041,5042,
5043,5044,5045,1366,5046,5047,5048,5049,5050,5051,5052,5053,5054,5055,1650,5056,
5057,5058,5059,5060,5061,5062,5063,5064,5065,5066,5067,5068,5069,5070,5071,5072,
5073,5074,5075,5076,5077,1651,5078,5079,5080,5081,5082,5083,5084,5085,5086,5087,
5088,5089,5090,5091,5092,5093,5094,5095,5096,5097,5098,5099,5100,5101,5102,5103,
5104,5105,5106,5107,5108,5109,5110,1652,5111,5112,5113,5114,5115,5116,5117,5118,
1367,5119,5120,5121,5122,5123,5124,5125,5126,5127,5128,5129,1653,5130,5131,5132,
5133,5134,5135,5136,5137,5138,5139,5140,5141,5142,5143,5144,5145,5146,5147,5148,
5149,1368,5150,1654,5151,1369,5152,5153,5154,5155,5156,5157,5158,5159,5160,5161,
5162,5163,5164,5165,5166,5167,5168,5169,5170,5171,5172,5173,5174,5175,5176,5177,
5178,1370,5179,5180,5181,5182,5183,5184,5185,5186,5187,5188,5189,5190,5191,5192,
5193,5194,5195,5196,5197,5198,1655,5199,5200,5201,5202,1656,5203,5204,5205,5206,
1371,5207,1372,5208,5209,5210,5211,1373,5212,5213,1374,5214,5215,5216,5217,5218,
5219,5220,5221,5222,5223,5224,5225,5226,5227,5228,5229,5230,5231,5232,5233,5234,
5235,5236,5237,5238,5239,5240,5241,5242,5243,5244,5245,5246,5247,1657,5248,5249,
5250,5251,1658,1263,5252,5253,5254,5255,5256,1375,5257,5258,5259,5260,5261,5262,
5263,5264,5265,5266,5267,5268,5269,5270,5271,5272,5273,5274,5275,5276,5277,5278,
5279,5280,5281,5282,5283,1659,5284,5285,5286,5287,5288,5289,5290,5291,5292,5293,
5294,5295,5296,5297,5298,5299,5300,1660,5301,5302,5303,5304,5305,5306,5307,5308,
5309,5310,5311,5312,5313,5314,5315,5316,5317,5318,5319,5320,5321,1376,5322,5323,
5324,5325,5326,5327,5328,5329,5330,5331,5332,5333,1198,5334,5335,5336,5337,5338,
5339,5340,5341,5342,5343,1661,5344,5345,5346,5347,5348,5349,5350,5351,5352,5353,
5354,5355,5356,5357,5358,5359,5360,5361,5362,5363,5364,5365,5366,5367,5368,5369,
5370,5371,5372,5373,5374,5375,5376,5377,5378,5379,5380,5381,5382,5383,5384,5385,
5386,5387,5388,5389,5390,5391,5392,5393,5394,5395,5396,5397,5398,1264,5399,5400,
5401,5402,5403,5404,5405,5406,5407,5408,5409,5410,5411,5412,1662,5413,5414,5415,
5416,1663,5417,5418,5419,5420,5421,5422,5423,5424,5425,5426,5427,5428,5429,5430,
5431,5432,5433,5434,5435,5436,5437,5438,1664,5439,5440,5441,5442,5443,5444,5445,
5446,5447,5448,5449,5450,5451,5452,5453,5454,5455,5456,5457,5458,5459,5460,5461,
5462,5463,5464,5465,5466,5467,5468,5469,5470,5471,5472,5473,5474,5475,5476,5477,
5478,1154,5479,5480,5481,5482,5483,5484,5485,1665,5486,5487,5488,5489,5490,5491,
5492,5493,5494,5495,5496,5497,5498,5499,5500,5501,5502,5503,5504,5505,5506,5507,
5508,5509,5510,5511,5512,5513,5514,5515,5516,5517,5518,5519,5520,5521,5522,5523,
5524,5525,5526,5527,5528,5529,5530,5531,5532,5533,5534,5535,5536,5537,5538,5539,
5540,5541,5542,5543,5544,5545,5546,5547,5548,1377,5549,5550,5551,5552,5553,5554,
5555,5556,5557,5558,5559,5560,5561,5562,5563,5564,5565,5566,5567,5568,5569,5570,
1114,5571,5572,5573,5574,5575,5576,5577,5578,5579,5580,5581,5582,5583,5584,5585,
5586,5587,5588,5589,5590,5591,5592,1378,5593,5594,5595,5596,5597,5598,5599,5600,
5601,5602,5603,5604,5605,5606,5607,5608,5609,5610,5611,5612,5613,5614,1379,5615,
5616,5617,5618,5619,5620,5621,5622,5623,5624,5625,5626,5627,5628,5629,5630,5631,
5632,5633,5634,1380,5635,5636,5637,5638,5639,5640,5641,5642,5643,5644,5645,5646,
5647,5648,5649,1381,1056,5650,5651,5652,5653,5654,5655,5656,5657,5658,5659,5660,
1666,5661,5662,5663,5664,5665,5666,5667,5668,1667,5669,1668,5670,5671,5672,5673,
5674,5675,5676,5677,5678,1155,5679,5680,5681,5682,5683,5684,5685,5686,5687,5688,
5689,5690,5691,5692,5693,5694,5695,5696,5697,5698,1669,5699,5700,5701,5702,5703,
5704,5705,1670,5706,5707,5708,5709,5710,1671,5711,5712,5713,5714,1382,5715,5716,
5717,5718,5719,5720,5721,5722,5723,5724,5725,1672,5726,5727,1673,1674,5728,5729,
5730,5731,5732,5733,5734,5735,5736,1675,5737,5738,5739,5740,5741,5742,5743,5744,
1676,5745,5746,5747,5748,5749,5750,5751,1383,5752,5753,5754,5755,5756,5757,5758,
5759,5760,5761,5762,5763,5764,5765,5766,5767,5768,1677,5769,5770,5771,5772,5773,
1678,5774,5775,5776, 998,5777,5778,5779,5780,5781,5782,5783,5784,5785,1384,5786,
5787,5788,5789,5790,5791,5792,5793,5794,5795,5796,5797,5798,5799,5800,1679,5801,
5802,5803,1115,1116,5804,5805,5806,5807,5808,5809,5810,5811,5812,5813,5814,5815,
5816,5817,5818,5819,5820,5821,5822,5823,5824,5825,5826,5827,5828,5829,5830,5831,
5832,5833,5834,5835,5836,5837,5838,5839,5840,5841,5842,5843,5844,5845,5846,5847,
5848,5849,5850,5851,5852,5853,5854,5855,1680,5856,5857,5858,5859,5860,5861,5862,
5863,5864,1681,5865,5866,5867,1682,5868,5869,5870,5871,5872,5873,5874,5875,5876,
5877,5878,5879,1683,5880,1684,5881,5882,5883,5884,1685,5885,5886,5887,5888,5889,
5890,5891,5892,5893,5894,5895,5896,5897,5898,5899,5900,5901,5902,5903,5904,5905,
5906,5907,1686,5908,5909,5910,5911,5912,5913,5914,5915,5916,5917,5918,5919,5920,
5921,5922,5923,5924,5925,5926,5927,5928,5929,5930,5931,5932,5933,5934,5935,1687,
5936,5937,5938,5939,5940,5941,5942,5943,5944,5945,5946,5947,5948,5949,5950,5951,
5952,1688,1689,5953,1199,5954,5955,5956,5957,5958,5959,5960,5961,1690,5962,5963,
5964,5965,5966,5967,5968,5969,5970,5971,5972,5973,5974,5975,5976,5977,5978,5979,
5980,5981,1385,5982,1386,5983,5984,5985,5986,5987,5988,5989,5990,5991,5992,5993,
5994,5995,5996,5997,5998,5999,6000,6001,6002,6003,6004,6005,6006,6007,6008,6009,
6010,6011,6012,6013,6014,6015,6016,6017,6018,6019,6020,6021,6022,6023,6024,6025,
6026,6027,1265,6028,6029,1691,6030,6031,6032,6033,6034,6035,6036,6037,6038,6039,
6040,6041,6042,6043,6044,6045,6046,6047,6048,6049,6050,6051,6052,6053,6054,6055,
6056,6057,6058,6059,6060,6061,6062,6063,6064,6065,6066,6067,6068,6069,6070,6071,
6072,6073,6074,6075,6076,6077,6078,6079,6080,6081,6082,6083,6084,1692,6085,6086,
6087,6088,6089,6090,6091,6092,6093,6094,6095,6096,6097,6098,6099,6100,6101,6102,
6103,6104,6105,6106,6107,6108,6109,6110,6111,6112,6113,6114,6115,6116,6117,6118,
6119,6120,6121,6122,6123,6124,6125,6126,6127,6128,6129,6130,6131,1693,6132,6133,
6134,6135,6136,1694,6137,6138,6139,6140,6141,1695,6142,6143,6144,6145,6146,6147,
6148,6149,6150,6151,6152,6153,6154,6155,6156,6157,6158,6159,6160,6161,6162,6163,
6164,6165,6166,6167,6168,6169,6170,6171,6172,6173,6174,6175,6176,6177,6178,6179,
6180,6181,6182,6183,6184,6185,1696,6186,6187,6188,6189,6190,6191,6192,6193,6194,
6195,6196,6197,6198,6199,6200,6201,6202,6203,6204,6205,6206,6207,6208,6209,6210,
6211,6212,6213,6214,6215,6216,6217,6218,6219,1697,6220,6221,6222,6223,6224,6225,
6226,6227,6228,6229,6230,6231,6232,6233,6234,6235,6236,6237,6238,6239,6240,6241,
6242,6243,6244,6245,6246,6247,6248,6249,6250,6251,6252,6253,1698,6254,6255,6256,
6257,6258,6259,6260,6261,6262,6263,1200,6264,6265,6266,6267,6268,6269,6270,6271, #1024
6272,6273,6274,6275,6276,6277,6278,6279,6280,6281,6282,6283,6284,6285,6286,6287,
6288,6289,6290,6291,6292,6293,6294,6295,6296,6297,6298,6299,6300,6301,6302,1699,
6303,6304,1700,6305,6306,6307,6308,6309,6310,6311,6312,6313,6314,6315,6316,6317,
6318,6319,6320,6321,6322,6323,6324,6325,6326,6327,6328,6329,6330,6331,6332,6333,
6334,6335,6336,6337,6338,6339,1701,6340,6341,6342,6343,6344,1387,6345,6346,6347,
6348,6349,6350,6351,6352,6353,6354,6355,6356,6357,6358,6359,6360,6361,6362,6363,
6364,6365,6366,6367,6368,6369,6370,6371,6372,6373,6374,6375,6376,6377,6378,6379,
6380,6381,6382,6383,6384,6385,6386,6387,6388,6389,6390,6391,6392,6393,6394,6395,
6396,6397,6398,6399,6400,6401,6402,6403,6404,6405,6406,6407,6408,6409,6410,6411,
6412,6413,1702,6414,6415,6416,6417,6418,6419,6420,6421,6422,1703,6423,6424,6425,
6426,6427,6428,6429,6430,6431,6432,6433,6434,6435,6436,6437,6438,1704,6439,6440,
6441,6442,6443,6444,6445,6446,6447,6448,6449,6450,6451,6452,6453,6454,6455,6456,
6457,6458,6459,6460,6461,6462,6463,6464,6465,6466,6467,6468,6469,6470,6471,6472,
6473,6474,6475,6476,6477,6478,6479,6480,6481,6482,6483,6484,6485,6486,6487,6488,
6489,6490,6491,6492,6493,6494,6495,6496,6497,6498,6499,6500,6501,6502,6503,1266,
6504,6505,6506,6507,6508,6509,6510,6511,6512,6513,6514,6515,6516,6517,6518,6519,
6520,6521,6522,6523,6524,6525,6526,6527,6528,6529,6530,6531,6532,6533,6534,6535,
6536,6537,6538,6539,6540,6541,6542,6543,6544,6545,6546,6547,6548,6549,6550,6551,
1705,1706,6552,6553,6554,6555,6556,6557,6558,6559,6560,6561,6562,6563,6564,6565,
6566,6567,6568,6569,6570,6571,6572,6573,6574,6575,6576,6577,6578,6579,6580,6581,
6582,6583,6584,6585,6586,6587,6588,6589,6590,6591,6592,6593,6594,6595,6596,6597,
6598,6599,6600,6601,6602,6603,6604,6605,6606,6607,6608,6609,6610,6611,6612,6613,
6614,6615,6616,6617,6618,6619,6620,6621,6622,6623,6624,6625,6626,6627,6628,6629,
6630,6631,6632,6633,6634,6635,6636,6637,1388,6638,6639,6640,6641,6642,6643,6644,
1707,6645,6646,6647,6648,6649,6650,6651,6652,6653,6654,6655,6656,6657,6658,6659,
6660,6661,6662,6663,1708,6664,6665,6666,6667,6668,6669,6670,6671,6672,6673,6674,
1201,6675,6676,6677,6678,6679,6680,6681,6682,6683,6684,6685,6686,6687,6688,6689,
6690,6691,6692,6693,6694,6695,6696,6697,6698,6699,6700,6701,6702,6703,6704,6705,
6706,6707,6708,6709,6710,6711,6712,6713,6714,6715,6716,6717,6718,6719,6720,6721,
6722,6723,6724,6725,1389,6726,6727,6728,6729,6730,6731,6732,6733,6734,6735,6736,
1390,1709,6737,6738,6739,6740,6741,6742,1710,6743,6744,6745,6746,1391,6747,6748,
6749,6750,6751,6752,6753,6754,6755,6756,6757,1392,6758,6759,6760,6761,6762,6763,
6764,6765,6766,6767,6768,6769,6770,6771,6772,6773,6774,6775,6776,6777,6778,6779,
6780,1202,6781,6782,6783,6784,6785,6786,6787,6788,6789,6790,6791,6792,6793,6794,
6795,6796,6797,6798,6799,6800,6801,6802,6803,6804,6805,6806,6807,6808,6809,1711,
6810,6811,6812,6813,6814,6815,6816,6817,6818,6819,6820,6821,6822,6823,6824,6825,
6826,6827,6828,6829,6830,6831,6832,6833,6834,6835,6836,1393,6837,6838,6839,6840,
6841,6842,6843,6844,6845,6846,6847,6848,6849,6850,6851,6852,6853,6854,6855,6856,
6857,6858,6859,6860,6861,6862,6863,6864,6865,6866,6867,6868,6869,6870,6871,6872,
6873,6874,6875,6876,6877,6878,6879,6880,6881,6882,6883,6884,6885,6886,6887,6888,
6889,6890,6891,6892,6893,6894,6895,6896,6897,6898,6899,6900,6901,6902,1712,6903,
6904,6905,6906,6907,6908,6909,6910,1713,6911,6912,6913,6914,6915,6916,6917,6918,
6919,6920,6921,6922,6923,6924,6925,6926,6927,6928,6929,6930,6931,6932,6933,6934,
6935,6936,6937,6938,6939,6940,6941,6942,6943,6944,6945,6946,6947,6948,6949,6950,
6951,6952,6953,6954,6955,6956,6957,6958,6959,6960,6961,6962,6963,6964,6965,6966,
6967,6968,6969,6970,6971,6972,6973,6974,1714,6975,6976,6977,6978,6979,6980,6981,
6982,6983,6984,6985,6986,6987,6988,1394,6989,6990,6991,6992,6993,6994,6995,6996,
6997,6998,6999,7000,1715,7001,7002,7003,7004,7005,7006,7007,7008,7009,7010,7011,
7012,7013,7014,7015,7016,7017,7018,7019,7020,7021,7022,7023,7024,7025,7026,7027,
7028,1716,7029,7030,7031,7032,7033,7034,7035,7036,7037,7038,7039,7040,7041,7042,
7043,7044,7045,7046,7047,7048,7049,7050,7051,7052,7053,7054,7055,7056,7057,7058,
7059,7060,7061,7062,7063,7064,7065,7066,7067,7068,7069,7070,7071,7072,7073,7074,
7075,7076,7077,7078,7079,7080,7081,7082,7083,7084,7085,7086,7087,7088,7089,7090,
7091,7092,7093,7094,7095,7096,7097,7098,7099,7100,7101,7102,7103,7104,7105,7106,
7107,7108,7109,7110,7111,7112,7113,7114,7115,7116,7117,7118,7119,7120,7121,7122,
7123,7124,7125,7126,7127,7128,7129,7130,7131,7132,7133,7134,7135,7136,7137,7138,
7139,7140,7141,7142,7143,7144,7145,7146,7147,7148,7149,7150,7151,7152,7153,7154,
7155,7156,7157,7158,7159,7160,7161,7162,7163,7164,7165,7166,7167,7168,7169,7170,
7171,7172,7173,7174,7175,7176,7177,7178,7179,7180,7181,7182,7183,7184,7185,7186,
7187,7188,7189,7190,7191,7192,7193,7194,7195,7196,7197,7198,7199,7200,7201,7202,
7203,7204,7205,7206,7207,1395,7208,7209,7210,7211,7212,7213,1717,7214,7215,7216,
7217,7218,7219,7220,7221,7222,7223,7224,7225,7226,7227,7228,7229,7230,7231,7232,
7233,7234,7235,7236,7237,7238,7239,7240,7241,7242,7243,7244,7245,7246,7247,7248,
7249,7250,7251,7252,7253,7254,7255,7256,7257,7258,7259,7260,7261,7262,7263,7264,
7265,7266,7267,7268,7269,7270,7271,7272,7273,7274,7275,7276,7277,7278,7279,7280,
7281,7282,7283,7284,7285,7286,7287,7288,7289,7290,7291,7292,7293,7294,7295,7296,
7297,7298,7299,7300,7301,7302,7303,7304,7305,7306,7307,7308,7309,7310,7311,7312,
7313,1718,7314,7315,7316,7317,7318,7319,7320,7321,7322,7323,7324,7325,7326,7327,
7328,7329,7330,7331,7332,7333,7334,7335,7336,7337,7338,7339,7340,7341,7342,7343,
7344,7345,7346,7347,7348,7349,7350,7351,7352,7353,7354,7355,7356,7357,7358,7359,
7360,7361,7362,7363,7364,7365,7366,7367,7368,7369,7370,7371,7372,7373,7374,7375,
7376,7377,7378,7379,7380,7381,7382,7383,7384,7385,7386,7387,7388,7389,7390,7391,
7392,7393,7394,7395,7396,7397,7398,7399,7400,7401,7402,7403,7404,7405,7406,7407,
7408,7409,7410,7411,7412,7413,7414,7415,7416,7417,7418,7419,7420,7421,7422,7423,
7424,7425,7426,7427,7428,7429,7430,7431,7432,7433,7434,7435,7436,7437,7438,7439,
7440,7441,7442,7443,7444,7445,7446,7447,7448,7449,7450,7451,7452,7453,7454,7455,
7456,7457,7458,7459,7460,7461,7462,7463,7464,7465,7466,7467,7468,7469,7470,7471,
7472,7473,7474,7475,7476,7477,7478,7479,7480,7481,7482,7483,7484,7485,7486,7487,
7488,7489,7490,7491,7492,7493,7494,7495,7496,7497,7498,7499,7500,7501,7502,7503,
7504,7505,7506,7507,7508,7509,7510,7511,7512,7513,7514,7515,7516,7517,7518,7519,
7520,7521,7522,7523,7524,7525,7526,7527,7528,7529,7530,7531,7532,7533,7534,7535,
7536,7537,7538,7539,7540,7541,7542,7543,7544,7545,7546,7547,7548,7549,7550,7551,
7552,7553,7554,7555,7556,7557,7558,7559,7560,7561,7562,7563,7564,7565,7566,7567,
7568,7569,7570,7571,7572,7573,7574,7575,7576,7577,7578,7579,7580,7581,7582,7583,
7584,7585,7586,7587,7588,7589,7590,7591,7592,7593,7594,7595,7596,7597,7598,7599,
7600,7601,7602,7603,7604,7605,7606,7607,7608,7609,7610,7611,7612,7613,7614,7615,
7616,7617,7618,7619,7620,7621,7622,7623,7624,7625,7626,7627,7628,7629,7630,7631,
7632,7633,7634,7635,7636,7637,7638,7639,7640,7641,7642,7643,7644,7645,7646,7647,
7648,7649,7650,7651,7652,7653,7654,7655,7656,7657,7658,7659,7660,7661,7662,7663,
7664,7665,7666,7667,7668,7669,7670,7671,7672,7673,7674,7675,7676,7677,7678,7679,
7680,7681,7682,7683,7684,7685,7686,7687,7688,7689,7690,7691,7692,7693,7694,7695,
7696,7697,7698,7699,7700,7701,7702,7703,7704,7705,7706,7707,7708,7709,7710,7711,
7712,7713,7714,7715,7716,7717,7718,7719,7720,7721,7722,7723,7724,7725,7726,7727,
7728,7729,7730,7731,7732,7733,7734,7735,7736,7737,7738,7739,7740,7741,7742,7743,
7744,7745,7746,7747,7748,7749,7750,7751,7752,7753,7754,7755,7756,7757,7758,7759,
7760,7761,7762,7763,7764,7765,7766,7767,7768,7769,7770,7771,7772,7773,7774,7775,
7776,7777,7778,7779,7780,7781,7782,7783,7784,7785,7786,7787,7788,7789,7790,7791,
7792,7793,7794,7795,7796,7797,7798,7799,7800,7801,7802,7803,7804,7805,7806,7807,
7808,7809,7810,7811,7812,7813,7814,7815,7816,7817,7818,7819,7820,7821,7822,7823,
7824,7825,7826,7827,7828,7829,7830,7831,7832,7833,7834,7835,7836,7837,7838,7839,
7840,7841,7842,7843,7844,7845,7846,7847,7848,7849,7850,7851,7852,7853,7854,7855,
7856,7857,7858,7859,7860,7861,7862,7863,7864,7865,7866,7867,7868,7869,7870,7871,
7872,7873,7874,7875,7876,7877,7878,7879,7880,7881,7882,7883,7884,7885,7886,7887,
7888,7889,7890,7891,7892,7893,7894,7895,7896,7897,7898,7899,7900,7901,7902,7903,
7904,7905,7906,7907,7908,7909,7910,7911,7912,7913,7914,7915,7916,7917,7918,7919,
7920,7921,7922,7923,7924,7925,7926,7927,7928,7929,7930,7931,7932,7933,7934,7935,
7936,7937,7938,7939,7940,7941,7942,7943,7944,7945,7946,7947,7948,7949,7950,7951,
7952,7953,7954,7955,7956,7957,7958,7959,7960,7961,7962,7963,7964,7965,7966,7967,
7968,7969,7970,7971,7972,7973,7974,7975,7976,7977,7978,7979,7980,7981,7982,7983,
7984,7985,7986,7987,7988,7989,7990,7991,7992,7993,7994,7995,7996,7997,7998,7999,
8000,8001,8002,8003,8004,8005,8006,8007,8008,8009,8010,8011,8012,8013,8014,8015,
8016,8017,8018,8019,8020,8021,8022,8023,8024,8025,8026,8027,8028,8029,8030,8031,
8032,8033,8034,8035,8036,8037,8038,8039,8040,8041,8042,8043,8044,8045,8046,8047,
8048,8049,8050,8051,8052,8053,8054,8055,8056,8057,8058,8059,8060,8061,8062,8063,
8064,8065,8066,8067,8068,8069,8070,8071,8072,8073,8074,8075,8076,8077,8078,8079,
8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,
8096,8097,8098,8099,8100,8101,8102,8103,8104,8105,8106,8107,8108,8109,8110,8111,
8112,8113,8114,8115,8116,8117,8118,8119,8120,8121,8122,8123,8124,8125,8126,8127,
8128,8129,8130,8131,8132,8133,8134,8135,8136,8137,8138,8139,8140,8141,8142,8143,
8144,8145,8146,8147,8148,8149,8150,8151,8152,8153,8154,8155,8156,8157,8158,8159,
8160,8161,8162,8163,8164,8165,8166,8167,8168,8169,8170,8171,8172,8173,8174,8175,
8176,8177,8178,8179,8180,8181,8182,8183,8184,8185,8186,8187,8188,8189,8190,8191,
8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8203,8204,8205,8206,8207,
8208,8209,8210,8211,8212,8213,8214,8215,8216,8217,8218,8219,8220,8221,8222,8223,
8224,8225,8226,8227,8228,8229,8230,8231,8232,8233,8234,8235,8236,8237,8238,8239,
8240,8241,8242,8243,8244,8245,8246,8247,8248,8249,8250,8251,8252,8253,8254,8255,
8256,8257,8258,8259,8260,8261,8262,8263,8264,8265,8266,8267,8268,8269,8270,8271,
8272,8273,8274,8275,8276,8277,8278,8279,8280,8281,8282,8283,8284,8285,8286,8287,
8288,8289,8290,8291,8292,8293,8294,8295,8296,8297,8298,8299,8300,8301,8302,8303,
8304,8305,8306,8307,8308,8309,8310,8311,8312,8313,8314,8315,8316,8317,8318,8319,
8320,8321,8322,8323,8324,8325,8326,8327,8328,8329,8330,8331,8332,8333,8334,8335,
8336,8337,8338,8339,8340,8341,8342,8343,8344,8345,8346,8347,8348,8349,8350,8351,
8352,8353,8354,8355,8356,8357,8358,8359,8360,8361,8362,8363,8364,8365,8366,8367,
8368,8369,8370,8371,8372,8373,8374,8375,8376,8377,8378,8379,8380,8381,8382,8383,
8384,8385,8386,8387,8388,8389,8390,8391,8392,8393,8394,8395,8396,8397,8398,8399,
8400,8401,8402,8403,8404,8405,8406,8407,8408,8409,8410,8411,8412,8413,8414,8415,
8416,8417,8418,8419,8420,8421,8422,8423,8424,8425,8426,8427,8428,8429,8430,8431,
8432,8433,8434,8435,8436,8437,8438,8439,8440,8441,8442,8443,8444,8445,8446,8447,
8448,8449,8450,8451,8452,8453,8454,8455,8456,8457,8458,8459,8460,8461,8462,8463,
8464,8465,8466,8467,8468,8469,8470,8471,8472,8473,8474,8475,8476,8477,8478,8479,
8480,8481,8482,8483,8484,8485,8486,8487,8488,8489,8490,8491,8492,8493,8494,8495,
8496,8497,8498,8499,8500,8501,8502,8503,8504,8505,8506,8507,8508,8509,8510,8511,
8512,8513,8514,8515,8516,8517,8518,8519,8520,8521,8522,8523,8524,8525,8526,8527,
8528,8529,8530,8531,8532,8533,8534,8535,8536,8537,8538,8539,8540,8541,8542,8543,
8544,8545,8546,8547,8548,8549,8550,8551,8552,8553,8554,8555,8556,8557,8558,8559,
8560,8561,8562,8563,8564,8565,8566,8567,8568,8569,8570,8571,8572,8573,8574,8575,
8576,8577,8578,8579,8580,8581,8582,8583,8584,8585,8586,8587,8588,8589,8590,8591,
8592,8593,8594,8595,8596,8597,8598,8599,8600,8601,8602,8603,8604,8605,8606,8607,
8608,8609,8610,8611,8612,8613,8614,8615,8616,8617,8618,8619,8620,8621,8622,8623,
8624,8625,8626,8627,8628,8629,8630,8631,8632,8633,8634,8635,8636,8637,8638,8639,
8640,8641,8642,8643,8644,8645,8646,8647,8648,8649,8650,8651,8652,8653,8654,8655,
8656,8657,8658,8659,8660,8661,8662,8663,8664,8665,8666,8667,8668,8669,8670,8671,
8672,8673,8674,8675,8676,8677,8678,8679,8680,8681,8682,8683,8684,8685,8686,8687,
8688,8689,8690,8691,8692,8693,8694,8695,8696,8697,8698,8699,8700,8701,8702,8703,
8704,8705,8706,8707,8708,8709,8710,8711,8712,8713,8714,8715,8716,8717,8718,8719,
8720,8721,8722,8723,8724,8725,8726,8727,8728,8729,8730,8731,8732,8733,8734,8735,
8736,8737,8738,8739,8740,8741)
# flake8: noqa
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
428,
23144,
687,
3595,
3388,
45,
1318,
8418,
2387,
7142,
1463,
436,
24189,
1565,
24731,
199,
199,
3,
7960,
221,
10541,
378,
14,
1965,
199,
3,
7633,
221,
10541,
378,
14,
2942,
199,
3,
10574,
221,
10541,
378,
14,
30292,
199,
3,
6619,
10541,
378,
14,
5637,
1602,
199,
3,
18427,
10541,
378,
14,
27055,
199,
3,
199,
3,
473,
25395,
11839,
820,
32736,
275,
378,
14,
30292,
2481,
1182,
334,
17,
13,
16,
14,
30292,
2481,
9,
275,
18525,
14,
1194,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
8276,
16,
13,
7736,
9,
275,
378,
14,
12987,
14,
199,
3,
221,
199,
3,
29267,
11839,
820,
32736,
257,
199,
199,
23539,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
1227,
14,
16,
199,
199,
23539,
27373,
63,
8723,
63,
4305,
275,
499,
15139,
199,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
221,
199,
23539,
27373,
18139,
13875,
4738,
275,
334,
971,
523,
4944,
12,
21334,
12,
13960,
12,
969,
2534,
12,
841,
2835,
12,
1196,
1167,
12,
1196,
1165,
12,
650,
1651,
12,
1227,
1643,
12,
29532,
12,
1196,
2025,
12,
1520,
1780,
12,
8290,
12,
32730,
12,
1196,
1081,
12,
221,
10513,
12,
199,
969,
2576,
12,
1196,
1789,
12,
21083,
12,
959,
1344,
12,
845,
1196,
12,
713,
1644,
12,
1196,
1194,
12,
713,
1822,
12,
1227,
2426,
12,
713,
2333,
12,
959,
2036,
12,
1196,
821,
12,
1196,
1479,
12,
1196,
1465,
12,
1196,
1651,
12,
969,
2905,
12,
199,
969,
1020,
12,
1196,
1398,
12,
1196,
1216,
12,
1196,
2192,
12,
413,
2953,
12,
1227,
2025,
12,
650,
1479,
12,
709,
1641,
12,
650,
2333,
12,
1196,
708,
12,
499,
1822,
12,
841,
1299,
12,
221,
3388,
12,
1196,
1153,
12,
713,
1876,
12,
1196,
1082,
12,
199,
1749,
2322,
12,
1079,
383,
12,
1196,
1276,
12,
221,
10954,
12,
1749,
966,
12,
713,
2760,
12,
1196,
1344,
12,
1196,
1401,
12,
8375,
19,
12,
499,
2006,
12,
1196,
1703,
12,
21292,
12,
650,
969,
12,
1520,
1184,
12,
17640,
12,
1196,
1355,
12,
199,
25186,
12,
1749,
1555,
12,
1695,
969,
12,
1079,
614,
12,
1227,
2658,
12,
221,
13098,
12,
713,
966,
12,
28818,
12,
1196,
2167,
12,
1196,
2953,
12,
1196,
2260,
12,
1196,
2824,
12,
221,
3193,
12,
8264,
23,
12,
1227,
1822,
12,
1227,
1081,
12,
199,
1520,
2036,
12,
1196,
1602,
12,
1196,
2322,
12,
1196,
2466,
12,
1749,
1272,
12,
1520,
1555,
12,
20398,
12,
25454,
12,
1196,
2417,
12,
221,
5212,
12,
1695,
1165,
12,
11869,
12,
1227,
2114,
12,
1196,
2006,
12,
1196,
1887,
12,
1196,
1400,
12,
199,
1196,
2869,
12,
1227,
1196,
12,
1196,
2528,
12,
1227,
1479,
12,
1196,
2481,
12,
1196,
1477,
12,
1196,
1229,
12,
1196,
1367,
12,
1227,
2481,
12,
1196,
1641,
12,
1196,
2010,
12,
1196,
1427,
12,
1196,
2259,
12,
1196,
2976,
12,
1196,
2789,
12,
1695,
1367,
12,
199,
650,
1602,
12,
1196,
2766,
12,
1196,
772,
12,
1196,
2182,
12,
1196,
1272,
12,
221,
17838,
12,
13952,
12,
841,
1085,
12,
5939,
22,
12,
1749,
1717,
12,
8264,
24,
12,
1196,
1822,
12,
1196,
2333,
12,
1196,
1876,
12,
1749,
2466,
12,
713,
1717,
12,
199,
1520,
1643,
12,
8881,
16,
12,
845,
1085,
12,
8881,
17,
12,
499,
2953,
12,
8881,
18,
12,
8881,
19,
12,
8881,
20,
12,
713,
3172,
12,
8881,
21,
12,
959,
1876,
12,
8881,
22,
12,
22291,
12,
8881,
23,
12,
8881,
24,
12,
8881,
25,
12,
199,
1196,
1257,
12,
650,
1401,
12,
1520,
2869,
12,
709,
2010,
12,
221,
7294,
12,
1227,
1651,
12,
22540,
12,
1196,
2835,
12,
413,
1138,
12,
1749,
1690,
12,
27632,
12,
650,
1887,
12,
221,
15601,
12,
709,
1965,
12,
1196,
2564,
12,
221,
5851,
12,
199,
1196,
2658,
12,
650,
1965,
12,
1196,
1349,
12,
650,
1046,
12,
1196,
2426,
12,
1227,
1398,
12,
1520,
1477,
12,
29840,
12,
959,
1427,
12,
1196,
1184,
12,
1227,
1344,
12,
29202,
12,
713,
1690,
12,
1196,
1555,
12,
1520,
709,
12,
959,
1822,
12,
199,
1196,
1299,
12,
1749,
1276,
12,
1695,
1079,
12,
1196,
1407,
12,
1196,
2710,
12,
713,
1780,
12,
1520,
1272,
12,
959,
1651,
12,
1196,
3328,
12,
1196,
2942,
12,
713,
2036,
12,
1196,
3129,
12,
1196,
2635,
12,
1196,
2720,
12,
1196,
2534,
12,
1196,
2576,
12,
199,
1079,
1644,
12,
1196,
2905,
12,
1196,
1020,
12,
959,
1153,
12,
709,
1427,
12,
1079,
966,
12,
1079,
1717,
12,
845,
1367,
12,
1079,
1690,
12,
1749,
1344,
12,
10523,
20,
12,
23514,
12,
1085,
383,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
428,
23144,
687,
3595,
3388,
45,
1318,
8418,
2387,
7142,
1463,
436,
24189,
1565,
24731,
199,
199,
3,
7960,
221,
10541,
378,
14,
1965,
199,
3,
7633,
221,
10541,
378,
14,
2942,
199,
3,
10574,
221,
10541,
378,
14,
30292,
199,
3,
6619,
10541,
378,
14,
5637,
1602,
199,
3,
18427,
10541,
378,
14,
27055,
199,
3,
199,
3,
473,
25395,
11839,
820,
32736,
275,
378,
14,
30292,
2481,
1182,
334,
17,
13,
16,
14,
30292,
2481,
9,
275,
18525,
14,
1194,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
8276,
16,
13,
7736,
9,
275,
378,
14,
12987,
14,
199,
3,
221,
199,
3,
29267,
11839,
820,
32736,
257,
199,
199,
23539,
27373,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
1227,
14,
16,
199,
199,
23539,
27373,
63,
8723,
63,
4305,
275,
499,
15139,
199,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
221,
199,
23539,
27373,
18139,
13875,
4738,
275,
334,
971,
523,
4944,
12,
21334,
12,
13960,
12,
969,
2534,
12,
841,
2835,
12,
1196,
1167,
12,
1196,
1165,
12,
650,
1651,
12,
1227,
1643,
12,
29532,
12,
1196,
2025,
12,
1520,
1780,
12,
8290,
12,
32730,
12,
1196,
1081,
12,
221,
10513,
12,
199,
969,
2576,
12,
1196,
1789,
12,
21083,
12,
959,
1344,
12,
845,
1196,
12,
713,
1644,
12,
1196,
1194,
12,
713,
1822,
12,
1227,
2426,
12,
713,
2333,
12,
959,
2036,
12,
1196,
821,
12,
1196,
1479,
12,
1196,
1465,
12,
1196,
1651,
12,
969,
2905,
12,
199,
969,
1020,
12,
1196,
1398,
12,
1196,
1216,
12,
1196,
2192,
12,
413,
2953,
12,
1227,
2025,
12,
650,
1479,
12,
709,
1641,
12,
650,
2333,
12,
1196,
708,
12,
499,
1822,
12,
841,
1299,
12,
221,
3388,
12,
1196,
1153,
12,
713,
1876,
12,
1196,
1082,
12,
199,
1749,
2322,
12,
1079,
383,
12,
1196,
1276,
12,
221,
10954,
12,
1749,
966,
12,
713,
2760,
12,
1196,
1344,
12,
1196,
1401,
12,
8375,
19,
12,
499,
2006,
12,
1196,
1703,
12,
21292,
12,
650,
969,
12,
1520,
1184,
12,
17640,
12,
1196,
1355,
12,
199,
25186,
12,
1749,
1555,
12,
1695,
969,
12,
1079,
614,
12,
1227,
2658,
12,
221,
13098,
12,
713,
966,
12,
28818,
12,
1196,
2167,
12,
1196,
2953,
12,
1196,
2260,
12,
1196,
2824,
12,
221,
3193,
12,
8264,
23,
12,
1227,
1822,
12,
1227,
1081,
12,
199,
1520,
2036,
12,
1196,
1602,
12,
1196,
2322,
12,
1196,
2466,
12,
1749,
1272,
12,
1520,
1555,
12,
20398,
12,
25454,
12,
1196,
2417,
12,
221,
5212,
12,
1695,
1165,
12,
11869,
12,
1227,
2114,
12,
1196,
2006,
12,
1196,
1887,
12,
1196,
1400,
12,
199,
1196,
2869,
12,
1227,
1196,
12,
1196,
2528,
12,
1227,
1479,
12,
1196,
2481,
12,
1196,
1477,
12,
1196,
1229,
12,
1196,
1367,
12,
1227,
2481,
12,
1196,
1641,
12,
1196,
2010,
12,
1196,
1427,
12,
1196,
2259,
12,
1196,
2976,
12,
1196,
2789,
12,
1695,
1367,
12,
199,
650,
1602,
12,
1196,
2766,
12,
1196,
772,
12,
1196,
2182,
12,
1196,
1272,
12,
221,
17838,
12,
13952,
12,
841,
1085,
12,
5939,
22,
12,
1749,
1717,
12,
8264,
24,
12,
1196,
1822,
12,
1196,
2333,
12,
1196,
1876,
12,
1749,
2466,
12,
713,
1717,
12,
199,
1520,
1643,
12,
8881,
16,
12,
845,
1085,
12,
8881,
17,
12,
499,
2953,
12,
8881,
18,
12,
8881,
19,
12,
8881,
20,
12,
713,
3172,
12,
8881,
21,
12,
959,
1876,
12,
8881,
22,
12,
22291,
12,
8881,
23,
12,
8881,
24,
12,
8881,
25,
12,
199,
1196,
1257,
12,
650,
1401,
12,
1520,
2869,
12,
709,
2010,
12,
221,
7294,
12,
1227,
1651,
12,
22540,
12,
1196,
2835,
12,
413,
1138,
12,
1749,
1690,
12,
27632,
12,
650,
1887,
12,
221,
15601,
12,
709,
1965,
12,
1196,
2564,
12,
221,
5851,
12,
199,
1196,
2658,
12,
650,
1965,
12,
1196,
1349,
12,
650,
1046,
12,
1196,
2426,
12,
1227,
1398,
12,
1520,
1477,
12,
29840,
12,
959,
1427,
12,
1196,
1184,
12,
1227,
1344,
12,
29202,
12,
713,
1690,
12,
1196,
1555,
12,
1520,
709,
12,
959,
1822,
12,
199,
1196,
1299,
12,
1749,
1276,
12,
1695,
1079,
12,
1196,
1407,
12,
1196,
2710,
12,
713,
1780,
12,
1520,
1272,
12,
959,
1651,
12,
1196,
3328,
12,
1196,
2942,
12,
713,
2036,
12,
1196,
3129,
12,
1196,
2635,
12,
1196,
2720,
12,
1196,
2534,
12,
1196,
2576,
12,
199,
1079,
1644,
12,
1196,
2905,
12,
1196,
1020,
12,
959,
1153,
12,
709,
1427,
12,
1079,
966,
12,
1079,
1717,
12,
845,
1367,
12,
1079,
1690,
12,
1749,
1344,
12,
10523,
20,
12,
23514,
12,
1085,
383,
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,
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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
] |
CryptArc/bitcoin
|
test/functional/combine_logs.py
|
5
|
7590
|
#!/usr/bin/env python3
"""Combine logs from multiple bitcoin nodes as well as the test_framework log.
This streams the combined log output to stdout. Use combine_logs.py > outputfile
to write to an outputfile.
If no argument is provided, the most recent test directory will be used."""
import argparse
from collections import defaultdict, namedtuple
import glob
import heapq
import itertools
import os
import pathlib
import re
import sys
import tempfile
# N.B.: don't import any local modules here - this script must remain executable
# without the parent module installed.
# Should match same symbol in `test_framework.test_framework`.
TMPDIR_PREFIX = "bitcoin_func_test_"
# Matches on the date format at the start of the log event
TIMESTAMP_PATTERN = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{6})?Z")
LogEvent = namedtuple('LogEvent', ['timestamp', 'source', 'event'])
def main():
"""Main function. Parses args, reads the log files and renders them as text or html."""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'testdir', nargs='?', default='',
help=('temporary test directory to combine logs from. '
'Defaults to the most recent'))
parser.add_argument('-c', '--color', dest='color', action='store_true', help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)')
parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2')
args = parser.parse_args()
if args.html and args.color:
print("Only one out of --color or --html should be specified")
sys.exit(1)
testdir = args.testdir or find_latest_test_dir()
if not testdir:
print("No test directories found")
sys.exit(1)
if not args.testdir:
print("Opening latest test directory: {}".format(testdir), file=sys.stderr)
colors = defaultdict(lambda: '')
if args.color:
colors["test"] = "\033[0;36m" # CYAN
colors["node0"] = "\033[0;34m" # BLUE
colors["node1"] = "\033[0;32m" # GREEN
colors["node2"] = "\033[0;31m" # RED
colors["node3"] = "\033[0;33m" # YELLOW
colors["reset"] = "\033[0m" # Reset font color
log_events = read_logs(testdir)
if args.html:
print_logs_html(log_events)
else:
print_logs_plain(log_events, colors)
print_node_warnings(testdir, colors)
def read_logs(tmp_dir):
"""Reads log files.
Delegates to generator function get_log_events() to provide individual log events
for each of the input log files."""
# Find out what the folder is called that holds the debug.log file
chain = glob.glob("{}/node0/*/debug.log".format(tmp_dir))
if chain:
chain = chain[0] # pick the first one if more than one chain was found (should never happen)
chain = re.search(r'node0/(.+?)/debug\.log$', chain).group(1) # extract the chain name
else:
chain = 'regtest' # fallback to regtest (should only happen when none exists)
files = [("test", "%s/test_framework.log" % tmp_dir)]
for i in itertools.count():
logfile = "{}/node{}/{}/debug.log".format(tmp_dir, i, chain)
if not os.path.isfile(logfile):
break
files.append(("node%d" % i, logfile))
return heapq.merge(*[get_log_events(source, f) for source, f in files])
def print_node_warnings(tmp_dir, colors):
"""Print nodes' errors and warnings"""
warnings = []
for stream in ['stdout', 'stderr']:
for i in itertools.count():
folder = "{}/node{}/{}".format(tmp_dir, i, stream)
if not os.path.isdir(folder):
break
for (_, _, fns) in os.walk(folder):
for fn in fns:
warning = pathlib.Path('{}/{}'.format(folder, fn)).read_text().strip()
if warning:
warnings.append(("node{} {}".format(i, stream), warning))
print()
for w in warnings:
print("{} {} {} {}".format(colors[w[0].split()[0]], w[0], w[1], colors["reset"]))
def find_latest_test_dir():
"""Returns the latest tmpfile test directory prefix."""
tmpdir = tempfile.gettempdir()
def join_tmp(basename):
return os.path.join(tmpdir, basename)
def is_valid_test_tmpdir(basename):
fullpath = join_tmp(basename)
return (
os.path.isdir(fullpath)
and basename.startswith(TMPDIR_PREFIX)
and os.access(fullpath, os.R_OK)
)
testdir_paths = [
join_tmp(name) for name in os.listdir(tmpdir) if is_valid_test_tmpdir(name)
]
return max(testdir_paths, key=os.path.getmtime) if testdir_paths else None
def get_log_events(source, logfile):
"""Generator function that returns individual log events.
Log events may be split over multiple lines. We use the timestamp
regex match as the marker for a new log event."""
try:
with open(logfile, 'r', encoding='utf-8') as infile:
event = ''
timestamp = ''
for line in infile:
# skip blank lines
if line == '\n':
continue
# if this line has a timestamp, it's the start of a new log event.
time_match = TIMESTAMP_PATTERN.match(line)
if time_match:
if event:
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
timestamp = time_match.group()
if time_match.group(1) is None:
# timestamp does not have microseconds. Add zeroes.
timestamp_micro = timestamp.replace("Z", ".000000Z")
line = line.replace(timestamp, timestamp_micro)
timestamp = timestamp_micro
event = line
# if it doesn't have a timestamp, it's a continuation line of the previous log.
else:
# Add the line. Prefix with space equivalent to the source + timestamp so log lines are aligned
event += " " + line
# Flush the final event
yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip())
except FileNotFoundError:
print("File %s could not be opened. Continuing without it." % logfile, file=sys.stderr)
def print_logs_plain(log_events, colors):
"""Renders the iterator of log events into text."""
for event in log_events:
lines = event.event.splitlines()
print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"]))
if len(lines) > 1:
for line in lines[1:]:
print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"]))
def print_logs_html(log_events):
"""Renders the iterator of log events into html."""
try:
import jinja2
except ImportError:
print("jinja2 not found. Try `pip install jinja2`")
sys.exit(1)
print(jinja2.Environment(loader=jinja2.FileSystemLoader('./'))
.get_template('combined_log_template.html')
.render(title="Combined Logs from testcase", log_events=[event._asdict() for event in log_events]))
if __name__ == '__main__':
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
624,
23163,
9610,
687,
3663,
27214,
3380,
465,
5521,
465,
314,
511,
63,
4857,
943,
14,
199,
199,
2765,
13788,
314,
12149,
943,
1072,
370,
3839,
14,
3645,
13323,
63,
7270,
14,
647,
690,
32513,
199,
475,
2218,
370,
376,
32513,
14,
199,
199,
3917,
949,
1423,
365,
2741,
12,
314,
4750,
8058,
511,
2082,
911,
506,
1202,
1041,
199,
199,
646,
7534,
199,
504,
5055,
492,
10018,
12,
12863,
199,
646,
5739,
199,
646,
13295,
81,
199,
646,
7975,
199,
646,
747,
199,
646,
32212,
199,
646,
295,
199,
646,
984,
199,
646,
5549,
199,
199,
3,
653,
14,
34,
16781,
2793,
1133,
492,
1263,
2257,
4621,
2348,
446,
642,
2884,
1471,
5706,
7286,
199,
3,
1928,
314,
1676,
859,
4903,
14,
199,
199,
3,
7719,
1336,
2011,
5272,
315,
658,
396,
63,
4857,
14,
396,
63,
4857,
2313,
199,
17983,
3022,
63,
6351,
275,
298,
22816,
63,
1532,
63,
396,
12172,
199,
199,
3,
21682,
641,
314,
1434,
1475,
737,
314,
1343,
402,
314,
943,
1566,
199,
20277,
63,
10764,
275,
295,
14,
2014,
8,
82,
2,
12773,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
52,
60,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
2961,
3134,
68,
91,
22,
1552,
31,
58,
531,
199,
199,
2445,
2390,
275,
12863,
360,
2445,
2390,
297,
788,
3954,
297,
283,
1365,
297,
283,
1430,
1105,
199,
199,
318,
2446,
837,
272,
408,
6756,
805,
14,
29968,
1249,
12,
11597,
314,
943,
1584,
436,
3795,
83,
3062,
465,
1318,
503,
3517,
1041,
272,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
18971,
1301,
3108,
9698,
63,
533,
29,
18978,
14,
7963,
1872,
22779,
9,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
16634,
297,
9237,
31468,
849,
4581,
267,
1720,
7782,
13555,
511,
2082,
370,
13323,
9610,
687,
14,
283,
1598,
283,
16986,
370,
314,
4750,
8058,
1333,
272,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2850,
2326,
297,
2053,
534,
2326,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
4467,
314,
12149,
943,
543,
4474,
32076,
701,
1350,
334,
6537,
10694,
11167,
9229,
14,
3645,
6656,
446,
82,
367,
2455,
316,
5942,
272,
1798,
14,
525,
63,
2094,
4517,
1360,
297,
2053,
534,
1360,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
4467,
314,
12149,
943,
465,
3517,
14,
15127,
10321,
18,
14,
7305,
3907,
10321,
18,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
1249,
14,
1360,
436,
1249,
14,
2326,
26,
267,
870,
480,
5903,
1373,
734,
402,
1553,
2326,
503,
1553,
1360,
1077,
506,
2013,
531,
267,
984,
14,
2224,
8,
17,
9,
339,
7368,
275,
1249,
14,
16634,
503,
2342,
63,
7410,
63,
396,
63,
694,
342,
339,
340,
440,
7368,
26,
267,
870,
480,
1944,
511,
6602,
1911,
531,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
440,
1249,
14,
16634,
26,
267,
870,
480,
4299,
316,
8839,
511,
2082,
26,
8352,
908,
8,
16634,
395,
570,
29,
1274,
14,
3083,
9,
339,
9229,
275,
10018,
8,
2734,
26,
4074,
272,
340,
1249,
14,
2326,
26,
267,
9229,
905,
396,
937,
275,
1867,
8762,
59,
16,
27,
1344,
77,
2,
221,
327,
445,
57,
879,
267,
9229,
905,
932,
16,
937,
275,
1867,
8762,
59,
16,
27,
1082,
77,
2,
221,
327,
31408,
267,
9229,
905,
932,
17,
937,
275,
1867,
8762,
59,
16,
27,
708,
77,
2,
221,
327,
598,
14824,
267,
9229,
905,
932,
18,
937,
275,
1867,
8762,
59,
16,
27,
2192,
77,
2,
221,
327,
23443,
267,
9229,
905,
932,
19,
937,
275,
1867,
8762,
59,
16,
27,
1153,
77,
2,
221,
327,
1488,
23575,
267,
9229,
905,
3958,
937,
275,
1867,
8762,
59,
16,
77,
2,
221,
327,
15510,
5023,
3164,
339,
943,
63,
4368,
275,
1586,
63,
7270,
8,
16634,
9,
339,
340,
1249,
14,
1360,
26,
267,
870,
63,
7270,
63,
1360,
8,
793,
63,
4368,
9,
272,
587,
26,
267,
870,
63,
7270,
63,
6104,
8,
793,
63,
4368,
12,
9229,
9,
267,
870,
63,
932,
63,
5451,
8,
16634,
12,
9229,
9,
421,
199,
318,
1586,
63,
7270,
8,
2791,
63,
694,
304,
272,
408,
23614,
943,
1584,
14,
339,
1487,
4170,
2335,
370,
4306,
805,
664,
63,
793,
63,
4368,
342,
370,
5647,
8212,
943,
4474,
272,
367,
1924,
402,
314,
1324,
943,
1584,
1041,
339,
327,
6668,
734,
4052,
314,
4922,
365,
2797,
626,
15164,
314,
3105,
14,
793,
570,
272,
6036,
275,
5739,
14,
6463,
20794,
15,
932,
16,
6331,
15,
1757,
14,
793,
1674,
908,
8,
2791,
63,
694,
430,
272,
340,
6036,
26,
267,
6036,
275,
6036,
59,
16,
61,
221,
327,
3732,
314,
1642,
1373,
340,
1655,
2419,
1373,
6036,
1990,
1911,
334,
5626,
7078,
5992,
9,
267,
6036,
275,
295,
14,
1733,
8,
82,
7,
932,
16,
7985,
11198,
2447,
1757,
4537,
793,
4268,
6036,
680,
923,
8,
17,
9,
221,
327,
5536,
314,
6036,
536,
272,
587,
26,
267,
6036,
275,
283,
1135,
396,
7,
221,
327,
9567,
370,
1295,
396,
334,
5626,
1454,
5992,
1380,
7179,
3495,
9,
339,
1584,
275,
10003,
396,
401,
2071,
83,
15,
396,
63,
4857,
14,
793,
2,
450,
3529,
63,
694,
1874,
272,
367,
284,
315,
7975,
14,
835,
837,
267,
17251,
275,
11491,
15,
932,
2440,
19655,
1757,
14,
793,
1674,
908,
8,
2791,
63,
694,
12,
284,
12,
6036,
9,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
12804,
304,
288,
2059,
267,
1584,
14,
740,
9313,
932,
5,
68,
2,
450,
284,
12,
17251,
430,
339,
372,
13295,
81,
14,
5628,
23151,
362,
63,
793,
63,
4368,
8,
1365,
12,
289,
9,
367,
1350,
12,
289,
315,
1584,
566,
421,
199,
318,
870,
63,
932,
63,
5451,
8,
2791,
63,
694,
12,
9229,
304,
272,
408,
5375,
3380,
7,
2552,
436,
3598,
624,
339,
3598,
275,
942,
272,
367,
2547,
315,
788,
2703,
297,
283,
3083,
2565,
267,
367,
284,
315,
7975,
14,
835,
837,
288,
4922,
275,
11491,
15,
932,
2440,
15,
13536,
908,
8,
2791,
63,
694,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
624,
23163,
9610,
687,
3663,
27214,
3380,
465,
5521,
465,
314,
511,
63,
4857,
943,
14,
199,
199,
2765,
13788,
314,
12149,
943,
1072,
370,
3839,
14,
3645,
13323,
63,
7270,
14,
647,
690,
32513,
199,
475,
2218,
370,
376,
32513,
14,
199,
199,
3917,
949,
1423,
365,
2741,
12,
314,
4750,
8058,
511,
2082,
911,
506,
1202,
1041,
199,
199,
646,
7534,
199,
504,
5055,
492,
10018,
12,
12863,
199,
646,
5739,
199,
646,
13295,
81,
199,
646,
7975,
199,
646,
747,
199,
646,
32212,
199,
646,
295,
199,
646,
984,
199,
646,
5549,
199,
199,
3,
653,
14,
34,
16781,
2793,
1133,
492,
1263,
2257,
4621,
2348,
446,
642,
2884,
1471,
5706,
7286,
199,
3,
1928,
314,
1676,
859,
4903,
14,
199,
199,
3,
7719,
1336,
2011,
5272,
315,
658,
396,
63,
4857,
14,
396,
63,
4857,
2313,
199,
17983,
3022,
63,
6351,
275,
298,
22816,
63,
1532,
63,
396,
12172,
199,
199,
3,
21682,
641,
314,
1434,
1475,
737,
314,
1343,
402,
314,
943,
1566,
199,
20277,
63,
10764,
275,
295,
14,
2014,
8,
82,
2,
12773,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
52,
60,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
2961,
3134,
68,
91,
22,
1552,
31,
58,
531,
199,
199,
2445,
2390,
275,
12863,
360,
2445,
2390,
297,
788,
3954,
297,
283,
1365,
297,
283,
1430,
1105,
199,
199,
318,
2446,
837,
272,
408,
6756,
805,
14,
29968,
1249,
12,
11597,
314,
943,
1584,
436,
3795,
83,
3062,
465,
1318,
503,
3517,
1041,
272,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
18971,
1301,
3108,
9698,
63,
533,
29,
18978,
14,
7963,
1872,
22779,
9,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
16634,
297,
9237,
31468,
849,
4581,
267,
1720,
7782,
13555,
511,
2082,
370,
13323,
9610,
687,
14,
283,
1598,
283,
16986,
370,
314,
4750,
8058,
1333,
272,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2850,
2326,
297,
2053,
534,
2326,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
4467,
314,
12149,
943,
543,
4474,
32076,
701,
1350,
334,
6537,
10694,
11167,
9229,
14,
3645,
6656,
446,
82,
367,
2455,
316,
5942,
272,
1798,
14,
525,
63,
2094,
4517,
1360,
297,
2053,
534,
1360,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
4467,
314,
12149,
943,
465,
3517,
14,
15127,
10321,
18,
14,
7305,
3907,
10321,
18,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
340,
1249,
14,
1360,
436,
1249,
14,
2326,
26,
267,
870,
480,
5903,
1373,
734,
402,
1553,
2326,
503,
1553,
1360,
1077,
506,
2013,
531,
267,
984,
14,
2224,
8,
17,
9,
339,
7368,
275,
1249,
14,
16634,
503,
2342,
63,
7410,
63,
396,
63,
694,
342,
339,
340,
440,
7368,
26,
267,
870,
480,
1944,
511,
6602,
1911,
531,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
440,
1249,
14,
16634,
26,
267,
870,
480,
4299,
316,
8839,
511,
2082,
26,
8352,
908,
8,
16634,
395,
570,
29,
1274,
14,
3083,
9,
339,
9229,
275,
10018,
8,
2734,
26,
4074,
272,
340,
1249,
14,
2326,
26,
267,
9229,
905,
396,
937,
275,
1867,
8762,
59,
16,
27,
1344,
77,
2,
221,
327,
445,
57,
879,
267,
9229,
905,
932,
16,
937,
275,
1867,
8762,
59,
16,
27,
1082,
77,
2,
221,
327,
31408,
267,
9229,
905,
932,
17,
937,
275,
1867,
8762,
59,
16,
27,
708,
77,
2,
221,
327,
598,
14824,
267,
9229,
905,
932,
18,
937,
275,
1867,
8762,
59,
16,
27,
2192,
77,
2,
221,
327,
23443,
267,
9229,
905,
932,
19,
937,
275,
1867,
8762,
59,
16,
27,
1153,
77,
2,
221,
327,
1488,
23575,
267,
9229,
905,
3958,
937,
275,
1867,
8762,
59,
16,
77,
2,
221,
327,
15510,
5023,
3164,
339,
943,
63,
4368,
275,
1586,
63,
7270,
8,
16634,
9,
339,
340,
1249,
14,
1360,
26,
267,
870,
63,
7270,
63,
1360,
8,
793,
63,
4368,
9,
272,
587,
26,
267,
870,
63,
7270,
63,
6104,
8,
793,
63,
4368,
12,
9229,
9,
267,
870,
63,
932,
63,
5451,
8,
16634,
12,
9229,
9,
421,
199,
318,
1586,
63,
7270,
8,
2791,
63,
694,
304,
272,
408,
23614,
943,
1584,
14,
339,
1487,
4170,
2335,
370,
4306,
805,
664,
63,
793,
63,
4368,
342,
370,
5647,
8212,
943,
4474,
272,
367,
1924,
402,
314,
1324,
943,
1584,
1041,
339,
327,
6668,
734,
4052,
314,
4922,
365,
2797,
626,
15164,
314,
3105,
14,
793,
570,
272,
6036,
275,
5739,
14,
6463,
20794,
15,
932,
16,
6331,
15,
1757,
14,
793,
1674,
908,
8,
2791,
63,
694,
430,
272,
340,
6036,
26,
267,
6036,
275,
6036,
59,
16,
61,
221,
327,
3732,
314,
1642,
1373,
340,
1655,
2419,
1373,
6036,
1990,
1911,
334,
5626,
7078,
5992,
9,
267,
6036,
275,
295,
14,
1733,
8,
82,
7,
932,
16,
7985,
11198,
2447,
1757,
4537,
793,
4268,
6036,
680,
923,
8,
17,
9,
221,
327,
5536,
314,
6036,
536,
272,
587,
26,
267,
6036,
275,
283,
1135,
396,
7,
221,
327,
9567,
370,
1295,
396,
334,
5626,
1454,
5992,
1380,
7179,
3495,
9,
339,
1584,
275,
10003,
396,
401,
2071,
83,
15,
396,
63,
4857,
14,
793,
2,
450,
3529,
63,
694,
1874,
272,
367,
284,
315,
7975,
14,
835,
837,
267,
17251,
275,
11491,
15,
932,
2440,
19655,
1757,
14,
793,
1674,
908,
8,
2791,
63,
694,
12,
284,
12,
6036,
9,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
12804,
304,
288,
2059,
267,
1584,
14,
740,
9313,
932,
5,
68,
2,
450,
284,
12,
17251,
430,
339,
372,
13295,
81,
14,
5628,
23151,
362,
63,
793,
63,
4368,
8,
1365,
12,
289,
9,
367,
1350,
12,
289,
315,
1584,
566,
421,
199,
318,
870,
63,
932,
63,
5451,
8,
2791,
63,
694,
12,
9229,
304,
272,
408,
5375,
3380,
7,
2552,
436,
3598,
624,
339,
3598,
275,
942,
272,
367,
2547,
315,
788,
2703,
297,
283,
3083,
2565,
267,
367,
284,
315,
7975,
14,
835,
837,
288,
4922,
275,
11491,
15,
932,
2440,
15,
13536,
908,
8,
2791,
63,
694,
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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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
] |
piquadrat/django
|
django/db/migrations/operations/base.py
|
40
|
4830
|
from django.db import router
class Operation:
"""
Base class for migration operations.
It's responsible for both mutating the in-memory model state
(see db/migrations/state.py) to represent what it performs, as well
as actually performing it against a live database.
Note that some operations won't modify memory state at all (e.g. data
copying operations), and some will need their modifications to be
optionally specified by the user (e.g. custom Python code snippets)
Due to the way this class deals with deconstruction, it should be
considered immutable.
"""
# If this migration can be run in reverse.
# Some operations are impossible to reverse, like deleting data.
reversible = True
# Can this migration be represented as SQL? (things like RunPython cannot)
reduces_to_sql = True
# Should this operation be forced as atomic even on backends with no
# DDL transaction support (i.e., does it have no DDL, like RunPython)
atomic = False
# Should this operation be considered safe to elide and optimize across?
elidable = False
serialization_expand_args = []
def __new__(cls, *args, **kwargs):
# We capture the arguments to make returning them trivial
self = object.__new__(cls)
self._constructor_args = (args, kwargs)
return self
def deconstruct(self):
"""
Return a 3-tuple of class import path (or just name if it lives
under django.db.migrations), positional arguments, and keyword
arguments.
"""
return (
self.__class__.__name__,
self._constructor_args[0],
self._constructor_args[1],
)
def state_forwards(self, app_label, state):
"""
Take the state from the previous migration, and mutate it
so that it matches what this migration would perform.
"""
raise NotImplementedError('subclasses of Operation must provide a state_forwards() method')
def database_forwards(self, app_label, schema_editor, from_state, to_state):
"""
Perform the mutation on the database schema in the normal
(forwards) direction.
"""
raise NotImplementedError('subclasses of Operation must provide a database_forwards() method')
def database_backwards(self, app_label, schema_editor, from_state, to_state):
"""
Perform the mutation on the database schema in the reverse
direction - e.g. if this were CreateModel, it would in fact
drop the model's table.
"""
raise NotImplementedError('subclasses of Operation must provide a database_backwards() method')
def describe(self):
"""
Output a brief summary of what the action does.
"""
return "%s: %s" % (self.__class__.__name__, self._constructor_args)
def references_model(self, name, app_label=None):
"""
Return True if there is a chance this operation references the given
model name (as a string), with an optional app label for accuracy.
Used for optimization. If in doubt, return True;
returning a false positive will merely make the optimizer a little
less efficient, while returning a false negative may result in an
unusable optimized migration.
"""
return True
def references_field(self, model_name, name, app_label=None):
"""
Return True if there is a chance this operation references the given
field name, with an optional app label for accuracy.
Used for optimization. If in doubt, return True.
"""
return self.references_model(model_name, app_label)
def allow_migrate_model(self, connection_alias, model):
"""
Return wether or not a model may be migrated.
This is a thin wrapper around router.allow_migrate_model() that
preemptively rejects any proxy, swapped out, or unmanaged model.
"""
if not model._meta.can_migrate(connection_alias):
return False
return router.allow_migrate_model(connection_alias, model)
def reduce(self, operation, in_between, app_label=None):
"""
Return either a list of operations the actual operation should be
replaced with or a boolean that indicates whether or not the specified
operation can be optimized across.
"""
if self.elidable:
return [operation]
elif operation.elidable:
return [self]
return False
def __repr__(self):
return "<%s %s%s>" % (
self.__class__.__name__,
", ".join(map(repr, self._constructor_args[0])),
",".join(" %s=%r" % x for x in self._constructor_args[1].items()),
)
|
bsd-3-clause
|
[
504,
1639,
14,
697,
492,
6197,
421,
199,
533,
17954,
26,
272,
408,
272,
3523,
1021,
367,
8367,
5331,
14,
339,
2779,
1159,
17845,
367,
3865,
8567,
1958,
314,
315,
13,
4844,
1402,
1174,
272,
334,
3239,
1592,
15,
7685,
15,
929,
14,
647,
9,
370,
2954,
4052,
652,
18628,
12,
465,
5521,
272,
465,
5965,
19203,
652,
6169,
282,
12166,
3050,
14,
339,
3390,
626,
2005,
5331,
7859,
1133,
2811,
4402,
1174,
737,
1006,
334,
69,
14,
71,
14,
666,
272,
16743,
5331,
395,
436,
2005,
911,
1929,
3932,
23070,
370,
506,
272,
14190,
2013,
701,
314,
922,
334,
69,
14,
71,
14,
3537,
2018,
1233,
19484,
9,
339,
25855,
370,
314,
4340,
642,
1021,
477,
2551,
543,
477,
12708,
12,
652,
1077,
506,
272,
8652,
17092,
14,
272,
408,
339,
327,
982,
642,
8367,
883,
506,
1255,
315,
3837,
14,
272,
327,
6601,
5331,
787,
26847,
370,
3837,
12,
2839,
13794,
666,
14,
272,
29465,
1164,
275,
715,
339,
327,
6855,
642,
8367,
506,
11159,
465,
5385,
31,
334,
25970,
2839,
3378,
4718,
3913,
9,
272,
295,
10569,
63,
475,
63,
3009,
275,
715,
339,
327,
7719,
642,
3439,
506,
19565,
465,
15374,
2755,
641,
14745,
543,
949,
272,
327,
32078,
6008,
2291,
334,
73,
14,
69,
2020,
1630,
652,
1172,
949,
32078,
12,
2839,
3378,
4718,
9,
272,
15374,
275,
756,
339,
327,
7719,
642,
3439,
506,
8652,
5048,
370,
325,
8409,
436,
13497,
9371,
31,
272,
325,
7401,
461,
275,
756,
339,
16953,
63,
4441,
63,
589,
275,
942,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
2136,
12296,
314,
2368,
370,
1852,
8152,
3062,
28586,
267,
291,
275,
909,
855,
1222,
721,
1886,
9,
267,
291,
423,
1880,
63,
589,
275,
334,
589,
12,
2074,
9,
267,
372,
291,
339,
347,
477,
8514,
8,
277,
304,
267,
408,
267,
1432,
282,
650,
13,
2960,
402,
1021,
492,
931,
334,
269,
2951,
536,
340,
652,
27576,
267,
1334,
1639,
14,
697,
14,
7685,
395,
11333,
2368,
12,
436,
4252,
267,
2368,
14,
267,
408,
267,
372,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
291,
423,
1880,
63,
589,
59,
16,
467,
288,
291,
423,
1880,
63,
589,
59,
17,
467,
267,
776,
339,
347,
1174,
63,
19159,
8,
277,
12,
1145,
63,
1302,
12,
1174,
304,
267,
408,
267,
18146,
314,
1174,
687,
314,
4136,
8367,
12,
436,
31173,
652,
267,
880,
626,
652,
4450,
4052,
642,
8367,
3955,
5147,
14,
267,
408,
267,
746,
4279,
360,
19094,
402,
17954,
1471,
5647,
282,
1174,
63,
19159,
342,
1083,
358,
339,
347,
3050,
63,
19159,
8,
277,
12,
1145,
63,
1302,
12,
4177,
63,
7515,
12,
687,
63,
929,
12,
370,
63,
929,
304,
267,
408,
267,
14795,
314,
31083,
641,
314,
3050,
4177,
315,
314,
3293,
267,
334,
19159,
9,
7581,
14,
267,
408,
267,
746,
4279,
360,
19094,
402,
17954,
1471,
5647,
282,
3050,
63,
19159,
342,
1083,
358,
339,
347,
3050,
63,
22269,
8,
277,
12,
1145,
63,
1302,
12,
4177,
63,
7515,
12,
687,
63,
929,
12,
370,
63,
929,
304,
267,
408,
267,
14795,
314,
31083,
641,
314,
3050,
4177,
315,
314,
3837,
267,
7581,
446,
325,
14,
71,
14,
340,
642,
4898,
2790,
1685,
12,
652,
3955,
315,
10572,
267,
5978,
314,
1402,
1159,
1817,
14,
267,
408,
267,
746,
4279,
360,
19094,
402,
17954,
1471,
5647,
282,
3050,
63,
22269,
342,
1083,
358,
339,
347,
13743,
8,
277,
304,
267,
408,
267,
7242,
282,
29226,
6212,
402,
4052,
314,
1595,
1630,
14,
267,
408,
267,
372,
2071,
83,
26,
450,
83,
2,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
423,
1880,
63,
589,
9,
339,
347,
6941,
63,
1238,
8,
277,
12,
536,
12,
1145,
63,
1302,
29,
403,
304,
267,
408,
267,
1432,
715,
340,
2337,
365,
282,
22044,
642,
3439,
6941,
314,
1627,
267,
1402,
536,
334,
305,
282,
1059,
395,
543,
376,
2716,
1145,
1768,
367,
12862,
14,
398,
8051,
367,
13712,
14,
982,
315,
28584,
84,
12,
372,
715,
27,
267,
8152,
282,
3055,
7317,
911,
562,
264,
590,
1852,
314,
10736,
282,
12050,
267,
6656,
13402,
12,
1830,
8152,
282,
3055,
6946,
1443,
754,
315,
376,
267,
625,
14418,
20212,
8367,
14,
267,
408,
267,
372,
715,
339,
347,
6941,
63,
698,
8,
277,
12,
1402,
63,
354,
12,
536,
12,
1145,
63,
1302,
29,
403,
304,
267,
408,
267,
1432,
715,
340,
2337,
365,
282,
22044,
642,
3439,
6941,
314,
1627,
267,
901,
536,
12,
543,
376,
2716,
1145,
1768,
367,
12862,
14,
398,
8051,
367,
13712,
14,
982,
315,
28584,
84,
12,
372,
715,
14,
267,
408,
267,
372,
291,
14,
12635,
63,
1238,
8,
1238,
63,
354,
12,
1145,
63,
1302,
9,
339,
347,
2040,
63,
8462,
63,
1238,
8,
277,
12,
1950,
63,
3620,
12,
1402,
304,
267,
408,
267,
1432,
781,
728,
503,
440,
282,
1402,
1443,
506,
28322,
14,
398,
961,
365,
282,
30758,
4975,
6818,
6197,
14,
3306,
63,
8462,
63,
1238,
342,
626,
267,
299,
850,
311,
9462,
17100,
83,
1263,
4566,
12,
25072,
734,
12,
503,
625,
11122,
1402,
14,
267,
408,
267,
340,
440,
1402,
423,
2024,
14,
2425,
63,
8462,
8,
2105,
63,
3620,
304,
288,
372,
756,
398,
372,
6197,
14,
3306,
63,
8462,
63,
1238,
8,
2105,
63,
3620,
12,
1402,
9,
339,
347,
7114,
8,
277,
12,
3439,
12,
315,
63,
13007,
12,
1145,
63,
1302,
29,
403,
304,
267,
408,
267,
1432,
1902,
282,
769,
402,
5331,
314,
3503,
3439,
1077,
506,
267,
8717,
543,
503,
282,
5046,
626,
9126,
3775,
503,
440,
314,
2013,
267,
3439,
883,
506,
20212,
9371,
14,
267,
408,
267,
340,
291,
14,
69,
7401,
461,
26,
288,
372,
359,
5735,
61,
267,
916,
3439,
14,
69,
7401,
461,
26,
288,
372,
359,
277,
61,
267,
372,
756,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
450,
83,
5,
83,
4335,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
3872,
3680,
904,
8,
1130,
8,
2722,
12,
291,
423,
1880,
63,
589,
59,
16,
12884,
288,
19089,
904,
480,
450,
83,
2458,
82
] |
[
1639,
14,
697,
492,
6197,
421,
199,
533,
17954,
26,
272,
408,
272,
3523,
1021,
367,
8367,
5331,
14,
339,
2779,
1159,
17845,
367,
3865,
8567,
1958,
314,
315,
13,
4844,
1402,
1174,
272,
334,
3239,
1592,
15,
7685,
15,
929,
14,
647,
9,
370,
2954,
4052,
652,
18628,
12,
465,
5521,
272,
465,
5965,
19203,
652,
6169,
282,
12166,
3050,
14,
339,
3390,
626,
2005,
5331,
7859,
1133,
2811,
4402,
1174,
737,
1006,
334,
69,
14,
71,
14,
666,
272,
16743,
5331,
395,
436,
2005,
911,
1929,
3932,
23070,
370,
506,
272,
14190,
2013,
701,
314,
922,
334,
69,
14,
71,
14,
3537,
2018,
1233,
19484,
9,
339,
25855,
370,
314,
4340,
642,
1021,
477,
2551,
543,
477,
12708,
12,
652,
1077,
506,
272,
8652,
17092,
14,
272,
408,
339,
327,
982,
642,
8367,
883,
506,
1255,
315,
3837,
14,
272,
327,
6601,
5331,
787,
26847,
370,
3837,
12,
2839,
13794,
666,
14,
272,
29465,
1164,
275,
715,
339,
327,
6855,
642,
8367,
506,
11159,
465,
5385,
31,
334,
25970,
2839,
3378,
4718,
3913,
9,
272,
295,
10569,
63,
475,
63,
3009,
275,
715,
339,
327,
7719,
642,
3439,
506,
19565,
465,
15374,
2755,
641,
14745,
543,
949,
272,
327,
32078,
6008,
2291,
334,
73,
14,
69,
2020,
1630,
652,
1172,
949,
32078,
12,
2839,
3378,
4718,
9,
272,
15374,
275,
756,
339,
327,
7719,
642,
3439,
506,
8652,
5048,
370,
325,
8409,
436,
13497,
9371,
31,
272,
325,
7401,
461,
275,
756,
339,
16953,
63,
4441,
63,
589,
275,
942,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
2136,
12296,
314,
2368,
370,
1852,
8152,
3062,
28586,
267,
291,
275,
909,
855,
1222,
721,
1886,
9,
267,
291,
423,
1880,
63,
589,
275,
334,
589,
12,
2074,
9,
267,
372,
291,
339,
347,
477,
8514,
8,
277,
304,
267,
408,
267,
1432,
282,
650,
13,
2960,
402,
1021,
492,
931,
334,
269,
2951,
536,
340,
652,
27576,
267,
1334,
1639,
14,
697,
14,
7685,
395,
11333,
2368,
12,
436,
4252,
267,
2368,
14,
267,
408,
267,
372,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
291,
423,
1880,
63,
589,
59,
16,
467,
288,
291,
423,
1880,
63,
589,
59,
17,
467,
267,
776,
339,
347,
1174,
63,
19159,
8,
277,
12,
1145,
63,
1302,
12,
1174,
304,
267,
408,
267,
18146,
314,
1174,
687,
314,
4136,
8367,
12,
436,
31173,
652,
267,
880,
626,
652,
4450,
4052,
642,
8367,
3955,
5147,
14,
267,
408,
267,
746,
4279,
360,
19094,
402,
17954,
1471,
5647,
282,
1174,
63,
19159,
342,
1083,
358,
339,
347,
3050,
63,
19159,
8,
277,
12,
1145,
63,
1302,
12,
4177,
63,
7515,
12,
687,
63,
929,
12,
370,
63,
929,
304,
267,
408,
267,
14795,
314,
31083,
641,
314,
3050,
4177,
315,
314,
3293,
267,
334,
19159,
9,
7581,
14,
267,
408,
267,
746,
4279,
360,
19094,
402,
17954,
1471,
5647,
282,
3050,
63,
19159,
342,
1083,
358,
339,
347,
3050,
63,
22269,
8,
277,
12,
1145,
63,
1302,
12,
4177,
63,
7515,
12,
687,
63,
929,
12,
370,
63,
929,
304,
267,
408,
267,
14795,
314,
31083,
641,
314,
3050,
4177,
315,
314,
3837,
267,
7581,
446,
325,
14,
71,
14,
340,
642,
4898,
2790,
1685,
12,
652,
3955,
315,
10572,
267,
5978,
314,
1402,
1159,
1817,
14,
267,
408,
267,
746,
4279,
360,
19094,
402,
17954,
1471,
5647,
282,
3050,
63,
22269,
342,
1083,
358,
339,
347,
13743,
8,
277,
304,
267,
408,
267,
7242,
282,
29226,
6212,
402,
4052,
314,
1595,
1630,
14,
267,
408,
267,
372,
2071,
83,
26,
450,
83,
2,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
423,
1880,
63,
589,
9,
339,
347,
6941,
63,
1238,
8,
277,
12,
536,
12,
1145,
63,
1302,
29,
403,
304,
267,
408,
267,
1432,
715,
340,
2337,
365,
282,
22044,
642,
3439,
6941,
314,
1627,
267,
1402,
536,
334,
305,
282,
1059,
395,
543,
376,
2716,
1145,
1768,
367,
12862,
14,
398,
8051,
367,
13712,
14,
982,
315,
28584,
84,
12,
372,
715,
27,
267,
8152,
282,
3055,
7317,
911,
562,
264,
590,
1852,
314,
10736,
282,
12050,
267,
6656,
13402,
12,
1830,
8152,
282,
3055,
6946,
1443,
754,
315,
376,
267,
625,
14418,
20212,
8367,
14,
267,
408,
267,
372,
715,
339,
347,
6941,
63,
698,
8,
277,
12,
1402,
63,
354,
12,
536,
12,
1145,
63,
1302,
29,
403,
304,
267,
408,
267,
1432,
715,
340,
2337,
365,
282,
22044,
642,
3439,
6941,
314,
1627,
267,
901,
536,
12,
543,
376,
2716,
1145,
1768,
367,
12862,
14,
398,
8051,
367,
13712,
14,
982,
315,
28584,
84,
12,
372,
715,
14,
267,
408,
267,
372,
291,
14,
12635,
63,
1238,
8,
1238,
63,
354,
12,
1145,
63,
1302,
9,
339,
347,
2040,
63,
8462,
63,
1238,
8,
277,
12,
1950,
63,
3620,
12,
1402,
304,
267,
408,
267,
1432,
781,
728,
503,
440,
282,
1402,
1443,
506,
28322,
14,
398,
961,
365,
282,
30758,
4975,
6818,
6197,
14,
3306,
63,
8462,
63,
1238,
342,
626,
267,
299,
850,
311,
9462,
17100,
83,
1263,
4566,
12,
25072,
734,
12,
503,
625,
11122,
1402,
14,
267,
408,
267,
340,
440,
1402,
423,
2024,
14,
2425,
63,
8462,
8,
2105,
63,
3620,
304,
288,
372,
756,
398,
372,
6197,
14,
3306,
63,
8462,
63,
1238,
8,
2105,
63,
3620,
12,
1402,
9,
339,
347,
7114,
8,
277,
12,
3439,
12,
315,
63,
13007,
12,
1145,
63,
1302,
29,
403,
304,
267,
408,
267,
1432,
1902,
282,
769,
402,
5331,
314,
3503,
3439,
1077,
506,
267,
8717,
543,
503,
282,
5046,
626,
9126,
3775,
503,
440,
314,
2013,
267,
3439,
883,
506,
20212,
9371,
14,
267,
408,
267,
340,
291,
14,
69,
7401,
461,
26,
288,
372,
359,
5735,
61,
267,
916,
3439,
14,
69,
7401,
461,
26,
288,
372,
359,
277,
61,
267,
372,
756,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
450,
83,
5,
83,
4335,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
3872,
3680,
904,
8,
1130,
8,
2722,
12,
291,
423,
1880,
63,
589,
59,
16,
12884,
288,
19089,
904,
480,
450,
83,
2458,
82,
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,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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
] |
cuihaoleo/PyTest
|
PyTest.py
|
1
|
7675
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
##
# PyTest.py
# This file is part of PyTest.
#
# PyTest
# Python编写的OI评测器后端
# Copyright (C) 2011 CUI Hao
#
# 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/>.
#
# Author: 崔灏 (CUI Hao)
# Email: cuihao.leo@gmail.com
##
import cmd
import os
import shlex
import pickle
from PlayerClass import PyTest_Player
from ProblemClass import PyTest_Problem
from ProblemConfig import Cfg2Prob
class PyTest_Cmd (cmd.Cmd):
def __init__ (self):
cmd.Cmd.__init__(self)
self.prompt = "(PyTest) "
self.Name = "Unnamed"
self.Players = {}
self.Problems = {}
self.do_EOF = self.do_quit
def AddProb (self, cfg):
try:
prob = Cfg2Prob(cfg)
except Exception as exp:
print("无法添加题目 %s : 导入时发生错误")
print(exp)
else:
if prob.Name in self.Problems.keys():
print("无法添加题目 %s : 相同名称的题目已存在" % prob.Name)
else:
self.Problems[prob.Name] = prob
print("添加题目 %s" % prob.Name)
def AddPlayer (self, path):
try:
player = PyTest_Player(path)
except Exception as exp:
print("无法添加选手 %s : 导入时发生错误")
print(exp)
else:
if player.Name in self.Players.keys():
print("无法添加选手 %s : 相同名称的对象已存在" % player.Name)
else:
self.Players[player.Name] = player
print("添加选手 %s" % player.Name)
def DelProb (self, name):
try:
del self.Problems[name]
except KeyError:
print("无法删除题目 %s : 题目不存在" % name)
else:
print("删除题目 %s" % name)
def DelPlayer (self, name):
try:
del self.Players[name]
except KeyError:
print("无法删除选手 %s : 对象不存在" % name)
else:
print("删除选手 %s" % name)
def Testit (self, pl, pr):
try:
player = self.Players[pl]
except KeyError:
print("未知用户 %s" % pl)
return
try:
prob = self.Problems[pr]
except KeyError:
print("未知用户 %s" % pr)
return
player.Do(prob)
def help_quit (self):
print("quit")
print("退出")
def do_quit (self, line):
exit()
def help_name (self):
print("name [@名称]")
print("设置评测名称。若没有提供,显示当前名称")
def do_name (self, name):
if len(name.strip()) == 0:
print(self.Judge.Name)
else:
self.Judge.Name = name
def help_addprob (self):
print("addprob @配置文件1 [@配置文件2 [...]]")
print("添加题目")
def do_addprob (self, line):
for path in shlex.split(line):
self.AddProb(path)
def help_delprob (self):
print("delprob @题目1 [@题目2 [...]]")
print("删除题目")
def do_delprob (self, line):
for name in shlex.split(line):
self.DelProb(name)
def help_prob (self):
print("prob")
print("显示所有题目")
def do_prob (self, line):
for p in self.Problems:
print("%s: %s" % (p, self.Problems[p].CfgFile))
def help_add (self):
print("add @目录1 [@目录2 [...]]")
print("添加选手")
def do_add (self, line):
for path in shlex.split(line):
self.AddPlayer(path)
def help_addall (self):
print("addall @目录1 [@目录2 [...]]")
print("添加目录中的所有文件夹作为选手")
def do_addall (self, line):
for path in shlex.split(line):
try:
paths = next(os.walk(path))[1]
except StopIteration:
continue
for f in paths:
self.AddPlayer(os.path.join(path, f))
def help_del (self):
print("del @选手1 [@选手2 [...]]")
print("删除选手")
def do_del (self, line):
for name in shlex.split(line):
self.DelPlayer(name)
def help_player (self):
print("player")
print("显示所有选手")
def do_player (self, line):
for p in self.Players:
print("%s: %s" % (p, self.Players[p].Path))
def help_rec (self):
print("rec @选手 @题目")
print("显示详细评测信息")
def do_rec (self, line):
arg = shlex.split(line)
if len(arg)==2:
pl, pr = arg
else:
return
try:
li = self.Players[pl].Record[pr]
except KeyError:
print("记录不存在")
return
for idx in li:
print()
print("[测试#%s]" % idx)
for dic in li[idx]:
print("<文件 %s>" % dic.get("file", ""))
print("信息: %s" % dic.get("msg", ""))
print("得分: %s" % dic.get("score", ""))
def help_print (self):
print("打印Python表达式")
def do_print (self, line):
try:
print(eval(line))
except Exception as err:
print(err)
def help_test (self):
print("启动测试")
def do_test (self, line):
arg = shlex.split(line)
if len(arg) == 2:
Testit(*arg)
elif len(arg) == 0:
pls = input("测试对象(默认全部):").split()
prs = input("题目(默认全部):").split()
if len(pls) == 0:
pls = self.Players.keys()
if len(prs) == 0:
prs = self.Problems.keys()
for player in pls:
for prob in prs:
self.Testit(player, prob)
print()
def help_save (self):
print("储存本次测试")
def do_save (self, line):
path = shlex.split(line)[0]
if os.path.lexists(path):
while True:
ch = input("文件已存在,是否覆盖(Y/N)?")
if ch in ("y", "Y"):
break
elif ch in ("n", "N"):
return
f = open(path, "wb")
pickle.dump(self.Name, f, pickle.HIGHEST_PROTOCOL)
pickle.dump(self.Players, f, pickle.HIGHEST_PROTOCOL)
pickle.dump(self.Problems, f, pickle.HIGHEST_PROTOCOL)
f.close()
def help_load (self):
print("加载测试")
def do_load (self, line):
path = shlex.split(line)[0]
try:
f = open(path, "rb")
except IOError as err:
print(err)
return
self.Name = pickle.load(f)
self.Players = pickle.load(f)
self.Problems = pickle.load(f)
if __name__ == '__main__':
pytest = PyTest_Cmd()
pytest.cmdloop()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
309,
199,
3,
1611,
774,
14,
647,
199,
3,
961,
570,
365,
1777,
402,
1611,
774,
14,
199,
3,
199,
3,
1611,
774,
199,
3,
2018,
17637,
17950,
248,
8106,
47,
41,
8400,
227,
19451,
234,
162,
248,
102,
30368,
21341,
108,
199,
3,
1898,
334,
35,
9,
7760,
221,
445,
6379,
869,
8035,
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,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
6529,
26,
7094,
113,
243,
164,
224,
238,
334,
35,
6379,
869,
8035,
9,
199,
3,
11426,
26,
286,
1907,
2411,
79,
14,
274,
79,
32,
6799,
14,
957,
199,
309,
199,
199,
646,
2088,
199,
646,
747,
199,
646,
16701,
199,
646,
5927,
199,
504,
25610,
2543,
492,
1611,
774,
63,
10921,
199,
504,
20980,
2543,
492,
1611,
774,
63,
16467,
199,
504,
20980,
2028,
492,
445,
9681,
18,
20122,
199,
199,
533,
1611,
774,
63,
7874,
334,
1760,
14,
7874,
304,
272,
347,
636,
826,
363,
334,
277,
304,
267,
2088,
14,
7874,
855,
826,
721,
277,
9,
267,
291,
14,
7650,
275,
7340,
2713,
774,
9,
298,
267,
291,
14,
985,
275,
298,
1358,
4579,
2,
267,
291,
14,
48,
4359,
275,
1052,
267,
291,
14,
919,
7561,
275,
1052,
267,
291,
14,
1117,
63,
13178,
275,
291,
14,
1117,
63,
10589,
339,
347,
2654,
20122,
334,
277,
12,
4810,
304,
267,
862,
26,
288,
5128,
275,
445,
9681,
18,
20122,
8,
4128,
9,
267,
871,
2186,
465,
1437,
26,
288,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
21262,
247,
31869,
450,
83,
221,
25742,
7094,
108,
121,
18236,
20494,
26835,
29319,
32064,
531,
288,
870,
8,
1474,
9,
267,
587,
26,
288,
340,
5128,
14,
985,
315,
291,
14,
919,
7561,
14,
1612,
837,
355,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
21262,
247,
31869,
450,
83,
221,
25742,
9112,
250,
117,
28956,
21434,
19012,
109,
8106,
21262,
247,
31869,
28913,
29846,
21448,
2,
450,
5128,
14,
985,
9,
288,
587,
26,
355,
291,
14,
919,
7561,
59,
6101,
14,
985,
61,
275,
5128,
355,
870,
480,
163,
116,
8698,
233,
255,
21262,
247,
31869,
450,
83,
2,
450,
5128,
14,
985,
9,
339,
347,
2654,
10921,
334,
277,
12,
931,
304,
267,
862,
26,
288,
7748,
275,
1611,
774,
63,
10921,
8,
515,
9,
267,
871,
2186,
465,
1437,
26,
288,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
14333,
232,
10862,
234,
450,
83,
221,
25742,
7094,
108,
121,
18236,
20494,
26835,
29319,
32064,
531,
288,
870,
8,
1474,
9,
267,
587,
26,
288,
340,
7748,
14,
985,
315,
291,
14,
48,
4359,
14,
1612,
837,
355,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
14333,
232,
10862,
234,
450,
83,
221,
25742,
9112,
250,
117,
28956,
21434,
19012,
109,
8106,
26604,
165,
110,
95,
28913,
29846,
21448,
2,
450,
7748,
14,
985,
9,
288,
587,
26,
355,
291,
14,
48,
4359,
59,
6147,
14,
985,
61,
275,
7748,
355,
870,
480,
163,
116,
8698,
233,
255,
14333,
232,
10862,
234,
450,
83,
2,
450,
7748,
14,
985,
9,
339,
347,
18464,
20122,
334,
277,
12,
536,
304,
267,
862,
26,
288,
2150,
291,
14,
919,
7561,
59,
354,
61,
267,
871,
4067,
26,
288,
870,
480,
11373,
255,
27397,
9051,
255,
31459,
21262,
247,
31869,
450,
83,
221,
25742,
10469,
96,
247,
31869,
19594,
29846,
21448,
2,
450,
536,
9,
267,
587,
26,
288,
870,
480,
9051,
255,
31459,
21262,
247,
31869,
450,
83,
2,
450,
536,
9,
339,
347,
18464,
10921,
334,
277,
12,
536,
304,
267,
862,
26,
288,
2150,
291,
14,
48,
4359,
59,
354,
61,
267,
871,
4067,
26,
288,
870,
480,
11373,
255,
27397,
9051,
255,
31459,
14333,
232,
10862,
234,
450,
83,
221,
25742,
7094,
108,
118,
165,
110,
95,
19594,
29846,
21448,
2,
450,
536,
9,
267,
587,
26,
288,
870,
480,
9051,
255,
31459,
14333,
232,
10862,
234,
450,
83,
2,
450,
536,
9,
339,
347,
1379,
390,
334,
277,
12,
1620,
12,
5448,
304,
267,
862,
26,
288,
7748,
275,
291,
14,
48,
4359,
59,
1168,
61,
267,
871,
4067,
26,
288,
870,
480,
6587,
104,
164,
18304,
22445,
450,
83,
2,
450,
1620,
9,
288,
372,
398,
862,
26,
288,
5128,
275,
291,
14,
919,
7561,
59,
2700,
61,
267,
871,
4067,
26,
288,
870,
480,
6587,
104,
164,
18304,
22445,
450,
83,
2,
450,
5448,
9,
288,
372,
398,
7748,
14,
2585,
8,
6101,
9,
5493,
347,
1720,
63,
10589,
334,
277,
304,
267,
870,
480,
10589,
531,
267,
870,
480,
14333,
223,
22914,
531,
272,
347,
886,
63,
10589,
334,
277,
12,
1004,
304,
267,
4458,
342,
339,
347,
1720,
63,
354,
334,
277,
304,
267,
870,
480,
354,
359,
32,
21434,
19012,
109,
12523,
267,
870,
480,
14082,
123,
27029,
8400,
227,
19451,
234,
21434,
19012,
109,
20061,
165,
234,
99,
163,
111,
95,
20916,
22843,
239,
25439,
250,
12356,
6812,
123,
29875,
119,
22918,
242,
27284,
21434,
19012,
109,
531,
272,
347,
886,
63,
354,
334,
277,
12,
536,
304,
267,
340,
822,
8,
354,
14,
1913,
1012,
508,
378,
26,
288,
870,
8,
277,
14,
42,
16603,
14,
985,
9,
267,
587,
26,
288
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
309,
199,
3,
1611,
774,
14,
647,
199,
3,
961,
570,
365,
1777,
402,
1611,
774,
14,
199,
3,
199,
3,
1611,
774,
199,
3,
2018,
17637,
17950,
248,
8106,
47,
41,
8400,
227,
19451,
234,
162,
248,
102,
30368,
21341,
108,
199,
3,
1898,
334,
35,
9,
7760,
221,
445,
6379,
869,
8035,
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,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
6529,
26,
7094,
113,
243,
164,
224,
238,
334,
35,
6379,
869,
8035,
9,
199,
3,
11426,
26,
286,
1907,
2411,
79,
14,
274,
79,
32,
6799,
14,
957,
199,
309,
199,
199,
646,
2088,
199,
646,
747,
199,
646,
16701,
199,
646,
5927,
199,
504,
25610,
2543,
492,
1611,
774,
63,
10921,
199,
504,
20980,
2543,
492,
1611,
774,
63,
16467,
199,
504,
20980,
2028,
492,
445,
9681,
18,
20122,
199,
199,
533,
1611,
774,
63,
7874,
334,
1760,
14,
7874,
304,
272,
347,
636,
826,
363,
334,
277,
304,
267,
2088,
14,
7874,
855,
826,
721,
277,
9,
267,
291,
14,
7650,
275,
7340,
2713,
774,
9,
298,
267,
291,
14,
985,
275,
298,
1358,
4579,
2,
267,
291,
14,
48,
4359,
275,
1052,
267,
291,
14,
919,
7561,
275,
1052,
267,
291,
14,
1117,
63,
13178,
275,
291,
14,
1117,
63,
10589,
339,
347,
2654,
20122,
334,
277,
12,
4810,
304,
267,
862,
26,
288,
5128,
275,
445,
9681,
18,
20122,
8,
4128,
9,
267,
871,
2186,
465,
1437,
26,
288,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
21262,
247,
31869,
450,
83,
221,
25742,
7094,
108,
121,
18236,
20494,
26835,
29319,
32064,
531,
288,
870,
8,
1474,
9,
267,
587,
26,
288,
340,
5128,
14,
985,
315,
291,
14,
919,
7561,
14,
1612,
837,
355,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
21262,
247,
31869,
450,
83,
221,
25742,
9112,
250,
117,
28956,
21434,
19012,
109,
8106,
21262,
247,
31869,
28913,
29846,
21448,
2,
450,
5128,
14,
985,
9,
288,
587,
26,
355,
291,
14,
919,
7561,
59,
6101,
14,
985,
61,
275,
5128,
355,
870,
480,
163,
116,
8698,
233,
255,
21262,
247,
31869,
450,
83,
2,
450,
5128,
14,
985,
9,
339,
347,
2654,
10921,
334,
277,
12,
931,
304,
267,
862,
26,
288,
7748,
275,
1611,
774,
63,
10921,
8,
515,
9,
267,
871,
2186,
465,
1437,
26,
288,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
14333,
232,
10862,
234,
450,
83,
221,
25742,
7094,
108,
121,
18236,
20494,
26835,
29319,
32064,
531,
288,
870,
8,
1474,
9,
267,
587,
26,
288,
340,
7748,
14,
985,
315,
291,
14,
48,
4359,
14,
1612,
837,
355,
870,
480,
11373,
255,
27397,
163,
116,
8698,
233,
255,
14333,
232,
10862,
234,
450,
83,
221,
25742,
9112,
250,
117,
28956,
21434,
19012,
109,
8106,
26604,
165,
110,
95,
28913,
29846,
21448,
2,
450,
7748,
14,
985,
9,
288,
587,
26,
355,
291,
14,
48,
4359,
59,
6147,
14,
985,
61,
275,
7748,
355,
870,
480,
163,
116,
8698,
233,
255,
14333,
232,
10862,
234,
450,
83,
2,
450,
7748,
14,
985,
9,
339,
347,
18464,
20122,
334,
277,
12,
536,
304,
267,
862,
26,
288,
2150,
291,
14,
919,
7561,
59,
354,
61,
267,
871,
4067,
26,
288,
870,
480,
11373,
255,
27397,
9051,
255,
31459,
21262,
247,
31869,
450,
83,
221,
25742,
10469,
96,
247,
31869,
19594,
29846,
21448,
2,
450,
536,
9,
267,
587,
26,
288,
870,
480,
9051,
255,
31459,
21262,
247,
31869,
450,
83,
2,
450,
536,
9,
339,
347,
18464,
10921,
334,
277,
12,
536,
304,
267,
862,
26,
288,
2150,
291,
14,
48,
4359,
59,
354,
61,
267,
871,
4067,
26,
288,
870,
480,
11373,
255,
27397,
9051,
255,
31459,
14333,
232,
10862,
234,
450,
83,
221,
25742,
7094,
108,
118,
165,
110,
95,
19594,
29846,
21448,
2,
450,
536,
9,
267,
587,
26,
288,
870,
480,
9051,
255,
31459,
14333,
232,
10862,
234,
450,
83,
2,
450,
536,
9,
339,
347,
1379,
390,
334,
277,
12,
1620,
12,
5448,
304,
267,
862,
26,
288,
7748,
275,
291,
14,
48,
4359,
59,
1168,
61,
267,
871,
4067,
26,
288,
870,
480,
6587,
104,
164,
18304,
22445,
450,
83,
2,
450,
1620,
9,
288,
372,
398,
862,
26,
288,
5128,
275,
291,
14,
919,
7561,
59,
2700,
61,
267,
871,
4067,
26,
288,
870,
480,
6587,
104,
164,
18304,
22445,
450,
83,
2,
450,
5448,
9,
288,
372,
398,
7748,
14,
2585,
8,
6101,
9,
5493,
347,
1720,
63,
10589,
334,
277,
304,
267,
870,
480,
10589,
531,
267,
870,
480,
14333,
223,
22914,
531,
272,
347,
886,
63,
10589,
334,
277,
12,
1004,
304,
267,
4458,
342,
339,
347,
1720,
63,
354,
334,
277,
304,
267,
870,
480,
354,
359,
32,
21434,
19012,
109,
12523,
267,
870,
480,
14082,
123,
27029,
8400,
227,
19451,
234,
21434,
19012,
109,
20061,
165,
234,
99,
163,
111,
95,
20916,
22843,
239,
25439,
250,
12356,
6812,
123,
29875,
119,
22918,
242,
27284,
21434,
19012,
109,
531,
272,
347,
886,
63,
354,
334,
277,
12,
536,
304,
267,
340,
822,
8,
354,
14,
1913,
1012,
508,
378,
26,
288,
870,
8,
277,
14,
42,
16603,
14,
985,
9,
267,
587,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1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ansible/modules/cloud/amazon/aws_api_gateway.py
|
38
|
11659
|
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: aws_api_gateway
short_description: Manage AWS API Gateway APIs
description:
- Allows for the management of API Gateway APIs
- Normally you should give the api_id since there is no other
stable guaranteed unique identifier for the API. If you do
not give api_id then a new API will be create each time
this is run.
- Beware that there are very hard limits on the rate that
you can call API Gateway's REST API. You may need to patch
your boto. See https://github.com/boto/boto3/issues/876
and discuss with your AWS rep.
- swagger_file and swagger_text are passed directly on to AWS
transparently whilst swagger_dict is an ansible dict which is
converted to JSON before the API definitions are uploaded.
version_added: '2.4'
requirements: [ boto3 ]
options:
api_id:
description:
- The ID of the API you want to manage.
state:
description:
- NOT IMPLEMENTED Create or delete API - currently we always create.
default: present
choices: [ 'present', 'absent' ]
swagger_file:
description:
- JSON or YAML file containing swagger definitions for API.
Exactly one of swagger_file, swagger_text or swagger_dict must
be present.
swagger_text:
description:
- Swagger definitions for API in JSON or YAML as a string direct
from playbook.
swagger_dict:
description:
- Swagger definitions API ansible dictionary which will be
converted to JSON and uploaded.
stage:
description:
- The name of the stage the API should be deployed to.
deploy_desc:
description:
- Description of the deployment - recorded and visible in the
AWS console.
default: Automatic deployment by Ansible.
author:
- 'Michael De La Rue (@mikedlr)'
extends_documentation_fragment:
- aws
- ec2
notes:
- A future version of this module will probably use tags or another
ID so that an API can be create only once.
- As an early work around an intermediate version will probably do
the same using a tag embedded in the API name.
'''
EXAMPLES = '''
# Update API resources for development
- name: update API
aws_api_gateway:
api_id: 'abc123321cba'
state: present
swagger_file: my_api.yml
# update definitions and deploy API to production
- name: deploy API
aws_api_gateway:
api_id: 'abc123321cba'
state: present
swagger_file: my_api.yml
stage: production
deploy_desc: Make auth fix available.
'''
RETURN = '''
output:
description: the data returned by put_restapi in boto3
returned: success
type: dict
sample:
'data':
{
"id": "abc123321cba",
"name": "MY REST API",
"createdDate": 1484233401
}
'''
import json
try:
import botocore
HAS_BOTOCORE = True
except ImportError:
HAS_BOTOCORE = False
from ansible.module_utils.basic import AnsibleModule, traceback
from ansible.module_utils.ec2 import (AWSRetry, HAS_BOTO3, ec2_argument_spec, get_aws_connection_info,
boto3_conn, camel_dict_to_snake_dict)
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(
dict(
api_id=dict(type='str', required=False),
state=dict(type='str', default='present', choices=['present', 'absent']),
swagger_file=dict(type='path', default=None, aliases=['src', 'api_file']),
swagger_dict=dict(type='json', default=None),
swagger_text=dict(type='str', default=None),
stage=dict(type='str', default=None),
deploy_desc=dict(type='str', default="Automatic deployment by Ansible."),
)
)
mutually_exclusive = [['swagger_file', 'swagger_dict', 'swagger_text']] # noqa: F841
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False,
mutually_exclusive=mutually_exclusive)
api_id = module.params.get('api_id')
state = module.params.get('state') # noqa: F841
swagger_file = module.params.get('swagger_file')
swagger_dict = module.params.get('swagger_dict')
swagger_text = module.params.get('swagger_text')
stage = module.params.get('stage')
deploy_desc = module.params.get('deploy_desc')
# check_mode = module.check_mode
changed = False
if not HAS_BOTO3:
module.fail_json(msg='Python module "boto3" is missing, please install boto3')
if not HAS_BOTOCORE:
module.fail_json(msg='Python module "botocore" is missing, please install it')
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
try:
client = boto3_conn(module, conn_type='client', resource='apigateway',
region=region, endpoint=ec2_url, **aws_connect_kwargs)
except botocore.exceptions.NoRegionError:
module.fail_json(msg="Region must be specified as a parameter, in "
"AWS_DEFAULT_REGION environment variable or in boto configuration file")
except (botocore.exceptions.ValidationError, botocore.exceptions.ClientError) as e:
fail_json_aws(module, e, msg="connecting to AWS")
changed = True # for now it will stay that way until we can sometimes avoid change
conf_res = None
dep_res = None
del_res = None
if state == "present":
if api_id is None:
api_id = create_empty_api(module, client)
api_data = get_api_definitions(module, swagger_file=swagger_file,
swagger_dict=swagger_dict, swagger_text=swagger_text)
conf_res, dep_res = ensure_api_in_correct_state(module, client, api_id=api_id,
api_data=api_data, stage=stage,
deploy_desc=deploy_desc)
if state == "absent":
del_res = delete_rest_api(module, client, api_id)
exit_args = {"changed": changed, "api_id": api_id}
if conf_res is not None:
exit_args['configure_response'] = camel_dict_to_snake_dict(conf_res)
if dep_res is not None:
exit_args['deploy_response'] = camel_dict_to_snake_dict(dep_res)
if del_res is not None:
exit_args['delete_response'] = camel_dict_to_snake_dict(del_res)
module.exit_json(**exit_args)
def get_api_definitions(module, swagger_file=None, swagger_dict=None, swagger_text=None):
apidata = None
if swagger_file is not None:
try:
with open(swagger_file) as f:
apidata = f.read()
except OSError as e:
msg = "Failed trying to read swagger file {}: {}".format(str(swagger_file), str(e))
module.fail_json(msg=msg, exception=traceback.format_exc())
if swagger_dict is not None:
apidata = json.dumps(swagger_dict)
if swagger_text is not None:
apidata = swagger_text
if apidata is None:
module.fail_json(msg='module error - failed to get API data')
return apidata
def create_empty_api(module, client):
"""
creates a new empty API ready to be configured. The description is
temporarily set to show the API as incomplete but should be
updated when the API is configured.
"""
desc = "Incomplete API creation by ansible aws_api_gateway module"
try:
awsret = create_api(client, name="ansible-temp-api", description=desc)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
fail_json_aws(module, e, msg="creating API")
return awsret["id"]
def delete_rest_api(module, client, api_id):
"""
creates a new empty API ready to be configured. The description is
temporarily set to show the API as incomplete but should be
updated when the API is configured.
"""
try:
delete_response = delete_api(client, api_id=api_id)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
fail_json_aws(module, e, msg="deleting API {}".format(api_id))
return delete_response
def ensure_api_in_correct_state(module, client, api_id=None, api_data=None, stage=None,
deploy_desc=None):
"""Make sure that we have the API configured and deployed as instructed.
This function first configures the API correctly uploading the
swagger definitions and then deploys those. Configuration and
deployment should be closely tied because there is only one set of
definitions so if we stop, they may be updated by someone else and
then we deploy the wrong configuration.
"""
configure_response = None
try:
configure_response = configure_api(client, api_data=api_data, api_id=api_id)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
fail_json_aws(module, e, msg="configuring API {}".format(api_id))
deploy_response = None
if stage:
try:
deploy_response = create_deployment(client, api_id=api_id, stage=stage,
description=deploy_desc)
except (botocore.exceptions.ClientError, botocore.exceptions.EndpointConnectionError) as e:
msg = "deploying api {} to stage {}".format(api_id, stage)
fail_json_aws(module, e, msg)
return configure_response, deploy_response
# There is a PR open to merge fail_json_aws this into the standard module code;
# see https://github.com/ansible/ansible/pull/23882
def fail_json_aws(module, exception, msg=None):
"""call fail_json with processed exception
function for converting exceptions thrown by AWS SDK modules,
botocore, boto3 and boto, into nice error messages.
"""
last_traceback = traceback.format_exc()
try:
except_msg = exception.message
except AttributeError:
except_msg = str(exception)
if msg is not None:
message = '{}: {}'.format(msg, except_msg)
else:
message = except_msg
try:
response = exception.response
except AttributeError:
response = None
if response is None:
module.fail_json(msg=message, traceback=last_traceback)
else:
module.fail_json(msg=message, traceback=last_traceback,
**camel_dict_to_snake_dict(response))
retry_params = {"tries": 10, "delay": 5, "backoff": 1.2}
@AWSRetry.backoff(**retry_params)
def create_api(client, name=None, description=None):
return client.create_rest_api(name="ansible-temp-api", description=description)
@AWSRetry.backoff(**retry_params)
def delete_api(client, api_id=None):
return client.delete_rest_api(restApiId=api_id)
@AWSRetry.backoff(**retry_params)
def configure_api(client, api_data=None, api_id=None, mode="overwrite"):
return client.put_rest_api(body=api_data, restApiId=api_id, mode=mode)
@AWSRetry.backoff(**retry_params)
def create_deployment(client, api_id=None, stage=None, description=None):
# we can also get None as an argument so we don't do this as a defult
return client.create_deployment(restApiId=api_id, stageName=stage, description=description)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
11488,
63,
1246,
63,
7019,
199,
3612,
63,
1802,
26,
14944,
10168,
3261,
27166,
15913,
199,
1802,
26,
1362,
446,
22819,
367,
314,
10041,
402,
3261,
27166,
15913,
1362,
446,
24573,
1265,
1077,
8120,
314,
2986,
63,
344,
3967,
2337,
365,
949,
1163,
2126,
17830,
17334,
3747,
5148,
367,
314,
3261,
14,
221,
982,
1265,
886,
2126,
440,
8120,
2986,
63,
344,
2066,
282,
892,
3261,
911,
506,
1218,
1924,
900,
2126,
642,
365,
1255,
14,
1362,
446,
699,
546,
1530,
626,
2337,
787,
7437,
7508,
10976,
641,
314,
6634,
626,
2126,
1265,
883,
1240,
3261,
27166,
1159,
14880,
3261,
14,
221,
2047,
1443,
1929,
370,
3371,
2126,
2195,
6055,
14,
221,
1666,
4178,
921,
5031,
14,
957,
15,
10914,
15,
10914,
19,
15,
10115,
15,
14690,
2126,
436,
4339,
27678,
543,
2195,
10168,
1833,
14,
1362,
446,
5584,
16267,
63,
493,
436,
5584,
16267,
63,
505,
787,
3032,
5370,
641,
370,
10168,
2126,
17265,
590,
704,
382,
270,
5584,
16267,
63,
807,
365,
376,
3242,
1211,
1314,
365,
2126,
6702,
370,
4840,
2544,
314,
3261,
10269,
787,
14238,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
20,
7,
199,
7538,
26,
359,
6055,
19,
1622,
199,
1419,
26,
523,
2986,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
2870,
402,
314,
3261,
1265,
2934,
370,
9635,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
2845,
5025,
10320,
1149,
2790,
503,
3145,
3261,
446,
5544,
781,
3544,
1218,
14,
272,
849,
26,
3451,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
523,
5584,
16267,
63,
493,
26,
272,
1369,
26,
489,
446,
4840,
503,
18916,
570,
3035,
5584,
16267,
10269,
367,
3261,
14,
267,
1316,
2442,
590,
1373,
402,
5584,
16267,
63,
493,
12,
5584,
16267,
63,
505,
503,
5584,
16267,
63,
807,
1471,
267,
506,
3451,
14,
523,
5584,
16267,
63,
505,
26,
272,
1369,
26,
489,
446,
16666,
16267,
10269,
367,
3261,
315,
4840,
503,
18916,
465,
282,
1059,
4125,
267,
687,
15695,
14,
523,
5584,
16267,
63,
807,
26,
272,
1369,
26,
489,
446,
16666,
16267,
10269,
3261,
3242,
2600,
1314,
911,
506,
267,
6702,
370,
4840,
436,
14238,
14,
523,
9546,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
9546,
314,
3261,
1077,
506,
26181,
370,
14,
523,
12287,
63,
3257,
26,
272,
1369,
26,
489,
446,
11994,
402,
314,
14295,
446,
18894,
436,
8917,
315,
314,
267,
10168,
8559,
14,
272,
849,
26,
9195,
3889,
14295,
701,
2622,
14,
199,
2502,
26,
272,
446,
283,
45,
11781,
1487,
7964,
820,
310,
8593,
2664,
25503,
7493,
3171,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
5983,
26,
2043,
446,
437,
6466,
1015,
402,
642,
859,
911,
8646,
675,
3762,
503,
4573,
1362,
2870,
880,
626,
376,
3261,
883,
506,
1218,
1454,
5403,
14,
2043,
446,
3709,
376,
14670,
1736,
6818,
376,
13197,
1015,
911,
8646,
886,
1362,
314,
2011,
1808,
282,
1947,
12169,
315,
314,
3261,
536,
14,
199,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
6162,
3261,
5944,
367,
16367,
199,
13,
536,
26,
1678,
3261,
523,
11488,
63,
1246,
63,
7019,
26,
272,
2986,
63,
344,
26,
283,
3175,
4288,
12638,
28995,
7,
272,
1174,
26,
3451,
272,
5584,
16267,
63,
493,
26,
3002,
63,
1246,
14,
11714,
199,
199,
3,
1678,
10269,
436,
12287,
3261,
370,
9920,
199,
13,
536,
26,
12287,
3261,
523,
11488,
63,
1246,
63,
7019,
26,
272,
2986,
63,
344,
26,
283,
3175,
4288,
12638,
28995,
7,
272,
1174,
26,
3451,
272,
5584,
16267,
63,
493,
26,
3002,
63,
1246,
14,
11714,
272,
9546,
26,
9920,
272,
12287,
63,
3257,
26,
4155,
1790,
5325,
2808,
14,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1199,
26,
523,
1369,
26,
314,
666,
2138,
701,
5324,
63,
3911,
1246,
315,
6055,
19,
523,
2138,
26,
3182,
523,
730,
26,
1211,
523,
2690,
26,
272,
283,
576,
356,
489,
469,
881,
298,
344,
582,
298,
3175,
4288,
12638,
28995,
401,
881,
298,
354,
582,
298,
12339,
14880,
3261,
401,
881,
298,
3966,
2506,
582,
4329,
1349,
1789,
1082,
614,
489,
789,
199,
2344,
199,
199,
646,
2022,
199,
199,
893,
26,
272,
492,
21199,
272,
7509,
63,
11372,
21137,
5788,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
11372,
21137,
5788,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
12,
5190,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
334,
13226,
12989,
12,
7509,
63,
21373,
19,
12,
7062,
18,
63,
2094,
63,
1650,
12,
664,
63,
7231,
63,
2105,
63,
815,
12,
4228,
6055,
19,
63,
1631,
12,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
7062,
18,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
2986,
63,
344,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
797,
395,
288,
1174,
29,
807,
8,
466,
534,
495,
297,
849,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
3815,
288,
5584,
16267,
63,
493,
29,
807,
8,
466,
534,
515,
297,
849,
29,
403,
12,
5481,
2968,
2164,
297,
283,
1246,
63,
493,
3815,
288,
5584,
16267,
63,
807,
29,
807,
8,
466,
534,
1001,
297,
849,
29,
403,
395,
288,
5584,
16267,
63,
505,
29,
807,
8,
466,
534,
495,
297,
849,
29,
403,
395,
288,
9546,
29,
807,
8,
466,
534,
495,
297,
849,
29,
403
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
11488,
63,
1246,
63,
7019,
199,
3612,
63,
1802,
26,
14944,
10168,
3261,
27166,
15913,
199,
1802,
26,
1362,
446,
22819,
367,
314,
10041,
402,
3261,
27166,
15913,
1362,
446,
24573,
1265,
1077,
8120,
314,
2986,
63,
344,
3967,
2337,
365,
949,
1163,
2126,
17830,
17334,
3747,
5148,
367,
314,
3261,
14,
221,
982,
1265,
886,
2126,
440,
8120,
2986,
63,
344,
2066,
282,
892,
3261,
911,
506,
1218,
1924,
900,
2126,
642,
365,
1255,
14,
1362,
446,
699,
546,
1530,
626,
2337,
787,
7437,
7508,
10976,
641,
314,
6634,
626,
2126,
1265,
883,
1240,
3261,
27166,
1159,
14880,
3261,
14,
221,
2047,
1443,
1929,
370,
3371,
2126,
2195,
6055,
14,
221,
1666,
4178,
921,
5031,
14,
957,
15,
10914,
15,
10914,
19,
15,
10115,
15,
14690,
2126,
436,
4339,
27678,
543,
2195,
10168,
1833,
14,
1362,
446,
5584,
16267,
63,
493,
436,
5584,
16267,
63,
505,
787,
3032,
5370,
641,
370,
10168,
2126,
17265,
590,
704,
382,
270,
5584,
16267,
63,
807,
365,
376,
3242,
1211,
1314,
365,
2126,
6702,
370,
4840,
2544,
314,
3261,
10269,
787,
14238,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
20,
7,
199,
7538,
26,
359,
6055,
19,
1622,
199,
1419,
26,
523,
2986,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
2870,
402,
314,
3261,
1265,
2934,
370,
9635,
14,
523,
1174,
26,
272,
1369,
26,
489,
446,
2845,
5025,
10320,
1149,
2790,
503,
3145,
3261,
446,
5544,
781,
3544,
1218,
14,
272,
849,
26,
3451,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
523,
5584,
16267,
63,
493,
26,
272,
1369,
26,
489,
446,
4840,
503,
18916,
570,
3035,
5584,
16267,
10269,
367,
3261,
14,
267,
1316,
2442,
590,
1373,
402,
5584,
16267,
63,
493,
12,
5584,
16267,
63,
505,
503,
5584,
16267,
63,
807,
1471,
267,
506,
3451,
14,
523,
5584,
16267,
63,
505,
26,
272,
1369,
26,
489,
446,
16666,
16267,
10269,
367,
3261,
315,
4840,
503,
18916,
465,
282,
1059,
4125,
267,
687,
15695,
14,
523,
5584,
16267,
63,
807,
26,
272,
1369,
26,
489,
446,
16666,
16267,
10269,
3261,
3242,
2600,
1314,
911,
506,
267,
6702,
370,
4840,
436,
14238,
14,
523,
9546,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
9546,
314,
3261,
1077,
506,
26181,
370,
14,
523,
12287,
63,
3257,
26,
272,
1369,
26,
489,
446,
11994,
402,
314,
14295,
446,
18894,
436,
8917,
315,
314,
267,
10168,
8559,
14,
272,
849,
26,
9195,
3889,
14295,
701,
2622,
14,
199,
2502,
26,
272,
446,
283,
45,
11781,
1487,
7964,
820,
310,
8593,
2664,
25503,
7493,
3171,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
5983,
26,
2043,
446,
437,
6466,
1015,
402,
642,
859,
911,
8646,
675,
3762,
503,
4573,
1362,
2870,
880,
626,
376,
3261,
883,
506,
1218,
1454,
5403,
14,
2043,
446,
3709,
376,
14670,
1736,
6818,
376,
13197,
1015,
911,
8646,
886,
1362,
314,
2011,
1808,
282,
1947,
12169,
315,
314,
3261,
536,
14,
199,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
6162,
3261,
5944,
367,
16367,
199,
13,
536,
26,
1678,
3261,
523,
11488,
63,
1246,
63,
7019,
26,
272,
2986,
63,
344,
26,
283,
3175,
4288,
12638,
28995,
7,
272,
1174,
26,
3451,
272,
5584,
16267,
63,
493,
26,
3002,
63,
1246,
14,
11714,
199,
199,
3,
1678,
10269,
436,
12287,
3261,
370,
9920,
199,
13,
536,
26,
12287,
3261,
523,
11488,
63,
1246,
63,
7019,
26,
272,
2986,
63,
344,
26,
283,
3175,
4288,
12638,
28995,
7,
272,
1174,
26,
3451,
272,
5584,
16267,
63,
493,
26,
3002,
63,
1246,
14,
11714,
272,
9546,
26,
9920,
272,
12287,
63,
3257,
26,
4155,
1790,
5325,
2808,
14,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1199,
26,
523,
1369,
26,
314,
666,
2138,
701,
5324,
63,
3911,
1246,
315,
6055,
19,
523,
2138,
26,
3182,
523,
730,
26,
1211,
523,
2690,
26,
272,
283,
576,
356,
489,
469,
881,
298,
344,
582,
298,
3175,
4288,
12638,
28995,
401,
881,
298,
354,
582,
298,
12339,
14880,
3261,
401,
881,
298,
3966,
2506,
582,
4329,
1349,
1789,
1082,
614,
489,
789,
199,
2344,
199,
199,
646,
2022,
199,
199,
893,
26,
272,
492,
21199,
272,
7509,
63,
11372,
21137,
5788,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
11372,
21137,
5788,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
12,
5190,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
334,
13226,
12989,
12,
7509,
63,
21373,
19,
12,
7062,
18,
63,
2094,
63,
1650,
12,
664,
63,
7231,
63,
2105,
63,
815,
12,
4228,
6055,
19,
63,
1631,
12,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
7062,
18,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
2986,
63,
344,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
797,
395,
288,
1174,
29,
807,
8,
466,
534,
495,
297,
849,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
3815,
288,
5584,
16267,
63,
493,
29,
807,
8,
466,
534,
515,
297,
849,
29,
403,
12,
5481,
2968,
2164,
297,
283,
1246,
63,
493,
3815,
288,
5584,
16267,
63,
807,
29,
807,
8,
466,
534,
1001,
297,
849,
29,
403,
395,
288,
5584,
16267,
63,
505,
29,
807,
8,
466,
534,
495,
297,
849,
29,
403,
395,
288,
9546,
29,
807,
8,
466,
534,
495,
297,
849,
29,
403,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
killbug2004/volatility
|
volatility/plugins/linux/dmesg.py
|
54
|
3132
|
# Volatility
# Copyright (C) 2007-2013 Volatility Foundation
#
# This file is part of Volatility.
#
# Volatility 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.
#
# Volatility 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 Volatility. If not, see <http://www.gnu.org/licenses/>.
#
"""
@author: Andrew Case
@license: GNU General Public License 2.0
@contact: atcuno@gmail.com
@organization:
"""
import volatility.obj as obj
import volatility.plugins.linux.common as linux_common
class linux_dmesg(linux_common.AbstractLinuxCommand):
"""Gather dmesg buffer"""
def _get_log_info(self):
ptr_addr = self.addr_space.profile.get_symbol("log_buf")
log_buf_addr = obj.Object("unsigned long", offset = ptr_addr, vm = self.addr_space)
log_buf_len = obj.Object("int", self.addr_space.profile.get_symbol("log_buf_len"), vm = self.addr_space)
return (log_buf_addr, log_buf_len)
# pre 3.x
def _pre_3(self, buf_addr, buf_len):
return obj.Object("String", offset = buf_addr, vm = self.addr_space, length = buf_len)
def _ver_3(self, buf_addr, buf_len):
'''
During 3.x, the kernel switched the kernel debug buffer from just a big char array to the variable now
holding variable sized records tracked by inline 'log' structures
We deal with this by walking all the logs and building the buffer up and then returning it
This produces the same results as the old way
'''
ret = ""
size_of_log = self.profile.get_obj_size("log")
cur_addr = buf_addr
end_addr = buf_addr + buf_len
log = obj.Object("log", offset = cur_addr, vm = self.addr_space)
cur_len = log.len
while cur_addr < end_addr and cur_len != 0:
msg_len = log.text_len
cur_ts = log.ts_nsec
buf = obj.Object("String", offset = cur_addr + size_of_log, vm = self.addr_space, length = msg_len)
ret = ret + "[{0}.{1}] {2}\n".format(cur_ts, cur_ts / 1000000000, buf)
cur_addr = cur_addr + cur_len
log = obj.Object("log", offset = cur_addr, vm = self.addr_space)
cur_len = log.len
return ret
def calculate(self):
linux_common.set_plugin_members(self)
(log_buf_addr, log_buf_len) = self._get_log_info()
if self.profile.has_type("log") and self.profile.obj_has_member("log", "ts_nsec"):
yield self._ver_3(log_buf_addr, log_buf_len)
else:
yield self._pre_3(log_buf_addr, log_buf_len)
def render_text(self, outfd, data):
for buf in data:
outfd.write("{0:s}\n".format(buf))
|
gpl-2.0
|
[
3,
28367,
199,
3,
1898,
334,
35,
9,
10219,
13,
6965,
28367,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28367,
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,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
624,
199,
32,
2502,
26,
755,
6061,
5257,
12425,
199,
32,
1682,
26,
420,
1664,
1696,
1684,
844,
499,
14,
16,
199,
32,
7811,
26,
420,
737,
67,
324,
79,
32,
6799,
14,
957,
199,
32,
9071,
26,
221,
199,
624,
199,
199,
646,
5236,
18783,
14,
1113,
465,
1559,
199,
646,
5236,
18783,
14,
5265,
14,
5135,
14,
2330,
465,
18369,
63,
2330,
199,
199,
533,
18369,
63,
12673,
8,
5135,
63,
2330,
14,
8458,
14091,
3110,
304,
272,
408,
39,
7404,
30396,
3335,
624,
339,
347,
485,
362,
63,
793,
63,
815,
8,
277,
304,
398,
12448,
63,
2697,
275,
291,
14,
2697,
63,
2638,
14,
2913,
14,
362,
63,
5155,
480,
793,
63,
1436,
531,
267,
943,
63,
1436,
63,
2697,
275,
1559,
14,
1692,
480,
2244,
1846,
401,
3268,
275,
12448,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
9,
267,
943,
63,
1436,
63,
552,
275,
1559,
14,
1692,
480,
442,
401,
291,
14,
2697,
63,
2638,
14,
2913,
14,
362,
63,
5155,
480,
793,
63,
1436,
63,
552,
1288,
4169,
275,
291,
14,
2697,
63,
2638,
9,
398,
372,
334,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
339,
327,
876,
650,
14,
88,
272,
347,
485,
657,
63,
19,
8,
277,
12,
4123,
63,
2697,
12,
4123,
63,
552,
304,
398,
372,
1559,
14,
1692,
480,
1558,
401,
3268,
275,
4123,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
12,
2582,
275,
4123,
63,
552,
9,
339,
347,
485,
422,
63,
19,
8,
277,
12,
4123,
63,
2697,
12,
4123,
63,
552,
304,
267,
1449,
267,
577,
4039,
650,
14,
88,
12,
314,
5114,
308,
28986,
314,
5114,
3105,
3335,
687,
2951,
282,
7282,
1495,
1625,
370,
314,
1750,
3063,
267,
17573,
1750,
308,
1759,
5767,
23268,
701,
8308,
283,
793,
7,
13955,
267,
2136,
7962,
543,
642,
701,
12778,
316,
1006,
314,
9610,
436,
10015,
314,
3335,
1536,
436,
2066,
8152,
652,
267,
961,
16904,
314,
2011,
2058,
465,
314,
2269,
4340,
267,
1449,
398,
2203,
275,
3087,
398,
1568,
63,
1618,
63,
793,
275,
291,
14,
2913,
14,
362,
63,
1113,
63,
890,
480,
793,
531,
398,
1094,
63,
2697,
275,
4123,
63,
2697,
267,
1284,
63,
2697,
275,
4123,
63,
2697,
435,
4123,
63,
552,
398,
943,
275,
1559,
14,
1692,
480,
793,
401,
3268,
275,
1094,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
9,
267,
1094,
63,
552,
275,
943,
14,
552,
398,
1830,
1094,
63,
2697,
665,
1284,
63,
2697,
436,
1094,
63,
552,
1137,
378,
26,
953,
1499,
63,
552,
275,
943,
14,
505,
63,
552,
288,
1094,
63,
1086,
275,
943,
14,
1086,
63,
78,
3321,
953,
4123,
275,
1559,
14,
1692,
480,
1558,
401,
3268,
275,
1094,
63,
2697,
435,
1568,
63,
1618,
63,
793,
12,
4169,
275,
291,
14,
2697,
63,
2638,
12,
2582,
275,
1499,
63,
552,
9,
953,
2203,
275,
2203,
435,
7369,
91,
16,
26944,
17,
11049,
469,
18,
4988,
78,
1674,
908,
8,
895,
63,
1086,
12,
1094,
63,
1086,
1182,
413,
25464,
12,
4123,
9,
953,
1094,
63,
2697,
275,
1094,
63,
2697,
435,
1094,
63,
552,
953,
943,
275,
1559,
14,
1692,
480,
793,
401,
3268,
275,
1094,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
9,
288,
1094,
63,
552,
275,
943,
14,
552,
398,
372,
2203,
339,
347,
8671,
8,
277,
304,
267,
18369,
63,
2330,
14,
409,
63,
2718,
63,
6334,
8,
277,
9,
267,
334,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
275,
291,
423,
362,
63,
793,
63,
815,
342,
398,
340,
291,
14,
2913,
14,
1989,
63,
466,
480,
793,
531,
436,
291,
14,
2913,
14,
1113,
63,
1989,
63,
1114,
480,
793,
401,
298,
1086,
63,
78,
3321,
2349,
288,
1995,
291,
423,
422,
63,
19,
8,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
398,
587,
26,
288,
1995,
291,
423,
657,
63,
19,
8,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
339,
347,
3795,
63,
505,
8,
277,
12,
734,
2592,
12,
666,
304,
398,
367,
4123,
315,
666,
26,
288,
734,
2592,
14,
952,
13076,
16,
26,
83,
4988,
78,
1674,
908,
8,
1436,
430,
28154,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
28367,
199,
3,
1898,
334,
35,
9,
10219,
13,
6965,
28367,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28367,
14,
199,
3,
199,
3,
28367,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28367,
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,
28367,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
624,
199,
32,
2502,
26,
755,
6061,
5257,
12425,
199,
32,
1682,
26,
420,
1664,
1696,
1684,
844,
499,
14,
16,
199,
32,
7811,
26,
420,
737,
67,
324,
79,
32,
6799,
14,
957,
199,
32,
9071,
26,
221,
199,
624,
199,
199,
646,
5236,
18783,
14,
1113,
465,
1559,
199,
646,
5236,
18783,
14,
5265,
14,
5135,
14,
2330,
465,
18369,
63,
2330,
199,
199,
533,
18369,
63,
12673,
8,
5135,
63,
2330,
14,
8458,
14091,
3110,
304,
272,
408,
39,
7404,
30396,
3335,
624,
339,
347,
485,
362,
63,
793,
63,
815,
8,
277,
304,
398,
12448,
63,
2697,
275,
291,
14,
2697,
63,
2638,
14,
2913,
14,
362,
63,
5155,
480,
793,
63,
1436,
531,
267,
943,
63,
1436,
63,
2697,
275,
1559,
14,
1692,
480,
2244,
1846,
401,
3268,
275,
12448,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
9,
267,
943,
63,
1436,
63,
552,
275,
1559,
14,
1692,
480,
442,
401,
291,
14,
2697,
63,
2638,
14,
2913,
14,
362,
63,
5155,
480,
793,
63,
1436,
63,
552,
1288,
4169,
275,
291,
14,
2697,
63,
2638,
9,
398,
372,
334,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
339,
327,
876,
650,
14,
88,
272,
347,
485,
657,
63,
19,
8,
277,
12,
4123,
63,
2697,
12,
4123,
63,
552,
304,
398,
372,
1559,
14,
1692,
480,
1558,
401,
3268,
275,
4123,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
12,
2582,
275,
4123,
63,
552,
9,
339,
347,
485,
422,
63,
19,
8,
277,
12,
4123,
63,
2697,
12,
4123,
63,
552,
304,
267,
1449,
267,
577,
4039,
650,
14,
88,
12,
314,
5114,
308,
28986,
314,
5114,
3105,
3335,
687,
2951,
282,
7282,
1495,
1625,
370,
314,
1750,
3063,
267,
17573,
1750,
308,
1759,
5767,
23268,
701,
8308,
283,
793,
7,
13955,
267,
2136,
7962,
543,
642,
701,
12778,
316,
1006,
314,
9610,
436,
10015,
314,
3335,
1536,
436,
2066,
8152,
652,
267,
961,
16904,
314,
2011,
2058,
465,
314,
2269,
4340,
267,
1449,
398,
2203,
275,
3087,
398,
1568,
63,
1618,
63,
793,
275,
291,
14,
2913,
14,
362,
63,
1113,
63,
890,
480,
793,
531,
398,
1094,
63,
2697,
275,
4123,
63,
2697,
267,
1284,
63,
2697,
275,
4123,
63,
2697,
435,
4123,
63,
552,
398,
943,
275,
1559,
14,
1692,
480,
793,
401,
3268,
275,
1094,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
9,
267,
1094,
63,
552,
275,
943,
14,
552,
398,
1830,
1094,
63,
2697,
665,
1284,
63,
2697,
436,
1094,
63,
552,
1137,
378,
26,
953,
1499,
63,
552,
275,
943,
14,
505,
63,
552,
288,
1094,
63,
1086,
275,
943,
14,
1086,
63,
78,
3321,
953,
4123,
275,
1559,
14,
1692,
480,
1558,
401,
3268,
275,
1094,
63,
2697,
435,
1568,
63,
1618,
63,
793,
12,
4169,
275,
291,
14,
2697,
63,
2638,
12,
2582,
275,
1499,
63,
552,
9,
953,
2203,
275,
2203,
435,
7369,
91,
16,
26944,
17,
11049,
469,
18,
4988,
78,
1674,
908,
8,
895,
63,
1086,
12,
1094,
63,
1086,
1182,
413,
25464,
12,
4123,
9,
953,
1094,
63,
2697,
275,
1094,
63,
2697,
435,
1094,
63,
552,
953,
943,
275,
1559,
14,
1692,
480,
793,
401,
3268,
275,
1094,
63,
2697,
12,
4169,
275,
291,
14,
2697,
63,
2638,
9,
288,
1094,
63,
552,
275,
943,
14,
552,
398,
372,
2203,
339,
347,
8671,
8,
277,
304,
267,
18369,
63,
2330,
14,
409,
63,
2718,
63,
6334,
8,
277,
9,
267,
334,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
275,
291,
423,
362,
63,
793,
63,
815,
342,
398,
340,
291,
14,
2913,
14,
1989,
63,
466,
480,
793,
531,
436,
291,
14,
2913,
14,
1113,
63,
1989,
63,
1114,
480,
793,
401,
298,
1086,
63,
78,
3321,
2349,
288,
1995,
291,
423,
422,
63,
19,
8,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
398,
587,
26,
288,
1995,
291,
423,
657,
63,
19,
8,
793,
63,
1436,
63,
2697,
12,
943,
63,
1436,
63,
552,
9,
339,
347,
3795,
63,
505,
8,
277,
12,
734,
2592,
12,
666,
304,
398,
367,
4123,
315,
666,
26,
288,
734,
2592,
14,
952,
13076,
16,
26,
83,
4988,
78,
1674,
908,
8,
1436,
430,
28154,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Vizerai/grpc
|
src/python/grpcio_tests/tests/qps/client_runner.py
|
25
|
2685
|
# Copyright 2016 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.
"""Defines behavior for WHEN clients send requests.
Each client exposes a non-blocking send_request() method that the
ClientRunner invokes either periodically or in response to some event.
"""
import abc
import threading
import time
class ClientRunner:
"""Abstract interface for sending requests from clients."""
__metaclass__ = abc.ABCMeta
def __init__(self, client):
self._client = client
@abc.abstractmethod
def start(self):
raise NotImplementedError()
@abc.abstractmethod
def stop(self):
raise NotImplementedError()
class OpenLoopClientRunner(ClientRunner):
def __init__(self, client, interval_generator):
super(OpenLoopClientRunner, self).__init__(client)
self._is_running = False
self._interval_generator = interval_generator
self._dispatch_thread = threading.Thread(
target=self._dispatch_requests, args=())
def start(self):
self._is_running = True
self._client.start()
self._dispatch_thread.start()
def stop(self):
self._is_running = False
self._client.stop()
self._dispatch_thread.join()
self._client = None
def _dispatch_requests(self):
while self._is_running:
self._client.send_request()
time.sleep(next(self._interval_generator))
class ClosedLoopClientRunner(ClientRunner):
def __init__(self, client, request_count):
super(ClosedLoopClientRunner, self).__init__(client)
self._is_running = False
self._request_count = request_count
# Send a new request on each response for closed loop
self._client.add_response_callback(self._send_request)
def start(self):
self._is_running = True
self._client.start()
for _ in xrange(self._request_count):
self._client.send_request()
def stop(self):
self._is_running = False
self._client.stop()
self._client = None
def _send_request(self, client, response_time):
if self._is_running:
client.send_request()
|
apache-2.0
|
[
3,
1898,
7800,
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,
23891,
5953,
367,
27802,
13431,
3222,
4145,
14,
199,
199,
22321,
1890,
444,
10553,
282,
2222,
13,
13091,
3222,
63,
1069,
342,
1083,
626,
314,
199,
3041,
7446,
29761,
1902,
18745,
1183,
503,
315,
1177,
370,
2005,
1566,
14,
199,
624,
199,
199,
646,
13022,
199,
646,
5796,
199,
646,
900,
421,
199,
533,
6810,
7446,
26,
272,
408,
8458,
3217,
367,
10209,
4145,
687,
13431,
1041,
339,
636,
6577,
363,
275,
13022,
14,
22254,
339,
347,
636,
826,
721,
277,
12,
1890,
304,
267,
291,
423,
1258,
275,
1890,
339,
768,
3175,
14,
10315,
272,
347,
1343,
8,
277,
304,
267,
746,
4279,
342,
339,
768,
3175,
14,
10315,
272,
347,
3631,
8,
277,
304,
267,
746,
4279,
342,
421,
199,
533,
3232,
7382,
3041,
7446,
8,
3041,
7446,
304,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
6252,
63,
4679,
304,
267,
1613,
8,
4299,
7382,
3041,
7446,
12,
291,
2843,
826,
721,
1258,
9,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
4284,
63,
4679,
275,
6252,
63,
4679,
267,
291,
423,
6052,
63,
2671,
275,
5796,
14,
4436,
8,
288,
1347,
29,
277,
423,
6052,
63,
6615,
12,
1249,
29,
1012,
339,
347,
1343,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
715,
267,
291,
423,
1258,
14,
928,
342,
267,
291,
423,
6052,
63,
2671,
14,
928,
342,
339,
347,
3631,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
1258,
14,
2379,
342,
267,
291,
423,
6052,
63,
2671,
14,
904,
342,
267,
291,
423,
1258,
275,
488,
339,
347,
485,
6052,
63,
6615,
8,
277,
304,
267,
1830,
291,
423,
374,
63,
5720,
26,
288,
291,
423,
1258,
14,
2254,
63,
1069,
342,
288,
900,
14,
4532,
8,
2184,
8,
277,
423,
4284,
63,
4679,
430,
421,
199,
533,
5980,
939,
7382,
3041,
7446,
8,
3041,
7446,
304,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
1056,
63,
835,
304,
267,
1613,
8,
15190,
7382,
3041,
7446,
12,
291,
2843,
826,
721,
1258,
9,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
1069,
63,
835,
275,
1056,
63,
835,
267,
327,
10217,
282,
892,
1056,
641,
1924,
1177,
367,
6876,
4438,
267,
291,
423,
1258,
14,
525,
63,
1310,
63,
3058,
8,
277,
423,
2254,
63,
1069,
9,
339,
347,
1343,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
715,
267,
291,
423,
1258,
14,
928,
342,
267,
367,
485,
315,
4945,
8,
277,
423,
1069,
63,
835,
304,
288,
291,
423,
1258,
14,
2254,
63,
1069,
342,
339,
347,
3631,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
1258,
14,
2379,
342,
267,
291,
423,
1258,
275,
488,
339,
347,
485,
2254,
63,
1069,
8,
277,
12,
1890,
12,
1177,
63,
521,
304,
267,
340,
291,
423,
374,
63,
5720,
26,
288,
1890,
14,
2254,
63,
1069,
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
] |
[
1898,
7800,
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,
23891,
5953,
367,
27802,
13431,
3222,
4145,
14,
199,
199,
22321,
1890,
444,
10553,
282,
2222,
13,
13091,
3222,
63,
1069,
342,
1083,
626,
314,
199,
3041,
7446,
29761,
1902,
18745,
1183,
503,
315,
1177,
370,
2005,
1566,
14,
199,
624,
199,
199,
646,
13022,
199,
646,
5796,
199,
646,
900,
421,
199,
533,
6810,
7446,
26,
272,
408,
8458,
3217,
367,
10209,
4145,
687,
13431,
1041,
339,
636,
6577,
363,
275,
13022,
14,
22254,
339,
347,
636,
826,
721,
277,
12,
1890,
304,
267,
291,
423,
1258,
275,
1890,
339,
768,
3175,
14,
10315,
272,
347,
1343,
8,
277,
304,
267,
746,
4279,
342,
339,
768,
3175,
14,
10315,
272,
347,
3631,
8,
277,
304,
267,
746,
4279,
342,
421,
199,
533,
3232,
7382,
3041,
7446,
8,
3041,
7446,
304,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
6252,
63,
4679,
304,
267,
1613,
8,
4299,
7382,
3041,
7446,
12,
291,
2843,
826,
721,
1258,
9,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
4284,
63,
4679,
275,
6252,
63,
4679,
267,
291,
423,
6052,
63,
2671,
275,
5796,
14,
4436,
8,
288,
1347,
29,
277,
423,
6052,
63,
6615,
12,
1249,
29,
1012,
339,
347,
1343,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
715,
267,
291,
423,
1258,
14,
928,
342,
267,
291,
423,
6052,
63,
2671,
14,
928,
342,
339,
347,
3631,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
1258,
14,
2379,
342,
267,
291,
423,
6052,
63,
2671,
14,
904,
342,
267,
291,
423,
1258,
275,
488,
339,
347,
485,
6052,
63,
6615,
8,
277,
304,
267,
1830,
291,
423,
374,
63,
5720,
26,
288,
291,
423,
1258,
14,
2254,
63,
1069,
342,
288,
900,
14,
4532,
8,
2184,
8,
277,
423,
4284,
63,
4679,
430,
421,
199,
533,
5980,
939,
7382,
3041,
7446,
8,
3041,
7446,
304,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
1056,
63,
835,
304,
267,
1613,
8,
15190,
7382,
3041,
7446,
12,
291,
2843,
826,
721,
1258,
9,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
1069,
63,
835,
275,
1056,
63,
835,
267,
327,
10217,
282,
892,
1056,
641,
1924,
1177,
367,
6876,
4438,
267,
291,
423,
1258,
14,
525,
63,
1310,
63,
3058,
8,
277,
423,
2254,
63,
1069,
9,
339,
347,
1343,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
715,
267,
291,
423,
1258,
14,
928,
342,
267,
367,
485,
315,
4945,
8,
277,
423,
1069,
63,
835,
304,
288,
291,
423,
1258,
14,
2254,
63,
1069,
342,
339,
347,
3631,
8,
277,
304,
267,
291,
423,
374,
63,
5720,
275,
756,
267,
291,
423,
1258,
14,
2379,
342,
267,
291,
423,
1258,
275,
488,
339,
347,
485,
2254,
63,
1069,
8,
277,
12,
1890,
12,
1177,
63,
521,
304,
267,
340,
291,
423,
374,
63,
5720,
26,
288,
1890,
14,
2254,
63,
1069,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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2014 Rackspace, 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 types
import mock
from oslo_config import cfg
from ironic.common import dhcp_factory
from ironic.common import exception
from ironic.common import image_service
from ironic.common import images
from ironic.common import raid
from ironic.common import states
from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils
from ironic.drivers.modules import agent
from ironic.drivers.modules import agent_base_vendor
from ironic.drivers.modules import agent_client
from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules import fake
from ironic.drivers.modules import pxe
from ironic.tests.unit.conductor import mgr_utils
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.objects import utils as object_utils
INSTANCE_INFO = db_utils.get_test_agent_instance_info()
DRIVER_INFO = db_utils.get_test_agent_driver_info()
DRIVER_INTERNAL_INFO = db_utils.get_test_agent_driver_internal_info()
CONF = cfg.CONF
class TestAgentMethods(db_base.DbTestCase):
def setUp(self):
super(TestAgentMethods, self).setUp()
self.node = object_utils.create_test_node(self.context,
driver='fake_agent')
dhcp_factory.DHCPFactory._dhcp_provider = None
@mock.patch.object(image_service, 'GlanceImageService', autospec=True)
def test_build_instance_info_for_deploy_glance_image(self, glance_mock):
i_info = self.node.instance_info
i_info['image_source'] = '733d1c44-a2ea-414b-aca7-69decf20d810'
driver_internal_info = self.node.driver_internal_info
driver_internal_info['is_whole_disk_image'] = True
self.node.driver_internal_info = driver_internal_info
self.node.instance_info = i_info
self.node.save()
image_info = {'checksum': 'aa', 'disk_format': 'qcow2',
'container_format': 'bare'}
glance_mock.return_value.show = mock.MagicMock(spec_set=[],
return_value=image_info)
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task:
agent.build_instance_info_for_deploy(task)
glance_mock.assert_called_once_with(version=2,
context=task.context)
glance_mock.return_value.show.assert_called_once_with(
self.node.instance_info['image_source'])
glance_mock.return_value.swift_temp_url.assert_called_once_with(
image_info)
@mock.patch.object(deploy_utils, 'parse_instance_info', autospec=True)
@mock.patch.object(image_service, 'GlanceImageService', autospec=True)
def test_build_instance_info_for_deploy_glance_partition_image(
self, glance_mock, parse_instance_info_mock):
i_info = self.node.instance_info
i_info['image_source'] = '733d1c44-a2ea-414b-aca7-69decf20d810'
i_info['kernel'] = '13ce5a56-1de3-4916-b8b2-be778645d003'
i_info['ramdisk'] = 'a5a370a8-1b39-433f-be63-2c7d708e4b4e'
i_info['root_gb'] = 5
i_info['swap_mb'] = 4
i_info['ephemeral_gb'] = 0
i_info['ephemeral_format'] = None
i_info['configdrive'] = 'configdrive'
driver_internal_info = self.node.driver_internal_info
driver_internal_info['is_whole_disk_image'] = False
self.node.driver_internal_info = driver_internal_info
self.node.instance_info = i_info
self.node.save()
image_info = {'checksum': 'aa', 'disk_format': 'qcow2',
'container_format': 'bare',
'properties': {'kernel_id': 'kernel',
'ramdisk_id': 'ramdisk'}}
glance_mock.return_value.show = mock.MagicMock(spec_set=[],
return_value=image_info)
glance_obj_mock = glance_mock.return_value
glance_obj_mock.swift_temp_url.return_value = 'temp-url'
parse_instance_info_mock.return_value = {'swap_mb': 4}
image_source = '733d1c44-a2ea-414b-aca7-69decf20d810'
expected_i_info = {'root_gb': 5,
'swap_mb': 4,
'ephemeral_gb': 0,
'ephemeral_format': None,
'configdrive': 'configdrive',
'image_source': image_source,
'image_url': 'temp-url',
'kernel': 'kernel',
'ramdisk': 'ramdisk',
'image_type': 'partition',
'image_checksum': 'aa',
'fake_password': 'fakepass',
'image_container_format': 'bare',
'image_disk_format': 'qcow2',
'foo': 'bar'}
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task:
info = agent.build_instance_info_for_deploy(task)
glance_mock.assert_called_once_with(version=2,
context=task.context)
glance_mock.return_value.show.assert_called_once_with(
self.node.instance_info['image_source'])
glance_mock.return_value.swift_temp_url.assert_called_once_with(
image_info)
image_type = task.node.instance_info.get('image_type')
self.assertEqual('partition', image_type)
self.assertEqual('kernel', info.get('kernel'))
self.assertEqual('ramdisk', info.get('ramdisk'))
self.assertEqual(expected_i_info, info)
parse_instance_info_mock.assert_called_once_with(task.node)
@mock.patch.object(image_service.HttpImageService, 'validate_href',
autospec=True)
def test_build_instance_info_for_deploy_nonglance_image(
self, validate_href_mock):
i_info = self.node.instance_info
driver_internal_info = self.node.driver_internal_info
i_info['image_source'] = 'http://image-ref'
i_info['image_checksum'] = 'aa'
i_info['root_gb'] = 10
i_info['image_checksum'] = 'aa'
driver_internal_info['is_whole_disk_image'] = True
self.node.instance_info = i_info
self.node.driver_internal_info = driver_internal_info
self.node.save()
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task:
info = agent.build_instance_info_for_deploy(task)
self.assertEqual(self.node.instance_info['image_source'],
info['image_url'])
validate_href_mock.assert_called_once_with(
mock.ANY, 'http://image-ref')
@mock.patch.object(deploy_utils, 'parse_instance_info', autospec=True)
@mock.patch.object(image_service.HttpImageService, 'validate_href',
autospec=True)
def test_build_instance_info_for_deploy_nonglance_partition_image(
self, validate_href_mock, parse_instance_info_mock):
i_info = self.node.instance_info
driver_internal_info = self.node.driver_internal_info
i_info['image_source'] = 'http://image-ref'
i_info['kernel'] = 'http://kernel-ref'
i_info['ramdisk'] = 'http://ramdisk-ref'
i_info['image_checksum'] = 'aa'
i_info['root_gb'] = 10
driver_internal_info['is_whole_disk_image'] = False
self.node.instance_info = i_info
self.node.driver_internal_info = driver_internal_info
self.node.save()
mgr_utils.mock_the_extension_manager(driver='fake_agent')
validate_href_mock.side_effect = ['http://image-ref',
'http://kernel-ref',
'http://ramdisk-ref']
parse_instance_info_mock.return_value = {'swap_mb': 5}
expected_i_info = {'image_source': 'http://image-ref',
'image_url': 'http://image-ref',
'image_type': 'partition',
'kernel': 'http://kernel-ref',
'ramdisk': 'http://ramdisk-ref',
'image_checksum': 'aa',
'root_gb': 10,
'swap_mb': 5,
'fake_password': 'fakepass',
'foo': 'bar'}
with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task:
info = agent.build_instance_info_for_deploy(task)
self.assertEqual(self.node.instance_info['image_source'],
info['image_url'])
validate_href_mock.assert_called_once_with(
mock.ANY, 'http://image-ref')
self.assertEqual('partition', info.get('image_type'))
self.assertEqual(expected_i_info, info)
parse_instance_info_mock.assert_called_once_with(task.node)
@mock.patch.object(image_service.HttpImageService, 'validate_href',
autospec=True)
def test_build_instance_info_for_deploy_nonsupported_image(
self, validate_href_mock):
validate_href_mock.side_effect = iter(
[exception.ImageRefValidationFailed(
image_href='file://img.qcow2', reason='fail')])
i_info = self.node.instance_info
i_info['image_source'] = 'file://img.qcow2'
i_info['image_checksum'] = 'aa'
self.node.instance_info = i_info
self.node.save()
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task:
self.assertRaises(exception.ImageRefValidationFailed,
agent.build_instance_info_for_deploy, task)
@mock.patch.object(images, 'image_show', autospec=True)
def test_check_image_size(self, show_mock):
show_mock.return_value = {
'size': 10 * 1024 * 1024,
'disk_format': 'qcow2',
}
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties['memory_mb'] = 10
agent.check_image_size(task, 'fake-image')
show_mock.assert_called_once_with(self.context, 'fake-image')
@mock.patch.object(images, 'image_show', autospec=True)
def test_check_image_size_without_memory_mb(self, show_mock):
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties.pop('memory_mb', None)
agent.check_image_size(task, 'fake-image')
self.assertFalse(show_mock.called)
@mock.patch.object(images, 'image_show', autospec=True)
def test_check_image_size_fail(self, show_mock):
show_mock.return_value = {
'size': 11 * 1024 * 1024,
'disk_format': 'qcow2',
}
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties['memory_mb'] = 10
self.assertRaises(exception.InvalidParameterValue,
agent.check_image_size,
task, 'fake-image')
show_mock.assert_called_once_with(self.context, 'fake-image')
@mock.patch.object(images, 'image_show', autospec=True)
def test_check_image_size_fail_by_agent_consumed_memory(self, show_mock):
self.config(memory_consumed_by_agent=2, group='agent')
show_mock.return_value = {
'size': 9 * 1024 * 1024,
'disk_format': 'qcow2',
}
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties['memory_mb'] = 10
self.assertRaises(exception.InvalidParameterValue,
agent.check_image_size,
task, 'fake-image')
show_mock.assert_called_once_with(self.context, 'fake-image')
@mock.patch.object(images, 'image_show', autospec=True)
def test_check_image_size_raw_stream_enabled(self, show_mock):
CONF.set_override('stream_raw_images', True, 'agent')
# Image is bigger than memory but it's raw and will be streamed
# so the test should pass
show_mock.return_value = {
'size': 15 * 1024 * 1024,
'disk_format': 'raw',
}
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties['memory_mb'] = 10
agent.check_image_size(task, 'fake-image')
show_mock.assert_called_once_with(self.context, 'fake-image')
@mock.patch.object(images, 'image_show', autospec=True)
def test_check_image_size_raw_stream_disabled(self, show_mock):
CONF.set_override('stream_raw_images', False, 'agent')
show_mock.return_value = {
'size': 15 * 1024 * 1024,
'disk_format': 'raw',
}
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties['memory_mb'] = 10
# Image is raw but stream is disabled, so test should fail since
# the image is bigger than the RAM size
self.assertRaises(exception.InvalidParameterValue,
agent.check_image_size,
task, 'fake-image')
show_mock.assert_called_once_with(self.context, 'fake-image')
class TestAgentDeploy(db_base.DbTestCase):
def setUp(self):
super(TestAgentDeploy, self).setUp()
mgr_utils.mock_the_extension_manager(driver='fake_agent')
self.driver = agent.AgentDeploy()
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
}
self.node = object_utils.create_test_node(self.context, **n)
self.ports = [
object_utils.create_test_port(self.context, node_id=self.node.id)]
dhcp_factory.DHCPFactory._dhcp_provider = None
def test_get_properties(self):
expected = agent.COMMON_PROPERTIES
self.assertEqual(expected, self.driver.get_properties())
@mock.patch.object(deploy_utils, 'validate_capabilities',
spec_set=True, autospec=True)
@mock.patch.object(images, 'image_show', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'validate', autospec=True)
def test_validate(self, pxe_boot_validate_mock, show_mock,
validate_capability_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.driver.validate(task)
pxe_boot_validate_mock.assert_called_once_with(
task.driver.boot, task)
show_mock.assert_called_once_with(self.context, 'fake-image')
validate_capability_mock.assert_called_once_with(task.node)
@mock.patch.object(deploy_utils, 'validate_capabilities',
spec_set=True, autospec=True)
@mock.patch.object(images, 'image_show', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'validate', autospec=True)
def test_validate_driver_info_manage_agent_boot_false(
self, pxe_boot_validate_mock, show_mock,
validate_capability_mock):
self.config(manage_agent_boot=False, group='agent')
self.node.driver_info = {}
self.node.save()
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.driver.validate(task)
self.assertFalse(pxe_boot_validate_mock.called)
show_mock.assert_called_once_with(self.context, 'fake-image')
validate_capability_mock.assert_called_once_with(task.node)
@mock.patch.object(pxe.PXEBoot, 'validate', autospec=True)
def test_validate_instance_info_missing_params(
self, pxe_boot_validate_mock):
self.node.instance_info = {}
self.node.save()
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
e = self.assertRaises(exception.MissingParameterValue,
self.driver.validate, task)
pxe_boot_validate_mock.assert_called_once_with(
task.driver.boot, task)
self.assertIn('instance_info.image_source', str(e))
@mock.patch.object(pxe.PXEBoot, 'validate', autospec=True)
def test_validate_nonglance_image_no_checksum(
self, pxe_boot_validate_mock):
i_info = self.node.instance_info
i_info['image_source'] = 'http://image-ref'
del i_info['image_checksum']
self.node.instance_info = i_info
self.node.save()
with task_manager.acquire(
self.context, self.node.uuid, shared=False) as task:
self.assertRaises(exception.MissingParameterValue,
self.driver.validate, task)
pxe_boot_validate_mock.assert_called_once_with(
task.driver.boot, task)
@mock.patch.object(images, 'image_show', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'validate', autospec=True)
def test_validate_invalid_root_device_hints(
self, pxe_boot_validate_mock, show_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
task.node.properties['root_device'] = {'size': 'not-int'}
self.assertRaises(exception.InvalidParameterValue,
task.driver.deploy.validate, task)
pxe_boot_validate_mock.assert_called_once_with(
task.driver.boot, task)
show_mock.assert_called_once_with(self.context, 'fake-image')
@mock.patch.object(images, 'image_show', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'validate', autospec=True)
def test_validate_invalid_proxies(self, pxe_boot_validate_mock, show_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
task.node.driver_info.update({
'image_https_proxy': 'git://spam.ni',
'image_http_proxy': 'http://spam.ni',
'image_no_proxy': '1' * 500})
self.assertRaisesRegexp(exception.InvalidParameterValue,
'image_https_proxy.*image_no_proxy',
task.driver.deploy.validate, task)
pxe_boot_validate_mock.assert_called_once_with(
task.driver.boot, task)
show_mock.assert_called_once_with(self.context, 'fake-image')
@mock.patch('ironic.conductor.utils.node_power_action', autospec=True)
def test_deploy(self, power_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
driver_return = self.driver.deploy(task)
self.assertEqual(driver_return, states.DEPLOYWAIT)
power_mock.assert_called_once_with(task, states.REBOOT)
@mock.patch('ironic.conductor.utils.node_power_action', autospec=True)
def test_tear_down(self, power_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
driver_return = self.driver.tear_down(task)
power_mock.assert_called_once_with(task, states.POWER_OFF)
self.assertEqual(driver_return, states.DELETED)
@mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk')
@mock.patch.object(deploy_utils, 'build_agent_options')
@mock.patch.object(agent, 'build_instance_info_for_deploy')
def test_prepare(self, build_instance_info_mock, build_options_mock,
pxe_prepare_ramdisk_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
task.node.provision_state = states.DEPLOYING
build_instance_info_mock.return_value = {'foo': 'bar'}
build_options_mock.return_value = {'a': 'b'}
self.driver.prepare(task)
build_instance_info_mock.assert_called_once_with(task)
build_options_mock.assert_called_once_with(task.node)
pxe_prepare_ramdisk_mock.assert_called_once_with(
task, {'a': 'b'})
self.node.refresh()
self.assertEqual('bar', self.node.instance_info['foo'])
@mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk')
@mock.patch.object(deploy_utils, 'build_agent_options')
@mock.patch.object(agent, 'build_instance_info_for_deploy')
def test_prepare_manage_agent_boot_false(
self, build_instance_info_mock, build_options_mock,
pxe_prepare_ramdisk_mock):
self.config(group='agent', manage_agent_boot=False)
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
task.node.provision_state = states.DEPLOYING
build_instance_info_mock.return_value = {'foo': 'bar'}
self.driver.prepare(task)
build_instance_info_mock.assert_called_once_with(task)
self.assertFalse(build_options_mock.called)
self.assertFalse(pxe_prepare_ramdisk_mock.called)
self.node.refresh()
self.assertEqual('bar', self.node.instance_info['foo'])
@mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk')
@mock.patch.object(deploy_utils, 'build_agent_options')
@mock.patch.object(agent, 'build_instance_info_for_deploy')
def test_prepare_active(
self, build_instance_info_mock, build_options_mock,
pxe_prepare_ramdisk_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
task.node.provision_state = states.ACTIVE
self.driver.prepare(task)
self.assertFalse(build_instance_info_mock.called)
self.assertFalse(build_options_mock.called)
self.assertFalse(pxe_prepare_ramdisk_mock.called)
@mock.patch('ironic.common.dhcp_factory.DHCPFactory._set_dhcp_provider')
@mock.patch('ironic.common.dhcp_factory.DHCPFactory.clean_dhcp')
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk')
def test_clean_up(self, pxe_clean_up_ramdisk_mock, clean_dhcp_mock,
set_dhcp_provider_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.driver.clean_up(task)
pxe_clean_up_ramdisk_mock.assert_called_once_with(task)
set_dhcp_provider_mock.assert_called_once_with()
clean_dhcp_mock.assert_called_once_with(task)
@mock.patch('ironic.common.dhcp_factory.DHCPFactory._set_dhcp_provider')
@mock.patch('ironic.common.dhcp_factory.DHCPFactory.clean_dhcp')
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk')
def test_clean_up_manage_agent_boot_false(self, pxe_clean_up_ramdisk_mock,
clean_dhcp_mock,
set_dhcp_provider_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.config(group='agent', manage_agent_boot=False)
self.driver.clean_up(task)
self.assertFalse(pxe_clean_up_ramdisk_mock.called)
set_dhcp_provider_mock.assert_called_once_with()
clean_dhcp_mock.assert_called_once_with(task)
@mock.patch('ironic.drivers.modules.deploy_utils.agent_get_clean_steps',
autospec=True)
def test_get_clean_steps(self, mock_get_clean_steps):
# Test getting clean steps
mock_steps = [{'priority': 10, 'interface': 'deploy',
'step': 'erase_devices'}]
mock_get_clean_steps.return_value = mock_steps
with task_manager.acquire(self.context, self.node.uuid) as task:
steps = self.driver.get_clean_steps(task)
mock_get_clean_steps.assert_called_once_with(
task, interface='deploy',
override_priorities={'erase_devices': None})
self.assertEqual(mock_steps, steps)
@mock.patch('ironic.drivers.modules.deploy_utils.agent_get_clean_steps',
autospec=True)
def test_get_clean_steps_config_priority(self, mock_get_clean_steps):
# Test that we can override the priority of get clean steps
# Use 0 because it is an edge case (false-y) and used in devstack
self.config(erase_devices_priority=0, group='deploy')
mock_steps = [{'priority': 10, 'interface': 'deploy',
'step': 'erase_devices'}]
mock_get_clean_steps.return_value = mock_steps
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.get_clean_steps(task)
mock_get_clean_steps.assert_called_once_with(
task, interface='deploy',
override_priorities={'erase_devices': 0})
@mock.patch.object(deploy_utils, 'prepare_inband_cleaning', autospec=True)
def test_prepare_cleaning(self, prepare_inband_cleaning_mock):
prepare_inband_cleaning_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertEqual(
states.CLEANWAIT, self.driver.prepare_cleaning(task))
prepare_inband_cleaning_mock.assert_called_once_with(
task, manage_boot=True)
@mock.patch.object(deploy_utils, 'prepare_inband_cleaning', autospec=True)
def test_prepare_cleaning_manage_agent_boot_false(
self, prepare_inband_cleaning_mock):
prepare_inband_cleaning_mock.return_value = states.CLEANWAIT
self.config(group='agent', manage_agent_boot=False)
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertEqual(
states.CLEANWAIT, self.driver.prepare_cleaning(task))
prepare_inband_cleaning_mock.assert_called_once_with(
task, manage_boot=False)
@mock.patch.object(deploy_utils, 'tear_down_inband_cleaning',
autospec=True)
def test_tear_down_cleaning(self, tear_down_cleaning_mock):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.tear_down_cleaning(task)
tear_down_cleaning_mock.assert_called_once_with(
task, manage_boot=True)
@mock.patch.object(deploy_utils, 'tear_down_inband_cleaning',
autospec=True)
def test_tear_down_cleaning_manage_agent_boot_false(
self, tear_down_cleaning_mock):
self.config(group='agent', manage_agent_boot=False)
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.tear_down_cleaning(task)
tear_down_cleaning_mock.assert_called_once_with(
task, manage_boot=False)
class TestAgentVendor(db_base.DbTestCase):
def setUp(self):
super(TestAgentVendor, self).setUp()
mgr_utils.mock_the_extension_manager(driver="fake_agent")
self.passthru = agent.AgentVendorInterface()
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
}
self.node = object_utils.create_test_node(self.context, **n)
def _test_continue_deploy(self, additional_driver_info=None,
additional_expected_image_info=None):
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
driver_info = self.node.driver_info
driver_info.update(additional_driver_info or {})
self.node.driver_info = driver_info
self.node.save()
test_temp_url = 'http://image'
expected_image_info = {
'urls': [test_temp_url],
'id': 'fake-image',
'checksum': 'checksum',
'disk_format': 'qcow2',
'container_format': 'bare',
'stream_raw_images': CONF.agent.stream_raw_images,
}
expected_image_info.update(additional_expected_image_info or {})
client_mock = mock.MagicMock(spec_set=['prepare_image'])
self.passthru._client = client_mock
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
self.passthru.continue_deploy(task)
client_mock.prepare_image.assert_called_with(task.node,
expected_image_info)
self.assertEqual(states.DEPLOYWAIT, task.node.provision_state)
self.assertEqual(states.ACTIVE,
task.node.target_provision_state)
def test_continue_deploy(self):
self._test_continue_deploy()
def test_continue_deploy_with_proxies(self):
self._test_continue_deploy(
additional_driver_info={'image_https_proxy': 'https://spam.ni',
'image_http_proxy': 'spam.ni',
'image_no_proxy': '.eggs.com'},
additional_expected_image_info={
'proxies': {'https': 'https://spam.ni',
'http': 'spam.ni'},
'no_proxy': '.eggs.com'}
)
def test_continue_deploy_with_no_proxy_without_proxies(self):
self._test_continue_deploy(
additional_driver_info={'image_no_proxy': '.eggs.com'}
)
def test_continue_deploy_image_source_is_url(self):
instance_info = self.node.instance_info
instance_info['image_source'] = 'http://example.com/woof.img'
self.node.instance_info = instance_info
self._test_continue_deploy(
additional_expected_image_info={
'id': 'woof.img'
}
)
def test_continue_deploy_partition_image(self):
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
i_info = self.node.instance_info
i_info['kernel'] = 'kernel'
i_info['ramdisk'] = 'ramdisk'
i_info['root_gb'] = 10
i_info['swap_mb'] = 10
i_info['ephemeral_mb'] = 0
i_info['ephemeral_format'] = 'abc'
i_info['configdrive'] = 'configdrive'
i_info['preserve_ephemeral'] = False
i_info['image_type'] = 'partition'
i_info['root_mb'] = 10240
i_info['deploy_boot_mode'] = 'bios'
i_info['capabilities'] = {"boot_option": "local",
"disk_label": "msdos"}
self.node.instance_info = i_info
driver_internal_info = self.node.driver_internal_info
driver_internal_info['is_whole_disk_image'] = False
self.node.driver_internal_info = driver_internal_info
self.node.save()
test_temp_url = 'http://image'
expected_image_info = {
'urls': [test_temp_url],
'id': 'fake-image',
'node_uuid': self.node.uuid,
'checksum': 'checksum',
'disk_format': 'qcow2',
'container_format': 'bare',
'stream_raw_images': True,
'kernel': 'kernel',
'ramdisk': 'ramdisk',
'root_gb': 10,
'swap_mb': 10,
'ephemeral_mb': 0,
'ephemeral_format': 'abc',
'configdrive': 'configdrive',
'preserve_ephemeral': False,
'image_type': 'partition',
'root_mb': 10240,
'boot_option': 'local',
'deploy_boot_mode': 'bios',
'disk_label': 'msdos'
}
client_mock = mock.MagicMock(spec_set=['prepare_image'])
self.passthru._client = client_mock
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
self.passthru.continue_deploy(task)
client_mock.prepare_image.assert_called_with(task.node,
expected_image_info)
self.assertEqual(states.DEPLOYWAIT, task.node.provision_state)
self.assertEqual(states.ACTIVE,
task.node.target_provision_state)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
spec=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'power_off',
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance(self, clean_pxe_mock, check_deploy_mock,
prepare_mock, power_off_mock,
get_power_state_mock, node_power_action_mock,
uuid_mock):
check_deploy_mock.return_value = None
uuid_mock.return_value = 'root_uuid'
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = True
self.passthru.reboot_to_instance(task)
clean_pxe_mock.assert_called_once_with(task.driver.boot, task)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
power_off_mock.assert_called_once_with(task.node)
get_power_state_mock.assert_called_once_with(task)
node_power_action_mock.assert_called_once_with(
task, states.REBOOT)
self.assertFalse(prepare_mock.called)
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
driver_int_info = task.node.driver_internal_info
self.assertIsNone(driver_int_info.get('root_uuid_or_disk_id'))
self.assertFalse(uuid_mock.called)
@mock.patch.object(deploy_utils, 'get_boot_mode_for_deploy', autospec=True)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
spec=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'power_off',
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_partition_image(self, clean_pxe_mock,
check_deploy_mock,
prepare_mock, power_off_mock,
get_power_state_mock,
node_power_action_mock,
uuid_mock, boot_mode_mock):
check_deploy_mock.return_value = None
uuid_mock.return_value = 'root_uuid'
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
boot_mode_mock.return_value = 'bios'
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = False
self.passthru.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
power_off_mock.assert_called_once_with(task.node)
get_power_state_mock.assert_called_once_with(task)
node_power_action_mock.assert_called_once_with(
task, states.REBOOT)
prepare_mock.assert_called_once_with(task.driver.boot, task)
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
driver_int_info = task.node.driver_internal_info
self.assertEqual(driver_int_info.get('root_uuid_or_disk_id'),
'root_uuid')
uuid_mock.assert_called_once_with(self.passthru, task, 'root_uuid')
boot_mode_mock.assert_called_once_with(task.node)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
spec=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'power_off',
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_boot_none(self, clean_pxe_mock,
check_deploy_mock,
prepare_mock, power_off_mock,
get_power_state_mock,
node_power_action_mock,
uuid_mock):
check_deploy_mock.return_value = None
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = True
task.driver.boot = None
self.passthru.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
self.assertFalse(prepare_mock.called)
power_off_mock.assert_called_once_with(task.node)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
driver_int_info = task.node.driver_internal_info
self.assertIsNone(driver_int_info.get('root_uuid_or_disk_id'))
get_power_state_mock.assert_called_once_with(task)
node_power_action_mock.assert_called_once_with(
task, states.REBOOT)
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
self.assertFalse(uuid_mock.called)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
spec=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'power_off',
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_boot_error(self, clean_pxe_mock,
check_deploy_mock,
prepare_mock, power_off_mock,
get_power_state_mock,
node_power_action_mock,
uuid_mock):
check_deploy_mock.return_value = "Error"
uuid_mock.return_value = None
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = True
task.driver.boot = None
self.passthru.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
self.assertFalse(prepare_mock.called)
self.assertFalse(power_off_mock.called)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
self.assertEqual(states.DEPLOYFAIL, task.node.provision_state)
self.assertEqual(states.ACTIVE, task.node.target_provision_state)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'configure_local_boot', autospec=True)
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
spec=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'power_off',
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_localboot(self, clean_pxe_mock,
check_deploy_mock,
prepare_mock, power_off_mock,
get_power_state_mock,
node_power_action_mock,
uuid_mock,
bootdev_mock,
configure_mock):
check_deploy_mock.return_value = None
uuid_mock.side_effect = ['root_uuid', 'efi_uuid']
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = False
boot_option = {'capabilities': '{"boot_option": "local"}'}
task.node.instance_info = boot_option
self.passthru.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
self.assertFalse(bootdev_mock.called)
power_off_mock.assert_called_once_with(task.node)
get_power_state_mock.assert_called_once_with(task)
node_power_action_mock.assert_called_once_with(
task, states.REBOOT)
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_has_started(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = []
self.assertFalse(self.passthru.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_has_started_is_done(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'SUCCESS'}]
self.assertTrue(self.passthru.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_has_started_did_start(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertTrue(self.passthru.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_has_started_multiple_commands(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'cache_image',
'command_status': 'SUCCESS'},
{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertTrue(self.passthru.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_has_started_other_commands(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'cache_image',
'command_status': 'SUCCESS'}]
self.assertFalse(self.passthru.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'SUCCESS'}]
self.assertTrue(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_empty_response(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = []
self.assertFalse(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_race(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'some_other_command',
'command_status': 'SUCCESS'}]
self.assertFalse(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_still_running(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertFalse(self.passthru.deploy_is_done(task))
class AgentRAIDTestCase(db_base.DbTestCase):
def setUp(self):
super(AgentRAIDTestCase, self).setUp()
mgr_utils.mock_the_extension_manager(driver="fake_agent")
self.passthru = agent.AgentVendorInterface()
self.target_raid_config = {
"logical_disks": [
{'size_gb': 200, 'raid_level': 0, 'is_root_volume': True},
{'size_gb': 200, 'raid_level': 5}
]}
self.clean_step = {'step': 'create_configuration',
'interface': 'raid'}
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
'target_raid_config': self.target_raid_config,
'clean_step': self.clean_step,
}
self.node = object_utils.create_test_node(self.context, **n)
@mock.patch.object(deploy_utils, 'agent_get_clean_steps', autospec=True)
def test_get_clean_steps(self, get_steps_mock):
get_steps_mock.return_value = [
{'step': 'create_configuration', 'interface': 'raid',
'priority': 1},
{'step': 'delete_configuration', 'interface': 'raid',
'priority': 2}]
with task_manager.acquire(self.context, self.node.uuid) as task:
ret = task.driver.raid.get_clean_steps(task)
self.assertEqual(0, ret[0]['priority'])
self.assertEqual(0, ret[1]['priority'])
@mock.patch.object(deploy_utils, 'agent_execute_clean_step',
autospec=True)
def test_create_configuration(self, execute_mock):
with task_manager.acquire(self.context, self.node.uuid) as task:
execute_mock.return_value = states.CLEANWAIT
return_value = task.driver.raid.create_configuration(task)
self.assertEqual(states.CLEANWAIT, return_value)
self.assertEqual(
self.target_raid_config,
task.node.driver_internal_info['target_raid_config'])
execute_mock.assert_called_once_with(task, self.clean_step)
@mock.patch.object(deploy_utils, 'agent_execute_clean_step',
autospec=True)
def test_create_configuration_skip_root(self, execute_mock):
with task_manager.acquire(self.context, self.node.uuid) as task:
execute_mock.return_value = states.CLEANWAIT
return_value = task.driver.raid.create_configuration(
task, create_root_volume=False)
self.assertEqual(states.CLEANWAIT, return_value)
execute_mock.assert_called_once_with(task, self.clean_step)
exp_target_raid_config = {
"logical_disks": [
{'size_gb': 200, 'raid_level': 5}
]}
self.assertEqual(
exp_target_raid_config,
task.node.driver_internal_info['target_raid_config'])
@mock.patch.object(deploy_utils, 'agent_execute_clean_step',
autospec=True)
def test_create_configuration_skip_nonroot(self, execute_mock):
with task_manager.acquire(self.context, self.node.uuid) as task:
execute_mock.return_value = states.CLEANWAIT
return_value = task.driver.raid.create_configuration(
task, create_nonroot_volumes=False)
self.assertEqual(states.CLEANWAIT, return_value)
execute_mock.assert_called_once_with(task, self.clean_step)
exp_target_raid_config = {
"logical_disks": [
{'size_gb': 200, 'raid_level': 0, 'is_root_volume': True},
]}
self.assertEqual(
exp_target_raid_config,
task.node.driver_internal_info['target_raid_config'])
@mock.patch.object(deploy_utils, 'agent_execute_clean_step',
autospec=True)
def test_create_configuration_no_target_raid_config_after_skipping(
self, execute_mock):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(
exception.MissingParameterValue,
task.driver.raid.create_configuration,
task, create_root_volume=False,
create_nonroot_volumes=False)
self.assertFalse(execute_mock.called)
@mock.patch.object(deploy_utils, 'agent_execute_clean_step',
autospec=True)
def test_create_configuration_empty_target_raid_config(
self, execute_mock):
execute_mock.return_value = states.CLEANING
self.node.target_raid_config = {}
self.node.save()
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.MissingParameterValue,
task.driver.raid.create_configuration,
task)
self.assertFalse(execute_mock.called)
@mock.patch.object(raid, 'update_raid_info', autospec=True)
def test__create_configuration_final(
self, update_raid_info_mock):
command = {'command_result': {'clean_result': 'foo'}}
with task_manager.acquire(self.context, self.node.uuid) as task:
raid_mgmt = agent.AgentRAID
raid_mgmt._create_configuration_final(task, command)
update_raid_info_mock.assert_called_once_with(task.node, 'foo')
@mock.patch.object(raid, 'update_raid_info', autospec=True)
def test__create_configuration_final_registered(
self, update_raid_info_mock):
self.node.clean_step = {'interface': 'raid',
'step': 'create_configuration'}
command = {'command_result': {'clean_result': 'foo'}}
create_hook = agent_base_vendor._get_post_clean_step_hook(self.node)
with task_manager.acquire(self.context, self.node.uuid) as task:
create_hook(task, command)
update_raid_info_mock.assert_called_once_with(task.node, 'foo')
@mock.patch.object(raid, 'update_raid_info', autospec=True)
def test__create_configuration_final_bad_command_result(
self, update_raid_info_mock):
command = {}
with task_manager.acquire(self.context, self.node.uuid) as task:
raid_mgmt = agent.AgentRAID
self.assertRaises(exception.IronicException,
raid_mgmt._create_configuration_final,
task, command)
self.assertFalse(update_raid_info_mock.called)
@mock.patch.object(deploy_utils, 'agent_execute_clean_step',
autospec=True)
def test_delete_configuration(self, execute_mock):
execute_mock.return_value = states.CLEANING
with task_manager.acquire(self.context, self.node.uuid) as task:
return_value = task.driver.raid.delete_configuration(task)
execute_mock.assert_called_once_with(task, self.clean_step)
self.assertEqual(states.CLEANING, return_value)
def test__delete_configuration_final(self):
command = {'command_result': {'clean_result': 'foo'}}
with task_manager.acquire(self.context, self.node.uuid) as task:
task.node.raid_config = {'foo': 'bar'}
raid_mgmt = agent.AgentRAID
raid_mgmt._delete_configuration_final(task, command)
self.node.refresh()
self.assertEqual({}, self.node.raid_config)
def test__delete_configuration_final_registered(
self):
self.node.clean_step = {'interface': 'raid',
'step': 'delete_configuration'}
self.node.raid_config = {'foo': 'bar'}
command = {'command_result': {'clean_result': 'foo'}}
delete_hook = agent_base_vendor._get_post_clean_step_hook(self.node)
with task_manager.acquire(self.context, self.node.uuid) as task:
delete_hook(task, command)
self.node.refresh()
self.assertEqual({}, self.node.raid_config)
|
apache-2.0
|
[
3,
1898,
6927,
32679,
12,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
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,
646,
2943,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
28372,
14,
2330,
492,
19064,
63,
3702,
199,
504,
28372,
14,
2330,
492,
1919,
199,
504,
28372,
14,
2330,
492,
1834,
63,
1364,
199,
504,
28372,
14,
2330,
492,
5935,
199,
504,
28372,
14,
2330,
492,
660,
344,
199,
504,
28372,
14,
2330,
492,
6363,
199,
504,
28372,
14,
28678,
492,
2120,
63,
2609,
199,
504,
28372,
14,
28678,
492,
3778,
465,
5256,
63,
1208,
199,
504,
28372,
14,
13337,
14,
3112,
492,
6631,
199,
504,
28372,
14,
13337,
14,
3112,
492,
6631,
63,
1095,
63,
9884,
199,
504,
28372,
14,
13337,
14,
3112,
492,
6631,
63,
1258,
199,
504,
28372,
14,
13337,
14,
3112,
492,
12287,
63,
1208,
199,
504,
28372,
14,
13337,
14,
3112,
492,
4026,
199,
504,
28372,
14,
13337,
14,
3112,
492,
299,
1845,
199,
504,
28372,
14,
2219,
14,
3248,
14,
28678,
492,
18137,
63,
1208,
199,
504,
28372,
14,
2219,
14,
3248,
14,
697,
492,
1300,
465,
1592,
63,
1095,
199,
504,
28372,
14,
2219,
14,
3248,
14,
697,
492,
3778,
465,
1592,
63,
1208,
199,
504,
28372,
14,
2219,
14,
3248,
14,
1462,
492,
3778,
465,
909,
63,
1208,
421,
199,
18235,
63,
4531,
275,
1592,
63,
1208,
14,
362,
63,
396,
63,
4054,
63,
842,
63,
815,
342,
199,
23401,
63,
4531,
275,
1592,
63,
1208,
14,
362,
63,
396,
63,
4054,
63,
3090,
63,
815,
342,
199,
23401,
63,
17681,
63,
4531,
275,
1592,
63,
1208,
14,
362,
63,
396,
63,
4054,
63,
3090,
63,
4672,
63,
815,
342,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
533,
1379,
7788,
10385,
8,
697,
63,
1095,
14,
8882,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
7788,
10385,
12,
291,
680,
5996,
342,
267,
291,
14,
932,
275,
909,
63,
1208,
14,
981,
63,
396,
63,
932,
8,
277,
14,
1100,
12,
8179,
5253,
534,
3183,
63,
4054,
358,
267,
19064,
63,
3702,
14,
29977,
2927,
423,
10801,
63,
3780,
275,
488,
339,
768,
1805,
14,
2068,
14,
785,
8,
1569,
63,
1364,
12,
283,
17541,
554,
3491,
3167,
297,
18052,
29,
549,
9,
272,
347,
511,
63,
1506,
63,
842,
63,
815,
63,
509,
63,
11060,
63,
18773,
63,
1569,
8,
277,
12,
21785,
63,
1805,
304,
267,
284,
63,
815,
275,
291,
14,
932,
14,
842,
63,
815,
267,
284,
63,
815,
459,
1569,
63,
1365,
418,
275,
283,
31666,
68,
17,
67,
1602,
13,
65,
18,
4489,
13,
25250,
66,
13,
30632,
23,
13,
1876,
271,
2177,
1165,
68,
31086,
7,
267,
5253,
63,
4672,
63,
815,
275,
291,
14,
932,
14,
3090,
63,
4672,
63,
815,
267,
5253,
63,
4672,
63,
815,
459,
374,
63,
21224,
63,
4032,
63,
1569,
418,
275,
715,
267,
291,
14,
932,
14,
3090,
63,
4672,
63,
815,
275,
5253,
63,
4672,
63,
815,
267,
291,
14,
932,
14,
842,
63,
815,
275,
284,
63,
815,
267,
291,
14,
932,
14,
2117,
342,
398,
1834,
63,
815,
275,
791,
8928,
356,
283,
2158,
297,
283,
4032,
63,
908,
356,
283,
81,
19969,
18,
297,
1993,
283,
3600,
63,
908,
356,
283,
14890,
936,
267,
21785,
63,
1805,
14,
1107,
63,
585,
14,
2384,
275,
1683,
14,
11988,
8,
1650,
63,
409,
6034,
10940,
372,
63,
585,
29,
1569,
63,
815,
9,
398,
18137,
63,
1208,
14,
1805,
63,
1589,
63,
3435,
63,
2609,
8,
3090,
534,
3183,
63,
4054,
358,
267,
543,
2120,
63,
2609,
14,
8174,
8,
355,
291,
14,
1100,
12,
291,
14,
932,
14,
2580,
12,
5709,
29,
797,
9,
465,
2120,
26,
953,
6631,
14,
1506,
63,
842,
63,
815,
63,
509,
63,
11060,
8,
1765,
9,
953,
21785,
63,
1805,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1023,
29,
18,
12,
6059,
1067,
29,
1765,
14,
1100,
9,
288,
21785,
63,
1805,
14,
1107,
63,
585,
14,
2384,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
355,
291,
14,
932,
14,
842,
63,
815,
459,
1569,
63,
1365,
1105,
288,
21785,
63,
1805,
14,
1107,
63,
585,
14,
13215,
63,
808,
63,
633,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
355,
1834,
63,
815,
9,
339,
768,
1805,
14,
2068,
14,
785,
8,
11060,
63,
1208,
12,
283,
1122,
63,
842,
63,
815,
297,
18052,
29,
549,
9,
272,
768,
1805,
14,
2068,
14,
785,
8,
1569,
63,
1364,
12,
283,
17541,
554,
3491,
3167,
297,
18052,
29,
549,
9,
272,
347,
511,
63,
1506,
63,
842,
63,
815,
63,
509,
63,
11060,
63,
18773,
63,
5312,
63,
1569,
8,
288,
291,
12,
21785,
63,
1805,
12,
2198,
63,
842,
63,
815,
63,
1805,
304,
267,
284,
63,
815,
275,
291,
14,
932,
14,
842,
63,
815,
267,
284,
63,
815,
459,
1569,
63,
1365,
418,
275,
283,
31666,
68,
17,
67,
1602,
13,
65,
18,
4489,
13,
25250,
66,
13,
30632,
23,
13,
1876,
271,
2177,
1165,
68,
31086,
7,
267,
284,
63,
815,
459,
4989,
418,
275,
283,
969,
301,
21,
65,
1367,
13,
17,
271,
19,
13,
1887,
975,
13,
66,
24,
66,
18,
13,
1235,
16156,
13067,
68,
8262,
7,
267,
284,
63,
815,
459,
26541,
418,
275,
283,
65,
21,
65,
13812,
65,
24,
13,
17,
66,
1355,
13,
23404,
70
] |
[
1898,
6927,
32679,
12,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
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,
646,
2943,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
28372,
14,
2330,
492,
19064,
63,
3702,
199,
504,
28372,
14,
2330,
492,
1919,
199,
504,
28372,
14,
2330,
492,
1834,
63,
1364,
199,
504,
28372,
14,
2330,
492,
5935,
199,
504,
28372,
14,
2330,
492,
660,
344,
199,
504,
28372,
14,
2330,
492,
6363,
199,
504,
28372,
14,
28678,
492,
2120,
63,
2609,
199,
504,
28372,
14,
28678,
492,
3778,
465,
5256,
63,
1208,
199,
504,
28372,
14,
13337,
14,
3112,
492,
6631,
199,
504,
28372,
14,
13337,
14,
3112,
492,
6631,
63,
1095,
63,
9884,
199,
504,
28372,
14,
13337,
14,
3112,
492,
6631,
63,
1258,
199,
504,
28372,
14,
13337,
14,
3112,
492,
12287,
63,
1208,
199,
504,
28372,
14,
13337,
14,
3112,
492,
4026,
199,
504,
28372,
14,
13337,
14,
3112,
492,
299,
1845,
199,
504,
28372,
14,
2219,
14,
3248,
14,
28678,
492,
18137,
63,
1208,
199,
504,
28372,
14,
2219,
14,
3248,
14,
697,
492,
1300,
465,
1592,
63,
1095,
199,
504,
28372,
14,
2219,
14,
3248,
14,
697,
492,
3778,
465,
1592,
63,
1208,
199,
504,
28372,
14,
2219,
14,
3248,
14,
1462,
492,
3778,
465,
909,
63,
1208,
421,
199,
18235,
63,
4531,
275,
1592,
63,
1208,
14,
362,
63,
396,
63,
4054,
63,
842,
63,
815,
342,
199,
23401,
63,
4531,
275,
1592,
63,
1208,
14,
362,
63,
396,
63,
4054,
63,
3090,
63,
815,
342,
199,
23401,
63,
17681,
63,
4531,
275,
1592,
63,
1208,
14,
362,
63,
396,
63,
4054,
63,
3090,
63,
4672,
63,
815,
342,
199,
199,
3103,
275,
4810,
14,
3103,
421,
199,
533,
1379,
7788,
10385,
8,
697,
63,
1095,
14,
8882,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
7788,
10385,
12,
291,
680,
5996,
342,
267,
291,
14,
932,
275,
909,
63,
1208,
14,
981,
63,
396,
63,
932,
8,
277,
14,
1100,
12,
8179,
5253,
534,
3183,
63,
4054,
358,
267,
19064,
63,
3702,
14,
29977,
2927,
423,
10801,
63,
3780,
275,
488,
339,
768,
1805,
14,
2068,
14,
785,
8,
1569,
63,
1364,
12,
283,
17541,
554,
3491,
3167,
297,
18052,
29,
549,
9,
272,
347,
511,
63,
1506,
63,
842,
63,
815,
63,
509,
63,
11060,
63,
18773,
63,
1569,
8,
277,
12,
21785,
63,
1805,
304,
267,
284,
63,
815,
275,
291,
14,
932,
14,
842,
63,
815,
267,
284,
63,
815,
459,
1569,
63,
1365,
418,
275,
283,
31666,
68,
17,
67,
1602,
13,
65,
18,
4489,
13,
25250,
66,
13,
30632,
23,
13,
1876,
271,
2177,
1165,
68,
31086,
7,
267,
5253,
63,
4672,
63,
815,
275,
291,
14,
932,
14,
3090,
63,
4672,
63,
815,
267,
5253,
63,
4672,
63,
815,
459,
374,
63,
21224,
63,
4032,
63,
1569,
418,
275,
715,
267,
291,
14,
932,
14,
3090,
63,
4672,
63,
815,
275,
5253,
63,
4672,
63,
815,
267,
291,
14,
932,
14,
842,
63,
815,
275,
284,
63,
815,
267,
291,
14,
932,
14,
2117,
342,
398,
1834,
63,
815,
275,
791,
8928,
356,
283,
2158,
297,
283,
4032,
63,
908,
356,
283,
81,
19969,
18,
297,
1993,
283,
3600,
63,
908,
356,
283,
14890,
936,
267,
21785,
63,
1805,
14,
1107,
63,
585,
14,
2384,
275,
1683,
14,
11988,
8,
1650,
63,
409,
6034,
10940,
372,
63,
585,
29,
1569,
63,
815,
9,
398,
18137,
63,
1208,
14,
1805,
63,
1589,
63,
3435,
63,
2609,
8,
3090,
534,
3183,
63,
4054,
358,
267,
543,
2120,
63,
2609,
14,
8174,
8,
355,
291,
14,
1100,
12,
291,
14,
932,
14,
2580,
12,
5709,
29,
797,
9,
465,
2120,
26,
953,
6631,
14,
1506,
63,
842,
63,
815,
63,
509,
63,
11060,
8,
1765,
9,
953,
21785,
63,
1805,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1023,
29,
18,
12,
6059,
1067,
29,
1765,
14,
1100,
9,
288,
21785,
63,
1805,
14,
1107,
63,
585,
14,
2384,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
355,
291,
14,
932,
14,
842,
63,
815,
459,
1569,
63,
1365,
1105,
288,
21785,
63,
1805,
14,
1107,
63,
585,
14,
13215,
63,
808,
63,
633,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
355,
1834,
63,
815,
9,
339,
768,
1805,
14,
2068,
14,
785,
8,
11060,
63,
1208,
12,
283,
1122,
63,
842,
63,
815,
297,
18052,
29,
549,
9,
272,
768,
1805,
14,
2068,
14,
785,
8,
1569,
63,
1364,
12,
283,
17541,
554,
3491,
3167,
297,
18052,
29,
549,
9,
272,
347,
511,
63,
1506,
63,
842,
63,
815,
63,
509,
63,
11060,
63,
18773,
63,
5312,
63,
1569,
8,
288,
291,
12,
21785,
63,
1805,
12,
2198,
63,
842,
63,
815,
63,
1805,
304,
267,
284,
63,
815,
275,
291,
14,
932,
14,
842,
63,
815,
267,
284,
63,
815,
459,
1569,
63,
1365,
418,
275,
283,
31666,
68,
17,
67,
1602,
13,
65,
18,
4489,
13,
25250,
66,
13,
30632,
23,
13,
1876,
271,
2177,
1165,
68,
31086,
7,
267,
284,
63,
815,
459,
4989,
418,
275,
283,
969,
301,
21,
65,
1367,
13,
17,
271,
19,
13,
1887,
975,
13,
66,
24,
66,
18,
13,
1235,
16156,
13067,
68,
8262,
7,
267,
284,
63,
815,
459,
26541,
418,
275,
283,
65,
21,
65,
13812,
65,
24,
13,
17,
66,
1355,
13,
23404,
70,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jawed123/flask
|
examples/flaskr/flaskr.py
|
157
|
2893
|
# -*- coding: utf-8 -*-
"""
Flaskr
~~~~~~
A microblog example application written as Flask tutorial with
Flask and sqlite3.
:copyright: (c) 2015 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
import os
from sqlite3 import dbapi2 as sqlite3
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
# create our little application :)
app = Flask(__name__)
# Load default config and override config from an environment variable
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'flaskr.db'),
DEBUG=True,
SECRET_KEY='development key',
USERNAME='admin',
PASSWORD='default'
))
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
def connect_db():
"""Connects to the specific database."""
rv = sqlite3.connect(app.config['DATABASE'])
rv.row_factory = sqlite3.Row
return rv
def init_db():
"""Initializes the database."""
db = get_db()
with app.open_resource('schema.sql', mode='r') as f:
db.cursor().executescript(f.read())
db.commit()
@app.cli.command('initdb')
def initdb_command():
"""Creates the database tables."""
init_db()
print('Initialized the database.')
def get_db():
"""Opens a new database connection if there is none yet for the
current application context.
"""
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
@app.teardown_appcontext
def close_db(error):
"""Closes the database again at the end of the request."""
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()
@app.route('/')
def show_entries():
db = get_db()
cur = db.execute('select title, text from entries order by id desc')
entries = cur.fetchall()
return render_template('show_entries.html', entries=entries)
@app.route('/add', methods=['POST'])
def add_entry():
if not session.get('logged_in'):
abort(401)
db = get_db()
db.execute('insert into entries (title, text) values (?, ?)',
[request.form['title'], request.form['text']])
db.commit()
flash('New entry was successfully posted')
return redirect(url_for('show_entries'))
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('show_entries'))
return render_template('login.html', error=error)
@app.route('/logout')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('show_entries'))
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
16704,
82,
272,
221,
2878,
1714,
339,
437,
9967,
11486,
2893,
4223,
5313,
465,
16704,
307,
15888,
543,
272,
16704,
436,
11723,
19,
14,
339,
520,
7307,
26,
334,
67,
9,
6900,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
504,
11723,
19,
492,
29333,
18,
465,
11723,
19,
199,
504,
7209,
492,
16704,
12,
1056,
12,
2351,
12,
486,
12,
4660,
12,
1166,
63,
509,
12,
12004,
12,
971,
1362,
3795,
63,
1160,
12,
14775,
421,
199,
3,
1218,
4154,
12050,
4223,
32428,
199,
571,
275,
16704,
3460,
354,
3368,
199,
199,
3,
7190,
849,
1101,
436,
4278,
1101,
687,
376,
3734,
1750,
199,
571,
14,
888,
14,
873,
8,
807,
8,
272,
31705,
29,
736,
14,
515,
14,
904,
8,
571,
14,
1231,
63,
515,
12,
283,
15720,
82,
14,
697,
659,
272,
10990,
29,
549,
12,
272,
5795,
11771,
63,
3078,
534,
31688,
790,
297,
272,
13044,
2339,
534,
2113,
297,
272,
21705,
5172,
534,
885,
7,
199,
430,
199,
571,
14,
888,
14,
504,
63,
1813,
1391,
360,
3143,
7946,
50,
63,
13931,
297,
10866,
29,
549,
9,
421,
199,
318,
4907,
63,
697,
837,
272,
408,
8631,
83,
370,
314,
2488,
3050,
1041,
272,
4336,
275,
11723,
19,
14,
2242,
8,
571,
14,
888,
459,
17873,
1105,
272,
4336,
14,
1143,
63,
3702,
275,
11723,
19,
14,
5810,
272,
372,
4336,
421,
199,
318,
4205,
63,
697,
837,
272,
408,
23489,
314,
3050,
1041,
272,
1592,
275,
664,
63,
697,
342,
272,
543,
1145,
14,
1490,
63,
1927,
360,
3629,
14,
3009,
297,
818,
534,
82,
358,
465,
289,
26,
267,
1592,
14,
3937,
1252,
2526,
1579,
8,
70,
14,
739,
1012,
272,
1592,
14,
3543,
342,
421,
199,
32,
571,
14,
2764,
14,
1531,
360,
826,
697,
358,
199,
318,
4205,
697,
63,
1531,
837,
272,
408,
10607,
314,
3050,
6716,
1041,
272,
4205,
63,
697,
342,
272,
870,
360,
23031,
314,
3050,
2659,
421,
199,
318,
664,
63,
697,
837,
272,
408,
4299,
83,
282,
892,
3050,
1950,
340,
2337,
365,
7179,
5966,
367,
314,
272,
1453,
4223,
1067,
14,
272,
408,
272,
340,
440,
2688,
8,
71,
12,
283,
10659,
63,
697,
735,
267,
486,
14,
10659,
63,
697,
275,
4907,
63,
697,
342,
272,
372,
486,
14,
10659,
63,
697,
421,
199,
32,
571,
14,
15236,
63,
571,
1100,
199,
318,
4002,
63,
697,
8,
705,
304,
272,
408,
3337,
874,
314,
3050,
4020,
737,
314,
1284,
402,
314,
1056,
1041,
272,
340,
2688,
8,
71,
12,
283,
10659,
63,
697,
735,
267,
486,
14,
10659,
63,
697,
14,
1600,
342,
421,
199,
32,
571,
14,
4449,
7825,
199,
318,
2498,
63,
3189,
837,
272,
1592,
275,
664,
63,
697,
342,
272,
1094,
275,
1592,
14,
2526,
360,
2416,
2538,
12,
1318,
687,
4811,
1865,
701,
1305,
4328,
358,
272,
4811,
275,
1094,
14,
10174,
342,
272,
372,
3795,
63,
1160,
360,
2384,
63,
3189,
14,
1360,
297,
4811,
29,
3189,
9,
421,
199,
32,
571,
14,
4449,
2336,
525,
297,
3102,
2968,
4030,
1105,
199,
318,
1050,
63,
2373,
837,
272,
340,
440,
2351,
14,
362,
360,
12419,
63,
262,
735,
267,
12004,
8,
8854,
9,
272,
1592,
275,
664,
63,
697,
342,
272,
1592,
14,
2526,
360,
3176,
1901,
4811,
334,
1213,
12,
1318,
9,
1338,
7558,
12,
5805,
3196,
2049,
359,
1069,
14,
964,
459,
1213,
995,
1056,
14,
964,
459,
505,
12121,
272,
1592,
14,
3543,
342,
272,
14775,
360,
4665,
2397,
1990,
8792,
22752,
358,
272,
372,
4660,
8,
633,
63,
509,
360,
2384,
63,
3189,
1333,
421,
199,
32,
571,
14,
4449,
2336,
2886,
297,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
4676,
837,
272,
1125,
275,
488,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
340,
1056,
14,
964,
459,
2473,
418,
1137,
1145,
14,
888,
459,
11958,
2565,
288,
1125,
275,
283,
3364,
3434,
7,
267,
916,
1056,
14,
964,
459,
2060,
418,
1137,
1145,
14,
888,
459,
9032,
2565,
288,
1125,
275,
283,
3364,
2505,
7,
267,
587,
26,
288,
2351,
459,
12419,
63,
262,
418,
275,
715,
288,
14775,
360,
5556,
4898,
10367,
315,
358,
288,
372,
4660,
8,
633,
63,
509,
360,
2384,
63,
3189,
1333,
272,
372,
3795,
63,
1160,
360,
2886,
14,
1360,
297,
1125,
29,
705,
9,
421,
199,
32,
571,
14,
4449,
2336,
11646,
358,
199,
318,
22079,
837,
272,
2351,
14,
1935,
360,
12419,
63,
262,
297,
488,
9,
272,
14775,
360,
5556,
4898,
10367,
734,
358,
272,
372,
4660,
8,
633,
63,
509,
360,
2384,
63,
3189,
1333,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
16704,
82,
272,
221,
2878,
1714,
339,
437,
9967,
11486,
2893,
4223,
5313,
465,
16704,
307,
15888,
543,
272,
16704,
436,
11723,
19,
14,
339,
520,
7307,
26,
334,
67,
9,
6900,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
504,
11723,
19,
492,
29333,
18,
465,
11723,
19,
199,
504,
7209,
492,
16704,
12,
1056,
12,
2351,
12,
486,
12,
4660,
12,
1166,
63,
509,
12,
12004,
12,
971,
1362,
3795,
63,
1160,
12,
14775,
421,
199,
3,
1218,
4154,
12050,
4223,
32428,
199,
571,
275,
16704,
3460,
354,
3368,
199,
199,
3,
7190,
849,
1101,
436,
4278,
1101,
687,
376,
3734,
1750,
199,
571,
14,
888,
14,
873,
8,
807,
8,
272,
31705,
29,
736,
14,
515,
14,
904,
8,
571,
14,
1231,
63,
515,
12,
283,
15720,
82,
14,
697,
659,
272,
10990,
29,
549,
12,
272,
5795,
11771,
63,
3078,
534,
31688,
790,
297,
272,
13044,
2339,
534,
2113,
297,
272,
21705,
5172,
534,
885,
7,
199,
430,
199,
571,
14,
888,
14,
504,
63,
1813,
1391,
360,
3143,
7946,
50,
63,
13931,
297,
10866,
29,
549,
9,
421,
199,
318,
4907,
63,
697,
837,
272,
408,
8631,
83,
370,
314,
2488,
3050,
1041,
272,
4336,
275,
11723,
19,
14,
2242,
8,
571,
14,
888,
459,
17873,
1105,
272,
4336,
14,
1143,
63,
3702,
275,
11723,
19,
14,
5810,
272,
372,
4336,
421,
199,
318,
4205,
63,
697,
837,
272,
408,
23489,
314,
3050,
1041,
272,
1592,
275,
664,
63,
697,
342,
272,
543,
1145,
14,
1490,
63,
1927,
360,
3629,
14,
3009,
297,
818,
534,
82,
358,
465,
289,
26,
267,
1592,
14,
3937,
1252,
2526,
1579,
8,
70,
14,
739,
1012,
272,
1592,
14,
3543,
342,
421,
199,
32,
571,
14,
2764,
14,
1531,
360,
826,
697,
358,
199,
318,
4205,
697,
63,
1531,
837,
272,
408,
10607,
314,
3050,
6716,
1041,
272,
4205,
63,
697,
342,
272,
870,
360,
23031,
314,
3050,
2659,
421,
199,
318,
664,
63,
697,
837,
272,
408,
4299,
83,
282,
892,
3050,
1950,
340,
2337,
365,
7179,
5966,
367,
314,
272,
1453,
4223,
1067,
14,
272,
408,
272,
340,
440,
2688,
8,
71,
12,
283,
10659,
63,
697,
735,
267,
486,
14,
10659,
63,
697,
275,
4907,
63,
697,
342,
272,
372,
486,
14,
10659,
63,
697,
421,
199,
32,
571,
14,
15236,
63,
571,
1100,
199,
318,
4002,
63,
697,
8,
705,
304,
272,
408,
3337,
874,
314,
3050,
4020,
737,
314,
1284,
402,
314,
1056,
1041,
272,
340,
2688,
8,
71,
12,
283,
10659,
63,
697,
735,
267,
486,
14,
10659,
63,
697,
14,
1600,
342,
421,
199,
32,
571,
14,
4449,
7825,
199,
318,
2498,
63,
3189,
837,
272,
1592,
275,
664,
63,
697,
342,
272,
1094,
275,
1592,
14,
2526,
360,
2416,
2538,
12,
1318,
687,
4811,
1865,
701,
1305,
4328,
358,
272,
4811,
275,
1094,
14,
10174,
342,
272,
372,
3795,
63,
1160,
360,
2384,
63,
3189,
14,
1360,
297,
4811,
29,
3189,
9,
421,
199,
32,
571,
14,
4449,
2336,
525,
297,
3102,
2968,
4030,
1105,
199,
318,
1050,
63,
2373,
837,
272,
340,
440,
2351,
14,
362,
360,
12419,
63,
262,
735,
267,
12004,
8,
8854,
9,
272,
1592,
275,
664,
63,
697,
342,
272,
1592,
14,
2526,
360,
3176,
1901,
4811,
334,
1213,
12,
1318,
9,
1338,
7558,
12,
5805,
3196,
2049,
359,
1069,
14,
964,
459,
1213,
995,
1056,
14,
964,
459,
505,
12121,
272,
1592,
14,
3543,
342,
272,
14775,
360,
4665,
2397,
1990,
8792,
22752,
358,
272,
372,
4660,
8,
633,
63,
509,
360,
2384,
63,
3189,
1333,
421,
199,
32,
571,
14,
4449,
2336,
2886,
297,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
4676,
837,
272,
1125,
275,
488,
272,
340,
1056,
14,
765,
508,
283,
4030,
356,
267,
340,
1056,
14,
964,
459,
2473,
418,
1137,
1145,
14,
888,
459,
11958,
2565,
288,
1125,
275,
283,
3364,
3434,
7,
267,
916,
1056,
14,
964,
459,
2060,
418,
1137,
1145,
14,
888,
459,
9032,
2565,
288,
1125,
275,
283,
3364,
2505,
7,
267,
587,
26,
288,
2351,
459,
12419,
63,
262,
418,
275,
715,
288,
14775,
360,
5556,
4898,
10367,
315,
358,
288,
372,
4660,
8,
633,
63,
509,
360,
2384,
63,
3189,
1333,
272,
372,
3795,
63,
1160,
360,
2886,
14,
1360,
297,
1125,
29,
705,
9,
421,
199,
32,
571,
14,
4449,
2336,
11646,
358,
199,
318,
22079,
837,
272,
2351,
14,
1935,
360,
12419,
63,
262,
297,
488,
9,
272,
14775,
360,
5556,
4898,
10367,
734,
358,
272,
372,
4660,
8,
633,
63,
509,
360,
2384,
63,
3189,
1333,
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,
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,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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
] |
feibaliang/blog
|
node_modules/pygmentize-bundled/vendor/pygments/build-3.3/pygments/lexers/web.py
|
94
|
155814
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.web
~~~~~~~~~~~~~~~~~~~
Lexers for web-related languages and markup.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import copy
from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \
include, this
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Other, Punctuation, Literal
from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
html_doctype_matches, unirange
from pygments.lexers.agile import RubyLexer
from pygments.lexers.compiled import ScalaLexer
__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JsonLexer', 'CssLexer',
'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer',
'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer',
'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer',
'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer',
'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer']
class JavascriptLexer(RegexLexer):
"""
For JavaScript source code.
"""
name = 'JavaScript'
aliases = ['js', 'javascript']
filenames = ['*.js', ]
mimetypes = ['application/javascript', 'application/x-javascript',
'text/x-javascript', 'text/javascript', ]
flags = re.DOTALL
tokens = {
'commentsandwhitespace': [
(r'\s+', Text),
(r'<!--', Comment),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline)
],
'slashstartsregex': [
include('commentsandwhitespace'),
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'(?=/)', Text, ('#pop', 'badregex')),
(r'', Text, '#pop')
],
'badregex': [
(r'\n', Text, '#pop')
],
'root': [
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|'
r'this)\b', Keyword, 'slashstartsregex'),
(r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
(r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
r'extends|final|float|goto|implements|import|int|interface|long|native|'
r'package|private|protected|public|short|static|super|synchronized|throws|'
r'transient|volatile)\b', Keyword.Reserved),
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
r'decodeURIComponent|encodeURI|encodeURIComponent|'
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
r'window)\b', Name.Builtin),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-fA-F]+', Number.Hex),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
]
}
class JsonLexer(RegexLexer):
"""
For JSON data structures.
*New in Pygments 1.5.*
"""
name = 'JSON'
aliases = ['json']
filenames = ['*.json']
mimetypes = [ 'application/json', ]
# integer part of a number
int_part = r'-?(0|[1-9]\d*)'
# fractional part of a number
frac_part = r'\.\d+'
# exponential part of a number
exp_part = r'[eE](\+|-)?\d+'
flags = re.DOTALL
tokens = {
'whitespace': [
(r'\s+', Text),
],
# represents a simple terminal value
'simplevalue': [
(r'(true|false|null)\b', Keyword.Constant),
(('%(int_part)s(%(frac_part)s%(exp_part)s|'
'%(exp_part)s|%(frac_part)s)') % vars(),
Number.Float),
(int_part, Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
],
# the right hand side of an object, after the attribute name
'objectattribute': [
include('value'),
(r':', Punctuation),
# comma terminates the attribute but expects more
(r',', Punctuation, '#pop'),
# a closing bracket terminates the entire object, so pop twice
(r'}', Punctuation, ('#pop', '#pop')),
],
# a json object - { attr, attr, ... }
'objectvalue': [
include('whitespace'),
(r'"(\\\\|\\"|[^"])*"', Name.Tag, 'objectattribute'),
(r'}', Punctuation, '#pop'),
],
# json array - [ value, value, ... }
'arrayvalue': [
include('whitespace'),
include('value'),
(r',', Punctuation),
(r']', Punctuation, '#pop'),
],
# a json value - either a simple value or a complex value (object or array)
'value': [
include('whitespace'),
include('simplevalue'),
(r'{', Punctuation, 'objectvalue'),
(r'\[', Punctuation, 'arrayvalue'),
],
# the root of a json document whould be a value
'root': [
include('value'),
],
}
JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5
class ActionScriptLexer(RegexLexer):
"""
For ActionScript source code.
*New in Pygments 0.9.*
"""
name = 'ActionScript'
aliases = ['as', 'actionscript']
filenames = ['*.as']
mimetypes = ['application/x-actionscript3', 'text/x-actionscript3',
'text/actionscript3']
flags = re.DOTALL
tokens = {
'root': [
(r'\s+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex),
(r'[~\^\*!%&<>\|+=:;,/?\\-]+', Operator),
(r'[{}\[\]();.]+', Punctuation),
(r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
r'throw|try|catch|var|with|new|typeof|arguments|instanceof|this|'
r'switch)\b', Keyword),
(r'(class|public|final|internal|native|override|private|protected|'
r'static|import|extends|implements|interface|intrinsic|return|super|'
r'dynamic|function|const|get|namespace|package|set)\b',
Keyword.Declaration),
(r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b',
Keyword.Constant),
(r'(Accessibility|AccessibilityProperties|ActionScriptVersion|'
r'ActivityEvent|AntiAliasType|ApplicationDomain|AsBroadcaster|Array|'
r'AsyncErrorEvent|AVM1Movie|BevelFilter|Bitmap|BitmapData|'
r'BitmapDataChannel|BitmapFilter|BitmapFilterQuality|BitmapFilterType|'
r'BlendMode|BlurFilter|Boolean|ByteArray|Camera|Capabilities|CapsStyle|'
r'Class|Color|ColorMatrixFilter|ColorTransform|ContextMenu|'
r'ContextMenuBuiltInItems|ContextMenuEvent|ContextMenuItem|'
r'ConvultionFilter|CSMSettings|DataEvent|Date|DefinitionError|'
r'DeleteObjectSample|Dictionary|DisplacmentMapFilter|DisplayObject|'
r'DisplacmentMapFilterMode|DisplayObjectContainer|DropShadowFilter|'
r'Endian|EOFError|Error|ErrorEvent|EvalError|Event|EventDispatcher|'
r'EventPhase|ExternalInterface|FileFilter|FileReference|'
r'FileReferenceList|FocusDirection|FocusEvent|Font|FontStyle|FontType|'
r'FrameLabel|FullScreenEvent|Function|GlowFilter|GradientBevelFilter|'
r'GradientGlowFilter|GradientType|Graphics|GridFitType|HTTPStatusEvent|'
r'IBitmapDrawable|ID3Info|IDataInput|IDataOutput|IDynamicPropertyOutput'
r'IDynamicPropertyWriter|IEventDispatcher|IExternalizable|'
r'IllegalOperationError|IME|IMEConversionMode|IMEEvent|int|'
r'InteractiveObject|InterpolationMethod|InvalidSWFError|InvokeEvent|'
r'IOError|IOErrorEvent|JointStyle|Key|Keyboard|KeyboardEvent|KeyLocation|'
r'LineScaleMode|Loader|LoaderContext|LoaderInfo|LoadVars|LocalConnection|'
r'Locale|Math|Matrix|MemoryError|Microphone|MorphShape|Mouse|MouseEvent|'
r'MovieClip|MovieClipLoader|Namespace|NetConnection|NetStatusEvent|'
r'NetStream|NewObjectSample|Number|Object|ObjectEncoding|PixelSnapping|'
r'Point|PrintJob|PrintJobOptions|PrintJobOrientation|ProgressEvent|Proxy|'
r'QName|RangeError|Rectangle|ReferenceError|RegExp|Responder|Sample|Scene|'
r'ScriptTimeoutError|Security|SecurityDomain|SecurityError|'
r'SecurityErrorEvent|SecurityPanel|Selection|Shape|SharedObject|'
r'SharedObjectFlushStatus|SimpleButton|Socket|Sound|SoundChannel|'
r'SoundLoaderContext|SoundMixer|SoundTransform|SpreadMethod|Sprite|'
r'StackFrame|StackOverflowError|Stage|StageAlign|StageDisplayState|'
r'StageQuality|StageScaleMode|StaticText|StatusEvent|String|StyleSheet|'
r'SWFVersion|SyncEvent|SyntaxError|System|TextColorType|TextField|'
r'TextFieldAutoSize|TextFieldType|TextFormat|TextFormatAlign|'
r'TextLineMetrics|TextRenderer|TextSnapshot|Timer|TimerEvent|Transform|'
r'TypeError|uint|URIError|URLLoader|URLLoaderDataFormat|URLRequest|'
r'URLRequestHeader|URLRequestMethod|URLStream|URLVariabeles|VerifyError|'
r'Video|XML|XMLDocument|XMLList|XMLNode|XMLNodeType|XMLSocket|XMLUI)\b',
Name.Builtin),
(r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
r'unescape)\b',Name.Function),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-f]+', Number.Hex),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
]
}
class ActionScript3Lexer(RegexLexer):
"""
For ActionScript 3 source code.
*New in Pygments 0.11.*
"""
name = 'ActionScript 3'
aliases = ['as3', 'actionscript3']
filenames = ['*.as']
mimetypes = ['application/x-actionscript', 'text/x-actionscript',
'text/actionscript']
identifier = r'[$a-zA-Z_][a-zA-Z0-9_]*'
typeidentifier = identifier + '(?:\.<\w+>)?'
flags = re.DOTALL | re.MULTILINE
tokens = {
'root': [
(r'\s+', Text),
(r'(function\s+)(' + identifier + r')(\s*)(\()',
bygroups(Keyword.Declaration, Name.Function, Text, Operator),
'funcparams'),
(r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' +
typeidentifier + r')',
bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text,
Keyword.Type)),
(r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)',
bygroups(Keyword, Text, Name.Namespace, Text)),
(r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()',
bygroups(Keyword, Text, Keyword.Type, Text, Operator)),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex),
(r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)),
(r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
r'throw|try|catch|with|new|typeof|arguments|instanceof|this|'
r'switch|import|include|as|is)\b',
Keyword),
(r'(class|public|final|internal|native|override|private|protected|'
r'static|import|extends|implements|interface|intrinsic|return|super|'
r'dynamic|function|const|get|namespace|package|set)\b',
Keyword.Declaration),
(r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b',
Keyword.Constant),
(r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
r'unescape)\b', Name.Function),
(identifier, Name),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-f]+', Number.Hex),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r'[~\^\*!%&<>\|+=:;,/?\\{}\[\]().-]+', Operator),
],
'funcparams': [
(r'\s+', Text),
(r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' +
typeidentifier + r'|\*)(\s*)',
bygroups(Text, Punctuation, Name, Text, Operator, Text,
Keyword.Type, Text), 'defval'),
(r'\)', Operator, 'type')
],
'type': [
(r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)',
bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'),
(r'\s*', Text, '#pop:2')
],
'defval': [
(r'(=)(\s*)([^(),]+)(\s*)(,?)',
bygroups(Operator, Text, using(this), Text, Operator), '#pop'),
(r',?', Operator, '#pop')
]
}
def analyse_text(text):
if re.match(r'\w+\s*:\s*\w', text):
return 0.3
return 0
class CssLexer(RegexLexer):
"""
For CSS (Cascading Style Sheets).
"""
name = 'CSS'
aliases = ['css']
filenames = ['*.css']
mimetypes = ['text/css']
tokens = {
'root': [
include('basics'),
],
'basics': [
(r'\s+', Text),
(r'/\*(?:.|\n)*?\*/', Comment),
(r'{', Punctuation, 'content'),
(r'\:[a-zA-Z0-9_-]+', Name.Decorator),
(r'\.[a-zA-Z0-9_-]+', Name.Class),
(r'\#[a-zA-Z0-9_-]+', Name.Function),
(r'@[a-zA-Z0-9_-]+', Keyword, 'atrule'),
(r'[a-zA-Z0-9_-]+', Name.Tag),
(r'[~\^\*!%&\[\]\(\)<>\|+=@:;,./?-]', Operator),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single)
],
'atrule': [
(r'{', Punctuation, 'atcontent'),
(r';', Punctuation, '#pop'),
include('basics'),
],
'atcontent': [
include('basics'),
(r'}', Punctuation, '#pop:2'),
],
'content': [
(r'\s+', Text),
(r'}', Punctuation, '#pop'),
(r'url\(.*?\)', String.Other),
(r'^@.*?$', Comment.Preproc),
(r'(azimuth|background-attachment|background-color|'
r'background-image|background-position|background-repeat|'
r'background|border-bottom-color|border-bottom-style|'
r'border-bottom-width|border-left-color|border-left-style|'
r'border-left-width|border-right|border-right-color|'
r'border-right-style|border-right-width|border-top-color|'
r'border-top-style|border-top-width|border-bottom|'
r'border-collapse|border-left|border-width|border-color|'
r'border-spacing|border-style|border-top|border|caption-side|'
r'clear|clip|color|content|counter-increment|counter-reset|'
r'cue-after|cue-before|cue|cursor|direction|display|'
r'elevation|empty-cells|float|font-family|font-size|'
r'font-size-adjust|font-stretch|font-style|font-variant|'
r'font-weight|font|height|letter-spacing|line-height|'
r'list-style-type|list-style-image|list-style-position|'
r'list-style|margin-bottom|margin-left|margin-right|'
r'margin-top|margin|marker-offset|marks|max-height|max-width|'
r'min-height|min-width|opacity|orphans|outline|outline-color|'
r'outline-style|outline-width|overflow(?:-x|-y)?|padding-bottom|'
r'padding-left|padding-right|padding-top|padding|page|'
r'page-break-after|page-break-before|page-break-inside|'
r'pause-after|pause-before|pause|pitch|pitch-range|'
r'play-during|position|quotes|richness|right|size|'
r'speak-header|speak-numeral|speak-punctuation|speak|'
r'speech-rate|stress|table-layout|text-align|text-decoration|'
r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
r'vertical-align|visibility|voice-family|volume|white-space|'
r'widows|width|word-spacing|z-index|bottom|left|'
r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
r'behind|below|bidi-override|blink|block|bold|bolder|both|'
r'capitalize|center-left|center-right|center|circle|'
r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
r'inherit|inline-table|inline|inset|inside|invert|italic|'
r'justify|katakana-iroha|katakana|landscape|larger|large|'
r'left-side|leftwards|level|lighter|line-through|list-item|'
r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
r'lower|low|medium|message-box|middle|mix|monospace|'
r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
r'open-quote|outset|outside|overline|pointer|portrait|px|'
r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
r'rightwards|s-resize|sans-serif|scroll|se-resize|'
r'semi-condensed|semi-expanded|separate|serif|show|silent|'
r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
r'spell-out|square|static|status-bar|super|sw-resize|'
r'table-caption|table-cell|table-column|table-column-group|'
r'table-footer-group|table-header-group|table-row|'
r'table-row-group|text|text-bottom|text-top|thick|thin|'
r'transparent|ultra-condensed|ultra-expanded|underline|'
r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Keyword),
(r'(indigo|gold|firebrick|indianred|yellow|darkolivegreen|'
r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
r'mediumslateblue|black|springgreen|crimson|lightsalmon|brown|'
r'turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|'
r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|'
r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
r'violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|'
r'darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|'
r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
r'gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|'
r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
r'lightcoral|orangered|navajowhite|lime|palegreen|burlywood|'
r'seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|'
r'peru|aquamarine|white|darkslategray|ivory|dodgerblue|'
r'lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|'
r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
r'plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|'
r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
r'lightyellow|lavenderblush|linen|mediumaquamarine|green|'
r'blueviolet|peachpuff)\b', Name.Builtin),
(r'\!important', Comment.Preproc),
(r'/\*(?:.|\n)*?\*/', Comment),
(r'\#[a-zA-Z0-9]{1,6}', Number),
(r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex|s)\b', Number),
(r'-?[0-9]+', Number),
(r'[~\^\*!%&<>\|+=@:,./?-]+', Operator),
(r'[\[\]();]+', Punctuation),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name)
]
}
class ObjectiveJLexer(RegexLexer):
"""
For Objective-J source code with preprocessor directives.
*New in Pygments 1.3.*
"""
name = 'Objective-J'
aliases = ['objective-j', 'objectivej', 'obj-j', 'objj']
filenames = ['*.j']
mimetypes = ['text/x-objective-j']
#: optional Comment or Whitespace
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*'
flags = re.DOTALL | re.MULTILINE
tokens = {
'root': [
include('whitespace'),
# function definition
(r'^(' + _ws + r'[\+-]' + _ws + r')([\(a-zA-Z_].*?[^\(])(' + _ws + '{)',
bygroups(using(this), using(this, state='function_signature'),
using(this))),
# class definition
(r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
'classname'),
(r'(@class|@protocol)(\s*)', bygroups(Keyword, Text),
'forward_classname'),
(r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
include('statements'),
('[{\(\)}]', Punctuation),
(';', Punctuation),
],
'whitespace': [
(r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")',
bygroups(Comment.Preproc, Text, String.Double)),
(r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)',
bygroups(Comment.Preproc, Text, String.Double)),
(r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")',
bygroups(Comment.Preproc, Text, String.Double)),
(r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)',
bygroups(Comment.Preproc, Text, String.Double)),
(r'#if\s+0', Comment.Preproc, 'if0'),
(r'#', Comment.Preproc, 'macro'),
(r'\n', Text),
(r'\s+', Text),
(r'\\\n', Text), # line continuation
(r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
(r'<!--', Comment),
],
'slashstartsregex': [
include('whitespace'),
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'(?=/)', Text, ('#pop', 'badregex')),
(r'', Text, '#pop'),
],
'badregex': [
(r'\n', Text, '#pop'),
],
'statements': [
(r'(L|@)?"', String, 'string'),
(r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
String.Char),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
(r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
(r'0[0-7]+[Ll]?', Number.Oct),
(r'\d+[Ll]?', Number.Integer),
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?',
Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(for|in|while|do|break|return|continue|switch|case|default|if|'
r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
r'prototype|__proto__)\b', Keyword, 'slashstartsregex'),
(r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
(r'(@selector|@private|@protected|@public|@encode|'
r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword),
(r'(int|long|float|short|double|char|unsigned|signed|void|'
r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b',
Keyword.Type),
(r'(self|super)\b', Name.Builtin),
(r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant),
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
(r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|'
r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|'
r'SQRT2)\b', Keyword.Constant),
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
r'decodeURIComponent|encodeURI|encodeURIComponent|'
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
r'window)\b', Name.Builtin),
(r'([$a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r')(?=\()',
bygroups(Name.Function, using(this))),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name),
],
'classname' : [
# interface definition that inherits
(r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r':' + _ws +
r')([a-zA-Z_][a-zA-Z0-9_]*)?',
bygroups(Name.Class, using(this), Name.Class), '#pop'),
# interface definition for a category
(r'([a-zA-Z_][a-zA-Z0-9_]*)(' + _ws + r'\()([a-zA-Z_][a-zA-Z0-9_]*)(\))',
bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
# simple interface / implementation
(r'([a-zA-Z_][a-zA-Z0-9_]*)', Name.Class, '#pop'),
],
'forward_classname' : [
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*,\s*)',
bygroups(Name.Class, Text), '#push'),
(r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*;?)',
bygroups(Name.Class, Text), '#pop'),
],
'function_signature': [
include('whitespace'),
# start of a selector w/ parameters
(r'(\(' + _ws + r')' # open paren
r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
r'(' + _ws + r'\)' + _ws + r')' # close paren
r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
bygroups(using(this), Keyword.Type, using(this),
Name.Function), 'function_parameters'),
# no-param function
(r'(\(' + _ws + r')' # open paren
r'([a-zA-Z_][a-zA-Z0-9_]+)' # return type
r'(' + _ws + r'\)' + _ws + r')' # close paren
r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
bygroups(using(this), Keyword.Type, using(this),
Name.Function), "#pop"),
# no return type given, start of a selector w/ parameters
(r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
bygroups (Name.Function), 'function_parameters'),
# no return type given, no-param function
(r'([$a-zA-Z_][a-zA-Z0-9_]+)', # function name
bygroups(Name.Function), "#pop"),
('', Text, '#pop'),
],
'function_parameters': [
include('whitespace'),
# parameters
(r'(\(' + _ws + ')' # open paren
r'([^\)]+)' # type
r'(' + _ws + r'\)' + _ws + r')' # close paren
r'([$a-zA-Z_][a-zA-Z0-9_]+)', # param name
bygroups(using(this), Keyword.Type, using(this), Text)),
# one piece of a selector name
(r'([$a-zA-Z_][a-zA-Z0-9_]+' + _ws + r':)', # function name
Name.Function),
# smallest possible selector piece
(r'(:)', Name.Function),
# var args
(r'(,' + _ws + r'\.\.\.)', using(this)),
# param name
(r'([$a-zA-Z_][a-zA-Z0-9_]+)', Text),
],
'expression' : [
(r'([$a-zA-Z_][a-zA-Z0-9_]*)(\()', bygroups(Name.Function,
Punctuation)),
(r'(\))', Punctuation, "#pop"),
],
'string': [
(r'"', String, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
(r'[^\\"\n]+', String), # all other characters
(r'\\\n', String), # line continuation
(r'\\', String), # stray backslash
],
'macro': [
(r'[^/\n]+', Comment.Preproc),
(r'/[*](.|\n)*?[*]/', Comment.Multiline),
(r'//.*?\n', Comment.Single, '#pop'),
(r'/', Comment.Preproc),
(r'(?<=\\)\n', Comment.Preproc),
(r'\n', Comment.Preproc, '#pop'),
],
'if0': [
(r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
(r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
(r'.*?\n', Comment),
]
}
def analyse_text(text):
if re.search('^\s*@import\s+[<"]', text, re.MULTILINE):
# special directive found in most Objective-J files
return True
return False
class HtmlLexer(RegexLexer):
"""
For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted
by the appropriate lexer.
"""
name = 'HTML'
aliases = ['html']
filenames = ['*.html', '*.htm', '*.xhtml', '*.xslt']
mimetypes = ['text/html', 'application/xhtml+xml']
flags = re.IGNORECASE | re.DOTALL
tokens = {
'root': [
('[^<&]+', Text),
(r'&\S*?;', Name.Entity),
(r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc),
('<!--', Comment, 'comment'),
(r'<\?.*?\?>', Comment.Preproc),
('<![^>]*>', Comment.Preproc),
(r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
(r'<\s*style\s*', Name.Tag, ('style-content', 'tag')),
# note: this allows tag names not used in HTML like <x:with-dash>,
# this is to support yet-unknown template engines and the like
(r'<\s*[\w:.-]+', Name.Tag, 'tag'),
(r'<\s*/\s*[\w:.-]+\s*>', Name.Tag),
],
'comment': [
('[^-]+', Comment),
('-->', Comment, '#pop'),
('-', Comment),
],
'tag': [
(r'\s+', Text),
(r'[a-zA-Z0-9_:-]+\s*=', Name.Attribute, 'attr'),
(r'[a-zA-Z0-9_:-]+', Name.Attribute),
(r'/?\s*>', Name.Tag, '#pop'),
],
'script-content': [
(r'<\s*/\s*script\s*>', Name.Tag, '#pop'),
(r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)),
],
'style-content': [
(r'<\s*/\s*style\s*>', Name.Tag, '#pop'),
(r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)),
],
'attr': [
('".*?"', String, '#pop'),
("'.*?'", String, '#pop'),
(r'[^\s>]+', String, '#pop'),
],
}
def analyse_text(text):
if html_doctype_matches(text):
return 0.5
class PhpLexer(RegexLexer):
"""
For `PHP <http://www.php.net/>`_ source code.
For PHP embedded in HTML, use the `HtmlPhpLexer`.
Additional options accepted:
`startinline`
If given and ``True`` the lexer starts highlighting with
php code (i.e.: no starting ``<?php`` required). The default
is ``False``.
`funcnamehighlighting`
If given and ``True``, highlight builtin function names
(default: ``True``).
`disabledmodules`
If given, must be a list of module names whose function names
should not be highlighted. By default all modules are highlighted
except the special ``'unknown'`` module that includes functions
that are known to php but are undocumented.
To get a list of allowed modules have a look into the
`_phpbuiltins` module:
.. sourcecode:: pycon
>>> from pygments.lexers._phpbuiltins import MODULES
>>> MODULES.keys()
['PHP Options/Info', 'Zip', 'dba', ...]
In fact the names of those modules match the module names from
the php documentation.
"""
name = 'PHP'
aliases = ['php', 'php3', 'php4', 'php5']
filenames = ['*.php', '*.php[345]', '*.inc']
mimetypes = ['text/x-php']
flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
tokens = {
'root': [
(r'<\?(php)?', Comment.Preproc, 'php'),
(r'[^<]+', Other),
(r'<', Other)
],
'php': [
(r'\?>', Comment.Preproc, '#pop'),
(r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String),
(r'\s+', Text),
(r'#.*?\n', Comment.Single),
(r'//.*?\n', Comment.Single),
# put the empty comment here, it is otherwise seen as
# the start of a docstring
(r'/\*\*/', Comment.Multiline),
(r'/\*\*.*?\*/', String.Doc),
(r'/\*.*?\*/', Comment.Multiline),
(r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)',
bygroups(Operator, Text, Name.Attribute)),
(r'[~!%^&*+=|:.<>/?@-]+', Operator),
(r'[\[\]{}();,]+', Punctuation),
(r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
(r'(function)(\s*)(?=\()', bygroups(Keyword, Text)),
(r'(function)(\s+)(&?)(\s*)',
bygroups(Keyword, Text, Operator, Text), 'functionname'),
(r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
bygroups(Keyword, Text, Name.Constant)),
(r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|'
r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|'
r'FALSE|print|for|require|continue|foreach|require_once|'
r'declare|return|default|static|do|switch|die|stdClass|'
r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|'
r'virtual|endfor|include_once|while|endforeach|global|__FILE__|'
r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|'
r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|'
r'implements|public|private|protected|abstract|clone|try|'
r'catch|throw|this|use|namespace|trait)\b', Keyword),
(r'(true|false|null)\b', Keyword.Constant),
(r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable),
(r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
(r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other),
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
(r'\d+[eE][+-]?[0-9]+', Number.Float),
(r'0[0-7]+', Number.Oct),
(r'0[xX][a-fA-F0-9]+', Number.Hex),
(r'\d+', Number.Integer),
(r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single),
(r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick),
(r'"', String.Double, 'string'),
],
'classname': [
(r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop')
],
'functionname': [
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
],
'string': [
(r'"', String.Double, '#pop'),
(r'[^{$"\\]+', String.Double),
(r'\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape),
(r'\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?',
String.Interpol),
(r'(\{\$\{)(.*?)(\}\})',
bygroups(String.Interpol, using(this, _startinline=True),
String.Interpol)),
(r'(\{)(\$.*?)(\})',
bygroups(String.Interpol, using(this, _startinline=True),
String.Interpol)),
(r'(\$\{)(\S+)(\})',
bygroups(String.Interpol, Name.Variable, String.Interpol)),
(r'[${\\]+', String.Double)
],
}
def __init__(self, **options):
self.funcnamehighlighting = get_bool_opt(
options, 'funcnamehighlighting', True)
self.disabledmodules = get_list_opt(
options, 'disabledmodules', ['unknown'])
self.startinline = get_bool_opt(options, 'startinline', False)
# private option argument for the lexer itself
if '_startinline' in options:
self.startinline = options.pop('_startinline')
# collect activated functions in a set
self._functions = set()
if self.funcnamehighlighting:
from pygments.lexers._phpbuiltins import MODULES
for key, value in MODULES.items():
if key not in self.disabledmodules:
self._functions.update(value)
RegexLexer.__init__(self, **options)
def get_tokens_unprocessed(self, text):
stack = ['root']
if self.startinline:
stack.append('php')
for index, token, value in \
RegexLexer.get_tokens_unprocessed(self, text, stack):
if token is Name.Other:
if value in self._functions:
yield index, Name.Builtin, value
continue
yield index, token, value
def analyse_text(text):
rv = 0.0
if re.search(r'<\?(?!xml)', text):
rv += 0.3
if '?>' in text:
rv += 0.1
return rv
class DtdLexer(RegexLexer):
"""
A lexer for DTDs (Document Type Definitions).
*New in Pygments 1.5.*
"""
flags = re.MULTILINE | re.DOTALL
name = 'DTD'
aliases = ['dtd']
filenames = ['*.dtd']
mimetypes = ['application/xml-dtd']
tokens = {
'root': [
include('common'),
(r'(<!ELEMENT)(\s+)(\S+)',
bygroups(Keyword, Text, Name.Tag), 'element'),
(r'(<!ATTLIST)(\s+)(\S+)',
bygroups(Keyword, Text, Name.Tag), 'attlist'),
(r'(<!ENTITY)(\s+)(\S+)',
bygroups(Keyword, Text, Name.Entity), 'entity'),
(r'(<!NOTATION)(\s+)(\S+)',
bygroups(Keyword, Text, Name.Tag), 'notation'),
(r'(<!\[)([^\[\s]+)(\s*)(\[)', # conditional sections
bygroups(Keyword, Name.Entity, Text, Keyword)),
(r'(<!DOCTYPE)(\s+)([^>\s]+)',
bygroups(Keyword, Text, Name.Tag)),
(r'PUBLIC|SYSTEM', Keyword.Constant),
(r'[\[\]>]', Keyword),
],
'common': [
(r'\s+', Text),
(r'(%|&)[^;]*;', Name.Entity),
('<!--', Comment, 'comment'),
(r'[(|)*,?+]', Operator),
(r'"[^"]*"', String.Double),
(r'\'[^\']*\'', String.Single),
],
'comment': [
('[^-]+', Comment),
('-->', Comment, '#pop'),
('-', Comment),
],
'element': [
include('common'),
(r'EMPTY|ANY|#PCDATA', Keyword.Constant),
(r'[^>\s\|()?+*,]+', Name.Tag),
(r'>', Keyword, '#pop'),
],
'attlist': [
include('common'),
(r'CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION',
Keyword.Constant),
(r'#REQUIRED|#IMPLIED|#FIXED', Keyword.Constant),
(r'xml:space|xml:lang', Keyword.Reserved),
(r'[^>\s\|()?+*,]+', Name.Attribute),
(r'>', Keyword, '#pop'),
],
'entity': [
include('common'),
(r'SYSTEM|PUBLIC|NDATA', Keyword.Constant),
(r'[^>\s\|()?+*,]+', Name.Entity),
(r'>', Keyword, '#pop'),
],
'notation': [
include('common'),
(r'SYSTEM|PUBLIC', Keyword.Constant),
(r'[^>\s\|()?+*,]+', Name.Attribute),
(r'>', Keyword, '#pop'),
],
}
def analyse_text(text):
if not looks_like_xml(text) and \
('<!ELEMENT' in text or '<!ATTLIST' in text or '<!ENTITY' in text):
return 0.8
class XmlLexer(RegexLexer):
"""
Generic lexer for XML (eXtensible Markup Language).
"""
flags = re.MULTILINE | re.DOTALL | re.UNICODE
name = 'XML'
aliases = ['xml']
filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd',
'*.wsdl', '*.wsf']
mimetypes = ['text/xml', 'application/xml', 'image/svg+xml',
'application/rss+xml', 'application/atom+xml']
tokens = {
'root': [
('[^<&]+', Text),
(r'&\S*?;', Name.Entity),
(r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc),
('<!--', Comment, 'comment'),
(r'<\?.*?\?>', Comment.Preproc),
('<![^>]*>', Comment.Preproc),
(r'<\s*[\w:.-]+', Name.Tag, 'tag'),
(r'<\s*/\s*[\w:.-]+\s*>', Name.Tag),
],
'comment': [
('[^-]+', Comment),
('-->', Comment, '#pop'),
('-', Comment),
],
'tag': [
(r'\s+', Text),
(r'[\w.:-]+\s*=', Name.Attribute, 'attr'),
(r'/?\s*>', Name.Tag, '#pop'),
],
'attr': [
('\s+', Text),
('".*?"', String, '#pop'),
("'.*?'", String, '#pop'),
(r'[^\s>]+', String, '#pop'),
],
}
def analyse_text(text):
if looks_like_xml(text):
return 0.5
class XsltLexer(XmlLexer):
'''
A lexer for XSLT.
*New in Pygments 0.10.*
'''
name = 'XSLT'
aliases = ['xslt']
filenames = ['*.xsl', '*.xslt', '*.xpl'] # xpl is XProc
mimetypes = ['application/xsl+xml', 'application/xslt+xml']
EXTRA_KEYWORDS = set([
'apply-imports', 'apply-templates', 'attribute',
'attribute-set', 'call-template', 'choose', 'comment',
'copy', 'copy-of', 'decimal-format', 'element', 'fallback',
'for-each', 'if', 'import', 'include', 'key', 'message',
'namespace-alias', 'number', 'otherwise', 'output', 'param',
'preserve-space', 'processing-instruction', 'sort',
'strip-space', 'stylesheet', 'template', 'text', 'transform',
'value-of', 'variable', 'when', 'with-param'
])
def get_tokens_unprocessed(self, text):
for index, token, value in XmlLexer.get_tokens_unprocessed(self, text):
m = re.match('</?xsl:([^>]*)/?>?', value)
if token is Name.Tag and m and m.group(1) in self.EXTRA_KEYWORDS:
yield index, Keyword, value
else:
yield index, token, value
def analyse_text(text):
if looks_like_xml(text) and '<xsl' in text:
return 0.8
class MxmlLexer(RegexLexer):
"""
For MXML markup.
Nested AS3 in <script> tags is highlighted by the appropriate lexer.
*New in Pygments 1.1.*
"""
flags = re.MULTILINE | re.DOTALL
name = 'MXML'
aliases = ['mxml']
filenames = ['*.mxml']
mimetimes = ['text/xml', 'application/xml']
tokens = {
'root': [
('[^<&]+', Text),
(r'&\S*?;', Name.Entity),
(r'(\<\!\[CDATA\[)(.*?)(\]\]\>)',
bygroups(String, using(ActionScript3Lexer), String)),
('<!--', Comment, 'comment'),
(r'<\?.*?\?>', Comment.Preproc),
('<![^>]*>', Comment.Preproc),
(r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'),
(r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag),
],
'comment': [
('[^-]+', Comment),
('-->', Comment, '#pop'),
('-', Comment),
],
'tag': [
(r'\s+', Text),
(r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'),
(r'/?\s*>', Name.Tag, '#pop'),
],
'attr': [
('\s+', Text),
('".*?"', String, '#pop'),
("'.*?'", String, '#pop'),
(r'[^\s>]+', String, '#pop'),
],
}
class HaxeLexer(ExtendedRegexLexer):
"""
For Haxe source code (http://haxe.org/).
*New in Pygments 1.3.*
"""
name = 'Haxe'
aliases = ['hx', 'Haxe', 'haxe', 'haXe', 'hxsl']
filenames = ['*.hx', '*.hxsl']
mimetypes = ['text/haxe', 'text/x-haxe', 'text/x-hx']
# keywords extracted from lexer.mll in the haxe compiler source
keyword = (r'(?:function|class|static|var|if|else|while|do|for|'
r'break|return|continue|extends|implements|import|'
r'switch|case|default|public|private|try|untyped|'
r'catch|new|this|throw|extern|enum|in|interface|'
r'cast|override|dynamic|typedef|package|'
r'inline|using|null|true|false|abstract)\b')
# idtype in lexer.mll
typeid = r'_*[A-Z][_a-zA-Z0-9]*'
# combined ident and dollar and idtype
ident = r'(?:_*[a-z][_a-zA-Z0-9]*|_+[0-9][_a-zA-Z0-9]*|' + typeid + \
'|_+|\$[_a-zA-Z0-9]+)'
binop = (r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|'
r'!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|'
r'/|\-|=>|=)')
# ident except keywords
ident_no_keyword = r'(?!' + keyword + ')' + ident
flags = re.DOTALL | re.MULTILINE
preproc_stack = []
def preproc_callback(self, match, ctx):
proc = match.group(2)
if proc == 'if':
# store the current stack
self.preproc_stack.append(ctx.stack[:])
elif proc in ['else', 'elseif']:
# restore the stack back to right before #if
if self.preproc_stack: ctx.stack = self.preproc_stack[-1][:]
elif proc == 'end':
# remove the saved stack of previous #if
if self.preproc_stack: self.preproc_stack.pop()
# #if and #elseif should follow by an expr
if proc in ['if', 'elseif']:
ctx.stack.append('preproc-expr')
# #error can be optionally follow by the error msg
if proc in ['error']:
ctx.stack.append('preproc-error')
yield match.start(), Comment.Preproc, '#' + proc
ctx.pos = match.end()
tokens = {
'root': [
include('spaces'),
include('meta'),
(r'(?:package)\b', Keyword.Namespace, ('semicolon', 'package')),
(r'(?:import)\b', Keyword.Namespace, ('semicolon', 'import')),
(r'(?:using)\b', Keyword.Namespace, ('semicolon', 'using')),
(r'(?:extern|private)\b', Keyword.Declaration),
(r'(?:abstract)\b', Keyword.Declaration, 'abstract'),
(r'(?:class|interface)\b', Keyword.Declaration, 'class'),
(r'(?:enum)\b', Keyword.Declaration, 'enum'),
(r'(?:typedef)\b', Keyword.Declaration, 'typedef'),
# top-level expression
# although it is not supported in haxe, but it is common to write
# expression in web pages the positive lookahead here is to prevent
# an infinite loop at the EOF
(r'(?=.)', Text, 'expr-statement'),
],
# space/tab/comment/preproc
'spaces': [
(r'\s+', Text),
(r'//[^\n\r]*', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'(#)(if|elseif|else|end|error)\b', preproc_callback),
],
'string-single-interpol': [
(r'\$\{', String.Interpol, ('string-interpol-close', 'expr')),
(r'\$\$', String.Escape),
(r'\$(?=' + ident + ')', String.Interpol, 'ident'),
include('string-single'),
],
'string-single': [
(r"'", String.Single, '#pop'),
(r'\\.', String.Escape),
(r'.', String.Single),
],
'string-double': [
(r'"', String.Double, '#pop'),
(r'\\.', String.Escape),
(r'.', String.Double),
],
'string-interpol-close': [
(r'\$'+ident, String.Interpol),
(r'\}', String.Interpol, '#pop'),
],
'package': [
include('spaces'),
(ident, Name.Namespace),
(r'\.', Punctuation, 'import-ident'),
(r'', Text, '#pop'),
],
'import': [
include('spaces'),
(ident, Name.Namespace),
(r'\*', Keyword), # wildcard import
(r'\.', Punctuation, 'import-ident'),
(r'in', Keyword.Namespace, 'ident'),
(r'', Text, '#pop'),
],
'import-ident': [
include('spaces'),
(r'\*', Keyword, '#pop'), # wildcard import
(ident, Name.Namespace, '#pop'),
],
'using': [
include('spaces'),
(ident, Name.Namespace),
(r'\.', Punctuation, 'import-ident'),
(r'', Text, '#pop'),
],
'preproc-error': [
(r'\s+', Comment.Preproc),
(r"'", String.Single, ('#pop', 'string-single')),
(r'"', String.Double, ('#pop', 'string-double')),
(r'', Text, '#pop'),
],
'preproc-expr': [
(r'\s+', Comment.Preproc),
(r'\!', Comment.Preproc),
(r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')),
(ident, Comment.Preproc, '#pop'),
(r"'", String.Single, ('#pop', 'string-single')),
(r'"', String.Double, ('#pop', 'string-double')),
],
'preproc-parenthesis': [
(r'\s+', Comment.Preproc),
(r'\)', Comment.Preproc, '#pop'),
('', Text, 'preproc-expr-in-parenthesis'),
],
'preproc-expr-chain': [
(r'\s+', Comment.Preproc),
(binop, Comment.Preproc, ('#pop', 'preproc-expr-in-parenthesis')),
(r'', Text, '#pop'),
],
# same as 'preproc-expr' but able to chain 'preproc-expr-chain'
'preproc-expr-in-parenthesis': [
(r'\s+', Comment.Preproc),
(r'\!', Comment.Preproc),
(r'\(', Comment.Preproc,
('#pop', 'preproc-expr-chain', 'preproc-parenthesis')),
(ident, Comment.Preproc, ('#pop', 'preproc-expr-chain')),
(r"'", String.Single,
('#pop', 'preproc-expr-chain', 'string-single')),
(r'"', String.Double,
('#pop', 'preproc-expr-chain', 'string-double')),
],
'abstract' : [
include('spaces'),
(r'', Text, ('#pop', 'abstract-body', 'abstract-relation',
'abstract-opaque', 'type-param-constraint', 'type-name')),
],
'abstract-body' : [
include('spaces'),
(r'\{', Punctuation, ('#pop', 'class-body')),
],
'abstract-opaque' : [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'parenthesis-close', 'type')),
(r'', Text, '#pop'),
],
'abstract-relation': [
include('spaces'),
(r'(?:to|from)', Keyword.Declaration, 'type'),
(r',', Punctuation),
(r'', Text, '#pop'),
],
'meta': [
include('spaces'),
(r'@', Name.Decorator, ('meta-body', 'meta-ident', 'meta-colon')),
],
# optional colon
'meta-colon': [
include('spaces'),
(r':', Name.Decorator, '#pop'),
(r'', Text, '#pop'),
],
# same as 'ident' but set token as Name.Decorator instead of Name
'meta-ident': [
include('spaces'),
(ident, Name.Decorator, '#pop'),
],
'meta-body': [
include('spaces'),
(r'\(', Name.Decorator, ('#pop', 'meta-call')),
(r'', Text, '#pop'),
],
'meta-call': [
include('spaces'),
(r'\)', Name.Decorator, '#pop'),
(r'', Text, ('#pop', 'meta-call-sep', 'expr')),
],
'meta-call-sep': [
include('spaces'),
(r'\)', Name.Decorator, '#pop'),
(r',', Punctuation, ('#pop', 'meta-call')),
],
'typedef': [
include('spaces'),
(r'', Text, ('#pop', 'typedef-body', 'type-param-constraint',
'type-name')),
],
'typedef-body': [
include('spaces'),
(r'=', Operator, ('#pop', 'optional-semicolon', 'type')),
],
'enum': [
include('spaces'),
(r'', Text, ('#pop', 'enum-body', 'bracket-open',
'type-param-constraint', 'type-name')),
],
'enum-body': [
include('spaces'),
include('meta'),
(r'\}', Punctuation, '#pop'),
(ident_no_keyword, Name, ('enum-member', 'type-param-constraint')),
],
'enum-member': [
include('spaces'),
(r'\(', Punctuation,
('#pop', 'semicolon', 'flag', 'function-param')),
(r'', Punctuation, ('#pop', 'semicolon', 'flag')),
],
'class': [
include('spaces'),
(r'', Text, ('#pop', 'class-body', 'bracket-open', 'extends',
'type-param-constraint', 'type-name')),
],
'extends': [
include('spaces'),
(r'(?:extends|implements)\b', Keyword.Declaration, 'type'),
(r',', Punctuation), # the comma is made optional here, since haxe2
# requires the comma but haxe3 does not allow it
(r'', Text, '#pop'),
],
'bracket-open': [
include('spaces'),
(r'\{', Punctuation, '#pop'),
],
'bracket-close': [
include('spaces'),
(r'\}', Punctuation, '#pop'),
],
'class-body': [
include('spaces'),
include('meta'),
(r'\}', Punctuation, '#pop'),
(r'(?:static|public|private|override|dynamic|inline|macro)\b',
Keyword.Declaration),
(r'', Text, 'class-member'),
],
'class-member': [
include('spaces'),
(r'(var)\b', Keyword.Declaration,
('#pop', 'optional-semicolon', 'prop')),
(r'(function)\b', Keyword.Declaration,
('#pop', 'optional-semicolon', 'class-method')),
],
# local function, anonymous or not
'function-local': [
include('spaces'),
(r'(' + ident_no_keyword + ')?', Name.Function,
('#pop', 'expr', 'flag', 'function-param',
'parenthesis-open', 'type-param-constraint')),
],
'optional-expr': [
include('spaces'),
include('expr'),
(r'', Text, '#pop'),
],
'class-method': [
include('spaces'),
(ident, Name.Function, ('#pop', 'optional-expr', 'flag',
'function-param', 'parenthesis-open',
'type-param-constraint')),
],
# function arguments
'function-param': [
include('spaces'),
(r'\)', Punctuation, '#pop'),
(r'\?', Punctuation),
(ident_no_keyword, Name,
('#pop', 'function-param-sep', 'assign', 'flag')),
],
'function-param-sep': [
include('spaces'),
(r'\)', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'function-param')),
],
# class property
# eg. var prop(default, null):String;
'prop': [
include('spaces'),
(ident_no_keyword, Name, ('#pop', 'assign', 'flag', 'prop-get-set')),
],
'prop-get-set': [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'parenthesis-close',
'prop-get-set-opt', 'comma', 'prop-get-set-opt')),
(r'', Text, '#pop'),
],
'prop-get-set-opt': [
include('spaces'),
(r'(?:default|null|never|dynamic|get|set)\b', Keyword, '#pop'),
(ident_no_keyword, Text, '#pop'), #custom getter/setter
],
'expr-statement': [
include('spaces'),
# makes semicolon optional here, just to avoid checking the last
# one is bracket or not.
(r'', Text, ('#pop', 'optional-semicolon', 'expr')),
],
'expr': [
include('spaces'),
(r'@', Name.Decorator, ('#pop', 'optional-expr', 'meta-body',
'meta-ident', 'meta-colon')),
(r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator),
(r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')),
(r'(?:inline)\b', Keyword.Declaration),
(r'(?:function)\b', Keyword.Declaration, ('#pop', 'expr-chain',
'function-local')),
(r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket')),
(r'(?:true|false|null)\b', Keyword.Constant, ('#pop', 'expr-chain')),
(r'(?:this)\b', Keyword, ('#pop', 'expr-chain')),
(r'(?:cast)\b', Keyword, ('#pop', 'expr-chain', 'cast')),
(r'(?:try)\b', Keyword, ('#pop', 'catch', 'expr')),
(r'(?:var)\b', Keyword.Declaration, ('#pop', 'var')),
(r'(?:new)\b', Keyword, ('#pop', 'expr-chain', 'new')),
(r'(?:switch)\b', Keyword, ('#pop', 'switch')),
(r'(?:if)\b', Keyword, ('#pop', 'if')),
(r'(?:do)\b', Keyword, ('#pop', 'do')),
(r'(?:while)\b', Keyword, ('#pop', 'while')),
(r'(?:for)\b', Keyword, ('#pop', 'for')),
(r'(?:untyped|throw)\b', Keyword),
(r'(?:return)\b', Keyword, ('#pop', 'optional-expr')),
(r'(?:macro)\b', Keyword, ('#pop', 'macro')),
(r'(?:continue|break)\b', Keyword, '#pop'),
(r'(?:\$\s*[a-z]\b|\$(?!'+ident+'))', Name, ('#pop', 'dollar')),
(ident_no_keyword, Name, ('#pop', 'expr-chain')),
# Float
(r'\.[0-9]+', Number.Float, ('#pop', 'expr-chain')),
(r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')),
(r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')),
(r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'expr-chain')),
(r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'expr-chain')),
# Int
(r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'expr-chain')),
(r'[0-9]+', Number.Integer, ('#pop', 'expr-chain')),
# String
(r"'", String.Single, ('#pop', 'expr-chain', 'string-single-interpol')),
(r'"', String.Double, ('#pop', 'expr-chain', 'string-double')),
# EReg
(r'~/(\\\\|\\/|[^/\n])*/[gimsu]*', String.Regex, ('#pop', 'expr-chain')),
# Array
(r'\[', Punctuation, ('#pop', 'expr-chain', 'array-decl')),
],
'expr-chain': [
include('spaces'),
(r'(?:\+\+|\-\-)', Operator),
(binop, Operator, ('#pop', 'expr')),
(r'(?:in)\b', Keyword, ('#pop', 'expr')),
(r'\?', Operator, ('#pop', 'expr', 'ternary', 'expr')),
(r'(\.)(' + ident_no_keyword + ')', bygroups(Punctuation, Name)),
(r'\[', Punctuation, 'array-access'),
(r'\(', Punctuation, 'call'),
(r'', Text, '#pop'),
],
# macro reification
'macro': [
include('spaces'),
(r':', Punctuation, ('#pop', 'type')),
(r'', Text, ('#pop', 'expr')),
],
# cast can be written as "cast expr" or "cast(expr, type)"
'cast': [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'parenthesis-close',
'cast-type', 'expr')),
(r'', Text, ('#pop', 'expr')),
],
# optionally give a type as the 2nd argument of cast()
'cast-type': [
include('spaces'),
(r',', Punctuation, ('#pop', 'type')),
(r'', Text, '#pop'),
],
'catch': [
include('spaces'),
(r'(?:catch)\b', Keyword, ('expr', 'function-param',
'parenthesis-open')),
(r'', Text, '#pop'),
],
# do-while loop
'do': [
include('spaces'),
(r'', Punctuation, ('#pop', 'do-while', 'expr')),
],
# the while after do
'do-while': [
include('spaces'),
(r'(?:while)\b', Keyword, ('#pop', 'parenthesis',
'parenthesis-open')),
],
'while': [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')),
],
'for': [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')),
],
'if': [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'else', 'optional-semicolon', 'expr',
'parenthesis')),
],
'else': [
include('spaces'),
(r'(?:else)\b', Keyword, ('#pop', 'expr')),
(r'', Text, '#pop'),
],
'switch': [
include('spaces'),
(r'', Text, ('#pop', 'switch-body', 'bracket-open', 'expr')),
],
'switch-body': [
include('spaces'),
(r'(?:case|default)\b', Keyword, ('case-block', 'case')),
(r'\}', Punctuation, '#pop'),
],
'case': [
include('spaces'),
(r':', Punctuation, '#pop'),
(r'', Text, ('#pop', 'case-sep', 'case-guard', 'expr')),
],
'case-sep': [
include('spaces'),
(r':', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'case')),
],
'case-guard': [
include('spaces'),
(r'(?:if)\b', Keyword, ('#pop', 'parenthesis', 'parenthesis-open')),
(r'', Text, '#pop'),
],
# optional multiple expr under a case
'case-block': [
include('spaces'),
(r'(?!(?:case|default)\b|\})', Keyword, 'expr-statement'),
(r'', Text, '#pop'),
],
'new': [
include('spaces'),
(r'', Text, ('#pop', 'call', 'parenthesis-open', 'type')),
],
'array-decl': [
include('spaces'),
(r'\]', Punctuation, '#pop'),
(r'', Text, ('#pop', 'array-decl-sep', 'expr')),
],
'array-decl-sep': [
include('spaces'),
(r'\]', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'array-decl')),
],
'array-access': [
include('spaces'),
(r'', Text, ('#pop', 'array-access-close', 'expr')),
],
'array-access-close': [
include('spaces'),
(r'\]', Punctuation, '#pop'),
],
'comma': [
include('spaces'),
(r',', Punctuation, '#pop'),
],
'colon': [
include('spaces'),
(r':', Punctuation, '#pop'),
],
'semicolon': [
include('spaces'),
(r';', Punctuation, '#pop'),
],
'optional-semicolon': [
include('spaces'),
(r';', Punctuation, '#pop'),
(r'', Text, '#pop'),
],
# identity that CAN be a Haxe keyword
'ident': [
include('spaces'),
(ident, Name, '#pop'),
],
'dollar': [
include('spaces'),
(r'\{', Keyword, ('#pop', 'bracket-close', 'expr')),
(r'', Text, ('#pop', 'expr-chain')),
],
'type-name': [
include('spaces'),
(typeid, Name, '#pop'),
],
'type-full-name': [
include('spaces'),
(r'\.', Punctuation, 'ident'),
(r'', Text, '#pop'),
],
'type': [
include('spaces'),
(r'\?', Punctuation),
(ident, Name, ('#pop', 'type-check', 'type-full-name')),
(r'\{', Punctuation, ('#pop', 'type-check', 'type-struct')),
(r'\(', Punctuation, ('#pop', 'type-check', 'type-parenthesis')),
],
'type-parenthesis': [
include('spaces'),
(r'', Text, ('#pop', 'parenthesis-close', 'type')),
],
'type-check': [
include('spaces'),
(r'->', Punctuation, ('#pop', 'type')),
(r'<(?!=)', Punctuation, 'type-param'),
(r'', Text, '#pop'),
],
'type-struct': [
include('spaces'),
(r'\}', Punctuation, '#pop'),
(r'\?', Punctuation),
(r'>', Punctuation, ('comma', 'type')),
(ident_no_keyword, Name, ('#pop', 'type-struct-sep', 'type', 'colon')),
include('class-body'),
],
'type-struct-sep': [
include('spaces'),
(r'\}', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'type-struct')),
],
# type-param can be a normal type or a constant literal...
'type-param-type': [
# Float
(r'\.[0-9]+', Number.Float, '#pop'),
(r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, '#pop'),
(r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, '#pop'),
(r'[0-9]+\.[0-9]+', Number.Float, '#pop'),
(r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, '#pop'),
# Int
(r'0x[0-9a-fA-F]+', Number.Hex, '#pop'),
(r'[0-9]+', Number.Integer, '#pop'),
# String
(r"'", String.Single, ('#pop', 'string-single')),
(r'"', String.Double, ('#pop', 'string-double')),
# EReg
(r'~/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex, '#pop'),
# Array
(r'\[', Operator, ('#pop', 'array-decl')),
include('type'),
],
# type-param part of a type
# ie. the <A,B> path in Map<A,B>
'type-param': [
include('spaces'),
(r'', Text, ('#pop', 'type-param-sep', 'type-param-type')),
],
'type-param-sep': [
include('spaces'),
(r'>', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'type-param')),
],
# optional type-param that may include constraint
# ie. <T:Constraint, T2:(ConstraintA,ConstraintB)>
'type-param-constraint': [
include('spaces'),
(r'<(?!=)', Punctuation, ('#pop', 'type-param-constraint-sep',
'type-param-constraint-flag', 'type-name')),
(r'', Text, '#pop'),
],
'type-param-constraint-sep': [
include('spaces'),
(r'>', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'type-param-constraint-sep',
'type-param-constraint-flag', 'type-name')),
],
# the optional constraint inside type-param
'type-param-constraint-flag': [
include('spaces'),
(r':', Punctuation, ('#pop', 'type-param-constraint-flag-type')),
(r'', Text, '#pop'),
],
'type-param-constraint-flag-type': [
include('spaces'),
(r'\(', Punctuation, ('#pop', 'type-param-constraint-flag-type-sep',
'type')),
(r'', Text, ('#pop', 'type')),
],
'type-param-constraint-flag-type-sep': [
include('spaces'),
(r'\)', Punctuation, '#pop'),
(r',', Punctuation, 'type'),
],
# a parenthesis expr that contain exactly one expr
'parenthesis': [
include('spaces'),
(r'', Text, ('#pop', 'parenthesis-close', 'expr')),
],
'parenthesis-open': [
include('spaces'),
(r'\(', Punctuation, '#pop'),
],
'parenthesis-close': [
include('spaces'),
(r'\)', Punctuation, '#pop'),
],
'var': [
include('spaces'),
(ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag')),
],
# optional more var decl.
'var-sep': [
include('spaces'),
(r',', Punctuation, ('#pop', 'var')),
(r'', Text, '#pop'),
],
# optional assignment
'assign': [
include('spaces'),
(r'=', Operator, ('#pop', 'expr')),
(r'', Text, '#pop'),
],
# optional type flag
'flag': [
include('spaces'),
(r':', Punctuation, ('#pop', 'type')),
(r'', Text, '#pop'),
],
# colon as part of a ternary operator (?:)
'ternary': [
include('spaces'),
(r':', Operator, '#pop'),
],
# function call
'call': [
include('spaces'),
(r'\)', Punctuation, '#pop'),
(r'', Text, ('#pop', 'call-sep', 'expr')),
],
# after a call param
'call-sep': [
include('spaces'),
(r'\)', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'call')),
],
# bracket can be block or object
'bracket': [
include('spaces'),
(r'(?!(?:\$\s*[a-z]\b|\$(?!'+ident+')))' + ident_no_keyword, Name,
('#pop', 'bracket-check')),
(r"'", String.Single, ('#pop', 'bracket-check', 'string-single')),
(r'"', String.Double, ('#pop', 'bracket-check', 'string-double')),
(r'', Text, ('#pop', 'block')),
],
'bracket-check': [
include('spaces'),
(r':', Punctuation, ('#pop', 'object-sep', 'expr')), #is object
(r'', Text, ('#pop', 'block', 'optional-semicolon', 'expr-chain')), #is block
],
# code block
'block': [
include('spaces'),
(r'\}', Punctuation, '#pop'),
(r'', Text, 'expr-statement'),
],
# object in key-value pairs
'object': [
include('spaces'),
(r'\}', Punctuation, '#pop'),
(r'', Text, ('#pop', 'object-sep', 'expr', 'colon', 'ident-or-string'))
],
# a key of an object
'ident-or-string': [
include('spaces'),
(ident_no_keyword, Name, '#pop'),
(r"'", String.Single, ('#pop', 'string-single')),
(r'"', String.Double, ('#pop', 'string-double')),
],
# after a key-value pair in object
'object-sep': [
include('spaces'),
(r'\}', Punctuation, '#pop'),
(r',', Punctuation, ('#pop', 'object')),
],
}
def analyse_text(text):
if re.match(r'\w+\s*:\s*\w', text): return 0.3
def _indentation(lexer, match, ctx):
indentation = match.group(0)
yield match.start(), Text, indentation
ctx.last_indentation = indentation
ctx.pos = match.end()
if hasattr(ctx, 'block_state') and ctx.block_state and \
indentation.startswith(ctx.block_indentation) and \
indentation != ctx.block_indentation:
ctx.stack.append(ctx.block_state)
else:
ctx.block_state = None
ctx.block_indentation = None
ctx.stack.append('content')
def _starts_block(token, state):
def callback(lexer, match, ctx):
yield match.start(), token, match.group(0)
if hasattr(ctx, 'last_indentation'):
ctx.block_indentation = ctx.last_indentation
else:
ctx.block_indentation = ''
ctx.block_state = state
ctx.pos = match.end()
return callback
class HamlLexer(ExtendedRegexLexer):
"""
For Haml markup.
*New in Pygments 1.3.*
"""
name = 'Haml'
aliases = ['haml', 'HAML']
filenames = ['*.haml']
mimetypes = ['text/x-haml']
flags = re.IGNORECASE
# Haml can include " |\n" anywhere,
# which is ignored and used to wrap long lines.
# To accomodate this, use this custom faux dot instead.
_dot = r'(?: \|\n(?=.* \|)|.)'
# In certain places, a comma at the end of the line
# allows line wrapping as well.
_comma_dot = r'(?:,\s*\n|' + _dot + ')'
tokens = {
'root': [
(r'[ \t]*\n', Text),
(r'[ \t]*', _indentation),
],
'css': [
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
],
'eval-or-plain': [
(r'[&!]?==', Punctuation, 'plain'),
(r'([&!]?[=~])(' + _comma_dot + r'*\n)',
bygroups(Punctuation, using(RubyLexer)),
'root'),
(r'', Text, 'plain'),
],
'content': [
include('css'),
(r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
(r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'),
(r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)',
bygroups(Comment, Comment.Special, Comment),
'#pop'),
(r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'),
'#pop'),
(r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc,
'haml-comment-block'), '#pop'),
(r'(-)(' + _comma_dot + r'*\n)',
bygroups(Punctuation, using(RubyLexer)),
'#pop'),
(r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'),
'#pop'),
include('eval-or-plain'),
],
'tag': [
include('css'),
(r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)),
(r'\[' + _dot + '*?\]', using(RubyLexer)),
(r'\(', Text, 'html-attributes'),
(r'/[ \t]*\n', Punctuation, '#pop:2'),
(r'[<>]{1,2}(?=[ \t=])', Punctuation),
include('eval-or-plain'),
],
'plain': [
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
(r'(#\{)(' + _dot + '*?)(\})',
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
(r'\n', Text, 'root'),
],
'html-attributes': [
(r'\s+', Text),
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
(r'[a-z0-9_:-]+', Name.Attribute),
(r'\)', Text, '#pop'),
],
'html-attribute-value': [
(r'[ \t]+', Text),
(r'[a-z0-9_]+', Name.Variable, '#pop'),
(r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
(r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
(r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
(r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
],
'html-comment-block': [
(_dot + '+', Comment),
(r'\n', Text, 'root'),
],
'haml-comment-block': [
(_dot + '+', Comment.Preproc),
(r'\n', Text, 'root'),
],
'filter-block': [
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
(r'(#\{)(' + _dot + '*?)(\})',
bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
(r'\n', Text, 'root'),
],
}
common_sass_tokens = {
'value': [
(r'[ \t]+', Text),
(r'[!$][\w-]+', Name.Variable),
(r'url\(', String.Other, 'string-url'),
(r'[a-z_-][\w-]*(?=\()', Name.Function),
(r'(azimuth|background-attachment|background-color|'
r'background-image|background-position|background-repeat|'
r'background|border-bottom-color|border-bottom-style|'
r'border-bottom-width|border-left-color|border-left-style|'
r'border-left-width|border-right|border-right-color|'
r'border-right-style|border-right-width|border-top-color|'
r'border-top-style|border-top-width|border-bottom|'
r'border-collapse|border-left|border-width|border-color|'
r'border-spacing|border-style|border-top|border|caption-side|'
r'clear|clip|color|content|counter-increment|counter-reset|'
r'cue-after|cue-before|cue|cursor|direction|display|'
r'elevation|empty-cells|float|font-family|font-size|'
r'font-size-adjust|font-stretch|font-style|font-variant|'
r'font-weight|font|height|letter-spacing|line-height|'
r'list-style-type|list-style-image|list-style-position|'
r'list-style|margin-bottom|margin-left|margin-right|'
r'margin-top|margin|marker-offset|marks|max-height|max-width|'
r'min-height|min-width|opacity|orphans|outline|outline-color|'
r'outline-style|outline-width|overflow|padding-bottom|'
r'padding-left|padding-right|padding-top|padding|page|'
r'page-break-after|page-break-before|page-break-inside|'
r'pause-after|pause-before|pause|pitch|pitch-range|'
r'play-during|position|quotes|richness|right|size|'
r'speak-header|speak-numeral|speak-punctuation|speak|'
r'speech-rate|stress|table-layout|text-align|text-decoration|'
r'text-indent|text-shadow|text-transform|top|unicode-bidi|'
r'vertical-align|visibility|voice-family|volume|white-space|'
r'widows|width|word-spacing|z-index|bottom|left|'
r'above|absolute|always|armenian|aural|auto|avoid|baseline|'
r'behind|below|bidi-override|blink|block|bold|bolder|both|'
r'capitalize|center-left|center-right|center|circle|'
r'cjk-ideographic|close-quote|collapse|condensed|continuous|'
r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|'
r'decimal|default|digits|disc|dotted|double|e-resize|embed|'
r'extra-condensed|extra-expanded|expanded|fantasy|far-left|'
r'far-right|faster|fast|fixed|georgian|groove|hebrew|help|'
r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|'
r'inherit|inline-table|inline|inset|inside|invert|italic|'
r'justify|katakana-iroha|katakana|landscape|larger|large|'
r'left-side|leftwards|level|lighter|line-through|list-item|'
r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|'
r'lower|low|medium|message-box|middle|mix|monospace|'
r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|'
r'no-repeat|none|normal|nowrap|nw-resize|oblique|once|'
r'open-quote|outset|outside|overline|pointer|portrait|px|'
r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|'
r'rightwards|s-resize|sans-serif|scroll|se-resize|'
r'semi-condensed|semi-expanded|separate|serif|show|silent|'
r'slow|slower|small-caps|small-caption|smaller|soft|solid|'
r'spell-out|square|static|status-bar|super|sw-resize|'
r'table-caption|table-cell|table-column|table-column-group|'
r'table-footer-group|table-header-group|table-row|'
r'table-row-group|text|text-bottom|text-top|thick|thin|'
r'transparent|ultra-condensed|ultra-expanded|underline|'
r'upper-alpha|upper-latin|upper-roman|uppercase|url|'
r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|'
r'x-low|x-small|x-soft|xx-large|xx-small|yes)\b', Name.Constant),
(r'(indigo|gold|firebrick|indianred|darkolivegreen|'
r'darkseagreen|mediumvioletred|mediumorchid|chartreuse|'
r'mediumslateblue|springgreen|crimson|lightsalmon|brown|'
r'turquoise|olivedrab|cyan|skyblue|darkturquoise|'
r'goldenrod|darkgreen|darkviolet|darkgray|lightpink|'
r'darkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|'
r'violet|orchid|ghostwhite|honeydew|cornflowerblue|'
r'darkblue|darkkhaki|mediumpurple|cornsilk|bisque|slategray|'
r'darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|'
r'gainsboro|mediumturquoise|floralwhite|coral|lightgrey|'
r'lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|'
r'greenyellow|royalblue|lightseagreen|mistyrose|sienna|'
r'lightcoral|orangered|navajowhite|palegreen|burlywood|'
r'seashell|mediumspringgreen|papayawhip|blanchedalmond|'
r'peru|aquamarine|darkslategray|ivory|dodgerblue|'
r'lemonchiffon|chocolate|orange|forestgreen|slateblue|'
r'mintcream|antiquewhite|darkorange|cadetblue|moccasin|'
r'limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|'
r'plum|darkgoldenrod|sandybrown|magenta|tan|'
r'rosybrown|pink|lightblue|palevioletred|mediumseagreen|'
r'dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|'
r'paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|'
r'lightslategray|lawngreen|lightgreen|tomato|hotpink|'
r'lightyellow|lavenderblush|linen|mediumaquamarine|'
r'blueviolet|peachpuff)\b', Name.Entity),
(r'(black|silver|gray|white|maroon|red|purple|fuchsia|green|'
r'lime|olive|yellow|navy|blue|teal|aqua)\b', Name.Builtin),
(r'\!(important|default)', Name.Exception),
(r'(true|false)', Name.Pseudo),
(r'(and|or|not)', Operator.Word),
(r'/\*', Comment.Multiline, 'inline-comment'),
(r'//[^\n]*', Comment.Single),
(r'\#[a-z0-9]{1,6}', Number.Hex),
(r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)),
(r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)),
(r'#{', String.Interpol, 'interpolation'),
(r'[~\^\*!&%<>\|+=@:,./?-]+', Operator),
(r'[\[\]()]+', Punctuation),
(r'"', String.Double, 'string-double'),
(r"'", String.Single, 'string-single'),
(r'[a-z_-][\w-]*', Name),
],
'interpolation': [
(r'\}', String.Interpol, '#pop'),
include('value'),
],
'selector': [
(r'[ \t]+', Text),
(r'\:', Name.Decorator, 'pseudo-class'),
(r'\.', Name.Class, 'class'),
(r'\#', Name.Namespace, 'id'),
(r'[a-zA-Z0-9_-]+', Name.Tag),
(r'#\{', String.Interpol, 'interpolation'),
(r'&', Keyword),
(r'[~\^\*!&\[\]\(\)<>\|+=@:;,./?-]', Operator),
(r'"', String.Double, 'string-double'),
(r"'", String.Single, 'string-single'),
],
'string-double': [
(r'(\\.|#(?=[^\n{])|[^\n"#])+', String.Double),
(r'#\{', String.Interpol, 'interpolation'),
(r'"', String.Double, '#pop'),
],
'string-single': [
(r"(\\.|#(?=[^\n{])|[^\n'#])+", String.Double),
(r'#\{', String.Interpol, 'interpolation'),
(r"'", String.Double, '#pop'),
],
'string-url': [
(r'(\\#|#(?=[^\n{])|[^\n#)])+', String.Other),
(r'#\{', String.Interpol, 'interpolation'),
(r'\)', String.Other, '#pop'),
],
'pseudo-class': [
(r'[\w-]+', Name.Decorator),
(r'#\{', String.Interpol, 'interpolation'),
(r'', Text, '#pop'),
],
'class': [
(r'[\w-]+', Name.Class),
(r'#\{', String.Interpol, 'interpolation'),
(r'', Text, '#pop'),
],
'id': [
(r'[\w-]+', Name.Namespace),
(r'#\{', String.Interpol, 'interpolation'),
(r'', Text, '#pop'),
],
'for': [
(r'(from|to|through)', Operator.Word),
include('value'),
],
}
class SassLexer(ExtendedRegexLexer):
"""
For Sass stylesheets.
*New in Pygments 1.3.*
"""
name = 'Sass'
aliases = ['sass', 'SASS']
filenames = ['*.sass']
mimetypes = ['text/x-sass']
flags = re.IGNORECASE
tokens = {
'root': [
(r'[ \t]*\n', Text),
(r'[ \t]*', _indentation),
],
'content': [
(r'//[^\n]*', _starts_block(Comment.Single, 'single-comment'),
'root'),
(r'/\*[^\n]*', _starts_block(Comment.Multiline, 'multi-comment'),
'root'),
(r'@import', Keyword, 'import'),
(r'@for', Keyword, 'for'),
(r'@(debug|warn|if|while)', Keyword, 'value'),
(r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'),
(r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'),
(r'@extend', Keyword, 'selector'),
(r'@[a-z0-9_-]+', Keyword, 'selector'),
(r'=[\w-]+', Name.Function, 'value'),
(r'\+[\w-]+', Name.Decorator, 'value'),
(r'([!$][\w-]\w*)([ \t]*(?:(?:\|\|)?=|:))',
bygroups(Name.Variable, Operator), 'value'),
(r':', Name.Attribute, 'old-style-attr'),
(r'(?=.+?[=:]([^a-z]|$))', Name.Attribute, 'new-style-attr'),
(r'', Text, 'selector'),
],
'single-comment': [
(r'.+', Comment.Single),
(r'\n', Text, 'root'),
],
'multi-comment': [
(r'.+', Comment.Multiline),
(r'\n', Text, 'root'),
],
'import': [
(r'[ \t]+', Text),
(r'\S+', String),
(r'\n', Text, 'root'),
],
'old-style-attr': [
(r'[^\s:="\[]+', Name.Attribute),
(r'#{', String.Interpol, 'interpolation'),
(r'[ \t]*=', Operator, 'value'),
(r'', Text, 'value'),
],
'new-style-attr': [
(r'[^\s:="\[]+', Name.Attribute),
(r'#{', String.Interpol, 'interpolation'),
(r'[ \t]*[=:]', Operator, 'value'),
],
'inline-comment': [
(r"(\\#|#(?=[^\n{])|\*(?=[^\n/])|[^\n#*])+", Comment.Multiline),
(r'#\{', String.Interpol, 'interpolation'),
(r"\*/", Comment, '#pop'),
],
}
for group, common in common_sass_tokens.items():
tokens[group] = copy.copy(common)
tokens['value'].append((r'\n', Text, 'root'))
tokens['selector'].append((r'\n', Text, 'root'))
class ScssLexer(RegexLexer):
"""
For SCSS stylesheets.
"""
name = 'SCSS'
aliases = ['scss']
filenames = ['*.scss']
mimetypes = ['text/x-scss']
flags = re.IGNORECASE | re.DOTALL
tokens = {
'root': [
(r'\s+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'@import', Keyword, 'value'),
(r'@for', Keyword, 'for'),
(r'@(debug|warn|if|while)', Keyword, 'value'),
(r'(@mixin)( [\w-]+)', bygroups(Keyword, Name.Function), 'value'),
(r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'),
(r'@extend', Keyword, 'selector'),
(r'@[a-z0-9_-]+', Keyword, 'selector'),
(r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'),
(r'(?=[^;{}][;}])', Name.Attribute, 'attr'),
(r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'),
(r'', Text, 'selector'),
],
'attr': [
(r'[^\s:="\[]+', Name.Attribute),
(r'#{', String.Interpol, 'interpolation'),
(r'[ \t]*:', Operator, 'value'),
],
'inline-comment': [
(r"(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+", Comment.Multiline),
(r'#\{', String.Interpol, 'interpolation'),
(r"\*/", Comment, '#pop'),
],
}
for group, common in common_sass_tokens.items():
tokens[group] = copy.copy(common)
tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')])
tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')])
class CoffeeScriptLexer(RegexLexer):
"""
For `CoffeeScript`_ source code.
.. _CoffeeScript: http://coffeescript.org
*New in Pygments 1.3.*
"""
name = 'CoffeeScript'
aliases = ['coffee-script', 'coffeescript', 'coffee']
filenames = ['*.coffee']
mimetypes = ['text/coffeescript']
flags = re.DOTALL
tokens = {
'commentsandwhitespace': [
(r'\s+', Text),
(r'###[^#].*?###', Comment.Multiline),
(r'#(?!##[^#]).*?\n', Comment.Single),
],
'multilineregex': [
(r'[^/#]+', String.Regex),
(r'///([gim]+\b|\B)', String.Regex, '#pop'),
(r'#{', String.Interpol, 'interpoling_string'),
(r'[/#]', String.Regex),
],
'slashstartsregex': [
include('commentsandwhitespace'),
(r'///', String.Regex, ('#pop', 'multilineregex')),
(r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'', Text, '#pop'),
],
'root': [
# this next expr leads to infinite loops root -> slashstartsregex
#(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|'
r'=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?',
Operator, 'slashstartsregex'),
(r'(?:\([^()]+\))?\s*[=-]>', Name.Function),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(?<![\.\$])(for|own|in|of|while|until|'
r'loop|break|return|continue|'
r'switch|when|then|if|unless|else|'
r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
r'extends|this|class|by)\b', Keyword, 'slashstartsregex'),
(r'(?<![\.\$])(true|false|yes|no|on|off|null|'
r'NaN|Infinity|undefined)\b',
Keyword.Constant),
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
r'decodeURIComponent|encodeURI|encodeURIComponent|'
r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b',
Name.Builtin),
(r'[$a-zA-Z_][a-zA-Z0-9_\.:\$]*\s*[:=]\s', Name.Variable,
'slashstartsregex'),
(r'@[$a-zA-Z_][a-zA-Z0-9_\.:\$]*\s*[:=]\s', Name.Variable.Instance,
'slashstartsregex'),
(r'@', Name.Other, 'slashstartsregex'),
(r'@?[$a-zA-Z_][a-zA-Z0-9_\$]*', Name.Other, 'slashstartsregex'),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-fA-F]+', Number.Hex),
(r'[0-9]+', Number.Integer),
('"""', String, 'tdqs'),
("'''", String, 'tsqs'),
('"', String, 'dqs'),
("'", String, 'sqs'),
],
'strings': [
(r'[^#\\\'"]+', String),
# note that all coffee script strings are multi-line.
# hashmarks, quotes and backslashes must be parsed one at a time
],
'interpoling_string' : [
(r'}', String.Interpol, "#pop"),
include('root')
],
'dqs': [
(r'"', String, '#pop'),
(r'\\.|\'', String), # double-quoted string don't need ' escapes
(r'#{', String.Interpol, "interpoling_string"),
include('strings')
],
'sqs': [
(r"'", String, '#pop'),
(r'#|\\.|"', String), # single quoted strings don't need " escapses
include('strings')
],
'tdqs': [
(r'"""', String, '#pop'),
(r'\\.|\'|"', String), # no need to escape quotes in triple-string
(r'#{', String.Interpol, "interpoling_string"),
include('strings'),
],
'tsqs': [
(r"'''", String, '#pop'),
(r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings
include('strings')
],
}
class LiveScriptLexer(RegexLexer):
"""
For `LiveScript`_ source code.
.. _LiveScript: http://gkz.github.com/LiveScript/
New in Pygments 1.6.
"""
name = 'LiveScript'
aliases = ['live-script', 'livescript']
filenames = ['*.ls']
mimetypes = ['text/livescript']
flags = re.DOTALL
tokens = {
'commentsandwhitespace': [
(r'\s+', Text),
(r'/\*.*?\*/', Comment.Multiline),
(r'#.*?\n', Comment.Single),
],
'multilineregex': [
include('commentsandwhitespace'),
(r'//([gim]+\b|\B)', String.Regex, '#pop'),
(r'/', String.Regex),
(r'[^/#]+', String.Regex)
],
'slashstartsregex': [
include('commentsandwhitespace'),
(r'//', String.Regex, ('#pop', 'multilineregex')),
(r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'', Text, '#pop'),
],
'root': [
# this next expr leads to infinite loops root -> slashstartsregex
#(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|'
r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function),
(r'\+\+|&&|(?<![\.\$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|'
r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|'
r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|'
r'[+*`%&\|\^/])=?',
Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(?<![\.\$])(for|own|in|of|while|until|loop|break|'
r'return|continue|switch|when|then|if|unless|else|'
r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
r'extends|this|class|by|const|var|to|til)\b', Keyword,
'slashstartsregex'),
(r'(?<![\.\$])(true|false|yes|no|on|off|'
r'null|NaN|Infinity|undefined|void)\b',
Keyword.Constant),
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
r'decodeURIComponent|encodeURI|encodeURIComponent|'
r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b',
Name.Builtin),
(r'[$a-zA-Z_][a-zA-Z0-9_\.\-:\$]*\s*[:=]\s', Name.Variable,
'slashstartsregex'),
(r'@[$a-zA-Z_][a-zA-Z0-9_\.\-:\$]*\s*[:=]\s', Name.Variable.Instance,
'slashstartsregex'),
(r'@', Name.Other, 'slashstartsregex'),
(r'@?[$a-zA-Z_][a-zA-Z0-9_\-]*', Name.Other, 'slashstartsregex'),
(r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float),
(r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer),
('"""', String, 'tdqs'),
("'''", String, 'tsqs'),
('"', String, 'dqs'),
("'", String, 'sqs'),
(r'\\[\w$-]+', String),
(r'<\[.*\]>', String),
],
'strings': [
(r'[^#\\\'"]+', String),
# note that all coffee script strings are multi-line.
# hashmarks, quotes and backslashes must be parsed one at a time
],
'interpoling_string' : [
(r'}', String.Interpol, "#pop"),
include('root')
],
'dqs': [
(r'"', String, '#pop'),
(r'\\.|\'', String), # double-quoted string don't need ' escapes
(r'#{', String.Interpol, "interpoling_string"),
(r'#', String),
include('strings')
],
'sqs': [
(r"'", String, '#pop'),
(r'#|\\.|"', String), # single quoted strings don't need " escapses
include('strings')
],
'tdqs': [
(r'"""', String, '#pop'),
(r'\\.|\'|"', String), # no need to escape quotes in triple-string
(r'#{', String.Interpol, "interpoling_string"),
(r'#', String),
include('strings'),
],
'tsqs': [
(r"'''", String, '#pop'),
(r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings
include('strings')
],
}
class DuelLexer(RegexLexer):
"""
Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks.
See http://duelengine.org/.
See http://jsonml.org/jbst/.
*New in Pygments 1.4.*
"""
name = 'Duel'
aliases = ['duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST']
filenames = ['*.duel','*.jbst']
mimetypes = ['text/x-duel','text/x-jbst']
flags = re.DOTALL
tokens = {
'root': [
(r'(<%[@=#!:]?)(.*?)(%>)',
bygroups(Name.Tag, using(JavascriptLexer), Name.Tag)),
(r'(<%\$)(.*?)(:)(.*?)(%>)',
bygroups(Name.Tag, Name.Function, Punctuation, String, Name.Tag)),
(r'(<%--)(.*?)(--%>)',
bygroups(Name.Tag, Comment.Multiline, Name.Tag)),
(r'(<script.*?>)(.*?)(</script>)',
bygroups(using(HtmlLexer),
using(JavascriptLexer), using(HtmlLexer))),
(r'(.+?)(?=<)', using(HtmlLexer)),
(r'.+', using(HtmlLexer)),
],
}
class ScamlLexer(ExtendedRegexLexer):
"""
For `Scaml markup <http://scalate.fusesource.org/>`_. Scaml is Haml for Scala.
*New in Pygments 1.4.*
"""
name = 'Scaml'
aliases = ['scaml', 'SCAML']
filenames = ['*.scaml']
mimetypes = ['text/x-scaml']
flags = re.IGNORECASE
# Scaml does not yet support the " |\n" notation to
# wrap long lines. Once it does, use the custom faux
# dot instead.
# _dot = r'(?: \|\n(?=.* \|)|.)'
_dot = r'.'
tokens = {
'root': [
(r'[ \t]*\n', Text),
(r'[ \t]*', _indentation),
],
'css': [
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
],
'eval-or-plain': [
(r'[&!]?==', Punctuation, 'plain'),
(r'([&!]?[=~])(' + _dot + r'*\n)',
bygroups(Punctuation, using(ScalaLexer)),
'root'),
(r'', Text, 'plain'),
],
'content': [
include('css'),
(r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
(r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'),
(r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)',
bygroups(Comment, Comment.Special, Comment),
'#pop'),
(r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'),
'#pop'),
(r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc,
'scaml-comment-block'), '#pop'),
(r'(-@\s*)(import)?(' + _dot + r'*\n)',
bygroups(Punctuation, Keyword, using(ScalaLexer)),
'#pop'),
(r'(-)(' + _dot + r'*\n)',
bygroups(Punctuation, using(ScalaLexer)),
'#pop'),
(r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'),
'#pop'),
include('eval-or-plain'),
],
'tag': [
include('css'),
(r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)),
(r'\[' + _dot + '*?\]', using(ScalaLexer)),
(r'\(', Text, 'html-attributes'),
(r'/[ \t]*\n', Punctuation, '#pop:2'),
(r'[<>]{1,2}(?=[ \t=])', Punctuation),
include('eval-or-plain'),
],
'plain': [
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
(r'(#\{)(' + _dot + '*?)(\})',
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
(r'\n', Text, 'root'),
],
'html-attributes': [
(r'\s+', Text),
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
(r'[a-z0-9_:-]+', Name.Attribute),
(r'\)', Text, '#pop'),
],
'html-attribute-value': [
(r'[ \t]+', Text),
(r'[a-z0-9_]+', Name.Variable, '#pop'),
(r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
(r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
(r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
(r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
],
'html-comment-block': [
(_dot + '+', Comment),
(r'\n', Text, 'root'),
],
'scaml-comment-block': [
(_dot + '+', Comment.Preproc),
(r'\n', Text, 'root'),
],
'filter-block': [
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
(r'(#\{)(' + _dot + '*?)(\})',
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
(r'\n', Text, 'root'),
],
}
class JadeLexer(ExtendedRegexLexer):
"""
For Jade markup.
Jade is a variant of Scaml, see:
http://scalate.fusesource.org/documentation/scaml-reference.html
*New in Pygments 1.4.*
"""
name = 'Jade'
aliases = ['jade', 'JADE']
filenames = ['*.jade']
mimetypes = ['text/x-jade']
flags = re.IGNORECASE
_dot = r'.'
tokens = {
'root': [
(r'[ \t]*\n', Text),
(r'[ \t]*', _indentation),
],
'css': [
(r'\.[a-z0-9_:-]+', Name.Class, 'tag'),
(r'\#[a-z0-9_:-]+', Name.Function, 'tag'),
],
'eval-or-plain': [
(r'[&!]?==', Punctuation, 'plain'),
(r'([&!]?[=~])(' + _dot + r'*\n)',
bygroups(Punctuation, using(ScalaLexer)), 'root'),
(r'', Text, 'plain'),
],
'content': [
include('css'),
(r'!!!' + _dot + r'*\n', Name.Namespace, '#pop'),
(r'(/)(\[' + _dot + '*?\])(' + _dot + r'*\n)',
bygroups(Comment, Comment.Special, Comment),
'#pop'),
(r'/' + _dot + r'*\n', _starts_block(Comment, 'html-comment-block'),
'#pop'),
(r'-#' + _dot + r'*\n', _starts_block(Comment.Preproc,
'scaml-comment-block'), '#pop'),
(r'(-@\s*)(import)?(' + _dot + r'*\n)',
bygroups(Punctuation, Keyword, using(ScalaLexer)),
'#pop'),
(r'(-)(' + _dot + r'*\n)',
bygroups(Punctuation, using(ScalaLexer)),
'#pop'),
(r':' + _dot + r'*\n', _starts_block(Name.Decorator, 'filter-block'),
'#pop'),
(r'[a-z0-9_:-]+', Name.Tag, 'tag'),
(r'\|', Text, 'eval-or-plain'),
],
'tag': [
include('css'),
(r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)),
(r'\[' + _dot + '*?\]', using(ScalaLexer)),
(r'\(', Text, 'html-attributes'),
(r'/[ \t]*\n', Punctuation, '#pop:2'),
(r'[<>]{1,2}(?=[ \t=])', Punctuation),
include('eval-or-plain'),
],
'plain': [
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
(r'(#\{)(' + _dot + '*?)(\})',
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
(r'\n', Text, 'root'),
],
'html-attributes': [
(r'\s+', Text),
(r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'),
(r'[a-z0-9_:-]+', Name.Attribute),
(r'\)', Text, '#pop'),
],
'html-attribute-value': [
(r'[ \t]+', Text),
(r'[a-z0-9_]+', Name.Variable, '#pop'),
(r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'),
(r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'),
(r"'(\\\\|\\'|[^'\n])*'", String, '#pop'),
(r'"(\\\\|\\"|[^"\n])*"', String, '#pop'),
],
'html-comment-block': [
(_dot + '+', Comment),
(r'\n', Text, 'root'),
],
'scaml-comment-block': [
(_dot + '+', Comment.Preproc),
(r'\n', Text, 'root'),
],
'filter-block': [
(r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
(r'(#\{)(' + _dot + '*?)(\})',
bygroups(String.Interpol, using(ScalaLexer), String.Interpol)),
(r'\n', Text, 'root'),
],
}
class XQueryLexer(ExtendedRegexLexer):
"""
An XQuery lexer, parsing a stream and outputting the tokens needed to
highlight xquery code.
*New in Pygments 1.4.*
"""
name = 'XQuery'
aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm']
filenames = ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm']
mimetypes = ['text/xquery', 'application/xquery']
xquery_parse_state = []
# FIX UNICODE LATER
#ncnamestartchar = (
# ur"[A-Z]|_|[a-z]|[\u00C0-\u00D6]|[\u00D8-\u00F6]|[\u00F8-\u02FF]|"
# ur"[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|"
# ur"[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|"
# ur"[\u10000-\uEFFFF]"
#)
ncnamestartchar = r"(?:[A-Z]|_|[a-z])"
# FIX UNICODE LATER
#ncnamechar = ncnamestartchar + (ur"|-|\.|[0-9]|\u00B7|[\u0300-\u036F]|"
# ur"[\u203F-\u2040]")
ncnamechar = r"(?:" + ncnamestartchar + r"|-|\.|[0-9])"
ncname = "(?:%s+%s*)" % (ncnamestartchar, ncnamechar)
pitarget_namestartchar = r"(?:[A-KN-WY-Z]|_|:|[a-kn-wy-z])"
pitarget_namechar = r"(?:" + pitarget_namestartchar + r"|-|\.|[0-9])"
pitarget = "%s+%s*" % (pitarget_namestartchar, pitarget_namechar)
prefixedname = "%s:%s" % (ncname, ncname)
unprefixedname = ncname
qname = "(?:%s|%s)" % (prefixedname, unprefixedname)
entityref = r'(?:&(?:lt|gt|amp|quot|apos|nbsp);)'
charref = r'(?:&#[0-9]+;|&#x[0-9a-fA-F]+;)'
stringdouble = r'(?:"(?:' + entityref + r'|' + charref + r'|""|[^&"])*")'
stringsingle = r"(?:'(?:" + entityref + r"|" + charref + r"|''|[^&'])*')"
# FIX UNICODE LATER
#elementcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|'
# ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]')
elementcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]'
#quotattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0021]|[\u0023-\u0025]|'
# ur'[\u0027-\u003b]|[\u003d-\u007a]|\u007c|[\u007e-\u007F]')
quotattrcontentchar = r'[A-Za-z]|\s|\d|[!#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_\'`\|~]'
#aposattrcontentchar = (ur'\t|\r|\n|[\u0020-\u0025]|[\u0028-\u003b]|'
# ur'[\u003d-\u007a]|\u007c|[\u007e-\u007F]')
aposattrcontentchar = r'[A-Za-z]|\s|\d|[!"#$%\(\)\*\+,\-\./\:;=\?\@\[\\\]^_`\|~]'
# CHAR elements - fix the above elementcontentchar, quotattrcontentchar,
# aposattrcontentchar
#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
flags = re.DOTALL | re.MULTILINE | re.UNICODE
def punctuation_root_callback(lexer, match, ctx):
yield match.start(), Punctuation, match.group(1)
# transition to root always - don't pop off stack
ctx.stack = ['root']
ctx.pos = match.end()
def operator_root_callback(lexer, match, ctx):
yield match.start(), Operator, match.group(1)
# transition to root always - don't pop off stack
ctx.stack = ['root']
ctx.pos = match.end()
def popstate_tag_callback(lexer, match, ctx):
yield match.start(), Name.Tag, match.group(1)
ctx.stack.append(lexer.xquery_parse_state.pop())
ctx.pos = match.end()
def popstate_xmlcomment_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append(lexer.xquery_parse_state.pop())
ctx.pos = match.end()
def popstate_kindtest_callback(lexer, match, ctx):
yield match.start(), Punctuation, match.group(1)
next_state = lexer.xquery_parse_state.pop()
if next_state == 'occurrenceindicator':
if re.match("[?*+]+", match.group(2)):
yield match.start(), Punctuation, match.group(2)
ctx.stack.append('operator')
ctx.pos = match.end()
else:
ctx.stack.append('operator')
ctx.pos = match.end(1)
else:
ctx.stack.append(next_state)
ctx.pos = match.end(1)
def popstate_callback(lexer, match, ctx):
yield match.start(), Punctuation, match.group(1)
# if we have run out of our state stack, pop whatever is on the pygments
# state stack
if len(lexer.xquery_parse_state) == 0:
ctx.stack.pop()
elif len(ctx.stack) > 1:
ctx.stack.append(lexer.xquery_parse_state.pop())
else:
# i don't know if i'll need this, but in case, default back to root
ctx.stack = ['root']
ctx.pos = match.end()
def pushstate_element_content_starttag_callback(lexer, match, ctx):
yield match.start(), Name.Tag, match.group(1)
lexer.xquery_parse_state.append('element_content')
ctx.stack.append('start_tag')
ctx.pos = match.end()
def pushstate_cdata_section_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('cdata_section')
lexer.xquery_parse_state.append(ctx.state.pop)
ctx.pos = match.end()
def pushstate_starttag_callback(lexer, match, ctx):
yield match.start(), Name.Tag, match.group(1)
lexer.xquery_parse_state.append(ctx.state.pop)
ctx.stack.append('start_tag')
ctx.pos = match.end()
def pushstate_operator_order_callback(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
ctx.stack = ['root']
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
def pushstate_operator_root_validate(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
ctx.stack = ['root']
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
def pushstate_operator_root_validate_withmode(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Keyword, match.group(3)
ctx.stack = ['root']
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
def pushstate_operator_processing_instruction_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('processing_instruction')
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
def pushstate_element_content_processing_instruction_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('processing_instruction')
lexer.xquery_parse_state.append('element_content')
ctx.pos = match.end()
def pushstate_element_content_cdata_section_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('cdata_section')
lexer.xquery_parse_state.append('element_content')
ctx.pos = match.end()
def pushstate_operator_cdata_section_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('cdata_section')
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
def pushstate_element_content_xmlcomment_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('xml_comment')
lexer.xquery_parse_state.append('element_content')
ctx.pos = match.end()
def pushstate_operator_xmlcomment_callback(lexer, match, ctx):
yield match.start(), String.Doc, match.group(1)
ctx.stack.append('xml_comment')
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
def pushstate_kindtest_callback(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
lexer.xquery_parse_state.append('kindtest')
ctx.stack.append('kindtest')
ctx.pos = match.end()
def pushstate_operator_kindtestforpi_callback(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
lexer.xquery_parse_state.append('operator')
ctx.stack.append('kindtestforpi')
ctx.pos = match.end()
def pushstate_operator_kindtest_callback(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
lexer.xquery_parse_state.append('operator')
ctx.stack.append('kindtest')
ctx.pos = match.end()
def pushstate_occurrenceindicator_kindtest_callback(lexer, match, ctx):
yield match.start(), Name.Tag, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
lexer.xquery_parse_state.append('occurrenceindicator')
ctx.stack.append('kindtest')
ctx.pos = match.end()
def pushstate_operator_starttag_callback(lexer, match, ctx):
yield match.start(), Name.Tag, match.group(1)
lexer.xquery_parse_state.append('operator')
ctx.stack.append('start_tag')
ctx.pos = match.end()
def pushstate_operator_root_callback(lexer, match, ctx):
yield match.start(), Punctuation, match.group(1)
lexer.xquery_parse_state.append('operator')
ctx.stack = ['root']#.append('root')
ctx.pos = match.end()
def pushstate_operator_root_construct_callback(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
lexer.xquery_parse_state.append('operator')
ctx.stack = ['root']
ctx.pos = match.end()
def pushstate_root_callback(lexer, match, ctx):
yield match.start(), Punctuation, match.group(1)
cur_state = ctx.stack.pop()
lexer.xquery_parse_state.append(cur_state)
ctx.stack = ['root']#.append('root')
ctx.pos = match.end()
def pushstate_operator_attribute_callback(lexer, match, ctx):
yield match.start(), Name.Attribute, match.group(1)
ctx.stack.append('operator')
ctx.pos = match.end()
def pushstate_operator_callback(lexer, match, ctx):
yield match.start(), Keyword, match.group(1)
yield match.start(), Text, match.group(2)
yield match.start(), Punctuation, match.group(3)
lexer.xquery_parse_state.append('operator')
ctx.pos = match.end()
tokens = {
'comment': [
# xquery comments
(r'(:\))', Comment, '#pop'),
(r'(\(:)', Comment, '#push'),
(r'[^:)]', Comment),
(r'([^:)]|:|\))', Comment),
],
'whitespace': [
(r'\s+', Text),
],
'operator': [
include('whitespace'),
(r'(\})', popstate_callback),
(r'\(:', Comment, 'comment'),
(r'(\{)', pushstate_root_callback),
(r'then|else|external|at|div|except', Keyword, 'root'),
(r'order by', Keyword, 'root'),
(r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'),
(r'and|or', Operator.Word, 'root'),
(r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)',
Operator.Word, 'root'),
(r'return|satisfies|to|union|where|preserve\s+strip',
Keyword, 'root'),
(r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\||:=|=)',
operator_root_callback),
(r'(::|;|\[|//|/|,)',
punctuation_root_callback),
(r'(castable|cast)(\s+)(as)\b',
bygroups(Keyword, Text, Keyword), 'singletype'),
(r'(instance)(\s+)(of)\b',
bygroups(Keyword, Text, Keyword), 'itemtype'),
(r'(treat)(\s+)(as)\b',
bygroups(Keyword, Text, Keyword), 'itemtype'),
(r'(case|as)\b', Keyword, 'itemtype'),
(r'(\))(\s*)(as)',
bygroups(Punctuation, Text, Keyword), 'itemtype'),
(r'\$', Name.Variable, 'varname'),
(r'(for|let)(\s+)(\$)',
bygroups(Keyword, Text, Name.Variable), 'varname'),
#(r'\)|\?|\]', Punctuation, '#push'),
(r'\)|\?|\]', Punctuation),
(r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)),
(r'ascending|descending|default', Keyword, '#push'),
(r'external', Keyword),
(r'collation', Keyword, 'uritooperator'),
# finally catch all string literals and stay in operator state
(stringdouble, String.Double),
(stringsingle, String.Single),
(r'(catch)(\s*)', bygroups(Keyword, Text), 'root'),
],
'uritooperator': [
(stringdouble, String.Double, '#pop'),
(stringsingle, String.Single, '#pop'),
],
'namespacedecl': [
include('whitespace'),
(r'\(:', Comment, 'comment'),
(r'(at)(\s+)('+stringdouble+')', bygroups(Keyword, Text, String.Double)),
(r"(at)(\s+)("+stringsingle+')', bygroups(Keyword, Text, String.Single)),
(stringdouble, String.Double),
(stringsingle, String.Single),
(r',', Punctuation),
(r'=', Operator),
(r';', Punctuation, 'root'),
(ncname, Name.Namespace),
],
'namespacekeyword': [
include('whitespace'),
(r'\(:', Comment, 'comment'),
(stringdouble, String.Double, 'namespacedecl'),
(stringsingle, String.Single, 'namespacedecl'),
(r'inherit|no-inherit', Keyword, 'root'),
(r'namespace', Keyword, 'namespacedecl'),
(r'(default)(\s+)(element)', bygroups(Keyword, Text, Keyword)),
(r'preserve|no-preserve', Keyword),
(r',', Punctuation),
],
'varname': [
(r'\(:', Comment, 'comment'),
(qname, Name.Variable, 'operator'),
],
'singletype': [
(r'\(:', Comment, 'comment'),
(ncname + r'(:\*)', Name.Variable, 'operator'),
(qname, Name.Variable, 'operator'),
],
'itemtype': [
include('whitespace'),
(r'\(:', Comment, 'comment'),
(r'\$', Punctuation, 'varname'),
(r'(void)(\s*)(\()(\s*)(\))',
bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'),
(r'(element|attribute|schema-element|schema-attribute|comment|text|'
r'node|binary|document-node|empty-sequence)(\s*)(\()',
pushstate_occurrenceindicator_kindtest_callback),
# Marklogic specific type?
(r'(processing-instruction)(\s*)(\()',
bygroups(Keyword, Text, Punctuation),
('occurrenceindicator', 'kindtestforpi')),
(r'(item)(\s*)(\()(\s*)(\))(?=[*+?])',
bygroups(Keyword, Text, Punctuation, Text, Punctuation),
'occurrenceindicator'),
(r'\(\#', Punctuation, 'pragma'),
(r';', Punctuation, '#pop'),
(r'then|else', Keyword, '#pop'),
(r'(at)(\s+)(' + stringdouble + ')',
bygroups(Keyword, Text, String.Double), 'namespacedecl'),
(r'(at)(\s+)(' + stringsingle + ')',
bygroups(Keyword, Text, String.Single), 'namespacedecl'),
(r'except|intersect|in|is|return|satisfies|to|union|where',
Keyword, 'root'),
(r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'),
(r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|', Operator, 'root'),
(r'external|at', Keyword, 'root'),
(r'(stable)(\s+)(order)(\s+)(by)',
bygroups(Keyword, Text, Keyword, Text, Keyword), 'root'),
(r'(castable|cast)(\s+)(as)',
bygroups(Keyword, Text, Keyword), 'singletype'),
(r'(treat)(\s+)(as)', bygroups(Keyword, Text, Keyword)),
(r'(instance)(\s+)(of)', bygroups(Keyword, Text, Keyword)),
(r'case|as', Keyword, 'itemtype'),
(r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
(ncname + r':\*', Keyword.Type, 'operator'),
(qname, Keyword.Type, 'occurrenceindicator'),
],
'kindtest': [
(r'\(:', Comment, 'comment'),
(r'{', Punctuation, 'root'),
(r'(\))([*+?]?)', popstate_kindtest_callback),
(r'\*', Name, 'closekindtest'),
(qname, Name, 'closekindtest'),
(r'(element|schema-element)(\s*)(\()', pushstate_kindtest_callback),
],
'kindtestforpi': [
(r'\(:', Comment, 'comment'),
(r'\)', Punctuation, '#pop'),
(ncname, Name.Variable),
(stringdouble, String.Double),
(stringsingle, String.Single),
],
'closekindtest': [
(r'\(:', Comment, 'comment'),
(r'(\))', popstate_callback),
(r',', Punctuation),
(r'(\{)', pushstate_operator_root_callback),
(r'\?', Punctuation),
],
'xml_comment': [
(r'(-->)', popstate_xmlcomment_callback),
(r'[^-]{1,2}', Literal),
(r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' +
unirange(0x10000, 0x10ffff), Literal),
],
'processing_instruction': [
(r'\s+', Text, 'processing_instruction_content'),
(r'\?>', String.Doc, '#pop'),
(pitarget, Name),
],
'processing_instruction_content': [
(r'\?>', String.Doc, '#pop'),
(r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' +
unirange(0x10000, 0x10ffff), Literal),
],
'cdata_section': [
(r']]>', String.Doc, '#pop'),
(r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' +
unirange(0x10000, 0x10ffff), Literal),
],
'start_tag': [
include('whitespace'),
(r'(/>)', popstate_tag_callback),
(r'>', Name.Tag, 'element_content'),
(r'"', Punctuation, 'quot_attribute_content'),
(r"'", Punctuation, 'apos_attribute_content'),
(r'=', Operator),
(qname, Name.Tag),
],
'quot_attribute_content': [
(r'"', Punctuation, 'start_tag'),
(r'(\{)', pushstate_root_callback),
(r'""', Name.Attribute),
(quotattrcontentchar, Name.Attribute),
(entityref, Name.Attribute),
(charref, Name.Attribute),
(r'\{\{|\}\}', Name.Attribute),
],
'apos_attribute_content': [
(r"'", Punctuation, 'start_tag'),
(r'\{', Punctuation, 'root'),
(r"''", Name.Attribute),
(aposattrcontentchar, Name.Attribute),
(entityref, Name.Attribute),
(charref, Name.Attribute),
(r'\{\{|\}\}', Name.Attribute),
],
'element_content': [
(r'</', Name.Tag, 'end_tag'),
(r'(\{)', pushstate_root_callback),
(r'(<!--)', pushstate_element_content_xmlcomment_callback),
(r'(<\?)', pushstate_element_content_processing_instruction_callback),
(r'(<!\[CDATA\[)', pushstate_element_content_cdata_section_callback),
(r'(<)', pushstate_element_content_starttag_callback),
(elementcontentchar, Literal),
(entityref, Literal),
(charref, Literal),
(r'\{\{|\}\}', Literal),
],
'end_tag': [
include('whitespace'),
(r'(>)', popstate_tag_callback),
(qname, Name.Tag),
],
'xmlspace_decl': [
(r'\(:', Comment, 'comment'),
(r'preserve|strip', Keyword, '#pop'),
],
'declareordering': [
(r'\(:', Comment, 'comment'),
include('whitespace'),
(r'ordered|unordered', Keyword, '#pop'),
],
'xqueryversion': [
include('whitespace'),
(r'\(:', Comment, 'comment'),
(stringdouble, String.Double),
(stringsingle, String.Single),
(r'encoding', Keyword),
(r';', Punctuation, '#pop'),
],
'pragma': [
(qname, Name.Variable, 'pragmacontents'),
],
'pragmacontents': [
(r'#\)', Punctuation, 'operator'),
(r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' +
unirange(0x10000, 0x10ffff), Literal),
(r'(\s+)', Text),
],
'occurrenceindicator': [
include('whitespace'),
(r'\(:', Comment, 'comment'),
(r'\*|\?|\+', Operator, 'operator'),
(r':=', Operator, 'root'),
(r'', Text, 'operator'),
],
'option': [
include('whitespace'),
(qname, Name.Variable, '#pop'),
],
'qname_braren': [
include('whitespace'),
(r'(\{)', pushstate_operator_root_callback),
(r'(\()', Punctuation, 'root'),
],
'element_qname': [
(qname, Name.Variable, 'root'),
],
'attribute_qname': [
(qname, Name.Variable, 'root'),
],
'root': [
include('whitespace'),
(r'\(:', Comment, 'comment'),
# handle operator state
# order on numbers matters - handle most complex first
(r'\d+(\.\d*)?[eE][\+\-]?\d+', Number.Double, 'operator'),
(r'(\.\d+)[eE][\+\-]?\d+', Number.Double, 'operator'),
(r'(\.\d+|\d+\.\d*)', Number, 'operator'),
(r'(\d+)', Number.Integer, 'operator'),
(r'(\.\.|\.|\))', Punctuation, 'operator'),
(r'(declare)(\s+)(construction)',
bygroups(Keyword, Text, Keyword), 'operator'),
(r'(declare)(\s+)(default)(\s+)(order)',
bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'),
(ncname + ':\*', Name, 'operator'),
('\*:'+ncname, Name.Tag, 'operator'),
('\*', Name.Tag, 'operator'),
(stringdouble, String.Double, 'operator'),
(stringsingle, String.Single, 'operator'),
(r'(\})', popstate_callback),
#NAMESPACE DECL
(r'(declare)(\s+)(default)(\s+)(collation)',
bygroups(Keyword, Text, Keyword, Text, Keyword)),
(r'(module|declare)(\s+)(namespace)',
bygroups(Keyword, Text, Keyword), 'namespacedecl'),
(r'(declare)(\s+)(base-uri)',
bygroups(Keyword, Text, Keyword), 'namespacedecl'),
#NAMESPACE KEYWORD
(r'(declare)(\s+)(default)(\s+)(element|function)',
bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'),
(r'(import)(\s+)(schema|module)',
bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'),
(r'(declare)(\s+)(copy-namespaces)',
bygroups(Keyword, Text, Keyword), 'namespacekeyword'),
#VARNAMEs
(r'(for|let|some|every)(\s+)(\$)',
bygroups(Keyword, Text, Name.Variable), 'varname'),
(r'\$', Name.Variable, 'varname'),
(r'(declare)(\s+)(variable)(\s+)(\$)',
bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'),
#ITEMTYPE
(r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
(r'(element|attribute|schema-element|schema-attribute|comment|'
r'text|node|document-node|empty-sequence)(\s+)(\()',
pushstate_operator_kindtest_callback),
(r'(processing-instruction)(\s+)(\()',
pushstate_operator_kindtestforpi_callback),
(r'(<!--)', pushstate_operator_xmlcomment_callback),
(r'(<\?)', pushstate_operator_processing_instruction_callback),
(r'(<!\[CDATA\[)', pushstate_operator_cdata_section_callback),
# (r'</', Name.Tag, 'end_tag'),
(r'(<)', pushstate_operator_starttag_callback),
(r'(declare)(\s+)(boundary-space)',
bygroups(Keyword, Text, Keyword), 'xmlspace_decl'),
(r'(validate)(\s+)(lax|strict)',
pushstate_operator_root_validate_withmode),
(r'(validate)(\s*)(\{)', pushstate_operator_root_validate),
(r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
(r'(element|attribute)(\s*)(\{)',
pushstate_operator_root_construct_callback),
(r'(document|text|processing-instruction|comment)(\s*)(\{)',
pushstate_operator_root_construct_callback),
#ATTRIBUTE
(r'(attribute)(\s+)(?=' + qname + r')',
bygroups(Keyword, Text), 'attribute_qname'),
#ELEMENT
(r'(element)(\s+)(?=' +qname+ r')',
bygroups(Keyword, Text), 'element_qname'),
#PROCESSING_INSTRUCTION
(r'(processing-instruction)(\s+)(' + ncname + r')(\s*)(\{)',
bygroups(Keyword, Text, Name.Variable, Text, Punctuation),
'operator'),
(r'(declare|define)(\s+)(function)',
bygroups(Keyword, Text, Keyword)),
(r'(\{)', pushstate_operator_root_callback),
(r'(unordered|ordered)(\s*)(\{)',
pushstate_operator_order_callback),
(r'(declare)(\s+)(ordering)',
bygroups(Keyword, Text, Keyword), 'declareordering'),
(r'(xquery)(\s+)(version)',
bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'),
(r'(\(#)', Punctuation, 'pragma'),
# sometimes return can occur in root state
(r'return', Keyword),
(r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword),
'option'),
#URI LITERALS - single and double quoted
(r'(at)(\s+)('+stringdouble+')', String.Double, 'namespacedecl'),
(r'(at)(\s+)('+stringsingle+')', String.Single, 'namespacedecl'),
(r'(ancestor-or-self|ancestor|attribute|child|descendant-or-self)(::)',
bygroups(Keyword, Punctuation)),
(r'(descendant|following-sibling|following|parent|preceding-sibling'
r'|preceding|self)(::)', bygroups(Keyword, Punctuation)),
(r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
(r'then|else', Keyword),
# ML specific
(r'(try)(\s*)', bygroups(Keyword, Text), 'root'),
(r'(catch)(\s*)(\()(\$)',
bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'),
(r'(@'+qname+')', Name.Attribute),
(r'(@'+ncname+')', Name.Attribute),
(r'@\*:'+ncname, Name.Attribute),
(r'(@)', Name.Attribute),
(r'//|/|\+|-|;|,|\(|\)', Punctuation),
# STANDALONE QNAMES
(qname + r'(?=\s*{)', Name.Tag, 'qname_braren'),
(qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'),
(qname, Name.Tag, 'operator'),
]
}
class DartLexer(RegexLexer):
"""
For `Dart <http://dartlang.org/>`_ source code.
*New in Pygments 1.5.*
"""
name = 'Dart'
aliases = ['dart']
filenames = ['*.dart']
mimetypes = ['text/x-dart']
flags = re.MULTILINE | re.DOTALL
tokens = {
'root': [
include('string_literal'),
(r'#!(.*?)$', Comment.Preproc),
(r'\b(import|export)\b', Keyword, 'import_decl'),
(r'\b(library|source|part of|part)\b', Keyword),
(r'[^\S\n]+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline),
(r'\b(class)\b(\s+)',
bygroups(Keyword.Declaration, Text), 'class'),
(r'\b(assert|break|case|catch|continue|default|do|else|finally|for|'
r'if|in|is|new|return|super|switch|this|throw|try|while)\b',
Keyword),
(r'\b(abstract|const|extends|factory|final|get|implements|'
r'native|operator|set|static|typedef|var)\b', Keyword.Declaration),
(r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type),
(r'\b(false|null|true)\b', Keyword.Constant),
(r'[~!%^&*+=|?:<>/-]|as', Operator),
(r'[a-zA-Z_$][a-zA-Z0-9_]*:', Name.Label),
(r'[a-zA-Z_$][a-zA-Z0-9_]*', Name),
(r'[(){}\[\],.;]', Punctuation),
(r'0[xX][0-9a-fA-F]+', Number.Hex),
# DIGIT+ (‘.’ DIGIT*)? EXPONENT?
(r'\d+(\.\d*)?([eE][+-]?\d+)?', Number),
(r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT?
(r'\n', Text)
# pseudo-keyword negate intentionally left out
],
'class': [
(r'[a-zA-Z_$][a-zA-Z0-9_]*', Name.Class, '#pop')
],
'import_decl': [
include('string_literal'),
(r'\s+', Text),
(r'\b(as|show|hide)\b', Keyword),
(r'[a-zA-Z_$][a-zA-Z0-9_]*', Name),
(r'\,', Punctuation),
(r'\;', Punctuation, '#pop')
],
'string_literal': [
# Raw strings.
(r'r"""([\s|\S]*?)"""', String.Double),
(r"r'''([\s|\S]*?)'''", String.Single),
(r'r"(.*?)"', String.Double),
(r"r'(.*?)'", String.Single),
# Normal Strings.
(r'"""', String.Double, 'string_double_multiline'),
(r"'''", String.Single, 'string_single_multiline'),
(r'"', String.Double, 'string_double'),
(r"'", String.Single, 'string_single')
],
'string_common': [
(r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z\'\"$\\])",
String.Escape),
(r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)),
(r'(\$\{)(.*?)(\})',
bygroups(String.Interpol, using(this), String.Interpol))
],
'string_double': [
(r'"', String.Double, '#pop'),
(r'[^\"$\\\n]+', String.Double),
include('string_common'),
(r'\$+', String.Double)
],
'string_double_multiline': [
(r'"""', String.Double, '#pop'),
(r'[^\"$\\]+', String.Double),
include('string_common'),
(r'(\$|\")+', String.Double)
],
'string_single': [
(r"'", String.Single, '#pop'),
(r"[^\'$\\\n]+", String.Single),
include('string_common'),
(r'\$+', String.Single)
],
'string_single_multiline': [
(r"'''", String.Single, '#pop'),
(r'[^\'$\\]+', String.Single),
include('string_common'),
(r'(\$|\')+', String.Single)
]
}
class TypeScriptLexer(RegexLexer):
"""
For `TypeScript <http://www.python.org>`_ source code.
*New in Pygments 1.6.*
"""
name = 'TypeScript'
aliases = ['ts']
filenames = ['*.ts']
mimetypes = ['text/x-typescript']
flags = re.DOTALL
tokens = {
'commentsandwhitespace': [
(r'\s+', Text),
(r'<!--', Comment),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline)
],
'slashstartsregex': [
include('commentsandwhitespace'),
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'(?=/)', Text, ('#pop', 'badregex')),
(r'', Text, '#pop')
],
'badregex': [
(r'\n', Text, '#pop')
],
'root': [
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
r'this)\b', Keyword, 'slashstartsregex'),
(r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
(r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
r'extends|final|float|goto|implements|import|int|interface|long|native|'
r'package|private|protected|public|short|static|super|synchronized|throws|'
r'transient|volatile)\b', Keyword.Reserved),
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
r'decodeURIComponent|encodeURI|encodeURIComponent|'
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
r'window)\b', Name.Builtin),
# Match stuff like: module name {...}
(r'\b(module)(\s*)(\s*[a-zA-Z0-9_?.$][\w?.$]*)(\s*)',
bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'),
# Match variable type keywords
(r'\b(string|bool|number)\b', Keyword.Type),
# Match stuff like: constructor
(r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved),
# Match stuff like: super(argument, list)
(r'(super)(\s*)(\([a-zA-Z0-9,_?.$\s]+\s*\))',
bygroups(Keyword.Reserved, Text), 'slashstartsregex'),
# Match stuff like: function() {...}
(r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'),
# Match stuff like: (function: return type)
(r'([a-zA-Z0-9_?.$][\w?.$]*)(\s*:\s*)([a-zA-Z0-9_?.$][\w?.$]*)',
bygroups(Name.Other, Text, Keyword.Type)),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-fA-F]+', Number.Hex),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
]
}
class LassoLexer(RegexLexer):
"""
For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9
syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in
HTML, use the `LassoHtmlLexer`.
Additional options accepted:
`builtinshighlighting`
If given and ``True``, highlight builtin types, traits, methods, and
members (default: ``True``).
`requiredelimiters`
If given and ``True``, only highlight code between delimiters as Lasso
(default: ``False``).
*New in Pygments 1.6.*
"""
name = 'Lasso'
aliases = ['lasso', 'lassoscript']
filenames = ['*.lasso', '*.lasso[89]']
alias_filenames = ['*.incl', '*.inc', '*.las']
mimetypes = ['text/x-lasso']
flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
tokens = {
'root': [
(r'^#!.+lasso9\b', Comment.Preproc, 'lasso'),
(r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'),
(r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')),
(r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')),
(r'<\?(LassoScript|lasso|=)', Comment.Preproc,
('delimiters', 'anglebrackets')),
(r'<', Other, 'delimiters'),
(r'\s+', Other),
(r'', Other, ('delimiters', 'lassofile')),
],
'delimiters': [
(r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'),
(r'\[noprocess\]', Comment.Preproc, 'noprocess'),
(r'\[', Comment.Preproc, 'squarebrackets'),
(r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'),
(r'<', Other),
(r'[^[<]+', Other),
],
'nosquarebrackets': [
(r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'),
(r'<', Other),
(r'[^<]+', Other),
],
'noprocess': [
(r'\[/noprocess\]', Comment.Preproc, '#pop'),
(r'\[', Other),
(r'[^[]', Other),
],
'squarebrackets': [
(r'\]', Comment.Preproc, '#pop'),
include('lasso'),
],
'anglebrackets': [
(r'\?>', Comment.Preproc, '#pop'),
include('lasso'),
],
'lassofile': [
(r'\]', Comment.Preproc, '#pop'),
(r'\?>', Comment.Preproc, '#pop'),
include('lasso'),
],
'whitespacecomments': [
(r'\s+', Text),
(r'//.*?\n', Comment.Single),
(r'/\*\*!.*?\*/', String.Doc),
(r'/\*.*?\*/', Comment.Multiline),
],
'lasso': [
# whitespace/comments
include('whitespacecomments'),
# literals
(r'\d*\.\d+(e[+-]?\d+)?', Number.Float),
(r'0x[\da-f]+', Number.Hex),
(r'\d+', Number.Integer),
(r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)),
(r"'", String.Single, 'singlestring'),
(r'"', String.Double, 'doublestring'),
(r'`[^`]*`', String.Backtick),
# names
(r'\$[a-z_][\w.]*', Name.Variable),
(r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance),
(r"(\.)('[a-z_][\w.]*')",
bygroups(Name.Builtin.Pseudo, Name.Variable.Class)),
(r"(self)(\s*->\s*)('[a-z_][\w.]*')",
bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)),
(r'(\.\.?)([a-z_][\w.]*)',
bygroups(Name.Builtin.Pseudo, Name.Other.Member)),
(r'(->\\?\s*|&\s*)([a-z_][\w.]*)',
bygroups(Operator, Name.Other.Member)),
(r'(self|inherited|global|void)\b', Name.Builtin.Pseudo),
(r'-[a-z_][\w.]*', Name.Attribute),
(r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)),
(r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|'
r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|'
r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|'
r'Error_InvalidDatabase|Error_InvalidPassword|'
r'Error_InvalidUsername|Error_ModuleNotFound|'
r'Error_NoError|Error_NoPermission|Error_OutOfMemory|'
r'Error_ReqColumnMissing|Error_ReqFieldMissing|'
r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|'
r'Error_UpdateError)\b', Name.Exception),
# definitions
(r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b',
bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)),
(r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%<>]|==)',
bygroups(Keyword.Declaration, Text, Name.Class, Operator,
Name.Function), 'signature'),
(r'(define)(\s+)([a-z_][\w.]*)',
bygroups(Keyword.Declaration, Text, Name.Function), 'signature'),
(r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|'
r'[-+*/%<>]|==)(?=\s*\())', bygroups(Keyword, Text, Name.Function),
'signature'),
(r'(public|protected|private)(\s+)([a-z_][\w.]*)',
bygroups(Keyword, Text, Name.Function)),
# keywords
(r'(true|false|none|minimal|full|all)\b', Keyword.Constant),
(r'(local|var|variable|data(?=\s))\b', Keyword.Declaration),
(r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|'
r'null|list|queue|set|stack|staticarray)\b', Keyword.Type),
(r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)),
(r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)),
(r'require\b', Keyword, 'requiresection'),
(r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)),
(r'(/?)(Cache|Database_Names|Database_SchemaNames|'
r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|'
r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|'
r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|'
r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|'
r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|'
r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|'
r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|'
r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|'
r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|'
r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|'
r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|'
r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|'
r'Tag_Name|ascending|average|by|define|descending|do|equals|'
r'frozen|group|handle_failure|import|in|into|join|let|match|max|'
r'min|on|order|parent|protected|provide|public|require|skip|'
r'split_thread|sum|take|thread|to|trait|type|where|with|yield)\b',
bygroups(Punctuation, Keyword)),
# other
(r',', Punctuation, 'commamember'),
(r'(and|or|not)\b', Operator.Word),
(r'([a-z_][\w.]*)(\s*::\s*)?([a-z_][\w.]*)?(\s*=(?!=))',
bygroups(Name, Punctuation, Name.Label, Operator)),
(r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)),
(r'(=)(bw|ew|cn|lte?|gte?|n?eq|ft|n?rx)\b',
bygroups(Operator, Operator.Word)),
(r':=|[-+*/%=<>&|!?\\]+', Operator),
(r'[{}():;,@^]', Punctuation),
],
'singlestring': [
(r"'", String.Single, '#pop'),
(r"[^'\\]+", String.Single),
include('escape'),
(r"\\+", String.Single),
],
'doublestring': [
(r'"', String.Double, '#pop'),
(r'[^"\\]+', String.Double),
include('escape'),
(r'\\+', String.Double),
],
'escape': [
(r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|'
r'[abefnrtv?\"\'\\]|$)', String.Escape),
],
'signature': [
(r'=>', Operator, '#pop'),
(r'\)', Punctuation, '#pop'),
(r'[(,]', Punctuation, 'parameter'),
include('lasso'),
],
'parameter': [
(r'\)', Punctuation, '#pop'),
(r'-?[a-z_][\w.]*', Name.Attribute, '#pop'),
(r'\.\.\.', Name.Builtin.Pseudo),
include('lasso'),
],
'requiresection': [
(r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=\s*\())', Name, 'requiresignature'),
(r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=(\s*::\s*[\w.]+)?\s*,))', Name),
(r'[a-z_][\w.]*=?|[-+*/%<>]|==', Name, '#pop'),
(r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)),
(r',', Punctuation),
include('whitespacecomments'),
],
'requiresignature': [
(r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'),
(r'\)', Punctuation, '#pop:2'),
(r'-?[a-z_][\w.]*', Name.Attribute),
(r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)),
(r'\.\.\.', Name.Builtin.Pseudo),
(r'[(,]', Punctuation),
include('whitespacecomments'),
],
'commamember': [
(r'(([a-z_][\w.]*=?|[-+*/%<>]|==)'
r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))',
Name.Function, 'signature'),
include('whitespacecomments'),
(r'', Text, '#pop'),
],
}
def __init__(self, **options):
self.builtinshighlighting = get_bool_opt(
options, 'builtinshighlighting', True)
self.requiredelimiters = get_bool_opt(
options, 'requiredelimiters', False)
self._builtins = set()
self._members = set()
if self.builtinshighlighting:
from pygments.lexers._lassobuiltins import BUILTINS, MEMBERS
for key, value in BUILTINS.items():
self._builtins.update(value)
for key, value in MEMBERS.items():
self._members.update(value)
RegexLexer.__init__(self, **options)
def get_tokens_unprocessed(self, text):
stack = ['root']
if self.requiredelimiters:
stack.append('delimiters')
for index, token, value in \
RegexLexer.get_tokens_unprocessed(self, text, stack):
if (token is Name.Other and value.lower() in self._builtins or
token is Name.Other.Member and value.lower() in self._members):
yield index, Name.Builtin, value
continue
yield index, token, value
def analyse_text(text):
rv = 0.0
if 'bin/lasso9' in text:
rv += 0.8
if re.search(r'<\?(=|lasso)|\A\[', text, re.I):
rv += 0.4
if re.search(r'local\(', text, re.I):
rv += 0.4
if '?>' in text:
rv += 0.1
return rv
class QmlLexer(RegexLexer):
"""
For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html.
*New in Pygments 1.6.*
"""
# QML is based on javascript, so much of this is taken from the
# JavascriptLexer above.
name = 'QML'
aliases = ['qml', 'Qt Meta Language', 'Qt modeling Language']
filenames = ['*.qml',]
mimetypes = [ 'application/x-qml',]
# pasted from JavascriptLexer, with some additions
flags = re.DOTALL
tokens = {
'commentsandwhitespace': [
(r'\s+', Text),
(r'<!--', Comment),
(r'//.*?\n', Comment.Single),
(r'/\*.*?\*/', Comment.Multiline)
],
'slashstartsregex': [
include('commentsandwhitespace'),
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'(?=/)', Text, ('#pop', 'badregex')),
(r'', Text, '#pop')
],
'badregex': [
(r'\n', Text, '#pop')
],
'root' : [
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
# QML insertions
(r'\bid\s*:\s*[A-Za-z][_A-Za-z.0-9]*',Keyword.Declaration,
'slashstartsregex'),
(r'\b[A-Za-z][_A-Za-z.0-9]*\s*:',Keyword, 'slashstartsregex'),
# the rest from JavascriptLexer
(r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
r'this)\b', Keyword, 'slashstartsregex'),
(r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
(r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
r'extends|final|float|goto|implements|import|int|interface|long|native|'
r'package|private|protected|public|short|static|super|synchronized|throws|'
r'transient|volatile)\b', Keyword.Reserved),
(r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
(r'(Array|Boolean|Date|Error|Function|Math|netscape|'
r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
r'decodeURIComponent|encodeURI|encodeURIComponent|'
r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
r'window)\b', Name.Builtin),
(r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
(r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
(r'0x[0-9a-fA-F]+', Number.Hex),
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
]
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
2520,
272,
18294,
23597,
339,
491,
476,
1192,
367,
3330,
13,
2407,
10815,
436,
9189,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
646,
1331,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
12,
13706,
19856,
12,
10259,
12,
1808,
12,
971,
1362,
2387,
12,
642,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
1362,
4860,
12,
5439,
12,
10357,
12,
18271,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
12,
664,
63,
513,
63,
2992,
12,
10734,
63,
2930,
63,
1652,
12,
971,
2079,
3517,
63,
6356,
63,
6742,
12,
625,
723,
618,
199,
504,
13277,
14,
12245,
14,
643,
441,
492,
820,
10972,
5838,
199,
504,
13277,
14,
12245,
14,
8427,
492,
17619,
65,
5838,
421,
199,
363,
452,
363,
275,
788,
12957,
5838,
297,
283,
8672,
5838,
297,
283,
31708,
5838,
297,
283,
9653,
5838,
297,
283,
35,
385,
5838,
297,
1779,
283,
5663,
80,
5838,
297,
283,
3310,
5229,
5838,
297,
283,
56,
2482,
84,
5838,
297,
283,
3310,
5229,
19,
5838,
297,
1779,
283,
45,
1652,
5838,
297,
283,
40,
1219,
69,
5838,
297,
283,
40,
3935,
5838,
297,
283,
51,
405,
5838,
297,
283,
51,
3919,
5838,
297,
1779,
283,
29104,
42,
5838,
297,
283,
967,
24715,
5229,
5838,
297,
283,
17458,
5229,
5838,
297,
1779,
283,
36,
13086,
5838,
297,
283,
7181,
3935,
5838,
297,
283,
42,
9587,
5838,
297,
283,
56,
3227,
5838,
297,
1779,
283,
36,
2076,
5838,
297,
283,
36,
580,
5838,
297,
283,
27537,
5838,
297,
283,
49,
757,
5838,
297,
283,
804,
5229,
5838,
418,
421,
199,
533,
31861,
5838,
8,
19856,
304,
272,
408,
272,
2104,
15250,
1350,
1233,
14,
272,
408,
339,
536,
275,
283,
21986,
7,
272,
5481,
275,
788,
3596,
297,
283,
9554,
418,
272,
6203,
275,
17855,
3596,
297,
1622,
272,
13290,
275,
788,
3578,
15,
9554,
297,
283,
3578,
15,
88,
13,
9554,
297,
326,
283,
505,
15,
88,
13,
9554,
297,
283,
505,
15,
9554,
297,
1622,
339,
3285,
275,
295,
14,
16504,
272,
4645,
275,
469,
267,
283,
6223,
460,
8506,
356,
359,
288,
334,
82,
1154,
83,
7386,
4516,
395,
288,
334,
82,
7601,
17722,
297,
6819,
395,
288,
334,
82,
28866,
21040,
78,
297,
6819,
14,
7200,
395,
288,
334,
82,
32575,
10,
21040,
10,
3678,
6819,
14,
18933,
9,
267,
2156,
267,
283,
7001,
17116,
3821,
356,
359,
288,
2387,
360,
6223,
460,
8506,
659,
288,
334,
82,
7,
7985,
20942,
23629,
28787,
9780,
78,
61,
6113,
7528,
20942,
92,
16045,
61,
9780,
78,
19100,
29030,
4805,
1467,
519,
21731,
71,
1017,
24621,
66,
6113,
34,
3196,
2624,
14,
5103,
12,
3943,
1935,
659,
288,
334,
82,
10120,
13043,
3196,
4516,
12,
22870,
1935,
297,
283,
4087,
3821,
3855,
288,
334,
82,
6448,
4516,
12,
3943,
1935,
358,
267,
2156,
267,
283,
4087,
3821,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
12,
3943,
1935,
358,
267,
2156,
267,
283,
1231,
356,
359,
288,
334,
82,
24550,
9529,
83,
92,
15,
92,
25273,
3196,
4516,
12,
283,
7001,
17116,
3821,
659,
288,
2387,
360,
6223,
460,
8506,
659,
288,
334,
82,
1154,
7896,
21449,
306,
92,
94,
92,
12574,
6113,
20910,
26,
6113,
6113,
10644,
1103,
2229,
9529,
78,
9,
5227,
1467,
519,
6774,
8999,
92,
6071,
20910,
389,
20910,
1111,
20910,
1988,
16137,
11,
32639,
28103,
6113,
62,
15,
566,
29,
7044,
11013,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
3894,
91,
2961,
59,
27031,
4300,
10357,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
3894,
30446,
1055,
4300,
10357,
395,
288,
334,
82,
6774,
509,
92,
262,
92,
6710,
92,
1117,
92,
4785,
92,
1107,
92,
6958,
92,
5656,
92,
2546,
92,
885,
92,
692,
92,
2836,
5227,
1467,
519,
1133,
72,
1143,
92,
893,
92,
9341,
92,
15172,
92,
1222,
92,
1807,
92,
23426,
92,
842,
1618,
92,
1647,
92,
11481,
5227,
1467,
519,
1133,
866,
2862,
66,
297,
6431,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
6774,
1391,
92,
2723,
92,
1045,
92,
1593,
2862,
66,
297,
6431,
14,
17737,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
6774,
6198,
92,
4871,
92,
4414,
92,
1560,
92,
533,
92,
1297,
92,
17612,
92,
3157,
92,
4869,
92,
3790,
5227,
1467,
519,
7,
11036,
92,
5094,
92,
1609,
92,
14867,
92,
24900,
92,
646,
92,
442,
92,
3266,
92,
2809,
92,
6106,
5227,
1467,
519,
7,
2491,
92,
4239,
92,
6798,
92,
3455,
92,
3612,
92,
1986,
92,
4792,
92,
16473,
1759,
92,
32229,
5227,
1467,
519,
1133,
1312,
14928,
92,
32059,
2862,
66,
297,
6431,
14,
10285,
395,
288,
334,
82,
6774,
2052,
92,
3910,
92,
2307,
92,
14300,
92,
14660,
92,
10705,
2862,
66,
297,
6431,
14,
9737,
395,
288,
334,
82,
6774,
3836,
92,
4082,
92,
2506,
92,
547,
92,
3481,
92,
18568,
92,
846,
3588,
5227,
1467,
519,
7,
3259,
92,
1692,
92,
25135,
92,
2872,
4527,
92,
1558,
92,
11846,
92,
2708,
7639,
5227,
1467,
519,
5121,
69,
600,
1230,
948,
22527,
1946,
92,
2143,
7639,
92,
2143,
1230,
948,
22527,
1946,
5227,
1467,
519,
7,
547,
92,
2579,
92,
374,
8694,
1175,
92,
374,
14300,
92,
1122,
5136,
92,
1122,
3241,
92,
3554,
92,
3749,
5227,
1467,
519,
7,
3806,
2862,
66,
297,
2812,
14,
12306,
395,
288,
334,
82,
3894,
4,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
14,
8632,
395,
288,
334,
82,
3894,
16,
13,
25,
1527,
16,
13,
25,
3672,
27658,
16,
13,
25,
2807,
779,
20565,
1527,
16,
13,
25,
23763,
59,
2592,
61,
7044,
4860,
14,
5136,
395,
288,
334,
82,
7,
16,
88,
59,
16,
13,
25,
65,
13,
13753,
13,
38,
11529,
4860,
14,
10373,
395,
288,
334,
82,
3894,
16,
13,
25,
11529,
4860,
14,
2674,
395,
288,
334
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
2520,
272,
18294,
23597,
339,
491,
476,
1192,
367,
3330,
13,
2407,
10815,
436,
9189,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
646,
1331,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
12,
13706,
19856,
12,
10259,
12,
1808,
12,
971,
1362,
2387,
12,
642,
199,
504,
13277,
14,
1418,
492,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
971,
1362,
4860,
12,
5439,
12,
10357,
12,
18271,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
12,
664,
63,
513,
63,
2992,
12,
10734,
63,
2930,
63,
1652,
12,
971,
2079,
3517,
63,
6356,
63,
6742,
12,
625,
723,
618,
199,
504,
13277,
14,
12245,
14,
643,
441,
492,
820,
10972,
5838,
199,
504,
13277,
14,
12245,
14,
8427,
492,
17619,
65,
5838,
421,
199,
363,
452,
363,
275,
788,
12957,
5838,
297,
283,
8672,
5838,
297,
283,
31708,
5838,
297,
283,
9653,
5838,
297,
283,
35,
385,
5838,
297,
1779,
283,
5663,
80,
5838,
297,
283,
3310,
5229,
5838,
297,
283,
56,
2482,
84,
5838,
297,
283,
3310,
5229,
19,
5838,
297,
1779,
283,
45,
1652,
5838,
297,
283,
40,
1219,
69,
5838,
297,
283,
40,
3935,
5838,
297,
283,
51,
405,
5838,
297,
283,
51,
3919,
5838,
297,
1779,
283,
29104,
42,
5838,
297,
283,
967,
24715,
5229,
5838,
297,
283,
17458,
5229,
5838,
297,
1779,
283,
36,
13086,
5838,
297,
283,
7181,
3935,
5838,
297,
283,
42,
9587,
5838,
297,
283,
56,
3227,
5838,
297,
1779,
283,
36,
2076,
5838,
297,
283,
36,
580,
5838,
297,
283,
27537,
5838,
297,
283,
49,
757,
5838,
297,
283,
804,
5229,
5838,
418,
421,
199,
533,
31861,
5838,
8,
19856,
304,
272,
408,
272,
2104,
15250,
1350,
1233,
14,
272,
408,
339,
536,
275,
283,
21986,
7,
272,
5481,
275,
788,
3596,
297,
283,
9554,
418,
272,
6203,
275,
17855,
3596,
297,
1622,
272,
13290,
275,
788,
3578,
15,
9554,
297,
283,
3578,
15,
88,
13,
9554,
297,
326,
283,
505,
15,
88,
13,
9554,
297,
283,
505,
15,
9554,
297,
1622,
339,
3285,
275,
295,
14,
16504,
272,
4645,
275,
469,
267,
283,
6223,
460,
8506,
356,
359,
288,
334,
82,
1154,
83,
7386,
4516,
395,
288,
334,
82,
7601,
17722,
297,
6819,
395,
288,
334,
82,
28866,
21040,
78,
297,
6819,
14,
7200,
395,
288,
334,
82,
32575,
10,
21040,
10,
3678,
6819,
14,
18933,
9,
267,
2156,
267,
283,
7001,
17116,
3821,
356,
359,
288,
2387,
360,
6223,
460,
8506,
659,
288,
334,
82,
7,
7985,
20942,
23629,
28787,
9780,
78,
61,
6113,
7528,
20942,
92,
16045,
61,
9780,
78,
19100,
29030,
4805,
1467,
519,
21731,
71,
1017,
24621,
66,
6113,
34,
3196,
2624,
14,
5103,
12,
3943,
1935,
659,
288,
334,
82,
10120,
13043,
3196,
4516,
12,
22870,
1935,
297,
283,
4087,
3821,
3855,
288,
334,
82,
6448,
4516,
12,
3943,
1935,
358,
267,
2156,
267,
283,
4087,
3821,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
12,
3943,
1935,
358,
267,
2156,
267,
283,
1231,
356,
359,
288,
334,
82,
24550,
9529,
83,
92,
15,
92,
25273,
3196,
4516,
12,
283,
7001,
17116,
3821,
659,
288,
2387,
360,
6223,
460,
8506,
659,
288,
334,
82,
1154,
7896,
21449,
306,
92,
94,
92,
12574,
6113,
20910,
26,
6113,
6113,
10644,
1103,
2229,
9529,
78,
9,
5227,
1467,
519,
6774,
8999,
92,
6071,
20910,
389,
20910,
1111,
20910,
1988,
16137,
11,
32639,
28103,
6113,
62,
15,
566,
29,
7044,
11013,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
3894,
91,
2961,
59,
27031,
4300,
10357,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
3894,
30446,
1055,
4300,
10357,
395,
288,
334,
82,
6774,
509,
92,
262,
92,
6710,
92,
1117,
92,
4785,
92,
1107,
92,
6958,
92,
5656,
92,
2546,
92,
885,
92,
692,
92,
2836,
5227,
1467,
519,
1133,
72,
1143,
92,
893,
92,
9341,
92,
15172,
92,
1222,
92,
1807,
92,
23426,
92,
842,
1618,
92,
1647,
92,
11481,
5227,
1467,
519,
1133,
866,
2862,
66,
297,
6431,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
6774,
1391,
92,
2723,
92,
1045,
92,
1593,
2862,
66,
297,
6431,
14,
17737,
12,
283,
7001,
17116,
3821,
659,
288,
334,
82,
6774,
6198,
92,
4871,
92,
4414,
92,
1560,
92,
533,
92,
1297,
92,
17612,
92,
3157,
92,
4869,
92,
3790,
5227,
1467,
519,
7,
11036,
92,
5094,
92,
1609,
92,
14867,
92,
24900,
92,
646,
92,
442,
92,
3266,
92,
2809,
92,
6106,
5227,
1467,
519,
7,
2491,
92,
4239,
92,
6798,
92,
3455,
92,
3612,
92,
1986,
92,
4792,
92,
16473,
1759,
92,
32229,
5227,
1467,
519,
1133,
1312,
14928,
92,
32059,
2862,
66,
297,
6431,
14,
10285,
395,
288,
334,
82,
6774,
2052,
92,
3910,
92,
2307,
92,
14300,
92,
14660,
92,
10705,
2862,
66,
297,
6431,
14,
9737,
395,
288,
334,
82,
6774,
3836,
92,
4082,
92,
2506,
92,
547,
92,
3481,
92,
18568,
92,
846,
3588,
5227,
1467,
519,
7,
3259,
92,
1692,
92,
25135,
92,
2872,
4527,
92,
1558,
92,
11846,
92,
2708,
7639,
5227,
1467,
519,
5121,
69,
600,
1230,
948,
22527,
1946,
92,
2143,
7639,
92,
2143,
1230,
948,
22527,
1946,
5227,
1467,
519,
7,
547,
92,
2579,
92,
374,
8694,
1175,
92,
374,
14300,
92,
1122,
5136,
92,
1122,
3241,
92,
3554,
92,
3749,
5227,
1467,
519,
7,
3806,
2862,
66,
297,
2812,
14,
12306,
395,
288,
334,
82,
3894,
4,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
14,
8632,
395,
288,
334,
82,
3894,
16,
13,
25,
1527,
16,
13,
25,
3672,
27658,
16,
13,
25,
2807,
779,
20565,
1527,
16,
13,
25,
23763,
59,
2592,
61,
7044,
4860,
14,
5136,
395,
288,
334,
82,
7,
16,
88,
59,
16,
13,
25,
65,
13,
13753,
13,
38,
11529,
4860,
14,
10373,
395,
288,
334,
82,
3894,
16,
13,
25,
11529,
4860,
14,
2674,
395,
288,
334,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
shuhaida6704/account-financial-reporting
|
account_financial_report_webkit_xls/wizard/open_invoices_wizard.py
|
37
|
1876
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
#
# Copyright (c) 2013 Noviat nv/sa (www.noviat.com). All rights reserved.
#
# 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 orm
# import logging
# _logger = logging.getLogger(__name__)
class open_invoices_webkit_wizard(orm.TransientModel):
_inherit = 'open.invoices.webkit'
def xls_export(self, cr, uid, ids, context=None):
return self.check_report(cr, uid, ids, context=context)
def _print_report(self, cr, uid, ids, data, context=None):
context = context or {}
if context.get('xls_export'):
# we update form with display account value
data = self.pre_print_report(cr, uid, ids, data, context=context)
return {'type': 'ir.actions.report.xml',
'report_name': 'account.account_report_open_invoices_xls',
'datas': data}
else:
return super(open_invoices_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
6171,
3091,
433,
292,
26510,
15,
2231,
334,
1544,
14,
889,
433,
292,
14,
957,
680,
2900,
4481,
4644,
14,
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,
9813,
199,
3,
492,
2050,
199,
3,
485,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1551,
63,
28809,
63,
12554,
63,
9819,
8,
1025,
14,
14612,
14928,
1685,
304,
272,
485,
6486,
275,
283,
1490,
14,
28809,
14,
12554,
7,
339,
347,
671,
478,
63,
3790,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1074,
63,
3070,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
339,
347,
485,
1361,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
666,
12,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
1052,
267,
340,
1067,
14,
362,
360,
19023,
63,
3790,
735,
288,
327,
781,
1678,
1824,
543,
2929,
2933,
574,
288,
666,
275,
291,
14,
657,
63,
1361,
63,
3070,
8,
1556,
12,
1747,
12,
2762,
12,
666,
12,
1067,
29,
1100,
9,
288,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
490,
283,
3070,
63,
354,
356,
283,
2048,
14,
2048,
63,
3070,
63,
1490,
63,
28809,
63,
19023,
297,
490,
283,
11563,
356,
666,
93,
267,
587,
26,
288,
372,
1613,
8,
1490,
63,
28809,
63,
12554,
63,
9819,
12,
291,
10445,
1361,
63,
3070,
8,
355,
2467,
12,
1747,
12,
2762,
12,
666,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
6171,
3091,
433,
292,
26510,
15,
2231,
334,
1544,
14,
889,
433,
292,
14,
957,
680,
2900,
4481,
4644,
14,
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,
9813,
199,
3,
492,
2050,
199,
3,
485,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1551,
63,
28809,
63,
12554,
63,
9819,
8,
1025,
14,
14612,
14928,
1685,
304,
272,
485,
6486,
275,
283,
1490,
14,
28809,
14,
12554,
7,
339,
347,
671,
478,
63,
3790,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1074,
63,
3070,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
339,
347,
485,
1361,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
666,
12,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
1052,
267,
340,
1067,
14,
362,
360,
19023,
63,
3790,
735,
288,
327,
781,
1678,
1824,
543,
2929,
2933,
574,
288,
666,
275,
291,
14,
657,
63,
1361,
63,
3070,
8,
1556,
12,
1747,
12,
2762,
12,
666,
12,
1067,
29,
1100,
9,
288,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
3070,
14,
1652,
297,
490,
283,
3070,
63,
354,
356,
283,
2048,
14,
2048,
63,
3070,
63,
1490,
63,
28809,
63,
19023,
297,
490,
283,
11563,
356,
666,
93,
267,
587,
26,
288,
372,
1613,
8,
1490,
63,
28809,
63,
12554,
63,
9819,
12,
291,
10445,
1361,
63,
3070,
8,
355,
2467,
12,
1747,
12,
2762,
12,
666,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
John-Hart/autorest
|
src/generator/AutoRest.Python.Azure.Tests/Expected/AcceptanceTests/Lro/setup.py
|
10
|
1170
|
# 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.
# --------------------------------------------------------------------------
# coding: utf-8
from setuptools import setup, find_packages
NAME = "autorestlongrunningoperationtestservice"
VERSION = "1.0.0"
# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
REQUIRES = ["msrest>=0.4.0", "msrestazure>=0.4.0"]
setup(
name=NAME,
version=VERSION,
description="AutoRestLongRunningOperationTestService",
author_email="",
url="",
keywords=["Swagger", "AutoRestLongRunningOperationTestService"],
install_requires=REQUIRES,
packages=find_packages(),
include_package_data=True,
long_description="""\
Long-running Operation for AutoRest
"""
)
|
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,
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
2339,
275,
298,
27082,
270,
2809,
5720,
5735,
396,
1364,
2,
199,
4612,
275,
298,
17,
14,
16,
14,
16,
2,
199,
199,
3,
4005,
3907,
314,
3555,
12,
1255,
314,
2569,
199,
3,
199,
3,
2366,
3272,
14,
647,
3907,
199,
3,
199,
3,
876,
21763,
26,
9116,
199,
3,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
13623,
199,
199,
5255,
41,
3830,
275,
2097,
25427,
8119,
16,
14,
20,
14,
16,
401,
298,
706,
264,
1207,
7895,
8119,
16,
14,
20,
14,
16,
937,
199,
199,
2758,
8,
272,
536,
29,
2339,
12,
272,
1015,
29,
4612,
12,
272,
1369,
628,
3358,
13726,
9551,
9602,
6044,
774,
3167,
401,
272,
4132,
63,
2123,
8772,
272,
1166,
8772,
272,
7681,
6270,
10941,
16267,
401,
298,
3358,
13726,
9551,
9602,
6044,
774,
3167,
2255,
272,
3907,
63,
6537,
29,
5255,
41,
3830,
12,
272,
6117,
29,
1623,
63,
5154,
1062,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
1846,
63,
1802,
11916,
60,
272,
19944,
13,
5720,
17954,
367,
9195,
13726,
272,
408,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
3,
2803,
26,
2774,
13,
24,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
2339,
275,
298,
27082,
270,
2809,
5720,
5735,
396,
1364,
2,
199,
4612,
275,
298,
17,
14,
16,
14,
16,
2,
199,
199,
3,
4005,
3907,
314,
3555,
12,
1255,
314,
2569,
199,
3,
199,
3,
2366,
3272,
14,
647,
3907,
199,
3,
199,
3,
876,
21763,
26,
9116,
199,
3,
1455,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
13623,
199,
199,
5255,
41,
3830,
275,
2097,
25427,
8119,
16,
14,
20,
14,
16,
401,
298,
706,
264,
1207,
7895,
8119,
16,
14,
20,
14,
16,
937,
199,
199,
2758,
8,
272,
536,
29,
2339,
12,
272,
1015,
29,
4612,
12,
272,
1369,
628,
3358,
13726,
9551,
9602,
6044,
774,
3167,
401,
272,
4132,
63,
2123,
8772,
272,
1166,
8772,
272,
7681,
6270,
10941,
16267,
401,
298,
3358,
13726,
9551,
9602,
6044,
774,
3167,
2255,
272,
3907,
63,
6537,
29,
5255,
41,
3830,
12,
272,
6117,
29,
1623,
63,
5154,
1062,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
1846,
63,
1802,
11916,
60,
272,
19944,
13,
5720,
17954,
367,
9195,
13726,
272,
408,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
geggo/pyface
|
pyface/workbench/i_workbench_window_layout.py
|
3
|
10821
|
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.
# Description: <Enthought pyface package component>
#------------------------------------------------------------------------------
""" The workbench window layout interface. """
# Enthought library imports.
from traits.api import Event, HasTraits, Instance, Interface, Str
from traits.api import provides
# Local imports.
from .i_editor import IEditor
from .i_view import IView
class IWorkbenchWindowLayout(Interface):
""" The workbench window layout interface.
Window layouts are responsible for creating and managing the internal
structure of a workbench window (it knows how to add and remove views and
editors etc).
"""
# The Id of the editor area.
# FIXME v3: This is toolkit specific.
editor_area_id = Str
# The workbench window that this is the layout for.
window = Instance('pyface.workbench.api.WorkbenchWindow')
#### Events ####
# Fired when an editor is about to be opened (or restored).
editor_opening = Event(IEditor)
# Fired when an editor has been opened (or restored).
editor_opened = Event(IEditor)
# Fired when an editor is about to be closed.
editor_closing = Event(IEditor)
# Fired when an editor has been closed.
editor_closed = Event(IEditor)
# Fired when a view is about to be opened (or restored).
view_opening = Event(IView)
# Fired when a view has been opened (or restored).
view_opened = Event(IView)
# Fired when a view is about to be closed (*not* hidden!).
view_closing = Event(IView)
# Fired when a view has been closed (*not* hidden!).
view_closed = Event(IView)
# FIXME v3: The "just for convenience" returns are a really bad idea.
#
# Why? They allow the call to be used on the LHS of an expression...
# Because they have nothing to do with what the call is supposed to be
# doing, they are unlikely to be used (because they are so unexpected and
# inconsistently implemented), and only serve to replace two shorter lines
# of code with one long one, arguably making code more difficult to read.
def activate_editor(self, editor):
""" Activate an editor.
Returns the editor (just for convenience).
"""
def activate_view(self, view):
""" Activate a view.
Returns the view (just for convenience).
"""
def add_editor(self, editor, title):
""" Add an editor.
Returns the editor (just for convenience).
"""
def add_view(self, view, position=None, relative_to=None, size=(-1, -1)):
""" Add a view.
Returns the view (just for convenience).
"""
def close_editor(self, editor):
""" Close an editor.
Returns the editor (just for convenience).
"""
def close_view(self, view):
""" Close a view.
FIXME v3: Currently views are never 'closed' in the same sense as an
editor is closed. When we close an editor, we destroy its control.
When we close a view, we merely hide its control. I'm not sure if this
is a good idea or not. It came about after discussion with Dave P. and
he mentioned that some views might find it hard to persist enough state
that they can be re-created exactly as they were when they are shown
again.
Returns the view (just for convenience).
"""
def close(self):
""" Close the entire window layout.
FIXME v3: Should this be called 'destroy'?
"""
def create_initial_layout(self, parent):
""" Create the initial window layout.
Returns the layout.
"""
def contains_view(self, view):
""" Return True if the view exists in the window layout.
Note that this returns True even if the view is hidden.
"""
def hide_editor_area(self):
""" Hide the editor area.
"""
def hide_view(self, view):
""" Hide a view.
Returns the view (just for convenience).
"""
def refresh(self):
""" Refresh the window layout to reflect any changes.
"""
def reset_editors(self):
""" Activate the first editor in every group.
"""
def reset_views(self):
""" Activate the first view in every region.
"""
def show_editor_area(self):
""" Show the editor area.
"""
def show_view(self, view):
""" Show a view.
"""
#### Methods for saving and restoring the layout ##########################
def get_view_memento(self):
""" Returns the state of the views.
"""
def set_view_memento(self, memento):
""" Restores the state of the views.
"""
def get_editor_memento(self):
""" Returns the state of the editors.
"""
def set_editor_memento(self, memento):
""" Restores the state of the editors.
"""
def get_toolkit_memento(self):
""" Return any toolkit-specific data that should be part of the memento.
"""
def set_toolkit_memento(self, memento):
""" Restores any toolkit-specific data.
"""
@provides(IWorkbenchWindowLayout)
class MWorkbenchWindowLayout(HasTraits):
""" Mixin containing common code for toolkit-specific implementations. """
#### 'IWorkbenchWindowLayout' interface ###################################
# The Id of the editor area.
# FIXME v3: This is toolkit specific.
editor_area_id = Str
# The workbench window that this is the layout for.
window = Instance('pyface.workbench.api.WorkbenchWindow')
#### Events ####
# Fired when an editor is about to be opened (or restored).
editor_opening = Event(IEditor)
# Fired when an editor has been opened (or restored).
editor_opened = Event(IEditor)
# Fired when an editor is about to be closed.
editor_closing = Event(IEditor)
# Fired when an editor has been closed.
editor_closed = Event(IEditor)
# Fired when a view is about to be opened (or restored).
view_opening = Event(IView)
# Fired when a view has been opened (or restored).
view_opened = Event(IView)
# Fired when a view is about to be closed (*not* hidden!).
view_closing = Event(IView)
# Fired when a view has been closed (*not* hidden!).
view_closed = Event(IView)
###########################################################################
# 'IWorkbenchWindowLayout' interface.
###########################################################################
def activate_editor(self, editor):
""" Activate an editor. """
raise NotImplementedError
def activate_view(self, view):
""" Activate a view. """
raise NotImplementedError
def add_editor(self, editor, title):
""" Add an editor. """
raise NotImplementedError
def add_view(self, view, position=None, relative_to=None, size=(-1, -1)):
""" Add a view. """
raise NotImplementedError
def close_editor(self, editor):
""" Close an editor. """
raise NotImplementedError
def close_view(self, view):
""" Close a view. """
raise NotImplementedError
def close(self):
""" Close the entire window layout. """
raise NotImplementedError
def create_initial_layout(self, parent):
""" Create the initial window layout. """
raise NotImplementedError
def contains_view(self, view):
""" Return True if the view exists in the window layout. """
raise NotImplementedError
def hide_editor_area(self):
""" Hide the editor area. """
raise NotImplementedError
def hide_view(self, view):
""" Hide a view. """
raise NotImplementedError
def refresh(self):
""" Refresh the window layout to reflect any changes. """
raise NotImplementedError
def reset_editors(self):
""" Activate the first editor in every group. """
raise NotImplementedError
def reset_views(self):
""" Activate the first view in every region. """
raise NotImplementedError
def show_editor_area(self):
""" Show the editor area. """
raise NotImplementedError
def show_view(self, view):
""" Show a view. """
raise NotImplementedError
#### Methods for saving and restoring the layout ##########################
def get_view_memento(self):
""" Returns the state of the views. """
raise NotImplementedError
def set_view_memento(self, memento):
""" Restores the state of the views. """
raise NotImplementedError
def get_editor_memento(self):
""" Returns the state of the editors. """
raise NotImplementedError
def set_editor_memento(self, memento):
""" Restores the state of the editors. """
raise NotImplementedError
def get_toolkit_memento(self):
""" Return any toolkit-specific data that should be part of the memento.
"""
return None
def set_toolkit_memento(self, memento):
""" Restores any toolkit-specific data.
"""
return
###########################################################################
# Protected 'MWorkbenchWindowLayout' interface.
###########################################################################
def _get_editor_references(self):
""" Returns a reference to every editor. """
editor_manager = self.window.editor_manager
editor_references = {}
for editor in self.window.editors:
# Create the editor reference.
#
# If the editor manager returns 'None' instead of a resource
# reference then this editor will not appear the next time the
# workbench starts up. This is useful for things like text files
# that have an editor but have NEVER been saved.
editor_reference = editor_manager.get_editor_memento(editor)
if editor_reference is not None:
editor_references[editor.id] = editor_reference
return editor_references
#### EOF ######################################################################
|
bsd-3-clause
|
[
20974,
199,
3,
1898,
334,
67,
9,
11811,
12,
3447,
273,
20816,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
1928,
3750,
1334,
314,
2895,
402,
314,
6289,
199,
3,
4190,
5120,
315,
655,
273,
20816,
15,
3961,
14,
2424,
436,
1443,
506,
295,
16832,
1454,
199,
3,
1334,
314,
3704,
11736,
315,
314,
282,
1707,
32016,
379,
4190,
14,
221,
710,
4190,
199,
3,
365,
2597,
2808,
18470,
737,
1455,
921,
1544,
14,
287,
273,
20816,
14,
957,
15,
2383,
15,
15400,
14,
2424,
199,
3,
3868,
25088,
367,
1808,
3447,
273,
20816,
1551,
1350,
1,
199,
3,
199,
3,
6529,
26,
3447,
273,
20816,
12,
3277,
14,
199,
3,
11994,
26,
665,
1327,
273,
20816,
1134,
1409,
2559,
3931,
30,
199,
20974,
199,
624,
710,
1736,
16571,
4353,
7054,
3217,
14,
408,
421,
199,
3,
3447,
273,
20816,
3555,
8925,
14,
199,
504,
19692,
14,
1246,
492,
6763,
12,
13481,
31116,
12,
10066,
12,
14816,
12,
8303,
199,
504,
19692,
14,
1246,
492,
6571,
199,
199,
3,
10111,
8925,
14,
199,
504,
1275,
73,
63,
7515,
492,
473,
10423,
199,
504,
1275,
73,
63,
1345,
492,
473,
2768,
421,
199,
533,
473,
6517,
16571,
4301,
4798,
8,
4267,
304,
272,
408,
710,
1736,
16571,
4353,
7054,
3217,
14,
339,
15689,
7054,
83,
787,
17845,
367,
6425,
436,
28453,
314,
5007,
272,
5523,
402,
282,
1736,
16571,
4353,
334,
390,
19428,
4212,
370,
1050,
436,
2813,
6858,
436,
272,
5283,
1384,
5423,
680,
339,
408,
339,
327,
710,
15418,
402,
314,
8823,
9150,
14,
272,
327,
7600,
373,
19,
26,
961,
365,
4744,
6065,
2488,
14,
272,
8823,
63,
6789,
63,
344,
275,
8303,
339,
327,
710,
1736,
16571,
4353,
626,
642,
365,
314,
7054,
367,
14,
272,
4353,
275,
10066,
360,
647,
1409,
14,
800,
16571,
14,
1246,
14,
6517,
16571,
4301,
358,
339,
14055,
27982,
14055,
339,
327,
481,
16139,
1380,
376,
8823,
365,
3595,
370,
506,
12123,
334,
269,
14429,
680,
272,
8823,
63,
21849,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
376,
8823,
965,
2757,
12123,
334,
269,
14429,
680,
272,
8823,
63,
19234,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
376,
8823,
365,
3595,
370,
506,
6876,
14,
272,
8823,
63,
11707,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
376,
8823,
965,
2757,
6876,
14,
272,
8823,
63,
5938,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
282,
2455,
365,
3595,
370,
506,
12123,
334,
269,
14429,
680,
272,
2455,
63,
21849,
275,
6763,
8,
41,
2768,
9,
339,
327,
481,
16139,
1380,
282,
2455,
965,
2757,
12123,
334,
269,
14429,
680,
272,
2455,
63,
19234,
275,
6763,
8,
41,
2768,
9,
339,
327,
481,
16139,
1380,
282,
2455,
365,
3595,
370,
506,
6876,
19943,
1397,
10,
8752,
1,
680,
272,
2455,
63,
11707,
275,
6763,
8,
41,
2768,
9,
339,
327,
481,
16139,
1380,
282,
2455,
965,
2757,
6876,
19943,
1397,
10,
8752,
1,
680,
272,
2455,
63,
5938,
275,
6763,
8,
41,
2768,
9,
339,
327,
7600,
373,
19,
26,
710,
298,
4764,
367,
16777,
2,
2529,
787,
282,
7710,
4875,
16819,
14,
272,
327,
272,
327,
6827,
31,
9322,
2040,
314,
1240,
370,
506,
1202,
641,
314,
491,
15467,
402,
376,
3965,
1396,
272,
327,
13821,
2985,
1172,
6548,
370,
886,
543,
4052,
314,
1240,
365,
20042,
370,
506,
272,
327,
9689,
12,
2985,
787,
625,
24227,
370,
506,
1202,
334,
20684,
2985,
787,
880,
10537,
436,
272,
327,
27253,
590,
6366,
395,
436,
1454,
14062,
370,
3350,
2877,
18299,
2385,
272,
327,
402,
1233,
543,
1373,
1846,
1373,
12,
1680,
85,
6665,
10663,
1233,
1655,
29870,
370,
1586,
14,
272,
347,
15422,
63,
7515,
8,
277,
12,
8823,
304,
267,
408,
21904,
2409,
376,
8823,
14,
398,
1803,
314,
8823,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
15422,
63,
1345,
8,
277,
12,
2455,
304,
267,
408,
21904,
2409,
282,
2455,
14,
398,
1803,
314,
2455,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
1050,
63,
7515,
8,
277,
12,
8823,
12,
2538,
304,
267,
408,
2654,
376,
8823,
14,
398,
1803,
314,
8823,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
1050,
63,
1345,
8,
277,
12,
2455,
12,
3421,
29,
403,
12,
3847,
63,
475,
29,
403,
12,
1568,
26154,
17,
12,
446,
17,
2298,
267,
408,
2654,
282,
2455,
14,
398,
1803,
314,
2455,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
4002,
63,
7515,
8,
277,
12,
8823,
304,
267,
408,
15524,
376,
8823,
14,
398,
1803,
314,
8823,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
4002,
63,
1345,
8,
277,
12,
2455,
304,
267,
408,
15524,
282,
2455,
14,
398,
7600,
373,
19,
26,
13550,
6858,
787,
7078,
283,
5938,
7,
315,
314,
2011,
12249,
465,
376,
267,
8823,
365,
6876,
14,
3979,
781,
4002,
376,
8823,
12,
781,
11972,
2399,
3304,
14,
267,
3979,
781,
4002,
282,
2455,
12,
781,
562,
264,
590,
13714,
2399,
3304,
14,
473,
6704,
440,
3238,
340,
642,
267,
365,
282,
6954,
16819,
503,
440,
14,
2779,
20382,
3595,
2410,
16582,
543,
577,
811,
510,
14,
436,
267,
946,
26239,
626,
2005,
6858,
5594,
2342,
652,
7508,
370,
22400,
8321,
1174,
267,
626,
2985,
883,
506,
295,
13,
3966,
8840,
465,
2985,
4898,
1380,
2985,
787,
9164,
267,
4020,
14,
398,
1803,
314,
2455,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
4002,
8,
277,
304,
267,
408,
15524,
314,
8039,
4353,
7054,
14,
398,
7600,
373,
19,
26,
7719,
642,
506,
2797,
283,
7237,
27716,
398,
408,
339,
347,
1218,
63,
2747,
63,
4209,
8,
277,
12,
1676,
304,
267,
408,
2790,
314,
2536,
4353,
7054,
14,
398,
1803,
314,
7054,
14,
398,
408,
339,
347,
3509,
63,
1345,
8,
277,
12,
2455,
304,
267,
408,
1432,
715,
340,
314,
2455,
3495,
315,
314,
4353,
7054,
14,
398,
3390,
626,
642,
2529,
715,
2755,
340,
314,
2455,
365,
8752,
14,
398,
408,
339,
347,
13714,
63,
7515,
63,
6789,
8,
277,
304,
267,
408,
869,
2655,
314,
8823,
9150,
14
] |
[
199,
3,
1898,
334,
67,
9,
11811,
12,
3447,
273,
20816,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
1928,
3750,
1334,
314,
2895,
402,
314,
6289,
199,
3,
4190,
5120,
315,
655,
273,
20816,
15,
3961,
14,
2424,
436,
1443,
506,
295,
16832,
1454,
199,
3,
1334,
314,
3704,
11736,
315,
314,
282,
1707,
32016,
379,
4190,
14,
221,
710,
4190,
199,
3,
365,
2597,
2808,
18470,
737,
1455,
921,
1544,
14,
287,
273,
20816,
14,
957,
15,
2383,
15,
15400,
14,
2424,
199,
3,
3868,
25088,
367,
1808,
3447,
273,
20816,
1551,
1350,
1,
199,
3,
199,
3,
6529,
26,
3447,
273,
20816,
12,
3277,
14,
199,
3,
11994,
26,
665,
1327,
273,
20816,
1134,
1409,
2559,
3931,
30,
199,
20974,
199,
624,
710,
1736,
16571,
4353,
7054,
3217,
14,
408,
421,
199,
3,
3447,
273,
20816,
3555,
8925,
14,
199,
504,
19692,
14,
1246,
492,
6763,
12,
13481,
31116,
12,
10066,
12,
14816,
12,
8303,
199,
504,
19692,
14,
1246,
492,
6571,
199,
199,
3,
10111,
8925,
14,
199,
504,
1275,
73,
63,
7515,
492,
473,
10423,
199,
504,
1275,
73,
63,
1345,
492,
473,
2768,
421,
199,
533,
473,
6517,
16571,
4301,
4798,
8,
4267,
304,
272,
408,
710,
1736,
16571,
4353,
7054,
3217,
14,
339,
15689,
7054,
83,
787,
17845,
367,
6425,
436,
28453,
314,
5007,
272,
5523,
402,
282,
1736,
16571,
4353,
334,
390,
19428,
4212,
370,
1050,
436,
2813,
6858,
436,
272,
5283,
1384,
5423,
680,
339,
408,
339,
327,
710,
15418,
402,
314,
8823,
9150,
14,
272,
327,
7600,
373,
19,
26,
961,
365,
4744,
6065,
2488,
14,
272,
8823,
63,
6789,
63,
344,
275,
8303,
339,
327,
710,
1736,
16571,
4353,
626,
642,
365,
314,
7054,
367,
14,
272,
4353,
275,
10066,
360,
647,
1409,
14,
800,
16571,
14,
1246,
14,
6517,
16571,
4301,
358,
339,
14055,
27982,
14055,
339,
327,
481,
16139,
1380,
376,
8823,
365,
3595,
370,
506,
12123,
334,
269,
14429,
680,
272,
8823,
63,
21849,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
376,
8823,
965,
2757,
12123,
334,
269,
14429,
680,
272,
8823,
63,
19234,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
376,
8823,
365,
3595,
370,
506,
6876,
14,
272,
8823,
63,
11707,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
376,
8823,
965,
2757,
6876,
14,
272,
8823,
63,
5938,
275,
6763,
8,
4332,
27050,
9,
339,
327,
481,
16139,
1380,
282,
2455,
365,
3595,
370,
506,
12123,
334,
269,
14429,
680,
272,
2455,
63,
21849,
275,
6763,
8,
41,
2768,
9,
339,
327,
481,
16139,
1380,
282,
2455,
965,
2757,
12123,
334,
269,
14429,
680,
272,
2455,
63,
19234,
275,
6763,
8,
41,
2768,
9,
339,
327,
481,
16139,
1380,
282,
2455,
365,
3595,
370,
506,
6876,
19943,
1397,
10,
8752,
1,
680,
272,
2455,
63,
11707,
275,
6763,
8,
41,
2768,
9,
339,
327,
481,
16139,
1380,
282,
2455,
965,
2757,
6876,
19943,
1397,
10,
8752,
1,
680,
272,
2455,
63,
5938,
275,
6763,
8,
41,
2768,
9,
339,
327,
7600,
373,
19,
26,
710,
298,
4764,
367,
16777,
2,
2529,
787,
282,
7710,
4875,
16819,
14,
272,
327,
272,
327,
6827,
31,
9322,
2040,
314,
1240,
370,
506,
1202,
641,
314,
491,
15467,
402,
376,
3965,
1396,
272,
327,
13821,
2985,
1172,
6548,
370,
886,
543,
4052,
314,
1240,
365,
20042,
370,
506,
272,
327,
9689,
12,
2985,
787,
625,
24227,
370,
506,
1202,
334,
20684,
2985,
787,
880,
10537,
436,
272,
327,
27253,
590,
6366,
395,
436,
1454,
14062,
370,
3350,
2877,
18299,
2385,
272,
327,
402,
1233,
543,
1373,
1846,
1373,
12,
1680,
85,
6665,
10663,
1233,
1655,
29870,
370,
1586,
14,
272,
347,
15422,
63,
7515,
8,
277,
12,
8823,
304,
267,
408,
21904,
2409,
376,
8823,
14,
398,
1803,
314,
8823,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
15422,
63,
1345,
8,
277,
12,
2455,
304,
267,
408,
21904,
2409,
282,
2455,
14,
398,
1803,
314,
2455,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
1050,
63,
7515,
8,
277,
12,
8823,
12,
2538,
304,
267,
408,
2654,
376,
8823,
14,
398,
1803,
314,
8823,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
1050,
63,
1345,
8,
277,
12,
2455,
12,
3421,
29,
403,
12,
3847,
63,
475,
29,
403,
12,
1568,
26154,
17,
12,
446,
17,
2298,
267,
408,
2654,
282,
2455,
14,
398,
1803,
314,
2455,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
4002,
63,
7515,
8,
277,
12,
8823,
304,
267,
408,
15524,
376,
8823,
14,
398,
1803,
314,
8823,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
4002,
63,
1345,
8,
277,
12,
2455,
304,
267,
408,
15524,
282,
2455,
14,
398,
7600,
373,
19,
26,
13550,
6858,
787,
7078,
283,
5938,
7,
315,
314,
2011,
12249,
465,
376,
267,
8823,
365,
6876,
14,
3979,
781,
4002,
376,
8823,
12,
781,
11972,
2399,
3304,
14,
267,
3979,
781,
4002,
282,
2455,
12,
781,
562,
264,
590,
13714,
2399,
3304,
14,
473,
6704,
440,
3238,
340,
642,
267,
365,
282,
6954,
16819,
503,
440,
14,
2779,
20382,
3595,
2410,
16582,
543,
577,
811,
510,
14,
436,
267,
946,
26239,
626,
2005,
6858,
5594,
2342,
652,
7508,
370,
22400,
8321,
1174,
267,
626,
2985,
883,
506,
295,
13,
3966,
8840,
465,
2985,
4898,
1380,
2985,
787,
9164,
267,
4020,
14,
398,
1803,
314,
2455,
334,
4764,
367,
16777,
680,
398,
408,
339,
347,
4002,
8,
277,
304,
267,
408,
15524,
314,
8039,
4353,
7054,
14,
398,
7600,
373,
19,
26,
7719,
642,
506,
2797,
283,
7237,
27716,
398,
408,
339,
347,
1218,
63,
2747,
63,
4209,
8,
277,
12,
1676,
304,
267,
408,
2790,
314,
2536,
4353,
7054,
14,
398,
1803,
314,
7054,
14,
398,
408,
339,
347,
3509,
63,
1345,
8,
277,
12,
2455,
304,
267,
408,
1432,
715,
340,
314,
2455,
3495,
315,
314,
4353,
7054,
14,
398,
3390,
626,
642,
2529,
715,
2755,
340,
314,
2455,
365,
8752,
14,
398,
408,
339,
347,
13714,
63,
7515,
63,
6789,
8,
277,
304,
267,
408,
869,
2655,
314,
8823,
9150,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
nandhp/youtube-dl
|
youtube_dl/extractor/bild.py
|
48
|
1362
|
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
int_or_none,
unescapeHTML,
)
class BildIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?bild\.de/(?:[^/]+/)+(?P<display_id>[^/]+)-(?P<id>\d+)(?:,auto=true)?\.bild\.html'
IE_DESC = 'Bild.de'
_TEST = {
'url': 'http://www.bild.de/video/clip/apple-ipad-air/das-koennen-die-neuen-ipads-38184146.bild.html',
'md5': 'dd495cbd99f2413502a1713a1156ac8a',
'info_dict': {
'id': '38184146',
'ext': 'mp4',
'title': 'Das können die neuen iPads',
'description': 'md5:a4058c4fa2a804ab59c00d7244bbf62f',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': 196,
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
video_data = self._download_json(
url.split('.bild.html')[0] + ',view=json.bild.html', video_id)
return {
'id': video_id,
'title': unescapeHTML(video_data['title']).strip(),
'description': unescapeHTML(video_data.get('description')),
'url': video_data['clipList'][0]['srces'][0]['src'],
'thumbnail': video_data.get('poster'),
'duration': int_or_none(video_data.get('durationSec')),
}
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
22221,
4943,
12,
199,
9,
421,
199,
533,
699,
668,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
66,
668,
4537,
271,
32576,
26285,
15,
6393,
2229,
48,
28,
2918,
63,
344,
26906,
7216,
2229,
48,
28,
344,
3072,
68,
8771,
5169,
12,
2495,
29,
2052,
5547,
4537,
66,
668,
4537,
1360,
7,
272,
15292,
63,
15119,
275,
283,
34,
668,
14,
271,
7,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
66,
668,
14,
271,
15,
3722,
15,
7548,
15,
12820,
13,
711,
350,
13,
8387,
15,
24315,
13,
7697,
287,
78,
287,
13,
15130,
13,
685,
85,
287,
13,
711,
9402,
13,
1703,
10078,
11432,
14,
66,
668,
14,
1360,
297,
267,
283,
1064,
21,
356,
283,
617,
20384,
2894,
68,
1020,
70,
1194,
8312,
996,
65,
1196,
969,
65,
845,
1367,
645,
24,
65,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1703,
10078,
11432,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
36,
305,
1022,
14614,
4411,
287,
18833,
221,
1279,
85,
287,
284,
48,
9402,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
65,
15770,
24,
67,
20,
667,
18,
65,
26073,
371,
1427,
67,
383,
68,
23,
11603,
31319,
2789,
70,
297,
288,
283,
8311,
356,
283,
264,
23497,
2859,
32569,
8476,
4268,
288,
283,
5553,
356,
32132,
12,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
3991,
63,
576,
275,
291,
423,
4249,
63,
1001,
8,
288,
1166,
14,
1294,
5175,
66,
668,
14,
1360,
5832,
16,
61,
435,
1656,
1345,
29,
1001,
14,
66,
668,
14,
1360,
297,
3991,
63,
344,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
22221,
4943,
8,
3722,
63,
576,
459,
1213,
13227,
1913,
1062,
288,
283,
1802,
356,
22221,
4943,
8,
3722,
63,
576,
14,
362,
360,
1802,
3855,
288,
283,
633,
356,
3991,
63,
576,
459,
7548,
1296,
3488,
16,
2733,
5474,
823,
3488,
16,
2733,
2164,
995,
288,
283,
8311,
356,
3991,
63,
576,
14,
362,
360,
20801,
659,
288,
283,
5553,
356,
1109,
63,
269,
63,
3592,
8,
3722,
63,
576,
14,
362,
360,
5553,
4933,
3855,
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
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
22221,
4943,
12,
199,
9,
421,
199,
533,
699,
668,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
66,
668,
4537,
271,
32576,
26285,
15,
6393,
2229,
48,
28,
2918,
63,
344,
26906,
7216,
2229,
48,
28,
344,
3072,
68,
8771,
5169,
12,
2495,
29,
2052,
5547,
4537,
66,
668,
4537,
1360,
7,
272,
15292,
63,
15119,
275,
283,
34,
668,
14,
271,
7,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
66,
668,
14,
271,
15,
3722,
15,
7548,
15,
12820,
13,
711,
350,
13,
8387,
15,
24315,
13,
7697,
287,
78,
287,
13,
15130,
13,
685,
85,
287,
13,
711,
9402,
13,
1703,
10078,
11432,
14,
66,
668,
14,
1360,
297,
267,
283,
1064,
21,
356,
283,
617,
20384,
2894,
68,
1020,
70,
1194,
8312,
996,
65,
1196,
969,
65,
845,
1367,
645,
24,
65,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1703,
10078,
11432,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
36,
305,
1022,
14614,
4411,
287,
18833,
221,
1279,
85,
287,
284,
48,
9402,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
65,
15770,
24,
67,
20,
667,
18,
65,
26073,
371,
1427,
67,
383,
68,
23,
11603,
31319,
2789,
70,
297,
288,
283,
8311,
356,
283,
264,
23497,
2859,
32569,
8476,
4268,
288,
283,
5553,
356,
32132,
12,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
3991,
63,
576,
275,
291,
423,
4249,
63,
1001,
8,
288,
1166,
14,
1294,
5175,
66,
668,
14,
1360,
5832,
16,
61,
435,
1656,
1345,
29,
1001,
14,
66,
668,
14,
1360,
297,
3991,
63,
344,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
22221,
4943,
8,
3722,
63,
576,
459,
1213,
13227,
1913,
1062,
288,
283,
1802,
356,
22221,
4943,
8,
3722,
63,
576,
14,
362,
360,
1802,
3855,
288,
283,
633,
356,
3991,
63,
576,
459,
7548,
1296,
3488,
16,
2733,
5474,
823,
3488,
16,
2733,
2164,
995,
288,
283,
8311,
356,
3991,
63,
576,
14,
362,
360,
20801,
659,
288,
283,
5553,
356,
1109,
63,
269,
63,
3592,
8,
3722,
63,
576,
14,
362,
360,
5553,
4933,
3855,
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,
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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
from homeassistant.components.homekit import get_accessory
from homeassistant.components.homekit.const import (
DEVICE_CLASS_MOTION,
PROP_CELSIUS,
THRESHOLD_CO,
THRESHOLD_CO2,
)
from homeassistant.components.homekit.type_sensors import (
BINARY_SENSOR_SERVICE_MAP,
AirQualitySensor,
BinarySensor,
CarbonDioxideSensor,
CarbonMonoxideSensor,
HumiditySensor,
LightSensor,
TemperatureSensor,
)
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
EVENT_HOMEASSISTANT_START,
PERCENTAGE,
STATE_HOME,
STATE_NOT_HOME,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.core import CoreState
from homeassistant.helpers import entity_registry as er
async def test_temperature(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "sensor.temperature"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = TemperatureSensor(hass, hk_driver, "Temperature", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_temp.value == 0.0
for key, value in PROP_CELSIUS.items():
assert acc.char_temp.properties[key] == value
hass.states.async_set(
entity_id, STATE_UNKNOWN, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS}
)
await hass.async_block_till_done()
assert acc.char_temp.value == 0.0
hass.states.async_set(entity_id, "20", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
await hass.async_block_till_done()
assert acc.char_temp.value == 20
hass.states.async_set(
entity_id, "75.2", {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}
)
await hass.async_block_till_done()
assert acc.char_temp.value == 24
async def test_humidity(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "sensor.humidity"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = HumiditySensor(hass, hk_driver, "Humidity", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_humidity.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_humidity.value == 0
hass.states.async_set(entity_id, "20")
await hass.async_block_till_done()
assert acc.char_humidity.value == 20
async def test_air_quality(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "sensor.air_quality"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = AirQualitySensor(hass, hk_driver, "Air Quality", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_density.value == 0
assert acc.char_quality.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_density.value == 0
assert acc.char_quality.value == 0
hass.states.async_set(entity_id, "34")
await hass.async_block_till_done()
assert acc.char_density.value == 34
assert acc.char_quality.value == 1
hass.states.async_set(entity_id, "200")
await hass.async_block_till_done()
assert acc.char_density.value == 200
assert acc.char_quality.value == 5
async def test_co(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "sensor.co"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = CarbonMonoxideSensor(hass, hk_driver, "CO", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_level.value == 0
assert acc.char_peak.value == 0
assert acc.char_detected.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_level.value == 0
assert acc.char_peak.value == 0
assert acc.char_detected.value == 0
value = 32
assert value > THRESHOLD_CO
hass.states.async_set(entity_id, str(value))
await hass.async_block_till_done()
assert acc.char_level.value == 32
assert acc.char_peak.value == 32
assert acc.char_detected.value == 1
value = 10
assert value < THRESHOLD_CO
hass.states.async_set(entity_id, str(value))
await hass.async_block_till_done()
assert acc.char_level.value == 10
assert acc.char_peak.value == 32
assert acc.char_detected.value == 0
async def test_co2(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "sensor.co2"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = CarbonDioxideSensor(hass, hk_driver, "CO2", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_level.value == 0
assert acc.char_peak.value == 0
assert acc.char_detected.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_level.value == 0
assert acc.char_peak.value == 0
assert acc.char_detected.value == 0
value = 1100
assert value > THRESHOLD_CO2
hass.states.async_set(entity_id, str(value))
await hass.async_block_till_done()
assert acc.char_level.value == 1100
assert acc.char_peak.value == 1100
assert acc.char_detected.value == 1
value = 800
assert value < THRESHOLD_CO2
hass.states.async_set(entity_id, str(value))
await hass.async_block_till_done()
assert acc.char_level.value == 800
assert acc.char_peak.value == 1100
assert acc.char_detected.value == 0
async def test_light(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "sensor.light"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = LightSensor(hass, hk_driver, "Light", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_light.value == 0.0001
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_light.value == 0.0001
hass.states.async_set(entity_id, "300")
await hass.async_block_till_done()
assert acc.char_light.value == 300
async def test_binary(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "binary_sensor.opening"
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_DEVICE_CLASS: "opening"})
await hass.async_block_till_done()
acc = BinarySensor(hass, hk_driver, "Window Opening", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_detected.value == 0
hass.states.async_set(entity_id, STATE_ON, {ATTR_DEVICE_CLASS: "opening"})
await hass.async_block_till_done()
assert acc.char_detected.value == 1
hass.states.async_set(entity_id, STATE_OFF, {ATTR_DEVICE_CLASS: "opening"})
await hass.async_block_till_done()
assert acc.char_detected.value == 0
hass.states.async_set(entity_id, STATE_HOME, {ATTR_DEVICE_CLASS: "opening"})
await hass.async_block_till_done()
assert acc.char_detected.value == 1
hass.states.async_set(entity_id, STATE_NOT_HOME, {ATTR_DEVICE_CLASS: "opening"})
await hass.async_block_till_done()
assert acc.char_detected.value == 0
hass.states.async_remove(entity_id)
await hass.async_block_till_done()
assert acc.char_detected.value == 0
async def test_motion_uses_bool(hass, hk_driver):
"""Test if accessory is updated after state change."""
entity_id = "binary_sensor.motion"
hass.states.async_set(
entity_id, STATE_UNKNOWN, {ATTR_DEVICE_CLASS: DEVICE_CLASS_MOTION}
)
await hass.async_block_till_done()
acc = BinarySensor(hass, hk_driver, "Motion Sensor", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 10 # Sensor
assert acc.char_detected.value is False
hass.states.async_set(entity_id, STATE_ON, {ATTR_DEVICE_CLASS: DEVICE_CLASS_MOTION})
await hass.async_block_till_done()
assert acc.char_detected.value is True
hass.states.async_set(
entity_id, STATE_OFF, {ATTR_DEVICE_CLASS: DEVICE_CLASS_MOTION}
)
await hass.async_block_till_done()
assert acc.char_detected.value is False
hass.states.async_set(
entity_id, STATE_HOME, {ATTR_DEVICE_CLASS: DEVICE_CLASS_MOTION}
)
await hass.async_block_till_done()
assert acc.char_detected.value is True
hass.states.async_set(
entity_id, STATE_NOT_HOME, {ATTR_DEVICE_CLASS: DEVICE_CLASS_MOTION}
)
await hass.async_block_till_done()
assert acc.char_detected.value is False
hass.states.async_remove(entity_id)
await hass.async_block_till_done()
assert acc.char_detected.value is False
async def test_binary_device_classes(hass, hk_driver):
"""Test if services and characteristics are assigned correctly."""
entity_id = "binary_sensor.demo"
for device_class, (service, char, _) in BINARY_SENSOR_SERVICE_MAP.items():
hass.states.async_set(entity_id, STATE_OFF, {ATTR_DEVICE_CLASS: device_class})
await hass.async_block_till_done()
acc = BinarySensor(hass, hk_driver, "Binary Sensor", entity_id, 2, None)
assert acc.get_service(service).display_name == service
assert acc.char_detected.display_name == char
async def test_sensor_restore(hass, hk_driver, events):
"""Test setting up an entity from state in the event registry."""
hass.state = CoreState.not_running
registry = er.async_get(hass)
registry.async_get_or_create(
"sensor",
"generic",
"1234",
suggested_object_id="temperature",
device_class="temperature",
)
registry.async_get_or_create(
"sensor",
"generic",
"12345",
suggested_object_id="humidity",
device_class="humidity",
unit_of_measurement=PERCENTAGE,
)
hass.bus.async_fire(EVENT_HOMEASSISTANT_START, {})
await hass.async_block_till_done()
acc = get_accessory(hass, hk_driver, hass.states.get("sensor.temperature"), 2, {})
assert acc.category == 10
acc = get_accessory(hass, hk_driver, hass.states.get("sensor.humidity"), 2, {})
assert acc.category == 10
|
apache-2.0
|
[
624,
774,
3365,
2879,
1089,
2943,
26,
428,
17564,
1041,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
492,
664,
63,
2732,
1089,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
14,
1297,
492,
334,
272,
11643,
63,
6885,
63,
27235,
1075,
12,
272,
3611,
48,
63,
21595,
2684,
1668,
12,
272,
4221,
15098,
5104,
63,
1439,
12,
272,
4221,
15098,
5104,
63,
1439,
18,
12,
199,
9,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
14,
466,
63,
22675,
492,
334,
272,
32698,
63,
24151,
63,
10486,
63,
5443,
12,
272,
22102,
19436,
10160,
12,
272,
14161,
10160,
12,
272,
445,
31585,
1341,
19131,
2655,
10160,
12,
272,
445,
31585,
6671,
19131,
2655,
10160,
12,
272,
869,
21704,
10160,
12,
272,
29684,
10160,
12,
272,
12540,
7899,
10160,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
10555,
63,
6885,
12,
272,
10762,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
272,
6461,
63,
9524,
16435,
840,
1441,
63,
7363,
12,
272,
26684,
2962,
12,
272,
11377,
63,
9524,
12,
272,
11377,
63,
4609,
63,
9524,
12,
272,
11377,
63,
7517,
12,
272,
11377,
63,
615,
12,
272,
11377,
63,
11588,
12,
272,
24314,
63,
21595,
2684,
1668,
12,
272,
24314,
63,
2078,
14784,
742,
1645,
649,
12,
199,
9,
199,
504,
8846,
14,
1018,
492,
11672,
2223,
199,
504,
8846,
14,
7546,
492,
4642,
63,
5189,
465,
9266,
421,
199,
4146,
347,
511,
63,
12954,
8,
5387,
12,
394,
75,
63,
3090,
304,
272,
408,
774,
340,
2879,
1089,
365,
4588,
2410,
1174,
1570,
1041,
272,
4642,
63,
344,
275,
298,
8956,
14,
12954,
2,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
488,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
6907,
275,
12540,
7899,
10160,
8,
5387,
12,
394,
75,
63,
3090,
12,
298,
27409,
401,
4642,
63,
344,
12,
499,
12,
488,
9,
272,
5517,
6907,
14,
1065,
342,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
702,
6907,
14,
21745,
508,
499,
272,
702,
6907,
14,
3710,
508,
1616,
221,
327,
18474,
339,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
378,
14,
16,
272,
367,
790,
12,
574,
315,
3611,
48,
63,
21595,
2684,
1668,
14,
1744,
837,
267,
702,
6907,
14,
1560,
63,
808,
14,
3282,
59,
498,
61,
508,
574,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
267,
4642,
63,
344,
12,
11377,
63,
11588,
12,
469,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
26,
24314,
63,
21595,
2684,
1668,
93,
272,
776,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
378,
14,
16,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
298,
1165,
401,
469,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
26,
24314,
63,
21595,
2684,
1668,
1552,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
3388,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
267,
4642,
63,
344,
12,
298,
2194,
14,
18,
401,
469,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
26,
24314,
63,
2078,
14784,
742,
1645,
649,
93,
272,
776,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
5504,
421,
199,
4146,
347,
511,
63,
31812,
8,
5387,
12,
394,
75,
63,
3090,
304,
272,
408,
774,
340,
2879,
1089,
365,
4588,
2410,
1174,
1570,
1041,
272,
4642,
63,
344,
275,
298,
8956,
14,
31812,
2,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
488,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
6907,
275,
869,
21704,
10160,
8,
5387,
12,
394,
75,
63,
3090,
12,
298,
40,
21704,
401,
4642,
63,
344,
12,
499,
12,
488,
9,
272,
5517,
6907,
14,
1065,
342,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
702,
6907,
14,
21745,
508,
499,
272,
702,
6907,
14,
3710,
508,
1616,
221,
327,
18474,
339,
702,
6907,
14,
1560,
63,
31812,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
11377,
63,
11588,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
31812,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
298,
1165,
531,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
31812,
14,
585,
508,
3388,
421,
199,
4146,
347,
511,
63,
8387,
63,
9161,
8,
5387,
12,
394,
75,
63,
3090,
304,
272,
408,
774,
340,
2879,
1089,
365,
4588,
2410,
1174,
1570,
1041,
272,
4642,
63,
344,
275,
298,
8956,
14,
8387,
63,
9161,
2,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
488,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
6907,
275,
22102,
19436,
10160,
8,
5387,
12,
394,
75,
63,
3090,
12,
298,
28948,
24108,
401,
4642,
63,
344,
12,
499,
12,
488,
9,
272,
5517,
6907,
14,
1065,
342,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
702,
6907,
14,
21745,
508,
499,
272,
702,
6907,
14,
3710,
508,
1616,
221,
327,
18474,
339,
702,
6907,
14,
1560,
63,
15669,
14,
585,
508,
378,
272,
702,
6907,
14,
1560,
63,
9161,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
11377,
63,
11588,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
15669,
14,
585,
508,
378,
272,
702,
6907,
14,
1560,
63,
9161,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
298,
1082,
531,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587
] |
[
774,
3365,
2879,
1089,
2943,
26,
428,
17564,
1041,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
492,
664,
63,
2732,
1089,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
14,
1297,
492,
334,
272,
11643,
63,
6885,
63,
27235,
1075,
12,
272,
3611,
48,
63,
21595,
2684,
1668,
12,
272,
4221,
15098,
5104,
63,
1439,
12,
272,
4221,
15098,
5104,
63,
1439,
18,
12,
199,
9,
199,
504,
8846,
14,
4608,
14,
4219,
6065,
14,
466,
63,
22675,
492,
334,
272,
32698,
63,
24151,
63,
10486,
63,
5443,
12,
272,
22102,
19436,
10160,
12,
272,
14161,
10160,
12,
272,
445,
31585,
1341,
19131,
2655,
10160,
12,
272,
445,
31585,
6671,
19131,
2655,
10160,
12,
272,
869,
21704,
10160,
12,
272,
29684,
10160,
12,
272,
12540,
7899,
10160,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
10555,
63,
6885,
12,
272,
10762,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
272,
6461,
63,
9524,
16435,
840,
1441,
63,
7363,
12,
272,
26684,
2962,
12,
272,
11377,
63,
9524,
12,
272,
11377,
63,
4609,
63,
9524,
12,
272,
11377,
63,
7517,
12,
272,
11377,
63,
615,
12,
272,
11377,
63,
11588,
12,
272,
24314,
63,
21595,
2684,
1668,
12,
272,
24314,
63,
2078,
14784,
742,
1645,
649,
12,
199,
9,
199,
504,
8846,
14,
1018,
492,
11672,
2223,
199,
504,
8846,
14,
7546,
492,
4642,
63,
5189,
465,
9266,
421,
199,
4146,
347,
511,
63,
12954,
8,
5387,
12,
394,
75,
63,
3090,
304,
272,
408,
774,
340,
2879,
1089,
365,
4588,
2410,
1174,
1570,
1041,
272,
4642,
63,
344,
275,
298,
8956,
14,
12954,
2,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
488,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
6907,
275,
12540,
7899,
10160,
8,
5387,
12,
394,
75,
63,
3090,
12,
298,
27409,
401,
4642,
63,
344,
12,
499,
12,
488,
9,
272,
5517,
6907,
14,
1065,
342,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
702,
6907,
14,
21745,
508,
499,
272,
702,
6907,
14,
3710,
508,
1616,
221,
327,
18474,
339,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
378,
14,
16,
272,
367,
790,
12,
574,
315,
3611,
48,
63,
21595,
2684,
1668,
14,
1744,
837,
267,
702,
6907,
14,
1560,
63,
808,
14,
3282,
59,
498,
61,
508,
574,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
267,
4642,
63,
344,
12,
11377,
63,
11588,
12,
469,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
26,
24314,
63,
21595,
2684,
1668,
93,
272,
776,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
378,
14,
16,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
298,
1165,
401,
469,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
26,
24314,
63,
21595,
2684,
1668,
1552,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
3388,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
267,
4642,
63,
344,
12,
298,
2194,
14,
18,
401,
469,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
26,
24314,
63,
2078,
14784,
742,
1645,
649,
93,
272,
776,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
808,
14,
585,
508,
5504,
421,
199,
4146,
347,
511,
63,
31812,
8,
5387,
12,
394,
75,
63,
3090,
304,
272,
408,
774,
340,
2879,
1089,
365,
4588,
2410,
1174,
1570,
1041,
272,
4642,
63,
344,
275,
298,
8956,
14,
31812,
2,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
488,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
6907,
275,
869,
21704,
10160,
8,
5387,
12,
394,
75,
63,
3090,
12,
298,
40,
21704,
401,
4642,
63,
344,
12,
499,
12,
488,
9,
272,
5517,
6907,
14,
1065,
342,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
702,
6907,
14,
21745,
508,
499,
272,
702,
6907,
14,
3710,
508,
1616,
221,
327,
18474,
339,
702,
6907,
14,
1560,
63,
31812,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
11377,
63,
11588,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
31812,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
298,
1165,
531,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
31812,
14,
585,
508,
3388,
421,
199,
4146,
347,
511,
63,
8387,
63,
9161,
8,
5387,
12,
394,
75,
63,
3090,
304,
272,
408,
774,
340,
2879,
1089,
365,
4588,
2410,
1174,
1570,
1041,
272,
4642,
63,
344,
275,
298,
8956,
14,
8387,
63,
9161,
2,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
488,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
6907,
275,
22102,
19436,
10160,
8,
5387,
12,
394,
75,
63,
3090,
12,
298,
28948,
24108,
401,
4642,
63,
344,
12,
499,
12,
488,
9,
272,
5517,
6907,
14,
1065,
342,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
702,
6907,
14,
21745,
508,
499,
272,
702,
6907,
14,
3710,
508,
1616,
221,
327,
18474,
339,
702,
6907,
14,
1560,
63,
15669,
14,
585,
508,
378,
272,
702,
6907,
14,
1560,
63,
9161,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
11377,
63,
11588,
9,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
272,
702,
6907,
14,
1560,
63,
15669,
14,
585,
508,
378,
272,
702,
6907,
14,
1560,
63,
9161,
14,
585,
508,
378,
339,
6298,
14,
4981,
14,
4146,
63,
409,
8,
4502,
63,
344,
12,
298,
1082,
531,
272,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
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,
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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
] |
lmregus/Portfolio
|
python/design_patterns/env/lib/python3.7/site-packages/prompt_toolkit/output/color_depth.py
|
1
|
1497
|
from __future__ import unicode_literals
from prompt_toolkit.utils import is_windows
import os
__all__ = [
'ColorDepth',
]
class ColorDepth(object):
"""
Possible color depth values for the output.
"""
#: One color only.
DEPTH_1_BIT = 'DEPTH_1_BIT'
#: ANSI Colors.
DEPTH_4_BIT = 'DEPTH_4_BIT'
#: The default.
DEPTH_8_BIT = 'DEPTH_8_BIT'
#: 24 bit True color.
DEPTH_24_BIT = 'DEPTH_24_BIT'
# Aliases.
MONOCHROME = DEPTH_1_BIT
ANSI_COLORS_ONLY = DEPTH_4_BIT
DEFAULT = DEPTH_8_BIT
TRUE_COLOR = DEPTH_24_BIT
_ALL = [DEPTH_1_BIT, DEPTH_4_BIT, DEPTH_8_BIT, DEPTH_24_BIT]
@classmethod
def default(cls, term=''):
"""
If the user doesn't specify a color depth, use this as a default.
"""
if term in ('linux', 'eterm-color'):
return cls.DEPTH_4_BIT
# For now, always use 4 bit color on Windows 10 by default, even when
# vt100 escape sequences with ENABLE_VIRTUAL_TERMINAL_PROCESSING are
# supported. We don't have a reliable way yet to know whether our
# console supports true color or only 4-bit.
if is_windows() and 'PROMPT_TOOLKIT_COLOR_DEPTH' not in os.environ:
return cls.DEPTH_4_BIT
# Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable.
if os.environ.get('PROMPT_TOOLKIT_COLOR_DEPTH') in cls._ALL:
return os.environ['PROMPT_TOOLKIT_COLOR_DEPTH']
return cls.DEPTH_8_BIT
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
8457,
63,
31994,
14,
1208,
492,
365,
63,
8258,
199,
646,
747,
199,
199,
363,
452,
363,
275,
359,
272,
283,
4117,
14125,
297,
199,
61,
421,
199,
533,
11581,
14125,
8,
785,
304,
272,
408,
272,
18558,
3164,
5818,
1338,
367,
314,
1072,
14,
272,
408,
272,
6079,
7309,
3164,
1454,
14,
272,
30850,
2080,
63,
17,
63,
11970,
275,
283,
19715,
63,
17,
63,
11970,
7,
339,
6079,
25600,
3626,
1384,
14,
272,
30850,
2080,
63,
20,
63,
11970,
275,
283,
19715,
63,
20,
63,
11970,
7,
339,
6079,
710,
849,
14,
272,
30850,
2080,
63,
24,
63,
11970,
275,
283,
19715,
63,
24,
63,
11970,
7,
339,
6079,
5504,
4546,
715,
3164,
14,
272,
30850,
2080,
63,
1194,
63,
11970,
275,
283,
19715,
63,
1194,
63,
11970,
7,
339,
327,
15170,
3274,
14,
272,
603,
615,
47,
1244,
31364,
275,
30850,
2080,
63,
17,
63,
11970,
272,
25600,
63,
25671,
63,
10452,
275,
30850,
2080,
63,
20,
63,
11970,
272,
6186,
275,
30850,
2080,
63,
24,
63,
11970,
272,
9074,
4187,
63,
7134,
275,
30850,
2080,
63,
1194,
63,
11970,
339,
485,
1761,
275,
359,
19715,
63,
17,
63,
11970,
12,
30850,
2080,
63,
20,
63,
11970,
12,
30850,
2080,
63,
24,
63,
11970,
12,
30850,
2080,
63,
1194,
63,
11970,
61,
339,
768,
3744,
272,
347,
849,
8,
1886,
12,
6707,
9280,
267,
408,
267,
982,
314,
922,
3181,
1133,
4165,
282,
3164,
5818,
12,
675,
642,
465,
282,
849,
14,
267,
408,
267,
340,
6707,
315,
661,
5135,
297,
283,
69,
5125,
13,
2326,
735,
288,
372,
843,
14,
19715,
63,
20,
63,
11970,
398,
327,
2104,
3063,
12,
3544,
675,
841,
4546,
3164,
641,
5417,
1616,
701,
849,
12,
2755,
1380,
267,
327,
18585,
1960,
4772,
8013,
543,
27926,
63,
25618,
63,
28376,
748,
63,
10494,
1206,
787,
267,
327,
3748,
14,
2136,
2793,
1133,
1172,
282,
32150,
4340,
5966,
370,
5715,
3775,
4154,
267,
327,
8559,
5171,
2549,
3164,
503,
1454,
841,
13,
2075,
14,
267,
340,
365,
63,
8258,
342,
436,
283,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
7,
440,
315,
747,
14,
2314,
26,
288,
372,
843,
14,
19715,
63,
20,
63,
11970,
398,
327,
2670,
314,
658,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
64,
3734,
1750,
14,
267,
340,
747,
14,
2314,
14,
362,
360,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
358,
315,
843,
423,
1761,
26,
288,
372,
747,
14,
2314,
459,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
418,
398,
372,
843,
14,
19715,
63,
24,
63,
11970,
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
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
8457,
63,
31994,
14,
1208,
492,
365,
63,
8258,
199,
646,
747,
199,
199,
363,
452,
363,
275,
359,
272,
283,
4117,
14125,
297,
199,
61,
421,
199,
533,
11581,
14125,
8,
785,
304,
272,
408,
272,
18558,
3164,
5818,
1338,
367,
314,
1072,
14,
272,
408,
272,
6079,
7309,
3164,
1454,
14,
272,
30850,
2080,
63,
17,
63,
11970,
275,
283,
19715,
63,
17,
63,
11970,
7,
339,
6079,
25600,
3626,
1384,
14,
272,
30850,
2080,
63,
20,
63,
11970,
275,
283,
19715,
63,
20,
63,
11970,
7,
339,
6079,
710,
849,
14,
272,
30850,
2080,
63,
24,
63,
11970,
275,
283,
19715,
63,
24,
63,
11970,
7,
339,
6079,
5504,
4546,
715,
3164,
14,
272,
30850,
2080,
63,
1194,
63,
11970,
275,
283,
19715,
63,
1194,
63,
11970,
7,
339,
327,
15170,
3274,
14,
272,
603,
615,
47,
1244,
31364,
275,
30850,
2080,
63,
17,
63,
11970,
272,
25600,
63,
25671,
63,
10452,
275,
30850,
2080,
63,
20,
63,
11970,
272,
6186,
275,
30850,
2080,
63,
24,
63,
11970,
272,
9074,
4187,
63,
7134,
275,
30850,
2080,
63,
1194,
63,
11970,
339,
485,
1761,
275,
359,
19715,
63,
17,
63,
11970,
12,
30850,
2080,
63,
20,
63,
11970,
12,
30850,
2080,
63,
24,
63,
11970,
12,
30850,
2080,
63,
1194,
63,
11970,
61,
339,
768,
3744,
272,
347,
849,
8,
1886,
12,
6707,
9280,
267,
408,
267,
982,
314,
922,
3181,
1133,
4165,
282,
3164,
5818,
12,
675,
642,
465,
282,
849,
14,
267,
408,
267,
340,
6707,
315,
661,
5135,
297,
283,
69,
5125,
13,
2326,
735,
288,
372,
843,
14,
19715,
63,
20,
63,
11970,
398,
327,
2104,
3063,
12,
3544,
675,
841,
4546,
3164,
641,
5417,
1616,
701,
849,
12,
2755,
1380,
267,
327,
18585,
1960,
4772,
8013,
543,
27926,
63,
25618,
63,
28376,
748,
63,
10494,
1206,
787,
267,
327,
3748,
14,
2136,
2793,
1133,
1172,
282,
32150,
4340,
5966,
370,
5715,
3775,
4154,
267,
327,
8559,
5171,
2549,
3164,
503,
1454,
841,
13,
2075,
14,
267,
340,
365,
63,
8258,
342,
436,
283,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
7,
440,
315,
747,
14,
2314,
26,
288,
372,
843,
14,
19715,
63,
20,
63,
11970,
398,
327,
2670,
314,
658,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
64,
3734,
1750,
14,
267,
340,
747,
14,
2314,
14,
362,
360,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
358,
315,
843,
423,
1761,
26,
288,
372,
747,
14,
2314,
459,
2514,
26178,
63,
9731,
43,
649,
63,
7134,
63,
19715,
418,
398,
372,
843,
14,
19715,
63,
24,
63,
11970,
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,
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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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
] |
yqm/sl4a
|
python/src/Lib/encodings/euc_jisx0213.py
|
816
|
1051
|
#
# euc_jisx0213.py: Python Unicode Codec for EUC_JISX0213
#
# Written by Hye-Shik Chang <perky@FreeBSD.org>
#
import _codecs_jp, codecs
import _multibytecodec as mbc
codec = _codecs_jp.getcodec('euc_jisx0213')
class Codec(codecs.Codec):
encode = codec.encode
decode = codec.decode
class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
codecs.IncrementalEncoder):
codec = codec
class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
codecs.IncrementalDecoder):
codec = codec
class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
codec = codec
class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
codec = codec
def getregentry():
return codecs.CodecInfo(
name='euc_jisx0213',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
apache-2.0
|
[
3,
199,
3,
325,
947,
63,
18941,
88,
996,
969,
14,
647,
26,
2018,
6140,
13732,
367,
662,
13371,
63,
22290,
56,
996,
969,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
11538,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
11538,
14,
362,
9276,
360,
15149,
63,
18941,
88,
996,
969,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
15149,
63,
18941,
88,
996,
969,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
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,
32768,
32768,
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,
325,
947,
63,
18941,
88,
996,
969,
14,
647,
26,
2018,
6140,
13732,
367,
662,
13371,
63,
22290,
56,
996,
969,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
11538,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
11538,
14,
362,
9276,
360,
15149,
63,
18941,
88,
996,
969,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
15149,
63,
18941,
88,
996,
969,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
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,
32768,
32768,
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,
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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
] |
takis/odoo
|
openerp/addons/test_inherit/models.py
|
69
|
2503
|
# -*- coding: utf-8 -*-
from openerp import models, fields, api, osv
# We just create a new model
class mother(models.Model):
_name = 'test.inherit.mother'
_columns = {
# check interoperability of field inheritance with old-style fields
'name': osv.fields.char('Name'),
'state': osv.fields.selection([('a', 'A'), ('b', 'B')], string='State'),
}
_defaults = {
'name': 'Foo',
}
surname = fields.Char(compute='_compute_surname')
@api.one
@api.depends('name')
def _compute_surname(self):
self.surname = self.name or ''
# We want to inherits from the parent model and we add some fields
# in the child object
class daughter(models.Model):
_name = 'test.inherit.daughter'
template_id = fields.Many2one('test.inherit.mother', 'Template',
delegate=True, required=True, ondelete='cascade')
field_in_daughter = fields.Char('Field1')
# We add a new field in the parent object. Because of a recent refactoring,
# this feature was broken.
# This test and these models try to show the bug and fix it.
class mother(models.Model):
_inherit = 'test.inherit.mother'
field_in_mother = fields.Char()
partner_id = fields.Many2one('res.partner')
# extend the name field: make it required and change its default value
name = fields.Char(required=True, default='Bar')
# extend the selection of the state field
state = fields.Selection(selection_add=[('c', 'C')])
# override the computed field, and extend its dependencies
@api.one
@api.depends('field_in_mother')
def _compute_surname(self):
if self.field_in_mother:
self.surname = self.field_in_mother
else:
super(mother, self)._compute_surname()
class mother(models.Model):
_inherit = 'test.inherit.mother'
# extend again the selection of the state field
state = fields.Selection(selection_add=[('d', 'D')])
class daughter(models.Model):
_inherit = 'test.inherit.daughter'
# simply redeclare the field without adding any option
template_id = fields.Many2one()
# change the default value of an inherited field
name = fields.Char(default='Baz')
class res_partner(models.Model):
_inherit = 'res.partner'
# define a one2many field based on the inherited field partner_id
daughter_ids = fields.One2many('test.inherit.daughter', 'partner_id')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
9506,
199,
199,
3,
2136,
2951,
1218,
282,
892,
1402,
199,
533,
1303,
728,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
6486,
14,
573,
728,
7,
339,
485,
3406,
275,
469,
267,
327,
1104,
4661,
9198,
3616,
402,
901,
15433,
543,
2269,
13,
2487,
1504,
267,
283,
354,
356,
9506,
14,
955,
14,
1560,
360,
985,
659,
267,
283,
929,
356,
9506,
14,
955,
14,
5592,
8318,
65,
297,
283,
33,
659,
661,
66,
297,
283,
34,
2665,
1059,
534,
2223,
659,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
354,
356,
283,
5686,
297,
272,
789,
339,
308,
21121,
275,
1504,
14,
1610,
8,
3357,
17574,
3357,
63,
30959,
358,
339,
768,
1246,
14,
368,
272,
768,
1246,
14,
8912,
360,
354,
358,
272,
347,
485,
3357,
63,
30959,
8,
277,
304,
267,
291,
14,
30959,
275,
291,
14,
354,
503,
2125,
199,
199,
3,
2136,
2934,
370,
21592,
687,
314,
1676,
1402,
436,
781,
1050,
2005,
1504,
199,
3,
315,
314,
1982,
909,
199,
533,
12927,
3080,
351,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
6486,
14,
983,
3080,
351,
7,
339,
1978,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
396,
14,
6486,
14,
573,
728,
297,
283,
4231,
297,
3303,
13080,
29,
549,
12,
1415,
29,
549,
12,
16549,
534,
15377,
358,
272,
901,
63,
262,
63,
983,
3080,
351,
275,
1504,
14,
1610,
360,
792,
17,
358,
421,
199,
3,
2136,
1050,
282,
892,
901,
315,
314,
1676,
909,
14,
13821,
402,
282,
8058,
24200,
316,
12,
199,
3,
642,
3878,
1990,
10529,
14,
199,
3,
961,
511,
436,
3520,
1709,
862,
370,
2498,
314,
6519,
436,
5325,
652,
14,
199,
533,
1303,
728,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
396,
14,
6486,
14,
573,
728,
7,
339,
901,
63,
262,
63,
573,
728,
275,
1504,
14,
1610,
342,
272,
5854,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3899,
358,
339,
327,
12247,
314,
536,
901,
26,
1852,
652,
1415,
436,
1570,
2399,
849,
574,
272,
536,
275,
1504,
14,
1610,
8,
2427,
29,
549,
12,
849,
534,
5281,
358,
339,
327,
12247,
314,
7267,
402,
314,
1174,
901,
272,
1174,
275,
1504,
14,
7713,
8,
5592,
63,
525,
11699,
67,
297,
283,
35,
2023,
339,
327,
4278,
314,
9235,
901,
12,
436,
12247,
2399,
5124,
272,
768,
1246,
14,
368,
272,
768,
1246,
14,
8912,
360,
698,
63,
262,
63,
573,
728,
358,
272,
347,
485,
3357,
63,
30959,
8,
277,
304,
267,
340,
291,
14,
698,
63,
262,
63,
573,
728,
26,
288,
291,
14,
30959,
275,
291,
14,
698,
63,
262,
63,
573,
728,
267,
587,
26,
288,
1613,
8,
573,
728,
12,
291,
10445,
3357,
63,
30959,
342,
421,
199,
533,
1303,
728,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
396,
14,
6486,
14,
573,
728,
7,
339,
327,
12247,
4020,
314,
7267,
402,
314,
1174,
901,
272,
1174,
275,
1504,
14,
7713,
8,
5592,
63,
525,
11699,
68,
297,
283,
36,
2023,
421,
199,
533,
12927,
3080,
351,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
396,
14,
6486,
14,
983,
3080,
351,
7,
339,
327,
9329,
295,
16536,
314,
901,
1928,
7791,
1263,
945,
272,
1978,
63,
344,
275,
1504,
14,
4089,
18,
368,
342,
339,
327,
1570,
314,
849,
574,
402,
376,
12623,
901,
272,
536,
275,
1504,
14,
1610,
8,
885,
534,
19726,
358,
421,
199,
533,
522,
63,
3899,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
470,
14,
3899,
7,
339,
327,
5627,
282,
1373,
18,
3479,
901,
4079,
641,
314,
12623,
901,
5854,
63,
344,
272,
12927,
3080,
351,
63,
1580,
275,
1504,
14,
4395,
18,
3479,
360,
396,
14,
6486,
14,
983,
3080,
351,
297,
283,
3899,
63,
344,
358,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
9506,
199,
199,
3,
2136,
2951,
1218,
282,
892,
1402,
199,
533,
1303,
728,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
6486,
14,
573,
728,
7,
339,
485,
3406,
275,
469,
267,
327,
1104,
4661,
9198,
3616,
402,
901,
15433,
543,
2269,
13,
2487,
1504,
267,
283,
354,
356,
9506,
14,
955,
14,
1560,
360,
985,
659,
267,
283,
929,
356,
9506,
14,
955,
14,
5592,
8318,
65,
297,
283,
33,
659,
661,
66,
297,
283,
34,
2665,
1059,
534,
2223,
659,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
354,
356,
283,
5686,
297,
272,
789,
339,
308,
21121,
275,
1504,
14,
1610,
8,
3357,
17574,
3357,
63,
30959,
358,
339,
768,
1246,
14,
368,
272,
768,
1246,
14,
8912,
360,
354,
358,
272,
347,
485,
3357,
63,
30959,
8,
277,
304,
267,
291,
14,
30959,
275,
291,
14,
354,
503,
2125,
199,
199,
3,
2136,
2934,
370,
21592,
687,
314,
1676,
1402,
436,
781,
1050,
2005,
1504,
199,
3,
315,
314,
1982,
909,
199,
533,
12927,
3080,
351,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
6486,
14,
983,
3080,
351,
7,
339,
1978,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
396,
14,
6486,
14,
573,
728,
297,
283,
4231,
297,
3303,
13080,
29,
549,
12,
1415,
29,
549,
12,
16549,
534,
15377,
358,
272,
901,
63,
262,
63,
983,
3080,
351,
275,
1504,
14,
1610,
360,
792,
17,
358,
421,
199,
3,
2136,
1050,
282,
892,
901,
315,
314,
1676,
909,
14,
13821,
402,
282,
8058,
24200,
316,
12,
199,
3,
642,
3878,
1990,
10529,
14,
199,
3,
961,
511,
436,
3520,
1709,
862,
370,
2498,
314,
6519,
436,
5325,
652,
14,
199,
533,
1303,
728,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
396,
14,
6486,
14,
573,
728,
7,
339,
901,
63,
262,
63,
573,
728,
275,
1504,
14,
1610,
342,
272,
5854,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3899,
358,
339,
327,
12247,
314,
536,
901,
26,
1852,
652,
1415,
436,
1570,
2399,
849,
574,
272,
536,
275,
1504,
14,
1610,
8,
2427,
29,
549,
12,
849,
534,
5281,
358,
339,
327,
12247,
314,
7267,
402,
314,
1174,
901,
272,
1174,
275,
1504,
14,
7713,
8,
5592,
63,
525,
11699,
67,
297,
283,
35,
2023,
339,
327,
4278,
314,
9235,
901,
12,
436,
12247,
2399,
5124,
272,
768,
1246,
14,
368,
272,
768,
1246,
14,
8912,
360,
698,
63,
262,
63,
573,
728,
358,
272,
347,
485,
3357,
63,
30959,
8,
277,
304,
267,
340,
291,
14,
698,
63,
262,
63,
573,
728,
26,
288,
291,
14,
30959,
275,
291,
14,
698,
63,
262,
63,
573,
728,
267,
587,
26,
288,
1613,
8,
573,
728,
12,
291,
10445,
3357,
63,
30959,
342,
421,
199,
533,
1303,
728,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
396,
14,
6486,
14,
573,
728,
7,
339,
327,
12247,
4020,
314,
7267,
402,
314,
1174,
901,
272,
1174,
275,
1504,
14,
7713,
8,
5592,
63,
525,
11699,
68,
297,
283,
36,
2023,
421,
199,
533,
12927,
3080,
351,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
396,
14,
6486,
14,
983,
3080,
351,
7,
339,
327,
9329,
295,
16536,
314,
901,
1928,
7791,
1263,
945,
272,
1978,
63,
344,
275,
1504,
14,
4089,
18,
368,
342,
339,
327,
1570,
314,
849,
574,
402,
376,
12623,
901,
272,
536,
275,
1504,
14,
1610,
8,
885,
534,
19726,
358,
421,
199,
533,
522,
63,
3899,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
470,
14,
3899,
7,
339,
327,
5627,
282,
1373,
18,
3479,
901,
4079,
641,
314,
12623,
901,
5854,
63,
344,
272,
12927,
3080,
351,
63,
1580,
275,
1504,
14,
4395,
18,
3479,
360,
396,
14,
6486,
14,
983,
3080,
351,
297,
283,
3899,
63,
344,
358,
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,
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,
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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
] |
dominicelse/scipy
|
scipy/io/tests/test_fortran.py
|
14
|
2593
|
''' Tests for fortran sequential files '''
import tempfile
import shutil
from os import path
from glob import iglob
import re
from numpy.testing import assert_equal, assert_allclose, run_module_suite
import numpy as np
from scipy.io import FortranFile
DATA_PATH = path.join(path.dirname(__file__), 'data')
def test_fortranfiles_read():
for filename in iglob(path.join(DATA_PATH, "fortran-*-*x*x*.dat")):
m = re.search(r'fortran-([^-]+)-(\d+)x(\d+)x(\d+).dat', filename, re.I)
if not m:
raise RuntimeError("Couldn't match %s filename to regex" % filename)
dims = (int(m.group(2)), int(m.group(3)), int(m.group(4)))
f = FortranFile(filename, 'r', '<u4')
data = f.read_record(dtype=m.group(1).replace('s', '<')).reshape(dims)
f.close()
counter = 0
for k in range(dims[2]):
for j in range(dims[1]):
for i in range(dims[0]):
assert_equal(counter, data[i,j,k])
counter += 1
def test_fortranfiles_mixed_record():
filename = path.join(DATA_PATH, "fortran-mixed.dat")
with FortranFile(filename, 'r', '<u4') as f:
record = f.read_record('<i4,<f4,<i8,(2)<f8')
assert_equal(record['f0'][0], 1)
assert_allclose(record['f1'][0], 2.3)
assert_equal(record['f2'][0], 4)
assert_allclose(record['f3'][0], [5.6, 7.8])
def test_fortranfiles_write():
for filename in iglob(path.join(DATA_PATH, "fortran-*-*x*x*.dat")):
m = re.search(r'fortran-([^-]+)-(\d+)x(\d+)x(\d+).dat', filename, re.I)
if not m:
raise RuntimeError("Couldn't match %s filename to regex" % filename)
dims = (int(m.group(2)), int(m.group(3)), int(m.group(4)))
counter = 0
data = np.zeros(dims, dtype=m.group(1).replace('s', '<'))
for k in range(dims[2]):
for j in range(dims[1]):
for i in range(dims[0]):
data[i,j,k] = counter
counter += 1
tmpdir = tempfile.mkdtemp()
try:
testFile = path.join(tmpdir,path.basename(filename))
f = FortranFile(testFile, 'w','<u4')
f.write_record(data)
f.close()
originalfile = open(filename, 'rb')
newfile = open(testFile, 'rb')
assert_equal(originalfile.read(), newfile.read(),
err_msg=filename)
originalfile.close()
newfile.close()
finally:
shutil.rmtree(tmpdir)
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
2344,
6496,
367,
289,
14522,
23381,
1584,
1449,
199,
199,
646,
5549,
199,
646,
5145,
199,
504,
747,
492,
931,
199,
504,
5739,
492,
284,
6463,
199,
646,
295,
199,
199,
504,
2680,
14,
4776,
492,
702,
63,
1452,
12,
702,
63,
7520,
12,
1255,
63,
578,
63,
5768,
199,
646,
2680,
465,
980,
199,
199,
504,
7026,
14,
2308,
492,
19998,
1173,
421,
199,
3998,
63,
3243,
275,
931,
14,
904,
8,
515,
14,
3475,
3460,
493,
10139,
283,
576,
358,
421,
199,
318,
511,
63,
18496,
1725,
63,
739,
837,
272,
367,
1788,
315,
284,
6463,
8,
515,
14,
904,
8,
3998,
63,
3243,
12,
298,
18496,
13,
1837,
10,
88,
10,
88,
4856,
4616,
14150,
267,
333,
275,
295,
14,
1733,
8,
82,
7,
18496,
13,
7059,
20253,
7216,
2961,
68,
8771,
88,
2961,
68,
8771,
88,
2961,
68,
11,
680,
4616,
297,
1788,
12,
295,
14,
41,
9,
267,
340,
440,
333,
26,
288,
746,
6064,
480,
20485,
1133,
1336,
450,
83,
1788,
370,
5163,
2,
450,
1788,
9,
398,
17476,
275,
334,
442,
8,
77,
14,
923,
8,
18,
1826,
1109,
8,
77,
14,
923,
8,
19,
1826,
1109,
8,
77,
14,
923,
8,
20,
1724,
398,
289,
275,
19998,
1173,
8,
1501,
12,
283,
82,
297,
2650,
85,
20,
358,
267,
666,
275,
289,
14,
739,
63,
3059,
8,
2271,
29,
77,
14,
923,
8,
17,
680,
1814,
360,
83,
297,
2650,
11103,
5217,
8,
5380,
9,
267,
289,
14,
1600,
342,
398,
7055,
275,
378,
267,
367,
1022,
315,
1425,
8,
5380,
59,
18,
4682,
288,
367,
1335,
315,
1425,
8,
5380,
59,
17,
4682,
355,
367,
284,
315,
1425,
8,
5380,
59,
16,
4682,
490,
702,
63,
1452,
8,
5337,
12,
666,
59,
73,
12,
74,
12,
75,
566,
490,
7055,
847,
413,
421,
199,
318,
511,
63,
18496,
1725,
63,
10455,
63,
3059,
837,
272,
1788,
275,
931,
14,
904,
8,
3998,
63,
3243,
12,
298,
18496,
13,
10455,
14,
4616,
531,
272,
543,
19998,
1173,
8,
1501,
12,
283,
82,
297,
2650,
85,
20,
358,
465,
289,
26,
267,
2777,
275,
289,
14,
739,
63,
3059,
4827,
73,
20,
30027,
70,
20,
30027,
73,
24,
12803,
18,
21528,
70,
24,
358,
339,
702,
63,
1452,
8,
3059,
459,
70,
16,
3488,
16,
467,
413,
9,
272,
702,
63,
7520,
8,
3059,
459,
70,
17,
3488,
16,
467,
499,
14,
19,
9,
272,
702,
63,
1452,
8,
3059,
459,
70,
18,
3488,
16,
467,
841,
9,
272,
702,
63,
7520,
8,
3059,
459,
70,
19,
3488,
16,
467,
359,
21,
14,
22,
12,
1520,
14,
24,
566,
421,
199,
318,
511,
63,
18496,
1725,
63,
952,
837,
272,
367,
1788,
315,
284,
6463,
8,
515,
14,
904,
8,
3998,
63,
3243,
12,
298,
18496,
13,
1837,
10,
88,
10,
88,
4856,
4616,
14150,
267,
333,
275,
295,
14,
1733,
8,
82,
7,
18496,
13,
7059,
20253,
7216,
2961,
68,
8771,
88,
2961,
68,
8771,
88,
2961,
68,
11,
680,
4616,
297,
1788,
12,
295,
14,
41,
9,
267,
340,
440,
333,
26,
288,
746,
6064,
480,
20485,
1133,
1336,
450,
83,
1788,
370,
5163,
2,
450,
1788,
9,
267,
17476,
275,
334,
442,
8,
77,
14,
923,
8,
18,
1826,
1109,
8,
77,
14,
923,
8,
19,
1826,
1109,
8,
77,
14,
923,
8,
20,
1724,
398,
7055,
275,
378,
267,
666,
275,
980,
14,
4250,
8,
5380,
12,
2152,
29,
77,
14,
923,
8,
17,
680,
1814,
360,
83,
297,
2650,
1333,
267,
367,
1022,
315,
1425,
8,
5380,
59,
18,
4682,
288,
367,
1335,
315,
1425,
8,
5380,
59,
17,
4682,
355,
367,
284,
315,
1425,
8,
5380,
59,
16,
4682,
490,
666,
59,
73,
12,
74,
12,
75,
61,
275,
7055,
490,
7055,
847,
413,
267,
12885,
275,
5549,
14,
11983,
342,
267,
862,
26,
288,
511,
1173,
275,
931,
14,
904,
8,
8616,
12,
515,
14,
4846,
8,
1501,
430,
288,
289,
275,
19998,
1173,
8,
396,
1173,
12,
283,
87,
1673,
28,
85,
20,
358,
288,
289,
14,
952,
63,
3059,
8,
576,
9,
288,
289,
14,
1600,
342,
288,
6330,
7411,
441,
275,
1551,
8,
1501,
12,
283,
4848,
358,
288,
892,
493,
275,
1551,
8,
396,
1173,
12,
283,
4848,
358,
288,
702,
63,
1452,
8,
6493,
7411,
441,
14,
739,
1062,
892,
493,
14,
739,
1062,
586,
2329,
63,
1328,
29,
1501,
9,
288,
6330,
7411,
441,
14,
1600,
342,
288,
892,
493,
14,
1600,
342,
267,
3753,
26,
288,
5145,
14,
9242,
8,
8616,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
578,
63,
5768,
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
] |
[
6496,
367,
289,
14522,
23381,
1584,
1449,
199,
199,
646,
5549,
199,
646,
5145,
199,
504,
747,
492,
931,
199,
504,
5739,
492,
284,
6463,
199,
646,
295,
199,
199,
504,
2680,
14,
4776,
492,
702,
63,
1452,
12,
702,
63,
7520,
12,
1255,
63,
578,
63,
5768,
199,
646,
2680,
465,
980,
199,
199,
504,
7026,
14,
2308,
492,
19998,
1173,
421,
199,
3998,
63,
3243,
275,
931,
14,
904,
8,
515,
14,
3475,
3460,
493,
10139,
283,
576,
358,
421,
199,
318,
511,
63,
18496,
1725,
63,
739,
837,
272,
367,
1788,
315,
284,
6463,
8,
515,
14,
904,
8,
3998,
63,
3243,
12,
298,
18496,
13,
1837,
10,
88,
10,
88,
4856,
4616,
14150,
267,
333,
275,
295,
14,
1733,
8,
82,
7,
18496,
13,
7059,
20253,
7216,
2961,
68,
8771,
88,
2961,
68,
8771,
88,
2961,
68,
11,
680,
4616,
297,
1788,
12,
295,
14,
41,
9,
267,
340,
440,
333,
26,
288,
746,
6064,
480,
20485,
1133,
1336,
450,
83,
1788,
370,
5163,
2,
450,
1788,
9,
398,
17476,
275,
334,
442,
8,
77,
14,
923,
8,
18,
1826,
1109,
8,
77,
14,
923,
8,
19,
1826,
1109,
8,
77,
14,
923,
8,
20,
1724,
398,
289,
275,
19998,
1173,
8,
1501,
12,
283,
82,
297,
2650,
85,
20,
358,
267,
666,
275,
289,
14,
739,
63,
3059,
8,
2271,
29,
77,
14,
923,
8,
17,
680,
1814,
360,
83,
297,
2650,
11103,
5217,
8,
5380,
9,
267,
289,
14,
1600,
342,
398,
7055,
275,
378,
267,
367,
1022,
315,
1425,
8,
5380,
59,
18,
4682,
288,
367,
1335,
315,
1425,
8,
5380,
59,
17,
4682,
355,
367,
284,
315,
1425,
8,
5380,
59,
16,
4682,
490,
702,
63,
1452,
8,
5337,
12,
666,
59,
73,
12,
74,
12,
75,
566,
490,
7055,
847,
413,
421,
199,
318,
511,
63,
18496,
1725,
63,
10455,
63,
3059,
837,
272,
1788,
275,
931,
14,
904,
8,
3998,
63,
3243,
12,
298,
18496,
13,
10455,
14,
4616,
531,
272,
543,
19998,
1173,
8,
1501,
12,
283,
82,
297,
2650,
85,
20,
358,
465,
289,
26,
267,
2777,
275,
289,
14,
739,
63,
3059,
4827,
73,
20,
30027,
70,
20,
30027,
73,
24,
12803,
18,
21528,
70,
24,
358,
339,
702,
63,
1452,
8,
3059,
459,
70,
16,
3488,
16,
467,
413,
9,
272,
702,
63,
7520,
8,
3059,
459,
70,
17,
3488,
16,
467,
499,
14,
19,
9,
272,
702,
63,
1452,
8,
3059,
459,
70,
18,
3488,
16,
467,
841,
9,
272,
702,
63,
7520,
8,
3059,
459,
70,
19,
3488,
16,
467,
359,
21,
14,
22,
12,
1520,
14,
24,
566,
421,
199,
318,
511,
63,
18496,
1725,
63,
952,
837,
272,
367,
1788,
315,
284,
6463,
8,
515,
14,
904,
8,
3998,
63,
3243,
12,
298,
18496,
13,
1837,
10,
88,
10,
88,
4856,
4616,
14150,
267,
333,
275,
295,
14,
1733,
8,
82,
7,
18496,
13,
7059,
20253,
7216,
2961,
68,
8771,
88,
2961,
68,
8771,
88,
2961,
68,
11,
680,
4616,
297,
1788,
12,
295,
14,
41,
9,
267,
340,
440,
333,
26,
288,
746,
6064,
480,
20485,
1133,
1336,
450,
83,
1788,
370,
5163,
2,
450,
1788,
9,
267,
17476,
275,
334,
442,
8,
77,
14,
923,
8,
18,
1826,
1109,
8,
77,
14,
923,
8,
19,
1826,
1109,
8,
77,
14,
923,
8,
20,
1724,
398,
7055,
275,
378,
267,
666,
275,
980,
14,
4250,
8,
5380,
12,
2152,
29,
77,
14,
923,
8,
17,
680,
1814,
360,
83,
297,
2650,
1333,
267,
367,
1022,
315,
1425,
8,
5380,
59,
18,
4682,
288,
367,
1335,
315,
1425,
8,
5380,
59,
17,
4682,
355,
367,
284,
315,
1425,
8,
5380,
59,
16,
4682,
490,
666,
59,
73,
12,
74,
12,
75,
61,
275,
7055,
490,
7055,
847,
413,
267,
12885,
275,
5549,
14,
11983,
342,
267,
862,
26,
288,
511,
1173,
275,
931,
14,
904,
8,
8616,
12,
515,
14,
4846,
8,
1501,
430,
288,
289,
275,
19998,
1173,
8,
396,
1173,
12,
283,
87,
1673,
28,
85,
20,
358,
288,
289,
14,
952,
63,
3059,
8,
576,
9,
288,
289,
14,
1600,
342,
288,
6330,
7411,
441,
275,
1551,
8,
1501,
12,
283,
4848,
358,
288,
892,
493,
275,
1551,
8,
396,
1173,
12,
283,
4848,
358,
288,
702,
63,
1452,
8,
6493,
7411,
441,
14,
739,
1062,
892,
493,
14,
739,
1062,
586,
2329,
63,
1328,
29,
1501,
9,
288,
6330,
7411,
441,
14,
1600,
342,
288,
892,
493,
14,
1600,
342,
267,
3753,
26,
288,
5145,
14,
9242,
8,
8616,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
578,
63,
5768,
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,
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,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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
] |
javachengwc/hue
|
desktop/core/ext-py/tablib-0.10.0/tablib/packages/odf/teletype.py
|
101
|
5187
|
# -*- coding: utf-8 -*-
#
# Create and extract text from ODF, handling whitespace correctly.
# Copyright (C) 2008 J. David Eisenberg
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
Class for handling whitespace properly in OpenDocument.
While it is possible to use getTextContent() and setTextContent()
to extract or create ODF content, these won't extract or create
the appropriate <text:s>, <text:tab>, or <text:line-break>
elements. This module takes care of that problem.
"""
from odf.element import Node
import odf.opendocument
from odf.text import S,LineBreak,Tab
class WhitespaceText(object):
def __init__(self):
self.textBuffer = []
self.spaceCount = 0
def addTextToElement(self, odfElement, s):
""" Process an input string, inserting
<text:tab> elements for '\t',
<text:line-break> elements for '\n', and
<text:s> elements for runs of more than one blank.
These will be added to the given element.
"""
i = 0
ch = ' '
# When we encounter a tab or newline, we can immediately
# dump any accumulated text and then emit the appropriate
# ODF element.
#
# When we encounter a space, we add it to the text buffer,
# and then collect more spaces. If there are more spaces
# after the first one, we dump the text buffer and then
# then emit the appropriate <text:s> element.
while i < len(s):
ch = s[i]
if ch == '\t':
self._emitTextBuffer(odfElement)
odfElement.addElement(Tab())
i += 1
elif ch == '\n':
self._emitTextBuffer(odfElement);
odfElement.addElement(LineBreak())
i += 1
elif ch == ' ':
self.textBuffer.append(' ')
i += 1
self.spaceCount = 0
while i < len(s) and (s[i] == ' '):
self.spaceCount += 1
i += 1
if self.spaceCount > 0:
self._emitTextBuffer(odfElement)
self._emitSpaces(odfElement)
else:
self.textBuffer.append(ch)
i += 1
self._emitTextBuffer(odfElement)
def _emitTextBuffer(self, odfElement):
""" Creates a Text Node whose contents are the current textBuffer.
Side effect: clears the text buffer.
"""
if len(self.textBuffer) > 0:
odfElement.addText(''.join(self.textBuffer))
self.textBuffer = []
def _emitSpaces(self, odfElement):
""" Creates a <text:s> element for the current spaceCount.
Side effect: sets spaceCount back to zero
"""
if self.spaceCount > 0:
spaceElement = S(c=self.spaceCount)
odfElement.addElement(spaceElement)
self.spaceCount = 0
def addTextToElement(odfElement, s):
wst = WhitespaceText()
wst.addTextToElement(odfElement, s)
def extractText(odfElement):
""" Extract text content from an Element, with whitespace represented
properly. Returns the text, with tabs, spaces, and newlines
correctly evaluated. This method recursively descends through the
children of the given element, accumulating text and "unwrapping"
<text:s>, <text:tab>, and <text:line-break> elements along the way.
"""
result = [];
if len(odfElement.childNodes) != 0:
for child in odfElement.childNodes:
if child.nodeType == Node.TEXT_NODE:
result.append(child.data)
elif child.nodeType == Node.ELEMENT_NODE:
subElement = child
tagName = subElement.qname;
if tagName == (u"urn:oasis:names:tc:opendocument:xmlns:text:1.0", u"line-break"):
result.append("\n")
elif tagName == (u"urn:oasis:names:tc:opendocument:xmlns:text:1.0", u"tab"):
result.append("\t")
elif tagName == (u"urn:oasis:names:tc:opendocument:xmlns:text:1.0", u"s"):
c = subElement.getAttribute('c')
if c:
spaceCount = int(c)
else:
spaceCount = 1
result.append(" " * spaceCount)
else:
result.append(extractText(subElement))
return ''.join(result)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
257,
2790,
436,
5536,
1318,
687,
593,
3888,
12,
7252,
8139,
6657,
14,
199,
3,
257,
1898,
334,
35,
9,
9079,
1603,
14,
20232,
662,
572,
78,
14630,
199,
3,
199,
3,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
199,
3,
257,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
257,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
421,
199,
624,
199,
2543,
367,
7252,
8139,
7684,
315,
3232,
5564,
14,
199,
199,
25215,
652,
365,
3962,
370,
675,
664,
1872,
2714,
342,
436,
663,
1872,
2714,
342,
199,
475,
5536,
503,
1218,
593,
3888,
1564,
12,
3520,
7859,
1133,
5536,
503,
1218,
199,
1589,
5827,
665,
505,
26,
83,
6244,
665,
505,
26,
2902,
6244,
503,
665,
505,
26,
604,
13,
4785,
30,
199,
5527,
14,
221,
961,
859,
6181,
10296,
402,
626,
5160,
14,
199,
624,
199,
199,
504,
312,
1587,
14,
2108,
492,
5013,
199,
646,
312,
1587,
14,
411,
500,
679,
760,
199,
504,
312,
1587,
14,
505,
492,
428,
12,
3049,
13948,
12,
7690,
199,
199,
533,
24403,
1872,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
505,
3299,
275,
942,
267,
291,
14,
2638,
2353,
275,
378,
339,
347,
1050,
1872,
1378,
2162,
8,
277,
12,
312,
1587,
2162,
12,
308,
304,
267,
408,
7132,
376,
1324,
1059,
12,
28498,
288,
665,
505,
26,
2902,
30,
4008,
367,
1557,
84,
297,
288,
665,
505,
26,
604,
13,
4785,
30,
4008,
367,
1557,
78,
297,
436,
288,
665,
505,
26,
83,
30,
4008,
367,
7858,
402,
1655,
2419,
1373,
4596,
14,
288,
5723,
911,
506,
3483,
370,
314,
1627,
1819,
14,
267,
408,
267,
284,
275,
378,
267,
682,
275,
283,
283,
398,
327,
3979,
781,
655,
5337,
282,
5174,
503,
8057,
12,
781,
883,
9939,
267,
327,
5461,
1263,
29845,
1318,
436,
2066,
8689,
314,
5827,
267,
327,
593,
3888,
1819,
14,
267,
327,
267,
327,
3979,
781,
655,
5337,
282,
4601,
12,
781,
1050,
652,
370,
314,
1318,
3335,
12,
267,
327,
436,
2066,
8775,
1655,
7883,
14,
221,
982,
2337,
787,
1655,
7883,
267,
327,
2410,
314,
1642,
1373,
12,
781,
5461,
314,
1318,
3335,
436,
2066,
267,
327,
2066,
8689,
314,
5827,
665,
505,
26,
83,
30,
1819,
14,
398,
1830,
284,
665,
822,
8,
83,
304,
288,
682,
275,
308,
59,
73,
61,
288,
340,
682,
508,
1557,
84,
356,
355,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
9,
355,
312,
1587,
2162,
14,
525,
2162,
8,
7690,
1012,
355,
284,
847,
413,
288,
916,
682,
508,
1557,
78,
356,
355,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
2736,
355,
312,
1587,
2162,
14,
525,
2162,
8,
3049,
13948,
1012,
355,
284,
847,
413,
288,
916,
682,
508,
283,
7596,
355,
291,
14,
505,
3299,
14,
740,
360,
5320,
355,
284,
847,
413,
355,
291,
14,
2638,
2353,
275,
378,
355,
1830,
284,
665,
822,
8,
83,
9,
436,
334,
83,
59,
73,
61,
508,
283,
18927,
490,
291,
14,
2638,
2353,
847,
413,
490,
284,
847,
413,
355,
340,
291,
14,
2638,
2353,
690,
378,
26,
490,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
9,
490,
291,
423,
8159,
23415,
8,
364,
70,
2162,
9,
288,
587,
26,
355,
291,
14,
505,
3299,
14,
740,
8,
335,
9,
355,
284,
847,
413,
398,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
9,
339,
347,
485,
8159,
1872,
3299,
8,
277,
12,
312,
1587,
2162,
304,
267,
408,
10560,
282,
4516,
5013,
7447,
4072,
787,
314,
1453,
1318,
3299,
14,
288,
428,
2655,
7763,
26,
5436,
83,
314,
1318,
3335,
14,
267,
408,
267,
340,
822,
8,
277,
14,
505,
3299,
9,
690,
378,
26,
288,
312,
1587,
2162,
14,
525,
1872,
17840,
904,
8,
277,
14,
505,
3299,
430,
267,
291,
14,
505,
3299,
275,
942,
2378,
347,
485,
8159,
23415,
8,
277,
12,
312,
1587,
2162,
304,
267,
408,
10560,
282,
665,
505,
26,
83,
30,
1819,
367,
314,
1453,
4601,
2353,
14,
288,
428,
2655,
7763,
26,
5951,
4601,
2353,
1771,
370,
4697,
267,
408,
267,
340,
291,
14,
2638,
2353,
690,
378,
26,
288,
4601,
2162,
275,
428,
8,
67,
29,
277,
14,
2638,
2353,
9,
288,
312,
1587,
2162,
14,
525,
2162,
8,
2638,
2162,
9,
267,
291,
14,
2638,
2353,
275,
378,
199,
199,
318,
1050,
1872,
1378,
2162,
8,
364,
70,
2162,
12,
308,
304,
272,
336,
270,
275,
24403,
1872,
342,
272,
336,
270,
14,
525,
1872,
1378,
2162,
8,
364,
70,
2162,
12,
308,
9,
199,
199,
318,
5536,
1872,
8,
364,
70,
2162,
304,
272,
408,
12892,
1318,
1564,
687,
376,
6566,
12,
543,
8139,
11159,
267,
7684,
14,
1803,
314,
1318,
12,
543,
12187,
12,
7883,
12,
436,
14930,
267,
6657,
13006,
14,
961,
1083,
15035,
4328,
3198,
4012,
314,
267,
4978,
402,
314,
1627,
1819,
12,
11162,
20529,
1318,
436,
298,
324,
87,
15521,
2,
267,
665,
505,
26,
83,
6244,
665,
505,
26,
2902,
6244,
436,
665,
505,
26,
604,
13,
4785,
30,
4008,
3180,
314,
4340,
14,
272,
408,
272,
754,
275,
22750,
339,
340,
822,
8,
364,
70,
2162,
14,
10626,
9,
1137,
378,
26,
267,
367,
1982,
315,
312
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
257,
2790,
436,
5536,
1318,
687,
593,
3888,
12,
7252,
8139,
6657,
14,
199,
3,
257,
1898,
334,
35,
9,
9079,
1603,
14,
20232,
662,
572,
78,
14630,
199,
3,
199,
3,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
257,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
199,
3,
257,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
257,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
421,
199,
624,
199,
2543,
367,
7252,
8139,
7684,
315,
3232,
5564,
14,
199,
199,
25215,
652,
365,
3962,
370,
675,
664,
1872,
2714,
342,
436,
663,
1872,
2714,
342,
199,
475,
5536,
503,
1218,
593,
3888,
1564,
12,
3520,
7859,
1133,
5536,
503,
1218,
199,
1589,
5827,
665,
505,
26,
83,
6244,
665,
505,
26,
2902,
6244,
503,
665,
505,
26,
604,
13,
4785,
30,
199,
5527,
14,
221,
961,
859,
6181,
10296,
402,
626,
5160,
14,
199,
624,
199,
199,
504,
312,
1587,
14,
2108,
492,
5013,
199,
646,
312,
1587,
14,
411,
500,
679,
760,
199,
504,
312,
1587,
14,
505,
492,
428,
12,
3049,
13948,
12,
7690,
199,
199,
533,
24403,
1872,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
505,
3299,
275,
942,
267,
291,
14,
2638,
2353,
275,
378,
339,
347,
1050,
1872,
1378,
2162,
8,
277,
12,
312,
1587,
2162,
12,
308,
304,
267,
408,
7132,
376,
1324,
1059,
12,
28498,
288,
665,
505,
26,
2902,
30,
4008,
367,
1557,
84,
297,
288,
665,
505,
26,
604,
13,
4785,
30,
4008,
367,
1557,
78,
297,
436,
288,
665,
505,
26,
83,
30,
4008,
367,
7858,
402,
1655,
2419,
1373,
4596,
14,
288,
5723,
911,
506,
3483,
370,
314,
1627,
1819,
14,
267,
408,
267,
284,
275,
378,
267,
682,
275,
283,
283,
398,
327,
3979,
781,
655,
5337,
282,
5174,
503,
8057,
12,
781,
883,
9939,
267,
327,
5461,
1263,
29845,
1318,
436,
2066,
8689,
314,
5827,
267,
327,
593,
3888,
1819,
14,
267,
327,
267,
327,
3979,
781,
655,
5337,
282,
4601,
12,
781,
1050,
652,
370,
314,
1318,
3335,
12,
267,
327,
436,
2066,
8775,
1655,
7883,
14,
221,
982,
2337,
787,
1655,
7883,
267,
327,
2410,
314,
1642,
1373,
12,
781,
5461,
314,
1318,
3335,
436,
2066,
267,
327,
2066,
8689,
314,
5827,
665,
505,
26,
83,
30,
1819,
14,
398,
1830,
284,
665,
822,
8,
83,
304,
288,
682,
275,
308,
59,
73,
61,
288,
340,
682,
508,
1557,
84,
356,
355,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
9,
355,
312,
1587,
2162,
14,
525,
2162,
8,
7690,
1012,
355,
284,
847,
413,
288,
916,
682,
508,
1557,
78,
356,
355,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
2736,
355,
312,
1587,
2162,
14,
525,
2162,
8,
3049,
13948,
1012,
355,
284,
847,
413,
288,
916,
682,
508,
283,
7596,
355,
291,
14,
505,
3299,
14,
740,
360,
5320,
355,
284,
847,
413,
355,
291,
14,
2638,
2353,
275,
378,
355,
1830,
284,
665,
822,
8,
83,
9,
436,
334,
83,
59,
73,
61,
508,
283,
18927,
490,
291,
14,
2638,
2353,
847,
413,
490,
284,
847,
413,
355,
340,
291,
14,
2638,
2353,
690,
378,
26,
490,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
9,
490,
291,
423,
8159,
23415,
8,
364,
70,
2162,
9,
288,
587,
26,
355,
291,
14,
505,
3299,
14,
740,
8,
335,
9,
355,
284,
847,
413,
398,
291,
423,
8159,
1872,
3299,
8,
364,
70,
2162,
9,
339,
347,
485,
8159,
1872,
3299,
8,
277,
12,
312,
1587,
2162,
304,
267,
408,
10560,
282,
4516,
5013,
7447,
4072,
787,
314,
1453,
1318,
3299,
14,
288,
428,
2655,
7763,
26,
5436,
83,
314,
1318,
3335,
14,
267,
408,
267,
340,
822,
8,
277,
14,
505,
3299,
9,
690,
378,
26,
288,
312,
1587,
2162,
14,
525,
1872,
17840,
904,
8,
277,
14,
505,
3299,
430,
267,
291,
14,
505,
3299,
275,
942,
2378,
347,
485,
8159,
23415,
8,
277,
12,
312,
1587,
2162,
304,
267,
408,
10560,
282,
665,
505,
26,
83,
30,
1819,
367,
314,
1453,
4601,
2353,
14,
288,
428,
2655,
7763,
26,
5951,
4601,
2353,
1771,
370,
4697,
267,
408,
267,
340,
291,
14,
2638,
2353,
690,
378,
26,
288,
4601,
2162,
275,
428,
8,
67,
29,
277,
14,
2638,
2353,
9,
288,
312,
1587,
2162,
14,
525,
2162,
8,
2638,
2162,
9,
267,
291,
14,
2638,
2353,
275,
378,
199,
199,
318,
1050,
1872,
1378,
2162,
8,
364,
70,
2162,
12,
308,
304,
272,
336,
270,
275,
24403,
1872,
342,
272,
336,
270,
14,
525,
1872,
1378,
2162,
8,
364,
70,
2162,
12,
308,
9,
199,
199,
318,
5536,
1872,
8,
364,
70,
2162,
304,
272,
408,
12892,
1318,
1564,
687,
376,
6566,
12,
543,
8139,
11159,
267,
7684,
14,
1803,
314,
1318,
12,
543,
12187,
12,
7883,
12,
436,
14930,
267,
6657,
13006,
14,
961,
1083,
15035,
4328,
3198,
4012,
314,
267,
4978,
402,
314,
1627,
1819,
12,
11162,
20529,
1318,
436,
298,
324,
87,
15521,
2,
267,
665,
505,
26,
83,
6244,
665,
505,
26,
2902,
6244,
436,
665,
505,
26,
604,
13,
4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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
] |
samuknet/servo
|
tests/wpt/web-platform-tests/tools/py/py/_path/svnwc.py
|
176
|
43848
|
"""
svn-Command based Implementation of a Subversion WorkingCopy Path.
SvnWCCommandPath is the main class.
"""
import os, sys, time, re, calendar
import py
import subprocess
from py._path import common
#-----------------------------------------------------------
# Caching latest repository revision and repo-paths
# (getting them is slow with the current implementations)
#
# XXX make mt-safe
#-----------------------------------------------------------
class cache:
proplist = {}
info = {}
entries = {}
prop = {}
class RepoEntry:
def __init__(self, url, rev, timestamp):
self.url = url
self.rev = rev
self.timestamp = timestamp
def __str__(self):
return "repo: %s;%s %s" %(self.url, self.rev, self.timestamp)
class RepoCache:
""" The Repocache manages discovered repository paths
and their revisions. If inside a timeout the cache
will even return the revision of the root.
"""
timeout = 20 # seconds after which we forget that we know the last revision
def __init__(self):
self.repos = []
def clear(self):
self.repos = []
def put(self, url, rev, timestamp=None):
if rev is None:
return
if timestamp is None:
timestamp = time.time()
for entry in self.repos:
if url == entry.url:
entry.timestamp = timestamp
entry.rev = rev
#print "set repo", entry
break
else:
entry = RepoEntry(url, rev, timestamp)
self.repos.append(entry)
#print "appended repo", entry
def get(self, url):
now = time.time()
for entry in self.repos:
if url.startswith(entry.url):
if now < entry.timestamp + self.timeout:
#print "returning immediate Etrny", entry
return entry.url, entry.rev
return entry.url, -1
return url, -1
repositories = RepoCache()
# svn support code
ALLOWED_CHARS = "_ -/\\=$.~+%" #add characters as necessary when tested
if sys.platform == "win32":
ALLOWED_CHARS += ":"
ALLOWED_CHARS_HOST = ALLOWED_CHARS + '@:'
def _getsvnversion(ver=[]):
try:
return ver[0]
except IndexError:
v = py.process.cmdexec("svn -q --version")
v.strip()
v = '.'.join(v.split('.')[:2])
ver.append(v)
return v
def _escape_helper(text):
text = str(text)
if py.std.sys.platform != 'win32':
text = str(text).replace('$', '\\$')
return text
def _check_for_bad_chars(text, allowed_chars=ALLOWED_CHARS):
for c in str(text):
if c.isalnum():
continue
if c in allowed_chars:
continue
return True
return False
def checkbadchars(url):
# (hpk) not quite sure about the exact purpose, guido w.?
proto, uri = url.split("://", 1)
if proto != "file":
host, uripath = uri.split('/', 1)
# only check for bad chars in the non-protocol parts
if (_check_for_bad_chars(host, ALLOWED_CHARS_HOST) \
or _check_for_bad_chars(uripath, ALLOWED_CHARS)):
raise ValueError("bad char in %r" % (url, ))
#_______________________________________________________________
class SvnPathBase(common.PathBase):
""" Base implementation for SvnPath implementations. """
sep = '/'
def _geturl(self):
return self.strpath
url = property(_geturl, None, None, "url of this svn-path.")
def __str__(self):
""" return a string representation (including rev-number) """
return self.strpath
def __hash__(self):
return hash(self.strpath)
def new(self, **kw):
""" create a modified version of this path. A 'rev' argument
indicates a new revision.
the following keyword arguments modify various path parts::
http://host.com/repo/path/file.ext
|-----------------------| dirname
|------| basename
|--| purebasename
|--| ext
"""
obj = object.__new__(self.__class__)
obj.rev = kw.get('rev', self.rev)
obj.auth = kw.get('auth', self.auth)
dirname, basename, purebasename, ext = self._getbyspec(
"dirname,basename,purebasename,ext")
if 'basename' in kw:
if 'purebasename' in kw or 'ext' in kw:
raise ValueError("invalid specification %r" % kw)
else:
pb = kw.setdefault('purebasename', purebasename)
ext = kw.setdefault('ext', ext)
if ext and not ext.startswith('.'):
ext = '.' + ext
kw['basename'] = pb + ext
kw.setdefault('dirname', dirname)
kw.setdefault('sep', self.sep)
if kw['basename']:
obj.strpath = "%(dirname)s%(sep)s%(basename)s" % kw
else:
obj.strpath = "%(dirname)s" % kw
return obj
def _getbyspec(self, spec):
""" get specified parts of the path. 'arg' is a string
with comma separated path parts. The parts are returned
in exactly the order of the specification.
you may specify the following parts:
http://host.com/repo/path/file.ext
|-----------------------| dirname
|------| basename
|--| purebasename
|--| ext
"""
res = []
parts = self.strpath.split(self.sep)
for name in spec.split(','):
name = name.strip()
if name == 'dirname':
res.append(self.sep.join(parts[:-1]))
elif name == 'basename':
res.append(parts[-1])
else:
basename = parts[-1]
i = basename.rfind('.')
if i == -1:
purebasename, ext = basename, ''
else:
purebasename, ext = basename[:i], basename[i:]
if name == 'purebasename':
res.append(purebasename)
elif name == 'ext':
res.append(ext)
else:
raise NameError("Don't know part %r" % name)
return res
def __eq__(self, other):
""" return true if path and rev attributes each match """
return (str(self) == str(other) and
(self.rev == other.rev or self.rev == other.rev))
def __ne__(self, other):
return not self == other
def join(self, *args):
""" return a new Path (with the same revision) which is composed
of the self Path followed by 'args' path components.
"""
if not args:
return self
args = tuple([arg.strip(self.sep) for arg in args])
parts = (self.strpath, ) + args
newpath = self.__class__(self.sep.join(parts), self.rev, self.auth)
return newpath
def propget(self, name):
""" return the content of the given property. """
value = self._propget(name)
return value
def proplist(self):
""" list all property names. """
content = self._proplist()
return content
def size(self):
""" Return the size of the file content of the Path. """
return self.info().size
def mtime(self):
""" Return the last modification time of the file. """
return self.info().mtime
# shared help methods
def _escape(self, cmd):
return _escape_helper(cmd)
#def _childmaxrev(self):
# """ return maximum revision number of childs (or self.rev if no childs) """
# rev = self.rev
# for name, info in self._listdir_nameinfo():
# rev = max(rev, info.created_rev)
# return rev
#def _getlatestrevision(self):
# """ return latest repo-revision for this path. """
# url = self.strpath
# path = self.__class__(url, None)
#
# # we need a long walk to find the root-repo and revision
# while 1:
# try:
# rev = max(rev, path._childmaxrev())
# previous = path
# path = path.dirpath()
# except (IOError, process.cmdexec.Error):
# break
# if rev is None:
# raise IOError, "could not determine newest repo revision for %s" % self
# return rev
class Checkers(common.Checkers):
def dir(self):
try:
return self.path.info().kind == 'dir'
except py.error.Error:
return self._listdirworks()
def _listdirworks(self):
try:
self.path.listdir()
except py.error.ENOENT:
return False
else:
return True
def file(self):
try:
return self.path.info().kind == 'file'
except py.error.ENOENT:
return False
def exists(self):
try:
return self.path.info()
except py.error.ENOENT:
return self._listdirworks()
def parse_apr_time(timestr):
i = timestr.rfind('.')
if i == -1:
raise ValueError("could not parse %s" % timestr)
timestr = timestr[:i]
parsedtime = time.strptime(timestr, "%Y-%m-%dT%H:%M:%S")
return time.mktime(parsedtime)
class PropListDict(dict):
""" a Dictionary which fetches values (InfoSvnCommand instances) lazily"""
def __init__(self, path, keynames):
dict.__init__(self, [(x, None) for x in keynames])
self.path = path
def __getitem__(self, key):
value = dict.__getitem__(self, key)
if value is None:
value = self.path.propget(key)
dict.__setitem__(self, key, value)
return value
def fixlocale():
if sys.platform != 'win32':
return 'LC_ALL=C '
return ''
# some nasty chunk of code to solve path and url conversion and quoting issues
ILLEGAL_CHARS = '* | \ / : < > ? \t \n \x0b \x0c \r'.split(' ')
if os.sep in ILLEGAL_CHARS:
ILLEGAL_CHARS.remove(os.sep)
ISWINDOWS = sys.platform == 'win32'
_reg_allow_disk = re.compile(r'^([a-z]\:\\)?[^:]+$', re.I)
def _check_path(path):
illegal = ILLEGAL_CHARS[:]
sp = path.strpath
if ISWINDOWS:
illegal.remove(':')
if not _reg_allow_disk.match(sp):
raise ValueError('path may not contain a colon (:)')
for char in sp:
if char not in string.printable or char in illegal:
raise ValueError('illegal character %r in path' % (char,))
def path_to_fspath(path, addat=True):
_check_path(path)
sp = path.strpath
if addat and path.rev != -1:
sp = '%s@%s' % (sp, path.rev)
elif addat:
sp = '%s@HEAD' % (sp,)
return sp
def url_from_path(path):
fspath = path_to_fspath(path, False)
quote = py.std.urllib.quote
if ISWINDOWS:
match = _reg_allow_disk.match(fspath)
fspath = fspath.replace('\\', '/')
if match.group(1):
fspath = '/%s%s' % (match.group(1).replace('\\', '/'),
quote(fspath[len(match.group(1)):]))
else:
fspath = quote(fspath)
else:
fspath = quote(fspath)
if path.rev != -1:
fspath = '%s@%s' % (fspath, path.rev)
else:
fspath = '%s@HEAD' % (fspath,)
return 'file://%s' % (fspath,)
class SvnAuth(object):
""" container for auth information for Subversion """
def __init__(self, username, password, cache_auth=True, interactive=True):
self.username = username
self.password = password
self.cache_auth = cache_auth
self.interactive = interactive
def makecmdoptions(self):
uname = self.username.replace('"', '\\"')
passwd = self.password.replace('"', '\\"')
ret = []
if uname:
ret.append('--username="%s"' % (uname,))
if passwd:
ret.append('--password="%s"' % (passwd,))
if not self.cache_auth:
ret.append('--no-auth-cache')
if not self.interactive:
ret.append('--non-interactive')
return ' '.join(ret)
def __str__(self):
return "<SvnAuth username=%s ...>" %(self.username,)
rex_blame = re.compile(r'\s*(\d+)\s*(\S+) (.*)')
class SvnWCCommandPath(common.PathBase):
""" path implementation offering access/modification to svn working copies.
It has methods similar to the functions in os.path and similar to the
commands of the svn client.
"""
sep = os.sep
def __new__(cls, wcpath=None, auth=None):
self = object.__new__(cls)
if isinstance(wcpath, cls):
if wcpath.__class__ == cls:
return wcpath
wcpath = wcpath.localpath
if _check_for_bad_chars(str(wcpath),
ALLOWED_CHARS):
raise ValueError("bad char in wcpath %s" % (wcpath, ))
self.localpath = py.path.local(wcpath)
self.auth = auth
return self
strpath = property(lambda x: str(x.localpath), None, None, "string path")
rev = property(lambda x: x.info(usecache=0).rev, None, None, "revision")
def __eq__(self, other):
return self.localpath == getattr(other, 'localpath', None)
def _geturl(self):
if getattr(self, '_url', None) is None:
info = self.info()
self._url = info.url #SvnPath(info.url, info.rev)
assert isinstance(self._url, py.builtin._basestring)
return self._url
url = property(_geturl, None, None, "url of this WC item")
def _escape(self, cmd):
return _escape_helper(cmd)
def dump(self, obj):
""" pickle object into path location"""
return self.localpath.dump(obj)
def svnurl(self):
""" return current SvnPath for this WC-item. """
info = self.info()
return py.path.svnurl(info.url)
def __repr__(self):
return "svnwc(%r)" % (self.strpath) # , self._url)
def __str__(self):
return str(self.localpath)
def _makeauthoptions(self):
if self.auth is None:
return ''
return self.auth.makecmdoptions()
def _authsvn(self, cmd, args=None):
args = args and list(args) or []
args.append(self._makeauthoptions())
return self._svn(cmd, *args)
def _svn(self, cmd, *args):
l = ['svn %s' % cmd]
args = [self._escape(item) for item in args]
l.extend(args)
l.append('"%s"' % self._escape(self.strpath))
# try fixing the locale because we can't otherwise parse
string = fixlocale() + " ".join(l)
try:
try:
key = 'LC_MESSAGES'
hold = os.environ.get(key)
os.environ[key] = 'C'
out = py.process.cmdexec(string)
finally:
if hold:
os.environ[key] = hold
else:
del os.environ[key]
except py.process.cmdexec.Error:
e = sys.exc_info()[1]
strerr = e.err.lower()
if strerr.find('not found') != -1:
raise py.error.ENOENT(self)
elif strerr.find("E200009:") != -1:
raise py.error.ENOENT(self)
if (strerr.find('file exists') != -1 or
strerr.find('file already exists') != -1 or
strerr.find('w150002:') != -1 or
strerr.find("can't create directory") != -1):
raise py.error.EEXIST(strerr) #self)
raise
return out
def switch(self, url):
""" switch to given URL. """
self._authsvn('switch', [url])
def checkout(self, url=None, rev=None):
""" checkout from url to local wcpath. """
args = []
if url is None:
url = self.url
if rev is None or rev == -1:
if (py.std.sys.platform != 'win32' and
_getsvnversion() == '1.3'):
url += "@HEAD"
else:
if _getsvnversion() == '1.3':
url += "@%d" % rev
else:
args.append('-r' + str(rev))
args.append(url)
self._authsvn('co', args)
def update(self, rev='HEAD', interactive=True):
""" update working copy item to given revision. (None -> HEAD). """
opts = ['-r', rev]
if not interactive:
opts.append("--non-interactive")
self._authsvn('up', opts)
def write(self, content, mode='w'):
""" write content into local filesystem wc. """
self.localpath.write(content, mode)
def dirpath(self, *args):
""" return the directory Path of the current Path. """
return self.__class__(self.localpath.dirpath(*args), auth=self.auth)
def _ensuredirs(self):
parent = self.dirpath()
if parent.check(dir=0):
parent._ensuredirs()
if self.check(dir=0):
self.mkdir()
return self
def ensure(self, *args, **kwargs):
""" ensure that an args-joined path exists (by default as
a file). if you specify a keyword argument 'directory=True'
then the path is forced to be a directory path.
"""
p = self.join(*args)
if p.check():
if p.check(versioned=False):
p.add()
return p
if kwargs.get('dir', 0):
return p._ensuredirs()
parent = p.dirpath()
parent._ensuredirs()
p.write("")
p.add()
return p
def mkdir(self, *args):
""" create & return the directory joined with args. """
if args:
return self.join(*args).mkdir()
else:
self._svn('mkdir')
return self
def add(self):
""" add ourself to svn """
self._svn('add')
def remove(self, rec=1, force=1):
""" remove a file or a directory tree. 'rec'ursive is
ignored and considered always true (because of
underlying svn semantics.
"""
assert rec, "svn cannot remove non-recursively"
if not self.check(versioned=True):
# not added to svn (anymore?), just remove
py.path.local(self).remove()
return
flags = []
if force:
flags.append('--force')
self._svn('remove', *flags)
def copy(self, target):
""" copy path to target."""
py.process.cmdexec("svn copy %s %s" %(str(self), str(target)))
def rename(self, target):
""" rename this path to target. """
py.process.cmdexec("svn move --force %s %s" %(str(self), str(target)))
def lock(self):
""" set a lock (exclusive) on the resource """
out = self._authsvn('lock').strip()
if not out:
# warning or error, raise exception
raise ValueError("unknown error in svn lock command")
def unlock(self):
""" unset a previously set lock """
out = self._authsvn('unlock').strip()
if out.startswith('svn:'):
# warning or error, raise exception
raise Exception(out[4:])
def cleanup(self):
""" remove any locks from the resource """
# XXX should be fixed properly!!!
try:
self.unlock()
except:
pass
def status(self, updates=0, rec=0, externals=0):
""" return (collective) Status object for this file. """
# http://svnbook.red-bean.com/book.html#svn-ch-3-sect-4.3.1
# 2201 2192 jum test
# XXX
if externals:
raise ValueError("XXX cannot perform status() "
"on external items yet")
else:
#1.2 supports: externals = '--ignore-externals'
externals = ''
if rec:
rec= ''
else:
rec = '--non-recursive'
# XXX does not work on all subversion versions
#if not externals:
# externals = '--ignore-externals'
if updates:
updates = '-u'
else:
updates = ''
try:
cmd = 'status -v --xml --no-ignore %s %s %s' % (
updates, rec, externals)
out = self._authsvn(cmd)
except py.process.cmdexec.Error:
cmd = 'status -v --no-ignore %s %s %s' % (
updates, rec, externals)
out = self._authsvn(cmd)
rootstatus = WCStatus(self).fromstring(out, self)
else:
rootstatus = XMLWCStatus(self).fromstring(out, self)
return rootstatus
def diff(self, rev=None):
""" return a diff of the current path against revision rev (defaulting
to the last one).
"""
args = []
if rev is not None:
args.append("-r %d" % rev)
out = self._authsvn('diff', args)
return out
def blame(self):
""" return a list of tuples of three elements:
(revision, commiter, line)
"""
out = self._svn('blame')
result = []
blamelines = out.splitlines()
reallines = py.path.svnurl(self.url).readlines()
for i, (blameline, line) in enumerate(
zip(blamelines, reallines)):
m = rex_blame.match(blameline)
if not m:
raise ValueError("output line %r of svn blame does not match "
"expected format" % (line, ))
rev, name, _ = m.groups()
result.append((int(rev), name, line))
return result
_rex_commit = re.compile(r'.*Committed revision (\d+)\.$', re.DOTALL)
def commit(self, msg='', rec=1):
""" commit with support for non-recursive commits """
# XXX i guess escaping should be done better here?!?
cmd = 'commit -m "%s" --force-log' % (msg.replace('"', '\\"'),)
if not rec:
cmd += ' -N'
out = self._authsvn(cmd)
try:
del cache.info[self]
except KeyError:
pass
if out:
m = self._rex_commit.match(out)
return int(m.group(1))
def propset(self, name, value, *args):
""" set property name to value on this path. """
d = py.path.local.mkdtemp()
try:
p = d.join('value')
p.write(value)
self._svn('propset', name, '--file', str(p), *args)
finally:
d.remove()
def propget(self, name):
""" get property name on this path. """
res = self._svn('propget', name)
return res[:-1] # strip trailing newline
def propdel(self, name):
""" delete property name on this path. """
res = self._svn('propdel', name)
return res[:-1] # strip trailing newline
def proplist(self, rec=0):
""" return a mapping of property names to property values.
If rec is True, then return a dictionary mapping sub-paths to such mappings.
"""
if rec:
res = self._svn('proplist -R')
return make_recursive_propdict(self, res)
else:
res = self._svn('proplist')
lines = res.split('\n')
lines = [x.strip() for x in lines[1:]]
return PropListDict(self, lines)
def revert(self, rec=0):
""" revert the local changes of this path. if rec is True, do so
recursively. """
if rec:
result = self._svn('revert -R')
else:
result = self._svn('revert')
return result
def new(self, **kw):
""" create a modified version of this path. A 'rev' argument
indicates a new revision.
the following keyword arguments modify various path parts:
http://host.com/repo/path/file.ext
|-----------------------| dirname
|------| basename
|--| purebasename
|--| ext
"""
if kw:
localpath = self.localpath.new(**kw)
else:
localpath = self.localpath
return self.__class__(localpath, auth=self.auth)
def join(self, *args, **kwargs):
""" return a new Path (with the same revision) which is composed
of the self Path followed by 'args' path components.
"""
if not args:
return self
localpath = self.localpath.join(*args, **kwargs)
return self.__class__(localpath, auth=self.auth)
def info(self, usecache=1):
""" return an Info structure with svn-provided information. """
info = usecache and cache.info.get(self)
if not info:
try:
output = self._svn('info')
except py.process.cmdexec.Error:
e = sys.exc_info()[1]
if e.err.find('Path is not a working copy directory') != -1:
raise py.error.ENOENT(self, e.err)
elif e.err.find("is not under version control") != -1:
raise py.error.ENOENT(self, e.err)
raise
# XXX SVN 1.3 has output on stderr instead of stdout (while it does
# return 0!), so a bit nasty, but we assume no output is output
# to stderr...
if (output.strip() == '' or
output.lower().find('not a versioned resource') != -1):
raise py.error.ENOENT(self, output)
info = InfoSvnWCCommand(output)
# Can't reliably compare on Windows without access to win32api
if py.std.sys.platform != 'win32':
if info.path != self.localpath:
raise py.error.ENOENT(self, "not a versioned resource:" +
" %s != %s" % (info.path, self.localpath))
cache.info[self] = info
return info
def listdir(self, fil=None, sort=None):
""" return a sequence of Paths.
listdir will return either a tuple or a list of paths
depending on implementation choices.
"""
if isinstance(fil, str):
fil = common.FNMatcher(fil)
# XXX unify argument naming with LocalPath.listdir
def notsvn(path):
return path.basename != '.svn'
paths = []
for localpath in self.localpath.listdir(notsvn):
p = self.__class__(localpath, auth=self.auth)
if notsvn(p) and (not fil or fil(p)):
paths.append(p)
self._sortlist(paths, sort)
return paths
def open(self, mode='r'):
""" return an opened file with the given mode. """
return open(self.strpath, mode)
def _getbyspec(self, spec):
return self.localpath._getbyspec(spec)
class Checkers(py.path.local.Checkers):
def __init__(self, path):
self.svnwcpath = path
self.path = path.localpath
def versioned(self):
try:
s = self.svnwcpath.info()
except (py.error.ENOENT, py.error.EEXIST):
return False
except py.process.cmdexec.Error:
e = sys.exc_info()[1]
if e.err.find('is not a working copy')!=-1:
return False
if e.err.lower().find('not a versioned resource') != -1:
return False
raise
else:
return True
def log(self, rev_start=None, rev_end=1, verbose=False):
""" return a list of LogEntry instances for this path.
rev_start is the starting revision (defaulting to the first one).
rev_end is the last revision (defaulting to HEAD).
if verbose is True, then the LogEntry instances also know which files changed.
"""
assert self.check() # make it simpler for the pipe
rev_start = rev_start is None and "HEAD" or rev_start
rev_end = rev_end is None and "HEAD" or rev_end
if rev_start == "HEAD" and rev_end == 1:
rev_opt = ""
else:
rev_opt = "-r %s:%s" % (rev_start, rev_end)
verbose_opt = verbose and "-v" or ""
locale_env = fixlocale()
# some blather on stderr
auth_opt = self._makeauthoptions()
#stdin, stdout, stderr = os.popen3(locale_env +
# 'svn log --xml %s %s %s "%s"' % (
# rev_opt, verbose_opt, auth_opt,
# self.strpath))
cmd = locale_env + 'svn log --xml %s %s %s "%s"' % (
rev_opt, verbose_opt, auth_opt, self.strpath)
popen = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)
stdout, stderr = popen.communicate()
stdout = py.builtin._totext(stdout, sys.getdefaultencoding())
minidom,ExpatError = importxml()
try:
tree = minidom.parseString(stdout)
except ExpatError:
raise ValueError('no such revision')
result = []
for logentry in filter(None, tree.firstChild.childNodes):
if logentry.nodeType == logentry.ELEMENT_NODE:
result.append(LogEntry(logentry))
return result
def size(self):
""" Return the size of the file content of the Path. """
return self.info().size
def mtime(self):
""" Return the last modification time of the file. """
return self.info().mtime
def __hash__(self):
return hash((self.strpath, self.__class__, self.auth))
class WCStatus:
attrnames = ('modified','added', 'conflict', 'unchanged', 'external',
'deleted', 'prop_modified', 'unknown', 'update_available',
'incomplete', 'kindmismatch', 'ignored', 'locked', 'replaced'
)
def __init__(self, wcpath, rev=None, modrev=None, author=None):
self.wcpath = wcpath
self.rev = rev
self.modrev = modrev
self.author = author
for name in self.attrnames:
setattr(self, name, [])
def allpath(self, sort=True, **kw):
d = {}
for name in self.attrnames:
if name not in kw or kw[name]:
for path in getattr(self, name):
d[path] = 1
l = d.keys()
if sort:
l.sort()
return l
# XXX a bit scary to assume there's always 2 spaces between username and
# path, however with win32 allowing spaces in user names there doesn't
# seem to be a more solid approach :(
_rex_status = re.compile(r'\s+(\d+|-)\s+(\S+)\s+(.+?)\s{2,}(.*)')
def fromstring(data, rootwcpath, rev=None, modrev=None, author=None):
""" return a new WCStatus object from data 's'
"""
rootstatus = WCStatus(rootwcpath, rev, modrev, author)
update_rev = None
for line in data.split('\n'):
if not line.strip():
continue
#print "processing %r" % line
flags, rest = line[:8], line[8:]
# first column
c0,c1,c2,c3,c4,c5,x6,c7 = flags
#if '*' in line:
# print "flags", repr(flags), "rest", repr(rest)
if c0 in '?XI':
fn = line.split(None, 1)[1]
if c0 == '?':
wcpath = rootwcpath.join(fn, abs=1)
rootstatus.unknown.append(wcpath)
elif c0 == 'X':
wcpath = rootwcpath.__class__(
rootwcpath.localpath.join(fn, abs=1),
auth=rootwcpath.auth)
rootstatus.external.append(wcpath)
elif c0 == 'I':
wcpath = rootwcpath.join(fn, abs=1)
rootstatus.ignored.append(wcpath)
continue
#elif c0 in '~!' or c4 == 'S':
# raise NotImplementedError("received flag %r" % c0)
m = WCStatus._rex_status.match(rest)
if not m:
if c7 == '*':
fn = rest.strip()
wcpath = rootwcpath.join(fn, abs=1)
rootstatus.update_available.append(wcpath)
continue
if line.lower().find('against revision:')!=-1:
update_rev = int(rest.split(':')[1].strip())
continue
if line.lower().find('status on external') > -1:
# XXX not sure what to do here... perhaps we want to
# store some state instead of just continuing, as right
# now it makes the top-level external get added twice
# (once as external, once as 'normal' unchanged item)
# because of the way SVN presents external items
continue
# keep trying
raise ValueError("could not parse line %r" % line)
else:
rev, modrev, author, fn = m.groups()
wcpath = rootwcpath.join(fn, abs=1)
#assert wcpath.check()
if c0 == 'M':
assert wcpath.check(file=1), "didn't expect a directory with changed content here"
rootstatus.modified.append(wcpath)
elif c0 == 'A' or c3 == '+' :
rootstatus.added.append(wcpath)
elif c0 == 'D':
rootstatus.deleted.append(wcpath)
elif c0 == 'C':
rootstatus.conflict.append(wcpath)
elif c0 == '~':
rootstatus.kindmismatch.append(wcpath)
elif c0 == '!':
rootstatus.incomplete.append(wcpath)
elif c0 == 'R':
rootstatus.replaced.append(wcpath)
elif not c0.strip():
rootstatus.unchanged.append(wcpath)
else:
raise NotImplementedError("received flag %r" % c0)
if c1 == 'M':
rootstatus.prop_modified.append(wcpath)
# XXX do we cover all client versions here?
if c2 == 'L' or c5 == 'K':
rootstatus.locked.append(wcpath)
if c7 == '*':
rootstatus.update_available.append(wcpath)
if wcpath == rootwcpath:
rootstatus.rev = rev
rootstatus.modrev = modrev
rootstatus.author = author
if update_rev:
rootstatus.update_rev = update_rev
continue
return rootstatus
fromstring = staticmethod(fromstring)
class XMLWCStatus(WCStatus):
def fromstring(data, rootwcpath, rev=None, modrev=None, author=None):
""" parse 'data' (XML string as outputted by svn st) into a status obj
"""
# XXX for externals, the path is shown twice: once
# with external information, and once with full info as if
# the item was a normal non-external... the current way of
# dealing with this issue is by ignoring it - this does make
# externals appear as external items as well as 'normal',
# unchanged ones in the status object so this is far from ideal
rootstatus = WCStatus(rootwcpath, rev, modrev, author)
update_rev = None
minidom, ExpatError = importxml()
try:
doc = minidom.parseString(data)
except ExpatError:
e = sys.exc_info()[1]
raise ValueError(str(e))
urevels = doc.getElementsByTagName('against')
if urevels:
rootstatus.update_rev = urevels[-1].getAttribute('revision')
for entryel in doc.getElementsByTagName('entry'):
path = entryel.getAttribute('path')
statusel = entryel.getElementsByTagName('wc-status')[0]
itemstatus = statusel.getAttribute('item')
if itemstatus == 'unversioned':
wcpath = rootwcpath.join(path, abs=1)
rootstatus.unknown.append(wcpath)
continue
elif itemstatus == 'external':
wcpath = rootwcpath.__class__(
rootwcpath.localpath.join(path, abs=1),
auth=rootwcpath.auth)
rootstatus.external.append(wcpath)
continue
elif itemstatus == 'ignored':
wcpath = rootwcpath.join(path, abs=1)
rootstatus.ignored.append(wcpath)
continue
elif itemstatus == 'incomplete':
wcpath = rootwcpath.join(path, abs=1)
rootstatus.incomplete.append(wcpath)
continue
rev = statusel.getAttribute('revision')
if itemstatus == 'added' or itemstatus == 'none':
rev = '0'
modrev = '?'
author = '?'
date = ''
elif itemstatus == "replaced":
pass
else:
#print entryel.toxml()
commitel = entryel.getElementsByTagName('commit')[0]
if commitel:
modrev = commitel.getAttribute('revision')
author = ''
author_els = commitel.getElementsByTagName('author')
if author_els:
for c in author_els[0].childNodes:
author += c.nodeValue
date = ''
for c in commitel.getElementsByTagName('date')[0]\
.childNodes:
date += c.nodeValue
wcpath = rootwcpath.join(path, abs=1)
assert itemstatus != 'modified' or wcpath.check(file=1), (
'did\'t expect a directory with changed content here')
itemattrname = {
'normal': 'unchanged',
'unversioned': 'unknown',
'conflicted': 'conflict',
'none': 'added',
}.get(itemstatus, itemstatus)
attr = getattr(rootstatus, itemattrname)
attr.append(wcpath)
propsstatus = statusel.getAttribute('props')
if propsstatus not in ('none', 'normal'):
rootstatus.prop_modified.append(wcpath)
if wcpath == rootwcpath:
rootstatus.rev = rev
rootstatus.modrev = modrev
rootstatus.author = author
rootstatus.date = date
# handle repos-status element (remote info)
rstatusels = entryel.getElementsByTagName('repos-status')
if rstatusels:
rstatusel = rstatusels[0]
ritemstatus = rstatusel.getAttribute('item')
if ritemstatus in ('added', 'modified'):
rootstatus.update_available.append(wcpath)
lockels = entryel.getElementsByTagName('lock')
if len(lockels):
rootstatus.locked.append(wcpath)
return rootstatus
fromstring = staticmethod(fromstring)
class InfoSvnWCCommand:
def __init__(self, output):
# Path: test
# URL: http://codespeak.net/svn/std.path/trunk/dist/std.path/test
# Repository UUID: fd0d7bf2-dfb6-0310-8d31-b7ecfe96aada
# Revision: 2151
# Node Kind: directory
# Schedule: normal
# Last Changed Author: hpk
# Last Changed Rev: 2100
# Last Changed Date: 2003-10-27 20:43:14 +0100 (Mon, 27 Oct 2003)
# Properties Last Updated: 2003-11-03 14:47:48 +0100 (Mon, 03 Nov 2003)
d = {}
for line in output.split('\n'):
if not line.strip():
continue
key, value = line.split(':', 1)
key = key.lower().replace(' ', '')
value = value.strip()
d[key] = value
try:
self.url = d['url']
except KeyError:
raise ValueError("Not a versioned resource")
#raise ValueError, "Not a versioned resource %r" % path
self.kind = d['nodekind'] == 'directory' and 'dir' or d['nodekind']
try:
self.rev = int(d['revision'])
except KeyError:
self.rev = None
self.path = py.path.local(d['path'])
self.size = self.path.size()
if 'lastchangedrev' in d:
self.created_rev = int(d['lastchangedrev'])
if 'lastchangedauthor' in d:
self.last_author = d['lastchangedauthor']
if 'lastchangeddate' in d:
self.mtime = parse_wcinfotime(d['lastchangeddate'])
self.time = self.mtime * 1000000
def __eq__(self, other):
return self.__dict__ == other.__dict__
def parse_wcinfotime(timestr):
""" Returns seconds since epoch, UTC. """
# example: 2003-10-27 20:43:14 +0100 (Mon, 27 Oct 2003)
m = re.match(r'(\d+-\d+-\d+ \d+:\d+:\d+) ([+-]\d+) .*', timestr)
if not m:
raise ValueError("timestring %r does not match" % timestr)
timestr, timezone = m.groups()
# do not handle timezone specially, return value should be UTC
parsedtime = time.strptime(timestr, "%Y-%m-%d %H:%M:%S")
return calendar.timegm(parsedtime)
def make_recursive_propdict(wcroot,
output,
rex = re.compile("Properties on '(.*)':")):
""" Return a dictionary of path->PropListDict mappings. """
lines = [x for x in output.split('\n') if x]
pdict = {}
while lines:
line = lines.pop(0)
m = rex.match(line)
if not m:
raise ValueError("could not parse propget-line: %r" % line)
path = m.groups()[0]
wcpath = wcroot.join(path, abs=1)
propnames = []
while lines and lines[0].startswith(' '):
propname = lines.pop(0).strip()
propnames.append(propname)
assert propnames, "must have found properties!"
pdict[wcpath] = PropListDict(wcpath, propnames)
return pdict
def importxml(cache=[]):
if cache:
return cache
from xml.dom import minidom
from xml.parsers.expat import ExpatError
cache.extend([minidom, ExpatError])
return cache
class LogEntry:
def __init__(self, logentry):
self.rev = int(logentry.getAttribute('revision'))
for lpart in filter(None, logentry.childNodes):
if lpart.nodeType == lpart.ELEMENT_NODE:
if lpart.nodeName == 'author':
self.author = lpart.firstChild.nodeValue
elif lpart.nodeName == 'msg':
if lpart.firstChild:
self.msg = lpart.firstChild.nodeValue
else:
self.msg = ''
elif lpart.nodeName == 'date':
#2003-07-29T20:05:11.598637Z
timestr = lpart.firstChild.nodeValue
self.date = parse_apr_time(timestr)
elif lpart.nodeName == 'paths':
self.strpaths = []
for ppart in filter(None, lpart.childNodes):
if ppart.nodeType == ppart.ELEMENT_NODE:
self.strpaths.append(PathEntry(ppart))
def __repr__(self):
return '<Logentry rev=%d author=%s date=%s>' % (
self.rev, self.author, self.date)
|
mpl-2.0
|
[
624,
199,
6836,
13,
3110,
4079,
24425,
402,
282,
31098,
9361,
316,
5116,
6912,
14,
819,
428,
6002,
55,
35,
3110,
2042,
221,
365,
314,
2446,
1021,
14,
199,
199,
624,
199,
199,
646,
747,
12,
984,
12,
900,
12,
295,
12,
11234,
199,
646,
1134,
199,
646,
3873,
199,
504,
1134,
423,
515,
492,
2863,
199,
199,
17807,
13715,
199,
3,
445,
23302,
8839,
7611,
6974,
436,
3831,
13,
3771,
199,
3,
334,
362,
1337,
3062,
365,
11999,
543,
314,
1453,
12591,
9,
199,
3,
199,
3,
5787,
1852,
19592,
13,
3489,
199,
17807,
13715,
199,
199,
533,
2581,
26,
272,
5931,
513,
275,
1052,
272,
2256,
275,
1052,
272,
4811,
275,
1052,
272,
5931,
275,
1052,
199,
199,
533,
20069,
3900,
26,
272,
347,
636,
826,
721,
277,
12,
1166,
12,
6822,
12,
4913,
304,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
4964,
275,
6822,
267,
291,
14,
3954,
275,
4913,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
3417,
26,
450,
83,
27,
5,
83,
221,
450,
83,
2,
2818,
277,
14,
633,
12,
291,
14,
4964,
12,
291,
14,
3954,
9,
199,
199,
533,
20069,
4437,
26,
272,
408,
710,
20069,
1637,
31965,
24983,
7611,
3792,
272,
436,
3932,
22164,
14,
221,
982,
6272,
282,
2653,
314,
2581,
272,
911,
2755,
372,
314,
6974,
402,
314,
1738,
14,
272,
408,
272,
2653,
275,
3388,
327,
4696,
2410,
1314,
781,
19459,
626,
781,
5715,
314,
2061,
6974,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
11857,
275,
942,
339,
347,
5436,
8,
277,
304,
267,
291,
14,
11857,
275,
942,
339,
347,
5324,
8,
277,
12,
1166,
12,
6822,
12,
4913,
29,
403,
304,
267,
340,
6822,
365,
488,
26,
288,
372,
267,
340,
4913,
365,
488,
26,
288,
4913,
275,
900,
14,
521,
342,
398,
367,
2397,
315,
291,
14,
11857,
26,
288,
340,
1166,
508,
2397,
14,
633,
26,
355,
2397,
14,
3954,
275,
4913,
355,
2397,
14,
4964,
275,
6822,
355,
327,
1361,
298,
409,
3831,
401,
2397,
355,
2059,
267,
587,
26,
288,
2397,
275,
20069,
3900,
8,
633,
12,
6822,
12,
4913,
9,
288,
291,
14,
11857,
14,
740,
8,
2373,
9,
288,
327,
1361,
298,
5435,
770,
3831,
401,
2397,
339,
347,
664,
8,
277,
12,
1166,
304,
267,
3063,
275,
900,
14,
521,
342,
267,
367,
2397,
315,
291,
14,
11857,
26,
288,
340,
1166,
14,
2460,
8,
2373,
14,
633,
304,
355,
340,
3063,
665,
2397,
14,
3954,
435,
291,
14,
2593,
26,
490,
327,
1361,
298,
24112,
8569,
662,
454,
9745,
401,
2397,
490,
372,
2397,
14,
633,
12,
2397,
14,
4964,
355,
372,
2397,
14,
633,
12,
446,
17,
267,
372,
1166,
12,
446,
17,
199,
199,
23949,
275,
20069,
4437,
342,
421,
199,
3,
11327,
2291,
1233,
199,
199,
17350,
63,
16326,
275,
2668,
446,
15,
1103,
28617,
14,
94,
25389,
2,
327,
525,
4110,
465,
5784,
1380,
12470,
199,
692,
984,
14,
3246,
508,
298,
2676,
708,
582,
272,
27805,
1149,
63,
16326,
847,
14725,
199,
17350,
63,
16326,
63,
5449,
275,
27805,
1149,
63,
16326,
435,
10267,
4881,
199,
199,
318,
485,
362,
6836,
1023,
8,
422,
17894,
272,
862,
26,
267,
372,
809,
59,
16,
61,
272,
871,
7888,
26,
267,
373,
275,
1134,
14,
1412,
14,
4400,
731,
825,
480,
6836,
446,
81,
1553,
1023,
531,
267,
373,
14,
1913,
342,
267,
373,
275,
15671,
904,
8,
86,
14,
1294,
7563,
1491,
18,
566,
267,
809,
14,
740,
8,
86,
9,
267,
372,
373,
199,
199,
318,
485,
3765,
63,
3676,
8,
505,
304,
272,
1318,
275,
620,
8,
505,
9,
272,
340,
1134,
14,
1516,
14,
1274,
14,
3246,
1137,
283,
2676,
708,
356,
267,
1318,
275,
620,
8,
505,
680,
1814,
360,
4268,
6468,
9988,
272,
372,
1318,
199,
199,
318,
485,
1074,
63,
509,
63,
4087,
63,
6574,
8,
505,
12,
4370,
63,
6574,
29,
17350,
63,
16326,
304,
272,
367,
286,
315,
620,
8,
505,
304,
267,
340,
286,
14,
28235,
1507,
837,
288,
1980,
267,
340,
286,
315,
4370,
63,
6574,
26,
288,
1980,
267,
372,
715,
272,
372,
756,
199,
199,
318,
1104,
4087,
6574,
8,
633,
304,
272,
327,
334,
72,
2051,
9,
440,
18794,
3238,
3595,
314,
5835,
12016,
12,
15593,
79,
336,
14,
31,
272,
4104,
12,
5108,
275,
1166,
14,
1294,
480,
921,
401,
413,
9,
272,
340,
4104,
1137,
298,
493,
582,
267,
1591,
12,
5108,
515,
275,
5108,
14,
1294,
10998,
413,
9,
267,
327,
1454,
1104,
367,
4875,
8365,
315,
314,
2222,
13,
3922,
4184,
267,
340,
6110,
1074,
63,
509,
63,
4087,
63,
6574,
8,
1102,
12,
27805,
1149,
63,
16326,
63,
5449,
9,
971,
288,
503,
485,
1074,
63,
509,
63,
4087,
63,
6574,
8,
2302,
515,
12,
27805,
1149,
63,
16326,
2298,
288,
746,
1722,
480,
4087,
1495,
315,
450,
82,
2,
450,
334,
633,
12,
5082,
421,
199,
3,
22794,
13088,
7785,
4741,
8989,
199,
199,
533,
428,
6002,
2042,
1563,
8,
2330,
14,
2042,
1563,
304,
272,
408,
3523,
4514,
367,
428,
6002,
2042,
12591,
14,
408,
272,
7375,
275,
7324,
339,
347,
485,
32130,
8,
277,
304,
267,
372,
291,
14,
495,
515,
272,
1166,
275,
3324,
1547,
32130,
12,
488,
12,
488,
12,
298,
633,
402,
642,
11327,
13,
515,
2685,
339,
347,
636,
495,
721,
277,
304,
267,
408,
372,
282,
1059,
6025,
334,
15768,
6822,
13,
1955,
9,
408,
267,
372,
291,
14,
495,
515,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
495,
515,
9,
339,
347,
892,
8,
277,
12,
1011,
829,
304,
267,
408,
1218,
282,
6042,
1015,
402,
642,
931,
14,
437,
283,
4964,
7,
1423,
288,
9126,
282,
892,
6974,
14,
288,
314,
2569,
4252,
2368,
2811,
7750,
931,
4184,
447,
25841,
1455,
921,
1102,
14,
957,
15,
3417,
15,
515,
15,
493,
14,
832,
1598,
1204,
777,
12797,
92,
3515,
9017,
3147,
1204,
8648,
92,
9593,
3147,
1204,
306,
92,
258,
15111,
4846,
4490,
1204,
306,
92,
1599,
267,
408,
267,
1559,
275,
909,
855,
1222,
721,
277,
855,
533,
3368,
267,
1559,
14,
4964,
275,
4775
] |
[
199,
6836,
13,
3110,
4079,
24425,
402,
282,
31098,
9361,
316,
5116,
6912,
14,
819,
428,
6002,
55,
35,
3110,
2042,
221,
365,
314,
2446,
1021,
14,
199,
199,
624,
199,
199,
646,
747,
12,
984,
12,
900,
12,
295,
12,
11234,
199,
646,
1134,
199,
646,
3873,
199,
504,
1134,
423,
515,
492,
2863,
199,
199,
17807,
13715,
199,
3,
445,
23302,
8839,
7611,
6974,
436,
3831,
13,
3771,
199,
3,
334,
362,
1337,
3062,
365,
11999,
543,
314,
1453,
12591,
9,
199,
3,
199,
3,
5787,
1852,
19592,
13,
3489,
199,
17807,
13715,
199,
199,
533,
2581,
26,
272,
5931,
513,
275,
1052,
272,
2256,
275,
1052,
272,
4811,
275,
1052,
272,
5931,
275,
1052,
199,
199,
533,
20069,
3900,
26,
272,
347,
636,
826,
721,
277,
12,
1166,
12,
6822,
12,
4913,
304,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
4964,
275,
6822,
267,
291,
14,
3954,
275,
4913,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
3417,
26,
450,
83,
27,
5,
83,
221,
450,
83,
2,
2818,
277,
14,
633,
12,
291,
14,
4964,
12,
291,
14,
3954,
9,
199,
199,
533,
20069,
4437,
26,
272,
408,
710,
20069,
1637,
31965,
24983,
7611,
3792,
272,
436,
3932,
22164,
14,
221,
982,
6272,
282,
2653,
314,
2581,
272,
911,
2755,
372,
314,
6974,
402,
314,
1738,
14,
272,
408,
272,
2653,
275,
3388,
327,
4696,
2410,
1314,
781,
19459,
626,
781,
5715,
314,
2061,
6974,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
11857,
275,
942,
339,
347,
5436,
8,
277,
304,
267,
291,
14,
11857,
275,
942,
339,
347,
5324,
8,
277,
12,
1166,
12,
6822,
12,
4913,
29,
403,
304,
267,
340,
6822,
365,
488,
26,
288,
372,
267,
340,
4913,
365,
488,
26,
288,
4913,
275,
900,
14,
521,
342,
398,
367,
2397,
315,
291,
14,
11857,
26,
288,
340,
1166,
508,
2397,
14,
633,
26,
355,
2397,
14,
3954,
275,
4913,
355,
2397,
14,
4964,
275,
6822,
355,
327,
1361,
298,
409,
3831,
401,
2397,
355,
2059,
267,
587,
26,
288,
2397,
275,
20069,
3900,
8,
633,
12,
6822,
12,
4913,
9,
288,
291,
14,
11857,
14,
740,
8,
2373,
9,
288,
327,
1361,
298,
5435,
770,
3831,
401,
2397,
339,
347,
664,
8,
277,
12,
1166,
304,
267,
3063,
275,
900,
14,
521,
342,
267,
367,
2397,
315,
291,
14,
11857,
26,
288,
340,
1166,
14,
2460,
8,
2373,
14,
633,
304,
355,
340,
3063,
665,
2397,
14,
3954,
435,
291,
14,
2593,
26,
490,
327,
1361,
298,
24112,
8569,
662,
454,
9745,
401,
2397,
490,
372,
2397,
14,
633,
12,
2397,
14,
4964,
355,
372,
2397,
14,
633,
12,
446,
17,
267,
372,
1166,
12,
446,
17,
199,
199,
23949,
275,
20069,
4437,
342,
421,
199,
3,
11327,
2291,
1233,
199,
199,
17350,
63,
16326,
275,
2668,
446,
15,
1103,
28617,
14,
94,
25389,
2,
327,
525,
4110,
465,
5784,
1380,
12470,
199,
692,
984,
14,
3246,
508,
298,
2676,
708,
582,
272,
27805,
1149,
63,
16326,
847,
14725,
199,
17350,
63,
16326,
63,
5449,
275,
27805,
1149,
63,
16326,
435,
10267,
4881,
199,
199,
318,
485,
362,
6836,
1023,
8,
422,
17894,
272,
862,
26,
267,
372,
809,
59,
16,
61,
272,
871,
7888,
26,
267,
373,
275,
1134,
14,
1412,
14,
4400,
731,
825,
480,
6836,
446,
81,
1553,
1023,
531,
267,
373,
14,
1913,
342,
267,
373,
275,
15671,
904,
8,
86,
14,
1294,
7563,
1491,
18,
566,
267,
809,
14,
740,
8,
86,
9,
267,
372,
373,
199,
199,
318,
485,
3765,
63,
3676,
8,
505,
304,
272,
1318,
275,
620,
8,
505,
9,
272,
340,
1134,
14,
1516,
14,
1274,
14,
3246,
1137,
283,
2676,
708,
356,
267,
1318,
275,
620,
8,
505,
680,
1814,
360,
4268,
6468,
9988,
272,
372,
1318,
199,
199,
318,
485,
1074,
63,
509,
63,
4087,
63,
6574,
8,
505,
12,
4370,
63,
6574,
29,
17350,
63,
16326,
304,
272,
367,
286,
315,
620,
8,
505,
304,
267,
340,
286,
14,
28235,
1507,
837,
288,
1980,
267,
340,
286,
315,
4370,
63,
6574,
26,
288,
1980,
267,
372,
715,
272,
372,
756,
199,
199,
318,
1104,
4087,
6574,
8,
633,
304,
272,
327,
334,
72,
2051,
9,
440,
18794,
3238,
3595,
314,
5835,
12016,
12,
15593,
79,
336,
14,
31,
272,
4104,
12,
5108,
275,
1166,
14,
1294,
480,
921,
401,
413,
9,
272,
340,
4104,
1137,
298,
493,
582,
267,
1591,
12,
5108,
515,
275,
5108,
14,
1294,
10998,
413,
9,
267,
327,
1454,
1104,
367,
4875,
8365,
315,
314,
2222,
13,
3922,
4184,
267,
340,
6110,
1074,
63,
509,
63,
4087,
63,
6574,
8,
1102,
12,
27805,
1149,
63,
16326,
63,
5449,
9,
971,
288,
503,
485,
1074,
63,
509,
63,
4087,
63,
6574,
8,
2302,
515,
12,
27805,
1149,
63,
16326,
2298,
288,
746,
1722,
480,
4087,
1495,
315,
450,
82,
2,
450,
334,
633,
12,
5082,
421,
199,
3,
22794,
13088,
7785,
4741,
8989,
199,
199,
533,
428,
6002,
2042,
1563,
8,
2330,
14,
2042,
1563,
304,
272,
408,
3523,
4514,
367,
428,
6002,
2042,
12591,
14,
408,
272,
7375,
275,
7324,
339,
347,
485,
32130,
8,
277,
304,
267,
372,
291,
14,
495,
515,
272,
1166,
275,
3324,
1547,
32130,
12,
488,
12,
488,
12,
298,
633,
402,
642,
11327,
13,
515,
2685,
339,
347,
636,
495,
721,
277,
304,
267,
408,
372,
282,
1059,
6025,
334,
15768,
6822,
13,
1955,
9,
408,
267,
372,
291,
14,
495,
515,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
495,
515,
9,
339,
347,
892,
8,
277,
12,
1011,
829,
304,
267,
408,
1218,
282,
6042,
1015,
402,
642,
931,
14,
437,
283,
4964,
7,
1423,
288,
9126,
282,
892,
6974,
14,
288,
314,
2569,
4252,
2368,
2811,
7750,
931,
4184,
447,
25841,
1455,
921,
1102,
14,
957,
15,
3417,
15,
515,
15,
493,
14,
832,
1598,
1204,
777,
12797,
92,
3515,
9017,
3147,
1204,
8648,
92,
9593,
3147,
1204,
306,
92,
258,
15111,
4846,
4490,
1204,
306,
92,
1599,
267,
408,
267,
1559,
275,
909,
855,
1222,
721,
277,
855,
533,
3368,
267,
1559,
14,
4964,
275,
4775,
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
] |
richpolis/siveinpy
|
env/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/coordseq.py
|
624
|
3112
|
from ctypes import c_double, c_int, c_uint, POINTER
from django.contrib.gis.geos.libgeos import GEOM_PTR, CS_PTR
from django.contrib.gis.geos.prototypes.errcheck import last_arg_byref, GEOSException
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
## Error-checking routines specific to coordinate sequences. ##
def check_cs_ptr(result, func, cargs):
"Error checking on routines that return Geometries."
if not result:
raise GEOSException('Error encountered checking Coordinate Sequence returned from GEOS C function "%s".' % func.__name__)
return result
def check_cs_op(result, func, cargs):
"Checks the status code of a coordinate sequence operation."
if result == 0:
raise GEOSException('Could not set value on coordinate sequence')
else:
return result
def check_cs_get(result, func, cargs):
"Checking the coordinate sequence retrieval."
check_cs_op(result, func, cargs)
# Object in by reference, return its value.
return last_arg_byref(cargs)
## Coordinate sequence prototype generation functions. ##
def cs_int(func):
"For coordinate sequence routines that return an integer."
func.argtypes = [CS_PTR, POINTER(c_uint)]
func.restype = c_int
func.errcheck = check_cs_get
return func
def cs_operation(func, ordinate=False, get=False):
"For coordinate sequence operations."
if get:
# Get routines get double parameter passed-in by reference.
func.errcheck = check_cs_get
dbl_param = POINTER(c_double)
else:
func.errcheck = check_cs_op
dbl_param = c_double
if ordinate:
# Get/Set ordinate routines have an extra uint parameter.
func.argtypes = [CS_PTR, c_uint, c_uint, dbl_param]
else:
func.argtypes = [CS_PTR, c_uint, dbl_param]
func.restype = c_int
return func
def cs_output(func, argtypes):
"For routines that return a coordinate sequence."
func.argtypes = argtypes
func.restype = CS_PTR
func.errcheck = check_cs_ptr
return func
## Coordinate Sequence ctypes prototypes ##
# Coordinate Sequence constructors & cloning.
cs_clone = cs_output(GEOSFunc('GEOSCoordSeq_clone'), [CS_PTR])
create_cs = cs_output(GEOSFunc('GEOSCoordSeq_create'), [c_uint, c_uint])
get_cs = cs_output(GEOSFunc('GEOSGeom_getCoordSeq'), [GEOM_PTR])
# Getting, setting ordinate
cs_getordinate = cs_operation(GEOSFunc('GEOSCoordSeq_getOrdinate'), ordinate=True, get=True)
cs_setordinate = cs_operation(GEOSFunc('GEOSCoordSeq_setOrdinate'), ordinate=True)
# For getting, x, y, z
cs_getx = cs_operation(GEOSFunc('GEOSCoordSeq_getX'), get=True)
cs_gety = cs_operation(GEOSFunc('GEOSCoordSeq_getY'), get=True)
cs_getz = cs_operation(GEOSFunc('GEOSCoordSeq_getZ'), get=True)
# For setting, x, y, z
cs_setx = cs_operation(GEOSFunc('GEOSCoordSeq_setX'))
cs_sety = cs_operation(GEOSFunc('GEOSCoordSeq_setY'))
cs_setz = cs_operation(GEOSFunc('GEOSCoordSeq_setZ'))
# These routines return size & dimensions.
cs_getsize = cs_int(GEOSFunc('GEOSCoordSeq_getSize'))
cs_getdims = cs_int(GEOSFunc('GEOSCoordSeq_getDimensions'))
|
mit
|
[
504,
5577,
492,
286,
63,
3157,
12,
286,
63,
442,
12,
286,
63,
1635,
12,
6569,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
8991,
7474,
63,
14528,
12,
17447,
63,
14528,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
21205,
492,
2061,
63,
1273,
63,
20447,
12,
21390,
21686,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
2671,
3489,
492,
11920,
7465,
199,
199,
309,
4520,
13,
19527,
14975,
2488,
370,
10021,
8013,
14,
925,
199,
318,
1104,
63,
1259,
63,
4695,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
547,
7907,
641,
14975,
626,
372,
5346,
14100,
2122,
272,
340,
440,
754,
26,
267,
746,
21390,
21686,
360,
547,
14556,
7907,
25334,
323,
10975,
2138,
687,
11920,
445,
805,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
199,
199,
318,
1104,
63,
1259,
63,
411,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
11834,
314,
2004,
1233,
402,
282,
10021,
3414,
3439,
2122,
272,
340,
754,
508,
378,
26,
267,
746,
21390,
21686,
360,
6531,
440,
663,
574,
641,
10021,
3414,
358,
272,
587,
26,
267,
372,
754,
199,
199,
318,
1104,
63,
1259,
63,
362,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
14740,
314,
10021,
3414,
27157,
2122,
272,
1104,
63,
1259,
63,
411,
8,
1099,
12,
2562,
12,
286,
589,
9,
272,
327,
6935,
315,
701,
3659,
12,
372,
2399,
574,
14,
272,
372,
2061,
63,
1273,
63,
20447,
8,
67,
589,
9,
199,
199,
309,
25334,
323,
3414,
19393,
10152,
3423,
14,
925,
199,
318,
7117,
63,
442,
8,
1532,
304,
272,
298,
1858,
10021,
3414,
14975,
626,
372,
376,
3000,
2122,
272,
2562,
14,
10025,
275,
359,
3298,
63,
14528,
12,
6569,
8,
67,
63,
1635,
1874,
272,
2562,
14,
9990,
275,
286,
63,
442,
272,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
362,
272,
372,
2562,
199,
199,
318,
7117,
63,
5735,
8,
1532,
12,
6206,
23043,
29,
797,
12,
664,
29,
797,
304,
272,
298,
1858,
10021,
3414,
5331,
2122,
272,
340,
664,
26,
267,
327,
2372,
14975,
664,
4270,
2725,
3032,
13,
262,
701,
3659,
14,
267,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
362,
267,
1592,
76,
63,
635,
275,
6569,
8,
67,
63,
3157,
9,
272,
587,
26,
267,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
411,
267,
1592,
76,
63,
635,
275,
286,
63,
3157,
339,
340,
6206,
23043,
26,
267,
327,
2372,
15,
1084,
6206,
23043,
14975,
1172,
376,
2402,
3152,
2725,
14,
267,
2562,
14,
10025,
275,
359,
3298,
63,
14528,
12,
286,
63,
1635,
12,
286,
63,
1635,
12,
1592,
76,
63,
635,
61,
272,
587,
26,
267,
2562,
14,
10025,
275,
359,
3298,
63,
14528,
12,
286,
63,
1635,
12,
1592,
76,
63,
635,
61,
339,
2562,
14,
9990,
275,
286,
63,
442,
272,
372,
2562,
199,
199,
318,
7117,
63,
1199,
8,
1532,
12,
29669,
304,
272,
298,
1858,
14975,
626,
372,
282,
10021,
3414,
2122,
272,
2562,
14,
10025,
275,
29669,
272,
2562,
14,
9990,
275,
17447,
63,
14528,
272,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
4695,
272,
372,
2562,
199,
199,
309,
25334,
323,
10975,
5577,
19393,
83,
925,
199,
199,
3,
25334,
323,
10975,
31604,
1253,
824,
19718,
14,
199,
1259,
63,
6311,
275,
7117,
63,
1199,
8,
31887,
360,
14151,
14957,
11205,
63,
6311,
659,
359,
3298,
63,
14528,
566,
199,
981,
63,
1259,
275,
7117,
63,
1199,
8,
31887,
360,
14151,
14957,
11205,
63,
981,
659,
359,
67,
63,
1635,
12,
286,
63,
1635,
566,
199,
362,
63,
1259,
275,
7117,
63,
1199,
8,
31887,
360,
14151,
13427,
63,
362,
14957,
11205,
659,
359,
31080,
63,
14528,
566,
199,
199,
3,
20703,
12,
4260,
6206,
23043,
199,
1259,
63,
362,
4055,
323,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
30457,
68,
23043,
659,
6206,
23043,
29,
549,
12,
664,
29,
549,
9,
199,
1259,
63,
409,
4055,
323,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
2844,
68,
23043,
659,
6206,
23043,
29,
549,
9,
199,
199,
3,
2104,
10232,
12,
671,
12,
612,
12,
1315,
199,
1259,
63,
362,
88,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
56,
659,
664,
29,
549,
9,
199,
1259,
63,
362,
89,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
57,
659,
664,
29,
549,
9,
199,
1259,
63,
362,
90,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
58,
659,
664,
29,
549,
9,
199,
199,
3,
2104,
4260,
12,
671,
12,
612,
12,
1315,
199,
1259,
63,
409,
88,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
56,
1333,
199,
1259,
63,
261,
369,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
57,
1333,
199,
1259,
63,
409,
90,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
58,
1333,
199,
199,
3,
5723,
14975,
372,
1568,
1253,
7365,
14,
199,
1259,
63,
20733,
275,
7117,
63,
442,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
2320,
1333,
199,
1259,
63,
362,
5380,
275,
7117,
63,
442,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
23370,
1333,
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
] |
[
5577,
492,
286,
63,
3157,
12,
286,
63,
442,
12,
286,
63,
1635,
12,
6569,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
773,
12151,
492,
8991,
7474,
63,
14528,
12,
17447,
63,
14528,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
21205,
492,
2061,
63,
1273,
63,
20447,
12,
21390,
21686,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
14,
16141,
83,
14,
2671,
3489,
492,
11920,
7465,
199,
199,
309,
4520,
13,
19527,
14975,
2488,
370,
10021,
8013,
14,
925,
199,
318,
1104,
63,
1259,
63,
4695,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
547,
7907,
641,
14975,
626,
372,
5346,
14100,
2122,
272,
340,
440,
754,
26,
267,
746,
21390,
21686,
360,
547,
14556,
7907,
25334,
323,
10975,
2138,
687,
11920,
445,
805,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
199,
199,
318,
1104,
63,
1259,
63,
411,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
11834,
314,
2004,
1233,
402,
282,
10021,
3414,
3439,
2122,
272,
340,
754,
508,
378,
26,
267,
746,
21390,
21686,
360,
6531,
440,
663,
574,
641,
10021,
3414,
358,
272,
587,
26,
267,
372,
754,
199,
199,
318,
1104,
63,
1259,
63,
362,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
14740,
314,
10021,
3414,
27157,
2122,
272,
1104,
63,
1259,
63,
411,
8,
1099,
12,
2562,
12,
286,
589,
9,
272,
327,
6935,
315,
701,
3659,
12,
372,
2399,
574,
14,
272,
372,
2061,
63,
1273,
63,
20447,
8,
67,
589,
9,
199,
199,
309,
25334,
323,
3414,
19393,
10152,
3423,
14,
925,
199,
318,
7117,
63,
442,
8,
1532,
304,
272,
298,
1858,
10021,
3414,
14975,
626,
372,
376,
3000,
2122,
272,
2562,
14,
10025,
275,
359,
3298,
63,
14528,
12,
6569,
8,
67,
63,
1635,
1874,
272,
2562,
14,
9990,
275,
286,
63,
442,
272,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
362,
272,
372,
2562,
199,
199,
318,
7117,
63,
5735,
8,
1532,
12,
6206,
23043,
29,
797,
12,
664,
29,
797,
304,
272,
298,
1858,
10021,
3414,
5331,
2122,
272,
340,
664,
26,
267,
327,
2372,
14975,
664,
4270,
2725,
3032,
13,
262,
701,
3659,
14,
267,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
362,
267,
1592,
76,
63,
635,
275,
6569,
8,
67,
63,
3157,
9,
272,
587,
26,
267,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
411,
267,
1592,
76,
63,
635,
275,
286,
63,
3157,
339,
340,
6206,
23043,
26,
267,
327,
2372,
15,
1084,
6206,
23043,
14975,
1172,
376,
2402,
3152,
2725,
14,
267,
2562,
14,
10025,
275,
359,
3298,
63,
14528,
12,
286,
63,
1635,
12,
286,
63,
1635,
12,
1592,
76,
63,
635,
61,
272,
587,
26,
267,
2562,
14,
10025,
275,
359,
3298,
63,
14528,
12,
286,
63,
1635,
12,
1592,
76,
63,
635,
61,
339,
2562,
14,
9990,
275,
286,
63,
442,
272,
372,
2562,
199,
199,
318,
7117,
63,
1199,
8,
1532,
12,
29669,
304,
272,
298,
1858,
14975,
626,
372,
282,
10021,
3414,
2122,
272,
2562,
14,
10025,
275,
29669,
272,
2562,
14,
9990,
275,
17447,
63,
14528,
272,
2562,
14,
21205,
275,
1104,
63,
1259,
63,
4695,
272,
372,
2562,
199,
199,
309,
25334,
323,
10975,
5577,
19393,
83,
925,
199,
199,
3,
25334,
323,
10975,
31604,
1253,
824,
19718,
14,
199,
1259,
63,
6311,
275,
7117,
63,
1199,
8,
31887,
360,
14151,
14957,
11205,
63,
6311,
659,
359,
3298,
63,
14528,
566,
199,
981,
63,
1259,
275,
7117,
63,
1199,
8,
31887,
360,
14151,
14957,
11205,
63,
981,
659,
359,
67,
63,
1635,
12,
286,
63,
1635,
566,
199,
362,
63,
1259,
275,
7117,
63,
1199,
8,
31887,
360,
14151,
13427,
63,
362,
14957,
11205,
659,
359,
31080,
63,
14528,
566,
199,
199,
3,
20703,
12,
4260,
6206,
23043,
199,
1259,
63,
362,
4055,
323,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
30457,
68,
23043,
659,
6206,
23043,
29,
549,
12,
664,
29,
549,
9,
199,
1259,
63,
409,
4055,
323,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
2844,
68,
23043,
659,
6206,
23043,
29,
549,
9,
199,
199,
3,
2104,
10232,
12,
671,
12,
612,
12,
1315,
199,
1259,
63,
362,
88,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
56,
659,
664,
29,
549,
9,
199,
1259,
63,
362,
89,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
57,
659,
664,
29,
549,
9,
199,
1259,
63,
362,
90,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
58,
659,
664,
29,
549,
9,
199,
199,
3,
2104,
4260,
12,
671,
12,
612,
12,
1315,
199,
1259,
63,
409,
88,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
56,
1333,
199,
1259,
63,
261,
369,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
57,
1333,
199,
1259,
63,
409,
90,
275,
7117,
63,
5735,
8,
31887,
360,
14151,
14957,
11205,
63,
409,
58,
1333,
199,
199,
3,
5723,
14975,
372,
1568,
1253,
7365,
14,
199,
1259,
63,
20733,
275,
7117,
63,
442,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
2320,
1333,
199,
1259,
63,
362,
5380,
275,
7117,
63,
442,
8,
31887,
360,
14151,
14957,
11205,
63,
362,
23370,
1333,
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,
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,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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
] |
palmer159/openstack-test
|
packstack/installer/utils/shortcuts.py
|
3
|
1698
|
# -*- coding: utf-8 -*-
# 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 grp
import os
import pwd
def host_iter(config):
for key, value in config.iteritems():
if key.endswith("_HOST"):
host = value.split('/')[0]
if host:
yield key, host
if key.endswith("_HOSTS"):
for i in value.split(","):
host = i.strip().split('/')[0]
if host:
yield key, host
def hosts(config):
result = set()
for key, host in host_iter(config):
result.add(host)
return result
def get_current_user():
try:
user = pwd.getpwnam(os.getlogin())
uid, gid = user.pw_uid, user.pw_gid
except OSError:
# in case program is run by a script
uid, gid = os.getuid(), os.getgid()
return uid, gid
def get_current_username():
uid, gid = get_current_user()
user = pwd.getpwuid(uid).pw_name
group = grp.getgrgid(gid).gr_name
return user, group
def split_hosts(hosts_string):
hosts = set()
for host in hosts_string.split(','):
shost = host.strip()
if shost:
hosts.add(shost)
return hosts
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
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,
259,
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,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
18598,
199,
646,
747,
199,
646,
14374,
421,
199,
318,
1591,
63,
1661,
8,
888,
304,
272,
367,
790,
12,
574,
315,
1101,
14,
4611,
837,
267,
340,
790,
14,
4130,
11008,
5449,
2349,
288,
1591,
275,
574,
14,
1294,
30746,
16,
61,
288,
340,
1591,
26,
355,
1995,
790,
12,
1591,
267,
340,
790,
14,
4130,
11008,
23775,
2349,
288,
367,
284,
315,
574,
14,
1294,
8,
2266,
304,
355,
1591,
275,
284,
14,
1913,
1252,
1294,
30746,
16,
61,
355,
340,
1591,
26,
490,
1995,
790,
12,
1591,
421,
199,
318,
7057,
8,
888,
304,
272,
754,
275,
663,
342,
272,
367,
790,
12,
1591,
315,
1591,
63,
1661,
8,
888,
304,
267,
754,
14,
525,
8,
1102,
9,
272,
372,
754,
421,
199,
318,
664,
63,
1818,
63,
751,
837,
272,
862,
26,
267,
922,
275,
14374,
14,
362,
80,
3501,
455,
8,
736,
14,
362,
2886,
1012,
267,
1747,
12,
15122,
275,
922,
14,
8796,
63,
1535,
12,
922,
14,
8796,
63,
8787,
272,
871,
6440,
26,
267,
327,
315,
1930,
2240,
365,
1255,
701,
282,
2884,
267,
1747,
12,
15122,
275,
747,
14,
362,
1535,
1062,
747,
14,
362,
8787,
342,
272,
372,
1747,
12,
15122,
421,
199,
318,
664,
63,
1818,
63,
2473,
837,
272,
1747,
12,
15122,
275,
664,
63,
1818,
63,
751,
342,
272,
922,
275,
14374,
14,
362,
8796,
1535,
8,
1535,
680,
8796,
63,
354,
272,
1572,
275,
18598,
14,
362,
2587,
8787,
8,
8787,
680,
2587,
63,
354,
272,
372,
922,
12,
1572,
421,
199,
318,
3715,
63,
5146,
8,
5146,
63,
875,
304,
272,
7057,
275,
663,
342,
272,
367,
1591,
315,
7057,
63,
875,
14,
1294,
25908,
267,
930,
270,
275,
1591,
14,
1913,
342,
267,
340,
930,
270,
26,
288,
7057,
14,
525,
8,
83,
1102,
9,
272,
372,
7057,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
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,
259,
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,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
18598,
199,
646,
747,
199,
646,
14374,
421,
199,
318,
1591,
63,
1661,
8,
888,
304,
272,
367,
790,
12,
574,
315,
1101,
14,
4611,
837,
267,
340,
790,
14,
4130,
11008,
5449,
2349,
288,
1591,
275,
574,
14,
1294,
30746,
16,
61,
288,
340,
1591,
26,
355,
1995,
790,
12,
1591,
267,
340,
790,
14,
4130,
11008,
23775,
2349,
288,
367,
284,
315,
574,
14,
1294,
8,
2266,
304,
355,
1591,
275,
284,
14,
1913,
1252,
1294,
30746,
16,
61,
355,
340,
1591,
26,
490,
1995,
790,
12,
1591,
421,
199,
318,
7057,
8,
888,
304,
272,
754,
275,
663,
342,
272,
367,
790,
12,
1591,
315,
1591,
63,
1661,
8,
888,
304,
267,
754,
14,
525,
8,
1102,
9,
272,
372,
754,
421,
199,
318,
664,
63,
1818,
63,
751,
837,
272,
862,
26,
267,
922,
275,
14374,
14,
362,
80,
3501,
455,
8,
736,
14,
362,
2886,
1012,
267,
1747,
12,
15122,
275,
922,
14,
8796,
63,
1535,
12,
922,
14,
8796,
63,
8787,
272,
871,
6440,
26,
267,
327,
315,
1930,
2240,
365,
1255,
701,
282,
2884,
267,
1747,
12,
15122,
275,
747,
14,
362,
1535,
1062,
747,
14,
362,
8787,
342,
272,
372,
1747,
12,
15122,
421,
199,
318,
664,
63,
1818,
63,
2473,
837,
272,
1747,
12,
15122,
275,
664,
63,
1818,
63,
751,
342,
272,
922,
275,
14374,
14,
362,
8796,
1535,
8,
1535,
680,
8796,
63,
354,
272,
1572,
275,
18598,
14,
362,
2587,
8787,
8,
8787,
680,
2587,
63,
354,
272,
372,
922,
12,
1572,
421,
199,
318,
3715,
63,
5146,
8,
5146,
63,
875,
304,
272,
7057,
275,
663,
342,
272,
367,
1591,
315,
7057,
63,
875,
14,
1294,
25908,
267,
930,
270,
275,
1591,
14,
1913,
342,
267,
340,
930,
270,
26,
288,
7057,
14,
525,
8,
83,
1102,
9,
272,
372,
7057,
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,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sangh/LaserShow
|
pyglet-hg/pyglet/image/codecs/bmp.py
|
18
|
12417
|
# ----------------------------------------------------------------------------
# pyglet
# Copyright (c) 2006-2008 Alex Holkner
# 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 pyglet 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.
# ----------------------------------------------------------------------------
'''Decoder for BMP files.
Currently supports version 3 and 4 bitmaps with BI_RGB and BI_BITFIELDS
encoding. Alpha channel is supported for 32-bit BI_RGB only.
'''
# Official docs are at
# http://msdn2.microsoft.com/en-us/library/ms532311.aspx
#
# But some details including alignment and bit/byte order are omitted; see
# http://www.fileformat.info/format/bmp/egff.htm
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import ctypes
from pyglet.image import ImageData
from pyglet.image.codecs import ImageDecoder, ImageDecodeException
BYTE = ctypes.c_ubyte
WORD = ctypes.c_uint16
DWORD = ctypes.c_uint32
LONG = ctypes.c_int32
FXPT2DOT30 = ctypes.c_uint32
BI_RGB = 0
BI_RLE8 = 1
BI_RLE4 = 2
BI_BITFIELDS = 3
class BITMAPFILEHEADER(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('bfType', WORD),
('bfSize', DWORD),
('bfReserved1', WORD),
('bfReserved2', WORD),
('bfOffBits', DWORD)
]
class BITMAPINFOHEADER(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('biSize', DWORD),
('biWidth', LONG),
('biHeight', LONG),
('biPlanes', WORD),
('biBitCount', WORD),
('biCompression', DWORD),
('biSizeImage', DWORD),
('biXPelsPerMeter', LONG),
('biYPelsPerMeter', LONG),
('biClrUsed', DWORD),
('biClrImportant', DWORD)
]
CIEXYZTRIPLE = FXPT2DOT30 * 9
class BITMAPV4HEADER(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('biSize', DWORD),
('biWidth', LONG),
('biHeight', LONG),
('biPlanes', WORD),
('biBitCount', WORD),
('biCompression', DWORD),
('biSizeImage', DWORD),
('biXPelsPerMeter', LONG),
('biYPelsPerMeter', LONG),
('biClrUsed', DWORD),
('biClrImportant', DWORD),
('bV4RedMask', DWORD),
('bV4GreenMask', DWORD),
('bV4BlueMask', DWORD),
('bV4AlphaMask', DWORD),
('bV4CSType', DWORD),
('bV4Endpoints', CIEXYZTRIPLE),
('bV4GammaRed', DWORD),
('bV4GammaGreen', DWORD),
('bV4GammaBlue', DWORD),
]
class RGBFields(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('red', DWORD),
('green', DWORD),
('blue', DWORD),
]
class RGBQUAD(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('rgbBlue', BYTE),
('rgbGreen', BYTE),
('rgbRed', BYTE),
('rgbReserved', BYTE)
]
def __repr__(self):
return '<%d, %d, %d>' % (self.rgbRed, self.rgbGreen, self.rgbBlue)
def ptr_add(ptr, offset):
address = ctypes.addressof(ptr.contents) + offset
return ctypes.pointer(type(ptr.contents).from_address(address))
def to_ctypes(buffer, offset, type):
if offset + ctypes.sizeof(type) > len(buffer):
raise ImageDecodeException('BMP file is truncated')
ptr = ptr_add(ctypes.pointer(buffer), offset)
return ctypes.cast(ptr, ctypes.POINTER(type)).contents
class BMPImageDecoder(ImageDecoder):
def get_file_extensions(self):
return ['.bmp']
def decode(self, file, filename):
if not file:
file = open(filename, 'rb')
bytes = file.read()
buffer = ctypes.c_buffer(bytes)
if bytes[:2] != 'BM':
raise ImageDecodeException(
'Not a Windows bitmap file: %r' % (filename or file))
file_header = to_ctypes(buffer, 0, BITMAPFILEHEADER)
bits_offset = file_header.bfOffBits
info_header_offset = ctypes.sizeof(BITMAPFILEHEADER)
info_header = to_ctypes(buffer, info_header_offset, BITMAPINFOHEADER)
palette_offset = info_header_offset + info_header.biSize
if info_header.biSize < ctypes.sizeof(BITMAPINFOHEADER):
raise ImageDecodeException(
'Unsupported BMP type: %r' % (filename or file))
width = info_header.biWidth
height = info_header.biHeight
if width <= 0 or info_header.biPlanes != 1:
raise ImageDecodeException(
'BMP file has corrupt parameters: %r' % (filename or file))
pitch_sign = height < 0 and -1 or 1
height = abs(height)
compression = info_header.biCompression
if compression not in (BI_RGB, BI_BITFIELDS):
raise ImageDecodeException(
'Unsupported compression: %r' % (filename or file))
clr_used = 0
bitcount = info_header.biBitCount
if bitcount == 1:
pitch = (width + 7) // 8
bits_type = ctypes.c_ubyte
decoder = decode_1bit
elif bitcount == 4:
pitch = (width + 1) // 2
bits_type = ctypes.c_ubyte
decoder = decode_4bit
elif bitcount == 8:
bits_type = ctypes.c_ubyte
pitch = width
decoder = decode_8bit
elif bitcount == 16:
pitch = width * 2
bits_type = ctypes.c_uint16
decoder = decode_bitfields
elif bitcount == 24:
pitch = width * 3
bits_type = ctypes.c_ubyte
decoder = decode_24bit
elif bitcount == 32:
pitch = width * 4
if compression == BI_RGB:
decoder = decode_32bit_rgb
bits_type = ctypes.c_ubyte
elif compression == BI_BITFIELDS:
decoder = decode_bitfields
bits_type = ctypes.c_uint32
else:
raise ImageDecodeException(
'Unsupported compression: %r' % (filename or file))
else:
raise ImageDecodeException(
'Unsupported bit count %d: %r' % (bitcount, filename or file))
pitch = (pitch + 3) & ~3
packed_width = pitch // ctypes.sizeof(bits_type)
if bitcount < 16 and compression == BI_RGB:
clr_used = info_header.biClrUsed or (1 << bitcount)
palette = to_ctypes(buffer, palette_offset, RGBQUAD * clr_used)
bits = to_ctypes(buffer, bits_offset,
bits_type * packed_width * height)
return decoder(bits, palette, width, height, pitch, pitch_sign)
elif bitcount >= 16 and compression == BI_RGB:
bits = to_ctypes(buffer, bits_offset,
bits_type * (packed_width * height))
return decoder(bits, None, width, height, pitch, pitch_sign)
elif compression == BI_BITFIELDS:
if info_header.biSize >= ctypes.sizeof(BITMAPV4HEADER):
info_header = to_ctypes(buffer, info_header_offset,
BITMAPV4HEADER)
r_mask = info_header.bV4RedMask
g_mask = info_header.bV4GreenMask
b_mask = info_header.bV4BlueMask
else:
fields_offset = info_header_offset + \
ctypes.sizeof(BITMAPINFOHEADER)
fields = to_ctypes(buffer, fields_offset, RGBFields)
r_mask = fields.red
g_mask = fields.green
b_mask = fields.blue
class _BitsArray(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('data', bits_type * packed_width * height),
]
bits = to_ctypes(buffer, bits_offset, _BitsArray).data
return decoder(bits, r_mask, g_mask, b_mask,
width, height, pitch, pitch_sign)
def decode_1bit(bits, palette, width, height, pitch, pitch_sign):
rgb_pitch = (((pitch << 3) + 7) & ~0x7) * 3
buffer = (ctypes.c_ubyte * (height * rgb_pitch))()
i = 0
for row in bits:
for packed in row:
for _ in range(8):
rgb = palette[(packed & 0x80) >> 7]
buffer[i] = rgb.rgbRed
buffer[i + 1] = rgb.rgbGreen
buffer[i + 2] = rgb.rgbBlue
i += 3
packed <<= 1
return ImageData(width, height, 'RGB', buffer, pitch_sign * rgb_pitch)
def decode_4bit(bits, palette, width, height, pitch, pitch_sign):
rgb_pitch = (((pitch << 1) + 1) & ~0x1) * 3
buffer = (ctypes.c_ubyte * (height * rgb_pitch))()
i = 0
for row in bits:
for packed in row:
for index in ((packed & 0xf0) >> 4, packed & 0xf):
rgb = palette[index]
buffer[i] = rgb.rgbRed
buffer[i + 1] = rgb.rgbGreen
buffer[i + 2] = rgb.rgbBlue
i += 3
return ImageData(width, height, 'RGB', buffer, pitch_sign * rgb_pitch)
def decode_8bit(bits, palette, width, height, pitch, pitch_sign):
rgb_pitch = pitch * 3
buffer = (ctypes.c_ubyte * (height * rgb_pitch))()
i = 0
for row in bits:
for index in row:
rgb = palette[index]
buffer[i] = rgb.rgbRed
buffer[i + 1] = rgb.rgbGreen
buffer[i + 2] = rgb.rgbBlue
i += 3
return ImageData(width, height, 'RGB', buffer, pitch_sign * rgb_pitch)
def decode_24bit(bits, palette, width, height, pitch, pitch_sign):
buffer = (ctypes.c_ubyte * (height * pitch))()
ctypes.memmove(buffer, bits, len(buffer))
return ImageData(width, height, 'BGR', buffer, pitch_sign * pitch)
def decode_32bit_rgb(bits, palette, width, height, pitch, pitch_sign):
buffer = (ctypes.c_ubyte * (height * pitch))()
ctypes.memmove(buffer, bits, len(buffer))
return ImageData(width, height, 'BGRA', buffer, pitch_sign * pitch)
def get_shift(mask):
if not mask:
return 0
# Shift down
shift = 0
while not (1 << shift) & mask:
shift += 1
# Shift up
shift_up = 0
while (mask >> shift) >> shift_up:
shift_up += 1
s = shift - (8 - shift_up)
if s < 0:
return 0, -s
else:
return s, 0
def decode_bitfields(bits, r_mask, g_mask, b_mask,
width, height, pitch, pitch_sign):
r_shift1, r_shift2 = get_shift(r_mask)
g_shift1, g_shift2 = get_shift(g_mask)
b_shift1, b_shift2 = get_shift(b_mask)
rgb_pitch = 3 * len(bits[0])
buffer = (ctypes.c_ubyte * (height * rgb_pitch))()
i = 0
for row in bits:
for packed in row:
buffer[i] = (packed & r_mask) >> r_shift1 << r_shift2
buffer[i+1] = (packed & g_mask) >> g_shift1 << g_shift2
buffer[i+2] = (packed & b_mask) >> b_shift1 << b_shift2
i += 3
return ImageData(width, height, 'RGB', buffer, pitch_sign * rgb_pitch)
def get_decoders():
return [BMPImageDecoder()]
def get_encoders():
return []
|
bsd-3-clause
|
[
3,
27103,
199,
3,
23409,
199,
3,
1898,
334,
67,
9,
8315,
13,
9300,
22986,
869,
393,
75,
1372,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
221,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
221,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
259,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
259,
4084,
14,
199,
3,
221,
627,
11443,
314,
536,
402,
23409,
6590,
314,
1561,
402,
2399,
199,
3,
259,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
259,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
259,
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,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
27103,
199,
199,
2344,
8326,
367,
699,
1658,
1584,
14,
199,
199,
31499,
5171,
1015,
650,
436,
841,
4546,
8919,
543,
699,
41,
63,
12067,
436,
699,
41,
63,
11970,
12767,
199,
2991,
14,
221,
32657,
3623,
365,
3748,
367,
4337,
13,
2075,
699,
41,
63,
12067,
1454,
14,
199,
2344,
199,
199,
3,
24545,
16714,
9149,
787,
737,
199,
3,
1455,
921,
706,
4272,
18,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
706,
21,
13905,
845,
14,
26146,
199,
3,
199,
3,
11017,
2005,
2436,
5893,
13177,
436,
4546,
15,
4414,
1865,
787,
11684,
27,
1937,
199,
3,
1455,
921,
1544,
14,
493,
908,
14,
815,
15,
908,
15,
22308,
15,
5902,
556,
14,
15575,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
646,
5577,
199,
199,
504,
23409,
14,
1569,
492,
6047,
1451,
199,
504,
23409,
14,
1569,
14,
8933,
492,
6047,
8326,
12,
6047,
9400,
1726,
199,
199,
19714,
275,
5577,
14,
67,
63,
20790,
199,
5172,
275,
5577,
14,
67,
63,
1635,
975,
199,
24754,
275,
5577,
14,
67,
63,
1635,
708,
199,
12375,
275,
5577,
14,
67,
63,
442,
708,
199,
22322,
4189,
18,
13203,
1216,
275,
5577,
14,
67,
63,
1635,
708,
199,
199,
19419,
63,
12067,
275,
378,
199,
19419,
63,
50,
906,
24,
275,
413,
199,
19419,
63,
50,
906,
20,
275,
499,
199,
19419,
63,
11970,
12767,
275,
650,
199,
199,
533,
699,
649,
5443,
3817,
7311,
8,
9798,
14,
44,
390,
1118,
1327,
6268,
10766,
304,
272,
485,
1389,
63,
275,
413,
272,
485,
955,
63,
275,
359,
267,
661,
4361,
804,
297,
31858,
395,
267,
661,
4361,
2320,
297,
13936,
395,
267,
661,
4361,
10285,
17,
297,
31858,
395,
267,
661,
4361,
10285,
18,
297,
31858,
395,
267,
661,
4361,
5195,
10787,
297,
13936,
9,
272,
1622,
199,
199,
533,
699,
649,
5443,
4531,
7311,
8,
9798,
14,
44,
390,
1118,
1327,
6268,
10766,
304,
272,
485,
1389,
63,
275,
413,
272,
485,
955,
63,
275,
359,
267,
661,
4492,
2320,
297,
13936,
395,
267,
661,
4492,
6216,
297,
26594,
395,
267,
661,
4492,
8436,
297,
26594,
395,
267,
661,
4492,
13375,
397,
297,
31858,
395,
267,
661,
4492,
4734,
2353,
297,
31858,
395,
267,
661,
4492,
25551,
297,
13936,
395,
267,
661,
4492,
2320,
3491,
297,
13936,
395,
267,
661,
4492,
20168,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
7431,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
1968,
82,
9167,
297,
13936,
395,
267,
661,
4492,
1968,
82,
6295,
867,
297,
13936,
9,
272,
1622,
199,
199,
3553,
1438,
26184,
1766,
1772,
906,
275,
481,
56,
4189,
18,
13203,
1216,
627,
1749,
199,
199,
533,
699,
649,
5443,
54,
20,
7311,
8,
9798,
14,
44,
390,
1118,
1327,
6268,
10766,
304,
272,
485,
1389,
63,
275,
413,
272,
485,
955,
63,
275,
359,
267,
661,
4492,
2320,
297,
13936,
395,
267,
661,
4492,
6216,
297,
26594,
395,
267,
661,
4492,
8436,
297,
26594,
395,
267,
661,
4492,
13375,
397,
297,
31858,
395,
267,
661,
4492,
4734,
2353,
297,
31858,
395,
267,
661,
4492,
25551,
297,
13936,
395,
267,
661,
4492,
2320,
3491,
297,
13936,
395,
267,
661,
4492,
20168,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
7431,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
1968,
82,
9167,
297,
13936,
395,
267,
661,
4492,
1968,
82,
6295,
867,
297,
13936,
395,
267,
661,
66,
54,
20,
10858,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
19456,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
15617,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
16192,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
3298,
804,
297,
13936,
395,
267,
661,
66,
54,
20,
3005,
3438,
297,
445,
41,
1438,
26184,
1766,
1772,
906,
395,
267,
661,
66,
54,
20,
15091,
10858,
297,
13936,
395,
267,
661,
66,
54,
20,
15091,
19456,
297,
13936,
395,
267,
661,
66,
54,
20,
15091,
15617,
297,
13936,
395,
272,
1622,
199,
199,
533,
19013,
7304
] |
[
27103,
199,
3,
23409,
199,
3,
1898,
334,
67,
9,
8315,
13,
9300,
22986,
869,
393,
75,
1372,
199,
3,
2900,
4481,
4644,
14,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
221,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
221,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
3,
259,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
259,
4084,
14,
199,
3,
221,
627,
11443,
314,
536,
402,
23409,
6590,
314,
1561,
402,
2399,
199,
3,
259,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
259,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
259,
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,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
27103,
199,
199,
2344,
8326,
367,
699,
1658,
1584,
14,
199,
199,
31499,
5171,
1015,
650,
436,
841,
4546,
8919,
543,
699,
41,
63,
12067,
436,
699,
41,
63,
11970,
12767,
199,
2991,
14,
221,
32657,
3623,
365,
3748,
367,
4337,
13,
2075,
699,
41,
63,
12067,
1454,
14,
199,
2344,
199,
199,
3,
24545,
16714,
9149,
787,
737,
199,
3,
1455,
921,
706,
4272,
18,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
706,
21,
13905,
845,
14,
26146,
199,
3,
199,
3,
11017,
2005,
2436,
5893,
13177,
436,
4546,
15,
4414,
1865,
787,
11684,
27,
1937,
199,
3,
1455,
921,
1544,
14,
493,
908,
14,
815,
15,
908,
15,
22308,
15,
5902,
556,
14,
15575,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
646,
5577,
199,
199,
504,
23409,
14,
1569,
492,
6047,
1451,
199,
504,
23409,
14,
1569,
14,
8933,
492,
6047,
8326,
12,
6047,
9400,
1726,
199,
199,
19714,
275,
5577,
14,
67,
63,
20790,
199,
5172,
275,
5577,
14,
67,
63,
1635,
975,
199,
24754,
275,
5577,
14,
67,
63,
1635,
708,
199,
12375,
275,
5577,
14,
67,
63,
442,
708,
199,
22322,
4189,
18,
13203,
1216,
275,
5577,
14,
67,
63,
1635,
708,
199,
199,
19419,
63,
12067,
275,
378,
199,
19419,
63,
50,
906,
24,
275,
413,
199,
19419,
63,
50,
906,
20,
275,
499,
199,
19419,
63,
11970,
12767,
275,
650,
199,
199,
533,
699,
649,
5443,
3817,
7311,
8,
9798,
14,
44,
390,
1118,
1327,
6268,
10766,
304,
272,
485,
1389,
63,
275,
413,
272,
485,
955,
63,
275,
359,
267,
661,
4361,
804,
297,
31858,
395,
267,
661,
4361,
2320,
297,
13936,
395,
267,
661,
4361,
10285,
17,
297,
31858,
395,
267,
661,
4361,
10285,
18,
297,
31858,
395,
267,
661,
4361,
5195,
10787,
297,
13936,
9,
272,
1622,
199,
199,
533,
699,
649,
5443,
4531,
7311,
8,
9798,
14,
44,
390,
1118,
1327,
6268,
10766,
304,
272,
485,
1389,
63,
275,
413,
272,
485,
955,
63,
275,
359,
267,
661,
4492,
2320,
297,
13936,
395,
267,
661,
4492,
6216,
297,
26594,
395,
267,
661,
4492,
8436,
297,
26594,
395,
267,
661,
4492,
13375,
397,
297,
31858,
395,
267,
661,
4492,
4734,
2353,
297,
31858,
395,
267,
661,
4492,
25551,
297,
13936,
395,
267,
661,
4492,
2320,
3491,
297,
13936,
395,
267,
661,
4492,
20168,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
7431,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
1968,
82,
9167,
297,
13936,
395,
267,
661,
4492,
1968,
82,
6295,
867,
297,
13936,
9,
272,
1622,
199,
199,
3553,
1438,
26184,
1766,
1772,
906,
275,
481,
56,
4189,
18,
13203,
1216,
627,
1749,
199,
199,
533,
699,
649,
5443,
54,
20,
7311,
8,
9798,
14,
44,
390,
1118,
1327,
6268,
10766,
304,
272,
485,
1389,
63,
275,
413,
272,
485,
955,
63,
275,
359,
267,
661,
4492,
2320,
297,
13936,
395,
267,
661,
4492,
6216,
297,
26594,
395,
267,
661,
4492,
8436,
297,
26594,
395,
267,
661,
4492,
13375,
397,
297,
31858,
395,
267,
661,
4492,
4734,
2353,
297,
31858,
395,
267,
661,
4492,
25551,
297,
13936,
395,
267,
661,
4492,
2320,
3491,
297,
13936,
395,
267,
661,
4492,
20168,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
7431,
18099,
2623,
27937,
297,
26594,
395,
267,
661,
4492,
1968,
82,
9167,
297,
13936,
395,
267,
661,
4492,
1968,
82,
6295,
867,
297,
13936,
395,
267,
661,
66,
54,
20,
10858,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
19456,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
15617,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
16192,
5144,
297,
13936,
395,
267,
661,
66,
54,
20,
3298,
804,
297,
13936,
395,
267,
661,
66,
54,
20,
3005,
3438,
297,
445,
41,
1438,
26184,
1766,
1772,
906,
395,
267,
661,
66,
54,
20,
15091,
10858,
297,
13936,
395,
267,
661,
66,
54,
20,
15091,
19456,
297,
13936,
395,
267,
661,
66,
54,
20,
15091,
15617,
297,
13936,
395,
272,
1622,
199,
199,
533,
19013,
7304,
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,
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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
] |
WorldViews/Spirals
|
dummyServer.py
|
1
|
2519
|
import json, time
import flask
from flask import Flask, render_template, send_file, \
jsonify, send_from_directory, request
from flask_socketio import SocketIO, emit
rdb = None
try:
import rethinkdb as rdb
#rdb.connect('localhost', 28015).repl()
conn = rdb.connect(db='test')
except:
print "*** Running without DB ***"
rdb = None
app = Flask(__name__, static_url_path='')
app.debug = True
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@app.route('/')
def index():
return send_file('index.html')
@app.route('/regp/', methods=['POST','GET'])
def reg():
print "reg path:", request.path
print "reg args", request.args
t = time.time()
name = request.args.get('name')
tagStr = request.args.get('tagStr')
clientType = request.args.get('clientType')
lon = float(request.args.get('longitude'))
lat = float(request.args.get('latitude'))
room = request.args.get('room')
numUsers = int(request.args.get('numUsers'))
obj = {'t': t, 'name': name, 'tagStr': tagStr,
'lon': lon, 'lat': lat, 'room': room,
'numUsers': numUsers, 'clientType': clientType}
print obj
return "ok"
@app.route('/Viewer/<path:path>')
def send(path):
print "send_page", path
return send_from_directory('Viewer', path)
@app.route('/Cesium/<path:path>')
def send_page(path):
print "send_page", path
return send_from_directory('Cesium', path)
@app.route('/db/<path:etype>')
def query(etype):
#print "query", etype
t = time.time()
if rdb == None:
return flask.jsonify({'error': 'No DB', 't': t, 'records': []})
recs = rdb.table(etype).run(conn)
items = [x for x in recs]
obj = {'type': etype,
't' : t,
'records': items}
return flask.jsonify(obj)
@socketio.on('my event')
def test_message(message):
emit('my response', {'data': 'got it!'})
@socketio.on('chat')
def handle_chat(msg):
print "handle_chat:", msg
emit('chat', msg, broadcast=True)
addMsg(msg, 'chat')
@socketio.on('notes')
def handle_notes(msg):
print "handle_notes:", msg
emit('notes', msg, broadcast=True)
addMsg(msg, 'notes')
@socketio.on('people')
def handle_people(msg):
#print "handle_people:", msg
emit('people', msg, broadcast=True)
def addMsg(msgStr, etype):
obj = json.loads(msgStr)
rdb.table(etype).insert(obj).run(conn)
if __name__ == '__main__':
#socketio.run(app, port=80)
socketio.run(app, host="0.0.0.0", port=80)
|
mit
|
[
199,
646,
2022,
12,
900,
199,
646,
7209,
199,
504,
7209,
492,
16704,
12,
3795,
63,
1160,
12,
3222,
63,
493,
12,
971,
2116,
23819,
12,
3222,
63,
504,
63,
3619,
12,
1056,
199,
504,
7209,
63,
5096,
69,
4538,
492,
17766,
2090,
12,
8689,
199,
199,
82,
697,
275,
488,
199,
893,
26,
272,
492,
295,
29727,
697,
465,
519,
697,
272,
327,
82,
697,
14,
2242,
360,
5967,
297,
7294,
11164,
680,
16349,
342,
272,
2557,
275,
519,
697,
14,
2242,
8,
697,
534,
396,
358,
199,
2590,
26,
272,
870,
298,
9153,
26848,
1928,
6249,
1011,
12469,
272,
519,
697,
275,
488,
199,
199,
571,
275,
16704,
3460,
354,
3108,
2955,
63,
633,
63,
515,
13275,
199,
571,
14,
1757,
275,
715,
199,
571,
14,
888,
459,
12961,
63,
3078,
418,
275,
283,
4731,
11213,
199,
199,
5096,
69,
4538,
275,
17766,
2090,
8,
571,
9,
199,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
837,
272,
372,
3222,
63,
493,
360,
1080,
14,
1360,
358,
199,
199,
32,
571,
14,
4449,
2336,
1135,
80,
3678,
3102,
2968,
4030,
1673,
2970,
1105,
199,
318,
1295,
837,
272,
870,
298,
1135,
931,
6783,
1056,
14,
515,
272,
870,
298,
1135,
1249,
401,
1056,
14,
589,
272,
307,
275,
900,
14,
521,
342,
272,
536,
275,
1056,
14,
589,
14,
362,
360,
354,
358,
272,
1947,
2848,
275,
1056,
14,
589,
14,
362,
360,
1450,
2848,
358,
272,
1890,
804,
275,
1056,
14,
589,
14,
362,
360,
1258,
804,
358,
272,
6132,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13803,
1333,
272,
8396,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13331,
1333,
272,
14726,
275,
1056,
14,
589,
14,
362,
360,
11245,
358,
272,
1967,
12117,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
1507,
12117,
1333,
272,
1559,
275,
791,
84,
356,
307,
12,
283,
354,
356,
536,
12,
283,
1450,
2848,
356,
1947,
2848,
12,
1779,
283,
5298,
356,
6132,
12,
283,
4452,
356,
8396,
12,
283,
11245,
356,
14726,
12,
1779,
283,
1507,
12117,
356,
1967,
12117,
12,
283,
1258,
804,
356,
1890,
804,
93,
272,
870,
1559,
272,
372,
298,
745,
2,
199,
199,
32,
571,
14,
4449,
2336,
22347,
8316,
515,
26,
515,
5971,
199,
318,
3222,
8,
515,
304,
272,
870,
298,
2254,
63,
1606,
401,
931,
272,
372,
3222,
63,
504,
63,
3619,
360,
22347,
297,
931,
9,
199,
199,
32,
571,
14,
4449,
2336,
24417,
338,
453,
8316,
515,
26,
515,
5971,
199,
318,
3222,
63,
1606,
8,
515,
304,
272,
870,
298,
2254,
63,
1606,
401,
931,
272,
372,
3222,
63,
504,
63,
3619,
360,
24417,
338,
453,
297,
931,
9,
199,
199,
32,
571,
14,
4449,
2336,
697,
8316,
515,
26,
29232,
5971,
199,
318,
1827,
8,
29232,
304,
272,
327,
1361,
298,
1131,
401,
30527,
272,
307,
275,
900,
14,
521,
342,
272,
340,
519,
697,
508,
488,
26,
267,
372,
7209,
14,
1001,
2021,
3252,
705,
356,
283,
1944,
6249,
297,
283,
84,
356,
307,
12,
283,
6502,
356,
942,
1552,
272,
26399,
275,
519,
697,
14,
1224,
8,
29232,
680,
1065,
8,
1631,
9,
272,
2974,
275,
359,
88,
367,
671,
315,
26399,
61,
272,
1559,
275,
791,
466,
356,
30527,
12,
1779,
283,
84,
7,
520,
307,
12,
1779,
283,
6502,
356,
2974,
93,
272,
372,
7209,
14,
1001,
2021,
8,
1113,
9,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
1662,
1566,
358,
199,
318,
511,
63,
1188,
8,
1188,
304,
272,
8689,
360,
1662,
1177,
297,
791,
576,
356,
283,
7808,
652,
1,
3071,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
10289,
358,
199,
318,
2429,
63,
10289,
8,
1328,
304,
272,
870,
298,
2479,
63,
10289,
6783,
1499,
272,
8689,
360,
10289,
297,
1499,
12,
11180,
29,
549,
9,
272,
1050,
6173,
8,
1328,
12,
283,
10289,
358,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
5983,
358,
199,
318,
2429,
63,
5983,
8,
1328,
304,
272,
870,
298,
2479,
63,
5983,
6783,
1499,
272,
8689,
360,
5983,
297,
1499,
12,
11180,
29,
549,
9,
272,
1050,
6173,
8,
1328,
12,
283,
5983,
358,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
13562,
358,
199,
318,
2429,
63,
13562,
8,
1328,
304,
272,
327,
1361,
298,
2479,
63,
13562,
6783,
1499,
272,
8689,
360,
13562,
297,
1499,
12,
11180,
29,
549,
9,
199,
199,
318,
1050,
6173,
8,
1328,
2848,
12,
30527,
304,
272,
1559,
275,
2022,
14,
3640,
8,
1328,
2848,
9,
272,
519,
697,
14,
1224,
8,
29232,
680,
3176,
8,
1113,
680,
1065,
8,
1631,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
5096,
69,
4538,
14,
1065,
8,
571,
12,
1844,
29,
1257,
9,
272,
6771,
69,
4538,
14,
1065,
8,
571,
12,
1591,
628,
16,
14,
16,
14,
16,
14,
16,
401,
1844,
29,
1257,
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
] |
[
646,
2022,
12,
900,
199,
646,
7209,
199,
504,
7209,
492,
16704,
12,
3795,
63,
1160,
12,
3222,
63,
493,
12,
971,
2116,
23819,
12,
3222,
63,
504,
63,
3619,
12,
1056,
199,
504,
7209,
63,
5096,
69,
4538,
492,
17766,
2090,
12,
8689,
199,
199,
82,
697,
275,
488,
199,
893,
26,
272,
492,
295,
29727,
697,
465,
519,
697,
272,
327,
82,
697,
14,
2242,
360,
5967,
297,
7294,
11164,
680,
16349,
342,
272,
2557,
275,
519,
697,
14,
2242,
8,
697,
534,
396,
358,
199,
2590,
26,
272,
870,
298,
9153,
26848,
1928,
6249,
1011,
12469,
272,
519,
697,
275,
488,
199,
199,
571,
275,
16704,
3460,
354,
3108,
2955,
63,
633,
63,
515,
13275,
199,
571,
14,
1757,
275,
715,
199,
571,
14,
888,
459,
12961,
63,
3078,
418,
275,
283,
4731,
11213,
199,
199,
5096,
69,
4538,
275,
17766,
2090,
8,
571,
9,
199,
199,
32,
571,
14,
4449,
7825,
199,
318,
1478,
837,
272,
372,
3222,
63,
493,
360,
1080,
14,
1360,
358,
199,
199,
32,
571,
14,
4449,
2336,
1135,
80,
3678,
3102,
2968,
4030,
1673,
2970,
1105,
199,
318,
1295,
837,
272,
870,
298,
1135,
931,
6783,
1056,
14,
515,
272,
870,
298,
1135,
1249,
401,
1056,
14,
589,
272,
307,
275,
900,
14,
521,
342,
272,
536,
275,
1056,
14,
589,
14,
362,
360,
354,
358,
272,
1947,
2848,
275,
1056,
14,
589,
14,
362,
360,
1450,
2848,
358,
272,
1890,
804,
275,
1056,
14,
589,
14,
362,
360,
1258,
804,
358,
272,
6132,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13803,
1333,
272,
8396,
275,
2069,
8,
1069,
14,
589,
14,
362,
360,
13331,
1333,
272,
14726,
275,
1056,
14,
589,
14,
362,
360,
11245,
358,
272,
1967,
12117,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
1507,
12117,
1333,
272,
1559,
275,
791,
84,
356,
307,
12,
283,
354,
356,
536,
12,
283,
1450,
2848,
356,
1947,
2848,
12,
1779,
283,
5298,
356,
6132,
12,
283,
4452,
356,
8396,
12,
283,
11245,
356,
14726,
12,
1779,
283,
1507,
12117,
356,
1967,
12117,
12,
283,
1258,
804,
356,
1890,
804,
93,
272,
870,
1559,
272,
372,
298,
745,
2,
199,
199,
32,
571,
14,
4449,
2336,
22347,
8316,
515,
26,
515,
5971,
199,
318,
3222,
8,
515,
304,
272,
870,
298,
2254,
63,
1606,
401,
931,
272,
372,
3222,
63,
504,
63,
3619,
360,
22347,
297,
931,
9,
199,
199,
32,
571,
14,
4449,
2336,
24417,
338,
453,
8316,
515,
26,
515,
5971,
199,
318,
3222,
63,
1606,
8,
515,
304,
272,
870,
298,
2254,
63,
1606,
401,
931,
272,
372,
3222,
63,
504,
63,
3619,
360,
24417,
338,
453,
297,
931,
9,
199,
199,
32,
571,
14,
4449,
2336,
697,
8316,
515,
26,
29232,
5971,
199,
318,
1827,
8,
29232,
304,
272,
327,
1361,
298,
1131,
401,
30527,
272,
307,
275,
900,
14,
521,
342,
272,
340,
519,
697,
508,
488,
26,
267,
372,
7209,
14,
1001,
2021,
3252,
705,
356,
283,
1944,
6249,
297,
283,
84,
356,
307,
12,
283,
6502,
356,
942,
1552,
272,
26399,
275,
519,
697,
14,
1224,
8,
29232,
680,
1065,
8,
1631,
9,
272,
2974,
275,
359,
88,
367,
671,
315,
26399,
61,
272,
1559,
275,
791,
466,
356,
30527,
12,
1779,
283,
84,
7,
520,
307,
12,
1779,
283,
6502,
356,
2974,
93,
272,
372,
7209,
14,
1001,
2021,
8,
1113,
9,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
1662,
1566,
358,
199,
318,
511,
63,
1188,
8,
1188,
304,
272,
8689,
360,
1662,
1177,
297,
791,
576,
356,
283,
7808,
652,
1,
3071,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
10289,
358,
199,
318,
2429,
63,
10289,
8,
1328,
304,
272,
870,
298,
2479,
63,
10289,
6783,
1499,
272,
8689,
360,
10289,
297,
1499,
12,
11180,
29,
549,
9,
272,
1050,
6173,
8,
1328,
12,
283,
10289,
358,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
5983,
358,
199,
318,
2429,
63,
5983,
8,
1328,
304,
272,
870,
298,
2479,
63,
5983,
6783,
1499,
272,
8689,
360,
5983,
297,
1499,
12,
11180,
29,
549,
9,
272,
1050,
6173,
8,
1328,
12,
283,
5983,
358,
199,
199,
32,
5096,
69,
4538,
14,
265,
360,
13562,
358,
199,
318,
2429,
63,
13562,
8,
1328,
304,
272,
327,
1361,
298,
2479,
63,
13562,
6783,
1499,
272,
8689,
360,
13562,
297,
1499,
12,
11180,
29,
549,
9,
199,
199,
318,
1050,
6173,
8,
1328,
2848,
12,
30527,
304,
272,
1559,
275,
2022,
14,
3640,
8,
1328,
2848,
9,
272,
519,
697,
14,
1224,
8,
29232,
680,
3176,
8,
1113,
680,
1065,
8,
1631,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
5096,
69,
4538,
14,
1065,
8,
571,
12,
1844,
29,
1257,
9,
272,
6771,
69,
4538,
14,
1065,
8,
571,
12,
1591,
628,
16,
14,
16,
14,
16,
14,
16,
401,
1844,
29,
1257,
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,
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
] |
jedie/bootstrap_env
|
bootstrap_env/admin_shell/normal_shell.py
|
1
|
7715
|
"""
Admin Shell commands available in 'normal' install mode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORTANT:
Every import from external packages must be made with LazyImportError!
Otherwise the bootstrap will fail, because no external package is
available in bootstrap process!
:created: 03.2018 by Jens Diemer, www.jensdiemer.de
:copyleft: 2018 by the bootstrap_env team, see AUTHORS for more details.
:license: GNU General Public License v3 or later (GPLv3+), see LICENSE for more details.
"""
import os
import sys
from pathlib import Path
# Bootstrap-Env
from bootstrap_env.boot_bootstrap_env import Cmd2, VerboseSubprocess, __version__, get_pip_file_name, in_virtualenv
from bootstrap_env.utils.import_utils import LazyImportError
from bootstrap_env.version import __version__ as bootstrap_env_version
# External libs:
try:
from cookiecutter.main import cookiecutter
except ImportError as err:
# Re-Raise ImportError on first usage
cookiecutter = LazyImportError(err)
class AdminShell(Cmd2):
"""
Normal user commands.
Only this commands are available in 'normal' installation mode.
"""
version = __version__
def __init__(self, path_helper, *args, **kwargs):
self.path_helper = path_helper # bootstrap_env.admin_shell.path_helper.PathHelper instance
super().__init__(*args, **kwargs)
def get_pip3_path(self):
if not in_virtualenv():
self.stdout.write("\nERROR: Only allowed in activated virtualenv!\n\n")
return
if sys.platform == 'win32':
bin_dir_name="Scripts"
else:
bin_dir_name = "bin"
pip3_path = Path(sys.prefix, bin_dir_name, get_pip_file_name()) # e.g.: .../bin/pip3
if not pip3_path.is_file():
print("ERROR: pip not found here: '%s'" % pip3_path)
return
print("pip found here: '%s'" % pip3_path)
return pip3_path
def do_install_test_requirements(self, arg=None):
"""
Install packages to run tests
"""
pip3_path = self.get_pip3_path()
VerboseSubprocess(
str(pip3_path), "install", "-r", str(self.path_helper.test_req_path)
).verbose_call(check=True) # Exit on error
def do_pytest(self, arg=None):
"""
Run tests via pytest
"""
try:
import pytest
except ImportError as err:
print("ERROR: Can't import pytest: %s (pytest not installed, in normal installation!)" % err)
else:
root_path = str(self.path_helper.base)
print("chdir %r" % root_path)
os.chdir(root_path)
args = sys.argv[2:]
print("Call Pytest with args: %s" % repr(args))
exit_code = pytest.main(args=args)
sys.exit(exit_code)
def do_pip_freeze(self, arg=None):
"""
Just run 'pip freeze'
"""
return_code = VerboseSubprocess("pip3", "freeze").verbose_call(check=False)
def do_update_env(self, arg=None):
"""
Update all packages in virtualenv.
(Call this command only in a activated virtualenv.)
"""
pip3_path = str(self.get_pip3_path())
# Upgrade pip first:
if sys.platform == 'win32':
# Note: On windows it will crash with a PermissionError: [WinError 32]
# because pip can't replace himself while running ;)
# Work-a-round is "python -m pip install --upgrade pip"
# see also: https://github.com/pypa/pip/issues/3804
return_code = VerboseSubprocess(
sys.executable or "python",
"-m", "pip", "install", "--upgrade", "pip",
).verbose_call(check=False)
else:
return_code = VerboseSubprocess(
pip3_path, "install", "--upgrade", "pip"
).verbose_call(check=False)
root_path = self.path_helper.base.parent
# Update the requirements files by...
if self.path_helper.normal_mode:
# ... update 'bootstrap_env' PyPi package
return_code = VerboseSubprocess(
pip3_path, "install", "--upgrade", self.path_helper.egg_name
).verbose_call(check=False)
else:
# ... git pull bootstrap_env sources
return_code = VerboseSubprocess(
"git", "pull", "origin",
cwd=str(root_path)
).verbose_call(check=False)
return_code = VerboseSubprocess(
pip3_path, "install", "--editable", ".",
cwd=str(root_path)
).verbose_call(check=False)
requirement_file_path = str(self.path_helper.req_filepath)
# Update with requirements files:
self.stdout.write("Use: '%s'\n" % requirement_file_path)
return_code = VerboseSubprocess(
pip3_path, "install",
"--exists-action", "b", # action when a path already exists: (b)ackup
"--upgrade",
"--requirement", requirement_file_path,
timeout=120 # extended timeout for slow Travis ;)
).verbose_call(check=False)
self.stdout.write("Please restart %s\n" % self.self_filename)
sys.exit(0)
def do_pip_sync(self, arg=None):
"""
run pip-sync (use with care)
pip-sync will install/upgrade/uninstall everything necessary to match the requirements.txt contents.
Be careful: pip-sync is meant to be used only with a requirements.txt generated by pip-compile!
"""
if self.path_helper.egg_name == "bootstrap_env":
print("ERROR: command not allowed for 'bootstrap_env' !\n")
print(
"bootstrap_env doesn't use pip-compile,"
" because Bootstrap-env should be used as a tool in other projects"
" and the projects himself should pin requirements ;) "
)
return
# Run pip-sync only in developer mode
return_code = VerboseSubprocess(
"pip-sync", str(self.path_helper.req_filepath),
cwd=str(self.path_helper.base.parent)
).verbose_call(check=False)
self.stdout.write("Please restart %s\n" % self.self_filename)
sys.exit(0)
def complete_generate_bootstrap(self, text, line, begidx, endidx):
# print("text: %r" % text)
# print("line: %r" % line)
return self._complete_path(text, line, begidx, endidx)
def confirm(self, txt, confirm_values=("y", "j")):
if input("\n%s" % txt).lower() in confirm_values:
return True
return False
def do_generate_bootstrap(self, arg=None):
"""
Generate new bootstrap file via cookiecutter
direct call, e.g.:
bootstrap_env_admin.py generate_bootstrap ~/new_project
"""
if not arg:
print("INFO: No output path given.")
output_dir = Path(arg).expanduser().resolve()
if output_dir.is_dir():
print("Create bootstrap file in: %s" % output_dir)
print("ERROR: output path already exists!")
return
txt = "Create bootstrap file in: %s ? [Y/N]" % output_dir
if not self.confirm(txt):
print("Abort.")
return
repro_path = Path(self.package_path, "boot_source")
result = cookiecutter(
template=str(repro_path),
output_dir=str(output_dir),
extra_context={
"_version": bootstrap_env_version,
}
)
print("bootstrap file created here: %s" % result)
|
gpl-3.0
|
[
199,
624,
272,
9516,
24599,
3718,
2808,
315,
283,
3302,
7,
3907,
818,
272,
18294,
30642,
2878,
23597,
339,
5025,
2596,
1441,
26,
267,
18414,
492,
687,
5957,
6117,
1471,
506,
6326,
543,
22373,
17825,
1,
267,
6630,
314,
15865,
911,
2449,
12,
2952,
949,
5957,
2559,
365,
267,
2808,
315,
15865,
2112,
1,
339,
520,
3966,
26,
30569,
14,
12682,
701,
1603,
8764,
577,
1873,
2626,
12,
20732,
14,
74,
8764,
15130,
2626,
14,
271,
272,
520,
1574,
3039,
26,
14894,
701,
314,
15865,
63,
1813,
8099,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
1664,
1696,
1684,
844,
373,
19,
503,
2945,
334,
28863,
19,
11,
395,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
504,
32212,
492,
6912,
199,
199,
3,
27324,
7868,
13,
7744,
199,
504,
15865,
63,
1813,
14,
4930,
63,
11146,
63,
1813,
492,
26005,
18,
12,
5444,
2220,
22299,
12,
636,
1023,
3108,
664,
63,
9983,
63,
493,
63,
354,
12,
315,
63,
21611,
199,
504,
15865,
63,
1813,
14,
1208,
14,
646,
63,
1208,
492,
22373,
17825,
199,
504,
15865,
63,
1813,
14,
1023,
492,
636,
1023,
363,
465,
15865,
63,
1813,
63,
1023,
199,
199,
3,
18802,
20314,
26,
199,
893,
26,
272,
687,
512,
745,
73,
825,
18404,
14,
973,
492,
512,
745,
73,
825,
18404,
199,
2590,
3545,
465,
2329,
26,
272,
327,
799,
13,
18111,
3545,
641,
1642,
4503,
272,
512,
745,
73,
825,
18404,
275,
22373,
17825,
8,
1508,
9,
4388,
199,
533,
9516,
8529,
8,
7874,
18,
304,
272,
408,
272,
11514,
922,
3718,
14,
272,
5972,
642,
3718,
787,
2808,
315,
283,
3302,
7,
12096,
818,
14,
272,
408,
272,
1015,
275,
636,
1023,
363,
339,
347,
636,
826,
721,
277,
12,
931,
63,
3676,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
515,
63,
3676,
275,
931,
63,
3676,
327,
15865,
63,
1813,
14,
2113,
63,
5641,
14,
515,
63,
3676,
14,
2042,
4433,
1256,
398,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
9983,
19,
63,
515,
8,
277,
304,
267,
340,
440,
315,
63,
21611,
837,
288,
291,
14,
2703,
14,
952,
4582,
78,
3170,
26,
5972,
4370,
315,
22225,
19128,
12525,
78,
60,
78,
531,
288,
372,
398,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
2517,
63,
694,
63,
354,
628,
25681,
2,
267,
587,
26,
288,
2517,
63,
694,
63,
354,
275,
298,
1393,
2,
398,
7305,
19,
63,
515,
275,
6912,
8,
1274,
14,
1861,
12,
2517,
63,
694,
63,
354,
12,
664,
63,
9983,
63,
493,
63,
354,
1012,
327,
325,
14,
71,
16781,
2263,
15,
1393,
15,
9983,
19,
267,
340,
440,
7305,
19,
63,
515,
14,
374,
63,
493,
837,
288,
870,
480,
3170,
26,
7305,
440,
1911,
2348,
26,
1543,
83,
4065,
450,
7305,
19,
63,
515,
9,
288,
372,
398,
870,
480,
9983,
1911,
2348,
26,
1543,
83,
4065,
450,
7305,
19,
63,
515,
9,
267,
372,
7305,
19,
63,
515,
339,
347,
886,
63,
3174,
63,
396,
63,
7538,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
13276,
6117,
370,
1255,
2295,
267,
408,
267,
7305,
19,
63,
515,
275,
291,
14,
362,
63,
9983,
19,
63,
515,
342,
267,
5444,
2220,
22299,
8,
288,
620,
8,
9983,
19,
63,
515,
395,
298,
3174,
401,
3905,
82,
401,
620,
8,
277,
14,
515,
63,
3676,
14,
396,
63,
2103,
63,
515,
9,
267,
7092,
3832,
63,
1250,
8,
1074,
29,
549,
9,
327,
18704,
641,
1125,
339,
347,
886,
63,
4462,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
3378,
2295,
4799,
4613,
267,
408,
267,
862,
26,
288,
492,
4613,
267,
871,
3545,
465,
2329,
26,
288,
870,
480,
3170,
26,
6855,
1133,
492,
4613,
26,
450,
83,
334,
4462,
440,
4903,
12,
315,
3293,
12096,
1,
2924,
450,
2329,
9,
267,
587,
26,
288,
1738,
63,
515,
275,
620,
8,
277,
14,
515,
63,
3676,
14,
1095,
9,
288,
870,
480,
8563,
450,
82,
2,
450,
1738,
63,
515,
9,
288,
747,
14,
8563,
8,
1231,
63,
515,
9,
953,
1249,
275,
984,
14,
3020,
59,
18,
2938,
288,
870,
480,
2176,
1611,
396,
543,
1249,
26,
450,
83,
2,
450,
4700,
8,
589,
430,
288,
4458,
63,
600,
275,
4613,
14,
973,
8,
589,
29,
589,
9,
288,
984,
14,
2224,
8,
2224,
63,
600,
9,
339,
347,
886,
63,
9983,
63,
18459,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
13870,
1255,
283,
9983,
22778,
7,
267,
408,
267,
372,
63,
600,
275,
5444,
2220,
22299,
480,
9983,
19,
401,
298,
18459,
3471,
3832,
63,
1250,
8,
1074,
29,
797,
9,
339,
347,
886,
63,
873,
63,
1813,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
6162,
1006,
6117,
315,
19128,
14,
398,
334,
2176,
642,
1414,
1454,
315,
282,
22225,
19128,
4959,
267,
408,
267,
7305,
19,
63,
515,
275,
620,
8,
277,
14,
362,
63,
9983,
19,
63,
515,
1012,
398,
327,
4949,
4523,
7305,
1642,
26,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
327,
3390,
26,
4068,
10061,
652,
911,
12420,
543,
282,
8779,
547,
26,
359,
8886,
547,
4337,
61,
288,
327,
2952,
7305,
883,
1133,
3350,
26457,
277,
1830,
3879,
8700,
9,
288,
327,
9361,
13,
65,
13,
2363,
365,
298,
1548,
446,
77,
7305,
3907,
1553,
9375,
7305,
2,
288,
327,
1937,
2597,
26,
4178,
921,
5031,
14,
957,
15,
647,
387,
15,
9983,
15,
10115,
15,
1703,
966,
288,
372,
63,
600,
275,
5444,
2220,
22299,
8,
355,
984,
14,
5904,
503,
298,
1548,
401,
355,
3905,
77,
401,
298,
9983,
401,
298,
3174,
401,
4320,
9375,
401,
298,
9983,
401,
288,
7092,
3832,
63,
1250,
8,
1074,
29,
797,
9,
267,
587,
26,
288,
372,
63,
600,
275,
5444,
2220,
22299,
8,
355,
7305,
19,
63,
515,
12,
298,
3174,
401,
4320,
9375,
401,
298,
9983,
2,
288,
7092,
3832,
63,
1250,
8,
1074,
29,
797,
9,
398,
1738,
63,
515,
275,
291,
14,
515,
63,
3676,
14,
1095,
14,
1708,
398
] |
[
624,
272,
9516,
24599,
3718,
2808,
315,
283,
3302,
7,
3907,
818,
272,
18294,
30642,
2878,
23597,
339,
5025,
2596,
1441,
26,
267,
18414,
492,
687,
5957,
6117,
1471,
506,
6326,
543,
22373,
17825,
1,
267,
6630,
314,
15865,
911,
2449,
12,
2952,
949,
5957,
2559,
365,
267,
2808,
315,
15865,
2112,
1,
339,
520,
3966,
26,
30569,
14,
12682,
701,
1603,
8764,
577,
1873,
2626,
12,
20732,
14,
74,
8764,
15130,
2626,
14,
271,
272,
520,
1574,
3039,
26,
14894,
701,
314,
15865,
63,
1813,
8099,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
1664,
1696,
1684,
844,
373,
19,
503,
2945,
334,
28863,
19,
11,
395,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
504,
32212,
492,
6912,
199,
199,
3,
27324,
7868,
13,
7744,
199,
504,
15865,
63,
1813,
14,
4930,
63,
11146,
63,
1813,
492,
26005,
18,
12,
5444,
2220,
22299,
12,
636,
1023,
3108,
664,
63,
9983,
63,
493,
63,
354,
12,
315,
63,
21611,
199,
504,
15865,
63,
1813,
14,
1208,
14,
646,
63,
1208,
492,
22373,
17825,
199,
504,
15865,
63,
1813,
14,
1023,
492,
636,
1023,
363,
465,
15865,
63,
1813,
63,
1023,
199,
199,
3,
18802,
20314,
26,
199,
893,
26,
272,
687,
512,
745,
73,
825,
18404,
14,
973,
492,
512,
745,
73,
825,
18404,
199,
2590,
3545,
465,
2329,
26,
272,
327,
799,
13,
18111,
3545,
641,
1642,
4503,
272,
512,
745,
73,
825,
18404,
275,
22373,
17825,
8,
1508,
9,
4388,
199,
533,
9516,
8529,
8,
7874,
18,
304,
272,
408,
272,
11514,
922,
3718,
14,
272,
5972,
642,
3718,
787,
2808,
315,
283,
3302,
7,
12096,
818,
14,
272,
408,
272,
1015,
275,
636,
1023,
363,
339,
347,
636,
826,
721,
277,
12,
931,
63,
3676,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
515,
63,
3676,
275,
931,
63,
3676,
327,
15865,
63,
1813,
14,
2113,
63,
5641,
14,
515,
63,
3676,
14,
2042,
4433,
1256,
398,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
664,
63,
9983,
19,
63,
515,
8,
277,
304,
267,
340,
440,
315,
63,
21611,
837,
288,
291,
14,
2703,
14,
952,
4582,
78,
3170,
26,
5972,
4370,
315,
22225,
19128,
12525,
78,
60,
78,
531,
288,
372,
398,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
2517,
63,
694,
63,
354,
628,
25681,
2,
267,
587,
26,
288,
2517,
63,
694,
63,
354,
275,
298,
1393,
2,
398,
7305,
19,
63,
515,
275,
6912,
8,
1274,
14,
1861,
12,
2517,
63,
694,
63,
354,
12,
664,
63,
9983,
63,
493,
63,
354,
1012,
327,
325,
14,
71,
16781,
2263,
15,
1393,
15,
9983,
19,
267,
340,
440,
7305,
19,
63,
515,
14,
374,
63,
493,
837,
288,
870,
480,
3170,
26,
7305,
440,
1911,
2348,
26,
1543,
83,
4065,
450,
7305,
19,
63,
515,
9,
288,
372,
398,
870,
480,
9983,
1911,
2348,
26,
1543,
83,
4065,
450,
7305,
19,
63,
515,
9,
267,
372,
7305,
19,
63,
515,
339,
347,
886,
63,
3174,
63,
396,
63,
7538,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
13276,
6117,
370,
1255,
2295,
267,
408,
267,
7305,
19,
63,
515,
275,
291,
14,
362,
63,
9983,
19,
63,
515,
342,
267,
5444,
2220,
22299,
8,
288,
620,
8,
9983,
19,
63,
515,
395,
298,
3174,
401,
3905,
82,
401,
620,
8,
277,
14,
515,
63,
3676,
14,
396,
63,
2103,
63,
515,
9,
267,
7092,
3832,
63,
1250,
8,
1074,
29,
549,
9,
327,
18704,
641,
1125,
339,
347,
886,
63,
4462,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
3378,
2295,
4799,
4613,
267,
408,
267,
862,
26,
288,
492,
4613,
267,
871,
3545,
465,
2329,
26,
288,
870,
480,
3170,
26,
6855,
1133,
492,
4613,
26,
450,
83,
334,
4462,
440,
4903,
12,
315,
3293,
12096,
1,
2924,
450,
2329,
9,
267,
587,
26,
288,
1738,
63,
515,
275,
620,
8,
277,
14,
515,
63,
3676,
14,
1095,
9,
288,
870,
480,
8563,
450,
82,
2,
450,
1738,
63,
515,
9,
288,
747,
14,
8563,
8,
1231,
63,
515,
9,
953,
1249,
275,
984,
14,
3020,
59,
18,
2938,
288,
870,
480,
2176,
1611,
396,
543,
1249,
26,
450,
83,
2,
450,
4700,
8,
589,
430,
288,
4458,
63,
600,
275,
4613,
14,
973,
8,
589,
29,
589,
9,
288,
984,
14,
2224,
8,
2224,
63,
600,
9,
339,
347,
886,
63,
9983,
63,
18459,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
13870,
1255,
283,
9983,
22778,
7,
267,
408,
267,
372,
63,
600,
275,
5444,
2220,
22299,
480,
9983,
19,
401,
298,
18459,
3471,
3832,
63,
1250,
8,
1074,
29,
797,
9,
339,
347,
886,
63,
873,
63,
1813,
8,
277,
12,
1680,
29,
403,
304,
267,
408,
267,
6162,
1006,
6117,
315,
19128,
14,
398,
334,
2176,
642,
1414,
1454,
315,
282,
22225,
19128,
4959,
267,
408,
267,
7305,
19,
63,
515,
275,
620,
8,
277,
14,
362,
63,
9983,
19,
63,
515,
1012,
398,
327,
4949,
4523,
7305,
1642,
26,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
288,
327,
3390,
26,
4068,
10061,
652,
911,
12420,
543,
282,
8779,
547,
26,
359,
8886,
547,
4337,
61,
288,
327,
2952,
7305,
883,
1133,
3350,
26457,
277,
1830,
3879,
8700,
9,
288,
327,
9361,
13,
65,
13,
2363,
365,
298,
1548,
446,
77,
7305,
3907,
1553,
9375,
7305,
2,
288,
327,
1937,
2597,
26,
4178,
921,
5031,
14,
957,
15,
647,
387,
15,
9983,
15,
10115,
15,
1703,
966,
288,
372,
63,
600,
275,
5444,
2220,
22299,
8,
355,
984,
14,
5904,
503,
298,
1548,
401,
355,
3905,
77,
401,
298,
9983,
401,
298,
3174,
401,
4320,
9375,
401,
298,
9983,
401,
288,
7092,
3832,
63,
1250,
8,
1074,
29,
797,
9,
267,
587,
26,
288,
372,
63,
600,
275,
5444,
2220,
22299,
8,
355,
7305,
19,
63,
515,
12,
298,
3174,
401,
4320,
9375,
401,
298,
9983,
2,
288,
7092,
3832,
63,
1250,
8,
1074,
29,
797,
9,
398,
1738,
63,
515,
275,
291,
14,
515,
63,
3676,
14,
1095,
14,
1708,
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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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
] |
fitoria/askbot-devel
|
askbot/migrations/0162_auto__add_field_post_language_code.py
|
14
|
35079
|
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Post.language_code'
db.add_column('askbot_post', 'language_code', self.gf('django.db.models.fields.CharField')(default='en', max_length=16), keep_default=False)
def backwards(self, orm):
# Deleting field 'Post.language_code'
db.delete_column('askbot_post', 'language_code')
models = {
'askbot.activity': {
'Meta': {'object_name': 'Activity', 'db_table': "u'activity'"},
'active_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'activity_type': ('django.db.models.fields.SmallIntegerField', [], {}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_auditted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
'question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Post']", 'null': 'True'}),
'receiving_users': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'received_activity'", 'symmetrical': 'False', 'to': "orm['auth.User']"}),
'recipients': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'incoming_activity'", 'symmetrical': 'False', 'through': "orm['askbot.ActivityAuditStatus']", 'to': "orm['auth.User']"}),
'summary': ('django.db.models.fields.TextField', [], {'default': "''"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'askbot.activityauditstatus': {
'Meta': {'unique_together': "(('user', 'activity'),)", 'object_name': 'ActivityAuditStatus'},
'activity': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Activity']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'status': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'askbot.anonymousanswer': {
'Meta': {'object_name': 'AnonymousAnswer'},
'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ip_addr': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'anonymous_answers'", 'to': "orm['askbot.Post']"}),
'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
'text': ('django.db.models.fields.TextField', [], {}),
'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'askbot.anonymousquestion': {
'Meta': {'object_name': 'AnonymousQuestion'},
'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ip_addr': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
'is_anonymous': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}),
'text': ('django.db.models.fields.TextField', [], {}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'askbot.askwidget': {
'Meta': {'object_name': 'AskWidget'},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Group']", 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'include_text_field': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'inner_style': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'outer_style': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'tag': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Tag']", 'null': 'True', 'blank': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'askbot.award': {
'Meta': {'object_name': 'Award', 'db_table': "u'award'"},
'awarded_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'badge': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award_badge'", 'to': "orm['askbot.BadgeData']"}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'notified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award_user'", 'to': "orm['auth.User']"})
},
'askbot.badgedata': {
'Meta': {'ordering': "('slug',)", 'object_name': 'BadgeData'},
'awarded_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'awarded_to': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'badges'", 'symmetrical': 'False', 'through': "orm['askbot.Award']", 'to': "orm['auth.User']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'})
},
'askbot.bulktagsubscription': {
'Meta': {'ordering': "['-date_added']", 'object_name': 'BulkTagSubscription'},
'date_added': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['askbot.Group']", 'symmetrical': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['askbot.Tag']", 'symmetrical': 'False'}),
'users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False'})
},
'askbot.draftanswer': {
'Meta': {'object_name': 'DraftAnswer'},
'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'draft_answers'", 'to': "orm['auth.User']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'text': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'thread': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'draft_answers'", 'to': "orm['askbot.Thread']"})
},
'askbot.draftquestion': {
'Meta': {'object_name': 'DraftQuestion'},
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125', 'null': 'True'}),
'text': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '300', 'null': 'True'})
},
'askbot.emailfeedsetting': {
'Meta': {'unique_together': "(('subscriber', 'feed_type'),)", 'object_name': 'EmailFeedSetting'},
'added_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'feed_type': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'frequency': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '8'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'reported_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'subscriber': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'notification_subscriptions'", 'to': "orm['auth.User']"})
},
'askbot.favoritequestion': {
'Meta': {'object_name': 'FavoriteQuestion', 'db_table': "u'favorite_question'"},
'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'thread': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Thread']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'user_favorite_questions'", 'to': "orm['auth.User']"})
},
'askbot.group': {
'Meta': {'object_name': 'Group', '_ormbases': ['auth.Group']},
'description': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'related_name': "'described_group'", 'unique': 'True', 'null': 'True', 'to': "orm['askbot.Post']"}),
'group_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.Group']", 'unique': 'True', 'primary_key': 'True'}),
'is_vip': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'logo_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True'}),
'moderate_answers_to_enquirers': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'moderate_email': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'openness': ('django.db.models.fields.SmallIntegerField', [], {'default': '2'}),
'preapproved_email_domains': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'}),
'preapproved_emails': ('django.db.models.fields.TextField', [], {'default': "''", 'null': 'True', 'blank': 'True'})
},
'askbot.groupmembership': {
'Meta': {'object_name': 'GroupMembership', '_ormbases': ['auth.AuthUserGroups']},
'authusergroups_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.AuthUserGroups']", 'unique': 'True', 'primary_key': 'True'}),
'level': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'})
},
'askbot.markedtag': {
'Meta': {'object_name': 'MarkedTag'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'reason': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'user_selections'", 'to': "orm['askbot.Tag']"}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tag_selections'", 'to': "orm['auth.User']"})
},
'askbot.post': {
'Meta': {'object_name': 'Post'},
'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'approved': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['auth.User']"}),
'comment_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_posts'", 'null': 'True', 'to': "orm['auth.User']"}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'group_posts'", 'symmetrical': 'False', 'through': "orm['askbot.PostToGroup']", 'to': "orm['askbot.Group']"}),
'html': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_anonymous': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'language_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '16'}),
'last_edited_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'last_edited_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'last_edited_posts'", 'null': 'True', 'to': "orm['auth.User']"}),
'locked': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'locked_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'locked_posts'", 'null': 'True', 'to': "orm['auth.User']"}),
'offensive_flag_count': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'old_answer_id': ('django.db.models.fields.PositiveIntegerField', [], {'default': 'None', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
'old_comment_id': ('django.db.models.fields.PositiveIntegerField', [], {'default': 'None', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
'old_question_id': ('django.db.models.fields.PositiveIntegerField', [], {'default': 'None', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'comments'", 'null': 'True', 'to': "orm['askbot.Post']"}),
'points': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_column': "'score'"}),
'post_type': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'summary': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'text': ('django.db.models.fields.TextField', [], {'null': 'True'}),
'thread': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'posts'", 'null': 'True', 'blank': 'True', 'to': "orm['askbot.Thread']"}),
'vote_down_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'vote_up_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'wikified_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'})
},
'askbot.postflagreason': {
'Meta': {'object_name': 'PostFlagReason'},
'added_at': ('django.db.models.fields.DateTimeField', [], {}),
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
'details': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'post_reject_reasons'", 'to': "orm['askbot.Post']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '128'})
},
'askbot.postrevision': {
'Meta': {'ordering': "('-revision',)", 'unique_together': "(('post', 'revision'),)", 'object_name': 'PostRevision'},
'approved': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}),
'approved_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'approved_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'postrevisions'", 'to': "orm['auth.User']"}),
'by_email': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_anonymous': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'post': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'revisions'", 'null': 'True', 'to': "orm['askbot.Post']"}),
'revised_at': ('django.db.models.fields.DateTimeField', [], {}),
'revision': ('django.db.models.fields.PositiveIntegerField', [], {}),
'summary': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}),
'tagnames': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '125', 'blank': 'True'}),
'text': ('django.db.models.fields.TextField', [], {}),
'title': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '300', 'blank': 'True'})
},
'askbot.posttogroup': {
'Meta': {'unique_together': "(('post', 'group'),)", 'object_name': 'PostToGroup', 'db_table': "'askbot_post_groups'"},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Group']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'post': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Post']"})
},
'askbot.questionview': {
'Meta': {'object_name': 'QuestionView'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'viewed'", 'to': "orm['askbot.Post']"}),
'when': ('django.db.models.fields.DateTimeField', [], {}),
'who': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'question_views'", 'to': "orm['auth.User']"})
},
'askbot.questionwidget': {
'Meta': {'object_name': 'QuestionWidget'},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Group']", 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'order_by': ('django.db.models.fields.CharField', [], {'default': "'-added_at'", 'max_length': '18'}),
'question_number': ('django.db.models.fields.PositiveIntegerField', [], {'default': '7'}),
'search_query': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '50', 'null': 'True', 'blank': 'True'}),
'style': ('django.db.models.fields.TextField', [], {'default': '"\\n@import url(\'http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300,400,700\');\\nbody {\\n overflow: hidden;\\n}\\n\\n#container {\\n width: 200px;\\n height: 350px;\\n}\\nul {\\n list-style: none;\\n padding: 5px;\\n margin: 5px;\\n}\\nli {\\n border-bottom: #CCC 1px solid;\\n padding-bottom: 5px;\\n padding-top: 5px;\\n}\\nli:last-child {\\n border: none;\\n}\\na {\\n text-decoration: none;\\n color: #464646;\\n font-family: \'Yanone Kaffeesatz\', sans-serif;\\n font-size: 15px;\\n}\\n"', 'blank': 'True'}),
'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'askbot.replyaddress': {
'Meta': {'object_name': 'ReplyAddress'},
'address': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '25'}),
'allowed_from_email': ('django.db.models.fields.EmailField', [], {'max_length': '150'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'post': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reply_addresses'", 'null': 'True', 'to': "orm['askbot.Post']"}),
'reply_action': ('django.db.models.fields.CharField', [], {'default': "'auto_answer_or_comment'", 'max_length': '32'}),
'response_post': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'edit_addresses'", 'null': 'True', 'to': "orm['askbot.Post']"}),
'used_at': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'askbot.repute': {
'Meta': {'object_name': 'Repute', 'db_table': "u'repute'"},
'comment': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'negative': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'positive': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Post']", 'null': 'True', 'blank': 'True'}),
'reputation': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
'reputation_type': ('django.db.models.fields.SmallIntegerField', [], {}),
'reputed_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'askbot.tag': {
'Meta': {'ordering': "('-used_count', 'name')", 'object_name': 'Tag', 'db_table': "u'tag'"},
'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'created_tags'", 'to': "orm['auth.User']"}),
'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_tags'", 'null': 'True', 'to': "orm['auth.User']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'status': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
'suggested_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'suggested_tags'", 'symmetrical': 'False', 'to': "orm['auth.User']"}),
'tag_wiki': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'described_tag'", 'unique': 'True', 'null': 'True', 'to': "orm['askbot.Post']"}),
'used_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
},
'askbot.thread': {
'Meta': {'object_name': 'Thread'},
'accepted_answer': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': "orm['askbot.Post']"}),
'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'answer_accepted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'answer_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'approved': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}),
'close_reason': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'closed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'closed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'closed_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'favorited_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'unused_favorite_threads'", 'symmetrical': 'False', 'through': "orm['askbot.FavoriteQuestion']", 'to': "orm['auth.User']"}),
'favourite_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'followed_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'followed_threads'", 'symmetrical': 'False', 'to': "orm['auth.User']"}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'group_threads'", 'symmetrical': 'False', 'through': "orm['askbot.ThreadToGroup']", 'to': "orm['askbot.Group']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language_code': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '16'}),
'last_activity_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_activity_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'unused_last_active_in_threads'", 'to': "orm['auth.User']"}),
'points': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_column': "'score'"}),
'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}),
'tags': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'threads'", 'symmetrical': 'False', 'to': "orm['askbot.Tag']"}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
'view_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
},
'askbot.threadtogroup': {
'Meta': {'unique_together': "(('thread', 'group'),)", 'object_name': 'ThreadToGroup', 'db_table': "'askbot_thread_groups'"},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Group']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'thread': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['askbot.Thread']"}),
'visibility': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'})
},
'askbot.vote': {
'Meta': {'unique_together': "(('user', 'voted_post'),)", 'object_name': 'Vote', 'db_table': "u'vote'"},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'votes'", 'to': "orm['auth.User']"}),
'vote': ('django.db.models.fields.SmallIntegerField', [], {}),
'voted_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'voted_post': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'votes'", 'to': "orm['askbot.Post']"})
},
'auth.authusergroups': {
'Meta': {'unique_together': "(('group', 'user'),)", 'object_name': 'AuthUserGroups', 'db_table': "'auth_user_groups'", 'managed': 'False'},
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.Group']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}),
'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}),
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
'email_signature': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_fake': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'languages': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '128'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}),
'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'show_marked_tags': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}),
'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}),
'subscribed_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['askbot']
|
gpl-3.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
2728,
327,
12934,
901,
283,
6564,
14,
3671,
63,
600,
7,
267,
1592,
14,
525,
63,
2301,
360,
20963,
63,
1932,
297,
283,
3671,
63,
600,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
287,
297,
1390,
63,
1267,
29,
975,
395,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
2728,
327,
15920,
901,
283,
6564,
14,
3671,
63,
600,
7,
267,
1592,
14,
1807,
63,
2301,
360,
20963,
63,
1932,
297,
283,
3671,
63,
600,
358,
2378,
1709,
275,
469,
267,
283,
20963,
14,
8240,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
14350,
297,
283,
697,
63,
1224,
356,
298,
85,
7,
8240,
15208,
288,
283,
2682,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
8240,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
14640,
297,
990,
8613,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
14274,
471,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
785,
63,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
8591,
297,
990,
8613,
288,
283,
4790,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
20963,
14,
6564,
6256,
283,
2307,
356,
283,
549,
1604,
288,
283,
24890,
316,
63,
3707,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
2407,
63,
354,
356,
3546,
9226,
63,
8240,
4662,
283,
10247,
356,
283,
797,
297,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6097,
288,
283,
18323,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
2407,
63,
354,
356,
3546,
15994,
63,
8240,
4662,
283,
10247,
356,
283,
797,
297,
283,
8304,
356,
298,
1025,
459,
20963,
14,
14350,
23601,
3694,
6256,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6097,
288,
283,
4705,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
791,
885,
356,
17172,
5593,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
20963,
14,
8240,
14274,
1205,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
751,
297,
283,
8240,
9878,
283,
785,
63,
354,
356,
283,
14350,
23601,
3694,
2267,
288,
283,
8240,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
20963,
14,
14350,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1205,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
14640,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
20963,
14,
12628,
5934,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
23902,
19104,
2267,
288,
283,
3270,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2502,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
2307,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
711,
63,
2697,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
26969,
297,
990,
791,
988,
63,
1267,
356,
283,
1046,
1604,
288,
283,
4790,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
12628,
63,
13379,
4662,
283,
475,
356,
298,
1025,
459,
20963,
14,
6564,
6097,
288,
283,
1730,
63,
498,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2167,
1604,
288,
283,
505,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
8613,
288,
283,
6797,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
3071,
267,
1660,
267,
283,
20963,
14,
12628,
4790,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
23902,
16778,
2267,
288,
283,
3270,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2502,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
2307,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
711,
63,
2697,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
26969,
297,
990,
791,
988,
63,
1267,
356,
283,
1046,
1604,
288,
283,
374,
63,
12628,
356,
661,
1176,
14,
697,
14
] |
[
2644,
26,
2774,
13,
24,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
2728,
327,
12934,
901,
283,
6564,
14,
3671,
63,
600,
7,
267,
1592,
14,
525,
63,
2301,
360,
20963,
63,
1932,
297,
283,
3671,
63,
600,
297,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
287,
297,
1390,
63,
1267,
29,
975,
395,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
2728,
327,
15920,
901,
283,
6564,
14,
3671,
63,
600,
7,
267,
1592,
14,
1807,
63,
2301,
360,
20963,
63,
1932,
297,
283,
3671,
63,
600,
358,
2378,
1709,
275,
469,
267,
283,
20963,
14,
8240,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
14350,
297,
283,
697,
63,
1224,
356,
298,
85,
7,
8240,
15208,
288,
283,
2682,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
8240,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
14640,
297,
990,
8613,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
14274,
471,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
785,
63,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
8591,
297,
990,
8613,
288,
283,
4790,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
20963,
14,
6564,
6256,
283,
2307,
356,
283,
549,
1604,
288,
283,
24890,
316,
63,
3707,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
2407,
63,
354,
356,
3546,
9226,
63,
8240,
4662,
283,
10247,
356,
283,
797,
297,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6097,
288,
283,
18323,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
2407,
63,
354,
356,
3546,
15994,
63,
8240,
4662,
283,
10247,
356,
283,
797,
297,
283,
8304,
356,
298,
1025,
459,
20963,
14,
14350,
23601,
3694,
6256,
283,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6097,
288,
283,
4705,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
791,
885,
356,
17172,
5593,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
20963,
14,
8240,
14274,
1205,
356,
469,
288,
283,
3396,
356,
791,
3235,
63,
6314,
356,
9510,
751,
297,
283,
8240,
9878,
283,
785,
63,
354,
356,
283,
14350,
23601,
3694,
2267,
288,
283,
8240,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
20963,
14,
14350,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1205,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
14640,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
751,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
13687,
267,
1660,
267,
283,
20963,
14,
12628,
5934,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
23902,
19104,
2267,
288,
283,
3270,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2502,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
2307,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
711,
63,
2697,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
26969,
297,
990,
791,
988,
63,
1267,
356,
283,
1046,
1604,
288,
283,
4790,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
12628,
63,
13379,
4662,
283,
475,
356,
298,
1025,
459,
20963,
14,
6564,
6097,
288,
283,
1730,
63,
498,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2167,
1604,
288,
283,
505,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
8613,
288,
283,
6797,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
3071,
267,
1660,
267,
283,
20963,
14,
12628,
4790,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
23902,
16778,
2267,
288,
283,
3270,
63,
292,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2502,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
2307,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
711,
63,
2697,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
26969,
297,
990,
791,
988,
63,
1267,
356,
283,
1046,
1604,
288,
283,
374,
63,
12628,
356,
661,
1176,
14,
697,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dago/ansible-modules-extras
|
cloud/profitbricks/profitbricks_nic.py
|
132
|
8769
|
#!/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/>.
DOCUMENTATION = '''
---
module: profitbricks_nic
short_description: Create or Remove a NIC.
description:
- This module allows you to create or restore a volume snapshot. This module has a dependency on profitbricks >= 1.0.0
version_added: "2.0"
options:
datacenter:
description:
- The datacenter in which to operate.
required: true
server:
description:
- The server name or ID.
required: true
name:
description:
- The name or ID of the NIC. This is only required on deletes, but not on create.
required: true
lan:
description:
- The LAN to place the NIC on. You can pass a LAN that doesn't exist and it will be created. Required on create.
required: true
subscription_user:
description:
- The ProfitBricks username. Overrides the PB_SUBSCRIPTION_ID environement variable.
required: false
subscription_password:
description:
- THe ProfitBricks password. Overrides the PB_PASSWORD environement variable.
required: false
wait:
description:
- wait for the operation to complete before returning
required: false
default: "yes"
choices: [ "yes", "no" ]
wait_timeout:
description:
- how long before wait gives up, in seconds
default: 600
state:
description:
- Indicate desired state of the resource
required: false
default: 'present'
choices: ["present", "absent"]
requirements: [ "profitbricks" ]
author: Matt Baldwin (baldwin@stackpointcloud.com)
'''
EXAMPLES = '''
# Create a NIC
- profitbricks_nic:
datacenter: Tardis One
server: node002
lan: 2
wait_timeout: 500
state: present
# Remove a NIC
- profitbricks_nic:
datacenter: Tardis One
server: node002
name: 7341c2454f
wait_timeout: 500
state: absent
'''
import re
import uuid
import time
HAS_PB_SDK = True
try:
from profitbricks.client import ProfitBricksService, NIC
except ImportError:
HAS_PB_SDK = False
uuid_match = re.compile(
'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I)
def _wait_for_completion(profitbricks, promise, wait_timeout, msg):
if not promise: return
wait_timeout = time.time() + wait_timeout
while wait_timeout > time.time():
time.sleep(5)
operation_result = profitbricks.get_request(
request_id=promise['requestId'],
status=True)
if operation_result['metadata']['status'] == "DONE":
return
elif operation_result['metadata']['status'] == "FAILED":
raise Exception(
'Request failed to complete ' + msg + ' "' + str(
promise['requestId']) + '" to complete.')
raise Exception(
'Timed out waiting for async operation ' + msg + ' "' + str(
promise['requestId']
) + '" to complete.')
def create_nic(module, profitbricks):
"""
Creates a NIC.
module : AnsibleModule object
profitbricks: authenticated profitbricks object.
Returns:
True if the nic creates, false otherwise
"""
datacenter = module.params.get('datacenter')
server = module.params.get('server')
lan = module.params.get('lan')
name = module.params.get('name')
wait = module.params.get('wait')
wait_timeout = module.params.get('wait_timeout')
# Locate UUID for Datacenter
if not (uuid_match.match(datacenter)):
datacenter_list = profitbricks.list_datacenters()
for d in datacenter_list['items']:
dc = profitbricks.get_datacenter(d['id'])
if datacenter == dc['properties']['name']:
datacenter = d['id']
break
# Locate UUID for Server
if not (uuid_match.match(server)):
server_list = profitbricks.list_servers(datacenter)
for s in server_list['items']:
if server == s['properties']['name']:
server = s['id']
break
try:
n = NIC(
name=name,
lan=lan
)
nic_response = profitbricks.create_nic(datacenter, server, n)
if wait:
_wait_for_completion(profitbricks, nic_response,
wait_timeout, "create_nic")
return nic_response
except Exception as e:
module.fail_json(msg="failed to create the NIC: %s" % str(e))
def delete_nic(module, profitbricks):
"""
Removes a NIC
module : AnsibleModule object
profitbricks: authenticated profitbricks object.
Returns:
True if the NIC was removed, false otherwise
"""
datacenter = module.params.get('datacenter')
server = module.params.get('server')
name = module.params.get('name')
# Locate UUID for Datacenter
if not (uuid_match.match(datacenter)):
datacenter_list = profitbricks.list_datacenters()
for d in datacenter_list['items']:
dc = profitbricks.get_datacenter(d['id'])
if datacenter == dc['properties']['name']:
datacenter = d['id']
break
# Locate UUID for Server
server_found = False
if not (uuid_match.match(server)):
server_list = profitbricks.list_servers(datacenter)
for s in server_list['items']:
if server == s['properties']['name']:
server_found = True
server = s['id']
break
if not server_found:
return False
# Locate UUID for NIC
nic_found = False
if not (uuid_match.match(name)):
nic_list = profitbricks.list_nics(datacenter, server)
for n in nic_list['items']:
if name == n['properties']['name']:
nic_found = True
name = n['id']
break
if not nic_found:
return False
try:
nic_response = profitbricks.delete_nic(datacenter, server, name)
return nic_response
except Exception as e:
module.fail_json(msg="failed to remove the NIC: %s" % str(e))
def main():
module = AnsibleModule(
argument_spec=dict(
datacenter=dict(),
server=dict(),
name=dict(default=str(uuid.uuid4()).replace('-','')[:10]),
lan=dict(),
subscription_user=dict(),
subscription_password=dict(),
wait=dict(type='bool', default=True),
wait_timeout=dict(type='int', default=600),
state=dict(default='present'),
)
)
if not HAS_PB_SDK:
module.fail_json(msg='profitbricks required for this module')
if not module.params.get('subscription_user'):
module.fail_json(msg='subscription_user parameter is required')
if not module.params.get('subscription_password'):
module.fail_json(msg='subscription_password parameter is required')
if not module.params.get('datacenter'):
module.fail_json(msg='datacenter parameter is required')
if not module.params.get('server'):
module.fail_json(msg='server parameter is required')
subscription_user = module.params.get('subscription_user')
subscription_password = module.params.get('subscription_password')
profitbricks = ProfitBricksService(
username=subscription_user,
password=subscription_password)
state = module.params.get('state')
if state == 'absent':
if not module.params.get('name'):
module.fail_json(msg='name parameter is required')
try:
(changed) = delete_nic(module, profitbricks)
module.exit_json(changed=changed)
except Exception as e:
module.fail_json(msg='failed to set nic state: %s' % str(e))
elif state == 'present':
if not module.params.get('lan'):
module.fail_json(msg='lan parameter is required')
try:
(nic_dict) = create_nic(module, profitbricks)
module.exit_json(nics=nic_dict)
except Exception as e:
module.fail_json(msg='failed to set nic state: %s' % str(e))
from ansible.module_utils.basic import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32630,
30855,
63,
12165,
199,
3612,
63,
1802,
26,
2790,
503,
5852,
282,
31265,
14,
199,
1802,
26,
1362,
446,
961,
859,
6127,
1265,
370,
1218,
503,
9066,
282,
3301,
5740,
14,
961,
859,
965,
282,
5936,
641,
32630,
30855,
2356,
413,
14,
16,
14,
16,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1419,
26,
523,
16606,
26,
272,
1369,
26,
489,
446,
710,
16606,
315,
1314,
370,
19218,
14,
272,
1415,
26,
2549,
523,
1654,
26,
272,
1369,
26,
489,
446,
710,
1654,
536,
503,
2870,
14,
272,
1415,
26,
2549,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
503,
2870,
402,
314,
31265,
14,
961,
365,
1454,
1415,
641,
21812,
12,
1325,
440,
641,
1218,
14,
272,
1415,
26,
2549,
523,
634,
290,
26,
272,
1369,
26,
489,
446,
710,
491,
879,
370,
4192,
314,
31265,
641,
14,
2047,
883,
986,
282,
491,
879,
626,
3181,
1133,
2187,
436,
652,
911,
506,
2737,
14,
11105,
641,
1218,
14,
272,
1415,
26,
2549,
523,
9966,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
2165,
3269,
34,
322,
5618,
3434,
14,
31144,
314,
510,
34,
63,
6348,
10484,
1075,
63,
998,
655,
1042,
368,
434,
1750,
14,
272,
1415,
26,
3055,
523,
9966,
63,
2060,
26,
272,
1369,
26,
489,
446,
377,
1966,
2165,
3269,
34,
322,
5618,
2505,
14,
31144,
314,
510,
34,
63,
9032,
655,
1042,
368,
434,
1750,
14,
272,
1415,
26,
3055,
523,
3618,
26,
272,
1369,
26,
489,
446,
3618,
367,
314,
3439,
370,
4890,
2544,
8152,
272,
1415,
26,
3055,
272,
849,
26,
298,
5066,
2,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
3618,
63,
2593,
26,
272,
1369,
26,
489,
446,
4212,
1846,
2544,
3618,
10557,
1536,
12,
315,
4696,
272,
849,
26,
11624,
523,
1174,
26,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
937,
199,
199,
7538,
26,
359,
298,
496,
3269,
30855,
2,
1622,
199,
2502,
26,
31653,
23928,
68,
2676,
334,
4982,
68,
2676,
32,
2340,
1403,
4091,
14,
957,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
199,
3,
2790,
282,
31265,
199,
13,
32630,
30855,
63,
12165,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
1654,
26,
1031,
7432,
272,
634,
290,
26,
499,
272,
3618,
63,
2593,
26,
6891,
272,
1174,
26,
3451,
199,
199,
3,
5852,
282,
31265,
199,
13,
32630,
30855,
63,
12165,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
1654,
26,
1031,
7432,
272,
536,
26,
1520,
15590,
67,
1194,
1477,
70,
272,
3618,
63,
2593,
26,
6891,
272,
1174,
26,
9552,
199,
199,
2344,
199,
199,
646,
295,
199,
646,
5377,
199,
646,
900,
199,
199,
13533,
63,
13167,
63,
14939,
275,
715,
199,
199,
893,
26,
272,
687,
32630,
30855,
14,
1258,
492,
2165,
3269,
34,
322,
5618,
3167,
12,
31265,
199,
2590,
3545,
26,
272,
7509,
63,
13167,
63,
14939,
275,
756,
199,
199,
2580,
63,
1431,
275,
295,
14,
2014,
8,
272,
6730,
60,
87,
8194,
24,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
713,
7293,
295,
14,
41,
9,
421,
199,
318,
485,
2573,
63,
509,
63,
13207,
8,
496,
3269,
30855,
12,
8023,
572,
12,
3618,
63,
2593,
12,
1499,
304,
272,
340,
440,
8023,
572,
26,
372,
272,
3618,
63,
2593,
275,
900,
14,
521,
342,
435,
3618,
63,
2593,
272,
1830,
3618,
63,
2593,
690,
900,
14,
521,
837,
267,
900,
14,
4532,
8,
21,
9,
267,
3439,
63,
1099,
275,
32630,
30855,
14,
362,
63,
1069,
8,
288,
1056,
63,
344,
29,
12741,
572,
459,
1069,
1304,
995,
288,
2004,
29,
549,
9,
398,
340,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
22162,
582,
288,
372,
267,
916,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
12299,
582,
288,
746,
2186,
8,
355,
283,
2017,
3405,
370,
4890,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
490,
8023,
572,
459,
1069,
1304,
1105,
435,
5522,
370,
4890,
2659,
339,
746,
2186,
8,
267,
283,
28682,
734,
10923,
367,
5316,
3439,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
288,
8023,
572,
459,
1069,
1304,
418,
288,
776,
435,
5522,
370,
4890,
2659,
199,
199,
318,
1218,
63,
12165,
8,
578,
12,
32630,
30855,
304,
272,
408,
272,
10560,
282,
31265,
14,
339,
859,
520,
6953,
909,
272,
32630,
30855,
26,
15082,
32630,
30855,
909,
14,
339,
1803,
26,
267,
715,
340,
314,
14304,
8491,
12,
3055,
4257,
272,
408,
272,
16606,
275,
859,
14,
1162,
14,
362,
360,
17770,
358,
272,
1654,
275,
859,
14,
1162,
14,
362,
360,
1000,
358,
272,
634,
290,
275,
859,
14,
1162,
14,
362,
360,
1502,
358,
272,
536,
275,
859,
14,
1162,
14,
362,
360,
354,
358,
272,
3618,
275,
859,
14,
1162,
14,
362,
360,
2573,
358,
272,
3618,
63,
2593,
275,
859,
14,
1162,
14,
362,
360,
2573,
63,
2593,
358,
339
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
32630,
30855,
63,
12165,
199,
3612,
63,
1802,
26,
2790,
503,
5852,
282,
31265,
14,
199,
1802,
26,
1362,
446,
961,
859,
6127,
1265,
370,
1218,
503,
9066,
282,
3301,
5740,
14,
961,
859,
965,
282,
5936,
641,
32630,
30855,
2356,
413,
14,
16,
14,
16,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
1419,
26,
523,
16606,
26,
272,
1369,
26,
489,
446,
710,
16606,
315,
1314,
370,
19218,
14,
272,
1415,
26,
2549,
523,
1654,
26,
272,
1369,
26,
489,
446,
710,
1654,
536,
503,
2870,
14,
272,
1415,
26,
2549,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
503,
2870,
402,
314,
31265,
14,
961,
365,
1454,
1415,
641,
21812,
12,
1325,
440,
641,
1218,
14,
272,
1415,
26,
2549,
523,
634,
290,
26,
272,
1369,
26,
489,
446,
710,
491,
879,
370,
4192,
314,
31265,
641,
14,
2047,
883,
986,
282,
491,
879,
626,
3181,
1133,
2187,
436,
652,
911,
506,
2737,
14,
11105,
641,
1218,
14,
272,
1415,
26,
2549,
523,
9966,
63,
751,
26,
272,
1369,
26,
489,
446,
710,
2165,
3269,
34,
322,
5618,
3434,
14,
31144,
314,
510,
34,
63,
6348,
10484,
1075,
63,
998,
655,
1042,
368,
434,
1750,
14,
272,
1415,
26,
3055,
523,
9966,
63,
2060,
26,
272,
1369,
26,
489,
446,
377,
1966,
2165,
3269,
34,
322,
5618,
2505,
14,
31144,
314,
510,
34,
63,
9032,
655,
1042,
368,
434,
1750,
14,
272,
1415,
26,
3055,
523,
3618,
26,
272,
1369,
26,
489,
446,
3618,
367,
314,
3439,
370,
4890,
2544,
8152,
272,
1415,
26,
3055,
272,
849,
26,
298,
5066,
2,
272,
3415,
26,
359,
298,
5066,
401,
298,
889,
2,
1622,
523,
3618,
63,
2593,
26,
272,
1369,
26,
489,
446,
4212,
1846,
2544,
3618,
10557,
1536,
12,
315,
4696,
272,
849,
26,
11624,
523,
1174,
26,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
272,
1415,
26,
3055,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
2097,
1881,
401,
298,
5575,
937,
199,
199,
7538,
26,
359,
298,
496,
3269,
30855,
2,
1622,
199,
2502,
26,
31653,
23928,
68,
2676,
334,
4982,
68,
2676,
32,
2340,
1403,
4091,
14,
957,
9,
199,
2344,
199,
199,
8918,
275,
1449,
199,
199,
3,
2790,
282,
31265,
199,
13,
32630,
30855,
63,
12165,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
1654,
26,
1031,
7432,
272,
634,
290,
26,
499,
272,
3618,
63,
2593,
26,
6891,
272,
1174,
26,
3451,
199,
199,
3,
5852,
282,
31265,
199,
13,
32630,
30855,
63,
12165,
26,
272,
16606,
26,
16017,
2297,
7309,
272,
1654,
26,
1031,
7432,
272,
536,
26,
1520,
15590,
67,
1194,
1477,
70,
272,
3618,
63,
2593,
26,
6891,
272,
1174,
26,
9552,
199,
199,
2344,
199,
199,
646,
295,
199,
646,
5377,
199,
646,
900,
199,
199,
13533,
63,
13167,
63,
14939,
275,
715,
199,
199,
893,
26,
272,
687,
32630,
30855,
14,
1258,
492,
2165,
3269,
34,
322,
5618,
3167,
12,
31265,
199,
2590,
3545,
26,
272,
7509,
63,
13167,
63,
14939,
275,
756,
199,
199,
2580,
63,
1431,
275,
295,
14,
2014,
8,
272,
6730,
60,
87,
8194,
24,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
20,
17063,
7023,
87,
8194,
713,
7293,
295,
14,
41,
9,
421,
199,
318,
485,
2573,
63,
509,
63,
13207,
8,
496,
3269,
30855,
12,
8023,
572,
12,
3618,
63,
2593,
12,
1499,
304,
272,
340,
440,
8023,
572,
26,
372,
272,
3618,
63,
2593,
275,
900,
14,
521,
342,
435,
3618,
63,
2593,
272,
1830,
3618,
63,
2593,
690,
900,
14,
521,
837,
267,
900,
14,
4532,
8,
21,
9,
267,
3439,
63,
1099,
275,
32630,
30855,
14,
362,
63,
1069,
8,
288,
1056,
63,
344,
29,
12741,
572,
459,
1069,
1304,
995,
288,
2004,
29,
549,
9,
398,
340,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
22162,
582,
288,
372,
267,
916,
3439,
63,
1099,
459,
2343,
2545,
1205,
418,
508,
298,
12299,
582,
288,
746,
2186,
8,
355,
283,
2017,
3405,
370,
4890,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
490,
8023,
572,
459,
1069,
1304,
1105,
435,
5522,
370,
4890,
2659,
339,
746,
2186,
8,
267,
283,
28682,
734,
10923,
367,
5316,
3439,
283,
435,
1499,
435,
283,
3546,
435,
620,
8,
288,
8023,
572,
459,
1069,
1304,
418,
288,
776,
435,
5522,
370,
4890,
2659,
199,
199,
318,
1218,
63,
12165,
8,
578,
12,
32630,
30855,
304,
272,
408,
272,
10560,
282,
31265,
14,
339,
859,
520,
6953,
909,
272,
32630,
30855,
26,
15082,
32630,
30855,
909,
14,
339,
1803,
26,
267,
715,
340,
314,
14304,
8491,
12,
3055,
4257,
272,
408,
272,
16606,
275,
859,
14,
1162,
14,
362,
360,
17770,
358,
272,
1654,
275,
859,
14,
1162,
14,
362,
360,
1000,
358,
272,
634,
290,
275,
859,
14,
1162,
14,
362,
360,
1502,
358,
272,
536,
275,
859,
14,
1162,
14,
362,
360,
354,
358,
272,
3618,
275,
859,
14,
1162,
14,
362,
360,
2573,
358,
272,
3618,
63,
2593,
275,
859,
14,
1162,
14,
362,
360,
2573,
63,
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,
1,
1,
1,
1,
1
] |
nschaetti/nsNLP
|
data/Text.py
|
1
|
2476
|
# -*- coding: utf-8 -*-
#
# File : corpus/IQLACorpus.py
# Description : .
# Date : 16/08/2017
#
# Copyright Nils Schaetti, University of Neuchâtel <nils.schaetti@unine.ch>
# Imports
from Sample import Sample
import codecs
# Class to access to a text
class Text(Sample):
"""
Class to access to a text
"""
# Constructor
def __init__(self, text_path, author, text_title):
"""
Constructor
:param text_path:
:param author:
"""
super(Text, self).__init__(text_path, author)
self._text_path = text_path
self._author = author
self._title = text_title
# end __init__
########################################
# Public
########################################
# Get title
def get_title(self):
"""
Get title
:return:
"""
return self._title
# end get_title
# Get text
def get_text(self):
"""
Get text
:return:
"""
return codecs.open(self._text_path, 'r', encoding='utf-8').read()
# end text
# Save text
def save(self, text):
"""
Save text
:param text:
:return:
"""
return codecs.open(self._text_path, 'w', encoding='utf-8').write(text)
# end save
# Get author
def get_author(self):
"""
Get author
:return:
"""
return self._author
# end author
# Get path
def get_path(self):
"""
Get path
:return:
"""
return self._text_path
# end get_path
# Get X
def x(self):
"""
Get X
:return:
"""
return self.get_text()
# end x
# Get Y
def y(self):
"""
Get Y
:return:
"""
return self.get_author().get_name()
# end y
########################################
# Override
########################################
# To string
def __unicode__(self):
"""
To string
:return:
"""
return u"Text(title: {}, path:{}, author:{})".format(self._title, self._text_path, self._author.get_name())
# end __unicode__
# To string
def __str__(self):
"""
To string
:return:
"""
return "Text(title: {}, path:{}, author:{})".format(self._title, self._text_path, self._author.get_name())
# end __unicode__
# end Text
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3814,
520,
16831,
15,
41,
2940,
1348,
269,
8843,
14,
647,
199,
3,
11994,
520,
1275,
199,
3,
6148,
520,
3193,
15,
2036,
15,
10680,
199,
3,
199,
3,
1898,
653,
17841,
428,
9518,
386,
280,
12,
15904,
402,
5612,
2133,
128,
96,
14146,
665,
78,
17841,
14,
83,
9518,
386,
280,
32,
324,
1132,
14,
335,
30,
199,
199,
3,
24339,
199,
504,
15227,
492,
15227,
199,
646,
6010,
421,
199,
3,
8089,
370,
2879,
370,
282,
1318,
199,
533,
4516,
8,
8176,
304,
272,
408,
272,
8089,
370,
2879,
370,
282,
1318,
272,
408,
339,
327,
20297,
272,
347,
636,
826,
721,
277,
12,
1318,
63,
515,
12,
4132,
12,
1318,
63,
1213,
304,
267,
408,
267,
20297,
267,
520,
635,
1318,
63,
515,
26,
267,
520,
635,
4132,
26,
267,
408,
267,
1613,
8,
1872,
12,
291,
2843,
826,
721,
505,
63,
515,
12,
4132,
9,
267,
291,
423,
505,
63,
515,
275,
1318,
63,
515,
267,
291,
423,
2502,
275,
4132,
267,
291,
423,
1213,
275,
1318,
63,
1213,
272,
327,
1284,
636,
826,
363,
339,
26316,
272,
327,
1684,
272,
26316,
339,
327,
2372,
2538,
272,
347,
664,
63,
1213,
8,
277,
304,
267,
408,
267,
2372,
2538,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
423,
1213,
272,
327,
1284,
664,
63,
1213,
339,
327,
2372,
1318,
272,
347,
664,
63,
505,
8,
277,
304,
267,
408,
267,
2372,
1318,
267,
520,
1107,
26,
267,
408,
267,
372,
6010,
14,
1490,
8,
277,
423,
505,
63,
515,
12,
283,
82,
297,
2644,
534,
1624,
13,
24,
1959,
739,
342,
272,
327,
1284,
1318,
339,
327,
11063,
1318,
272,
347,
3354,
8,
277,
12,
1318,
304,
267,
408,
267,
11063,
1318,
267,
520,
635,
1318,
26,
267,
520,
1107,
26,
267,
408,
267,
372,
6010,
14,
1490,
8,
277,
423,
505,
63,
515,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
1959,
952,
8,
505,
9,
272,
327,
1284,
3354,
339,
327,
2372,
4132,
272,
347,
664,
63,
2502,
8,
277,
304,
267,
408,
267,
2372,
4132,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
423,
2502,
272,
327,
1284,
4132,
339,
327,
2372,
931,
272,
347,
664,
63,
515,
8,
277,
304,
267,
408,
267,
2372,
931,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
423,
505,
63,
515,
272,
327,
1284,
664,
63,
515,
339,
327,
2372,
1323,
272,
347,
671,
8,
277,
304,
267,
408,
267,
2372,
1323,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
14,
362,
63,
505,
342,
272,
327,
1284,
671,
339,
327,
2372,
1488,
272,
347,
612,
8,
277,
304,
267,
408,
267,
2372,
1488,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
14,
362,
63,
2502,
1252,
362,
63,
354,
342,
272,
327,
1284,
612,
339,
26316,
272,
327,
11041,
272,
26316,
339,
327,
4005,
1059,
272,
347,
636,
2975,
721,
277,
304,
267,
408,
267,
4005,
1059,
267,
520,
1107,
26,
267,
408,
267,
372,
399,
2,
1872,
8,
1213,
26,
5479,
931,
14534,
1386,
4132,
14534,
25974,
908,
8,
277,
423,
1213,
12,
291,
423,
505,
63,
515,
12,
291,
423,
2502,
14,
362,
63,
354,
1012,
272,
327,
1284,
636,
2975,
363,
339,
327,
4005,
1059,
272,
347,
636,
495,
721,
277,
304,
267,
408,
267,
4005,
1059,
267,
520,
1107,
26,
267,
408,
267,
372,
298,
1872,
8,
1213,
26,
5479,
931,
14534,
1386,
4132,
14534,
25974,
908,
8,
277,
423,
1213,
12,
291,
423,
505,
63,
515,
12,
291,
423,
2502,
14,
362,
63,
354,
1012,
272,
327,
1284,
636,
2975,
363,
199,
199,
3,
1284,
4516,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3814,
520,
16831,
15,
41,
2940,
1348,
269,
8843,
14,
647,
199,
3,
11994,
520,
1275,
199,
3,
6148,
520,
3193,
15,
2036,
15,
10680,
199,
3,
199,
3,
1898,
653,
17841,
428,
9518,
386,
280,
12,
15904,
402,
5612,
2133,
128,
96,
14146,
665,
78,
17841,
14,
83,
9518,
386,
280,
32,
324,
1132,
14,
335,
30,
199,
199,
3,
24339,
199,
504,
15227,
492,
15227,
199,
646,
6010,
421,
199,
3,
8089,
370,
2879,
370,
282,
1318,
199,
533,
4516,
8,
8176,
304,
272,
408,
272,
8089,
370,
2879,
370,
282,
1318,
272,
408,
339,
327,
20297,
272,
347,
636,
826,
721,
277,
12,
1318,
63,
515,
12,
4132,
12,
1318,
63,
1213,
304,
267,
408,
267,
20297,
267,
520,
635,
1318,
63,
515,
26,
267,
520,
635,
4132,
26,
267,
408,
267,
1613,
8,
1872,
12,
291,
2843,
826,
721,
505,
63,
515,
12,
4132,
9,
267,
291,
423,
505,
63,
515,
275,
1318,
63,
515,
267,
291,
423,
2502,
275,
4132,
267,
291,
423,
1213,
275,
1318,
63,
1213,
272,
327,
1284,
636,
826,
363,
339,
26316,
272,
327,
1684,
272,
26316,
339,
327,
2372,
2538,
272,
347,
664,
63,
1213,
8,
277,
304,
267,
408,
267,
2372,
2538,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
423,
1213,
272,
327,
1284,
664,
63,
1213,
339,
327,
2372,
1318,
272,
347,
664,
63,
505,
8,
277,
304,
267,
408,
267,
2372,
1318,
267,
520,
1107,
26,
267,
408,
267,
372,
6010,
14,
1490,
8,
277,
423,
505,
63,
515,
12,
283,
82,
297,
2644,
534,
1624,
13,
24,
1959,
739,
342,
272,
327,
1284,
1318,
339,
327,
11063,
1318,
272,
347,
3354,
8,
277,
12,
1318,
304,
267,
408,
267,
11063,
1318,
267,
520,
635,
1318,
26,
267,
520,
1107,
26,
267,
408,
267,
372,
6010,
14,
1490,
8,
277,
423,
505,
63,
515,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
1959,
952,
8,
505,
9,
272,
327,
1284,
3354,
339,
327,
2372,
4132,
272,
347,
664,
63,
2502,
8,
277,
304,
267,
408,
267,
2372,
4132,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
423,
2502,
272,
327,
1284,
4132,
339,
327,
2372,
931,
272,
347,
664,
63,
515,
8,
277,
304,
267,
408,
267,
2372,
931,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
423,
505,
63,
515,
272,
327,
1284,
664,
63,
515,
339,
327,
2372,
1323,
272,
347,
671,
8,
277,
304,
267,
408,
267,
2372,
1323,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
14,
362,
63,
505,
342,
272,
327,
1284,
671,
339,
327,
2372,
1488,
272,
347,
612,
8,
277,
304,
267,
408,
267,
2372,
1488,
267,
520,
1107,
26,
267,
408,
267,
372,
291,
14,
362,
63,
2502,
1252,
362,
63,
354,
342,
272,
327,
1284,
612,
339,
26316,
272,
327,
11041,
272,
26316,
339,
327,
4005,
1059,
272,
347,
636,
2975,
721,
277,
304,
267,
408,
267,
4005,
1059,
267,
520,
1107,
26,
267,
408,
267,
372,
399,
2,
1872,
8,
1213,
26,
5479,
931,
14534,
1386,
4132,
14534,
25974,
908,
8,
277,
423,
1213,
12,
291,
423,
505,
63,
515,
12,
291,
423,
2502,
14,
362,
63,
354,
1012,
272,
327,
1284,
636,
2975,
363,
339,
327,
4005,
1059,
272,
347,
636,
495,
721,
277,
304,
267,
408,
267,
4005,
1059,
267,
520,
1107,
26,
267,
408,
267,
372,
298,
1872,
8,
1213,
26,
5479,
931,
14534,
1386,
4132,
14534,
25974,
908,
8,
277,
423,
1213,
12,
291,
423,
505,
63,
515,
12,
291,
423,
2502,
14,
362,
63,
354,
1012,
272,
327,
1284,
636,
2975,
363,
199,
199,
3,
1284,
4516,
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,
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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v('OUTPUT_NAME', 'train.data')
LABEL_PREFIX = os.getenv('LABEL_PREFIX', '__LABEL__')
csv_file = open('data_detikcom_labelled.csv')
csv_reader = csv.DictReader(csv_file)
train_file = open(OUTPUT_NAME, 'w')
for row in csv_reader:
title = row['title'].strip().lower()
raw_content = row['raw_content']
clean_content = BeautifulSoup(raw_content, 'lxml').text
content = []
labels = []
# Compile regex to remove non-alphanum char
nonalpha = re.compile('[^a-z\-]+')
for word in title.split(' '):
word = word.lower()
word = nonalpha.sub('', word)
if word != '':
content.append(word)
for word in clean_content.split(' '):
word = word.lower()
word = nonalpha.sub('', word)
if word != '':
content.append(word)
content_str = ' '.join(content).strip()
if row['sentiment_1'] != '':
label = row['sentiment_1']
label_name = '{}{}'.format(LABEL_PREFIX, label)
labels.append(label_name)
if row['sentiment_2'] != '':
label = row['sentiment_2']
label_name = '{}{}'.format(LABEL_PREFIX, label)
labels.append(label_name)
if row['sentiment_3'] != '':
label = row['sentiment_3']
label_name = '{}{}'.format(LABEL_PREFIX, label)
labels.append(label_name)
# Skip content if label not exists
if not labels: continue
label_str = ' '.join(labels)
train_line = '{} {}\n'.format(label_str, content_str)
train_file.write(train_line)
csv_file.close()
|
bsd-3-clause
|
[
646,
7392,
199,
504,
9922,
20,
492,
17132,
199,
504,
5055,
492,
14427,
199,
646,
295,
199,
646,
747,
199,
199,
8414,
63,
2339,
275,
747,
14,
12959,
360,
8414,
63,
2339,
297,
283,
2834,
14,
576,
358,
199,
13837,
63,
6351,
275,
747,
14,
12959,
360,
13837,
63,
6351,
297,
2560,
13837,
13766,
199,
199,
4737,
63,
493,
275,
1551,
360,
576,
63,
271,
30298,
957,
63,
1302,
1146,
14,
4737,
358,
199,
4737,
63,
5503,
275,
7392,
14,
2141,
5929,
8,
4737,
63,
493,
9,
199,
199,
2834,
63,
493,
275,
1551,
8,
8414,
63,
2339,
12,
283,
87,
358,
199,
509,
1962,
315,
7392,
63,
5503,
26,
272,
2538,
275,
1962,
459,
1213,
2278,
1913,
1252,
2325,
342,
272,
3066,
63,
1317,
275,
1962,
459,
1773,
63,
1317,
418,
272,
3633,
63,
1317,
275,
17132,
8,
1773,
63,
1317,
12,
283,
22899,
1959,
505,
272,
1564,
275,
942,
272,
3628,
275,
942,
339,
327,
24562,
5163,
370,
2813,
2222,
13,
10305,
290,
453,
1495,
272,
2222,
4468,
275,
295,
14,
2014,
360,
4735,
65,
13,
90,
16185,
2807,
358,
339,
367,
4349,
315,
2538,
14,
1294,
360,
18927,
267,
4349,
275,
4349,
14,
2325,
342,
267,
4349,
275,
2222,
4468,
14,
954,
8594,
4349,
9,
267,
340,
4349,
1137,
8061,
288,
1564,
14,
740,
8,
1027,
9,
272,
367,
4349,
315,
3633,
63,
1317,
14,
1294,
360,
18927,
267,
4349,
275,
4349,
14,
2325,
342,
267,
4349,
275,
2222,
4468,
14,
954,
8594,
4349,
9,
267,
340,
4349,
1137,
8061,
288,
1564,
14,
740,
8,
1027,
9,
272,
1564,
63,
495,
275,
283,
1987,
904,
8,
1317,
680,
1913,
342,
339,
340,
1962,
459,
2464,
280,
434,
63,
17,
418,
1137,
8061,
267,
1768,
275,
1962,
459,
2464,
280,
434,
63,
17,
418,
267,
1768,
63,
354,
275,
9005,
11123,
908,
8,
13837,
63,
6351,
12,
1768,
9,
267,
3628,
14,
740,
8,
1302,
63,
354,
9,
272,
340,
1962,
459,
2464,
280,
434,
63,
18,
418,
1137,
8061,
267,
1768,
275,
1962,
459,
2464,
280,
434,
63,
18,
418,
267,
1768,
63,
354,
275,
9005,
11123,
908,
8,
13837,
63,
6351,
12,
1768,
9,
267,
3628,
14,
740,
8,
1302,
63,
354,
9,
272,
340,
1962,
459,
2464,
280,
434,
63,
19,
418,
1137,
8061,
267,
1768,
275,
1962,
459,
2464,
280,
434,
63,
19,
418,
267,
1768,
63,
354,
275,
9005,
11123,
908,
8,
13837,
63,
6351,
12,
1768,
9,
267,
3628,
14,
740,
8,
1302,
63,
354,
9,
339,
327,
8232,
1564,
340,
1768,
440,
3495,
272,
340,
440,
3628,
26,
1980,
272,
1768,
63,
495,
275,
283,
1987,
904,
8,
3512,
9,
272,
3560,
63,
604,
275,
9005,
22902,
78,
1370,
908,
8,
1302,
63,
495,
12,
1564,
63,
495,
9,
272,
3560,
63,
493,
14,
952,
8,
2834,
63,
604,
9,
199,
199,
4737,
63,
493,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7392,
199,
504,
9922,
20,
492,
17132,
199,
504,
5055,
492,
14427,
199,
646,
295,
199,
646,
747,
199,
199,
8414,
63,
2339,
275,
747,
14,
12959,
360,
8414,
63,
2339,
297,
283,
2834,
14,
576,
358,
199,
13837,
63,
6351,
275,
747,
14,
12959,
360,
13837,
63,
6351,
297,
2560,
13837,
13766,
199,
199,
4737,
63,
493,
275,
1551,
360,
576,
63,
271,
30298,
957,
63,
1302,
1146,
14,
4737,
358,
199,
4737,
63,
5503,
275,
7392,
14,
2141,
5929,
8,
4737,
63,
493,
9,
199,
199,
2834,
63,
493,
275,
1551,
8,
8414,
63,
2339,
12,
283,
87,
358,
199,
509,
1962,
315,
7392,
63,
5503,
26,
272,
2538,
275,
1962,
459,
1213,
2278,
1913,
1252,
2325,
342,
272,
3066,
63,
1317,
275,
1962,
459,
1773,
63,
1317,
418,
272,
3633,
63,
1317,
275,
17132,
8,
1773,
63,
1317,
12,
283,
22899,
1959,
505,
272,
1564,
275,
942,
272,
3628,
275,
942,
339,
327,
24562,
5163,
370,
2813,
2222,
13,
10305,
290,
453,
1495,
272,
2222,
4468,
275,
295,
14,
2014,
360,
4735,
65,
13,
90,
16185,
2807,
358,
339,
367,
4349,
315,
2538,
14,
1294,
360,
18927,
267,
4349,
275,
4349,
14,
2325,
342,
267,
4349,
275,
2222,
4468,
14,
954,
8594,
4349,
9,
267,
340,
4349,
1137,
8061,
288,
1564,
14,
740,
8,
1027,
9,
272,
367,
4349,
315,
3633,
63,
1317,
14,
1294,
360,
18927,
267,
4349,
275,
4349,
14,
2325,
342,
267,
4349,
275,
2222,
4468,
14,
954,
8594,
4349,
9,
267,
340,
4349,
1137,
8061,
288,
1564,
14,
740,
8,
1027,
9,
272,
1564,
63,
495,
275,
283,
1987,
904,
8,
1317,
680,
1913,
342,
339,
340,
1962,
459,
2464,
280,
434,
63,
17,
418,
1137,
8061,
267,
1768,
275,
1962,
459,
2464,
280,
434,
63,
17,
418,
267,
1768,
63,
354,
275,
9005,
11123,
908,
8,
13837,
63,
6351,
12,
1768,
9,
267,
3628,
14,
740,
8,
1302,
63,
354,
9,
272,
340,
1962,
459,
2464,
280,
434,
63,
18,
418,
1137,
8061,
267,
1768,
275,
1962,
459,
2464,
280,
434,
63,
18,
418,
267,
1768,
63,
354,
275,
9005,
11123,
908,
8,
13837,
63,
6351,
12,
1768,
9,
267,
3628,
14,
740,
8,
1302,
63,
354,
9,
272,
340,
1962,
459,
2464,
280,
434,
63,
19,
418,
1137,
8061,
267,
1768,
275,
1962,
459,
2464,
280,
434,
63,
19,
418,
267,
1768,
63,
354,
275,
9005,
11123,
908,
8,
13837,
63,
6351,
12,
1768,
9,
267,
3628,
14,
740,
8,
1302,
63,
354,
9,
339,
327,
8232,
1564,
340,
1768,
440,
3495,
272,
340,
440,
3628,
26,
1980,
272,
1768,
63,
495,
275,
283,
1987,
904,
8,
3512,
9,
272,
3560,
63,
604,
275,
9005,
22902,
78,
1370,
908,
8,
1302,
63,
495,
12,
1564,
63,
495,
9,
272,
3560,
63,
493,
14,
952,
8,
2834,
63,
604,
9,
199,
199,
4737,
63,
493,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jh23453/privacyidea
|
privacyidea/lib/resolvers/LDAPIdResolver.py
|
1
|
41677
|
# -*- coding: utf-8 -*-
# Copyright (C) 2014 Cornelius Kölbel
# contact: corny@cornelinux.de
#
# 2017-01-23 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Add certificate verification
# 2017-01-07 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Use get_info=ldap3.NONE for binds to avoid querying of subschema
# Remove LDAPFILTER and self.reversefilter
# 2016-07-14 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Adding getUserId cache.
# 2016-04-13 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Add object_classes and dn_composition to configuration
# to allow flexible user_add
# 2016-04-10 Martin Wheldon <martin.wheldon@greenhills-it.co.uk>
# Allow user accounts held in LDAP to be edited, providing
# that the account they are using has permission to edit
# those attributes in the LDAP directory
# 2016-02-22 Salvo Rapisarda
# Allow objectGUID to be a users attribute
# 2016-02-19 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Allow objectGUID to be the uid.
# 2015-10-05 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Remove reverse_map, so that one LDAP field can map
# to several privacyIDEA fields.
# 2015-04-16 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Add redundancy with LDAP3 Server pools. Round Robin Strategy
# 2015-04-15 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Increase test coverage
# 2014-12-25 Cornelius Kölbel <cornelius@privacyidea.org>
# Rewrite for flask migration
#
# This code is free software; you can redistribute it and/or
# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
# License as published by the Free Software Foundation; either
# version 3 of the License, or any later version.
#
# This code 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/>.
#
__doc__ = """This is the resolver to find users in LDAP directories like
OpenLDAP and Active Directory.
The file is tested in tests/test_lib_resolver.py
"""
import logging
import yaml
import functools
from UserIdResolver import UserIdResolver
import ldap3
from ldap3 import MODIFY_REPLACE, MODIFY_ADD, MODIFY_DELETE
from ldap3 import Server, Tls, Connection
import ssl
import os.path
import traceback
import hashlib
import binascii
from privacyidea.lib.crypto import urandom, geturandom
from privacyidea.lib.utils import is_true
import datetime
from privacyidea.lib import _
from privacyidea.lib.utils import to_utf8
from privacyidea.lib.error import privacyIDEAError
import uuid
from ldap3.utils.conv import escape_bytes
CACHE = {}
log = logging.getLogger(__name__)
ENCODING = "utf-8"
# The number of rounds the resolver tries to reach a responding server in the
# pool
SERVERPOOL_ROUNDS = 2
# The number of seconds a non-responding server is removed from the server pool
SERVERPOOL_SKIP = 30
# 1 sec == 10^9 nano secs == 10^7 * (100 nano secs)
MS_AD_MULTIPLYER = 10 ** 7
MS_AD_START = datetime.datetime(1601, 1, 1)
if os.path.isfile("/etc/privacyidea/ldap-ca.crt"):
DEFAULT_CA_FILE = "/etc/privacyidea/ldap-ca.crt"
elif os.path.isfile("/etc/ssl/certs/ca-certificates.crt"):
DEFAULT_CA_FILE = "/etc/ssl/certs/ca-certificates.crt"
elif os.path.isfile("/etc/ssl/certs/ca-bundle.crt"):
DEFAULT_CA_FILE = "/etc/ssl/certs/ca-bundle.crt"
else:
DEFAULT_CA_FILE = "/etc/privacyidea/ldap-ca.crt"
def get_ad_timestamp_now():
"""
returns the current UTC time as it is used in Active Directory in the
attribute accountExpires.
This is 100-nano-secs since 1.1.1601
:return: time
:rtype: int
"""
utc_now = datetime.datetime.utcnow()
elapsed_time = utc_now - MS_AD_START
total_seconds = elapsed_time.total_seconds()
# convert this to (100 nanoseconds)
return int(MS_AD_MULTIPLYER * total_seconds)
def trim_objectGUID(userId):
userId = uuid.UUID("{{{0!s}}}".format(userId)).bytes_le
userId = escape_bytes(userId)
return userId
def get_info_configuration(noschemas):
"""
Given the value of the NOSCHEMAS config option, return the value that should
be passed as ldap3's `get_info` argument.
:param noschemas: a boolean
:return: one of ldap3.SCHEMA or ldap3.NONE
"""
get_schema_info = ldap3.SCHEMA
if noschemas:
get_schema_info = ldap3.NONE
log.debug("Get LDAP schema info: {0!s}".format(get_schema_info))
return get_schema_info
def cache(func):
"""
cache the user with his loginname, resolver and UID in a local
dictionary cache.
This is a per process cache.
"""
@functools.wraps(func)
def cache_wrapper(self, *args, **kwds):
# If it does not exist, create the node for this instance
resolver_id = self.getResolverId()
if not resolver_id in CACHE:
CACHE[resolver_id] = {"getUserId": {},
"getUserInfo": {},
"_getDN": {}}
# get the portion of the cache for this very LDAP resolver
r_cache = CACHE.get(resolver_id).get(func.func_name)
if args[0] in r_cache and \
datetime.datetime.now() < r_cache[args[0]][
"timestamp"] + \
datetime.timedelta(seconds=self.cache_timeout):
log.debug("Reading {0!s} from cache for {1!s}".format(args[0],
func.func_name))
return r_cache[args[0]]["value"]
f_result = func(self, *args, **kwds)
# now we cache the result
CACHE[resolver_id][func.func_name][args[0]] = {
"value": f_result,
"timestamp": datetime.datetime.now()}
return f_result
return cache_wrapper
class AUTHTYPE(object):
SIMPLE = "Simple"
SASL_DIGEST_MD5 = "SASL Digest-MD5"
NTLM = "NTLM"
class IdResolver (UserIdResolver):
# If the resolver could be configured editable
updateable = True
def __init__(self):
self.i_am_bound = False
self.uri = ""
self.basedn = ""
self.binddn = ""
self.bindpw = ""
self.object_classes = []
self.dn_template = ""
self.timeout = 5.0 # seconds!
self.sizelimit = 500
self.loginname_attribute = ""
self.searchfilter = ""
self.userinfo = {}
self.uidtype = ""
self.noreferrals = False
self._editable = False
self.resolverId = self.uri
self.scope = ldap3.SUBTREE
self.cache_timeout = 120
self.tls_context = None
self.start_tls = False
def checkPass(self, uid, password):
"""
This function checks the password for a given uid.
- returns true in case of success
- false if password does not match
"""
if self.authtype == AUTHTYPE.NTLM: # pragma: no cover
# fetch the PreWindows 2000 Domain from the self.binddn
# which would be of the format DOMAIN\username and compose the
# bind_user to DOMAIN\sAMAcountName
domain_name = self.binddn.split('\\')[0]
uinfo = self.getUserInfo(uid)
# In fact we need the sAMAccountName. If the username mapping is
# another attribute than the sAMAccountName the authentication
# will fail!
bind_user = "{0!s}\{1!s}".format(domain_name, uinfo.get("username"))
else:
bind_user = self._getDN(uid)
server_pool = self.get_serverpool(self.uri, self.timeout,
get_info=ldap3.NONE,
tls_context=self.tls_context)
try:
log.debug("Authtype: {0!r}".format(self.authtype))
log.debug("user : {0!r}".format(bind_user))
# Whatever happens. If we have an empty bind_user, we must break
# since we must avoid anonymous binds!
if not bind_user or len(bind_user) < 1:
raise Exception("No valid user. Empty bind_user.")
l = self.create_connection(authtype=self.authtype,
server=server_pool,
user=bind_user,
password=password,
receive_timeout=self.timeout,
auto_referrals=not self.noreferrals,
start_tls=self.start_tls)
r = l.bind()
log.debug("bind result: {0!r}".format(r))
if not r:
raise Exception("Wrong credentials")
log.debug("bind seems successful.")
l.unbind()
log.debug("unbind successful.")
except Exception as e:
log.warning("failed to check password for {0!r}/{1!r}: {2!r}".format(uid, bind_user, e))
log.debug(traceback.format_exc())
return False
return True
def _trim_result(self, result_list):
"""
The resultlist can contain entries of type:searchResEntry and of
type:searchResRef. If self.noreferrals is true, all type:searchResRef
will be removed.
:param result_list: The result list of a LDAP search
:type result_list: resultlist (list of dicts)
:return: new resultlist
"""
if self.noreferrals:
new_list = []
for result in result_list:
if result.get("type") == "searchResEntry":
new_list.append(result)
elif result.get("type") == "searchResRef":
# This is a Referral
pass
else:
new_list = result_list
return new_list
@staticmethod
def _escape_loginname(loginname):
"""
This function escapes the loginname according to
https://msdn.microsoft.com/en-us/library/aa746475(v=vs.85).aspx
This is to avoid username guessing by trying to login as user
a*
ac*
ach*
achm*
achme*
achemd*
:param loginname: The loginname
:return: The escaped loginname
"""
return loginname.replace("\\", "\\5c").replace("*", "\\2a").replace(
"(", "\\28").replace(")", "\\29").replace("/", "\\2f")
@staticmethod
def _get_uid(entry, uidtype):
uid = None
if uidtype.lower() == "dn":
uid = entry.get("dn")
else:
attributes = entry.get("attributes")
if type(attributes.get(uidtype)) == list:
uid = attributes.get(uidtype)[0]
else:
uid = attributes.get(uidtype)
return uid
def _trim_user_id(self, userId):
"""
If we search for the objectGUID we can not search for the normal
string representation but we need to search for the bytestring in AD.
:param userId: The userId
:return: the trimmed userId
"""
if self.uidtype == "objectGUID":
userId = trim_objectGUID(userId)
return userId
@cache
def _getDN(self, userId):
"""
This function returns the DN of a userId.
Therefor it evaluates the self.uidtype.
:param userId: The userid of a user
:type userId: string
:return: The DN of the object.
"""
dn = ""
if self.uidtype.lower() == "dn":
dn = userId
else:
# get the DN for the Object
self._bind()
search_userId = self._trim_user_id(userId)
filter = "(&{0!s}({1!s}={2!s}))".format(self.searchfilter,
self.uidtype, search_userId)
self.l.search(search_base=self.basedn,
search_scope=self.scope,
search_filter=filter,
attributes=self.userinfo.values())
r = self.l.response
r = self._trim_result(r)
if len(r) > 1: # pragma: no cover
raise Exception("Found more than one object for uid {0!r}".format(userId))
elif len(r) == 1:
dn = r[0].get("dn")
else:
log.info("The filter {0!s} returned no DN.".format(filter))
return dn
def _bind(self):
if not self.i_am_bound:
server_pool = self.get_serverpool(self.uri, self.timeout,
get_info=self.get_info,
tls_context=self.tls_context)
self.l = self.create_connection(authtype=self.authtype,
server=server_pool,
user=self.binddn,
password=self.bindpw,
receive_timeout=self.timeout,
auto_referrals=not
self.noreferrals,
start_tls=self.start_tls)
#log.error("LDAP Server Pool States: %s" % server_pool.pool_states)
if not self.l.bind():
raise Exception("Wrong credentials")
self.i_am_bound = True
@cache
def getUserInfo(self, userId):
"""
This function returns all user info for a given userid/object.
:param userId: The userid of the object
:type userId: string
:return: A dictionary with the keys defined in self.userinfo
:rtype: dict
"""
ret = {}
self._bind()
if self.uidtype.lower() == "dn":
# encode utf8, so that also german ulauts work in the DN
self.l.search(search_base=to_utf8(userId),
search_scope=self.scope,
search_filter="(&" + self.searchfilter + ")",
attributes=self.userinfo.values())
else:
search_userId = self._trim_user_id(userId)
filter = "(&{0!s}({1!s}={2!s}))".format(self.searchfilter,
self.uidtype, search_userId)
self.l.search(search_base=self.basedn,
search_scope=self.scope,
search_filter=filter,
attributes=self.userinfo.values())
r = self.l.response
r = self._trim_result(r)
if len(r) > 1: # pragma: no cover
raise Exception("Found more than one object for uid {0!r}".format(userId))
for entry in r:
attributes = entry.get("attributes")
ret = self._ldap_attributes_to_user_object(attributes)
return ret
def _ldap_attributes_to_user_object(self, attributes):
"""
This helper function converts the LDAP attributes to a dictionary for
the privacyIDEA user. The LDAP Userinfo mapping is used to do so.
:param attributes:
:return: dict with privacyIDEA users.
"""
ret = {}
for ldap_k, ldap_v in attributes.items():
for map_k, map_v in self.userinfo.items():
if ldap_k == map_v:
if ldap_k == "objectGUID":
ret[map_k] = ldap_v[0]
elif type(ldap_v) == list and map_k not in ["mobile"]:
# All lists (except) mobile return the first value as
# a string. Mobile is returned as a list
if ldap_v:
ret[map_k] = ldap_v[0]
else:
ret[map_k] = ""
else:
ret[map_k] = ldap_v
return ret
def getUsername(self, user_id):
"""
Returns the username/loginname for a given user_id
:param user_id: The user_id in this resolver
:type user_id: string
:return: username
:rtype: string
"""
info = self.getUserInfo(user_id)
return info.get('username', "")
@cache
def getUserId(self, LoginName):
"""
resolve the loginname to the userid.
:param LoginName: The login name from the credentials
:type LoginName: string
:return: UserId as found for the LoginName
"""
userid = ""
self._bind()
filter = "(&{0!s}({1!s}={2!s}))".format(self.searchfilter, self.loginname_attribute,
self._escape_loginname(LoginName))
# create search attributes
attributes = self.userinfo.values()
if self.uidtype.lower() != "dn":
attributes.append(str(self.uidtype))
log.debug("Searching user {0!r} in LDAP.".format(LoginName))
self.l.search(search_base=self.basedn,
search_scope=self.scope,
search_filter=filter,
attributes=attributes)
r = self.l.response
r = self._trim_result(r)
if len(r) > 1: # pragma: no cover
raise Exception("Found more than one object for Loginname {0!r}".format(
LoginName))
for entry in r:
userid = self._get_uid(entry, self.uidtype)
return userid
def getUserList(self, searchDict):
"""
:param searchDict: A dictionary with search parameters
:type searchDict: dict
:return: list of users, where each user is a dictionary
"""
ret = []
self._bind()
attributes = self.userinfo.values()
ad_timestamp = get_ad_timestamp_now()
if self.uidtype.lower() != "dn":
attributes.append(str(self.uidtype))
# do the filter depending on the searchDict
filter = u"(&" + self.searchfilter
for search_key in searchDict.keys():
if search_key == "accountExpires":
comperator = ">="
if searchDict[search_key] in ["1", 1]:
comperator = "<="
filter += "(&({0!s}{1!s}{2!s})(!({3!s}=0)))".format(self.userinfo[search_key],
comperator,
get_ad_timestamp_now(),
self.userinfo[search_key])
else:
filter += u"({0!s}={1!s})".format(self.userinfo[search_key],
searchDict[search_key])
filter += ")"
g = self.l.extend.standard.paged_search(search_base=self.basedn,
search_filter=filter,
search_scope=self.scope,
attributes=attributes,
paged_size=100,
size_limit=self.sizelimit,
generator=True)
# returns a generator of dictionaries
for entry in g:
# Simple fix for ignored sizelimit with Active Directory
if len(ret) >= self.sizelimit:
break
try:
attributes = entry.get("attributes")
user = self._ldap_attributes_to_user_object(attributes)
user['userid'] = self._get_uid(entry, self.uidtype)
ret.append(user)
except Exception as exx: # pragma: no cover
log.error("Error during fetching LDAP objects: {0!r}".format(exx))
log.debug("{0!s}".format(traceback.format_exc()))
return ret
def getResolverId(self):
"""
Returns the resolver Id
This should be an Identifier of the resolver, preferable the type
and the name of the resolver.
"""
s = "{0!s}{1!s}{2!s}{3!s}".format(self.uri, self.basedn,
self.searchfilter, self.userinfo)
r = binascii.hexlify(hashlib.sha1(s).digest())
return r
@staticmethod
def getResolverClassType():
return 'ldapresolver'
@staticmethod
def getResolverDescriptor():
return IdResolver.getResolverClassDescriptor()
@staticmethod
def getResolverType():
return IdResolver.getResolverClassType()
def loadConfig(self, config):
"""
Load the config from conf.
:param config: The configuration from the Config Table
:type config: dict
'#ldap_uri': 'LDAPURI',
'#ldap_basedn': 'LDAPBASE',
'#ldap_binddn': 'BINDDN',
'#ldap_password': 'BINDPW',
'#ldap_timeout': 'TIMEOUT',
'#ldap_sizelimit': 'SIZELIMIT',
'#ldap_loginattr': 'LOGINNAMEATTRIBUTE',
'#ldap_searchfilter': 'LDAPSEARCHFILTER',
'#ldap_mapping': 'USERINFO',
'#ldap_uidtype': 'UIDTYPE',
'#ldap_noreferrals' : 'NOREFERRALS',
'#ldap_editable' : 'EDITABLE',
'#ldap_certificate': 'CACERTIFICATE',
"""
self.uri = config.get("LDAPURI")
self.basedn = config.get("LDAPBASE")
self.binddn = config.get("BINDDN")
# object_classes is a comma separated list like
# ["top", "person", "organizationalPerson", "user", "inetOrgPerson"]
self.object_classes = [cl.strip() for cl in config.get("OBJECT_CLASSES", "").split(",")]
self.dn_template = config.get("DN_TEMPLATE", "")
self.bindpw = config.get("BINDPW")
self.timeout = float(config.get("TIMEOUT", 5))
self.cache_timeout = int(config.get("CACHE_TIMEOUT", 120))
self.sizelimit = int(config.get("SIZELIMIT", 500))
self.loginname_attribute = config.get("LOGINNAMEATTRIBUTE")
self.searchfilter = config.get("LDAPSEARCHFILTER")
userinfo = config.get("USERINFO", "{}")
self.userinfo = yaml.safe_load(userinfo)
self.userinfo["username"] = self.loginname_attribute
self.map = yaml.safe_load(userinfo)
self.uidtype = config.get("UIDTYPE", "DN")
self.noreferrals = is_true(config.get("NOREFERRALS", False))
self.start_tls = is_true(config.get("START_TLS", False))
self.get_info = get_info_configuration(is_true(config.get("NOSCHEMAS", False)))
self._editable = config.get("EDITABLE", False)
self.scope = config.get("SCOPE") or ldap3.SUBTREE
self.resolverId = self.uri
self.authtype = config.get("AUTHTYPE", AUTHTYPE.SIMPLE)
self.tls_verify = is_true(config.get("TLS_VERIFY", False))
self.tls_ca_file = config.get("TLS_CA_FILE") or DEFAULT_CA_FILE
if self.tls_verify and (self.uri.lower().startswith("ldaps") or
self.start_tls):
self.tls_context = Tls(validate=ssl.CERT_REQUIRED,
version=ssl.PROTOCOL_TLSv1,
ca_certs_file=self.tls_ca_file)
else:
self.tls_context = None
return self
@staticmethod
def split_uri(uri):
"""
Splits LDAP URIs like:
* ldap://server
* ldaps://server
* ldap[s]://server:1234
* server
:param uri: The LDAP URI
:return: Returns a tuple of Servername, Port and SSL(bool)
"""
port = None
ssl = False
ldap_elems = uri.split(":")
if len(ldap_elems) == 3:
server = ldap_elems[1].strip("/")
port = int(ldap_elems[2])
if ldap_elems[0].lower() == "ldaps":
ssl = True
else:
ssl = False
elif len(ldap_elems) == 2:
server = ldap_elems[1].strip("/")
port = None
if ldap_elems[0].lower() == "ldaps":
ssl = True
else:
ssl = False
else:
server = uri
return server, port, ssl
@classmethod
def get_serverpool(cls, urilist, timeout, get_info=None, tls_context=None):
"""
This create the serverpool for the ldap3 connection.
The URI from the LDAP resolver can contain a comma separated list of
LDAP servers. These are split and then added to the pool.
See
https://github.com/cannatag/ldap3/blob/master/docs/manual/source/servers.rst#server-pool
:param urilist: The list of LDAP URIs, comma separated
:type urilist: basestring
:param timeout: The connection timeout
:type timeout: float
:param get_info: The get_info type passed to the ldap3.Sever
constructor. default: ldap3.SCHEMA, should be ldap3.NONE in case
of a bind.
:param tls_context: A ldap3.tls object, which defines if certificate
verification should be performed
:return: Server Pool
:rtype: LDAP3 Server Pool Instance
"""
get_info = get_info or ldap3.SCHEMA
server_pool = ldap3.ServerPool(None, ldap3.ROUND_ROBIN,
active=SERVERPOOL_ROUNDS,
exhaust=SERVERPOOL_SKIP)
for uri in urilist.split(","):
uri = uri.strip()
host, port, ssl = cls.split_uri(uri)
server = ldap3.Server(host, port=port,
use_ssl=ssl,
connect_timeout=float(timeout),
get_info=get_info,
tls=tls_context)
server_pool.add(server)
log.debug("Added {0!s}, {1!s}, {2!s} to server pool.".format(host, port, ssl))
return server_pool
@classmethod
def getResolverClassDescriptor(cls):
"""
return the descriptor of the resolver, which is
- the class name and
- the config description
:return: resolver description dict
:rtype: dict
"""
descriptor = {}
typ = cls.getResolverType()
descriptor['clazz'] = "useridresolver.LDAPIdResolver.IdResolver"
descriptor['config'] = {'LDAPURI': 'string',
'LDAPBASE': 'string',
'BINDDN': 'string',
'BINDPW': 'password',
'TIMEOUT': 'int',
'SIZELIMIT': 'int',
'LOGINNAMEATTRIBUTE': 'string',
'LDAPSEARCHFILTER': 'string',
'USERINFO': 'string',
'UIDTYPE': 'string',
'NOREFERRALS': 'bool',
'NOSCHEMAS': 'bool',
'CACERTIFICATE': 'string',
'EDITABLE': 'bool',
'SCOPE': 'string',
'AUTHTYPE': 'string',
'TLS_VERIFY': 'bool',
'TLS_CA_FILE': 'string',
'START_TLS': 'bool'}
return {typ: descriptor}
@classmethod
def testconnection(cls, param):
"""
This function lets you test the to be saved LDAP connection.
:param param: A dictionary with all necessary parameter to test
the connection.
:type param: dict
:return: Tuple of success and a description
:rtype: (bool, string)
Parameters are:
BINDDN, BINDPW, LDAPURI, TIMEOUT, LDAPBASE, LOGINNAMEATTRIBUTE,
LDAPSEARCHFILTER, USERINFO, SIZELIMIT, NOREFERRALS, CACERTIFICATE,
AUTHTYPE, TLS_VERIFY, TLS_CA_FILE
"""
success = False
uidtype = param.get("UIDTYPE")
timeout = float(param.get("TIMEOUT", 5))
ldap_uri = param.get("LDAPURI")
size_limit = int(param.get("SIZELIMIT", 500))
if is_true(param.get("TLS_VERIFY")) \
and (ldap_uri.lower().startswith("ldaps") or
param.get("START_TLS")):
tls_ca_file = param.get("TLS_CA_FILE") or DEFAULT_CA_FILE
tls_context = Tls(validate=ssl.CERT_REQUIRED,
version=ssl.PROTOCOL_TLSv1,
ca_certs_file=tls_ca_file)
else:
tls_context = None
get_info = get_info_configuration(is_true(param.get("NOSCHEMAS")))
try:
server_pool = cls.get_serverpool(ldap_uri, timeout,
tls_context=tls_context,
get_info=get_info)
l = cls.create_connection(authtype=param.get("AUTHTYPE",
AUTHTYPE.SIMPLE),
server=server_pool,
user=param.get("BINDDN"),
password=param.get("BINDPW"),
receive_timeout=timeout,
auto_referrals=not param.get(
"NOREFERRALS"),
start_tls=param.get("START_TLS", False))
#log.error("LDAP Server Pool States: %s" % server_pool.pool_states)
if not l.bind():
raise Exception("Wrong credentials")
# create searchattributes
attributes = yaml.safe_load(param["USERINFO"]).values()
if uidtype.lower() != "dn":
attributes.append(str(uidtype))
# search for users...
g = l.extend.standard.paged_search(
search_base=param["LDAPBASE"],
search_filter="(&" + param["LDAPSEARCHFILTER"] + ")",
search_scope=param.get("SCOPE") or ldap3.SUBTREE,
attributes=attributes,
paged_size=100,
size_limit=size_limit,
generator=True)
# returns a generator of dictionaries
count = 0
uidtype_count = 0
for entry in g:
try:
userid = cls._get_uid(entry, uidtype)
count += 1
if userid:
uidtype_count += 1
except Exception as exx: # pragma: no cover
log.warning("Error during fetching LDAP objects:"
" {0!r}".format(exx))
log.debug("{0!s}".format(traceback.format_exc()))
if uidtype_count < count: # pragma: no cover
desc = _("Your LDAP config found %i user objects, but only %i "
"with the specified uidtype" % (count, uidtype_count))
else:
desc = _("Your LDAP config seems to be OK, %i user objects "
"found.") % count
l.unbind()
success = True
except Exception as e:
desc = "{0!r}".format(e)
return success, desc
def add_user(self, attributes=None):
"""
Add a new user to the LDAP directory.
The user can only be created in the LDAP using a DN.
So we have to construct the DN out of the given attributes.
attributes are these
"username", "surname", "givenname", "email",
"mobile", "phone", "password"
:param attributes: Attributes according to the attribute mapping
:type attributes: dict
:return: The new UID of the user. The UserIdResolver needs to
determine the way how to create the UID.
"""
# TODO: We still have some utf8 issues creating users with special characters.
attributes = attributes or {}
dn = self.dn_template
dn = dn.replace("<basedn>", self.basedn)
dn = dn.replace("<username>", attributes.get("username", ""))
dn = dn.replace("<givenname>", attributes.get("givenname", ""))
dn = dn.replace("<surname>", attributes.get("surname", ""))
try:
self._bind()
params = self._attributes_to_ldap_attributes(attributes)
self.l.add(dn, self.object_classes, params)
except Exception as e:
log.error("Error accessing LDAP server: {0}".format(e))
log.debug("{0}".format(traceback.format_exc()))
raise privacyIDEAError(e)
if self.l.result.get('result') != 0:
log.error("Error during adding of user {0}: {1}".format(dn, self.l.result.get('message')))
raise privacyIDEAError(self.l.result.get('message'))
return self.getUserId(attributes.get("username"))
def delete_user(self, uid):
"""
Delete a user from the LDAP Directory.
The user is referenced by the user id.
:param uid: The uid of the user object, that should be deleted.
:type uid: basestring
:return: Returns True in case of success
:rtype: bool
"""
res = True
try:
self._bind()
self.l.delete(self._getDN(uid))
except Exception as exx:
log.error("Error deleting user: {0}".format(exx))
res = False
return res
def _attributes_to_ldap_attributes(self, attributes):
"""
takes the attributes and maps them to the LDAP attributes
:param attributes: Attributes to be updated
:type attributes: dict
:return: dict with attribute name as keys and values
"""
ldap_attributes = {}
for fieldname, value in attributes.iteritems():
if self.map.get(fieldname):
if fieldname == "password":
# Variable value may be either a string or a list
# so catch the TypeError exception if we get the wrong
# variable type
try:
pw_hash = self._create_ssha(value[1][0])
value[1][0] = pw_hash
ldap_attributes[self.map.get(fieldname)] = value
except TypeError as e:
pw_hash = self._create_ssha(value)
ldap_attributes[self.map.get(fieldname)] = pw_hash
else:
ldap_attributes[self.map.get(fieldname)] = value
return ldap_attributes
@staticmethod
def _create_ssha(password):
"""
Encodes the given password as a base64 SSHA hash
:param password: string to hash
:type password: basestring
:return: string encoded as a base64 SSHA hash
"""
salt = geturandom(4)
# Hash password string and append the salt
sha_hash = hashlib.sha1(password)
sha_hash.update(salt)
# Create a base64 encoded string
digest_b64 = '{0}{1}'.format(sha_hash.digest(),
salt).encode('base64').strip()
# Tag it with SSHA
tagged_digest = '{{SSHA}}{}'.format(digest_b64)
return tagged_digest
def _create_ldap_modify_changes(self, attributes, uid):
"""
Identifies if an LDAP attribute already exists and if the value needs to be updated, deleted or added.
:param attributes: Attributes to be updated
:type attributes: dict
:param uid: The uid of the user object in the resolver
:type uid: basestring
:return: dict with attribute name as keys and values
"""
modify_changes = {}
uinfo = self.getUserInfo(uid)
for fieldname, value in attributes.iteritems():
if value:
if fieldname in uinfo:
modify_changes[fieldname] = [MODIFY_REPLACE, [value]]
else:
modify_changes[fieldname] = [MODIFY_ADD, [value]]
else:
modify_changes[fieldname] = [MODIFY_DELETE, [value]]
return modify_changes
def update_user(self, uid, attributes=None):
"""
Update an existing user.
This function is also used to update the password. Since the
attribute mapping know, which field contains the password,
this function can also take care for password changing.
Attributes that are not contained in the dict attributes are not
modified.
:param uid: The uid of the user object in the resolver.
:type uid: basestring
:param attributes: Attributes to be updated.
:type attributes: dict
:return: True in case of success
"""
attributes = attributes or {}
try:
self._bind()
mapped = self._create_ldap_modify_changes(attributes, uid)
params = self._attributes_to_ldap_attributes(mapped)
self.l.modify(self._getDN(uid), params)
except Exception as e:
log.error("Error accessing LDAP server: {0!s}".format(e))
log.debug("{0!s}".format(traceback.format_exc()))
return False
if self.l.result.get('result') != 0:
log.error("Error during update of user {0!s}: {1!s}".format(uid, self.l.result.get("message")))
return False
return True
@staticmethod
def create_connection(authtype=None, server=None, user=None,
password=None, auto_bind=False,
client_strategy=ldap3.SYNC,
check_names=True,
auto_referrals=False,
receive_timeout=5,
start_tls=False):
"""
Create a connection to the LDAP server.
:param authtype:
:param server:
:param user:
:param password:
:param auto_bind:
:param client_strategy:
:param check_names:
:param auto_referrals:
:param receive_timeout: At the moment we do not use this,
since receive_timeout is not supported by ldap3 < 2.
:return:
"""
authentication = None
if not user:
authentication = ldap3.ANONYMOUS
if authtype == AUTHTYPE.SIMPLE:
if not authentication:
authentication = ldap3.SIMPLE
# SIMPLE works with passwords as UTF8 and unicode
l = ldap3.Connection(server, user=user,
password=password,
auto_bind=auto_bind,
client_strategy=client_strategy,
authentication=authentication,
check_names=check_names,
# receive_timeout=receive_timeout,
auto_referrals=auto_referrals)
elif authtype == AUTHTYPE.NTLM: # pragma: no cover
if not authentication:
authentication = ldap3.NTLM
# NTLM requires the password to be unicode
l = ldap3.Connection(server,
user=user,
password=password,
auto_bind=auto_bind,
client_strategy=client_strategy,
authentication=authentication,
check_names=check_names,
# receive_timeout=receive_timeout,
auto_referrals=auto_referrals)
elif authtype == AUTHTYPE.SASL_DIGEST_MD5: # pragma: no cover
if not authentication:
authentication = ldap3.SASL
password = to_utf8(password)
sasl_credentials = (str(user), str(password))
l = ldap3.Connection(server,
sasl_mechanism="DIGEST-MD5",
sasl_credentials=sasl_credentials,
auto_bind=auto_bind,
client_strategy=client_strategy,
authentication=authentication,
check_names=check_names,
# receive_timeout=receive_timeout,
auto_referrals=auto_referrals)
else:
raise Exception("Authtype {0!s} not supported".format(authtype))
if start_tls:
l.open(read_server_info=False)
log.debug("Doing start_tls")
r = l.start_tls(read_server_info=False)
return l
@property
def editable(self):
"""
Return true, if the instance of the resolver is configured editable
:return:
"""
# Depending on the database this might look different
# Usually this is "1"
return is_true(self._editable)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
221,
1898,
334,
35,
9,
6927,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
199,
3,
221,
8966,
26,
221,
1970,
9745,
32,
989,
2715,
7226,
14,
271,
199,
3,
199,
3,
221,
9708,
13,
614,
13,
1789,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
2654,
5897,
14786,
199,
3,
221,
9708,
13,
614,
13,
1780,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
3645,
664,
63,
815,
29,
9642,
19,
14,
9185,
367,
5398,
83,
370,
5126,
27405,
402,
1007,
3629,
199,
3,
3777,
5852,
20717,
9905,
436,
291,
14,
4471,
1541,
199,
3,
221,
7800,
13,
1780,
13,
1079,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
12934,
664,
1899,
1304,
2581,
14,
199,
3,
221,
7800,
13,
966,
13,
969,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
2654,
909,
63,
2888,
436,
14052,
63,
13000,
370,
2897,
199,
3,
3777,
370,
2040,
26841,
922,
63,
525,
199,
3,
221,
7800,
13,
966,
13,
709,
603,
26788,
2816,
457,
265,
665,
77,
26788,
14,
2191,
457,
265,
32,
7731,
72,
15350,
13,
390,
14,
331,
14,
3210,
30,
199,
3,
3777,
9812,
922,
12639,
23608,
315,
20717,
370,
506,
21062,
12,
13070,
199,
3,
3777,
626,
314,
2933,
2985,
787,
1808,
965,
4983,
370,
5283,
199,
3,
3777,
5204,
3004,
315,
314,
20717,
2082,
199,
3,
221,
7800,
13,
996,
13,
1081,
428,
279,
2392,
820,
12662,
285,
983,
199,
3,
3777,
9812,
909,
17856,
370,
506,
282,
4390,
2225,
199,
3,
221,
7800,
13,
996,
13,
1167,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
9812,
909,
17856,
370,
506,
314,
1747,
14,
199,
3,
221,
6900,
13,
709,
13,
1717,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
5852,
3837,
63,
1130,
12,
880,
626,
1373,
20717,
901,
883,
2341,
199,
3,
3777,
370,
9978,
16254,
4085,
11259,
33,
1504,
14,
199,
3,
221,
6900,
13,
966,
13,
975,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
2654,
8992,
32270,
543,
20717,
19,
7146,
20092,
14,
31312,
6848,
1393,
8303,
5374,
199,
3,
221,
6900,
13,
966,
13,
1046,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
1010,
16772,
511,
11745,
199,
3,
221,
6927,
13,
713,
13,
821,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
32,
17258,
2655,
65,
14,
1308,
30,
199,
3,
3777,
799,
952,
367,
7209,
8367,
199,
3,
199,
3,
961,
1233,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
437,
1665,
12960,
29087,
748,
21755,
5113,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
650,
402,
314,
844,
12,
503,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
1233,
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,
437,
1665,
12960,
29087,
748,
21755,
5113,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
363,
1301,
363,
275,
408,
2765,
365,
314,
15611,
370,
2342,
4390,
315,
20717,
6602,
2839,
199,
4299,
19534,
436,
23241,
15191,
14,
199,
199,
1918,
570,
365,
12470,
315,
2295,
15,
396,
63,
773,
63,
7717,
14,
647,
199,
624,
199,
199,
646,
2050,
199,
646,
8864,
199,
646,
9143,
199,
199,
504,
2876,
1304,
12407,
492,
2876,
1304,
12407,
199,
199,
646,
13727,
19,
199,
504,
13727,
19,
492,
10362,
1914,
18114,
63,
27010,
12,
10362,
1914,
18114,
63,
9732,
12,
10362,
1914,
18114,
63,
7014,
199,
504,
13727,
19,
492,
7146,
12,
377,
478,
12,
8113,
199,
646,
6149,
199,
199,
646,
747,
14,
515,
199,
199,
646,
5190,
199,
199,
646,
8337,
199,
646,
14755,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
10316,
492,
7629,
1241,
12,
664,
22776,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
1208,
492,
365,
63,
2052,
199,
646,
2197,
199,
199,
504,
16254,
4085,
2655,
65,
14,
773,
492,
485,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
1208,
492,
370,
63,
1624,
24,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
705,
492,
16254,
4085,
11259,
33,
547,
199,
646,
5377,
199,
504,
13727,
19,
14,
1208,
14,
5598,
492,
4772,
63,
2394,
199,
199,
8677,
275,
1052,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
16314,
275,
298,
1624,
13,
24,
2,
199,
3,
710,
1329,
402,
27194,
314,
15611,
11275,
370,
12276,
282,
9163,
1098,
1654,
315,
314,
199,
3,
221,
4203,
199,
6613,
19693,
63,
1092,
1734,
3177,
275,
499,
199,
3,
710,
1329,
402,
4696,
282,
2222,
13,
31137,
1654,
365,
4829,
687,
314,
1654,
4203,
199,
6613,
19693,
63,
13525,
275,
4233,
199,
3,
413,
6513,
508,
1616,
62,
25,
302,
8143,
20091,
508,
1616,
62,
23,
627,
334,
1960,
302,
8143,
20091,
9,
199,
3053
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
221,
1898,
334,
35,
9,
6927,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
199,
3,
221,
8966,
26,
221,
1970,
9745,
32,
989,
2715,
7226,
14,
271,
199,
3,
199,
3,
221,
9708,
13,
614,
13,
1789,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
2654,
5897,
14786,
199,
3,
221,
9708,
13,
614,
13,
1780,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
3645,
664,
63,
815,
29,
9642,
19,
14,
9185,
367,
5398,
83,
370,
5126,
27405,
402,
1007,
3629,
199,
3,
3777,
5852,
20717,
9905,
436,
291,
14,
4471,
1541,
199,
3,
221,
7800,
13,
1780,
13,
1079,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
12934,
664,
1899,
1304,
2581,
14,
199,
3,
221,
7800,
13,
966,
13,
969,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
2654,
909,
63,
2888,
436,
14052,
63,
13000,
370,
2897,
199,
3,
3777,
370,
2040,
26841,
922,
63,
525,
199,
3,
221,
7800,
13,
966,
13,
709,
603,
26788,
2816,
457,
265,
665,
77,
26788,
14,
2191,
457,
265,
32,
7731,
72,
15350,
13,
390,
14,
331,
14,
3210,
30,
199,
3,
3777,
9812,
922,
12639,
23608,
315,
20717,
370,
506,
21062,
12,
13070,
199,
3,
3777,
626,
314,
2933,
2985,
787,
1808,
965,
4983,
370,
5283,
199,
3,
3777,
5204,
3004,
315,
314,
20717,
2082,
199,
3,
221,
7800,
13,
996,
13,
1081,
428,
279,
2392,
820,
12662,
285,
983,
199,
3,
3777,
9812,
909,
17856,
370,
506,
282,
4390,
2225,
199,
3,
221,
7800,
13,
996,
13,
1167,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
9812,
909,
17856,
370,
506,
314,
1747,
14,
199,
3,
221,
6900,
13,
709,
13,
1717,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
5852,
3837,
63,
1130,
12,
880,
626,
1373,
20717,
901,
883,
2341,
199,
3,
3777,
370,
9978,
16254,
4085,
11259,
33,
1504,
14,
199,
3,
221,
6900,
13,
966,
13,
975,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
2654,
8992,
32270,
543,
20717,
19,
7146,
20092,
14,
31312,
6848,
1393,
8303,
5374,
199,
3,
221,
6900,
13,
966,
13,
1046,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
14,
7697,
17778,
352,
32,
846,
18974,
2492,
14,
390,
30,
199,
3,
3777,
1010,
16772,
511,
11745,
199,
3,
221,
6927,
13,
713,
13,
821,
7499,
685,
317,
527,
1804,
14614,
6374,
352,
665,
989,
685,
317,
527,
32,
17258,
2655,
65,
14,
1308,
30,
199,
3,
3777,
799,
952,
367,
7209,
8367,
199,
3,
199,
3,
961,
1233,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
437,
1665,
12960,
29087,
748,
21755,
5113,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
650,
402,
314,
844,
12,
503,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
1233,
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,
437,
1665,
12960,
29087,
748,
21755,
5113,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
199,
3,
844,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
363,
1301,
363,
275,
408,
2765,
365,
314,
15611,
370,
2342,
4390,
315,
20717,
6602,
2839,
199,
4299,
19534,
436,
23241,
15191,
14,
199,
199,
1918,
570,
365,
12470,
315,
2295,
15,
396,
63,
773,
63,
7717,
14,
647,
199,
624,
199,
199,
646,
2050,
199,
646,
8864,
199,
646,
9143,
199,
199,
504,
2876,
1304,
12407,
492,
2876,
1304,
12407,
199,
199,
646,
13727,
19,
199,
504,
13727,
19,
492,
10362,
1914,
18114,
63,
27010,
12,
10362,
1914,
18114,
63,
9732,
12,
10362,
1914,
18114,
63,
7014,
199,
504,
13727,
19,
492,
7146,
12,
377,
478,
12,
8113,
199,
646,
6149,
199,
199,
646,
747,
14,
515,
199,
199,
646,
5190,
199,
199,
646,
8337,
199,
646,
14755,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
10316,
492,
7629,
1241,
12,
664,
22776,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
1208,
492,
365,
63,
2052,
199,
646,
2197,
199,
199,
504,
16254,
4085,
2655,
65,
14,
773,
492,
485,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
1208,
492,
370,
63,
1624,
24,
199,
504,
16254,
4085,
2655,
65,
14,
773,
14,
705,
492,
16254,
4085,
11259,
33,
547,
199,
646,
5377,
199,
504,
13727,
19,
14,
1208,
14,
5598,
492,
4772,
63,
2394,
199,
199,
8677,
275,
1052,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
16314,
275,
298,
1624,
13,
24,
2,
199,
3,
710,
1329,
402,
27194,
314,
15611,
11275,
370,
12276,
282,
9163,
1098,
1654,
315,
314,
199,
3,
221,
4203,
199,
6613,
19693,
63,
1092,
1734,
3177,
275,
499,
199,
3,
710,
1329,
402,
4696,
282,
2222,
13,
31137,
1654,
365,
4829,
687,
314,
1654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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
] |
ixs/func
|
func/overlord/cmd_modules/show.py
|
6
|
1062
|
"""
show introspection commandline
Copyright 2007, Red Hat, Inc
see AUTHORS
This software may be freely redistributed under the terms of the GNU
general public license.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
import optparse
import pprint
import xmlrpclib
from func.overlord import base_command
import show_hardware
class Show(base_command.BaseCommand):
name = "show"
usage = "show reports about minion info"
summary = usage
subCommandClasses = [show_hardware.ShowHardware]
def addOptions(self):
self.parser.add_option("-v", "--verbose", dest="verbose",
action="store_true")
def handleOptions(self, options):
self.options = options
self.verbose = options.verbose
def parse(self, argv):
self.argv = argv
return base_command.BaseCommand.parse(self, argv)
def do(self, args):
pass
|
gpl-2.0
|
[
624,
199,
2384,
1109,
14254,
28279,
199,
199,
7384,
10219,
12,
9572,
13002,
12,
3277,
199,
3239,
10610,
199,
199,
2765,
2032,
1443,
506,
20673,
7742,
295,
16832,
1334,
314,
2895,
402,
314,
1664,
199,
10706,
4575,
4190,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
1227,
2194,
603,
405,
437,
432,
12,
445,
455,
9528,
12,
4828,
12497,
7491,
12,
8217,
14,
199,
624,
421,
199,
646,
8691,
199,
646,
10933,
199,
646,
19122,
199,
199,
504,
2562,
14,
1883,
76,
2181,
492,
1300,
63,
1531,
199,
646,
2498,
63,
16529,
4388,
199,
533,
12968,
8,
1095,
63,
1531,
14,
25150,
304,
272,
536,
275,
298,
2384,
2,
272,
4503,
275,
298,
2384,
13924,
3595,
1748,
1636,
2256,
2,
272,
6212,
275,
4503,
272,
1007,
3110,
15711,
275,
359,
2384,
63,
16529,
14,
6824,
23219,
61,
339,
347,
1050,
4558,
8,
277,
304,
267,
291,
14,
2087,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
3044,
1595,
628,
1617,
63,
2052,
531,
339,
347,
2429,
4558,
8,
277,
12,
1511,
304,
267,
291,
14,
1419,
275,
1511,
398,
291,
14,
3832,
275,
1511,
14,
3832,
2378,
347,
2198,
8,
277,
12,
9238,
304,
267,
291,
14,
3020,
275,
9238,
398,
372,
1300,
63,
1531,
14,
25150,
14,
1122,
8,
277,
12,
9238,
9,
268,
339,
347,
886,
8,
277,
12,
1249,
304,
267,
986,
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
] |
[
199,
2384,
1109,
14254,
28279,
199,
199,
7384,
10219,
12,
9572,
13002,
12,
3277,
199,
3239,
10610,
199,
199,
2765,
2032,
1443,
506,
20673,
7742,
295,
16832,
1334,
314,
2895,
402,
314,
1664,
199,
10706,
4575,
4190,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
1227,
2194,
603,
405,
437,
432,
12,
445,
455,
9528,
12,
4828,
12497,
7491,
12,
8217,
14,
199,
624,
421,
199,
646,
8691,
199,
646,
10933,
199,
646,
19122,
199,
199,
504,
2562,
14,
1883,
76,
2181,
492,
1300,
63,
1531,
199,
646,
2498,
63,
16529,
4388,
199,
533,
12968,
8,
1095,
63,
1531,
14,
25150,
304,
272,
536,
275,
298,
2384,
2,
272,
4503,
275,
298,
2384,
13924,
3595,
1748,
1636,
2256,
2,
272,
6212,
275,
4503,
272,
1007,
3110,
15711,
275,
359,
2384,
63,
16529,
14,
6824,
23219,
61,
339,
347,
1050,
4558,
8,
277,
304,
267,
291,
14,
2087,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
628,
3832,
401,
3044,
1595,
628,
1617,
63,
2052,
531,
339,
347,
2429,
4558,
8,
277,
12,
1511,
304,
267,
291,
14,
1419,
275,
1511,
398,
291,
14,
3832,
275,
1511,
14,
3832,
2378,
347,
2198,
8,
277,
12,
9238,
304,
267,
291,
14,
3020,
275,
9238,
398,
372,
1300,
63,
1531,
14,
25150,
14,
1122,
8,
277,
12,
9238,
9,
268,
339,
347,
886,
8,
277,
12,
1249,
304,
267,
986,
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,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
blindfuzzy/LHF
|
Tools/linuxprivchk.py
|
1
|
25080
|
#!/usr/bin/env python
###############################################################################################################
## [Title]: linuxprivchecker.py -- a Linux Privilege Escalation Check Script
## [Author]: Mike Czumak (T_v3rn1x) -- @SecuritySift
##-------------------------------------------------------------------------------------------------------------
## [Details]:
## This script is intended to be executed locally on a Linux box to enumerate basic system info and
## search for common privilege escalation vectors such as world writable files, misconfigurations, clear-text
## passwords and applicable exploits.
##-------------------------------------------------------------------------------------------------------------
## [Warning]:
## This script comes as-is with no promise of functionality or accuracy. I have no plans to maintain updates,
## I did not write it to be efficient and in some cases you may find the functions may not produce the desired
## results. For example, the function that links packages to running processes is based on keywords and will
## not always be accurate. Also, the exploit list included in this function will need to be updated over time.
## Feel free to change or improve it any way you see fit.
##-------------------------------------------------------------------------------------------------------------
## [Modification, Distribution, and Attribution]:
## You are free to modify and/or distribute this script as you wish. I only ask that you maintain original
## author attribution and not attempt to sell it or incorporate it into any commercial offering (as if it's
## worth anything anyway :)
###############################################################################################################
# conditional import for older versions of python not compatible with subprocess
try:
import subprocess as sub
compatmode = 0 # newer version of python, no need for compatibility mode
except ImportError:
import os # older version of python, need to use os instead
compatmode = 1
# title / formatting
bigline = "================================================================================================="
smlline = "-------------------------------------------------------------------------------------------------"
print bigline
print "LINUX PRIVILEGE ESCALATION CHECKER"
print bigline
print
# loop through dictionary, execute the commands, store the results, return updated dict
def execCmd(cmdDict):
for item in cmdDict:
cmd = cmdDict[item]["cmd"]
if compatmode == 0: # newer version of python, use preferred subprocess
out, error = sub.Popen([cmd], stdout=sub.PIPE, stderr=sub.PIPE, shell=True).communicate()
results = out.split('\n')
else: # older version of python, use os.popen
echo_stdout = os.popen(cmd, 'r')
results = echo_stdout.read().split('\n')
cmdDict[item]["results"]=results
return cmdDict
# print results for each previously executed command, no return value
def printResults(cmdDict):
for item in cmdDict:
msg = cmdDict[item]["msg"]
results = cmdDict[item]["results"]
print "[+] " + msg
for result in results:
if result.strip() != "":
print " " + result.strip()
print
return
def writeResults(msg, results):
f = open("privcheckout.txt", "a");
f.write("[+] " + str(len(results)-1) + " " + msg)
for result in results:
if result.strip() != "":
f.write(" " + result.strip())
f.close()
return
# Basic system info
print "[*] GETTING BASIC SYSTEM INFO...\n"
results=[]
sysInfo = {"OS":{"cmd":"cat /etc/issue","msg":"Operating System","results":results},
"KERNEL":{"cmd":"cat /proc/version","msg":"Kernel","results":results},
"HOSTNAME":{"cmd":"hostname", "msg":"Hostname", "results":results}
}
sysInfo = execCmd(sysInfo)
printResults(sysInfo)
# Networking Info
print "[*] GETTING NETWORKING INFO...\n"
netInfo = {"NETINFO":{"cmd":"/sbin/ifconfig -a", "msg":"Interfaces", "results":results},
"ROUTE":{"cmd":"route", "msg":"Route", "results":results},
"NETSTAT":{"cmd":"netstat -antup | grep -v 'TIME_WAIT'", "msg":"Netstat", "results":results}
}
netInfo = execCmd(netInfo)
printResults(netInfo)
# File System Info
print "[*] GETTING FILESYSTEM INFO...\n"
driveInfo = {"MOUNT":{"cmd":"mount","msg":"Mount results", "results":results},
"FSTAB":{"cmd":"cat /etc/fstab 2>/dev/null", "msg":"fstab entries", "results":results}
}
driveInfo = execCmd(driveInfo)
printResults(driveInfo)
# Scheduled Cron Jobs
cronInfo = {"CRON":{"cmd":"ls -la /etc/cron* 2>/dev/null", "msg":"Scheduled cron jobs", "results":results},
"CRONW": {"cmd":"ls -aRl /etc/cron* 2>/dev/null | awk '$1 ~ /w.$/' 2>/dev/null", "msg":"Writable cron dirs", "results":results}
}
cronInfo = execCmd(cronInfo)
printResults(cronInfo)
# User Info
print "\n[*] ENUMERATING USER AND ENVIRONMENTAL INFO...\n"
userInfo = {"WHOAMI":{"cmd":"whoami", "msg":"Current User", "results":results},
"ID":{"cmd":"id","msg":"Current User ID", "results":results},
"ALLUSERS":{"cmd":"cat /etc/passwd", "msg":"All users", "results":results},
"SUPUSERS":{"cmd":"grep -v -E '^#' /etc/passwd | awk -F: '$3 == 0{print $1}'", "msg":"Super Users Found:", "results":results},
"HISTORY":{"cmd":"ls -la ~/.*_history; ls -la /root/.*_history 2>/dev/null", "msg":"Root and current user history (depends on privs)", "results":results},
"ENV":{"cmd":"env 2>/dev/null | grep -v 'LS_COLORS'", "msg":"Environment", "results":results},
"SUDOERS":{"cmd":"cat /etc/sudoers 2>/dev/null | grep -v '#' 2>/dev/null", "msg":"Sudoers (privileged)", "results":results},
"LOGGEDIN":{"cmd":"w 2>/dev/null", "msg":"Logged in User Activity", "results":results}
}
userInfo = execCmd(userInfo)
printResults(userInfo)
if "root" in userInfo["ID"]["results"][0]:
print "[!] ARE YOU SURE YOU'RE NOT ROOT ALREADY?\n"
# File/Directory Privs
print "[*] ENUMERATING FILE AND DIRECTORY PERMISSIONS/CONTENTS...\n"
fdPerms = {"WWDIRSROOT":{"cmd":"find / \( -wholename '/home/homedir*' -prune \) -o \( -type d -perm -0002 \) -exec ls -ld '{}' ';' 2>/dev/null | grep root", "msg":"World Writeable Directories for User/Group 'Root'", "results":results},
"WWDIRS":{"cmd":"find / \( -wholename '/home/homedir*' -prune \) -o \( -type d -perm -0002 \) -exec ls -ld '{}' ';' 2>/dev/null | grep -v root", "msg":"World Writeable Directories for Users other than Root", "results":results},
"WWFILES":{"cmd":"find / \( -wholename '/home/homedir/*' -prune -o -wholename '/proc/*' -prune \) -o \( -type f -perm -0002 \) -exec ls -l '{}' ';' 2>/dev/null", "msg":"World Writable Files", "results":results},
"SUID":{"cmd":"find / \( -perm -2000 -o -perm -4000 \) -exec ls -ld {} \; 2>/dev/null", "msg":"SUID/SGID Files and Directories", "results":results},
"ROOTHOME":{"cmd":"ls -ahlR /root 2>/dev/null", "msg":"Checking if root's home folder is accessible", "results":results}
}
fdPerms = execCmd(fdPerms)
printResults(fdPerms)
pwdFiles = {"LOGPWDS":{"cmd":"find /var/log -name '*.log' 2>/dev/null | xargs -l10 egrep 'pwd|password' 2>/dev/null", "msg":"Logs containing keyword 'password'", "results":results},
"CONFPWDS":{"cmd":"find /etc -name '*.c*' 2>/dev/null | xargs -l10 egrep 'pwd|password' 2>/dev/null", "msg":"Config files containing keyword 'password'", "results":results},
"SHADOW":{"cmd":"cat /etc/shadow 2>/dev/null", "msg":"Shadow File (Privileged)", "results":results}
}
pwdFiles = execCmd(pwdFiles)
printResults(pwdFiles)
# Processes and Applications
print "[*] ENUMERATING PROCESSES AND APPLICATIONS...\n"
if "debian" in sysInfo["KERNEL"]["results"][0] or "ubuntu" in sysInfo["KERNEL"]["results"][0]:
getPkgs = "dpkg -l | awk '{$1=$4=\"\"; print $0}'" # debian
else:
getPkgs = "rpm -qa | sort -u" # RH/other
getAppProc = {"PROCS":{"cmd":"ps aux | awk '{print $1,$2,$9,$10,$11}'", "msg":"Current processes", "results":results},
"PKGS":{"cmd":getPkgs, "msg":"Installed Packages", "results":results}
}
getAppProc = execCmd(getAppProc)
printResults(getAppProc) # comment to reduce output
otherApps = { "SUDO":{"cmd":"sudo -V | grep version 2>/dev/null", "msg":"Sudo Version (Check out http://www.exploit-db.com/search/?action=search&filter_page=1&filter_description=sudo)", "results":results},
"APACHE":{"cmd":"apache2 -v; apache2ctl -M; httpd -v; apachectl -l 2>/dev/null", "msg":"Apache Version and Modules", "results":results},
"APACHECONF":{"cmd":"cat /etc/apache2/apache2.conf 2>/dev/null", "msg":"Apache Config File", "results":results}
}
otherApps = execCmd(otherApps)
printResults(otherApps)
print "[*] IDENTIFYING PROCESSES AND PACKAGES RUNNING AS ROOT OR OTHER SUPERUSER...\n"
# find the package information for the processes currently running
# under root or another super user
procs = getAppProc["PROCS"]["results"]
pkgs = getAppProc["PKGS"]["results"]
supusers = userInfo["SUPUSERS"]["results"]
procdict = {} # dictionary to hold the processes running as super users
for proc in procs: # loop through each process
relatedpkgs = [] # list to hold the packages related to a process
try:
for user in supusers: # loop through the known super users
if (user != "") and (user in proc): # if the process is being run by a super user
procname = proc.split(" ")[4] # grab the process name
if "/" in procname:
splitname = procname.split("/")
procname = splitname[len(splitname)-1]
for pkg in pkgs: # loop through the packages
if not len(procname) < 3: # name too short to get reliable package results
if procname in pkg:
if procname in procdict:
relatedpkgs = procdict[proc] # if already in the dict, grab its pkg list
if pkg not in relatedpkgs:
relatedpkgs.append(pkg) # add pkg to the list
procdict[proc]=relatedpkgs # add any found related packages to the process dictionary entry
except:
pass
for key in procdict:
print " " + key # print the process name
try:
if not procdict[key][0] == "": # only print the rest if related packages were found
print " Possible Related Packages: "
for entry in procdict[key]:
print " " + entry # print each related package
except:
pass
# EXPLOIT ENUMERATION
# First discover the avaialable tools
print
print "[*] ENUMERATING INSTALLED LANGUAGES/TOOLS FOR SPLOIT BUILDING...\n"
devTools = {"TOOLS":{"cmd":"which awk perl python ruby gcc cc vi vim nmap find netcat nc wget tftp ftp 2>/dev/null", "msg":"Installed Tools", "results":results}}
devTools = execCmd(devTools)
printResults(devTools)
print "[+] Related Shell Escape Sequences...\n"
escapeCmd = {"vi":[":!bash", ":set shell=/bin/bash:shell"], "awk":["awk 'BEGIN {system(\"/bin/bash\")}'"], "perl":["perl -e 'exec \"/bin/bash\";'"], "find":["find / -exec /usr/bin/awk 'BEGIN {system(\"/bin/bash\")}' \\;"], "nmap":["--interactive"]}
for cmd in escapeCmd:
for result in devTools["TOOLS"]["results"]:
if cmd in result:
for item in escapeCmd[cmd]:
print " " + cmd + "-->\t" + item
print
print "[*] FINDING RELEVENT PRIVILEGE ESCALATION EXPLOITS...\n"
# Now check for relevant exploits (note: this list should be updated over time; source: Exploit-DB)
# sploit format = sploit name : {minversion, maxversion, exploitdb#, language, {keywords for applicability}} -- current keywords are 'kernel', 'proc', 'pkg' (unused), and 'os'
sploits= { "2.2.x-2.4.x ptrace kmod local exploit":{"minver":"2.2", "maxver":"2.4.99", "exploitdb":"3", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.4.20 Module Loader Local Root Exploit":{"minver":"0", "maxver":"2.4.20", "exploitdb":"12", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4.22 "'do_brk()'" local Root Exploit (PoC)":{"minver":"2.4.22", "maxver":"2.4.22", "exploitdb":"129", "lang":"asm", "keywords":{"loc":["kernel"], "val":"kernel"}},
"<= 2.4.22 (do_brk) Local Root Exploit (working)":{"minver":"0", "maxver":"2.4.22", "exploitdb":"131", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4.x mremap() bound checking Root Exploit":{"minver":"2.4", "maxver":"2.4.99", "exploitdb":"145", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"<= 2.4.29-rc2 uselib() Privilege Elevation":{"minver":"0", "maxver":"2.4.29", "exploitdb":"744", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4 uselib() Privilege Elevation Exploit":{"minver":"2.4", "maxver":"2.4", "exploitdb":"778", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4.x / 2.6.x uselib() Local Privilege Escalation Exploit":{"minver":"2.4", "maxver":"2.6.99", "exploitdb":"895", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4/2.6 bluez Local Root Privilege Escalation Exploit (update)":{"minver":"2.4", "maxver":"2.6.99", "exploitdb":"926", "lang":"c", "keywords":{"loc":["proc","pkg"], "val":"bluez"}},
"<= 2.6.11 (CPL 0) Local Root Exploit (k-rad3.c)":{"minver":"0", "maxver":"2.6.11", "exploitdb":"1397", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"MySQL 4.x/5.0 User-Defined Function Local Privilege Escalation Exploit":{"minver":"0", "maxver":"99", "exploitdb":"1518", "lang":"c", "keywords":{"loc":["proc","pkg"], "val":"mysql"}},
"2.6.13 <= 2.6.17.4 sys_prctl() Local Root Exploit":{"minver":"2.6.13", "maxver":"2.6.17.4", "exploitdb":"2004", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.13 <= 2.6.17.4 sys_prctl() Local Root Exploit (2)":{"minver":"2.6.13", "maxver":"2.6.17.4", "exploitdb":"2005", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.13 <= 2.6.17.4 sys_prctl() Local Root Exploit (3)":{"minver":"2.6.13", "maxver":"2.6.17.4", "exploitdb":"2006", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.13 <= 2.6.17.4 sys_prctl() Local Root Exploit (4)":{"minver":"2.6.13", "maxver":"2.6.17.4", "exploitdb":"2011", "lang":"sh", "keywords":{"loc":["kernel"], "val":"kernel"}},
"<= 2.6.17.4 (proc) Local Root Exploit":{"minver":"0", "maxver":"2.6.17.4", "exploitdb":"2013", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.13 <= 2.6.17.4 prctl() Local Root Exploit (logrotate)":{"minver":"2.6.13", "maxver":"2.6.17.4", "exploitdb":"2031", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Ubuntu/Debian Apache 1.3.33/1.3.34 (CGI TTY) Local Root Exploit":{"minver":"4.10", "maxver":"7.04", "exploitdb":"3384", "lang":"c", "keywords":{"loc":["os"], "val":"debian"}},
"Linux/Kernel 2.4/2.6 x86-64 System Call Emulation Exploit":{"minver":"2.4", "maxver":"2.6", "exploitdb":"4460", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.6.11.5 BLUETOOTH Stack Local Root Exploit":{"minver":"0", "maxver":"2.6.11.5", "exploitdb":"4756", "lang":"c", "keywords":{"loc":["proc","pkg"], "val":"bluetooth"}},
"2.6.17 - 2.6.24.1 vmsplice Local Root Exploit":{"minver":"2.6.17", "maxver":"2.6.24.1", "exploitdb":"5092", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.23 - 2.6.24 vmsplice Local Root Exploit":{"minver":"2.6.23", "maxver":"2.6.24", "exploitdb":"5093", "lang":"c", "keywords":{"loc":["os"], "val":"debian"}},
"Debian OpenSSL Predictable PRNG Bruteforce SSH Exploit":{"minver":"0", "maxver":"99", "exploitdb":"5720", "lang":"python", "keywords":{"loc":["os"], "val":"debian"}},
"Linux Kernel < 2.6.22 ftruncate()/open() Local Exploit":{"minver":"0", "maxver":"2.6.22", "exploitdb":"6851", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.6.29 exit_notify() Local Privilege Escalation Exploit":{"minver":"0", "maxver":"2.6.29", "exploitdb":"8369", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6 UDEV Local Privilege Escalation Exploit":{"minver":"2.6", "maxver":"2.6.99", "exploitdb":"8478", "lang":"c", "keywords":{"loc":["proc","pkg"], "val":"udev"}},
"2.6 UDEV < 141 Local Privilege Escalation Exploit":{"minver":"2.6", "maxver":"2.6.99", "exploitdb":"8572", "lang":"c", "keywords":{"loc":["proc","pkg"], "val":"udev"}},
"2.6.x ptrace_attach Local Privilege Escalation Exploit":{"minver":"2.6", "maxver":"2.6.99", "exploitdb":"8673", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.29 ptrace_attach() Local Root Race Condition Exploit":{"minver":"2.6.29", "maxver":"2.6.29", "exploitdb":"8678", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Linux Kernel <=2.6.28.3 set_selection() UTF-8 Off By One Local Exploit":{"minver":"0", "maxver":"2.6.28.3", "exploitdb":"9083", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Test Kernel Local Root Exploit 0day":{"minver":"2.6.18", "maxver":"2.6.30", "exploitdb":"9191", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"PulseAudio (setuid) Priv. Escalation Exploit (ubu/9.04)(slack/12.2.0)":{"minver":"2.6.9", "maxver":"2.6.30", "exploitdb":"9208", "lang":"c", "keywords":{"loc":["pkg"], "val":"pulse"}},
"2.x sock_sendpage() Local Ring0 Root Exploit":{"minver":"2", "maxver":"2.99", "exploitdb":"9435", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.x sock_sendpage() Local Root Exploit 2":{"minver":"2", "maxver":"2.99", "exploitdb":"9436", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4/2.6 sock_sendpage() ring0 Root Exploit (simple ver)":{"minver":"2.4", "maxver":"2.6.99", "exploitdb":"9479", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6 < 2.6.19 (32bit) ip_append_data() ring0 Root Exploit":{"minver":"2.6", "maxver":"2.6.19", "exploitdb":"9542", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4/2.6 sock_sendpage() Local Root Exploit (ppc)":{"minver":"2.4", "maxver":"2.6.99", "exploitdb":"9545", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.6.19 udp_sendmsg Local Root Exploit (x86/x64)":{"minver":"0", "maxver":"2.6.19", "exploitdb":"9574", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.6.19 udp_sendmsg Local Root Exploit":{"minver":"0", "maxver":"2.6.19", "exploitdb":"9575", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4/2.6 sock_sendpage() Local Root Exploit [2]":{"minver":"2.4", "maxver":"2.6.99", "exploitdb":"9598", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4/2.6 sock_sendpage() Local Root Exploit [3]":{"minver":"2.4", "maxver":"2.6.99", "exploitdb":"9641", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4.1-2.4.37 and 2.6.1-2.6.32-rc5 Pipe.c Privelege Escalation":{"minver":"2.4.1", "maxver":"2.6.32", "exploitdb":"9844", "lang":"python", "keywords":{"loc":["kernel"], "val":"kernel"}},
"'pipe.c' Local Privilege Escalation Vulnerability":{"minver":"2.4.1", "maxver":"2.6.32", "exploitdb":"10018", "lang":"sh", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.6.18-20 2009 Local Root Exploit":{"minver":"2.6.18", "maxver":"2.6.20", "exploitdb":"10613", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Apache Spamassassin Milter Plugin Remote Root Command Execution":{"minver":"0", "maxver":"99", "exploitdb":"11662", "lang":"sh", "keywords":{"loc":["proc"], "val":"spamass-milter"}},
"<= 2.6.34-rc3 ReiserFS xattr Privilege Escalation":{"minver":"0", "maxver":"2.6.34", "exploitdb":"12130", "lang":"python", "keywords":{"loc":["mnt"], "val":"reiser"}},
"Ubuntu PAM MOTD local root":{"minver":"7", "maxver":"10.04", "exploitdb":"14339", "lang":"sh", "keywords":{"loc":["os"], "val":"ubuntu"}},
"< 2.6.36-rc1 CAN BCM Privilege Escalation Exploit":{"minver":"0", "maxver":"2.6.36", "exploitdb":"14814", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Kernel ia32syscall Emulation Privilege Escalation":{"minver":"0", "maxver":"99", "exploitdb":"15023", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Linux RDS Protocol Local Privilege Escalation":{"minver":"0", "maxver":"2.6.36", "exploitdb":"15285", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"<= 2.6.37 Local Privilege Escalation":{"minver":"0", "maxver":"2.6.37", "exploitdb":"15704", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.6.37-rc2 ACPI custom_method Privilege Escalation":{"minver":"0", "maxver":"2.6.37", "exploitdb":"15774", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"CAP_SYS_ADMIN to root Exploit":{"minver":"0", "maxver":"99", "exploitdb":"15916", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"CAP_SYS_ADMIN to Root Exploit 2 (32 and 64-bit)":{"minver":"0", "maxver":"99", "exploitdb":"15944", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"< 2.6.36.2 Econet Privilege Escalation Exploit":{"minver":"0", "maxver":"2.6.36.2", "exploitdb":"17787", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Sendpage Local Privilege Escalation":{"minver":"0", "maxver":"99", "exploitdb":"19933", "lang":"ruby", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.4.18/19 Privileged File Descriptor Resource Exhaustion Vulnerability":{"minver":"2.4.18", "maxver":"2.4.19", "exploitdb":"21598", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.2.x/2.4.x Privileged Process Hijacking Vulnerability (1)":{"minver":"2.2", "maxver":"2.4.99", "exploitdb":"22362", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"2.2.x/2.4.x Privileged Process Hijacking Vulnerability (2)":{"minver":"2.2", "maxver":"2.4.99", "exploitdb":"22363", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
"Samba 2.2.8 Share Local Privilege Elevation Vulnerability":{"minver":"2.2.8", "maxver":"2.2.8", "exploitdb":"23674", "lang":"c", "keywords":{"loc":["proc","pkg"], "val":"samba"}},
"open-time Capability file_ns_capable() Privilege Escalation":{"minver":"0", "maxver":"99", "exploitdb":"25450", "lang":"c", "keywords":{"loc":["kernel"], "val":"kernel"}},
}
# variable declaration
os = sysInfo["OS"]["results"][0]
version = sysInfo["KERNEL"]["results"][0].split(" ")[2].split("-")[0]
langs = devTools["TOOLS"]["results"]
procs = getAppProc["PROCS"]["results"]
kernel = str(sysInfo["KERNEL"]["results"][0])
mount = driveInfo["MOUNT"]["results"]
#pkgs = getAppProc["PKGS"]["results"] # currently not using packages for sploit appicability but my in future
# lists to hold ranked, applicable sploits
# note: this is a best-effort, basic ranking designed to help in prioritizing priv escalation exploit checks
# all applicable exploits should be checked and this function could probably use some improvement
avgprob = []
highprob = []
for sploit in sploits:
lang = 0 # use to rank applicability of sploits
keyword = sploits[sploit]["keywords"]["val"]
sploitout = sploit + " || " + "http://www.exploit-db.com/exploits/" + sploits[sploit]["exploitdb"] + " || " + "Language=" + sploits[sploit]["lang"]
# first check for kernell applicability
if (version >= sploits[sploit]["minver"]) and (version <= sploits[sploit]["maxver"]):
# next check language applicability
if (sploits[sploit]["lang"] == "c") and (("gcc" in str(langs)) or ("cc" in str(langs))):
lang = 1 # language found, increase applicability score
elif sploits[sploit]["lang"] == "sh":
lang = 1 # language found, increase applicability score
elif (sploits[sploit]["lang"] in str(langs)):
lang = 1 # language found, increase applicability score
if lang == 0:
sploitout = sploitout + "**" # added mark if language not detected on system
# next check keyword matches to determine if some sploits have a higher probability of success
for loc in sploits[sploit]["keywords"]["loc"]:
if loc == "proc":
for proc in procs:
if keyword in proc:
highprob.append(sploitout) # if sploit is associated with a running process consider it a higher probability/applicability
break
break
elif loc == "os":
if (keyword in os) or (keyword in kernel):
highprob.append(sploitout) # if sploit is specifically applicable to this OS consider it a higher probability/applicability
break
elif loc == "mnt":
if keyword in mount:
highprob.append(sploitout) # if sploit is specifically applicable to a mounted file system consider it a higher probability/applicability
break
else:
avgprob.append(sploitout) # otherwise, consider average probability/applicability based only on kernel version
print " Note: Exploits relying on a compile/scripting language not detected on this system are marked with a '**' but should still be tested!"
print
print " The following exploits are ranked higher in probability of success because this script detected a related running process, OS, or mounted file system"
for exploit in highprob:
print " - " + exploit
print
print " The following exploits are applicable to this kernel version and should be investigated as well"
for exploit in avgprob:
print " - " + exploit
print
print "Finished"
print bigline
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3060,
26634,
14776,
199,
309,
359,
6888,
2189,
18369,
10605,
6743,
14,
647,
1553,
282,
10130,
8538,
17228,
662,
4732,
425,
2670,
14914,
199,
309,
359,
5949,
2189,
603,
7455,
445,
90,
85,
22191,
334,
52,
63,
86,
19,
11641,
17,
88,
9,
1553,
768,
7676,
51,
2949,
199,
309,
3606,
1444,
8684,
199,
309,
359,
11347,
2189,
199,
309,
961,
2884,
365,
11619,
370,
506,
7934,
17738,
641,
282,
10130,
5689,
370,
3874,
5678,
2656,
2256,
436,
199,
309,
2754,
367,
2863,
1979,
17228,
325,
4732,
425,
11102,
4066,
465,
6701,
17267,
1584,
12,
3201,
10057,
12,
5436,
13,
505,
199,
309,
19572,
436,
3964,
15868,
1405,
14,
199,
309,
3606,
1444,
8684,
199,
309,
359,
3849,
2189,
199,
309,
961,
2884,
12477,
465,
13,
374,
543,
949,
8023,
572,
402,
9330,
503,
12862,
14,
221,
473,
1172,
949,
1620,
796,
370,
11075,
7029,
12,
199,
309,
473,
8103,
440,
2218,
652,
370,
506,
13402,
436,
315,
2005,
5560,
1265,
1443,
2342,
314,
3423,
1443,
440,
7389,
314,
6387,
199,
309,
2058,
14,
221,
2104,
2893,
12,
314,
805,
626,
6220,
6117,
370,
3879,
10358,
365,
4079,
641,
7681,
436,
911,
199,
309,
440,
3544,
506,
23189,
14,
221,
6121,
12,
314,
15868,
390,
769,
5120,
315,
642,
805,
911,
1929,
370,
506,
4588,
1806,
900,
14,
199,
309,
7949,
352,
2867,
370,
1570,
503,
19053,
652,
1263,
4340,
1265,
1937,
5542,
14,
199,
309,
3606,
1444,
8684,
199,
309,
359,
29188,
12,
11839,
12,
436,
2854,
15980,
2189,
199,
309,
2047,
787,
2867,
370,
2811,
436,
15,
269,
11207,
642,
2884,
465,
1265,
13809,
14,
221,
473,
1454,
7198,
626,
1265,
11075,
3379,
199,
309,
4132,
737,
15980,
436,
440,
7427,
370,
12743,
652,
503,
30147,
323,
652,
1901,
1263,
2414,
23012,
2331,
15663,
334,
305,
340,
652,
1159,
199,
309,
25235,
7003,
15988,
32428,
199,
3060,
26634,
14776,
199,
199,
3,
12303,
492,
367,
12731,
5459,
402,
2366,
440,
9025,
543,
3873,
199,
893,
26,
272,
492,
3873,
465,
1007,
272,
8434,
632,
275,
378,
327,
15666,
1015,
402,
2366,
12,
949,
1929,
367,
7163,
818,
199,
2590,
3545,
26,
272,
492,
747,
327,
12731,
1015,
402,
2366,
12,
1929,
370,
675,
747,
3140,
272,
8434,
632,
275,
413,
199,
199,
3,
2538,
1182,
10803,
199,
5076,
604,
275,
298,
5695,
2486,
628,
199,
83,
757,
604,
275,
298,
3606,
1444,
23245,
199,
199,
1361,
7282,
604,
199,
1361,
298,
26030,
28644,
8453,
4962,
10427,
13329,
2594,
17654,
540,
2,
199,
1361,
7282,
604,
199,
1361,
199,
199,
3,
4438,
4012,
2600,
12,
5341,
314,
3718,
12,
3877,
314,
2058,
12,
372,
4588,
1211,
199,
318,
2146,
7874,
8,
1760,
2141,
304,
272,
367,
1242,
315,
2088,
2141,
26,
267,
2088,
275,
2088,
2141,
59,
1053,
7541,
1760,
937,
199,
198,
692,
8434,
632,
508,
378,
26,
327,
15666,
1015,
402,
2366,
12,
675,
14388,
3873,
288,
734,
12,
1125,
275,
1007,
14,
7942,
779,
1760,
467,
3839,
29,
954,
14,
6089,
12,
4635,
29,
954,
14,
6089,
12,
5218,
29,
549,
680,
10664,
342,
288,
2058,
275,
734,
14,
1294,
2258,
78,
358,
199,
198,
2836,
26,
327,
12731,
1015,
402,
2366,
12,
675,
747,
14,
12207,
6722,
11343,
63,
2703,
275,
747,
14,
12207,
8,
1760,
12,
283,
82,
358,
288,
2058,
275,
11343,
63,
2703,
14,
739,
1252,
1294,
2258,
78,
358,
267,
2088,
2141,
59,
1053,
7541,
2604,
8713,
2604,
272,
372,
2088,
2141,
199,
199,
3,
870,
2058,
367,
1924,
10889,
7934,
1414,
12,
949,
372,
574,
199,
318,
870,
6579,
8,
1760,
2141,
304,
272,
367,
1242,
315,
2088,
2141,
26,
199,
198,
1328,
275,
2088,
2141,
59,
1053,
7541,
1328,
937,
199,
198,
2604,
275,
2088,
2141,
59,
1053,
7541,
2604,
937,
267,
870,
7369,
11,
61,
298,
435,
1499,
267,
367,
754,
315,
2058,
26,
6722,
340,
754,
14,
1913,
342,
1137,
10812,
507,
263,
870,
298,
259,
298,
435,
754,
14,
1913,
342,
199,
198,
1361,
272,
372,
199,
199,
318,
2218,
6579,
8,
1328,
12,
2058,
304,
272,
289,
275,
1551,
480,
10605,
12891,
14,
2424,
401,
298,
65,
3547,
272,
289,
14,
952,
10994,
11,
61,
298,
435,
620,
8,
552,
8,
2604,
7216,
17,
9,
435,
298,
298,
435,
1499,
9,
272,
367,
754,
315,
2058,
26,
267,
340,
754,
14,
1913,
342,
1137,
10812,
288,
289,
14,
952,
480,
259,
298,
435,
754,
14,
1913,
1012,
272,
289,
14,
1600,
342,
272,
372,
199,
199,
3,
10082,
2656,
2256,
199,
1361,
7369,
30431,
9576,
52,
1206,
4147,
948,
20859,
24008,
29279,
78,
2,
199,
199,
2604,
9811,
199,
199,
1274,
2354,
275,
2420,
3100,
18517,
1760,
5122,
3385,
1182,
6839,
15,
5237,
2266,
1328,
5122,
23699,
6187,
2266,
2604,
582,
2604,
1386,
21979,
298,
30142,
18517,
1760,
5122,
3385,
1182,
4687,
15,
1023,
2266,
1328,
5122,
14127,
2266,
2604,
582,
2604,
1386,
21979,
298,
22647,
18517,
1760,
5122,
4269,
401,
298,
1328,
5122,
25680,
401,
298,
2604,
582,
2604,
93,
17957,
789,
199,
199,
1274,
2354,
275,
2146,
7874,
8,
1274,
2354,
9,
199,
1361,
6579,
8,
1274,
2354,
9,
199,
199,
3,
7220,
316,
10332,
199,
199,
1361,
7369,
30431,
9576,
52,
1206,
18340,
8406,
1206,
24008,
29279,
78,
2,
199,
199,
846,
2354,
275,
2420,
7278,
4531,
18517,
1760,
5122,
15,
21457,
15,
692,
888,
446,
65,
401,
298,
1328,
5122,
18680,
401,
298,
2604,
582,
2604,
1386,
21979,
298,
1092,
4586,
18517,
1760,
5122,
4449,
401,
298,
1328,
5122,
7161,
401,
298,
2604,
582,
2604,
1386,
21979,
298,
7278,
4315,
18517,
1760,
5122,
846,
3736,
446,
867,
384,
1204,
20595,
446,
86,
283,
4961,
63,
12458,
4662,
298,
1328,
5122,
2480,
3736,
401,
298,
2604,
582,
2604,
93,
17957,
789,
199,
199,
846,
2354,
275,
2146,
7874,
8,
846,
2354,
9,
199,
1361,
6579,
8,
846,
2354,
9,
199,
199,
3,
3814,
6187,
10332,
199,
1361,
7369,
30431,
9576,
52,
1206,
16444,
654,
57,
9757,
24008,
29279,
78,
2,
199,
199,
9541,
2354,
275,
2420,
2679,
17252,
18517,
1760,
5122,
3956,
2266,
1328,
5122,
24467,
2058,
401,
298,
2604,
582,
2604,
1386,
507,
258,
298,
38
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3060,
26634,
14776,
199,
309,
359,
6888,
2189,
18369,
10605,
6743,
14,
647,
1553,
282,
10130,
8538,
17228,
662,
4732,
425,
2670,
14914,
199,
309,
359,
5949,
2189,
603,
7455,
445,
90,
85,
22191,
334,
52,
63,
86,
19,
11641,
17,
88,
9,
1553,
768,
7676,
51,
2949,
199,
309,
3606,
1444,
8684,
199,
309,
359,
11347,
2189,
199,
309,
961,
2884,
365,
11619,
370,
506,
7934,
17738,
641,
282,
10130,
5689,
370,
3874,
5678,
2656,
2256,
436,
199,
309,
2754,
367,
2863,
1979,
17228,
325,
4732,
425,
11102,
4066,
465,
6701,
17267,
1584,
12,
3201,
10057,
12,
5436,
13,
505,
199,
309,
19572,
436,
3964,
15868,
1405,
14,
199,
309,
3606,
1444,
8684,
199,
309,
359,
3849,
2189,
199,
309,
961,
2884,
12477,
465,
13,
374,
543,
949,
8023,
572,
402,
9330,
503,
12862,
14,
221,
473,
1172,
949,
1620,
796,
370,
11075,
7029,
12,
199,
309,
473,
8103,
440,
2218,
652,
370,
506,
13402,
436,
315,
2005,
5560,
1265,
1443,
2342,
314,
3423,
1443,
440,
7389,
314,
6387,
199,
309,
2058,
14,
221,
2104,
2893,
12,
314,
805,
626,
6220,
6117,
370,
3879,
10358,
365,
4079,
641,
7681,
436,
911,
199,
309,
440,
3544,
506,
23189,
14,
221,
6121,
12,
314,
15868,
390,
769,
5120,
315,
642,
805,
911,
1929,
370,
506,
4588,
1806,
900,
14,
199,
309,
7949,
352,
2867,
370,
1570,
503,
19053,
652,
1263,
4340,
1265,
1937,
5542,
14,
199,
309,
3606,
1444,
8684,
199,
309,
359,
29188,
12,
11839,
12,
436,
2854,
15980,
2189,
199,
309,
2047,
787,
2867,
370,
2811,
436,
15,
269,
11207,
642,
2884,
465,
1265,
13809,
14,
221,
473,
1454,
7198,
626,
1265,
11075,
3379,
199,
309,
4132,
737,
15980,
436,
440,
7427,
370,
12743,
652,
503,
30147,
323,
652,
1901,
1263,
2414,
23012,
2331,
15663,
334,
305,
340,
652,
1159,
199,
309,
25235,
7003,
15988,
32428,
199,
3060,
26634,
14776,
199,
199,
3,
12303,
492,
367,
12731,
5459,
402,
2366,
440,
9025,
543,
3873,
199,
893,
26,
272,
492,
3873,
465,
1007,
272,
8434,
632,
275,
378,
327,
15666,
1015,
402,
2366,
12,
949,
1929,
367,
7163,
818,
199,
2590,
3545,
26,
272,
492,
747,
327,
12731,
1015,
402,
2366,
12,
1929,
370,
675,
747,
3140,
272,
8434,
632,
275,
413,
199,
199,
3,
2538,
1182,
10803,
199,
5076,
604,
275,
298,
5695,
2486,
628,
199,
83,
757,
604,
275,
298,
3606,
1444,
23245,
199,
199,
1361,
7282,
604,
199,
1361,
298,
26030,
28644,
8453,
4962,
10427,
13329,
2594,
17654,
540,
2,
199,
1361,
7282,
604,
199,
1361,
199,
199,
3,
4438,
4012,
2600,
12,
5341,
314,
3718,
12,
3877,
314,
2058,
12,
372,
4588,
1211,
199,
318,
2146,
7874,
8,
1760,
2141,
304,
272,
367,
1242,
315,
2088,
2141,
26,
267,
2088,
275,
2088,
2141,
59,
1053,
7541,
1760,
937,
199,
198,
692,
8434,
632,
508,
378,
26,
327,
15666,
1015,
402,
2366,
12,
675,
14388,
3873,
288,
734,
12,
1125,
275,
1007,
14,
7942,
779,
1760,
467,
3839,
29,
954,
14,
6089,
12,
4635,
29,
954,
14,
6089,
12,
5218,
29,
549,
680,
10664,
342,
288,
2058,
275,
734,
14,
1294,
2258,
78,
358,
199,
198,
2836,
26,
327,
12731,
1015,
402,
2366,
12,
675,
747,
14,
12207,
6722,
11343,
63,
2703,
275,
747,
14,
12207,
8,
1760,
12,
283,
82,
358,
288,
2058,
275,
11343,
63,
2703,
14,
739,
1252,
1294,
2258,
78,
358,
267,
2088,
2141,
59,
1053,
7541,
2604,
8713,
2604,
272,
372,
2088,
2141,
199,
199,
3,
870,
2058,
367,
1924,
10889,
7934,
1414,
12,
949,
372,
574,
199,
318,
870,
6579,
8,
1760,
2141,
304,
272,
367,
1242,
315,
2088,
2141,
26,
199,
198,
1328,
275,
2088,
2141,
59,
1053,
7541,
1328,
937,
199,
198,
2604,
275,
2088,
2141,
59,
1053,
7541,
2604,
937,
267,
870,
7369,
11,
61,
298,
435,
1499,
267,
367,
754,
315,
2058,
26,
6722,
340,
754,
14,
1913,
342,
1137,
10812,
507,
263,
870,
298,
259,
298,
435,
754,
14,
1913,
342,
199,
198,
1361,
272,
372,
199,
199,
318,
2218,
6579,
8,
1328,
12,
2058,
304,
272,
289,
275,
1551,
480,
10605,
12891,
14,
2424,
401,
298,
65,
3547,
272,
289,
14,
952,
10994,
11,
61,
298,
435,
620,
8,
552,
8,
2604,
7216,
17,
9,
435,
298,
298,
435,
1499,
9,
272,
367,
754,
315,
2058,
26,
267,
340,
754,
14,
1913,
342,
1137,
10812,
288,
289,
14,
952,
480,
259,
298,
435,
754,
14,
1913,
1012,
272,
289,
14,
1600,
342,
272,
372,
199,
199,
3,
10082,
2656,
2256,
199,
1361,
7369,
30431,
9576,
52,
1206,
4147,
948,
20859,
24008,
29279,
78,
2,
199,
199,
2604,
9811,
199,
199,
1274,
2354,
275,
2420,
3100,
18517,
1760,
5122,
3385,
1182,
6839,
15,
5237,
2266,
1328,
5122,
23699,
6187,
2266,
2604,
582,
2604,
1386,
21979,
298,
30142,
18517,
1760,
5122,
3385,
1182,
4687,
15,
1023,
2266,
1328,
5122,
14127,
2266,
2604,
582,
2604,
1386,
21979,
298,
22647,
18517,
1760,
5122,
4269,
401,
298,
1328,
5122,
25680,
401,
298,
2604,
582,
2604,
93,
17957,
789,
199,
199,
1274,
2354,
275,
2146,
7874,
8,
1274,
2354,
9,
199,
1361,
6579,
8,
1274,
2354,
9,
199,
199,
3,
7220,
316,
10332,
199,
199,
1361,
7369,
30431,
9576,
52,
1206,
18340,
8406,
1206,
24008,
29279,
78,
2,
199,
199,
846,
2354,
275,
2420,
7278,
4531,
18517,
1760,
5122,
15,
21457,
15,
692,
888,
446,
65,
401,
298,
1328,
5122,
18680,
401,
298,
2604,
582,
2604,
1386,
21979,
298,
1092,
4586,
18517,
1760,
5122,
4449,
401,
298,
1328,
5122,
7161,
401,
298,
2604,
582,
2604,
1386,
21979,
298,
7278,
4315,
18517,
1760,
5122,
846,
3736,
446,
867,
384,
1204,
20595,
446,
86,
283,
4961,
63,
12458,
4662,
298,
1328,
5122,
2480,
3736,
401,
298,
2604,
582,
2604,
93,
17957,
789,
199,
199,
846,
2354,
275,
2146,
7874,
8,
846,
2354,
9,
199,
1361,
6579,
8,
846,
2354,
9,
199,
199,
3,
3814,
6187,
10332,
199,
1361,
7369,
30431,
9576,
52,
1206,
16444,
654,
57,
9757,
24008,
29279,
78,
2,
199,
199,
9541,
2354,
275,
2420,
2679,
17252,
18517,
1760,
5122,
3956,
2266,
1328,
5122,
24467,
2058,
401,
298,
2604,
582,
2604,
1386,
507,
258,
298,
38,
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,
1
] |
lmazuel/azure-sdk-for-python
|
azure-mgmt-rdbms/azure/mgmt/rdbms/mysql/models/log_file_py3.py
|
2
|
2365
|
# 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 .proxy_resource import ProxyResource
class LogFile(ProxyResource):
"""Represents a log file.
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource ID
:vartype id: str
:ivar name: Resource name.
:vartype name: str
:ivar type: Resource type.
:vartype type: str
:param size_in_kb: Size of the log file.
:type size_in_kb: long
:ivar created_time: Creation timestamp of the log file.
:vartype created_time: datetime
:ivar last_modified_time: Last modified timestamp of the log file.
:vartype last_modified_time: datetime
:param log_file_type: Type of the log file.
:type log_file_type: str
:param url: The url to download the log file from.
:type url: str
"""
_validation = {
'id': {'readonly': True},
'name': {'readonly': True},
'type': {'readonly': True},
'created_time': {'readonly': True},
'last_modified_time': {'readonly': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'size_in_kb': {'key': 'properties.sizeInKB', 'type': 'long'},
'created_time': {'key': 'properties.createdTime', 'type': 'iso-8601'},
'last_modified_time': {'key': 'properties.lastModifiedTime', 'type': 'iso-8601'},
'log_file_type': {'key': 'properties.type', 'type': 'str'},
'url': {'key': 'properties.url', 'type': 'str'},
}
def __init__(self, *, size_in_kb: int=None, log_file_type: str=None, url: str=None, **kwargs) -> None:
super(LogFile, self).__init__(, **kwargs)
self.size_in_kb = size_in_kb
self.created_time = None
self.last_modified_time = None
self.log_file_type = log_file_type
self.url = url
|
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,
1275,
3280,
63,
1927,
492,
12373,
4031,
421,
199,
533,
5297,
1173,
8,
4936,
4031,
304,
272,
408,
18089,
282,
943,
570,
14,
339,
17198,
787,
1454,
16460,
701,
314,
1654,
12,
436,
911,
506,
5525,
1380,
272,
10209,
282,
1056,
14,
339,
520,
7725,
1305,
26,
7337,
2870,
272,
520,
19729,
1305,
26,
620,
272,
520,
7725,
536,
26,
7337,
536,
14,
272,
520,
19729,
536,
26,
620,
272,
520,
7725,
730,
26,
7337,
730,
14,
272,
520,
19729,
730,
26,
620,
272,
520,
635,
1568,
63,
262,
63,
7862,
26,
14579,
402,
314,
943,
570,
14,
272,
520,
466,
1568,
63,
262,
63,
7862,
26,
1846,
272,
520,
7725,
2737,
63,
521,
26,
9750,
425,
4913,
402,
314,
943,
570,
14,
272,
520,
19729,
2737,
63,
521,
26,
2197,
272,
520,
7725,
2061,
63,
5540,
63,
521,
26,
15237,
6042,
4913,
402,
314,
943,
570,
14,
272,
520,
19729,
2061,
63,
5540,
63,
521,
26,
2197,
272,
520,
635,
943,
63,
493,
63,
466,
26,
2434,
402,
314,
943,
570,
14,
272,
520,
466,
943,
63,
493,
63,
466,
26,
620,
272,
520,
635,
1166,
26,
710,
1166,
370,
5235,
314,
943,
570,
687,
14,
272,
520,
466,
1166,
26,
620,
272,
408,
339,
485,
6136,
275,
469,
267,
283,
344,
356,
791,
6753,
356,
715,
1386,
267,
283,
354,
356,
791,
6753,
356,
715,
1386,
267,
283,
466,
356,
791,
6753,
356,
715,
1386,
267,
283,
3966,
63,
521,
356,
791,
6753,
356,
715,
1386,
267,
283,
2019,
63,
5540,
63,
521,
356,
791,
6753,
356,
715,
1386,
272,
789,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
890,
63,
262,
63,
7862,
356,
791,
498,
356,
283,
3282,
14,
890,
607,
12780,
297,
283,
466,
356,
283,
2809,
2267,
267,
283,
3966,
63,
521,
356,
791,
498,
356,
283,
3282,
14,
3966,
1366,
297,
283,
466,
356,
283,
4595,
13,
15363,
2267,
267,
283,
2019,
63,
5540,
63,
521,
356,
791,
498,
356,
283,
3282,
14,
2019,
11911,
1366,
297,
283,
466,
356,
283,
4595,
13,
15363,
2267,
267,
283,
793,
63,
493,
63,
466,
356,
791,
498,
356,
283,
3282,
14,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
633,
356,
791,
498,
356,
283,
3282,
14,
633,
297,
283,
466,
356,
283,
495,
2267,
272,
789,
339,
347,
636,
826,
721,
277,
12,
9889,
1568,
63,
262,
63,
7862,
26,
1109,
29,
403,
12,
943,
63,
493,
63,
466,
26,
620,
29,
403,
12,
1166,
26,
620,
29,
403,
12,
1011,
958,
9,
1035,
488,
26,
267,
1613,
8,
19336,
12,
291,
2843,
826,
721,
12,
1011,
958,
9,
267,
291,
14,
890,
63,
262,
63,
7862,
275,
1568,
63,
262,
63,
7862,
267,
291,
14,
3966,
63,
521,
275,
488,
267,
291,
14,
2019,
63,
5540,
63,
521,
275,
488,
267,
291,
14,
793,
63,
493,
63,
466,
275,
943,
63,
493,
63,
466,
267,
291,
14,
633,
275,
1166,
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
] |
[
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,
1275,
3280,
63,
1927,
492,
12373,
4031,
421,
199,
533,
5297,
1173,
8,
4936,
4031,
304,
272,
408,
18089,
282,
943,
570,
14,
339,
17198,
787,
1454,
16460,
701,
314,
1654,
12,
436,
911,
506,
5525,
1380,
272,
10209,
282,
1056,
14,
339,
520,
7725,
1305,
26,
7337,
2870,
272,
520,
19729,
1305,
26,
620,
272,
520,
7725,
536,
26,
7337,
536,
14,
272,
520,
19729,
536,
26,
620,
272,
520,
7725,
730,
26,
7337,
730,
14,
272,
520,
19729,
730,
26,
620,
272,
520,
635,
1568,
63,
262,
63,
7862,
26,
14579,
402,
314,
943,
570,
14,
272,
520,
466,
1568,
63,
262,
63,
7862,
26,
1846,
272,
520,
7725,
2737,
63,
521,
26,
9750,
425,
4913,
402,
314,
943,
570,
14,
272,
520,
19729,
2737,
63,
521,
26,
2197,
272,
520,
7725,
2061,
63,
5540,
63,
521,
26,
15237,
6042,
4913,
402,
314,
943,
570,
14,
272,
520,
19729,
2061,
63,
5540,
63,
521,
26,
2197,
272,
520,
635,
943,
63,
493,
63,
466,
26,
2434,
402,
314,
943,
570,
14,
272,
520,
466,
943,
63,
493,
63,
466,
26,
620,
272,
520,
635,
1166,
26,
710,
1166,
370,
5235,
314,
943,
570,
687,
14,
272,
520,
466,
1166,
26,
620,
272,
408,
339,
485,
6136,
275,
469,
267,
283,
344,
356,
791,
6753,
356,
715,
1386,
267,
283,
354,
356,
791,
6753,
356,
715,
1386,
267,
283,
466,
356,
791,
6753,
356,
715,
1386,
267,
283,
3966,
63,
521,
356,
791,
6753,
356,
715,
1386,
267,
283,
2019,
63,
5540,
63,
521,
356,
791,
6753,
356,
715,
1386,
272,
789,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
890,
63,
262,
63,
7862,
356,
791,
498,
356,
283,
3282,
14,
890,
607,
12780,
297,
283,
466,
356,
283,
2809,
2267,
267,
283,
3966,
63,
521,
356,
791,
498,
356,
283,
3282,
14,
3966,
1366,
297,
283,
466,
356,
283,
4595,
13,
15363,
2267,
267,
283,
2019,
63,
5540,
63,
521,
356,
791,
498,
356,
283,
3282,
14,
2019,
11911,
1366,
297,
283,
466,
356,
283,
4595,
13,
15363,
2267,
267,
283,
793,
63,
493,
63,
466,
356,
791,
498,
356,
283,
3282,
14,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
633,
356,
791,
498,
356,
283,
3282,
14,
633,
297,
283,
466,
356,
283,
495,
2267,
272,
789,
339,
347,
636,
826,
721,
277,
12,
9889,
1568,
63,
262,
63,
7862,
26,
1109,
29,
403,
12,
943,
63,
493,
63,
466,
26,
620,
29,
403,
12,
1166,
26,
620,
29,
403,
12,
1011,
958,
9,
1035,
488,
26,
267,
1613,
8,
19336,
12,
291,
2843,
826,
721,
12,
1011,
958,
9,
267,
291,
14,
890,
63,
262,
63,
7862,
275,
1568,
63,
262,
63,
7862,
267,
291,
14,
3966,
63,
521,
275,
488,
267,
291,
14,
2019,
63,
5540,
63,
521,
275,
488,
267,
291,
14,
793,
63,
493,
63,
466,
275,
943,
63,
493,
63,
466,
267,
291,
14,
633,
275,
1166,
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,
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,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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
] |
catapult-project/catapult-csm
|
third_party/gsutil/third_party/boto/boto/rds/optiongroup.py
|
180
|
15665
|
# Copyright (c) 2013 Amazon.com, Inc. or its affiliates.
# All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""
Represents an OptionGroup
"""
from boto.rds.dbsecuritygroup import DBSecurityGroup
from boto.resultset import ResultSet
class OptionGroup(object):
"""
Represents an RDS option group
Properties reference available from the AWS documentation at
http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_OptionGroup.html
:ivar connection: :py:class:`boto.rds.RDSConnection` associated with the
current object
:ivar name: Name of the option group
:ivar description: The description of the option group
:ivar engine_name: The name of the database engine to use
:ivar major_engine_version: The major version number of the engine to use
:ivar allow_both_vpc_and_nonvpc: Indicates whether this option group can be
applied to both VPC and non-VPC instances.
The value ``True`` indicates the option
group can be applied to both VPC and
non-VPC instances.
:ivar vpc_id: If AllowsVpcAndNonVpcInstanceMemberships is 'false', this
field is blank. If AllowsVpcAndNonVpcInstanceMemberships is
``True`` and this field is blank, then this option group can
be applied to both VPC and non-VPC instances. If this field
contains a value, then this option group can only be applied
to instances that are in the VPC indicated by this field.
:ivar options: The list of :py:class:`boto.rds.optiongroup.Option` objects
associated with the group
"""
def __init__(self, connection=None, name=None, engine_name=None,
major_engine_version=None, description=None,
allow_both_vpc_and_nonvpc=False, vpc_id=None):
self.name = name
self.engine_name = engine_name
self.major_engine_version = major_engine_version
self.description = description
self.allow_both_vpc_and_nonvpc = allow_both_vpc_and_nonvpc
self.vpc_id = vpc_id
self.options = []
def __repr__(self):
return 'OptionGroup:%s' % self.name
def startElement(self, name, attrs, connection):
if name == 'Options':
self.options = ResultSet([
('Options', Option)
])
else:
return None
def endElement(self, name, value, connection):
if name == 'OptionGroupName':
self.name = value
elif name == 'EngineName':
self.engine_name = value
elif name == 'MajorEngineVersion':
self.major_engine_version = value
elif name == 'OptionGroupDescription':
self.description = value
elif name == 'AllowsVpcAndNonVpcInstanceMemberships':
if value.lower() == 'true':
self.allow_both_vpc_and_nonvpc = True
else:
self.allow_both_vpc_and_nonvpc = False
elif name == 'VpcId':
self.vpc_id = value
else:
setattr(self, name, value)
def delete(self):
return self.connection.delete_option_group(self.name)
class Option(object):
"""
Describes a Option for use in an OptionGroup
:ivar name: The name of the option
:ivar description: The description of the option.
:ivar permanent: Indicate if this option is permanent.
:ivar persistent: Indicate if this option is persistent.
:ivar port: If required, the port configured for this option to use.
:ivar settings: The option settings for this option.
:ivar db_security_groups: If the option requires access to a port, then
this DB Security Group allows access to the port.
:ivar vpc_security_groups: If the option requires access to a port, then
this VPC Security Group allows access to the
port.
"""
def __init__(self, name=None, description=None, permanent=False,
persistent=False, port=None, settings=None,
db_security_groups=None, vpc_security_groups=None):
self.name = name
self.description = description
self.permanent = permanent
self.persistent = persistent
self.port = port
self.settings = settings
self.db_security_groups = db_security_groups
self.vpc_security_groups = vpc_security_groups
if self.settings is None:
self.settings = []
if self.db_security_groups is None:
self.db_security_groups = []
if self.vpc_security_groups is None:
self.vpc_security_groups = []
def __repr__(self):
return 'Option:%s' % self.name
def startElement(self, name, attrs, connection):
if name == 'OptionSettings':
self.settings = ResultSet([
('OptionSettings', OptionSetting)
])
elif name == 'DBSecurityGroupMemberships':
self.db_security_groups = ResultSet([
('DBSecurityGroupMemberships', DBSecurityGroup)
])
elif name == 'VpcSecurityGroupMemberships':
self.vpc_security_groups = ResultSet([
('VpcSecurityGroupMemberships', VpcSecurityGroup)
])
else:
return None
def endElement(self, name, value, connection):
if name == 'OptionName':
self.name = value
elif name == 'OptionDescription':
self.description = value
elif name == 'Permanent':
if value.lower() == 'true':
self.permenant = True
else:
self.permenant = False
elif name == 'Persistent':
if value.lower() == 'true':
self.persistent = True
else:
self.persistent = False
elif name == 'Port':
self.port = int(value)
else:
setattr(self, name, value)
class OptionSetting(object):
"""
Describes a OptionSetting for use in an Option
:ivar name: The name of the option that has settings that you can set.
:ivar description: The description of the option setting.
:ivar value: The current value of the option setting.
:ivar default_value: The default value of the option setting.
:ivar allowed_values: The allowed values of the option setting.
:ivar data_type: The data type of the option setting.
:ivar apply_type: The DB engine specific parameter type.
:ivar is_modifiable: A Boolean value that, when true, indicates the option
setting can be modified from the default.
:ivar is_collection: Indicates if the option setting is part of a
collection.
"""
def __init__(self, name=None, description=None, value=None,
default_value=False, allowed_values=None, data_type=None,
apply_type=None, is_modifiable=False, is_collection=False):
self.name = name
self.description = description
self.value = value
self.default_value = default_value
self.allowed_values = allowed_values
self.data_type = data_type
self.apply_type = apply_type
self.is_modifiable = is_modifiable
self.is_collection = is_collection
def __repr__(self):
return 'OptionSetting:%s' % self.name
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
if name == 'Name':
self.name = value
elif name == 'Description':
self.description = value
elif name == 'Value':
self.value = value
elif name == 'DefaultValue':
self.default_value = value
elif name == 'AllowedValues':
self.allowed_values = value
elif name == 'DataType':
self.data_type = value
elif name == 'ApplyType':
self.apply_type = value
elif name == 'IsModifiable':
if value.lower() == 'true':
self.is_modifiable = True
else:
self.is_modifiable = False
elif name == 'IsCollection':
if value.lower() == 'true':
self.is_collection = True
else:
self.is_collection = False
else:
setattr(self, name, value)
class VpcSecurityGroup(object):
"""
Describes a VPC security group for use in a OptionGroup
"""
def __init__(self, vpc_id=None, status=None):
self.vpc_id = vpc_id
self.status = status
def __repr__(self):
return 'VpcSecurityGroup:%s' % self.vpc_id
def startElement(self, name, attrs, connection):
pass
def endElement(self, name, value, connection):
if name == 'VpcSecurityGroupId':
self.vpc_id = value
elif name == 'Status':
self.status = value
else:
setattr(self, name, value)
class OptionGroupOption(object):
"""
Describes a OptionGroupOption for use in an OptionGroup
:ivar name: The name of the option
:ivar description: The description of the option.
:ivar engine_name: Engine name that this option can be applied to.
:ivar major_engine_version: Indicates the major engine version that the
option is available for.
:ivar min_minor_engine_version: The minimum required engine version for the
option to be applied.
:ivar permanent: Indicate if this option is permanent.
:ivar persistent: Indicate if this option is persistent.
:ivar port_required: Specifies whether the option requires a port.
:ivar default_port: If the option requires a port, specifies the default
port for the option.
:ivar settings: The option settings for this option.
:ivar depends_on: List of all options that are prerequisites for this
option.
"""
def __init__(self, name=None, description=None, engine_name=None,
major_engine_version=None, min_minor_engine_version=None,
permanent=False, persistent=False, port_required=False,
default_port=None, settings=None, depends_on=None):
self.name = name
self.description = description
self.engine_name = engine_name
self.major_engine_version = major_engine_version
self.min_minor_engine_version = min_minor_engine_version
self.permanent = permanent
self.persistent = persistent
self.port_required = port_required
self.default_port = default_port
self.settings = settings
self.depends_on = depends_on
if self.settings is None:
self.settings = []
if self.depends_on is None:
self.depends_on = []
def __repr__(self):
return 'OptionGroupOption:%s' % self.name
def startElement(self, name, attrs, connection):
if name == 'OptionGroupOptionSettings':
self.settings = ResultSet([
('OptionGroupOptionSettings', OptionGroupOptionSetting)
])
elif name == 'OptionsDependedOn':
self.depends_on = []
else:
return None
def endElement(self, name, value, connection):
if name == 'Name':
self.name = value
elif name == 'Description':
self.description = value
elif name == 'EngineName':
self.engine_name = value
elif name == 'MajorEngineVersion':
self.major_engine_version = value
elif name == 'MinimumRequiredMinorEngineVersion':
self.min_minor_engine_version = value
elif name == 'Permanent':
if value.lower() == 'true':
self.permenant = True
else:
self.permenant = False
elif name == 'Persistent':
if value.lower() == 'true':
self.persistent = True
else:
self.persistent = False
elif name == 'PortRequired':
if value.lower() == 'true':
self.port_required = True
else:
self.port_required = False
elif name == 'DefaultPort':
self.default_port = int(value)
else:
setattr(self, name, value)
class OptionGroupOptionSetting(object):
"""
Describes a OptionGroupOptionSetting for use in an OptionGroupOption.
:ivar name: The name of the option that has settings that you can set.
:ivar description: The description of the option setting.
:ivar value: The current value of the option setting.
:ivar default_value: The default value of the option setting.
:ivar allowed_values: The allowed values of the option setting.
:ivar data_type: The data type of the option setting.
:ivar apply_type: The DB engine specific parameter type.
:ivar is_modifiable: A Boolean value that, when true, indicates the option
setting can be modified from the default.
:ivar is_collection: Indicates if the option setting is part of a
collection.
"""
def __init__(self, name=None, description=None, default_value=False,
allowed_values=None, apply_type=None, is_modifiable=False):
self.name = name
self.description = description
self.default_value = default_value
self.allowed_values = allowed_values
self.apply_type = apply_type
self.is_modifiable = is_modifiable
def __repr__(self):
return 'OptionGroupOptionSetting:%s' % self.name
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
if name == 'SettingName':
self.name = value
elif name == 'SettingDescription':
self.description = value
elif name == 'DefaultValue':
self.default_value = value
elif name == 'AllowedValues':
self.allowed_values = value
elif name == 'ApplyType':
self.apply_type = value
elif name == 'IsModifiable':
if value.lower() == 'true':
self.is_modifiable = True
else:
self.is_modifiable = False
else:
setattr(self, name, value)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6171,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
199,
3,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
18089,
376,
3207,
2448,
199,
624,
199,
199,
504,
6055,
14,
23098,
14,
697,
4416,
923,
492,
6249,
19280,
199,
504,
6055,
14,
1099,
409,
492,
30751,
421,
199,
533,
3207,
2448,
8,
785,
304,
272,
408,
272,
21591,
376,
820,
3177,
945,
1572,
339,
19329,
3659,
2808,
687,
314,
10168,
3794,
737,
272,
1455,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
33,
8872,
50,
3177,
15,
7410,
15,
3735,
5083,
15,
3735,
63,
2602,
2448,
14,
1360,
339,
520,
7725,
1950,
26,
520,
647,
26,
533,
1705,
10914,
14,
23098,
14,
50,
3177,
3225,
64,
4568,
543,
314,
1993,
1453,
909,
272,
520,
7725,
536,
26,
2812,
402,
314,
945,
1572,
272,
520,
7725,
1369,
26,
710,
1369,
402,
314,
945,
1572,
272,
520,
7725,
6869,
63,
354,
26,
710,
536,
402,
314,
3050,
6869,
370,
675,
272,
520,
7725,
12160,
63,
3908,
63,
1023,
26,
710,
12160,
1015,
1329,
402,
314,
6869,
370,
675,
272,
520,
7725,
2040,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
26,
19334,
3775,
642,
945,
1572,
883,
506,
3660,
6781,
370,
3865,
19209,
436,
2222,
13,
54,
4222,
4454,
14,
3660,
710,
574,
1124,
549,
1040,
9126,
314,
945,
3660,
1572,
883,
506,
6781,
370,
3865,
19209,
436,
3660,
2222,
13,
54,
4222,
4454,
14,
272,
520,
7725,
12830,
63,
344,
26,
982,
22819,
28893,
3325,
6932,
28893,
3244,
19480,
83,
365,
283,
3910,
297,
642,
2116,
901,
365,
4596,
14,
982,
22819,
28893,
3325,
6932,
28893,
3244,
19480,
83,
365,
2116,
1124,
549,
1040,
436,
642,
901,
365,
4596,
12,
2066,
642,
945,
1572,
883,
2116,
506,
6781,
370,
3865,
19209,
436,
2222,
13,
54,
4222,
4454,
14,
982,
642,
901,
2116,
3509,
282,
574,
12,
2066,
642,
945,
1572,
883,
1454,
506,
6781,
2116,
370,
4454,
626,
787,
315,
314,
19209,
22141,
701,
642,
901,
14,
272,
520,
7725,
1511,
26,
710,
769,
402,
520,
647,
26,
533,
1705,
10914,
14,
23098,
14,
1422,
923,
14,
2602,
64,
2251,
673,
4568,
543,
314,
1572,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
536,
29,
403,
12,
6869,
63,
354,
29,
403,
12,
326,
12160,
63,
3908,
63,
1023,
29,
403,
12,
1369,
29,
403,
12,
326,
2040,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
29,
797,
12,
12830,
63,
344,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3908,
63,
354,
275,
6869,
63,
354,
267,
291,
14,
8452,
63,
3908,
63,
1023,
275,
12160,
63,
3908,
63,
1023,
267,
291,
14,
1802,
275,
1369,
267,
291,
14,
3306,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
275,
2040,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
267,
291,
14,
11742,
63,
344,
275,
12830,
63,
344,
267,
291,
14,
1419,
275,
942,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
2602,
2448,
2689,
83,
7,
450,
291,
14,
354,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
340,
536,
508,
283,
4558,
356,
288,
291,
14,
1419,
275,
30751,
779,
355,
661,
4558,
297,
3207,
9,
288,
4794,
267,
587,
26,
288,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
2602,
14405,
356,
288,
291,
14,
354,
275,
574,
267,
916,
536,
508,
283,
8524,
985,
356,
288,
291,
14,
3908,
63,
354,
275,
574,
267,
916,
536,
508,
283,
21657,
8524,
3353,
356,
288,
291,
14,
8452,
63,
3908,
63,
1023,
275,
574,
267,
916,
536,
508,
283,
2602,
2448,
5831,
356,
288,
291,
14,
1802,
275,
574,
267,
916,
536,
508,
283,
19780,
28893,
3325,
6932,
28893,
3244,
19480,
83,
356,
288,
340,
574,
14,
2325,
342,
508,
283,
2052,
356,
355,
291,
14,
3306,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
275,
715,
288,
587,
26,
355,
291,
14,
3306,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
275,
756,
267,
916,
536,
508,
283,
28893,
1304,
356,
288,
291,
14,
11742,
63,
344,
275,
574,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
3145,
8,
277,
304,
267,
372,
291,
14,
2105,
14,
1807,
63,
1422,
63,
923,
8,
277,
14,
354,
9,
421,
199,
533,
3207,
8,
785,
304,
272,
408,
272,
28571,
11562,
282,
3207,
367,
675,
315,
376,
3207,
2448,
339,
520,
7725,
536,
26,
710,
536,
402,
314,
945,
272,
520,
7725,
1369,
26,
710,
1369,
402,
314,
945,
14,
272,
520,
7725,
19860,
26,
1010,
10188,
340,
642,
945,
365,
19860
] |
[
1898,
334,
67,
9,
6171,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
199,
3,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
18089,
376,
3207,
2448,
199,
624,
199,
199,
504,
6055,
14,
23098,
14,
697,
4416,
923,
492,
6249,
19280,
199,
504,
6055,
14,
1099,
409,
492,
30751,
421,
199,
533,
3207,
2448,
8,
785,
304,
272,
408,
272,
21591,
376,
820,
3177,
945,
1572,
339,
19329,
3659,
2808,
687,
314,
10168,
3794,
737,
272,
1455,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
33,
8872,
50,
3177,
15,
7410,
15,
3735,
5083,
15,
3735,
63,
2602,
2448,
14,
1360,
339,
520,
7725,
1950,
26,
520,
647,
26,
533,
1705,
10914,
14,
23098,
14,
50,
3177,
3225,
64,
4568,
543,
314,
1993,
1453,
909,
272,
520,
7725,
536,
26,
2812,
402,
314,
945,
1572,
272,
520,
7725,
1369,
26,
710,
1369,
402,
314,
945,
1572,
272,
520,
7725,
6869,
63,
354,
26,
710,
536,
402,
314,
3050,
6869,
370,
675,
272,
520,
7725,
12160,
63,
3908,
63,
1023,
26,
710,
12160,
1015,
1329,
402,
314,
6869,
370,
675,
272,
520,
7725,
2040,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
26,
19334,
3775,
642,
945,
1572,
883,
506,
3660,
6781,
370,
3865,
19209,
436,
2222,
13,
54,
4222,
4454,
14,
3660,
710,
574,
1124,
549,
1040,
9126,
314,
945,
3660,
1572,
883,
506,
6781,
370,
3865,
19209,
436,
3660,
2222,
13,
54,
4222,
4454,
14,
272,
520,
7725,
12830,
63,
344,
26,
982,
22819,
28893,
3325,
6932,
28893,
3244,
19480,
83,
365,
283,
3910,
297,
642,
2116,
901,
365,
4596,
14,
982,
22819,
28893,
3325,
6932,
28893,
3244,
19480,
83,
365,
2116,
1124,
549,
1040,
436,
642,
901,
365,
4596,
12,
2066,
642,
945,
1572,
883,
2116,
506,
6781,
370,
3865,
19209,
436,
2222,
13,
54,
4222,
4454,
14,
982,
642,
901,
2116,
3509,
282,
574,
12,
2066,
642,
945,
1572,
883,
1454,
506,
6781,
2116,
370,
4454,
626,
787,
315,
314,
19209,
22141,
701,
642,
901,
14,
272,
520,
7725,
1511,
26,
710,
769,
402,
520,
647,
26,
533,
1705,
10914,
14,
23098,
14,
1422,
923,
14,
2602,
64,
2251,
673,
4568,
543,
314,
1572,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
536,
29,
403,
12,
6869,
63,
354,
29,
403,
12,
326,
12160,
63,
3908,
63,
1023,
29,
403,
12,
1369,
29,
403,
12,
326,
2040,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
29,
797,
12,
12830,
63,
344,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3908,
63,
354,
275,
6869,
63,
354,
267,
291,
14,
8452,
63,
3908,
63,
1023,
275,
12160,
63,
3908,
63,
1023,
267,
291,
14,
1802,
275,
1369,
267,
291,
14,
3306,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
275,
2040,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
267,
291,
14,
11742,
63,
344,
275,
12830,
63,
344,
267,
291,
14,
1419,
275,
942,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
2602,
2448,
2689,
83,
7,
450,
291,
14,
354,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
340,
536,
508,
283,
4558,
356,
288,
291,
14,
1419,
275,
30751,
779,
355,
661,
4558,
297,
3207,
9,
288,
4794,
267,
587,
26,
288,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
2602,
14405,
356,
288,
291,
14,
354,
275,
574,
267,
916,
536,
508,
283,
8524,
985,
356,
288,
291,
14,
3908,
63,
354,
275,
574,
267,
916,
536,
508,
283,
21657,
8524,
3353,
356,
288,
291,
14,
8452,
63,
3908,
63,
1023,
275,
574,
267,
916,
536,
508,
283,
2602,
2448,
5831,
356,
288,
291,
14,
1802,
275,
574,
267,
916,
536,
508,
283,
19780,
28893,
3325,
6932,
28893,
3244,
19480,
83,
356,
288,
340,
574,
14,
2325,
342,
508,
283,
2052,
356,
355,
291,
14,
3306,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
275,
715,
288,
587,
26,
355,
291,
14,
3306,
63,
10727,
63,
11742,
63,
460,
63,
2865,
11742,
275,
756,
267,
916,
536,
508,
283,
28893,
1304,
356,
288,
291,
14,
11742,
63,
344,
275,
574,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
3145,
8,
277,
304,
267,
372,
291,
14,
2105,
14,
1807,
63,
1422,
63,
923,
8,
277,
14,
354,
9,
421,
199,
533,
3207,
8,
785,
304,
272,
408,
272,
28571,
11562,
282,
3207,
367,
675,
315,
376,
3207,
2448,
339,
520,
7725,
536,
26,
710,
536,
402,
314,
945,
272,
520,
7725,
1369,
26,
710,
1369,
402,
314,
945,
14,
272,
520,
7725,
19860,
26,
1010,
10188,
340,
642,
945,
365,
19860,
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
] |
delta2323/chainer
|
chainer/functions/array/transpose.py
|
3
|
1222
|
import numpy
from chainer import function
from chainer.utils import type_check
class Transpose(function.Function):
"""Permute the dimensions of an array."""
def __init__(self, axes=None):
self.axes = axes
def check_type_forward(self, in_types):
type_check.expect(in_types.size() == 1,)
@property
def label(self):
return 'Transpose'
def forward(self, inputs):
self.retain_inputs(())
x = inputs[0]
y = x.transpose(self.axes)
return y,
def backward(self, inputs, grad_outputs):
gy = grad_outputs[0]
inv_axes = self.axes
if self.axes:
axes = tuple(ax % len(self.axes) for ax in self.axes)
inv_axes = tuple(numpy.argsort(axes))
gx = gy.transpose(inv_axes)
return gx,
def transpose(x, axes=None):
"""Permute the dimensions of an input variable without copy.
Args:
x (~chainer.Variable): Input variable.
axes (tuple of ints): By default, reverse the dimensions,
otherwise permute the axes according to the values given.
Returns:
~chainer.Variable: Variable whose axes are permuted.
"""
return Transpose(axes)(x)
|
mit
|
[
646,
2680,
199,
199,
504,
20333,
492,
805,
199,
504,
20333,
14,
1208,
492,
730,
63,
1074,
421,
199,
533,
6266,
4070,
8,
1593,
14,
3481,
304,
272,
408,
2623,
12423,
314,
7365,
402,
376,
1625,
1041,
339,
347,
636,
826,
721,
277,
12,
7824,
29,
403,
304,
267,
291,
14,
6402,
275,
7824,
339,
347,
1104,
63,
466,
63,
6688,
8,
277,
12,
315,
63,
1313,
304,
267,
730,
63,
1074,
14,
4921,
8,
262,
63,
1313,
14,
890,
342,
508,
413,
4258,
339,
768,
1829,
272,
347,
1768,
8,
277,
304,
267,
372,
283,
3188,
4070,
7,
339,
347,
7568,
8,
277,
12,
4153,
304,
267,
291,
14,
264,
877,
63,
3711,
30812,
267,
671,
275,
4153,
59,
16,
61,
267,
612,
275,
671,
14,
10483,
8,
277,
14,
6402,
9,
267,
372,
612,
12,
339,
347,
13388,
8,
277,
12,
4153,
12,
7659,
63,
4467,
304,
267,
28089,
275,
7659,
63,
4467,
59,
16,
61,
267,
4572,
63,
6402,
275,
291,
14,
6402,
267,
340,
291,
14,
6402,
26,
288,
7824,
275,
2008,
8,
1219,
450,
822,
8,
277,
14,
6402,
9,
367,
2185,
315,
291,
14,
6402,
9,
288,
4572,
63,
6402,
275,
2008,
8,
4714,
14,
20188,
8,
6402,
430,
267,
486,
88,
275,
28089,
14,
10483,
8,
5350,
63,
6402,
9,
267,
372,
486,
88,
12,
421,
199,
318,
16992,
8,
88,
12,
7824,
29,
403,
304,
272,
408,
2623,
12423,
314,
7365,
402,
376,
1324,
1750,
1928,
1331,
14,
339,
3033,
26,
267,
671,
31742,
27243,
14,
2773,
304,
6924,
1750,
14,
267,
7824,
334,
2960,
402,
14526,
304,
4885,
849,
12,
3837,
314,
7365,
12,
288,
4257,
10869,
938,
314,
7824,
7182,
370,
314,
1338,
1627,
14,
339,
1803,
26,
267,
6146,
27243,
14,
2773,
26,
4905,
7447,
7824,
787,
10869,
4241,
14,
339,
408,
272,
372,
6266,
4070,
8,
6402,
5130,
88,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2680,
199,
199,
504,
20333,
492,
805,
199,
504,
20333,
14,
1208,
492,
730,
63,
1074,
421,
199,
533,
6266,
4070,
8,
1593,
14,
3481,
304,
272,
408,
2623,
12423,
314,
7365,
402,
376,
1625,
1041,
339,
347,
636,
826,
721,
277,
12,
7824,
29,
403,
304,
267,
291,
14,
6402,
275,
7824,
339,
347,
1104,
63,
466,
63,
6688,
8,
277,
12,
315,
63,
1313,
304,
267,
730,
63,
1074,
14,
4921,
8,
262,
63,
1313,
14,
890,
342,
508,
413,
4258,
339,
768,
1829,
272,
347,
1768,
8,
277,
304,
267,
372,
283,
3188,
4070,
7,
339,
347,
7568,
8,
277,
12,
4153,
304,
267,
291,
14,
264,
877,
63,
3711,
30812,
267,
671,
275,
4153,
59,
16,
61,
267,
612,
275,
671,
14,
10483,
8,
277,
14,
6402,
9,
267,
372,
612,
12,
339,
347,
13388,
8,
277,
12,
4153,
12,
7659,
63,
4467,
304,
267,
28089,
275,
7659,
63,
4467,
59,
16,
61,
267,
4572,
63,
6402,
275,
291,
14,
6402,
267,
340,
291,
14,
6402,
26,
288,
7824,
275,
2008,
8,
1219,
450,
822,
8,
277,
14,
6402,
9,
367,
2185,
315,
291,
14,
6402,
9,
288,
4572,
63,
6402,
275,
2008,
8,
4714,
14,
20188,
8,
6402,
430,
267,
486,
88,
275,
28089,
14,
10483,
8,
5350,
63,
6402,
9,
267,
372,
486,
88,
12,
421,
199,
318,
16992,
8,
88,
12,
7824,
29,
403,
304,
272,
408,
2623,
12423,
314,
7365,
402,
376,
1324,
1750,
1928,
1331,
14,
339,
3033,
26,
267,
671,
31742,
27243,
14,
2773,
304,
6924,
1750,
14,
267,
7824,
334,
2960,
402,
14526,
304,
4885,
849,
12,
3837,
314,
7365,
12,
288,
4257,
10869,
938,
314,
7824,
7182,
370,
314,
1338,
1627,
14,
339,
1803,
26,
267,
6146,
27243,
14,
2773,
26,
4905,
7447,
7824,
787,
10869,
4241,
14,
339,
408,
272,
372,
6266,
4070,
8,
6402,
5130,
88,
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,
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,
0
] |
jcasner/nupic
|
external/linux32/lib/python2.6/site-packages/matplotlib/path.py
|
69
|
20263
|
"""
Contains a class for managing paths (polylines).
"""
import math
from weakref import WeakValueDictionary
import numpy as np
from numpy import ma
from matplotlib._path import point_in_path, get_path_extents, \
point_in_path_collection, get_path_collection_extents, \
path_in_path, path_intersects_path, convert_path_to_polygons
from matplotlib.cbook import simple_linear_interpolation
class Path(object):
"""
:class:`Path` represents a series of possibly disconnected,
possibly closed, line and curve segments.
The underlying storage is made up of two parallel numpy arrays:
- *vertices*: an Nx2 float array of vertices
- *codes*: an N-length uint8 array of vertex types
These two arrays always have the same length in the first
dimension. For example, to represent a cubic curve, you must
provide three vertices as well as three codes ``CURVE3``.
The code types are:
- ``STOP`` : 1 vertex (ignored)
A marker for the end of the entire path (currently not
required and ignored)
- ``MOVETO`` : 1 vertex
Pick up the pen and move to the given vertex.
- ``LINETO`` : 1 vertex
Draw a line from the current position to the given vertex.
- ``CURVE3`` : 1 control point, 1 endpoint
Draw a quadratic Bezier curve from the current position,
with the given control point, to the given end point.
- ``CURVE4`` : 2 control points, 1 endpoint
Draw a cubic Bezier curve from the current position, with
the given control points, to the given end point.
- ``CLOSEPOLY`` : 1 vertex (ignored)
Draw a line segment to the start point of the current
polyline.
Users of Path objects should not access the vertices and codes
arrays directly. Instead, they should use :meth:`iter_segments`
to get the vertex/code pairs. This is important, since many
:class:`Path` objects, as an optimization, do not store a *codes*
at all, but have a default one provided for them by
:meth:`iter_segments`.
Note also that the vertices and codes arrays should be treated as
immutable -- there are a number of optimizations and assumptions
made up front in the constructor that will not change when the
data changes.
"""
# Path codes
STOP = 0 # 1 vertex
MOVETO = 1 # 1 vertex
LINETO = 2 # 1 vertex
CURVE3 = 3 # 2 vertices
CURVE4 = 4 # 3 vertices
CLOSEPOLY = 5 # 1 vertex
NUM_VERTICES = [1, 1, 1, 2, 3, 1]
code_type = np.uint8
def __init__(self, vertices, codes=None):
"""
Create a new path with the given vertices and codes.
*vertices* is an Nx2 numpy float array, masked array or Python
sequence.
*codes* is an N-length numpy array or Python sequence of type
:attr:`matplotlib.path.Path.code_type`.
These two arrays must have the same length in the first
dimension.
If *codes* is None, *vertices* will be treated as a series of
line segments.
If *vertices* contains masked values, they will be converted
to NaNs which are then handled correctly by the Agg
PathIterator and other consumers of path data, such as
:meth:`iter_segments`.
"""
if ma.isMaskedArray(vertices):
vertices = vertices.astype(np.float_).filled(np.nan)
else:
vertices = np.asarray(vertices, np.float_)
if codes is not None:
codes = np.asarray(codes, self.code_type)
assert codes.ndim == 1
assert len(codes) == len(vertices)
assert vertices.ndim == 2
assert vertices.shape[1] == 2
self.should_simplify = (len(vertices) >= 128 and
(codes is None or np.all(codes <= Path.LINETO)))
self.has_nonfinite = not np.isfinite(vertices).all()
self.codes = codes
self.vertices = vertices
#@staticmethod
def make_compound_path(*args):
"""
(staticmethod) Make a compound path from a list of Path
objects. Only polygons (not curves) are supported.
"""
for p in args:
assert p.codes is None
lengths = [len(x) for x in args]
total_length = sum(lengths)
vertices = np.vstack([x.vertices for x in args])
vertices.reshape((total_length, 2))
codes = Path.LINETO * np.ones(total_length)
i = 0
for length in lengths:
codes[i] = Path.MOVETO
i += length
return Path(vertices, codes)
make_compound_path = staticmethod(make_compound_path)
def __repr__(self):
return "Path(%s, %s)" % (self.vertices, self.codes)
def __len__(self):
return len(self.vertices)
def iter_segments(self, simplify=None):
"""
Iterates over all of the curve segments in the path. Each
iteration returns a 2-tuple (*vertices*, *code*), where
*vertices* is a sequence of 1 - 3 coordinate pairs, and *code* is
one of the :class:`Path` codes.
If *simplify* is provided, it must be a tuple (*width*,
*height*) defining the size of the figure, in native units
(e.g. pixels or points). Simplification implies both removing
adjacent line segments that are very close to parallel, and
removing line segments outside of the figure. The path will
be simplified *only* if :attr:`should_simplify` is True, which
is determined in the constructor by this criteria:
- No curves
- More than 128 vertices
"""
vertices = self.vertices
if not len(vertices):
return
codes = self.codes
len_vertices = len(vertices)
isfinite = np.isfinite
NUM_VERTICES = self.NUM_VERTICES
MOVETO = self.MOVETO
LINETO = self.LINETO
CLOSEPOLY = self.CLOSEPOLY
STOP = self.STOP
if simplify is not None and self.should_simplify:
polygons = self.to_polygons(None, *simplify)
for vertices in polygons:
yield vertices[0], MOVETO
for v in vertices[1:]:
yield v, LINETO
elif codes is None:
if self.has_nonfinite:
next_code = MOVETO
for v in vertices:
if np.isfinite(v).all():
yield v, next_code
next_code = LINETO
else:
next_code = MOVETO
else:
yield vertices[0], MOVETO
for v in vertices[1:]:
yield v, LINETO
else:
i = 0
was_nan = False
while i < len_vertices:
code = codes[i]
if code == CLOSEPOLY:
yield [], code
i += 1
elif code == STOP:
return
else:
num_vertices = NUM_VERTICES[int(code)]
curr_vertices = vertices[i:i+num_vertices].flatten()
if not isfinite(curr_vertices).all():
was_nan = True
elif was_nan:
yield curr_vertices[-2:], MOVETO
was_nan = False
else:
yield curr_vertices, code
i += num_vertices
def transformed(self, transform):
"""
Return a transformed copy of the path.
.. seealso::
:class:`matplotlib.transforms.TransformedPath`:
A specialized path class that will cache the
transformed result and automatically update when the
transform changes.
"""
return Path(transform.transform(self.vertices), self.codes)
def contains_point(self, point, transform=None):
"""
Returns *True* if the path contains the given point.
If *transform* is not *None*, the path will be transformed
before performing the test.
"""
if transform is not None:
transform = transform.frozen()
return point_in_path(point[0], point[1], self, transform)
def contains_path(self, path, transform=None):
"""
Returns *True* if this path completely contains the given path.
If *transform* is not *None*, the path will be transformed
before performing the test.
"""
if transform is not None:
transform = transform.frozen()
return path_in_path(self, None, path, transform)
def get_extents(self, transform=None):
"""
Returns the extents (*xmin*, *ymin*, *xmax*, *ymax*) of the
path.
Unlike computing the extents on the *vertices* alone, this
algorithm will take into account the curves and deal with
control points appropriately.
"""
from transforms import Bbox
if transform is not None:
transform = transform.frozen()
return Bbox(get_path_extents(self, transform))
def intersects_path(self, other, filled=True):
"""
Returns *True* if this path intersects another given path.
*filled*, when True, treats the paths as if they were filled.
That is, if one path completely encloses the other,
:meth:`intersects_path` will return True.
"""
return path_intersects_path(self, other, filled)
def intersects_bbox(self, bbox, filled=True):
"""
Returns *True* if this path intersects a given
:class:`~matplotlib.transforms.Bbox`.
*filled*, when True, treats the path as if it was filled.
That is, if one path completely encloses the other,
:meth:`intersects_path` will return True.
"""
from transforms import BboxTransformTo
rectangle = self.unit_rectangle().transformed(
BboxTransformTo(bbox))
result = self.intersects_path(rectangle, filled)
return result
def interpolated(self, steps):
"""
Returns a new path resampled to length N x steps. Does not
currently handle interpolating curves.
"""
vertices = simple_linear_interpolation(self.vertices, steps)
codes = self.codes
if codes is not None:
new_codes = Path.LINETO * np.ones(((len(codes) - 1) * steps + 1, ))
new_codes[0::steps] = codes
else:
new_codes = None
return Path(vertices, new_codes)
def to_polygons(self, transform=None, width=0, height=0):
"""
Convert this path to a list of polygons. Each polygon is an
Nx2 array of vertices. In other words, each polygon has no
``MOVETO`` instructions or curves. This is useful for
displaying in backends that do not support compound paths or
Bezier curves, such as GDK.
If *width* and *height* are both non-zero then the lines will
be simplified so that vertices outside of (0, 0), (width,
height) will be clipped.
"""
if len(self.vertices) == 0:
return []
if transform is not None:
transform = transform.frozen()
if self.codes is None and (width == 0 or height == 0):
if transform is None:
return [self.vertices]
else:
return [transform.transform(self.vertices)]
# Deal with the case where there are curves and/or multiple
# subpaths (using extension code)
return convert_path_to_polygons(self, transform, width, height)
_unit_rectangle = None
#@classmethod
def unit_rectangle(cls):
"""
(staticmethod) Returns a :class:`Path` of the unit rectangle
from (0, 0) to (1, 1).
"""
if cls._unit_rectangle is None:
cls._unit_rectangle = \
Path([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]])
return cls._unit_rectangle
unit_rectangle = classmethod(unit_rectangle)
_unit_regular_polygons = WeakValueDictionary()
#@classmethod
def unit_regular_polygon(cls, numVertices):
"""
(staticmethod) Returns a :class:`Path` for a unit regular
polygon with the given *numVertices* and radius of 1.0,
centered at (0, 0).
"""
if numVertices <= 16:
path = cls._unit_regular_polygons.get(numVertices)
else:
path = None
if path is None:
theta = (2*np.pi/numVertices *
np.arange(numVertices + 1).reshape((numVertices + 1, 1)))
# This initial rotation is to make sure the polygon always
# "points-up"
theta += np.pi / 2.0
verts = np.concatenate((np.cos(theta), np.sin(theta)), 1)
path = Path(verts)
cls._unit_regular_polygons[numVertices] = path
return path
unit_regular_polygon = classmethod(unit_regular_polygon)
_unit_regular_stars = WeakValueDictionary()
#@classmethod
def unit_regular_star(cls, numVertices, innerCircle=0.5):
"""
(staticmethod) Returns a :class:`Path` for a unit regular star
with the given numVertices and radius of 1.0, centered at (0,
0).
"""
if numVertices <= 16:
path = cls._unit_regular_stars.get((numVertices, innerCircle))
else:
path = None
if path is None:
ns2 = numVertices * 2
theta = (2*np.pi/ns2 * np.arange(ns2 + 1))
# This initial rotation is to make sure the polygon always
# "points-up"
theta += np.pi / 2.0
r = np.ones(ns2 + 1)
r[1::2] = innerCircle
verts = np.vstack((r*np.cos(theta), r*np.sin(theta))).transpose()
path = Path(verts)
cls._unit_regular_polygons[(numVertices, innerCircle)] = path
return path
unit_regular_star = classmethod(unit_regular_star)
#@classmethod
def unit_regular_asterisk(cls, numVertices):
"""
(staticmethod) Returns a :class:`Path` for a unit regular
asterisk with the given numVertices and radius of 1.0,
centered at (0, 0).
"""
return cls.unit_regular_star(numVertices, 0.0)
unit_regular_asterisk = classmethod(unit_regular_asterisk)
_unit_circle = None
#@classmethod
def unit_circle(cls):
"""
(staticmethod) Returns a :class:`Path` of the unit circle.
The circle is approximated using cubic Bezier curves. This
uses 8 splines around the circle using the approach presented
here:
Lancaster, Don. `Approximating a Circle or an Ellipse Using Four
Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_.
"""
if cls._unit_circle is None:
MAGIC = 0.2652031
SQRTHALF = np.sqrt(0.5)
MAGIC45 = np.sqrt((MAGIC*MAGIC) / 2.0)
vertices = np.array(
[[0.0, -1.0],
[MAGIC, -1.0],
[SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45],
[SQRTHALF, -SQRTHALF],
[SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45],
[1.0, -MAGIC],
[1.0, 0.0],
[1.0, MAGIC],
[SQRTHALF+MAGIC45, SQRTHALF-MAGIC45],
[SQRTHALF, SQRTHALF],
[SQRTHALF-MAGIC45, SQRTHALF+MAGIC45],
[MAGIC, 1.0],
[0.0, 1.0],
[-MAGIC, 1.0],
[-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45],
[-SQRTHALF, SQRTHALF],
[-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45],
[-1.0, MAGIC],
[-1.0, 0.0],
[-1.0, -MAGIC],
[-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45],
[-SQRTHALF, -SQRTHALF],
[-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45],
[-MAGIC, -1.0],
[0.0, -1.0],
[0.0, -1.0]],
np.float_)
codes = cls.CURVE4 * np.ones(26)
codes[0] = cls.MOVETO
codes[-1] = cls.CLOSEPOLY
cls._unit_circle = Path(vertices, codes)
return cls._unit_circle
unit_circle = classmethod(unit_circle)
#@classmethod
def arc(cls, theta1, theta2, n=None, is_wedge=False):
"""
(staticmethod) Returns an arc on the unit circle from angle
*theta1* to angle *theta2* (in degrees).
If *n* is provided, it is the number of spline segments to make.
If *n* is not provided, the number of spline segments is
determined based on the delta between *theta1* and *theta2*.
Masionobe, L. 2003. `Drawing an elliptical arc using
polylines, quadratic or cubic Bezier curves
<http://www.spaceroots.org/documents/ellipse/index.html>`_.
"""
# degrees to radians
theta1 *= np.pi / 180.0
theta2 *= np.pi / 180.0
twopi = np.pi * 2.0
halfpi = np.pi * 0.5
eta1 = np.arctan2(np.sin(theta1), np.cos(theta1))
eta2 = np.arctan2(np.sin(theta2), np.cos(theta2))
eta2 -= twopi * np.floor((eta2 - eta1) / twopi)
if (theta2 - theta1 > np.pi) and (eta2 - eta1 < np.pi):
eta2 += twopi
# number of curve segments to make
if n is None:
n = int(2 ** np.ceil((eta2 - eta1) / halfpi))
if n < 1:
raise ValueError("n must be >= 1 or None")
deta = (eta2 - eta1) / n
t = np.tan(0.5 * deta)
alpha = np.sin(deta) * (np.sqrt(4.0 + 3.0 * t * t) - 1) / 3.0
steps = np.linspace(eta1, eta2, n + 1, True)
cos_eta = np.cos(steps)
sin_eta = np.sin(steps)
xA = cos_eta[:-1]
yA = sin_eta[:-1]
xA_dot = -yA
yA_dot = xA
xB = cos_eta[1:]
yB = sin_eta[1:]
xB_dot = -yB
yB_dot = xB
if is_wedge:
length = n * 3 + 4
vertices = np.zeros((length, 2), np.float_)
codes = Path.CURVE4 * np.ones((length, ), Path.code_type)
vertices[1] = [xA[0], yA[0]]
codes[0:2] = [Path.MOVETO, Path.LINETO]
codes[-2:] = [Path.LINETO, Path.CLOSEPOLY]
vertex_offset = 2
end = length - 2
else:
length = n * 3 + 1
vertices = np.zeros((length, 2), np.float_)
codes = Path.CURVE4 * np.ones((length, ), Path.code_type)
vertices[0] = [xA[0], yA[0]]
codes[0] = Path.MOVETO
vertex_offset = 1
end = length
vertices[vertex_offset :end:3, 0] = xA + alpha * xA_dot
vertices[vertex_offset :end:3, 1] = yA + alpha * yA_dot
vertices[vertex_offset+1:end:3, 0] = xB - alpha * xB_dot
vertices[vertex_offset+1:end:3, 1] = yB - alpha * yB_dot
vertices[vertex_offset+2:end:3, 0] = xB
vertices[vertex_offset+2:end:3, 1] = yB
return Path(vertices, codes)
arc = classmethod(arc)
#@classmethod
def wedge(cls, theta1, theta2, n=None):
"""
(staticmethod) Returns a wedge of the unit circle from angle
*theta1* to angle *theta2* (in degrees).
If *n* is provided, it is the number of spline segments to make.
If *n* is not provided, the number of spline segments is
determined based on the delta between *theta1* and *theta2*.
"""
return cls.arc(theta1, theta2, n, True)
wedge = classmethod(wedge)
_get_path_collection_extents = get_path_collection_extents
def get_path_collection_extents(*args):
"""
Given a sequence of :class:`Path` objects, returns the bounding
box that encapsulates all of them.
"""
from transforms import Bbox
if len(args[1]) == 0:
raise ValueError("No paths provided")
return Bbox.from_extents(*_get_path_collection_extents(*args))
|
agpl-3.0
|
[
624,
199,
6906,
282,
1021,
367,
28453,
3792,
334,
6023,
1278,
680,
199,
624,
199,
199,
646,
3473,
199,
504,
13852,
492,
28224,
1110,
11728,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
492,
610,
199,
199,
504,
8027,
423,
515,
492,
2376,
63,
262,
63,
515,
12,
664,
63,
515,
63,
11599,
83,
12,
971,
272,
2376,
63,
262,
63,
515,
63,
3627,
12,
664,
63,
515,
63,
3627,
63,
11599,
83,
12,
971,
272,
931,
63,
262,
63,
515,
12,
931,
63,
1058,
25353,
63,
515,
12,
3957,
63,
515,
63,
475,
63,
2515,
18067,
199,
504,
8027,
14,
67,
2706,
492,
3486,
63,
6676,
63,
21080,
199,
199,
533,
6912,
8,
785,
304,
272,
408,
272,
520,
533,
1705,
2042,
64,
8469,
282,
6779,
402,
12570,
25602,
12,
272,
12570,
6876,
12,
1004,
436,
15318,
11998,
14,
339,
710,
8793,
4887,
365,
6326,
1536,
402,
2877,
9861,
2680,
6572,
26,
489,
446,
627,
12637,
19429,
376,
653,
88,
18,
2069,
1625,
402,
14971,
489,
446,
627,
6021,
19429,
376,
653,
13,
1267,
3152,
24,
1625,
402,
12759,
2943,
339,
5723,
2877,
6572,
3544,
1172,
314,
2011,
2582,
315,
314,
1642,
272,
6240,
14,
221,
2104,
2893,
12,
370,
2954,
282,
22217,
530,
15318,
12,
1265,
1471,
272,
5647,
7795,
14971,
465,
5521,
465,
7795,
9479,
1124,
7013,
2524,
19,
4345,
339,
710,
1233,
2943,
787,
26,
10817,
446,
1124,
11632,
1040,
257,
520,
221,
413,
12759,
334,
11996,
9,
1779,
437,
3608,
367,
314,
1284,
402,
314,
8039,
931,
334,
19767,
440,
1779,
1415,
436,
5525,
9,
10817,
446,
1124,
24321,
26614,
1040,
520,
221,
413,
12759,
288,
16568,
1536,
314,
12374,
436,
4057,
370,
314,
1627,
12759,
14,
10817,
446,
1124,
6143,
26614,
1040,
520,
221,
413,
12759,
288,
17813,
282,
1004,
687,
314,
1453,
3421,
370,
314,
1627,
12759,
14,
10817,
446,
1124,
7013,
2524,
19,
1040,
520,
221,
413,
3304,
2376,
12,
413,
6037,
881,
17813,
282,
16744,
19826,
6423,
90,
4446,
15318,
687,
314,
1453,
3421,
12,
881,
543,
314,
1627,
3304,
2376,
12,
370,
314,
1627,
1284,
2376,
14,
10817,
446,
1124,
7013,
2524,
20,
1040,
520,
221,
499,
3304,
4501,
12,
413,
6037,
881,
17813,
282,
22217,
530,
6423,
90,
4446,
15318,
687,
314,
1453,
3421,
12,
543,
881,
314,
1627,
3304,
4501,
12,
370,
314,
1627,
1284,
2376,
14,
10817,
446,
1124,
18219,
19869,
1040,
520,
413,
12759,
334,
11996,
9,
881,
17813,
282,
1004,
8135,
370,
314,
1343,
2376,
402,
314,
1453,
881,
8446,
604,
14,
339,
20123,
402,
6912,
2251,
1077,
440,
2879,
314,
14971,
436,
9479,
272,
6572,
5370,
14,
221,
15345,
12,
2985,
1077,
675,
520,
5247,
1705,
1661,
63,
13879,
64,
272,
370,
664,
314,
12759,
15,
600,
6342,
14,
221,
961,
365,
11012,
12,
3967,
5002,
272,
520,
533,
1705,
2042,
64,
2251,
12,
465,
376,
13712,
12,
886,
440,
3877,
282,
627,
6021,
10,
272,
737,
1006,
12,
1325,
1172,
282,
849,
1373,
2741,
367,
3062,
701,
272,
520,
5247,
1705,
1661,
63,
13879,
2313,
339,
3390,
2597,
626,
314,
14971,
436,
9479,
6572,
1077,
506,
10184,
465,
272,
17092,
1553,
2337,
787,
282,
1329,
402,
5323,
12270,
436,
21546,
272,
6326,
1536,
13738,
315,
314,
3787,
626,
911,
440,
1570,
1380,
314,
272,
666,
4493,
14,
272,
408,
339,
327,
6912,
9479,
272,
22348,
420,
275,
378,
327,
413,
12759,
272,
10362,
54,
26614,
259,
275,
413,
327,
413,
12759,
272,
491,
11367,
47,
259,
275,
499,
327,
413,
12759,
272,
18715,
2524,
19,
259,
275,
650,
327,
499,
14971,
272,
18715,
2524,
20,
259,
275,
841,
327,
650,
14971,
272,
445,
1484,
899,
19869,
275,
959,
327,
413,
12759,
339,
11576,
63,
8851,
7040,
275,
359,
17,
12,
413,
12,
413,
12,
499,
12,
650,
12,
413,
61,
339,
1233,
63,
466,
275,
980,
14,
1635,
24,
339,
347,
636,
826,
721,
277,
12,
14971,
12,
9479,
29,
403,
304,
267,
408,
267,
2790,
282,
892,
931,
543,
314,
1627,
14971,
436,
9479,
14,
398,
627,
12637,
10,
365,
376,
653,
88,
18,
2680,
2069,
1625,
12,
9742,
1625,
503,
2018,
267,
3414,
14,
398,
627,
6021,
10,
365,
376,
653,
13,
1267,
2680,
1625,
503,
2018,
3414,
402,
730,
267,
520,
962,
1705,
16440,
14,
515,
14,
2042,
14,
600,
63,
466,
2313,
398,
5723,
2877,
6572,
1471,
1172,
314,
2011,
2582,
315,
314,
1642,
267,
6240,
14,
398,
982,
627,
6021,
10,
365,
488,
12,
627,
12637,
10,
911,
506,
10184,
465,
282,
6779,
402,
267,
1004,
11998,
14,
398,
982,
627,
12637,
10,
3509,
9742,
1338,
12,
2985,
911,
506,
6702,
267,
370,
31930,
1314,
787,
2066,
8860,
6657,
701,
314,
18693,
267,
6912,
3585,
436,
1163,
9451,
2393,
402,
931,
666,
12,
4066,
465,
267,
520,
5247,
1705,
1661,
63,
13879,
2313,
267,
408,
267,
340,
610,
14,
374,
5144,
20999,
8,
12637,
304,
288,
14971,
275,
14971,
14,
6041,
8,
1590,
14,
1609,
63,
680,
17647,
8,
1590,
14,
4304,
9,
267,
587,
26,
288,
14971,
275,
980,
14,
8748,
8,
12637,
12,
980,
14,
1609,
4602,
398,
340,
9479,
365,
440,
488,
26,
288,
9479,
275,
980,
14,
8748,
8,
6021,
12,
291,
14,
600,
63,
466,
9,
288,
702,
9479,
14,
8322,
508,
413,
288,
702,
822,
8,
6021,
9,
508,
822,
8,
12637,
9,
398,
702,
14971,
14,
8322,
508,
499,
267,
702,
14971,
14,
1392,
59,
17,
61,
508,
499,
398,
291,
14,
5626,
63,
19084,
275,
334,
552,
8,
12637,
9,
2356,
7960,
436,
1816,
334,
6021,
365,
488,
503,
980,
14,
452,
8,
6021,
2695,
6912,
14,
6143,
26614,
1724,
267,
291,
14,
1989,
63,
2865,
8005,
275,
440,
980,
14,
30276,
8,
12637,
680,
452,
342,
267,
291,
14,
6021,
275,
9479,
267,
291,
14,
12637,
275,
14971,
339,
9213,
4639,
272,
347,
1852,
63,
15278,
63,
515,
2031,
589,
304,
267,
408,
267,
334,
4639,
9,
4155,
282,
16487,
931,
687,
282,
769,
402,
6912,
267,
2251,
14,
221,
5972,
30658,
334,
1397,
1094,
2310,
9,
787,
3748,
14,
267,
408,
267,
367,
299,
315,
1249,
26,
288,
702,
299,
14,
6021,
365,
488,
398,
17464,
275,
359,
552,
8,
88
] |
[
199,
6906,
282,
1021,
367,
28453,
3792,
334,
6023,
1278,
680,
199,
624,
199,
199,
646,
3473,
199,
504,
13852,
492,
28224,
1110,
11728,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
492,
610,
199,
199,
504,
8027,
423,
515,
492,
2376,
63,
262,
63,
515,
12,
664,
63,
515,
63,
11599,
83,
12,
971,
272,
2376,
63,
262,
63,
515,
63,
3627,
12,
664,
63,
515,
63,
3627,
63,
11599,
83,
12,
971,
272,
931,
63,
262,
63,
515,
12,
931,
63,
1058,
25353,
63,
515,
12,
3957,
63,
515,
63,
475,
63,
2515,
18067,
199,
504,
8027,
14,
67,
2706,
492,
3486,
63,
6676,
63,
21080,
199,
199,
533,
6912,
8,
785,
304,
272,
408,
272,
520,
533,
1705,
2042,
64,
8469,
282,
6779,
402,
12570,
25602,
12,
272,
12570,
6876,
12,
1004,
436,
15318,
11998,
14,
339,
710,
8793,
4887,
365,
6326,
1536,
402,
2877,
9861,
2680,
6572,
26,
489,
446,
627,
12637,
19429,
376,
653,
88,
18,
2069,
1625,
402,
14971,
489,
446,
627,
6021,
19429,
376,
653,
13,
1267,
3152,
24,
1625,
402,
12759,
2943,
339,
5723,
2877,
6572,
3544,
1172,
314,
2011,
2582,
315,
314,
1642,
272,
6240,
14,
221,
2104,
2893,
12,
370,
2954,
282,
22217,
530,
15318,
12,
1265,
1471,
272,
5647,
7795,
14971,
465,
5521,
465,
7795,
9479,
1124,
7013,
2524,
19,
4345,
339,
710,
1233,
2943,
787,
26,
10817,
446,
1124,
11632,
1040,
257,
520,
221,
413,
12759,
334,
11996,
9,
1779,
437,
3608,
367,
314,
1284,
402,
314,
8039,
931,
334,
19767,
440,
1779,
1415,
436,
5525,
9,
10817,
446,
1124,
24321,
26614,
1040,
520,
221,
413,
12759,
288,
16568,
1536,
314,
12374,
436,
4057,
370,
314,
1627,
12759,
14,
10817,
446,
1124,
6143,
26614,
1040,
520,
221,
413,
12759,
288,
17813,
282,
1004,
687,
314,
1453,
3421,
370,
314,
1627,
12759,
14,
10817,
446,
1124,
7013,
2524,
19,
1040,
520,
221,
413,
3304,
2376,
12,
413,
6037,
881,
17813,
282,
16744,
19826,
6423,
90,
4446,
15318,
687,
314,
1453,
3421,
12,
881,
543,
314,
1627,
3304,
2376,
12,
370,
314,
1627,
1284,
2376,
14,
10817,
446,
1124,
7013,
2524,
20,
1040,
520,
221,
499,
3304,
4501,
12,
413,
6037,
881,
17813,
282,
22217,
530,
6423,
90,
4446,
15318,
687,
314,
1453,
3421,
12,
543,
881,
314,
1627,
3304,
4501,
12,
370,
314,
1627,
1284,
2376,
14,
10817,
446,
1124,
18219,
19869,
1040,
520,
413,
12759,
334,
11996,
9,
881,
17813,
282,
1004,
8135,
370,
314,
1343,
2376,
402,
314,
1453,
881,
8446,
604,
14,
339,
20123,
402,
6912,
2251,
1077,
440,
2879,
314,
14971,
436,
9479,
272,
6572,
5370,
14,
221,
15345,
12,
2985,
1077,
675,
520,
5247,
1705,
1661,
63,
13879,
64,
272,
370,
664,
314,
12759,
15,
600,
6342,
14,
221,
961,
365,
11012,
12,
3967,
5002,
272,
520,
533,
1705,
2042,
64,
2251,
12,
465,
376,
13712,
12,
886,
440,
3877,
282,
627,
6021,
10,
272,
737,
1006,
12,
1325,
1172,
282,
849,
1373,
2741,
367,
3062,
701,
272,
520,
5247,
1705,
1661,
63,
13879,
2313,
339,
3390,
2597,
626,
314,
14971,
436,
9479,
6572,
1077,
506,
10184,
465,
272,
17092,
1553,
2337,
787,
282,
1329,
402,
5323,
12270,
436,
21546,
272,
6326,
1536,
13738,
315,
314,
3787,
626,
911,
440,
1570,
1380,
314,
272,
666,
4493,
14,
272,
408,
339,
327,
6912,
9479,
272,
22348,
420,
275,
378,
327,
413,
12759,
272,
10362,
54,
26614,
259,
275,
413,
327,
413,
12759,
272,
491,
11367,
47,
259,
275,
499,
327,
413,
12759,
272,
18715,
2524,
19,
259,
275,
650,
327,
499,
14971,
272,
18715,
2524,
20,
259,
275,
841,
327,
650,
14971,
272,
445,
1484,
899,
19869,
275,
959,
327,
413,
12759,
339,
11576,
63,
8851,
7040,
275,
359,
17,
12,
413,
12,
413,
12,
499,
12,
650,
12,
413,
61,
339,
1233,
63,
466,
275,
980,
14,
1635,
24,
339,
347,
636,
826,
721,
277,
12,
14971,
12,
9479,
29,
403,
304,
267,
408,
267,
2790,
282,
892,
931,
543,
314,
1627,
14971,
436,
9479,
14,
398,
627,
12637,
10,
365,
376,
653,
88,
18,
2680,
2069,
1625,
12,
9742,
1625,
503,
2018,
267,
3414,
14,
398,
627,
6021,
10,
365,
376,
653,
13,
1267,
2680,
1625,
503,
2018,
3414,
402,
730,
267,
520,
962,
1705,
16440,
14,
515,
14,
2042,
14,
600,
63,
466,
2313,
398,
5723,
2877,
6572,
1471,
1172,
314,
2011,
2582,
315,
314,
1642,
267,
6240,
14,
398,
982,
627,
6021,
10,
365,
488,
12,
627,
12637,
10,
911,
506,
10184,
465,
282,
6779,
402,
267,
1004,
11998,
14,
398,
982,
627,
12637,
10,
3509,
9742,
1338,
12,
2985,
911,
506,
6702,
267,
370,
31930,
1314,
787,
2066,
8860,
6657,
701,
314,
18693,
267,
6912,
3585,
436,
1163,
9451,
2393,
402,
931,
666,
12,
4066,
465,
267,
520,
5247,
1705,
1661,
63,
13879,
2313,
267,
408,
267,
340,
610,
14,
374,
5144,
20999,
8,
12637,
304,
288,
14971,
275,
14971,
14,
6041,
8,
1590,
14,
1609,
63,
680,
17647,
8,
1590,
14,
4304,
9,
267,
587,
26,
288,
14971,
275,
980,
14,
8748,
8,
12637,
12,
980,
14,
1609,
4602,
398,
340,
9479,
365,
440,
488,
26,
288,
9479,
275,
980,
14,
8748,
8,
6021,
12,
291,
14,
600,
63,
466,
9,
288,
702,
9479,
14,
8322,
508,
413,
288,
702,
822,
8,
6021,
9,
508,
822,
8,
12637,
9,
398,
702,
14971,
14,
8322,
508,
499,
267,
702,
14971,
14,
1392,
59,
17,
61,
508,
499,
398,
291,
14,
5626,
63,
19084,
275,
334,
552,
8,
12637,
9,
2356,
7960,
436,
1816,
334,
6021,
365,
488,
503,
980,
14,
452,
8,
6021,
2695,
6912,
14,
6143,
26614,
1724,
267,
291,
14,
1989,
63,
2865,
8005,
275,
440,
980,
14,
30276,
8,
12637,
680,
452,
342,
267,
291,
14,
6021,
275,
9479,
267,
291,
14,
12637,
275,
14971,
339,
9213,
4639,
272,
347,
1852,
63,
15278,
63,
515,
2031,
589,
304,
267,
408,
267,
334,
4639,
9,
4155,
282,
16487,
931,
687,
282,
769,
402,
6912,
267,
2251,
14,
221,
5972,
30658,
334,
1397,
1094,
2310,
9,
787,
3748,
14,
267,
408,
267,
367,
299,
315,
1249,
26,
288,
702,
299,
14,
6021,
365,
488,
398,
17464,
275,
359,
552,
8,
88,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
manqala/erpnext
|
erpnext/patches/v7_0/create_warehouse_nestedset.py
|
21
|
4746
|
from __future__ import unicode_literals
import frappe, erpnext
from frappe import _
from frappe.utils import cint
from frappe.utils.nestedset import rebuild_tree
def execute():
"""
Patch Reference:
1. check whether warehouse is associated to company or not
2. if warehouse is associated with company
a. create warehouse group for company
b. set warehouse group as parent to other warehouses and set is_group as 0
3. if warehouses is not associated with company
a. get distinct companies from stock ledger entries
b. if sle have only company,
i. set default company to all warehouse
ii. repeat 2.a and 2.b
c. if have multiple companies,
i. create group warehouse without company
ii. repeat 2.b
"""
frappe.reload_doc("stock", "doctype", "warehouse")
if check_is_warehouse_associated_with_company():
for company in frappe.get_all("Company", fields=["name", "abbr"]):
make_warehouse_nestedset(company)
else:
sle_against_companies = frappe.db.sql_list("""select distinct company from `tabStock Ledger Entry`""")
if len(sle_against_companies) == 1:
company = frappe.db.get_value("Company", sle_against_companies[0],
fieldname=["name", "abbr"], as_dict=1)
set_company_to_warehouse(company.name)
make_warehouse_nestedset(company)
elif len(sle_against_companies) > 1:
make_warehouse_nestedset()
def check_is_warehouse_associated_with_company():
warehouse_associcated_with_company = False
for warehouse in frappe.get_all("Warehouse", fields=["name", "company"]):
if warehouse.company:
warehouse_associcated_with_company = True
return warehouse_associcated_with_company
def make_warehouse_nestedset(company=None):
validate_parent_account_for_warehouse(company)
stock_account_group = get_stock_account_group(company.name)
enable_perpetual_inventory = cint(erpnext.is_perpetual_inventory_enabled(company.name)) or 0
if not stock_account_group and enable_perpetual_inventory:
return
if company:
warehouse_group = "{0} - {1}".format(_("All Warehouses"), company.abbr)
ignore_mandatory = False
else:
warehouse_group = _("All Warehouses")
ignore_mandatory = True
if not frappe.db.get_value("Warehouse", warehouse_group):
create_default_warehouse_group(company, stock_account_group, ignore_mandatory)
set_parent_to_warehouse(warehouse_group, company)
if enable_perpetual_inventory:
set_parent_to_warehouse_account(company)
def validate_parent_account_for_warehouse(company=None):
if not company:
return
if cint(erpnext.is_perpetual_inventory_enabled(company.name)):
parent_account = frappe.db.sql("""select name from tabAccount
where account_type='Stock' and company=%s and is_group=1
and (warehouse is null or warehouse = '')""", company.name)
if not parent_account:
current_parent_accounts_for_warehouse = frappe.db.sql("""select parent_account from tabAccount
where account_type='Warehouse' and (warehouse is not null or warehouse != '') """)
if current_parent_accounts_for_warehouse:
frappe.db.set_value("Account", current_parent_accounts_for_warehouse[0][0], "account_type", "Stock")
def create_default_warehouse_group(company=None, stock_account_group=None, ignore_mandatory=False):
wh = frappe.get_doc({
"doctype": "Warehouse",
"warehouse_name": _("All Warehouses"),
"is_group": 1,
"company": company.name if company else "",
"parent_warehouse": ""
})
if ignore_mandatory:
wh.flags.ignore_mandatory = ignore_mandatory
wh.insert(ignore_permissions=True)
def set_parent_to_warehouse(warehouse_group, company=None):
frappe.db.sql(""" update tabWarehouse set parent_warehouse = %s, is_group = 0
where (is_group = 0 or is_group is null or is_group = '') and ifnull(company, '') = %s
""",(warehouse_group, company.name if company else ""))
rebuild_tree("Warehouse", "parent_warehouse")
def set_parent_to_warehouse_account(company):
frappe.db.sql(""" update tabAccount set parent_account = %s
where is_group = 0 and account_type = "Warehouse"
and (warehouse is not null or warehouse != '') and company = %s
""",("{0} - {1}".format(_("All Warehouses"), company.abbr), company.name))
rebuild_tree("Account", "parent_account")
def set_company_to_warehouse(company):
frappe.db.sql("update tabWahouse set company=%s", company)
def get_stock_account_group(company):
stock_account_group = frappe.db.get_all('Account', filters = {'company': company, 'is_group': 1,
'account_type': 'Stock', 'root_type': 'Asset'}, limit=1)
if not stock_account_group:
stock_account_group = frappe.db.get_all('Account', filters = {'company': company, 'is_group': 1,
'parent_account': '', 'root_type': 'Asset'}, limit=1)
return stock_account_group[0].name if stock_account_group else None
|
gpl-3.0
|
[
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
12,
29106,
199,
504,
6950,
492,
485,
199,
504,
6950,
14,
1208,
492,
286,
442,
199,
504,
6950,
14,
1208,
14,
6376,
409,
492,
22110,
63,
2350,
199,
199,
318,
5341,
837,
199,
198,
624,
199,
198,
11173,
10944,
26,
507,
198,
17,
14,
1104,
3775,
13782,
365,
4568,
370,
7233,
503,
440,
507,
198,
18,
14,
340,
13782,
365,
4568,
543,
7233,
686,
198,
65,
14,
1218,
13782,
1572,
367,
7233,
686,
198,
66,
14,
663,
13782,
1572,
465,
1676,
370,
1163,
336,
1530,
526,
5589,
436,
663,
365,
63,
923,
465,
378,
507,
198,
19,
14,
340,
336,
1530,
526,
5589,
365,
440,
4568,
543,
7233,
686,
198,
65,
14,
664,
15392,
1013,
23461,
687,
10952,
29239,
836,
4811,
686,
198,
66,
14,
340,
26220,
1172,
1454,
7233,
12,
1585,
198,
73,
14,
663,
849,
7233,
370,
1006,
13782,
1585,
198,
5908,
14,
11982,
499,
14,
65,
436,
499,
14,
66,
686,
198,
67,
14,
340,
1172,
3663,
1013,
23461,
12,
1585,
198,
73,
14,
1218,
1572,
13782,
1928,
7233,
1585,
198,
5908,
14,
11982,
499,
14,
66,
199,
198,
624,
8299,
198,
9098,
14,
9233,
63,
1301,
480,
6088,
401,
298,
6356,
401,
298,
12806,
531,
421,
198,
692,
1104,
63,
374,
63,
12806,
63,
22288,
63,
1045,
63,
4627,
837,
507,
198,
509,
7233,
315,
6950,
14,
362,
63,
452,
480,
16063,
401,
1504,
6270,
354,
401,
298,
20787,
21473,
686,
198,
1875,
63,
12806,
63,
6376,
409,
8,
4627,
9,
199,
198,
2836,
26,
507,
198,
23042,
63,
17777,
63,
863,
23461,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
15392,
7233,
687,
658,
2902,
17103,
491,
379,
836,
11855,
64,
6141,
2742,
198,
692,
822,
8,
23042,
63,
17777,
63,
863,
23461,
9,
508,
413,
26,
686,
198,
4627,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
16063,
401,
26220,
63,
17777,
63,
863,
23461,
59,
16,
467,
28932,
198,
13646,
6270,
354,
401,
298,
20787,
2255,
465,
63,
807,
29,
17,
9,
686,
198,
409,
63,
4627,
63,
475,
63,
12806,
8,
4627,
14,
354,
9,
686,
198,
1875,
63,
12806,
63,
6376,
409,
8,
4627,
9,
2742,
198,
4164,
822,
8,
23042,
63,
17777,
63,
863,
23461,
9,
690,
413,
26,
686,
198,
1875,
63,
12806,
63,
6376,
409,
342,
199,
199,
318,
1104,
63,
374,
63,
12806,
63,
22288,
63,
1045,
63,
4627,
837,
199,
198,
12806,
63,
16824,
530,
972,
63,
1045,
63,
4627,
275,
756,
421,
198,
509,
13782,
315,
6950,
14,
362,
63,
452,
480,
55,
11499,
401,
1504,
6270,
354,
401,
298,
4627,
21473,
507,
198,
692,
13782,
14,
4627,
26,
686,
198,
12806,
63,
16824,
530,
972,
63,
1045,
63,
4627,
275,
715,
421,
198,
1107,
13782,
63,
16824,
530,
972,
63,
1045,
63,
4627,
199,
199,
318,
1852,
63,
12806,
63,
6376,
409,
8,
4627,
29,
403,
304,
199,
198,
3502,
63,
1708,
63,
2048,
63,
509,
63,
12806,
8,
4627,
9,
199,
198,
6088,
63,
2048,
63,
923,
275,
664,
63,
6088,
63,
2048,
63,
923,
8,
4627,
14,
354,
9,
199,
198,
4296,
63,
529,
321,
1688,
63,
7212,
275,
286,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
4627,
14,
354,
430,
503,
378,
199,
198,
692,
440,
10952,
63,
2048,
63,
923,
436,
4756,
63,
529,
321,
1688,
63,
7212,
26,
507,
198,
1107,
421,
198,
692,
7233,
26,
507,
198,
12806,
63,
923,
275,
5310,
16,
93,
446,
469,
17,
5469,
908,
6115,
2422,
644,
1530,
526,
5589,
1288,
7233,
14,
20787,
9,
507,
198,
4247,
63,
19900,
275,
756,
199,
198,
2836,
26,
507,
198,
12806,
63,
923,
275,
3824,
2422,
644,
1530,
526,
5589,
531,
507,
198,
4247,
63,
19900,
275,
715,
421,
198,
692,
440,
6950,
14,
697,
14,
362,
63,
585,
480,
55,
11499,
401,
13782,
63,
923,
304,
507,
198,
981,
63,
885,
63,
12806,
63,
923,
8,
4627,
12,
10952,
63,
2048,
63,
923,
12,
3686,
63,
19900,
9,
421,
198,
409,
63,
1708,
63,
475,
63,
12806,
8,
12806,
63,
923,
12,
7233,
9,
199,
198,
692,
4756,
63,
529,
321,
1688,
63,
7212,
26,
507,
198,
409,
63,
1708,
63,
475,
63,
12806,
63,
2048,
8,
4627,
9,
199,
199,
318,
4107,
63,
1708,
63,
2048,
63,
509,
63,
12806,
8,
4627,
29,
403,
304,
199,
198,
692,
440,
7233,
26,
507,
198,
1107,
421,
198,
692,
286,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
4627,
14,
354,
2298,
507,
198,
1708,
63,
2048,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
536,
687,
5174,
6009,
686,
198,
4509,
2933,
63,
466,
534,
17103,
7,
436,
7233,
2458,
83,
436,
365,
63,
923,
29,
17,
686,
198,
460,
334,
12806,
365,
2973,
503,
13782,
275,
4074,
7208,
7233,
14,
354,
9,
2742,
198,
692,
440,
1676,
63,
2048,
26,
686,
198,
1818,
63,
1708,
63,
8370,
63,
509,
63,
12806,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
1676,
63,
2048,
687,
5174,
6009,
1585,
198,
4509,
2933,
63,
466,
534,
55,
11499,
7,
436,
334,
12806,
365,
440,
2973,
503,
13782,
1137,
4074,
7857,
6319,
198,
692,
1453,
63,
1708,
63,
8370,
63,
509,
63,
12806,
26,
1585,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
6009,
401,
1453,
63,
1708,
63,
8370,
63,
509,
63,
12806,
59,
16,
1527,
16,
467,
298,
2048,
63,
466,
401,
298,
17103,
531,
199,
199,
318,
1218,
63,
885,
63,
12806,
63,
923,
8,
4627,
29,
403,
12,
10952,
63,
2048,
63,
923,
29,
403,
12,
3686,
63,
19900,
29,
797,
304,
199,
198,
2191,
275,
6950,
14,
362,
63,
1301,
2561,
507,
198,
2,
6356,
582,
298,
55,
11499,
401,
507,
198,
2,
12806,
63,
354,
582,
3824,
2422,
644,
1530,
526,
5589,
1288,
507,
198,
2,
374,
63,
923,
582,
413,
12,
507,
198,
2,
4627,
582,
7233,
14,
354,
340,
7233,
587,
4873,
507,
198,
2,
1708,
63,
12806,
582,
3087,
199,
198,
1552,
421,
198,
692,
3686,
63,
19900,
26,
507,
198,
2191
] |
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
12,
29106,
199,
504,
6950,
492,
485,
199,
504,
6950,
14,
1208,
492,
286,
442,
199,
504,
6950,
14,
1208,
14,
6376,
409,
492,
22110,
63,
2350,
199,
199,
318,
5341,
837,
199,
198,
624,
199,
198,
11173,
10944,
26,
507,
198,
17,
14,
1104,
3775,
13782,
365,
4568,
370,
7233,
503,
440,
507,
198,
18,
14,
340,
13782,
365,
4568,
543,
7233,
686,
198,
65,
14,
1218,
13782,
1572,
367,
7233,
686,
198,
66,
14,
663,
13782,
1572,
465,
1676,
370,
1163,
336,
1530,
526,
5589,
436,
663,
365,
63,
923,
465,
378,
507,
198,
19,
14,
340,
336,
1530,
526,
5589,
365,
440,
4568,
543,
7233,
686,
198,
65,
14,
664,
15392,
1013,
23461,
687,
10952,
29239,
836,
4811,
686,
198,
66,
14,
340,
26220,
1172,
1454,
7233,
12,
1585,
198,
73,
14,
663,
849,
7233,
370,
1006,
13782,
1585,
198,
5908,
14,
11982,
499,
14,
65,
436,
499,
14,
66,
686,
198,
67,
14,
340,
1172,
3663,
1013,
23461,
12,
1585,
198,
73,
14,
1218,
1572,
13782,
1928,
7233,
1585,
198,
5908,
14,
11982,
499,
14,
66,
199,
198,
624,
8299,
198,
9098,
14,
9233,
63,
1301,
480,
6088,
401,
298,
6356,
401,
298,
12806,
531,
421,
198,
692,
1104,
63,
374,
63,
12806,
63,
22288,
63,
1045,
63,
4627,
837,
507,
198,
509,
7233,
315,
6950,
14,
362,
63,
452,
480,
16063,
401,
1504,
6270,
354,
401,
298,
20787,
21473,
686,
198,
1875,
63,
12806,
63,
6376,
409,
8,
4627,
9,
199,
198,
2836,
26,
507,
198,
23042,
63,
17777,
63,
863,
23461,
275,
6950,
14,
697,
14,
3009,
63,
513,
4852,
2416,
15392,
7233,
687,
658,
2902,
17103,
491,
379,
836,
11855,
64,
6141,
2742,
198,
692,
822,
8,
23042,
63,
17777,
63,
863,
23461,
9,
508,
413,
26,
686,
198,
4627,
275,
6950,
14,
697,
14,
362,
63,
585,
480,
16063,
401,
26220,
63,
17777,
63,
863,
23461,
59,
16,
467,
28932,
198,
13646,
6270,
354,
401,
298,
20787,
2255,
465,
63,
807,
29,
17,
9,
686,
198,
409,
63,
4627,
63,
475,
63,
12806,
8,
4627,
14,
354,
9,
686,
198,
1875,
63,
12806,
63,
6376,
409,
8,
4627,
9,
2742,
198,
4164,
822,
8,
23042,
63,
17777,
63,
863,
23461,
9,
690,
413,
26,
686,
198,
1875,
63,
12806,
63,
6376,
409,
342,
199,
199,
318,
1104,
63,
374,
63,
12806,
63,
22288,
63,
1045,
63,
4627,
837,
199,
198,
12806,
63,
16824,
530,
972,
63,
1045,
63,
4627,
275,
756,
421,
198,
509,
13782,
315,
6950,
14,
362,
63,
452,
480,
55,
11499,
401,
1504,
6270,
354,
401,
298,
4627,
21473,
507,
198,
692,
13782,
14,
4627,
26,
686,
198,
12806,
63,
16824,
530,
972,
63,
1045,
63,
4627,
275,
715,
421,
198,
1107,
13782,
63,
16824,
530,
972,
63,
1045,
63,
4627,
199,
199,
318,
1852,
63,
12806,
63,
6376,
409,
8,
4627,
29,
403,
304,
199,
198,
3502,
63,
1708,
63,
2048,
63,
509,
63,
12806,
8,
4627,
9,
199,
198,
6088,
63,
2048,
63,
923,
275,
664,
63,
6088,
63,
2048,
63,
923,
8,
4627,
14,
354,
9,
199,
198,
4296,
63,
529,
321,
1688,
63,
7212,
275,
286,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
4627,
14,
354,
430,
503,
378,
199,
198,
692,
440,
10952,
63,
2048,
63,
923,
436,
4756,
63,
529,
321,
1688,
63,
7212,
26,
507,
198,
1107,
421,
198,
692,
7233,
26,
507,
198,
12806,
63,
923,
275,
5310,
16,
93,
446,
469,
17,
5469,
908,
6115,
2422,
644,
1530,
526,
5589,
1288,
7233,
14,
20787,
9,
507,
198,
4247,
63,
19900,
275,
756,
199,
198,
2836,
26,
507,
198,
12806,
63,
923,
275,
3824,
2422,
644,
1530,
526,
5589,
531,
507,
198,
4247,
63,
19900,
275,
715,
421,
198,
692,
440,
6950,
14,
697,
14,
362,
63,
585,
480,
55,
11499,
401,
13782,
63,
923,
304,
507,
198,
981,
63,
885,
63,
12806,
63,
923,
8,
4627,
12,
10952,
63,
2048,
63,
923,
12,
3686,
63,
19900,
9,
421,
198,
409,
63,
1708,
63,
475,
63,
12806,
8,
12806,
63,
923,
12,
7233,
9,
199,
198,
692,
4756,
63,
529,
321,
1688,
63,
7212,
26,
507,
198,
409,
63,
1708,
63,
475,
63,
12806,
63,
2048,
8,
4627,
9,
199,
199,
318,
4107,
63,
1708,
63,
2048,
63,
509,
63,
12806,
8,
4627,
29,
403,
304,
199,
198,
692,
440,
7233,
26,
507,
198,
1107,
421,
198,
692,
286,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
4627,
14,
354,
2298,
507,
198,
1708,
63,
2048,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
536,
687,
5174,
6009,
686,
198,
4509,
2933,
63,
466,
534,
17103,
7,
436,
7233,
2458,
83,
436,
365,
63,
923,
29,
17,
686,
198,
460,
334,
12806,
365,
2973,
503,
13782,
275,
4074,
7208,
7233,
14,
354,
9,
2742,
198,
692,
440,
1676,
63,
2048,
26,
686,
198,
1818,
63,
1708,
63,
8370,
63,
509,
63,
12806,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
1676,
63,
2048,
687,
5174,
6009,
1585,
198,
4509,
2933,
63,
466,
534,
55,
11499,
7,
436,
334,
12806,
365,
440,
2973,
503,
13782,
1137,
4074,
7857,
6319,
198,
692,
1453,
63,
1708,
63,
8370,
63,
509,
63,
12806,
26,
1585,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
6009,
401,
1453,
63,
1708,
63,
8370,
63,
509,
63,
12806,
59,
16,
1527,
16,
467,
298,
2048,
63,
466,
401,
298,
17103,
531,
199,
199,
318,
1218,
63,
885,
63,
12806,
63,
923,
8,
4627,
29,
403,
12,
10952,
63,
2048,
63,
923,
29,
403,
12,
3686,
63,
19900,
29,
797,
304,
199,
198,
2191,
275,
6950,
14,
362,
63,
1301,
2561,
507,
198,
2,
6356,
582,
298,
55,
11499,
401,
507,
198,
2,
12806,
63,
354,
582,
3824,
2422,
644,
1530,
526,
5589,
1288,
507,
198,
2,
374,
63,
923,
582,
413,
12,
507,
198,
2,
4627,
582,
7233,
14,
354,
340,
7233,
587,
4873,
507,
198,
2,
1708,
63,
12806,
582,
3087,
199,
198,
1552,
421,
198,
692,
3686,
63,
19900,
26,
507,
198,
2191,
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,
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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
] |
benschmaus/catapult
|
telemetry/third_party/web-page-replay/httpproxy_test.py
|
11
|
8557
|
#!/usr/bin/env python
# Copyright 2015 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.
import httparchive
import httplib
import httpproxy
import threading
import unittest
import util
class MockCustomResponseHandler(object):
def __init__(self, response):
"""
Args:
response: An instance of ArchivedHttpResponse that is returned for each
request.
"""
self._response = response
def handle(self, request):
del request
return self._response
class MockHttpArchiveFetch(object):
def __init__(self, response):
"""
Args:
response: An instance of ArchivedHttpResponse that is returned for each
request.
"""
self.is_record_mode = False
self._response = response
def __call__(self, request):
del request # unused
return self._response
class MockHttpArchiveHandler(httpproxy.HttpArchiveHandler):
def handle_one_request(self):
httpproxy.HttpArchiveHandler.handle_one_request(self)
HttpProxyTest.HANDLED_REQUEST_COUNT += 1
class MockRules(object):
def Find(self, unused_rule_type_name): # pylint: disable=unused-argument
return lambda unused_request, unused_response: None
class HttpProxyTest(unittest.TestCase):
def setUp(self):
self.has_proxy_server_bound_port = False
self.has_proxy_server_started = False
self.allow_generate_304 = False
self.serve_response_by_http_archive = False
def set_up_proxy_server(self, response):
"""
Args:
response: An instance of ArchivedHttpResponse that is returned for each
request.
"""
HttpProxyTest.HANDLED_REQUEST_COUNT = 0
self.host = 'localhost'
self.port = 8889
custom_handlers = MockCustomResponseHandler(
response if not self.serve_response_by_http_archive else None)
rules = MockRules()
http_archive_fetch = MockHttpArchiveFetch(
response if self.serve_response_by_http_archive else None)
self.proxy_server = httpproxy.HttpProxyServer(
http_archive_fetch, custom_handlers, rules,
host=self.host, port=self.port,
allow_generate_304=self.allow_generate_304)
self.proxy_server.RequestHandlerClass = MockHttpArchiveHandler
self.has_proxy_server_bound_port = True
def tear_down_proxy_server(self):
if self.has_proxy_server_started:
self.proxy_server.shutdown()
if self.has_proxy_server_bound_port:
self.proxy_server.server_close()
def tearDown(self):
self.tear_down_proxy_server()
def serve_requests_forever(self):
self.has_proxy_server_started = True
self.proxy_server.serve_forever(poll_interval=0.01)
# Tests that handle_one_request does not leak threads, and does not try to
# re-handle connections that are finished.
def test_handle_one_request_closes_connection(self):
# By default, BaseHTTPServer.py treats all HTTP 1.1 requests as keep-alive.
# Intentionally use HTTP 1.0 to prevent this behavior.
response = httparchive.ArchivedHttpResponse(
version=10, status=200, reason="OK",
headers=[], response_data=["bat1"])
self.set_up_proxy_server(response)
t = threading.Thread(
target=HttpProxyTest.serve_requests_forever, args=(self,))
t.start()
initial_thread_count = threading.activeCount()
# Make a bunch of requests.
request_count = 10
for _ in range(request_count):
conn = httplib.HTTPConnection('localhost', 8889, timeout=10)
conn.request("GET", "/index.html")
res = conn.getresponse().read()
self.assertEqual(res, "bat1")
conn.close()
# Check to make sure that there is no leaked thread.
util.WaitFor(lambda: threading.activeCount() == initial_thread_count, 2)
self.assertEqual(request_count, HttpProxyTest.HANDLED_REQUEST_COUNT)
# Tests that keep-alive header works.
def test_keep_alive_header(self):
response = httparchive.ArchivedHttpResponse(
version=11, status=200, reason="OK",
headers=[("Connection", "keep-alive")], response_data=["bat1"])
self.set_up_proxy_server(response)
t = threading.Thread(
target=HttpProxyTest.serve_requests_forever, args=(self,))
t.start()
initial_thread_count = threading.activeCount()
# Make a bunch of requests.
request_count = 10
connections = []
for _ in range(request_count):
conn = httplib.HTTPConnection('localhost', 8889, timeout=10)
conn.request("GET", "/index.html", headers={"Connection": "keep-alive"})
res = conn.getresponse().read()
self.assertEqual(res, "bat1")
connections.append(conn)
# Repeat the same requests.
for conn in connections:
conn.request("GET", "/index.html", headers={"Connection": "keep-alive"})
res = conn.getresponse().read()
self.assertEqual(res, "bat1")
# Check that the right number of requests have been handled.
self.assertEqual(2 * request_count, HttpProxyTest.HANDLED_REQUEST_COUNT)
# Check to make sure that exactly "request_count" new threads are active.
self.assertEqual(
threading.activeCount(), initial_thread_count + request_count)
for conn in connections:
conn.close()
util.WaitFor(lambda: threading.activeCount() == initial_thread_count, 1)
# Test that opening 400 simultaneous connections does not cause httpproxy to
# hit a process fd limit. The default limit is 256 fds.
def test_max_fd(self):
response = httparchive.ArchivedHttpResponse(
version=11, status=200, reason="OK",
headers=[("Connection", "keep-alive")], response_data=["bat1"])
self.set_up_proxy_server(response)
t = threading.Thread(
target=HttpProxyTest.serve_requests_forever, args=(self,))
t.start()
# Make a bunch of requests.
request_count = 400
connections = []
for _ in range(request_count):
conn = httplib.HTTPConnection('localhost', 8889, timeout=10)
conn.request("GET", "/index.html", headers={"Connection": "keep-alive"})
res = conn.getresponse().read()
self.assertEqual(res, "bat1")
connections.append(conn)
# Check that the right number of requests have been handled.
self.assertEqual(request_count, HttpProxyTest.HANDLED_REQUEST_COUNT)
for conn in connections:
conn.close()
# Tests that conditional requests return 304.
def test_generate_304(self):
REQUEST_HEADERS = [
{},
{'If-Modified-Since': 'whatever'},
{'If-None-Match': 'whatever yet again'}]
RESPONSE_STATUSES = [200, 204, 304, 404]
for allow_generate_304 in [False, True]:
self.allow_generate_304 = allow_generate_304
for serve_response_by_http_archive in [False, True]:
self.serve_response_by_http_archive = serve_response_by_http_archive
for response_status in RESPONSE_STATUSES:
response = None
if response_status != 404:
response = httparchive.ArchivedHttpResponse(
version=11, status=response_status, reason="OK", headers=[],
response_data=["some content"])
self.set_up_proxy_server(response)
t = threading.Thread(
target=HttpProxyTest.serve_requests_forever, args=(self,))
t.start()
for method in ['GET', 'HEAD', 'POST']:
for headers in REQUEST_HEADERS:
connection = httplib.HTTPConnection('localhost', 8889, timeout=10)
connection.request(method, "/index.html", headers=headers)
response = connection.getresponse()
connection.close()
if (allow_generate_304 and
serve_response_by_http_archive and
method in ['GET', 'HEAD'] and
headers and
response_status == 200):
self.assertEqual(304, response.status)
self.assertEqual('', response.read())
else:
self.assertEqual(response_status, response.status)
self.tear_down_proxy_server()
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
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,
421,
199,
646,
22768,
462,
335,
1912,
199,
646,
8809,
199,
646,
1455,
3280,
199,
646,
5796,
199,
646,
2882,
199,
646,
4884,
421,
199,
533,
4420,
7223,
2364,
2461,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
1177,
304,
272,
408,
272,
3033,
26,
489,
1177,
26,
1626,
1256,
402,
19521,
12905,
16287,
626,
365,
2138,
367,
1924,
489,
1056,
14,
272,
408,
272,
291,
423,
1310,
275,
1177,
819,
347,
2429,
8,
277,
12,
1056,
304,
272,
2150,
1056,
272,
372,
291,
423,
1310,
421,
199,
533,
4420,
5779,
13042,
11135,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
1177,
304,
272,
408,
272,
3033,
26,
489,
1177,
26,
1626,
1256,
402,
19521,
12905,
16287,
626,
365,
2138,
367,
1924,
489,
1056,
14,
272,
408,
272,
291,
14,
374,
63,
3059,
63,
632,
275,
756,
272,
291,
423,
1310,
275,
1177,
819,
347,
636,
1250,
721,
277,
12,
1056,
304,
272,
2150,
1056,
327,
9563,
272,
372,
291,
423,
1310,
421,
199,
533,
4420,
5779,
13042,
2461,
8,
1014,
3280,
14,
5779,
13042,
2461,
304,
523,
347,
2429,
63,
368,
63,
1069,
8,
277,
304,
272,
1455,
3280,
14,
5779,
13042,
2461,
14,
2479,
63,
368,
63,
1069,
8,
277,
9,
272,
4760,
4936,
774,
14,
10854,
5290,
63,
6780,
63,
8760,
847,
413,
421,
199,
533,
4420,
12920,
8,
785,
304,
523,
347,
6668,
8,
277,
12,
9563,
63,
2200,
63,
466,
63,
354,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
372,
2400,
9563,
63,
1069,
12,
9563,
63,
1310,
26,
488,
421,
199,
533,
4760,
4936,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
3556,
63,
719,
275,
756,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
8924,
275,
756,
272,
291,
14,
3306,
63,
4208,
63,
8533,
275,
756,
272,
291,
14,
4909,
63,
1310,
63,
991,
63,
1014,
63,
6404,
275,
756,
819,
347,
663,
63,
384,
63,
3280,
63,
1000,
8,
277,
12,
1177,
304,
272,
408,
272,
3033,
26,
489,
1177,
26,
1626,
1256,
402,
19521,
12905,
16287,
626,
365,
2138,
367,
1924,
489,
1056,
14,
272,
408,
272,
4760,
4936,
774,
14,
10854,
5290,
63,
6780,
63,
8760,
275,
378,
272,
291,
14,
1102,
275,
283,
5967,
7,
272,
291,
14,
719,
275,
10523,
1407,
272,
3537,
63,
5586,
275,
4420,
7223,
2364,
2461,
8,
267,
1177,
340,
440,
291,
14,
4909,
63,
1310,
63,
991,
63,
1014,
63,
6404,
587,
488,
9,
272,
4713,
275,
4420,
12920,
342,
272,
1455,
63,
6404,
63,
3535,
275,
4420,
5779,
13042,
11135,
8,
267,
1177,
340,
291,
14,
4909,
63,
1310,
63,
991,
63,
1014,
63,
6404,
587,
488,
9,
272,
291,
14,
3280,
63,
1000,
275,
1455,
3280,
14,
5779,
4936,
3120,
8,
267,
1455,
63,
6404,
63,
3535,
12,
3537,
63,
5586,
12,
4713,
12,
267,
1591,
29,
277,
14,
1102,
12,
1844,
29,
277,
14,
719,
12,
267,
2040,
63,
4208,
63,
8533,
29,
277,
14,
3306,
63,
4208,
63,
8533,
9,
272,
291,
14,
3280,
63,
1000,
14,
11149,
2543,
275,
4420,
5779,
13042,
2461,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
3556,
63,
719,
275,
715,
819,
347,
1565,
285,
63,
2110,
63,
3280,
63,
1000,
8,
277,
304,
272,
340,
291,
14,
1989,
63,
3280,
63,
1000,
63,
8924,
26,
489,
291,
14,
3280,
63,
1000,
14,
8831,
342,
272,
340,
291,
14,
1989,
63,
3280,
63,
1000,
63,
3556,
63,
719,
26,
489,
291,
14,
3280,
63,
1000,
14,
1000,
63,
1600,
342,
819,
347,
6766,
8,
277,
304,
272,
291,
14,
266,
285,
63,
2110,
63,
3280,
63,
1000,
342,
819,
347,
14062,
63,
6615,
63,
21327,
8,
277,
304,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
8924,
275,
715,
272,
291,
14,
3280,
63,
1000,
14,
4909,
63,
21327,
8,
6843,
63,
4284,
29,
16,
14,
614,
9,
819,
327,
6496,
626,
2429,
63,
368,
63,
1069,
1630,
440,
25831,
7183,
12,
436,
1630,
440,
862,
370,
523,
327,
295,
13,
2479,
6947,
626,
787,
9158,
14,
523,
347,
511,
63,
2479,
63,
368,
63,
1069,
63,
1251,
874,
63,
2105,
8,
277,
304,
272,
327,
4885,
849,
12,
3523,
14938,
14,
647,
20991,
1956,
1006,
3101,
413,
14,
17,
4145,
465,
4215,
13,
9631,
14,
272,
327,
1010,
9553,
1183,
675,
3101,
413,
14,
16,
370,
7981,
642,
5953,
14,
272,
1177,
275,
22768,
462,
335,
1912,
14,
8438,
12905,
16287,
8,
267,
1015,
29,
709,
12,
2004,
29,
1840,
12,
4499,
628,
3593,
401,
267,
2323,
6034,
1177,
63,
576,
6270,
13475,
17,
3135,
272,
291,
14,
409,
63,
384,
63,
3280,
63,
1000,
8,
1310,
9,
272,
307,
275,
5796,
14,
4436,
8,
267,
1347,
29,
5779,
4936,
774,
14,
4909,
63,
6615,
63,
21327,
12,
1249,
2687,
277,
4641,
272,
307,
14,
928,
342,
339,
2536,
63,
2671,
63,
835,
275,
5796,
14,
2682,
2353,
342,
339,
327,
4155,
282,
22219,
402,
4145,
14,
272,
1056,
63,
835,
275,
1616,
272,
367,
485,
315,
1425,
8,
1069,
63,
835,
304,
489,
2557,
275,
8809,
14,
19114,
360,
5967,
297,
10523,
1407,
12,
2653,
29,
709,
9,
489,
2557,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6900,
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,
421,
199,
646,
22768,
462,
335,
1912,
199,
646,
8809,
199,
646,
1455,
3280,
199,
646,
5796,
199,
646,
2882,
199,
646,
4884,
421,
199,
533,
4420,
7223,
2364,
2461,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
1177,
304,
272,
408,
272,
3033,
26,
489,
1177,
26,
1626,
1256,
402,
19521,
12905,
16287,
626,
365,
2138,
367,
1924,
489,
1056,
14,
272,
408,
272,
291,
423,
1310,
275,
1177,
819,
347,
2429,
8,
277,
12,
1056,
304,
272,
2150,
1056,
272,
372,
291,
423,
1310,
421,
199,
533,
4420,
5779,
13042,
11135,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
1177,
304,
272,
408,
272,
3033,
26,
489,
1177,
26,
1626,
1256,
402,
19521,
12905,
16287,
626,
365,
2138,
367,
1924,
489,
1056,
14,
272,
408,
272,
291,
14,
374,
63,
3059,
63,
632,
275,
756,
272,
291,
423,
1310,
275,
1177,
819,
347,
636,
1250,
721,
277,
12,
1056,
304,
272,
2150,
1056,
327,
9563,
272,
372,
291,
423,
1310,
421,
199,
533,
4420,
5779,
13042,
2461,
8,
1014,
3280,
14,
5779,
13042,
2461,
304,
523,
347,
2429,
63,
368,
63,
1069,
8,
277,
304,
272,
1455,
3280,
14,
5779,
13042,
2461,
14,
2479,
63,
368,
63,
1069,
8,
277,
9,
272,
4760,
4936,
774,
14,
10854,
5290,
63,
6780,
63,
8760,
847,
413,
421,
199,
533,
4420,
12920,
8,
785,
304,
523,
347,
6668,
8,
277,
12,
9563,
63,
2200,
63,
466,
63,
354,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
372,
2400,
9563,
63,
1069,
12,
9563,
63,
1310,
26,
488,
421,
199,
533,
4760,
4936,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
3556,
63,
719,
275,
756,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
8924,
275,
756,
272,
291,
14,
3306,
63,
4208,
63,
8533,
275,
756,
272,
291,
14,
4909,
63,
1310,
63,
991,
63,
1014,
63,
6404,
275,
756,
819,
347,
663,
63,
384,
63,
3280,
63,
1000,
8,
277,
12,
1177,
304,
272,
408,
272,
3033,
26,
489,
1177,
26,
1626,
1256,
402,
19521,
12905,
16287,
626,
365,
2138,
367,
1924,
489,
1056,
14,
272,
408,
272,
4760,
4936,
774,
14,
10854,
5290,
63,
6780,
63,
8760,
275,
378,
272,
291,
14,
1102,
275,
283,
5967,
7,
272,
291,
14,
719,
275,
10523,
1407,
272,
3537,
63,
5586,
275,
4420,
7223,
2364,
2461,
8,
267,
1177,
340,
440,
291,
14,
4909,
63,
1310,
63,
991,
63,
1014,
63,
6404,
587,
488,
9,
272,
4713,
275,
4420,
12920,
342,
272,
1455,
63,
6404,
63,
3535,
275,
4420,
5779,
13042,
11135,
8,
267,
1177,
340,
291,
14,
4909,
63,
1310,
63,
991,
63,
1014,
63,
6404,
587,
488,
9,
272,
291,
14,
3280,
63,
1000,
275,
1455,
3280,
14,
5779,
4936,
3120,
8,
267,
1455,
63,
6404,
63,
3535,
12,
3537,
63,
5586,
12,
4713,
12,
267,
1591,
29,
277,
14,
1102,
12,
1844,
29,
277,
14,
719,
12,
267,
2040,
63,
4208,
63,
8533,
29,
277,
14,
3306,
63,
4208,
63,
8533,
9,
272,
291,
14,
3280,
63,
1000,
14,
11149,
2543,
275,
4420,
5779,
13042,
2461,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
3556,
63,
719,
275,
715,
819,
347,
1565,
285,
63,
2110,
63,
3280,
63,
1000,
8,
277,
304,
272,
340,
291,
14,
1989,
63,
3280,
63,
1000,
63,
8924,
26,
489,
291,
14,
3280,
63,
1000,
14,
8831,
342,
272,
340,
291,
14,
1989,
63,
3280,
63,
1000,
63,
3556,
63,
719,
26,
489,
291,
14,
3280,
63,
1000,
14,
1000,
63,
1600,
342,
819,
347,
6766,
8,
277,
304,
272,
291,
14,
266,
285,
63,
2110,
63,
3280,
63,
1000,
342,
819,
347,
14062,
63,
6615,
63,
21327,
8,
277,
304,
272,
291,
14,
1989,
63,
3280,
63,
1000,
63,
8924,
275,
715,
272,
291,
14,
3280,
63,
1000,
14,
4909,
63,
21327,
8,
6843,
63,
4284,
29,
16,
14,
614,
9,
819,
327,
6496,
626,
2429,
63,
368,
63,
1069,
1630,
440,
25831,
7183,
12,
436,
1630,
440,
862,
370,
523,
327,
295,
13,
2479,
6947,
626,
787,
9158,
14,
523,
347,
511,
63,
2479,
63,
368,
63,
1069,
63,
1251,
874,
63,
2105,
8,
277,
304,
272,
327,
4885,
849,
12,
3523,
14938,
14,
647,
20991,
1956,
1006,
3101,
413,
14,
17,
4145,
465,
4215,
13,
9631,
14,
272,
327,
1010,
9553,
1183,
675,
3101,
413,
14,
16,
370,
7981,
642,
5953,
14,
272,
1177,
275,
22768,
462,
335,
1912,
14,
8438,
12905,
16287,
8,
267,
1015,
29,
709,
12,
2004,
29,
1840,
12,
4499,
628,
3593,
401,
267,
2323,
6034,
1177,
63,
576,
6270,
13475,
17,
3135,
272,
291,
14,
409,
63,
384,
63,
3280,
63,
1000,
8,
1310,
9,
272,
307,
275,
5796,
14,
4436,
8,
267,
1347,
29,
5779,
4936,
774,
14,
4909,
63,
6615,
63,
21327,
12,
1249,
2687,
277,
4641,
272,
307,
14,
928,
342,
339,
2536,
63,
2671,
63,
835,
275,
5796,
14,
2682,
2353,
342,
339,
327,
4155,
282,
22219,
402,
4145,
14,
272,
1056,
63,
835,
275,
1616,
272,
367,
485,
315,
1425,
8,
1069,
63,
835,
304,
489,
2557,
275,
8809,
14,
19114,
360,
5967,
297,
10523,
1407,
12,
2653,
29,
709,
9,
489,
2557,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
oudalab/phyllo
|
phyllo/extractors/regula_ad_monachoDB.py
|
1
|
3765
|
import sqlite3
import urllib
import re
from urllib.request import urlopen
from bs4 import BeautifulSoup
# several names in the <pagehead> but not sure what to put as an author name
def main():
# The collection URL below.
collURL = 'http://www.thelatinlibrary.com/regula.html'
collOpen = urllib.request.urlopen(collURL)
collSOUP = BeautifulSoup(collOpen, 'html5lib')
author = "unknown"
colltitle = collSOUP.title.string.strip()
date = "no date found"
textsURL = [collURL]
with sqlite3.connect('texts.db') as db:
c = db.cursor()
c.execute(
'CREATE TABLE IF NOT EXISTS texts (id INTEGER PRIMARY KEY, title TEXT, book TEXT,'
' language TEXT, author TEXT, date TEXT, chapter TEXT, verse TEXT, passage TEXT,'
' link TEXT, documentType TEXT)')
c.execute("DELETE FROM texts WHERE title = 'REGULA AD MONACHOS I'")
c.execute("DELETE FROM texts WHERE title = 'SS. PATRUM REGULA AD MONACHOS II.'")
c.execute("DELETE FROM texts WHERE title = 'SS. PATRUM REGULA AD MONACHOS III.'")
c.execute("DELETE FROM texts WHERE title = 'REGULA ORIENTALIS\nEX PATRUM ORIENTALIUM REGULIS COLLECTA'")
for url in textsURL:
chapter = "Preface"
verse = 0
title = "REGULA AD MONACHOS I"
openurl = urllib.request.urlopen(url)
textsoup = BeautifulSoup(openurl, 'html5lib')
getp = textsoup.find_all('p')
for p in getp:
# make sure it's not a paragraph without the main text
try:
if p['class'][0].lower() in ['border', 'pagehead', 'shortborder', 'smallborder', 'margin',
'internal_navigation']: # these are not part of the main t
continue
except:
pass
verses = []
text = p.get_text()
text = text.strip()
if p.find('b') is not None:
if text.startswith("SS.") or text.startswith("REGULA"):
# this is the title of a new work
title = text
chapter = -1
continue
else:
if text.startswith("CAPUT"):
chapter = text
print(chapter)
verse = 0
continue
else:
chapter = chapter + ": " + text
continue
if title == "REGULA AD MONACHOS I":
verses.append(text)
elif text.startswith("PRAEFATIO"):
chapter = text
verse = 0
continue
elif re.match('[IVXL]+\.', text):
chapter = text.split(" ")[0].strip()
print(chapter)
verse = 0
text = text.replace(chapter, '')
verses.append(text)
else:
verses.append(text)
for v in verses:
if v.startswith('Christian'):
continue
if v is None or v == '' or v.isspace():
continue
# verse number assignment.
verse += 1
c.execute("INSERT INTO texts VALUES (?,?,?,?,?,?,?, ?, ?, ?, ?)",
(None, colltitle, title, 'Latin', author, date, chapter,
verse, v, url, 'prose'))
if __name__ == '__main__':
main()
|
apache-2.0
|
[
646,
11723,
19,
199,
646,
4011,
199,
646,
295,
199,
504,
4011,
14,
1069,
492,
18279,
199,
504,
9922,
20,
492,
17132,
199,
199,
3,
9978,
1561,
315,
314,
665,
1606,
2993,
30,
1325,
440,
3238,
4052,
370,
5324,
465,
376,
4132,
536,
199,
199,
318,
2446,
837,
272,
327,
710,
3245,
2851,
5084,
14,
272,
23721,
2632,
275,
283,
1014,
921,
1544,
14,
273,
352,
14667,
4342,
14,
957,
15,
1135,
7586,
14,
1360,
7,
272,
23721,
4299,
275,
4011,
14,
1069,
14,
10890,
8,
15772,
2632,
9,
272,
23721,
4118,
2160,
275,
17132,
8,
15772,
4299,
12,
283,
1360,
21,
773,
358,
272,
4132,
275,
298,
5187,
2,
272,
23721,
1213,
275,
23721,
4118,
2160,
14,
1213,
14,
875,
14,
1913,
342,
272,
1434,
275,
298,
889,
1434,
1911,
2,
339,
24857,
2632,
275,
359,
15772,
2632,
61,
339,
543,
11723,
19,
14,
2242,
360,
19517,
14,
697,
358,
465,
1592,
26,
267,
286,
275,
1592,
14,
3937,
342,
267,
286,
14,
2526,
8,
267,
283,
8366,
9934,
8036,
2845,
23875,
24857,
334,
344,
17086,
19770,
9301,
12,
2538,
11951,
12,
6719,
11951,
2584,
267,
283,
2637,
11951,
12,
4132,
11951,
12,
1434,
11951,
12,
17044,
11951,
12,
809,
261,
11951,
12,
986,
474,
11951,
2584,
267,
283,
2142,
11951,
12,
2213,
804,
11951,
5942,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
5616,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
9859,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
2300,
14,
31467,
50,
2639,
14142,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
41,
3530,
531,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
2300,
14,
31467,
50,
2639,
14142,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
8921,
3530,
531,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
5616,
1293,
33,
1549,
25451,
748,
1311,
60,
78,
1438,
31467,
50,
2639,
1549,
25451,
748,
24967,
14142,
1293,
1311,
13513,
3923,
33,
9859,
7318,
367,
1166,
315,
24857,
2632,
26,
288,
17044,
275,
298,
2398,
1409,
2,
288,
809,
261,
275,
378,
288,
2538,
275,
298,
5616,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
2,
288,
1551,
633,
275,
4011,
14,
1069,
14,
10890,
8,
633,
9,
288,
1318,
9317,
275,
17132,
8,
1490,
633,
12,
283,
1360,
21,
773,
358,
953,
664,
80,
275,
1318,
9317,
14,
1623,
63,
452,
360,
80,
358,
953,
367,
299,
315,
664,
80,
26,
2234,
327,
1852,
3238,
652,
1159,
440,
282,
13168,
1928,
314,
2446,
1318,
355,
862,
26,
490,
340,
299,
459,
533,
3488,
16,
1055,
2325,
342,
315,
788,
8665,
297,
283,
1606,
2993,
297,
283,
3612,
8665,
297,
283,
7241,
8665,
297,
283,
9650,
297,
1740,
283,
4672,
63,
24148,
2565,
221,
327,
3520,
787,
440,
1777,
402,
314,
2446,
307,
717,
1980,
355,
871,
26,
490,
986,
2234,
809,
874,
275,
942,
355,
1318,
275,
299,
14,
362,
63,
505,
342,
355,
1318,
275,
1318,
14,
1913,
342,
2234,
340,
299,
14,
1623,
360,
66,
358,
365,
440,
488,
26,
490,
340,
1318,
14,
2460,
480,
2300,
2685,
503,
1318,
14,
2460,
480,
5616,
1293,
33,
2349,
717,
327,
642,
365,
314,
2538,
402,
282,
892,
1736,
717,
2538,
275,
1318,
717,
17044,
275,
446,
17,
717,
1980,
490,
587,
26,
717,
340,
1318,
14,
2460,
480,
8549,
934,
2349,
1169,
17044,
275,
1318,
1169,
870,
8,
11316,
9,
1169,
809,
261,
275,
378,
1169,
1980,
717,
587,
26,
1169,
17044,
275,
17044,
435,
7244,
298,
435,
1318,
1169,
1980,
2234,
340,
2538,
508,
298,
5616,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
582,
490,
809,
874,
14,
740,
8,
505,
9,
2234,
916,
1318,
14,
2460,
480,
48,
2847,
14153,
619,
2090,
2349,
490,
17044,
275,
1318,
490,
809,
261,
275,
378,
490,
1980,
355,
916,
295,
14,
1431,
11894,
6882,
25774,
24621,
3130,
1318,
304,
490,
17044,
275,
1318,
14,
1294,
480,
298,
2788,
16,
1055,
1913,
342,
490,
870,
8,
11316,
9,
490,
809,
261,
275,
378,
490,
1318,
275,
1318,
14,
1814,
8,
11316,
12,
4074,
490,
809,
874,
14,
740,
8,
505,
9,
355,
587,
26,
490,
809,
874,
14,
740,
8,
505,
9,
2234,
367,
373,
315,
809,
874,
26,
490,
340,
373,
14,
2460,
360,
1049,
18824,
5653,
735,
717,
1980,
4951,
340,
373,
365,
488,
503,
373,
508,
2125,
503,
373,
14,
23360,
837,
717,
1980,
490,
327,
809,
261,
1329,
9801,
14,
490,
809,
261,
847,
413,
490,
286,
14,
2526,
480,
10258,
12872,
24857,
13992,
7558,
12,
22556,
22556,
22556,
22556,
22556,
22556,
21259,
21259,
21259,
5805,
4186,
2892,
334,
403,
12,
23721,
1213,
12,
2538,
12,
283,
27317,
297,
4132,
12,
1434,
12,
17044,
12,
3044,
809,
261,
12,
373,
12,
1166,
12,
283,
496,
261,
1333,
421,
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
] |
[
11723,
19,
199,
646,
4011,
199,
646,
295,
199,
504,
4011,
14,
1069,
492,
18279,
199,
504,
9922,
20,
492,
17132,
199,
199,
3,
9978,
1561,
315,
314,
665,
1606,
2993,
30,
1325,
440,
3238,
4052,
370,
5324,
465,
376,
4132,
536,
199,
199,
318,
2446,
837,
272,
327,
710,
3245,
2851,
5084,
14,
272,
23721,
2632,
275,
283,
1014,
921,
1544,
14,
273,
352,
14667,
4342,
14,
957,
15,
1135,
7586,
14,
1360,
7,
272,
23721,
4299,
275,
4011,
14,
1069,
14,
10890,
8,
15772,
2632,
9,
272,
23721,
4118,
2160,
275,
17132,
8,
15772,
4299,
12,
283,
1360,
21,
773,
358,
272,
4132,
275,
298,
5187,
2,
272,
23721,
1213,
275,
23721,
4118,
2160,
14,
1213,
14,
875,
14,
1913,
342,
272,
1434,
275,
298,
889,
1434,
1911,
2,
339,
24857,
2632,
275,
359,
15772,
2632,
61,
339,
543,
11723,
19,
14,
2242,
360,
19517,
14,
697,
358,
465,
1592,
26,
267,
286,
275,
1592,
14,
3937,
342,
267,
286,
14,
2526,
8,
267,
283,
8366,
9934,
8036,
2845,
23875,
24857,
334,
344,
17086,
19770,
9301,
12,
2538,
11951,
12,
6719,
11951,
2584,
267,
283,
2637,
11951,
12,
4132,
11951,
12,
1434,
11951,
12,
17044,
11951,
12,
809,
261,
11951,
12,
986,
474,
11951,
2584,
267,
283,
2142,
11951,
12,
2213,
804,
11951,
5942,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
5616,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
9859,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
2300,
14,
31467,
50,
2639,
14142,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
41,
3530,
531,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
2300,
14,
31467,
50,
2639,
14142,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
8921,
3530,
531,
267,
286,
14,
2526,
480,
7014,
4442,
24857,
6038,
2538,
275,
283,
5616,
1293,
33,
1549,
25451,
748,
1311,
60,
78,
1438,
31467,
50,
2639,
1549,
25451,
748,
24967,
14142,
1293,
1311,
13513,
3923,
33,
9859,
7318,
367,
1166,
315,
24857,
2632,
26,
288,
17044,
275,
298,
2398,
1409,
2,
288,
809,
261,
275,
378,
288,
2538,
275,
298,
5616,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
2,
288,
1551,
633,
275,
4011,
14,
1069,
14,
10890,
8,
633,
9,
288,
1318,
9317,
275,
17132,
8,
1490,
633,
12,
283,
1360,
21,
773,
358,
953,
664,
80,
275,
1318,
9317,
14,
1623,
63,
452,
360,
80,
358,
953,
367,
299,
315,
664,
80,
26,
2234,
327,
1852,
3238,
652,
1159,
440,
282,
13168,
1928,
314,
2446,
1318,
355,
862,
26,
490,
340,
299,
459,
533,
3488,
16,
1055,
2325,
342,
315,
788,
8665,
297,
283,
1606,
2993,
297,
283,
3612,
8665,
297,
283,
7241,
8665,
297,
283,
9650,
297,
1740,
283,
4672,
63,
24148,
2565,
221,
327,
3520,
787,
440,
1777,
402,
314,
2446,
307,
717,
1980,
355,
871,
26,
490,
986,
2234,
809,
874,
275,
942,
355,
1318,
275,
299,
14,
362,
63,
505,
342,
355,
1318,
275,
1318,
14,
1913,
342,
2234,
340,
299,
14,
1623,
360,
66,
358,
365,
440,
488,
26,
490,
340,
1318,
14,
2460,
480,
2300,
2685,
503,
1318,
14,
2460,
480,
5616,
1293,
33,
2349,
717,
327,
642,
365,
314,
2538,
402,
282,
892,
1736,
717,
2538,
275,
1318,
717,
17044,
275,
446,
17,
717,
1980,
490,
587,
26,
717,
340,
1318,
14,
2460,
480,
8549,
934,
2349,
1169,
17044,
275,
1318,
1169,
870,
8,
11316,
9,
1169,
809,
261,
275,
378,
1169,
1980,
717,
587,
26,
1169,
17044,
275,
17044,
435,
7244,
298,
435,
1318,
1169,
1980,
2234,
340,
2538,
508,
298,
5616,
1293,
33,
16271,
603,
615,
33,
1244,
3100,
473,
582,
490,
809,
874,
14,
740,
8,
505,
9,
2234,
916,
1318,
14,
2460,
480,
48,
2847,
14153,
619,
2090,
2349,
490,
17044,
275,
1318,
490,
809,
261,
275,
378,
490,
1980,
355,
916,
295,
14,
1431,
11894,
6882,
25774,
24621,
3130,
1318,
304,
490,
17044,
275,
1318,
14,
1294,
480,
298,
2788,
16,
1055,
1913,
342,
490,
870,
8,
11316,
9,
490,
809,
261,
275,
378,
490,
1318,
275,
1318,
14,
1814,
8,
11316,
12,
4074,
490,
809,
874,
14,
740,
8,
505,
9,
355,
587,
26,
490,
809,
874,
14,
740,
8,
505,
9,
2234,
367,
373,
315,
809,
874,
26,
490,
340,
373,
14,
2460,
360,
1049,
18824,
5653,
735,
717,
1980,
4951,
340,
373,
365,
488,
503,
373,
508,
2125,
503,
373,
14,
23360,
837,
717,
1980,
490,
327,
809,
261,
1329,
9801,
14,
490,
809,
261,
847,
413,
490,
286,
14,
2526,
480,
10258,
12872,
24857,
13992,
7558,
12,
22556,
22556,
22556,
22556,
22556,
22556,
21259,
21259,
21259,
5805,
4186,
2892,
334,
403,
12,
23721,
1213,
12,
2538,
12,
283,
27317,
297,
4132,
12,
1434,
12,
17044,
12,
3044,
809,
261,
12,
373,
12,
1166,
12,
283,
496,
261,
1333,
421,
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,
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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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.
"""VMRC console drivers."""
import base64
from oslo.config import cfg
from nova import exception
from nova.openstack.common import jsonutils
from nova.virt.vmwareapi import vim_util
vmrc_opts = [
cfg.IntOpt('console_vmrc_port',
default=443,
help="Port for VMware VMRC connections"),
cfg.IntOpt('console_vmrc_error_retries',
default=10,
help="Number of retries for retrieving VMRC information"),
]
CONF = cfg.CONF
CONF.register_opts(vmrc_opts)
class VMRCConsole(object):
"""VMRC console driver with ESX credentials."""
def __init__(self):
super(VMRCConsole, self).__init__()
@property
def console_type(self):
return 'vmrc+credentials'
def get_port(self, context):
"""Get available port for consoles."""
return CONF.console_vmrc_port
def setup_console(self, context, console):
"""Sets up console."""
pass
def teardown_console(self, context, console):
"""Tears down console."""
pass
def init_host(self):
"""Perform console initialization."""
pass
def fix_pool_password(self, password):
"""Encode password."""
# TODO(sateesh): Encrypt pool password
return password
def generate_password(self, vim_session, pool, instance_name):
"""Returns VMRC Connection credentials.
Return string is of the form '<VM PATH>:<ESX Username>@<ESX Password>'.
"""
username, password = pool['username'], pool['password']
vms = vim_session._call_method(vim_util, 'get_objects',
'VirtualMachine', ['name', 'config.files.vmPathName'])
vm_ds_path_name = None
vm_ref = None
for vm in vms:
vm_name = None
ds_path_name = None
for prop in vm.propSet:
if prop.name == 'name':
vm_name = prop.val
elif prop.name == 'config.files.vmPathName':
ds_path_name = prop.val
if vm_name == instance_name:
vm_ref = vm.obj
vm_ds_path_name = ds_path_name
break
if vm_ref is None:
raise exception.InstanceNotFound(instance_id=instance_name)
json_data = jsonutils.dumps({'vm_id': vm_ds_path_name,
'username': username,
'password': password})
return base64.b64encode(json_data)
def is_otp(self):
"""Is one time password or not."""
return False
class VMRCSessionConsole(VMRCConsole):
"""VMRC console driver with VMRC One Time Sessions."""
def __init__(self):
super(VMRCSessionConsole, self).__init__()
@property
def console_type(self):
return 'vmrc+session'
def generate_password(self, vim_session, pool, instance_name):
"""Returns a VMRC Session.
Return string is of the form '<VM MOID>:<VMRC Ticket>'.
"""
vms = vim_session._call_method(vim_util, 'get_objects',
'VirtualMachine', ['name'])
vm_ref = None
for vm in vms:
if vm.propSet[0].val == instance_name:
vm_ref = vm.obj
if vm_ref is None:
raise exception.InstanceNotFound(instance_id=instance_name)
virtual_machine_ticket = vim_session._call_method(
vim_session._get_vim(),
'AcquireCloneTicket',
vim_session._get_vim().get_service_content().sessionManager)
json_data = jsonutils.dumps({'vm_id': str(vm_ref.value),
'username': virtual_machine_ticket,
'password': virtual_machine_ticket})
return base64.b64encode(json_data)
def is_otp(self):
"""Is one time password or not."""
return True
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7760,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
1898,
7760,
14260,
2752,
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,
624,
6849,
8205,
8559,
19016,
1041,
199,
199,
646,
1300,
772,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
8512,
14,
2330,
492,
18705,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6695,
63,
1974,
421,
199,
2611,
1195,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
6614,
63,
2611,
1195,
63,
719,
297,
2049,
849,
29,
16284,
12,
2049,
1720,
628,
4313,
367,
27391,
7525,
8205,
6947,
1288,
272,
4810,
14,
3241,
9985,
360,
6614,
63,
2611,
1195,
63,
705,
63,
10937,
297,
2049,
849,
29,
709,
12,
2049,
1720,
628,
3259,
402,
10086,
367,
23812,
7525,
8205,
2556,
1288,
272,
1622,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
2611,
1195,
63,
3291,
9,
421,
199,
533,
7525,
8205,
9270,
8,
785,
304,
272,
408,
6849,
8205,
8559,
5253,
543,
10427,
56,
6235,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6849,
8205,
9270,
12,
291,
2843,
826,
4533,
339,
768,
1829,
272,
347,
8559,
63,
466,
8,
277,
304,
267,
372,
283,
2611,
1195,
11,
6942,
7,
339,
347,
664,
63,
719,
8,
277,
12,
1067,
304,
267,
408,
1002,
2808,
1844,
367,
406,
1152,
2978,
1041,
267,
372,
6392,
14,
6614,
63,
2611,
1195,
63,
719,
339,
347,
3272,
63,
6614,
8,
277,
12,
1067,
12,
8559,
304,
267,
408,
9899,
1536,
8559,
1041,
267,
986,
339,
347,
17558,
63,
6614,
8,
277,
12,
1067,
12,
8559,
304,
267,
408,
52,
2210,
83,
3224,
8559,
1041,
267,
986,
339,
347,
4205,
63,
1102,
8,
277,
304,
267,
408,
20906,
8559,
11097,
1041,
267,
986,
339,
347,
5325,
63,
2293,
63,
2060,
8,
277,
12,
2505,
304,
267,
408,
9686,
2505,
1041,
267,
327,
3254,
8,
83,
323,
10613,
304,
3447,
4997,
4203,
2505,
267,
372,
2505,
339,
347,
3550,
63,
2060,
8,
277,
12,
6695,
63,
1730,
12,
4203,
12,
1256,
63,
354,
304,
267,
408,
3407,
7525,
8205,
8113,
6235,
14,
398,
1432,
1059,
365,
402,
314,
1824,
2650,
6849,
15097,
30,
16875,
654,
56,
29739,
30,
32,
28,
654,
56,
13635,
22936,
398,
408,
267,
3434,
12,
2505,
275,
4203,
459,
2473,
995,
4203,
459,
2060,
418,
267,
22505,
275,
6695,
63,
1730,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
283,
362,
63,
1462,
297,
490,
283,
29863,
297,
788,
354,
297,
283,
888,
14,
1725,
14,
2611,
27775,
1105,
267,
4169,
63,
795,
63,
515,
63,
354,
275,
488,
267,
4169,
63,
1121,
275,
488,
267,
367,
4169,
315,
22505,
26,
288,
4169,
63,
354,
275,
488,
288,
6364,
63,
515,
63,
354,
275,
488,
288,
367,
5931,
315,
4169,
14,
4469,
1084,
26,
355,
340,
5931,
14,
354,
508,
283,
354,
356,
490,
4169,
63,
354,
275,
5931,
14,
637,
355,
916,
5931,
14,
354,
508,
283,
888,
14,
1725,
14,
2611,
27775,
356,
490,
6364,
63,
515,
63,
354,
275,
5931,
14,
637,
288,
340,
4169,
63,
354,
508,
1256,
63,
354,
26,
355,
4169,
63,
1121,
275,
4169,
14,
1113,
355,
4169,
63,
795,
63,
515,
63,
354,
275,
6364,
63,
515,
63,
354,
355,
2059,
267,
340,
4169,
63,
1121,
365,
488,
26,
288,
746,
1919,
14,
3244,
4667,
8,
842,
63,
344,
29,
842,
63,
354,
9,
267,
2022,
63,
576,
275,
18705,
14,
4180,
3252,
2611,
63,
344,
356,
4169,
63,
795,
63,
515,
63,
354,
12,
3660,
283,
2473,
356,
3434,
12,
3660,
283,
2060,
356,
2505,
1552,
267,
372,
1300,
772,
14,
66,
772,
2143,
8,
1001,
63,
576,
9,
339,
347,
365,
63,
357,
80,
8,
277,
304,
267,
408,
1831,
1373,
900,
2505,
503,
440,
1041,
267,
372,
756,
421,
199,
533,
7525,
50,
3298,
3552,
9270,
8,
6849,
8205,
9270,
304,
272,
408,
6849,
8205,
8559,
5253,
543,
7525,
8205,
7309,
4703,
428,
30414,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6849,
50,
3298,
3552,
9270,
12,
291,
2843,
826,
4533,
339,
768,
1829,
272,
347,
8559,
63,
466,
8,
277,
304,
267,
372,
283,
2611,
1195,
11,
1730,
7,
339,
347,
3550,
63,
2060,
8,
277,
12,
6695,
63,
1730,
12,
4203,
12,
1256,
63,
354,
304,
267,
408,
3407,
282,
7525,
8205,
8596,
14,
398,
1432,
1059,
365,
402,
314,
1824,
2650,
6849,
10362,
998,
30,
16875,
6849,
8205,
21932,
22936,
398,
408,
267,
22505,
275,
6695,
63,
1730,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
283,
362,
63,
1462,
297,
490,
283,
29863,
297,
788,
354,
1105,
267,
4169,
63,
1121,
275,
488,
267,
367,
4169,
315,
22505,
26,
288,
340,
4169,
14,
4469,
1084,
59,
16,
1055,
637,
508,
1256,
63,
354,
26,
355,
4169,
63,
1121,
275,
4169,
14,
1113,
267,
340,
4169,
63,
1121,
365,
488,
26,
288,
746,
1919,
14,
3244,
4667,
8,
842,
63,
344,
29,
842,
63,
354,
9,
267,
5791,
63,
6744,
63,
9201,
275,
6695,
63,
1730,
423,
1250,
63,
765,
8,
355,
6695,
63,
1730,
423,
362,
63,
16361,
1062,
355,
283,
1945,
2272,
21222,
25813,
297,
355,
6695,
63,
1730,
423,
362,
63,
16361,
1252,
362,
63,
1364,
63,
1317,
1252,
1730,
2988
] |
[
1898,
334,
67,
9,
7760,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
1898,
7760,
14260,
2752,
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,
624,
6849,
8205,
8559,
19016,
1041,
199,
199,
646,
1300,
772,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
8512,
14,
2330,
492,
18705,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6695,
63,
1974,
421,
199,
2611,
1195,
63,
3291,
275,
359,
272,
4810,
14,
3241,
9985,
360,
6614,
63,
2611,
1195,
63,
719,
297,
2049,
849,
29,
16284,
12,
2049,
1720,
628,
4313,
367,
27391,
7525,
8205,
6947,
1288,
272,
4810,
14,
3241,
9985,
360,
6614,
63,
2611,
1195,
63,
705,
63,
10937,
297,
2049,
849,
29,
709,
12,
2049,
1720,
628,
3259,
402,
10086,
367,
23812,
7525,
8205,
2556,
1288,
272,
1622,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
2611,
1195,
63,
3291,
9,
421,
199,
533,
7525,
8205,
9270,
8,
785,
304,
272,
408,
6849,
8205,
8559,
5253,
543,
10427,
56,
6235,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6849,
8205,
9270,
12,
291,
2843,
826,
4533,
339,
768,
1829,
272,
347,
8559,
63,
466,
8,
277,
304,
267,
372,
283,
2611,
1195,
11,
6942,
7,
339,
347,
664,
63,
719,
8,
277,
12,
1067,
304,
267,
408,
1002,
2808,
1844,
367,
406,
1152,
2978,
1041,
267,
372,
6392,
14,
6614,
63,
2611,
1195,
63,
719,
339,
347,
3272,
63,
6614,
8,
277,
12,
1067,
12,
8559,
304,
267,
408,
9899,
1536,
8559,
1041,
267,
986,
339,
347,
17558,
63,
6614,
8,
277,
12,
1067,
12,
8559,
304,
267,
408,
52,
2210,
83,
3224,
8559,
1041,
267,
986,
339,
347,
4205,
63,
1102,
8,
277,
304,
267,
408,
20906,
8559,
11097,
1041,
267,
986,
339,
347,
5325,
63,
2293,
63,
2060,
8,
277,
12,
2505,
304,
267,
408,
9686,
2505,
1041,
267,
327,
3254,
8,
83,
323,
10613,
304,
3447,
4997,
4203,
2505,
267,
372,
2505,
339,
347,
3550,
63,
2060,
8,
277,
12,
6695,
63,
1730,
12,
4203,
12,
1256,
63,
354,
304,
267,
408,
3407,
7525,
8205,
8113,
6235,
14,
398,
1432,
1059,
365,
402,
314,
1824,
2650,
6849,
15097,
30,
16875,
654,
56,
29739,
30,
32,
28,
654,
56,
13635,
22936,
398,
408,
267,
3434,
12,
2505,
275,
4203,
459,
2473,
995,
4203,
459,
2060,
418,
267,
22505,
275,
6695,
63,
1730,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
283,
362,
63,
1462,
297,
490,
283,
29863,
297,
788,
354,
297,
283,
888,
14,
1725,
14,
2611,
27775,
1105,
267,
4169,
63,
795,
63,
515,
63,
354,
275,
488,
267,
4169,
63,
1121,
275,
488,
267,
367,
4169,
315,
22505,
26,
288,
4169,
63,
354,
275,
488,
288,
6364,
63,
515,
63,
354,
275,
488,
288,
367,
5931,
315,
4169,
14,
4469,
1084,
26,
355,
340,
5931,
14,
354,
508,
283,
354,
356,
490,
4169,
63,
354,
275,
5931,
14,
637,
355,
916,
5931,
14,
354,
508,
283,
888,
14,
1725,
14,
2611,
27775,
356,
490,
6364,
63,
515,
63,
354,
275,
5931,
14,
637,
288,
340,
4169,
63,
354,
508,
1256,
63,
354,
26,
355,
4169,
63,
1121,
275,
4169,
14,
1113,
355,
4169,
63,
795,
63,
515,
63,
354,
275,
6364,
63,
515,
63,
354,
355,
2059,
267,
340,
4169,
63,
1121,
365,
488,
26,
288,
746,
1919,
14,
3244,
4667,
8,
842,
63,
344,
29,
842,
63,
354,
9,
267,
2022,
63,
576,
275,
18705,
14,
4180,
3252,
2611,
63,
344,
356,
4169,
63,
795,
63,
515,
63,
354,
12,
3660,
283,
2473,
356,
3434,
12,
3660,
283,
2060,
356,
2505,
1552,
267,
372,
1300,
772,
14,
66,
772,
2143,
8,
1001,
63,
576,
9,
339,
347,
365,
63,
357,
80,
8,
277,
304,
267,
408,
1831,
1373,
900,
2505,
503,
440,
1041,
267,
372,
756,
421,
199,
533,
7525,
50,
3298,
3552,
9270,
8,
6849,
8205,
9270,
304,
272,
408,
6849,
8205,
8559,
5253,
543,
7525,
8205,
7309,
4703,
428,
30414,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
6849,
50,
3298,
3552,
9270,
12,
291,
2843,
826,
4533,
339,
768,
1829,
272,
347,
8559,
63,
466,
8,
277,
304,
267,
372,
283,
2611,
1195,
11,
1730,
7,
339,
347,
3550,
63,
2060,
8,
277,
12,
6695,
63,
1730,
12,
4203,
12,
1256,
63,
354,
304,
267,
408,
3407,
282,
7525,
8205,
8596,
14,
398,
1432,
1059,
365,
402,
314,
1824,
2650,
6849,
10362,
998,
30,
16875,
6849,
8205,
21932,
22936,
398,
408,
267,
22505,
275,
6695,
63,
1730,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
283,
362,
63,
1462,
297,
490,
283,
29863,
297,
788,
354,
1105,
267,
4169,
63,
1121,
275,
488,
267,
367,
4169,
315,
22505,
26,
288,
340,
4169,
14,
4469,
1084,
59,
16,
1055,
637,
508,
1256,
63,
354,
26,
355,
4169,
63,
1121,
275,
4169,
14,
1113,
267,
340,
4169,
63,
1121,
365,
488,
26,
288,
746,
1919,
14,
3244,
4667,
8,
842,
63,
344,
29,
842,
63,
354,
9,
267,
5791,
63,
6744,
63,
9201,
275,
6695,
63,
1730,
423,
1250,
63,
765,
8,
355,
6695,
63,
1730,
423,
362,
63,
16361,
1062,
355,
283,
1945,
2272,
21222,
25813,
297,
355,
6695,
63,
1730,
423,
362,
63,
16361,
1252,
362,
63,
1364,
63,
1317,
1252,
1730,
2988,
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,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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
] |
darkleons/odoo
|
addons/l10n_be_hr_payroll/l10n_be_hr_payroll.py
|
379
|
3110
|
#-*- coding:utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>). All Rights Reserved
#
# 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
import openerp.addons.decimal_precision as dp
class hr_contract_be(osv.osv):
_inherit = 'hr.contract'
_columns = {
'travel_reimbursement_amount': fields.float('Reimbursement of travel expenses', digits_compute=dp.get_precision('Payroll')),
'car_company_amount': fields.float('Company car employer', digits_compute=dp.get_precision('Payroll')),
'car_employee_deduction': fields.float('Company Car Deduction for Worker', digits_compute=dp.get_precision('Payroll')),
'misc_onss_deduction': fields.float('Miscellaneous exempt ONSS ', digits_compute=dp.get_precision('Payroll')),
'meal_voucher_amount': fields.float('Check Value Meal ', digits_compute=dp.get_precision('Payroll')),
'meal_voucher_employee_deduction': fields.float('Check Value Meal - by worker ', digits_compute=dp.get_precision('Payroll')),
'insurance_employee_deduction': fields.float('Insurance Group - by worker ', digits_compute=dp.get_precision('Payroll')),
'misc_advantage_amount': fields.float('Benefits of various nature ', digits_compute=dp.get_precision('Payroll')),
'additional_net_amount': fields.float('Net supplements', digits_compute=dp.get_precision('Payroll')),
'retained_net_amount': fields.float('Net retained ', digits_compute=dp.get_precision('Payroll')),
}
class hr_employee_be(osv.osv):
_inherit = 'hr.employee'
_columns = {
'spouse_fiscal_status': fields.selection([('without income','Without Income'),('with income','With Income')], 'Tax status for spouse'),
'disabled_spouse_bool': fields.boolean('Disabled Spouse', help="if recipient spouse is declared disabled by law"),
'disabled_children_bool': fields.boolean('Disabled Children', help="if recipient children is/are declared disabled by law"),
'resident_bool': fields.boolean('Nonresident', help="if recipient lives in a foreign country"),
'disabled_children_number': fields.integer('Number of disabled children'),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7760,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
2900,
5924,
5702,
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,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
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,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
199,
533,
16140,
63,
14624,
63,
1235,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
6271,
14,
14624,
7,
339,
485,
3406,
275,
469,
267,
283,
1239,
1090,
63,
264,
73,
887,
1394,
434,
63,
4606,
356,
1504,
14,
1609,
360,
497,
73,
887,
1394,
434,
402,
1468,
1090,
26963,
83,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
7007,
63,
4627,
63,
4606,
356,
1504,
14,
1609,
360,
16063,
9590,
9052,
3374,
281,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
7007,
63,
10103,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
16063,
14243,
577,
24095,
367,
23886,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
9923,
63,
265,
385,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
30248,
444,
19046,
5258,
2300,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
278,
279,
63,
16637,
63,
4606,
356,
1504,
14,
1609,
360,
1799,
1594,
3194,
279,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
278,
279,
63,
16637,
63,
10103,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
1799,
1594,
3194,
279,
446,
701,
7239,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
3617,
300,
554,
63,
10103,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
13962,
300,
554,
5611,
446,
701,
7239,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
9923,
63,
21650,
25331,
63,
4606,
356,
1504,
14,
1609,
360,
34,
6349,
14948,
402,
7750,
302,
1463,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
8460,
63,
846,
63,
4606,
356,
1504,
14,
1609,
360,
2480,
4973,
20446,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
264,
877,
379,
63,
846,
63,
4606,
356,
1504,
14,
1609,
360,
2480,
30403,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
272,
789,
421,
199,
533,
16140,
63,
10103,
63,
1235,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
6271,
14,
10103,
7,
339,
485,
3406,
275,
469,
267,
283,
22522,
1180,
63,
18646,
63,
1205,
356,
1504,
14,
5592,
8318,
7395,
315,
4352,
1673,
12450,
1010,
4352,
8157,
1045,
315,
4352,
1673,
3007,
1010,
4352,
2665,
283,
26019,
2004,
367,
25664,
1180,
659,
267,
283,
7011,
63,
22522,
1180,
63,
2245,
356,
1504,
14,
4871,
360,
15049,
428,
555,
1180,
297,
1720,
628,
692,
10318,
25664,
1180,
365,
14290,
6980,
701,
4179,
1288,
267,
283,
7011,
63,
3223,
63,
2245,
356,
1504,
14,
4871,
360,
15049,
12988,
828,
297,
1720,
628,
692,
10318,
4978,
365,
15,
1530,
14290,
6980,
701,
4179,
1288,
267,
283,
20807,
1326,
63,
2245,
356,
1504,
14,
4871,
360,
6932,
20807,
1326,
297,
1720,
628,
692,
10318,
27576,
315,
282,
11608,
9023,
1288,
267,
283,
7011,
63,
3223,
63,
1955,
356,
1504,
14,
4115,
360,
3259,
402,
6980,
4978,
659,
272,
789,
421,
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
] |
[
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7760,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
2900,
5924,
5702,
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,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
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,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
199,
533,
16140,
63,
14624,
63,
1235,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
6271,
14,
14624,
7,
339,
485,
3406,
275,
469,
267,
283,
1239,
1090,
63,
264,
73,
887,
1394,
434,
63,
4606,
356,
1504,
14,
1609,
360,
497,
73,
887,
1394,
434,
402,
1468,
1090,
26963,
83,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
7007,
63,
4627,
63,
4606,
356,
1504,
14,
1609,
360,
16063,
9590,
9052,
3374,
281,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
7007,
63,
10103,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
16063,
14243,
577,
24095,
367,
23886,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
9923,
63,
265,
385,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
30248,
444,
19046,
5258,
2300,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
278,
279,
63,
16637,
63,
4606,
356,
1504,
14,
1609,
360,
1799,
1594,
3194,
279,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
278,
279,
63,
16637,
63,
10103,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
1799,
1594,
3194,
279,
446,
701,
7239,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
3617,
300,
554,
63,
10103,
63,
770,
85,
414,
356,
1504,
14,
1609,
360,
13962,
300,
554,
5611,
446,
701,
7239,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
9923,
63,
21650,
25331,
63,
4606,
356,
1504,
14,
1609,
360,
34,
6349,
14948,
402,
7750,
302,
1463,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
8460,
63,
846,
63,
4606,
356,
1504,
14,
1609,
360,
2480,
4973,
20446,
297,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
267,
283,
264,
877,
379,
63,
846,
63,
4606,
356,
1504,
14,
1609,
360,
2480,
30403,
1656,
7576,
63,
3357,
29,
5780,
14,
362,
63,
6833,
360,
10517,
2827,
3855,
272,
789,
421,
199,
533,
16140,
63,
10103,
63,
1235,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
6271,
14,
10103,
7,
339,
485,
3406,
275,
469,
267,
283,
22522,
1180,
63,
18646,
63,
1205,
356,
1504,
14,
5592,
8318,
7395,
315,
4352,
1673,
12450,
1010,
4352,
8157,
1045,
315,
4352,
1673,
3007,
1010,
4352,
2665,
283,
26019,
2004,
367,
25664,
1180,
659,
267,
283,
7011,
63,
22522,
1180,
63,
2245,
356,
1504,
14,
4871,
360,
15049,
428,
555,
1180,
297,
1720,
628,
692,
10318,
25664,
1180,
365,
14290,
6980,
701,
4179,
1288,
267,
283,
7011,
63,
3223,
63,
2245,
356,
1504,
14,
4871,
360,
15049,
12988,
828,
297,
1720,
628,
692,
10318,
4978,
365,
15,
1530,
14290,
6980,
701,
4179,
1288,
267,
283,
20807,
1326,
63,
2245,
356,
1504,
14,
4871,
360,
6932,
20807,
1326,
297,
1720,
628,
692,
10318,
27576,
315,
282,
11608,
9023,
1288,
267,
283,
7011,
63,
3223,
63,
1955,
356,
1504,
14,
4115,
360,
3259,
402,
6980,
4978,
659,
272,
789,
421,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
endlessm/chromium-browser
|
third_party/catapult/third_party/gsutil/gslib/vendored/boto/boto/dynamodb/layer2.py
|
135
|
33814
|
# Copyright (c) 2011 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2011 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
from boto.dynamodb.layer1 import Layer1
from boto.dynamodb.table import Table
from boto.dynamodb.schema import Schema
from boto.dynamodb.item import Item
from boto.dynamodb.batch import BatchList, BatchWriteList
from boto.dynamodb.types import get_dynamodb_type, Dynamizer, \
LossyFloatDynamizer, NonBooleanDynamizer
class TableGenerator(object):
"""
This is an object that wraps up the table_generator function.
The only real reason to have this is that we want to be able
to accumulate and return the ConsumedCapacityUnits element that
is part of each response.
:ivar last_evaluated_key: A sequence representing the key(s)
of the item last evaluated, or None if no additional
results are available.
:ivar remaining: The remaining quantity of results requested.
:ivar table: The table to which the call was made.
"""
def __init__(self, table, callable, remaining, item_class, kwargs):
self.table = table
self.callable = callable
self.remaining = -1 if remaining is None else remaining
self.item_class = item_class
self.kwargs = kwargs
self._consumed_units = 0.0
self.last_evaluated_key = None
self._count = 0
self._scanned_count = 0
self._response = None
@property
def count(self):
"""
The total number of items retrieved thus far. This value changes with
iteration and even when issuing a call with count=True, it is necessary
to complete the iteration to assert an accurate count value.
"""
self.response
return self._count
@property
def scanned_count(self):
"""
As above, but representing the total number of items scanned by
DynamoDB, without regard to any filters.
"""
self.response
return self._scanned_count
@property
def consumed_units(self):
"""
Returns a float representing the ConsumedCapacityUnits accumulated.
"""
self.response
return self._consumed_units
@property
def response(self):
"""
The current response to the call from DynamoDB.
"""
return self.next_response() if self._response is None else self._response
def next_response(self):
"""
Issue a call and return the result. You can invoke this method
while iterating over the TableGenerator in order to skip to the
next "page" of results.
"""
# preserve any existing limit in case the user alters self.remaining
limit = self.kwargs.get('limit')
if (self.remaining > 0 and (limit is None or limit > self.remaining)):
self.kwargs['limit'] = self.remaining
self._response = self.callable(**self.kwargs)
self.kwargs['limit'] = limit
self._consumed_units += self._response.get('ConsumedCapacityUnits', 0.0)
self._count += self._response.get('Count', 0)
self._scanned_count += self._response.get('ScannedCount', 0)
# at the expense of a possibly gratuitous dynamize, ensure that
# early generator termination won't result in bad LEK values
if 'LastEvaluatedKey' in self._response:
lek = self._response['LastEvaluatedKey']
esk = self.table.layer2.dynamize_last_evaluated_key(lek)
self.kwargs['exclusive_start_key'] = esk
lektuple = (lek['HashKeyElement'],)
if 'RangeKeyElement' in lek:
lektuple += (lek['RangeKeyElement'],)
self.last_evaluated_key = lektuple
else:
self.last_evaluated_key = None
return self._response
def __iter__(self):
while self.remaining != 0:
response = self.response
for item in response.get('Items', []):
self.remaining -= 1
yield self.item_class(self.table, attrs=item)
if self.remaining == 0:
break
if response is not self._response:
break
else:
if self.last_evaluated_key is not None:
self.next_response()
continue
break
if response is not self._response:
continue
break
class Layer2(object):
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
debug=0, security_token=None, region=None,
validate_certs=True, dynamizer=LossyFloatDynamizer,
profile_name=None):
self.layer1 = Layer1(aws_access_key_id, aws_secret_access_key,
is_secure, port, proxy, proxy_port,
debug, security_token, region,
validate_certs=validate_certs,
profile_name=profile_name)
self.dynamizer = dynamizer()
def use_decimals(self, use_boolean=False):
"""
Use the ``decimal.Decimal`` type for encoding/decoding numeric types.
By default, ints/floats are used to represent numeric types
('N', 'NS') received from DynamoDB. Using the ``Decimal``
type is recommended to prevent loss of precision.
"""
# Eventually this should be made the default dynamizer.
self.dynamizer = Dynamizer() if use_boolean else NonBooleanDynamizer()
def dynamize_attribute_updates(self, pending_updates):
"""
Convert a set of pending item updates into the structure
required by Layer1.
"""
d = {}
for attr_name in pending_updates:
action, value = pending_updates[attr_name]
if value is None:
# DELETE without an attribute value
d[attr_name] = {"Action": action}
else:
d[attr_name] = {"Action": action,
"Value": self.dynamizer.encode(value)}
return d
def dynamize_item(self, item):
d = {}
for attr_name in item:
d[attr_name] = self.dynamizer.encode(item[attr_name])
return d
def dynamize_range_key_condition(self, range_key_condition):
"""
Convert a layer2 range_key_condition parameter into the
structure required by Layer1.
"""
return range_key_condition.to_dict()
def dynamize_scan_filter(self, scan_filter):
"""
Convert a layer2 scan_filter parameter into the
structure required by Layer1.
"""
d = None
if scan_filter:
d = {}
for attr_name in scan_filter:
condition = scan_filter[attr_name]
d[attr_name] = condition.to_dict()
return d
def dynamize_expected_value(self, expected_value):
"""
Convert an expected_value parameter into the data structure
required for Layer1.
"""
d = None
if expected_value:
d = {}
for attr_name in expected_value:
attr_value = expected_value[attr_name]
if attr_value is True:
attr_value = {'Exists': True}
elif attr_value is False:
attr_value = {'Exists': False}
else:
val = self.dynamizer.encode(expected_value[attr_name])
attr_value = {'Value': val}
d[attr_name] = attr_value
return d
def dynamize_last_evaluated_key(self, last_evaluated_key):
"""
Convert a last_evaluated_key parameter into the data structure
required for Layer1.
"""
d = None
if last_evaluated_key:
hash_key = last_evaluated_key['HashKeyElement']
d = {'HashKeyElement': self.dynamizer.encode(hash_key)}
if 'RangeKeyElement' in last_evaluated_key:
range_key = last_evaluated_key['RangeKeyElement']
d['RangeKeyElement'] = self.dynamizer.encode(range_key)
return d
def build_key_from_values(self, schema, hash_key, range_key=None):
"""
Build a Key structure to be used for accessing items
in Amazon DynamoDB. This method takes the supplied hash_key
and optional range_key and validates them against the
schema. If there is a mismatch, a TypeError is raised.
Otherwise, a Python dict version of a Amazon DynamoDB Key
data structure is returned.
:type hash_key: int|float|str|unicode|Binary
:param hash_key: The hash key of the item you are looking for.
The type of the hash key should match the type defined in
the schema.
:type range_key: int|float|str|unicode|Binary
:param range_key: The range key of the item your are looking for.
This should be supplied only if the schema requires a
range key. The type of the range key should match the
type defined in the schema.
"""
dynamodb_key = {}
dynamodb_value = self.dynamizer.encode(hash_key)
if list(dynamodb_value.keys())[0] != schema.hash_key_type:
msg = 'Hashkey must be of type: %s' % schema.hash_key_type
raise TypeError(msg)
dynamodb_key['HashKeyElement'] = dynamodb_value
if range_key is not None:
dynamodb_value = self.dynamizer.encode(range_key)
if list(dynamodb_value.keys())[0] != schema.range_key_type:
msg = 'RangeKey must be of type: %s' % schema.range_key_type
raise TypeError(msg)
dynamodb_key['RangeKeyElement'] = dynamodb_value
return dynamodb_key
def new_batch_list(self):
"""
Return a new, empty :class:`boto.dynamodb.batch.BatchList`
object.
"""
return BatchList(self)
def new_batch_write_list(self):
"""
Return a new, empty :class:`boto.dynamodb.batch.BatchWriteList`
object.
"""
return BatchWriteList(self)
def list_tables(self, limit=None):
"""
Return a list of the names of all tables associated with the
current account and region.
:type limit: int
:param limit: The maximum number of tables to return.
"""
tables = []
start_table = None
while not limit or len(tables) < limit:
this_round_limit = None
if limit:
this_round_limit = limit - len(tables)
this_round_limit = min(this_round_limit, 100)
result = self.layer1.list_tables(limit=this_round_limit, start_table=start_table)
tables.extend(result.get('TableNames', []))
start_table = result.get('LastEvaluatedTableName', None)
if not start_table:
break
return tables
def describe_table(self, name):
"""
Retrieve information about an existing table.
:type name: str
:param name: The name of the desired table.
"""
return self.layer1.describe_table(name)
def table_from_schema(self, name, schema):
"""
Create a Table object from a schema.
This method will create a Table object without
making any API calls. If you know the name and schema
of the table, you can use this method instead of
``get_table``.
Example usage::
table = layer2.table_from_schema(
'tablename',
Schema.create(hash_key=('foo', 'N')))
:type name: str
:param name: The name of the table.
:type schema: :class:`boto.dynamodb.schema.Schema`
:param schema: The schema associated with the table.
:rtype: :class:`boto.dynamodb.table.Table`
:return: A Table object representing the table.
"""
return Table.create_from_schema(self, name, schema)
def get_table(self, name):
"""
Retrieve the Table object for an existing table.
:type name: str
:param name: The name of the desired table.
:rtype: :class:`boto.dynamodb.table.Table`
:return: A Table object representing the table.
"""
response = self.layer1.describe_table(name)
return Table(self, response)
lookup = get_table
def create_table(self, name, schema, read_units, write_units):
"""
Create a new Amazon DynamoDB table.
:type name: str
:param name: The name of the desired table.
:type schema: :class:`boto.dynamodb.schema.Schema`
:param schema: The Schema object that defines the schema used
by this table.
:type read_units: int
:param read_units: The value for ReadCapacityUnits.
:type write_units: int
:param write_units: The value for WriteCapacityUnits.
:rtype: :class:`boto.dynamodb.table.Table`
:return: A Table object representing the new Amazon DynamoDB table.
"""
response = self.layer1.create_table(name, schema.dict,
{'ReadCapacityUnits': read_units,
'WriteCapacityUnits': write_units})
return Table(self, response)
def update_throughput(self, table, read_units, write_units):
"""
Update the ProvisionedThroughput for the Amazon DynamoDB Table.
:type table: :class:`boto.dynamodb.table.Table`
:param table: The Table object whose throughput is being updated.
:type read_units: int
:param read_units: The new value for ReadCapacityUnits.
:type write_units: int
:param write_units: The new value for WriteCapacityUnits.
"""
response = self.layer1.update_table(table.name,
{'ReadCapacityUnits': read_units,
'WriteCapacityUnits': write_units})
table.update_from_response(response)
def delete_table(self, table):
"""
Delete this table and all items in it. After calling this
the Table objects status attribute will be set to 'DELETING'.
:type table: :class:`boto.dynamodb.table.Table`
:param table: The Table object that is being deleted.
"""
response = self.layer1.delete_table(table.name)
table.update_from_response(response)
def create_schema(self, hash_key_name, hash_key_proto_value,
range_key_name=None, range_key_proto_value=None):
"""
Create a Schema object used when creating a Table.
:type hash_key_name: str
:param hash_key_name: The name of the HashKey for the schema.
:type hash_key_proto_value: int|long|float|str|unicode|Binary
:param hash_key_proto_value: A sample or prototype of the type
of value you want to use for the HashKey. Alternatively,
you can also just pass in the Python type (e.g. int, float, etc.).
:type range_key_name: str
:param range_key_name: The name of the RangeKey for the schema.
This parameter is optional.
:type range_key_proto_value: int|long|float|str|unicode|Binary
:param range_key_proto_value: A sample or prototype of the type
of value you want to use for the RangeKey. Alternatively,
you can also pass in the Python type (e.g. int, float, etc.)
This parameter is optional.
"""
hash_key = (hash_key_name, get_dynamodb_type(hash_key_proto_value))
if range_key_name and range_key_proto_value is not None:
range_key = (range_key_name,
get_dynamodb_type(range_key_proto_value))
else:
range_key = None
return Schema.create(hash_key, range_key)
def get_item(self, table, hash_key, range_key=None,
attributes_to_get=None, consistent_read=False,
item_class=Item):
"""
Retrieve an existing item from the table.
:type table: :class:`boto.dynamodb.table.Table`
:param table: The Table object from which the item is retrieved.
:type hash_key: int|long|float|str|unicode|Binary
:param hash_key: The HashKey of the requested item. The
type of the value must match the type defined in the
schema for the table.
:type range_key: int|long|float|str|unicode|Binary
:param range_key: The optional RangeKey of the requested item.
The type of the value must match the type defined in the
schema for the table.
:type attributes_to_get: list
:param attributes_to_get: A list of attribute names.
If supplied, only the specified attribute names will
be returned. Otherwise, all attributes will be returned.
:type consistent_read: bool
:param consistent_read: If True, a consistent read
request is issued. Otherwise, an eventually consistent
request is issued.
:type item_class: Class
:param item_class: Allows you to override the class used
to generate the items. This should be a subclass of
:class:`boto.dynamodb.item.Item`
"""
key = self.build_key_from_values(table.schema, hash_key, range_key)
response = self.layer1.get_item(table.name, key,
attributes_to_get, consistent_read,
object_hook=self.dynamizer.decode)
item = item_class(table, hash_key, range_key, response['Item'])
if 'ConsumedCapacityUnits' in response:
item.consumed_units = response['ConsumedCapacityUnits']
return item
def batch_get_item(self, batch_list):
"""
Return a set of attributes for a multiple items in
multiple tables using their primary keys.
:type batch_list: :class:`boto.dynamodb.batch.BatchList`
:param batch_list: A BatchList object which consists of a
list of :class:`boto.dynamoddb.batch.Batch` objects.
Each Batch object contains the information about one
batch of objects that you wish to retrieve in this
request.
"""
request_items = batch_list.to_dict()
return self.layer1.batch_get_item(request_items,
object_hook=self.dynamizer.decode)
def batch_write_item(self, batch_list):
"""
Performs multiple Puts and Deletes in one batch.
:type batch_list: :class:`boto.dynamodb.batch.BatchWriteList`
:param batch_list: A BatchWriteList object which consists of a
list of :class:`boto.dynamoddb.batch.BatchWrite` objects.
Each Batch object contains the information about one
batch of objects that you wish to put or delete.
"""
request_items = batch_list.to_dict()
return self.layer1.batch_write_item(request_items,
object_hook=self.dynamizer.decode)
def put_item(self, item, expected_value=None, return_values=None):
"""
Store a new item or completely replace an existing item
in Amazon DynamoDB.
:type item: :class:`boto.dynamodb.item.Item`
:param item: The Item to write to Amazon DynamoDB.
:type expected_value: dict
:param expected_value: A dictionary of name/value pairs that you expect.
This dictionary should have name/value pairs where the name
is the name of the attribute and the value is either the value
you are expecting or False if you expect the attribute not to
exist.
:type return_values: str
:param return_values: Controls the return of attribute
name-value pairs before then were changed. Possible
values are: None or 'ALL_OLD'. If 'ALL_OLD' is
specified and the item is overwritten, the content
of the old item is returned.
"""
expected_value = self.dynamize_expected_value(expected_value)
response = self.layer1.put_item(item.table.name,
self.dynamize_item(item),
expected_value, return_values,
object_hook=self.dynamizer.decode)
if 'ConsumedCapacityUnits' in response:
item.consumed_units = response['ConsumedCapacityUnits']
return response
def update_item(self, item, expected_value=None, return_values=None):
"""
Commit pending item updates to Amazon DynamoDB.
:type item: :class:`boto.dynamodb.item.Item`
:param item: The Item to update in Amazon DynamoDB. It is expected
that you would have called the add_attribute, put_attribute
and/or delete_attribute methods on this Item prior to calling
this method. Those queued changes are what will be updated.
:type expected_value: dict
:param expected_value: A dictionary of name/value pairs that you
expect. This dictionary should have name/value pairs where the
name is the name of the attribute and the value is either the
value you are expecting or False if you expect the attribute
not to exist.
:type return_values: str
:param return_values: Controls the return of attribute name/value pairs
before they were updated. Possible values are: None, 'ALL_OLD',
'UPDATED_OLD', 'ALL_NEW' or 'UPDATED_NEW'. If 'ALL_OLD' is
specified and the item is overwritten, the content of the old item
is returned. If 'ALL_NEW' is specified, then all the attributes of
the new version of the item are returned. If 'UPDATED_NEW' is
specified, the new versions of only the updated attributes are
returned.
"""
expected_value = self.dynamize_expected_value(expected_value)
key = self.build_key_from_values(item.table.schema,
item.hash_key, item.range_key)
attr_updates = self.dynamize_attribute_updates(item._updates)
response = self.layer1.update_item(item.table.name, key,
attr_updates,
expected_value, return_values,
object_hook=self.dynamizer.decode)
item._updates.clear()
if 'ConsumedCapacityUnits' in response:
item.consumed_units = response['ConsumedCapacityUnits']
return response
def delete_item(self, item, expected_value=None, return_values=None):
"""
Delete the item from Amazon DynamoDB.
:type item: :class:`boto.dynamodb.item.Item`
:param item: The Item to delete from Amazon DynamoDB.
:type expected_value: dict
:param expected_value: A dictionary of name/value pairs that you expect.
This dictionary should have name/value pairs where the name
is the name of the attribute and the value is either the value
you are expecting or False if you expect the attribute not to
exist.
:type return_values: str
:param return_values: Controls the return of attribute
name-value pairs before then were changed. Possible
values are: None or 'ALL_OLD'. If 'ALL_OLD' is
specified and the item is overwritten, the content
of the old item is returned.
"""
expected_value = self.dynamize_expected_value(expected_value)
key = self.build_key_from_values(item.table.schema,
item.hash_key, item.range_key)
return self.layer1.delete_item(item.table.name, key,
expected=expected_value,
return_values=return_values,
object_hook=self.dynamizer.decode)
def query(self, table, hash_key, range_key_condition=None,
attributes_to_get=None, request_limit=None,
max_results=None, consistent_read=False,
scan_index_forward=True, exclusive_start_key=None,
item_class=Item, count=False):
"""
Perform a query on the table.
:type table: :class:`boto.dynamodb.table.Table`
:param table: The Table object that is being queried.
:type hash_key: int|long|float|str|unicode|Binary
:param hash_key: The HashKey of the requested item. The
type of the value must match the type defined in the
schema for the table.
:type range_key_condition: :class:`boto.dynamodb.condition.Condition`
:param range_key_condition: A Condition object.
Condition object can be one of the following types:
EQ|LE|LT|GE|GT|BEGINS_WITH|BETWEEN
The only condition which expects or will accept two
values is 'BETWEEN', otherwise a single value should
be passed to the Condition constructor.
:type attributes_to_get: list
:param attributes_to_get: A list of attribute names.
If supplied, only the specified attribute names will
be returned. Otherwise, all attributes will be returned.
:type request_limit: int
:param request_limit: The maximum number of items to retrieve
from Amazon DynamoDB on each request. You may want to set
a specific request_limit based on the provisioned throughput
of your table. The default behavior is to retrieve as many
results as possible per request.
:type max_results: int
:param max_results: The maximum number of results that will
be retrieved from Amazon DynamoDB in total. For example,
if you only wanted to see the first 100 results from the
query, regardless of how many were actually available, you
could set max_results to 100 and the generator returned
from the query method will only yeild 100 results max.
:type consistent_read: bool
:param consistent_read: If True, a consistent read
request is issued. Otherwise, an eventually consistent
request is issued.
:type scan_index_forward: bool
:param scan_index_forward: Specified forward or backward
traversal of the index. Default is forward (True).
:type count: bool
:param count: If True, Amazon DynamoDB returns a total
number of items for the Query operation, even if the
operation has no matching items for the assigned filter.
If count is True, the actual items are not returned and
the count is accessible as the ``count`` attribute of
the returned object.
:type exclusive_start_key: list or tuple
:param exclusive_start_key: Primary key of the item from
which to continue an earlier query. This would be
provided as the LastEvaluatedKey in that query.
:type item_class: Class
:param item_class: Allows you to override the class used
to generate the items. This should be a subclass of
:class:`boto.dynamodb.item.Item`
:rtype: :class:`boto.dynamodb.layer2.TableGenerator`
"""
if range_key_condition:
rkc = self.dynamize_range_key_condition(range_key_condition)
else:
rkc = None
if exclusive_start_key:
esk = self.build_key_from_values(table.schema,
*exclusive_start_key)
else:
esk = None
kwargs = {'table_name': table.name,
'hash_key_value': self.dynamizer.encode(hash_key),
'range_key_conditions': rkc,
'attributes_to_get': attributes_to_get,
'limit': request_limit,
'count': count,
'consistent_read': consistent_read,
'scan_index_forward': scan_index_forward,
'exclusive_start_key': esk,
'object_hook': self.dynamizer.decode}
return TableGenerator(table, self.layer1.query,
max_results, item_class, kwargs)
def scan(self, table, scan_filter=None,
attributes_to_get=None, request_limit=None, max_results=None,
exclusive_start_key=None, item_class=Item, count=False):
"""
Perform a scan of DynamoDB.
:type table: :class:`boto.dynamodb.table.Table`
:param table: The Table object that is being scanned.
:type scan_filter: A dict
:param scan_filter: A dictionary where the key is the
attribute name and the value is a
:class:`boto.dynamodb.condition.Condition` object.
Valid Condition objects include:
* EQ - equal (1)
* NE - not equal (1)
* LE - less than or equal (1)
* LT - less than (1)
* GE - greater than or equal (1)
* GT - greater than (1)
* NOT_NULL - attribute exists (0, use None)
* NULL - attribute does not exist (0, use None)
* CONTAINS - substring or value in list (1)
* NOT_CONTAINS - absence of substring or value in list (1)
* BEGINS_WITH - substring prefix (1)
* IN - exact match in list (N)
* BETWEEN - >= first value, <= second value (2)
:type attributes_to_get: list
:param attributes_to_get: A list of attribute names.
If supplied, only the specified attribute names will
be returned. Otherwise, all attributes will be returned.
:type request_limit: int
:param request_limit: The maximum number of items to retrieve
from Amazon DynamoDB on each request. You may want to set
a specific request_limit based on the provisioned throughput
of your table. The default behavior is to retrieve as many
results as possible per request.
:type max_results: int
:param max_results: The maximum number of results that will
be retrieved from Amazon DynamoDB in total. For example,
if you only wanted to see the first 100 results from the
query, regardless of how many were actually available, you
could set max_results to 100 and the generator returned
from the query method will only yeild 100 results max.
:type count: bool
:param count: If True, Amazon DynamoDB returns a total
number of items for the Scan operation, even if the
operation has no matching items for the assigned filter.
If count is True, the actual items are not returned and
the count is accessible as the ``count`` attribute of
the returned object.
:type exclusive_start_key: list or tuple
:param exclusive_start_key: Primary key of the item from
which to continue an earlier query. This would be
provided as the LastEvaluatedKey in that query.
:type item_class: Class
:param item_class: Allows you to override the class used
to generate the items. This should be a subclass of
:class:`boto.dynamodb.item.Item`
:rtype: :class:`boto.dynamodb.layer2.TableGenerator`
"""
if exclusive_start_key:
esk = self.build_key_from_values(table.schema,
*exclusive_start_key)
else:
esk = None
kwargs = {'table_name': table.name,
'scan_filter': self.dynamize_scan_filter(scan_filter),
'attributes_to_get': attributes_to_get,
'limit': request_limit,
'count': count,
'exclusive_start_key': esk,
'object_hook': self.dynamizer.decode}
return TableGenerator(table, self.layer1.scan,
max_results, item_class, kwargs)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
7760,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7760,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
504,
6055,
14,
30001,
14,
1897,
17,
492,
11915,
17,
199,
504,
6055,
14,
30001,
14,
1224,
492,
6957,
199,
504,
6055,
14,
30001,
14,
3629,
492,
13268,
199,
504,
6055,
14,
30001,
14,
1053,
492,
7020,
199,
504,
6055,
14,
30001,
14,
2912,
492,
17206,
1296,
12,
17206,
30017,
199,
504,
6055,
14,
30001,
14,
1313,
492,
664,
63,
30001,
63,
466,
12,
577,
4019,
1793,
12,
971,
267,
3835,
385,
89,
5136,
36,
4019,
1793,
12,
10172,
4082,
36,
4019,
1793,
421,
199,
533,
6957,
7599,
8,
785,
304,
272,
408,
272,
961,
365,
376,
909,
626,
14018,
1536,
314,
1817,
63,
4679,
805,
14,
272,
710,
1454,
3363,
4499,
370,
1172,
642,
365,
626,
781,
2934,
370,
506,
7688,
272,
370,
30535,
436,
372,
314,
1448,
3639,
68,
22688,
15121,
1819,
626,
272,
365,
1777,
402,
1924,
1177,
14,
339,
520,
7725,
2061,
63,
2579,
23130,
63,
498,
26,
437,
3414,
6144,
314,
790,
8,
83,
9,
267,
402,
314,
1242,
2061,
13006,
12,
503,
488,
340,
949,
4722,
267,
2058,
787,
2808,
14,
339,
520,
7725,
7971,
26,
710,
7971,
12524,
402,
2058,
5839,
14,
339,
520,
7725,
1817,
26,
710,
1817,
370,
1314,
314,
1240,
1990,
6326,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1817,
12,
4550,
12,
7971,
12,
1242,
63,
533,
12,
2074,
304,
267,
291,
14,
1224,
275,
1817,
267,
291,
14,
8296,
275,
4550,
267,
291,
14,
11266,
275,
446,
17,
340,
7971,
365,
488,
587,
7971,
267,
291,
14,
1053,
63,
533,
275,
1242,
63,
533,
267,
291,
14,
958,
275,
2074,
267,
291,
423,
20688,
63,
5260,
275,
378,
14,
16,
267,
291,
14,
2019,
63,
2579,
23130,
63,
498,
275,
488,
267,
291,
423,
835,
275,
378,
267,
291,
423,
551,
9386,
63,
835,
275,
378,
267,
291,
423,
1310,
275,
488,
339,
768,
1829,
272,
347,
2338,
8,
277,
304,
267,
408,
267,
710,
3141,
1329,
402,
2974,
12396,
12850,
12474,
14,
221,
961,
574,
4493,
543,
267,
8494,
436,
2755,
1380,
365,
9648,
316,
282,
1240,
543,
2338,
29,
549,
12,
652,
365,
5784,
267,
370,
4890,
314,
8494,
370,
702,
376,
23189,
2338,
574,
14,
267,
408,
267,
291,
14,
1310,
267,
372,
291,
423,
835,
339,
768,
1829,
272,
347,
28261,
63,
835,
8,
277,
304,
267,
408,
267,
3709,
3432,
12,
1325,
6144,
314,
3141,
1329,
402,
2974,
28261,
701,
267,
31856,
12,
1928,
8794,
370,
1263,
4766,
14,
267,
408,
267,
291,
14,
1310,
267,
372,
291,
423,
551,
9386,
63,
835,
339,
768,
1829,
272,
347,
16949,
63,
5260,
8,
277,
304,
267,
408,
267,
1803,
282,
2069,
6144,
314,
1448,
3639,
68,
22688,
15121,
29845,
14,
267,
408,
267,
291,
14,
1310,
267,
372,
291,
423,
20688,
63,
5260,
339,
768,
1829,
272,
347,
1177,
8,
277,
304,
267,
408,
267,
710,
1453,
1177,
370,
314,
1240,
687,
31856,
14,
267,
408,
267,
372,
291,
14,
2184,
63,
1310,
342,
340,
291,
423,
1310,
365,
488,
587,
291,
423,
1310,
339,
347,
2163,
63,
1310,
8,
277,
304,
267,
408,
267,
13383,
282,
1240,
436,
372,
314,
754,
14,
221,
2047,
883,
12677,
642,
1083,
267,
1830,
25012,
1806,
314,
6957,
7599,
315,
1865,
370,
3372,
370,
314,
267,
2163,
298,
1606,
2,
402,
2058,
14,
267,
408,
267,
327,
11211,
1263,
3411,
2304,
315,
1930,
314,
922,
741,
878,
291,
14,
11266,
267,
2304,
275,
291,
14,
958,
14,
362,
360,
3097,
358,
267,
340,
334,
277,
14,
11266,
690,
378,
436,
334,
3097,
365,
488,
503,
2304,
690,
291,
14,
11266,
2298,
288,
291,
14,
958,
459,
3097,
418,
275,
291,
14,
11266,
267,
291,
423,
1310,
275,
291,
14,
8296,
3682,
277,
14,
958,
9,
267,
291,
14,
958,
459,
3097,
418,
275,
2304,
267,
291,
423,
20688,
63,
5260,
847,
291,
423,
1310,
14,
362,
360,
21042,
68,
22688,
15121,
297,
378,
14,
16,
9,
267,
291,
423,
835,
847,
291,
423,
1310,
14,
362,
360,
2353,
297,
378,
9,
267,
291,
423,
551,
9386,
63,
835,
847,
291,
423,
1310,
14,
362,
360,
7181,
9386,
2353,
297,
378,
9,
267,
327,
737,
314,
26963,
402,
282,
12570,
7192,
292,
4993,
1785,
31388,
794,
12,
4868,
626,
267,
327,
14670,
4306,
23868,
7859,
1133,
754,
315,
4875,
6124,
43,
1338,
267,
340,
283,
6090,
10006,
23130,
1197,
7,
315,
291,
423,
1310,
26,
288,
1026,
75,
275,
291,
423,
1310,
459,
6090,
10006,
23130,
1197,
418,
288,
325,
1339,
275,
291
] |
[
1898,
334,
67,
9,
7760,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7760,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
504,
6055,
14,
30001,
14,
1897,
17,
492,
11915,
17,
199,
504,
6055,
14,
30001,
14,
1224,
492,
6957,
199,
504,
6055,
14,
30001,
14,
3629,
492,
13268,
199,
504,
6055,
14,
30001,
14,
1053,
492,
7020,
199,
504,
6055,
14,
30001,
14,
2912,
492,
17206,
1296,
12,
17206,
30017,
199,
504,
6055,
14,
30001,
14,
1313,
492,
664,
63,
30001,
63,
466,
12,
577,
4019,
1793,
12,
971,
267,
3835,
385,
89,
5136,
36,
4019,
1793,
12,
10172,
4082,
36,
4019,
1793,
421,
199,
533,
6957,
7599,
8,
785,
304,
272,
408,
272,
961,
365,
376,
909,
626,
14018,
1536,
314,
1817,
63,
4679,
805,
14,
272,
710,
1454,
3363,
4499,
370,
1172,
642,
365,
626,
781,
2934,
370,
506,
7688,
272,
370,
30535,
436,
372,
314,
1448,
3639,
68,
22688,
15121,
1819,
626,
272,
365,
1777,
402,
1924,
1177,
14,
339,
520,
7725,
2061,
63,
2579,
23130,
63,
498,
26,
437,
3414,
6144,
314,
790,
8,
83,
9,
267,
402,
314,
1242,
2061,
13006,
12,
503,
488,
340,
949,
4722,
267,
2058,
787,
2808,
14,
339,
520,
7725,
7971,
26,
710,
7971,
12524,
402,
2058,
5839,
14,
339,
520,
7725,
1817,
26,
710,
1817,
370,
1314,
314,
1240,
1990,
6326,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1817,
12,
4550,
12,
7971,
12,
1242,
63,
533,
12,
2074,
304,
267,
291,
14,
1224,
275,
1817,
267,
291,
14,
8296,
275,
4550,
267,
291,
14,
11266,
275,
446,
17,
340,
7971,
365,
488,
587,
7971,
267,
291,
14,
1053,
63,
533,
275,
1242,
63,
533,
267,
291,
14,
958,
275,
2074,
267,
291,
423,
20688,
63,
5260,
275,
378,
14,
16,
267,
291,
14,
2019,
63,
2579,
23130,
63,
498,
275,
488,
267,
291,
423,
835,
275,
378,
267,
291,
423,
551,
9386,
63,
835,
275,
378,
267,
291,
423,
1310,
275,
488,
339,
768,
1829,
272,
347,
2338,
8,
277,
304,
267,
408,
267,
710,
3141,
1329,
402,
2974,
12396,
12850,
12474,
14,
221,
961,
574,
4493,
543,
267,
8494,
436,
2755,
1380,
365,
9648,
316,
282,
1240,
543,
2338,
29,
549,
12,
652,
365,
5784,
267,
370,
4890,
314,
8494,
370,
702,
376,
23189,
2338,
574,
14,
267,
408,
267,
291,
14,
1310,
267,
372,
291,
423,
835,
339,
768,
1829,
272,
347,
28261,
63,
835,
8,
277,
304,
267,
408,
267,
3709,
3432,
12,
1325,
6144,
314,
3141,
1329,
402,
2974,
28261,
701,
267,
31856,
12,
1928,
8794,
370,
1263,
4766,
14,
267,
408,
267,
291,
14,
1310,
267,
372,
291,
423,
551,
9386,
63,
835,
339,
768,
1829,
272,
347,
16949,
63,
5260,
8,
277,
304,
267,
408,
267,
1803,
282,
2069,
6144,
314,
1448,
3639,
68,
22688,
15121,
29845,
14,
267,
408,
267,
291,
14,
1310,
267,
372,
291,
423,
20688,
63,
5260,
339,
768,
1829,
272,
347,
1177,
8,
277,
304,
267,
408,
267,
710,
1453,
1177,
370,
314,
1240,
687,
31856,
14,
267,
408,
267,
372,
291,
14,
2184,
63,
1310,
342,
340,
291,
423,
1310,
365,
488,
587,
291,
423,
1310,
339,
347,
2163,
63,
1310,
8,
277,
304,
267,
408,
267,
13383,
282,
1240,
436,
372,
314,
754,
14,
221,
2047,
883,
12677,
642,
1083,
267,
1830,
25012,
1806,
314,
6957,
7599,
315,
1865,
370,
3372,
370,
314,
267,
2163,
298,
1606,
2,
402,
2058,
14,
267,
408,
267,
327,
11211,
1263,
3411,
2304,
315,
1930,
314,
922,
741,
878,
291,
14,
11266,
267,
2304,
275,
291,
14,
958,
14,
362,
360,
3097,
358,
267,
340,
334,
277,
14,
11266,
690,
378,
436,
334,
3097,
365,
488,
503,
2304,
690,
291,
14,
11266,
2298,
288,
291,
14,
958,
459,
3097,
418,
275,
291,
14,
11266,
267,
291,
423,
1310,
275,
291,
14,
8296,
3682,
277,
14,
958,
9,
267,
291,
14,
958,
459,
3097,
418,
275,
2304,
267,
291,
423,
20688,
63,
5260,
847,
291,
423,
1310,
14,
362,
360,
21042,
68,
22688,
15121,
297,
378,
14,
16,
9,
267,
291,
423,
835,
847,
291,
423,
1310,
14,
362,
360,
2353,
297,
378,
9,
267,
291,
423,
551,
9386,
63,
835,
847,
291,
423,
1310,
14,
362,
360,
7181,
9386,
2353,
297,
378,
9,
267,
327,
737,
314,
26963,
402,
282,
12570,
7192,
292,
4993,
1785,
31388,
794,
12,
4868,
626,
267,
327,
14670,
4306,
23868,
7859,
1133,
754,
315,
4875,
6124,
43,
1338,
267,
340,
283,
6090,
10006,
23130,
1197,
7,
315,
291,
423,
1310,
26,
288,
1026,
75,
275,
291,
423,
1310,
459,
6090,
10006,
23130,
1197,
418,
288,
325,
1339,
275,
291,
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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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
] |
kenshay/ImageScripter
|
ProgramData/SystemFiles/Python/Lib/site-packages/numpy/fft/tests/test_fftpack.py
|
134
|
6052
|
from __future__ import division, absolute_import, print_function
import numpy as np
from numpy.random import random
from numpy.testing import TestCase, run_module_suite, assert_array_almost_equal
from numpy.testing import assert_array_equal
import threading
import sys
if sys.version_info[0] >= 3:
import queue
else:
import Queue as queue
def fft1(x):
L = len(x)
phase = -2j*np.pi*(np.arange(L)/float(L))
phase = np.arange(L).reshape(-1, 1) * phase
return np.sum(x*np.exp(phase), axis=1)
class TestFFTShift(TestCase):
def test_fft_n(self):
self.assertRaises(ValueError, np.fft.fft, [1, 2, 3], 0)
class TestFFT1D(TestCase):
def test_fft(self):
x = random(30) + 1j*random(30)
assert_array_almost_equal(fft1(x), np.fft.fft(x))
assert_array_almost_equal(fft1(x) / np.sqrt(30),
np.fft.fft(x, norm="ortho"))
def test_ifft(self):
x = random(30) + 1j*random(30)
assert_array_almost_equal(x, np.fft.ifft(np.fft.fft(x)))
assert_array_almost_equal(
x, np.fft.ifft(np.fft.fft(x, norm="ortho"), norm="ortho"))
def test_fft2(self):
x = random((30, 20)) + 1j*random((30, 20))
assert_array_almost_equal(np.fft.fft(np.fft.fft(x, axis=1), axis=0),
np.fft.fft2(x))
assert_array_almost_equal(np.fft.fft2(x) / np.sqrt(30 * 20),
np.fft.fft2(x, norm="ortho"))
def test_ifft2(self):
x = random((30, 20)) + 1j*random((30, 20))
assert_array_almost_equal(np.fft.ifft(np.fft.ifft(x, axis=1), axis=0),
np.fft.ifft2(x))
assert_array_almost_equal(np.fft.ifft2(x) * np.sqrt(30 * 20),
np.fft.ifft2(x, norm="ortho"))
def test_fftn(self):
x = random((30, 20, 10)) + 1j*random((30, 20, 10))
assert_array_almost_equal(
np.fft.fft(np.fft.fft(np.fft.fft(x, axis=2), axis=1), axis=0),
np.fft.fftn(x))
assert_array_almost_equal(np.fft.fftn(x) / np.sqrt(30 * 20 * 10),
np.fft.fftn(x, norm="ortho"))
def test_ifftn(self):
x = random((30, 20, 10)) + 1j*random((30, 20, 10))
assert_array_almost_equal(
np.fft.ifft(np.fft.ifft(np.fft.ifft(x, axis=2), axis=1), axis=0),
np.fft.ifftn(x))
assert_array_almost_equal(np.fft.ifftn(x) * np.sqrt(30 * 20 * 10),
np.fft.ifftn(x, norm="ortho"))
def test_rfft(self):
x = random(30)
assert_array_almost_equal(np.fft.fft(x)[:16], np.fft.rfft(x))
assert_array_almost_equal(np.fft.rfft(x) / np.sqrt(30),
np.fft.rfft(x, norm="ortho"))
def test_irfft(self):
x = random(30)
assert_array_almost_equal(x, np.fft.irfft(np.fft.rfft(x)))
assert_array_almost_equal(
x, np.fft.irfft(np.fft.rfft(x, norm="ortho"), norm="ortho"))
def test_rfft2(self):
x = random((30, 20))
assert_array_almost_equal(np.fft.fft2(x)[:, :11], np.fft.rfft2(x))
assert_array_almost_equal(np.fft.rfft2(x) / np.sqrt(30 * 20),
np.fft.rfft2(x, norm="ortho"))
def test_irfft2(self):
x = random((30, 20))
assert_array_almost_equal(x, np.fft.irfft2(np.fft.rfft2(x)))
assert_array_almost_equal(
x, np.fft.irfft2(np.fft.rfft2(x, norm="ortho"), norm="ortho"))
def test_rfftn(self):
x = random((30, 20, 10))
assert_array_almost_equal(np.fft.fftn(x)[:, :, :6], np.fft.rfftn(x))
assert_array_almost_equal(np.fft.rfftn(x) / np.sqrt(30 * 20 * 10),
np.fft.rfftn(x, norm="ortho"))
def test_irfftn(self):
x = random((30, 20, 10))
assert_array_almost_equal(x, np.fft.irfftn(np.fft.rfftn(x)))
assert_array_almost_equal(
x, np.fft.irfftn(np.fft.rfftn(x, norm="ortho"), norm="ortho"))
def test_hfft(self):
x = random(14) + 1j*random(14)
x_herm = np.concatenate((random(1), x, random(1)))
x = np.concatenate((x_herm, x[::-1].conj()))
assert_array_almost_equal(np.fft.fft(x), np.fft.hfft(x_herm))
assert_array_almost_equal(np.fft.hfft(x_herm) / np.sqrt(30),
np.fft.hfft(x_herm, norm="ortho"))
def test_ihttf(self):
x = random(14) + 1j*random(14)
x_herm = np.concatenate((random(1), x, random(1)))
x = np.concatenate((x_herm, x[::-1].conj()))
assert_array_almost_equal(x_herm, np.fft.ihfft(np.fft.hfft(x_herm)))
assert_array_almost_equal(
x_herm, np.fft.ihfft(np.fft.hfft(x_herm, norm="ortho"),
norm="ortho"))
class TestFFTThreadSafe(TestCase):
threads = 16
input_shape = (800, 200)
def _test_mtsame(self, func, *args):
def worker(args, q):
q.put(func(*args))
q = queue.Queue()
expected = func(*args)
# Spin off a bunch of threads to call the same function simultaneously
t = [threading.Thread(target=worker, args=(args, q))
for i in range(self.threads)]
[x.start() for x in t]
[x.join() for x in t]
# Make sure all threads returned the correct value
for i in range(self.threads):
assert_array_equal(q.get(timeout=5), expected,
'Function returned wrong value in multithreaded context')
def test_fft(self):
a = np.ones(self.input_shape) * 1+0j
self._test_mtsame(np.fft.fft, a)
def test_ifft(self):
a = np.ones(self.input_shape) * 1+0j
self._test_mtsame(np.fft.ifft, a)
def test_rfft(self):
a = np.ones(self.input_shape)
self._test_mtsame(np.fft.rfft, a)
def test_irfft(self):
a = np.ones(self.input_shape) * 1+0j
self._test_mtsame(np.fft.irfft, a)
if __name__ == "__main__":
run_module_suite()
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
2355,
492,
2196,
199,
504,
2680,
14,
4776,
492,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
646,
5796,
199,
646,
984,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
272,
492,
4126,
199,
2836,
26,
272,
492,
10703,
465,
4126,
421,
199,
318,
18160,
17,
8,
88,
304,
272,
491,
275,
822,
8,
88,
9,
272,
7669,
275,
446,
18,
74,
10,
1590,
14,
1038,
5830,
1590,
14,
5605,
8,
44,
2447,
1609,
8,
44,
430,
272,
7669,
275,
980,
14,
5605,
8,
44,
680,
5217,
2801,
17,
12,
413,
9,
627,
7669,
272,
372,
980,
14,
1838,
8,
88,
10,
1590,
14,
1474,
8,
6971,
395,
3114,
29,
17,
9,
421,
199,
533,
1379,
1665,
52,
14379,
8,
1746,
304,
339,
347,
511,
63,
9996,
63,
78,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
980,
14,
9996,
14,
9996,
12,
359,
17,
12,
499,
12,
650,
467,
378,
9,
421,
199,
533,
1379,
1665,
52,
17,
36,
8,
1746,
304,
339,
347,
511,
63,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
435,
413,
74,
10,
2355,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
9996,
17,
8,
88,
395,
980,
14,
9996,
14,
9996,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
9996,
17,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
395,
3303,
980,
14,
9996,
14,
9996,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
73,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
435,
413,
74,
10,
2355,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
88,
12,
980,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
1724,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
671,
12,
980,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
12,
6316,
628,
11297,
79,
1288,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
9996,
18,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
12,
3114,
29,
17,
395,
3114,
29,
16,
395,
3303,
980,
14,
9996,
14,
9996,
18,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
9996,
18,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
627,
3388,
395,
3303,
980,
14,
9996,
14,
9996,
18,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
73,
9996,
18,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
73,
9996,
8,
88,
12,
3114,
29,
17,
395,
3114,
29,
16,
395,
3303,
980,
14,
9996,
14,
73,
9996,
18,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
73,
9996,
18,
8,
88,
9,
627,
980,
14,
5079,
8,
1216,
627,
3388,
395,
3303,
980,
14,
9996,
14,
73,
9996,
18,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
556,
5889,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
12,
1616,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
12,
1616,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
980,
14,
9996,
14,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
12,
3114,
29,
18,
395,
3114,
29,
17,
395,
3114,
29,
16,
395,
288,
980,
14,
9996,
14,
556,
5889,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
556,
5889,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
627,
3388,
627,
1616,
395,
3303,
980,
14,
9996,
14,
556,
5889,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
15126,
5889,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
12,
1616,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
12,
1616,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
980,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
73,
9996,
8,
88,
12,
3114,
29,
18,
395,
3114,
29,
17,
395,
3114,
29,
16,
395,
288,
980,
14,
9996,
14,
15126,
5889,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
15126,
5889,
8,
88,
9,
627,
980,
14,
5079,
8,
1216,
627,
3388,
627,
1616,
395,
3303,
980,
14,
9996,
14,
15126,
5889,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
82,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
9996,
8,
88,
18562,
975,
467,
980,
14,
9996,
14,
82,
9996,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
82,
9996,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
395,
3303,
980,
14,
9996,
14,
82,
9996,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
723,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
88,
12,
980,
14,
9996,
14,
723,
9996,
8,
1590,
14,
9996,
14,
82,
9996,
8,
88,
1724,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
671,
12,
980,
14,
9996,
14,
723,
9996,
8,
1590,
14,
9996,
14,
82,
9996,
8,
88,
12,
6316,
628
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
2355,
492,
2196,
199,
504,
2680,
14,
4776,
492,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
646,
5796,
199,
646,
984,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
272,
492,
4126,
199,
2836,
26,
272,
492,
10703,
465,
4126,
421,
199,
318,
18160,
17,
8,
88,
304,
272,
491,
275,
822,
8,
88,
9,
272,
7669,
275,
446,
18,
74,
10,
1590,
14,
1038,
5830,
1590,
14,
5605,
8,
44,
2447,
1609,
8,
44,
430,
272,
7669,
275,
980,
14,
5605,
8,
44,
680,
5217,
2801,
17,
12,
413,
9,
627,
7669,
272,
372,
980,
14,
1838,
8,
88,
10,
1590,
14,
1474,
8,
6971,
395,
3114,
29,
17,
9,
421,
199,
533,
1379,
1665,
52,
14379,
8,
1746,
304,
339,
347,
511,
63,
9996,
63,
78,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
980,
14,
9996,
14,
9996,
12,
359,
17,
12,
499,
12,
650,
467,
378,
9,
421,
199,
533,
1379,
1665,
52,
17,
36,
8,
1746,
304,
339,
347,
511,
63,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
435,
413,
74,
10,
2355,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
9996,
17,
8,
88,
395,
980,
14,
9996,
14,
9996,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
9996,
17,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
395,
3303,
980,
14,
9996,
14,
9996,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
73,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
435,
413,
74,
10,
2355,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
88,
12,
980,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
1724,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
671,
12,
980,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
12,
6316,
628,
11297,
79,
1288,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
9996,
18,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
12,
3114,
29,
17,
395,
3114,
29,
16,
395,
3303,
980,
14,
9996,
14,
9996,
18,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
9996,
18,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
627,
3388,
395,
3303,
980,
14,
9996,
14,
9996,
18,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
73,
9996,
18,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
73,
9996,
8,
88,
12,
3114,
29,
17,
395,
3114,
29,
16,
395,
3303,
980,
14,
9996,
14,
73,
9996,
18,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
73,
9996,
18,
8,
88,
9,
627,
980,
14,
5079,
8,
1216,
627,
3388,
395,
3303,
980,
14,
9996,
14,
73,
9996,
18,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
556,
5889,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
12,
1616,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
12,
1616,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
980,
14,
9996,
14,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
1590,
14,
9996,
14,
9996,
8,
88,
12,
3114,
29,
18,
395,
3114,
29,
17,
395,
3114,
29,
16,
395,
288,
980,
14,
9996,
14,
556,
5889,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
556,
5889,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
627,
3388,
627,
1616,
395,
3303,
980,
14,
9996,
14,
556,
5889,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
15126,
5889,
8,
277,
304,
267,
671,
275,
2196,
1332,
1216,
12,
3388,
12,
1616,
430,
435,
413,
74,
10,
2355,
1332,
1216,
12,
3388,
12,
1616,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
980,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
73,
9996,
8,
1590,
14,
9996,
14,
73,
9996,
8,
88,
12,
3114,
29,
18,
395,
3114,
29,
17,
395,
3114,
29,
16,
395,
288,
980,
14,
9996,
14,
15126,
5889,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
15126,
5889,
8,
88,
9,
627,
980,
14,
5079,
8,
1216,
627,
3388,
627,
1616,
395,
3303,
980,
14,
9996,
14,
15126,
5889,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
82,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
9996,
8,
88,
18562,
975,
467,
980,
14,
9996,
14,
82,
9996,
8,
88,
430,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
9996,
14,
82,
9996,
8,
88,
9,
1182,
980,
14,
5079,
8,
1216,
395,
3303,
980,
14,
9996,
14,
82,
9996,
8,
88,
12,
6316,
628,
11297,
79,
2237,
339,
347,
511,
63,
723,
9996,
8,
277,
304,
267,
671,
275,
2196,
8,
1216,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
88,
12,
980,
14,
9996,
14,
723,
9996,
8,
1590,
14,
9996,
14,
82,
9996,
8,
88,
1724,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
288,
671,
12,
980,
14,
9996,
14,
723,
9996,
8,
1590,
14,
9996,
14,
82,
9996,
8,
88,
12,
6316,
628,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ukncsc/viper
|
viper/modules/cuckoo.py
|
2
|
11252
|
# This file is part of Viper - https://github.com/viper-framework/viper
# See the file 'LICENSE' for copying permission.
try:
import requests
HAVE_REQUESTS = True
except ImportError:
HAVE_REQUESTS = False
import os
import shutil
import tempfile
import tarfile
import contextlib
from cStringIO import StringIO
from viper.common.abstracts import Module
from viper.core.session import __sessions__
from viper.core.config import Config
from viper.core.database import Database
from viper.common.objects import File
from viper.core.storage import store_sample
cfg = Config()
# context manager for dropped files
@contextlib.contextmanager
def create_temp():
temp_dir = tempfile.mkdtemp()
yield temp_dir
shutil.rmtree(temp_dir)
class Cuckoo(Module):
cmd = 'cuckoo'
description = 'Submit the file to Cuckoo Sandbox'
authors = ['nex', 'Kevin Breen']
def __init__(self):
super(Cuckoo, self).__init__()
self.parser.add_argument('-s', '--status', action='store_true', help='Get Analysis Status')
self.parser.add_argument('-f', '--file', action='store_true', help='Submit File for analysis')
self.parser.add_argument('-r', '--resubmit', action='store_true', help='Resubmit Analysis of File')
self.parser.add_argument('-d', '--dropped', type=int, help='Get all Dropped Samples from task id')
self.parser.add_argument('-m', '--machine', help='Name of Machine or all')
self.parser.add_argument('-p', '--package', help='Select a package type to run')
self.parser.add_argument('-o', '--options', help='Options in the format "procmemdump=yes,nohuman=yes"')
self.parser.add_argument('-i', '--instance', help='Select a Cuckoo instance')
def add_file(self, file_path, tags, parent):
obj = File(file_path)
new_path = store_sample(obj)
if new_path:
# Add file to the database.
db = Database()
db.add(obj=obj, tags=tags, parent_sha=parent)
return obj.sha256
def api_query(self, api_method, api_uri, files=None, params=None):
if files:
try:
response = requests.post(api_uri, files=files, data=params)
except requests.ConnectionError:
self.log('error', "Unable to connect to Cuckoo API at '{0}'.".format(api_uri))
return
except Exception as e:
self.log('error', "Failed performing request at '{0}': {1}".format(api_uri, e))
return
if not files and api_method == 'post':
# POST to API
return
if not files and api_method == 'get':
# GET from API
try:
response = requests.get(api_uri)
except requests.ConnectionError:
self.log('error', "Unable to connect to Cuckoo API at '{0}'.".format(api_uri))
return
except Exception as e:
self.log('error', "Failed performing request at '{0}': {1}".format(api_uri, e))
return
return response
def run(self):
super(Cuckoo, self).run()
if self.args is None:
return
# Get the connections string from config
if cfg.cuckoo.cuckoo_host:
if self.args.instance == "offline":
cuckoo_host = cfg.cuckoooffline.cuckoo_host
elif self.args.instance == "online":
cuckoo_host = cfg.cuckoo.cuckoo_host
else:
self.log('error', 'Cuckoo instance not set')
return
else:
self.log('error', 'Cuckoo Config Not Set')
return
if cfg.cuckoo.cuckoo_modified:
search_url = '{0}/api/tasks/search/sha256'.format(cuckoo_host)
submit_file_url = '{0}/api/tasks/create/file/'.format(cuckoo_host)
status_url = '{0}/api/cuckoo/status'.format(cuckoo_host)
else:
search_url = '{0}/tasks/list'.format(cuckoo_host)
submit_file_url = '{0}/tasks/create/file'.format(cuckoo_host)
status_url = '{0}/cuckoo/status'.format(cuckoo_host)
if self.args.status:
# get the JSON
try:
api_status = self.api_query('get', status_url).json()
except:
return
if cfg.cuckoo.cuckoo_modified:
cuckoo_version = api_status['data']['version']
machines = '{0}/{1}'.format(api_status['data']['machines']['available'],
api_status['data']['machines']['total']
)
tasks = [api_status['data']['tasks']['completed'],
api_status['data']['tasks']['pending'],
api_status['data']['tasks']['reported'],
api_status['data']['tasks']['running'],
api_status['data']['tasks']['total']
]
else:
cuckoo_version = api_status['version']
machines = '{0}/{1}'.format(api_status['machines']['available'],
api_status['machines']['total']
)
tasks = [api_status['tasks']['completed'],
api_status['tasks']['pending'],
api_status['tasks']['reported'],
api_status['tasks']['running'],
api_status['tasks']['total']
]
self.log('info', "Cuckoo")
self.log('item', "Version: {0}".format(cuckoo_version))
self.log('item', "Available Machines: {0}".format(machines))
self.log('info', "Tasks")
self.log('item', "Completed: {0}".format(tasks[0]))
self.log('item', "Pending: {0}".format(tasks[1]))
self.log('item', "Reported: {0}".format(tasks[2]))
self.log('item', "Running: {0}".format(tasks[3]))
self.log('item', "Total: {0}".format(tasks[4]))
if self.args.file:
if not __sessions__.is_set():
self.log('error', "No open session")
return
if not self.args.resubmit:
# Check for existing Session
if cfg.cuckoo.cuckoo_modified:
search_results = self.api_query('get', '{0}/{1}'.format(search_url, __sessions__.current.file.sha256)).json()
if search_results['data'] != "Sample not found in database":
self.log('info', "Found {0} Results".format(len(search_results['data'])))
rows = []
header = ['ID', 'Started On', 'Status', 'Completed On']
for result in search_results['data']:
rows.append([result['id'], result['started_on'], result['status'], result['completed_on']])
self.log('table', dict(header=header, rows=rows))
self.log('warning', "use -r, --resubmit to force a new analysis")
return
else:
search_results = self.api_query('get', search_url).json()
count = 0
if 'tasks' in search_results:
rows = []
header = ['ID', 'Started On', 'Status', 'Completed On']
for result in search_results['tasks']:
try:
if result['sample']['sha256'] == __sessions__.current.file.sha256:
rows.append([result['id'], result['started_on'], result['status'], result['completed_on']])
count += 1
except:
pass
if len(rows) > 0:
self.log('info', "Found {0} Results".format(count))
self.log('table', dict(header=header, rows=rows))
self.log('warning', "use -r, --resubmit to force a new analysis")
return
# Submit the file
params = {}
if self.args.machine:
params['machine'] = self.args.machine
if self.args.package:
params['package'] = self.args.package
if self.args.options:
params['options'] = self.args.options
files = {'file': (__sessions__.current.file.name, open(__sessions__.current.file.path, 'rb').read())}
submit_file = self.api_query('post', submit_file_url, files=files, params=params).json()
try:
self.log('info', "Task Submitted ID: {0}".format(submit_file['task_id']))
except KeyError:
try:
self.log('info', "Task Submitted ID: {0}".format(submit_file['task_ids'][0]))
except KeyError:
self.log('error', submit_file)
if self.args.dropped and __sessions__.is_set():
try:
task_id = int(self.args.dropped)
except:
self.log('error', "Not a valid task id")
# Handle Modified-Cuckoo
if cfg.cuckoo.cuckoo_modified:
dropped_url = '{0}/api/tasks/get/dropped/{1}'.format(cuckoo_host, task_id)
else:
dropped_url = '{0}/tasks/report/{1}/dropped'.format(cuckoo_host, task_id)
dropped_result = self.api_query('get', dropped_url)
if dropped_result.content.startswith('BZ'):
# explode BZ
with tarfile.open(fileobj=StringIO(dropped_result.content)) as bz_file:
for item in bz_file:
# Write Files to tmp dir
if item.isreg():
# Create temp dirs to prevent duplicate filenames creating Errors
with create_temp() as temp_dir:
file_path = os.path.join(temp_dir, os.path.basename(item.name))
with open(file_path, 'wb') as out:
out.write(bz_file.extractfile(item).read())
# Add the file
self.log('info', "Storing Dropped File {0}".format(item.name))
self.add_file(file_path,
'Cuckoo_ID_{0}'.format(task_id),
__sessions__.current.file.sha256
)
return
else:
if not __sessions__.is_set():
self.log('error', "No open session")
return
try:
json_error = dropped_result.json()
self.log('error', json_error['data'])
except Exception as e:
self.log('error', "Your broke something, {0}".format(e))
|
bsd-3-clause
|
[
3,
961,
570,
365,
1777,
402,
6561,
529,
446,
4178,
921,
5031,
14,
957,
15,
433,
529,
13,
4857,
15,
433,
529,
199,
3,
1666,
314,
570,
283,
3961,
7,
367,
16743,
4983,
14,
199,
199,
893,
26,
272,
492,
4145,
272,
25227,
63,
6780,
51,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
6780,
51,
275,
756,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
646,
13608,
199,
646,
15502,
199,
504,
15073,
492,
5228,
199,
199,
504,
1321,
529,
14,
2330,
14,
6198,
83,
492,
5673,
199,
504,
1321,
529,
14,
1018,
14,
1730,
492,
636,
11676,
363,
199,
504,
1321,
529,
14,
1018,
14,
888,
492,
4094,
199,
504,
1321,
529,
14,
1018,
14,
4659,
492,
8692,
199,
504,
1321,
529,
14,
2330,
14,
1462,
492,
3814,
199,
504,
1321,
529,
14,
1018,
14,
3494,
492,
3877,
63,
3271,
199,
199,
4128,
275,
4094,
342,
199,
199,
3,
1067,
5256,
367,
17481,
1584,
199,
32,
23464,
14,
14237,
199,
318,
1218,
63,
808,
837,
272,
2388,
63,
694,
275,
5549,
14,
11983,
342,
272,
1995,
2388,
63,
694,
272,
5145,
14,
9242,
8,
808,
63,
694,
9,
199,
199,
533,
445,
10112,
1534,
8,
2377,
304,
272,
2088,
275,
283,
67,
10112,
1534,
7,
272,
1369,
275,
283,
17187,
314,
570,
370,
445,
10112,
1534,
428,
10075,
7,
272,
11462,
275,
788,
14743,
297,
283,
1136,
11908,
699,
3441,
418,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
35,
10112,
1534,
12,
291,
2843,
826,
4533,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
1205,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1002,
21916,
9795,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
70,
297,
2850,
493,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
17187,
3814,
367,
11284,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
82,
297,
2850,
15527,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1322,
14760,
21916,
402,
3814,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
68,
297,
2850,
27557,
297,
730,
29,
442,
12,
1720,
534,
1002,
1006,
18110,
1915,
428,
1889,
687,
2120,
1305,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
77,
297,
2850,
6744,
297,
221,
1720,
534,
985,
402,
18722,
503,
1006,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
80,
297,
2850,
2491,
297,
221,
1720,
534,
5446,
282,
2559,
730,
370,
1255,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
79,
297,
2850,
1419,
297,
221,
1720,
534,
4558,
315,
314,
1475,
298,
4687,
278,
1064,
1220,
29,
5066,
12,
889,
14864,
29,
5066,
9008,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
73,
297,
2850,
842,
297,
1720,
534,
5446,
282,
445,
10112,
1534,
1256,
358,
2378,
347,
1050,
63,
493,
8,
277,
12,
570,
63,
515,
12,
3762,
12,
1676,
304,
267,
1559,
275,
3814,
8,
493,
63,
515,
9,
267,
892,
63,
515,
275,
3877,
63,
3271,
8,
1113,
9,
267,
340,
892,
63,
515,
26,
288,
327,
2654,
570,
370,
314,
3050,
14,
288,
1592,
275,
8692,
342,
288,
1592,
14,
525,
8,
1113,
29,
1113,
12,
3762,
29,
2969,
12,
1676,
63,
4835,
29,
1708,
9,
288,
372,
1559,
14,
4835,
3912,
2378,
347,
2986,
63,
1131,
8,
277,
12,
2986,
63,
765,
12,
2986,
63,
2302,
12,
1584,
29,
403,
12,
1862,
29,
403,
304,
267,
340,
1584,
26,
288,
862,
26,
355,
1177,
275,
4145,
14,
1932,
8,
1246,
63,
2302,
12,
1584,
29,
1725,
12,
666,
29,
1162,
9,
953,
871,
4145,
14,
20349,
26,
355,
291,
14,
793,
360,
705,
297,
298,
6005,
370,
4907,
370,
445,
10112,
1534,
3261,
737,
5041,
16,
5285,
1674,
908,
8,
1246,
63,
2302,
430,
355,
372,
288,
871,
2186,
465,
325,
26,
355,
291,
14,
793,
360,
705,
297,
298,
4276,
19203,
1056,
737,
5041,
16,
93,
356,
469,
17,
5469,
908,
8,
1246,
63,
2302,
12,
325,
430,
355,
372,
398,
340,
440,
1584,
436,
2986,
63,
765,
508,
283,
1932,
356,
288,
327,
8761,
370,
3261,
288,
372,
398,
340,
440,
1584,
436,
2986,
63,
765,
508,
283,
362,
356,
288,
327,
9576,
687,
3261,
288,
862,
26,
355,
1177,
275,
4145,
14,
362,
8,
1246,
63,
2302,
9,
288,
871,
4145,
14,
20349,
26,
355,
291,
14,
793,
360,
705,
297,
298,
6005,
370,
4907,
370,
445,
10112,
1534,
3261,
737,
5041,
16,
5285,
1674,
908,
8,
1246,
63,
2302,
430,
355,
372,
288,
871,
2186,
465,
325,
26,
355,
291,
14,
793,
360,
705,
297,
298,
4276,
19203,
1056,
737,
5041,
16,
93,
356,
469,
17,
5469,
908,
8,
1246,
63,
2302,
12,
325,
430,
355,
372,
267,
372,
1177,
339,
347,
1255,
8,
277,
304,
267,
1613,
8,
35,
10112,
1534,
12,
291,
680,
1065,
342,
267,
340,
291,
14,
589,
365,
488,
26,
288,
372,
398,
327,
2372,
314,
6947,
1059,
687,
1101,
398,
340,
4810,
14,
67,
10112,
1534,
14,
67,
10112,
1534,
63,
1102,
26,
288,
340,
291,
14,
589,
14,
842,
508,
298,
18430,
582,
355,
286,
10112,
1534,
63,
1102,
275,
4810,
14,
67,
10112,
1534,
18430,
14,
67,
10112,
1534,
63,
1102,
288,
916,
291,
14,
589,
14,
842,
508,
298,
15178,
582,
355,
286,
10112,
1534,
63,
1102,
275,
4810,
14,
67,
10112,
1534,
14,
67,
10112,
1534,
63,
1102,
288,
587,
26,
355,
291,
14,
793,
360,
705,
297,
283,
35,
10112,
1534,
1256,
440,
663,
358,
355,
372,
267,
587,
26,
288,
291,
14,
793,
360,
705,
297,
283,
35,
10112,
1534,
4094,
2832,
2494,
358,
288,
372,
398,
340,
4810,
14,
67,
10112,
1534,
14,
67,
10112,
1534,
63,
5540,
26,
288,
2754,
63,
633,
275,
5041,
16,
5995,
1246,
15,
5054,
15,
1733,
15,
4835,
3912,
1370,
908,
8,
67,
10112,
1534,
63,
1102,
9,
288,
11482,
63,
493,
63,
633,
275,
5041,
16,
5995,
1246,
15,
5054,
15,
981,
15,
493,
15,
1370,
908,
8,
67,
10112,
1534,
63,
1102,
9,
288,
2004,
63,
633,
275,
5041,
16,
5995,
1246,
15,
67,
10112,
1534,
15,
1205,
1370,
908
] |
[
961,
570,
365,
1777,
402,
6561,
529,
446,
4178,
921,
5031,
14,
957,
15,
433,
529,
13,
4857,
15,
433,
529,
199,
3,
1666,
314,
570,
283,
3961,
7,
367,
16743,
4983,
14,
199,
199,
893,
26,
272,
492,
4145,
272,
25227,
63,
6780,
51,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
6780,
51,
275,
756,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
646,
13608,
199,
646,
15502,
199,
504,
15073,
492,
5228,
199,
199,
504,
1321,
529,
14,
2330,
14,
6198,
83,
492,
5673,
199,
504,
1321,
529,
14,
1018,
14,
1730,
492,
636,
11676,
363,
199,
504,
1321,
529,
14,
1018,
14,
888,
492,
4094,
199,
504,
1321,
529,
14,
1018,
14,
4659,
492,
8692,
199,
504,
1321,
529,
14,
2330,
14,
1462,
492,
3814,
199,
504,
1321,
529,
14,
1018,
14,
3494,
492,
3877,
63,
3271,
199,
199,
4128,
275,
4094,
342,
199,
199,
3,
1067,
5256,
367,
17481,
1584,
199,
32,
23464,
14,
14237,
199,
318,
1218,
63,
808,
837,
272,
2388,
63,
694,
275,
5549,
14,
11983,
342,
272,
1995,
2388,
63,
694,
272,
5145,
14,
9242,
8,
808,
63,
694,
9,
199,
199,
533,
445,
10112,
1534,
8,
2377,
304,
272,
2088,
275,
283,
67,
10112,
1534,
7,
272,
1369,
275,
283,
17187,
314,
570,
370,
445,
10112,
1534,
428,
10075,
7,
272,
11462,
275,
788,
14743,
297,
283,
1136,
11908,
699,
3441,
418,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
35,
10112,
1534,
12,
291,
2843,
826,
4533,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
83,
297,
2850,
1205,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1002,
21916,
9795,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
70,
297,
2850,
493,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
17187,
3814,
367,
11284,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
82,
297,
2850,
15527,
297,
1595,
534,
1617,
63,
2052,
297,
1720,
534,
1322,
14760,
21916,
402,
3814,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
68,
297,
2850,
27557,
297,
730,
29,
442,
12,
1720,
534,
1002,
1006,
18110,
1915,
428,
1889,
687,
2120,
1305,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
77,
297,
2850,
6744,
297,
221,
1720,
534,
985,
402,
18722,
503,
1006,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
80,
297,
2850,
2491,
297,
221,
1720,
534,
5446,
282,
2559,
730,
370,
1255,
358,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
79,
297,
2850,
1419,
297,
221,
1720,
534,
4558,
315,
314,
1475,
298,
4687,
278,
1064,
1220,
29,
5066,
12,
889,
14864,
29,
5066,
9008,
267,
291,
14,
2087,
14,
525,
63,
2094,
3654,
73,
297,
2850,
842,
297,
1720,
534,
5446,
282,
445,
10112,
1534,
1256,
358,
2378,
347,
1050,
63,
493,
8,
277,
12,
570,
63,
515,
12,
3762,
12,
1676,
304,
267,
1559,
275,
3814,
8,
493,
63,
515,
9,
267,
892,
63,
515,
275,
3877,
63,
3271,
8,
1113,
9,
267,
340,
892,
63,
515,
26,
288,
327,
2654,
570,
370,
314,
3050,
14,
288,
1592,
275,
8692,
342,
288,
1592,
14,
525,
8,
1113,
29,
1113,
12,
3762,
29,
2969,
12,
1676,
63,
4835,
29,
1708,
9,
288,
372,
1559,
14,
4835,
3912,
2378,
347,
2986,
63,
1131,
8,
277,
12,
2986,
63,
765,
12,
2986,
63,
2302,
12,
1584,
29,
403,
12,
1862,
29,
403,
304,
267,
340,
1584,
26,
288,
862,
26,
355,
1177,
275,
4145,
14,
1932,
8,
1246,
63,
2302,
12,
1584,
29,
1725,
12,
666,
29,
1162,
9,
953,
871,
4145,
14,
20349,
26,
355,
291,
14,
793,
360,
705,
297,
298,
6005,
370,
4907,
370,
445,
10112,
1534,
3261,
737,
5041,
16,
5285,
1674,
908,
8,
1246,
63,
2302,
430,
355,
372,
288,
871,
2186,
465,
325,
26,
355,
291,
14,
793,
360,
705,
297,
298,
4276,
19203,
1056,
737,
5041,
16,
93,
356,
469,
17,
5469,
908,
8,
1246,
63,
2302,
12,
325,
430,
355,
372,
398,
340,
440,
1584,
436,
2986,
63,
765,
508,
283,
1932,
356,
288,
327,
8761,
370,
3261,
288,
372,
398,
340,
440,
1584,
436,
2986,
63,
765,
508,
283,
362,
356,
288,
327,
9576,
687,
3261,
288,
862,
26,
355,
1177,
275,
4145,
14,
362,
8,
1246,
63,
2302,
9,
288,
871,
4145,
14,
20349,
26,
355,
291,
14,
793,
360,
705,
297,
298,
6005,
370,
4907,
370,
445,
10112,
1534,
3261,
737,
5041,
16,
5285,
1674,
908,
8,
1246,
63,
2302,
430,
355,
372,
288,
871,
2186,
465,
325,
26,
355,
291,
14,
793,
360,
705,
297,
298,
4276,
19203,
1056,
737,
5041,
16,
93,
356,
469,
17,
5469,
908,
8,
1246,
63,
2302,
12,
325,
430,
355,
372,
267,
372,
1177,
339,
347,
1255,
8,
277,
304,
267,
1613,
8,
35,
10112,
1534,
12,
291,
680,
1065,
342,
267,
340,
291,
14,
589,
365,
488,
26,
288,
372,
398,
327,
2372,
314,
6947,
1059,
687,
1101,
398,
340,
4810,
14,
67,
10112,
1534,
14,
67,
10112,
1534,
63,
1102,
26,
288,
340,
291,
14,
589,
14,
842,
508,
298,
18430,
582,
355,
286,
10112,
1534,
63,
1102,
275,
4810,
14,
67,
10112,
1534,
18430,
14,
67,
10112,
1534,
63,
1102,
288,
916,
291,
14,
589,
14,
842,
508,
298,
15178,
582,
355,
286,
10112,
1534,
63,
1102,
275,
4810,
14,
67,
10112,
1534,
14,
67,
10112,
1534,
63,
1102,
288,
587,
26,
355,
291,
14,
793,
360,
705,
297,
283,
35,
10112,
1534,
1256,
440,
663,
358,
355,
372,
267,
587,
26,
288,
291,
14,
793,
360,
705,
297,
283,
35,
10112,
1534,
4094,
2832,
2494,
358,
288,
372,
398,
340,
4810,
14,
67,
10112,
1534,
14,
67,
10112,
1534,
63,
5540,
26,
288,
2754,
63,
633,
275,
5041,
16,
5995,
1246,
15,
5054,
15,
1733,
15,
4835,
3912,
1370,
908,
8,
67,
10112,
1534,
63,
1102,
9,
288,
11482,
63,
493,
63,
633,
275,
5041,
16,
5995,
1246,
15,
5054,
15,
981,
15,
493,
15,
1370,
908,
8,
67,
10112,
1534,
63,
1102,
9,
288,
2004,
63,
633,
275,
5041,
16,
5995,
1246,
15,
67,
10112,
1534,
15,
1205,
1370,
908,
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,
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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
] |
izonder/intellij-community
|
python/lib/Lib/site-packages/django/contrib/localflavor/tr/forms.py
|
71
|
3415
|
"""
TR-specific Form helpers
"""
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select, CharField
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
phone_digits_re = re.compile(r'^(\+90|0)? ?(([1-9]\d{2})|\([1-9]\d{2}\)) ?([2-9]\d{2} ?\d{2} ?\d{2})$')
class TRPostalCodeField(RegexField):
default_error_messages = {
'invalid': _(u'Enter a postal code in the format XXXXX.'),
}
def __init__(self, *args, **kwargs):
super(TRPostalCodeField, self).__init__(r'^\d{5}$',
max_length=5, min_length=5, *args, **kwargs)
def clean(self, value):
value = super(TRPostalCodeField, self).clean(value)
if value in EMPTY_VALUES:
return u''
if len(value) != 5:
raise ValidationError(self.error_messages['invalid'])
province_code = int(value[:2])
if province_code == 0 or province_code > 81:
raise ValidationError(self.error_messages['invalid'])
return value
class TRPhoneNumberField(CharField):
default_error_messages = {
'invalid': _(u'Phone numbers must be in 0XXX XXX XXXX format.'),
}
def clean(self, value):
super(TRPhoneNumberField, self).clean(value)
if value in EMPTY_VALUES:
return u''
value = re.sub('(\(|\)|\s+)', '', smart_unicode(value))
m = phone_digits_re.search(value)
if m:
return u'%s%s' % (m.group(2), m.group(4))
raise ValidationError(self.error_messages['invalid'])
class TRIdentificationNumberField(Field):
"""
A Turkey Identification Number number.
See: http://tr.wikipedia.org/wiki/T%C3%BCrkiye_Cumhuriyeti_Kimlik_Numaras%C4%B1
Checks the following rules to determine whether the number is valid:
* The number is 11-digits.
* First digit is not 0.
* Conforms to the following two formula:
(sum(1st, 3rd, 5th, 7th, 9th)*7 - sum(2nd,4th,6th,8th)) % 10 = 10th digit
sum(1st to 10th) % 10 = 11th digit
"""
default_error_messages = {
'invalid': _(u'Enter a valid Turkish Identification number.'),
'not_11': _(u'Turkish Identification number must be 11 digits.'),
}
def clean(self, value):
super(TRIdentificationNumberField, self).clean(value)
if value in EMPTY_VALUES:
return u''
if len(value) != 11:
raise ValidationError(self.error_messages['not_11'])
if not re.match(r'^\d{11}$', value):
raise ValidationError(self.error_messages['invalid'])
if int(value[0]) == 0:
raise ValidationError(self.error_messages['invalid'])
chksum = (sum([int(value[i]) for i in xrange(0,9,2)])*7-
sum([int(value[i]) for i in xrange(1,9,2)])) % 10
if chksum != int(value[9]) or \
(sum([int(value[i]) for i in xrange(10)]) % 10) != int(value[10]):
raise ValidationError(self.error_messages['invalid'])
return value
class TRProvinceSelect(Select):
"""
A Select widget that uses a list of provinces in Turkey as its choices.
"""
def __init__(self, attrs=None):
from tr_provinces import PROVINCE_CHOICES
super(TRProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES)
|
apache-2.0
|
[
624,
199,
1766,
13,
6100,
8204,
10897,
199,
624,
199,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
5024,
12,
12939,
792,
12,
9496,
12,
12064,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
646,
295,
199,
199,
9339,
63,
7022,
63,
264,
275,
295,
14,
2014,
8,
82,
31344,
11,
2710,
92,
16,
5547,
5805,
27123,
17,
13,
25,
7272,
68,
91,
18,
1552,
6113,
779,
17,
13,
25,
7272,
68,
91,
18,
4988,
430,
5805,
779,
18,
13,
25,
7272,
68,
91,
18,
93,
5805,
60,
68,
91,
18,
93,
5805,
60,
68,
91,
18,
1552,
9988,
199,
199,
533,
9074,
6564,
279,
3034,
792,
8,
5103,
792,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
8038,
272,
789,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1766,
6564,
279,
3034,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
21,
19204,
288,
1390,
63,
1267,
29,
21,
12,
1748,
63,
1267,
29,
21,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
574,
275,
1613,
8,
1766,
6564,
279,
3034,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
340,
822,
8,
585,
9,
1137,
959,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
24074,
2855,
63,
600,
275,
1109,
8,
585,
1491,
18,
566,
267,
340,
24074,
2855,
63,
600,
508,
378,
503,
24074,
2855,
63,
600,
690,
19071,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
421,
199,
533,
9074,
25640,
792,
8,
2183,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
15199,
5579,
1471,
506,
315,
378,
13933,
5787,
5787,
56,
1475,
8038,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
1766,
25640,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
574,
275,
295,
14,
954,
360,
2961,
8,
6113,
9,
6113,
83,
14705,
3260,
11179,
63,
2975,
8,
585,
430,
267,
333,
275,
14617,
63,
7022,
63,
264,
14,
1733,
8,
585,
9,
267,
340,
333,
26,
288,
372,
399,
5956,
83,
5,
83,
7,
450,
334,
77,
14,
923,
8,
18,
395,
333,
14,
923,
8,
20,
430,
267,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
199,
199,
533,
377,
6129,
24926,
3259,
792,
8,
792,
304,
272,
408,
272,
437,
377,
300,
498,
473,
24926,
4860,
1329,
14,
199,
198,
9295,
26,
1455,
921,
454,
14,
13961,
14,
1308,
15,
6797,
15,
52,
5,
35,
19,
5,
6265,
82,
8810,
8048,
63,
35,
453,
72,
2302,
8048,
280,
63,
43,
1017,
317,
75,
63,
5667,
285,
305,
5,
35,
20,
5,
34,
17,
339,
13813,
314,
2569,
4713,
370,
6705,
3775,
314,
1329,
365,
1686,
26,
398,
627,
710,
1329,
365,
4119,
13,
7022,
14,
267,
627,
7758,
10964,
365,
440,
378,
14,
267,
627,
1448,
3351,
370,
314,
2569,
2877,
15723,
26,
881,
334,
1838,
8,
17,
270,
12,
650,
6883,
12,
959,
273,
12,
1520,
273,
12,
1749,
273,
3342,
23,
446,
3089,
8,
18,
977,
12,
20,
273,
12,
22,
273,
12,
24,
273,
430,
450,
1616,
275,
1616,
273,
10964,
881,
3089,
8,
17,
270,
370,
1616,
273,
9,
450,
1616,
275,
4119,
273,
10964,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
1686,
377,
300,
75,
2453,
473,
24926,
1329,
8038,
267,
283,
1397,
63,
845,
356,
12561,
85,
7,
27438,
75,
2453,
473,
24926,
1329,
1471,
506,
4119,
7576,
8038,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
1766,
41,
24926,
3259,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
340,
822,
8,
585,
9,
1137,
4119,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
1397,
63,
845,
1105,
267,
340,
440,
295,
14,
1431,
8,
82,
15542,
68,
91,
845,
19204,
574,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
340,
1109,
8,
585,
59,
16,
566,
508,
378,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
26979,
1838,
275,
334,
1838,
779,
442,
8,
585,
59,
73,
566,
367,
284,
315,
4945,
8,
16,
12,
25,
12,
18,
3948,
10,
23,
13,
1871,
3515,
3089,
779,
442,
8,
585,
59,
73,
566,
367,
284,
315,
4945,
8,
17,
12,
25,
12,
18,
19563,
450,
1616,
267,
340,
26979,
1838,
1137,
1109,
8,
585,
59,
25,
566,
503,
971,
1779,
334,
1838,
779,
442,
8,
585,
59,
73,
566,
367,
284,
315,
4945,
8,
709,
3948,
450,
1616,
9,
1137,
1109,
8,
585,
59,
709,
4682,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
199,
199,
533,
9074,
919,
86,
2855,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
557,
11908,
823,
315,
377,
300,
498,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
5651,
63,
496,
11908,
823,
492,
3611,
54,
568,
2089,
63,
16236,
267,
1613,
8,
1766,
919,
86,
2855,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
2514,
54,
568,
2089,
63,
16236,
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
] |
[
199,
1766,
13,
6100,
8204,
10897,
199,
624,
199,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
5024,
12,
12939,
792,
12,
9496,
12,
12064,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
2975,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
646,
295,
199,
199,
9339,
63,
7022,
63,
264,
275,
295,
14,
2014,
8,
82,
31344,
11,
2710,
92,
16,
5547,
5805,
27123,
17,
13,
25,
7272,
68,
91,
18,
1552,
6113,
779,
17,
13,
25,
7272,
68,
91,
18,
4988,
430,
5805,
779,
18,
13,
25,
7272,
68,
91,
18,
93,
5805,
60,
68,
91,
18,
93,
5805,
60,
68,
91,
18,
1552,
9988,
199,
199,
533,
9074,
6564,
279,
3034,
792,
8,
5103,
792,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
2963,
279,
1233,
315,
314,
1475,
5787,
2483,
8038,
272,
789,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1766,
6564,
279,
3034,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
21,
19204,
288,
1390,
63,
1267,
29,
21,
12,
1748,
63,
1267,
29,
21,
12,
627,
589,
12,
1011,
958,
9,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
574,
275,
1613,
8,
1766,
6564,
279,
3034,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
340,
822,
8,
585,
9,
1137,
959,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
24074,
2855,
63,
600,
275,
1109,
8,
585,
1491,
18,
566,
267,
340,
24074,
2855,
63,
600,
508,
378,
503,
24074,
2855,
63,
600,
690,
19071,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
421,
199,
533,
9074,
25640,
792,
8,
2183,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
15199,
5579,
1471,
506,
315,
378,
13933,
5787,
5787,
56,
1475,
8038,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
1766,
25640,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
574,
275,
295,
14,
954,
360,
2961,
8,
6113,
9,
6113,
83,
14705,
3260,
11179,
63,
2975,
8,
585,
430,
267,
333,
275,
14617,
63,
7022,
63,
264,
14,
1733,
8,
585,
9,
267,
340,
333,
26,
288,
372,
399,
5956,
83,
5,
83,
7,
450,
334,
77,
14,
923,
8,
18,
395,
333,
14,
923,
8,
20,
430,
267,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
199,
199,
533,
377,
6129,
24926,
3259,
792,
8,
792,
304,
272,
408,
272,
437,
377,
300,
498,
473,
24926,
4860,
1329,
14,
199,
198,
9295,
26,
1455,
921,
454,
14,
13961,
14,
1308,
15,
6797,
15,
52,
5,
35,
19,
5,
6265,
82,
8810,
8048,
63,
35,
453,
72,
2302,
8048,
280,
63,
43,
1017,
317,
75,
63,
5667,
285,
305,
5,
35,
20,
5,
34,
17,
339,
13813,
314,
2569,
4713,
370,
6705,
3775,
314,
1329,
365,
1686,
26,
398,
627,
710,
1329,
365,
4119,
13,
7022,
14,
267,
627,
7758,
10964,
365,
440,
378,
14,
267,
627,
1448,
3351,
370,
314,
2569,
2877,
15723,
26,
881,
334,
1838,
8,
17,
270,
12,
650,
6883,
12,
959,
273,
12,
1520,
273,
12,
1749,
273,
3342,
23,
446,
3089,
8,
18,
977,
12,
20,
273,
12,
22,
273,
12,
24,
273,
430,
450,
1616,
275,
1616,
273,
10964,
881,
3089,
8,
17,
270,
370,
1616,
273,
9,
450,
1616,
275,
4119,
273,
10964,
272,
408,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
12561,
85,
7,
8468,
282,
1686,
377,
300,
75,
2453,
473,
24926,
1329,
8038,
267,
283,
1397,
63,
845,
356,
12561,
85,
7,
27438,
75,
2453,
473,
24926,
1329,
1471,
506,
4119,
7576,
8038,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
1766,
41,
24926,
3259,
792,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
267,
340,
822,
8,
585,
9,
1137,
4119,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
1397,
63,
845,
1105,
267,
340,
440,
295,
14,
1431,
8,
82,
15542,
68,
91,
845,
19204,
574,
304,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
340,
1109,
8,
585,
59,
16,
566,
508,
378,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
26979,
1838,
275,
334,
1838,
779,
442,
8,
585,
59,
73,
566,
367,
284,
315,
4945,
8,
16,
12,
25,
12,
18,
3948,
10,
23,
13,
1871,
3515,
3089,
779,
442,
8,
585,
59,
73,
566,
367,
284,
315,
4945,
8,
17,
12,
25,
12,
18,
19563,
450,
1616,
267,
340,
26979,
1838,
1137,
1109,
8,
585,
59,
25,
566,
503,
971,
1779,
334,
1838,
779,
442,
8,
585,
59,
73,
566,
367,
284,
315,
4945,
8,
709,
3948,
450,
1616,
9,
1137,
1109,
8,
585,
59,
709,
4682,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
372,
574,
199,
199,
533,
9074,
919,
86,
2855,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
557,
11908,
823,
315,
377,
300,
498,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
5651,
63,
496,
11908,
823,
492,
3611,
54,
568,
2089,
63,
16236,
267,
1613,
8,
1766,
919,
86,
2855,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
2514,
54,
568,
2089,
63,
16236,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
garydonovan/google-maps-services-python
|
googlemaps/client.py
|
6
|
13027
|
#
# Copyright 2014 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.
#
"""
Core client functionality, common across all API requests (including performing
HTTP requests).
"""
import base64
import collections
from datetime import datetime
from datetime import timedelta
import hashlib
import hmac
import requests
import random
import time
import googlemaps
try: # Python 3
from urllib.parse import urlencode
except ImportError: # Python 2
from urllib import urlencode
_USER_AGENT = "GoogleGeoApiClientPython/%s" % googlemaps.__version__
_DEFAULT_BASE_URL = "https://maps.googleapis.com"
_RETRIABLE_STATUSES = set([500, 503, 504])
class Client(object):
"""Performs requests to the Google Maps API web services."""
def __init__(self, key=None, client_id=None, client_secret=None,
timeout=None, connect_timeout=None, read_timeout=None,
retry_timeout=60, requests_kwargs=None,
queries_per_second=10):
"""
:param key: Maps API key. Required, unless "client_id" and
"client_secret" are set.
:type key: string
:param client_id: (for Maps API for Work customers) Your client ID.
:type client_id: string
:param client_secret: (for Maps API for Work customers) Your client
secret (base64 encoded).
:type client_secret: string
:param timeout: Combined connect and read timeout for HTTP requests, in
seconds. Specify "None" for no timeout.
:type timeout: int
:param connect_timeout: Connection timeout for HTTP requests, in
seconds. You should specify read_timeout in addition to this option.
Note that this requires requests >= 2.4.0.
:type connect_timeout: int
:param read_timeout: Read timeout for HTTP requests, in
seconds. You should specify connect_timeout in addition to this
option. Note that this requires requests >= 2.4.0.
:type read_timeout: int
:param retry_timeout: Timeout across multiple retriable requests, in
seconds.
:type retry_timeout: int
:param queries_per_second: Number of queries per second permitted.
If the rate limit is reached, the client will sleep for the
appropriate amount of time before it runs the current query.
:type queries_per_second: int
:raises ValueError: when either credentials are missing, incomplete
or invalid.
:raises NotImplementedError: if connect_timeout and read_timeout are
used with a version of requests prior to 2.4.0.
:param requests_kwargs: Extra keyword arguments for the requests
library, which among other things allow for proxy auth to be
implemented. See the official requests docs for more info:
http://docs.python-requests.org/en/latest/api/#main-interface
:type requests_kwargs: dict
"""
if not key and not (client_secret and client_id):
raise ValueError("Must provide API key or enterprise credentials "
"when creating client.")
if key and not key.startswith("AIza"):
raise ValueError("Invalid API key provided.")
self.key = key
if timeout and (connect_timeout or read_timeout):
raise ValueError("Specify either timeout, or connect_timeout " +
"and read_timeout")
if connect_timeout and read_timeout:
# Check that the version of requests is >= 2.4.0
chunks = requests.__version__.split(".")
if chunks[0] < 2 or (chunks[0] == 2 and chunks[1] < 4):
raise NotImplementedError("Connect/Read timeouts require "
"requests v2.4.0 or higher")
self.timeout = (connect_timeout, read_timeout)
else:
self.timeout = timeout
self.client_id = client_id
self.client_secret = client_secret
self.retry_timeout = timedelta(seconds=retry_timeout)
self.requests_kwargs = requests_kwargs or {}
self.requests_kwargs.update({
"headers": {"User-Agent": _USER_AGENT},
"timeout": self.timeout,
"verify": True, # NOTE(cbro): verify SSL certs.
})
self.sent_times = collections.deque("", queries_per_second)
def _get(self, url, params, first_request_time=None, retry_counter=0,
base_url=_DEFAULT_BASE_URL, accepts_clientid=True, extract_body=None):
"""Performs HTTP GET request with credentials, returning the body as
JSON.
:param url: URL path for the request. Should begin with a slash.
:type url: string
:param params: HTTP GET parameters.
:type params: dict or list of key/value tuples
:param first_request_time: The time of the first request (None if no retries
have occurred).
:type first_request_time: datetime.datetime
:param retry_counter: The number of this retry, or zero for first attempt.
:type retry_counter: int
:param base_url: The base URL for the request. Defaults to the Maps API
server. Should not have a trailing slash.
:type base_url: string
:param accepts_clientid: Whether this call supports the client/signature
params. Some APIs require API keys (e.g. Roads).
:type accepts_clientid: bool
:param extract_body: A function that extracts the body from the request.
If the request was not successful, the function should raise a
googlemaps.HTTPError or googlemaps.ApiError as appropriate.
:type extract_body: function
:raises ApiError: when the API returns an error.
:raises Timeout: if the request timed out.
:raises TransportError: when something went wrong while trying to
exceute a request.
"""
if not first_request_time:
first_request_time = datetime.now()
elapsed = datetime.now() - first_request_time
if elapsed > self.retry_timeout:
raise googlemaps.exceptions.Timeout()
if retry_counter > 0:
# 0.5 * (1.5 ^ i) is an increased sleep time of 1.5x per iteration,
# starting at 0.5s when retry_counter=0. The first retry will occur
# at 1, so subtract that first.
delay_seconds = 0.5 * 1.5 ** (retry_counter - 1)
# Jitter this value by 50% and pause.
time.sleep(delay_seconds * (random.random() + 0.5))
authed_url = self._generate_auth_url(url, params, accepts_clientid)
try:
resp = requests.get(base_url + authed_url, **self.requests_kwargs)
except requests.exceptions.Timeout:
raise googlemaps.exceptions.Timeout()
except Exception as e:
raise googlemaps.exceptions.TransportError(e)
if resp.status_code in _RETRIABLE_STATUSES:
# Retry request.
return self._get(url, params, first_request_time, retry_counter + 1,
base_url, accepts_clientid, extract_body)
# Check if the time of the nth previous query (where n is queries_per_second)
# is under a second ago - if so, sleep for the difference.
if self.sent_times and len(self.sent_times) == self.sent_times.maxlen:
elapsed_since_earliest = time.time() - self.sent_times[0]
if elapsed_since_earliest < 1:
time.sleep(1 - elapsed_since_earliest)
try:
if extract_body:
result = extract_body(resp)
else:
result = self._get_body(resp)
self.sent_times.append(time.time())
return result
except googlemaps.exceptions._RetriableRequest:
# Retry request.
return self._get(url, params, first_request_time, retry_counter + 1,
base_url, accepts_clientid, extract_body)
def _get_body(self, resp):
if resp.status_code != 200:
raise googlemaps.exceptions.HTTPError(resp.status_code)
body = resp.json()
api_status = body["status"]
if api_status == "OK" or api_status == "ZERO_RESULTS":
return body
if api_status == "OVER_QUERY_LIMIT":
raise googlemaps.exceptions._RetriableRequest()
if "error_message" in body:
raise googlemaps.exceptions.ApiError(api_status,
body["error_message"])
else:
raise googlemaps.exceptions.ApiError(api_status)
def _generate_auth_url(self, path, params, accepts_clientid):
"""Returns the path and query string portion of the request URL, first
adding any necessary parameters.
:param path: The path portion of the URL.
:type path: string
:param params: URL parameters.
:type params: dict or list of key/value tuples
:rtype: string
"""
# Deterministic ordering through sorting by key.
# Useful for tests, and in the future, any caching.
if type(params) is dict:
params = sorted(params.items())
else:
params = params[:] # Take a copy.
if accepts_clientid and self.client_id and self.client_secret:
params.append(("client", self.client_id))
path = "?".join([path, urlencode_params(params)])
sig = sign_hmac(self.client_secret, path)
return path + "&signature=" + sig
if self.key:
params.append(("key", self.key))
return path + "?" + urlencode_params(params)
raise ValueError("Must provide API key for this API. It does not accept "
"enterprise credentials.")
from googlemaps.directions import directions
from googlemaps.distance_matrix import distance_matrix
from googlemaps.elevation import elevation
from googlemaps.elevation import elevation_along_path
from googlemaps.geocoding import geocode
from googlemaps.geocoding import reverse_geocode
from googlemaps.timezone import timezone
from googlemaps.roads import snap_to_roads
from googlemaps.roads import speed_limits
from googlemaps.roads import snapped_speed_limits
Client.directions = directions
Client.distance_matrix = distance_matrix
Client.elevation = elevation
Client.elevation_along_path = elevation_along_path
Client.geocode = geocode
Client.reverse_geocode = reverse_geocode
Client.timezone = timezone
Client.snap_to_roads = snap_to_roads
Client.speed_limits = speed_limits
Client.snapped_speed_limits = snapped_speed_limits
def sign_hmac(secret, payload):
"""Returns a base64-encoded HMAC-SHA1 signature of a given string.
:param secret: The key used for the signature, base64 encoded.
:type secret: string
:param payload: The payload to sign.
:type payload: string
:rtype: string
"""
payload = payload.encode('ascii', 'strict')
secret = secret.encode('ascii', 'strict')
sig = hmac.new(base64.urlsafe_b64decode(secret), payload, hashlib.sha1)
out = base64.urlsafe_b64encode(sig.digest())
return out.decode('utf-8')
def urlencode_params(params):
"""URL encodes the parameters.
:param params: The parameters
:type params: list of key/value tuples.
"""
# urlencode does not handle unicode strings in Python 2.
# Firstly, normalize the values so they get encoded correctly.
params = [(key, normalize_for_urlencode(val)) for key, val in params]
# Secondly, unquote unreserved chars which are incorrectly quoted
# by urllib.urlencode, causing invalid auth signatures. See GH #72
# for more info.
return requests.utils.unquote_unreserved(urlencode(params))
try:
unicode
# NOTE(cbro): `unicode` was removed in Python 3. In Python 3, NameError is
# raised here, and caught below.
def normalize_for_urlencode(value):
"""(Python 2) Converts the value to a `str` (raw bytes)."""
if isinstance(value, unicode):
return value.encode('utf8')
if isinstance(value, str):
return value
return normalize_for_urlencode(str(value))
except NameError:
def normalize_for_urlencode(value):
"""(Python 3) No-op."""
# urlencode in Python 3 handles all the types we are passing it.
return value
|
apache-2.0
|
[
3,
199,
3,
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
199,
3,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
199,
3,
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,
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,
1334,
199,
3,
314,
844,
14,
199,
3,
199,
199,
624,
199,
5402,
1890,
9330,
12,
2863,
9371,
1006,
3261,
4145,
334,
15768,
19203,
199,
2856,
4145,
680,
199,
624,
199,
199,
646,
1300,
772,
199,
646,
5055,
199,
504,
2197,
492,
2197,
199,
504,
2197,
492,
6871,
199,
646,
8337,
199,
646,
20330,
199,
646,
4145,
199,
646,
2196,
199,
646,
900,
199,
199,
646,
6233,
8919,
199,
199,
893,
26,
327,
2018,
650,
272,
687,
4011,
14,
1122,
492,
16511,
199,
2590,
3545,
26,
327,
2018,
499,
272,
687,
4011,
492,
16511,
421,
199,
63,
3791,
63,
14565,
275,
298,
13266,
10748,
7394,
3041,
4718,
3149,
83,
2,
450,
6233,
8919,
855,
1023,
363,
199,
63,
3472,
63,
5825,
63,
2632,
275,
298,
2859,
921,
8919,
14,
17533,
14,
957,
2,
199,
199,
63,
7341,
6129,
2617,
63,
6305,
654,
275,
663,
779,
5783,
12,
24046,
12,
959,
966,
566,
199,
199,
533,
6810,
8,
785,
304,
272,
408,
2623,
3351,
4145,
370,
314,
4475,
23673,
3261,
3330,
8500,
1041,
339,
347,
636,
826,
721,
277,
12,
790,
29,
403,
12,
1890,
63,
344,
29,
403,
12,
1890,
63,
4731,
29,
403,
12,
326,
2653,
29,
403,
12,
4907,
63,
2593,
29,
403,
12,
1586,
63,
2593,
29,
403,
12,
326,
7269,
63,
2593,
29,
2259,
12,
4145,
63,
958,
29,
403,
12,
326,
9212,
63,
529,
63,
4375,
29,
709,
304,
267,
408,
267,
520,
635,
790,
26,
23673,
3261,
790,
14,
11105,
12,
7444,
298,
1258,
63,
344,
2,
436,
288,
298,
1258,
63,
4731,
2,
787,
663,
14,
267,
520,
466,
790,
26,
1059,
398,
520,
635,
1890,
63,
344,
26,
334,
509,
23673,
3261,
367,
9361,
286,
28078,
9,
19519,
1890,
2870,
14,
267,
520,
466,
1890,
63,
344,
26,
1059,
398,
520,
635,
1890,
63,
4731,
26,
334,
509,
23673,
3261,
367,
9361,
286,
28078,
9,
19519,
1890,
288,
7565,
334,
1095,
772,
5737,
680,
267,
520,
466,
1890,
63,
4731,
26,
1059,
398,
520,
635,
2653,
26,
22170,
379,
4907,
436,
1586,
2653,
367,
3101,
4145,
12,
315,
288,
4696,
14,
13327,
298,
403,
2,
367,
949,
2653,
14,
267,
520,
466,
2653,
26,
1109,
398,
520,
635,
4907,
63,
2593,
26,
8113,
2653,
367,
3101,
4145,
12,
315,
288,
4696,
14,
2047,
1077,
4165,
1586,
63,
2593,
315,
10234,
370,
642,
945,
14,
288,
3390,
626,
642,
5074,
4145,
2356,
499,
14,
20,
14,
16,
14,
267,
520,
466,
4907,
63,
2593,
26,
1109,
398,
520,
635,
1586,
63,
2593,
26,
5574,
2653,
367,
3101,
4145,
12,
315,
288,
4696,
14,
2047,
1077,
4165,
4907,
63,
2593,
315,
10234,
370,
642,
288,
945,
14,
3390,
626,
642,
5074,
4145,
2356,
499,
14,
20,
14,
16,
14,
267,
520,
466,
1586,
63,
2593,
26,
1109,
398,
520,
635,
7269,
63,
2593,
26,
12878,
9371,
3663,
4444,
461,
4145,
12,
315,
288,
4696,
14,
267,
520,
466,
7269,
63,
2593,
26,
1109,
398,
520,
635,
9212,
63,
529,
63,
4375,
26,
4860,
402,
9212,
1126,
3499,
8211,
14,
288,
982,
314,
6634,
2304,
365,
13075,
12,
314,
1890,
911,
9435,
367,
314,
288,
5827,
5982,
402,
900,
2544,
652,
7858,
314,
1453,
1827,
14,
267,
520,
466,
9212,
63,
529,
63,
4375,
26,
1109,
398,
520,
3536,
1722,
26,
1380,
1902,
6235,
787,
4124,
12,
17110,
288,
503,
3866,
14,
267,
520,
3536,
4279,
26,
340,
4907,
63,
2593,
436,
1586,
63,
2593,
787,
288,
1202,
543,
282,
1015,
402,
4145,
6791,
370,
499,
14,
20,
14,
16,
14,
398,
520,
635,
4145,
63,
958,
26,
11177,
4252,
2368,
367,
314,
4145,
288,
3555,
12,
1314,
16885,
1163,
7645,
2040,
367,
4566,
1790,
370,
506,
288,
6366,
14,
1666,
314,
25410,
4145,
9149,
367,
1655,
2256,
26,
288,
1455,
921,
4757,
14,
1548,
13,
6615,
14,
1308,
15,
287,
15,
7410,
15,
1246,
12645,
973,
13,
3266,
267,
520,
466,
4145,
63,
958,
26,
1211,
398,
408,
267,
340,
440,
790,
436,
440,
334,
1258,
63,
4731,
436,
1890,
63,
344,
304,
288,
746,
1722,
480,
13757,
5647,
3261,
790,
503,
9509,
13219,
6235,
298,
2490,
298,
6526,
6425,
1890,
2685,
398,
340,
790,
436,
440,
790,
14,
2460,
480,
7730,
8076,
2349,
288,
746,
1722,
480,
3364,
3261,
790,
2741,
2685,
398,
291,
14,
498,
275,
790,
398,
340,
2653,
436,
334,
2242,
63,
2593,
503,
1586,
63,
2593,
304,
288,
746,
1722,
480,
17768,
1902,
2653,
12,
503,
4907,
63,
2593,
298,
435,
2490,
298,
460,
1586,
63,
2593,
531,
398,
340,
4907,
63,
2593,
436,
1586,
63,
2593,
26,
288,
327,
2670,
626,
314,
1015,
402,
4145,
365,
2356,
499,
14,
20,
14,
16,
288,
8291,
275,
4145,
855,
1023,
4343,
1294,
15857,
288,
340,
8291,
59,
16,
61,
665,
499,
503,
334,
10660,
59,
16,
61,
508,
499,
436,
8291,
59,
17,
61,
665,
841,
304,
355,
746,
4279,
480,
8631,
15,
3284,
25870,
4409,
298,
5101,
298,
6615,
373,
18,
14,
20,
14,
16,
503,
10948,
531,
288,
291,
14,
2593,
275,
334,
2242,
63,
2593,
12,
1586,
63,
2593,
9,
267,
587,
26,
288,
291,
14,
2593,
275,
2653,
398,
291,
14,
1258,
63,
344,
275,
1890,
63,
344,
267,
291,
14,
1258,
63,
4731,
275,
1890,
63,
4731,
267,
291,
14,
7154,
63,
2593,
275,
6871,
8,
4515,
29,
7154,
63
] |
[
199,
3,
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
199,
3,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
199,
3,
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,
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,
1334,
199,
3,
314,
844,
14,
199,
3,
199,
199,
624,
199,
5402,
1890,
9330,
12,
2863,
9371,
1006,
3261,
4145,
334,
15768,
19203,
199,
2856,
4145,
680,
199,
624,
199,
199,
646,
1300,
772,
199,
646,
5055,
199,
504,
2197,
492,
2197,
199,
504,
2197,
492,
6871,
199,
646,
8337,
199,
646,
20330,
199,
646,
4145,
199,
646,
2196,
199,
646,
900,
199,
199,
646,
6233,
8919,
199,
199,
893,
26,
327,
2018,
650,
272,
687,
4011,
14,
1122,
492,
16511,
199,
2590,
3545,
26,
327,
2018,
499,
272,
687,
4011,
492,
16511,
421,
199,
63,
3791,
63,
14565,
275,
298,
13266,
10748,
7394,
3041,
4718,
3149,
83,
2,
450,
6233,
8919,
855,
1023,
363,
199,
63,
3472,
63,
5825,
63,
2632,
275,
298,
2859,
921,
8919,
14,
17533,
14,
957,
2,
199,
199,
63,
7341,
6129,
2617,
63,
6305,
654,
275,
663,
779,
5783,
12,
24046,
12,
959,
966,
566,
199,
199,
533,
6810,
8,
785,
304,
272,
408,
2623,
3351,
4145,
370,
314,
4475,
23673,
3261,
3330,
8500,
1041,
339,
347,
636,
826,
721,
277,
12,
790,
29,
403,
12,
1890,
63,
344,
29,
403,
12,
1890,
63,
4731,
29,
403,
12,
326,
2653,
29,
403,
12,
4907,
63,
2593,
29,
403,
12,
1586,
63,
2593,
29,
403,
12,
326,
7269,
63,
2593,
29,
2259,
12,
4145,
63,
958,
29,
403,
12,
326,
9212,
63,
529,
63,
4375,
29,
709,
304,
267,
408,
267,
520,
635,
790,
26,
23673,
3261,
790,
14,
11105,
12,
7444,
298,
1258,
63,
344,
2,
436,
288,
298,
1258,
63,
4731,
2,
787,
663,
14,
267,
520,
466,
790,
26,
1059,
398,
520,
635,
1890,
63,
344,
26,
334,
509,
23673,
3261,
367,
9361,
286,
28078,
9,
19519,
1890,
2870,
14,
267,
520,
466,
1890,
63,
344,
26,
1059,
398,
520,
635,
1890,
63,
4731,
26,
334,
509,
23673,
3261,
367,
9361,
286,
28078,
9,
19519,
1890,
288,
7565,
334,
1095,
772,
5737,
680,
267,
520,
466,
1890,
63,
4731,
26,
1059,
398,
520,
635,
2653,
26,
22170,
379,
4907,
436,
1586,
2653,
367,
3101,
4145,
12,
315,
288,
4696,
14,
13327,
298,
403,
2,
367,
949,
2653,
14,
267,
520,
466,
2653,
26,
1109,
398,
520,
635,
4907,
63,
2593,
26,
8113,
2653,
367,
3101,
4145,
12,
315,
288,
4696,
14,
2047,
1077,
4165,
1586,
63,
2593,
315,
10234,
370,
642,
945,
14,
288,
3390,
626,
642,
5074,
4145,
2356,
499,
14,
20,
14,
16,
14,
267,
520,
466,
4907,
63,
2593,
26,
1109,
398,
520,
635,
1586,
63,
2593,
26,
5574,
2653,
367,
3101,
4145,
12,
315,
288,
4696,
14,
2047,
1077,
4165,
4907,
63,
2593,
315,
10234,
370,
642,
288,
945,
14,
3390,
626,
642,
5074,
4145,
2356,
499,
14,
20,
14,
16,
14,
267,
520,
466,
1586,
63,
2593,
26,
1109,
398,
520,
635,
7269,
63,
2593,
26,
12878,
9371,
3663,
4444,
461,
4145,
12,
315,
288,
4696,
14,
267,
520,
466,
7269,
63,
2593,
26,
1109,
398,
520,
635,
9212,
63,
529,
63,
4375,
26,
4860,
402,
9212,
1126,
3499,
8211,
14,
288,
982,
314,
6634,
2304,
365,
13075,
12,
314,
1890,
911,
9435,
367,
314,
288,
5827,
5982,
402,
900,
2544,
652,
7858,
314,
1453,
1827,
14,
267,
520,
466,
9212,
63,
529,
63,
4375,
26,
1109,
398,
520,
3536,
1722,
26,
1380,
1902,
6235,
787,
4124,
12,
17110,
288,
503,
3866,
14,
267,
520,
3536,
4279,
26,
340,
4907,
63,
2593,
436,
1586,
63,
2593,
787,
288,
1202,
543,
282,
1015,
402,
4145,
6791,
370,
499,
14,
20,
14,
16,
14,
398,
520,
635,
4145,
63,
958,
26,
11177,
4252,
2368,
367,
314,
4145,
288,
3555,
12,
1314,
16885,
1163,
7645,
2040,
367,
4566,
1790,
370,
506,
288,
6366,
14,
1666,
314,
25410,
4145,
9149,
367,
1655,
2256,
26,
288,
1455,
921,
4757,
14,
1548,
13,
6615,
14,
1308,
15,
287,
15,
7410,
15,
1246,
12645,
973,
13,
3266,
267,
520,
466,
4145,
63,
958,
26,
1211,
398,
408,
267,
340,
440,
790,
436,
440,
334,
1258,
63,
4731,
436,
1890,
63,
344,
304,
288,
746,
1722,
480,
13757,
5647,
3261,
790,
503,
9509,
13219,
6235,
298,
2490,
298,
6526,
6425,
1890,
2685,
398,
340,
790,
436,
440,
790,
14,
2460,
480,
7730,
8076,
2349,
288,
746,
1722,
480,
3364,
3261,
790,
2741,
2685,
398,
291,
14,
498,
275,
790,
398,
340,
2653,
436,
334,
2242,
63,
2593,
503,
1586,
63,
2593,
304,
288,
746,
1722,
480,
17768,
1902,
2653,
12,
503,
4907,
63,
2593,
298,
435,
2490,
298,
460,
1586,
63,
2593,
531,
398,
340,
4907,
63,
2593,
436,
1586,
63,
2593,
26,
288,
327,
2670,
626,
314,
1015,
402,
4145,
365,
2356,
499,
14,
20,
14,
16,
288,
8291,
275,
4145,
855,
1023,
4343,
1294,
15857,
288,
340,
8291,
59,
16,
61,
665,
499,
503,
334,
10660,
59,
16,
61,
508,
499,
436,
8291,
59,
17,
61,
665,
841,
304,
355,
746,
4279,
480,
8631,
15,
3284,
25870,
4409,
298,
5101,
298,
6615,
373,
18,
14,
20,
14,
16,
503,
10948,
531,
288,
291,
14,
2593,
275,
334,
2242,
63,
2593,
12,
1586,
63,
2593,
9,
267,
587,
26,
288,
291,
14,
2593,
275,
2653,
398,
291,
14,
1258,
63,
344,
275,
1890,
63,
344,
267,
291,
14,
1258,
63,
4731,
275,
1890,
63,
4731,
267,
291,
14,
7154,
63,
2593,
275,
6871,
8,
4515,
29,
7154,
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,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